diff options
author | John Diamond <john@kry.se> | 2021-09-08 22:16:48 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-09 02:32:29 +0200 |
commit | c1063e3219eb5fb345ef1622607aacf8836bab96 (patch) | |
tree | a13fe3ccacd509d4b9e484812d7388395011320c /Userland | |
parent | 882c7b12959788b9ac40bf5641a7b50d0844a428 (diff) | |
download | serenity-c1063e3219eb5fb345ef1622607aacf8836bab96.zip |
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.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibGUI/FilePicker.cpp | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/Userland/Libraries/LibGUI/FilePicker.cpp b/Userland/Libraries/LibGUI/FilePicker.cpp index 8b696e1954..380b207a4e 100644 --- a/Userland/Libraries/LibGUI/FilePicker.cpp +++ b/Userland/Libraries/LibGUI/FilePicker.cpp @@ -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); |