Merge commit 'ec3455e34dbec87376f00d19d9cc944eef51dae7' into pipelines/run-20261111-1951-material-cleanup-terminal-and-chat-shell-1213
This commit is contained in:
@@ -4,7 +4,7 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../../core/error_reason.dart';
|
||||
import '../../../ui/adaptive/app_menu_anchor.dart';
|
||||
import '../../../ui/adaptive/app_popups.dart';
|
||||
import 'chat_bar_control_style.dart';
|
||||
import 'chat_efforts.dart';
|
||||
import 'chat_models.dart';
|
||||
@@ -92,9 +92,13 @@ class _ChatEffortControlState extends State<ChatEffortControl> {
|
||||
}
|
||||
|
||||
Future<void> _chooseFromMenu(ChatEffortLevel level) async {
|
||||
if (level.id == _state.effort) return;
|
||||
if (level.id == _state.effort || level.id == _state.current) {
|
||||
Navigator.of(context).pop();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await _choose(level);
|
||||
if (mounted) Navigator.of(context).pop();
|
||||
} catch (error) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.maybeOf(context)?.showSnackBar(
|
||||
@@ -128,57 +132,62 @@ class _ChatEffortControlState extends State<ChatEffortControl> {
|
||||
],
|
||||
);
|
||||
const key = Key('chat-effort');
|
||||
return AppMenuAnchor(
|
||||
menuChildren: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(12, 8, 12, 4),
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 280),
|
||||
return Semantics(
|
||||
container: true,
|
||||
button: true,
|
||||
label: 'Change thinking level, currently ${_state.currentName}',
|
||||
onTap: _open,
|
||||
child: ExcludeSemantics(
|
||||
child: Tooltip(
|
||||
message: 'Change thinking level (currently ${_state.currentName})',
|
||||
child: TextButton(
|
||||
key: key,
|
||||
style: chatBarTextButtonStyle(context, compact: iconOnly),
|
||||
onPressed: _open,
|
||||
child: content,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _open() async {
|
||||
await showAppChoiceMenu<void>(
|
||||
context,
|
||||
width: 320,
|
||||
semanticLabel: 'Change thinking level',
|
||||
builder: (_) => ListView(
|
||||
key: const Key('chat-effort-menu'),
|
||||
shrinkWrap: true,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 8),
|
||||
child: Text(
|
||||
chatEffortNote(running: widget.running),
|
||||
key: const Key('chat-effort-note'),
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
),
|
||||
),
|
||||
for (final level in _state.levels)
|
||||
MenuItemButton(
|
||||
key: ValueKey<String>('chat-effort-option-${level.id}'),
|
||||
trailingIcon: level.id == _state.current
|
||||
? const Icon(Icons.check)
|
||||
: null,
|
||||
onPressed: () => unawaited(_chooseFromMenu(level)),
|
||||
child: level.description.isEmpty
|
||||
? Text(level.name)
|
||||
: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(level.name),
|
||||
Text(
|
||||
level.description,
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
builder: (context, menu, _) => Semantics(
|
||||
container: true,
|
||||
button: true,
|
||||
label: 'Change thinking level, currently ${_state.currentName}',
|
||||
onTap: () => menu.isOpen ? menu.close() : menu.open(),
|
||||
child: ExcludeSemantics(
|
||||
child: Tooltip(
|
||||
message: 'Change thinking level (currently ${_state.currentName})',
|
||||
child: TextButton(
|
||||
key: key,
|
||||
style: chatBarTextButtonStyle(context),
|
||||
onPressed: () => menu.isOpen ? menu.close() : menu.open(),
|
||||
child: content,
|
||||
for (final level in _state.levels)
|
||||
AppChoiceMenuItem(
|
||||
key: ValueKey<String>('chat-effort-option-${level.id}'),
|
||||
selected: level.id == _state.current,
|
||||
onTap: () => unawaited(_chooseFromMenu(level)),
|
||||
child: level.description.isEmpty
|
||||
? Text(level.name)
|
||||
: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(level.name),
|
||||
Text(
|
||||
level.description,
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -249,17 +249,23 @@ class _ChatModePickerState extends State<_ChatModePicker> {
|
||||
)
|
||||
else
|
||||
for (final mode in modes)
|
||||
ListTile(
|
||||
AppChoiceMenuItem(
|
||||
key: ValueKey<String>('chat-mode-option-${mode.id}'),
|
||||
enabled: !_busy,
|
||||
title: Text(mode.name),
|
||||
subtitle: mode.description.isEmpty
|
||||
? null
|
||||
: Text(mode.description),
|
||||
trailing: mode.id == _current
|
||||
? Icon(Icons.check, color: theme.colorScheme.primary)
|
||||
: null,
|
||||
onTap: () => _choose(mode),
|
||||
selected: mode.id == _current,
|
||||
onTap: _busy ? null : () => _choose(mode),
|
||||
child: mode.description.isEmpty
|
||||
? Text(mode.name)
|
||||
: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(mode.name),
|
||||
Text(
|
||||
mode.description,
|
||||
style: theme.textTheme.bodySmall,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -4,6 +4,7 @@ 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 'chat_models.dart';
|
||||
|
||||
@@ -22,7 +23,6 @@ class ChatModelChooser extends StatefulWidget {
|
||||
required this.backend,
|
||||
required this.currentProvider,
|
||||
required this.currentModel,
|
||||
required this.cupertino,
|
||||
required this.onAccepted,
|
||||
});
|
||||
|
||||
@@ -31,7 +31,6 @@ class ChatModelChooser extends StatefulWidget {
|
||||
final String backend;
|
||||
final String currentProvider;
|
||||
final String currentModel;
|
||||
final bool cupertino;
|
||||
final ValueChanged<ChatModelSelection> onAccepted;
|
||||
|
||||
@override
|
||||
@@ -92,6 +91,10 @@ class _ChatModelChooserState extends State<ChatModelChooser> {
|
||||
|
||||
Future<void> _choose(JsonMap model) async {
|
||||
if (_busy) return;
|
||||
if (_isCurrent(model)) {
|
||||
Navigator.of(context).pop();
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
_busy = true;
|
||||
_error = null;
|
||||
@@ -147,95 +150,105 @@ class _ChatModelChooserState extends State<ChatModelChooser> {
|
||||
final secondary = theme.colorScheme.onSurfaceVariant;
|
||||
final matches = filterChatModels(_models, _search.text);
|
||||
final needle = _search.text.trim();
|
||||
return SimpleDialog(
|
||||
key: const Key('chat-model-chooser'),
|
||||
title: const Text('Change model'),
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(24, 0, 24, 8),
|
||||
child: Text(
|
||||
chatModelSelectionNote(widget.backend),
|
||||
style: theme.textTheme.bodySmall?.copyWith(color: secondary),
|
||||
),
|
||||
),
|
||||
if (_loading)
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(24, 8, 24, 8),
|
||||
child: Row(
|
||||
children: [
|
||||
const CircularProgressIndicator(),
|
||||
const SizedBox(width: 12),
|
||||
const Expanded(child: Text('Loading models…')),
|
||||
],
|
||||
return SafeArea(
|
||||
child: SingleChildScrollView(
|
||||
key: const Key('chat-model-chooser'),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Padding(
|
||||
padding: EdgeInsets.fromLTRB(16, 0, 16, 8),
|
||||
child: Text('Change model'),
|
||||
),
|
||||
)
|
||||
else if (_error != null)
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(24, 0, 24, 8),
|
||||
child: Text(
|
||||
_error!,
|
||||
key: const Key('chat-model-error'),
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
color: theme.colorScheme.error,
|
||||
),
|
||||
),
|
||||
)
|
||||
else if (_models.isEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(24, 0, 24, 8),
|
||||
child: Text(
|
||||
'No models are available for this chat.',
|
||||
style: theme.textTheme.bodyMedium?.copyWith(color: secondary),
|
||||
),
|
||||
)
|
||||
else ...[
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(24, 0, 24, 8),
|
||||
child: TextField(
|
||||
key: const Key('chat-model-search'),
|
||||
controller: _search,
|
||||
onChanged: (_) => setState(() {}),
|
||||
decoration: const InputDecoration(
|
||||
prefixIcon: Icon(Icons.search),
|
||||
hintText: 'Search models',
|
||||
),
|
||||
),
|
||||
),
|
||||
for (final model in matches)
|
||||
SimpleDialogOption(
|
||||
key: _optionKey(model),
|
||||
onPressed: _busy ? null : () => _choose(model),
|
||||
child: _optionRow(context, model),
|
||||
),
|
||||
if (matches.isEmpty && needle.isNotEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(24, 0, 24, 8),
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 8),
|
||||
child: Text(
|
||||
'No models match "$needle".',
|
||||
key: const Key('chat-model-no-match'),
|
||||
style: theme.textTheme.bodyMedium?.copyWith(color: secondary),
|
||||
chatModelSelectionNote(widget.backend),
|
||||
style: theme.textTheme.bodySmall?.copyWith(color: secondary),
|
||||
),
|
||||
),
|
||||
],
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 4, 16, 8),
|
||||
child: Align(
|
||||
alignment: AlignmentDirectional.centerEnd,
|
||||
child: TextButton(
|
||||
key: const Key('chat-model-cancel'),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text('Cancel'),
|
||||
if (_loading)
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 8, 16, 8),
|
||||
child: Row(
|
||||
children: [
|
||||
const CircularProgressIndicator(),
|
||||
const SizedBox(width: 12),
|
||||
const Expanded(child: Text('Loading models…')),
|
||||
],
|
||||
),
|
||||
)
|
||||
else if (_error != null)
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 8),
|
||||
child: Text(
|
||||
_error!,
|
||||
key: const Key('chat-model-error'),
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
color: theme.colorScheme.error,
|
||||
),
|
||||
),
|
||||
)
|
||||
else if (_models.isEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 8),
|
||||
child: Text(
|
||||
'No models are available for this chat.',
|
||||
style: theme.textTheme.bodyMedium?.copyWith(color: secondary),
|
||||
),
|
||||
)
|
||||
else ...[
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 8),
|
||||
child: TextField(
|
||||
key: const Key('chat-model-search'),
|
||||
controller: _search,
|
||||
onChanged: (_) => setState(() {}),
|
||||
decoration: const InputDecoration(
|
||||
prefixIcon: Icon(Icons.search),
|
||||
hintText: 'Search models',
|
||||
),
|
||||
),
|
||||
),
|
||||
for (final model in matches)
|
||||
AppChoiceMenuItem(
|
||||
key: _optionKey(model),
|
||||
selected: _isCurrent(model),
|
||||
onTap: _busy ? null : () => _choose(model),
|
||||
child: _optionRow(context, model),
|
||||
),
|
||||
if (matches.isEmpty && needle.isNotEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 8),
|
||||
child: Text(
|
||||
'No models match "$needle".',
|
||||
key: const Key('chat-model-no-match'),
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
color: secondary,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 4, 16, 8),
|
||||
child: Align(
|
||||
alignment: AlignmentDirectional.centerEnd,
|
||||
child: TextButton(
|
||||
key: const Key('chat-model-cancel'),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _optionRow(BuildContext context, JsonMap model) {
|
||||
final selected = _isCurrent(model);
|
||||
final secondary = Theme.of(context).colorScheme.onSurfaceVariant;
|
||||
final accent = Theme.of(context).colorScheme.primary;
|
||||
final provider = '${model['provider'] ?? ''}'.trim();
|
||||
return Semantics(
|
||||
selected: selected,
|
||||
@@ -252,7 +265,7 @@ class _ChatModelChooserState extends State<ChatModelChooser> {
|
||||
],
|
||||
),
|
||||
),
|
||||
if (selected) Icon(Icons.check, color: accent),
|
||||
// The shared menu row supplies the check mark.
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../../ui/adaptive/app_popups.dart';
|
||||
import 'chat_bar_control_style.dart';
|
||||
import 'chat_model_chooser.dart';
|
||||
import 'chat_models.dart';
|
||||
@@ -79,10 +80,14 @@ class _ChatModelControlState extends State<ChatModelControl> {
|
||||
backend: '${widget.session['backend'] ?? ''}'.trim(),
|
||||
currentProvider: _provider,
|
||||
currentModel: _model,
|
||||
cupertino: false,
|
||||
onAccepted: _accept,
|
||||
);
|
||||
await showDialog<void>(context: context, builder: (_) => chooser);
|
||||
await showAppChoiceMenu<void>(
|
||||
context,
|
||||
width: 420,
|
||||
semanticLabel: 'Change model',
|
||||
builder: (_) => chooser,
|
||||
);
|
||||
}
|
||||
|
||||
void _accept(ChatModelSelection applied) {
|
||||
|
||||
@@ -221,7 +221,7 @@ class ChatWindows {
|
||||
if (event is KeyDownEvent) tiling.floatActive();
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
if (event is KeyDownEvent) manager.toggleGroup(chatWindowKind);
|
||||
if (event is KeyDownEvent) manager.toggleOrRaiseGroup(chatWindowKind);
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../../../ui/input/keyboard_owner.dart';
|
||||
|
||||
/// Whether [event] shows or hides the floating chats: Alt+Y (Option+Y),
|
||||
/// Ctrl+Y, and Cmd+Y on Apple platforms, matching the terminal's Alt+T. It is
|
||||
/// a global key handler like the terminal's toggle, so it works while a
|
||||
/// composer or the terminal has the keyboard; a plain Y (or Shift+Y) always
|
||||
/// types. Alt+Y is always the chord, as Alt+T is for the terminal. On Apple
|
||||
/// platforms Ctrl+Y inside a terminal is left to the shell (yank), since Cmd+Y
|
||||
/// is there; elsewhere Ctrl+Y is the chord, so it takes priority over the
|
||||
/// shell's yank.
|
||||
/// platforms Ctrl+Y is also the chord, so it takes priority over the shell's
|
||||
/// yank.
|
||||
///
|
||||
/// A held chord's repeats match too (and are swallowed); only its first
|
||||
/// press toggles.
|
||||
@@ -31,7 +28,7 @@ bool chatFloatShortcut(
|
||||
if (alt) return !control && !meta;
|
||||
if (control == meta) return false;
|
||||
if (!_apple(platform ?? defaultTargetPlatform)) return control;
|
||||
return meta || !primaryFocusIsTypingSurface();
|
||||
return control || meta;
|
||||
}
|
||||
|
||||
bool _apple(TargetPlatform platform) =>
|
||||
|
||||
Reference in New Issue
Block a user