[dconf-editor] Add copy-path action.



commit 5f0af263a3f9ba067eef261518c9c16ceaf02871
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Sat Jan 20 11:52:58 2018 +0100

    Add copy-path action.

 editor/browser-view.vala     |    9 +++++++++
 editor/dconf-editor.vala     |    5 ++---
 editor/dconf-model.vala      |   19 +++++++++++++++----
 editor/dconf-window.vala     |   41 +++++++++++++++++++++++------------------
 editor/key-list-box-row.vala |    7 ++++---
 editor/pathbar.vala          |    2 +-
 editor/registry-search.vala  |    9 +++++++++
 7 files changed, 63 insertions(+), 29 deletions(-)
---
diff --git a/editor/browser-view.vala b/editor/browser-view.vala
index 040b141..a5a6d85 100644
--- a/editor/browser-view.vala
+++ b/editor/browser-view.vala
@@ -182,6 +182,15 @@ class BrowserView : Grid
         return ((BrowsableView) stack.get_visible_child ()).get_copy_text ();
     }
 
+    public string? get_copy_path_text ()
+    {
+        if (current_view_is_search_results_view ())
+            return search_results_view.get_copy_path_text ();
+
+        warning ("BrowserView get_copy_path_text() called but current view is not search results view.");
+        return null;
+    }
+
     public bool show_row_popover ()
     {
         if (current_view_is_browse_view ())
diff --git a/editor/dconf-editor.vala b/editor/dconf-editor.vala
index 812bc4a..94633ba 100644
--- a/editor/dconf-editor.vala
+++ b/editor/dconf-editor.vala
@@ -250,7 +250,7 @@ class ConfigurationEditor : Gtk.Application
         Gtk.Window.set_default_icon_name ("ca.desrt.dconf-editor");
 
         add_action_entries (action_entries, this);
-//        set_accels_for_action ("win.", { "<Primary><Shift>x" });
+        set_accels_for_action ("ui.copy-path", { "<Primary><Shift>c" });
 
         Gtk.CssProvider css_provider = new Gtk.CssProvider ();
         css_provider.load_from_resource ("/ca/desrt/dconf-editor/ui/dconf-editor.css");
@@ -402,9 +402,8 @@ class ConfigurationEditor : Gtk.Application
     private uint notification_number = 0;
 
     private void copy_cb (SimpleAction action, Variant? gvariant)
+        requires (gvariant != null)
     {
-        if (gvariant == null)
-            return;
         copy (((!) gvariant).get_string ().compress ());
     }
 
diff --git a/editor/dconf-model.vala b/editor/dconf-model.vala
index 802d719..2869dde 100644
--- a/editor/dconf-model.vala
+++ b/editor/dconf-model.vala
@@ -387,11 +387,22 @@ public class SettingsModel : Object
     * * Key value methods
     \*/
 
-    public string get_key_copy_text (Key key)
+    public string get_key_copy_text (string full_name)
     {
-        if (key is GSettingsKey)
-            return key.descriptor + " " + get_key_value (key).print (false);
-        return is_key_ghost ((DConfKey) key) ? _("%s (key erased)").printf (key.full_name) : key.descriptor 
+ " " + get_key_value (key).print (false);
+        Key? key = get_key (full_name);
+        if (key == null)
+            return full_name;
+
+        if (((!) key) is GSettingsKey)
+            return ((!) key).descriptor + " " + get_key_value ((!) key).print (false);
+
+        if (!(((!) key) is DConfKey))
+            assert_not_reached ();
+
+        if (is_key_ghost ((DConfKey) (!) key))
+            return _("%s (key erased)").printf (((!) key).full_name);
+
+        return ((!) key).descriptor + " " + get_key_value ((!) key).print (false);
     }
 
     public Variant get_key_value (Key key)
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index 610ddbf..75870ea 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -371,7 +371,9 @@ class DConfWindow : ApplicationWindow
 
         { "enter-delay-mode", enter_delay_mode },
         { "apply-delayed-settings", apply_delayed_settings },
-        { "dismiss-delayed-settings", dismiss_delayed_settings }
+        { "dismiss-delayed-settings", dismiss_delayed_settings },
+
+        { "copy-path", copy_path }
     };
 
     private void open_folder (SimpleAction action, Variant? path_variant)
@@ -455,6 +457,19 @@ class DConfWindow : ApplicationWindow
         invalidate_popovers ();
     }
 
+    private void copy_path (/* SimpleAction action, Variant? path_variant */)
+    {
+        browser_view.discard_row_popover ();
+
+        if (search_bar.search_mode_enabled)
+        {
+            string selected_row_text = browser_view.get_copy_path_text () ?? current_path;
+            ((ConfigurationEditor) get_application ()).copy (selected_row_text);
+        }
+        else
+            ((ConfigurationEditor) get_application ()).copy (current_path);
+    }
+
     /*\
     * * Directories tree
     \*/
@@ -484,7 +499,7 @@ class DConfWindow : ApplicationWindow
 
     private void request_object_path (string full_name, bool notify_missing = true)
     {
-        SettingObject? found_object = model.get_key (full_name);
+        Key? found_object = model.get_key (full_name);
         if (found_object == null)
         {
             if (notify_missing)
@@ -498,7 +513,7 @@ class DConfWindow : ApplicationWindow
         }
         else
         {
-            browser_view.prepare_properties_view ((Key) found_object,
+            browser_view.prepare_properties_view ((!) 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));
@@ -538,11 +553,8 @@ class DConfWindow : ApplicationWindow
 
         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(\"" + model.get_key_copy_text ((Key) (!) 
object) + "\")");   // 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) + "\")");
+            Variant variant = new Variant.string (model.get_key_copy_text (current_path));
+            menu.append (_("Copy descriptor"), "app.copy(" + variant.print (false) + ")");   // TODO what 
happens on multiple schemas defining one key?..
         }
         else
         {
@@ -688,20 +700,13 @@ class DConfWindow : ApplicationWindow
                     return true;
                 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 = model.get_key_copy_text ((Key) (!) setting_object);
-                    }
+                    if (selected_row_text == null && SettingsModel.is_key_path (current_path))
+                        selected_row_text = model.get_key_copy_text (current_path);
                     ConfigurationEditor application = (ConfigurationEditor) get_application ();
                     application.copy (selected_row_text == null ? current_path : (!) selected_row_text);
                     return true;
-                case "C":
-                    browser_view.discard_row_popover ();
-                    ((ConfigurationEditor) get_application ()).copy (current_path);
-                    return true;
                 case "F1":
                     browser_view.discard_row_popover ();
                     if ((event.state & Gdk.ModifierType.SHIFT_MASK) == 0)
diff --git a/editor/key-list-box-row.vala b/editor/key-list-box-row.vala
index 8213697..d69a715 100644
--- a/editor/key-list-box-row.vala
+++ b/editor/key-list-box-row.vala
@@ -341,7 +341,7 @@ private class KeyListBoxRowEditableNoSchema : KeyListBoxRow
     protected override string get_text ()
     {
         SettingsModel model = modifications_handler.model;
-        return model.get_key_copy_text (key);
+        return model.get_key_copy_text (key.full_name);
     }
 
     protected override bool generate_popover (ContextPopover popover)
@@ -482,7 +482,7 @@ private class KeyListBoxRowEditable : KeyListBoxRow
     protected override string get_text ()
     {
         SettingsModel model = modifications_handler.model;
-        return model.get_key_copy_text (key);
+        return model.get_key_copy_text (key.full_name);
     }
 
     protected override bool generate_popover (ContextPopover popover)
@@ -658,8 +658,9 @@ private class ContextPopover : Popover
 
     public void new_copy_action (string text)
     {
+        Variant variant = new Variant.string (text);
         /* Translators: "copy to clipboard" action in the right-click menu on the list of keys */
-        current_section.append (_("Copy"), "app.copy(\"" + text.escape (null).escape (null) + "\")");
+        current_section.append (_("Copy"), "app.copy(" + variant.print (false) + ")");
     }
 
     public void set_group (string group_name)
diff --git a/editor/pathbar.vala b/editor/pathbar.vala
index d8752b4..1f89ccc 100644
--- a/editor/pathbar.vala
+++ b/editor/pathbar.vala
@@ -229,7 +229,7 @@ private class PathBarItem : Button
             return;
 
         GLib.Menu menu = new GLib.Menu ();
-        menu.append (_("Copy current path"), "app.copy(\"" + get_action_target_value ().get_string () + 
"\")");
+        menu.append (_("Copy current path"), "ui.copy-path"); // or "app.copy(\"" + get_action_target_value 
().get_string () + "\")"
         menu.freeze ();
 
         Popover popover_test = new Popover.from_model (this, (MenuModel) menu);
diff --git a/editor/registry-search.vala b/editor/registry-search.vala
index 0077763..0ffb911 100644
--- a/editor/registry-search.vala
+++ b/editor/registry-search.vala
@@ -307,6 +307,15 @@ class RegistrySearch : Grid, BrowsableView
             return ((ClickableListBoxRow) ((!) selected_row).get_child ()).get_text ();
     }
 
+    public string? get_copy_path_text ()
+    {
+        ListBoxRow? selected_row = key_list_box.get_selected_row ();
+        if (selected_row == null)
+            return null;
+        else
+            return ((!) selected_row).get_action_target_value ().get_string ();
+    }
+
     public void toggle_boolean_key ()
     {
         ListBoxRow? selected_row = (ListBoxRow?) key_list_box.get_selected_row ();


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