[dconf-editor] Introduce OverlayedListRow.



commit f835dc8445c58a7db87936eea3319ef706194760
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Mon Nov 26 18:39:34 2018 +0100

    Introduce OverlayedListRow.

 editor/about-list.vala           | 46 +++++++++++++++++-----------------------
 editor/bookmark.ui               |  2 +-
 editor/bookmarks-list.vala       | 18 ++++++----------
 editor/delayed-setting-view.ui   |  2 +-
 editor/delayed-setting-view.vala |  7 +++++-
 editor/modifications-list.vala   | 11 ----------
 editor/overlayed-list.vala       | 35 +++++++++++++++++++++++++++---
 7 files changed, 65 insertions(+), 56 deletions(-)
---
diff --git a/editor/about-list.vala b/editor/about-list.vala
index a65dc64..7258214 100644
--- a/editor/about-list.vala
+++ b/editor/about-list.vala
@@ -39,29 +39,6 @@ private class AboutList : OverlayedList
         show_apropos ();
     }
 
-    internal string? get_copy_text ()
-    {
-        string? nullable_selection = Clipboard.@get (Gdk.SELECTION_PRIMARY).wait_for_text ();
-        if (nullable_selection != null)
-        {
-             string selection = ((!) nullable_selection).dup ();
-             if (selection != "")
-                return selection;
-        }
-
-        Widget? focus_child = main_list_box.get_focus_child ();
-        if (focus_child == null)
-            return null;
-        Widget? child = ((Bin) (!) focus_child).get_child ();
-        if (child == null || !((!) child is AboutListItem))
-            assert_not_reached ();
-
-        string? copy_text = ((AboutListItem) (!) child).copy_text;
-        if (copy_text == null)
-            return null;
-        return ((!) copy_text).dup ();
-    }
-
     /*\
     * * Action entries
     \*/
@@ -132,10 +109,22 @@ private class AboutList : OverlayedList
     }
 }
 
-private class AboutListItem : Grid
+private class AboutListItem : OverlayedListRow
 {
     public string? copy_text { internal get; construct; default = null; }
 
+    internal override string? get_copy_text ()
+    {
+        string? nullable_selection = Clipboard.@get (Gdk.SELECTION_PRIMARY).wait_for_text ();
+        if (nullable_selection != null)
+        {
+             string selection = ((!) nullable_selection).dup ();
+             if (selection != "" && copy_text != null && selection in (!) copy_text)
+                return selection;
+        }
+        return copy_text;
+    }
+
     internal AboutListItem.from_label (string text, string? css_class = null)
     {
         Object (copy_text: text);
@@ -184,7 +173,10 @@ private class AboutListItem : Grid
     {
         Object (copy_text: text);
 
-        this.orientation = Orientation.VERTICAL;
+        Grid grid = new Grid ();
+        grid.orientation = Orientation.VERTICAL;
+        grid.visible = true;
+        add (grid);
 
         Label label = new Label (title);
         label.visible = true;
@@ -192,7 +184,7 @@ private class AboutListItem : Grid
         label.wrap_mode = Pango.WrapMode.WORD_CHAR;
         label.wrap = true;
         label.get_style_context ().add_class ("bold-label");
-        add (label);
+        grid.add (label);
 
         label = new Label (text);
         label.visible = true;
@@ -202,6 +194,6 @@ private class AboutListItem : Grid
         label.selectable = true;
         label.get_style_context ().add_class ("small-label");
         label.justify = Justification.CENTER;
-        add (label);
+        grid.add (label);
     }
 }
diff --git a/editor/bookmark.ui b/editor/bookmark.ui
index 1236076..3a20da0 100644
--- a/editor/bookmark.ui
+++ b/editor/bookmark.ui
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface domain="dconf-editor">
   <!-- interface-requires gtk+ 3.0 -->
-  <template class="Bookmark" parent="GtkListBoxRow">
+  <template class="Bookmark" parent="OverlayedListRow">
     <child>
       <object class="GtkGrid"> <!-- TODO remove? -->
         <property name="visible">True</property>
diff --git a/editor/bookmarks-list.vala b/editor/bookmarks-list.vala
index 9daba94..0ae94ae 100644
--- a/editor/bookmarks-list.vala
+++ b/editor/bookmarks-list.vala
@@ -109,17 +109,6 @@ private class BookmarksList : OverlayedList
         return give_focus_to_switch;
     }
 
-    internal string? get_copy_text ()
-    {
-        List<weak ListBoxRow> selected_rows = main_list_box.get_selected_rows ();
-        if (selected_rows.length () != 1)
-            return null;
-        ListBoxRow row = selected_rows.nth_data (0);
-        if (!(row is Bookmark))
-            assert_not_reached ();
-        return ((Bookmark) row).bookmark_name;  // FIXME row should keep focus
-    }
-
     internal Variant get_bookmarks_as_variant ()
     {
         return settings.get_value ("bookmarks");
@@ -502,7 +491,7 @@ private class BookmarksList : OverlayedList
 }
 
 [GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/bookmark.ui")]
-private class Bookmark : ListBoxRow
+private class Bookmark : OverlayedListRow
 {
     [GtkChild] private Label bookmark_label;
 
@@ -533,6 +522,11 @@ private class Bookmark : ListBoxRow
             set_detailed_action_name (inactive_action_name);
     }
 
+    internal override string? get_copy_text ()
+    {
+        return bookmark_name;
+    }
+
     /*\
     * * Actions names
     \*/
diff --git a/editor/delayed-setting-view.ui b/editor/delayed-setting-view.ui
index 4fa4085..652acd7 100644
--- a/editor/delayed-setting-view.ui
+++ b/editor/delayed-setting-view.ui
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <!-- interface-requires gtk+ 3.0 -->
-  <template class="DelayedSettingView" parent="GtkListBoxRow">
+  <template class="DelayedSettingView" parent="OverlayedListRow">
     <child>
       <object class="GtkGrid">
         <property name="visible">True</property>
diff --git a/editor/delayed-setting-view.vala b/editor/delayed-setting-view.vala
index e4854b6..f0f5ba4 100644
--- a/editor/delayed-setting-view.vala
+++ b/editor/delayed-setting-view.vala
@@ -18,7 +18,7 @@
 using Gtk;
 
 [GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/delayed-setting-view.ui")]
-private class DelayedSettingView : ListBoxRow
+private class DelayedSettingView : OverlayedListRow
 {
     [GtkChild] private Label key_name_label;
     [GtkChild] private Label key_value_label;
@@ -50,6 +50,11 @@ private class DelayedSettingView : ListBoxRow
         }
     }
 
+    internal override string? get_copy_text ()
+    {
+        return full_name;
+    }
+
     /*\
     * * "Updating" planned value
     \*/
diff --git a/editor/modifications-list.vala b/editor/modifications-list.vala
index d36c930..8b13dc6 100644
--- a/editor/modifications-list.vala
+++ b/editor/modifications-list.vala
@@ -109,17 +109,6 @@ private class ModificationsList : OverlayedList
             main_list_box.select_row ((!) first_row);
     }
 
-    internal string? get_copy_text ()
-    {
-        List<weak ListBoxRow> selected_rows = main_list_box.get_selected_rows ();
-        if (selected_rows.length () != 1)
-            return null;
-        ListBoxRow row = selected_rows.nth_data (0);
-        if (!(row is DelayedSettingView))
-            assert_not_reached ();
-        return ((DelayedSettingView) row).full_name;  // FIXME row should keep focus
-    }
-
     /*\
     * * Updating values; TODO only works for watched keys...
     \*/
diff --git a/editor/overlayed-list.vala b/editor/overlayed-list.vala
index b310541..9bf759d 100644
--- a/editor/overlayed-list.vala
+++ b/editor/overlayed-list.vala
@@ -191,6 +191,32 @@ private abstract class OverlayedList : Overlay, AdaptativeWidget
         adjustment.set_value (adjustment.get_upper ());
     }
 
+    internal string? get_copy_text ()
+    {
+        List<weak ListBoxRow> selected_rows = main_list_box.get_selected_rows ();
+        OverlayedListRow row;
+        switch (selected_rows.length ())
+        {
+            case 0:
+                Widget? focus_child = main_list_box.get_focus_child ();
+                if (focus_child == null)
+                    return null;
+                if (!((!) focus_child is OverlayedListRow))
+                    assert_not_reached ();
+                row = (OverlayedListRow) (!) focus_child;
+                break;
+            case 1:
+                ListBoxRow selected_row = selected_rows.nth_data (0);
+                if (!(selected_row is OverlayedListRow))
+                    assert_not_reached ();
+                row = (OverlayedListRow) selected_row;
+                break;
+            default:
+                return null;
+        }
+        return row.get_copy_text ();  // FIXME row should keep focus
+    }
+
     /*\
     * * selection state
     \*/
@@ -277,9 +303,7 @@ private abstract class OverlayedList : Overlay, AdaptativeWidget
     {
         content_changed_handler = main_list_store.items_changed.connect (on_content_changed);
 
-        destroy.connect (() => {
-                main_list_store.disconnect (content_changed_handler);
-            });
+        destroy.connect (() => main_list_store.disconnect (content_changed_handler));
     }
 
     private void on_content_changed (GLib.ListModel main_list_model, uint position, uint removed, uint added)
@@ -310,3 +334,8 @@ private abstract class OverlayedList : Overlay, AdaptativeWidget
         edit_mode_box.visible = is_editable && n_items != 0;
     }
 }
+
+private abstract class OverlayedListRow : ListBoxRow
+{
+    internal abstract string? get_copy_text ();
+}


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