2019-03-29 17:03:30 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <LibGUI/GModel.h>
|
|
|
|
|
|
|
|
class GFileSystemModel : public GModel {
|
|
|
|
friend class Node;
|
|
|
|
public:
|
2019-03-29 17:14:03 +01:00
|
|
|
enum Mode { Invalid, DirectoriesOnly, FilesAndDirectories };
|
|
|
|
|
|
|
|
static Retained<GFileSystemModel> create(const String& root_path = "/", Mode mode = Mode::FilesAndDirectories)
|
2019-03-29 17:03:30 +01:00
|
|
|
{
|
2019-03-29 17:14:03 +01:00
|
|
|
return adopt(*new GFileSystemModel(root_path, mode));
|
2019-03-29 17:03:30 +01:00
|
|
|
}
|
|
|
|
virtual ~GFileSystemModel() override;
|
|
|
|
|
|
|
|
String root_path() const { return m_root_path; }
|
2019-03-30 02:22:38 +01:00
|
|
|
String path(const GModelIndex&) const;
|
2019-03-30 03:27:25 +01:00
|
|
|
GModelIndex index(const String& path) const;
|
2019-03-29 17:03:30 +01:00
|
|
|
|
|
|
|
virtual int row_count(const GModelIndex& = GModelIndex()) const override;
|
|
|
|
virtual int column_count(const GModelIndex& = GModelIndex()) const override;
|
|
|
|
virtual GVariant data(const GModelIndex&, Role = Role::Display) const override;
|
|
|
|
virtual void update() override;
|
|
|
|
virtual GModelIndex parent_index(const GModelIndex&) const override;
|
2019-03-29 20:36:15 +01:00
|
|
|
virtual GModelIndex index(int row, int column = 0, const GModelIndex& parent = GModelIndex()) const override;
|
2019-03-29 17:03:30 +01:00
|
|
|
virtual void activate(const GModelIndex&) override;
|
|
|
|
|
|
|
|
private:
|
2019-03-29 17:14:03 +01:00
|
|
|
GFileSystemModel(const String& root_path, Mode);
|
2019-03-29 17:03:30 +01:00
|
|
|
|
|
|
|
String m_root_path;
|
2019-03-29 17:14:03 +01:00
|
|
|
Mode m_mode { Invalid };
|
2019-03-29 17:03:30 +01:00
|
|
|
|
|
|
|
struct Node;
|
|
|
|
Node* m_root { nullptr };
|
2019-03-30 04:20:28 +01:00
|
|
|
|
|
|
|
GIcon m_open_folder_icon;
|
|
|
|
GIcon m_closed_folder_icon;
|
|
|
|
GIcon m_file_icon;
|
2019-03-29 17:03:30 +01:00
|
|
|
};
|