This commit is contained in:
lxsang 2020-04-02 18:33:07 +02:00
parent 4fda59a964
commit 3a47785a47
15 changed files with 230 additions and 82 deletions

View File

@ -35,6 +35,7 @@ coffees= src/core/core.coffee \
src/core/tags/SwitchTag.coffee \
src/core/tags/NSpinnerTag.coffee \
src/core/tags/MenuTag.coffee \
src/core/tags/GridView.coffee \
src/antos.coffee

View File

@ -18,29 +18,29 @@
class Announcer
constructor: () ->
@observable = {}
@enable = true
disable: () ->
@off("*")
@enable = false
on: (evtName, callback) ->
return unless @enable
@observable[evtName] = { one: new Set(), many: new Set() } unless @observable[evtName]
@observable[evtName].many.push callback
@observable[evtName].many.add callback
one: (evtName, callback) ->
return unless @enable
@observable[evtName] = { one: new Set(), many: new Set() } unless @observable[evtName]
@observable[evtName].one.push callback
@observable[evtName].one.add callback
off: (evtName, callback) ->
me = @
fn = (evt, cb) ->
return unless me.observable[evt]
if cb
for f, i in me.observable[evt].one
if f == cb
me.observable[evt].one.splice i, 1
break
for f, i in me.observable[evt].many
if f == cb
me.observable[evt].many.splice i, 1
break
me.observable[evt].one.delete(cb)
me.observable[evt].many.delete(cb)
else
delete me.observable[evt] if me.observable[evt]
if evtName is "*" then fn k, callback for k, v of me.observable else fn evtName, callback
@ -51,10 +51,10 @@ class Announcer
names = [name, "*"]
for evt in names
continue unless me.observable[evt]
for f, i in me.observable[evt].one
me.observable[evt].one.forEach (f) ->
f data
me.observable[evt].one = new Set()
for f, i in me.observable[evt].many
me.observable[evt].one = new Set()
me.observable[evt].many.forEach (f) ->
f data
if evtName is "*"
@ -68,7 +68,7 @@ Ant.OS.announcer =
quota: 0
listeners: {}
on: (e, f, a) ->
Ant.OS.announcer.listeners[a.pid] = new Set() unless Ant.OS.announcer.listeners[a.pid]
Ant.OS.announcer.listeners[a.pid] = [] unless Ant.OS.announcer.listeners[a.pid]
Ant.OS.announcer.listeners[a.pid].push { e: e, f: f }
Ant.OS.announcer.observable.on e, f
trigger: (e, d) -> Ant.OS.announcer.observable.trigger e, d

View File

@ -25,7 +25,7 @@ class BaseModel
@systemsetting = Ant.OS.setting
me = @
@on "exit", () -> me.quit()
@host = "#desktop"
@host = @_gui.workspace
@dialog = undefined
render: (p) ->
Ant.OS.GUI.loadScheme p, @, @host

View File

@ -11,23 +11,23 @@ class ButtonTag extends Ant.OS.GUI.BaseTag
@setopt "onbtclick", () ->
on_color_changed: (v) ->
__color__: (v) ->
console.log @refs
@refs.label.set "color", v
on_icon_changed: (v) ->
__icon__: (v) ->
@refs.label.set "icon", v
on_iconclass_changed: (v) ->
__iconclass__: (v) ->
@refs.label.set "iconclass", v
on_text_changed: (v) ->
__text__: (v) ->
@refs.label.set "text", v
on_enable_changed: (v) ->
__enable__: (v) ->
$(@refs.button).prop "disabled", !(@get "enable")
on_selected_changed: (v) ->
__selected__: (v) ->
$(@button).removeClass()
$(@button).addClass "selected" if v

View File

@ -0,0 +1,110 @@
class GridCellPrototype extends Ant.OS.GUI.BaseTag
constructor: (r, o) ->
super r, o
@setopt "class", "afxgridcell"
@setopt "data", {}
__class__: (v) ->
$(@root).removeClass().addClass @get("class")
class SimpleGridCell extends GridCellPrototype
constructor: (r, o) ->
super r, o
@setopt "header", false
__header__: (v) ->
__data__: (d) ->
@refs.cell.set k, v for k, v of d
mount: () ->
$(@root).css "display", "block"
layout: () ->
[{
el: "afx-label", ref: "cell"
}]
class GridViewTag extends Ant.OS.GUI.BaseTag
constructor: (r, o) ->
super r, o
@setopt "header", []
@setopt "headeritem", "afx-grid-cell"
@setopt "cellitem", "afx-grid-cell"
@setopt "cellclass", "afxgridcell"
@setopt "rows", []
__header__: (v) ->
return $(@refs.header).hide() if not v or v.length is 0
$(@refs.header).empty()
for item in v
el = $("<#{@get("headeritem")}>").appendTo @refs.header
el[0].uify undefined
el[0].set "data", item
item.domel = el[0]
@calibrate()
__rows__: (rows) ->
$(@refs.grid).empty()
for row in rows
for cell in row
el = $("<#{@get("cellitem")}>").appendTo @refs.grid
el[0].uify undefined
el[0].set "data", cell
cell.domel = el[0]
has_header: () ->
h = @get("header")
return h and h.length > 0
calibrate: () ->
@calibrate_header()
if @has_header()
$(@refs.container).css "height", $(@root).height() - $(@refs.header).height() + "px"
else
$(@refs.container).css "height", $(@root).height() + "px"
calibrate_header: () ->
header = @get "header"
return if not header or header.length is 0
colssize = []
ocw = 0
nauto = 0
totalw = $(@root).parent().width()
$.each header, (i, item) ->
if item.width
colssize.push item.width
ocw += item.width
else
colssize.push -1
nauto++
if nauto > 0
cellw = parseInt((totalw - ocw) / nauto)
$.each colssize, (i, e) ->
return unless e is -1
colssize[i] = cellw
template = ""
template += "#{v}px " for v in colssize
$(@refs.grid).css "grid-template-columns", template
$(@refs.header).css "grid-template-columns", template
mount: () ->
me = @
$(@refs.grid).css "display", "grid"
$(@refs.header).css "display", "grid"
@observable.on "resize", (e) -> me.calibrate()
$(@refs.container)
.css "width", "100%"
.css "overflow-x", "hidden"
.css "overflow-y", "auto"
layout: () ->
[
{ el: "div", ref: "header" },
{ el: "div", ref: "container", children: [
{ el: "div", ref: "grid" }
] }
]
Ant.OS.GUI.define "afx-grid-view", GridViewTag
Ant.OS.GUI.define "afx-grid-cell", SimpleGridCell
Ant.OS.GUI.define "afx-grid-cell-proto", GridCellPrototype

View File

@ -10,11 +10,11 @@ class LabelTag extends Ant.OS.GUI.BaseTag
mount: () ->
on_color_changed: (v) ->
__color__: (v) ->
return unless v
$(@refs.container).css "color", v
on_icon_changed: (v) ->
__icon__: (v) ->
$(@refs.i).attr "style", ""
if v
$(@refs.i)
@ -25,7 +25,7 @@ class LabelTag extends Ant.OS.GUI.BaseTag
else
$(@refs.i).hide()
on_iconclass_changed: (v) ->
__iconclass__: (v) ->
$(@refs.iclass).removeClass()
if v
$(@refs.iclass).addClass v
@ -35,7 +35,7 @@ class LabelTag extends Ant.OS.GUI.BaseTag
on_text_changed: (v) ->
__text__: (v) ->
@refs.text.nodeValue = v.__() if v
layout: () ->

View File

@ -31,16 +31,16 @@ class SimpleListItemTag extends ListViewItemTag
e.item = me.root
me.get("onclose")(e)
on_closable_changed: (v) ->
__closable__: (v) ->
if v then $(@refs.btcl).show() else $(@refs.btcl).hide()
on_selected_changed: (v) ->
__selected__: (v) ->
$(@refs.item).removeClass()
return unless v
$(@refs.item).addClass "selected"
@get("onselect")({ item: @root })
on_data_changed: (v) ->
__data__: (v) ->
return unless v
@refs.label.set "class", v.class if v.class
@refs.label.set "color", v.color if v.color
@ -81,10 +81,10 @@ class ListViewTag extends Ant.OS.GUI.BaseTag
@get "multiselect"
on_buttons_changed: (v) ->
__buttons__: (v) ->
return if @get "dropdown"
on_data_changed: (data) ->
__data__: (data) ->
$( @refs.mlist).empty()
for item in data
el = $("<#{@get "itemtag"}>").appendTo @refs.mlist
@ -140,7 +140,7 @@ class ListViewTag extends Ant.OS.GUI.BaseTag
return unless e.item
$(e.item).remove()
on_dropdown_changed: (v) ->
__dropdown__: (v) ->
$(@refs.container).removeAttr "style"
$(@refs.mlist).removeAttr "style"
$(@refs.container).css "flex", 1

View File

@ -4,15 +4,16 @@ class MenuEntryTag extends Ant.OS.GUI.BaseTag
super r, o
@setopt "data", {}
@setopt "onmenuselect", () ->
@setopt "onchildselect", () ->
@setopt "children", undefined
@setopt "child", undefined
@setopt "parent", undefined
@setopt "rootid", undefined
@setopt "root", undefined
on_data_changed: (data) ->
__data__: (data) ->
@set k, v for k, v of data
on_child_changed: (v) ->
__child__: (v) ->
@set "children", v
has_children: () ->
@ -34,47 +35,47 @@ class SimpleMenuEntryTag extends MenuEntryTag
@setopt "shortcut", undefined
@setopt "checked", false
on_switch_changed: (v) ->
__switch__: (v) ->
if @get("radio") or v
$(@refs.switch).show()
else
$(@refs.switch).hide()
on_radio_changed: (v) ->
__radio__: (v) ->
if @get("switch") or v
$(@refs.switch).show()
else
$(@refs.switch).hide()
on_checked_changed: (v) ->
__checked__: (v) ->
return unless @get("radio") or @get("switch")
@refs.switch.set "swon", v
on_color_changed: (v) ->
__color__: (v) ->
return unless v
@refs.label.set "color", v
on_icon_changed: (v) ->
__icon__: (v) ->
$(@refs.container).removeClass("fix_padding")
return unless v
@refs.label.set "icon", v
$(@refs.container).addClass("fix_padding")
on_iconclass_changed: (v) ->
__iconclass__: (v) ->
return unless v
@refs.label.set "iconclass", v
on_text_changed: (v) ->
__text__: (v) ->
return unless v isnt undefined
@refs.label.set "text", v
on_shortcut_changed: (v) ->
__shortcut__: (v) ->
$(@refs.shortcut).hide()
return unless v
$(@refs.shortcut).show()
$(@refs.shortcut).val v
on_children_changed: (v) ->
__children__: (v) ->
me = @
$(@refs.container).removeClass("afx_submenu")
return $(@refs.submenu).hide() unless v and v.length > 0
@ -83,6 +84,7 @@ class SimpleMenuEntryTag extends MenuEntryTag
.show()
.attr("style", "")
@refs.submenu.set "parent", @
@refs.submenu.set "root", me.get("root")
@refs.submenu.set "items", v
if @is_root()
$(@refs.container).mouseleave (e) ->
@ -110,7 +112,6 @@ class SimpleMenuEntryTag extends MenuEntryTag
e.item = @root
evt = { id: @aid(), data: e }
e.preventDefault()
children = @get("children")
if @is_root() and @has_children() and not @get "context"
$(@refs.submenu).show()
else
@ -121,9 +122,11 @@ class SimpleMenuEntryTag extends MenuEntryTag
p = @get "parent"
p.reset_radio() if p
@set "checked", !@get "checked"
@get("onmenuselect") evt
@observable.trigger "menuselect", evt
if @get("parent")
@get("parent").get("onchildselect") evt
if @get("root")
@get("root").get("onmenuitemselect") evt
layout: () ->
[{
@ -142,17 +145,24 @@ class SimpleMenuEntryTag extends MenuEntryTag
class MenuTag extends Ant.OS.GUI.BaseTag
constructor: (r, o) ->
super r, o
me = @
@setopt "context", false
@setopt "parent", undefined
@setopt "root", undefined
@setopt "contentag", "afx-menu-entry"
@setopt "onmenuitemselect", (e) -> me.handleselect e
@setopt "onmenuselect", (e) ->
@setopt "items", []
me = @
@root.show = (e) ->
me.showctxmenu e
handleselect: (e) ->
$(@root).hide() if @isctxmenu()
@get("onmenuselect") e
@observable.trigger "menuselect", e
showctxmenu: (e) ->
return unless @get "context"
#console.log
$(@root)
.css("top", e.clientY - 15 + "px")
.css("left", e.clientX - 5 + "px")
@ -161,28 +171,31 @@ class MenuTag extends Ant.OS.GUI.BaseTag
isctxmenu: () ->
return @get "context"
is_root: () ->
return @get("root") is undefined
mount: () ->
me = @
on_context_changed: (v) ->
return unless me.isctxmenu()
$(@refs.container).mouseleave (e) ->
return unless me.is_root()
$(me.root).hide()
__context__: (v) ->
$(@refs.container).removeClass("context")
return unless v
$(@refs.container).addClass("context")
$(@root).hide()
@observable.on "menuselect", (e) ->
console.log e.data.item
console.log e.data.item.get("rootid")
on_items_changed: (data) ->
__items__: (data) ->
me = @
$(@refs.container).empty()
$("<li>").appendTo(@refs.container).addClass("afx-corner-fix")
for item in data
el = $("<#{@get("contentag")}>").appendTo @refs.container
el[0].uify @observable
el[0].set "data", item
el[0].uify undefined
el[0].set "parent", me.get("parent")
el[0].set "rootid", if me.get("parent") then me.get("parent").get("rootid") else me.aid()
el[0].set "root", if me.get("parent") then me.get("parent").get("root") else me
el[0].set "data", item
item.domel = el[0]
$("<li>").appendTo(@refs.container).addClass("afx-corner-fix")

View File

@ -53,7 +53,7 @@ class NSpinnerTag extends Ant.OS.GUI.BaseTag
fn @refs.decr, "bottom"
fn @refs.incr, "top"
on_value_changed: (v) ->
__value__: (v) ->
$(@refs.holder).val @get("value")
evt = { id: @aid(), data: v }
@get("onchange")(evt)

View File

@ -18,7 +18,7 @@ class SwitchTag extends Ant.OS.GUI.BaseTag
@get("onchange") evt
@observable.trigger "switch", evt
on_swon_changed: (v) ->
__swon__: (v) ->
$(@refs.switch).removeClass()
$(@refs.switch).addClass "swon" if v

View File

@ -12,7 +12,7 @@ class TileLayoutTag extends Ant.OS.GUI.BaseTag
.css("width", "100%")
me = @
@observable.on "resize", (e) -> me.calibrate()
@observable.on "calibrate", (e) -> me.calibrate()
# @observable.on "calibrate", (e) -> me.calibrate()
@calibrate()
calibrate: () ->

View File

@ -74,10 +74,10 @@ class WindowTag extends Ant.OS.GUI.BaseTag
@resize()
@observable.trigger "rendered", { id: me.aid() }
on_minimizable_changed: (value) ->
__minimizable__: (value) ->
if value then $(@refs["minbt"]).show() else $(@refs["minbt"]).hide()
on_resizable_changed: (value) ->
__resizable__: (value) ->
if value
$(@refs["maxbt"]).show()
$(@refs["grip"]).show()
@ -85,7 +85,7 @@ class WindowTag extends Ant.OS.GUI.BaseTag
$(@refs["maxbt"]).hide()
$(@refs["grip"]).hide()
on_apptitle_changed: (value) ->
__apptitle__: (value) ->
$(@refs["dragger"]).text value.__() if value
enable_dragging: () ->

View File

@ -11,7 +11,8 @@ class Ant.OS.GUI.BaseTag
@root.get = (k) -> me.get k
@root.aid = () -> me.aid()
@refs = {}
@setopt "data-id", Math.floor(Math.random() * 100000) + 1
@setopt "data-id", (Math.floor(Math.random() * 100000) + 1).toString()
$(@root).attr "data-id", @get("data-id")
@children = []
for obj in @layout()
@ -40,7 +41,7 @@ class Ant.OS.GUI.BaseTag
@set k, v for k, v of value
else
@opts[opt] = value
@["on_#{opt}_changed"](value) if @["on_#{opt}_changed"]
@["__#{opt}__"](value) if @["__#{opt}__"]
@
aid: () ->

View File

@ -33,7 +33,7 @@ class Files extends this.OS.GUI.BaseApplication
@viewType.list = true
@apps = []
@view.contextmenuHandler = (e, m) ->
@view.contextmenuHandle = (e, m) ->
m.set "items", [ me.mnFile(), me.mnEdit() ]
m.set "onmenuselect", (evt) ->
me._gui.launch evt.item.data.app, evt.item.data.args if evt.item.data.app

View File

@ -58,8 +58,7 @@ class ShowCase extends this.OS.GUI.BaseApplication
<afx-list-view data-id="list" dropdown="false" multiselect="false" />
</afx-hbox>
<afx-hbox data-height="150">
<div>box center 3</div>
<div>box center 4</div>
<afx-grid-view data-id="grid" />
</afx-hbox>
</afx-vbox>
<afx-vbox data-width="150">
@ -73,20 +72,22 @@ class ShowCase extends this.OS.GUI.BaseApplication
ctmenu = $.parseHTML """<afx-menu data-id="mn-context" context="true" style="display:none;" /></div>"""
($ "#desktop").append scheme[0]
($ "#wrapper").append ctmenu[0]
obj = scheme[0].uify()
me.subwin = scheme[0].uify()
bt = $ "[data-id='bttest']", scheme[0]
bt[0].set "onbtclick", (e) ->
console.log "btclicked"
obj.set "resizable", true
obj.set "minimizable", false
obj.observable.on "exit", () ->
obj.observable.off "*"
$(obj).remove()
me.subwin.set "resizable", true
me.subwin.set "minimizable", false
me.subwin.observable.on "exit", () ->
me.subwin.observable.off "*"
$(me.subwin).remove()
me.quit()
obj.observable.on "btclick", (e) ->
me.subwin.observable.on "btclick", (e) ->
console.log "button clicked"
me.subwin.observable.on "menuselect", (e) ->
console.log e.id
list = $ "[data-id='list']", scheme[0]
@ -112,11 +113,30 @@ class ShowCase extends this.OS.GUI.BaseApplication
menu = $ "[data-id='menu']", scheme[0]
menu[0].set "items", @menu()
ctmenu = ctmenu[0].uify(obj.observable)
ctmenu = ctmenu[0].uify(me.subwin.observable)
ctmenu.set "items", @menu()
ctmenu.set "onmenuselect", (e) ->
console.log "root event", e
list[0].contextmenuHandle = (e) ->
console.log e
ctmenu.show e
grid = $ "[data-id='grid']", scheme[0]
grid[0].set "header", [{ text: "header1", width: 80 }, { text: "header2" }, { text: "header3" }]
grid[0].set "rows", [
[{ text: "text 1" }, { text: "text 2" }, { text: "text 3" }],
[{ text: "text 4" }, { text: "text 5" }, { text: "text 6" }],
[{ text: "text 7" }, { text: "text 8" }, { text: "text 9" }],
[{ text: "text 7" }, { text: "Subgrid on columns and rows. Subgrid on columns, implicit grid rows. Subgrid on rows, defined column tracks" }, { text: "text 9" }],
[{ text: "text 7" }, { text: "text 8" }, { text: "text 9" }],
[{ text: "text 7" }, { text: "text 8" }, { text: "text 9" }],
[{ text: "text 7" }, { text: "text 8" }, { text: "text 9" }],
[{ text: "text 7" }, { text: "text 8" }, { text: "text 9" }],
[{ text: "text 7" }, { text: "text 8" }, { text: "text 9" }],
[{ text: "text 7" }, { text: "text 8" }, { text: "text 9" }],
[{ text: "text 7" }, { text: "text 8" }, { text: "text 9" }]
]
mnFile:() ->
#console.log file
me = @
@ -130,7 +150,7 @@ class ShowCase extends this.OS.GUI.BaseApplication
{ text: "__(Download)", dataid: "#{@name}-download" },
{ text: "__(Share file)", dataid: "#{@name}-share", shortcut: 'C-S' },
{ text: "__(Properties)", dataid: "#{@name}-info", shortcut: 'C-I' }
], onmenuselect: (e) ->
], onchildselect: (e) -> console.log "child", e
}
return arr
mnEdit: () ->
@ -143,8 +163,11 @@ class ShowCase extends this.OS.GUI.BaseApplication
{ text: "__(Cut)", dataid: "#{@name}-cut", shortcut: 'C-X' },
{ text: "__(Copy)", dataid: "#{@name}-copy", shortcut: 'C-C' },
{ text: "__(Paste)", dataid: "#{@name}-paste", shortcut: 'C-P' }
], onmenuselect: (e) ->
], onchildselect: (e) -> console.log "child", e
}
cleanup: () ->
return unless @subwin
$(@subwin).remove()
menu: () ->
me = @
menu = [
@ -153,7 +176,7 @@ class ShowCase extends this.OS.GUI.BaseApplication
{
text: "__(View)",
child: [
{ text: "__(Refresh)", dataid: "#{@name}-refresh" },
{ text: "__(Refresh)", dataid: "#{@name}-refresh", onmenuselect: (e) -> console.log "select", e },
{ text: "__(Sidebar)", switch: true, checked: true },
{ text: "__(Navigation bar)", switch: true, checked: false },
{ text: "__(Hidden files)", switch: true, checked: true, dataid: "#{@name}-hidden" },
@ -161,9 +184,9 @@ class ShowCase extends this.OS.GUI.BaseApplication
{ text: "__(Icon view)", radio: true, checked: true, dataid: "#{@name}-icon", type: 'icon' },
{ text: "__(List view)", radio:true, checked: false, dataid: "#{@name}-list", type: 'list' },
{ text: "__(Tree view)", radio:true, checked: false, dataid: "#{@name}-tree", type: 'tree' }
], onmenuselect: (e) ->
], onchildselect: (e) -> console.log "child", e
},
], onmenuselect: (e) ->
], onchildselect: (e) -> console.log "child", e
},
]
menu