VFS (contd)

This commit is contained in:
Xuan Sang LE
2018-01-28 16:33:49 +01:00
parent c048824ce4
commit 60bae901a0
8 changed files with 87 additions and 25 deletions

View File

@ -246,6 +246,7 @@ class FileDiaLog extends BaseDialog
main: () ->
fileview = @find "fileview"
location = @find "location"
filename = @find "filename"
me = @
@scheme.set "apptitle", "#{@title}"
fileview.set "fetch", (e, f) ->
@ -262,14 +263,20 @@ class FileDiaLog extends BaseDialog
fileview.set "data", d.result
location.set "items", ( i for i in @systemsetting.VFS.mountpoints when i.type isnt "app" )
location.set "selected", 0 unless location.get "selected"
fileview.set "onfileselect", (f) ->
($ filename).val f.filename if f.type is "file"
(@find "bt-ok").set "onbtclick", (e) ->
f = fileview.get "selectedFile"
return unless f
return unless f.type is "file" or ( me.data and me.data.seldir )
me.handler f if me.handler
d = f.path
d = f.path.asFileHandler().parent() if f.type is "file"
me.handler d, ($ filename).val() if me.handler
#sel = if me.data and me.data.selection then me.data.selection else "file"
#me.handler f, ($ filename).val() if me.handler and ((f.type is sel) or (sel is "*"))
me.quit()
(@find "bt-cancel").set "onbtclick", (e) ->
me.quit()
($ filename).css("display", "block").val @data.file.basename or "Untitled" if @data and @data.file
this.OS.register "FileDiaLog", FileDiaLog

View File

@ -1,8 +1,9 @@
<afx-app-window data-id = 'file-dialog-window' width='400' height='250'>
<afx-app-window data-id = 'file-dialog-window' width='400' height='300'>
<afx-vbox>
<afx-list-view data-id = "location" dropdown = "false" data-width = "120"></afx-list-view>
<afx-hbox>
<afx-file-view data-id = "fileview" view='tree' status = false></afx-file-view>
<input data-height = '26' type = "text" data-id = "filename" style="margin-left:5px; margin-right:5px;display:none;" />
<div data-height = '30' style=' text-align:right;padding-top:3px;'>
<afx-button data-id = "bt-ok" text = "Ok"></afx-button>
<afx-button data-id = "bt-cancel" text = "Cancel"></afx-button>

View File

@ -180,13 +180,15 @@
self.root.observable.on("fileselect", function(e){
if(e.id != self.rid) return
self.selectedFile = e.data
if(self.onfileselect)
self.onfileselect(e.data)
$(self.refs.stbar).html("Selected: " + e.data.filename + " (" + e.data.size + " bytes)")
})
self.root.observable.on("filedbclick", function(e){
if(e.id != self.rid ) return
if(e.data.type == "file" && self.onfileopen)
self.onfileopen(e.data)
else if(self.chdir)
else if(self.chdir && e.data.type == "dir")
self.chdir(e.data.path)
})
calibre_size()

View File

@ -141,6 +141,7 @@
}
_autoselect(it,i)
{
if(self.selidx == i) return true
if(!it.selected || it.selected == false) return false
var data = {
id:self.rid,

View File

@ -22,7 +22,6 @@
{
if(k == "selected")
{
console.log("selected", v)
if(self.selidx != -1)
self.items[self.selidx].selected =false
if(self.items[v]) self.items[v].selected = true
@ -122,7 +121,7 @@
_autoselect(it,i)
{
if(!it.selected || it.selected == false) return false
//if(self.selidx == i) return false
if(self.selidx == i) return true
var data = {
id:self.rid,
data:it,

View File

@ -4,6 +4,12 @@ String.prototype.hash = () ->
hash = (hash * 33) ^ this.charCodeAt(--i) while i
hash >>> 0
String.prototype.asBase64 = () ->
tmp = encodeURIComponent this
return btoa ( tmp.replace /%([0-9A-F]{2})/g, (match, p1) ->
return String.fromCharCode (parseInt p1, 16)
)
String.prototype.asFileHandler = () ->
list = this.split ":///"
switch list[0]
@ -16,12 +22,12 @@ this.OS.API.VFS = {}
class BasicFileHandler
constructor: (path) ->
@dirty = false
@cache = undefined
@setPath path
setPath: (p) ->
@ready = false
@dirty = false
@cache = undefined
return unless p
@path = p
list = @path.split ":///"
@ -39,10 +45,14 @@ class BasicFileHandler
return false if not @basename
@basename[0] is "."
hash: () ->
hash: () ->
return -1 unless @path
return @path.hash()
getb64: (m) ->
return "" unless @cache
b64 = @cache.asBase64()
return "data:#{m};base64,#{b64}"
parent: () ->
return @ if @isRoot()
return (@protocol + ":///" + (@genealogy.slice 0 , @genealogy.length - 1).join "/")