Since placeholder are added everywhere we would have to create the
packing actions list in notify::parent and make sure the actions
implementations work without a gladewidget.
Packing actions implemented so far can work with placeholders but there
is no way to tell if future actions will, so i guess we would need some
way to differentiate normal packing actions with the packing actions
that can work with a placeholder, maybe a simple flag can do the trick
so...
* notify::parent is to hackish but its probably the easiest way to do it
otherwise we would have to have GladeWidget for placeholders, rigth?¿
or at least the placeholder would need a parent property (GladeWidget)
anyway we would need to change how placeholder are created, packed
etc :S
well... i have started writing nonsese!... again! :P
anyway, this is a little patch showing all this hack!
Index: plugins/gtk+/glade-gtk.c
===================================================================
--- plugins/gtk+/glade-gtk.c (revision 1335)
+++ plugins/gtk+/glade-gtk.c (working copy)
@@ -1031,10 +1031,12 @@ glade_gtk_box_notebook_child_insert_acti
GList *children, *l;
gint child_pos, size;
- widget = glade_widget_get_from_gobject (object);
- glade_widget_pack_property_get (widget, "position", &child_pos);
+ gtk_container_child_get (GTK_CONTAINER (container),
+ GTK_WIDGET (object),
+ "position", &child_pos, NULL);
- glade_command_push_group (group_format, glade_widget_get_name (widget));
+ widget = glade_widget_get_from_gobject (object);
+ glade_command_push_group (group_format, (widget) ? glade_widget_get_name (widget) : "placeholder");
children = glade_widget_adaptor_get_children (adaptor, container);
/* Make sure widgets does not get destroyed */
@@ -1912,10 +1914,12 @@ glade_gtk_table_child_insert_action (Gla
GList *children, *l;
gint child_pos, size;
- widget = glade_widget_get_from_gobject (object);
- glade_widget_pack_property_get (widget, attach1, &child_pos);
+ gtk_container_child_get (GTK_CONTAINER (container),
+ GTK_WIDGET (object),
+ attach1, &child_pos, NULL);
- glade_command_push_group (group_format, glade_widget_get_name (widget));
+ widget = glade_widget_get_from_gobject (object);
+ glade_command_push_group (group_format, (widget) ? glade_widget_get_name (widget) : "placeholder");
children = glade_widget_adaptor_get_children (adaptor, container);
/* Make sure widgets does not get destroyed */
Index: gladeui/glade-popup.c
===================================================================
--- gladeui/glade-popup.c (revision 1334)
+++ gladeui/glade-popup.c (working copy)
@@ -180,7 +180,7 @@ glade_popup_menuitem_activated (GtkMenuI
{
GladeWidget *widget;
- if ((widget = g_object_get_data (G_OBJECT (item), "glade-widget")))
+ if ((widget = g_object_get_data (G_OBJECT (item), "gwa-data")))
glade_widget_adaptor_action_activate (widget->adaptor,
widget->object,
action_path);
@@ -191,26 +191,40 @@ glade_popup_menuitem_packing_activated (
{
GladeWidget *widget;
- if ((widget = g_object_get_data (G_OBJECT (item), "glade-widget")))
+ if ((widget = g_object_get_data (G_OBJECT (item), "gwa-data")))
glade_widget_adaptor_child_action_activate (widget->parent->adaptor,
widget->parent->object,
widget->object,
action_path);
}
+static void
+glade_popup_menuitem_ph_packing_activated (GtkMenuItem *item, const gchar *action_path)
+{
+ GladePlaceholder *ph;
+ GladeWidget *parent;
+
+ if ((ph = g_object_get_data (G_OBJECT (item), "gwa-data")))
+ {
+ parent = glade_placeholder_get_parent (ph);
+ glade_widget_adaptor_child_action_activate (parent->adaptor,
+ parent->object,
+ G_OBJECT (ph),
+ action_path);
+ }
+}
+
static gint
glade_popup_action_populate_menu_real (GtkWidget *menu,
- GladeWidget *widget,
- GladeWidgetAction *action,
- gboolean packing)
+ GList *actions,
+ GCallback callback,
+ gpointer data)
{
GtkWidget *item;
GList *list;
gint n = 0;
- for (list = (action) ? action->actions : (packing) ? widget->packing_actions : widget->actions;
- list;
- list = g_list_next (list))
+ for (list = actions; list; list = g_list_next (list))
{
GladeWidgetAction *a = list->data;
GtkWidget *submenu = NULL;
@@ -218,18 +232,19 @@ glade_popup_action_populate_menu_real (G
if (a->actions)
{
submenu = gtk_menu_new ();
- n += glade_popup_action_populate_menu_real (submenu, widget, a, packing);
+ n += glade_popup_action_populate_menu_real (submenu,
+ a->actions,
+ callback,
+ data);
}
item = glade_popup_append_item (menu,
- a->klass->stock,
- a->klass->label, TRUE,
- (a->actions) ? NULL : (packing)
- ? glade_popup_menuitem_packing_activated
- : glade_popup_menuitem_activated,
- (a->actions) ? NULL : a->klass->path);
+ a->klass->stock,
+ a->klass->label, TRUE,
+ (a->actions) ? NULL : callback,
+ (a->actions) ? NULL : a->klass->path);
- g_object_set_data (G_OBJECT (item), "glade-widget", widget);
+ g_object_set_data (G_OBJECT (item), "gwa-data", data);
gtk_widget_set_sensitive (item, a->sensitive);
if (submenu)
@@ -265,15 +280,24 @@ glade_popup_action_populate_menu (GtkWid
{
g_return_val_if_fail (GLADE_IS_WIDGET_ACTION (action), 0);
if (glade_widget_get_action (widget, action->klass->path))
- return glade_popup_action_populate_menu_real (menu, widget, action, FALSE);
+ return glade_popup_action_populate_menu_real (menu,
+ action->actions,
+ G_CALLBACK (glade_popup_menuitem_activated),
+ widget);
if (glade_widget_get_pack_action (widget, action->klass->path))
- return glade_popup_action_populate_menu_real (menu, widget, action, TRUE);
-
+ return glade_popup_action_populate_menu_real (menu,
+ action->actions,
+ G_CALLBACK (glade_popup_menuitem_packing_activated),
+ widget);
+
return 0;
}
- n = glade_popup_action_populate_menu_real (menu, widget, action, FALSE);
+ n = glade_popup_action_populate_menu_real (menu,
+ widget->actions,
+ G_CALLBACK (glade_popup_menuitem_activated),
+ widget);
if (widget->packing_actions)
{
@@ -283,7 +307,10 @@ glade_popup_action_populate_menu (GtkWid
gtk_menu_shell_append (GTK_MENU_SHELL (menu), separator);
gtk_widget_show (separator);
}
- n += glade_popup_action_populate_menu_real (menu, widget, action, TRUE);
+ n += glade_popup_action_populate_menu_real (menu,
+ widget->packing_actions,
+ G_CALLBACK (glade_popup_menuitem_packing_activated),
+ widget);
}
return n;
@@ -335,6 +362,18 @@ glade_popup_create_placeholder_menu (Gla
glade_popup_append_item (popup_menu, GTK_STOCK_PASTE, NULL, sensitive,
glade_popup_placeholder_paste_cb, placeholder);
+ if (placeholder->packing_actions)
+ {
+ GtkWidget *separator = gtk_menu_item_new ();
+ gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), separator);
+ gtk_widget_show (separator);
+
+ glade_popup_action_populate_menu_real (popup_menu,
+ placeholder->packing_actions,
+ G_CALLBACK (glade_popup_menuitem_ph_packing_activated),
+ placeholder);
+ }
+
return popup_menu;
}
Index: gladeui/glade-widget.c
===================================================================
--- gladeui/glade-widget.c (revision 1334)
+++ gladeui/glade-widget.c (working copy)
@@ -112,8 +112,6 @@ static GQuark glade_widget_name_q
static void
glade_widget_set_packing_actions (GladeWidget *widget, GladeWidget *parent)
{
- GList *l;
-
if (widget->packing_actions)
{
g_list_foreach (widget->packing_actions, (GFunc)g_object_unref, NULL);
@@ -121,16 +119,8 @@ glade_widget_set_packing_actions (GladeW
widget->packing_actions = NULL;
}
- for (l = parent->adaptor->packing_actions; l; l = g_list_next (l))
- {
- GWActionClass *action = l->data;
- GObject *obj = g_object_new (GLADE_TYPE_WIDGET_ACTION,
- "class", action, NULL);
-
- widget->packing_actions = g_list_prepend (widget->packing_actions,
- GLADE_WIDGET_ACTION (obj));
- }
- widget->packing_actions = g_list_reverse (widget->packing_actions);
+ if (parent->adaptor->packing_actions)
+ widget->packing_actions = glade_widget_adaptor_pack_actions_new (parent->adaptor);
}
static void
Index: gladeui/glade-widget-adaptor.c
===================================================================
--- gladeui/glade-widget-adaptor.c (revision 1334)
+++ gladeui/glade-widget-adaptor.c (working copy)
@@ -2572,6 +2572,33 @@ glade_widget_adaptor_pack_action_remove
action_path);
}
+
+/**
+ * glade_widget_adaptor_pack_actions_new:
+ * @adaptor: A #GladeWidgetAdaptor
+ *
+ * Create a list of packing actions.
+ *
+ * Returns: a new list of GladeWidgetAction.
+ */
+GList *
+glade_widget_adaptor_pack_actions_new (GladeWidgetAdaptor *adaptor)
+{
+ GList *l, *list = NULL;
+
+ g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL);
+
+ for (l = adaptor->packing_actions; l; l = g_list_next (l))
+ {
+ GWActionClass *action = l->data;
+ GObject *obj = g_object_new (GLADE_TYPE_WIDGET_ACTION,
+ "class", action, NULL);
+
+ list = g_list_prepend (list, GLADE_WIDGET_ACTION (obj));
+ }
+ return g_list_reverse (list);
+}
+
/**
* glade_widget_adaptor_action_activate:
* @adaptor: A #GladeWidgetAdaptor
Index: gladeui/glade-widget-adaptor.h
===================================================================
--- gladeui/glade-widget-adaptor.h (revision 1334)
+++ gladeui/glade-widget-adaptor.h (working copy)
@@ -608,6 +608,8 @@ gboolean glade_widget_adapto
gboolean glade_widget_adaptor_pack_action_remove (GladeWidgetAdaptor *adaptor,
const gchar *action_path);
+GList *glade_widget_adaptor_pack_actions_new (GladeWidgetAdaptor *adaptor);
+
void glade_widget_adaptor_action_activate (GladeWidgetAdaptor *adaptor,
GObject *object,
const gchar *action_path);
Index: gladeui/glade-placeholder.c
===================================================================
--- gladeui/glade-placeholder.c (revision 1334)
+++ gladeui/glade-placeholder.c (working copy)
@@ -120,9 +120,29 @@ glade_placeholder_class_init (GladePlace
}
static void
+glade_placeholder_notify_parent (GObject *gobject,
+ GParamSpec *arg1,
+ gpointer user_data)
+{
+ GladePlaceholder *placeholder = GLADE_PLACEHOLDER (gobject);
+ GladeWidget *parent = glade_placeholder_get_parent (placeholder);
+
+ if (placeholder->packing_actions)
+ {
+ g_list_foreach (placeholder->packing_actions, (GFunc)g_object_unref, NULL);
+ g_list_free (placeholder->packing_actions);
+ placeholder->packing_actions = NULL;
+ }
+
+ if (parent && parent->adaptor->packing_actions)
+ placeholder->packing_actions = glade_widget_adaptor_pack_actions_new (parent->adaptor);
+}
+
+static void
glade_placeholder_init (GladePlaceholder *placeholder)
{
placeholder->placeholder_pixmap = NULL;
+ placeholder->packing_actions = NULL;
GTK_WIDGET_SET_FLAGS (GTK_WIDGET (placeholder), GTK_CAN_FOCUS);
@@ -130,6 +150,10 @@ glade_placeholder_init (GladePlaceholder
GLADE_PLACEHOLDER_WIDTH_REQ,
GLADE_PLACEHOLDER_HEIGHT_REQ);
+ g_signal_connect (placeholder, "notify::parent",
+ G_CALLBACK (glade_placeholder_notify_parent),
+ NULL);
+
gtk_widget_show (GTK_WIDGET (placeholder));
}
@@ -157,6 +181,12 @@ glade_placeholder_finalize (GObject *obj
if (placeholder->placeholder_pixmap)
g_object_unref (placeholder->placeholder_pixmap);
+ if (placeholder->packing_actions)
+ {
+ g_list_foreach (placeholder->packing_actions, (GFunc)g_object_unref, NULL);
+ g_list_free (placeholder->packing_actions);
+ }
+
G_OBJECT_CLASS (parent_class)->finalize (object);
}
Index: gladeui/glade-placeholder.h
===================================================================
--- gladeui/glade-placeholder.h (revision 1334)
+++ gladeui/glade-placeholder.h (working copy)
@@ -26,6 +26,8 @@ struct _GladePlaceholder
GtkWidget widget;
GdkPixmap *placeholder_pixmap;
+
+ GList *packing_actions;
};
struct _GladePlaceholderClass
_______________________________________________
Glade-devel maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/glade-devel