Compare commits

..

2 Commits

Author SHA1 Message Date
0abadc1850 [studio] Fix QuestionPopup to only emit a response when there is a response
All checks were successful
Build / build (push) Successful in 3m36s
2025-02-03 00:35:37 -06:00
4e068d628c [studio] Fix misrender flash on tab close 2025-02-03 00:19:14 -06:00
3 changed files with 25 additions and 8 deletions

View File

@ -231,7 +231,10 @@ void StudioUI::drawTabs() noexcept {
if (m_activeEditorOnLastDraw != e.get()) [[unlikely]] { if (m_activeEditorOnLastDraw != e.get()) [[unlikely]] {
m_activeEditor->onActivated(); m_activeEditor->onActivated();
} }
if (open) [[likely]] { if (m_closeActiveTab) [[unlikely]] {
ImGui::SetTabItemClosed(e->itemDisplayName().c_str());
} else if (open) [[likely]] {
e->draw(m_sctx); e->draw(m_sctx);
} }
m_activeEditorOnLastDraw = e.get(); m_activeEditorOnLastDraw = e.get();
@ -258,6 +261,20 @@ void StudioUI::drawTabs() noexcept {
++it; ++it;
} }
} }
if (m_closeActiveTab) [[unlikely]] {
if (m_activeEditor) {
auto const idx = find_if(
m_editors.begin(), m_editors.end(),
[this](ox::UPtr<BaseEditor> const &e) {
return m_activeEditor == e.get();
});
if (idx != m_editors.end()) {
oxLogError(m_editors.erase(idx.offset()).error);
}
m_activeEditor = nullptr;
}
m_closeActiveTab = false;
}
} }
void StudioUI::loadEditorMaker(EditorMaker const&editorMaker) noexcept { void StudioUI::loadEditorMaker(EditorMaker const&editorMaker) noexcept {
@ -407,13 +424,12 @@ ox::Error StudioUI::handleMoveFile(ox::StringViewCR oldPath, ox::StringViewCR ne
} }
ox::Error StudioUI::handleDeleteFile(ox::StringViewCR path) noexcept { ox::Error StudioUI::handleDeleteFile(ox::StringViewCR path) noexcept {
for (size_t i{}; auto &e : m_editors) { for (auto &e : m_editors) {
if (path == e->itemPath()) { if (path == e->itemPath()) {
oxLogError(m_editors.erase(i).error);
oxLogError(closeFile(path)); oxLogError(closeFile(path));
m_closeActiveTab = true;
break; break;
} }
++i;
} }
return m_projectExplorer.refreshProjectTreeModel(); return m_projectExplorer.refreshProjectTreeModel();
} }
@ -505,13 +521,12 @@ ox::Error StudioUI::handleCloseFileResponse(ig::PopupResponse const response) no
} }
ox::Error StudioUI::closeCurrentFile() noexcept { ox::Error StudioUI::closeCurrentFile() noexcept {
for (size_t i{}; auto &e : m_editors) { for (auto &e : m_editors) {
if (m_activeEditor == e.get()) { if (m_activeEditor == e.get()) {
oxLogError(closeFile(e->itemPath())); oxLogError(closeFile(e->itemPath()));
oxLogError(m_editors.erase(i).error); m_closeActiveTab = true;
break; break;
} }
++i;
} }
return {}; return {};
} }

View File

@ -41,6 +41,7 @@ class StudioUI: public ox::SignalHandler {
BaseEditor *m_activeEditorOnLastDraw = nullptr; BaseEditor *m_activeEditorOnLastDraw = nullptr;
BaseEditor *m_activeEditor = nullptr; BaseEditor *m_activeEditor = nullptr;
BaseEditor *m_activeEditorUpdatePending = nullptr; BaseEditor *m_activeEditorUpdatePending = nullptr;
bool m_closeActiveTab{};
ox::Vector<ox::Pair<ox::String>> m_queuedMoves; ox::Vector<ox::Pair<ox::String>> m_queuedMoves;
ox::Vector<ox::Pair<ox::String>> m_queuedDirMoves; ox::Vector<ox::Pair<ox::String>> m_queuedDirMoves;
NewMenu m_newMenu{keelCtx(m_tctx)}; NewMenu m_newMenu{keelCtx(m_tctx)};

View File

@ -260,14 +260,15 @@ void QuestionPopup::draw(StudioContext &ctx, ImVec2 const &sz) noexcept {
if (ImGui::BeginPopupModal(m_title.c_str(), &m_open, modalFlags)) { if (ImGui::BeginPopupModal(m_title.c_str(), &m_open, modalFlags)) {
ImGui::Text("%s", m_question.c_str()); ImGui::Text("%s", m_question.c_str());
auto const r = PopupControlsOkCancel(m_open, "Yes", "No"); auto const r = PopupControlsOkCancel(m_open, "Yes", "No");
response.emit(r);
switch (r) { switch (r) {
case PopupResponse::None: case PopupResponse::None:
break; break;
case PopupResponse::OK: case PopupResponse::OK:
response.emit(r);
close(); close();
break; break;
case PopupResponse::Cancel: case PopupResponse::Cancel:
response.emit(r);
close(); close();
break; break;
} }