Commit 9b5aa90b authored by Tristan Van Berkom's avatar Tristan Van Berkom

Fixed bug in glade_widget_dup_internal () (stupid typo of mine when fixing

	* src/glade-widget.c: Fixed bug in glade_widget_dup_internal ()
	  (stupid typo of mine when fixing 320077)

	* src/glade-utils.[ch]: Removed all the Cut/Copy/Paste/Delete
	  stuff, now all in GladeApp.

	* src/glade-app.c: Moved the bulk of code from glade-utils to
	  glade-app (cut/copy/paste/delete) since it was confusing to
	  see the chain of events, it should be simpler overall now.

	* doc/glade-sections.txt, doc/tmpl/*: Adjusted doc structure
	  for new apis and removed old apis.
parent 669b275e
......@@ -2,6 +2,19 @@
* TODO: Updated the list.
* src/glade-widget.c: Fixed bug in glade_widget_dup_internal ()
(stupid typo of mine when fixing 320077)
* src/glade-utils.[ch]: Removed all the Cut/Copy/Paste/Delete
stuff, now all in GladeApp.
* src/glade-app.c: Moved the bulk of code from glade-utils to
glade-app (cut/copy/paste/delete) since it was confusing to
see the chain of events, it should be simpler overall now.
* doc/glade-sections.txt, doc/tmpl/*: Adjusted doc structure
for new apis and removed old apis.
2006-02-13 Tristan Van Berkom <tvb@gnome.org>
* src/glade-command.c: No more glade_util_ui_message(), deffer that
......
......@@ -52,6 +52,11 @@ glade_default_app_show_properties
glade_default_app_hide_properties
glade_default_app_set_transient_parent
glade_default_app_get_transient_parent
glade_default_app_command_cut
glade_default_app_command_copy
glade_default_app_command_paste
glade_default_app_command_delete
glade_default_app_command_delete_clipboard
glade_default_app_is_selected
glade_default_app_selection_set
glade_default_app_selection_add
......@@ -565,11 +570,6 @@ glade_util_uri_list_parse
glade_util_gtkcontainer_relation
glade_util_any_gtkcontainer_relation
glade_util_widget_pastable
glade_util_paste_clipboard
glade_util_cut_selection
glade_util_copy_selection
glade_util_delete_selection
glade_util_delete_clipboard
glade_util_count_placeholders
glade_util_find_iter_by_widget
glade_util_basenames_match
......
......@@ -440,6 +440,41 @@ to initialize the Glade core.
@Returns:
<!-- ##### FUNCTION glade_default_app_command_cut ##### -->
<para>
</para>
<!-- ##### FUNCTION glade_default_app_command_copy ##### -->
<para>
</para>
<!-- ##### FUNCTION glade_default_app_command_paste ##### -->
<para>
</para>
<!-- ##### FUNCTION glade_default_app_command_delete ##### -->
<para>
</para>
<!-- ##### FUNCTION glade_default_app_command_delete_clipboard ##### -->
<para>
</para>
<!-- ##### FUNCTION glade_default_app_is_selected ##### -->
<para>
......
......@@ -257,43 +257,6 @@ This is where all of that really usefull miscalanious stuff lands up.
@Returns:
<!-- ##### FUNCTION glade_util_paste_clipboard ##### -->
<para>
</para>
@placeholder:
@parent:
<!-- ##### FUNCTION glade_util_cut_selection ##### -->
<para>
</para>
<!-- ##### FUNCTION glade_util_copy_selection ##### -->
<para>
</para>
<!-- ##### FUNCTION glade_util_delete_selection ##### -->
<para>
</para>
<!-- ##### FUNCTION glade_util_delete_clipboard ##### -->
<para>
</para>
<!-- ##### FUNCTION glade_util_count_placeholders ##### -->
<para>
......
......@@ -763,59 +763,305 @@ glade_app_set_project (GladeApp *app, GladeProject *project)
glade_app_update_ui (app);
}
/**
* glade_app_command_copy:
* @app: A #GladeApp
*
* Copy the active project's selection (the new copies
* will end up on the clipboard and will be set as
* the clipboards selection).
*/
void
glade_app_command_copy (GladeApp *app)
{
if (app->priv->active_project)
GList *widgets = NULL, *list;
GladeWidget *widget;
gboolean failed = FALSE;
g_return_if_fail (GLADE_IS_APP (app));
if (app->priv->active_project == NULL) return;
for (list = glade_default_app_get_selection ();
list && list->data; list = list->next)
{
widget = glade_widget_get_from_gobject (GTK_WIDGET (list->data));
widgets = g_list_prepend (widgets, widget);
g_assert (widget);
if (widget->internal)
{
glade_util_ui_message
(glade_app_get_window(app),
GLADE_UI_INFO,
_("You cannot copy a widget "
"internal to a composite widget."));
failed = TRUE;
break;
}
}
if (failed == FALSE && widgets != NULL)
{
glade_util_copy_selection ();
/* update UI. */
glade_command_copy (widgets);
glade_app_update_ui (app);
}
else if (widgets == NULL)
glade_util_ui_message (glade_app_get_window(app),
GLADE_UI_INFO,
_("No widget selected."));
if (widgets) g_list_free (widgets);
}
/**
* glade_app_command_cut:
* @app: A #GladeApp
*
* Cut the active project's selection (the cut objects
* will end up on the clipboard and will be set as
* the clipboards selection).
*/
void
glade_app_command_cut (GladeApp *app)
{
if (app->priv->active_project)
GList *widgets = NULL, *list;
GladeWidget *widget;
gboolean failed = FALSE;
g_return_if_fail (GLADE_IS_APP (app));
if (app->priv->active_project == NULL) return;
for (list = glade_default_app_get_selection ();
list && list->data; list = list->next)
{
glade_util_cut_selection ();
/* Update UI. */
widget = glade_widget_get_from_gobject (GTK_WIDGET (list->data));
widgets = g_list_prepend (widgets, widget);
g_assert (widget);
if (widget->internal)
{
glade_util_ui_message
(glade_app_get_window(app),
GLADE_UI_INFO,
_("You cannot cut a widget "
"internal to a composite widget."));
failed = TRUE;
break;
}
}
if (failed == FALSE && widgets != NULL)
{
glade_command_cut (widgets);
glade_app_update_ui (app);
}
else if (widgets == NULL)
glade_util_ui_message (glade_app_get_window(app),
GLADE_UI_INFO,
_("No widget selected."));
if (widgets) g_list_free (widgets);
}
/**
* glade_app_command_paste:
* @app: A #GladeApp
*
* Paste the clipboard selection to the active project's
* selection (the project must have only one object selected).
*/
void
glade_app_command_paste (GladeApp *app)
{
if (app->priv->active_project)
GladeClipboard *clipboard;
GList *list;
GladeWidget *widget = NULL;
gint gtkcontainer_relations = 0;
GladePlaceholder *placeholder;
GladeWidget *parent;
g_return_if_fail (GLADE_IS_APP (app));
if (app->priv->active_project == NULL) return;
list = glade_project_selection_get (app->priv->active_project);
clipboard = glade_app_get_clipboard (app);
/* 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);
/* Check if selection is good */
if ((list = glade_default_app_get_selection ()) != NULL)
{
GList *list = glade_project_selection_get (app->priv->active_project);
GladePlaceholder *placeholder = list ? NULL : glade_util_selected_placeholder ();
GladeWidget *parent =
list ? glade_widget_get_from_gobject (list->data) :
glade_placeholder_get_parent (placeholder);
glade_util_paste_clipboard (placeholder, parent);
if (placeholder == NULL &&
g_list_length (list) != 1)
{
glade_util_ui_message (glade_app_get_window(app),
GLADE_UI_INFO,
_("Unable to paste to multiple widgets"));
return;
}
}
/* Check if we have anything to paste */
if (g_list_length (clipboard->selection) == 0)
{
glade_util_ui_message (glade_app_get_window (app), GLADE_UI_INFO,
_("No widget selected on the clipboard"));
return;
}
/* Check that we have compatible heirarchies */
for (list = clipboard->selection;
list && list->data; list = list->next)
{
widget = list->data;
/* Update UI. */
glade_app_update_ui (app);
if (GTK_WIDGET_TOPLEVEL (widget->object) == FALSE && parent)
{
/* Ensure a paste is supported
*/
if (glade_util_widget_pastable (widget, parent) == FALSE)
{
glade_util_ui_message (glade_default_app_get_window (),
GLADE_UI_ERROR,
_("Unable to paste widget %s to parent %s"),
widget->name, parent->name);
return;
}
/* Count gtk container relations
*/
if (glade_util_gtkcontainer_relation (parent, widget))
gtkcontainer_relations++;
}
}
g_assert (widget);
/* Check that GladeFixedManager will cope */
if (GTK_WIDGET_TOPLEVEL (widget->object) == FALSE &&
parent && parent->manager != NULL &&
gtkcontainer_relations != 1)
{
glade_util_ui_message (glade_default_app_get_window (),
GLADE_UI_INFO,
_("Only one widget can be pasted at a "
"time to this container"));
return;
}
/* Check that enough placeholders are available */
if (parent && parent->manager == NULL &&
glade_util_count_placeholders (parent) < gtkcontainer_relations)
{
glade_util_ui_message (glade_default_app_get_window (),
GLADE_UI_INFO,
_("Insufficient amount of placeholders in "
"target container"));
return;
}
glade_command_paste (clipboard->selection, parent, placeholder);
glade_app_update_ui (app);
}
/**
* glade_app_command_delete:
* @app: A #GladeApp
*
* Delete the active project's selection.
*/
void
glade_app_command_delete (GladeApp *app)
{
/* glade_util_delete_selection performs a glade_command_delete
* on each of the selected widgets */
if (app->priv->active_project)
GList *widgets = NULL, *list;
GladeWidget *widget;
gboolean failed = FALSE;
g_return_if_fail (GLADE_IS_APP (app));
if (app->priv->active_project == NULL) return;
for (list = glade_default_app_get_selection ();
list && list->data; list = list->next)
{
glade_util_delete_selection ();
/* Update UI. */
widget = glade_widget_get_from_gobject (GTK_WIDGET (list->data));
widgets = g_list_prepend (widgets, widget);
g_assert (widget);
if (widget->internal)
{
glade_util_ui_message
(glade_app_get_window(app),
GLADE_UI_INFO,
_("You cannot delete a widget "
"internal to a composite widget."));
failed = TRUE;
break;
}
}
if (failed == FALSE && widgets != NULL)
{
glade_command_delete (widgets);
glade_app_update_ui (app);
}
else if (widgets == NULL)
glade_util_ui_message (glade_app_get_window(app),
GLADE_UI_INFO,
_("No widget selected."));
if (widgets) g_list_free (widgets);
}
/**
* glade_app_command_delete_clipboard:
* @app: A #GladeApp
*
* Delete the clipboard's selection.
*/
void
glade_app_command_delete_clipboard (GladeApp *app)
{
GladeClipboard *clipboard;
GladeWidget *gwidget;
GList *list;
g_return_if_fail (GLADE_IS_APP (app));
clipboard = glade_app_get_clipboard (app);
if (clipboard->selection == NULL)
glade_util_ui_message (glade_app_get_window (app), GLADE_UI_INFO,
_("No widget selected on the clipboard"));
for (list = clipboard->selection; list; list = list->next)
{
gwidget = list->data;
if (gwidget->internal)
{
glade_util_ui_message
(glade_default_app_get_window(),
GLADE_UI_INFO,
_("You cannot delete a widget "
"internal to a composite widget."));
return;
}
}
glade_command_delete (clipboard->selection);
glade_app_update_ui (app);
}
void
glade_app_command_undo (GladeApp *app)
{
......@@ -1168,3 +1414,38 @@ glade_default_app_redo_button_new (void)
g_return_val_if_fail (glade_default_app != NULL, NULL);
return glade_app_undo_redo_button_new (glade_default_app, FALSE);
}
void
glade_default_app_command_cut (void)
{
g_return_if_fail (glade_default_app != NULL);
return glade_app_command_cut (glade_default_app);
}
void
glade_default_app_command_copy (void)
{
g_return_if_fail (glade_default_app != NULL);
return glade_app_command_copy (glade_default_app);
}
void
glade_default_app_command_paste (void)
{
g_return_if_fail (glade_default_app != NULL);
return glade_app_command_paste (glade_default_app);
}
void
glade_default_app_command_delete (void)
{
g_return_if_fail (glade_default_app != NULL);
return glade_app_command_delete (glade_default_app);
}
void
glade_default_app_command_delete_clipboard (void)
{
g_return_if_fail (glade_default_app != NULL);
return glade_app_command_delete_clipboard (glade_default_app);
}
......@@ -170,6 +170,25 @@ void glade_default_app_set_transient_parent (GtkWindow *parent);
LIBGLADEUI_API
GtkWindow *glade_default_app_get_transient_parent (void);
LIBGLADEUI_API
GtkWidget *glade_default_app_undo_button_new (void);
LIBGLADEUI_API
GtkWidget *glade_default_app_redo_button_new (void);
/* GladeCommand interface stuff
*/
LIBGLADEUI_API
void glade_default_app_command_cut (void);
LIBGLADEUI_API
void glade_default_app_command_copy (void);
LIBGLADEUI_API
void glade_default_app_command_paste (void);
LIBGLADEUI_API
void glade_default_app_command_delete (void);
LIBGLADEUI_API
void glade_default_app_command_delete_clipboard (void);
/* These handle selection on a global scope and take care
* of multiple project logic.
......@@ -189,10 +208,7 @@ LIBGLADEUI_API
void glade_default_app_selection_clear (gboolean emit_signal);
LIBGLADEUI_API
void glade_default_app_selection_changed(void);
LIBGLADEUI_API
GtkWidget *glade_default_app_undo_button_new (void);
LIBGLADEUI_API
GtkWidget *glade_default_app_redo_button_new (void);
G_END_DECLS
......
......@@ -1559,7 +1559,7 @@ glade_command_cut_copy_paste_common (GList *widgets,
/**
* glade_command_paste:
* @widgets: a #GList
* @widgets: a #GList of #GladeWidget
* @parent: a #GladeWidget
* @placeholder: a #GladePlaceholder
*
......
......@@ -61,7 +61,7 @@ glade_popup_cut_cb (GtkMenuItem *item, GladeWidget *widget)
glade_default_app_selection_set
(glade_widget_get_object (widget), FALSE);
}
glade_util_cut_selection ();
glade_default_app_command_cut ();
}
static void
......@@ -77,7 +77,7 @@ glade_popup_copy_cb (GtkMenuItem *item, GladeWidget *widget)
glade_default_app_selection_set
(glade_widget_get_object (widget), FALSE);
glade_util_copy_selection ();
glade_default_app_command_copy ();
}
static void
......@@ -90,7 +90,7 @@ glade_popup_paste_cb (GtkMenuItem *item, GladeWidget *widget)
glade_default_app_selection_set
(glade_widget_get_object (widget), FALSE);
glade_util_paste_clipboard (NULL, widget);
glade_default_app_command_paste ();
}
static void
......@@ -104,7 +104,7 @@ glade_popup_delete_cb (GtkMenuItem *item, GladeWidget *widget)
glade_default_app_selection_set
(glade_widget_get_object (widget), FALSE);
glade_util_delete_selection ();
glade_default_app_command_delete ();
}
......@@ -131,8 +131,9 @@ glade_popup_placeholder_paste_cb (GtkMenuItem *item,
glade_util_clear_selection ();
glade_default_app_selection_clear (FALSE);
glade_util_paste_clipboard (placeholder,
glade_placeholder_get_parent (placeholder));
/* Set selection on the placeholder first */
glade_util_add_selection (GTK_WIDGET (placeholder));
glade_default_app_command_paste ();
}
......@@ -146,13 +147,13 @@ glade_popup_clipboard_paste_cb (GtkMenuItem *item,
glade_util_clear_selection ();
glade_default_app_selection_clear (FALSE);
glade_util_paste_clipboard (NULL, NULL);
glade_default_app_command_paste ();
}
static void
glade_popup_clipboard_delete_cb (GtkMenuItem *item, GladeWidget *widget)
{
glade_util_delete_clipboard ();
glade_default_app_command_delete_clipboard ();
}
static void
......
......@@ -1095,272 +1095,6 @@ glade_util_count_placeholders (GladeWidget *parent)
return placeholders;
}
/**
* glade_util_paste_clipboard:
* @placeholder: The #GladePlaceholder to paste the clipboard item to,
* if NULL; paste to the selected object in the active project.
*
* Paste the clipboard selection to the active project's
* selection (the project must have only one object selected).
*/
void
glade_util_paste_clipboard (GladePlaceholder *placeholder,
GladeWidget *parent)
{
GladeClipboard *clipboard = glade_default_app_get_clipboard ();
GList *list;
GladeWidget *widget = NULL;
gint gtkcontainer_relations = 0;
g_return_if_fail (placeholder == NULL || GLADE_IS_PLACEHOLDER (placeholder));
g_return_if_fail (parent == NULL || GLADE_IS_WIDGET (parent));
if ((list = glade_default_app_get_selection ()) != NULL)
{
if (placeholder == NULL &&
g_list_length (list) != 1)
{
glade_util_ui_message (glade_default_app_get_window(),
GLADE_UI_WARN,
_("Unable to paste to multiple widgets"));
return;
}
}
if (g_list_length (clipboard->selection) == 0)
{
glade_util_ui_message (glade_default_app_get_window (), GLADE_UI_WARN,
_("No widget selected on the clipboard"));
return;
}
for (list = clipboard->selection;
list && list->data; list = list->next)
{
widget = list->data;
if (GTK_WIDGET_TOPLEVEL (widget->object) == FALSE && parent)
{
/* Ensure a paste is supported
*/
if (glade_util_widget_pastable (widget, parent) == FALSE)
{
glade_util_ui_message (glade_default_app_get_window (),
GLADE_UI_ERROR,
_("Unable to paste widget %s to parent %s"),
widget->name, parent->name);
return;
}
/* Count gtk container relations
*/
if (glade_util_gtkcontainer_relation (parent, widget))
gtkcontainer_relations++;
}
}
g_assert (widget);
/* Ensure enough placeholders are available */
if (GTK_WIDGET_TOPLEVEL (widget->object) == FALSE &&
parent && parent->manager != NULL &&
gtkcontainer_relations != 1)
{
glade_util_ui_message (glade_default_app_get_window (),
GLADE_UI_WARN,
_("Only one widget can be pasted at a "
"time to this container"));
return;
}
if (parent && parent->manager == NULL &&
glade_util_count_placeholders (parent) < gtkcontainer_relations)
{
glade_util_ui_message (glade_default_app_get_window (),
GLADE_UI_WARN,
_("Insufficient amount of placeholders in "
"target container"));
return;
}
glade_command_paste (clipboard->selection, parent, placeholder);
}
/**
* glade_util_delete_clipboard:
*
* Cut the active project's selection.
*/
void
glade_util_delete_clipboard (void)
{
GladeClipboard *clipboard = glade_default_app_get_clipboard ();
GladeWidget *gwidget;
GList *list;
for (list = clipboard->selection; list; list = list->next)
{
gwidget = list->data;
if (gwidget->internal)
{
glade_util_ui_message
(glade_default_app_get_window(),
GLADE_UI_INFO,
_("You cannot delete a widget "
"internal to a composite widget."));
return;
}
}
glade_command_delete (clipboard->selection);
}
/**
* glade_util_cut_selection:
*
* Cut the active project's selection.
*/
void
glade_util_cut_selection (void)
{
GList *widgets = NULL, *list;
GladeWidget *widget;
gboolean failed = FALSE;
for (list = glade_default_app_get_selection ();
list && list->data; list = list->next)
{
widget = glade_widget_get_from_gobject (GTK_WIDGET (list->data));
widgets = g_list_prepend (widgets, widget);
if (widget->internal)
{
glade_util_ui_message
(glade_default_app_get_window(),
GLADE_UI_INFO,
_("You cannot cut a widget "
"internal to a composite widget."));
failed = TRUE;
break;
}
}