[dconf-editor] Add ModificationsRevealer class and UI file.
- From: Arnaud Bonatti <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dconf-editor] Add ModificationsRevealer class and UI file.
- Date: Tue, 24 May 2016 00:49:44 +0000 (UTC)
commit 03f8efb5fbc818f866d99826e4924d47c5ea1f23
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Tue May 24 02:49:28 2016 +0200
Add ModificationsRevealer class and UI file.
editor/Makefile.am | 2 +
editor/dconf-editor.gresource.xml | 1 +
editor/dconf-editor.ui | 42 +-------------
editor/dconf-window.vala | 90 ++--------------------------
editor/modifications-revealer.ui | 46 ++++++++++++++
editor/modifications-revealer.vala | 117 ++++++++++++++++++++++++++++++++++++
po/POTFILES.in | 2 +
7 files changed, 174 insertions(+), 126 deletions(-)
---
diff --git a/editor/Makefile.am b/editor/Makefile.am
index 3ebf8f1..9755ef4 100644
--- a/editor/Makefile.am
+++ b/editor/Makefile.am
@@ -30,6 +30,7 @@ resource_data = \
bookmarks.ui \
bookmark.ui \
help-overlay.ui \
+ modifications-revealer.ui \
pathbar.ui \
pathbar-item.ui \
property-row.ui
@@ -47,6 +48,7 @@ dconf_editor_SOURCES = \
dconf-view.vala \
bookmarks.vala \
key-list-box-row.vala \
+ modifications-revealer.vala \
pathbar.vala
desktopdir = $(datadir)/applications
diff --git a/editor/dconf-editor.gresource.xml b/editor/dconf-editor.gresource.xml
index 9db9def..4ccad1a 100644
--- a/editor/dconf-editor.gresource.xml
+++ b/editor/dconf-editor.gresource.xml
@@ -8,6 +8,7 @@
<file preprocess="xml-stripblanks">folder-list-box-row.ui</file>
<file preprocess="xml-stripblanks">key-list-box-row.ui</file>
<file preprocess="xml-stripblanks">key-editor.ui</file>
+ <file preprocess="xml-stripblanks">modifications-revealer.ui</file>
<file preprocess="xml-stripblanks">pathbar.ui</file>
<file preprocess="xml-stripblanks">pathbar-item.ui</file>
<file preprocess="xml-stripblanks">property-row.ui</file>
diff --git a/editor/dconf-editor.ui b/editor/dconf-editor.ui
index 21334d1..54b595a 100644
--- a/editor/dconf-editor.ui
+++ b/editor/dconf-editor.ui
@@ -214,51 +214,11 @@
</object>
</child>
<child>
- <object class="GtkRevealer" id="revealer">
+ <object class="ModificationsRevealer" 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>
- <property name="margin-left">6</property><!-- GtkActionBar creates a GtkBox which
"spacing" property is not editable -->
- <property name="margin-right">6</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-window.vala b/editor/dconf-window.vala
index f188631..f2f91f4 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -42,13 +42,7 @@ 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> gsettings_keys_awaiting_hashtable = new GenericSet<string> (str_hash,
str_equal);
- [GtkChild] private Revealer revealer;
- [GtkChild] private Label revealer_label;
- private DConf.Client dconf_client = new DConf.Client ();
- private DConf.Changeset dconf_changeset = new DConf.Changeset ();
- private HashTable<string, DConfKey> dconf_keys_awaiting_hashtable = new HashTable<string, DConfKey>
(str_hash, str_equal);
+ [GtkChild] private ModificationsRevealer revealer;
[GtkChild] private SearchBar search_bar;
[GtkChild] private SearchEntry search_entry;
@@ -397,7 +391,7 @@ class DConfWindow : ApplicationWindow
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);
+ revealer.add_delayed_dconf_settings (key, new_value);
else if (new_value != null)
key.value = new_value;
else
@@ -407,87 +401,13 @@ class DConfWindow : ApplicationWindow
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);
+ revealer.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);
-
- DConfKey? existing_key = dconf_keys_awaiting_hashtable.lookup (key.full_name);
- if (existing_key == null)
- dconf_keys_awaiting_hashtable.insert (key.full_name, key);
-
- update_revealer ();
- }
-
- private void add_delayed_glib_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 (!gsettings_keys_awaiting_hashtable.contains (key.descriptor))
- gsettings_keys_awaiting_hashtable.add (key.descriptor);
-
- update_revealer ();
- }
-
- private void update_revealer ()
- requires (dconf_keys_awaiting_hashtable.length != 0 || gsettings_keys_awaiting_hashtable.length != 0)
- {
- if (dconf_keys_awaiting_hashtable.length == 0)
- revealer_label.set_text (_("%u gsettings operations awaiting.").printf
(gsettings_keys_awaiting_hashtable.length));
- else if (gsettings_keys_awaiting_hashtable.length == 0)
- revealer_label.set_text (_("%u dconf operations awaiting.").printf
(dconf_keys_awaiting_hashtable.length));
- else
- revealer_label.set_text (_("%u gsettings operations and %u dconf operations awaiting.").printf
(gsettings_keys_awaiting_hashtable.length, dconf_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; });
- gsettings_keys_awaiting_hashtable.remove_all ();
-
- try {
- dconf_client.change_sync (dconf_changeset);
- } catch (Error error) {
- warning (error.message);
- }
- dconf_changeset = new DConf.Changeset ();
- dconf_keys_awaiting_hashtable.foreach_remove ((full_name, key) => { key.is_ghost = true; return
true; });
- }
-
- [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; });
- gsettings_keys_awaiting_hashtable.remove_all ();
-
- dconf_changeset = new DConf.Changeset ();
- dconf_keys_awaiting_hashtable.remove_all ();
- }
-
/*\
* * Action entries
\*/
@@ -523,10 +443,10 @@ class DConfWindow : ApplicationWindow
if (!((Key) setting_object).has_schema)
{
if (!((DConfKey) setting_object).is_ghost)
- add_delayed_dconf_settings ((DConfKey) setting_object, null);
+ revealer.add_delayed_dconf_settings ((DConfKey) setting_object, null);
}
else if (!((GSettingsKey) setting_object).is_default)
- add_delayed_glib_settings ((GSettingsKey) setting_object, null);
+ revealer.add_delayed_glib_settings ((GSettingsKey) setting_object, null);
}
}
diff --git a/editor/modifications-revealer.ui b/editor/modifications-revealer.ui
new file mode 100644
index 0000000..d64debf
--- /dev/null
+++ b/editor/modifications-revealer.ui
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.0 -->
+ <template class="ModificationsRevealer" parent="GtkRevealer">
+ <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="label">
+ <property name="visible">True</property>
+ <property name="margin-left">6</property><!-- GtkActionBar creates a GtkBox which "spacing"
property is not editable -->
+ <property name="margin-right">6</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>
+ </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/modifications-revealer.vala b/editor/modifications-revealer.vala
new file mode 100644
index 0000000..02fa53d
--- /dev/null
+++ b/editor/modifications-revealer.vala
@@ -0,0 +1,117 @@
+/*
+ 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 <http://www.gnu.org/licenses/>.
+*/
+
+using Gtk;
+
+[GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/modifications-revealer.ui")]
+class ModificationsRevealer : Revealer
+{
+ [GtkChild] private Label label;
+
+ private HashTable<string, GLib.Settings> delayed_settings_hashtable = new HashTable<string,
GLib.Settings> (str_hash, str_equal);
+ private GenericSet<string> gsettings_keys_awaiting_hashtable = new GenericSet<string> (str_hash,
str_equal);
+
+ private DConf.Client dconf_client = new DConf.Client ();
+ private DConf.Changeset dconf_changeset = new DConf.Changeset ();
+ private HashTable<string, DConfKey> dconf_keys_awaiting_hashtable = new HashTable<string, DConfKey>
(str_hash, str_equal);
+
+ /*\
+ * * Public calls
+ \*/
+
+ public void add_delayed_dconf_settings (DConfKey key, Variant? new_value)
+ {
+ dconf_changeset.set (key.full_name, new_value);
+
+ DConfKey? existing_key = dconf_keys_awaiting_hashtable.lookup (key.full_name);
+ if (existing_key == null)
+ dconf_keys_awaiting_hashtable.insert (key.full_name, key);
+
+ update ();
+ }
+
+ public void add_delayed_glib_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 (!gsettings_keys_awaiting_hashtable.contains (key.descriptor))
+ gsettings_keys_awaiting_hashtable.add (key.descriptor);
+
+ update ();
+ }
+
+ /*\
+ * * Buttons callbacks
+ \*/
+
+ [GtkCallback]
+ private void apply_delayed_settings ()
+ {
+ set_reveal_child (false);
+
+ delayed_settings_hashtable.foreach_remove ((schema_id, schema_settings) => { schema_settings.apply
(); return true; });
+ gsettings_keys_awaiting_hashtable.remove_all ();
+
+ try {
+ dconf_client.change_sync (dconf_changeset);
+ } catch (Error error) {
+ warning (error.message);
+ }
+ dconf_changeset = new DConf.Changeset ();
+ dconf_keys_awaiting_hashtable.foreach_remove ((full_name, key) => { key.is_ghost = true; return
true; });
+ }
+
+ [GtkCallback]
+ private void dismiss_delayed_settings ()
+ {
+ set_reveal_child (false);
+
+ delayed_settings_hashtable.foreach_remove ((schema_id, schema_settings) => { schema_settings.revert
(); return true; });
+ gsettings_keys_awaiting_hashtable.remove_all ();
+
+ dconf_changeset = new DConf.Changeset ();
+ dconf_keys_awaiting_hashtable.remove_all ();
+ }
+
+ /*\
+ * * Utilities
+ \*/
+
+ private void update ()
+ requires (dconf_keys_awaiting_hashtable.length != 0 || gsettings_keys_awaiting_hashtable.length != 0)
+ {
+ if (dconf_keys_awaiting_hashtable.length == 0)
+ label.set_text (_("%u gsettings operations awaiting.").printf
(gsettings_keys_awaiting_hashtable.length));
+ else if (gsettings_keys_awaiting_hashtable.length == 0)
+ label.set_text (_("%u dconf operations awaiting.").printf
(dconf_keys_awaiting_hashtable.length));
+ else
+ label.set_text (_("%u gsettings operations and %u dconf operations awaiting.").printf
(gsettings_keys_awaiting_hashtable.length, dconf_keys_awaiting_hashtable.length));
+
+ set_reveal_child (true);
+ }
+}
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 1f725c2..f303e9d 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -12,3 +12,5 @@ editor/dconf-window.vala
[type: gettext/glade]editor/help-overlay.ui
[type: gettext/glade]editor/key-editor.ui
editor/key-list-box-row.vala
+[type: gettext/glade]editor/modifications-revealer.ui
+editor/modifications-revealer.vala
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]