[yelp] [yelp-window] First round on the bookmarks editor
- From: Shaun McCance <shaunm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [yelp] [yelp-window] First round on the bookmarks editor
- Date: Thu, 27 May 2010 20:07:41 +0000 (UTC)
commit 64ea4e594c0dbc2de41e0d83c51282408ec62e08
Author: Shaun McCance <shaunm gnome org>
Date: Thu May 27 15:07:19 2010 -0500
[yelp-window] First round on the bookmarks editor
src/yelp-application.c | 26 ++++++
src/yelp-application.h | 3 +
src/yelp-window.c | 210 +++++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 238 insertions(+), 1 deletions(-)
---
diff --git a/src/yelp-application.c b/src/yelp-application.c
index 375e43c..9dcfba0 100644
--- a/src/yelp-application.c
+++ b/src/yelp-application.c
@@ -617,6 +617,32 @@ yelp_application_add_bookmark (YelpApplication *app,
}
void
+yelp_application_remove_bookmark (YelpApplication *app,
+ const gchar *doc_uri,
+ const gchar *page_id)
+{
+ GSettings *settings;
+
+ settings = application_get_doc_settings (app, doc_uri);
+
+ if (settings) {
+ GVariantBuilder builder;
+ GVariantIter *iter;
+ gchar *this_id, *this_icon, *this_title;
+ g_settings_get (settings, "bookmarks", "a(sss)", &iter);
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(sss)"));
+ while (g_variant_iter_loop (iter, "(&s&s&s)", &this_id, &this_icon, &this_title)) {
+ if (!g_str_equal (page_id, this_id))
+ g_variant_builder_add (&builder, "(sss)", this_id, this_icon, this_title);
+ }
+ g_variant_iter_free (iter);
+
+ g_settings_set_value (settings, "bookmarks", g_variant_builder_end (&builder));
+ g_signal_emit (app, signals[BOOKMARKS_CHANGED], 0, doc_uri);
+ }
+}
+
+void
yelp_application_update_bookmarks (YelpApplication *app,
const gchar *doc_uri,
const gchar *page_id,
diff --git a/src/yelp-application.h b/src/yelp-application.h
index bf664a9..7c3aa5c 100644
--- a/src/yelp-application.h
+++ b/src/yelp-application.h
@@ -65,6 +65,9 @@ void yelp_application_add_bookmark (YelpApplication *app,
const gchar *page_id,
const gchar *icon,
const gchar *title);
+void yelp_application_remove_bookmark (YelpApplication *app,
+ const gchar *doc_uri,
+ const gchar *page_id);
void yelp_application_update_bookmarks (YelpApplication *app,
const gchar *doc_uri,
const gchar *page_id,
diff --git a/src/yelp-window.c b/src/yelp-window.c
index 14a126a..ca6a166 100644
--- a/src/yelp-window.c
+++ b/src/yelp-window.c
@@ -70,6 +70,8 @@ static void window_close (GtkAction *action,
YelpWindow *window);
static void window_add_bookmark (GtkAction *action,
YelpWindow *window);
+static void window_edit_bookmarks (GtkAction *action,
+ YelpWindow *window);
static void window_load_bookmark (GtkAction *action,
YelpWindow *window);
static void window_find_in_page (GtkAction *action,
@@ -147,6 +149,18 @@ static gboolean hidden_key_press (GtkWidget *widget,
GdkEventKey *event,
YelpWindow *window);
+static gboolean bookmarks_closed (GtkWindow *bookmarks,
+ GdkEvent *event,
+ YelpWindow *window);
+static void bookmarks_set_bookmarks (YelpWindow *window);
+static void bookmark_activated (GtkTreeView *view,
+ GtkTreePath *path,
+ GtkTreeViewColumn *column,
+ YelpWindow *window);
+static gboolean bookmark_key_release (GtkTreeView *view,
+ GdkEventKey *event,
+ YelpWindow *window);
+
enum {
PROP_0,
PROP_APPLICATION
@@ -209,6 +223,7 @@ static const gchar *YELP_UI =
"</menu>"
"<menu action='BookmarksMenu'>"
"<menuitem action='AddBookmark'/>"
+ "<menuitem action='EditBookmarks'/>"
"<separator/>"
"<placeholder name='Bookmarks'/>"
"</menu>"
@@ -225,6 +240,10 @@ struct _YelpWindowPrivate {
GtkActionGroup *action_group;
YelpApplication *application;
+ GtkWidget *bookmarks_editor;
+ /* no ref */
+ GtkListStore *bookmarks_store;
+
/* no refs on these, owned by containers */
YelpView *view;
GtkWidget *vbox;
@@ -280,6 +299,11 @@ static const GtkActionEntry entries[] = {
"<Control>D",
NULL,
G_CALLBACK (window_add_bookmark) },
+ { "EditBookmarks", NULL,
+ N_("_Edit Bookmarks"),
+ "<Control>B",
+ NULL,
+ G_CALLBACK (window_edit_bookmarks) },
{ "Find", NULL,
N_("Find in Page..."),
"<Control>F",
@@ -381,6 +405,11 @@ yelp_window_dispose (GObject *object)
priv->entry_color_animate = 0;
}
+ if (priv->bookmarks_editor != NULL) {
+ gtk_widget_destroy (GTK_WIDGET (priv->bookmarks_editor));
+ priv->bookmarks_editor = NULL;
+ }
+
G_OBJECT_CLASS (yelp_window_parent_class)->dispose (object);
}
@@ -729,6 +758,66 @@ window_add_bookmark (GtkAction *action,
}
static void
+window_edit_bookmarks (GtkAction *action,
+ YelpWindow *window)
+{
+ YelpWindowPrivate *priv = GET_PRIV (window);
+ GtkWidget *scroll, *list;
+ gchar *title;
+
+ if (priv->bookmarks_editor != NULL) {
+ gtk_window_present_with_time (GTK_WINDOW (priv->bookmarks_editor),
+ gtk_get_current_event_time ());
+ return;
+ }
+
+ priv->bookmarks_editor = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_transient_for (GTK_WINDOW (priv->bookmarks_editor),
+ GTK_WINDOW (window));
+ /* %s will be replaced with the name of a document */
+ title = g_strdup_printf (_("Bookmarks for %s"),
+ gtk_window_get_title (GTK_WINDOW (window)));
+ gtk_window_set_title (GTK_WINDOW (priv->bookmarks_editor), title);
+ g_free (title);
+ gtk_container_set_border_width (GTK_CONTAINER (priv->bookmarks_editor), 6);
+ gtk_window_set_icon_name (GTK_WINDOW (priv->bookmarks_editor), "bookmark");
+ gtk_window_set_default_size (GTK_WINDOW (priv->bookmarks_editor), 300, 300);
+ g_signal_connect (priv->bookmarks_editor, "delete-event",
+ G_CALLBACK (bookmarks_closed), window);
+
+ scroll = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll),
+ GTK_POLICY_AUTOMATIC,
+ GTK_POLICY_AUTOMATIC);
+ gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroll),
+ GTK_SHADOW_IN);
+ gtk_container_add (GTK_CONTAINER (priv->bookmarks_editor), scroll);
+
+ priv->bookmarks_store = gtk_list_store_new (3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
+ list = gtk_tree_view_new_with_model (GTK_TREE_MODEL (priv->bookmarks_store));
+ gtk_container_add (GTK_CONTAINER (scroll), list);
+
+ g_signal_connect (list, "row-activated",
+ G_CALLBACK (bookmark_activated), window);
+ g_signal_connect (list, "key-release-event",
+ G_CALLBACK (bookmark_key_release), window);
+
+ gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (list), FALSE);
+ gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (list), 0, NULL,
+ gtk_cell_renderer_pixbuf_new (),
+ "icon-name", 1,
+ NULL);
+ gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (list), 1, NULL,
+ gtk_cell_renderer_text_new (),
+ "text", 2,
+ NULL);
+
+ bookmarks_set_bookmarks (window);
+
+ gtk_widget_show_all (priv->bookmarks_editor);
+}
+
+static void
window_load_bookmark (GtkAction *action,
YelpWindow *window)
{
@@ -760,8 +849,11 @@ app_bookmarks_changed (YelpApplication *app,
g_object_get (priv->view, "yelp-uri", &uri, NULL);
this_doc_uri = yelp_uri_get_document_uri (uri);
- if (g_str_equal (this_doc_uri, doc_uri))
+ if (g_str_equal (this_doc_uri, doc_uri)) {
window_set_bookmarks (window, doc_uri);
+ if (priv->bookmarks_editor != NULL)
+ bookmarks_set_bookmarks (window);
+ }
g_free (this_doc_uri);
g_object_unref (uri);
@@ -812,6 +904,8 @@ window_set_bookmarks (YelpWindow *window,
entry->title = title;
entries = g_slist_insert_sorted (entries, entry, (GCompareFunc) entry_compare);
}
+ gtk_action_set_sensitive (gtk_action_group_get_action (priv->action_group, "EditBookmarks"),
+ entries != NULL);
for ( ; entries != NULL; entries = g_slist_delete_link (entries, entries)) {
GSList *cur;
GtkAction *bookmark;
@@ -1674,3 +1768,117 @@ hidden_key_press (GtkWidget *widget,
}
return FALSE;
}
+
+static gboolean
+bookmarks_closed (GtkWindow *bookmarks,
+ GdkEvent *event,
+ YelpWindow *window)
+{
+ YelpWindowPrivate *priv = GET_PRIV (window);
+
+ gtk_widget_destroy (GTK_WIDGET (bookmarks));
+ priv->bookmarks_editor = NULL;
+
+ return TRUE;
+}
+
+static void
+bookmarks_set_bookmarks (YelpWindow *window)
+{
+ GVariant *value;
+ GVariantIter *viter;
+ YelpUri *uri;
+ gchar *doc_uri;
+ GSList *entries = NULL;
+ gchar *page_id, *icon, *title; /* do not free */
+ YelpWindowPrivate *priv = GET_PRIV (window);
+
+ gtk_list_store_clear (priv->bookmarks_store);
+
+ g_object_get (priv->view, "yelp-uri", &uri, NULL);
+ doc_uri = yelp_uri_get_document_uri (uri);
+ value = yelp_application_get_bookmarks (priv->application, doc_uri);
+ g_free (doc_uri);
+ g_object_unref (uri);
+
+ g_variant_get (value, "a(sss)", &viter);
+ while (g_variant_iter_loop (viter, "(&s&s&s)", &page_id, &icon, &title)) {
+ YelpMenuEntry *entry = g_new0 (YelpMenuEntry, 1);
+ entry->page_id = page_id;
+ entry->icon = icon;
+ entry->title = title;
+ entries = g_slist_insert_sorted (entries, entry, (GCompareFunc) entry_compare);
+ }
+ for ( ; entries != NULL; entries = g_slist_delete_link (entries, entries)) {
+ GtkTreeIter iter;
+ YelpMenuEntry *entry = (YelpMenuEntry *) entries->data;
+ gtk_list_store_append (priv->bookmarks_store, &iter);
+ gtk_list_store_set (priv->bookmarks_store, &iter,
+ 0, entry->page_id,
+ 1, entry->icon,
+ 2, entry->title,
+ -1);
+ g_free (entry);
+ }
+ g_variant_iter_free (viter);
+ g_variant_unref (value);
+}
+
+static void
+bookmark_activated (GtkTreeView *view,
+ GtkTreePath *path,
+ GtkTreeViewColumn *column,
+ YelpWindow *window)
+{
+ GtkTreeIter iter;
+ YelpWindowPrivate *priv = GET_PRIV (window);
+
+ if (gtk_tree_model_get_iter (GTK_TREE_MODEL (priv->bookmarks_store),
+ &iter, path)) {
+ YelpUri *base, *uri;
+ gchar *page_id, *xref;
+ gtk_tree_model_get (GTK_TREE_MODEL (priv->bookmarks_store), &iter,
+ 0, &page_id,
+ -1);
+ xref = g_strconcat ("xref:", page_id, NULL);
+ g_object_get (priv->view, "yelp-uri", &base, NULL);
+ uri = yelp_uri_new_relative (base, xref);
+
+ yelp_view_load_uri (priv->view, uri);
+
+ g_object_unref (base);
+ g_object_unref (uri);
+ g_free (xref);
+ g_free (page_id);
+ }
+}
+
+static gboolean
+bookmark_key_release (GtkTreeView *view,
+ GdkEventKey *event,
+ YelpWindow *window)
+{
+ if (event->keyval == GDK_Delete) {
+ YelpWindowPrivate *priv = GET_PRIV (window);
+ GtkTreeIter iter;
+ GtkTreeSelection *sel = gtk_tree_view_get_selection (view);
+
+ if (gtk_tree_selection_get_selected (sel, NULL, &iter)) {
+ YelpUri *uri;
+ gchar *doc_uri, *page_id;
+ gtk_tree_model_get (GTK_TREE_MODEL (priv->bookmarks_store), &iter,
+ 0, &page_id,
+ -1);
+ g_object_get (priv->view, "yelp-uri", &uri, NULL);
+ doc_uri = yelp_uri_get_document_uri (uri);
+ yelp_application_remove_bookmark (priv->application, doc_uri, page_id);
+ g_object_unref (uri);
+ g_free (doc_uri);
+ g_free (page_id);
+ }
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]