[studio] Fix file deletion to close file even if not active
This commit is contained in:
@ -551,24 +551,36 @@ ox::Error StudioUI::handleMoveFile(ox::StringViewCR oldPath, ox::StringViewCR ne
|
|||||||
|
|
||||||
ox::Error StudioUI::handleDeleteDir(ox::StringViewCR path) noexcept {
|
ox::Error StudioUI::handleDeleteDir(ox::StringViewCR path) noexcept {
|
||||||
auto const p = sfmt("{}/", path);
|
auto const p = sfmt("{}/", path);
|
||||||
for (auto &e : m_editors) {
|
std::ignore = m_editors.erase(
|
||||||
if (beginsWith(e->itemPath(), p)) {
|
std::remove_if(
|
||||||
oxLogError(closeFile(path));
|
m_editors.begin(), m_editors.end(),
|
||||||
m_closeActiveTab = true;
|
[&](ox::UPtr<BaseEditor> const &e) {
|
||||||
break;
|
if (beginsWith(e->itemPath(), p)) {
|
||||||
}
|
oxLogError(closeFile(path));
|
||||||
}
|
if (e.get() != m_activeEditor) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
m_closeActiveTab = true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}));
|
||||||
return m_projectExplorer.refreshProjectTreeModel();
|
return m_projectExplorer.refreshProjectTreeModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Error StudioUI::handleDeleteFile(ox::StringViewCR path) noexcept {
|
ox::Error StudioUI::handleDeleteFile(ox::StringViewCR path) noexcept {
|
||||||
for (auto &e : m_editors) {
|
std::ignore = m_editors.erase(
|
||||||
if (path == e->itemPath()) {
|
std::remove_if(
|
||||||
oxLogError(closeFile(path));
|
m_editors.begin(), m_editors.end(),
|
||||||
m_closeActiveTab = true;
|
[&](ox::UPtr<BaseEditor> const &e) {
|
||||||
break;
|
if (path == e->itemPath()) {
|
||||||
}
|
oxLogError(closeFile(path));
|
||||||
}
|
if (e.get() != m_activeEditor) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
m_closeActiveTab = true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}));
|
||||||
return m_projectExplorer.refreshProjectTreeModel();
|
return m_projectExplorer.refreshProjectTreeModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -666,10 +678,10 @@ ox::Error StudioUI::openFileActiveTab(ox::StringViewCR path, bool const makeActi
|
|||||||
}
|
}
|
||||||
OX_REQUIRE(ext, fileExt(path));
|
OX_REQUIRE(ext, fileExt(path));
|
||||||
// create Editor
|
// create Editor
|
||||||
BaseEditor *editor = nullptr;
|
ox::UPtr<BaseEditor> editor;
|
||||||
auto const err = m_editorMakers.contains(ext) ?
|
auto const err = m_editorMakers.contains(ext) ?
|
||||||
m_editorMakers[ext](path).moveTo(editor) :
|
m_editorMakers[ext](path).to<ox::UPtr<BaseEditor>>().moveTo(editor) :
|
||||||
ox::makeCatch<ClawEditor>(m_sctx, path).moveTo(editor);
|
ox::make_unique_catch<ClawEditor>(m_sctx, path).moveTo(editor);
|
||||||
if (err) {
|
if (err) {
|
||||||
if constexpr(!ox::defines::Debug) {
|
if constexpr(!ox::defines::Debug) {
|
||||||
oxErrf("Could not open Editor: {}\n", toStr(err));
|
oxErrf("Could not open Editor: {}\n", toStr(err));
|
||||||
@ -679,11 +691,11 @@ ox::Error StudioUI::openFileActiveTab(ox::StringViewCR path, bool const makeActi
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
editor->closed.connect(this, &StudioUI::closeFile);
|
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);
|
m_openFiles.emplace_back(path);
|
||||||
if (makeActiveTab) {
|
if (makeActiveTab) {
|
||||||
m_activeEditor = m_editors.back().value->get();
|
m_activeEditor = m_editors.back().value->get();
|
||||||
m_activeEditorUpdatePending = editor;
|
m_activeEditorUpdatePending = e.get();
|
||||||
}
|
}
|
||||||
// save to config
|
// save to config
|
||||||
studio::editConfig<StudioConfig>(keelCtx(m_tctx), [&path](StudioConfig &config) {
|
studio::editConfig<StudioConfig>(keelCtx(m_tctx), [&path](StudioConfig &config) {
|
||||||
|
Reference in New Issue
Block a user