Add font viewer

This commit is contained in:
James Babcock committed 2026-08-16 21:01:17 -07:00
1 parent 1b4844b1ef
commit 1d00849eb2
7 files changed
+775 -1

No files matched your search

+46 -1
View File
@@ -1,7 +1,9 @@
import { readTextFile, type DirectoryEntry } from "../../native/file-access";
import { isFontFile } from "../../native/font-files";
import { isDecodableImageFile } from "../../native/image-files";
import { FileBrowserLayer } from "./file-browser";
import { FileInfoDialogLayer, type FileInfoAction } from "./file-info-dialog";
import { FontPreviewerLayer } from "./font-previewer";
import { ImageViewerLayer } from "./image-viewer";
import { TextViewerLayer } from "./text-viewer";
import {
@@ -25,6 +27,8 @@ export type FilesAppOptions = InProcessAppOptions & {
openImageWindow: (title: string, path: string) => void;
/** Launch an EvenHub app package (.ehpk) through the EvenHub host. */
openEhpkApp: (path: string) => void;
/** Open a font file's previewer as its own shell window. */
openFontWindow: (title: string, path: string) => void;
};
/**
@@ -35,7 +39,7 @@ export type FilesAppOptions = InProcessAppOptions & {
export function createFilesAppWindow(options: FilesAppOptions): InProcessWindow {
let created: InProcessWindow | null = null;
const browser = new FileBrowserLayer({
isSupportedFile: (name) => TEXT_FILE.test(name) || EHPK_FILE.test(name) || isDecodableImageFile(name),
isSupportedFile: (name) => TEXT_FILE.test(name) || isDecodableImageFile(name) || EHPK_FILE.test(name) || isFontFile(name),
// The browser handles double-click itself (up a level), so it is not
// wrapped in YieldAtRootLayer; it yields explicitly from the top level.
onLeave: () => shell.yieldFocusToSidebar(),
@@ -86,6 +90,29 @@ export function createTextDocumentWindow(
});
}
/** One opened font file's previewer as its own window. */
export function createFontDocumentWindow(
windowId: string,
title: string,
path: string,
options: InProcessAppOptions,
): InProcessWindow {
return createInProcessWindow({
appId: "files",
windowId,
title,
iconLetter: "F",
icon: "type",
closeable: true,
actions: options.actions,
baseLayer: new YieldAtRootLayer(new FontPreviewerLayer(path, title)),
submitFrame: options.submitFrame,
setSurfaceVisible: options.setSurfaceVisible,
removeSurface: options.removeSurface,
onClosed: options.onClosed,
});
}
/** One opened image file as its own window. */
export function createImageDocumentWindow(
windowId: string,
@@ -163,5 +190,23 @@ function fileOpenActions(entry: DirectoryEntry, options: FilesAppOptions): FileI
},
];
}
if (isFontFile(entry.name)) {
return [
{
label: "Preview here",
onSelect: (ctx) => {
ctx.stack.pop();
ctx.stack.push(new FontPreviewerLayer(entry.path, entry.name));
},
},
{
label: "Open in new window",
onSelect: (ctx) => {
ctx.stack.pop();
options.openFontWindow(entry.name, entry.path);
},
},
];
}
return [];
}