Improve the handling of the currentOutlineButton
enabling/disabling (PR 12777 follow-up)
It's obviously better and more correct to handle the "pagesloaded" case within `PDFOutlineViewer` *itself*, rather than essentially splitting the logic in two parts and forcing `PDFSidebar` to deal with what should've been handled internally in `PDFOutlineViewer`. This is what I *should* have done in PR 12777, but for some reason didn't figure out how to implement it well enough back then; sorry about the churn here!
This commit is contained in:
parent
05b0798824
commit
27062f72c2
@ -53,6 +53,15 @@ class PDFOutlineViewer extends BaseTreeViewer {
|
||||
});
|
||||
this.eventBus._on("pagesloaded", evt => {
|
||||
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._sidebarView = evt.view;
|
||||
@ -66,17 +75,32 @@ class PDFOutlineViewer extends BaseTreeViewer {
|
||||
this._pageNumberToDestHashCapability = null;
|
||||
this._currentPageNumber = 1;
|
||||
this._isPagesLoaded = false;
|
||||
|
||||
if (
|
||||
this._currentOutlineItemCapability &&
|
||||
!this._currentOutlineItemCapability.settled
|
||||
) {
|
||||
this._currentOutlineItemCapability.resolve(/* enabled = */ false);
|
||||
}
|
||||
this._currentOutlineItemCapability = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_dispatchEvent(outlineCount) {
|
||||
this._currentOutlineItemCapability = createPromiseCapability();
|
||||
if (
|
||||
outlineCount === 0 ||
|
||||
this._pdfDocument?.loadingParams.disableAutoFetch
|
||||
) {
|
||||
this._currentOutlineItemCapability.resolve(/* enabled = */ false);
|
||||
}
|
||||
|
||||
this.eventBus.dispatch("outlineloaded", {
|
||||
source: this,
|
||||
outlineCount,
|
||||
enableCurrentOutlineItemButton:
|
||||
outlineCount > 0 && !this._pdfDocument?.loadingParams.disableAutoFetch,
|
||||
currentOutlineItemPromise: this._currentOutlineItemCapability.promise,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -425,11 +425,12 @@ class PDFSidebar {
|
||||
this.eventBus._on("outlineloaded", evt => {
|
||||
onTreeLoaded(evt.outlineCount, this.outlineButton, SidebarView.OUTLINE);
|
||||
|
||||
if (evt.enableCurrentOutlineItemButton) {
|
||||
this.pdfViewer.pagesPromise.then(() => {
|
||||
this._currentOutlineItemButton.disabled = !this.isInitialViewSet;
|
||||
});
|
||||
}
|
||||
evt.currentOutlineItemPromise.then(enabled => {
|
||||
if (!this.isInitialViewSet) {
|
||||
return;
|
||||
}
|
||||
this._currentOutlineItemButton.disabled = !enabled;
|
||||
});
|
||||
});
|
||||
|
||||
this.eventBus._on("attachmentsloaded", evt => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user