mirror of
https://github.com/RGBCube/serenity
synced 2025-05-25 21:05:07 +00:00
FileManager: Show an inline error message for inaccessible directories
Instead of popping up a message box whenever we can't read an opened directory, show the error message inside the DirectoryView (as a label) instead. This fixes a visual inconsistency where an inaccessible directory would be selected in the left-side treeview while the previous directory's contents were still showing on the right. This also makes keyboard navigation a bit more pleasant since you're not suddenly interrupted by a message box.
This commit is contained in:
parent
9b89303767
commit
8075db683b
3 changed files with 16 additions and 12 deletions
|
@ -32,6 +32,7 @@
|
||||||
#include <LibCore/MimeData.h>
|
#include <LibCore/MimeData.h>
|
||||||
#include <LibCore/StandardPaths.h>
|
#include <LibCore/StandardPaths.h>
|
||||||
#include <LibGUI/InputBox.h>
|
#include <LibGUI/InputBox.h>
|
||||||
|
#include <LibGUI/Label.h>
|
||||||
#include <LibGUI/MessageBox.h>
|
#include <LibGUI/MessageBox.h>
|
||||||
#include <LibGUI/SortingProxyModel.h>
|
#include <LibGUI/SortingProxyModel.h>
|
||||||
#include <serenity.h>
|
#include <serenity.h>
|
||||||
|
@ -135,6 +136,9 @@ DirectoryView::DirectoryView(Mode mode)
|
||||||
|
|
||||||
setup_actions();
|
setup_actions();
|
||||||
|
|
||||||
|
m_error_label = add<GUI::Label>();
|
||||||
|
m_error_label->set_font(m_error_label->font().bold_family_font());
|
||||||
|
|
||||||
setup_model();
|
setup_model();
|
||||||
|
|
||||||
setup_icon_view();
|
setup_icon_view();
|
||||||
|
@ -155,15 +159,20 @@ void DirectoryView::setup_model()
|
||||||
{
|
{
|
||||||
m_model->set_root_path(Core::StandardPaths::desktop_directory());
|
m_model->set_root_path(Core::StandardPaths::desktop_directory());
|
||||||
|
|
||||||
m_model->on_error = [this](int error, const char* error_string) {
|
m_model->on_error = [this](int, const char* error_string) {
|
||||||
|
auto failed_path = m_model->root_path();
|
||||||
bool quit = false;
|
bool quit = false;
|
||||||
if (m_path_history.size())
|
if (m_path_history.size())
|
||||||
open(m_path_history.at(m_path_history_position));
|
open(m_path_history.at(m_path_history_position));
|
||||||
else
|
else
|
||||||
quit = true;
|
quit = true;
|
||||||
|
|
||||||
if (on_error)
|
if (quit)
|
||||||
on_error(error, error_string, quit);
|
exit(1);
|
||||||
|
|
||||||
|
auto error_message = String::format("Could not read %s:\n%s", failed_path.characters(), error_string);
|
||||||
|
m_error_label->set_text(error_message);
|
||||||
|
set_active_widget(m_error_label);
|
||||||
};
|
};
|
||||||
|
|
||||||
m_model->on_complete = [this] {
|
m_model->on_complete = [this] {
|
||||||
|
@ -321,6 +330,8 @@ void DirectoryView::open(const StringView& path)
|
||||||
model().update();
|
model().update();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set_active_widget(¤t_view());
|
||||||
model().set_root_path(path);
|
model().set_root_path(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -86,7 +86,6 @@ public:
|
||||||
Function<void(const GUI::ModelIndex&, const GUI::ContextMenuEvent&)> on_context_menu_request;
|
Function<void(const GUI::ModelIndex&, const GUI::ContextMenuEvent&)> on_context_menu_request;
|
||||||
Function<void(const StringView&)> on_status_message;
|
Function<void(const StringView&)> on_status_message;
|
||||||
Function<void(int done, int total)> on_thumbnail_progress;
|
Function<void(int done, int total)> on_thumbnail_progress;
|
||||||
Function<void(int error, const char* error_string, bool quit)> on_error;
|
|
||||||
|
|
||||||
enum ViewMode {
|
enum ViewMode {
|
||||||
Invalid,
|
Invalid,
|
||||||
|
@ -174,6 +173,8 @@ private:
|
||||||
Vector<String> m_path_history;
|
Vector<String> m_path_history;
|
||||||
void add_path_to_history(const StringView& path);
|
void add_path_to_history(const StringView& path);
|
||||||
|
|
||||||
|
RefPtr<GUI::Label> m_error_label;
|
||||||
|
|
||||||
RefPtr<GUI::TableView> m_table_view;
|
RefPtr<GUI::TableView> m_table_view;
|
||||||
RefPtr<GUI::IconView> m_icon_view;
|
RefPtr<GUI::IconView> m_icon_view;
|
||||||
RefPtr<GUI::ColumnsView> m_columns_view;
|
RefPtr<GUI::ColumnsView> m_columns_view;
|
||||||
|
|
|
@ -540,14 +540,6 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
|
||||||
open_parent_directory_action->set_enabled(new_path != "/");
|
open_parent_directory_action->set_enabled(new_path != "/");
|
||||||
};
|
};
|
||||||
|
|
||||||
directory_view.on_error = [&](int, const char* error_string, bool quit) {
|
|
||||||
auto error_message = String::format("Could not read directory: %s", error_string);
|
|
||||||
GUI::MessageBox::show(window, error_message, "File Manager", GUI::MessageBox::Type::Error);
|
|
||||||
|
|
||||||
if (quit)
|
|
||||||
exit(1);
|
|
||||||
};
|
|
||||||
|
|
||||||
directory_view.on_status_message = [&](const StringView& message) {
|
directory_view.on_status_message = [&](const StringView& message) {
|
||||||
statusbar.set_text(message);
|
statusbar.set_text(message);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue