diff --git a/packages/chili-core/src/application.ts b/packages/chili-core/src/application.ts index 34e45900..8c92a05b 100644 --- a/packages/chili-core/src/application.ts +++ b/packages/chili-core/src/application.ts @@ -15,6 +15,7 @@ export interface IApplication extends IPropertyChanged { readonly services: IService[]; readonly storage: IStorage; readonly views: ObservableCollection; + readonly documents: Set; executingCommand: ICommand | undefined; activeView: IView | undefined; newDocument(name: string): Promise; diff --git a/packages/chili-ui/src/home/home.ts b/packages/chili-ui/src/home/home.ts index fd7d5b0a..e658b8b5 100644 --- a/packages/chili-ui/src/home/home.ts +++ b/packages/chili-ui/src/home/home.ts @@ -5,6 +5,13 @@ import { LanguageSelector } from "../components"; import { a, button, div, img, items, label, localize, span, svg } from "../controls"; import style from "./home.module.css"; +function hasOpen(app: IApplication, documentId: string) { + for (const document of app.documents) { + if (document.id === documentId) return true; + } + return false; +} + export const Home = async (app: IApplication) => { let documentArray: RecentDocumentDTO[] = await app.storage.page( Constants.DBName, @@ -64,7 +71,7 @@ export const Home = async (app: IApplication) => { { className: style.document, onclick: () => { - if (item.id === app.activeView?.document?.id) { + if (hasOpen(app, item.id)) { PubSub.default.pub("displayHome", false); } else { PubSub.default.pub( diff --git a/packages/chili/src/application.ts b/packages/chili/src/application.ts index e1958d30..2031d6b8 100644 --- a/packages/chili/src/application.ts +++ b/packages/chili/src/application.ts @@ -50,6 +50,7 @@ export class Application extends Observable implements IApplication { } readonly views = new ObservableCollection(); + readonly documents: Set = new Set(); executingCommand: ICommand | undefined; diff --git a/packages/chili/src/document.ts b/packages/chili/src/document.ts index 06211328..90cafe14 100644 --- a/packages/chili/src/document.ts +++ b/packages/chili/src/document.ts @@ -77,6 +77,7 @@ export class Document extends Observable implements IDocument { this.selection = new Selection(this); PubSub.default.sub("nodeLinkedListChanged", this.handleModelChanged); Logger.info(`new document: ${name}`); + application.documents.add(this); } private handleRootNodeNameChanged = (prop: string) => { @@ -129,6 +130,7 @@ export class Document extends Observable implements IDocument { let views = this.application.views.filter((x) => x.document === this); this.application.views.remove(...views); this.application.activeView = this.application.views.at(0); + this.application.documents.delete(this); Logger.info(`document: ${this._name} closed`); this.dispose();