mirror of https://github.com/GNOME/gimp.git
app: make the VectorsOptionsDialog private
and provide a custom callback instead. Also attach the "New Path" and "Edit Path Attributes" to their image/path.
This commit is contained in:
parent
e8a0e6a276
commit
2522c7ed02
|
@ -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));
|
||||
#define EDIT_DIALOG_KEY "gimp-vectors-edit-attributes-dialog"
|
||||
|
||||
g_signal_connect (options->dialog, "response",
|
||||
G_CALLBACK (vectors_edit_vectors_response),
|
||||
options);
|
||||
dialog = dialogs_get_dialog (G_OBJECT (vectors), EDIT_DIALOG_KEY);
|
||||
|
||||
gtk_widget_show (options->dialog);
|
||||
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"
|
||||
|
||||
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);
|
||||
dialog = dialogs_get_dialog (G_OBJECT (image), NEW_DIALOG_KEY);
|
||||
|
||||
g_signal_connect (options->dialog, "response",
|
||||
G_CALLBACK (vectors_new_vectors_response),
|
||||
options);
|
||||
if (! dialog)
|
||||
{
|
||||
GimpDialogConfig *config = GIMP_DIALOG_CONFIG (image->gimp->config);
|
||||
|
||||
gtk_widget_show (options->dialog);
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
GimpDialogConfig *config = GIMP_DIALOG_CONFIG (image->gimp->config);
|
||||
|
||||
config = GIMP_DIALOG_CONFIG (dialog->image->gimp->config);
|
||||
g_object_set (config,
|
||||
"path-new-name", vectors_name,
|
||||
NULL);
|
||||
|
||||
g_object_set (config,
|
||||
"path-new-name",
|
||||
gtk_entry_get_text (GTK_ENTRY (dialog->name_entry)),
|
||||
NULL);
|
||||
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);
|
||||
|
||||
vectors = gimp_vectors_new (dialog->image, config->vectors_new_name);
|
||||
|
||||
gimp_image_add_vectors (dialog->image, vectors,
|
||||
GIMP_IMAGE_ACTIVE_PARENT, -1, TRUE);
|
||||
|
||||
gimp_image_flush (dialog->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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -38,22 +38,45 @@
|
|||
#include "gimp-intl.h"
|
||||
|
||||
|
||||
static void vectors_options_dialog_free (VectorsOptionsDialog *dialog);
|
||||
typedef struct _VectorsOptionsDialog VectorsOptionsDialog;
|
||||
|
||||
|
||||
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)
|
||||
struct _VectorsOptionsDialog
|
||||
{
|
||||
VectorsOptionsDialog *options;
|
||||
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 *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 (options->name_entry), vectors_name);
|
||||
gtk_entry_set_text (GTK_ENTRY (private->name_entry), vectors_name);
|
||||
|
||||
return options;
|
||||
return dialog;
|
||||
}
|
||||
|
||||
static void
|
||||
vectors_options_dialog_free (VectorsOptionsDialog *dialog)
|
||||
vectors_options_dialog_response (GtkWidget *dialog,
|
||||
gint response_id,
|
||||
VectorsOptionsDialog *private)
|
||||
{
|
||||
g_slice_free (VectorsOptionsDialog, dialog);
|
||||
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 *private)
|
||||
{
|
||||
g_slice_free (VectorsOptionsDialog, private);
|
||||
}
|
||||
|
|
|
@ -19,28 +19,25 @@
|
|||
#define __VECTORS_OPTIONS_DIALOG_H__
|
||||
|
||||
|
||||
typedef struct _VectorsOptionsDialog VectorsOptionsDialog;
|
||||
|
||||
struct _VectorsOptionsDialog
|
||||
{
|
||||
GtkWidget *dialog;
|
||||
GtkWidget *name_entry;
|
||||
|
||||
GimpImage *image;
|
||||
GimpVectors *vectors;
|
||||
};
|
||||
typedef void (* GimpVectorsOptionsCallback) (GtkWidget *dialog,
|
||||
GimpImage *image,
|
||||
GimpVectors *vectors,
|
||||
const gchar *vectors_name,
|
||||
gpointer user_data);
|
||||
|
||||
|
||||
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);
|
||||
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__ */
|
||||
|
|
Loading…
Reference in New Issue