[studio] Make reusable FileTreeModel

This commit is contained in:
2025-01-22 01:04:25 -06:00
parent e1282b6bae
commit d15a0df7da
9 changed files with 153 additions and 142 deletions

View 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;
};
}