mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-04-09 23:04:02 +02:00
Merge pull request #20788 from calixteman/organize_context_menu
Add the pages organization actions in the Firefox context menu (bug 2018138)
This commit is contained in:
commit
72f98d4e00
@ -1852,7 +1852,7 @@ class AnnotationEditorUIManager {
|
||||
);
|
||||
|
||||
if (hasChanged) {
|
||||
this._eventBus.dispatch("annotationeditorstateschanged", {
|
||||
this._eventBus.dispatch("editingstateschanged", {
|
||||
source: this,
|
||||
details: Object.assign(this.#previousStates, details),
|
||||
});
|
||||
|
||||
@ -2173,7 +2173,7 @@ const PDFViewerApplication = {
|
||||
}
|
||||
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
|
||||
eventBus._on(
|
||||
"annotationeditorstateschanged",
|
||||
"editingstateschanged",
|
||||
evt => externalServices.updateEditorStates(evt),
|
||||
opts
|
||||
);
|
||||
|
||||
@ -133,6 +133,10 @@ class PDFThumbnailViewer {
|
||||
|
||||
#scrollableContainerHeight = 0;
|
||||
|
||||
#previousStates = {
|
||||
hasSelectedPages: false,
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {PDFThumbnailViewerOptions} options
|
||||
*/
|
||||
@ -185,6 +189,23 @@ class PDFThumbnailViewer {
|
||||
|
||||
this.#toggleMenuEntries(false);
|
||||
button.disabled = true;
|
||||
|
||||
this.eventBus.on("editingaction", ({ name }) => {
|
||||
switch (name) {
|
||||
case "copyPage":
|
||||
this.#copyPages();
|
||||
break;
|
||||
case "cutPage":
|
||||
this.#cutPages();
|
||||
break;
|
||||
case "deletePage":
|
||||
this.#deletePages();
|
||||
break;
|
||||
case "savePage":
|
||||
this.#saveExtractedPages();
|
||||
break;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
manageMenu.button.hidden = true;
|
||||
}
|
||||
@ -198,6 +219,24 @@ class PDFThumbnailViewer {
|
||||
this.#addEventListeners();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the different possible states of this manager, e.g. is there
|
||||
* something to copy, paste, ...
|
||||
* @param {Object} details
|
||||
*/
|
||||
#dispatchUpdateStates(details) {
|
||||
const hasChanged = Object.entries(details).some(
|
||||
([key, value]) => this.#previousStates[key] !== value
|
||||
);
|
||||
|
||||
if (hasChanged) {
|
||||
this.eventBus.dispatch("editingstateschanged", {
|
||||
source: this,
|
||||
details: Object.assign(this.#previousStates, details),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#scrollUpdated() {
|
||||
this.renderingQueue.renderHighestPriority();
|
||||
}
|
||||
@ -730,6 +769,9 @@ class PDFThumbnailViewer {
|
||||
this.#manageCopyButton.disabled =
|
||||
this.#manageCutButton.disabled =
|
||||
!this.#selectedPages?.size;
|
||||
this.#dispatchUpdateStates({
|
||||
hasSelectedPages: !!this.#selectedPages?.size,
|
||||
});
|
||||
}
|
||||
|
||||
#toggleMenuEntries(enable) {
|
||||
@ -895,6 +937,16 @@ class PDFThumbnailViewer {
|
||||
this.#computeThumbnailsPosition();
|
||||
}
|
||||
});
|
||||
this.container.addEventListener("focusout", () => {
|
||||
this.#dispatchUpdateStates({
|
||||
hasSelectedPages: false,
|
||||
});
|
||||
});
|
||||
this.container.addEventListener("focusin", () => {
|
||||
this.#dispatchUpdateStates({
|
||||
hasSelectedPages: !!this.#selectedPages?.size,
|
||||
});
|
||||
});
|
||||
this.container.addEventListener("keydown", e => {
|
||||
const { target } = e;
|
||||
const isCheckbox =
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user