Merge lp:~midori/midori/contextActionEscaped into lp:midori

Proposed by Cris Dywan
Status: Merged
Approved by: gue5t gue5t
Approved revision: 6585
Merged at revision: 6590
Proposed branch: lp:~midori/midori/contextActionEscaped
Merge into: lp:midori
Diff against target: 135 lines (+68/-16)
4 files modified
midori/midori-contextaction.vala (+13/-0)
midori/midori-notebook.vala (+20/-14)
midori/midori-view.c (+2/-2)
tests/notebook.vala (+33/-0)
To merge this branch: bzr merge lp:~midori/midori/contextActionEscaped
Reviewer Review Type Date Requested Status
gue5t gue5t Approve
Review via email: mp+209160@code.launchpad.net

Commit message

Implement and use ContextAction.escaped

To post a comment you must log in.
Revision history for this message
gue5t gue5t (gue5t) wrote :

This *removes* underscores, but it should duplicate underscores instead. With this patch, instead of the desired "foo_bar.com" appearing when right-clicking the empty space next to notebook tabs, "foobar.com" is shown (the old behavior is "foo<u>b</u>ar.com", if you mentally interpret the markup).

This patch is a lot simpler than what I had, which is a plus!

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

Damn me, I've mixed it up before, I'll think of a simple unit test so we know it actually does what it's meant to.

Revision history for this message
gue5t gue5t (gue5t) wrote :

Looks good now!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'midori/midori-contextaction.vala'
--- midori/midori-contextaction.vala 2013-08-02 23:45:16 +0000
+++ midori/midori-contextaction.vala 2014-03-06 23:52:22 +0000
@@ -22,6 +22,19 @@
22 children = new List<ContextAction> ();22 children = new List<ContextAction> ();
23 }23 }
2424
25 /*
26 The action label will be escaped for mnemonics so for example
27 "a_fairy_tale" will not get accel keys on "f" or "t".
28
29 Since: 0.5.8
30 */
31 public ContextAction.escaped (string name, string label, string? tooltip, string? stock_id) {
32 string? escaped_label = label.replace ("_", "__");
33 GLib.Object (name: name, label: escaped_label, tooltip: tooltip, stock_id: stock_id);
34 action_groups = new List<Gtk.ActionGroup> ();
35 children = new List<ContextAction> ();
36 }
37
25 public delegate void ActionActivateCallback (Gtk.Action action);38 public delegate void ActionActivateCallback (Gtk.Action action);
26 public void add_simple (string name, string? label, string? tooltip, string? stock_id, ActionActivateCallback callback) {39 public void add_simple (string name, string? label, string? tooltip, string? stock_id, ActionActivateCallback callback) {
27 var action = new ContextAction (name, label, tooltip, stock_id);40 var action = new ContextAction (name, label, tooltip, stock_id);
2841
=== modified file 'midori/midori-notebook.vala'
--- midori/midori-notebook.vala 2014-03-03 22:49:56 +0000
+++ midori/midori-notebook.vala 2014-03-06 23:52:22 +0000
@@ -260,6 +260,25 @@
260 notebook.create_window.disconnect (window_created);260 notebook.create_window.disconnect (window_created);
261 }261 }
262262
263 /* Since: 0.5.8 */
264 public ContextAction get_context_action () {
265 var menu = new Midori.ContextAction ("NotebookContextMenu", null, null, null);
266 uint counter = 0;
267 foreach (var child in notebook.get_children ()) {
268 var tab = child as Midori.Tab;
269 var tally = notebook.get_tab_label (tab) as Tally;
270 var action = new Midori.ContextAction.escaped ("Tab%u".printf (counter), tally.label.label, null, null);
271 action.gicon = tally.icon.gicon;
272 action.activate.connect (()=>{
273 notebook.set_current_page (notebook.page_num (tab));
274 });
275 menu.add (action);
276 counter++;
277 }
278 context_menu (menu);
279 return menu;
280 }
281
263 bool button_pressed (Gdk.EventButton event) {282 bool button_pressed (Gdk.EventButton event) {
264 /* Propagate events in logical label area */283 /* Propagate events in logical label area */
265 foreach (var child in notebook.get_children ()) {284 foreach (var child in notebook.get_children ()) {
@@ -280,20 +299,7 @@
280 return true;299 return true;
281 }300 }
282 else if (event.button == 3) {301 else if (event.button == 3) {
283 var menu = new Midori.ContextAction ("NotebookContextMenu", null, null, null);302 var menu = get_context_action ();
284 uint counter = 0;
285 foreach (var child in notebook.get_children ()) {
286 var tab = child as Midori.Tab;
287 var tally = notebook.get_tab_label (tab) as Tally;
288 var action = new Gtk.Action ("Tab%u".printf (counter), tally.label.label, null, null);
289 action.gicon = tally.icon.gicon;
290 action.activate.connect (()=>{
291 notebook.set_current_page (notebook.page_num (tab));
292 });
293 menu.add (action);
294 counter++;
295 }
296 context_menu (menu);
297 var popup = menu.create_menu (null, false);303 var popup = menu.create_menu (null, false);
298 popup.show ();304 popup.show ();
299 popup.attach_to_widget (this, null);305 popup.attach_to_widget (this, null);
300306
=== modified file 'midori/midori-view.c'
--- midori/midori-view.c 2014-03-03 22:49:56 +0000
+++ midori/midori-view.c 2014-03-06 23:52:22 +0000
@@ -2370,7 +2370,7 @@
2370 && strstr (view->selected_text, "://") == NULL))2370 && strstr (view->selected_text, "://") == NULL))
2371 {2371 {
2372 gchar* text = g_strdup_printf (_("Send a message to %s"), view->selected_text);2372 gchar* text = g_strdup_printf (_("Send a message to %s"), view->selected_text);
2373 GtkAction* action = gtk_action_new ("SendMessage", text, NULL, GTK_STOCK_JUMP_TO);2373 GtkAction* action = (GtkAction*)midori_context_action_new_escaped ("SendMessage", text, NULL, GTK_STOCK_JUMP_TO);
2374 g_object_set_data_full (G_OBJECT (action), "uri", g_strdup (view->selected_text), (GDestroyNotify)g_free);2374 g_object_set_data_full (G_OBJECT (action), "uri", g_strdup (view->selected_text), (GDestroyNotify)g_free);
2375 g_signal_connect (action, "activate", G_CALLBACK (midori_view_menu_open_email_activate_cb), view);2375 g_signal_connect (action, "activate", G_CALLBACK (midori_view_menu_open_email_activate_cb), view);
2376 midori_context_action_add (menu, action);2376 midori_context_action_add (menu, action);
@@ -2397,7 +2397,7 @@
2397 {2397 {
2398 GdkPixbuf* pixbuf;2398 GdkPixbuf* pixbuf;
2399 gchar* search_option = g_strdup_printf ("SearchWith%u", i);2399 gchar* search_option = g_strdup_printf ("SearchWith%u", i);
2400 GtkAction* action = gtk_action_new (search_option, katze_item_get_name (item), NULL, STOCK_EDIT_FIND);2400 GtkAction* action = (GtkAction*)midori_context_action_new_escaped (search_option, katze_item_get_name (item), NULL, STOCK_EDIT_FIND);
2401 g_free (search_option);2401 g_free (search_option);
2402 midori_context_action_add (searches, action);2402 midori_context_action_add (searches, action);
2403 if ((pixbuf = katze_item_get_pixbuf (item, view->web_view)))2403 if ((pixbuf = katze_item_get_pixbuf (item, view->web_view)))
24042404
=== added file 'tests/notebook.vala'
--- tests/notebook.vala 1970-01-01 00:00:00 +0000
+++ tests/notebook.vala 2014-03-06 23:52:22 +0000
@@ -0,0 +1,33 @@
1/*
2 Copyright (C) 2014 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
12void notebook_menu () {
13 var notebook = new Midori.Notebook ();
14 /* FIXME: we should just use a Tab but currently it has no title property */
15 var tab = new Midori.View.with_title ("a_fairy_tale", new Midori.WebSettings ());
16 /*var tab = new Midori.View.with_title (null, new Midori.WebSettings ());
17 view.set_html ("<title>a_fairy_tale</title><body>The earth is <em>flat</em> for a fact.</body>");
18 var loop = MainContext.default ();
19 do { loop.iteration (true); } while (view.load_status != Midori.LoadStatus.FINISHED);*/
20 notebook.insert (tab, 0);
21 var menu = notebook.get_context_action ();
22 var tab_menu = menu.get_by_name ("Tab0");
23 assert (tab_menu != null);
24 /* The underscores should be escaped */
25 Katze.assert_str_equal ("Tab0", tab_menu.label, "‪a__fairy__tale");
26}
27
28void main (string[] args) {
29 Test.init (ref args);
30 Midori.App.setup (ref args, null);
31 Test.add_func ("/notebook/menu", notebook_menu);
32 Test.run ();
33}

Subscribers

People subscribed via source and target branches

to all changes: