mirror of
https://github.com/lxsang/antos-frontend.git
synced 2024-12-27 09:48:21 +01:00
vfs (contd.)
This commit is contained in:
parent
dfbeb16601
commit
7bd53154ad
@ -1,10 +1,15 @@
|
|||||||
class BaseApplication extends this.OS.GUI.BaseModel
|
class BaseApplication extends this.OS.GUI.BaseModel
|
||||||
constructor: (name, args) ->
|
constructor: (name, args) ->
|
||||||
super name, args
|
super name, args
|
||||||
|
_OS.setting.applications[@name] = {} if not _OS.setting.applications[@name]
|
||||||
|
@setting = _OS.setting.applications[@name]
|
||||||
|
|
||||||
init: ->
|
init: ->
|
||||||
me = @
|
me = @
|
||||||
# first register some base event to the app
|
# first register some base event to the app
|
||||||
|
@subscribe "appregistry"
|
||||||
|
, ( m ) ->
|
||||||
|
me.applySetting m.data.m if (m.name is me.name)
|
||||||
|
|
||||||
@on "focus", () ->
|
@on "focus", () ->
|
||||||
me.sysdock.set "selectedApp", me
|
me.sysdock.set "selectedApp", me
|
||||||
@ -25,6 +30,11 @@ class BaseApplication extends this.OS.GUI.BaseModel
|
|||||||
path = "packages/#{@name}/scheme.html"
|
path = "packages/#{@name}/scheme.html"
|
||||||
@.render path
|
@.render path
|
||||||
|
|
||||||
|
applySetting: (k) ->
|
||||||
|
registry: (k, v) ->
|
||||||
|
@setting[k] = v
|
||||||
|
@publish "appregistry", k
|
||||||
|
|
||||||
show: () ->
|
show: () ->
|
||||||
@trigger "focus"
|
@trigger "focus"
|
||||||
|
|
||||||
|
@ -5,16 +5,7 @@ class BaseModel
|
|||||||
me = @
|
me = @
|
||||||
@on "exit", () -> me.quit()
|
@on "exit", () -> me.quit()
|
||||||
@host = "#desktop"
|
@host = "#desktop"
|
||||||
_OS.setting.applications[@name] = {} if not _OS.setting.applications[@name]
|
|
||||||
@setting = _OS.setting.applications[@name]
|
|
||||||
@dialog = undefined
|
@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) ->
|
render: (p) ->
|
||||||
_GUI.loadScheme p, @, @host
|
_GUI.loadScheme p, @, @host
|
||||||
@ -31,7 +22,7 @@ class BaseModel
|
|||||||
#implement by sub class
|
#implement by sub class
|
||||||
onexit: (e) ->
|
onexit: (e) ->
|
||||||
#implement by subclass
|
#implement by subclass
|
||||||
applySetting: (k) ->
|
|
||||||
one: (e, f) -> @observable.one e, f
|
one: (e, f) -> @observable.one e, f
|
||||||
on: (e, f) -> @observable.on e, f
|
on: (e, f) -> @observable.on e, f
|
||||||
|
|
||||||
@ -65,7 +56,7 @@ class BaseModel
|
|||||||
@publish "warning", m
|
@publish "warning", m
|
||||||
|
|
||||||
error: (m) ->
|
error: (m) ->
|
||||||
@publish "error", m
|
@publish "error", m + (@_api.throwe @name)
|
||||||
|
|
||||||
fail: (m) ->
|
fail: (m) ->
|
||||||
@publish "fail", m
|
@publish "fail", m
|
||||||
|
@ -3,6 +3,10 @@ self.OS.API.handler =
|
|||||||
path = "lua-api/fs/scandir"
|
path = "lua-api/fs/scandir"
|
||||||
_API.post path, { path: p }, c, (e, s) ->
|
_API.post path, { path: p }, c, (e, s) ->
|
||||||
_courrier.osfail "Fail to scan directory: #{p}", 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) ->
|
fileinfo: (p, c) ->
|
||||||
path = "lua-api/fs/fileinfo"
|
path = "lua-api/fs/fileinfo"
|
||||||
|
@ -70,7 +70,7 @@
|
|||||||
var rows = []
|
var rows = []
|
||||||
$.each(self.data, function(i,v){
|
$.each(self.data, function(i,v){
|
||||||
if(v.filename[0] == '.' && !self.showhidden) return
|
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)
|
rows.push(row)
|
||||||
})
|
})
|
||||||
self.refs.gridview.root.set("rows",rows)
|
self.refs.gridview.root.set("rows",rows)
|
||||||
@ -156,7 +156,7 @@
|
|||||||
self.refs.gridview.root.observable = self.root.observable
|
self.refs.gridview.root.observable = self.root.observable
|
||||||
self.refs.gridview.ongridselect = function(d)
|
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.root.observable.trigger("fileselect",data)
|
||||||
}
|
}
|
||||||
self.refs.gridview.ongriddbclick = function(d)
|
self.refs.gridview.ongriddbclick = function(d)
|
||||||
|
@ -37,7 +37,7 @@ class BasicFileHandler
|
|||||||
|
|
||||||
parent: () ->
|
parent: () ->
|
||||||
return @ if @isRoot()
|
return @ if @isRoot()
|
||||||
(@protocol + ":///" + (@genealogy.slice 0 , @genealogy.length - 1).join "/").asFileHandler()
|
return (@protocol + ":///" + (@genealogy.slice 0 , @genealogy.length - 1).join "/")
|
||||||
|
|
||||||
onready: (f) ->
|
onready: (f) ->
|
||||||
# read meta data
|
# read meta data
|
||||||
@ -49,25 +49,37 @@ class BasicFileHandler
|
|||||||
me.ready = true
|
me.ready = true
|
||||||
f()
|
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) ->
|
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) ->
|
remove: (f) ->
|
||||||
|
me = @
|
||||||
|
@onready (() -> me.action "remove", null, f)
|
||||||
|
|
||||||
|
move: (d, f) ->
|
||||||
|
me = @
|
||||||
|
@onready (() -> me action "move", d, f)
|
||||||
|
|
||||||
execute: (f) ->
|
execute: (f) ->
|
||||||
|
me = @
|
||||||
|
@onready (() -> me.action "execute", null, f)
|
||||||
|
|
||||||
mk: (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
|
# now export the class
|
||||||
self.OS.API.VFS.BasicFileHandler = BasicFileHandler
|
self.OS.API.VFS.BasicFileHandler = BasicFileHandler
|
||||||
@ -80,10 +92,17 @@ class RemoteFileHandler extends self.OS.API.VFS.BasicFileHandler
|
|||||||
meta: (f) ->
|
meta: (f) ->
|
||||||
_API.handler.fileinfo @path, f
|
_API.handler.fileinfo @path, f
|
||||||
|
|
||||||
read: (f) ->
|
action: (n, p, f) ->
|
||||||
return _API.handler.scandir @path, f if @meta.type is "dir"
|
switch n
|
||||||
#read the file
|
when "read"
|
||||||
_API.handler.readfile @path, f
|
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
|
self.OS.API.VFS.RemoteFileHandler = RemoteFileHandler
|
||||||
|
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
class Files extends this.OS.GUI.BaseApplication
|
class Files extends this.OS.GUI.BaseApplication
|
||||||
constructor: (args) ->
|
constructor: (args) ->
|
||||||
super "Files", args
|
super "Files", args
|
||||||
|
|
||||||
main: () ->
|
main: () ->
|
||||||
me = @
|
me = @
|
||||||
@scheme.set "apptitle", "Files manager"
|
@scheme.set "apptitle", "Files manager"
|
||||||
@view = @find "fileview"
|
@view = @find "fileview"
|
||||||
@navinput = @find "navinput"
|
@navinput = @find "navinput"
|
||||||
@navbar = @find "nav-bar"
|
@navbar = @find "nav-bar"
|
||||||
@prepaths = []
|
@currdir = undefined
|
||||||
@favo = @find "favouri"
|
@favo = @find "favouri"
|
||||||
|
|
||||||
@view.contextmenuHandler = (e, m) ->
|
@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
|
@favo.set "onlistselect", (e) -> me.chdir e.data.path, true
|
||||||
|
|
||||||
($ @find "btback").click () ->
|
($ @find "btback").click () ->
|
||||||
return if me.prepaths.length is 0
|
return if me.currdir.isRoot()
|
||||||
p = me.prepaths.pop()
|
p = me.currdir.parent()
|
||||||
me.favo.set "selected", -1
|
me.favo.set "selected", -1
|
||||||
me.chdir p, false
|
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}"
|
, (e, s) -> me.error "Cannot fetch child dir #{e.child.path}"
|
||||||
|
|
||||||
@setting.favorite = [
|
@setting.favorite = [
|
||||||
{ text: "Applications", path: 'apps:///', iconclass:"fa fa-adn"},
|
{ text: "Applications", path: 'app:///', iconclass: "fa fa-adn" },
|
||||||
{ text: "Home", path: 'home:///', iconclass:"fa fa-home", selected:true},
|
{ text: "Home", path: 'home:///', iconclass: "fa fa-home", selected: true },
|
||||||
{ text: "OS", path: 'os:///', iconclass:"fa fa-inbox" },
|
{ text: "OS", path: 'os:///', iconclass: "fa fa-inbox" },
|
||||||
{ text: "Desktop", path: 'home:///.desktop', iconclass: "fa fa-desktop" },
|
{ text: "Desktop", path: 'home:///.desktop', iconclass: "fa fa-desktop" },
|
||||||
] if not @setting.favorite
|
] if not @setting.favorite
|
||||||
@setting.sidebar = true if @setting.sidebar is undefined
|
@setting.sidebar = true if @setting.sidebar is undefined
|
||||||
@setting.nav = true if @setting.nav is undefined
|
@setting.nav = true if @setting.nav is undefined
|
||||||
|
@setting.showhidden = false if @setting.showhidden is undefined
|
||||||
@favo.set "items", @setting.favorite
|
@favo.set "items", @setting.favorite
|
||||||
@applySetting()
|
@applySetting()
|
||||||
|
|
||||||
applySetting: (k) ->
|
applySetting: (k) ->
|
||||||
# view setting
|
# view setting
|
||||||
@view.set "view", @setting.view if @setting.view
|
@view.set "view", @setting.view if @setting.view
|
||||||
@view.set "showhidden", @setting.showhidden if @setting.showhidden
|
@view.set "showhidden", @setting.showhidden
|
||||||
@toggleSidebar @setting.sidebar
|
@toggleSidebar @setting.sidebar
|
||||||
@toggleNav @setting.nav
|
@toggleNav @setting.nav
|
||||||
|
|
||||||
chdir: (p, push) ->
|
chdir: (p, push) ->
|
||||||
me = @
|
me = @
|
||||||
me._api.handler.scandir p,
|
dir = p.asFileHandler()
|
||||||
(d) ->
|
dir.read (d) ->
|
||||||
if(d.error)
|
if(d.error)
|
||||||
return me.error "Resource not found #{p}"
|
return me.error "Resource not found #{p}"
|
||||||
v = ($ me.navinput).val()
|
me.currdir = dir
|
||||||
me.prepaths.push v if push and v isnt ""
|
|
||||||
($ me.navinput).val p
|
($ me.navinput).val p
|
||||||
me.view.set "path", p
|
me.view.set "path", p
|
||||||
me.view.set "data", d.result
|
me.view.set "data", d.result
|
||||||
, (e, s) ->
|
|
||||||
me.error "Cannot chdir #{p}"
|
|
||||||
|
|
||||||
mnFile:() ->
|
mnFile:() ->
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user