NotePad apps

This commit is contained in:
Xuan Sang LE
2018-01-28 02:01:21 +01:00
parent ea074d9690
commit c048824ce4
13 changed files with 210 additions and 60 deletions

View File

@ -3,7 +3,6 @@ class BaseApplication extends this.OS.GUI.BaseModel
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

View File

@ -179,7 +179,7 @@ class YesNoDialog extends BasicDialog
},
{
label: "No", onclick: (d) ->
d handler false if dhandler
d.handler false if d.handler
d.quit()
}
],
@ -234,4 +234,42 @@ class AboutDialog extends BaseDialog
rows.push [ { value: k }, { value: v } ] for k, v of mt.info
(@find "mygrid").set "rows", rows
this.OS.register "AboutDialog", AboutDialog
this.OS.register "AboutDialog", AboutDialog
class FileDiaLog extends BaseDialog
constructor: () ->
super "FileDiaLog"
init: () ->
@render "resources/schemes/filedialog.html"
main: () ->
fileview = @find "fileview"
location = @find "location"
me = @
@scheme.set "apptitle", "#{@title}"
fileview.set "fetch", (e, f) ->
return unless e.child
e.child.path.asFileHandler().read (d) ->
return me.error "Resource not found #{e.child.path}" if d.error
f d.result
location.set "onlistselect", (e) ->
return unless e and e.data.path
e.data.path.asFileHandler().read (d) ->
if(d.error)
return me.error "Resource not found #{e.data.path}"
fileview.set "path", e.data.path
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"
(@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
me.quit()
(@find "bt-cancel").set "onbtclick", (e) ->
me.quit()
this.OS.register "FileDiaLog", FileDiaLog

View File

@ -3,6 +3,7 @@ class BaseModel
@observable = riot.observable()
@_api = self.OS.API
@_gui = self.OS.GUI
@systemsetting = self.OS.setting
me = @
@on "exit", () -> me.quit()
@host = "#desktop"

View File

@ -13,7 +13,7 @@ self.OS.API =
url: p,
contentType: 'application/json',
data: JSON.stringify d,
dataType: 'json',
dataType: 'json', # data type need to be configurable
success: null
}
#$.getJSON p, d
@ -89,7 +89,7 @@ self.OS.API =
get: (p, c, f) ->
q = _courrier.getMID()
_API.loading q, p
$.get p
$.get p # TODO add return type setting support
.done (data) ->
_API.loaded q, p, "OK"
c(data)

View File

@ -10,6 +10,7 @@ self.OS or=
applications: {}
desktop: {}
appearance: {}
VFS: {}
courrier:
observable: riot.observable()
quota: 0

View File

@ -61,16 +61,19 @@ self.OS.GUI =
_courrier.osfail "Cannot read service script: #{srv} ", e, s
appsByMime: (mime) ->
metas = ( a.meta for k, a of _OS.APP when a.type is 1)
mimes = ( m.mimes for m in metas )
metas = ( a.meta for k, a of _OS.APP when a and a.type is 1)
mimes = ( m.mimes for m in metas when m)
apps = []
# search app by mimes
f = ( arr, idx ) ->
arr.filter (m, i) ->
if mime.match (new RegExp m, "g")
apps.push metas[idx]
try
arr.filter (m, i) ->
if mime.match (new RegExp m, "g")
apps.push metas[idx]
return false
return false
return false
catch e
_courrier.osfail "Find app by mimes #{mime}", e, mime
( f m, i if m ) for m, i in mimes
return apps
@ -265,6 +268,14 @@ self.OS.GUI =
_OS.setting.applications = conf.applications if conf.applications
_OS.setting.appearance = conf.appearance if conf.appearance
_OS.setting.user = conf.user
_OS.setting.VFS = conf.VFS if conf.VFS
_OS.setting.VFS.mountpoints = [ #TODO: multi app try to write to this object, it neet to be cloned
{ text: "Applications", path: 'app:///', iconclass: "fa fa-adn", type: "app" },
{ text: "Home", path: 'home:///', iconclass: "fa fa-home", type: "fs" },
{ text: "OS", path: 'os:///', iconclass: "fa fa-inbox", type: "fs" },
{ text: "Desktop", path: 'home:///.desktop', iconclass: "fa fa-desktop", type: "fs"},
] if not _OS.setting.VFS.mountpoints
_OS.setting.desktop.path = "home:///.desktop" unless _OS.setting.desktop.path
_OS.setting.appearance.theme = "antos" unless _OS.setting.appearance.theme
# load theme
@ -279,5 +290,5 @@ self.OS.GUI =
# startup application here
_courrier.observable.one "desktoploaded", () ->
_GUI.launch "DummyApp"
#_GUI.launch "NotePad"
#_GUI.launch "DummyApp"
_GUI.launch "NotePad"

View File

@ -0,0 +1,12 @@
<afx-app-window data-id = 'file-dialog-window' width='400' height='250'>
<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>
<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>
</div>
</afx-hbox>
</afx-vbox>
</afx-app-window>

View File

@ -12,6 +12,7 @@
self.data = opts.data || []
self.path = opts.path || "home:///"
self.onfileselect
self.onfileopen
this.status = opts.status == undefined?true:opts.status
this.selectedFile = undefined
this.showhidden = opts.showhidden
@ -182,8 +183,11 @@
$(self.refs.stbar).html("Selected: " + e.data.filename + " (" + e.data.size + " bytes)")
})
self.root.observable.on("filedbclick", function(e){
if(e.id != self.rid || e.data.type == 'file' || !self.chdir) return
self.chdir(e.data.path)
if(e.id != self.rid ) return
if(e.data.type == "file" && self.onfileopen)
self.onfileopen(e.data)
else if(self.chdir)
self.chdir(e.data.path)
})
calibre_size()
self.root.observable.on("resize", function(e){

View File

@ -22,6 +22,7 @@
{
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
@ -121,6 +122,7 @@
_autoselect(it,i)
{
if(!it.selected || it.selected == false) return false
//if(self.selidx == i) return false
var data = {
id:self.rid,
data:it,
@ -133,9 +135,11 @@
$(self.refs.mlist).hide()
$(self.refs.current).html(it.text)
}
if(self.onlistselect)
self.onlistselect(data)
this.root.observable.trigger('listselect',data)
//console.log("list select")
return true
}
_select(event)

View File

@ -4,6 +4,7 @@
var self = this
this.closable = opts.closable || false
self.root.observable = opts.observable || riot.observable()
self.ontabselect = opts.ontabselect
get_observable(){
return self.root.observable
}
@ -12,6 +13,9 @@
return self.refs.list.root.get(k)
}
self.root.update = function(){
self.update()
}
self.on("mount", function(){
self.refs.list.root.observable = self.root.observable
@ -19,7 +23,10 @@
console.log("list select")
})*/
self.refs.list.root.set ("onlistselect",function (e) {
//console.log("tab is seleced")
self.root.observable.trigger("tabselect", e)
if(self.ontabselect)
self.ontabselect(e)
})
})
@ -31,6 +38,8 @@
{
self.closable = v
}
else if(k == "ontabselect")
self.ontabselect = v
else
{
if(k == "items")
@ -56,5 +65,6 @@
{
self.refs.list.root.remove(e,u)
}
</script>
</afx-tab-container>