[dconf-editor] Do not share application settings with SettingsModel.



commit 50e95672cb09de586cff89e72425f387c33ab6c9
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Fri Jan 12 00:33:51 2018 +0100

    Do not share application settings with SettingsModel.

 editor/dconf-model.vala  |   86 ++++++++++++++--------------------------------
 editor/dconf-window.vala |   62 ++++++++++++++++++++++++--------
 2 files changed, 72 insertions(+), 76 deletions(-)
---
diff --git a/editor/dconf-model.vala b/editor/dconf-model.vala
index 556d763..d6186f2 100644
--- a/editor/dconf-model.vala
+++ b/editor/dconf-model.vala
@@ -387,8 +387,6 @@ enum RelocatableSchemasEnabledMappings
 
 public class SettingsModel : Object
 {
-    private Settings application_settings;
-
     private SettingsSchemaSource? settings_schema_source = null;
     private HashTable<string, GenericSet<string>> relocatable_schema_paths = new HashTable<string, 
GenericSet<string>> (str_hash, str_equal);
     private HashTable<string, GenericSet<string>> startup_relocatable_schema_paths = new HashTable<string, 
GenericSet<string>> (str_hash, str_equal);
@@ -399,17 +397,34 @@ public class SettingsModel : Object
 
     public signal void paths_changed (GenericSet<string> modified_path_specs, bool internal_changes);
 
-    public SettingsModel (Settings application_settings)
-    {
-        this.application_settings = application_settings;
-    }
-
-    private void refresh_relocatable_schema_paths ()
+    public void refresh_relocatable_schema_paths (bool user_schemas,
+                                                  bool built_in_schemas,
+                                                  bool internal_schemas,
+                                                  bool startup_schemas,
+                                                  Variant user_paths_variant)
     {
         relocatable_schema_paths.remove_all ();
-        parse_relocatable_schemas_user_paths ();
-        create_relocatable_schemas_built_in_paths ();
-        parse_relocatable_schemas_startup_paths ();
+        if (user_schemas)
+        {
+            VariantIter entries_iter;
+            user_paths_variant.get ("a{ss}", out entries_iter);
+            string schema_id;
+            string path_spec;
+            while (entries_iter.next ("{ss}", out schema_id, out path_spec))
+                add_relocatable_schema_info (relocatable_schema_paths, schema_id, path_spec);
+        }
+        if (built_in_schemas)
+        {
+            string [,] known_mappings = ConfigurationEditor.known_mappings;
+            for (int i = 0; i < known_mappings.length [0]; i++)
+                add_relocatable_schema_info (relocatable_schema_paths, known_mappings [i,0], known_mappings 
[i,1]);
+        }
+        if (startup_schemas)
+        {
+            startup_relocatable_schema_paths.foreach ((schema_id, paths) => {
+                    paths.foreach ((path_spec) => add_relocatable_schema_info (relocatable_schema_paths, 
schema_id, path_spec));
+                });
+        }
     }
 
     public void add_mapping (string schema, string path)
@@ -419,18 +434,6 @@ public class SettingsModel : Object
 
     public void finalize_model ()
     {
-        refresh_relocatable_schema_paths ();
-        application_settings.changed ["relocatable-schemas-user-paths"].connect (() => {
-                RelocatableSchemasEnabledMappings enabled_mappings_flags = 
(RelocatableSchemasEnabledMappings) application_settings.get_flags ("relocatable-schemas-enabled-mappings");
-                if (!(RelocatableSchemasEnabledMappings.USER in enabled_mappings_flags))
-                    return;
-
-                refresh_relocatable_schema_paths ();
-            });
-        application_settings.changed ["relocatable-schemas-enabled-mappings"].connect (() => {
-                refresh_relocatable_schema_paths ();
-            });
-
         refresh_schema_source ();
         Timeout.add (3000, () => {
                 refresh_schema_source ();
@@ -509,43 +512,6 @@ public class SettingsModel : Object
             paths_changed (modified_path_specs, false);
     }
 
-    private void parse_relocatable_schemas_user_paths ()
-    {
-        RelocatableSchemasEnabledMappings enabled_mappings_flags = (RelocatableSchemasEnabledMappings) 
application_settings.get_flags ("relocatable-schemas-enabled-mappings");
-        if (!(RelocatableSchemasEnabledMappings.USER in enabled_mappings_flags))
-            return;
-
-        Variant user_paths_variant = application_settings.get_value ("relocatable-schemas-user-paths");
-        VariantIter entries_iter;
-        user_paths_variant.get ("a{ss}", out entries_iter);
-        string schema_id;
-        string path_spec;
-        while (entries_iter.next ("{ss}", out schema_id, out path_spec))
-            add_relocatable_schema_info (relocatable_schema_paths, schema_id, path_spec);
-    }
-
-    private void create_relocatable_schemas_built_in_paths ()
-    {
-        RelocatableSchemasEnabledMappings enabled_mappings_flags = (RelocatableSchemasEnabledMappings) 
application_settings.get_flags ("relocatable-schemas-enabled-mappings");
-        if (!(RelocatableSchemasEnabledMappings.BUILT_IN in enabled_mappings_flags))
-            return;
-
-        string [,] known_mappings = ConfigurationEditor.known_mappings;
-        for (int i = 0; i < known_mappings.length [0]; i++)
-            add_relocatable_schema_info (relocatable_schema_paths, known_mappings [i,0], known_mappings 
[i,1]);
-    }
-
-    private void parse_relocatable_schemas_startup_paths ()
-    {
-        RelocatableSchemasEnabledMappings enabled_mappings_flags = (RelocatableSchemasEnabledMappings) 
application_settings.get_flags ("relocatable-schemas-enabled-mappings");
-        if (!(RelocatableSchemasEnabledMappings.STARTUP in enabled_mappings_flags))
-            return;
-
-        startup_relocatable_schema_paths.foreach ((schema_id, paths) => {
-                paths.foreach ((path_spec) => add_relocatable_schema_info (relocatable_schema_paths, 
schema_id, path_spec));
-            });
-    }
-
     private void add_relocatable_schema_info (HashTable<string, GenericSet<string>> map, string schema_id, 
...)
     {
         GenericSet<string>? schema_info = map.lookup (schema_id);
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index fd0d045..2127c04 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -22,7 +22,7 @@ class DConfWindow : ApplicationWindow
 {
     private string current_path = "/";
 
-    private SettingsModel model;
+    private SettingsModel model = new SettingsModel ();
     private ModificationsHandler modifications_handler;
 
     private int window_width = 0;
@@ -70,25 +70,11 @@ class DConfWindow : ApplicationWindow
     {
         install_action_entries ();
 
-        model = new SettingsModel (settings);
-        pathbar.model = model;
         modifications_handler = new ModificationsHandler (model);
         revealer.modifications_handler = modifications_handler;
         browser_view.modifications_handler = modifications_handler;
         modifications_handler_reload_handler = modifications_handler.reload.connect (invalidate_popovers);
 
-        model.paths_changed.connect ((_model, modified_path_specs, internal_changes) => {
-                bool need_reload = browser_view.check_reload (current_path);
-                if (need_reload)
-                {
-                    if (internal_changes)
-                        reload_view (false);
-                    else
-                        browser_view.show_hard_reload_warning ();
-                }
-                pathbar.set_path (current_path); // update "ghost" status
-            });
-
         behaviour_changed_handler = settings.changed ["behaviour"].connect_after (invalidate_popovers);
         settings.bind ("behaviour", modifications_handler, "behaviour", 
SettingsBindFlags.GET|SettingsBindFlags.NO_SENSITIVITY);
 
@@ -183,7 +169,8 @@ class DConfWindow : ApplicationWindow
                 first_path = settings.get_string ("saved-view");
         }
 
-        model.finalize_model ();
+        pathbar.model = model;
+        prepare_model ();
 
         if (first_path == null)
             first_path = "/";
@@ -191,6 +178,49 @@ class DConfWindow : ApplicationWindow
         request_path ((!) first_path, true, strict);
     }
 
+    private void prepare_model ()
+    {
+        settings.changed ["relocatable-schemas-user-paths"].connect (() => {
+                RelocatableSchemasEnabledMappings enabled_mappings_flags = 
(RelocatableSchemasEnabledMappings) settings.get_flags ("relocatable-schemas-enabled-mappings");
+                if (!(RelocatableSchemasEnabledMappings.USER in enabled_mappings_flags))
+                    return;
+
+                model.refresh_relocatable_schema_paths (true,
+                                                        RelocatableSchemasEnabledMappings.BUILT_IN in 
enabled_mappings_flags,
+                                                        RelocatableSchemasEnabledMappings.INTERNAL in 
enabled_mappings_flags,
+                                                        RelocatableSchemasEnabledMappings.STARTUP  in 
enabled_mappings_flags,
+                                                        settings.get_value 
("relocatable-schemas-user-paths"));
+            });
+        settings.changed ["relocatable-schemas-enabled-mappings"].connect (() => {
+                RelocatableSchemasEnabledMappings enabled_mappings_flags = 
(RelocatableSchemasEnabledMappings) settings.get_flags ("relocatable-schemas-enabled-mappings");
+                model.refresh_relocatable_schema_paths (RelocatableSchemasEnabledMappings.USER     in 
enabled_mappings_flags,
+                                                        RelocatableSchemasEnabledMappings.BUILT_IN in 
enabled_mappings_flags,
+                                                        RelocatableSchemasEnabledMappings.INTERNAL in 
enabled_mappings_flags,
+                                                        RelocatableSchemasEnabledMappings.STARTUP  in 
enabled_mappings_flags,
+                                                        settings.get_value 
("relocatable-schemas-user-paths"));
+            });
+
+        RelocatableSchemasEnabledMappings enabled_mappings_flags = (RelocatableSchemasEnabledMappings) 
settings.get_flags ("relocatable-schemas-enabled-mappings");
+        model.refresh_relocatable_schema_paths (RelocatableSchemasEnabledMappings.USER     in 
enabled_mappings_flags,
+                                                RelocatableSchemasEnabledMappings.BUILT_IN in 
enabled_mappings_flags,
+                                                RelocatableSchemasEnabledMappings.INTERNAL in 
enabled_mappings_flags,
+                                                RelocatableSchemasEnabledMappings.STARTUP  in 
enabled_mappings_flags,
+                                                settings.get_value ("relocatable-schemas-user-paths"));
+        model.finalize_model ();
+
+        model.paths_changed.connect ((_model, modified_path_specs, internal_changes) => {
+                bool need_reload = browser_view.check_reload (current_path);
+                if (need_reload)
+                {
+                    if (internal_changes)
+                        reload_view (false);
+                    else
+                        browser_view.show_hard_reload_warning ();
+                }
+                pathbar.set_path (current_path); // update "ghost" status
+            });
+    }
+
     /*\
     * * Window management callbacks
     \*/


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