Merge lp:~midori/midori/navigationAction into lp:midori

Proposed by Cris Dywan
Status: Work in progress
Proposed branch: lp:~midori/midori/navigationAction
Merge into: lp:midori
Diff against target: 953 lines (+326/-419)
5 files modified
midori/midori-browser.c (+29/-416)
midori/midori-navigationaction.vala (+293/-0)
midori/midori-view.c (+3/-0)
midori/midori-window.vala (+0/-3)
po/POTFILES.in (+1/-0)
To merge this branch: bzr merge lp:~midori/midori/navigationAction
Reviewer Review Type Date Requested Status
Danielle Foré (community) Needs Fixing
Review via email: mp+257570@code.launchpad.net

Commit message

Split Back, Forward and friends into NavigationAction

To post a comment you must log in.
Revision history for this message
Danielle Foré (danrabbit) wrote :

Gtk.Stock is deprecated. Relevant icon names are "go-next", "go-previous", "go-home", "media-skip-forward", "media-skip-backward", "view-refresh"

review: Needs Fixing
lp:~midori/midori/navigationAction updated
6950. By Cris Dywan

Merge lp:midori

6951. By Cris Dywan

Remaining NavigationAction subclasses

6952. By Cris Dywan

Coding style fixes

Revision history for this message
Cris Dywan (kalikiana) wrote :

In 10 minutes I couldn't find a way to use GLib.Icon with ThemedIcon.with_fallbacks so that icons show (at all) and hide as per style, so for now I'll stick to stock icons.

lp:~midori/midori/navigationAction updated
6953. By Cris Dywan

Related page boilerplate in NavigationAction

Revision history for this message
Danielle Foré (danrabbit) wrote :

For what it's worth, Gtk.Action is also deprecated :p The only thing I can really figure out so far is that the button itself is visible but the Gtk.Image packed into it is set visible = false.

Revision history for this message
Cris Dywan (kalikiana) wrote :

The slight predicament is that there's nothing replacing Gtk.Action. We need something with an icon, a short cut, sub menus and a label. We have Midori.ContextAction. But it still inherits from Gtk.Action because otherwise a lot of code would have to be changed for the sake of re-implementing the same functionality without existing API... and trying to get away from that you hit these very stupid time sink bugs where GTK+ doesn't work the same way if you use gicon, historical bugs never fixed in Gtk.Action and code that wasn't tested because, well, GNOME default apps are never used with non-recent GTK+ releases.

That said, what I would like to see is icon names on ContextAction that automatically append -symbolic, alternate icon names and an accelerators property (plural). I did the midori_browser_add_action method as a step towards that, but I just don't see it happening in one branch.

Revision history for this message
Danielle Foré (danrabbit) wrote :

Hrm accoring to valadoc, GLib.Action replaces it http://valadoc.org/#!api=gio-2.0/GLib.Action

Unmerged revisions

6953. By Cris Dywan

Related page boilerplate in NavigationAction

6952. By Cris Dywan

Coding style fixes

6951. By Cris Dywan

Remaining NavigationAction subclasses

6950. By Cris Dywan

Merge lp:midori

6949. By Cris Dywan

Split Back, Forward and friends into NavigationAction

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'midori/midori-browser.c'
--- midori/midori-browser.c 2015-06-03 02:05:28 +0000
+++ midori/midori-browser.c 2015-06-07 21:30:55 +0000
@@ -192,12 +192,6 @@
192 GParamSpec* pspec,192 GParamSpec* pspec,
193 MidoriBrowser* browser);193 MidoriBrowser* browser);
194194
195static void
196midori_browser_toolbar_popup_context_menu_history (MidoriBrowser* browser,
197 GtkWidget* widget,
198 gboolean back,
199 gint x,
200 gint y);
201void195void
202midori_panel_set_toolbar_style (MidoriPanel* panel,196midori_panel_set_toolbar_style (MidoriPanel* panel,
203 GtkToolbarStyle style);197 GtkToolbarStyle style);
@@ -292,13 +286,6 @@
292{286{
293 GtkAction* action;287 GtkAction* action;
294288
295 _action_set_sensitive (browser, "Back", midori_view_can_go_back (view));
296 _action_set_sensitive (browser, "Forward", midori_tab_can_go_forward (MIDORI_TAB (view)));
297 _action_set_sensitive (browser, "Previous",
298 midori_view_get_previous_page (view) != NULL);
299 _action_set_sensitive (browser, "Next",
300 midori_view_get_next_page (view) != NULL);
301
302 _action_set_sensitive (browser, "AddSpeedDial", !midori_view_is_blank (view));289 _action_set_sensitive (browser, "AddSpeedDial", !midori_view_is_blank (view));
303 _action_set_sensitive (browser, "BookmarkAdd", !midori_view_is_blank (view));290 _action_set_sensitive (browser, "BookmarkAdd", !midori_view_is_blank (view));
304 _action_set_sensitive (browser, "MailTo", !midori_view_is_blank (view));291 _action_set_sensitive (browser, "MailTo", !midori_view_is_blank (view));
@@ -314,22 +301,6 @@
314 _action_set_sensitive (browser, "SourceViewDom",301 _action_set_sensitive (browser, "SourceViewDom",
315 midori_tab_can_view_source (MIDORI_TAB (view)));302 midori_tab_can_view_source (MIDORI_TAB (view)));
316303
317 action = _action_by_name (browser, "NextForward");
318 if (midori_tab_can_go_forward (MIDORI_TAB (view)))
319 {
320 g_object_set (action,
321 "stock-id", GTK_STOCK_GO_FORWARD,
322 "tooltip", _("Go forward to the next page"),
323 "sensitive", TRUE, NULL);
324 }
325 else
326 {
327 g_object_set (action,
328 "stock-id", GTK_STOCK_MEDIA_NEXT,
329 "tooltip", _("Go to the next sub-page"),
330 "sensitive", midori_view_get_next_page (view) != NULL, NULL);
331 }
332
333 action = _action_by_name (browser, "Location");304 action = _action_by_name (browser, "Location");
334 if (midori_tab_is_blank (MIDORI_TAB (view)))305 if (midori_tab_is_blank (MIDORI_TAB (view)))
335 {306 {
@@ -432,23 +403,6 @@
432 action = _action_by_name (browser, "Location");403 action = _action_by_name (browser, "Location");
433 midori_location_action_set_progress (MIDORI_LOCATION_ACTION (action), progress);404 midori_location_action_set_progress (MIDORI_LOCATION_ACTION (action), progress);
434405
435 _action_set_sensitive (browser, "Reload", !loading);
436 _action_set_sensitive (browser, "Stop", loading);
437
438 action = _action_by_name (browser, "ReloadStop");
439 if (!loading)
440 {
441 g_object_set (action,
442 "stock-id", GTK_STOCK_REFRESH,
443 "tooltip", _("Reload the current page"), NULL);
444 }
445 else
446 {
447 g_object_set (action,
448 "stock-id", GTK_STOCK_STOP,
449 "tooltip", _("Stop loading the current page"), NULL);
450 }
451
452 g_object_set (browser->throbber, "active", loading, "visible", loading, NULL);406 g_object_set (browser->throbber, "active", loading, "visible", loading, NULL);
453}407}
454408
@@ -734,8 +688,6 @@
734 const gchar* uri = midori_view_get_display_uri (view);688 const gchar* uri = midori_view_get_display_uri (view);
735 GtkAction* action = _action_by_name (browser, "Location");689 GtkAction* action = _action_by_name (browser, "Location");
736 midori_location_action_set_text (MIDORI_LOCATION_ACTION (action), uri);690 midori_location_action_set_text (MIDORI_LOCATION_ACTION (action), uri);
737 _action_set_sensitive (browser, "Back", midori_view_can_go_back (view));
738 _action_set_sensitive (browser, "Forward", midori_tab_can_go_forward (MIDORI_TAB (view)));
739 g_object_notify (G_OBJECT (browser), "uri");691 g_object_notify (G_OBJECT (browser), "uri");
740 }692 }
741}693}
@@ -2059,53 +2011,6 @@
2059 /* Nothing to do */2011 /* Nothing to do */
2060}2012}
20612013
2062static void
2063_update_tooltip_if_changed (GtkAction* action,
2064 const gchar* text)
2065{
2066 gchar *old;
2067 g_object_get (action, "tooltip", &old, NULL);
2068 if (g_strcmp0(old, text)) {
2069 g_object_set (action,
2070 "tooltip", text, NULL);
2071 }
2072 g_free (old);
2073}
2074
2075static void
2076_update_reload_tooltip (GtkWidget* widget,
2077 GdkEventKey* event,
2078 gboolean released)
2079{
2080 MidoriBrowser* browser = MIDORI_BROWSER (widget);
2081
2082 /* Update the reload/stop tooltip in case we are holding the hard refresh modifiers*/
2083 GtkAction *reload_stop = _action_by_name (browser, "ReloadStop");
2084 GtkAction *reload = _action_by_name (browser, "Reload");
2085 GdkModifierType mask;
2086 gdk_window_get_pointer (gtk_widget_get_window (widget), NULL, NULL, &mask);
2087 const gchar *target;
2088
2089 if ( mask & GDK_SHIFT_MASK)
2090 {
2091 target = _("Reload page without caching");
2092 }
2093 else
2094 {
2095 target = _("Reload the current page");
2096 }
2097 _update_tooltip_if_changed (reload_stop, target);
2098 _update_tooltip_if_changed (reload, target);
2099}
2100
2101static gboolean
2102midori_browser_key_release_event (GtkWidget* widget,
2103 GdkEventKey* event)
2104{
2105 _update_reload_tooltip (widget, event, TRUE);
2106 return GTK_WIDGET_CLASS (midori_browser_parent_class)->key_release_event (widget, event);
2107}
2108
2109static gboolean2014static gboolean
2110midori_browser_key_press_event (GtkWidget* widget,2015midori_browser_key_press_event (GtkWidget* widget,
2111 GdkEventKey* event)2016 GdkEventKey* event)
@@ -2115,7 +2020,6 @@
2115 GtkWidgetClass* widget_class;2020 GtkWidgetClass* widget_class;
2116 guint clean_state;2021 guint clean_state;
21172022
2118 _update_reload_tooltip(widget, event, FALSE);
2119 /* Interpret Ctrl(+Shift)+Tab as tab switching for compatibility */2023 /* Interpret Ctrl(+Shift)+Tab as tab switching for compatibility */
2120 if (midori_browser_get_nth_tab (browser, 1) != NULL2024 if (midori_browser_get_nth_tab (browser, 1) != NULL
2121 && event->keyval == GDK_KEY_Tab2025 && event->keyval == GDK_KEY_Tab
@@ -2156,18 +2060,15 @@
2156 && !webkit_web_view_can_paste_clipboard (WEBKIT_WEB_VIEW (focus)))2060 && !webkit_web_view_can_paste_clipboard (WEBKIT_WEB_VIEW (focus)))
2157 {2061 {
2158 /* Space at the bottom of the page: Go to next page */2062 /* Space at the bottom of the page: Go to next page */
2159 MidoriView* view = midori_view_get_for_widget (focus);
2160 GtkScrolledWindow* scrolled = GTK_SCROLLED_WINDOW (gtk_widget_get_parent (focus));2063 GtkScrolledWindow* scrolled = GTK_SCROLLED_WINDOW (gtk_widget_get_parent (focus));
2161 GtkAdjustment* vadjust = gtk_scrolled_window_get_vadjustment (scrolled);2064 GtkAdjustment* vadjust = gtk_scrolled_window_get_vadjustment (scrolled);
2162 if (gtk_adjustment_get_value (vadjust)2065 if (gtk_adjustment_get_value (vadjust)
2163 == (gtk_adjustment_get_upper (vadjust) - gtk_adjustment_get_page_size (vadjust)))2066 == (gtk_adjustment_get_upper (vadjust) - gtk_adjustment_get_page_size (vadjust)))
2164 {2067 {
2165 /* Duplicate here because the URI pointer might change */2068 GtkAction* next = _action_by_name (browser, "Next");
2166 gchar* uri = g_strdup (midori_view_get_next_page (view));2069 if (gtk_action_get_sensitive (next))
2167 if (uri != NULL)
2168 {2070 {
2169 midori_view_set_uri (view, uri);2071 gtk_action_activate (next);
2170 g_free (uri);
2171 return TRUE;2072 return TRUE;
2172 }2073 }
2173 }2074 }
@@ -2441,7 +2342,6 @@
24412342
2442 gtkwidget_class = GTK_WIDGET_CLASS (class);2343 gtkwidget_class = GTK_WIDGET_CLASS (class);
2443 gtkwidget_class->key_press_event = midori_browser_key_press_event;2344 gtkwidget_class->key_press_event = midori_browser_key_press_event;
2444 gtkwidget_class->key_release_event = midori_browser_key_release_event;
24452345
2446 gobject_class = G_OBJECT_CLASS (class);2346 gobject_class = G_OBJECT_CLASS (class);
2447 gobject_class->dispose = midori_browser_dispose;2347 gobject_class->dispose = midori_browser_dispose;
@@ -3515,37 +3415,6 @@
3515}3415}
35163416
3517static void3417static void
3518_action_reload_stop_activate (GtkAction* action,
3519 MidoriBrowser* browser)
3520{
3521 GtkWidget* view = midori_browser_get_current_tab (browser);
3522 gchar* stock_id;
3523 g_object_get (action, "stock-id", &stock_id, NULL);
3524
3525 /* Refresh or stop, depending on the stock id */
3526 if (!strcmp (stock_id, GTK_STOCK_REFRESH))
3527 {
3528 GdkModifierType state = (GdkModifierType)0;
3529 gint x, y;
3530 GdkWindow* window;
3531 gboolean from_cache = TRUE;
3532
3533 if (!strcmp (gtk_action_get_name (action), "ReloadUncached"))
3534 from_cache = FALSE;
3535 else if ((window = gtk_widget_get_window (GTK_WIDGET (browser))))
3536 {
3537 gdk_window_get_pointer (window, &x, &y, &state);
3538 if (state & GDK_SHIFT_MASK)
3539 from_cache = FALSE;
3540 }
3541 midori_view_reload (MIDORI_VIEW (view), from_cache);
3542 }
3543 else
3544 midori_tab_stop_loading (MIDORI_TAB (view));
3545 g_free (stock_id);
3546}
3547
3548static void
3549_action_zoom_activate (GtkAction* action,3418_action_zoom_activate (GtkAction* action,
3550 MidoriBrowser* browser)3419 MidoriBrowser* browser)
3551{3420{
@@ -3792,129 +3661,6 @@
3792 g_free (stylesheet);3661 g_free (stylesheet);
3793}3662}
37943663
3795static gboolean
3796_action_navigation_activate (GtkAction* action,
3797 MidoriBrowser* browser)
3798{
3799 MidoriView* view;
3800 GtkWidget* tab;
3801 gchar* uri;
3802 const gchar* name;
3803 gboolean middle_click;
3804
3805 g_assert (GTK_IS_ACTION (action));
3806
3807 if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (action),
3808 "midori-middle-click")))
3809 {
3810 middle_click = TRUE;
3811 g_object_set_data (G_OBJECT (action),
3812 "midori-middle-click",
3813 GINT_TO_POINTER(0));
3814 }
3815 else
3816 middle_click = FALSE;
3817
3818 tab = midori_browser_get_current_tab (browser);
3819 view = MIDORI_VIEW (tab);
3820 name = gtk_action_get_name (action);
3821
3822 if (!strcmp (name, "NextForward"))
3823 name = midori_tab_can_go_forward (MIDORI_TAB (view)) ? "Forward" : "Next";
3824
3825 if (g_str_equal (name, "Back"))
3826 {
3827 if (middle_click)
3828 {
3829 WebKitWebView* web_view = WEBKIT_WEB_VIEW (midori_view_get_web_view (view));
3830 #ifdef HAVE_WEBKIT2
3831 WebKitBackForwardList* list = webkit_web_view_get_back_forward_list (web_view);
3832 WebKitBackForwardListItem* item = webkit_back_forward_list_get_back_item (list);
3833 const gchar* back_uri = webkit_back_forward_list_item_get_uri (item);
3834 #else
3835 WebKitWebBackForwardList* list = webkit_web_view_get_back_forward_list (web_view);
3836 WebKitWebHistoryItem* item = webkit_web_back_forward_list_get_forward_item (list);
3837 const gchar* back_uri = webkit_web_history_item_get_uri (item);
3838 #endif
3839
3840 GtkWidget* new_view = midori_browser_add_uri (browser, back_uri);
3841 midori_browser_set_current_tab_smartly (browser, new_view);
3842 }
3843 else
3844 midori_view_go_back (view);
3845
3846 return TRUE;
3847 }
3848 else if (g_str_equal (name, "Forward"))
3849 {
3850 if (middle_click)
3851 {
3852 WebKitWebView* web_view = WEBKIT_WEB_VIEW (midori_view_get_web_view (view));
3853 #ifdef HAVE_WEBKIT2
3854 WebKitBackForwardList* list = webkit_web_view_get_back_forward_list (web_view);
3855 WebKitBackForwardListItem* item = webkit_back_forward_list_get_forward_item (list);
3856 const gchar* forward_uri = webkit_back_forward_list_item_get_uri (item);
3857 #else
3858 WebKitWebBackForwardList* list = webkit_web_view_get_back_forward_list (web_view);
3859 WebKitWebHistoryItem* item = webkit_web_back_forward_list_get_forward_item (list);
3860 const gchar* forward_uri = webkit_web_history_item_get_uri (item);
3861 #endif
3862
3863 GtkWidget* new_view = midori_browser_add_uri (browser, forward_uri);
3864 midori_browser_set_current_tab_smartly (browser, new_view);
3865 }
3866 else
3867 midori_tab_go_forward (MIDORI_TAB (view));
3868
3869 return TRUE;
3870 }
3871 else if (g_str_equal (name, "Previous"))
3872 {
3873 /* Duplicate here because the URI pointer might change */
3874 uri = g_strdup (midori_view_get_previous_page (view));
3875
3876 if (middle_click)
3877 {
3878 GtkWidget* new_view = midori_browser_add_uri (browser, uri);
3879 midori_browser_set_current_tab_smartly (browser, new_view);
3880 }
3881 else
3882 midori_view_set_uri (view, uri);
3883
3884 g_free (uri);
3885 return TRUE;
3886 }
3887 else if (g_str_equal (name, "Next"))
3888 {
3889 /* Duplicate here because the URI pointer might change */
3890 uri = g_strdup (midori_view_get_next_page (view));
3891
3892 if (middle_click)
3893 {
3894 GtkWidget* new_view = midori_browser_add_uri (browser, uri);
3895 midori_browser_set_current_tab_smartly (browser, new_view);
3896 }
3897 else
3898 midori_view_set_uri (view, uri);
3899
3900 g_free (uri);
3901 return TRUE;
3902 }
3903 else if (g_str_equal (name, "Homepage"))
3904 {
3905 if (middle_click)
3906 {
3907 GtkWidget* new_view = midori_browser_add_uri (browser, "about:home");
3908 midori_browser_set_current_tab_smartly (browser, new_view);
3909 }
3910 else
3911 midori_view_set_uri (view, "about:home");
3912
3913 return TRUE;
3914 }
3915 return FALSE;
3916}
3917
3918static void3664static void
3919_action_location_activate (GtkAction* action,3665_action_location_activate (GtkAction* action,
3920 MidoriBrowser* browser)3666 MidoriBrowser* browser)
@@ -4352,17 +4098,6 @@
4352 GtkAction* action,4098 GtkAction* action,
4353 MidoriBrowser* browser)4099 MidoriBrowser* browser)
4354{4100{
4355 const gchar* name = gtk_action_get_name (action);
4356 gboolean back = !g_strcmp0 (name, "Back");
4357 if (back
4358 || g_str_has_suffix (name, "Forward"))
4359 {
4360 midori_browser_toolbar_popup_context_menu_history (
4361 browser,
4362 widget,
4363 back, 0, 0);
4364 return TRUE;
4365 }
4366 return midori_browser_toolbar_popup_context_menu_cb (widget, 0, 0, 0, browser);4101 return midori_browser_toolbar_popup_context_menu_cb (widget, 0, 0, 0, browser);
4367}4102}
43684103
@@ -4455,23 +4190,6 @@
4455 return FALSE;4190 return FALSE;
4456}4191}
44574192
4458static gboolean
4459midori_browser_menu_item_middle_click_event_cb (GtkWidget* toolitem,
4460 GdkEventButton* event,
4461 MidoriBrowser* browser)
4462{
4463 if (MIDORI_EVENT_NEW_TAB (event))
4464 {
4465 GtkAction* action;
4466
4467 action = gtk_activatable_get_related_action (GTK_ACTIVATABLE (toolitem));
4468 g_object_set_data (G_OBJECT (action), "midori-middle-click", GINT_TO_POINTER (1));
4469
4470 return _action_navigation_activate (action, browser);
4471 }
4472 return FALSE;
4473}
4474
4475static void4193static void
4476_action_bookmark_add_activate (GtkAction* action,4194_action_bookmark_add_activate (GtkAction* action,
4477 MidoriBrowser* browser)4195 MidoriBrowser* browser)
@@ -5305,18 +5023,6 @@
53055023
5306 { "View", NULL, N_("_View") },5024 { "View", NULL, N_("_View") },
5307 { "Toolbars", NULL, N_("_Toolbars") },5025 { "Toolbars", NULL, N_("_Toolbars") },
5308 { "Reload", GTK_STOCK_REFRESH,
5309 NULL, "<Ctrl>r",
5310 N_("Reload the current page"), G_CALLBACK (_action_reload_stop_activate) },
5311 { "ReloadUncached", GTK_STOCK_REFRESH,
5312 N_("Reload page without caching"), "<Ctrl><Shift>r",
5313 NULL, G_CALLBACK (_action_reload_stop_activate) },
5314 { "Stop", GTK_STOCK_STOP,
5315 NULL, "Escape",
5316 N_("Stop loading the current page"), G_CALLBACK (_action_reload_stop_activate) },
5317 { "ReloadStop", GTK_STOCK_STOP,
5318 NULL, "",
5319 N_("Reload the current page"), G_CALLBACK (_action_reload_stop_activate) },
5320 { "ZoomIn", GTK_STOCK_ZOOM_IN,5026 { "ZoomIn", GTK_STOCK_ZOOM_IN,
5321 NULL, "<Ctrl>plus",5027 NULL, "<Ctrl>plus",
5322 N_("Increase the zoom level"), G_CALLBACK (_action_zoom_activate) },5028 N_("Increase the zoom level"), G_CALLBACK (_action_zoom_activate) },
@@ -5356,26 +5062,6 @@
5356 NULL, G_CALLBACK (_action_readable_activate) },5062 NULL, G_CALLBACK (_action_readable_activate) },
53575063
5358 { "Go", NULL, N_("_Go") },5064 { "Go", NULL, N_("_Go") },
5359 { "Back", GTK_STOCK_GO_BACK,
5360 NULL, "<Alt>Left",
5361 N_("Go back to the previous page"), G_CALLBACK (_action_navigation_activate) },
5362 { "Forward", GTK_STOCK_GO_FORWARD,
5363 NULL, "<Alt>Right",
5364 N_("Go forward to the next page"), G_CALLBACK (_action_navigation_activate) },
5365 { "Previous", GTK_STOCK_MEDIA_PREVIOUS,
5366 NULL, "<Alt><Shift>Left",
5367 /* i18n: Visit the previous logical page, ie. in a forum or blog */
5368 N_("Go to the previous sub-page"), G_CALLBACK (_action_navigation_activate) },
5369 { "Next", GTK_STOCK_MEDIA_NEXT,
5370 NULL, "<Alt><Shift>Right",
5371 /* i18n: Visit the following logical page, ie. in a forum or blog */
5372 N_("Go to the next sub-page"), G_CALLBACK (_action_navigation_activate) },
5373 { "NextForward", GTK_STOCK_MEDIA_NEXT,
5374 N_("Next or Forward"), "",
5375 N_("Go to the next sub-page or next page in history"), G_CALLBACK (_action_navigation_activate) },
5376 { "Homepage", GTK_STOCK_HOME,
5377 N_("_Homepage"), "<Alt>Home",
5378 N_("Go to your homepage"), G_CALLBACK (_action_navigation_activate) },
5379 { "TrashEmpty", GTK_STOCK_CLEAR,5065 { "TrashEmpty", GTK_STOCK_CLEAR,
5380 N_("Empty Trash"), "",5066 N_("Empty Trash"), "",
5381 NULL, G_CALLBACK (_action_trash_empty_activate) },5067 NULL, G_CALLBACK (_action_trash_empty_activate) },
@@ -5914,6 +5600,20 @@
5914 return FALSE;5600 return FALSE;
5915}5601}
59165602
5603static GtkAction*
5604midori_browser_add_action (MidoriBrowser* browser,
5605 GType type,
5606 const gchar* accelerator)
5607{
5608 GtkAction* action = g_object_new (type, NULL);
5609 g_return_val_if_fail (gtk_action_get_name (action) != NULL, action);
5610 gtk_action_group_add_action_with_accel (browser->action_group, action, accelerator);
5611 if (MIDORI_IS_NAVIGATION_ACTION (action))
5612 g_object_bind_property (browser, "tab", action, "tab", 0);
5613 g_object_unref (action);
5614 return action;
5615}
5616
5917static void5617static void
5918midori_browser_init (MidoriBrowser* browser)5618midori_browser_init (MidoriBrowser* browser)
5919{5619{
@@ -5925,9 +5625,6 @@
5925 GError* error;5625 GError* error;
5926 GtkAction* action;5626 GtkAction* action;
5927 GtkWidget* menuitem;5627 GtkWidget* menuitem;
5928 GtkWidget* homepage;
5929 GtkWidget* back;
5930 GtkWidget* forward;
5931 GtkWidget* hpaned;5628 GtkWidget* hpaned;
5932 GtkWidget* vpaned;5629 GtkWidget* vpaned;
5933 GtkWidget* scrolled;5630 GtkWidget* scrolled;
@@ -5995,6 +5692,17 @@
5995 /* Hide the 'Dummy' which only holds otherwise unused actions */5692 /* Hide the 'Dummy' which only holds otherwise unused actions */
5996 _action_set_visible (browser, "Dummy", FALSE);5693 _action_set_visible (browser, "Dummy", FALSE);
59975694
5695 midori_browser_add_action (browser, MIDORI_TYPE_BACK_ACTION, "<Alt>Left");
5696 midori_browser_add_action (browser, MIDORI_TYPE_PREVIOUS_ACTION, "<Alt><Shift>Left");
5697 midori_browser_add_action (browser, MIDORI_TYPE_FORWARD_ACTION, "<Alt>Right");
5698 midori_browser_add_action (browser, MIDORI_TYPE_NEXT_ACTION, "<Alt><Shift>Right");
5699 midori_browser_add_action (browser, MIDORI_TYPE_NEXT_FORWARD_ACTION, "");
5700 midori_browser_add_action (browser, MIDORI_TYPE_HOMEPAGE_ACTION, "<Alt>Home");
5701 midori_browser_add_action (browser, MIDORI_TYPE_STOP_ACTION, "Escape");
5702 midori_browser_add_action (browser, MIDORI_TYPE_RELOAD_ACTION, "<Ctrl>r");
5703 midori_browser_add_action (browser, MIDORI_TYPE_RELOAD_UNCACHED_ACTION, "<Ctrl><Shift>r");
5704 midori_browser_add_action (browser, MIDORI_TYPE_RELOAD_STOP_ACTION, "");
5705
5998 action = g_object_new (KATZE_TYPE_SEPARATOR_ACTION,5706 action = g_object_new (KATZE_TYPE_SEPARATOR_ACTION,
5999 "name", "Separator",5707 "name", "Separator",
6000 "label", _("_Separator"),5708 "label", _("_Separator"),
@@ -6049,11 +5757,7 @@
6049 action, "<Ctrl>K");5757 action, "<Ctrl>K");
6050 g_object_unref (action);5758 g_object_unref (action);
60515759
6052 action = g_object_new (MIDORI_TYPE_PANED_ACTION,5760 midori_browser_add_action (browser, MIDORI_TYPE_PANED_ACTION, "");
6053 "name", "LocationSearch",
6054 NULL);
6055 gtk_action_group_add_action (browser->action_group, action);
6056 g_object_unref (action);
60575761
6058 action = g_object_new (KATZE_TYPE_ARRAY_ACTION,5762 action = g_object_new (KATZE_TYPE_ARRAY_ACTION,
6059 "name", "Trash",5763 "name", "Trash",
@@ -6178,22 +5882,6 @@
6178 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (5882 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (
6179 gtk_ui_manager_get_widget (ui_manager, "/menubar/Go/Location")), NULL);5883 gtk_ui_manager_get_widget (ui_manager, "/menubar/Go/Location")), NULL);
61805884
6181 homepage = gtk_ui_manager_get_widget (ui_manager, "/menubar/Go/Homepage");
6182 g_signal_connect (homepage, "button-press-event",
6183 G_CALLBACK (midori_browser_menu_item_middle_click_event_cb), browser);
6184 back = gtk_ui_manager_get_widget (ui_manager, "/menubar/Go/Back");
6185 g_signal_connect (back, "button-press-event",
6186 G_CALLBACK (midori_browser_menu_item_middle_click_event_cb), browser);
6187 forward = gtk_ui_manager_get_widget (ui_manager, "/menubar/Go/Forward");
6188 g_signal_connect (forward, "button-press-event",
6189 G_CALLBACK (midori_browser_menu_item_middle_click_event_cb), browser);
6190 forward = gtk_ui_manager_get_widget (ui_manager, "/menubar/Go/Previous");
6191 g_signal_connect (forward, "button-press-event",
6192 G_CALLBACK (midori_browser_menu_item_middle_click_event_cb), browser);
6193 forward = gtk_ui_manager_get_widget (ui_manager, "/menubar/Go/Next");
6194 g_signal_connect (forward, "button-press-event",
6195 G_CALLBACK (midori_browser_menu_item_middle_click_event_cb), browser);
6196
6197 _action_set_sensitive (browser, "EncodingCustom", FALSE);5885 _action_set_sensitive (browser, "EncodingCustom", FALSE);
6198 _action_set_visible (browser, "LastSession", FALSE);5886 _action_set_visible (browser, "LastSession", FALSE);
61995887
@@ -6376,81 +6064,6 @@
6376 gtk_toolbar_style);6064 gtk_toolbar_style);
6377}6065}
63786066
6379#ifndef HAVE_WEBKIT2
6380static void
6381midori_browser_toolbar_popup_context_menu_history_cb (GtkMenuItem* menu_item,
6382 MidoriBrowser* browser)
6383{
6384 gint steps = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (menu_item), "steps"));
6385 MidoriView* view = MIDORI_VIEW (midori_browser_get_current_tab (browser));
6386 midori_view_go_back_or_forward (view, steps);
6387}
6388#endif
6389
6390static void
6391midori_browser_toolbar_popup_context_menu_history (MidoriBrowser* browser,
6392 GtkWidget* widget,
6393 gboolean back,
6394 gint x,
6395 gint y)
6396{
6397#ifndef HAVE_WEBKIT2
6398 const gint step = back ? -1 : 1;
6399 gint steps = step;
6400 GtkWidget* menu;
6401 WebKitWebBackForwardList* list;
6402 WebKitWebHistoryItem* current_item;
6403 WebKitWebHistoryItem* history_item;
6404 WebKitWebHistoryItem* (*history_next)(WebKitWebBackForwardList*);
6405 void (*history_action)(WebKitWebBackForwardList*);
6406
6407 list = webkit_web_view_get_back_forward_list (
6408 WEBKIT_WEB_VIEW (midori_view_get_web_view (
6409 MIDORI_VIEW (midori_browser_get_current_tab (browser)))));
6410
6411 if (!list)
6412 return;
6413
6414 menu = gtk_menu_new ();
6415
6416 history_action = back ?
6417 webkit_web_back_forward_list_go_back :
6418 webkit_web_back_forward_list_go_forward;
6419 history_next = back ?
6420 webkit_web_back_forward_list_get_back_item :
6421 webkit_web_back_forward_list_get_forward_item;
6422 current_item = webkit_web_back_forward_list_get_current_item (list);
6423
6424 for (; (history_item = history_next (list)); history_action (list), steps += step)
6425 {
6426 const gchar* uri = webkit_web_history_item_get_uri (history_item);
6427 GtkWidget* menu_item = gtk_image_menu_item_new_with_label (
6428 webkit_web_history_item_get_title (history_item));
6429 GdkPixbuf* pixbuf;
6430 if ((pixbuf = midori_paths_get_icon (uri, widget)))
6431 {
6432 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item),
6433 gtk_image_new_from_pixbuf (pixbuf));
6434 g_object_unref (pixbuf);
6435 }
6436 g_object_set_data (G_OBJECT (menu_item), "uri", (gpointer)uri);
6437 g_object_set_data (G_OBJECT (menu_item), "steps", GINT_TO_POINTER (steps));
6438 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
6439 g_signal_connect (G_OBJECT (menu_item), "activate",
6440 G_CALLBACK (midori_browser_toolbar_popup_context_menu_history_cb),
6441 browser);
6442 if (steps == (10 - 1))
6443 break;
6444 }
6445
6446 webkit_web_back_forward_list_go_to_item (list, current_item);
6447 gtk_widget_show_all (menu);
6448
6449 katze_widget_popup (widget, GTK_MENU (menu), NULL,
6450 KATZE_MENU_POSITION_LEFT);
6451#endif
6452}
6453
6454static void6067static void
6455_midori_browser_update_settings (MidoriBrowser* browser)6068_midori_browser_update_settings (MidoriBrowser* browser)
6456{6069{
64576070
=== added file 'midori/midori-navigationaction.vala'
--- midori/midori-navigationaction.vala 1970-01-01 00:00:00 +0000
+++ midori/midori-navigationaction.vala 2015-06-07 21:30:55 +0000
@@ -0,0 +1,293 @@
1/*
2 Copyright (C) 2015 Christian Dywan <christian@twotoasts.de>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 See the file COPYING for the full license text.
10*/
11
12namespace Midori {
13 /* Back or forward action, with a submenu
14 Since: 0.6.0 */
15 protected abstract class NavigationAction : Gtk.Action {
16 protected string uri { get; set; }
17 protected double progress { get; set; }
18
19 public Midori.Tab? tab { get; set; }
20 public signal string? middle_click_uri ();
21 public signal Gtk.Menu? context_menu ();
22
23 Gtk.ToolButton? toolitem;
24 public override unowned Gtk.Widget create_tool_item () {
25 toolitem = new Gtk.ToolButton (null, null);
26 toolitem.icon_widget = create_icon (Gtk.IconSize.LARGE_TOOLBAR);
27 bind_property ("label", toolitem, "label");
28 bind_property ("tooltip", toolitem, "tooltip-text");
29 bind_property ("is-important", toolitem, "is-important");
30 // Connect to child because ToolItem blocks button-press-event
31 toolitem.get_child ().button_press_event.connect ((event) => {
32 // Ctrl+click or middle click
33 string? uri = event.button == 2
34 || (event.button == 1 && (bool)(event.state & Gdk.ModifierType.CONTROL_MASK))
35 ? middle_click_uri () : null;
36 if (uri != null) {
37 Midori.Settings? settings = null;
38 /* Midori.View.settings */
39 tab.get ("settings", ref settings);
40 GLib.Signal.emit_by_name (tab, "new-tab", uri, settings.open_tabs_in_the_background);
41 return true;
42 }
43 Gtk.Menu? menu = event.button == 3 ? context_menu () : null;
44 if (menu != null) {
45 menu.show ();
46 menu.attach_to_widget (toolitem, null);
47 menu.popup (null, null, null, 1, Gtk.get_current_event_time ());
48 return true;
49 }
50 return false;
51 });
52 return toolitem;
53 }
54
55 construct {
56 notify["tab"].connect (tab_changed);
57 }
58
59 void tab_changed (ParamSpec pspec) {
60 tab.bind_property ("uri", this, "uri", 0);
61 tab.bind_property ("progress", this, "progress", 0);
62 }
63
64 string? related_page (string rel, string local) {
65#if HAVE_WEBKIT2
66 return null;
67#else
68 return null;
69#endif
70 }
71
72 string next_page () {
73 /* i18n: word stem of "next page" type links, case is not important */
74 return related_page ("next", _("next"));
75 }
76
77 string previous_page () {
78 /* i18n: word stem of "previous page" type links, case is not important */
79 return related_page ("prev", _("previous"));
80 }
81
82 protected bool can_go_next () {
83 return next_page () != null;
84 }
85
86 protected void go_next () {
87 tab.web_view.load_uri (next_page ());
88 }
89
90 protected void go_next_or_forward () {
91 if (tab.web_view.can_go_forward ())
92 tab.web_view.go_forward ();
93 else
94 go_next ();
95 }
96
97 protected bool can_go_previous () {
98 return previous_page () != null;
99 }
100
101 protected void go_previous () {
102 tab.web_view.load_uri (previous_page ());
103 }
104
105 GLib.Icon? scale_if_needed (GLib.Icon? icon) {
106 if (icon is Gdk.Pixbuf) {
107 var pixbuf = icon as Gdk.Pixbuf;
108 int icon_width = 16, icon_height = 16;
109 Gtk.icon_size_lookup (Gtk.IconSize.MENU, out icon_width, out icon_height);
110 if (pixbuf.width > icon_width || pixbuf.height > icon_height)
111 return pixbuf.scale_simple (icon_width, icon_height, Gdk.InterpType.BILINEAR);
112 }
113 return icon;
114 }
115
116#if HAVE_WEBKIT2
117 protected Gtk.Menu? build_menu (List<weak WebKit.BackForwardListItem> items) {
118#else
119 protected Gtk.Menu? build_menu (List<weak WebKit.WebHistoryItem> items) {
120#endif
121 var menu = new Gtk.Menu ();
122 foreach (var item in items) {
123 var menuitem = new Gtk.ImageMenuItem.with_label (item.get_title ());
124 var icon = new Midori.URI.Icon (item.get_uri ());
125 menuitem.image = new Gtk.Image.from_gicon (scale_if_needed (icon), Gtk.IconSize.MENU);
126 menuitem.always_show_image = true;
127 menuitem.show_all ();
128 menuitem.activate.connect (() =>{ tab.web_view.load_uri (item.get_uri ()); });
129 menu.append (menuitem);
130 }
131 return menu;
132 }
133 }
134
135 public class BackAction : NavigationAction {
136 construct {
137 set ("name", "Back",
138 "tooltip", _("Go back to the previous page"),
139 "stock-id", Gtk.Stock.GO_BACK,
140 "is-important", true);
141
142 bind_property ("uri", this, "sensitive", 0,
143 (binding, source, ref target) => { target = tab.web_view.can_go_back (); return true; });
144 activate.connect (() => { tab.web_view.go_back (); });
145 middle_click_uri.connect (() => { return tab.web_view.get_back_forward_list ().get_back_item ().get_uri (); });
146 context_menu.connect (() => { return build_menu (tab.web_view.get_back_forward_list ().get_back_list_with_limit (10)); });
147 }
148 }
149
150 public class PreviousAction : NavigationAction {
151 construct {
152 set ("name", "Previous",
153 /* i18n: Visit the previous logical page, ie. in a forum or blog */
154 "tooltip", _("Go to the previous sub-page"),
155 "stock-id", Gtk.Stock.MEDIA_PREVIOUS);
156
157 bind_property ("uri", this, "sensitive", 0,
158 (binding, source, ref target) => { target = can_go_previous (); return true; });
159 activate.connect (() => { go_previous (); });
160 context_menu.connect (() => { return build_menu (tab.web_view.get_back_forward_list ().get_back_list_with_limit (10)); });
161 }
162 }
163
164 public class ForwardAction : NavigationAction {
165 construct {
166 set ("name", "Forward",
167 "tooltip", _("Go forward to the next page"),
168 "stock-id", Gtk.Stock.GO_FORWARD);
169
170 bind_property ("uri", this, "sensitive", 0,
171 (binding, source, ref target) => { target = tab.web_view.can_go_forward (); return true; });
172 activate.connect (() => { tab.web_view.go_forward (); });
173 middle_click_uri.connect (() => { return tab.web_view.get_back_forward_list ().get_forward_item ().get_uri (); });
174 context_menu.connect (() => { return build_menu (tab.web_view.get_back_forward_list ().get_forward_list_with_limit (10)); });
175 }
176 }
177
178 public class NextAction : NavigationAction {
179 construct {
180 set ("name", "Next",
181 /* i18n: Visit the following logical page, ie. in a forum or blog */
182 "tooltip", _("Go to the next sub-page"),
183 "stock-id", Gtk.Stock.MEDIA_NEXT);
184
185 bind_property ("uri", this, "sensitive", 0,
186 (binding, source, ref target) => { target = can_go_next (); return true; });
187 activate.connect (() => { go_next (); });
188 context_menu.connect (() => { return build_menu (tab.web_view.get_back_forward_list ().get_forward_list_with_limit (10)); });
189 }
190 }
191
192 public class NextForwardAction : NavigationAction {
193 construct {
194 set ("name", "NextForward",
195 "label", _("Next or Forward"));
196
197 bind_property ("uri", this, "sensitive", 0,
198 (binding, source, ref target) => {
199 target = (tab.web_view.can_go_forward () || can_go_next ());
200 stock_id = (can_go_next () ? Gtk.Stock.GO_FORWARD : Gtk.Stock.MEDIA_NEXT);
201 tooltip = (can_go_next () ? _("Go forward to the next page") : _("Go to the next sub-page"));
202 return true;
203 });
204 activate.connect (() => { go_next_or_forward (); });
205 context_menu.connect (() => { return build_menu (tab.web_view.get_back_forward_list ().get_forward_list_with_limit (10)); });
206 }
207 }
208
209 public class HomepageAction : NavigationAction {
210 construct {
211 set ("name", "Homepage",
212 "label", _("_Homepage"),
213 "tooltip", _("Go to your homepage"),
214 "stock-id", Gtk.Stock.HOME);
215
216 activate.connect (() => { tab.web_view.load_uri ("about:home"); });
217 middle_click_uri.connect (() => { return "about:home"; });
218 }
219 }
220
221 public class StopAction : NavigationAction {
222 construct {
223 set ("name", "Stop",
224 "tooltip",_("Stop loading the current page"),
225 "stock-id", Gtk.Stock.STOP);
226
227 bind_property ("progress", this, "sensitive", 0,
228 (binding, source, ref target) =>{
229 target = progress > 0.0;
230 return true;
231 });
232 activate.connect (() => { tab.web_view.stop_loading (); });
233 }
234 }
235
236 public class ReloadAction : NavigationAction {
237 construct {
238 set ("name", "Reload",
239 "tooltip", _("Reload the current page"),
240 "stock-id", Gtk.Stock.REFRESH);
241
242 bind_property ("progress", this, "sensitive", 0,
243 (binding, source, ref target) =>{
244 target = progress == 0.0;
245 return true;
246 });
247 activate.connect (() => { tab.web_view.reload (); });
248 middle_click_uri.connect (() => { return tab.uri; });
249 }
250 }
251
252 public class ReloadUncachedAction : NavigationAction {
253 construct {
254 set ("name", "ReloadUncached",
255 "tooltip", _("Reload page without caching"),
256 "stock-id", Gtk.Stock.REFRESH);
257
258 bind_property ("progress", this, "sensitive", 0,
259 (binding, source, ref target) =>{
260 target = progress == 0.0;
261 return true;
262 });
263 activate.connect (() => { tab.web_view.reload_bypass_cache (); });
264 middle_click_uri.connect (() => { return tab.uri; });
265 }
266 }
267
268 public class ReloadStopAction : NavigationAction {
269 construct {
270 set ("name", "ReloadStop");
271
272 bind_property ("progress", this, "stock-id", 0,
273 (binding, source, ref target) => {
274 target = progress > 0.0 ? Gtk.Stock.STOP : Gtk.Stock.REFRESH;
275 tooltip = progress > 0.0 ? _("Stop loading the current page") : _("Reload the current page");
276 return true;
277 });
278 activate.connect (() => {
279 if (progress > 0.0)
280 tab.web_view.stop_loading ();
281 else {
282 int x, y, state;
283 tab.get_window ().get_pointer (out x, out y, out state);
284 if ((bool)(state & Gdk.ModifierType.SHIFT_MASK))
285 tab.web_view.reload_bypass_cache ();
286 else
287 tab.web_view.reload ();
288 }
289 });
290 middle_click_uri.connect (() => { return tab.uri; });
291 }
292 }
293}
0294
=== modified file 'midori/midori-view.c'
--- midori/midori-view.c 2015-03-23 11:33:24 +0000
+++ midori/midori-view.c 2015-06-07 21:30:55 +0000
@@ -4638,6 +4638,7 @@
4638 * Goes back or forward in history.4638 * Goes back or forward in history.
4639 *4639 *
4640 * Since: 0.4.54640 * Since: 0.4.5
4641 * Deprecated: 0.6.0
4641 **/4642 **/
4642void4643void
4643midori_view_go_back_or_forward (MidoriView* view,4644midori_view_go_back_or_forward (MidoriView* view,
@@ -4722,6 +4723,7 @@
4722 * Return value: an URI, or %NULL4723 * Return value: an URI, or %NULL
4723 *4724 *
4724 * Since: 0.2.34725 * Since: 0.2.3
4726 * Deprecated: 0.6.0
4725 **/4727 **/
4726const gchar*4728const gchar*
4727midori_view_get_previous_page (MidoriView* view)4729midori_view_get_previous_page (MidoriView* view)
@@ -4741,6 +4743,7 @@
4741 * Return value: an URI, or %NULL4743 * Return value: an URI, or %NULL
4742 *4744 *
4743 * Since: 0.2.34745 * Since: 0.2.3
4746 * Deprecated: 0.6.0
4744 **/4747 **/
4745const gchar*4748const gchar*
4746midori_view_get_next_page (MidoriView* view)4749midori_view_get_next_page (MidoriView* view)
47474750
=== modified file 'midori/midori-window.vala'
--- midori/midori-window.vala 2015-06-06 12:20:44 +0000
+++ midori/midori-window.vala 2015-06-07 21:30:55 +0000
@@ -85,9 +85,6 @@
8585
86 Gtk.ToolItem create_tool_item (Gtk.Action action) {86 Gtk.ToolItem create_tool_item (Gtk.Action action) {
87 var toolitem = action.create_tool_item () as Gtk.ToolItem;87 var toolitem = action.create_tool_item () as Gtk.ToolItem;
88 /* Show label if button has no icon of any kind */
89 if (action.icon_name == null && action.stock_id == null && action.gicon == null)
90 toolitem.is_important = true;
91 toolitem.get_child ().button_press_event.connect ((event) => {88 toolitem.get_child ().button_press_event.connect ((event) => {
92 return event.button == 3 && context_menu (toolitem, action); });89 return event.button == 3 && context_menu (toolitem, action); });
93 if (name == "CompactMenu")90 if (name == "CompactMenu")
9491
=== modified file 'po/POTFILES.in'
--- po/POTFILES.in 2015-05-24 00:19:21 +0000
+++ po/POTFILES.in 2015-06-07 21:30:55 +0000
@@ -11,6 +11,7 @@
11midori/midori-database.vala11midori/midori-database.vala
12midori/midori-extension.c12midori/midori-extension.c
13midori/midori-locationaction.c13midori/midori-locationaction.c
14midori/midori-navigationaction.vala
14midori/midori-panel.c15midori/midori-panel.c
15midori/midori-settings.vala16midori/midori-settings.vala
16midori/midori-websettings.c17midori/midori-websettings.c

Subscribers

People subscribed via source and target branches

to all changes: