[yelp/new-aday-design] Hooked up actions for previous and next page
- From: Shaun McCance <shaunm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [yelp/new-aday-design] Hooked up actions for previous and next page
- Date: Sun, 23 Feb 2014 17:18:45 +0000 (UTC)
commit 5176d07c5d3f30e3b51bcb3fdaa7ab6c8f1802f9
Author: Shaun McCance <shaunm gnome org>
Date: Sun Feb 23 12:12:33 2014 -0500
Hooked up actions for previous and next page
libyelp/yelp-view.c | 194 ++++++++++--------------------------------------
libyelp/yelp-view.h | 9 --
src/yelp-application.c | 12 +++
src/yelp-window.c | 33 ++++-----
4 files changed, 67 insertions(+), 181 deletions(-)
---
diff --git a/libyelp/yelp-view.c b/libyelp/yelp-view.c
index 4764cf2..576a05e 100644
--- a/libyelp/yelp-view.c
+++ b/libyelp/yelp-view.c
@@ -107,7 +107,8 @@ static void view_print (GtkAction *action,
static void view_history_action (GAction *action,
GVariant *parameter,
YelpView *view);
-static void view_navigation_action (GtkAction *action,
+static void view_navigation_action (GAction *action,
+ GVariant *parameter,
YelpView *view);
static void view_clear_load (YelpView *view);
@@ -131,28 +132,6 @@ static const GtkActionEntry entries[] = {
"<Control>P",
NULL,
G_CALLBACK (view_print) },
-#if 0
- {"YelpViewGoBack", GTK_STOCK_GO_BACK,
- N_("_Back"),
- "<Alt>Left",
- NULL,
- G_CALLBACK (view_history_action) },
- {"YelpViewGoForward", GTK_STOCK_GO_FORWARD,
- N_("_Forward"),
- "<Alt>Right",
- NULL,
- G_CALLBACK (view_history_action) },
-#endif
- {"YelpViewGoPrevious", NULL,
- N_("_Previous Page"),
- "<Control>Page_Up",
- NULL,
- G_CALLBACK (view_navigation_action) },
- {"YelpViewGoNext", NULL,
- N_("_Next Page"),
- "<Control>Page_Down",
- NULL,
- G_CALLBACK (view_navigation_action) }
};
static gchar *nautilus_sendto = NULL;
@@ -252,10 +231,8 @@ struct _YelpViewPrivate {
GSimpleAction *back_action;
GSimpleAction *forward_action;
-
-#if 0
- GtkActionGroup *action_group;
-#endif
+ GSimpleAction *prev_action;
+ GSimpleAction *next_action;
GSList *link_actions;
@@ -295,18 +272,6 @@ yelp_view_init (YelpView *view)
g_signal_connect (view, "script-alert",
G_CALLBACK (view_script_alert), NULL);
-#if 0
- priv->action_group = gtk_action_group_new ("YelpView");
- gtk_action_group_set_translation_domain (priv->action_group, GETTEXT_PACKAGE);
- gtk_action_group_add_actions (priv->action_group,
- entries, G_N_ELEMENTS (entries),
- view);
- action = gtk_action_group_get_action (priv->action_group, "YelpViewGoBack");
- gtk_action_set_sensitive (action, FALSE);
- action = gtk_action_group_get_action (priv->action_group, "YelpViewGoForward");
- gtk_action_set_sensitive (action, FALSE);
-#endif
-
priv->back_action = g_simple_action_new ("yelp-view-go-back", NULL);
g_simple_action_set_enabled (priv->back_action, FALSE);
g_signal_connect (priv->back_action,
@@ -320,6 +285,20 @@ yelp_view_init (YelpView *view)
"activate",
G_CALLBACK (view_history_action),
view);
+
+ priv->prev_action = g_simple_action_new ("yelp-view-go-previous", NULL);
+ g_simple_action_set_enabled (priv->prev_action, FALSE);
+ g_signal_connect (priv->prev_action,
+ "activate",
+ G_CALLBACK (view_navigation_action),
+ view);
+
+ priv->next_action = g_simple_action_new ("yelp-view-go-next", NULL);
+ g_simple_action_set_enabled (priv->next_action, FALSE);
+ g_signal_connect (priv->next_action,
+ "activate",
+ G_CALLBACK (view_navigation_action),
+ view);
}
static void
@@ -339,13 +318,6 @@ yelp_view_dispose (GObject *object)
priv->hadjuster = 0;
}
-#if 0
- if (priv->action_group) {
- g_object_unref (priv->action_group);
- priv->action_group = NULL;
- }
-#endif
-
if (priv->back_action) {
g_object_unref (priv->back_action);
priv->back_action = NULL;
@@ -356,6 +328,16 @@ yelp_view_dispose (GObject *object)
priv->forward_action = NULL;
}
+ if (priv->prev_action) {
+ g_object_unref (priv->prev_action);
+ priv->prev_action = NULL;
+ }
+
+ if (priv->next_action) {
+ g_object_unref (priv->next_action);
+ priv->next_action = NULL;
+ }
+
if (priv->document) {
g_object_unref (priv->document);
priv->document = NULL;
@@ -607,14 +589,8 @@ yelp_view_load_uri (YelpView *view,
g_object_set (view, "state", YELP_VIEW_STATE_LOADING, NULL);
-#if 0
- gtk_action_set_sensitive (gtk_action_group_get_action (priv->action_group,
- "YelpViewGoPrevious"),
- FALSE);
- gtk_action_set_sensitive (gtk_action_group_get_action (priv->action_group,
- "YelpViewGoNext"),
- FALSE);
-#endif
+ g_simple_action_set_enabled (priv->prev_action, FALSE);
+ g_simple_action_set_enabled (priv->next_action, FALSE);
if (!yelp_uri_is_resolved (uri)) {
if (priv->resolve_uri != NULL) {
@@ -673,35 +649,12 @@ yelp_view_register_actions (YelpView *view,
GActionMap *map)
{
YelpViewPrivate *priv = GET_PRIV (view);
- g_action_map_add_action (map, priv->back_action);
- g_action_map_add_action (map, priv->forward_action);
+ g_action_map_add_action (map, G_ACTION (priv->back_action));
+ g_action_map_add_action (map, G_ACTION (priv->forward_action));
+ g_action_map_add_action (map, G_ACTION (priv->prev_action));
+ g_action_map_add_action (map, G_ACTION (priv->next_action));
}
-
-#if 0
-GtkActionGroup *
-yelp_view_get_action_group (YelpView *view)
-{
- YelpViewPrivate *priv = GET_PRIV (view);
- return priv->action_group;
-}
-
-GAction *
-yelp_view_get_back_action (YelpView *view)
-{
- YelpViewPrivate *priv = GET_PRIV (view);
- return G_ACTION (priv->back_action);
-}
-
-GAction *
-yelp_view_get_forward_action (YelpView *view)
-{
- YelpViewPrivate *priv = GET_PRIV (view);
- return G_ACTION (priv->forward_action);
-}
-#endif
-
-
/******************************************************************************/
void
@@ -1619,8 +1572,9 @@ view_history_action (GAction *action,
}
static void
-view_navigation_action (GtkAction *action,
- YelpView *view)
+view_navigation_action (GAction *action,
+ GVariant *parameter,
+ YelpView *view)
{
YelpViewPrivate *priv = GET_PRIV (view);
gchar *page_id, *new_id, *xref;
@@ -1628,14 +1582,14 @@ view_navigation_action (GtkAction *action,
page_id = yelp_uri_get_page_id (priv->uri);
- if (g_str_equal (gtk_action_get_name (action), "YelpViewGoPrevious"))
+ if (g_str_equal (g_action_get_name (action), "yelp-view-go-previous"))
new_id = yelp_document_get_prev_id (priv->document, page_id);
else
new_id = yelp_document_get_next_id (priv->document, page_id);
/* Just in case we screwed up somewhere */
if (new_id == NULL) {
- gtk_action_set_sensitive (action, FALSE);
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);
return;
}
@@ -1924,8 +1878,6 @@ uri_resolved (YelpUri *uri,
YelpViewPrivate *priv = GET_PRIV (view);
YelpDocument *document;
YelpBackEntry *back;
- GtkAction *action;
- GSList *proxies, *cur;
GError *error = NULL;
gchar *struri;
GParamSpec *spec;
@@ -2000,66 +1952,7 @@ uri_resolved (YelpUri *uri,
}
priv->back_load = FALSE;
-#if 0
- action = gtk_action_group_get_action (priv->action_group, "YelpViewGoBack");
- gtk_action_set_sensitive (action, FALSE);
- proxies = gtk_action_get_proxies (action);
- if (priv->back_cur->next && priv->back_cur->next->data) {
- gchar *tooltip = "";
- back = priv->back_cur->next->data;
-
- gtk_action_set_sensitive (action, TRUE);
- if (back->title && back->desc) {
- gchar *color;
- color = yelp_settings_get_color (yelp_settings_get_default (),
- YELP_SETTINGS_COLOR_TEXT_LIGHT);
- tooltip = g_markup_printf_escaped ("<span size='larger'>%s</span>\n<span color='%s'>%s</span>",
- back->title, color, back->desc);
- g_free (color);
- }
- else if (back->title)
- tooltip = g_markup_printf_escaped ("<span size='larger'>%s</span>",
- back->title);
- /* Can't seem to use markup on GtkAction tooltip */
- for (cur = proxies; cur != NULL; cur = cur->next)
- gtk_widget_set_tooltip_markup (GTK_WIDGET (cur->data), tooltip);
- }
- else {
- for (cur = proxies; cur != NULL; cur = cur->next)
- gtk_widget_set_tooltip_text (GTK_WIDGET (cur->data), "");
- }
-#endif
g_simple_action_set_enabled (priv->back_action, (priv->back_cur->next && priv->back_cur->next->data));
-
-#if 0
- action = gtk_action_group_get_action (priv->action_group, "YelpViewGoForward");
- gtk_action_set_sensitive (action, FALSE);
- proxies = gtk_action_get_proxies (action);
- if (priv->back_cur->prev && priv->back_cur->prev->data) {
- gchar *tooltip = "";
- back = priv->back_cur->prev->data;
-
- gtk_action_set_sensitive (action, TRUE);
- if (back->title && back->desc) {
- gchar *color;
- color = yelp_settings_get_color (yelp_settings_get_default (),
- YELP_SETTINGS_COLOR_TEXT_LIGHT);
- tooltip = g_markup_printf_escaped ("<span size='larger'>%s</span>\n<span color='%s'>%s</span>",
- back->title, color, back->desc);
- g_free (color);
- }
- else if (back->title)
- tooltip = g_markup_printf_escaped ("<span size='larger'>%s</span>",
- back->title);
- /* Can't seem to use markup on GtkAction tooltip */
- for (cur = proxies; cur != NULL; cur = cur->next)
- gtk_widget_set_tooltip_markup (GTK_WIDGET (cur->data), tooltip);
- }
- else {
- for (cur = proxies; cur != NULL; cur = cur->next)
- gtk_widget_set_tooltip_text (GTK_WIDGET (cur->data), "");
- }
-#endif
g_simple_action_set_enabled (priv->forward_action, (priv->back_cur->prev && priv->back_cur->prev->data));
spec = g_object_class_find_property ((GObjectClass *) YELP_VIEW_GET_CLASS (view),
@@ -2119,7 +2012,6 @@ document_callback (YelpDocument *document,
if (signal == YELP_DOCUMENT_SIGNAL_INFO) {
gchar *prev_id, *next_id, *real_id;
- GtkAction *action;
YelpBackEntry *back = NULL;
GParamSpec *spec;
@@ -2155,17 +2047,13 @@ document_callback (YelpDocument *document,
back->desc = g_strdup (priv->page_desc);
}
-#if 0
prev_id = yelp_document_get_prev_id (document, priv->page_id);
- action = gtk_action_group_get_action (priv->action_group, "YelpViewGoPrevious");
- gtk_action_set_sensitive (action, prev_id != NULL);
+ g_simple_action_set_enabled (priv->prev_action, prev_id != NULL);
g_free (prev_id);
next_id = yelp_document_get_next_id (document, priv->page_id);
- action = gtk_action_group_get_action (priv->action_group, "YelpViewGoNext");
- gtk_action_set_sensitive (action, next_id != NULL);
+ g_simple_action_set_enabled (priv->next_action, next_id != NULL);
g_free (next_id);
-#endif
spec = g_object_class_find_property ((GObjectClass *) YELP_VIEW_GET_CLASS (view),
"root-title");
diff --git a/libyelp/yelp-view.h b/libyelp/yelp-view.h
index a0c1995..a96feef 100644
--- a/libyelp/yelp-view.h
+++ b/libyelp/yelp-view.h
@@ -73,18 +73,9 @@ void yelp_view_load_document (YelpView *view
YelpDocument *document);
YelpDocument * yelp_view_get_document (YelpView *view);
-#if 0
-GtkActionGroup * yelp_view_get_action_group (YelpView *view);
-#endif
-
void yelp_view_register_actions (YelpView *view,
GActionMap *map);
-#if 0
-GAction * yelp_view_get_back_action (YelpView *view);
-GAction * yelp_view_get_forward_action (YelpView *view);
-#endif
-
void yelp_view_add_link_action (YelpView *view,
GtkAction *action,
YelpViewActionValidFunc func,
diff --git a/src/yelp-application.c b/src/yelp-application.c
index 0b810cc..7eb65c3 100644
--- a/src/yelp-application.c
+++ b/src/yelp-application.c
@@ -150,6 +150,10 @@ yelp_application_init (YelpApplication *app)
"win.search",
NULL);
gtk_application_add_accelerator (GTK_APPLICATION (app),
+ "<Control>p",
+ "win.yelp-view-print",
+ NULL);
+ gtk_application_add_accelerator (GTK_APPLICATION (app),
"<Alt>Left",
"win.yelp-view-go-back",
NULL);
@@ -157,6 +161,14 @@ yelp_application_init (YelpApplication *app)
"<Alt>Right",
"win.yelp-view-go-forward",
NULL);
+ gtk_application_add_accelerator (GTK_APPLICATION (app),
+ "<Control>Page_Up",
+ "win.yelp-view-go-previous",
+ NULL);
+ gtk_application_add_accelerator (GTK_APPLICATION (app),
+ "<Control>Page_Down",
+ "win.yelp-view-go-next",
+ NULL);
}
static void
diff --git a/src/yelp-window.c b/src/yelp-window.c
index f4cce8c..f05ae58 100644
--- a/src/yelp-window.c
+++ b/src/yelp-window.c
@@ -159,8 +159,6 @@ static const gchar *YELP_UI =
"<ui>"
"<menubar>"
"<menu action='PageMenu'>"
- "<menuitem action='NewWindow'/>"
- "<menuitem action='Find'/>"
"<separator/>"
"<menuitem action='YelpViewPrint'/>"
"<separator/>"
@@ -172,24 +170,8 @@ static const gchar *YELP_UI =
"<separator/>"
"<menuitem action='ShowTextCursor'/>"
"</menu>"
- "<menu action='GoMenu'>"
- "<menuitem action='YelpViewGoBack'/>"
- "<menuitem action='YelpViewGoForward'/>"
- "<separator/>"
- "<menuitem action='YelpViewGoPrevious'/>"
- "<menuitem action='YelpViewGoNext'/>"
- "<separator/>"
"<menuitem action='GoAll'/>"
"</menu>"
- "<menu action='BookmarksMenu'>"
- "<menuitem action='AddBookmark'/>"
- "<menuitem action='RemoveBookmark'/>"
- "<separator/>"
- "<placeholder name='Bookmarks'/>"
- "</menu>"
- "</menubar>"
- "<accelerator action='Find'/>"
- "<accelerator action='Search'/>"
"<accelerator action='OpenLocation'/>"
"</ui>";
#endif
@@ -357,10 +339,10 @@ static void
window_construct (YelpWindow *window)
{
GtkWidget *scroll;
- GtkActionGroup *view_actions;
GtkAction *action;
GtkWidget *box, *button, *sw;
gchar *color, *text;
+ GMenu *menu;
YelpWindowPrivate *priv = GET_PRIV (window);
gboolean rtl;
@@ -415,6 +397,7 @@ window_construct (YelpWindow *window)
/** Menu **/
button = gtk_menu_button_new ();
+ gtk_menu_button_set_use_popover (GTK_MENU_BUTTON (button), TRUE);
gtk_widget_set_valign (button, GTK_ALIGN_CENTER);
gtk_style_context_add_class (gtk_widget_get_style_context (button), "image-button");
gtk_button_set_image (GTK_BUTTON (button),
@@ -422,6 +405,18 @@ window_construct (YelpWindow *window)
GTK_ICON_SIZE_MENU));
gtk_header_bar_pack_end (GTK_HEADER_BAR (priv->header), button);
+ menu = g_menu_new ();
+ g_menu_append (menu, _("New Window"), "win.new-window");
+ g_menu_append (menu, _("Find..."), "win.find");
+ g_menu_append (menu, _("Print..."), "win.yelp-view-print");
+ g_menu_append (menu, _("Previous Page"), "win.yelp-view-go-previous");
+ g_menu_append (menu, _("Next Page"), "win.yelp-view-go-next");
+ /* all documents */
+ /* larger/smaller text */
+ /* show text cursor */
+ /* open location */
+ gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (button), G_MENU_MODEL (menu));
+
/** 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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]