From cad54f7433f48a016f3ebc8ae37a6fe75090bcfb Mon Sep 17 00:00:00 2001 From: Nathan Dinsmore Date: Sun, 21 Apr 2013 13:53:39 -0400 Subject: Fixed #23 Only one of each kind of dialog can now be open at any given time. You can still open multiple dialogs for editing a costume and editing a block. --- widgets.js | 68 ++++++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 49 insertions(+), 19 deletions(-) (limited to 'widgets.js') diff --git a/widgets.js b/widgets.js index c779f69..0f39d63 100644 --- a/widgets.js +++ b/widgets.js @@ -1475,6 +1475,11 @@ DialogBoxMorph.prototype.inform = function ( new Point(1, 1), new Color(255, 255, 255) ); + + if (!this.key) { + this.key = 'information'; + } + this.labelString = title; this.createLabel(); if (pic) {this.setPicture(pic); } @@ -1484,11 +1489,7 @@ DialogBoxMorph.prototype.inform = function ( this.addButton('ok', 'OK'); this.drawNew(); this.fixLayout(); - if (world) { - world.add(this); - world.keyboardReceiver = this; - this.setCenter(world.center()); - } + this.popUp(world); }; DialogBoxMorph.prototype.askYesNo = function ( @@ -1509,6 +1510,11 @@ DialogBoxMorph.prototype.askYesNo = function ( new Point(1, 1), new Color(255, 255, 255) ); + + if (!this.key) { + this.key = 'prompt'; + } + this.labelString = title; this.createLabel(); if (pic) {this.setPicture(pic); } @@ -1518,11 +1524,7 @@ DialogBoxMorph.prototype.askYesNo = function ( this.fixLayout(); this.drawNew(); this.fixLayout(); - if (world) { - world.add(this); - world.keyboardReceiver = this; - this.setCenter(world.center()); - } + this.popUp(world); }; DialogBoxMorph.prototype.prompt = function ( @@ -1612,6 +1614,10 @@ DialogBoxMorph.prototype.prompt = function ( this.labelString = title; this.createLabel(); + if (!this.key) { + this.key = 'prompt'; + } + this.addBody(txt); txt.drawNew(); this.addButton('ok', 'OK'); @@ -1619,11 +1625,7 @@ DialogBoxMorph.prototype.prompt = function ( this.fixLayout(); this.drawNew(); this.fixLayout(); - if (world) { - world.add(this); - this.setCenter(world.center()); - this.edit(); - } + this.popUp(world); }; DialogBoxMorph.prototype.promptCredentials = function ( @@ -1980,11 +1982,11 @@ DialogBoxMorph.prototype.promptCredentials = function ( this.reactToChoice(); // initialize e-mail label - if (world) { - world.add(this); - this.setCenter(world.center()); - this.edit(); + if (!this.key) { + this.key = 'prompt'; } + + this.popUp(world); }; DialogBoxMorph.prototype.accept = function () { @@ -2024,6 +2026,34 @@ DialogBoxMorph.prototype.accept = function () { this.destroy(); }; +DialogBoxMorph.prototype.withKey = function (key) { + this.key = key; + return this; +}; + +DialogBoxMorph.prototype.popUp = function (world) { + if (world) { + if (this.key) { + if ((world.dialogs || (world.dialogs = {}))[this.key]) { + world.dialogs[this.key].destroy(); + } + world.dialogs[this.key] = this; + } + this.popUpWorld = world; + world.add(this); + world.keyboardReceiver = this; + this.setCenter(world.center()); + this.edit(); + } +}; + +DialogBoxMorph.prototype.destroy = function () { + DialogBoxMorph.uber.destroy.call(this); + if (this.key && this.popUpWorld && this.popUpWorld.dialogs) { + this.popUpWorld.dialogs[this.key] = undefined; + } +}; + DialogBoxMorph.prototype.ok = function () { this.accept(); }; -- cgit v1.3.1