[gnome-text-editor] page: proxy settings to action group



commit 5dadd06548800cf46b704b3b6b283161639886a3
Author: Christian Hergert <chergert redhat com>
Date:   Mon Feb 21 17:43:13 2022 -0800

    page: proxy settings to action group
    
    This gives access to some settings from menus.

 src/editor-page-actions.c | 28 ++++++++++++++++++++++++++++
 src/editor-page-private.h |  2 ++
 src/editor-page.c         | 21 +++++++++++++++++++++
 3 files changed, 51 insertions(+)
---
diff --git a/src/editor-page-actions.c b/src/editor-page-actions.c
index 3898c4f..fee7bc0 100644
--- a/src/editor-page-actions.c
+++ b/src/editor-page-actions.c
@@ -250,3 +250,31 @@ _editor_page_actions_init (EditorPage *self)
                            self,
                            G_CONNECT_SWAPPED);
 }
+
+void
+_editor_page_actions_bind_settings (EditorPage         *self,
+                                    EditorPageSettings *settings)
+{
+  GSimpleActionGroup *group;
+  static const char *props[] = {
+    "auto-indent",
+    "indent-style",
+    "indent-width",
+    "tab-width",
+  };
+
+  g_assert (EDITOR_IS_PAGE (self));
+  g_assert (!settings || EDITOR_IS_PAGE_SETTINGS (settings));
+
+  group = g_simple_action_group_new ();
+  if (settings != NULL)
+    {
+      for (guint i = 0; i < G_N_ELEMENTS (props); i++)
+        {
+          g_autoptr(GPropertyAction) action = g_property_action_new (props[i], settings, props[i]);
+          g_action_map_add_action (G_ACTION_MAP (group), G_ACTION (action));
+        }
+    }
+  gtk_widget_insert_action_group (GTK_WIDGET (self), "view", G_ACTION_GROUP (group));
+  g_clear_object (&group);
+}
diff --git a/src/editor-page-private.h b/src/editor-page-private.h
index bec58e7..4000b16 100644
--- a/src/editor-page-private.h
+++ b/src/editor-page-private.h
@@ -65,6 +65,8 @@ struct _EditorPage
 
 void          _editor_page_class_actions_init     (EditorPageClass      *klass);
 void          _editor_page_actions_init           (EditorPage           *self);
+void          _editor_page_actions_bind_settings  (EditorPage           *self,
+                                                   EditorPageSettings   *settings);
 EditorWindow *_editor_page_get_window             (EditorPage           *self);
 void          _editor_page_save                   (EditorPage           *self);
 void          _editor_page_save_as                (EditorPage           *self,
diff --git a/src/editor-page.c b/src/editor-page.c
index b83d210..da05066 100644
--- a/src/editor-page.c
+++ b/src/editor-page.c
@@ -336,6 +336,21 @@ font_desc_from_string (GBinding     *binding,
   return TRUE;
 }
 
+static void
+on_settings_changed_cb (EditorPage         *self,
+                        GParamSpec         *pspec,
+                        EditorBindingGroup *group)
+{
+  EditorPageSettings *settings;
+
+  g_assert (EDITOR_IS_PAGE (self));
+  g_assert (EDITOR_IS_BINDING_GROUP (group));
+
+  settings = EDITOR_PAGE_SETTINGS (editor_binding_group_get_source (group));
+
+  _editor_page_actions_bind_settings (self, settings);
+}
+
 static void
 editor_page_constructed (GObject *object)
 {
@@ -348,6 +363,12 @@ editor_page_constructed (GObject *object)
 
   self->settings_bindings = editor_binding_group_new ();
 
+  g_signal_connect_object (self->settings_bindings,
+                           "notify::source",
+                           G_CALLBACK (on_settings_changed_cb),
+                           self,
+                           G_CONNECT_SWAPPED);
+
   editor_binding_group_bind_full (self->settings_bindings, "custom-font",
                                   self->view, "font-desc",
                                   G_BINDING_SYNC_CREATE,


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