antosdk-apps/CodePad/build/debug/main.js

1 line
15 KiB
JavaScript
Raw Normal View History

var ace,OS;!function(t){let e;!function(e){class i extends e.BaseApplication{constructor(t){super("CodePad",t),this.currdir=void 0,this.sdk=void 0}main(){this.extensions={},this.eum=new s,this.fileview=this.find("fileview"),this.sidebar=this.find("sidebar"),this.bottombar=this.find("bottombar"),this.langstat=this.find("langstat"),this.editorstat=this.find("editorstat"),this.filestat=this.find("current-file-lbl"),this.logger=new a(this.find("output-tab")),this.split_mode=!0,this.eum.add(new e.ACEModel(this,this.find("left-tabbar"),this.find("left-editorarea"))).add(new e.ACEModel(this,this.find("right-tabbar"),this.find("right-editorarea"))),this.eum.onstatuschange=t=>this.updateStatus(t),this.fileview.fetch=t=>new Promise((async function(e,i){let s;s="string"==typeof t?t.asFileHandle():t;try{const t=await s.read();return t.error?i(t.error):e(t.result)}catch(t){return i(__e(t))}}));let t="Untitled".asFileHandle();return this.args&&this.args.length>0&&(this.addRecent(this.args[0].path),"dir"===this.args[0].type?this.currdir=this.args[0].path.asFileHandle():(t=this.args[0].path.asFileHandle(),this.currdir=t.parent())),this.setup(),this.eum.active.openFile(t)}setup(){this.setting.recent||(this.setting.recent=[]),this.fileview.onfileopen=t=>{if(t.data&&t.data.path&&"dir"!==t.data.type)return this.addRecent(t.data.path),this.eum.active.openFile(t.data.path.asFileHandle())},this.fileview.onfileselect=t=>{t.data&&t.data.path&&"dir"!==t.data.type&&this.eum.active.selectFile(t.data.path)},this.on("resize",()=>this.eum.resize()),this.on("focus",()=>this.eum.active.focus()),this.eum.contextmenuHandle=(t,e)=>(e.items=[{text:__("Change theme"),onmenuselect:async t=>{try{const t=this.eum.active.getThemes(),e=await this.openDialog("SelectionDialog",{title:__("Select theme"),data:t});this.eum.active.setTheme(e.theme)}catch(t){this.error(__("Unable to set theme"),t)}}},{text:__("Change language mode"),onmenuselect:async t=>{try{const t=this.eum.active.getModes().map(t=>({text:t.text,mode:t.mode})),e=await this.openDialog("SelectionDialog",{title:__("Select language"),data:t});this.eum.active.setMode(e)}catch(t){this.error(__("Unable to set language mode"),t)}}},{text:__("Build with AntOSDK"),shortcut:" (CTRL-ALT-B)",onmenuselect:async t=>{try{this.build()}catch(t){this.error(__("Unable to build with AntOSDK: {0}",t.toString()),t)}}}],e.show(t)),this.fileview.contextmenuHandle=(t,e)=>(e.items=[{text:"__(New file)",id:"new"},{text:"__(New folder)",id:"newdir"},{text:"__(Rename)",id:"rename"},{text:"__(Delete)",id:"delete"}],e.onmenuselect=t=>this.ctxFileMenuHandle(t),e.show(t)),this.bindKey("ALT-N",()=>this.menuAction("new")),this.bindKey("ALT-O",()=>this.menuAction("open")),this.bindKey("ALT-F",()=>this.menuAction("opendir")),this.bindKey("CTRL-S",()=>this.menuAction("save")),this.bindKey("ALT-W",()=>this.menuAction("saveas")),this.bindKey("CTRL-ALT-B",()=>this.build()),this.fileview.ondragndrop=t=>{const e=t.data.from[0].data.path.asFileHandle(),i=t.data.to.data.path;return e.move(`${i}/${e.basename}`).then((function(s){const a=i,o=e.parent().path;a.length<o.length?(t.data.to.update(a),t.data.from[0].parent.update(o)):(t.data.from[0].parent.update(o),t.data.to.update(a))})).catch(t=>this.error(__("Unable to move file/folder"),t))},this.on("filechange",t=>{let{path:e}=t.file;return"file"===t.type&&({path:e}=t.file.parent()),this.fileview.update(e)}),this.find("logger-clear").onbtclick=()=>{this.logger.clear()},void 0===this.setting.showBottomBar&&(this.setting.showBottomBar=!1),this.toggleSideBar(),this.toggleSplitMode(),this.applyAllSetting()}build(){this.currdir&&t.API.requires("pkg://libantosdk/main.js").then(async()=>{try{if(!t.API.AntOSDKBuilder)return;this.sdk||(this.sdk=new t.API.AntOSDKBuilder(this.logger,"")),this.logger.clear(),this.showBottomBar(!0);const e=(this.currdir.path+"/build.json").asFileHandle(),i=await e.read("json");i.root=this.currdir.path;const s=Object.keys(i.targets).map(t=>({text:t})),a=await this.openDialog("SelectionDialog",{title:__("Select a build target"),data:s});await this.load(this.sdk.batch([a.text],i)