[dconf-editor] Fix focus in RegistryInfo.



commit 382806e30a2d6177f08c0ce1865723f6772da356
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Sun Sep 4 01:43:51 2016 +0200

    Fix focus in RegistryInfo.

 editor/dconf-editor.css   |    2 +-
 editor/dconf-window.vala  |    2 +-
 editor/property-row.ui    |    1 -
 editor/registry-info.vala |   39 ++++++++++++++++++++++++++++++++++++---
 editor/registry-view.vala |   15 ++++++++++-----
 5 files changed, 48 insertions(+), 11 deletions(-)
---
diff --git a/editor/dconf-editor.css b/editor/dconf-editor.css
index 5bb5e3c..5987e18 100644
--- a/editor/dconf-editor.css
+++ b/editor/dconf-editor.css
@@ -196,7 +196,7 @@ list.properties-list {
   background-color:initial;
   padding:0.3em 0;
 }
-list.properties-list > row {
+list.properties-list > row {    /* TODO what? */
   padding:0 6px; /* align on headerbar's buttons */
 }
 
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index 2d0264a..d8f932e 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -320,7 +320,7 @@ class DConfWindow : ApplicationWindow
                     return true;
                 case "c":
                     registry_view.discard_row_popover (); // TODO avoid duplicate get_selected_row () call
-                    string? selected_row_text = registry_view.get_selected_row_text ();
+                    string? selected_row_text = registry_view.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/property-row.ui b/editor/property-row.ui
index 294d22f..8cf3bd1 100644
--- a/editor/property-row.ui
+++ b/editor/property-row.ui
@@ -3,7 +3,6 @@
   <!-- interface-requires gtk+ 3.0 -->
   <template class="PropertyRow" parent="GtkListBoxRow">
     <property name="visible">True</property>
-    <property name="can-focus">False</property>
     <child>
       <object class="GtkGrid" id="grid">
         <property name="visible">True</property>
diff --git a/editor/registry-info.vala b/editor/registry-info.vala
index d22e0bf..45392c8 100644
--- a/editor/registry-info.vala
+++ b/editor/registry-info.vala
@@ -101,7 +101,6 @@ class RegistryInfo : Grid
         label.xalign = 0;
         label.yalign = 0;
         label.wrap = true;
-        label.selectable = true;
         label.max_width_chars = 42;
         label.width_chars = 42;
         label.hexpand = true;
@@ -128,10 +127,11 @@ class RegistryInfo : Grid
         if (has_schema)
         {
             Switch custom_value_switch = new Switch ();
+            custom_value_switch.set_can_focus (false);
             custom_value_switch.halign = Align.START;
             custom_value_switch.hexpand = true;
             custom_value_switch.show ();
-            add_row_from_widget (_("Use default value"), custom_value_switch, null);
+            add_switch_row (_("Use default value"), custom_value_switch);
 
             custom_value_switch.bind_property ("active", key_editor_child, "sensitive", 
BindingFlags.SYNC_CREATE | BindingFlags.INVERT_BOOLEAN);
 
@@ -237,6 +237,17 @@ class RegistryInfo : Grid
             return Key.cool_text_value_from_variant (key.value, key.type_string);
     }
 
+    public string? get_copy_text ()
+    {
+        Widget? focused_row = properties_list_box.get_focus_child ();
+        if (focused_row == null)
+            return null;
+        else if ((!) focused_row is PropertyRow)
+            return ((PropertyRow) (!) focused_row).get_copy_text ();
+        else    // separator
+            return null;
+    }
+
     /*\
     * * Rows creation
     \*/
@@ -246,6 +257,14 @@ class RegistryInfo : Grid
         properties_list_box.add (new PropertyRow.from_label (property_name, property_value));
     }
 
+    private void add_switch_row (string property_name, Switch custom_value_switch)
+    {
+        PropertyRow row = new PropertyRow.from_widgets (property_name, custom_value_switch, null);
+        ulong default_value_row_activate_handler = row.activate.connect (() => 
custom_value_switch.set_active (!custom_value_switch.get_active ()));
+        row.destroy.connect (() => row.disconnect (default_value_row_activate_handler));
+        properties_list_box.add (row);
+    }
+
     private void add_row_from_widget (string property_name, Widget widget, string? type)
     {
         properties_list_box.add (new PropertyRow.from_widgets (property_name, widget, type != null ? 
add_warning ((!) type) : null));
@@ -263,6 +282,7 @@ class RegistryInfo : Grid
         ListBoxRow row = new ListBoxRow ();
         row.add (separator);
         row.set_sensitive (false);
+/* TODO could be selected by down arrow        row.focus.connect ((direction) => { row.move_focus 
(direction); return false; }); */
         row.show ();
         properties_list_box.add (row);
     }
@@ -300,16 +320,18 @@ private class PropertyRow : ListBoxRow
     [GtkChild] private Grid grid;
     [GtkChild] private Label name_label;
 
+    private Widget? value_widget = null;
+
     public PropertyRow.from_label (string property_name, string property_value)
     {
         name_label.set_text (property_name);
 
         Label value_label = new Label (property_value);
+        value_widget = value_label;
         value_label.valign = Align.START;
         value_label.xalign = 0;
         value_label.yalign = 0;
         value_label.wrap = true;
-        value_label.selectable = true;
         value_label.max_width_chars = 42;
         value_label.width_chars = 42;
         value_label.show ();
@@ -320,6 +342,9 @@ private class PropertyRow : ListBoxRow
     {
         name_label.set_text (property_name);
 
+        if (widget is Label)    // TODO handle other rows
+            value_widget = widget;
+
         grid.attach (widget, 1, 0, 1, 1);
         widget.valign = Align.CENTER;
 
@@ -332,4 +357,12 @@ private class PropertyRow : ListBoxRow
             grid.attach ((!) warning, 0, 1, 2, 1);
         }
     }
+
+    public string? get_copy_text ()
+    {
+        if (value_widget != null)
+            return ((Label) (!) value_widget).get_label ();
+        else
+            return null;
+    }
 }
diff --git a/editor/registry-view.vala b/editor/registry-view.vala
index 8be9d9b..ace5f5a 100644
--- a/editor/registry-view.vala
+++ b/editor/registry-view.vala
@@ -462,13 +462,18 @@ class RegistryView : Grid, PathElement
         return true;
     }
 
-    public string? get_selected_row_text ()
+    public string? get_copy_text ()
     {
-        ListBoxRow? selected_row = key_list_box.get_selected_row ();
-        if (selected_row == null)
-            return null;
+        if (stack.get_visible_child_name () != "browse-view")
+            return properties_view.get_copy_text ();
         else
-            return ((ClickableListBoxRow) ((!) selected_row).get_child ()).get_text ();
+        {
+            ListBoxRow? selected_row = key_list_box.get_selected_row ();
+            if (selected_row == null)
+                return null;
+            else
+                return ((ClickableListBoxRow) ((!) selected_row).get_child ()).get_text ();
+        }
     }
 
     public void discard_row_popover ()


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