image-actions.c 16.1 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 <http://www.gnu.org/licenses/>.
16 17 18 19
 */

#include "config.h"

20
#include <gegl.h>
21 22 23 24 25 26 27 28 29 30 31 32
#include <gtk/gtk.h>

#include "libgimpwidgets/gimpwidgets.h"

#include "actions-types.h"

#include "config/gimpguiconfig.h"

#include "core/gimp.h"
#include "core/gimpchannel.h"
#include "core/gimpcontext.h"
#include "core/gimpimage.h"
33
#include "core/gimpitemstack.h"
34 35 36 37

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

38
#include "actions.h"
39
#include "image-actions.h"
Michael Natterer's avatar
Michael Natterer committed
40
#include "image-commands.h"
41 42 43 44

#include "gimp-intl.h"


45
static const GimpActionEntry image_actions[] =
46
{
47
  { "image-menubar", NULL,
48
    NC_("image-action", "Image Menu"), NULL, NULL, NULL,
49 50
    GIMP_HELP_IMAGE_WINDOW },

51
  { "image-popup", NULL,
52
    NC_("image-action", "Image Menu"), NULL, NULL, NULL,
53 54
    GIMP_HELP_IMAGE_WINDOW },

55 56
  { "image-menu",             NULL, NC_("image-action", "_Image")      },
  { "image-mode-menu",        NULL, NC_("image-action", "_Mode")       },
57
  { "image-precision-menu",   NULL, NC_("image-action", "_Precision")  },
58 59
  { "image-transform-menu",   NULL, NC_("image-action", "_Transform")  },
  { "image-guides-menu",      NULL, NC_("image-action", "_Guides")     },
60

61 62 63 64 65
  { "colors-menu",            NULL, NC_("image-action", "_Colors")     },
  { "colors-info-menu",       NULL, NC_("image-action", "I_nfo")       },
  { "colors-auto-menu",       NULL, NC_("image-action", "_Auto")       },
  { "colors-map-menu",        NULL, NC_("image-action", "_Map")        },
  { "colors-components-menu", NULL, NC_("image-action", "C_omponents") },
66
  { "colors-desaturate-menu", NULL, NC_("image-action", "D_esaturate") },
67

68
  { "image-new", GTK_STOCK_NEW,
69
    NC_("image-action", "_New..."), "<primary>N",
70
    NC_("image-action", "Create a new image"),
71 72 73
    G_CALLBACK (image_new_cmd_callback),
    GIMP_HELP_FILE_NEW },

74
  { "image-resize", GIMP_STOCK_RESIZE,
75
    NC_("image-action", "Can_vas Size..."), NULL,
76
    NC_("image-action", "Adjust the image dimensions"),
77 78 79
    G_CALLBACK (image_resize_cmd_callback),
    GIMP_HELP_IMAGE_RESIZE },

80
  { "image-resize-to-layers", NULL,
81
    NC_("image-action", "Fit Canvas to L_ayers"), NULL,
82
    NC_("image-action", "Resize the image to enclose all layers"),
83 84 85
    G_CALLBACK (image_resize_to_layers_cmd_callback),
    GIMP_HELP_IMAGE_RESIZE_TO_LAYERS },

86
  { "image-resize-to-selection", NULL,
87
    NC_("image-action", "F_it Canvas to Selection"), NULL,
88
    NC_("image-action", "Resize the image to the extents of the selection"),
89 90 91
    G_CALLBACK (image_resize_to_selection_cmd_callback),
    GIMP_HELP_IMAGE_RESIZE_TO_SELECTION },

92
  { "image-print-size", GIMP_STOCK_PRINT_RESOLUTION,
93
    NC_("image-action", "_Print Size..."), NULL,
94
    NC_("image-action", "Adjust the print resolution"),
95 96 97
    G_CALLBACK (image_print_size_cmd_callback),
    GIMP_HELP_IMAGE_PRINT_SIZE },

98
  { "image-scale", GIMP_STOCK_SCALE,
99
    NC_("image-action", "_Scale Image..."), NULL,
100
    NC_("image-action", "Change the size of the image content"),
101 102 103
    G_CALLBACK (image_scale_cmd_callback),
    GIMP_HELP_IMAGE_SCALE },

104
  { "image-crop-to-selection", GIMP_STOCK_TOOL_CROP,
105
    NC_("image-action", "_Crop to Selection"), NULL,
106
    NC_("image-action", "Crop the image to the extents of the selection"),
107 108 109 110 111 112 113
    G_CALLBACK (image_crop_to_selection_cmd_callback),
    GIMP_HELP_IMAGE_CROP },

  { "image-crop-to-content", GIMP_STOCK_TOOL_CROP,
    NC_("image-action", "Crop to C_ontent"), NULL,
    NC_("image-action", "Crop the image to the extents of its content (remove empty borders from the image)"),
    G_CALLBACK (image_crop_to_content_cmd_callback),
114 115 116
    GIMP_HELP_IMAGE_CROP },

  { "image-duplicate", GIMP_STOCK_DUPLICATE,
117
    NC_("image-action", "_Duplicate"), "<primary>D",
118
    NC_("image-action", "Create a duplicate of this image"),
119 120 121 122
    G_CALLBACK (image_duplicate_cmd_callback),
    GIMP_HELP_IMAGE_DUPLICATE },

  { "image-merge-layers", NULL,
123
    NC_("image-action", "Merge Visible _Layers..."), "<primary>M",
124
    NC_("image-action", "Merge all visible layers into one layer"),
125 126 127 128
    G_CALLBACK (image_merge_layers_cmd_callback),
    GIMP_HELP_IMAGE_MERGE_LAYERS },

  { "image-flatten", NULL,
129
    NC_("image-action", "_Flatten Image"), NULL,
130
    NC_("image-action", "Merge all layers into one and remove transparency"),
131 132 133 134
    G_CALLBACK (image_flatten_image_cmd_callback),
    GIMP_HELP_IMAGE_FLATTEN },

  { "image-configure-grid", GIMP_STOCK_GRID,
135
    NC_("image-action", "Configure G_rid..."), NULL,
136
    NC_("image-action", "Configure the grid for this image"),
137
    G_CALLBACK (image_configure_grid_cmd_callback),
138 139
    GIMP_HELP_IMAGE_GRID },

140
  { "image-properties", GTK_STOCK_INFO,
141
    NC_("image-action", "Image Pr_operties"), "<alt>Return",
142
    NC_("image-action", "Display information about this image"),
143 144
    G_CALLBACK (image_properties_cmd_callback),
    GIMP_HELP_IMAGE_PROPERTIES }
145 146
};

147
static const GimpRadioActionEntry image_convert_base_type_actions[] =
148 149
{
  { "image-convert-rgb", GIMP_STOCK_CONVERT_RGB,
150
    NC_("image-convert-action", "_RGB"), NULL,
151
    NC_("image-convert-action", "Convert the image to the RGB colorspace"),
152
    GIMP_RGB, GIMP_HELP_IMAGE_CONVERT_RGB },
153 154

  { "image-convert-grayscale", GIMP_STOCK_CONVERT_GRAYSCALE,
155
    NC_("image-convert-action", "_Grayscale"), NULL,
156
    NC_("image-convert-action", "Convert the image to grayscale"),
157
    GIMP_GRAY, GIMP_HELP_IMAGE_CONVERT_GRAYSCALE },
158 159

  { "image-convert-indexed", GIMP_STOCK_CONVERT_INDEXED,
160
    NC_("image-convert-action", "_Indexed..."), NULL,
161
    NC_("image-convert-action", "Convert the image to indexed colors"),
162
    GIMP_INDEXED, GIMP_HELP_IMAGE_CONVERT_INDEXED }
163 164
};

165 166
static const GimpRadioActionEntry image_convert_precision_actions[] =
{
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
  { "image-convert-u8-linear", NULL,
    NC_("image-convert-action", "8 bit integer (linear)"), NULL,
    NC_("image-convert-action",
        "Convert the image to 8 bit linear integer"),
    GIMP_PRECISION_U8_LINEAR, GIMP_HELP_IMAGE_CONVERT_U8 },

  { "image-convert-u8-gamma", NULL,
    NC_("image-convert-action", "8 bit integer (gamma)"), NULL,
    NC_("image-convert-action",
        "Convert the image to 8 bit gamma-corrected integer"),
    GIMP_PRECISION_U8_GAMMA, GIMP_HELP_IMAGE_CONVERT_U8 },

  { "image-convert-u16-linear", NULL,
    NC_("image-convert-action", "16 bit integer (linear)"), NULL,
    NC_("image-convert-action",
        "Convert the image to 16 bit linear integer"),
    GIMP_PRECISION_U16_LINEAR, GIMP_HELP_IMAGE_CONVERT_U16 },

  { "image-convert-u16-gamma", NULL,
    NC_("image-convert-action", "16 bit integer (gamma)"), NULL,
    NC_("image-convert-action",
        "Convert the image to 16 bit gamma-corrected integer"),
    GIMP_PRECISION_U16_GAMMA, GIMP_HELP_IMAGE_CONVERT_U16 },

  { "image-convert-u32-linear", NULL,
    NC_("image-convert-action", "32 bit integer (linear)"), NULL,
    NC_("image-convert-action",
        "Convert the image to 32 bit linear integer"),
    GIMP_PRECISION_U32_LINEAR, GIMP_HELP_IMAGE_CONVERT_U32 },

  { "image-convert-u32-gamma", NULL,
    NC_("image-convert-action", "32 bit integer (gamma)"), NULL,
    NC_("image-convert-action",
        "Convert the image to 32 bit gamma-corrected integer"),
    GIMP_PRECISION_U32_GAMMA, GIMP_HELP_IMAGE_CONVERT_U32 },

  { "image-convert-half-linear", NULL,
    NC_("image-convert-action", "16 bit floating point (linear)"), NULL,
    NC_("image-convert-action",
        "Convert the image to 16 bit linear floating point"),
    GIMP_PRECISION_HALF_LINEAR, GIMP_HELP_IMAGE_CONVERT_HALF },

  { "image-convert-half-gamma", NULL,
    NC_("image-convert-action", "16 bit floating point (gamma)"), NULL,
    NC_("image-convert-action",
        "Convert the image to 16 bit gamma-corrected floating point"),
    GIMP_PRECISION_HALF_GAMMA, GIMP_HELP_IMAGE_CONVERT_HALF },

  { "image-convert-float-linear", NULL,
    NC_("image-convert-action", "32 bit floating point (linear)"), NULL,
    NC_("image-convert-action",
        "Convert the image to 32 bit linear floating point"),
    GIMP_PRECISION_FLOAT_LINEAR, GIMP_HELP_IMAGE_CONVERT_FLOAT },

  { "image-convert-float-gamma", NULL,
    NC_("image-convert-action", "32 bit floating point (gamma)"), NULL,
    NC_("image-convert-action",
        "Convert the image to 32 bit gamma-corrected floating point"),
    GIMP_PRECISION_FLOAT_GAMMA, GIMP_HELP_IMAGE_CONVERT_FLOAT }
226 227
};

228
static const GimpEnumActionEntry image_flip_actions[] =
229 230
{
  { "image-flip-horizontal", GIMP_STOCK_FLIP_HORIZONTAL,
231
    NC_("image-action", "Flip _Horizontally"), NULL,
232
    NC_("image-action", "Flip image horizontally"),
233
    GIMP_ORIENTATION_HORIZONTAL, FALSE,
234 235 236
    GIMP_HELP_IMAGE_FLIP_HORIZONTAL },

  { "image-flip-vertical", GIMP_STOCK_FLIP_VERTICAL,
237
    NC_("image-action", "Flip _Vertically"), NULL,
238
    NC_("image-action", "Flip image vertically"),
239
    GIMP_ORIENTATION_VERTICAL, FALSE,
240 241 242
    GIMP_HELP_IMAGE_FLIP_VERTICAL }
};

243
static const GimpEnumActionEntry image_rotate_actions[] =
244 245
{
  { "image-rotate-90", GIMP_STOCK_ROTATE_90,
246
    NC_("image-action", "Rotate 90° _clockwise"), NULL,
247
    NC_("image-action", "Rotate the image 90 degrees to the right"),
248
    GIMP_ROTATE_90, FALSE,
249 250 251
    GIMP_HELP_IMAGE_ROTATE_90 },

  { "image-rotate-180", GIMP_STOCK_ROTATE_180,
252
    NC_("image-action", "Rotate _180°"), NULL,
253
    NC_("image-action", "Turn the image upside-down"),
254
    GIMP_ROTATE_180, FALSE,
255 256 257
    GIMP_HELP_IMAGE_ROTATE_180 },

  { "image-rotate-270", GIMP_STOCK_ROTATE_270,
258
    NC_("image-action", "Rotate 90° counter-clock_wise"), NULL,
259
    NC_("image-action", "Rotate the image 90 degrees to the left"),
260
    GIMP_ROTATE_270, FALSE,
261 262 263 264 265
    GIMP_HELP_IMAGE_ROTATE_270 }
};


void
266
image_actions_setup (GimpActionGroup *group)
267
{
268
  gimp_action_group_add_actions (group, "image-action",
269
                                 image_actions,
270
                                 G_N_ELEMENTS (image_actions));
271

272
  gimp_action_group_add_radio_actions (group, "image-convert-action",
273 274 275 276 277 278 279 280
                                       image_convert_base_type_actions,
                                       G_N_ELEMENTS (image_convert_base_type_actions),
                                       NULL, 0,
                                       G_CALLBACK (image_convert_base_type_cmd_callback));

  gimp_action_group_add_radio_actions (group, "image-convert-action",
                                       image_convert_precision_actions,
                                       G_N_ELEMENTS (image_convert_precision_actions),
281
                                       NULL, 0,
282
                                       G_CALLBACK (image_convert_precision_cmd_callback));
283

284
  gimp_action_group_add_enum_actions (group, "image-action",
285 286
                                      image_flip_actions,
                                      G_N_ELEMENTS (image_flip_actions),
287
                                      G_CALLBACK (image_flip_cmd_callback));
288

289
  gimp_action_group_add_enum_actions (group, "image-action",
290 291
                                      image_rotate_actions,
                                      G_N_ELEMENTS (image_rotate_actions),
292
                                      G_CALLBACK (image_rotate_cmd_callback));
293 294 295 296 297 298 299 300 301

#define SET_ALWAYS_SHOW_IMAGE(action,show) \
        gimp_action_group_set_action_always_show_image (group, action, show)

  SET_ALWAYS_SHOW_IMAGE ("image-rotate-90",  TRUE);
  SET_ALWAYS_SHOW_IMAGE ("image-rotate-180", TRUE);
  SET_ALWAYS_SHOW_IMAGE ("image-rotate-270", TRUE);

#undef SET_ALWAYS_SHOW_IMAGE
302 303 304 305 306 307
}

void
image_actions_update (GimpActionGroup *group,
                      gpointer         data)
{
308 309 310 311 312 313 314
  GimpImage *image       = action_data_get_image (data);
  gboolean   is_indexed  = FALSE;
  gboolean   is_u8_gamma = FALSE;
  gboolean   aux         = FALSE;
  gboolean   lp          = FALSE;
  gboolean   sel         = FALSE;
  gboolean   groups      = FALSE;
315

316
  if (image)
317
    {
318 319
      GimpContainer *layers;
      const gchar   *action = NULL;
320

321
      switch (gimp_image_get_base_type (image))
322
        {
323 324 325 326
        case GIMP_RGB:     action = "image-convert-rgb";       break;
        case GIMP_GRAY:    action = "image-convert-grayscale"; break;
        case GIMP_INDEXED: action = "image-convert-indexed";   break;
        }
327

328
      gimp_action_group_set_action_active (group, action, TRUE);
329

330 331
      switch (gimp_image_get_precision (image))
        {
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
        case GIMP_PRECISION_U8_LINEAR:
          action = "image-convert-u8-linear";
          break;
        case GIMP_PRECISION_U8_GAMMA:
          action = "image-convert-u8-gamma";
          break;
        case GIMP_PRECISION_U16_LINEAR:
          action = "image-convert-u16-linear";
          break;
        case GIMP_PRECISION_U16_GAMMA:
          action = "image-convert-u16-gamma";
          break;
        case GIMP_PRECISION_U32_LINEAR:
          action = "image-convert-u32-linear";
          break;
        case GIMP_PRECISION_U32_GAMMA:
          action = "image-convert-u32-gamma";
          break;
        case GIMP_PRECISION_HALF_LINEAR:
          action = "image-convert-half-linear";
          break;
        case GIMP_PRECISION_HALF_GAMMA:
          action = "image-convert-half-gamma";
          break;
        case GIMP_PRECISION_FLOAT_LINEAR:
          action = "image-convert-float-linear";
          break;
        case GIMP_PRECISION_FLOAT_GAMMA:
          action = "image-convert-float-gamma";
          break;
362 363 364
        }

      gimp_action_group_set_action_active (group, action, TRUE);
365

366 367 368 369 370 371
      is_indexed  = (gimp_image_get_base_type (image) == GIMP_INDEXED);
      is_u8_gamma = (gimp_image_get_precision (image) ==
                     GIMP_PRECISION_U8_GAMMA);
      aux         = (gimp_image_get_active_channel (image) != NULL);
      lp          = ! gimp_image_is_empty (image);
      sel         = ! gimp_channel_is_empty (gimp_image_get_mask (image));
372 373 374 375

      layers = gimp_image_get_layers (image);

      groups = ! gimp_item_stack_is_flat (GIMP_ITEM_STACK (layers));
376 377 378 379 380
    }

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

381 382
  SET_SENSITIVE ("image-convert-rgb",       image);
  SET_SENSITIVE ("image-convert-grayscale", image);
383 384 385 386 387 388 389 390 391 392 393 394
  SET_SENSITIVE ("image-convert-indexed",   image && !groups && is_u8_gamma);

  SET_SENSITIVE ("image-convert-u8-gamma",     image);
  SET_SENSITIVE ("image-convert-u8-linear",    image && !is_indexed);
  SET_SENSITIVE ("image-convert-u16-gamma",    image && !is_indexed);
  SET_SENSITIVE ("image-convert-u16-linear",   image && !is_indexed);
  SET_SENSITIVE ("image-convert-u32-gamma",    image && !is_indexed);
  SET_SENSITIVE ("image-convert-u32-linear",   image && !is_indexed);
  SET_SENSITIVE ("image-convert-half-gamma",   image && !is_indexed);
  SET_SENSITIVE ("image-convert-half-linear",  image && !is_indexed);
  SET_SENSITIVE ("image-convert-float-gamma",  image && !is_indexed);
  SET_SENSITIVE ("image-convert-float-linear", image && !is_indexed);
395

396 397 398 399 400 401
  SET_SENSITIVE ("image-flip-horizontal", image);
  SET_SENSITIVE ("image-flip-vertical",   image);
  SET_SENSITIVE ("image-rotate-90",       image);
  SET_SENSITIVE ("image-rotate-180",      image);
  SET_SENSITIVE ("image-rotate-270",      image);

402 403 404 405 406
  SET_SENSITIVE ("image-resize",              image);
  SET_SENSITIVE ("image-resize-to-layers",    image);
  SET_SENSITIVE ("image-resize-to-selection", image && sel);
  SET_SENSITIVE ("image-print-size",          image);
  SET_SENSITIVE ("image-scale",               image);
407 408
  SET_SENSITIVE ("image-crop-to-selection",   image && sel);
  SET_SENSITIVE ("image-crop-to-content",     image);
409
  SET_SENSITIVE ("image-duplicate",           image);
410 411
  SET_SENSITIVE ("image-merge-layers",        image && !aux && lp);
  SET_SENSITIVE ("image-flatten",             image && !aux && lp);
412 413
  SET_SENSITIVE ("image-configure-grid",      image);
  SET_SENSITIVE ("image-properties",          image);
414 415 416

#undef SET_SENSITIVE
}