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
1=== modified file 'midori/midori-contextaction.vala'
2--- midori/midori-contextaction.vala 2013-08-02 23:45:16 +0000
3+++ midori/midori-contextaction.vala 2014-03-06 23:52:22 +0000
4@@ -22,6 +22,19 @@
5 children = new List<ContextAction> ();
6 }
7
8+ /*
9+ The action label will be escaped for mnemonics so for example
10+ "a_fairy_tale" will not get accel keys on "f" or "t".
11+
12+ Since: 0.5.8
13+ */
14+ public ContextAction.escaped (string name, string label, string? tooltip, string? stock_id) {
15+ string? escaped_label = label.replace ("_", "__");
16+ GLib.Object (name: name, label: escaped_label, tooltip: tooltip, stock_id: stock_id);
17+ action_groups = new List<Gtk.ActionGroup> ();
18+ children = new List<ContextAction> ();
19+ }
20+
21 public delegate void ActionActivateCallback (Gtk.Action action);
22 public void add_simple (string name, string? label, string? tooltip, string? stock_id, ActionActivateCallback callback) {
23 var action = new ContextAction (name, label, tooltip, stock_id);
24
25=== modified file 'midori/midori-notebook.vala'
26--- midori/midori-notebook.vala 2014-03-03 22:49:56 +0000
27+++ midori/midori-notebook.vala 2014-03-06 23:52:22 +0000
28@@ -260,6 +260,25 @@
29 notebook.create_window.disconnect (window_created);
30 }
31
32+ /* Since: 0.5.8 */
33+ public ContextAction get_context_action () {
34+ var menu = new Midori.ContextAction ("NotebookContextMenu", null, null, null);
35+ uint counter = 0;
36+ foreach (var child in notebook.get_children ()) {
37+ var tab = child as Midori.Tab;
38+ var tally = notebook.get_tab_label (tab) as Tally;
39+ var action = new Midori.ContextAction.escaped ("Tab%u".printf (counter), tally.label.label, null, null);
40+ action.gicon = tally.icon.gicon;
41+ action.activate.connect (()=>{
42+ notebook.set_current_page (notebook.page_num (tab));
43+ });
44+ menu.add (action);
45+ counter++;
46+ }
47+ context_menu (menu);
48+ return menu;
49+ }
50+
51 bool button_pressed (Gdk.EventButton event) {
52 /* Propagate events in logical label area */
53 foreach (var child in notebook.get_children ()) {
54@@ -280,20 +299,7 @@
55 return true;
56 }
57 else if (event.button == 3) {
58- var menu = new Midori.ContextAction ("NotebookContextMenu", null, null, null);
59- uint counter = 0;
60- foreach (var child in notebook.get_children ()) {
61- var tab = child as Midori.Tab;
62- var tally = notebook.get_tab_label (tab) as Tally;
63- var action = new Gtk.Action ("Tab%u".printf (counter), tally.label.label, null, null);
64- action.gicon = tally.icon.gicon;
65- action.activate.connect (()=>{
66- notebook.set_current_page (notebook.page_num (tab));
67- });
68- menu.add (action);
69- counter++;
70- }
71- context_menu (menu);
72+ var menu = get_context_action ();
73 var popup = menu.create_menu (null, false);
74 popup.show ();
75 popup.attach_to_widget (this, null);
76
77=== modified file 'midori/midori-view.c'
78--- midori/midori-view.c 2014-03-03 22:49:56 +0000
79+++ midori/midori-view.c 2014-03-06 23:52:22 +0000
80@@ -2370,7 +2370,7 @@
81 && strstr (view->selected_text, "://") == NULL))
82 {
83 gchar* text = g_strdup_printf (_("Send a message to %s"), view->selected_text);
84- GtkAction* action = gtk_action_new ("SendMessage", text, NULL, GTK_STOCK_JUMP_TO);
85+ GtkAction* action = (GtkAction*)midori_context_action_new_escaped ("SendMessage", text, NULL, GTK_STOCK_JUMP_TO);
86 g_object_set_data_full (G_OBJECT (action), "uri", g_strdup (view->selected_text), (GDestroyNotify)g_free);
87 g_signal_connect (action, "activate", G_CALLBACK (midori_view_menu_open_email_activate_cb), view);
88 midori_context_action_add (menu, action);
89@@ -2397,7 +2397,7 @@
90 {
91 GdkPixbuf* pixbuf;
92 gchar* search_option = g_strdup_printf ("SearchWith%u", i);
93- GtkAction* action = gtk_action_new (search_option, katze_item_get_name (item), NULL, STOCK_EDIT_FIND);
94+ GtkAction* action = (GtkAction*)midori_context_action_new_escaped (search_option, katze_item_get_name (item), NULL, STOCK_EDIT_FIND);
95 g_free (search_option);
96 midori_context_action_add (searches, action);
97 if ((pixbuf = katze_item_get_pixbuf (item, view->web_view)))
98
99=== added file 'tests/notebook.vala'
100--- tests/notebook.vala 1970-01-01 00:00:00 +0000
101+++ tests/notebook.vala 2014-03-06 23:52:22 +0000
102@@ -0,0 +1,33 @@
103+/*
104+ Copyright (C) 2014 Christian Dywan <christian@twotoasts.de>
105+
106+ This library is free software; you can redistribute it and/or
107+ modify it under the terms of the GNU Lesser General Public
108+ License as published by the Free Software Foundation; either
109+ version 2.1 of the License, or (at your option) any later version.
110+
111+ See the file COPYING for the full license text.
112+*/
113+
114+void notebook_menu () {
115+ var notebook = new Midori.Notebook ();
116+ /* FIXME: we should just use a Tab but currently it has no title property */
117+ var tab = new Midori.View.with_title ("a_fairy_tale", new Midori.WebSettings ());
118+ /*var tab = new Midori.View.with_title (null, new Midori.WebSettings ());
119+ view.set_html ("<title>a_fairy_tale</title><body>The earth is <em>flat</em> for a fact.</body>");
120+ var loop = MainContext.default ();
121+ do { loop.iteration (true); } while (view.load_status != Midori.LoadStatus.FINISHED);*/
122+ notebook.insert (tab, 0);
123+ var menu = notebook.get_context_action ();
124+ var tab_menu = menu.get_by_name ("Tab0");
125+ assert (tab_menu != null);
126+ /* The underscores should be escaped */
127+ Katze.assert_str_equal ("Tab0", tab_menu.label, "‪a__fairy__tale");
128+}
129+
130+void main (string[] args) {
131+ Test.init (ref args);
132+ Midori.App.setup (ref args, null);
133+ Test.add_func ("/notebook/menu", notebook_menu);
134+ Test.run ();
135+}

Subscribers

People subscribed via source and target branches

to all changes: