Implement locale drop-down menus

This commit is contained in:
rmzelle 2015-02-02 21:23:59 -05:00
parent 28301ea45f
commit 06e6168cb4
23 changed files with 461 additions and 149 deletions

View file

@ -34,16 +34,14 @@
var Zotero_File_Interface_Bibliography = new function() {
var _io, _saveStyle;
this.init = init;
this.styleChanged = styleChanged;
this.acceptSelection = acceptSelection;
var selectedLocale = "";
var defaultStyleLocale = "";
/*
* Initialize some variables and prepare event listeners for when chrome is done
* loading
*/
function init() {
this.init = function () {
// Set font size from pref
// Affects bibliography.xul and integrationDocPrefs.xul
var bibContainer = document.getElementById("zotero-bibliography-container");
@ -87,10 +85,18 @@ var Zotero_File_Interface_Bibliography = new function() {
selectIndex = 0;
}
// add locales to list
if(!_io.locale) {
_io.locale = Zotero.Prefs.get("export.lastLocale");
}
var menulist = document.getElementById("locale-menu");
selectedLocale = Zotero.Styles.populateLocaleList(menulist, _io.locale);
// Has to be async to work properly
window.setTimeout(function () {
listbox.ensureIndexIsVisible(selectIndex);
listbox.selectedIndex = selectIndex;
Zotero_File_Interface_Bibliography.styleChanged();
}, 0);
// ONLY FOR bibliography.xul: export options
@ -149,22 +155,24 @@ var Zotero_File_Interface_Bibliography = new function() {
// set style to false, in case this is cancelled
_io.style = false;
}
};
/*
* Called when locale is changed
*/
this.localeChanged = function (selectedValue) {
selectedLocale = selectedValue;
};
/*
* Called when style is changed
*/
function styleChanged(index) {
// When called from init(), selectedItem isn't yet set
if (index != undefined) {
var selectedItem = document.getElementById("style-listbox").getItemAtIndex(index);
}
else {
var selectedItem = document.getElementById("style-listbox").selectedItem;
}
this.styleChanged = function () {
var selectedItem = document.getElementById("style-listbox").selectedItem;
var selectedStyle = selectedItem.getAttribute('value');
var selectedStyleObj = Zotero.Styles.get(selectedStyle);
var selectedStyle = selectedItem.getAttribute('value'),
selectedStyleObj = Zotero.Styles.get(selectedStyle);
updateLocaleMenu(selectedStyleObj);
//
// For integrationDocPrefs.xul
@ -195,20 +203,55 @@ var Zotero_File_Interface_Bibliography = new function() {
// Change label to "Citation" or "Note" depending on style class
if(document.getElementById("citations")) {
let label = "";
if(Zotero.Styles.get(selectedStyle).class == "note") {
var label = Zotero.getString('citation.notes');
label = Zotero.getString('citation.notes');
} else {
var label = Zotero.getString('citation.citations');
label = Zotero.getString('citation.citations');
}
document.getElementById("citations").label = label;
}
window.sizeToContent();
};
/*
* Update locale menulist when style is changed
*/
function updateLocaleMenu(selectedStyle) {
// For styles with a default-locale, disable locale menulist and show locale
var menulist = document.getElementById("locale-menu");
// If not null, then menulist is extended with the default-locale value
// of the previously selected style
if (defaultStyleLocale) {
// Reset menulist
menulist.removeItemAt(0);
defaultStyleLocale = "";
}
if (selectedStyle.locale) {
defaultStyleLocale = selectedStyle.locale;
//add default-locale to menulist
let localeLabel = defaultStyleLocale;
if (Zotero.Styles.locales[defaultStyleLocale] !== undefined) {
localeLabel = Zotero.Styles.locales[defaultStyleLocale];
}
menulist.insertItemAt(0, localeLabel, defaultStyleLocale);
menulist.selectedIndex = 0;
menulist.disabled = true;
} else {
menulist.value = selectedLocale;
menulist.disabled = false;
}
}
function acceptSelection() {
this.acceptSelection = function () {
// collect code
_io.style = document.getElementById("style-listbox").selectedItem.value;
_io.locale = document.getElementById("locale-menu").selectedItem.value;
if(document.getElementById("output-method-radio")) {
// collect settings
_io.mode = document.getElementById("output-mode-radio").selectedItem.id;
@ -235,5 +278,8 @@ var Zotero_File_Interface_Bibliography = new function() {
if(_saveStyle) {
Zotero.Prefs.set("export.lastStyle", _io.style);
}
}
}
// save locale
Zotero.Prefs.set("export.lastLocale", selectedLocale);
};
}

View file

@ -16,6 +16,12 @@
<caption label="&zotero.bibliography.style.label;"/>
<listbox id="style-listbox" onselect="Zotero_File_Interface_Bibliography.styleChanged()"/>
</groupbox>
<groupbox>
<hbox align="center">
<caption label="&zotero.bibliography.locale.label;"/>
<menulist id="locale-menu" oncommand="Zotero_File_Interface_Bibliography.localeChanged(this.selectedItem.value)"/>
</hbox>
</groupbox>
<groupbox>
<caption label="&zotero.bibliography.outputMode;"/>
<radiogroup id="output-mode-radio">
@ -33,4 +39,4 @@
</radiogroup>
</groupbox>
</vbox>
</dialog>
</dialog>

View file

@ -420,15 +420,15 @@ var Zotero_File_Interface = new function() {
*
* Does not check that items are actual references (and not notes or attachments)
*/
function copyItemsToClipboard(items, style, asHTML, asCitations) {
function copyItemsToClipboard(items, style, locale, asHTML, asCitations) {
// copy to clipboard
var transferable = Components.classes["@mozilla.org/widget/transferable;1"].
createInstance(Components.interfaces.nsITransferable);
var clipboardService = Components.classes["@mozilla.org/widget/clipboard;1"].
getService(Components.interfaces.nsIClipboard);
var style = Zotero.Styles.get(style);
var cslEngine = style.getCiteProc();
var cslEngine = style.getCiteProc(locale);
// add HTML
var bibliography = Zotero.Cite.makeFormattedBibliographyOrCitationList(cslEngine, items, "html", asCitations);
var str = Components.classes["@mozilla.org/supports-string;1"].
@ -458,14 +458,14 @@ var Zotero_File_Interface = new function() {
*
* if |asHTML| is true, copy HTML source as text
*/
function copyCitationToClipboard(items, style, asHTML) {
function copyCitationToClipboard(items, style, locale, asHTML) {
// copy to clipboard
var transferable = Components.classes["@mozilla.org/widget/transferable;1"].
createInstance(Components.interfaces.nsITransferable);
var clipboardService = Components.classes["@mozilla.org/widget/clipboard;1"].
getService(Components.interfaces.nsIClipboard);
var style = Zotero.Styles.get(style).getCiteProc();
var style = Zotero.Styles.get(style).getCiteProc(locale);
var citation = {"citationItems":[{id:item.id} for each(item in items)], properties:{}};
// add HTML
@ -518,14 +518,17 @@ var Zotero_File_Interface = new function() {
format = "rtf";
}
// determine locale preference
var locale = io.locale;
// generate bibliography
try {
if(io.method == 'copy-to-clipboard') {
copyItemsToClipboard(items, io.style, false, io.mode === "citations");
copyItemsToClipboard(items, io.style, locale, false, io.mode === "citations");
}
else {
var style = Zotero.Styles.get(io.style);
var cslEngine = style.getCiteProc();
var cslEngine = style.getCiteProc(locale);
var bibliography = Zotero.Cite.makeFormattedBibliographyOrCitationList(cslEngine,
items, format, io.mode === "citations");
}

View file

@ -48,6 +48,13 @@
<listbox id="style-listbox" onselect="Zotero_File_Interface_Bibliography.styleChanged()"/>
</groupbox>
<groupbox>
<hbox align="center">
<caption label="&zotero.bibliography.locale.label;"/>
<menulist id="locale-menu" oncommand="Zotero_File_Interface_Bibliography.localeChanged(this.selectedItem.value)"/>
</hbox>
</groupbox>
<groupbox id="displayAs-groupbox">
<caption label="&zotero.integration.prefs.displayAs.label;"/>
<radiogroup id="displayAs" orient="horizontal">
@ -77,4 +84,4 @@
<checkbox id="storeReferences" label="&zotero.integration.prefs.storeReferences.label;"/>
<description class="radioDescription">&zotero.integration.prefs.storeReferences.caption;</description>
</vbox>
</dialog>
</dialog>

@ -1 +1 @@
Subproject commit d2b612f8a6f764cbd66e67238636fac3888a7736
Subproject commit c1679e2d7ec0819f73a486507c0c2d2a29cef3ed

View file

@ -44,10 +44,17 @@ Zotero_Preferences.Export = {
populateQuickCopyList: function () {
// Initialize default format drop-down
var format = Zotero.Prefs.get("export.quickCopy.setting");
format = Zotero.QuickCopy.unserializeSetting(format);
var menulist = document.getElementById("zotero-quickCopy-menu");
this.buildQuickCopyFormatDropDown(menulist, Zotero.QuickCopy.getContentType(format), format);
this.buildQuickCopyFormatDropDown(menulist, format.contentType, format);
menulist.setAttribute('preference', "pref-quickCopy-setting");
this.updateQuickCopyHTMLCheckbox();
// Initialize locale drop-down
var localeMenulist = document.getElementById("zotero-quickCopy-locale-menu");
this.populateQuickCopyLocaleList(localeMenulist);
localeMenulist.setAttribute('preference', "pref-quickCopy-locale");
this.updateQuickCopyUI();
if (!Zotero.isStandalone) {
this.refreshQuickCopySiteList();
@ -58,12 +65,12 @@ Zotero_Preferences.Export = {
/*
* Builds a Quick Copy drop-down
*/
buildQuickCopyFormatDropDown: function (menulist, contentType, currentFormat) {
if (!currentFormat) {
currentFormat = menulist.value;
buildQuickCopyFormatDropDown: function (menulist, contentType, format) {
if (!format) {
format = menulist.value;
}
// Strip contentType from mode
currentFormat = Zotero.QuickCopy.stripContentType(currentFormat);
format = Zotero.QuickCopy.unserializeSetting(format);
menulist.selectedItem = null;
menulist.removeAllItems();
@ -86,15 +93,14 @@ Zotero_Preferences.Export = {
// add styles to list
var styles = Zotero.Styles.getVisible();
for each(var style in styles) {
var baseVal = 'bibliography=' + style.styleID;
var val = 'bibliography' + (contentType == 'html' ? '/html' : '') + '=' + style.styleID;
var itemNode = document.createElement("menuitem");
itemNode.setAttribute("value", val);
itemNode.setAttribute("label", style.title);
itemNode.setAttribute("oncommand", 'Zotero_Preferences.Export.updateQuickCopyHTMLCheckbox()');
itemNode.setAttribute("oncommand", 'Zotero_Preferences.Export.updateQuickCopyUI()');
popup.appendChild(itemNode);
if (baseVal == currentFormat) {
if (format.mode == 'bibliography' && format.id == style.styleID) {
menulist.selectedItem = itemNode;
}
}
@ -115,14 +121,14 @@ Zotero_Preferences.Export = {
case '14763d24-8ba0-45df-8f52-b8d1108e7ac9':
continue;
}
var val = 'export=' + translators[i].translatorID;
var val = 'export=' + translators[i].translatorID;
var itemNode = document.createElement("menuitem");
itemNode.setAttribute("value", val);
itemNode.setAttribute("label", translators[i].label);
itemNode.setAttribute("oncommand", 'Zotero_Preferences.Export.updateQuickCopyHTMLCheckbox()');
itemNode.setAttribute("oncommand", 'Zotero_Preferences.Export.updateQuickCopyUI()');
popup.appendChild(itemNode);
if (val == currentFormat) {
if (format.mode == 'export' && format.id == translators[i].translatorID) {
menulist.selectedItem = itemNode;
}
}
@ -133,16 +139,49 @@ Zotero_Preferences.Export = {
},
updateQuickCopyHTMLCheckbox: function () {
updateQuickCopyUI: function () {
var format = document.getElementById('zotero-quickCopy-menu').value;
var mode, contentType;
var checkbox = document.getElementById('zotero-quickCopy-copyAsHTML');
[mode, format] = format.split('=');
[mode, contentType] = mode.split('/');
var checkbox = document.getElementById('zotero-quickCopy-copyAsHTML');
checkbox.checked = contentType == 'html';
checkbox.disabled = mode != 'bibliography';
var menulist = document.getElementById('zotero-quickCopy-locale-menu');
var menulistLabel = document.getElementById('zotero-quickCopy-locale-menu-label');
var lastSelectedLocale = menulist.value;
var localeLabel = "";
if (menulist.disabled === true) {
menulist.removeItemAt(0);
}
if (mode == 'bibliography') {
var defaultStyleLocale = Zotero.Styles.get(format).locale;
if (defaultStyleLocale) {
if (Zotero.Styles.locales[defaultStyleLocale] !== undefined) {
localeLabel = Zotero.Styles.locales[defaultStyleLocale];
} else {
localeLabel = defaultStyleLocale;
}
}
menulistLabel.disabled = false;
} else {
menulistLabel.disabled = true;
}
if (mode == 'bibliography' && !defaultStyleLocale) {
menulist.value = lastSelectedLocale;
menulist.disabled = false;
} else {
menulist.insertItemAt(0, localeLabel, lastSelectedLocale);
menulist.selectedIndex = 0;
menulist.disabled = true;
}
},
/**
@ -164,19 +203,24 @@ Zotero_Preferences.Export = {
showQuickCopySiteEditor: function (index) {
var treechildren = document.getElementById('quickCopy-siteSettings-rows');
if (index != undefined && index > -1 && index < treechildren.childNodes.length) {
var formattedName = document.getElementById('zotero-quickCopy-menu').label;
var locale = document.getElementById('zotero-quickCopy-locale-menu').value;
var asHTML = document.getElementById('zotero-quickCopy-copyAsHTML').checked;
if (index !== undefined && index > -1 && index < treechildren.childNodes.length) {
var treerow = treechildren.childNodes[index].firstChild;
var domain = treerow.childNodes[0].getAttribute('label');
var format = treerow.childNodes[1].getAttribute('label');
var asHTML = treerow.childNodes[2].getAttribute('label') != '';
formattedName = treerow.childNodes[1].getAttribute('label');
locale = treerow.childNodes[2].getAttribute('label');
asHTML = treerow.childNodes[3].getAttribute('label') !== '';
}
var format = Zotero.QuickCopy.getSettingFromFormattedName(format);
var format = Zotero.QuickCopy.getSettingFromFormattedName(formattedName);
if (asHTML) {
format = format.replace('bibliography=', 'bibliography/html=');
}
var io = {domain: domain, format: format, ok: false};
var io = {domain: domain, format: format, locale: locale, asHTML: asHTML, ok: false};
window.openDialog('chrome://zotero/content/preferences/quickCopySiteEditor.xul',
"zotero-preferences-quickCopySiteEditor", "chrome,modal,centerscreen", io);
@ -188,7 +232,10 @@ Zotero_Preferences.Export = {
Zotero.DB.query("DELETE FROM settings WHERE setting='quickCopySite' AND key=?", [domain]);
}
Zotero.DB.query("REPLACE INTO settings VALUES ('quickCopySite', ?, ?)", [io.domain, io.format]);
var quickCopysetting = Zotero.QuickCopy.unserializeSetting(io.format);
quickCopysetting.locale = io.locale;
Zotero.DB.query("REPLACE INTO settings VALUES ('quickCopySite', ?, ?)", [io.domain, JSON.stringify(quickCopysetting)]);
this.refreshQuickCopySiteList();
},
@ -213,17 +260,21 @@ Zotero_Preferences.Export = {
var treerow = document.createElement('treerow');
var domainCell = document.createElement('treecell');
var formatCell = document.createElement('treecell');
var localeCell = document.createElement('treecell');
var HTMLCell = document.createElement('treecell');
domainCell.setAttribute('label', siteData[i].domainPath);
var formatted = Zotero.QuickCopy.getFormattedNameFromSetting(siteData[i].format);
formatCell.setAttribute('label', formatted);
var copyAsHTML = Zotero.QuickCopy.getContentType(siteData[i].format) == 'html';
HTMLCell.setAttribute('label', copyAsHTML ? ' ✓ ' : '');
var formattedName = Zotero.QuickCopy.getFormattedNameFromSetting(siteData[i].format);
formatCell.setAttribute('label', formattedName);
var format = Zotero.QuickCopy.unserializeSetting(siteData[i].format);
localeCell.setAttribute('label', format.locale);
HTMLCell.setAttribute('label', format.contentType == 'html' ? ' ✓ ' : '');
treerow.appendChild(domainCell);
treerow.appendChild(formatCell);
treerow.appendChild(localeCell);
treerow.appendChild(HTMLCell);
treeitem.appendChild(treerow);
treechildren.appendChild(treeitem);
@ -241,6 +292,16 @@ Zotero_Preferences.Export = {
this.refreshQuickCopySiteList();
},
/*
* Builds the Quick Copy locale drop-down
*/
populateQuickCopyLocaleList: function (menulist, quickCopyLocale) {
if (!quickCopyLocale) {
quickCopyLocale = Zotero.Prefs.get("export.quickCopy.locale");
}
Zotero.Styles.populateLocaleList(menulist, quickCopyLocale);
},
updateQuickCopyInstructions: function () {
var prefix = Zotero.isMac ? Zotero.getString('general.keys.cmdShift') : Zotero.getString('general.keys.ctrlShift');
@ -253,9 +314,9 @@ Zotero_Preferences.Export = {
}
instr.appendChild(document.createTextNode(str));
var key = Zotero.Prefs.get('keys.copySelectedItemCitationsToClipboard');
var str = Zotero.getString('zotero.preferences.export.quickCopy.citationInstructions', prefix + key);
var instr = document.getElementById('quickCopy-citationInstructions');
key = Zotero.Prefs.get('keys.copySelectedItemCitationsToClipboard');
str = Zotero.getString('zotero.preferences.export.quickCopy.citationInstructions', prefix + key);
instr = document.getElementById('quickCopy-citationInstructions');
while (instr.hasChildNodes()) {
instr.removeChild(instr.firstChild);
}

View file

@ -33,6 +33,7 @@
<preferences>
<preference id="pref-quickCopy-setting" name="extensions.zotero.export.quickCopy.setting" type="string"/>
<preference id="pref-quickCopy-dragLimit" name="extensions.zotero.export.quickCopy.dragLimit" type="int"/>
<preference id="pref-quickCopy-locale" name="extensions.zotero.export.quickCopy.locale" type="string"/>
<preference id="pref-export-displayCharsetOption" name="extensions.zotero.export.displayCharsetOption" type="bool"/>
<preference id="pref-import-charset" name="extensions.zotero.import.charset" type="string"/>
</preferences>
@ -49,10 +50,15 @@
<label value="&zotero.preferences.quickCopy.defaultOutputFormat;" control="quickCopy-menu"/>
<menulist id="zotero-quickCopy-menu"/>
<separator class="thin"/>
<checkbox id="zotero-quickCopy-copyAsHTML" label="&zotero.preferences.quickCopy.copyAsHTML;"
oncommand="Zotero_Preferences.Export.buildQuickCopyFormatDropDown(document.getElementById('zotero-quickCopy-menu'), this.checked ? 'html' : '');"/>
<hbox align="center">
<label id="zotero-quickCopy-locale-menu-label" value="&zotero.preferences.quickCopy.locale;" control="zotero-quickCopy-locale-menu"/>
<menulist id="zotero-quickCopy-locale-menu"/>
<separator orient="vertical" width="15px"/>
<checkbox id="zotero-quickCopy-copyAsHTML" label="&zotero.preferences.quickCopy.copyAsHTML;"
oncommand="Zotero_Preferences.Export.buildQuickCopyFormatDropDown(document.getElementById('zotero-quickCopy-menu'), this.checked ? 'html' : '');"/>
</hbox>
<vbox id="zotero-prefpane-export-siteSettings"/>

View file

@ -42,6 +42,7 @@
<treecols>
<treecol id="quickCopy-urlColumn" label="&zotero.preferences.quickCopy.siteEditor.domainPath;" flex="1"/>
<treecol id="quickCopy-formatColumn" label="&zotero.preferences.quickCopy.siteEditor.outputFormat;" flex="2"/>
<treecol id="quickCopy-localeColumn" label="&zotero.preferences.quickCopy.siteEditor.locale;"/>
<treecol id="quickCopy-copyAsHTML" label="HTML"/>
</treecols>
<treechildren id="quickCopy-siteSettings-rows"/>

View file

@ -36,6 +36,7 @@
<script src="chrome://zotero/content/include.js"/>
<script src="preferences.js"/>
<script src="preferences_export.js"/>
<script>
<![CDATA[
@ -46,6 +47,14 @@
var io = window.arguments[0];
io.domain = document.getElementById('zotero-quickCopy-domain').value;
io.format = document.getElementById('zotero-quickCopy-menu').value;
var menulist = document.getElementById('zotero-quickCopy-locale-menu');
if (menulist.disabled === false) {
io.locale = menulist.value;
} else {
io.locale = "";
}
io.ok = true;
}
}
@ -55,10 +64,21 @@
<vbox id="zotero-preferences-quickCopySiteEditor">
<label value="&zotero.preferences.quickCopy.siteEditor.domainPath; &zotero.preferences.quickCopy.siteEditor.domainPath.example;" control="zotero-quickCopy-domain"/>
<textbox id="zotero-quickCopy-domain"/>
<separator class="thin"/>
<label value="&zotero.preferences.quickCopy.siteEditor.outputFormat;" control="zotero-quickCopy-menu"/>
<menulist id="zotero-quickCopy-menu"/>
<separator class="thin"/>
<label id="zotero-quickCopy-locale-menu-label" value="&zotero.preferences.quickCopy.locale;" control="zotero-quickCopy-locale-menu"/>
<hbox align="center">
<menulist id="zotero-quickCopy-locale-menu"/>
</hbox>
<separator class="thin"/>
<checkbox id="zotero-quickCopy-copyAsHTML" label="&zotero.preferences.quickCopy.copyAsHTML;"
oncommand="window.opener.Zotero_Preferences.Export.buildQuickCopyFormatDropDown(
document.getElementById('zotero-quickCopy-menu'), this.checked ? 'html' : ''
@ -68,13 +88,19 @@
<script>
<![CDATA[
var io = window.arguments[0];
var contentType = io.asHTML ? 'html' : '';
document.getElementById('zotero-quickCopy-domain').value = io.domain ? io.domain : '';
window.opener.Zotero_Preferences.Export.buildQuickCopyFormatDropDown(
document.getElementById('zotero-quickCopy-menu'),
Zotero.QuickCopy.getContentType(io.format),
contentType,
io.format
);
window.opener.Zotero_Preferences.Export.updateQuickCopyHTMLCheckbox();
window.opener.Zotero_Preferences.Export.populateQuickCopyLocaleList(
document.getElementById('zotero-quickCopy-locale-menu'),
io.locale
);
document.getElementById('zotero-quickCopy-copyAsHTML').checked = io.asHTML;
Zotero_Preferences.Export.updateQuickCopyUI();
]]>
</script>
</dialog>

View file

@ -496,7 +496,8 @@ var Zotero_RTFScan = new function() {
function _formatRTF() {
// load style and create ItemSet with all items
var zStyle = Zotero.Styles.get(document.getElementById("style-listbox").selectedItem.value)
var style = zStyle.getCiteProc();
var locale = document.getElementById("locale-menu").selectedItem.value;
var style = zStyle.getCiteProc(locale);
style.setOutputFormat("rtf");
var isNote = style.class == "note";
@ -597,7 +598,10 @@ var Zotero_RTFScan = new function() {
Zotero.File.putContents(outputFile, contents);
// save locale
Zotero.Prefs.set("export.lastLocale", locale);
document.documentElement.canAdvance = true;
document.documentElement.advance();
}
}
}

View file

@ -89,7 +89,12 @@
<caption label="&zotero.bibliography.style.label;"/>
<listbox id="style-listbox" onselect="Zotero_File_Interface_Bibliography.styleChanged()" flex="1"/>
</groupbox>
<groupbox>
<hbox align="center">
<caption label="&zotero.bibliography.locale.label;"/>
<menulist id="locale-menu" oncommand="Zotero_File_Interface_Bibliography.localeChanged(this.selectedItem.value)"/>
</hbox>
</groupbox>
<groupbox>
<caption label="&zotero.integration.prefs.displayAs.label;"/>
<radiogroup id="displayAs" orient="horizontal">

View file

@ -30,6 +30,11 @@ var Zotero_CSL_Editor = new function() {
this.generateBibliography = generateBibliography;
this.refresh = refresh;
function init() {
var quickCopyLocale = Zotero.Prefs.get("export.quickCopy.locale");
var menulist = document.getElementById("locale-menu");
Zotero.Styles.populateLocaleList(menulist, quickCopyLocale);
var cslList = document.getElementById('zotero-csl-list');
if (cslList.getAttribute('initialized') == 'true') {
if (currentStyle) {
@ -39,8 +44,8 @@ var Zotero_CSL_Editor = new function() {
return;
}
var rawDefaultStyle = Zotero.Prefs.get('export.quickCopy.setting');
var defaultStyle = Zotero.QuickCopy.stripContentType(rawDefaultStyle);
var quickCopyFormat = Zotero.Prefs.get('export.quickCopy.setting');
quickCopyFormat = Zotero.QuickCopy.unserializeSetting(quickCopyFormat);
var styles = Zotero.Styles.getAll();
var currentStyle = null;
@ -50,7 +55,7 @@ var Zotero_CSL_Editor = new function() {
continue;
}
var item = cslList.appendItem(style.title, style.styleID);
if (!currentStyle || defaultStyle == ('bibliography=' + style.styleID)) {
if (!currentStyle || (quickCopyFormat.mode == 'bibliography' && quickCopyFormat.id == style.styleID)) {
currentStyle = style.styleID;
cslList.selectedIndex = listPos;
}
@ -130,10 +135,12 @@ var Zotero_CSL_Editor = new function() {
iframe.contentDocument.documentElement.innerHTML = '<html><head><title></title></head><body><p style="color: red">' + Zotero.getString('styles.editor.warning.noItems') + '</p></body></html>';
return;
}
var locale = document.getElementById("locale-menu").selectedItem.value;
var styleObject, styleEngine;
try {
styleObject = new Zotero.Style(str);
styleEngine = styleObject.getCiteProc();
styleEngine = styleObject.getCiteProc(locale);
} catch(e) {
iframe.contentDocument.documentElement.innerHTML = '<div>' + Zotero.getString('styles.editor.warning.parseError') + '</div><div>'+e+'</div>';
throw e;

View file

@ -58,6 +58,7 @@
<menuitem label="near-note" value="4"/>
</menupopup>
</menulist>
<menulist id="locale-menu" oncommand="Zotero_CSL_Editor.refresh()"/>
<menulist id="zotero-csl-list" style="min-height: 1.6em; min-width: 100px" initialized="false" flex="1" oncommand="Zotero_CSL_Editor.loadCSL(this.selectedItem.value)"/>
</hbox>
<textbox id="zotero-csl-editor" type="timed" timeout="250" multiline="true"

View file

@ -31,6 +31,10 @@ var Zotero_CSL_Preview = new function() {
function init() {
//refresh();
var quickCopyLocale = Zotero.Prefs.get("export.quickCopy.locale");
var menulist = document.getElementById("locale-menu");
Zotero.Styles.populateLocaleList(menulist, quickCopyLocale);
var iframe = document.getElementById('zotero-csl-preview-box');
iframe.contentDocument.documentElement.innerHTML = '<html><head><title></title></head><body><p>' + Zotero.getString('styles.preview.instructions') + '</p></body></html>';
@ -86,7 +90,10 @@ var Zotero_CSL_Preview = new function() {
Zotero.debug("CSL IGNORE: citation format is " + style.categories);
return '';
}
var styleEngine = style.getCiteProc();
var locale = document.getElementById("locale-menu").selectedItem.value;
var styleEngine = style.getCiteProc(locale);
// Generate multiple citations
var citations = styleEngine.previewCitationCluster(

View file

@ -56,6 +56,8 @@
<menuitem value="numeric" label="&styles.preview.citationFormat.numeric;"/>
</menupopup>
</menulist>
<menulist id="locale-menu" oncommand="Zotero_CSL_Preview.refresh()"/>
</hbox>
<iframe id="zotero-csl-preview-box" flex="1" style="padding: 0 1em; background:white;" overflow="auto" type="content"/>
</vbox>

View file

@ -2039,7 +2039,7 @@ Zotero.Integration.Session.prototype.setData = function(data, resetStyle) {
try {
var getStyle = Zotero.Styles.get(data.style.styleID);
data.style.hasBibliography = getStyle.hasBibliography;
this.style = getStyle.getCiteProc(data.prefs.automaticJournalAbbreviations);
this.style = getStyle.getCiteProc(data.locale, data.prefs.automaticJournalAbbreviations);
this.style.setOutputFormat("rtf");
this.styleClass = getStyle.class;
this.dateModified = new Object();
@ -2069,6 +2069,7 @@ Zotero.Integration.Session.prototype.setDocPrefs = function(doc, primaryFieldTyp
if(this.data) {
io.style = this.data.style.styleID;
io.locale = this.data.locale;
io.useEndnotes = this.data.prefs.noteType == 0 ? 0 : this.data.prefs.noteType-1;
io.fieldType = this.data.prefs.fieldType;
io.primaryFieldType = primaryFieldType;
@ -2091,13 +2092,19 @@ Zotero.Integration.Session.prototype.setDocPrefs = function(doc, primaryFieldTyp
var data = new Zotero.Integration.DocumentData();
data.sessionID = oldData.sessionID;
data.style.styleID = io.style;
data.locale = io.locale;
data.prefs.fieldType = io.fieldType;
data.prefs.storeReferences = io.storeReferences;
data.prefs.automaticJournalAbbreviations = io.automaticJournalAbbreviations;
var localeChanged = false;
if (!oldData.locale || (oldData.locale != io.locale)) {
localeChanged = true;
}
me.setData(data, oldData &&
oldData.prefs.automaticJournalAbbreviations !=
data.prefs.automaticJournalAbbreviations);
(oldData.prefs.automaticJournalAbbreviations !=
data.prefs.automaticJournalAbbreviations || localeChanged));
// need to do this after setting the data so that we know if it's a note style
me.data.prefs.noteType = me.style && me.styleClass == "note" ? io.useEndnotes+1 : 0;

View file

@ -2670,12 +2670,12 @@ Zotero.ItemTreeView.prototype.onDragStart = function (event) {
event.dataTransfer.setData("text/plain", text);
}
format = Zotero.QuickCopy.unserializeSetting(format);
try {
var [mode, ] = format.split('=');
if (mode == 'export') {
if (format.mode == 'export') {
Zotero.QuickCopy.getContentFromItems(items, format, exportCallback);
}
else if (mode.indexOf('bibliography') == 0) {
else if (format.mode == 'bibliography') {
var content = Zotero.QuickCopy.getContentFromItems(items, format, null, event.shiftKey);
if (content) {
if (content.html) {
@ -2685,11 +2685,11 @@ Zotero.ItemTreeView.prototype.onDragStart = function (event) {
}
}
else {
Components.utils.reportError("Invalid Quick Copy mode '" + mode + "'");
Components.utils.reportError("Invalid Quick Copy mode");
}
}
catch (e) {
Components.utils.reportError(e + " with format '" + format + "'");
Components.utils.reportError(e + " with '" + format.id + "'");
}
}

View file

@ -25,27 +25,61 @@
Zotero.QuickCopy = new function() {
this.getFormattedNameFromSetting = getFormattedNameFromSetting;
this.getSettingFromFormattedName = getSettingFromFormattedName;
this.getContentType = getContentType;
this.stripContentType = stripContentType;
this.getFormatFromURL = getFormatFromURL;
this.getContentFromItems = getContentFromItems;
var _initialized = false;
var _formattedNames = {};
/*
* Return Quick Copy setting object from string, stringified object, or object
*
* Example string format: "bibliography/html=http://www.zotero.org/styles/apa"
*
* Quick Copy setting object has the following properties:
* - "mode": "bibliography" (for styles) or "export" (for export translators)
* - "contentType: "" (plain text output) or "html" (HTML output; for styles
* only)
* - "id": style ID or export translator ID
* - "locale": locale code (for styles only)
*/
this.unserializeSetting = function (setting) {
var settingObject = {};
if (typeof setting === 'string' || setting instanceof String) {
try {
// First test if string input is a stringified object
settingObject = JSON.parse(setting);
} catch (e) {
// Try parsing as formatted string
var parsedSetting = setting.match(/(bibliography|export)(?:\/([^=]+))?=(.+)$/);
if (parsedSetting) {
settingObject.mode = parsedSetting[1];
settingObject.contentType = parsedSetting[2] || '';
settingObject.id = parsedSetting[3];
settingObject.locale = '';
}
}
} else {
// Return input if not a string; it might already be an object
return setting;
}
return settingObject;
};
function getFormattedNameFromSetting(setting) {
this.getFormattedNameFromSetting = function (setting) {
if (!_initialized) {
_init();
}
var name = _formattedNames[this.stripContentType(setting)];
var format = this.unserializeSetting(setting);
var name = _formattedNames[format.mode + "=" + format.id];
return name ? name : '';
}
};
function getSettingFromFormattedName(name) {
this.getSettingFromFormattedName = function (name) {
if (!_initialized) {
_init();
}
@ -57,29 +91,15 @@ Zotero.QuickCopy = new function() {
}
return '';
}
};
/*
* Returns the setting with any contentType stripped from the mode part
*/
function getContentType(setting) {
var matches = setting.match(/(?:bibliography|export)\/([^=]+)=.+$/, '$1');
return matches ? matches[1] : '';
}
/*
* Returns the setting with any contentType stripped from the mode part
*/
function stripContentType(setting) {
return setting.replace(/(bibliography|export)(?:\/[^=]+)?=(.+)$/, '$1=$2');
}
function getFormatFromURL(url) {
this.getFormatFromURL = function(url) {
var quickCopyPref = Zotero.Prefs.get("export.quickCopy.setting");
quickCopyPref = JSON.stringify(this.unserializeSetting(quickCopyPref));
if (!url) {
return Zotero.Prefs.get("export.quickCopy.setting");
return quickCopyPref;
}
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
@ -91,7 +111,7 @@ Zotero.QuickCopy = new function() {
var urlPath = nsIURI.path;
}
catch (e) {
return Zotero.Prefs.get("export.quickCopy.setting");
return quickCopyPref;
}
var matches = [];
@ -100,13 +120,14 @@ Zotero.QuickCopy = new function() {
+ "WHERE setting='quickCopySite' AND (key LIKE ? OR key LIKE ?)";
var urlDomain = urlHostPort.match(/[^\.]+\.[^\.]+$/);
var rows = Zotero.DB.query(sql, ['%' + urlDomain + '%', '/%']);
for each(var row in rows) {
var [domain, path] = row.domainPath.split(/\//);
for (let i = 0; i < rows.length; i++) {
let row = rows[i];
let [domain, path] = row.domainPath.split(/\//);
path = '/' + (path ? path : '');
var re = new RegExp(domain + '$');
if (urlHostPort.match(re) && urlPath.indexOf(path) == 0) {
let re = new RegExp(domain + '$');
if (urlHostPort.match(re) && urlPath.indexOf(path) === 0) {
matches.push({
format: row.format,
format: JSON.stringify(this.unserializeSetting(row.format)),
domainLength: domain.length,
pathLength: path.length
});
@ -130,15 +151,15 @@ Zotero.QuickCopy = new function() {
}
return -1;
}
};
if (matches.length) {
matches.sort(sort);
return matches[0].format;
} else {
return quickCopyPref;
}
return Zotero.Prefs.get("export.quickCopy.setting");
}
};
/*
@ -146,8 +167,9 @@ Zotero.QuickCopy = new function() {
*
* |items| is an array of Zotero.Item objects
*
* |format| is a Quick Copy format string
* (e.g. "bibliography=http://purl.org/net/xbiblio/csl/styles/apa.csl")
* |format| may be a Quick Copy format string
* (e.g. "bibliography=http://www.zotero.org/styles/apa")
* or an Quick Copy format object
*
* |callback| is only necessary if using an export format and should be
* a function suitable for Zotero.Translate.setHandler, taking parameters
@ -157,25 +179,24 @@ Zotero.QuickCopy = new function() {
* If bibliography format, the process is synchronous and an object
* contain properties 'text' and 'html' is returned.
*/
function getContentFromItems(items, format, callback, modified) {
this.getContentFromItems = function (items, format, callback, modified) {
if (items.length > Zotero.Prefs.get('export.quickCopy.dragLimit')) {
Zotero.debug("Skipping quick copy for " + items.length + " items");
return false;
}
var [mode, format] = format.split('=');
var [mode, contentType] = mode.split('/');
format = this.unserializeSetting(format);
if (mode == 'export') {
if (format.mode == 'export') {
var translation = new Zotero.Translate.Export;
translation.noWait = true; // needed not to break drags
translation.setItems(items);
translation.setTranslator(format);
translation.setTranslator(format.id);
translation.setHandler("done", callback);
translation.translate();
return true;
}
else if (mode == 'bibliography') {
else if (format.mode == 'bibliography') {
// Move notes to separate array
var allNotes = true;
var notes = [];
@ -320,32 +341,35 @@ Zotero.QuickCopy = new function() {
}
var content = {
text: contentType == "html" ? html : text,
text: format.contentType == "html" ? html : text,
html: copyHTML
};
return content;
}
// determine locale preference
var locale = format.locale ? format.locale : Zotero.Prefs.get('export.quickCopy.locale');
// Copy citations if shift key pressed
if (modified) {
var csl = Zotero.Styles.get(format).getCiteProc();
var csl = Zotero.Styles.get(format.id).getCiteProc(locale);
csl.updateItems([item.id for each(item in items)]);
var citation = {citationItems:[{id:item.id} for each(item in items)], properties:{}};
var html = csl.previewCitationCluster(citation, [], [], "html");
var text = csl.previewCitationCluster(citation, [], [], "text");
} else {
var style = Zotero.Styles.get(format);
var cslEngine = style.getCiteProc();
var style = Zotero.Styles.get(format.id);
var cslEngine = style.getCiteProc(locale);
var html = Zotero.Cite.makeFormattedBibliographyOrCitationList(cslEngine, items, "html");
var text = Zotero.Cite.makeFormattedBibliographyOrCitationList(cslEngine, items, "text");
}
return {text:(contentType == "html" ? html : text), html:html};
return {text:(format.contentType == "html" ? html : text), html:html};
}
throw ("Invalid mode '" + mode + "' in Zotero.QuickCopy.getContentFromItems()");
}
throw ("Invalid mode '" + format.mode + "' in Zotero.QuickCopy.getContentFromItems()");
};
function _init() {

View file

@ -81,9 +81,35 @@ Zotero.Styles = new function() {
// hidden dir
dir.append("hidden");
if(dir.exists()) i += _readStylesFromDirectory(dir, true);
if (dir.exists()) i += _readStylesFromDirectory(dir, true);
Zotero.debug("Cached "+i+" styles in "+((new Date()).getTime() - start)+" ms");
// transfer and reset "export.bibliographyLocale" pref value
var bibliographyLocale = '';
bibliographyLocale = Zotero.Prefs.get("export.bibliographyLocale");
if (bibliographyLocale) {
Zotero.Prefs.set("export.lastLocale", bibliographyLocale);
Zotero.Prefs.set("export.quickCopy.locale", bibliographyLocale);
Zotero.Prefs.clear("export.bibliographyLocale");
}
// load available CSL locales
var localeFile = {};
var locales = {};
var primaryDialects = {};
var localesLocation = "chrome://zotero/content/locale/csl/locales.json";
localeFile = JSON.parse(Zotero.File.getContentsFromURL(localesLocation));
primaryDialects = localeFile["primary-dialects"];
// only keep localized language name
for (let locale in localeFile["language-names"]) {
locales[locale] = localeFile["language-names"][locale][0];
}
this.locales = locales;
this.primaryDialects = primaryDialects;
}
/**
@ -399,6 +425,74 @@ Zotero.Styles = new function() {
}
});
}
/**
* Populate menulist with locales
*/
this.populateLocaleList = function(menulist, prefLocale) {
if(!_initialized) this.init();
// Reset menulist
menulist.selectedItem = null;
menulist.removeAllItems();
var doc = menulist.ownerDocument;
var popup = doc.createElement('menupopup');
menulist.appendChild(popup);
var desiredLocale = "";
var fallbackLocale = Zotero.locale;
// Primary dialect conversion (e.g. "en" to "en-US")
if (Zotero.Styles.primaryDialects[prefLocale] !== undefined) {
prefLocale = Zotero.Styles.primaryDialects[prefLocale];
}
if (Zotero.Styles.primaryDialects[fallbackLocale] !== undefined) {
fallbackLocale = Zotero.Styles.primaryDialects[fallbackLocale];
}
if (prefLocale) {
desiredLocale = prefLocale;
} else {
desiredLocale = fallbackLocale;
}
var menuLocales = {};
var menuLocalesKeys = [];
var styleLocales = Zotero.Styles.locales;
for (let locale in styleLocales) {
menuLocales[locale] = styleLocales[locale];
}
menuLocalesKeys = Object.keys(menuLocales);
menuLocalesKeys.sort();
if (fallbackLocale && menuLocales[fallbackLocale] === undefined) {
menuLocales[fallbackLocale] = fallbackLocale;
menuLocalesKeys.unshift(fallbackLocale);
}
if (prefLocale && menuLocales[prefLocale] === undefined) {
menuLocales[prefLocale] = prefLocale;
menuLocalesKeys.unshift(prefLocale);
}
var itemNode;
for (let i=0; i<menuLocalesKeys.length; i++) {
var menuValue = menuLocalesKeys[i];
var menuLabel = menuLocales[menuLocalesKeys[i]];
itemNode = doc.createElement("menuitem");
itemNode.setAttribute("value", menuValue);
itemNode.setAttribute("label", menuLabel);
popup.appendChild(itemNode);
if (menuValue == desiredLocale) {
menulist.selectedItem = itemNode;
}
}
return desiredLocale;
};
}
/**
@ -478,10 +572,10 @@ Zotero.Style = function(arg) {
/**
* Get a citeproc-js CSL.Engine instance
* @param {Boolean} useAutomaticJournalAbbreviations Whether to automatically abbreviate titles
* @param {String} locale Locale code
* @param {Boolean} automaticJournalAbbreviations Whether to automatically abbreviate titles
*/
Zotero.Style.prototype.getCiteProc = function(automaticJournalAbbreviations) {
var locale = Zotero.Prefs.get('export.bibliographyLocale');
Zotero.Style.prototype.getCiteProc = function(locale, automaticJournalAbbreviations) {
if(!locale) {
var locale = Zotero.locale;
if(!locale) {

View file

@ -1866,24 +1866,27 @@ var ZoteroPane = new function()
}
var url = (window.content && window.content.location ? window.content.location.href : null);
var [mode, format] = Zotero.QuickCopy.getFormatFromURL(url).split('=');
var [mode, contentType] = mode.split('/');
var format = Zotero.QuickCopy.getFormatFromURL(url);
format = Zotero.QuickCopy.unserializeSetting(format);
if (mode == 'bibliography') {
// determine locale preference
var locale = format.locale ? format.locale : Zotero.Prefs.get('export.quickCopy.locale');
if (format.mode == 'bibliography') {
if (asCitations) {
Zotero_File_Interface.copyCitationToClipboard(items, format, contentType == 'html');
Zotero_File_Interface.copyCitationToClipboard(items, format.id, locale, format.contentType == 'html');
}
else {
Zotero_File_Interface.copyItemsToClipboard(items, format, contentType == 'html');
Zotero_File_Interface.copyItemsToClipboard(items, format.id, locale, format.contentType == 'html');
}
}
else if (mode == 'export') {
else if (format.mode == 'export') {
// Copy citations doesn't work in export mode
if (asCitations) {
return;
}
else {
Zotero_File_Interface.exportItemsToClipboard(items, format);
Zotero_File_Interface.exportItemsToClipboard(items, format.id);
}
}
}

View file

@ -101,12 +101,14 @@
<!ENTITY zotero.preferences.quickCopy.caption "Quick Copy">
<!ENTITY zotero.preferences.quickCopy.defaultOutputFormat "Default Output Format:">
<!ENTITY zotero.preferences.quickCopy.locale "Bibliography Locale:">
<!ENTITY zotero.preferences.quickCopy.copyAsHTML "Copy as HTML">
<!ENTITY zotero.preferences.quickCopy.macWarning "Note: Rich-text formatting will be lost on Mac OS X.">
<!ENTITY zotero.preferences.quickCopy.siteEditor.setings "Site-Specific Settings:">
<!ENTITY zotero.preferences.quickCopy.siteEditor.domainPath "Domain/Path">
<!ENTITY zotero.preferences.quickCopy.siteEditor.domainPath.example "(e.g. wikipedia.org)">
<!ENTITY zotero.preferences.quickCopy.siteEditor.outputFormat "Output Format">
<!ENTITY zotero.preferences.quickCopy.siteEditor.locale "Locale">
<!ENTITY zotero.preferences.quickCopy.dragLimit "Disable Quick Copy when dragging more than">
<!ENTITY zotero.preferences.prefpane.cite "Cite">

View file

@ -165,6 +165,7 @@
<!ENTITY zotero.bibliography.title "Create Citation/Bibliography">
<!ENTITY zotero.bibliography.style.label "Citation Style:">
<!ENTITY zotero.bibliography.locale.label "Locale:">
<!ENTITY zotero.bibliography.outputMode "Output Mode:">
<!ENTITY zotero.bibliography.bibliography "Bibliography">
<!ENTITY zotero.bibliography.outputMethod "Output Method:">

View file

@ -99,7 +99,6 @@ pref("extensions.zotero.export.lastTranslator", '14763d24-8ba0-45df-8f52-b8d1108
pref("extensions.zotero.export.translatorSettings", 'true,false');
pref("extensions.zotero.export.lastStyle", 'http://www.zotero.org/styles/chicago-note-bibliography');
pref("extensions.zotero.export.bibliographySettings", 'save-as-rtf');
pref("extensions.zotero.export.bibliographyLocale", '');
pref("extensions.zotero.export.displayCharsetOption", false);
pref("extensions.zotero.export.citePaperJournalArticleURL", false);
pref("extensions.zotero.cite.automaticJournalAbbreviations", true);