[gimp] app: clean up the palette-import-dialog in the spirit of recent dialog cleanup
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: clean up the palette-import-dialog in the spirit of recent dialog cleanup
- Date: Sun, 9 Oct 2016 19:08:58 +0000 (UTC)
commit f027bf53abda1b24fad2cdb6c9f5e90b118b366b
Author: Michael Natterer <mitch gimp org>
Date: Sun Oct 9 21:08:21 2016 +0200
app: clean up the palette-import-dialog in the spirit of recent dialog cleanup
app/dialogs/palette-import-dialog.c | 491 ++++++++++++++++++-----------------
app/dialogs/palette-import-dialog.h | 6 +-
2 files changed, 254 insertions(+), 243 deletions(-)
---
diff --git a/app/dialogs/palette-import-dialog.c b/app/dialogs/palette-import-dialog.c
index 8618bec..7aa032d 100644
--- a/app/dialogs/palette-import-dialog.c
+++ b/app/dialogs/palette-import-dialog.c
@@ -87,42 +87,42 @@ typedef struct
} ImportDialog;
-static void palette_import_free (ImportDialog *dialog);
-static void palette_import_response (GtkWidget *widget,
+static void palette_import_free (ImportDialog *private);
+static void palette_import_response (GtkWidget *dialog,
gint response_id,
- ImportDialog *dialog);
+ ImportDialog *private);
static void palette_import_gradient_changed (GimpContext *context,
GimpGradient *gradient,
- ImportDialog *dialog);
+ ImportDialog *private);
static void palette_import_image_changed (GimpContext *context,
GimpImage *image,
- ImportDialog *dialog);
+ ImportDialog *private);
static void palette_import_layer_changed (GimpImage *image,
- ImportDialog *dialog);
+ ImportDialog *private);
static void palette_import_mask_changed (GimpImage *image,
- ImportDialog *dialog);
+ ImportDialog *private);
static void palette_import_filename_changed (GtkFileChooser *button,
- ImportDialog *dialog);
+ ImportDialog *private);
static void import_dialog_drop_callback (GtkWidget *widget,
gint x,
gint y,
GimpViewable *viewable,
gpointer data);
static void palette_import_grad_callback (GtkWidget *widget,
- ImportDialog *dialog);
+ ImportDialog *private);
static void palette_import_image_callback (GtkWidget *widget,
- ImportDialog *dialog);
+ ImportDialog *private);
static void palette_import_file_callback (GtkWidget *widget,
- ImportDialog *dialog);
+ ImportDialog *private);
static void palette_import_columns_changed (GtkAdjustment *adjustment,
- ImportDialog *dialog);
+ ImportDialog *private);
static void palette_import_image_add (GimpContainer *container,
GimpImage *image,
- ImportDialog *dialog);
+ ImportDialog *private);
static void palette_import_image_remove (GimpContainer *container,
GimpImage *image,
- ImportDialog *dialog);
-static void palette_import_make_palette (ImportDialog *dialog);
+ ImportDialog *private);
+static void palette_import_make_palette (ImportDialog *private);
/* public functions */
@@ -130,8 +130,9 @@ static void palette_import_make_palette (ImportDialog *dialog);
GtkWidget *
palette_import_dialog_new (GimpContext *context)
{
- ImportDialog *dialog;
+ ImportDialog *private;
GimpGradient *gradient;
+ GtkWidget *dialog;
GtkWidget *button;
GtkWidget *main_hbox;
GtkWidget *frame;
@@ -145,51 +146,52 @@ palette_import_dialog_new (GimpContext *context)
gradient = gimp_context_get_gradient (context);
- dialog = g_slice_new0 (ImportDialog);
+ private = g_slice_new0 (ImportDialog);
- dialog->import_type = GRADIENT_IMPORT;
- dialog->context = gimp_context_new (context->gimp, "Palette Import",
+ private->import_type = GRADIENT_IMPORT;
+ private->context = gimp_context_new (context->gimp, "Palette Import",
context);
- dialog->dialog = gimp_dialog_new (_("Import a New Palette"),
- "gimp-palette-import", NULL, 0,
- gimp_standard_help_func,
- GIMP_HELP_PALETTE_IMPORT,
+ dialog = private->dialog =
+ gimp_dialog_new (_("Import a New Palette"),
+ "gimp-palette-import", NULL, 0,
+ gimp_standard_help_func,
+ GIMP_HELP_PALETTE_IMPORT,
- GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
- NULL);
+ NULL);
- button = gtk_dialog_add_button (GTK_DIALOG (dialog->dialog),
+ button = gtk_dialog_add_button (GTK_DIALOG (dialog),
_("_Import"), GTK_RESPONSE_OK);
gtk_button_set_image (GTK_BUTTON (button),
gtk_image_new_from_icon_name ("gtk-convert",
GTK_ICON_SIZE_BUTTON));
- gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog->dialog),
+ gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
GTK_RESPONSE_OK,
GTK_RESPONSE_CANCEL,
-1);
- g_object_set_data_full (G_OBJECT (dialog->dialog), "palette-import-dialog",
- dialog, (GDestroyNotify) palette_import_free);
+ g_object_weak_ref (G_OBJECT (dialog),
+ (GWeakNotify) palette_import_free, private);
- g_signal_connect (dialog->dialog, "response",
+ g_signal_connect (dialog, "response",
G_CALLBACK (palette_import_response),
- dialog);
+ private);
- gimp_dnd_viewable_dest_add (dialog->dialog,
+ gimp_dnd_viewable_dest_add (dialog,
GIMP_TYPE_GRADIENT,
import_dialog_drop_callback,
- dialog);
- gimp_dnd_viewable_dest_add (dialog->dialog,
+ private);
+ gimp_dnd_viewable_dest_add (dialog,
GIMP_TYPE_IMAGE,
import_dialog_drop_callback,
- dialog);
+ private);
main_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
gtk_container_set_border_width (GTK_CONTAINER (main_hbox), 12);
- gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog->dialog))),
+ gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
main_hbox, TRUE, TRUE, 0);
gtk_widget_show (main_hbox);
@@ -210,90 +212,90 @@ palette_import_dialog_new (GimpContext *context)
gtk_container_add (GTK_CONTAINER (frame), table);
gtk_widget_show (table);
- dialog->gradient_radio =
+ private->gradient_radio =
gtk_radio_button_new_with_mnemonic (group, _("_Gradient"));
- group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (dialog->gradient_radio));
- gtk_table_attach (GTK_TABLE (table), dialog->gradient_radio,
+ group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (private->gradient_radio));
+ gtk_table_attach (GTK_TABLE (table), private->gradient_radio,
0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
- gtk_widget_show (dialog->gradient_radio);
+ gtk_widget_show (private->gradient_radio);
- g_signal_connect (dialog->gradient_radio, "toggled",
+ g_signal_connect (private->gradient_radio, "toggled",
G_CALLBACK (palette_import_grad_callback),
- dialog);
+ private);
- dialog->image_radio =
+ private->image_radio =
gtk_radio_button_new_with_mnemonic (group, _("I_mage"));
- group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (dialog->image_radio));
- gtk_table_attach (GTK_TABLE (table), dialog->image_radio,
+ group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (private->image_radio));
+ gtk_table_attach (GTK_TABLE (table), private->image_radio,
0, 1, 1, 2, GTK_FILL, GTK_FILL, 0, 0);
- gtk_widget_show (dialog->image_radio);
+ gtk_widget_show (private->image_radio);
- g_signal_connect (dialog->image_radio, "toggled",
+ g_signal_connect (private->image_radio, "toggled",
G_CALLBACK (palette_import_image_callback),
- dialog);
+ private);
- gtk_widget_set_sensitive (dialog->image_radio,
+ gtk_widget_set_sensitive (private->image_radio,
! gimp_container_is_empty (context->gimp->images));
- dialog->sample_merged_toggle =
+ private->sample_merged_toggle =
gtk_check_button_new_with_mnemonic (_("Sample _Merged"));
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->sample_merged_toggle),
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (private->sample_merged_toggle),
TRUE);
- gtk_table_attach (GTK_TABLE (table), dialog->sample_merged_toggle,
+ gtk_table_attach (GTK_TABLE (table), private->sample_merged_toggle,
1, 2, 2, 3, GTK_FILL, GTK_FILL, 0, 0);
- gtk_widget_show (dialog->sample_merged_toggle);
+ gtk_widget_show (private->sample_merged_toggle);
- g_signal_connect_swapped (dialog->sample_merged_toggle, "toggled",
+ g_signal_connect_swapped (private->sample_merged_toggle, "toggled",
G_CALLBACK (palette_import_make_palette),
- dialog);
+ private);
- dialog->selection_only_toggle =
+ private->selection_only_toggle =
gtk_check_button_new_with_mnemonic (_("_Selected Pixels only"));
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->selection_only_toggle),
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (private->selection_only_toggle),
FALSE);
- gtk_table_attach (GTK_TABLE (table), dialog->selection_only_toggle,
+ gtk_table_attach (GTK_TABLE (table), private->selection_only_toggle,
1, 2, 3, 4, GTK_FILL, GTK_FILL, 0, 0);
- gtk_widget_show (dialog->selection_only_toggle);
+ gtk_widget_show (private->selection_only_toggle);
- g_signal_connect_swapped (dialog->selection_only_toggle, "toggled",
+ g_signal_connect_swapped (private->selection_only_toggle, "toggled",
G_CALLBACK (palette_import_make_palette),
- dialog);
+ private);
- dialog->file_radio =
+ private->file_radio =
gtk_radio_button_new_with_mnemonic (group, _("Palette _file"));
- group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (dialog->image_radio));
- gtk_table_attach (GTK_TABLE (table), dialog->file_radio,
+ group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (private->image_radio));
+ gtk_table_attach (GTK_TABLE (table), private->file_radio,
0, 1, 4, 5, GTK_FILL, GTK_FILL, 0, 0);
- gtk_widget_show (dialog->file_radio);
+ gtk_widget_show (private->file_radio);
- g_signal_connect (dialog->file_radio, "toggled",
+ g_signal_connect (private->file_radio, "toggled",
G_CALLBACK (palette_import_file_callback),
- dialog);
+ private);
size_group = gtk_size_group_new (GTK_SIZE_GROUP_VERTICAL);
/* The gradient menu */
- dialog->gradient_combo =
+ private->gradient_combo =
gimp_container_combo_box_new (gimp_data_factory_get_container (context->gimp->gradient_factory),
- dialog->context, 24, 1);
+ private->context, 24, 1);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
- NULL, 0.0, 0.5, dialog->gradient_combo, 1, FALSE);
- gtk_size_group_add_widget (size_group, dialog->gradient_combo);
+ NULL, 0.0, 0.5, private->gradient_combo, 1, FALSE);
+ gtk_size_group_add_widget (size_group, private->gradient_combo);
/* The image menu */
- dialog->image_combo =
- gimp_container_combo_box_new (context->gimp->images, dialog->context,
+ private->image_combo =
+ gimp_container_combo_box_new (context->gimp->images, private->context,
24, 1);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 1,
- NULL, 0.0, 0.5, dialog->image_combo, 1, FALSE);
- gtk_size_group_add_widget (size_group, dialog->image_combo);
+ NULL, 0.0, 0.5, private->image_combo, 1, FALSE);
+ gtk_size_group_add_widget (size_group, private->image_combo);
/* Palette file name entry */
- dialog->file_chooser = gtk_file_chooser_button_new (_("Select Palette File"),
+ private->file_chooser = gtk_file_chooser_button_new (_("Select Palette File"),
GTK_FILE_CHOOSER_ACTION_OPEN);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 4,
- NULL, 0.0, 0.5, dialog->file_chooser, 1, FALSE);
- gtk_size_group_add_widget (size_group, dialog->file_chooser);
+ NULL, 0.0, 0.5, private->file_chooser, 1, FALSE);
+ gtk_size_group_add_widget (size_group, private->file_chooser);
g_object_unref (size_group);
@@ -311,50 +313,50 @@ palette_import_dialog_new (GimpContext *context)
gtk_widget_show (table);
/* The source's name */
- dialog->entry = gtk_entry_new ();
- gtk_entry_set_text (GTK_ENTRY (dialog->entry),
+ private->entry = gtk_entry_new ();
+ gtk_entry_set_text (GTK_ENTRY (private->entry),
gradient ?
gimp_object_get_name (gradient) : _("New import"));
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
_("Palette _name:"), 0.0, 0.5,
- dialog->entry, 2, FALSE);
+ private->entry, 2, FALSE);
/* The # of colors */
- dialog->num_colors =
+ private->num_colors =
GTK_ADJUSTMENT (gimp_scale_entry_new (GTK_TABLE (table), 0, 1,
_("N_umber of colors:"), -1, 5,
256, 2, 10000, 1, 10, 0,
TRUE, 0.0, 0.0,
NULL, NULL));
- g_signal_connect_swapped (dialog->num_colors,
+ g_signal_connect_swapped (private->num_colors,
"value-changed",
G_CALLBACK (palette_import_make_palette),
- dialog);
+ private);
/* The columns */
- dialog->columns =
+ private->columns =
GTK_ADJUSTMENT (gimp_scale_entry_new (GTK_TABLE (table), 0, 2,
_("C_olumns:"), -1, 5,
16, 0, 64, 1, 8, 0,
TRUE, 0.0, 0.0,
NULL, NULL));
- g_signal_connect (dialog->columns, "value-changed",
+ g_signal_connect (private->columns, "value-changed",
G_CALLBACK (palette_import_columns_changed),
- dialog);
+ private);
/* The interval */
- dialog->threshold =
+ private->threshold =
GTK_ADJUSTMENT (gimp_scale_entry_new (GTK_TABLE (table), 0, 3,
_("I_nterval:"), -1, 5,
1, 1, 128, 1, 8, 0,
TRUE, 0.0, 0.0,
NULL, NULL));
- g_signal_connect_swapped (dialog->threshold, "value-changed",
+ g_signal_connect_swapped (private->threshold, "value-changed",
G_CALLBACK (palette_import_make_palette),
- dialog);
+ private);
/* The "Preview" frame */
@@ -370,99 +372,106 @@ palette_import_dialog_new (GimpContext *context)
gtk_box_pack_start (GTK_BOX (vbox), abox, FALSE, FALSE, 0);
gtk_widget_show (abox);
- dialog->preview = gimp_view_new_full_by_types (dialog->context,
+ private->preview = gimp_view_new_full_by_types (private->context,
GIMP_TYPE_VIEW,
GIMP_TYPE_PALETTE,
192, 192, 1,
TRUE, FALSE, FALSE);
- gtk_container_add (GTK_CONTAINER (abox), dialog->preview);
- gtk_widget_show (dialog->preview);
+ gtk_container_add (GTK_CONTAINER (abox), private->preview);
+ gtk_widget_show (private->preview);
- dialog->no_colors_label =
+ private->no_colors_label =
gtk_label_new (_("The selected source contains no colors."));
- gtk_widget_set_size_request (dialog->no_colors_label, 194, -1);
- gtk_label_set_line_wrap (GTK_LABEL (dialog->no_colors_label), TRUE);
- gimp_label_set_attributes (GTK_LABEL (dialog->no_colors_label),
+ gtk_widget_set_size_request (private->no_colors_label, 194, -1);
+ gtk_label_set_line_wrap (GTK_LABEL (private->no_colors_label), TRUE);
+ gimp_label_set_attributes (GTK_LABEL (private->no_colors_label),
PANGO_ATTR_STYLE, PANGO_STYLE_ITALIC,
-1);
- gtk_box_pack_start (GTK_BOX (vbox), dialog->no_colors_label, FALSE, FALSE, 0);
- gtk_widget_show (dialog->no_colors_label);
+ gtk_box_pack_start (GTK_BOX (vbox), private->no_colors_label, FALSE, FALSE, 0);
+ gtk_widget_show (private->no_colors_label);
/* keep the dialog up-to-date */
g_signal_connect (context->gimp->images, "add",
G_CALLBACK (palette_import_image_add),
- dialog);
+ private);
g_signal_connect (context->gimp->images, "remove",
G_CALLBACK (palette_import_image_remove),
- dialog);
+ private);
- g_signal_connect (dialog->context, "gradient-changed",
+ g_signal_connect (private->context, "gradient-changed",
G_CALLBACK (palette_import_gradient_changed),
- dialog);
- g_signal_connect (dialog->context, "image-changed",
+ private);
+ g_signal_connect (private->context, "image-changed",
G_CALLBACK (palette_import_image_changed),
- dialog);
- g_signal_connect (dialog->file_chooser, "selection-changed",
+ private);
+ g_signal_connect (private->file_chooser, "selection-changed",
G_CALLBACK (palette_import_filename_changed),
- dialog);
+ private);
- palette_import_grad_callback (dialog->gradient_radio, dialog);
+ palette_import_grad_callback (private->gradient_radio, private);
- return dialog->dialog;
+ return dialog;
}
/* private functions */
static void
-palette_import_free (ImportDialog *dialog)
+palette_import_free (ImportDialog *private)
{
- Gimp *gimp = dialog->context->gimp;
+ Gimp *gimp = private->context->gimp;
g_signal_handlers_disconnect_by_func (gimp->images,
palette_import_image_add,
- dialog);
+ private);
g_signal_handlers_disconnect_by_func (gimp->images,
palette_import_image_remove,
- dialog);
+ private);
- if (dialog->palette)
- g_object_unref (dialog->palette);
+ if (private->palette)
+ g_object_unref (private->palette);
- g_object_unref (dialog->context);
+ g_object_unref (private->context);
- g_slice_free (ImportDialog, dialog);
+ g_slice_free (ImportDialog, private);
}
/* the palette import response callback ************************************/
static void
-palette_import_response (GtkWidget *widget,
+palette_import_response (GtkWidget *dialog,
gint response_id,
- ImportDialog *dialog)
+ ImportDialog *private)
{
- Gimp *gimp = dialog->context->gimp;
+ palette_import_image_changed (private->context, NULL, private);
- palette_import_image_changed (dialog->context, NULL, dialog);
-
- if (dialog->palette)
+ if (response_id == GTK_RESPONSE_OK)
{
- if (response_id == GTK_RESPONSE_OK)
+ Gimp *gimp = private->context->gimp;
+
+ if (private->palette &&
+ gimp_palette_get_n_colors (private->palette) > 0)
{
- const gchar *name = gtk_entry_get_text (GTK_ENTRY (dialog->entry));
+ const gchar *name = gtk_entry_get_text (GTK_ENTRY (private->entry));
if (name && *name)
- gimp_object_set_name (GIMP_OBJECT (dialog->palette), name);
+ gimp_object_set_name (GIMP_OBJECT (private->palette), name);
gimp_container_add (gimp_data_factory_get_container (gimp->palette_factory),
- GIMP_OBJECT (dialog->palette));
+ GIMP_OBJECT (private->palette));
+ }
+ else
+ {
+ gimp_message_literal (gimp, G_OBJECT (dialog), GIMP_MESSAGE_ERROR,
+ _("There is no palette to import."));
+ return;
}
}
- gtk_widget_destroy (dialog->dialog);
+ gtk_widget_destroy (dialog);
}
@@ -471,35 +480,35 @@ palette_import_response (GtkWidget *widget,
static void
palette_import_gradient_changed (GimpContext *context,
GimpGradient *gradient,
- ImportDialog *dialog)
+ ImportDialog *private)
{
- if (gradient && dialog->import_type == GRADIENT_IMPORT)
+ if (gradient && private->import_type == GRADIENT_IMPORT)
{
- gtk_entry_set_text (GTK_ENTRY (dialog->entry),
+ gtk_entry_set_text (GTK_ENTRY (private->entry),
gimp_object_get_name (gradient));
- palette_import_make_palette (dialog);
+ palette_import_make_palette (private);
}
}
static void
palette_import_image_changed (GimpContext *context,
GimpImage *image,
- ImportDialog *dialog)
+ ImportDialog *private)
{
- if (dialog->image)
+ if (private->image)
{
- g_signal_handlers_disconnect_by_func (dialog->image,
+ g_signal_handlers_disconnect_by_func (private->image,
palette_import_layer_changed,
- dialog);
- g_signal_handlers_disconnect_by_func (dialog->image,
+ private);
+ g_signal_handlers_disconnect_by_func (private->image,
palette_import_mask_changed,
- dialog);
+ private);
}
- dialog->image = image;
+ private->image = image;
- if (dialog->import_type == IMAGE_IMPORT)
+ if (private->import_type == IMAGE_IMPORT)
{
gboolean sensitive = FALSE;
@@ -511,65 +520,65 @@ palette_import_image_changed (GimpContext *context,
gimp_image_get_display_name (image),
gimp_image_get_ID (image));
- gtk_entry_set_text (GTK_ENTRY (dialog->entry), label);
+ gtk_entry_set_text (GTK_ENTRY (private->entry), label);
g_free (label);
- palette_import_make_palette (dialog);
+ palette_import_make_palette (private);
if (gimp_image_get_base_type (image) != GIMP_INDEXED)
sensitive = TRUE;
}
- gtk_widget_set_sensitive (dialog->sample_merged_toggle, sensitive);
- gtk_widget_set_sensitive (dialog->selection_only_toggle, sensitive);
- gimp_scale_entry_set_sensitive (GTK_OBJECT (dialog->threshold),
+ gtk_widget_set_sensitive (private->sample_merged_toggle, sensitive);
+ gtk_widget_set_sensitive (private->selection_only_toggle, sensitive);
+ gimp_scale_entry_set_sensitive (GTK_OBJECT (private->threshold),
sensitive);
- gimp_scale_entry_set_sensitive (GTK_OBJECT (dialog->num_colors),
+ gimp_scale_entry_set_sensitive (GTK_OBJECT (private->num_colors),
sensitive);
}
- if (dialog->image)
+ if (private->image)
{
- g_signal_connect (dialog->image, "active-layer-changed",
+ g_signal_connect (private->image, "active-layer-changed",
G_CALLBACK (palette_import_layer_changed),
- dialog);
- g_signal_connect (dialog->image, "mask-changed",
+ private);
+ g_signal_connect (private->image, "mask-changed",
G_CALLBACK (palette_import_mask_changed),
- dialog);
+ private);
}
}
static void
palette_import_layer_changed (GimpImage *image,
- ImportDialog *dialog)
+ ImportDialog *private)
{
- if (dialog->import_type == IMAGE_IMPORT &&
+ if (private->import_type == IMAGE_IMPORT &&
! gtk_toggle_button_get_active
- (GTK_TOGGLE_BUTTON (dialog->sample_merged_toggle)))
+ (GTK_TOGGLE_BUTTON (private->sample_merged_toggle)))
{
- palette_import_make_palette (dialog);
+ palette_import_make_palette (private);
}
}
static void
palette_import_mask_changed (GimpImage *image,
- ImportDialog *dialog)
+ ImportDialog *private)
{
- if (dialog->import_type == IMAGE_IMPORT &&
+ if (private->import_type == IMAGE_IMPORT &&
gtk_toggle_button_get_active
- (GTK_TOGGLE_BUTTON (dialog->selection_only_toggle)))
+ (GTK_TOGGLE_BUTTON (private->selection_only_toggle)))
{
- palette_import_make_palette (dialog);
+ palette_import_make_palette (private);
}
}
static void
palette_import_filename_changed (GtkFileChooser *button,
- ImportDialog *dialog)
+ ImportDialog *private)
{
gchar *filename;
- if (dialog->import_type != FILE_IMPORT)
+ if (private->import_type != FILE_IMPORT)
return;
filename = gtk_file_chooser_get_filename (button);
@@ -579,17 +588,17 @@ palette_import_filename_changed (GtkFileChooser *button,
gchar *basename = g_filename_display_basename (filename);
/* TODO: strip filename extension */
- gtk_entry_set_text (GTK_ENTRY (dialog->entry), basename);
+ gtk_entry_set_text (GTK_ENTRY (private->entry), basename);
g_free (basename);
}
else
{
- gtk_entry_set_text (GTK_ENTRY (dialog->entry), "");
+ gtk_entry_set_text (GTK_ENTRY (private->entry), "");
}
g_free (filename);
- palette_import_make_palette (dialog);
+ palette_import_make_palette (private);
}
static void
@@ -599,22 +608,22 @@ import_dialog_drop_callback (GtkWidget *widget,
GimpViewable *viewable,
gpointer data)
{
- ImportDialog *dialog = data;
+ ImportDialog *private = data;
- gimp_context_set_by_type (dialog->context,
+ gimp_context_set_by_type (private->context,
G_TYPE_FROM_INSTANCE (viewable),
GIMP_OBJECT (viewable));
if (GIMP_IS_GRADIENT (viewable) &&
- dialog->import_type != GRADIENT_IMPORT)
+ private->import_type != GRADIENT_IMPORT)
{
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->gradient_radio),
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (private->gradient_radio),
TRUE);
}
else if (GIMP_IS_IMAGE (viewable) &&
- dialog->import_type != IMAGE_IMPORT)
+ private->import_type != IMAGE_IMPORT)
{
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->image_radio),
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (private->image_radio),
TRUE);
}
}
@@ -623,141 +632,142 @@ import_dialog_drop_callback (GtkWidget *widget,
/* the import source menu item callbacks ***********************************/
static void
-palette_import_set_sensitive (ImportDialog *dialog)
+palette_import_set_sensitive (ImportDialog *private)
{
- gboolean gradient = (dialog->import_type == GRADIENT_IMPORT);
- gboolean image = (dialog->import_type == IMAGE_IMPORT);
- gboolean file = (dialog->import_type == FILE_IMPORT);
-
- gtk_widget_set_sensitive (dialog->gradient_combo, gradient);
- gtk_widget_set_sensitive (dialog->image_combo, image);
- gtk_widget_set_sensitive (dialog->sample_merged_toggle, image);
- gtk_widget_set_sensitive (dialog->selection_only_toggle, image);
- gtk_widget_set_sensitive (dialog->file_chooser, file);
-
- gimp_scale_entry_set_sensitive (GTK_OBJECT (dialog->num_colors), ! file);
- gimp_scale_entry_set_sensitive (GTK_OBJECT (dialog->columns), ! file);
- gimp_scale_entry_set_sensitive (GTK_OBJECT (dialog->threshold), image);
+ gboolean gradient = (private->import_type == GRADIENT_IMPORT);
+ gboolean image = (private->import_type == IMAGE_IMPORT);
+ gboolean file = (private->import_type == FILE_IMPORT);
+
+ gtk_widget_set_sensitive (private->gradient_combo, gradient);
+ gtk_widget_set_sensitive (private->image_combo, image);
+ gtk_widget_set_sensitive (private->sample_merged_toggle, image);
+ gtk_widget_set_sensitive (private->selection_only_toggle, image);
+ gtk_widget_set_sensitive (private->file_chooser, file);
+
+ gimp_scale_entry_set_sensitive (GTK_OBJECT (private->num_colors), ! file);
+ gimp_scale_entry_set_sensitive (GTK_OBJECT (private->columns), ! file);
+ gimp_scale_entry_set_sensitive (GTK_OBJECT (private->threshold), image);
}
static void
palette_import_grad_callback (GtkWidget *widget,
- ImportDialog *dialog)
+ ImportDialog *private)
{
GimpGradient *gradient;
if (! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
return;
- dialog->import_type = GRADIENT_IMPORT;
+ private->import_type = GRADIENT_IMPORT;
- gradient = gimp_context_get_gradient (dialog->context);
+ gradient = gimp_context_get_gradient (private->context);
- gtk_entry_set_text (GTK_ENTRY (dialog->entry),
+ gtk_entry_set_text (GTK_ENTRY (private->entry),
gimp_object_get_name (gradient));
- palette_import_set_sensitive (dialog);
+ palette_import_set_sensitive (private);
- palette_import_make_palette (dialog);
+ palette_import_make_palette (private);
}
static void
palette_import_image_callback (GtkWidget *widget,
- ImportDialog *dialog)
+ ImportDialog *private)
{
GimpImage *image;
if (! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
return;
- dialog->import_type = IMAGE_IMPORT;
+ private->import_type = IMAGE_IMPORT;
- image = gimp_context_get_image (dialog->context);
+ image = gimp_context_get_image (private->context);
if (! image)
{
- GimpContainer *images = dialog->context->gimp->images;
+ GimpContainer *images = private->context->gimp->images;
image = GIMP_IMAGE (gimp_container_get_first_child (images));
}
- palette_import_set_sensitive (dialog);
+ palette_import_set_sensitive (private);
- palette_import_image_changed (dialog->context, image, dialog);
+ palette_import_image_changed (private->context, image, private);
}
static void
palette_import_file_callback (GtkWidget *widget,
- ImportDialog *dialog)
+ ImportDialog *private)
{
gchar *filename;
if (! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
return;
- dialog->import_type = FILE_IMPORT;
+ private->import_type = FILE_IMPORT;
filename =
- gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog->file_chooser));
+ gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (private->file_chooser));
if (filename)
{
gchar *basename = g_filename_display_basename (filename);
/* TODO: strip filename extension */
- gtk_entry_set_text (GTK_ENTRY (dialog->entry), basename);
+ gtk_entry_set_text (GTK_ENTRY (private->entry), basename);
g_free (basename);
g_free (filename);
}
else
{
- gtk_entry_set_text (GTK_ENTRY (dialog->entry), "");
+ gtk_entry_set_text (GTK_ENTRY (private->entry), "");
}
- palette_import_set_sensitive (dialog);
+ palette_import_set_sensitive (private);
}
static void
palette_import_columns_changed (GtkAdjustment *adj,
- ImportDialog *dialog)
+ ImportDialog *private)
{
- if (dialog->palette)
- gimp_palette_set_columns (dialog->palette,
+ if (private->palette)
+ gimp_palette_set_columns (private->palette,
ROUND (gtk_adjustment_get_value (adj)));
}
+
/* functions & callbacks to keep the import dialog uptodate ****************/
static void
palette_import_image_add (GimpContainer *container,
GimpImage *image,
- ImportDialog *dialog)
+ ImportDialog *private)
{
- if (! gtk_widget_is_sensitive (dialog->image_radio))
+ if (! gtk_widget_is_sensitive (private->image_radio))
{
- gtk_widget_set_sensitive (dialog->image_radio, TRUE);
- gimp_context_set_image (dialog->context, image);
+ gtk_widget_set_sensitive (private->image_radio, TRUE);
+ gimp_context_set_image (private->context, image);
}
}
static void
palette_import_image_remove (GimpContainer *container,
GimpImage *image,
- ImportDialog *dialog)
+ ImportDialog *private)
{
- if (! gimp_container_get_n_children (dialog->context->gimp->images))
+ if (! gimp_container_get_n_children (private->context->gimp->images))
{
- if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->image_radio)))
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->gradient_radio),
+ if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (private->image_radio)))
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (private->gradient_radio),
TRUE);
- gtk_widget_set_sensitive (dialog->image_radio, FALSE);
+ gtk_widget_set_sensitive (private->image_radio, FALSE);
}
}
static void
-palette_import_make_palette (ImportDialog *dialog)
+palette_import_make_palette (ImportDialog *private)
{
GimpPalette *palette = NULL;
const gchar *palette_name;
@@ -765,25 +775,25 @@ palette_import_make_palette (ImportDialog *dialog)
gint n_columns;
gint threshold;
- palette_name = gtk_entry_get_text (GTK_ENTRY (dialog->entry));
+ palette_name = gtk_entry_get_text (GTK_ENTRY (private->entry));
if (! palette_name || ! strlen (palette_name))
palette_name = _("Untitled");
- n_colors = ROUND (gtk_adjustment_get_value (dialog->num_colors));
- n_columns = ROUND (gtk_adjustment_get_value (dialog->columns));
- threshold = ROUND (gtk_adjustment_get_value (dialog->threshold));
+ n_colors = ROUND (gtk_adjustment_get_value (private->num_colors));
+ n_columns = ROUND (gtk_adjustment_get_value (private->columns));
+ threshold = ROUND (gtk_adjustment_get_value (private->threshold));
- switch (dialog->import_type)
+ switch (private->import_type)
{
case GRADIENT_IMPORT:
{
GimpGradient *gradient;
- gradient = gimp_context_get_gradient (dialog->context);
+ gradient = gimp_context_get_gradient (private->context);
palette = gimp_palette_import_from_gradient (gradient,
- dialog->context,
+ private->context,
FALSE,
palette_name,
n_colors);
@@ -792,28 +802,28 @@ palette_import_make_palette (ImportDialog *dialog)
case IMAGE_IMPORT:
{
- GimpImage *image = gimp_context_get_image (dialog->context);
+ GimpImage *image = gimp_context_get_image (private->context);
gboolean sample_merged;
gboolean selection_only;
sample_merged =
gtk_toggle_button_get_active
- (GTK_TOGGLE_BUTTON (dialog->sample_merged_toggle));
+ (GTK_TOGGLE_BUTTON (private->sample_merged_toggle));
selection_only =
gtk_toggle_button_get_active
- (GTK_TOGGLE_BUTTON (dialog->selection_only_toggle));
+ (GTK_TOGGLE_BUTTON (private->selection_only_toggle));
if (gimp_image_get_base_type (image) == GIMP_INDEXED)
{
palette = gimp_palette_import_from_indexed_image (image,
- dialog->context,
+ private->context,
palette_name);
}
else if (sample_merged)
{
palette = gimp_palette_import_from_image (image,
- dialog->context,
+ private->context,
palette_name,
n_colors,
threshold,
@@ -826,7 +836,7 @@ palette_import_make_palette (ImportDialog *dialog)
drawable = GIMP_DRAWABLE (gimp_image_get_active_layer (image));
palette = gimp_palette_import_from_drawable (drawable,
- dialog->context,
+ private->context,
palette_name,
n_colors,
threshold,
@@ -840,17 +850,17 @@ palette_import_make_palette (ImportDialog *dialog)
GFile *file;
GError *error = NULL;
- file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog->file_chooser));
+ file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (private->file_chooser));
- palette = gimp_palette_import_from_file (dialog->context,
+ palette = gimp_palette_import_from_file (private->context,
file,
palette_name, &error);
g_object_unref (file);
if (! palette)
{
- gimp_message_literal (dialog->context->gimp,
- G_OBJECT (dialog->dialog), GIMP_MESSAGE_ERROR,
+ gimp_message_literal (private->context->gimp,
+ G_OBJECT (private->dialog), GIMP_MESSAGE_ERROR,
error->message);
g_error_free (error);
}
@@ -858,20 +868,21 @@ palette_import_make_palette (ImportDialog *dialog)
break;
}
+ if (private->palette)
+ g_object_unref (private->palette);
+
+ private->palette = palette;
+
if (palette)
{
- if (dialog->palette)
- g_object_unref (dialog->palette);
-
gimp_palette_set_columns (palette, n_columns);
- gimp_view_set_viewable (GIMP_VIEW (dialog->preview),
+ gimp_view_set_viewable (GIMP_VIEW (private->preview),
GIMP_VIEWABLE (palette));
- dialog->palette = palette;
}
- gtk_widget_set_visible (dialog->no_colors_label,
- dialog->palette &&
- gimp_palette_get_n_colors (dialog->palette) > 0);
+ gtk_widget_set_visible (private->no_colors_label,
+ ! (palette &&
+ gimp_palette_get_n_colors (palette) > 0));
}
diff --git a/app/dialogs/palette-import-dialog.h b/app/dialogs/palette-import-dialog.h
index 17e5e66..264de1f 100644
--- a/app/dialogs/palette-import-dialog.h
+++ b/app/dialogs/palette-import-dialog.h
@@ -15,11 +15,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef __PALETTE_IMPORT_H__
-#define __PALETTE_IMPORT_H__
+#ifndef __PALETTE_IMPORT_DIALOG_H__
+#define __PALETTE_IMPORT_DIALOG_H__
GtkWidget * palette_import_dialog_new (GimpContext *context);
-#endif /* __PALETTE_IMPORT_H__ */
+#endif /* __PALETTE_IMPORT_DIALOG_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]