mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:07:35 +00:00
LibGUI: Disable Open/Save button in FilePicker when nothing is selected
The existing behaviour is that filename_textbox is cleared if a node of the wrong type is selected. Here we reflect that state update in the state of the ok_button. This change helps the user to avoid confirming (and seeing an alert) if they press "Open" after clicking on an invalid node.
This commit is contained in:
parent
882c7b1295
commit
c1063e3219
1 changed files with 16 additions and 15 deletions
|
@ -160,21 +160,6 @@ FilePicker::FilePicker(Window* parent_window, Mode mode, const StringView& filen
|
|||
on_file_return();
|
||||
};
|
||||
|
||||
m_view->on_selection_change = [this] {
|
||||
auto index = m_view->selection().first();
|
||||
auto& filter_model = (SortingProxyModel&)*m_view->model();
|
||||
auto local_index = filter_model.map_to_source(index);
|
||||
const FileSystemModel::Node& node = m_model->node(local_index);
|
||||
LexicalPath path { node.full_path() };
|
||||
|
||||
auto should_open_folder = m_mode == Mode::OpenFolder;
|
||||
if (should_open_folder == node.is_directory()) {
|
||||
m_filename_textbox->set_text(node.name);
|
||||
} else if (m_mode != Mode::Save) {
|
||||
m_filename_textbox->clear();
|
||||
}
|
||||
};
|
||||
|
||||
m_context_menu = GUI::Menu::construct();
|
||||
m_context_menu->add_action(GUI::Action::create_checkable(
|
||||
"Show dotfiles", { Mod_Ctrl, Key_H }, [&](auto& action) {
|
||||
|
@ -194,6 +179,7 @@ FilePicker::FilePicker(Window* parent_window, Mode mode, const StringView& filen
|
|||
ok_button.on_click = [this](auto) {
|
||||
on_file_return();
|
||||
};
|
||||
ok_button.set_enabled(!m_filename_textbox->text().is_empty());
|
||||
|
||||
auto& cancel_button = *widget.find_descendant_of_type_named<GUI::Button>("cancel_button");
|
||||
cancel_button.set_text("Cancel");
|
||||
|
@ -201,6 +187,21 @@ FilePicker::FilePicker(Window* parent_window, Mode mode, const StringView& filen
|
|||
done(ExecCancel);
|
||||
};
|
||||
|
||||
m_view->on_selection_change = [this, &ok_button] {
|
||||
auto index = m_view->selection().first();
|
||||
auto& filter_model = (SortingProxyModel&)*m_view->model();
|
||||
auto local_index = filter_model.map_to_source(index);
|
||||
const FileSystemModel::Node& node = m_model->node(local_index);
|
||||
|
||||
auto should_open_folder = m_mode == Mode::OpenFolder;
|
||||
if (should_open_folder == node.is_directory()) {
|
||||
m_filename_textbox->set_text(node.name);
|
||||
} else if (m_mode != Mode::Save) {
|
||||
m_filename_textbox->clear();
|
||||
}
|
||||
ok_button.set_enabled(!m_filename_textbox->text().is_empty());
|
||||
};
|
||||
|
||||
m_view->on_activation = [this](auto& index) {
|
||||
auto& filter_model = (SortingProxyModel&)*m_view->model();
|
||||
auto local_index = filter_model.map_to_source(index);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue