feat(workspace): refresh desktop editing experience and prepare 0.1.2
Gitea CI / Build Android APK (pull_request) Canceled after 0s
Gitea CI / Build Windows x64 app (pull_request) Canceled after 0s
Gitea CI / Audit and package Windows x64 (pull_request) Canceled after 0s
Gitea CI / Assemble and validate CI artifacts (pull_request) Canceled after 0s
Gitea CI / Gitea CI passed (pull_request) Canceled after 0s
Gitea CI / Check code and tests (pull_request) Canceled after 6m29s
Gitea CI / Build Android APK (pull_request) Canceled after 0s
Gitea CI / Build Windows x64 app (pull_request) Canceled after 0s
Gitea CI / Audit and package Windows x64 (pull_request) Canceled after 0s
Gitea CI / Assemble and validate CI artifacts (pull_request) Canceled after 0s
Gitea CI / Gitea CI passed (pull_request) Canceled after 0s
Gitea CI / Check code and tests (pull_request) Canceled after 6m29s
This commit is contained in:
1 parent
aa5255d1e4
commit
2e0033ce2d
260 files changed
+43963
-5591
No files matched your search
@@ -0,0 +1,127 @@
|
||||
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,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user