Refactor editor windowing boundaries
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "Composition/EditorWindowWorkspaceStore.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
|
||||
namespace XCEngine::UI::Editor::App {
|
||||
@@ -21,4 +22,86 @@ bool EditorWindowWorkspaceStore::ValidateWindowSet(
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EditorWindowWorkspaceStore::TrySetWindowSet(
|
||||
UIEditorWindowWorkspaceSet windowSet,
|
||||
std::string& outError) {
|
||||
if (!ValidateWindowSet(windowSet, outError)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_windowSet = std::move(windowSet);
|
||||
outError.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EditorWindowWorkspaceStore::UpsertWindowState(
|
||||
const UIEditorWindowWorkspaceState& windowState,
|
||||
bool primary,
|
||||
std::string& outError) {
|
||||
UIEditorWindowWorkspaceSet nextWindowSet = m_windowSet;
|
||||
if (UIEditorWindowWorkspaceState* existingState =
|
||||
FindMutableUIEditorWindowWorkspaceState(nextWindowSet, windowState.windowId);
|
||||
existingState != nullptr) {
|
||||
*existingState = windowState;
|
||||
} else {
|
||||
nextWindowSet.windows.push_back(windowState);
|
||||
}
|
||||
|
||||
if (primary || nextWindowSet.primaryWindowId.empty()) {
|
||||
nextWindowSet.primaryWindowId = windowState.windowId;
|
||||
}
|
||||
if (nextWindowSet.activeWindowId.empty() ||
|
||||
FindUIEditorWindowWorkspaceState(nextWindowSet, nextWindowSet.activeWindowId) == nullptr) {
|
||||
nextWindowSet.activeWindowId = windowState.windowId;
|
||||
}
|
||||
|
||||
if (!ValidateWindowSet(nextWindowSet, outError)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_windowSet = std::move(nextWindowSet);
|
||||
outError.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
void EditorWindowWorkspaceStore::RemoveWindowState(std::string_view windowId, bool primary) {
|
||||
if (primary) {
|
||||
m_windowSet = {};
|
||||
return;
|
||||
}
|
||||
|
||||
UIEditorWindowWorkspaceSet nextWindowSet = m_windowSet;
|
||||
nextWindowSet.windows.erase(
|
||||
std::remove_if(
|
||||
nextWindowSet.windows.begin(),
|
||||
nextWindowSet.windows.end(),
|
||||
[windowId](const UIEditorWindowWorkspaceState& state) {
|
||||
return state.windowId == windowId;
|
||||
}),
|
||||
nextWindowSet.windows.end());
|
||||
|
||||
if (nextWindowSet.windows.empty()) {
|
||||
m_windowSet = {};
|
||||
return;
|
||||
}
|
||||
|
||||
if (nextWindowSet.primaryWindowId == windowId ||
|
||||
FindUIEditorWindowWorkspaceState(nextWindowSet, nextWindowSet.primaryWindowId) == nullptr) {
|
||||
nextWindowSet.primaryWindowId = nextWindowSet.windows.front().windowId;
|
||||
}
|
||||
if (nextWindowSet.activeWindowId == windowId ||
|
||||
FindUIEditorWindowWorkspaceState(nextWindowSet, nextWindowSet.activeWindowId) == nullptr) {
|
||||
nextWindowSet.activeWindowId = nextWindowSet.primaryWindowId;
|
||||
}
|
||||
|
||||
std::string ignoredError = {};
|
||||
if (ValidateWindowSet(nextWindowSet, ignoredError)) {
|
||||
m_windowSet = std::move(nextWindowSet);
|
||||
}
|
||||
}
|
||||
|
||||
bool EditorWindowWorkspaceStore::IsPrimaryWindowId(std::string_view windowId) const {
|
||||
return !windowId.empty() && m_windowSet.primaryWindowId == windowId;
|
||||
}
|
||||
|
||||
} // namespace XCEngine::UI::Editor::App
|
||||
|
||||
Reference in New Issue
Block a user