Commit 714771d4 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

app/widgets/gimpgradienteditor.[ch] added public APIs for zooming the

2004-10-24  Michael Natterer  <mitch@gimp.org>

	* app/widgets/gimpgradienteditor.[ch]
	* app/widgets/gimppaletteeditor.[ch]: added public APIs for
	zooming the editors. Use gimp_editor_add_action_button() to create
	all buttons. Removed all button callbacks and all duplicated
	button sensitivity logic.

	* app/widgets/gimpdataeditor.c (gimp_data_editor_set_data): update
	the editor's UI manager if it exists.

	* app/actions/gradient-editor-actions.c
	* app/actions/gradient-editor-commands.[ch]: added zoom actions
	and callback and call gimp_gradient_editor_zoom(). Fixed
	gradient_editor_actions_update() to actually set all items'
	sensitivity (it was possible to modify read-only gradients and
	even to crash GIMP).

	* app/actions/palette-editor-actions.c
	* app/actions/palette-editor-commands.[ch]: changed "new" and
	"zoom" actions to actually do their job instead of calling
	gtk_button_clicked(editor->foo_button).
parent e64a292d
2004-10-24 Michael Natterer <mitch@gimp.org>
* app/widgets/gimpgradienteditor.[ch]
* app/widgets/gimppaletteeditor.[ch]: added public APIs for
zooming the editors. Use gimp_editor_add_action_button() to create
all buttons. Removed all button callbacks and all duplicated
button sensitivity logic.
* app/widgets/gimpdataeditor.c (gimp_data_editor_set_data): update
the editor's UI manager if it exists.
* app/actions/gradient-editor-actions.c
* app/actions/gradient-editor-commands.[ch]: added zoom actions
and callback and call gimp_gradient_editor_zoom(). Fixed
gradient_editor_actions_update() to actually set all items'
sensitivity (it was possible to modify read-only gradients and
even to crash GIMP).
* app/actions/palette-editor-actions.c
* app/actions/palette-editor-commands.[ch]: changed "new" and
"zoom" actions to actually do their job instead of calling
gtk_button_clicked(editor->foo_button).
2004-10-24 Michael Natterer <mitch@gimp.org>
* app/widgets/gimpcolormapeditor.c: removed the "Edit Color"
......
......@@ -268,7 +268,7 @@ static GimpRadioActionEntry gradient_editor_blending_actions[] =
{ "gradient-editor-blending-varies", NULL,
N_("(Varies)"), NULL, NULL,
0,
-1,
GIMP_HELP_GRADIENT_EDITOR_BLENDING }
};
......@@ -291,10 +291,31 @@ static GimpRadioActionEntry gradient_editor_coloring_actions[] =
{ "gradient-editor-coloring-varies", NULL,
N_("(Varies)"), NULL, NULL,
0,
-1,
GIMP_HELP_GRADIENT_EDITOR_COLORING }
};
static GimpEnumActionEntry gradient_editor_zoom_actions[] =
{
{ "gradient-editor-zoom-in", GTK_STOCK_ZOOM_IN,
N_("Zoom In"), NULL,
N_("Zoom in"),
GIMP_ZOOM_IN,
GIMP_HELP_GRADIENT_EDITOR_ZOOM_IN },
{ "gradient-editor-zoom-out", GTK_STOCK_ZOOM_OUT,
N_("Zoom Out"), NULL,
N_("Zoom out"),
GIMP_ZOOM_OUT,
GIMP_HELP_GRADIENT_EDITOR_ZOOM_OUT },
{ "gradient-editor-zoom-all", GTK_STOCK_ZOOM_FIT,
N_("Zoom All"), NULL,
N_("Zoom all"),
GIMP_ZOOM_TO, /* abused */
GIMP_HELP_GRADIENT_EDITOR_ZOOM_ALL }
};
void
gradient_editor_actions_setup (GimpActionGroup *group)
......@@ -335,65 +356,78 @@ gradient_editor_actions_setup (GimpActionGroup *group)
G_N_ELEMENTS (gradient_editor_coloring_actions),
0,
G_CALLBACK (gradient_editor_coloring_type_cmd_callback));
gimp_action_group_add_enum_actions (group,
gradient_editor_zoom_actions,
G_N_ELEMENTS (gradient_editor_zoom_actions),
G_CALLBACK (gradient_editor_zoom_cmd_callback));
}
void
gradient_editor_actions_update (GimpActionGroup *group,
gpointer data)
{
GimpGradientEditor *editor = GIMP_GRADIENT_EDITOR (data);
GimpGradientEditor *editor = GIMP_GRADIENT_EDITOR (data);
GimpDataEditor *data_editor = GIMP_DATA_EDITOR (data);
GimpGradient *gradient;
GimpContext *context;
GimpGradientSegment *left_seg;
GimpGradientSegment *right_seg;
gboolean editable = FALSE;
GimpGradientSegment *left_seg = NULL;
GimpGradientSegment *right_seg = NULL;
GimpRGB fg;
GimpRGB bg;
gboolean blending_equal = TRUE;
gboolean coloring_equal = TRUE;
gboolean selection;
gboolean delete;
gboolean selection = FALSE;
gboolean delete = FALSE;
context =
gimp_get_user_context (GIMP_DATA_EDITOR (editor)->data_factory->gimp);
gradient = GIMP_GRADIENT (data_editor->data);
if (editor->control_sel_l->prev)
left_seg = editor->control_sel_l->prev;
else
left_seg = gimp_gradient_segment_get_last (editor->control_sel_l);
context = gimp_get_user_context (data_editor->data_factory->gimp);
if (editor->control_sel_r->next)
right_seg = editor->control_sel_r->next;
else
right_seg = gimp_gradient_segment_get_first (editor->control_sel_r);
if (context)
if (gradient)
{
gimp_context_get_foreground (context, &fg);
gimp_context_get_background (context, &bg);
}
GimpGradientSegmentType type;
GimpGradientSegmentColor color;
GimpGradientSegment *seg, *aseg;
if (data_editor->data_editable)
editable = TRUE;
if (editor->control_sel_l->prev)
left_seg = editor->control_sel_l->prev;
else
left_seg = gimp_gradient_segment_get_last (editor->control_sel_l);
{
GimpGradientSegmentType type;
GimpGradientSegmentColor color;
GimpGradientSegment *seg, *aseg;
if (editor->control_sel_r->next)
right_seg = editor->control_sel_r->next;
else
right_seg = gimp_gradient_segment_get_first (editor->control_sel_r);
type = editor->control_sel_l->type;
color = editor->control_sel_l->color;
type = editor->control_sel_l->type;
color = editor->control_sel_l->color;
seg = editor->control_sel_l;
seg = editor->control_sel_l;
do
{
blending_equal = blending_equal && (seg->type == type);
coloring_equal = coloring_equal && (seg->color == color);
do
{
blending_equal = blending_equal && (seg->type == type);
coloring_equal = coloring_equal && (seg->color == color);
aseg = seg;
seg = seg->next;
}
while (aseg != editor->control_sel_r);
}
aseg = seg;
seg = seg->next;
}
while (aseg != editor->control_sel_r);
selection = (editor->control_sel_l != editor->control_sel_r);
delete = (editor->control_sel_l->prev || editor->control_sel_r->next);
selection = (editor->control_sel_l != editor->control_sel_r);
delete = (editor->control_sel_l->prev || editor->control_sel_r->next);
}
if (context)
{
gimp_context_get_foreground (context, &fg);
gimp_context_get_background (context, &bg);
}
#define SET_ACTIVE(action,condition) \
gimp_action_group_set_action_active (group, action, (condition) != 0)
......@@ -406,16 +440,37 @@ gradient_editor_actions_update (GimpActionGroup *group,
#define SET_VISIBLE(action,condition) \
gimp_action_group_set_action_visible (group, action, (condition) != 0)
SET_COLOR ("gradient-editor-left-color",
&editor->control_sel_l->left_color, FALSE);
SET_COLOR ("gradient-editor-load-left-left-neighbor",
&left_seg->right_color, FALSE);
SET_COLOR ("gradient-editor-load-left-right-endpoint",
&editor->control_sel_r->right_color, FALSE);
SET_SENSITIVE ("gradient-editor-left-color", editable);
SET_SENSITIVE ("gradient-editor-load-left-left-neighbor", editable);
SET_SENSITIVE ("gradient-editor-load-left-right-endpoint", editable);
if (gradient)
{
SET_COLOR ("gradient-editor-left-color",
&editor->control_sel_l->left_color, FALSE);
SET_COLOR ("gradient-editor-load-left-left-neighbor",
&left_seg->right_color, FALSE);
SET_COLOR ("gradient-editor-load-left-right-endpoint",
&editor->control_sel_r->right_color, FALSE);
}
SET_SENSITIVE ("gradient-editor-load-left-fg", editable);
SET_SENSITIVE ("gradient-editor-load-left-bg", editable);
SET_COLOR ("gradient-editor-load-left-fg", context ? &fg : NULL, FALSE);
SET_COLOR ("gradient-editor-load-left-bg", context ? &bg : NULL, FALSE);
SET_SENSITIVE ("gradient-editor-load-left-01", editable);
SET_SENSITIVE ("gradient-editor-load-left-02", editable);
SET_SENSITIVE ("gradient-editor-load-left-03", editable);
SET_SENSITIVE ("gradient-editor-load-left-04", editable);
SET_SENSITIVE ("gradient-editor-load-left-05", editable);
SET_SENSITIVE ("gradient-editor-load-left-06", editable);
SET_SENSITIVE ("gradient-editor-load-left-07", editable);
SET_SENSITIVE ("gradient-editor-load-left-08", editable);
SET_SENSITIVE ("gradient-editor-load-left-09", editable);
SET_SENSITIVE ("gradient-editor-load-left-10", editable);
SET_COLOR ("gradient-editor-load-left-01", &editor->saved_colors[0], TRUE);
SET_COLOR ("gradient-editor-load-left-02", &editor->saved_colors[1], TRUE);
SET_COLOR ("gradient-editor-load-left-03", &editor->saved_colors[2], TRUE);
......@@ -427,6 +482,17 @@ gradient_editor_actions_update (GimpActionGroup *group,
SET_COLOR ("gradient-editor-load-left-09", &editor->saved_colors[8], TRUE);
SET_COLOR ("gradient-editor-load-left-10", &editor->saved_colors[9], TRUE);
SET_SENSITIVE ("gradient-editor-save-left-01", gradient);
SET_SENSITIVE ("gradient-editor-save-left-02", gradient);
SET_SENSITIVE ("gradient-editor-save-left-03", gradient);
SET_SENSITIVE ("gradient-editor-save-left-04", gradient);
SET_SENSITIVE ("gradient-editor-save-left-05", gradient);
SET_SENSITIVE ("gradient-editor-save-left-06", gradient);
SET_SENSITIVE ("gradient-editor-save-left-07", gradient);
SET_SENSITIVE ("gradient-editor-save-left-08", gradient);
SET_SENSITIVE ("gradient-editor-save-left-09", gradient);
SET_SENSITIVE ("gradient-editor-save-left-10", gradient);
SET_COLOR ("gradient-editor-save-left-01", &editor->saved_colors[0], TRUE);
SET_COLOR ("gradient-editor-save-left-02", &editor->saved_colors[1], TRUE);
SET_COLOR ("gradient-editor-save-left-03", &editor->saved_colors[2], TRUE);
......@@ -438,16 +504,37 @@ gradient_editor_actions_update (GimpActionGroup *group,
SET_COLOR ("gradient-editor-save-left-09", &editor->saved_colors[8], TRUE);
SET_COLOR ("gradient-editor-save-left-10", &editor->saved_colors[9], TRUE);
SET_COLOR ("gradient-editor-right-color",
&editor->control_sel_r->right_color, FALSE);
SET_COLOR ("gradient-editor-load-right-right-neighbor",
&right_seg->left_color, FALSE);
SET_COLOR ("gradient-editor-load-right-left-endpoint",
&editor->control_sel_l->left_color, FALSE);
SET_SENSITIVE ("gradient-editor-right-color", editable);
SET_SENSITIVE ("gradient-editor-load-right-right-neighbor", editable);
SET_SENSITIVE ("gradient-editor-load-right-left-endpoint", editable);
if (gradient)
{
SET_COLOR ("gradient-editor-right-color",
&editor->control_sel_r->right_color, FALSE);
SET_COLOR ("gradient-editor-load-right-right-neighbor",
&right_seg->left_color, FALSE);
SET_COLOR ("gradient-editor-load-right-left-endpoint",
&editor->control_sel_l->left_color, FALSE);
}
SET_SENSITIVE ("gradient-editor-load-right-fg", editable);
SET_SENSITIVE ("gradient-editor-load-right-bg", editable);
SET_COLOR ("gradient-editor-load-right-fg", context ? &fg : NULL, FALSE);
SET_COLOR ("gradient-editor-load-right-bg", context ? &bg : NULL, FALSE);
SET_SENSITIVE ("gradient-editor-load-right-01", editable);
SET_SENSITIVE ("gradient-editor-load-right-02", editable);
SET_SENSITIVE ("gradient-editor-load-right-03", editable);
SET_SENSITIVE ("gradient-editor-load-right-04", editable);
SET_SENSITIVE ("gradient-editor-load-right-05", editable);
SET_SENSITIVE ("gradient-editor-load-right-06", editable);
SET_SENSITIVE ("gradient-editor-load-right-07", editable);
SET_SENSITIVE ("gradient-editor-load-right-08", editable);
SET_SENSITIVE ("gradient-editor-load-right-09", editable);
SET_SENSITIVE ("gradient-editor-load-right-10", editable);
SET_COLOR ("gradient-editor-load-right-01", &editor->saved_colors[0], TRUE);
SET_COLOR ("gradient-editor-load-right-02", &editor->saved_colors[1], TRUE);
SET_COLOR ("gradient-editor-load-right-03", &editor->saved_colors[2], TRUE);
......@@ -459,6 +546,17 @@ gradient_editor_actions_update (GimpActionGroup *group,
SET_COLOR ("gradient-editor-load-right-09", &editor->saved_colors[8], TRUE);
SET_COLOR ("gradient-editor-load-right-10", &editor->saved_colors[9], TRUE);
SET_SENSITIVE ("gradient-editor-save-right-01", gradient);
SET_SENSITIVE ("gradient-editor-save-right-02", gradient);
SET_SENSITIVE ("gradient-editor-save-right-03", gradient);
SET_SENSITIVE ("gradient-editor-save-right-04", gradient);
SET_SENSITIVE ("gradient-editor-save-right-05", gradient);
SET_SENSITIVE ("gradient-editor-save-right-06", gradient);
SET_SENSITIVE ("gradient-editor-save-right-07", gradient);
SET_SENSITIVE ("gradient-editor-save-right-08", gradient);
SET_SENSITIVE ("gradient-editor-save-right-09", gradient);
SET_SENSITIVE ("gradient-editor-save-right-10", gradient);
SET_COLOR ("gradient-editor-save-right-01", &editor->saved_colors[0], TRUE);
SET_COLOR ("gradient-editor-save-right-02", &editor->saved_colors[1], TRUE);
SET_COLOR ("gradient-editor-save-right-03", &editor->saved_colors[2], TRUE);
......@@ -470,6 +568,14 @@ gradient_editor_actions_update (GimpActionGroup *group,
SET_COLOR ("gradient-editor-save-right-09", &editor->saved_colors[8], TRUE);
SET_COLOR ("gradient-editor-save-right-10", &editor->saved_colors[9], TRUE);
SET_SENSITIVE ("gradient-editor-flip", editable);
SET_SENSITIVE ("gradient-editor-replicate", editable);
SET_SENSITIVE ("gradient-editor-split-midpoint", editable);
SET_SENSITIVE ("gradient-editor-split-uniform", editable);
SET_SENSITIVE ("gradient-editor-delete", editable && delete);
SET_SENSITIVE ("gradient-editor-recenter", editable);
SET_SENSITIVE ("gradient-editor-redistribute", editable);
if (! selection)
{
SET_LABEL ("gradient-editor-blending-func",
......@@ -516,11 +622,15 @@ gradient_editor_actions_update (GimpActionGroup *group,
}
SET_SENSITIVE ("gradient-editor-blending-varies", FALSE);
SET_SENSITIVE ("gradient-editor-coloring-varies", FALSE);
SET_VISIBLE ("gradient-editor-blending-varies", ! blending_equal);
SET_VISIBLE ("gradient-editor-blending-varies", ! blending_equal);
SET_SENSITIVE ("gradient-editor-blending-linear", editable);
SET_SENSITIVE ("gradient-editor-blending-curved", editable);
SET_SENSITIVE ("gradient-editor-blending-sine", editable);
SET_SENSITIVE ("gradient-editor-blending-sphere-increasing", editable);
SET_SENSITIVE ("gradient-editor-blending-sphere-decreasing", editable);
if (blending_equal)
if (blending_equal && gradient)
{
switch (editor->control_sel_l->type)
{
......@@ -546,9 +656,14 @@ gradient_editor_actions_update (GimpActionGroup *group,
SET_ACTIVE ("gradient-editor-blending-varies", TRUE);
}
SET_VISIBLE ("gradient-editor-coloring-varies", ! coloring_equal);
SET_SENSITIVE ("gradient-editor-coloring-varies", FALSE);
SET_VISIBLE ("gradient-editor-coloring-varies", ! coloring_equal);
if (coloring_equal)
SET_SENSITIVE ("gradient-editor-coloring-rgb", editable);
SET_SENSITIVE ("gradient-editor-coloring-hsv-ccw", editable);
SET_SENSITIVE ("gradient-editor-coloring-hsv-cw", editable);
if (coloring_equal && gradient)
{
switch (editor->control_sel_l->color)
{
......@@ -568,9 +683,12 @@ gradient_editor_actions_update (GimpActionGroup *group,
SET_ACTIVE ("gradient-editor-coloring-varies", TRUE);
}
SET_SENSITIVE ("gradient-editor-blend-color", selection);
SET_SENSITIVE ("gradient-editor-blend-opacity", selection);
SET_SENSITIVE ("gradient-editor-delete", delete);
SET_SENSITIVE ("gradient-editor-blend-color", editable && selection);
SET_SENSITIVE ("gradient-editor-blend-opacity", editable && selection);
SET_SENSITIVE ("gradient-editor-zoom-out", gradient);
SET_SENSITIVE ("gradient-editor-zoom-in", gradient);
SET_SENSITIVE ("gradient-editor-zoom-all", gradient);
#undef SET_ACTIVE
#undef SET_COLOR
......
......@@ -276,19 +276,23 @@ gradient_editor_blending_func_cmd_callback (GtkAction *action,
GtkAction *current,
gpointer data)
{
GimpGradientEditor *editor = GIMP_GRADIENT_EDITOR (data);
GimpGradient *gradient;
GimpGradientSegmentType type;
GimpGradientEditor *editor = GIMP_GRADIENT_EDITOR (data);
GimpGradient *gradient;
gint value;
gradient = GIMP_GRADIENT (GIMP_DATA_EDITOR (editor)->data);
type = (GimpGradientSegmentType)
gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action));
value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action));
gimp_gradient_segment_range_set_blending_function (gradient,
editor->control_sel_l,
editor->control_sel_r,
type);
if (gradient && value >= 0)
{
GimpGradientSegmentType type = value;
gimp_gradient_segment_range_set_blending_function (gradient,
editor->control_sel_l,
editor->control_sel_r,
type);
}
}
void
......@@ -296,27 +300,31 @@ gradient_editor_coloring_type_cmd_callback (GtkAction *action,
GtkAction *current,
gpointer data)
{
GimpGradientEditor *editor = GIMP_GRADIENT_EDITOR (data);
GimpGradient *gradient;
GimpGradientSegmentColor color;
GimpGradientEditor *editor = GIMP_GRADIENT_EDITOR (data);
GimpGradient *gradient;
gint value;
gradient = GIMP_GRADIENT (GIMP_DATA_EDITOR (editor)->data);
color = (GimpGradientSegmentColor)
gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action));
value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action));
gimp_gradient_segment_range_set_coloring_type (gradient,
editor->control_sel_l,
editor->control_sel_r,
color);
if (gradient && value >= 0)
{
GimpGradientSegmentColor color = value;
gimp_gradient_segment_range_set_coloring_type (gradient,
editor->control_sel_l,
editor->control_sel_r,
color);
}
}
void
gradient_editor_flip_cmd_callback (GtkAction *action,
gpointer data)
{
GimpGradientEditor *editor = GIMP_GRADIENT_EDITOR (data);
GimpGradient *gradient;
GimpGradientEditor *editor = GIMP_GRADIENT_EDITOR (data);
GimpGradient *gradient;
gradient = GIMP_GRADIENT (GIMP_DATA_EDITOR (editor)->data);
......@@ -573,6 +581,16 @@ gradient_editor_blend_opacity_cmd_callback (GtkAction *action,
FALSE, TRUE);
}
void
gradient_editor_zoom_cmd_callback (GtkAction *action,
gint value,
gpointer data)
{
GimpGradientEditor *editor = GIMP_GRADIENT_EDITOR (data);
gimp_gradient_editor_zoom (editor, (GimpZoomType) value);
}
/* private functions */
......
......@@ -65,5 +65,9 @@ void gradient_editor_blend_color_cmd_callback (GtkAction *action,
void gradient_editor_blend_opacity_cmd_callback (GtkAction *action,
gpointer data);
void gradient_editor_zoom_cmd_callback (GtkAction *action,
gint value,
gpointer data);
#endif /* __GRADIENT_EDITOR_COMMANDS_H__ */
......@@ -44,38 +44,51 @@ static GimpActionEntry palette_editor_actions[] =
GIMP_HELP_PALETTE_EDITOR_DIALOG },
{ "palette-editor-edit-color", GIMP_STOCK_EDIT,
N_("_Edit Color..."), "", NULL,
N_("_Edit Color..."), "",
N_("Edit color"),
G_CALLBACK (palette_editor_edit_color_cmd_callback),
GIMP_HELP_PALETTE_EDITOR_EDIT },
{ "palette-editor-delete-color", GTK_STOCK_DELETE,
N_("_Delete Color"), "",
N_("Delete color"),
G_CALLBACK (palette_editor_delete_color_cmd_callback),
GIMP_HELP_PALETTE_EDITOR_DELETE }
};
static GimpEnumActionEntry palette_editor_new_actions[] =
{
{ "palette-editor-new-color-fg", GTK_STOCK_NEW,
N_("New Color from _FG"), "", NULL,
G_CALLBACK (palette_editor_new_color_fg_cmd_callback),
N_("New Color from _FG"), "",
N_("New color from FG"),
FALSE,
GIMP_HELP_PALETTE_EDITOR_NEW },
{ "palette-editor-new-color-bg", GTK_STOCK_NEW,
N_("New Color from _BG"), "", NULL,
G_CALLBACK (palette_editor_new_color_bg_cmd_callback),
GIMP_HELP_PALETTE_EDITOR_NEW },
N_("New Color from _BG"), "",
N_("New color from BG"),
TRUE,
GIMP_HELP_PALETTE_EDITOR_NEW }
};
{ "palette-editor-delete-color", GTK_STOCK_DELETE,
N_("_Delete Color"), "", NULL,
G_CALLBACK (palette_editor_delete_color_cmd_callback),
GIMP_HELP_PALETTE_EDITOR_DELETE },
static GimpEnumActionEntry palette_editor_zoom_actions[] =
{
{ "palette-editor-zoom-in", GTK_STOCK_ZOOM_IN,
N_("Zoom _In"), "",
N_("Zoom in"),
GIMP_ZOOM_IN,
GIMP_HELP_PALETTE_EDITOR_ZOOM_IN },
{ "palette-editor-zoom-out", GTK_STOCK_ZOOM_OUT,
N_("Zoom _Out"), "", NULL,
G_CALLBACK (palette_editor_zoom_out_cmd_callback),
N_("Zoom _Out"), "",
N_("Zoom out"),
GIMP_ZOOM_OUT,
GIMP_HELP_PALETTE_EDITOR_ZOOM_OUT },
{ "palette-editor-zoom-in", GTK_STOCK_ZOOM_IN,
N_("Zoom _In"), "", NULL,
G_CALLBACK (palette_editor_zoom_in_cmd_callback),
GIMP_HELP_PALETTE_EDITOR_ZOOM_IN },
{ "palette-editor-zoom-all", GTK_STOCK_ZOOM_FIT,
N_("Zoom _All"), "", NULL,
G_CALLBACK (palette_editor_zoom_all_cmd_callback),
N_("Zoom _All"), "",
N_("Zoom all"),
GIMP_ZOOM_TO, /* abused */
GIMP_HELP_PALETTE_EDITOR_ZOOM_ALL }
};
......@@ -86,6 +99,16 @@ palette_editor_actions_setup (GimpActionGroup *group)
gimp_action_group_add_actions (group,
palette_editor_actions,
G_N_ELEMENTS (palette_editor_actions));
gimp_action_group_add_enum_actions (group,
palette_editor_new_actions,
G_N_ELEMENTS (palette_editor_new_actions),
G_CALLBACK (palette_editor_new_color_cmd_callback));
gimp_action_group_add_enum_actions (group,
palette_editor_zoom_actions,
G_N_ELEMENTS (palette_editor_zoom_actions),
G_CALLBACK (palette_editor_zoom_cmd_callback));
}
void
......@@ -122,17 +145,18 @@ palette_editor_actions_update (GimpActionGroup *group,
gimp_action_group_set_action_color (group, action, color, FALSE);
SET_SENSITIVE ("palette-editor-edit-color", editable && editor->color);
SET_SENSITIVE ("palette-editor-delete-color", editable && editor->color);
SET_SENSITIVE ("palette-editor-new-color-fg", editable);
SET_SENSITIVE ("palette-editor-new-color-bg", editable);
SET_SENSITIVE ("palette-editor-delete-color", editable && editor->color);
SET_COLOR ("palette-editor-new-color-fg", context ? &fg : NULL);
SET_COLOR ("palette-editor-new-color-bg", context ? &bg : NULL);
SET_SENSITIVE ("palette-editor-zoom-out", data);
SET_SENSITIVE ("palette-editor-zoom-in", data);
SET_SENSITIVE ("palette-editor-zoom-all", data);
SET_COLOR ("palette-editor-new-color-fg", context ? &fg : NULL);
SET_COLOR ("palette-editor-new-color-bg", context ? &bg : NULL);
#undef SET_SENSITIVE
#undef SET_COLOR
}
......@@ -24,10 +24,27 @@
#include "actions-types.h"
#include "core/gimp.h"
#include "core/gimpcontext.h"
#include "core/gimpdatafactory.h"
#include "core/gimppalette.h"
#include "widgets/gimpcolordialog.h"
#include "widgets/gimpdialogfactory.h"
#include "widgets/gimppaletteeditor.h"
#include "palette-editor-commands.h"
#include "gimp-intl.h"
/* local function prototypes */
static void palette_editor_edit_color_update (GimpColorDialog *dialog,
const GimpRGB *color,
GimpColorDialogState state,
GimpPaletteEditor *editor);
/* public functions */
......@@ -35,69 +52,123 @@ void
palette_editor_edit_color_cmd_callback (GtkAction *action,
gpointer data)
{
GimpPaletteEditor *editor = GIMP_PALETTE_EDITOR (data);
if (GTK_WIDGET_SENSITIVE (editor->edit_button))
gtk_button_clicked (GTK_BUTTON (editor->edit_button));
GimpPaletteEditor *editor = GIMP_PALETTE_EDITOR (data);
GimpDataEditor *data_editor = GIMP_DATA_EDITOR (data);
GimpPalette *palette;
if (! (data_editor->data && data_editor->data_editable && editor->color))
return;
palette = GIMP_PALETTE (data_editor->data);
if (! editor->color_dialog)
{
editor->color_dialog =
gimp_color_dialog_new (GIMP_VIEWABLE (palette),
_("Edit Palette Color"),
GIMP_STOCK_PALETTE,
_("Edit Color Palette Entry"),
GTK_WIDGET (editor),
gimp_dialog_factory_from_name ("toplevel"),
"gimp-palette-editor-color-dialog",
(const GimpRGB *) &editor->color->color,
FALSE, FALSE);
g_signal_connect (editor->color_dialog, "destroy",
G_CALLBACK (gtk_widget_destroyed),
&editor->color_dialog);
g_signal_connect (editor->color_dialog, "update",
G_CALLBACK (palette_editor_edit_color_update),
editor);
}
else
{
gimp_viewable_dialog_set_viewable (GIMP_VIEWABLE_DIALOG (editor->color_dialog),
GIMP_VIEWABLE (palette));
gimp_color_dialog_set_color (GIMP_COLOR_DIALOG (editor->color_dialog),
&editor->color->color);
}
gtk_window_present (GTK_WINDOW (editor->color_dialog));
}
void
palette_editor_new_color_fg_cmd_callback (GtkAction *action,
gpointer data)
palette_editor_new_color_cmd_callback (GtkAction *action,
gint value,
gpointer data)
{
GimpPaletteEditor *editor = GIMP_PALETTE_EDITOR (data);
GimpPaletteEditor *editor = GIMP_PALETTE_EDITOR (data);
GimpDataEditor *data_editor = GIMP_DATA_EDITOR (data);
if (GTK_WIDGET_SENSITIVE (editor->new_button))
gimp_button_extended_clicked (GIMP_BUTTON (editor->new_button), 0);
}
if (data_editor->data && data_editor->data_editable)
{
GimpPalette *palette = GIMP_PALETTE (data_editor->data);
GimpContext *context;
GimpRGB color;
void
palette_editor_new_color_bg_cmd_callback (GtkAction *action,
gpointer data)
{
GimpPaletteEditor *editor = GIMP_PALETTE_EDITOR (data);
context = gimp_get_user_context (data_editor->data_factory->gimp);
if (value)
gimp_context_get_background (context, &color);
else
gimp_context_get_foreground (context, &color);
if (GTK_WIDGET_SENSITIVE (editor->new_button))
gimp_button_extended_clicked (GIMP_BUTTON (editor->new_button),
GDK_CONTROL_MASK);
editor->color = gimp_palette_add_entry (palette, NULL, &color);
}
}
void
palette_editor_delete_color_cmd_callback (GtkAction *action,
gpointer data)
{
GimpPaletteEditor *editor = GIMP_PALETTE_EDITOR (data);
GimpPaletteEditor *editor = GIMP_PALETTE_EDITOR (data);
GimpDataEditor *data_editor = GIMP_DATA_EDITOR (data);
if (data_editor->data && data_editor->data_editable && editor->color)
{
GimpPalette *palette = GIMP_PALETTE (data_editor->data);
if (GTK_WIDGET_SENSITIVE (editor->delete_button))
gtk_button_clicked (GTK_BUTTON (editor->delete_button));
gimp_palette_delete_entry (palette, editor->color);
}
}