4733d4b615
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.
104 lines
3.2 KiB
Dart
104 lines
3.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../data/directory_listing.dart';
|
|
import 'files_drag.dart';
|
|
import 'files_icons.dart';
|
|
import 'files_models.dart';
|
|
import 'files_thumbnail.dart';
|
|
|
|
/// The folder's entries as the list or the thumbnail grid. Tapping opens a
|
|
/// folder or a file through [onTap]; [menu] supplies every entry's action
|
|
/// menu; holding and dragging an entry onto a folder row calls [onDrop].
|
|
class FilesEntries extends StatelessWidget {
|
|
const FilesEntries({
|
|
super.key,
|
|
required this.entries,
|
|
required this.view,
|
|
required this.endpoint,
|
|
required this.onTap,
|
|
required this.menu,
|
|
required this.onDrop,
|
|
});
|
|
final List<DirectoryEntry> entries;
|
|
final FilesViewMode view;
|
|
final String endpoint;
|
|
final ValueChanged<DirectoryEntry> onTap;
|
|
final Widget Function(DirectoryEntry entry) menu;
|
|
final void Function(DirectoryEntry dragged, DirectoryEntry folder) onDrop;
|
|
|
|
@override
|
|
Widget build(BuildContext context) =>
|
|
view == FilesViewMode.grid ? _grid() : _list();
|
|
|
|
Widget _list() => ListView.builder(
|
|
itemCount: entries.length,
|
|
itemBuilder: (_, index) {
|
|
final entry = entries[index];
|
|
return FilesDraggableEntry(
|
|
entry: entry,
|
|
onDrop: onDrop,
|
|
builder: (context, targeted) => ListTile(
|
|
selected: targeted,
|
|
selectedTileColor: Theme.of(context).colorScheme.primaryContainer,
|
|
onTap: () => onTap(entry),
|
|
leading: Icon(fileIcon(entry)),
|
|
title: Text(entry.name, maxLines: 2, overflow: TextOverflow.ellipsis),
|
|
subtitle: Text(
|
|
entry.isDir
|
|
? 'Folder'
|
|
: '${fileModifiedLabel(entry.modified)} · ${fileSizeLabel(entry.size)}',
|
|
),
|
|
trailing: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [if (!entry.isDir) Text(fileKind(entry)), menu(entry)],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
|
|
Widget _grid() => GridView.builder(
|
|
padding: const EdgeInsets.all(12),
|
|
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
|
|
maxCrossAxisExtent: 180,
|
|
childAspectRatio: .85,
|
|
),
|
|
itemCount: entries.length,
|
|
itemBuilder: (_, index) {
|
|
final entry = entries[index];
|
|
return FilesDraggableEntry(
|
|
entry: entry,
|
|
onDrop: onDrop,
|
|
builder: (context, targeted) => InkWell(
|
|
onTap: () => onTap(entry),
|
|
child: Card(
|
|
color: targeted
|
|
? Theme.of(context).colorScheme.primaryContainer
|
|
: null,
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(12),
|
|
child: Column(
|
|
children: [
|
|
Align(alignment: Alignment.centerRight, child: menu(entry)),
|
|
Expanded(
|
|
child: Center(
|
|
child: FileThumbnail(entry: entry, endpoint: endpoint),
|
|
),
|
|
),
|
|
const SizedBox(height: 8),
|
|
Text(
|
|
entry.name,
|
|
maxLines: 2,
|
|
overflow: TextOverflow.ellipsis,
|
|
textAlign: TextAlign.center,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|