From 05f9d2cd6f8d6bce74bb21ac21082effec21f151 Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Wed, 17 Aug 2011 04:51:43 +0000 Subject: [PATCH] Open reference formats and CSL files on double-click (currently only on OS X) --- chrome/content/zotero/fileInterface.js | 44 +++++++++++++++----------- components/zotero-service.js | 28 +++++++++++++++- 2 files changed, 52 insertions(+), 20 deletions(-) diff --git a/chrome/content/zotero/fileInterface.js b/chrome/content/zotero/fileInterface.js index d92d15c1fa..3630bb0df1 100644 --- a/chrome/content/zotero/fileInterface.js +++ b/chrome/content/zotero/fileInterface.js @@ -192,30 +192,36 @@ var Zotero_File_Interface = new function() { } } - /* + /** * Creates Zotero.Translate instance and shows file picker for file import */ - function importFile() { + function importFile(file) { var translation = new Zotero.Translate.Import(); - var translators = translation.getTranslators(); - - const nsIFilePicker = Components.interfaces.nsIFilePicker; - var fp = Components.classes["@mozilla.org/filepicker;1"] - .createInstance(nsIFilePicker); - fp.init(window, Zotero.getString("fileInterface.import"), nsIFilePicker.modeOpen); - - fp.appendFilters(nsIFilePicker.filterAll); - for(var i in translators) { - fp.appendFilter(translators[i].label, "*."+translators[i].target); + if(!file) { + var translators = translation.getTranslators(); + + const nsIFilePicker = Components.interfaces.nsIFilePicker; + var fp = Components.classes["@mozilla.org/filepicker;1"] + .createInstance(nsIFilePicker); + fp.init(window, Zotero.getString("fileInterface.import"), nsIFilePicker.modeOpen); + + fp.appendFilters(nsIFilePicker.filterAll); + for(var i in translators) { + fp.appendFilter(translators[i].label, "*."+translators[i].target); + } + + var rv = fp.show(); + if (rv !== nsIFilePicker.returnOK && rv !== nsIFilePicker.returnReplace) { + return false; + } + + file = fp.file; } - var rv = fp.show(); - if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) { - translation.setLocation(fp.file); - // get translators again, bc now we can check against the file - translation.setHandler("translators", function(obj, item) { _importTranslatorsAvailable(obj, item) }); - translators = translation.getTranslators(); - } + translation.setLocation(file); + // get translators again, bc now we can check against the file + translation.setHandler("translators", function(obj, item) { _importTranslatorsAvailable(obj, item) }); + translators = translation.getTranslators(); } diff --git a/components/zotero-service.js b/components/zotero-service.js index 1f8631ca6e..22a2f6e3a9 100644 --- a/components/zotero-service.js +++ b/components/zotero-service.js @@ -353,6 +353,9 @@ ZoteroCommandLineHandler.prototype = { if(isStandalone()) { var param = cmdLine.handleFlagWithParam("url", false); if(param) { + // don't open a new window + cmdLine.preventDefault = true; + var uri = cmdLine.resolveURI(param); if(uri.schemeIs("zotero")) { // Check for existing window and focus it @@ -360,11 +363,34 @@ ZoteroCommandLineHandler.prototype = { .getService(Components.interfaces.nsIWindowMediator); var win = wm.getMostRecentWindow("navigator:browser"); if(win) { - cmdLine.preventDefault = true; win.focus(); Components.classes["@mozilla.org/network/protocol;1?name=zotero"] .createInstance(Components.interfaces.nsIProtocolHandler).newChannel(uri); } + } else { + Zotero.debug("Not handling URL: "+uri.spec); + } + } + + var param = cmdLine.handleFlagWithParam("file", false); + if(param) { + // don't open a new window + cmdLine.preventDefault = true; + + var file = Components.classes["@mozilla.org/file/local;1"]. + createInstance(Components.interfaces.nsILocalFile); + file.initWithPath(param); + + if(file.leafName.substr(-4).toLowerCase() === ".csl" + || file.leafName.substr(-8).toLowerCase() === ".csl.txt") { + // Install CSL file + this.Zotero.Styles.install(file); + } else { + // Show file import dialog + var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] + .getService(Components.interfaces.nsIWindowMediator); + var browserWindow = wm.getMostRecentWindow("navigator:browser"); + browserWindow.Zotero_File_Interface.importFile(file); } } }