[gimp] app: make the VectorsOptionsDialog private
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: make the VectorsOptionsDialog private
- Date: Sat, 24 Sep 2016 18:33:42 +0000 (UTC)
commit 2522c7ed0256fbcee39df21679cf21ba28b4d0d2
Author: Michael Natterer <mitch gimp org>
Date: Sat Sep 24 20:32:44 2016 +0200
app: make the VectorsOptionsDialog private
and provide a custom callback instead. Also attach the "New Path"
and "Edit Path Attributes" to their image/path.
app/actions/vectors-commands.c | 178 +++++++++++++++++-----------------
app/dialogs/layer-add-mask-dialog.c | 7 +-
app/dialogs/vectors-options-dialog.c | 128 +++++++++++++++++--------
app/dialogs/vectors-options-dialog.h | 41 ++++----
4 files changed, 202 insertions(+), 152 deletions(-)
---
diff --git a/app/actions/vectors-commands.c b/app/actions/vectors-commands.c
index 6ae3a2e..411c696 100644
--- a/app/actions/vectors-commands.c
+++ b/app/actions/vectors-commands.c
@@ -73,18 +73,22 @@
/* local function prototypes */
-static void vectors_new_vectors_response (GtkWidget *widget,
- gint response_id,
- VectorsOptionsDialog *options);
-static void vectors_edit_vectors_response (GtkWidget *widget,
- gint response_id,
- VectorsOptionsDialog *options);
-static void vectors_import_response (GtkWidget *widget,
- gint response_id,
- VectorsImportDialog *dialog);
-static void vectors_export_response (GtkWidget *widget,
- gint response_id,
- VectorsExportDialog *dialog);
+static void vectors_new_callback (GtkWidget *dialog,
+ GimpImage *image,
+ GimpVectors *vectors,
+ const gchar *vectors_name,
+ gpointer user_data);
+static void vectors_edit_attributes_callback (GtkWidget *dialog,
+ GimpImage *image,
+ GimpVectors *vectors,
+ const gchar *vectors_name,
+ gpointer user_data);
+static void vectors_import_response (GtkWidget *widget,
+ gint response_id,
+ VectorsImportDialog *dialog);
+static void vectors_export_response (GtkWidget *widget,
+ gint response_id,
+ VectorsExportDialog *dialog);
/* private variables */
@@ -127,58 +131,71 @@ void
vectors_edit_attributes_cmd_callback (GtkAction *action,
gpointer data)
{
- VectorsOptionsDialog *options;
- GimpImage *image;
- GimpVectors *vectors;
- GtkWidget *widget;
+ GimpImage *image;
+ GimpVectors *vectors;
+ GtkWidget *widget;
+ GtkWidget *dialog;
return_if_no_vectors (image, vectors, data);
return_if_no_widget (widget, data);
- options = vectors_options_dialog_new (image, vectors,
- action_data_get_context (data),
- widget,
- _("Path Attributes"),
- "gimp-vectors-edit",
- "gtk-edit",
- _("Edit Path Attributes"),
- GIMP_HELP_PATH_EDIT,
- gimp_object_get_name (vectors));
-
- g_signal_connect (options->dialog, "response",
- G_CALLBACK (vectors_edit_vectors_response),
- options);
-
- gtk_widget_show (options->dialog);
+#define EDIT_DIALOG_KEY "gimp-vectors-edit-attributes-dialog"
+
+ dialog = dialogs_get_dialog (G_OBJECT (vectors), EDIT_DIALOG_KEY);
+
+ if (! dialog)
+ {
+ dialog = vectors_options_dialog_new (image, vectors,
+ action_data_get_context (data),
+ widget,
+ _("Path Attributes"),
+ "gimp-vectors-edit",
+ "gtk-edit",
+ _("Edit Path Attributes"),
+ GIMP_HELP_PATH_EDIT,
+ gimp_object_get_name (vectors),
+ vectors_edit_attributes_callback,
+ NULL);
+
+ dialogs_attach_dialog (G_OBJECT (vectors), EDIT_DIALOG_KEY, dialog);
+ }
+
+ gtk_window_present (GTK_WINDOW (dialog));
}
void
vectors_new_cmd_callback (GtkAction *action,
gpointer data)
{
- VectorsOptionsDialog *options;
- GimpImage *image;
- GtkWidget *widget;
- GimpDialogConfig *config;
+ GimpImage *image;
+ GtkWidget *widget;
+ GtkWidget *dialog;
return_if_no_image (image, data);
return_if_no_widget (widget, data);
- config = GIMP_DIALOG_CONFIG (image->gimp->config);
+#define NEW_DIALOG_KEY "gimp-vectors-new-dialog"
+
+ dialog = dialogs_get_dialog (G_OBJECT (image), NEW_DIALOG_KEY);
+
+ if (! dialog)
+ {
+ GimpDialogConfig *config = GIMP_DIALOG_CONFIG (image->gimp->config);
+
+ dialog = vectors_options_dialog_new (image, NULL,
+ action_data_get_context (data),
+ widget,
+ _("New Path"),
+ "gimp-vectors-new",
+ GIMP_STOCK_PATH,
+ _("New Path Options"),
+ GIMP_HELP_PATH_NEW,
+ config->vectors_new_name,
+ vectors_new_callback,
+ NULL);
+
+ dialogs_attach_dialog (G_OBJECT (image), NEW_DIALOG_KEY, dialog);
+ }
- options = vectors_options_dialog_new (image, NULL,
- action_data_get_context (data),
- widget,
- _("New Path"),
- "gimp-vectors-new",
- GIMP_STOCK_PATH,
- _("New Path Options"),
- GIMP_HELP_PATH_NEW,
- config->vectors_new_name);
-
- g_signal_connect (options->dialog, "response",
- G_CALLBACK (vectors_new_vectors_response),
- options);
-
- gtk_widget_show (options->dialog);
+ gtk_window_present (GTK_WINDOW (dialog));
}
void
@@ -763,53 +780,40 @@ vectors_lock_position_cmd_callback (GtkAction *action,
/* private functions */
static void
-vectors_new_vectors_response (GtkWidget *widget,
- gint response_id,
- VectorsOptionsDialog *dialog)
+vectors_new_callback (GtkWidget *dialog,
+ GimpImage *image,
+ GimpVectors *vectors,
+ const gchar *vectors_name,
+ gpointer user_data)
{
- if (response_id == GTK_RESPONSE_OK)
- {
- GimpDialogConfig *config;
- GimpVectors *vectors;
-
- config = GIMP_DIALOG_CONFIG (dialog->image->gimp->config);
-
- g_object_set (config,
- "path-new-name",
- gtk_entry_get_text (GTK_ENTRY (dialog->name_entry)),
- NULL);
+ GimpDialogConfig *config = GIMP_DIALOG_CONFIG (image->gimp->config);
- vectors = gimp_vectors_new (dialog->image, config->vectors_new_name);
+ g_object_set (config,
+ "path-new-name", vectors_name,
+ NULL);
- gimp_image_add_vectors (dialog->image, vectors,
- GIMP_IMAGE_ACTIVE_PARENT, -1, TRUE);
-
- gimp_image_flush (dialog->image);
- }
+ vectors = gimp_vectors_new (image, config->vectors_new_name);
+ gimp_image_add_vectors (image, vectors,
+ GIMP_IMAGE_ACTIVE_PARENT, -1, TRUE);
+ gimp_image_flush (image);
- gtk_widget_destroy (dialog->dialog);
+ gtk_widget_destroy (dialog);
}
static void
-vectors_edit_vectors_response (GtkWidget *widget,
- gint response_id,
- VectorsOptionsDialog *options)
+vectors_edit_attributes_callback (GtkWidget *dialog,
+ GimpImage *image,
+ GimpVectors *vectors,
+ const gchar *vectors_name,
+ gpointer user_data)
{
- if (response_id == GTK_RESPONSE_OK)
+ if (strcmp (vectors_name, gimp_object_get_name (vectors)))
{
- GimpVectors *vectors = options->vectors;
- const gchar *new_name;
-
- new_name = gtk_entry_get_text (GTK_ENTRY (options->name_entry));
-
- if (strcmp (new_name, gimp_object_get_name (vectors)))
- {
- gimp_item_rename (GIMP_ITEM (vectors), new_name, NULL);
- gimp_image_flush (options->image);
- }
+ gimp_item_rename (GIMP_ITEM (vectors), vectors_name, NULL);
+ gimp_image_flush (image);
}
- gtk_widget_destroy (options->dialog);
+ gtk_widget_destroy (dialog);
}
static void
diff --git a/app/dialogs/layer-add-mask-dialog.c b/app/dialogs/layer-add-mask-dialog.c
index 41eb34e..8bea16d 100644
--- a/app/dialogs/layer-add-mask-dialog.c
+++ b/app/dialogs/layer-add-mask-dialog.c
@@ -113,15 +113,14 @@ layer_add_mask_dialog_new (GimpLayer *layer,
NULL);
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
-
- g_object_weak_ref (G_OBJECT (dialog),
- (GWeakNotify) layer_add_mask_dialog_free, private);
-
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
GTK_RESPONSE_OK,
GTK_RESPONSE_CANCEL,
-1);
+ g_object_weak_ref (G_OBJECT (dialog),
+ (GWeakNotify) layer_add_mask_dialog_free, private);
+
g_signal_connect (dialog, "response",
G_CALLBACK (layer_add_mask_dialog_response),
private);
diff --git a/app/dialogs/vectors-options-dialog.c b/app/dialogs/vectors-options-dialog.c
index 72e9057..b1057b6 100644
--- a/app/dialogs/vectors-options-dialog.c
+++ b/app/dialogs/vectors-options-dialog.c
@@ -38,22 +38,45 @@
#include "gimp-intl.h"
-static void vectors_options_dialog_free (VectorsOptionsDialog *dialog);
-
-
-VectorsOptionsDialog *
-vectors_options_dialog_new (GimpImage *image,
- GimpVectors *vectors,
- GimpContext *context,
- GtkWidget *parent,
- const gchar *title,
- const gchar *role,
- const gchar *icon_name,
- const gchar *desc,
- const gchar *help_id,
- const gchar *vectors_name)
+typedef struct _VectorsOptionsDialog VectorsOptionsDialog;
+
+struct _VectorsOptionsDialog
+{
+ GimpImage *image;
+ GimpVectors *vectors;
+ GimpVectorsOptionsCallback callback;
+ gpointer user_data;
+
+ GtkWidget *name_entry;
+};
+
+
+/* local function prototypes */
+
+static void vectors_options_dialog_response (GtkWidget *dialog,
+ gint response_id,
+ VectorsOptionsDialog *private);
+static void vectors_options_dialog_free (VectorsOptionsDialog *private);
+
+
+/* public functions */
+
+GtkWidget *
+vectors_options_dialog_new (GimpImage *image,
+ GimpVectors *vectors,
+ GimpContext *context,
+ GtkWidget *parent,
+ const gchar *title,
+ const gchar *role,
+ const gchar *icon_name,
+ const gchar *desc,
+ const gchar *help_id,
+ const gchar *vectors_name,
+ GimpVectorsOptionsCallback callback,
+ gpointer user_data)
{
- VectorsOptionsDialog *options;
+ VectorsOptionsDialog *private;
+ GtkWidget *dialog;
GimpViewable *viewable;
GtkWidget *hbox;
GtkWidget *vbox;
@@ -68,40 +91,46 @@ vectors_options_dialog_new (GimpImage *image,
g_return_val_if_fail (icon_name != NULL, NULL);
g_return_val_if_fail (desc != NULL, NULL);
g_return_val_if_fail (help_id != NULL, NULL);
+ g_return_val_if_fail (callback != NULL, NULL);
- options = g_slice_new0 (VectorsOptionsDialog);
+ private = g_slice_new0 (VectorsOptionsDialog);
- options->image = image;
- options->vectors = vectors;
+ private->image = image;
+ private->vectors = vectors;
+ private->callback = callback;
+ private->user_data = user_data;
if (vectors)
viewable = GIMP_VIEWABLE (vectors);
else
viewable = GIMP_VIEWABLE (image);
- options->dialog =
- gimp_viewable_dialog_new (viewable, context,
- title, role, icon_name, desc,
- parent,
- gimp_standard_help_func,
- help_id,
+ dialog = gimp_viewable_dialog_new (viewable, context,
+ title, role, icon_name, desc,
+ parent,
+ gimp_standard_help_func,
+ help_id,
- GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
- GTK_STOCK_OK, GTK_RESPONSE_OK,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OK, GTK_RESPONSE_OK,
- NULL);
+ NULL);
- gtk_dialog_set_alternative_button_order (GTK_DIALOG (options->dialog),
+ gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
GTK_RESPONSE_OK,
GTK_RESPONSE_CANCEL,
-1);
- g_object_weak_ref (G_OBJECT (options->dialog),
- (GWeakNotify) vectors_options_dialog_free, options);
+ g_object_weak_ref (G_OBJECT (dialog),
+ (GWeakNotify) vectors_options_dialog_free, private);
+
+ g_signal_connect (dialog, "response",
+ G_CALLBACK (vectors_options_dialog_response),
+ private);
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
gtk_container_set_border_width (GTK_CONTAINER (hbox), 12);
- gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (options->dialog))),
+ gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
hbox, TRUE, TRUE, 0);
gtk_widget_show (hbox);
@@ -115,20 +144,41 @@ vectors_options_dialog_new (GimpImage *image,
gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
gtk_widget_show (table);
- options->name_entry = gtk_entry_new ();
- gtk_widget_set_size_request (options->name_entry, 150, -1);
- gtk_entry_set_activates_default (GTK_ENTRY (options->name_entry), TRUE);
+ private->name_entry = gtk_entry_new ();
+ gtk_widget_set_size_request (private->name_entry, 150, -1);
+ gtk_entry_set_activates_default (GTK_ENTRY (private->name_entry), TRUE);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
_("Path name:"), 0.0, 0.5,
- options->name_entry, 1, FALSE);
+ private->name_entry, 1, FALSE);
+
+ gtk_entry_set_text (GTK_ENTRY (private->name_entry), vectors_name);
- gtk_entry_set_text (GTK_ENTRY (options->name_entry), vectors_name);
+ return dialog;
+}
- return options;
+static void
+vectors_options_dialog_response (GtkWidget *dialog,
+ gint response_id,
+ VectorsOptionsDialog *private)
+{
+ if (response_id == GTK_RESPONSE_OK)
+ {
+ const gchar *name = gtk_entry_get_text (GTK_ENTRY (private->name_entry));
+
+ private->callback (dialog,
+ private->image,
+ private->vectors,
+ name,
+ private->user_data);
+ }
+ else
+ {
+ gtk_widget_destroy (dialog);
+ }
}
static void
-vectors_options_dialog_free (VectorsOptionsDialog *dialog)
+vectors_options_dialog_free (VectorsOptionsDialog *private)
{
- g_slice_free (VectorsOptionsDialog, dialog);
+ g_slice_free (VectorsOptionsDialog, private);
}
diff --git a/app/dialogs/vectors-options-dialog.h b/app/dialogs/vectors-options-dialog.h
index 20e77cb..db8012e 100644
--- a/app/dialogs/vectors-options-dialog.h
+++ b/app/dialogs/vectors-options-dialog.h
@@ -19,28 +19,25 @@
#define __VECTORS_OPTIONS_DIALOG_H__
-typedef struct _VectorsOptionsDialog VectorsOptionsDialog;
-
-struct _VectorsOptionsDialog
-{
- GtkWidget *dialog;
- GtkWidget *name_entry;
-
- GimpImage *image;
- GimpVectors *vectors;
-};
-
-
-VectorsOptionsDialog * vectors_options_dialog_new (GimpImage *image,
- GimpVectors *vectors,
- GimpContext *context,
- GtkWidget *parent,
- const gchar *title,
- const gchar *role,
- const gchar *icon_name,
- const gchar *desc,
- const gchar *help_id,
- const gchar *vectors_name);
+typedef void (* GimpVectorsOptionsCallback) (GtkWidget *dialog,
+ GimpImage *image,
+ GimpVectors *vectors,
+ const gchar *vectors_name,
+ gpointer user_data);
+
+
+GtkWidget * vectors_options_dialog_new (GimpImage *image,
+ GimpVectors *vectors,
+ GimpContext *context,
+ GtkWidget *parent,
+ const gchar *title,
+ const gchar *role,
+ const gchar *icon_name,
+ const gchar *desc,
+ const gchar *help_id,
+ const gchar *vectors_name,
+ GimpVectorsOptionsCallback callback,
+ gpointer user_data);
#endif /* __VECTORS_OPTIONS_DIALOG_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]