[studio] Make reusable FileTreeModel
This commit is contained in:
51
src/olympic/studio/modlib/include/studio/filetreemodel.hpp
Normal file
51
src/olympic/studio/modlib/include/studio/filetreemodel.hpp
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ox/std/memory.hpp>
|
||||
#include <ox/std/string.hpp>
|
||||
|
||||
#include <turbine/context.hpp>
|
||||
|
||||
namespace studio {
|
||||
|
||||
class FileExplorer {
|
||||
|
||||
public:
|
||||
virtual ~FileExplorer() = default;
|
||||
|
||||
virtual void fileOpened(ox::StringViewCR path) const noexcept = 0;
|
||||
|
||||
virtual void drawFileContextMenu(ox::StringViewCR path) const noexcept = 0;
|
||||
|
||||
virtual void drawDirContextMenu(ox::StringViewCR path) const noexcept = 0;
|
||||
|
||||
};
|
||||
|
||||
class FileTreeModel {
|
||||
private:
|
||||
FileExplorer &m_explorer;
|
||||
FileTreeModel *m_parent = nullptr;
|
||||
ox::String m_name;
|
||||
ox::String m_fullPath{m_parent ? m_parent->m_fullPath + "/" + m_name : ox::String{}};
|
||||
ox::String m_imguiNodeName{ox::sfmt("{}##{}", m_name, m_fullPath)};
|
||||
ox::Vector<ox::UPtr<FileTreeModel>> m_children;
|
||||
|
||||
public:
|
||||
virtual ~FileTreeModel() = default;
|
||||
|
||||
explicit FileTreeModel(
|
||||
FileExplorer &explorer, ox::StringParam name,
|
||||
FileTreeModel *parent = nullptr) noexcept;
|
||||
|
||||
FileTreeModel(FileTreeModel &&other) noexcept = default;
|
||||
|
||||
void draw(turbine::Context &tctx) const noexcept;
|
||||
|
||||
void setChildren(ox::Vector<ox::UPtr<FileTreeModel>> children) noexcept;
|
||||
|
||||
};
|
||||
|
||||
}
|
Reference in New Issue
Block a user