Merge lp:~attente/unity-gtk-module/1208019-2 into lp:unity-gtk-module/14.10

Proposed by William Hua
Status: Merged
Approved by: Ted Gould
Approved revision: 335
Merged at revision: 330
Proposed branch: lp:~attente/unity-gtk-module/1208019-2
Merge into: lp:unity-gtk-module/14.10
Diff against target: 895 lines (+442/-230)
7 files modified
lib/unity-gtk-action-group.c (+269/-161)
lib/unity-gtk-action-private.h (+19/-15)
lib/unity-gtk-action.c (+14/-0)
lib/unity-gtk-menu-item-private.h (+3/-1)
lib/unity-gtk-menu-item.c (+88/-26)
lib/unity-gtk-menu-section.c (+40/-25)
lib/unity-gtk-menu-shell.c (+9/-2)
To merge this branch: bzr merge lp:~attente/unity-gtk-module/1208019-2
Reviewer Review Type Date Requested Status
Ted Gould (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+224646@code.launchpad.net

Commit message

Forward show and hide signals to GTK+ menus.

Description of the change

Forward show and hide signals to GTK+ menus.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ted Gould (ted) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/unity-gtk-action-group.c'
--- lib/unity-gtk-action-group.c 2014-03-25 21:48:16 +0000
+++ lib/unity-gtk-action-group.c 2014-06-26 14:42:27 +0000
@@ -42,6 +42,14 @@
4242
43static gboolean unity_gtk_action_group_debug;43static gboolean unity_gtk_action_group_debug;
4444
45static gboolean
46g_signal_emit_hide (gpointer user_data)
47{
48 g_signal_emit_by_name (user_data, "hide");
49
50 return G_SOURCE_REMOVE;
51}
52
45static void53static void
46unity_gtk_action_group_handle_group_action_added (GActionGroup *action_group,54unity_gtk_action_group_handle_group_action_added (GActionGroup *action_group,
47 gchar *action_name,55 gchar *action_name,
@@ -272,54 +280,79 @@
272280
273 if (action != NULL)281 if (action != NULL)
274 {282 {
275 if (action->items_by_name != NULL)283 if (g_strcmp0 (name, action->name) == 0)
276 {284 {
277 if (value != NULL)285 if (action->items_by_name != NULL)
278 {286 {
279 const gchar *name;287 if (value != NULL)
280 UnityGtkMenuItem *item;288 {
281289 const gchar *name;
282 g_return_if_fail (g_variant_is_of_type (value, G_VARIANT_TYPE_STRING));290 UnityGtkMenuItem *item;
283291
284 name = g_variant_get_string (value, NULL);292 g_return_if_fail (g_variant_is_of_type (value, G_VARIANT_TYPE_STRING));
285 item = g_hash_table_lookup (action->items_by_name, name);293
286294 name = g_variant_get_string (value, NULL);
287 if (item == NULL || !unity_gtk_menu_item_is_check (item))295 item = g_hash_table_lookup (action->items_by_name, name);
288 {296
289 g_warn_if_reached ();297 if (item == NULL || !unity_gtk_menu_item_is_check (item))
290298 {
291 value = NULL;299 g_warn_if_reached ();
292 }300
293 else301 value = NULL;
294 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item->menu_item), TRUE);302 }
295 }303 else
296304 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item->menu_item), TRUE);
297 if (value == NULL)305 }
298 {306
299 GHashTableIter iter;307 if (value == NULL)
300 gpointer value;308 {
301309 GHashTableIter iter;
302 g_hash_table_iter_init (&iter, action->items_by_name);310 gpointer value;
303 while (g_hash_table_iter_next (&iter, NULL, &value))311
304 {312 g_hash_table_iter_init (&iter, action->items_by_name);
305 UnityGtkMenuItem *item = value;313 while (g_hash_table_iter_next (&iter, NULL, &value))
306314 {
307 if (unity_gtk_menu_item_is_check (item))315 UnityGtkMenuItem *item = value;
308 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item->menu_item), FALSE);316
309 }317 if (unity_gtk_menu_item_is_check (item))
310 }318 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item->menu_item), FALSE);
319 }
320 }
321 }
322 else if (action->item != NULL && unity_gtk_menu_item_is_check (action->item))
323 {
324 g_return_if_fail (value != NULL && g_variant_is_of_type (value, G_VARIANT_TYPE_BOOLEAN));
325
326 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (action->item->menu_item), g_variant_get_boolean (value));
327 }
328 else
329 g_warn_if_fail (value == NULL);
330
331 return;
311 }332 }
312 else if (action->item != NULL && unity_gtk_menu_item_is_check (action->item))333 else if (g_strcmp0 (name, action->subname) == 0)
313 {334 {
335 GtkWidget *submenu;
336
314 g_return_if_fail (value != NULL && g_variant_is_of_type (value, G_VARIANT_TYPE_BOOLEAN));337 g_return_if_fail (value != NULL && g_variant_is_of_type (value, G_VARIANT_TYPE_BOOLEAN));
315338 g_return_if_fail (action->item != NULL && action->item->menu_item != NULL);
316 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (action->item->menu_item), g_variant_get_boolean (value));339
340 submenu = gtk_menu_item_get_submenu (action->item->menu_item);
341
342 g_return_if_fail (submenu != NULL);
343
344 if (g_variant_get_boolean (value))
345 g_signal_emit_by_name (submenu, "show");
346 else
347 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, g_signal_emit_hide, g_object_ref (submenu), g_object_unref);
348
349 return;
317 }350 }
318 else351 else
319 g_warn_if_fail (value == NULL);352 g_warn_if_reached ();
320
321 return;
322 }353 }
354 else
355 g_warn_if_reached ();
323 }356 }
324 else357 else
325 g_warn_if_reached ();358 g_warn_if_reached ();
@@ -359,33 +392,40 @@
359392
360 if (action != NULL)393 if (action != NULL)
361 {394 {
362 if (action->items_by_name != NULL)395 if (g_strcmp0 (name, action->name) == 0)
363 {396 {
364 const gchar *name;397 if (action->items_by_name != NULL)
365 UnityGtkMenuItem *item;398 {
366399 const gchar *name;
367 g_return_if_fail (parameter != NULL && g_variant_is_of_type (parameter, G_VARIANT_TYPE_STRING));400 UnityGtkMenuItem *item;
368401
369 name = g_variant_get_string (parameter, NULL);402 g_return_if_fail (parameter != NULL && g_variant_is_of_type (parameter, G_VARIANT_TYPE_STRING));
370 item = g_hash_table_lookup (action->items_by_name, name);403
371404 name = g_variant_get_string (parameter, NULL);
372 if (item != NULL)405 item = g_hash_table_lookup (action->items_by_name, name);
373 unity_gtk_menu_item_activate (item);406
374407 if (item != NULL)
375 g_action_group_action_state_changed (G_ACTION_GROUP (group), action->name, parameter);408 unity_gtk_menu_item_activate (item);
376 }409
377 else if (action->item != NULL)410 g_action_group_action_state_changed (G_ACTION_GROUP (group), action->name, parameter);
378 {411 }
379 if (unity_gtk_menu_item_get_draw_as_radio (action->item))412 else if (action->item != NULL)
380 g_warn_if_fail (g_variant_is_of_type (parameter, G_VARIANT_TYPE_STRING));413 {
381 else414 if (unity_gtk_menu_item_get_draw_as_radio (action->item))
382 g_warn_if_fail (parameter == NULL);415 g_warn_if_fail (g_variant_is_of_type (parameter, G_VARIANT_TYPE_STRING));
383416 else
384 unity_gtk_menu_item_activate (action->item);417 g_warn_if_fail (parameter == NULL);
385 }418
386419 unity_gtk_menu_item_activate (action->item);
387 return;420 }
421
422 return;
423 }
424 else
425 g_warn_if_reached ();
388 }426 }
427 else
428 g_warn_if_reached ();
389 }429 }
390 else430 else
391 g_warn_if_reached ();431 g_warn_if_reached ();
@@ -419,111 +459,142 @@
419459
420 if (action != NULL)460 if (action != NULL)
421 {461 {
422 if (enabled != NULL)462 if (g_strcmp0 (name, action->name) == 0)
423 {463 {
424 if (action->items_by_name != NULL)464 if (enabled != NULL)
425 {465 {
426 GHashTableIter iter;466 if (action->items_by_name != NULL)
427 gpointer value;467 {
428468 GHashTableIter iter;
429 *enabled = FALSE;469 gpointer value;
430470
431 g_hash_table_iter_init (&iter, action->items_by_name);471 *enabled = FALSE;
432 while (!*enabled && g_hash_table_iter_next (&iter, NULL, &value))472
433 *enabled = unity_gtk_menu_item_is_sensitive (value);473 g_hash_table_iter_init (&iter, action->items_by_name);
434 }474 while (!*enabled && g_hash_table_iter_next (&iter, NULL, &value))
435 else475 *enabled = unity_gtk_menu_item_is_sensitive (value);
436 *enabled = action->item != NULL && unity_gtk_menu_item_is_sensitive (action->item);476 }
477 else
478 *enabled = action->item != NULL && unity_gtk_menu_item_is_sensitive (action->item);
479 }
480
481 if (parameter_type != NULL)
482 {
483 if (action->items_by_name != NULL || (action->item != NULL && unity_gtk_menu_item_get_draw_as_radio (action->item)))
484 *parameter_type = G_VARIANT_TYPE_STRING;
485 else
486 *parameter_type = NULL;
487 }
488
489 if (state_type != NULL)
490 {
491 if (action->items_by_name != NULL || (action->item != NULL && unity_gtk_menu_item_get_draw_as_radio (action->item)))
492 *state_type = G_VARIANT_TYPE_STRING;
493 else if (action->item != NULL && unity_gtk_menu_item_is_check (action->item))
494 *state_type = G_VARIANT_TYPE_BOOLEAN;
495 else
496 *state_type = NULL;
497 }
498
499 if (state_hint != NULL)
500 {
501 if (action->items_by_name != NULL)
502 {
503 GVariantBuilder builder;
504 GHashTableIter iter;
505 gpointer key;
506
507 g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
508
509 g_hash_table_iter_init (&iter, action->items_by_name);
510 while (g_hash_table_iter_next (&iter, &key, NULL))
511 g_variant_builder_add (&builder, "s", key);
512
513 *state_hint = g_variant_ref_sink (g_variant_builder_end (&builder));
514 }
515 else if (action->item != NULL && unity_gtk_menu_item_is_check (action->item))
516 {
517 GVariantBuilder builder;
518
519 if (unity_gtk_menu_item_get_draw_as_radio (action->item))
520 {
521 g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
522 g_variant_builder_add (&builder, "s", action->name);
523 *state_hint = g_variant_ref_sink (g_variant_builder_end (&builder));
524 }
525 else
526 {
527 g_variant_builder_init (&builder, G_VARIANT_TYPE_TUPLE);
528 g_variant_builder_add (&builder, "b", FALSE);
529 g_variant_builder_add (&builder, "b", TRUE);
530 *state_hint = g_variant_ref_sink (g_variant_builder_end (&builder));
531 }
532 }
533 else
534 *state_hint = NULL;
535 }
536
537 if (state != NULL)
538 {
539 if (action->items_by_name != NULL)
540 {
541 GHashTableIter iter;
542 gpointer key;
543 gpointer value;
544
545 *state = NULL;
546
547 g_hash_table_iter_init (&iter, action->items_by_name);
548 while (*state == NULL && g_hash_table_iter_next (&iter, &key, &value))
549 if (unity_gtk_menu_item_is_active (value))
550 *state = g_variant_ref_sink (g_variant_new_string (key));
551 }
552 else if (action->item != NULL && unity_gtk_menu_item_is_check (action->item))
553 {
554 if (unity_gtk_menu_item_get_draw_as_radio (action->item))
555 {
556 if (unity_gtk_menu_item_is_active (action->item))
557 *state = g_variant_ref_sink (g_variant_new_string (action->name));
558 else
559 *state = g_variant_ref_sink (g_variant_new_string (""));
560 }
561 else
562 *state = g_variant_ref_sink (g_variant_new_boolean (unity_gtk_menu_item_is_active (action->item)));
563 }
564 else
565 *state = NULL;
566 }
567
568 return TRUE;
437 }569 }
570 else if (g_strcmp0 (name, action->subname) == 0)
571 {
572 if (enabled != NULL)
573 *enabled = TRUE;
438574
439 if (parameter_type != NULL)575 if (parameter_type != NULL)
440 {
441 if (action->items_by_name != NULL || (action->item != NULL && unity_gtk_menu_item_get_draw_as_radio (action->item)))
442 *parameter_type = G_VARIANT_TYPE_STRING;
443 else
444 *parameter_type = NULL;576 *parameter_type = NULL;
445 }
446577
447 if (state_type != NULL)578 if (state_type != NULL)
448 {
449 if (action->items_by_name != NULL || (action->item != NULL && unity_gtk_menu_item_get_draw_as_radio (action->item)))
450 *state_type = G_VARIANT_TYPE_STRING;
451 else if (action->item != NULL && unity_gtk_menu_item_is_check (action->item))
452 *state_type = G_VARIANT_TYPE_BOOLEAN;579 *state_type = G_VARIANT_TYPE_BOOLEAN;
453 else
454 *state_type = NULL;
455 }
456580
457 if (state_hint != NULL)581 if (state_hint != NULL)
458 {
459 if (action->items_by_name != NULL)
460 {582 {
461 GVariantBuilder builder;583 GVariantBuilder builder;
462 GHashTableIter iter;584
463 gpointer key;585 g_variant_builder_init (&builder, G_VARIANT_TYPE_TUPLE);
464586 g_variant_builder_add (&builder, "b", FALSE);
465 g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);587 g_variant_builder_add (&builder, "b", TRUE);
466
467 g_hash_table_iter_init (&iter, action->items_by_name);
468 while (g_hash_table_iter_next (&iter, &key, NULL))
469 g_variant_builder_add (&builder, "s", key);
470
471 *state_hint = g_variant_ref_sink (g_variant_builder_end (&builder));588 *state_hint = g_variant_ref_sink (g_variant_builder_end (&builder));
472 }589 }
473 else if (action->item != NULL && unity_gtk_menu_item_is_check (action->item))590
474 {591 if (state != NULL)
475 GVariantBuilder builder;592 *state = g_variant_ref_sink (g_variant_new_boolean (TRUE));
476593
477 if (unity_gtk_menu_item_get_draw_as_radio (action->item))594 return TRUE;
478 {595 }
479 g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);596 else
480 g_variant_builder_add (&builder, "s", action->name);597 g_warn_if_reached ();
481 *state_hint = g_variant_ref_sink (g_variant_builder_end (&builder));
482 }
483 else
484 {
485 g_variant_builder_init (&builder, G_VARIANT_TYPE_TUPLE);
486 g_variant_builder_add (&builder, "b", FALSE);
487 g_variant_builder_add (&builder, "b", TRUE);
488 *state_hint = g_variant_ref_sink (g_variant_builder_end (&builder));
489 }
490 }
491 else
492 *state_hint = NULL;
493 }
494
495 if (state != NULL)
496 {
497 if (action->items_by_name != NULL)
498 {
499 GHashTableIter iter;
500 gpointer key;
501 gpointer value;
502
503 *state = NULL;
504
505 g_hash_table_iter_init (&iter, action->items_by_name);
506 while (*state == NULL && g_hash_table_iter_next (&iter, &key, &value))
507 if (unity_gtk_menu_item_is_active (value))
508 *state = g_variant_ref_sink (g_variant_new_string (key));
509 }
510 else if (action->item != NULL && unity_gtk_menu_item_is_check (action->item))
511 {
512 if (unity_gtk_menu_item_get_draw_as_radio (action->item))
513 {
514 if (unity_gtk_menu_item_is_active (action->item))
515 *state = g_variant_ref_sink (g_variant_new_string (action->name));
516 else
517 *state = g_variant_ref_sink (g_variant_new_string (""));
518 }
519 else
520 *state = g_variant_ref_sink (g_variant_new_boolean (unity_gtk_menu_item_is_active (action->item)));
521 }
522 else
523 *state = NULL;
524 }
525
526 return TRUE;
527 }598 }
528 }599 }
529 else600 else
@@ -865,6 +936,21 @@
865 g_warn_if_reached ();936 g_warn_if_reached ();
866937
867 g_action_group_action_added (G_ACTION_GROUP (group), new_action->name);938 g_action_group_action_added (G_ACTION_GROUP (group), new_action->name);
939
940 /* Add a new submenu action so we can detect opening and closing. */
941 if (item->menu_item != NULL && gtk_menu_item_get_submenu (item->menu_item) != NULL)
942 {
943 gchar *subname = unity_gtk_action_group_get_action_name (group, item);
944 unity_gtk_action_set_subname (new_action, subname);
945 g_free (subname);
946
947 if (group->actions_by_name != NULL)
948 g_hash_table_insert (group->actions_by_name, new_action->subname, g_object_ref (new_action));
949 else
950 g_warn_if_reached ();
951
952 g_action_group_action_added (G_ACTION_GROUP (group), new_action->subname);
953 }
868 }954 }
869 }955 }
870}956}
@@ -908,6 +994,17 @@
908994
909 if (g_hash_table_size (action->items_by_name) == 0)995 if (g_hash_table_size (action->items_by_name) == 0)
910 {996 {
997 /* Remove the submenu action used to detect opening and closing. */
998 if (action->subname != NULL)
999 {
1000 if (group->actions_by_name != NULL)
1001 g_hash_table_remove (group->actions_by_name, action->subname);
1002 else
1003 g_warn_if_reached ();
1004
1005 g_action_group_action_removed (G_ACTION_GROUP (group), action->subname);
1006 }
1007
911 if (group->actions_by_name != NULL)1008 if (group->actions_by_name != NULL)
912 g_hash_table_remove (group->actions_by_name, action->name);1009 g_hash_table_remove (group->actions_by_name, action->name);
913 else1010 else
@@ -924,6 +1021,17 @@
924 }1021 }
925 else1022 else
926 {1023 {
1024 /* Remove the submenu action used to detect opening and closing. */
1025 if (action->subname != NULL)
1026 {
1027 if (group->actions_by_name != NULL)
1028 g_hash_table_remove (group->actions_by_name, action->subname);
1029 else
1030 g_warn_if_reached ();
1031
1032 g_action_group_action_removed (G_ACTION_GROUP (group), action->subname);
1033 }
1034
927 if (group->actions_by_name != NULL)1035 if (group->actions_by_name != NULL)
928 g_hash_table_remove (group->actions_by_name, action->name);1036 g_hash_table_remove (group->actions_by_name, action->name);
929 else1037 else
9301038
=== modified file 'lib/unity-gtk-action-private.h'
--- lib/unity-gtk-action-private.h 2013-02-19 11:55:57 +0000
+++ lib/unity-gtk-action-private.h 2014-06-26 14:42:27 +0000
@@ -46,25 +46,29 @@
4646
47 /*< private >*/47 /*< private >*/
48 gchar *name;48 gchar *name;
49 gchar *subname;
49 UnityGtkMenuItem *item;50 UnityGtkMenuItem *item;
50 GHashTable *items_by_name;51 GHashTable *items_by_name;
51};52};
5253
53GType unity_gtk_action_get_type (void) G_GNUC_INTERNAL;54GType unity_gtk_action_get_type (void) G_GNUC_INTERNAL;
5455
55UnityGtkAction * unity_gtk_action_new (const gchar *name,56UnityGtkAction * unity_gtk_action_new (const gchar *name,
56 UnityGtkMenuItem *item) G_GNUC_INTERNAL;57 UnityGtkMenuItem *item) G_GNUC_INTERNAL;
5758
58UnityGtkAction * unity_gtk_action_new_radio (const gchar *name) G_GNUC_INTERNAL;59UnityGtkAction * unity_gtk_action_new_radio (const gchar *name) G_GNUC_INTERNAL;
5960
60void unity_gtk_action_set_name (UnityGtkAction *action,61void unity_gtk_action_set_name (UnityGtkAction *action,
61 const gchar *name) G_GNUC_INTERNAL;62 const gchar *name) G_GNUC_INTERNAL;
6263
63void unity_gtk_action_set_item (UnityGtkAction *action,64void unity_gtk_action_set_subname (UnityGtkAction *action,
64 UnityGtkMenuItem *item) G_GNUC_INTERNAL;65 const gchar *subname) G_GNUC_INTERNAL;
6566
66void unity_gtk_action_print (UnityGtkAction *action,67void unity_gtk_action_set_item (UnityGtkAction *action,
67 guint indent) G_GNUC_INTERNAL;68 UnityGtkMenuItem *item) G_GNUC_INTERNAL;
69
70void unity_gtk_action_print (UnityGtkAction *action,
71 guint indent) G_GNUC_INTERNAL;
6872
69G_END_DECLS73G_END_DECLS
7074
7175
=== modified file 'lib/unity-gtk-action.c'
--- lib/unity-gtk-action.c 2013-02-19 11:55:57 +0000
+++ lib/unity-gtk-action.c 2014-06-26 14:42:27 +0000
@@ -41,6 +41,7 @@
41 }41 }
4242
43 unity_gtk_action_set_item (action, NULL);43 unity_gtk_action_set_item (action, NULL);
44 unity_gtk_action_set_subname (action, NULL);
44 unity_gtk_action_set_name (action, NULL);45 unity_gtk_action_set_name (action, NULL);
4546
46 G_OBJECT_CLASS (unity_gtk_action_parent_class)->dispose (object);47 G_OBJECT_CLASS (unity_gtk_action_parent_class)->dispose (object);
@@ -93,6 +94,16 @@
93}94}
9495
95void96void
97unity_gtk_action_set_subname (UnityGtkAction *action,
98 const gchar *subname)
99{
100 g_return_if_fail (UNITY_GTK_IS_ACTION (action));
101
102 g_free (action->subname);
103 action->subname = g_strdup (subname);
104}
105
106void
96unity_gtk_action_set_item (UnityGtkAction *action,107unity_gtk_action_set_item (UnityGtkAction *action,
97 UnityGtkMenuItem *item)108 UnityGtkMenuItem *item)
98{109{
@@ -132,6 +143,9 @@
132 if (action->name != NULL)143 if (action->name != NULL)
133 g_print ("%s \"%s\"\n", space, action->name);144 g_print ("%s \"%s\"\n", space, action->name);
134145
146 if (action->subname != NULL)
147 g_print ("%s \"%s\"\n", space, action->subname);
148
135 if (action->item != NULL)149 if (action->item != NULL)
136 g_print ("%s (%s *) %p\n", space, G_OBJECT_CLASS_NAME (G_OBJECT_GET_CLASS (action->item)), action->item);150 g_print ("%s (%s *) %p\n", space, G_OBJECT_CLASS_NAME (G_OBJECT_GET_CLASS (action->item)), action->item);
137151
138152
=== modified file 'lib/unity-gtk-menu-item-private.h'
--- lib/unity-gtk-menu-item-private.h 2014-03-31 00:40:48 +0000
+++ lib/unity-gtk-menu-item-private.h 2014-06-26 14:42:27 +0000
@@ -52,7 +52,9 @@
52 guchar child_shell_valid : 1;52 guchar child_shell_valid : 1;
53 guint item_index;53 guint item_index;
54 UnityGtkAction *action;54 UnityGtkAction *action;
55 gchar *label;55 GtkLabel *first_label;
56 GtkLabel *second_label;
57 gchar *label_label;
56};58};
5759
58GType unity_gtk_menu_item_get_type (void) G_GNUC_INTERNAL;60GType unity_gtk_menu_item_get_type (void) G_GNUC_INTERNAL;
5961
=== modified file 'lib/unity-gtk-menu-item.c'
--- lib/unity-gtk-menu-item.c 2014-03-31 00:40:48 +0000
+++ lib/unity-gtk-menu-item.c 2014-06-26 14:42:27 +0000
@@ -368,6 +368,75 @@
368}368}
369369
370static void370static void
371unity_gtk_menu_item_disconnect_labels (UnityGtkMenuItem *item)
372{
373 g_return_if_fail (UNITY_GTK_IS_MENU_ITEM (item));
374
375 if (item->second_label != NULL)
376 {
377 g_signal_handlers_disconnect_by_data (item->second_label, item);
378 item->second_label = NULL;
379 }
380
381 if (item->first_label != NULL)
382 {
383 g_signal_handlers_disconnect_by_data (item->first_label, item);
384 item->first_label = NULL;
385 }
386}
387
388static gboolean
389unity_gtk_menu_item_connect_labels (UnityGtkMenuItem *item)
390{
391 GtkLabel *first_label = NULL;
392 GtkLabel *second_label = NULL;
393
394 g_return_val_if_fail (UNITY_GTK_IS_MENU_ITEM (item), FALSE);
395
396 if (item->menu_item != NULL)
397 {
398 /* ensure label is available */
399 gtk_menu_item_get_label (item->menu_item);
400
401 first_label = gtk_menu_item_get_nth_label (item->menu_item, 0);
402 second_label = gtk_menu_item_get_nth_label (item->menu_item, 1);
403 }
404
405 if (first_label != item->first_label || second_label != item->second_label)
406 {
407 unity_gtk_menu_item_disconnect_labels (item);
408
409 item->first_label = first_label;
410 item->second_label = second_label;
411
412 if (item->first_label != NULL)
413 g_signal_connect (item->first_label, "notify", G_CALLBACK (unity_gtk_menu_item_handle_label_notify), item);
414 if (item->second_label != NULL)
415 g_signal_connect (item->second_label, "notify", G_CALLBACK (unity_gtk_menu_item_handle_label_notify), item);
416
417 return TRUE;
418 }
419
420 return FALSE;
421}
422
423static void
424unity_gtk_menu_item_handle_add_or_remove (GtkContainer *container,
425 GtkWidget *widget,
426 gpointer user_data)
427{
428 UnityGtkMenuItem *item;
429
430 g_return_if_fail (UNITY_GTK_IS_MENU_ITEM (user_data));
431
432 item = UNITY_GTK_MENU_ITEM (user_data);
433
434 /* just ignore the case when parent_shell is NULL */
435 if (item->parent_shell != NULL && unity_gtk_menu_item_connect_labels (item))
436 unity_gtk_menu_shell_handle_item_notify (item->parent_shell, item, "label");
437}
438
439static void
371unity_gtk_menu_item_handle_accel_closures_changed (GtkWidget *widget,440unity_gtk_menu_item_handle_accel_closures_changed (GtkWidget *widget,
372 gpointer user_data)441 gpointer user_data)
373{442{
@@ -388,23 +457,16 @@
388unity_gtk_menu_item_set_menu_item (UnityGtkMenuItem *item,457unity_gtk_menu_item_set_menu_item (UnityGtkMenuItem *item,
389 GtkMenuItem *menu_item)458 GtkMenuItem *menu_item)
390{459{
391 GtkLabel *label;
392
393 g_return_if_fail (UNITY_GTK_IS_MENU_ITEM (item));460 g_return_if_fail (UNITY_GTK_IS_MENU_ITEM (item));
394461
395 if (menu_item != item->menu_item)462 if (menu_item != item->menu_item)
396 {463 {
397 UnityGtkMenuShell *child_shell = item->child_shell;464 UnityGtkMenuShell *child_shell = item->child_shell;
398465
466 unity_gtk_menu_item_disconnect_labels (item);
467
399 if (item->menu_item != NULL)468 if (item->menu_item != NULL)
400 {469 g_signal_handlers_disconnect_by_data (item->menu_item, item);
401 label = gtk_menu_item_get_nth_label (item->menu_item, 0);
402
403 if (label != NULL)
404 g_signal_handlers_disconnect_by_data (label, item);
405
406 g_signal_handlers_disconnect_by_data (item->menu_item, item);
407 }
408470
409 if (child_shell != NULL)471 if (child_shell != NULL)
410 {472 {
@@ -419,20 +481,20 @@
419 if (menu_item != NULL)481 if (menu_item != NULL)
420 {482 {
421 g_signal_connect (menu_item, "notify", G_CALLBACK (unity_gtk_menu_item_handle_item_notify), item);483 g_signal_connect (menu_item, "notify", G_CALLBACK (unity_gtk_menu_item_handle_item_notify), item);
422484 g_signal_connect (menu_item, "add", G_CALLBACK (unity_gtk_menu_item_handle_add_or_remove), item);
423 /* ensure label is available */485 g_signal_connect (menu_item, "remove", G_CALLBACK (unity_gtk_menu_item_handle_add_or_remove), item);
424 gtk_menu_item_get_label (menu_item);
425 label = gtk_menu_item_get_nth_label (menu_item, 0);
426
427 if (label != NULL)
428 g_signal_connect (label, "notify", G_CALLBACK (unity_gtk_menu_item_handle_label_notify), item);
429
430 g_signal_connect (menu_item, "accel-closures-changed", G_CALLBACK (unity_gtk_menu_item_handle_accel_closures_changed), item);486 g_signal_connect (menu_item, "accel-closures-changed", G_CALLBACK (unity_gtk_menu_item_handle_accel_closures_changed), item);
431487
432 /* LP: #1208019 */488 /*
489 * LP: #1208019: We do this because Eclipse sets menu item
490 * accelerators using private API, and there's no way for us to
491 * detect when they change.
492 */
433 if (gtk_menu_item_get_submenu (menu_item) != NULL)493 if (gtk_menu_item_get_submenu (menu_item) != NULL)
434 g_signal_emit_by_name (gtk_menu_item_get_submenu (menu_item), "show");494 g_signal_emit_by_name (gtk_menu_item_get_submenu (menu_item), "show");
435 }495 }
496
497 unity_gtk_menu_item_connect_labels (item);
436 }498 }
437}499}
438500
@@ -470,8 +532,8 @@
470532
471 item = UNITY_GTK_MENU_ITEM (object);533 item = UNITY_GTK_MENU_ITEM (object);
472534
473 g_free (item->label);535 g_free (item->label_label);
474 item->label = NULL;536 item->label_label = NULL;
475537
476 G_OBJECT_CLASS (unity_gtk_menu_item_parent_class)->finalize (object);538 G_OBJECT_CLASS (unity_gtk_menu_item_parent_class)->finalize (object);
477}539}
@@ -661,7 +723,7 @@
661 g_return_val_if_fail (UNITY_GTK_IS_MENU_ITEM (item), NULL);723 g_return_val_if_fail (UNITY_GTK_IS_MENU_ITEM (item), NULL);
662 g_return_val_if_fail (item->menu_item != NULL, NULL);724 g_return_val_if_fail (item->menu_item != NULL, NULL);
663725
664 if (item->label == NULL)726 if (item->label_label == NULL)
665 {727 {
666 const gchar *label_label = gtk_menu_item_get_label (item->menu_item);728 const gchar *label_label = gtk_menu_item_get_label (item->menu_item);
667729
@@ -691,16 +753,16 @@
691 if (gtk_label_get_use_underline (label))753 if (gtk_label_get_use_underline (label))
692 {754 {
693 if (item->parent_shell == NULL || item->parent_shell->has_mnemonics)755 if (item->parent_shell == NULL || item->parent_shell->has_mnemonics)
694 item->label = g_strdup (label_label);756 item->label_label = g_strdup (label_label);
695 else757 else
696 item->label = g_strdup_no_mnemonics (label_label);758 item->label_label = g_strdup_no_mnemonics (label_label);
697 }759 }
698 else760 else
699 item->label = g_strdup_escape_underscores (label_label);761 item->label_label = g_strdup_escape_underscores (label_label);
700 }762 }
701 }763 }
702764
703 return item->label;765 return item->label_label;
704}766}
705767
706GIcon *768GIcon *
707769
=== modified file 'lib/unity-gtk-menu-section.c'
--- lib/unity-gtk-menu-section.c 2014-03-31 00:40:48 +0000
+++ lib/unity-gtk-menu-section.c 2014-06-26 14:42:27 +0000
@@ -27,6 +27,10 @@
27#define G_MENU_ATTRIBUTE_ACCEL_TEXT "x-canonical-accel"27#define G_MENU_ATTRIBUTE_ACCEL_TEXT "x-canonical-accel"
28#endif28#endif
2929
30#ifndef G_MENU_ATTRIBUTE_SUBMENU_ACTION
31#define G_MENU_ATTRIBUTE_SUBMENU_ACTION "submenu-action"
32#endif
33
30G_DEFINE_TYPE (UnityGtkMenuSection,34G_DEFINE_TYPE (UnityGtkMenuSection,
31 unity_gtk_menu_section,35 unity_gtk_menu_section,
32 G_TYPE_MENU_MODEL);36 G_TYPE_MENU_MODEL);
@@ -136,32 +140,43 @@
136 g_object_unref (icon);140 g_object_unref (icon);
137 }141 }
138142
139 if (action != NULL && action->name != NULL)143 if (action != NULL)
140 {144 {
141 gchar *name = g_strdup_printf ("unity.%s", action->name);145 if (action->name != NULL)
142 GVariant *variant = g_variant_ref_sink (g_variant_new_string (name));146 {
143147 gchar *name = g_strdup_printf ("unity.%s", action->name);
144 g_hash_table_insert (*attributes, G_MENU_ATTRIBUTE_ACTION, variant);148 GVariant *variant = g_variant_ref_sink (g_variant_new_string (name));
145149
146 if (action->items_by_name != NULL)150 g_hash_table_insert (*attributes, G_MENU_ATTRIBUTE_ACTION, variant);
147 {151
148 GHashTableIter iter;152 if (action->items_by_name != NULL)
149 gpointer key;153 {
150 gpointer value;154 GHashTableIter iter;
151 const gchar *target = NULL;155 gpointer key;
152156 gpointer value;
153 g_hash_table_iter_init (&iter, action->items_by_name);157 const gchar *target = NULL;
154 while (target == NULL && g_hash_table_iter_next (&iter, &key, &value))158
155 if (value == item)159 g_hash_table_iter_init (&iter, action->items_by_name);
156 target = key;160 while (target == NULL && g_hash_table_iter_next (&iter, &key, &value))
157161 if (value == item)
158 if (target != NULL)162 target = key;
159 g_hash_table_insert (*attributes, G_MENU_ATTRIBUTE_TARGET, g_variant_ref_sink (g_variant_new_string (target)));163
160 }164 if (target != NULL)
161 else if (unity_gtk_menu_item_get_draw_as_radio (item))165 g_hash_table_insert (*attributes, G_MENU_ATTRIBUTE_TARGET, g_variant_ref_sink (g_variant_new_string (target)));
162 g_hash_table_insert (*attributes, G_MENU_ATTRIBUTE_TARGET, g_variant_ref_sink (g_variant_new_string (action->name)));166 }
163167 else if (unity_gtk_menu_item_get_draw_as_radio (item))
164 g_free (name);168 g_hash_table_insert (*attributes, G_MENU_ATTRIBUTE_TARGET, g_variant_ref_sink (g_variant_new_string (action->name)));
169
170 g_free (name);
171 }
172
173 if (action->subname != NULL)
174 {
175 gchar *subname = g_strdup_printf ("unity.%s", action->subname);
176 GVariant *variant = g_variant_ref_sink (g_variant_new_string (subname));
177 g_hash_table_insert (*attributes, G_MENU_ATTRIBUTE_SUBMENU_ACTION, variant);
178 g_free (subname);
179 }
165 }180 }
166181
167 if (item->menu_item != NULL)182 if (item->menu_item != NULL)
168183
=== modified file 'lib/unity-gtk-menu-shell.c'
--- lib/unity-gtk-menu-shell.c 2014-03-27 19:52:20 +0000
+++ lib/unity-gtk-menu-shell.c 2014-06-26 14:42:27 +0000
@@ -449,8 +449,8 @@
449 g_return_if_fail (UNITY_GTK_IS_MENU_ITEM (item));449 g_return_if_fail (UNITY_GTK_IS_MENU_ITEM (item));
450 g_warn_if_fail (item->parent_shell == shell);450 g_warn_if_fail (item->parent_shell == shell);
451451
452 g_free (item->label);452 g_free (item->label_label);
453 item->label = NULL;453 item->label_label = NULL;
454454
455 unity_gtk_menu_shell_update_item (shell, item);455 unity_gtk_menu_shell_update_item (shell, item);
456}456}
@@ -582,6 +582,13 @@
582 g_return_if_fail (UNITY_GTK_IS_MENU_ITEM (item));582 g_return_if_fail (UNITY_GTK_IS_MENU_ITEM (item));
583 g_warn_if_fail (item->parent_shell == shell);583 g_warn_if_fail (item->parent_shell == shell);
584584
585 if (shell->action_group != NULL)
586 {
587 /* If a submenu was added or removed, we need to update the submenu action. */
588 unity_gtk_action_group_disconnect_item (shell->action_group, item);
589 unity_gtk_action_group_connect_item (shell->action_group, item);
590 }
591
585 if (item->child_shell_valid)592 if (item->child_shell_valid)
586 {593 {
587 GtkMenuShell *old_submenu = item->child_shell != NULL ? item->child_shell->menu_shell : NULL;594 GtkMenuShell *old_submenu = item->child_shell != NULL ? item->child_shell->menu_shell : NULL;

Subscribers

People subscribed via source and target branches