diff options
author | Tristan Van Berkom <tristan.van.berkom@gmail.com> | 2004-11-05 19:44:21 +0000 |
---|---|---|
committer | David Hoover <dhoover@src.gnome.org> | 2004-11-05 19:44:21 +0000 |
commit | 7e43051d49e89ad5791d972b48720d2048e0db84 (patch) | |
tree | c86fc376de6794ab46d1b89d14886f1e88f66cf2 | |
parent | ca5f1e2c78021bd010a93510e466cae4612235ff (diff) | |
download | glade-7e43051d49e89ad5791d972b48720d2048e0db84.tar.gz |
Implemented glade_command_copy () (undo/redo works like a charm :-)
2004-11-03 Tristan Van Berkom <tristan.van.berkom@gmail.com>
* src/glade-command.[ch], glade-popup.c, glade-project-window.c:
Implemented glade_command_copy () (undo/redo works like a charm :-)
* src/glade-widget.c: Simplified / Improved code respecting custom properties.
* src/glade-project.c: Simplified some code around selection, project management
(improved fixes for bugs 156515 and 155892).
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | src/glade-command.c | 172 | ||||
-rw-r--r-- | src/glade-command.h | 1 | ||||
-rw-r--r-- | src/glade-popup.c | 7 | ||||
-rw-r--r-- | src/glade-project-window.c | 2 | ||||
-rw-r--r-- | src/glade-project.c | 17 | ||||
-rw-r--r-- | src/glade-widget.c | 32 | ||||
-rw-r--r-- | src/glade-widget.h | 4 |
8 files changed, 160 insertions, 86 deletions
@@ -1,3 +1,14 @@ +2004-11-03 Tristan Van Berkom <tristan.van.berkom@gmail.com> + + * src/glade-command.[ch], glade-popup.c, glade-project-window.c: + Implemented glade_command_copy () (undo/redo works like a charm :-) + + * src/glade-widget.c: Simplified / Improved code respecting custom properties. + + * src/glade-project.c: Simplified some code around selection, project management + (improved fixes for bugs 156515 and 155892). + + 2004-11-02 Shane Butler <shane_b@users.sourceforge.net> * src/glade-utils.[ch] (glade_util_file_dialog_new): rewrote function to create a GtkFileSelector or GtkFileChooser depending on the GTK+ version. diff --git a/src/glade-command.c b/src/glade-command.c index a3fbb6f7..7ff4d95d 100644 --- a/src/glade-command.c +++ b/src/glade-command.c @@ -755,8 +755,14 @@ glade_command_create (GladeWidgetClass *class, glade_palette_unselect_widget (gpw->palette); } +typedef enum { + GLADE_CUT, + GLADE_COPY, + GLADE_PASTE +} GladeCutCopyPasteType; + /** - * Cut/Paste + * Cut/Copy/Paste * * Following is the code to extend the GladeCommand Undo/Redo system to * Clipboard functions. @@ -767,25 +773,19 @@ typedef struct { GladeClipboard *clipboard; GladeWidget *widget; GladePlaceholder *placeholder; - gboolean cut; -} GladeCommandCutPaste; - + GladeCutCopyPasteType type; +} GladeCommandCutCopyPaste; -GLADE_MAKE_COMMAND (GladeCommandCutPaste, glade_command_cut_paste); -#define GLADE_COMMAND_CUT_PASTE_TYPE (glade_command_cut_paste_get_type ()) -#define GLADE_COMMAND_CUT_PASTE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GLADE_COMMAND_CUT_PASTE_TYPE, GladeCommandCutPaste)) -#define GLADE_COMMAND_CUT_PASTE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GLADE_COMMAND_CUT_PASTE_TYPE, GladeCommandCutPasteClass)) -#define GLADE_IS_COMMAND_CUT_PASTE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GLADE_COMMAND_CUT_PASTE_TYPE)) -#define GLADE_IS_COMMAND_CUT_PASTE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GLADE_COMMAND_CREATE_DELETE_TYPE)) -static gboolean -glade_command_cut_paste_undo (GladeCommand *cmd) -{ - return glade_command_cut_paste_execute (cmd); -} +GLADE_MAKE_COMMAND (GladeCommandCutCopyPaste, glade_command_cut_copy_paste); +#define GLADE_COMMAND_CUT_COPY_PASTE_TYPE (glade_command_cut_copy_paste_get_type ()) +#define GLADE_COMMAND_CUT_COPY_PASTE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GLADE_COMMAND_CUT_COPY_PASTE_TYPE, GladeCommandCutCopyPaste)) +#define GLADE_COMMAND_CUT_COPY_PASTE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GLADE_COMMAND_CUT_COPY_PASTE_TYPE, GladeCommandCutCopyPasteClass)) +#define GLADE_IS_COMMAND_CUT_COPY_PASTE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GLADE_COMMAND_CUT_COPY_PASTE_TYPE)) +#define GLADE_IS_COMMAND_CUT_COPY_PASTE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GLADE_COMMAND_CREATE_DELETE_TYPE)) static gboolean -glade_command_paste_execute (GladeCommandCutPaste *me) +glade_command_paste_execute (GladeCommandCutCopyPaste *me) { GladeWidget *glade_widget = me->widget; GladePlaceholder *placeholder = me->placeholder; @@ -815,7 +815,7 @@ glade_command_paste_execute (GladeCommandCutPaste *me) } static gboolean -glade_command_cut_execute (GladeCommandCutPaste *me) +glade_command_cut_execute (GladeCommandCutCopyPaste *me) { GladeWidget *glade_widget = me->widget; @@ -836,96 +836,153 @@ glade_command_cut_execute (GladeCommandCutPaste *me) gtk_widget_hide (glade_widget->widget); - glade_project_selection_remove (glade_widget->project, glade_widget->widget, TRUE); glade_project_remove_widget (glade_widget->project, glade_widget->widget); return TRUE; } +static gboolean +glade_command_copy_execute (GladeCommandCutCopyPaste *me) +{ + glade_clipboard_add (me->clipboard, me->widget); + return TRUE; +} + +static gboolean +glade_command_copy_undo (GladeCommandCutCopyPaste *me) +{ + glade_clipboard_remove (me->clipboard, me->widget); + return TRUE; +} + /** * Execute the cmd and revert it. Ie, after the execution of this * function cmd will point to the undo action */ static gboolean -glade_command_cut_paste_execute (GladeCommand *cmd) +glade_command_cut_copy_paste_execute (GladeCommand *cmd) { - GladeCommandCutPaste *me = (GladeCommandCutPaste *) cmd; - gboolean retval; + GladeCommandCutCopyPaste *me = (GladeCommandCutCopyPaste *) cmd; + gboolean retval = FALSE; - if (me->cut) + switch (me->type) + { + case GLADE_CUT: retval = glade_command_cut_execute (me); - else + break; + case GLADE_COPY: + retval = glade_command_copy_execute (me); + break; + case GLADE_PASTE: retval = glade_command_paste_execute (me); + break; + } - me->cut = !me->cut; + return retval; +} +static gboolean +glade_command_cut_copy_paste_undo (GladeCommand *cmd) +{ + GladeCommandCutCopyPaste *me = (GladeCommandCutCopyPaste *) cmd; + gboolean retval = FALSE; + + switch (me->type) + { + case GLADE_CUT: + retval = glade_command_paste_execute (me); + break; + case GLADE_COPY: + retval = glade_command_copy_undo (me); + break; + case GLADE_PASTE: + retval = glade_command_cut_execute (me); + break; + } return retval; } static void -glade_command_cut_paste_finalize (GObject *obj) +glade_command_cut_copy_paste_finalize (GObject *obj) { - GladeCommandCutPaste *cmd; + GladeCommandCutCopyPaste *cmd; - g_return_if_fail (GLADE_IS_COMMAND_CUT_PASTE (obj)); + g_return_if_fail (GLADE_IS_COMMAND_CUT_COPY_PASTE (obj)); - cmd = GLADE_COMMAND_CUT_PASTE (obj); + cmd = GLADE_COMMAND_CUT_COPY_PASTE (obj); g_object_unref (cmd->widget); - g_object_unref (cmd->placeholder); + if (cmd->placeholder) + g_object_unref (cmd->placeholder); glade_command_finalize (obj); } static gboolean -glade_command_cut_paste_unifies (GladeCommand *this, GladeCommand *other) +glade_command_cut_copy_paste_unifies (GladeCommand *this, GladeCommand *other) { return FALSE; } static void -glade_command_cut_paste_collapse (GladeCommand *this, GladeCommand *other) +glade_command_cut_copy_paste_collapse (GladeCommand *this, GladeCommand *other) { g_return_if_reached (); } static void -glade_command_cut_paste_common (GladeWidget *widget, - GladePlaceholder *placeholder, - GladeProject *project, - gboolean cut) +glade_command_cut_copy_paste_common (GladeWidget *widget, + GladePlaceholder *placeholder, + GladeProject *project, + GladeCutCopyPasteType type) { - GladeCommandCutPaste *me; + GladeCommandCutCopyPaste *me; GladeCommand *cmd; GladeProjectWindow *gpw; - me = (GladeCommandCutPaste *) g_object_new (GLADE_COMMAND_CUT_PASTE_TYPE, NULL); + me = (GladeCommandCutCopyPaste *) g_object_new (GLADE_COMMAND_CUT_COPY_PASTE_TYPE, NULL); cmd = (GladeCommand *) me; gpw = glade_project_window_get (); - me->cut = cut; - me->widget = g_object_ref(widget); + me->type = type; + me->widget = + (type == GLADE_COPY) ? + glade_widget_dup (widget) : + g_object_ref (widget); me->placeholder = placeholder; me->clipboard = gpw->clipboard; if (me->placeholder) g_object_ref (G_OBJECT (me->placeholder)); - if (cut) + switch (type) { + case GLADE_CUT: cmd->description = g_strdup_printf (_("Cut %s"), widget->name); - else + break; + case GLADE_COPY: + cmd->description = g_strdup_printf (_("Copy %s"), widget->name); + break; + case GLADE_PASTE: cmd->description = g_strdup_printf (_("Paste %s"), widget->name); + break; + } g_debug(("Pushing: %s\n", cmd->description)); /* * Push it onto the undo stack only on success */ - if (glade_command_cut_paste_execute (cmd)) + if (glade_command_cut_copy_paste_execute (cmd)) glade_command_push_undo (project, cmd); } +/** + * glade_command_paste: + * @widget: a #GladeWidget + * + * TODO: write me + */ void glade_command_paste (GladePlaceholder *placeholder) { @@ -947,7 +1004,7 @@ glade_command_paste (GladePlaceholder *placeholder) return; parent = glade_util_get_parent (GTK_WIDGET (placeholder)); - glade_command_cut_paste_common (widget, placeholder, parent->project, FALSE); + glade_command_cut_copy_paste_common (widget, placeholder, parent->project, GLADE_PASTE); } /** @@ -974,7 +1031,34 @@ glade_command_cut (GladeWidget *widget) if (widget->internal) return; - glade_command_cut_paste_common (widget, NULL, widget->project, TRUE); + glade_command_cut_copy_paste_common (widget, NULL, widget->project, GLADE_CUT); +} + +/** + * glade_command_copy: + * @widget: a #GladeWidget + * + * TODO: write me + */ +void +glade_command_copy (GladeWidget *widget) +{ + GladeProjectWindow *gpw; + + gpw = glade_project_window_get (); + + if (!widget) { + glade_util_ui_warn (gpw->window, _("No widget selected!")); + return; + } + + g_return_if_fail (GLADE_IS_WIDGET (widget)); + + /* internal children cannot be cut. Should we notify the user? */ + if (widget->internal) + return; + + glade_command_cut_copy_paste_common (widget, NULL, widget->project, GLADE_COPY); } /*********************************************************/ diff --git a/src/glade-command.h b/src/glade-command.h index 1f03e70c..a5d73063 100644 --- a/src/glade-command.h +++ b/src/glade-command.h @@ -51,6 +51,7 @@ void glade_command_delete (GladeWidget *glade_widget); void glade_command_create (GladeWidgetClass *widget_class, GladePlaceholder *placeholder, GladeProject *project); void glade_command_cut (GladeWidget *glade_widget); +void glade_command_copy (GladeWidget *glade_widget); void glade_command_paste (GladePlaceholder *placeholder); void glade_command_add_signal (GladeWidget *glade_widget, const GladeSignal *signal); diff --git a/src/glade-popup.c b/src/glade-popup.c index ae87b3eb..4b0ddffd 100644 --- a/src/glade-popup.c +++ b/src/glade-popup.c @@ -46,12 +46,7 @@ glade_popup_cut_cb (GtkMenuItem *item, GladeWidget *widget) static void glade_popup_copy_cb (GtkMenuItem *item, GladeWidget *widget) { - GladeProjectWindow *gpw; - GladeWidget *dupped; - gpw = glade_project_window_get (); - dupped = glade_widget_dup (widget); - - glade_clipboard_add (gpw->clipboard, dupped); + glade_command_copy (widget); } static void diff --git a/src/glade-project-window.c b/src/glade-project-window.c index 3f7dbc41..7bccf3e6 100644 --- a/src/glade-project-window.c +++ b/src/glade-project-window.c @@ -429,7 +429,7 @@ gpw_copy_cb (void) GladeWidget *widget = glade_widget_get_from_gtk_widget (GTK_WIDGET (list->data)); if (widget) - glade_clipboard_add (gpw->clipboard, widget); + glade_command_copy (widget); } } diff --git a/src/glade-project.c b/src/glade-project.c index b1366860..c4fb4dd8 100644 --- a/src/glade-project.c +++ b/src/glade-project.c @@ -419,17 +419,13 @@ glade_project_remove_widget (GladeProject *project, GtkWidget *widget) } g_list_free (children); } - - if (glade_util_has_nodes (widget)) - glade_util_remove_nodes (widget); + glade_project_selection_remove (project, widget, TRUE); + gwidget = glade_widget_get_from_gtk_widget (widget); if (!gwidget) return; - project->selection = g_list_remove (project->selection, widget); - glade_project_selection_changed (project); - widget_l = g_list_find (project->widgets, widget); if (widget_l != NULL) { @@ -628,13 +624,11 @@ glade_project_selection_add (GladeProject *project, g_return_if_fail (GTK_IS_WIDGET (widget)); gpw = glade_project_window_get (); - has_nodes = glade_util_has_nodes (widget); - if (has_nodes && gpw->editor->loaded_widget != NULL) + if (glade_util_has_nodes (widget)) return; - if (has_nodes == FALSE) - glade_util_add_nodes (widget); + glade_util_add_nodes (widget); if (project) { @@ -665,8 +659,7 @@ glade_project_selection_set (GladeProject *project, gpw = glade_project_window_get (); - if (glade_util_has_nodes (widget) && - gpw->editor->loaded_widget != NULL) + if (glade_util_has_nodes (widget)) return; glade_project_selection_clear (project, FALSE); diff --git a/src/glade-widget.c b/src/glade-widget.c index 580a359c..335d221a 100644 --- a/src/glade-widget.c +++ b/src/glade-widget.c @@ -329,18 +329,6 @@ glade_widget_sync_custom_props (GladeWidget *widget) } } -static void -glade_widget_sync_query_props (GladeWidget *widget) -{ - GList *l; - for (l = widget->properties; l && l->data; l = l->next) - { - GladeProperty *prop = GLADE_PROPERTY(l->data); - if (prop->class->query) - glade_property_sync (prop); - } -} - /** * glade_widget_build_object: * @klass: a #GladeWidgetClass @@ -479,16 +467,18 @@ glade_widget_new (GladeWidgetClass *klass, GladeProject *project) { GladeWidget *widget; - if ((widget = glade_widget_internal_new (klass, project, NULL)) != NULL && - widget->query_user) + if ((widget = glade_widget_internal_new (klass, project, NULL)) != NULL) { - GladeProjectWindow *gpw = glade_project_window_get (); - glade_editor_query_popup (gpw->editor, widget); + if (widget->query_user) + { + GladeProjectWindow *gpw = glade_project_window_get (); + glade_editor_query_popup (gpw->editor, widget); + } - /* The glade editor code only sets properties if they change, - * this is just in case they dont. + /* Properties that have custom set_functions on them need to be + * explicitly synchronized. */ - glade_widget_sync_query_props (widget); + glade_widget_sync_custom_props (widget); } return widget; } @@ -512,6 +502,7 @@ glade_widget_dup (GladeWidget *template) template->project, template); + if (GTK_IS_CONTAINER(template->widget)) { children = gtk_container_get_children(GTK_CONTAINER(template->widget)); @@ -535,10 +526,11 @@ glade_widget_dup (GladeWidget *template) } } } - gtk_widget_show_all (gwidget->widget); glade_widget_copy_custom_props (gwidget, template); + gtk_widget_show_all (gwidget->widget); + return gwidget; } diff --git a/src/glade-widget.h b/src/glade-widget.h index 155c215e..975c2cc8 100644 --- a/src/glade-widget.h +++ b/src/glade-widget.h @@ -38,9 +38,7 @@ struct _GladeWidget GtkWidget *widget; /* A pointer to the widget that was created. * and is shown as a "view" of the GladeWidget. * This widget is updated as the properties are - * modified for the GladeWidget. We should not - * destroy this widgets once created, we should - * just hide them + * modified for the GladeWidget. */ GList *properties; /* A list of GladeProperty. A GladeProperty is an |