mirror of
https://github.com/antos-rde/antosdk-apps.git
synced 2025-07-26 02:39:45 +02:00
correct more app
This commit is contained in:
@ -3,20 +3,18 @@ class TinyEditor extends this.OS.GUI.BaseApplication
|
||||
super "TinyEditor", args
|
||||
|
||||
main: () ->
|
||||
me = @
|
||||
@editor = @find "editor"
|
||||
@bindKey "ALT-N", () -> me.newFile()
|
||||
@bindKey "ALT-O", () -> me.openFile()
|
||||
@bindKey "CTRL-S", () -> me.saveFile()
|
||||
@filehandler = if @args and @args.length > 0 then @args[0].asFileHandler() else null
|
||||
$(@editor).on 'input', (e) ->
|
||||
return if me.filehandler.dirty is true
|
||||
me.filehandler.dirty = true
|
||||
me.scheme.set "apptitle", "#{me.filehandler.path}*"
|
||||
@bindKey "ALT-N", () => @newFile()
|
||||
@bindKey "ALT-O", () => @openFile()
|
||||
@bindKey "CTRL-S", () => @saveFile()
|
||||
@filehandle = if @args and @args.length > 0 then @args[0].asFileHandle() else null
|
||||
$(@editor).on 'input', (e) =>
|
||||
return if @filehandle.dirty is true
|
||||
@filehandle.dirty = true
|
||||
@scheme.set "apptitle", "#{@filehandle.path}*"
|
||||
@read()
|
||||
|
||||
menu: () ->
|
||||
me = @
|
||||
m = [
|
||||
{
|
||||
text: "__(File)",
|
||||
@ -25,60 +23,62 @@ class TinyEditor extends this.OS.GUI.BaseApplication
|
||||
{ text: "__(Open)", dataid :"open", shortcut: 'A-O' },
|
||||
{ text: "__(Save)", dataid :"save", shortcut: 'C-S' }
|
||||
],
|
||||
onmenuselect: (e) ->
|
||||
switch e.item.data.dataid
|
||||
when "new" then me.newFile()
|
||||
when "open" then me.openFile()
|
||||
when "save" then me.saveFile()
|
||||
onchildselect: (e) =>
|
||||
switch e.data.item.get("data").dataid
|
||||
when "new" then @newFile()
|
||||
when "open" then @openFile()
|
||||
when "save" then @saveFile()
|
||||
}
|
||||
]
|
||||
m
|
||||
|
||||
newFile: () ->
|
||||
@filehandler = null
|
||||
@filehandle = null
|
||||
@read()
|
||||
|
||||
openFile: () ->
|
||||
me = @
|
||||
@openDialog "FileDiaLog", ( dir, fname, d ) ->
|
||||
me.filehandler = "#{dir}/#{fname}".asFileHandler()
|
||||
me.read()
|
||||
, __("Open file")
|
||||
@openDialog "FileDialog", { title: __("Open file") }
|
||||
.then (d) =>
|
||||
@filehandle = d.file.path.asFileHandle()
|
||||
@read()
|
||||
,
|
||||
|
||||
saveFile: () ->
|
||||
me = @
|
||||
@filehandler.cache = @editor.value
|
||||
return @write() unless @filehandler.path is "Untitled"
|
||||
@openDialog "FileDiaLog", (dir, fname, d) ->
|
||||
me.filehandler.setPath "#{dir}/#{fname}"
|
||||
me.write()
|
||||
, __("Save as"), { file: me.filehandler }
|
||||
@filehandle.cache = @editor.value
|
||||
return @write() unless @filehandle.path is "Untitled"
|
||||
@openDialog("FileDialog", {
|
||||
title: __("Save as"),
|
||||
file: @filehandle
|
||||
}).then (f) =>
|
||||
d = f.file.path.asFileHandle()
|
||||
d = d.parent() if f.file.type is "file"
|
||||
@filehandle.setPath "#{d.path}/#{f.name}"
|
||||
@write()
|
||||
|
||||
read: () ->
|
||||
me = @
|
||||
@editor.value = ""
|
||||
if @filehandler is null
|
||||
@filehandler = "Untitled".asFileHandler()
|
||||
if @filehandle is null
|
||||
@filehandle = "Untitled".asFileHandle()
|
||||
@scheme.set "apptitle", "Untitled"
|
||||
return
|
||||
@filehandler.read (d) ->
|
||||
me.scheme.set "apptitle", me.filehandler.path
|
||||
me.editor.value = d
|
||||
@filehandle.read().then (d) =>
|
||||
@scheme.set "apptitle", @filehandle.path
|
||||
@editor.value = d
|
||||
.catch (e) => @error __("Unable to read file content")
|
||||
|
||||
write: () ->
|
||||
me = @
|
||||
@filehandler.write "text/plain", (d) ->
|
||||
return me.error __("Error saving file {0}", me.filehandler.path) if d.error
|
||||
me.filehandler.dirty = false
|
||||
me.scheme.set "apptitle", "#{me.filehandler.path}"
|
||||
@filehandle.write("text/plain").then (d) =>
|
||||
@filehandle.dirty = false
|
||||
@scheme.set "apptitle", "#{@filehandle.path}"
|
||||
.catch (e) => @error __("Error saving file {0}", @filehandle.path), e
|
||||
|
||||
|
||||
cleanup: (e) ->
|
||||
return unless @filehandler.dirty
|
||||
me = @
|
||||
return unless @filehandle.dirty
|
||||
e.preventDefault()
|
||||
@ask "__(Quit)", "__(Quit without saving?)", () ->
|
||||
me.filehandler.dirty = false
|
||||
me.quit()
|
||||
@ask { title: "__(Quit)", text: "__(Quit without saving?)" }
|
||||
.then () =>
|
||||
@filehandle.dirty = false
|
||||
@quit()
|
||||
|
||||
this.OS.register "TinyEditor", TinyEditor
|
Reference in New Issue
Block a user