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.
This commit is contained in:
2026-11-12 01:17:46 +00:00
parent 4f1b45571f
commit 3ce7f7a5dd
21 changed files with 1000 additions and 20 deletions
@@ -7,6 +7,7 @@ import '../../shell/detail_page.dart';
import 'chat_runtime.dart';
import 'conversation/chat_thread_view.dart';
import 'conversation/composer_focus_request.dart';
import 'workspace/chat_pane_commands.dart';
/// Where an open chat is shown and what that place alone decides: its Back,
/// its pane menu, whether it takes pastes, and what follows `/new` and
@@ -22,6 +23,7 @@ class ChatPanePlacement {
this.pasteTarget = false,
this.ownsPasteWhenFocused = false,
this.paneControls,
this.paneCommands,
this.onNextChat,
});
@@ -49,6 +51,9 @@ class ChatPanePlacement {
/// The pane menu's choices, built in the pane's own context.
final List<Widget> Function(BuildContext paneContext)? paneControls;
/// Choices the chat list hands to this chat's conversation to run.
final ChatPaneCommands? paneCommands;
final VoidCallback? onNextChat;
}
@@ -103,6 +108,7 @@ Widget buildChatPaneContent({
ownsPasteWhenFocused: placement.ownsPasteWhenFocused,
showBackButton: placement.showBackButton,
paneControls: placement.paneControls?.call(context) ?? const [],
paneCommands: placement.paneCommands,
),
),
);
@@ -0,0 +1,163 @@
part of 'screen.dart';
/// The move choices in the pane menu's order, with their pane label.
const _paneMoveChoices = [
(direction: ChatPaneDirection.up, action: SessionPaneAction.moveUp),
(direction: ChatPaneDirection.down, action: SessionPaneAction.moveDown),
(direction: ChatPaneDirection.left, action: SessionPaneAction.moveLeft),
(direction: ChatPaneDirection.right, action: SessionPaneAction.moveRight),
];
String _paneMoveLabel(ChatPaneDirection direction) => switch (direction) {
ChatPaneDirection.up => 'Move up',
ChatPaneDirection.down => 'Move down',
ChatPaneDirection.left => 'Move left',
ChatPaneDirection.right => 'Move right',
};
/// The chat list's row menu reaches the open panes' More choices. Each choice
/// is offered with the pane's own label and visibility, and runs the pane's
/// own handler for the row's chat, which is opened first.
mixin _ChatScreenPaneMenu on State<ChatScreen>, _ChatScreenWorkspace
implements SessionPaneMenu {
ChatPaneCommands get _paneCommands;
void _openBySelection(JsonMap session);
/// The open pane showing [id]'s chat, or null when it is not open.
ChatWorkspacePane? _paneShowing(String id) {
for (final pane in _workspace.panes) {
if (pane.sessionId == id) return pane;
}
return null;
}
@override
List<SessionPaneChoice> choicesFor(BuildContext context, JsonMap session) {
final id = '${session['id'] ?? ''}';
final panes = _workspace.paneCount;
final tiled = panes > 1;
final pane = _paneShowing(id);
// Moves exist only while the panes are tiled (the pane's own rule); the
// targets are absent otherwise.
final moves = pane == null ? null : _paneMoveTargets[pane.id];
final directory = '${session['directory'] ?? ''}'.trim();
return [
(
action: SessionPaneAction.addPane,
label: 'Add chat pane',
enabled: true,
),
if (tiled)
(
action: SessionPaneAction.openChats,
label: 'Open chats ($panes)',
enabled: true,
),
if (tiled && showsListBesideDetail(context))
(
action: SessionPaneAction.centerStage,
label: chatCenterStageLabel(ChatCenterStageController.instance),
enabled: true,
),
if (moves != null)
for (final move in _paneMoveChoices)
(
action: move.action,
label:
'${_paneMoveLabel(move.direction)} '
'(${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,
label: 'Chat details',
enabled: true,
),
(action: SessionPaneAction.files, label: 'Files', enabled: true),
(
action: SessionPaneAction.runCommand,
label: chatShellRunActionLabel,
enabled: true,
),
if (_paneCommands.hasFinished(id))
(
action: SessionPaneAction.dismissFinished,
label: chatShellDismissAllLabel,
enabled: true,
),
if (TerminalScope.maybeOf(context) != null && directory.isNotEmpty)
(
action: SessionPaneAction.openTerminal,
label: terminalOpenActionLabel,
enabled: true,
),
];
}
@override
void run(BuildContext context, JsonMap session, SessionPaneAction action) {
final id = '${session['id'] ?? ''}';
if (id.isEmpty) return;
switch (action) {
case SessionPaneAction.addPane:
_openBySelection(session);
_addPane(context);
case SessionPaneAction.openChats:
_openBySelection(session);
_pickPane(context);
case SessionPaneAction.centerStage:
_openBySelection(session);
ChatCenterStageController.instance.toggle();
case SessionPaneAction.moveUp:
_moveRowPane(session, ChatPaneDirection.up);
case SessionPaneAction.moveDown:
_moveRowPane(session, ChatPaneDirection.down);
case SessionPaneAction.moveLeft:
_moveRowPane(session, ChatPaneDirection.left);
case SessionPaneAction.moveRight:
_moveRowPane(session, ChatPaneDirection.right);
case SessionPaneAction.closePane:
for (final pane
in _workspace.panes
.where((pane) => pane.sessionId == id)
.toList()) {
_closePane(pane.id);
}
case SessionPaneAction.chatDetails:
_requestInOpenChat(session, ChatPaneCommand.details);
case SessionPaneAction.files:
_requestInOpenChat(session, ChatPaneCommand.files);
case SessionPaneAction.runCommand:
_requestInOpenChat(session, ChatPaneCommand.runCommand);
case SessionPaneAction.openTerminal:
_requestInOpenChat(session, ChatPaneCommand.openTerminal);
case SessionPaneAction.dismissFinished:
_requestInOpenChat(session, ChatPaneCommand.dismissFinished);
}
}
/// Swaps the pane showing [session]'s chat with its neighbour across
/// [direction], as that pane's own move does. The chat is already open here,
/// so nothing is opened first.
void _moveRowPane(JsonMap session, ChatPaneDirection direction) {
final pane = _paneShowing('${session['id'] ?? ''}');
if (pane == null) return;
final target = _paneMoveTargets[pane.id]?[direction];
if (target == null) return;
_movePane(pane.id, target);
}
/// Opens [session] and hands [command] to its conversation, which runs it
/// once built.
void _requestInOpenChat(JsonMap session, ChatPaneCommand command) {
_openBySelection(session);
_paneCommands.request('${session['id'] ?? ''}', command);
}
}
@@ -56,6 +56,15 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
Set<String> _visibleWorkspaceSessions = const {};
/// Each pane's move targets as the workspace last laid them out. Read when
/// the chat list's row menu opens; it needs no rebuild of its own.
Map<String, Map<ChatPaneDirection, String>> _paneMoveTargets = const {};
void _paneMoveTargetsChanged(
Map<String, Map<ChatPaneDirection, String>> targets,
) {
_paneMoveTargets = targets;
}
void _workspaceVisibilityChanged(Set<String> sessions) {
if (!mounted || setEquals(_visibleWorkspaceSessions, sessions)) return;
setState(() => _visibleWorkspaceSessions = Set.unmodifiable(sessions));
@@ -318,6 +327,7 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
chatColorShade(context, chatSessionColor(_rowFor(pane.sessionId))),
controller: _workspace,
onVisibleSessionIdsChanged: _workspaceVisibilityChanged,
onMoveTargetsChanged: _paneMoveTargetsChanged,
shortcutsEnabled: _workspaceVisible,
singlePane: !showsListBesideDetail(context),
mobilePeeks: true,
@@ -20,6 +20,7 @@ import '../../../core/transport/pipelines_client.dart'
import '../domain/chat_shown_items.dart';
import '../domain/chat_transcript.dart';
import '../domain/chat_turn_diffs.dart';
import '../workspace/chat_pane_commands.dart';
import '../ui/sessions/chat_color_picker.dart';
import '../ui/sessions/session_actions.dart';
import '../ui/sessions/session_row_content.dart';
@@ -118,6 +119,7 @@ class ChatThreadView extends StatefulWidget {
this.onColorSelected,
this.onNextChat,
this.paneControls = const [],
this.paneCommands,
this.sidebarControl,
this.showBackButton,
this.useNativeBack = false,
@@ -130,6 +132,9 @@ class ChatThreadView extends StatefulWidget {
/// Retained for existing callers; Next chat is no longer shown in the header.
final VoidCallback? onNextChat;
final List<Widget> paneControls;
/// The chat list's requests for this chat, run as the More menu runs them.
final ChatPaneCommands? paneCommands;
final Widget? sidebarControl;
final bool? showBackButton;
final bool useNativeBack;
@@ -214,7 +219,8 @@ class _ChatThreadViewState extends State<ChatThreadView> {
/// The operator's own shell commands in this chat (see `../shell/`).
late ChatShellRunsController _shellRuns = _attachShellRuns();
ChatShellRunsController _attachShellRuns() =>
ChatShellRunsController(widget.gateway, widget.sessionId);
ChatShellRunsController(widget.gateway, widget.sessionId)
..addListener(_reportFinishedRuns);
late ChatRowKeys _rowKeys = ChatRowKeys();
final _sentEntrances = ChatSentEntrances();
final _rowWidgets = ChatRowWidgets();
@@ -284,8 +290,51 @@ class _ChatThreadViewState extends State<ChatThreadView> {
if (mounted) _openFilesSheet();
});
}
_takeCommands();
}
/// Runs each request the chat list made for this chat, as the More menu does.
/// Waits until the saved Files state has loaded: Files is a toggle, and a
/// toggle taken before that load would be overwritten by it.
void _takeCommands() {
final commands = widget.paneCommands;
if (commands == null || !mounted || !_filesPrefsLoaded) return;
for (
var command = commands.take(widget.sessionId);
command != null;
command = commands.take(widget.sessionId)
) {
switch (command) {
case ChatPaneCommand.details:
unawaited(_openInfo());
case ChatPaneCommand.files:
_toggleFiles();
case ChatPaneCommand.runCommand:
_runShellFromMenu();
case ChatPaneCommand.openTerminal:
_openTerminalFromMenu();
case ChatPaneCommand.dismissFinished:
_dismissFinishedShellRuns();
}
}
}
/// Tells the chat list whether this chat holds finished command runs.
void _reportFinishedRuns() => widget.paneCommands?.setFinished(
widget.sessionId,
_shellRuns.finishedIds.isNotEmpty,
);
void _openTerminalFromMenu() => openInTerminal(
context,
widget.gateway,
'${widget.session?['directory'] ?? ''}'.trim(),
onRefused: _terminalRefused,
);
void _terminalRefused(String refusal) =>
_showCommandNotice("Couldn't open a terminal: $refusal", failed: true);
void _toggleFiles() {
final next = !_filesVisible;
if (!mounted) return;
@@ -585,11 +634,21 @@ class _ChatThreadViewState extends State<ChatThreadView> {
_savedPosition = widget.scrollPositions?.read(widget.sessionId);
_adoptCachedTranscript();
_seedCommandNotice();
widget.paneCommands?.addListener(_takeCommands);
_reportFinishedRuns();
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) _takeCommands();
});
}
@override
void didUpdateWidget(covariant ChatThreadView oldWidget) {
super.didUpdateWidget(oldWidget);
if (!identical(oldWidget.paneCommands, widget.paneCommands)) {
oldWidget.paneCommands?.removeListener(_takeCommands);
oldWidget.paneCommands?.setFinished(oldWidget.sessionId, false);
widget.paneCommands?.addListener(_takeCommands);
}
if (oldWidget.gateway != widget.gateway ||
oldWidget.sessionId != widget.sessionId) {
// The conversation being left keeps the position the operator chose.
@@ -604,12 +663,19 @@ class _ChatThreadViewState extends State<ChatThreadView> {
_composer.dispose();
_shellRuns.dispose();
_shellRuns = _attachShellRuns();
oldWidget.paneCommands?.setFinished(oldWidget.sessionId, false);
_reportFinishedRuns();
_files.removeListener(_persistFilesPreferences);
_files.dispose();
_files = _newFilesController()..addListener(_persistFilesPreferences);
_filesVisible = false;
_filesPrefsLoaded = false;
_reportedCenterStageFilesWidth = null;
unawaited(_loadFilesPreferences());
// A request the list made for this chat before the pane showed it.
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) _takeCommands();
});
_closed = false;
_controller = _attach();
_composer = _attachComposer();
@@ -676,6 +742,8 @@ class _ChatThreadViewState extends State<ChatThreadView> {
void dispose() {
_persistPosition();
_saveTranscript(widget.transcripts, widget.sessionId);
widget.paneCommands?.removeListener(_takeCommands);
widget.paneCommands?.setFinished(widget.sessionId, false);
_scroll.dispose();
_composer.dispose();
_controller.dispose();
@@ -1427,10 +1495,7 @@ class _ChatThreadViewState extends State<ChatThreadView> {
context,
gateway: widget.gateway,
directory: directory,
onRefused: (refusal) => _showCommandNotice(
"Couldn't open a terminal: $refusal",
failed: true,
),
onRefused: _terminalRefused,
),
],
controls: [
+21 -1
View File
@@ -20,6 +20,12 @@ 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';
import 'workspace/chat_pane_commands.dart';
import 'workspace/chat_float_shortcut.dart';
import 'workspace/chat_workspace_binding.dart';
import 'workspace/chat_workspace_snapshot.dart';
@@ -34,6 +40,7 @@ import 'workspace/chat_center_stage_action.dart';
import 'workspace/chat_center_stage_controller.dart';
import 'workspace/chat_center_stage_keys.dart';
import 'workspace/chat_pane_move_actions.dart';
import 'workspace/chat_pane_move_shortcuts.dart';
import 'workspace/chat_workspace_entrance.dart';
import 'ui/sessions/chat_adaptive.dart';
import 'conversation/composer_focus_request.dart';
@@ -49,6 +56,7 @@ import 'ui/sessions/chat_sessions_screen.dart';
import '../../ui/input/keyboard_owner.dart';
part 'chat_screen_float.dart';
part 'chat_screen_pane_menu.dart';
part 'chat_screen_keys.dart';
part 'chat_screen_workspace.dart';
@@ -103,7 +111,11 @@ class ChatScreen extends StatefulWidget {
}
class _ChatScreenState extends State<ChatScreen>
with _ChatScreenWorkspace, _ChatScreenKeys, _ChatScreenFloat {
with
_ChatScreenWorkspace,
_ChatScreenKeys,
_ChatScreenFloat,
_ChatScreenPaneMenu {
/// The chats' shared state: the list, opened rows, accepted models,
/// transcript positions and caches (see [ChatRuntime]).
late final ChatRuntime _runtime =
@@ -221,6 +233,7 @@ class _ChatScreenState extends State<ChatScreen>
/// Opens [session] chosen by a tap, click or Next chat: its composer takes
/// focus on a desktop host or after a mouse click, not from a finger on a
/// phone or tablet (see [chatSelectionFocusesComposer]).
@override
void _openBySelection(JsonMap session) =>
_open(session, focusComposer: chatSelectionFocusesComposer(session));
@@ -368,6 +381,7 @@ class _ChatScreenState extends State<ChatScreen>
@override
void dispose() {
_paneCommands.dispose();
HardwareKeyboard.instance.removeHandler(_cycleChatKey);
HardwareKeyboard.instance.removeHandler(_slashFocusKey);
_page.dispose();
@@ -384,6 +398,10 @@ class _ChatScreenState extends State<ChatScreen>
super.dispose();
}
/// Requests the chat list hands to an open chat (see [_ChatScreenPaneMenu]).
@override
final _paneCommands = ChatPaneCommands();
@override
Widget _thread(ChatWorkspacePane pane) {
final selected = pane.sessionId;
@@ -401,6 +419,7 @@ class _ChatScreenState extends State<ChatScreen>
useNativeBack: _page.open,
pasteTarget: _workspaceVisible && pane.id == _workspace.activePaneId,
showBackButton: _page.open || !showsListBesideDetail(context),
paneCommands: _paneCommands,
paneControls: (paneContext) => [
ChatBarAction(
label: 'Add chat pane',
@@ -467,6 +486,7 @@ class _ChatScreenState extends State<ChatScreen>
onOpenBeside: beside ? _openBeside : null,
onOpenBelow: _openBelow,
onFloat: _floatsHere ? _floatSession : null,
paneMenu: this,
onShortcutOpen: _openByShortcut,
onSessions: _adoptRows,
activeSessionId: selected,
@@ -4,6 +4,7 @@ import '../../../../core/api_gateway.dart';
import '../../domain/chat_sessions.dart';
import 'chat_adaptive.dart';
import 'session_list_material.dart';
import 'session_pane_menu.dart';
import 'session_row_style.dart';
typedef ChatSessionSection = ({String title, List<JsonMap> sessions});
@@ -34,6 +35,7 @@ class ChatSessionsBody extends StatelessWidget {
this.onOpenBeside,
this.onOpenBelow,
this.onFloat,
this.paneMenu,
required this.onRename,
required this.onClose,
required this.onReopen,
@@ -65,6 +67,7 @@ class ChatSessionsBody extends StatelessWidget {
final ValueChanged<JsonMap>? onOpenBeside;
final ValueChanged<JsonMap>? onOpenBelow;
final ValueChanged<JsonMap>? onFloat;
final SessionPaneMenu? paneMenu;
final ValueChanged<JsonMap> onRename;
final ValueChanged<JsonMap> onClose;
final ValueChanged<JsonMap> onReopen;
@@ -103,6 +106,7 @@ class ChatSessionsBody extends StatelessWidget {
onOpenBeside: onOpenBeside,
onOpenBelow: onOpenBelow,
onFloat: onFloat,
paneMenu: paneMenu,
onRename: onRename,
onClose: onClose,
onReopen: onReopen,
@@ -23,6 +23,7 @@ import 'chat_sessions_controller.dart';
import 'create_chat_dialog.dart';
import 'rename_chat_dialog.dart';
import 'session_actions.dart';
import 'session_pane_menu.dart';
/// Browses server-owned sessions. Opening a row is read-only at this layer.
class ChatSessionsScreen extends StatefulWidget {
@@ -33,6 +34,7 @@ class ChatSessionsScreen extends StatefulWidget {
this.onOpenBeside,
this.onOpenBelow,
this.onFloat,
this.paneMenu,
this.onShortcutOpen,
this.embedded = false,
this.syncToken = 0,
@@ -54,6 +56,9 @@ class ChatSessionsScreen extends StatefulWidget {
/// Floats the chat in a window over the app; absent when it cannot.
final ValueChanged<JsonMap>? onFloat;
/// The open panes' More choices for each row's menu, when the list has panes.
final SessionPaneMenu? paneMenu;
/// Opens a row the shell's Ctrl+1…Ctrl+9 named, so the destination can put
/// the keyboard in its composer; null opens it like a tap ([onOpen]).
final void Function(JsonMap session)? onShortcutOpen;
@@ -353,6 +358,7 @@ class _ChatSessionsScreenState extends State<ChatSessionsScreen> {
? null
: _openBelow,
onFloat: widget.onFloat,
paneMenu: widget.paneMenu,
onRename: _rename,
onClose: _close,
onReopen: _reopen,
@@ -3,6 +3,7 @@ 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';
@@ -34,6 +35,7 @@ class SessionActionsButton extends StatelessWidget {
this.allowOpenBeside = false,
this.allowOpenBelow = false,
this.allowFloat = false,
this.paneMenu,
});
final JsonMap session;
@@ -43,31 +45,48 @@ class SessionActionsButton extends StatelessWidget {
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<SessionAction>(
return AppOverflowMenu<Object>(
label: sessionActionsLabel(session, duplicateTitles),
sheetTitle: chatSessionTitle(session),
actions: [
actionsBuilder: () => [
if (allowOpenBeside)
const AppMenuAction(
const AppMenuAction<Object>(
value: SessionAction.openBeside,
label: 'Open to the right',
),
if (allowOpenBelow)
const AppMenuAction(
const AppMenuAction<Object>(
value: SessionAction.openBelow,
label: 'Open below',
),
if (allowFloat)
AppMenuAction(
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(value: item.action, label: item.label),
AppMenuAction<Object>(value: item.action, label: item.label),
],
onSelected: (_, action) => onSelected(action),
onSelected: (context, value) {
if (value is SessionAction) {
onSelected(value);
} else if (value is SessionPaneAction) {
paneMenu?.run(context, session, value);
}
},
);
}
}
@@ -5,6 +5,7 @@ import '../../../../ui/layout/collapsible_list_section.dart';
import '../../domain/chat_sessions.dart';
import 'chat_adaptive.dart';
import 'chat_sessions_body.dart';
import 'session_pane_menu.dart';
import 'session_row_memo.dart';
/// One entry of a chat section's lazy list: a directory header, a row or a
@@ -90,6 +91,7 @@ SessionListItem chatSessionRowItem(
ValueChanged<JsonMap>? onOpenBeside,
ValueChanged<JsonMap>? onOpenBelow,
ValueChanged<JsonMap>? onFloat,
SessionPaneMenu? paneMenu,
required ValueChanged<JsonMap> onStar,
required ValueChanged<JsonMap>? onColor,
required ValueChanged<JsonMap> onRename,
@@ -113,6 +115,7 @@ SessionListItem chatSessionRowItem(
onOpenBeside: onOpenBeside,
onOpenBelow: onOpenBelow,
onFloat: onFloat,
paneMenu: paneMenu,
onStar: onStar,
onColor: onColor,
onRename: onRename,
@@ -5,6 +5,7 @@ import '../../../../core/api_gateway.dart';
import 'chat_sessions_body.dart';
import 'chat_list_viewport.dart';
import 'session_list_items.dart';
import 'session_pane_menu.dart';
class MaterialSessionList extends StatelessWidget {
const MaterialSessionList({
@@ -16,6 +17,7 @@ class MaterialSessionList extends StatelessWidget {
this.onOpenBeside,
this.onOpenBelow,
this.onFloat,
this.paneMenu,
required this.onRename,
required this.onClose,
required this.onReopen,
@@ -43,6 +45,7 @@ class MaterialSessionList extends StatelessWidget {
final ValueChanged<JsonMap>? onOpenBeside;
final ValueChanged<JsonMap>? onOpenBelow;
final ValueChanged<JsonMap>? onFloat;
final SessionPaneMenu? paneMenu;
final ValueChanged<JsonMap> onRename;
final ValueChanged<JsonMap> onClose;
final ValueChanged<JsonMap> onReopen;
@@ -117,6 +120,7 @@ class MaterialSessionList extends StatelessWidget {
onOpenBeside: onOpenBeside,
onOpenBelow: onOpenBelow,
onFloat: onFloat,
paneMenu: paneMenu,
onStar: onStar,
onColor: onColor,
onRename: onRename,
@@ -0,0 +1,41 @@
import 'package:flutter/widgets.dart';
import '../../../../core/api_gateway.dart';
/// The pane More menu's choices that a chat row's menu also offers.
enum SessionPaneAction {
addPane,
openChats,
centerStage,
moveUp,
moveDown,
moveLeft,
moveRight,
closePane,
chatDetails,
files,
runCommand,
openTerminal,
dismissFinished,
}
/// One pane choice as the row's menu shows it: the pane's own label. A
/// disabled choice stays listed, as the pane lists it (a move with no pane
/// across that edge).
typedef SessionPaneChoice = ({
SessionPaneAction action,
String label,
bool enabled,
});
/// The open chat panes, as a chat row's menu reaches them. The offers are read
/// when the menu opens, so they follow the panes as they are then.
abstract interface class SessionPaneMenu {
/// The pane More menu's choices for [session] now, in the pane's order and
/// with its visibility (narrow layouts, one pane, no window or terminal).
List<SessionPaneChoice> choicesFor(BuildContext context, JsonMap session);
/// Runs [action] for [session], opening the chat first where the pane's
/// handler acts on an open chat.
void run(BuildContext context, JsonMap session, SessionPaneAction action);
}
@@ -15,6 +15,7 @@ import 'chat_session_state.dart';
import 'session_actions.dart';
import 'session_activity_badge.dart';
import 'session_harness_icon.dart';
import 'session_pane_menu.dart';
import 'session_row_style.dart';
/// One chat in the list, in the app's shared row on both hosts: the harness
@@ -34,6 +35,7 @@ class ChatSessionRow extends StatelessWidget {
this.onOpenBeside,
this.onOpenBelow,
this.onFloat,
this.paneMenu,
required this.onAction,
this.selected = false,
this.visible = false,
@@ -52,6 +54,7 @@ class ChatSessionRow extends StatelessWidget {
final ValueChanged<JsonMap>? onOpenBeside;
final ValueChanged<JsonMap>? onOpenBelow;
final ValueChanged<JsonMap>? onFloat;
final SessionPaneMenu? paneMenu;
final VoidCallback? onLongPress;
final ValueChanged<SessionAction> onAction;
final bool selected;
@@ -167,6 +170,7 @@ class ChatSessionRow extends StatelessWidget {
allowOpenBeside: onOpenBeside != null,
allowOpenBelow: onOpenBelow != null,
allowFloat: onFloat != null,
paneMenu: paneMenu,
),
),
);
@@ -4,6 +4,7 @@ import '../../../../core/api_gateway.dart';
import '../../../../ui/layout/memo_subtree.dart';
import '../../domain/chat_sessions.dart';
import 'session_actions.dart';
import 'session_pane_menu.dart';
import 'session_row_content.dart';
/// A chat row that rebuilds only when its own session or state changes, so a
@@ -23,6 +24,7 @@ Widget memoChatSessionRow({
ValueChanged<JsonMap>? onOpenBeside,
ValueChanged<JsonMap>? onOpenBelow,
ValueChanged<JsonMap>? onFloat,
SessionPaneMenu? paneMenu,
required ValueChanged<JsonMap> onStar,
required ValueChanged<JsonMap>? onColor,
required ValueChanged<JsonMap> onRename,
@@ -44,6 +46,7 @@ Widget memoChatSessionRow({
onOpenBeside,
onOpenBelow,
onFloat,
paneMenu,
onStar,
onColor,
onRename,
@@ -63,6 +66,7 @@ Widget memoChatSessionRow({
onOpenBeside: onOpenBeside,
onOpenBelow: onOpenBelow,
onFloat: onFloat,
paneMenu: paneMenu,
// A long-press is the touch way to the colour, the row's quick mark.
onLongPress: selectionOnly || onColor == null
? null
@@ -3,14 +3,19 @@ import 'package:flutter/material.dart';
import '../ui/sessions/chat_adaptive.dart';
import 'chat_center_stage_controller.dart';
/// The center-stage toggle's label, naming its keyboard shortcut.
String chatCenterStageLabel(ChatCenterStageController controller) {
final shortcut = chatCenterStageShortcutLabel();
return controller.value
? 'Leave center stage ($shortcut)'
: 'Center stage ($shortcut)';
}
/// The pane menu's center-stage toggle, naming its keyboard shortcut.
ChatBarAction chatCenterStageAction(ChatCenterStageController controller) {
final shortcut = chatCenterStageShortcutLabel();
return ChatBarAction(
identifier: 'chat-center-stage-toggle',
label: controller.value
? 'Leave center stage ($shortcut)'
: 'Center stage ($shortcut)',
label: chatCenterStageLabel(controller),
onPressed: controller.toggle,
materialIcon: controller.value
? Icons.view_quilt_outlined
@@ -0,0 +1,47 @@
import 'package:flutter/foundation.dart';
/// A pane menu action that lives in the conversation itself (its own state),
/// so a chat list choice asks the open conversation to run it.
enum ChatPaneCommand {
details,
files,
runCommand,
openTerminal,
dismissFinished,
}
/// Hands a chat list choice to the open conversation of one chat. The list
/// opens the chat first; its conversation takes the request once it is built
/// and runs the same handler its own More menu runs.
///
/// It also records which chats have finished command runs, so the list offers
/// Dismiss all finished commands where the pane would.
class ChatPaneCommands extends ChangeNotifier {
final List<(String, ChatPaneCommand)> _pending = [];
final Set<String> _finished = {};
/// Asks [sessionId]'s conversation to run [command].
void request(String sessionId, ChatPaneCommand command) {
_pending.add((sessionId, command));
notifyListeners();
}
/// Takes the oldest request for [sessionId], or null when there is none.
ChatPaneCommand? take(String sessionId) {
final index = _pending.indexWhere((entry) => entry.$1 == sessionId);
if (index < 0) return null;
return _pending.removeAt(index).$2;
}
/// Whether [sessionId]'s conversation holds finished command runs.
bool hasFinished(String sessionId) => _finished.contains(sessionId);
/// Called by a conversation as its finished runs change.
void setFinished(String sessionId, bool finished) {
if (finished) {
_finished.add(sessionId);
} else {
_finished.remove(sessionId);
}
}
}
@@ -35,6 +35,22 @@ enum ChatPaneChord { focus, move }
);
}
/// The move chord as text, for a menu item that cannot show it beside the
/// label: "Command+Option+Shift+Up" on macOS, "Ctrl+Alt+Shift+Up" elsewhere.
String chatPaneMoveShortcutLabel(
ChatPaneDirection direction, {
TargetPlatform? platform,
}) {
final mac = (platform ?? defaultTargetPlatform) == TargetPlatform.macOS;
final key = switch (direction) {
ChatPaneDirection.left => 'Left',
ChatPaneDirection.right => 'Right',
ChatPaneDirection.up => 'Up',
ChatPaneDirection.down => 'Down',
};
return mac ? 'Command+Option+Shift+$key' : 'Ctrl+Alt+Shift+$key';
}
/// The move chord as a menu shows it: Command on macOS, Ctrl elsewhere.
SingleActivator chatPaneMoveActivator(
ChatPaneDirection direction, {
@@ -40,6 +40,7 @@ class ChatWorkspace extends StatefulWidget {
this.animationStyle,
this.paneTitle,
this.onVisibleSessionIdsChanged,
this.onMoveTargetsChanged,
this.centerStage,
this.paneColor,
});
@@ -54,6 +55,11 @@ class ChatWorkspace extends StatefulWidget {
final String Function(ChatWorkspacePane)? paneTitle;
final ValueChanged<Set<String>>? onVisibleSessionIdsChanged;
/// Reports each pane's move targets (see [ChatWorkspacePaneScope.moveTargets])
/// after a layout that changed them. Empty while the panes are not tiled.
final ValueChanged<Map<String, Map<ChatPaneDirection, String>>>?
onMoveTargetsChanged;
/// While true on a wide window, the active chat takes center stage and the
/// others line up beside it (see [ChatCenterStageLayout]).
final ValueListenable<bool>? centerStage;
@@ -110,6 +116,30 @@ class _ChatWorkspaceState extends State<ChatWorkspace>
});
}
Map<String, Map<ChatPaneDirection, String>> _reportedMoveTargets = const {};
void _reportMoveTargets(Map<String, Map<ChatPaneDirection, String>> targets) {
if (_sameMoveTargets(targets, _reportedMoveTargets)) return;
_reportedMoveTargets = targets;
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted && identical(targets, _reportedMoveTargets)) {
widget.onMoveTargetsChanged?.call(targets);
}
});
}
static bool _sameMoveTargets(
Map<String, Map<ChatPaneDirection, String>> a,
Map<String, Map<ChatPaneDirection, String>> b,
) {
if (a.length != b.length) return false;
for (final MapEntry(key: id, value: targets) in a.entries) {
final other = b[id];
if (other == null || !mapEquals(targets, other)) return false;
}
return true;
}
void _reportPaneExtraWidth(String paneId, double width) {
if ((_paneExtraWidths[paneId] ?? 0) == width) return;
if (width == 0) {
@@ -234,6 +264,7 @@ class _ChatWorkspaceState extends State<ChatWorkspace>
direction: ?geometry.adjacent(pane.id, direction),
},
};
_reportMoveTargets(moveTargets);
// Finish one joined loop before taking the latest requested role.
// Repeated taps/chords never tear the tape or duplicate a live chat.
final activeId =