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

#include "config.h"

23
#include <stdlib.h>
24 25
#include <string.h>

26
#include <gdk-pixbuf/gdk-pixbuf.h>
27 28 29 30
#include <gegl.h>

#include "core-types.h"

31
#include "gimpimage.h"
32
#include "gimpimage-undo-push.h"
33 34 35 36 37 38 39 40
#include "gimpitem.h"
#include "gimpitemstack.h"
#include "gimpitemtree.h"


enum
{
  PROP_0,
41
  PROP_IMAGE,
42
  PROP_CONTAINER_TYPE,
43 44
  PROP_ITEM_TYPE,
  PROP_ACTIVE_ITEM
45 46 47 48 49 50 51
};


typedef struct _GimpItemTreePrivate GimpItemTreePrivate;

struct _GimpItemTreePrivate
{
52
  GimpImage  *image;
53

54 55
  GType       container_type;
  GType       item_type;
56

57 58 59
  GimpItem   *active_item;

  GHashTable *name_hash;
60 61 62
};

#define GIMP_ITEM_TREE_GET_PRIVATE(object) \
63
        ((GimpItemTreePrivate *) gimp_item_tree_get_instance_private ((GimpItemTree *) (object)))
64 65 66 67


/*  local function prototypes  */

68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
static void     gimp_item_tree_constructed   (GObject      *object);
static void     gimp_item_tree_finalize      (GObject      *object);
static void     gimp_item_tree_set_property  (GObject      *object,
                                              guint         property_id,
                                              const GValue *value,
                                              GParamSpec   *pspec);
static void     gimp_item_tree_get_property  (GObject      *object,
                                              guint         property_id,
                                              GValue       *value,
                                              GParamSpec   *pspec);

static gint64   gimp_item_tree_get_memsize   (GimpObject   *object,
                                              gint64       *gui_size);

static void     gimp_item_tree_uniquefy_name (GimpItemTree *tree,
                                              GimpItem     *item,
                                              const gchar  *new_name);
85 86


87
G_DEFINE_TYPE_WITH_PRIVATE (GimpItemTree, gimp_item_tree, GIMP_TYPE_OBJECT)
88 89 90 91 92 93 94 95 96 97

#define parent_class gimp_item_tree_parent_class


static void
gimp_item_tree_class_init (GimpItemTreeClass *klass)
{
  GObjectClass    *object_class      = G_OBJECT_CLASS (klass);
  GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass);

98
  object_class->constructed      = gimp_item_tree_constructed;
99 100 101 102 103 104
  object_class->finalize         = gimp_item_tree_finalize;
  object_class->set_property     = gimp_item_tree_set_property;
  object_class->get_property     = gimp_item_tree_get_property;

  gimp_object_class->get_memsize = gimp_item_tree_get_memsize;

105 106 107 108 109 110 111
  g_object_class_install_property (object_class, PROP_IMAGE,
                                   g_param_spec_object ("image",
                                                        NULL, NULL,
                                                        GIMP_TYPE_IMAGE,
                                                        GIMP_PARAM_READWRITE |
                                                        G_PARAM_CONSTRUCT_ONLY));

112 113 114 115 116 117 118 119 120 121 122 123 124 125
  g_object_class_install_property (object_class, PROP_CONTAINER_TYPE,
                                   g_param_spec_gtype ("container-type",
                                                       NULL, NULL,
                                                       GIMP_TYPE_ITEM_STACK,
                                                       GIMP_PARAM_READWRITE |
                                                       G_PARAM_CONSTRUCT_ONLY));

  g_object_class_install_property (object_class, PROP_ITEM_TYPE,
                                   g_param_spec_gtype ("item-type",
                                                       NULL, NULL,
                                                       GIMP_TYPE_ITEM,
                                                       GIMP_PARAM_READWRITE |
                                                       G_PARAM_CONSTRUCT_ONLY));

126 127 128 129 130
  g_object_class_install_property (object_class, PROP_ACTIVE_ITEM,
                                   g_param_spec_object ("active-item",
                                                        NULL, NULL,
                                                        GIMP_TYPE_ITEM,
                                                        GIMP_PARAM_READWRITE));
131 132 133 134 135
}

static void
gimp_item_tree_init (GimpItemTree *tree)
{
136 137 138
  GimpItemTreePrivate *private = GIMP_ITEM_TREE_GET_PRIVATE (tree);

  private->name_hash = g_hash_table_new (g_str_hash, g_str_equal);
139 140
}

141 142
static void
gimp_item_tree_constructed (GObject *object)
143
{
144 145
  GimpItemTree        *tree    = GIMP_ITEM_TREE (object);
  GimpItemTreePrivate *private = GIMP_ITEM_TREE_GET_PRIVATE (tree);
146

147
  G_OBJECT_CLASS (parent_class)->constructed (object);
148

149 150 151 152
  gimp_assert (GIMP_IS_IMAGE (private->image));
  gimp_assert (g_type_is_a (private->container_type, GIMP_TYPE_ITEM_STACK));
  gimp_assert (g_type_is_a (private->item_type,      GIMP_TYPE_ITEM));
  gimp_assert (private->item_type != GIMP_TYPE_ITEM);
153 154 155 156 157 158 159 160 161 162 163

  tree->container = g_object_new (private->container_type,
                                  "name",          g_type_name (private->item_type),
                                  "children-type", private->item_type,
                                  "policy",        GIMP_CONTAINER_POLICY_STRONG,
                                  NULL);
}

static void
gimp_item_tree_finalize (GObject *object)
{
164 165 166
  GimpItemTree        *tree    = GIMP_ITEM_TREE (object);
  GimpItemTreePrivate *private = GIMP_ITEM_TREE_GET_PRIVATE (tree);

167 168
  g_clear_pointer (&private->name_hash, g_hash_table_unref);
  g_clear_object (&tree->container);
169 170 171 172 173 174 175 176 177 178 179 180 181 182

  G_OBJECT_CLASS (parent_class)->finalize (object);
}

static void
gimp_item_tree_set_property (GObject      *object,
                             guint         property_id,
                             const GValue *value,
                             GParamSpec   *pspec)
{
  GimpItemTreePrivate *private = GIMP_ITEM_TREE_GET_PRIVATE (object);

  switch (property_id)
    {
183 184 185
    case PROP_IMAGE:
      private->image = g_value_get_object (value); /* don't ref */
      break;
186 187 188 189 190 191
    case PROP_CONTAINER_TYPE:
      private->container_type = g_value_get_gtype (value);
      break;
    case PROP_ITEM_TYPE:
      private->item_type = g_value_get_gtype (value);
      break;
192 193 194
    case PROP_ACTIVE_ITEM:
      private->active_item = g_value_get_object (value); /* don't ref */
      break;
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
      break;
    }
}

static void
gimp_item_tree_get_property (GObject    *object,
                             guint       property_id,
                             GValue     *value,
                             GParamSpec *pspec)
{
  GimpItemTreePrivate *private = GIMP_ITEM_TREE_GET_PRIVATE (object);

  switch (property_id)
    {
212 213 214
    case PROP_IMAGE:
      g_value_set_object (value, private->image);
      break;
215 216 217 218 219 220
    case PROP_CONTAINER_TYPE:
      g_value_set_gtype (value, private->container_type);
      break;
    case PROP_ITEM_TYPE:
      g_value_set_gtype (value, private->item_type);
      break;
221 222 223
    case PROP_ACTIVE_ITEM:
      g_value_set_object (value, private->active_item);
      break;
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
      break;
    }
}

static gint64
gimp_item_tree_get_memsize (GimpObject *object,
                            gint64     *gui_size)
{
  GimpItemTree *tree    = GIMP_ITEM_TREE (object);
  gint64        memsize = 0;

  memsize += gimp_object_get_memsize (GIMP_OBJECT (tree->container), gui_size);

  return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
                                                                  gui_size);
}


/*  public functions  */

GimpItemTree *
248 249 250
gimp_item_tree_new (GimpImage *image,
                    GType      container_type,
                    GType      item_type)
251
{
252
  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
253 254 255 256
  g_return_val_if_fail (g_type_is_a (container_type, GIMP_TYPE_ITEM_STACK), NULL);
  g_return_val_if_fail (g_type_is_a (item_type, GIMP_TYPE_ITEM), NULL);

  return g_object_new (GIMP_TYPE_ITEM_TREE,
257
                       "image",          image,
258 259 260 261
                       "container-type", container_type,
                       "item-type",      item_type,
                       NULL);
}
262

263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
GimpItem *
gimp_item_tree_get_active_item (GimpItemTree *tree)
{
  g_return_val_if_fail (GIMP_IS_ITEM_TREE (tree), NULL);

  return GIMP_ITEM_TREE_GET_PRIVATE (tree)->active_item;
}

void
gimp_item_tree_set_active_item (GimpItemTree *tree,
                                GimpItem     *item)
{
  GimpItemTreePrivate *private;

  g_return_if_fail (GIMP_IS_ITEM_TREE (tree));

  private = GIMP_ITEM_TREE_GET_PRIVATE (tree);

  g_return_if_fail (item == NULL ||
282
                    G_TYPE_CHECK_INSTANCE_TYPE (item, private->item_type));
283
  g_return_if_fail (item == NULL || gimp_item_get_tree (item) == tree);
284 285 286 287 288 289 290 291 292

  if (item != private->active_item)
    {
      private->active_item = item;

      g_object_notify (G_OBJECT (tree), "active-item");
    }
}

293 294 295 296 297 298 299 300 301 302 303
GimpItem *
gimp_item_tree_get_item_by_name (GimpItemTree *tree,
                                 const gchar  *name)
{
  g_return_val_if_fail (GIMP_IS_ITEM_TREE (tree), NULL);
  g_return_val_if_fail (name != NULL, NULL);

  return g_hash_table_lookup (GIMP_ITEM_TREE_GET_PRIVATE (tree)->name_hash,
                              name);
}

304 305 306 307 308
gboolean
gimp_item_tree_get_insert_pos (GimpItemTree  *tree,
                               GimpItem      *item,
                               GimpItem     **parent,
                               gint          *position)
309
{
310 311
  GimpItemTreePrivate *private;
  GimpContainer       *container;
312

313 314
  g_return_val_if_fail (GIMP_IS_ITEM_TREE (tree), FALSE);
  g_return_val_if_fail (parent != NULL, FALSE);
315

316 317
  private = GIMP_ITEM_TREE_GET_PRIVATE (tree);

318 319 320 321 322 323 324
  g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (item, private->item_type),
                        FALSE);
  g_return_val_if_fail (! gimp_item_is_attached (item), FALSE);
  g_return_val_if_fail (gimp_item_get_image (item) == private->image, FALSE);
  g_return_val_if_fail (*parent == NULL ||
                        *parent == GIMP_IMAGE_ACTIVE_PARENT ||
                        G_TYPE_CHECK_INSTANCE_TYPE (*parent, private->item_type),
325
                        FALSE);
326 327
  g_return_val_if_fail (*parent == NULL ||
                        *parent == GIMP_IMAGE_ACTIVE_PARENT ||
328
                        gimp_item_get_tree (*parent) == tree, FALSE);
329 330 331
  g_return_val_if_fail (*parent == NULL ||
                        *parent == GIMP_IMAGE_ACTIVE_PARENT ||
                        gimp_viewable_get_children (GIMP_VIEWABLE (*parent)),
332
                        FALSE);
333
  g_return_val_if_fail (position != NULL, FALSE);
334

335
  /*  if we want to insert in the active item's parent container  */
336
  if (*parent == GIMP_IMAGE_ACTIVE_PARENT)
337
    {
338
      if (private->active_item)
339 340 341 342 343
        {
          /*  if the active item is a branch, add to the top of that
           *  branch; add to the active item's parent container
           *  otherwise
           */
344
          if (gimp_viewable_get_children (GIMP_VIEWABLE (private->active_item)))
345
            {
346
              *parent   = private->active_item;
347 348 349 350
              *position = 0;
            }
          else
            {
351
              *parent = gimp_item_get_parent (private->active_item);
352 353 354 355 356
            }
        }
      else
        {
          /*  use the toplevel container if there is no active item  */
357
          *parent = NULL;
358 359 360
        }
    }

361 362
  if (*parent)
    container = gimp_viewable_get_children (GIMP_VIEWABLE (*parent));
363 364 365 366 367 368
  else
    container = tree->container;

  /*  if we want to add on top of the active item  */
  if (*position == -1)
    {
369
      if (private->active_item)
370 371 372
        *position =
          gimp_container_get_child_index (container,
                                          GIMP_OBJECT (private->active_item));
373 374 375 376 377 378 379 380 381 382 383

      /*  if the active item is not in the specified parent container,
       *  fall back to index 0
       */
      if (*position == -1)
        *position = 0;
    }

  /*  don't add at a non-existing index  */
  *position = CLAMP (*position, 0, gimp_container_get_n_children (container));

384
  return TRUE;
385 386
}

387 388 389 390 391 392
void
gimp_item_tree_add_item (GimpItemTree *tree,
                         GimpItem     *item,
                         GimpItem     *parent,
                         gint          position)
{
393 394
  GimpItemTreePrivate *private;
  GimpContainer       *container;
395
  GimpContainer       *children;
396 397

  g_return_if_fail (GIMP_IS_ITEM_TREE (tree));
398 399 400

  private = GIMP_ITEM_TREE_GET_PRIVATE (tree);

401
  g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (item, private->item_type));
402 403
  g_return_if_fail (! gimp_item_is_attached (item));
  g_return_if_fail (gimp_item_get_image (item) == private->image);
404 405
  g_return_if_fail (parent == NULL ||
                    G_TYPE_CHECK_INSTANCE_TYPE (parent, private->item_type));
406
  g_return_if_fail (parent == NULL || gimp_item_get_tree (parent) == tree);
407 408
  g_return_if_fail (parent == NULL ||
                    gimp_viewable_get_children (GIMP_VIEWABLE (parent)));
409

410 411
  gimp_item_tree_uniquefy_name (tree, item, NULL);

412 413 414 415 416 417 418 419 420 421 422 423 424 425
  children = gimp_viewable_get_children (GIMP_VIEWABLE (item));

  if (children)
    {
      GList *list = gimp_item_stack_get_item_list (GIMP_ITEM_STACK (children));

      while (list)
        {
          gimp_item_tree_uniquefy_name (tree, list->data, NULL);

          list = g_list_remove (list, list->data);
        }
    }

426 427 428 429 430 431 432 433 434 435
  if (parent)
    container = gimp_viewable_get_children (GIMP_VIEWABLE (parent));
  else
    container = tree->container;

  if (parent)
    gimp_viewable_set_parent (GIMP_VIEWABLE (item),
                              GIMP_VIEWABLE (parent));

  gimp_container_insert (container, GIMP_OBJECT (item), position);
436 437 438

  /*  if the item came from the undo stack, reset its "removed" state  */
  if (gimp_item_is_removed (item))
439
    gimp_item_unset_removed (item);
440 441 442 443 444 445 446
}

GimpItem *
gimp_item_tree_remove_item (GimpItemTree *tree,
                            GimpItem     *item,
                            GimpItem     *new_active)
{
447 448 449
  GimpItemTreePrivate *private;
  GimpItem            *parent;
  GimpContainer       *container;
450
  GimpContainer       *children;
451
  gint                 index;
452 453

  g_return_val_if_fail (GIMP_IS_ITEM_TREE (tree), NULL);
454 455 456

  private = GIMP_ITEM_TREE_GET_PRIVATE (tree);

457 458
  g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (item, private->item_type),
                        NULL);
459
  g_return_val_if_fail (gimp_item_get_tree (item) == tree, NULL);
460

461
  parent    = gimp_item_get_parent (item);
462 463 464 465 466
  container = gimp_item_get_container (item);
  index     = gimp_item_get_index (item);

  g_object_ref (item);

467 468 469
  g_hash_table_remove (private->name_hash,
                       gimp_object_get_name (item));

470 471 472 473 474 475 476 477 478 479 480 481 482 483 484
  children = gimp_viewable_get_children (GIMP_VIEWABLE (item));

  if (children)
    {
      GList *list = gimp_item_stack_get_item_list (GIMP_ITEM_STACK (children));

      while (list)
        {
          g_hash_table_remove (private->name_hash,
                               gimp_object_get_name (list->data));

          list = g_list_remove (list, list->data);
        }
    }

485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513
  gimp_container_remove (container, GIMP_OBJECT (item));

  if (parent)
    gimp_viewable_set_parent (GIMP_VIEWABLE (item), NULL);

  gimp_item_removed (item);

  if (! new_active)
    {
      gint n_children = gimp_container_get_n_children (container);

      if (n_children > 0)
        {
          index = CLAMP (index, 0, n_children - 1);

          new_active =
            GIMP_ITEM (gimp_container_get_child_by_index (container, index));
        }
      else if (parent)
        {
          new_active = parent;
        }
    }

  g_object_unref (item);

  return new_active;
}

514
gboolean
515 516 517 518 519 520
gimp_item_tree_reorder_item (GimpItemTree *tree,
                             GimpItem     *item,
                             GimpItem     *new_parent,
                             gint          new_index,
                             gboolean      push_undo,
                             const gchar  *undo_desc)
521 522 523 524 525 526 527 528 529 530 531 532
{
  GimpItemTreePrivate *private;
  GimpContainer       *container;
  GimpContainer       *new_container;
  gint                 n_items;

  g_return_val_if_fail (GIMP_IS_ITEM_TREE (tree), FALSE);

  private = GIMP_ITEM_TREE_GET_PRIVATE (tree);

  g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (item, private->item_type),
                        FALSE);
533
  g_return_val_if_fail (gimp_item_get_tree (item) == tree, FALSE);
534 535 536 537 538
  g_return_val_if_fail (new_parent == NULL ||
                        G_TYPE_CHECK_INSTANCE_TYPE (new_parent,
                                                    private->item_type),
                        FALSE);
  g_return_val_if_fail (new_parent == NULL ||
539
                        gimp_item_get_tree (new_parent) == tree, FALSE);
540 541 542
  g_return_val_if_fail (new_parent == NULL ||
                        gimp_viewable_get_children (GIMP_VIEWABLE (new_parent)),
                        FALSE);
543 544 545 546 547
  g_return_val_if_fail (item != new_parent, FALSE);
  g_return_val_if_fail (new_parent == NULL ||
                        ! gimp_viewable_is_ancestor (GIMP_VIEWABLE (item),
                                                     GIMP_VIEWABLE (new_parent)),
                        FALSE);
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565

  container = gimp_item_get_container (item);

  if (new_parent)
    new_container = gimp_viewable_get_children (GIMP_VIEWABLE (new_parent));
  else
    new_container = tree->container;

  n_items = gimp_container_get_n_children (new_container);

  if (new_container == container)
    n_items--;

  new_index = CLAMP (new_index, 0, n_items);

  if (new_container != container ||
      new_index     != gimp_item_get_index (item))
    {
566 567
      if (push_undo)
        gimp_image_undo_push_item_reorder (private->image, undo_desc, item);
568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589

      if (new_container != container)
        {
          g_object_ref (item);

          gimp_container_remove (container, GIMP_OBJECT (item));

          gimp_viewable_set_parent (GIMP_VIEWABLE (item),
                                    GIMP_VIEWABLE (new_parent));

          gimp_container_insert (new_container, GIMP_OBJECT (item), new_index);

          g_object_unref (item);
        }
      else
        {
          gimp_container_reorder (container, GIMP_OBJECT (item), new_index);
        }
    }

  return TRUE;
}
590 591 592 593 594

void
gimp_item_tree_rename_item (GimpItemTree *tree,
                            GimpItem     *item,
                            const gchar  *new_name,
595
                            gboolean      push_undo,
596 597 598 599 600 601 602 603
                            const gchar  *undo_desc)
{
  GimpItemTreePrivate *private;

  g_return_if_fail (GIMP_IS_ITEM_TREE (tree));

  private = GIMP_ITEM_TREE_GET_PRIVATE (tree);

604
  g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (item, private->item_type));
605
  g_return_if_fail (gimp_item_get_tree (item) == tree);
606 607 608 609
  g_return_if_fail (new_name != NULL);

  if (strcmp (new_name, gimp_object_get_name (item)))
    {
610
      if (push_undo)
611 612
        gimp_image_undo_push_item_rename (gimp_item_get_image (item),
                                          undo_desc, item);
613

614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632
      gimp_item_tree_uniquefy_name (tree, item, new_name);
    }
}


/*  private functions  */

static void
gimp_item_tree_uniquefy_name (GimpItemTree *tree,
                              GimpItem     *item,
                              const gchar  *new_name)
{
  GimpItemTreePrivate *private = GIMP_ITEM_TREE_GET_PRIVATE (tree);

  if (new_name)
    {
      g_hash_table_remove (private->name_hash,
                           gimp_object_get_name (item));

633 634
      gimp_object_set_name (GIMP_OBJECT (item), new_name);
    }
635

636 637 638 639 640 641 642 643
  /* Remove any trailing whitespace. */
  if (gimp_object_get_name (item))
    {
      gchar *name = g_strchomp (g_strdup (gimp_object_get_name (item)));

      gimp_object_take_name (GIMP_OBJECT (item), name);
    }

644 645
  if (g_hash_table_lookup (private->name_hash,
                           gimp_object_get_name (item)))
646
    {
647 648 649
      gchar      *name        = g_strdup (gimp_object_get_name (item));
      gchar      *new_name    = NULL;
      gint        number      = 0;
650
      gint        precision   = 1;
651
      GRegex     *end_numbers = g_regex_new (" ?#([0-9]+)\\s*$", 0, 0, NULL);
652 653 654
      GMatchInfo *match_info  = NULL;

      if (g_regex_match (end_numbers, name, 0, &match_info))
655
        {
656 657
          gchar *match;
          gint   start_pos;
658

659
          match  = g_match_info_fetch (match_info, 1);
660 661 662 663 664 665
          if (match && match[0] == '0')
            {
              precision = strlen (match);
            }
          number = atoi (match);
          g_free (match);
666

667
          g_match_info_fetch_pos (match_info, 0,
668 669
                                  &start_pos, NULL);
          name[start_pos] = '\0';
670
        }
671 672
      g_match_info_free (match_info);
      g_regex_unref (end_numbers);
673

674 675 676 677 678
      do
        {
          number++;

          g_free (new_name);
679

680
          new_name = g_strdup_printf ("%s #%.*d",
681
                                      name,
682
                                      precision,
683
                                      number);
684 685
        }
      while (g_hash_table_lookup (private->name_hash, new_name));
686 687

      g_free (name);
688 689

      gimp_object_take_name (GIMP_OBJECT (item), new_name);
690 691 692 693 694
    }

  g_hash_table_insert (private->name_hash,
                       (gpointer) gimp_object_get_name (item),
                       item);
695
}