[dconf-editor] Use a switch for bookmarking current path.
- From: Arnaud Bonatti <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dconf-editor] Use a switch for bookmarking current path.
- Date: Thu, 15 Oct 2015 02:58:36 +0000 (UTC)
commit 913b9e714fe97b35d2f2fb69c2f0ded8b2fd35ca
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Thu Oct 15 04:56:04 2015 +0200
Use a switch for bookmarking current path.
editor/bookmarks.ui | 37 ++++++++++++++++++++++++++++++++-----
editor/bookmarks.vala | 36 ++++++++++++++++++++----------------
editor/dconf-window.vala | 3 +++
3 files changed, 55 insertions(+), 21 deletions(-)
---
diff --git a/editor/bookmarks.ui b/editor/bookmarks.ui
index fc77682..ce738f2 100644
--- a/editor/bookmarks.ui
+++ b/editor/bookmarks.ui
@@ -2,20 +2,41 @@
<interface>
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkPopover" id="bookmarks_popover">
- <property name="width-request">250</property>
- <property name="height-request">250</property>
+ <property name="width-request">350</property>
+ <property name="height-request">300</property>
<child>
<object class="GtkGrid">
<property name="visible">True</property>
- <property name="orientation">vertical</property>
+ <property name="column-spacing">6</property>
<property name="row-spacing">6</property>
<property name="margin">4</property>
<child>
- <object class="GtkButton">
+ <object class="GtkLabel">
<property name="visible">True</property>
<property name="label" translatable="yes">Bookmark this Location</property>
- <signal name="clicked" handler="add_bookmark_cb"/>
+ <property name="margin-start">6</property>
+ <property name="halign">start</property>
</object>
+ <packing>
+ <property name="left-attach">0</property>
+ <property name="top-attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkSwitch" id="bookmarked_switch">
+ <property name="visible">True</property>
+ <property name="halign">end</property>
+ <child internal-child="accessible">
+ <object class="AtkObject">
+ <property name="AtkObject::accessible-name" translatable="yes">Location bookmarked</property>
+ <property name="AtkObject::accessible-description" translatable="yes">Toggle to bookmark
this location</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="left-attach">1</property>
+ <property name="top-attach">0</property>
+ </packing>
</child>
<child>
<object class="GtkScrolledWindow">
@@ -65,6 +86,12 @@ be added here</property> <!-- line wrap wanted -->
</object>
</child>
</object>
+ <packing>
+ <property name="left-attach">0</property>
+ <property name="top-attach">1</property>
+ <property name="width">2</property>
+ <property name="height">1</property>
+ </packing>
</child>
</object>
</child>
diff --git a/editor/bookmarks.vala b/editor/bookmarks.vala
index a33173d..227d73a 100644
--- a/editor/bookmarks.vala
+++ b/editor/bookmarks.vala
@@ -22,9 +22,11 @@ public class Bookmarks : MenuButton
{
[GtkChild] private ListBox bookmarks_list_box;
[GtkChild] private Popover bookmarks_popover;
- [GtkChild] private Image bookmarks_icon;
+ [GtkChild] private Image bookmarks_icon;
+ [GtkChild] private Switch bookmarked_switch;
public string current_path { get; set; }
+
public string schema { get; construct; }
private GLib.Settings settings;
private GLib.ListStore bookmarks_model;
@@ -35,20 +37,17 @@ public class Bookmarks : MenuButton
{
settings = new GLib.Settings (schema);
settings.changed ["bookmarks"].connect (update_bookmarks);
- notify ["current-path"].connect (update_icon);
+ settings.changed ["bookmarks"].connect (update_icon_and_switch); // TODO updates switch if switch
changed settings...
+ notify ["current-path"].connect (update_icon_and_switch);
+ bookmarked_switch.notify ["active"].connect (switch_changed_cb); // TODO activated when
current_path changes...
update_bookmarks ();
}
- private void update_icon ()
+ private void update_icon_and_switch ()
{
- 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";
+ bool is_bookmarked = current_path in settings.get_strv ("bookmarks");
+ bookmarks_icon.icon_name = is_bookmarked ? "starred-symbolic" : "non-starred-symbolic";
+ bookmarked_switch.active = is_bookmarked;
}
private void update_bookmarks ()
@@ -62,17 +61,20 @@ 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]
- private void add_bookmark_cb ()
+ private void switch_changed_cb ()
{
bookmarks_popover.closed ();
string [] bookmarks = settings.get_strv ("bookmarks");
- bookmarks += current_path;
- settings.set_strv ("bookmarks", bookmarks);
+ if (!bookmarked_switch.get_active ())
+ remove_bookmark (current_path);
+ else if (!(current_path in bookmarks))
+ {
+ bookmarks += current_path;
+ settings.set_strv ("bookmarks", bookmarks);
+ }
}
private Widget new_bookmark_row (Object item)
@@ -93,6 +95,8 @@ public class Bookmarks : MenuButton
{
bookmarks_popover.closed ();
string [] old_bookmarks = settings.get_strv ("bookmarks");
+ if (!(bookmark_name in old_bookmarks))
+ return;
string [] new_bookmarks = new string [0];
foreach (string bookmark in old_bookmarks)
if (bookmark != bookmark_name)
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index ddc82a7..68eb666 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -197,6 +197,9 @@ class DConfWindow : ApplicationWindow
[GtkCallback]
private bool on_key_press_event (Widget widget, Gdk.EventKey event) // TODO better?
{
+ if (bookmarks_button.active) // TODO open bug
+ return false;
+
if (Gdk.keyval_name (event.keyval) == "f" && (event.state & Gdk.ModifierType.CONTROL_MASK) != 0)
// TODO better?
{
search_bar.set_search_mode (!search_bar.get_search_mode ());
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]