[nostalgia] Cleanup config IO

This commit is contained in:
2024-06-01 20:14:29 -05:00
parent 6cbafc75bf
commit 3635702ede
3 changed files with 36 additions and 44 deletions

View File

@ -203,8 +203,8 @@ void StudioUI::drawTabs() noexcept {
if (ImGui::BeginTabItem(e->itemDisplayName().c_str(), &open, flags)) {
if (m_activeEditor != e.get()) {
m_activeEditor = e.get();
studio::editConfig<StudioConfig>(keelCtx(m_ctx), [&](StudioConfig *config) {
config->activeTabItemName = m_activeEditor->itemPath();
studio::editConfig<StudioConfig>(keelCtx(m_ctx), [&](StudioConfig &config) {
config.activeTabItemName = m_activeEditor->itemPath();
});
}
if (m_activeEditorUpdatePending == e.get()) {
@ -258,8 +258,8 @@ void StudioUI::loadModules() noexcept {
void StudioUI::toggleProjectExplorer() noexcept {
m_showProjectExplorer = !m_showProjectExplorer;
studio::editConfig<StudioConfig>(keelCtx(m_ctx), [&](StudioConfig *config) {
config->showProjectExplorer = m_showProjectExplorer;
studio::editConfig<StudioConfig>(keelCtx(m_ctx), [&](StudioConfig &config) {
config.showProjectExplorer = m_showProjectExplorer;
});
}
@ -342,9 +342,9 @@ ox::Error StudioUI::openProjectPath(ox::CRStringView path) noexcept {
m_project->fileDeleted.connect(&m_projectExplorer, &ProjectExplorer::refreshProjectTreeModel);
m_openFiles.clear();
m_editors.clear();
studio::editConfig<StudioConfig>(keelCtx(m_ctx), [&](StudioConfig *config) {
config->projectPath = ox::String(m_project->projectPath());
config->openFiles.clear();
studio::editConfig<StudioConfig>(keelCtx(m_ctx), [&](StudioConfig &config) {
config.projectPath = ox::String(m_project->projectPath());
config.openFiles.clear();
});
return m_projectExplorer.refreshProjectTreeModel();
}
@ -395,9 +395,9 @@ ox::Error StudioUI::openFileActiveTab(ox::CRStringView path, bool makeActiveTab)
m_activeEditorUpdatePending = editor;
}
// save to config
studio::editConfig<StudioConfig>(keelCtx(m_ctx), [&](StudioConfig *config) {
if (!config->openFiles.contains(path)) {
config->openFiles.emplace_back(path);
studio::editConfig<StudioConfig>(keelCtx(m_ctx), [&](StudioConfig &config) {
if (!config.openFiles.contains(path)) {
config.openFiles.emplace_back(path);
}
});
return {};
@ -409,8 +409,8 @@ ox::Error StudioUI::closeFile(ox::CRStringView path) noexcept {
}
std::ignore = m_openFiles.erase(std::remove(m_openFiles.begin(), m_openFiles.end(), path));
// save to config
studio::editConfig<StudioConfig>(keelCtx(m_ctx), [&](StudioConfig *config) {
std::ignore = config->openFiles.erase(std::remove(config->openFiles.begin(), config->openFiles.end(), path));
studio::editConfig<StudioConfig>(keelCtx(m_ctx), [&](StudioConfig &config) {
std::ignore = config.openFiles.erase(std::remove(config.openFiles.begin(), config.openFiles.end(), path));
});
return {};
}