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

View File

@ -11,14 +11,14 @@
namespace studio {
class ClawEditor: public studio::Editor {
class ClawEditor: public Editor {
private:
using ObjPath = ox::Vector<ox::StringView, 8>;
ox::ModelObject m_obj;
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:
static void drawRow(ox::ModelValue const&value) noexcept;

View File

@ -366,23 +366,17 @@ ox::Error StudioUI::openFileActiveTab(ox::CRStringView path, bool makeActiveTab)
}
oxRequire(ext, studio::fileExt(path));
// create Editor
studio::BaseEditor *editor = nullptr;
if (!m_editorMakers.contains(ext)) {
auto [obj, err] = m_project->loadObj<ox::ModelObject>(path);
if (err) {
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 constexpr(!ox::defines::Debug) {
oxErrf("Could not open Editor: {}\n", toStr(err));
} else {
oxErrf("Could not open Editor: {} ({}:{})\n", err.errCode, err.file, err.line);
}
return err;
BaseEditor *editor = nullptr;
auto const err = m_editorMakers.contains(ext) ?
m_editorMakers[ext](path).moveTo(editor) :
ox::makeCatch<ClawEditor>(m_sctx, path).moveTo(editor);
if (err) {
if constexpr(!ox::defines::Debug) {
oxErrf("Could not open Editor: {}\n", toStr(err));
} else {
oxErrf("Could not open Editor: {} ({}:{})\n", err.errCode, err.file, err.line);
}
return err;
}
editor->closed.connect(this, &StudioUI::closeFile);
m_editors.emplace_back(editor);