b1fcdcf2c3
- New chat: a cleared Name creates the chat without an operator title; the list shows the harness's own title, or the default name until it has one. The server no longer records "New chat" for a blank title and OpenCode is created without a title so it names the session itself. - New chat harness defaults to the one last used in the chosen folder, else anywhere, else OpenCode; remembered on the device per server. - Markdown tables wrap at word boundaries and never go below a column's longest word (tokens over ~40 characters may break); a table whose words cannot fit scrolls sideways with the code block affordance. - Composer: right-click, long-press, Shift+F10 or the context menu key on Send opens Send later... (30 min, 1 h, tomorrow 9:00, usage reset, pick a time), sent through the same path with send_at. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
179 lines
5.6 KiB
Dart
179 lines
5.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../../domain/chat_default_name.dart';
|
|
|
|
export '../../domain/chat_default_name.dart' show chatBackendLabel;
|
|
|
|
/// The web's directory prompt, also the directory picker's label.
|
|
const String chatCreatePrompt = 'Where should this chat live?';
|
|
|
|
/// Opens the folder picker from the create dialog.
|
|
const String chatChooseFolderLabel = 'Choose folder…';
|
|
|
|
/// The home choice: shown as `Home (~)` and sent as the `~` the server
|
|
/// documents.
|
|
const String chatHomeDirectory = '~';
|
|
const String chatHomeLabel = 'Home ($chatHomeDirectory)';
|
|
|
|
/// The web's directory choices: home first (the server's first directory is
|
|
/// its path), then the remaining server directories as sent.
|
|
List<String> chatDirectoryChoices(List<String> directories) => [
|
|
chatHomeDirectory,
|
|
...directories.skip(1),
|
|
];
|
|
|
|
/// The visible label of a directory choice; home names its resolved path.
|
|
String chatDirectoryLabel(String choice, List<String> directories) {
|
|
if (choice != chatHomeDirectory) return choice;
|
|
final home = directories.isEmpty ? chatHomeDirectory : directories.first;
|
|
return '$chatHomeLabel — $home';
|
|
}
|
|
|
|
/// The create dialog's server catalog area: loading, error with retry, the
|
|
/// directory choices and, only when the server offers more than one, the
|
|
/// harness choice.
|
|
class ChatCatalogFields extends StatelessWidget {
|
|
const ChatCatalogFields({
|
|
super.key,
|
|
required this.loading,
|
|
required this.error,
|
|
required this.directories,
|
|
required this.backends,
|
|
required this.directory,
|
|
required this.backend,
|
|
required this.onDirectory,
|
|
required this.onBackend,
|
|
required this.onRetry,
|
|
this.onBrowse,
|
|
});
|
|
|
|
final bool loading;
|
|
final String? error;
|
|
final List<String> directories;
|
|
final List<String> backends;
|
|
final String? directory;
|
|
final String? backend;
|
|
final ValueChanged<String> onDirectory;
|
|
final ValueChanged<String> onBackend;
|
|
final VoidCallback onRetry;
|
|
|
|
/// Opens the folder picker; null hides the "Choose folder" action.
|
|
final VoidCallback? onBrowse;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (loading) return const Text('Loading directories…');
|
|
if (error != null) {
|
|
return _message('Unable to load chat options: $error');
|
|
}
|
|
final choices = chatDirectoryChoices(directories);
|
|
String directoryLabel(String choice) =>
|
|
chatDirectoryLabel(choice, directories);
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
// Keyed by the value so a folder chosen in the picker replaces the
|
|
// dropdown's retained initial value.
|
|
KeyedSubtree(
|
|
key: ValueKey('chat-create-directory-$directory'),
|
|
child: MaterialPickerField(
|
|
fieldKey: const Key('chat-create-server-directory'),
|
|
label: chatCreatePrompt,
|
|
value: directory,
|
|
values: choices,
|
|
labelOf: directoryLabel,
|
|
onSelected: onDirectory,
|
|
),
|
|
),
|
|
if (onBrowse != null)
|
|
Align(
|
|
alignment: AlignmentDirectional.centerStart,
|
|
child: TextButton.icon(
|
|
key: const Key('chat-create-choose-folder'),
|
|
onPressed: onBrowse,
|
|
icon: const Icon(Icons.folder_open),
|
|
label: const Text(chatChooseFolderLabel),
|
|
),
|
|
),
|
|
if (backends.length > 1)
|
|
// Keyed by the value so the harness remembered for a folder,
|
|
// read after the field first shows, replaces its initial value.
|
|
KeyedSubtree(
|
|
key: ValueKey('chat-create-backend-$backend'),
|
|
child: MaterialPickerField(
|
|
fieldKey: const Key('chat-create-backend'),
|
|
label: 'Chat harness',
|
|
value: backend,
|
|
values: backends,
|
|
labelOf: chatBackendLabel,
|
|
onSelected: onBackend,
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _message(String text) {
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(text),
|
|
Align(
|
|
alignment: AlignmentDirectional.centerStart,
|
|
child: TextButton(onPressed: onRetry, child: const Text('Retry')),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
class MaterialPickerField extends StatelessWidget {
|
|
const MaterialPickerField({
|
|
super.key,
|
|
required this.fieldKey,
|
|
required this.label,
|
|
required this.value,
|
|
required this.values,
|
|
required this.onSelected,
|
|
this.labelOf,
|
|
});
|
|
|
|
final String label;
|
|
final String? value;
|
|
final List<String> values;
|
|
final ValueChanged<String> onSelected;
|
|
final Key fieldKey;
|
|
|
|
/// The visible text of a value; the value itself is what is sent.
|
|
final String Function(String value)? labelOf;
|
|
|
|
String _text(String value) => labelOf?.call(value) ?? value;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return DropdownButtonFormField<String>(
|
|
key: fieldKey,
|
|
initialValue: value,
|
|
isExpanded: true,
|
|
// Intrinsic item height: a 2x label must not be clipped by the 48px
|
|
// default, and a real path must ellipsize instead of overflowing.
|
|
itemHeight: null,
|
|
decoration: InputDecoration(labelText: label),
|
|
selectedItemBuilder: (context) => [
|
|
for (final item in values) _fieldLabel(item),
|
|
],
|
|
items: [
|
|
for (final item in values)
|
|
DropdownMenuItem(value: item, child: _fieldLabel(item)),
|
|
],
|
|
onChanged: (item) {
|
|
if (item != null) onSelected(item);
|
|
},
|
|
);
|
|
}
|
|
|
|
Widget _fieldLabel(String item) {
|
|
return Text(_text(item), maxLines: 1, overflow: TextOverflow.ellipsis);
|
|
}
|
|
}
|