Open reference formats and CSL files on double-click (currently only on OS X)
This commit is contained in:
parent
9261f8d5fb
commit
05f9d2cd6f
2 changed files with 52 additions and 20 deletions
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue