initial refactorings to the IDE

pull/95/head
jmoenig 2020-04-29 17:25:03 +02:00
rodzic 5806b7ac7f
commit 1903320c3b
1 zmienionych plików z 33 dodań i 51 usunięć

Wyświetl plik

@ -78,7 +78,7 @@ Animation, BoxMorph, BlockEditorMorph, BlockDialogMorph, Note*/
// Global stuff //////////////////////////////////////////////////////// // Global stuff ////////////////////////////////////////////////////////
modules.gui = '2020-April-24'; modules.gui = '2020-April-29';
// Declarations // Declarations
@ -324,11 +324,11 @@ IDE_Morph.prototype.openIn = function (world) {
world.userMenu = this.userMenu; world.userMenu = this.userMenu;
// override SnapCloud's user message with Morphic // override SnapCloud's user message with Morphic
this.cloud.message = function (string) { this.cloud.message = (string) => {
var m = new MenuMorph(null, string), var m = new MenuMorph(null, string),
intervalHandle; intervalHandle;
m.popUpCenteredInWorld(world); m.popUpCenteredInWorld(world);
intervalHandle = setInterval(function () { intervalHandle = setInterval(() => {
m.destroy(); m.destroy();
clearInterval(intervalHandle); clearInterval(intervalHandle);
}, 2000); }, 2000);
@ -336,7 +336,7 @@ IDE_Morph.prototype.openIn = function (world) {
// prevent non-DialogBoxMorphs from being dropped // prevent non-DialogBoxMorphs from being dropped
// onto the World in user-mode // onto the World in user-mode
world.reactToDropOf = function (morph) { world.reactToDropOf = (morph) => {
if (!(morph instanceof DialogBoxMorph || if (!(morph instanceof DialogBoxMorph ||
(morph instanceof MenuMorph))) { (morph instanceof MenuMorph))) {
if (world.hand.grabOrigin) { if (world.hand.grabOrigin) {
@ -414,10 +414,8 @@ IDE_Morph.prototype.openIn = function (world) {
hash = decodeURIComponent(hash); hash = decodeURIComponent(hash);
} }
if (contains( if (contains(
['project', 'blocks', 'sprites', 'snapdata'].map( ['project', 'blocks', 'sprites', 'snapdata'].map(each =>
function (each) { hash.substr(0, 8).indexOf(each)
return hash.substr(0, 8).indexOf(each);
}
), ),
1 1
)) { )) {
@ -462,13 +460,11 @@ IDE_Morph.prototype.openIn = function (world) {
myself.cloud.getPublicProject( myself.cloud.getPublicProject(
dict.ProjectName, dict.ProjectName,
dict.Username, dict.Username,
function (projectData) { projectData => {
var msg; var msg;
myself.nextSteps([ myself.nextSteps([
function () { () => msg = myself.showMessage('Opening project...'),
msg = myself.showMessage('Opening project...'); () => {
},
function () {
if (projectData.indexOf('<snapdata') === 0) { if (projectData.indexOf('<snapdata') === 0) {
myself.rawOpenCloudDataString(projectData); myself.rawOpenCloudDataString(projectData);
} else if ( } else if (
@ -478,7 +474,7 @@ IDE_Morph.prototype.openIn = function (world) {
} }
myself.hasChangedMedia = true; myself.hasChangedMedia = true;
}, },
function () { () => {
myself.shield.destroy(); myself.shield.destroy();
myself.shield = null; myself.shield = null;
msg.destroy(); msg.destroy();
@ -501,13 +497,11 @@ IDE_Morph.prototype.openIn = function (world) {
myself.cloud.getPublicProject( myself.cloud.getPublicProject(
dict.ProjectName, dict.ProjectName,
dict.Username, dict.Username,
function (projectData) { projectData => {
var msg; var msg;
myself.nextSteps([ myself.nextSteps([
function () { () => msg = myself.showMessage('Opening project...'),
msg = myself.showMessage('Opening project...'); () => {
},
function () {
if (projectData.indexOf('<snapdata') === 0) { if (projectData.indexOf('<snapdata') === 0) {
myself.rawOpenCloudDataString(projectData); myself.rawOpenCloudDataString(projectData);
} else if ( } else if (
@ -517,7 +511,7 @@ IDE_Morph.prototype.openIn = function (world) {
} }
myself.hasChangedMedia = true; myself.hasChangedMedia = true;
}, },
function () { () => {
myself.shield.destroy(); myself.shield.destroy();
myself.shield = null; myself.shield = null;
msg.destroy(); msg.destroy();
@ -537,7 +531,7 @@ IDE_Morph.prototype.openIn = function (world) {
myself.cloud.getPublicProject( myself.cloud.getPublicProject(
dict.ProjectName, dict.ProjectName,
dict.Username, dict.Username,
function (projectData) { projectData => {
myself.saveXMLAs(projectData, dict.ProjectName); myself.saveXMLAs(projectData, dict.ProjectName);
myself.showMessage( myself.showMessage(
'Saved project\n' + dict.ProjectName, 'Saved project\n' + dict.ProjectName,
@ -719,26 +713,24 @@ IDE_Morph.prototype.createControlBar = function () {
this.controlBar.color = this.frameColor; this.controlBar.color = this.frameColor;
this.controlBar.setHeight(this.logo.height()); // height is fixed this.controlBar.setHeight(this.logo.height()); // height is fixed
/* // let users manually enforce re-layout when changing orientation
this.controlBar.mouseClickLeft = function () { // is this needed? // on mobile devices
this.controlBar.mouseClickLeft = function () {
this.world().fillPage(); this.world().fillPage();
}; };
*/
this.add(this.controlBar); this.add(this.controlBar);
//smallStageButton //smallStageButton
button = new ToggleButtonMorph( button = new ToggleButtonMorph(
null, //colors, null, //colors,
myself, // the IDE is the target this, // the IDE is the target
'toggleStageSize', 'toggleStageSize',
[ [
new SymbolMorph('smallStage', 14), new SymbolMorph('smallStage', 14),
new SymbolMorph('normalStage', 14) new SymbolMorph('normalStage', 14)
], ],
function () { // query () => this.isSmallStage // query
return myself.isSmallStage;
}
); );
button.corner = 12; button.corner = 12;
@ -761,15 +753,13 @@ IDE_Morph.prototype.createControlBar = function () {
//appModeButton //appModeButton
button = new ToggleButtonMorph( button = new ToggleButtonMorph(
null, //colors, null, //colors,
myself, // the IDE is the target this, // the IDE is the target
'toggleAppMode', 'toggleAppMode',
[ [
new SymbolMorph('fullScreen', 14), new SymbolMorph('fullScreen', 14),
new SymbolMorph('normalScreen', 14) new SymbolMorph('normalScreen', 14)
], ],
function () { // query () => this.isAppMode // query
return myself.isAppMode;
}
); );
button.corner = 12; button.corner = 12;
@ -792,15 +782,13 @@ IDE_Morph.prototype.createControlBar = function () {
//steppingButton //steppingButton
button = new ToggleButtonMorph( button = new ToggleButtonMorph(
null, //colors, null, //colors,
myself, // the IDE is the target this, // the IDE is the target
'toggleSingleStepping', 'toggleSingleStepping',
[ [
new SymbolMorph('footprints', 16), new SymbolMorph('footprints', 16),
new SymbolMorph('footprints', 16) new SymbolMorph('footprints', 16)
], ],
function () { // query () => Process.prototype.enableSingleStepping // query
return Process.prototype.enableSingleStepping;
}
); );
button.corner = 12; button.corner = 12;
@ -830,12 +818,10 @@ IDE_Morph.prototype.createControlBar = function () {
new SymbolMorph('octagon', 14), new SymbolMorph('octagon', 14),
new SymbolMorph('square', 14) new SymbolMorph('square', 14)
], ],
function () { // query () => this.stage ? // query
return myself.stage ? myself.stage.enableCustomHatBlocks &&
myself.stage.enableCustomHatBlocks && myself.stage.threads.pauseCustomHatBlocks
myself.stage.threads.pauseCustomHatBlocks : true
: true;
}
); );
button.corner = 12; button.corner = 12;
@ -864,9 +850,7 @@ IDE_Morph.prototype.createControlBar = function () {
new SymbolMorph('pause', 12), new SymbolMorph('pause', 12),
new SymbolMorph('pointRight', 14) new SymbolMorph('pointRight', 14)
], ],
function () { // query () => this.isPaused() // query
return myself.isPaused();
}
); );
button.corner = 12; button.corner = 12;
@ -916,9 +900,9 @@ IDE_Morph.prototype.createControlBar = function () {
6, 6,
'horizontal' 'horizontal'
); );
slider.action = function (num) { slider.action = (num) => {
Process.prototype.flashTime = (num - 1) / 100; Process.prototype.flashTime = (num - 1) / 100;
myself.controlBar.refreshResumeSymbol(); this.controlBar.refreshResumeSymbol();
}; };
// slider.alpha = MorphicPreferences.isFlat ? 0.1 : 0.3; // slider.alpha = MorphicPreferences.isFlat ? 0.1 : 0.3;
slider.color = new Color(153, 255, 213); slider.color = new Color(153, 255, 213);
@ -997,8 +981,7 @@ IDE_Morph.prototype.createControlBar = function () {
this.controlBar.fixLayout = function () { this.controlBar.fixLayout = function () {
x = this.right() - padding; x = this.right() - padding;
[stopButton, pauseButton, startButton].forEach( [stopButton, pauseButton, startButton].forEach(button => {
function (button) {
button.setCenter(myself.controlBar.center()); button.setCenter(myself.controlBar.center());
button.setRight(x); button.setRight(x);
x -= button.width(); x -= button.width();
@ -1011,8 +994,7 @@ IDE_Morph.prototype.createControlBar = function () {
myself.right() - StageMorph.prototype.dimensions.x * myself.right() - StageMorph.prototype.dimensions.x *
(myself.isSmallStage ? myself.stageRatio : 1) (myself.isSmallStage ? myself.stageRatio : 1)
); );
[stageSizeButton, appModeButton].forEach( [stageSizeButton, appModeButton].forEach(button => {
function (button) {
x += padding; x += padding;
button.setCenter(myself.controlBar.center()); button.setCenter(myself.controlBar.center());
button.setLeft(x); button.setLeft(x);