Display scene file extensions in the editor only if there's ambiguity
This also simplifies the Editor Settings as the extension is now
automatically shown to avoid ambiguity.
(cherry picked from commit 218d124755
)
This commit is contained in:
parent
645842e0e8
commit
4881d96ef0
4 changed files with 27 additions and 9 deletions
|
@ -790,18 +790,34 @@ Ref<Script> EditorData::get_scene_root_script(int p_idx) const {
|
||||||
return s;
|
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());
|
ERR_FAIL_INDEX_V(p_idx, edited_scene.size(), String());
|
||||||
if (!edited_scene[p_idx].root)
|
if (!edited_scene[p_idx].root)
|
||||||
return TTR("[empty]");
|
return TTR("[empty]");
|
||||||
if (edited_scene[p_idx].root->get_filename() == "")
|
if (edited_scene[p_idx].root->get_filename() == "")
|
||||||
return TTR("[unsaved]");
|
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();
|
const String filename = edited_scene[p_idx].root->get_filename().get_file();
|
||||||
if (!show_ext) {
|
const String basename = filename.get_basename();
|
||||||
name = name.get_basename();
|
|
||||||
|
if (p_always_strip_extension) {
|
||||||
|
return basename;
|
||||||
}
|
}
|
||||||
return name;
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Else, return just the basename as there's no ambiguity.
|
||||||
|
return basename;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorData::set_scene_path(int p_idx, const String &p_path) {
|
void EditorData::set_scene_path(int p_idx, const String &p_path) {
|
||||||
|
|
|
@ -193,7 +193,7 @@ public:
|
||||||
Node *get_edited_scene_root(int p_idx = -1);
|
Node *get_edited_scene_root(int p_idx = -1);
|
||||||
int get_edited_scene_count() const;
|
int get_edited_scene_count() const;
|
||||||
Vector<EditedScene> get_edited_scenes() const;
|
Vector<EditedScene> get_edited_scenes() const;
|
||||||
String get_scene_title(int p_idx) const;
|
String get_scene_title(int p_idx, bool p_always_strip_extension = false) const;
|
||||||
String get_scene_path(int p_idx) const;
|
String get_scene_path(int p_idx) const;
|
||||||
String get_scene_type(int p_idx) const;
|
String get_scene_type(int p_idx) const;
|
||||||
void set_scene_path(int p_idx, const String &p_path);
|
void set_scene_path(int p_idx, const String &p_path);
|
||||||
|
|
|
@ -398,7 +398,6 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
|
||||||
hints["interface/theme/custom_theme"] = PropertyInfo(Variant::STRING, "interface/theme/custom_theme", PROPERTY_HINT_GLOBAL_FILE, "*.res,*.tres,*.theme", PROPERTY_USAGE_DEFAULT);
|
hints["interface/theme/custom_theme"] = PropertyInfo(Variant::STRING, "interface/theme/custom_theme", PROPERTY_HINT_GLOBAL_FILE, "*.res,*.tres,*.theme", PROPERTY_USAGE_DEFAULT);
|
||||||
|
|
||||||
// Scene tabs
|
// Scene tabs
|
||||||
_initial_set("interface/scene_tabs/show_extension", false);
|
|
||||||
_initial_set("interface/scene_tabs/show_thumbnail_on_hover", true);
|
_initial_set("interface/scene_tabs/show_thumbnail_on_hover", true);
|
||||||
_initial_set("interface/scene_tabs/resize_if_many_tabs", true);
|
_initial_set("interface/scene_tabs/resize_if_many_tabs", true);
|
||||||
_initial_set("interface/scene_tabs/minimum_width", 50);
|
_initial_set("interface/scene_tabs/minimum_width", 50);
|
||||||
|
|
|
@ -449,7 +449,10 @@ String RenameDialog::_substitute(const String &subject, const Node *node, int co
|
||||||
}
|
}
|
||||||
|
|
||||||
int current = EditorNode::get_singleton()->get_editor_data().get_edited_scene();
|
int current = EditorNode::get_singleton()->get_editor_data().get_edited_scene();
|
||||||
result = result.replace("${SCENE}", EditorNode::get_singleton()->get_editor_data().get_scene_title(current));
|
// Always request the scene title with the extension stripped.
|
||||||
|
// Otherwise, the result could vary depending on whether a scene with the same name
|
||||||
|
// (but different extension) is currently open.
|
||||||
|
result = result.replace("${SCENE}", EditorNode::get_singleton()->get_editor_data().get_scene_title(current, true));
|
||||||
|
|
||||||
Node *root_node = SceneTree::get_singleton()->get_edited_scene_root();
|
Node *root_node = SceneTree::get_singleton()->get_edited_scene_root();
|
||||||
if (root_node) {
|
if (root_node) {
|
||||||
|
|
Loading…
Reference in a new issue