Implement Next and Previous buttons and add to the default toolbar
This commit is contained in:
parent
f51785f0aa
commit
b45fe5cca2
4 changed files with 154 additions and 2 deletions
|
@ -299,6 +299,10 @@ _midori_browser_update_interface (MidoriBrowser* browser)
|
||||||
_action_set_sensitive (browser, "Stop", can_reload && loading);
|
_action_set_sensitive (browser, "Stop", can_reload && loading);
|
||||||
_action_set_sensitive (browser, "Back", midori_view_can_go_back (view));
|
_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, "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"),
|
gtk_action_set_visible (_action_by_name (browser, "AddSpeedDial"),
|
||||||
browser->speed_dial_in_new_tabs && !midori_view_is_blank (view));
|
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",
|
"Fullscreen", "Preferences", "Window", "Bookmarks",
|
||||||
"RecentlyVisited", "ReloadStop", "ZoomIn", "TabClose",
|
"RecentlyVisited", "ReloadStop", "ZoomIn", "TabClose",
|
||||||
"ZoomOut", "Separator", "Back", "Forward", "Homepage",
|
"ZoomOut", "Separator", "Back", "Forward", "Homepage",
|
||||||
"Panel", "Trash", "Search", "BookmarkAdd", NULL };
|
"Panel", "Trash", "Search", "BookmarkAdd", "Previous", "Next", NULL };
|
||||||
|
|
||||||
return actions;
|
return actions;
|
||||||
}
|
}
|
||||||
|
@ -3544,6 +3548,44 @@ _action_forward_activate (GtkAction* action,
|
||||||
midori_view_go_forward (MIDORI_VIEW (view));
|
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
|
static void
|
||||||
_action_homepage_activate (GtkAction* action,
|
_action_homepage_activate (GtkAction* action,
|
||||||
MidoriBrowser* browser)
|
MidoriBrowser* browser)
|
||||||
|
@ -4118,6 +4160,34 @@ midori_browser_menu_middle_click_on_navigation_action (MidoriBrowser* browser,
|
||||||
|
|
||||||
return TRUE;
|
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);
|
g_free (homepage);
|
||||||
|
|
||||||
|
@ -5050,6 +5120,12 @@ static const GtkActionEntry entries[] = {
|
||||||
{ "Forward", GTK_STOCK_GO_FORWARD,
|
{ "Forward", GTK_STOCK_GO_FORWARD,
|
||||||
NULL, "<Alt>Right",
|
NULL, "<Alt>Right",
|
||||||
N_("Go forward to the next page"), G_CALLBACK (_action_forward_activate) },
|
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,
|
{ "Homepage", STOCK_HOMEPAGE,
|
||||||
NULL, "<Alt>Home",
|
NULL, "<Alt>Home",
|
||||||
N_("Go to your homepage"), G_CALLBACK (_action_homepage_activate) },
|
N_("Go to your homepage"), G_CALLBACK (_action_homepage_activate) },
|
||||||
|
@ -5328,6 +5404,8 @@ static const gchar* ui_markup =
|
||||||
"<menu action='Go'>"
|
"<menu action='Go'>"
|
||||||
"<menuitem action='Back'/>"
|
"<menuitem action='Back'/>"
|
||||||
"<menuitem action='Forward'/>"
|
"<menuitem action='Forward'/>"
|
||||||
|
"<menuitem action='Previous'/>"
|
||||||
|
"<menuitem action='Next'/>"
|
||||||
"<menuitem action='Homepage'/>"
|
"<menuitem action='Homepage'/>"
|
||||||
"<menuitem action='Location'/>"
|
"<menuitem action='Location'/>"
|
||||||
"<menuitem action='Search'/>"
|
"<menuitem action='Search'/>"
|
||||||
|
@ -5898,6 +5976,12 @@ midori_browser_init (MidoriBrowser* browser)
|
||||||
g_signal_connect (back, "button-press-event",
|
g_signal_connect (back, "button-press-event",
|
||||||
G_CALLBACK (midori_browser_menu_item_middle_click_event_cb), browser);
|
G_CALLBACK (midori_browser_menu_item_middle_click_event_cb), browser);
|
||||||
forward = gtk_ui_manager_get_widget (ui_manager, "/menubar/Go/Forward");
|
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_signal_connect (forward, "button-press-event",
|
||||||
G_CALLBACK (midori_browser_menu_item_middle_click_event_cb), browser);
|
G_CALLBACK (midori_browser_menu_item_middle_click_event_cb), browser);
|
||||||
|
|
||||||
|
|
|
@ -4021,6 +4021,68 @@ midori_view_go_forward (MidoriView* view)
|
||||||
webkit_web_view_go_forward (WEBKIT_WEB_VIEW (view->web_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)
|
#if WEBKIT_CHECK_VERSION (1, 1, 5)
|
||||||
static GtkWidget*
|
static GtkWidget*
|
||||||
midori_view_print_create_custom_widget_cb (GtkPrintOperation* operation,
|
midori_view_print_create_custom_widget_cb (GtkPrintOperation* operation,
|
||||||
|
|
|
@ -160,6 +160,12 @@ midori_view_can_go_forward (MidoriView* view);
|
||||||
void
|
void
|
||||||
midori_view_go_forward (MidoriView* view);
|
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
|
gboolean
|
||||||
midori_view_can_print (MidoriView* view);
|
midori_view_can_print (MidoriView* view);
|
||||||
|
|
||||||
|
|
|
@ -526,7 +526,7 @@ midori_web_settings_class_init (MidoriWebSettingsClass* class)
|
||||||
"toolbar-items",
|
"toolbar-items",
|
||||||
_("Toolbar Items"),
|
_("Toolbar Items"),
|
||||||
_("The items to show on the toolbar"),
|
_("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));
|
flags));
|
||||||
|
|
||||||
g_object_class_install_property (gobject_class,
|
g_object_class_install_property (gobject_class,
|
||||||
|
|
Loading…
Reference in a new issue