[dconf-editor] Allow delayed mode for right-click popover changes.



commit cfdbf6d698253d293eb6c827bf3e3f7156bc1e2a
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Sun May 22 11:56:24 2016 +0200

    Allow delayed mode for right-click popover changes.

 editor/ca.desrt.dconf-editor.gschema.xml |    5 ++++
 editor/dconf-editor.css                  |   28 ++++++++++++++++++++++++
 editor/dconf-window.vala                 |   34 ++++++++++++++++++++++++++++++
 editor/key-list-box-row.vala             |   29 +++++++++++--------------
 4 files changed, 80 insertions(+), 16 deletions(-)
---
diff --git a/editor/ca.desrt.dconf-editor.gschema.xml b/editor/ca.desrt.dconf-editor.gschema.xml
index 9cd4ff3..6afb336 100644
--- a/editor/ca.desrt.dconf-editor.gschema.xml
+++ b/editor/ca.desrt.dconf-editor.gschema.xml
@@ -51,6 +51,11 @@
       <summary>The theme of the navigation list</summary>
       <description>The themes are defined by the application, you cannot add one. Two themes are available 
for now: 'three-twenty-two' that will remain as close as possible to the default theme of the 3.22 release, 
and 'small-rows' that tries to minimize the rows height.</description>
     </key>
+    <key name="delayed-apply-menu" type="b">
+      <default>false</default>
+      <summary>Switch right-click menu in delayed mode</summary>
+      <description>If 'true', dconf-editor ask for confirmation before applying changes set by the 
right-click menu.</description>
+    </key>
   </schema>
   <enum id="ca.desrt.dconf-editor.DemoEnum">
     <value value="0" nick="Red"/>
diff --git a/editor/dconf-editor.css b/editor/dconf-editor.css
index 08edca5..df37aea 100644
--- a/editor/dconf-editor.css
+++ b/editor/dconf-editor.css
@@ -16,6 +16,34 @@
 */
 
 /*\
+* * hamburger menu
+\*/
+
+/* egtk */
+window > popover.menu {
+  background:inherit;
+}
+
+/* separators */
+window > popover.menu > stack > box > box separator {
+  color:transparent;
+  min-height:0;
+  margin:0 0 0.4em 0;
+  border:none;  /* egtk */
+}
+
+window > popover.menu > stack > box > box > box {
+  border-top:1px solid alpha(currentColor,0.25);
+  margin-top:0.4em;
+}
+
+/* title */
+window > popover.menu > stack > box > box > box > box > label.separator {
+  font-weight:bold;
+  margin:0.5em 4rem 0 4rem;   /* 4rem left/right should be enough to be the biggest menu entry, so to center 
title */
+}
+
+/*\
 * * rows height and icon
 \*/
 
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index 948ea38..f188631 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -61,6 +61,7 @@ class DConfWindow : ApplicationWindow
     public DConfWindow ()
     {
         add_action_entries (action_entries, this);
+        add_action (settings.create_action ("delayed-apply-menu"));
 
         set_default_size (settings.get_int ("window-width"), settings.get_int ("window-height"));
         if (settings.get_boolean ("window-is-fullscreen"))
@@ -177,11 +178,18 @@ class DConfWindow : ApplicationWindow
 
         GLib.Menu menu = new GLib.Menu ();
         menu.append (_("Copy current path"), "app.copy(\"" + current_path + "\")");   // TODO protection 
against some chars in text? 1/2
+
         GLib.Menu section = new GLib.Menu ();
         section.append (_("Reset visible keys"), "win.reset-visible");
         section.append (_("Reset recursively"), "win.reset-recursive");
         section.freeze ();
         menu.append_section (null, section);
+
+        section = new GLib.Menu ();
+        section.append (_("Right click menu"), "win.delayed-apply-menu");
+        section.freeze ();
+        menu.append_section (_("Delayed Apply"), section);
+
         menu.freeze ();
         info_button.set_menu_model ((MenuModel) menu);
 
@@ -237,9 +245,15 @@ class DConfWindow : ApplicationWindow
         {
             Key key = (Key) item;
             if (key.has_schema)
+            {
                 row = new KeyListBoxRowEditable ((GSettingsKey) key);
+                ((KeyListBoxRow) row).set_key_value.connect ((variant) => { set_glib_key_value 
((GSettingsKey) key, variant); });
+            }
             else
+            {
                 row = new KeyListBoxRowEditableNoSchema ((DConfKey) key);
+                ((KeyListBoxRow) row).set_key_value.connect ((variant) => { set_dconf_key_value ((DConfKey) 
key, variant); });
+            }
             row.on_row_clicked.connect (() => { new_key_editor (key); });
             // TODO bug: row is always visually activated after the dialog destruction if mouse is over at 
this time
         }
@@ -380,6 +394,26 @@ class DConfWindow : ApplicationWindow
     * * Revealer stuff
     \*/
 
+    private void set_dconf_key_value (DConfKey key, Variant? new_value)
+    {
+        if (settings.get_boolean ("delayed-apply-menu"))
+            add_delayed_dconf_settings (key, new_value);
+        else if (new_value != null)
+            key.value = new_value;
+        else
+            assert_not_reached ();
+    }
+
+    private void set_glib_key_value (GSettingsKey key, Variant? new_value)
+    {
+        if (settings.get_boolean ("delayed-apply-menu"))
+            add_delayed_glib_settings (key, new_value);
+        else if (new_value != null)
+            key.value = new_value;
+        else
+            key.set_to_default ();
+    }
+
     private void add_delayed_dconf_settings (DConfKey key, Variant? new_value)
     {
         dconf_changeset.set (key.full_name, new_value);
diff --git a/editor/key-list-box-row.vala b/editor/key-list-box-row.vala
index f207ccd..5546f8b 100644
--- a/editor/key-list-box-row.vala
+++ b/editor/key-list-box-row.vala
@@ -111,6 +111,8 @@ private abstract class KeyListBoxRow : ClickableListBoxRow
     [GtkChild] protected Label key_value_label;
     [GtkChild] protected Label key_info_label;
 
+    public signal void set_key_value (Variant? new_value);
+
     protected static string cool_text_value (Key key)   // TODO better
     {
         return Key.cool_text_value_from_variant (key.value, key.type_string);
@@ -168,7 +170,7 @@ private class KeyListBoxRowEditableNoSchema : KeyListBoxRow
 
             popover.value_changed.connect ((gvariant) => {
                     destroy_popover ();
-                    key.value = gvariant;
+                    set_key_value (gvariant);
                 });
         }
         return true;
@@ -211,13 +213,9 @@ private class KeyListBoxRowEditable : KeyListBoxRow
             popover.new_section ();
             popover.create_buttons_list (key, true);
 
-            popover.set_to_default.connect (() => {
-                    destroy_popover ();
-                    key.set_to_default ();
-                });
             popover.value_changed.connect ((gvariant) => {
                     destroy_popover ();
-                    key.value = gvariant;
+                    set_key_value (gvariant);
                 });
         }
         else if (key.type_string == "<flags>")
@@ -227,18 +225,22 @@ private class KeyListBoxRowEditable : KeyListBoxRow
             if (!key.is_default)
                 popover.new_action ("default2", () => {
                         destroy_popover ();
-                        key.set_to_default ();
+                        set_key_value (null);
                     });
             popover.set_group ("flags");    // ensures a flag called "customize" or "default2" won't cause 
problems
 
             popover.create_flags_list ((GSettingsKey) key);
 
-            popover.value_changed.connect ((gvariant) => { key.value = gvariant; });
+            popover.value_changed.connect ((gvariant) => {
+                    set_key_value (gvariant);
+                });
         }
         else if (!key.is_default)
         {
             popover.new_section ();
-            popover.new_action ("default1", () => { key.set_to_default (); });
+            popover.new_action ("default1", () => {
+                    set_key_value (null);
+                });
         }
         return true;
     }
@@ -260,8 +262,7 @@ private class ContextPopover : Popover
     private ActionMap current_group;
 
     // public signals
-    public signal void set_to_default ();
-    public signal void value_changed (Variant gvariant);
+    public signal void value_changed (Variant? gvariant);
 
     public ContextPopover ()
     {
@@ -416,11 +417,7 @@ private class ContextPopover : Popover
         }
 
         ((GLib.ActionGroup) current_group).action_state_changed [ACTION_NAME].connect ((unknown_string, 
tmp_variant) => {
-                Variant? new_variant = tmp_variant.get_maybe ();
-                if (new_variant == null)
-                    set_to_default ();
-                else
-                    value_changed ((!) new_variant);
+                value_changed (tmp_variant.get_maybe ());
             });
 
         finalize_menu ();


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