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.lengththis.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))}catch(t){this.logger.error(__("No {0} file found in the current directory, or the file is invalid format","build.json"))}}).catch(t=>{this.logger.error(__("{0} is not installed, please install it: {1}","libantosdk"))})}updateStatus(t){t||(t=this.eum.active.getEditorStatus()),this.editorstat.text=__("Row {0}, col {1}, lines: {2}",t.row+1,t.column+1,t.line),t.langmode&&(this.langstat.text=t.langmode.text),this.filestat.text=t.file;let e=this.scheme;e.apptitle!=t.file&&(e.apptitle=t.file)}toggleSideBar(){this.currdir?($(this.sidebar).show(),this.fileview.path=this.currdir.path):$(this.sidebar).hide(),this.trigger("resize")}showOutput(t=!1){t&&this.showBottomBar(!0),this.bottombar.selectedIndex=0}applySetting(t){"showBottomBar"==t&&this.showBottomBar(this.setting.showBottomBar)}showBottomBar(t){this.setting.showBottomBar=t,t?$(this.bottombar).show():$(this.bottombar).hide(),this.trigger("resize")}toggleBottomBar(){this.showBottomBar(!this.setting.showBottomBar)}toggleSplitMode(){const t=this.find("right-panel"),e=this.eum.editors[1],i=this.eum.editors[0];if(this.split_mode){if(e.isDirty())return void this.notify(__("Unable to disable split view: Please save changes of modified files on the right panel"));e.closeAll(),$(t).hide(),this.split_mode=!1,i.focus()}else $(t).show(),this.split_mode=!0,e.openFile("Untitled".asFileHandle()),e.focus();this.trigger("resize")}fileMenu(){const t=this.setting.recent.map(t=>({text:t}));return{text:__("File"),nodes:[{text:__("New"),dataid:"new",shortcut:"A-N"},{text:__("Open Recent"),dataid:"recent",nodes:t,onchildselect:(t,e)=>{const i=t.data.item.data.text.asFileHandle();i.onready().then(t=>{t&&("dir"==t.type?(this.currdir=i,this.toggleSideBar()):this.eum.active.openFile(i))})}},{text:__("Open"),dataid:"open",shortcut:"A-O"},{text:__("Open Folder"),dataid:"opendir",shortcut:"A-F"},{text:__("Save"),dataid:"save",shortcut:"C-S"},{text:__("Save as"),dataid:"saveas",shortcut:"A-W"}],onchildselect:(t,e)=>this.menuAction(t.data.item.data.dataid,e)}}ctxFileMenuHandle(t){const e=t.data.item;if(!e)return;const i=e.data;if(!i)return;let s=this.fileview.selectedFile,a=this.currdir;switch(s&&"dir"===s.type&&(a=s.path.asFileHandle()),s&&"file"===s.type&&(a=s.path.asFileHandle().parent()),i.id){case"new":if(!a)return;this.openDialog("PromptDialog",{title:"__(New file)",label:"__(File name)"}).then(async t=>{const e=`${a.path}/${t}`.asFileHandle();try{return await e.write("text/plain"),this.fileview.update(a.path)}catch(t){return this.error(__("Fail to create: {0}",t.stack),t)}});break;case"newdir":if(!a)return;this.openDialog("PromptDialog",{title:"__(New folder)",label:"__(Folder name)"}).then(async t=>{try{return await a.mk(t),this.fileview.update(a.path)}catch(t){return this.error(__("Fail to create: {0}",a.path),t)}});break;case"rename":if(!s)return;this.openDialog("PromptDialog",{title:"__(Rename)",label:"__(File name)",value:s.filename}).then(async t=>{if(t!==s.filename){s=s.path.asFileHandle(),a=s.parent();try{return await s.move(`${a.path}/${t}`),this.fileview.update(a.path)}catch(t){return this.error(__("Fail to rename: {0}",s.path),t)}}});break;case"delete":if(!s)return;this.openDialog("YesNoDialog",{title:"__(Delete)",iconclass:"fa fa-question-circle",text:__("Do you really want to delete: {0}?",s.filename)}).then(async t=>{if(t){s=s.path.asFileHandle(),a=s.parent();try{return await s.remove(),this.fileview.update(a.path)}catch(t){return this.error(__("Fail to delete: {0}",s.path),t)}}})}}addRecent(t){this.setting.recent||(this.setting.recent=[]),this.setting.recent.includes(t)||(this.setting.recent.push(t),this.setting.recent.length>10&&(this.setting.recent=this.setting.recent.slice(0,10)))}menuAction(t,e){let i=this;switch(e&&(i=e),t){case"new":return i.eum.active.openFile("Untitled".asFileHandle());case"open":return i.openDialog("FileDialog",{title:__("Open file"),mimes:Array.from(i.meta().mimes).filter(t=>"dir"!==t)}).then(t=>{this.addRecent(t.file.path),i.eum.active.openFile(t.file.path.asFileHandle())});case"opendir":return i.openDialog("FileDialog",{title:__("Open folder"),mimes:["dir"]}).then((function(t){return i.addRecent(t.file.path),i.currdir=t.file.path.asFileHandle(),i.toggleSideBar()}));case"save":return i.eum.active.save();case"saveas":return i.eum.active.saveAs();default:return console.log(t)}}cleanup(t){let e;const i=this.eum.dirties();if(0!==i.length)t.preventDefault(),this.openDialog("YesNoDialog",{title:"__(Quit)",text:__("Ignore all unsaved files: {0} ?",(()=>{const t=[];for(e of Array.from(i))t.push(e.filename);return t})().join(", "))}).then(t=>{if(t){for(e of Array.from(i))e.dirty=!1;return this.quit(!1)}});else for(let t in this.extensions)this.extensions[t].ext&&this.extensions[t].ext.cleanup&&this.extensions[t].ext.cleanup()}menu(){return[this.fileMenu(),{text:"__(View)",nodes:[{text:"__(Toggle bottom bar)",dataid:"bottombar"},{text:"__(Toggle split view)",dataid:"splitview"}],onchildselect:(t,e)=>{switch(t.data.item.data.dataid){case"bottombar":return this.toggleBottomBar();case"splitview":return this.toggleSplitMode()}}}]}}e.CodePad=i;class s{constructor(){this.active_editor=void 0,this.models=[]}get editors(){return this.models}set contextmenuHandle(t){for(let e of this.models)e.contextmenuHandle=t}get active(){return this.active_editor}add(t){return this.models.push(t),this.active_editor||(this.active_editor=t),t.on("focus",()=>{this.active_editor=t}),this}set onstatuschange(t){for(let e of this.models)e.onstatuschange=t}dirties(){let t=[];for(let e of this.models)t=t.concat(e.dirties());return t}resize(){for(let t of this.models)t.resize()}}class a{constructor(t){this.target=t}info(t){this.log("info",t,!0)}warn(t){this.log("warn",t,!0)}error(t){this.log("error",t,!0)}log(t,e,i){let s=$("
").attr("class","code-pad-log-"+t);if(i){let t=new Date,i=t.getDate()+"/"+(t.getMonth()+1)+"/"+t.getFullYear()+" "+t.getHours()+":"+t.getMinutes()+":"+t.getSeconds();s.text(`[${i}]: ${e.__()}`)}else s.text(e.__());$(this.target).append(s),$(this.target).scrollTop($(this.target)[0].scrollHeight)}print(t){this.log("info",t,!1)}clear(){$(this.target).empty()}}i.Logger=a,i.dependencies=["pkg://ACECore/core/ace.js","pkg://ACECore/path.js","pkg://ACECore/core/ext-language_tools.js","pkg://ACECore/core/ext-modelist.js","pkg://ACECore/core/ext-themelist.js"]}(e=t.application||(t.application={}))}(OS||(OS={})),function(t){let e;!function(t){t.BaseEditorModel=class{constructor(t,e,i){this.container=i,this.currfile="Untitled".asFileHandle(),this.tabbar=e,this.editorSetup(i),this.app=t,this.editormux=!1,this.onstatuschange=void 0,this.on("focus",()=>{this.onstatuschange&&this.onstatuschange(this.getEditorStatus())}),this.on("input",()=>this.editormux?(this.editormux=!1,!1):this.currfile.dirty?void 0:(this.currfile.dirty=!0,this.currfile.text+="*",this.tabbar.update(void 0))),this.on("changeCursor",()=>{this.onstatuschange&&this.onstatuschange(this.getEditorStatus())}),this.tabbar.ontabselect=t=>this.selecteTab($(t.data.item).index()),this.tabbar.ontabclose=t=>{const e=t.data.item;return!!e&&(e.data.dirty?(this.app.openDialog("YesNoDialog",{title:__("Close tab"),text:__("Close without saving ?")}).then(t=>t?this.closeTab(e):this.focus()),!1):this.closeTab(e))}}findTabByFile(t){const e=this.tabbar.items,i=(()=>{const i=[];for(let s=0;s(t.cache=e||"",this.newTab(t))).catch(e=>this.app.error(__("Unable to open: {0}",t.path),e)):this.newTab(t):this.tabbar.selected=e}write(t){this.currfile.cache=this.getValue(),t.write("text/plain").then(e=>{t.dirty=!1,t.text=t.basename,this.tabbar.update(void 0)}).catch(e=>this.app.error(__("Unable to save file: {0}",t.path),e))}save(){return this.currfile.cache=this.getValue(),this.currfile.basename?this.write(this.currfile):this.saveAs()}saveAs(){this.app.openDialog("FileDialog",{title:__("Save as"),file:this.currfile}).then(t=>{let e=t.file.path.asFileHandle();"file"===t.file.type&&(e=e.parent()),this.currfile.setPath(`${e.path}/${t.name}`),this.write(this.currfile)})}dirties(){const t=[];for(let e of Array.from(this.tabbar.items))e.dirty&&t.push(e);return t}set contextmenuHandle(t){this.container.contextmenuHandle=t}closeAll(){this.tabbar.items=[],this.resetEditor()}isDirty(){return this.dirties().length>0}}}(e=t.application||(t.application={}))}(OS||(OS={})),function(t){let e;!function(t){class e extends t.BaseEditorModel{constructor(t,e,i){ace.require("ace/ext/language_tools"),super(t,e,i),this.modes=ace.require("ace/ext/modelist")}resetEditor(){this.setValue(""),this.editor.getSession().setUndoManager(new ace.UndoManager)}getTexModel(){const t={};return t.cursor=this.editor.getCursorPosition(),t.cache=this.getValue(),t.um=this.editor.session.getUndoManager(),t.langmode=this.mode,t}setTextModel(t){this.editor.getSession().setUndoManager(new ace.UndoManager),this.setValue(t.cache),this.setMode(t.langmode),t.cursor&&this.setCursor(t.cursor),this.editor.getSession().setUndoManager(t.um)}newTextModelFrom(t){const e={};return e.um=new ace.UndoManager,e.cache=t.cache,e.cursor=void 0,"Untitled"!==t.path.toString()?e.langmode=this.getModeForPath(t.path):e.langmode={text:"Text",mode:"ace/mode/text"},e}getModes(){const t=[];let e;for(e of Array.from(this.modes.modes))t.push({text:e.caption,mode:e.mode});return t}setTheme(t){this.editor.setTheme(t)}setCursor(t){this.editor.renderer.scrollCursorIntoView({row:t.row,column:t.column},.5),this.editor.selection.moveTo(t.row,t.column)}setMode(t){this.mode=t,this.editor.getSession().setMode(t.mode)}editorSetup(t){this.editor=ace.edit(t),this.editor.setOptions({enableBasicAutocompletion:!0,enableSnippets:!0,enableLiveAutocompletion:!0,highlightActiveLine:!0,highlightSelectedWord:!0,behavioursEnabled:!0,wrap:!0,fontSize:"10pt",showInvisibles:!0}),this.editor.setTheme("ace/theme/monokai"),this.editor.completers.push({getCompletions(t,e,i,s,a){}}),this.editor.getSession().setUseWrapMode(!0)}on(t,e){switch(t){case"input":case"focus":this.editor.on(t,e);break;case"changeCursor":this.editor.getSession().selection.on(t,e)}}resize(){this.editor.resize()}focus(){this.editor.focus()}getModeForPath(t){const e=this.modes.getModeForPath(t);return{text:e.caption,mode:e.mode}}getEditorStatus(){const t=this.editor.session.selection.getCursor(),e=this.editor.session.getLength();return{row:t.row,column:t.column,line:e,langmode:this.mode,file:this.currfile.path}}getValue(){return this.editor.getValue()}setValue(t){this.editor.setValue(t,-1)}getThemes(){const t=ace.require("ace/ext/themelist"),e=[];for(let i in t.themesByName){const s=t.themesByName[i];e.push({text:s.caption,theme:s.theme})}return e}}t.ACEModel=e}(e=t.application||(t.application={}))}(OS||(OS={}));