diff --git a/src/olympic/studio/applib/src/studioui.cpp b/src/olympic/studio/applib/src/studioui.cpp index 5ce33023..b3716859 100644 --- a/src/olympic/studio/applib/src/studioui.cpp +++ b/src/olympic/studio/applib/src/studioui.cpp @@ -551,24 +551,36 @@ ox::Error StudioUI::handleMoveFile(ox::StringViewCR oldPath, ox::StringViewCR ne ox::Error StudioUI::handleDeleteDir(ox::StringViewCR path) noexcept { auto const p = sfmt("{}/", path); - for (auto &e : m_editors) { - if (beginsWith(e->itemPath(), p)) { - oxLogError(closeFile(path)); - m_closeActiveTab = true; - break; - } - } + std::ignore = m_editors.erase( + std::remove_if( + m_editors.begin(), m_editors.end(), + [&](ox::UPtr const &e) { + if (beginsWith(e->itemPath(), p)) { + oxLogError(closeFile(path)); + if (e.get() != m_activeEditor) { + return true; + } + m_closeActiveTab = true; + } + return false; + })); return m_projectExplorer.refreshProjectTreeModel(); } ox::Error StudioUI::handleDeleteFile(ox::StringViewCR path) noexcept { - for (auto &e : m_editors) { - if (path == e->itemPath()) { - oxLogError(closeFile(path)); - m_closeActiveTab = true; - break; - } - } + std::ignore = m_editors.erase( + std::remove_if( + m_editors.begin(), m_editors.end(), + [&](ox::UPtr const &e) { + if (path == e->itemPath()) { + oxLogError(closeFile(path)); + if (e.get() != m_activeEditor) { + return true; + } + m_closeActiveTab = true; + } + return false; + })); return m_projectExplorer.refreshProjectTreeModel(); } @@ -666,10 +678,10 @@ ox::Error StudioUI::openFileActiveTab(ox::StringViewCR path, bool const makeActi } OX_REQUIRE(ext, fileExt(path)); // create Editor - BaseEditor *editor = nullptr; + ox::UPtr editor; auto const err = m_editorMakers.contains(ext) ? - m_editorMakers[ext](path).moveTo(editor) : - ox::makeCatch(m_sctx, path).moveTo(editor); + m_editorMakers[ext](path).to>().moveTo(editor) : + ox::make_unique_catch(m_sctx, path).moveTo(editor); if (err) { if constexpr(!ox::defines::Debug) { oxErrf("Could not open Editor: {}\n", toStr(err)); @@ -679,11 +691,11 @@ ox::Error StudioUI::openFileActiveTab(ox::StringViewCR path, bool const makeActi return err; } editor->closed.connect(this, &StudioUI::closeFile); - m_editors.emplace_back(editor); + auto const &e = m_editors.emplace_back(std::move(editor)); m_openFiles.emplace_back(path); if (makeActiveTab) { m_activeEditor = m_editors.back().value->get(); - m_activeEditorUpdatePending = editor; + m_activeEditorUpdatePending = e.get(); } // save to config studio::editConfig(keelCtx(m_tctx), [&path](StudioConfig &config) {