23 #include <glib/gi18n.h>
66 static const gchar popup_menu_ui[] =
67 "<popup
name=\"BookmarksPopup\" action=\"BookmarksPopupAction\">\n"
68 " <menuitem
name=\"OpenBookmark\" action=\"OpenBookmark\"/>\n"
70 " <menuitem
name=\"RenameBookmark\" action=\"RenameBookmark\"/>\n"
71 " <menuitem
name=\"RemoveBookmark\" action=\"RemoveBookmark\"/>\n"
76 GtkTreeSelection *selection)
81 if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
84 gtk_tree_model_get (model, &iter,
98 GtkTreeSelection *selection;
101 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->
tree_view));
102 page = ev_sidebar_bookmarks_get_selected_page (sidebar_bookmarks, selection);
111 GtkTreeView *tree_view = GTK_TREE_VIEW (priv->
tree_view);
112 GtkTreeSelection *selection;
117 selection = gtk_tree_view_get_selection (tree_view);
118 if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
121 path = gtk_tree_model_get_path (model, &iter);
122 gtk_tree_view_set_cursor (tree_view, path,
123 gtk_tree_view_get_column (tree_view, 0),
125 gtk_tree_path_free (path);
134 GtkTreeSelection *selection;
138 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->
tree_view));
139 page = ev_sidebar_bookmarks_get_selected_page (sidebar_bookmarks, selection);
146 {
"OpenBookmark", GTK_STOCK_OPEN, N_(
"_Open Bookmark"), NULL,
148 {
"RenameBookmark", NULL, N_(
"_Rename Bookmark"), NULL,
150 {
"RemoveBookmark", NULL, N_(
"_Remove Bookmark"), NULL,
173 model = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (priv->
tree_view)));
174 gtk_list_store_clear (model);
183 for (l = items; l; l = g_list_next (l)) {
186 gtk_list_store_append (model, &iter);
187 gtk_list_store_set (model, &iter,
210 page = ev_sidebar_bookmarks_get_selected_page (sidebar_bookmarks, selection);
224 GtkTreeSelection *selection;
228 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->
tree_view));
229 page = ev_sidebar_bookmarks_get_selected_page (sidebar_bookmarks, selection);
240 const gchar *path_string,
241 const gchar *new_text,
245 GtkTreePath *path = gtk_tree_path_new_from_string (path_string);
251 if (!new_text || new_text[0] ==
'\0')
254 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->
tree_view));
255 gtk_tree_model_get_iter (model, &iter, path);
256 gtk_tree_model_get (model, &iter,
259 gtk_tree_path_free (path);
262 bm.
title = g_markup_escape_text (new_text, -1);
270 gboolean keyboard_tip,
277 GtkTreePath *path = NULL;
283 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->
tree_view));
284 if (!gtk_tree_view_get_tooltip_context (GTK_TREE_VIEW (priv->
tree_view),
285 &x, &y, keyboard_tip,
286 &model, &path, &iter))
289 gtk_tree_model_get (model, &iter,
295 text = g_strdup_printf (
_(
"Page %s"), page_label);
296 gtk_tooltip_set_text (tooltip, text);
300 gtk_tree_view_set_tooltip_row (GTK_TREE_VIEW (priv->
tree_view),
302 gtk_tree_path_free (path);
311 gboolean keyboard_mode)
314 GtkTreeView *tree_view = GTK_TREE_VIEW (sidebar_bookmarks->priv->tree_view);
315 GtkTreeSelection *selection = gtk_tree_view_get_selection (tree_view);
318 if (!gtk_tree_selection_get_selected (selection, NULL, NULL))
323 if (!gtk_tree_view_get_path_at_pos (tree_view, x, y, &path, NULL, NULL, NULL))
326 g_signal_handlers_block_by_func (selection,
329 gtk_tree_view_set_cursor (tree_view, path, NULL,
FALSE);
330 g_signal_handlers_unblock_by_func (selection,
333 gtk_tree_path_free (path);
337 priv->
popup = gtk_ui_manager_get_widget (priv->
ui_manager,
"/BookmarksPopup");
339 gtk_menu_popup (GTK_MENU (priv->
popup),
342 keyboard_mode ? tree_view : NULL,
343 keyboard_mode ? 0 : 3,
344 gtk_get_current_event_time ());
350 GdkEventButton *event,
353 if (event->button != 3)
376 g_object_unref (priv->
model);
395 G_OBJECT_CLASS (ev_sidebar_bookmarks_parent_class)->dispose (
object);
405 GtkCellRenderer *renderer;
406 GtkTreeSelection *selection;
408 sidebar_bookmarks->priv = G_TYPE_INSTANCE_GET_PRIVATE (sidebar_bookmarks,
411 priv = sidebar_bookmarks->priv;
413 swindow = gtk_scrolled_window_new (NULL, NULL);
414 gtk_box_pack_start (GTK_BOX (sidebar_bookmarks), swindow,
TRUE,
TRUE, 0);
415 gtk_widget_show (swindow);
417 model = gtk_list_store_new (
N_COLUMNS, G_TYPE_STRING, G_TYPE_UINT);
418 priv->
tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model));
419 g_object_unref (model);
420 g_signal_connect (priv->
tree_view,
"query-tooltip",
424 "button-press-event",
427 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->
tree_view),
FALSE);
428 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->
tree_view));
429 g_signal_connect (selection,
"changed",
433 renderer = gtk_cell_renderer_text_new ();
434 g_object_set (renderer,
435 "ellipsize", PANGO_ELLIPSIZE_END,
438 g_signal_connect (renderer,
"edited",
441 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->
tree_view),
445 gtk_container_add (GTK_CONTAINER (swindow), priv->
tree_view);
448 hbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
449 gtk_widget_set_margin_top (hbox, 2);
450 gtk_widget_set_margin_bottom (hbox, 2);
451 gtk_widget_set_margin_start (hbox, 2);
452 gtk_widget_set_margin_end (hbox, 2);
453 gtk_button_box_set_layout (GTK_BUTTON_BOX (hbox), GTK_BUTTONBOX_CENTER);
454 gtk_style_context_add_class (gtk_widget_get_style_context (hbox), GTK_STYLE_CLASS_LINKED);
456 priv->
add_button = gtk_button_new_with_label (
_(
"Add"));
457 gtk_actionable_set_action_name (GTK_ACTIONABLE (priv->
add_button),
463 priv->
del_button = gtk_button_new_with_label (
_(
"Remove"));
464 g_signal_connect (priv->
del_button,
"clicked",
471 gtk_box_pack_end (GTK_BOX (sidebar_bookmarks), hbox,
FALSE,
TRUE, 0);
472 gtk_widget_show (hbox);
473 gtk_widget_show (GTK_WIDGET (sidebar_bookmarks));
476 priv->
action_group = gtk_action_group_new (
"BookmarsPopupActions");
477 gtk_action_group_set_translation_domain (priv->
action_group, NULL);
478 gtk_action_group_add_actions (priv->
action_group, popup_entries,
479 G_N_ELEMENTS (popup_entries),
482 gtk_ui_manager_insert_action_group (priv->
ui_manager,
484 gtk_ui_manager_add_ui_from_string (priv->
ui_manager, popup_menu_ui, -1, NULL);
499 g_value_set_object (value, sidebar_bookmarks->priv->tree_view);
502 G_OBJECT_WARN_INVALID_PROPERTY_ID (
object, prop_id, pspec);
510 GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
511 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
520 g_object_class_override_property (g_object_class,
PROP_WIDGET,
"main-widget");
527 "orientation", GTK_ORIENTATION_VERTICAL,
544 priv->
bookmarks = g_object_ref (bookmarks);
545 g_signal_connect (priv->
bookmarks,
"changed",
561 if (priv->
model == model)
565 g_object_unref (priv->
model);
566 priv->
model = g_object_ref (model);
579 return _(
"Bookmarks");