[dconf-editor] Remove get_text() from ClickableListBoxRow.



commit c8a0f35b392d5d2a33b716275b92c7286d2c6b3c
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Tue Jul 3 14:31:23 2018 +0200

    Remove get_text() from ClickableListBoxRow.

 editor/key-list-box-row.vala | 45 ++++++++++++++------------------------------
 editor/registry-info.vala    |  2 +-
 editor/registry-search.vala  |  2 +-
 editor/registry-view.vala    | 23 ++++++++++++++++++----
 4 files changed, 35 insertions(+), 37 deletions(-)
---
diff --git a/editor/key-list-box-row.vala b/editor/key-list-box-row.vala
index 83cd759..e3fc5c3 100644
--- a/editor/key-list-box-row.vala
+++ b/editor/key-list-box-row.vala
@@ -78,9 +78,6 @@ private abstract class ClickableListBoxRow : EventBox
 {
     public signal void on_popover_disappear ();
 
-    public abstract string get_text ();
-    protected Variant get_text_variant () { return new Variant.string (get_text ()); }
-
     public bool search_result_mode { protected get; construct; default = false; }
 
     public string full_name { get; construct; }
@@ -109,7 +106,10 @@ private abstract class ClickableListBoxRow : EventBox
     \*/
 
     private ContextPopover? nullable_popover = null;
-    protected virtual bool generate_popover (ContextPopover popover) { return false; }      // no popover 
should be created
+    protected virtual bool generate_popover (ContextPopover popover, Variant copy_text_variant) // use 
Variant to sanitize text
+    {
+        return false; // no popover should be created
+    }
 
     public void destroy_popover ()
     {
@@ -128,12 +128,12 @@ private abstract class ClickableListBoxRow : EventBox
         return (nullable_popover != null) && (((!) nullable_popover).visible);
     }
 
-    public void show_right_click_popover (int event_x = (int) (get_allocated_width () / 2.0))
+    public void show_right_click_popover (Variant copy_text_variant, int event_x = (int) 
(get_allocated_width () / 2.0))
     {
         if (nullable_popover == null)
         {
             nullable_popover = new ContextPopover ();
-            if (!generate_popover ((!) nullable_popover))
+            if (!generate_popover ((!) nullable_popover, copy_text_variant))
             {
                 ((!) nullable_popover).destroy ();  // TODO better, again
                 nullable_popover = null;
@@ -169,12 +169,7 @@ private class FolderListBoxRow : ClickableListBoxRow
         folder_name_label.set_text (search_result_mode ? path : label);
     }
 
-    public override string get_text ()
-    {
-        return full_name;
-    }
-
-    protected override bool generate_popover (ContextPopover popover)  // TODO better
+    protected override bool generate_popover (ContextPopover popover, Variant copy_text_variant)  // TODO 
better
     {
         Variant variant = new Variant.string (full_name);
 
@@ -185,7 +180,7 @@ private class FolderListBoxRow : ClickableListBoxRow
         }
 
         popover.new_gaction ("open", "ui.open-folder(" + variant.print (false) + ")");
-        popover.new_gaction ("copy", "app.copy(" + get_text_variant ().print (false) + ")");
+        popover.new_gaction ("copy", "app.copy(" + copy_text_variant.print (false) + ")");
 
         popover.new_section ();
         popover.new_gaction ("recursivereset", "ui.reset-recursive(" + variant.print (false) + ")");
@@ -352,13 +347,7 @@ private class KeyListBoxRowEditableNoSchema : KeyListBoxRow
         }
     }
 
-    protected override string get_text ()
-    {
-        SettingsModel model = modifications_handler.model;
-        return model.get_key_copy_text (full_name, ".dconf");
-    }
-
-    protected override bool generate_popover (ContextPopover popover)
+    protected override bool generate_popover (ContextPopover popover, Variant copy_text_variant)
     {
         SettingsModel model = modifications_handler.model;
         Variant variant_s = new Variant.string (full_name);
@@ -366,7 +355,7 @@ private class KeyListBoxRowEditableNoSchema : KeyListBoxRow
 
         if (model.is_key_ghost (full_name))
         {
-            popover.new_gaction ("copy", "app.copy(" + get_text_variant ().print (false) + ")");
+            popover.new_gaction ("copy", "app.copy(" + copy_text_variant.print (false) + ")");
             return true;
         }
 
@@ -377,7 +366,7 @@ private class KeyListBoxRowEditableNoSchema : KeyListBoxRow
         }
 
         popover.new_gaction ("customize", "ui.open-object(" + variant_ss.print (false) + ")");
-        popover.new_gaction ("copy", "app.copy(" + get_text_variant ().print (false) + ")");
+        popover.new_gaction ("copy", "app.copy(" + copy_text_variant.print (false) + ")");
 
         bool planned_change = modifications_handler.key_has_planned_change (full_name);
         Variant? planned_value = modifications_handler.get_key_planned_value (full_name);
@@ -496,13 +485,7 @@ private class KeyListBoxRowEditable : KeyListBoxRow
         key_value_label.set_label (Key.cool_text_value_from_variant (key_value, type_string));
     }
 
-    protected override string get_text ()
-    {
-        SettingsModel model = modifications_handler.model;
-        return model.get_key_copy_text (full_name, schema_id);
-    }
-
-    protected override bool generate_popover (ContextPopover popover)
+    protected override bool generate_popover (ContextPopover popover, Variant copy_text_variant)
     {
         SettingsModel model = modifications_handler.model;
         Variant variant_s = new Variant.string (full_name);
@@ -517,7 +500,7 @@ private class KeyListBoxRowEditable : KeyListBoxRow
         if (key.error_hard_conflicting_key)
         {
             popover.new_gaction ("detail", "ui.open-object(" + variant_ss.print (false) + ")");
-            popover.new_gaction ("copy", "app.copy(" + get_text_variant ().print (false) + ")");
+            popover.new_gaction ("copy", "app.copy(" + copy_text_variant.print (false) + ")");
             return true; // anything else is value-related, so we are done
         }
 
@@ -526,7 +509,7 @@ private class KeyListBoxRowEditable : KeyListBoxRow
         Variant? planned_value = modifications_handler.get_key_planned_value (full_name);
 
         popover.new_gaction ("customize", "ui.open-object(" + variant_ss.print (false) + ")");
-        popover.new_gaction ("copy", "app.copy(" + get_text_variant ().print (false) + ")");
+        popover.new_gaction ("copy", "app.copy(" + copy_text_variant.print (false) + ")");
 
         if (type_string == "b" || type_string == "<enum>" || type_string == "mb"
             || (
diff --git a/editor/registry-info.vala b/editor/registry-info.vala
index 605c617..f4069b8 100644
--- a/editor/registry-info.vala
+++ b/editor/registry-info.vala
@@ -354,7 +354,7 @@ class RegistryInfo : Grid, BrowsableView
             return Key.cool_text_value_from_variant (model.get_key_value (key), key.type_string);
     }
 
-    public string? get_copy_text ()
+    public string? get_copy_text () // can compile with "private", but is public 2/2
     {
         Widget? focused_row = properties_list_box.get_focus_child ();
         if (focused_row == null)
diff --git a/editor/registry-search.vala b/editor/registry-search.vala
index c551953..1743a0e 100644
--- a/editor/registry-search.vala
+++ b/editor/registry-search.vala
@@ -164,7 +164,7 @@ class RegistrySearch : RegistryList
                 event_x += widget_x;
             }
 
-            row.show_right_click_popover (event_x);
+            row.show_right_click_popover (get_copy_text_variant (row), event_x);
             rows_possibly_with_popover.append (row);
         }
         else
diff --git a/editor/registry-view.vala b/editor/registry-view.vala
index 1ebd62d..9b4aa6a 100644
--- a/editor/registry-view.vala
+++ b/editor/registry-view.vala
@@ -153,19 +153,34 @@ private abstract class RegistryList : Grid, BrowsableView
             row.hide_right_click_popover ();
         else
         {
-            row.show_right_click_popover ();
+            row.show_right_click_popover (get_copy_text_variant (row));
             rows_possibly_with_popover.append (row);
         }
         return true;
     }
 
-    public string? get_copy_text ()
+    public string? get_copy_text () // can compile with "private", but is public 1/2
     {
         ListBoxRow? selected_row = key_list_box.get_selected_row ();
         if (selected_row == null)
             return null;
 
-        return ((ClickableListBoxRow) ((!) selected_row).get_child ()).get_text ();
+        return _get_copy_text ((ClickableListBoxRow) ((!) selected_row).get_child ());
+    }
+    private string _get_copy_text (ClickableListBoxRow row)
+    {
+        if (row is FolderListBoxRow)
+            return row.full_name;
+        // (row is KeyListBoxRow)
+        SettingsModel model = modifications_handler.model;
+        if (row is KeyListBoxRowEditable)
+            return model.get_key_copy_text (row.full_name, ((KeyListBoxRowEditable) row).schema_id);
+        // (row is KeyListBoxRowEditableNoSchema)
+        return model.get_key_copy_text (row.full_name, ".dconf");
+    }
+    protected Variant get_copy_text_variant (ClickableListBoxRow row)
+    {
+        return new Variant.string (_get_copy_text (row));
     }
 
     public void toggle_boolean_key ()
@@ -399,7 +414,7 @@ class RegistryView : RegistryList
                 event_x += widget_x;
             }
 
-            row.show_right_click_popover (event_x);
+            row.show_right_click_popover (get_copy_text_variant (row), event_x);
             rows_possibly_with_popover.append (row);
         }
 


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