Add chat files panel explorer shell with sorting and views
This commit is contained in:
@@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../../core/servers/server_scope.dart';
|
||||
import '../../../shell/shell_bar.dart';
|
||||
import '../data/chat_attachment_images.dart';
|
||||
import '../data/chat_repository.dart';
|
||||
@@ -51,6 +52,9 @@ import 'chat_reading_width.dart';
|
||||
import 'chat_thread_header.dart';
|
||||
import 'chat_transcript_anchor.dart';
|
||||
import 'chat_transcript_cache.dart';
|
||||
import '../files/files_controller.dart';
|
||||
import '../files/files_panel.dart';
|
||||
import '../files/files_preferences.dart';
|
||||
import 'chat_transcript_scroll_view.dart';
|
||||
import 'chat_permission_card_model.dart';
|
||||
import 'chat_permission_group.dart';
|
||||
@@ -212,6 +216,86 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
int _commandNoticeSeq = 0;
|
||||
|
||||
final ScrollController _scroll = ScrollController();
|
||||
late FilesController _files = _newFilesController();
|
||||
bool _filesVisible = false;
|
||||
bool _filesPrefsLoaded = false;
|
||||
bool _filesSheetOpen = false;
|
||||
|
||||
FilesController _newFilesController() => FilesController(
|
||||
gateway: widget.gateway,
|
||||
initialPath: '${widget.session?['directory'] ?? ''}',
|
||||
);
|
||||
|
||||
FilesPreferences get _filesPreferences =>
|
||||
FilesPreferences(serverStorageScope(serverIdentity(widget.gateway)));
|
||||
|
||||
Future<void> _loadFilesPreferences() async {
|
||||
final prefs = _filesPreferences;
|
||||
final visible = await prefs.visible();
|
||||
final view = await prefs.view();
|
||||
final sort = await prefs.sort();
|
||||
if (!mounted) return;
|
||||
_files.view = view;
|
||||
_files.sort = sort;
|
||||
setState(() {
|
||||
_filesVisible = visible;
|
||||
_filesPrefsLoaded = true;
|
||||
});
|
||||
if (visible && MediaQuery.sizeOf(context).width < 700) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) _openFilesSheet();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void _toggleFiles() {
|
||||
final next = !_filesVisible;
|
||||
if (!mounted) return;
|
||||
setState(() => _filesVisible = next);
|
||||
unawaited(_filesPreferences.setVisible(next));
|
||||
if (next && MediaQuery.sizeOf(context).width < 700) _openFilesSheet();
|
||||
}
|
||||
|
||||
void _openFilesSheet() {
|
||||
if (!mounted ||
|
||||
_filesSheetOpen ||
|
||||
!_filesVisible ||
|
||||
MediaQuery.sizeOf(context).width >= 700) {
|
||||
return;
|
||||
}
|
||||
_filesSheetOpen = true;
|
||||
final cupertino =
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
final sheet = cupertino
|
||||
? showCupertinoModalPopup<void>(
|
||||
context: context,
|
||||
builder: (_) => Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: SafeArea(
|
||||
child: CupertinoPopupSurface(
|
||||
child: SizedBox(
|
||||
height: MediaQuery.sizeOf(context).height * .85,
|
||||
child: FilesPanel(controller: _files),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
: showModalBottomSheet<void>(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
builder: (_) => SizedBox(
|
||||
height: MediaQuery.sizeOf(context).height * .85,
|
||||
child: FilesPanel(controller: _files),
|
||||
),
|
||||
);
|
||||
sheet.whenComplete(() {
|
||||
_filesSheetOpen = false;
|
||||
if (!mounted) return;
|
||||
setState(() => _filesVisible = false);
|
||||
unawaited(_filesPreferences.setVisible(false));
|
||||
});
|
||||
}
|
||||
|
||||
/// True while the transcript's end is in view. The operator's own upward
|
||||
/// scroll releases it; only returning to the end (or the jump control) arms
|
||||
@@ -466,6 +550,8 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_files.addListener(_persistFilesPreferences);
|
||||
unawaited(_loadFilesPreferences());
|
||||
_savedPosition = widget.scrollPositions?.read(widget.sessionId);
|
||||
_adoptCachedTranscript();
|
||||
_seedCommandNotice();
|
||||
@@ -486,6 +572,11 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
}
|
||||
_controller.dispose();
|
||||
_composer.dispose();
|
||||
_files.removeListener(_persistFilesPreferences);
|
||||
_files.dispose();
|
||||
_files = _newFilesController()..addListener(_persistFilesPreferences);
|
||||
_filesVisible = false;
|
||||
unawaited(_loadFilesPreferences());
|
||||
_closed = false;
|
||||
_controller = _attach();
|
||||
_composer = _attachComposer();
|
||||
@@ -549,9 +640,18 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
_scroll.dispose();
|
||||
_composer.dispose();
|
||||
_controller.dispose();
|
||||
_files.removeListener(_persistFilesPreferences);
|
||||
_files.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _persistFilesPreferences() {
|
||||
if (!_filesPrefsLoaded) return;
|
||||
final prefs = _filesPreferences;
|
||||
unawaited(prefs.setView(_files.view));
|
||||
unawaited(prefs.setSort(_files.sort));
|
||||
}
|
||||
|
||||
/// The ids of the transcript's messages in view order. Cards are conversation
|
||||
/// state, not messages, so a pending approval does not count as an arrival.
|
||||
List<String> _messageIds() => [
|
||||
@@ -1146,13 +1246,26 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
// composer sits below it; the wheel over them scrolls it, as a page
|
||||
// scrolls under fixed bars.
|
||||
final column = VerticalWheelForwarder(controller: _scroll, child: page);
|
||||
if (!inShellBar) return column;
|
||||
final wideFiles =
|
||||
_filesVisible && MediaQuery.sizeOf(context).width >= 700;
|
||||
final content = wideFiles
|
||||
? Row(
|
||||
children: [
|
||||
Expanded(child: column),
|
||||
SizedBox(
|
||||
width: filesPanelWidth(MediaQuery.sizeOf(context).width),
|
||||
child: FilesPanel(controller: _files),
|
||||
),
|
||||
],
|
||||
)
|
||||
: column;
|
||||
if (!inShellBar) return content;
|
||||
// The conversation draws its own floating bar; the page shows none.
|
||||
final title = widget.title.trim();
|
||||
return ShellBar(
|
||||
barless: true,
|
||||
title: title.isEmpty ? null : title,
|
||||
child: column,
|
||||
child: content,
|
||||
);
|
||||
},
|
||||
);
|
||||
@@ -1212,6 +1325,15 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
// would take more than half the pill. A session without a mode draws
|
||||
// no mode control, so no empty pill is ever drawn.
|
||||
controls: [
|
||||
ChatBarAction(
|
||||
label: 'Files',
|
||||
identifier: 'chat-files-toggle',
|
||||
onPressed: _toggleFiles,
|
||||
materialIcon: _filesVisible ? Icons.folder : Icons.folder_outlined,
|
||||
cupertinoIcon: _filesVisible
|
||||
? CupertinoIcons.folder_fill
|
||||
: CupertinoIcons.folder,
|
||||
),
|
||||
?widget.sidebarControl,
|
||||
...widget.paneControls,
|
||||
if (hasModel)
|
||||
|
||||
Reference in New Issue
Block a user