diff --git a/byob.js b/byob.js index bc7e96ae..73582431 100644 --- a/byob.js +++ b/byob.js @@ -1026,6 +1026,10 @@ BlockDialogMorph.prototype = new DialogBoxMorph(); BlockDialogMorph.prototype.constructor = BlockDialogMorph; BlockDialogMorph.uber = DialogBoxMorph.prototype; +// BlockDialogMorph constants: + +BlockDialogMorph.prototype.key = 'makeABlock'; + // BlockDialogMorph instance creation: function BlockDialogMorph(target, action, environment) { @@ -1099,11 +1103,7 @@ BlockDialogMorph.prototype.openForChange = function ( this.scopes = null; this.fixLayout(); this.drawNew(); - if (world) { - world.add(this); - this.setCenter(world.center()); - this.edit(); - } + this.popUp(world); }; // category buttons @@ -1544,8 +1544,7 @@ BlockEditorMorph.prototype.popUp = function () { var world = this.target.world(); if (world) { - world.add(this); - world.keyboardReceiver = this; + BlockEditorMorph.uber.popUp.call(this, world); this.handle = new HandleMorph( this, 280, @@ -1553,7 +1552,6 @@ BlockEditorMorph.prototype.popUp = function () { this.corner, this.corner ); - this.setCenter(world.center()); } }; @@ -2424,11 +2422,7 @@ InputSlotDialogMorph.prototype.open = function ( this.fixLayout(); this.drawNew(); this.fixLayout(); - if (world) { - world.add(this); - this.setCenter(world.center()); - this.edit(); - } + this.popUp(world); this.add(this.types); // make the types come to front Morph.prototype.trackChanges = oldFlag; this.changed(); @@ -2846,6 +2840,10 @@ BlockExportDialogMorph.prototype = new DialogBoxMorph(); BlockExportDialogMorph.prototype.constructor = BlockExportDialogMorph; BlockExportDialogMorph.uber = DialogBoxMorph.prototype; +// BlockExportDialogMorph constants: + +BlockExportDialogMorph.prototype.key = 'blockExport'; + // BlockExportDialogMorph instance creation: function BlockExportDialogMorph(serializer, blocks) { @@ -2952,8 +2950,7 @@ BlockExportDialogMorph.prototype.buildContents = function () { BlockExportDialogMorph.prototype.popUp = function (wrrld) { var world = wrrld || this.target.world(); if (world) { - world.add(this); - world.keyboardReceiver = this; + BlockExportDialogMorph.uber.popUp.call(this, world); this.handle = new HandleMorph( this, 200, @@ -2961,7 +2958,6 @@ BlockExportDialogMorph.prototype.popUp = function (wrrld) { this.corner, this.corner ); - this.setCenter(world.center()); } }; @@ -3024,6 +3020,10 @@ BlockImportDialogMorph.prototype = new DialogBoxMorph(); BlockImportDialogMorph.prototype.constructor = BlockImportDialogMorph; BlockImportDialogMorph.uber = DialogBoxMorph.prototype; +// BlockImportDialogMorph constants: + +BlockImportDialogMorph.prototype.key = 'blockImport'; + // BlockImportDialogMorph instance creation: function BlockImportDialogMorph(blocks, target, name) { diff --git a/gui.js b/gui.js index 6314d858..3d6654f6 100644 --- a/gui.js +++ b/gui.js @@ -1679,7 +1679,7 @@ IDE_Morph.prototype.cloudMenu = function () { } else { myself.prompt('Export Project As...', function (name) { myself.exportProjectMedia(name); - }); + }, 'exportProject'); } }, null, @@ -1693,7 +1693,7 @@ IDE_Morph.prototype.cloudMenu = function () { } else { myself.prompt('Export Project As...', function (name) { myself.exportProjectNoMedia(name); - }); + }, 'exportProject'); } }, null, @@ -1707,7 +1707,7 @@ IDE_Morph.prototype.cloudMenu = function () { } else { myself.prompt('Export Project As...', function (name) { myself.exportProjectAsCloudData(name); - }); + }, 'exportProject'); } }, null, @@ -1754,8 +1754,8 @@ IDE_Morph.prototype.cloudMenu = function () { myself.cloudError() ); - }); - }); + }, 'project'); + }, 'project'); }, null, new Color(100, 0, 0) @@ -1996,7 +1996,7 @@ IDE_Morph.prototype.projectMenu = function () { } else { myself.prompt('Export Project As...', function (name) { myself.exportProject(name); - }); + }, 'exportProject'); } }, 'show project data as XML\nin a new browser window', @@ -2181,7 +2181,7 @@ IDE_Morph.prototype.aboutSnap = function () { }; IDE_Morph.prototype.editProjectNotes = function () { - var dialog = new DialogBoxMorph(), + var dialog = new DialogBoxMorph().withKey('projectNotes'), frame = new ScrollFrameMorph(), text = new TextMorph(this.projectNotes || ''), ok = dialog.ok, @@ -2228,7 +2228,7 @@ IDE_Morph.prototype.editProjectNotes = function () { dialog.addButton('cancel', 'Cancel'); dialog.fixLayout(); dialog.drawNew(); - world.add(dialog); + dialog.popUp(world); dialog.setCenter(world.center()); text.edit(); }; @@ -2935,7 +2935,7 @@ IDE_Morph.prototype.userSetBlocksScale = function () { function (num) { myself.setBlocksScale(num); } - ).prompt( + ).withKey('zoomBlocks').prompt( 'Zoom blocks', SyntaxElementMorph.prototype.scale.toString(), this.world(), @@ -3007,7 +3007,7 @@ IDE_Morph.prototype.initializeCloud = function () { myself.cloudError() ); } - ).promptCredentials( + ).withKey('cloud').promptCredentials( 'Sign in', 'login', null, @@ -3048,7 +3048,7 @@ IDE_Morph.prototype.createCloudAccount = function () { myself.cloudError() ); } - ).promptCredentials( + ).withKey('cloud').promptCredentials( 'Sign up', 'signup', 'http://snap.berkeley.edu/tos.html', @@ -3078,7 +3078,7 @@ IDE_Morph.prototype.changeCloudPassword = function () { myself.cloudError() ); } - ).promptCredentials( + ).withKey('cloud').promptCredentials( 'Change Password', 'changePassword', null, @@ -3335,7 +3335,7 @@ IDE_Morph.prototype.setCloudURL = function () { function (url) { SnapCloud.url = url; } - ).prompt( + ).withKey('cloudURL').prompt( 'Cloud URL', SnapCloud.url, this.world(), @@ -3385,8 +3385,8 @@ IDE_Morph.prototype.confirm = function (message, title, action) { ); }; -IDE_Morph.prototype.prompt = function (message, callback, choices) { - (new DialogBoxMorph(null, callback)).prompt( +IDE_Morph.prototype.prompt = function (message, callback, choices, key) { + (new DialogBoxMorph(null, callback)).withKey(key).prompt( message, '', this.world(), @@ -3403,6 +3403,10 @@ ProjectDialogMorph.prototype = new DialogBoxMorph(); ProjectDialogMorph.prototype.constructor = ProjectDialogMorph; ProjectDialogMorph.uber = DialogBoxMorph.prototype; +// ProjectDialogMorph constants: + +ProjectDialogMorph.prototype.key = 'project'; + // ProjectDialogMorph instance creation: function ProjectDialogMorph(ide, label) { @@ -3585,8 +3589,7 @@ ProjectDialogMorph.prototype.buildContents = function () { ProjectDialogMorph.prototype.popUp = function (wrrld) { var world = wrrld || this.ide.world(); if (world) { - world.add(this); - world.keyboardReceiver = this; + ProjectDialogMorph.uber.popUp.call(this, world); this.handle = new HandleMorph( this, 350, @@ -3594,8 +3597,6 @@ ProjectDialogMorph.prototype.popUp = function (wrrld) { this.corner, this.corner ); - this.setCenter(world.center()); - this.edit(); } }; @@ -4690,7 +4691,7 @@ CostumeIconMorph.prototype.editCostume = function () { CostumeIconMorph.prototype.renameCostume = function () { var costume = this.object, ide = this.parentThatIsA(IDE_Morph); - (new DialogBoxMorph( + new DialogBoxMorph( null, function (answer) { if (answer && (answer !== costume.name)) { @@ -4699,7 +4700,7 @@ CostumeIconMorph.prototype.renameCostume = function () { ide.hasChangedMedia = true; } } - )).prompt( + ).prompt( 'rename costume', costume.name, this.world() diff --git a/objects.js b/objects.js index 1b7027ff..f0a86975 100644 --- a/objects.js +++ b/objects.js @@ -4476,11 +4476,7 @@ Costume.prototype.edit = function (aWorld) { dialog.fixLayout(); dialog.drawNew(); dialog.fixLayout(); - if (aWorld) { - aWorld.add(dialog); - aWorld.keyboardReceiver = dialog; - dialog.setCenter(aWorld.center()); - } + dialog.popUp(aWorld); }; // Costume thumbnail diff --git a/widgets.js b/widgets.js index c779f692..0f39d632 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(); };