Commit b702dbfa authored by Juan Pablo Ugarte's avatar Juan Pablo Ugarte

added packing action list to GladePlaceholder

* gladeui/glade-placeholder.[ch]: added packing action list to GladePlaceholder

* gladeui/glade-popup.c: added packing actions to placeholder popup

* gladeui/glade-widget-adaptor.[ch]: added glade_widget_adaptor_pack_actions_new ()

* gladeui/glade-widget.c: use new function glade_widget_adaptor_pack_actions_new () in
  glade_widget_set_packing_actions()

* plugins/gtk+/glade-gtk.c: take into acount placeholders get paking actions
  glade_gtk_box_notebook_child_insert_action() and glade_gtk_table_child_insert_action() fixed.

svn path=/trunk/; revision=1339
parent 69e8c4c4
2007-06-06 Juan Pablo Ugarte <juanpablougarte@gmail.com>
* gladeui/glade-placeholder.[ch]: added packing action list to GladePlaceholder
* gladeui/glade-popup.c: added packing actions to placeholder popup
* gladeui/glade-widget-adaptor.[ch]: added glade_widget_adaptor_pack_actions_new ()
* gladeui/glade-widget.c: use new function glade_widget_adaptor_pack_actions_new () in
glade_widget_set_packing_actions()
* plugins/gtk+/glade-gtk.c: take into acount placeholders get paking actions
glade_gtk_box_notebook_child_insert_action() and glade_gtk_table_child_insert_action() fixed.
* gladeui/glade-app.[ch], gladeui/Makefile.am: removed every reference to
binding script directory. (bug #444605)
......
......@@ -119,10 +119,30 @@ glade_placeholder_class_init (GladePlaceholderClass *klass)
widget_class->popup_menu = glade_placeholder_popup_menu;
}
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 *placeholder)
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 *object)
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);
}
......
......@@ -26,6 +26,8 @@ struct _GladePlaceholder
GtkWidget widget;
GdkPixmap *placeholder_pixmap;
GList *packing_actions;
};
struct _GladePlaceholderClass
......
......@@ -180,7 +180,7 @@ glade_popup_menuitem_activated (GtkMenuItem *item, const gchar *action_path)
{
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 (GtkMenuItem *item, const gchar *action_p
{
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 (GtkWidget *menu,
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 (GtkWidget *menu,
{
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 (GtkWidget *menu,
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 (GladePlaceholder *placeholder)
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;
}
......
......@@ -2572,6 +2572,33 @@ glade_widget_adaptor_pack_action_remove (GladeWidgetAdaptor *adaptor,
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
......
......@@ -608,6 +608,8 @@ gboolean glade_widget_adaptor_action_remove (GladeWidgetAdaptor
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);
......
......@@ -112,8 +112,6 @@ static GQuark glade_widget_name_quark = 0;
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 (GladeWidget *widget, GladeWidget *parent)
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
......
......@@ -1027,21 +1027,22 @@ glade_gtk_box_notebook_child_insert_action (GladeWidgetAdaptor *adaptor,
const gchar *group_format,
gboolean after)
{
GladeWidget *parent, *widget;
GladeWidget *parent;
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));
parent = glade_widget_get_from_gobject (container);
glade_command_push_group (group_format, glade_widget_get_name (parent));
children = glade_widget_adaptor_get_children (adaptor, container);
/* Make sure widgets does not get destroyed */
g_list_foreach (children, (GFunc) g_object_ref, NULL);
/* Expand container */
parent = glade_widget_get_from_gobject (container);
glade_widget_property_get (parent, size_prop, &size);
glade_command_set_property (glade_widget_get_property (parent, size_prop),
size + 1);
......@@ -1076,14 +1077,14 @@ glade_gtk_box_child_action_activate (GladeWidgetAdaptor *adaptor,
{
glade_gtk_box_notebook_child_insert_action (adaptor, container,
object, "size",
_("Insert after widget %s"),
_("Insert placeholder to %s"),
TRUE);
}
else if (strcmp (action_path, "insert_before") == 0)
{
glade_gtk_box_notebook_child_insert_action (adaptor, container,
object, "size",
_("Insert before widget %s"),
_("Insert placeholder to %s"),
FALSE);
}
else
......@@ -1908,21 +1909,22 @@ glade_gtk_table_child_insert_action (GladeWidgetAdaptor *adaptor,
const gchar *attach2,
gboolean after)
{
GladeWidget *parent, *widget;
GladeWidget *parent;
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));
parent = glade_widget_get_from_gobject (container);
glade_command_push_group (group_format, glade_widget_get_name (parent));
children = glade_widget_adaptor_get_children (adaptor, container);
/* Make sure widgets does not get destroyed */
g_list_foreach (children, (GFunc) g_object_ref, NULL);
/* Expand the table */
parent = glade_widget_get_from_gobject (container);
glade_widget_property_get (parent, n_row_col, &size);
glade_command_set_property (glade_widget_get_property (parent, n_row_col),
size + 1);
......@@ -1962,28 +1964,28 @@ glade_gtk_table_child_action_activate (GladeWidgetAdaptor *adaptor,
if (strcmp (action_path, "insert_row/after") == 0)
{
glade_gtk_table_child_insert_action (adaptor, container, object,
_("Insert Row after widget %s"),
_("Insert Row on %s"),
"n-rows","top-attach",
"bottom-attach", TRUE);
}
else if (strcmp (action_path, "insert_row/before") == 0)
{
glade_gtk_table_child_insert_action (adaptor, container, object,
_("Insert Row before widget %s"),
_("Insert Row on %s"),
"n-rows","top-attach",
"bottom-attach", FALSE);
}
else if (strcmp (action_path, "insert_column/after") == 0)
{
glade_gtk_table_child_insert_action (adaptor, container, object,
_("Insert Column after widget %s"),
_("Insert Column on %s"),
"n-columns","right-attach",
"left-attach", TRUE);
}
else if (strcmp (action_path, "insert_column/before") == 0)
{
glade_gtk_table_child_insert_action (adaptor, container, object,
_("Insert Column before widget %s"),
_("Insert Column on %s"),
"n-columns","right-attach",
"left-attach", FALSE);
}
......@@ -2795,14 +2797,14 @@ glade_gtk_notebook_child_action_activate (GladeWidgetAdaptor *adaptor,
{
glade_gtk_box_notebook_child_insert_action (adaptor, container,
object, "pages",
_("Insert page after widget %s"),
_("Insert page on %s"),
TRUE);
}
else if (strcmp (action_path, "insert_page_before") == 0)
{
glade_gtk_box_notebook_child_insert_action (adaptor, container,
object, "pages",
_("Insert page before widget %s"),
_("Insert page on %s"),
FALSE);
}
else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment