Build chat panes through one content builder
Phase 2.2 of docs/plans/floating-windows.md: buildChatPaneContent wraps a conversation in the scopes it needs and keys it by the runtime, so the tiling and (next) a floating window build the same subtree. The tiling uses it; behaviour is unchanged.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import 'chat_pane_content.dart';
|
||||
import 'chat_runtime.dart';
|
||||
import 'workspace/federated_workspace_store.dart';
|
||||
import '../../core/servers/chat/federated_chat_gateway.dart';
|
||||
import '../../core/servers/server_context.dart';
|
||||
import '../../shell/destination.dart';
|
||||
import '../../shell/shell_bar.dart';
|
||||
import '../../shell/shell_destination_menu.dart';
|
||||
@@ -27,8 +27,6 @@ import 'workspace/chat_workspace_binding.dart';
|
||||
import 'workspace/chat_workspace_snapshot.dart';
|
||||
import 'workspace/chat_workspace_store.dart';
|
||||
import 'conversation/chat_bar_tint.dart';
|
||||
import 'conversation/chat_efforts.dart';
|
||||
import 'conversation/chat_models.dart';
|
||||
import 'conversation/chat_pane_picker.dart';
|
||||
import 'conversation/chat_add_pane_picker.dart';
|
||||
import 'conversation/chat_sidebar_controls.dart';
|
||||
@@ -40,7 +38,6 @@ import 'workspace/chat_center_stage_keys.dart';
|
||||
import 'workspace/chat_pane_move_actions.dart';
|
||||
import 'workspace/chat_workspace_entrance.dart';
|
||||
import 'ui/sessions/chat_adaptive.dart';
|
||||
import 'conversation/chat_thread_view.dart';
|
||||
import 'conversation/composer_focus_request.dart';
|
||||
import 'conversation/composer_selection_focus.dart';
|
||||
import 'domain/chat_commands.dart';
|
||||
@@ -139,7 +136,7 @@ class _ChatScreenState extends State<ChatScreen>
|
||||
_runtime
|
||||
..gateway = widget.gateway
|
||||
..addListener(_runtimeChanged);
|
||||
_sessions.onSessionReplaced = _replacedElsewhere;
|
||||
_runtime.addSessionReplacedListener(_replacedElsewhere);
|
||||
final initial = widget.initialSessionId;
|
||||
if (initial != null && initial.isNotEmpty) {
|
||||
_workspace.open(initial);
|
||||
@@ -275,13 +272,6 @@ class _ChatScreenState extends State<ChatScreen>
|
||||
if (_workspace.paneCount == 0) _open(session);
|
||||
}
|
||||
|
||||
/// `/rename` was accepted for [id]: the opened row follows the shared title
|
||||
/// and the list re-reads it.
|
||||
void _renamed(String id, String title) {
|
||||
_runtime.renamed(id, title);
|
||||
unawaited(_sessions.refresh());
|
||||
}
|
||||
|
||||
/// `/close` was accepted: the conversation leaves, back to the list, which
|
||||
/// re-reads the closed row.
|
||||
void _closed(String sessionId) {
|
||||
@@ -328,25 +318,6 @@ class _ChatScreenState extends State<ChatScreen>
|
||||
);
|
||||
}
|
||||
|
||||
void _modelChanged(String id, ChatModelSelection applied) {
|
||||
if (mounted) _runtime.modelChanged(id, applied);
|
||||
}
|
||||
|
||||
/// An accepted mode switch updates the opened row, so reopening the chat in
|
||||
/// this visit shows it before the list re-reads. The list then re-reads, so
|
||||
/// a listing already in flight from before the switch is superseded rather
|
||||
/// than adopted over the accepted mode.
|
||||
void _modeChanged(String id, String mode, String name) {
|
||||
if (!mounted || !_runtime.modeChanged(id, mode, name)) return;
|
||||
unawaited(_sessions.refresh());
|
||||
}
|
||||
|
||||
/// An accepted thinking level updates the opened row like a mode switch.
|
||||
void _effortChanged(String id, ChatEffortState state) {
|
||||
if (!mounted || !_runtime.effortChanged(id, state)) return;
|
||||
unawaited(_sessions.refresh());
|
||||
}
|
||||
|
||||
@override
|
||||
JsonMap? _rowFor(String id) => _runtime.rowFor(id);
|
||||
|
||||
@@ -410,97 +381,62 @@ class _ChatScreenState extends State<ChatScreen>
|
||||
_sessions.removeListener(_availableSessionsChanged);
|
||||
_folds.removeListener(_nextChanged);
|
||||
_runtime.removeListener(_runtimeChanged);
|
||||
if (widget.runtime == null) {
|
||||
_runtime.dispose();
|
||||
} else {
|
||||
_sessions.onSessionReplaced = null;
|
||||
}
|
||||
_runtime.removeSessionReplacedListener(_replacedElsewhere);
|
||||
if (widget.runtime == null) _runtime.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget _thread(
|
||||
String selected,
|
||||
VoidCallback onBack, {
|
||||
ChatWorkspacePane? pane,
|
||||
BuildContext? paneContext,
|
||||
}) {
|
||||
final row = _rowFor(selected);
|
||||
final start = _runtime.startNotice;
|
||||
final thread = ChatThreadView(
|
||||
key: ValueKey<String>('chat-session-$selected'),
|
||||
gateway: _runtime.gatewayFor(selected),
|
||||
Widget _thread(ChatWorkspacePane pane) {
|
||||
final selected = pane.sessionId;
|
||||
return buildChatPaneContent(
|
||||
runtime: _runtime,
|
||||
sessionId: selected,
|
||||
title: '${row?['title'] ?? ''}'.trim(),
|
||||
session: row,
|
||||
syncToken: widget.syncToken,
|
||||
scrollPositions: _runtime.scrollPositions,
|
||||
transcripts: _runtime.transcripts,
|
||||
initialNotice: start != null && start.id == selected
|
||||
? start.notice
|
||||
: null,
|
||||
onBack: onBack,
|
||||
onModelChanged: (applied) => _modelChanged(selected, applied),
|
||||
onModeChanged: (mode, name) => _modeChanged(selected, mode, name),
|
||||
onEffortChanged: (state) => _effortChanged(selected, state),
|
||||
onNewSession: _startedNewSession,
|
||||
onSessionRenamed: (title) => _renamed(selected, title),
|
||||
onSessionClosed: () => _closed(selected),
|
||||
onColorSelected: (color) => _sessions.setColor(selected, color),
|
||||
onNextChat: _nextAfter(selected) != null
|
||||
? () => _openNext(selected)
|
||||
: null,
|
||||
useNativeBack: _page.open,
|
||||
pasteTarget:
|
||||
_workspaceVisible &&
|
||||
(pane == null || pane.id == _workspace.activePaneId),
|
||||
// A floating chat is never the active pane, so its composer takes a
|
||||
// paste while it has the keyboard.
|
||||
ownsPasteWhenFocused: pane != null && _workspace.isFloating(pane.id),
|
||||
showBackButton: pane == null
|
||||
? null
|
||||
: _page.open || !showsListBesideDetail(context),
|
||||
paneControls: pane == null
|
||||
? const []
|
||||
: _workspace.isFloating(pane.id)
|
||||
? _floatControls(pane)
|
||||
: [
|
||||
ChatBarAction(
|
||||
label: 'Add chat pane',
|
||||
onPressed: () => _addPane(paneContext ?? context),
|
||||
materialIcon: Icons.add_box_outlined,
|
||||
cupertinoIcon: CupertinoIcons.plus_square,
|
||||
),
|
||||
if (_workspace.paneCount > 1)
|
||||
placement: ChatPanePlacement(
|
||||
syncToken: widget.syncToken,
|
||||
onBack: _back,
|
||||
onNewSession: _startedNewSession,
|
||||
onSessionClosed: () => _closed(selected),
|
||||
onNextChat: _nextAfter(selected) != null
|
||||
? () => _openNext(selected)
|
||||
: null,
|
||||
useNativeBack: _page.open,
|
||||
pasteTarget: _workspaceVisible && pane.id == _workspace.activePaneId,
|
||||
// A floating chat is never the active pane, so its composer takes a
|
||||
// paste while it has the keyboard.
|
||||
ownsPasteWhenFocused: _workspace.isFloating(pane.id),
|
||||
showBackButton: _page.open || !showsListBesideDetail(context),
|
||||
paneControls: (paneContext) => _workspace.isFloating(pane.id)
|
||||
? _floatControls(pane)
|
||||
: [
|
||||
ChatBarAction(
|
||||
label: 'Open chats (${_workspace.paneCount})',
|
||||
onPressed: () => _pickPane(paneContext ?? context),
|
||||
materialIcon: Icons.view_quilt_outlined,
|
||||
cupertinoIcon: CupertinoIcons.square_split_2x2,
|
||||
label: 'Add chat pane',
|
||||
onPressed: () => _addPane(paneContext),
|
||||
materialIcon: Icons.add_box_outlined,
|
||||
cupertinoIcon: CupertinoIcons.plus_square,
|
||||
),
|
||||
if (_workspace.paneCount > 1 && showsListBesideDetail(context))
|
||||
chatCenterStageAction(ChatCenterStageController.instance),
|
||||
...chatPaneMoveActions(
|
||||
ChatWorkspacePaneScope.maybeOf(paneContext ?? context),
|
||||
onMove: (target) => _movePane(pane.id, target),
|
||||
),
|
||||
..._floatControls(pane),
|
||||
if (_workspace.paneCount > 1)
|
||||
ChatBarAction(
|
||||
label: 'Close pane',
|
||||
onPressed: () => _closePane(pane.id),
|
||||
materialIcon: Icons.close,
|
||||
cupertinoIcon: CupertinoIcons.xmark,
|
||||
if (_workspace.paneCount > 1)
|
||||
ChatBarAction(
|
||||
label: 'Open chats (${_workspace.paneCount})',
|
||||
onPressed: () => _pickPane(paneContext),
|
||||
materialIcon: Icons.view_quilt_outlined,
|
||||
cupertinoIcon: CupertinoIcons.square_split_2x2,
|
||||
),
|
||||
if (_workspace.paneCount > 1 && showsListBesideDetail(context))
|
||||
chatCenterStageAction(ChatCenterStageController.instance),
|
||||
...chatPaneMoveActions(
|
||||
ChatWorkspacePaneScope.maybeOf(paneContext),
|
||||
onMove: (target) => _movePane(pane.id, target),
|
||||
),
|
||||
],
|
||||
);
|
||||
return ChatComposerFocusScope(
|
||||
sessionId: selected,
|
||||
requests: _composerFocus,
|
||||
child: ServerContext.forServer(
|
||||
context,
|
||||
_runtime.serverIdFor(selected),
|
||||
thread,
|
||||
..._floatControls(pane),
|
||||
if (_workspace.paneCount > 1)
|
||||
ChatBarAction(
|
||||
label: 'Close pane',
|
||||
onPressed: () => _closePane(pane.id),
|
||||
materialIcon: Icons.close,
|
||||
cupertinoIcon: CupertinoIcons.xmark,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user