Add the Flutter video editing application with project management, media import, timeline editing, preview, AI assistance, diagnostics and settings. Include shared UI and native host packages, platform runners, application tests and release tooling. Provide usage and contribution guides, the MIT license and third-party notices. Exclude local credentials, build outputs and validation data.
66 lines
1.9 KiB
Dart
66 lines
1.9 KiB
Dart
import 'dart:async';
|
|
import 'dart:convert';
|
|
|
|
import 'package:cutdex_sdk/editor.dart';
|
|
import 'package:cutdex_sdk/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();
|
|
}
|
|
}
|
|
}
|
|
}
|