feat: initial Cutdex application
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.
This commit is contained in:
commit
27e77fff39
718 files changed
+183958
No files matched your search
@@ -0,0 +1,84 @@
|
||||
import 'package:cutdex_sdk/project.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import '../../workspace/external_media_import.dart';
|
||||
import '../../workspace/media_import.dart';
|
||||
import '../../workspace/media_import_feedback.dart';
|
||||
import 'agent_media_attachments.dart';
|
||||
|
||||
/// Owns attachment operations for one conversation or draft, even while hidden.
|
||||
class AgentComposerController extends ChangeNotifier {
|
||||
AgentComposerController({
|
||||
required this.canImport,
|
||||
required this.pickFiles,
|
||||
required this.importMedia,
|
||||
List<AgentMediaAttachment>? attachments,
|
||||
}) : attachments = attachments ?? [];
|
||||
|
||||
final bool Function() canImport;
|
||||
final Future<List<ExternalMediaFile>> Function() pickFiles;
|
||||
final Future<ExternalMediaSelection?> Function(List<ExternalMediaFile>)
|
||||
importMedia;
|
||||
final List<AgentMediaAttachment> attachments;
|
||||
final feedback = MediaImportFeedbackController();
|
||||
bool _busy = false;
|
||||
bool _disposed = false;
|
||||
bool get busy => _busy;
|
||||
|
||||
void attach(AssetDocument asset) {
|
||||
if (_disposed || attachments.any((item) => item.id == asset.id)) return;
|
||||
attachments.add(AgentMediaAttachment.fromAsset(asset));
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void remove(String id) {
|
||||
attachments.removeWhere((item) => item.id == id);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void clear() {
|
||||
attachments.clear();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<ExternalMediaSelection?> pickAttachments() => _run(pickFiles);
|
||||
|
||||
Future<ExternalMediaSelection?> importAttachments(
|
||||
List<ExternalMediaFile> files,
|
||||
) => _run(() async => files);
|
||||
|
||||
Future<ExternalMediaSelection?> _run(
|
||||
Future<List<ExternalMediaFile>> Function() select,
|
||||
) async {
|
||||
if (_disposed || _busy || !canImport()) return null;
|
||||
_busy = true;
|
||||
notifyListeners();
|
||||
try {
|
||||
final files = await select();
|
||||
if (_disposed || files.isEmpty || !canImport()) return null;
|
||||
final result = await importMedia(files);
|
||||
// Deleting the conversation invalidates this destination. Hiding its
|
||||
// presentation does not, so completed imports still populate the draft.
|
||||
if (!_disposed) {
|
||||
for (final asset in result?.selected ?? <AssetDocument>[]) {
|
||||
attach(asset);
|
||||
}
|
||||
feedback.recordResult(result);
|
||||
}
|
||||
return result;
|
||||
} catch (_) {
|
||||
if (!_disposed) feedback.recordFailure();
|
||||
rethrow;
|
||||
} finally {
|
||||
_busy = false;
|
||||
if (!_disposed) notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_disposed = true;
|
||||
feedback.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user