Skip to content

Commit 359d61a

Browse files
gonfunkosebjacobs
authored andcommitted
fix: add support for Scratch-style procedures (#6)
* fix: add support for Scratch-style procedures * refactor: remove underscore procedure creation callback
1 parent 0492e0d commit 359d61a

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

src/containers/blocks.jsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class Blocks extends React.Component {
7979
'setBlocks',
8080
'setLocale'
8181
]);
82-
this.ScratchBlocks.prompt = this.handlePromptStart;
82+
this.ScratchBlocks.dialog.setPrompt(this.handlePromptStart);
8383
this.ScratchBlocks.statusButtonCallback = this.handleConnectionModalStart;
8484
this.ScratchBlocks.recordSoundCallback = this.handleOpenSoundRecorder;
8585

@@ -91,12 +91,12 @@ class Blocks extends React.Component {
9191
}
9292
componentDidMount () {
9393
this.ScratchBlocks = VMScratchBlocks(this.props.vm, this.props.useCatBlocks);
94-
this.ScratchBlocks.prompt = this.handlePromptStart;
94+
this.ScratchBlocks.dialog.setPrompt(this.handlePromptStart);
9595
this.ScratchBlocks.statusButtonCallback = this.handleConnectionModalStart;
9696
this.ScratchBlocks.recordSoundCallback = this.handleOpenSoundRecorder;
9797

9898
// this.ScratchBlocks.FieldColourSlider.activateEyedropper_ = this.props.onActivateColorPicker;
99-
this.ScratchBlocks.Procedures.externalProcedureDefCallback = this.props.onActivateCustomProcedures;
99+
this.ScratchBlocks.ScratchProcedures.externalProcedureDefCallback = this.props.onActivateCustomProcedures;
100100
this.ScratchBlocks.ScratchMsgs.setLocale(this.props.locale);
101101

102102
const theme = this.ScratchBlocks.Theme.defineTheme('Scratch', {
@@ -115,6 +115,8 @@ class Blocks extends React.Component {
115115
}
116116
);
117117
this.workspace = this.ScratchBlocks.inject(this.blocks, workspaceConfig);
118+
this.workspace.registerToolboxCategoryCallback('PROCEDURE',
119+
this.ScratchBlocks.ScratchProcedures.getProceduresCategory);
118120

119121
// Register buttons under new callback keys for creating variables,
120122
// lists, and procedures from extensions.
@@ -124,7 +126,7 @@ class Blocks extends React.Component {
124126
const varListButtonCallback = type =>
125127
(() => this.ScratchBlocks.Variables.createVariable(this.workspace, null, type));
126128
const procButtonCallback = () => {
127-
this.ScratchBlocks.Procedures.createProcedureDefCallback_(this.workspace);
129+
this.ScratchBlocks.ScratchProcedures.createProcedureDefCallback(this.workspace);
128130
};
129131

130132
toolboxWorkspace.registerButtonCallback('MAKE_A_VARIABLE', varListButtonCallback(''));
@@ -545,8 +547,8 @@ class Blocks extends React.Component {
545547
handleCustomProceduresClose (data) {
546548
this.props.onRequestCloseCustomProcedures(data);
547549
const ws = this.workspace;
548-
ws.refreshToolboxSelection_();
549-
ws.toolbox_.scrollToCategoryById('myBlocks');
550+
this.updateToolbox();
551+
ws.getToolbox().selectCategoryByName('myBlocks');
550552
}
551553
handleDrop (dragInfo) {
552554
fetch(dragInfo.payload.bodyUrl)

src/containers/custom-procedures.jsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import defaultsDeep from 'lodash.defaultsdeep';
33
import PropTypes from 'prop-types';
44
import React from 'react';
55
import CustomProceduresComponent from '../components/custom-procedures/custom-procedures.jsx';
6-
import ScratchBlocks from 'scratch-blocks';
6+
import {ScratchBlocks} from 'scratch-blocks';
77
import {connect} from 'react-redux';
88

99
class CustomProcedures extends React.Component {
@@ -37,11 +37,13 @@ class CustomProcedures extends React.Component {
3737
{rtl: this.props.isRtl}
3838
);
3939

40-
// @todo This is a hack to make there be no toolbox.
41-
const oldDefaultToolbox = ScratchBlocks.Blocks.defaultToolbox;
42-
ScratchBlocks.Blocks.defaultToolbox = null;
40+
const theme = ScratchBlocks.Theme.defineTheme('Scratch', {
41+
'base': ScratchBlocks.Themes.Zelos,
42+
'startHats': true
43+
});
44+
workspaceConfig.theme = theme;
45+
workspaceConfig.renderer = 'zelos';
4346
this.workspace = ScratchBlocks.inject(this.blocks, workspaceConfig);
44-
ScratchBlocks.Blocks.defaultToolbox = oldDefaultToolbox;
4547

4648
// Create the procedure declaration block for editing the mutation.
4749
this.mutationRoot = this.workspace.newBlock('procedures_declaration');

0 commit comments

Comments
 (0)