From 13a42d51d1951b151f22aafab2b214ada74309ac Mon Sep 17 00:00:00 2001 From: "shliang%netscape.com" Date: Wed, 16 Apr 2003 07:07:10 +0000 Subject: [PATCH] bug 107877. default font prefs for msg compose. r=neil, brade, sr=sspitzer, jag. --- editor/ui/composer/content/editor.js | 40 ++++++--- editor/ui/composer/content/editorOverlay.xul | 1 + .../content/pref-composing_messages.xul | 88 ++++++++++++++++++- .../locale/en-US/pref-composing_messages.dtd | 6 ++ .../resources/content/MsgComposeCommands.js | 55 +++++++++++- mailnews/mailnews.js | 6 ++ modules/libpref/src/init/mailnews.js | 6 ++ 7 files changed, 183 insertions(+), 19 deletions(-) diff --git a/editor/ui/composer/content/editor.js b/editor/ui/composer/content/editor.js index 68549f8b3e97..86545295bd54 100644 --- a/editor/ui/composer/content/editor.js +++ b/editor/ui/composer/content/editor.js @@ -1038,6 +1038,8 @@ function initFontFaceMenu(menuPopup) } } +const kFixedFontFaceMenuItems = 7; // number of fixed font face menuitems + function initLocalFontFaceMenu(menuPopup) { if (!gLocalFonts) @@ -1049,22 +1051,32 @@ function initLocalFontFaceMenu(menuPopup) .getService(Components.interfaces.nsIFontEnumerator); var localFontCount = { value: 0 } gLocalFonts = enumerator.EnumerateAllFonts(localFontCount); - for (var i = 0; i < gLocalFonts.length; ++i) - { - if (gLocalFonts[i] != "") - { - var itemNode = document.createElementNS(XUL_NS, "menuitem"); - itemNode.setAttribute("label", gLocalFonts[i]); - itemNode.setAttribute("value", gLocalFonts[i]); - itemNode.setAttribute("type", "radio"); - itemNode.setAttribute("name", "2"); - itemNode.setAttribute("observes", "cmd_renderedHTMLEnabler"); - menuPopup.appendChild(itemNode); - } - } } catch(e) { } } + + var useRadioMenuitems = (menuPopup.parentNode.localName == "menu"); // don't do this for menulists + if (menuPopup.childNodes.length == kFixedFontFaceMenuItems) + { + if (gLocalFonts.length == 0) { + menuPopup.childNodes[kFixedFontFaceMenuItems - 1].hidden = true; + } + for (var i = 0; i < gLocalFonts.length; ++i) + { + if (gLocalFonts[i] != "") + { + var itemNode = document.createElementNS(XUL_NS, "menuitem"); + itemNode.setAttribute("label", gLocalFonts[i]); + itemNode.setAttribute("value", gLocalFonts[i]); + if (useRadioMenuitems) { + itemNode.setAttribute("type", "radio"); + itemNode.setAttribute("name", "2"); + } + itemNode.setAttribute("observes", "cmd_renderedHTMLEnabler"); + menuPopup.appendChild(itemNode); + } + } + } } @@ -1132,7 +1144,7 @@ function initFontSizeMenu(menuPopup) // note that no item is checked in the case of "mixed" selection children[mediumIndex].setAttribute("checked", !sizeWasFound); } - } +} function onHighlightColorChange() { diff --git a/editor/ui/composer/content/editorOverlay.xul b/editor/ui/composer/content/editorOverlay.xul index 2681c6725ac7..6360d3891ecd 100644 --- a/editor/ui/composer/content/editorOverlay.xul +++ b/editor/ui/composer/content/editorOverlay.xul @@ -752,6 +752,7 @@ + diff --git a/mailnews/compose/prefs/resources/content/pref-composing_messages.xul b/mailnews/compose/prefs/resources/content/pref-composing_messages.xul index 4f206adf834e..ccead4041477 100644 --- a/mailnews/compose/prefs/resources/content/pref-composing_messages.xul +++ b/mailnews/compose/prefs/resources/content/pref-composing_messages.xul @@ -2,16 +2,22 @@ - + +%pref-composing_messagesDTD; + +%editorOverlayDTD; +]> @@ -109,6 +150,45 @@ + + + + + + + + + + diff --git a/mailnews/compose/resources/content/MsgComposeCommands.js b/mailnews/compose/resources/content/MsgComposeCommands.js index 618cb9a9338b..7731986e2a19 100644 --- a/mailnews/compose/resources/content/MsgComposeCommands.js +++ b/mailnews/compose/resources/content/MsgComposeCommands.js @@ -1103,6 +1103,11 @@ function ComposeFieldsReady(msgType) } CompFields2Recipients(gMsgCompose.compFields, gMsgCompose.type); SetComposeWindowTitle(); + + // need timeout for reply to work + if (gMsgCompose.composeHTML) + setTimeout("loadHTMLMsgPrefs();", 0); + enableEditableFields(); AdjustFocus(); } @@ -1230,8 +1235,14 @@ function ComposeStartup(recycled, aParams) document.getElementById("insertMenu").setAttribute("hidden", true); document.getElementById("menu_showFormatToolbar").setAttribute("hidden", true); } + + if (gMsgCompose.composeHTML) { + var fontsList = document.getElementById("FontFacePopup"); + initLocalFontFaceMenu(fontsList); + } + // Do setup common to Message Composer and Web Composer - EditorSharedStartup(); + EditorSharedStartup(); } var msgCompFields = gMsgCompose.compFields; @@ -1274,6 +1285,7 @@ function ComposeStartup(recycled, aParams) // Force color picker on toolbar to show document colors onFontColorChange(); onBackgroundColorChange(); + // XXX todo: reset paragraph select to "Body Text" } } else @@ -2828,3 +2840,44 @@ function SwitchElementFocus(event) SetMsgAddressingWidgetTreeElementFocus(); } } + +function loadHTMLMsgPrefs() { + var pref = GetPrefs(); + + var fontFace; + var fontSize; + var textColor; + var bgColor; + + try { + fontFace = pref.getCharPref("msgcompose.font_face"); + doStatefulCommand('cmd_fontFace', fontFace); + EditorRemoveTextProperty("font","face"); + EditorSetTextProperty("font", "face", fontFace); + } catch (e) {} + + try { + fontSize = pref.getCharPref("msgcompose.font_size"); + EditorSetFontSize(fontSize); + } catch (e) {} + + var bodyElement = GetBodyElement(); + + try { + textColor = pref.getCharPref("msgcompose.text_color"); + bodyElement.setAttribute("text", textColor); + gDefaultTextColor = textColor; + document.getElementById("cmd_fontColor").setAttribute("state", textColor); + onFontColorChange(); + } catch (e) {} + + try { + bgColor = pref.getCharPref("msgcompose.background_color"); + bodyElement.setAttribute("bgcolor", bgColor); + gDefaultBackgroundColor = bgColor; + document.getElementById("cmd_backgroundColor").setAttribute("state", bgColor); + onBackgroundColorChange(); + } catch (e) {} + +} + diff --git a/mailnews/mailnews.js b/mailnews/mailnews.js index 299e5d53b35d..b049ec7fcb52 100644 --- a/mailnews/mailnews.js +++ b/mailnews/mailnews.js @@ -509,6 +509,12 @@ pref("mailnews.fakeaccount.server", ""); pref("mailnews.message_display.disable_remote_image", false); pref("mailnews.message_display.allow.plugins", true); +// default msg compose font prefs +pref("msgcompose.font_face", ""); +pref("msgcompose.font_size", "medium"); +pref("msgcompose.text_color", "#000000"); +pref("msgcompose.background_color", "#FFFFFF"); + // When there is no disclosed recipients (only bcc), we should address the message to empty group // to prevent some mail server to disclose the bcc recipients pref("mail.compose.add_undisclosed_recipients", true); diff --git a/modules/libpref/src/init/mailnews.js b/modules/libpref/src/init/mailnews.js index 299e5d53b35d..b049ec7fcb52 100644 --- a/modules/libpref/src/init/mailnews.js +++ b/modules/libpref/src/init/mailnews.js @@ -509,6 +509,12 @@ pref("mailnews.fakeaccount.server", ""); pref("mailnews.message_display.disable_remote_image", false); pref("mailnews.message_display.allow.plugins", true); +// default msg compose font prefs +pref("msgcompose.font_face", ""); +pref("msgcompose.font_size", "medium"); +pref("msgcompose.text_color", "#000000"); +pref("msgcompose.background_color", "#FFFFFF"); + // When there is no disclosed recipients (only bcc), we should address the message to empty group // to prevent some mail server to disclose the bcc recipients pref("mail.compose.add_undisclosed_recipients", true);