From d998ac4b6657280e5b62e502ba6a87bce1867fce Mon Sep 17 00:00:00 2001 From: Xuan Sang LE Date: Thu, 25 Jan 2018 00:49:02 +0100 Subject: [PATCH] add Files package features --- src/core/BaseDialog.coffee | 30 ++++++++++++++++++++- src/core/handlers/RemoteHandler.coffee | 5 ++++ src/core/tags/afx-list-view.js | 2 +- src/core/vfs.coffee | 2 ++ src/packages/Files/main.coffee | 37 +++++++++++++++++++++----- 5 files changed, 67 insertions(+), 9 deletions(-) diff --git a/src/core/BaseDialog.coffee b/src/core/BaseDialog.coffee index 1cfd133..45bb6b0 100644 --- a/src/core/BaseDialog.coffee +++ b/src/core/BaseDialog.coffee @@ -46,7 +46,7 @@ class BasicDialog extends BaseDialog init: () -> html = " " - html += "<#{@conf.tag} data-id = 'content'>" + html += "<#{@conf.tag} #{@conf.att} data-id = 'content'>" html += "
" html += "" for k,v of @conf.buttons html += "
" @@ -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 diff --git a/src/core/handlers/RemoteHandler.coffee b/src/core/handlers/RemoteHandler.coffee index a60d2da..5f7d550 100644 --- a/src/core/handlers/RemoteHandler.coffee +++ b/src/core/handlers/RemoteHandler.coffee @@ -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) -> diff --git a/src/core/tags/afx-list-view.js b/src/core/tags/afx-list-view.js index f38f346..2fed093 100644 --- a/src/core/tags/afx-list-view.js +++ b/src/core/tags/afx-list-view.js @@ -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 } diff --git a/src/core/vfs.coffee b/src/core/vfs.coffee index 6bb06ce..e2a950d 100644 --- a/src/core/vfs.coffee +++ b/src/core/vfs.coffee @@ -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 diff --git a/src/packages/Files/main.coffee b/src/packages/Files/main.coffee index b5cafd4..bad7586 100644 --- a/src/packages/Files/main.coffee +++ b/src/packages/Files/main.coffee @@ -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 \ No newline at end of file