mirror of
https://github.com/antos-rde/antosdk-apps.git
synced 2024-12-27 04:28:21 +01:00
1 line
5.0 KiB
JavaScript
1 line
5.0 KiB
JavaScript
(function(){var t;(t=class extends this.OS.application.BaseApplication{constructor(t){super("DiffEditor",t)}main(){var t,e,i,r,s,o;for(this.editor_cnt=this.find("diffeditor"),this.fileview=this.find("fileview"),this.fileview.fetch=t=>new Promise((e,i)=>t.asFileHandle().read().then(t=>t.error?i(t.error):e(t.result)).catch(t=>i(__e(t)))),this.fileview.onfileopen=t=>{if(t.data&&t.data.path&&"dir"!==t.data.type)return this.openFile(t.data.path.asFileHandle())},this.currdir=void 0,ace.require("ace/ext/language_tools"),this.modelist=ace.require("ace/ext/modelist"),this.differ=new AceDiff({element:this.editor_cnt,theme:"ace/theme/monokai",left:{content:""},right:{content:""}}),this.editors=this.differ.getEditors(),r={enableBasicAutocompletion:!0,enableSnippets:!0,enableLiveAutocompletion:!0,highlightActiveLine:!0,highlightSelectedWord:!0,behavioursEnabled:!0,fontSize:"10pt",showInvisibles:!0},this.editors.left.setOptions(r),this.editors.right.setOptions(r),this.editors.left.current_file=void 0,this.editors.right.current_file=void 0,this.editors.left.afx_label=this.find("left-file"),this.editors.right.afx_label=this.find("right-file"),this.editors.left.mux=!1,this.editors.right.mux=!1,this.on("resize",()=>(this.editors=this.differ.getEditors(),this.editors.left.resize(),this.editors.right.resize())),$(".acediff__left .ace_scrollbar-v",this.editor_cnt).scroll(()=>this.editors.right.session.setScrollTop(this.editors.left.session.getScrollTop())),$(".acediff__right .ace_scrollbar-v",this.editor_cnt).scroll(()=>this.editors.left.session.setScrollTop(this.editors.right.session.getScrollTop())),this.editors.left.on("focus",t=>this.current_editor=this.editors.left),this.editors.right.on("focus",t=>this.current_editor=this.editors.right),this.editors.left.on("input",t=>this.editors.left.mux?this.editors.left.mux=!1:this.editors.left.current_file?this.editors.left.current_file.dirty?void 0:(this.editors.left.current_file.dirty=!0,this.editors.left.afx_label.text+="*"):this.editors.left.afx_label.text=__("Temporary file")),this.editors.right.on("input",t=>this.editors.right.mux?this.editors.right.mux=!1:this.editors.right.current_file?this.editors.right.current_file.dirty?void 0:(this.editors.right.current_file.dirty=!0,this.editors.right.afx_label.text+="*"):this.editors.right.afx_label.text=__("Temporary file")),this.current_editor=this.editors.left,this.current_editor.focus(),i=[],t=0,e=(s=this.modelist.modes).length;t<e;t++)o=s[t],i.push({text:o.caption,mode:o.mode});return this.langlist=this.find("langmode"),this.langlist.data=i,this.langlist.onlistselect=t=>(this.editors.left.getSession().setMode(t.data.item.data.mode),this.editors.right.getSession().setMode(t.data.item.data.mode)),this.bindKey("ALT-O",()=>this.menuAction("open")),this.bindKey("ALT-F",()=>this.menuAction("opendir")),this.bindKey("CTRL-S",()=>this.menuAction("save")),this.toggleSideBar()}toggleSideBar(){return this.currdir?($(this.fileview).show(),this.fileview.path=this.currdir.path):$(this.fileview).hide(),this.trigger("resize")}menu(){return[{text:__("File"),nodes:[{text:__("Open"),dataid:"open",shortcut:"A-O"},{text:__("Open Folder"),dataid:"opendir",shortcut:"A-F"},{text:__("Save"),dataid:"save",shortcut:"C-S"}],onchildselect:t=>this.menuAction(t.data.item.data.dataid)}]}openFile(t){return this.current_editor.mux=!0,t.read().then(e=>{var i,r,s,o,h,l;for(t.cache=e,this.current_editor.current_file=t,this.current_editor.afx_label.text=t.path,this.current_editor.setValue(e,-1),h=this.modelist.getModeForPath(t.path),i=s=0,o=(l=this.langlist.data).length;s<o;i=++s)l[i].mode===h.mode&&(r=i);if(void 0!==r)return this.langlist.selected=r})}menuAction(t){var e;switch(t){case"open":return this.openDialog("FileDialog",{title:__("Open file"),mimes:["text/.*","application/json","application/javascript"]}).then(t=>this.openFile(t.file.path.asFileHandle()));case"opendir":return this.openDialog("FileDialog",{title:__("Open folder"),mimes:["dir"]}).then(t=>(this.currdir=t.file.path.asFileHandle(),this.toggleSideBar()));case"save":return(e=t=>{if(t.current_file&&t.current_file.dirty)return t.current_file.cache=t.getValue(),t.current_file.write("text/plain").then(e=>(t.current_file.dirty=!1,t.afx_label.text=t.current_file.path,this.notify(__("File {0} saved",t.current_file.path)))).catch(e=>this.error(__("Unable to save to: {0}",t.current_file.path),e))})(this.editors.left),e(this.editors.right);default:return console.log(t)}}cleanup(t){var e;return e=!1,this.editors.left.current_file&&this.editors.left.current_file.dirty&&(e=!0),this.editors.right.current_file&&this.editors.right.current_file.dirty&&(e=!0),e?(t.preventDefault(),this.ask({title:__("Unsaved changes"),text:__("Ignore modification ?")}).then(t=>{if(t)return this.editors.left.current_file.dirty=!1,this.editors.right.current_file.dirty=!1,this.quit()})):this.differ.destroy()}}).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","pkg://AceDiff/main.js","pkg://AceDiff/main.css"],this.OS.register("DiffEditor",t)}).call(this); |