From 303f980954ad9bf24c7adcfbc68e0a1a620faabe Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Sun, 20 Jun 2010 10:48:38 +0000 Subject: [PATCH] Fix for "The command is not available because no document is open" error (part 2) --- chrome/content/zotero/xpcom/integration.js | 11 +++++++---- components/zotero-integration-service.js | 3 ++- idl/zoteroIntegration.idl | 5 +++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/chrome/content/zotero/xpcom/integration.js b/chrome/content/zotero/xpcom/integration.js index aa465d35f3..061540bd6e 100644 --- a/chrome/content/zotero/xpcom/integration.js +++ b/chrome/content/zotero/xpcom/integration.js @@ -156,7 +156,7 @@ Zotero.Integration = new function() { /** * Executes an integration command. */ - this.execCommand = function execCommand(agent, command) { + this.execCommand = function execCommand(agent, command, docId) { if(_inProgress) { Zotero.Integration.activate(); Zotero.debug("Integration: Request already in progress; not executing "+agent+" "+command); @@ -183,7 +183,10 @@ Zotero.Integration = new function() { // Try to create a new document; otherwise display an error using the alert service try { - var integration = new Zotero.Integration.Document(application); + Zotero.debug(application.getDocument); + Zotero.debug(docId); + var document = (application.getDocument && docId ? application.getDocument(docId) : application.getActiveDocument()); + var integration = new Zotero.Integration.Document(application, document); } catch(e) { _inProgress = false; Zotero.Integration.activate(); @@ -330,9 +333,9 @@ const BIBLIOGRAPHY_PLACEHOLDER = "{Bibliography}"; /** * */ -Zotero.Integration.Document = function(app) { +Zotero.Integration.Document = function(app, doc) { this._app = app; - this._doc = app.getActiveDocument(); + this._doc = doc; } /** diff --git a/components/zotero-integration-service.js b/components/zotero-integration-service.js index ae9a42f591..04058da2c6 100644 --- a/components/zotero-integration-service.js +++ b/components/zotero-integration-service.js @@ -35,13 +35,14 @@ const ZoteroIntegrationCommandLineHandler = { handle : function(cmdLine) { var agent = cmdLine.handleFlagWithParam("ZoteroIntegrationAgent", false); var command = cmdLine.handleFlagWithParam("ZoteroIntegrationCommand", false); + var docId = cmdLine.handleFlagWithParam("ZoteroIntegrationDocument", false); if(agent && command) { if(!this.Zotero) this.Zotero = Components.classes["@zotero.org/Zotero;1"] .getService(Components.interfaces.nsISupports).wrappedJSObject; var Zotero = this.Zotero; // Not quite sure why this is necessary to get the appropriate scoping var timer = Components.classes["@mozilla.org/timer;1"].createInstance(Components.interfaces.nsITimer); - timer.initWithCallback({notify:function() { Zotero.Integration.execCommand(agent, command) }}, 0, + timer.initWithCallback({notify:function() { Zotero.Integration.execCommand(agent, command, docId) }}, 0, Components.interfaces.nsITimer.TYPE_ONE_SHOT); } }, diff --git a/idl/zoteroIntegration.idl b/idl/zoteroIntegration.idl index a922fd8949..a00c15d8a2 100755 --- a/idl/zoteroIntegration.idl +++ b/idl/zoteroIntegration.idl @@ -146,6 +146,11 @@ interface zoteroIntegrationApplication : nsISupports * The active document. */ zoteroIntegrationDocument getActiveDocument(); + + /** + * A document by some app-specific identifier. + */ + zoteroIntegrationDocument getDocument(in wstring documentIdentifier); }; ///////////////////////////////////////////////////////////////////////////////