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.
This commit is contained in:
parent
f4e3701893
commit
6105dfdac9
|
@ -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<String> dirs;
|
||||
|
|
|
@ -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!
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -199,7 +199,10 @@ Vector<String> 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"));
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -135,7 +135,8 @@ Vector<String> 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");
|
||||
|
|
|
@ -76,6 +76,8 @@ private:
|
|||
VBoxContainer *vbox;
|
||||
Mode mode;
|
||||
LineEdit *dir;
|
||||
HBoxContainer *drives_container;
|
||||
HBoxContainer *shortcuts_container;
|
||||
OptionButton *drives;
|
||||
Tree *tree;
|
||||
HBoxContainer *file_box;
|
||||
|
|
Loading…
Reference in New Issue