Show the mode picker and the add-pane picker as menus on desktop
Phase 2b.2 of docs/plans/floating-windows.md, implemented by pipeline run 303: both use showAppChoiceMenu (a menu anchored to its button on a wide app, a bottom sheet on a phone).
This commit is contained in:
@@ -276,22 +276,34 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
|
||||
},
|
||||
);
|
||||
|
||||
void _addPane(BuildContext context) => showAddChatPanePicker(
|
||||
context,
|
||||
controller: _sessionsForSidebar,
|
||||
sidebarFolds: _foldsForSidebar,
|
||||
excludedSessionIds: _workspace.panes.map((pane) => pane.sessionId).toSet(),
|
||||
onSelected: (session) {
|
||||
if (!showsListBesideDetail(context)) {
|
||||
// Save a horizontal desktop layout underneath the phone tape. Keep
|
||||
// the rail compact so unfolding leaves room for the panes themselves.
|
||||
_setSidebarMode(ChatSidebarMode.compact);
|
||||
_openBeside(session);
|
||||
} else {
|
||||
_openBelow(session);
|
||||
}
|
||||
},
|
||||
);
|
||||
void _addPane(BuildContext context) {
|
||||
// The action normally lives in the pane's More menu. Let that menu finish
|
||||
// closing before pushing the picker, otherwise its root-overlay teardown
|
||||
// can hide the newly opened anchored menu.
|
||||
Future<void>.delayed(Duration.zero, () {
|
||||
if (!context.mounted) return;
|
||||
unawaited(
|
||||
showAddChatPanePicker(
|
||||
context,
|
||||
controller: _sessionsForSidebar,
|
||||
sidebarFolds: _foldsForSidebar,
|
||||
excludedSessionIds: _workspace.panes
|
||||
.map((pane) => pane.sessionId)
|
||||
.toSet(),
|
||||
onSelected: (session) {
|
||||
if (!showsListBesideDetail(context)) {
|
||||
// Save a horizontal desktop layout underneath the phone tape.
|
||||
// Keep the rail compact so unfolding leaves room for the panes.
|
||||
_setSidebarMode(ChatSidebarMode.compact);
|
||||
_openBeside(session);
|
||||
} else {
|
||||
_openBelow(session);
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Widget _workspaceView() => SafeArea(
|
||||
top: false,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../../ui/adaptive/app_popups.dart';
|
||||
import '../domain/chat_cycle.dart';
|
||||
import '../ui/sessions/chat_adaptive.dart';
|
||||
import '../ui/sessions/chat_sessions_body.dart';
|
||||
@@ -16,29 +16,25 @@ Future<void> showAddChatPanePicker(
|
||||
required Set<String> excludedSessionIds,
|
||||
required ValueChanged<JsonMap> onSelected,
|
||||
}) async {
|
||||
final cupertino = chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
Widget content(BuildContext context) => FractionallySizedBox(
|
||||
heightFactor: 0.85,
|
||||
child: _AddChatPanePicker(
|
||||
controller: controller,
|
||||
sidebarFolds: sidebarFolds,
|
||||
excludedSessionIds: excludedSessionIds,
|
||||
cupertino: cupertino,
|
||||
final selected = await showAppChoiceMenu<JsonMap>(
|
||||
context,
|
||||
width: 420,
|
||||
builder: (popupContext) => ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
maxHeight: MediaQuery.sizeOf(popupContext).height * 0.85,
|
||||
),
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) => SizedBox(
|
||||
height: constraints.maxHeight,
|
||||
child: _AddChatPanePicker(
|
||||
controller: controller,
|
||||
sidebarFolds: sidebarFolds,
|
||||
excludedSessionIds: excludedSessionIds,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
final selected = cupertino
|
||||
? await showCupertinoModalPopup<JsonMap>(
|
||||
context: context,
|
||||
builder: content,
|
||||
)
|
||||
: await showModalBottomSheet<JsonMap>(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
useSafeArea: true,
|
||||
showDragHandle: true,
|
||||
constraints: const BoxConstraints(maxWidth: 720),
|
||||
builder: content,
|
||||
);
|
||||
if (selected == null || !context.mounted) return;
|
||||
final id = '${selected['id'] ?? ''}';
|
||||
final current =
|
||||
@@ -60,12 +56,10 @@ class _AddChatPanePicker extends StatefulWidget {
|
||||
required this.controller,
|
||||
required this.sidebarFolds,
|
||||
required this.excludedSessionIds,
|
||||
required this.cupertino,
|
||||
});
|
||||
final ChatSessionsController controller;
|
||||
final ChatSectionFolds sidebarFolds;
|
||||
final Set<String> excludedSessionIds;
|
||||
final bool cupertino;
|
||||
|
||||
@override
|
||||
State<_AddChatPanePicker> createState() => _AddChatPanePickerState();
|
||||
@@ -92,25 +86,18 @@ class _AddChatPanePickerState extends State<_AddChatPanePicker> {
|
||||
Widget build(BuildContext context) {
|
||||
final list = Column(
|
||||
children: [
|
||||
if (!widget.cupertino)
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(24, 8, 8, 0),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
'Add chat pane',
|
||||
style: Theme.of(context).textTheme.titleLarge,
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
],
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(24, 16, 24, 0),
|
||||
child: Text(
|
||||
'Add chat pane',
|
||||
style: Theme.of(context).textTheme.titleLarge,
|
||||
),
|
||||
ChatSearchField(controller: _search, onChanged: (_) => setState(() {})),
|
||||
),
|
||||
ChatSearchField(
|
||||
controller: _search,
|
||||
autofocus: true,
|
||||
onChanged: (_) => setState(() {}),
|
||||
),
|
||||
Expanded(
|
||||
child: ListenableBuilder(
|
||||
listenable: Listenable.merge([
|
||||
@@ -168,26 +155,14 @@ class _AddChatPanePickerState extends State<_AddChatPanePicker> {
|
||||
),
|
||||
],
|
||||
);
|
||||
return widget.cupertino
|
||||
? CupertinoPageScaffold(
|
||||
navigationBar: CupertinoNavigationBar(
|
||||
automaticallyImplyLeading: false,
|
||||
middle: const Text('Add chat pane'),
|
||||
trailing: CupertinoButton(
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
),
|
||||
child: SafeArea(child: list),
|
||||
)
|
||||
: Material(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
bottom: MediaQuery.viewInsetsOf(context).bottom,
|
||||
),
|
||||
child: SafeArea(top: false, child: list),
|
||||
),
|
||||
);
|
||||
|
||||
return Material(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
bottom: MediaQuery.viewInsetsOf(context).bottom,
|
||||
),
|
||||
child: SafeArea(top: false, child: list),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../../core/error_reason.dart';
|
||||
import '../../../ui/adaptive/app_popups.dart';
|
||||
import '../data/chat_repository.dart';
|
||||
import '../ui/sessions/chat_adaptive.dart';
|
||||
import 'chat_bar_control_style.dart';
|
||||
|
||||
/// The conversation bar's permission-mode control.
|
||||
@@ -56,14 +55,11 @@ class _ChatModeControlState extends State<ChatModeControl> {
|
||||
}
|
||||
|
||||
Future<void> _open() async {
|
||||
final cupertino =
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
final repository = ChatRepository(widget.gateway);
|
||||
final picker = _ChatModePicker(
|
||||
load: () => repository.modes(widget.sessionId),
|
||||
current: _mode,
|
||||
currentName: _name,
|
||||
cupertino: cupertino,
|
||||
choose: (mode) async {
|
||||
final applied = await repository.selectMode(widget.sessionId, mode.id);
|
||||
final name = applied == mode.id ? mode.name : applied;
|
||||
@@ -76,27 +72,12 @@ class _ChatModeControlState extends State<ChatModeControl> {
|
||||
}
|
||||
},
|
||||
);
|
||||
if (cupertino) {
|
||||
await showCupertinoModalPopup<void>(
|
||||
context: context,
|
||||
builder: (_) => picker,
|
||||
);
|
||||
return;
|
||||
}
|
||||
await showModalBottomSheet<void>(
|
||||
context: context,
|
||||
showDragHandle: true,
|
||||
isScrollControlled: true,
|
||||
useSafeArea: true,
|
||||
builder: (_) => picker,
|
||||
);
|
||||
await showAppChoiceMenu<void>(context, builder: (_) => picker);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (_mode.isEmpty || _name.isEmpty) return const SizedBox.shrink();
|
||||
final cupertino =
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
final label = _name;
|
||||
// At phone widths the title and a named mode cannot both remain useful.
|
||||
// Keep the mode's shield, whose semantic label and picker still name it.
|
||||
@@ -105,34 +86,13 @@ class _ChatModeControlState extends State<ChatModeControl> {
|
||||
final content = Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
cupertino
|
||||
? CupertinoIcons.shield_lefthalf_fill
|
||||
: Icons.shield_outlined,
|
||||
),
|
||||
const Icon(Icons.shield_outlined),
|
||||
if (!iconOnly) ...[
|
||||
const SizedBox(width: 4),
|
||||
Flexible(child: Text(label, overflow: TextOverflow.ellipsis)),
|
||||
],
|
||||
],
|
||||
);
|
||||
const key = Key('chat-mode');
|
||||
if (cupertino) {
|
||||
return Semantics(
|
||||
container: true,
|
||||
button: true,
|
||||
label: 'Change mode, currently $label',
|
||||
onTap: _open,
|
||||
child: ExcludeSemantics(
|
||||
child: CupertinoButton(
|
||||
key: key,
|
||||
padding: chatBarButtonPadding,
|
||||
onPressed: _open,
|
||||
child: chatBarCupertinoContent(context, content),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return Semantics(
|
||||
container: true,
|
||||
button: true,
|
||||
@@ -142,7 +102,7 @@ class _ChatModeControlState extends State<ChatModeControl> {
|
||||
child: Tooltip(
|
||||
message: 'Change mode (currently $label)',
|
||||
child: TextButton(
|
||||
key: key,
|
||||
key: const Key('chat-mode'),
|
||||
style: chatBarTextButtonStyle(context, compact: iconOnly),
|
||||
onPressed: _open,
|
||||
child: content,
|
||||
@@ -164,14 +124,12 @@ class _ChatModePicker extends StatefulWidget {
|
||||
required this.load,
|
||||
required this.current,
|
||||
required this.currentName,
|
||||
required this.cupertino,
|
||||
required this.choose,
|
||||
});
|
||||
|
||||
final Future<({List<JsonMap> modes, String current})> Function() load;
|
||||
final String current;
|
||||
final String currentName;
|
||||
final bool cupertino;
|
||||
final Future<void> Function(_Mode mode) choose;
|
||||
|
||||
@override
|
||||
@@ -261,8 +219,7 @@ class _ChatModePickerState extends State<_ChatModePicker> {
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) =>
|
||||
widget.cupertino ? _cupertinoSheet(context) : _materialSheet(context);
|
||||
Widget build(BuildContext context) => _materialSheet(context);
|
||||
|
||||
Widget _materialSheet(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
@@ -308,55 +265,4 @@ class _ChatModePickerState extends State<_ChatModePicker> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _cupertinoSheet(BuildContext context) {
|
||||
final secondary = CupertinoColors.secondaryLabel.resolveFrom(context);
|
||||
final modes = _visibleModes;
|
||||
final loaded = _modes != null;
|
||||
return CupertinoActionSheet(
|
||||
key: const Key('chat-mode-sheet'),
|
||||
title: const Text('Mode'),
|
||||
message: _error != null
|
||||
? Text(
|
||||
_error!,
|
||||
style: TextStyle(
|
||||
color: CupertinoColors.systemRed.resolveFrom(context),
|
||||
),
|
||||
)
|
||||
: !loaded
|
||||
? const CupertinoActivityIndicator()
|
||||
: null,
|
||||
actions: [
|
||||
for (final mode in modes)
|
||||
CupertinoActionSheetAction(
|
||||
key: ValueKey<String>('chat-mode-option-${mode.id}'),
|
||||
onPressed: () => _choose(mode),
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Flexible(child: Text(mode.name)),
|
||||
if (mode.id == _current) ...[
|
||||
const SizedBox(width: 6),
|
||||
const Icon(CupertinoIcons.checkmark_alt),
|
||||
],
|
||||
],
|
||||
),
|
||||
if (mode.description.isNotEmpty)
|
||||
Text(
|
||||
mode.description,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(fontSize: 13, color: secondary),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
cancelButton: CupertinoActionSheetAction(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,10 +100,12 @@ class ChatSearchField extends StatelessWidget {
|
||||
required this.controller,
|
||||
required this.onChanged,
|
||||
this.trailing = const [],
|
||||
this.autofocus = false,
|
||||
});
|
||||
|
||||
final TextEditingController controller;
|
||||
final ValueChanged<String> onChanged;
|
||||
final bool autofocus;
|
||||
|
||||
/// Actions on the search row's trailing edge, as the web's chat toolbar
|
||||
/// keeps New chat beside its search input.
|
||||
@@ -120,6 +122,7 @@ class ChatSearchField extends StatelessWidget {
|
||||
: TextField(
|
||||
controller: controller,
|
||||
onChanged: onChanged,
|
||||
autofocus: autofocus,
|
||||
decoration: const InputDecoration(
|
||||
prefixIcon: Icon(Icons.search),
|
||||
labelText: 'Search chats',
|
||||
|
||||
Reference in New Issue
Block a user