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

reworked glade_app_command_paste () placeholders can not be selected

* src/glade-app.c: reworked glade_app_command_paste () placeholders can
  not be selected anymore.

* src/glade-command.c: in glade_command_cut_copy_paste_common () we try
  to use the placeholder which has the pointer over it first.

* src/glade-fixed.[ch]: add new property "use-placeholders".

* src/glade-gtk.c: set "use-placeholders" for GtkBox and GtkTable.

* src/glade-popup.c: reworked glade_popup_create_placeholder_menu () and
  glade_popup_placeholder_paste_cb (), placeholders do not get selected
  anymore.

* src/glade-utils.[ch] glade_util_selected_placeholder () removed,
  added glade_util_get_placeholder_from_pointer ().
parent 8caed58a
2006-08-08 Juan Pablo Ugarte <juanpablougarte@gmail.com>
* src/glade-app.c: reworked glade_app_command_paste () placeholders can
not be selected anymore.
* src/glade-command.c: in glade_command_cut_copy_paste_common () we try
to use the placeholder which has the pointer over it first.
* src/glade-fixed.[ch]: add new property "use-placeholders".
* src/glade-gtk.c: set "use-placeholders" for GtkBox and GtkTable.
* src/glade-popup.c: reworked glade_popup_create_placeholder_menu () and
glade_popup_placeholder_paste_cb (), placeholders do not get selected
anymore.
* src/glade-utils.[ch] glade_util_selected_placeholder () removed,
added glade_util_get_placeholder_from_pointer ().
2006-08-08 Vincent Geddes <vincent.geddes@gmail.com>
* src/glade-gtk.c: GtkDialog's main vbox now has 2 placeholders
......
......@@ -4,7 +4,6 @@ Tasks/Bugs Blocking glade-3 3.0:
================================
o Default notebook tab labels (bug 345438) (Tristan)
(We'll do a clean-up here... but not command recursion just yet).
o Unable to paste widget into other empty placeholder than the first one (bug 349494)
Wishlist items for 3.0 release:
===============================
......
......@@ -1070,10 +1070,9 @@ glade_app_command_paste (void)
GladeApp *app;
GladeClipboard *clipboard;
GList *list;
GladeWidget *widget = NULL;
GladeWidget *widget = NULL, *parent;
gint gtkcontainer_relations = 0;
GladePlaceholder *placeholder;
GladeWidget *parent;
GladeFixed *fixed = NULL;
app = glade_app_get();
if (app->priv->active_project == NULL)
......@@ -1082,21 +1081,17 @@ glade_app_command_paste (void)
list = glade_project_selection_get (app->priv->active_project);
clipboard = glade_app_get_clipboard ();
/* If there is a selection, dont use a placeholder to paste into */
placeholder = list ? NULL : glade_util_selected_placeholder ();
/* If there is a selection, paste in to the selected widget, otherwise
* paste into the placeholder's parent.
*/
parent = list ? glade_widget_get_from_gobject (list->data) :
(placeholder ? glade_placeholder_get_parent (placeholder) : NULL);
parent = list ? glade_widget_get_from_gobject (list->data) : NULL;
if (parent && GLADE_IS_FIXED (parent)) fixed = GLADE_FIXED (parent);
/* Check if selection is good */
if ((list = glade_app_get_selection ()) != NULL)
{
if (placeholder == NULL &&
g_list_length (list) != 1)
if (g_list_length (list) != 1)
{
glade_util_ui_message (glade_app_get_window(),
GLADE_UI_INFO,
......@@ -1146,7 +1141,7 @@ glade_app_command_paste (void)
/* Check that GladeFixed will cope...
*/
if (GTK_WIDGET_TOPLEVEL (widget->object) == FALSE &&
parent && GLADE_IS_FIXED (parent) &&
parent && fixed && fixed->use_placeholders == FALSE &&
gtkcontainer_relations != 1)
{
glade_util_ui_message (glade_app_get_window (),
......@@ -1157,7 +1152,7 @@ glade_app_command_paste (void)
}
/* Check that enough placeholders are available */
if (parent && GLADE_IS_FIXED (parent) == FALSE &&
if (parent && (fixed == NULL || fixed->use_placeholders) &&
glade_util_count_placeholders (parent) < gtkcontainer_relations)
{
glade_util_ui_message (glade_app_get_window (),
......@@ -1167,7 +1162,7 @@ glade_app_command_paste (void)
return;
}
glade_command_paste (clipboard->selection, parent, placeholder);
glade_command_paste (clipboard->selection, parent, NULL);
glade_app_update_ui ();
}
......
......@@ -1502,9 +1502,10 @@ glade_command_cut_copy_paste_common (GList *widgets,
{
GladeCommandCutCopyPaste *me;
CommandData *cdata;
GladeWidget *widget = NULL, *child;
GladeWidget *widget = NULL;
GList *l, *list, *children, *placeholders = NULL;
gchar *fmt = NULL;
GtkWidget *child;
g_return_if_fail (widgets && widgets->data);
g_return_if_fail (parent == NULL || GLADE_IS_WIDGET (parent));
......@@ -1591,8 +1592,17 @@ glade_command_cut_copy_paste_common (GList *widgets,
else if (type == GLADE_PASTE && cdata->parent &&
glade_util_gtkcontainer_relation (cdata->parent, widget))
{
if ((children = glade_widget_class_container_get_children
(cdata->parent->widget_class, cdata->parent->object)) != NULL)
GtkContainer *cont = GTK_CONTAINER (cdata->parent->object);
child = glade_util_get_placeholder_from_pointer (cont);
if (child && g_list_find (placeholders, child) == NULL)
{
placeholders = g_list_append (placeholders, child);
glade_command_placeholder_connect
(cdata, GLADE_PLACEHOLDER (child));
}
else if ((children = glade_widget_class_container_get_children
(cdata->parent->widget_class, cdata->parent->object)) != NULL)
{
for (l = children; l && l->data; l = l->next)
{
......
......@@ -45,7 +45,8 @@ enum {
PROP_Y_PROP,
PROP_WIDTH_PROP,
PROP_HEIGHT_PROP,
PROP_CAN_RESIZE
PROP_CAN_RESIZE,
PROP_USE_PLACEHOLDERS
};
/* signals */
......@@ -953,6 +954,9 @@ glade_fixed_set_property (GObject *object,
case PROP_CAN_RESIZE:
fixed->can_resize = g_value_get_boolean (value);
break;
case PROP_USE_PLACEHOLDERS:
fixed->use_placeholders = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
......@@ -969,11 +973,12 @@ glade_fixed_get_property (GObject *object,
switch (prop_id)
{
case PROP_X_PROP: g_value_set_string (value, fixed->x_prop); break;
case PROP_Y_PROP: g_value_set_string (value, fixed->y_prop); break;
case PROP_WIDTH_PROP: g_value_set_string (value, fixed->width_prop); break;
case PROP_HEIGHT_PROP: g_value_set_string (value, fixed->height_prop); break;
case PROP_CAN_RESIZE: g_value_set_boolean (value, fixed->can_resize); break;
case PROP_X_PROP: g_value_set_string (value, fixed->x_prop); break;
case PROP_Y_PROP: g_value_set_string (value, fixed->y_prop); break;
case PROP_WIDTH_PROP: g_value_set_string (value, fixed->width_prop); break;
case PROP_HEIGHT_PROP: g_value_set_string (value, fixed->height_prop); break;
case PROP_CAN_RESIZE: g_value_set_boolean (value, fixed->can_resize); break;
case PROP_USE_PLACEHOLDERS: g_value_set_boolean (value, fixed->use_placeholders); break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
......@@ -1051,6 +1056,12 @@ glade_fixed_class_init (GladeFixedClass *fixed_class)
_("Whether this container supports resizes of child widgets"),
TRUE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
g_object_class_install_property
(gobject_class, PROP_USE_PLACEHOLDERS,
g_param_spec_boolean
("use_placeholders", _("Use Placeholders"),
_("Whether this container use placeholders, the backend is responsable for setting up this property"),
FALSE, G_PARAM_READWRITE));
/**
* GladeFixed::configure-child:
......
......@@ -53,6 +53,7 @@ struct _GladeFixed {
gboolean can_resize; /* whether the container supports child resizes or only
* drags.
*/
gboolean use_placeholders;
/* State machine used to commit properties at the end
* of a drag or a resize (i.e. a "configure").
......
......@@ -556,7 +556,10 @@ glade_gtk_box_post_create (GObject *container, GladeCreateReason reason)
/* Implement drag in GtkBox but not resize.
*/
g_object_set (gwidget, "can-resize", FALSE, NULL);
g_object_set (gwidget,
"can-resize", FALSE,
"use-placeholders", TRUE,
NULL);
g_signal_connect (G_OBJECT (gwidget), "configure-child",
G_CALLBACK (glade_gtk_box_configure_child), container);
......@@ -1330,6 +1333,8 @@ glade_gtk_table_post_create (GObject *container, GladeCreateReason reason)
GladeWidget *gwidget =
glade_widget_get_from_gobject (container);
g_object_set (gwidget, "use-placeholders", TRUE, NULL);
g_signal_connect (G_OBJECT (gwidget), "configure-child",
G_CALLBACK (glade_gtk_table_configure_child), container);
......
......@@ -125,14 +125,14 @@ glade_popup_add_item_cb (GtkMenuItem *item,
PLACEHOLDER POPUP
*******************************************************/
static void
glade_popup_placeholder_paste_cb (GtkMenuItem *item,
GladePlaceholder *placeholder)
glade_popup_placeholder_paste_cb (GtkMenuItem *item,
GladeWidget *widget)
{
glade_util_clear_selection ();
glade_app_selection_clear (FALSE);
/* Set selection on the placeholder first */
glade_util_add_selection (GTK_WIDGET (placeholder));
/* Set selection on the placeholder's parent first */
glade_app_selection_set (widget->object, FALSE);
glade_app_command_paste ();
}
......@@ -308,14 +308,16 @@ glade_popup_create_placeholder_menu (GladePlaceholder *placeholder)
GladeWidget *parent;
gboolean sensitive;
if ((parent = glade_placeholder_get_parent (placeholder)) == NULL)
return NULL;
popup_menu = gtk_menu_new ();
sensitive = glade_clipboard_get_has_selection (glade_app_get_clipboard ());
glade_popup_append_item (popup_menu, GTK_STOCK_PASTE, NULL, sensitive,
glade_popup_placeholder_paste_cb, placeholder);
glade_popup_placeholder_paste_cb, parent);
if ((parent = glade_placeholder_get_parent(placeholder)) != NULL)
glade_popup_populate_childs(popup_menu, parent);
glade_popup_populate_childs(popup_menu, parent);
return popup_menu;
}
......
......@@ -949,22 +949,6 @@ glade_util_get_selection ()
return glade_util_selection;
}
/**
* glade_util_selected_placeholder:
*
* Returns: The selected placeholder, if there
* is only one selected item and that item is a placeholder.
*/
GladePlaceholder *
glade_util_selected_placeholder ()
{
if (g_list_length (glade_util_selection) == 1 &&
GLADE_IS_PLACEHOLDER (glade_util_selection->data))
return glade_util_selection->data;
return NULL;
}
/*
* taken from gtk... maybe someday we can convince them to
* expose gtk_container_get_all_children
......@@ -1775,3 +1759,37 @@ glade_util_deep_fixed_event (GtkWidget *widget,
return FALSE;
}
GtkWidget *
glade_util_get_placeholder_from_pointer (GtkContainer *container)
{
GtkWidget *retval = NULL, *child;
GList *c, *l;
g_return_val_if_fail (GTK_IS_CONTAINER (container), NULL);
for (c = l = glade_util_container_get_all_children (container);
l;
l = g_list_next (l))
{
child = l->data;
if (GLADE_IS_PLACEHOLDER (child))
{
gint x, y;
gtk_widget_get_pointer (child, &x, &y);
if (x >= 0 && y >= 0 &&
x <= child->allocation.width &&
y <= child->allocation.height)
{
retval = child;
break;
}
}
}
g_list_free (c);
return retval;
}
......@@ -72,8 +72,6 @@ LIBGLADEUI_API
void glade_util_clear_selection (void);
LIBGLADEUI_API
GList *glade_util_get_selection (void);
LIBGLADEUI_API
GladePlaceholder *glade_util_selected_placeholder (void);
LIBGLADEUI_API
void glade_util_queue_draw_nodes (GdkWindow *window);
......@@ -148,6 +146,9 @@ gboolean glade_util_deep_fixed_event (GtkWidget *widget,
GdkEvent *event,
GladeWidget *gwidget);
LIBGLADEUI_API
GtkWidget *glade_util_get_placeholder_from_pointer (GtkContainer *container);
G_END_DECLS
#endif /* __GLADE_UTILS_H__ */
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