import 'package:cutdex_sdk/editor.dart'; import 'package:cutdex_sdk/preview.dart'; import 'package:cutdex_sdk/timeline/model.dart'; import 'package:flutter/foundation.dart'; import 'property_edit_boundary.dart'; import '../../workspace/timeline_session.dart'; /// Owns the asynchronous edit boundary for one selected clip. class PropertyEditController extends ChangeNotifier { PropertyEditController({ required this.session, required this.sequence, required this.clip, required this.projectId, required this.timelineId, required this.operation, }); final EditorTimelineSession session; final SequenceId sequence; final ElementId clip; final String projectId, timelineId, operation; Object get identity => (session, sequence, clip, projectId, timelineId); late final _boundary = PropertyEditBoundary(session, sequence, clip); bool _disposed = false; bool _saving = false; bool _failed = false; bool get saving => _saving; bool get failed => _failed; @override void dispose() { _disposed = true; _boundary.dispose(); super.dispose(); } ClipParameterAnimation? get animation { final view = session.view(sequence); final query = view.version.kernelVersion.query(); final handle = query.elementById(clip); return handle == null ? null : ClipParameterAnimation( query.element(handle), view.playheadTick - query.absoluteStart(handle), ); } Future run( PreviewController? preview, void Function(EditorCommandService, int) action, { bool seek = false, }) async { if (_disposed || saving || !_boundary.canRun(preview)) return false; try { return await _boundary.run( preview, (target) { action(session.commands, target.tick); return true; }, operation: operation, seek: seek, started: () { _saving = true; _failed = false; notifyListeners(); }, ); } catch (_) { if (!_disposed) { _failed = true; notifyListeners(); } return false; } finally { if (!_disposed) { _saving = false; notifyListeners(); } } } }