Gimp/app/gui/layers-menu.c
Michael Natterer 69539fc5c4 added GimpMenuPositionFunc typedef.
2003-07-02  Michael Natterer  <mitch@gimp.org>

	* app/widgets/widgets-types.h: added GimpMenuPositionFunc typedef.

	* app/widgets/gimpwidgets-utils.[ch]: made gimp_menu_position()
	a GimpMenuPositionFunc.

	* app/widgets/gimpitemfactory.[ch]
	(gimp_item_factory_popup_with_data): added position_func and
	position_data parameters. Use gimp_menu_position() if no
	position_func is given.

	* app/display/gimpdisplayshell-callbacks.c: removed
	gimp_display_shell_origin_menu_popup() and call
	gimp_item_factory_popup_with_data() directly from
	gimp_display_shell_popup_menu(), using
	gimp_display_shell_origin_menu_position() as position_func.

	* app/widgets/gimpeditor.[ch]: added a GtkWidget::popup_menu()
	implementation so all context menus are keyboard accessible.
	Added "gpointer factory_data" member so the menu can be popped up
	in the right context.

	* app/gui/channels-menu.c
	* app/gui/layers-menu.c
	* app/gui/vectors-menu.c: make them work without an active image
	since they can be popped up at any time now.

	* app/gui/image-menu.c
	* app/gui/toolbox-menu.c: cleanup.

	* app/widgets/gimpcolormapeditor.c
	* app/widgets/gimpcomponenteditor.c
	* app/widgets/gimpcontainereditor.c
	* app/widgets/gimpdockbook.c
	* app/widgets/gimperrorconsole.c
	* app/widgets/gimpgradienteditor.c
	* app/widgets/gimpitemtreeview.c
	* app/widgets/gimppaletteeditor.c: pass NULL, NULL as
	position_func and position_data so the default implementation is
	used.
2003-07-02 12:03:56 +00:00

236 lines
7.4 KiB
C

/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
#include "gui-types.h"
#include "core/gimpimage.h"
#include "core/gimplayer.h"
#include "core/gimplist.h"
#include "widgets/gimpitemfactory.h"
#include "widgets/gimpitemtreeview.h"
#include "layers-commands.h"
#include "layers-menu.h"
#include "menus.h"
#include "gimp-intl.h"
GimpItemFactoryEntry layers_menu_entries[] =
{
{ { N_("/New Layer..."), "<control>N",
layers_new_cmd_callback, 0,
"<StockItem>", GTK_STOCK_NEW },
NULL,
"dialogs/new_layer.html", NULL },
{ { N_("/Raise Layer"), "<control>F",
layers_raise_cmd_callback, 0,
"<StockItem>", GTK_STOCK_GO_UP },
NULL,
"stack/stack.html#raise_layer", NULL },
{ { N_("/Layer to Top"), "<control><shift>F",
layers_raise_to_top_cmd_callback, 0,
"<StockItem>", GTK_STOCK_GOTO_TOP },
NULL,
"stack/stack.html#later_to_top", NULL },
{ { N_("/Lower Layer"), "<control>B",
layers_lower_cmd_callback, 0,
"<StockItem>", GTK_STOCK_GO_DOWN },
NULL,
"stack/stack.html#lower_layer", NULL },
{ { N_("/Layer to Bottom"), "<control><shift>B",
layers_lower_to_bottom_cmd_callback, 0,
"<StockItem>", GTK_STOCK_GOTO_BOTTOM },
NULL,
"stack/stack.html#layer_to_bottom", NULL },
{ { N_("/Duplicate Layer"), "<control>C",
layers_duplicate_cmd_callback, 0,
"<StockItem>", GIMP_STOCK_DUPLICATE },
NULL,
"duplicate_layer.html", NULL },
{ { N_("/Anchor Layer"), "<control>H",
layers_anchor_cmd_callback, 0,
"<StockItem>", GIMP_STOCK_ANCHOR },
NULL,
"anchor_layer.html", NULL },
{ { N_("/Merge Down"), "<control><shift>M",
layers_merge_down_cmd_callback, 0,
"<StockItem>", GIMP_STOCK_MERGE_DOWN },
NULL,
"merge_down.html", NULL },
{ { N_("/Delete Layer"), "<control>X",
layers_delete_cmd_callback, 0,
"<StockItem>", GTK_STOCK_DELETE },
NULL,
"delete_layer.html", NULL },
MENU_SEPARATOR ("/---"),
{ { N_("/Layer Boundary Size..."), "<control>R",
layers_resize_cmd_callback, 0,
"<StockItem>", GIMP_STOCK_RESIZE },
NULL,
"dialogs/layer_boundary_size.html", NULL },
{ { N_("/Layer to Imagesize"), NULL,
layers_resize_to_image_cmd_callback, 0,
"<StockItem>", GIMP_STOCK_LAYER_TO_IMAGESIZE },
NULL,
"layer_to_image_size.html", NULL },
{ { N_("/Scale Layer..."), "<control>S",
layers_scale_cmd_callback, 0,
"<StockItem>", GIMP_STOCK_SCALE },
NULL,
"dialogs/scale_layer.html", NULL },
MENU_SEPARATOR ("/---"),
{ { N_("/Add Layer Mask..."), NULL,
layers_add_layer_mask_cmd_callback, 0 },
NULL,
"dialogs/add_layer_mask.html", NULL },
{ { N_("/Apply Layer Mask"), NULL,
layers_apply_layer_mask_cmd_callback, 0 },
NULL,
"apply_mask.html", NULL },
{ { N_("/Delete Layer Mask"), NULL,
layers_delete_layer_mask_cmd_callback, 0,
"<StockItem>", GTK_STOCK_DELETE },
NULL,
"delete_mask.html", NULL },
{ { N_("/Mask to Selection"), NULL,
layers_mask_select_cmd_callback, 0,
"<StockItem>", GIMP_STOCK_SELECTION_REPLACE },
NULL,
"mask_to_selection.html", NULL },
MENU_SEPARATOR ("/---"),
{ { N_("/Add Alpha Channel"), NULL,
layers_add_alpha_channel_cmd_callback, 0 },
NULL,
"add_alpha_channel.html", NULL },
{ { N_("/Alpha to Selection"), NULL,
layers_alpha_select_cmd_callback, 0,
"<StockItem>", GIMP_STOCK_SELECTION_REPLACE },
NULL,
"alpha_to_selection.html", NULL },
MENU_SEPARATOR ("/---"),
{ { N_("/Edit Layer Attributes..."), NULL,
layers_edit_attributes_cmd_callback, 0,
"<StockItem>", GIMP_STOCK_EDIT },
NULL,
"dialogs/edit_layer_attributes.html", NULL }
};
gint n_layers_menu_entries = G_N_ELEMENTS (layers_menu_entries);
void
layers_menu_update (GtkItemFactory *factory,
gpointer data)
{
GimpImage *gimage;
GimpLayer *layer = NULL;
gboolean fs = FALSE; /* floating sel */
gboolean ac = FALSE; /* active channel */
gboolean lm = FALSE; /* layer mask */
gboolean alpha = FALSE; /* alpha channel present */
gboolean indexed = FALSE; /* is indexed */
gboolean next_alpha = FALSE;
GList *next = NULL;
GList *prev = NULL;
gimage = GIMP_ITEM_TREE_VIEW (data)->gimage;
if (gimage)
{
GList *list;
layer = gimp_image_get_active_layer (gimage);
if (layer)
lm = (gimp_layer_get_mask (layer)) ? TRUE : FALSE;
fs = (gimp_image_floating_sel (gimage) != NULL);
ac = (gimp_image_get_active_channel (gimage) != NULL);
alpha = layer && gimp_drawable_has_alpha (GIMP_DRAWABLE (layer));
indexed = (gimp_image_base_type (gimage) == GIMP_INDEXED);
for (list = GIMP_LIST (gimage->layers)->list;
list;
list = g_list_next (list))
{
if (layer == (GimpLayer *) list->data)
{
prev = g_list_previous (list);
next = g_list_next (list);
break;
}
}
if (next)
next_alpha = gimp_drawable_has_alpha (GIMP_DRAWABLE (next->data));
else
next_alpha = FALSE;
}
#define SET_SENSITIVE(menu,condition) \
gimp_item_factory_set_sensitive (factory, menu, (condition) != 0)
SET_SENSITIVE ("/New Layer...", gimage);
SET_SENSITIVE ("/Raise Layer", layer && !fs && !ac && alpha && prev);
SET_SENSITIVE ("/Layer to Top", layer && !fs && !ac && alpha && prev);
SET_SENSITIVE ("/Lower Layer", layer && !fs && !ac && next && next_alpha);
SET_SENSITIVE ("/Layer to Bottom", layer && !fs && !ac && next && next_alpha);
SET_SENSITIVE ("/Duplicate Layer", layer && !fs && !ac);
SET_SENSITIVE ("/Anchor Layer", layer && fs && !ac);
SET_SENSITIVE ("/Merge Down", layer && !fs && !ac && next);
SET_SENSITIVE ("/Delete Layer", layer && !ac);
SET_SENSITIVE ("/Layer Boundary Size...", layer && !ac);
SET_SENSITIVE ("/Layer to Imagesize", layer && !ac);
SET_SENSITIVE ("/Scale Layer...", layer && !ac);
SET_SENSITIVE ("/Add Layer Mask...", layer && !fs && !ac && !lm && alpha);
SET_SENSITIVE ("/Apply Layer Mask", layer && !fs && !ac && lm);
SET_SENSITIVE ("/Delete Layer Mask", layer && !fs && !ac && lm);
SET_SENSITIVE ("/Mask to Selection", layer && !fs && !ac && lm);
SET_SENSITIVE ("/Add Alpha Channel", layer && !fs && !alpha);
SET_SENSITIVE ("/Alpha to Selection", layer && !fs && !ac && alpha);
SET_SENSITIVE ("/Edit Layer Attributes...", layer && !fs && !ac);
#undef SET_SENSITIVE
}