[dconf-editor] Organize access to SettingsModel instance a bit



commit 811d7f3009a74dbdedfe4d9f0e868069928ef1d9
Author: Davi da Silva Böger <dsboger gmail com>
Date:   Fri Dec 15 16:32:07 2017 -0200

    Organize access to SettingsModel instance a bit

 editor/browser-view.vala     |   28 ++++++++++++++++----------
 editor/dconf-window.vala     |    4 +-
 editor/key-list-box-row.vala |   44 +++++++++++++++++++++++++----------------
 editor/registry-info.vala    |   33 +++++++++++++++++--------------
 editor/registry-search.vala  |    5 ++-
 5 files changed, 67 insertions(+), 47 deletions(-)
---
diff --git a/editor/browser-view.vala b/editor/browser-view.vala
index 9f95883..338117f 100644
--- a/editor/browser-view.vala
+++ b/editor/browser-view.vala
@@ -119,7 +119,8 @@ class BrowserView : Grid, PathElement
 
     public void set_directory (Directory directory, string? selected)
     {
-        GLib.ListStore? key_model = window.model.get_children (directory);
+        SettingsModel model = modifications_handler.model;
+        GLib.ListStore? key_model = model.get_children (directory);
         if (key_model != null)
         {
             current_directory = directory;
@@ -321,13 +322,15 @@ class BrowserView : Grid, PathElement
 
     public void reset (bool recursively)
     {
-        reset_objects (window.model.get_children (current_directory), recursively);
+        SettingsModel model = modifications_handler.model;
+        reset_objects (model.get_children (current_directory), recursively);
     }
 
     public void reset_directory (Directory parent, bool recursively)
     {
+        SettingsModel model = modifications_handler.model;
         enter_delay_mode ();
-        GLib.ListStore? objects = window.model.get_children (parent);
+        GLib.ListStore? objects = model.get_children (parent);
         if (objects != null)
         {
             reset_generic ((!) objects, recursively);
@@ -344,6 +347,7 @@ class BrowserView : Grid, PathElement
 
     private void reset_generic (GLib.ListStore? objects, bool recursively)
     {
+        SettingsModel model = modifications_handler.model;
         if (objects == null)
             return;
 
@@ -357,7 +361,7 @@ class BrowserView : Grid, PathElement
             if (setting_object is Directory)
             {
                 if (recursively) {
-                    GLib.ListStore? children = window.model.get_children ((Directory) setting_object);
+                    GLib.ListStore? children = model.get_children ((Directory) setting_object);
                     if (children != null)
                         reset_generic ((!) children, true);
                 }
@@ -365,10 +369,10 @@ class BrowserView : Grid, PathElement
             }
             if (setting_object is DConfKey)
             {
-                if (!modifications_handler.model.is_key_ghost ((DConfKey) setting_object))
+                if (!model.is_key_ghost ((DConfKey) setting_object))
                     modifications_handler.add_delayed_setting ((Key) setting_object, null);
             }
-            else if (!modifications_handler.model.is_key_default ((GSettingsKey) setting_object))
+            else if (!model.is_key_default ((GSettingsKey) setting_object))
                 modifications_handler.add_delayed_setting ((Key) setting_object, null);
         }
     }
@@ -387,10 +391,11 @@ class BrowserView : Grid, PathElement
 
     private void reload_view (bool notify_missing)
     {
+        SettingsModel model = modifications_handler.model;
         if (current_view_is_browse_view ())
         {
             string? saved_selection = browse_view.get_selected_row_name ();
-            Directory? directory = window.model.get_directory (current_path);
+            Directory? directory = model.get_directory (current_path);
             if (directory == null)
                 request_path (current_path, notify_missing); // rely on fallback detection
             else
@@ -407,16 +412,17 @@ class BrowserView : Grid, PathElement
 
     public void check_reload (bool internal_changes)
     {
+        SettingsModel model = modifications_handler.model;
         if (current_view_is_properties_view ())
         {
-            Key? fresh_key = (Key?) modifications_handler.model.get_object (current_path);
-            if (fresh_key != null && !properties_view.check_reload ((!) fresh_key, 
modifications_handler.model.get_key_value ((!) fresh_key)))
+            Key? fresh_key = (Key?) model.get_object (current_path);
+            if (fresh_key != null && !properties_view.check_reload ((!) fresh_key, model.get_key_value ((!) 
fresh_key)))
                 return;
         }
         else if (current_view_is_browse_view ())
         {
-            Directory? fresh_dir = (Directory?) modifications_handler.model.get_directory (current_path);
-            GLib.ListStore? fresh_key_model = modifications_handler.model.get_children (fresh_dir);
+            Directory? fresh_dir = (Directory?) model.get_directory (current_path);
+            GLib.ListStore? fresh_key_model = model.get_children (fresh_dir);
             if (fresh_key_model != null)
             {
                 sorting_options.sort_key_model ((!) fresh_key_model); // RegistryView.check_reload assumes 
the same order as the current view for faster comparison
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index 0f2af80..abb3d3a 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -31,8 +31,8 @@ class DConfWindow : ApplicationWindow
 
     public string current_path { get; set; default = "/"; } // not synced bidi, needed for saving on 
destroy, even after child destruction
 
-    public SettingsModel model { get; private set; }
-    public ModificationsHandler modifications_handler { get; private set; }
+    private SettingsModel model;
+    private ModificationsHandler modifications_handler;
 
     private int window_width = 0;
     private int window_height = 0;
diff --git a/editor/key-list-box-row.vala b/editor/key-list-box-row.vala
index a30d737..c79dd22 100644
--- a/editor/key-list-box-row.vala
+++ b/editor/key-list-box-row.vala
@@ -262,6 +262,7 @@ private abstract class KeyListBoxRow : ClickableListBoxRow
 
     public void set_delayed_icon ()
     {
+        SettingsModel model = modifications_handler.model;
         Key key = abstract_key;
         StyleContext context = get_style_context ();
         if (modifications_handler.key_has_planned_change (key))
@@ -278,7 +279,7 @@ private abstract class KeyListBoxRow : ClickableListBoxRow
         else
         {
             context.remove_class ("delayed");
-            if (key is DConfKey && modifications_handler.model.is_key_ghost ((DConfKey) key))
+            if (key is DConfKey && model.is_key_ghost ((DConfKey) key))
                 context.add_class ("erase");
             else
                 context.remove_class ("erase");
@@ -293,11 +294,12 @@ private class KeyListBoxRowEditableNoSchema : KeyListBoxRow
 
     construct
     {
+        SettingsModel model = modifications_handler.model;
         get_style_context ().add_class ("dconf-key");
 
         if (boolean_switch != null)
             ((!) boolean_switch).notify ["active"].connect (
-                        () => modifications_handler.model.set_key_value (key, new Variant.boolean (((!) 
boolean_switch).get_active ())));
+                        () => model.set_key_value (key, new Variant.boolean (((!) boolean_switch).get_active 
())));
 
         key_info_label.get_style_context ().add_class ("italic-label");
         key_info_label.set_label (_("No Schema Found"));
@@ -310,7 +312,8 @@ private class KeyListBoxRowEditableNoSchema : KeyListBoxRow
 
     protected override void update ()
     {
-        if (modifications_handler.model.is_key_ghost (key))
+        SettingsModel model = modifications_handler.model;
+        if (model.is_key_ghost (key))
         {
             if (boolean_switch != null)
             {
@@ -321,7 +324,7 @@ private class KeyListBoxRowEditableNoSchema : KeyListBoxRow
         }
         else
         {
-            Variant key_value = modifications_handler.model.get_key_value (key);
+            Variant key_value = model.get_key_value (key);
             if (boolean_switch != null)
             {
                 key_value_label.hide ();
@@ -334,12 +337,14 @@ private class KeyListBoxRowEditableNoSchema : KeyListBoxRow
 
     protected override string get_text ()
     {
-        return modifications_handler.model.get_key_copy_text (key);
+        SettingsModel model = modifications_handler.model;
+        return model.get_key_copy_text (key);
     }
 
     protected override bool generate_popover (ContextPopover popover)
     {
-        if (modifications_handler.model.is_key_ghost (key))
+        SettingsModel model = modifications_handler.model;
+        if (model.is_key_ghost (key))
         {
             popover.new_copy_action (get_text ());
             return true;
@@ -413,15 +418,16 @@ private class KeyListBoxRowEditable : KeyListBoxRow
 
     construct
     {
+        SettingsModel model = modifications_handler.model;
         get_style_context ().add_class ("gsettings-key");
 
         if (boolean_switch != null)
             boolean_switch_toggled_handler = ((!) boolean_switch).notify ["active"].connect (() => {
                     bool boolean = ((!) boolean_switch).get_active ();
                     if (boolean == key.default_value.get_boolean ())
-                        modifications_handler.model.set_key_to_default (key);
+                        model.set_key_to_default (key);
                     else
-                        modifications_handler.model.set_key_value (key, new Variant.boolean (boolean));
+                        model.set_key_value (key, new Variant.boolean (boolean));
                 });
 
         if (key.summary != "")
@@ -440,9 +446,10 @@ private class KeyListBoxRowEditable : KeyListBoxRow
 
     protected override void update ()
     {
+        SettingsModel model = modifications_handler.model;
         if (boolean_switch != null)
         {
-            bool boolean = modifications_handler.model.get_key_value (key).get_boolean ();
+            bool boolean = model.get_key_value (key).get_boolean ();
             if (((!) boolean_switch).get_active () != boolean)
             {
                 if (boolean_switch_toggled_handler > 0)
@@ -457,20 +464,22 @@ private class KeyListBoxRowEditable : KeyListBoxRow
         }
 
         StyleContext css_context = get_style_context ();
-        if (modifications_handler.model.is_key_default (key))
+        if (model.is_key_default (key))
             css_context.remove_class ("edited");
         else
             css_context.add_class ("edited");
-        key_value_label.set_label (Key.cool_text_value_from_variant 
(modifications_handler.model.get_key_value (key), key.type_string));
+        key_value_label.set_label (Key.cool_text_value_from_variant (model.get_key_value (key), 
key.type_string));
     }
 
     protected override string get_text ()
     {
-        return modifications_handler.model.get_key_copy_text (key);
+        SettingsModel model = modifications_handler.model;
+        return model.get_key_copy_text (key);
     }
 
     protected override bool generate_popover (ContextPopover popover)
     {
+        SettingsModel model = modifications_handler.model;
         if (search_result_mode)
         {
             popover.new_action ("open_parent", () => on_open_parent ());
@@ -505,7 +514,7 @@ private class KeyListBoxRowEditable : KeyListBoxRow
                 });
             popover.value_changed.connect ((gvariant) => {
                     hide_right_click_popover ();
-                    Variant key_value = modifications_handler.model.get_key_value (key);
+                    Variant key_value = model.get_key_value (key);
                     action.change_state (new Variant.maybe (null, new Variant.maybe (new VariantType 
(key_value.get_type_string ()), gvariant)));
                     set_key_value (gvariant);
                 });
@@ -514,7 +523,7 @@ private class KeyListBoxRowEditable : KeyListBoxRow
         {
             popover.new_section ();
 
-            if (!modifications_handler.model.is_key_default (key))
+            if (!model.is_key_default (key))
                 popover.new_action ("default2", () => {
                         destroy_popover ();
                         set_key_value (null);
@@ -538,7 +547,7 @@ private class KeyListBoxRowEditable : KeyListBoxRow
                         set_key_value (null);
                     });
         }
-        else if (!modifications_handler.model.is_key_default (key))
+        else if (!model.is_key_default (key))
         {
             popover.new_section ();
             popover.new_action ("default1", () => {
@@ -706,11 +715,12 @@ private class ContextPopover : Popover
 
     public GLib.Action create_buttons_list (Key key, bool has_default_value, ModificationsHandler 
modifications_handler)
     {
+        SettingsModel model = modifications_handler.model;
         set_group ("enum");
         const string ACTION_NAME = "choice";
         string group_dot_action = "enum.choice";
 
-        Variant key_value = modifications_handler.model.get_key_value (key);
+        Variant key_value = model.get_key_value (key);
         VariantType original_type = key_value.get_type ();
         VariantType nullable_type = new VariantType.maybe (original_type);
         VariantType nullable_nullable_type = new VariantType.maybe (nullable_type);
@@ -725,7 +735,7 @@ private class ContextPopover : Popover
             value_variant = modifications_handler.get_key_custom_value (key);
         else if (planned_change)
             value_variant = planned_value;
-        else if (key is GSettingsKey && modifications_handler.model.is_key_default ((GSettingsKey) key))
+        else if (key is GSettingsKey && model.is_key_default ((GSettingsKey) key))
             value_variant = null;
         else
             value_variant = key_value;
diff --git a/editor/registry-info.vala b/editor/registry-info.vala
index 7cd684d..654ae79 100644
--- a/editor/registry-info.vala
+++ b/editor/registry-info.vala
@@ -62,7 +62,8 @@ class RegistryInfo : Grid, BrowsableView
 
     public void populate_properties_list_box (Key key, bool warning_multiple_schemas)
     {
-        if (key is DConfKey && modifications_handler.model.is_key_ghost ((DConfKey) key))   // TODO place in 
"requires"
+        SettingsModel model = modifications_handler.model;
+        if (key is DConfKey && model.is_key_ghost ((DConfKey) key))   // TODO place in "requires"
             assert_not_reached ();
         clean ();   // for when switching between two keys, for example with a search (maybe also bookmarks)
 
@@ -99,12 +100,12 @@ class RegistryInfo : Grid, BrowsableView
 
         if (!dict.lookup ("type-code",    "s", out tmp_string))  assert_not_reached ();
 
-        Label label = new Label (get_current_value_text (has_schema && 
modifications_handler.model.is_key_default ((GSettingsKey) key), key));
+        Label label = new Label (get_current_value_text (has_schema && model.is_key_default ((GSettingsKey) 
key), key));
         ulong key_value_changed_handler = key.value_changed.connect (() => {
-                if (!has_schema && modifications_handler.model.is_key_ghost ((DConfKey) key))
+                if (!has_schema && model.is_key_ghost ((DConfKey) key))
                     label.set_text (_("Key erased."));
                 else
-                    label.set_text (get_current_value_text (has_schema && 
modifications_handler.model.is_key_default ((GSettingsKey) key), key));
+                    label.set_text (get_current_value_text (has_schema && model.is_key_default 
((GSettingsKey) key), key));
             });
         label.halign = Align.START;
         label.valign = Align.START;
@@ -136,7 +137,7 @@ class RegistryInfo : Grid, BrowsableView
                         modifications_handler.dismiss_change (key);
                 }
                 else
-                    modifications_handler.model.set_key_value (key, key_editor_child.get_variant ());
+                    model.set_key_value (key, key_editor_child.get_variant ());
             });
 
         if (has_schema)
@@ -168,20 +169,20 @@ class RegistryInfo : Grid, BrowsableView
                     {
                         if (custom_value_switch.get_active ())
                         {
-                            modifications_handler.model.set_key_to_default ((GSettingsKey) key);
+                            model.set_key_to_default ((GSettingsKey) key);
                             SignalHandler.block (key_editor_child, value_has_changed_handler);
-                            key_editor_child.reload (modifications_handler.model.get_key_value (key));
+                            key_editor_child.reload (model.get_key_value (key));
                             //if (tmp_string == "<flags>")                      let's try to live without 
this...
                             //    key.planned_value = key.value;
                             SignalHandler.unblock (key_editor_child, value_has_changed_handler);
                         }
                         else
-                            modifications_handler.model.set_key_value (key, 
modifications_handler.model.get_key_value (key));  // TODO that hurts...
+                            model.set_key_value (key, model.get_key_value (key));  // TODO that hurts...
                     }
                 });
             revealer_reload_1_handler = modifications_handler.reload.connect (() => {
                     SignalHandler.block (custom_value_switch, switch_active_handler);
-                    custom_value_switch.set_active (modifications_handler.model.is_key_default (gkey));
+                    custom_value_switch.set_active (model.is_key_default (gkey));
                     SignalHandler.unblock (custom_value_switch, switch_active_handler);
                 });
             custom_value_switch.destroy.connect (() => custom_value_switch.disconnect 
(switch_active_handler));
@@ -196,10 +197,10 @@ class RegistryInfo : Grid, BrowsableView
 
         ulong child_activated_handler = key_editor_child.child_activated.connect (() => 
modifications_handler.apply_delayed_settings ());  // TODO "only" used for string-based and spin widgets
         revealer_reload_2_handler = modifications_handler.reload.connect (() => {
-                if (key is DConfKey && modifications_handler.model.is_key_ghost ((DConfKey) key))
+                if (key is DConfKey && model.is_key_ghost ((DConfKey) key))
                     return;
                 SignalHandler.block (key_editor_child, value_has_changed_handler);
-                key_editor_child.reload (modifications_handler.model.get_key_value (key));
+                key_editor_child.reload (model.get_key_value (key));
                 //if (tmp_string == "<flags>")                      let's try to live without this...
                 //    key.planned_value = key.value;
                 SignalHandler.unblock (key_editor_child, value_has_changed_handler);
@@ -215,6 +216,7 @@ class RegistryInfo : Grid, BrowsableView
 
     private KeyEditorChild create_child (Key key, bool has_schema)
     {
+        SettingsModel model = modifications_handler.model;
         Variant initial_value = modifications_handler.get_key_custom_value (key);
         switch (key.type_string)
         {
@@ -222,7 +224,7 @@ class RegistryInfo : Grid, BrowsableView
                 switch (((GSettingsKey) key).range_content.n_children ())
                 {
                     case 0:  assert_not_reached ();
-                    case 1:  return (KeyEditorChild) new KeyEditorChildSingle 
(modifications_handler.model.get_key_value (key), modifications_handler.model.get_key_value (key).get_string 
());
+                    case 1:  return (KeyEditorChild) new KeyEditorChildSingle (model.get_key_value (key), 
model.get_key_value (key).get_string ());
                     default: return (KeyEditorChild) new KeyEditorChildEnum (key, initial_value, 
modifications_handler);
                 }
             case "<flags>":
@@ -237,7 +239,7 @@ class RegistryInfo : Grid, BrowsableView
                 {
                     Variant range = ((GSettingsKey) key).range_content;
                     if (Key.get_variant_as_int64 (range.get_child_value (0)) == Key.get_variant_as_int64 
(range.get_child_value (1)))
-                        return (KeyEditorChild) new KeyEditorChildSingle 
(modifications_handler.model.get_key_value (key), modifications_handler.model.get_key_value (key).print 
(false));
+                        return (KeyEditorChild) new KeyEditorChildSingle (model.get_key_value (key), 
model.get_key_value (key).print (false));
                 }
                 return (KeyEditorChild) new KeyEditorChildNumberInt (key, initial_value);
             case "y":
@@ -248,7 +250,7 @@ class RegistryInfo : Grid, BrowsableView
                 {
                     Variant range = ((GSettingsKey) key).range_content;
                     if (Key.get_variant_as_uint64 (range.get_child_value (0)) == Key.get_variant_as_uint64 
(range.get_child_value (1)))
-                        return (KeyEditorChild) new KeyEditorChildSingle 
(modifications_handler.model.get_key_value (key), modifications_handler.model.get_key_value (key).print 
(false));
+                        return (KeyEditorChild) new KeyEditorChildSingle (model.get_key_value (key), 
model.get_key_value (key).print (false));
                 }
                 return (KeyEditorChild) new KeyEditorChildNumberInt (key, initial_value);
             case "d":
@@ -265,10 +267,11 @@ class RegistryInfo : Grid, BrowsableView
 
     private string get_current_value_text (bool is_default, Key key)
     {
+        SettingsModel model = modifications_handler.model;
         if (is_default)
             return _("Default value");
         else
-            return Key.cool_text_value_from_variant (modifications_handler.model.get_key_value (key), 
key.type_string);
+            return Key.cool_text_value_from_variant (model.get_key_value (key), key.type_string);
     }
 
     public string? get_copy_text ()
diff --git a/editor/registry-search.vala b/editor/registry-search.vala
index 0adc0d3..8245635 100644
--- a/editor/registry-search.vala
+++ b/editor/registry-search.vala
@@ -393,7 +393,7 @@ class RegistrySearch : Grid, PathElement, BrowsableView
             return;
         }
 
-        SettingsModel model = window.model;
+        SettingsModel model = modifications_handler.model;
         string current_path = window.current_path;
         if (old_term != null && term.has_prefix ((!) old_term))
         {
@@ -563,12 +563,13 @@ class RegistrySearch : Grid, PathElement, BrowsableView
 
     private bool global_search_step (string current_path, string term)
     {
+        SettingsModel model = modifications_handler.model;
         if (!search_nodes.is_empty ())
         {
             Directory next = (!) search_nodes.pop_head ();
             bool local_again = next.full_name == current_path;
 
-            GLib.ListStore? next_key_model = window.model.get_children (next);
+            GLib.ListStore? next_key_model = model.get_children (next);
             if (next_key_model == null)
                 return true;
 


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