diff --git a/chrome/content/zotfile/options.js b/chrome/content/zotfile/options.js
index 758bc850..78b9d933 100644
--- a/chrome/content/zotfile/options.js
+++ b/chrome/content/zotfile/options.js
@@ -60,7 +60,21 @@ var updatePreferenceWindow = function (which) {
if(which=="subfolder-tablet" || which=="all") disablePreference("tablet-subfolder", "tablet-subfolderFormat", revert);
// storeCopyOfFile-tablet
- if(which=="storeCopyOfFile" || which=="all") disablePreference("tablet-storeCopyOfFile", "tablet-storeCopyOfFile_suffix", revert);
+ if(which=="storeCopyOfFile" || which=="all"){
+ disablePreference("tablet-storeCopyOfFile", "tablet-storeCopyOfFile_suffix", revert);
+ }
+
+ // storeCopyOfFile or tablet-rename
+ if(which=="storeCopyOfFile" || which=="tablet-rename" || which=="all"){
+ var storecopy = document.getElementById('pref-zotfile-tablet-storeCopyOfFile').value;
+ var rename = document.getElementById('pref-zotfile-tablet-rename').value
+ // the value is the status before clicking
+ if (which == "storeCopyOfFile") storecopy = !storecopy;
+ if (which == "tablet-rename") rename = !rename;
+ // enable keep-one-annotated option when storeCopyOfFile is on but tablet-rename is off
+ var enable_keep_one_annotated = storecopy && !rename;
+ document.getElementById('id-zotfile-tablet-keep-one-annotated').disabled = !enable_keep_one_annotated;
+ }
// batch renaming
if(which=="confirm" || which=="all") disablePreference("confirmation_batch_ask", "confirmation_batch", revert);
diff --git a/chrome/content/zotfile/options.xul b/chrome/content/zotfile/options.xul
index ab3f72f3..29995390 100644
--- a/chrome/content/zotfile/options.xul
+++ b/chrome/content/zotfile/options.xul
@@ -44,6 +44,7 @@
+
@@ -165,12 +166,13 @@
-
+
+
diff --git a/chrome/content/zotfile/overlay.xul b/chrome/content/zotfile/overlay.xul
index 5d5f001c..fd8ec7d1 100644
--- a/chrome/content/zotfile/overlay.xul
+++ b/chrome/content/zotfile/overlay.xul
@@ -20,26 +20,27 @@
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/chrome/content/zotfile/tablet.js b/chrome/content/zotfile/tablet.js
index 32a02225..8550799a 100644
--- a/chrome/content/zotfile/tablet.js
+++ b/chrome/content/zotfile/tablet.js
@@ -465,10 +465,11 @@ Zotero.ZotFile.Tablet = new function() {
/**
* Send selected Zotero attachments to tablet
+ * @param {bool} annotation_only whether only select the annotation file.
* @param {int} idx_subfolder Index of subfolder
* @yield {void}
*/
- this.sendSelectedAttachmentsToTablet = Zotero.Promise.coroutine(function* (idx_subfolder) {
+ this.sendSelectedAttachmentsToTablet = Zotero.Promise.coroutine(function* (annotation_only, idx_subfolder) {
// get selected attachments
var atts = Zotero.Items.get(this.getSelectedAttachments())
.filter(this.checkFileType);
@@ -482,6 +483,40 @@ Zotero.ZotFile.Tablet = new function() {
project_folder = subfolders[idx_subfolder].path;
}
}
+ var annotation_only = typeof annotation_only !== 'undefined' ? annotation_only : false;
+ // only choose the longest `suffix` (A_suffix_suffix > A_suffix > A)
+ if (annotation_only) {
+ var set = new Set();
+ for (let i = 0; i < atts.length; i++) {
+ var att = atts[i];
+ // parentid.filename
+ var filename = att.attachmentFilename;
+ var filetype = this.Utils.getFiletype(filename);
+ var re = new RegExp("\." + filetype + "$", 'i');
+ if(filetype != '') filename = filename.replace(re, "");
+ var suffix_re = new RegExp(this.getPref('tablet.storeCopyOfFile_suffix'), 'i');
+ var rmsuffix = filename.replace(suffix_re, "");
+ while(rmsuffix != filename) {
+ set.add(att.parentItemID + "." + rmsuffix);
+ filename = rmsuffix;
+ rmsuffix = filename.replace(suffix_re, "");
+ }
+ }
+ var i = 0;
+ while(i < atts.length) {
+ var att = atts[i];
+ var filename = att.attachmentFilename;
+ var filetype = this.Utils.getFiletype(filename);
+ var re = new RegExp("\." + filetype + "$", 'i');
+ if(filetype != '') filename = filename.replace(re, "");
+ var key = att.parentItemID + "." + filename;
+ if (set.has(key)) {
+ atts.splice(i, 1);
+ } else {
+ i++;
+ }
+ }
+ }
// confirm
var atts_tablet = yield Zotero.Promise.filter(atts, att =>
this.Tablet.getTabletStatus(att) && this.Tablet.getTabletFilePath(att, false)),
@@ -606,6 +641,7 @@ Zotero.ZotFile.Tablet = new function() {
var item = Zotero.Items.get(att.parentItemID),
tablet_status = 1,
item_pulled = false,
+ annotated_pulled = false,
att_deleted = false,
att_mode = this.Tablet.getInfo(att, 'mode'),
attSubfolder = this.Tablet.getInfo(att, 'projectFolder').trim();
@@ -651,36 +687,61 @@ Zotero.ZotFile.Tablet = new function() {
item_pulled = true;
}
}
- // if saving a copy of the file as a new attachment with suffix and reader file was modified
- if (this.getPref('tablet.storeCopyOfFile') && tablet_status != 2) {
- var filename = this.Utils.addSuffix(OS.Path.basename(path_zotero), this.getPref('tablet.storeCopyOfFile_suffix'));
- //add linked attachment
- if (item.library.libraryType == 'user' && !this.getPref('import')) {
- let path_copied = OS.Path.join(OS.Path.dirname(path_zotero), filename);
- yield OS.File.move(path_tablet, path_copied);
- var options = {file: path_copied, libraryID: item.libraryID, parentItemID: item.id, collections: undefined};
- att_new = yield Zotero.Attachments.linkFromFile(options);
- item_pulled = true;
- // extract annotations from attachment and add note
- if (this.getPref('pdfExtraction.Pull'))
- this.Tablet.extractPdfs.push(att_new.id);
- }
- //imports attachment
- if (item.library.libraryType != 'user' || this.getPref('import')) {
- // import file on reader
- var options = {file: path_tablet, libraryID: item.libraryID, parentItemID: item.id, collections: undefined};
- att_new = yield Zotero.Attachments.importFromFile(options);
- // rename file associated with attachment
- yield att_new.renameAttachmentFile(filename);
- // change title of attachment item
- att_new.setField('title', filename);
- yield att_new.saveTx();
- // remove file on reader
- yield OS.File.remove(path_tablet);
- item_pulled = true;
- // extract annotations from attachment and add note
- if (this.getPref('pdfExtraction.Pull'))
- this.Tablet.extractPdfs.push(att_new.id);
+
+ // add filetype to suffix
+ var suffix = this.getPref('tablet.storeCopyOfFile_suffix');
+ var filetype = this.Utils.getFiletype(path_zotero);
+ if(filetype != '') suffix = suffix + '.' + filetype;
+ if (this.getPref('tablet.storeCopyOfFile') && tablet_status != 2) {
+ // move the file when keepOneAnnotated and storeCopyOfFile are true and the filename is end with storeCopyOfFile_suffix.
+ // otherwise, import the file as new attachment with given suffix.
+ // except for setting annotated_pulled, the behavior is same as previous replacement.
+ if (this.getPref('tablet.keepOneAnnotated') && path_zotero.endsWith(suffix)) {
+ // prompt if both file have been modified
+ if (tablet_status == 1) {
+ tablet_status = this.promptUser(this.ZFgetString('tablet.fileConflict', [att.attachmentFilename]),
+ this.ZFgetString('tablet.fileConflict.replaceZ'),
+ this.ZFgetString('general.cancel'),
+ this.ZFgetString('tablet.fileConflict.removeT'));
+ //att_deleted is true to display a special message when the attachments have been deleted from tablet without being sent back to Zotero
+ if (tablet_status == 2) att_deleted = true;
+ }
+ // replace zotero file
+ if(tablet_status == 0) {
+ yield OS.File.move(path_tablet, path_zotero);
+ item_pulled = true;
+ annotated_pulled = true;
+ }
+ } else {
+ var filename = this.Utils.addSuffix(OS.Path.basename(path_zotero), this.getPref('tablet.storeCopyOfFile_suffix'));
+ //add linked attachment
+ if (item.library.libraryType == 'user' && !this.getPref('import')) {
+ let path_copied = OS.Path.join(OS.Path.dirname(path_zotero), filename);
+ yield OS.File.move(path_tablet, path_copied);
+ var options = {file: path_copied, libraryID: item.libraryID, parentItemID: item.id, collections: undefined};
+ att_new = yield Zotero.Attachments.linkFromFile(options);
+ item_pulled = true;
+ // extract annotations from attachment and add note
+ if (this.getPref('pdfExtraction.Pull'))
+ this.Tablet.extractPdfs.push(att_new.id);
+ }
+ //imports attachment
+ if (item.library.libraryType != 'user' || this.getPref('import')) {
+ // import file on reader
+ var options = {file: path_tablet, libraryID: item.libraryID, parentItemID: item.id, collections: undefined};
+ att_new = yield Zotero.Attachments.importFromFile(options);
+ // rename file associated with attachment
+ yield att_new.renameAttachmentFile(filename);
+ // change title of attachment item
+ att_new.setField('title', filename);
+ yield att_new.saveTx();
+ // remove file on reader
+ yield OS.File.remove(path_tablet);
+ item_pulled = true;
+ // extract annotations from attachment and add note
+ if (this.getPref('pdfExtraction.Pull'))
+ this.Tablet.extractPdfs.push(att_new.id);
+ }
}
}
// Pull without replacement (i.e. remove file on tablet)
@@ -716,7 +777,7 @@ Zotero.ZotFile.Tablet = new function() {
// clear attachment note
this.Tablet.clearInfo(att);
// extract annotations from attachment and add note
- if (this.getPref('pdfExtraction.Pull') && tablet_status != 2 && !this.getPref('tablet.storeCopyOfFile'))
+ if (this.getPref('pdfExtraction.Pull') && tablet_status != 2 && (!this.getPref('tablet.storeCopyOfFile') || annotated_pulled))
this.Tablet.extractPdfs.push(att.id);
// remove tag from parent item
var tag_parent = this.getPref('tablet.tagParentPush_tag');
diff --git a/chrome/content/zotfile/ui.js b/chrome/content/zotfile/ui.js
index 798af941..b86d7af3 100644
--- a/chrome/content/zotfile/ui.js
+++ b/chrome/content/zotfile/ui.js
@@ -67,15 +67,16 @@ Zotero.ZotFile.UI = new function() {
sep1: 4,
warning2: 5,
push2reader: 6,
- updatefile: 7,
- pullreader: 8,
- sep2: 9,
- tablet: 10,
- warning3: 11,
- subfolders: new Array(12,13,14,15,16,17,18,19,20,21,22,23,24,25,26),
- sep3: 27,
- menuConfigure: 28,
- length:29
+ pushannotation2reader: 7,
+ updatefile: 8,
+ pullreader: 9,
+ sep2: 10,
+ tablet: 11,
+ warning3: 12,
+ subfolders: new Array(13,14,15,16,17,18,19,20,21,22,23,24,25,26,27),
+ sep3: 28,
+ menuConfigure: 29,
+ length:30
};
// list of disabled and show menu-items
var disable = [m.tablet, m.warning1, m.warning2, m.warning3], show = [];
@@ -122,9 +123,10 @@ Zotero.ZotFile.UI = new function() {
menu.childNodes[m.warning2].setAttribute('label',this.ZFgetString('menu.itemIsInGroupLibrary'));
}
if(valid_destination && !group_library) {
- show.push(m.push2reader, m.pullreader);
+ show.push(m.push2reader, m.pushannotation2reader, m.pullreader);
// set tooltip for base folder
menu.childNodes[m.push2reader].setAttribute('tooltiptext', this.ZFgetString('menu.sendAttToBaseFolder', [this.getPref('tablet.dest_dir')]));
+ menu.childNodes[m.pushannotation2reader].setAttribute('tooltiptext', this.ZFgetString('menu.sendAnnToBaseFolder', [this.getPref('tablet.dest_dir')]));
if(!menu_tablet) disable.push(m.pullreader);
// add update menu item
if(this.Tablet.checkSelectedSearch() || this.getPref('tablet.updateAlwaysShow')) {
@@ -233,6 +235,15 @@ Zotero.ZotFile.UI = new function() {
},
'disabled': tablet ? 'true' : 'false'
},
+ {
+ 'label': 'Send Annotation to Tablet',
+ 'tooltiptext': '',
+ 'command': function(e) {
+ Zotero.ZotFile.Tablet.sendSelectedAttachmentsToTablet(true);
+ Zotero.ZotFile.UI.buildTabletMenu();
+ },
+ 'disabled': tablet ? 'true' : 'false'
+ },
{
'label': 'Get from Tablet',
'tooltiptext': '',
@@ -271,7 +282,7 @@ Zotero.ZotFile.UI = new function() {
var menuitem = pane.document.createElement('menuitem');
menuitem.setAttribute('label', folder.label);
menuitem.addEventListener('command', function(event) {
- this.Tablet.sendSelectedAttachmentsToTablet(i);
+ this.Tablet.sendSelectedAttachmentsToTablet(false, i);
this.UI.buildTabletMenu();
});
menupopup.appendChild(menuitem);
diff --git a/chrome/locale/de-DE/options.dtd b/chrome/locale/de-DE/options.dtd
index 44f948a3..664e7f90 100644
--- a/chrome/locale/de-DE/options.dtd
+++ b/chrome/locale/de-DE/options.dtd
@@ -34,6 +34,7 @@
+
diff --git a/chrome/locale/de-DE/overlay.dtd b/chrome/locale/de-DE/overlay.dtd
index 6b0f127b..2631ffed 100644
--- a/chrome/locale/de-DE/overlay.dtd
+++ b/chrome/locale/de-DE/overlay.dtd
@@ -10,6 +10,8 @@
+
+
diff --git a/chrome/locale/de-DE/zotfile.properties b/chrome/locale/de-DE/zotfile.properties
index b7344f85..ec8addf5 100644
--- a/chrome/locale/de-DE/zotfile.properties
+++ b/chrome/locale/de-DE/zotfile.properties
@@ -27,6 +27,7 @@ menu.invalidTabletLocation = Speicherort für Dateien auf dem Tablet PC ist n
menu.itemIsInGroupLibrary = Ausgewählte Objekte sind in einer Gruppenbibliothek.
menu.sendAttToBaseFolder = Schicke Datei nach '%S'
menu.sendAttToSubfolder = Schicke Datei nach '...%S'
+menu.sendAnnToBaseFolder = Anmerkungsdatei senden an '%S'
menu.itemIsInNoCollection = Objekt ist in keiner Sammlung.
menu.noSubfoldersDefined = Keine Unterordner definiert.
menu.collection.tooltip = Zeige Objekte in '%S'
diff --git a/chrome/locale/en-US/options.dtd b/chrome/locale/en-US/options.dtd
index 98b56729..aa95e100 100644
--- a/chrome/locale/en-US/options.dtd
+++ b/chrome/locale/en-US/options.dtd
@@ -34,6 +34,7 @@
+
diff --git a/chrome/locale/en-US/overlay.dtd b/chrome/locale/en-US/overlay.dtd
index 370f35c0..958ff590 100644
--- a/chrome/locale/en-US/overlay.dtd
+++ b/chrome/locale/en-US/overlay.dtd
@@ -10,6 +10,8 @@
+
+
diff --git a/chrome/locale/en-US/zotfile.properties b/chrome/locale/en-US/zotfile.properties
index 976d632b..ba390f71 100644
--- a/chrome/locale/en-US/zotfile.properties
+++ b/chrome/locale/en-US/zotfile.properties
@@ -27,6 +27,7 @@ menu.invalidTabletLocation = Location for tablet files is not defined or inva
menu.itemIsInGroupLibrary = Selected item is in group library.
menu.sendAttToBaseFolder = Send Attachment File to '%S'
menu.sendAttToSubfolder = Send Attachment File to '...%S'
+menu.sendAnnToBaseFolder = Send Annotation File to '%S'
menu.itemIsInNoCollection = Item is in no collection.
menu.noSubfoldersDefined = No subfolders defined.
menu.collection.tooltip = Show items in '%S'
diff --git a/chrome/locale/fr-FR/options.dtd b/chrome/locale/fr-FR/options.dtd
index 6093b301..2d0658f3 100644
--- a/chrome/locale/fr-FR/options.dtd
+++ b/chrome/locale/fr-FR/options.dtd
@@ -34,6 +34,8 @@
+
diff --git a/chrome/locale/fr-FR/overlay.dtd b/chrome/locale/fr-FR/overlay.dtd
index b4f1f19e..807a6492 100644
--- a/chrome/locale/fr-FR/overlay.dtd
+++ b/chrome/locale/fr-FR/overlay.dtd
@@ -10,6 +10,8 @@
+
+
diff --git a/chrome/locale/fr-FR/zotfile.properties b/chrome/locale/fr-FR/zotfile.properties
index 04dee109..6780ac53 100644
--- a/chrome/locale/fr-FR/zotfile.properties
+++ b/chrome/locale/fr-FR/zotfile.properties
@@ -27,6 +27,7 @@ menu.invalidTabletLocation = L'emplacement des fichiers de la tablette n'est
menu.itemIsInGroupLibrary = Le document sélectionné est dans une bibliothèque de groupe.
menu.sendAttToBaseFolder = Envoyer la pièce jointe vers '%S'
menu.sendAttToSubfolder = Envoyer la pièce jointe vers '...%S'
+menu.sendAnnToBaseFolder = Envoyer le fichier d'annotation à '%S'
menu.itemIsInNoCollection = Le document n'est dans aucune collection.
menu.noSubfoldersDefined = Aucun sous-dossier n'est défini.
menu.collection.tooltip = Montrer les documents dans '%S'
diff --git a/chrome/locale/it-IT/options.dtd b/chrome/locale/it-IT/options.dtd
index 686591fa..80a9dce1 100644
--- a/chrome/locale/it-IT/options.dtd
+++ b/chrome/locale/it-IT/options.dtd
@@ -34,6 +34,8 @@
+
diff --git a/chrome/locale/it-IT/overlay.dtd b/chrome/locale/it-IT/overlay.dtd
index 1a3c844d..91c34b47 100644
--- a/chrome/locale/it-IT/overlay.dtd
+++ b/chrome/locale/it-IT/overlay.dtd
@@ -10,6 +10,8 @@
+
+
diff --git a/chrome/locale/it-IT/zotfile.properties b/chrome/locale/it-IT/zotfile.properties
index eb52bb59..ed811901 100644
--- a/chrome/locale/it-IT/zotfile.properties
+++ b/chrome/locale/it-IT/zotfile.properties
@@ -27,6 +27,7 @@ menu.invalidTabletLocation = La posizione dei file sul tablet non è definita
menu.itemIsInGroupLibrary = Oggetto selezionato in una libreria di gruppo.
menu.sendAttToBaseFolder = Invia allegato al file a '%S'
menu.sendAttToSubfolder = Invia file a '...%S'
+menu.sendAnnToBaseFolder = Invia file di annotazioni a '%S'
menu.itemIsInNoCollection = Oggetto non nella collezione.
menu.noSubfoldersDefined = Nessuna sottocartella definita.
menu.collection.tooltip = Mostra oggetti in '%S'
diff --git a/defaults/preferences/defaults.js b/defaults/preferences/defaults.js
index d9a7689c..a2c57921 100644
--- a/defaults/preferences/defaults.js
+++ b/defaults/preferences/defaults.js
@@ -44,6 +44,7 @@ pref("extensions.zotfile.wildcards.user",'{}');
pref("extensions.zotfile.tablet", false);
pref("extensions.zotfile.tablet.dest_dir", "");
pref("extensions.zotfile.tablet.rename", true);
+pref("extensions.zotfile.tablet.keepOneAnnotated", false);
pref("extensions.zotfile.tablet.updateAlwaysShow", false);
pref("extensions.zotfile.tablet.updateExtractAnnotations", false);
pref("extensions.zotfile.tablet.dest_dir_relativePath", true);