Skip to content

Commit 1208362

Browse files
committed
Move steps into opmode and only show when not already in opmode
1 parent 6eb73b7 commit 1208362

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

src/blocks/mrc_steps.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ export const setup = function () {
153153
Blockly.Blocks[BLOCK_NAME] = STEPS;
154154
};
155155

156+
export function isStepsInWorkspace(workspace: Blockly.Workspace): boolean {
157+
const blocks = workspace.getBlocksByType(BLOCK_NAME);
158+
return blocks.length > 0;
159+
};
160+
156161
export const pythonFromBlock = function (
157162
block: StepsBlock,
158163
generator: ExtendedPythonGenerator,

src/editor/editor.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import * as storageNames from '../storage/names';
2929
import * as storageProject from '../storage/project';
3030
import * as eventHandler from '../blocks/mrc_event_handler';
3131
import * as classMethodDef from '../blocks/mrc_class_method_def';
32+
import * as blockSteps from '../blocks/mrc_steps';
3233
import * as mechanismComponentHolder from '../blocks/mrc_mechanism_component_holder';
3334
//import { testAllBlocksInToolbox } from '../toolbox/toolbox_tests';
3435
import { applyExpandedCategories, getToolboxJSON } from '../toolbox/toolbox';
@@ -378,6 +379,13 @@ export class Editor {
378379
this.blocklyWorkspace, methodNamesAlreadyOverridden);
379380
return methodNamesAlreadyOverridden;
380381
}
382+
public isStepsInWorkspace(): boolean {
383+
if (!this.blocklyWorkspace.rendered) {
384+
// This editor has been abandoned.
385+
throw new Error('this.blocklyWorkspace has been disposed.');
386+
}
387+
return blockSteps.isStepsInWorkspace(this.blocklyWorkspace);
388+
}
381389

382390
public getEventsFromWorkspace(): storageModuleContent.Event[] {
383391
if (!this.blocklyWorkspace.rendered) {

src/toolbox/methods_category.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ class MethodsCategory {
9999
methodNamesAlreadyOverridden, contents);
100100
break;
101101
case storageModule.ModuleType.OPMODE:
102+
const hasSteps = editor.isStepsInWorkspace();
103+
if (!hasSteps) {
104+
contents.push({
105+
kind: 'block',
106+
type: 'mrc_steps',
107+
});
108+
}
102109
// Add the methods for an OpMode.
103110
this.addClassBlocksForCurrentModule(
104111
Blockly.Msg['MORE_OPMODE_METHODS_LABEL'], this.opmodeClassBlocks, [],

src/toolbox/test_category.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ export function getCategory(): toolboxItems.Category {
2020

2121
addBuiltInFunctionBlocks([printFunction], contents);
2222

23-
contents.push({
24-
kind: 'block',
25-
type: 'mrc_steps',
26-
});
27-
2823
return {
2924
kind: 'category',
3025
name: Blockly.Msg['MRC_CATEGORY_TEST'],

0 commit comments

Comments
 (0)