diff options
author | Adam Jakubek <ajakubek@gmail.com> | 2022-08-30 21:57:30 +0200 |
---|---|---|
committer | Sam Atkins <atkinssj@gmail.com> | 2022-08-31 10:32:41 +0100 |
commit | aa466723eb37315d0dc43af7e7078976499bea78 (patch) | |
tree | 1b120248b3399708095bec046b21b5ca1bdde6e6 /Userland | |
parent | f7e6593910ccc22babaf670607ffcd8b90f5bf37 (diff) | |
download | serenity-aa466723eb37315d0dc43af7e7078976499bea78.zip |
FileManager: Navigate to parent dir when current location is removed
When the location currently displayed in FileManager is removed, find
the nearest existing parent path and open it in the window.
Without the fix, the FileManager window remained in the deleted
directory.
Changing the path in 'DirectoryView' object will automatically update
other components in the FileManager (breadcrumb bar, directory tree
view).
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Applications/FileManager/DirectoryView.cpp | 13 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/FileSystemModel.cpp | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/FileSystemModel.h | 1 |
3 files changed, 15 insertions, 0 deletions
diff --git a/Userland/Applications/FileManager/DirectoryView.cpp b/Userland/Applications/FileManager/DirectoryView.cpp index 21ca93702e..0311dd5816 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 9872055acf..35e8432712 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 5d87f5c4f6..b35e1be454 100644 --- a/Userland/Libraries/LibGUI/FileSystemModel.h +++ b/Userland/Libraries/LibGUI/FileSystemModel.h @@ -120,6 +120,7 @@ public: Function<void(int error, char const* error_string)> on_directory_change_error; Function<void(int error, char const* error_string)> on_rename_error; Function<void(String const& old_name, String const& new_name)> on_rename_successful; + Function<void()> on_root_path_removed; virtual int tree_column() const override { return Column::Name; } virtual int row_count(ModelIndex const& = ModelIndex()) const override; |