[dconf-editor] Add bookmarks.
- From: Arnaud Bonatti <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dconf-editor] Add bookmarks.
- Date: Sat, 10 Oct 2015 00:56:46 +0000 (UTC)
commit c973810e2ac76c0f272e95cbceee663df64b7acf
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Sat Oct 10 02:55:36 2015 +0200
Add bookmarks.
editor/Makefile.am | 3 +-
editor/bookmark.ui | 33 ++++++++++
editor/ca.desrt.dconf-editor.gschema.xml | 5 ++
editor/dconf-editor.gresource.xml | 1 +
editor/dconf-editor.ui | 89 ++++++++++++++++++++++++++++
editor/dconf-model.vala | 15 +++--
editor/dconf-window.vala | 94 ++++++++++++++++++++++++++++++
7 files changed, 233 insertions(+), 7 deletions(-)
---
diff --git a/editor/Makefile.am b/editor/Makefile.am
index 341f34f..fcfaefd 100644
--- a/editor/Makefile.am
+++ b/editor/Makefile.am
@@ -26,7 +26,8 @@ resource_data = \
dconf-editor.ui \
key-list-box-row.ui \
key-editor.ui \
- key-editor-no-schema.ui
+ key-editor-no-schema.ui \
+ bookmark.ui
resources.c: $(resource_data)
$(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --sourcedir=$(srcdir) --target=$@ --generate-source $<
diff --git a/editor/bookmark.ui b/editor/bookmark.ui
new file mode 100644
index 0000000..10c9dd7
--- /dev/null
+++ b/editor/bookmark.ui
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.0 -->
+ <template class="Bookmark" parent="GtkGrid">
+ <property name="orientation">horizontal</property>
+ <property name="margin-left">8</property>
+ <child>
+ <object class="GtkLabel" id="bookmark_label">
+ <property name="visible">True</property>
+ <property name="hexpand">True</property>
+ <property name="halign">start</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkButton">
+ <property name="visible">True</property>
+ <property name="margin">2</property>
+ <signal name="clicked" handler="remove_cb"/>
+ <style>
+ <class name="image-button"/>
+ <class name="sidebar-button"/>
+ </style>
+ <child>
+ <object class="GtkImage">
+ <property name="visible">True</property>
+ <property name="icon-size">1</property>
+ <property name="icon-name">window-close-symbolic</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/editor/ca.desrt.dconf-editor.gschema.xml b/editor/ca.desrt.dconf-editor.gschema.xml
index 932e5b1..8108eb2 100644
--- a/editor/ca.desrt.dconf-editor.gschema.xml
+++ b/editor/ca.desrt.dconf-editor.gschema.xml
@@ -22,6 +22,11 @@
<summary>A flag to enable fullscreen mode</summary>
<description>A flag to enable fullscreen mode</description>
</key>
+ <key name="bookmarks" type="as">
+ <default>[]</default>
+ <summary>A list of bookmarked paths</summary>
+ <description>Contains all paths bookmarked by the user as an array of strings.</description>
+ </key>
</schema>
<enum id="ca.desrt.dconf-editor.DemoEnum">
<value value="0" nick="Red"/>
diff --git a/editor/dconf-editor.gresource.xml b/editor/dconf-editor.gresource.xml
index 174029e..48650c4 100644
--- a/editor/dconf-editor.gresource.xml
+++ b/editor/dconf-editor.gresource.xml
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/ca/desrt/dconf-editor/ui">
+ <file preprocess="xml-stripblanks">bookmark.ui</file>
<file preprocess="xml-stripblanks">dconf-editor.ui</file>
<file preprocess="xml-stripblanks">key-list-box-row.ui</file>
<file preprocess="xml-stripblanks">key-editor.ui</file>
diff --git a/editor/dconf-editor.ui b/editor/dconf-editor.ui
index faad9b3..129e697 100644
--- a/editor/dconf-editor.ui
+++ b/editor/dconf-editor.ui
@@ -1,6 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
+ <object class="GtkPopover" id="bookmarks_popover">
+ <property name="width-request">250</property>
+ <property name="height-request">222</property>
+ <child>
+ <object class="GtkGrid">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <property name="row-spacing">6</property>
+ <property name="margin">4</property>
+ <child>
+ <object class="GtkButton">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Bookmark this Location</property>
+ <signal name="clicked" handler="add_bookmark_cb"/>
+ </object>
+ </child>
+ <child>
+ <object class="GtkScrolledWindow">
+ <property name="visible">True</property>
+ <property name="expand">True</property>
+ <property name="hscrollbar-policy">never</property>
+ <property name="shadow-type">etched-in</property>
+ <child>
+ <object class="GtkListBox" id="bookmarks_list_box">
+ <property name="visible">True</property>
+ <property name="activate-on-single-click">True</property>
+ <signal name="row-activated" handler="bookmark_activated_cb"/>
+ <child type="placeholder">
+ <object class="GtkGrid">
+ <property name="visible">True</property>
+ <property name="row-spacing">12</property>
+ <property name="expand">True</property>
+ <property name="halign">center</property>
+ <property name="valign">center</property>
+ <property name="orientation">vertical</property>
+ <style>
+ <class name="dim-label"/>
+ </style>
+ <child>
+ <object class="GtkImage">
+ <property name="visible">True</property>
+ <property name="icon-name">starred-symbolic</property> <!-- or starred-symbolic? or
dconf-editor-symbolic? -->
+ <property name="pixel-size">36</property>
+ <style>
+ <class name="dim-label"/>
+ </style>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="justify">center</property>
+ <property name="label" translatable="yes">Bookmarks will
+be added here</property> <!-- line wrap wanted -->
+ <attributes>
+ <attribute name="weight" value="bold"/>
+ </attributes>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
<template class="DConfWindow" parent="GtkApplicationWindow">
<property name="visible">False</property>
<property name="title" translatable="yes">dconf Editor</property>
@@ -36,6 +104,27 @@
<property name="pack-type">end</property>
</packing>
</child>
+ <child>
+ <object class="GtkMenuButton">
+ <property name="visible">True</property>
+ <property name="valign">center</property>
+ <property name="sensitive">True</property>
+ <property name="popover">bookmarks_popover</property>
+ <style>
+ <class name="image-button"/>
+ </style>
+ <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-size">1</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="pack-type">end</property>
+ </packing>
+ </child>
</object>
</child>
<child>
diff --git a/editor/dconf-model.vala b/editor/dconf-model.vala
index 73a7350..007384c 100644
--- a/editor/dconf-model.vala
+++ b/editor/dconf-model.vala
@@ -335,7 +335,7 @@ public class SettingsModel : GLib.Object, Gtk.TreeModel
public int get_n_columns()
{
- return 2;
+ return 3;
}
public Type get_column_type (int index)
@@ -381,12 +381,15 @@ public class SettingsModel : GLib.Object, Gtk.TreeModel
return path;
}
- public void get_value(Gtk.TreeIter iter, int column, out Value value)
+ public void get_value (Gtk.TreeIter iter, int column, out Value value)
{
- if (column == 0)
- value = get_directory(iter);
- else
- value = get_directory(iter).name;
+ switch (column)
+ {
+ case 0: value = get_directory (iter); break;
+ case 1: value = get_directory (iter).name; break;
+ case 2: value = get_directory (iter).full_name; break;
+ default: assert_not_reached ();
+ }
}
public bool iter_next(ref Gtk.TreeIter iter)
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index c39ef5a..4955610 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -30,6 +30,11 @@ class DConfWindow : ApplicationWindow
[GtkChild] private TreeSelection dir_tree_selection;
[GtkChild] private ListBox key_list_box;
+ private GLib.ListStore bookmarks_model;
+ private GLib.Settings settings;
+ [GtkChild] private Popover bookmarks_popover;
+ [GtkChild] private ListBox bookmarks_list_box;
+
[GtkChild] private SearchBar search_bar;
[GtkChild] private SearchEntry search_entry;
[GtkChild] private Button search_next_button;
@@ -41,6 +46,10 @@ class DConfWindow : ApplicationWindow
model = new SettingsModel ();
dir_tree_view.set_model (model);
+ settings = new GLib.Settings ("ca.desrt.dconf-editor.Settings");
+ settings.changed ["bookmarks"].connect (update_bookmarks);
+ update_bookmarks ();
+
TreeIter iter;
if (model.get_iter_first (out iter))
dir_tree_selection.select_iter (iter);
@@ -251,6 +260,91 @@ class DConfWindow : ApplicationWindow
return true;
}
+
+ /*\
+ * * Bookmarks
+ \*/
+
+ private void update_bookmarks ()
+ {
+ bookmarks_model = new GLib.ListStore (typeof (Bookmark));
+ string [] bookmarks = settings.get_strv ("bookmarks");
+ foreach (string bookmark in bookmarks)
+ bookmarks_model.append (new Bookmark (bookmark));
+ bookmarks_list_box.bind_model (bookmarks_model, new_bookmark_row);
+ }
+
+ [GtkCallback]
+ private void add_bookmark_cb ()
+ {
+ bookmarks_popover.closed ();
+
+ 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);
+ string full_path = full_path_value.get_string ();
+
+ string [] bookmarks = settings.get_strv ("bookmarks");
+ bookmarks += full_path;
+ settings.set_strv ("bookmarks", bookmarks);
+ }
+
+ private Widget new_bookmark_row (Object item)
+ {
+ return (Bookmark) item;
+ }
+
+ [GtkCallback]
+ private void bookmark_activated_cb (ListBoxRow list_box_row)
+ {
+ TreeIter iter;
+ if (model.get_iter_first (out iter))
+ {
+ string full_name = ((Bookmark) list_box_row.get_child ()).full_name;
+ do
+ {
+ Directory dir = model.get_directory (iter);
+
+ if (dir.full_name == full_name)
+ {
+ bookmarks_popover.closed ();
+ select_dir (iter);
+ return;
+ }
+ }
+ 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 ();
+ }
+}
+
+[GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/bookmark.ui")]
+private class Bookmark : Grid
+{
+ public string full_name;
+ [GtkChild] private Label bookmark_label;
+
+ public Bookmark (string _full_name)
+ {
+ this.full_name = _full_name;
+ bookmark_label.set_label (_full_name);
+ }
+
+ [GtkCallback]
+ private void remove_cb ()
+ {
+ GLib.Settings settings = new GLib.Settings ("ca.desrt.dconf-editor.Settings");
+ string [] old_bookmarks = settings.get_strv ("bookmarks");
+ string [] new_bookmarks = new string [0];
+ foreach (string bookmark in old_bookmarks)
+ if (bookmark != full_name)
+ new_bookmarks += bookmark;
+ settings.set_strv ("bookmarks", new_bookmarks);
+ }
}
[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]