Merge pull request #277 from zhaouv/editor-blockly-search
lastusedblocks
This commit is contained in:
commit
08683c9156
@ -4,12 +4,13 @@ editor_blockly = function () {
|
|||||||
|
|
||||||
initscript = String.raw`
|
initscript = String.raw`
|
||||||
(function(){
|
(function(){
|
||||||
var getCategory = function(name){
|
var getCategory = function(name,custom){
|
||||||
for(var node of document.getElementById('toolbox').children) {
|
for(var node of document.getElementById('toolbox').children) {
|
||||||
if(node.getAttribute('name')==name) return node;
|
if(node.getAttribute('name')==name) return node;
|
||||||
}
|
}
|
||||||
var node = document.createElement('category');
|
var node = document.createElement('category');
|
||||||
node.setAttribute('name',name);
|
node.setAttribute('name',name);
|
||||||
|
if(custom)node.setAttribute('custom',custom);
|
||||||
document.getElementById('toolbox').appendChild(node);
|
document.getElementById('toolbox').appendChild(node);
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
@ -243,15 +244,19 @@ editor_blockly = function () {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},'event'),
|
},'event'),
|
||||||
|
|
||||||
],
|
],
|
||||||
|
'最近使用':[
|
||||||
|
'<label text="此处只是占位符,实际定义在editor_blockly.searchBlockCategoryCallback中"></label>',
|
||||||
|
]
|
||||||
}
|
}
|
||||||
var toolboxgap = '<sep gap="5"></sep>'
|
var toolboxgap = '<sep gap="5"></sep>'
|
||||||
//xml_text = MotaActionFunctions.actionParser.parse(obj,type||'event')
|
//xml_text = MotaActionFunctions.actionParser.parse(obj,type||'event')
|
||||||
//MotaActionBlocks['idString_e'].xmlText()
|
//MotaActionBlocks['idString_e'].xmlText()
|
||||||
|
|
||||||
for (var name in toolboxObj){
|
for (var name in toolboxObj){
|
||||||
getCategory(name).innerHTML = toolboxObj[name].join(toolboxgap);
|
var custom = null;
|
||||||
|
if(name=='最近使用')custom='searchBlockCategory';
|
||||||
|
getCategory(name,custom).innerHTML = toolboxObj[name].join(toolboxgap);
|
||||||
}
|
}
|
||||||
|
|
||||||
var blocklyArea = document.getElementById('blocklyArea');
|
var blocklyArea = document.getElementById('blocklyArea');
|
||||||
@ -269,6 +274,21 @@ var workspace = Blockly.inject(blocklyDiv,{
|
|||||||
},
|
},
|
||||||
trashcan: false,
|
trashcan: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
editor_blockly.searchBlockCategoryCallback = function(workspace) {
|
||||||
|
var xmlList = [];
|
||||||
|
for (var i = 0; i < editor_blockly.lastUsedType.length; i++) {
|
||||||
|
var blockText = '<xml>' +
|
||||||
|
MotaActionBlocks[editor_blockly.lastUsedType[i]].xmlText() +
|
||||||
|
'</xml>';
|
||||||
|
var block = Blockly.Xml.textToDom(blockText).firstChild;
|
||||||
|
xmlList.push(block);
|
||||||
|
}
|
||||||
|
return xmlList;
|
||||||
|
};
|
||||||
|
|
||||||
|
workspace.registerToolboxCategoryCallback(
|
||||||
|
'searchBlockCategory', editor_blockly.searchBlockCategoryCallback);
|
||||||
|
|
||||||
var onresize = function(e) {
|
var onresize = function(e) {
|
||||||
blocklyDiv.style.width = blocklyArea.offsetWidth + 'px';
|
blocklyDiv.style.width = blocklyArea.offsetWidth + 'px';
|
||||||
@ -291,6 +311,9 @@ document.getElementById('blocklyDiv').onmousewheel = function(e){
|
|||||||
|
|
||||||
var doubleClickCheck=[[0,'abc']];
|
var doubleClickCheck=[[0,'abc']];
|
||||||
function omitedcheckUpdateFunction(event) {
|
function omitedcheckUpdateFunction(event) {
|
||||||
|
if(event.type==='ui'||event.type==='move'){
|
||||||
|
editor_blockly.addIntoLastUsedType(event.blockId);
|
||||||
|
}
|
||||||
if(event.type==='ui'){
|
if(event.type==='ui'){
|
||||||
var newClick = [new Date().getTime(),event.blockId];
|
var newClick = [new Date().getTime(),event.blockId];
|
||||||
var lastClick = doubleClickCheck.shift();
|
var lastClick = doubleClickCheck.shift();
|
||||||
@ -511,6 +534,21 @@ document.getElementById('blocklyDiv').onmousewheel = function(e){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
editor_blockly.lastUsedType=['comment_s']//初始空着比较难看
|
||||||
|
editor_blockly.lastUsedTypeNum=15
|
||||||
|
|
||||||
|
editor_blockly.addIntoLastUsedType=function(blockId){
|
||||||
|
var b = editor_blockly.workspace.getBlockById(blockId);
|
||||||
|
if(!b)return;
|
||||||
|
var blockType = b.type;
|
||||||
|
if(!blockType || ['pass_s','emptyshop'].indexOf(blockType)!==-1)return;
|
||||||
|
if(editor_blockly.lastUsedType.indexOf(blockType)!==-1){
|
||||||
|
editor_blockly.lastUsedType.splice(editor_blockly.lastUsedType.indexOf(blockType),1)
|
||||||
|
}
|
||||||
|
editor_blockly.lastUsedType.unshift(blockType)
|
||||||
|
editor_blockly.lastUsedType=editor_blockly.lastUsedType.slice(0,editor_blockly.lastUsedTypeNum)
|
||||||
|
}
|
||||||
|
|
||||||
return editor_blockly;
|
return editor_blockly;
|
||||||
}
|
}
|
||||||
//editor_blockly=editor_blockly();
|
//editor_blockly=editor_blockly();
|
||||||
Loading…
Reference in New Issue
Block a user