[nostalgia/studio] Make opening a file switch to its tab

This commit is contained in:
Gary Talent 2022-04-03 00:32:23 -05:00
parent 83ad1623d3
commit 60d67218db
2 changed files with 18 additions and 2 deletions

View File

@ -183,9 +183,15 @@ void StudioUI::drawTabs() noexcept {
for (auto it = m_editors.begin(); it != m_editors.end();) {
auto const &e = *it;
auto open = true;
const auto flags = e->unsavedChanges() ? ImGuiTabItemFlags_UnsavedDocument : 0;
const auto unsavedChanges = e->unsavedChanges() ? ImGuiTabItemFlags_UnsavedDocument : 0;
const auto selected = m_activeEditorUpdatePending && e.get() == m_acitveEditor ?
ImGuiTabItemFlags_SetSelected : 0;
const auto flags = unsavedChanges | selected;
if (ImGui::BeginTabItem(e->itemDisplayName().c_str(), &open, flags)) {
if (selected) {
m_acitveEditor = e.get();
m_activeEditorUpdatePending = false;
}
e->draw(m_ctx);
ImGui::EndTabItem();
}
@ -283,6 +289,13 @@ ox::Error StudioUI::openProject(const ox::String &path) noexcept {
ox::Error StudioUI::openFile(const ox::String &path) noexcept {
if (m_openFiles.contains(path)) {
for (auto &e : m_editors) {
if (e->itemName() == path) {
m_acitveEditor = e.get();
m_activeEditorUpdatePending = true;
break;
}
}
return OxError(0);
}
oxRequire(ext, studio::fileExt(path));
@ -298,6 +311,8 @@ ox::Error StudioUI::openFile(const ox::String &path) noexcept {
editor->closed.connect(this, &StudioUI::closeFile);
m_editors.emplace_back(editor);
m_openFiles.emplace_back(path);
m_acitveEditor = m_editors.back().value.get();
m_activeEditorUpdatePending = true;
// save to config
studio::editConfig<StudioConfig>(m_ctx, [&](StudioConfig *config) {
if (!config->openFiles.contains((path))) {

View File

@ -30,6 +30,7 @@ class StudioUI: public ox::SignalHandler {
ProjectExplorer *m_projectExplorer = nullptr;
ox::Vector<ox::String> m_openFiles;
studio::Editor *m_acitveEditor = nullptr;
bool m_activeEditorUpdatePending = false;
bool m_saveEnabled = false;
bool m_aboutEnabled = false;
bool m_showProjectExplorer = true;