[dconf-editor] Introduce ModificationsList.



commit 38e62a5b38a5567797477a47bf1d5a96f7ceb822
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Fri Oct 26 11:04:21 2018 +0200

    Introduce ModificationsList.

 editor/dconf-editor.gresource.xml  |   1 +
 editor/meson.build                 |   2 +
 editor/modifications-list.ui       |  79 +++++++++++++++++++
 editor/modifications-list.vala     | 151 +++++++++++++++++++++++++++++++++++++
 editor/modifications-revealer.ui   |  21 +-----
 editor/modifications-revealer.vala |  82 +++-----------------
 6 files changed, 246 insertions(+), 90 deletions(-)
---
diff --git a/editor/dconf-editor.gresource.xml b/editor/dconf-editor.gresource.xml
index ed364f0..510f7e3 100644
--- a/editor/dconf-editor.gresource.xml
+++ b/editor/dconf-editor.gresource.xml
@@ -19,6 +19,7 @@
     <file>large-pathbar.css</file>
     <file preprocess="xml-stripblanks">large-pathbar.ui</file>
     <file preprocess="xml-stripblanks">large-pathbar-item.ui</file>
+    <file preprocess="xml-stripblanks">modifications-list.ui</file>
     <file preprocess="xml-stripblanks">modifications-revealer.ui</file>
     <file preprocess="xml-stripblanks">pathentry.ui</file>
     <file preprocess="xml-stripblanks">pathwidget.ui</file>
diff --git a/editor/meson.build b/editor/meson.build
index e158ce4..3062cbc 100644
--- a/editor/meson.build
+++ b/editor/meson.build
@@ -83,6 +83,7 @@ sources = files(
   'large-pathbar.vala',
   'model-utils.vala',
   'modifications-handler.vala',
+  'modifications-list.vala',
   'modifications-revealer.vala',
   'night-light-monitor.vala',
   'pathentry.vala',
@@ -118,6 +119,7 @@ resource_data = files(
   'large-pathbar-item.ui',
   'large-pathbar.css',
   'large-pathbar.ui',
+  'modifications-list.ui',
   'modifications-revealer.ui',
   'pathentry.ui',
   'pathwidget.ui',
diff --git a/editor/modifications-list.ui b/editor/modifications-list.ui
new file mode 100644
index 0000000..24fb3a6
--- /dev/null
+++ b/editor/modifications-list.ui
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface domain="dconf-editor">
+  <!-- interface-requires gtk+ 3.0 -->
+  <template class="ModificationsList" parent="GtkOverlay">
+    <property name="expand">True</property>
+    <property name="valign">fill</property>
+    <child>
+      <object class="GtkScrolledWindow" id="scrolled">
+        <property name="visible">True</property>
+        <property name="can-focus">False</property>
+        <!-- property name="expand">True</property>
+        <property name="hscrollbar-policy">never</property>
+        <property name="shadow-type">etched-in</property>
+        <property name="max-content-height">300</property>
+        <property name="propagate-natural-width">True</property>
+        <property name="propagate-natural-height">True</property -->
+        <child>
+          <object class="GtkListBox" id="delayed_settings_listbox">
+            <property name="visible">True</property>
+            <property name="activate-on-single-click">True</property>
+            <property name="selection-mode">browse</property>
+            <!-- signal name="selected-rows-changed" handler="on_selection_changed"/>
+            <signal name="add" handler="on_content_changed"/>
+            <signal name="remove" handler="on_content_changed"/ -->
+            <style>
+              <class name="delayed-list"/>
+              <class name="padding-bottom"/>
+            </style>
+            <child type="placeholder">
+              <object class="RegistryPlaceholder" id="placeholder">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">Delayed mode is on&#xA;but&#xA;no pending 
changes</property>
+                <property name="icon-name">document-open-recent-symbolic</property> <!-- or 
dconf-editor-symbolic? -->
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+    <!-- child type="overlay">
+      <object class="GtkBox" id="edit_mode_box">
+        <property name="visible">False</property>
+        <property name="halign">center</property>
+        <property name="valign">end</property>
+        <property name="width-request">200</property>
+        <style>
+          <class name="linked"/>
+          <class name="linked-circular"/>
+        </style>
+        <child>
+          <object class="GtkModelButton" id="leave_edit_mode_button">
+            <property name="visible">True</property>
+            <property name="hexpand">True</property>
+            <property name="centered">True</property>
+            <property name="iconic">True</property>
+            <property name="focus-on-click">False</property>
+            <property name="text" translatable="yes">Use</property>
+            <style>
+              <class name="left-on-ltr"/>
+            </style>
+          </object>
+        </child>
+        <child>
+          <object class="GtkModelButton" id="enter_edit_mode_button">
+            <property name="visible">True</property>
+            <property name="hexpand">True</property>
+            <property name="centered">True</property>
+            <property name="iconic">True</property>
+            <property name="focus-on-click">False</property>
+            <property name="text" translatable="yes">Edit</property>
+            <style>
+              <class name="right-on-ltr"/>
+            </style>
+          </object>
+        </child>
+      </object>
+    </child -->
+  </template>
+</interface>
diff --git a/editor/modifications-list.vala b/editor/modifications-list.vala
new file mode 100644
index 0000000..5e074e5
--- /dev/null
+++ b/editor/modifications-list.vala
@@ -0,0 +1,151 @@
+/*
+  This file is part of Dconf Editor
+
+  Dconf Editor is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  Dconf Editor is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with Dconf Editor.  If not, see <https://www.gnu.org/licenses/>.
+*/
+
+using Gtk;
+
+[GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/modifications-list.ui")]
+private class ModificationsList : Overlay
+{
+    [GtkChild] private ScrolledWindow   scrolled;
+    [GtkChild] private ListBox          delayed_settings_listbox;
+/*    [GtkChild] private Box              edit_mode_box;
+
+    [GtkChild] private ModelButton enter_edit_mode_button;
+    [GtkChild] private ModelButton leave_edit_mode_button;
+    public string edit_mode_action_prefix
+    {
+        construct
+        {
+            // TODO sanitize "value"
+            enter_edit_mode_button.set_detailed_action_name (value + ".set-edit-mode(true)");
+            leave_edit_mode_button.set_detailed_action_name (value + ".set-edit-mode(false)");
+        }
+    } */
+
+    public bool needs_shadows
+    {
+        construct
+        {
+            if (value)
+                scrolled.shadow_type = ShadowType.ETCHED_IN;
+            else
+                scrolled.shadow_type = ShadowType.NONE;
+        }
+    }
+
+    [GtkChild] private RegistryPlaceholder placeholder;
+    public bool big_placeholder { internal construct { placeholder.big = value; }}
+
+    construct
+    {
+        delayed_settings_listbox.set_header_func (delayed_setting_row_update_header);
+    }
+
+    private static void delayed_setting_row_update_header (ListBoxRow row, ListBoxRow? before)
+    {
+        string row_key_name = ((DelayedSettingView) row.get_child ()).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;
+
+            if (ModelUtils.get_parent_path (row_key_name) != ModelUtils.get_parent_path (before_key_name))
+                add_location_header = true;
+        }
+
+        if (add_location_header)
+        {
+            Grid location_header = new Grid ();
+            location_header.show ();
+            location_header.orientation = Orientation.VERTICAL;
+
+            Label location_header_label = new Label (ModelUtils.get_parent_path (row_key_name));
+            location_header_label.show ();
+            location_header_label.hexpand = true;
+            location_header_label.halign = Align.START;
+
+            StyleContext context = location_header_label.get_style_context ();
+            context.add_class ("dim-label");
+            context.add_class ("bold-label");
+            context.add_class ("list-row-header");
+
+            location_header.add (location_header_label);
+
+            Separator separator_header = new Separator (Orientation.HORIZONTAL);
+            separator_header.show ();
+            location_header.add (separator_header);
+
+            row.set_header (location_header);
+        }
+        else
+        {
+            Separator separator_header = new Separator (Orientation.HORIZONTAL);
+            separator_header.show ();
+            row.set_header (separator_header);
+        }
+    }
+
+    /*\
+    * * Modifications list public functions
+    \*/
+
+    internal bool dismiss_selected_modification (ModificationsHandler modifications_handler)
+    {
+        ListBoxRow? selected_row = delayed_settings_listbox.get_selected_row ();
+        if (selected_row == null)
+            return false;
+
+        modifications_handler.dismiss_change (((DelayedSettingView) (!) ((!) selected_row).get_child 
()).full_name);
+        return true;
+    }
+
+    internal void bind_model (GLib.ListStore modifications, ListBoxCreateWidgetFunc 
delayed_setting_row_create)
+    {
+        delayed_settings_listbox.bind_model (modifications, delayed_setting_row_create);
+        select_first_row (delayed_settings_listbox);
+    }
+    private static inline void select_first_row (ListBox delayed_settings_listbox)
+    {
+        ListBoxRow? first_row = delayed_settings_listbox.get_row_at_index (0);
+        if (first_row != null)
+            delayed_settings_listbox.select_row ((!) first_row);
+    }
+
+    /*\
+    * * Updating values; TODO only works for watched keys...
+    \*/
+
+    internal void gkey_value_push (string full_name, uint16 context_id, Variant key_value, bool 
is_key_default)
+    {
+        delayed_settings_listbox.foreach ((widget) => {
+                DelayedSettingView row = (DelayedSettingView) ((Bin) widget).get_child ();
+                if (row.full_name == full_name && row.context_id == context_id)
+                    row.update_gsettings_key_current_value (key_value, is_key_default);
+            });
+    }
+
+    internal void dkey_value_push (string full_name, Variant? key_value_or_null)
+    {
+        delayed_settings_listbox.foreach ((widget) => {
+                DelayedSettingView row = (DelayedSettingView) ((Bin) widget).get_child ();
+                if (row.full_name == full_name)
+                    row.update_dconf_key_current_value (key_value_or_null);
+            });
+    }
+}
diff --git a/editor/modifications-revealer.ui b/editor/modifications-revealer.ui
index e6478c6..a473505 100644
--- a/editor/modifications-revealer.ui
+++ b/editor/modifications-revealer.ui
@@ -90,26 +90,9 @@
       <class name="delayed-settings-popover"/>
     </style>
     <child>
-      <object class="GtkScrolledWindow">
+      <object class="ModificationsList" id="modifications_list">
         <property name="visible">True</property>
-        <property name="shadow-type">etched-in</property>
-        <property name="can-focus">False</property>
-        <child>
-          <object class="GtkListBox" id="delayed_settings_listbox">
-            <property name="visible">True</property>
-            <property name="activate-on-single-click">True</property>
-            <property name="selection-mode">browse</property>
-            <style>
-              <class name="delayed-list"/>
-            </style>
-            <child type="placeholder">
-              <object class="RegistryPlaceholder">
-                <property name="visible">True</property>
-                <property name="label" translatable="yes">Delayed setting changes will be shown 
here</property>
-              </object>
-            </child>
-          </object>
-        </child>
+        <property name="needs-shadows">True</property>
       </object>
     </child>
   </object>
diff --git a/editor/modifications-revealer.vala b/editor/modifications-revealer.vala
index 4e0db7f..da44f44 100644
--- a/editor/modifications-revealer.vala
+++ b/editor/modifications-revealer.vala
@@ -35,14 +35,12 @@ private class ModificationsRevealer : Revealer
     [GtkChild] private ModelButton apply_button;
     [GtkChild] private MenuButton delayed_list_button;
     [GtkChild] private Popover delayed_settings_list_popover;
-    [GtkChild] private ListBox delayed_settings_listbox;
+    [GtkChild] private ModificationsList modifications_list;
 
     private ThemedIcon apply_button_icon = new ThemedIcon.from_names ({"object-select-symbolic"});
 
     construct
     {
-        delayed_settings_listbox.set_header_func (delayed_setting_row_update_header);
-
         apply_button.icon = null;
         apply_button.get_style_context ().add_class ("text-button");
     }
@@ -141,13 +139,10 @@ private class ModificationsRevealer : Revealer
         if (!delayed_list_button.active)
             return false;
 
-        ListBoxRow? selected_row = delayed_settings_listbox.get_selected_row ();
-        if (selected_row == null)
-            return false;
-
-        modifications_handler.dismiss_change (((DelayedSettingView) (!) ((!) selected_row).get_child 
()).full_name);
-        update ();
-        return true;
+        bool dismissed = modifications_list.dismiss_selected_modification (modifications_handler);
+        if (dismissed)
+            update ();
+        return dismissed;
     }
 
     internal void hide_modifications_list ()
@@ -222,72 +217,18 @@ private class ModificationsRevealer : Revealer
         return wrapper;
     }
 
-    private void delayed_setting_row_update_header (ListBoxRow row, ListBoxRow? before)
-    {
-        string row_key_name = ((DelayedSettingView) row.get_child ()).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;
-
-            if (ModelUtils.get_parent_path (row_key_name) != ModelUtils.get_parent_path (before_key_name))
-                add_location_header = true;
-        }
-
-        if (add_location_header)
-        {
-            Grid location_header = new Grid ();
-            location_header.show ();
-            location_header.orientation = Orientation.VERTICAL;
-
-            Label location_header_label = new Label (ModelUtils.get_parent_path (row_key_name));
-            location_header_label.show ();
-            location_header_label.hexpand = true;
-            location_header_label.halign = Align.START;
-
-            StyleContext context = location_header_label.get_style_context ();
-            context.add_class ("dim-label");
-            context.add_class ("bold-label");
-            context.add_class ("list-row-header");
-
-            location_header.add (location_header_label);
-
-            Separator separator_header = new Separator (Orientation.HORIZONTAL);
-            separator_header.show ();
-            location_header.add (separator_header);
-
-            row.set_header (location_header);
-        }
-        else
-        {
-            Separator separator_header = new Separator (Orientation.HORIZONTAL);
-            separator_header.show ();
-            row.set_header (separator_header);
-        }
-    }
-
     /*\
     * * Updating values; TODO only works for watched keys...
     \*/
 
     internal void gkey_value_push (string full_name, uint16 context_id, Variant key_value, bool 
is_key_default)
     {
-        delayed_settings_listbox.foreach ((widget) => {
-                DelayedSettingView row = (DelayedSettingView) ((Bin) widget).get_child ();
-                if (row.full_name == full_name && row.context_id == context_id)
-                    row.update_gsettings_key_current_value (key_value, is_key_default);
-            });
+        modifications_list.gkey_value_push (full_name, context_id, key_value, is_key_default);
     }
 
     internal void dkey_value_push (string full_name, Variant? key_value_or_null)
     {
-        delayed_settings_listbox.foreach ((widget) => {
-                DelayedSettingView row = (DelayedSettingView) ((Bin) widget).get_child ();
-                if (row.full_name == full_name)
-                    row.update_dconf_key_current_value (key_value_or_null);
-            });
+        modifications_list.dkey_value_push (full_name, key_value_or_null);
     }
 
     /*\
@@ -296,12 +237,11 @@ private class ModificationsRevealer : Revealer
 
     private void update ()
     {
-        GLib.ListStore modifications_list = modifications_handler.get_delayed_settings ();
-        delayed_settings_listbox.bind_model (modifications_list, delayed_setting_row_create);
-        if (modifications_list.get_n_items () == 0)
+        GLib.ListStore modifications_liststore = modifications_handler.get_delayed_settings ();
+        modifications_list.bind_model (modifications_liststore, delayed_setting_row_create);
+
+        if (modifications_liststore.get_n_items () == 0)
             delayed_settings_list_popover.popdown ();
-        else
-            delayed_settings_listbox.select_row ((!) delayed_settings_listbox.get_row_at_index (0));
 
         if (modifications_handler.mode == ModificationsMode.NONE)
         {


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