mirror of
https://gitlab.gnome.org/GNOME/gimp.git
synced 2025-10-08 07:22:41 +02:00
app: allow item numbering schemes with fixed number of digits.
If someone ended a layer name with 001, one would expect the next layer to be 002 and not 2. We now account for this.
This commit is contained in:
@@ -660,6 +660,7 @@ gimp_item_tree_uniquefy_name (GimpItemTree *tree,
|
|||||||
gchar *name = g_strdup (gimp_object_get_name (item));
|
gchar *name = g_strdup (gimp_object_get_name (item));
|
||||||
gchar *new_name = NULL;
|
gchar *new_name = NULL;
|
||||||
gint number = 0;
|
gint number = 0;
|
||||||
|
gint precision = 1;
|
||||||
gboolean hashed = TRUE;
|
gboolean hashed = TRUE;
|
||||||
GRegex *end_numbers = g_regex_new ("(^|[^0-9])([0-9]+)\\s*$", 0, 0, NULL);
|
GRegex *end_numbers = g_regex_new ("(^|[^0-9])([0-9]+)\\s*$", 0, 0, NULL);
|
||||||
GMatchInfo *match_info = NULL;
|
GMatchInfo *match_info = NULL;
|
||||||
@@ -667,10 +668,18 @@ gimp_item_tree_uniquefy_name (GimpItemTree *tree,
|
|||||||
if (g_regex_match (end_numbers, name, 0, &match_info))
|
if (g_regex_match (end_numbers, name, 0, &match_info))
|
||||||
{
|
{
|
||||||
/* Allow counting styles without a hash as alternative. */
|
/* Allow counting styles without a hash as alternative. */
|
||||||
gint start_pos;
|
gchar *match;
|
||||||
|
gint start_pos;
|
||||||
|
|
||||||
hashed = FALSE;
|
hashed = FALSE;
|
||||||
number = atoi (g_match_info_fetch (match_info, 2));
|
|
||||||
|
match = g_match_info_fetch (match_info, 2);
|
||||||
|
if (match && match[0] == '0')
|
||||||
|
{
|
||||||
|
precision = strlen (match);
|
||||||
|
}
|
||||||
|
number = atoi (match);
|
||||||
|
g_free (match);
|
||||||
|
|
||||||
g_match_info_fetch_pos (match_info, 2,
|
g_match_info_fetch_pos (match_info, 2,
|
||||||
&start_pos, NULL);
|
&start_pos, NULL);
|
||||||
@@ -685,9 +694,10 @@ gimp_item_tree_uniquefy_name (GimpItemTree *tree,
|
|||||||
|
|
||||||
g_free (new_name);
|
g_free (new_name);
|
||||||
|
|
||||||
new_name = g_strdup_printf ("%s%s%d",
|
new_name = g_strdup_printf ("%s%s%.*d",
|
||||||
name,
|
name,
|
||||||
hashed ? " #" : "",
|
hashed ? " #" : "",
|
||||||
|
precision,
|
||||||
number);
|
number);
|
||||||
}
|
}
|
||||||
while (g_hash_table_lookup (private->name_hash, new_name));
|
while (g_hash_table_lookup (private->name_hash, new_name));
|
||||||
|
Reference in New Issue
Block a user