Files
pipelines/app/lib/features/chat/ui/sessions/session_actions.dart
T
alan 3ce7f7a5dd Expose pane actions in chat list menu
Share the open chat pane menu choices with session rows so list actions use the same handlers and target the selected chat. Add command routing, pane movement support, and focused coverage for wide and narrow layouts.
2026-11-12 01:17:46 +00:00

132 lines
3.9 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),
actionsBuilder: () => [
if (allowOpenBeside)
const AppMenuAction<Object>(
value: SessionAction.openBeside,
label: 'Open to the right',
),
if (allowOpenBelow)
const AppMenuAction<Object>(
value: SessionAction.openBelow,
label: 'Open below',
),
if (allowFloat)
AppMenuAction<Object>(
value: SessionAction.float,
label: 'Float (${chatFloatShortcutLabel()})',
),
for (final choice
in paneMenu?.choicesFor(context, session) ??
const <SessionPaneChoice>[])
AppMenuAction<Object>(
value: choice.action,
label: choice.label,
enabled: choice.enabled,
),
for (final item in _items(session))
AppMenuAction<Object>(value: item.action, label: item.label),
],
onSelected: (context, value) {
if (value is SessionAction) {
onSelected(value);
} else if (value is SessionPaneAction) {
paneMenu?.run(context, session, value);
}
},
);
}
}
List<({SessionAction action, String label})> _items(JsonMap session) {
final isClosed = session['closed_at'] != null;
return [
(
action: SessionAction.star,
label: session['starred'] == true ? 'Unstar' : 'Star',
),
(action: SessionAction.color, label: 'Colour…'),
(action: SessionAction.rename, label: 'Rename…'),
isClosed
? (action: SessionAction.reopen, label: 'Reopen')
: (action: SessionAction.close, label: 'Close chat…'),
(action: SessionAction.hide, label: 'Hide on this device'),
];
}
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;
}