Merge branch 'main' into pipelines/run-20261112-2323-read-chat-replies-aloud-with-word-highli-e079

This commit is contained in:
2026-11-13 01:29:09 +00:00
18 changed files with 668 additions and 126 deletions
@@ -48,12 +48,6 @@ mixin _ChatScreenPaneMenu on State<ChatScreen>, _ChatScreenWorkspace
label: 'Add chat pane',
enabled: true,
),
if (tiled)
(
action: SessionPaneAction.openChats,
label: 'Open chats ($panes)',
enabled: true,
),
if (tiled && showsListBesideDetail(context))
(
action: SessionPaneAction.centerStage,
@@ -69,12 +63,6 @@ mixin _ChatScreenPaneMenu on State<ChatScreen>, _ChatScreenWorkspace
'(${chatPaneMoveShortcutLabel(move.direction)})',
enabled: moves[move.direction] != null,
),
if (pane != null && tiled)
(
action: SessionPaneAction.closePane,
label: 'Close pane',
enabled: true,
),
if (WindowScope.maybeOf(context) != null)
(
action: SessionPaneAction.chatDetails,
@@ -82,11 +70,6 @@ mixin _ChatScreenPaneMenu on State<ChatScreen>, _ChatScreenWorkspace
enabled: true,
),
(action: SessionPaneAction.files, label: 'Files', enabled: true),
(
action: SessionPaneAction.runCommand,
label: chatShellRunActionLabel,
enabled: true,
),
if (_paneCommands.hasFinished(id))
(
action: SessionPaneAction.dismissFinished,
@@ -99,6 +82,13 @@ mixin _ChatScreenPaneMenu on State<ChatScreen>, _ChatScreenWorkspace
label: terminalOpenActionLabel,
enabled: true,
),
// Closing comes last.
if (pane != null && tiled)
(
action: SessionPaneAction.closePane,
label: 'Close pane',
enabled: true,
),
];
}
@@ -106,6 +106,8 @@ class ChatThreadHeader extends StatelessWidget {
if (action is! SegmentedOverflowable) action,
if (settingsEntry != null || menuActions.isNotEmpty)
SegmentedMoreButton(
sheetTitle: title.isEmpty ? 'Chat' : title,
sheetSubtitle: folder.isEmpty ? null : folder,
entries: [
?settingsEntry,
for (final action in menuActions) action.overflowEntry,
@@ -1467,6 +1467,10 @@ class _ChatThreadViewState extends State<ChatThreadView> {
);
}
/// A pane control that closes the pane: listed last in the menu.
static bool _closes(Widget control) =>
control is ChatBarAction && control.destructive;
Widget _buildHeader(
JsonMap? session,
bool inShellBar,
@@ -1484,6 +1488,12 @@ class _ChatThreadViewState extends State<ChatThreadView> {
final folder = directory
.split(RegExp(r'[/\\]'))
.lastWhere((part) => part.isNotEmpty, orElse: () => '');
final openTerminal = terminalOpenMenuAction(
context,
gateway: widget.gateway,
directory: directory,
onRefused: _terminalRefused,
);
return ChatThreadHeader(
key: const Key('chat-thread-header'),
chatColor: chatSessionColor(session),
@@ -1514,8 +1524,9 @@ class _ChatThreadViewState extends State<ChatThreadView> {
materialIcon: _filesVisible ? Icons.folder : Icons.folder_outlined,
),
// A narrow layout's terminal button, beside Files; wide keeps the
// shell bar's.
?terminalChatBarAction(context),
// shell bar's. Where the menu already offers the chat's terminal
// (Open in terminal) there is no second terminal entry.
if (openTerminal == null) ?terminalChatBarAction(context),
],
moreActions: [
?widget.sidebarControl,
@@ -1536,16 +1547,12 @@ class _ChatThreadViewState extends State<ChatThreadView> {
onPressed: _openInfo,
materialIcon: Icons.info_outline,
),
...widget.paneControls,
chatShellRunMenuAction(onPressed: _runShellFromMenu),
...widget.paneControls.where((c) => !_closes(c)),
if (_shellRuns.finishedIds.isNotEmpty)
chatShellDismissAllMenuAction(onPressed: _dismissFinishedShellRuns),
?terminalOpenMenuAction(
context,
gateway: widget.gateway,
directory: directory,
onRefused: _terminalRefused,
),
?openTerminal,
// Closing comes last.
...widget.paneControls.where(_closes),
],
controls: [
// Labelled, so a narrow bar's settings sheet shows their names.
+29 -4
View File
@@ -11,6 +11,9 @@ import 'files_entry_actions.dart';
import 'files_upload_notice.dart';
import 'files_viewer.dart';
import 'files_header.dart';
import 'files_models.dart';
import 'files_preview.dart';
import '../../artifacts/domain/artifact_kind.dart';
import '../../../ui/layout/app_overflow_menu.dart';
import '../../terminal/terminal_open_action.dart';
import '../../terminal/terminal_scope.dart';
@@ -160,6 +163,10 @@ class _FilesPanelState extends State<FilesPanel> {
/// Open and Download for a file, then Rename, Move and Delete for any entry.
Widget _menu(DirectoryEntry entry) => AppOverflowMenu<FileAction>(
label: entry.isDir ? 'Folder actions' : 'File actions',
sheetTitle: entry.name,
sheetSubtitle: entry.isDir
? 'Folder'
: '${artifactKindLabel(artifactKind(fileContentType(entry.name), entry.name))} · ${fileSizeLabel(entry.size)}',
onSelected: (_, action) => switch (action) {
FileAction.open => _open(entry),
FileAction.download => widget.viewer.download(
@@ -179,19 +186,37 @@ class _FilesPanelState extends State<FilesPanel> {
},
actions: [
if (!entry.isDir) ...const [
AppMenuAction(value: FileAction.open, label: 'Open'),
AppMenuAction(value: FileAction.download, label: 'Download'),
AppMenuAction(
value: FileAction.open,
label: 'Open',
icon: Icons.open_in_new,
),
AppMenuAction(
value: FileAction.download,
label: 'Download',
icon: Icons.download_outlined,
),
],
if (entry.isDir && TerminalScope.maybeOf(context) != null)
const AppMenuAction(
value: FileAction.terminal,
label: terminalOpenActionLabel,
icon: Icons.terminal,
),
const AppMenuAction(value: FileAction.rename, label: 'Rename…'),
const AppMenuAction(value: FileAction.move, label: 'Move…'),
const AppMenuAction(
value: FileAction.rename,
label: 'Rename…',
icon: Icons.edit_outlined,
),
const AppMenuAction(
value: FileAction.move,
label: 'Move…',
icon: Icons.drive_file_move_outlined,
),
const AppMenuAction(
value: FileAction.delete,
label: 'Delete…',
icon: Icons.delete_outline,
destructive: true,
),
],
+1 -7
View File
@@ -22,7 +22,6 @@ import 'package:flutter/services.dart';
import '../../core/api_gateway.dart';
import '../../core/servers/server_scope.dart';
import '../../shell/windows/window_scope.dart';
import 'shell/chat_shell_command.dart';
import 'shell/chat_shell_dismiss.dart';
import '../terminal/terminal_open_action.dart';
import 'ui/sessions/session_pane_menu.dart';
@@ -440,12 +439,6 @@ class _ChatScreenState extends State<ChatScreen>
onPressed: () => _addPane(paneContext),
materialIcon: Icons.add_box_outlined,
),
if (_workspace.paneCount > 1)
ChatBarAction(
label: 'Open chats (${_workspace.paneCount})',
onPressed: () => _pickPane(paneContext),
materialIcon: Icons.view_quilt_outlined,
),
if (_workspace.paneCount > 1 && showsListBesideDetail(context))
chatCenterStageAction(ChatCenterStageController.instance),
...chatPaneMoveActions(
@@ -458,6 +451,7 @@ class _ChatScreenState extends State<ChatScreen>
label: 'Close pane',
onPressed: () => _closePane(pane.id),
materialIcon: Icons.close,
destructive: true,
),
],
),
@@ -8,6 +8,7 @@ class ChatBarAction extends StatelessWidget implements SegmentedOverflowable {
required this.onPressed,
required this.materialIcon,
this.identifier,
this.destructive = false,
});
final String label;
@@ -16,12 +17,16 @@ class ChatBarAction extends StatelessWidget implements SegmentedOverflowable {
final String? identifier;
/// Closes or removes something; menus list it last, in the error colour.
final bool destructive;
/// A narrow bar moves it into its More menu, under the bar's host's icon.
@override
SegmentedOverflowEntry get overflowEntry => SegmentedOverflowEntry(
label: label,
icon: materialIcon,
onPressed: onPressed,
destructive: destructive,
);
@override
@@ -53,21 +53,27 @@ class SessionActionsButton extends StatelessWidget {
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) ??
@@ -76,9 +82,16 @@ class SessionActionsButton extends StatelessWidget {
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),
AppMenuAction<Object>(
value: item.action,
label: item.label,
icon: item.icon,
destructive: item.action == SessionAction.close,
),
],
onSelected: (context, value) {
if (value is SessionAction) {
@@ -91,19 +104,51 @@ class SessionActionsButton extends StatelessWidget {
}
}
List<({SessionAction action, String label})> _items(JsonMap session) {
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: session['starred'] == true ? 'Unstar' : '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,
),
(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'),
? (action: SessionAction.reopen, label: 'Reopen', icon: Icons.restore)
: (
action: SessionAction.close,
label: 'Close chat…',
icon: Icons.close,
),
];
}
+174
View File
@@ -0,0 +1,174 @@
import 'package:flutter/material.dart';
/// One action in an [showAppActionSheet] sheet.
class AppSheetAction {
const AppSheetAction({
required this.label,
this.icon,
this.onSelected,
this.destructive = false,
this.enabled = true,
this.selected = false,
this.choices = const [],
this.key,
});
final String label;
final IconData? icon;
/// Runs once the sheet has closed. Null (with no [choices]) disables it.
final VoidCallback? onSelected;
/// Shown last, after a divider, in the theme's error colour.
final bool destructive;
final bool enabled;
/// Marks the current choice in a [choices] list.
final bool selected;
/// Choices offered on a second sheet (a sort order) instead of [onSelected].
final List<AppSheetAction> choices;
/// Placed on the row so tests can find it.
final Key? key;
}
/// A phone's menu: a modal bottom sheet with a header naming what the actions
/// apply to ([title], [subtitle]) and one full-width row per action, each with
/// its icon. Destructive actions come last, after a divider, in the error
/// colour. The chosen action runs after the sheet has closed.
Future<void> showAppActionSheet(
BuildContext context, {
String? title,
String? subtitle,
required List<AppSheetAction> actions,
}) async {
final chosen = await showModalBottomSheet<AppSheetAction>(
context: context,
useRootNavigator: true,
showDragHandle: true,
isScrollControlled: true,
useSafeArea: true,
builder: (sheet) =>
_ActionSheet(title: title, subtitle: subtitle, actions: actions),
);
if (chosen == null) return;
if (chosen.choices.isNotEmpty) {
if (!context.mounted) return;
return showAppActionSheet(
context,
title: chosen.label,
actions: chosen.choices,
);
}
chosen.onSelected?.call();
}
class _ActionSheet extends StatelessWidget {
const _ActionSheet({
required this.title,
required this.subtitle,
required this.actions,
});
final String? title;
final String? subtitle;
final List<AppSheetAction> actions;
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final regular = [
for (final action in actions)
if (!action.destructive) action,
];
final destructive = [
for (final action in actions)
if (action.destructive) action,
];
final hasTitle = title != null && title!.trim().isNotEmpty;
return SafeArea(
top: false,
child: SingleChildScrollView(
padding: const EdgeInsets.only(bottom: 8),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (hasTitle) ...[
Padding(
padding: const EdgeInsets.fromLTRB(24, 0, 24, 12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title!,
style: theme.textTheme.titleMedium,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
if (subtitle != null && subtitle!.trim().isNotEmpty) ...[
const SizedBox(height: 2),
Text(
subtitle!,
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
],
],
),
),
const Divider(height: 1),
],
const SizedBox(height: 8),
for (final action in regular) _ActionRow(action: action),
if (destructive.isNotEmpty) ...[
if (regular.isNotEmpty)
const Divider(height: 17, indent: 24, endIndent: 24),
for (final action in destructive) _ActionRow(action: action),
],
],
),
),
);
}
}
class _ActionRow extends StatelessWidget {
const _ActionRow({required this.action});
final AppSheetAction action;
@override
Widget build(BuildContext context) {
final scheme = Theme.of(context).colorScheme;
final enabled =
action.enabled &&
(action.onSelected != null || action.choices.isNotEmpty);
final color = action.destructive ? scheme.error : null;
return ListTile(
key: action.key,
enabled: enabled,
minTileHeight: 56,
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
leading: action.icon == null
? null
: Icon(action.icon, color: enabled ? color : null),
iconColor: scheme.onSurfaceVariant,
title: Text(
action.label,
style: color == null || !enabled ? null : TextStyle(color: color),
),
trailing: action.choices.isNotEmpty
? const Icon(Icons.chevron_right)
: action.selected
? Icon(Icons.check, color: scheme.primary)
: null,
selected: action.selected,
onTap: enabled ? () => Navigator.of(context).pop(action) : null,
);
}
}
@@ -1,4 +1,6 @@
import 'app_action_sheet.dart';
import 'app_menu_anchor.dart';
import 'app_popups.dart';
import 'package:flutter/material.dart';
/// The key of a [SegmentedBar]'s More button, shown when its actions do not
@@ -27,11 +29,16 @@ class SegmentedOverflowEntry {
this.onPressed,
this.choices = const [],
this.shortcut,
this.destructive = false,
});
final String label;
final IconData icon;
/// Closes or removes something (Close pane): listed last on a phone sheet,
/// after a divider, in the error colour.
final bool destructive;
/// What choosing the entry does; null (with no [choices]) disables it.
final VoidCallback? onPressed;
@@ -68,16 +75,55 @@ class SegmentedOverflowAction extends StatelessWidget
}
/// The bar's More button: the host's overflow icon at the platform's touch
/// target, opening a Material menu of [entries].
/// target, opening a Material menu of [entries] on a wide app and a bottom
/// sheet headed by [sheetTitle] on a phone.
class SegmentedMoreButton extends StatelessWidget {
const SegmentedMoreButton({super.key, required this.entries});
const SegmentedMoreButton({
super.key,
required this.entries,
this.sheetTitle,
this.sheetSubtitle,
});
final List<SegmentedOverflowEntry> entries;
/// The phone sheet's header: what the actions apply to (a chat).
final String? sheetTitle;
final String? sheetSubtitle;
static const String label = 'More actions';
@override
Widget build(BuildContext context) {
if (!usesDesktopPopups(context)) {
return IconButton(
key: segmentedMoreKey,
tooltip: label,
icon: const Icon(Icons.more_vert),
onPressed: () => showAppActionSheet(
context,
title: sheetTitle,
subtitle: sheetSubtitle,
actions: [
for (final entry in entries)
AppSheetAction(
label: entry.label,
icon: entry.icon,
onSelected: entry.onPressed,
destructive: entry.destructive,
choices: [
for (final choice in entry.choices)
AppSheetAction(
label: choice.label,
selected: choice.selected,
onSelected: choice.onSelected,
),
],
),
],
),
);
}
return AppMenuAnchor(
menuChildren: [
for (final entry in entries)
+104 -14
View File
@@ -1,10 +1,14 @@
import 'package:flutter/material.dart';
import '../adaptive/app_action_sheet.dart';
import '../adaptive/app_popups.dart';
/// One choice in an [AppOverflowMenu].
class AppMenuAction<T> {
const AppMenuAction({
required this.value,
required this.label,
this.icon,
this.key,
this.destructive = false,
this.enabled = true,
@@ -13,22 +17,25 @@ class AppMenuAction<T> {
final T value;
final String label;
/// The action's glyph, beside its label in the menu and the phone sheet.
final IconData? icon;
/// Placed on the menu item so tests can find the same item.
final Key? key;
/// A disabled item stays listed but cannot be chosen.
final bool enabled;
// Kept for callers that distinguish destructive actions in their data model;
// Material PopupMenuItem does not apply a separate action-sheet treatment.
/// Listed last, after a divider, in the theme's error colour.
final bool destructive;
}
/// The app's one row/header overflow control: the host's "more" icon that
/// opens the row's secondary actions.
///
/// Shows a [PopupMenuButton] with [Icons.more_vert]. Every list row and the run
/// header use this, so overflow actions are anchored to their button.
/// On a wide app it is a menu anchored to its button, with each action's icon;
/// on a phone it opens a bottom sheet headed by [sheetTitle], with full-width
/// rows (see [showAppActionSheet]). Destructive actions come last either way.
class AppOverflowMenu<T> extends StatelessWidget {
const AppOverflowMenu({
super.key,
@@ -37,6 +44,7 @@ class AppOverflowMenu<T> extends StatelessWidget {
required this.onSelected,
this.label = 'More actions',
this.sheetTitle,
this.sheetSubtitle,
this.enabled = true,
this.icon = const Icon(Icons.more_vert),
});
@@ -53,20 +61,60 @@ class AppOverflowMenu<T> extends StatelessWidget {
/// Tooltip and accessible label.
final String label;
/// Retained for source compatibility; Material menus do not show a title.
/// The phone sheet's header: what the actions apply to (a chat, a file).
final String? sheetTitle;
/// A second header line under [sheetTitle] (a file's size, a folder).
final String? sheetSubtitle;
final bool enabled;
/// The button glyph. Most callers use the default overflow icon; controls
/// whose action has a distinct meaning can provide a matching Material icon.
final Widget icon;
List<AppMenuAction<T>> _ordered() {
final all = actionsBuilder?.call() ?? actions;
return [
for (final action in all)
if (!action.destructive) action,
for (final action in all)
if (action.destructive) action,
];
}
@override
Widget build(BuildContext context) {
if (actionsBuilder == null && actions.isEmpty) {
return const SizedBox.shrink();
}
if (!usesDesktopPopups(context)) {
return IconButton(
icon: icon,
tooltip: label,
onPressed: !enabled
? null
: () => showAppActionSheet(
context,
title: sheetTitle,
subtitle: sheetSubtitle,
actions: [
for (final action in _ordered())
AppSheetAction(
key: action.key,
label: action.label,
icon: action.icon,
destructive: action.destructive,
enabled: action.enabled,
onSelected: () {
if (context.mounted) onSelected(context, action.value);
},
),
],
),
);
}
final scheme = Theme.of(context).colorScheme;
return Localizations.override(
context: context,
delegates: const [DefaultMaterialLocalizations.delegate],
@@ -76,18 +124,60 @@ class AppOverflowMenu<T> extends StatelessWidget {
icon: icon,
tooltip: label,
enabled: enabled,
constraints: const BoxConstraints(minWidth: 220),
onSelected: (value) => onSelected(context, value),
itemBuilder: (_) => [
for (final action in actionsBuilder?.call() ?? actions)
PopupMenuItem<T>(
key: action.key,
value: action.value,
enabled: action.enabled,
child: Text(action.label),
),
],
itemBuilder: (_) {
final ordered = _ordered();
final firstDestructive = ordered.indexWhere((a) => a.destructive);
return [
for (final (index, action) in ordered.indexed) ...[
if (index == firstDestructive && index > 0)
const PopupMenuDivider(),
PopupMenuItem<T>(
key: action.key,
value: action.value,
enabled: action.enabled,
child: _MenuRow(
label: action.label,
icon: action.icon,
color: action.destructive && action.enabled
? scheme.error
: null,
),
),
],
];
},
),
),
);
}
}
class _MenuRow extends StatelessWidget {
const _MenuRow({required this.label, this.icon, this.color});
final String label;
final IconData? icon;
final Color? color;
@override
Widget build(BuildContext context) {
final text = Text(
label,
style: color == null ? null : TextStyle(color: color),
);
if (icon == null) return text;
return Row(
children: [
Icon(
icon,
size: 20,
color: color ?? Theme.of(context).colorScheme.onSurfaceVariant,
),
const SizedBox(width: 12),
Flexible(child: text),
],
);
}
}