Merge pull request #13212 from Snuffleupagus/BaseTreeViewer-init-checks
Check that the correct `pdfDocument` is still active, before rendering the outline/attachments/layers
This commit is contained in:
commit
86374d4f75
@ -1383,14 +1383,23 @@ const PDFViewerApplication = {
|
|||||||
|
|
||||||
onePageRendered.then(() => {
|
onePageRendered.then(() => {
|
||||||
pdfDocument.getOutline().then(outline => {
|
pdfDocument.getOutline().then(outline => {
|
||||||
|
if (pdfDocument !== this.pdfDocument) {
|
||||||
|
return; // The document was closed while the outline resolved.
|
||||||
|
}
|
||||||
this.pdfOutlineViewer.render({ outline, pdfDocument });
|
this.pdfOutlineViewer.render({ outline, pdfDocument });
|
||||||
});
|
});
|
||||||
pdfDocument.getAttachments().then(attachments => {
|
pdfDocument.getAttachments().then(attachments => {
|
||||||
|
if (pdfDocument !== this.pdfDocument) {
|
||||||
|
return; // The document was closed while the attachments resolved.
|
||||||
|
}
|
||||||
this.pdfAttachmentViewer.render({ attachments });
|
this.pdfAttachmentViewer.render({ attachments });
|
||||||
});
|
});
|
||||||
// Ensure that the layers accurately reflects the current state in the
|
// Ensure that the layers accurately reflects the current state in the
|
||||||
// viewer itself, rather than the default state provided by the API.
|
// viewer itself, rather than the default state provided by the API.
|
||||||
pdfViewer.optionalContentConfigPromise.then(optionalContentConfig => {
|
pdfViewer.optionalContentConfigPromise.then(optionalContentConfig => {
|
||||||
|
if (pdfDocument !== this.pdfDocument) {
|
||||||
|
return; // The document was closed while the layers resolved.
|
||||||
|
}
|
||||||
this.pdfLayerViewer.render({ optionalContentConfig, pdfDocument });
|
this.pdfLayerViewer.render({ optionalContentConfig, pdfDocument });
|
||||||
});
|
});
|
||||||
if (
|
if (
|
||||||
|
@ -53,6 +53,15 @@ class PDFOutlineViewer extends BaseTreeViewer {
|
|||||||
});
|
});
|
||||||
this.eventBus._on("pagesloaded", evt => {
|
this.eventBus._on("pagesloaded", evt => {
|
||||||
this._isPagesLoaded = !!evt.pagesCount;
|
this._isPagesLoaded = !!evt.pagesCount;
|
||||||
|
|
||||||
|
// If the capability is still pending, note the `_dispatchEvent`-method,
|
||||||
|
// we know that the `currentOutlineItem`-button should be enabled here.
|
||||||
|
if (
|
||||||
|
this._currentOutlineItemCapability &&
|
||||||
|
!this._currentOutlineItemCapability.settled
|
||||||
|
) {
|
||||||
|
this._currentOutlineItemCapability.resolve(/* enabled = */ true);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
this.eventBus._on("sidebarviewchanged", evt => {
|
this.eventBus._on("sidebarviewchanged", evt => {
|
||||||
this._sidebarView = evt.view;
|
this._sidebarView = evt.view;
|
||||||
@ -66,17 +75,32 @@ class PDFOutlineViewer extends BaseTreeViewer {
|
|||||||
this._pageNumberToDestHashCapability = null;
|
this._pageNumberToDestHashCapability = null;
|
||||||
this._currentPageNumber = 1;
|
this._currentPageNumber = 1;
|
||||||
this._isPagesLoaded = false;
|
this._isPagesLoaded = false;
|
||||||
|
|
||||||
|
if (
|
||||||
|
this._currentOutlineItemCapability &&
|
||||||
|
!this._currentOutlineItemCapability.settled
|
||||||
|
) {
|
||||||
|
this._currentOutlineItemCapability.resolve(/* enabled = */ false);
|
||||||
|
}
|
||||||
|
this._currentOutlineItemCapability = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_dispatchEvent(outlineCount) {
|
_dispatchEvent(outlineCount) {
|
||||||
|
this._currentOutlineItemCapability = createPromiseCapability();
|
||||||
|
if (
|
||||||
|
outlineCount === 0 ||
|
||||||
|
this._pdfDocument?.loadingParams.disableAutoFetch
|
||||||
|
) {
|
||||||
|
this._currentOutlineItemCapability.resolve(/* enabled = */ false);
|
||||||
|
}
|
||||||
|
|
||||||
this.eventBus.dispatch("outlineloaded", {
|
this.eventBus.dispatch("outlineloaded", {
|
||||||
source: this,
|
source: this,
|
||||||
outlineCount,
|
outlineCount,
|
||||||
enableCurrentOutlineItemButton:
|
currentOutlineItemPromise: this._currentOutlineItemCapability.promise,
|
||||||
outlineCount > 0 && !this._pdfDocument?.loadingParams.disableAutoFetch,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -425,11 +425,12 @@ class PDFSidebar {
|
|||||||
this.eventBus._on("outlineloaded", evt => {
|
this.eventBus._on("outlineloaded", evt => {
|
||||||
onTreeLoaded(evt.outlineCount, this.outlineButton, SidebarView.OUTLINE);
|
onTreeLoaded(evt.outlineCount, this.outlineButton, SidebarView.OUTLINE);
|
||||||
|
|
||||||
if (evt.enableCurrentOutlineItemButton) {
|
evt.currentOutlineItemPromise.then(enabled => {
|
||||||
this.pdfViewer.pagesPromise.then(() => {
|
if (!this.isInitialViewSet) {
|
||||||
this._currentOutlineItemButton.disabled = !this.isInitialViewSet;
|
return;
|
||||||
});
|
}
|
||||||
}
|
this._currentOutlineItemButton.disabled = !enabled;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
this.eventBus._on("attachmentsloaded", evt => {
|
this.eventBus._on("attachmentsloaded", evt => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user