[dconf-editor] Move bookmarks in a separate file.
- From: Arnaud Bonatti <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dconf-editor] Move bookmarks in a separate file.
- Date: Wed, 14 Oct 2015 23:19:18 +0000 (UTC)
commit 3fe827d2d22d353141fd2e8d49914d38178023ca
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Thu Oct 15 01:13:02 2015 +0200
Move bookmarks in a separate file.
editor/Makefile.am | 4 +-
editor/bookmark.ui | 9 +++-
editor/bookmarks.ui | 91 ++++++++++++++++++++++++++++++++
editor/bookmarks.vala | 104 +++++++++++++++++++++++++++++++++++++
editor/dconf-editor.gresource.xml | 1 +
editor/dconf-editor.ui | 92 ++++-----------------------------
editor/dconf-window.vala | 69 ++----------------------
7 files changed, 222 insertions(+), 148 deletions(-)
---
diff --git a/editor/Makefile.am b/editor/Makefile.am
index fcfaefd..fe7a3ab 100644
--- a/editor/Makefile.am
+++ b/editor/Makefile.am
@@ -27,6 +27,7 @@ resource_data = \
key-list-box-row.ui \
key-editor.ui \
key-editor-no-schema.ui \
+ bookmarks.ui \
bookmark.ui
resources.c: $(resource_data)
@@ -39,7 +40,8 @@ dconf_editor_SOURCES = \
dconf-editor.vala \
dconf-window.vala \
dconf-model.vala \
- dconf-view.vala
+ dconf-view.vala \
+ bookmarks.vala
desktopdir = $(datadir)/applications
desktop_in_files = ca.desrt.dconf-editor.desktop.in.in
diff --git a/editor/bookmark.ui b/editor/bookmark.ui
index 206b034..c7952c2 100644
--- a/editor/bookmark.ui
+++ b/editor/bookmark.ui
@@ -14,14 +14,19 @@
</object>
</child>
<child>
- <object class="GtkButton">
+ <object class="GtkButton" id="destroy_button">
<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 internal-child="accessible">
+ <object class="AtkObject">
+ <property name="AtkObject::accessible-name" translatable="yes">Remove</property>
+ <property name="AtkObject::accessible-description" translatable="yes">Remove this
bookmark</property>
+ </object>
+ </child>
<child>
<object class="GtkImage">
<property name="visible">True</property>
diff --git a/editor/bookmarks.ui b/editor/bookmarks.ui
new file mode 100644
index 0000000..0dfe552
--- /dev/null
+++ b/editor/bookmarks.ui
@@ -0,0 +1,91 @@
+<?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">250</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="Bookmarks" parent="GtkMenuButton">
+ <property name="popover">bookmarks_popover</property>
+ <style>
+ <class name="image-button"/>
+ </style>
+ <child internal-child="accessible">
+ <object class="AtkObject">
+ <property name="AtkObject::accessible-name" translatable="yes">Bookmarks</property>
+ <property name="AtkObject::accessible-description" translatable="yes">Manage your
bookmarks</property>
+ </object>
+ </child>
+ <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>
+ </template>
+</interface>
diff --git a/editor/bookmarks.vala b/editor/bookmarks.vala
new file mode 100644
index 0000000..f7f0b38
--- /dev/null
+++ b/editor/bookmarks.vala
@@ -0,0 +1,104 @@
+/*
+ This file is part of Dconf Editor
+
+ Dconf Editor is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Dconf Editor is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Dconf Editor. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+using Gtk;
+
+[GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/bookmarks.ui")]
+public class Bookmarks : MenuButton
+{
+ [GtkChild] private ListBox bookmarks_list_box;
+ [GtkChild] private Popover bookmarks_popover;
+
+ 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);
+ update_bookmarks ();
+ }
+
+ private void update_bookmarks ()
+ {
+ bookmarks_model = new GLib.ListStore (typeof (Bookmark));
+ string [] bookmarks = settings.get_strv ("bookmarks");
+ foreach (string bookmark in bookmarks)
+ {
+ Bookmark bookmark_row = new Bookmark (bookmark);
+ bookmark_row.destroy_button.clicked.connect (() => { remove_bookmark (bookmark); });
+ bookmarks_model.append (bookmark_row);
+ }
+ bookmarks_list_box.bind_model (bookmarks_model, new_bookmark_row);
+ }
+
+ [GtkCallback]
+ private void add_bookmark_cb ()
+ {
+ bookmarks_popover.closed ();
+
+ string path = get_current_path ();
+
+ string [] bookmarks = settings.get_strv ("bookmarks");
+ bookmarks += 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)
+ {
+ bookmarks_popover.closed ();
+ string bookmark = ((Bookmark) list_box_row.get_child ()).bookmark_name;
+ if (!bookmark_activated (bookmark))
+ warning ("broken bookmark: %s", bookmark);
+ }
+
+ private void remove_bookmark (string bookmark_name)
+ {
+ bookmarks_popover.closed ();
+ string [] old_bookmarks = settings.get_strv ("bookmarks");
+ string [] new_bookmarks = new string [0];
+ foreach (string bookmark in old_bookmarks)
+ if (bookmark != bookmark_name)
+ new_bookmarks += bookmark;
+ settings.set_strv ("bookmarks", new_bookmarks);
+ }
+}
+
+[GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/bookmark.ui")]
+private class Bookmark : Grid
+{
+ public string bookmark_name { get; private set; }
+
+ [GtkChild] private Label bookmark_label;
+ [GtkChild] public Button destroy_button;
+
+ public Bookmark (string name)
+ {
+ bookmark_name = name;
+ bookmark_label.set_label (name);
+ }
+}
diff --git a/editor/dconf-editor.gresource.xml b/editor/dconf-editor.gresource.xml
index 48650c4..e87969f 100644
--- a/editor/dconf-editor.gresource.xml
+++ b/editor/dconf-editor.gresource.xml
@@ -2,6 +2,7 @@
<gresources>
<gresource prefix="/ca/desrt/dconf-editor/ui">
<file preprocess="xml-stripblanks">bookmark.ui</file>
+ <file preprocess="xml-stripblanks">bookmarks.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 5c799be..474cd01 100644
--- a/editor/dconf-editor.ui
+++ b/editor/dconf-editor.ui
@@ -1,74 +1,6 @@
<?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">250</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>
@@ -93,6 +25,12 @@ be added here</property> <!-- line wrap wanted -->
<style>
<class name="image-button"/>
</style>
+ <child internal-child="accessible">
+ <object class="AtkObject">
+ <property name="AtkObject::accessible-name" translatable="yes">Search</property>
+ <property name="AtkObject::accessible-description" translatable="yes">Search keys</property>
+ </object>
+ </child>
<child>
<object class="GtkImage">
<property name="visible">True</property>
@@ -106,21 +44,11 @@ be added here</property> <!-- line wrap wanted -->
</packing>
</child>
<child>
- <object class="GtkMenuButton">
+ <object class="Bookmarks">
<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>
+ <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 d26e634..24475ba 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -31,10 +31,7 @@ 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;
@@ -55,9 +52,6 @@ class DConfWindow : ApplicationWindow
model = new SettingsModel ();
dir_tree_view.set_model (model);
- settings.changed ["bookmarks"].connect (update_bookmarks);
- update_bookmarks ();
-
current_path = settings.get_string ("saved-view");
if (!settings.get_boolean ("restore-view") || current_path == "/" || current_path == "" ||
!scroll_to_path (current_path))
{
@@ -289,47 +283,19 @@ class DConfWindow : ApplicationWindow
* * 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 ()
+ private string get_current_path ()
{
- 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;
+ return full_path_value.get_string ();
}
[GtkCallback]
- private void bookmark_activated_cb (ListBoxRow list_box_row)
- {
- if (scroll_to_path (((Bookmark) list_box_row.get_child ()).full_name))
- return;
- MessageDialog dialog = new MessageDialog (this, DialogFlags.MODAL, MessageType.ERROR,
ButtonsType.OK, _("Oops! Cannot find something at this path."));
- dialog.run ();
- dialog.destroy ();
- }
-
private bool scroll_to_path (string full_name)
{
TreeIter iter;
@@ -341,42 +307,19 @@ class DConfWindow : ApplicationWindow
if (dir.full_name == full_name)
{
- bookmarks_popover.closed ();
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/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")]
private class KeyListBoxRow : EventBox
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]