Skip to content
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

[api-minor][editor] Indicate, in the title, if the document has been edited (bug 1785854) #15351

Merged
merged 1 commit into from Aug 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/display/annotation_storage.js
Expand Up @@ -68,12 +68,21 @@ class AnnotationStorage {
* Remove a value from the storage.
* @param {string} key
*/
removeKey(key) {
remove(key) {
this._storage.delete(key);

if (this._storage.size === 0) {
this.resetModified();
}

if (typeof this.onAnnotationEditor === "function") {
for (const value of this._storage.values()) {
if (value instanceof AnnotationEditor) {
return;
}
}
this.onAnnotationEditor(null);
}
}

/**
Expand Down Expand Up @@ -172,15 +181,6 @@ class AnnotationStorage {
return clone;
}

get hasAnnotationEditors() {
for (const value of this._storage.values()) {
if (value instanceof AnnotationEditor) {
return true;
}
}
return false;
}

/**
* PLEASE NOTE: Only intended for usage within the API itself.
* @ignore
Expand Down
2 changes: 1 addition & 1 deletion src/display/editor/annotation_editor_layer.js
Expand Up @@ -207,7 +207,7 @@ class AnnotationEditorLayer {

this.#uiManager.removeEditor(editor);
this.detach(editor);
this.annotationStorage.removeKey(editor.id);
this.annotationStorage.remove(editor.id);
editor.div.style.display = "none";
setTimeout(() => {
// When the div is removed from DOM the focus can move on the
Expand Down
37 changes: 22 additions & 15 deletions web/app.js
Expand Up @@ -262,6 +262,8 @@ const PDFViewerApplication = {
_wheelUnusedTicks: 0,
_idleCallbacks: new Set(),
_PDFBug: null,
_hasAnnotationEditors: false,
_title: document.title,
_printAnnotationStoragePromise: null,

// Called once when the document is loaded.
Expand Down Expand Up @@ -788,12 +790,14 @@ const PDFViewerApplication = {
this.setTitle(title);
},

setTitle(title) {
setTitle(title = this._title) {
this._title = title;

if (this.isViewerEmbedded) {
// Embedded PDF viewers should not be changing their parent page's title.
return;
}
document.title = title;
document.title = `${this._hasAnnotationEditors ? "* " : ""}${title}`;
},

get _docFilename() {
Expand Down Expand Up @@ -880,10 +884,12 @@ const PDFViewerApplication = {
this._contentLength = null;
this._saveInProgress = false;
this._docStats = null;
this._hasAnnotationEditors = false;

this._cancelIdleCallbacks();
promises.push(this.pdfScriptingManager.destroyPromise);

this.setTitle();
this.pdfSidebar.reset();
this.pdfOutlineViewer.reset();
this.pdfAttachmentViewer.reset();
Expand Down Expand Up @@ -1045,12 +1051,10 @@ const PDFViewerApplication = {
this._saveInProgress = false;
}

if (this.pdfDocument?.annotationStorage.hasAnnotationEditors) {
if (this._hasAnnotationEditors) {
this.externalServices.reportTelemetry({
type: "editing",
data: {
type: "save",
},
data: { type: "save" },
});
}
},
Expand Down Expand Up @@ -1582,7 +1586,7 @@ const PDFViewerApplication = {
}
if (pdfTitle) {
this.setTitle(
`${pdfTitle} - ${this._contentDispositionFilename || document.title}`
`${pdfTitle} - ${this._contentDispositionFilename || this._title}`
);
} else if (this._contentDispositionFilename) {
this.setTitle(this._contentDispositionFilename);
Expand Down Expand Up @@ -1744,10 +1748,15 @@ const PDFViewerApplication = {
}
};
annotationStorage.onAnnotationEditor = typeStr => {
this.externalServices.reportTelemetry({
type: "editing",
data: { type: typeStr },
});
this._hasAnnotationEditors = !!typeStr;
this.setTitle();

if (typeStr) {
this.externalServices.reportTelemetry({
type: "editing",
data: { type: typeStr },
});
}
};
},

Expand Down Expand Up @@ -1888,12 +1897,10 @@ const PDFViewerApplication = {
type: "print",
});

if (this.pdfDocument?.annotationStorage.hasAnnotationEditors) {
if (this._hasAnnotationEditors) {
this.externalServices.reportTelemetry({
type: "editing",
data: {
type: "print",
},
data: { type: "print" },
});
}
},
Expand Down