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
This commit is contained in:
Dan Stillman 2016-11-27 15:36:37 -05:00
parent 5a6f1eef63
commit 0609b62a39

View file

@ -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
});
}
}
}
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);
// 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" }
);
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);
}
} else {
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);
}
}
else {
var charsetSeparator = document.createElement("menuseparator");
charsetPopup.appendChild(charsetSeparator);
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
});
}
}
}
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");