[dconf-editor] Make DelayedSettingView a ListBoxRow.



commit b51d74261065aec242321672c5a0177f296ca40a
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Mon Nov 26 16:07:56 2018 +0100

    Make DelayedSettingView a ListBoxRow.

 editor/browser-view.vala           |  51 +--------
 editor/delayed-setting-view.ui     | 206 +++++++++++++++++++------------------
 editor/delayed-setting-view.vala   |   2 +-
 editor/modifications-list.vala     |  21 ++--
 editor/modifications-revealer.vala |  16 +--
 5 files changed, 129 insertions(+), 167 deletions(-)
---
diff --git a/editor/browser-view.vala b/editor/browser-view.vala
index e9d6548..74bc2dc 100644
--- a/editor/browser-view.vala
+++ b/editor/browser-view.vala
@@ -263,55 +263,8 @@ private class BrowserView : Stack, AdaptativeWidget
     }
     private Widget delayed_setting_row_create (Object object)
     {
-        string full_name = ((SimpleSettingObject) object).full_name;
-        uint16 context_id = ((SimpleSettingObject) object).context_id;
-
-        SettingsModel model = modifications_handler.model;
-
-        RegistryVariantDict properties = new RegistryVariantDict.from_aqv (model.get_key_properties 
(full_name, context_id, (uint16) (PropertyQuery.HAS_SCHEMA & PropertyQuery.IS_DEFAULT & 
PropertyQuery.DEFAULT_VALUE & PropertyQuery.KEY_VALUE)));
-
-        bool has_schema;
-        if (!properties.lookup (PropertyQuery.HAS_SCHEMA,               "b",    out has_schema))
-            assert_not_reached ();
-
-        bool has_schema_and_is_default;
-        if (!has_schema)
-            has_schema_and_is_default = false;
-        else if (!properties.lookup (PropertyQuery.IS_DEFAULT,          "b",    out 
has_schema_and_is_default))
-            assert_not_reached ();
-
-        Variant? planned_value = modifications_handler.get_key_planned_value (full_name);
-        string? cool_planned_value = null;
-        if (planned_value != null)
-            cool_planned_value = Key.cool_text_value_from_variant ((!) planned_value);
-
-        string? cool_default_value = null;
-        if (has_schema
-         && !properties.lookup (PropertyQuery.DEFAULT_VALUE,            "s",    out cool_default_value))
-            assert_not_reached ();
-
-        Variant key_value;
-        if (!properties.lookup (PropertyQuery.KEY_VALUE,                "v",    out key_value))
-            assert_not_reached ();
-
-        properties.clear ();
-
-        DelayedSettingView view = new DelayedSettingView (((SimpleSettingObject) object).name,
-                                                          full_name,
-                                                          context_id,
-                                                          has_schema_and_is_default,    // at row creation, 
key is never ghost
-                                                          key_value,
-                                                          cool_planned_value,
-                                                          cool_default_value);
-
-        ListBoxRow wrapper = new ListBoxRow ();
-        wrapper.add (view);
-        if (modifications_handler.get_current_delay_mode ())
-        {
-            Variant variant = new Variant ("(sq)", full_name, context_id);
-            wrapper.set_detailed_action_name ("ui.open-object(" + variant.print (true) + ")");
-        }
-        return wrapper;
+        SimpleSettingObject sso = (SimpleSettingObject) object;
+        return ModificationsRevealer.create_delayed_setting_row (modifications_handler, sso.name, 
sso.full_name, sso.context_id);
     }
 
     [GtkCallback]
diff --git a/editor/delayed-setting-view.ui b/editor/delayed-setting-view.ui
index a8477e0..4fa4085 100644
--- a/editor/delayed-setting-view.ui
+++ b/editor/delayed-setting-view.ui
@@ -1,139 +1,143 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <!-- interface-requires gtk+ 3.0 -->
-  <template class="DelayedSettingView" parent="GtkGrid">
-    <property name="visible">True</property> <!-- TODO useful? -->
-    <property name="orientation">vertical</property>
+  <template class="DelayedSettingView" parent="GtkListBoxRow">
     <child>
-      <object class="GtkLabel" id="key_name_label">
-        <property name="visible">True</property>
-        <property name="halign">start</property>
-        <property name="hexpand">true</property>
-        <style>
-          <class name="key-name"/>
-        </style>
-      </object>
-      <packing>
-        <property name="left-attach">0</property>
-        <property name="top-attach">0</property>
-        <property name="width">2</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkButton" id="cancel_change_button">
+      <object class="GtkGrid">
         <property name="visible">True</property>
-        <property name="halign">end</property>
-        <property name="hexpand">false</property>
-        <property name="valign">center</property>
-        <property name="can-focus">False</property>
-        <style>
-          <class name="flat"/>
-          <class name="circular"/>
-        </style>
+        <property name="orientation">vertical</property>
         <child>
-          <object class="GtkImage">
+          <object class="GtkLabel" id="key_name_label">
             <property name="visible">True</property>
-            <property name="icon-name">window-close-symbolic</property>
+            <property name="halign">start</property>
+            <property name="hexpand">true</property>
+            <style>
+              <class name="key-name"/>
+            </style>
           </object>
+          <packing>
+            <property name="left-attach">0</property>
+            <property name="top-attach">0</property>
+            <property name="width">2</property>
+          </packing>
         </child>
-      </object>
-      <packing>
-        <property name="left-attach">3</property>
-        <property name="top-attach">0</property>
-        <property name="height">3</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkImage">
-        <property name="visible">True</property>
-        <property name="halign">start</property>
-        <property name="icon-name">list-remove-symbolic</property>
-        <style>
-          <class name="diff-bullet"/>
-        </style>
-      </object>
-      <packing>
-        <property name="left-attach">0</property>
-        <property name="top-attach">1</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkGrid">
-        <property name="visible">True</property>
-        <property name="hexpand">True</property>
         <child>
-          <object class="GtkLabel" id="key_value_label">
+          <object class="GtkButton" id="cancel_change_button">
             <property name="visible">True</property>
-            <property name="halign">start</property>
-            <property name="ellipsize">end</property>
-            <property name="max-width-chars">42</property>
+            <property name="halign">end</property>
+            <property name="hexpand">false</property>
+            <property name="valign">center</property>
+            <property name="can-focus">False</property>
             <style>
-              <class name="value-label"/>
+              <class name="flat"/>
+              <class name="circular"/>
             </style>
+            <child>
+              <object class="GtkImage">
+                <property name="visible">True</property>
+                <property name="icon-name">window-close-symbolic</property>
+              </object>
+            </child>
           </object>
+          <packing>
+            <property name="left-attach">3</property>
+            <property name="top-attach">0</property>
+            <property name="height">3</property>
+          </packing>
         </child>
         <child>
-          <object class="GtkLabel" id="key_value_default">
+          <object class="GtkImage">
             <property name="visible">True</property>
             <property name="halign">start</property>
-            <property name="hexpand">True</property>
-            <property name="label" translatable="yes">Default value</property>
+            <property name="icon-name">list-remove-symbolic</property>
             <style>
-              <class name="bold-label"/>
+              <class name="diff-bullet"/>
             </style>
           </object>
+          <packing>
+            <property name="left-attach">0</property>
+            <property name="top-attach">1</property>
+          </packing>
         </child>
-      </object>
-      <packing>
-        <property name="left-attach">1</property>
-        <property name="top-attach">1</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkImage">
-        <property name="visible">True</property>
-        <property name="halign">start</property>
-        <property name="icon-name">list-add-symbolic</property>
-        <style>
-          <class name="diff-bullet"/>
-        </style>
-      </object>
-      <packing>
-        <property name="left-attach">0</property>
-        <property name="top-attach">2</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkGrid">
-        <property name="visible">True</property>
-        <property name="hexpand">True</property>
         <child>
-          <object class="GtkLabel" id="planned_value_label">
+          <object class="GtkGrid">
+            <property name="visible">True</property>
+            <property name="hexpand">True</property>
+            <child>
+              <object class="GtkLabel" id="key_value_label">
+                <property name="visible">True</property>
+                <property name="halign">start</property>
+                <property name="ellipsize">end</property>
+                <property name="max-width-chars">42</property>
+                <style>
+                  <class name="value-label"/>
+                </style>
+              </object>
+            </child>
+            <child>
+              <object class="GtkLabel" id="key_value_default">
+                <property name="visible">True</property>
+                <property name="halign">start</property>
+                <property name="hexpand">True</property>
+                <property name="label" translatable="yes">Default value</property>
+                <style>
+                  <class name="bold-label"/>
+                </style>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="left-attach">1</property>
+            <property name="top-attach">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkImage">
             <property name="visible">True</property>
             <property name="halign">start</property>
-            <property name="ellipsize">end</property>
-            <property name="max-width-chars">42</property>
+            <property name="icon-name">list-add-symbolic</property>
             <style>
-              <class name="value-label"/>
+              <class name="diff-bullet"/>
             </style>
           </object>
+          <packing>
+            <property name="left-attach">0</property>
+            <property name="top-attach">2</property>
+          </packing>
         </child>
         <child>
-          <object class="GtkLabel" id="planned_value_default">
+          <object class="GtkGrid">
             <property name="visible">True</property>
-            <property name="halign">start</property>
             <property name="hexpand">True</property>
-            <property name="label" translatable="yes">Default value</property>
-            <style>
-              <class name="bold-label"/>
-            </style>
+            <child>
+              <object class="GtkLabel" id="planned_value_label">
+                <property name="visible">True</property>
+                <property name="halign">start</property>
+                <property name="ellipsize">end</property>
+                <property name="max-width-chars">42</property>
+                <style>
+                  <class name="value-label"/>
+                </style>
+              </object>
+            </child>
+            <child>
+              <object class="GtkLabel" id="planned_value_default">
+                <property name="visible">True</property>
+                <property name="halign">start</property>
+                <property name="hexpand">True</property>
+                <property name="label" translatable="yes">Default value</property>
+                <style>
+                  <class name="bold-label"/>
+                </style>
+              </object>
+            </child>
           </object>
+          <packing>
+            <property name="left-attach">1</property>
+            <property name="top-attach">2</property>
+          </packing>
         </child>
       </object>
-      <packing>
-        <property name="left-attach">1</property>
-        <property name="top-attach">2</property>
-      </packing>
     </child>
   </template>
 </interface>
diff --git a/editor/delayed-setting-view.vala b/editor/delayed-setting-view.vala
index 8c80388..e4854b6 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 : Grid
+private class DelayedSettingView : ListBoxRow
 {
     [GtkChild] private Label key_name_label;
     [GtkChild] private Label key_value_label;
diff --git a/editor/modifications-list.vala b/editor/modifications-list.vala
index 5167f97..d36c930 100644
--- a/editor/modifications-list.vala
+++ b/editor/modifications-list.vala
@@ -33,15 +33,19 @@ private class ModificationsList : OverlayedList
         main_list_box.set_header_func (delayed_setting_row_update_header);
     }
 
-    private static void delayed_setting_row_update_header (ListBoxRow row, ListBoxRow? before)
+    private static void delayed_setting_row_update_header (ListBoxRow _row, ListBoxRow? before)
     {
-        string row_key_name = ((DelayedSettingView) row.get_child ()).full_name;
+        if (!(_row is DelayedSettingView))
+            assert_not_reached ();
+
+        DelayedSettingView row = (DelayedSettingView) (!) _row;
+        string row_key_name = ((DelayedSettingView) row).full_name;
         bool add_location_header = false;
         if (before == null)
             add_location_header = true;
         else
         {
-            string before_key_name = ((DelayedSettingView) ((!) before).get_child ()).full_name;
+            string before_key_name = ((DelayedSettingView) (!) before).full_name;
 
             if (ModelUtils.get_parent_path (row_key_name) != ModelUtils.get_parent_path (before_key_name))
                 add_location_header = true;
@@ -89,7 +93,7 @@ private class ModificationsList : OverlayedList
         if (selected_row == null)
             return false;
 
-        modifications_handler.dismiss_change (((DelayedSettingView) (!) ((!) selected_row).get_child 
()).full_name);
+        modifications_handler.dismiss_change (((DelayedSettingView) (!) selected_row).full_name);
         return true;
     }
 
@@ -111,10 +115,9 @@ private class ModificationsList : OverlayedList
         if (selected_rows.length () != 1)
             return null;
         ListBoxRow row = selected_rows.nth_data (0);
-        Widget? child = row.get_child ();
-        if (child == null || !((!) child is DelayedSettingView))
+        if (!(row is DelayedSettingView))
             assert_not_reached ();
-        return ((DelayedSettingView) (!) child).full_name;  // FIXME row should keep focus
+        return ((DelayedSettingView) row).full_name;  // FIXME row should keep focus
     }
 
     /*\
@@ -124,7 +127,7 @@ private class ModificationsList : OverlayedList
     internal void gkey_value_push (string full_name, uint16 context_id, Variant key_value, bool 
is_key_default)
     {
         main_list_box.foreach ((widget) => {
-                DelayedSettingView row = (DelayedSettingView) ((Bin) widget).get_child ();
+                DelayedSettingView row = (DelayedSettingView) widget;
                 if (row.full_name == full_name && row.context_id == context_id)
                     row.update_gsettings_key_current_value (key_value, is_key_default);
             });
@@ -133,7 +136,7 @@ private class ModificationsList : OverlayedList
     internal void dkey_value_push (string full_name, Variant? key_value_or_null)
     {
         main_list_box.foreach ((widget) => {
-                DelayedSettingView row = (DelayedSettingView) ((Bin) widget).get_child ();
+                DelayedSettingView row = (DelayedSettingView) widget;
                 if (row.full_name == full_name)
                     row.update_dconf_key_current_value (key_value_or_null);
             });
diff --git a/editor/modifications-revealer.vala b/editor/modifications-revealer.vala
index 3eceac9..cc0b011 100644
--- a/editor/modifications-revealer.vala
+++ b/editor/modifications-revealer.vala
@@ -171,9 +171,12 @@ private class ModificationsRevealer : Revealer, AdaptativeWidget
 
     private Widget delayed_setting_row_create (Object object)
     {
-        string full_name = ((SimpleSettingObject) object).full_name;
-        uint16 context_id = ((SimpleSettingObject) object).context_id;
+        SimpleSettingObject sso = (SimpleSettingObject) object;
+        return create_delayed_setting_row (modifications_handler, sso.name, sso.full_name, sso.context_id);
+    }
 
+    internal static Widget create_delayed_setting_row (ModificationsHandler modifications_handler, string 
name, string full_name, uint16 context_id)
+    {
         SettingsModel model = modifications_handler.model;
 
         RegistryVariantDict properties = new RegistryVariantDict.from_aqv (model.get_key_properties 
(full_name, context_id, (uint16) (PropertyQuery.HAS_SCHEMA & PropertyQuery.IS_DEFAULT & 
PropertyQuery.DEFAULT_VALUE & PropertyQuery.KEY_VALUE)));
@@ -204,7 +207,7 @@ private class ModificationsRevealer : Revealer, AdaptativeWidget
 
         properties.clear ();
 
-        DelayedSettingView view = new DelayedSettingView (((SimpleSettingObject) object).name,
+        DelayedSettingView view = new DelayedSettingView (name,
                                                           full_name,
                                                           context_id,
                                                           has_schema_and_is_default,    // at row creation, 
key is never ghost
@@ -212,14 +215,13 @@ private class ModificationsRevealer : Revealer, AdaptativeWidget
                                                           cool_planned_value,
                                                           cool_default_value);
 
-        ListBoxRow wrapper = new ListBoxRow ();
-        wrapper.add (view);
         if (modifications_handler.get_current_delay_mode ())
         {
             Variant variant = new Variant ("(sq)", full_name, context_id);
-            wrapper.set_detailed_action_name ("ui.open-object(" + variant.print (true) + ")");
+            view.set_detailed_action_name ("ui.open-object(" + variant.print (true) + ")");
         }
-        return wrapper;
+        view.show ();
+        return view;
     }
 
     /*\


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