checkpoint: commit current workspace state
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace XCEngine::UI::Editor::App {
|
||||
|
||||
struct WindowWorkspaceTransferRequest {
|
||||
enum class Type : std::uint8_t {
|
||||
None = 0,
|
||||
StartGlobalTabDrag,
|
||||
DetachPanel,
|
||||
};
|
||||
|
||||
Type type = Type::None;
|
||||
std::string sourceWindowId = {};
|
||||
std::string sourceNodeId = {};
|
||||
std::string panelId = {};
|
||||
std::int32_t screenX = 0;
|
||||
std::int32_t screenY = 0;
|
||||
bool hasScreenPoint = false;
|
||||
|
||||
bool IsValid() const {
|
||||
return type != Type::None &&
|
||||
!sourceWindowId.empty() &&
|
||||
!sourceNodeId.empty() &&
|
||||
!panelId.empty() &&
|
||||
hasScreenPoint;
|
||||
}
|
||||
};
|
||||
|
||||
class WindowWorkspaceTransferQueue final {
|
||||
public:
|
||||
|
||||
void QueueWorkspaceTransferRequest(const WindowWorkspaceTransferRequest& request) {
|
||||
if (!request.IsValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto it = std::find_if(
|
||||
m_pendingWorkspaceTransferRequests.begin(),
|
||||
m_pendingWorkspaceTransferRequests.end(),
|
||||
[&request](const WindowWorkspaceTransferRequest& current) {
|
||||
return current.type == request.type &&
|
||||
current.sourceWindowId == request.sourceWindowId &&
|
||||
current.sourceNodeId == request.sourceNodeId &&
|
||||
current.panelId == request.panelId;
|
||||
});
|
||||
if (it == m_pendingWorkspaceTransferRequests.end()) {
|
||||
m_pendingWorkspaceTransferRequests.push_back(request);
|
||||
} else {
|
||||
*it = request;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<WindowWorkspaceTransferRequest> ConsumePendingWorkspaceTransferRequests() {
|
||||
std::vector<WindowWorkspaceTransferRequest> requests =
|
||||
std::move(m_pendingWorkspaceTransferRequests);
|
||||
m_pendingWorkspaceTransferRequests.clear();
|
||||
return requests;
|
||||
}
|
||||
|
||||
void RemoveWindow(std::string_view windowId) {
|
||||
if (windowId.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::erase_if(
|
||||
m_pendingWorkspaceTransferRequests,
|
||||
[windowId](const WindowWorkspaceTransferRequest& current) {
|
||||
return current.sourceWindowId == windowId;
|
||||
});
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<WindowWorkspaceTransferRequest> m_pendingWorkspaceTransferRequests = {};
|
||||
};
|
||||
|
||||
} // namespace XCEngine::UI::Editor::App
|
||||
|
||||
|
||||
Reference in New Issue
Block a user