new_editor: stabilize multi-window host lifecycle
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
#include "Composition/EditorWindowWorkspaceStore.h"
|
||||
|
||||
#include <XCEditor/Foundation/UIEditorRuntimeTrace.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
#include <utility>
|
||||
|
||||
namespace XCEngine::UI::Editor::App {
|
||||
@@ -39,6 +42,24 @@ void UpsertWindowState(
|
||||
windowSet.windows.push_back(std::move(windowState));
|
||||
}
|
||||
|
||||
std::string DescribeWindowSetState(const UIEditorWindowWorkspaceSet& windowSet) {
|
||||
std::ostringstream stream = {};
|
||||
stream << "primary='" << windowSet.primaryWindowId
|
||||
<< "' active='" << windowSet.activeWindowId
|
||||
<< "' count=" << windowSet.windows.size()
|
||||
<< " windows=[";
|
||||
bool first = true;
|
||||
for (const UIEditorWindowWorkspaceState& state : windowSet.windows) {
|
||||
if (!first) {
|
||||
stream << ',';
|
||||
}
|
||||
first = false;
|
||||
stream << state.windowId;
|
||||
}
|
||||
stream << ']';
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
EditorWindowWorkspaceStore::EditorWindowWorkspaceStore(UIEditorPanelRegistry panelRegistry)
|
||||
@@ -133,12 +154,24 @@ void EditorWindowWorkspaceStore::ReplaceWindowSet(UIEditorWindowWorkspaceSet win
|
||||
}
|
||||
|
||||
void EditorWindowWorkspaceStore::RemoveWindow(std::string_view windowId, bool primary) {
|
||||
const std::string beforeState = DescribeWindowSetState(m_windowSet);
|
||||
if (m_windowSet.windows.empty()) {
|
||||
AppendUIEditorRuntimeTrace(
|
||||
"window-close",
|
||||
"store remove skipped windowId='" + std::string(windowId) +
|
||||
"' primaryArg=" + (primary ? "1" : "0") +
|
||||
" stateBefore=" + beforeState);
|
||||
return;
|
||||
}
|
||||
|
||||
if (primary || m_windowSet.primaryWindowId == windowId) {
|
||||
m_windowSet = {};
|
||||
AppendUIEditorRuntimeTrace(
|
||||
"window-close",
|
||||
"store remove cleared all windows windowId='" + std::string(windowId) +
|
||||
"' primaryArg=" + (primary ? "1" : "0") +
|
||||
" stateBefore=" + beforeState +
|
||||
" stateAfter=" + DescribeWindowSetState(m_windowSet));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -164,6 +197,13 @@ void EditorWindowWorkspaceStore::RemoveWindow(std::string_view windowId, bool pr
|
||||
FindUIEditorWindowWorkspaceState(m_windowSet, m_windowSet.activeWindowId) == nullptr) {
|
||||
m_windowSet.activeWindowId = ResolveFallbackWindowId(m_windowSet);
|
||||
}
|
||||
|
||||
AppendUIEditorRuntimeTrace(
|
||||
"window-close",
|
||||
"store remove completed windowId='" + std::string(windowId) +
|
||||
"' primaryArg=" + (primary ? "1" : "0") +
|
||||
" stateBefore=" + beforeState +
|
||||
" stateAfter=" + DescribeWindowSetState(m_windowSet));
|
||||
}
|
||||
|
||||
} // namespace XCEngine::UI::Editor::App
|
||||
|
||||
Reference in New Issue
Block a user