From 80e3cf3ef7e7934205fba2c7ad8e3310178d322b Mon Sep 17 00:00:00 2001 From: Karol Kosek Date: Tue, 27 Jul 2021 13:52:28 +0200 Subject: [PATCH] LibGUI: Show an error message on open error in the FilePicker --- Userland/Libraries/LibGUI/FilePicker.cpp | 9 +++++++++ Userland/Libraries/LibGUI/FilePicker.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/Userland/Libraries/LibGUI/FilePicker.cpp b/Userland/Libraries/LibGUI/FilePicker.cpp index daaf2df9b1..f3e97cdbe3 100644 --- a/Userland/Libraries/LibGUI/FilePicker.cpp +++ b/Userland/Libraries/LibGUI/FilePicker.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -104,6 +105,9 @@ FilePicker::FilePicker(Window* parent_window, Mode mode, const StringView& filen m_model->register_client(*this); + m_error_label = m_view->add(); + m_error_label->set_font(m_error_label->font().bold_variant()); + m_location_textbox->on_return_pressed = [this] { set_path(m_location_textbox->text()); }; @@ -212,7 +216,12 @@ FilePicker::FilePicker(Window* parent_window, Mode mode, const StringView& filen auto& common_locations_frame = *widget.find_descendant_of_type_named("common_locations_frame"); common_locations_frame.set_background_role(Gfx::ColorRole::Tray); + m_model->on_directory_change_error = [&](int, char const* error_string) { + m_error_label->set_text(String::formatted("Could not open {}:\n{}", m_model->root_path(), error_string)); + m_view->set_active_widget(m_error_label); + }; m_model->on_complete = [&] { + m_view->set_active_widget(&m_view->current_view()); for (auto location_button : m_common_location_buttons) location_button.button.set_checked(m_model->root_path() == location_button.path); }; diff --git a/Userland/Libraries/LibGUI/FilePicker.h b/Userland/Libraries/LibGUI/FilePicker.h index 216a97dfb1..44858dfcda 100644 --- a/Userland/Libraries/LibGUI/FilePicker.h +++ b/Userland/Libraries/LibGUI/FilePicker.h @@ -68,6 +68,8 @@ private: NonnullRefPtr m_model; String m_selected_file; + RefPtr m_error_label; + RefPtr m_filename_textbox; RefPtr m_location_textbox; Vector m_common_location_buttons;