From 6105dfdac952f11b429f7a9ba96ccb6f0e3efaf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20J=2E=20Est=C3=A9banez?= Date: Fri, 6 Mar 2020 12:12:02 +0100 Subject: [PATCH] Improve UX of drive letters Namely, move the drive dropdown to just the left of the path text box and don't include the former in the latter. This improves the UX on Windows. In the UNIX case, since its concept of drives is (ab)used to provide shortcuts to useful paths, its dropdown is kept at the original location. --- core/os/dir_access.cpp | 10 ++++++++++ core/os/dir_access.h | 2 ++ drivers/unix/dir_access_unix.cpp | 5 +++++ drivers/unix/dir_access_unix.h | 1 + drivers/windows/dir_access_windows.cpp | 7 +++++++ drivers/windows/dir_access_windows.h | 1 + editor/editor_file_dialog.cpp | 26 ++++++++++++++++++++------ editor/editor_file_dialog.h | 2 ++ scene/gui/file_dialog.cpp | 19 ++++++++++++++++--- scene/gui/file_dialog.h | 2 ++ 10 files changed, 66 insertions(+), 9 deletions(-) diff --git a/core/os/dir_access.cpp b/core/os/dir_access.cpp index 0477db82be0..c1a23d2029f 100644 --- a/core/os/dir_access.cpp +++ b/core/os/dir_access.cpp @@ -66,6 +66,16 @@ int DirAccess::get_current_drive() { return 0; } +bool DirAccess::drives_are_shortcuts() { + + return false; +} + +String DirAccess::get_current_dir_without_drive() { + + return get_current_dir(); +} + static Error _erase_recursive(DirAccess *da) { List dirs; diff --git a/core/os/dir_access.h b/core/os/dir_access.h index 55a6d53f72f..59765bfb298 100644 --- a/core/os/dir_access.h +++ b/core/os/dir_access.h @@ -76,9 +76,11 @@ public: virtual int get_drive_count() = 0; virtual String get_drive(int p_drive) = 0; virtual int get_current_drive(); + virtual bool drives_are_shortcuts(); virtual Error change_dir(String p_dir) = 0; ///< can be relative or absolute, return false on success virtual String get_current_dir() = 0; ///< return current dir location + virtual String get_current_dir_without_drive(); virtual Error make_dir(String p_dir) = 0; virtual Error make_dir_recursive(String p_dir); virtual Error erase_contents_recursive(); //super dangerous, use with care! diff --git a/drivers/unix/dir_access_unix.cpp b/drivers/unix/dir_access_unix.cpp index 02cb4fa956c..66c76e9bec3 100644 --- a/drivers/unix/dir_access_unix.cpp +++ b/drivers/unix/dir_access_unix.cpp @@ -269,6 +269,11 @@ String DirAccessUnix::get_drive(int p_drive) { return list[p_drive]; } +bool DirAccessUnix::drives_are_shortcuts() { + + return true; +} + Error DirAccessUnix::make_dir(String p_dir) { GLOBAL_LOCK_FUNCTION diff --git a/drivers/unix/dir_access_unix.h b/drivers/unix/dir_access_unix.h index 32ddc766389..4237dd56912 100644 --- a/drivers/unix/dir_access_unix.h +++ b/drivers/unix/dir_access_unix.h @@ -63,6 +63,7 @@ public: virtual int get_drive_count(); virtual String get_drive(int p_drive); + virtual bool drives_are_shortcuts(); virtual Error change_dir(String p_dir); ///< can be relative or absolute, return false on success virtual String get_current_dir(); ///< return current dir location diff --git a/drivers/windows/dir_access_windows.cpp b/drivers/windows/dir_access_windows.cpp index 8e0eac6986b..5d1ab48106c 100644 --- a/drivers/windows/dir_access_windows.cpp +++ b/drivers/windows/dir_access_windows.cpp @@ -206,6 +206,13 @@ String DirAccessWindows::get_current_dir() { return current_dir; } +String DirAccessWindows::get_current_dir_without_drive() { + + String dir = get_current_dir(); + int p = current_dir.find(":"); + return p != -1 ? dir.right(p + 1) : dir; +} + bool DirAccessWindows::file_exists(String p_file) { GLOBAL_LOCK_FUNCTION diff --git a/drivers/windows/dir_access_windows.h b/drivers/windows/dir_access_windows.h index 43951c0be9a..69328489cfe 100644 --- a/drivers/windows/dir_access_windows.h +++ b/drivers/windows/dir_access_windows.h @@ -70,6 +70,7 @@ public: virtual Error change_dir(String p_dir); ///< can be relative or absolute, return false on success virtual String get_current_dir(); ///< return current dir location + virtual String get_current_dir_without_drive(); virtual bool file_exists(String p_file); virtual bool dir_exists(String p_dir); diff --git a/editor/editor_file_dialog.cpp b/editor/editor_file_dialog.cpp index 625f46f9d3c..b6ee8446830 100644 --- a/editor/editor_file_dialog.cpp +++ b/editor/editor_file_dialog.cpp @@ -199,7 +199,10 @@ Vector EditorFileDialog::get_selected_files() const { void EditorFileDialog::update_dir() { - dir->set_text(dir_access->get_current_dir()); + if (drives->is_visible()) { + drives->select(dir_access->get_current_drive()); + } + dir->set_text(dir_access->get_current_dir_without_drive()); // Disable "Open" button only when selecting file(s) mode. get_ok()->set_disabled(_is_open_should_be_disabled()); @@ -946,7 +949,7 @@ void EditorFileDialog::add_filter(const String &p_filter) { String EditorFileDialog::get_current_dir() const { - return dir->get_text(); + return dir_access->get_current_dir(); } String EditorFileDialog::get_current_file() const { @@ -954,7 +957,7 @@ String EditorFileDialog::get_current_file() const { } String EditorFileDialog::get_current_path() const { - return dir->get_text().plus_file(file->get_text()); + return dir_access->get_current_dir().plus_file(file->get_text()); } void EditorFileDialog::set_current_dir(const String &p_dir) { @@ -1149,6 +1152,12 @@ void EditorFileDialog::_update_drives() { drives->hide(); } else { drives->clear(); + Node *dp = drives->get_parent(); + if (dp) { + dp->remove_child(drives); + } + dp = dir_access->drives_are_shortcuts() ? shortcuts_container : drives_container; + dp->add_child(drives); drives->show(); for (int i = 0; i < dir_access->get_drive_count(); i++) { @@ -1543,6 +1552,12 @@ EditorFileDialog::EditorFileDialog() { pathhb->add_child(memnew(Label(TTR("Path:")))); + drives_container = memnew(HBoxContainer); + pathhb->add_child(drives_container); + + drives = memnew(OptionButton); + drives->connect("item_selected", this, "_select_drive"); + dir = memnew(LineEdit); pathhb->add_child(dir); dir->set_h_size_flags(SIZE_EXPAND_FILL); @@ -1586,9 +1601,8 @@ EditorFileDialog::EditorFileDialog() { mode_list->set_tooltip(TTR("View items as a list.")); pathhb->add_child(mode_list); - drives = memnew(OptionButton); - pathhb->add_child(drives); - drives->connect("item_selected", this, "_select_drive"); + shortcuts_container = memnew(HBoxContainer); + pathhb->add_child(shortcuts_container); makedir = memnew(Button); makedir->set_text(TTR("Create Folder")); diff --git a/editor/editor_file_dialog.h b/editor/editor_file_dialog.h index 6af261e8dd4..e7ee178b375 100644 --- a/editor/editor_file_dialog.h +++ b/editor/editor_file_dialog.h @@ -100,6 +100,8 @@ private: ToolButton *dir_next; ToolButton *dir_up; + HBoxContainer *drives_container; + HBoxContainer *shortcuts_container; OptionButton *drives; ItemList *item_list; PopupMenu *item_menu; diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index 2cc9c1a53a8..fc06f4bf3c4 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -135,7 +135,8 @@ Vector FileDialog::get_selected_files() const { void FileDialog::update_dir() { - dir->set_text(dir_access->get_current_dir()); + dir->set_text(dir_access->get_current_dir_without_drive()); + if (drives->is_visible()) { drives->select(dir_access->get_current_drive()); } @@ -789,6 +790,12 @@ void FileDialog::_update_drives() { drives->hide(); } else { drives->clear(); + Node *dp = drives->get_parent(); + if (dp) { + dp->remove_child(drives); + } + dp = dir_access->drives_are_shortcuts() ? shortcuts_container : drives_container; + dp->add_child(drives); drives->show(); for (int i = 0; i < dir_access->get_drive_count(); i++) { @@ -902,11 +909,14 @@ FileDialog::FileDialog() { hbc->add_child(dir_up); dir_up->connect("pressed", this, "_go_up"); + hbc->add_child(memnew(Label(RTR("Path:")))); + + drives_container = memnew(HBoxContainer); + hbc->add_child(drives_container); + drives = memnew(OptionButton); - hbc->add_child(drives); drives->connect("item_selected", this, "_select_drive"); - hbc->add_child(memnew(Label(RTR("Path:")))); dir = memnew(LineEdit); hbc->add_child(dir); dir->set_h_size_flags(SIZE_EXPAND_FILL); @@ -923,6 +933,9 @@ FileDialog::FileDialog() { show_hidden->connect("toggled", this, "set_show_hidden_files"); hbc->add_child(show_hidden); + shortcuts_container = memnew(HBoxContainer); + hbc->add_child(shortcuts_container); + makedir = memnew(Button); makedir->set_text(RTR("Create Folder")); makedir->connect("pressed", this, "_make_dir"); diff --git a/scene/gui/file_dialog.h b/scene/gui/file_dialog.h index d9ab00e0f2d..fdf26489f7b 100644 --- a/scene/gui/file_dialog.h +++ b/scene/gui/file_dialog.h @@ -76,6 +76,8 @@ private: VBoxContainer *vbox; Mode mode; LineEdit *dir; + HBoxContainer *drives_container; + HBoxContainer *shortcuts_container; OptionButton *drives; Tree *tree; HBoxContainer *file_box;