[dconf-editor] More manual signals disconnections.
- From: Arnaud Bonatti <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dconf-editor] More manual signals disconnections.
- Date: Tue, 26 Jul 2016 14:25:20 +0000 (UTC)
commit 500968a5a65f91b575096525b7851b3cc12885e1
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Tue Jul 26 16:25:02 2016 +0200
More manual signals disconnections.
editor/registry-info.vala | 110 ++++++++++++++++++++++++++-------------------
editor/registry-view.ui | 1 +
editor/registry-view.vala | 41 +++++++++++------
3 files changed, 90 insertions(+), 62 deletions(-)
---
diff --git a/editor/registry-info.vala b/editor/registry-info.vala
index 9a36603..8bb7b35 100644
--- a/editor/registry-info.vala
+++ b/editor/registry-info.vala
@@ -24,28 +24,39 @@ class RegistryInfo : Grid
[GtkChild] private ListBox properties_list_box;
[GtkChild] private Button erase_button;
+ public ModificationsRevealer revealer { get; set; }
+
+ /*\
+ * * Cleaning
+ \*/
+
private ulong erase_button_handler = 0;
private ulong revealer_reload_1_handler = 0;
private ulong revealer_reload_2_handler = 0;
- public bool populate_properties_list_box (ModificationsRevealer revealer, Key key)
+ public void clean ()
{
- if (erase_button_handler != 0)
- {
- erase_button.disconnect (erase_button_handler);
- erase_button_handler = 0;
- }
- if (revealer_reload_1_handler != 0)
- {
- revealer.disconnect (revealer_reload_1_handler);
- revealer_reload_1_handler = 0;
- }
- if (revealer_reload_2_handler != 0)
- {
- revealer.disconnect (revealer_reload_2_handler);
- revealer_reload_2_handler = 0;
- }
+ disconnect_handler (erase_button, ref erase_button_handler);
+ disconnect_handler (revealer, ref revealer_reload_1_handler);
+ disconnect_handler (revealer, ref revealer_reload_2_handler);
+ properties_list_box.@foreach ((widget) => { widget.destroy (); });
+ }
+ private void disconnect_handler (Widget widget, ref ulong handler)
+ {
+ if (handler == 0) // erase_button_handler & revealer_reload_1_handler depend of the key's type
+ return;
+ widget.disconnect (handler);
+ handler = 0;
+ }
+
+ /*\
+ * * Populating
+ \*/
+
+ public bool populate_properties_list_box (Key key)
+ requires (erase_button_handler == 0 && revealer_reload_1_handler == 0 && revealer_reload_2_handler
== 0)
+ {
bool has_schema;
unowned Variant [] dict_container;
key.properties.get ("(ba{ss})", out has_schema, out dict_container);
@@ -82,7 +93,7 @@ class RegistryInfo : Grid
if (!dict.lookup ("type-code", "s", out tmp_string)) assert_not_reached ();
Label label = new Label (get_current_value_text (has_schema && ((GSettingsKey) key).is_default,
key));
- key.value_changed.connect (() => { label.set_text (get_current_value_text (has_schema &&
((GSettingsKey) key).is_default, key)); });
+ ulong key_value_changed_handler = key.value_changed.connect (() => { label.set_text
(get_current_value_text (has_schema && ((GSettingsKey) key).is_default, key)); });
label.halign = Align.START;
label.valign = Align.START;
label.xalign = 0;
@@ -97,8 +108,23 @@ class RegistryInfo : Grid
add_separator ();
- bool disable_revealer_for_value = false;
KeyEditorChild key_editor_child = create_child (key);
+
+ ulong value_has_changed_handler = key_editor_child.value_has_changed.connect ((enable_revealer,
is_valid) => {
+ if (enable_revealer)
+ {
+ if (revealer.should_delay_apply (tmp_string))
+ {
+ if (is_valid)
+ revealer.add_delayed_setting (key, key_editor_child.get_variant ());
+ else
+ revealer.dismiss_change (key);
+ }
+ else
+ key.value = key_editor_child.get_variant ();
+ }
+ });
+
if (has_schema)
{
Switch custom_value_switch = new Switch ();
@@ -109,18 +135,10 @@ class RegistryInfo : Grid
custom_value_switch.bind_property ("active", key_editor_child, "sensitive",
BindingFlags.SYNC_CREATE | BindingFlags.INVERT_BOOLEAN);
- bool disable_revealer_for_switch = false;
GSettingsKey gkey = (GSettingsKey) key;
- revealer_reload_1_handler = revealer.reload.connect (() => {
- disable_revealer_for_switch = true;
- custom_value_switch.set_active (gkey.is_default);
- disable_revealer_for_switch = false; // TODO bad but needed
- });
custom_value_switch.set_active (key.planned_change ? key.planned_value == null :
gkey.is_default);
- custom_value_switch.notify ["active"].connect (() => {
- if (disable_revealer_for_switch)
- disable_revealer_for_switch = false;
- else if (revealer.should_delay_apply (tmp_string))
+ ulong switch_active_handler = custom_value_switch.notify ["active"].connect (() => {
+ if (revealer.should_delay_apply (tmp_string))
{
if (custom_value_switch.get_active ())
revealer.add_delayed_setting (key, null);
@@ -136,15 +154,22 @@ class RegistryInfo : Grid
if (custom_value_switch.get_active ())
{
((GSettingsKey) key).set_to_default ();
- disable_revealer_for_value = true;
+ SignalHandler.block (key_editor_child, value_has_changed_handler);
key_editor_child.reload (key.value);
if (tmp_string == "<flags>")
key.planned_value = key.value;
+ SignalHandler.unblock (key_editor_child, value_has_changed_handler);
}
else
key.value = key.value; // TODO that hurts...
}
});
+ revealer_reload_1_handler = revealer.reload.connect (() => {
+ SignalHandler.block (custom_value_switch, switch_active_handler);
+ custom_value_switch.set_active (gkey.is_default);
+ SignalHandler.unblock (custom_value_switch, switch_active_handler);
+ });
+ custom_value_switch.destroy.connect (() => { custom_value_switch.disconnect
(switch_active_handler); });
}
else
{
@@ -154,31 +179,22 @@ class RegistryInfo : Grid
});
}
- key_editor_child.value_has_changed.connect ((enable_revealer, is_valid) => {
- if (disable_revealer_for_value)
- disable_revealer_for_value = false;
- else if (enable_revealer)
- {
- if (revealer.should_delay_apply (tmp_string))
- {
- if (is_valid)
- revealer.add_delayed_setting (key, key_editor_child.get_variant ());
- else
- revealer.dismiss_change (key);
- }
- else
- key.value = key_editor_child.get_variant ();
- }
- });
- key_editor_child.child_activated.connect (() => { revealer.apply_delayed_settings (); }); // TODO
"only" used for string-based and spin widgets
+ ulong child_activated_handler = key_editor_child.child_activated.connect (() => {
revealer.apply_delayed_settings (); }); // TODO "only" used for string-based and spin widgets
revealer_reload_2_handler = revealer.reload.connect (() => {
- disable_revealer_for_value = true;
+ SignalHandler.block (key_editor_child, value_has_changed_handler);
key_editor_child.reload (key.value);
if (tmp_string == "<flags>")
key.planned_value = key.value;
+ SignalHandler.unblock (key_editor_child, value_has_changed_handler);
});
add_row_from_widget (_("Custom value"), key_editor_child, tmp_string);
+ key_editor_child.destroy.connect (() => {
+ key.disconnect (key_value_changed_handler);
+ key_editor_child.disconnect (value_has_changed_handler);
+ key_editor_child.disconnect (child_activated_handler);
+ });
+
return true;
}
diff --git a/editor/registry-view.ui b/editor/registry-view.ui
index 8bc0528..cdb30ae 100644
--- a/editor/registry-view.ui
+++ b/editor/registry-view.ui
@@ -111,6 +111,7 @@
<child>
<object class="RegistryInfo" id="properties_view">
<property name="visible">True</property>
+ <property name="revealer">revealer</property>
</object>
</child>
</object>
diff --git a/editor/registry-view.vala b/editor/registry-view.vala
index 0c16667..85d4c93 100644
--- a/editor/registry-view.vala
+++ b/editor/registry-view.vala
@@ -81,6 +81,23 @@ class RegistryView : Grid
get_dconf_window ().update_hamburger_menu ();
}
+ /*\
+ * * Stack switching
+ \*/
+
+ private void show_browse_view (bool transition = true)
+ {
+ enable_transition (transition);
+ stack.set_visible_child_name ("browse-view");
+ properties_view.clean ();
+ }
+
+ private void show_properties_view (bool transition = true)
+ {
+ enable_transition (transition);
+ stack.set_visible_child (properties_view);
+ }
+
public void enable_transition (bool enable)
{
stack.set_transition_type (enable ? StackTransitionType.CROSSFADE : StackTransitionType.NONE);
@@ -137,7 +154,7 @@ class RegistryView : Grid
get_dconf_window ().show_notification (_("Cannot find key \"%s\" here.").printf (key_name));
return true;
}
- if (!properties_view.populate_properties_list_box (revealer, (!) key))
+ if (!properties_view.populate_properties_list_box ((!) key))
{
open_folder (folder_name);
get_dconf_window ().show_notification (_("Key \"%s\" has been removed.").printf (key_name));
@@ -146,7 +163,7 @@ class RegistryView : Grid
update_current_path (full_name);
invalidate_popovers ();
- stack.set_visible_child (properties_view);
+ show_properties_view ();
return true;
}
private bool select_folder (string full_name)
@@ -190,7 +207,7 @@ class RegistryView : Grid
{
update_current_path (folder_path);
invalidate_popovers ();
- stack.set_visible_child_name ("browse-view");
+ show_browse_view ();
}
private DConfWindow get_dconf_window ()
@@ -231,11 +248,11 @@ class RegistryView : Grid
set_delayed_icon (row, key);
on_row_clicked_handler = row.on_row_clicked.connect (() => {
- if (!properties_view.populate_properties_list_box (revealer, key)) // TODO unduplicate
+ if (!properties_view.populate_properties_list_box (key)) // TODO unduplicate
return;
update_current_path (key.full_name);
- stack.set_visible_child (properties_view);
+ show_properties_view ();
});
// TODO bug: row is always visually activated after the dialog destruction if mouse is over at
this time
@@ -462,9 +479,7 @@ class RegistryView : Grid
dir_tree_selection.select_iter (iter);
update_current_path (dir.full_name);
- enable_transition (false);
- stack.set_visible_child_name ("browse-view");
- enable_transition (true);
+ show_browse_view (false);
return;
}
on_first_directory = false;
@@ -480,23 +495,19 @@ class RegistryView : Grid
update_current_path (dir.full_name);
key_list_box.select_row (key_list_box.get_row_at_index (position)); // TODO scroll to
key in ListBox
- enable_transition (false);
- stack.set_visible_child_name ("browse-view");
- enable_transition (true);
+ show_browse_view (false);
return;
}
else if (object is Key)
{
Key key = (Key) object;
- if ((key is GSettingsKey || !((DConfKey) key).is_ghost) && key_matches (key,
search_entry.text) && properties_view.populate_properties_list_box (revealer, key))
+ if ((key is GSettingsKey || !((DConfKey) key).is_ghost) && key_matches (key,
search_entry.text) && properties_view.populate_properties_list_box (key))
{
dir_tree_selection.select_iter (iter);
update_current_path (object.full_name);
key_list_box.select_row (key_list_box.get_row_at_index (position));
- enable_transition (false);
- stack.set_visible_child (properties_view);
- enable_transition (true);
+ show_properties_view (false);
return;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]