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.
63 lines
2.1 KiB
Dart
63 lines
2.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../data/directory_listing.dart';
|
|
import '../ui/folder_picker/folder_picker_purpose.dart';
|
|
import '../ui/folder_picker/folder_picker_route.dart';
|
|
import 'files_controller.dart';
|
|
import 'files_delete_dialog.dart';
|
|
import 'files_mutations.dart';
|
|
import 'files_rename_dialog.dart';
|
|
|
|
/// The Files panel's Rename…, Move… and Delete… flows: each asks, then hands
|
|
/// the confirmed request to the controller, which performs it, reloads the
|
|
/// folder and keeps any refusal for the panel's notice.
|
|
Future<void> renameEntry(
|
|
BuildContext context,
|
|
FilesController controller,
|
|
DirectoryEntry entry,
|
|
) async {
|
|
final name = await showRenameEntryDialog(context, entry);
|
|
if (name == null) return;
|
|
await controller.rename(entry, name);
|
|
}
|
|
|
|
String _moveTo(String folder) => 'Move to $folder';
|
|
|
|
/// Browses folders from the shown one. A folder cannot be moved into itself or
|
|
/// below, and nothing is offered the folder it is already in.
|
|
Future<void> moveEntry(
|
|
BuildContext context,
|
|
FilesController controller,
|
|
DirectoryEntry entry,
|
|
) async {
|
|
final into = await showFolderPicker(
|
|
context,
|
|
gateway: controller.gateway,
|
|
initialPath: controller.listing?.path,
|
|
purpose: FolderPickerPurpose(
|
|
title: 'Move “${entry.name}”',
|
|
confirmLabel: 'Move here',
|
|
describe: _moveTo,
|
|
icon: Icons.drive_file_move_outline,
|
|
excludedPath: entry.isDir ? entry.path : null,
|
|
unchoosablePath: controller.listing?.path,
|
|
),
|
|
);
|
|
if (into == null) return;
|
|
await controller.move(entry, into);
|
|
}
|
|
|
|
/// Confirms, deletes, and when the server reports a folder with contents asks
|
|
/// once more before deleting recursively.
|
|
Future<void> deleteEntry(
|
|
BuildContext context,
|
|
FilesController controller,
|
|
DirectoryEntry entry,
|
|
) async {
|
|
if (!await confirmDeleteEntry(context, entry)) return;
|
|
final result = await controller.delete(entry);
|
|
if (result != FilesDeleteResult.notEmpty || !context.mounted) return;
|
|
if (!await confirmDeleteRecursive(context, entry)) return;
|
|
await controller.delete(entry, recursive: true);
|
|
}
|