diff --git a/Userland/Applications/FileManager/DirectoryView.cpp b/Userland/Applications/FileManager/DirectoryView.cpp index 21ca93702e2..0311dd58168 100644 --- a/Userland/Applications/FileManager/DirectoryView.cpp +++ b/Userland/Applications/FileManager/DirectoryView.cpp @@ -196,6 +196,19 @@ void DirectoryView::setup_model() on_path_change(model().root_path(), true, can_write_in_path); }; + m_model->on_root_path_removed = [this] { + // Change model root to the first existing parent directory. + LexicalPath model_root(model().root_path()); + + while (model_root.string() != "/") { + model_root = model_root.parent(); + if (Core::File::is_directory(model_root.string())) + break; + } + + open(model_root.string()); + }; + m_model->register_client(*this); m_model->on_thumbnail_progress = [this](int done, int total) { diff --git a/Userland/Libraries/LibGUI/FileSystemModel.cpp b/Userland/Libraries/LibGUI/FileSystemModel.cpp index 9872055acf8..35e8432712d 100644 --- a/Userland/Libraries/LibGUI/FileSystemModel.cpp +++ b/Userland/Libraries/LibGUI/FileSystemModel.cpp @@ -421,6 +421,7 @@ void FileSystemModel::handle_file_event(Core::FileWatcherEvent const& event) if (&child.value() == m_root) { // Root directory of the filesystem model has been removed. All items became invalid. invalidate(); + on_root_path_removed(); break; } diff --git a/Userland/Libraries/LibGUI/FileSystemModel.h b/Userland/Libraries/LibGUI/FileSystemModel.h index 5d87f5c4f63..b35e1be4542 100644 --- a/Userland/Libraries/LibGUI/FileSystemModel.h +++ b/Userland/Libraries/LibGUI/FileSystemModel.h @@ -120,6 +120,7 @@ public: Function on_directory_change_error; Function on_rename_error; Function on_rename_successful; + Function on_root_path_removed; virtual int tree_column() const override { return Column::Name; } virtual int row_count(ModelIndex const& = ModelIndex()) const override;