channels-actions.c 12.6 KB
Newer Older
1
/* GIMP - The GNU Image Manipulation Program
2 3
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
4
 * This program is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
7 8 9 10 11 12 13 14
 * (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
15
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
16 17 18 19
 */

#include "config.h"

20
#include <gegl.h>
21 22 23 24 25 26 27
#include <gtk/gtk.h>

#include "libgimpwidgets/gimpwidgets.h"

#include "actions-types.h"

#include "core/gimpimage.h"
28
#include "core/gimpitem.h"
29 30 31 32

#include "widgets/gimpactiongroup.h"
#include "widgets/gimpcomponenteditor.h"
#include "widgets/gimphelp-ids.h"
33

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

#include "gimp-intl.h"


42
static const GimpActionEntry channels_actions[] =
43
{
44
  { "channels-popup", GIMP_ICON_DIALOG_CHANNELS,
45
    NC_("channels-action", "Channels Menu"), NULL, NULL, NULL,
46
    GIMP_HELP_CHANNEL_DIALOG },
47

48
  { "channels-color-tag-menu", NULL,
49 50 51
    NC_("channels-action", "Color Tag"), NULL, NULL, NULL,
    GIMP_HELP_CHANNEL_COLOR_TAG },

52
  { "channels-edit-attributes", GIMP_ICON_EDIT,
53
    NC_("channels-action", "_Edit Channel Attributes..."), NULL,
54
    NC_("channels-action", "Edit the channel's name, color and opacity"),
55 56 57
    G_CALLBACK (channels_edit_attributes_cmd_callback),
    GIMP_HELP_CHANNEL_EDIT },

58
  { "channels-new", GIMP_ICON_DOCUMENT_NEW,
59
    NC_("channels-action", "_New Channel..."), NULL,
60
    NC_("channels-action", "Create a new channel"),
61 62 63
    G_CALLBACK (channels_new_cmd_callback),
    GIMP_HELP_CHANNEL_NEW },

64
  { "channels-new-last-values", GIMP_ICON_DOCUMENT_NEW,
65
    NC_("channels-action", "_New Channel"), NULL,
66
    NC_("channels-action", "Create a new channel with last used values"),
67
    G_CALLBACK (channels_new_last_vals_cmd_callback),
68 69
    GIMP_HELP_CHANNEL_NEW },

70
  { "channels-duplicate", GIMP_ICON_OBJECT_DUPLICATE,
71
    NC_("channels-action", "D_uplicate Channel"), NULL,
72 73
    NC_("channels-action",
        "Create a duplicate of this channel and add it to the image"),
74 75 76
    G_CALLBACK (channels_duplicate_cmd_callback),
    GIMP_HELP_CHANNEL_DUPLICATE },

77
  { "channels-delete", GIMP_ICON_EDIT_DELETE,
78
    NC_("channels-action", "_Delete Channel"), NULL,
79
    NC_("channels-action", "Delete this channel"),
80 81 82
    G_CALLBACK (channels_delete_cmd_callback),
    GIMP_HELP_CHANNEL_DELETE },

83
  { "channels-raise", GIMP_ICON_GO_UP,
84
    NC_("channels-action", "_Raise Channel"), NULL,
85
    NC_("channels-action", "Raise this channel one step in the channel stack"),
86 87 88
    G_CALLBACK (channels_raise_cmd_callback),
    GIMP_HELP_CHANNEL_RAISE },

89
  { "channels-raise-to-top", GIMP_ICON_GO_TOP,
90
    NC_("channels-action", "Raise Channel to _Top"), NULL,
91 92
    NC_("channels-action",
        "Raise this channel to the top of the channel stack"),
93 94 95
    G_CALLBACK (channels_raise_to_top_cmd_callback),
    GIMP_HELP_CHANNEL_RAISE_TO_TOP },

96
  { "channels-lower", GIMP_ICON_GO_DOWN,
97
    NC_("channels-action", "_Lower Channel"), NULL,
98
    NC_("channels-action", "Lower this channel one step in the channel stack"),
99 100 101
    G_CALLBACK (channels_lower_cmd_callback),
    GIMP_HELP_CHANNEL_LOWER },

102
  { "channels-lower-to-bottom", GIMP_ICON_GO_BOTTOM,
103
    NC_("channels-action", "Lower Channel to _Bottom"), NULL,
104 105
    NC_("channels-action",
        "Lower this channel to the bottom of the channel stack"),
106 107 108 109
    G_CALLBACK (channels_lower_to_bottom_cmd_callback),
    GIMP_HELP_CHANNEL_LOWER_TO_BOTTOM }
};

110 111
static const GimpToggleActionEntry channels_toggle_actions[] =
{
112
  { "channels-visible", GIMP_ICON_VISIBLE,
113
    NC_("channels-action", "Toggle Channel _Visibility"), NULL, NULL,
114 115 116 117
    G_CALLBACK (channels_visible_cmd_callback),
    FALSE,
    GIMP_HELP_CHANNEL_VISIBLE },

118
  { "channels-linked", GIMP_ICON_LINKED,
119
    NC_("channels-action", "Toggle Channel _Linked State"), NULL, NULL,
120 121 122 123
    G_CALLBACK (channels_linked_cmd_callback),
    FALSE,
    GIMP_HELP_CHANNEL_LINKED },

124
  { "channels-lock-content", NULL /* GIMP_ICON_LOCK */,
125
    NC_("channels-action", "L_ock Pixels of Channel"), NULL, NULL,
126 127 128 129
    G_CALLBACK (channels_lock_content_cmd_callback),
    FALSE,
    GIMP_HELP_CHANNEL_LOCK_PIXELS },

130
  { "channels-lock-position", GIMP_ICON_TOOL_MOVE,
131
    NC_("channels-action", "L_ock Position of Channel"), NULL, NULL,
132 133 134 135 136 137 138
    G_CALLBACK (channels_lock_position_cmd_callback),
    FALSE,
    GIMP_HELP_CHANNEL_LOCK_POSITION }
};

static const GimpEnumActionEntry channels_color_tag_actions[] =
{
139
  { "channels-color-tag-none", GIMP_ICON_EDIT_CLEAR,
140
    NC_("channels-action", "None"), NULL,
141
    NC_("channels-action", "Channel Color Tag: Clear"),
142 143 144 145
    GIMP_COLOR_TAG_NONE, FALSE,
    GIMP_HELP_CHANNEL_COLOR_TAG },

  { "channels-color-tag-blue", NULL,
146
    NC_("channels-action", "Blue"), NULL,
147
    NC_("channels-action", "Channel Color Tag: Set to Blue"),
148 149 150 151
    GIMP_COLOR_TAG_BLUE, FALSE,
    GIMP_HELP_CHANNEL_COLOR_TAG },

  { "channels-color-tag-green", NULL,
152
    NC_("channels-action", "Green"), NULL,
153
    NC_("channels-action", "Channel Color Tag: Set to Green"),
154 155 156 157
    GIMP_COLOR_TAG_GREEN, FALSE,
    GIMP_HELP_CHANNEL_COLOR_TAG },

  { "channels-color-tag-yellow", NULL,
158
    NC_("channels-action", "Yellow"), NULL,
159
    NC_("channels-action", "Channel Color Tag: Set to Yellow"),
160 161 162 163
    GIMP_COLOR_TAG_YELLOW, FALSE,
    GIMP_HELP_CHANNEL_COLOR_TAG },

  { "channels-color-tag-orange", NULL,
164
    NC_("channels-action", "Orange"), NULL,
165
    NC_("channels-action", "Channel Color Tag: Set to Orange"),
166 167 168 169
    GIMP_COLOR_TAG_ORANGE, FALSE,
    GIMP_HELP_CHANNEL_COLOR_TAG },

  { "channels-color-tag-brown", NULL,
170
    NC_("channels-action", "Brown"), NULL,
171
    NC_("channels-action", "Channel Color Tag: Set to Brown"),
172 173 174 175
    GIMP_COLOR_TAG_BROWN, FALSE,
    GIMP_HELP_CHANNEL_COLOR_TAG },

  { "channels-color-tag-red", NULL,
176
    NC_("channels-action", "Red"), NULL,
177
    NC_("channels-action", "Channel Color Tag: Set to Red"),
178 179 180 181
    GIMP_COLOR_TAG_RED, FALSE,
    GIMP_HELP_CHANNEL_COLOR_TAG },

  { "channels-color-tag-violet", NULL,
182
    NC_("channels-action", "Violet"), NULL,
183
    NC_("channels-action", "Channel Color Tag: Set to Violet"),
184 185 186 187
    GIMP_COLOR_TAG_VIOLET, FALSE,
    GIMP_HELP_CHANNEL_COLOR_TAG },

  { "channels-color-tag-gray", NULL,
188
    NC_("channels-action", "Gray"), NULL,
189
    NC_("channels-action", "Channel Color Tag: Set to Gray"),
190 191 192 193
    GIMP_COLOR_TAG_GRAY, FALSE,
    GIMP_HELP_CHANNEL_COLOR_TAG }
};

194
static const GimpEnumActionEntry channels_to_selection_actions[] =
195
{
196
  { "channels-selection-replace", GIMP_ICON_SELECTION_REPLACE,
197
    NC_("channels-action", "Channel to Sele_ction"), NULL,
198
    NC_("channels-action", "Replace the selection with this channel"),
199
    GIMP_CHANNEL_OP_REPLACE, FALSE,
200 201
    GIMP_HELP_CHANNEL_SELECTION_REPLACE },

202
  { "channels-selection-add", GIMP_ICON_SELECTION_ADD,
203
    NC_("channels-action", "_Add to Selection"), NULL,
204
    NC_("channels-action", "Add this channel to the current selection"),
205
    GIMP_CHANNEL_OP_ADD, FALSE,
206 207
    GIMP_HELP_CHANNEL_SELECTION_ADD },

208
  { "channels-selection-subtract", GIMP_ICON_SELECTION_SUBTRACT,
209
    NC_("channels-action", "_Subtract from Selection"), NULL,
210
    NC_("channels-action", "Subtract this channel from the current selection"),
211
    GIMP_CHANNEL_OP_SUBTRACT, FALSE,
212 213
    GIMP_HELP_CHANNEL_SELECTION_SUBTRACT },

214
  { "channels-selection-intersect", GIMP_ICON_SELECTION_INTERSECT,
215
    NC_("channels-action", "_Intersect with Selection"), NULL,
216
    NC_("channels-action", "Intersect this channel with the current selection"),
217
    GIMP_CHANNEL_OP_INTERSECT, FALSE,
218 219 220
    GIMP_HELP_CHANNEL_SELECTION_INTERSECT }
};

221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
static const GimpEnumActionEntry channels_select_actions[] =
{
  { "channels-select-top", NULL,
    NC_("channels-action", "Select _Top Channel"), NULL,
    NC_("channels-action", "Select the topmost channel"),
    GIMP_ACTION_SELECT_FIRST, FALSE,
    GIMP_HELP_CHANNEL_TOP },

  { "channels-select-bottom", NULL,
    NC_("channels-action", "Select _Bottom Channel"), NULL,
    NC_("channels-action", "Select the bottommost channel"),
    GIMP_ACTION_SELECT_LAST, FALSE,
    GIMP_HELP_CHANNEL_BOTTOM },

  { "channels-select-previous", NULL,
    NC_("channels-action", "Select _Previous Channel"), NULL,
    NC_("channels-action", "Select the channel above the current channel"),
    GIMP_ACTION_SELECT_PREVIOUS, FALSE,
    GIMP_HELP_CHANNEL_PREVIOUS },

  { "channels-select-next", NULL,
    NC_("channels-action", "Select _Next Channel"), NULL,
    NC_("channels-action", "Select the channel below the current channel"),
    GIMP_ACTION_SELECT_NEXT, FALSE,
    GIMP_HELP_CHANNEL_NEXT }
};

248 249

void
250
channels_actions_setup (GimpActionGroup *group)
251
{
252
  gimp_action_group_add_actions (group, "channels-action",
253
                                 channels_actions,
254
                                 G_N_ELEMENTS (channels_actions));
255

256 257 258 259 260 261 262 263 264
  gimp_action_group_add_toggle_actions (group, "channels-action",
                                        channels_toggle_actions,
                                        G_N_ELEMENTS (channels_toggle_actions));

  gimp_action_group_add_enum_actions (group, "channels-action",
                                      channels_color_tag_actions,
                                      G_N_ELEMENTS (channels_color_tag_actions),
                                      G_CALLBACK (channels_color_tag_cmd_callback));

265
  gimp_action_group_add_enum_actions (group, "channels-action",
266 267
                                      channels_to_selection_actions,
                                      G_N_ELEMENTS (channels_to_selection_actions),
268
                                      G_CALLBACK (channels_to_selection_cmd_callback));
269

270 271 272 273 274
  gimp_action_group_add_enum_actions (group, "channels-action",
                                      channels_select_actions,
                                      G_N_ELEMENTS (channels_select_actions),
                                      G_CALLBACK (channels_select_cmd_callback));

275
  items_actions_setup (group, "channels");
276 277 278 279 280 281
}

void
channels_actions_update (GimpActionGroup *group,
                         gpointer         data)
{
282
  GimpImage   *image     = action_data_get_image (data);
283 284 285 286 287 288
  GimpChannel *channel   = NULL;
  gboolean     fs        = FALSE;
  gboolean     component = FALSE;
  GList       *next      = NULL;
  GList       *prev      = NULL;

289
  if (image)
290
    {
291
      fs = (gimp_image_get_floating_selection (image) != NULL);
292

293
      if (GIMP_IS_COMPONENT_EDITOR (data))
294 295 296 297
        {
          if (GIMP_COMPONENT_EDITOR (data)->clicked_component != -1)
            component = TRUE;
        }
298
      else
299
        {
300
          channel = gimp_image_get_active_channel (image);
301

302
          if (channel)
303
            {
304
              GList *channel_list;
305 306
              GList *list;

307 308 309
              channel_list = gimp_item_get_container_iter (GIMP_ITEM (channel));

              list = g_list_find (channel_list, channel);
310 311

              if (list)
312 313 314 315 316 317 318 319 320 321 322 323 324
                {
                  prev = g_list_previous (list);
                  next = g_list_next (list);
                }
            }
        }
    }

#define SET_SENSITIVE(action,condition) \
        gimp_action_group_set_action_sensitive (group, action, (condition) != 0)

  SET_SENSITIVE ("channels-edit-attributes", !fs && channel);

325 326
  SET_SENSITIVE ("channels-new",             !fs && image);
  SET_SENSITIVE ("channels-new-last-values", !fs && image);
327 328 329 330 331 332 333 334 335 336 337 338 339
  SET_SENSITIVE ("channels-duplicate",       !fs && (channel || component));
  SET_SENSITIVE ("channels-delete",          !fs && channel);

  SET_SENSITIVE ("channels-raise",           !fs && channel && prev);
  SET_SENSITIVE ("channels-raise-to-top",    !fs && channel && prev);
  SET_SENSITIVE ("channels-lower",           !fs && channel && next);
  SET_SENSITIVE ("channels-lower-to-bottom", !fs && channel && next);

  SET_SENSITIVE ("channels-selection-replace",   !fs && (channel || component));
  SET_SENSITIVE ("channels-selection-add",       !fs && (channel || component));
  SET_SENSITIVE ("channels-selection-subtract",  !fs && (channel || component));
  SET_SENSITIVE ("channels-selection-intersect", !fs && (channel || component));

340 341 342 343 344
  SET_SENSITIVE ("channels-select-top",      !fs && channel && prev);
  SET_SENSITIVE ("channels-select-bottom",   !fs && channel && next);
  SET_SENSITIVE ("channels-select-previous", !fs && channel && prev);
  SET_SENSITIVE ("channels-select-next",     !fs && channel && next);

345
#undef SET_SENSITIVE
346 347

  items_actions_update (group, "channels", GIMP_ITEM (channel));
348
}