Commit b8739d59 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

added "name" attributes to all submenus.

2004-05-13  Michael Natterer  <mitch@gimp.org>

	* menus/tool-options-menu.xml: added "name" attributes to all
	submenus.

	* app/menus/tool-options-menu.c: use the menu names instead of the
	overly long action names.

	* app/actions/colormap-editor-commands.c
	* app/actions/tool-options-commands.c: added some callback
	implementations.

	* app/widgets/gimpcolormapeditor.c
	* app/widgets/gimptooloptionseditor.c: removed the callbacks here
	and use action buttons.

	* app/actions/actions.c
	* app/actions/colormap-editor-actions.c
	* app/actions/edit-actions.c: code review / cleanup.
parent b5ebbaaf
2004-05-13 Michael Natterer <mitch@gimp.org>
* menus/tool-options-menu.xml: added "name" attributes to all
submenus.
* app/menus/tool-options-menu.c: use the menu names instead of the
overly long action names.
* app/actions/colormap-editor-commands.c
* app/actions/tool-options-commands.c: added some callback
implementations.
* app/widgets/gimpcolormapeditor.c
* app/widgets/gimptooloptionseditor.c: removed the callbacks here
and use action buttons.
* app/actions/actions.c
* app/actions/colormap-editor-actions.c
* app/actions/edit-actions.c: code review / cleanup.
2004-05-13 Michael Natterer <mitch@gimp.org>
* app/core/gimpcontainer.c (gimp_container_add_handler): don't
......
......@@ -311,4 +311,3 @@ action_data_get_widget (gpointer data)
return NULL;
}
......@@ -27,9 +27,9 @@
#include "core/gimpimage.h"
#include "widgets/gimpactiongroup.h"
#include "widgets/gimpcolormapeditor.h"
#include "widgets/gimphelp-ids.h"
#include "actions.h"
#include "colormap-editor-actions.h"
#include "colormap-editor-commands.h"
......@@ -79,13 +79,11 @@ void
colormap_editor_actions_update (GimpActionGroup *group,
gpointer data)
{
GimpColormapEditor *editor;
GimpImage *gimage;
gboolean indexed = FALSE;
gint num_colors = 0;
GimpImage *gimage;
gboolean indexed = FALSE;
gint num_colors = 0;
editor = GIMP_COLORMAP_EDITOR (data);
gimage = GIMP_IMAGE_EDITOR (editor)->gimage;
gimage = action_data_get_image (data);
if (gimage)
{
......
......@@ -24,8 +24,13 @@
#include "actions-types.h"
#include "core/gimpcontext.h"
#include "core/gimpimage.h"
#include "core/gimpimage-colormap.h"
#include "widgets/gimpcolormapeditor.h"
#include "actions.h"
#include "colormap-editor-commands.h"
......@@ -46,9 +51,21 @@ colormap_editor_add_color_cmd_callback (GtkAction *action,
gint value,
gpointer data)
{
GimpColormapEditor *editor = GIMP_COLORMAP_EDITOR (data);
GimpContext *context;
GimpImage *gimage;
return_if_no_context (context, data);
return_if_no_image (gimage, data);
if (gimage->num_cols < 256)
{
GimpRGB color;
if (value)
gimp_context_get_background (context, &color);
else
gimp_context_get_foreground (context, &color);
if (GTK_WIDGET_SENSITIVE (editor->add_button))
gimp_button_extended_clicked (GIMP_BUTTON (editor->add_button),
value ? GDK_CONTROL_MASK : 0);
gimp_image_add_colormap_entry (gimage, &color);
gimp_image_flush (gimage);
}
}
......@@ -27,9 +27,9 @@
#include "core/gimpimage.h"
#include "widgets/gimpactiongroup.h"
#include "widgets/gimpcolormapeditor.h"
#include "widgets/gimphelp-ids.h"
#include "actions.h"
#include "colormap-editor-actions.h"
#include "colormap-editor-commands.h"
......@@ -79,13 +79,11 @@ void
colormap_editor_actions_update (GimpActionGroup *group,
gpointer data)
{
GimpColormapEditor *editor;
GimpImage *gimage;
gboolean indexed = FALSE;
gint num_colors = 0;
GimpImage *gimage;
gboolean indexed = FALSE;
gint num_colors = 0;
editor = GIMP_COLORMAP_EDITOR (data);
gimage = GIMP_IMAGE_EDITOR (editor)->gimage;
gimage = action_data_get_image (data);
if (gimage)
{
......
......@@ -24,8 +24,13 @@
#include "actions-types.h"
#include "core/gimpcontext.h"
#include "core/gimpimage.h"
#include "core/gimpimage-colormap.h"
#include "widgets/gimpcolormapeditor.h"
#include "actions.h"
#include "colormap-editor-commands.h"
......@@ -46,9 +51,21 @@ colormap_editor_add_color_cmd_callback (GtkAction *action,
gint value,
gpointer data)
{
GimpColormapEditor *editor = GIMP_COLORMAP_EDITOR (data);
GimpContext *context;
GimpImage *gimage;
return_if_no_context (context, data);
return_if_no_image (gimage, data);
if (gimage->num_cols < 256)
{
GimpRGB color;
if (value)
gimp_context_get_background (context, &color);
else
gimp_context_get_foreground (context, &color);
if (GTK_WIDGET_SENSITIVE (editor->add_button))
gimp_button_extended_clicked (GIMP_BUTTON (editor->add_button),
value ? GDK_CONTROL_MASK : 0);
gimp_image_add_colormap_entry (gimage, &color);
gimp_image_flush (gimage);
}
}
......@@ -151,6 +151,7 @@ edit_actions_setup (GimpActionGroup *group)
{
GimpContext *user_context;
GimpRGB color;
GimpPattern *pattern;
gimp_action_group_add_actions (group,
edit_actions,
......@@ -183,6 +184,9 @@ edit_actions_setup (GimpActionGroup *group)
gimp_context_get_background (user_context, &color);
edit_actions_background_changed (user_context, &color, group);
pattern = gimp_context_get_pattern (user_context);
edit_actions_pattern_changed (user_context, pattern, group);
}
void
......@@ -190,16 +194,37 @@ edit_actions_update (GimpActionGroup *group,
gpointer data)
{
GimpImage *gimage;
GimpDrawable *drawable = NULL;
gboolean sel = FALSE;
GimpDrawable *drawable = NULL;
gchar *undo_name = NULL;
gchar *redo_name = NULL;
gboolean undo_enabled = FALSE;
gimage = action_data_get_image (data);
if (gimage)
{
sel = ! gimp_channel_is_empty (gimp_image_get_mask (gimage));
GimpUndo *undo;
GimpUndo *redo;
drawable = gimp_image_active_drawable (gimage);
undo_enabled = gimp_image_undo_is_enabled (gimage);
if (undo_enabled)
{
undo = gimp_undo_stack_peek (gimage->undo_stack);
redo = gimp_undo_stack_peek (gimage->redo_stack);
if (undo)
undo_name =
g_strdup_printf (_("_Undo %s"),
gimp_object_get_name (GIMP_OBJECT (undo)));
if (redo)
redo_name =
g_strdup_printf (_("_Redo %s"),
gimp_object_get_name (GIMP_OBJECT (redo)));
}
}
#define SET_LABEL(action,label) \
......@@ -207,42 +232,15 @@ edit_actions_update (GimpActionGroup *group,
#define SET_SENSITIVE(action,condition) \
gimp_action_group_set_action_sensitive (group, action, (condition) != 0)
{
gchar *undo_name = NULL;
gchar *redo_name = NULL;
gboolean enabled = FALSE;
if (gimage && gimp_image_undo_is_enabled (gimage))
{
GimpUndo *undo;
GimpUndo *redo;
undo = gimp_undo_stack_peek (gimage->undo_stack);
redo = gimp_undo_stack_peek (gimage->redo_stack);
enabled = TRUE;
if (undo)
undo_name =
g_strdup_printf (_("_Undo %s"),
gimp_object_get_name (GIMP_OBJECT (undo)));
if (redo)
redo_name =
g_strdup_printf (_("_Redo %s"),
gimp_object_get_name (GIMP_OBJECT (redo)));
}
SET_LABEL ("edit-undo", undo_name ? undo_name : _("_Undo"));
SET_LABEL ("edit-redo", redo_name ? redo_name : _("_Redo"));
SET_LABEL ("edit-undo", undo_name ? undo_name : _("_Undo"));
SET_LABEL ("edit-redo", redo_name ? redo_name : _("_Redo"));
SET_SENSITIVE ("edit-undo", enabled && undo_name);
SET_SENSITIVE ("edit-redo", enabled && redo_name);
SET_SENSITIVE ("edit-undo-clear", enabled && (redo_name || redo_name));
SET_SENSITIVE ("edit-undo", undo_enabled && undo_name);
SET_SENSITIVE ("edit-redo", undo_enabled && redo_name);
SET_SENSITIVE ("edit-undo-clear", undo_enabled && (redo_name || redo_name));
g_free (undo_name);
g_free (redo_name);
}
g_free (undo_name);
g_free (redo_name);
SET_SENSITIVE ("edit-cut", drawable);
SET_SENSITIVE ("edit-copy", drawable);
......
......@@ -174,21 +174,54 @@ void
tool_options_reset_cmd_callback (GtkAction *action,
gpointer data)
{
GimpToolOptionsEditor *editor = GIMP_TOOL_OPTIONS_EDITOR (data);
GimpEditor *editor = GIMP_EDITOR (data);
GimpContext *context = gimp_get_user_context (editor->ui_manager->gimp);
GimpToolInfo *tool_info = gimp_context_get_tool (context);
if (GTK_WIDGET_SENSITIVE (editor->reset_button))
gtk_button_clicked (GTK_BUTTON (editor->reset_button));
gimp_tool_options_reset (tool_info->tool_options);
}
static void
tool_options_reset_all_callback (GtkWidget *widget,
gboolean reset_all,
gpointer data)
{
Gimp *gimp = GIMP (data);
if (reset_all)
{
GList *list;
for (list = GIMP_LIST (gimp->tool_info_list)->list;
list;
list = g_list_next (list))
{
GimpToolInfo *tool_info = list->data;
gimp_tool_options_reset (tool_info->tool_options);
}
}
}
void
tool_options_reset_all_cmd_callback (GtkAction *action,
gpointer data)
{
GimpToolOptionsEditor *editor = GIMP_TOOL_OPTIONS_EDITOR (data);
if (GTK_WIDGET_SENSITIVE (editor->reset_button))
gimp_button_extended_clicked (GIMP_BUTTON (editor->reset_button),
GDK_SHIFT_MASK);
GimpEditor *editor = GIMP_EDITOR (data);
GtkWidget *qbox;
qbox = gimp_query_boolean_box (_("Reset Tool Options"),
GTK_WIDGET (editor),
gimp_standard_help_func,
GIMP_HELP_TOOL_OPTIONS_RESET,
GTK_STOCK_DIALOG_QUESTION,
_("Do you really want to reset all "
"tool options to default values?"),
GIMP_STOCK_RESET, GTK_STOCK_CANCEL,
G_OBJECT (editor), "unmap",
tool_options_reset_all_callback,
editor->ui_manager->gimp);
gtk_widget_show (qbox);
}
......
......@@ -47,7 +47,7 @@ static void tool_options_menu_update_presets (GimpUIManager *manager,
guint merge_id,
const gchar *ui_path,
const gchar *menu_path,
const gchar *action_prefix,
const gchar *which_action,
GimpContainer *presets);
......@@ -110,23 +110,19 @@ tool_options_menu_update_after (GimpUIManager *manager,
GUINT_TO_POINTER (merge_id));
tool_options_menu_update_presets (manager, merge_id, ui_path,
"tool-options-save-menu",
"tool-options-save-",
"Save", "save",
tool_info->options_presets);
tool_options_menu_update_presets (manager, merge_id, ui_path,
"tool-options-restore-menu",
"tool-options-restore-",
"Restore", "restore",
tool_info->options_presets);
tool_options_menu_update_presets (manager, merge_id, ui_path,
"tool-options-rename-menu",
"tool-options-rename-",
"Rename", "rename",
tool_info->options_presets);
tool_options_menu_update_presets (manager, merge_id, ui_path,
"tool-options-delete-menu",
"tool-options-delete-",
"Delete", "delete",
tool_info->options_presets);
gtk_ui_manager_ensure_update (GTK_UI_MANAGER (manager));
......@@ -137,11 +133,11 @@ tool_options_menu_update_presets (GimpUIManager *manager,
guint merge_id,
const gchar *ui_path,
const gchar *menu_path,
const gchar *action_prefix,
const gchar *which_action,
GimpContainer *presets)
{
gint n_children;
gint i;
gint n_children;
gint i;
n_children = gimp_container_num_children (presets);
......@@ -150,8 +146,8 @@ tool_options_menu_update_presets (GimpUIManager *manager,
gchar *action_name;
gchar *path;
action_name = g_strdup_printf ("tool-options-%s-%03d", which_action, i);
path = g_strdup_printf ("%s/%s", ui_path, menu_path);
action_name = g_strdup_printf ("%s%03d", action_prefix, i);
gtk_ui_manager_add_ui (GTK_UI_MANAGER (manager), merge_id,
path, action_name, action_name,
......
......@@ -88,6 +88,10 @@ enum
static void gimp_colormap_editor_class_init (GimpColormapEditorClass *klass);
static void gimp_colormap_editor_init (GimpColormapEditor *colormap_editor);
static GObject * gimp_colormap_editor_constructor (GType type,
guint n_params,
GObjectConstructParam *params);
static void gimp_colormap_editor_destroy (GtkObject *object);
static void gimp_colormap_editor_unmap (GtkWidget *widget);
......@@ -127,11 +131,6 @@ static gboolean gimp_colormap_hex_entry_focus_out (GtkEntry *entry,
static void gimp_colormap_edit_clicked (GtkWidget *widget,
GimpColormapEditor *editor);
static void gimp_colormap_add_clicked (GtkWidget *widget,
GimpColormapEditor *editor);
static void gimp_colormap_add_ext_clicked (GtkWidget *widget,
GdkModifierType state,
GimpColormapEditor *editor);
static void gimp_colormap_image_mode_changed (GimpImage *gimage,
GimpColormapEditor *editor);
......@@ -148,41 +147,38 @@ static GimpImageEditorClass *parent_class = NULL;
GType
gimp_colormap_editor_get_type (void)
{
static GType gcd_type = 0;
static GType type = 0;
if (! gcd_type)
if (! type)
{
static const GTypeInfo gcd_info =
static const GTypeInfo info =
{
sizeof (GimpColormapEditorClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_colormap_editor_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpColormapEditor),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_colormap_editor_init,
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_colormap_editor_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpColormapEditor),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_colormap_editor_init,
};
gcd_type = g_type_register_static (GIMP_TYPE_IMAGE_EDITOR,
"GimpColormapEditor",
&gcd_info, 0);
type = g_type_register_static (GIMP_TYPE_IMAGE_EDITOR,
"GimpColormapEditor",
&info, 0);
}
return gcd_type;
return type;
}
static void
gimp_colormap_editor_class_init (GimpColormapEditorClass* klass)
{
GtkObjectClass *object_class;
GtkWidgetClass *widget_class;
GimpImageEditorClass *image_editor_class;
object_class = GTK_OBJECT_CLASS (klass);
widget_class = GTK_WIDGET_CLASS (klass);
image_editor_class = GIMP_IMAGE_EDITOR_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GimpImageEditorClass *image_editor_class = GIMP_IMAGE_EDITOR_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
......@@ -196,7 +192,9 @@ gimp_colormap_editor_class_init (GimpColormapEditorClass* klass)
G_TYPE_NONE, 1,
GDK_TYPE_MODIFIER_TYPE);
object_class->destroy = gimp_colormap_editor_destroy;
object_class->constructor = gimp_colormap_editor_constructor;
gtk_object_class->destroy = gimp_colormap_editor_destroy;
widget_class->unmap = gimp_colormap_editor_unmap;
......@@ -208,8 +206,6 @@ gimp_colormap_editor_class_init (GimpColormapEditorClass* klass)
static void
gimp_colormap_editor_init (GimpColormapEditor *editor)
{
gchar *str;
editor->col_index = 0;
editor->dnd_col_index = 0;
editor->palette = NULL;
......@@ -220,6 +216,20 @@ gimp_colormap_editor_init (GimpColormapEditor *editor)
editor->index_spinbutton = NULL;
editor->color_entry = NULL;
editor->color_notebook = NULL;
}
static GObject *
gimp_colormap_editor_constructor (GType type,
guint n_params,
GObjectConstructParam *params)
{
GObject *object;
GimpColormapEditor *editor;
gchar *str;
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
editor = GIMP_COLORMAP_EDITOR (object);
editor->edit_button =
gimp_editor_add_button (GIMP_EDITOR (editor),
......@@ -232,13 +242,16 @@ gimp_colormap_editor_init (GimpColormapEditor *editor)
str = g_strdup_printf (_("Add Color from FG\n%s from BG"),
gimp_get_mod_name_control ());
editor->add_button =
gimp_editor_add_button (GIMP_EDITOR (editor),
GTK_STOCK_ADD, str,
GIMP_HELP_INDEXED_PALETTE_ADD,
G_CALLBACK (gimp_colormap_add_clicked),
G_CALLBACK (gimp_colormap_add_ext_clicked),
editor);
gimp_editor_add_action_button (GIMP_EDITOR (editor), "colormap-editor",
"colormap-editor-add-color-from-fg",
"colormap-editor-add-color-from-bg",
GDK_CONTROL_MASK,
NULL);
gimp_help_set_help_data (editor->add_button, str,
GIMP_HELP_INDEXED_PALETTE_ADD);
g_free (str);
return object;
}
static void
......@@ -929,36 +942,6 @@ gimp_colormap_edit_clicked (GtkWidget *widget,
}
}
static void
gimp_colormap_add_clicked (GtkWidget *widget,
GimpColormapEditor *editor)
{
gimp_colormap_add_ext_clicked (widget, 0, editor);
}
static void
gimp_colormap_add_ext_clicked (GtkWidget *widget,
GdkModifierType state,
GimpColormapEditor *editor)
{
GimpImage *gimage = GIMP_IMAGE_EDITOR (editor)->gimage;
if (gimage && gimage->num_cols < 256)
{
GimpContext *context;
GimpRGB color;
context = gimp_get_user_context (gimage->gimp);
if (state & GDK_CONTROL_MASK)
gimp_context_get_background (context, &color);
else
gimp_context_get_foreground (context, &color);
gimp_image_add_colormap_entry (gimage, &color);
}
}
static void
gimp_colormap_image_mode_changed (GimpImage *gimage,
GimpColormapEditor *editor)
......
......@@ -51,6 +51,10 @@ static void gimp_tool_options_editor_class_init (GimpToolOptionsEditorC
static void gimp_tool_options_editor_init (GimpToolOptionsEditor *editor);
static void gimp_tool_options_editor_docked_iface_init (GimpDockedInterface *docked_iface);
static GObject * gimp_tool_options_editor_constructor (GType type,
guint n_params,
GObjectConstructParam *params);
static void gimp_tool_options_editor_destroy (GtkObject *object);
static GtkWidget *gimp_tool_options_editor_get_preview (GimpDocked *docked,
......@@ -64,12 +68,6 @@ static void gimp_tool_options_editor_restore_clicked (GtkWidget *w
GimpToolOptionsEditor *editor);
static void gimp_tool_options_editor_delete_clicked (GtkWidget *widget,
GimpToolOptionsEditor *editor);
static void gimp_tool_options_editor_reset_clicked (GtkWidget *widget,
GimpToolOptionsEditor *editor);
static void gimp_tool_options_editor_reset_ext_clicked (GtkWidget *widget,
GdkModifierType state,
GimpToolOptionsEditor *editor);
static void gimp_tool_options_editor_drop_tool (GtkWidget *widget,
GimpViewable *viewable,
gpointer data);
......@@ -126,18 +124,62 @@ gimp_tool_options_editor_get_type (void)
static void
gimp_tool_options_editor_class_init (GimpToolOptionsEditorClass *klass)
{
GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
object_class->destroy = gimp_tool_options_editor_destroy;
object_class->constructor = gimp_tool_options_editor_constructor;
gtk_object_class->destroy = gimp_tool_options_editor_destroy;