瀏覽代碼

Prevent renaming to an unkown extension from FileSystem dock.

(cherry picked from commit c24433f5007af7b29080e6ea4708c1efe435dcad)
jmb462 3 年之前
父節點
當前提交
3641ec61bb
共有 3 個文件被更改,包括 11 次插入0 次删除
  1. 4 0
      editor/editor_file_system.cpp
  2. 1 0
      editor/editor_file_system.h
  3. 6 0
      editor/filesystem_dock.cpp

+ 4 - 0
editor/editor_file_system.cpp

@@ -1498,6 +1498,10 @@ void EditorFileSystem::update_file(const String &p_file) {
 	_queue_update_script_classes();
 }
 
+Set<String> EditorFileSystem::get_valid_extensions() const {
+	return valid_extensions;
+}
+
 Error EditorFileSystem::_reimport_group(const String &p_group_file, const Vector<String> &p_files) {
 	String importer_name;
 

+ 1 - 0
editor/editor_file_system.h

@@ -262,6 +262,7 @@ public:
 	void scan_changes();
 	void get_changed_sources(List<String> *r_changed);
 	void update_file(const String &p_file);
+	Set<String> get_valid_extensions() const;
 
 	EditorFileSystemDirectory *get_filesystem_path(const String &p_path);
 	String get_file_type(const String &p_file) const;

+ 6 - 0
editor/filesystem_dock.cpp

@@ -1436,12 +1436,18 @@ void FileSystemDock::_folder_removed(String p_folder) {
 
 void FileSystemDock::_rename_operation_confirm() {
 	String new_name = rename_dialog_text->get_text().strip_edges();
+	String old_name = tree->get_selected()->get_text(0);
 	if (new_name.length() == 0) {
 		EditorNode::get_singleton()->show_warning(TTR("No name provided."));
 		return;
 	} else if (new_name.find("/") != -1 || new_name.find("\\") != -1 || new_name.find(":") != -1) {
 		EditorNode::get_singleton()->show_warning(TTR("Name contains invalid characters."));
 		return;
+	} else if (to_rename.is_file && old_name.get_extension() != new_name.get_extension()) {
+		if (!EditorFileSystem::get_singleton()->get_valid_extensions().find(new_name.get_extension())) {
+			EditorNode::get_singleton()->show_warning(TTR("This file extension is not recognized by the editor.\nIf you want to rename it anyway, use your operating system's file manager.\nAfter renaming to an unknown extension, the file won't be shown in the editor anymore."));
+			return;
+		}
 	}
 
 	String old_path = to_rename.path.ends_with("/") ? to_rename.path.substr(0, to_rename.path.length() - 1) : to_rename.path;