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

Fixed "Open" button being enabled when nothing is selected in a FileDialog while in "Open folder" mode #16710

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions scene/gui/file_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ void FileDialog::_action_pressed() {
bool valid = false;

if (filter->get_selected() == filter->get_item_count() - 1) {
valid = true; //match none
valid = true; // match none
} else if (filters.size() > 1 && filter->get_selected() == 0) {
// match all filters
for (int i = 0; i < filters.size(); i++) {
Expand Down Expand Up @@ -287,7 +287,7 @@ bool FileDialog::_is_open_should_be_disabled() {
TreeItem *ti = tree->get_selected();
// We have something that we can't select?
if (!ti)
return true;
return mode != MODE_OPEN_DIR; // In "Open folder" mode, having nothing selected picks the current folder.

Dictionary d = ti->get_metadata(0);

Expand Down Expand Up @@ -320,16 +320,14 @@ void FileDialog::deselect_items() {
case MODE_OPEN_FILE:
case MODE_OPEN_FILES:
get_ok()->set_text(TTR("Open"));
get_ok()->set_disabled(false);
break;

case MODE_OPEN_DIR:
get_ok()->set_text(TTR("Select Current Folder"));
get_ok()->set_disabled(false);
break;
}
}
}

void FileDialog::_tree_selected() {

TreeItem *ti = tree->get_selected();
Expand All @@ -347,7 +345,7 @@ void FileDialog::_tree_selected() {
get_ok()->set_disabled(_is_open_should_be_disabled());
}

void FileDialog::_tree_dc_selected() {
void FileDialog::_tree_item_activated() {

TreeItem *ti = tree->get_selected();
if (!ti)
Expand Down Expand Up @@ -756,7 +754,7 @@ void FileDialog::_bind_methods() {
ClassDB::bind_method(D_METHOD("_unhandled_input"), &FileDialog::_unhandled_input);

ClassDB::bind_method(D_METHOD("_tree_selected"), &FileDialog::_tree_selected);
ClassDB::bind_method(D_METHOD("_tree_db_selected"), &FileDialog::_tree_dc_selected);
ClassDB::bind_method(D_METHOD("_tree_item_activated"), &FileDialog::_tree_item_activated);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually my bad, the original name needs to be kept for the binding to avoid breaking compatibility (but the C++ name can still be changed). Will add this one to #16863.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that it starts with an underscore, I think this is not a problem.

This won't be listed in documentation or autocompleted in GDScript. If anyone uses underscore-starting methods, they should be prepared to fix their messy hacks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. :)

ClassDB::bind_method(D_METHOD("_dir_entered"), &FileDialog::_dir_entered);
ClassDB::bind_method(D_METHOD("_file_entered"), &FileDialog::_file_entered);
ClassDB::bind_method(D_METHOD("_action_pressed"), &FileDialog::_action_pressed);
Expand Down Expand Up @@ -881,7 +879,7 @@ FileDialog::FileDialog() {
filter = memnew(OptionButton);
filter->set_stretch_ratio(3);
filter->set_h_size_flags(SIZE_EXPAND_FILL);
filter->set_clip_text(true); //too many extensions overflow it
filter->set_clip_text(true); // too many extensions overflows it
hbc->add_child(filter);
vbc->add_child(hbc);

Expand All @@ -890,9 +888,8 @@ FileDialog::FileDialog() {
_update_drives();

connect("confirmed", this, "_action_pressed");
//cancel->connect("pressed", this,"_cancel_pressed");
tree->connect("cell_selected", this, "_tree_selected", varray(), CONNECT_DEFERRED);
tree->connect("item_activated", this, "_tree_db_selected", varray());
tree->connect("item_activated", this, "_tree_item_activated", varray());
tree->connect("nothing_selected", this, "deselect_items");
dir->connect("text_entered", this, "_dir_entered");
file->connect("text_entered", this, "_file_entered");
Expand Down Expand Up @@ -922,7 +919,6 @@ FileDialog::FileDialog() {
exterr->set_text(RTR("Must use a valid extension."));
add_child(exterr);

//update_file_list();
update_filters();
update_dir();

Expand Down
2 changes: 1 addition & 1 deletion scene/gui/file_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class FileDialog : public ConfirmationDialog {
void _tree_selected();

void _select_drive(int p_idx);
void _tree_dc_selected();
void _tree_item_activated();
void _dir_entered(String p_dir);
void _file_entered(const String &p_file);
void _action_pressed();
Expand Down