[dconf-editor] Add "copy" shortcut.



commit 80e8da78119cfe3350a792a5085046ac89a7c796
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Wed Nov 25 14:51:21 2015 +0100

    Add "copy" shortcut.

 editor/dconf-window.vala     |   21 ++++++++++++++++-----
 editor/key-list-box-row.vala |   23 ++++++++++++++++++-----
 2 files changed, 34 insertions(+), 10 deletions(-)
---
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index 45d013f..517e91d 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -219,12 +219,23 @@ class DConfWindow : ApplicationWindow
     [GtkCallback]
     private bool on_key_press_event (Widget widget, Gdk.EventKey event)     // TODO better?
     {
-        if (Gdk.keyval_name (event.keyval) == "f" && (event.state & Gdk.ModifierType.CONTROL_MASK) != 0)    
// TODO better?
+        if ((event.state & Gdk.ModifierType.CONTROL_MASK) != 0)
         {
-            if (bookmarks_button.active)
-                bookmarks_button.active = false;
-            search_bar.set_search_mode (!search_bar.get_search_mode ());
-            return true;
+            switch (Gdk.keyval_name (event.keyval))
+            {
+                case "f":
+                    if (bookmarks_button.active)
+                        bookmarks_button.active = false;
+                    search_bar.set_search_mode (!search_bar.get_search_mode ());
+                    return true;
+                case "c":
+                    ListBoxRow? selected_row = (ListBoxRow) key_list_box.get_selected_row ();
+                    if (selected_row != null)
+                        ((KeyListBoxRow) ((!) selected_row).get_child ()).copy_text ();
+                    return true;
+                default:
+                    break;  // TODO report bug for making <ctrl>v work?
+            }
         }
 
         if (bookmarks_button.active)        // TODO open bug
diff --git a/editor/key-list-box-row.vala b/editor/key-list-box-row.vala
index 5d93324..06a6fa6 100644
--- a/editor/key-list-box-row.vala
+++ b/editor/key-list-box-row.vala
@@ -18,7 +18,7 @@
 using Gtk;
 
 [GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/key-list-box-row.ui")]
-private class KeyListBoxRow : EventBox
+private abstract class KeyListBoxRow : EventBox
 {
     protected Window window { get; set; }
     protected Notification notification = new Notification (_("Copied to clipboard"));
@@ -55,8 +55,11 @@ private class KeyListBoxRow : EventBox
         return false;
     }
 
-    protected void copy_text (string text)
+    protected abstract string get_text ();
+    public void copy_text ()
     {
+        string text = get_text ();
+
         // clipboard
         Gdk.Display? display = Gdk.Display.get_default ();
         if (display == null)
@@ -69,7 +72,7 @@ private class KeyListBoxRow : EventBox
         GLib.Application application = window.get_application ();   // TODO better; but "of course", after 
the window is added to the application...
         if (notification_active == true)
         {
-            Source.remove (notification_number);
+            Source.remove (notification_number);  // FIXME doesn't work [as expected], the timeout runs 
until its end, and withdraws the notification then
             notification_active = false;
         }
 
@@ -114,10 +117,15 @@ private class KeyListBoxRowEditableNoSchema : KeyListBoxRow
         key.value_changed.connect (() => { key_value_label.label = cool_text_value (key); if 
(nullable_popover != null) nullable_popover.destroy (); });
     }
 
+    protected override string get_text ()
+    {
+        return key.full_name + " " + key.value.print (false);
+    }
+
     protected override bool generate_popover (ContextPopover popover)
     {
         popover.new_action ("customize", () => { show_dialog (); });
-        popover.new_action ("copy", () => { copy_text (key.full_name + " " + key.value.print (false)); });
+        popover.new_action ("copy", () => { copy_text (); });
 
         if (key.type_string == "b" || key.type_string == "mb")
         {
@@ -149,10 +157,15 @@ private class KeyListBoxRowEditable : KeyListBoxRow
         key.value_changed.connect (() => { update (); if (nullable_popover != null) nullable_popover.destroy 
(); });
     }
 
+    protected override string get_text ()
+    {
+        return key.schema_id + " " + key.name + " " + key.value.print (false);
+    }
+
     protected override bool generate_popover (ContextPopover popover)
     {
         popover.new_action ("customize", () => { show_dialog (); });
-        popover.new_action ("copy", () => { copy_text (key.schema_id + " " + key.name + " " + 
key.value.print (false)); });
+        popover.new_action ("copy", () => { copy_text (); });
 
         if (key.type_string == "b" || key.type_string == "<enum>" || key.type_string == "mb")
         {


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