Skip to content

Commit

Permalink
✨ feat: automatically display all models when opened Document
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangechen committed Jan 30, 2024
1 parent 72d3e4c commit 95eacd9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
5 changes: 3 additions & 2 deletions packages/chili-ui/src/home/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ export const Home = async (app: IApplication) => {
div(
{
className: style.document,
onclick: () => {
app.openDocument(item.id);
onclick: async () => {
let document = await app.openDocument(item.id);
document?.visual.viewer.activeView?.cameraController.fitContent();
},
},
img({ className: style.img, src: item.image }),
Expand Down
25 changes: 7 additions & 18 deletions packages/chili/src/commands/application/openDocument.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2022-2023 the Chili authors. All rights reserved. AGPL-3.0 license.

import { IApplication, ICommand, Serialized, command, readFileAsync } from "chili-core";
import { IApplication, ICommand, IView, PubSub, Serialized, command, readFileAsync } from "chili-core";

@command({
name: "doc.open",
Expand All @@ -9,22 +9,11 @@ import { IApplication, ICommand, Serialized, command, readFileAsync } from "chil
})
export class OpenDocument implements ICommand {
async execute(app: IApplication): Promise<void> {
let input = document.createElement("input");
input.type = "file";
input.style.visibility = "hidden";
input.accept = ".cd";
input.onchange = () => {
let file = input.files?.item(0);
if (!file) return;
let reader = new FileReader();
reader.onload = async (e) => {
let data = e.target?.result as string;
let json: Serialized = JSON.parse(data);
await app.loadDocument(json);
};
reader.readAsText(file);
};
document.body.appendChild(input);
input.click();
let files = await readFileAsync(".cd", false);
if (files.status === "success") {
let json: Serialized = JSON.parse(files.value[0].data);
let document = await app.loadDocument(json);
document.visual.viewer.activeView?.cameraController.fitContent();
}
}
}

0 comments on commit 95eacd9

Please sign in to comment.