From 778cb78f313a685a37e0e95cdfc51f68c01d6b2e Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Mon, 21 Feb 2022 20:07:25 -0600 Subject: [PATCH] [nostalgia/studio] Add creation of StudioContext --- src/nostalgia/studio/main.cpp | 8 ++++++-- src/nostalgia/studio/studioapp.cpp | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/nostalgia/studio/main.cpp b/src/nostalgia/studio/main.cpp index 6b6bf513..14bbc94c 100644 --- a/src/nostalgia/studio/main.cpp +++ b/src/nostalgia/studio/main.cpp @@ -6,6 +6,7 @@ #include +#include "lib/context.hpp" #include "studioapp.hpp" namespace nostalgia { @@ -23,7 +24,8 @@ class StudioUIDrawer: public core::Drawer { }; static int eventHandler(core::Context *ctx) noexcept { - auto ui = core::applicationData(ctx); + auto sctx = core::applicationData(ctx); + auto ui = dynamic_cast(sctx->ui); ui->update(); return 16; } @@ -32,9 +34,11 @@ static ox::Error run(ox::UniquePtr fs) noexcept { oxRequireM(ctx, core::init(std::move(fs), "NostalgiaStudio")); core::setWindowTitle(ctx.get(), "Nostalgia Studio"); core::setEventHandler(ctx.get(), eventHandler); + studio::StudioContext studioCtx; + core::setApplicationData(ctx.get(), &studioCtx); StudioUI ui(ctx.get()); + studioCtx.ui = &ui; StudioUIDrawer drawer(&ui); - core::setApplicationData(ctx.get(), &ui); ctx->drawers.emplace_back(&drawer); return core::run(ctx.get()); } diff --git a/src/nostalgia/studio/studioapp.cpp b/src/nostalgia/studio/studioapp.cpp index de990861..68aaac9f 100644 --- a/src/nostalgia/studio/studioapp.cpp +++ b/src/nostalgia/studio/studioapp.cpp @@ -215,6 +215,8 @@ ox::Error StudioUI::openProject(const ox::String &path) noexcept { m_ctx->rom = std::move(fs); core::setWindowTitle(m_ctx, ox::sfmt("Nostalgia Studio - {}", path).c_str()); m_project = ox::make_unique(m_ctx->rom.get(), path); + auto sctx = applicationData(m_ctx); + sctx->project = m_project.get(); m_project->fileAdded.connect(m_projectExplorer, &ProjectExplorer::refreshProjectTreeModel); m_project->fileDeleted.connect(m_projectExplorer, &ProjectExplorer::refreshProjectTreeModel); studio::editConfig(m_ctx, [&](StudioConfig *config) {