Gitea CI / Check code and tests (pull_request) Failing after 8s
Gitea CI / Build Android APK (pull_request) Skipped
Gitea CI / Build Windows x64 app (pull_request) Skipped
Gitea CI / Audit and package Windows x64 (pull_request) Skipped
Gitea CI / Assemble and validate CI artifacts (pull_request) Skipped
Gitea CI / Gitea CI passed (pull_request) Failing after 1s
66 lines
1.9 KiB
Dart
66 lines
1.9 KiB
Dart
import 'dart:async';
|
|
import 'dart:convert';
|
|
|
|
import 'package:cutdex_core/editor.dart';
|
|
import 'package:cutdex_core/tools.dart';
|
|
|
|
import 'editor_command_host.dart';
|
|
|
|
/// Owns the mutable workspace/dispatcher lifecycle without knowing any protocol.
|
|
class EditorToolRegistry {
|
|
EditorToolRegistry(EditorSession session)
|
|
: owner = session,
|
|
_session = session,
|
|
dynamicWorkspaces = false,
|
|
workspaces = Map.unmodifiable({
|
|
for (final sequence in session.document.sequences)
|
|
jsonEncode([session.document.id, sequence.id.value]): editorToolsFor(
|
|
session,
|
|
sequence.id,
|
|
),
|
|
});
|
|
|
|
EditorToolRegistry.application(EditorCommandHost host)
|
|
: owner = Object(),
|
|
dynamicWorkspaces = true,
|
|
workspaces = {'application': EditorToolDispatcher(host: host)};
|
|
|
|
final bool dynamicWorkspaces;
|
|
final Object owner;
|
|
final Map<String, EditorToolDispatcher> workspaces;
|
|
EditorSession? _session;
|
|
int _generation = 0;
|
|
|
|
void attach(EditorSession? session, {String? projectId}) {
|
|
if (!dynamicWorkspaces || identical(_session, session)) return;
|
|
for (final id
|
|
in workspaces.keys.where((id) => id != 'application').toList()) {
|
|
unawaited(releaseEditorTools(_session!, workspaces.remove(id)!));
|
|
}
|
|
_session = session;
|
|
if (session == null) return;
|
|
final generation = ++_generation;
|
|
for (final sequence in session.document.sequences) {
|
|
workspaces[jsonEncode([
|
|
projectId,
|
|
session.document.id,
|
|
sequence.id.value,
|
|
generation,
|
|
])] = editorToolsFor(
|
|
session,
|
|
sequence.id,
|
|
);
|
|
}
|
|
}
|
|
|
|
Future<void> dispose() async {
|
|
for (final entry in workspaces.entries.toList()) {
|
|
if (_session != null && entry.key != 'application') {
|
|
await releaseEditorTools(_session!, entry.value);
|
|
} else {
|
|
await entry.value.dispose();
|
|
}
|
|
}
|
|
}
|
|
}
|