From d1d14daa1ea676b849f658e962a34703eb4b5b2c Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 1 Oct 2024 10:16:30 +0200 Subject: [PATCH] Improve timeline tracks renaming to use shared utility with proper incrementing --- Source/Editor/GUI/Timeline/Timeline.cs | 11 ++--------- Source/Editor/GUI/Timeline/Track.cs | 8 +++----- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/Source/Editor/GUI/Timeline/Timeline.cs b/Source/Editor/GUI/Timeline/Timeline.cs index 81fe950b9..556c4dcdb 100644 --- a/Source/Editor/GUI/Timeline/Timeline.cs +++ b/Source/Editor/GUI/Timeline/Timeline.cs @@ -1288,10 +1288,7 @@ namespace FlaxEditor.GUI.Timeline public virtual void AddTrack(Track track, bool withUndo = true) { // Ensure name is unique - int idx = 1; - var name = track.Name; - while (!IsTrackNameValid(track.Name)) - track.Name = string.Format("{0} {1}", name, idx++); + track.Name = GetValidTrackName(track.Name); // Add it to the timeline _tracks.Add(track); @@ -1843,11 +1840,7 @@ namespace FlaxEditor.GUI.Timeline /// The track name. public string GetValidTrackName(string name) { - string newName = name; - int count = 0; - while (!IsTrackNameValid(newName)) - newName = string.Format("{0} {1}", name, count++); - return newName; + return Utilities.Utils.IncrementNameNumber(name, IsTrackNameValid); } /// diff --git a/Source/Editor/GUI/Timeline/Track.cs b/Source/Editor/GUI/Timeline/Track.cs index 929b213e4..ec2dd63d8 100644 --- a/Source/Editor/GUI/Timeline/Track.cs +++ b/Source/Editor/GUI/Timeline/Track.cs @@ -854,11 +854,9 @@ namespace FlaxEditor.GUI.Timeline /// The base name. public void Rename(string name) { - string newName = name; - int count = 0; - while (_timeline != null && !_timeline.IsTrackNameValid(newName)) - newName = string.Format("{0} {1}", name, count++); - OnRename(newName); + if (_timeline != null) + name = _timeline.GetValidTrackName(name); + OnRename(name); } ///