+function updateIterMenu() {
+ let currentIter = 0;
+ try {
+ currentIter = gPref.getIntPref("mandelbrot.iteration_max");
+ }
+ catch(e) { }
+ if (currentIter < 10) {
+ currentIter = 500;
+ setIter(currentIter);
+ }
+
+ let popup = document.getElementById("menu_iterPopup");
+ let item = popup.firstChild;
+ while (item) {
+ if (item.getAttribute("name") == "iter") {
+ if (item.getAttribute("value") == currentIter)
+ item.setAttribute("checked","true");
+ else
+ item.removeAttribute("checked");
+ }
+ item = item.nextSibling;
+ }
+}
+
+function setIter(aIter) {
+ gPref.setIntPref("mandelbrot.iteration_max", aIter);
+}
+
+function updatePaletteMenu() {
+ let currentPalette = '';
+ try {
+ currentPalette = gPref.getCharPref("mandelbrot.color_palette");
+ }
+ catch(e) { }
+ if (!currentPalette.length) {
+ currentPalette = 'kairo';
+ setPalette(currentPalette);
+ }
+ if (!gColorPalette || !gColorPalette.length)
+ gColorPalette = getColorPalette(currentPalette);
+
+ let popup = document.getElementById("menu_palettePopup");
+ let item = popup.firstChild;
+ while (item) {
+ if (item.getAttribute("name") == "palette") {
+ if (item.getAttribute("value") == currentPalette)
+ item.setAttribute("checked", "true");
+ else
+ item.removeAttribute("checked");
+ }
+ item = item.nextSibling;
+ }
+}
+
+function setPalette(aPaletteID) {
+ gPref.setCharPref("mandelbrot.color_palette", aPaletteID);
+ gColorPalette = getColorPalette(aPaletteID);
+}
+
+function imgSettings() {
+ window.openDialog("chrome://mandelbrot/content/image-settings.xul");
+}
+
+function updateDebugMenu() {
+ let scope = (document.getElementById("mandelbrotWindow").nodeName == "page") ? "content" : "chrome";
+ for each (let type in ["tracejit", "methodjit"]) {
+ let jitMenuItem = document.getElementById(type + "Enabled");
+ jitMenuItem.setAttribute("checked", gPref.getBoolPref("javascript.options." + type + "." + scope));
+ }
+}
+
+function toggleJITState(jitMenuItem, jittype) {
+ let scope = (document.getElementById("mandelbrotWindow").nodeName == "page") ? "content" : "chrome";
+ let jitpref = "javascript.options." + jittype + "jit." + scope;
+ let jitEnabled = !gPref.getBoolPref(jitpref);
+ gPref.setBoolPref(jitpref, jitEnabled)
+ jitMenuItem.setAttribute("checked", jitEnabled ? "true" : "false");
+}
+
+function updateAlgoMenu() {
+ let currentAlgo = '';
+ try {
+ currentAlgo = gPref.getCharPref("mandelbrot.use_algorithm");
+ }
+ catch(e) { }
+ if (!currentAlgo.length) {
+ currentAlgo = 'numeric';
+ setAlgorithm(currentAlgo);
+ }
+
+ let popup = document.getElementById("menu_algoPopup");
+ let item = popup.firstChild;
+ while (item) {
+ if (item.getAttribute("name") == "algorithm") {
+ if (item.getAttribute("value") == currentAlgo)
+ item.setAttribute("checked", "true");
+ else
+ item.removeAttribute("checked");
+ }
+ item = item.nextSibling;
+ }
+}
+
+function setAlgorithm(algoID) {
+ gPref.setCharPref("mandelbrot.use_algorithm", algoID);
+}
+
+function addonsManager(aPane) {
+ let theEM = Components.classes["@mozilla.org/appshell/window-mediator;1"]
+ .getService(Components.interfaces.nsIWindowMediator)
+ .getMostRecentWindow("Extension:Manager");
+ if (theEM) {
+ theEM.focus();
+ if (aPane)
+ theEM.showView(aPane);
+ return;
+ }
+
+ const EMURL = "chrome://mozapps/content/extensions/extensions.xul";
+ const EMFEATURES = "all,dialog=no";
+ if (aPane)
+ window.openDialog(EMURL, "", EMFEATURES, aPane);
+ else
+ window.openDialog(EMURL, "", EMFEATURES);
+}
+
+function errorConsole() {
+ toOpenWindowByType("global:console", "chrome://global/content/console.xul");
+}
+
+/***** helper functions from external sources *****/
+
+// function below is based on http://developer.mozilla.org/en/docs/Code_snippets:Canvas
+// custom modifications:
+// - use "a"-prefix on function arguments
+// - take an nsILocalFile as aDestFile argument
+// - always do silent download
+function saveCanvas(aCanvas, aDestFile) {