From 046de9db4dc77e1f97c3b737ba1f945121afbc39 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Fri, 13 Nov 2026 01:14:12 +0000 Subject: [PATCH] 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. --- .../features/chat/chat_screen_pane_menu.dart | 24 +-- .../chat/conversation/chat_thread_header.dart | 2 + .../chat/conversation/chat_thread_view.dart | 27 ++- app/lib/features/chat/files/files_panel.dart | 33 +++- app/lib/features/chat/screen.dart | 8 +- .../chat/ui/sessions/chat_adaptive.dart | 5 + .../chat/ui/sessions/session_actions.dart | 61 +++++- app/lib/ui/adaptive/app_action_sheet.dart | 174 +++++++++++++++++ .../ui/adaptive/segmented_bar_overflow.dart | 50 ++++- app/lib/ui/layout/app_overflow_menu.dart | 118 ++++++++++-- .../chat/chat_floating_pane_test.dart | 45 ++--- .../chat_seen_interaction_test.dart | 16 +- .../chat_thread_stop_menu_test.dart | 8 +- .../chat/shell/chat_shell_composer_test.dart | 22 --- .../chat/shell/chat_shell_dismiss_test.dart | 9 +- .../chat/workspace/chat_pane_dim_test.dart | 5 +- .../ui/adaptive/app_action_sheet_test.dart | 177 ++++++++++++++++++ app/test/ui/layout/app_list_row_test.dart | 10 +- 18 files changed, 668 insertions(+), 126 deletions(-) create mode 100644 app/lib/ui/adaptive/app_action_sheet.dart create mode 100644 app/test/ui/adaptive/app_action_sheet_test.dart diff --git a/app/lib/features/chat/chat_screen_pane_menu.dart b/app/lib/features/chat/chat_screen_pane_menu.dart index f6265c32..b7e2b909 100644 --- a/app/lib/features/chat/chat_screen_pane_menu.dart +++ b/app/lib/features/chat/chat_screen_pane_menu.dart @@ -48,12 +48,6 @@ mixin _ChatScreenPaneMenu on State, _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, _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, _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, _ChatScreenWorkspace label: terminalOpenActionLabel, enabled: true, ), + // Closing comes last. + if (pane != null && tiled) + ( + action: SessionPaneAction.closePane, + label: 'Close pane', + enabled: true, + ), ]; } diff --git a/app/lib/features/chat/conversation/chat_thread_header.dart b/app/lib/features/chat/conversation/chat_thread_header.dart index 39f49192..8ceeec52 100644 --- a/app/lib/features/chat/conversation/chat_thread_header.dart +++ b/app/lib/features/chat/conversation/chat_thread_header.dart @@ -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, diff --git a/app/lib/features/chat/conversation/chat_thread_view.dart b/app/lib/features/chat/conversation/chat_thread_view.dart index f1c248e8..aa6e4b08 100644 --- a/app/lib/features/chat/conversation/chat_thread_view.dart +++ b/app/lib/features/chat/conversation/chat_thread_view.dart @@ -1457,6 +1457,10 @@ class _ChatThreadViewState extends State { ); } + /// 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, @@ -1474,6 +1478,12 @@ class _ChatThreadViewState extends State { 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), @@ -1504,8 +1514,9 @@ class _ChatThreadViewState extends State { 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, @@ -1526,16 +1537,12 @@ class _ChatThreadViewState extends State { 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. diff --git a/app/lib/features/chat/files/files_panel.dart b/app/lib/features/chat/files/files_panel.dart index 2a091e8d..35077f17 100644 --- a/app/lib/features/chat/files/files_panel.dart +++ b/app/lib/features/chat/files/files_panel.dart @@ -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 { /// Open and Download for a file, then Rename, Move and Delete for any entry. Widget _menu(DirectoryEntry entry) => AppOverflowMenu( 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 { }, 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, ), ], diff --git a/app/lib/features/chat/screen.dart b/app/lib/features/chat/screen.dart index 91741c65..dadd1888 100644 --- a/app/lib/features/chat/screen.dart +++ b/app/lib/features/chat/screen.dart @@ -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 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 label: 'Close pane', onPressed: () => _closePane(pane.id), materialIcon: Icons.close, + destructive: true, ), ], ), diff --git a/app/lib/features/chat/ui/sessions/chat_adaptive.dart b/app/lib/features/chat/ui/sessions/chat_adaptive.dart index 5831c600..09f74bcd 100644 --- a/app/lib/features/chat/ui/sessions/chat_adaptive.dart +++ b/app/lib/features/chat/ui/sessions/chat_adaptive.dart @@ -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 diff --git a/app/lib/features/chat/ui/sessions/session_actions.dart b/app/lib/features/chat/ui/sessions/session_actions.dart index 1ae3217e..eda03201 100644 --- a/app/lib/features/chat/ui/sessions/session_actions.dart +++ b/app/lib/features/chat/ui/sessions/session_actions.dart @@ -53,21 +53,27 @@ class SessionActionsButton extends StatelessWidget { return AppOverflowMenu( label: sessionActionsLabel(session, duplicateTitles), sheetTitle: chatSessionTitle(session), + sheetSubtitle: '${session['directory'] ?? ''}'.trim().isEmpty + ? null + : '${session['directory']}', actionsBuilder: () => [ if (allowOpenBeside) const AppMenuAction( value: SessionAction.openBeside, label: 'Open to the right', + icon: Icons.vertical_split_outlined, ), if (allowOpenBelow) const AppMenuAction( value: SessionAction.openBelow, label: 'Open below', + icon: Icons.horizontal_split_outlined, ), if (allowFloat) AppMenuAction( 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(value: item.action, label: item.label), + AppMenuAction( + 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, + ), ]; } diff --git a/app/lib/ui/adaptive/app_action_sheet.dart b/app/lib/ui/adaptive/app_action_sheet.dart new file mode 100644 index 00000000..6672d12c --- /dev/null +++ b/app/lib/ui/adaptive/app_action_sheet.dart @@ -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 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 showAppActionSheet( + BuildContext context, { + String? title, + String? subtitle, + required List actions, +}) async { + final chosen = await showModalBottomSheet( + 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 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, + ); + } +} diff --git a/app/lib/ui/adaptive/segmented_bar_overflow.dart b/app/lib/ui/adaptive/segmented_bar_overflow.dart index 203673ca..2ef8eb29 100644 --- a/app/lib/ui/adaptive/segmented_bar_overflow.dart +++ b/app/lib/ui/adaptive/segmented_bar_overflow.dart @@ -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 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) diff --git a/app/lib/ui/layout/app_overflow_menu.dart b/app/lib/ui/layout/app_overflow_menu.dart index 7583fc27..0a5ad50d 100644 --- a/app/lib/ui/layout/app_overflow_menu.dart +++ b/app/lib/ui/layout/app_overflow_menu.dart @@ -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 { const AppMenuAction({ required this.value, required this.label, + this.icon, this.key, this.destructive = false, this.enabled = true, @@ -13,22 +17,25 @@ class AppMenuAction { 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 extends StatelessWidget { const AppOverflowMenu({ super.key, @@ -37,6 +44,7 @@ class AppOverflowMenu 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 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> _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 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( - 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( + 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), + ], + ); + } +} diff --git a/app/test/features/chat/chat_floating_pane_test.dart b/app/test/features/chat/chat_floating_pane_test.dart index 5696291b..3be68061 100644 --- a/app/test/features/chat/chat_floating_pane_test.dart +++ b/app/test/features/chat/chat_floating_pane_test.dart @@ -11,7 +11,6 @@ import 'package:pipelines_app/features/chat/screen.dart'; import 'package:pipelines_app/features/chat/windows/chat_windows.dart'; import 'package:pipelines_app/features/chat/workspace/chat_float_store.dart'; import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart'; -import 'package:pipelines_app/features/chat/shell/chat_shell_command.dart'; import 'package:pipelines_app/features/chat/workspace/chat_workspace_store.dart'; import 'package:pipelines_app/features/terminal/terminal_scope.dart'; import 'package:pipelines_app/shell/windows/window_frame.dart'; @@ -236,12 +235,16 @@ Future> _listMenu(WidgetTester tester, String id) async { // Windows sit over the list, so the list's menu is reached with them hidden. await tester.tap(find.byTooltip('Chat actions for Chat $id').first); await tester.pumpAndSettle(); + // A wide app shows an anchored menu; a phone shows a bottom sheet of rows. + final rows = find.byType(PopupMenuItem).evaluate().isNotEmpty + ? find.byType(PopupMenuItem) + : find.descendant( + of: find.byType(BottomSheet), + matching: find.byType(ListTile), + ); return [ for (final text in tester.widgetList( - find.descendant( - of: find.byType(PopupMenuItem), - matching: find.byType(Text), - ), + find.descendant(of: rows, matching: find.byType(Text)), )) text.data!, ]; @@ -788,7 +791,9 @@ void main() { await tester.tap(finder.first); await tester.pumpAndSettle(); expect(find.textContaining('Float'), findsNothing); - expect(find.text('Open chats (2)'), findsOneWidget); + // A phone's menu is a bottom sheet. + expect(find.byType(BottomSheet), findsOneWidget); + expect(find.text('Open chats (2)'), findsNothing); await app.stop(tester); }); @@ -808,13 +813,15 @@ void main() { 'Open below', 'Float (Alt+Y)', 'Add chat pane', - 'Open chats (2)', - 'Close pane', 'Files', - 'Run command…', 'Star', + // Closing comes last. + 'Close pane', ]), ); + expect(labels, isNot(contains('Open chats (2)'))); + expect(labels, isNot(contains('Run command…'))); + expect(labels.last, 'Close chat…'); expect(labels.any((label) => label.startsWith('Center stage')), isTrue); // Only a window's own pane offers Chat details, and no terminal is wired. expect(labels, isNot(contains('Chat details'))); @@ -900,24 +907,6 @@ void main() { await app.stop(tester); }); - testWidgets('a list choice runs the command dialog for its chat', ( - tester, - ) async { - await _saved('a', 'b'); - final app = _App(_Store()); - await app.start(tester); - app.manager.setGroupShown(chatWindowKind, false); - await tester.pumpAndSettle(); - - await _listChoice(tester, 'b', 'Run command…'); - expect(find.text(chatShellRunDialogTitle), findsOneWidget); - await tester.sendKeyEvent(LogicalKeyboardKey.escape); - await tester.pumpAndSettle(); - expect(_workspace(tester).panes.map((p) => p.sessionId), ['a', 'b']); - expect(tester.takeException(), isNull); - await app.stop(tester); - }); - testWidgets('narrow layouts offer the list the panes it can reach', ( tester, ) async { @@ -929,7 +918,7 @@ void main() { await tester.pumpAndSettle(); final labels = await _listMenu(tester, 'b'); expect(labels, contains('Add chat pane')); - expect(labels, contains('Open chats (2)')); + expect(labels, isNot(contains('Open chats (2)'))); expect(labels.any((label) => label.startsWith('Center stage')), isFalse); expect(labels, isNot(contains('Float (Alt+Y)'))); expect(labels, isNot(contains('Open to the right'))); diff --git a/app/test/features/chat/conversation/chat_seen_interaction_test.dart b/app/test/features/chat/conversation/chat_seen_interaction_test.dart index 69410d10..11137685 100644 --- a/app/test/features/chat/conversation/chat_seen_interaction_test.dart +++ b/app/test/features/chat/conversation/chat_seen_interaction_test.dart @@ -106,7 +106,11 @@ void main() { await tester.sendKeyEvent(LogicalKeyboardKey.keyA); await tester.pump(); - expect(count, 0, reason: 'a key with no focus in the pane is not its input'); + expect( + count, + 0, + reason: 'a key with no focus in the pane is not its input', + ); focus.requestFocus(); await tester.pump(); @@ -116,7 +120,9 @@ void main() { expect(count, 1); }); - testWidgets('code-driven focus into the pane reports nothing', (tester) async { + testWidgets('code-driven focus into the pane reports nothing', ( + tester, + ) async { var count = 0; final focus = FocusNode(); addTearDown(focus.dispose); @@ -127,7 +133,11 @@ void main() { await tester.pump(const Duration(seconds: 1)); expect(focus.hasFocus, isTrue); - expect(count, 0, reason: 'focus moved in code, with no key press, is passive'); + expect( + count, + 0, + reason: 'focus moved in code, with no key press, is passive', + ); }); testWidgets('Tab from outside the pane into it reports once', (tester) async { diff --git a/app/test/features/chat/conversation/chat_thread_stop_menu_test.dart b/app/test/features/chat/conversation/chat_thread_stop_menu_test.dart index b8128505..24ba0456 100644 --- a/app/test/features/chat/conversation/chat_thread_stop_menu_test.dart +++ b/app/test/features/chat/conversation/chat_thread_stop_menu_test.dart @@ -38,8 +38,12 @@ void main() { tester, ) async { final gateway = await pumpThread(tester); - await tester.tap(find.byTooltip('More actions').hitTestable().first); - await tester.pumpAndSettle(); + // With nothing else to offer, the bar shows no More menu at all. + final more = find.byTooltip('More actions').hitTestable(); + if (more.evaluate().isNotEmpty) { + await tester.tap(more.first); + await tester.pumpAndSettle(); + } expect(find.text('Stop'), findsNothing); expect(gateway.interruptBodies, isEmpty); }); diff --git a/app/test/features/chat/shell/chat_shell_composer_test.dart b/app/test/features/chat/shell/chat_shell_composer_test.dart index 96dd6ccb..28616014 100644 --- a/app/test/features/chat/shell/chat_shell_composer_test.dart +++ b/app/test/features/chat/shell/chat_shell_composer_test.dart @@ -1,7 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:pipelines_app/ui/adaptive/segmented_bar_overflow.dart'; import 'chat_shell_fixtures.dart'; @@ -66,25 +65,4 @@ void main() { expect(find.text('Type a command after !.'), findsOneWidget); expect(gateway.bodies('chat_shell_run'), isEmpty); }); - - testWidgets('Run command… in the actions menu runs the typed command', ( - tester, - ) async { - await tester.pumpWidget(shellThread(gateway)); - await tester.pump(); - await tester.tap(find.byKey(segmentedMoreKey).hitTestable().first); - await tester.pumpAndSettle(); - await tester.tap(find.text('Run command…')); - await tester.pumpAndSettle(); - await tester.enterText( - find.byKey(const Key('chat-shell-run-field')), - ' ls -la ', - ); - await tester.tap(find.byKey(const Key('chat-shell-run-confirm'))); - // The running card's indicator never settles; let the dialog close. - await tester.pump(); - await tester.pump(const Duration(seconds: 1)); - expect(gateway.bodies('chat_shell_run').single['command'], 'ls -la'); - expect(find.text('\$ ls -la'), findsOneWidget); - }); } diff --git a/app/test/features/chat/shell/chat_shell_dismiss_test.dart b/app/test/features/chat/shell/chat_shell_dismiss_test.dart index a6a3b0f3..b9f38c00 100644 --- a/app/test/features/chat/shell/chat_shell_dismiss_test.dart +++ b/app/test/features/chat/shell/chat_shell_dismiss_test.dart @@ -71,9 +71,12 @@ void main() { gateway.runs = [shellRecord('run_live')]; await tester.pumpWidget(shellThread(gateway)); await tester.pump(); - await tester.tap(find.byKey(segmentedMoreKey).hitTestable().first); - await tester.pump(const Duration(milliseconds: 500)); - expect(find.text('Run command…'), findsOneWidget); + // With nothing else to offer, the bar shows no More menu at all. + final more = find.byKey(segmentedMoreKey).hitTestable(); + if (more.evaluate().isNotEmpty) { + await tester.tap(more.first); + await tester.pump(const Duration(milliseconds: 500)); + } expect(find.text('Dismiss all finished commands'), findsNothing); }); diff --git a/app/test/features/chat/workspace/chat_pane_dim_test.dart b/app/test/features/chat/workspace/chat_pane_dim_test.dart index 34983706..c51b3c59 100644 --- a/app/test/features/chat/workspace/chat_pane_dim_test.dart +++ b/app/test/features/chat/workspace/chat_pane_dim_test.dart @@ -174,9 +174,6 @@ void main() { await tester.pumpAndSettle(); final scrim = find.byKey(const ValueKey('chat-pane-dim-scrim')).first; - expect( - tester.widget(scrim).duration, - Motion.standard, - ); + expect(tester.widget(scrim).duration, Motion.standard); }); } diff --git a/app/test/ui/adaptive/app_action_sheet_test.dart b/app/test/ui/adaptive/app_action_sheet_test.dart new file mode 100644 index 00000000..378e62b6 --- /dev/null +++ b/app/test/ui/adaptive/app_action_sheet_test.dart @@ -0,0 +1,177 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/ui/adaptive/segmented_bar_overflow.dart'; +import 'package:pipelines_app/ui/layout/app_overflow_menu.dart'; + +void _size(WidgetTester tester, double width) { + tester.view.physicalSize = Size(width, 900); + tester.view.devicePixelRatio = 1; + addTearDown(tester.view.reset); +} + +Widget _menu(void Function(String) picked) => MaterialApp( + home: Scaffold( + body: Center( + child: AppOverflowMenu( + key: const Key('menu'), + sheetTitle: 'notes.md', + sheetSubtitle: 'Markdown · 2 KB', + onSelected: (_, value) => picked(value), + actions: const [ + AppMenuAction( + value: 'delete', + label: 'Delete…', + icon: Icons.delete_outline, + destructive: true, + ), + AppMenuAction(value: 'open', label: 'Open', icon: Icons.open_in_new), + AppMenuAction( + value: 'rename', + label: 'Rename…', + icon: Icons.edit_outlined, + ), + ], + ), + ), + ), +); + +void main() { + testWidgets('a phone opens a headed sheet with icon rows and destructive ' + 'actions last', (tester) async { + _size(tester, 430); + String? picked; + await tester.pumpWidget(_menu((value) => picked = value)); + await tester.tap(find.byKey(const Key('menu'))); + await tester.pumpAndSettle(); + + expect(find.byType(BottomSheet), findsOneWidget); + expect(find.text('notes.md'), findsOneWidget); + expect(find.text('Markdown · 2 KB'), findsOneWidget); + final rows = find.descendant( + of: find.byType(BottomSheet), + matching: find.byType(ListTile), + ); + expect(rows, findsNWidgets(3)); + final labels = [ + for (final tile in tester.widgetList(rows)) + (tile.title! as Text).data, + ]; + expect(labels, ['Open', 'Rename…', 'Delete…']); + for (final icon in [ + Icons.open_in_new, + Icons.edit_outlined, + Icons.delete_outline, + ]) { + expect( + find.descendant(of: rows, matching: find.byIcon(icon)), + findsOneWidget, + ); + } + // Rows are full width and at least 56 px tall. + final open = tester.getRect(find.widgetWithText(ListTile, 'Open')); + expect(open.height, greaterThanOrEqualTo(56)); + expect(open.width, closeTo(430, 1)); + // The destructive row reads in the error colour. + final scheme = Theme.of(tester.element(rows.first)).colorScheme; + final deleteText = tester.widget(find.text('Delete…')); + expect(deleteText.style?.color, scheme.error); + + await tester.tap(find.text('Rename…')); + await tester.pumpAndSettle(); + expect(find.byType(BottomSheet), findsNothing); + expect(picked, 'rename'); + }); + + testWidgets( + 'a wide app keeps an anchored menu with icons, destructive last', + (tester) async { + _size(tester, 1200); + String? picked; + await tester.pumpWidget(_menu((value) => picked = value)); + await tester.tap(find.byKey(const Key('menu'))); + await tester.pumpAndSettle(); + + expect(find.byType(BottomSheet), findsNothing); + final items = find.byType(PopupMenuItem); + expect(items, findsNWidgets(3)); + expect( + [ + for (final item in tester.widgetList>(items)) + item.value, + ], + ['open', 'rename', 'delete'], + ); + expect(find.byType(PopupMenuDivider), findsOneWidget); + expect(find.byIcon(Icons.edit_outlined), findsOneWidget); + expect(tester.getSize(items.first).width, greaterThanOrEqualTo(220)); + await tester.tap(find.text('Open')); + await tester.pumpAndSettle(); + expect(picked, 'open'); + }, + ); + + testWidgets('a bar More button opens the same sheet on a phone, with ' + 'submenu choices on a second sheet', (tester) async { + _size(tester, 430); + var closed = 0; + String? sort; + await tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: Center( + child: SegmentedMoreButton( + sheetTitle: 'Chat a', + sheetSubtitle: 'demo', + entries: [ + SegmentedOverflowEntry( + label: 'Close pane', + icon: Icons.close, + destructive: true, + onPressed: () => closed++, + ), + SegmentedOverflowEntry( + label: 'Sort', + icon: Icons.sort, + choices: [ + SegmentedMenuChoice( + label: 'Name', + selected: true, + onSelected: () => sort = 'name', + ), + SegmentedMenuChoice( + label: 'Size', + onSelected: () => sort = 'size', + ), + ], + ), + ], + ), + ), + ), + ), + ); + await tester.tap(find.byKey(segmentedMoreKey)); + await tester.pumpAndSettle(); + expect(find.text('Chat a'), findsOneWidget); + final labels = [ + for (final tile in tester.widgetList(find.byType(ListTile))) + (tile.title! as Text).data, + ]; + expect(labels, ['Sort', 'Close pane']); + + await tester.tap(find.text('Sort')); + await tester.pumpAndSettle(); + expect(find.text('Name'), findsOneWidget); + expect(find.byIcon(Icons.check), findsOneWidget); + await tester.tap(find.text('Size')); + await tester.pumpAndSettle(); + expect(sort, 'size'); + + await tester.tap(find.byKey(segmentedMoreKey)); + await tester.pumpAndSettle(); + await tester.tap(find.text('Close pane')); + await tester.pumpAndSettle(); + expect(closed, 1); + }); +} diff --git a/app/test/ui/layout/app_list_row_test.dart b/app/test/ui/layout/app_list_row_test.dart index 0faa92f5..3a771e19 100644 --- a/app/test/ui/layout/app_list_row_test.dart +++ b/app/test/ui/layout/app_list_row_test.dart @@ -106,7 +106,7 @@ void main() { await tester.pumpAndSettle(); expect(taps, 1); - // The overflow control is a Material menu. + // The overflow control opens a phone's bottom sheet at this width. expect( find.descendant( of: find.byKey(const Key('menu')), @@ -117,7 +117,13 @@ void main() { await tester.tap(find.byKey(const Key('menu'))); await tester.pumpAndSettle(); expect(taps, 1, reason: 'the menu is its own control'); - expect(find.byType(PopupMenuItem), findsNWidgets(2)); + expect( + find.descendant( + of: find.byType(BottomSheet), + matching: find.byType(ListTile), + ), + findsNWidgets(2), + ); await tester.tap(find.byKey(const Key('menu-delete'))); await tester.pumpAndSettle(); expect(picked, 'delete');