Merge pull request #12871 from Snuffleupagus/simplify-pdfSidebarNotification
Only display a notification on the `sidebarToggle`-button, and not the individual view-buttons (PR 7959 follow-up)
This commit is contained in:
commit
a10dc1cb6e
@ -25,8 +25,6 @@ const UI_NOTIFICATION_CLASS = "pdfSidebarNotification";
|
|||||||
* @property {PDFThumbnailViewer} pdfThumbnailViewer - The thumbnail viewer.
|
* @property {PDFThumbnailViewer} pdfThumbnailViewer - The thumbnail viewer.
|
||||||
* @property {EventBus} eventBus - The application event bus.
|
* @property {EventBus} eventBus - The application event bus.
|
||||||
* @property {IL10n} l10n - The localization service.
|
* @property {IL10n} l10n - The localization service.
|
||||||
* @property {boolean} [disableNotification] - Disable the notification for
|
|
||||||
* documents containing outline/attachments. The default value is `false`.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -69,7 +67,6 @@ class PDFSidebar {
|
|||||||
pdfThumbnailViewer,
|
pdfThumbnailViewer,
|
||||||
eventBus,
|
eventBus,
|
||||||
l10n = NullL10n,
|
l10n = NullL10n,
|
||||||
disableNotification = false,
|
|
||||||
}) {
|
}) {
|
||||||
this.isOpen = false;
|
this.isOpen = false;
|
||||||
this.active = SidebarView.THUMBS;
|
this.active = SidebarView.THUMBS;
|
||||||
@ -103,7 +100,6 @@ class PDFSidebar {
|
|||||||
|
|
||||||
this.eventBus = eventBus;
|
this.eventBus = eventBus;
|
||||||
this.l10n = l10n;
|
this.l10n = l10n;
|
||||||
this._disableNotification = disableNotification;
|
|
||||||
|
|
||||||
this._addEventListeners();
|
this._addEventListeners();
|
||||||
}
|
}
|
||||||
@ -111,7 +107,7 @@ class PDFSidebar {
|
|||||||
reset() {
|
reset() {
|
||||||
this.isInitialViewSet = false;
|
this.isInitialViewSet = false;
|
||||||
|
|
||||||
this._hideUINotification(null);
|
this._hideUINotification(/* reset = */ true);
|
||||||
this.switchView(SidebarView.THUMBS);
|
this.switchView(SidebarView.THUMBS);
|
||||||
|
|
||||||
this.outlineButton.disabled = false;
|
this.outlineButton.disabled = false;
|
||||||
@ -259,7 +255,6 @@ class PDFSidebar {
|
|||||||
if (isViewChanged) {
|
if (isViewChanged) {
|
||||||
this._dispatchEvent();
|
this._dispatchEvent();
|
||||||
}
|
}
|
||||||
this._hideUINotification(this.active);
|
|
||||||
return isViewChanged;
|
return isViewChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -278,7 +273,7 @@ class PDFSidebar {
|
|||||||
this._forceRendering();
|
this._forceRendering();
|
||||||
this._dispatchEvent();
|
this._dispatchEvent();
|
||||||
|
|
||||||
this._hideUINotification(this.active);
|
this._hideUINotification();
|
||||||
}
|
}
|
||||||
|
|
||||||
close() {
|
close() {
|
||||||
@ -347,11 +342,7 @@ class PDFSidebar {
|
|||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_showUINotification(view) {
|
_showUINotification() {
|
||||||
if (this._disableNotification) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.l10n
|
this.l10n
|
||||||
.get(
|
.get(
|
||||||
"toggle_sidebar_notification2.title",
|
"toggle_sidebar_notification2.title",
|
||||||
@ -366,67 +357,27 @@ class PDFSidebar {
|
|||||||
// Only show the notification on the `toggleButton` if the sidebar is
|
// Only show the notification on the `toggleButton` if the sidebar is
|
||||||
// currently closed, to avoid unnecessarily bothering the user.
|
// currently closed, to avoid unnecessarily bothering the user.
|
||||||
this.toggleButton.classList.add(UI_NOTIFICATION_CLASS);
|
this.toggleButton.classList.add(UI_NOTIFICATION_CLASS);
|
||||||
} else if (view === this.active) {
|
|
||||||
// If the sidebar is currently open *and* the `view` is visible, do not
|
|
||||||
// bother the user with a notification on the corresponding button.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (view) {
|
|
||||||
case SidebarView.OUTLINE:
|
|
||||||
this.outlineButton.classList.add(UI_NOTIFICATION_CLASS);
|
|
||||||
break;
|
|
||||||
case SidebarView.ATTACHMENTS:
|
|
||||||
this.attachmentsButton.classList.add(UI_NOTIFICATION_CLASS);
|
|
||||||
break;
|
|
||||||
case SidebarView.LAYERS:
|
|
||||||
this.layersButton.classList.add(UI_NOTIFICATION_CLASS);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_hideUINotification(view) {
|
_hideUINotification(reset = false) {
|
||||||
if (this._disableNotification) {
|
if (this.isOpen || reset) {
|
||||||
return;
|
// Only hide the notification on the `toggleButton` if the sidebar is
|
||||||
}
|
// currently open, or when the current PDF document is being closed.
|
||||||
|
|
||||||
const removeNotification = sidebarView => {
|
|
||||||
switch (sidebarView) {
|
|
||||||
case SidebarView.OUTLINE:
|
|
||||||
this.outlineButton.classList.remove(UI_NOTIFICATION_CLASS);
|
|
||||||
break;
|
|
||||||
case SidebarView.ATTACHMENTS:
|
|
||||||
this.attachmentsButton.classList.remove(UI_NOTIFICATION_CLASS);
|
|
||||||
break;
|
|
||||||
case SidebarView.LAYERS:
|
|
||||||
this.layersButton.classList.remove(UI_NOTIFICATION_CLASS);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!this.isOpen && view !== null) {
|
|
||||||
// Only hide the notifications when the sidebar is currently open,
|
|
||||||
// or when it is being reset (i.e. `view === null`).
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.toggleButton.classList.remove(UI_NOTIFICATION_CLASS);
|
this.toggleButton.classList.remove(UI_NOTIFICATION_CLASS);
|
||||||
|
|
||||||
if (view !== null) {
|
|
||||||
removeNotification(view);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Remove all sidebar notifications on reset.
|
|
||||||
for (view in SidebarView) {
|
|
||||||
removeNotification(SidebarView[view]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.l10n.get("toggle_sidebar.title", null, "Toggle Sidebar").then(msg => {
|
if (reset) {
|
||||||
|
this.l10n
|
||||||
|
.get("toggle_sidebar.title", null, "Toggle Sidebar")
|
||||||
|
.then(msg => {
|
||||||
this.toggleButton.title = msg;
|
this.toggleButton.title = msg;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
@ -475,7 +426,7 @@ class PDFSidebar {
|
|||||||
button.disabled = !count;
|
button.disabled = !count;
|
||||||
|
|
||||||
if (count) {
|
if (count) {
|
||||||
this._showUINotification(view);
|
this._showUINotification();
|
||||||
} else if (this.active === view) {
|
} else if (this.active === view) {
|
||||||
// If the `view` was opened by the user during document load,
|
// If the `view` was opened by the user during document load,
|
||||||
// switch away from it if it turns out to be empty.
|
// switch away from it if it turns out to be empty.
|
||||||
|
Loading…
Reference in New Issue
Block a user