[dconf-editor] Allow ghosts on small screens.



commit 70873d55fd39d9a388b54f84a5d093afe56552b0
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Thu Oct 18 21:03:07 2018 +0200

    Allow ghosts on small screens.

 editor/dconf-window.vala  | 10 ++++++++--
 editor/short-pathbar.vala | 45 ++++++++++++++++++++++++++++++++++++---------
 2 files changed, 44 insertions(+), 11 deletions(-)
---
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index 8473895..a77d64d 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -537,6 +537,7 @@ private class DConfWindow : ApplicationWindow
     \*/
 
     private SimpleAction open_path_action;
+    private SimpleAction disabled_state_action;
 
     private SimpleAction reload_search_action;
     private bool reload_search_next = true;
@@ -547,6 +548,9 @@ private class DConfWindow : ApplicationWindow
         action_group.add_action_entries (ui_action_entries, this);
         insert_action_group ("ui", action_group);
 
+        disabled_state_action = (SimpleAction) action_group.lookup_action ("disabled-state");
+        disabled_state_action.set_enabled (false);
+
         open_path_action = (SimpleAction) action_group.lookup_action ("open-path");
 
         reload_search_action = (SimpleAction) action_group.lookup_action ("reload-search");
@@ -555,8 +559,9 @@ private class DConfWindow : ApplicationWindow
 
     private const GLib.ActionEntry [] ui_action_entries =
     {
-        { "empty",      empty, "*" },
-        { "empty-null", empty },
+        { "empty",          empty, "*" },
+        { "empty-null",     empty },
+        { "disabled-state", empty, "(sq)", "('',uint16 65535)" },
 
         { "notify-folder-emptied", notify_folder_emptied, "s" },
         { "notify-object-deleted", notify_object_deleted, "(sq)" },
@@ -1204,6 +1209,7 @@ private class DConfWindow : ApplicationWindow
 
         Variant variant = new Variant ("(sq)", path, (type == ViewType.FOLDER) || (type == ViewType.CONFIG) 
? ModelUtils.folder_context_id : ModelUtils.undefined_context_id);
         open_path_action.set_state (variant);
+        disabled_state_action.set_state (variant);
     }
 
     private void invalidate_popovers_with_ui_reload ()
diff --git a/editor/short-pathbar.vala b/editor/short-pathbar.vala
index 0bfbb5e..10f1634 100644
--- a/editor/short-pathbar.vala
+++ b/editor/short-pathbar.vala
@@ -20,6 +20,8 @@ using Gtk;
 [GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/short-pathbar.ui")]
 private class ShortPathbar : Grid, Pathbar
 {
+    private string non_ghost_path = "";
+
     private string complete_path = "";
     internal string get_complete_path ()
     {
@@ -59,11 +61,34 @@ private class ShortPathbar : Grid, Pathbar
 
         if (!path.has_suffix ("/")
          || !complete_path.has_prefix (path))
+        {
             complete_path = path;
+            non_ghost_path = path;
+        }
 
         view_label.set_text (ModelUtils.get_name (path));
+        update_menu ();
+    }
 
-        GLib.Menu menu = new GLib.Menu ();
+    internal void update_ghosts (string _non_ghost_path, bool is_search)
+    {
+        non_ghost_path = _non_ghost_path;
+        update_menu ();
+    }
+
+    /*\
+    * * menu creation
+    \*/
+
+    private void update_menu ()
+    {
+        GLib.Menu menu;
+        _update_menu (complete_path, non_ghost_path, out menu);
+        menu_button.set_menu_model (menu);
+    }
+    private static void _update_menu (string complete_path, string non_ghost_path, out GLib.Menu menu)
+    {
+        menu = new GLib.Menu ();
         GLib.Menu section = new GLib.Menu ();
 
         string [] split = complete_path.split ("/", /* max tokens disabled */ 0);
@@ -83,19 +108,26 @@ private class ShortPathbar : Grid, Pathbar
         {
             tmp_path += item + "/";
             Variant variant = new Variant ("(sq)", tmp_path, ModelUtils.folder_context_id);
-            menu.append (item, "ui.open-path(" + variant.print (true) + ")");  // TODO append or prepend?
+            if (non_ghost_path.has_prefix (tmp_path))
+                menu.append (item, "ui.open-path(" + variant.print (true) + ")");  // TODO append or prepend?
+            else
+                menu.append (item, "ui.disabled-state(" + variant.print (true) + ")");  // TODO append or 
prepend?
         }
 
         // key or nothing
         if (last != "")
         {
             bool is_folder = ModelUtils.is_folder_path (complete_path);
-            uint16 context_id = is_folder ? ModelUtils.folder_context_id : ModelUtils.undefined_context_id;
             tmp_path += last;
             if (is_folder)
                 tmp_path += "/";
+
+            uint16 context_id = is_folder ? ModelUtils.folder_context_id : ModelUtils.undefined_context_id;
             Variant variant = new Variant ("(sq)", tmp_path, context_id);
-            menu.append (last, "ui.open-path(" + variant.print (true) + ")");
+            if (non_ghost_path.has_prefix (tmp_path))   // FIXME problem if key and folder named similarly
+                menu.append (last, "ui.open-path(" + variant.print (true) + ")");
+            else
+                menu.append (last, "ui.disabled-state(" + variant.print (true) + ")");  // TODO append or 
prepend?
         }
 
         section.freeze ();
@@ -109,10 +141,5 @@ private class ShortPathbar : Grid, Pathbar
         menu.append_section (null, section);
 
         menu.freeze ();
-        menu_button.set_menu_model (menu);
-    }
-
-    internal void update_ghosts (string non_ghost_path, bool is_search)
-    {
     }
 }


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