You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-11 13:10:58 +00:00
Fix FileSystem navigation when using Split Mode
This commit is contained in:
@@ -705,88 +705,62 @@ void FileSystemDock::_set_current_path_line_edit_text(const String &p_path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FileSystemDock::_navigate_to_path(const String &p_path, bool p_select_in_favorites) {
|
void FileSystemDock::_navigate_to_path(const String &p_path, bool p_select_in_favorites) {
|
||||||
|
String target_path = p_path;
|
||||||
bool is_directory = false;
|
bool is_directory = false;
|
||||||
if (p_path == "Favorites") {
|
|
||||||
current_path = p_path;
|
if (p_path.is_empty()) {
|
||||||
} else {
|
target_path = "res://";
|
||||||
String target_path = p_path;
|
is_directory = true;
|
||||||
// If the path is a file, do not only go to the directory in the tree, also select the file in the file list.
|
} else if (p_path != "Favorites") {
|
||||||
if (target_path.ends_with("/")) {
|
|
||||||
target_path = target_path.trim_suffix("/");
|
|
||||||
}
|
|
||||||
Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
|
Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
|
||||||
if (da->file_exists(p_path)) {
|
if (da->dir_exists(p_path)) {
|
||||||
current_path = target_path;
|
|
||||||
} else if (da->dir_exists(p_path)) {
|
|
||||||
current_path = target_path + "/";
|
|
||||||
is_directory = true;
|
is_directory = true;
|
||||||
} else {
|
if (!p_path.ends_with("/")) {
|
||||||
|
target_path += "/";
|
||||||
|
}
|
||||||
|
} else if (!da->file_exists(p_path)) {
|
||||||
ERR_FAIL_MSG(vformat("Cannot navigate to '%s' as it has not been found in the file system!", p_path));
|
ERR_FAIL_MSG(vformat("Cannot navigate to '%s' as it has not been found in the file system!", p_path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
current_path = target_path;
|
||||||
_set_current_path_line_edit_text(current_path);
|
_set_current_path_line_edit_text(current_path);
|
||||||
_push_to_history();
|
_push_to_history();
|
||||||
|
|
||||||
const String file_name = is_directory ? p_path.trim_suffix("/").get_file() + "/" : p_path.get_file();
|
String base_dir_path = target_path.get_base_dir();
|
||||||
bool found = false;
|
if (base_dir_path != "res://") {
|
||||||
|
base_dir_path += "/";
|
||||||
TreeItem **base_dir_ptr;
|
|
||||||
{
|
|
||||||
const String base_dir = current_path.get_base_dir();
|
|
||||||
if (base_dir == "res://") {
|
|
||||||
base_dir_ptr = folder_map.getptr(base_dir);
|
|
||||||
} else if (is_directory) {
|
|
||||||
base_dir_ptr = folder_map.getptr(base_dir.get_base_dir() + "/");
|
|
||||||
} else {
|
|
||||||
base_dir_ptr = folder_map.getptr(base_dir + "/");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (base_dir_ptr) {
|
TreeItem **directory_ptr = folder_map.getptr(base_dir_path);
|
||||||
TreeItem *directory = *base_dir_ptr;
|
if (!directory_ptr) {
|
||||||
{
|
|
||||||
TreeItem *entry = directory->get_first_child();
|
|
||||||
while (entry) {
|
|
||||||
if (entry->get_metadata(0).operator String().ends_with(file_name)) {
|
|
||||||
tree->deselect_all();
|
|
||||||
entry->select(0);
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
entry = entry->get_next();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
while (directory) {
|
|
||||||
directory->set_collapsed(false);
|
|
||||||
directory = directory->get_parent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!found) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
tree->ensure_cursor_is_visible();
|
// Unfold all folders along the path.
|
||||||
if (display_mode != DISPLAY_MODE_TREE_ONLY) {
|
TreeItem *ti = *directory_ptr;
|
||||||
_update_file_list(false);
|
while (ti) {
|
||||||
|
ti->set_collapsed(false);
|
||||||
// Reset the scroll for a directory.
|
ti = ti->get_parent();
|
||||||
if (is_directory) {
|
|
||||||
files->get_v_scroll_bar()->set_value(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!file_name.is_empty()) {
|
// Select the file or directory in the tree.
|
||||||
for (int i = 0; i < files->get_item_count(); i++) {
|
tree->deselect_all();
|
||||||
if (files->get_item_text(i) == file_name) {
|
if (display_mode == DISPLAY_MODE_TREE_ONLY) {
|
||||||
files->select(i, true);
|
const String file_name = is_directory ? target_path.trim_suffix("/").get_file() + "/" : target_path.get_file();
|
||||||
files->ensure_current_is_visible();
|
TreeItem *item = is_directory ? *directory_ptr : (*directory_ptr)->get_first_child();
|
||||||
|
while (item) {
|
||||||
|
if (item->get_metadata(0).operator String().ends_with(file_name)) {
|
||||||
|
item->select(0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
item = item->get_next();
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
(*directory_ptr)->select(0);
|
||||||
|
_update_file_list(false);
|
||||||
}
|
}
|
||||||
|
tree->ensure_cursor_is_visible();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileSystemDock::_update_filtered_items(TreeItem *p_tree_item) {
|
bool FileSystemDock::_update_filtered_items(TreeItem *p_tree_item) {
|
||||||
|
|||||||
Reference in New Issue
Block a user