From: Robert Kaiser Date: Sun, 16 Jan 2011 17:36:44 +0000 (+0100) Subject: add item to new Firefox button menu, make Firefox and SeaMonkey open Mandelbrot in... X-Git-Url: https://git-public.kairo.at/?a=commitdiff_plain;h=a79ddf52a4fc390cd21b22fbb2525590cb7d663c;p=mandelbrot.git add item to new Firefox button menu, make Firefox and SeaMonkey open Mandelbrot in tabs, improve pref handling by centralising error handling and value adjustments, make syncProp checkbox work correctly --- diff --git a/extension/fxOverlay.xul b/extension/fxOverlay.xul index 4293022..53c56ef 100644 --- a/extension/fxOverlay.xul +++ b/extension/fxOverlay.xul @@ -45,7 +45,7 @@ + oncommand="gBrowser.addTab('about:mandelbrot');"/> @@ -54,5 +54,10 @@ command="Tools:Mandelbrot" insertafter="devToolsSeparator"/> - + + + diff --git a/extension/smOverlay.xul b/extension/smOverlay.xul index 573f671..e03c8e2 100644 --- a/extension/smOverlay.xul +++ b/extension/smOverlay.xul @@ -45,14 +45,14 @@ + oncommand="getBrowser().addTab('about:mandelbrot');"/> - + + insertafter="addonsmgr"/> diff --git a/jar.mn b/jar.mn index 69628f4..31d693c 100644 --- a/jar.mn +++ b/jar.mn @@ -9,7 +9,7 @@ mandelbrot.jar: % style about:mandelbrot chrome://mandelbrot/skin/mobileUI.css application={a23983c0-fd0e-11dc-95ff-0800200c9a66} % overlay chrome://browser/content/browser.xul chrome://mandelbrot/content/fxOverlay.xul application={ec8030f7-c20a-464f-9b0e-13a3a9e97384} % overlay chrome://browser/content/browser.xul chrome://mandelbrot/content/mobileOverlay.xul application={a23983c0-fd0e-11dc-95ff-0800200c9a66} -% overlay chrome://communicator/content/tasksOverlay.xul chrome://mandelbrot/content/smOverlay.xul application={92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a} +% overlay chrome://navigator/content/navigator.xul chrome://mandelbrot/content/smOverlay.xul application={92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a} % component {289dae5f-2a1d-4632-8df9-79c50147f91f} components/aboutMandelbrot.js % contract @mozilla.org/network/protocol/about;1?what=mandelbrot {289dae5f-2a1d-4632-8df9-79c50147f91f} content/mandelbrot/mandelbrot.js (xulapp/chrome/mandelbrot/content/mandelbrot.js) diff --git a/xulapp/chrome/mandelbrot/content/mandelbrot-tab.xul b/xulapp/chrome/mandelbrot/content/mandelbrot-tab.xul index b525e10..3b61bc6 100644 --- a/xulapp/chrome/mandelbrot/content/mandelbrot-tab.xul +++ b/xulapp/chrome/mandelbrot/content/mandelbrot-tab.xul @@ -198,8 +198,8 @@ - diff --git a/xulapp/chrome/mandelbrot/content/mandelbrot.js b/xulapp/chrome/mandelbrot/content/mandelbrot.js index 0a4a31a..c2bfba2 100644 --- a/xulapp/chrome/mandelbrot/content/mandelbrot.js +++ b/xulapp/chrome/mandelbrot/content/mandelbrot.js @@ -53,25 +53,99 @@ function Startup() { document.getElementById("statusLabel").value = gMbrotBundle.getString("statusEmpty"); } -function adjustCoordsAndDraw(aC_min, aC_max) { - let iWidth = 0; - try { - iWidth = gPref.getIntPref("mandelbrot.image.width"); - } - catch (e) { } - if ((iWidth < 10) || (iWidth > 5000)) { - iWidth = 300; - gPref.setIntPref("mandelbrot.image.width", iWidth); - } - let iHeight = 0; - try { - iHeight = gPref.getIntPref("mandelbrot.image.height"); - } - catch (e) { } - if ((iHeight < 10) || (iHeight > 5000)) { - iHeight = 300; - gPref.setIntPref("mandelbrot.image.height", iHeight); +function getAdjustPref(prefname) { + let value; + switch (prefname) { + case "image.width": + case "image.height": + value = 0; + try { + value = gPref.getIntPref("mandelbrot." + prefname); + } + catch (e) { } + if ((value < 10) || (value > 5000)) { + value = 300; + gPref.setIntPref("mandelbrot." + prefname, value); + } + return value; + case "last_image.Cr_*": + let Cr_min = -2.0; + let Cr_max = 1.0; + try { + Cr_min = parseFloat(gPref.getCharPref("mandelbrot.last_image.Cr_min")); + Cr_max = parseFloat(gPref.getCharPref("mandelbrot.last_image.Cr_max")); + } + catch (e) { } + if ((Cr_min < -3) || (Cr_min > 2) || + (Cr_max < -3) || (Cr_max > 2) || (Cr_min >= Cr_max)) { + Cr_min = -2.0; Cr_max = 1.0; + } + gPref.setCharPref("mandelbrot.last_image.Cr_min", Cr_min); + gPref.setCharPref("mandelbrot.last_image.Cr_max", Cr_max); + return {Cr_min: Cr_min, Cr_max: Cr_max}; + case "last_image.Ci_*": + let Ci_min = -1.5; + let Ci_max = 1.5; + try { + Ci_min = parseFloat(gPref.getCharPref("mandelbrot.last_image.Ci_min")); + Ci_max = parseFloat(gPref.getCharPref("mandelbrot.last_image.Ci_max")); + } + catch (e) { } + if ((Ci_min < -2.5) || (Ci_min > 2.5) || + (Ci_max < -2.5) || (Ci_max > 2.5) || (Ci_min >= Ci_max)) { + Ci_min = -1.5; Ci_max = 1.5; + } + gPref.setCharPref("mandelbrot.last_image.Ci_min", Ci_min); + gPref.setCharPref("mandelbrot.last_image.Ci_max", Ci_max); + return {Ci_min: Ci_min, Ci_max: Ci_max}; + case "iteration_max": + value = 500; + try { + value = gPref.getIntPref("mandelbrot." + prefname); + } + catch (e) { + setIter(value); + } + if (value < 10 || value > 10000) { + value = 500; + setIter(value); + } + return value; + case "use_algorithm": + value = "numeric"; + try { + value = gPref.getCharPref("mandelbrot." + prefname); + } + catch (e) { + setAlgorithm(value); + } + return value; + case "color_palette": + value = "kairo"; + try { + value = gPref.getCharPref("mandelbrot." + prefname); + } + catch(e) { + setPalette(value); + } + return value; + case "syncProportions": + value = true; + try { + value = gPref.getBoolPref("mandelbrot." + prefname); + } + catch(e) { + gPref.setBoolPref("mandelbrot." + prefname, value); + } + return value; + default: + return false; } +} + +function adjustCoordsAndDraw(aC_min, aC_max) { + let iWidth = getAdjustPref("image.width"); + let iHeight = getAdjustPref("image.height"); // correct coordinates if (aC_min.r < -2) @@ -111,55 +185,19 @@ function drawImage() { document.getElementById("statusLabel").value = gMbrotBundle.getString("statusDrawing"); - let Cr_min = -2.0; - let Cr_max = 1.0; - try { - Cr_min = parseFloat(gPref.getCharPref("mandelbrot.last_image.Cr_min")); - Cr_max = parseFloat(gPref.getCharPref("mandelbrot.last_image.Cr_max")); - } - catch (e) { } - if ((Cr_min < -3) || (Cr_min > 2) || - (Cr_max < -3) || (Cr_max > 2) || (Cr_min >= Cr_max)) { - Cr_min = -2.0; Cr_max = 1.0; - } - gPref.setCharPref("mandelbrot.last_image.Cr_min", Cr_min); - gPref.setCharPref("mandelbrot.last_image.Cr_max", Cr_max); + let Cr_vals = getAdjustPref("last_image.Cr_*"); + let Cr_min = Cr_vals.Cr_min; + let Cr_max = Cr_vals.Cr_max; - let Ci_min = -1.5; - let Ci_max = 1.5; - try { - Ci_min = parseFloat(gPref.getCharPref("mandelbrot.last_image.Ci_min")); - Ci_max = parseFloat(gPref.getCharPref("mandelbrot.last_image.Ci_max")); - } - catch (e) { } - if ((Ci_min < -2.5) || (Ci_min > 2.5) || - (Ci_max < -2.5) || (Ci_max > 2.5) || (Ci_min >= Ci_max)) { - Ci_min = -1.5; Ci_max = 1.5; - } - gPref.setCharPref("mandelbrot.last_image.Ci_min", Ci_min); - gPref.setCharPref("mandelbrot.last_image.Ci_max", Ci_max); + let Ci_vals = getAdjustPref("last_image.Ci_*"); + let Ci_min = Ci_vals.Ci_min; + let Ci_max = Ci_vals.Ci_max; - let iterMax = gPref.getIntPref("mandelbrot.iteration_max"); - let algorithm = gPref.getCharPref("mandelbrot.use_algorithm"); + let iterMax = getAdjustPref("iteration_max"); + let algorithm = getAdjustPref("use_algorithm"); - let iWidth = 0; - try { - iWidth = gPref.getIntPref("mandelbrot.image.width"); - } - catch (e) { } - if ((iWidth < 10) || (iWidth > 5000)) { - iWidth = 300; - gPref.setIntPref("mandelbrot.image.width", iWidth); - } - let iHeight = 0; - try { - iHeight = gPref.getIntPref("mandelbrot.image.height"); - } - catch (e) { } - if ((iHeight < 10) || (iHeight > 5000)) { - iHeight = 300; - gPref.setIntPref("mandelbrot.image.height", iHeight); - } + let iWidth = getAdjustPref("image.width"); + let iHeight = getAdjustPref("image.height"); gCurrentImageData = { C_min: new complex(Cr_min, Ci_min), @@ -617,15 +655,7 @@ function saveBookmark() { } function updateIterMenu() { - let currentIter = 0; - try { - currentIter = gPref.getIntPref("mandelbrot.iteration_max"); - } - catch(e) { } - if (currentIter < 10) { - currentIter = 500; - setIter(currentIter); - } + let currentIter = getAdjustPref("iteration_max"); let popup = document.getElementById("menu_iterPopup"); let item = popup.firstChild; @@ -645,15 +675,7 @@ function setIter(aIter) { } function updatePaletteMenu() { - let currentPalette = ''; - try { - currentPalette = gPref.getCharPref("mandelbrot.color_palette"); - } - catch(e) { } - if (!currentPalette.length) { - currentPalette = 'kairo'; - setPalette(currentPalette); - } + let currentPalette = getAdjustPref("color_palette"); if (!gColorPalette || !gColorPalette.length) gColorPalette = getColorPalette(currentPalette); @@ -705,15 +727,7 @@ function toggleJITState(jitMenuItem, jittype) { } function updateAlgoMenu() { - let currentAlgo = ''; - try { - currentAlgo = gPref.getCharPref("mandelbrot.use_algorithm"); - } - catch(e) { } - if (!currentAlgo.length) { - currentAlgo = 'numeric'; - setAlgorithm(currentAlgo); - } + let currentAlgo = getAdjustPref("use_algorithm"); let popup = document.getElementById("menu_algoPopup"); let item = popup.firstChild; @@ -757,16 +771,15 @@ function errorConsole() { function initImgSettings() { // Get values from prefs. - for each (let coord in ["Cr_min", "Cr_max", "Ci_min", "Ci_max"]) { - document.getElementById("is_" + coord).value = - roundCoord(parseFloat(gPref.getCharPref("mandelbrot.last_image." + coord))); + for each (let coord in ["Cr", "Ci"]) { + let coord_vals = getAdjustPref("last_image." + coord + "_*"); + document.getElementById("is_" + coord + "_min").value = coord_vals[coord + "_min"]; + document.getElementById("is_" + coord + "_max").value = coord_vals[coord + "_max"]; } for each (let dim in ["width", "height"]) { - document.getElementById("is_img_" + dim).value = - gPref.getIntPref("mandelbrot.image." + dim); + document.getElementById("is_img_" + dim).value = getAdjustPref("image." + dim); } - document.getElementById("is_syncProp").checked = - gPref.getBoolPref("mandelbrot.syncProportions"); + document.getElementById("is_syncProp").checked = getAdjustPref("syncProportions"); // Calculate scales. recalcCoord("Cr", "scale"); @@ -840,21 +853,13 @@ function drawPreview() { Ci_min = -2.0; Ci_max = 1.0; } - let iterMax = gPref.getIntPref("mandelbrot.iteration_max"); - let algorithm = gPref.getCharPref("mandelbrot.use_algorithm"); + let iterMax = getAdjustPref("iteration_max"); + let algorithm = getAdjustPref("use_algorithm"); context.fillStyle = "rgba(255, 255, 255, 127)"; context.fillRect(0, 0, canvas.width, canvas.height); - try { - var currentPalette = gPref.getCharPref("mandelbrot.color_palette"); - } - catch(e) { - var currentPalette = ""; - } - if (!currentPalette.length) { - currentPalette = "kairo"; - } + let currentPalette = getAdjustPref("color_palette"); gColorPalette = getColorPalette(currentPalette); drawLine(0, [Cr_min, Cr_max, Ci_min, Ci_max], diff --git a/xulapp/chrome/mandelbrot/content/mandelbrot.xul b/xulapp/chrome/mandelbrot/content/mandelbrot.xul index a9cb1e4..cbf7c6d 100644 --- a/xulapp/chrome/mandelbrot/content/mandelbrot.xul +++ b/xulapp/chrome/mandelbrot/content/mandelbrot.xul @@ -187,8 +187,8 @@ - diff --git a/xulapp/chrome/mandelbrot/skin/classic/mandelbrot.css b/xulapp/chrome/mandelbrot/skin/classic/mandelbrot.css index a287ac5..28f6ee4 100644 --- a/xulapp/chrome/mandelbrot/skin/classic/mandelbrot.css +++ b/xulapp/chrome/mandelbrot/skin/classic/mandelbrot.css @@ -42,7 +42,7 @@ html|link { display: none; } -#tasksMenuMandelbrot, #menu_openMandelbrot { +#tasksMenuMandelbrot, #menu_openMandelbrot, #appmenu_openMandelbrot { list-style-image: url("chrome://mandelbrot/skin/mandelbrotIcon16.png"); }