gimpimage-undo.c 20.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 <https://www.gnu.org/licenses/>.
16 17 18 19
 */

#include "config.h"

20
#include <gdk-pixbuf/gdk-pixbuf.h>
21
#include <gegl.h>
22

23
#include "core-types.h"
24

25 26 27
#include "config/gimpcoreconfig.h"

#include "gimp.h"
28
#include "gimp-utils.h"
29
#include "gimpdrawableundo.h"
30
#include "gimpimage.h"
31
#include "gimpimage-private.h"
32
#include "gimpimage-undo.h"
33
#include "gimpitem.h"
34
#include "gimplist.h"
35 36 37
#include "gimpundostack.h"


38 39
/*  local function prototypes  */

40
static void          gimp_image_undo_pop_stack       (GimpImage     *image,
41 42 43
                                                      GimpUndoStack *undo_stack,
                                                      GimpUndoStack *redo_stack,
                                                      GimpUndoMode   undo_mode);
44 45
static void          gimp_image_undo_free_space      (GimpImage     *image);
static void          gimp_image_undo_free_redo       (GimpImage     *image);
46

47
static GimpDirtyMask gimp_image_undo_dirty_from_type (GimpUndoType   undo_type);
48 49 50 51


/*  public functions  */

52
gboolean
53
gimp_image_undo_is_enabled (GimpImage *image)
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
{
  g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);

  return (GIMP_IMAGE_GET_PRIVATE (image)->undo_freeze_count == 0);
}

gboolean
gimp_image_undo_enable (GimpImage *image)
{
  g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);

  /*  Free all undo steps as they are now invalidated  */
  gimp_image_undo_free (image);

  return gimp_image_undo_thaw (image);
}

gboolean
gimp_image_undo_disable (GimpImage *image)
{
  g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);

  return gimp_image_undo_freeze (image);
}

gboolean
gimp_image_undo_freeze (GimpImage *image)
{
  GimpImagePrivate *private;

  g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);

  private = GIMP_IMAGE_GET_PRIVATE (image);

  private->undo_freeze_count++;

  if (private->undo_freeze_count == 1)
    gimp_image_undo_event (image, GIMP_UNDO_EVENT_UNDO_FREEZE, NULL);

  return TRUE;
}

gboolean
gimp_image_undo_thaw (GimpImage *image)
{
  GimpImagePrivate *private;

  g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);

  private = GIMP_IMAGE_GET_PRIVATE (image);

  g_return_val_if_fail (private->undo_freeze_count > 0, FALSE);

  private->undo_freeze_count--;

  if (private->undo_freeze_count == 0)
    gimp_image_undo_event (image, GIMP_UNDO_EVENT_UNDO_THAW, NULL);

  return TRUE;
}

115
gboolean
116
gimp_image_undo (GimpImage *image)
117
{
118 119
  GimpImagePrivate *private;

120
  g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
121 122 123 124

  private = GIMP_IMAGE_GET_PRIVATE (image);

  g_return_val_if_fail (private->pushing_undo_group == GIMP_UNDO_GROUP_NONE,
125
                        FALSE);
126

127
  gimp_image_undo_pop_stack (image,
128 129
                             private->undo_stack,
                             private->redo_stack,
130 131 132
                             GIMP_UNDO_MODE_UNDO);

  return TRUE;
133 134
}

135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
gboolean
gimp_image_redo (GimpImage *image)
{
  GimpImagePrivate *private;

  g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);

  private = GIMP_IMAGE_GET_PRIVATE (image);

  g_return_val_if_fail (private->pushing_undo_group == GIMP_UNDO_GROUP_NONE,
                        FALSE);

  gimp_image_undo_pop_stack (image,
                             private->redo_stack,
                             private->undo_stack,
                             GIMP_UNDO_MODE_REDO);

  return TRUE;
}

155 156 157 158 159 160 161
/*
 * this function continues to undo as long as it only sees certain
 * undo types, in particular visibility changes.
 */
gboolean
gimp_image_strong_undo (GimpImage *image)
{
162 163
  GimpImagePrivate *private;
  GimpUndo         *undo;
164 165

  g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
166 167 168 169

  private = GIMP_IMAGE_GET_PRIVATE (image);

  g_return_val_if_fail (private->pushing_undo_group == GIMP_UNDO_GROUP_NONE,
170 171
                        FALSE);

172
  undo = gimp_undo_stack_peek (private->undo_stack);
173 174 175 176 177

  gimp_image_undo (image);

  while (gimp_undo_is_weak (undo))
    {
178
      undo = gimp_undo_stack_peek (private->undo_stack);
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
      if (gimp_undo_is_weak (undo))
        gimp_image_undo (image);
    }

  return TRUE;
}

/*
 * this function continues to redo as long as it only sees certain
 * undo types, in particular visibility changes.  Note that the
 * order of events is set up to make it exactly reverse
 * gimp_image_strong_undo().
 */
gboolean
gimp_image_strong_redo (GimpImage *image)
{
195 196
  GimpImagePrivate *private;
  GimpUndo         *undo;
197 198

  g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
199 200 201 202

  private = GIMP_IMAGE_GET_PRIVATE (image);

  g_return_val_if_fail (private->pushing_undo_group == GIMP_UNDO_GROUP_NONE,
203 204
                        FALSE);

205
  undo = gimp_undo_stack_peek (private->redo_stack);
206 207 208 209 210

  gimp_image_redo (image);

  while (gimp_undo_is_weak (undo))
    {
211
      undo = gimp_undo_stack_peek (private->redo_stack);
212 213 214 215 216 217 218
      if (gimp_undo_is_weak (undo))
        gimp_image_redo (image);
    }

  return TRUE;
}

219
GimpUndoStack *
220
gimp_image_get_undo_stack (GimpImage *image)
221 222 223 224 225 226 227
{
  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);

  return GIMP_IMAGE_GET_PRIVATE (image)->undo_stack;
}

GimpUndoStack *
228
gimp_image_get_redo_stack (GimpImage *image)
229 230 231 232 233 234
{
  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);

  return GIMP_IMAGE_GET_PRIVATE (image)->redo_stack;
}

235
void
236
gimp_image_undo_free (GimpImage *image)
237
{
238 239
  GimpImagePrivate *private;

240
  g_return_if_fail (GIMP_IS_IMAGE (image));
241

242 243
  private = GIMP_IMAGE_GET_PRIVATE (image);

244 245 246
  /*  Emit the UNDO_FREE event before actually freeing everything
   *  so the views can properly detach from the undo items
   */
247
  gimp_image_undo_event (image, GIMP_UNDO_EVENT_UNDO_FREE, NULL);
248

249 250
  gimp_undo_free (GIMP_UNDO (private->undo_stack), GIMP_UNDO_MODE_UNDO);
  gimp_undo_free (GIMP_UNDO (private->redo_stack), GIMP_UNDO_MODE_REDO);
251 252 253 254

  /* If the image was dirty, but could become clean by redo-ing
   * some actions, then it should now become 'infinitely' dirty.
   * This is because we've just nuked the actions that would allow
255
   * the image to become clean again.
256
   */
257 258
  if (private->dirty < 0)
    private->dirty = 100000;
259 260 261 262 263 264 265

  /* The same applies to the case where the image would become clean
   * due to undo actions, but since user can't undo without an undo
   * stack, that's not so much a problem.
   */
}

266
gint
267
gimp_image_get_undo_group_count (GimpImage *image)
268 269 270 271 272 273
{
  g_return_val_if_fail (GIMP_IS_IMAGE (image), 0);

  return GIMP_IMAGE_GET_PRIVATE (image)->group_count;
}

274
gboolean
275
gimp_image_undo_group_start (GimpImage    *image,
276
                             GimpUndoType  undo_type,
277 278
                             const gchar  *name)
{
279 280 281
  GimpImagePrivate *private;
  GimpUndoStack    *undo_group;
  GimpDirtyMask     dirty_mask;
282

283
  g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
284 285
  g_return_val_if_fail (undo_type >  GIMP_UNDO_GROUP_FIRST &&
                        undo_type <= GIMP_UNDO_GROUP_LAST, FALSE);
286

287 288
  private = GIMP_IMAGE_GET_PRIVATE (image);

289
  if (! name)
290
    name = gimp_undo_type_to_name (undo_type);
291

292
  dirty_mask = gimp_image_undo_dirty_from_type (undo_type);
293

294
  /* Notify listeners that the image will be modified */
295
  if (private->group_count == 0 && dirty_mask != GIMP_DIRTY_NONE)
296
    gimp_image_dirty (image, dirty_mask);
297

298
  if (private->undo_freeze_count > 0)
299 300
    return FALSE;

301
  private->group_count++;
302 303

  /*  If we're already in a group...ignore  */
304
  if (private->group_count > 1)
305 306 307
    return TRUE;

  /*  nuke the redo stack  */
308
  gimp_image_undo_free_redo (image);
309

310
  undo_group = gimp_undo_stack_new (image);
311 312

  gimp_object_set_name (GIMP_OBJECT (undo_group), name);
313
  GIMP_UNDO (undo_group)->undo_type  = undo_type;
314
  GIMP_UNDO (undo_group)->dirty_mask = dirty_mask;
315

316
  gimp_undo_stack_push_undo (private->undo_stack, GIMP_UNDO (undo_group));
317

318
  private->pushing_undo_group = undo_type;
319 320 321 322 323

  return TRUE;
}

gboolean
324
gimp_image_undo_group_end (GimpImage *image)
325
{
326 327
  GimpImagePrivate *private;

328
  g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
329

330 331 332
  private = GIMP_IMAGE_GET_PRIVATE (image);

  if (private->undo_freeze_count > 0)
333 334
    return FALSE;

335
  g_return_val_if_fail (private->group_count > 0, FALSE);
336

337
  private->group_count--;
338

339
  if (private->group_count == 0)
340
    {
341
      private->pushing_undo_group = GIMP_UNDO_GROUP_NONE;
342 343 344 345

      /* Do it here, since undo_push doesn't emit this event while in
       * the middle of a group
       */
346
      gimp_image_undo_event (image, GIMP_UNDO_EVENT_UNDO_PUSHED,
347
                             gimp_undo_stack_peek (private->undo_stack));
348

349
      gimp_image_undo_free_space (image);
350 351 352 353 354 355
    }

  return TRUE;
}

GimpUndo *
356 357 358 359 360
gimp_image_undo_push (GimpImage     *image,
                      GType          object_type,
                      GimpUndoType   undo_type,
                      const gchar   *name,
                      GimpDirtyMask  dirty_mask,
361
                      ...)
362
{
363 364 365 366 367 368
  GimpImagePrivate  *private;
  gint               n_properties = 0;
  gchar            **names        = NULL;
  GValue            *values       = NULL;
  va_list            args;
  GimpUndo          *undo;
369

370
  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
371 372
  g_return_val_if_fail (g_type_is_a (object_type, GIMP_TYPE_UNDO), NULL);
  g_return_val_if_fail (undo_type > GIMP_UNDO_GROUP_LAST, NULL);
373

374 375
  private = GIMP_IMAGE_GET_PRIVATE (image);

376 377 378
  /* Does this undo dirty the image?  If so, we always want to mark
   * image dirty, even if we can't actually push the undo.
   */
379
  if (dirty_mask != GIMP_DIRTY_NONE)
380
    gimp_image_dirty (image, dirty_mask);
381

382
  if (private->undo_freeze_count > 0)
383 384
    return NULL;

385
  if (! name)
386
    name = gimp_undo_type_to_name (undo_type);
387

388 389 390 391 392 393 394
  names = gimp_properties_append (object_type,
                                  &n_properties, names, &values,
                                  "name",       name,
                                  "image",      image,
                                  "undo-type",  undo_type,
                                  "dirty-mask", dirty_mask,
                                  NULL);
395

396
  va_start (args, dirty_mask);
397 398 399
  names = gimp_properties_append_valist (object_type,
                                         &n_properties, names, &values,
                                         args);
400
  va_end (args);
401

402 403 404 405
  undo = (GimpUndo *) g_object_new_with_properties (object_type,
                                                    n_properties,
                                                    (const gchar **) names,
                                                    (const GValue *) values);
406

407
  gimp_properties_free (n_properties, names, values);
408

409
  /*  nuke the redo stack  */
410
  gimp_image_undo_free_redo (image);
411

412
  if (private->pushing_undo_group == GIMP_UNDO_GROUP_NONE)
413
    {
414
      gimp_undo_stack_push_undo (private->undo_stack, undo);
415

416
      gimp_image_undo_event (image, GIMP_UNDO_EVENT_UNDO_PUSHED, undo);
417

418
      gimp_image_undo_free_space (image);
419

420
      /*  freeing undo space may have freed the newly pushed undo  */
421
      if (gimp_undo_stack_peek (private->undo_stack) == undo)
422
        return undo;
423 424 425 426 427
    }
  else
    {
      GimpUndoStack *undo_group;

428
      undo_group = GIMP_UNDO_STACK (gimp_undo_stack_peek (private->undo_stack));
429

430
      gimp_undo_stack_push_undo (undo_group, undo);
431

432
      return undo;
433
    }
434

435
  return NULL;
436 437
}

438
GimpUndo *
439
gimp_image_undo_can_compress (GimpImage    *image,
440 441 442
                              GType         object_type,
                              GimpUndoType  undo_type)
{
443 444
  GimpImagePrivate *private;

445
  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
446

447 448
  private = GIMP_IMAGE_GET_PRIVATE (image);

449
  if (gimp_image_is_dirty (image) &&
450
      ! gimp_undo_stack_peek (private->redo_stack))
451
    {
452
      GimpUndo *undo = gimp_undo_stack_peek (private->undo_stack);
453 454 455 456 457 458 459 460 461 462 463

      if (undo && undo->undo_type == undo_type &&
          g_type_is_a (G_TYPE_FROM_INSTANCE (undo), object_type))
        {
          return undo;
        }
    }

  return NULL;
}

464 465 466
GimpUndo *
gimp_image_undo_get_fadeable (GimpImage *image)
{
467 468
  GimpImagePrivate *private;
  GimpUndo         *undo;
469 470 471

  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);

472 473 474
  private = GIMP_IMAGE_GET_PRIVATE (image);

  undo = gimp_undo_stack_peek (private->undo_stack);
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491

  if (GIMP_IS_UNDO_STACK (undo) && undo->undo_type == GIMP_UNDO_GROUP_PAINT)
    {
      GimpUndoStack *stack = GIMP_UNDO_STACK (undo);

      if (gimp_undo_stack_get_depth (stack) == 2)
        {
          undo = gimp_undo_stack_peek (stack);
        }
    }

  if (GIMP_IS_DRAWABLE_UNDO (undo))
    return undo;

  return NULL;
}

492 493 494 495

/*  private functions  */

static void
496
gimp_image_undo_pop_stack (GimpImage     *image,
497 498 499
                           GimpUndoStack *undo_stack,
                           GimpUndoStack *redo_stack,
                           GimpUndoMode   undo_mode)
500
{
501 502 503
  GimpUndo            *undo;
  GimpUndoAccumulator  accum = { 0, };

504
  g_object_freeze_notify (G_OBJECT (image));
505

506 507
  undo = gimp_undo_stack_pop_undo (undo_stack, undo_mode, &accum);

508 509 510 511
  if (undo)
    {
      if (GIMP_IS_UNDO_STACK (undo))
        gimp_list_reverse (GIMP_LIST (GIMP_UNDO_STACK (undo)->undos));
512

513
      gimp_undo_stack_push_undo (redo_stack, undo);
514

515
      if (accum.mode_changed)
516
        gimp_image_mode_changed (image);
517

518 519 520
      if (accum.precision_changed)
        gimp_image_precision_changed (image);

521
      if (accum.size_changed)
522 523
        gimp_image_size_changed_detailed (image,
                                          accum.previous_origin_x,
524 525 526
                                          accum.previous_origin_y,
                                          accum.previous_width,
                                          accum.previous_height);
527

528
      if (accum.resolution_changed)
529
        gimp_image_resolution_changed (image);
530

531
      if (accum.unit_changed)
532
        gimp_image_unit_changed (image);
533

534
      /* let others know that we just popped an action */
535
      gimp_image_undo_event (image,
536 537 538 539
                             (undo_mode == GIMP_UNDO_MODE_UNDO) ?
                             GIMP_UNDO_EVENT_UNDO : GIMP_UNDO_EVENT_REDO,
                             undo);
    }
540

541
  g_object_thaw_notify (G_OBJECT (image));
542 543 544
}

static void
545
gimp_image_undo_free_space (GimpImage *image)
546
{
547 548 549 550 551
  GimpImagePrivate *private = GIMP_IMAGE_GET_PRIVATE (image);
  GimpContainer    *container;
  gint              min_undo_levels;
  gint              max_undo_levels;
  gint64            undo_size;
552

553
  container = private->undo_stack->undos;
554

555
  min_undo_levels = image->gimp->config->levels_of_undo;
556
  max_undo_levels = 1024; /* FIXME */
557
  undo_size       = image->gimp->config->undo_size;
558

559 560
#ifdef DEBUG_IMAGE_UNDO
  g_printerr ("undo_steps: %d    undo_bytes: %ld\n",
561
              gimp_container_get_n_children (container),
562
              (glong) gimp_object_get_memsize (GIMP_OBJECT (container), NULL));
563 564 565
#endif

  /*  keep at least min_undo_levels undo steps  */
566
  if (gimp_container_get_n_children (container) <= min_undo_levels)
567 568
    return;

569
  while ((gimp_object_get_memsize (GIMP_OBJECT (container), NULL) > undo_size) ||
570
         (gimp_container_get_n_children (container) > max_undo_levels))
571
    {
572
      GimpUndo *freed = gimp_undo_stack_free_bottom (private->undo_stack,
573 574 575 576
                                                     GIMP_UNDO_MODE_UNDO);

#ifdef DEBUG_IMAGE_UNDO
      g_printerr ("freed one step: undo_steps: %d    undo_bytes: %ld\n",
577
                  gimp_container_get_n_children (container),
578 579
                  (glong) gimp_object_get_memsize (GIMP_OBJECT (container),
                                                   NULL));
580 581
#endif

582
      gimp_image_undo_event (image, GIMP_UNDO_EVENT_UNDO_EXPIRED, freed);
583 584

      g_object_unref (freed);
585

586
      if (gimp_container_get_n_children (container) <= min_undo_levels)
587 588 589 590
        return;
    }
}

591
static void
592
gimp_image_undo_free_redo (GimpImage *image)
593
{
594
  GimpImagePrivate *private   = GIMP_IMAGE_GET_PRIVATE (image);
595
  GimpContainer    *container = private->redo_stack->undos;
596

597 598
#ifdef DEBUG_IMAGE_UNDO
  g_printerr ("redo_steps: %d    redo_bytes: %ld\n",
599
              gimp_container_get_n_children (container),
600
              (glong) gimp_object_get_memsize (GIMP_OBJECT (container), NULL));
601 602
#endif

603 604 605
  if (gimp_container_is_empty (container))
    return;

606
  while (gimp_container_get_n_children (container) > 0)
607
    {
608
      GimpUndo *freed = gimp_undo_stack_free_bottom (private->redo_stack,
609 610 611 612
                                                     GIMP_UNDO_MODE_REDO);

#ifdef DEBUG_IMAGE_UNDO
      g_printerr ("freed one step: redo_steps: %d    redo_bytes: %ld\n",
613
                  gimp_container_get_n_children (container),
614 615
                  (glong )gimp_object_get_memsize (GIMP_OBJECT (container),
                                                   NULL));
616 617
#endif

618
      gimp_image_undo_event (image, GIMP_UNDO_EVENT_REDO_EXPIRED, freed);
619 620 621

      g_object_unref (freed);
    }
622 623 624 625

  /* We need to use <= here because the undo counter has already been
   * incremented at this point.
   */
626
  if (private->dirty <= 0)
627 628 629 630 631 632
    {
      /* If the image was dirty, but could become clean by redo-ing
       * some actions, then it should now become 'infinitely' dirty.
       * This is because we've just nuked the actions that would allow
       * the image to become clean again.
       */
633
      private->dirty = 100000;
634
    }
635
}
636 637

static GimpDirtyMask
638
gimp_image_undo_dirty_from_type (GimpUndoType undo_type)
639
{
640
  switch (undo_type)
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657
    {
    case GIMP_UNDO_GROUP_IMAGE_SCALE:
    case GIMP_UNDO_GROUP_IMAGE_RESIZE:
    case GIMP_UNDO_GROUP_IMAGE_FLIP:
    case GIMP_UNDO_GROUP_IMAGE_ROTATE:
    case GIMP_UNDO_GROUP_IMAGE_CROP:
      return GIMP_DIRTY_IMAGE | GIMP_DIRTY_IMAGE_SIZE;

    case GIMP_UNDO_GROUP_IMAGE_CONVERT:
      return GIMP_DIRTY_IMAGE | GIMP_DIRTY_DRAWABLE;

    case GIMP_UNDO_GROUP_IMAGE_LAYERS_MERGE:
      return GIMP_DIRTY_IMAGE_STRUCTURE | GIMP_DIRTY_DRAWABLE;

    case GIMP_UNDO_GROUP_IMAGE_VECTORS_MERGE:
      return GIMP_DIRTY_IMAGE_STRUCTURE | GIMP_DIRTY_VECTORS;

658
    case GIMP_UNDO_GROUP_IMAGE_QUICK_MASK: /* FIXME */
659 660 661
      return GIMP_DIRTY_IMAGE_STRUCTURE | GIMP_DIRTY_SELECTION;

    case GIMP_UNDO_GROUP_IMAGE_GRID:
662
    case GIMP_UNDO_GROUP_GUIDE:
663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723
      return GIMP_DIRTY_IMAGE_META;

    case GIMP_UNDO_GROUP_DRAWABLE:
    case GIMP_UNDO_GROUP_DRAWABLE_MOD:
      return GIMP_DIRTY_ITEM | GIMP_DIRTY_DRAWABLE;

    case GIMP_UNDO_GROUP_MASK: /* FIXME */
      return GIMP_DIRTY_SELECTION;

    case GIMP_UNDO_GROUP_ITEM_VISIBILITY:
    case GIMP_UNDO_GROUP_ITEM_LINKED:
    case GIMP_UNDO_GROUP_ITEM_PROPERTIES:
      return GIMP_DIRTY_ITEM_META;

    case GIMP_UNDO_GROUP_ITEM_DISPLACE: /* FIXME */
      return GIMP_DIRTY_ITEM | GIMP_DIRTY_DRAWABLE | GIMP_DIRTY_VECTORS;

    case GIMP_UNDO_GROUP_ITEM_SCALE: /* FIXME */
    case GIMP_UNDO_GROUP_ITEM_RESIZE: /* FIXME */
      return GIMP_DIRTY_ITEM | GIMP_DIRTY_DRAWABLE | GIMP_DIRTY_VECTORS;

    case GIMP_UNDO_GROUP_LAYER_ADD_MASK:
    case GIMP_UNDO_GROUP_LAYER_APPLY_MASK:
      return GIMP_DIRTY_IMAGE_STRUCTURE;

    case GIMP_UNDO_GROUP_FS_TO_LAYER:
    case GIMP_UNDO_GROUP_FS_FLOAT:
    case GIMP_UNDO_GROUP_FS_ANCHOR:
      return GIMP_DIRTY_IMAGE_STRUCTURE;

    case GIMP_UNDO_GROUP_EDIT_PASTE:
      return GIMP_DIRTY_IMAGE_STRUCTURE;

    case GIMP_UNDO_GROUP_EDIT_CUT:
      return GIMP_DIRTY_ITEM | GIMP_DIRTY_DRAWABLE;

    case GIMP_UNDO_GROUP_TEXT:
      return GIMP_DIRTY_ITEM | GIMP_DIRTY_DRAWABLE;

    case GIMP_UNDO_GROUP_TRANSFORM: /* FIXME */
      return GIMP_DIRTY_ITEM | GIMP_DIRTY_DRAWABLE | GIMP_DIRTY_VECTORS;

    case GIMP_UNDO_GROUP_PAINT:
      return GIMP_DIRTY_ITEM | GIMP_DIRTY_DRAWABLE;

    case GIMP_UNDO_GROUP_PARASITE_ATTACH:
    case GIMP_UNDO_GROUP_PARASITE_REMOVE:
      return GIMP_DIRTY_IMAGE_META | GIMP_DIRTY_ITEM_META;

    case GIMP_UNDO_GROUP_VECTORS_IMPORT:
      return GIMP_DIRTY_IMAGE_STRUCTURE | GIMP_DIRTY_VECTORS;

    case GIMP_UNDO_GROUP_MISC:
      return GIMP_DIRTY_ALL;

    default:
      break;
    }

  return GIMP_DIRTY_ALL;
}