app, menus: Colormap dockable now shows a delete button.

This comes with a "colormap-delete-color" into the "colormap" action group. The
action/button will be insensitive when the selected color is used in the image,
since it is only possible to delete unused colors.
This commit is contained in:
Jehan 2023-10-09 01:07:01 +02:00
parent dbaa8b6a1c
commit c8de818349
9 changed files with 161 additions and 35 deletions

View File

@ -30,6 +30,7 @@
#include "core/gimpimage-colormap.h"
#include "widgets/gimpactiongroup.h"
#include "widgets/gimpcolormapeditor.h"
#include "widgets/gimphelp-ids.h"
#include "actions.h"
@ -45,6 +46,12 @@ static const GimpActionEntry colormap_actions[] =
NC_("colormap-action", "_Edit Color..."), NULL, { NULL },
NC_("colormap-action", "Edit this color"),
colormap_edit_color_cmd_callback,
GIMP_HELP_INDEXED_PALETTE_EDIT },
{ "colormap-delete-color", GIMP_ICON_EDIT_DELETE,
NC_("colormap-action", "_Delete Color..."), NULL, { NULL },
NC_("colormap-action", "Delete this color"),
colormap_delete_color_cmd_callback,
GIMP_HELP_INDEXED_PALETTE_EDIT }
};
@ -112,13 +119,14 @@ void
colormap_actions_update (GimpActionGroup *group,
gpointer data)
{
GimpImage *image = action_data_get_image (data);
GimpContext *context = action_data_get_context (data);
gboolean indexed = FALSE;
gboolean drawable_indexed = FALSE;
gint num_colors = 0;
GimpRGB fg;
GimpRGB bg;
GimpColormapEditor *editor = GIMP_COLORMAP_EDITOR (data);
GimpImage *image = action_data_get_image (data);
GimpContext *context = action_data_get_context (data);
gboolean indexed = FALSE;
gboolean drawable_indexed = FALSE;
gint num_colors = 0;
GimpRGB fg;
GimpRGB bg;
if (image)
{
@ -150,6 +158,9 @@ colormap_actions_update (GimpActionGroup *group,
SET_SENSITIVE ("colormap-edit-color",
indexed && num_colors > 0);
SET_SENSITIVE ("colormap-delete-color",
indexed && num_colors > 0 &&
gimp_colormap_editor_is_color_deletable (editor));
SET_SENSITIVE ("colormap-add-color-from-fg",
indexed && num_colors < 256);

View File

@ -46,6 +46,16 @@ colormap_edit_color_cmd_callback (GimpAction *action,
gimp_colormap_editor_edit_color (editor);
}
void
colormap_delete_color_cmd_callback (GimpAction *action,
GVariant *value,
gpointer data)
{
GimpColormapEditor *editor = GIMP_COLORMAP_EDITOR (data);
gimp_colormap_editor_delete_color (editor);
}
void
colormap_add_color_cmd_callback (GimpAction *action,
GVariant *value,

View File

@ -22,6 +22,9 @@
void colormap_edit_color_cmd_callback (GimpAction *action,
GVariant *value,
gpointer data);
void colormap_delete_color_cmd_callback (GimpAction *action,
GVariant *value,
gpointer data);
void colormap_add_color_cmd_callback (GimpAction *action,
GVariant *value,
gpointer data);

View File

@ -43,29 +43,33 @@
#include "gimp-intl.h"
static void gimp_colormap_editor_docked_iface_init (GimpDockedInterface *face);
static void gimp_colormap_editor_docked_iface_init (GimpDockedInterface *face);
static void gimp_colormap_editor_constructed (GObject *object);
static void gimp_colormap_editor_dispose (GObject *object);
static void gimp_colormap_editor_constructed (GObject *object);
static void gimp_colormap_editor_dispose (GObject *object);
static void gimp_colormap_editor_unmap (GtkWidget *widget);
static void gimp_colormap_editor_unmap (GtkWidget *widget);
static void gimp_colormap_editor_set_context (GimpDocked *docked,
GimpContext *context);
static void gimp_colormap_editor_set_context (GimpDocked *docked,
GimpContext *context);
static void gimp_colormap_editor_color_update (GimpColorDialog *dialog,
const GimpRGB *color,
GimpColorDialogState state,
GimpColormapEditor *editor);
static void gimp_colormap_editor_color_update (GimpColorDialog *dialog,
const GimpRGB *color,
GimpColorDialogState state,
GimpColormapEditor *editor);
static gboolean gimp_colormap_editor_entry_button_press (GtkWidget *widget,
GdkEvent *event,
gpointer user_data);
static gboolean gimp_colormap_editor_entry_popup (GtkWidget *widget,
gpointer user_data);
static void gimp_colormap_editor_color_clicked (GimpColormapEditor *editor,
GimpPaletteEntry *entry,
GdkModifierType state);
static void gimp_colormap_editor_notify_index (GimpColormapSelection *selection,
const GParamSpec *pspec,
GimpColormapEditor *editor);
static gboolean gimp_colormap_editor_entry_button_press (GtkWidget *widget,
GdkEvent *event,
gpointer user_data);
static gboolean gimp_colormap_editor_entry_popup (GtkWidget *widget,
gpointer user_data);
static void gimp_colormap_editor_color_clicked (GimpColormapEditor *editor,
GimpPaletteEntry *entry,
GdkModifierType state);
G_DEFINE_TYPE_WITH_CODE (GimpColormapEditor, gimp_colormap_editor,
GIMP_TYPE_IMAGE_EDITOR,
@ -123,6 +127,9 @@ gimp_colormap_editor_constructed (GObject *object)
gimp_editor_add_action_button (GIMP_EDITOR (editor), "colormap",
"colormap-edit-color",
NULL);
gimp_editor_add_action_button (GIMP_EDITOR (editor), "colormap",
"colormap-delete-color",
NULL);
gimp_editor_add_action_button (GIMP_EDITOR (editor), "colormap",
"colormap-add-color-from-fg",
@ -193,6 +200,9 @@ gimp_colormap_editor_set_context (GimpDocked *docked,
g_signal_connect (editor->selection, "popup-menu",
G_CALLBACK (gimp_colormap_editor_entry_popup),
editor);
g_signal_connect (editor->selection, "notify::index",
G_CALLBACK (gimp_colormap_editor_notify_index),
editor);
}
}
@ -277,6 +287,43 @@ gimp_colormap_editor_edit_color (GimpColormapEditor *editor)
gtk_window_present (GTK_WINDOW (editor->color_dialog));
}
void
gimp_colormap_editor_delete_color (GimpColormapEditor *editor)
{
GimpColormapSelection *selection;
GimpImage *image;
gint index;
g_return_if_fail (GIMP_IS_COLORMAP_EDITOR (editor));
g_return_if_fail (gimp_colormap_editor_is_color_deletable (editor));
image = GIMP_IMAGE_EDITOR (editor)->image;
selection = GIMP_COLORMAP_SELECTION (editor->selection);
index = gimp_colormap_selection_get_index (selection, NULL);
gimp_image_delete_colormap_entry (image, index, TRUE);
}
gboolean
gimp_colormap_editor_is_color_deletable (GimpColormapEditor *editor)
{
GimpColormapSelection *selection;
GimpImage *image;
gint index;
g_return_val_if_fail (GIMP_IS_COLORMAP_EDITOR (editor), FALSE);
image = GIMP_IMAGE_EDITOR (editor)->image;
selection = GIMP_COLORMAP_SELECTION (editor->selection);
index = gimp_colormap_selection_get_index (selection, NULL);
if (index == -1)
/* No colormap. */
return FALSE;
else
return ! gimp_image_colormap_is_index_used (image, index);
}
gint
gimp_colormap_editor_get_index (GimpColormapEditor *editor,
const GimpRGB *search)
@ -407,3 +454,16 @@ gimp_colormap_editor_color_clicked (GimpColormapEditor *editor,
else
gimp_context_set_foreground (image_editor->context, &entry->color);
}
static void
gimp_colormap_editor_notify_index (GimpColormapSelection *selection,
const GParamSpec *pspec,
GimpColormapEditor *editor)
{
g_return_if_fail (GIMP_IS_COLORMAP_EDITOR (editor));
gimp_editor_set_action_sensitive (GIMP_EDITOR (editor), "colormap",
"colormap-delete-color",
gimp_colormap_editor_is_color_deletable (editor),
_("The color is used in this indexed image"));
}

View File

@ -46,19 +46,21 @@ struct _GimpColormapEditorClass
};
GType gimp_colormap_editor_get_type (void) G_GNUC_CONST;
GType gimp_colormap_editor_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_colormap_editor_new (GimpMenuFactory *menu_factory);
GtkWidget * gimp_colormap_editor_new (GimpMenuFactory *menu_factory);
void gimp_colormap_editor_edit_color (GimpColormapEditor *editor);
void gimp_colormap_editor_edit_color (GimpColormapEditor *editor);
void gimp_colormap_editor_delete_color (GimpColormapEditor *editor);
gboolean gimp_colormap_editor_is_color_deletable (GimpColormapEditor *editor);
gint gimp_colormap_editor_get_index (GimpColormapEditor *editor,
const GimpRGB *search);
gboolean gimp_colormap_editor_set_index (GimpColormapEditor *editor,
gint index,
GimpRGB *color);
gint gimp_colormap_editor_get_index (GimpColormapEditor *editor,
const GimpRGB *search);
gboolean gimp_colormap_editor_set_index (GimpColormapEditor *editor,
gint index,
GimpRGB *color);
gint gimp_colormap_editor_max_index (GimpColormapEditor *editor);
gint gimp_colormap_editor_max_index (GimpColormapEditor *editor);
#endif /* __GIMP_COLORMAP_EDITOR_H__ */

View File

@ -53,7 +53,8 @@
enum
{
PROP_0,
PROP_CONTEXT
PROP_CONTEXT,
PROP_INDEX
};
enum
@ -165,6 +166,10 @@ gimp_colormap_selection_class_init (GimpColormapSelectionClass* klass)
GIMP_TYPE_CONTEXT,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class, PROP_INDEX,
g_param_spec_int ("index", NULL, NULL,
0, G_MAXINT, 0,
GIMP_PARAM_READABLE));
}
static void
@ -281,6 +286,9 @@ gimp_colormap_selection_get_property (GObject *object,
case PROP_CONTEXT:
g_value_set_object (value, selection->context);
break;
case PROP_INDEX:
g_value_set_int (value, selection->col_index);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@ -429,6 +437,7 @@ gimp_colormap_selection_set_index (GimpColormapSelection *selection,
selection->col_index = index;
g_object_notify (G_OBJECT (selection), "index");
gimp_palette_view_select_entry (GIMP_PALETTE_VIEW (selection->view),
gimp_palette_get_entry (palette, index));

View File

@ -774,6 +774,31 @@ gimp_editor_add_action_button (GimpEditor *editor,
return button;
}
void
gimp_editor_set_action_sensitive (GimpEditor *editor,
const gchar *group_name,
const gchar *action_name,
gboolean sensitive,
const gchar *reason)
{
GimpActionGroup *group;
GimpAction *action;
g_return_val_if_fail (GIMP_IS_EDITOR (editor), NULL);
g_return_val_if_fail (action_name != NULL, NULL);
g_return_val_if_fail (editor->priv->ui_manager != NULL, NULL);
group = gimp_ui_manager_get_action_group (editor->priv->ui_manager,
group_name);
g_return_val_if_fail (group != NULL, NULL);
action = gimp_action_group_get_action (group, action_name);
g_return_val_if_fail (action != NULL, NULL);
gimp_action_set_sensitive (action, sensitive, reason);
}
void
gimp_editor_set_show_name (GimpEditor *editor,
gboolean show)

View File

@ -85,6 +85,11 @@ GtkWidget * gimp_editor_add_action_button (GimpEditor *editor,
const gchar *group_name,
const gchar *action_name,
...) G_GNUC_NULL_TERMINATED;
void gimp_editor_set_action_sensitive (GimpEditor *editor,
const gchar *group_name,
const gchar *action_name,
gboolean sensitive,
const gchar *reason);
void gimp_editor_set_show_name (GimpEditor *editor,
gboolean show);

View File

@ -3,6 +3,7 @@
<interface>
<menu id="/colormap-popup">
<item><attribute name="action">colormap.colormap-edit-color</attribute></item>
<item><attribute name="action">colormap.colormap-delete-color</attribute></item>
<item><attribute name="action">colormap.colormap-add-color-from-fg</attribute></item>
<item><attribute name="action">colormap.colormap-add-color-from-bg</attribute></item>
<section>