mirror of
https://github.com/google/blockly.git
synced 2026-01-07 17:10:11 +01:00
chore: Use JSON objects for context menu callbackFactory (#7382)
* chore: use json object for context callbackFactory * Add test file for context menu callback function.
This commit is contained in:
@@ -9,7 +9,6 @@
|
||||
import * as ContextMenu from '../core/contextmenu.js';
|
||||
import * as Extensions from '../core/extensions.js';
|
||||
import * as Variables from '../core/variables.js';
|
||||
import * as xmlUtils from '../core/utils/xml.js';
|
||||
import type {Block} from '../core/block.js';
|
||||
import type {
|
||||
ContextMenuOption,
|
||||
@@ -102,18 +101,16 @@ const CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MIXIN = {
|
||||
contextMenuMsg = Msg['VARIABLES_SET_CREATE_GET'];
|
||||
}
|
||||
|
||||
const name = this.getField('VAR')!.getText();
|
||||
const xmlField = xmlUtils.createElement('field');
|
||||
xmlField.setAttribute('name', 'VAR');
|
||||
xmlField.appendChild(xmlUtils.createTextNode(name));
|
||||
const xmlBlock = xmlUtils.createElement('block');
|
||||
xmlBlock.setAttribute('type', oppositeType);
|
||||
xmlBlock.appendChild(xmlField);
|
||||
const varField = this.getField('VAR')!;
|
||||
const newVarBlockState = {
|
||||
type: oppositeType,
|
||||
fields: {VAR: varField.saveState(true)},
|
||||
};
|
||||
|
||||
options.push({
|
||||
enabled: this.workspace.remainingCapacity() > 0,
|
||||
text: contextMenuMsg.replace('%1', name),
|
||||
callback: ContextMenu.callbackFactory(this, xmlBlock),
|
||||
text: contextMenuMsg.replace('%1', varField.getText()),
|
||||
callback: ContextMenu.callbackFactory(this, newVarBlockState),
|
||||
});
|
||||
// Getter blocks have the option to rename or delete that variable.
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user