mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 06:52:40 -05:00
Merge pull request #1779 from rschamp/project-dirty-signal
Add "project changed" event
This commit is contained in:
commit
dd2023e2f3
3 changed files with 31 additions and 4 deletions
|
@ -487,6 +487,10 @@ class Blocks {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// forceNoGlow is set to true on containers that don't affect the project serialization,
|
||||||
|
// e.g., the toolbox or monitor containers.
|
||||||
|
if (optRuntime && !this.forceNoGlow) optRuntime.emitProjectChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
|
@ -501,6 +501,14 @@ class Runtime extends EventEmitter {
|
||||||
return 'PROJECT_LOADED';
|
return 'PROJECT_LOADED';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event name for report that a change was made that can be saved
|
||||||
|
* @const {string}
|
||||||
|
*/
|
||||||
|
static get PROJECT_CHANGED () {
|
||||||
|
return 'PROJECT_CHANGED';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event name for targets update report.
|
* Event name for targets update report.
|
||||||
* @const {string}
|
* @const {string}
|
||||||
|
@ -1737,7 +1745,6 @@ class Runtime extends EventEmitter {
|
||||||
// Script glows must be cleared.
|
// Script glows must be cleared.
|
||||||
this._scriptGlowsPreviousFrame = [];
|
this._scriptGlowsPreviousFrame = [];
|
||||||
this._updateGlows();
|
this._updateGlows();
|
||||||
this.requestTargetsUpdate(editingTarget);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2035,6 +2042,13 @@ class Runtime extends EventEmitter {
|
||||||
this.emit(Runtime.PROJECT_LOADED);
|
this.emit(Runtime.PROJECT_LOADED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Report that the project has changed in a way that would affect serialization
|
||||||
|
*/
|
||||||
|
emitProjectChanged () {
|
||||||
|
this.emit(Runtime.PROJECT_CHANGED);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Report that a new target has been created, possibly by cloning an existing target.
|
* Report that a new target has been created, possibly by cloning an existing target.
|
||||||
* @param {Target} newTarget - the newly created target.
|
* @param {Target} newTarget - the newly created target.
|
||||||
|
|
|
@ -84,6 +84,9 @@ class VirtualMachine extends EventEmitter {
|
||||||
this.runtime.on(Runtime.PROJECT_RUN_STOP, () => {
|
this.runtime.on(Runtime.PROJECT_RUN_STOP, () => {
|
||||||
this.emit(Runtime.PROJECT_RUN_STOP);
|
this.emit(Runtime.PROJECT_RUN_STOP);
|
||||||
});
|
});
|
||||||
|
this.runtime.on(Runtime.PROJECT_CHANGED, () => {
|
||||||
|
this.emit(Runtime.PROJECT_CHANGED);
|
||||||
|
});
|
||||||
this.runtime.on(Runtime.VISUAL_REPORT, visualReport => {
|
this.runtime.on(Runtime.VISUAL_REPORT, visualReport => {
|
||||||
this.emit(Runtime.VISUAL_REPORT, visualReport);
|
this.emit(Runtime.VISUAL_REPORT, visualReport);
|
||||||
});
|
});
|
||||||
|
@ -476,7 +479,7 @@ class VirtualMachine extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the VM user's knowledge of targets and blocks on the workspace.
|
// Update the VM user's knowledge of targets and blocks on the workspace.
|
||||||
this.emitTargetsUpdate();
|
this.emitTargetsUpdate(false /* Don't emit project change */);
|
||||||
this.emitWorkspaceUpdate();
|
this.emitWorkspaceUpdate();
|
||||||
this.runtime.setEditingTarget(this.editingTarget);
|
this.runtime.setEditingTarget(this.editingTarget);
|
||||||
this.runtime.ioDevices.cloud.setStage(this.runtime.getTargetForStage());
|
this.runtime.ioDevices.cloud.setStage(this.runtime.getTargetForStage());
|
||||||
|
@ -1105,7 +1108,7 @@ class VirtualMachine extends EventEmitter {
|
||||||
if (target) {
|
if (target) {
|
||||||
this.editingTarget = target;
|
this.editingTarget = target;
|
||||||
// Emit appropriate UI updates.
|
// Emit appropriate UI updates.
|
||||||
this.emitTargetsUpdate();
|
this.emitTargetsUpdate(false /* Don't emit project change */);
|
||||||
this.emitWorkspaceUpdate();
|
this.emitWorkspaceUpdate();
|
||||||
this.runtime.setEditingTarget(target);
|
this.runtime.setEditingTarget(target);
|
||||||
}
|
}
|
||||||
|
@ -1199,6 +1202,7 @@ class VirtualMachine extends EventEmitter {
|
||||||
if (this.editingTarget) {
|
if (this.editingTarget) {
|
||||||
this.emitWorkspaceUpdate();
|
this.emitWorkspaceUpdate();
|
||||||
this.runtime.setEditingTarget(this.editingTarget);
|
this.runtime.setEditingTarget(this.editingTarget);
|
||||||
|
this.emitTargetsUpdate(false /* Don't emit project change */);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1206,8 +1210,12 @@ class VirtualMachine extends EventEmitter {
|
||||||
* Emit metadata about available targets.
|
* Emit metadata about available targets.
|
||||||
* An editor UI could use this to display a list of targets and show
|
* An editor UI could use this to display a list of targets and show
|
||||||
* the currently editing one.
|
* the currently editing one.
|
||||||
|
* @param {bool} triggerProjectChange If true, also emit a project changed event.
|
||||||
|
* Disabled selectively by updates that don't affect project serialization.
|
||||||
|
* Defaults to true.
|
||||||
*/
|
*/
|
||||||
emitTargetsUpdate () {
|
emitTargetsUpdate (triggerProjectChange) {
|
||||||
|
if (typeof triggerProjectChange === 'undefined') triggerProjectChange = true;
|
||||||
this.emit('targetsUpdate', {
|
this.emit('targetsUpdate', {
|
||||||
// [[target id, human readable target name], ...].
|
// [[target id, human readable target name], ...].
|
||||||
targetList: this.runtime.targets
|
targetList: this.runtime.targets
|
||||||
|
@ -1220,6 +1228,7 @@ class VirtualMachine extends EventEmitter {
|
||||||
// Currently editing target id.
|
// Currently editing target id.
|
||||||
editingTarget: this.editingTarget ? this.editingTarget.id : null
|
editingTarget: this.editingTarget ? this.editingTarget.id : null
|
||||||
});
|
});
|
||||||
|
if (triggerProjectChange) this.runtime.emitProjectChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue