Connect independent resizable chat panes with routed focus and narrow layouts
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../ui/sessions/chat_adaptive.dart';
|
||||
|
||||
/// Selects a retained pane when the window cannot show every chat at once.
|
||||
Future<void> showChatPanePicker(
|
||||
BuildContext context, {
|
||||
required List<({String id, String title})> panes,
|
||||
required String? activeId,
|
||||
required ValueChanged<String> onSelected,
|
||||
}) async {
|
||||
final String? selected;
|
||||
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) {
|
||||
selected = await showCupertinoModalPopup<String>(
|
||||
context: context,
|
||||
builder: (context) => CupertinoActionSheet(
|
||||
title: const Text('Open chats'),
|
||||
actions: [
|
||||
for (final pane in panes)
|
||||
CupertinoActionSheetAction(
|
||||
isDefaultAction: pane.id == activeId,
|
||||
onPressed: () => Navigator.pop(context, pane.id),
|
||||
child: Text(pane.title),
|
||||
),
|
||||
],
|
||||
cancelButton: CupertinoActionSheetAction(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
selected = await showDialog<String>(
|
||||
context: context,
|
||||
builder: (context) => SimpleDialog(
|
||||
title: const Text('Open chats'),
|
||||
children: [
|
||||
for (final pane in panes)
|
||||
SimpleDialogOption(
|
||||
onPressed: () => Navigator.pop(context, pane.id),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(child: Text(pane.title)),
|
||||
if (pane.id == activeId) const Icon(Icons.check),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
if (selected != null && context.mounted) onSelected(selected);
|
||||
}
|
||||
@@ -90,6 +90,8 @@ class ChatThreadView extends StatefulWidget {
|
||||
this.fileBridge = const ArtifactFileBridge(),
|
||||
this.onColorSelected,
|
||||
this.onNextChat,
|
||||
this.paneControls = const [],
|
||||
this.showBackButton,
|
||||
});
|
||||
|
||||
final ApiGateway gateway;
|
||||
@@ -97,6 +99,8 @@ class ChatThreadView extends StatefulWidget {
|
||||
/// Opens the chat after this one in the list (wrapping to the first), from
|
||||
/// the bar's Next chat button; null when there is no other chat to open.
|
||||
final VoidCallback? onNextChat;
|
||||
final List<Widget> paneControls;
|
||||
final bool? showBackButton;
|
||||
|
||||
/// Sets the chat's shared colour (a palette name, null for none) from the
|
||||
/// information sheet; null leaves the sheet without the Colour choice.
|
||||
@@ -1154,9 +1158,11 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
/// the model and mode controls.
|
||||
Widget _header(BuildContext context, bool inShellBar) {
|
||||
final session = widget.session;
|
||||
final canGoBack = inShellBar
|
||||
? ModalRoute.of(context)?.impliesAppBarDismissal ?? false
|
||||
: true;
|
||||
final canGoBack =
|
||||
widget.showBackButton ??
|
||||
(inShellBar
|
||||
? ModalRoute.of(context)?.impliesAppBarDismissal ?? false
|
||||
: true);
|
||||
final answeredBy = latestReplyModel(_controller.messages);
|
||||
return _chrome.widgetFor('header', answeredBy, [
|
||||
widget,
|
||||
@@ -1191,13 +1197,16 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
showBack: canGoBack,
|
||||
// A pushed page keeps the platform's stock Back (pop this route); a
|
||||
// standalone conversation calls its owner.
|
||||
onBack: inShellBar ? null : widget.onBack,
|
||||
onBack: widget.showBackButton == true
|
||||
? widget.onBack
|
||||
: (inShellBar ? null : widget.onBack),
|
||||
// Each control is its own action, so each pops in (and sinks) on its
|
||||
// own. Natural width while the bar has room; past the title's share
|
||||
// the model ellipsises, and the mode keeps its whole name until it
|
||||
// would take more than half the pill. A session without a mode draws
|
||||
// no mode control, so no empty pill is ever drawn.
|
||||
controls: [
|
||||
...widget.paneControls,
|
||||
if (hasModel)
|
||||
ChatModelControl(
|
||||
key: ValueKey<String>('chat-model-${widget.sessionId}'),
|
||||
|
||||
Reference in New Issue
Block a user