[dconf-editor] Reset visible keys in delay mode.



commit c96d2eac5c1a505c04fe986b40201a972aae1306
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Sun May 15 19:41:39 2016 +0200

    Reset visible keys in delay mode.

 editor/dconf-editor.ui       |   43 +++++++++++++++++++++++++++++++++++
 editor/dconf-model.vala      |    2 +
 editor/dconf-window.vala     |   51 ++++++++++++++++++++++++++++++++++++++++-
 editor/key-list-box-row.vala |    2 +-
 4 files changed, 95 insertions(+), 3 deletions(-)
---
diff --git a/editor/dconf-editor.ui b/editor/dconf-editor.ui
index e3b506f..028f43b 100644
--- a/editor/dconf-editor.ui
+++ b/editor/dconf-editor.ui
@@ -213,7 +213,50 @@
             </child>
           </object>
         </child>
+        <child>
+          <object class="GtkRevealer" id="revealer">
+            <property name="visible">True</property>
+            <property name="reveal-child">False</property>
+            <child>
+              <object class="GtkActionBar">
+                <property name="visible">True</property>
+                <child>
+                  <object class="GtkButton" id="dismiss-button">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">Dismiss</property>
+                    <signal name="clicked" handler="dismiss_delayed_settings"/>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkLabel" id="revealer_label">
+                    <property name="visible">True</property>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkButton" id="apply-button">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">Apply</property>
+                    <signal name="clicked" handler="apply_delayed_settings"/>
+                    <style>
+                      <class name="suggested-action"/>
+                    </style>
+                  </object>
+                  <packing>
+                    <property name="pack-type">end</property>
+                  </packing>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
       </object>
     </child>
   </template>
+  <object class="GtkSizeGroup">
+    <property name="mode">both</property>
+    <widgets>
+      <widget name="dismiss-button"/>
+      <widget name="apply-button"/>
+    </widgets>
+  </object>
 </interface>
diff --git a/editor/dconf-model.vala b/editor/dconf-model.vala
index 379d963..938e25c 100644
--- a/editor/dconf-model.vala
+++ b/editor/dconf-model.vala
@@ -393,6 +393,8 @@ public class GSettingsKey : Key
     public string range_type             { get; construct; }
     public Variant range_content         { get; construct; }
 
+    public string descriptor { owned get { return schema_id + " " + name; } }
+
     private GLib.Settings settings;
 
     public override Variant value
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index 317ab03..f3931d2 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -42,6 +42,11 @@ class DConfWindow : ApplicationWindow
     private GLib.Settings settings = new GLib.Settings ("ca.desrt.dconf-editor.Settings");
     [GtkChild] private Bookmarks bookmarks_button;
 
+    private HashTable<string, GLib.Settings> delayed_settings_hashtable = new HashTable<string, 
GLib.Settings> (str_hash, str_equal);
+    private GenericSet<string> keys_awaiting_hashtable = new GenericSet<string> (str_hash, str_equal);
+    [GtkChild] private Revealer revealer;
+    [GtkChild] private Label revealer_label;
+
     [GtkChild] private SearchBar search_bar;
     [GtkChild] private SearchEntry search_entry;
     [GtkChild] private Button search_next_button;
@@ -368,6 +373,48 @@ class DConfWindow : ApplicationWindow
     }
 
     /*\
+    * * Revealer stuff
+    \*/
+
+    private void add_delayed_settings (GSettingsKey key, Variant? new_value)
+    {
+        GLib.Settings? settings = delayed_settings_hashtable.lookup (key.schema_id);
+        if (settings == null)
+        {
+            settings = new GLib.Settings (key.schema_id);
+            ((!) settings).delay ();
+            delayed_settings_hashtable.insert (key.schema_id, (!) settings);
+        }
+
+        if (new_value == null)
+            ((!) settings).reset (key.name);
+        else
+            ((!) settings).set_value (key.name, (!) new_value);
+
+        if (!keys_awaiting_hashtable.contains (key.descriptor))
+            keys_awaiting_hashtable.add (key.descriptor);
+        revealer_label.set_text (_("%u operations awaiting.").printf (keys_awaiting_hashtable.length));
+
+        revealer.set_reveal_child (true);
+    }
+
+    [GtkCallback]
+    private void apply_delayed_settings ()
+    {
+        revealer.set_reveal_child (false);
+        delayed_settings_hashtable.foreach_remove ((schema_id, schema_settings) => { schema_settings.apply 
(); return true; });
+        keys_awaiting_hashtable.remove_all ();
+    }
+
+    [GtkCallback]
+    private void dismiss_delayed_settings ()
+    {
+        revealer.set_reveal_child (false);
+        delayed_settings_hashtable.foreach_remove ((schema_id, schema_settings) => { schema_settings.revert 
(); return true; });
+        keys_awaiting_hashtable.remove_all ();
+    }
+
+    /*\
     * * Action entries
     \*/
 
@@ -395,9 +442,9 @@ class DConfWindow : ApplicationWindow
             SettingObject setting_object = (SettingObject) ((!) object);
             /* if (recursively && setting_object.is_view)
                 reset_generic (((Directory) setting_object).key_model, true);
-            else */ if (setting_object.is_view || !((Key) setting_object).has_schema)
+            else */ if (setting_object.is_view || !((Key) setting_object).has_schema || ((GSettingsKey) 
setting_object).is_default)
                 continue;
-            ((GSettingsKey) setting_object).set_to_default ();
+            add_delayed_settings ((GSettingsKey) setting_object, null);
         }
     }
 
diff --git a/editor/key-list-box-row.vala b/editor/key-list-box-row.vala
index 7c5ace8..d56ae40 100644
--- a/editor/key-list-box-row.vala
+++ b/editor/key-list-box-row.vala
@@ -186,7 +186,7 @@ private class KeyListBoxRowEditable : KeyListBoxRow
 
     protected override string get_text ()
     {
-        return key.schema_id + " " + key.name + " " + key.value.print (false);
+        return key.descriptor + " " + key.value.print (false);
     }
 
     protected override bool generate_popover (ContextPopover popover)


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