|
| 1 | +"use strict"; |
| 2 | +vareditor_1=require('../../atom/editor'); |
| 3 | +varaction_helpers_1=require('./action-helpers'); |
| 4 | +varType={ |
| 5 | +OPEN:'open', |
| 6 | +SET:'set', |
| 7 | +INSERT:'insert', |
| 8 | +OPEN_CONSOLE:'openConsole', |
| 9 | +}; |
| 10 | +functioneditorActions(actionString){ |
| 11 | +returnnewPromise(function(resolve,reject){ |
| 12 | +varcommand=action_helpers_1.getCommand(actionString); |
| 13 | +varparams=action_helpers_1.getParams(actionString); |
| 14 | +switch(command){ |
| 15 | +caseType.OPEN: |
| 16 | +varobj=action_helpers_1.getOptions(params[0]); |
| 17 | +varfile=obj.param; |
| 18 | +varoptions=obj.options; |
| 19 | +if(params.length===1){ |
| 20 | +editor_1.open(file,options); |
| 21 | +setTimeout(function(){ |
| 22 | +resolve(); |
| 23 | +},100); |
| 24 | +} |
| 25 | +break; |
| 26 | +caseType.SET: |
| 27 | +if(params.length===1){ |
| 28 | +varcontent_1=params[0]; |
| 29 | +setTimeout(function(){ |
| 30 | +editor_1.set(content_1); |
| 31 | +resolve(true); |
| 32 | +}); |
| 33 | +} |
| 34 | +break; |
| 35 | +caseType.INSERT: |
| 36 | +if(params.length===1){ |
| 37 | +varcontent_2=params[0]; |
| 38 | +setTimeout(function(){ |
| 39 | +editor_1.insert(content_2,{}); |
| 40 | +resolve(true); |
| 41 | +}); |
| 42 | +} |
| 43 | +break; |
| 44 | +caseType.OPEN_CONSOLE: |
| 45 | +if(params.length===0){ |
| 46 | +setTimeout(function(){ |
| 47 | +editor_1.openDevTools(); |
| 48 | +resolve(true); |
| 49 | +}); |
| 50 | +} |
| 51 | +break; |
| 52 | +default: |
| 53 | +console.log('Invalid editor action command'); |
| 54 | +reject(false); |
| 55 | +} |
| 56 | +}).catch(function(err){ |
| 57 | +console.error('Error with editor',err); |
| 58 | +}); |
| 59 | +} |
| 60 | +exports.editorActions=editorActions; |