[gnome-text-editor] preferences: give access to style schemes



commit bc86cac531cc86d0c35162a42bfb77610dfc83a3
Author: Christian Hergert <chergert redhat com>
Date:   Thu Jul 29 17:51:12 2021 -0700

    preferences: give access to style schemes
    
    This gives access to selecting a style scheme in the preferences panel
    within the window.
    
    It still has an issue that our style-variant is overriding things in that
    setting 'solarized-dark' will use 'solarized-light' if the application is
    in light mode. That will require further work.
    
    Fixes #79

 src/editor-window-private.h |  1 +
 src/editor-window.c         | 31 +++++++++++++++++++++++++++++++
 src/editor-window.ui        |  5 +++++
 3 files changed, 37 insertions(+)
---
diff --git a/src/editor-window-private.h b/src/editor-window-private.h
index 375e206..a60a588 100644
--- a/src/editor-window-private.h
+++ b/src/editor-window-private.h
@@ -52,6 +52,7 @@ struct _EditorWindow
   GtkMenuButton        *options_menu;
   GtkMenuButton        *export_menu;
   GtkRevealer          *preferences_revealer;
+  AdwPreferencesGroup  *scheme_group;
 
   /* Borrowed References */
   EditorPage           *visible_page;
diff --git a/src/editor-window.c b/src/editor-window.c
index 7012878..461a147 100644
--- a/src/editor-window.c
+++ b/src/editor-window.c
@@ -28,6 +28,7 @@
 #include "editor-document.h"
 #include "editor-open-popover-private.h"
 #include "editor-preferences-font.h"
+#include "editor-preferences-radio.h"
 #include "editor-preferences-spin.h"
 #include "editor-preferences-switch.h"
 #include "editor-save-changes-dialog-private.h"
@@ -275,6 +276,8 @@ static void
 editor_window_constructed (GObject *object)
 {
   EditorWindow *self = (EditorWindow *)object;
+  GtkSourceStyleSchemeManager *sm;
+  const char * const *scheme_ids;
   GtkApplication *app;
   EditorSession *session;
   GtkPopover *popover;
@@ -304,6 +307,33 @@ editor_window_constructed (GObject *object)
 
   options_menu = gtk_application_get_menu_by_id (GTK_APPLICATION (app), "options-menu");
   gtk_menu_button_set_menu_model (self->options_menu, G_MENU_MODEL (options_menu));
+
+  /* Populate schemes for preferences */
+  sm = gtk_source_style_scheme_manager_get_default ();
+  if ((scheme_ids = gtk_source_style_scheme_manager_get_scheme_ids (sm)))
+    {
+      EditorPreferencesRadio *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);
+          EditorPreferencesRadio *radio;
+
+          radio = g_object_new (EDITOR_TYPE_PREFERENCES_RADIO,
+                                "schema-id", "org.gnome.TextEditor",
+                                "schema-key", "style-scheme",
+                                "schema-value", scheme_ids[i],
+                                "title", name,
+                                NULL);
+          adw_preferences_group_add (self->scheme_group, GTK_WIDGET (radio));
+
+          if (group == NULL)
+            group = radio;
+          else
+            editor_preferences_radio_set_group (radio, group);
+        }
+    }
 }
 
 static void
@@ -411,6 +441,7 @@ editor_window_class_init (EditorWindowClass *klass)
   gtk_widget_class_bind_template_child (widget_class, EditorWindow, position_label);
   gtk_widget_class_bind_template_child (widget_class, EditorWindow, preferences_revealer);
   gtk_widget_class_bind_template_child (widget_class, EditorWindow, primary_menu);
+  gtk_widget_class_bind_template_child (widget_class, EditorWindow, scheme_group);
   gtk_widget_class_bind_template_child (widget_class, EditorWindow, stack);
   gtk_widget_class_bind_template_child (widget_class, EditorWindow, subtitle);
   gtk_widget_class_bind_template_child (widget_class, EditorWindow, tab_bar);
diff --git a/src/editor-window.ui b/src/editor-window.ui
index 8444c18..2b8a125 100644
--- a/src/editor-window.ui
+++ b/src/editor-window.ui
@@ -257,6 +257,11 @@ Or, press Ctrl+W to close the window.</property>
                                 </child>
                               </object>
                             </child>
+                            <child>
+                              <object class="AdwPreferencesGroup" id="scheme_group">
+                                <property name="margin-top">12</property>
+                              </object>
+                            </child>
                           </object>
                         </child>
                       </object>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]