Gitea CI / Check code and tests (push) Successful in 6m37s
Gitea CI / Build Windows x64 app (push) Successful in 3m18s
Gitea CI / Build Android APK (push) Successful in 3m47s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m7s
Gitea CI / Assemble and validate CI artifacts (push) Successful in 50s
Gitea CI / Gitea CI passed (push) Successful in 2s
Gitea Release / Prepare draft Release (push) Successful in 9s
Gitea Release / Upload Android to draft Release (push) Successful in 16s
Gitea Release / Upload Windows to draft Release (push) Successful in 22s
Gitea Release / Verify and publish Release (push) Successful in 14s
128 lines
4.3 KiB
Dart
128 lines
4.3 KiB
Dart
import 'package:flutter/widgets.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import '../../integrations/platform/platform_capabilities.dart';
|
|
import '../../integrations/platform/native_project_drop_region.dart';
|
|
import '../../integrations/platform/native_file_drop_policy.dart';
|
|
import '../../workspace/projects.dart';
|
|
import '../../workspace/media_import.dart';
|
|
import '../../workspace/external_media_import.dart';
|
|
import '../../shared/widgets/drop_to_add_overlay.dart';
|
|
import '../media/media_asset_drag.dart';
|
|
import 'agent_composer_controller.dart';
|
|
|
|
/// Shared attachment drop handling for docked and floating chat presentations.
|
|
class AgentAttachmentDropRegion extends ConsumerStatefulWidget {
|
|
const AgentAttachmentDropRegion({
|
|
super.key,
|
|
required this.projectId,
|
|
required this.composer,
|
|
required this.child,
|
|
this.shrinkWrap = false,
|
|
});
|
|
final String? projectId;
|
|
final AgentComposerController composer;
|
|
final Widget child;
|
|
final bool shrinkWrap;
|
|
@override
|
|
ConsumerState<AgentAttachmentDropRegion> createState() =>
|
|
_AgentAttachmentDropRegionState();
|
|
}
|
|
|
|
class _AgentAttachmentDropRegionState
|
|
extends ConsumerState<AgentAttachmentDropRegion> {
|
|
bool _hovering = false;
|
|
bool _canAttach(MediaAssetDrag drag) {
|
|
final workspace = ref.read(projectsProvider).value;
|
|
return widget.projectId == drag.projectId &&
|
|
workspace?.activeProject?.id == drag.projectId &&
|
|
!widget.composer.attachments.any((item) => item.id == drag.assetId) &&
|
|
workspace!.assets.any((asset) => asset.id == drag.assetId);
|
|
}
|
|
|
|
bool _canAttachFiles(List<ExternalMediaFile> files) {
|
|
if (files.isEmpty) return true;
|
|
final assets = ref.read(projectsProvider).value?.assets;
|
|
if (assets == null) return false;
|
|
final ids = {for (final item in widget.composer.attachments) item.id};
|
|
final locations = {
|
|
for (final asset in assets)
|
|
if (ids.contains(asset.id)) ?mediaSourceLocation(asset),
|
|
};
|
|
return files.any((file) => !locations.contains(file.sourceUri.toString()));
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final workspace = ref.watch(
|
|
projectsProvider.select(
|
|
(value) => value.value?.copyWith(
|
|
recent: const [],
|
|
timelines: const [],
|
|
error: null,
|
|
creatingTimeline: false,
|
|
),
|
|
),
|
|
);
|
|
final native = ref.watch(platformCapabilitiesProvider).nativeFileDrop;
|
|
final importing =
|
|
widget.composer.busy ||
|
|
widget.projectId != null &&
|
|
ref.watch(
|
|
externalMediaImportProvider(widget.projectId!)
|
|
.select((value) => value.isLoading),
|
|
);
|
|
final internal = DragTarget<MediaAssetDrag>(
|
|
key: const Key('agent-panel-drop-target'),
|
|
onWillAcceptWithDetails: (details) => _canAttach(details.data),
|
|
onAcceptWithDetails: (details) {
|
|
if (_canAttach(details.data)) {
|
|
widget.composer.attach(
|
|
ref
|
|
.read(projectsProvider)
|
|
.value!
|
|
.assets
|
|
.firstWhere((asset) => asset.id == details.data.assetId),
|
|
);
|
|
}
|
|
},
|
|
builder: (context, candidates, _) => Stack(
|
|
fit: widget.shrinkWrap ? StackFit.loose : StackFit.expand,
|
|
children: [
|
|
widget.child,
|
|
if (candidates.isNotEmpty || _hovering)
|
|
const Positioned.fill(
|
|
child: DropToAddOverlay(key: Key('agent-drop-overlay')),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
if (!native) return internal;
|
|
return NativeProjectDropRegion(
|
|
regionId: 'attachments',
|
|
policy: NativeFileDropPolicy.attachments,
|
|
enabled:
|
|
widget.projectId != null &&
|
|
workspace?.activeProject?.id == widget.projectId &&
|
|
(workspace?.projectBusy == false || importing),
|
|
onEnter: (files) {
|
|
if (!importing && _canAttachFiles(files)) {
|
|
setState(() => _hovering = true);
|
|
}
|
|
},
|
|
onExit: () {
|
|
if (mounted && _hovering) setState(() => _hovering = false);
|
|
},
|
|
onDrop: (files) async {
|
|
setState(() => _hovering = false);
|
|
try {
|
|
await widget.composer.importAttachments(files);
|
|
} catch (_) {
|
|
/* Shared composer publishes import feedback. */
|
|
}
|
|
},
|
|
child: internal,
|
|
);
|
|
}
|
|
}
|