1 /* GIMP - The GNU Image Manipulation Program
2  * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3  *
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  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * 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 #include "config.h"
19 
20 #include <gegl.h>
21 #include <gtk/gtk.h>
22 
23 #include "libgimpwidgets/gimpwidgets.h"
24 
25 #include "actions-types.h"
26 
27 #include "operations/layer-modes/gimp-layer-modes.h"
28 
29 #include "core/gimpchannel.h"
30 #include "core/gimpimage.h"
31 #include "core/gimplayer.h"
32 #include "core/gimplayer-floating-selection.h"
33 
34 #include "text/gimptextlayer.h"
35 
36 #include "widgets/gimphelp-ids.h"
37 #include "widgets/gimpactiongroup.h"
38 #include "widgets/gimpwidgets-utils.h"
39 
40 #include "actions.h"
41 #include "image-commands.h"
42 #include "items-actions.h"
43 #include "layers-actions.h"
44 #include "layers-commands.h"
45 
46 #include "gimp-intl.h"
47 
48 
49 static const GimpActionEntry layers_actions[] =
50 {
51   { "layers-popup", GIMP_ICON_DIALOG_LAYERS,
52     NC_("layers-action", "Layers Menu"), NULL, NULL, NULL,
53     GIMP_HELP_LAYER_DIALOG },
54 
55   { "layers-blend-space-menu", NULL,
56     NC_("layers-action", "Blend Space"), NULL, NULL, NULL,
57     NULL },
58 
59   { "layers-composite-space-menu", NULL,
60     NC_("layers-action", "Composite Space"), NULL, NULL, NULL,
61     NULL },
62 
63   { "layers-composite-mode-menu", NULL,
64     NC_("layers-action", "Composite Mode"), NULL, NULL, NULL,
65     NULL },
66 
67   { "layers-color-tag-menu", NULL,
68     NC_("layers-action", "Color Tag"), NULL, NULL, NULL,
69     GIMP_HELP_LAYER_COLOR_TAG },
70 
71   { "layers-menu",                   NULL,
72     NC_("layers-action", "_Layer")        },
73   { "layers-stack-menu",             NULL,
74     NC_("layers-action", "Stac_k")        },
75   { "layers-mask-menu",              NULL,
76     NC_("layers-action", "_Mask")         },
77   { "layers-transparency-menu",      NULL,
78     NC_("layers-action", "Tr_ansparency") },
79   { "layers-transform-menu",         NULL,
80     NC_("layers-action", "_Transform")    },
81   { "layers-properties-menu",        GIMP_ICON_DOCUMENT_PROPERTIES,
82     NC_("layers-action", "_Properties")   },
83   { "layers-opacity-menu",           GIMP_ICON_TRANSPARENCY,
84     NC_("layers-action", "_Opacity")      },
85   { "layers-mode-menu",              GIMP_ICON_TOOL_PENCIL,
86     NC_("layers-action", "Layer _Mode")   },
87 
88   { "layers-edit", GIMP_ICON_EDIT,
89     NC_("layers-action", "Default Edit Action"), NULL,
90     NC_("layers-action", "Activate the default edit action for this type of layer"),
91     layers_edit_cmd_callback,
92     GIMP_HELP_LAYER_EDIT },
93 
94   { "layers-edit-text", GIMP_ICON_EDIT,
95     NC_("layers-action", "Edit Te_xt on canvas"), NULL,
96     NC_("layers-action", "Edit this text layer content on canvas"),
97     layers_edit_text_cmd_callback,
98     GIMP_HELP_LAYER_EDIT },
99 
100   { "layers-edit-attributes", GIMP_ICON_EDIT,
101     NC_("layers-action", "_Edit Layer Attributes..."), NULL,
102     NC_("layers-action", "Edit the layer's name"),
103     layers_edit_attributes_cmd_callback,
104     GIMP_HELP_LAYER_EDIT },
105 
106   { "layers-new", GIMP_ICON_DOCUMENT_NEW,
107     NC_("layers-action", "_New Layer..."), "<primary><shift>N",
108     NC_("layers-action", "Create a new layer and add it to the image"),
109     layers_new_cmd_callback,
110     GIMP_HELP_LAYER_NEW },
111 
112   { "layers-new-last-values", GIMP_ICON_DOCUMENT_NEW,
113     NC_("layers-action", "_New Layer"), NULL,
114     NC_("layers-action", "Create a new layer with last used values"),
115     layers_new_last_vals_cmd_callback,
116     GIMP_HELP_LAYER_NEW },
117 
118   { "layers-new-from-visible", NULL,
119     NC_("layers-action", "New from _Visible"), NULL,
120     NC_("layers-action",
121         "Create a new layer from what is visible in this image"),
122     layers_new_from_visible_cmd_callback,
123     GIMP_HELP_LAYER_NEW_FROM_VISIBLE },
124 
125   { "layers-new-group", GIMP_ICON_FOLDER_NEW,
126     NC_("layers-action", "New Layer _Group"), NULL,
127     NC_("layers-action", "Create a new layer group and add it to the image"),
128     layers_new_group_cmd_callback,
129     GIMP_HELP_LAYER_NEW },
130 
131   { "layers-duplicate", GIMP_ICON_OBJECT_DUPLICATE,
132     NC_("layers-action", "D_uplicate Layer"), "<primary><shift>D",
133     NC_("layers-action",
134         "Create a duplicate of the layer and add it to the image"),
135     layers_duplicate_cmd_callback,
136     GIMP_HELP_LAYER_DUPLICATE },
137 
138   { "layers-delete", GIMP_ICON_EDIT_DELETE,
139     NC_("layers-action", "_Delete Layer"), NULL,
140     NC_("layers-action", "Delete this layer"),
141     layers_delete_cmd_callback,
142     GIMP_HELP_LAYER_DELETE },
143 
144   { "layers-raise", GIMP_ICON_GO_UP,
145     NC_("layers-action", "_Raise Layer"), NULL,
146     NC_("layers-action", "Raise this layer one step in the layer stack"),
147     layers_raise_cmd_callback,
148     GIMP_HELP_LAYER_RAISE },
149 
150   { "layers-raise-to-top", GIMP_ICON_GO_TOP,
151     NC_("layers-action", "Layer to _Top"), NULL,
152     NC_("layers-action", "Move this layer to the top of the layer stack"),
153     layers_raise_to_top_cmd_callback,
154     GIMP_HELP_LAYER_RAISE_TO_TOP },
155 
156   { "layers-lower", GIMP_ICON_GO_DOWN,
157     NC_("layers-action", "_Lower Layer"), NULL,
158     NC_("layers-action", "Lower this layer one step in the layer stack"),
159     layers_lower_cmd_callback,
160     GIMP_HELP_LAYER_LOWER },
161 
162   { "layers-lower-to-bottom", GIMP_ICON_GO_BOTTOM,
163     NC_("layers-action", "Layer to _Bottom"), NULL,
164     NC_("layers-action", "Move this layer to the bottom of the layer stack"),
165     layers_lower_to_bottom_cmd_callback,
166     GIMP_HELP_LAYER_LOWER_TO_BOTTOM },
167 
168   { "layers-anchor", GIMP_ICON_LAYER_ANCHOR,
169     NC_("layers-action", "_Anchor Layer"), "<primary>H",
170     NC_("layers-action", "Anchor the floating layer"),
171     layers_anchor_cmd_callback,
172     GIMP_HELP_LAYER_ANCHOR },
173 
174   { "layers-merge-down", GIMP_ICON_LAYER_MERGE_DOWN,
175     NC_("layers-action", "Merge Do_wn"), NULL,
176     NC_("layers-action", "Merge this layer with the first visible layer below it"),
177     layers_merge_down_cmd_callback,
178     GIMP_HELP_LAYER_MERGE_DOWN },
179 
180   /* this is the same as layers-merge-down, except it's sensitive even if
181    * the layer can't be merged down
182    */
183   { "layers-merge-down-button", GIMP_ICON_LAYER_MERGE_DOWN,
184     NC_("layers-action", "Merge Do_wn"), NULL,
185     NC_("layers-action", "Merge this layer with the first visible layer below it"),
186     layers_merge_down_cmd_callback,
187     GIMP_HELP_LAYER_MERGE_DOWN },
188 
189   { "layers-merge-group", NULL,
190     NC_("layers-action", "Merge Layer Group"), NULL,
191     NC_("layers-action", "Merge the layer group's layers into one normal layer"),
192     layers_merge_group_cmd_callback,
193     GIMP_HELP_LAYER_MERGE_GROUP },
194 
195   { "layers-merge-layers", NULL,
196     NC_("layers-action", "Merge _Visible Layers..."), NULL,
197     NC_("layers-action", "Merge all visible layers into one layer"),
198     image_merge_layers_cmd_callback,
199     GIMP_HELP_IMAGE_MERGE_LAYERS },
200 
201   { "layers-merge-layers-last-values", NULL,
202     NC_("layers-action", "Merge _Visible Layers"), NULL,
203     NC_("layers-action", "Merge all visible layers with last used values"),
204     image_merge_layers_last_vals_cmd_callback,
205     GIMP_HELP_IMAGE_MERGE_LAYERS },
206 
207   { "layers-flatten-image", NULL,
208     NC_("layers-action", "_Flatten Image"), NULL,
209     NC_("layers-action", "Merge all layers into one and remove transparency"),
210     image_flatten_image_cmd_callback,
211     GIMP_HELP_IMAGE_FLATTEN },
212 
213   { "layers-text-discard", GIMP_ICON_TOOL_TEXT,
214     NC_("layers-action", "_Discard Text Information"), NULL,
215     NC_("layers-action", "Turn this text layer into a normal layer"),
216     layers_text_discard_cmd_callback,
217     GIMP_HELP_LAYER_TEXT_DISCARD },
218 
219   { "layers-text-to-vectors", GIMP_ICON_TOOL_TEXT,
220     NC_("layers-action", "Text to _Path"), NULL,
221     NC_("layers-action", "Create a path from this text layer"),
222     layers_text_to_vectors_cmd_callback,
223     GIMP_HELP_LAYER_TEXT_TO_PATH },
224 
225   { "layers-text-along-vectors", GIMP_ICON_TOOL_TEXT,
226     NC_("layers-action", "Text alon_g Path"), NULL,
227     NC_("layers-action", "Warp this layer's text along the current path"),
228     layers_text_along_vectors_cmd_callback,
229     GIMP_HELP_LAYER_TEXT_ALONG_PATH },
230 
231   { "layers-resize", GIMP_ICON_OBJECT_RESIZE,
232     NC_("layers-action", "Layer B_oundary Size..."), NULL,
233     NC_("layers-action", "Adjust the layer dimensions"),
234     layers_resize_cmd_callback,
235     GIMP_HELP_LAYER_RESIZE },
236 
237   { "layers-resize-to-image", GIMP_ICON_LAYER_TO_IMAGESIZE,
238     NC_("layers-action", "Layer to _Image Size"), NULL,
239     NC_("layers-action", "Resize the layer to the size of the image"),
240     layers_resize_to_image_cmd_callback,
241     GIMP_HELP_LAYER_RESIZE_TO_IMAGE },
242 
243   { "layers-scale", GIMP_ICON_OBJECT_SCALE,
244     NC_("layers-action", "_Scale Layer..."), NULL,
245     NC_("layers-action", "Change the size of the layer content"),
246     layers_scale_cmd_callback,
247     GIMP_HELP_LAYER_SCALE },
248 
249   { "layers-crop-to-selection", GIMP_ICON_TOOL_CROP,
250     NC_("layers-action", "_Crop to Selection"), NULL,
251     NC_("layers-action", "Crop the layer to the extents of the selection"),
252     layers_crop_to_selection_cmd_callback,
253     GIMP_HELP_LAYER_CROP },
254 
255   { "layers-crop-to-content", GIMP_ICON_TOOL_CROP,
256     NC_("layers-action", "Crop to C_ontent"), NULL,
257     NC_("layers-action", "Crop the layer to the extents of its content (remove empty borders from the layer)"),
258     layers_crop_to_content_cmd_callback,
259     GIMP_HELP_LAYER_CROP },
260 
261   { "layers-mask-add", GIMP_ICON_LAYER_MASK,
262     NC_("layers-action", "Add La_yer Mask..."), NULL,
263     NC_("layers-action",
264         "Add a mask that allows non-destructive editing of transparency"),
265     layers_mask_add_cmd_callback,
266     GIMP_HELP_LAYER_MASK_ADD },
267 
268   /* this is the same as layers-mask-add, except it's sensitive even if
269    * there is a mask on the layer
270    */
271   { "layers-mask-add-button", GIMP_ICON_LAYER_MASK,
272     NC_("layers-action", "Add La_yer Mask..."), NULL,
273     NC_("layers-action",
274         "Add a mask that allows non-destructive editing of transparency"),
275     layers_mask_add_cmd_callback,
276     GIMP_HELP_LAYER_MASK_ADD },
277 
278   { "layers-mask-add-last-values", GIMP_ICON_LAYER_MASK,
279     NC_("layers-action", "Add La_yer Mask"), NULL,
280     NC_("layers-action",
281         "Add a mask with last used values"),
282     layers_mask_add_last_vals_cmd_callback,
283     GIMP_HELP_LAYER_MASK_ADD },
284 
285   { "layers-alpha-add", GIMP_ICON_TRANSPARENCY,
286     NC_("layers-action", "Add Alpha C_hannel"), NULL,
287     NC_("layers-action", "Add transparency information to the layer"),
288     layers_alpha_add_cmd_callback,
289     GIMP_HELP_LAYER_ALPHA_ADD },
290 
291   { "layers-alpha-remove", NULL,
292     NC_("layers-action", "_Remove Alpha Channel"), NULL,
293     NC_("layers-action", "Remove transparency information from the layer"),
294     layers_alpha_remove_cmd_callback,
295     GIMP_HELP_LAYER_ALPHA_REMOVE }
296 };
297 
298 static const GimpToggleActionEntry layers_toggle_actions[] =
299 {
300   { "layers-mask-edit", GIMP_ICON_EDIT,
301     NC_("layers-action", "_Edit Layer Mask"), NULL,
302     NC_("layers-action", "Work on the layer mask"),
303     layers_mask_edit_cmd_callback,
304     FALSE,
305     GIMP_HELP_LAYER_MASK_EDIT },
306 
307   { "layers-mask-show", GIMP_ICON_VISIBLE,
308     NC_("layers-action", "S_how Layer Mask"), NULL, NULL,
309     layers_mask_show_cmd_callback,
310     FALSE,
311     GIMP_HELP_LAYER_MASK_SHOW },
312 
313   { "layers-mask-disable", NULL,
314     NC_("layers-action", "_Disable Layer Mask"), NULL,
315     NC_("layers-action", "Dismiss the effect of the layer mask"),
316     layers_mask_disable_cmd_callback,
317     FALSE,
318     GIMP_HELP_LAYER_MASK_DISABLE },
319 
320   { "layers-visible", GIMP_ICON_VISIBLE,
321     NC_("layers-action", "Toggle Layer _Visibility"), NULL, NULL,
322     layers_visible_cmd_callback,
323     FALSE,
324     GIMP_HELP_LAYER_VISIBLE },
325 
326   { "layers-linked", GIMP_ICON_LINKED,
327     NC_("layers-action", "Toggle Layer _Linked State"), NULL, NULL,
328     layers_linked_cmd_callback,
329     FALSE,
330     GIMP_HELP_LAYER_LINKED },
331 
332   { "layers-lock-content", NULL /* GIMP_ICON_LOCK */,
333     NC_("layers-action", "L_ock Pixels of Layer"), NULL, NULL,
334     layers_lock_content_cmd_callback,
335     FALSE,
336     GIMP_HELP_LAYER_LOCK_PIXELS },
337 
338   { "layers-lock-position", GIMP_ICON_TOOL_MOVE,
339     NC_("layers-action", "L_ock Position of Layer"), NULL, NULL,
340     layers_lock_position_cmd_callback,
341     FALSE,
342     GIMP_HELP_LAYER_LOCK_POSITION },
343 
344   { "layers-lock-alpha", GIMP_ICON_TRANSPARENCY,
345     NC_("layers-action", "Lock Alph_a Channel"), NULL,
346     NC_("layers-action",
347         "Keep transparency information on this layer from being modified"),
348     layers_lock_alpha_cmd_callback,
349     FALSE,
350     GIMP_HELP_LAYER_LOCK_ALPHA },
351 };
352 
353 static const GimpRadioActionEntry layers_blend_space_actions[] =
354 {
355   { "layers-blend-space-auto", NULL,
356     NC_("layers-action", "Auto"), NULL,
357     NC_("layers-action", "Layer Blend Space: Auto"),
358     GIMP_LAYER_COLOR_SPACE_AUTO,
359     NULL },
360 
361   { "layers-blend-space-rgb-linear", NULL,
362     NC_("layers-action", "RGB (linear)"), NULL,
363     NC_("layers-action", "Layer Blend Space: RGB (linear)"),
364     GIMP_LAYER_COLOR_SPACE_RGB_LINEAR,
365     NULL },
366 
367   { "layers-blend-space-rgb-perceptual", NULL,
368     NC_("layers-action", "RGB (perceptual)"), NULL,
369     NC_("layers-action", "Layer Blend Space: RGB (perceptual)"),
370     GIMP_LAYER_COLOR_SPACE_RGB_PERCEPTUAL,
371     NULL }
372 };
373 
374 static const GimpRadioActionEntry layers_composite_space_actions[] =
375 {
376   { "layers-composite-space-auto", NULL,
377     NC_("layers-action", "Auto"), NULL,
378     NC_("layers-action", "Layer Composite Space: Auto"),
379     GIMP_LAYER_COLOR_SPACE_AUTO,
380     NULL },
381 
382   { "layers-composite-space-rgb-linear", NULL,
383     NC_("layers-action", "RGB (linear)"), NULL,
384     NC_("layers-action", "Layer Composite Space: RGB (linear)"),
385     GIMP_LAYER_COLOR_SPACE_RGB_LINEAR,
386     NULL },
387 
388   { "layers-composite-space-rgb-perceptual", NULL,
389     NC_("layers-action", "RGB (perceptual)"), NULL,
390     NC_("layers-action", "Layer Composite Space: RGB (perceptual)"),
391     GIMP_LAYER_COLOR_SPACE_RGB_PERCEPTUAL,
392     NULL }
393 };
394 
395 static const GimpRadioActionEntry layers_composite_mode_actions[] =
396 {
397   { "layers-composite-mode-auto", NULL,
398     NC_("layers-action", "Auto"), NULL,
399     NC_("layers-action", "Layer Composite Mode: Auto"),
400     GIMP_LAYER_COMPOSITE_AUTO,
401     NULL },
402 
403   { "layers-composite-mode-union", NULL,
404     NC_("layers-action", "Union"), NULL,
405     NC_("layers-action", "Layer Composite Mode: Union"),
406     GIMP_LAYER_COMPOSITE_UNION,
407     NULL },
408 
409   { "layers-composite-mode-clip-to-backdrop", NULL,
410     NC_("layers-action", "Clip to Backdrop"), NULL,
411     NC_("layers-action", "Layer Composite Mode: Clip to Backdrop"),
412     GIMP_LAYER_COMPOSITE_CLIP_TO_BACKDROP,
413     NULL },
414 
415   { "layers-composite-mode-clip-to-layer", NULL,
416     NC_("layers-action", "Clip to Layer"), NULL,
417     NC_("layers-action", "Layer Composite Mode: Clip to Layer"),
418     GIMP_LAYER_COMPOSITE_CLIP_TO_LAYER,
419     NULL },
420 
421   { "layers-composite-mode-intersection", NULL,
422     NC_("layers-action", "Intersection"), NULL,
423     NC_("layers-action", "Layer Composite Mode: Intersection"),
424     GIMP_LAYER_COMPOSITE_INTERSECTION,
425     NULL }
426 };
427 
428 static const GimpEnumActionEntry layers_color_tag_actions[] =
429 {
430   { "layers-color-tag-none", GIMP_ICON_EDIT_CLEAR,
431     NC_("layers-action", "None"), NULL,
432     NC_("layers-action", "Layer Color Tag: Clear"),
433     GIMP_COLOR_TAG_NONE, FALSE,
434     GIMP_HELP_LAYER_COLOR_TAG },
435 
436   { "layers-color-tag-blue", NULL,
437     NC_("layers-action", "Blue"), NULL,
438     NC_("layers-action", "Layer Color Tag: Set to Blue"),
439     GIMP_COLOR_TAG_BLUE, FALSE,
440     GIMP_HELP_LAYER_COLOR_TAG },
441 
442   { "layers-color-tag-green", NULL,
443     NC_("layers-action", "Green"), NULL,
444     NC_("layers-action", "Layer Color Tag: Set to Green"),
445     GIMP_COLOR_TAG_GREEN, FALSE,
446     GIMP_HELP_LAYER_COLOR_TAG },
447 
448   { "layers-color-tag-yellow", NULL,
449     NC_("layers-action", "Yellow"), NULL,
450     NC_("layers-action", "Layer Color Tag: Set to Yellow"),
451     GIMP_COLOR_TAG_YELLOW, FALSE,
452     GIMP_HELP_LAYER_COLOR_TAG },
453 
454   { "layers-color-tag-orange", NULL,
455     NC_("layers-action", "Orange"), NULL,
456     NC_("layers-action", "Layer Color Tag: Set to Orange"),
457     GIMP_COLOR_TAG_ORANGE, FALSE,
458     GIMP_HELP_LAYER_COLOR_TAG },
459 
460   { "layers-color-tag-brown", NULL,
461     NC_("layers-action", "Brown"), NULL,
462     NC_("layers-action", "Layer Color Tag: Set to Brown"),
463     GIMP_COLOR_TAG_BROWN, FALSE,
464     GIMP_HELP_LAYER_COLOR_TAG },
465 
466   { "layers-color-tag-red", NULL,
467     NC_("layers-action", "Red"), NULL,
468     NC_("layers-action", "Layer Color Tag: Set to Red"),
469     GIMP_COLOR_TAG_RED, FALSE,
470     GIMP_HELP_LAYER_COLOR_TAG },
471 
472   { "layers-color-tag-violet", NULL,
473     NC_("layers-action", "Violet"), NULL,
474     NC_("layers-action", "Layer Color Tag: Set to Violet"),
475     GIMP_COLOR_TAG_VIOLET, FALSE,
476     GIMP_HELP_LAYER_COLOR_TAG },
477 
478   { "layers-color-tag-gray", NULL,
479     NC_("layers-action", "Gray"), NULL,
480     NC_("layers-action", "Layer Color Tag: Set to Gray"),
481     GIMP_COLOR_TAG_GRAY, FALSE,
482     GIMP_HELP_LAYER_COLOR_TAG }
483 };
484 
485 static const GimpEnumActionEntry layers_mask_apply_actions[] =
486 {
487   { "layers-mask-apply", NULL,
488     NC_("layers-action", "Apply Layer _Mask"), NULL,
489     NC_("layers-action", "Apply the effect of the layer mask and remove it"),
490     GIMP_MASK_APPLY, FALSE,
491     GIMP_HELP_LAYER_MASK_APPLY },
492 
493   { "layers-mask-delete", GIMP_ICON_EDIT_DELETE,
494     NC_("layers-action", "Delete Layer Mas_k"), NULL,
495     NC_("layers-action", "Remove the layer mask and its effect"),
496     GIMP_MASK_DISCARD, FALSE,
497     GIMP_HELP_LAYER_MASK_DELETE }
498 };
499 
500 static const GimpEnumActionEntry layers_mask_to_selection_actions[] =
501 {
502   { "layers-mask-selection-replace", GIMP_ICON_SELECTION_REPLACE,
503     NC_("layers-action", "_Mask to Selection"), NULL,
504     NC_("layers-action", "Replace the selection with the layer mask"),
505     GIMP_CHANNEL_OP_REPLACE, FALSE,
506     GIMP_HELP_LAYER_MASK_SELECTION_REPLACE },
507 
508   { "layers-mask-selection-add", GIMP_ICON_SELECTION_ADD,
509     NC_("layers-action", "_Add to Selection"), NULL,
510     NC_("layers-action", "Add the layer mask to the current selection"),
511     GIMP_CHANNEL_OP_ADD, FALSE,
512     GIMP_HELP_LAYER_MASK_SELECTION_ADD },
513 
514   { "layers-mask-selection-subtract", GIMP_ICON_SELECTION_SUBTRACT,
515     NC_("layers-action", "_Subtract from Selection"), NULL,
516     NC_("layers-action", "Subtract the layer mask from the current selection"),
517     GIMP_CHANNEL_OP_SUBTRACT, FALSE,
518     GIMP_HELP_LAYER_MASK_SELECTION_SUBTRACT },
519 
520   { "layers-mask-selection-intersect", GIMP_ICON_SELECTION_INTERSECT,
521     NC_("layers-action", "_Intersect with Selection"), NULL,
522     NC_("layers-action", "Intersect the layer mask with the current selection"),
523     GIMP_CHANNEL_OP_INTERSECT, FALSE,
524     GIMP_HELP_LAYER_MASK_SELECTION_INTERSECT }
525 };
526 
527 static const GimpEnumActionEntry layers_alpha_to_selection_actions[] =
528 {
529   { "layers-alpha-selection-replace", GIMP_ICON_SELECTION_REPLACE,
530     NC_("layers-action", "Al_pha to Selection"), NULL,
531     NC_("layers-action",
532         "Replace the selection with the layer's alpha channel"),
533     GIMP_CHANNEL_OP_REPLACE, FALSE,
534     GIMP_HELP_LAYER_ALPHA_SELECTION_REPLACE },
535 
536   { "layers-alpha-selection-add", GIMP_ICON_SELECTION_ADD,
537     NC_("layers-action", "A_dd to Selection"), NULL,
538     NC_("layers-action",
539         "Add the layer's alpha channel to the current selection"),
540     GIMP_CHANNEL_OP_ADD, FALSE,
541     GIMP_HELP_LAYER_ALPHA_SELECTION_ADD },
542 
543   { "layers-alpha-selection-subtract", GIMP_ICON_SELECTION_SUBTRACT,
544     NC_("layers-action", "_Subtract from Selection"), NULL,
545     NC_("layers-action",
546         "Subtract the layer's alpha channel from the current selection"),
547     GIMP_CHANNEL_OP_SUBTRACT, FALSE,
548     GIMP_HELP_LAYER_ALPHA_SELECTION_SUBTRACT },
549 
550   { "layers-alpha-selection-intersect", GIMP_ICON_SELECTION_INTERSECT,
551     NC_("layers-action", "_Intersect with Selection"), NULL,
552     NC_("layers-action",
553         "Intersect the layer's alpha channel with the current selection"),
554     GIMP_CHANNEL_OP_INTERSECT, FALSE,
555     GIMP_HELP_LAYER_ALPHA_SELECTION_INTERSECT }
556 };
557 
558 static const GimpEnumActionEntry layers_select_actions[] =
559 {
560   { "layers-select-top", NULL,
561     NC_("layers-action", "Select _Top Layer"), "Home",
562     NC_("layers-action", "Select the topmost layer"),
563     GIMP_ACTION_SELECT_FIRST, FALSE,
564     GIMP_HELP_LAYER_TOP },
565 
566   { "layers-select-bottom", NULL,
567     NC_("layers-action", "Select _Bottom Layer"), "End",
568     NC_("layers-action", "Select the bottommost layer"),
569     GIMP_ACTION_SELECT_LAST, FALSE,
570     GIMP_HELP_LAYER_BOTTOM },
571 
572   { "layers-select-previous", NULL,
573     NC_("layers-action", "Select _Previous Layer"), "Prior",
574     NC_("layers-action", "Select the layer above the current layer"),
575     GIMP_ACTION_SELECT_PREVIOUS, FALSE,
576     GIMP_HELP_LAYER_PREVIOUS },
577 
578   { "layers-select-next", NULL,
579     NC_("layers-action", "Select _Next Layer"), "Next",
580     NC_("layers-action", "Select the layer below the current layer"),
581     GIMP_ACTION_SELECT_NEXT, FALSE,
582     GIMP_HELP_LAYER_NEXT }
583 };
584 
585 static const GimpEnumActionEntry layers_opacity_actions[] =
586 {
587   { "layers-opacity-set", GIMP_ICON_TRANSPARENCY,
588     NC_("layers-action", "Layer Opacity: Set"), NULL, NULL,
589     GIMP_ACTION_SELECT_SET, TRUE,
590     GIMP_HELP_LAYER_OPACITY },
591   { "layers-opacity-transparent", GIMP_ICON_TRANSPARENCY,
592     NC_("layers-action", "Layer Opacity: Make Completely Transparent"), NULL, NULL,
593     GIMP_ACTION_SELECT_FIRST, FALSE,
594     GIMP_HELP_LAYER_OPACITY },
595   { "layers-opacity-opaque", GIMP_ICON_TRANSPARENCY,
596     NC_("layers-action", "Layer Opacity: Make Completely Opaque"), NULL, NULL,
597     GIMP_ACTION_SELECT_LAST, FALSE,
598     GIMP_HELP_LAYER_OPACITY },
599   { "layers-opacity-decrease", GIMP_ICON_TRANSPARENCY,
600     NC_("layers-action", "Layer Opacity: Make More Transparent"), NULL, NULL,
601     GIMP_ACTION_SELECT_PREVIOUS, FALSE,
602     GIMP_HELP_LAYER_OPACITY },
603   { "layers-opacity-increase", GIMP_ICON_TRANSPARENCY,
604     NC_("layers-action", "Layer Opacity: Make More Opaque"), NULL, NULL,
605     GIMP_ACTION_SELECT_NEXT, FALSE,
606     GIMP_HELP_LAYER_OPACITY },
607   { "layers-opacity-decrease-skip", GIMP_ICON_TRANSPARENCY,
608     NC_("layers-action", "Layer Opacity: Make 10% More Transparent"), NULL, NULL,
609     GIMP_ACTION_SELECT_SKIP_PREVIOUS, FALSE,
610     GIMP_HELP_LAYER_OPACITY },
611   { "layers-opacity-increase-skip", GIMP_ICON_TRANSPARENCY,
612     NC_("layers-action", "Layer Opacity: Make 10% More Opaque"), NULL, NULL,
613     GIMP_ACTION_SELECT_SKIP_NEXT, FALSE,
614     GIMP_HELP_LAYER_OPACITY }
615 };
616 
617 static const GimpEnumActionEntry layers_mode_actions[] =
618 {
619   { "layers-mode-first", GIMP_ICON_TOOL_PENCIL,
620     NC_("layers-action", "Layer Mode: Select First"), NULL, NULL,
621     GIMP_ACTION_SELECT_FIRST, FALSE,
622     GIMP_HELP_LAYER_MODE },
623   { "layers-mode-last", GIMP_ICON_TOOL_PENCIL,
624     NC_("layers-action", "Layer Mode: Select Last"), NULL, NULL,
625     GIMP_ACTION_SELECT_LAST, FALSE,
626     GIMP_HELP_LAYER_MODE },
627   { "layers-mode-previous", GIMP_ICON_TOOL_PENCIL,
628     NC_("layers-action", "Layer Mode: Select Previous"), NULL, NULL,
629     GIMP_ACTION_SELECT_PREVIOUS, FALSE,
630     GIMP_HELP_LAYER_MODE },
631   { "layers-mode-next", GIMP_ICON_TOOL_PENCIL,
632     NC_("layers-action", "Layer Mode: Select Next"), NULL, NULL,
633     GIMP_ACTION_SELECT_NEXT, FALSE,
634     GIMP_HELP_LAYER_MODE }
635 };
636 
637 /**
638  * layers_actions_fix_tooltip:
639  * @group:
640  * @action:
641  * @modifiers:
642  *
643  * Make layer alpha to selection click-shortcuts discoverable, at
644  * least in theory.
645  **/
646 static void
layers_actions_fix_tooltip(GimpActionGroup * group,const gchar * action,GdkModifierType modifiers)647 layers_actions_fix_tooltip (GimpActionGroup *group,
648                             const gchar     *action,
649                             GdkModifierType  modifiers)
650 {
651   const gchar *old_hint;
652   gchar       *new_hint;
653 
654   old_hint = gimp_action_group_get_action_tooltip (group,
655                                                    action);
656   new_hint = g_strconcat (old_hint,
657                           "\n",
658                           /* Will be followed with e.g. "Shift-Click
659                              on thumbnail"
660                            */
661                           _("Shortcut: "),
662                           gimp_get_mod_string (modifiers),
663                           /* Will be prepended with a modifier key
664                              string, e.g. "Shift"
665                            */
666                           _("-Click on thumbnail in Layers dockable"),
667                           NULL);
668 
669   gimp_action_group_set_action_tooltip (group, action, new_hint);
670   g_free (new_hint);
671 }
672 
673 void
layers_actions_setup(GimpActionGroup * group)674 layers_actions_setup (GimpActionGroup *group)
675 {
676   GdkDisplay      *display = gdk_display_get_default ();
677   GdkModifierType  extend_mask;
678   GdkModifierType  modify_mask;
679 
680   extend_mask =
681     gdk_keymap_get_modifier_mask (gdk_keymap_get_for_display (display),
682                                   GDK_MODIFIER_INTENT_EXTEND_SELECTION);
683   modify_mask =
684     gdk_keymap_get_modifier_mask (gdk_keymap_get_for_display (display),
685                                   GDK_MODIFIER_INTENT_MODIFY_SELECTION);
686 
687   gimp_action_group_add_actions (group, "layers-action",
688                                  layers_actions,
689                                  G_N_ELEMENTS (layers_actions));
690 
691   gimp_action_group_add_toggle_actions (group, "layers-action",
692                                         layers_toggle_actions,
693                                         G_N_ELEMENTS (layers_toggle_actions));
694 
695   gimp_action_group_add_radio_actions (group, "layers-action",
696                                        layers_blend_space_actions,
697                                        G_N_ELEMENTS (layers_blend_space_actions),
698                                        NULL, 0,
699                                        layers_blend_space_cmd_callback);
700 
701   gimp_action_group_add_radio_actions (group, "layers-action",
702                                        layers_composite_space_actions,
703                                        G_N_ELEMENTS (layers_composite_space_actions),
704                                        NULL, 0,
705                                        layers_composite_space_cmd_callback);
706 
707   gimp_action_group_add_radio_actions (group, "layers-action",
708                                        layers_composite_mode_actions,
709                                        G_N_ELEMENTS (layers_composite_mode_actions),
710                                        NULL, 0,
711                                        layers_composite_mode_cmd_callback);
712 
713   gimp_action_group_add_enum_actions (group, "layers-action",
714                                       layers_color_tag_actions,
715                                       G_N_ELEMENTS (layers_color_tag_actions),
716                                       layers_color_tag_cmd_callback);
717 
718   gimp_action_group_add_enum_actions (group, "layers-action",
719                                       layers_mask_apply_actions,
720                                       G_N_ELEMENTS (layers_mask_apply_actions),
721                                       layers_mask_apply_cmd_callback);
722 
723   gimp_action_group_add_enum_actions (group, "layers-action",
724                                       layers_mask_to_selection_actions,
725                                       G_N_ELEMENTS (layers_mask_to_selection_actions),
726                                       layers_mask_to_selection_cmd_callback);
727 
728   gimp_action_group_add_enum_actions (group, "layers-action",
729                                       layers_alpha_to_selection_actions,
730                                       G_N_ELEMENTS (layers_alpha_to_selection_actions),
731                                       layers_alpha_to_selection_cmd_callback);
732 
733   layers_actions_fix_tooltip (group, "layers-alpha-selection-replace",
734                               GDK_MOD1_MASK);
735   layers_actions_fix_tooltip (group, "layers-alpha-selection-add",
736                               extend_mask | GDK_MOD1_MASK);
737   layers_actions_fix_tooltip (group, "layers-alpha-selection-subtract",
738                               modify_mask | GDK_MOD1_MASK);
739   layers_actions_fix_tooltip (group, "layers-alpha-selection-intersect",
740                               extend_mask | modify_mask | GDK_MOD1_MASK);
741 
742   gimp_action_group_add_enum_actions (group, "layers-action",
743                                       layers_select_actions,
744                                       G_N_ELEMENTS (layers_select_actions),
745                                       layers_select_cmd_callback);
746 
747   gimp_action_group_add_enum_actions (group, "layers-action",
748                                       layers_opacity_actions,
749                                       G_N_ELEMENTS (layers_opacity_actions),
750                                       layers_opacity_cmd_callback);
751 
752   gimp_action_group_add_enum_actions (group, "layers-action",
753                                       layers_mode_actions,
754                                       G_N_ELEMENTS (layers_mode_actions),
755                                       layers_mode_cmd_callback);
756 
757   items_actions_setup (group, "layers");
758 }
759 
760 void
layers_actions_update(GimpActionGroup * group,gpointer data)761 layers_actions_update (GimpActionGroup *group,
762                        gpointer         data)
763 {
764   GimpImage     *image          = action_data_get_image (data);
765   GimpLayer     *layer          = NULL;
766   GimpLayerMask *mask           = NULL;     /*  layer mask             */
767   gboolean       fs             = FALSE;    /*  floating sel           */
768   gboolean       ac             = FALSE;    /*  active channel         */
769   gboolean       sel            = FALSE;
770   gboolean       alpha          = FALSE;    /*  alpha channel present  */
771   gboolean       indexed        = FALSE;    /*  is indexed             */
772   gboolean       lock_alpha     = FALSE;
773   gboolean       can_lock_alpha = FALSE;
774   gboolean       text_layer     = FALSE;
775   gboolean       visible        = FALSE;
776   gboolean       writable       = FALSE;
777   gboolean       movable        = FALSE;
778   gboolean       children       = FALSE;
779   gboolean       bs_mutable     = FALSE;
780   gboolean       cs_mutable     = FALSE;
781   gboolean       cm_mutable     = FALSE;
782   GList         *next           = NULL;
783   GList         *next_visible   = NULL;
784   GList         *prev           = NULL;
785   gboolean       next_mode      = FALSE;
786   gboolean       prev_mode      = FALSE;
787 
788   if (image)
789     {
790       fs      = (gimp_image_get_floating_selection (image) != NULL);
791       ac      = (gimp_image_get_active_channel (image) != NULL);
792       sel     = ! gimp_channel_is_empty (gimp_image_get_mask (image));
793       indexed = (gimp_image_get_base_type (image) == GIMP_INDEXED);
794 
795       layer = gimp_image_get_active_layer (image);
796 
797       if (layer)
798         {
799           GimpLayerMode *modes;
800           GimpLayerMode  mode   = gimp_layer_get_mode (layer);
801           const gchar   *action = NULL;
802           GList         *layer_list;
803           GList         *list;
804           gint           n_modes;
805           gint           i = 0;
806 
807           switch (gimp_layer_get_blend_space (layer))
808             {
809             case GIMP_LAYER_COLOR_SPACE_AUTO:
810               action = "layers-blend-space-auto"; break;
811             case GIMP_LAYER_COLOR_SPACE_RGB_LINEAR:
812               action = "layers-blend-space-rgb-linear"; break;
813             case GIMP_LAYER_COLOR_SPACE_RGB_PERCEPTUAL:
814               action = "layers-blend-space-rgb-perceptual"; break;
815             default:
816               action = NULL; break; /* can't happen */
817             }
818 
819           if (action)
820             gimp_action_group_set_action_active (group, action, TRUE);
821 
822           switch (gimp_layer_get_composite_space (layer))
823             {
824             case GIMP_LAYER_COLOR_SPACE_AUTO:
825               action = "layers-composite-space-auto"; break;
826             case GIMP_LAYER_COLOR_SPACE_RGB_LINEAR:
827               action = "layers-composite-space-rgb-linear"; break;
828             case GIMP_LAYER_COLOR_SPACE_RGB_PERCEPTUAL:
829               action = "layers-composite-space-rgb-perceptual"; break;
830             default:
831               action = NULL; break; /* can't happen */
832             }
833 
834           if (action)
835             gimp_action_group_set_action_active (group, action, TRUE);
836 
837           switch (gimp_layer_get_composite_mode (layer))
838             {
839             case GIMP_LAYER_COMPOSITE_AUTO:
840               action = "layers-composite-mode-auto"; break;
841             case GIMP_LAYER_COMPOSITE_UNION:
842               action = "layers-composite-mode-union"; break;
843             case GIMP_LAYER_COMPOSITE_CLIP_TO_BACKDROP:
844               action = "layers-composite-mode-clip-to-backdrop"; break;
845             case GIMP_LAYER_COMPOSITE_CLIP_TO_LAYER:
846               action = "layers-composite-mode-clip-to-layer"; break;
847             case GIMP_LAYER_COMPOSITE_INTERSECTION:
848               action = "layers-composite-mode-intersection"; break;
849             }
850 
851           gimp_action_group_set_action_active (group, action, TRUE);
852 
853           bs_mutable = gimp_layer_mode_is_blend_space_mutable (mode);
854           cs_mutable = gimp_layer_mode_is_composite_space_mutable (mode);
855           cm_mutable = gimp_layer_mode_is_composite_mode_mutable (mode);
856 
857           mask           = gimp_layer_get_mask (layer);
858           lock_alpha     = gimp_layer_get_lock_alpha (layer);
859           can_lock_alpha = gimp_layer_can_lock_alpha (layer);
860           alpha          = gimp_drawable_has_alpha (GIMP_DRAWABLE (layer));
861           visible        = gimp_item_get_visible (GIMP_ITEM (layer));
862           writable       = ! gimp_item_is_content_locked (GIMP_ITEM (layer));
863           movable        = ! gimp_item_is_position_locked (GIMP_ITEM (layer));
864 
865           if (gimp_viewable_get_children (GIMP_VIEWABLE (layer)))
866             children = TRUE;
867 
868           layer_list = gimp_item_get_container_iter (GIMP_ITEM (layer));
869 
870           list = g_list_find (layer_list, layer);
871 
872           if (list)
873             {
874               prev = g_list_previous (list);
875               next = g_list_next (list);
876 
877               for (next_visible = next;
878                    next_visible;
879                    next_visible = g_list_next (next_visible))
880                 {
881                   if (gimp_item_get_visible (next_visible->data))
882                     {
883                       /*  "next_visible" is actually "next_visible" and
884                        *  "writable" and "not group"
885                        */
886                       if (gimp_item_is_content_locked (next_visible->data) ||
887                           gimp_viewable_get_children (next_visible->data))
888                         next_visible = NULL;
889 
890                       break;
891                     }
892                 }
893             }
894 
895           modes = gimp_layer_mode_get_context_array (mode,
896                                                      GIMP_LAYER_MODE_CONTEXT_LAYER,
897                                                      &n_modes);
898           while (i < (n_modes - 1) && modes[i] != mode)
899             i++;
900           g_free (modes);
901           next_mode = (i < n_modes - 1);
902           prev_mode = (i > 0);
903 
904           text_layer = gimp_item_is_text_layer (GIMP_ITEM (layer));
905         }
906     }
907 
908 #define SET_VISIBLE(action,condition) \
909         gimp_action_group_set_action_visible (group, action, (condition) != 0)
910 #define SET_SENSITIVE(action,condition) \
911         gimp_action_group_set_action_sensitive (group, action, (condition) != 0)
912 #define SET_ACTIVE(action,condition) \
913         gimp_action_group_set_action_active (group, action, (condition) != 0)
914 #define SET_LABEL(action,label) \
915         gimp_action_group_set_action_label (group, action, label)
916 
917   SET_SENSITIVE ("layers-edit",             !ac && ((layer && !fs) || text_layer));
918   SET_VISIBLE   ("layers-edit-text",        text_layer && !ac);
919   SET_SENSITIVE ("layers-edit-text",        text_layer && !ac);
920   SET_SENSITIVE ("layers-edit-attributes",  layer && !fs && !ac);
921 
922   if (layer && gimp_layer_is_floating_sel (layer))
923     {
924       SET_LABEL ("layers-new",             C_("layers-action", "To _New Layer"));
925       SET_LABEL ("layers-new-last-values", C_("layers-action", "To _New Layer"));
926     }
927   else
928     {
929       SET_LABEL ("layers-new",             C_("layers-action", "_New Layer..."));
930       SET_LABEL ("layers-new-last-values", C_("layers-action", "_New Layer"));
931     }
932 
933   SET_SENSITIVE ("layers-new",              image);
934   SET_SENSITIVE ("layers-new-last-values",  image);
935   SET_SENSITIVE ("layers-new-from-visible", image);
936   SET_SENSITIVE ("layers-new-group",        image && !indexed);
937   SET_SENSITIVE ("layers-duplicate",        layer && !fs && !ac);
938   SET_SENSITIVE ("layers-delete",           layer && !ac);
939 
940   SET_SENSITIVE ("layers-mode-first",       layer && !ac && prev_mode);
941   SET_SENSITIVE ("layers-mode-last",        layer && !ac && next_mode);
942   SET_SENSITIVE ("layers-mode-previous",    layer && !ac && prev_mode);
943   SET_SENSITIVE ("layers-mode-next",        layer && !ac && next_mode);
944 
945   SET_SENSITIVE ("layers-select-top",       layer && !fs && !ac && prev);
946   SET_SENSITIVE ("layers-select-bottom",    layer && !fs && !ac && next);
947   SET_SENSITIVE ("layers-select-previous",  layer && !fs && !ac && prev);
948   SET_SENSITIVE ("layers-select-next",      layer && !fs && !ac && next);
949 
950   SET_SENSITIVE ("layers-raise",            layer && !fs && !ac && prev);
951   SET_SENSITIVE ("layers-raise-to-top",     layer && !fs && !ac && prev);
952   SET_SENSITIVE ("layers-lower",            layer && !fs && !ac && next);
953   SET_SENSITIVE ("layers-lower-to-bottom",  layer && !fs && !ac && next);
954 
955   SET_VISIBLE   ("layers-anchor",            layer &&  fs && !ac);
956   SET_VISIBLE   ("layers-merge-down",        !fs);
957   SET_SENSITIVE ("layers-merge-down",        layer && !fs && !ac && visible && next_visible);
958   SET_VISIBLE   ("layers-merge-down-button", !fs);
959   SET_SENSITIVE ("layers-merge-down-button", layer && !fs && !ac);
960   SET_VISIBLE   ("layers-merge-group",       children);
961   SET_SENSITIVE ("layers-merge-group",       layer && !fs && !ac && children);
962   SET_SENSITIVE ("layers-merge-layers",      layer && !fs && !ac);
963   SET_SENSITIVE ("layers-flatten-image",     layer && !fs && !ac);
964 
965   SET_VISIBLE   ("layers-text-discard",       text_layer && !ac);
966   SET_VISIBLE   ("layers-text-to-vectors",    text_layer && !ac);
967   SET_VISIBLE   ("layers-text-along-vectors", text_layer && !ac);
968 
969   SET_SENSITIVE ("layers-resize",          writable && movable && !ac);
970   SET_SENSITIVE ("layers-resize-to-image", writable && movable && !ac);
971   SET_SENSITIVE ("layers-scale",           writable && movable && !ac);
972 
973   SET_SENSITIVE ("layers-crop-to-selection", writable && movable && sel);
974   SET_SENSITIVE ("layers-crop-to-content",   writable && movable);
975 
976   SET_SENSITIVE ("layers-alpha-add",    writable && !children && !fs && !alpha);
977   SET_SENSITIVE ("layers-alpha-remove", writable && !children && !fs &&  alpha);
978 
979   SET_SENSITIVE ("layers-lock-alpha", can_lock_alpha);
980   SET_ACTIVE    ("layers-lock-alpha", lock_alpha);
981 
982   SET_SENSITIVE ("layers-blend-space-auto",           layer && bs_mutable);
983   SET_SENSITIVE ("layers-blend-space-rgb-linear",     layer && bs_mutable);
984   SET_SENSITIVE ("layers-blend-space-rgb-perceptual", layer && bs_mutable);
985 
986   SET_SENSITIVE ("layers-composite-space-auto",           layer && cs_mutable);
987   SET_SENSITIVE ("layers-composite-space-rgb-linear",     layer && cs_mutable);
988   SET_SENSITIVE ("layers-composite-space-rgb-perceptual", layer && cs_mutable);
989 
990   SET_SENSITIVE ("layers-composite-mode-auto",             layer && cm_mutable);
991   SET_SENSITIVE ("layers-composite-mode-union",            layer && cm_mutable);
992   SET_SENSITIVE ("layers-composite-mode-clip-to-backdrop", layer && cm_mutable);
993   SET_SENSITIVE ("layers-composite-mode-clip-to-layer",    layer && cm_mutable);
994   SET_SENSITIVE ("layers-composite-mode-intersection",     layer && cm_mutable);
995 
996   SET_SENSITIVE ("layers-mask-add",             layer && !fs && !ac && !mask);
997   SET_SENSITIVE ("layers-mask-add-button",      layer && !fs && !ac);
998   SET_SENSITIVE ("layers-mask-add-last-values", layer && !fs && !ac && !mask);
999 
1000   SET_SENSITIVE ("layers-mask-apply",  writable && !fs && !ac &&  mask && !children);
1001   SET_SENSITIVE ("layers-mask-delete", layer    && !fs && !ac &&  mask);
1002 
1003   SET_SENSITIVE ("layers-mask-edit",    layer && !fs && !ac &&  mask);
1004   SET_SENSITIVE ("layers-mask-show",    layer && !fs && !ac &&  mask);
1005   SET_SENSITIVE ("layers-mask-disable", layer && !fs && !ac &&  mask);
1006 
1007   SET_ACTIVE ("layers-mask-edit",    mask && gimp_layer_get_edit_mask (layer));
1008   SET_ACTIVE ("layers-mask-show",    mask && gimp_layer_get_show_mask (layer));
1009   SET_ACTIVE ("layers-mask-disable", mask && !gimp_layer_get_apply_mask (layer));
1010 
1011   SET_SENSITIVE ("layers-mask-selection-replace",   layer && !fs && !ac && mask);
1012   SET_SENSITIVE ("layers-mask-selection-add",       layer && !fs && !ac && mask);
1013   SET_SENSITIVE ("layers-mask-selection-subtract",  layer && !fs && !ac && mask);
1014   SET_SENSITIVE ("layers-mask-selection-intersect", layer && !fs && !ac && mask);
1015 
1016   SET_SENSITIVE ("layers-alpha-selection-replace",   layer && !fs && !ac);
1017   SET_SENSITIVE ("layers-alpha-selection-add",       layer && !fs && !ac);
1018   SET_SENSITIVE ("layers-alpha-selection-subtract",  layer && !fs && !ac);
1019   SET_SENSITIVE ("layers-alpha-selection-intersect", layer && !fs && !ac);
1020 
1021 #undef SET_VISIBLE
1022 #undef SET_SENSITIVE
1023 #undef SET_ACTIVE
1024 #undef SET_LABEL
1025 
1026   items_actions_update (group, "layers", GIMP_ITEM (layer));
1027 }
1028