summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Applications/FileManager/main.cpp7
-rw-r--r--LibGUI/GFileSystemModel.cpp9
-rw-r--r--LibGUI/GFileSystemModel.h1
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;