40 using FileSystem = ocu::filesystem<Asset, FileManager>;
41 using File = FileSystem::file;
42 using Path = std::filesystem::path;
43 using FileID = FileSystem::file_id;
44 using CreateFunc =
Asset* (*)(
const Path&);
45 using LoadFunc =
Asset* (*)(
const Path&);
46 using ImportFunc =
Asset* (*)(
const Path&,
const Path&);
53 std::vector<std::string> Extensions;
58 AssetDetail() : Create(
nullptr), Load(
nullptr), Import(
nullptr) { }
59 AssetDetail(
const std::string& name) : Name(name), Create(
nullptr), Load(
nullptr), Import(
nullptr) {}
62 AssetDetail(
const std::string& name,
const std::vector<std::string>& exts,
63 const CreateFunc create,
const LoadFunc load,
const ImportFunc
import)
64 : Name(name), Extensions(exts), Create(create), Load(load), Import(
import) {}
67 using AssetMenuHierarchy = ocu::directed_tree<AssetDetail>;
68 using AssetType = AssetMenuHierarchy::node;
69 using ExtensionMapping = ocu::map<std::string, AssetType>;
71 static AssetMenuHierarchy& AssetMenu() {
static AssetMenuHierarchy Menu;
return Menu; }
72 static ExtensionMapping& ExtensionMap() {
static ExtensionMapping Map;
return Map; }
79 Asset(
const Path& path) : Dirty_(
false) { }
80 virtual ~Asset() =
default;
82 bool Dirty()
const {
return Dirty_; }
84 virtual void Open() { };
85 virtual void Save(
const Path& path) { Dirty_ =
false; }
87 File& GetFile() {
return Manager_->Get(File_); }
88 FileID GetID()
const {
return File_; }
91 void MakeDirty() { Dirty_ =
true; }
103 Folder(
const std::filesystem::path& p) :
Asset(p) { };
106 void Open()
override { Manager_->CurrentDirectory_ = GetID(); }
110 static Asset* load(
const Path& file, FileID
id);
111 static Asset*
import(
const Path& src,
const Path& dst, FileID id);
112 static Asset* create(
const Path& file, FileID
id);
121 FileID CurrentDirectory()
const {
return CurrentDirectory_; }
122 void CurrentDirectory(FileID
id) { CurrentDirectory_ = id; }
124 FileID Create(
const std::string& name) {
return Filesystem_.create(name, CurrentDirectory_); }
125 FileID Import(
const Path& path) {
return Filesystem_.import(path, CurrentDirectory_); }
126 FileID LoadDirectory(
const Path& path) {
return Filesystem_.load_directory(path); }
127 void CloseDirectory(FileID dir) { Filesystem_.close_directory(dir); }
129 FileID Get(
const Path& path)
const {
return Filesystem_.find(path); }
130 File& Get(FileID
id) {
return Filesystem_[id]; }
131 const File& Get(FileID
id)
const {
return Filesystem_[id]; }
133 FileID Parent(FileID
id)
const {
return Filesystem_.parent(
id); }
138 static Path GetHomeDirectory();
139 static void Register(
const std::filesystem::path& path,
140 const std::vector<std::string>& extension,
141 CreateFunc create, LoadFunc load, ImportFunc
import);
143 FileSystem Filesystem_;
144 FileID CurrentDirectory_, Selected_;
145 bool Rename_, FocusRename_;
146 std::string RenameBuffer_;