[dconf-editor] Privatize get_directory().



commit ec999d7401b77aa53256060f2e2511c483d4013c
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Fri Jan 19 06:47:54 2018 +0100

    Privatize get_directory().

 editor/dconf-model.vala     |   48 ++++++++++++++++++++++++++++++++++++++++++-
 editor/dconf-window.vala    |   29 +++++++++----------------
 editor/pathbar.vala         |    4 +-
 editor/registry-search.vala |    2 +-
 4 files changed, 61 insertions(+), 22 deletions(-)
---
diff --git a/editor/dconf-model.vala b/editor/dconf-model.vala
index 4dee17f..802d719 100644
--- a/editor/dconf-model.vala
+++ b/editor/dconf-model.vala
@@ -87,8 +87,22 @@ public class SettingsModel : Object
     * * Objects requests
     \*/
 
-    public Directory? get_directory (string path)
+    public Directory get_root_directory ()
     {
+        Directory root = new Directory ("/", "/");
+        uint schemas_count = 0;
+        uint subpaths_count = 0;
+        source_manager.cached_schemas.get_content_count ("/", out schemas_count, out subpaths_count);
+        if (schemas_count > 1)
+            root.warning_multiple_schemas = true;
+        return root;
+    }
+
+    private Directory? get_directory (string path)
+    {
+        if (path == "/")
+            return get_root_directory ();
+
         Directory? dir = null;
         uint schemas_count = 0;
         uint subpaths_count = 0;
@@ -338,6 +352,38 @@ public class SettingsModel : Object
     }
 
     /*\
+    * * Directory methods
+    \*/
+
+    public bool get_warning_multiple_schemas (string path)
+    {
+        Directory? dir = get_directory (path);
+        if (dir == null)
+            assert_not_reached ();
+        return ((!) dir).warning_multiple_schemas;
+    }
+
+    public bool directory_is_ghost (string path)
+    {
+        if (path == "/")
+            return false;
+        return get_directory (path) == null;
+    }
+
+    public string get_fallback_path (string path, out bool warning_multiple_schemas)
+    {
+        Directory? dir = get_directory (path);
+        string fallback_path = path;
+        while (dir == null)
+        {
+            fallback_path = get_parent_path (fallback_path);
+            dir = get_directory (fallback_path);
+        }
+        warning_multiple_schemas = ((!) dir).warning_multiple_schemas;
+        return fallback_path;
+    }
+
+    /*\
     * * Key value methods
     \*/
 
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index 168b08f..610ddbf 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -410,7 +410,7 @@ class DConfWindow : ApplicationWindow
 
     private void reload_object (/* SimpleAction action, Variant? path_variant */)
     {
-        request_object_path (current_path);
+        request_object_path (current_path, false);
     }
 
     private void reload_search (/* SimpleAction action, Variant? path_variant */)
@@ -461,25 +461,17 @@ class DConfWindow : ApplicationWindow
 
     private void request_folder_path (string full_name, string selected_or_empty = "", bool notify_missing = 
true)
     {
-        Directory? found_object = model.get_directory (full_name);
-        bool not_found = found_object == null;
+        bool warning_multiple_schemas;
+        string fallback_path = model.get_fallback_path (full_name, out warning_multiple_schemas);
 
-        string fallback_path = full_name;
-        while (found_object == null)
-        {
-            fallback_path = SettingsModel.get_parent_path (fallback_path);
-            found_object = model.get_directory (fallback_path);
-        }
-        if (not_found && notify_missing)
+        if (notify_missing && (fallback_path != full_name))
             cannot_find_folder (full_name); // do not place after, full_name is in some cases changed by 
set_directory()...
 
-        GLib.ListStore? key_model = model.get_children (((!) found_object).full_name);
+        GLib.ListStore? key_model = model.get_children (fallback_path);
         if (key_model != null)
         {
-            browser_view.prepare_browse_view ((!) key_model,
-                                              current_path.has_prefix (((!) found_object).full_name),
-                                              ((!) found_object).warning_multiple_schemas);
-            update_current_path (((!) found_object).full_name);
+            browser_view.prepare_browse_view ((!) key_model, current_path.has_prefix (fallback_path), 
warning_multiple_schemas);
+            update_current_path (fallback_path);
 
             if (selected_or_empty == "")
                 browser_view.select_row (pathbar.get_selected_child (fallback_path));
@@ -506,8 +498,9 @@ class DConfWindow : ApplicationWindow
         }
         else
         {
-            Directory parent_directory = (!) model.get_directory (SettingsModel.get_parent_path (full_name));
-            browser_view.prepare_properties_view ((Key) found_object, current_path == 
SettingsModel.get_parent_path (full_name), parent_directory.warning_multiple_schemas);
+            browser_view.prepare_properties_view ((Key) found_object,
+                                                  current_path == SettingsModel.get_parent_path (full_name),
+                                                  model.get_warning_multiple_schemas 
(SettingsModel.get_parent_path (full_name)));
             update_current_path (strdup (full_name));
         }
 
@@ -864,7 +857,7 @@ class DConfWindow : ApplicationWindow
     }
     private void cannot_find_folder (string full_name)
     {
-        show_notification (_("Cannot find folder “%s”.").printf (full_name));
+        show_notification (_("Folder “%s” doesn’t exist anymore.").printf (full_name));
     }
 
     [GtkCallback]
diff --git a/editor/pathbar.vala b/editor/pathbar.vala
index 15a77a2..d8752b4 100644
--- a/editor/pathbar.vala
+++ b/editor/pathbar.vala
@@ -57,7 +57,7 @@ public class PathBar : Box
                         complete_path += "/";
                         if (last_item != null)
                         {
-                            bool is_ghost = model.get_directory (complete_path) == null;
+                            bool is_ghost = model.directory_is_ghost (complete_path);
                             set_is_ghost ((!) last_item, is_ghost);
                             last_item = null;
                             set_is_ghost (child, is_ghost);
@@ -110,7 +110,7 @@ public class PathBar : Box
                 foreach (string item in split [0:split.length - 1])
                 {
                     complete_path += item + "/";
-                    bool is_ghost = model.get_directory (complete_path) == null;
+                    bool is_ghost = model.directory_is_ghost (complete_path);
                     set_is_ghost (add_path_bar_item (item, complete_path, true, !is_key_path && (index == 
split.length - 2)), is_ghost);
                     set_is_ghost (add_slash_label (), is_ghost);
                     index++;
diff --git a/editor/registry-search.vala b/editor/registry-search.vala
index d9b391b..0077763 100644
--- a/editor/registry-search.vala
+++ b/editor/registry-search.vala
@@ -518,7 +518,7 @@ class RegistrySearch : Grid, BrowsableView
 
     private void start_global_search (SettingsModel model, string current_path, string term)
     {
-        search_nodes.push_head ((!) model.get_directory ("/"));
+        search_nodes.push_head (model.get_root_directory ());
         resume_global_search (current_path, term);
     }
 


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