载入中...
搜索中...
未找到
EditorSession.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
8#include "editor/EditorTool.h"
10
11#include <cstdint>
12#include <optional>
13#include <string>
14#include <utility>
15#include <vector>
16
17namespace eve::editor {
18
19class AutosaveService;
20class EditorTargetCoordinator;
21
31public:
35 ~EditorSession() noexcept;
36
37 EditorSession(const EditorSession&) = delete;
39
41 bool addTool(IEditorTool* tool);
43 bool removeTool(const std::string& id);
45 void clearTools();
46
48 int getToolCount() const;
50 IEditorTool* getTool(int index) const;
52 IEditorTool* findTool(const std::string& id) const;
53
55 bool activateTool(const std::string& id);
57 IEditorTool* activeTool() const { return activeTool_; }
59 std::string activeToolId() const;
60
62 ToolResponse dispatchPointer(const EditorPointerEvent& event);
64 ToolResponse dispatchKey(const EditorKeyEvent& event);
66 void update(float dt);
68 void drawOverlay(IEditorOverlay& overlay);
70 void inspect(IEditorInspector& inspector);
72 void cancelActiveTool();
73
75 bool hasPointerCapture() const { return capturedPointerId_ >= 0; }
77 int capturedPointerId() const { return capturedPointerId_; }
79 EditorContext& context() { return context_; }
81 const EditorContext& context() const { return context_; }
87 void bindTarget(IEditableTarget& target);
89 void bindTarget(IEditableTarget* target);
91 void clearTarget();
93 IEditableTarget* target() const;
95 const TargetId& boundTargetId() const noexcept { return boundTargetId_; }
97 EditorTransactions& transactions() { return transactions_; }
99 EditConstraintPipeline& constraints() { return constraints_; }
101 bool execute(std::unique_ptr<IEditCommand> command);
103 [[nodiscard]] Result<void> executeChecked(std::unique_ptr<IEditCommand> command);
104
108 void clearCommandService() { commandService_ = nullptr; }
112 EditorCommandService* commandService() const { return commandService_; }
114 void setHostProfile(HostProfile profile) { hostProfile_ = std::move(profile); }
116 const HostProfile& hostProfile() const { return hostProfile_; }
118 void setSessionId(SessionId id) { sessionId_ = std::move(id); }
120 const SessionId& sessionId() const { return sessionId_; }
122 EditorContextSnapshot contextSnapshot() const;
132 Result<EditorValue> executeCommand(const CommandId& id, const EditorValue& payload = {},
133 CommandSource source = CommandSource::Api);
135 Result<CommandPlan> planCommand(const CommandId& id, const EditorValue& payload = {},
136 CommandSource source = CommandSource::Api,
137 std::optional<Revision> expectedRevision = std::nullopt) const;
139 Result<TransactionReceipt> executePlan(const CommandPlan& plan, const EditorValue& payload = {},
140 CommandSource source = CommandSource::Api);
142 Result<TransactionReceipt> executeCommandReceipt(const CommandId& id, const EditorValue& payload = {},
143 CommandSource source = CommandSource::Api);
145 std::vector<CommandDescriptor> availableCommands() const;
151 Result<PlanId> retainPlan(const CommandId& id, const EditorValue& payload = {},
152 CommandSource source = CommandSource::Api,
153 std::optional<Revision> expectedRevision = std::nullopt);
155 Result<TransactionReceipt> executeRetainedPlan(const PlanId& id, CommandSource source = CommandSource::Api);
157 Result<void> cancelRetainedPlan(const PlanId& id);
159 void clearRetainedPlans();
160
166 void setDocumentServices(DocumentService* documents, AutosaveService* autosave = nullptr);
168 void bindDocumentServices(DocumentService& documents, AutosaveService* autosave = nullptr);
170 void clearDocumentServices();
176 Result<DocumentSnapshot> bindDocument(const DocumentId& document);
178 void unbindDocument();
180 const DocumentId& activeDocument() const { return activeDocument_; }
187 Result<DocumentSnapshot> editDocument(EditorValue content,
188 std::optional<Revision> expectedRevision = std::nullopt);
190 Result<DocumentSnapshot> saveDocument();
192 Result<StoredDocument> autosaveDocument();
194 Result<DocumentSnapshot> pollDocumentChanges();
196 void setAutosaveInterval(float seconds);
198 void setExternalPollInterval(float seconds);
200 Revision lastAutosavedRevision() const { return lastAutosavedRevision_; }
201
202private:
204 void bindTrackedTarget(IEditableTarget& target, std::weak_ptr<void> lifetime, EditorTargetCoordinator& coordinator,
205 std::uint64_t generation);
206 void invalidateTrackedTarget(EditorTargetCoordinator& coordinator, const TargetId& target,
207 std::uint64_t generation);
208 void coordinatorDestroyed(EditorTargetCoordinator& coordinator) noexcept;
209 void releaseTargetBinding();
210 void deactivateCurrent();
211
212 std::vector<IEditorTool*> tools_;
213 IEditorTool* activeTool_ = nullptr;
214 int capturedPointerId_ = -1;
215 EditorContext context_;
216 IEditableTarget* target_ = nullptr;
217 std::weak_ptr<void> targetLifetime_;
218 bool targetLifetimeTracked_ = false;
219 TargetId boundTargetId_;
220 std::uint64_t targetGeneration_ = 0;
221 std::uint64_t nextDirectTargetGeneration_ = 1;
222 EditorTargetCoordinator* targetCoordinator_ = nullptr;
223 EditorTransactions transactions_;
224 EditConstraintPipeline constraints_;
225 EditorCommandService* commandService_ = nullptr;
226 HostProfile hostProfile_ = HostProfile::developer();
227 SessionId sessionId_;
228 std::uint64_t receiptSequence_ = 0;
229 std::uint64_t toolGeneration_ = 0;
230 struct RetainedPlan {
231 CommandPlan plan;
233 };
234 std::vector<RetainedPlan> retainedPlans_;
235 DocumentService* documentService_ = nullptr;
236 AutosaveService* autosaveService_ = nullptr;
237 DocumentId activeDocument_;
238 float autosaveInterval_ = 30.f;
239 float autosaveElapsed_ = 0.f;
240 float externalPollInterval_ = 1.f;
241 float externalPollElapsed_ = 0.f;
242 Revision lastAutosavedRevision_ = 0;
243};
244
245} // namespace eve::editor
LogicalId target
Value::Object payload
void * service
#define EVENGINE_API_ORCHESTRATION
Definition Export.h:111
std::weak_ptr< const void > lifetime
std::uint32_t generation
uint32_t index
const UnitySourceAsset & source
Move-only operation result carrying either a value or Status.
Definition Result.h:155
UUID-backed identifier adapter for legacy textual boundaries.
Definition Identity.h:314
Id128 public API.
Definition Identity.h:112
IEditableTarget public API.
Deterministic owning value tree shared by authoring hosts.
Autosave coordinator that never overwrites the formal document URI.
Document coordinator with revision-safe requestSave/executeSave sequencing.
Ordered, non-owning constraint chain with diagnostics.
Registry and execution gate for UI-, script- and automation-neutral commands.
Context supplied by EditorSession to tools.
Definition EditorTool.h:71
Hosts interchangeable editor tools and routes their lifecycle/input.
const DocumentId & activeDocument() const
Return the active document identity, or an empty id.
bool hasPointerCapture() const
True when pointer capture.
const HostProfile & hostProfile() const
Return the current host capability boundary.
int capturedPointerId() const
Captured pointer id.
void bindCommandService(EditorCommandService &service)
Bind a non-owning V2 command service that must outlive this binding.
EditorSession(const EditorSession &)=delete
void setCommandService(EditorCommandService *service)
Compatibility-only nullable pointer facade over bindCommandService() and clearCommandService().
IEditorTool * activeTool() const
Active tool.
const EditorContext & context() const
Context.
EditorSession & operator=(const EditorSession &)=delete
EditConstraintPipeline & constraints()
Constraints.
EditorTransactions & transactions()
Transactions.
void setSessionId(SessionId id)
Assign the stable identity included in asynchronous context snapshots.
void setHostProfile(HostProfile profile)
Set the host capability boundary used for command discovery and execution.
Revision lastAutosavedRevision() const
Last edit revision successfully written to the draft store.
const SessionId & sessionId() const
Return the stable session identity.
const TargetId & boundTargetId() const noexcept
Return the identity of the current binding without dereferencing the target.
void clearCommandService()
Clear the V2 command service binding.
EditorContext & context()
Context.
EditorCommandService * commandService() const
Return the bound V2 command service, or nullptr.
Coordinates editable targets, per-target histories and domain commands.
Executes, groups, rolls back and replays arbitrary edit commands.
Upper capability boundary for one editor host.
UI-independent property editor used by tools to expose settings.
Sink implemented by a 2D or 3D viewport to render tool feedback.
Protocol implemented by every editor tool.
Definition EditorTool.h:110
CommandSource
Source that initiated an authoring command.
eve::editing::Revision Revision
CommandPlan public API.
ContextSnapshot public API.
Keyboard input normalized by the editor host.
Definition EditorTool.h:40
Pointer input normalized by an editor viewport adapter.
Definition EditorTool.h:20
Result returned by a tool after processing input.
Definition EditorTool.h:50