[nostalgia,studio] Fix crash that occurred when navigating to file that is not already open
All checks were successful
Build / build (push) Successful in 1m32s

This commit is contained in:
Gary Talent 2025-02-20 23:57:02 -06:00
parent d0a32e247e
commit 25a7873ea2
4 changed files with 20 additions and 10 deletions

View File

@ -566,8 +566,10 @@ void TileSheetEditorImGui::drawPaletteMenu() noexcept {
m_view.setPalIdx(i);
}
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(0)) {
auto const rqst = ox::sfmt<ox::BasicString<100>>("{};{}", i, m_model.palettePage());
oxLogError(studio::navigateTo(m_sctx, m_model.palPath(), rqst));
studio::navigateTo(
m_sctx,
m_model.palPath(),
ox::sfmt("{};{}", i, m_model.palettePage()));
}
// Column: color RGB
ImGui::TableNextColumn();

View File

@ -18,8 +18,8 @@
namespace studio {
ox::Error navigateTo(StudioContext &ctx, ox::StringViewCR filePath, ox::StringViewCR args) noexcept {
return ctx.ui.navigateTo(filePath, args);
void navigateTo(StudioContext &ctx, ox::StringParam filePath, ox::StringParam navArgs) noexcept {
ctx.ui.navigateTo(std::move(filePath), std::move(navArgs));
}
namespace ig {
@ -111,10 +111,8 @@ void StudioUI::handleKeyEvent(turbine::Key const key, bool const down) noexcept
}
}
ox::Error StudioUI::navigateTo(ox::StringViewCR path, ox::StringViewCR navArgs) noexcept {
OX_RETURN_ERROR(openFile(path));
m_activeEditor->navigateTo(navArgs);
return {};
void StudioUI::navigateTo(ox::StringParam path, ox::StringParam navArgs) noexcept {
m_navAction.emplace(std::move(path), std::move(navArgs));
}
void StudioUI::draw() noexcept {
@ -287,6 +285,11 @@ void StudioUI::drawTabs() noexcept {
}
m_closeActiveTab = false;
}
if (m_navAction) {
oxLogError(openFile(m_navAction->path));
m_activeEditor->navigateTo(m_navAction->args);
m_navAction.reset();
}
}
void StudioUI::loadEditorMaker(EditorMaker const&editorMaker) noexcept {

View File

@ -62,13 +62,18 @@ class StudioUI: public ox::SignalHandler {
&m_renameFile,
};
bool m_showProjectExplorer = true;
struct NavAction {
ox::String path;
ox::String args;
};
ox::Optional<NavAction> m_navAction;
public:
explicit StudioUI(turbine::Context &ctx, ox::StringParam projectDataDir) noexcept;
void handleKeyEvent(turbine::Key, bool down) noexcept;
ox::Error navigateTo(ox::StringViewCR path, ox::StringViewCR navArgs = {}) noexcept;
void navigateTo(ox::StringParam path, ox::StringParam navArgs) noexcept;
[[nodiscard]]
constexpr Project *project() noexcept {

View File

@ -27,6 +27,6 @@ inline keel::Context &keelCtx(StudioContext &ctx) noexcept {
return keelCtx(ctx.tctx);
}
ox::Error navigateTo(StudioContext &ctx, ox::StringViewCR filePath, ox::StringViewCR args) noexcept;
void navigateTo(StudioContext &ctx, ox::StringParam filePath, ox::StringParam navArgs) noexcept;
}