diff --git a/chrome/content/zotero/xpcom/annotations.js b/chrome/content/zotero/xpcom/annotations.js index 2ce739932e..5fa92bc8b9 100644 --- a/chrome/content/zotero/xpcom/annotations.js +++ b/chrome/content/zotero/xpcom/annotations.js @@ -54,8 +54,8 @@ Zotero.Annotations = new function () { if (!item) { throw new Error(`Item not found`); } - if (item.itemType != 'annotation' || item.annotationType != 'image') { - throw new Error("Item must be an image annotation item"); + if (item.itemType != 'annotation' || !['image', 'ink'].includes(item.annotationType)) { + throw new Error("Item must be an image/ink annotation item"); } var cacheDir = Zotero.DataDirectory.getSubdirectory('cache', true); @@ -127,7 +127,7 @@ Zotero.Annotations = new function () { if (o.type == 'highlight') { o.text = item.annotationText; } - else if (o.type == 'image') { + else if (['image', 'ink'].includes(o.type)) { let file = this.getCacheImagePath(item); if (await OS.File.exists(file)) { o.image = await Zotero.File.generateDataURI(file, 'image/png'); diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js index 4774f47f54..0eceae03d9 100644 --- a/chrome/content/zotero/xpcom/data/item.js +++ b/chrome/content/zotero/xpcom/data/item.js @@ -1864,8 +1864,11 @@ Zotero.Item.prototype._saveData = Zotero.Promise.coroutine(function* (env) { // Clear cached child items of the parent attachment reloadParentChildItems[parentItemID] = true; - // Mark cache image for deletion when image annotation position changes - if (!isNew && type == 'image' && this._hasFieldChanged('annotationPosition')) { + // Mark cache image for deletion when image or ink annotation position (or ink color) changes + if (!isNew && ( + ['image', 'ink'].includes(type) && this._hasFieldChanged('annotationPosition') + || type == 'ink' && this._hasFieldChanged('annotationColor') + )) { let libraryID = this.libraryID; let key = this.key; Zotero.DB.addCurrentCallback("commit", function () { @@ -3764,23 +3767,6 @@ for (let name of ['position']) { } -/** - * @property {Zotero.Item} annotationImageAttachment - */ -Zotero.defineProperty(Zotero.Item.prototype, 'annotationImageAttachment', { - get: function () { - if (!this.isImageAnnotation()) { - return undefined; - } - var attachments = this.getAttachments(); - if (!attachments.length) { - throw new Error("No attachments found for image annotation"); - } - return Zotero.Items.get(attachments[0]); - } -}); - - /** * Determine if an item is an annotation * @@ -3796,8 +3782,8 @@ Zotero.Item.prototype.isAnnotation = function() { * * @return {Boolean} **/ -Zotero.Item.prototype.isImageAnnotation = function() { - return this.isAnnotation() && this._getLatestField('annotationType') == 'image'; +Zotero.Item.prototype.isAnnotationSupportingImage = function() { + return this.isAnnotation() && ['image', 'ink'].includes(this._getLatestField('annotationType')); } @@ -4709,9 +4695,9 @@ Zotero.Item.prototype._eraseData = Zotero.Promise.coroutine(function* (env) { // Zotero.Sync.EventListeners.ChangeListener needs to know if this was a storage file env.notifierData[this.id].storageDeleteLog = this.isStoredFileAttachment(); } - // Delete cached file for image annotation + // Delete cached file for image and ink annotations else if (this.isAnnotation()) { - if (this.isImageAnnotation()) { + if (this.isAnnotationSupportingImage()) { yield Zotero.Annotations.removeCacheImage(this); } } diff --git a/chrome/content/zotero/xpcom/pdfWorker/manager.js b/chrome/content/zotero/xpcom/pdfWorker/manager.js index 787dcf2a0c..c3477c0569 100644 --- a/chrome/content/zotero/xpcom/pdfWorker/manager.js +++ b/chrome/content/zotero/xpcom/pdfWorker/manager.js @@ -335,6 +335,7 @@ Zotero.PDFWorker = new PDFWorker(); // PDF Renderer +// TODO: Add ink annotations rendering class PDFRenderer { constructor() { this._browser = null; diff --git a/chrome/content/zotero/xpcom/reader.js b/chrome/content/zotero/xpcom/reader.js index 8f0a52c08f..081d4a5b3f 100644 --- a/chrome/content/zotero/xpcom/reader.js +++ b/chrome/content/zotero/xpcom/reader.js @@ -391,7 +391,7 @@ class ReaderInstance { popup.openPopupAtScreen(data.x, data.y, true); } - _openAnnotationPopup(x, y, ids, colors, selectedColor, readOnly) { + _openAnnotationPopup(x, y, ids, colors, selectedColor, readOnly, enableAddToNote) { let popup = this._window.document.createElement('menupopup'); this._popupset.appendChild(popup); popup.addEventListener('popuphidden', function () { @@ -402,7 +402,7 @@ class ReaderInstance { menuitem = this._window.document.createElement('menuitem'); menuitem.setAttribute('label', Zotero.getString('pdfReader.addToNote')); let hasActiveEditor = this._window.ZoteroContextPane && this._window.ZoteroContextPane.getActiveEditor(); - menuitem.setAttribute('disabled', !hasActiveEditor); + menuitem.setAttribute('disabled', !hasActiveEditor || !enableAddToNote); menuitem.addEventListener('command', () => { let data = { action: 'popupCmd', @@ -551,8 +551,8 @@ class ReaderInstance { return; } case 'openAnnotationPopup': { - let { x, y, ids, colors, selectedColor, readOnly } = message; - this._openAnnotationPopup(x, y, ids, colors, selectedColor, readOnly); + let { x, y, ids, colors, selectedColor, readOnly, enableAddToNote } = message; + this._openAnnotationPopup(x, y, ids, colors, selectedColor, readOnly, enableAddToNote); return; } case 'openColorPopup': { diff --git a/pdf-reader b/pdf-reader index fdedbbefcf..d659a92acd 160000 --- a/pdf-reader +++ b/pdf-reader @@ -1 +1 @@ -Subproject commit fdedbbefcf56693915628f54f581c1897d61bc67 +Subproject commit d659a92acdf1450eccb2c9f58cc7808197b76e9f