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.
This commit is contained in:
@@ -2,6 +2,7 @@ import 'package:flutter/foundation.dart';
|
||||
|
||||
import '../../../../core/api_gateway.dart';
|
||||
import '../../data/directory_listing.dart';
|
||||
import 'folder_picker_purpose.dart';
|
||||
|
||||
/// The folder picker's state: the last listing, the folder being loaded, an
|
||||
/// inline error, the hidden toggle and the filter. Listing goes through the
|
||||
@@ -11,6 +12,7 @@ class FolderPickerController extends ChangeNotifier {
|
||||
required this.gateway,
|
||||
this.initialPath,
|
||||
this.recentFolders = const [],
|
||||
this.purpose = FolderPickerPurpose.startChat,
|
||||
});
|
||||
|
||||
final ApiGateway gateway;
|
||||
@@ -19,6 +21,9 @@ class FolderPickerController extends ChangeNotifier {
|
||||
/// Every recent chat folder the server reported; [recents] filters them.
|
||||
final List<String> recentFolders;
|
||||
|
||||
/// Which folders may be chosen or entered.
|
||||
final FolderPickerPurpose purpose;
|
||||
|
||||
DirectoryListing? _listing;
|
||||
String? _error;
|
||||
String? _failedPath;
|
||||
@@ -37,8 +42,18 @@ class FolderPickerController extends ChangeNotifier {
|
||||
/// The home directory once any listing has arrived.
|
||||
String? get home => _listing?.home;
|
||||
|
||||
/// The folder "Start chat here" would use: only a successfully listed one.
|
||||
String? get selectable => _loading || _error != null ? null : _listing?.path;
|
||||
/// The folder the confirm button would use: only a successfully listed one
|
||||
/// that the purpose offers.
|
||||
String? get selectable {
|
||||
final path = _listing?.path;
|
||||
if (_loading || _error != null || path == null) return null;
|
||||
return purpose.offers(path) ? path : null;
|
||||
}
|
||||
|
||||
/// Whether a listed folder may be entered; the purpose's excluded subtree
|
||||
/// (a folder being moved) may not.
|
||||
bool canEnter(DirectoryEntry entry) =>
|
||||
entry.isDir && !purpose.excludes(entry.path);
|
||||
|
||||
bool get atHome => _listing != null && _listing!.parent == null;
|
||||
|
||||
|
||||
@@ -49,7 +49,9 @@ class FolderPickerList extends StatelessWidget {
|
||||
_EntryRow(
|
||||
cupertino: cupertino,
|
||||
entry: entry,
|
||||
onTap: entry.isDir ? () => controller.open(entry.path) : null,
|
||||
onTap: controller.canEnter(entry)
|
||||
? () => controller.open(entry.path)
|
||||
: null,
|
||||
),
|
||||
if (entries.isEmpty)
|
||||
FolderPickerNote(
|
||||
@@ -119,7 +121,10 @@ class _EntryRow extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final folder = entry.isDir;
|
||||
final trailing = folder
|
||||
// A folder the picker may not enter (the one being moved) reads like a
|
||||
// file: dimmed and without a chevron.
|
||||
final enabled = onTap != null;
|
||||
final trailing = enabled
|
||||
? Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
@@ -137,19 +142,19 @@ class _EntryRow extends StatelessWidget {
|
||||
key: ValueKey('folder-entry-${entry.path}'),
|
||||
leading: Icon(
|
||||
folder ? CupertinoIcons.folder_fill : CupertinoIcons.doc,
|
||||
color: folder ? null : dim,
|
||||
color: enabled ? null : dim,
|
||||
),
|
||||
title: Text(entry.name, style: folder ? null : TextStyle(color: dim)),
|
||||
title: Text(entry.name, style: enabled ? null : TextStyle(color: dim)),
|
||||
trailing: trailing,
|
||||
onTap: onTap,
|
||||
);
|
||||
}
|
||||
return ListTile(
|
||||
key: ValueKey('folder-entry-${entry.path}'),
|
||||
enabled: folder,
|
||||
enabled: enabled,
|
||||
leading: Icon(
|
||||
folder ? Icons.folder : Icons.insert_drive_file_outlined,
|
||||
color: folder ? Theme.of(context).colorScheme.primary : null,
|
||||
color: enabled ? Theme.of(context).colorScheme.primary : null,
|
||||
),
|
||||
title: Text(entry.name),
|
||||
trailing: trailing,
|
||||
|
||||
@@ -7,24 +7,28 @@ import '../sessions/chat_adaptive.dart';
|
||||
import 'folder_picker_controller.dart';
|
||||
import 'folder_picker_list.dart';
|
||||
import 'folder_picker_parts.dart';
|
||||
import 'folder_picker_purpose.dart';
|
||||
|
||||
const String folderPickerTitle = 'Choose folder';
|
||||
const String folderPickerStartLabel = 'Start chat here';
|
||||
|
||||
/// The folder picker: breadcrumbs, a filter and hidden toggle, the current
|
||||
/// folder's entries and a prominent "Start chat here". It pops with the chosen
|
||||
/// absolute path; Back climbs one folder and leaves only at home.
|
||||
/// folder's entries and a prominent confirm ("Start chat here" by default; the
|
||||
/// [purpose] names it). It pops with the chosen absolute path; Back climbs one
|
||||
/// folder and leaves only at home.
|
||||
class FolderPickerPage extends StatefulWidget {
|
||||
const FolderPickerPage({
|
||||
super.key,
|
||||
required this.gateway,
|
||||
this.initialPath,
|
||||
this.recents = const [],
|
||||
this.purpose = FolderPickerPurpose.startChat,
|
||||
});
|
||||
|
||||
final ApiGateway gateway;
|
||||
final String? initialPath;
|
||||
final List<String> recents;
|
||||
final FolderPickerPurpose purpose;
|
||||
|
||||
@override
|
||||
State<FolderPickerPage> createState() => _FolderPickerPageState();
|
||||
@@ -35,6 +39,7 @@ class _FolderPickerPageState extends State<FolderPickerPage> {
|
||||
gateway: widget.gateway,
|
||||
initialPath: widget.initialPath,
|
||||
recentFolders: widget.recents,
|
||||
purpose: widget.purpose,
|
||||
);
|
||||
final _filter = TextEditingController();
|
||||
String? _shownPath;
|
||||
@@ -96,6 +101,7 @@ class _FolderPickerPageState extends State<FolderPickerPage> {
|
||||
path: _controller.selectable,
|
||||
home: _controller.home,
|
||||
onStart: _start,
|
||||
purpose: widget.purpose,
|
||||
),
|
||||
],
|
||||
);
|
||||
@@ -114,7 +120,7 @@ class _FolderPickerPageState extends State<FolderPickerPage> {
|
||||
cupertino: cupertino,
|
||||
automaticallyImplyLeading: false,
|
||||
leading: SegmentedBackButton(cupertino: cupertino, onPressed: _back),
|
||||
title: folderPickerTitle,
|
||||
title: widget.purpose.title,
|
||||
actions: [
|
||||
if (cupertino)
|
||||
CupertinoButton(
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import '../../data/directory_listing.dart';
|
||||
import 'folder_picker_controller.dart';
|
||||
import 'folder_picker_purpose.dart';
|
||||
|
||||
/// The path from `~` to the current folder; every crumb but the last opens
|
||||
/// that folder. It scrolls so the current folder stays visible.
|
||||
@@ -196,8 +197,9 @@ class FolderPickerToolbar extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
/// The prominent confirm: names the folder and starts the chat there. It is
|
||||
/// disabled until a folder is listed (never while loading or after an error).
|
||||
/// The prominent confirm: names the folder and confirms it for the picker's
|
||||
/// purpose. It is disabled until an offered folder is listed (never while
|
||||
/// loading, after an error, or in a folder the purpose does not offer).
|
||||
class FolderStartBar extends StatelessWidget {
|
||||
const FolderStartBar({
|
||||
super.key,
|
||||
@@ -205,30 +207,32 @@ class FolderStartBar extends StatelessWidget {
|
||||
required this.path,
|
||||
required this.home,
|
||||
required this.onStart,
|
||||
this.purpose = FolderPickerPurpose.startChat,
|
||||
});
|
||||
|
||||
final bool cupertino;
|
||||
final String? path;
|
||||
final String? home;
|
||||
final VoidCallback onStart;
|
||||
final FolderPickerPurpose purpose;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final where = path == null || home == null
|
||||
? 'No folder selected'
|
||||
: 'Start in ${homeRelativeLabel(home!, path!)}';
|
||||
: purpose.describe(homeRelativeLabel(home!, path!));
|
||||
final onPressed = path == null ? null : onStart;
|
||||
final button = cupertino
|
||||
? CupertinoButton.filled(
|
||||
key: const Key('folder-picker-start'),
|
||||
onPressed: onPressed,
|
||||
child: const Text('Start chat here'),
|
||||
child: Text(purpose.confirmLabel),
|
||||
)
|
||||
: FilledButton.icon(
|
||||
key: const Key('folder-picker-start'),
|
||||
onPressed: onPressed,
|
||||
icon: const Icon(Icons.chat_bubble_outline),
|
||||
label: const Text('Start chat here'),
|
||||
icon: Icon(purpose.icon),
|
||||
label: Text(purpose.confirmLabel),
|
||||
);
|
||||
final content = Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 8, 16, 12),
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../data/directory_listing.dart';
|
||||
|
||||
String _startIn(String folder) => 'Start in $folder';
|
||||
|
||||
/// What the folder picker is choosing a folder for: its title, the confirm
|
||||
/// button's words and icon, and which listed folders it may offer.
|
||||
///
|
||||
/// The default picks where a chat starts. The Files panel's Move uses one that
|
||||
/// keeps the moved folder's own subtree out of reach and does not offer the
|
||||
/// folder the entry is already in.
|
||||
class FolderPickerPurpose {
|
||||
const FolderPickerPurpose({
|
||||
required this.title,
|
||||
required this.confirmLabel,
|
||||
required this.describe,
|
||||
required this.icon,
|
||||
this.excludedPath,
|
||||
this.unchoosablePath,
|
||||
});
|
||||
|
||||
static const startChat = FolderPickerPurpose(
|
||||
title: 'Choose folder',
|
||||
confirmLabel: 'Start chat here',
|
||||
describe: _startIn,
|
||||
icon: Icons.chat_bubble_outline,
|
||||
);
|
||||
|
||||
final String title;
|
||||
final String confirmLabel;
|
||||
|
||||
/// The line above the confirm button for a listed folder's `~/…` label.
|
||||
final String Function(String folderLabel) describe;
|
||||
final IconData icon;
|
||||
|
||||
/// A folder the picker neither enters nor offers, nor anything below it.
|
||||
final String? excludedPath;
|
||||
|
||||
/// One folder the picker enters but does not offer as the choice.
|
||||
final String? unchoosablePath;
|
||||
|
||||
bool excludes(String path) =>
|
||||
excludedPath != null && isInsideHome(excludedPath!, path);
|
||||
|
||||
bool offers(String path) => !excludes(path) && path != unchoosablePath;
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import 'package:flutter/material.dart';
|
||||
import '../../../../core/api_gateway.dart';
|
||||
import '../sessions/chat_adaptive.dart';
|
||||
import 'folder_picker_page.dart';
|
||||
import 'folder_picker_purpose.dart';
|
||||
|
||||
/// At or above this window width the picker is a large dialog over the create
|
||||
/// dialog; below it, a full-screen page.
|
||||
@@ -17,12 +18,14 @@ const double _dialogMaxHeight = 900;
|
||||
|
||||
/// Opens the folder picker and resolves to the chosen absolute folder, or
|
||||
/// null when the operator cancels. [initialPath] opens there when the server
|
||||
/// can list it; [recents] are offered as quick picks at the home level.
|
||||
/// can list it; [recents] are offered as quick picks at the home level;
|
||||
/// [purpose] names the choice (a chat's start folder unless given).
|
||||
Future<String?> showFolderPicker(
|
||||
BuildContext context, {
|
||||
required ApiGateway gateway,
|
||||
String? initialPath,
|
||||
List<String> recents = const [],
|
||||
FolderPickerPurpose purpose = FolderPickerPurpose.startChat,
|
||||
}) {
|
||||
final cupertino = chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
final size = MediaQuery.sizeOf(context);
|
||||
@@ -32,6 +35,7 @@ Future<String?> showFolderPicker(
|
||||
gateway: gateway,
|
||||
initialPath: initialPath,
|
||||
recents: recents,
|
||||
purpose: purpose,
|
||||
);
|
||||
if (!wide) {
|
||||
return navigator.push<String>(
|
||||
|
||||
Reference in New Issue
Block a user