Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions core/block_transformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@ Blockly.BlockTransformer.prototype.doTransform = function (refactorable) {
};

Blockly.BlockTransformer.prototype.executeAction = function (action) {
let result = true;
try {
this.apply(action);
result = this.apply(action);
} catch (err) {
throw "failed to apply transformation:" +
JSON.stringify(action)
+ "\n" + err.message;
}
return true;
return result;
};

Blockly.BlockTransformer.prototype.apply = function (action) {
const actionType = action.type;
this[actionType](action);
return this[actionType](action);
};

Blockly.BlockTransformer.prototype.VarDeclareAction = function (action) {
Expand Down Expand Up @@ -67,7 +68,11 @@ Blockly.BlockTransformer.prototype.VarRename = function (action) {
Blockly.BlockTransformer.prototype.BlockCreateAction = function (action) {
let dom = Blockly.Xml.textToDom(action.block_xml).firstChild;
let block = Blockly.Xml.domToBlock(dom, this.workspace);
return true;
if (block.type === "procedures_definition") {
return block;
// Blockly.Procedures.editProcedureCallback_(block);
}
return true
};

Blockly.BlockTransformer.prototype.InsertBlockAction = function (action) {
Expand Down
32 changes: 28 additions & 4 deletions core/hint.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ Blockly.Hint.prototype.setBubbleSize = function(width, height) {
* Show or hide the hint bubble.
* @param {boolean} visible True if the bubble should be visible.
*/
Blockly.Hint.prototype.setVisible = function(visible) {
Blockly.Hint.prototype.setVisible = function(visible, hintType) {
if (visible == this.isVisible()) {
// No change.
return;
Expand All @@ -144,9 +144,13 @@ Blockly.Hint.prototype.setVisible = function(visible) {
/** @type {!Blockly.WorkspaceSvg} */ (this.block_.workspace),
content, this.block_.svgPath_, this.iconXY_, null, null);
// specific for hint
this.bubble_.registerContextMenuCallback(this.showContextMenu_.bind(this));
this.bubble_.registerMouseOverCallback(this.showCodeHint_.bind(this));
this.bubble_.registerMouseOutCallback(this.hideCodeHint_.bind(this));
if (hintType === "edit_procedure") {
this.bubble_.registerContextMenuCallback(this.showEditContextMenu_.bind(this));
} else {
this.bubble_.registerContextMenuCallback(this.showContextMenu_.bind(this));
this.bubble_.registerMouseOverCallback(this.showCodeHint_.bind(this));
this.bubble_.registerMouseOutCallback(this.hideCodeHint_.bind(this));
}

if (this.block_.RTL) {
// Right-align the paragraph.
Expand All @@ -169,6 +173,26 @@ Blockly.Hint.prototype.setVisible = function(visible) {
}
};

/**
* Show the context menu for this comment's bubble.
* @param {!Event} e The mouse event
* @private
*/
Blockly.Hint.prototype.showEditContextMenu_ = function(e) {
var menuOptions = [];
var block = this.block_;
var _this = this;
menuOptions.push({
enabled: true,
text: Blockly.Msg.EDIT_PROCEDURE,
callback: function() {
Blockly.Procedures.editProcedureCallback_(block);
_this.setVisible(false, "edit_procedure");
}
});
Blockly.ContextMenu.show(e, menuOptions, block.RTL);
};

/**
* Show the context menu for this comment's bubble.
* @param {!Event} e The mouse event
Expand Down