mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 18:58:12 +00:00
FileManager: Make the directory view follow the tree view selection.
This commit is contained in:
parent
be42382a3a
commit
f10e0d0546
3 changed files with 16 additions and 1 deletions
|
@ -54,7 +54,8 @@ int main(int argc, char** argv)
|
||||||
auto* splitter = new GWidget(widget);
|
auto* splitter = new GWidget(widget);
|
||||||
splitter->set_layout(make<GBoxLayout>(Orientation::Horizontal));
|
splitter->set_layout(make<GBoxLayout>(Orientation::Horizontal));
|
||||||
auto* tree_view = new GTreeView(splitter);
|
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_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
|
||||||
tree_view->set_preferred_size({ 200, 0 });
|
tree_view->set_preferred_size({ 200, 0 });
|
||||||
auto* directory_view = new DirectoryView(splitter);
|
auto* directory_view = new DirectoryView(splitter);
|
||||||
|
@ -70,6 +71,10 @@ int main(int argc, char** argv)
|
||||||
directory_view->open(editor.text());
|
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&) {
|
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();
|
directory_view->open_parent_directory();
|
||||||
});
|
});
|
||||||
|
|
|
@ -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)
|
GFileSystemModel::GFileSystemModel(const String& root_path, Mode mode)
|
||||||
: m_root_path(FileSystemPath(root_path).string())
|
: m_root_path(FileSystemPath(root_path).string())
|
||||||
, m_mode(mode)
|
, m_mode(mode)
|
||||||
|
|
|
@ -14,6 +14,7 @@ public:
|
||||||
virtual ~GFileSystemModel() override;
|
virtual ~GFileSystemModel() override;
|
||||||
|
|
||||||
String root_path() const { return m_root_path; }
|
String root_path() const { return m_root_path; }
|
||||||
|
String path(const GModelIndex&) const;
|
||||||
|
|
||||||
virtual int row_count(const GModelIndex& = GModelIndex()) const override;
|
virtual int row_count(const GModelIndex& = GModelIndex()) const override;
|
||||||
virtual int column_count(const GModelIndex& = GModelIndex()) const override;
|
virtual int column_count(const GModelIndex& = GModelIndex()) const override;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue