[studio] Cleanup

This commit is contained in:
Gary Talent 2024-09-07 02:25:09 -05:00
parent c45efa6019
commit 712299faf3
3 changed files with 17 additions and 23 deletions

View File

@ -8,12 +8,12 @@
namespace studio { namespace studio {
ClawEditor::ClawEditor(ox::CRStringView path, ox::ModelObject obj) noexcept: ClawEditor::ClawEditor(StudioContext &sctx, ox::StringParam path):
Editor(path), Editor(std::move(path)),
m_obj(std::move(obj)) { m_obj(sctx.project->loadObj<ox::ModelObject>(itemPath()).unwrapThrow()) {
} }
void ClawEditor::draw(studio::StudioContext&) noexcept { void ClawEditor::draw(StudioContext&) noexcept {
ImGui::BeginChild("PaletteEditor"); ImGui::BeginChild("PaletteEditor");
static constexpr auto flags = ImGuiTableFlags_RowBg | ImGuiTableFlags_NoBordersInBody; static constexpr auto flags = ImGuiTableFlags_RowBg | ImGuiTableFlags_NoBordersInBody;
if (ImGui::BeginTable("ObjTree", 3, flags)) { if (ImGui::BeginTable("ObjTree", 3, flags)) {

View File

@ -11,14 +11,14 @@
namespace studio { namespace studio {
class ClawEditor: public studio::Editor { class ClawEditor: public Editor {
private: private:
using ObjPath = ox::Vector<ox::StringView, 8>; using ObjPath = ox::Vector<ox::StringView, 8>;
ox::ModelObject m_obj; ox::ModelObject m_obj;
public: public:
ClawEditor(ox::CRStringView path, ox::ModelObject obj) noexcept; ClawEditor(StudioContext &sctx, ox::StringParam path);
void draw(studio::StudioContext&) noexcept final; void draw(StudioContext&) noexcept final;
private: private:
static void drawRow(ox::ModelValue const&value) noexcept; static void drawRow(ox::ModelValue const&value) noexcept;

View File

@ -366,15 +366,10 @@ ox::Error StudioUI::openFileActiveTab(ox::CRStringView path, bool makeActiveTab)
} }
oxRequire(ext, studio::fileExt(path)); oxRequire(ext, studio::fileExt(path));
// create Editor // create Editor
studio::BaseEditor *editor = nullptr; BaseEditor *editor = nullptr;
if (!m_editorMakers.contains(ext)) { auto const err = m_editorMakers.contains(ext) ?
auto [obj, err] = m_project->loadObj<ox::ModelObject>(path); m_editorMakers[ext](path).moveTo(editor) :
if (err) { ox::makeCatch<ClawEditor>(m_sctx, path).moveTo(editor);
return OxError(1, "There is no editor for this file extension");
}
editor = ox::make<ClawEditor>(path, std::move(obj));
} else {
auto const err = m_editorMakers[ext](path).moveTo(editor);
if (err) { if (err) {
if constexpr(!ox::defines::Debug) { if constexpr(!ox::defines::Debug) {
oxErrf("Could not open Editor: {}\n", toStr(err)); oxErrf("Could not open Editor: {}\n", toStr(err));
@ -383,7 +378,6 @@ ox::Error StudioUI::openFileActiveTab(ox::CRStringView path, bool makeActiveTab)
} }
return err; return err;
} }
}
editor->closed.connect(this, &StudioUI::closeFile); editor->closed.connect(this, &StudioUI::closeFile);
m_editors.emplace_back(editor); m_editors.emplace_back(editor);
m_openFiles.emplace_back(path); m_openFiles.emplace_back(path);