antos-frontend/src/core/BaseApplication.coffee

88 lines
2.6 KiB
CoffeeScript
Raw Normal View History

class BaseApplication extends this.OS.GUI.BaseModel
2017-08-27 23:40:02 +02:00
constructor: (name, args) ->
super name, args
2018-01-24 15:03:33 +01:00
_OS.setting.applications[@name] = {} if not _OS.setting.applications[@name]
@setting = _OS.setting.applications[@name]
2017-08-11 01:58:46 +02:00
init: ->
2017-08-14 00:20:19 +02:00
me = @
# first register some base event to the app
2018-01-24 15:03:33 +01:00
@subscribe "appregistry"
, ( m ) ->
me.applySetting m.data.m if (m.name is me.name)
2017-08-15 02:56:04 +02:00
@on "focus", () ->
me.sysdock.set "selectedApp", me
2017-08-14 00:20:19 +02:00
me.appmenu.pid = me.pid
me.appmenu.set "items", (me.baseMenu() || [])
2017-08-15 02:56:04 +02:00
me.appmenu.set "onmenuselect", (d) ->
me.trigger("menuselect", d)
2017-08-24 01:53:13 +02:00
me.dialog.show() if me.dialog
2017-08-15 02:56:04 +02:00
@on "hide", () ->
2017-08-14 00:20:19 +02:00
me.sysdock.set "selectedApp", null
2017-08-15 02:56:04 +02:00
me.appmenu.set "items", []
2017-08-24 01:53:13 +02:00
me.dialog.hide() if me.dialog
@on "menuselect", (d) ->
switch d.e.item.data.dataid
2017-08-26 16:50:13 +02:00
when "#{me.name}-about" then me.openDialog "AboutDialog", ()->
2017-08-14 00:20:19 +02:00
when "#{me.name}-exit" then me.trigger "exit"
#now load the scheme
2018-02-01 19:36:09 +01:00
path = "#{@meta().path}/scheme.html"
@.render path
2017-08-14 00:20:19 +02:00
2018-01-24 15:03:33 +01:00
applySetting: (k) ->
registry: (k, v) ->
@setting[k] = v
@publish "appregistry", k
2017-08-14 00:20:19 +02:00
show: () ->
@trigger "focus"
2017-08-14 00:20:19 +02:00
blur: () ->
2017-08-15 02:56:04 +02:00
@.appmenu.set "items", [] if @.appmenu and @.pid == @.appmenu.pid
@trigger "blur"
2017-08-14 00:20:19 +02:00
hide: () ->
@trigger "hide"
2017-08-14 00:20:19 +02:00
2017-08-15 02:56:04 +02:00
toggle: () ->
@trigger "toggle"
2017-08-14 00:20:19 +02:00
onexit: (evt) ->
@cleanup(evt)
2017-08-14 00:20:19 +02:00
if not evt.prevent
2017-08-15 02:56:04 +02:00
@.appmenu.set "items", [] if @.pid == @.appmenu.pid
2017-08-14 00:20:19 +02:00
($ @scheme).remove()
2017-08-27 23:40:02 +02:00
meta: () -> _OS.APP[@name].meta
2017-08-15 02:56:04 +02:00
baseMenu: ->
2017-08-16 00:57:11 +02:00
mn =
2017-08-14 00:20:19 +02:00
[{
2017-08-27 23:40:02 +02:00
text: _OS.APP[@name].meta.name,
2017-08-15 02:56:04 +02:00
child: [
{ text: "About", dataid: "#{@name}-about" },
{ text: "Exit", dataid: "#{@name}-exit" }
2017-08-14 00:20:19 +02:00
]
}]
2017-08-16 00:57:11 +02:00
mn = mn.concat @menu() || []
mn
2017-08-14 00:20:19 +02:00
main: ->
#main program
# implement by subclasses
menu: ->
# implement by subclasses
# to add menu to application
[]
2017-08-11 01:58:46 +02:00
open:->
#implement by subclasses
data:->
#implement by subclasses
2017-08-14 00:20:19 +02:00
# to return app data
2017-08-11 01:58:46 +02:00
update:->
#implement by subclasses
cleanup: (e) ->
2017-08-14 00:20:19 +02:00
#implement by subclasses
# to handle the exit event
# use e.preventDefault() to
# discard the quit command
2017-08-15 02:56:04 +02:00
BaseApplication.type = 1
this.OS.GUI.BaseApplication = BaseApplication