summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/yelp-application.c16
-rw-r--r--src/yelp-window.c717
-rw-r--r--src/yelp-window.h4
3 files changed, 335 insertions, 402 deletions
diff --git a/src/yelp-application.c b/src/yelp-application.c
index 2ac1f998..0b810cc7 100644
--- a/src/yelp-application.c
+++ b/src/yelp-application.c
@@ -141,6 +141,22 @@ yelp_application_init (YelpApplication *app)
priv->docsettings = g_hash_table_new_full (g_str_hash, g_str_equal,
(GDestroyNotify) g_free,
(GDestroyNotify) g_object_unref);
+ gtk_application_add_accelerator (GTK_APPLICATION (app),
+ "<Control>f",
+ "win.find",
+ NULL);
+ gtk_application_add_accelerator (GTK_APPLICATION (app),
+ "<Control>s",
+ "win.search",
+ NULL);
+ gtk_application_add_accelerator (GTK_APPLICATION (app),
+ "<Alt>Left",
+ "win.yelp-view-go-back",
+ NULL);
+ gtk_application_add_accelerator (GTK_APPLICATION (app),
+ "<Alt>Right",
+ "win.yelp-view-go-forward",
+ NULL);
}
static void
diff --git a/src/yelp-window.c b/src/yelp-window.c
index d36c8fee..9ce10dac 100644
--- a/src/yelp-window.c
+++ b/src/yelp-window.c
@@ -26,9 +26,10 @@
#include <gdk/gdkkeysyms.h>
#include <glib/gi18n.h>
+#include <gio/gio.h>
#include <gtk/gtk.h>
-#include "yelp-location-entry.h"
+#include "yelp-search-entry.h"
#include "yelp-settings.h"
#include "yelp-uri.h"
#include "yelp-view.h"
@@ -50,8 +51,7 @@ static void yelp_window_set_property (GObject *object,
GParamSpec *pspec);
static void window_construct (YelpWindow *window);
-static void window_new (GtkAction *action,
- YelpWindow *window);
+
static gboolean window_map_event (YelpWindow *window,
GdkEvent *event,
gpointer user_data);
@@ -67,19 +67,18 @@ static void window_drag_received (YelpWindow *window,
guint time,
gpointer userdata);
static gboolean window_resize_signal (YelpWindow *window);
-static void window_close (GtkAction *action,
- YelpWindow *window);
-static void window_go_all (GtkAction *action,
- YelpWindow *window);
-static void window_add_bookmark (GtkAction *action,
- YelpWindow *window);
-static void window_remove_bookmark (GtkAction *action,
+
+static void bookmark_activated (GtkListBox *box,
+ GtkListBoxRow *row,
YelpWindow *window);
-static void window_load_bookmark (GtkAction *action,
+static void bookmark_removed (GtkButton *button,
YelpWindow *window);
-static void window_find_in_page (GtkAction *action,
+static void bookmark_added (GtkButton *button,
YelpWindow *window);
-static void window_start_search (GtkAction *action,
+
+
+/* FIXME: all below */
+static void window_go_all (GtkAction *action,
YelpWindow *window);
static void window_open_location (GtkAction *action,
YelpWindow *window);
@@ -95,23 +94,28 @@ static void app_bookmarks_changed (YelpApplication *app,
YelpWindow *window);
static void window_set_bookmarks (YelpWindow *window,
const gchar *doc_uri);
-static void window_set_bookmark_action (YelpWindow *window);
-static gboolean find_entry_focus_out (GtkEntry *entry,
- GdkEventFocus *event,
- YelpWindow *window);
+static void window_set_bookmark_buttons (YelpWindow *window);
+
+static void action_new_window (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer userdata);
+static void action_print (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer userdata);
+static void action_search (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer userdata);
+static void action_find (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer userdata);
+
+
static gboolean find_entry_key_press (GtkEntry *entry,
GdkEventKey *event,
YelpWindow *window);
static void find_entry_changed (GtkEntry *entry,
YelpWindow *window);
-static gboolean entry_focus_in (GtkEntry *entry,
- GdkEventFocus *event,
- YelpWindow *window);
-static gboolean entry_focus_out (YelpLocationEntry *entry,
- GdkEventFocus *event,
- YelpWindow *window);
-
static void view_new_window (YelpView *view,
YelpUri *uri,
YelpWindow *window);
@@ -147,9 +151,10 @@ enum {
static guint signals[LAST_SIGNAL] = { 0 };
-G_DEFINE_TYPE (YelpWindow, yelp_window, GTK_TYPE_WINDOW);
+G_DEFINE_TYPE (YelpWindow, yelp_window, GTK_TYPE_APPLICATION_WINDOW);
#define GET_PRIV(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), YELP_TYPE_WINDOW, YelpWindowPrivate))
+#if 0
static const gchar *YELP_UI =
"<ui>"
"<menubar>"
@@ -187,88 +192,51 @@ static const gchar *YELP_UI =
"<accelerator action='Search'/>"
"<accelerator action='OpenLocation'/>"
"</ui>";
+#endif
typedef struct _YelpWindowPrivate YelpWindowPrivate;
struct _YelpWindowPrivate {
- GtkListStore *history;
- GtkUIManager *ui_manager;
- GtkActionGroup *action_group;
YelpApplication *application;
gulong bookmarks_changed;
gulong read_later_changed;
/* no refs on these, owned by containers */
- YelpView *view;
+ GtkWidget *header;
GtkWidget *vbox_view;
GtkWidget *vbox_full;
- GtkWidget *hbox;
- YelpLocationEntry *entry;
- GtkWidget *hidden_entry;
+ GtkWidget *search_bar;
+ GtkWidget *search_entry;
+ GtkWidget *find_bar;
GtkWidget *find_entry;
- GtkWidget *find_label;
+ GtkWidget *bookmark_menu;
+ GtkWidget *bookmark_list;
+ GtkWidget *bookmark_add;
+ GtkWidget *bookmark_remove;
+ YelpView *view;
+
+ GtkWidget *hidden_entry;
GtkWidget *read_later_vbox;
/* refs because we dynamically add & remove */
- GtkWidget *find_bar;
GtkWidget *align_location;
GtkWidget *align_hidden;
GtkWidget *read_later;
gchar *doc_uri;
- GtkActionGroup *bookmark_actions;
- guint bookmarks_merge_id;
-
guint resize_signal;
gint width;
gint height;
- guint entry_color_animate;
- gfloat entry_color_step;
-
gboolean configured;
};
-static const GtkActionEntry entries[] = {
- { "PageMenu", NULL, N_("_Page") },
- { "ViewMenu", NULL, N_("_View") },
- { "GoMenu", NULL, N_("_Go") },
- { "BookmarksMenu", NULL, N_("_Bookmarks") },
-
- { "NewWindow", NULL,
- N_("_New Window"),
- "<Control>N",
- NULL,
- G_CALLBACK (window_new) },
- { "CloseWindow", NULL,
- N_("_Close"),
- "<Control>W",
- NULL,
- G_CALLBACK (window_close) },
+static const GtkActionEntry gtkentries[] = {
{ "GoAll", NULL,
N_("_All Documents"),
NULL, NULL,
G_CALLBACK (window_go_all) },
- { "AddBookmark", NULL,
- N_("_Add Bookmark"),
- "<Control>D",
- NULL,
- G_CALLBACK (window_add_bookmark) },
- { "RemoveBookmark", NULL,
- N_("_Remove Bookmark"),
- NULL, NULL,
- G_CALLBACK (window_remove_bookmark) },
- { "Find", NULL,
- N_("Find in Page..."),
- "<Control>F",
- NULL,
- G_CALLBACK (window_find_in_page) },
- { "Search", NULL,
- N_("Search..."),
- "<Control>S",
- NULL,
- G_CALLBACK (window_start_search) },
{ "OpenLocation", NULL,
N_("Open Location"),
"<Control>L",
@@ -319,21 +287,6 @@ yelp_window_dispose (GObject *object)
{
YelpWindowPrivate *priv = GET_PRIV (object);
- if (priv->history) {
- g_object_unref (priv->history);
- priv->history = NULL;
- }
-
- if (priv->action_group) {
- g_object_unref (priv->action_group);
- priv->action_group = NULL;
- }
-
- if (priv->bookmark_actions) {
- g_object_unref (priv->bookmark_actions);
- priv->bookmark_actions = NULL;
- }
-
if (priv->read_later_changed) {
g_source_remove (priv->read_later_changed);
priv->read_later_changed = 0;
@@ -354,16 +307,6 @@ yelp_window_dispose (GObject *object)
priv->align_hidden = NULL;
}
- if (priv->find_bar) {
- g_object_unref (priv->find_bar);
- priv->find_bar = NULL;
- }
-
- if (priv->entry_color_animate != 0) {
- g_source_remove (priv->entry_color_animate);
- priv->entry_color_animate = 0;
- }
-
G_OBJECT_CLASS (yelp_window_parent_class)->dispose (object);
}
@@ -416,14 +359,24 @@ window_construct (YelpWindow *window)
GtkWidget *scroll;
GtkActionGroup *view_actions;
GtkAction *action;
- GtkWidget *vbox, *button, *label;
+ GtkWidget *box, *button, *sw;
gchar *color, *text;
YelpWindowPrivate *priv = GET_PRIV (window);
- gtk_window_set_icon_name (GTK_WINDOW (window), "help-browser");
+ const GActionEntry entries[] = {
+ { "new-window", action_new_window, NULL, NULL, NULL },
+ { "print", action_print, NULL, NULL, NULL },
+ { "search", action_search, NULL, NULL, NULL },
+ { "find", action_find, NULL, NULL, NULL },
+ };
+ gtk_window_set_icon_name (GTK_WINDOW (window), "help-browser");
priv->view = (YelpView *) yelp_view_new ();
+ g_action_map_add_action_entries (G_ACTION_MAP (window),
+ entries, G_N_ELEMENTS (entries), window);
+ yelp_view_register_actions (priv->view, G_ACTION_MAP (window));
+
action = gtk_action_new ("ReadLinkLater", _("Read Link _Later"), NULL, NULL);
g_signal_connect (action, "activate", G_CALLBACK (window_read_later), window);
yelp_view_add_link_action (priv->view, action,
@@ -436,110 +389,139 @@ window_construct (YelpWindow *window)
priv->vbox_full = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
gtk_container_add (GTK_CONTAINER (window), priv->vbox_full);
+ priv->header = gtk_header_bar_new ();
+ gtk_header_bar_set_show_close_button (GTK_HEADER_BAR (priv->header), TRUE);
+ gtk_window_set_titlebar (GTK_WINDOW (window), priv->header);
+
+ /** Back/Forward **/
+ box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+ gtk_style_context_add_class (gtk_widget_get_style_context (box), "linked");
+ gtk_header_bar_pack_start (GTK_HEADER_BAR (priv->header), box);
+
+ button = gtk_button_new_from_icon_name ("go-previous-symbolic", GTK_ICON_SIZE_MENU);
+ gtk_style_context_add_class (gtk_widget_get_style_context (button), "image-button");
+ gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
+ g_object_set (button, "action-name", "win.yelp-view-go-back", NULL);
+
+ button = gtk_button_new_from_icon_name ("go-next-symbolic", GTK_ICON_SIZE_MENU);
+ gtk_style_context_add_class (gtk_widget_get_style_context (button), "image-button");
+ gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
+ g_object_set (button, "action-name", "win.yelp-view-go-forward", NULL);
+
+ /** Menu **/
+ button = gtk_menu_button_new ();
+ gtk_style_context_add_class (gtk_widget_get_style_context (button), "image-button");
+ gtk_button_set_image (GTK_BUTTON (button),
+ gtk_image_new_from_icon_name ("emblem-system-symbolic",
+ GTK_ICON_SIZE_MENU));
+ gtk_header_bar_pack_end (GTK_HEADER_BAR (priv->header), button);
+
+ /** Search **/
priv->vbox_view = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_box_pack_start (GTK_BOX (priv->vbox_full), priv->vbox_view, TRUE, TRUE, 0);
- priv->action_group = gtk_action_group_new ("YelpWindowActions");
- gtk_action_group_set_translation_domain (priv->action_group, GETTEXT_PACKAGE);
- gtk_action_group_add_actions (priv->action_group,
- entries, G_N_ELEMENTS (entries),
- window);
-
+ priv->search_bar = gtk_search_bar_new ();
+ gtk_box_pack_start (GTK_BOX (priv->vbox_view), priv->search_bar, FALSE, FALSE, 0);
+ priv->search_entry = yelp_search_entry_new (priv->view,
+ YELP_BOOKMARKS (priv->application));
+ g_object_set (priv->search_entry, "width-request", 400, NULL);
+ gtk_container_add (GTK_CONTAINER (priv->search_bar), priv->search_entry);
+ button = gtk_toggle_button_new ();
+ gtk_style_context_add_class (gtk_widget_get_style_context (button), "image-button");
+ gtk_button_set_image (GTK_BUTTON (button),
+ gtk_image_new_from_icon_name ("edit-find-symbolic",
+ GTK_ICON_SIZE_MENU));
+ g_object_bind_property (button, "active",
+ priv->search_bar, "search-mode-enabled",
+ G_BINDING_BIDIRECTIONAL);
+ gtk_header_bar_pack_end (GTK_HEADER_BAR (priv->header), button);
+
+ /** Bookmarks **/
+ button = gtk_menu_button_new ();
+ gtk_style_context_add_class (gtk_widget_get_style_context (button), "image-button");
+ gtk_button_set_image (GTK_BUTTON (button),
+ gtk_image_new_from_icon_name ("yelp-bookmark-remove-symbolic",
+ GTK_ICON_SIZE_MENU));
+ gtk_header_bar_pack_end (GTK_HEADER_BAR (priv->header), button);
+
+ priv->bookmark_menu = gtk_popover_new (button);
+ g_object_set (priv->bookmark_menu, "border-width", 12, NULL);
+ gtk_menu_button_set_popover (GTK_MENU_BUTTON (button), priv->bookmark_menu);
+
+ box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
+ gtk_container_add (GTK_CONTAINER (priv->bookmark_menu), box);
+ sw = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
+ GTK_POLICY_AUTOMATIC,
+ GTK_POLICY_AUTOMATIC);
+ gtk_box_pack_start (GTK_BOX (box), sw, TRUE, TRUE, 0);
+ priv->bookmark_list = gtk_list_box_new ();
+ g_object_set (priv->bookmark_list, "selection-mode", GTK_SELECTION_NONE, NULL);
+ g_signal_connect (priv->bookmark_list, "row-activated",
+ G_CALLBACK (bookmark_activated), window);
+ gtk_container_add (GTK_CONTAINER (box), priv->bookmark_list);
+
+ priv->bookmark_add = gtk_button_new_with_label (_("Add Bookmark"));
+ g_signal_connect (priv->bookmark_add, "clicked",
+ G_CALLBACK (bookmark_added), window);
+ gtk_box_pack_end (GTK_BOX (box), priv->bookmark_add, FALSE, FALSE, 0);
+ gtk_widget_show_all (box);
+
+ priv->bookmark_remove = gtk_button_new_with_label (_("Remove Bookmark"));
+ g_signal_connect (priv->bookmark_remove, "clicked",
+ G_CALLBACK (bookmark_removed), window);
+ gtk_box_pack_end (GTK_BOX (box), priv->bookmark_remove, FALSE, FALSE, 0);
+ gtk_widget_show_all (box);
+
+#if 0
priv->bookmark_actions = gtk_action_group_new ("BookmarkActions");
gtk_action_group_set_translate_func (priv->bookmark_actions, NULL, NULL, NULL);
+#endif
- priv->ui_manager = gtk_ui_manager_new ();
- gtk_ui_manager_insert_action_group (priv->ui_manager, priv->action_group, 0);
- gtk_ui_manager_insert_action_group (priv->ui_manager, priv->bookmark_actions, 1);
- gtk_ui_manager_insert_action_group (priv->ui_manager,
- yelp_application_get_action_group (priv->application),
- 2);
- view_actions = yelp_view_get_action_group (priv->view);
- gtk_ui_manager_insert_action_group (priv->ui_manager, view_actions, 3);
- gtk_window_add_accel_group (GTK_WINDOW (window),
- gtk_ui_manager_get_accel_group (priv->ui_manager));
- gtk_ui_manager_add_ui_from_string (priv->ui_manager, YELP_UI, -1, NULL);
- gtk_box_pack_start (GTK_BOX (priv->vbox_view),
- gtk_ui_manager_get_widget (priv->ui_manager, "/ui/menubar"),
- FALSE, FALSE, 0);
-
- priv->bookmarks_merge_id = gtk_ui_manager_new_merge_id (priv->ui_manager);
priv->bookmarks_changed =
g_signal_connect (priv->application, "bookmarks-changed",
G_CALLBACK (app_bookmarks_changed), window);
- priv->hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
- g_object_set (priv->hbox, "border-width", 2, NULL);
- gtk_box_pack_start (GTK_BOX (priv->vbox_view), priv->hbox, FALSE, FALSE, 0);
+ /** Find **/
+ priv->find_bar = gtk_search_bar_new ();
+ gtk_search_bar_set_show_close_button (GTK_SEARCH_BAR (priv->find_bar), TRUE);
+ gtk_box_pack_start (GTK_BOX (priv->vbox_view), priv->find_bar, FALSE, FALSE, 0);
+ box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+ g_object_set (box, "width-request", 300, NULL);
+ gtk_style_context_add_class (gtk_widget_get_style_context (box), "linked");
+ gtk_container_add (GTK_CONTAINER (priv->find_bar), box);
+
+ priv->find_entry = gtk_search_entry_new ();
+ gtk_box_pack_start (GTK_BOX (box), priv->find_entry, TRUE, TRUE, 0);
+ gtk_search_bar_connect_entry (GTK_SEARCH_BAR (priv->find_bar), GTK_ENTRY (priv->find_entry));
+ g_signal_connect (priv->find_entry, "changed",
+ G_CALLBACK (find_entry_changed), window);
+ g_signal_connect (priv->find_entry, "key-press-event",
+ G_CALLBACK (find_entry_key_press), window);
- action = gtk_action_group_get_action (view_actions, "YelpViewGoBack");
- button = gtk_action_create_tool_item (action);
- gtk_box_pack_start (GTK_BOX (priv->hbox),
- button,
- FALSE, FALSE, 0);
- action = gtk_action_group_get_action (view_actions, "YelpViewGoForward");
- button = gtk_action_create_tool_item (action);
- gtk_box_pack_start (GTK_BOX (priv->hbox),
- button,
- FALSE, FALSE, 0);
+ button = gtk_button_new_from_icon_name ("go-up-symbolic", GTK_ICON_SIZE_MENU);
+ gtk_style_context_add_class (gtk_widget_get_style_context (button), "raised");
+ gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
+ /* FIXME: signal_connect */
- priv->entry = (YelpLocationEntry *) yelp_location_entry_new (priv->view,
- YELP_BOOKMARKS (priv->application));
- g_signal_connect (gtk_bin_get_child (GTK_BIN (priv->entry)), "focus-in-event",
- G_CALLBACK (entry_focus_in), window);
- g_signal_connect (priv->entry, "focus-out-event",
- G_CALLBACK (entry_focus_out), window);
-
- priv->align_location = g_object_ref_sink (gtk_alignment_new (0.0, 0.5, 1.0, 0.0));
- gtk_box_pack_start (GTK_BOX (priv->hbox),
- GTK_WIDGET (priv->align_location),
- TRUE, TRUE, 0);
- gtk_container_add (GTK_CONTAINER (priv->align_location), GTK_WIDGET (priv->entry));
-
- priv->hidden_entry = gtk_entry_new ();
- priv->align_hidden = g_object_ref_sink (gtk_alignment_new (0.0, 0.5, 1.0, 0.0));
- gtk_container_add (GTK_CONTAINER (priv->align_hidden), GTK_WIDGET (priv->hidden_entry));
-
- g_signal_connect (priv->hidden_entry, "activate",
- G_CALLBACK (hidden_entry_activate), window);
- g_signal_connect_swapped (priv->hidden_entry, "focus-out-event",
- G_CALLBACK (hidden_entry_hide), window);
- g_signal_connect (priv->hidden_entry, "key-press-event",
- G_CALLBACK (hidden_key_press), window);
+ button = gtk_button_new_from_icon_name ("go-down-symbolic", GTK_ICON_SIZE_MENU);
+ gtk_style_context_add_class (gtk_widget_get_style_context (button), "raised");
+ gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
+ /* FIXME: signal_connect */
+
+ gtk_widget_show_all (priv->find_bar);
+ /** View **/
scroll = gtk_scrolled_window_new (NULL, NULL);
+ g_object_set (scroll, "width-request", 420, 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_box_pack_start (GTK_BOX (priv->vbox_view), scroll, TRUE, TRUE, 0);
- priv->find_bar = g_object_ref_sink (gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6));
- g_object_set (priv->find_bar,
- "border-width", 2,
- "margin-right", 16,
- NULL);
-
- label = gtk_label_new (_("Find:"));
- gtk_box_pack_start (GTK_BOX (priv->find_bar), label, FALSE, FALSE, 6);
-
- priv->find_entry = gtk_entry_new ();
- g_signal_connect (priv->find_entry, "changed",
- G_CALLBACK (find_entry_changed), window);
- g_signal_connect (priv->find_entry, "key-press-event",
- G_CALLBACK (find_entry_key_press), window);
- g_signal_connect (priv->find_entry, "focus-out-event",
- G_CALLBACK (find_entry_focus_out), window);
- g_object_set (priv->find_entry, "width-request", 300, NULL);
- gtk_box_pack_start (GTK_BOX (priv->find_bar), priv->find_entry, FALSE, FALSE, 0);
-
- priv->find_label = gtk_label_new ("");
- g_object_set (priv->find_label, "xalign", 0.0, NULL);
- gtk_box_pack_start (GTK_BOX (priv->find_bar), priv->find_label, FALSE, FALSE, 0);
-
+ /** Read Later **/
priv->read_later = g_object_ref_sink (gtk_info_bar_new ());
- vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
+ box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
color = yelp_settings_get_color (yelp_settings_get_default (),
YELP_SETTINGS_COLOR_TEXT_LIGHT);
text = g_markup_printf_escaped ("<span weight='bold' color='%s'>%s</span>",
@@ -548,19 +530,19 @@ window_construct (YelpWindow *window)
g_object_set (button, "use-markup", TRUE, "xalign", 0.0, NULL);
g_free (color);
g_free (text);
- gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (gtk_info_bar_get_content_area (GTK_INFO_BAR (priv->read_later))),
- vbox,
+ box,
FALSE, FALSE, 0);
priv->read_later_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
- gtk_box_pack_start (GTK_BOX (vbox), priv->read_later_vbox, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (box), priv->read_later_vbox, FALSE, FALSE, 0);
g_signal_connect (priv->view, "new-view-requested", G_CALLBACK (view_new_window), window);
g_signal_connect (priv->view, "loaded", G_CALLBACK (view_loaded), window);
g_signal_connect (priv->view, "notify::yelp-uri", G_CALLBACK (view_uri_selected), window);
g_signal_connect_swapped (priv->view, "notify::page-id",
- G_CALLBACK (window_set_bookmark_action), window);
- window_set_bookmark_action (window);
+ G_CALLBACK (window_set_bookmark_buttons), window);
+ window_set_bookmark_buttons (window);
g_signal_connect (priv->view, "notify::root-title", G_CALLBACK (view_root_title), window);
gtk_container_add (GTK_CONTAINER (scroll), GTK_WIDGET (priv->view));
gtk_widget_grab_focus (GTK_WIDGET (priv->view));
@@ -617,10 +599,13 @@ yelp_window_get_geometry (YelpWindow *window,
/******************************************************************************/
static void
-window_new (GtkAction *action, YelpWindow *window)
+action_new_window (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer userdata)
{
YelpUri *yuri;
gchar *uri = NULL;
+ YelpWindow *window = YELP_WINDOW (userdata);
YelpWindowPrivate *priv = GET_PRIV (window);
g_object_get (priv->view, "yelp-uri", &yuri, NULL);
@@ -633,6 +618,40 @@ window_new (GtkAction *action, YelpWindow *window)
}
static void
+action_print (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer userdata)
+{
+ /* FIXME */
+}
+
+static void
+action_search (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer userdata)
+{
+ YelpWindowPrivate *priv = GET_PRIV (userdata);
+
+ gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (priv->find_bar), FALSE);
+ gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (priv->search_bar), TRUE);
+ gtk_widget_grab_focus (priv->search_entry);
+}
+
+static void
+action_find (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer userdata)
+{
+ YelpWindowPrivate *priv = GET_PRIV (userdata);
+
+ gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (priv->search_bar), FALSE);
+ gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (priv->find_bar), TRUE);
+ gtk_widget_grab_focus (priv->find_entry);
+}
+
+/******************************************************************************/
+
+static void
window_drag_received (YelpWindow *window,
GdkDragContext *context,
gint x,
@@ -704,83 +723,90 @@ window_resize_signal (YelpWindow *window)
}
static void
-window_close (GtkAction *action, YelpWindow *window)
+window_go_all (GtkAction *action,
+ YelpWindow *window)
{
- gboolean ret;
- g_signal_emit_by_name (window, "delete-event", NULL, &ret);
- gtk_widget_destroy (GTK_WIDGET (window));
+ YelpWindowPrivate *priv = GET_PRIV (window);
+ yelp_view_load (priv->view, "help-list:");
}
static void
-window_go_all (GtkAction *action,
- YelpWindow *window)
+bookmark_activated (GtkListBox *box,
+ GtkListBoxRow *row,
+ YelpWindow *window)
{
+ YelpUri *base, *uri;
+ gchar *xref;
YelpWindowPrivate *priv = GET_PRIV (window);
- yelp_view_load (priv->view, "help-list:");
+
+ gtk_widget_hide (priv->bookmark_menu);
+
+ xref = g_strconcat ("xref:",
+ (gchar *) g_object_get_data (G_OBJECT (row), "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);
}
static void
-window_add_bookmark (GtkAction *action,
- YelpWindow *window)
+bookmark_removed (GtkButton *button,
+ YelpWindow *window)
{
YelpUri *uri;
- gchar *doc_uri, *page_id, *icon, *title;
+ gchar *doc_uri;
+ gchar *page_id = NULL;
YelpWindowPrivate *priv = GET_PRIV (window);
- g_object_get (priv->view,
- "yelp-uri", &uri,
- "page-id", &page_id,
- "page-icon", &icon,
- "page-title", &title,
- NULL);
+ g_object_get (priv->view, "yelp-uri", &uri, NULL);
doc_uri = yelp_uri_get_document_uri (uri);
- yelp_application_add_bookmark (YELP_BOOKMARKS (priv->application),
- doc_uri, page_id, icon, title);
+
+ /* The 'Remove Bookmark' button removes a bookmark for the current page.
+ The buttons next to each bookmark have page_id attached to them.
+ */
+ if ((gpointer) button == (gpointer) priv->bookmark_remove)
+ g_object_get (priv->view,
+ "page-id", &page_id,
+ NULL);
+
+ yelp_application_remove_bookmark (YELP_BOOKMARKS (priv->application),
+ doc_uri,
+ page_id ? page_id :
+ g_object_get_data (G_OBJECT (button), "page-id"));
+ if (page_id)
+ g_free (page_id);
g_free (doc_uri);
- g_free (page_id);
- g_free (icon);
- g_free (title);
g_object_unref (uri);
}
static void
-window_remove_bookmark (GtkAction *action,
- YelpWindow *window)
+bookmark_added (GtkButton *button,
+ YelpWindow *window)
{
YelpUri *uri;
- gchar *doc_uri, *page_id;
+ gchar *doc_uri, *page_id, *icon, *title;
YelpWindowPrivate *priv = GET_PRIV (window);
g_object_get (priv->view,
"yelp-uri", &uri,
"page-id", &page_id,
+ "page-icon", &icon,
+ "page-title", &title,
NULL);
doc_uri = yelp_uri_get_document_uri (uri);
- yelp_application_remove_bookmark (YELP_BOOKMARKS (priv->application),
- doc_uri, page_id);
+ yelp_application_add_bookmark (YELP_BOOKMARKS (priv->application),
+ doc_uri, page_id, icon, title);
g_free (doc_uri);
g_free (page_id);
+ g_free (icon);
+ g_free (title);
g_object_unref (uri);
}
-static void
-window_load_bookmark (GtkAction *action,
- YelpWindow *window)
-{
- YelpUri *base, *uri;
- gchar *xref;
- YelpWindowPrivate *priv = GET_PRIV (window);
-
- /* Bookmark action names are prefixed with 'LoadBookmark-' */
- xref = g_strconcat ("xref:", gtk_action_get_name (action) + 13, 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);
-}
static void
app_bookmarks_changed (YelpApplication *app,
@@ -834,11 +860,17 @@ window_set_bookmarks (YelpWindow *window,
GVariantIter *iter;
gchar *page_id, *icon, *title;
YelpWindowPrivate *priv = GET_PRIV (window);
+ GList *children, *cur;
GSList *entries = NULL;
- window_set_bookmark_action (window);
+ window_set_bookmark_buttons (window);
- gtk_ui_manager_remove_ui (priv->ui_manager, priv->bookmarks_merge_id);
+ children = gtk_container_get_children (GTK_CONTAINER (priv->bookmark_list));
+ for (cur = children ; cur != NULL; cur = cur->next) {
+ gtk_container_remove (GTK_CONTAINER (priv->bookmark_list),
+ GTK_WIDGET (cur->data));
+ }
+ g_list_free (children);
value = yelp_application_get_bookmarks (priv->application, doc_uri);
g_variant_get (value, "a(sss)", &iter);
@@ -850,41 +882,29 @@ window_set_bookmarks (YelpWindow *window,
entries = g_slist_insert_sorted (entries, entry, (GCompareFunc) entry_compare);
}
for ( ; entries != NULL; entries = g_slist_delete_link (entries, entries)) {
- GSList *cur;
- GtkAction *bookmark;
+ GtkWidget *row, *box, *button;
YelpMenuEntry *entry = (YelpMenuEntry *) entries->data;
- gchar *action_id = g_strconcat ("LoadBookmark-", entry->page_id, NULL);
-
- bookmark = gtk_action_group_get_action (priv->bookmark_actions, action_id);
- if (bookmark) {
- /* The action might have been set by a different document using
- * the same page ID. We can just reuse the action, since it's
- * just a page ID relative to the current URI, but we need to
- * reset the title and icon.
- */
- g_object_set (bookmark,
- "label", entry->title,
- "icon-name", entry->icon,
- NULL);
- } else {
- bookmark = gtk_action_new (action_id, entry->title, NULL, NULL);
- g_signal_connect (bookmark, "activate",
- G_CALLBACK (window_load_bookmark), window);
- gtk_action_set_icon_name (bookmark, entry->icon);
- gtk_action_group_add_action (priv->bookmark_actions, bookmark);
- }
- gtk_ui_manager_add_ui (priv->ui_manager,
- priv->bookmarks_merge_id,
- "ui/menubar/BookmarksMenu/Bookmarks",
- action_id, action_id,
- GTK_UI_MANAGER_MENUITEM,
- FALSE);
- gtk_ui_manager_ensure_update (priv->ui_manager);
- for (cur = gtk_action_get_proxies (bookmark); cur != NULL; cur = cur->next) {
- if (GTK_IS_IMAGE_MENU_ITEM (cur->data))
- g_object_set (cur->data, "always-show-image", TRUE, NULL);
- }
- g_free (action_id);
+
+ row = gtk_list_box_row_new ();
+ g_object_set_data_full (G_OBJECT (row), "page-id",
+ g_strdup (entry->page_id), (GDestroyNotify) g_free);
+ box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
+ gtk_container_add (GTK_CONTAINER (row), box);
+ button = gtk_label_new (entry->title);
+ g_object_set (button, "halign", GTK_ALIGN_START, NULL);
+ gtk_box_pack_start (GTK_BOX (box), button, TRUE, TRUE, 0);
+ button = gtk_button_new_from_icon_name ("edit-delete-symbolic", GTK_ICON_SIZE_MENU);
+ g_object_set (button,
+ "relief", GTK_RELIEF_NONE,
+ "focus-on-click", FALSE,
+ NULL);
+ g_object_set_data_full (G_OBJECT (button), "page-id",
+ g_strdup (entry->page_id), (GDestroyNotify) g_free);
+ g_signal_connect (button, "clicked", G_CALLBACK (bookmark_removed), window);
+ gtk_box_pack_end (GTK_BOX (box), button, FALSE, FALSE, 0);
+ gtk_box_pack_end (GTK_BOX (box), gtk_separator_new (GTK_ORIENTATION_VERTICAL), FALSE, FALSE, 0);
+ gtk_widget_show_all (row);
+ gtk_container_add (GTK_CONTAINER (priv->bookmark_list), row);
g_free (entry->icon);
g_free (entry);
}
@@ -894,31 +914,29 @@ window_set_bookmarks (YelpWindow *window,
}
static void
-window_set_bookmark_action (YelpWindow *window)
+window_set_bookmark_buttons (YelpWindow *window)
{
YelpUri *uri = NULL;
gchar *doc_uri = NULL, *page_id = NULL;
- GtkAction *action_add, *action_del;
gboolean bookmarked;
YelpWindowPrivate *priv = GET_PRIV (window);
- action_add = gtk_action_group_get_action (priv->action_group, "AddBookmark");
- action_del = gtk_action_group_get_action (priv->action_group, "RemoveBookmark");
g_object_get (priv->view,
"yelp-uri", &uri,
"page-id", &page_id,
NULL);
if (page_id == NULL || uri == NULL) {
- gtk_action_set_sensitive (action_add, FALSE);
- gtk_action_set_sensitive (action_del, FALSE);
+ gtk_widget_hide (priv->bookmark_add);
+ gtk_widget_hide (priv->bookmark_remove);
goto done;
}
doc_uri = yelp_uri_get_document_uri (uri);
bookmarked = yelp_application_is_bookmarked (YELP_BOOKMARKS (priv->application),
doc_uri, page_id);
- gtk_action_set_sensitive (action_add, !bookmarked);
- gtk_action_set_sensitive (action_del, bookmarked);
+
+ gtk_widget_set_visible (priv->bookmark_add, !bookmarked);
+ gtk_widget_set_visible (priv->bookmark_remove, bookmarked);
done:
g_free (page_id);
@@ -928,28 +946,15 @@ window_set_bookmark_action (YelpWindow *window)
}
static void
-window_start_search (GtkAction *action, YelpWindow *window)
-{
- YelpWindowPrivate *priv = GET_PRIV (window);
-
- yelp_location_entry_start_search (priv->entry);
-}
-
-static void
window_open_location (GtkAction *action, YelpWindow *window)
{
+#if 0
YelpUri *yuri = NULL;
gchar *uri = NULL;
GdkColor yellow;
gchar *color;
YelpWindowPrivate *priv = GET_PRIV (window);
- gtk_container_remove (GTK_CONTAINER (priv->hbox),
- priv->align_location);
- gtk_box_pack_start (GTK_BOX (priv->hbox),
- priv->align_hidden,
- TRUE, TRUE, 0);
-
gtk_widget_show_all (priv->align_hidden);
gtk_entry_set_text (GTK_ENTRY (priv->hidden_entry), "");
gtk_widget_grab_focus (priv->hidden_entry);
@@ -978,6 +983,7 @@ window_open_location (GtkAction *action, YelpWindow *window)
gtk_editable_select_region (GTK_EDITABLE (priv->hidden_entry), 5, -1);
g_free (uri);
}
+#endif
}
static void
@@ -1101,24 +1107,6 @@ app_read_later_changed (YelpApplication *app,
}
}
-static void
-window_find_in_page (GtkAction *action,
- YelpWindow *window)
-{
- YelpWindowPrivate *priv = GET_PRIV (window);
-
- if (gtk_widget_get_parent (priv->find_bar) != NULL) {
- gtk_widget_grab_focus (priv->find_entry);
- return;
- }
-
- g_object_set (priv->find_entry, "width-request", 2 * priv->width / 3, NULL);
-
- gtk_box_pack_end (GTK_BOX (priv->vbox_view), priv->find_bar, FALSE, FALSE, 0);
- gtk_widget_show_all (priv->find_bar);
- gtk_widget_grab_focus (priv->find_entry);
-}
-
static gboolean
find_entry_key_press (GtkEntry *entry,
GdkEventKey *event,
@@ -1142,19 +1130,6 @@ find_entry_key_press (GtkEntry *entry,
return FALSE;
}
-static gboolean
-find_entry_focus_out (GtkEntry *entry,
- GdkEventFocus *event,
- YelpWindow *window)
-{
- YelpWindowPrivate *priv = GET_PRIV (window);
- webkit_web_view_unmark_text_matches (WEBKIT_WEB_VIEW (priv->view));
- webkit_web_view_set_highlight_text_matches (WEBKIT_WEB_VIEW (priv->view), FALSE);
- if (gtk_widget_get_parent (priv->find_bar) != NULL)
- gtk_container_remove (GTK_CONTAINER (priv->vbox_view), priv->find_bar);
- return FALSE;
-}
-
static void
find_entry_changed (GtkEntry *entry,
YelpWindow *window)
@@ -1167,88 +1142,20 @@ find_entry_changed (GtkEntry *entry,
text = gtk_editable_get_chars (GTK_EDITABLE (entry), 0, -1);
- if (text[0] == '\0') {
- gtk_label_set_text (GTK_LABEL (priv->find_label), "");
- return;
- }
-
count = webkit_web_view_mark_text_matches (WEBKIT_WEB_VIEW (priv->view),
text, FALSE, 0);
if (count > 0) {
- gchar *label = g_strdup_printf (ngettext ("%i match", "%i matches", count), count);
webkit_web_view_set_highlight_text_matches (WEBKIT_WEB_VIEW (priv->view), TRUE);
webkit_web_view_search_text (WEBKIT_WEB_VIEW (priv->view),
text, FALSE, TRUE, TRUE);
- gtk_label_set_text (GTK_LABEL (priv->find_label), label);
- g_free (label);
}
else {
webkit_web_view_set_highlight_text_matches (WEBKIT_WEB_VIEW (priv->view), FALSE);
- gtk_label_set_text (GTK_LABEL (priv->find_label), _("No matches"));
}
g_free (text);
}
-static gboolean
-entry_color_animate (YelpWindow *window)
-{
- gchar *color;
- GdkColor yellow, base;
- YelpWindowPrivate *priv = GET_PRIV (window);
-
- color = yelp_settings_get_color (yelp_settings_get_default (),
- YELP_SETTINGS_COLOR_YELLOW_BASE);
- gdk_color_parse (color, &yellow);
- g_free (color);
-
- color = yelp_settings_get_color (yelp_settings_get_default (),
- YELP_SETTINGS_COLOR_BASE);
- gdk_color_parse (color, &base);
- g_free (color);
-
- yellow.red = priv->entry_color_step * yellow.red + (1.0 - priv->entry_color_step) * base.red;
- yellow.green = priv->entry_color_step * yellow.green + (1.0 - priv->entry_color_step) * base.green;
- yellow.blue = priv->entry_color_step * yellow.blue + (1.0 - priv->entry_color_step) * base.blue;
-
- gtk_widget_modify_base (gtk_bin_get_child (GTK_BIN (priv->entry)), GTK_STATE_NORMAL, &yellow);
-
- priv->entry_color_step -= 0.05;
-
- if (priv->entry_color_step < 0.0) {
- priv->entry_color_animate = 0;
- return FALSE;
- }
-
- return TRUE;
-}
-
-static gboolean
-entry_focus_in (GtkEntry *entry,
- GdkEventFocus *event,
- YelpWindow *window)
-{
- YelpWindowPrivate *priv = GET_PRIV (window);
-
- if (priv->entry_color_animate != 0)
- return FALSE;
-
- priv->entry_color_step = 1.0;
- priv->entry_color_animate = g_timeout_add (40, (GSourceFunc) entry_color_animate, window);
-
- return FALSE;
-}
-
-static gboolean
-entry_focus_out (YelpLocationEntry *entry,
- GdkEventFocus *event,
- YelpWindow *window)
-{
- YelpWindowPrivate *priv = GET_PRIV (window);
- gtk_widget_grab_focus (GTK_WIDGET (priv->view));
- return FALSE;
-}
-
static void
view_new_window (YelpView *view,
YelpUri *uri,
@@ -1348,14 +1255,22 @@ view_root_title (YelpView *view,
GParamSpec *pspec,
YelpWindow *window)
{
- gchar *title;
- g_object_get (view, "root-title", &title, NULL);
+ YelpWindowPrivate *priv = GET_PRIV (window);
+ gchar *root_title, *page_title;
+ g_object_get (view, "root-title", &root_title, "page-title", &page_title, NULL);
- if (title) {
- gtk_window_set_title (GTK_WINDOW (window), title);
- g_free (title);
+ if (page_title) {
+ gtk_header_bar_set_title (GTK_HEADER_BAR (priv->header), page_title);
+ g_free (page_title);
} else {
- gtk_window_set_title (GTK_WINDOW (window), _("Help"));
+ gtk_header_bar_set_title (GTK_HEADER_BAR (priv->header), _("Help"));
+ }
+
+ if (root_title) {
+ gtk_header_bar_set_subtitle (GTK_HEADER_BAR (priv->header), root_title);
+ g_free (root_title);
+ } else {
+ gtk_header_bar_set_subtitle (GTK_HEADER_BAR (priv->header), NULL);
}
}
@@ -1378,11 +1293,13 @@ hidden_entry_hide (YelpWindow *window)
YelpWindowPrivate *priv = GET_PRIV (window);
if (gtk_widget_get_parent (priv->align_hidden) != NULL) {
+#if 0
gtk_container_remove (GTK_CONTAINER (priv->hbox),
priv->align_hidden);
gtk_box_pack_start (GTK_BOX (priv->hbox),
priv->align_location,
TRUE, TRUE, 0);
+#endif
}
}
diff --git a/src/yelp-window.h b/src/yelp-window.h
index 64db4c0f..a1303068 100644
--- a/src/yelp-window.h
+++ b/src/yelp-window.h
@@ -36,12 +36,12 @@ typedef struct _YelpWindowClass YelpWindowClass;
struct _YelpWindow
{
- GtkWindow parent;
+ GtkApplicationWindow parent;
};
struct _YelpWindowClass
{
- GtkWindowClass parent_class;
+ GtkApplicationWindowClass parent_class;
};
GType yelp_window_get_type (void);