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

Proposed by Christian 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 Christian Dywan

Merge lp:midori

6951. By Christian Dywan

Remaining NavigationAction subclasses

6952. By Christian Dywan

Coding style fixes

Revision history for this message
Christian 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 Christian 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
Christian 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 Christian Dywan

Related page boilerplate in NavigationAction

6952. By Christian Dywan

Coding style fixes

6951. By Christian Dywan

Remaining NavigationAction subclasses

6950. By Christian Dywan

Merge lp:midori

6949. By Christian 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
1=== modified file 'midori/midori-browser.c'
2--- midori/midori-browser.c 2015-06-03 02:05:28 +0000
3+++ midori/midori-browser.c 2015-06-07 21:30:55 +0000
4@@ -192,12 +192,6 @@
5 GParamSpec* pspec,
6 MidoriBrowser* browser);
7
8-static void
9-midori_browser_toolbar_popup_context_menu_history (MidoriBrowser* browser,
10- GtkWidget* widget,
11- gboolean back,
12- gint x,
13- gint y);
14 void
15 midori_panel_set_toolbar_style (MidoriPanel* panel,
16 GtkToolbarStyle style);
17@@ -292,13 +286,6 @@
18 {
19 GtkAction* action;
20
21- _action_set_sensitive (browser, "Back", midori_view_can_go_back (view));
22- _action_set_sensitive (browser, "Forward", midori_tab_can_go_forward (MIDORI_TAB (view)));
23- _action_set_sensitive (browser, "Previous",
24- midori_view_get_previous_page (view) != NULL);
25- _action_set_sensitive (browser, "Next",
26- midori_view_get_next_page (view) != NULL);
27-
28 _action_set_sensitive (browser, "AddSpeedDial", !midori_view_is_blank (view));
29 _action_set_sensitive (browser, "BookmarkAdd", !midori_view_is_blank (view));
30 _action_set_sensitive (browser, "MailTo", !midori_view_is_blank (view));
31@@ -314,22 +301,6 @@
32 _action_set_sensitive (browser, "SourceViewDom",
33 midori_tab_can_view_source (MIDORI_TAB (view)));
34
35- action = _action_by_name (browser, "NextForward");
36- if (midori_tab_can_go_forward (MIDORI_TAB (view)))
37- {
38- g_object_set (action,
39- "stock-id", GTK_STOCK_GO_FORWARD,
40- "tooltip", _("Go forward to the next page"),
41- "sensitive", TRUE, NULL);
42- }
43- else
44- {
45- g_object_set (action,
46- "stock-id", GTK_STOCK_MEDIA_NEXT,
47- "tooltip", _("Go to the next sub-page"),
48- "sensitive", midori_view_get_next_page (view) != NULL, NULL);
49- }
50-
51 action = _action_by_name (browser, "Location");
52 if (midori_tab_is_blank (MIDORI_TAB (view)))
53 {
54@@ -432,23 +403,6 @@
55 action = _action_by_name (browser, "Location");
56 midori_location_action_set_progress (MIDORI_LOCATION_ACTION (action), progress);
57
58- _action_set_sensitive (browser, "Reload", !loading);
59- _action_set_sensitive (browser, "Stop", loading);
60-
61- action = _action_by_name (browser, "ReloadStop");
62- if (!loading)
63- {
64- g_object_set (action,
65- "stock-id", GTK_STOCK_REFRESH,
66- "tooltip", _("Reload the current page"), NULL);
67- }
68- else
69- {
70- g_object_set (action,
71- "stock-id", GTK_STOCK_STOP,
72- "tooltip", _("Stop loading the current page"), NULL);
73- }
74-
75 g_object_set (browser->throbber, "active", loading, "visible", loading, NULL);
76 }
77
78@@ -734,8 +688,6 @@
79 const gchar* uri = midori_view_get_display_uri (view);
80 GtkAction* action = _action_by_name (browser, "Location");
81 midori_location_action_set_text (MIDORI_LOCATION_ACTION (action), uri);
82- _action_set_sensitive (browser, "Back", midori_view_can_go_back (view));
83- _action_set_sensitive (browser, "Forward", midori_tab_can_go_forward (MIDORI_TAB (view)));
84 g_object_notify (G_OBJECT (browser), "uri");
85 }
86 }
87@@ -2059,53 +2011,6 @@
88 /* Nothing to do */
89 }
90
91-static void
92-_update_tooltip_if_changed (GtkAction* action,
93- const gchar* text)
94-{
95- gchar *old;
96- g_object_get (action, "tooltip", &old, NULL);
97- if (g_strcmp0(old, text)) {
98- g_object_set (action,
99- "tooltip", text, NULL);
100- }
101- g_free (old);
102-}
103-
104-static void
105-_update_reload_tooltip (GtkWidget* widget,
106- GdkEventKey* event,
107- gboolean released)
108-{
109- MidoriBrowser* browser = MIDORI_BROWSER (widget);
110-
111- /* Update the reload/stop tooltip in case we are holding the hard refresh modifiers*/
112- GtkAction *reload_stop = _action_by_name (browser, "ReloadStop");
113- GtkAction *reload = _action_by_name (browser, "Reload");
114- GdkModifierType mask;
115- gdk_window_get_pointer (gtk_widget_get_window (widget), NULL, NULL, &mask);
116- const gchar *target;
117-
118- if ( mask & GDK_SHIFT_MASK)
119- {
120- target = _("Reload page without caching");
121- }
122- else
123- {
124- target = _("Reload the current page");
125- }
126- _update_tooltip_if_changed (reload_stop, target);
127- _update_tooltip_if_changed (reload, target);
128-}
129-
130-static gboolean
131-midori_browser_key_release_event (GtkWidget* widget,
132- GdkEventKey* event)
133-{
134- _update_reload_tooltip (widget, event, TRUE);
135- return GTK_WIDGET_CLASS (midori_browser_parent_class)->key_release_event (widget, event);
136-}
137-
138 static gboolean
139 midori_browser_key_press_event (GtkWidget* widget,
140 GdkEventKey* event)
141@@ -2115,7 +2020,6 @@
142 GtkWidgetClass* widget_class;
143 guint clean_state;
144
145- _update_reload_tooltip(widget, event, FALSE);
146 /* Interpret Ctrl(+Shift)+Tab as tab switching for compatibility */
147 if (midori_browser_get_nth_tab (browser, 1) != NULL
148 && event->keyval == GDK_KEY_Tab
149@@ -2156,18 +2060,15 @@
150 && !webkit_web_view_can_paste_clipboard (WEBKIT_WEB_VIEW (focus)))
151 {
152 /* Space at the bottom of the page: Go to next page */
153- MidoriView* view = midori_view_get_for_widget (focus);
154 GtkScrolledWindow* scrolled = GTK_SCROLLED_WINDOW (gtk_widget_get_parent (focus));
155 GtkAdjustment* vadjust = gtk_scrolled_window_get_vadjustment (scrolled);
156 if (gtk_adjustment_get_value (vadjust)
157 == (gtk_adjustment_get_upper (vadjust) - gtk_adjustment_get_page_size (vadjust)))
158 {
159- /* Duplicate here because the URI pointer might change */
160- gchar* uri = g_strdup (midori_view_get_next_page (view));
161- if (uri != NULL)
162+ GtkAction* next = _action_by_name (browser, "Next");
163+ if (gtk_action_get_sensitive (next))
164 {
165- midori_view_set_uri (view, uri);
166- g_free (uri);
167+ gtk_action_activate (next);
168 return TRUE;
169 }
170 }
171@@ -2441,7 +2342,6 @@
172
173 gtkwidget_class = GTK_WIDGET_CLASS (class);
174 gtkwidget_class->key_press_event = midori_browser_key_press_event;
175- gtkwidget_class->key_release_event = midori_browser_key_release_event;
176
177 gobject_class = G_OBJECT_CLASS (class);
178 gobject_class->dispose = midori_browser_dispose;
179@@ -3515,37 +3415,6 @@
180 }
181
182 static void
183-_action_reload_stop_activate (GtkAction* action,
184- MidoriBrowser* browser)
185-{
186- GtkWidget* view = midori_browser_get_current_tab (browser);
187- gchar* stock_id;
188- g_object_get (action, "stock-id", &stock_id, NULL);
189-
190- /* Refresh or stop, depending on the stock id */
191- if (!strcmp (stock_id, GTK_STOCK_REFRESH))
192- {
193- GdkModifierType state = (GdkModifierType)0;
194- gint x, y;
195- GdkWindow* window;
196- gboolean from_cache = TRUE;
197-
198- if (!strcmp (gtk_action_get_name (action), "ReloadUncached"))
199- from_cache = FALSE;
200- else if ((window = gtk_widget_get_window (GTK_WIDGET (browser))))
201- {
202- gdk_window_get_pointer (window, &x, &y, &state);
203- if (state & GDK_SHIFT_MASK)
204- from_cache = FALSE;
205- }
206- midori_view_reload (MIDORI_VIEW (view), from_cache);
207- }
208- else
209- midori_tab_stop_loading (MIDORI_TAB (view));
210- g_free (stock_id);
211-}
212-
213-static void
214 _action_zoom_activate (GtkAction* action,
215 MidoriBrowser* browser)
216 {
217@@ -3792,129 +3661,6 @@
218 g_free (stylesheet);
219 }
220
221-static gboolean
222-_action_navigation_activate (GtkAction* action,
223- MidoriBrowser* browser)
224-{
225- MidoriView* view;
226- GtkWidget* tab;
227- gchar* uri;
228- const gchar* name;
229- gboolean middle_click;
230-
231- g_assert (GTK_IS_ACTION (action));
232-
233- if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (action),
234- "midori-middle-click")))
235- {
236- middle_click = TRUE;
237- g_object_set_data (G_OBJECT (action),
238- "midori-middle-click",
239- GINT_TO_POINTER(0));
240- }
241- else
242- middle_click = FALSE;
243-
244- tab = midori_browser_get_current_tab (browser);
245- view = MIDORI_VIEW (tab);
246- name = gtk_action_get_name (action);
247-
248- if (!strcmp (name, "NextForward"))
249- name = midori_tab_can_go_forward (MIDORI_TAB (view)) ? "Forward" : "Next";
250-
251- if (g_str_equal (name, "Back"))
252- {
253- if (middle_click)
254- {
255- WebKitWebView* web_view = WEBKIT_WEB_VIEW (midori_view_get_web_view (view));
256- #ifdef HAVE_WEBKIT2
257- WebKitBackForwardList* list = webkit_web_view_get_back_forward_list (web_view);
258- WebKitBackForwardListItem* item = webkit_back_forward_list_get_back_item (list);
259- const gchar* back_uri = webkit_back_forward_list_item_get_uri (item);
260- #else
261- WebKitWebBackForwardList* list = webkit_web_view_get_back_forward_list (web_view);
262- WebKitWebHistoryItem* item = webkit_web_back_forward_list_get_forward_item (list);
263- const gchar* back_uri = webkit_web_history_item_get_uri (item);
264- #endif
265-
266- GtkWidget* new_view = midori_browser_add_uri (browser, back_uri);
267- midori_browser_set_current_tab_smartly (browser, new_view);
268- }
269- else
270- midori_view_go_back (view);
271-
272- return TRUE;
273- }
274- else if (g_str_equal (name, "Forward"))
275- {
276- if (middle_click)
277- {
278- WebKitWebView* web_view = WEBKIT_WEB_VIEW (midori_view_get_web_view (view));
279- #ifdef HAVE_WEBKIT2
280- WebKitBackForwardList* list = webkit_web_view_get_back_forward_list (web_view);
281- WebKitBackForwardListItem* item = webkit_back_forward_list_get_forward_item (list);
282- const gchar* forward_uri = webkit_back_forward_list_item_get_uri (item);
283- #else
284- WebKitWebBackForwardList* list = webkit_web_view_get_back_forward_list (web_view);
285- WebKitWebHistoryItem* item = webkit_web_back_forward_list_get_forward_item (list);
286- const gchar* forward_uri = webkit_web_history_item_get_uri (item);
287- #endif
288-
289- GtkWidget* new_view = midori_browser_add_uri (browser, forward_uri);
290- midori_browser_set_current_tab_smartly (browser, new_view);
291- }
292- else
293- midori_tab_go_forward (MIDORI_TAB (view));
294-
295- return TRUE;
296- }
297- else if (g_str_equal (name, "Previous"))
298- {
299- /* Duplicate here because the URI pointer might change */
300- uri = g_strdup (midori_view_get_previous_page (view));
301-
302- if (middle_click)
303- {
304- GtkWidget* new_view = midori_browser_add_uri (browser, uri);
305- midori_browser_set_current_tab_smartly (browser, new_view);
306- }
307- else
308- midori_view_set_uri (view, uri);
309-
310- g_free (uri);
311- return TRUE;
312- }
313- else if (g_str_equal (name, "Next"))
314- {
315- /* Duplicate here because the URI pointer might change */
316- uri = g_strdup (midori_view_get_next_page (view));
317-
318- if (middle_click)
319- {
320- GtkWidget* new_view = midori_browser_add_uri (browser, uri);
321- midori_browser_set_current_tab_smartly (browser, new_view);
322- }
323- else
324- midori_view_set_uri (view, uri);
325-
326- g_free (uri);
327- return TRUE;
328- }
329- else if (g_str_equal (name, "Homepage"))
330- {
331- if (middle_click)
332- {
333- GtkWidget* new_view = midori_browser_add_uri (browser, "about:home");
334- midori_browser_set_current_tab_smartly (browser, new_view);
335- }
336- else
337- midori_view_set_uri (view, "about:home");
338-
339- return TRUE;
340- }
341- return FALSE;
342-}
343-
344 static void
345 _action_location_activate (GtkAction* action,
346 MidoriBrowser* browser)
347@@ -4352,17 +4098,6 @@
348 GtkAction* action,
349 MidoriBrowser* browser)
350 {
351- const gchar* name = gtk_action_get_name (action);
352- gboolean back = !g_strcmp0 (name, "Back");
353- if (back
354- || g_str_has_suffix (name, "Forward"))
355- {
356- midori_browser_toolbar_popup_context_menu_history (
357- browser,
358- widget,
359- back, 0, 0);
360- return TRUE;
361- }
362 return midori_browser_toolbar_popup_context_menu_cb (widget, 0, 0, 0, browser);
363 }
364
365@@ -4455,23 +4190,6 @@
366 return FALSE;
367 }
368
369-static gboolean
370-midori_browser_menu_item_middle_click_event_cb (GtkWidget* toolitem,
371- GdkEventButton* event,
372- MidoriBrowser* browser)
373-{
374- if (MIDORI_EVENT_NEW_TAB (event))
375- {
376- GtkAction* action;
377-
378- action = gtk_activatable_get_related_action (GTK_ACTIVATABLE (toolitem));
379- g_object_set_data (G_OBJECT (action), "midori-middle-click", GINT_TO_POINTER (1));
380-
381- return _action_navigation_activate (action, browser);
382- }
383- return FALSE;
384-}
385-
386 static void
387 _action_bookmark_add_activate (GtkAction* action,
388 MidoriBrowser* browser)
389@@ -5305,18 +5023,6 @@
390
391 { "View", NULL, N_("_View") },
392 { "Toolbars", NULL, N_("_Toolbars") },
393- { "Reload", GTK_STOCK_REFRESH,
394- NULL, "<Ctrl>r",
395- N_("Reload the current page"), G_CALLBACK (_action_reload_stop_activate) },
396- { "ReloadUncached", GTK_STOCK_REFRESH,
397- N_("Reload page without caching"), "<Ctrl><Shift>r",
398- NULL, G_CALLBACK (_action_reload_stop_activate) },
399- { "Stop", GTK_STOCK_STOP,
400- NULL, "Escape",
401- N_("Stop loading the current page"), G_CALLBACK (_action_reload_stop_activate) },
402- { "ReloadStop", GTK_STOCK_STOP,
403- NULL, "",
404- N_("Reload the current page"), G_CALLBACK (_action_reload_stop_activate) },
405 { "ZoomIn", GTK_STOCK_ZOOM_IN,
406 NULL, "<Ctrl>plus",
407 N_("Increase the zoom level"), G_CALLBACK (_action_zoom_activate) },
408@@ -5356,26 +5062,6 @@
409 NULL, G_CALLBACK (_action_readable_activate) },
410
411 { "Go", NULL, N_("_Go") },
412- { "Back", GTK_STOCK_GO_BACK,
413- NULL, "<Alt>Left",
414- N_("Go back to the previous page"), G_CALLBACK (_action_navigation_activate) },
415- { "Forward", GTK_STOCK_GO_FORWARD,
416- NULL, "<Alt>Right",
417- N_("Go forward to the next page"), G_CALLBACK (_action_navigation_activate) },
418- { "Previous", GTK_STOCK_MEDIA_PREVIOUS,
419- NULL, "<Alt><Shift>Left",
420- /* i18n: Visit the previous logical page, ie. in a forum or blog */
421- N_("Go to the previous sub-page"), G_CALLBACK (_action_navigation_activate) },
422- { "Next", GTK_STOCK_MEDIA_NEXT,
423- NULL, "<Alt><Shift>Right",
424- /* i18n: Visit the following logical page, ie. in a forum or blog */
425- N_("Go to the next sub-page"), G_CALLBACK (_action_navigation_activate) },
426- { "NextForward", GTK_STOCK_MEDIA_NEXT,
427- N_("Next or Forward"), "",
428- N_("Go to the next sub-page or next page in history"), G_CALLBACK (_action_navigation_activate) },
429- { "Homepage", GTK_STOCK_HOME,
430- N_("_Homepage"), "<Alt>Home",
431- N_("Go to your homepage"), G_CALLBACK (_action_navigation_activate) },
432 { "TrashEmpty", GTK_STOCK_CLEAR,
433 N_("Empty Trash"), "",
434 NULL, G_CALLBACK (_action_trash_empty_activate) },
435@@ -5914,6 +5600,20 @@
436 return FALSE;
437 }
438
439+static GtkAction*
440+midori_browser_add_action (MidoriBrowser* browser,
441+ GType type,
442+ const gchar* accelerator)
443+{
444+ GtkAction* action = g_object_new (type, NULL);
445+ g_return_val_if_fail (gtk_action_get_name (action) != NULL, action);
446+ gtk_action_group_add_action_with_accel (browser->action_group, action, accelerator);
447+ if (MIDORI_IS_NAVIGATION_ACTION (action))
448+ g_object_bind_property (browser, "tab", action, "tab", 0);
449+ g_object_unref (action);
450+ return action;
451+}
452+
453 static void
454 midori_browser_init (MidoriBrowser* browser)
455 {
456@@ -5925,9 +5625,6 @@
457 GError* error;
458 GtkAction* action;
459 GtkWidget* menuitem;
460- GtkWidget* homepage;
461- GtkWidget* back;
462- GtkWidget* forward;
463 GtkWidget* hpaned;
464 GtkWidget* vpaned;
465 GtkWidget* scrolled;
466@@ -5995,6 +5692,17 @@
467 /* Hide the 'Dummy' which only holds otherwise unused actions */
468 _action_set_visible (browser, "Dummy", FALSE);
469
470+ midori_browser_add_action (browser, MIDORI_TYPE_BACK_ACTION, "<Alt>Left");
471+ midori_browser_add_action (browser, MIDORI_TYPE_PREVIOUS_ACTION, "<Alt><Shift>Left");
472+ midori_browser_add_action (browser, MIDORI_TYPE_FORWARD_ACTION, "<Alt>Right");
473+ midori_browser_add_action (browser, MIDORI_TYPE_NEXT_ACTION, "<Alt><Shift>Right");
474+ midori_browser_add_action (browser, MIDORI_TYPE_NEXT_FORWARD_ACTION, "");
475+ midori_browser_add_action (browser, MIDORI_TYPE_HOMEPAGE_ACTION, "<Alt>Home");
476+ midori_browser_add_action (browser, MIDORI_TYPE_STOP_ACTION, "Escape");
477+ midori_browser_add_action (browser, MIDORI_TYPE_RELOAD_ACTION, "<Ctrl>r");
478+ midori_browser_add_action (browser, MIDORI_TYPE_RELOAD_UNCACHED_ACTION, "<Ctrl><Shift>r");
479+ midori_browser_add_action (browser, MIDORI_TYPE_RELOAD_STOP_ACTION, "");
480+
481 action = g_object_new (KATZE_TYPE_SEPARATOR_ACTION,
482 "name", "Separator",
483 "label", _("_Separator"),
484@@ -6049,11 +5757,7 @@
485 action, "<Ctrl>K");
486 g_object_unref (action);
487
488- action = g_object_new (MIDORI_TYPE_PANED_ACTION,
489- "name", "LocationSearch",
490- NULL);
491- gtk_action_group_add_action (browser->action_group, action);
492- g_object_unref (action);
493+ midori_browser_add_action (browser, MIDORI_TYPE_PANED_ACTION, "");
494
495 action = g_object_new (KATZE_TYPE_ARRAY_ACTION,
496 "name", "Trash",
497@@ -6178,22 +5882,6 @@
498 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (
499 gtk_ui_manager_get_widget (ui_manager, "/menubar/Go/Location")), NULL);
500
501- homepage = gtk_ui_manager_get_widget (ui_manager, "/menubar/Go/Homepage");
502- g_signal_connect (homepage, "button-press-event",
503- G_CALLBACK (midori_browser_menu_item_middle_click_event_cb), browser);
504- back = gtk_ui_manager_get_widget (ui_manager, "/menubar/Go/Back");
505- g_signal_connect (back, "button-press-event",
506- G_CALLBACK (midori_browser_menu_item_middle_click_event_cb), browser);
507- forward = gtk_ui_manager_get_widget (ui_manager, "/menubar/Go/Forward");
508- g_signal_connect (forward, "button-press-event",
509- G_CALLBACK (midori_browser_menu_item_middle_click_event_cb), browser);
510- forward = gtk_ui_manager_get_widget (ui_manager, "/menubar/Go/Previous");
511- g_signal_connect (forward, "button-press-event",
512- G_CALLBACK (midori_browser_menu_item_middle_click_event_cb), browser);
513- forward = gtk_ui_manager_get_widget (ui_manager, "/menubar/Go/Next");
514- g_signal_connect (forward, "button-press-event",
515- G_CALLBACK (midori_browser_menu_item_middle_click_event_cb), browser);
516-
517 _action_set_sensitive (browser, "EncodingCustom", FALSE);
518 _action_set_visible (browser, "LastSession", FALSE);
519
520@@ -6376,81 +6064,6 @@
521 gtk_toolbar_style);
522 }
523
524-#ifndef HAVE_WEBKIT2
525-static void
526-midori_browser_toolbar_popup_context_menu_history_cb (GtkMenuItem* menu_item,
527- MidoriBrowser* browser)
528-{
529- gint steps = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (menu_item), "steps"));
530- MidoriView* view = MIDORI_VIEW (midori_browser_get_current_tab (browser));
531- midori_view_go_back_or_forward (view, steps);
532-}
533-#endif
534-
535-static void
536-midori_browser_toolbar_popup_context_menu_history (MidoriBrowser* browser,
537- GtkWidget* widget,
538- gboolean back,
539- gint x,
540- gint y)
541-{
542-#ifndef HAVE_WEBKIT2
543- const gint step = back ? -1 : 1;
544- gint steps = step;
545- GtkWidget* menu;
546- WebKitWebBackForwardList* list;
547- WebKitWebHistoryItem* current_item;
548- WebKitWebHistoryItem* history_item;
549- WebKitWebHistoryItem* (*history_next)(WebKitWebBackForwardList*);
550- void (*history_action)(WebKitWebBackForwardList*);
551-
552- list = webkit_web_view_get_back_forward_list (
553- WEBKIT_WEB_VIEW (midori_view_get_web_view (
554- MIDORI_VIEW (midori_browser_get_current_tab (browser)))));
555-
556- if (!list)
557- return;
558-
559- menu = gtk_menu_new ();
560-
561- history_action = back ?
562- webkit_web_back_forward_list_go_back :
563- webkit_web_back_forward_list_go_forward;
564- history_next = back ?
565- webkit_web_back_forward_list_get_back_item :
566- webkit_web_back_forward_list_get_forward_item;
567- current_item = webkit_web_back_forward_list_get_current_item (list);
568-
569- for (; (history_item = history_next (list)); history_action (list), steps += step)
570- {
571- const gchar* uri = webkit_web_history_item_get_uri (history_item);
572- GtkWidget* menu_item = gtk_image_menu_item_new_with_label (
573- webkit_web_history_item_get_title (history_item));
574- GdkPixbuf* pixbuf;
575- if ((pixbuf = midori_paths_get_icon (uri, widget)))
576- {
577- gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item),
578- gtk_image_new_from_pixbuf (pixbuf));
579- g_object_unref (pixbuf);
580- }
581- g_object_set_data (G_OBJECT (menu_item), "uri", (gpointer)uri);
582- g_object_set_data (G_OBJECT (menu_item), "steps", GINT_TO_POINTER (steps));
583- gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
584- g_signal_connect (G_OBJECT (menu_item), "activate",
585- G_CALLBACK (midori_browser_toolbar_popup_context_menu_history_cb),
586- browser);
587- if (steps == (10 - 1))
588- break;
589- }
590-
591- webkit_web_back_forward_list_go_to_item (list, current_item);
592- gtk_widget_show_all (menu);
593-
594- katze_widget_popup (widget, GTK_MENU (menu), NULL,
595- KATZE_MENU_POSITION_LEFT);
596-#endif
597-}
598-
599 static void
600 _midori_browser_update_settings (MidoriBrowser* browser)
601 {
602
603=== added file 'midori/midori-navigationaction.vala'
604--- midori/midori-navigationaction.vala 1970-01-01 00:00:00 +0000
605+++ midori/midori-navigationaction.vala 2015-06-07 21:30:55 +0000
606@@ -0,0 +1,293 @@
607+/*
608+ Copyright (C) 2015 Christian Dywan <christian@twotoasts.de>
609+
610+ This library is free software; you can redistribute it and/or
611+ modify it under the terms of the GNU Lesser General Public
612+ License as published by the Free Software Foundation; either
613+ version 2.1 of the License, or (at your option) any later version.
614+
615+ See the file COPYING for the full license text.
616+*/
617+
618+namespace Midori {
619+ /* Back or forward action, with a submenu
620+ Since: 0.6.0 */
621+ protected abstract class NavigationAction : Gtk.Action {
622+ protected string uri { get; set; }
623+ protected double progress { get; set; }
624+
625+ public Midori.Tab? tab { get; set; }
626+ public signal string? middle_click_uri ();
627+ public signal Gtk.Menu? context_menu ();
628+
629+ Gtk.ToolButton? toolitem;
630+ public override unowned Gtk.Widget create_tool_item () {
631+ toolitem = new Gtk.ToolButton (null, null);
632+ toolitem.icon_widget = create_icon (Gtk.IconSize.LARGE_TOOLBAR);
633+ bind_property ("label", toolitem, "label");
634+ bind_property ("tooltip", toolitem, "tooltip-text");
635+ bind_property ("is-important", toolitem, "is-important");
636+ // Connect to child because ToolItem blocks button-press-event
637+ toolitem.get_child ().button_press_event.connect ((event) => {
638+ // Ctrl+click or middle click
639+ string? uri = event.button == 2
640+ || (event.button == 1 && (bool)(event.state & Gdk.ModifierType.CONTROL_MASK))
641+ ? middle_click_uri () : null;
642+ if (uri != null) {
643+ Midori.Settings? settings = null;
644+ /* Midori.View.settings */
645+ tab.get ("settings", ref settings);
646+ GLib.Signal.emit_by_name (tab, "new-tab", uri, settings.open_tabs_in_the_background);
647+ return true;
648+ }
649+ Gtk.Menu? menu = event.button == 3 ? context_menu () : null;
650+ if (menu != null) {
651+ menu.show ();
652+ menu.attach_to_widget (toolitem, null);
653+ menu.popup (null, null, null, 1, Gtk.get_current_event_time ());
654+ return true;
655+ }
656+ return false;
657+ });
658+ return toolitem;
659+ }
660+
661+ construct {
662+ notify["tab"].connect (tab_changed);
663+ }
664+
665+ void tab_changed (ParamSpec pspec) {
666+ tab.bind_property ("uri", this, "uri", 0);
667+ tab.bind_property ("progress", this, "progress", 0);
668+ }
669+
670+ string? related_page (string rel, string local) {
671+#if HAVE_WEBKIT2
672+ return null;
673+#else
674+ return null;
675+#endif
676+ }
677+
678+ string next_page () {
679+ /* i18n: word stem of "next page" type links, case is not important */
680+ return related_page ("next", _("next"));
681+ }
682+
683+ string previous_page () {
684+ /* i18n: word stem of "previous page" type links, case is not important */
685+ return related_page ("prev", _("previous"));
686+ }
687+
688+ protected bool can_go_next () {
689+ return next_page () != null;
690+ }
691+
692+ protected void go_next () {
693+ tab.web_view.load_uri (next_page ());
694+ }
695+
696+ protected void go_next_or_forward () {
697+ if (tab.web_view.can_go_forward ())
698+ tab.web_view.go_forward ();
699+ else
700+ go_next ();
701+ }
702+
703+ protected bool can_go_previous () {
704+ return previous_page () != null;
705+ }
706+
707+ protected void go_previous () {
708+ tab.web_view.load_uri (previous_page ());
709+ }
710+
711+ GLib.Icon? scale_if_needed (GLib.Icon? icon) {
712+ if (icon is Gdk.Pixbuf) {
713+ var pixbuf = icon as Gdk.Pixbuf;
714+ int icon_width = 16, icon_height = 16;
715+ Gtk.icon_size_lookup (Gtk.IconSize.MENU, out icon_width, out icon_height);
716+ if (pixbuf.width > icon_width || pixbuf.height > icon_height)
717+ return pixbuf.scale_simple (icon_width, icon_height, Gdk.InterpType.BILINEAR);
718+ }
719+ return icon;
720+ }
721+
722+#if HAVE_WEBKIT2
723+ protected Gtk.Menu? build_menu (List<weak WebKit.BackForwardListItem> items) {
724+#else
725+ protected Gtk.Menu? build_menu (List<weak WebKit.WebHistoryItem> items) {
726+#endif
727+ var menu = new Gtk.Menu ();
728+ foreach (var item in items) {
729+ var menuitem = new Gtk.ImageMenuItem.with_label (item.get_title ());
730+ var icon = new Midori.URI.Icon (item.get_uri ());
731+ menuitem.image = new Gtk.Image.from_gicon (scale_if_needed (icon), Gtk.IconSize.MENU);
732+ menuitem.always_show_image = true;
733+ menuitem.show_all ();
734+ menuitem.activate.connect (() =>{ tab.web_view.load_uri (item.get_uri ()); });
735+ menu.append (menuitem);
736+ }
737+ return menu;
738+ }
739+ }
740+
741+ public class BackAction : NavigationAction {
742+ construct {
743+ set ("name", "Back",
744+ "tooltip", _("Go back to the previous page"),
745+ "stock-id", Gtk.Stock.GO_BACK,
746+ "is-important", true);
747+
748+ bind_property ("uri", this, "sensitive", 0,
749+ (binding, source, ref target) => { target = tab.web_view.can_go_back (); return true; });
750+ activate.connect (() => { tab.web_view.go_back (); });
751+ middle_click_uri.connect (() => { return tab.web_view.get_back_forward_list ().get_back_item ().get_uri (); });
752+ context_menu.connect (() => { return build_menu (tab.web_view.get_back_forward_list ().get_back_list_with_limit (10)); });
753+ }
754+ }
755+
756+ public class PreviousAction : NavigationAction {
757+ construct {
758+ set ("name", "Previous",
759+ /* i18n: Visit the previous logical page, ie. in a forum or blog */
760+ "tooltip", _("Go to the previous sub-page"),
761+ "stock-id", Gtk.Stock.MEDIA_PREVIOUS);
762+
763+ bind_property ("uri", this, "sensitive", 0,
764+ (binding, source, ref target) => { target = can_go_previous (); return true; });
765+ activate.connect (() => { go_previous (); });
766+ context_menu.connect (() => { return build_menu (tab.web_view.get_back_forward_list ().get_back_list_with_limit (10)); });
767+ }
768+ }
769+
770+ public class ForwardAction : NavigationAction {
771+ construct {
772+ set ("name", "Forward",
773+ "tooltip", _("Go forward to the next page"),
774+ "stock-id", Gtk.Stock.GO_FORWARD);
775+
776+ bind_property ("uri", this, "sensitive", 0,
777+ (binding, source, ref target) => { target = tab.web_view.can_go_forward (); return true; });
778+ activate.connect (() => { tab.web_view.go_forward (); });
779+ middle_click_uri.connect (() => { return tab.web_view.get_back_forward_list ().get_forward_item ().get_uri (); });
780+ context_menu.connect (() => { return build_menu (tab.web_view.get_back_forward_list ().get_forward_list_with_limit (10)); });
781+ }
782+ }
783+
784+ public class NextAction : NavigationAction {
785+ construct {
786+ set ("name", "Next",
787+ /* i18n: Visit the following logical page, ie. in a forum or blog */
788+ "tooltip", _("Go to the next sub-page"),
789+ "stock-id", Gtk.Stock.MEDIA_NEXT);
790+
791+ bind_property ("uri", this, "sensitive", 0,
792+ (binding, source, ref target) => { target = can_go_next (); return true; });
793+ activate.connect (() => { go_next (); });
794+ context_menu.connect (() => { return build_menu (tab.web_view.get_back_forward_list ().get_forward_list_with_limit (10)); });
795+ }
796+ }
797+
798+ public class NextForwardAction : NavigationAction {
799+ construct {
800+ set ("name", "NextForward",
801+ "label", _("Next or Forward"));
802+
803+ bind_property ("uri", this, "sensitive", 0,
804+ (binding, source, ref target) => {
805+ target = (tab.web_view.can_go_forward () || can_go_next ());
806+ stock_id = (can_go_next () ? Gtk.Stock.GO_FORWARD : Gtk.Stock.MEDIA_NEXT);
807+ tooltip = (can_go_next () ? _("Go forward to the next page") : _("Go to the next sub-page"));
808+ return true;
809+ });
810+ activate.connect (() => { go_next_or_forward (); });
811+ context_menu.connect (() => { return build_menu (tab.web_view.get_back_forward_list ().get_forward_list_with_limit (10)); });
812+ }
813+ }
814+
815+ public class HomepageAction : NavigationAction {
816+ construct {
817+ set ("name", "Homepage",
818+ "label", _("_Homepage"),
819+ "tooltip", _("Go to your homepage"),
820+ "stock-id", Gtk.Stock.HOME);
821+
822+ activate.connect (() => { tab.web_view.load_uri ("about:home"); });
823+ middle_click_uri.connect (() => { return "about:home"; });
824+ }
825+ }
826+
827+ public class StopAction : NavigationAction {
828+ construct {
829+ set ("name", "Stop",
830+ "tooltip",_("Stop loading the current page"),
831+ "stock-id", Gtk.Stock.STOP);
832+
833+ bind_property ("progress", this, "sensitive", 0,
834+ (binding, source, ref target) =>{
835+ target = progress > 0.0;
836+ return true;
837+ });
838+ activate.connect (() => { tab.web_view.stop_loading (); });
839+ }
840+ }
841+
842+ public class ReloadAction : NavigationAction {
843+ construct {
844+ set ("name", "Reload",
845+ "tooltip", _("Reload the current page"),
846+ "stock-id", Gtk.Stock.REFRESH);
847+
848+ bind_property ("progress", this, "sensitive", 0,
849+ (binding, source, ref target) =>{
850+ target = progress == 0.0;
851+ return true;
852+ });
853+ activate.connect (() => { tab.web_view.reload (); });
854+ middle_click_uri.connect (() => { return tab.uri; });
855+ }
856+ }
857+
858+ public class ReloadUncachedAction : NavigationAction {
859+ construct {
860+ set ("name", "ReloadUncached",
861+ "tooltip", _("Reload page without caching"),
862+ "stock-id", Gtk.Stock.REFRESH);
863+
864+ bind_property ("progress", this, "sensitive", 0,
865+ (binding, source, ref target) =>{
866+ target = progress == 0.0;
867+ return true;
868+ });
869+ activate.connect (() => { tab.web_view.reload_bypass_cache (); });
870+ middle_click_uri.connect (() => { return tab.uri; });
871+ }
872+ }
873+
874+ public class ReloadStopAction : NavigationAction {
875+ construct {
876+ set ("name", "ReloadStop");
877+
878+ bind_property ("progress", this, "stock-id", 0,
879+ (binding, source, ref target) => {
880+ target = progress > 0.0 ? Gtk.Stock.STOP : Gtk.Stock.REFRESH;
881+ tooltip = progress > 0.0 ? _("Stop loading the current page") : _("Reload the current page");
882+ return true;
883+ });
884+ activate.connect (() => {
885+ if (progress > 0.0)
886+ tab.web_view.stop_loading ();
887+ else {
888+ int x, y, state;
889+ tab.get_window ().get_pointer (out x, out y, out state);
890+ if ((bool)(state & Gdk.ModifierType.SHIFT_MASK))
891+ tab.web_view.reload_bypass_cache ();
892+ else
893+ tab.web_view.reload ();
894+ }
895+ });
896+ middle_click_uri.connect (() => { return tab.uri; });
897+ }
898+ }
899+}
900
901=== modified file 'midori/midori-view.c'
902--- midori/midori-view.c 2015-03-23 11:33:24 +0000
903+++ midori/midori-view.c 2015-06-07 21:30:55 +0000
904@@ -4638,6 +4638,7 @@
905 * Goes back or forward in history.
906 *
907 * Since: 0.4.5
908+ * Deprecated: 0.6.0
909 **/
910 void
911 midori_view_go_back_or_forward (MidoriView* view,
912@@ -4722,6 +4723,7 @@
913 * Return value: an URI, or %NULL
914 *
915 * Since: 0.2.3
916+ * Deprecated: 0.6.0
917 **/
918 const gchar*
919 midori_view_get_previous_page (MidoriView* view)
920@@ -4741,6 +4743,7 @@
921 * Return value: an URI, or %NULL
922 *
923 * Since: 0.2.3
924+ * Deprecated: 0.6.0
925 **/
926 const gchar*
927 midori_view_get_next_page (MidoriView* view)
928
929=== modified file 'midori/midori-window.vala'
930--- midori/midori-window.vala 2015-06-06 12:20:44 +0000
931+++ midori/midori-window.vala 2015-06-07 21:30:55 +0000
932@@ -85,9 +85,6 @@
933
934 Gtk.ToolItem create_tool_item (Gtk.Action action) {
935 var toolitem = action.create_tool_item () as Gtk.ToolItem;
936- /* Show label if button has no icon of any kind */
937- if (action.icon_name == null && action.stock_id == null && action.gicon == null)
938- toolitem.is_important = true;
939 toolitem.get_child ().button_press_event.connect ((event) => {
940 return event.button == 3 && context_menu (toolitem, action); });
941 if (name == "CompactMenu")
942
943=== modified file 'po/POTFILES.in'
944--- po/POTFILES.in 2015-05-24 00:19:21 +0000
945+++ po/POTFILES.in 2015-06-07 21:30:55 +0000
946@@ -11,6 +11,7 @@
947 midori/midori-database.vala
948 midori/midori-extension.c
949 midori/midori-locationaction.c
950+midori/midori-navigationaction.vala
951 midori/midori-panel.c
952 midori/midori-settings.vala
953 midori/midori-websettings.c

Subscribers

People subscribed via source and target branches

to all changes: