From 0609b62a39bcd1286bc7319934364de5146c13c4 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sun, 27 Nov 2016 15:36:37 -0500 Subject: [PATCH] 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 --- chrome/content/zotero/charsetMenu.js | 115 +++++++++++++++------------ 1 file changed, 63 insertions(+), 52 deletions(-) diff --git a/chrome/content/zotero/charsetMenu.js b/chrome/content/zotero/charsetMenu.js index bd30fea32..8de8954df 100644 --- 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 - }); - } - } - } - 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= 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= 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");