X-Git-Url: https://git-public.kairo.at/?p=mandelbrot.git;a=blobdiff_plain;f=xulapp%2Fchrome%2Fmandelbrot%2Fcontent%2Fmandelbrot.js;h=28b443c1d50c1dd581a148eb4ddd6833c02e651f;hp=8bce0da87e16d65efa77403155e03db3bdea07da;hb=fa4ecb249ee06df34c4604172d81084f4111e766;hpb=287a980b69cc2ab6bba1159822b42eb033c70efd diff --git a/xulapp/chrome/mandelbrot/content/mandelbrot.js b/xulapp/chrome/mandelbrot/content/mandelbrot.js index 8bce0da..28b443c 100644 --- a/xulapp/chrome/mandelbrot/content/mandelbrot.js +++ b/xulapp/chrome/mandelbrot/content/mandelbrot.js @@ -40,12 +40,13 @@ var gPref = Components.classes["@mozilla.org/preferences-service;1"] .getService(Components.interfaces.nsIPrefService) .getBranch(null); var gStartTime = 0; +var gMbrotBundle; function Startup() { updateIterMenu(); updatePaletteMenu(); - document.getElementById("statusLabel").value = - document.getElementById("mbrotBundle").getString("statusEmpty"); + gMbrotBundle = document.getElementById("mbrotBundle"); + document.getElementById("statusLabel").value = gMbrotBundle.getString("statusEmpty"); } function drawImage() { @@ -54,8 +55,7 @@ function drawImage() { document.getElementById("drawButton").hidden = true; - document.getElementById("statusLabel").value = - document.getElementById("mbrotBundle").getString("statusDrawing"); + document.getElementById("statusLabel").value = gMbrotBundle.getString("statusDrawing"); let Cr_min = -2.0; let Cr_max = 1.0; @@ -147,7 +147,7 @@ function EndCalc() { let endTime = new Date(); let timeUsed = (endTime.getTime() - gStartTime.getTime()) / 1000; document.getElementById("statusLabel").value = - document.getElementById("mbrotBundle").getFormattedString("statusTime", [timeUsed.toFixed(3)]); + gMbrotBundle.getFormattedString("statusTime", [timeUsed.toFixed(3)]); gStartTime = 0; } @@ -348,17 +348,22 @@ function mouseevent(etype, event) { y: event.clientY - canvas.offsetTop}; break; case 'up': - if (event.button == 0) - alert(zoomstart.x + ',' + zoomstart.y + '-' + - (event.clientX - canvas.offsetLeft) + ',' + - (event.clientY - canvas.offsetTop)); + if (event.button == 0) { + var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] + .getService(Components.interfaces.nsIPromptService); + var ok = prompts.confirm(null, gMbrotBundle.getString("zoomConfirmTitle"), + gMbrotBundle.getString("zoomConfirmLabel") + ' --- ' + + zoomstart.x + ',' + zoomstart.y + '-' + + (event.clientX - canvas.offsetLeft) + ',' + + (event.clientY - canvas.offsetTop)); + // ok is now true if OK was clicked, and false if cancel was clicked + } zoomstart = undefined; break; } } function saveImage() { - const bundle = document.getElementById("mbrotBundle"); const nsIFilePicker = Components.interfaces.nsIFilePicker; var fp = null; try { @@ -366,9 +371,9 @@ function saveImage() { .createInstance(nsIFilePicker); } catch (e) {} if (!fp) return; - var promptString = bundle.getString("savePrompt"); + var promptString = gMbrotBundle.getString("savePrompt"); fp.init(window, promptString, nsIFilePicker.modeSave); - fp.appendFilter(bundle.getString("pngFilterName"), "*.png"); + fp.appendFilter(gMbrotBundle.getString("pngFilterName"), "*.png"); fp.defaultString = "mandelbrot.png"; var fpResult = fp.show(); @@ -410,8 +415,7 @@ function updateBookmarkMenu(aParent) { } // Create the "Nothing Available" Menu item and disable it. var na = aParent.appendChild(document.createElement("menuitem")); - na.setAttribute("label", - document.getElementById("mbrotBundle").getString("noBookmarks")); + na.setAttribute("label", gMbrotBundle.getString("noBookmarks")); na.setAttribute("disabled", "true"); } @@ -419,8 +423,16 @@ function callBookmark(evtarget) { } function saveBookmark() { - // XXX: retrieve wanted bookmark name - var bmName = "mandelbrot bm test"; + // retrieve wanted bookmark name with a prompt + var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] + .getService(Components.interfaces.nsIPromptService); + var input = {value: ""}; // empty default value + var ok = prompts.prompt(null, gMbrotBundle.getString("saveBookmarkTitle"), gMbrotBundle.getString("saveBookmarkLabel"), input, null, {}); + // ok is true if OK is pressed, false if Cancel. input.value holds the value of the edit field if "OK" was pressed. + if (!ok || !input.value) + return + + var bmName = input.value; // Open or create the bookmarks database. var file = Components.classes["@mozilla.org/file/directory_service;1"]