124 lines
3.8 KiB
Dart
124 lines
3.8 KiB
Dart
part of 'screen.dart';
|
|
|
|
/// Pane layout, focus and route publication for one Chat destination visit.
|
|
mixin _ChatScreenWorkspace on State<ChatScreen> {
|
|
Map<String, JsonMap> get _openedSessions;
|
|
ChatComposerFocusRequests get _composerFocus;
|
|
JsonMap? _rowFor(String id);
|
|
void _back();
|
|
Widget _thread(
|
|
String selected,
|
|
VoidCallback onBack, {
|
|
ChatWorkspacePane? pane,
|
|
BuildContext? paneContext,
|
|
});
|
|
|
|
final ChatWorkspaceController _workspace = ChatWorkspaceController();
|
|
final GlobalKey _workspaceKey = GlobalKey();
|
|
bool _workspaceVisible = false;
|
|
bool _usedWorkspace = false;
|
|
String? _publishedWorkspaceSession;
|
|
String _workspaceSignature = '';
|
|
|
|
void _workspaceChanged() {
|
|
if (!mounted) return;
|
|
final signature =
|
|
'${_workspace.activePaneId}:${_workspace.panes.map((p) => '${p.id}=${p.sessionId}').join(',')}';
|
|
if (_workspaceSignature == signature) return;
|
|
_workspaceSignature = signature;
|
|
void update() {
|
|
if (!mounted) return;
|
|
setState(() {});
|
|
_publishWorkspaceRoute();
|
|
}
|
|
|
|
if (SchedulerBinding.instance.schedulerPhase ==
|
|
SchedulerPhase.persistentCallbacks) {
|
|
WidgetsBinding.instance.addPostFrameCallback((_) => update());
|
|
} else {
|
|
update();
|
|
}
|
|
}
|
|
|
|
void _publishWorkspaceRoute() {
|
|
if (!mounted) return;
|
|
final id = _workspace.activePane?.sessionId;
|
|
final destination = ShellBarScope.maybeOf(context)?.registry.focus;
|
|
if (!_workspaceVisible ||
|
|
id == null ||
|
|
id == _publishedWorkspaceSession ||
|
|
(destination != null && destination != AppDestination.chat)) {
|
|
return;
|
|
}
|
|
_publishedWorkspaceSession = id;
|
|
widget.onSessionSelected?.call(id);
|
|
}
|
|
|
|
void _split(JsonMap session, ChatSplitAxis axis) {
|
|
final id = '${session['id'] ?? ''}';
|
|
if (id.isEmpty) return;
|
|
_openedSessions[id] = session;
|
|
_workspaceVisible = true;
|
|
_workspace.splitActive(id, axis);
|
|
_composerFocus.request(id);
|
|
}
|
|
|
|
void _openBeside(JsonMap session) =>
|
|
_split(session, ChatSplitAxis.horizontal);
|
|
void _openBelow(JsonMap session) => _split(session, ChatSplitAxis.vertical);
|
|
|
|
void _closePane(String paneId) {
|
|
_workspace.close(paneId);
|
|
if (_workspace.paneCount == 0) _back();
|
|
}
|
|
|
|
void _pickPane(BuildContext context) => showChatPanePicker(
|
|
context,
|
|
panes: [
|
|
for (final pane in _workspace.panes)
|
|
(
|
|
id: pane.id,
|
|
title: '${_rowFor(pane.sessionId)?['title'] ?? pane.sessionId}',
|
|
),
|
|
],
|
|
activeId: _workspace.activePaneId,
|
|
onSelected: (id) {
|
|
_workspace.activate(id);
|
|
final session = _workspace.activePane?.sessionId;
|
|
if (session != null && chatSelectionFocusesComposer(const {})) {
|
|
_composerFocus.request(session);
|
|
}
|
|
},
|
|
);
|
|
|
|
Widget _workspaceView() => ChatWorkspace(
|
|
key: _workspaceKey,
|
|
controller: _workspace,
|
|
shortcutsEnabled: _workspaceVisible,
|
|
singlePane: !showsListBesideDetail(context),
|
|
onFocusPane: (pane) => _composerFocus.request(pane.sessionId),
|
|
paneBuilder: (context, pane, active) => Semantics(
|
|
selected: active,
|
|
child: DecoratedBox(
|
|
position: DecorationPosition.foreground,
|
|
decoration: BoxDecoration(
|
|
border: Border.all(
|
|
color: _workspace.paneCount > 1 && active
|
|
? (chatControlsStyleOf(context) == ChatControlsStyle.cupertino
|
|
? CupertinoTheme.of(context).primaryColor
|
|
: Theme.of(context).colorScheme.primary)
|
|
: Colors.transparent,
|
|
),
|
|
),
|
|
child: DetailPane(
|
|
key: ValueKey('chat-pane-detail-${pane.id}'),
|
|
destination: AppDestination.chat,
|
|
implyBack: false,
|
|
builder: (context) =>
|
|
_thread(pane.sessionId, _back, pane: pane, paneContext: context),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|