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 "/")

View File

@ -36,6 +36,7 @@ class Files extends this.OS.GUI.BaseApplication
@view.set "chdir", (p) -> me.chdir p
@view.set "fetch", (e, f) ->
return unless e.child
return if e.child.filename is "[..]"
e.child.path.asFileHandler().read (d) ->
return me.error "Resource not found #{e.child.path}" if d.error
f d.result
@ -66,6 +67,12 @@ class Files extends this.OS.GUI.BaseApplication
if(d.error)
return me.error "Resource not found #{p}"
me.currdir = dir
if not dir.isRoot()
p = dir.parent().asFileHandler()
p.filename = "[..]"
p.type = "dir"
#p.size = 0
d.result.unshift p
($ me.navinput).val dir.path
me.view.set "path", dir.path
me.view.set "data", d.result

View File

@ -43,9 +43,9 @@ class NotePad extends this.OS.GUI.BaseApplication
mode: m.theme,
selected: if m.theme is "ace/theme/monokai" then true else false
} for k, m of themes.themesByName
themelist.set "items", ldata
themelist.set "onlistselect", (e) ->
me.editor.setTheme e.data.mode
themelist.set "items", ldata
stat = @find "editorstat"
#status
@ -71,12 +71,15 @@ class NotePad extends this.OS.GUI.BaseApplication
@fileview.set "chdir", (d) -> me.chdir d
@fileview.set "fetch", (e, f) ->
return unless e.child
return if e.child.filename is "[..]"
e.child.path.asFileHandler().read (d) ->
return me.error "Resource not found #{e.child.path}" if d.error
f d.result
@fileview.set "onfileopen", (e) ->
return if e.type is "dir"
me.open e.path.asFileHandler()
@location.set "onlistselect", (e) -> me.chdir e.data.path
@location.set "onlistselect", (e) ->
me.chdir e.data.path
@location.set "items", ( i for i in @systemsetting.VFS.mountpoints when i.type isnt "app" )
@location.set "selected", 0 unless @location.get "selected"
@tabarea = @find "tabarea"
@ -101,11 +104,18 @@ class NotePad extends this.OS.GUI.BaseApplication
return @newtab file if file.path.toString() is "Untitled"
me = @
file.read (_d) ->
d = if typeof _d is "string" then _d else JSON.stringify _d
me.scheme.set "apptitle", file.basename
d = if typeof _d is "string" then _d else JSON.stringify _d #TODO
file.cache = d or ""
me.newtab file
save: (file) ->
me = @
file.write (file.getb64 "text/plain"), (d) ->
return me.error "Error saving file #{file.basename}" if d.error
file.dirty = false
file.text = file.basename
me.tabarea.update()
findTabByFile: (file) ->
lst = @tabarea.get "items"
its = ( i for d, i in lst when d.hash() is file.hash() )
@ -136,6 +146,7 @@ class NotePad extends this.OS.GUI.BaseApplication
#return if i is @tabarea.get "selidx"
file = (@tabarea.get "items")[i]
return unless file
@scheme.set "apptitle", file.text.toString()
#return if file is @currfile
if @currfile isnt file
@currfile.cache = @editor.getValue()
@ -155,16 +166,23 @@ class NotePad extends this.OS.GUI.BaseApplication
@editor.selection.moveTo file.cursor.row, file.cursor.column
@editor.focus()
chdir: (p) ->
chdir: (pth) ->
#console.log "called", @_api.throwe("FCK")
return unless pth
me = @
me._api.handler.scandir p,
(d) ->
if(d.error)
return me.error "Resource not found #{p}"
me.fileview.set "path", p
me.fileview.set "data", d.result
, (e, s) ->
me.error "Cannot chdir #{p}"
dir = pth.asFileHandler()
dir.read (d) ->
if(d.error)
return me.error "Resource not found #{p}"
if not dir.isRoot()
p = dir.parent().asFileHandler()
p.filename = "[..]"
p.type = "dir"
#p.size = 0
d.result.unshift p
($ me.navinput).val dir.path
me.fileview.set "path", pth
me.fileview.set "data", d.result
menu: () ->
me = @
@ -172,16 +190,33 @@ class NotePad extends this.OS.GUI.BaseApplication
text: "File",
child: [
{ text: "Open", dataid: "#{@name}-Open" },
{ text: "Close", dataid: "#{@name}-Close" }
{ text: "Save", dataid: "#{@name}-Save" },
{ text: "Save as", dataid: "#{@name}-Saveas" }
],
onmenuselect: (e) -> me.actionFile e
}]
menu
actionFile: (e) ->
me = @
saveas = () ->
me.openDialog "FileDiaLog", (d, n) ->
me.currfile.setPath "#{d}/#{n}"
me.save me.currfile
, "Save as", { file: me.currfile }
switch e.item.data.dataid
when "#{@name}-Open"
@openDialog "FileDiaLog", null, "Select file", { seldir: true }
@openDialog "FileDiaLog", ( d, f ) ->
me.open "#{d}/#{f}".asFileHandler()
, "Open file"
when "#{@name}-Save"
@currfile.cache = @editor.getValue()
return @save @currfile if @currfile.basename
saveas()
when "#{@name}-Saveas"
@currfile.cache = @editor.getValue()
saveas()
NotePad.singleton = false
this.OS.register "NotePad", NotePad