From: Christian Dywan Date: Sat, 26 Dec 2009 22:12:36 +0000 (+0100) Subject: Implement Next and Previous buttons and add to the default toolbar X-Git-Url: https://spindle.queued.net/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b45fe5cca2f0fd71e63790f8151e79e62d8bf764;p=midori Implement Next and Previous buttons and add to the default toolbar --- diff --git a/midori/midori-browser.c b/midori/midori-browser.c index 834aaaf9..f34d72b6 100644 --- a/midori/midori-browser.c +++ b/midori/midori-browser.c @@ -299,6 +299,10 @@ _midori_browser_update_interface (MidoriBrowser* browser) _action_set_sensitive (browser, "Stop", can_reload && loading); _action_set_sensitive (browser, "Back", midori_view_can_go_back (view)); _action_set_sensitive (browser, "Forward", midori_view_can_go_forward (view)); + _action_set_sensitive (browser, "Previous", + midori_view_get_previous_page (view) != NULL); + _action_set_sensitive (browser, "Next", + midori_view_get_next_page (view) != NULL); gtk_action_set_visible (_action_by_name (browser, "AddSpeedDial"), browser->speed_dial_in_new_tabs && !midori_view_is_blank (view)); @@ -2696,7 +2700,7 @@ midori_browser_get_toolbar_actions (MidoriBrowser* browser) "Fullscreen", "Preferences", "Window", "Bookmarks", "RecentlyVisited", "ReloadStop", "ZoomIn", "TabClose", "ZoomOut", "Separator", "Back", "Forward", "Homepage", - "Panel", "Trash", "Search", "BookmarkAdd", NULL }; + "Panel", "Trash", "Search", "BookmarkAdd", "Previous", "Next", NULL }; return actions; } @@ -3544,6 +3548,44 @@ _action_forward_activate (GtkAction* action, midori_view_go_forward (MIDORI_VIEW (view)); } +static void +_action_previous_activate (GtkAction* action, + MidoriBrowser* browser) +{ + if (g_object_get_data (G_OBJECT (action), "midori-middle-click")) + { + g_object_set_data (G_OBJECT (action), "midori-middle-click", (void*)0); + return; + } + + GtkWidget* view = midori_browser_get_current_tab (browser); + if (view) + { + gchar* uri = g_strdup (midori_view_get_previous_page (MIDORI_VIEW (view))); + midori_view_set_uri (MIDORI_VIEW (view), uri); + g_free (uri); + } +} + +static void +_action_next_activate (GtkAction* action, + MidoriBrowser* browser) +{ + if (g_object_get_data (G_OBJECT (action), "midori-middle-click")) + { + g_object_set_data (G_OBJECT (action), "midori-middle-click", (void*)0); + return; + } + + GtkWidget* view = midori_browser_get_current_tab (browser); + if (view) + { + gchar* uri = g_strdup (midori_view_get_next_page (MIDORI_VIEW (view))); + midori_view_set_uri (MIDORI_VIEW (view), uri); + g_free (uri); + } +} + static void _action_homepage_activate (GtkAction* action, MidoriBrowser* browser) @@ -4118,6 +4160,34 @@ midori_browser_menu_middle_click_on_navigation_action (MidoriBrowser* browser, return TRUE; } + else if (g_str_equal (name, "Previous")) + { + GtkWidget *view; + gint n; + + view = midori_browser_get_current_tab (browser); + n = midori_browser_add_uri (browser, + midori_view_get_previous_page (MIDORI_VIEW (view))); + _midori_browser_set_current_page_smartly (browser, n); + + g_object_set_data (G_OBJECT (action), "midori-middle-click", (void*)1); + + return TRUE; + } + else if (g_str_equal (name, "Next")) + { + GtkWidget *view; + gint n; + + view = midori_browser_get_current_tab (browser); + n = midori_browser_add_uri (browser, + midori_view_get_next_page (MIDORI_VIEW (view))); + _midori_browser_set_current_page_smartly (browser, n); + + g_object_set_data (G_OBJECT (action), "midori-middle-click", (void*)1); + + return TRUE; + } g_free (homepage); @@ -5050,6 +5120,12 @@ static const GtkActionEntry entries[] = { { "Forward", GTK_STOCK_GO_FORWARD, NULL, "Right", N_("Go forward to the next page"), G_CALLBACK (_action_forward_activate) }, + { "Previous", GTK_STOCK_MEDIA_PREVIOUS, + NULL, "Left", + N_("Go to the previous sub-page"), G_CALLBACK (_action_previous_activate) }, + { "Next", GTK_STOCK_MEDIA_NEXT, + NULL, "Right", + N_("Go to the next sub-page"), G_CALLBACK (_action_next_activate) }, { "Homepage", STOCK_HOMEPAGE, NULL, "Home", N_("Go to your homepage"), G_CALLBACK (_action_homepage_activate) }, @@ -5328,6 +5404,8 @@ static const gchar* ui_markup = "" "" "" + "" + "" "" "" "" @@ -5898,6 +5976,12 @@ midori_browser_init (MidoriBrowser* browser) g_signal_connect (back, "button-press-event", G_CALLBACK (midori_browser_menu_item_middle_click_event_cb), browser); forward = gtk_ui_manager_get_widget (ui_manager, "/menubar/Go/Forward"); + g_signal_connect (forward, "button-press-event", + G_CALLBACK (midori_browser_menu_item_middle_click_event_cb), browser); + forward = gtk_ui_manager_get_widget (ui_manager, "/menubar/Go/Previous"); + g_signal_connect (forward, "button-press-event", + G_CALLBACK (midori_browser_menu_item_middle_click_event_cb), browser); + forward = gtk_ui_manager_get_widget (ui_manager, "/menubar/Go/Next"); g_signal_connect (forward, "button-press-event", G_CALLBACK (midori_browser_menu_item_middle_click_event_cb), browser); diff --git a/midori/midori-view.c b/midori/midori-view.c index 8729d09e..bfc55bf9 100644 --- a/midori/midori-view.c +++ b/midori/midori-view.c @@ -4021,6 +4021,68 @@ midori_view_go_forward (MidoriView* view) webkit_web_view_go_forward (WEBKIT_WEB_VIEW (view->web_view)); } +/** + * midori_view_get_previous_page + * @view: a #MidoriView + * + * Determines the previous sub-page in the view. + * + * Return value: an URI, or %NULL + * + * Since: 0.2.3 + **/ +const gchar* +midori_view_get_previous_page (MidoriView* view) +{ + static gchar* uri = NULL; + WebKitWebFrame* web_frame; + JSContextRef js_context; + + g_return_val_if_fail (MIDORI_IS_VIEW (view), NULL); + + web_frame = webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (view->web_view)); + js_context = webkit_web_frame_get_global_context (web_frame); + katze_assign (uri, sokoke_js_script_eval (js_context, + "(function (l) { for (i in l) " + "if ((l[i].rel && l[i].rel == 'prev') " + " || (l[i].innerHTML" + " && l[i].innerHTML.toLowerCase ().indexOf ('prev') != -1)) " + "{ return l[i].href; } return 0; })(" + "document.getElementsByTagName ('a'));", NULL)); + return uri && uri[0] != '0' ? uri : NULL; +} + +/** + * midori_view_get_next_page + * @view: a #MidoriView + * + * Determines the next sub-page in the view. + * + * Return value: an URI, or %NULL + * + * Since: 0.2.3 + **/ +const gchar* +midori_view_get_next_page (MidoriView* view) +{ + static gchar* uri = NULL; + WebKitWebFrame* web_frame; + JSContextRef js_context; + + g_return_val_if_fail (MIDORI_IS_VIEW (view), NULL); + + web_frame = webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (view->web_view)); + js_context = webkit_web_frame_get_global_context (web_frame); + katze_assign (uri, sokoke_js_script_eval (js_context, + "(function (l) { for (i in l) " + "if ((l[i].rel && l[i].rel == 'next') " + " || (l[i].innerHTML" + " && l[i].innerHTML.toLowerCase ().indexOf ('next') != -1)) " + "{ return l[i].href; } return 0; })(" + "document.getElementsByTagName ('a'));", NULL)); + return uri && uri[0] != '0' ? uri : NULL; +} + #if WEBKIT_CHECK_VERSION (1, 1, 5) static GtkWidget* midori_view_print_create_custom_widget_cb (GtkPrintOperation* operation, diff --git a/midori/midori-view.h b/midori/midori-view.h index fc798fbd..a8a74526 100644 --- a/midori/midori-view.h +++ b/midori/midori-view.h @@ -160,6 +160,12 @@ midori_view_can_go_forward (MidoriView* view); void midori_view_go_forward (MidoriView* view); +const gchar* +midori_view_get_previous_page (MidoriView* view); + +const gchar* +midori_view_get_next_page (MidoriView* view); + gboolean midori_view_can_print (MidoriView* view); diff --git a/midori/midori-websettings.c b/midori/midori-websettings.c index b64145fd..b543c640 100644 --- a/midori/midori-websettings.c +++ b/midori/midori-websettings.c @@ -526,7 +526,7 @@ midori_web_settings_class_init (MidoriWebSettingsClass* class) "toolbar-items", _("Toolbar Items"), _("The items to show on the toolbar"), - "TabNew,Back,Forward,ReloadStop,Location,Panel,Search,Trash", + "TabNew,Back,Forward,Next,ReloadStop,Location,Panel,Search,Trash", flags)); g_object_class_install_property (gobject_class,