diff options
-rw-r--r-- | Applications/FileManager/main.cpp | 2 | ||||
-rw-r--r-- | LibGUI/GFileSystemModel.cpp | 6 | ||||
-rw-r--r-- | LibGUI/GFileSystemModel.h | 9 |
3 files changed, 11 insertions, 6 deletions
diff --git a/Applications/FileManager/main.cpp b/Applications/FileManager/main.cpp index a546c3e395..3d5feec079 100644 --- a/Applications/FileManager/main.cpp +++ b/Applications/FileManager/main.cpp @@ -54,7 +54,7 @@ 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("/")); + tree_view->set_model(GFileSystemModel::create("/", GFileSystemModel::Mode::DirectoriesOnly)); tree_view->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill); tree_view->set_preferred_size({ 200, 0 }); auto* directory_view = new DirectoryView(splitter); diff --git a/LibGUI/GFileSystemModel.cpp b/LibGUI/GFileSystemModel.cpp index 7f80a68178..a50ef3b595 100644 --- a/LibGUI/GFileSystemModel.cpp +++ b/LibGUI/GFileSystemModel.cpp @@ -51,7 +51,6 @@ struct GFileSystemModel::Node { auto full_path = this->full_path(model); DIR* dirp = opendir(full_path.characters()); - dbgprintf("traverse if needed: %s (%p)\n", full_path.characters(), dirp); if (!dirp) return; @@ -64,6 +63,8 @@ struct GFileSystemModel::Node { perror("lstat"); continue; } + if (model.m_mode == DirectoriesOnly && !S_ISDIR(st.st_mode)) + continue; auto* child = new Node; child->name = de->d_name; child->type = S_ISDIR(st.st_mode) ? Node::Type::Directory : Node::Type::File; @@ -91,8 +92,9 @@ struct GFileSystemModel::Node { } }; -GFileSystemModel::GFileSystemModel(const String& root_path) +GFileSystemModel::GFileSystemModel(const String& root_path, Mode mode) : m_root_path(FileSystemPath(root_path).string()) + , m_mode(mode) { update(); } diff --git a/LibGUI/GFileSystemModel.h b/LibGUI/GFileSystemModel.h index c465d68b6e..09f137625a 100644 --- a/LibGUI/GFileSystemModel.h +++ b/LibGUI/GFileSystemModel.h @@ -5,9 +5,11 @@ class GFileSystemModel : public GModel { friend class Node; public: - static Retained<GFileSystemModel> create(const String& root_path = "/") + enum Mode { Invalid, DirectoriesOnly, FilesAndDirectories }; + + static Retained<GFileSystemModel> create(const String& root_path = "/", Mode mode = Mode::FilesAndDirectories) { - return adopt(*new GFileSystemModel(root_path)); + return adopt(*new GFileSystemModel(root_path, mode)); } virtual ~GFileSystemModel() override; @@ -22,9 +24,10 @@ public: virtual void activate(const GModelIndex&) override; private: - explicit GFileSystemModel(const String& root_path); + GFileSystemModel(const String& root_path, Mode); String m_root_path; + Mode m_mode { Invalid }; struct Node; Node* m_root { nullptr }; |