[dconf-editor] Rework CLI-given path opening.



commit 0803f4cb93e91711fd910b626dd4badaba97c9f2
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Sat Jan 20 12:08:29 2018 +0100

    Rework CLI-given path opening.

 editor/dconf-model.vala  |   11 +++++++++++
 editor/dconf-window.vala |   11 +++++++----
 2 files changed, 18 insertions(+), 4 deletions(-)
---
diff --git a/editor/dconf-model.vala b/editor/dconf-model.vala
index 2869dde..a017807 100644
--- a/editor/dconf-model.vala
+++ b/editor/dconf-model.vala
@@ -157,6 +157,17 @@ public class SettingsModel : Object
         return get_key_from_path_and_name (key_model, get_name (path));
     }
 
+    public bool path_exists (string path)
+    {
+        if (is_key_path (path))
+        {
+            GLib.ListStore? key_model = get_children (get_parent_path (path));
+            return get_key_from_path_and_name (key_model, get_name (path)) != null;
+        }
+        else
+            return get_directory (path) != null;
+    }
+
     private static Key? get_key_from_path_and_name (GLib.ListStore? key_model, string key_name)
     {
         if (key_model == null)
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index 75870ea..685b278 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -153,11 +153,14 @@ class DConfWindow : ApplicationWindow
         if (first_path == null)
             first_path = "/";
 
-        SettingObject? found_object = model.get_object ((!) first_path, false);
-        if (found_object == null || (!) found_object is Key)
+        if (!SettingsModel.is_key_path ((!) first_path))
+            request_folder_path ((!) first_path);
+        else if (model.path_exists ((!) first_path))
             request_object_path ((!) first_path);
+        else if (model.path_exists ((!) first_path + "/"))
+            request_folder_path ((!) first_path + "/");
         else
-            request_folder_path (((!) found_object).full_name);
+            request_object_path ((!) first_path);
     }
 
     private void prepare_model ()
@@ -862,7 +865,7 @@ class DConfWindow : ApplicationWindow
     }
     private void cannot_find_folder (string full_name)
     {
-        show_notification (_("Folder “%s” doesn’t exist anymore.").printf (full_name));
+        show_notification (_("There’s nothing in requested folder “%s”.").printf (full_name));
     }
 
     [GtkCallback]


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