summaryrefslogtreecommitdiff
path: root/editor/editor_data.cpp
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2021-03-23 12:58:07 +0100
committerGitHub <noreply@github.com>2021-03-23 12:58:07 +0100
commitecfa2f8de2feb0fc2fe0e6989c362630ce23f1f2 (patch)
treef538a9c486d7efbaf6125cfdad969365eea4163b /editor/editor_data.cpp
parent70eff30c5f5f4f54a9c0ed4d65d7a664e45f38ea (diff)
parent218d1247555417a203845c35160d5cc8af72e1d2 (diff)
Merge pull request #35320 from Calinou/edited-scene-extension-if-ambiguous
Display scene file extensions in the editor only if there's ambiguity
Diffstat (limited to 'editor/editor_data.cpp')
-rw-r--r--editor/editor_data.cpp28
1 files changed, 22 insertions, 6 deletions
diff --git a/editor/editor_data.cpp b/editor/editor_data.cpp
index 213c3f5631..fa4703d425 100644
--- a/editor/editor_data.cpp
+++ b/editor/editor_data.cpp
@@ -741,7 +741,7 @@ Ref<Script> EditorData::get_scene_root_script(int p_idx) const {
return s;
}
-String EditorData::get_scene_title(int p_idx) const {
+String EditorData::get_scene_title(int p_idx, bool p_always_strip_extension) const {
ERR_FAIL_INDEX_V(p_idx, edited_scene.size(), String());
if (!edited_scene[p_idx].root) {
return TTR("[empty]");
@@ -749,12 +749,28 @@ String EditorData::get_scene_title(int p_idx) const {
if (edited_scene[p_idx].root->get_filename() == "") {
return TTR("[unsaved]");
}
- bool show_ext = EDITOR_DEF("interface/scene_tabs/show_extension", false);
- String name = edited_scene[p_idx].root->get_filename().get_file();
- if (!show_ext) {
- name = name.get_basename();
+
+ const String filename = edited_scene[p_idx].root->get_filename().get_file();
+ const String basename = filename.get_basename();
+
+ if (p_always_strip_extension) {
+ return basename;
+ }
+
+ // Return the filename including the extension if there's ambiguity (e.g. both `foo.tscn` and `foo.scn` are being edited).
+ for (int i = 0; i < edited_scene.size(); i++) {
+ if (i == p_idx) {
+ // Don't compare the edited scene against itself.
+ continue;
+ }
+
+ if (edited_scene[i].root && basename == edited_scene[i].root->get_filename().get_file().get_basename()) {
+ return filename;
+ }
}
- return name;
+
+ // Else, return just the basename as there's no ambiguity.
+ return basename;
}
void EditorData::set_scene_path(int p_idx, const String &p_path) {