[dconf-editor] Move path-related action in pathbar.



commit 5d243e467533e7e62650cb4856ad2f4e477a2421
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Wed Dec 13 17:03:54 2017 +0100

    Move path-related action in pathbar.

 editor/dconf-editor.css      |    2 +-
 editor/dconf-model.vala      |    9 +++++
 editor/dconf-window.vala     |   17 ++++++++-
 editor/key-list-box-row.vala |    4 +-
 editor/pathbar-item.ui       |    1 +
 editor/pathbar.ui            |   14 ++------
 editor/pathbar.vala          |   73 ++++++++++++++++++++++++++++++++++++++----
 7 files changed, 98 insertions(+), 22 deletions(-)
---
diff --git a/editor/dconf-editor.css b/editor/dconf-editor.css
index c6a3b33..b413d3e 100644
--- a/editor/dconf-editor.css
+++ b/editor/dconf-editor.css
@@ -151,7 +151,7 @@
 * * pathbar
 \*/
 
-.root-button {
+.root-button > label {
   background-image:-gtk-icontheme("ca.desrt.dconf-editor-symbolic");
   background-position:center;
   background-size:1.1rem;
diff --git a/editor/dconf-model.vala b/editor/dconf-model.vala
index 7012828..f6099ee 100644
--- a/editor/dconf-model.vala
+++ b/editor/dconf-model.vala
@@ -40,6 +40,7 @@ public class Directory : SettingObject
 public abstract class Key : SettingObject
 {
     public abstract string descriptor { owned get; }
+    public abstract string get_copy_text ();
 
     public string type_string { get; protected set; default = "*"; }
     public Variant properties { owned get; protected set; }
@@ -247,6 +248,10 @@ public abstract class Key : SettingObject
 public class DConfKey : Key
 {
     public override string descriptor { owned get { return full_name; } }
+    public override string get_copy_text ()
+    {
+        return is_ghost ? _("%s (key erased)").printf (full_name) : descriptor + " " + value.print (false);
+    }
 
     private DConf.Client client;
 
@@ -333,6 +338,10 @@ public class GSettingsKey : Key
             return @"$schema_id $name";
         }
     }
+    public override string get_copy_text ()
+    {
+        return descriptor + " " + value.print (false);
+    }
 
     public GLib.Settings settings { get; construct; }
 
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index cfa0141..f610c6a 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -365,9 +365,16 @@ class DConfWindow : ApplicationWindow
         GLib.Menu section;
 
         GLib.Menu menu = new GLib.Menu ();
-        menu.append (_("Copy current path"), "app.copy(\"" + current_path.escape (null).escape (null) + 
"\")");
 
-        if (!SettingsModel.is_key_path (current_path))
+        if (SettingsModel.is_key_path (current_path))   // mainly here for ensuring menu is never empty
+        {
+            SettingObject? object = model.get_object (current_path);
+            if (object != null && (!) object is Key)
+                menu.append (_("Copy descriptor"), "app.copy(\"" + ((Key) (!) object).get_copy_text () + 
"\")");   // TODO what happens on multiple schemas defining one key?..
+            else    // fallback that should never be reached
+                menu.append (_("Copy current path"), "app.copy(\"" + current_path.escape (null).escape 
(null) + "\")");
+        }
+        else
         {
             section = new GLib.Menu ();
             section.append (_("Reset visible keys"), "win.reset-visible");
@@ -516,6 +523,12 @@ class DConfWindow : ApplicationWindow
                 case "c":
                     browser_view.discard_row_popover (); // TODO avoid duplicate get_selected_row () call
                     string? selected_row_text = browser_view.get_copy_text ();
+                    if (selected_row_text == null)
+                    {
+                        SettingObject? setting_object = model.get_object (current_path);
+                        if (setting_object != null && (!) setting_object is Key)
+                            selected_row_text = ((Key) (!) setting_object).get_copy_text ();
+                    }
                     ConfigurationEditor application = (ConfigurationEditor) get_application ();
                     application.copy (selected_row_text == null ? current_path : (!) selected_row_text);
                     return true;
diff --git a/editor/key-list-box-row.vala b/editor/key-list-box-row.vala
index 993f766..bca2489 100644
--- a/editor/key-list-box-row.vala
+++ b/editor/key-list-box-row.vala
@@ -342,7 +342,7 @@ private class KeyListBoxRowEditableNoSchema : KeyListBoxRow
 
     protected override string get_text ()
     {
-        return key.is_ghost ? _("%s (key erased)").printf (key.full_name) : key.descriptor + " " + 
key.value.print (false);
+        return key.get_copy_text ();
     }
 
     protected override bool generate_popover (ContextPopover popover, ModificationsHandler 
modifications_handler)
@@ -479,7 +479,7 @@ private class KeyListBoxRowEditable : KeyListBoxRow
 
     protected override string get_text ()
     {
-        return key.descriptor + " " + key.value.print (false);
+        return key.get_copy_text ();
     }
 
     protected override bool generate_popover (ContextPopover popover, ModificationsHandler 
modifications_handler)
diff --git a/editor/pathbar-item.ui b/editor/pathbar-item.ui
index 0934642..4858233 100644
--- a/editor/pathbar-item.ui
+++ b/editor/pathbar-item.ui
@@ -4,6 +4,7 @@
   <template class="PathBarItem" parent="GtkButton">
     <property name="focus-on-click">False</property>
     <property name="action-name">win.open-path</property>
+    <signal name="clicked" handler="update_cursor"/>
     <child>
       <object class="GtkLabel" id="text_label">
         <property name="visible">True</property>
diff --git a/editor/pathbar.ui b/editor/pathbar.ui
index 1db278d..61e62d5 100644
--- a/editor/pathbar.ui
+++ b/editor/pathbar.ui
@@ -7,19 +7,13 @@
       <class name="pathbar"/>
     </style>
     <child>
-      <object class="GtkButton" id="root_button">
+      <object class="PathBarItem" id="root_button">
         <property name="visible">True</property>
-        <property name="focus-on-click">False</property>
         <property name="action-name">win.open-path</property>
         <property name="action-target">'/'</property>
-        <child>
-          <object class="GtkLabel">
-            <style>
-              <class name="item"/>
-              <class name="root-button"/>
-            </style>
-          </object>
-        </child>
+        <style>
+          <class name="root-button"/>
+        </style>
       </object>
     </child>
   </template>
diff --git a/editor/pathbar.vala b/editor/pathbar.vala
index 56f5037..0fc3326 100644
--- a/editor/pathbar.vala
+++ b/editor/pathbar.vala
@@ -20,7 +20,7 @@ using Gtk;
 [GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/pathbar.ui")]
 public class PathBar : Box, PathElement
 {
-    [GtkChild] private Button root_button;
+    [GtkChild] private PathBarItem root_button;
 
     private string complete_path = "";
 
@@ -55,24 +55,26 @@ public class PathBar : Box, PathElement
                     return;
                 }
 
+                PathBarItem item = (PathBarItem) child;
+
                 if (maintain_all)
                 {
-                    complete_path += ((PathBarItem) child).text_string;
-                    activate_item (child, false);
+                    complete_path += item.text_string;
+                    activate_item (item, false);
                     return;
                 }
 
-                if (child == root_button || (!destroy_all && ((PathBarItem) child).text_string == split [0]))
+                if (item == root_button || (!destroy_all && item.text_string == split [0]))
                 {
                     complete_path += split [0];
                     split = split [1:split.length];
                     if (split.length == 0 || (split.length == 1 && !is_key_path))
                     {
-                        activate_item (child, true);
+                        activate_item (item, true);
                         maintain_all = true;
                     }
                     else
-                        activate_item (child, false);
+                        activate_item (item, false);
                     return;
                 }
 
@@ -146,15 +148,24 @@ public class PathBar : Box, PathElement
         activate_item (path_bar_item, block);   // has to be after add()
     }
 
-    private void activate_item (Widget item, bool state)
+    private void activate_item (PathBarItem item, bool state)
     {
         StyleContext context = item.get_style_context ();
         if (state == context.has_class ("active"))
             return;
         if (state)
+        {
+            item.cursor_type = PathBarItem.CursorType.CONTEXT;
+            item.set_action_name (null);
+            item.set_sensitive (true);  // GAction do not play well with other kind of... reactions
             context.add_class ("active");
+        }
         else
+        {
+            item.cursor_type = PathBarItem.CursorType.POINTER;
+            item.set_action_name ("win.open-path");
             context.remove_class ("active");
+        }
     }
 }
 
@@ -164,6 +175,54 @@ private class PathBarItem : Button
     public string text_string { get; construct; }
     [GtkChild] private Label text_label;
 
+    public enum CursorType {
+        DEFAULT,
+        POINTER,
+        CONTEXT
+    }
+    public CursorType cursor_type { get; set; default = CursorType.POINTER; }
+
+    construct
+    {
+        enter_notify_event.connect (() => { set_new_cursor_type (cursor_type); });
+        leave_notify_event.connect (() => { set_new_cursor_type (CursorType.DEFAULT); });
+    }
+
+    private void set_new_cursor_type (CursorType new_cursor_type)
+    {
+        Gdk.Window? gdk_window = get_window ();
+        Gdk.Display? display = Gdk.Display.get_default ();
+        if (gdk_window == null || display == null)
+            return;
+
+        Gdk.Cursor? cursor = null;
+        switch (new_cursor_type)
+        {
+            case CursorType.DEFAULT: cursor = null; break;
+            case CursorType.POINTER: cursor = new Gdk.Cursor.from_name ((!) display, "pointer"); break;
+            case CursorType.CONTEXT: cursor = new Gdk.Cursor.from_name ((!) display, "context-menu"); break;
+        }
+        ((!) gdk_window).set_cursor (cursor);
+    }
+
+    [GtkCallback]
+    private void update_cursor ()
+    {
+        if (cursor_type != CursorType.CONTEXT)
+        {
+            cursor_type = CursorType.CONTEXT;
+            set_new_cursor_type (cursor_type);
+            return;
+        }
+
+        GLib.Menu menu = new GLib.Menu ();
+        menu.append (_("Copy current path"), "app.copy(\"" + get_action_target_value ().get_string () + 
"\")");
+        menu.freeze ();
+
+        Popover popover_test = new Popover.from_model (this, (MenuModel) menu);
+        popover_test.popup ();
+    }
+
     public PathBarItem (string label)
     {
         Object (text_string: label);


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