[dconf-editor] Udptate bookmarks' icon.
- From: Arnaud Bonatti <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dconf-editor] Udptate bookmarks' icon.
- Date: Thu, 15 Oct 2015 01:00:35 +0000 (UTC)
commit a1bea0f0d813c2269c5826210dc5764fb1f081fa
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Thu Oct 15 03:00:00 2015 +0200
Udptate bookmarks' icon.
editor/bookmarks.ui | 2 +-
editor/bookmarks.vala | 21 +++++++++++---
editor/dconf-editor.ui | 3 +-
editor/dconf-window.vala | 67 ++++++++++++++++++---------------------------
4 files changed, 46 insertions(+), 47 deletions(-)
---
diff --git a/editor/bookmarks.ui b/editor/bookmarks.ui
index 0dfe552..fc77682 100644
--- a/editor/bookmarks.ui
+++ b/editor/bookmarks.ui
@@ -83,7 +83,7 @@ be added here</property> <!-- line wrap wanted -->
<child>
<object class="GtkImage" id="bookmarks_icon">
<property name="visible">True</property>
- <property name="icon-name">non-starred-symbolic</property> <!-- or starred-symbolic? may be changing
-->
+ <property name="icon-name">non-starred-symbolic</property>
<property name="icon-size">1</property>
</object>
</child>
diff --git a/editor/bookmarks.vala b/editor/bookmarks.vala
index f7f0b38..a33173d 100644
--- a/editor/bookmarks.vala
+++ b/editor/bookmarks.vala
@@ -22,21 +22,35 @@ public class Bookmarks : MenuButton
{
[GtkChild] private ListBox bookmarks_list_box;
[GtkChild] private Popover bookmarks_popover;
+ [GtkChild] private Image bookmarks_icon;
+ public string current_path { get; set; }
public string schema { get; construct; }
private GLib.Settings settings;
private GLib.ListStore bookmarks_model;
- public signal string get_current_path ();
public signal bool bookmark_activated (string bookmark);
construct
{
settings = new GLib.Settings (schema);
settings.changed ["bookmarks"].connect (update_bookmarks);
+ notify ["current-path"].connect (update_icon);
update_bookmarks ();
}
+ private void update_icon ()
+ {
+ bool path_is_bookmarked = false;
+ string [] bookmarks = settings.get_strv ("bookmarks");
+ foreach (string bookmark in bookmarks)
+ {
+ if (bookmark == current_path)
+ path_is_bookmarked = true;
+ }
+ bookmarks_icon.icon_name = path_is_bookmarked ? "starred-symbolic" : "non-starred-symbolic";
+ }
+
private void update_bookmarks ()
{
bookmarks_model = new GLib.ListStore (typeof (Bookmark));
@@ -48,6 +62,7 @@ public class Bookmarks : MenuButton
bookmarks_model.append (bookmark_row);
}
bookmarks_list_box.bind_model (bookmarks_model, new_bookmark_row);
+ update_icon (); // TODO duplicates work
}
[GtkCallback]
@@ -55,10 +70,8 @@ public class Bookmarks : MenuButton
{
bookmarks_popover.closed ();
- string path = get_current_path ();
-
string [] bookmarks = settings.get_strv ("bookmarks");
- bookmarks += path;
+ bookmarks += current_path;
settings.set_strv ("bookmarks", bookmarks);
}
diff --git a/editor/dconf-editor.ui b/editor/dconf-editor.ui
index 474cd01..1f18e89 100644
--- a/editor/dconf-editor.ui
+++ b/editor/dconf-editor.ui
@@ -44,11 +44,10 @@
</packing>
</child>
<child>
- <object class="Bookmarks">
+ <object class="Bookmarks" id="bookmarks_button">
<property name="visible">True</property>
<property name="schema">ca.desrt.dconf-editor.Settings</property>
<signal name="bookmark_activated" handler="scroll_to_path"/>
- <signal name="get_current_path" handler="get_current_path"/>
</object>
<packing>
<property name="pack-type">end</property>
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index 24475ba..ddc82a7 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -32,6 +32,7 @@ class DConfWindow : ApplicationWindow
[GtkChild] private ListBox key_list_box;
private GLib.Settings settings;
+ [GtkChild] private Bookmarks bookmarks_button;
[GtkChild] private SearchBar search_bar;
[GtkChild] private SearchEntry search_entry;
@@ -111,11 +112,37 @@ class DConfWindow : ApplicationWindow
{
key_model = model.get_directory (iter).key_model;
current_path = model.get_directory (iter).full_name;
+ bookmarks_button.current_path = current_path;
}
key_list_box.bind_model (key_model, new_list_box_row);
}
+ [GtkCallback]
+ private bool scroll_to_path (string full_name)
+ {
+ TreeIter iter;
+ if (model.get_iter_first (out iter))
+ {
+ do
+ {
+ Directory dir = model.get_directory (iter);
+
+ if (dir.full_name == full_name)
+ {
+ select_dir (iter);
+ bookmarks_button.current_path = full_name;
+ return true;
+ }
+ }
+ while (get_next_iter (ref iter));
+ }
+ MessageDialog dialog = new MessageDialog (this, DialogFlags.MODAL, MessageType.ERROR,
ButtonsType.OK, _("Oops! Cannot find something at this path."));
+ dialog.run ();
+ dialog.destroy ();
+ return false;
+ }
+
/*\
* * Key ListBox
\*/
@@ -278,46 +305,6 @@ class DConfWindow : ApplicationWindow
return true;
}
-
- /*\
- * * Bookmarks
- \*/
-
- [GtkCallback]
- private string get_current_path ()
- {
- TreeIter iter;
- if (!dir_tree_selection.get_selected (null, out iter))
- assert_not_reached ();
-
- Value full_path_value = Value (typeof (string));
- model.get_value (iter, 2, out full_path_value);
- return full_path_value.get_string ();
- }
-
- [GtkCallback]
- private bool scroll_to_path (string full_name)
- {
- TreeIter iter;
- if (model.get_iter_first (out iter))
- {
- do
- {
- Directory dir = model.get_directory (iter);
-
- if (dir.full_name == full_name)
- {
- select_dir (iter);
- return true;
- }
- }
- while (get_next_iter (ref iter));
- }
- MessageDialog dialog = new MessageDialog (this, DialogFlags.MODAL, MessageType.ERROR,
ButtonsType.OK, _("Oops! Cannot find something at this path."));
- dialog.run ();
- dialog.destroy ();
- return false;
- }
}
[GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/key-list-box-row.ui")]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]