Fix for "The command is not available because no document is open" error (part 2)

This commit is contained in:
Simon Kornblith 2010-06-20 10:48:38 +00:00
parent 3d70456938
commit 303f980954
3 changed files with 14 additions and 5 deletions

View file

@ -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;
}
/**

View file

@ -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);
}
},

View file

@ -146,6 +146,11 @@ interface zoteroIntegrationApplication : nsISupports
* The active document.
*/
zoteroIntegrationDocument getActiveDocument();
/**
* A document by some app-specific identifier.
*/
zoteroIntegrationDocument getDocument(in wstring documentIdentifier);
};
///////////////////////////////////////////////////////////////////////////////