-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
update window title when the document name changes #1624
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -7,7 +7,7 @@ | |||||
generally be MobX-observable. | ||||||
*/ | ||||||
import { cloneDeep } from "lodash" | ||||||
import { action, computed, makeObservable, observable, reaction, flow } from "mobx" | ||||||
import { action, autorun, computed, makeObservable, observable, reaction, flow } from "mobx" | ||||||
import { getSnapshot } from "mobx-state-tree" | ||||||
import { CloudFileManager } from "@concord-consortium/cloud-file-manager" | ||||||
import { createCodapDocument } from "./codap/create-codap-document" | ||||||
|
@@ -24,6 +24,8 @@ | |||||
import { CodapV2Document } from "../v2/codap-v2-document" | ||||||
import { importV2Document } from "../v2/import-v2-document" | ||||||
|
||||||
const kAppName = "CODAP" | ||||||
|
||||||
type AppMode = "normal" | "performance" | ||||||
|
||||||
type ISerializedDocumentModel = IDocumentModelSnapshot & {revisionId?: string} | ||||||
|
@@ -42,6 +44,7 @@ | |||||
private version = "" | ||||||
private cfm: CloudFileManager | undefined | ||||||
private dirtyMonitorDisposer: (() => void) | undefined | ||||||
titleMonitorDisposer: any | ||||||
|
||||||
constructor() { | ||||||
this.currentDocument = createCodapDocument() | ||||||
|
@@ -120,13 +123,20 @@ | |||||
if (metadata) { | ||||||
const metadataEntries = Object.entries(metadata) | ||||||
metadataEntries.forEach(([key, value]) => { | ||||||
if (value != null) { | ||||||
if (value == null) return | ||||||
|
||||||
if (key === "filename") { | ||||||
// We don't save the filename because it is redundant with the filename in the actual | ||||||
// filesystem. | ||||||
// However we need to the extension-less name for the window title | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
or something like that. |
||||||
// The CFM also expects the document to have a name field when the document | ||||||
// is loaded from a filesystem that doesn't use filenames. | ||||||
this.currentDocument.setTitleFromFilename(value) | ||||||
} else { | ||||||
this.currentDocument.setProperty(key, value) | ||||||
} | ||||||
}) | ||||||
} | ||||||
const docTitle = this.currentDocument.getDocumentTitle() | ||||||
this.currentDocument.setTitle(docTitle || t("DG.Document.defaultDocumentName")) | ||||||
if (content.revisionId && this.treeManager) { | ||||||
// Restore the revisionId from the stored document | ||||||
// This will allow us to consistently compare the local document | ||||||
|
@@ -153,22 +163,42 @@ | |||||
|
||||||
@action | ||||||
enableDocumentMonitoring() { | ||||||
this.currentDocument?.treeMonitor?.enableMonitoring() | ||||||
if (this.currentDocument && !this.dirtyMonitorDisposer) { | ||||||
if (!this.currentDocument) return | ||||||
|
||||||
this.currentDocument.treeMonitor?.enableMonitoring() | ||||||
if (!this.dirtyMonitorDisposer) { | ||||||
this.dirtyMonitorDisposer = reaction( | ||||||
() => this.treeManager?.revisionId, | ||||||
() => { | ||||||
this.cfm?.client.dirty(true) | ||||||
} | ||||||
) | ||||||
} | ||||||
|
||||||
// TODO: look for tests of opening documents so we can update them to check | ||||||
// the title | ||||||
if (!this.titleMonitorDisposer) { | ||||||
this.titleMonitorDisposer = autorun(() => { | ||||||
const { title } = this.currentDocument | ||||||
|
||||||
// TODO: handle componentMode and embeddedMode | ||||||
// if ((DG.get('componentMode') === 'yes') || (DG.get('embeddedMode') === 'yes')) { | ||||||
// return; | ||||||
// } | ||||||
|
||||||
const titleString = t("DG.main.page.title", {vars: [title, kAppName]}) | ||||||
window.document.title = titleString | ||||||
}) | ||||||
} | ||||||
} | ||||||
|
||||||
@action | ||||||
disableDocumentMonitoring() { | ||||||
this.currentDocument?.treeMonitor?.disableMonitoring() | ||||||
this.dirtyMonitorDisposer?.() | ||||||
this.dirtyMonitorDisposer = undefined | ||||||
this.titleMonitorDisposer?.() | ||||||
this.titleMonitorDisposer = undefined | ||||||
} | ||||||
|
||||||
@action | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ interface IOptions { | |
} | ||
export function createCodapDocument(snapshot?: ICodapDocumentModelSnapshot, options?: IOptions): IDocumentModel { | ||
const { layout = "free", noGlobals = false } = options || {} | ||
// Note: The version and build will not be updated after the document is first created | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can/should we do something about that? Seems like the expectation would be that it would be the version that most recently saved it. |
||
const document = createDocumentModel({ type: "CODAP", version, build: `${buildNumber}`, ...snapshot }) | ||
// create the content if there isn't any | ||
if (!document.content) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.