From a7d4b1e7f7cf62168bda5bc6110bb9bf9cb78bc9 Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Tue, 28 May 2024 09:46:21 +0200 Subject: [PATCH] Editor: Use the full name for tabs if the short name is not unique --- editor/limbo_ai_editor_plugin.cpp | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/editor/limbo_ai_editor_plugin.cpp b/editor/limbo_ai_editor_plugin.cpp index a264913..2fbc58e 100644 --- a/editor/limbo_ai_editor_plugin.cpp +++ b/editor/limbo_ai_editor_plugin.cpp @@ -971,21 +971,42 @@ void LimboAIEditor::_tab_closed(int p_tab) { void LimboAIEditor::_update_tabs() { updating_tabs = true; tab_bar->clear_tabs(); + + Vector short_names; + // Keep track of how many times each short name is used. + HashMap usage_counts; + for (int i = 0; i < history.size(); i++) { String tab_name; - if (history[i]->get_path().is_empty()) { - tab_name = "[new]"; - } else if (history[i]->get_path().contains("::")) { + if (history[i]->get_path().contains("::")) { tab_name = history[i]->get_path().get_file(); } else { tab_name = history[i]->get_path().get_file().get_basename(); } + short_names.append(tab_name); + if (usage_counts.has(tab_name)) { + usage_counts[tab_name] += 1; + } else { + usage_counts[tab_name] = 1; + } + } + + for (int i = 0; i < short_names.size(); i++) { + String tab_name = short_names[i]; + if (tab_name.is_empty()) { + tab_name = "[new]"; + } else if (usage_counts[tab_name] > 1) { + // Use the full name if the short name is not unique. + tab_name = history[i]->get_path().trim_prefix("res://"); + } tab_bar->add_tab(tab_name, LimboUtility::get_singleton()->get_task_icon("BehaviorTree")); } + if (idx_history >= 0) { ERR_FAIL_INDEX(idx_history, history.size()); tab_bar->set_current_tab(idx_history); } + updating_tabs = false; }