From 09e8cdbd294d5f722af502f36c9445a3f3116c39 Mon Sep 17 00:00:00 2001 From: "scott%scott-macgregor.org" Date: Fri, 27 Jan 2006 22:22:40 +0000 Subject: [PATCH] Bug #315057 --> Display - Fonts tab: The pull-down menu of Character Encodings doesn't work. build the menu popup by hand instead of using the xul template builder (which doesn't work with dynamic overlays) sr=bienvenu --- mail/components/preferences/display.js | 48 +++++++++++++++++++++++++ mail/components/preferences/display.xul | 21 ++++------- 2 files changed, 55 insertions(+), 14 deletions(-) diff --git a/mail/components/preferences/display.js b/mail/components/preferences/display.js index d78c4a72aad..6ccb4c3e1a1 100644 --- a/mail/components/preferences/display.js +++ b/mail/components/preferences/display.js @@ -44,6 +44,12 @@ var gDisplayPane = { var preference = document.getElementById("mail.preferences.display.selectedTabIndex"); if (preference.value) document.getElementById("displayPrefs").selectedIndex = preference.value; + + // build the charset menu list. We do this by hand instead of using the xul template + // builder because of Bug #285076, + this.createCharsetMenus(document.getElementById("viewDefaultCharset-menupopup"), "NC:DecodersRoot", + document.getElementById('mailnews.view_default_charset').value); + this.mInitialized = true; }, @@ -74,6 +80,44 @@ var gDisplayPane = { { document.documentElement.openSubDialog("chrome://messenger/content/preferences/fonts.xul", "", null); }, + + addMenuItem: function(aMenuPopup, aLabel, aValue) + { + var menuItem = document.createElement('menuitem'); + menuItem.setAttribute('label', aLabel); + menuItem.setAttribute('value', aValue); + aMenuPopup.appendChild(menuItem); + }, + + readRDFString: function(aDS,aRes,aProp) + { + var n = aDS.GetTarget(aRes, aProp, true); + return (n) ? n.QueryInterface(Components.interfaces.nsIRDFLiteral).Value : ""; + }, + + createCharsetMenus: function(aMenuPopup, aRoot, aPreferenceValue) + { + var rdfService = Components.classes["@mozilla.org/rdf/rdf-service;1"] + .getService(Components.interfaces.nsIRDFService); + var kNC_Root = rdfService.GetResource(aRoot); + var kNC_Name = rdfService.GetResource("http://home.netscape.com/NC-rdf#Name"); + + var rdfDataSource = rdfService.GetDataSource("rdf:charset-menu"); + var rdfContainer = Components.classes["@mozilla.org/rdf/container;1"].getService(Components.interfaces.nsIRDFContainer); + rdfContainer.Init(rdfDataSource, kNC_Root); + + var charset; + var availableCharsets = rdfContainer.GetElements(); + + for (var i = 0; i < rdfContainer.GetCount(); i++) + { + charset = availableCharsets.getNext().QueryInterface(Components.interfaces.nsIRDFResource); + + this.addMenuItem(aMenuPopup, this.readRDFString(rdfDataSource, charset, kNC_Name), charset.Value); + if (charset.Value == aPreferenceValue) + aMenuPopup.parentNode.value = charset.Value; + } + }, mCharsetMenuInitialized: false, readDefaultCharset: function() @@ -83,6 +127,10 @@ var gDisplayPane = { Components.classes["@mozilla.org/observer-service;1"] .getService(Components.interfaces.nsIObserverService) .notifyObservers(null, "charsetmenu-selected", "mailedit"); + // build the charset menu list. We do this by hand instead of using the xul template + // builder because of Bug #285076, + this.createCharsetMenus(document.getElementById("sendDefaultCharset-menupopup"), "NC:MaileditCharsetMenuRoot", + document.getElementById('mailnews.send_default_charset').value); this.mCharsetMenuInitialized = true; } return undefined; diff --git a/mail/components/preferences/display.xul b/mail/components/preferences/display.xul index b76c37e45f6..7269e3f4545 100644 --- a/mail/components/preferences/display.xul +++ b/mail/components/preferences/display.xul @@ -229,26 +229,19 @@