Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FileSystem Dock] Add option to show some unsupported files in the dock. #96603

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion doc/classes/EditorSettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,11 @@
If [code]true[/code], displays folders in the FileSystem dock's bottom pane when split mode is enabled. If [code]false[/code], only files will be displayed in the bottom pane. Split mode can be toggled by pressing the icon next to the [code]res://[/code] folder path.
[b]Note:[/b] This setting has no effect when split mode is disabled (which is the default).
</member>
<member name="docks/filesystem/other_file_extensions" type="String" setter="" getter="">
A comma separated list of unsupported file extensions to show in the FileSystem dock, e.g. [code]"ico,icns"[/code].
</member>
<member name="docks/filesystem/textfile_extensions" type="String" setter="" getter="">
List of file extensions to consider as editable text files in the FileSystem dock (by double-clicking on the files).
A comma separated list of file extensions to consider as editable text files in the FileSystem dock (by double-clicking on the files), e.g. [code]"txt,md,cfg,ini,log,json,yml,yaml,toml,xml"[/code].
</member>
<member name="docks/filesystem/thumbnail_size" type="int" setter="" getter="">
The thumbnail size to use in the FileSystem dock (in pixels). See also [member filesystem/file_dialog/thumbnail_size].
Expand Down
29 changes: 25 additions & 4 deletions editor/editor_file_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,7 @@ void EditorFileSystem::_process_file_system(const ScannedDirectory *p_scan_dir,
fi->script_class_name = _get_global_script_class(fi->type, path, &fi->script_class_extends, &fi->script_class_icon_path);
fi->modified_time = 0;
fi->import_modified_time = 0;
fi->import_valid = fi->type == "TextFile" ? true : ResourceLoader::is_import_valid(path);
fi->import_valid = (fi->type == "TextFile" || fi->type == "OtherFile") ? true : ResourceLoader::is_import_valid(path);

ItemAction ia;
ia.action = ItemAction::ACTION_FILE_TEST_REIMPORT;
Expand Down Expand Up @@ -1118,6 +1118,9 @@ void EditorFileSystem::_process_file_system(const ScannedDirectory *p_scan_dir,
if (fi->type == "" && textfile_extensions.has(ext)) {
fi->type = "TextFile";
}
if (fi->type == "" && other_file_extensions.has(ext)) {
fi->type = "OtherFile";
}
fi->uid = ResourceLoader::get_resource_uid(path);
fi->script_class_name = _get_global_script_class(fi->type, path, &fi->script_class_extends, &fi->script_class_icon_path);
fi->deps = _get_dependencies(path);
Expand Down Expand Up @@ -1263,8 +1266,11 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir, ScanPr
if (fi->type == "" && textfile_extensions.has(ext)) {
fi->type = "TextFile";
}
if (fi->type == "" && other_file_extensions.has(ext)) {
fi->type = "OtherFile";
}
fi->script_class_name = _get_global_script_class(fi->type, path, &fi->script_class_extends, &fi->script_class_icon_path);
fi->import_valid = fi->type == "TextFile" ? true : ResourceLoader::is_import_valid(path);
fi->import_valid = (fi->type == "TextFile" || fi->type == "OtherFile") ? true : ResourceLoader::is_import_valid(path);
fi->import_group_file = ResourceLoader::get_import_group_file(path);

{
Expand Down Expand Up @@ -2118,6 +2124,9 @@ void EditorFileSystem::update_files(const Vector<String> &p_script_paths) {
if (type.is_empty() && textfile_extensions.has(file.get_extension())) {
type = "TextFile";
}
if (type.is_empty() && other_file_extensions.has(file.get_extension())) {
type = "OtherFile";
}
String script_class = ResourceLoader::get_resource_script_class(file);

ResourceUID::ID uid = ResourceLoader::get_resource_uid(file);
Expand All @@ -2137,7 +2146,7 @@ void EditorFileSystem::update_files(const Vector<String> &p_script_paths) {
EditorFileSystemDirectory::FileInfo *fi = memnew(EditorFileSystemDirectory::FileInfo);
fi->file = file_name;
fi->import_modified_time = 0;
fi->import_valid = type == "TextFile" ? true : ResourceLoader::is_import_valid(file);
fi->import_valid = (type == "TextFile" || type == "OtherFile") ? true : ResourceLoader::is_import_valid(file);

if (idx == fs->files.size()) {
fs->files.push_back(fi);
Expand All @@ -2161,7 +2170,7 @@ void EditorFileSystem::update_files(const Vector<String> &p_script_paths) {
fs->files[cpos]->import_group_file = ResourceLoader::get_import_group_file(file);
fs->files[cpos]->modified_time = FileAccess::get_modified_time(file);
fs->files[cpos]->deps = _get_dependencies(file);
fs->files[cpos]->import_valid = type == "TextFile" ? true : ResourceLoader::is_import_valid(file);
fs->files[cpos]->import_valid = (type == "TextFile" || type == "OtherFile") ? true : ResourceLoader::is_import_valid(file);

if (uid != ResourceUID::INVALID_ID) {
if (ResourceUID::get_singleton()->has_id(uid)) {
Expand Down Expand Up @@ -2419,6 +2428,9 @@ Error EditorFileSystem::_reimport_group(const String &p_group_file, const Vector
if (fs->files[cpos]->type == "" && textfile_extensions.has(file.get_extension())) {
fs->files[cpos]->type = "TextFile";
}
if (fs->files[cpos]->type == "" && other_file_extensions.has(file.get_extension())) {
fs->files[cpos]->type = "OtherFile";
}
fs->files[cpos]->import_valid = err == OK;

if (ResourceUID::get_singleton()->has_id(uid)) {
Expand Down Expand Up @@ -3119,6 +3131,7 @@ void EditorFileSystem::_update_extensions() {
valid_extensions.clear();
import_extensions.clear();
textfile_extensions.clear();
other_file_extensions.clear();

List<String> extensionsl;
ResourceLoader::get_recognized_extensions_for_type("", &extensionsl);
Expand All @@ -3134,6 +3147,14 @@ void EditorFileSystem::_update_extensions() {
valid_extensions.insert(E);
textfile_extensions.insert(E);
}
const Vector<String> other_file_ext = ((String)(EDITOR_GET("docks/filesystem/other_file_extensions"))).split(",", false);
for (const String &E : other_file_ext) {
if (valid_extensions.has(E)) {
continue;
}
valid_extensions.insert(E);
other_file_extensions.insert(E);
}

extensionsl.clear();
ResourceFormatImporter::get_singleton()->get_recognized_extensions(&extensionsl);
Expand Down
1 change: 1 addition & 0 deletions editor/editor_file_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ class EditorFileSystem : public Node {
int _insert_actions_delete_files_directory(EditorFileSystemDirectory *p_dir);

HashSet<String> textfile_extensions;
HashSet<String> other_file_extensions;
HashSet<String> valid_extensions;
HashSet<String> import_extensions;

Expand Down
18 changes: 17 additions & 1 deletion editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,7 @@ void EditorNode::_notification(int p_what) {

if (EditorSettings::get_singleton()->check_changed_settings_in_group("docks/filesystem")) {
HashSet<String> updated_textfile_extensions;
HashSet<String> updated_other_file_extensions;
bool extensions_match = true;
const Vector<String> textfile_ext = ((String)(EDITOR_GET("docks/filesystem/textfile_extensions"))).split(",", false);
for (const String &E : textfile_ext) {
Expand All @@ -833,9 +834,17 @@ void EditorNode::_notification(int p_what) {
extensions_match = false;
}
}
const Vector<String> other_file_ext = ((String)(EDITOR_GET("docks/filesystem/other_file_extensions"))).split(",", false);
for (const String &E : other_file_ext) {
updated_other_file_extensions.insert(E);
if (extensions_match && !other_file_extensions.has(E)) {
extensions_match = false;
}
}

if (!extensions_match || updated_textfile_extensions.size() < textfile_extensions.size()) {
if (!extensions_match || updated_textfile_extensions.size() < textfile_extensions.size() || updated_other_file_extensions.size() < other_file_extensions.size()) {
textfile_extensions = updated_textfile_extensions;
other_file_extensions = updated_other_file_extensions;
EditorFileSystem::get_singleton()->scan();
}
}
Expand Down Expand Up @@ -1326,6 +1335,9 @@ Error EditorNode::load_resource(const String &p_resource, bool p_ignore_broken_d
res = ResourceLoader::load(p_resource, "", ResourceFormatLoader::CACHE_MODE_REUSE, &err);
} else if (textfile_extensions.has(p_resource.get_extension())) {
res = ScriptEditor::get_singleton()->open_file(p_resource);
} else if (other_file_extensions.has(p_resource.get_extension())) {
OS::get_singleton()->shell_open(ProjectSettings::get_singleton()->globalize_path(p_resource));
return OK;
}
ERR_FAIL_COND_V(!res.is_valid(), ERR_CANT_OPEN);

Expand Down Expand Up @@ -6980,6 +6992,10 @@ EditorNode::EditorNode() {
for (const String &E : textfile_ext) {
textfile_extensions.insert(E);
}
const Vector<String> other_file_ext = ((String)(EDITOR_GET("docks/filesystem/other_file_extensions"))).split(",", false);
for (const String &E : other_file_ext) {
other_file_extensions.insert(E);
}

resource_preview = memnew(EditorResourcePreview);
add_child(resource_preview);
Expand Down
1 change: 1 addition & 0 deletions editor/editor_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ class EditorNode : public Node {
String import_reload_fn;

HashSet<String> textfile_extensions;
HashSet<String> other_file_extensions;
HashSet<FileDialog *> file_dialogs;
HashSet<EditorFileDialog *> editor_file_dialogs;

Expand Down
1 change: 1 addition & 0 deletions editor/editor_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "docks/filesystem/thumbnail_size", 64, "32,128,16")
_initial_set("docks/filesystem/always_show_folders", true);
_initial_set("docks/filesystem/textfile_extensions", "txt,md,cfg,ini,log,json,yml,yaml,toml,xml");
_initial_set("docks/filesystem/other_file_extensions", "ico,icns");

// Property editor
EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "docks/property_editor/auto_refresh_interval", 0.2, "0.01,1,0.001"); // Update 5 times per second by default.
Expand Down
2 changes: 1 addition & 1 deletion editor/export/project_export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ bool ProjectExportDialog::_fill_tree(EditorFileSystemDirectory *p_dir, TreeItem
if (p_export_filter == EditorExportPreset::EXPORT_SELECTED_SCENES && type != "PackedScene") {
continue;
}
if (type == "TextFile") {
if (type == "TextFile" || type == "OtherFile") {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion editor/filesystem_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ bool FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory
List<FileInfo> file_list;
for (int i = 0; i < p_dir->get_file_count(); i++) {
String file_type = p_dir->get_file_type(i);
if (file_type != "TextFile" && _is_file_type_disabled_by_feature_profile(file_type)) {
if (file_type != "TextFile" && file_type != "OtherFile" && _is_file_type_disabled_by_feature_profile(file_type)) {
// If type is disabled, file won't be displayed.
continue;
}
Expand Down
Loading