mirror of
https://github.com/google/blockly.git
synced 2026-01-18 22:37:09 +01:00
Blockly Factory: Disable Disconnected Blocks, Nit UI, Bug fix (#595)
* disabled disconnected blocks in block factory change to block def and also warn user fixed bug and renamed math_foo * clearUndo upon opening a saved block, change alert messages that use ok * removed warning for unsaved blocks. in separate CL * fix bug and make the blank option clickable
This commit is contained in:
@@ -29,7 +29,7 @@ Blockly.Blocks['factory_base'] = {
|
||||
this.setColour(120);
|
||||
this.appendDummyInput()
|
||||
.appendField('name')
|
||||
.appendField(new Blockly.FieldTextInput('math_foo'), 'NAME');
|
||||
.appendField(new Blockly.FieldTextInput('block_type'), 'NAME');
|
||||
this.appendStatementInput('INPUTS')
|
||||
.setCheck('Input')
|
||||
.appendField('inputs');
|
||||
|
||||
@@ -321,7 +321,7 @@ AppController.prototype.onTab = function() {
|
||||
// Update exporter's block selector to reflect current block library.
|
||||
this.exporter.updateSelector();
|
||||
|
||||
// Update the preview to reflect any changes made to the blocks.
|
||||
// Update the exporter's preview to reflect any changes made to the blocks.
|
||||
this.exporter.updatePreview();
|
||||
|
||||
} else if (this.selectedTab == AppController.BLOCK_FACTORY) {
|
||||
@@ -519,8 +519,8 @@ AppController.prototype.assignBlockFactoryClickHandlers = function() {
|
||||
|
||||
document.getElementById('createNewBlockButton')
|
||||
.addEventListener('click', function() {
|
||||
BlockFactory.showStarterBlock();
|
||||
BlockLibraryView.selectDefaultOption('blockLibraryDropdown');
|
||||
BlockFactory.showStarterBlock();
|
||||
BlockLibraryView.selectDefaultOption('blockLibraryDropdown');
|
||||
});
|
||||
};
|
||||
|
||||
@@ -529,6 +529,7 @@ AppController.prototype.assignBlockFactoryClickHandlers = function() {
|
||||
*/
|
||||
AppController.prototype.addBlockFactoryEventListeners = function() {
|
||||
BlockFactory.mainWorkspace.addChangeListener(BlockFactory.updateLanguage);
|
||||
BlockFactory.mainWorkspace.addChangeListener(Blockly.Events.disableOrphans);
|
||||
document.getElementById('direction')
|
||||
.addEventListener('change', BlockFactory.updatePreview);
|
||||
document.getElementById('languageTA')
|
||||
|
||||
@@ -86,9 +86,14 @@ BlockLibraryController.prototype.removeFromBlockLibrary = function() {
|
||||
* @param {string} blockType - Block to edit on block factory.
|
||||
*/
|
||||
BlockLibraryController.prototype.openBlock = function(blockType) {
|
||||
var xml = this.storage.getBlockXml(blockType);
|
||||
BlockFactory.mainWorkspace.clear();
|
||||
Blockly.Xml.domToWorkspace(xml, BlockFactory.mainWorkspace);
|
||||
if (blockType =='BLOCK_LIBRARY_DEFAULT_BLANK') {
|
||||
BlockFactory.showStarterBlock();
|
||||
} else {
|
||||
var xml = this.storage.getBlockXml(blockType);
|
||||
BlockFactory.mainWorkspace.clear();
|
||||
Blockly.Xml.domToWorkspace(xml, BlockFactory.mainWorkspace);
|
||||
BlockFactory.mainWorkspace.clearUndo();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -107,8 +112,7 @@ BlockLibraryController.prototype.getSelectedBlockType =
|
||||
* updating the dropdown and displaying the starter block (factory_base).
|
||||
*/
|
||||
BlockLibraryController.prototype.clearBlockLibrary = function() {
|
||||
var check = confirm(
|
||||
'Click OK to clear your block library.');
|
||||
var check = confirm('Delete all blocks from library?');
|
||||
if (check) {
|
||||
// Clear Block Library Storage.
|
||||
this.storage.clear();
|
||||
@@ -128,12 +132,13 @@ BlockLibraryController.prototype.clearBlockLibrary = function() {
|
||||
*/
|
||||
BlockLibraryController.prototype.saveToBlockLibrary = function() {
|
||||
var blockType = this.getCurrentBlockType_();
|
||||
|
||||
// If block under that name already exists, confirm that user wants to replace
|
||||
// saved block.
|
||||
if (this.isInBlockLibrary(blockType)) {
|
||||
var replace = confirm('You already have a block called ' + blockType +
|
||||
' in your library. Click OK to replace.');
|
||||
if (!replace) {
|
||||
var replace = confirm('You already have a block called "' + blockType +
|
||||
'" in your library. Replace this block?');
|
||||
if ( !replace) {
|
||||
// Do not save if user doesn't want to replace the saved block.
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ BlockLibraryView.addOption
|
||||
*/
|
||||
BlockLibraryView.addDefaultOption = function(dropdownID) {
|
||||
BlockLibraryView.addOption(
|
||||
'BLOCK_LIBRARY_DEFAULT_BLANK', '', dropdownID, true, false);
|
||||
'BLOCK_LIBRARY_DEFAULT_BLANK', '', dropdownID, true, true);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -249,4 +249,3 @@ BlockFactory.showStarterBlock = function() {
|
||||
Blockly.Xml.domToWorkspace(
|
||||
Blockly.Xml.textToDom(xml), BlockFactory.mainWorkspace);
|
||||
};
|
||||
|
||||
|
||||
@@ -337,7 +337,7 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td height="5%">
|
||||
<h3>Language code:
|
||||
<h3>Block Definition:
|
||||
<select id="format">
|
||||
<option value="JSON">JSON</option>
|
||||
<option value="JavaScript">JavaScript</option>
|
||||
|
||||
Reference in New Issue
Block a user