Commit b9800e44 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

app/actions/channels-commands.c removed massive code duplication by

2004-09-20  Michael Natterer  <mitch@gimp.org>

	* app/actions/channels-commands.c
	* app/actions/vectors-commands.c: removed massive code duplication
	by factoring out the code that creates the "New Channel/Path" and
	"Edit Channel/Path Attributes" dialogs out to utility functions.
	GUI spacing and Code cleanup.

	* app/actions/layers-commands.c: minor GUI spacing and code
	cleanup.
parent 811ca2dc
2004-09-20 Michael Natterer <mitch@gimp.org>
* app/actions/channels-commands.c
* app/actions/vectors-commands.c: removed massive code duplication
by factoring out the code that creates the "New Channel/Path" and
"Edit Channel/Path Attributes" dialogs out to utility functions.
GUI spacing and Code cleanup.
* app/actions/layers-commands.c: minor GUI spacing and code
cleanup.
2004-09-19 Sven Neumann <sven@gimp.org>
* app/base/tile-manager.c (tile_manager_get_memsize): count valid
......
......@@ -45,12 +45,42 @@
#include "gimp-intl.h"
typedef struct _ChannelOptions ChannelOptions;
struct _ChannelOptions
{
GtkWidget *query_box;
GtkWidget *name_entry;
GtkWidget *color_panel;
GimpImage *gimage;
GimpContext *context;
GimpChannel *channel;
};
/* local function prototypes */
static void channels_opacity_update (GtkAdjustment *adjustment,
gpointer data);
static void channels_color_changed (GimpColorButton *button,
gpointer data);
static ChannelOptions * channels_query_new (GimpImage *gimage,
GimpContext *context,
GimpChannel *channel,
GtkWidget *parent);
static void channels_new_channel_response (GtkWidget *widget,
gint response_id,
ChannelOptions *options);
static void channels_edit_channel_response (GtkWidget *widget,
gint response_id,
ChannelOptions *options);
static void channels_opacity_update (GtkAdjustment *adjustment,
gpointer data);
static void channels_color_changed (GimpColorButton *button,
gpointer data);
/* private variables */
static gchar *channel_name = NULL;
static GimpRGB channel_color = { 0.0, 0.0, 0.0, 0.5 };
/* public functions */
......@@ -228,61 +258,6 @@ channels_to_selection_cmd_callback (GtkAction *action,
gimp_image_flush (gimage);
}
/**********************************/
/* The new channel query dialog */
/**********************************/
typedef struct _NewChannelOptions NewChannelOptions;
struct _NewChannelOptions
{
GtkWidget *query_box;
GtkWidget *name_entry;
GtkWidget *color_panel;
GimpContext *context;
GimpImage *gimage;
};
static gchar *channel_name = NULL;
static GimpRGB channel_color = { 0.0, 0.0, 0.0, 0.5 };
static void
new_channel_query_response (GtkWidget *widget,
gint response_id,
NewChannelOptions *options)
{
if (response_id == GTK_RESPONSE_OK)
{
GimpChannel *new_channel;
if (channel_name)
g_free (channel_name);
channel_name =
g_strdup (gtk_entry_get_text (GTK_ENTRY (options->name_entry)));
gimp_color_button_get_color (GIMP_COLOR_BUTTON (options->color_panel),
&channel_color);
new_channel = gimp_channel_new (options->gimage,
options->gimage->width,
options->gimage->height,
channel_name,
&channel_color);
gimp_drawable_fill_by_type (GIMP_DRAWABLE (new_channel),
options->context,
GIMP_TRANSPARENT_FILL);
gimp_image_add_channel (options->gimage, new_channel, -1);
gimp_image_flush (options->gimage);
}
gtk_widget_destroy (options->query_box);
}
void
channels_new_channel_query (GimpImage *gimage,
GimpContext *context,
......@@ -290,15 +265,11 @@ channels_new_channel_query (GimpImage *gimage,
gboolean interactive,
GtkWidget *parent)
{
NewChannelOptions *options;
GtkWidget *hbox;
GtkWidget *vbox;
GtkWidget *table;
GtkObject *opacity_scale_data;
ChannelOptions *options;
g_return_if_fail (GIMP_IS_IMAGE (gimage));
g_return_if_fail (GIMP_IS_CONTEXT (context));
g_return_if_fail (! template || GIMP_IS_CHANNEL (template));
g_return_if_fail (template == NULL || GIMP_IS_CHANNEL (template));
if (template || ! interactive)
{
......@@ -334,63 +305,134 @@ channels_new_channel_query (GimpImage *gimage,
return;
}
/* the new options structure */
options = g_new (NewChannelOptions, 1);
options->gimage = gimage;
options->context = context;
options->color_panel = gimp_color_panel_new (_("New Channel Color"),
options = channels_query_new (gimage, context, NULL, parent);
g_signal_connect (options->query_box, "response",
G_CALLBACK (channels_new_channel_response),
options);
gtk_widget_show (options->query_box);
}
void
channels_edit_channel_query (GimpChannel *channel,
GimpContext *context,
GtkWidget *parent)
{
ChannelOptions *options;
g_return_if_fail (GIMP_IS_CHANNEL (channel));
g_return_if_fail (GIMP_IS_CONTEXT (context));
options = channels_query_new (gimp_item_get_image (GIMP_ITEM (channel)),
context, channel, parent);
g_signal_connect (options->query_box, "response",
G_CALLBACK (channels_edit_channel_response),
options);
gtk_widget_show (options->query_box);
}
/* private functions */
static ChannelOptions *
channels_query_new (GimpImage *gimage,
GimpContext *context,
GimpChannel *channel,
GtkWidget *parent)
{
ChannelOptions *options;
GtkWidget *hbox;
GtkWidget *vbox;
GtkWidget *table;
GtkObject *opacity_scale_data;
options = g_new0 (ChannelOptions, 1);
options->gimage = gimage;
options->context = context;
options->channel = channel;
if (channel)
channel_color = channel->color;
options->color_panel = gimp_color_panel_new (channel ?
_("Edit Channel Color") :
_("New Channel Color"),
&channel_color,
GIMP_COLOR_AREA_LARGE_CHECKS,
48, 64);
gimp_color_panel_set_context (GIMP_COLOR_PANEL (options->color_panel),
context);
options->query_box =
gimp_viewable_dialog_new (GIMP_VIEWABLE (gimage),
_("New Channel"), "gimp-channel-new",
GIMP_STOCK_CHANNEL,
_("New Channel Options"),
parent,
gimp_standard_help_func,
GIMP_HELP_CHANNEL_NEW,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OK, GTK_RESPONSE_OK,
NULL);
if (channel)
{
options->query_box =
gimp_viewable_dialog_new (GIMP_VIEWABLE (channel),
_("Channel Attributes"), "gimp-channel-edit",
GIMP_STOCK_EDIT,
_("Edit Channel Attributes"),
parent,
gimp_standard_help_func,
GIMP_HELP_CHANNEL_EDIT,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OK, GTK_RESPONSE_OK,
NULL);
}
else
{
options->query_box =
gimp_viewable_dialog_new (GIMP_VIEWABLE (gimage),
_("New Channel"), "gimp-channel-new",
GIMP_STOCK_CHANNEL,
_("New Channel Options"),
parent,
gimp_standard_help_func,
GIMP_HELP_CHANNEL_NEW,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OK, GTK_RESPONSE_OK,
NULL);
}
g_object_weak_ref (G_OBJECT (options->query_box),
(GWeakNotify) g_free,
options);
g_signal_connect (options->query_box, "response",
G_CALLBACK (new_channel_query_response),
options);
hbox = gtk_hbox_new (FALSE, 6);
hbox = gtk_hbox_new (FALSE, 12);
gtk_container_set_border_width (GTK_CONTAINER (hbox), 12);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (options->query_box)->vbox),
hbox);
gtk_widget_show (hbox);
vbox = gtk_vbox_new (FALSE, 2);
vbox = gtk_vbox_new (FALSE, 6);
gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
gtk_widget_show (vbox);
table = gtk_table_new (2, 3, FALSE);
gtk_table_set_col_spacings (GTK_TABLE (table), 2);
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
gtk_table_set_col_spacings (GTK_TABLE (table), 6);
gtk_table_set_row_spacings (GTK_TABLE (table), 6);
gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
gtk_widget_show (table);
options->name_entry = gtk_entry_new ();
gtk_entry_set_activates_default (GTK_ENTRY (options->name_entry), TRUE);
gtk_entry_set_text (GTK_ENTRY (options->name_entry),
(channel_name ? channel_name : _("New Channel")));
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
_("Channel Name:"), 0.0, 0.5,
options->name_entry, 2, FALSE);
if (channel)
gtk_entry_set_text (GTK_ENTRY (options->name_entry),
gimp_object_get_name (GIMP_OBJECT (channel)));
else
gtk_entry_set_text (GTK_ENTRY (options->name_entry),
channel_name ? channel_name : _("New Channel"));
opacity_scale_data = gimp_scale_entry_new (GTK_TABLE (table), 0, 1,
_("Fill Opacity:"), 100, -1,
channel_color.a * 100.0,
......@@ -410,29 +452,47 @@ channels_new_channel_query (GimpImage *gimage,
G_CALLBACK (channels_color_changed),
opacity_scale_data);
gtk_widget_show (options->query_box);
return options;
}
/****************************************/
/* The edit channel attributes dialog */
/****************************************/
static void
channels_new_channel_response (GtkWidget *widget,
gint response_id,
ChannelOptions *options)
{
if (response_id == GTK_RESPONSE_OK)
{
GimpChannel *new_channel;
typedef struct _EditChannelOptions EditChannelOptions;
if (channel_name)
g_free (channel_name);
channel_name =
g_strdup (gtk_entry_get_text (GTK_ENTRY (options->name_entry)));
struct _EditChannelOptions
{
GtkWidget *query_box;
GtkWidget *name_entry;
GtkWidget *color_panel;
gimp_color_button_get_color (GIMP_COLOR_BUTTON (options->color_panel),
&channel_color);
GimpChannel *channel;
GimpImage *gimage;
};
new_channel = gimp_channel_new (options->gimage,
options->gimage->width,
options->gimage->height,
channel_name,
&channel_color);
gimp_drawable_fill_by_type (GIMP_DRAWABLE (new_channel),
options->context,
GIMP_TRANSPARENT_FILL);
gimp_image_add_channel (options->gimage, new_channel, -1);
gimp_image_flush (options->gimage);
}
gtk_widget_destroy (options->query_box);
}
static void
edit_channel_query_response (GtkWidget *widget,
gint response_id,
EditChannelOptions *options)
channels_edit_channel_response (GtkWidget *widget,
gint response_id,
ChannelOptions *options)
{
if (response_id == GTK_RESPONSE_OK)
{
......@@ -474,106 +534,6 @@ edit_channel_query_response (GtkWidget *widget,
gtk_widget_destroy (options->query_box);
}
void
channels_edit_channel_query (GimpChannel *channel,
GimpContext *context,
GtkWidget *parent)
{
EditChannelOptions *options;
GtkWidget *hbox;
GtkWidget *vbox;
GtkWidget *table;
GtkObject *opacity_scale_data;
g_return_if_fail (GIMP_IS_CHANNEL (channel));
g_return_if_fail (GIMP_IS_CONTEXT (context));
options = g_new0 (EditChannelOptions, 1);
options->channel = channel;
options->gimage = gimp_item_get_image (GIMP_ITEM (channel));
channel_color = channel->color;
options->color_panel = gimp_color_panel_new (_("Edit Channel Color"),
&channel_color,
GIMP_COLOR_AREA_LARGE_CHECKS,
48, 64);
gimp_color_panel_set_context (GIMP_COLOR_PANEL (options->color_panel),
context);
/* The dialog */
options->query_box =
gimp_viewable_dialog_new (GIMP_VIEWABLE (channel),
_("Channel Attributes"), "gimp-channel-edit",
GIMP_STOCK_EDIT,
_("Edit Channel Attributes"),
parent,
gimp_standard_help_func,
GIMP_HELP_CHANNEL_EDIT,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OK, GTK_RESPONSE_OK,
NULL);
g_object_weak_ref (G_OBJECT (options->query_box),
(GWeakNotify) g_free,
options);
g_signal_connect (options->query_box, "response",
G_CALLBACK (edit_channel_query_response),
options);
hbox = gtk_hbox_new (FALSE, 6);
gtk_container_set_border_width (GTK_CONTAINER (hbox), 12);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (options->query_box)->vbox),
hbox);
gtk_widget_show (hbox);
vbox = gtk_vbox_new (FALSE, 2);
gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
gtk_widget_show (vbox);
table = gtk_table_new (2, 3, FALSE);
gtk_table_set_col_spacings (GTK_TABLE (table), 2);
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
gtk_widget_show (table);
options->name_entry = gtk_entry_new ();
gtk_entry_set_activates_default (GTK_ENTRY (options->name_entry), TRUE);
gtk_entry_set_text (GTK_ENTRY (options->name_entry),
gimp_object_get_name (GIMP_OBJECT (channel)));
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
_("Channel Name:"), 0.0, 0.5,
options->name_entry, 2, FALSE);
opacity_scale_data = gimp_scale_entry_new (GTK_TABLE (table), 0, 1,
_("Fill Opacity:"), 100, -1,
channel_color.a * 100.0,
0.0, 100.0, 1.0, 10.0, 1,
TRUE, 0.0, 0.0,
NULL, NULL);
g_signal_connect (opacity_scale_data, "value_changed",
G_CALLBACK (channels_opacity_update),
options->color_panel);
gtk_box_pack_start (GTK_BOX (hbox), options->color_panel,
TRUE, TRUE, 0);
gtk_widget_show (options->color_panel);
g_signal_connect (options->color_panel, "color_changed",
G_CALLBACK (channels_color_changed),
opacity_scale_data);
gtk_widget_show (options->query_box);
}
/* private functions */
static void
channels_opacity_update (GtkAdjustment *adjustment,
gpointer data)
......
......@@ -111,6 +111,12 @@ static void layers_resize_layer_query (GimpDisplay *gdisp,
static gint layers_mode_index (GimpLayerModeEffects layer_mode);
/* private variables */
static GimpFillType fill_type = GIMP_TRANSPARENT_FILL;
static gchar *layer_name = NULL;
/* public functions */
void
......@@ -676,8 +682,6 @@ struct _NewLayerOptions
GimpImage *gimage;
};
static GimpFillType fill_type = GIMP_TRANSPARENT_FILL;
static gchar *layer_name = NULL;
static void
new_layer_query_response (GtkWidget *widget,
......@@ -837,8 +841,8 @@ layers_new_layer_query (GimpImage *gimage,
gtk_widget_show (vbox);
table = gtk_table_new (3, 2, FALSE);
gtk_table_set_col_spacing (GTK_TABLE (table), 0, 4);
gtk_table_set_row_spacing (GTK_TABLE (table), 0, 4);
gtk_table_set_col_spacing (GTK_TABLE (table), 0, 6);
gtk_table_set_row_spacing (GTK_TABLE (table), 0, 6);
gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
gtk_widget_show (table);
......@@ -1042,8 +1046,8 @@ layers_edit_layer_query (GimpLayer *layer,
gtk_widget_show (vbox);
table = gtk_table_new (1, 2, FALSE);
gtk_table_set_col_spacing (GTK_TABLE (table), 0, 4);
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
gtk_table_set_col_spacings (GTK_TABLE (table), 6);
gtk_table_set_row_spacings (GTK_TABLE (table), 6);
gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
gtk_widget_show (table);
......@@ -1213,12 +1217,10 @@ scale_layer_query_ok_callback (GtkWidget *widget,
gpointer data)
{
ScaleLayerOptions *options = data;
GimpLayer *layer;
if (options->dialog->width > 0 && options->dialog->height > 0 &&
(layer = (options->layer)))
if (options->dialog->width > 0 && options->dialog->height > 0)
{
GimpImage *gimage = gimp_item_get_image (GIMP_ITEM (layer));
GimpImage *gimage = gimp_item_get_image (GIMP_ITEM (options->layer));
GimpProgress *progress;
gtk_widget_set_sensitive (options->dialog->shell, FALSE);
......@@ -1226,7 +1228,7 @@ scale_layer_query_ok_callback (GtkWidget *widget,
progress = gimp_progress_start (GIMP_PROGRESS (options->gdisp),
_("Scaling..."), FALSE);
gimp_item_scale_by_origin (GIMP_ITEM (layer),
gimp_item_scale_by_origin (GIMP_ITEM (options->layer),
options->dialog->width,
options->dialog->height,
options->dialog->interpolation,
......@@ -1298,16 +1300,14 @@ resize_layer_query_ok_callback (GtkWidget *widget,
gpointer data)
{
ResizeLayerOptions *options = data;
GimpLayer *layer;
if (options->dialog->width > 0 && options->dialog->height > 0 &&
(layer = (options->layer)))
if (options->dialog->width > 0 && options->dialog->height > 0)
{
GimpImage *gimage = gimp_item_get_image (GIMP_ITEM (layer));
GimpImage *gimage = gimp_item_get_image (GIMP_ITEM (options->layer));
gtk_widget_set_sensitive (options->dialog->shell, FALSE);
gimp_item_resize (GIMP_ITEM (layer),
gimp_item_resize (GIMP_ITEM (options->layer),
options->context,
options->dialog->width,
options->dialog->height,
......
......@@ -64,13 +64,46 @@
#include "gimp-intl.h"
typedef struct _VectorsOptions VectorsOptions;
struct _VectorsOptions
{
GtkWidget *query_box;
GtkWidget *name_entry;
GimpImage *gimage;
GimpVectors *vectors;
};
/* local function prototypes */
static void vectors_import_query (GimpImage *gimage,
GtkWidget *parent);
static void vectors_export_query (GimpImage *gimage,
GimpVectors *vectors,
GtkWidget *parent);
static VectorsOptions * vectors_query_new (GimpImage *gimage,
GimpContext *context,
GimpVectors *vectors,
GtkWidget *parent);
static void vectors_new_vectors_response (GtkWidget *widget,
gint response_id,
VectorsOptions *options);
static void vectors_edit_vectors_response (GtkWidget *widget,
gint response_id,
VectorsOptions *options);
static void vectors_import_query (GimpImage *gimage,
GtkWidget *parent);
static void vectors_import_response (GtkWidget *dialog,
gint response_id,
GimpImage *gimage);
static void vectors_export_query (GimpImage *gimage,
GimpVectors *vectors,
GtkWidget *parent);
static void vectors_export_response (GtkWidget *dialog,
gint response_id,
GimpImage *gimage);
/* private variables */
static gchar *vectors_name = NULL;
/* public functions */
......@@ -434,47 +467,6 @@ vectors_vectors_tool (GimpVectors *vectors,
gimp_vector_tool_set_vectors (GIMP_VECTOR_TOOL (active_tool), vectors);
}