Files
pipelines/app/lib/features/chat/ui/sessions/session_actions.dart
T
alan 046de9db4d Use proper phone sheets for chat and Files menus
On phones the chat's More menu, chat list rows and Files entries open a
Material bottom sheet headed by the chat or file, with full-width icon
rows and destructive actions last in the error colour; desktop menus
show icons, a minimum width and destructive actions after a divider.
The chat menu drops Run command and Open chats, keeps a single terminal
entry and lists Close pane last.
2026-11-13 01:14:12 +00:00

177 lines
5.5 KiB
Dart

import 'package:flutter/material.dart';
import '../../../../core/api_gateway.dart';
import '../../domain/chat_sessions.dart';
import '../../workspace/chat_float_shortcut.dart';
import 'session_pane_menu.dart';
import 'session_row_style.dart';
import '../../../../ui/layout/app_overflow_menu.dart';
enum SessionAction {
openBeside,
openBelow,
float,
star,
color,
rename,
close,
reopen,
hide,
}
/// The close confirmation's body, matching the web client's explanation.
String closeChatConfirmation(String title) =>
'Closes "$title" and marks it closed on every device. '
'A turn that is running is stopped first. '
'Nothing is deleted — the chat and its history are kept, '
'and you can reopen it from the list.';
class SessionActionsButton extends StatelessWidget {
const SessionActionsButton({
super.key,
required this.session,
required this.onSelected,
this.duplicateTitles = const {},
this.allowOpenBeside = false,
this.allowOpenBelow = false,
this.allowFloat = false,
this.paneMenu,
});
final JsonMap session;
final ValueChanged<SessionAction> onSelected;
final Set<String> duplicateTitles;
final bool allowOpenBeside;
final bool allowOpenBelow;
final bool allowFloat;
/// The open panes' choices, offered after the list's split and float items.
final SessionPaneMenu? paneMenu;
@override
Widget build(BuildContext context) {
return AppOverflowMenu<Object>(
label: sessionActionsLabel(session, duplicateTitles),
sheetTitle: chatSessionTitle(session),
sheetSubtitle: '${session['directory'] ?? ''}'.trim().isEmpty
? null
: '${session['directory']}',
actionsBuilder: () => [
if (allowOpenBeside)
const AppMenuAction<Object>(
value: SessionAction.openBeside,
label: 'Open to the right',
icon: Icons.vertical_split_outlined,
),
if (allowOpenBelow)
const AppMenuAction<Object>(
value: SessionAction.openBelow,
label: 'Open below',
icon: Icons.horizontal_split_outlined,
),
if (allowFloat)
AppMenuAction<Object>(
value: SessionAction.float,
label: 'Float (${chatFloatShortcutLabel()})',
icon: Icons.picture_in_picture_alt_outlined,
),
for (final choice
in paneMenu?.choicesFor(context, session) ??
const <SessionPaneChoice>[])
AppMenuAction<Object>(
value: choice.action,
label: choice.label,
enabled: choice.enabled,
icon: _paneIcon(choice.action),
destructive: choice.action == SessionPaneAction.closePane,
),
for (final item in _items(session))
AppMenuAction<Object>(
value: item.action,
label: item.label,
icon: item.icon,
destructive: item.action == SessionAction.close,
),
],
onSelected: (context, value) {
if (value is SessionAction) {
onSelected(value);
} else if (value is SessionPaneAction) {
paneMenu?.run(context, session, value);
}
},
);
}
}
IconData _paneIcon(SessionPaneAction action) => switch (action) {
SessionPaneAction.addPane => Icons.add_box_outlined,
SessionPaneAction.openChats => Icons.view_quilt_outlined,
SessionPaneAction.centerStage => Icons.center_focus_strong_outlined,
SessionPaneAction.moveUp => Icons.arrow_upward,
SessionPaneAction.moveDown => Icons.arrow_downward,
SessionPaneAction.moveLeft => Icons.arrow_back,
SessionPaneAction.moveRight => Icons.arrow_forward,
SessionPaneAction.closePane => Icons.close,
SessionPaneAction.chatDetails => Icons.info_outline,
SessionPaneAction.files => Icons.folder_outlined,
SessionPaneAction.runCommand => Icons.terminal,
SessionPaneAction.openTerminal => Icons.terminal,
SessionPaneAction.dismissFinished => Icons.clear_all,
};
List<({SessionAction action, String label, IconData icon})> _items(
JsonMap session,
) {
final isClosed = session['closed_at'] != null;
final starred = session['starred'] == true;
return [
(
action: SessionAction.star,
label: starred ? 'Unstar' : 'Star',
icon: starred ? Icons.star : Icons.star_outline,
),
(
action: SessionAction.color,
label: 'Colour…',
icon: Icons.palette_outlined,
),
(action: SessionAction.rename, label: 'Rename…', icon: Icons.edit_outlined),
(
action: SessionAction.hide,
label: 'Hide on this device',
icon: Icons.visibility_off_outlined,
),
isClosed
? (action: SessionAction.reopen, label: 'Reopen', icon: Icons.restore)
: (
action: SessionAction.close,
label: 'Close chat…',
icon: Icons.close,
),
];
}
Future<bool> confirmCloseChat(BuildContext context, JsonMap session) async {
final title = chatSessionTitle(session);
final body = closeChatConfirmation(title);
final confirmed = await showDialog<bool>(
context: context,
builder: (context) => AlertDialog(
title: const Text('Close chat?'),
content: Text(body),
actions: [
TextButton(
onPressed: () => Navigator.pop(context, false),
child: const Text('Cancel'),
),
FilledButton(
onPressed: () => Navigator.pop(context, true),
child: const Text('Close chat'),
),
],
),
);
return confirmed == true;
}