palette-editor-actions.c 4.96 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
/* The GIMP -- an image manipulation program
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#include "config.h"

#include <gtk/gtk.h>

#include "libgimpwidgets/gimpwidgets.h"

#include "actions-types.h"

27 28 29
#include "core/gimp.h"
#include "core/gimpcontext.h"

30 31 32 33 34
#include "widgets/gimpactiongroup.h"
#include "widgets/gimphelp-ids.h"
#include "widgets/gimppaletteeditor.h"

#include "palette-editor-actions.h"
Michael Natterer's avatar
Michael Natterer committed
35
#include "palette-editor-commands.h"
36 37 38 39 40 41

#include "gimp-intl.h"


static GimpActionEntry palette_editor_actions[] =
{
42 43
  { "palette-editor-popup", GIMP_STOCK_PALETTE,
    N_("Palette Editor Menu"), NULL, NULL, NULL,
44
    GIMP_HELP_PALETTE_EDITOR_DIALOG },
45

46
  { "palette-editor-edit-color", GIMP_STOCK_EDIT,
47 48
    N_("_Edit Color..."), "",
    N_("Edit color"),
49 50 51
    G_CALLBACK (palette_editor_edit_color_cmd_callback),
    GIMP_HELP_PALETTE_EDITOR_EDIT },

52 53 54 55 56 57 58 59 60
  { "palette-editor-delete-color", GTK_STOCK_DELETE,
    N_("_Delete Color"), "",
    N_("Delete color"),
    G_CALLBACK (palette_editor_delete_color_cmd_callback),
    GIMP_HELP_PALETTE_EDITOR_DELETE }
};

static GimpEnumActionEntry palette_editor_new_actions[] =
{
61
  { "palette-editor-new-color-fg", GTK_STOCK_NEW,
62 63
    N_("New Color from _FG"), "",
    N_("New color from FG"),
64
    FALSE, FALSE,
65 66 67
    GIMP_HELP_PALETTE_EDITOR_NEW },

  { "palette-editor-new-color-bg", GTK_STOCK_NEW,
68 69
    N_("New Color from _BG"), "",
    N_("New color from BG"),
70
    TRUE, FALSE,
71 72
    GIMP_HELP_PALETTE_EDITOR_NEW }
};
73

74 75 76 77 78
static GimpEnumActionEntry palette_editor_zoom_actions[] =
{
  { "palette-editor-zoom-in", GTK_STOCK_ZOOM_IN,
    N_("Zoom _In"), "",
    N_("Zoom in"),
79
    GIMP_ZOOM_IN, FALSE,
80
    GIMP_HELP_PALETTE_EDITOR_ZOOM_IN },
81 82

  { "palette-editor-zoom-out", GTK_STOCK_ZOOM_OUT,
83 84
    N_("Zoom _Out"), "",
    N_("Zoom out"),
85
    GIMP_ZOOM_OUT, FALSE,
86 87 88
    GIMP_HELP_PALETTE_EDITOR_ZOOM_OUT },

  { "palette-editor-zoom-all", GTK_STOCK_ZOOM_FIT,
89 90
    N_("Zoom _All"), "",
    N_("Zoom all"),
91
    GIMP_ZOOM_TO /* abused */, FALSE,
92 93 94 95 96
    GIMP_HELP_PALETTE_EDITOR_ZOOM_ALL }
};


void
97
palette_editor_actions_setup (GimpActionGroup *group)
98 99 100
{
  gimp_action_group_add_actions (group,
                                 palette_editor_actions,
101
                                 G_N_ELEMENTS (palette_editor_actions));
102 103 104 105 106 107 108 109 110 111

  gimp_action_group_add_enum_actions (group,
                                      palette_editor_new_actions,
                                      G_N_ELEMENTS (palette_editor_new_actions),
                                      G_CALLBACK (palette_editor_new_color_cmd_callback));

  gimp_action_group_add_enum_actions (group,
                                      palette_editor_zoom_actions,
                                      G_N_ELEMENTS (palette_editor_zoom_actions),
                                      G_CALLBACK (palette_editor_zoom_cmd_callback));
112 113 114 115
}

void
palette_editor_actions_update (GimpActionGroup *group,
116
                               gpointer         user_data)
117
{
118 119
  GimpPaletteEditor *editor      = GIMP_PALETTE_EDITOR (user_data);
  GimpDataEditor    *data_editor = GIMP_DATA_EDITOR (user_data);
120 121
  GimpContext       *context;
  GimpData          *data;
122
  gboolean           editable    = FALSE;
123 124 125 126
  GimpRGB            fg;
  GimpRGB            bg;

  context = gimp_get_user_context (group->gimp);
127

128
  data = data_editor->data;
129

130 131 132 133 134 135 136 137 138 139 140
  if (data)
    {
      if (data_editor->data_editable)
        editable = TRUE;
    }

  if (context)
    {
      gimp_context_get_foreground (context, &fg);
      gimp_context_get_background (context, &bg);
    }
141 142 143

#define SET_SENSITIVE(action,condition) \
        gimp_action_group_set_action_sensitive (group, action, (condition) != 0)
144 145
#define SET_COLOR(action,color) \
        gimp_action_group_set_action_color (group, action, color, FALSE);
146 147

  SET_SENSITIVE ("palette-editor-edit-color",   editable && editor->color);
148 149
  SET_SENSITIVE ("palette-editor-delete-color", editable && editor->color);

150 151
  SET_SENSITIVE ("palette-editor-new-color-fg", editable);
  SET_SENSITIVE ("palette-editor-new-color-bg", editable);
152 153 154

  SET_COLOR ("palette-editor-new-color-fg", context ? &fg : NULL);
  SET_COLOR ("palette-editor-new-color-bg", context ? &bg : NULL);
155

156 157 158 159
  SET_SENSITIVE ("palette-editor-zoom-out", data);
  SET_SENSITIVE ("palette-editor-zoom-in",  data);
  SET_SENSITIVE ("palette-editor-zoom-all", data);

160
#undef SET_SENSITIVE
161
#undef SET_COLOR
162
}