vfs (contd.)

This commit is contained in:
Xuan Sang LE 2018-01-24 15:03:33 +01:00
parent dfbeb16601
commit 7bd53154ad
6 changed files with 70 additions and 47 deletions

View File

@ -1,11 +1,16 @@
class BaseApplication extends this.OS.GUI.BaseModel
constructor: (name, args) ->
super name, args
_OS.setting.applications[@name] = {} if not _OS.setting.applications[@name]
@setting = _OS.setting.applications[@name]
init: ->
me = @
# first register some base event to the app
@subscribe "appregistry"
, ( m ) ->
me.applySetting m.data.m if (m.name is me.name)
@on "focus", () ->
me.sysdock.set "selectedApp", me
me.appmenu.pid = me.pid
@ -25,6 +30,11 @@ class BaseApplication extends this.OS.GUI.BaseModel
path = "packages/#{@name}/scheme.html"
@.render path
applySetting: (k) ->
registry: (k, v) ->
@setting[k] = v
@publish "appregistry", k
show: () ->
@trigger "focus"

View File

@ -5,16 +5,7 @@ class BaseModel
me = @
@on "exit", () -> me.quit()
@host = "#desktop"
_OS.setting.applications[@name] = {} if not _OS.setting.applications[@name]
@setting = _OS.setting.applications[@name]
@dialog = undefined
@subscribe "appregistry"
, ( m ) ->
me.applySetting m.data.m if (m.name is me.name)
registry: (k, v) ->
@setting[k] = v
@publish "appregistry", k
render: (p) ->
_GUI.loadScheme p, @, @host
@ -31,7 +22,7 @@ class BaseModel
#implement by sub class
onexit: (e) ->
#implement by subclass
applySetting: (k) ->
one: (e, f) -> @observable.one e, f
on: (e, f) -> @observable.on e, f
@ -65,7 +56,7 @@ class BaseModel
@publish "warning", m
error: (m) ->
@publish "error", m
@publish "error", m + (@_api.throwe @name)
fail: (m) ->
@publish "fail", m

View File

@ -3,6 +3,10 @@ self.OS.API.handler =
path = "lua-api/fs/scandir"
_API.post path, { path: p }, c, (e, s) ->
_courrier.osfail "Fail to scan directory: #{p}", e, s
mkdir: (p, c ) ->
path = "lua-api/fs/mkdir"
_API.post path, { path: p }, c, (e, s) ->
_courrier.osfail "Fail to create directory: #{p}", e, s
fileinfo: (p, c) ->
path = "lua-api/fs/fileinfo"

View File

@ -70,7 +70,7 @@
var rows = []
$.each(self.data, function(i,v){
if(v.filename[0] == '.' && !self.showhidden) return
var row = [{value:v.filename, iconclass: v.type},{value:v.mime},{value:v.size}]
var row = [{value:v.filename, iconclass: v.type},{value:v.mime},{value:v.size},{idx:i}]
rows.push(row)
})
self.refs.gridview.root.set("rows",rows)
@ -156,7 +156,7 @@
self.refs.gridview.root.observable = self.root.observable
self.refs.gridview.ongridselect = function(d)
{
var data = {id:self.rid, data:self.data[d.data.i], idx:d.data.i}
var data = {id:self.rid, data:self.data[d.data.child[3].idx], idx:d.data.child[3].idx}
self.root.observable.trigger("fileselect",data)
}
self.refs.gridview.ongriddbclick = function(d)

View File

@ -37,7 +37,7 @@ class BasicFileHandler
parent: () ->
return @ if @isRoot()
(@protocol + ":///" + (@genealogy.slice 0 , @genealogy.length - 1).join "/").asFileHandler()
return (@protocol + ":///" + (@genealogy.slice 0 , @genealogy.length - 1).join "/")
onready: (f) ->
# read meta data
@ -49,25 +49,37 @@ class BasicFileHandler
me.ready = true
f()
#public interface for all action on file
do: (a, f) ->
return _courrier.osfail "VFS unknown action: #{a}", (_API.throwe "OS.VFS"), a if not @[a]
me = @
@onready (() -> me[a] f)
# methods implemented by subclasses used as private methods
meta: (f) ->
read: (f) ->
me = @
@onready (() -> me.action "read", null, f)
write: (f) ->
write: (d, f) ->
@action "write", d, f
mk: (d, f) ->
me = @
@onready (() -> me.action "mk", d, f)
remove: (f) ->
me = @
@onready (() -> me.action "remove", null, f)
move: (d, f) ->
me = @
@onready (() -> me action "move", d, f)
execute: (f) ->
mk: (f) ->
me = @
@onready (() -> me.action "execute", null, f)
#mk: (f) ->
meta: (f) ->
# for main action read, write, remove, execute
# must be implemented by subclasses
action: (n, p, f) ->
return _courrier.osfail "VFS unknown action: #{n}", (_API.throwe "OS.VFS"), n
# now export the class
self.OS.API.VFS.BasicFileHandler = BasicFileHandler
@ -80,10 +92,17 @@ class RemoteFileHandler extends self.OS.API.VFS.BasicFileHandler
meta: (f) ->
_API.handler.fileinfo @path, f
read: (f) ->
return _API.handler.scandir @path, f if @meta.type is "dir"
#read the file
_API.handler.readfile @path, f
action: (n, p, f) ->
switch n
when "read"
return _API.handler.scandir @path, f if @meta.type is "dir"
#read the file
_API.handler.readfile @path, f
when "mk"
return f { error: "#{@path} is not a directory" } if @meta.type is "file"
_API.handler.mkdir "#{@path}/#{p}", f
else
return _courrier.osfail "VFS unknown action: #{n}", (_API.throwe "OS.VFS"), n
self.OS.API.VFS.RemoteFileHandler = RemoteFileHandler

View File

@ -1,13 +1,14 @@
class Files extends this.OS.GUI.BaseApplication
constructor: (args) ->
super "Files", args
main: () ->
me = @
@scheme.set "apptitle", "Files manager"
@view = @find "fileview"
@navinput = @find "navinput"
@navbar = @find "nav-bar"
@prepaths = []
@currdir = undefined
@favo = @find "favouri"
@view.contextmenuHandler = (e, m) ->
@ -19,8 +20,8 @@ class Files extends this.OS.GUI.BaseApplication
@favo.set "onlistselect", (e) -> me.chdir e.data.path, true
($ @find "btback").click () ->
return if me.prepaths.length is 0
p = me.prepaths.pop()
return if me.currdir.isRoot()
p = me.currdir.parent()
me.favo.set "selected", -1
me.chdir p, false
@ -35,36 +36,34 @@ class Files extends this.OS.GUI.BaseApplication
, (e, s) -> me.error "Cannot fetch child dir #{e.child.path}"
@setting.favorite = [
{ text: "Applications", path: 'apps:///', iconclass:"fa fa-adn"},
{ text: "Home", path: 'home:///', iconclass:"fa fa-home", selected:true},
{ text: "OS", path: 'os:///', iconclass:"fa fa-inbox" },
{ text: "Applications", path: 'app:///', iconclass: "fa fa-adn" },
{ text: "Home", path: 'home:///', iconclass: "fa fa-home", selected: true },
{ text: "OS", path: 'os:///', iconclass: "fa fa-inbox" },
{ text: "Desktop", path: 'home:///.desktop', iconclass: "fa fa-desktop" },
] if not @setting.favorite
@setting.sidebar = true if @setting.sidebar is undefined
@setting.nav = true if @setting.nav is undefined
@setting.showhidden = false if @setting.showhidden is undefined
@favo.set "items", @setting.favorite
@applySetting()
applySetting: (k) ->
# view setting
@view.set "view", @setting.view if @setting.view
@view.set "showhidden", @setting.showhidden if @setting.showhidden
@view.set "showhidden", @setting.showhidden
@toggleSidebar @setting.sidebar
@toggleNav @setting.nav
chdir: (p, push) ->
me = @
me._api.handler.scandir p,
(d) ->
dir = p.asFileHandler()
dir.read (d) ->
if(d.error)
return me.error "Resource not found #{p}"
v = ($ me.navinput).val()
me.prepaths.push v if push and v isnt ""
me.currdir = dir
($ me.navinput).val p
me.view.set "path", p
me.view.set "data", d.result
, (e, s) ->
me.error "Cannot chdir #{p}"
mnFile:() ->
{