Skip to content

Commit 05709b3

Browse files
committed
Merge pull request #96603 from bruvzg/fs_ext_list
[FileSystem Dock] Add option to show some unsupported files in the dock.
2 parents d06a10c + 22b19c4 commit 05709b3

8 files changed

+51
-8
lines changed

doc/classes/EditorSettings.xml

+4-1
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,11 @@
207207
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.
208208
[b]Note:[/b] This setting has no effect when split mode is disabled (which is the default).
209209
</member>
210+
<member name="docks/filesystem/other_file_extensions" type="String" setter="" getter="">
211+
A comma separated list of unsupported file extensions to show in the FileSystem dock, e.g. [code]"ico,icns"[/code].
212+
</member>
210213
<member name="docks/filesystem/textfile_extensions" type="String" setter="" getter="">
211-
List of file extensions to consider as editable text files in the FileSystem dock (by double-clicking on the files).
214+
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].
212215
</member>
213216
<member name="docks/filesystem/thumbnail_size" type="int" setter="" getter="">
214217
The thumbnail size to use in the FileSystem dock (in pixels). See also [member filesystem/file_dialog/thumbnail_size].

editor/editor_file_system.cpp

+25-4
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,7 @@ void EditorFileSystem::_process_file_system(const ScannedDirectory *p_scan_dir,
10751075
fi->script_class_name = _get_global_script_class(fi->type, path, &fi->script_class_extends, &fi->script_class_icon_path);
10761076
fi->modified_time = 0;
10771077
fi->import_modified_time = 0;
1078-
fi->import_valid = fi->type == "TextFile" ? true : ResourceLoader::is_import_valid(path);
1078+
fi->import_valid = (fi->type == "TextFile" || fi->type == "OtherFile") ? true : ResourceLoader::is_import_valid(path);
10791079

10801080
ItemAction ia;
10811081
ia.action = ItemAction::ACTION_FILE_TEST_REIMPORT;
@@ -1118,6 +1118,9 @@ void EditorFileSystem::_process_file_system(const ScannedDirectory *p_scan_dir,
11181118
if (fi->type == "" && textfile_extensions.has(ext)) {
11191119
fi->type = "TextFile";
11201120
}
1121+
if (fi->type == "" && other_file_extensions.has(ext)) {
1122+
fi->type = "OtherFile";
1123+
}
11211124
fi->uid = ResourceLoader::get_resource_uid(path);
11221125
fi->script_class_name = _get_global_script_class(fi->type, path, &fi->script_class_extends, &fi->script_class_icon_path);
11231126
fi->deps = _get_dependencies(path);
@@ -1263,8 +1266,11 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir, ScanPr
12631266
if (fi->type == "" && textfile_extensions.has(ext)) {
12641267
fi->type = "TextFile";
12651268
}
1269+
if (fi->type == "" && other_file_extensions.has(ext)) {
1270+
fi->type = "OtherFile";
1271+
}
12661272
fi->script_class_name = _get_global_script_class(fi->type, path, &fi->script_class_extends, &fi->script_class_icon_path);
1267-
fi->import_valid = fi->type == "TextFile" ? true : ResourceLoader::is_import_valid(path);
1273+
fi->import_valid = (fi->type == "TextFile" || fi->type == "OtherFile") ? true : ResourceLoader::is_import_valid(path);
12681274
fi->import_group_file = ResourceLoader::get_import_group_file(path);
12691275

12701276
{
@@ -2118,6 +2124,9 @@ void EditorFileSystem::update_files(const Vector<String> &p_script_paths) {
21182124
if (type.is_empty() && textfile_extensions.has(file.get_extension())) {
21192125
type = "TextFile";
21202126
}
2127+
if (type.is_empty() && other_file_extensions.has(file.get_extension())) {
2128+
type = "OtherFile";
2129+
}
21212130
String script_class = ResourceLoader::get_resource_script_class(file);
21222131

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

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

21662175
if (uid != ResourceUID::INVALID_ID) {
21672176
if (ResourceUID::get_singleton()->has_id(uid)) {
@@ -2419,6 +2428,9 @@ Error EditorFileSystem::_reimport_group(const String &p_group_file, const Vector
24192428
if (fs->files[cpos]->type == "" && textfile_extensions.has(file.get_extension())) {
24202429
fs->files[cpos]->type = "TextFile";
24212430
}
2431+
if (fs->files[cpos]->type == "" && other_file_extensions.has(file.get_extension())) {
2432+
fs->files[cpos]->type = "OtherFile";
2433+
}
24222434
fs->files[cpos]->import_valid = err == OK;
24232435

24242436
if (ResourceUID::get_singleton()->has_id(uid)) {
@@ -3119,6 +3131,7 @@ void EditorFileSystem::_update_extensions() {
31193131
valid_extensions.clear();
31203132
import_extensions.clear();
31213133
textfile_extensions.clear();
3134+
other_file_extensions.clear();
31223135

31233136
List<String> extensionsl;
31243137
ResourceLoader::get_recognized_extensions_for_type("", &extensionsl);
@@ -3134,6 +3147,14 @@ void EditorFileSystem::_update_extensions() {
31343147
valid_extensions.insert(E);
31353148
textfile_extensions.insert(E);
31363149
}
3150+
const Vector<String> other_file_ext = ((String)(EDITOR_GET("docks/filesystem/other_file_extensions"))).split(",", false);
3151+
for (const String &E : other_file_ext) {
3152+
if (valid_extensions.has(E)) {
3153+
continue;
3154+
}
3155+
valid_extensions.insert(E);
3156+
other_file_extensions.insert(E);
3157+
}
31373158

31383159
extensionsl.clear();
31393160
ResourceFormatImporter::get_singleton()->get_recognized_extensions(&extensionsl);

editor/editor_file_system.h

+1
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ class EditorFileSystem : public Node {
235235
int _insert_actions_delete_files_directory(EditorFileSystemDirectory *p_dir);
236236

237237
HashSet<String> textfile_extensions;
238+
HashSet<String> other_file_extensions;
238239
HashSet<String> valid_extensions;
239240
HashSet<String> import_extensions;
240241

editor/editor_node.cpp

+17-1
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,7 @@ void EditorNode::_notification(int p_what) {
825825

826826
if (EditorSettings::get_singleton()->check_changed_settings_in_group("docks/filesystem")) {
827827
HashSet<String> updated_textfile_extensions;
828+
HashSet<String> updated_other_file_extensions;
828829
bool extensions_match = true;
829830
const Vector<String> textfile_ext = ((String)(EDITOR_GET("docks/filesystem/textfile_extensions"))).split(",", false);
830831
for (const String &E : textfile_ext) {
@@ -833,9 +834,17 @@ void EditorNode::_notification(int p_what) {
833834
extensions_match = false;
834835
}
835836
}
837+
const Vector<String> other_file_ext = ((String)(EDITOR_GET("docks/filesystem/other_file_extensions"))).split(",", false);
838+
for (const String &E : other_file_ext) {
839+
updated_other_file_extensions.insert(E);
840+
if (extensions_match && !other_file_extensions.has(E)) {
841+
extensions_match = false;
842+
}
843+
}
836844

837-
if (!extensions_match || updated_textfile_extensions.size() < textfile_extensions.size()) {
845+
if (!extensions_match || updated_textfile_extensions.size() < textfile_extensions.size() || updated_other_file_extensions.size() < other_file_extensions.size()) {
838846
textfile_extensions = updated_textfile_extensions;
847+
other_file_extensions = updated_other_file_extensions;
839848
EditorFileSystem::get_singleton()->scan();
840849
}
841850
}
@@ -1326,6 +1335,9 @@ Error EditorNode::load_resource(const String &p_resource, bool p_ignore_broken_d
13261335
res = ResourceLoader::load(p_resource, "", ResourceFormatLoader::CACHE_MODE_REUSE, &err);
13271336
} else if (textfile_extensions.has(p_resource.get_extension())) {
13281337
res = ScriptEditor::get_singleton()->open_file(p_resource);
1338+
} else if (other_file_extensions.has(p_resource.get_extension())) {
1339+
OS::get_singleton()->shell_open(ProjectSettings::get_singleton()->globalize_path(p_resource));
1340+
return OK;
13291341
}
13301342
ERR_FAIL_COND_V(!res.is_valid(), ERR_CANT_OPEN);
13311343

@@ -6980,6 +6992,10 @@ EditorNode::EditorNode() {
69806992
for (const String &E : textfile_ext) {
69816993
textfile_extensions.insert(E);
69826994
}
6995+
const Vector<String> other_file_ext = ((String)(EDITOR_GET("docks/filesystem/other_file_extensions"))).split(",", false);
6996+
for (const String &E : other_file_ext) {
6997+
other_file_extensions.insert(E);
6998+
}
69836999

69847000
resource_preview = memnew(EditorResourcePreview);
69857001
add_child(resource_preview);

editor/editor_node.h

+1
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@ class EditorNode : public Node {
489489
String import_reload_fn;
490490

491491
HashSet<String> textfile_extensions;
492+
HashSet<String> other_file_extensions;
492493
HashSet<FileDialog *> file_dialogs;
493494
HashSet<EditorFileDialog *> editor_file_dialogs;
494495

editor/editor_settings.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,7 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
593593
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "docks/filesystem/thumbnail_size", 64, "32,128,16")
594594
_initial_set("docks/filesystem/always_show_folders", true);
595595
_initial_set("docks/filesystem/textfile_extensions", "txt,md,cfg,ini,log,json,yml,yaml,toml,xml");
596+
_initial_set("docks/filesystem/other_file_extensions", "ico,icns");
596597

597598
// Property editor
598599
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.

editor/export/project_export.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ bool ProjectExportDialog::_fill_tree(EditorFileSystemDirectory *p_dir, TreeItem
903903
if (p_export_filter == EditorExportPreset::EXPORT_SELECTED_SCENES && type != "PackedScene") {
904904
continue;
905905
}
906-
if (type == "TextFile") {
906+
if (type == "TextFile" || type == "OtherFile") {
907907
continue;
908908
}
909909

editor/filesystem_dock.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ bool FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory
271271
List<FileInfo> file_list;
272272
for (int i = 0; i < p_dir->get_file_count(); i++) {
273273
String file_type = p_dir->get_file_type(i);
274-
if (file_type != "TextFile" && _is_file_type_disabled_by_feature_profile(file_type)) {
274+
if (file_type != "TextFile" && file_type != "OtherFile" && _is_file_type_disabled_by_feature_profile(file_type)) {
275275
// If type is disabled, file won't be displayed.
276276
continue;
277277
}

0 commit comments

Comments
 (0)