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

Improve UX of drive letters (3.2) #36639

Merged
merged 1 commit into from
Mar 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions core/os/dir_access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions core/os/dir_access.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ class DirAccess {
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!
Expand Down
5 changes: 5 additions & 0 deletions drivers/unix/dir_access_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions drivers/unix/dir_access_unix.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class DirAccessUnix : public DirAccess {

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
Expand Down
7 changes: 7 additions & 0 deletions drivers/windows/dir_access_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions drivers/windows/dir_access_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class DirAccessWindows : public DirAccess {

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);
Expand Down
26 changes: 20 additions & 6 deletions editor/editor_file_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -946,15 +949,15 @@ 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 {

return file->get_text();
}
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) {

Expand Down Expand Up @@ -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++) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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"));
Expand Down
2 changes: 2 additions & 0 deletions editor/editor_file_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ class EditorFileDialog : public ConfirmationDialog {
ToolButton *dir_next;
ToolButton *dir_up;

HBoxContainer *drives_container;
HBoxContainer *shortcuts_container;
OptionButton *drives;
ItemList *item_list;
PopupMenu *item_menu;
Expand Down
19 changes: 16 additions & 3 deletions scene/gui/file_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down Expand Up @@ -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++) {
Expand Down Expand Up @@ -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);
Expand All @@ -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");
Expand Down
2 changes: 2 additions & 0 deletions scene/gui/file_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class FileDialog : public ConfirmationDialog {
VBoxContainer *vbox;
Mode mode;
LineEdit *dir;
HBoxContainer *drives_container;
HBoxContainer *shortcuts_container;
OptionButton *drives;
Tree *tree;
HBoxContainer *file_box;
Expand Down