Advertisement
Guest User

ubuntu_gtk_custom_menu_items.patch for gtk3-git

a guest
Apr 3rd, 2014
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 3.60 KB | None | 0 0
  1. # Description: gtk_menu_new_from_model doesn't support custom menu items
  2. # Ubuntu: https://bugs.launchpad.net/ubuntu/+source/gtk+3.0/+bug/1039476
  3. #
  4. diff --git a/gtk/gtkmodelmenu.c b/gtk/gtkmodelmenu.c
  5. index dccf72a..4574e64 100644
  6. --- a/gtk/gtkmodelmenu.c
  7. +++ b/gtk/gtkmodelmenu.c
  8. @@ -28,6 +28,7 @@
  9.  #include "config.h"
  10.  
  11.  #include "gtkmenutracker.h"
  12. +#include "gtkwidgetprivate.h"
  13.  
  14.  /*< private >
  15.   * SECTION:gtkmenutracker
  16. @@ -73,6 +74,80 @@ gtk_model_menu_binding_free (gpointer data)
  17.    g_slice_free (GtkMenuTrackerSection, section);
  18.  }
  19.  
  20. +static GtkMenuItem *
  21. +gtk_menu_tracker_create_custom_item (GMenuModel  *menu,
  22. +                                   gint         item_index,
  23. +                                   const gchar *action_namespace)
  24. +{
  25. +  GtkMenuItem *item = NULL;
  26. +  gchar *typename = NULL;
  27. +  GType type;
  28. +  GObjectClass *class = NULL;
  29. +  GParamSpec *pspec;
  30. +  GMenuItem *menuitem = NULL;
  31. +
  32. +  if (!g_menu_model_get_item_attribute (menu, item_index, "x-canonical-type", "s", &typename))
  33. +      return NULL;
  34. +
  35. +  type = g_type_from_name (typename);
  36. +  if (type == 0)
  37. +    {
  38. +      g_warning ("gtk_menu_new_from_model: cannot find type '%s'", typename);
  39. +      goto out;
  40. +    }
  41. +  if (!g_type_is_a (type, GTK_TYPE_MENU_ITEM))
  42. +    {
  43. +      g_warning ("gtk_menu_new_from_model: '%s' is not derived from GtkMenuItem", typename);
  44. +      goto out;
  45. +    }
  46. +
  47. +  class = g_type_class_ref (type);
  48. +
  49. +  pspec = g_object_class_find_property (class, "menu-item");
  50. +  if (pspec == NULL || G_PARAM_SPEC_VALUE_TYPE (pspec) != G_TYPE_MENU_ITEM)
  51. +    {
  52. +      g_warning ("gtk_menu_new_from_model: '%s' does not have a 'menu-item' property", typename);
  53. +      goto out;
  54. +    }
  55. +
  56. +  pspec = g_object_class_find_property (class, "action-group");
  57. +  if (pspec == NULL || G_PARAM_SPEC_VALUE_TYPE (pspec) != G_TYPE_ACTION_GROUP)
  58. +    {
  59. +      g_warning ("gtk_menu_new_from_model: '%s' does not have an 'action-group' property", typename);
  60. +      goto out;
  61. +    }
  62. +
  63. +  menuitem = g_menu_item_new_from_model (menu, item_index);
  64. +  if (action_namespace)
  65. +    {
  66. +      gchar *action;
  67. +      gchar *fullname;
  68. +
  69. +      g_menu_item_get_attribute (menuitem, G_MENU_ATTRIBUTE_ACTION, "s", &action);
  70. +      fullname = g_strconcat (action_namespace, ".", action, NULL);
  71. +      g_menu_item_set_attribute (menuitem, G_MENU_ATTRIBUTE_ACTION, "s", fullname);
  72. +
  73. +      g_free (action);
  74. +      g_free (fullname);
  75. +    }
  76. +
  77. +  item = g_object_new (type,
  78. +                       "menu-item", menuitem,
  79. +                       NULL);
  80. +
  81. +  g_object_set (item,
  82. +                "action-group", _gtk_widget_get_action_muxer (GTK_WIDGET (item)),
  83. +                NULL);
  84. +
  85. +out:
  86. +  if (menuitem)
  87. +    g_object_unref (menuitem);
  88. +  if (class)
  89. +    g_type_class_unref (class);
  90. +  g_free (typename);
  91. +  return item;
  92. +}
  93. +
  94.  static GtkMenuTrackerSection *
  95.  gtk_menu_tracker_section_new (GtkMenuTracker *tracker,
  96.                                GMenuModel     *model,
  97. @@ -107,7 +182,10 @@ gtk_model_menu_binding_append_item (GtkModelMenuBinding  *binding,
  98.      {
  99.        GtkMenuItem *item;
  100.  
  101. -          item = _gtk_menu_tracker_item_new (tracker->observable, model, position + n_items,
  102. -                                             section->action_namespace, FALSE);
  103. +          item = _gtk_menu_traker_create_custom_item (model, item_index, action_namespace);
  104. +      if (item == NULL)
  105. +            item = _gtk_menu_tracker_item_new (tracker->observable, model, position + n_items,
  106. +
  107.        gtk_menu_shell_append (binding->shell, GTK_WIDGET (item));
  108.        gtk_widget_show (GTK_WIDGET (item));
  109.        binding->n_items++;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement