add Files package features

This commit is contained in:
Xuan Sang LE 2018-01-25 00:49:02 +01:00
parent 7e62d71913
commit d998ac4b66
5 changed files with 67 additions and 9 deletions

View File

@ -46,7 +46,7 @@ class BasicDialog extends BaseDialog
init: () ->
html = "<afx-app-window data-id = 'dia-window' apptitle='#{@name}' width='#{@conf.width}' height='#{@conf.height}'>
<afx-hbox>"
html += "<#{@conf.tag} data-id = 'content'></#{@conf.tag}>"
html += "<#{@conf.tag} #{@conf.att} data-id = 'content'></#{@conf.tag}>"
html += "<div data-height = '40' style=' text-align:right;padding-top:3px;'>"
html += "<afx-button data-id = 'bt#{k}' text = '#{v.label}' style='margin-right:5px;'></afx-button>" for k,v of @conf.buttons
html += "</div></afx-hbox></afx-app-window>"
@ -64,6 +64,33 @@ class BasicDialog extends BaseDialog
this.OS.GUI.BasicDialog = BasicDialog
class PromptDialog extends BasicDialog
constructor: () ->
super "PromptDialog", {
tag: "input",
width: 200,
height: 90,
resizable: false,
buttons: [
{
label: "0k",
onclick: (d) ->
txt = (d.find "content").value
return d.quit() if txt is ""
d.handler txt if d.handler
d.quit()
},
{
label: "Cancel",
onclick: (d) -> d.quit()
}
],
filldata: (d) ->
d.scheme.set "apptitle", d.data if d.data
}
this.OS.register "PromptDialog", PromptDialog
class CalendarDialog extends BasicDialog
constructor: () ->
super "CalendarDialog", {
@ -129,6 +156,7 @@ class InfoDialog extends BasicDialog
rows = []
rows.push [ { value: k }, { value: v } ] for k, v of d.data
(d.find "content").set "rows", rows
d.scheme.set "apptitle", d.data.filename
}
this.OS.register "InfoDialog", InfoDialog

View File

@ -18,6 +18,11 @@ self.OS.API.handler =
_API.get path + p, c, (e, s) ->
_courrier.osfail "Fail to read file: #{p}",e , s
write: (p, d , c) ->
path = "lua-api/fs/write"
_API.post path, { path: p, data: d }, c, (e, s) ->
_courrier.osfail "Fail to write to file: #{p}", e, s
scanapp: (p, c ) ->
path = "lua-api/system/application"
auth: (c) ->

View File

@ -135,7 +135,7 @@
event.preventUpdate = true
return
}
if(self.selidx != -1)
if(self.selidx != -1 && self.selidx < self.items.length)
self.items[self.selidx].selected =false
event.item.item.selected = true
}

View File

@ -101,6 +101,8 @@ class RemoteFileHandler extends self.OS.API.VFS.BasicFileHandler
when "mk"
return f { error: "#{@path} is not a directory" } if @meta.type is "file"
_API.handler.mkdir "#{@path}/#{p}", f
when "write"
_API.handler.write @path, p, f
else
return _courrier.osfail "VFS unknown action: #{n}", (_API.throwe "OS.VFS"), n

View File

@ -17,18 +17,18 @@ class Files extends this.OS.GUI.BaseApplication
#@on "fileselect", (d) -> console.log d
@on "filedbclick", (e) ->
#if e.data.type is 'dir' then me.chdir e.data.path, true
@favo.set "onlistselect", (e) -> me.chdir e.data.path, true
@favo.set "onlistselect", (e) -> me.chdir e.data.path
($ @find "btback").click () ->
return if me.currdir.isRoot()
p = me.currdir.parent()
me.favo.set "selected", -1
me.chdir p, false
me.chdir p
($ @navinput).keyup (e) ->
me.chdir ($ me.navinput).val() if e.keyCode is 13 #enter
@view.set "chdir", (p) -> me.chdir p, true
@view.set "chdir", (p) -> me.chdir p
@view.set "fetch", (e, f) ->
return unless e.child
me._api.handler.scandir e.child.path,
@ -56,7 +56,7 @@ class Files extends this.OS.GUI.BaseApplication
chdir: (p, push) ->
me = @
dir = p.asFileHandler()
dir = if p then p.asFileHandler() else me.currdir
dir.read (d) ->
if(d.error)
return me.error "Resource not found #{p}"
@ -66,13 +66,14 @@ class Files extends this.OS.GUI.BaseApplication
me.view.set "data", d.result
mnFile:() ->
me = @
{
text: "File",
child: [
{ text: "New file", dataid: "#{@name}-mkf" },
{ text: "New folder", dataid: "#{@name}-mkdir" },
{ text: "Upload", dataid: "#{@name}-upload" }
]
], onmenuselect: (e) -> me.actionFile e
}
mnEdit: () ->
me = @
@ -126,7 +127,7 @@ class Files extends this.OS.GUI.BaseApplication
@registry "showhidden",e.item.data.checked
#@.setting.showhidden = e.item.data.checked
when "#{@name}-refresh"
@.chdir ($ @.navinput).val(), false
@.chdir ($ @.navinput).val()
when "#{@name}-side"
@registry "sidebar",e.item.data.checked
#@setting.sidebar = e.item.data.checked
@ -138,11 +139,33 @@ class Files extends this.OS.GUI.BaseApplication
actionEdit: (e) ->
switch e.item.data.dataid
when "#{@.name}-info"
when "#{@name}-info"
file = @view.get "selectedFile"
return unless file
@openDialog "InfoDialog", null, file
when "#{@name}-mkdir"
console.log "mkdir"
@openDialog "PromptDialog", (d) -> console.log d
else
@_api.handler.setting()
actionFile: (e) ->
me = @
switch e.item.data.dataid
when "#{@name}-mkdir"
@openDialog "PromptDialog",
(d) ->
me.currdir.mk d, (r) ->
if r.result then me.chdir null else me.error "Fail to create #{d}"
, "New folder"
when "#{@name}-mkf"
@openDialog "PromptDialog",
(d) ->
fp = "#{me.currdir.path}/#{d}".asFileHandler()
fp.write "", (r) ->
if r.result then me.chdir null else me.error "Fail to create #{d}"
, "New file"
else
console.log e
this.OS.register "Files", Files