[dconf-editor] Use GAction for bookmark.
- From: Arnaud Bonatti <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dconf-editor] Use GAction for bookmark.
- Date: Thu, 15 Feb 2018 16:12:38 +0000 (UTC)
commit 2f89bd88d7c730600baf06f504009f0fec12c1ad
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Thu Feb 15 16:21:20 2018 +0100
Use GAction for bookmark.
editor/bookmarks.ui | 2 +
editor/bookmarks.vala | 73 ++++++++++++++++++++++++++--------------------
editor/dconf-window.vala | 4 +-
3 files changed, 45 insertions(+), 34 deletions(-)
---
diff --git a/editor/bookmarks.ui b/editor/bookmarks.ui
index 346b101..df8d3ce 100644
--- a/editor/bookmarks.ui
+++ b/editor/bookmarks.ui
@@ -29,6 +29,8 @@
<object class="GtkSwitch" id="bookmarked_switch">
<property name="visible">True</property>
<property name="halign">end</property>
+ <property name="action-name">ui.empty</property>
+ <property name="action-target">''</property>
<child internal-child="accessible">
<object class="AtkObject">
<property name="AtkObject::accessible-name" translatable="yes">Location bookmarked</property>
diff --git a/editor/bookmarks.vala b/editor/bookmarks.vala
index 2fb5d2f..fe62014 100644
--- a/editor/bookmarks.vala
+++ b/editor/bookmarks.vala
@@ -27,26 +27,17 @@ public class Bookmarks : MenuButton
[GtkChild] private Switch bookmarked_switch;
private string current_path = "/";
- public void set_path (string path)
- {
- if (current_path != path)
- current_path = path;
- update_icon_and_switch ();
- }
private string schema_id = "ca.desrt.dconf-editor.Bookmarks"; // TODO move in a library
public string schema_path { private get; construct; }
private GLib.Settings settings;
- private ulong switch_active_handler = 0;
-
construct
{
install_action_entries ();
settings = new GLib.Settings.with_path (schema_id, schema_path);
- switch_active_handler = bookmarked_switch.notify ["active"].connect (switch_changed_cb);
ulong bookmarks_changed_handler = settings.changed ["bookmarks"].connect (() => {
update_bookmarks ();
update_icon_and_switch ();
@@ -56,14 +47,37 @@ public class Bookmarks : MenuButton
bookmarked_switch.grab_focus ();
destroy.connect (() => settings.disconnect (bookmarks_changed_handler));
- bookmarked_switch.destroy.connect (() => bookmarked_switch.disconnect (switch_active_handler));
}
+ /*\
+ * * Public calls
+ \*/
+
+ public void set_path (string path)
+ {
+ if (current_path != path)
+ current_path = path;
+ update_icon_and_switch ();
+ }
+
+ // for search
public string [] get_bookmarks ()
{
return settings.get_strv ("bookmarks");
}
+ // keyboard call
+ public void set_bookmarked (string path, bool new_state)
+ {
+ if (path == current_path && bookmarked_switch.get_active () == new_state)
+ return;
+
+ if (new_state)
+ append_bookmark (path);
+ else
+ remove_bookmark (path);
+ }
+
/*\
* * Action entries
\*/
@@ -77,9 +91,16 @@ public class Bookmarks : MenuButton
private const GLib.ActionEntry [] action_entries =
{
+ { "bookmark", bookmark, "s" },
{ "unbookmark", unbookmark, "s" }
};
+ private void bookmark (SimpleAction action, Variant? path_variant)
+ requires (path_variant != null)
+ {
+ append_bookmark (((!) path_variant).get_string ());
+ }
+
private void unbookmark (SimpleAction action, Variant? path_variant)
requires (path_variant != null)
{
@@ -92,27 +113,28 @@ public class Bookmarks : MenuButton
private void update_icon_and_switch ()
{
+ Variant variant = new Variant.string (current_path);
if (current_path in settings.get_strv ("bookmarks"))
{
if (bookmarks_icon.icon_name != "starred-symbolic")
bookmarks_icon.icon_name = "starred-symbolic";
update_switch (true);
+ bookmarked_switch.set_detailed_action_name ("bookmarks.unbookmark(" + variant.print (false) +
")");
}
else
{
if (bookmarks_icon.icon_name != "non-starred-symbolic")
bookmarks_icon.icon_name = "non-starred-symbolic";
update_switch (false);
+ bookmarked_switch.set_detailed_action_name ("bookmarks.bookmark(" + variant.print (false) + ")");
}
}
private void update_switch (bool bookmarked)
- requires (switch_active_handler != 0)
{
if (bookmarked == bookmarked_switch.active)
return;
- SignalHandler.block (bookmarked_switch, switch_active_handler);
+ bookmarked_switch.set_detailed_action_name ("ui.empty('')");
bookmarked_switch.active = bookmarked;
- SignalHandler.unblock (bookmarked_switch, switch_active_handler);
}
private void update_bookmarks ()
@@ -143,35 +165,22 @@ public class Bookmarks : MenuButton
}
}
- private void switch_changed_cb ()
+ private void append_bookmark (string path)
{
- bookmarks_popover.closed ();
+ bookmarks_popover.closed (); // if the popover is visible, the size of the listbox could change
1/2
- if (!bookmarked_switch.get_active ())
- remove_bookmark (current_path);
- else
- bookmark_current_path ();
- }
-
- private void bookmark_current_path ()
- {
string [] bookmarks = settings.get_strv ("bookmarks");
- if (!(current_path in bookmarks))
+ if (!(path in bookmarks))
{
- bookmarks += current_path;
+ bookmarks += path;
settings.set_strv ("bookmarks", bookmarks);
}
}
- public void set_bookmarked (bool new_state)
- {
- if (bookmarked_switch.get_active () != new_state)
- bookmarked_switch.set_active (new_state);
- }
-
private void remove_bookmark (string bookmark_name)
{
- bookmarks_popover.closed ();
+ bookmarks_popover.closed (); // if the popover is visible, the size of the listbox could change
2/2
+
string [] old_bookmarks = settings.get_strv ("bookmarks");
if (!(bookmark_name in old_bookmarks))
return;
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index 3ef92e6..d575ff9 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -740,7 +740,7 @@ class DConfWindow : ApplicationWindow
if (info_button.active)
info_button.active = false;
browser_view.discard_row_popover ();
- bookmarks_button.set_bookmarked (true);
+ bookmarks_button.set_bookmarked (current_path, true);
return true;
case "D":
if (bookmarks_button.sensitive == false)
@@ -748,7 +748,7 @@ class DConfWindow : ApplicationWindow
if (info_button.active)
info_button.active = false;
browser_view.discard_row_popover ();
- bookmarks_button.set_bookmarked (false);
+ bookmarks_button.set_bookmarked (current_path, false);
return true;
case "f":
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]