summaryrefslogtreecommitdiffstats
path: root/editor/filesystem_dock.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/filesystem_dock.cpp')
-rw-r--r--editor/filesystem_dock.cpp140
1 files changed, 97 insertions, 43 deletions
diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp
index 0f83e109fa..233f20a8b3 100644
--- a/editor/filesystem_dock.cpp
+++ b/editor/filesystem_dock.cpp
@@ -453,7 +453,7 @@ void FileSystemDock::_update_tree(const Vector<String> &p_uncollapsed_paths, boo
int index;
EditorFileSystemDirectory *dir = EditorFileSystem::get_singleton()->find_file(favorite, &index);
if (dir) {
- icon = _get_tree_item_icon(dir->get_file_import_is_valid(index), dir->get_file_path(index), dir->get_file_type(index));
+ icon = _get_tree_item_icon(dir->get_file_import_is_valid(index), dir->get_file_type(index), _get_entry_script_icon(dir, index));
} else {
icon = get_editor_theme_icon(SNAME("File"));
}
@@ -576,9 +576,9 @@ void FileSystemDock::_notification(int p_what) {
if ((String(dd["favorite"]) == "all")) {
tree->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN);
}
- } else if ((String(dd["type"]) == "files") || (String(dd["type"]) == "files_and_dirs") || (String(dd["type"]) == "resource")) {
+ } else if ((String(dd["type"]) == "files") || (String(dd["type"]) == "files_and_dirs")) {
tree->set_drop_mode_flags(Tree::DROP_MODE_ON_ITEM | Tree::DROP_MODE_INBETWEEN);
- } else if ((String(dd["type"]) == "nodes")) {
+ } else if ((String(dd["type"]) == "nodes") || (String(dd["type"]) == "resource")) {
holding_branch = true;
TreeItem *item = tree->get_next_selected(tree->get_root());
while (item) {
@@ -776,12 +776,7 @@ void FileSystemDock::navigate_to_path(const String &p_path) {
_navigate_to_path(p_path);
// Ensure that the FileSystem dock is visible.
- if (get_window() == get_tree()->get_root()) {
- TabContainer *tab_container = (TabContainer *)get_parent_control();
- tab_container->set_current_tab(tab_container->get_tab_idx_from_control((Control *)this));
- } else {
- get_window()->grab_focus();
- }
+ EditorDockManager::get_singleton()->focus_dock(this);
}
void FileSystemDock::_file_list_thumbnail_done(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, const Variant &p_udata) {
@@ -885,7 +880,7 @@ void FileSystemDock::_search(EditorFileSystemDirectory *p_path, List<FileInfo> *
struct FileSystemDock::FileInfoTypeComparator {
bool operator()(const FileInfo &p_a, const FileInfo &p_b) const {
- return NaturalNoCaseComparator()(p_a.name.get_extension() + p_a.type + p_a.name.get_basename(), p_b.name.get_extension() + p_b.type + p_b.name.get_basename());
+ return FileNoCaseComparator()(p_a.name.get_extension() + p_a.type + p_a.name.get_basename(), p_b.name.get_extension() + p_b.type + p_b.name.get_basename());
}
};
@@ -1009,6 +1004,7 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) {
fi.path = favorite;
if (efd) {
fi.type = efd->get_file_type(index);
+ fi.icon_path = _get_entry_script_icon(efd, index);
fi.import_broken = !efd->get_file_import_is_valid(index);
fi.modified_time = efd->get_file_modified_time(index);
} else {
@@ -1101,6 +1097,7 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) {
fi.name = efd->get_file(i);
fi.path = directory.path_join(fi.name);
fi.type = efd->get_file_type(i);
+ fi.icon_path = _get_entry_script_icon(efd, i);
fi.import_broken = !efd->get_file_import_is_valid(i);
fi.modified_time = efd->get_file_modified_time(i);
@@ -1118,7 +1115,6 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) {
FileInfo *finfo = &(E);
String fname = finfo->name;
String fpath = finfo->path;
- String ftype = finfo->type;
Ref<Texture2D> type_icon;
Ref<Texture2D> big_icon;
@@ -1126,11 +1122,10 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) {
String tooltip = fpath;
// Select the icons.
+ type_icon = _get_tree_item_icon(!finfo->import_broken, finfo->type, finfo->icon_path);
if (!finfo->import_broken) {
- type_icon = (has_theme_icon(ftype, EditorStringName(EditorIcons))) ? get_editor_theme_icon(ftype) : get_editor_theme_icon(SNAME("Object"));
big_icon = file_thumbnail;
} else {
- type_icon = get_editor_theme_icon(SNAME("ImportFail"));
big_icon = file_thumbnail_broken;
tooltip += "\n" + TTR("Status: Import of file failed. Please fix file and reimport manually.");
}
@@ -1566,10 +1561,42 @@ void FileSystemDock::_try_duplicate_item(const FileOrFolder &p_item, const Strin
}
void FileSystemDock::_update_resource_paths_after_move(const HashMap<String, String> &p_renames, const HashMap<String, ResourceUID::ID> &p_uids) const {
- // Update the paths in ResourceUID, so that UIDs remain valid.
- for (const KeyValue<String, ResourceUID::ID> &pair : p_uids) {
- if (p_renames.has(pair.key)) {
- ResourceUID::get_singleton()->set_id(pair.value, p_renames[pair.key]);
+ for (const KeyValue<String, String> &pair : p_renames) {
+ // Update UID path.
+ const String &old_path = pair.key;
+ const String &new_path = pair.value;
+
+ const HashMap<String, ResourceUID::ID>::ConstIterator I = p_uids.find(old_path);
+ if (I) {
+ ResourceUID::get_singleton()->set_id(I->value, new_path);
+ }
+
+ ScriptServer::remove_global_class_by_path(old_path);
+
+ int index = -1;
+ EditorFileSystemDirectory *efd = EditorFileSystem::get_singleton()->find_file(old_path, &index);
+
+ if (!efd || index < 0) {
+ // The file was removed.
+ continue;
+ }
+
+ // Update paths for global classes.
+ if (!efd->get_file_script_class_name(index).is_empty()) {
+ String lang;
+ for (int i = 0; i < ScriptServer::get_language_count(); i++) {
+ if (ScriptServer::get_language(i)->handles_global_class_type(efd->get_file_type(index))) {
+ lang = ScriptServer::get_language(i)->get_name();
+ break;
+ }
+ }
+ if (lang.is_empty()) {
+ continue; // No language found that can handle this global class.
+ }
+
+ ScriptServer::add_global_class(efd->get_file_script_class_name(index), efd->get_file_script_class_extends(index), lang, new_path);
+ EditorNode::get_editor_data().script_class_set_icon_path(efd->get_file_script_class_name(index), efd->get_file_script_class_icon_path(index));
+ EditorNode::get_editor_data().script_class_set_name(new_path, efd->get_file_script_class_name(index));
}
}
@@ -1588,10 +1615,13 @@ void FileSystemDock::_update_resource_paths_after_move(const HashMap<String, Str
if (p_renames.has(base_path)) {
base_path = p_renames[base_path];
+ r->set_path(base_path + extra_path);
}
-
- r->set_path(base_path + extra_path);
}
+
+ ScriptServer::save_global_classes();
+ EditorNode::get_editor_data().script_class_save_icon_paths();
+ EditorFileSystem::get_singleton()->emit_signal(SNAME("script_classes_updated"));
}
void FileSystemDock::_update_dependencies_after_move(const HashMap<String, String> &p_renames, const HashSet<String> &p_file_owners) const {
@@ -1715,6 +1745,13 @@ void FileSystemDock::_make_scene_confirm() {
}
void FileSystemDock::_resource_removed(const Ref<Resource> &p_resource) {
+ const Ref<Script> &scr = p_resource;
+ if (scr.is_valid()) {
+ ScriptServer::remove_global_class_by_path(scr->get_path());
+ ScriptServer::save_global_classes();
+ EditorNode::get_editor_data().script_class_save_icon_paths();
+ EditorFileSystem::get_singleton()->emit_signal(SNAME("script_classes_updated"));
+ }
emit_signal(SNAME("resource_removed"), p_resource);
}
@@ -2043,7 +2080,7 @@ Vector<String> FileSystemDock::_tree_get_selected(bool remove_self_inclusion, bo
Vector<String> FileSystemDock::_remove_self_included_paths(Vector<String> selected_strings) {
// Remove paths or files that are included into another.
if (selected_strings.size() > 1) {
- selected_strings.sort_custom<NaturalNoCaseComparator>();
+ selected_strings.sort_custom<FileNoCaseComparator>();
String last_path = "";
for (int i = 0; i < selected_strings.size(); i++) {
if (!last_path.is_empty() && selected_strings[i].begins_with(last_path)) {
@@ -2762,7 +2799,7 @@ bool FileSystemDock::can_drop_data_fw(const Point2 &p_point, const Variant &p_da
String to_dir;
bool favorite;
_get_drag_target_folder(to_dir, favorite, p_point, p_from);
- return !to_dir.is_empty();
+ return !favorite;
}
if (drag_data.has("type") && (String(drag_data["type"]) == "files" || String(drag_data["type"]) == "files_and_dirs")) {
@@ -2877,7 +2914,12 @@ void FileSystemDock::drop_data_fw(const Point2 &p_point, const Variant &p_data,
Ref<Resource> res = drag_data["resource"];
String to_dir;
bool favorite;
+ tree->set_drop_mode_flags(Tree::DROP_MODE_ON_ITEM);
_get_drag_target_folder(to_dir, favorite, p_point, p_from);
+ if (to_dir.is_empty()) {
+ to_dir = get_current_directory();
+ }
+
if (res.is_valid() && !to_dir.is_empty()) {
EditorNode::get_singleton()->push_item(res.ptr());
EditorNode::get_singleton()->save_resource_as(res, to_dir);
@@ -2923,7 +2965,11 @@ void FileSystemDock::drop_data_fw(const Point2 &p_point, const Variant &p_data,
if (drag_data.has("type") && String(drag_data["type"]) == "nodes") {
String to_dir;
bool favorite;
+ tree->set_drop_mode_flags(Tree::DROP_MODE_ON_ITEM);
_get_drag_target_folder(to_dir, favorite, p_point, p_from);
+ if (to_dir.is_empty()) {
+ to_dir = get_current_directory();
+ }
SceneTreeDock::get_singleton()->save_branch_to_file(to_dir);
}
}
@@ -2936,6 +2982,7 @@ void FileSystemDock::_get_drag_target_folder(String &target, bool &target_favori
if (p_from == files) {
int pos = files->get_item_at_position(p_point, true);
if (pos == -1) {
+ target = get_current_directory();
return;
}
@@ -3325,6 +3372,7 @@ void FileSystemDock::_file_list_empty_clicked(const Vector2 &p_pos, MouseButton
file_list_popup->add_icon_item(get_editor_theme_icon(SNAME("TextFile")), TTR("New TextFile..."), FILE_NEW_TEXTFILE);
file_list_popup->add_separator();
file_list_popup->add_icon_shortcut(get_editor_theme_icon(SNAME("Filesystem")), ED_GET_SHORTCUT("filesystem_dock/show_in_explorer"), FILE_SHOW_IN_EXPLORER);
+ file_list_popup->add_icon_shortcut(get_editor_theme_icon(SNAME("Terminal")), ED_GET_SHORTCUT("filesystem_dock/open_in_terminal"), FILE_OPEN_IN_TERMINAL);
file_list_popup->set_position(files->get_screen_position() + p_pos);
file_list_popup->reset_size();
@@ -3458,37 +3506,41 @@ void FileSystemDock::_tree_gui_input(Ref<InputEvent> p_event) {
void FileSystemDock::_file_list_gui_input(Ref<InputEvent> p_event) {
Ref<InputEventMouseMotion> mm = p_event;
if (mm.is_valid() && holding_branch) {
- const int item_idx = files->get_item_at_position(mm->get_position());
+ const int item_idx = files->get_item_at_position(mm->get_position(), true);
+ files->deselect_all();
+ String fpath;
if (item_idx != -1) {
- files->deselect_all();
- String fpath = files->get_item_metadata(item_idx);
+ fpath = files->get_item_metadata(item_idx);
if (fpath.ends_with("/") || fpath == "res://") {
files->select(item_idx);
}
+ } else {
+ fpath = get_current_directory();
+ }
- TreeItem *deselect_item = tree->get_next_selected(tree->get_root());
- while (deselect_item) {
- deselect_item->deselect(0);
- deselect_item = tree->get_next_selected(deselect_item);
+ TreeItem *deselect_item = tree->get_next_selected(tree->get_root());
+ while (deselect_item) {
+ deselect_item->deselect(0);
+ deselect_item = tree->get_next_selected(deselect_item);
+ }
+
+ // Try to select the corresponding tree item.
+ TreeItem *tree_item = (item_idx != -1) ? tree->get_item_with_text(files->get_item_text(item_idx)) : nullptr;
+
+ if (tree_item) {
+ tree_item->select(0);
+ } else {
+ // Find parent folder.
+ fpath = fpath.substr(0, fpath.rfind("/") + 1);
+ if (fpath.size() > String("res://").size()) {
+ fpath = fpath.left(fpath.size() - 2); // Remove last '/'.
+ const int slash_idx = fpath.rfind("/");
+ fpath = fpath.substr(slash_idx + 1, fpath.size() - slash_idx - 1);
}
- // Try to select the corresponding tree item.
- TreeItem *tree_item = tree->get_item_with_text(files->get_item_text(item_idx));
+ tree_item = tree->get_item_with_text(fpath);
if (tree_item) {
tree_item->select(0);
- } else {
- // Find parent folder.
- fpath = fpath.substr(0, fpath.rfind("/") + 1);
- if (fpath.size() > String("res://").size()) {
- fpath = fpath.left(fpath.size() - 2); // Remove last '/'.
- const int slash_idx = fpath.rfind("/");
- fpath = fpath.substr(slash_idx + 1, fpath.size() - slash_idx - 1);
- }
-
- tree_item = tree->get_item_with_text(fpath);
- if (tree_item) {
- tree_item->select(0);
- }
}
}
}
@@ -3905,7 +3957,9 @@ FileSystemDock::FileSystemDock() {
add_child(split_box);
tree = memnew(FileSystemTree);
+ tree->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
+ tree->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
tree->set_hide_root(true);
SET_DRAG_FORWARDING_GCD(tree, FileSystemDock);
tree->set_allow_rmb_select(true);