[Xfce4-commits] <midori:master> Implement Next and Previous buttons and add to the default toolbar
Christian Dywan
noreply at xfce.org
Sun Dec 27 17:08:04 CET 2009
Updating branch refs/heads/master
to b45fe5cca2f0fd71e63790f8151e79e62d8bf764 (commit)
from f51785f0aa0d88ebbc57924674ad43ef7b29549a (commit)
commit b45fe5cca2f0fd71e63790f8151e79e62d8bf764
Author: Christian Dywan <christian at twotoasts.de>
Date: Sat Dec 26 23:12:36 2009 +0100
Implement Next and Previous buttons and add to the default toolbar
midori/midori-browser.c | 86 ++++++++++++++++++++++++++++++++++++++++++-
midori/midori-view.c | 62 +++++++++++++++++++++++++++++++
midori/midori-view.h | 6 +++
midori/midori-websettings.c | 2 +-
4 files changed, 154 insertions(+), 2 deletions(-)
diff --git a/midori/midori-browser.c b/midori/midori-browser.c
index 834aaaf..f34d72b 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;
}
@@ -3545,6 +3549,44 @@ _action_forward_activate (GtkAction* action,
}
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, "<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) },
@@ -5328,6 +5404,8 @@ static const gchar* ui_markup =
"<menu action='Go'>"
"<menuitem action='Back'/>"
"<menuitem action='Forward'/>"
+ "<menuitem action='Previous'/>"
+ "<menuitem action='Next'/>"
"<menuitem action='Homepage'/>"
"<menuitem action='Location'/>"
"<menuitem action='Search'/>"
@@ -5900,6 +5978,12 @@ midori_browser_init (MidoriBrowser* 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);
#if HAVE_HILDON
_action_set_visible (browser, "Menubar", FALSE);
diff --git a/midori/midori-view.c b/midori/midori-view.c
index 8729d09..bfc55bf 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 fc798fb..a8a7452 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 b64145f..b543c64 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,
More information about the Xfce4-commits
mailing list