update code

This commit is contained in:
Xuan Sang LE
2020-06-05 17:45:07 +02:00
parent aae08d9efe
commit 676cce26c2
61 changed files with 685 additions and 264 deletions

View File

@@ -1,3 +1,3 @@
# TinyEditor
This is the example project for the tutorial: [https://blog.lxsang.me/post/id/20](https://blog.lxsang.me/post/id/20)
This is the example project for the tutorial: [https://blog.lxsang.me/post/id/20](https://blog.lxsang.me/post/id/20). The tutorial is outdated, it is no longer compatible with the new antos API

View File

@@ -1 +1 @@
(function(){var e;e=class extends this.OS.GUI.BaseApplication{constructor(e){super("TinyEditor",e)}main(){return this.editor=this.find("editor"),this.bindKey("ALT-N",()=>this.newFile()),this.bindKey("ALT-O",()=>this.openFile()),this.bindKey("CTRL-S",()=>this.saveFile()),this.filehandle=this.args&&this.args.length>0?this.args[0].path.asFileHandle():null,$(this.editor).on("input",e=>{if(!0!==this.filehandle.dirty)return this.filehandle.dirty=!0,this.scheme.set("apptitle",this.filehandle.path+"*")}),this.read()}menu(){return[{text:"__(File)",child:[{text:"__(New)",dataid:"new",shortcut:"A-N"},{text:"__(Open)",dataid:"open",shortcut:"A-O"},{text:"__(Save)",dataid:"save",shortcut:"C-S"}],onchildselect:e=>{switch(e.data.item.get("data").dataid){case"new":return this.newFile();case"open":return this.openFile();case"save":return this.saveFile()}}}]}newFile(){return this.filehandle=null,this.read()}openFile(){return this.openDialog("FileDialog",{title:__("Open file")}).then(e=>(this.filehandle=e.file.path.asFileHandle(),this.read()))}saveFile(){return this.filehandle.cache=this.editor.value,"Untitled"!==this.filehandle.path?this.write():this.openDialog("FileDialog",{title:__("Save as"),file:this.filehandle}).then(e=>{var t;return t=e.file.path.asFileHandle(),"file"===e.file.type&&(t=t.parent()),this.filehandle.setPath(`${t.path}/${e.name}`),this.write()})}read(){return this.editor.value="",null===this.filehandle?(this.filehandle="Untitled".asFileHandle(),void this.scheme.set("apptitle","Untitled")):this.filehandle.read().then(e=>(this.scheme.set("apptitle",this.filehandle.path),this.editor.value=e)).catch(e=>this.error(__("Unable to read file content")))}write(){return this.filehandle.write("text/plain").then(e=>(this.filehandle.dirty=!1,this.scheme.set("apptitle",""+this.filehandle.path))).catch(e=>this.error(__("Error saving file {0}",this.filehandle.path),e))}cleanup(e){if(this.filehandle.dirty)return e.preventDefault(),this.ask({title:"__(Quit)",text:"__(Quit without saving?)"}).then(()=>(this.filehandle.dirty=!1,this.quit()))}},this.OS.register("TinyEditor",e)}).call(this);
(function(){var e;e=class extends this.OS.application.BaseApplication{constructor(e){super("TinyEditor",e)}main(){return this.editor=this.find("editor"),this.bindKey("ALT-N",()=>this.newFile()),this.bindKey("ALT-O",()=>this.openFile()),this.bindKey("CTRL-S",()=>this.saveFile()),this.filehandle=this.args&&this.args.length>0?this.args[0].path.asFileHandle():null,$(this.editor).on("input",e=>{if(!0!==this.filehandle.dirty)return this.filehandle.dirty=!0,this.scheme.apptitle=this.filehandle.path+"*"}),this.read()}menu(){return[{text:"__(File)",nodes:[{text:"__(New)",dataid:"new",shortcut:"A-N"},{text:"__(Open)",dataid:"open",shortcut:"A-O"},{text:"__(Save)",dataid:"save",shortcut:"C-S"}],onchildselect:e=>{switch(e.data.item.data.dataid){case"new":return this.newFile();case"open":return this.openFile();case"save":return this.saveFile()}}}]}newFile(){return this.filehandle=null,this.read()}openFile(){return this.openDialog("FileDialog",{title:__("Open file")}).then(e=>(this.filehandle=e.file.path.asFileHandle(),this.read()))}saveFile(){return this.filehandle.cache=this.editor.value,"Untitled"!==this.filehandle.path?this.write():this.openDialog("FileDialog",{title:__("Save as"),file:this.filehandle}).then(e=>{var t;return t=e.file.path.asFileHandle(),"file"===e.file.type&&(t=t.parent()),this.filehandle.setPath(`${t.path}/${e.name}`),this.write()})}read(){return this.editor.value="",null===this.filehandle?(this.filehandle="Untitled".asFileHandle(),void(this.scheme.apptitle="Untitled")):this.filehandle.read().then(e=>(this.scheme.apptitle=this.filehandle.path,this.editor.value=e)).catch(e=>this.error(__("Unable to read file content")))}write(){return this.filehandle.write("text/plain").then(e=>(this.filehandle.dirty=!1,this.scheme.apptitle=""+this.filehandle.path)).catch(e=>this.error(__("Error saving file {0}",this.filehandle.path),e))}cleanup(e){if(this.filehandle.dirty)return e.preventDefault(),this.ask({title:"__(Quit)",text:"__(Quit without saving?)"}).then(e=>{if(e)return this.filehandle.dirty=!1,this.quit()})}},this.OS.register("TinyEditor",e)}).call(this);

View File

@@ -6,7 +6,7 @@
"author": "Xuan Sang LE",
"email": "xsang.le@gmail.com"
},
"version":"0.0.3-a",
"version":"0.0.4-a",
"category":"Other",
"iconclass":"fa fa-adn",
"mimes":["text/.*"]

View File

@@ -1,4 +1,4 @@
class TinyEditor extends this.OS.GUI.BaseApplication
class TinyEditor extends this.OS.application.BaseApplication
constructor: ( args ) ->
super "TinyEditor", args
@@ -11,20 +11,20 @@ class TinyEditor extends this.OS.GUI.BaseApplication
$(@editor).on 'input', (e) =>
return if @filehandle.dirty is true
@filehandle.dirty = true
@scheme.set "apptitle", "#{@filehandle.path}*"
@scheme.apptitle = "#{@filehandle.path}*"
@read()
menu: () ->
m = [
{
text: "__(File)",
child: [
nodes: [
{ text: "__(New)", dataid :"new", shortcut: 'A-N' },
{ text: "__(Open)", dataid :"open", shortcut: 'A-O' },
{ text: "__(Save)", dataid :"save", shortcut: 'C-S' }
],
onchildselect: (e) =>
switch e.data.item.get("data").dataid
switch e.data.item.data.dataid
when "new" then @newFile()
when "open" then @openFile()
when "save" then @saveFile()
@@ -59,17 +59,17 @@ class TinyEditor extends this.OS.GUI.BaseApplication
@editor.value = ""
if @filehandle is null
@filehandle = "Untitled".asFileHandle()
@scheme.set "apptitle", "Untitled"
@scheme.apptitle = "Untitled"
return
@filehandle.read().then (d) =>
@scheme.set "apptitle", @filehandle.path
@scheme.apptitle = @filehandle.path
@editor.value = d
.catch (e) => @error __("Unable to read file content")
write: () ->
@filehandle.write("text/plain").then (d) =>
@filehandle.dirty = false
@scheme.set "apptitle", "#{@filehandle.path}"
@scheme.apptitle = "#{@filehandle.path}"
.catch (e) => @error __("Error saving file {0}", @filehandle.path), e
@@ -77,7 +77,8 @@ class TinyEditor extends this.OS.GUI.BaseApplication
return unless @filehandle.dirty
e.preventDefault()
@ask { title: "__(Quit)", text: "__(Quit without saving?)" }
.then () =>
.then (d) =>
return unless d
@filehandle.dirty = false
@quit()

View File

@@ -6,7 +6,7 @@
"author": "Xuan Sang LE",
"email": "xsang.le@gmail.com"
},
"version":"0.0.3-a",
"version":"0.0.4-a",
"category":"Other",
"iconclass":"fa fa-adn",
"mimes":["text/.*"]