Merge lp:~aauzi/midori/fix-1184716 into lp:midori
- fix-1184716
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Cris Dywan |
Approved revision: | 6186 |
Merged at revision: | 6572 |
Proposed branch: | lp:~aauzi/midori/fix-1184716 |
Merge into: | lp:midori |
Diff against target: |
581 lines (+194/-144) 3 files modified
katze/katze-arrayaction.c (+131/-83) midori/marshal.list (+1/-1) midori/midori-browser.c (+62/-60) |
To merge this branch: | bzr merge lp:~aauzi/midori/fix-1184716 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Cris Dywan | Approve | ||
Review via email: mp+188200@code.launchpad.net |
This proposal supersedes a proposal from 2013-05-28.
Commit message
Implements context popup menu on menu entries of bookmark bar and bookmark menu.
Description of the change
(For review: doesn't depend on other branches)
Implements context popup menu on menu entries of bookmark bar and bookmark menu.
- 6184. By André Auzi
-
merge lp:midori and build with Gtk3
- 6185. By André Auzi
-
simplify things by an straight forward evolution of activate-item-alt
- 6186. By André Auzi
-
select correct marshalling and update comment
André Auzi (aauzi) wrote : | # |
> To be frank there's 3 places in the code that look very evil to me:
> a) constructing events when event is NULL
> As mentioned on IRC this may be better solved by introducing a context-menu
> signal and pushing the event handling into KatzeArrayAction. Faking events is
> something to avoid when you can and this feels like bending over backwards for
> supporting the API.
It's good to come back later and review things with some distance.
It looks like a much simple evolution of activate-item-alt is enough to achieve the expected behavior.
> b) pointer_
> Not sure what the exact situation is. Can't we get a widget from the event?
it's not necessary for what I'm expecting nowadays, I got rid of it.
> c) gtk_window_
> I don't see how the code verifies that the given window is the correct one.
> Maybe try midori_
> "browser" is in that situation.
it actually is an evolution of midori_
I've added a check of ancestor.
It works fine with multiple browser windows.
Cris Dywan (kalikiana) wrote : | # |
Got confirmation from others on IRC that it works well (always good to have since I personally hardly use bookmarks), tested with trunk, so let's see if tarmac gets this in without another update.
Preview Diff
1 | === modified file 'katze/katze-arrayaction.c' |
2 | --- katze/katze-arrayaction.c 2012-12-16 18:40:00 +0000 |
3 | +++ katze/katze-arrayaction.c 2013-12-26 17:42:30 +0000 |
4 | @@ -159,15 +159,14 @@ |
5 | /** |
6 | * KatzeArrayAction::activate-item-alt: |
7 | * @array: the object on which the signal is emitted |
8 | + * @proxy: the %GtkWidget that caught the event |
9 | * @item: the item being activated |
10 | - * @button: the mouse button pressed |
11 | + * @event: the mouse button pressed event |
12 | * |
13 | * An item was clicked, with the specified @button. |
14 | * |
15 | * Return value: %TRUE if the event was handled. If %FALSE is returned, |
16 | * the default "activate-item" signal is emitted. |
17 | - * |
18 | - * Since: 0.1.7 |
19 | **/ |
20 | signals[ACTIVATE_ITEM_ALT] = g_signal_new ("activate-item-alt", |
21 | G_TYPE_FROM_CLASS (class), |
22 | @@ -175,9 +174,9 @@ |
23 | 0, |
24 | 0, |
25 | NULL, |
26 | - midori_cclosure_marshal_BOOLEAN__OBJECT_UINT, |
27 | - G_TYPE_BOOLEAN, 2, |
28 | - KATZE_TYPE_ITEM, G_TYPE_UINT); |
29 | + midori_cclosure_marshal_BOOLEAN__OBJECT_OBJECT_POINTER, |
30 | + G_TYPE_BOOLEAN, 3, |
31 | + KATZE_TYPE_ITEM, GTK_TYPE_WIDGET, G_TYPE_POINTER); |
32 | |
33 | gobject_class = G_OBJECT_CLASS (class); |
34 | gobject_class->finalize = katze_array_action_finalize; |
35 | @@ -287,14 +286,33 @@ |
36 | |
37 | static void |
38 | katze_array_action_activate_item (KatzeArrayAction* action, |
39 | - KatzeItem* item, |
40 | - gint button) |
41 | -{ |
42 | + KatzeItem* item) |
43 | +{ |
44 | + g_signal_emit (action, signals[ACTIVATE_ITEM], 0, item); |
45 | +} |
46 | + |
47 | +static gboolean |
48 | +katze_array_action_activate_item_alt (KatzeArrayAction* action, |
49 | + KatzeItem* item, |
50 | + GdkEventButton* event, |
51 | + GtkWidget* proxy) |
52 | +{ |
53 | + /* katze_array_action_activate_item emits the signal. |
54 | + * It can result from "clicked" event where the button event |
55 | + * is not provided. |
56 | + */ |
57 | + |
58 | gboolean handled = FALSE; |
59 | + |
60 | + g_assert (event); |
61 | + |
62 | g_signal_emit (action, signals[ACTIVATE_ITEM_ALT], 0, item, |
63 | - button, &handled); |
64 | + proxy, event, &handled); |
65 | + |
66 | if (!handled) |
67 | - g_signal_emit (action, signals[ACTIVATE_ITEM], 0, item); |
68 | + katze_array_action_activate_item (action, item); |
69 | + |
70 | + return handled; |
71 | } |
72 | |
73 | static void |
74 | @@ -302,7 +320,18 @@ |
75 | KatzeArrayAction* array_action) |
76 | { |
77 | KatzeItem* item = g_object_get_data (G_OBJECT (proxy), "KatzeItem"); |
78 | - katze_array_action_activate_item (array_action, item, 1); |
79 | + |
80 | + katze_array_action_activate_item (array_action, item); |
81 | +} |
82 | + |
83 | +static gboolean |
84 | +katze_array_action_menu_item_button_press_cb (GtkWidget* proxy, |
85 | + GdkEventButton* event, |
86 | + KatzeArrayAction* array_action) |
87 | +{ |
88 | + KatzeItem* item = g_object_get_data (G_OBJECT (proxy), "KatzeItem"); |
89 | + |
90 | + return katze_array_action_activate_item_alt (array_action, item, event, proxy); |
91 | } |
92 | |
93 | static gboolean |
94 | @@ -310,22 +339,70 @@ |
95 | GdkEventButton* event, |
96 | KatzeArrayAction* array_action) |
97 | { |
98 | - KatzeItem* item = g_object_get_data (G_OBJECT (proxy), "KatzeItem"); |
99 | - |
100 | - katze_array_action_activate_item (array_action, item, event->button); |
101 | - |
102 | - /* we need to block the 'activate' handler which would be called |
103 | - * otherwise as well */ |
104 | - g_signal_handlers_block_by_func (proxy, |
105 | - katze_array_action_menu_activate_cb, array_action); |
106 | - |
107 | - return TRUE; |
108 | + /* Take precedence over menu button-press-event handling to avoid |
109 | + menu item activation and menu disparition for popup opening |
110 | + */ |
111 | + |
112 | + return katze_array_action_menu_item_button_press_cb (gtk_get_event_widget ((GdkEvent *) event), event, array_action); |
113 | +} |
114 | + |
115 | +static gboolean |
116 | +katze_array_action_tool_item_child_button_press_cb (GtkWidget* proxy, |
117 | + GdkEventButton* event, |
118 | + KatzeArrayAction* array_action) |
119 | +{ |
120 | + GtkWidget* toolitem = gtk_widget_get_parent (proxy); |
121 | + KatzeItem* item = g_object_get_data (G_OBJECT (toolitem), "KatzeItem"); |
122 | + |
123 | + /* let the 'clicked' signal be processed normally */ |
124 | + if (event->button == 1) |
125 | + return FALSE; |
126 | + |
127 | + return katze_array_action_activate_item_alt (array_action, item, event, proxy); |
128 | } |
129 | |
130 | static void |
131 | katze_array_action_menu_item_select_cb (GtkWidget* proxy, |
132 | KatzeArrayAction* array_action); |
133 | |
134 | +static GtkWidget* |
135 | +katze_array_action_menu_item_new (KatzeArrayAction* array_action, |
136 | + KatzeItem* item) |
137 | +{ |
138 | + GtkWidget* menuitem = katze_image_menu_item_new_ellipsized ( |
139 | + katze_item_get_name (item)); |
140 | + GtkWidget* image = katze_item_get_image (item, menuitem); |
141 | + |
142 | + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image); |
143 | + gtk_image_menu_item_set_always_show_image ( |
144 | + GTK_IMAGE_MENU_ITEM (menuitem), TRUE); |
145 | + |
146 | + g_object_set_data (G_OBJECT (menuitem), "KatzeItem", item); |
147 | + |
148 | + if (KATZE_ITEM_IS_FOLDER (item)) |
149 | + { |
150 | + GtkWidget* submenu = gtk_menu_new (); |
151 | + gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu); |
152 | + g_signal_connect (submenu, "button-press-event", |
153 | + G_CALLBACK (katze_array_action_menu_button_press_cb), array_action); |
154 | + g_signal_connect (menuitem, "select", |
155 | + G_CALLBACK (katze_array_action_menu_item_select_cb), array_action); |
156 | + g_signal_connect (menuitem, "activate", |
157 | + G_CALLBACK (katze_array_action_menu_item_select_cb), array_action); |
158 | + } |
159 | + else |
160 | + { |
161 | + /* we need the 'activate' signal as well for keyboard events */ |
162 | + g_signal_connect (menuitem, "activate", |
163 | + G_CALLBACK (katze_array_action_menu_activate_cb), array_action); |
164 | + } |
165 | + |
166 | + g_signal_connect (menuitem, "button-press-event", |
167 | + G_CALLBACK (katze_array_action_menu_item_button_press_cb), array_action); |
168 | + |
169 | + return menuitem; |
170 | +} |
171 | + |
172 | /** |
173 | * katze_array_action_generate_menu: |
174 | * @array_action: a #KatzeArrayAction |
175 | @@ -355,15 +432,13 @@ |
176 | gint summand; |
177 | KatzeItem* item; |
178 | GtkWidget* menuitem; |
179 | - GtkWidget* image; |
180 | - GtkWidget* submenu; |
181 | |
182 | g_return_if_fail (KATZE_IS_ARRAY_ACTION (array_action)); |
183 | g_return_if_fail (KATZE_IS_ITEM (array)); |
184 | g_return_if_fail (GTK_IS_MENU_SHELL (menu)); |
185 | g_return_if_fail (GTK_IS_TOOL_ITEM (proxy) |
186 | - || GTK_IS_MENU_ITEM (proxy) |
187 | - || GTK_IS_WINDOW (proxy)); |
188 | + || GTK_IS_MENU_ITEM (proxy) |
189 | + || GTK_IS_WINDOW (proxy)); |
190 | |
191 | if (!KATZE_IS_ARRAY (array)) |
192 | return; |
193 | @@ -388,35 +463,19 @@ |
194 | gtk_menu_shell_append (menu, menuitem); |
195 | continue; |
196 | } |
197 | - menuitem = katze_image_menu_item_new_ellipsized ( |
198 | - katze_item_get_name (item)); |
199 | - image = katze_item_get_image (item, menuitem); |
200 | - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image); |
201 | - gtk_image_menu_item_set_always_show_image ( |
202 | - GTK_IMAGE_MENU_ITEM (menuitem), TRUE); |
203 | - gtk_menu_shell_append (menu, menuitem); |
204 | - g_object_set_data (G_OBJECT (menuitem), "KatzeItem", item); |
205 | + |
206 | + menuitem = katze_array_action_menu_item_new (array_action, item); |
207 | + |
208 | if (KATZE_ITEM_IS_FOLDER (item)) |
209 | { |
210 | - submenu = gtk_menu_new (); |
211 | - gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu); |
212 | + GtkWidget* submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (menuitem)); |
213 | /* Make sure menu appears to contain items */ |
214 | gtk_menu_shell_append (GTK_MENU_SHELL (submenu), |
215 | gtk_separator_menu_item_new ()); |
216 | - g_signal_connect (menuitem, "select", |
217 | - G_CALLBACK (katze_array_action_menu_item_select_cb), array_action); |
218 | - g_signal_connect (menuitem, "activate", |
219 | - G_CALLBACK (katze_array_action_menu_item_select_cb), array_action); |
220 | - } |
221 | - else |
222 | - { |
223 | - /* we need the 'activate' signal as well for keyboard events */ |
224 | - g_signal_connect (menuitem, "activate", |
225 | - G_CALLBACK (katze_array_action_menu_activate_cb), array_action); |
226 | - } |
227 | - g_signal_connect (menuitem, "button-press-event", |
228 | - G_CALLBACK (katze_array_action_menu_button_press_cb), array_action); |
229 | + } |
230 | + |
231 | gtk_widget_show (menuitem); |
232 | + gtk_menu_shell_append (menu, menuitem); |
233 | } |
234 | } |
235 | |
236 | @@ -444,7 +503,7 @@ |
237 | katze_array_action_generate_menu (array_action, array, GTK_MENU_SHELL (menu), proxy); |
238 | g_signal_emit (array_action, signals[POPULATE_FOLDER], 0, menu, array, &handled); |
239 | g_object_set_data (G_OBJECT (proxy), "last-update", |
240 | - GINT_TO_POINTER (time (NULL))); |
241 | + GINT_TO_POINTER (time (NULL))); |
242 | return TRUE; |
243 | } |
244 | |
245 | @@ -476,13 +535,14 @@ |
246 | gboolean handled = FALSE; |
247 | |
248 | array = (KatzeArray*)g_object_get_data (G_OBJECT (proxy), "KatzeItem"); |
249 | + |
250 | if (GTK_IS_MENU_ITEM (proxy)) |
251 | { |
252 | if (katze_array_action_menu_item_need_update (array_action, proxy)) |
253 | { |
254 | g_signal_emit (array_action, signals[POPULATE_FOLDER], 0, |
255 | - gtk_menu_item_get_submenu (GTK_MENU_ITEM (proxy)), |
256 | - array, &handled); |
257 | + gtk_menu_item_get_submenu (GTK_MENU_ITEM (proxy)), |
258 | + array, &handled); |
259 | if (!handled) |
260 | g_signal_emit (array_action, signals[POPULATE_POPUP], 0, |
261 | gtk_menu_item_get_submenu (GTK_MENU_ITEM (proxy))); |
262 | @@ -492,7 +552,7 @@ |
263 | |
264 | if (KATZE_IS_ITEM (array) && katze_item_get_uri ((KatzeItem*)array)) |
265 | { |
266 | - katze_array_action_activate_item (array_action, KATZE_ITEM (array), 1); |
267 | + katze_array_action_activate_item (array_action, KATZE_ITEM (array)); |
268 | return; |
269 | } |
270 | |
271 | @@ -512,7 +572,7 @@ |
272 | } |
273 | |
274 | katze_widget_popup (GTK_WIDGET (proxy), GTK_MENU (menu), |
275 | - NULL, KATZE_MENU_POSITION_LEFT); |
276 | + NULL, KATZE_MENU_POSITION_LEFT); |
277 | gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), TRUE); |
278 | g_object_set_data (G_OBJECT (menu), "KatzeArrayAction", array_action); |
279 | g_signal_connect (menu, "deactivate", |
280 | @@ -606,31 +666,9 @@ |
281 | { |
282 | KatzeArrayAction* array_action; |
283 | GtkWidget* menuitem; |
284 | - GtkWidget* image; |
285 | |
286 | array_action = g_object_get_data (G_OBJECT (proxy), "KatzeArrayAction"); |
287 | - menuitem = katze_image_menu_item_new_ellipsized ( |
288 | - katze_item_get_name (item)); |
289 | - image = katze_item_get_image (item, menuitem); |
290 | - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image); |
291 | - gtk_image_menu_item_set_always_show_image ( |
292 | - GTK_IMAGE_MENU_ITEM (menuitem), TRUE); |
293 | - g_object_set_data (G_OBJECT (menuitem), "KatzeItem", item); |
294 | - if (KATZE_ITEM_IS_FOLDER (item)) |
295 | - { |
296 | - GtkWidget* submenu = gtk_menu_new (); |
297 | - gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu); |
298 | - g_signal_connect (menuitem, "select", |
299 | - G_CALLBACK (katze_array_action_menu_item_select_cb), array_action); |
300 | - } |
301 | - else |
302 | - { |
303 | - g_signal_connect (menuitem, "button-press-event", |
304 | - G_CALLBACK (katze_array_action_menu_button_press_cb), array_action); |
305 | - /* we need the 'activate' signal as well for keyboard events */ |
306 | - g_signal_connect (menuitem, "activate", |
307 | - G_CALLBACK (katze_array_action_menu_activate_cb), array_action); |
308 | - } |
309 | + menuitem = katze_array_action_menu_item_new (array_action, item); |
310 | gtk_tool_item_set_proxy_menu_item (GTK_TOOL_ITEM (proxy), |
311 | "katze-tool-item-menu", menuitem); |
312 | return TRUE; |
313 | @@ -706,9 +744,19 @@ |
314 | else |
315 | gtk_tool_item_set_tooltip_text (toolitem, uri); |
316 | |
317 | - g_object_set_data (G_OBJECT (toolitem), "KatzeArray", item); |
318 | + g_object_set_data (G_OBJECT (toolitem), "KatzeItem", item); |
319 | g_signal_connect (toolitem, "clicked", |
320 | G_CALLBACK (katze_array_action_proxy_clicked_cb), array_action); |
321 | + if (KATZE_IS_ITEM (item)) |
322 | + { |
323 | + /* Tool items block the "button-press-event" but we can get it |
324 | + * when connecting it to the tool item's child widget |
325 | + */ |
326 | + |
327 | + GtkWidget* child = gtk_bin_get_child (GTK_BIN (toolitem)); |
328 | + g_signal_connect (child, "button-press-event", |
329 | + G_CALLBACK (katze_array_action_tool_item_child_button_press_cb), array_action); |
330 | + } |
331 | |
332 | g_object_set_data (G_OBJECT (toolitem), "KatzeArrayAction", array_action); |
333 | g_signal_connect (item, "notify", |
334 | @@ -779,11 +827,11 @@ |
335 | |
336 | /* FIXME: Add and remove items dynamically */ |
337 | /*g_object_connect (array, |
338 | - "signal-after::add-item", |
339 | - katze_array_action_engines_add_item_cb, array_action, |
340 | - "signal-after::remove-item", |
341 | - katze_array_action_engines_remove_item_cb, array_action, |
342 | - NULL);*/ |
343 | + "signal-after::add-item", |
344 | + katze_array_action_engines_add_item_cb, array_action, |
345 | + "signal-after::remove-item", |
346 | + katze_array_action_engines_remove_item_cb, array_action, |
347 | + NULL);*/ |
348 | |
349 | g_object_notify (G_OBJECT (array_action), "array"); |
350 | |
351 | |
352 | === modified file 'midori/marshal.list' |
353 | --- midori/marshal.list 2013-09-03 14:45:17 +0000 |
354 | +++ midori/marshal.list 2013-12-26 17:42:30 +0000 |
355 | @@ -1,6 +1,6 @@ |
356 | BOOLEAN:OBJECT |
357 | BOOLEAN:OBJECT,OBJECT |
358 | -BOOLEAN:OBJECT,UINT |
359 | +BOOLEAN:OBJECT,OBJECT,POINTER |
360 | BOOLEAN:VOID |
361 | BOOLEAN:STRING |
362 | OBJECT:OBJECT |
363 | |
364 | === modified file 'midori/midori-browser.c' |
365 | --- midori/midori-browser.c 2013-12-18 23:41:05 +0000 |
366 | +++ midori/midori-browser.c 2013-12-26 17:42:30 +0000 |
367 | @@ -916,7 +916,7 @@ |
368 | folders = g_list_append (folders, folder); |
369 | } |
370 | |
371 | - sqlite3_clear_bindings (statement); |
372 | + sqlite3_clear_bindings (statement); |
373 | sqlite3_reset (statement); |
374 | } |
375 | |
376 | @@ -2979,18 +2979,31 @@ |
377 | return TRUE; |
378 | } |
379 | |
380 | +static void |
381 | +midori_browser_bookmark_popup (GtkWidget* proxy, |
382 | + GdkEventButton* event, |
383 | + KatzeItem* item, |
384 | + MidoriBrowser* browser); |
385 | + |
386 | static gboolean |
387 | -midori_bookmarkbar_activate_item_alt (GtkAction* action, |
388 | - KatzeItem* item, |
389 | - guint button, |
390 | - MidoriBrowser* browser) |
391 | +midori_bookmarkbar_activate_item_alt (GtkAction* action, |
392 | + KatzeItem* item, |
393 | + GtkWidget* proxy, |
394 | + GdkEventButton* event, |
395 | + MidoriBrowser* browser) |
396 | { |
397 | - if (MIDORI_EVENT_NEW_TAB (gtk_get_current_event ())) |
398 | + g_assert (event); |
399 | + |
400 | + if (MIDORI_EVENT_NEW_TAB (event)) |
401 | { |
402 | GtkWidget* view = midori_browser_add_item (browser, item); |
403 | midori_browser_set_current_tab_smartly (browser, view); |
404 | } |
405 | - else if (button == 1) |
406 | + else if (MIDORI_EVENT_CONTEXT_MENU (event)) |
407 | + { |
408 | + midori_browser_bookmark_popup (proxy, NULL, item, browser); |
409 | + } |
410 | + else if (event->button == 1) |
411 | { |
412 | midori_browser_open_bookmark (browser, item); |
413 | } |
414 | @@ -3028,17 +3041,20 @@ |
415 | } |
416 | |
417 | static gboolean |
418 | -_action_trash_activate_item_alt (GtkAction* action, |
419 | - KatzeItem* item, |
420 | - guint button, |
421 | - MidoriBrowser* browser) |
422 | +_action_trash_activate_item_alt (GtkAction* action, |
423 | + KatzeItem* item, |
424 | + GtkWidget* proxy, |
425 | + GdkEventButton* event, |
426 | + MidoriBrowser* browser) |
427 | { |
428 | - if (MIDORI_EVENT_NEW_TAB (gtk_get_current_event ())) |
429 | + g_assert (event); |
430 | + |
431 | + if (MIDORI_EVENT_NEW_TAB (event)) |
432 | { |
433 | midori_browser_set_current_tab_smartly (browser, |
434 | midori_browser_restore_tab (browser, item)); |
435 | } |
436 | - else if (button == 1) |
437 | + else if (event->button == 1) |
438 | { |
439 | midori_browser_set_current_tab (browser, |
440 | midori_browser_restore_tab (browser, item)); |
441 | @@ -3095,12 +3111,6 @@ |
442 | midori_context_action_create_menu (menu, default_menu, TRUE); |
443 | } |
444 | |
445 | -static void |
446 | -midori_browser_bookmark_popup (GtkWidget* widget, |
447 | - GdkEventButton* event, |
448 | - KatzeItem* item, |
449 | - MidoriBrowser* browser); |
450 | - |
451 | static gboolean |
452 | _action_bookmarks_populate_folder (GtkAction* action, |
453 | GtkMenuShell* menu, |
454 | @@ -3174,10 +3184,11 @@ |
455 | } |
456 | |
457 | static void |
458 | -_action_window_activate_item_alt (GtkAction* action, |
459 | - KatzeItem* item, |
460 | - gint button, |
461 | - MidoriBrowser* browser) |
462 | +_action_window_activate_item_alt (GtkAction* action, |
463 | + KatzeItem* item, |
464 | + GtkWidget* proxy, |
465 | + GdkEventButton* event, |
466 | + MidoriBrowser* browser) |
467 | { |
468 | midori_browser_set_current_item (browser, item); |
469 | } |
470 | @@ -4238,6 +4249,9 @@ |
471 | it is an item, we forward it to the actual widget. */ |
472 | if ((GTK_IS_BOX (toolitem) || GTK_IS_MENU_BAR (toolitem))) |
473 | { |
474 | + if (gtk_widget_get_window (toolitem) != event->window) |
475 | + return FALSE; |
476 | + |
477 | midori_browser_toolbar_popup_context_menu_cb ( |
478 | GTK_IS_BIN (toolitem) && gtk_bin_get_child (GTK_BIN (toolitem)) ? |
479 | gtk_widget_get_parent (toolitem) : toolitem, |
480 | @@ -5876,8 +5890,6 @@ |
481 | g_object_connect (action, |
482 | "signal::populate-popup", |
483 | _action_tools_populate_popup, browser, |
484 | - "signal::activate-item-alt", |
485 | - midori_bookmarkbar_activate_item_alt, browser, |
486 | NULL); |
487 | gtk_action_group_add_action (browser->action_group, action); |
488 | g_object_unref (action); |
489 | @@ -6599,29 +6611,6 @@ |
490 | g_value_unset (&value); |
491 | } |
492 | |
493 | -static gboolean |
494 | -midori_bookmarkbar_item_button_press_event_cb (GtkWidget* toolitem, |
495 | - GdkEventButton* event, |
496 | - MidoriBrowser* browser) |
497 | -{ |
498 | - KatzeItem* item = (KatzeItem*)g_object_get_data (G_OBJECT (toolitem), "KatzeItem"); |
499 | - if (MIDORI_EVENT_NEW_TAB (event)) |
500 | - { |
501 | - if (KATZE_ITEM_IS_BOOKMARK (item)) |
502 | - { |
503 | - GtkWidget* view = midori_browser_add_uri (browser, katze_item_get_uri (item)); |
504 | - midori_browser_set_current_tab_smartly (browser, view); |
505 | - return TRUE; |
506 | - } |
507 | - } |
508 | - else if (MIDORI_EVENT_CONTEXT_MENU (event)) |
509 | - { |
510 | - midori_browser_bookmark_popup (toolitem, NULL, item, browser); |
511 | - return TRUE; |
512 | - } |
513 | - return FALSE; |
514 | -} |
515 | - |
516 | static void |
517 | midori_bookmarkbar_insert_item (GtkWidget* toolbar, |
518 | KatzeItem* item) |
519 | @@ -6632,15 +6621,7 @@ |
520 | KATZE_ARRAY_ACTION (action), item); |
521 | g_object_set_data (G_OBJECT (toolitem), "KatzeItem", item); |
522 | |
523 | - if (KATZE_IS_ITEM (item)) |
524 | - { |
525 | - GtkWidget* child = gtk_bin_get_child (GTK_BIN (toolitem)); |
526 | - g_object_set_data (G_OBJECT (child), "KatzeItem", item); |
527 | - g_signal_connect (child, "button-press-event", |
528 | - G_CALLBACK (midori_bookmarkbar_item_button_press_event_cb), |
529 | - browser); |
530 | - } |
531 | - else /* Separator */ |
532 | + if (!KATZE_IS_ITEM (item)) /* Separator */ |
533 | gtk_tool_item_set_use_drag_window (toolitem, TRUE); |
534 | |
535 | gtk_widget_show (GTK_WIDGET (toolitem)); |
536 | @@ -6649,13 +6630,13 @@ |
537 | |
538 | static void |
539 | midori_bookmarkbar_add_item_cb (KatzeArray* bookmarks, |
540 | - KatzeItem* item, |
541 | - MidoriBrowser* browser) |
542 | + KatzeItem* item, |
543 | + MidoriBrowser* browser) |
544 | { |
545 | if (gtk_widget_get_visible (browser->bookmarkbar)) |
546 | midori_bookmarkbar_populate (browser); |
547 | else if (katze_item_get_meta_boolean (item, "toolbar")) |
548 | - _action_set_active (browser, "Bookmarkbar", TRUE); |
549 | + _action_set_active (browser, "Bookmarkbar", TRUE); |
550 | midori_browser_update_history (item, "bookmark", "created"); |
551 | } |
552 | |
553 | @@ -7458,7 +7439,28 @@ |
554 | |
555 | browser = gtk_window_get_transient_for (GTK_WINDOW (browser)); |
556 | if (!MIDORI_IS_BROWSER (browser)) |
557 | + { |
558 | + /* For some reason, when called on the widget of the |
559 | + * application menubar we get here. |
560 | + */ |
561 | + |
562 | + GList* top_levels = gtk_window_list_toplevels (); |
563 | + GList *iter; |
564 | + |
565 | + for (iter = top_levels; iter; iter = g_list_next (iter)) |
566 | + { |
567 | + browser = iter->data; |
568 | + |
569 | + if (MIDORI_IS_BROWSER (browser) && gtk_widget_is_ancestor( GTK_WIDGET (browser), widget)) |
570 | + { |
571 | + g_list_free (top_levels); |
572 | + return MIDORI_BROWSER (browser); |
573 | + } |
574 | + } |
575 | + |
576 | + g_list_free (top_levels); |
577 | return NULL; |
578 | + } |
579 | } |
580 | |
581 | return MIDORI_BROWSER (browser); |
To be frank there's 3 places in the code that look very evil to me:
a) constructing events when event is NULL
As mentioned on IRC this may be better solved by introducing a context-menu signal and pushing the event handling into KatzeArrayAction. Faking events is something to avoid when you can and this feels like bending over backwards for supporting the API.
b) pointer_ in_menu_ window
Not sure what the exact situation is. Can't we get a widget from the event?
c) gtk_window_ list_toplevels to find a browser browser_ get_for_ widget? At least check what the original "browser" is in that situation.
I don't see how the code verifies that the given window is the correct one.
Maybe try midori_