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:
@@ -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: [
|
||||
|
||||
Reference in New Issue
Block a user