Improve ink annotations support:
- Allow to select in sidebar or PDF page - Allow to delete or change color - Generate image and store as with image annotation
This commit is contained in:
parent
6206209ed2
commit
59455ebfa7
5 changed files with 18 additions and 31 deletions
|
@ -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');
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -335,6 +335,7 @@ Zotero.PDFWorker = new PDFWorker();
|
|||
|
||||
|
||||
// PDF Renderer
|
||||
// TODO: Add ink annotations rendering
|
||||
class PDFRenderer {
|
||||
constructor() {
|
||||
this._browser = null;
|
||||
|
|
|
@ -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': {
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit fdedbbefcf56693915628f54f581c1897d61bc67
|
||||
Subproject commit d659a92acdf1450eccb2c9f58cc7808197b76e9f
|
Loading…
Add table
Reference in a new issue