Commit 4c070aff authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

app/widgets/gimppaletteeditor.[ch] app/gui/palette-editor-commands.[ch]

2003-05-26  Michael Natterer  <mitch@gimp.org>

	* app/widgets/gimppaletteeditor.[ch]
	* app/gui/palette-editor-commands.[ch]
	* app/gui/palette-editor-menu.c: started to clean up the palette
	editor: added buttons for all menu items and menu items for all
	buttons. Improved selected palette entry handling. Moved all code
	to gimppaletteeditor.c and call it from the menu callbacks.  Lots
	of cleanup (unfinished).
parent 2f31d12f
2003-05-26 Michael Natterer <mitch@gimp.org>
* app/widgets/gimppaletteeditor.[ch]
* app/gui/palette-editor-commands.[ch]
* app/gui/palette-editor-menu.c: started to clean up the palette
editor: added buttons for all menu items and menu items for all
buttons. Improved selected palette entry handling. Moved all code
to gimppaletteeditor.c and call it from the menu callbacks. Lots
of cleanup (unfinished).
2003-05-26 Pedro Gimeno <pggimeno@wanadoo.es>
* app/tools/gimpeditselectiontool.c (selection_transform_segs):
......@@ -20,31 +20,12 @@
#include <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
#include "gui-types.h"
#include "core/gimp.h"
#include "core/gimpcontext.h"
#include "core/gimppalette.h"
#include "widgets/gimppaletteeditor.h"
#include "widgets/gimptoolbox-color-area.h"
#include "color-notebook.h"
#include "dialogs.h"
#include "palette-editor-commands.h"
#include "gimp-intl.h"
/* local function prototypes */
static void palette_editor_color_notebook_callback (ColorNotebook *color_notebook,
const GimpRGB *color,
ColorNotebookState state,
gpointer data);
/* public functions */
......@@ -53,26 +34,10 @@ palette_editor_new_color_cmd_callback (GtkWidget *widget,
gpointer data,
guint action)
{
GimpPaletteEditor *editor;
GimpPalette *palette;
GimpContext *user_context;
GimpRGB color;
editor = GIMP_PALETTE_EDITOR (data);
palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data);
if (! palette)
return;
user_context = gimp_get_user_context (GIMP_DATA_EDITOR (editor)->gimp);
if (active_color == FOREGROUND)
gimp_context_get_foreground (user_context, &color);
else if (active_color == BACKGROUND)
gimp_context_get_background (user_context, &color);
GimpPaletteEditor *editor = GIMP_PALETTE_EDITOR (data);
editor->color = gimp_palette_add_entry (palette, NULL, &color);
if (GTK_WIDGET_SENSITIVE (editor->edit_button))
gtk_button_clicked (GTK_BUTTON (editor->edit_button));
}
void
......@@ -80,44 +45,10 @@ palette_editor_edit_color_cmd_callback (GtkWidget *widget,
gpointer data,
guint action)
{
GimpPaletteEditor *editor;
GimpPalette *palette;
editor = GIMP_PALETTE_EDITOR (data);
palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data);
if (! (palette && editor->color))
return;
if (! editor->color_notebook)
{
editor->color_notebook =
color_notebook_viewable_new (GIMP_VIEWABLE (palette),
_("Edit Palette Color"),
GTK_STOCK_SELECT_COLOR,
_("Edit Color Palette Entry"),
global_dialog_factory,
"gimp-palette-editor-color-dialog",
(const GimpRGB *) &editor->color->color,
palette_editor_color_notebook_callback,
editor,
FALSE, FALSE);
editor->color_notebook_active = TRUE;
}
else
{
if (! editor->color_notebook_active)
{
color_notebook_set_viewable (editor->color_notebook,
GIMP_VIEWABLE (palette));
color_notebook_show (editor->color_notebook);
editor->color_notebook_active = TRUE;
}
color_notebook_set_color (editor->color_notebook,
&editor->color->color);
}
GimpPaletteEditor *editor = GIMP_PALETTE_EDITOR (data);
if (GTK_WIDGET_SENSITIVE (editor->edit_button))
gtk_button_clicked (GTK_BUTTON (editor->edit_button));
}
void
......@@ -125,64 +56,41 @@ palette_editor_delete_color_cmd_callback (GtkWidget *widget,
gpointer data,
guint action)
{
GimpPaletteEditor *editor;
GimpPalette *palette;
editor = GIMP_PALETTE_EDITOR (data);
palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data);
GimpPaletteEditor *editor = GIMP_PALETTE_EDITOR (data);
if (GTK_WIDGET_SENSITIVE (editor->delete_button))
gtk_button_clicked (GTK_BUTTON (editor->delete_button));
}
if (! (palette && editor->color))
return;
void
palette_editor_zoom_in_cmd_callback (GtkWidget *widget,
gpointer data,
guint action)
{
GimpPaletteEditor *editor = GIMP_PALETTE_EDITOR (data);
gimp_palette_delete_entry (palette, editor->color);
if (GTK_WIDGET_SENSITIVE (editor->zoom_in_button))
gtk_button_clicked (GTK_BUTTON (editor->zoom_in_button));
}
void
palette_editor_zoom_out_cmd_callback (GtkWidget *widget,
gpointer data,
guint action)
{
GimpPaletteEditor *editor = GIMP_PALETTE_EDITOR (data);
/* private functions */
if (GTK_WIDGET_SENSITIVE (editor->zoom_out_button))
gtk_button_clicked (GTK_BUTTON (editor->zoom_out_button));
}
static void
palette_editor_color_notebook_callback (ColorNotebook *color_notebook,
const GimpRGB *color,
ColorNotebookState state,
gpointer data)
void
palette_editor_zoom_all_cmd_callback (GtkWidget *widget,
gpointer data,
guint action)
{
GimpPaletteEditor *editor;
GimpPalette *palette;
GimpContext *user_context;
editor = GIMP_PALETTE_EDITOR (data);
palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data);
user_context = gimp_get_user_context (GIMP_DATA_EDITOR (editor)->gimp);
switch (state)
{
case COLOR_NOTEBOOK_UPDATE:
break;
case COLOR_NOTEBOOK_OK:
if (editor->color)
{
editor->color->color = *color;
/* Update either foreground or background colors */
if (active_color == FOREGROUND)
gimp_context_set_foreground (user_context, color);
else if (active_color == BACKGROUND)
gimp_context_set_background (user_context, color);
gimp_data_dirty (GIMP_DATA (palette));
}
/* Fallthrough */
case COLOR_NOTEBOOK_CANCEL:
if (editor->color_notebook_active)
{
color_notebook_hide (editor->color_notebook);
editor->color_notebook_active = FALSE;
}
}
GimpPaletteEditor *editor = GIMP_PALETTE_EDITOR (data);
if (GTK_WIDGET_SENSITIVE (editor->zoom_all_button))
gtk_button_clicked (GTK_BUTTON (editor->zoom_all_button));
}
......@@ -30,5 +30,15 @@ void palette_editor_delete_color_cmd_callback (GtkWidget *widget,
gpointer data,
guint action);
void palette_editor_zoom_in_cmd_callback (GtkWidget *widget,
gpointer data,
guint action);
void palette_editor_zoom_out_cmd_callback (GtkWidget *widget,
gpointer data,
guint action);
void palette_editor_zoom_all_cmd_callback (GtkWidget *widget,
gpointer data,
guint action);
#endif /* __PALETTE_EDITOR_COMMANDS_H__ */
......@@ -20,31 +20,12 @@
#include <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
#include "gui-types.h"
#include "core/gimp.h"
#include "core/gimpcontext.h"
#include "core/gimppalette.h"
#include "widgets/gimppaletteeditor.h"
#include "widgets/gimptoolbox-color-area.h"
#include "color-notebook.h"
#include "dialogs.h"
#include "palette-editor-commands.h"
#include "gimp-intl.h"
/* local function prototypes */
static void palette_editor_color_notebook_callback (ColorNotebook *color_notebook,
const GimpRGB *color,
ColorNotebookState state,
gpointer data);
/* public functions */
......@@ -53,26 +34,10 @@ palette_editor_new_color_cmd_callback (GtkWidget *widget,
gpointer data,
guint action)
{
GimpPaletteEditor *editor;
GimpPalette *palette;
GimpContext *user_context;
GimpRGB color;
editor = GIMP_PALETTE_EDITOR (data);
palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data);
if (! palette)
return;
user_context = gimp_get_user_context (GIMP_DATA_EDITOR (editor)->gimp);
if (active_color == FOREGROUND)
gimp_context_get_foreground (user_context, &color);
else if (active_color == BACKGROUND)
gimp_context_get_background (user_context, &color);
GimpPaletteEditor *editor = GIMP_PALETTE_EDITOR (data);
editor->color = gimp_palette_add_entry (palette, NULL, &color);
if (GTK_WIDGET_SENSITIVE (editor->edit_button))
gtk_button_clicked (GTK_BUTTON (editor->edit_button));
}
void
......@@ -80,44 +45,10 @@ palette_editor_edit_color_cmd_callback (GtkWidget *widget,
gpointer data,
guint action)
{
GimpPaletteEditor *editor;
GimpPalette *palette;
editor = GIMP_PALETTE_EDITOR (data);
palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data);
if (! (palette && editor->color))
return;
if (! editor->color_notebook)
{
editor->color_notebook =
color_notebook_viewable_new (GIMP_VIEWABLE (palette),
_("Edit Palette Color"),
GTK_STOCK_SELECT_COLOR,
_("Edit Color Palette Entry"),
global_dialog_factory,
"gimp-palette-editor-color-dialog",
(const GimpRGB *) &editor->color->color,
palette_editor_color_notebook_callback,
editor,
FALSE, FALSE);
editor->color_notebook_active = TRUE;
}
else
{
if (! editor->color_notebook_active)
{
color_notebook_set_viewable (editor->color_notebook,
GIMP_VIEWABLE (palette));
color_notebook_show (editor->color_notebook);
editor->color_notebook_active = TRUE;
}
color_notebook_set_color (editor->color_notebook,
&editor->color->color);
}
GimpPaletteEditor *editor = GIMP_PALETTE_EDITOR (data);
if (GTK_WIDGET_SENSITIVE (editor->edit_button))
gtk_button_clicked (GTK_BUTTON (editor->edit_button));
}
void
......@@ -125,64 +56,41 @@ palette_editor_delete_color_cmd_callback (GtkWidget *widget,
gpointer data,
guint action)
{
GimpPaletteEditor *editor;
GimpPalette *palette;
editor = GIMP_PALETTE_EDITOR (data);
palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data);
GimpPaletteEditor *editor = GIMP_PALETTE_EDITOR (data);
if (GTK_WIDGET_SENSITIVE (editor->delete_button))
gtk_button_clicked (GTK_BUTTON (editor->delete_button));
}
if (! (palette && editor->color))
return;
void
palette_editor_zoom_in_cmd_callback (GtkWidget *widget,
gpointer data,
guint action)
{
GimpPaletteEditor *editor = GIMP_PALETTE_EDITOR (data);
gimp_palette_delete_entry (palette, editor->color);
if (GTK_WIDGET_SENSITIVE (editor->zoom_in_button))
gtk_button_clicked (GTK_BUTTON (editor->zoom_in_button));
}
void
palette_editor_zoom_out_cmd_callback (GtkWidget *widget,
gpointer data,
guint action)
{
GimpPaletteEditor *editor = GIMP_PALETTE_EDITOR (data);
/* private functions */
if (GTK_WIDGET_SENSITIVE (editor->zoom_out_button))
gtk_button_clicked (GTK_BUTTON (editor->zoom_out_button));
}
static void
palette_editor_color_notebook_callback (ColorNotebook *color_notebook,
const GimpRGB *color,
ColorNotebookState state,
gpointer data)
void
palette_editor_zoom_all_cmd_callback (GtkWidget *widget,
gpointer data,
guint action)
{
GimpPaletteEditor *editor;
GimpPalette *palette;
GimpContext *user_context;
editor = GIMP_PALETTE_EDITOR (data);
palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data);
user_context = gimp_get_user_context (GIMP_DATA_EDITOR (editor)->gimp);
switch (state)
{
case COLOR_NOTEBOOK_UPDATE:
break;
case COLOR_NOTEBOOK_OK:
if (editor->color)
{
editor->color->color = *color;
/* Update either foreground or background colors */
if (active_color == FOREGROUND)
gimp_context_set_foreground (user_context, color);
else if (active_color == BACKGROUND)
gimp_context_set_background (user_context, color);
gimp_data_dirty (GIMP_DATA (palette));
}
/* Fallthrough */
case COLOR_NOTEBOOK_CANCEL:
if (editor->color_notebook_active)
{
color_notebook_hide (editor->color_notebook);
editor->color_notebook_active = FALSE;
}
}
GimpPaletteEditor *editor = GIMP_PALETTE_EDITOR (data);
if (GTK_WIDGET_SENSITIVE (editor->zoom_all_button))
gtk_button_clicked (GTK_BUTTON (editor->zoom_all_button));
}
......@@ -30,5 +30,15 @@ void palette_editor_delete_color_cmd_callback (GtkWidget *widget,
gpointer data,
guint action);
void palette_editor_zoom_in_cmd_callback (GtkWidget *widget,
gpointer data,
guint action);
void palette_editor_zoom_out_cmd_callback (GtkWidget *widget,
gpointer data,
guint action);
void palette_editor_zoom_all_cmd_callback (GtkWidget *widget,
gpointer data,
guint action);
#endif /* __PALETTE_EDITOR_COMMANDS_H__ */
......@@ -35,21 +35,33 @@
GimpItemFactoryEntry palette_editor_menu_entries[] =
{
{ { N_("/New Color"), NULL,
{ { N_("/New Color"), "",
palette_editor_new_color_cmd_callback, 0,
"<StockItem>", GTK_STOCK_NEW },
NULL,
NULL, NULL },
{ { N_("/Edit Color..."), NULL,
NULL, NULL, NULL },
{ { N_("/Edit Color..."), "",
palette_editor_edit_color_cmd_callback, 0,
"<StockItem>", GIMP_STOCK_EDIT },
NULL,
NULL, NULL },
{ { N_("/Delete Color"), NULL,
NULL, NULL, NULL },
{ { N_("/Delete Color"), "",
palette_editor_delete_color_cmd_callback, 0,
"<StockItem>", GTK_STOCK_DELETE },
NULL,
NULL, NULL }
NULL, NULL, NULL },
{ { "/---", NULL, NULL, 0, "<Separator>", NULL }, NULL, NULL, NULL },
{ { N_("/Zoom In"), "",
palette_editor_zoom_in_cmd_callback, 0,
"<StockItem>", GTK_STOCK_ZOOM_IN },
NULL, NULL, NULL },
{ { N_("/Zoom Out"), "",
palette_editor_zoom_out_cmd_callback, 0,
"<StockItem>", GTK_STOCK_ZOOM_OUT },
NULL, NULL, NULL },
{ { N_("/Zoom All"), "",
palette_editor_zoom_all_cmd_callback, 0,
"<StockItem>", GTK_STOCK_ZOOM_FIT },
NULL, NULL, NULL }
};
gint n_palette_editor_menu_entries = G_N_ELEMENTS (palette_editor_menu_entries);
......@@ -60,15 +72,25 @@ palette_editor_menu_update (GtkItemFactory *factory,
gpointer data)
{
GimpPaletteEditor *editor;
GimpDataEditor *data_editor;
gboolean editable = FALSE;
editor = GIMP_PALETTE_EDITOR (data);
editor = GIMP_PALETTE_EDITOR (data);
data_editor = GIMP_DATA_EDITOR (data);
if (data_editor->data && data_editor->data_editable)
editable = TRUE;
#define SET_SENSITIVE(menu,condition) \
gimp_item_factory_set_sensitive (factory, menu, (condition) != 0)
SET_SENSITIVE ("/New Color", TRUE);
SET_SENSITIVE ("/Edit Color...", editor->color);
SET_SENSITIVE ("/Delete Color", editor->color);
SET_SENSITIVE ("/New Color", editable);
SET_SENSITIVE ("/Edit Color...", editable && editor->color);
SET_SENSITIVE ("/Delete Color", editable && editor->color);
SET_SENSITIVE ("/Zoom In", data_editor->data);
SET_SENSITIVE ("/Zoom Out", data_editor->data);
SET_SENSITIVE ("/Zoom All", data_editor->data);
#undef SET_SENSITIVE
}
This diff is collapsed.
......@@ -53,18 +53,22 @@ struct _GimpPaletteEditor
GtkWidget *color_name;
GtkAdjustment *columns_data;
GtkWidget *new_button;
GtkWidget *edit_button;
GtkWidget *delete_button;
GtkWidget *zoom_in_button;
GtkWidget *zoom_out_button;
GtkWidget *zoom_all_button;
ColorNotebook *color_notebook;
gboolean color_notebook_active;
GimpPaletteEntry *color;
GimpPaletteEntry *dnd_color;
guint entry_sig_id;
gfloat zoom_factor; /* range from 0.1 to 4.0 */
gint col_width;
gint last_width;
gint columns;
gboolean freeze_update;
gboolean columns_valid;
};
......
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