reordered drop destinations so vectors are preferred over SVG.

2004-06-29  Michael Natterer  <mitch@gimp.org>

	* app/display/gimpdisplayshell.c: reordered drop destinations
	so vectors are preferred over SVG.

	* app/vectors/gimpvectors-import.[ch]: added "gint position"
	parameter to all import functions so the imported vectors can be
	added at any position in the vectors stack.

	* app/actions/vectors-commands.c
	* app/display/gimpdisplayshell-dnd.c
	* tools/pdbgen/pdb/paths.pdb: changed accordingly (pass -1 as
	position).

	* app/pdb/paths_cmds.c: regenerated.

	* app/widgets/gimpvectorstreeview.c: implemented SVG DND from and
	to the paths dialog.
This commit is contained in:
Michael Natterer 2004-06-29 13:34:16 +00:00 committed by Michael Natterer
parent 03b4c71d69
commit 4685112cff
9 changed files with 190 additions and 21 deletions

View File

@ -1,3 +1,22 @@
2004-06-29 Michael Natterer <mitch@gimp.org>
* app/display/gimpdisplayshell.c: reordered drop destinations
so vectors are preferred over SVG.
* app/vectors/gimpvectors-import.[ch]: added "gint position"
parameter to all import functions so the imported vectors can be
added at any position in the vectors stack.
* app/actions/vectors-commands.c
* app/display/gimpdisplayshell-dnd.c
* tools/pdbgen/pdb/paths.pdb: changed accordingly (pass -1 as
position).
* app/pdb/paths_cmds.c: regenerated.
* app/widgets/gimpvectorstreeview.c: implemented SVG DND from and
to the paths dialog.
2004-06-29 Michael Natterer <mitch@gimp.org>
* app/widgets/gimpcontainertreeview-dnd.c: don't free the SVG data

View File

@ -635,7 +635,7 @@ vectors_import_response (GtkWidget *dialog,
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
if (gimp_vectors_import_file (gimage, filename, FALSE, FALSE, &error))
if (gimp_vectors_import_file (gimage, filename, FALSE, FALSE, -1, &error))
{
gimp_image_flush (gimage);
}

View File

@ -51,6 +51,7 @@
#include "gimp-intl.h"
/* #define DEBUG_DND */
#ifdef DEBUG_DND
@ -70,6 +71,8 @@ gimp_display_shell_drop_drawable (GtkWidget *widget,
GType new_type;
GimpItem *new_item;
D (g_print ("drop drawable on canvas\n"));
if (gimage->gimp->busy)
return;
@ -120,6 +123,8 @@ gimp_display_shell_drop_vectors (GtkWidget *widget,
GimpImage *gimage = shell->gdisp->gimage;
GimpItem *new_item;
D (g_print ("drop vectors on canvas\n"));
if (gimage->gimp->busy)
return;
@ -154,13 +159,13 @@ gimp_display_shell_drop_svg (GtkWidget *widget,
GimpImage *gimage = shell->gdisp->gimage;
GError *error = NULL;
D (g_print ("drop SVG on canvas\n"));
if (gimage->gimp->busy)
return;
D (g_print ("drop SVG on canvas\n"));
if (! gimp_vectors_import_buffer (gimage, svg_data, svg_data_len,
TRUE, TRUE, &error))
TRUE, TRUE, -1, &error))
{
g_message (error->message);
g_clear_error (&error);
@ -222,6 +227,8 @@ gimp_display_shell_drop_pattern (GtkWidget *widget,
GimpViewable *viewable,
gpointer data)
{
D (g_print ("drop pattern on canvas\n"));
if (GIMP_IS_PATTERN (viewable))
gimp_display_shell_bucket_fill (GIMP_DISPLAY_SHELL (data),
GIMP_PATTERN_BUCKET_FILL,
@ -233,6 +240,8 @@ gimp_display_shell_drop_color (GtkWidget *widget,
const GimpRGB *color,
gpointer data)
{
D (g_print ("drop color on canvas\n"));
gimp_display_shell_bucket_fill (GIMP_DISPLAY_SHELL (data),
GIMP_FG_BUCKET_FILL,
color, NULL);
@ -248,6 +257,8 @@ gimp_display_shell_drop_buffer (GtkWidget *widget,
GimpBuffer *buffer;
gint x, y, width, height;
D (g_print ("drop buffer on canvas\n"));
if (gimage->gimp->busy)
return;
@ -277,6 +288,8 @@ gimp_display_shell_drop_files (GtkWidget *widget,
GimpContext *context;
GList *list;
D (g_print ("drop files on canvas\n"));
context = gimp_get_user_context (gimage->gimp);
for (list = files; list; list = g_list_next (list))

View File

@ -362,9 +362,6 @@ gimp_display_shell_init (GimpDisplayShell *shell)
gimp_dnd_viewable_dest_add (GTK_WIDGET (shell), GIMP_TYPE_CHANNEL,
gimp_display_shell_drop_drawable,
shell);
gimp_dnd_svg_dest_add (GTK_WIDGET (shell),
gimp_display_shell_drop_svg,
shell);
gimp_dnd_viewable_dest_add (GTK_WIDGET (shell), GIMP_TYPE_VECTORS,
gimp_display_shell_drop_vectors,
shell);
@ -377,6 +374,9 @@ gimp_display_shell_init (GimpDisplayShell *shell)
gimp_dnd_color_dest_add (GTK_WIDGET (shell),
gimp_display_shell_drop_color,
shell);
gimp_dnd_svg_dest_add (GTK_WIDGET (shell),
gimp_display_shell_drop_svg,
shell);
gimp_help_connect (GTK_WIDGET (shell), gimp_standard_help_func,
GIMP_HELP_IMAGE_WINDOW, NULL);

View File

@ -1237,7 +1237,7 @@ path_import_invoker (Gimp *gimp,
scale = args[3].value.pdb_int ? TRUE : FALSE;
if (success)
success = gimp_vectors_import_file (gimage, filename, merge, scale, NULL);
success = gimp_vectors_import_file (gimage, filename, merge, scale, -1, NULL);
return procedural_db_return_args (&path_import_proc, success);
}

View File

@ -93,6 +93,7 @@ static gboolean gimp_vectors_import (GimpImage *image,
gint len,
gboolean merge,
gboolean scale,
gint position,
GError **error);
static void svg_parser_start_element (GMarkupParseContext *context,
@ -169,13 +170,15 @@ gimp_vectors_import_file (GimpImage *image,
const gchar *filename,
gboolean merge,
gboolean scale,
gint position,
GError **error)
{
g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
g_return_val_if_fail (filename != NULL, FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
return gimp_vectors_import (image, filename, NULL, 0, merge, scale, error);
return gimp_vectors_import (image, filename, NULL, 0, merge, scale, position,
error);
}
/**
@ -197,13 +200,15 @@ gimp_vectors_import_buffer (GimpImage *image,
gint len,
gboolean merge,
gboolean scale,
gint position,
GError **error)
{
g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
g_return_val_if_fail (buffer != NULL || len == 0, FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
return gimp_vectors_import (image, NULL, buffer, len, merge, scale, error);
return gimp_vectors_import (image, NULL, buffer, len, merge, scale, position,
error);
}
static gboolean
@ -213,6 +218,7 @@ gimp_vectors_import (GimpImage *image,
gint len,
gboolean merge,
gboolean scale,
gint position,
GError **error)
{
GimpXmlParser *xml_parser;
@ -266,8 +272,11 @@ gimp_vectors_import (GimpImage *image,
vectors = gimp_vectors_new (image,
((merge || !path->id) ?
_("Imported Path") : path->id));
gimp_image_add_vectors (image, vectors, -1);
gimp_image_add_vectors (image, vectors, position);
gimp_vectors_freeze (vectors);
if (position != -1)
position++;
}
for (list = path->strokes; list; list = list->next)

View File

@ -27,12 +27,14 @@ gboolean gimp_vectors_import_file (GimpImage *image,
const gchar *filename,
gboolean merge,
gboolean scale,
gint position,
GError **error);
gboolean gimp_vectors_import_buffer (GimpImage *image,
const gchar *buffer,
gint len,
gboolean merge,
gboolean scale,
gint position,
GError **error);

View File

@ -21,6 +21,8 @@
#include "config.h"
#include <string.h>
#include <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
@ -33,6 +35,8 @@
#include "core/gimpimage.h"
#include "vectors/gimpvectors.h"
#include "vectors/gimpvectors-export.h"
#include "vectors/gimpvectors-import.h"
#include "gimpcontainerview.h"
#include "gimpvectorstreeview.h"
@ -46,12 +50,25 @@
static void gimp_vectors_tree_view_class_init (GimpVectorsTreeViewClass *klass);
static void gimp_vectors_tree_view_init (GimpVectorsTreeView *view);
static void gimp_vectors_tree_view_view_iface_init (GimpContainerViewInterface *view_iface);
static GObject * gimp_vectors_tree_view_constructor (GType type,
guint n_params,
GObjectConstructParam *params);
static void gimp_vectors_tree_view_set_container (GimpContainerView *view,
GimpContainer *container);
static void gimp_vectors_tree_view_drop_svg (GimpContainerTreeView *tree_view,
const gchar *svg_data,
gint svg_data_len,
GimpViewable *dest_viewable,
GtkTreeViewDropPosition drop_pos);
static gchar * gimp_vectors_tree_view_drag_svg (GtkWidget *widget,
gint *svg_data_len,
gpointer data);
static GimpItemTreeViewClass *parent_class = NULL;
static GimpContainerViewInterface *parent_view_iface = NULL;
GType
@ -74,9 +91,19 @@ gimp_vectors_tree_view_get_type (void)
(GInstanceInitFunc) gimp_vectors_tree_view_init,
};
static const GInterfaceInfo view_iface_info =
{
(GInterfaceInitFunc) gimp_vectors_tree_view_view_iface_init,
NULL, /* iface_finalize */
NULL /* iface_data */
};
view_type = g_type_register_static (GIMP_TYPE_ITEM_TREE_VIEW,
"GimpVectorsTreeView",
&view_info, 0);
g_type_add_interface_static (view_type, GIMP_TYPE_CONTAINER_VIEW,
&view_iface_info);
}
return view_type;
@ -85,13 +112,20 @@ gimp_vectors_tree_view_get_type (void)
static void
gimp_vectors_tree_view_class_init (GimpVectorsTreeViewClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpItemTreeViewClass *item_view_class = GIMP_ITEM_TREE_VIEW_CLASS (klass);
GObjectClass *object_class;
GimpContainerTreeViewClass *view_class;
GimpItemTreeViewClass *item_view_class;
object_class = G_OBJECT_CLASS (klass);
view_class = GIMP_CONTAINER_TREE_VIEW_CLASS (klass);
item_view_class = GIMP_ITEM_TREE_VIEW_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
object_class->constructor = gimp_vectors_tree_view_constructor;
view_class->drop_svg = gimp_vectors_tree_view_drop_svg;
item_view_class->get_container = gimp_image_get_vectors;
item_view_class->get_active_item = (GimpGetItemFunc) gimp_image_get_active_vectors;
item_view_class->set_active_item = (GimpSetItemFunc) gimp_image_set_active_vectors;
@ -123,6 +157,14 @@ gimp_vectors_tree_view_init (GimpVectorsTreeView *view)
{
}
static void
gimp_vectors_tree_view_view_iface_init (GimpContainerViewInterface *view_iface)
{
parent_view_iface = g_type_interface_peek_parent (view_iface);
view_iface->set_container = gimp_vectors_tree_view_set_container;
}
static GObject *
gimp_vectors_tree_view_constructor (GType type,
guint n_params,
@ -130,12 +172,14 @@ gimp_vectors_tree_view_constructor (GType type,
{
GObject *object;
GimpEditor *editor;
GimpContainerTreeView *tree_view;
GimpVectorsTreeView *view;
gchar *str;
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
editor = GIMP_EDITOR (object);
tree_view = GIMP_CONTAINER_TREE_VIEW (object);
view = GIMP_VECTORS_TREE_VIEW (object);
/* Hide basically useless Edit button */
@ -194,6 +238,8 @@ gimp_vectors_tree_view_constructor (GType type,
gtk_box_reorder_child (GTK_BOX (editor->button_box),
view->stroke_button, 7);
gimp_dnd_svg_dest_add (GTK_WIDGET (tree_view->view), NULL, view);
gimp_container_view_enable_dnd (GIMP_CONTAINER_VIEW (editor),
GTK_BUTTON (view->toselection_button),
GIMP_TYPE_VECTORS);
@ -203,3 +249,83 @@ gimp_vectors_tree_view_constructor (GType type,
return object;
}
static void
gimp_vectors_tree_view_set_container (GimpContainerView *view,
GimpContainer *container)
{
GimpContainerTreeView *tree_view = GIMP_CONTAINER_TREE_VIEW (view);
GimpContainer *old_container;
old_container = gimp_container_view_get_container (GIMP_CONTAINER_VIEW (view));
if (old_container && ! container)
{
gimp_dnd_svg_source_remove (GTK_WIDGET (tree_view->view));
}
parent_view_iface->set_container (view, container);
if (! old_container && container)
{
gimp_dnd_svg_source_add (GTK_WIDGET (tree_view->view),
gimp_vectors_tree_view_drag_svg,
tree_view);
}
}
static void
gimp_vectors_tree_view_drop_svg (GimpContainerTreeView *tree_view,
const gchar *svg_data,
gint svg_data_len,
GimpViewable *dest_viewable,
GtkTreeViewDropPosition drop_pos)
{
GimpItemTreeView *view = GIMP_ITEM_TREE_VIEW (tree_view);
GimpImage *gimage = view->gimage;
GError *error = NULL;
gint index;
g_print ("%s: SVG dropped (len = %d)\n", G_STRFUNC, svg_data_len);
index = gimp_image_get_vectors_index (gimage, GIMP_VECTORS (dest_viewable));
if (drop_pos == GTK_TREE_VIEW_DROP_AFTER)
index++;
if (! gimp_vectors_import_buffer (gimage, svg_data, svg_data_len,
TRUE, TRUE, index, &error))
{
g_message (error->message);
g_clear_error (&error);
}
else
{
gimp_image_flush (gimage);
}
}
static gchar *
gimp_vectors_tree_view_drag_svg (GtkWidget *widget,
gint *svg_data_len,
gpointer data)
{
GimpItemTreeView *view = GIMP_ITEM_TREE_VIEW (data);
GimpImage *gimage = view->gimage;
GimpItem *item;
gchar *svg_data = NULL;
item = GIMP_ITEM_TREE_VIEW_GET_CLASS (view)->get_active_item (gimage);
*svg_data_len = 0;
if (item)
{
svg_data = gimp_vectors_export_string (gimage, GIMP_VECTORS (item));
if (svg_data)
*svg_data_len = strlen (svg_data) + 1;
}
return svg_data;
}

View File

@ -664,7 +664,7 @@ HELP
%invoke = (
headers => [ qw("vectors/gimpvectors-import.h") ],
code => 'success = gimp_vectors_import_file (gimage, filename, merge, scale, NULL);'
code => 'success = gimp_vectors_import_file (gimage, filename, merge, scale, -1, NULL);'
);
}