载入中...
搜索中...
未找到
UiThemePreview.cpp
浏览该文件的文档.
3
4#include "ui/Theme.h"
5
6namespace eve::ui_editing {
7namespace {
8
9EditorDiagnostic previewDiagnostic(const char* rule, std::string message) {
11 DiagnosticSeverity::Error, std::move(message));
12}
13
14} // namespace
15
17 Revision expectedRevision) const {
19 snapshot.documentRevision = catalog.revision();
20 snapshot.themeId = themeId;
21 if (expectedRevision != catalog.revision()) {
22 snapshot.status = EditorStatus::Conflict;
23 snapshot.diagnostics.push_back(
24 previewDiagnostic("editor.ui-theme.stale-preview", "Theme preview requires the current catalog revision"));
25 return snapshot;
26 }
27 auto asset = catalog.theme(themeId);
28 if (!asset.ok()) {
29 snapshot.status = EditorStatus::NotFound;
30 snapshot.diagnostics.insert(snapshot.diagnostics.end(), asset.status().diagnostics().begin(),
31 asset.status().diagnostics().end());
32 return snapshot;
33 }
34 snapshot.theme = asset.value().tokens;
35 snapshot.runtimeName = catalog.runtimeName(themeId);
36 snapshot.status = EditorStatus::Applied;
37 return snapshot;
38}
39
41 auto asset = catalog.theme(catalog.activeId());
42 if (!asset.ok()) return Result<void>::failure(asset.status());
43 auto diagnostics = validateThemeTokens(asset.value().tokens);
44 if (!diagnostics.empty())
45 return eve::editing::failed<void>(EditorStatus::Rejected, RuleId("editor.ui-theme.publish"),
46 "Active theme tokens are invalid");
47 ui::setGlobalTheme(asset.value().tokens, catalog.runtimeName(catalog.activeId()));
48 return eve::editing::applied<void>();
49}
50
51} // namespace eve::ui_editing
std::string message
Move-only operation result carrying either a value or Status.
Definition Result.h:155
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
std::uint64_t revision() const override
Return the current revision.
Serializable catalog of named UI themes with one active publication slot.
Definition UiTheme.h:60
std::string runtimeName(const ObjectId &id) const
Runtime name written to ui::globalThemeName(): dark, light, or custom.
Definition UiTheme.cpp:151
const ObjectId & activeId() const noexcept
Active publication id; empty only if the catalog failed to seed.
Definition UiTheme.h:93
Result< UiThemeAsset > theme(const ObjectId &id) const
Copy one named theme, or NotFound.
Definition UiTheme.cpp:143
UiThemePreviewSnapshot build(const UiThemeCatalogTarget &catalog, const ObjectId &themeId, Revision expectedRevision) const
Copy tokens for themeId when expectedRevision matches the catalog.
Result< void > publish(const UiThemeCatalogTarget &catalog) const
Replace the process global theme with the catalog's active asset.
Diagnostic ruleDiagnostic(eve::DiagnosticCode code, RuleId rule, DiagnosticSeverity severity, std::string message)
Build a common diagnostic carrying an open editing rule identity.
editing::Diagnostic EditorDiagnostic
Definition UiDocument.h:45
std::vector< EditorDiagnostic > validateThemeTokens(const ui::Theme &theme)
Validate theme tokens.
void setGlobalTheme(const Theme &theme)
Sets the global theme.
Definition Theme.cpp:281
Revision-bound Theme copy used by gallery hosts without mutating globalTheme.
Definition UiTheme.h:163
std::vector< EditorDiagnostic > diagnostics
Definition UiTheme.h:169