From b12614646d0166c3b1b760ca8b76b4bff69cda10 Mon Sep 17 00:00:00 2001 From: MEST 1999 Sven Neumann Date: Tue, 6 Jul 1999 20:43:52 +0000 Subject: [PATCH] app/commands.[ch] app/global_edit.[ch] added "Paste As New" feature that Tue Jul 6 22:40:16 MEST 1999 Sven Neumann * app/commands.[ch] * app/global_edit.[ch] * app/menus.c: added "Paste As New" feature that allows to paste the current (or a named) buffer to a new image. Still need to add PDB call for that... --Sven --- ChangeLog | 8 +++ app/actions/help-commands.c | 10 +++ app/actions/help-commands.h | 25 ++++---- app/commands.c | 10 +++ app/commands.h | 25 ++++---- app/core/gimp-edit.c | 117 +++++++++++++++++++++++++++++----- app/core/gimp-edit.h | 32 +++++----- app/core/gimpedit.c | 117 +++++++++++++++++++++++++++++----- app/core/gimpedit.h | 32 +++++----- app/global_edit.c | 117 +++++++++++++++++++++++++++++----- app/global_edit.h | 32 +++++----- app/gui/commands.c | 10 +++ app/gui/commands.h | 25 ++++---- app/gui/help-commands.c | 10 +++ app/gui/help-commands.h | 25 ++++---- app/gui/menus.c | 2 + app/menus.c | 2 + app/menus/menus.c | 2 + app/widgets/gimpitemfactory.c | 2 + 19 files changed, 465 insertions(+), 138 deletions(-) diff --git a/ChangeLog b/ChangeLog index e09c8daf7d..858597b474 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Tue Jul 6 22:40:16 MEST 1999 Sven Neumann + + * app/commands.[ch] + * app/global_edit.[ch] + * app/menus.c: added "Paste As New" feature that allows to paste + the current (or a named) buffer to a new image. Still need to + add PDB call for that... + Tue Jul 6 19:58:48 MEST 1999 Sven Neumann * app/fuzzy_select.c: give user feedback on the threshold diff --git a/app/actions/help-commands.c b/app/actions/help-commands.c index 23aeb4834e..3e29b22516 100644 --- a/app/actions/help-commands.c +++ b/app/actions/help-commands.c @@ -183,6 +183,16 @@ edit_paste_into_cmd_callback (GtkWidget *widget, global_edit_paste (gdisp, 1); } +void +edit_paste_as_new_cmd_callback (GtkWidget *widget, + gpointer client_data) +{ + GDisplay * gdisp; + return_if_no_display (gdisp); + + global_edit_paste_as_new (gdisp); +} + void edit_clear_cmd_callback (GtkWidget *widget, gpointer client_data) diff --git a/app/actions/help-commands.h b/app/actions/help-commands.h index 86edf36fe5..274436bd6a 100644 --- a/app/actions/help-commands.h +++ b/app/actions/help-commands.h @@ -14,18 +14,19 @@ void file_pref_cmd_callback (GtkWidget *, gpointer); void file_close_cmd_callback (GtkWidget *, gpointer); void file_quit_cmd_callback (GtkWidget *, gpointer); -void edit_cut_cmd_callback (GtkWidget *, gpointer); -void edit_copy_cmd_callback (GtkWidget *, gpointer); -void edit_paste_cmd_callback (GtkWidget *, gpointer); -void edit_paste_into_cmd_callback (GtkWidget *, gpointer); -void edit_clear_cmd_callback (GtkWidget *, gpointer); -void edit_fill_cmd_callback (GtkWidget *, gpointer); -void edit_stroke_cmd_callback (GtkWidget *, gpointer); -void edit_undo_cmd_callback (GtkWidget *, gpointer); -void edit_redo_cmd_callback (GtkWidget *, gpointer); -void edit_named_cut_cmd_callback (GtkWidget *, gpointer); -void edit_named_copy_cmd_callback (GtkWidget *, gpointer); -void edit_named_paste_cmd_callback (GtkWidget *, gpointer); +void edit_cut_cmd_callback (GtkWidget *, gpointer); +void edit_copy_cmd_callback (GtkWidget *, gpointer); +void edit_paste_cmd_callback (GtkWidget *, gpointer); +void edit_paste_into_cmd_callback (GtkWidget *, gpointer); +void edit_paste_as_new_cmd_callback (GtkWidget *, gpointer); +void edit_clear_cmd_callback (GtkWidget *, gpointer); +void edit_fill_cmd_callback (GtkWidget *, gpointer); +void edit_stroke_cmd_callback (GtkWidget *, gpointer); +void edit_undo_cmd_callback (GtkWidget *, gpointer); +void edit_redo_cmd_callback (GtkWidget *, gpointer); +void edit_named_cut_cmd_callback (GtkWidget *, gpointer); +void edit_named_copy_cmd_callback (GtkWidget *, gpointer); +void edit_named_paste_cmd_callback (GtkWidget *, gpointer); void select_invert_cmd_callback (GtkWidget *, gpointer); void select_all_cmd_callback (GtkWidget *, gpointer); diff --git a/app/commands.c b/app/commands.c index 23aeb4834e..3e29b22516 100644 --- a/app/commands.c +++ b/app/commands.c @@ -183,6 +183,16 @@ edit_paste_into_cmd_callback (GtkWidget *widget, global_edit_paste (gdisp, 1); } +void +edit_paste_as_new_cmd_callback (GtkWidget *widget, + gpointer client_data) +{ + GDisplay * gdisp; + return_if_no_display (gdisp); + + global_edit_paste_as_new (gdisp); +} + void edit_clear_cmd_callback (GtkWidget *widget, gpointer client_data) diff --git a/app/commands.h b/app/commands.h index 86edf36fe5..274436bd6a 100644 --- a/app/commands.h +++ b/app/commands.h @@ -14,18 +14,19 @@ void file_pref_cmd_callback (GtkWidget *, gpointer); void file_close_cmd_callback (GtkWidget *, gpointer); void file_quit_cmd_callback (GtkWidget *, gpointer); -void edit_cut_cmd_callback (GtkWidget *, gpointer); -void edit_copy_cmd_callback (GtkWidget *, gpointer); -void edit_paste_cmd_callback (GtkWidget *, gpointer); -void edit_paste_into_cmd_callback (GtkWidget *, gpointer); -void edit_clear_cmd_callback (GtkWidget *, gpointer); -void edit_fill_cmd_callback (GtkWidget *, gpointer); -void edit_stroke_cmd_callback (GtkWidget *, gpointer); -void edit_undo_cmd_callback (GtkWidget *, gpointer); -void edit_redo_cmd_callback (GtkWidget *, gpointer); -void edit_named_cut_cmd_callback (GtkWidget *, gpointer); -void edit_named_copy_cmd_callback (GtkWidget *, gpointer); -void edit_named_paste_cmd_callback (GtkWidget *, gpointer); +void edit_cut_cmd_callback (GtkWidget *, gpointer); +void edit_copy_cmd_callback (GtkWidget *, gpointer); +void edit_paste_cmd_callback (GtkWidget *, gpointer); +void edit_paste_into_cmd_callback (GtkWidget *, gpointer); +void edit_paste_as_new_cmd_callback (GtkWidget *, gpointer); +void edit_clear_cmd_callback (GtkWidget *, gpointer); +void edit_fill_cmd_callback (GtkWidget *, gpointer); +void edit_stroke_cmd_callback (GtkWidget *, gpointer); +void edit_undo_cmd_callback (GtkWidget *, gpointer); +void edit_redo_cmd_callback (GtkWidget *, gpointer); +void edit_named_cut_cmd_callback (GtkWidget *, gpointer); +void edit_named_copy_cmd_callback (GtkWidget *, gpointer); +void edit_named_paste_cmd_callback (GtkWidget *, gpointer); void select_invert_cmd_callback (GtkWidget *, gpointer); void select_all_cmd_callback (GtkWidget *, gpointer); diff --git a/app/core/gimp-edit.c b/app/core/gimp-edit.c index 4f4e547a00..53f02ae123 100644 --- a/app/core/gimp-edit.c +++ b/app/core/gimp-edit.c @@ -45,6 +45,7 @@ struct _PasteNamedDlg GtkWidget *shell; GtkWidget *list; int paste_into; + int paste_as_new; GDisplay *gdisp; }; @@ -271,10 +272,10 @@ edit_copy (GImage *gimage, } GimpLayer* -edit_paste (GImage *gimage, +edit_paste (GImage *gimage, GimpDrawable *drawable, - TileManager *paste, - int paste_into) + TileManager *paste, + int paste_into) { Layer * float_layer; int x1, y1, x2, y2; @@ -315,6 +316,48 @@ edit_paste (GImage *gimage, else return NULL; } + +int +edit_paste_as_new (GImage *invoke, + TileManager *paste) +{ + GImage *gimage; + GimpDrawable *drawable; + Layer *layer; + Layer *float_layer; + GDisplay *gdisp; + + if (!global_buf) + return FALSE; + + /* create a new image */ + gimage = gimage_new (paste->width, paste->height, invoke->base_type); + gimp_image_set_resolution (gimage, invoke->xresolution, invoke->yresolution); + gimp_image_set_unit (gimage, invoke->unit); + + layer = layer_new (gimage, gimage->width, gimage->height, + (invoke->base_type == RGB) ? RGBA_GIMAGE : GRAYA_GIMAGE, + _("Pasted Layer"), OPAQUE_OPACITY, NORMAL); + + /* add the new layer to the image */ + gimage_disable_undo (gimage); + gimage_add_layer (gimage, layer, 0); + drawable = gimage_active_drawable (gimage); + drawable_fill (GIMP_DRAWABLE (drawable), TRANSPARENT_FILL); + + /* make a new floating layer */ + float_layer = layer_from_tiles (gimage, drawable, paste, + _("Pasted Layer"), OPAQUE_OPACITY, NORMAL); + + /* add the new floating selection */ + floating_sel_attach (float_layer, drawable); + floating_sel_anchor (float_layer); + gimage_enable_undo (gimage); + gdisp = gdisplay_new (gimage, 0x0101); + gimp_context_set_display (gimp_context_get_user (), gdisp); + + return TRUE; +} gboolean edit_clear (GImage *gimage, @@ -434,7 +477,8 @@ global_edit_paste (void *gdisp_ptr, gdisp = (GDisplay *) gdisp_ptr; active_tool_control (HALT, gdisp_ptr); - if (!edit_paste (gdisp->gimage, gimage_active_drawable (gdisp->gimage), global_buf, paste_into)) + if (!edit_paste (gdisp->gimage, gimage_active_drawable (gdisp->gimage), + global_buf, paste_into)) return FALSE; else { @@ -444,6 +488,21 @@ global_edit_paste (void *gdisp_ptr, } } +int +global_edit_paste_as_new (void *gdisp_ptr) +{ + GDisplay *gdisp; + + if (!global_buf) + return FALSE; + + /* stop any active tool */ + gdisp = (GDisplay *) gdisp_ptr; + active_tool_control (HALT, gdisp_ptr); + + return (edit_paste_as_new (gdisp->gimage, global_buf)); +} + void global_edit_free () { @@ -489,9 +548,12 @@ named_buffer_paste_foreach (GtkWidget *w, { pn_dlg = (PasteNamedDlg *) client_data; nb = (NamedBuffer *) gtk_object_get_user_data (GTK_OBJECT (w)); - edit_paste (pn_dlg->gdisp->gimage, - gimage_active_drawable (pn_dlg->gdisp->gimage), - nb->buf, pn_dlg->paste_into); + if (pn_dlg->paste_as_new) + edit_paste_as_new (pn_dlg->gdisp->gimage, nb->buf); + else + edit_paste (pn_dlg->gdisp->gimage, + gimage_active_drawable (pn_dlg->gdisp->gimage), + nb->buf, pn_dlg->paste_into); } } @@ -578,9 +640,23 @@ named_buffer_paste_into_update (GtkWidget *w, pn_dlg = (PasteNamedDlg *) client_data; if (GTK_TOGGLE_BUTTON (w)->active) - pn_dlg->paste_into = FALSE; - else pn_dlg->paste_into = TRUE; + else + pn_dlg->paste_into = FALSE; +} + +static void +named_buffer_paste_as_new_update (GtkWidget *w, + gpointer client_data) +{ + PasteNamedDlg *pn_dlg; + + pn_dlg = (PasteNamedDlg *) client_data; + + if (GTK_TOGGLE_BUTTON (w)->active) + pn_dlg->paste_as_new = TRUE; + else + pn_dlg->paste_as_new = FALSE; } static void @@ -595,12 +671,14 @@ paste_named_buffer (GDisplay *gdisp) PasteNamedDlg *pn_dlg; GtkWidget *vbox; GtkWidget *label; - GtkWidget *paste_into; + GtkWidget *toggle; GtkWidget *listbox; pn_dlg = (PasteNamedDlg *) g_malloc (sizeof (PasteNamedDlg)); pn_dlg->gdisp = gdisp; - + pn_dlg->paste_into = FALSE; + pn_dlg->paste_as_new = FALSE; + pn_dlg->shell = gtk_dialog_new (); gtk_window_set_wmclass (GTK_WINDOW (pn_dlg->shell), "paste_named_buffer", "Gimp"); gtk_window_set_title (GTK_WINDOW (pn_dlg->shell), _("Paste Named Buffer")); @@ -634,12 +712,21 @@ paste_named_buffer (GDisplay *gdisp) set_list_of_named_buffers (pn_dlg->list); gtk_widget_show (pn_dlg->list); - paste_into = gtk_check_button_new_with_label (_("Replace Current Selection")); - gtk_box_pack_start (GTK_BOX (vbox), paste_into, FALSE, FALSE, 0); - gtk_signal_connect (GTK_OBJECT (paste_into), "toggled", + toggle = gtk_check_button_new_with_label (_("Replace Current Selection")); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), (pn_dlg->paste_into)); + gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0); + gtk_signal_connect (GTK_OBJECT (toggle), "toggled", (GtkSignalFunc) named_buffer_paste_into_update, pn_dlg); - gtk_widget_show (paste_into); + gtk_widget_show (toggle); + + toggle = gtk_check_button_new_with_label (_("Paste As New")); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), (pn_dlg->paste_as_new)); + gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0); + gtk_signal_connect (GTK_OBJECT (toggle), "toggled", + (GtkSignalFunc) named_buffer_paste_as_new_update, + pn_dlg); + gtk_widget_show (toggle); action_items[0].user_data = pn_dlg; action_items[1].user_data = pn_dlg; diff --git a/app/core/gimp-edit.h b/app/core/gimp-edit.h index 2ce68096ab..68b2e4b9c6 100644 --- a/app/core/gimp-edit.h +++ b/app/core/gimp-edit.h @@ -21,22 +21,24 @@ #include "gimage.h" /* The interface functions */ -TileManager * crop_buffer (TileManager *, int); -TileManager * edit_cut (GImage *, GimpDrawable *); -TileManager * edit_copy (GImage *, GimpDrawable *); -GimpLayer* edit_paste (GImage *, GimpDrawable *, - TileManager *, int); -int edit_clear (GImage *, GimpDrawable *); -int edit_fill (GImage *, GimpDrawable *); +TileManager * crop_buffer (TileManager *, int); +TileManager * edit_cut (GImage *, GimpDrawable *); +TileManager * edit_copy (GImage *, GimpDrawable *); +GimpLayer* edit_paste (GImage *, GimpDrawable *, + TileManager *, int); +int edit_paste_as_new (GImage *, TileManager *); +int edit_clear (GImage *, GimpDrawable *); +int edit_fill (GImage *, GimpDrawable *); -int global_edit_cut (void *); -int global_edit_copy (void *); -int global_edit_paste (void *, int); -void global_edit_free (void); +int global_edit_cut (void *); +int global_edit_copy (void *); +int global_edit_paste (void *, int); +int global_edit_paste_as_new (void *); +void global_edit_free (void); -int named_edit_cut (void *); -int named_edit_copy (void *); -int named_edit_paste (void *); -void named_buffers_free (void); +int named_edit_cut (void *); +int named_edit_copy (void *); +int named_edit_paste (void *); +void named_buffers_free (void); #endif /* __GLOBAL_EDIT_H__ */ diff --git a/app/core/gimpedit.c b/app/core/gimpedit.c index 4f4e547a00..53f02ae123 100644 --- a/app/core/gimpedit.c +++ b/app/core/gimpedit.c @@ -45,6 +45,7 @@ struct _PasteNamedDlg GtkWidget *shell; GtkWidget *list; int paste_into; + int paste_as_new; GDisplay *gdisp; }; @@ -271,10 +272,10 @@ edit_copy (GImage *gimage, } GimpLayer* -edit_paste (GImage *gimage, +edit_paste (GImage *gimage, GimpDrawable *drawable, - TileManager *paste, - int paste_into) + TileManager *paste, + int paste_into) { Layer * float_layer; int x1, y1, x2, y2; @@ -315,6 +316,48 @@ edit_paste (GImage *gimage, else return NULL; } + +int +edit_paste_as_new (GImage *invoke, + TileManager *paste) +{ + GImage *gimage; + GimpDrawable *drawable; + Layer *layer; + Layer *float_layer; + GDisplay *gdisp; + + if (!global_buf) + return FALSE; + + /* create a new image */ + gimage = gimage_new (paste->width, paste->height, invoke->base_type); + gimp_image_set_resolution (gimage, invoke->xresolution, invoke->yresolution); + gimp_image_set_unit (gimage, invoke->unit); + + layer = layer_new (gimage, gimage->width, gimage->height, + (invoke->base_type == RGB) ? RGBA_GIMAGE : GRAYA_GIMAGE, + _("Pasted Layer"), OPAQUE_OPACITY, NORMAL); + + /* add the new layer to the image */ + gimage_disable_undo (gimage); + gimage_add_layer (gimage, layer, 0); + drawable = gimage_active_drawable (gimage); + drawable_fill (GIMP_DRAWABLE (drawable), TRANSPARENT_FILL); + + /* make a new floating layer */ + float_layer = layer_from_tiles (gimage, drawable, paste, + _("Pasted Layer"), OPAQUE_OPACITY, NORMAL); + + /* add the new floating selection */ + floating_sel_attach (float_layer, drawable); + floating_sel_anchor (float_layer); + gimage_enable_undo (gimage); + gdisp = gdisplay_new (gimage, 0x0101); + gimp_context_set_display (gimp_context_get_user (), gdisp); + + return TRUE; +} gboolean edit_clear (GImage *gimage, @@ -434,7 +477,8 @@ global_edit_paste (void *gdisp_ptr, gdisp = (GDisplay *) gdisp_ptr; active_tool_control (HALT, gdisp_ptr); - if (!edit_paste (gdisp->gimage, gimage_active_drawable (gdisp->gimage), global_buf, paste_into)) + if (!edit_paste (gdisp->gimage, gimage_active_drawable (gdisp->gimage), + global_buf, paste_into)) return FALSE; else { @@ -444,6 +488,21 @@ global_edit_paste (void *gdisp_ptr, } } +int +global_edit_paste_as_new (void *gdisp_ptr) +{ + GDisplay *gdisp; + + if (!global_buf) + return FALSE; + + /* stop any active tool */ + gdisp = (GDisplay *) gdisp_ptr; + active_tool_control (HALT, gdisp_ptr); + + return (edit_paste_as_new (gdisp->gimage, global_buf)); +} + void global_edit_free () { @@ -489,9 +548,12 @@ named_buffer_paste_foreach (GtkWidget *w, { pn_dlg = (PasteNamedDlg *) client_data; nb = (NamedBuffer *) gtk_object_get_user_data (GTK_OBJECT (w)); - edit_paste (pn_dlg->gdisp->gimage, - gimage_active_drawable (pn_dlg->gdisp->gimage), - nb->buf, pn_dlg->paste_into); + if (pn_dlg->paste_as_new) + edit_paste_as_new (pn_dlg->gdisp->gimage, nb->buf); + else + edit_paste (pn_dlg->gdisp->gimage, + gimage_active_drawable (pn_dlg->gdisp->gimage), + nb->buf, pn_dlg->paste_into); } } @@ -578,9 +640,23 @@ named_buffer_paste_into_update (GtkWidget *w, pn_dlg = (PasteNamedDlg *) client_data; if (GTK_TOGGLE_BUTTON (w)->active) - pn_dlg->paste_into = FALSE; - else pn_dlg->paste_into = TRUE; + else + pn_dlg->paste_into = FALSE; +} + +static void +named_buffer_paste_as_new_update (GtkWidget *w, + gpointer client_data) +{ + PasteNamedDlg *pn_dlg; + + pn_dlg = (PasteNamedDlg *) client_data; + + if (GTK_TOGGLE_BUTTON (w)->active) + pn_dlg->paste_as_new = TRUE; + else + pn_dlg->paste_as_new = FALSE; } static void @@ -595,12 +671,14 @@ paste_named_buffer (GDisplay *gdisp) PasteNamedDlg *pn_dlg; GtkWidget *vbox; GtkWidget *label; - GtkWidget *paste_into; + GtkWidget *toggle; GtkWidget *listbox; pn_dlg = (PasteNamedDlg *) g_malloc (sizeof (PasteNamedDlg)); pn_dlg->gdisp = gdisp; - + pn_dlg->paste_into = FALSE; + pn_dlg->paste_as_new = FALSE; + pn_dlg->shell = gtk_dialog_new (); gtk_window_set_wmclass (GTK_WINDOW (pn_dlg->shell), "paste_named_buffer", "Gimp"); gtk_window_set_title (GTK_WINDOW (pn_dlg->shell), _("Paste Named Buffer")); @@ -634,12 +712,21 @@ paste_named_buffer (GDisplay *gdisp) set_list_of_named_buffers (pn_dlg->list); gtk_widget_show (pn_dlg->list); - paste_into = gtk_check_button_new_with_label (_("Replace Current Selection")); - gtk_box_pack_start (GTK_BOX (vbox), paste_into, FALSE, FALSE, 0); - gtk_signal_connect (GTK_OBJECT (paste_into), "toggled", + toggle = gtk_check_button_new_with_label (_("Replace Current Selection")); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), (pn_dlg->paste_into)); + gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0); + gtk_signal_connect (GTK_OBJECT (toggle), "toggled", (GtkSignalFunc) named_buffer_paste_into_update, pn_dlg); - gtk_widget_show (paste_into); + gtk_widget_show (toggle); + + toggle = gtk_check_button_new_with_label (_("Paste As New")); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), (pn_dlg->paste_as_new)); + gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0); + gtk_signal_connect (GTK_OBJECT (toggle), "toggled", + (GtkSignalFunc) named_buffer_paste_as_new_update, + pn_dlg); + gtk_widget_show (toggle); action_items[0].user_data = pn_dlg; action_items[1].user_data = pn_dlg; diff --git a/app/core/gimpedit.h b/app/core/gimpedit.h index 2ce68096ab..68b2e4b9c6 100644 --- a/app/core/gimpedit.h +++ b/app/core/gimpedit.h @@ -21,22 +21,24 @@ #include "gimage.h" /* The interface functions */ -TileManager * crop_buffer (TileManager *, int); -TileManager * edit_cut (GImage *, GimpDrawable *); -TileManager * edit_copy (GImage *, GimpDrawable *); -GimpLayer* edit_paste (GImage *, GimpDrawable *, - TileManager *, int); -int edit_clear (GImage *, GimpDrawable *); -int edit_fill (GImage *, GimpDrawable *); +TileManager * crop_buffer (TileManager *, int); +TileManager * edit_cut (GImage *, GimpDrawable *); +TileManager * edit_copy (GImage *, GimpDrawable *); +GimpLayer* edit_paste (GImage *, GimpDrawable *, + TileManager *, int); +int edit_paste_as_new (GImage *, TileManager *); +int edit_clear (GImage *, GimpDrawable *); +int edit_fill (GImage *, GimpDrawable *); -int global_edit_cut (void *); -int global_edit_copy (void *); -int global_edit_paste (void *, int); -void global_edit_free (void); +int global_edit_cut (void *); +int global_edit_copy (void *); +int global_edit_paste (void *, int); +int global_edit_paste_as_new (void *); +void global_edit_free (void); -int named_edit_cut (void *); -int named_edit_copy (void *); -int named_edit_paste (void *); -void named_buffers_free (void); +int named_edit_cut (void *); +int named_edit_copy (void *); +int named_edit_paste (void *); +void named_buffers_free (void); #endif /* __GLOBAL_EDIT_H__ */ diff --git a/app/global_edit.c b/app/global_edit.c index 4f4e547a00..53f02ae123 100644 --- a/app/global_edit.c +++ b/app/global_edit.c @@ -45,6 +45,7 @@ struct _PasteNamedDlg GtkWidget *shell; GtkWidget *list; int paste_into; + int paste_as_new; GDisplay *gdisp; }; @@ -271,10 +272,10 @@ edit_copy (GImage *gimage, } GimpLayer* -edit_paste (GImage *gimage, +edit_paste (GImage *gimage, GimpDrawable *drawable, - TileManager *paste, - int paste_into) + TileManager *paste, + int paste_into) { Layer * float_layer; int x1, y1, x2, y2; @@ -315,6 +316,48 @@ edit_paste (GImage *gimage, else return NULL; } + +int +edit_paste_as_new (GImage *invoke, + TileManager *paste) +{ + GImage *gimage; + GimpDrawable *drawable; + Layer *layer; + Layer *float_layer; + GDisplay *gdisp; + + if (!global_buf) + return FALSE; + + /* create a new image */ + gimage = gimage_new (paste->width, paste->height, invoke->base_type); + gimp_image_set_resolution (gimage, invoke->xresolution, invoke->yresolution); + gimp_image_set_unit (gimage, invoke->unit); + + layer = layer_new (gimage, gimage->width, gimage->height, + (invoke->base_type == RGB) ? RGBA_GIMAGE : GRAYA_GIMAGE, + _("Pasted Layer"), OPAQUE_OPACITY, NORMAL); + + /* add the new layer to the image */ + gimage_disable_undo (gimage); + gimage_add_layer (gimage, layer, 0); + drawable = gimage_active_drawable (gimage); + drawable_fill (GIMP_DRAWABLE (drawable), TRANSPARENT_FILL); + + /* make a new floating layer */ + float_layer = layer_from_tiles (gimage, drawable, paste, + _("Pasted Layer"), OPAQUE_OPACITY, NORMAL); + + /* add the new floating selection */ + floating_sel_attach (float_layer, drawable); + floating_sel_anchor (float_layer); + gimage_enable_undo (gimage); + gdisp = gdisplay_new (gimage, 0x0101); + gimp_context_set_display (gimp_context_get_user (), gdisp); + + return TRUE; +} gboolean edit_clear (GImage *gimage, @@ -434,7 +477,8 @@ global_edit_paste (void *gdisp_ptr, gdisp = (GDisplay *) gdisp_ptr; active_tool_control (HALT, gdisp_ptr); - if (!edit_paste (gdisp->gimage, gimage_active_drawable (gdisp->gimage), global_buf, paste_into)) + if (!edit_paste (gdisp->gimage, gimage_active_drawable (gdisp->gimage), + global_buf, paste_into)) return FALSE; else { @@ -444,6 +488,21 @@ global_edit_paste (void *gdisp_ptr, } } +int +global_edit_paste_as_new (void *gdisp_ptr) +{ + GDisplay *gdisp; + + if (!global_buf) + return FALSE; + + /* stop any active tool */ + gdisp = (GDisplay *) gdisp_ptr; + active_tool_control (HALT, gdisp_ptr); + + return (edit_paste_as_new (gdisp->gimage, global_buf)); +} + void global_edit_free () { @@ -489,9 +548,12 @@ named_buffer_paste_foreach (GtkWidget *w, { pn_dlg = (PasteNamedDlg *) client_data; nb = (NamedBuffer *) gtk_object_get_user_data (GTK_OBJECT (w)); - edit_paste (pn_dlg->gdisp->gimage, - gimage_active_drawable (pn_dlg->gdisp->gimage), - nb->buf, pn_dlg->paste_into); + if (pn_dlg->paste_as_new) + edit_paste_as_new (pn_dlg->gdisp->gimage, nb->buf); + else + edit_paste (pn_dlg->gdisp->gimage, + gimage_active_drawable (pn_dlg->gdisp->gimage), + nb->buf, pn_dlg->paste_into); } } @@ -578,9 +640,23 @@ named_buffer_paste_into_update (GtkWidget *w, pn_dlg = (PasteNamedDlg *) client_data; if (GTK_TOGGLE_BUTTON (w)->active) - pn_dlg->paste_into = FALSE; - else pn_dlg->paste_into = TRUE; + else + pn_dlg->paste_into = FALSE; +} + +static void +named_buffer_paste_as_new_update (GtkWidget *w, + gpointer client_data) +{ + PasteNamedDlg *pn_dlg; + + pn_dlg = (PasteNamedDlg *) client_data; + + if (GTK_TOGGLE_BUTTON (w)->active) + pn_dlg->paste_as_new = TRUE; + else + pn_dlg->paste_as_new = FALSE; } static void @@ -595,12 +671,14 @@ paste_named_buffer (GDisplay *gdisp) PasteNamedDlg *pn_dlg; GtkWidget *vbox; GtkWidget *label; - GtkWidget *paste_into; + GtkWidget *toggle; GtkWidget *listbox; pn_dlg = (PasteNamedDlg *) g_malloc (sizeof (PasteNamedDlg)); pn_dlg->gdisp = gdisp; - + pn_dlg->paste_into = FALSE; + pn_dlg->paste_as_new = FALSE; + pn_dlg->shell = gtk_dialog_new (); gtk_window_set_wmclass (GTK_WINDOW (pn_dlg->shell), "paste_named_buffer", "Gimp"); gtk_window_set_title (GTK_WINDOW (pn_dlg->shell), _("Paste Named Buffer")); @@ -634,12 +712,21 @@ paste_named_buffer (GDisplay *gdisp) set_list_of_named_buffers (pn_dlg->list); gtk_widget_show (pn_dlg->list); - paste_into = gtk_check_button_new_with_label (_("Replace Current Selection")); - gtk_box_pack_start (GTK_BOX (vbox), paste_into, FALSE, FALSE, 0); - gtk_signal_connect (GTK_OBJECT (paste_into), "toggled", + toggle = gtk_check_button_new_with_label (_("Replace Current Selection")); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), (pn_dlg->paste_into)); + gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0); + gtk_signal_connect (GTK_OBJECT (toggle), "toggled", (GtkSignalFunc) named_buffer_paste_into_update, pn_dlg); - gtk_widget_show (paste_into); + gtk_widget_show (toggle); + + toggle = gtk_check_button_new_with_label (_("Paste As New")); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), (pn_dlg->paste_as_new)); + gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0); + gtk_signal_connect (GTK_OBJECT (toggle), "toggled", + (GtkSignalFunc) named_buffer_paste_as_new_update, + pn_dlg); + gtk_widget_show (toggle); action_items[0].user_data = pn_dlg; action_items[1].user_data = pn_dlg; diff --git a/app/global_edit.h b/app/global_edit.h index 2ce68096ab..68b2e4b9c6 100644 --- a/app/global_edit.h +++ b/app/global_edit.h @@ -21,22 +21,24 @@ #include "gimage.h" /* The interface functions */ -TileManager * crop_buffer (TileManager *, int); -TileManager * edit_cut (GImage *, GimpDrawable *); -TileManager * edit_copy (GImage *, GimpDrawable *); -GimpLayer* edit_paste (GImage *, GimpDrawable *, - TileManager *, int); -int edit_clear (GImage *, GimpDrawable *); -int edit_fill (GImage *, GimpDrawable *); +TileManager * crop_buffer (TileManager *, int); +TileManager * edit_cut (GImage *, GimpDrawable *); +TileManager * edit_copy (GImage *, GimpDrawable *); +GimpLayer* edit_paste (GImage *, GimpDrawable *, + TileManager *, int); +int edit_paste_as_new (GImage *, TileManager *); +int edit_clear (GImage *, GimpDrawable *); +int edit_fill (GImage *, GimpDrawable *); -int global_edit_cut (void *); -int global_edit_copy (void *); -int global_edit_paste (void *, int); -void global_edit_free (void); +int global_edit_cut (void *); +int global_edit_copy (void *); +int global_edit_paste (void *, int); +int global_edit_paste_as_new (void *); +void global_edit_free (void); -int named_edit_cut (void *); -int named_edit_copy (void *); -int named_edit_paste (void *); -void named_buffers_free (void); +int named_edit_cut (void *); +int named_edit_copy (void *); +int named_edit_paste (void *); +void named_buffers_free (void); #endif /* __GLOBAL_EDIT_H__ */ diff --git a/app/gui/commands.c b/app/gui/commands.c index 23aeb4834e..3e29b22516 100644 --- a/app/gui/commands.c +++ b/app/gui/commands.c @@ -183,6 +183,16 @@ edit_paste_into_cmd_callback (GtkWidget *widget, global_edit_paste (gdisp, 1); } +void +edit_paste_as_new_cmd_callback (GtkWidget *widget, + gpointer client_data) +{ + GDisplay * gdisp; + return_if_no_display (gdisp); + + global_edit_paste_as_new (gdisp); +} + void edit_clear_cmd_callback (GtkWidget *widget, gpointer client_data) diff --git a/app/gui/commands.h b/app/gui/commands.h index 86edf36fe5..274436bd6a 100644 --- a/app/gui/commands.h +++ b/app/gui/commands.h @@ -14,18 +14,19 @@ void file_pref_cmd_callback (GtkWidget *, gpointer); void file_close_cmd_callback (GtkWidget *, gpointer); void file_quit_cmd_callback (GtkWidget *, gpointer); -void edit_cut_cmd_callback (GtkWidget *, gpointer); -void edit_copy_cmd_callback (GtkWidget *, gpointer); -void edit_paste_cmd_callback (GtkWidget *, gpointer); -void edit_paste_into_cmd_callback (GtkWidget *, gpointer); -void edit_clear_cmd_callback (GtkWidget *, gpointer); -void edit_fill_cmd_callback (GtkWidget *, gpointer); -void edit_stroke_cmd_callback (GtkWidget *, gpointer); -void edit_undo_cmd_callback (GtkWidget *, gpointer); -void edit_redo_cmd_callback (GtkWidget *, gpointer); -void edit_named_cut_cmd_callback (GtkWidget *, gpointer); -void edit_named_copy_cmd_callback (GtkWidget *, gpointer); -void edit_named_paste_cmd_callback (GtkWidget *, gpointer); +void edit_cut_cmd_callback (GtkWidget *, gpointer); +void edit_copy_cmd_callback (GtkWidget *, gpointer); +void edit_paste_cmd_callback (GtkWidget *, gpointer); +void edit_paste_into_cmd_callback (GtkWidget *, gpointer); +void edit_paste_as_new_cmd_callback (GtkWidget *, gpointer); +void edit_clear_cmd_callback (GtkWidget *, gpointer); +void edit_fill_cmd_callback (GtkWidget *, gpointer); +void edit_stroke_cmd_callback (GtkWidget *, gpointer); +void edit_undo_cmd_callback (GtkWidget *, gpointer); +void edit_redo_cmd_callback (GtkWidget *, gpointer); +void edit_named_cut_cmd_callback (GtkWidget *, gpointer); +void edit_named_copy_cmd_callback (GtkWidget *, gpointer); +void edit_named_paste_cmd_callback (GtkWidget *, gpointer); void select_invert_cmd_callback (GtkWidget *, gpointer); void select_all_cmd_callback (GtkWidget *, gpointer); diff --git a/app/gui/help-commands.c b/app/gui/help-commands.c index 23aeb4834e..3e29b22516 100644 --- a/app/gui/help-commands.c +++ b/app/gui/help-commands.c @@ -183,6 +183,16 @@ edit_paste_into_cmd_callback (GtkWidget *widget, global_edit_paste (gdisp, 1); } +void +edit_paste_as_new_cmd_callback (GtkWidget *widget, + gpointer client_data) +{ + GDisplay * gdisp; + return_if_no_display (gdisp); + + global_edit_paste_as_new (gdisp); +} + void edit_clear_cmd_callback (GtkWidget *widget, gpointer client_data) diff --git a/app/gui/help-commands.h b/app/gui/help-commands.h index 86edf36fe5..274436bd6a 100644 --- a/app/gui/help-commands.h +++ b/app/gui/help-commands.h @@ -14,18 +14,19 @@ void file_pref_cmd_callback (GtkWidget *, gpointer); void file_close_cmd_callback (GtkWidget *, gpointer); void file_quit_cmd_callback (GtkWidget *, gpointer); -void edit_cut_cmd_callback (GtkWidget *, gpointer); -void edit_copy_cmd_callback (GtkWidget *, gpointer); -void edit_paste_cmd_callback (GtkWidget *, gpointer); -void edit_paste_into_cmd_callback (GtkWidget *, gpointer); -void edit_clear_cmd_callback (GtkWidget *, gpointer); -void edit_fill_cmd_callback (GtkWidget *, gpointer); -void edit_stroke_cmd_callback (GtkWidget *, gpointer); -void edit_undo_cmd_callback (GtkWidget *, gpointer); -void edit_redo_cmd_callback (GtkWidget *, gpointer); -void edit_named_cut_cmd_callback (GtkWidget *, gpointer); -void edit_named_copy_cmd_callback (GtkWidget *, gpointer); -void edit_named_paste_cmd_callback (GtkWidget *, gpointer); +void edit_cut_cmd_callback (GtkWidget *, gpointer); +void edit_copy_cmd_callback (GtkWidget *, gpointer); +void edit_paste_cmd_callback (GtkWidget *, gpointer); +void edit_paste_into_cmd_callback (GtkWidget *, gpointer); +void edit_paste_as_new_cmd_callback (GtkWidget *, gpointer); +void edit_clear_cmd_callback (GtkWidget *, gpointer); +void edit_fill_cmd_callback (GtkWidget *, gpointer); +void edit_stroke_cmd_callback (GtkWidget *, gpointer); +void edit_undo_cmd_callback (GtkWidget *, gpointer); +void edit_redo_cmd_callback (GtkWidget *, gpointer); +void edit_named_cut_cmd_callback (GtkWidget *, gpointer); +void edit_named_copy_cmd_callback (GtkWidget *, gpointer); +void edit_named_paste_cmd_callback (GtkWidget *, gpointer); void select_invert_cmd_callback (GtkWidget *, gpointer); void select_all_cmd_callback (GtkWidget *, gpointer); diff --git a/app/gui/menus.c b/app/gui/menus.c index 27bde8c3c0..25bc317348 100644 --- a/app/gui/menus.c +++ b/app/gui/menus.c @@ -103,6 +103,8 @@ static GtkItemFactoryEntry image_entries[] = { N_("/Edit/Copy"), "C", edit_copy_cmd_callback, 0 }, { N_("/Edit/Paste"), "V", edit_paste_cmd_callback, 0 }, { N_("/Edit/Paste Into"), NULL, edit_paste_into_cmd_callback, 0 }, + { N_("/Edit/Paste As New"), NULL, edit_paste_as_new_cmd_callback, 0 }, + { N_("/Edit/---"), NULL, NULL, 0, "" }, { N_("/Edit/Clear"), "K", edit_clear_cmd_callback, 0 }, { N_("/Edit/Fill"), "period", edit_fill_cmd_callback, 0 }, { N_("/Edit/Stroke"), NULL, edit_stroke_cmd_callback, 0 }, diff --git a/app/menus.c b/app/menus.c index 27bde8c3c0..25bc317348 100644 --- a/app/menus.c +++ b/app/menus.c @@ -103,6 +103,8 @@ static GtkItemFactoryEntry image_entries[] = { N_("/Edit/Copy"), "C", edit_copy_cmd_callback, 0 }, { N_("/Edit/Paste"), "V", edit_paste_cmd_callback, 0 }, { N_("/Edit/Paste Into"), NULL, edit_paste_into_cmd_callback, 0 }, + { N_("/Edit/Paste As New"), NULL, edit_paste_as_new_cmd_callback, 0 }, + { N_("/Edit/---"), NULL, NULL, 0, "" }, { N_("/Edit/Clear"), "K", edit_clear_cmd_callback, 0 }, { N_("/Edit/Fill"), "period", edit_fill_cmd_callback, 0 }, { N_("/Edit/Stroke"), NULL, edit_stroke_cmd_callback, 0 }, diff --git a/app/menus/menus.c b/app/menus/menus.c index 27bde8c3c0..25bc317348 100644 --- a/app/menus/menus.c +++ b/app/menus/menus.c @@ -103,6 +103,8 @@ static GtkItemFactoryEntry image_entries[] = { N_("/Edit/Copy"), "C", edit_copy_cmd_callback, 0 }, { N_("/Edit/Paste"), "V", edit_paste_cmd_callback, 0 }, { N_("/Edit/Paste Into"), NULL, edit_paste_into_cmd_callback, 0 }, + { N_("/Edit/Paste As New"), NULL, edit_paste_as_new_cmd_callback, 0 }, + { N_("/Edit/---"), NULL, NULL, 0, "" }, { N_("/Edit/Clear"), "K", edit_clear_cmd_callback, 0 }, { N_("/Edit/Fill"), "period", edit_fill_cmd_callback, 0 }, { N_("/Edit/Stroke"), NULL, edit_stroke_cmd_callback, 0 }, diff --git a/app/widgets/gimpitemfactory.c b/app/widgets/gimpitemfactory.c index 27bde8c3c0..25bc317348 100644 --- a/app/widgets/gimpitemfactory.c +++ b/app/widgets/gimpitemfactory.c @@ -103,6 +103,8 @@ static GtkItemFactoryEntry image_entries[] = { N_("/Edit/Copy"), "C", edit_copy_cmd_callback, 0 }, { N_("/Edit/Paste"), "V", edit_paste_cmd_callback, 0 }, { N_("/Edit/Paste Into"), NULL, edit_paste_into_cmd_callback, 0 }, + { N_("/Edit/Paste As New"), NULL, edit_paste_as_new_cmd_callback, 0 }, + { N_("/Edit/---"), NULL, NULL, 0, "" }, { N_("/Edit/Clear"), "K", edit_clear_cmd_callback, 0 }, { N_("/Edit/Fill"), "period", edit_fill_cmd_callback, 0 }, { N_("/Edit/Stroke"), NULL, edit_stroke_cmd_callback, 0 },