diff --git a/extensions/irc/xul/content/commands.js b/extensions/irc/xul/content/commands.js index 8882afc34108..4569d0d5c1df 100644 --- a/extensions/irc/xul/content/commands.js +++ b/extensions/irc/xul/content/commands.js @@ -73,6 +73,10 @@ function initCommands() ["enable-plugin", cmdAblePlugin, CMD_CONSOLE], ["eval", cmdEval, CMD_CONSOLE], ["focus-input", cmdFocusInput, CMD_CONSOLE], + ["font-family", cmdFont, CMD_CONSOLE], + ["font-family-other", cmdFont, 0], + ["font-size", cmdFont, CMD_CONSOLE], + ["font-size-other", cmdFont, 0], ["goto-url", cmdGotoURL, 0], ["goto-url-newwin", cmdGotoURL, 0], ["goto-url-newtab", cmdGotoURL, 0], @@ -113,6 +117,7 @@ function initCommands() ["squery", cmdSquery, CMD_NEED_SRV | CMD_CONSOLE], ["stalk", cmdStalk, CMD_CONSOLE], ["supports", cmdSupports, CMD_NEED_SRV | CMD_CONSOLE], + ["sync-fonts", cmdSync, 0], ["sync-headers", cmdSync, 0], ["sync-logs", cmdSync, 0], ["sync-motifs", cmdSync, 0], @@ -143,6 +148,20 @@ function initCommands() ["name", "pref username", CMD_CONSOLE], ["part", "leave", CMD_CONSOLE], ["j", "join", CMD_CONSOLE], + // These are all the font family/size menu commands... + ["font-family-default", "font-family default", 0], + ["font-family-serif", "font-family serif", 0], + ["font-family-sans-serif", "font-family sans-serif", 0], + ["font-family-monospace", "font-family monospace", 0], + ["font-size-default", "font-size default", 0], + ["font-size-small", "font-size small", 0], + ["font-size-medium", "font-size medium", 0], + ["font-size-large", "font-size large", 0], + ["font-size-bigger", "font-size bigger", 0], + // This next command is not visible; it maps to Ctrl-=, which is what + // you get when the user tries to do Ctrl-+ (previous command's key). + ["font-size-bigger2", "font-size bigger", 0], + ["font-size-smaller", "font-size smaller", 0], ["toggle-oas", "open-at-startup toggle", 0], ["toggle-ccm", "toggle-pref collapseMsgs", 0], ["toggle-copy", "toggle-pref copyMessages", 0], @@ -169,7 +188,7 @@ function initCommands() client.commandManager.defineCommands(cmdary); client.commandManager.argTypes.__aliasTypes__(["reason", "action", "text", - "message", "params", + "message", "params", "font", "reason", "expression", "ircCommand", "prefValue", "newTopic", "commandList"], @@ -637,6 +656,18 @@ function cmdSync(e) switch (e.command.name) { + case "sync-fonts": + fun = function () + { + if (view.prefs["displayHeader"]) + view.setHeaderState(false); + view.changeCSS(view.getFontCSS("data"), + "cz-fonts"); + if (view.prefs["displayHeader"]) + view.setHeaderState(true); + }; + break; + case "sync-headers": fun = function () { @@ -2227,3 +2258,93 @@ function cmdIgnore(e) display(getMsg(MSG_IGNORE_LIST_2, arraySpeak(list))); } } + +function cmdFont(e) +{ + var view = client; + var pref, val, pVal; + + if (e.command.name == "font-family") + { + pref = "font.family"; + val = e.font; + + // Save new value, then display pref value. + if (val) + view.prefs[pref] = val; + + display(getMsg(MSG_FONTS_FAMILY_FMT, view.prefs[pref])); + } + else if (e.command.name == "font-size") + { + pref = "font.size"; + val = e.fontSize; + + // Ok, we've got an input. + if (val) + { + // Get the current value, use user's default if needed. + pVal = view.prefs[pref]; + if (pVal == 0) + pVal = getDefaultFontSize(); + + // Handle user's input... + switch(val) { + case "default": + val = 0; + break; + + case "small": + val = getDefaultFontSize() - 2; + break; + + case "medium": + val = getDefaultFontSize(); + break; + + case "large": + val = getDefaultFontSize() + 2; + break; + + case "smaller": + val = pVal - 2; + break; + + case "bigger": + val = pVal + 2; + break; + + default: + val = Number(val); + } + // Save the new value. + view.prefs[pref] = val; + } + + // Show the user what the pref is set to. + if (view.prefs[pref] == 0) + display(MSG_FONTS_SIZE_DEFAULT); + else + display(getMsg(MSG_FONTS_SIZE_FMT, view.prefs[pref])); + } + else if (e.command.name == "font-family-other") + { + val = prompt(MSG_FONTS_FAMILY_PICK, view.prefs["font.family"]); + if (!val) + return; + + dispatch("font-family", { font: val }); + } + else if (e.command.name == "font-size-other") + { + pVal = view.prefs["font.size"]; + if (pVal == 0) + pVal = getDefaultFontSize(); + + val = prompt(MSG_FONTS_SIZE_PICK, pVal); + if (!val) + return; + + dispatch("font-size", { fontSize: val }); + } +} diff --git a/extensions/irc/xul/content/menus.js b/extensions/irc/xul/content/menus.js index 183916512c1b..2c119be6bffc 100644 --- a/extensions/irc/xul/content/menus.js +++ b/extensions/irc/xul/content/menus.js @@ -40,6 +40,31 @@ function initMenus() return "client.prefs['motif.current'] == " + "client.prefs['motif." + name + "']"; }; + + function isFontFamily(name) + { + return "cx.sourceObject.prefs['font.family'] == '" + name + "'"; + }; + + function isFontFamilyCustom() + { + return "!cx.sourceObject.prefs['font.family']." + + "match(/^(default|(sans-)?serif|monospace)$/)"; + }; + + function isFontSize(size) + { + return "cx.fontSize == cx.fontSizeDefault + " + size; + }; + + function isFontSizeCustom() + { + // It's "custom" if it's set (non-zero/not default), not the default + // size (medium) and not +/-2 (small/large). + return "'fontSize' in cx && cx.fontSize != 0 && " + + "cx.fontSizeDefault != cx.fontSize && " + + "Math.abs((cx.fontSizeDefault - cx.fontSize) / 2) != 1"; + }; function onMenuCommand (event, window) { @@ -124,6 +149,7 @@ function initMenus() ["leave", {visibleif: "cx.channel && cx.channel.active"}], ["-"], [">popup:motifs"], + [">popup:fonts"], ["toggle-ccm", {type: "checkbox", checkedif: "client.prefs['collapseMsgs']"}], @@ -167,6 +193,38 @@ function initMenus() ] }; + client.menuSpecs["popup:fonts"] = { + label: MSG_MNU_FONTS, + getContext: getFontContext, + items: + [ + ["font-size-bigger", {}], + ["font-size-smaller", {}], + ["-"], + ["font-size-default", + {type: "checkbox", checkedif: "!cx.fontSize"}], + ["font-size-small", + {type: "checkbox", checkedif: isFontSize(-2)}], + ["font-size-medium", + {type: "checkbox", checkedif: isFontSize(0)}], + ["font-size-large", + {type: "checkbox", checkedif: isFontSize(+2)}], + ["font-size-other", + {type: "checkbox", checkedif: isFontSizeCustom()}], + ["-"], + ["font-family-default", + {type: "checkbox", checkedif: isFontFamily("default")}], + ["font-family-serif", + {type: "checkbox", checkedif: isFontFamily("serif")}], + ["font-family-sans-serif", + {type: "checkbox", checkedif: isFontFamily("sans-serif")}], + ["font-family-monospace", + {type: "checkbox", checkedif: isFontFamily("monospace")}], + ["font-family-other", + {type: "checkbox", checkedif: isFontFamilyCustom()}] + ] + }; + var isopish = "(cx.channel.iAmOp() || cx.channel.iAmHalfOp())"; client.menuSpecs["popup:opcommands"] = { diff --git a/extensions/irc/xul/content/prefs.js b/extensions/irc/xul/content/prefs.js index 4afe18f6e4d2..d967d21d1959 100644 --- a/extensions/irc/xul/content/prefs.js +++ b/extensions/irc/xul/content/prefs.js @@ -89,6 +89,8 @@ function initPrefs() ["deleteOnPart", true], ["displayHeader", true], ["guessCommands", true], + ["font.family", "lucida, sans-serif"], + ["font.size", 0], ["initialURLs", []], ["initialScripts", [getURLSpecFromFile(scriptPath.path)]], ["log", false], @@ -189,6 +191,8 @@ function getNetworkPrefManager(network) ["connectTries", defer], ["desc", defer], ["displayHeader", client.prefs["networkHeader"]], + ["font.family", defer], + ["font.size", defer], ["log", client.prefs["networkLog"]], ["logFileName", logDefault.path], ["motif.current", defer], @@ -259,6 +263,8 @@ function getChannelPrefManager(channel) ["charset", defer], ["collapseMsgs", defer], ["displayHeader", client.prefs["channelHeader"]], + ["font.family", defer], + ["font.size", defer], ["log", client.prefs["channelLog"]], ["logFileName", logDefault.path], ["motif.current", defer], @@ -302,6 +308,8 @@ function getUserPrefManager(user) ["charset", defer], ["collapseMsgs", defer], ["displayHeader", client.prefs["userHeader"]], + ["font.family", defer], + ["font.size", defer], ["motif.current", defer], ["outputWindowURL", defer], ["log", client.prefs["userLog"]], @@ -350,6 +358,11 @@ function onPrefChanged(prefName, newValue, oldValue) CIRCNetwork.prototype.MAX_CONNECT_ATTEMPTS = newValue; break; + case "font.family": + case "font.size": + dispatch("sync-fonts"); + break; + case "showModeSymbols": if (newValue) setListMode("symbol"); @@ -467,6 +480,11 @@ function onNetworkPrefChanged(network, prefName, newValue, oldValue) network.stayingPower = newValue; break; + case "font.family": + case "font.size": + dispatch("sync-fonts"); + break; + case "motif.current": dispatch("sync-motifs"); break; @@ -511,8 +529,14 @@ function onChannelPrefChanged(channel, prefName, newValue, oldValue) switch (prefName) { + case "font.family": + case "font.size": + dispatch("sync-fonts"); + break; + case "motif.current": dispatch("sync-motifs"); + break; case "outputWindowURL": dispatch("sync-windows"); @@ -550,8 +574,14 @@ function onUserPrefChanged(user, prefName, newValue, oldValue) switch (prefName) { + case "font.family": + case "font.size": + dispatch("sync-fonts"); + break; + case "motif.current": dispatch("sync-motifs"); + break; case "outputWindowURL": dispatch("sync-windows"); diff --git a/extensions/irc/xul/content/static.js b/extensions/irc/xul/content/static.js index 1472ee782870..6893eb909afc 100644 --- a/extensions/irc/xul/content/static.js +++ b/extensions/irc/xul/content/static.js @@ -34,7 +34,7 @@ * Samuel Sieb, samuel@sieb.net, MIRC color codes, munger menu, and various */ -const __cz_version = "0.9.58"; +const __cz_version = "0.9.59"; const __cz_condition = "green"; var warn; @@ -812,6 +812,35 @@ function updateStalkExpression(network) network.stalkExpression = new RegExp(re, "i"); } +function getDefaultFontSize() +{ + const PREF_CTRID = "@mozilla.org/preferences-service;1"; + const nsIPrefService = Components.interfaces.nsIPrefService; + const nsIPrefBranch = Components.interfaces.nsIPrefBranch; + + var prefService = + Components.classes[PREF_CTRID].getService(nsIPrefService); + var prefBranch = prefService.getBranch(null); + + // PX size pref: font.size.variable.x-western + var pxSize = 16; + try + { + pxSize = prefBranch.getIntPref("font.size.variable.x-western"); + } + catch(ex) { } + + // DPI pref : browser.display.screen_resolution + var dpi = 96; + try + { + dpi = prefBranch.getIntPref("browser.display.screen_resolution"); + } + catch(ex) { } + + return Math.round((pxSize / dpi) * 72); +} + function getDefaultContext(cx) { return getObjectDetails(client.currentObject, cx); @@ -915,6 +944,26 @@ function getUserlistContext(cx) return cx; } +function getFontContext(cx) +{ + cx = getObjectDetails(client.currentObject, cx); + cx.fontSizeDefault = getDefaultFontSize(); + var view = client; + + if ("prefs" in cx.sourceObject) + { + cx.fontFamily = view.prefs["font.family"]; + if (cx.fontFamily.match(/^(default|(sans-)?serif|monospace)$/)) + delete cx.fontFamily; + + cx.fontSize = view.prefs["font.size"]; + if (cx.fontSize == 0) + delete cx.fontSize; + } + + return cx; +} + function msgIsImportant (msg, sourceNick, network) { var re = network.stalkExpression; @@ -2071,6 +2120,8 @@ function client_statechange (webProgress, request, stateFlags, status) cwin.initOutputWindow(client, frame.source, onMessageViewClick); cwin.changeCSS(frame.source.getTimestampCSS("data"), "cz-timestamp-format"); + cwin.changeCSS(frame.source.getFontCSS("data"), + "cz-fonts"); scrollDown(frame, true); webProgress.removeProgressListener(this); } @@ -2636,6 +2687,33 @@ function this_getTimestampCSS(format) return css; } +client.getFontCSS = +CIRCNetwork.prototype.getFontCSS = +CIRCChannel.prototype.getFontCSS = +CIRCUser.prototype.getFontCSS = +function this_getFontCSS(format) +{ + /* See this_getTimestampCSS. */ + var css; + var fs; + var fn; + + if (this.prefs["font.family"] != "default") + fn = "font-family: " + this.prefs["font.family"] + ";"; + else + fn = "font-family: inherit;"; + if (this.prefs["font.size"] != 0) + fs = "font-size: " + this.prefs["font.size"] + "pt;"; + else + fs = "font-size: medium;"; + + css = "body.chatzilla-body { " + fs + fn + " }"; + + if (format == "data") + return "data:text/css," + encodeURIComponent(css); + return css; +} + client.display = client.displayHere = CIRCNetwork.prototype.displayHere = diff --git a/extensions/irc/xul/locale/en-US/chatzilla.properties b/extensions/irc/xul/locale/en-US/chatzilla.properties index 7560c371b29d..2c386a1ff9bc 100644 --- a/extensions/irc/xul/locale/en-US/chatzilla.properties +++ b/extensions/irc/xul/locale/en-US/chatzilla.properties @@ -90,11 +90,12 @@ cmd.cmd-copy-link-url.help = Copies the URL of the current link to clipboard. cmd.commands.params = [] cmd.commands.help = Lists all command names matching , or all command names if pattern is not specified. -cmd.sync-motifs.help = Syncronizes all views with their current motif setting. -cmd.sync-logs.help = Syncronizes all views with their current logging setting. -cmd.sync-windows.help = Syncronizes all views with their current output window setting. -cmd.sync-headers.help = Syncronizes all views with their current header display setting. +cmd.sync-fonts.help = Syncronizes all views with their current font settings. +cmd.sync-headers.help = Syncronizes all views with their current header display setting. +cmd.sync-logs.help = Syncronizes all views with their current logging setting. +cmd.sync-motifs.help = Syncronizes all views with their current motif setting. cmd.sync-timestamps.help = Syncronizes all views with their current timestamp display settings. +cmd.sync-windows.help = Syncronizes all views with their current output window setting. cmd.ctcp.params = [] cmd.ctcp.help = Sends the CTCP code to the target (user or channel) . If are specified they are sent along as well. @@ -143,6 +144,37 @@ cmd.exit.help = Disconnects from all active servers and networks, providing t cmd.focus-input.key = VK_ESCAPE cmd.focus-input.help = Force keyboard focus to the input box. +cmd.font-family.params = [] +cmd.font-family.help = Sets or views the font family being used on the current view. Ommit to see the current font family. The value |default| will use your global font family, |serif|, |sans-serif| and |monospace| will use your global font settings, other values will set a font directly. + +cmd.font-family-default.label = Default &Font +cmd.font-family-serif.label = Se&rif +cmd.font-family-sans-serif.label = S&ans Serif +cmd.font-family-monospace.label = Mo&nospace + +cmd.font-family-other.format = Other ($fontFamily)... +cmd.font-family-other.label = O&ther... +cmd.font-family-other.help = Prompts for a font family name. + +cmd.font-size.params = [] +cmd.font-size.help = Sets or views the font size being used on the current view. Ommit to see the current font size. The size value is specified in points (pt). The value |default| will use your global font size, and the values |bigger| and |smaller| increase or reduce the size by a fixed amount each time. + +cmd.font-size-bigger.label = Make Text &Bigger +cmd.font-size-bigger.key = accel + +cmd.font-size-bigger2.key = accel = +cmd.font-size-smaller.label = Make Text &Smaller +cmd.font-size-smaller.key = accel - + +cmd.font-size-default.label = Default Si&ze +cmd.font-size-default.key = accel 0 +cmd.font-size-small.label = Sma&ll +cmd.font-size-medium.label = &Medium +cmd.font-size-large.label = Lar&ge + +cmd.font-size-other.format = Other ($fontSize pt)... +cmd.font-size-other.label = &Other... +cmd.font-size-other.help = Prompts for a font size. + cmd.goto-url.label = Open Link cmd.goto-url.params = cmd.goto-url.help = Navigate to the url specified by . If the is not an irc: url, it will be opened in the most recent browser window. @@ -499,6 +531,7 @@ msg.mnu.help = &Help msg.mnu.view = &View msg.mnu.motifs = Co&lor Scheme msg.mnu.opcommands = &Operator Commands +msg.mnu.fonts = &Font Family and Size msg.client.name = *client* msg.cant.disable = Plugin %S does not support being disabled. @@ -682,6 +715,12 @@ msg.someone.quit = %S has left %S (%S) msg.unknown.ctcp = Unknown CTCP %S (%S) from %S +msg.fonts.family.fmt = Font family is ``%S''. +msg.fonts.family.pick = Enter the font family you wish to use: +msg.fonts.size.fmt = Font size is %Spt. +msg.fonts.size.default = Font size is default. +msg.fonts.size.pick = Enter the font size you wish to use: + msg.supports.chanTypes = Supported channel types: %S. msg.supports.chanModesA = Supported channel modes (A: lists): %S. msg.supports.chanModesB = Supported channel modes (B: param): %S.