mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
[Editor] Dispatch an event when some global states are changing
- this way the context menu in Firefox can take into account what we have in the clipboard, if an editor is selected, ... - when the user will click on a context menu item, an action will be triggered, hence this patch adds what is required to handle it; - some tests will be added in the Firefox' patch.
This commit is contained in:
parent
a1ac1a61b7
commit
ec0f9f6dcf
8 changed files with 278 additions and 28 deletions
14
web/app.js
14
web/app.js
|
@ -186,6 +186,10 @@ class DefaultExternalServices {
|
|||
static get isInAutomation() {
|
||||
return shadow(this, "isInAutomation", false);
|
||||
}
|
||||
|
||||
static updateEditorStates(data) {
|
||||
throw new Error("Not implemented: updateEditorStates");
|
||||
}
|
||||
}
|
||||
|
||||
const PDFViewerApplication = {
|
||||
|
@ -1954,6 +1958,12 @@ const PDFViewerApplication = {
|
|||
eventBus._on("fileinputchange", webViewerFileInputChange);
|
||||
eventBus._on("openfile", webViewerOpenFile);
|
||||
}
|
||||
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
|
||||
eventBus._on(
|
||||
"annotationeditorstateschanged",
|
||||
webViewerAnnotationEditorStatesChanged
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
bindWindowEvents() {
|
||||
|
@ -3076,6 +3086,10 @@ function beforeUnload(evt) {
|
|||
return false;
|
||||
}
|
||||
|
||||
function webViewerAnnotationEditorStatesChanged(data) {
|
||||
PDFViewerApplication.externalServices.updateEditorStates(data);
|
||||
}
|
||||
|
||||
/* Abstract factory for the print service. */
|
||||
const PDFPrintServiceFactory = {
|
||||
instance: {
|
||||
|
|
|
@ -640,6 +640,10 @@ class BaseViewer {
|
|||
if (this._scriptingManager) {
|
||||
this._scriptingManager.setDocument(null);
|
||||
}
|
||||
if (this.#annotationEditorUIManager) {
|
||||
this.#annotationEditorUIManager.destroy();
|
||||
this.#annotationEditorUIManager = null;
|
||||
}
|
||||
}
|
||||
|
||||
this.pdfDocument = pdfDocument;
|
||||
|
@ -899,7 +903,6 @@ class BaseViewer {
|
|||
}
|
||||
|
||||
_resetView() {
|
||||
this.#annotationEditorUIManager = null;
|
||||
this._pages = [];
|
||||
this._currentPageNumber = 1;
|
||||
this._currentScale = UNKNOWN_SCALE;
|
||||
|
|
|
@ -271,6 +271,20 @@ class MozL10n {
|
|||
window.addEventListener("save", handleEvent);
|
||||
})();
|
||||
|
||||
(function listenEditingEvent() {
|
||||
const handleEvent = function ({ detail }) {
|
||||
if (!PDFViewerApplication.initialized) {
|
||||
return;
|
||||
}
|
||||
PDFViewerApplication.eventBus.dispatch("editingaction", {
|
||||
source: window,
|
||||
name: detail.name,
|
||||
});
|
||||
};
|
||||
|
||||
window.addEventListener("editingaction", handleEvent);
|
||||
})();
|
||||
|
||||
class FirefoxComDataRangeTransport extends PDFDataRangeTransport {
|
||||
requestDataRange(begin, end) {
|
||||
FirefoxCom.request("requestDataRange", { begin, end });
|
||||
|
@ -384,6 +398,10 @@ class FirefoxExternalServices extends DefaultExternalServices {
|
|||
return new FirefoxPreferences();
|
||||
}
|
||||
|
||||
static updateEditorStates(data) {
|
||||
FirefoxCom.request("updateEditorStates", data);
|
||||
}
|
||||
|
||||
static createL10n(options) {
|
||||
const mozL10n = document.mozL10n;
|
||||
// TODO refactor mozL10n.setExternalLocalizerServices
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue