[gimp] app: move the colormap editor color dialog code to GimpColormapEditor
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: move the colormap editor color dialog code to GimpColormapEditor
- Date: Thu, 21 Jun 2018 11:44:29 +0000 (UTC)
commit 5edc0306f9e09a112148307667e3c2e273d69c52
Author: Michael Natterer <mitch gimp org>
Date: Thu Jun 21 13:43:25 2018 +0200
app: move the colormap editor color dialog code to GimpColormapEditor
See commit below.
app/actions/colormap-commands.c | 97 +-----------------------------------
app/widgets/gimpcolormapeditor.c | 105 ++++++++++++++++++++++++++++++++++++---
app/widgets/gimpcolormapeditor.h | 18 ++++---
po/POTFILES.in | 1 -
4 files changed, 111 insertions(+), 110 deletions(-)
---
diff --git a/app/actions/colormap-commands.c b/app/actions/colormap-commands.c
index b996927919..3936cf0c30 100644
--- a/app/actions/colormap-commands.c
+++ b/app/actions/colormap-commands.c
@@ -20,9 +20,6 @@
#include <gegl.h>
#include <gtk/gtk.h>
-#include "libgimpcolor/gimpcolor.h"
-#include "libgimpwidgets/gimpwidgets.h"
-
#include "actions-types.h"
#include "core/gimpchannel-select.h"
@@ -30,23 +27,11 @@
#include "core/gimpimage.h"
#include "core/gimpimage-colormap.h"
-#include "widgets/gimpcolordialog.h"
#include "widgets/gimpcolormapeditor.h"
-#include "widgets/gimpdialogfactory.h"
#include "actions.h"
#include "colormap-commands.h"
-#include "gimp-intl.h"
-
-
-/* local function prototypes */
-
-static void colormap_edit_color_update (GimpColorDialog *dialog,
- const GimpRGB *color,
- GimpColorDialogState state,
- GimpColormapEditor *editor);
-
/* public functions */
@@ -54,60 +39,9 @@ void
colormap_edit_color_cmd_callback (GtkAction *action,
gpointer data)
{
- GimpColormapEditor *editor;
- GimpImage *image;
- const guchar *colormap;
- GimpRGB color;
- gchar *desc;
- return_if_no_image (image, data);
-
- editor = GIMP_COLORMAP_EDITOR (data);
-
- colormap = gimp_image_get_colormap (image);
-
- gimp_rgba_set_uchar (&color,
- colormap[editor->col_index * 3],
- colormap[editor->col_index * 3 + 1],
- colormap[editor->col_index * 3 + 2],
- 255);
-
- desc = g_strdup_printf (_("Edit colormap entry #%d"), editor->col_index);
-
- if (! editor->color_dialog)
- {
- editor->color_dialog =
- gimp_color_dialog_new (GIMP_VIEWABLE (image),
- action_data_get_context (data),
- _("Edit Colormap Entry"),
- GIMP_ICON_COLORMAP,
- desc,
- GTK_WIDGET (editor),
- gimp_dialog_factory_get_singleton (),
- "gimp-colormap-editor-color-dialog",
- (const GimpRGB *) &color,
- FALSE, FALSE);
-
- g_signal_connect (editor->color_dialog, "destroy",
- G_CALLBACK (gtk_widget_destroyed),
- &editor->color_dialog);
-
- g_signal_connect (editor->color_dialog, "update",
- G_CALLBACK (colormap_edit_color_update),
- editor);
- }
- else
- {
- gimp_viewable_dialog_set_viewable (GIMP_VIEWABLE_DIALOG (editor->color_dialog),
- GIMP_VIEWABLE (image),
- action_data_get_context (data));
- g_object_set (editor->color_dialog, "description", desc, NULL);
- gimp_color_dialog_set_color (GIMP_COLOR_DIALOG (editor->color_dialog),
- &color);
- }
-
- g_free (desc);
+ GimpColormapEditor *editor = GIMP_COLORMAP_EDITOR (data);
- gtk_window_present (GTK_WINDOW (editor->color_dialog));
+ gimp_colormap_editor_edit_color (editor);
}
void
@@ -154,30 +88,3 @@ colormap_to_selection_cmd_callback (GtkAction *action,
op,
FALSE, 0.0, 0.0);
}
-
-
-/* private functions */
-
-static void
-colormap_edit_color_update (GimpColorDialog *dialog,
- const GimpRGB *color,
- GimpColorDialogState state,
- GimpColormapEditor *editor)
-{
- GimpImage *image = GIMP_IMAGE_EDITOR (editor)->image;
-
- switch (state)
- {
- case GIMP_COLOR_DIALOG_UPDATE:
- break;
-
- case GIMP_COLOR_DIALOG_OK:
- gimp_image_set_colormap_entry (image, editor->col_index, color, TRUE);
- gimp_image_flush (image);
- /* Fall through */
-
- case GIMP_COLOR_DIALOG_CANCEL:
- gtk_widget_hide (editor->color_dialog);
- break;
- }
-}
diff --git a/app/widgets/gimpcolormapeditor.c b/app/widgets/gimpcolormapeditor.c
index 18ac42305b..c405f5183b 100644
--- a/app/widgets/gimpcolormapeditor.c
+++ b/app/widgets/gimpcolormapeditor.c
@@ -34,7 +34,9 @@
#include "core/gimpmarshal.h"
#include "core/gimppalette.h"
+#include "gimpcolordialog.h"
#include "gimpcolormapeditor.h"
+#include "gimpdialogfactory.h"
#include "gimpdnd.h"
#include "gimpdocked.h"
#include "gimpmenufactory.h"
@@ -107,6 +109,12 @@ static void gimp_colormap_image_colormap_changed (GimpImage *image,
gint ncol,
GimpColormapEditor *editor);
+static void gimp_colormap_editor_edit_color_update
+ (GimpColorDialog *dialog,
+ const GimpRGB *color,
+ GimpColorDialogState state,
+ GimpColormapEditor *editor);
+
G_DEFINE_TYPE_WITH_CODE (GimpColormapEditor, gimp_colormap_editor,
GIMP_TYPE_IMAGE_EDITOR,
@@ -258,11 +266,7 @@ gimp_colormap_editor_dispose (GObject *object)
{
GimpColormapEditor *editor = GIMP_COLORMAP_EDITOR (object);
- if (editor->color_dialog)
- {
- gtk_widget_destroy (editor->color_dialog);
- editor->color_dialog = NULL;
- }
+ g_clear_pointer (&editor->color_dialog, gtk_widget_destroy);
G_OBJECT_CLASS (parent_class)->dispose (object);
}
@@ -368,6 +372,71 @@ gimp_colormap_editor_new (GimpMenuFactory *menu_factory)
NULL);
}
+void
+gimp_colormap_editor_edit_color (GimpColormapEditor *editor)
+{
+ GimpImage *image;
+ const guchar *colormap;
+ GimpRGB color;
+ gchar *desc;
+ gint index;
+
+ g_return_if_fail (GIMP_IS_COLORMAP_EDITOR (editor));
+
+ image = GIMP_IMAGE_EDITOR (editor)->image;
+
+ if (! HAVE_COLORMAP (image))
+ return;
+
+ index = editor->col_index;
+
+ colormap = gimp_image_get_colormap (image);
+
+ gimp_rgba_set_uchar (&color,
+ colormap[index * 3],
+ colormap[index * 3 + 1],
+ colormap[index * 3 + 2],
+ 255);
+
+ desc = g_strdup_printf (_("Edit colormap entry #%d"), index);
+
+ if (! editor->color_dialog)
+ {
+ editor->color_dialog =
+ gimp_color_dialog_new (GIMP_VIEWABLE (image),
+ GIMP_IMAGE_EDITOR (editor)->context,
+ _("Edit Colormap Entry"),
+ GIMP_ICON_COLORMAP,
+ desc,
+ GTK_WIDGET (editor),
+ gimp_dialog_factory_get_singleton (),
+ "gimp-colormap-editor-color-dialog",
+ (const GimpRGB *) &color,
+ FALSE, FALSE);
+
+ g_signal_connect (editor->color_dialog, "destroy",
+ G_CALLBACK (gtk_widget_destroyed),
+ &editor->color_dialog);
+
+ g_signal_connect (editor->color_dialog, "update",
+ G_CALLBACK (gimp_colormap_editor_edit_color_update),
+ editor);
+ }
+ else
+ {
+ gimp_viewable_dialog_set_viewable (GIMP_VIEWABLE_DIALOG (editor->color_dialog),
+ GIMP_VIEWABLE (image),
+ GIMP_IMAGE_EDITOR (editor)->context);
+ g_object_set (editor->color_dialog, "description", desc, NULL);
+ gimp_color_dialog_set_color (GIMP_COLOR_DIALOG (editor->color_dialog),
+ &color);
+ }
+
+ g_free (desc);
+
+ gtk_window_present (GTK_WINDOW (editor->color_dialog));
+}
+
gint
gimp_colormap_editor_get_index (GimpColormapEditor *editor,
const GimpRGB *search)
@@ -375,7 +444,7 @@ gimp_colormap_editor_get_index (GimpColormapEditor *editor,
GimpImage *image;
gint index;
- g_return_val_if_fail (GIMP_IS_COLORMAP_EDITOR (editor), 01);
+ g_return_val_if_fail (GIMP_IS_COLORMAP_EDITOR (editor), 0);
image = GIMP_IMAGE_EDITOR (editor)->image;
@@ -687,3 +756,27 @@ gimp_colormap_image_colormap_changed (GimpImage *image,
if (ncol == editor->col_index || ncol == -1)
gimp_colormap_editor_update_entries (editor);
}
+
+static void
+gimp_colormap_editor_edit_color_update (GimpColorDialog *dialog,
+ const GimpRGB *color,
+ GimpColorDialogState state,
+ GimpColormapEditor *editor)
+{
+ GimpImage *image = GIMP_IMAGE_EDITOR (editor)->image;
+
+ switch (state)
+ {
+ case GIMP_COLOR_DIALOG_UPDATE:
+ break;
+
+ case GIMP_COLOR_DIALOG_OK:
+ gimp_image_set_colormap_entry (image, editor->col_index, color, TRUE);
+ gimp_image_flush (image);
+ /* Fall through */
+
+ case GIMP_COLOR_DIALOG_CANCEL:
+ gtk_widget_hide (editor->color_dialog);
+ break;
+ }
+}
diff --git a/app/widgets/gimpcolormapeditor.h b/app/widgets/gimpcolormapeditor.h
index cc5db57168..0a010e1aa0 100644
--- a/app/widgets/gimpcolormapeditor.h
+++ b/app/widgets/gimpcolormapeditor.h
@@ -54,17 +54,19 @@ 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);
-gint gimp_colormap_editor_get_index (GimpColormapEditor *editor,
- const GimpRGB *search);
-gboolean gimp_colormap_editor_set_index (GimpColormapEditor *editor,
- gint index,
- GimpRGB *color);
+void gimp_colormap_editor_edit_color (GimpColormapEditor *editor);
-gint gimp_colormap_editor_max_index (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_max_index (GimpColormapEditor *editor);
#endif /* __GIMP_COLORMAP_EDITOR_H__ */
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 10ad32cfc0..5754e6fcc9 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -20,7 +20,6 @@ app/actions/buffers-actions.c
app/actions/channels-actions.c
app/actions/channels-commands.c
app/actions/colormap-actions.c
-app/actions/colormap-commands.c
app/actions/context-actions.c
app/actions/context-commands.c
app/actions/cursor-info-actions.c
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]