_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));
"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;
}
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)
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);
{ "Forward", GTK_STOCK_GO_FORWARD,
NULL, "<Alt>Right",
N_("Go forward to the next page"), G_CALLBACK (_action_forward_activate) },
+ { "Previous", GTK_STOCK_MEDIA_PREVIOUS,
+ NULL, "<Ctrl>Left",
+ N_("Go to the previous sub-page"), G_CALLBACK (_action_previous_activate) },
+ { "Next", GTK_STOCK_MEDIA_NEXT,
+ NULL, "<Ctrl>Right",
+ N_("Go to the next sub-page"), G_CALLBACK (_action_next_activate) },
{ "Homepage", STOCK_HOMEPAGE,
NULL, "<Alt>Home",
N_("Go to your homepage"), G_CALLBACK (_action_homepage_activate) },
"<menu action='Go'>"
"<menuitem action='Back'/>"
"<menuitem action='Forward'/>"
+ "<menuitem action='Previous'/>"
+ "<menuitem action='Next'/>"
"<menuitem action='Homepage'/>"
"<menuitem action='Location'/>"
"<menuitem action='Search'/>"
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);
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,