mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 08:58:11 +00:00
GFileSystemModel: Add a "DirectoriesOnly" mode.
This commit is contained in:
parent
4d3c5fd83e
commit
6b72c62c5f
3 changed files with 11 additions and 6 deletions
|
@ -54,7 +54,7 @@ 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("/"));
|
tree_view->set_model(GFileSystemModel::create("/", GFileSystemModel::Mode::DirectoriesOnly));
|
||||||
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);
|
||||||
|
|
|
@ -51,7 +51,6 @@ struct GFileSystemModel::Node {
|
||||||
|
|
||||||
auto full_path = this->full_path(model);
|
auto full_path = this->full_path(model);
|
||||||
DIR* dirp = opendir(full_path.characters());
|
DIR* dirp = opendir(full_path.characters());
|
||||||
dbgprintf("traverse if needed: %s (%p)\n", full_path.characters(), dirp);
|
|
||||||
if (!dirp)
|
if (!dirp)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -64,6 +63,8 @@ struct GFileSystemModel::Node {
|
||||||
perror("lstat");
|
perror("lstat");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (model.m_mode == DirectoriesOnly && !S_ISDIR(st.st_mode))
|
||||||
|
continue;
|
||||||
auto* child = new Node;
|
auto* child = new Node;
|
||||||
child->name = de->d_name;
|
child->name = de->d_name;
|
||||||
child->type = S_ISDIR(st.st_mode) ? Node::Type::Directory : Node::Type::File;
|
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_root_path(FileSystemPath(root_path).string())
|
||||||
|
, m_mode(mode)
|
||||||
{
|
{
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,9 +5,11 @@
|
||||||
class GFileSystemModel : public GModel {
|
class GFileSystemModel : public GModel {
|
||||||
friend class Node;
|
friend class Node;
|
||||||
public:
|
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;
|
virtual ~GFileSystemModel() override;
|
||||||
|
|
||||||
|
@ -22,9 +24,10 @@ public:
|
||||||
virtual void activate(const GModelIndex&) override;
|
virtual void activate(const GModelIndex&) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit GFileSystemModel(const String& root_path);
|
GFileSystemModel(const String& root_path, Mode);
|
||||||
|
|
||||||
String m_root_path;
|
String m_root_path;
|
||||||
|
Mode m_mode { Invalid };
|
||||||
|
|
||||||
struct Node;
|
struct Node;
|
||||||
Node* m_root { nullptr };
|
Node* m_root { nullptr };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue