diff options
| author | Jens Mönig <jens@moenig.org> | 2013-04-23 08:27:46 -0700 |
|---|---|---|
| committer | Jens Mönig <jens@moenig.org> | 2013-04-23 08:27:46 -0700 |
| commit | 49998bb0dee32016c5e6242274814dd43e38f681 (patch) | |
| tree | 96e94d361804a95c0d0e33bf51c4f1a29eb5d47f /widgets.js | |
| parent | 3328d87f2fb95a800e775530e711343cde545e89 (diff) | |
| parent | cad54f7433f48a016f3ebc8ae37a6fe75090bcfb (diff) | |
| download | snap-49998bb0dee32016c5e6242274814dd43e38f681.tar.gz snap-49998bb0dee32016c5e6242274814dd43e38f681.zip | |
Merge pull request #74 from queryselector/issue-23
Fixed #23
Diffstat (limited to 'widgets.js')
| -rw-r--r-- | widgets.js | 68 |
1 files changed, 49 insertions, 19 deletions
@@ -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(); }; |
