From 26ae4062a795d5be34d6d7c2c82b4077a1984cc7 Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Sat, 13 Sep 2003 02:33:30 +0000 Subject: [PATCH] app/core/core-enums.[ch] add vectors in an undo-group. 2003-09-13 Sven Neumann * app/core/core-enums.[ch] * app/vectors/gimpvectors-import.c: add vectors in an undo-group. * app/gui/vectors-commands.c: added simple file selection dialogs for vectors import and export. --- ChangeLog | 8 ++ app/actions/vectors-commands.c | 147 +++++++++++++++++++++++++++---- app/core/core-enums.c | 1 + app/core/core-enums.h | 1 + app/gui/vectors-commands.c | 147 +++++++++++++++++++++++++++---- app/vectors/gimpvectors-import.c | 6 ++ 6 files changed, 280 insertions(+), 30 deletions(-) diff --git a/ChangeLog b/ChangeLog index 39aef23042..f1fe83f61a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2003-09-13 Sven Neumann + + * app/core/core-enums.[ch] + * app/vectors/gimpvectors-import.c: add vectors in an undo-group. + + * app/gui/vectors-commands.c: added simple file selection dialogs + for vectors import and export. + 2003-09-13 Sven Neumann * app/vectors/gimpvectors-import.c: simplified the parser and diff --git a/app/actions/vectors-commands.c b/app/actions/vectors-commands.c index 3bb41f846e..d8b38aa334 100644 --- a/app/actions/vectors-commands.c +++ b/app/actions/vectors-commands.c @@ -77,6 +77,11 @@ return +static void vectors_import_query (GimpImage *gimage); +static void vectors_export_query (GimpImage *gimage, + GimpVectors *vectors); + + /* public functions */ void @@ -227,16 +232,9 @@ vectors_import_cmd_callback (GtkWidget *widget, gpointer data) { GimpImage *gimage; - GError *error = NULL; return_if_no_image (gimage, data); - if (! gimp_vectors_import (gimage, "path.svg", FALSE, &error)) - { - g_message (error->message); - g_error_free (error); - } - - gimp_image_flush (gimage); + vectors_import_query (gimage); } void @@ -245,15 +243,9 @@ vectors_export_cmd_callback (GtkWidget *widget, { GimpImage *gimage; GimpVectors *active_vectors; - GError *error = NULL; return_if_no_vectors (gimage, active_vectors, data); - if (! gimp_vectors_export (gimage, active_vectors, - "path-export.svg", &error)) - { - g_message (error->message); - g_error_free (error); - } + vectors_export_query (gimage, active_vectors); } void @@ -595,3 +587,128 @@ vectors_edit_vectors_query (GimpVectors *vectors) gtk_widget_show (hbox); gtk_widget_show (options->query_box); } + + +/*******************************/ +/* The vectors import dialog */ +/*******************************/ + +static void +vectors_import_ok_callback (GtkWidget *widget) +{ + GimpImage *gimage = g_object_get_data (G_OBJECT (widget), "gimp-image"); + + if (gimage) + { + const gchar *filename; + GError *error = NULL; + + filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (widget)); + + if (gimp_vectors_import (gimage, filename, FALSE, &error)) + { + gimp_image_flush (gimage); + } + else + { + g_message (error->message); + g_error_free (error); + } + + g_object_weak_unref (G_OBJECT (gimage), + (GWeakNotify) gtk_widget_destroy, widget); + } + + gtk_widget_destroy (widget); +} + +static void +vectors_import_query (GimpImage *gimage) +{ + GtkFileSelection *filesel; + + filesel = + GTK_FILE_SELECTION (gtk_file_selection_new (_("Import Paths from SVG"))); + + g_object_set_data (G_OBJECT (filesel), "gimp-image", gimage); + g_object_weak_ref (G_OBJECT (gimage), + (GWeakNotify) gtk_widget_destroy, filesel); + + gtk_window_set_wmclass (GTK_WINDOW (filesel), "gimp-vectors-import", "Gimp"); + gtk_window_set_position (GTK_WINDOW (filesel), GTK_WIN_POS_MOUSE); + + gtk_container_set_border_width (GTK_CONTAINER (filesel), 2); + gtk_container_set_border_width (GTK_CONTAINER (filesel->button_area), 2); + + g_signal_connect_swapped (filesel->ok_button, "clicked", + G_CALLBACK (vectors_import_ok_callback), + filesel); + g_signal_connect_swapped (filesel->cancel_button, "clicked", + G_CALLBACK (gtk_widget_destroy), + filesel); + + gtk_widget_show (GTK_WIDGET (filesel)); +} + + +/*******************************/ +/* The vectors export dialog */ +/*******************************/ + +static void +vectors_export_ok_callback (GtkWidget *widget) +{ + GimpImage *gimage = g_object_get_data (G_OBJECT (widget), "gimp-image"); + + if (gimage) + { + const gchar *filename; + GError *error = NULL; + + filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (widget)); + + if (gimp_vectors_export (gimage, NULL, filename, &error)) + { + gimp_image_flush (gimage); + } + else + { + g_message (error->message); + g_error_free (error); + } + + g_object_weak_unref (G_OBJECT (gimage), + (GWeakNotify) gtk_widget_destroy, widget); + } + + gtk_widget_destroy (widget); +} + +static void +vectors_export_query (GimpImage *gimage, + GimpVectors *vectors) +{ + GtkFileSelection *filesel; + + filesel = + GTK_FILE_SELECTION (gtk_file_selection_new (_("Export Path to SVG"))); + + g_object_set_data (G_OBJECT (filesel), "gimp-image", gimage); + g_object_weak_ref (G_OBJECT (gimage), + (GWeakNotify) gtk_widget_destroy, filesel); + + gtk_window_set_wmclass (GTK_WINDOW (filesel), "gimp-vectors-export", "Gimp"); + gtk_window_set_position (GTK_WINDOW (filesel), GTK_WIN_POS_MOUSE); + + gtk_container_set_border_width (GTK_CONTAINER (filesel), 2); + gtk_container_set_border_width (GTK_CONTAINER (filesel->button_area), 2); + + g_signal_connect_swapped (filesel->ok_button, "clicked", + G_CALLBACK (vectors_export_ok_callback), + filesel); + g_signal_connect_swapped (filesel->cancel_button, "clicked", + G_CALLBACK (gtk_widget_destroy), + filesel); + + gtk_widget_show (GTK_WIDGET (filesel)); +} diff --git a/app/core/core-enums.c b/app/core/core-enums.c index b56559a840..6fa8460401 100644 --- a/app/core/core-enums.c +++ b/app/core/core-enums.c @@ -518,6 +518,7 @@ static const GEnumValue gimp_undo_type_enum_values[] = { GIMP_UNDO_GROUP_PAINT, N_("Paint"), "group-paint" }, { GIMP_UNDO_GROUP_PARASITE_ATTACH, N_("Attach Parasite"), "group-parasite-attach" }, { GIMP_UNDO_GROUP_PARASITE_REMOVE, N_("Remove Parasite"), "group-parasite-remove" }, + { GIMP_UNDO_GROUP_VECTORS_IMPORT, N_("Import Paths"), "group-vectors-import" }, { GIMP_UNDO_GROUP_MISC, N_("Plug-In"), "group-misc" }, { GIMP_UNDO_IMAGE, N_("Image"), "image" }, { GIMP_UNDO_IMAGE_MOD, N_("Image Mod"), "image-mod" }, diff --git a/app/core/core-enums.h b/app/core/core-enums.h index 1de9c28365..0e90f92f2b 100644 --- a/app/core/core-enums.h +++ b/app/core/core-enums.h @@ -381,6 +381,7 @@ typedef enum /*< pdb-skip >*/ GIMP_UNDO_GROUP_PAINT, /*< desc="Paint" >*/ GIMP_UNDO_GROUP_PARASITE_ATTACH, /*< desc="Attach Parasite" >*/ GIMP_UNDO_GROUP_PARASITE_REMOVE, /*< desc="Remove Parasite" >*/ + GIMP_UNDO_GROUP_VECTORS_IMPORT, /*< desc="Import Paths" >*/ GIMP_UNDO_GROUP_MISC, /*< desc="Plug-In" >*/ GIMP_UNDO_GROUP_LAST = GIMP_UNDO_GROUP_MISC, /*< skip >*/ diff --git a/app/gui/vectors-commands.c b/app/gui/vectors-commands.c index 3bb41f846e..d8b38aa334 100644 --- a/app/gui/vectors-commands.c +++ b/app/gui/vectors-commands.c @@ -77,6 +77,11 @@ return +static void vectors_import_query (GimpImage *gimage); +static void vectors_export_query (GimpImage *gimage, + GimpVectors *vectors); + + /* public functions */ void @@ -227,16 +232,9 @@ vectors_import_cmd_callback (GtkWidget *widget, gpointer data) { GimpImage *gimage; - GError *error = NULL; return_if_no_image (gimage, data); - if (! gimp_vectors_import (gimage, "path.svg", FALSE, &error)) - { - g_message (error->message); - g_error_free (error); - } - - gimp_image_flush (gimage); + vectors_import_query (gimage); } void @@ -245,15 +243,9 @@ vectors_export_cmd_callback (GtkWidget *widget, { GimpImage *gimage; GimpVectors *active_vectors; - GError *error = NULL; return_if_no_vectors (gimage, active_vectors, data); - if (! gimp_vectors_export (gimage, active_vectors, - "path-export.svg", &error)) - { - g_message (error->message); - g_error_free (error); - } + vectors_export_query (gimage, active_vectors); } void @@ -595,3 +587,128 @@ vectors_edit_vectors_query (GimpVectors *vectors) gtk_widget_show (hbox); gtk_widget_show (options->query_box); } + + +/*******************************/ +/* The vectors import dialog */ +/*******************************/ + +static void +vectors_import_ok_callback (GtkWidget *widget) +{ + GimpImage *gimage = g_object_get_data (G_OBJECT (widget), "gimp-image"); + + if (gimage) + { + const gchar *filename; + GError *error = NULL; + + filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (widget)); + + if (gimp_vectors_import (gimage, filename, FALSE, &error)) + { + gimp_image_flush (gimage); + } + else + { + g_message (error->message); + g_error_free (error); + } + + g_object_weak_unref (G_OBJECT (gimage), + (GWeakNotify) gtk_widget_destroy, widget); + } + + gtk_widget_destroy (widget); +} + +static void +vectors_import_query (GimpImage *gimage) +{ + GtkFileSelection *filesel; + + filesel = + GTK_FILE_SELECTION (gtk_file_selection_new (_("Import Paths from SVG"))); + + g_object_set_data (G_OBJECT (filesel), "gimp-image", gimage); + g_object_weak_ref (G_OBJECT (gimage), + (GWeakNotify) gtk_widget_destroy, filesel); + + gtk_window_set_wmclass (GTK_WINDOW (filesel), "gimp-vectors-import", "Gimp"); + gtk_window_set_position (GTK_WINDOW (filesel), GTK_WIN_POS_MOUSE); + + gtk_container_set_border_width (GTK_CONTAINER (filesel), 2); + gtk_container_set_border_width (GTK_CONTAINER (filesel->button_area), 2); + + g_signal_connect_swapped (filesel->ok_button, "clicked", + G_CALLBACK (vectors_import_ok_callback), + filesel); + g_signal_connect_swapped (filesel->cancel_button, "clicked", + G_CALLBACK (gtk_widget_destroy), + filesel); + + gtk_widget_show (GTK_WIDGET (filesel)); +} + + +/*******************************/ +/* The vectors export dialog */ +/*******************************/ + +static void +vectors_export_ok_callback (GtkWidget *widget) +{ + GimpImage *gimage = g_object_get_data (G_OBJECT (widget), "gimp-image"); + + if (gimage) + { + const gchar *filename; + GError *error = NULL; + + filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (widget)); + + if (gimp_vectors_export (gimage, NULL, filename, &error)) + { + gimp_image_flush (gimage); + } + else + { + g_message (error->message); + g_error_free (error); + } + + g_object_weak_unref (G_OBJECT (gimage), + (GWeakNotify) gtk_widget_destroy, widget); + } + + gtk_widget_destroy (widget); +} + +static void +vectors_export_query (GimpImage *gimage, + GimpVectors *vectors) +{ + GtkFileSelection *filesel; + + filesel = + GTK_FILE_SELECTION (gtk_file_selection_new (_("Export Path to SVG"))); + + g_object_set_data (G_OBJECT (filesel), "gimp-image", gimage); + g_object_weak_ref (G_OBJECT (gimage), + (GWeakNotify) gtk_widget_destroy, filesel); + + gtk_window_set_wmclass (GTK_WINDOW (filesel), "gimp-vectors-export", "Gimp"); + gtk_window_set_position (GTK_WINDOW (filesel), GTK_WIN_POS_MOUSE); + + gtk_container_set_border_width (GTK_CONTAINER (filesel), 2); + gtk_container_set_border_width (GTK_CONTAINER (filesel->button_area), 2); + + g_signal_connect_swapped (filesel->ok_button, "clicked", + G_CALLBACK (vectors_export_ok_callback), + filesel); + g_signal_connect_swapped (filesel->cancel_button, "clicked", + G_CALLBACK (gtk_widget_destroy), + filesel); + + gtk_widget_show (GTK_WIDGET (filesel)); +} diff --git a/app/vectors/gimpvectors-import.c b/app/vectors/gimpvectors-import.c index 3873635197..e058f1efba 100644 --- a/app/vectors/gimpvectors-import.c +++ b/app/vectors/gimpvectors-import.c @@ -35,6 +35,7 @@ #include "vectors-types.h" #include "core/gimpimage.h" +#include "core/gimpimage-undo.h" #include "gimpbezierstroke.h" #include "gimpstroke.h" @@ -182,6 +183,9 @@ gimp_vectors_import (GimpImage *image, base.paths = g_list_reverse (base.paths); + gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_VECTORS_IMPORT, + _("Import Paths")); + vectors = gimp_vectors_new (image, _("Imported Path")); for (paths = base.paths; paths; paths = paths->next) @@ -201,6 +205,8 @@ gimp_vectors_import (GimpImage *image, } gimp_image_add_vectors (image, vectors, -1); + + gimp_image_undo_group_end (image); } else {