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.
79 lines
2.5 KiB
Dart
79 lines
2.5 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../data/directory_listing.dart';
|
|
import '../ui/sessions/chat_adaptive.dart';
|
|
|
|
/// Confirms deleting [entry]. A folder is described as deleted only when
|
|
/// empty; the server refuses a folder with contents and the panel then asks
|
|
/// again with [confirmDeleteRecursive].
|
|
Future<bool> confirmDeleteEntry(BuildContext context, DirectoryEntry entry) =>
|
|
_confirm(
|
|
context,
|
|
title: 'Delete “${entry.name}”?',
|
|
body: entry.isDir
|
|
? 'The folder is removed from the server if it is empty. '
|
|
'This cannot be undone.'
|
|
: 'The file is removed from the server. This cannot be undone.',
|
|
action: 'Delete',
|
|
);
|
|
|
|
/// Asks again once the server reported the folder is not empty; confirming
|
|
/// deletes the folder and everything inside it.
|
|
Future<bool> confirmDeleteRecursive(
|
|
BuildContext context,
|
|
DirectoryEntry entry,
|
|
) => _confirm(
|
|
context,
|
|
title: 'Delete “${entry.name}” and its contents?',
|
|
body:
|
|
'“${entry.name}” is not empty. Delete the folder and everything '
|
|
'inside it? This cannot be undone.',
|
|
action: 'Delete all',
|
|
);
|
|
|
|
Future<bool> _confirm(
|
|
BuildContext context, {
|
|
required String title,
|
|
required String body,
|
|
required String action,
|
|
}) async {
|
|
final confirmed = chatControlsStyleOf(context) == ChatControlsStyle.cupertino
|
|
? await showCupertinoDialog<bool>(
|
|
context: context,
|
|
builder: (context) => CupertinoAlertDialog(
|
|
title: Text(title),
|
|
content: Text(body),
|
|
actions: [
|
|
CupertinoDialogAction(
|
|
onPressed: () => Navigator.pop(context, false),
|
|
child: const Text('Cancel'),
|
|
),
|
|
CupertinoDialogAction(
|
|
isDestructiveAction: true,
|
|
onPressed: () => Navigator.pop(context, true),
|
|
child: Text(action),
|
|
),
|
|
],
|
|
),
|
|
)
|
|
: await showDialog<bool>(
|
|
context: context,
|
|
builder: (context) => AlertDialog(
|
|
title: Text(title),
|
|
content: Text(body),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context, false),
|
|
child: const Text('Cancel'),
|
|
),
|
|
FilledButton(
|
|
onPressed: () => Navigator.pop(context, true),
|
|
child: Text(action),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
return confirmed == true;
|
|
}
|