Commit 1c1dd203 authored by Michael Natterer's avatar Michael Natterer 😴

app: move the palette editor color dialog code to GimpPaletteEditor

That's cleaner than having it in palette-editor-commands.c
parent ab9f70d9
......@@ -20,32 +20,16 @@
#include <gegl.h>
#include <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
#include "actions-types.h"
#include "core/gimp.h"
#include "core/gimpcontext.h"
#include "core/gimpdatafactory.h"
#include "core/gimppalette.h"
#include "widgets/gimpcolordialog.h"
#include "widgets/gimpdialogfactory.h"
#include "widgets/gimppaletteeditor.h"
#include "widgets/gimppaletteview.h"
#include "palette-editor-commands.h"
#include "gimp-intl.h"
/* local function prototypes */
static void palette_editor_edit_color_update (GimpColorDialog *dialog,
const GimpRGB *color,
GimpColorDialogState state,
GimpPaletteEditor *editor);
/* public functions */
......@@ -53,47 +37,9 @@ void
palette_editor_edit_color_cmd_callback (GtkAction *action,
gpointer data)
{
GimpPaletteEditor *editor = GIMP_PALETTE_EDITOR (data);
GimpDataEditor *data_editor = GIMP_DATA_EDITOR (data);
GimpPalette *palette;
if (! (data_editor->data_editable && editor->color))
return;
palette = GIMP_PALETTE (data_editor->data);
if (! editor->color_dialog)
{
editor->color_dialog =
gimp_color_dialog_new (GIMP_VIEWABLE (palette),
data_editor->context,
_("Edit Palette Color"),
GIMP_ICON_PALETTE,
_("Edit Color Palette Entry"),
GTK_WIDGET (editor),
gimp_dialog_factory_get_singleton (),
"gimp-palette-editor-color-dialog",
&editor->color->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 (palette_editor_edit_color_update),
editor);
}
else
{
gimp_viewable_dialog_set_viewable (GIMP_VIEWABLE_DIALOG (editor->color_dialog),
GIMP_VIEWABLE (palette),
data_editor->context);
gimp_color_dialog_set_color (GIMP_COLOR_DIALOG (editor->color_dialog),
&editor->color->color);
}
GimpPaletteEditor *editor = GIMP_PALETTE_EDITOR (data);
gtk_window_present (GTK_WINDOW (editor->color_dialog));
gimp_palette_editor_edit_color (editor);
}
void
......@@ -144,33 +90,3 @@ palette_editor_zoom_cmd_callback (GtkAction *action,
gimp_palette_editor_zoom (editor, (GimpZoomType) value);
}
/* private functions */
static void
palette_editor_edit_color_update (GimpColorDialog *dialog,
const GimpRGB *color,
GimpColorDialogState state,
GimpPaletteEditor *editor)
{
GimpPalette *palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data);
switch (state)
{
case GIMP_COLOR_DIALOG_UPDATE:
break;
case GIMP_COLOR_DIALOG_OK:
if (editor->color)
{
editor->color->color = *color;
gimp_data_dirty (GIMP_DATA (palette));
}
/* Fallthrough */
case GIMP_COLOR_DIALOG_CANCEL:
gtk_widget_hide (editor->color_dialog);
break;
}
}
......@@ -35,8 +35,10 @@
#include "core/gimpdatafactory.h"
#include "core/gimppalette.h"
#include "gimpcolordialog.h"
#include "gimpdnd.h"
#include "gimpdocked.h"
#include "gimpdialogfactory.h"
#include "gimphelp-ids.h"
#include "gimppaletteeditor.h"
#include "gimppaletteview.h"
......@@ -121,6 +123,10 @@ static void palette_editor_resize (GimpPaletteEditor *editor,
gint width,
gdouble zoom_factor);
static void palette_editor_scroll_top_left (GimpPaletteEditor *editor);
static void palette_editor_edit_color_update (GimpColorDialog *dialog,
const GimpRGB *color,
GimpColorDialogState state,
GimpPaletteEditor *editor);
G_DEFINE_TYPE_WITH_CODE (GimpPaletteEditor, gimp_palette_editor,
......@@ -301,11 +307,7 @@ gimp_palette_editor_dispose (GObject *object)
{
GimpPaletteEditor *editor = GIMP_PALETTE_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);
}
......@@ -452,6 +454,55 @@ gimp_palette_editor_new (GimpContext *context,
NULL);
}
void
gimp_palette_editor_edit_color (GimpPaletteEditor *editor)
{
GimpDataEditor *data_editor;
GimpPalette *palette;
g_return_if_fail (GIMP_IS_PALETTE_EDITOR (editor));
data_editor = GIMP_DATA_EDITOR (editor);
if (! (data_editor->data_editable && editor->color))
return;
palette = GIMP_PALETTE (gimp_data_editor_get_data (data_editor));
if (! editor->color_dialog)
{
editor->color_dialog =
gimp_color_dialog_new (GIMP_VIEWABLE (palette),
data_editor->context,
_("Edit Palette Color"),
GIMP_ICON_PALETTE,
_("Edit Color Palette Entry"),
GTK_WIDGET (editor),
gimp_dialog_factory_get_singleton (),
"gimp-palette-editor-color-dialog",
&editor->color->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 (palette_editor_edit_color_update),
editor);
}
else
{
gimp_viewable_dialog_set_viewable (GIMP_VIEWABLE_DIALOG (editor->color_dialog),
GIMP_VIEWABLE (palette),
data_editor->context);
gimp_color_dialog_set_color (GIMP_COLOR_DIALOG (editor->color_dialog),
&editor->color->color);
}
gtk_window_present (GTK_WINDOW (editor->color_dialog));
}
void
gimp_palette_editor_pick_color (GimpPaletteEditor *editor,
const GimpRGB *color,
......@@ -867,3 +918,30 @@ palette_editor_scroll_top_left (GimpPaletteEditor *palette_editor)
if (vadj)
gtk_adjustment_set_value (vadj, 0.0);
}
static void
palette_editor_edit_color_update (GimpColorDialog *dialog,
const GimpRGB *color,
GimpColorDialogState state,
GimpPaletteEditor *editor)
{
GimpPalette *palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data);
switch (state)
{
case GIMP_COLOR_DIALOG_UPDATE:
break;
case GIMP_COLOR_DIALOG_OK:
if (editor->color)
{
editor->color->color = *color;
gimp_data_dirty (GIMP_DATA (palette));
}
/* Fallthrough */
case GIMP_COLOR_DIALOG_CANCEL:
gtk_widget_hide (editor->color_dialog);
break;
}
}
......@@ -62,6 +62,7 @@ GType gimp_palette_editor_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_palette_editor_new (GimpContext *context,
GimpMenuFactory *menu_factory);
void gimp_palette_editor_edit_color (GimpPaletteEditor *editor);
void gimp_palette_editor_pick_color (GimpPaletteEditor *editor,
const GimpRGB *color,
GimpColorPickState pick_state);
......
......@@ -58,7 +58,6 @@ app/actions/layers-actions.c
app/actions/layers-commands.c
app/actions/mypaint-brushes-actions.c
app/actions/palette-editor-actions.c
app/actions/palette-editor-commands.c
app/actions/palettes-actions.c
app/actions/palettes-commands.c
app/actions/patterns-actions.c
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment