Page through a folder's files in the file viewer

Opening a file from the Files panel now passes the folder's previewable
files in their shown order, so the arrows, swipes and Previous/Next step
through them and Escape closes the viewer. Download follows the file on
screen.
This commit is contained in:
2026-11-10 00:14:18 +00:00
parent ec70bee12e
commit 339cce0424
4 changed files with 84 additions and 15 deletions
+6 -1
View File
@@ -217,7 +217,12 @@ class _FilesPanelState extends State<FilesPanel> {
if (widget.onOpen != null) {
widget.onOpen!(entry);
} else {
widget.viewer.open(context, endpoint: _endpoint, entry: entry);
widget.viewer.open(
context,
endpoint: _endpoint,
entry: entry,
siblings: widget.controller.entries,
);
}
}
}
+26 -12
View File
@@ -37,10 +37,14 @@ class FilesViewer {
final ArtifactExternalOpen openExternal;
final FileUrlLauncher launch;
/// Opens [entry]. [siblings] are the folder's entries in the order shown;
/// the viewer then steps through every previewable one with the arrows,
/// swipes and Previous/Next, and Escape closes it.
Future<void> open(
BuildContext context, {
required String endpoint,
required DirectoryEntry entry,
List<DirectoryEntry> siblings = const [],
}) async {
final urls = resolveFileUrls(endpoint, entry.path);
if (urls == null) {
@@ -62,18 +66,28 @@ class FilesViewer {
_showSheet(context, entry, urls);
return;
}
final artifact = ArtifactRecord(
name: entry.name,
url: urls.view.toString(),
contentType: type,
sizeBytes: entry.size ?? 0,
raw: const {},
);
final group = ArtifactGroup(
stageKey: 'Files',
visit: 1,
artifacts: [artifact],
);
ArtifactRecord? record(DirectoryEntry file) {
if (file.isDir || !isPreviewableFile(file.name)) return null;
final links = resolveFileUrls(endpoint, file.path);
if (links == null) return null;
final kind = fileContentType(file.name);
if (artifactKind(kind, file.name) == ArtifactKind.pdf) return null;
return ArtifactRecord(
name: file.name,
url: links.view.toString(),
contentType: kind,
sizeBytes: file.size ?? 0,
raw: {'download_url': links.download.toString()},
);
}
final artifact = record(entry)!;
final pages = [
for (final file in siblings)
if (file.path == entry.path) artifact else ?record(file),
];
if (!pages.contains(artifact)) pages.add(artifact);
final group = ArtifactGroup(stageKey: 'Files', visit: 1, artifacts: pages);
final page = ArtifactViewerPage(
groups: [group],
selectedIdentity: artifactVisitIdentityOf(group, artifact),