Commit 89bb3fff authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

don't create a display here.

2005-09-03  Michael Natterer  <mitch@gimp.org>

	* app/core/gimp-edit.[ch] (gimp_edit_paste_as_new): don't create a
	display here.

	(gimp_edit_named_cut)
	(gimp_edit_named_copy)
	(gimp_edit_named_copy_visible): new functions containing named
	buffer wrappers around the functions affecting the global buffer
	only.

	* app/actions/edit-commands.c: use the new functions instead of
	implementing them here, create a display for the image returned
	by paste as new.

	* app/actions/buffers-commands.c
	* app/widgets/gimptoolbox-dnd.c: create displays here too.

	* tools/pdbgen/pdb/edit.pdb: added wrappers for paste as new and
	wrappers for all the cut/copy/paste named stuff.
	Fixes bug #315130. Cleaned up and de-obfuscated.

	* libgimp/gimp.def: changed accordingly.

	* app/pdb/edit_cmds.c
	* app/pdb/internal_procs.c
	* libgimp/gimpedit_pdb.[ch]: regenerated.
parent 5f2904f9
2005-09-03 Michael Natterer <mitch@gimp.org>
* app/core/gimp-edit.[ch] (gimp_edit_paste_as_new): don't create a
display here.
(gimp_edit_named_cut)
(gimp_edit_named_copy)
(gimp_edit_named_copy_visible): new functions containing named
buffer wrappers around the functions affecting the global buffer
only.
* app/actions/edit-commands.c: use the new functions instead of
implementing them here, create a display for the image returned
by paste as new.
* app/actions/buffers-commands.c
* app/widgets/gimptoolbox-dnd.c: create displays here too.
* tools/pdbgen/pdb/edit.pdb: added wrappers for paste as new and
wrappers for all the cut/copy/paste named stuff.
Fixes bug #315130. Cleaned up and de-obfuscated.
* libgimp/gimp.def: changed accordingly.
* app/pdb/edit_cmds.c
* app/pdb/internal_procs.c
* libgimp/gimpedit_pdb.[ch]: regenerated.
2005-09-02 Sven Neumann <sven@gimp.org>
* app/widgets/gimpcontainergridview.c
......
......@@ -22,6 +22,7 @@
#include "actions-types.h"
#include "core/gimp.h"
#include "core/gimp-edit.h"
#include "core/gimpcontainer.h"
#include "core/gimpcontext.h"
......@@ -77,10 +78,21 @@ buffers_paste_as_new_cmd_callback (GtkAction *action,
if (buffer && gimp_container_have (container, GIMP_OBJECT (buffer)))
{
GimpImage *gimage = gimp_context_get_image (context);
GimpImage *image = gimp_context_get_image (context);
if (gimage)
gimp_edit_paste_as_new (gimage->gimp, gimage, buffer);
if (image)
{
GimpImage *new_image;
new_image = gimp_edit_paste_as_new (image->gimp, image, buffer);
if (new_image)
{
gimp_create_display (image->gimp, new_image,
GIMP_UNIT_PIXEL, 1.0);
g_object_unref (new_image);
}
}
}
}
......
......@@ -225,7 +225,16 @@ edit_paste_as_new_cmd_callback (GtkAction *action,
if (buffer)
{
gimp_edit_paste_as_new (gimp, action_data_get_image (data), buffer);
GimpImage *image;
image = gimp_edit_paste_as_new (gimp, action_data_get_image (data),
buffer);
if (image)
{
gimp_create_display (image->gimp, image, GIMP_UNIT_PIXEL, 1.0);
g_object_unref (image);
}
g_object_unref (buffer);
}
......@@ -366,9 +375,8 @@ cut_named_buffer_callback (GtkWidget *widget,
const gchar *name,
gpointer data)
{
GimpImage *gimage = GIMP_IMAGE (data);
const GimpBuffer *cut_buffer;
GimpDrawable *drawable;
GimpImage *gimage = GIMP_IMAGE (data);
GimpDrawable *drawable;
drawable = gimp_image_active_drawable (gimage);
......@@ -378,22 +386,12 @@ cut_named_buffer_callback (GtkWidget *widget,
return;
}
cut_buffer = gimp_edit_cut (gimage, drawable,
gimp_get_user_context (gimage->gimp));
if (! (name && strlen (name)))
name = _("(Unnamed Buffer)");
if (cut_buffer)
if (gimp_edit_named_cut (gimage, name, drawable,
gimp_get_user_context (gimage->gimp)))
{
GimpBuffer *new_buffer;
if (! (name && strlen (name)))
name = _("(Unnamed Buffer)");
new_buffer = gimp_buffer_new (cut_buffer->tiles, name, TRUE);
gimp_container_add (gimage->gimp->named_buffers,
GIMP_OBJECT (new_buffer));
g_object_unref (new_buffer);
gimp_image_flush (gimage);
}
}
......@@ -403,9 +401,8 @@ copy_named_buffer_callback (GtkWidget *widget,
const gchar *name,
gpointer data)
{
GimpImage *gimage = GIMP_IMAGE (data);
const GimpBuffer *copy_buffer;
GimpDrawable *drawable;
GimpImage *gimage = GIMP_IMAGE (data);
GimpDrawable *drawable;
drawable = gimp_image_active_drawable (gimage);
......@@ -415,22 +412,12 @@ copy_named_buffer_callback (GtkWidget *widget,
return;
}
copy_buffer = gimp_edit_copy (gimage, drawable,
gimp_get_user_context (gimage->gimp));
if (! (name && strlen (name)))
name = _("(Unnamed Buffer)");
if (copy_buffer)
if (gimp_edit_named_copy (gimage, name, drawable,
gimp_get_user_context (gimage->gimp)))
{
GimpBuffer *new_buffer;
if (! (name && strlen (name)))
name = _("(Unnamed Buffer)");
new_buffer = gimp_buffer_new (copy_buffer->tiles, name, TRUE);
gimp_container_add (gimage->gimp->named_buffers,
GIMP_OBJECT (new_buffer));
g_object_unref (new_buffer);
gimp_image_flush (gimage);
}
}
......@@ -320,12 +320,102 @@ gimp_edit_paste_as_new (Gimp *gimp,
gimp_image_undo_enable (gimage);
gimp_create_display (gimp, gimage, GIMP_UNIT_PIXEL, 1.0);
g_object_unref (gimage);
return gimage;
}
const gchar *
gimp_edit_named_cut (GimpImage *gimage,
const gchar *name,
GimpDrawable *drawable,
GimpContext *context)
{
const GimpBuffer *buffer;
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
g_return_val_if_fail (name != NULL, NULL);
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), NULL);
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
buffer = gimp_edit_cut (gimage, drawable, context);
if (buffer)
{
GimpBuffer *named_buffer;
named_buffer = gimp_buffer_new (buffer->tiles, name, TRUE);
gimp_container_add (gimage->gimp->named_buffers,
GIMP_OBJECT (named_buffer));
g_object_unref (named_buffer);
return gimp_object_get_name (GIMP_OBJECT (named_buffer));
}
return NULL;
}
const gchar *
gimp_edit_named_copy (GimpImage *gimage,
const gchar *name,
GimpDrawable *drawable,
GimpContext *context)
{
const GimpBuffer *buffer;
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
g_return_val_if_fail (name != NULL, NULL);
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), NULL);
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
buffer = gimp_edit_copy (gimage, drawable, context);
if (buffer)
{
GimpBuffer *named_buffer;
named_buffer = gimp_buffer_new (buffer->tiles, name, TRUE);
gimp_container_add (gimage->gimp->named_buffers,
GIMP_OBJECT (named_buffer));
g_object_unref (named_buffer);
return gimp_object_get_name (GIMP_OBJECT (named_buffer));
}
return NULL;
}
const gchar *
gimp_edit_named_copy_visible (GimpImage *gimage,
const gchar *name,
GimpContext *context)
{
const GimpBuffer *buffer;
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
g_return_val_if_fail (name != NULL, NULL);
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
buffer = gimp_edit_copy_visible (gimage, context);
if (buffer)
{
GimpBuffer *named_buffer;
named_buffer = gimp_buffer_new (buffer->tiles, name, TRUE);
gimp_container_add (gimage->gimp->named_buffers,
GIMP_OBJECT (named_buffer));
g_object_unref (named_buffer);
return gimp_object_get_name (GIMP_OBJECT (named_buffer));
}
return NULL;
}
gboolean
gimp_edit_clear (GimpImage *gimage,
GimpDrawable *drawable,
......
......@@ -20,32 +20,45 @@
#define __GIMP_EDIT_H__
const GimpBuffer * gimp_edit_cut (GimpImage *gimage,
GimpDrawable *drawable,
GimpContext *context);
const GimpBuffer * gimp_edit_copy (GimpImage *gimage,
GimpDrawable *drawable,
GimpContext *context);
const GimpBuffer * gimp_edit_copy_visible (GimpImage *gimage,
GimpContext *context);
GimpLayer * gimp_edit_paste (GimpImage *gimage,
GimpDrawable *drawable,
GimpBuffer *paste,
gboolean paste_into,
gint viewport_x,
gint viewport_y,
gint viewport_width,
gint viewport_height);
GimpImage * gimp_edit_paste_as_new (Gimp *gimp,
GimpImage *gimage,
GimpBuffer *paste);
gboolean gimp_edit_clear (GimpImage *gimage,
GimpDrawable *drawable,
GimpContext *context);
gboolean gimp_edit_fill (GimpImage *gimage,
GimpDrawable *drawable,
GimpContext *context,
GimpFillType fill_type);
const GimpBuffer * gimp_edit_cut (GimpImage *gimage,
GimpDrawable *drawable,
GimpContext *context);
const GimpBuffer * gimp_edit_copy (GimpImage *gimage,
GimpDrawable *drawable,
GimpContext *context);
const GimpBuffer * gimp_edit_copy_visible (GimpImage *gimage,
GimpContext *context);
GimpLayer * gimp_edit_paste (GimpImage *gimage,
GimpDrawable *drawable,
GimpBuffer *paste,
gboolean paste_into,
gint viewport_x,
gint viewport_y,
gint viewport_width,
gint viewport_height);
GimpImage * gimp_edit_paste_as_new (Gimp *gimp,
GimpImage *gimage,
GimpBuffer *paste);
const gchar * gimp_edit_named_cut (GimpImage *gimage,
const gchar *name,
GimpDrawable *drawable,
GimpContext *context);
const gchar * gimp_edit_named_copy (GimpImage *gimage,
const gchar *name,
GimpDrawable *drawable,
GimpContext *context);
const gchar * gimp_edit_named_copy_visible (GimpImage *gimage,
const gchar *name,
GimpContext *context);
gboolean gimp_edit_clear (GimpImage *gimage,
GimpDrawable *drawable,
GimpContext *context);
gboolean gimp_edit_fill (GimpImage *gimage,
GimpDrawable *drawable,
GimpContext *context,
GimpFillType fill_type);
#endif /* __GIMP_EDIT_H__ */
......@@ -20,6 +20,7 @@
#include "config.h"
#include <string.h>
#include <glib-object.h>
......@@ -29,6 +30,7 @@
#include "core/gimp-edit.h"
#include "core/gimp.h"
#include "core/gimpchannel.h"
#include "core/gimpcontainer.h"
#include "core/gimpdrawable-blend.h"
#include "core/gimpdrawable-bucket-fill.h"
#include "core/gimpdrawable.h"
......@@ -42,6 +44,12 @@ static ProcRecord edit_cut_proc;
static ProcRecord edit_copy_proc;
static ProcRecord edit_copy_visible_proc;
static ProcRecord edit_paste_proc;
static ProcRecord edit_paste_as_new_proc;
static ProcRecord edit_named_cut_proc;
static ProcRecord edit_named_copy_proc;
static ProcRecord edit_named_copy_visible_proc;
static ProcRecord edit_named_paste_proc;
static ProcRecord edit_named_paste_as_new_proc;
static ProcRecord edit_clear_proc;
static ProcRecord edit_fill_proc;
static ProcRecord edit_bucket_fill_proc;
......@@ -55,6 +63,12 @@ register_edit_procs (Gimp *gimp)
procedural_db_register (gimp, &edit_copy_proc);
procedural_db_register (gimp, &edit_copy_visible_proc);
procedural_db_register (gimp, &edit_paste_proc);
procedural_db_register (gimp, &edit_paste_as_new_proc);
procedural_db_register (gimp, &edit_named_cut_proc);
procedural_db_register (gimp, &edit_named_copy_proc);
procedural_db_register (gimp, &edit_named_copy_visible_proc);
procedural_db_register (gimp, &edit_named_paste_proc);
procedural_db_register (gimp, &edit_named_paste_as_new_proc);
procedural_db_register (gimp, &edit_clear_proc);
procedural_db_register (gimp, &edit_fill_proc);
procedural_db_register (gimp, &edit_bucket_fill_proc);
......@@ -83,9 +97,9 @@ edit_cut_invoker (Gimp *gimp,
if (success)
{
GimpImage *gimage = gimp_item_get_image (GIMP_ITEM (drawable));
GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
non_empty = gimp_edit_cut (gimage, drawable, context) != NULL;
non_empty = gimp_edit_cut (image, drawable, context) != NULL;
}
}
......@@ -154,9 +168,9 @@ edit_copy_invoker (Gimp *gimp,
if (success)
{
GimpImage *gimage = gimp_item_get_image (GIMP_ITEM (drawable));
GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
non_empty = gimp_edit_copy (gimage, drawable, context) != NULL;
non_empty = gimp_edit_copy (image, drawable, context) != NULL;
}
}
......@@ -350,6 +364,491 @@ static ProcRecord edit_paste_proc =
{ { edit_paste_invoker } }
};
static Argument *
edit_paste_as_new_invoker (Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
Argument *args)
{
gboolean success = TRUE;
Argument *return_args;
GimpImage *image = NULL;
success = (gimp->global_buffer != NULL);
if (success)
{
image = gimp_edit_paste_as_new (gimp, NULL, gimp->global_buffer);
if (! image)
success = FALSE;
}
return_args = procedural_db_return_args (&edit_paste_as_new_proc, success);
if (success)
return_args[1].value.pdb_int = gimp_image_get_ID (image);
return return_args;
}
static ProcArg edit_paste_as_new_outargs[] =
{
{
GIMP_PDB_IMAGE,
"image",
"The new image"
}
};
static ProcRecord edit_paste_as_new_proc =
{
"gimp-edit-paste-as-new",
"gimp-edit-paste-as-new",
"Paste buffer to a new image.",
"This procedure pastes a copy of the internal GIMP edit buffer to a new image. The GIMP edit buffer will be empty unless a call was previously made to either 'gimp-edit-cut' or 'gimp-edit-copy'. This procedure returns the new image.",
"Michael Natterer <mitch@gimp.org>",
"Michael Natterer <mitch@gimp.org>",
"2005",
NULL,
GIMP_INTERNAL,
0,
NULL,
1,
edit_paste_as_new_outargs,
{ { edit_paste_as_new_invoker } }
};
static Argument *
edit_named_cut_invoker (Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
Argument *args)
{
gboolean success = TRUE;
Argument *return_args;
GimpDrawable *drawable;
gchar *buffer_name;
gchar *real_name = NULL;
drawable = (GimpDrawable *) gimp_item_get_by_ID (gimp, args[0].value.pdb_int);
if (! (GIMP_IS_DRAWABLE (drawable) && ! gimp_item_is_removed (GIMP_ITEM (drawable))))
success = FALSE;
buffer_name = (gchar *) args[1].value.pdb_pointer;
if (buffer_name == NULL || !g_utf8_validate (buffer_name, -1, NULL))
success = FALSE;
if (success)
{
success = (strlen (buffer_name) > 0 &&
gimp_item_is_attached (GIMP_ITEM (drawable)));
if (success)
{
GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
real_name = (gchar *) gimp_edit_named_cut (image, buffer_name,
drawable, context);
if (real_name)
real_name = g_strdup (real_name);
else
success = FALSE;
}
}
return_args = procedural_db_return_args (&edit_named_cut_proc, success);
if (success)
return_args[1].value.pdb_pointer = real_name;
return return_args;
}
static ProcArg edit_named_cut_inargs[] =
{
{
GIMP_PDB_DRAWABLE,
"drawable",
"The drawable to cut from"
},
{
GIMP_PDB_STRING,
"buffer-name",
"The name of the buffer to create"
}
};
static ProcArg edit_named_cut_outargs[] =
{
{
GIMP_PDB_STRING,
"real-name",
"The real name given to the buffer, or NULL if the selection contained only transparent pixels"
}
};
static ProcRecord edit_named_cut_proc =
{
"gimp-edit-named-cut",
"gimp-edit-named-cut",
"Cut into a named buffer.",
"This procedure works like gimp-edit-cut, but additionally stores the cut buffer into a named buffer that will stay available for later pasting, regardless of any intermediate copy or cut operations.",
"Michael Natterer <mitch@gimp.org>",
"Michael Natterer <mitch@gimp.org>",
"2005",
NULL,
GIMP_INTERNAL,
2,
edit_named_cut_inargs,
1,
edit_named_cut_outargs,
{ { edit_named_cut_invoker } }
};
static Argument *
edit_named_copy_invoker (Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
Argument *args)
{
gboolean success = TRUE;
Argument *return_args;
GimpDrawable *drawable;
gchar *buffer_name;
gchar *real_name = NULL;
drawable = (GimpDrawable *) gimp_item_get_by_ID (gimp, args[0].value.pdb_int);
if (! (GIMP_IS_DRAWABLE (drawable) && ! gimp_item_is_removed (GIMP_ITEM (drawable))))
success = FALSE;
buffer_name = (gchar *) args[1].value.pdb_pointer;
if (buffer_name == NULL || !g_utf8_validate (buffer_name, -1, NULL))
success = FALSE;
if (success)
{
success = (strlen (buffer_name) > 0 &&
gimp_item_is_attached (GIMP_ITEM (drawable)));
if (success)
{
GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
real_name = (gchar *) gimp_edit_named_copy (image, buffer_name,
drawable, context);
if (real_name)
real_name = g_strdup (real_name);
else
success = FALSE;
}
}
return_args = procedural_db_return_args (&edit_named_copy_proc, success);
if (success)
return_args[1].value.pdb_pointer = real_name;
return return_args;
}
static ProcArg edit_named_copy_inargs[] =
{
{
GIMP_PDB_DRAWABLE,
"drawable",
"The drawable to copy from"
},
{
GIMP_PDB_STRING,
"buffer-name",
"The name of the buffer to create"
}
};
static ProcArg edit_named_copy_outargs[] =
{
{
GIMP_PDB_STRING,
"real-name",
"The real name given to the buffer, or NULL if the selection contained only transparent pixels"
}
};
static ProcRecord edit_named_copy_proc =
{
"gimp-edit-named-copy",
"gimp-edit-named-copy",
"Copy into a named buffer.",
"This procedure works like gimp-edit-copy, but additionally stores the copied buffer into a named buffer that will stay available for later pasting, regardless of any intermediate copy or cut operations.",
"Michael Natterer <mitch@gimp.org>",
"Michael Natterer <mitch@gimp.org>",
"2005",