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

1 line
29 KiB
JavaScript
Raw Normal View History

2022-07-04 19:58:51 +02:00
var OS;!function(t){let e,i;!function(e){let i;!function(e){class i extends t.API.VFS.BaseFileHandle{constructor(t){super(""),this.path=`${t[0].path} -> ${t[1].path}`,this.cache=t,this.basename=`${t[0].basename} -> ${t[1].basename}`,this.info={type:"file",mime:void 0,size:0,name:this.basename,path:this.path},this.ready=!0}meta(){return new Promise(async(t,e)=>{try{await Promise.all([this.cache[0].meta(),this.cache[1].meta]),t({result:this.info,error:!1})}catch(t){e(t)}})}_rd(t){return new Promise(async(t,e)=>{try{this.cache[0].cache=await this.cache[0].read(),this.cache[1].cache=await this.cache[1].read(),t(this.cache)}catch(t){e(t)}})}_wr(t,e){return this.cache=e,new Promise((t,e)=>{t({result:!0,error:!1})})}setPath(t){}}e.DiffEditorFileHandle=i}(i=e.VFS||(e.VFS={}))}(e=t.API||(t.API={})),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.onstatuschange=void 0,this.on("focus",()=>{this.onstatuschange&&this.onstatuschange(this.getEditorStatus())}),this.on("input",()=>{if(!this.currfile.dirty)return console.log("dirty",this.currfile.path),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 a=0;a<e.length;a++)e[a].hash()===t.hash()&&i.push(a);return i})();return 0===i.length?-1:i[0]}newTab(t){t.text=t.basename?t.basename:t.path,t.cache||(t.cache=""),t.textModel=this.newTextModelFrom(t),this.currfile.selected=!1,t.selected=!0,this.tabbar.push(t)}closeTab(t){this.tabbar.delete(t);const e=this.tabbar.items.length;return 0===e?(this.openFile("Untitled".asFileHandle()),!1):(this.tabbar.selected=e-1,!1)}selecteTab(t){const e=this.tabbar.items[t];e&&(this.currfile!==e&&(this.currfile.textModel=this.getTexModel(),this.currfile.selected=!1,this.currfile=e),this.setTextModel(e.textModel),this.focus())}selectFile(t){const e=this.findTabByFile(t.asFileHandle());-1!==e&&(this.tabbar.selected=e)}openFile(t){const e=this.findTabByFile(t);-1===e?"Untitled"!==t.path.toString()?t.read().then(e=>(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(){this.currfile.cache=this.getValue(),this.currfile.write("text/plain").then(t=>{this.currfile.dirty=!1,this.currfile.text=this.currfile.basename,this.tabbar.update(void 0)}).catch(t=>this.app.error(__("Unable to save file: {0}",this.currfile.path),t))}save(){return this.currfile.cache=this.getValue(),this.currfile.basename?this.write():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()})}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.openFile("Untitled".asFileHandle()),this.resetEditor()}isDirty(){return this.dirties().length>0}setTabbarCtxMenu(t,e){this.tabbar.contextmenuHandle=(i,a)=>(a.items=t,a.onmenuselect=t=>{if(e){const a=$(i.target).closest("afx-list-item");e(a[0],t.data.item.data)}},a.show(i))}}}(i=t.application||(t.application={}))}(OS||(OS={})),function(t){let e;!function(e){class i extends t.application.BaseEditorModel{constructor(t,e,i){super(t,e,i)}resetEditor(){}getTexModel(){return{model:this.editor.getModel(),position:this.editor.getPosition()}}setTextModel(t){this.editor.setModel(t.model),t.position&&(this.editor.setPosition(t.position),this.editor.revealLineInCenter(t.position.lineNumber))}