diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-03-30 02:22:38 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-03-30 02:22:38 +0100 |
commit | f10e0d054612eef415ce96a0e2383910d39668c0 (patch) | |
tree | c7abc33c39c98287c55c6281d57d8bbaa405e850 | |
parent | be42382a3a1c10585d272394557caed170ae0093 (diff) | |
download | serenity-f10e0d054612eef415ce96a0e2383910d39668c0.zip |
FileManager: Make the directory view follow the tree view selection.
-rw-r--r-- | Applications/FileManager/main.cpp | 7 | ||||
-rw-r--r-- | LibGUI/GFileSystemModel.cpp | 9 | ||||
-rw-r--r-- | LibGUI/GFileSystemModel.h | 1 |
3 files changed, 16 insertions, 1 deletions
diff --git a/Applications/FileManager/main.cpp b/Applications/FileManager/main.cpp index 3d5feec079..708a6c9aec 100644 --- a/Applications/FileManager/main.cpp +++ b/Applications/FileManager/main.cpp @@ -54,7 +54,8 @@ int main(int argc, char** argv) auto* splitter = new GWidget(widget); splitter->set_layout(make<GBoxLayout>(Orientation::Horizontal)); auto* tree_view = new GTreeView(splitter); - tree_view->set_model(GFileSystemModel::create("/", GFileSystemModel::Mode::DirectoriesOnly)); + auto file_system_model = GFileSystemModel::create("/", GFileSystemModel::Mode::DirectoriesOnly); + tree_view->set_model(file_system_model.copy_ref()); tree_view->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill); tree_view->set_preferred_size({ 200, 0 }); auto* directory_view = new DirectoryView(splitter); @@ -70,6 +71,10 @@ int main(int argc, char** argv) directory_view->open(editor.text()); }; + file_system_model->on_selection_changed = [&] (auto& index) { + directory_view->open(file_system_model->path(index)); + }; + auto open_parent_directory_action = GAction::create("Open parent directory", { Mod_Alt, Key_Up }, GraphicsBitmap::load_from_file("/res/icons/16x16/open-parent-directory.png"), [directory_view] (const GAction&) { directory_view->open_parent_directory(); }); diff --git a/LibGUI/GFileSystemModel.cpp b/LibGUI/GFileSystemModel.cpp index 2bed9f2090..b13b863838 100644 --- a/LibGUI/GFileSystemModel.cpp +++ b/LibGUI/GFileSystemModel.cpp @@ -92,6 +92,15 @@ struct GFileSystemModel::Node { } }; +String GFileSystemModel::path(const GModelIndex& index) const +{ + if (!index.is_valid()) + return { }; + auto& node = *(Node*)index.internal_data(); + node.reify_if_needed(*this); + return node.full_path(*this); +} + GFileSystemModel::GFileSystemModel(const String& root_path, Mode mode) : m_root_path(FileSystemPath(root_path).string()) , m_mode(mode) diff --git a/LibGUI/GFileSystemModel.h b/LibGUI/GFileSystemModel.h index be9cc6600f..6e409fc4e0 100644 --- a/LibGUI/GFileSystemModel.h +++ b/LibGUI/GFileSystemModel.h @@ -14,6 +14,7 @@ public: virtual ~GFileSystemModel() override; String root_path() const { return m_root_path; } + String path(const GModelIndex&) const; virtual int row_count(const GModelIndex& = GModelIndex()) const override; virtual int column_count(const GModelIndex& = GModelIndex()) const override; |