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

Update filesystem dock on script, scene, and resource creation #52189

Closed
Closed
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
19 changes: 19 additions & 0 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "core/extension/native_extension_manager.h"
#include "core/input/input.h"
#include "core/io/config_file.h"
#include "core/io/dir_access.h"
#include "core/io/file_access.h"
#include "core/io/image_loader.h"
#include "core/io/resource_loader.h"
Expand Down Expand Up @@ -1130,6 +1131,10 @@ void EditorNode::save_resource_in_path(const Ref<Resource> &p_resource, const St
}

String path = ProjectSettings::get_singleton()->localize_path(p_path);
DirAccess *da = DirAccess::open("res://");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should probably protect the remaining of the function from crash with ERR_FAIL_COND(!da).

bool is_new = !da->file_exists(path);
memdelete(da);

Error err = ResourceSaver::save(path, p_resource, flg | ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS);

if (err != OK) {
Expand All @@ -1142,6 +1147,10 @@ void EditorNode::save_resource_in_path(const Ref<Resource> &p_resource, const St
}

((Resource *)p_resource.ptr())->set_path(path);

if (is_new) {
emit_signal(SNAME("resource_created"), p_resource);
}
emit_signal(SNAME("resource_saved"), p_resource);
editor_data.notify_resource_saved(p_resource);
}
Expand Down Expand Up @@ -1673,6 +1682,10 @@ void EditorNode::_save_scene(String p_file, int idx) {
}
flg |= ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS;

DirAccess *da = DirAccess::open("res://");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

bool is_new = !da->file_exists(p_file);
memdelete(da);

err = ResourceSaver::save(p_file, sdata, flg);

_save_external_resources();
Expand All @@ -1696,6 +1709,11 @@ void EditorNode::_save_scene(String p_file, int idx) {

_update_title();
_update_scene_tabs();

if (is_new) {
emit_signal(SNAME("resource_created"), sdata);
}
emit_signal(SNAME("resource_saved"), sdata);
} else {
_dialog_display_save_error(p_file, err);
}
Expand Down Expand Up @@ -5655,6 +5673,7 @@ void EditorNode::_bind_methods() {
ADD_SIGNAL(MethodInfo("stop_pressed"));
ADD_SIGNAL(MethodInfo("request_help_search"));
ADD_SIGNAL(MethodInfo("script_add_function_request", PropertyInfo(Variant::OBJECT, "obj"), PropertyInfo(Variant::STRING, "function"), PropertyInfo(Variant::PACKED_STRING_ARRAY, "args")));
ADD_SIGNAL(MethodInfo("resource_created", PropertyInfo(Variant::OBJECT, "obj")));
ADD_SIGNAL(MethodInfo("resource_saved", PropertyInfo(Variant::OBJECT, "obj")));
ADD_SIGNAL(MethodInfo("project_settings_changed"));
}
Expand Down
20 changes: 14 additions & 6 deletions editor/filesystem_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,12 @@ void FileSystemDock::_notification(int p_what) {
}
} break;

case NOTIFICATION_READY: {
// Scenes and other resources are saved outside of this class, and they may look out of order
// or mislabeled in the dock; so we need to update the list here.
editor->connect("resource_created", callable_mp(this, &FileSystemDock::_resource_created));
} break;

case NOTIFICATION_PROCESS: {
if (EditorFileSystem::get_singleton()->is_scanning()) {
scanning_progress->set_value(EditorFileSystem::get_singleton()->get_scanning_progress() * 100);
Expand Down Expand Up @@ -1387,7 +1393,6 @@ void FileSystemDock::_make_dir_confirm() {
memdelete(da);

if (err == OK) {
print_verbose("FileSystem: calling rescan.");
_rescan();
} else {
EditorNode::get_singleton()->show_warning(TTR("Could not create folder."));
Expand Down Expand Up @@ -1514,7 +1519,6 @@ void FileSystemDock::_rename_operation_confirm() {

editor->set_current_tab(current_tab);

print_verbose("FileSystem: calling rescan.");
_rescan();

print_verbose("FileSystem: saving moved scenes.");
Expand Down Expand Up @@ -1554,7 +1558,6 @@ void FileSystemDock::_duplicate_operation_confirm() {
_try_duplicate_item(to_duplicate, new_path);

// Rescan everything.
print_verbose("FileSystem: calling rescan.");
_rescan();
}

Expand Down Expand Up @@ -1625,7 +1628,6 @@ void FileSystemDock::_move_operation_confirm(const String &p_to_path, bool p_ove

editor->set_current_tab(current_tab);

print_verbose("FileSystem: calling rescan.");
_rescan();

print_verbose("FileSystem: saving moved scenes.");
Expand Down Expand Up @@ -1957,7 +1959,11 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected
}
}

void FileSystemDock::_resource_created() {
void FileSystemDock::_resource_created(const Ref<Resource> &p_resource) {
_rescan();
}

void FileSystemDock::_resource_confirm() {
Variant c = new_resource_dialog->instance_selected();

ERR_FAIL_COND(!c);
Expand Down Expand Up @@ -2009,6 +2015,7 @@ void FileSystemDock::_search_changed(const String &p_text, const Control *p_from
}

void FileSystemDock::_rescan() {
print_verbose("FileSystem: calling rescan.");
_set_scanning_mode();
EditorFileSystem::get_singleton()->scan();
}
Expand Down Expand Up @@ -2968,11 +2975,12 @@ FileSystemDock::FileSystemDock(EditorNode *p_editor) {
make_script_dialog = memnew(ScriptCreateDialog);
make_script_dialog->set_title(TTR("Create Script"));
add_child(make_script_dialog);
make_script_dialog->connect("script_created", callable_mp(this, &FileSystemDock::_rescan).unbind(1));

new_resource_dialog = memnew(CreateDialog);
add_child(new_resource_dialog);
new_resource_dialog->set_base_type("Resource");
new_resource_dialog->connect("create", callable_mp(this, &FileSystemDock::_resource_created));
new_resource_dialog->connect("create", callable_mp(this, &FileSystemDock::_resource_confirm));

searched_string = String();
uncollapsed_paths_before_search = Vector<String>();
Expand Down
3 changes: 2 additions & 1 deletion editor/filesystem_dock.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ class FileSystemDock : public VBoxContainer {
void _files_moved(String p_old_file, String p_new_file);
void _folder_moved(String p_old_folder, String p_new_folder);

void _resource_created();
void _resource_created(const Ref<Resource> &p_resource);
void _resource_confirm();
void _make_dir_confirm();
void _make_scene_confirm();
void _rename_operation_confirm();
Expand Down