[gnome-text-editor] prefs: implement new style scheme chooser
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-text-editor] prefs: implement new style scheme chooser
- Date: Tue, 12 Oct 2021 00:45:02 +0000 (UTC)
commit 98f74b5f4d03877dd39a7b1e9eedaa21b822ceb3
Author: Christian Hergert <chergert redhat com>
Date: Mon Oct 11 17:39:42 2021 -0700
prefs: implement new style scheme chooser
This implements the new style scheme selector design. There may be follow
up work to do on how we want to switch between light and dark variants
based on metadata in the styleschemes, however that can be implemented
elsewhere (in EditorApplication, for example) and probably requires a new
issue specifically for it.
Fixes #178
src/editor-window-private.h | 2 +-
src/editor-window.c | 58 ++++++++++++++++++++++++++++-----------------
src/editor-window.ui | 6 ++++-
3 files changed, 42 insertions(+), 24 deletions(-)
---
diff --git a/src/editor-window-private.h b/src/editor-window-private.h
index 143b6bc..b28b0d4 100644
--- a/src/editor-window-private.h
+++ b/src/editor-window-private.h
@@ -51,7 +51,7 @@ struct _EditorWindow
GtkMenuButton *primary_menu;
GtkMenuButton *options_menu;
GtkMenuButton *export_menu;
- AdwPreferencesGroup *scheme_group;
+ GtkGrid *scheme_group;
AdwFlap *flap;
/* Borrowed References */
diff --git a/src/editor-window.c b/src/editor-window.c
index e4eac54..29bcf22 100644
--- a/src/editor-window.c
+++ b/src/editor-window.c
@@ -47,6 +47,29 @@ enum {
static GParamSpec *properties[N_PROPS];
+static void
+update_style_scheme_cb (EditorWindow *self,
+ const char *key,
+ GSettings *settings)
+{
+ g_autofree char *id = NULL;
+
+ g_assert (EDITOR_IS_WINDOW (self));
+
+ id = g_settings_get_string (settings, "style-scheme");
+
+ for (GtkWidget *child = gtk_widget_get_first_child (GTK_WIDGET (self->scheme_group));
+ child;
+ child = gtk_widget_get_next_sibling (child))
+ {
+ GtkSourceStyleSchemePreview *preview = GTK_SOURCE_STYLE_SCHEME_PREVIEW (child);
+ GtkSourceStyleScheme *scheme = gtk_source_style_scheme_preview_get_scheme (preview);
+ const char *scheme_id = gtk_source_style_scheme_get_id (scheme);
+
+ gtk_source_style_scheme_preview_set_selected (preview, g_strcmp0 (scheme_id, id) == 0);
+ }
+}
+
static void
update_subtitle_visibility_cb (EditorWindow *self)
{
@@ -312,32 +335,18 @@ editor_window_constructed (GObject *object)
sm = gtk_source_style_scheme_manager_get_default ();
if ((scheme_ids = gtk_source_style_scheme_manager_get_scheme_ids (sm)))
{
- GtkCheckButton *group = NULL;
-
for (guint i = 0; scheme_ids[i]; i++)
{
GtkSourceStyleScheme *scheme = gtk_source_style_scheme_manager_get_scheme (sm, scheme_ids[i]);
- const char *name = gtk_source_style_scheme_get_name (scheme);
- GtkWidget *radio;
- GtkWidget *w;
-
- radio = g_object_new (GTK_TYPE_CHECK_BUTTON,
- "can-focus", FALSE,
- "valign", GTK_ALIGN_CENTER,
- "action-name", "app.style-scheme",
- "action-target", g_variant_new_string (scheme_ids[i]),
- NULL);
- w = adw_action_row_new ();
- adw_preferences_row_set_title (ADW_PREFERENCES_ROW (w), name);
- adw_action_row_add_prefix (ADW_ACTION_ROW (w), radio);
- adw_action_row_set_activatable_widget (ADW_ACTION_ROW (w), radio);
- adw_preferences_group_add (self->scheme_group, w);
-
- if (group == NULL)
- group = GTK_CHECK_BUTTON (radio);
- else
- gtk_check_button_set_group (GTK_CHECK_BUTTON (radio), group);
+ GtkWidget *preview = gtk_source_style_scheme_preview_new (scheme);
+
+ gtk_actionable_set_action_name (GTK_ACTIONABLE (preview), "app.style-scheme");
+ gtk_actionable_set_action_target (GTK_ACTIONABLE (preview), "s", scheme_ids[i]);
+ gtk_widget_set_hexpand (preview, TRUE);
+ gtk_grid_attach (self->scheme_group, preview, i % 2, i / 2, 1, 1);
}
+
+ update_style_scheme_cb (self, "style-scheme", self->settings);
}
}
@@ -612,6 +621,11 @@ editor_window_init (EditorWindow *self)
G_CALLBACK (update_subtitle_visibility_cb),
self,
G_CONNECT_SWAPPED);
+ g_signal_connect_object (self->settings,
+ "changed::style-scheme",
+ G_CALLBACK (update_style_scheme_cb),
+ self,
+ G_CONNECT_SWAPPED);
g_signal_connect_swapped (adw_tab_view_get_pages (self->tab_view),
"items-changed",
diff --git a/src/editor-window.ui b/src/editor-window.ui
index 423053d..d538045 100644
--- a/src/editor-window.ui
+++ b/src/editor-window.ui
@@ -182,6 +182,7 @@ Or, press Ctrl+W to close the window.</property>
</style>
<child>
<object class="GtkBox">
+ <property name="hexpand">false</property>
<property name="orientation">vertical</property>
<property name="width-request">300</property>
<property name="margin-start">12</property>
@@ -281,7 +282,10 @@ Or, press Ctrl+W to close the window.</property>
</object>
</child>
<child>
- <object class="AdwPreferencesGroup" id="scheme_group">
+ <object class="GtkGrid" id="scheme_group">
+ <property name="hexpand">true</property>
+ <property name="column-spacing">9</property>
+ <property name="row-spacing">9</property>
<property name="margin-top">12</property>
</object>
</child>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]