]> spindle.queued.net Git - midori/commitdiff
Implement Next and Previous buttons and add to the default toolbar
authorChristian Dywan <christian@twotoasts.de>
Sat, 26 Dec 2009 22:12:36 +0000 (23:12 +0100)
committerChristian Dywan <christian@twotoasts.de>
Sun, 27 Dec 2009 12:41:37 +0000 (13:41 +0100)
midori/midori-browser.c
midori/midori-view.c
midori/midori-view.h
midori/midori-websettings.c

index 834aaaf9b9b64da5455e484b0c3394e5a81a4180..f34d72b67c52c41f313c9f9b6dbc2e7bd8b4ae85 100644 (file)
@@ -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, "<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'/>"
@@ -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);
 
index 8729d09e9894fe7287a836afaab4f52f278d66d4..bfc55bf9b44a730634ea223027b06aaf1f080b93 100644 (file)
@@ -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,
index fc798fbda4d33c461d1d85a8253058dea225f10c..a8a7452673d18cbba0a1deb0f6f03a1afb08d185 100644 (file)
@@ -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);
 
index b64145fdcae7a1a1d065ddc7d9a856baaac14352..b543c640db862fc4fce20b5a18a470901f4a65f8 100644 (file)
@@ -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,