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

Ported the layers, channels and paths dialogs from

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

	Ported the layers, channels and paths dialogs from
	gimp_editor_add_button() to gimp_editor_add_action_button(),
	removing a massive amount of duplicated code, sensitivity logic
	and confusing utility functions.

	* app/actions/channels-actions.c
	* app/actions/channels-commands.[ch]
	* app/actions/layers-actions.c
	* app/actions/layers-commands.[ch]
	* app/actions/vectors-actions.c
	* app/actions/vectors-commands.[ch]: added "foo-new-default"
	actions and callbacks which create items without a dialog,
	optionally using default values from a passed template. Removed
	all public utility function that were passed as function pointers
	to widget construtors. Added tooltips to all actions which are now
	used for dialog buttons.

	* app/widgets/gimpeditor.c (gimp_editor_add_action_button):
	automatically create multi-line tooltips showing the modifiers for
	extended action buttons. Removes the need for lots of insane
	format strings that need to be translated correctly.

	* app/widgets/gimpitemtreeview.[ch] (struct GimpItemTreeViewClass):
	replaced tooltip and help_id strings by action names.

	(struct GimpItemTreeView)
	(gimp_item_tree_view_new): removed "edit", "new" and "activate"
	function pointers.

	(gimp_item_tree_view_constructor): create all buttons
	with gimp_editor_add_action_button(), using the action names
	from GimpItemTreeViewClass.

	Removed tons of "clicked" callbacks and all code which sets the
	buttons' sensitivity. They are not needed any longer.

	Require all subclasses to implement GimpItemTreeView::new_item(),
	a new virtual function which creates a plain new item without
	showing a dialog.

	* app/widgets/gimpdrawabletreeview.c
	* app/widgets/gimpchanneltreeview.c
	* app/widgets/gimplayertreeview.c
	* app/widgets/gimpvectorstreeview.c: fill in the action names and
	implement GimpItemTreeView::new_item(). Removed all button
	sensitivity logic.

	* app/dialogs/dialogs-constructors.c: changed accordingly. Doesn't
	include anything from actions/ any more.
parent 0e15d4f6
2004-10-16 Michael Natterer <mitch@gimp.org>
Ported the layers, channels and paths dialogs from
gimp_editor_add_button() to gimp_editor_add_action_button(),
removing a massive amount of duplicated code, sensitivity logic
and confusing utility functions.
* app/actions/channels-actions.c
* app/actions/channels-commands.[ch]
* app/actions/layers-actions.c
* app/actions/layers-commands.[ch]
* app/actions/vectors-actions.c
* app/actions/vectors-commands.[ch]: added "foo-new-default"
actions and callbacks which create items without a dialog,
optionally using default values from a passed template. Removed
all public utility function that were passed as function pointers
to widget construtors. Added tooltips to all actions which are now
used for dialog buttons.
* app/widgets/gimpeditor.c (gimp_editor_add_action_button):
automatically create multi-line tooltips showing the modifiers for
extended action buttons. Removes the need for lots of insane
format strings that need to be translated correctly.
* app/widgets/gimpitemtreeview.[ch] (struct GimpItemTreeViewClass):
replaced tooltip and help_id strings by action names.
(struct GimpItemTreeView)
(gimp_item_tree_view_new): removed "edit", "new" and "activate"
function pointers.
(gimp_item_tree_view_constructor): create all buttons
with gimp_editor_add_action_button(), using the action names
from GimpItemTreeViewClass.
Removed tons of "clicked" callbacks and all code which sets the
buttons' sensitivity. They are not needed any longer.
Require all subclasses to implement GimpItemTreeView::new_item(),
a new virtual function which creates a plain new item without
showing a dialog.
* app/widgets/gimpdrawabletreeview.c
* app/widgets/gimpchanneltreeview.c
* app/widgets/gimplayertreeview.c
* app/widgets/gimpvectorstreeview.c: fill in the action names and
implement GimpItemTreeView::new_item(). Removed all button
sensitivity logic.
* app/dialogs/dialogs-constructors.c: changed accordingly. Doesn't
include anything from actions/ any more.
2004-10-15 Michael Natterer <mitch@gimp.org>
* tools/pdbgen/pdb/layer.pdb: fixed parameter descriptions for
......
......@@ -44,42 +44,56 @@ static GimpActionEntry channels_actions[] =
GIMP_HELP_CHANNEL_DIALOG },
{ "channels-edit-attributes", GIMP_STOCK_EDIT,
N_("_Edit Channel Attributes..."), NULL, NULL,
N_("_Edit Channel Attributes..."), NULL,
N_("Edit channel attributes"),
G_CALLBACK (channels_edit_attributes_cmd_callback),
GIMP_HELP_CHANNEL_EDIT },
{ "channels-new", GTK_STOCK_NEW,
N_("_New Channel..."), "", NULL,
N_("_New Channel..."), "",
N_("New channel dialog"),
G_CALLBACK (channels_new_cmd_callback),
GIMP_HELP_CHANNEL_NEW },
{ "channels-new-default", GTK_STOCK_NEW,
N_("_New Channel"), "",
N_("New channel"),
G_CALLBACK (channels_new_default_cmd_callback),
GIMP_HELP_CHANNEL_NEW },
{ "channels-duplicate", GIMP_STOCK_DUPLICATE,
N_("D_uplicate Channel"), NULL, NULL,
N_("D_uplicate Channel"), NULL,
N_("Duplicate channel"),
G_CALLBACK (channels_duplicate_cmd_callback),
GIMP_HELP_CHANNEL_DUPLICATE },
{ "channels-delete", GTK_STOCK_DELETE,
N_("_Delete Channel"), "", NULL,
N_("_Delete Channel"), "",
N_("Delete channel"),
G_CALLBACK (channels_delete_cmd_callback),
GIMP_HELP_CHANNEL_DELETE },
{ "channels-raise", GTK_STOCK_GO_UP,
N_("_Raise Channel"), "", NULL,
N_("_Raise Channel"), "",
N_("Raise channel"),
G_CALLBACK (channels_raise_cmd_callback),
GIMP_HELP_CHANNEL_RAISE },
{ "channels-raise-to-top", GTK_STOCK_GOTO_TOP,
N_("Raise Channel to _Top"), "", NULL,
N_("Raise Channel to _Top"), "",
N_("Raise channel to top"),
G_CALLBACK (channels_raise_to_top_cmd_callback),
GIMP_HELP_CHANNEL_RAISE_TO_TOP },
{ "channels-lower", GTK_STOCK_GO_DOWN,
N_("_Lower Channel"), "", NULL,
N_("_Lower Channel"), "",
N_("Lower channel"),
G_CALLBACK (channels_lower_cmd_callback),
GIMP_HELP_CHANNEL_LOWER },
{ "channels-lower-to-bottom", GTK_STOCK_GOTO_BOTTOM,
N_("Lower Channel to _Bottom"), "", NULL,
N_("Lower Channel to _Bottom"), "",
N_("Lower channel to bottom"),
G_CALLBACK (channels_lower_to_bottom_cmd_callback),
GIMP_HELP_CHANNEL_LOWER_TO_BOTTOM }
};
......@@ -169,6 +183,7 @@ channels_actions_update (GimpActionGroup *group,
SET_SENSITIVE ("channels-edit-attributes", !fs && channel);
SET_SENSITIVE ("channels-new", !fs && gimage);
SET_SENSITIVE ("channels-new-default", !fs && gimage);
SET_SENSITIVE ("channels-duplicate", !fs && (channel || component));
SET_SENSITIVE ("channels-delete", !fs && channel);
......
......@@ -33,6 +33,7 @@
#include "core/gimpimage.h"
#include "core/gimpimage-undo.h"
#include "widgets/gimpaction.h"
#include "widgets/gimpcolorpanel.h"
#include "widgets/gimpcomponenteditor.h"
#include "widgets/gimpdock.h"
......@@ -65,9 +66,15 @@ static ChannelOptions * channels_query_new (GimpImage *gimage,
GimpContext *context,
GimpChannel *channel,
GtkWidget *parent);
static void channels_new_channel_query (GimpImage *gimage,
GimpContext *context,
GtkWidget *parent);
static void channels_new_channel_response (GtkWidget *widget,
gint response_id,
ChannelOptions *options);
static void channels_edit_channel_query (GimpChannel *channel,
GimpContext *context,
GtkWidget *parent);
static void channels_edit_channel_response (GtkWidget *widget,
gint response_id,
ChannelOptions *options);
......@@ -108,8 +115,49 @@ channels_new_cmd_callback (GtkAction *action,
return_if_no_image (gimage, data);
return_if_no_widget (widget, data);
channels_new_channel_query (gimage, action_data_get_context (data),
NULL, TRUE, widget);
channels_new_channel_query (gimage, action_data_get_context (data), widget);
}
void
channels_new_default_cmd_callback (GtkAction *action,
gpointer data)
{
GimpImage *gimage;
GimpChannel *new_channel;
gint width, height;
GimpRGB color;
return_if_no_image (gimage, data);
if (GIMP_IS_CHANNEL (GIMP_ACTION (action)->viewable))
{
GimpChannel *template = GIMP_CHANNEL (GIMP_ACTION (action)->viewable);
width = gimp_item_width (GIMP_ITEM (template));
height = gimp_item_height (GIMP_ITEM (template));
color = template->color;
}
else
{
width = gimp_image_get_width (gimage);
height = gimp_image_get_height (gimage);
gimp_rgba_set (&color, 0.0, 0.0, 0.0, 0.5);
}
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_EDIT_PASTE,
_("New Channel"));
new_channel = gimp_channel_new (gimage, width, height,
_("Empty Channel"), &color);
gimp_drawable_fill_by_type (GIMP_DRAWABLE (new_channel),
action_data_get_context (data),
GIMP_TRANSPARENT_FILL);
gimp_image_add_channel (gimage, new_channel, -1);
gimp_image_undo_group_end (gimage);
gimp_image_flush (gimage);
}
void
......@@ -258,82 +306,6 @@ channels_to_selection_cmd_callback (GtkAction *action,
gimp_image_flush (gimage);
}
void
channels_new_channel_query (GimpImage *gimage,
GimpContext *context,
GimpChannel *template,
gboolean interactive,
GtkWidget *parent)
{
ChannelOptions *options;
g_return_if_fail (GIMP_IS_IMAGE (gimage));
g_return_if_fail (GIMP_IS_CONTEXT (context));
g_return_if_fail (template == NULL || GIMP_IS_CHANNEL (template));
if (template || ! interactive)
{
GimpChannel *new_channel;
gint width, height;
GimpRGB color;
if (template)
{
width = gimp_item_width (GIMP_ITEM (template));
height = gimp_item_height (GIMP_ITEM (template));
color = template->color;
}
else
{
width = gimp_image_get_width (gimage);
height = gimp_image_get_height (gimage);
gimp_rgba_set (&color, 0.0, 0.0, 0.0, 0.5);
}
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_EDIT_PASTE,
_("New Channel"));
new_channel = gimp_channel_new (gimage, width, height,
_("Empty Channel"), &color);
gimp_drawable_fill_by_type (GIMP_DRAWABLE (new_channel), context,
GIMP_TRANSPARENT_FILL);
gimp_image_add_channel (gimage, new_channel, -1);
gimp_image_undo_group_end (gimage);
return;
}
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 */
......@@ -455,6 +427,22 @@ channels_query_new (GimpImage *gimage,
return options;
}
static void
channels_new_channel_query (GimpImage *gimage,
GimpContext *context,
GtkWidget *parent)
{
ChannelOptions *options;
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);
}
static void
channels_new_channel_response (GtkWidget *widget,
gint response_id,
......@@ -489,6 +477,26 @@ channels_new_channel_response (GtkWidget *widget,
gtk_widget_destroy (options->query_box);
}
static 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);
}
static void
channels_edit_channel_response (GtkWidget *widget,
gint response_id,
......
......@@ -24,6 +24,8 @@ void channels_edit_attributes_cmd_callback (GtkAction *action,
gpointer data);
void channels_new_cmd_callback (GtkAction *action,
gpointer data);
void channels_new_default_cmd_callback (GtkAction *action,
gpointer data);
void channels_raise_cmd_callback (GtkAction *action,
gpointer data);
......@@ -42,14 +44,5 @@ void channels_to_selection_cmd_callback (GtkAction *action,
gint value,
gpointer data);
void channels_new_channel_query (GimpImage *gimage,
GimpContext *context,
GimpChannel *template,
gboolean interactive,
GtkWidget *parent);
void channels_edit_channel_query (GimpChannel *channel,
GimpContext *context,
GtkWidget *parent);
#endif /* __CHANNELS_COMMANDS_H__ */
......@@ -64,42 +64,56 @@ static GimpActionEntry layers_actions[] =
GIMP_HELP_TOOL_TEXT },
{ "layers-edit-attributes", GIMP_STOCK_EDIT,
N_("_Edit Layer Attributes..."), NULL, NULL,
N_("_Edit Layer Attributes..."), NULL,
N_("Edit layer attributes"),
G_CALLBACK (layers_edit_attributes_cmd_callback),
GIMP_HELP_LAYER_EDIT },
{ "layers-new", GTK_STOCK_NEW,
N_("_New Layer..."), "", NULL,
N_("_New Layer..."), "",
N_("New layer dialog"),
G_CALLBACK (layers_new_cmd_callback),
GIMP_HELP_LAYER_NEW },
{ "layers-new-default", GTK_STOCK_NEW,
N_("_New Layer"), "",
N_("New layer"),
G_CALLBACK (layers_new_default_cmd_callback),
GIMP_HELP_LAYER_NEW },
{ "layers-duplicate", GIMP_STOCK_DUPLICATE,
N_("D_uplicate Layer"), NULL, NULL,
N_("D_uplicate Layer"), NULL,
N_("Duplicate layer"),
G_CALLBACK (layers_duplicate_cmd_callback),
GIMP_HELP_LAYER_DUPLICATE },
{ "layers-delete", GTK_STOCK_DELETE,
N_("_Delete Layer"), "", NULL,
N_("_Delete Layer"), "",
N_("Delete layer"),
G_CALLBACK (layers_delete_cmd_callback),
GIMP_HELP_LAYER_DELETE },
{ "layers-raise", GTK_STOCK_GO_UP,
N_("_Raise Layer"), "", NULL,
N_("_Raise Layer"), "",
N_("Raise layer"),
G_CALLBACK (layers_raise_cmd_callback),
GIMP_HELP_LAYER_RAISE },
{ "layers-raise-to-top", GTK_STOCK_GOTO_TOP,
N_("Layer to _Top"), "", NULL,
N_("Layer to _Top"), "",
N_("Raise layer to top"),
G_CALLBACK (layers_raise_to_top_cmd_callback),
GIMP_HELP_LAYER_RAISE_TO_TOP },
{ "layers-lower", GTK_STOCK_GO_DOWN,
N_("_Lower Layer"), "", NULL,
N_("_Lower Layer"), "",
N_("Lower layer"),
G_CALLBACK (layers_lower_cmd_callback),
GIMP_HELP_LAYER_LOWER },
{ "layers-lower-to-bottom", GTK_STOCK_GOTO_BOTTOM,
N_("Layer to _Bottom"), "", NULL,
N_("Layer to _Bottom"), "",
N_("Lower layer to bottom"),
G_CALLBACK (layers_lower_to_bottom_cmd_callback),
GIMP_HELP_LAYER_LOWER_TO_BOTTOM },
......@@ -437,6 +451,7 @@ layers_actions_update (GimpActionGroup *group,
SET_SENSITIVE ("layers-edit-attributes", layer && !fs && !ac);
SET_SENSITIVE ("layers-new", gimage);
SET_SENSITIVE ("layers-new-default", gimage);
SET_SENSITIVE ("layers-duplicate", layer && !fs && !ac);
SET_SENSITIVE ("layers-delete", layer && !ac);
......
......@@ -48,6 +48,7 @@
#include "text/gimptext.h"
#include "text/gimptextlayer.h"
#include "widgets/gimpaction.h"
#include "widgets/gimpdock.h"
#include "widgets/gimpenumwidgets.h"
#include "widgets/gimphelp-ids.h"
......@@ -99,6 +100,12 @@ static const GimpLayerModeEffects layer_modes[] =
/* local function prototypes */
static void layers_new_layer_query (GimpImage *gimage,
GimpContext *context,
GtkWidget *parent);
static void layers_edit_layer_query (GimpLayer *layer,
GimpContext *context,
GtkWidget *parent);
static void layers_add_mask_query (GimpLayer *layer,
GtkWidget *parent);
static void layers_scale_layer_query (GimpDisplay *gdisp,
......@@ -128,10 +135,35 @@ layers_text_tool_cmd_callback (GtkAction *action,
GimpImage *gimage;
GimpLayer *layer;
GtkWidget *widget;
GimpTool *active_tool;
return_if_no_layer (gimage, layer, data);
return_if_no_widget (widget, data);
layers_text_tool (layer, action_data_get_context (data), widget);
if (! gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
{
layers_edit_layer_query (layer, action_data_get_context (data), widget);
return;
}
active_tool = tool_manager_get_active (gimage->gimp);
if (! GIMP_IS_TEXT_TOOL (active_tool))
{
GimpToolInfo *tool_info;
tool_info = (GimpToolInfo *)
gimp_container_get_child_by_name (gimage->gimp->tool_info_list,
"gimp-text-tool");
if (GIMP_IS_TOOL_INFO (tool_info))
{
gimp_context_set_tool (action_data_get_context (data), tool_info);
active_tool = tool_manager_get_active (gimage->gimp);
}
}
if (GIMP_IS_TEXT_TOOL (active_tool))
gimp_text_tool_set_layer (GIMP_TEXT_TOOL (active_tool), layer);
}
void
......@@ -153,11 +185,83 @@ layers_new_cmd_callback (GtkAction *action,
{
GimpImage *gimage;
GtkWidget *widget;
GimpLayer *floating_sel;
return_if_no_image (gimage, data);
return_if_no_widget (widget, data);
layers_new_layer_query (gimage, action_data_get_context (data),
NULL, TRUE, widget);
/* If there is a floating selection, the new command transforms
* the current fs into a new layer
*/
if ((floating_sel = gimp_image_floating_sel (gimage)))
{
floating_sel_to_layer (floating_sel);
gimp_image_flush (gimage);
return;
}
layers_new_layer_query (gimage, action_data_get_context (data), widget);
}
void
layers_new_default_cmd_callback (GtkAction *action,
gpointer data)
{
GimpImage *gimage;
GimpLayer *floating_sel;
GimpLayer *new_layer;
gint width, height;
gint off_x, off_y;
gdouble opacity;
GimpLayerModeEffects mode;
return_if_no_image (gimage, data);
/* If there is a floating selection, the new command transforms
* the current fs into a new layer
*/
if ((floating_sel = gimp_image_floating_sel (gimage)))
{
floating_sel_to_layer (floating_sel);
gimp_image_flush (gimage);
return;
}
if (GIMP_IS_LAYER (GIMP_ACTION (action)->viewable))
{
GimpLayer *template = GIMP_LAYER (GIMP_ACTION (action)->viewable);
gimp_item_offsets (GIMP_ITEM (template), &off_x, &off_y);
width = gimp_item_width (GIMP_ITEM (template));
height = gimp_item_height (GIMP_ITEM (template));
opacity = template->opacity;
mode = template->mode;
}
else
{
width = gimp_image_get_width (gimage);
height = gimp_image_get_height (gimage);
off_x = 0;
off_y = 0;
opacity = 1.0;
mode = GIMP_NORMAL_MODE;
}
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_EDIT_PASTE,
_("New Layer"));
new_layer = gimp_layer_new (gimage, width, height,
gimp_image_base_type_with_alpha (gimage),
_("Empty Layer"), opacity, mode);
gimp_drawable_fill_by_type (GIMP_DRAWABLE (new_layer),
action_data_get_context (data),
GIMP_TRANSPARENT_FILL);
gimp_item_translate (GIMP_ITEM (new_layer), off_x, off_y, FALSE);
gimp_image_add_layer (gimage, new_layer, -1);
gimp_image_undo_group_end (gimage);
gimp_image_flush (gimage);
}
void
......@@ -622,47 +726,6 @@ layers_preserve_trans_cmd_callback (GtkAction *action,
}
}
void
layers_text_tool (GimpLayer *layer,
GimpContext *context,
GtkWidget *parent)
{
GimpImage *gimage;
GimpTool *active_tool;
g_return_if_fail (GIMP_IS_LAYER (layer));
g_return_if_fail (GIMP_IS_CONTEXT (context));
if (! gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
{
layers_edit_layer_query (layer, context, parent);
return;
}
gimage = gimp_item_get_image (GIMP_ITEM (layer));
active_tool = tool_manager_get_active (gimage->gimp);
if (! GIMP_IS_TEXT_TOOL (active_tool))
{
GimpContainer *tool_info_list = gimage->gimp->tool_info_list;
GimpToolInfo *tool_info;
tool_info = (GimpToolInfo *)
gimp_container_get_child_by_name (tool_info_list,
"gimp-text-tool");
if (GIMP_IS_TOOL_INFO (tool_info))
{
gimp_context_set_tool (context, tool_info);
active_tool = tool_manager_get_active (gimage->gimp);
}
}
if (GIMP_IS_TEXT_TOOL (active_tool))
gimp_text_tool_set_layer (GIMP_TEXT_TOOL (active_tool), layer);
}