Files
pipelines/app/lib/features/chat/files/files_drag.dart
T
alan 4733d4b615 Rename, move and delete entries from the chat Files panel
Every row and tile menu gains Rename…, Move… and Delete… (folders now
have a menu too). Rename prefills the name with the file's stem selected
and applies the server's name rules inline. Move reuses the chat folder
picker through a FolderPickerPurpose: titled for the entry, confirmed
with Move here, never offering the entry's current folder and keeping a
moved folder's own subtree out of reach. Delete confirms, and when the
server reports a folder with contents asks once more before deleting
recursively. Holding an entry and dropping it on a folder row or tile
moves it there; the target highlights and refuses itself and ancestors.

FilesController performs each request through files_mutations.dart,
shows Renaming…/Moving…/Deleting… progress, reloads the shown folder
afterwards and keeps a refusal in the server's words in the panel's
notice until dismissed.
2026-11-09 01:46:28 +00:00

75 lines
2.4 KiB
Dart

import 'package:flutter/material.dart';
import '../data/directory_listing.dart';
import 'files_icons.dart';
import 'files_models.dart';
/// Moves [entry] into another listed folder by dragging it there: a press and
/// hold starts the drag (so a touch scroll stays a scroll), the folder row
/// under the pointer highlights, and releasing hands the pair to [onDrop].
///
/// Every entry is a drag source; a folder is also a target, unless the dragged
/// entry is itself or one of its ancestors ([canDropEntryOn]). The server
/// still refuses a same-named target, which the panel's notice then shows.
class FilesDraggableEntry extends StatelessWidget {
const FilesDraggableEntry({
super.key,
required this.entry,
required this.onDrop,
required this.builder,
});
final DirectoryEntry entry;
final void Function(DirectoryEntry dragged, DirectoryEntry folder) onDrop;
/// Builds the row or tile; [targeted] is true while an acceptable entry is
/// held over this folder.
final Widget Function(BuildContext context, bool targeted) builder;
@override
Widget build(BuildContext context) {
if (!entry.isDir) return _source(context, false);
return DragTarget<DirectoryEntry>(
onWillAcceptWithDetails: (details) => canDropEntryOn(details.data, entry),
onAcceptWithDetails: (details) => onDrop(details.data, entry),
builder: (context, candidates, _) =>
_source(context, candidates.isNotEmpty),
);
}
Widget _source(BuildContext context, bool targeted) =>
LongPressDraggable<DirectoryEntry>(
data: entry,
feedback: _DragFeedback(entry: entry),
childWhenDragging: Opacity(
opacity: .4,
child: builder(context, targeted),
),
child: builder(context, targeted),
);
}
/// What travels under the pointer: the entry's icon and name on a raised
/// surface, so it reads as the row being carried.
class _DragFeedback extends StatelessWidget {
const _DragFeedback({required this.entry});
final DirectoryEntry entry;
@override
Widget build(BuildContext context) => Material(
elevation: 4,
borderRadius: BorderRadius.circular(8),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(fileIcon(entry)),
const SizedBox(width: 8),
Text(entry.name),
],
),
),
);
}