2006-12-09 21:33:38 +00:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2001-06-26 12:09:43 +00:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-17 22:28:01 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2001-06-26 12:09:43 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-17 22:28:01 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2001-06-26 12:09:43 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2018-07-11 23:27:07 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2001-06-26 12:09:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2002-03-28 00:10:56 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2008-10-09 20:24:04 +00:00
|
|
|
#include <gegl.h>
|
2001-06-26 12:09:43 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2005-05-07 13:56:05 +00:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2001-06-26 12:09:43 +00:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
2004-04-20 13:25:55 +00:00
|
|
|
#include "actions-types.h"
|
2001-06-26 12:09:43 +00:00
|
|
|
|
2001-07-04 19:31:35 +00:00
|
|
|
#include "core/gimp.h"
|
2003-09-15 17:26:28 +00:00
|
|
|
#include "core/gimp-edit.h"
|
2001-06-26 12:09:43 +00:00
|
|
|
#include "core/gimpbuffer.h"
|
|
|
|
#include "core/gimpcontainer.h"
|
|
|
|
#include "core/gimpdrawable.h"
|
2018-04-18 23:44:34 +02:00
|
|
|
#include "core/gimpdrawable-edit.h"
|
2024-03-12 13:29:36 +00:00
|
|
|
#include "core/gimpdrawable-filters.h"
|
|
|
|
#include "core/gimpdrawablefilter.h"
|
2016-03-11 19:52:36 +01:00
|
|
|
#include "core/gimpfilloptions.h"
|
2008-08-07 17:19:32 +00:00
|
|
|
#include "core/gimplayer.h"
|
2015-06-17 13:21:01 +02:00
|
|
|
#include "core/gimplayer-new.h"
|
2022-10-29 18:53:44 +00:00
|
|
|
#include "core/gimplayermask.h"
|
2024-03-12 13:29:36 +00:00
|
|
|
#include "core/gimplist.h"
|
2001-06-26 12:09:43 +00:00
|
|
|
#include "core/gimpimage.h"
|
2003-02-12 17:11:34 +00:00
|
|
|
#include "core/gimpimage-undo.h"
|
2001-06-26 12:09:43 +00:00
|
|
|
|
2024-07-13 05:07:57 +00:00
|
|
|
#include "vectors/gimppath-import.h"
|
2005-05-16 12:31:04 +00:00
|
|
|
|
2004-07-07 14:38:23 +00:00
|
|
|
#include "widgets/gimpclipboard.h"
|
2003-08-21 15:54:47 +00:00
|
|
|
#include "widgets/gimphelp-ids.h"
|
2001-06-29 19:25:03 +00:00
|
|
|
#include "widgets/gimpdialogfactory.h"
|
2004-10-13 15:27:00 +00:00
|
|
|
#include "widgets/gimpmessagebox.h"
|
|
|
|
#include "widgets/gimpmessagedialog.h"
|
2014-05-02 03:01:23 +02:00
|
|
|
#include "widgets/gimpwidgets-utils.h"
|
2012-01-30 23:33:21 +01:00
|
|
|
#include "widgets/gimpwindowstrategy.h"
|
2001-06-29 19:25:03 +00:00
|
|
|
|
2009-06-21 23:37:18 +02:00
|
|
|
#include "display/gimpdisplay.h"
|
|
|
|
#include "display/gimpdisplayshell.h"
|
|
|
|
#include "display/gimpdisplayshell-transform.h"
|
|
|
|
|
2018-12-31 04:37:50 -05:00
|
|
|
#include "tools/gimptools-utils.h"
|
2013-05-12 19:51:52 +02:00
|
|
|
#include "tools/tool_manager.h"
|
|
|
|
|
2004-05-03 14:03:51 +00:00
|
|
|
#include "actions.h"
|
2001-06-26 12:09:43 +00:00
|
|
|
#include "edit-commands.h"
|
|
|
|
|
2003-03-25 16:38:19 +00:00
|
|
|
#include "gimp-intl.h"
|
2001-06-26 12:09:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* local function prototypes */
|
|
|
|
|
2018-12-31 04:37:50 -05:00
|
|
|
static gboolean check_drawable_alpha (GimpDrawable *drawable,
|
|
|
|
gpointer data);
|
|
|
|
static void edit_paste (GimpDisplay *display,
|
|
|
|
GimpPasteType paste_type,
|
2022-11-12 22:17:00 +01:00
|
|
|
gboolean merged,
|
2018-12-31 04:37:50 -05:00
|
|
|
gboolean try_svg);
|
|
|
|
static void cut_named_buffer_callback (GtkWidget *widget,
|
|
|
|
const gchar *name,
|
|
|
|
gpointer data);
|
|
|
|
static void copy_named_buffer_callback (GtkWidget *widget,
|
|
|
|
const gchar *name,
|
|
|
|
gpointer data);
|
|
|
|
static void copy_named_visible_buffer_callback (GtkWidget *widget,
|
|
|
|
const gchar *name,
|
|
|
|
gpointer data);
|
2001-06-26 12:09:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
|
|
|
void
|
2019-07-02 16:12:18 +02:00
|
|
|
edit_undo_cmd_callback (GimpAction *action,
|
2019-07-04 01:11:48 +02:00
|
|
|
GVariant *value,
|
2019-07-02 16:12:18 +02:00
|
|
|
gpointer data)
|
2001-06-26 12:09:43 +00:00
|
|
|
{
|
2013-05-12 19:51:52 +02:00
|
|
|
GimpImage *image;
|
|
|
|
GimpDisplay *display;
|
2006-03-28 17:08:36 +00:00
|
|
|
return_if_no_image (image, data);
|
2013-05-12 19:51:52 +02:00
|
|
|
return_if_no_display (display, data);
|
2001-06-26 12:09:43 +00:00
|
|
|
|
2013-05-12 19:51:52 +02:00
|
|
|
if (tool_manager_undo_active (image->gimp, display) ||
|
|
|
|
gimp_image_undo (image))
|
|
|
|
{
|
|
|
|
gimp_image_flush (image);
|
|
|
|
}
|
2001-06-26 12:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-07-02 16:12:18 +02:00
|
|
|
edit_redo_cmd_callback (GimpAction *action,
|
2019-07-04 01:11:48 +02:00
|
|
|
GVariant *value,
|
2019-07-02 16:12:18 +02:00
|
|
|
gpointer data)
|
2001-06-26 12:09:43 +00:00
|
|
|
{
|
2013-05-12 19:51:52 +02:00
|
|
|
GimpImage *image;
|
|
|
|
GimpDisplay *display;
|
2006-03-28 17:08:36 +00:00
|
|
|
return_if_no_image (image, data);
|
2013-05-12 19:51:52 +02:00
|
|
|
return_if_no_display (display, data);
|
2001-06-26 12:09:43 +00:00
|
|
|
|
2013-05-12 19:51:52 +02:00
|
|
|
if (tool_manager_redo_active (image->gimp, display) ||
|
|
|
|
gimp_image_redo (image))
|
|
|
|
{
|
|
|
|
gimp_image_flush (image);
|
|
|
|
}
|
2001-06-26 12:09:43 +00:00
|
|
|
}
|
|
|
|
|
2006-06-13 02:03:44 +00:00
|
|
|
void
|
2019-07-02 16:12:18 +02:00
|
|
|
edit_strong_undo_cmd_callback (GimpAction *action,
|
2019-07-04 01:11:48 +02:00
|
|
|
GVariant *value,
|
2019-07-02 16:12:18 +02:00
|
|
|
gpointer data)
|
2006-06-13 02:03:44 +00:00
|
|
|
{
|
|
|
|
GimpImage *image;
|
|
|
|
return_if_no_image (image, data);
|
|
|
|
|
|
|
|
if (gimp_image_strong_undo (image))
|
|
|
|
gimp_image_flush (image);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-07-02 16:12:18 +02:00
|
|
|
edit_strong_redo_cmd_callback (GimpAction *action,
|
2019-07-04 01:11:48 +02:00
|
|
|
GVariant *value,
|
2019-07-02 16:12:18 +02:00
|
|
|
gpointer data)
|
2006-06-13 02:03:44 +00:00
|
|
|
{
|
|
|
|
GimpImage *image;
|
|
|
|
return_if_no_image (image, data);
|
|
|
|
|
|
|
|
if (gimp_image_strong_redo (image))
|
|
|
|
gimp_image_flush (image);
|
|
|
|
}
|
|
|
|
|
2004-05-12 18:36:33 +00:00
|
|
|
void
|
2019-07-02 16:12:18 +02:00
|
|
|
edit_undo_clear_cmd_callback (GimpAction *action,
|
2019-07-04 01:11:48 +02:00
|
|
|
GVariant *value,
|
2019-07-02 16:12:18 +02:00
|
|
|
gpointer data)
|
2004-05-12 18:36:33 +00:00
|
|
|
{
|
2010-02-04 20:06:49 +01:00
|
|
|
GimpImage *image;
|
|
|
|
GimpUndoStack *undo_stack;
|
|
|
|
GimpUndoStack *redo_stack;
|
|
|
|
GtkWidget *widget;
|
|
|
|
GtkWidget *dialog;
|
|
|
|
gchar *size;
|
|
|
|
gint64 memsize;
|
|
|
|
gint64 guisize;
|
2006-03-28 17:08:36 +00:00
|
|
|
return_if_no_image (image, data);
|
2004-05-12 18:36:33 +00:00
|
|
|
return_if_no_widget (widget, data);
|
|
|
|
|
2017-03-05 16:01:59 +01:00
|
|
|
dialog = gimp_message_dialog_new (_("Clear Undo History"),
|
|
|
|
GIMP_ICON_DIALOG_WARNING,
|
2005-07-08 15:27:38 +00:00
|
|
|
widget,
|
|
|
|
GTK_DIALOG_MODAL |
|
|
|
|
GTK_DIALOG_DESTROY_WITH_PARENT,
|
2005-05-07 14:27:47 +00:00
|
|
|
gimp_standard_help_func,
|
|
|
|
GIMP_HELP_EDIT_UNDO_CLEAR,
|
2004-10-13 15:27:00 +00:00
|
|
|
|
2017-02-12 16:06:34 +01:00
|
|
|
_("_Cancel"), GTK_RESPONSE_CANCEL,
|
|
|
|
_("Cl_ear"), GTK_RESPONSE_OK,
|
2004-10-13 15:27:00 +00:00
|
|
|
|
|
|
|
NULL);
|
|
|
|
|
2018-05-10 17:04:37 +02:00
|
|
|
gimp_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
|
2005-02-10 11:00:46 +00:00
|
|
|
GTK_RESPONSE_OK,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
-1);
|
|
|
|
|
2005-07-08 15:27:38 +00:00
|
|
|
g_signal_connect_object (gtk_widget_get_toplevel (widget), "unmap",
|
2004-10-13 15:27:00 +00:00
|
|
|
G_CALLBACK (gtk_widget_destroy),
|
|
|
|
dialog, G_CONNECT_SWAPPED);
|
|
|
|
|
2006-03-28 17:08:36 +00:00
|
|
|
g_signal_connect_object (image, "disconnect",
|
2005-07-08 15:27:38 +00:00
|
|
|
G_CALLBACK (gtk_widget_destroy),
|
|
|
|
dialog, G_CONNECT_SWAPPED);
|
2004-10-13 15:27:00 +00:00
|
|
|
|
|
|
|
gimp_message_box_set_primary_text (GIMP_MESSAGE_DIALOG (dialog)->box,
|
|
|
|
_("Really clear image's undo history?"));
|
|
|
|
|
2010-02-04 20:06:49 +01:00
|
|
|
undo_stack = gimp_image_get_undo_stack (image);
|
|
|
|
redo_stack = gimp_image_get_redo_stack (image);
|
|
|
|
|
|
|
|
memsize = gimp_object_get_memsize (GIMP_OBJECT (undo_stack), &guisize);
|
2005-05-07 13:56:05 +00:00
|
|
|
memsize += guisize;
|
2010-02-04 20:06:49 +01:00
|
|
|
memsize += gimp_object_get_memsize (GIMP_OBJECT (redo_stack), &guisize);
|
2005-05-07 13:56:05 +00:00
|
|
|
memsize += guisize;
|
|
|
|
|
2011-09-13 11:39:24 +02:00
|
|
|
size = g_format_size (memsize);
|
2005-05-07 13:56:05 +00:00
|
|
|
|
|
|
|
gimp_message_box_set_text (GIMP_MESSAGE_DIALOG (dialog)->box,
|
|
|
|
_("Clearing the undo history of this "
|
|
|
|
"image will gain %s of memory."), size);
|
|
|
|
g_free (size);
|
|
|
|
|
2005-07-08 15:27:38 +00:00
|
|
|
if (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK)
|
|
|
|
{
|
2006-03-28 17:08:36 +00:00
|
|
|
gimp_image_undo_disable (image);
|
|
|
|
gimp_image_undo_enable (image);
|
|
|
|
gimp_image_flush (image);
|
2005-07-08 15:27:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_destroy (dialog);
|
2004-05-12 18:36:33 +00:00
|
|
|
}
|
|
|
|
|
2001-06-26 12:09:43 +00:00
|
|
|
void
|
2019-07-02 16:12:18 +02:00
|
|
|
edit_cut_cmd_callback (GimpAction *action,
|
2019-07-04 01:11:48 +02:00
|
|
|
GVariant *value,
|
2019-07-02 16:12:18 +02:00
|
|
|
gpointer data)
|
2001-06-26 12:09:43 +00:00
|
|
|
{
|
2006-03-28 17:08:36 +00:00
|
|
|
GimpImage *image;
|
2020-05-26 16:15:15 +02:00
|
|
|
GList *drawables;
|
|
|
|
GList *iter;
|
2016-09-19 23:53:40 +02:00
|
|
|
GimpObject *cut;
|
2007-12-14 13:58:10 +00:00
|
|
|
GError *error = NULL;
|
2020-05-26 16:15:15 +02:00
|
|
|
return_if_no_drawables (image, drawables, data);
|
2001-06-26 12:09:43 +00:00
|
|
|
|
2020-05-26 16:15:15 +02:00
|
|
|
for (iter = drawables; iter; iter = iter->next)
|
|
|
|
if (! check_drawable_alpha (iter->data, data))
|
|
|
|
{
|
|
|
|
g_list_free (drawables);
|
|
|
|
return;
|
|
|
|
}
|
2018-12-31 04:37:50 -05:00
|
|
|
|
2020-05-26 16:15:15 +02:00
|
|
|
cut = gimp_edit_cut (image, drawables, action_data_get_context (data), &error);
|
2016-09-19 23:53:40 +02:00
|
|
|
|
|
|
|
if (cut)
|
2007-12-14 13:58:10 +00:00
|
|
|
{
|
2008-03-04 21:37:52 +00:00
|
|
|
GimpDisplay *display = action_data_get_display (data);
|
|
|
|
|
|
|
|
if (display)
|
app, libgimp, pdb, plug-ins: allow pasting multiple full layers.
When a selection exists, we are copying then pasting the selection
contents. In particular, with multi-layer selection, it means pasting a
merged result of the selected layers (like a sample merged but limited
to selected layers).
Yet when no selection exists, with a single layer selected, a cut in
particular would remove the layer fully, then a paste would copy it
elsewhere (in the same image or even on a different image). This was
still working, but not with multiple layers. This is now fixed and we
can now copy/cut then paste several layers (without merge), which is
sometimes a very practical way to move layers (sometimes simpler than
drag'n drop, especially between images).
As a consequence, the PDB function gimp_edit_paste() now also returns an
array of layers (not a single layer).
2021-04-24 22:45:09 +02:00
|
|
|
{
|
|
|
|
gchar *msg;
|
|
|
|
|
|
|
|
if (GIMP_IS_IMAGE (cut))
|
|
|
|
msg = g_strdup_printf (ngettext ("Cut layer to the clipboard.",
|
|
|
|
"Cut %d layers to the clipboard.",
|
|
|
|
g_list_length (drawables)),
|
|
|
|
g_list_length (drawables));
|
|
|
|
else
|
|
|
|
msg = g_strdup (_("Cut pixels to the clipboard."));
|
|
|
|
|
|
|
|
gimp_message_literal (image->gimp,
|
|
|
|
G_OBJECT (display), GIMP_MESSAGE_INFO,
|
|
|
|
msg);
|
|
|
|
g_free (msg);
|
|
|
|
}
|
2008-03-04 21:37:52 +00:00
|
|
|
|
2007-12-14 13:58:10 +00:00
|
|
|
gimp_image_flush (image);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-11-04 12:33:09 +00:00
|
|
|
gimp_message_literal (image->gimp,
|
2013-09-15 04:59:20 +12:00
|
|
|
G_OBJECT (action_data_get_display (data)),
|
|
|
|
GIMP_MESSAGE_WARNING,
|
|
|
|
error->message);
|
2007-12-14 13:58:10 +00:00
|
|
|
g_clear_error (&error);
|
|
|
|
}
|
2020-05-26 16:15:15 +02:00
|
|
|
g_list_free (drawables);
|
2001-06-26 12:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-07-02 16:12:18 +02:00
|
|
|
edit_copy_cmd_callback (GimpAction *action,
|
2019-07-04 01:11:48 +02:00
|
|
|
GVariant *value,
|
2019-07-02 16:12:18 +02:00
|
|
|
gpointer data)
|
2001-06-26 12:09:43 +00:00
|
|
|
{
|
2006-03-28 17:08:36 +00:00
|
|
|
GimpImage *image;
|
2020-05-06 15:46:51 +02:00
|
|
|
GList *drawables;
|
2016-09-19 23:53:40 +02:00
|
|
|
GimpObject *copy;
|
2007-12-14 13:58:10 +00:00
|
|
|
GError *error = NULL;
|
2020-05-06 15:46:51 +02:00
|
|
|
return_if_no_drawables (image, drawables, data);
|
2001-06-26 12:09:43 +00:00
|
|
|
|
2020-05-06 15:46:51 +02:00
|
|
|
copy = gimp_edit_copy (image, drawables, action_data_get_context (data),
|
2016-09-19 23:53:40 +02:00
|
|
|
&error);
|
|
|
|
|
|
|
|
if (copy)
|
2007-02-18 18:50:55 +00:00
|
|
|
{
|
|
|
|
GimpDisplay *display = action_data_get_display (data);
|
|
|
|
|
|
|
|
if (display)
|
2008-11-04 12:33:09 +00:00
|
|
|
gimp_message_literal (image->gimp,
|
2013-09-15 04:59:20 +12:00
|
|
|
G_OBJECT (display), GIMP_MESSAGE_INFO,
|
2016-09-19 23:53:40 +02:00
|
|
|
GIMP_IS_IMAGE (copy) ?
|
|
|
|
_("Copied layer to the clipboard.") :
|
|
|
|
_("Copied pixels to the clipboard."));
|
2007-02-18 18:50:55 +00:00
|
|
|
|
|
|
|
gimp_image_flush (image);
|
|
|
|
}
|
2007-12-14 13:58:10 +00:00
|
|
|
else
|
|
|
|
{
|
2008-11-04 12:33:09 +00:00
|
|
|
gimp_message_literal (image->gimp,
|
2013-09-15 04:59:20 +12:00
|
|
|
G_OBJECT (action_data_get_display (data)),
|
|
|
|
GIMP_MESSAGE_WARNING,
|
|
|
|
error->message);
|
2007-12-14 13:58:10 +00:00
|
|
|
g_clear_error (&error);
|
|
|
|
}
|
2020-05-06 15:46:51 +02:00
|
|
|
|
|
|
|
g_list_free (drawables);
|
2004-12-12 14:01:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-07-02 16:12:18 +02:00
|
|
|
edit_copy_visible_cmd_callback (GimpAction *action,
|
2019-07-04 01:11:48 +02:00
|
|
|
GVariant *value,
|
2019-07-02 16:12:18 +02:00
|
|
|
gpointer data)
|
2004-12-12 14:01:08 +00:00
|
|
|
{
|
2006-03-28 17:08:36 +00:00
|
|
|
GimpImage *image;
|
2007-12-14 13:58:10 +00:00
|
|
|
GError *error = NULL;
|
2006-03-28 17:08:36 +00:00
|
|
|
return_if_no_image (image, data);
|
2004-12-12 14:01:08 +00:00
|
|
|
|
2007-12-14 13:58:10 +00:00
|
|
|
if (gimp_edit_copy_visible (image, action_data_get_context (data), &error))
|
|
|
|
{
|
2008-03-04 21:37:52 +00:00
|
|
|
GimpDisplay *display = action_data_get_display (data);
|
|
|
|
|
|
|
|
if (display)
|
2008-11-04 12:33:09 +00:00
|
|
|
gimp_message_literal (image->gimp,
|
2013-09-15 04:59:20 +12:00
|
|
|
G_OBJECT (display), GIMP_MESSAGE_INFO,
|
2016-09-19 23:53:40 +02:00
|
|
|
_("Copied pixels to the clipboard."));
|
2008-03-04 21:37:52 +00:00
|
|
|
|
2007-12-14 13:58:10 +00:00
|
|
|
gimp_image_flush (image);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-11-04 12:33:09 +00:00
|
|
|
gimp_message_literal (image->gimp,
|
2013-09-15 04:59:20 +12:00
|
|
|
G_OBJECT (action_data_get_display (data)),
|
|
|
|
GIMP_MESSAGE_WARNING,
|
|
|
|
error->message);
|
2007-12-14 13:58:10 +00:00
|
|
|
g_clear_error (&error);
|
|
|
|
}
|
2001-06-26 12:09:43 +00:00
|
|
|
}
|
|
|
|
|
2004-04-19 14:54:24 +00:00
|
|
|
void
|
2019-07-02 16:12:18 +02:00
|
|
|
edit_paste_cmd_callback (GimpAction *action,
|
2019-07-04 01:11:48 +02:00
|
|
|
GVariant *value,
|
2019-07-02 16:12:18 +02:00
|
|
|
gpointer data)
|
2004-04-19 14:54:24 +00:00
|
|
|
{
|
2022-10-29 18:53:44 +00:00
|
|
|
GimpImage *image;
|
2017-11-12 18:41:05 +01:00
|
|
|
GimpDisplay *display = action_data_get_display (data);
|
2019-07-04 01:11:48 +02:00
|
|
|
GimpPasteType paste_type = (GimpPasteType) g_variant_get_int32 (value);
|
2022-10-29 18:53:44 +00:00
|
|
|
GimpPasteType converted_type;
|
|
|
|
GList *drawables;
|
2022-11-12 22:17:00 +01:00
|
|
|
gboolean merged = FALSE;
|
2022-10-29 18:53:44 +00:00
|
|
|
|
2023-05-20 19:59:58 +00:00
|
|
|
if (paste_type == GIMP_PASTE_TYPE_NEW_LAYER_OR_FLOATING)
|
2016-09-19 12:36:11 +02:00
|
|
|
{
|
2017-11-12 18:41:05 +01:00
|
|
|
if (! display || ! gimp_display_get_image (display))
|
|
|
|
{
|
2019-07-04 01:11:48 +02:00
|
|
|
edit_paste_as_new_image_cmd_callback (action, value, data);
|
2017-11-12 18:41:05 +01:00
|
|
|
return;
|
|
|
|
}
|
2016-09-19 12:36:11 +02:00
|
|
|
}
|
2004-04-19 14:54:24 +00:00
|
|
|
|
2023-05-20 19:59:58 +00:00
|
|
|
return_if_no_image (image, data);
|
|
|
|
|
2017-11-12 18:41:05 +01:00
|
|
|
if (! display)
|
|
|
|
return;
|
2004-04-19 14:54:24 +00:00
|
|
|
|
2017-11-12 18:41:05 +01:00
|
|
|
switch (paste_type)
|
|
|
|
{
|
|
|
|
case GIMP_PASTE_TYPE_FLOATING:
|
|
|
|
case GIMP_PASTE_TYPE_FLOATING_IN_PLACE:
|
|
|
|
case GIMP_PASTE_TYPE_FLOATING_INTO:
|
|
|
|
case GIMP_PASTE_TYPE_FLOATING_INTO_IN_PLACE:
|
2022-11-12 22:17:00 +01:00
|
|
|
edit_paste (display, paste_type, merged, TRUE);
|
2017-11-12 18:41:05 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_PASTE_TYPE_NEW_LAYER:
|
|
|
|
case GIMP_PASTE_TYPE_NEW_LAYER_IN_PLACE:
|
2022-11-12 22:17:00 +01:00
|
|
|
edit_paste (display, paste_type, merged, FALSE);
|
2017-11-12 18:41:05 +01:00
|
|
|
break;
|
2022-10-29 18:53:44 +00:00
|
|
|
|
2022-11-12 22:17:00 +01:00
|
|
|
case GIMP_PASTE_TYPE_NEW_MERGED_LAYER_OR_FLOATING:
|
|
|
|
case GIMP_PASTE_TYPE_NEW_MERGED_LAYER_OR_FLOATING_IN_PLACE:
|
|
|
|
merged = TRUE;
|
2022-10-29 18:53:44 +00:00
|
|
|
case GIMP_PASTE_TYPE_NEW_LAYER_OR_FLOATING:
|
|
|
|
case GIMP_PASTE_TYPE_NEW_LAYER_OR_FLOATING_IN_PLACE:
|
|
|
|
drawables = gimp_image_get_selected_drawables (image);
|
|
|
|
|
|
|
|
if (drawables &&
|
|
|
|
(g_list_length (drawables) == 1) &&
|
|
|
|
GIMP_IS_LAYER_MASK (drawables->data))
|
|
|
|
{
|
2022-11-12 22:17:00 +01:00
|
|
|
converted_type = (paste_type == GIMP_PASTE_TYPE_NEW_LAYER_OR_FLOATING ||
|
|
|
|
paste_type == GIMP_PASTE_TYPE_NEW_MERGED_LAYER_OR_FLOATING) ?
|
2022-10-29 18:53:44 +00:00
|
|
|
GIMP_PASTE_TYPE_FLOATING :
|
|
|
|
GIMP_PASTE_TYPE_FLOATING_IN_PLACE;
|
|
|
|
|
2022-11-12 22:17:00 +01:00
|
|
|
edit_paste (display, converted_type, merged, TRUE);
|
2022-10-29 18:53:44 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-11-12 22:17:00 +01:00
|
|
|
converted_type = (paste_type == GIMP_PASTE_TYPE_NEW_LAYER_OR_FLOATING ||
|
|
|
|
paste_type == GIMP_PASTE_TYPE_NEW_MERGED_LAYER_OR_FLOATING) ?
|
2022-10-29 18:53:44 +00:00
|
|
|
GIMP_PASTE_TYPE_NEW_LAYER :
|
|
|
|
GIMP_PASTE_TYPE_NEW_LAYER_IN_PLACE;
|
|
|
|
|
2022-11-12 22:17:00 +01:00
|
|
|
edit_paste (display, converted_type, merged, FALSE);
|
2022-10-29 18:53:44 +00:00
|
|
|
}
|
2022-11-09 17:01:44 +01:00
|
|
|
g_list_free (drawables);
|
2022-10-29 18:53:44 +00:00
|
|
|
|
|
|
|
break;
|
2017-11-12 18:41:05 +01:00
|
|
|
}
|
2016-09-20 20:43:01 +02:00
|
|
|
}
|
|
|
|
|
2001-06-26 12:09:43 +00:00
|
|
|
void
|
2019-07-02 16:12:18 +02:00
|
|
|
edit_paste_as_new_image_cmd_callback (GimpAction *action,
|
2019-07-04 01:11:48 +02:00
|
|
|
GVariant *value,
|
2019-07-02 16:12:18 +02:00
|
|
|
gpointer data)
|
2001-06-26 12:09:43 +00:00
|
|
|
{
|
2004-07-02 14:08:15 +00:00
|
|
|
Gimp *gimp;
|
2014-05-02 20:20:46 +02:00
|
|
|
GtkWidget *widget;
|
2016-09-21 12:37:51 +02:00
|
|
|
GimpObject *paste;
|
|
|
|
GimpImage *image = NULL;
|
2004-05-03 14:46:29 +00:00
|
|
|
return_if_no_gimp (gimp, data);
|
2014-05-02 20:20:46 +02:00
|
|
|
return_if_no_widget (widget, data);
|
2001-06-26 12:09:43 +00:00
|
|
|
|
2016-09-21 12:37:51 +02:00
|
|
|
paste = gimp_clipboard_get_object (gimp);
|
2004-07-02 14:08:15 +00:00
|
|
|
|
2016-09-21 12:37:51 +02:00
|
|
|
if (paste)
|
2004-07-02 14:08:15 +00:00
|
|
|
{
|
2023-01-24 12:47:02 +01:00
|
|
|
image = gimp_edit_paste_as_new_image (gimp, paste,
|
|
|
|
action_data_get_context (data));
|
2016-09-21 12:37:51 +02:00
|
|
|
g_object_unref (paste);
|
2016-09-19 23:53:40 +02:00
|
|
|
}
|
2005-09-02 22:50:06 +00:00
|
|
|
|
2016-09-21 12:37:51 +02:00
|
|
|
if (image)
|
2016-09-19 23:53:40 +02:00
|
|
|
{
|
2016-09-21 12:37:51 +02:00
|
|
|
gimp_create_display (gimp, image, GIMP_UNIT_PIXEL, 1.0,
|
2018-04-29 17:27:47 +02:00
|
|
|
G_OBJECT (gimp_widget_get_monitor (widget)));
|
2016-09-21 12:37:51 +02:00
|
|
|
g_object_unref (image);
|
2008-08-07 16:25:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-11-04 12:33:09 +00:00
|
|
|
gimp_message_literal (gimp, NULL, GIMP_MESSAGE_WARNING,
|
2016-09-19 23:53:40 +02:00
|
|
|
_("There is no image data in the clipboard "
|
|
|
|
"to paste."));
|
2008-08-07 16:25:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-26 12:09:43 +00:00
|
|
|
void
|
2019-07-02 16:12:18 +02:00
|
|
|
edit_named_cut_cmd_callback (GimpAction *action,
|
2019-07-04 01:11:48 +02:00
|
|
|
GVariant *value,
|
2019-07-02 16:12:18 +02:00
|
|
|
gpointer data)
|
2001-06-26 12:09:43 +00:00
|
|
|
{
|
2006-03-28 17:08:36 +00:00
|
|
|
GimpImage *image;
|
2004-05-03 14:46:29 +00:00
|
|
|
GtkWidget *widget;
|
2004-10-19 14:08:44 +00:00
|
|
|
GtkWidget *dialog;
|
2006-03-28 17:08:36 +00:00
|
|
|
return_if_no_image (image, data);
|
2004-05-03 14:46:29 +00:00
|
|
|
return_if_no_widget (widget, data);
|
2001-06-26 12:09:43 +00:00
|
|
|
|
2004-10-19 14:08:44 +00:00
|
|
|
dialog = gimp_query_string_box (_("Cut Named"), widget,
|
|
|
|
gimp_standard_help_func,
|
|
|
|
GIMP_HELP_BUFFER_CUT,
|
|
|
|
_("Enter a name for this buffer"),
|
|
|
|
NULL,
|
2006-03-28 17:08:36 +00:00
|
|
|
G_OBJECT (image), "disconnect",
|
2019-08-07 22:48:06 +02:00
|
|
|
cut_named_buffer_callback,
|
|
|
|
image, NULL);
|
2004-10-19 14:08:44 +00:00
|
|
|
gtk_widget_show (dialog);
|
2001-06-26 12:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-07-02 16:12:18 +02:00
|
|
|
edit_named_copy_cmd_callback (GimpAction *action,
|
2019-07-04 01:11:48 +02:00
|
|
|
GVariant *value,
|
2019-07-02 16:12:18 +02:00
|
|
|
gpointer data)
|
2001-06-26 12:09:43 +00:00
|
|
|
{
|
2006-03-28 17:08:36 +00:00
|
|
|
GimpImage *image;
|
2004-05-03 14:46:29 +00:00
|
|
|
GtkWidget *widget;
|
2004-10-19 14:08:44 +00:00
|
|
|
GtkWidget *dialog;
|
2006-03-28 17:08:36 +00:00
|
|
|
return_if_no_image (image, data);
|
2004-05-03 14:46:29 +00:00
|
|
|
return_if_no_widget (widget, data);
|
2001-06-26 12:09:43 +00:00
|
|
|
|
2004-10-19 14:08:44 +00:00
|
|
|
dialog = gimp_query_string_box (_("Copy Named"), widget,
|
|
|
|
gimp_standard_help_func,
|
|
|
|
GIMP_HELP_BUFFER_COPY,
|
|
|
|
_("Enter a name for this buffer"),
|
|
|
|
NULL,
|
2006-03-28 17:08:36 +00:00
|
|
|
G_OBJECT (image), "disconnect",
|
2019-08-07 22:48:06 +02:00
|
|
|
copy_named_buffer_callback,
|
|
|
|
image, NULL);
|
2004-10-19 14:08:44 +00:00
|
|
|
gtk_widget_show (dialog);
|
2001-06-26 12:09:43 +00:00
|
|
|
}
|
|
|
|
|
2005-09-05 00:37:25 +00:00
|
|
|
void
|
2019-07-02 16:12:18 +02:00
|
|
|
edit_named_copy_visible_cmd_callback (GimpAction *action,
|
2019-07-04 01:11:48 +02:00
|
|
|
GVariant *value,
|
2019-07-02 16:12:18 +02:00
|
|
|
gpointer data)
|
2005-09-05 00:37:25 +00:00
|
|
|
{
|
2006-03-28 17:08:36 +00:00
|
|
|
GimpImage *image;
|
2005-09-05 00:37:25 +00:00
|
|
|
GtkWidget *widget;
|
|
|
|
GtkWidget *dialog;
|
2006-03-28 17:08:36 +00:00
|
|
|
return_if_no_image (image, data);
|
2005-09-05 00:37:25 +00:00
|
|
|
return_if_no_widget (widget, data);
|
|
|
|
|
2021-08-30 20:27:10 +02:00
|
|
|
dialog = gimp_query_string_box (_("Copy Visible Named"), widget,
|
2005-09-05 00:37:25 +00:00
|
|
|
gimp_standard_help_func,
|
|
|
|
GIMP_HELP_BUFFER_COPY,
|
|
|
|
_("Enter a name for this buffer"),
|
|
|
|
NULL,
|
2006-03-28 17:08:36 +00:00
|
|
|
G_OBJECT (image), "disconnect",
|
2019-08-07 22:48:06 +02:00
|
|
|
copy_named_visible_buffer_callback,
|
|
|
|
image, NULL);
|
2005-09-05 00:37:25 +00:00
|
|
|
gtk_widget_show (dialog);
|
|
|
|
}
|
|
|
|
|
2001-06-26 12:09:43 +00:00
|
|
|
void
|
2019-07-02 16:12:18 +02:00
|
|
|
edit_named_paste_cmd_callback (GimpAction *action,
|
2019-07-04 01:11:48 +02:00
|
|
|
GVariant *value,
|
2019-07-02 16:12:18 +02:00
|
|
|
gpointer data)
|
2001-06-26 12:09:43 +00:00
|
|
|
{
|
2012-01-30 23:24:44 +01:00
|
|
|
Gimp *gimp;
|
2004-05-03 14:46:29 +00:00
|
|
|
GtkWidget *widget;
|
2012-01-30 23:24:44 +01:00
|
|
|
return_if_no_gimp (gimp, data);
|
2004-05-03 14:46:29 +00:00
|
|
|
return_if_no_widget (widget, data);
|
2004-04-29 12:52:29 +00:00
|
|
|
|
2012-01-30 23:24:44 +01:00
|
|
|
gimp_window_strategy_show_dockable_dialog (GIMP_WINDOW_STRATEGY (gimp_get_window_strategy (gimp)),
|
|
|
|
gimp,
|
|
|
|
gimp_dialog_factory_get_singleton (),
|
2014-05-02 03:01:23 +02:00
|
|
|
gimp_widget_get_monitor (widget),
|
2012-01-30 23:24:44 +01:00
|
|
|
"gimp-buffer-list|gimp-buffer-grid");
|
2001-06-26 12:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-07-02 16:12:18 +02:00
|
|
|
edit_clear_cmd_callback (GimpAction *action,
|
2019-07-04 01:11:48 +02:00
|
|
|
GVariant *value,
|
2019-07-02 16:12:18 +02:00
|
|
|
gpointer data)
|
2001-06-26 12:09:43 +00:00
|
|
|
{
|
2020-07-30 21:18:54 +02:00
|
|
|
GimpImage *image;
|
|
|
|
GList *drawables;
|
|
|
|
GList *iter;
|
2001-06-26 12:09:43 +00:00
|
|
|
|
2020-07-30 21:18:54 +02:00
|
|
|
return_if_no_drawables (image, drawables, data);
|
|
|
|
|
|
|
|
for (iter = drawables; iter; iter = iter->next)
|
|
|
|
/* Return if any has a locked alpha. */
|
|
|
|
if (! check_drawable_alpha (iter->data, data))
|
2021-08-21 19:06:14 +02:00
|
|
|
{
|
|
|
|
g_list_free (drawables);
|
|
|
|
return;
|
|
|
|
}
|
2020-07-30 21:18:54 +02:00
|
|
|
|
|
|
|
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_PAINT,
|
|
|
|
_("Clear"));
|
2018-12-31 04:37:50 -05:00
|
|
|
|
2020-07-30 21:18:54 +02:00
|
|
|
for (iter = drawables; iter; iter = iter->next)
|
|
|
|
if (! gimp_viewable_get_children (GIMP_VIEWABLE (iter->data)) &&
|
2022-02-15 15:42:44 +01:00
|
|
|
! gimp_item_is_content_locked (GIMP_ITEM (iter->data), NULL))
|
2020-07-30 21:18:54 +02:00
|
|
|
gimp_drawable_edit_clear (iter->data, action_data_get_context (data));
|
|
|
|
|
|
|
|
gimp_image_undo_group_end (image);
|
2006-03-28 17:08:36 +00:00
|
|
|
gimp_image_flush (image);
|
2020-07-30 21:18:54 +02:00
|
|
|
g_list_free (drawables);
|
2001-06-26 12:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-07-02 16:12:18 +02:00
|
|
|
edit_fill_cmd_callback (GimpAction *action,
|
2019-07-04 01:11:48 +02:00
|
|
|
GVariant *value,
|
2019-07-02 16:12:18 +02:00
|
|
|
gpointer data)
|
2001-06-26 12:09:43 +00:00
|
|
|
{
|
2016-03-11 19:52:36 +01:00
|
|
|
GimpImage *image;
|
2020-07-31 17:52:53 +02:00
|
|
|
GList *drawables;
|
|
|
|
GList *iter;
|
2016-03-11 19:52:36 +01:00
|
|
|
GimpFillType fill_type;
|
|
|
|
GimpFillOptions *options;
|
|
|
|
GError *error = NULL;
|
2020-07-31 17:52:53 +02:00
|
|
|
return_if_no_drawables (image, drawables, data);
|
2001-06-26 12:09:43 +00:00
|
|
|
|
2019-07-04 01:11:48 +02:00
|
|
|
fill_type = (GimpFillType) g_variant_get_int32 (value);
|
2001-06-26 12:09:43 +00:00
|
|
|
|
2016-03-15 20:10:16 +01:00
|
|
|
options = gimp_fill_options_new (action_data_get_gimp (data), NULL, FALSE);
|
2016-03-11 19:52:36 +01:00
|
|
|
|
|
|
|
if (gimp_fill_options_set_by_fill_type (options,
|
|
|
|
action_data_get_context (data),
|
|
|
|
fill_type, &error))
|
2014-06-03 14:00:01 +02:00
|
|
|
{
|
2020-07-31 17:52:53 +02:00
|
|
|
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_PAINT,
|
|
|
|
gimp_fill_options_get_undo_desc (options));
|
|
|
|
|
|
|
|
for (iter = drawables; iter; iter = iter->next)
|
|
|
|
gimp_drawable_edit_fill (iter->data, options, NULL);
|
|
|
|
|
|
|
|
gimp_image_undo_group_end (image);
|
2014-06-03 14:00:01 +02:00
|
|
|
gimp_image_flush (image);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gimp_message_literal (image->gimp, NULL, GIMP_MESSAGE_WARNING,
|
|
|
|
error->message);
|
|
|
|
g_clear_error (&error);
|
|
|
|
}
|
2016-03-11 19:52:36 +01:00
|
|
|
|
2020-08-01 12:04:04 +02:00
|
|
|
g_list_free (drawables);
|
2016-03-11 19:52:36 +01:00
|
|
|
g_object_unref (options);
|
2001-06-26 12:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
2018-12-31 04:37:50 -05:00
|
|
|
static gboolean
|
|
|
|
check_drawable_alpha (GimpDrawable *drawable,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2022-02-15 20:13:10 +01:00
|
|
|
GimpLayer *locked_layer = NULL;
|
|
|
|
|
2018-12-31 04:37:50 -05:00
|
|
|
if (gimp_drawable_has_alpha (drawable) &&
|
|
|
|
GIMP_IS_LAYER (drawable) &&
|
2022-02-15 20:13:10 +01:00
|
|
|
gimp_layer_is_alpha_locked (GIMP_LAYER (drawable), &locked_layer))
|
2018-12-31 04:37:50 -05:00
|
|
|
{
|
|
|
|
Gimp *gimp = action_data_get_gimp (data);
|
|
|
|
GimpDisplay *display = action_data_get_display (data);
|
|
|
|
|
|
|
|
if (gimp && display)
|
|
|
|
{
|
|
|
|
gimp_message_literal (
|
|
|
|
gimp, G_OBJECT (display), GIMP_MESSAGE_WARNING,
|
2020-05-26 16:15:15 +02:00
|
|
|
_("A selected layer's alpha channel is locked."));
|
2018-12-31 04:37:50 -05:00
|
|
|
|
2022-02-15 20:13:10 +01:00
|
|
|
gimp_tools_blink_lock_box (gimp, GIMP_ITEM (locked_layer));
|
2018-12-31 04:37:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-07-07 09:43:35 +00:00
|
|
|
static void
|
2016-09-19 23:53:40 +02:00
|
|
|
edit_paste (GimpDisplay *display,
|
|
|
|
GimpPasteType paste_type,
|
2022-11-12 22:17:00 +01:00
|
|
|
gboolean merged,
|
2016-09-19 23:53:40 +02:00
|
|
|
gboolean try_svg)
|
2004-07-07 09:43:35 +00:00
|
|
|
{
|
2016-09-19 23:53:40 +02:00
|
|
|
GimpImage *image = gimp_display_get_image (display);
|
|
|
|
GimpObject *paste;
|
2005-05-16 12:31:04 +00:00
|
|
|
|
2022-11-12 22:17:00 +01:00
|
|
|
g_return_if_fail (paste_type != GIMP_PASTE_TYPE_NEW_LAYER_OR_FLOATING &&
|
|
|
|
paste_type != GIMP_PASTE_TYPE_NEW_LAYER_OR_FLOATING_IN_PLACE &&
|
|
|
|
paste_type != GIMP_PASTE_TYPE_NEW_MERGED_LAYER_OR_FLOATING &&
|
|
|
|
paste_type != GIMP_PASTE_TYPE_NEW_MERGED_LAYER_OR_FLOATING_IN_PLACE);
|
2022-11-09 17:01:44 +01:00
|
|
|
|
2016-09-19 23:53:40 +02:00
|
|
|
if (try_svg)
|
2004-07-07 09:43:35 +00:00
|
|
|
{
|
2016-09-19 23:53:40 +02:00
|
|
|
gchar *svg;
|
|
|
|
gsize svg_size;
|
|
|
|
|
|
|
|
svg = gimp_clipboard_get_svg (display->gimp, &svg_size);
|
|
|
|
|
|
|
|
if (svg)
|
2005-05-16 12:31:04 +00:00
|
|
|
{
|
2024-07-13 05:07:57 +00:00
|
|
|
if (gimp_path_import_buffer (image, svg, svg_size,
|
|
|
|
TRUE, FALSE,
|
|
|
|
GIMP_IMAGE_ACTIVE_PARENT, -1,
|
|
|
|
NULL, NULL))
|
2016-09-19 23:53:40 +02:00
|
|
|
{
|
|
|
|
gimp_image_flush (image);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (svg);
|
|
|
|
|
|
|
|
return;
|
2005-05-16 12:31:04 +00:00
|
|
|
}
|
2016-09-19 23:53:40 +02:00
|
|
|
}
|
2004-07-07 09:43:35 +00:00
|
|
|
|
2016-09-21 12:37:51 +02:00
|
|
|
paste = gimp_clipboard_get_object (display->gimp);
|
2016-09-19 23:53:40 +02:00
|
|
|
|
|
|
|
if (paste)
|
|
|
|
{
|
2020-08-01 12:04:04 +02:00
|
|
|
GimpDisplayShell *shell = gimp_display_get_shell (display);
|
|
|
|
GList *drawables = gimp_image_get_selected_drawables (image);
|
app, libgimp, pdb, plug-ins: allow pasting multiple full layers.
When a selection exists, we are copying then pasting the selection
contents. In particular, with multi-layer selection, it means pasting a
merged result of the selected layers (like a sample merged but limited
to selected layers).
Yet when no selection exists, with a single layer selected, a cut in
particular would remove the layer fully, then a paste would copy it
elsewhere (in the same image or even on a different image). This was
still working, but not with multiple layers. This is now fixed and we
can now copy/cut then paste several layers (without merge), which is
sometimes a very practical way to move layers (sometimes simpler than
drag'n drop, especially between images).
As a consequence, the PDB function gimp_edit_paste() now also returns an
array of layers (not a single layer).
2021-04-24 22:45:09 +02:00
|
|
|
GList *pasted_layers;
|
2016-09-21 12:37:51 +02:00
|
|
|
gint x, y;
|
|
|
|
gint width, height;
|
|
|
|
|
2022-11-09 17:01:44 +01:00
|
|
|
if (g_list_length (drawables) != 1 ||
|
|
|
|
(paste_type != GIMP_PASTE_TYPE_NEW_LAYER &&
|
|
|
|
paste_type != GIMP_PASTE_TYPE_NEW_LAYER_IN_PLACE))
|
2005-05-16 12:31:04 +00:00
|
|
|
{
|
2022-11-09 17:01:44 +01:00
|
|
|
if (g_list_length (drawables) != 1)
|
|
|
|
{
|
|
|
|
gimp_message_literal (display->gimp, G_OBJECT (display),
|
|
|
|
GIMP_MESSAGE_INFO,
|
|
|
|
_("Pasted as new layer because the "
|
|
|
|
"target is not a single layer or layer mask."));
|
|
|
|
}
|
|
|
|
else if (gimp_viewable_get_children (GIMP_VIEWABLE (drawables->data)))
|
2005-05-16 12:31:04 +00:00
|
|
|
{
|
2016-09-19 23:53:40 +02:00
|
|
|
gimp_message_literal (display->gimp, G_OBJECT (display),
|
|
|
|
GIMP_MESSAGE_INFO,
|
|
|
|
_("Pasted as new layer because the "
|
|
|
|
"target is a layer group."));
|
2005-05-16 12:31:04 +00:00
|
|
|
}
|
2022-11-09 17:01:44 +01:00
|
|
|
else if (gimp_item_is_content_locked (GIMP_ITEM (drawables->data), NULL))
|
2016-09-19 23:53:40 +02:00
|
|
|
{
|
|
|
|
gimp_message_literal (display->gimp, G_OBJECT (display),
|
|
|
|
GIMP_MESSAGE_INFO,
|
|
|
|
_("Pasted as new layer because the "
|
|
|
|
"target's pixels are locked."));
|
|
|
|
}
|
2018-03-24 12:43:30 -04:00
|
|
|
|
|
|
|
/* the actual paste-type conversion happens in gimp_edit_paste() */
|
2005-05-16 12:31:04 +00:00
|
|
|
}
|
2016-09-19 23:53:40 +02:00
|
|
|
|
2019-09-15 16:25:20 +03:00
|
|
|
gimp_display_shell_untransform_viewport (
|
|
|
|
shell,
|
|
|
|
! gimp_display_shell_get_infinite_canvas (shell),
|
|
|
|
&x, &y, &width, &height);
|
2016-09-19 23:53:40 +02:00
|
|
|
|
2022-11-12 22:17:00 +01:00
|
|
|
if ((pasted_layers = gimp_edit_paste (image, drawables, paste, paste_type,
|
|
|
|
gimp_get_user_context (display->gimp),
|
|
|
|
merged, x, y, width, height)))
|
2006-09-22 16:44:47 +00:00
|
|
|
{
|
app, libgimp, pdb, plug-ins: allow pasting multiple full layers.
When a selection exists, we are copying then pasting the selection
contents. In particular, with multi-layer selection, it means pasting a
merged result of the selected layers (like a sample merged but limited
to selected layers).
Yet when no selection exists, with a single layer selected, a cut in
particular would remove the layer fully, then a paste would copy it
elsewhere (in the same image or even on a different image). This was
still working, but not with multiple layers. This is now fixed and we
can now copy/cut then paste several layers (without merge), which is
sometimes a very practical way to move layers (sometimes simpler than
drag'n drop, especially between images).
As a consequence, the PDB function gimp_edit_paste() now also returns an
array of layers (not a single layer).
2021-04-24 22:45:09 +02:00
|
|
|
gimp_image_set_selected_layers (image, pasted_layers);
|
2024-03-12 13:29:36 +00:00
|
|
|
|
|
|
|
/* Copy over layer effects */
|
|
|
|
if (GIMP_IS_IMAGE (paste))
|
|
|
|
{
|
|
|
|
GList *old_layers_list;
|
|
|
|
GList *new_layers_list;
|
|
|
|
|
|
|
|
old_layers_list = gimp_image_get_layer_iter (GIMP_IMAGE (paste));
|
|
|
|
for (new_layers_list = pasted_layers; new_layers_list;
|
|
|
|
new_layers_list = g_list_next (new_layers_list))
|
|
|
|
{
|
|
|
|
GimpLayer *layer = old_layers_list->data;
|
|
|
|
GimpLayer *new_layer = new_layers_list->data;
|
|
|
|
|
|
|
|
if (gimp_drawable_has_filters (GIMP_DRAWABLE (layer)))
|
|
|
|
{
|
|
|
|
GList *filter_list;
|
|
|
|
GimpContainer *filters;
|
|
|
|
|
|
|
|
filters = gimp_drawable_get_filters (GIMP_DRAWABLE (layer));
|
|
|
|
|
|
|
|
for (filter_list = GIMP_LIST (filters)->queue->tail;
|
|
|
|
filter_list;
|
|
|
|
filter_list = g_list_previous (filter_list))
|
|
|
|
{
|
|
|
|
if (GIMP_IS_DRAWABLE_FILTER (filter_list->data))
|
|
|
|
{
|
|
|
|
GimpDrawableFilter *old_filter = filter_list->data;
|
|
|
|
GimpDrawableFilter *filter;
|
|
|
|
|
|
|
|
filter =
|
|
|
|
gimp_drawable_filter_duplicate (GIMP_DRAWABLE (new_layer),
|
|
|
|
old_filter);
|
|
|
|
|
2024-05-14 04:05:06 +00:00
|
|
|
if (filter != NULL)
|
|
|
|
{
|
|
|
|
gimp_drawable_filter_apply (filter, NULL);
|
|
|
|
gimp_drawable_filter_commit (filter, TRUE, NULL, FALSE);
|
|
|
|
|
|
|
|
gimp_drawable_filter_layer_mask_freeze (filter);
|
|
|
|
g_object_unref (filter);
|
|
|
|
}
|
2024-03-12 13:29:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
old_layers_list = g_list_next (old_layers_list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
app, libgimp, pdb, plug-ins: allow pasting multiple full layers.
When a selection exists, we are copying then pasting the selection
contents. In particular, with multi-layer selection, it means pasting a
merged result of the selected layers (like a sample merged but limited
to selected layers).
Yet when no selection exists, with a single layer selected, a cut in
particular would remove the layer fully, then a paste would copy it
elsewhere (in the same image or even on a different image). This was
still working, but not with multiple layers. This is now fixed and we
can now copy/cut then paste several layers (without merge), which is
sometimes a very practical way to move layers (sometimes simpler than
drag'n drop, especially between images).
As a consequence, the PDB function gimp_edit_paste() now also returns an
array of layers (not a single layer).
2021-04-24 22:45:09 +02:00
|
|
|
g_list_free (pasted_layers);
|
2016-09-19 23:53:40 +02:00
|
|
|
gimp_image_flush (image);
|
2006-09-22 16:44:47 +00:00
|
|
|
}
|
2016-09-19 23:53:40 +02:00
|
|
|
|
2022-11-09 17:01:44 +01:00
|
|
|
g_list_free (drawables);
|
2016-09-19 23:53:40 +02:00
|
|
|
g_object_unref (paste);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gimp_message_literal (display->gimp, G_OBJECT (display),
|
|
|
|
GIMP_MESSAGE_WARNING,
|
|
|
|
_("There is no image data in the clipboard "
|
|
|
|
"to paste."));
|
2004-07-07 09:43:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-26 12:09:43 +00:00
|
|
|
static void
|
2003-09-05 01:56:50 +00:00
|
|
|
cut_named_buffer_callback (GtkWidget *widget,
|
2004-01-16 10:06:19 +00:00
|
|
|
const gchar *name,
|
|
|
|
gpointer data)
|
2001-06-26 12:09:43 +00:00
|
|
|
{
|
2020-05-26 16:15:15 +02:00
|
|
|
GimpImage *image = GIMP_IMAGE (data);
|
|
|
|
GList *drawables = gimp_image_get_selected_drawables (image);
|
|
|
|
GError *error = NULL;
|
2004-02-19 12:49:15 +00:00
|
|
|
|
2020-05-26 16:15:15 +02:00
|
|
|
if (! drawables)
|
2004-02-19 12:49:15 +00:00
|
|
|
{
|
2008-11-04 12:33:09 +00:00
|
|
|
gimp_message_literal (image->gimp, NULL, GIMP_MESSAGE_WARNING,
|
2020-05-26 16:15:15 +02:00
|
|
|
_("There are no selected layers or channels to cut from."));
|
2004-02-19 12:49:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-09-02 22:50:06 +00:00
|
|
|
if (! (name && strlen (name)))
|
|
|
|
name = _("(Unnamed Buffer)");
|
2001-12-12 23:48:18 +00:00
|
|
|
|
2020-05-26 16:15:15 +02:00
|
|
|
if (gimp_edit_named_cut (image, name, drawables,
|
2007-12-14 13:58:10 +00:00
|
|
|
gimp_get_user_context (image->gimp), &error))
|
2001-06-26 12:09:43 +00:00
|
|
|
{
|
2006-03-28 17:08:36 +00:00
|
|
|
gimp_image_flush (image);
|
2004-02-19 12:49:15 +00:00
|
|
|
}
|
2007-12-14 13:58:10 +00:00
|
|
|
else
|
|
|
|
{
|
2008-11-04 12:33:09 +00:00
|
|
|
gimp_message_literal (image->gimp, NULL, GIMP_MESSAGE_WARNING,
|
2013-09-15 04:59:20 +12:00
|
|
|
error->message);
|
2007-12-14 13:58:10 +00:00
|
|
|
g_clear_error (&error);
|
|
|
|
}
|
2020-05-26 16:15:15 +02:00
|
|
|
g_list_free (drawables);
|
2001-06-26 12:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-09-05 01:40:29 +00:00
|
|
|
copy_named_buffer_callback (GtkWidget *widget,
|
2006-04-12 12:49:29 +00:00
|
|
|
const gchar *name,
|
|
|
|
gpointer data)
|
2001-06-26 12:09:43 +00:00
|
|
|
{
|
2020-05-26 16:15:15 +02:00
|
|
|
GimpImage *image = GIMP_IMAGE (data);
|
|
|
|
GList *drawables = gimp_image_get_selected_drawables (image);
|
|
|
|
GError *error = NULL;
|
2004-02-19 12:49:15 +00:00
|
|
|
|
2020-05-26 16:15:15 +02:00
|
|
|
if (! drawables)
|
2004-02-19 12:49:15 +00:00
|
|
|
{
|
2008-11-04 12:33:09 +00:00
|
|
|
gimp_message_literal (image->gimp, NULL, GIMP_MESSAGE_WARNING,
|
2020-05-26 16:15:15 +02:00
|
|
|
_("There are no selected layers or channels to copy from."));
|
2004-02-19 12:49:15 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-06-29 19:25:03 +00:00
|
|
|
|
2005-09-02 22:50:06 +00:00
|
|
|
if (! (name && strlen (name)))
|
|
|
|
name = _("(Unnamed Buffer)");
|
2001-06-26 12:09:43 +00:00
|
|
|
|
2020-05-26 16:15:15 +02:00
|
|
|
if (gimp_edit_named_copy (image, name, drawables,
|
2007-12-14 13:58:10 +00:00
|
|
|
gimp_get_user_context (image->gimp), &error))
|
2001-06-26 12:09:43 +00:00
|
|
|
{
|
2006-03-28 17:08:36 +00:00
|
|
|
gimp_image_flush (image);
|
2001-06-26 12:09:43 +00:00
|
|
|
}
|
2007-12-14 13:58:10 +00:00
|
|
|
else
|
|
|
|
{
|
2008-11-04 12:33:09 +00:00
|
|
|
gimp_message_literal (image->gimp, NULL, GIMP_MESSAGE_WARNING,
|
2013-09-15 04:59:20 +12:00
|
|
|
error->message);
|
2007-12-14 13:58:10 +00:00
|
|
|
g_clear_error (&error);
|
|
|
|
}
|
2020-05-26 16:15:15 +02:00
|
|
|
g_list_free (drawables);
|
2001-06-26 12:09:43 +00:00
|
|
|
}
|
2005-09-05 00:37:25 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
copy_named_visible_buffer_callback (GtkWidget *widget,
|
|
|
|
const gchar *name,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2006-03-28 17:08:36 +00:00
|
|
|
GimpImage *image = GIMP_IMAGE (data);
|
2007-12-14 13:58:10 +00:00
|
|
|
GError *error = NULL;
|
2005-09-05 00:37:25 +00:00
|
|
|
|
|
|
|
if (! (name && strlen (name)))
|
|
|
|
name = _("(Unnamed Buffer)");
|
|
|
|
|
2006-03-28 17:08:36 +00:00
|
|
|
if (gimp_edit_named_copy_visible (image, name,
|
2007-12-14 13:58:10 +00:00
|
|
|
gimp_get_user_context (image->gimp),
|
|
|
|
&error))
|
2005-09-05 00:37:25 +00:00
|
|
|
{
|
2006-03-28 17:08:36 +00:00
|
|
|
gimp_image_flush (image);
|
2005-09-05 00:37:25 +00:00
|
|
|
}
|
2007-12-14 13:58:10 +00:00
|
|
|
else
|
|
|
|
{
|
2008-11-04 12:33:09 +00:00
|
|
|
gimp_message_literal (image->gimp, NULL, GIMP_MESSAGE_WARNING,
|
2013-09-15 04:59:20 +12:00
|
|
|
error->message);
|
2007-12-14 13:58:10 +00:00
|
|
|
g_clear_error (&error);
|
|
|
|
}
|
2005-09-05 00:37:25 +00:00
|
|
|
}
|