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

Attempt to delay disabling of the attachment view until FileAttachment annotations of the *initial* page has been parsed #8788

Merged
merged 2 commits into from
Aug 17, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions web/pdf_attachment_viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,12 @@ class PDFAttachmentViewer {
* @param {PDFAttachmentViewerOptions} options
*/
constructor({ container, eventBus, downloadManager, }) {
this.attachments = null;

this.container = container;
this.eventBus = eventBus;
this.downloadManager = downloadManager;

this._renderedCapability = createPromiseCapability();
this.reset();

this.eventBus.on('fileattachmentannotation',
this._appendAttachment.bind(this));
}
Expand All @@ -63,12 +62,12 @@ class PDFAttachmentViewer {
* @private
*/
_dispatchEvent(attachmentsCount) {
this._renderedCapability.resolve();

this.eventBus.dispatch('attachmentsloaded', {
source: this,
attachmentsCount,
});

this._renderedCapability.resolve();
}

/**
Expand Down
5 changes: 2 additions & 3 deletions web/pdf_outline_viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@ class PDFOutlineViewer {
* @param {PDFOutlineViewerOptions} options
*/
constructor({ container, linkService, eventBus, }) {
this.outline = null;
this.lastToggleIsShow = true;

this.container = container;
this.linkService = linkService;
this.eventBus = eventBus;

this.reset();
}

reset() {
Expand Down
30 changes: 22 additions & 8 deletions web/pdf_sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,17 +420,31 @@ class PDFSidebar {
});

this.eventBus.on('attachmentsloaded', (evt) => {
let attachmentsCount = evt.attachmentsCount;
if (evt.attachmentsCount) {
this.attachmentsButton.disabled = false;

this.attachmentsButton.disabled = !attachmentsCount;

if (attachmentsCount) {
this._showUINotification(SidebarView.ATTACHMENTS);
} else if (this.active === SidebarView.ATTACHMENTS) {
// If the attachment view was opened during document load, switch away
// from it if it turns out that the document has no attachments.
this.switchView(SidebarView.THUMBS);
return;
}

// Attempt to avoid temporarily disabling, and switching away from, the
// attachment view for documents that do not contain proper attachments
// but *only* FileAttachment annotations. Hence we defer those operations
// slightly to allow time for parsing any FileAttachment annotations that
// may be present on the *initially* rendered page of the document.
Promise.resolve().then(() => {
if (this.attachmentsView.hasChildNodes()) {
// FileAttachment annotations were appended to the attachment view.
return;
}
this.attachmentsButton.disabled = true;

if (this.active === SidebarView.ATTACHMENTS) {
// If the attachment view was opened during document load, switch away
// from it if it turns out that the document has no attachments.
this.switchView(SidebarView.THUMBS);
}
});
});

// Update the thumbnailViewer, if visible, when exiting presentation mode.
Expand Down