www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit d871e2540bb6c8efc739f1e670f030a621ed724b
parent 285dac425c4dbff8cec6fb59436ea55d25a711f1
Author: Dan Stillman <dstillman@zotero.org>
Date:   Mon,  7 Mar 2016 01:11:26 -0500

Revert "Make citing work via right-click"

This reverts commit f95832d4a950b4c2dc6de9757256f5022ae05860.

No longer necessary with deasyncification.

Diffstat:
Mchrome/content/zotero/fileInterface.js | 17+++++++++--------
Mchrome/content/zotero/xpcom/cite.js | 99+++++++++++++++++++++++++++++++------------------------------------------------
Mchrome/content/zotero/xpcom/style.js | 7+++----
3 files changed, 51 insertions(+), 72 deletions(-)

diff --git a/chrome/content/zotero/fileInterface.js b/chrome/content/zotero/fileInterface.js @@ -126,6 +126,7 @@ var Zotero_File_Interface = new function() { this.exportItems = exportItems; this.bibliographyFromCollection = bibliographyFromCollection; this.bibliographyFromItems = bibliographyFromItems; + this.copyItemsToClipboard = copyItemsToClipboard; this.copyCitationToClipboard = copyCitationToClipboard; /** @@ -407,7 +408,7 @@ var Zotero_File_Interface = new function() { * * Does not check that items are actual references (and not notes or attachments) */ - this.copyItemsToClipboard = Zotero.Promise.coroutine(function* (items, style, locale, asHTML, asCitations) { + function copyItemsToClipboard(items, style, locale, asHTML, asCitations) { // copy to clipboard var transferable = Components.classes["@mozilla.org/widget/transferable;1"]. createInstance(Components.interfaces.nsITransferable); @@ -417,7 +418,7 @@ var Zotero_File_Interface = new function() { var cslEngine = style.getCiteProc(locale); // add HTML - var bibliography = yield Zotero.Cite.makeFormattedBibliographyOrCitationList(cslEngine, items, "html", asCitations); + var bibliography = Zotero.Cite.makeFormattedBibliographyOrCitationList(cslEngine, items, "html", asCitations); var str = Components.classes["@mozilla.org/supports-string;1"]. createInstance(Components.interfaces.nsISupportsString); str.data = bibliography; @@ -427,7 +428,7 @@ var Zotero_File_Interface = new function() { // add text (or HTML source) if(!asHTML) { cslEngine = style.getCiteProc(locale); - var bibliography = yield Zotero.Cite.makeFormattedBibliographyOrCitationList(cslEngine, items, "text", asCitations); + var bibliography = Zotero.Cite.makeFormattedBibliographyOrCitationList(cslEngine, items, "text", asCitations); } var str = Components.classes["@mozilla.org/supports-string;1"]. createInstance(Components.interfaces.nsISupportsString); @@ -436,7 +437,7 @@ var Zotero_File_Interface = new function() { transferable.setTransferData("text/unicode", str, bibliography.length*2); clipboardService.setData(transferable, null, Components.interfaces.nsIClipboard.kGlobalClipboard); - }); + } /* @@ -483,7 +484,7 @@ var Zotero_File_Interface = new function() { /* * Shows bibliography options and creates a bibliography */ - let _doBibliographyOptions = Zotero.Promise.coroutine(function* (name, items) { + function _doBibliographyOptions(name, items) { // make sure at least one item is not a standalone note or attachment var haveRegularItem = false; for each(var item in items) { @@ -515,12 +516,12 @@ var Zotero_File_Interface = new function() { // generate bibliography try { if(io.method == 'copy-to-clipboard') { - yield Zotero_File_Interface.copyItemsToClipboard(items, io.style, locale, false, io.mode === "citations"); + Zotero_File_Interface.copyItemsToClipboard(items, io.style, locale, false, io.mode === "citations"); } else { var style = Zotero.Styles.get(io.style); var cslEngine = style.getCiteProc(locale); - var bibliography = yield Zotero.Cite.makeFormattedBibliographyOrCitationList(cslEngine, + var bibliography = Zotero.Cite.makeFormattedBibliographyOrCitationList(cslEngine, items, format, io.mode === "citations"); } } catch(e) { @@ -598,7 +599,7 @@ var Zotero_File_Interface = new function() { fStream.close(); } } - }); + } function _saveBibliography(name, format) { diff --git a/chrome/content/zotero/xpcom/cite.js b/chrome/content/zotero/xpcom/cite.js @@ -71,9 +71,9 @@ Zotero.Cite = { * @param {String} format The format of the output (html, text, or rtf) * @return {String} Bibliography or item list in specified format */ - "makeFormattedBibliographyOrCitationList":Zotero.Promise.coroutine(function* (cslEngine, items, format, asCitationList) { + "makeFormattedBibliographyOrCitationList":function(cslEngine, items, format, asCitationList) { cslEngine.setOutputFormat(format); - yield cslEngine.updateItems(items.map(item => item.id)); + cslEngine.updateItems(items.map(item => item.id)); if(!asCitationList) { var bibliography = Zotero.Cite.makeFormattedBibliography(cslEngine, format); @@ -84,7 +84,7 @@ Zotero.Cite = { var citations=[]; for (var i=0, ilen=items.length; i<ilen; i++) { var item = items[i]; - var outList = yield cslEngine.appendCitationCluster({"citationItems":[{"id":item.id}], "properties":{}}, true); + var outList = cslEngine.appendCitationCluster({"citationItems":[{"id":item.id}], "properties":{}}, true); for (var j=0, jlen=outList.length; j<jlen; j++) { var citationPos = outList[j][0]; citations[citationPos] = outList[j][1]; @@ -124,7 +124,7 @@ Zotero.Cite = { return "<\\rtf \n"+citations.join("\\\n")+"\n}"; } } - }), + }, /** * Makes a formatted bibliography @@ -492,54 +492,21 @@ Zotero.Cite.System = function(automaticJournalAbbreviations) { if(automaticJournalAbbreviations) { this.getAbbreviation = Zotero.Cite.getAbbreviation; } - this.items = {}; } Zotero.Cite.System.prototype = { /** - * Asynchronously fetch item and convert to CSL JSON - */ - "addItem":Zotero.Promise.coroutine(function* (zoteroItem) { - if (typeof(zoteroItem) != "object") { - if (this.items.hasOwnProperty(zoteroItem)) return; - zoteroItem = yield Zotero.Items.getAsync(zoteroItem); - } - if (this.items.hasOwnProperty(zoteroItem.id)) return; - let item = yield Zotero.Utilities.itemToCSLJSON(zoteroItem); - item.id = zoteroItem.id; - - if (!Zotero.Prefs.get("export.citePaperJournalArticleURL")) { - var itemType = Zotero.ItemTypes.getName(zoteroItem.itemTypeID); - // don't return URL or accessed information for journal articles if a - // pages field exists - if (["journalArticle", "newspaperArticle", "magazineArticle"].indexOf(itemType) !== -1 - && item.pages - ) { - delete item.URL; - delete item.accessed; - } - } - this.items[item.id] = item; - }), - - /** - * Asynchronously fetch items and convert them to CSL JSON - */ - "addItems":Zotero.Promise.coroutine(function* (items) { - for (let item of items) { - yield this.addItem(item); - } - }), - - /** * citeproc-js system function for getting items * See http://gsl-nagoya-u.net/http/pub/citeproc-doc.html#retrieveitem * @param {String|Integer} Item ID, or string item for embedded citations * @return {Object} citeproc-js item */ "retrieveItem":function retrieveItem(item) { - let slashIndex; - if(typeof item === "string" && (slashIndex = item.indexOf("/")) !== -1) { + var zoteroItem, slashIndex; + if(typeof item === "object" && item !== null && item instanceof Zotero.Item) { + //if(this._cache[item.id]) return this._cache[item.id]; + zoteroItem = item; + } else if(typeof item === "string" && (slashIndex = item.indexOf("/")) !== -1) { // is an embedded item var sessionID = item.substr(0, slashIndex); var session = Zotero.Integration.sessions[sessionID] @@ -550,8 +517,37 @@ Zotero.Cite.System.prototype = { return embeddedCitation; } } + } else { + // is an item ID + //if(this._cache[item]) return this._cache[item]; + try { + zoteroItem = Zotero.Items.get(item); + } catch(e) {} } - return this.items[item]; + + if(!zoteroItem) { + throw "Zotero.Cite.System.retrieveItem called on non-item "+item; + } + + throw new Error("Unimplemented"); + var cslItem = Zotero.Utilities.itemToCSLJSON(zoteroItem); + + // TEMP: citeproc-js currently expects the id property to be the item DB id + cslItem.id = zoteroItem.id; + + if (!Zotero.Prefs.get("export.citePaperJournalArticleURL")) { + var itemType = Zotero.ItemTypes.getName(zoteroItem.itemTypeID); + // don't return URL or accessed information for journal articles if a + // pages field exists + if (["journalArticle", "newspaperArticle", "magazineArticle"].indexOf(itemType) !== -1 + && zoteroItem.getField("pages") + ) { + delete cslItem.URL; + delete cslItem.accessed; + } + } + + return cslItem; }, /** @@ -579,20 +575,3 @@ Zotero.Cite.System.prototype = { return str.value; } }; - -Zotero.Cite.AsyncCiteProc = function() { - Zotero.CiteProc.CSL.Engine.apply(this, arguments); -} -Zotero.Cite.AsyncCiteProc.prototype = Object.create(Zotero.CiteProc.CSL.Engine.prototype); -Zotero.Cite.AsyncCiteProc.prototype.updateItems = Zotero.Promise.coroutine(function*(items) { - yield this.sys.addItems(items); - Zotero.CiteProc.CSL.Engine.prototype.updateItems.call(this, items); -}); -Zotero.Cite.AsyncCiteProc.prototype.appendCitationCluster = Zotero.Promise.coroutine(function*(citation, isRegistered) { - if (!isRegistered) { - for (let citationItem of citation.citationItems) { - yield this.sys.addItem(citationItem.id); - } - } - return Zotero.CiteProc.CSL.Engine.prototype.appendCitationCluster.call(this, citation, isRegistered); -}); diff --git a/chrome/content/zotero/xpcom/style.js b/chrome/content/zotero/xpcom/style.js @@ -437,7 +437,7 @@ Zotero.Styles = new function() { yield Zotero.File.putContentsAsync(destFile, style); yield Zotero.Styles.reinit(); - + // Refresh preferences windows var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]. getService(Components.interfaces.nsIWindowMediator); @@ -691,7 +691,7 @@ Zotero.Style.prototype.getCiteProc = function(locale, automaticJournalAbbreviati } try { - var citeproc = new Zotero.Cite.AsyncCiteProc( + var citeproc = new Zotero.CiteProc.CSL.Engine( new Zotero.Cite.System(automaticJournalAbbreviations), xml, locale, @@ -832,4 +832,4 @@ Zotero.Style.prototype.remove = Zotero.Promise.coroutine(function* () { } return Zotero.Styles.reinit(); -}); -\ No newline at end of file +});