@@ -137,6 +137,9 @@ function initialise () {
137137 ipcRenderer . on ( 'paste' , function ( event , clipboard ) {
138138 document . getElementsByClassName ( 'blocklyHtmlInput' ) [ 0 ] . value = clipboard
139139 } )
140+ ipcRenderer . on ( 'testBlock' , function ( event ) {
141+ importTestBlock ( dialog . showOpenDialog ( { properties : [ 'openDirectory' ] } ) [ 0 ] )
142+ } )
140143 } )
141144 } )
142145 } )
@@ -2371,52 +2374,57 @@ document.body.ondrop = (ev) => {
23712374 // import the xml file
23722375 importRecipe ( filepath )
23732376 } else {
2374- fs . stat ( filepath , function ( error , stats ) {
2375- if ( stats . isDirectory ( ) ) {
2376- if ( process . platform == 'win32' ) {
2377- var folderName = filepath . split ( '\\' ) . slice ( - 1 ) [ 0 ]
2378- var jsonFile = path . normalize ( filepath + '\\' + folderName + '.json' )
2379- } else {
2380- var folderName = filepath . split ( '/' ) . slice ( - 1 ) [ 0 ]
2381- var jsonFile = path . normalize ( filepath + '/' + folderName + '.json' )
2382- }
2383- fs . stat ( jsonFile , function ( error , stats ) {
2384- if ( ! error ) {
2385- if ( process . platform == 'win32' ) {
2386- var blocksFolder = '\\..\\pibakery-blocks\\'
2387- } else {
2388- var blocksFolder = '/../pibakery-blocks/'
2377+ importTestBlock ( filepath )
2378+ }
2379+ }
2380+
2381+
2382+ function importTestBlock ( filepath ) {
2383+ fs . stat ( filepath , function ( error , stats ) {
2384+ if ( stats . isDirectory ( ) ) {
2385+ if ( process . platform == 'win32' ) {
2386+ var folderName = filepath . split ( '\\' ) . slice ( - 1 ) [ 0 ]
2387+ var jsonFile = path . normalize ( filepath + '\\' + folderName + '.json' )
2388+ } else {
2389+ var folderName = filepath . split ( '/' ) . slice ( - 1 ) [ 0 ]
2390+ var jsonFile = path . normalize ( filepath + '/' + folderName + '.json' )
2391+ }
2392+ fs . stat ( jsonFile , function ( error , stats ) {
2393+ if ( ! error ) {
2394+ if ( process . platform == 'win32' ) {
2395+ var blocksFolder = '\\..\\pibakery-blocks\\'
2396+ } else {
2397+ var blocksFolder = '/../pibakery-blocks/'
2398+ }
2399+ fs . stat ( path . normalize ( __dirname + blocksFolder + folderName ) , function ( error , stats ) {
2400+ if ( ! error ) {
2401+ var choice = dialog . showMessageBox (
2402+ {
2403+ type : 'question' ,
2404+ buttons : [ 'Yes' , 'No' ] ,
2405+ title : 'Block Conflict' ,
2406+ message : 'The block you are trying to import conflicts with a block already imported into PiBakery. Do you want to overwrite the existing block?'
2407+ } )
2408+ if ( choice == 1 ) {
2409+ return
2410+ } else {
2411+ fs . removeSync ( path . normalize ( __dirname + blocksFolder + folderName ) )
2412+ }
23892413 }
2390- fs . stat ( path . normalize ( __dirname + blocksFolder + folderName ) , function ( error , stats ) {
2391- if ( ! error ) {
2392- var choice = dialog . showMessageBox (
2393- {
2394- type : 'question' ,
2395- buttons : [ 'Yes' , 'No' ] ,
2396- title : 'Block Conflict' ,
2397- message : 'The block you are trying to import conflicts with a block already imported into PiBakery. Do you want to overwrite the existing block?'
2398- } )
2399- if ( choice == 1 ) {
2400- return
2401- } else {
2402- fs . removeSync ( path . normalize ( __dirname + blocksFolder + folderName ) )
2403- }
2414+ tempBlocks . push ( [ folderName , filepath ] )
2415+ fs . readFile ( jsonFile , 'utf8' , function ( error , data ) {
2416+ if ( error ) {
2417+ console . error ( error )
2418+ alert ( "Error loading block '" + folderName + "'." )
2419+ } else {
2420+ importBlock ( data )
2421+ workspace . updateToolbox ( document . getElementById ( 'toolbox' ) )
2422+ alert ( "Imported Block. '" + folderName + "' will be available to use until you next restart PiBakery." )
24042423 }
2405- tempBlocks . push ( [ folderName , filepath ] )
2406- fs . readFile ( jsonFile , 'utf8' , function ( error , data ) {
2407- if ( error ) {
2408- console . error ( error )
2409- alert ( "Error loading block '" + folderName + "'." )
2410- } else {
2411- importBlock ( data )
2412- workspace . updateToolbox ( document . getElementById ( 'toolbox' ) )
2413- alert ( "Imported Block. '" + folderName + "' will be available to use until you next restart PiBakery." )
2414- }
2415- } )
24162424 } )
2417- }
2418- } )
2419- }
2420- } )
2421- }
2425+ } )
2426+ }
2427+ } )
2428+ }
2429+ } )
24222430}
0 commit comments