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

added virtual method context_item() which works like select_item() and

2001-04-29  Michael Natterer  <mitch@gimp.org>

	* app/widgets/gimpcontainerview.[ch]: added virtual method
	context_item() which works like select_item() and activate_item()
	and a function to trigger the signal from subclasses (marked as
	"protected").

	* app/widgets/gimpcontainerlistview.c: invoke context_item() on
	right click.

	* app/widgets/gimpdrawablelistview.[ch]: implement context_item()
	and show a context menu. The functions to show the menu as well as
	functions to create a new drawable and to edit it's attriutes must
	be passed to the constructor now.

	* app/gui/channels-commands.[ch]
	* app/gui/layers-commands.[ch]: added functions which show the
	layers and channels context menus. No accelerators supported yet.
	Auto-destroy all dialogs when their drawable is removed from the
	image.

	* app/gui/dialogs-constructors.c: changed the calls to
	gimp_drawable_list_view_new() accordingly.

	* app/gui/menus.c
	* app/gui/test-commands.[ch]: removed some test dialogs.
parent f4f40a20
2001-04-29 Michael Natterer <mitch@gimp.org>
* app/widgets/gimpcontainerview.[ch]: added virtual method
context_item() which works like select_item() and activate_item()
and a function to trigger the signal from subclasses (marked as
"protected").
* app/widgets/gimpcontainerlistview.c: invoke context_item() on
right click.
* app/widgets/gimpdrawablelistview.[ch]: implement context_item()
and show a context menu. The functions to show the menu as well as
functions to create a new drawable and to edit it's attriutes must
be passed to the constructor now.
* app/gui/channels-commands.[ch]
* app/gui/layers-commands.[ch]: added functions which show the
layers and channels context menus. No accelerators supported yet.
Auto-destroy all dialogs when their drawable is removed from the
image.
* app/gui/dialogs-constructors.c: changed the calls to
gimp_drawable_list_view_new() accordingly.
* app/gui/menus.c
* app/gui/test-commands.[ch]: removed some test dialogs.
2001-04-28 David Neary <dneary@eircom.net>
* app/tools/transform_options.[ch]: Separated the transform
......
......@@ -30,15 +30,20 @@
#include "channels-commands.h"
#include "gdisplay.h"
#include "gimpui.h"
#include "menus.h"
#include "drawable.h"
#include "gimage_mask.h"
#include "gimpchannel.h"
#include "gimpimage.h"
#include "gimplist.h"
#include "libgimp/gimpintl.h"
static void channels_menu_set_sensitivity (GimpImage *gimage);
void
channels_new_channel_cmd_callback (GtkWidget *widget,
gpointer data)
......@@ -511,6 +516,10 @@ channels_edit_channel_query (GimpChannel *channel)
GTK_SIGNAL_FUNC (g_free),
(GtkObject *) options);
gtk_signal_connect_object_while_alive (GTK_OBJECT (channel), "removed",
GTK_SIGNAL_FUNC (gtk_widget_destroy),
GTK_OBJECT (options->query_box));
/* The main hbox */
hbox = gtk_hbox_new (FALSE, 2);
gtk_container_set_border_width (GTK_CONTAINER (hbox), 4);
......@@ -572,3 +581,67 @@ channels_edit_channel_query (GimpChannel *channel)
gtk_widget_show (hbox);
gtk_widget_show (options->query_box);
}
void
channels_show_context_menu (GimpImage *gimage)
{
GtkItemFactory *item_factory;
gint x, y;
channels_menu_set_sensitivity (gimage);
item_factory = menus_get_channels_factory ();
gimp_menu_position (GTK_MENU (item_factory->widget), &x, &y);
gtk_item_factory_popup_with_data (item_factory,
gimage, NULL,
x, y,
3, 0);
}
static void
channels_menu_set_sensitivity (GimpImage *gimage)
{
GimpChannel *channel;
gboolean fs;
GList *list;
GList *next = NULL;
GList *prev = NULL;
g_return_if_fail (gimage != NULL);
g_return_if_fail (GIMP_IS_IMAGE (gimage));
channel = gimp_image_get_active_channel (gimage);
fs = (gimp_image_floating_sel (gimage) != NULL);
for (list = GIMP_LIST (gimage->channels)->list;
list;
list = g_list_next (list))
{
if (channel == (GimpChannel *) list->data)
{
prev = g_list_previous (list);
next = g_list_next (list);
break;
}
}
#define SET_SENSITIVE(menu,condition) \
menus_set_sensitive ("<Channels>/" menu, (condition) != 0)
SET_SENSITIVE ("New Channel...", !fs);
SET_SENSITIVE ("Raise Channel", channel && !fs && prev);
SET_SENSITIVE ("Lower Channel", channel && !fs && next);
SET_SENSITIVE ("Duplicate Channel", channel && !fs);
SET_SENSITIVE ("Channel to Selection", channel);
SET_SENSITIVE ("Add to Selection", channel);
SET_SENSITIVE ("Subtract from Selection", channel);
SET_SENSITIVE ("Intersect with Selection", channel);
SET_SENSITIVE ("Delete Channel", channel && !fs);
SET_SENSITIVE ("Edit Channel Attributes...", channel && !fs);
#undef SET_OPS_SENSITIVE
}
......@@ -43,6 +43,7 @@ void channels_edit_channel_attributes_cmd_callback (GtkWidget *widget,
void channels_new_channel_query (GimpImage *gimage);
void channels_edit_channel_query (GimpChannel *channel);
void channels_show_context_menu (GimpImage *gimage);
#endif /* __CHANNELS_COMMANDS_H__ */
......@@ -33,6 +33,7 @@
#include "gdisplay.h"
#include "gimpui.h"
#include "layers-commands.h"
#include "menus.h"
#include "resize.h"
#include "drawable.h"
......@@ -47,11 +48,12 @@
#include "libgimp/gimpintl.h"
static void layers_add_mask_query (GimpLayer *layer);
static void layers_scale_layer_query (GimpImage *gimage,
GimpLayer *layer);
static void layers_resize_layer_query (GimpImage *gimage,
GimpLayer *layer);
static void layers_add_mask_query (GimpLayer *layer);
static void layers_scale_layer_query (GimpImage *gimage,
GimpLayer *layer);
static void layers_resize_layer_query (GimpImage *gimage,
GimpLayer *layer);
static void layers_menu_set_sensitivity (GimpImage *gimage);
void
......@@ -567,8 +569,8 @@ layers_new_layer_query (GimpImage *gimage)
GtkWidget *spinbutton;
GtkWidget *frame;
/* The new options structure */
options = g_new (NewLayerOptions, 1);
options = g_new0 (NewLayerOptions, 1);
options->fill_type = fill_type;
options->gimage = gimage;
......@@ -775,6 +777,10 @@ layers_edit_layer_query (GimpLayer *layer)
GTK_SIGNAL_FUNC (g_free),
(GtkObject *) options);
gtk_signal_connect_object_while_alive (GTK_OBJECT (layer), "removed",
GTK_SIGNAL_FUNC (gtk_widget_destroy),
GTK_OBJECT (options->query_box));
/* The main vbox */
vbox = gtk_vbox_new (FALSE, 2);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 4);
......@@ -874,6 +880,10 @@ layers_add_mask_query (GimpLayer *layer)
GTK_SIGNAL_FUNC (g_free),
(GtkObject *) options);
gtk_signal_connect_object_while_alive (GTK_OBJECT (layer), "removed",
GTK_SIGNAL_FUNC (gtk_widget_destroy),
GTK_OBJECT (options->query_box));
/* The radio frame and box */
if (gimage->selection_mask)
{
......@@ -1131,8 +1141,8 @@ layer_merge_query_ok_callback (GtkWidget *widget,
void
layers_layer_merge_query (GimpImage *gimage,
/* if FALSE, anchor active layer */
gboolean merge_visible)
/* if FALSE, anchor active layer */
gboolean merge_visible)
{
LayerMergeOptions *options;
GtkWidget *vbox;
......@@ -1192,3 +1202,111 @@ layers_layer_merge_query (GimpImage *gimage,
gtk_widget_show (vbox);
gtk_widget_show (options->query_box);
}
void
layers_show_context_menu (GimpImage *gimage)
{
GtkItemFactory *item_factory;
gint x, y;
layers_menu_set_sensitivity (gimage);
item_factory = menus_get_layers_factory ();
gimp_menu_position (GTK_MENU (item_factory->widget), &x, &y);
gtk_item_factory_popup_with_data (item_factory,
gimage, NULL,
x, y,
3, 0);
}
static void
layers_menu_set_sensitivity (GimpImage *gimage)
{
GimpLayer *layer;
gboolean fs = FALSE; /* no floating sel */
gboolean ac = FALSE; /* no active channel */
gboolean lm = FALSE; /* layer mask */
gboolean lp = FALSE; /* layers present */
gboolean alpha = FALSE; /* alpha channel present */
gboolean indexed = FALSE; /* is indexed */
gboolean next_alpha = FALSE;
GList *list;
GList *next = NULL;
GList *prev = NULL;
g_return_if_fail (gimage != NULL);
g_return_if_fail (GIMP_IS_IMAGE (gimage));
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_layer_has_alpha (layer);
lp = ! gimp_image_is_empty (gimage);
indexed = (gimp_image_base_type (gimage) == 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_layer_has_alpha (GIMP_LAYER (next->data));
else
next_alpha = FALSE;
#define SET_SENSITIVE(menu,condition) \
menus_set_sensitive ("<Layers>/" menu, (condition) != 0)
SET_SENSITIVE ("New Layer...", gimage);
SET_SENSITIVE ("Stack/Raise Layer",
fs && ac && gimage && lp && alpha && prev);
SET_SENSITIVE ("Stack/Lower Layer",
fs && ac && gimage && lp && next && next_alpha);
SET_SENSITIVE ("Stack/Layer to Top",
fs && ac && gimage && lp && alpha && prev);
SET_SENSITIVE ("Stack/Layer to Bottom",
fs && ac && gimage && lp && next && next_alpha);
SET_SENSITIVE ("Duplicate Layer", fs && ac && gimage && lp);
SET_SENSITIVE ("Anchor Layer", !fs && ac && gimage && lp);
SET_SENSITIVE ("Delete Layer", ac && gimage && lp);
SET_SENSITIVE ("Layer Boundary Size...", ac && gimage && lp);
SET_SENSITIVE ("Layer to Imagesize", ac && gimage && lp);
SET_SENSITIVE ("Scale Layer...", ac && gimage && lp);
SET_SENSITIVE ("Merge Visible Layers...", fs && ac && gimage && lp);
SET_SENSITIVE ("Merge Down", fs && ac && gimage && lp && next);
SET_SENSITIVE ("Flatten Image", fs && ac && gimage && lp);
SET_SENSITIVE ("Add Layer Mask...",
fs && ac && gimage && !lm && lp && alpha && !indexed);
SET_SENSITIVE ("Apply Layer Mask", fs && ac && gimage && lm && lp);
SET_SENSITIVE ("Delete Layer Mask", fs && ac && gimage && lm && lp);
SET_SENSITIVE ("Mask to Selection", fs && ac && gimage && lm && lp);
SET_SENSITIVE ("Add Alpha Channel", !alpha);
SET_SENSITIVE ("Alpha to Selection", fs && ac && gimage && lp && alpha);
SET_SENSITIVE ("Edit Layer Attributes...", ac && gimage && lp);
#undef SET_SENSITIVE
}
......@@ -69,6 +69,8 @@ void layers_edit_attributes_cmd_callback (GtkWidget *widet,
void layers_new_layer_query (GimpImage *gimage);
void layers_edit_layer_query (GimpLayer *layer);
void layers_show_context_menu (GimpImage *gimage);
void layers_layer_merge_query (GimpImage *gimage,
gboolean merge_visible);
......
......@@ -41,6 +41,7 @@
#include "about-dialog.h"
#include "brush-editor.h"
#include "brush-select.h"
#include "channels-commands.h"
#include "color-area.h"
#include "colormap-dialog.h"
#include "devices.h"
......@@ -50,6 +51,7 @@
#include "gdisplay.h"
#include "gradient-editor.h"
#include "gradient-select.h"
#include "layers-commands.h"
#include "lc_dialog.h"
#include "palette-editor.h"
#include "pattern-select.h"
......@@ -292,6 +294,8 @@ dialogs_dock_new (GimpDialogFactory *factory,
}
/* list views */
GtkWidget *
dialogs_image_list_view_new (GimpDialogFactory *factory,
GimpContext *context)
......@@ -357,7 +361,7 @@ dialogs_gradient_list_view_new (GimpDialogFactory *factory,
global_gradient_factory,
dialogs_edit_gradient_func,
context,
32,
32 / 2,
5, 3);
return dialogs_dockable_new (view,
......@@ -538,7 +542,10 @@ dialogs_layer_list_view_new (GimpDialogFactory *factory,
(GimpReorderDrawableFunc) gimp_image_position_layer,
(GimpAddDrawableFunc) gimp_image_add_layer,
(GimpRemoveDrawableFunc) gimp_image_remove_layer,
(GimpCopyDrawableFunc) gimp_layer_copy);
(GimpCopyDrawableFunc) gimp_layer_copy,
(GimpNewDrawableFunc) layers_new_layer_query,
(GimpEditDrawableFunc) layers_edit_layer_query,
(GimpDrawableContextFunc) layers_show_context_menu);
dockable = dialogs_dockable_new (view,
"Layer List", "Layers",
......@@ -570,7 +577,10 @@ dialogs_channel_list_view_new (GimpDialogFactory *factory,
(GimpReorderDrawableFunc) gimp_image_position_channel,
(GimpAddDrawableFunc) gimp_image_add_channel,
(GimpRemoveDrawableFunc) gimp_image_remove_channel,
(GimpCopyDrawableFunc) gimp_channel_copy);
(GimpCopyDrawableFunc) gimp_channel_copy,
(GimpNewDrawableFunc) channels_new_channel_query,
(GimpEditDrawableFunc) channels_edit_channel_query,
(GimpDrawableContextFunc) channels_show_context_menu);
dockable = dialogs_dockable_new (view,
"Channel List", "Channels",
......
......@@ -30,15 +30,20 @@
#include "channels-commands.h"
#include "gdisplay.h"
#include "gimpui.h"
#include "menus.h"
#include "drawable.h"
#include "gimage_mask.h"
#include "gimpchannel.h"
#include "gimpimage.h"
#include "gimplist.h"
#include "libgimp/gimpintl.h"
static void channels_menu_set_sensitivity (GimpImage *gimage);
void
channels_new_channel_cmd_callback (GtkWidget *widget,
gpointer data)
......@@ -511,6 +516,10 @@ channels_edit_channel_query (GimpChannel *channel)
GTK_SIGNAL_FUNC (g_free),
(GtkObject *) options);
gtk_signal_connect_object_while_alive (GTK_OBJECT (channel), "removed",
GTK_SIGNAL_FUNC (gtk_widget_destroy),
GTK_OBJECT (options->query_box));
/* The main hbox */
hbox = gtk_hbox_new (FALSE, 2);
gtk_container_set_border_width (GTK_CONTAINER (hbox), 4);
......@@ -572,3 +581,67 @@ channels_edit_channel_query (GimpChannel *channel)
gtk_widget_show (hbox);
gtk_widget_show (options->query_box);
}
void
channels_show_context_menu (GimpImage *gimage)
{
GtkItemFactory *item_factory;
gint x, y;
channels_menu_set_sensitivity (gimage);
item_factory = menus_get_channels_factory ();
gimp_menu_position (GTK_MENU (item_factory->widget), &x, &y);
gtk_item_factory_popup_with_data (item_factory,
gimage, NULL,
x, y,
3, 0);
}
static void
channels_menu_set_sensitivity (GimpImage *gimage)
{
GimpChannel *channel;
gboolean fs;
GList *list;
GList *next = NULL;
GList *prev = NULL;
g_return_if_fail (gimage != NULL);
g_return_if_fail (GIMP_IS_IMAGE (gimage));
channel = gimp_image_get_active_channel (gimage);
fs = (gimp_image_floating_sel (gimage) != NULL);
for (list = GIMP_LIST (gimage->channels)->list;
list;
list = g_list_next (list))
{
if (channel == (GimpChannel *) list->data)
{
prev = g_list_previous (list);
next = g_list_next (list);
break;
}
}
#define SET_SENSITIVE(menu,condition) \
menus_set_sensitive ("<Channels>/" menu, (condition) != 0)
SET_SENSITIVE ("New Channel...", !fs);
SET_SENSITIVE ("Raise Channel", channel && !fs && prev);
SET_SENSITIVE ("Lower Channel", channel && !fs && next);
SET_SENSITIVE ("Duplicate Channel", channel && !fs);
SET_SENSITIVE ("Channel to Selection", channel);
SET_SENSITIVE ("Add to Selection", channel);
SET_SENSITIVE ("Subtract from Selection", channel);
SET_SENSITIVE ("Intersect with Selection", channel);
SET_SENSITIVE ("Delete Channel", channel && !fs);
SET_SENSITIVE ("Edit Channel Attributes...", channel && !fs);
#undef SET_OPS_SENSITIVE
}
......@@ -43,6 +43,7 @@ void channels_edit_channel_attributes_cmd_callback (GtkWidget *widget,
void channels_new_channel_query (GimpImage *gimage);
void channels_edit_channel_query (GimpChannel *channel);
void channels_show_context_menu (GimpImage *gimage);
#endif /* __CHANNELS_COMMANDS_H__ */
......@@ -41,6 +41,7 @@
#include "about-dialog.h"
#include "brush-editor.h"
#include "brush-select.h"
#include "channels-commands.h"
#include "color-area.h"
#include "colormap-dialog.h"
#include "devices.h"
......@@ -50,6 +51,7 @@
#include "gdisplay.h"
#include "gradient-editor.h"
#include "gradient-select.h"
#include "layers-commands.h"
#include "lc_dialog.h"
#include "palette-editor.h"
#include "pattern-select.h"
......@@ -292,6 +294,8 @@ dialogs_dock_new (GimpDialogFactory *factory,
}
/* list views */
GtkWidget *
dialogs_image_list_view_new (GimpDialogFactory *factory,
GimpContext *context)
......@@ -357,7 +361,7 @@ dialogs_gradient_list_view_new (GimpDialogFactory *factory,
global_gradient_factory,
dialogs_edit_gradient_func,
context,
32,
32 / 2,
5, 3);
return dialogs_dockable_new (view,
......@@ -538,7 +542,10 @@ dialogs_layer_list_view_new (GimpDialogFactory *factory,
(GimpReorderDrawableFunc) gimp_image_position_layer,
(GimpAddDrawableFunc) gimp_image_add_layer,
(GimpRemoveDrawableFunc) gimp_image_remove_layer,
(GimpCopyDrawableFunc) gimp_layer_copy);
(GimpCopyDrawableFunc) gimp_layer_copy,
(GimpNewDrawableFunc) layers_new_layer_query,
(GimpEditDrawableFunc) layers_edit_layer_query,
(GimpDrawableContextFunc) layers_show_context_menu);
dockable = dialogs_dockable_new (view,
"Layer List", "Layers",
......@@ -570,7 +577,10 @@ dialogs_channel_list_view_new (GimpDialogFactory *factory,
(GimpReorderDrawableFunc) gimp_image_position_channel,
(GimpAddDrawableFunc) gimp_image_add_channel,
(GimpRemoveDrawableFunc) gimp_image_remove_channel,
(GimpCopyDrawableFunc) gimp_channel_copy);
(GimpCopyDrawableFunc) gimp_channel_copy,
(GimpNewDrawableFunc) channels_new_channel_query,
(GimpEditDrawableFunc) channels_edit_channel_query,
(GimpDrawableContextFunc) channels_show_context_menu);
dockable = dialogs_dockable_new (view,
"Channel List", "Channels",
......
......@@ -33,6 +33,7 @@
#include "gdisplay.h"
#include "gimpui.h"
#include "layers-commands.h"
#include "menus.h"
#include "resize.h"
#include "drawable.h"
......@@ -47,11 +48,12 @@
#include "libgimp/gimpintl.h"
static void layers_add_mask_query (GimpLayer *layer);
static void layers_scale_layer_query (GimpImage *gimage,
GimpLayer *layer);
static void layers_resize_layer_query (GimpImage *gimage,
GimpLayer *layer);
static void layers_add_mask_query (GimpLayer *layer);
static void layers_scale_layer_query (GimpImage *gimage,
GimpLayer *layer);
static void layers_resize_layer_query (GimpImage *gimage,
GimpLayer *layer);
static void layers_menu_set_sensitivity (GimpImage *gimage);
void
......@@ -567,8 +569,8 @@ layers_new_layer_query (GimpImage *gimage)
GtkWidget *spinbutton;
GtkWidget *frame;
/* The new options structure */
options = g_new (NewLayerOptions, 1);
options = g_new0 (NewLayerOptions, 1);
options->fill_type = fill_type;
options->gimage = gimage;
......@@ -775,6 +777,10 @@ layers_edit_layer_query (GimpLayer *layer)
GTK_SIGNAL_FUNC (g_free),
(GtkObject *) options);
gtk_signal_connect_object_while_alive (GTK_OBJECT (layer), "removed",
GTK_SIGNAL_FUNC (gtk_widget_destroy),
GTK_OBJECT (options->query_box));
/* The main vbox */
vbox = gtk_vbox_new (FALSE, 2);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 4);
......@@ -874,6 +880,10 @@ layers_add_mask_query (GimpLayer *layer)
GTK_SIGNAL_FUNC (g_free),
(GtkObject *) options);
gtk_signal_connect_object_while_alive (GTK_OBJECT (layer), "removed",
GTK_SIGNAL_FUNC (gtk_widget_destroy),
GTK_OBJECT (options->query_box));
/* The radio frame and box */
if (gimage->selection_mask)
{
......@@ -1131,8 +1141,8 @@ layer_merge_query_ok_callback (GtkWidget *widget,
void
layers_layer_merge_query (GimpImage *gimage,
/* if FALSE, anchor active layer */
gboolean merge_visible)
/* if FALSE, anchor active layer */
gboolean merge_visible)
{
LayerMergeOptions *options;
GtkWidget *vbox;
......@@ -1192,3 +1202,111 @@ layers_layer_merge_query (GimpImage *gimage,
gtk_widget_show (vbox);
gtk_widget_show (options->query_box);
}
void
layers_show_context_menu (GimpImage *gimage)