Open reference formats and CSL files on double-click (currently only on OS X)
This commit is contained in:
parent
9261f8d5fb
commit
05f9d2cd6f
|
@ -192,30 +192,36 @@ var Zotero_File_Interface = new function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Creates Zotero.Translate instance and shows file picker for file import
|
* Creates Zotero.Translate instance and shows file picker for file import
|
||||||
*/
|
*/
|
||||||
function importFile() {
|
function importFile(file) {
|
||||||
var translation = new Zotero.Translate.Import();
|
var translation = new Zotero.Translate.Import();
|
||||||
var translators = translation.getTranslators();
|
if(!file) {
|
||||||
|
var translators = translation.getTranslators();
|
||||||
const nsIFilePicker = Components.interfaces.nsIFilePicker;
|
|
||||||
var fp = Components.classes["@mozilla.org/filepicker;1"]
|
const nsIFilePicker = Components.interfaces.nsIFilePicker;
|
||||||
.createInstance(nsIFilePicker);
|
var fp = Components.classes["@mozilla.org/filepicker;1"]
|
||||||
fp.init(window, Zotero.getString("fileInterface.import"), nsIFilePicker.modeOpen);
|
.createInstance(nsIFilePicker);
|
||||||
|
fp.init(window, Zotero.getString("fileInterface.import"), nsIFilePicker.modeOpen);
|
||||||
fp.appendFilters(nsIFilePicker.filterAll);
|
|
||||||
for(var i in translators) {
|
fp.appendFilters(nsIFilePicker.filterAll);
|
||||||
fp.appendFilter(translators[i].label, "*."+translators[i].target);
|
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();
|
translation.setLocation(file);
|
||||||
if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) {
|
// get translators again, bc now we can check against the file
|
||||||
translation.setLocation(fp.file);
|
translation.setHandler("translators", function(obj, item) { _importTranslatorsAvailable(obj, item) });
|
||||||
// get translators again, bc now we can check against the file
|
translators = translation.getTranslators();
|
||||||
translation.setHandler("translators", function(obj, item) { _importTranslatorsAvailable(obj, item) });
|
|
||||||
translators = translation.getTranslators();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -353,6 +353,9 @@ ZoteroCommandLineHandler.prototype = {
|
||||||
if(isStandalone()) {
|
if(isStandalone()) {
|
||||||
var param = cmdLine.handleFlagWithParam("url", false);
|
var param = cmdLine.handleFlagWithParam("url", false);
|
||||||
if(param) {
|
if(param) {
|
||||||
|
// don't open a new window
|
||||||
|
cmdLine.preventDefault = true;
|
||||||
|
|
||||||
var uri = cmdLine.resolveURI(param);
|
var uri = cmdLine.resolveURI(param);
|
||||||
if(uri.schemeIs("zotero")) {
|
if(uri.schemeIs("zotero")) {
|
||||||
// Check for existing window and focus it
|
// Check for existing window and focus it
|
||||||
|
@ -360,11 +363,34 @@ ZoteroCommandLineHandler.prototype = {
|
||||||
.getService(Components.interfaces.nsIWindowMediator);
|
.getService(Components.interfaces.nsIWindowMediator);
|
||||||
var win = wm.getMostRecentWindow("navigator:browser");
|
var win = wm.getMostRecentWindow("navigator:browser");
|
||||||
if(win) {
|
if(win) {
|
||||||
cmdLine.preventDefault = true;
|
|
||||||
win.focus();
|
win.focus();
|
||||||
Components.classes["@mozilla.org/network/protocol;1?name=zotero"]
|
Components.classes["@mozilla.org/network/protocol;1?name=zotero"]
|
||||||
.createInstance(Components.interfaces.nsIProtocolHandler).newChannel(uri);
|
.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…
Reference in New Issue
Block a user