From db8d3fd4b4bb55202ffd715c7562b1b80844bc04 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 30 Sep 2016 02:42:17 -0400 Subject: [PATCH 1/2] Fix dragging of files to the filesystem on macOS (and maybe Linux) Calling getTransferData('zotero/item') when handling the application/x-moz-file-promise seems to have stopped working between Fx46 and Fx47, though I can't get older Nightly builds to run with mozregression (Sierra?) to find the specific change. Instead, work around this by passing an array of item ids to the file drag data provider. --- chrome/content/zotero/xpcom/itemTreeView.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/chrome/content/zotero/xpcom/itemTreeView.js b/chrome/content/zotero/xpcom/itemTreeView.js index 5952df6f7..2eccf6b54 100644 --- a/chrome/content/zotero/xpcom/itemTreeView.js +++ b/chrome/content/zotero/xpcom/itemTreeView.js @@ -2612,7 +2612,7 @@ Zotero.ItemTreeView.prototype.onDragStart = function (event) { Zotero.debug("Adding file via x-moz-file-promise"); event.dataTransfer.mozSetDataAt( "application/x-moz-file-promise", - new Zotero.ItemTreeView.fileDragDataProvider(), + new Zotero.ItemTreeView.fileDragDataProvider(itemIDs), 0 ); break; @@ -2688,7 +2688,9 @@ Zotero.ItemTreeView.prototype.onDragStart = function (event) { // Implements nsIFlavorDataProvider for dragging attachment files to OS // // Not used on Windows in Firefox 3 or higher -Zotero.ItemTreeView.fileDragDataProvider = function() { }; +Zotero.ItemTreeView.fileDragDataProvider = function (itemIDs) { + this._itemIDs = itemIDs; +}; Zotero.ItemTreeView.fileDragDataProvider.prototype = { QueryInterface : function(iid) { @@ -2712,13 +2714,7 @@ Zotero.ItemTreeView.fileDragDataProvider.prototype = { transferable.getTransferData("application/x-moz-file-promise-dir", dirPrimitive, dataSize); var destDir = dirPrimitive.value.QueryInterface(Components.interfaces.nsILocalFile); - // Get the items we're dragging - var items = {}; - transferable.getTransferData("zotero/item", items, dataSize); - items.value.QueryInterface(Components.interfaces.nsISupportsString); - - var draggedItems = Zotero.Items.get(items.value.data.split(',')); - + var draggedItems = Zotero.Items.get(this._itemIDs); var items = []; // Make sure files exist From ddcec3d2945af55af59c65f4c6cab9860dfb4424 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Wed, 28 Sep 2016 11:45:18 -0400 Subject: [PATCH 2/2] Remove test for Extra field parsing after 30f7ef093 --- test/tests/utilities.js | 41 ----------------------------------------- 1 file changed, 41 deletions(-) diff --git a/test/tests/utilities.js b/test/tests/utilities.js index 79e7f2e0d..5f9c54901 100644 --- a/test/tests/utilities.js +++ b/test/tests/utilities.js @@ -235,47 +235,6 @@ describe("Zotero.Utilities", function() { assert.throws(Zotero.Utilities.itemToCSLJSON.bind(Zotero.Utilities, exportFormat), /^Unexpected Zotero Item type ".*"$/, 'throws an error when trying to map invalid item types'); }); - it("should map additional fields from Extra field", function() { - let item = new Zotero.Item('journalArticle'); - item.setField('extra', 'PMID: 12345\nPMCID:123456\nDOI:10.5064/F6PN93H4'); - item = Zotero.Items.get(item.save()); - - let cslJSON = Zotero.Utilities.itemToCSLJSON(item); - - assert.equal(cslJSON.PMID, '12345', 'PMID from Extra is mapped to PMID'); - assert.equal(cslJSON.PMCID, '123456', 'PMCID from Extra is mapped to PMCID'); - assert.equal(cslJSON.DOI, '10.5064/F6PN93H4', 'DOI from Extra field is mapped to DOI'); - - item.setField('extra', 'PMID: 12345'); - item.save(); - cslJSON = Zotero.Utilities.itemToCSLJSON(item); - - assert.equal(cslJSON.PMID, '12345', 'single-line entry is extracted correctly'); - - item.setField('extra', 'some junk: note\nPMID: 12345\nstuff in-between\nPMCID: 123456\nDOI: 10.5064/F6PN93H4\nlast bit of junk!'); - item.save(); - cslJSON = Zotero.Utilities.itemToCSLJSON(item); - - assert.equal(cslJSON.PMID, '12345', 'PMID from mixed Extra field is mapped to PMID'); - assert.equal(cslJSON.PMCID, '123456', 'PMCID from mixed Extra field is mapped to PMCID'); - assert.equal(cslJSON.DOI, '10.5064/F6PN93H4', 'DOI from mixed Extra field is mapped to DOI'); - - item.setField('extra', 'a\n PMID: 12345\nfoo PMCID: 123456\n10.5064/F6PN93H4'); - item.save(); - cslJSON = Zotero.Utilities.itemToCSLJSON(item); - - assert.isUndefined(cslJSON.PMCID, 'field label must not be preceded by other text'); - assert.isUndefined(cslJSON.PMID, 'field label must not be preceded by a space'); - assert.isUndefined(cslJSON.DOI, 'DOI must be preceded by label'); - assert.equal(cslJSON.note, 'a\n PMID: 12345\nfoo PMCID: 123456\n10.5064/F6PN93H4', 'note is left untouched if nothing is extracted'); - - - item.setField('extra', 'something\npmid: 12345\n'); - item.save(); - cslJSON = Zotero.Utilities.itemToCSLJSON(item); - - assert.isUndefined(cslJSON.PMID, 'field labels are case-sensitive'); - }); it("should parse particles in creator names", function() { let creators = [ {