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
@@ -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 =