commit 0609b62a39bcd1286bc7319934364de5146c13c4
parent 5a6f1eef639ffa7a426e268c9c79afaf87c8579a
Author: Dan Stillman <dstillman@zotero.org>
Date: Sun, 27 Nov 2016 15:36:37 -0500
Show only UTF-8, UTF-8 w/o BOM, and Western for export charsets
See https://forums.zotero.org/discussion/comment/263644/#Comment_263644
We might want to consider removing the export charset checkbox in the
prefs and either always showing the charset option for translators or
always showing it for BibTeX (where "Western" really means "ASCII") but
nothing else.
Fixes #1124
Diffstat:
1 file changed, 62 insertions(+), 51 deletions(-)
diff --git a/chrome/content/zotero/charsetMenu.js b/chrome/content/zotero/charsetMenu.js
@@ -39,65 +39,76 @@ var Zotero_Charset_Menu = new function() {
// get charset popup and charset RDF
var charsetPopup = document.createElement("menupopup");
charsetMenu.appendChild(charsetPopup);
- var charsetSeparator = document.createElement("menuseparator");
- charsetPopup.appendChild(charsetSeparator);
var charsets = [];
-
- Components.utils.import("resource://gre/modules/CharsetMenu.jsm");
- var cmData = CharsetMenu.getData();
- for (let charsetList of [cmData.pinnedCharsets, cmData.otherCharsets]) {
- for each(var charsetInfo in charsetList) {
- if(charsetInfo.value == "UTF-8") {
- charsets.push({
- "label":"Unicode (UTF-8)",
- "value":"UTF-8"
- });
- } else {
- charsets.push({
- "label":charsetInfo.label,
- "value":charsetInfo.value
- });
- }
+
+ // Only list UTF-8 and Western for export
+ if (exportMenu) {
+ charsets.push(
+ { label: "Unicode (UTF-8)", value: "UTF-8" },
+ { label: Zotero.getString("charset.UTF8withoutBOM"), value: "UTF-8xBOM" },
+ { label: "Western", value: "windows-1252" }
+ );
+
+ for (let charset of charsets) {
+ let { label, value } = charset;
+
+ let itemNode = document.createElement("menuitem");
+ itemNode.setAttribute("label", label);
+ itemNode.setAttribute("value", value);
+
+ charsetMap[value] = itemNode;
+ charsetPopup.appendChild(itemNode);
}
}
- charsets = charsets.concat([
- {"label":"UTF-16LE", "value":"UTF-16LE"},
- {"label":"UTF-16BE", "value":"UTF-16BE"},
- {"label":"Western (IBM-850)", "value":"IBM850"},
- {"label":"Western (MacRoman)", "value":"macintosh"}
- ]);
-
- for(var i=0; i<charsets.length; i++) {
- var charset = charsets[i].value,
- label = charsets[i].label;
-
- // add element
- var itemNode = document.createElement("menuitem");
- itemNode.setAttribute("label", label);
- itemNode.setAttribute("value", charset);
+ else {
+ var charsetSeparator = document.createElement("menuseparator");
+ charsetPopup.appendChild(charsetSeparator);
- charsetMap[charset] = itemNode;
- if(isUTF16 || (label.length >= 7 &&
- label.substr(0, 7) == "Western")) {
- charsetPopup.insertBefore(itemNode, charsetSeparator);
- } else if(charset == "UTF-8") {
- var oldFirst = (charsetPopup.firstChild ? charsetPopup.firstChild : null);
- charsetPopup.insertBefore(itemNode, oldFirst);
- // also add (without BOM) if requested
- if(exportMenu) {
- var itemNode = document.createElement("menuitem");
- itemNode.setAttribute("label", Zotero.getString("charset.UTF8withoutBOM"));
- itemNode.setAttribute("value", charset+"xBOM");
- charsetMap[charset+"xBOM"] = itemNode;
- charsetPopup.insertBefore(itemNode, oldFirst);
+ Components.utils.import("resource://gre/modules/CharsetMenu.jsm");
+ var cmData = CharsetMenu.getData();
+ for (let charsetList of [cmData.pinnedCharsets, cmData.otherCharsets]) {
+ for each(var charsetInfo in charsetList) {
+ if(charsetInfo.value == "UTF-8") {
+ charsets.push({
+ "label":"Unicode (UTF-8)",
+ "value":"UTF-8"
+ });
+ } else {
+ charsets.push({
+ "label":charsetInfo.label,
+ "value":charsetInfo.value
+ });
+ }
}
- } else {
- charsetPopup.appendChild(itemNode);
}
- }
+ charsets = charsets.concat([
+ {"label":"UTF-16LE", "value":"UTF-16LE"},
+ {"label":"UTF-16BE", "value":"UTF-16BE"},
+ {"label":"Western (IBM-850)", "value":"IBM850"},
+ {"label":"Western (MacRoman)", "value":"macintosh"}
+ ]);
- if(!exportMenu) {
+ for(var i=0; i<charsets.length; i++) {
+ var charset = charsets[i].value,
+ label = charsets[i].label;
+
+ // add element
+ var itemNode = document.createElement("menuitem");
+ itemNode.setAttribute("label", label);
+ itemNode.setAttribute("value", charset);
+
+ charsetMap[charset] = itemNode;
+ if (label.length >= 7 && label.substr(0, 7) == "Western") {
+ charsetPopup.insertBefore(itemNode, charsetSeparator);
+ } else if(charset == "UTF-8") {
+ var oldFirst = (charsetPopup.firstChild ? charsetPopup.firstChild : null);
+ charsetPopup.insertBefore(itemNode, oldFirst);
+ } else {
+ charsetPopup.appendChild(itemNode);
+ }
+ }
+
var itemNode = document.createElement("menuitem");
itemNode.setAttribute("label", Zotero.getString("charset.autoDetect"));
itemNode.setAttribute("value", "auto");