diff --git a/chrome/content/zotero/selectItemsDialog.js b/chrome/content/zotero/selectItemsDialog.js index d7512cb35..4b66ad4cf 100644 --- a/chrome/content/zotero/selectItemsDialog.js +++ b/chrome/content/zotero/selectItemsDialog.js @@ -36,6 +36,9 @@ function doLoad() Zotero.setFontSize(sbc); io = window.arguments[0]; + if(io.wrappedJSObject) io = io.wrappedJSObject; + if(io.addBorder) document.getElementsByTagName("dialog")[0].style.border = "1px solid black"; + if(io.singleSelection) document.getElementById("zotero-items-tree").setAttribute("seltype", "single"); collectionsView = new Zotero.CollectionTreeView(); document.getElementById('zotero-collections-tree').view = collectionsView; diff --git a/chrome/content/zotero/xpcom/integration.js b/chrome/content/zotero/xpcom/integration.js index eafdd8791..bc2f8ee4a 100644 --- a/chrome/content/zotero/xpcom/integration.js +++ b/chrome/content/zotero/xpcom/integration.js @@ -20,7 +20,7 @@ ***** END LICENSE BLOCK ***** */ -const API_VERSION = 1; +const API_VERSION = 2; const COMPAT_API_VERSION = 5; Zotero.Integration = new function() { @@ -415,6 +415,12 @@ Zotero.Integration.Request = function(xml) { if(this.needPrefs) { this.setDocPrefs(); } + if(this.body.reselectItem.length()) { + this.reselectItem(); + } else { + // if no more reselections, clear the reselectItem map + this._session.reselectItem = new Object(); + } if(this.body.updateCitations.length() || this.body.updateBibliography.length()) { this.processCitations(); } @@ -431,8 +437,7 @@ Zotero.Integration.Request = function(xml) { try { var text = Zotero.getString("integration.error."+e, Zotero.version); code = e; - } catch(e) { - } + } catch(e) {} this.responseXML = @@ -494,7 +499,7 @@ Zotero.Integration.Request.prototype.setDocPrefs = function() { var io = new function() { this.wrappedJSObject = this; - } + }; io.openOffice = this.header.client.@agent == "OpenOffice.org" @@ -502,7 +507,7 @@ Zotero.Integration.Request.prototype.setDocPrefs = function() { io.useEndnotes = this._session.prefs.useEndnotes; io.useBookmarks = this._session.prefs.fieldType; - this.watcher = Components.classes["@mozilla.org/embedcomp/window-watcher;1"] + Components.classes["@mozilla.org/embedcomp/window-watcher;1"] .getService(Components.interfaces.nsIWindowWatcher) .openWindow(null, 'chrome://zotero/content/integrationDocPrefs.xul', '', 'chrome,modal,centerscreen' + (Zotero.isWin ? ',popup' : ''), io, true); @@ -528,6 +533,28 @@ Zotero.Integration.Request.prototype.setDocPrefs = function() { this.responseBody.appendChild(); } +/** + * Reselects an item to replace a deleted item + **/ +Zotero.Integration.Request.prototype.reselectItem = function() { + default xml namespace = Zotero.Integration.ns; with({}); + + var io = new function() { + this.wrappedJSObject = this; + }; + io.addBorder = Zotero.isWin; + io.singleSelection = true; + + Components.classes["@mozilla.org/embedcomp/window-watcher;1"] + .getService(Components.interfaces.nsIWindowWatcher) + .openWindow(null,'chrome://zotero/content/selectItemsDialog.xul', '', + 'chrome,modal,centerscreen,resizable=yes' + (Zotero.isWin ? ',popup' : ''), io, true); + + if(io.dataOut && io.dataOut.length) { + this._session.reselectItem[this.body.reselectItem.@id] = io.dataOut[0]; + } +} + /** * Updates citations **/ @@ -552,44 +579,48 @@ Zotero.Integration.Request.prototype.processCitations = function() { } } - // load bibliography data here - if(this.header.bibliography.length()) { - this._session.loadBibliographyData(Zotero.Utilities.prototype.trim(this.header.bibliography.toString())); - } - - this._session.updateItemSet(); - - // create new citation - if(editCitationIndex) { - this._session.updateCitations(editCitationIndex-1); - var added = this._session.editCitation(editCitationIndex, editCitation); - if(!added) { - if(editCitation) { - this._session.addCitation(editCitationIndex, editCitation); - } else { - this._session.deleteCitation(editCitationIndex); - } + if(!this._session.haveMissing) { + // load bibliography data here + if(this.header.bibliography.length()) { + this._session.loadBibliographyData(Zotero.Utilities.prototype.trim(this.header.bibliography.toString())); } + this._session.updateItemSet(); } - this._session.updateCitations(); - // edit bibliography - if(this.body.updateBibliography.@edit.toString()) { - this._session.editBibliography(); - } - - // update - var output = new Array(); - if(this.body.updateBibliography.length() // if we want updated bib - && (this._session.bibliographyHasChanged // and bibliography changed - || this.body.updateBibliography.@force.toString())) { // or if we should generate regardless of changes - if(this._session.bibliographyDataHasChanged) { - this.responseBody.updateBibliographyResponse.code = this._session.getBibliographyData(); + if(!this._session.haveMissing) { + // create new citation + if(editCitationIndex) { + this._session.updateCitations(editCitationIndex-1); + var added = this._session.editCitation(editCitationIndex, editCitation); + if(!added) { + if(editCitation) { + this._session.addCitation(editCitationIndex, editCitation); + } else { + this._session.deleteCitation(editCitationIndex); + } + } + this._session.updateItemSet(); + } + this._session.updateCitations(); + + // edit bibliography + if(this.body.updateBibliography.@edit.toString()) { + this._session.editBibliography(); + } + + // update + var output = new Array(); + if(this.body.updateBibliography.length() // if we want updated bib + && (this._session.bibliographyHasChanged // and bibliography changed + || this.body.updateBibliography.@force.toString())) { // or if we should generate regardless of changes + if(this._session.bibliographyDataHasChanged) { + this.responseBody.updateBibliographyResponse.code = this._session.getBibliographyData(); + } + this.responseBody.updateBibliographyResponse.text = this._session.getBibliography(true); } - this.responseBody.updateBibliographyResponse.text = this._session.getBibliography(true); } - + // get citations if(this.body.updateCitations.length()) { this.responseBody.updateCitationsResponse.citations = this._session.getCitations(!!this.body.updateCitations.@force.toString() || this._session.regenerateAll, true); @@ -797,6 +828,7 @@ Zotero.Integration.Session = function() { // holds items not in document that should be in bibliography this.uncitedItems = new Object(); this.prefs = new Object(); + this.reselectItem = new Object(); this.resetRequest(); } @@ -832,11 +864,12 @@ Zotero.Integration.Session.prototype.resetRequest = function() { this.citationsByItemID = new Object(); this.citationsByIndex = new Array(); + this.haveMissing = false; this.regenerateAll = false; this.bibliographyHasChanged = false; this.bibliographyDataHasChanged = false; this.updateItemIDs = new Object(); - this.updateIndices = new Object() + this.updateIndices = new Object(); } /* @@ -900,28 +933,28 @@ Zotero.Integration.Session.prototype.addCitation = function(index, arg) { } var completed = this.completeCitation(citation); - if(!completed) { - // doesn't exist - this.deleteCitation(index); - return; - } // add to citationsByItemID and citationsByIndex - for(var i=0; i 1) { + // use n tags if there are multiple items in the citation + for(var j=0; j; + } + } else { + citationXML.missing = ; + } + } else { + citationXML["@delete"] = "1"; + } + output.appendChild(citationXML); } else { output.push("!"); output.push("!"); } - } else { + } else if(!useXML || !this.haveMissing) { var field = this.getCitationField(citation); if(useXML) { @@ -1365,9 +1441,9 @@ Zotero.Integration.Session.prototype.getCitations = function(regenerateAll, useX } else { output.push(citationText == "" ? " " : citationText); } + + if(useXML) output.appendChild(citationXML); } - - if(useXML) output.appendChild(citationXML); } return output; @@ -1533,7 +1609,7 @@ Zotero.Integration.Session.BibliographyEditInterface.prototype.remove = function for(var j=0; j