[gnome-builder/wip/chergert/layout] editor: use file-settings for proper cascading



commit 2b1bb0e236006c18b7ffa601d6057791ae504ea8
Author: Christian Hergert <chergert redhat com>
Date:   Fri Jul 7 19:22:42 2017 -0700

    editor: use file-settings for proper cascading
    
    This ensures that we cascade our file-settings by tweaking
    the mutation layer (topmost). That way changes to the underlying
    file-settings (via gsettings, editorconfig, etc) do not cause
    our tweak settings to be overridden.

 libide/editor/ide-editor-properties.ui  |   10 +++---
 libide/editor/ide-editor-view-actions.c |   53 +++++++++++++++++++++++++-----
 2 files changed, 49 insertions(+), 14 deletions(-)
---
diff --git a/libide/editor/ide-editor-properties.ui b/libide/editor/ide-editor-properties.ui
index 3429d8b..390175b 100644
--- a/libide/editor/ide-editor-properties.ui
+++ b/libide/editor/ide-editor-properties.ui
@@ -37,7 +37,7 @@
                 <property name="visible">true</property>
                 <property name="label" translatable="yes">Show right margin</property>
                 <property name="halign">fill</property>
-                <property name="action-name">source-view.show-right-margin</property>
+                <property name="action-name">file-settings.show-right-margin</property>
               </object>
             </child>
             <child>
@@ -116,7 +116,7 @@
                         <property name="label" translatable="yes">2</property>
                         <property name="focus-on-click">false</property>
                         <property name="halign">fill</property>
-                        <property name="action-name">source-view.tab-width</property>
+                        <property name="action-name">file-settings.tab-width</property>
                         <property name="action-target">uint32 2</property>
                       </object>
                     </child>
@@ -126,7 +126,7 @@
                         <property name="label" translatable="yes">3</property>
                         <property name="focus-on-click">false</property>
                         <property name="halign">fill</property>
-                        <property name="action-name">source-view.tab-width</property>
+                        <property name="action-name">file-settings.tab-width</property>
                         <property name="action-target">uint32 3</property>
                       </object>
                     </child>
@@ -136,7 +136,7 @@
                         <property name="label" translatable="yes">4</property>
                         <property name="focus-on-click">false</property>
                         <property name="halign">fill</property>
-                        <property name="action-name">source-view.tab-width</property>
+                        <property name="action-name">file-settings.tab-width</property>
                         <property name="action-target">uint32 4</property>
                       </object>
                     </child>
@@ -146,7 +146,7 @@
                         <property name="label" translatable="yes">8</property>
                         <property name="focus-on-click">false</property>
                         <property name="halign">fill</property>
-                        <property name="action-name">source-view.tab-width</property>
+                        <property name="action-name">file-settings.tab-width</property>
                         <property name="action-target">uint32 8</property>
                       </object>
                     </child>
diff --git a/libide/editor/ide-editor-view-actions.c b/libide/editor/ide-editor-view-actions.c
index 062b27c..efa236d 100644
--- a/libide/editor/ide-editor-view-actions.c
+++ b/libide/editor/ide-editor-view-actions.c
@@ -21,6 +21,7 @@
 #include <glib/gi18n.h>
 
 #include "files/ide-file.h"
+#include "files/ide-file-settings.h"
 #include "buffers/ide-buffer.h"
 #include "buffers/ide-buffer-manager.h"
 #include "editor/ide-editor-private.h"
@@ -375,6 +376,26 @@ ide_editor_view_actions_save_as (GSimpleAction *action,
   gtk_native_dialog_destroy (GTK_NATIVE_DIALOG (dialog));
 }
 
+static void
+ide_editor_view_actions_notify_file_settings (IdeEditorView *self,
+                                              GParamSpec    *pspec,
+                                              IdeSourceView *source_view)
+{
+  IdeFileSettings *file_settings;
+  GActionGroup *group;
+
+  g_assert (IDE_IS_EDITOR_VIEW (self));
+  g_assert (IDE_IS_SOURCE_VIEW (source_view));
+
+  group = gtk_widget_get_action_group (GTK_WIDGET (self), "file-settings");
+  g_assert (DZL_IS_PROPERTIES_GROUP (group));
+
+  file_settings = ide_source_view_get_file_settings (source_view);
+  g_assert (!file_settings || IDE_IS_FILE_SETTINGS (file_settings));
+
+  g_object_set (group, "object", file_settings, NULL);
+}
+
 static const GActionEntry editor_view_entries[] = {
   { "print", ide_editor_view_actions_print },
   { "reload", ide_editor_view_actions_reload },
@@ -395,34 +416,48 @@ void
 _ide_editor_view_init_actions (IdeEditorView *self)
 {
   g_autoptr(GSimpleActionGroup) group = NULL;
-  g_autoptr(DzlPropertiesGroup) properties = NULL;
+  g_autoptr(DzlPropertiesGroup) sv_props = NULL;
+  g_autoptr(DzlPropertiesGroup) file_props = NULL;
+  IdeSourceView *source_view;
 
   g_return_if_fail (IDE_IS_EDITOR_VIEW (self));
 
+  source_view = ide_editor_view_get_view (self);
+
+  /* Setup our user-facing actions */
   group = g_simple_action_group_new ();
   g_action_map_add_action_entries (G_ACTION_MAP (group),
                                    editor_view_entries,
                                    G_N_ELEMENTS (editor_view_entries),
                                    self);
+  gtk_widget_insert_action_group (GTK_WIDGET (self), "editor-view", G_ACTION_GROUP (group));
 
   /* We want to access some settings properties as stateful GAction so they
    * manipulated using regular Gtk widgets from the properties panel.
    */
-  properties = dzl_properties_group_new (G_OBJECT (self->source_view));
+  sv_props = dzl_properties_group_new (G_OBJECT (source_view));
   for (guint i = 0; i < G_N_ELEMENTS (source_view_property_actions); i++)
     {
       const gchar *name = source_view_property_actions[i];
-      dzl_properties_group_add_property (properties, name, name);
+      dzl_properties_group_add_property (sv_props, name, name);
     }
-  dzl_properties_group_add_property_full (properties,
+  dzl_properties_group_add_property_full (sv_props,
                                           "use-spaces",
                                           "insert-spaces-instead-of-tabs",
                                           DZL_PROPERTIES_FLAGS_STATEFUL_BOOLEANS);
+  gtk_widget_insert_action_group (GTK_WIDGET (self), "source-view", G_ACTION_GROUP (sv_props));
 
-  /* Our groups will be copied up to be accessed outside of our widget
-   * hierarchy. So we expose them all on the IdeEditorView directly
-   * for that purpose.
+  /*
+   * We want to bind our file-settings, used to tweak values in the
+   * source-view, to a GActionGroup that can be manipulated by the properties
+   * editor. Make sure we get notified of changes and sink the current state.
    */
-  gtk_widget_insert_action_group (GTK_WIDGET (self), "editor-view", G_ACTION_GROUP (group));
-  gtk_widget_insert_action_group (GTK_WIDGET (self), "source-view", G_ACTION_GROUP (properties));
+  file_props = dzl_properties_group_new_for_type (IDE_TYPE_FILE_SETTINGS);
+  dzl_properties_group_add_all_properties (file_props);
+  g_signal_connect_swapped (source_view,
+                            "notify::file-settings",
+                            G_CALLBACK (ide_editor_view_actions_notify_file_settings),
+                            self);
+  gtk_widget_insert_action_group (GTK_WIDGET (self), "file-settings", G_ACTION_GROUP (file_props));
+  ide_editor_view_actions_notify_file_settings (self, NULL, source_view);
 }


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