GitLab repository storage has been migrated to hashed layout. Please contact Infrastructure team if you notice any issues with repositories or hooks.

view-actions.c 30.3 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
#include <gtk/gtk.h>

23
#include "libgimpmath/gimpmath.h"
24
#include "libgimpcolor/gimpcolor.h"
25 26 27 28
#include "libgimpwidgets/gimpwidgets.h"

#include "actions-types.h"

29
#include "config/gimpdisplayoptions.h"
30 31 32 33 34 35 36
#include "config/gimpguiconfig.h"

#include "core/gimp.h"
#include "core/gimpcontext.h"
#include "core/gimpimage.h"

#include "widgets/gimpactiongroup.h"
37
#include "widgets/gimprender.h"
38
#include "widgets/gimphelp-ids.h"
39
#include "widgets/gimpwidgets-utils.h"
40 41 42 43

#include "display/gimpdisplay.h"
#include "display/gimpdisplayshell.h"
#include "display/gimpdisplayshell-appearance.h"
44
#include "display/gimpdisplayshell-scale.h"
45
#include "display/gimpimagewindow.h"
46

47
#include "actions.h"
48
#include "view-actions.h"
Michael Natterer's avatar
Michael Natterer committed
49
#include "view-commands.h"
50
#include "window-actions.h"
51
#include "window-commands.h"
52 53 54 55 56 57

#include "gimp-intl.h"


/*  local function prototypes  */

58 59
static void   view_actions_set_zoom          (GimpActionGroup   *group,
                                              GimpDisplayShell  *shell);
60 61
static void   view_actions_set_rotate        (GimpActionGroup   *group,
                                              GimpDisplayShell  *shell);
62 63 64
static void   view_actions_check_type_notify (GimpDisplayConfig *config,
                                              GParamSpec        *pspec,
                                              GimpActionGroup   *group);
65 66


67
static const GimpActionEntry view_actions[] =
68
{
69 70
  { "view-menu",                NULL, NC_("view-action", "_View")          },
  { "view-zoom-menu",           NULL, NC_("view-action", "_Zoom")          },
71
  { "view-rotate-menu",         NULL, NC_("view-action", "_Rotate")        },
72
  { "view-padding-color-menu",  NULL, NC_("view-action", "_Padding Color") },
73
  { "view-move-to-screen-menu", GIMP_STOCK_MOVE_TO_SCREEN,
74
    NC_("view-action", "Move to Screen"), NULL, NULL, NULL,
75
    GIMP_HELP_VIEW_CHANGE_SCREEN },
76

77 78
  { "view-new", "window-new",
    NC_("view-action", "_New View"), NULL,
79
    NC_("view-action", "Create another view on this image"),
80
    G_CALLBACK (view_new_cmd_callback),
81 82
    GIMP_HELP_VIEW_NEW },

83
  { "view-close", "window-close",
84 85 86
    NC_("view-action",  "_Close View"), "<primary>W",
    NC_("view-action", "Close the active image view"),
    G_CALLBACK (view_close_cmd_callback),
87 88
    GIMP_HELP_FILE_CLOSE },

89
  { "view-zoom-fit-in", "zoom-fit-best",
90
    NC_("view-action", "_Fit Image in Window"), "<primary><shift>J",
91
    NC_("view-action", "Adjust the zoom ratio so that the image becomes fully visible"),
92 93 94
    G_CALLBACK (view_zoom_fit_in_cmd_callback),
    GIMP_HELP_VIEW_ZOOM_FIT_IN },

95
  { "view-zoom-fill", "zoom-fit-best",
96
    NC_("view-action", "Fi_ll Window"), NULL,
97
    NC_("view-action", "Adjust the zoom ratio so that the entire window is used"),
98 99
    G_CALLBACK (view_zoom_fill_cmd_callback),
    GIMP_HELP_VIEW_ZOOM_FILL },
100

101 102 103 104 105 106
  { "view-zoom-selection", "gimp-selection",
    NC_("view-action", "Zoom to _Selection"), NULL,
    NC_("view-action", "Adjust the zoom ratio so that the selection fills the window"),
    G_CALLBACK (view_zoom_selection_cmd_callback),
    GIMP_HELP_VIEW_ZOOM_SELECTION },

107
  { "view-zoom-revert", NULL,
108
    NC_("view-action", "Re_vert Zoom"), "grave",
109
    NC_("view-action", "Restore the previous zoom level"),
110 111 112
    G_CALLBACK (view_zoom_revert_cmd_callback),
    GIMP_HELP_VIEW_ZOOM_REVERT },

113 114 115
  { "view-rotate-other", NULL,
    NC_("view-action", "Othe_r..."), NULL,
    NC_("view-action", "Set a custom rotation angle"),
116
    G_CALLBACK (view_rotate_other_cmd_callback),
117 118
    GIMP_HELP_VIEW_ROTATE_OTHER },

119
  { "view-navigation-window", GIMP_STOCK_NAVIGATION,
120
    NC_("view-action", "Na_vigation Window"), NULL,
121
    NC_("view-action", "Show an overview window for this image"),
122 123 124 125
    G_CALLBACK (view_navigation_window_cmd_callback),
    GIMP_HELP_NAVIGATION_DIALOG },

  { "view-display-filters", GIMP_STOCK_DISPLAY_FILTER,
126
    NC_("view-action", "Display _Filters..."), NULL,
127
    NC_("view-action", "Configure filters applied to this view"),
128 129 130
    G_CALLBACK (view_display_filters_cmd_callback),
    GIMP_HELP_DISPLAY_FILTER_DIALOG },

131
  { "view-shrink-wrap", "zoom-fit-best",
132
    NC_("view-action", "Shrink _Wrap"), "<primary>J",
133
    NC_("view-action", "Reduce the image window to the size of the image display"),
134
    G_CALLBACK (view_shrink_wrap_cmd_callback),
135 136 137
    GIMP_HELP_VIEW_SHRINK_WRAP },

  { "view-open-display", NULL,
138
    NC_("view-action", "_Open Display..."), NULL,
139
    NC_("view-action", "Connect to another display"),
140 141
    G_CALLBACK (window_open_display_cmd_callback),
    NULL }
142 143
};

144
static const GimpToggleActionEntry view_toggle_actions[] =
145 146
{
  { "view-dot-for-dot", NULL,
147
    NC_("view-action", "_Dot for Dot"), NULL,
148
    NC_("view-action", "A pixel on the screen represents an image pixel"),
149 150 151 152 153
    G_CALLBACK (view_dot_for_dot_cmd_callback),
    TRUE,
    GIMP_HELP_VIEW_DOT_FOR_DOT },

  { "view-show-selection", NULL,
154
    NC_("view-action", "Show _Selection"), "<primary>T",
155
    NC_("view-action", "Display the selection outline"),
156 157 158 159 160
    G_CALLBACK (view_toggle_selection_cmd_callback),
    TRUE,
    GIMP_HELP_VIEW_SHOW_SELECTION },

  { "view-show-layer-boundary", NULL,
161
    NC_("view-action", "Show _Layer Boundary"), NULL,
162
    NC_("view-action", "Draw a border around the active layer"),
163 164 165 166 167
    G_CALLBACK (view_toggle_layer_boundary_cmd_callback),
    TRUE,
    GIMP_HELP_VIEW_SHOW_LAYER_BOUNDARY },

  { "view-show-guides", NULL,
168
    NC_("view-action", "Show _Guides"), "<primary><shift>T",
169
    NC_("view-action", "Display the image's guides"),
170 171 172 173 174
    G_CALLBACK (view_toggle_guides_cmd_callback),
    TRUE,
    GIMP_HELP_VIEW_SHOW_GUIDES },

  { "view-show-grid", NULL,
175
    NC_("view-action", "S_how Grid"), NULL,
176
    NC_("view-action", "Display the image's grid"),
177 178 179 180
    G_CALLBACK (view_toggle_grid_cmd_callback),
    FALSE,
    GIMP_HELP_VIEW_SHOW_GRID },

181
  { "view-show-sample-points", NULL,
182
    NC_("view-action", "Show Sample Points"), NULL,
183
    NC_("view-action", "Display the image's color sample points"),
184 185 186 187
    G_CALLBACK (view_toggle_sample_points_cmd_callback),
    TRUE,
    GIMP_HELP_VIEW_SHOW_SAMPLE_POINTS },

188
  { "view-snap-to-guides", NULL,
189
    NC_("view-action", "Sn_ap to Guides"), NULL,
190
    NC_("view-action", "Tool operations snap to guides"),
191 192 193 194
    G_CALLBACK (view_snap_to_guides_cmd_callback),
    TRUE,
    GIMP_HELP_VIEW_SNAP_TO_GUIDES },

195
  { "view-snap-to-grid", NULL,
196
    NC_("view-action", "Sna_p to Grid"), NULL,
197
    NC_("view-action", "Tool operations snap to the grid"),
198 199 200 201
    G_CALLBACK (view_snap_to_grid_cmd_callback),
    FALSE,
    GIMP_HELP_VIEW_SNAP_TO_GRID },

202
  { "view-snap-to-canvas", NULL,
203
    NC_("view-action", "Snap to _Canvas Edges"), NULL,
204
    NC_("view-action", "Tool operations snap to the canvas edges"),
205 206 207 208 209
    G_CALLBACK (view_snap_to_canvas_cmd_callback),
    FALSE,
    GIMP_HELP_VIEW_SNAP_TO_CANVAS },

  { "view-snap-to-vectors", NULL,
210
    NC_("view-action", "Snap t_o Active Path"), NULL,
211
    NC_("view-action", "Tool operations snap to the active path"),
212 213 214 215
    G_CALLBACK (view_snap_to_vectors_cmd_callback),
    FALSE,
    GIMP_HELP_VIEW_SNAP_TO_VECTORS },

216
  { "view-show-menubar", NULL,
217
    NC_("view-action", "Show _Menubar"), NULL,
218
    NC_("view-action", "Show this window's menubar"),
219 220 221 222 223
    G_CALLBACK (view_toggle_menubar_cmd_callback),
    TRUE,
    GIMP_HELP_VIEW_SHOW_MENUBAR },

  { "view-show-rulers", NULL,
224
    NC_("view-action", "Show R_ulers"), "<primary><shift>R",
225
    NC_("view-action", "Show this window's rulers"),
226 227 228 229 230
    G_CALLBACK (view_toggle_rulers_cmd_callback),
    TRUE,
    GIMP_HELP_VIEW_SHOW_RULERS },

  { "view-show-scrollbars", NULL,
231
    NC_("view-action", "Show Scroll_bars"), NULL,
232
    NC_("view-action", "Show this window's scrollbars"),
233 234 235 236 237
    G_CALLBACK (view_toggle_scrollbars_cmd_callback),
    TRUE,
    GIMP_HELP_VIEW_SHOW_SCROLLBARS },

  { "view-show-statusbar", NULL,
238
    NC_("view-action", "Show S_tatusbar"), NULL,
239
    NC_("view-action", "Show this window's statusbar"),
240 241 242 243
    G_CALLBACK (view_toggle_statusbar_cmd_callback),
    TRUE,
    GIMP_HELP_VIEW_SHOW_STATUSBAR },

244
  { "view-fullscreen", "view-fullscreen",
245
    NC_("view-action", "Fullscr_een"), "F11",
246
    NC_("view-action", "Toggle fullscreen view"),
247 248
    G_CALLBACK (view_fullscreen_cmd_callback),
    FALSE,
249
    GIMP_HELP_VIEW_FULLSCREEN }
250 251
};

252
static const GimpEnumActionEntry view_zoom_actions[] =
253 254 255
{
  { "view-zoom", NULL,
    "Set zoom factor", NULL, NULL,
256
    GIMP_ACTION_SELECT_SET, TRUE,
257
    NULL },
258

259
  { "view-zoom-minimum", "zoom-out",
260
    "Zoom out as far as possible", NULL, NULL,
261
    GIMP_ACTION_SELECT_FIRST, FALSE,
262 263
    GIMP_HELP_VIEW_ZOOM_OUT },

264
  { "view-zoom-maximum", "zoom-in",
265
    "Zoom in as far as possible", NULL, NULL,
266
    GIMP_ACTION_SELECT_LAST, FALSE,
267 268
    GIMP_HELP_VIEW_ZOOM_IN },

269
  { "view-zoom-out", "zoom-out",
270
    NC_("view-zoom-action", "Zoom _Out"), "minus",
271
    NC_("view-zoom-action", "Zoom out"),
272
    GIMP_ACTION_SELECT_PREVIOUS, FALSE,
273
    GIMP_HELP_VIEW_ZOOM_OUT },
274

275
  { "view-zoom-in", "zoom-in",
276
    NC_("view-zoom-action", "Zoom _In"), "plus",
277
    NC_("view-zoom-action", "Zoom in"),
278
    GIMP_ACTION_SELECT_NEXT, FALSE,
279
    GIMP_HELP_VIEW_ZOOM_IN },
280

281
  { "view-zoom-out-accel", GIMP_STOCK_CHAR_PICKER,
282
    NC_("view-zoom-action", "Zoom Out"), "KP_Subtract",
283
    NC_("view-zoom-action", "Zoom out"),
284
    GIMP_ACTION_SELECT_PREVIOUS, FALSE,
285
    GIMP_HELP_VIEW_ZOOM_OUT },
286

287
  { "view-zoom-in-accel", GIMP_STOCK_CHAR_PICKER,
288
    NC_("view-zoom-action", "Zoom In"), "KP_Add",
289
    NC_("view-zoom-action", "Zoom in"),
290
    GIMP_ACTION_SELECT_NEXT, FALSE,
291
    GIMP_HELP_VIEW_ZOOM_IN },
292

293
  { "view-zoom-out-skip", "zoom-out",
294
    "Zoom out a lot", NULL, NULL,
295
    GIMP_ACTION_SELECT_SKIP_PREVIOUS, FALSE,
296 297
    GIMP_HELP_VIEW_ZOOM_OUT },

298
  { "view-zoom-in-skip", "zoom-in",
299
    "Zoom in a lot", NULL, NULL,
300
    GIMP_ACTION_SELECT_SKIP_NEXT, FALSE,
301
    GIMP_HELP_VIEW_ZOOM_IN }
302 303
};

304
static const GimpRadioActionEntry view_zoom_explicit_actions[] =
305 306
{
  { "view-zoom-16-1", NULL,
307
    NC_("view-zoom-action", "1_6:1  (1600%)"), "5",
308
    NC_("view-zoom-action", "Zoom 16:1"),
309 310 311
    160000,
    GIMP_HELP_VIEW_ZOOM_IN },

312 313 314 315 316 317
  { "view-zoom-16-1-accel", NULL,
    NC_("view-zoom-action", "1_6:1  (1600%)"), "KP_5",
    NC_("view-zoom-action", "Zoom 16:1"),
    160000,
    GIMP_HELP_VIEW_ZOOM_IN },

318
  { "view-zoom-8-1", NULL,
319
    NC_("view-zoom-action", "_8:1  (800%)"), "4",
320
    NC_("view-zoom-action", "Zoom 8:1"),
321 322 323
    80000,
    GIMP_HELP_VIEW_ZOOM_IN },

324 325 326 327 328 329
  { "view-zoom-8-1-accel", NULL,
    NC_("view-zoom-action", "_8:1  (800%)"), "KP_4",
    NC_("view-zoom-action", "Zoom 8:1"),
    80000,
    GIMP_HELP_VIEW_ZOOM_IN },

330
  { "view-zoom-4-1", NULL,
331
    NC_("view-zoom-action", "_4:1  (400%)"), "3",
332
    NC_("view-zoom-action", "Zoom 4:1"),
333 334 335
    40000,
    GIMP_HELP_VIEW_ZOOM_IN },

336 337 338 339 340 341
  { "view-zoom-4-1-accel", NULL,
    NC_("view-zoom-action", "_4:1  (400%)"), "KP_3",
    NC_("view-zoom-action", "Zoom 4:1"),
    40000,
    GIMP_HELP_VIEW_ZOOM_IN },

342
  { "view-zoom-2-1", NULL,
343
    NC_("view-zoom-action", "_2:1  (200%)"), "2",
344
    NC_("view-zoom-action", "Zoom 2:1"),
345 346 347
    20000,
    GIMP_HELP_VIEW_ZOOM_IN },

348 349 350 351 352 353
  { "view-zoom-2-1-accel", NULL,
    NC_("view-zoom-action", "_2:1  (200%)"), "KP_2",
    NC_("view-zoom-action", "Zoom 2:1"),
    20000,
    GIMP_HELP_VIEW_ZOOM_IN },

354
  { "view-zoom-1-1", "zoom-original",
355
    NC_("view-zoom-action", "_1:1  (100%)"), "1",
356
    NC_("view-zoom-action", "Zoom 1:1"),
357 358 359
    10000,
    GIMP_HELP_VIEW_ZOOM_100 },

360
  { "view-zoom-1-1-accel", "zoom-original",
361 362 363 364 365
    NC_("view-zoom-action", "_1:1  (100%)"), "KP_1",
    NC_("view-zoom-action", "Zoom 1:1"),
    10000,
    GIMP_HELP_VIEW_ZOOM_100 },

366
  { "view-zoom-1-2", NULL,
367
    NC_("view-zoom-action", "1:_2  (50%)"), "<shift>2",
368
    NC_("view-zoom-action", "Zoom 1:2"),
369 370 371 372
    5000,
    GIMP_HELP_VIEW_ZOOM_OUT },

  { "view-zoom-1-4", NULL,
373
    NC_("view-zoom-action", "1:_4  (25%)"), "<shift>3",
374
    NC_("view-zoom-action", "Zoom 1:4"),
375 376 377 378
    2500,
    GIMP_HELP_VIEW_ZOOM_OUT },

  { "view-zoom-1-8", NULL,
379
    NC_("view-zoom-action", "1:_8  (12.5%)"), "<shift>4",
380
    NC_("view-zoom-action", "Zoom 1:8"),
381 382 383 384
    1250,
    GIMP_HELP_VIEW_ZOOM_OUT },

  { "view-zoom-1-16", NULL,
385
    NC_("view-zoom-action", "1:1_6  (6.25%)"), "<shift>5",
386
    NC_("view-zoom-action", "Zoom 1:16"),
387 388 389 390
    625,
    GIMP_HELP_VIEW_ZOOM_OUT },

  { "view-zoom-other", NULL,
391
    NC_("view-zoom-action", "Othe_r..."), NULL,
392
    NC_("view-zoom-action", "Set a custom zoom factor"),
393 394 395 396
    0,
    GIMP_HELP_VIEW_ZOOM_OTHER }
};

397 398 399 400 401 402 403 404 405 406 407 408 409 410
static const GimpEnumActionEntry view_rotate_absolute_actions[] =
{
  { "view-rotate-set-absolute", NULL,
    "Display Rotation Absolute Angle Set", NULL, NULL,
    GIMP_ACTION_SELECT_SET, TRUE,
    NULL },

  { "view-rotate-reset", GIMP_STOCK_RESET,
    NC_("view-action", "_Reset to 0°"), "exclam",
    NC_("view-action", "Reset the angle of rotation to 0°"),
    GIMP_ACTION_SELECT_SET_TO_DEFAULT, FALSE,
    GIMP_HELP_VIEW_ROTATE_RESET },
};

411
static const GimpEnumActionEntry view_rotate_relative_actions[] =
412
{
413 414 415 416 417 418
  { "view-rotate-15", GIMP_STOCK_ROTATE_90,
    NC_("view-action", "Rotate 15° _clockwise"), NULL,
    NC_("view-action", "Rotate 15 degrees to the right"),
    GIMP_ACTION_SELECT_NEXT, FALSE,
    GIMP_HELP_VIEW_ROTATE_15 },

419 420 421
  { "view-rotate-90", GIMP_STOCK_ROTATE_90,
    NC_("view-action", "Rotate 90° _clockwise"), NULL,
    NC_("view-action", "Rotate 90 degrees to the right"),
422
    GIMP_ACTION_SELECT_SKIP_NEXT, FALSE,
423 424 425 426 427
    GIMP_HELP_VIEW_ROTATE_90 },

  { "view-rotate-180", GIMP_STOCK_ROTATE_180,
    NC_("view-action", "Rotate _180°"), NULL,
    NC_("view-action", "Turn upside-down"),
428
    GIMP_ACTION_SELECT_LAST, FALSE,
429 430 431 432 433
    GIMP_HELP_VIEW_ROTATE_180 },

  { "view-rotate-270", GIMP_STOCK_ROTATE_270,
    NC_("view-action", "Rotate 90° counter-clock_wise"), NULL,
    NC_("view-action", "Rotate 90 degrees to the left"),
434 435 436 437 438 439 440 441
    GIMP_ACTION_SELECT_SKIP_PREVIOUS, FALSE,
    GIMP_HELP_VIEW_ROTATE_270 },

  { "view-rotate-345", GIMP_STOCK_ROTATE_270,
    NC_("view-action", "Rotate 15° counter-clock_wise"), NULL,
    NC_("view-action", "Rotate 15 degrees to the left"),
    GIMP_ACTION_SELECT_PREVIOUS, FALSE,
    GIMP_HELP_VIEW_ROTATE_345 }
442 443
};

444
static const GimpEnumActionEntry view_padding_color_actions[] =
445 446
{
  { "view-padding-color-theme", NULL,
447
    NC_("view-padding-color", "From _Theme"), NULL,
448
    NC_("view-padding-color", "Use the current theme's background color"),
449
    GIMP_CANVAS_PADDING_MODE_DEFAULT, FALSE,
450 451 452
    GIMP_HELP_VIEW_PADDING_COLOR },

  { "view-padding-color-light-check", NULL,
453
    NC_("view-padding-color", "_Light Check Color"), NULL,
454
    NC_("view-padding-color", "Use the light check color"),
455
    GIMP_CANVAS_PADDING_MODE_LIGHT_CHECK, FALSE,
456 457 458
    GIMP_HELP_VIEW_PADDING_COLOR },

  { "view-padding-color-dark-check", NULL,
459
    NC_("view-padding-color", "_Dark Check Color"), NULL,
460
    NC_("view-padding-color", "Use the dark check color"),
461
    GIMP_CANVAS_PADDING_MODE_DARK_CHECK, FALSE,
462 463
    GIMP_HELP_VIEW_PADDING_COLOR },

464
  { "view-padding-color-custom", "gtk-select-color",
465
    NC_("view-padding-color", "Select _Custom Color..."), NULL,
466
    NC_("view-padding-color", "Use an arbitrary color"),
467
    GIMP_CANVAS_PADDING_MODE_CUSTOM, FALSE,
468 469 470
    GIMP_HELP_VIEW_PADDING_COLOR },

  { "view-padding-color-prefs", GIMP_STOCK_RESET,
471
    NC_("view-padding-color", "As in _Preferences"), NULL,
472 473
    NC_("view-padding-color",
        "Reset padding color to what's configured in preferences"),
474
    GIMP_CANVAS_PADDING_MODE_RESET, FALSE,
475 476 477
    GIMP_HELP_VIEW_PADDING_COLOR }
};

478
static const GimpEnumActionEntry view_scroll_horizontal_actions[] =
479 480 481
{
  { "view-scroll-horizontal", NULL,
    "Set horizontal scroll offset", NULL, NULL,
482
    GIMP_ACTION_SELECT_SET, TRUE,
483
    NULL },
484

485 486
  { "view-scroll-left-border", NULL,
    "Scroll to left border", NULL, NULL,
487
    GIMP_ACTION_SELECT_FIRST, FALSE,
488
    NULL },
489

490 491
  { "view-scroll-right-border", NULL,
    "Scroll to right border", NULL, NULL,
492
    GIMP_ACTION_SELECT_LAST, FALSE,
493
    NULL },
494

495 496
  { "view-scroll-left", NULL,
    "Scroll left", NULL, NULL,
497
    GIMP_ACTION_SELECT_PREVIOUS, FALSE,
498
    NULL },
499

500 501
  { "view-scroll-right", NULL,
    "Scroll right", NULL, NULL,
502
    GIMP_ACTION_SELECT_NEXT, FALSE,
503
    NULL },
504

505 506
  { "view-scroll-page-left", NULL,
    "Scroll page left", NULL, NULL,
507
    GIMP_ACTION_SELECT_SKIP_PREVIOUS, FALSE,
508
    NULL },
509

510 511
  { "view-scroll-page-right", NULL,
    "Scroll page right", NULL, NULL,
512
    GIMP_ACTION_SELECT_SKIP_NEXT, FALSE,
513 514 515
    NULL }
};

516
static const GimpEnumActionEntry view_scroll_vertical_actions[] =
517 518 519
{
  { "view-scroll-vertical", NULL,
    "Set vertical scroll offset", NULL, NULL,
520
    GIMP_ACTION_SELECT_SET, TRUE,
521
    NULL },
522

523 524
  { "view-scroll-top-border", NULL,
    "Scroll to top border", NULL, NULL,
525
    GIMP_ACTION_SELECT_FIRST, FALSE,
526
    NULL },
527

528 529
  { "view-scroll-bottom-border", NULL,
    "Scroll to bottom border", NULL, NULL,
530
    GIMP_ACTION_SELECT_LAST, FALSE,
531
    NULL },
532

533 534
  { "view-scroll-up", NULL,
    "Scroll up", NULL, NULL,
535
    GIMP_ACTION_SELECT_PREVIOUS, FALSE,
536
    NULL },
537

538 539
  { "view-scroll-down", NULL,
    "Scroll down", NULL, NULL,
540
    GIMP_ACTION_SELECT_NEXT, FALSE,
541
    NULL },
542

543 544
  { "view-scroll-page-up", NULL,
    "Scroll page up", NULL, NULL,
545
    GIMP_ACTION_SELECT_SKIP_PREVIOUS, FALSE,
546
    NULL },
547

548 549
  { "view-scroll-page-down", NULL,
    "Scroll page down", NULL, NULL,
550
    GIMP_ACTION_SELECT_SKIP_NEXT, FALSE,
551 552 553
    NULL }
};

554 555

void
556
view_actions_setup (GimpActionGroup *group)
557
{
558 559
  GtkAction *action;

560
  gimp_action_group_add_actions (group, "view-action",
561
                                 view_actions,
562
                                 G_N_ELEMENTS (view_actions));
563

564
  gimp_action_group_add_toggle_actions (group, "view-action",
565
                                        view_toggle_actions,
566
                                        G_N_ELEMENTS (view_toggle_actions));
567

568
  gimp_action_group_add_enum_actions (group, "view-zoom-action",
569 570 571 572
                                      view_zoom_actions,
                                      G_N_ELEMENTS (view_zoom_actions),
                                      G_CALLBACK (view_zoom_cmd_callback));

573
  gimp_action_group_add_radio_actions (group, "view-zoom-action",
574 575
                                       view_zoom_explicit_actions,
                                       G_N_ELEMENTS (view_zoom_explicit_actions),
576
                                       NULL,
577
                                       10000,
578
                                       G_CALLBACK (view_zoom_explicit_cmd_callback));
579

580 581 582 583 584
  gimp_action_group_add_enum_actions (group, "view-action",
                                      view_rotate_absolute_actions,
                                      G_N_ELEMENTS (view_rotate_absolute_actions),
                                      G_CALLBACK (view_rotate_absolute_cmd_callback));

585
  gimp_action_group_add_enum_actions (group, "view-action",
586 587 588
                                      view_rotate_relative_actions,
                                      G_N_ELEMENTS (view_rotate_relative_actions),
                                      G_CALLBACK (view_rotate_relative_cmd_callback));
589

590
  gimp_action_group_add_enum_actions (group, "view-padding-color",
591 592 593 594
                                      view_padding_color_actions,
                                      G_N_ELEMENTS (view_padding_color_actions),
                                      G_CALLBACK (view_padding_color_cmd_callback));

595
  gimp_action_group_add_enum_actions (group, NULL,
596 597 598 599
                                      view_scroll_horizontal_actions,
                                      G_N_ELEMENTS (view_scroll_horizontal_actions),
                                      G_CALLBACK (view_scroll_horizontal_cmd_callback));

600
  gimp_action_group_add_enum_actions (group, NULL,
601 602 603 604
                                      view_scroll_vertical_actions,
                                      G_N_ELEMENTS (view_scroll_vertical_actions),
                                      G_CALLBACK (view_scroll_vertical_cmd_callback));

605 606 607 608 609 610 611 612
  /*  connect "activate" of view-zoom-other manually so it can be
   *  selected even if it's the active item of the radio group
   */
  action = gtk_action_group_get_action (GTK_ACTION_GROUP (group),
                                        "view-zoom-other");
  g_signal_connect (action, "activate",
                    G_CALLBACK (view_zoom_other_cmd_callback),
                    group->user_data);
613 614 615 616 617 618

  g_signal_connect_object (group->gimp->config, "notify::check-type",
                           G_CALLBACK (view_actions_check_type_notify),
                           group, 0);
  view_actions_check_type_notify (GIMP_DISPLAY_CONFIG (group->gimp->config),
                                  NULL, group);
619

620
  if (GIMP_IS_IMAGE_WINDOW (group->user_data) ||
621 622 623 624 625 626 627 628 629
      GIMP_IS_GIMP (group->user_data))
    {
      /*  add window actions only if the context of the group is
       *  the display itself or the global popup (not if the context
       *  is a dock)
       *  (see dock-actions.c)
       */
      window_actions_setup (group, GIMP_HELP_VIEW_CHANGE_SCREEN);
    }
630 631 632 633 634 635
}

void
view_actions_update (GimpActionGroup *group,
                     gpointer         data)
{
636
  GimpDisplay        *display        = action_data_get_display (data);
637
  GimpImage          *image          = NULL;
638 639 640 641 642
  GimpDisplayShell   *shell          = NULL;
  GimpDisplayOptions *options        = NULL;
  gchar              *label          = NULL;
  gboolean            fullscreen     = FALSE;
  gboolean            revert_enabled = FALSE;   /* able to revert zoom? */
643

644
  if (display)
645
    {
646
      GimpImageWindow *window;
647

648
      image  = gimp_display_get_image (display);
649
      shell  = gimp_display_get_shell (display);
650
      window = gimp_display_shell_get_window (shell);
651

652 653
      if (window)
        fullscreen = gimp_image_window_get_fullscreen (window);
654

655 656 657
      options = (image ?
                 (fullscreen ? shell->fullscreen_options : shell->options) :
                 shell->no_image_options);
658 659

      revert_enabled = gimp_display_shell_scale_can_revert (shell);
660 661 662 663 664 665
    }

#define SET_ACTIVE(action,condition) \
        gimp_action_group_set_action_active (group, action, (condition) != 0)
#define SET_SENSITIVE(action,condition) \
        gimp_action_group_set_action_sensitive (group, action, (condition) != 0)
666 667
#define SET_COLOR(action,color) \
        gimp_action_group_set_action_color (group, action, color, FALSE)
668

669
  SET_SENSITIVE ("view-new",   image);
670
  SET_SENSITIVE ("view-close", image);
671

672
  SET_SENSITIVE ("view-dot-for-dot", image);
673 674
  SET_ACTIVE    ("view-dot-for-dot", display && shell->dot_for_dot);

675 676 677 678 679 680 681 682 683 684 685
  SET_SENSITIVE ("view-zoom-revert", revert_enabled);
  if (revert_enabled)
    {
      label = g_strdup_printf (_("Re_vert Zoom (%d%%)"),
                               ROUND (shell->last_scale * 100));
      gimp_action_group_set_action_label (group, "view-zoom-revert", label);
      g_free (label);
    }
  else
    {
      gimp_action_group_set_action_label (group, "view-zoom-revert",
686
                                          _("Re_vert Zoom"));
687 688
    }

689 690 691 692 693 694 695 696 697 698 699 700
  SET_SENSITIVE ("view-zoom",            image);
  SET_SENSITIVE ("view-zoom-minimum",    image);
  SET_SENSITIVE ("view-zoom-maximum",    image);
  SET_SENSITIVE ("view-zoom-in",         image);
  SET_SENSITIVE ("view-zoom-in-accel",   image);
  SET_SENSITIVE ("view-zoom-in-skip",    image);
  SET_SENSITIVE ("view-zoom-out",        image);
  SET_SENSITIVE ("view-zoom-out-accel",  image);
  SET_SENSITIVE ("view-zoom-out-skip",   image);

  SET_SENSITIVE ("view-zoom-fit-in",     image);
  SET_SENSITIVE ("view-zoom-fill",       image);
701
  SET_SENSITIVE ("view-zoom-selection",  image);
702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720
  SET_SENSITIVE ("view-zoom-revert",     image);

  SET_SENSITIVE ("view-zoom-16-1",       image);
  SET_SENSITIVE ("view-zoom-16-1-accel", image);
  SET_SENSITIVE ("view-zoom-8-1",        image);
  SET_SENSITIVE ("view-zoom-8-1-accel",  image);
  SET_SENSITIVE ("view-zoom-4-1",        image);
  SET_SENSITIVE ("view-zoom-4-1-accel",  image);
  SET_SENSITIVE ("view-zoom-2-1",        image);
  SET_SENSITIVE ("view-zoom-2-1-accel",  image);
  SET_SENSITIVE ("view-zoom-1-1",        image);
  SET_SENSITIVE ("view-zoom-1-1-accel",  image);
  SET_SENSITIVE ("view-zoom-1-2",        image);
  SET_SENSITIVE ("view-zoom-1-4",        image);
  SET_SENSITIVE ("view-zoom-1-8",        image);
  SET_SENSITIVE ("view-zoom-1-16",       image);
  SET_SENSITIVE ("view-zoom-other",      image);

  SET_SENSITIVE ("view-rotate-reset",    image);
721 722
  SET_SENSITIVE ("view-rotate-15",       image);
  SET_SENSITIVE ("view-rotate-345",      image);
723 724 725 726
  SET_SENSITIVE ("view-rotate-90",       image);
  SET_SENSITIVE ("view-rotate-180",      image);
  SET_SENSITIVE ("view-rotate-270",      image);
  SET_SENSITIVE ("view-rotate-other",    image);
727

728
  if (image)
729 730 731 732
    {
      view_actions_set_zoom (group, shell);
      view_actions_set_rotate (group, shell);
    }
733

734 735
  SET_SENSITIVE ("view-navigation-window", image);
  SET_SENSITIVE ("view-display-filters",   image);
736

737
  SET_SENSITIVE ("view-show-selection",      image);
738
  SET_ACTIVE    ("view-show-selection",      display && options->show_selection);
739
  SET_SENSITIVE ("view-show-layer-boundary", image);
740
  SET_ACTIVE    ("view-show-layer-boundary", display && options->show_layer_boundary);
741
  SET_SENSITIVE ("view-show-guides",         image);
742
  SET_ACTIVE    ("view-show-guides",         display && options->show_guides);
743
  SET_SENSITIVE ("view-show-grid",           image);
744
  SET_ACTIVE    ("view-show-grid",           display && options->show_grid);
745
  SET_SENSITIVE ("view-show-sample-points",  image);
746
  SET_ACTIVE    ("view-show-sample-points",  display && options->show_sample_points);
747

748
  SET_SENSITIVE ("view-snap-to-guides",      image);
749
  SET_ACTIVE    ("view-snap-to-guides",      display && options->snap_to_guides);
750
  SET_SENSITIVE ("view-snap-to-grid",        image);
751
  SET_ACTIVE    ("view-snap-to-grid",        display && options->snap_to_grid);
752
  SET_SENSITIVE ("view-snap-to-canvas",      image);
753
  SET_ACTIVE    ("view-snap-to-canvas",      display && options->snap_to_canvas);
754
  SET_SENSITIVE ("view-snap-to-vectors",     image);
755
  SET_ACTIVE    ("view-snap-to-vectors",     display && options->snap_to_path);
756

757 758 759 760 761
  SET_SENSITIVE ("view-padding-color-theme",       image);
  SET_SENSITIVE ("view-padding-color-light-check", image);
  SET_SENSITIVE ("view-padding-color-dark-check",  image);
  SET_SENSITIVE ("view-padding-color-custom",      image);
  SET_SENSITIVE ("view-padding-color-prefs",       image);
762

763
  if (display)
764 765 766 767 768
    {
      SET_COLOR ("view-padding-color-menu", &options->padding_color);

      if (shell->canvas)
        {
769 770
          GtkStyle *style = gtk_widget_get_style (shell->canvas);
          GimpRGB   color;
771 772

          gtk_widget_ensure_style (shell->canvas);
773
          gimp_rgb_set_gdk_color (&color, style->bg + GTK_STATE_NORMAL);
774 775 776 777 778 779
          gimp_rgb_set_alpha (&color, GIMP_OPACITY_OPAQUE);

          SET_COLOR ("view-padding-color-theme",  &color);
        }
    }

780
  SET_SENSITIVE ("view-show-menubar",    image);
781
  SET_ACTIVE    ("view-show-menubar",    display && options->show_menubar);
782
  SET_SENSITIVE ("view-show-rulers",     image);
783
  SET_ACTIVE    ("view-show-rulers",     display && options->show_rulers);
784
  SET_SENSITIVE ("view-show-scrollbars", image);
785
  SET_ACTIVE    ("view-show-scrollbars", display && options->show_scrollbars);
786
  SET_SENSITIVE ("view-show-statusbar",  image);
787
  SET_ACTIVE    ("view-show-statusbar",  display && options->show_statusbar);
788

789
  SET_SENSITIVE ("view-shrink-wrap", image);
790
  SET_ACTIVE    ("view-fullscreen",  display && fullscreen);
791

792
  if (GIMP_IS_IMAGE_WINDOW (group->user_data) ||
793 794
      GIMP_IS_GIMP (group->user_data))
    {
795 796 797 798 799
      GtkWidget *window = NULL;

      if (shell)
        window = gtk_widget_get_toplevel (GTK_WIDGET (shell));

800
      /*  see view_actions_setup()  */
801 802
      if (GTK_IS_WINDOW (window))
        window_actions_update (group, window);
803
    }
804 805 806

#undef SET_ACTIVE
#undef SET_SENSITIVE
807
#undef SET_COLOR
808 809 810 811 812 813 814 815 816 817
}


/*  private functions  */

static void
view_actions_set_zoom (GimpActionGroup  *group,
                       GimpDisplayShell *shell)
{
  const gchar *action = NULL;
818
  gchar       *str;
819
  gchar       *label;
820 821 822 823 824
  guint        scale;

  g_object_get (shell->zoom,
                "percentage", &str,
                NULL);
825

826
  scale = ROUND (gimp_zoom_model_get_factor (shell->zoom) * 1000);
827 828 829 830 831 832 833 834 835 836 837 838 839 840 841

  switch (scale)
    {
    case 16000:  action = "view-zoom-16-1";  break;
    case  8000:  action = "view-zoom-8-1";   break;
    case  4000:  action = "view-zoom-4-1";   break;
    case  2000:  action = "view-zoom-2-1";   break;
    case  1000:  action = "view-zoom-1-1";   break;
    case   500:  action = "view-zoom-1-2";   break;
    case   250:  action = "view-zoom-1-4";   break;
    case   125:  action = "view-zoom-1-8";   break;
    case    63:
    case    62:  action = "view-zoom-1-16";  break;
    }

842
  if (! action)
843
    {
844
      action = "view-zoom-other";
845

846
      label = g_strdup_printf (_("Othe_r (%s)..."), str);
847 848 849
      gimp_action_group_set_action_label (group, action, label);
      g_free (label);

850
      shell->other_scale = gimp_zoom_model_get_factor (shell->zoom);
851 852 853 854
    }

  gimp_action_group_set_action_active (group, action, TRUE);

855
  label = g_strdup_printf (_("_Zoom (%s)"), str);
856 857 858 859 860
  gimp_action_group_set_action_label (group, "view-zoom-menu", label);
  g_free (label);

  /* flag as dirty */
  shell->other_scale = - fabs (shell->other_scale);
861 862

  g_free (str);
863
}
864

865 866 867 868 869 870 871 872 873 874 875
static void
view_actions_set_rotate (GimpActionGroup  *group,
                         GimpDisplayShell *shell)
{
  gchar *label;

  label = g_strdup_printf (_("_Rotate (%d°)"), (gint) shell->rotate_angle);
  gimp_action_group_set_action_label (group, "view-rotate-menu", label);
  g_free (label);
}

876 877 878 879 880 881
static void
view_actions_check_type_notify (GimpDisplayConfig *config,
                                GParamSpec        *pspec,
                                GimpActionGroup   *group)
{
  gimp_action_group_set_action_color (group, "view-padding-color-light-check",
882 883
                                      gimp_render_light_check_color (),
                                      FALSE);
884
  gimp_action_group_set_action_color (group, "view-padding-color-dark-check",
885 886
                                      gimp_render_dark_check_color (),
                                      FALSE);
887
}