closes #465, Remember bibliography and export preferences

This commit is contained in:
Simon Kornblith 2006-12-22 17:09:46 +00:00
parent da1f4944f5
commit cac436a7ee
4 changed files with 64 additions and 12 deletions

View File

@ -29,7 +29,7 @@
// Class to provide options for bibliography
var Zotero_File_Interface_Bibliography = new function() {
var _io;
var _io, _saveStyle;
this.init = init;
this.acceptSelection = acceptSelection;
@ -48,6 +48,12 @@ var Zotero_File_Interface_Bibliography = new function() {
var styleMenu = document.getElementById("style-menu");
var styles = Zotero.Cite.getStyles();
// if no style is set, get the last style used
if(!_io.style) {
_io.style = Zotero.Prefs.get("export.lastStyle");
_saveStyle = true;
}
// add styles to list
for(i in styles) {
var itemNode = document.createElement("menuitem");
@ -65,11 +71,15 @@ var Zotero_File_Interface_Bibliography = new function() {
styleMenu.selectedIndex = 0;
}
// disable clipboard on the Mac, because it can't support formatted
// output
if(Zotero.isMac && document.getElementById("copy-to-clipboard") &&
!Zotero.Prefs.get("enableMacClipboard")) {
document.getElementById("copy-to-clipboard").hidden = "true";
if(document.getElementById("save-as-rtf")) {
// restore saved bibliographic settings
document.getElementById(Zotero.Prefs.get("export.bibliographySettings")).setAttribute("selected", "true");
// disable clipboard on the Mac, because it can't support formatted
// output
if(Zotero.isMac && !Zotero.Prefs.get("enableMacClipboard")) {
document.getElementById("copy-to-clipboard").hidden = "true";
}
}
// move to center of screen
@ -84,7 +94,16 @@ var Zotero_File_Interface_Bibliography = new function() {
// collect code
_io.style = document.getElementById("style-menu").selectedItem.value;
if(document.getElementById("output-radio")) {
// collect settings
_io.output = document.getElementById("output-radio").selectedItem.id;
// save settings
Zotero.Prefs.set("export.bibliographySettings", _io.output);
}
// save style (this happens only for "Export Bibliography," or Word
// integration when no bibliography style was previously selected)
if(_saveStyle) {
Zotero.Prefs.set("export.lastStyle", _io.style);
}
}
}

View File

@ -20,7 +20,7 @@
<groupbox>
<caption label="&zotero.bibliography.output.label;"/>
<radiogroup id="output-radio">
<radio id="save-as-rtf" selected="true" label="&zotero.bibliography.saveAsRTF.label;"/>
<radio id="save-as-rtf" label="&zotero.bibliography.saveAsRTF.label;"/>
<radio id="save-as-html" label="&zotero.bibliography.saveAsHTML.label;"/>
<radio id="copy-to-clipboard" label="&zotero.bibliography.copyToClipboard.label;"/>
<radio id="print" label="&zotero.bibliography.print.label;"/>

View File

@ -46,6 +46,8 @@ var Zotero_File_Interface_Export = new function() {
var formatMenu = document.getElementById("format-menu");
var optionsBox = document.getElementById("translator-options");
var selectedTranslator = Zotero.Prefs.get("export.lastTranslator");
// add styles to list
for(i in translators) {
var itemNode = document.createElement("menuitem");
@ -75,6 +77,11 @@ var Zotero_File_Interface_Export = new function() {
addedOptions[option] = true;
}
}
// select last selected translator
if(translators[i].translatorID == selectedTranslator) {
formatMenu.selectedIndex = i;
}
}
// select first item by default
@ -82,17 +89,21 @@ var Zotero_File_Interface_Export = new function() {
formatMenu.selectedIndex = 0;
}
updateOptions();
updateOptions(Zotero.Prefs.get("export.translatorSettings"));
}
/*
* update translator-specific options
*/
function updateOptions() {
function updateOptions(optionString) {
// get selected translator
var index = document.getElementById("format-menu").selectedIndex;
var translatorOptions = window.arguments[0].translators[index].displayOptions;
if(optionString) {
var options = optionString.split(",");
}
var optionsBox = document.getElementById("translator-options");
for(var i=0; i<optionsBox.childNodes.length; i++) {
// loop through options to see which should be enabled
@ -105,8 +116,14 @@ var Zotero_File_Interface_Export = new function() {
var defValue = translatorOptions[optionName];
if(typeof(defValue) == "boolean") {
// if option exists, enable it and set to default value
node.setAttribute("checked", (defValue ? "true" : "false"));
if(optionString) {
// if there's a saved prefs string, use it
var isChecked = options.shift();
} else {
// use defaults
var isChecked = (defValue ? "true" : "false");
}
node.setAttribute("checked", isChecked);
}
} else {
// option should be disabled and unchecked to prevent confusion
@ -124,7 +141,11 @@ var Zotero_File_Interface_Export = new function() {
var index = document.getElementById("format-menu").selectedIndex;
window.arguments[0].selectedTranslator = window.arguments[0].translators[index];
// set options on selected translator
// save selected translator
Zotero.Prefs.set("export.lastTranslator", window.arguments[0].translators[index].translatorID);
// set options on selected translator and generate optionString
var optionString = "";
var optionsAvailable = window.arguments[0].selectedTranslator.displayOptions;
for(var option in optionsAvailable) {
var defValue = optionsAvailable[option];
@ -132,12 +153,18 @@ var Zotero_File_Interface_Export = new function() {
if(typeof(defValue) == "boolean") {
if(element.checked == true) {
optionString += ",true";
optionsAvailable[option] = true;
} else {
optionString += ",false";
optionsAvailable[option] = false;
}
}
}
// save options
if(optionString) optionString = optionString.substr(1);
Zotero.Prefs.set("export.translatorSettings", optionString);
}
/*

View File

@ -24,3 +24,9 @@ pref("extensions.zotero.keys.quicksearch", 'K');
pref("extensions.zotero.keys.newItem", 'N');
pref("extensions.zotero.keys.newNote", 'O');
pref("extensions.zotero.keys.toggleTagSelector", 'T');
// Export and citation settings
pref("extensions.zotero.export.lastTranslator", '14763d24-8ba0-45df-8f52-b8d1108e7ac9');
pref("extensions.zotero.export.translatorSettings", 'true,false');
pref("extensions.zotero.export.lastStyle", 'http://purl.org/net/xbiblio/csl/styles/apa.csl');
pref("extensions.zotero.export.bibliographySettings", 'save-as-rtf');