This commit is contained in:
lxsang 2020-04-02 10:29:52 +02:00
parent 328a37320e
commit 4fda59a964
4 changed files with 41 additions and 10 deletions

View File

@ -20,11 +20,11 @@ class Announcer
@observable = {} @observable = {}
on: (evtName, callback) -> on: (evtName, callback) ->
@observable[evtName] = { one: [], many: [] } unless @observable[evtName] @observable[evtName] = { one: new Set(), many: new Set() } unless @observable[evtName]
@observable[evtName].many.push callback @observable[evtName].many.push callback
one: (evtName, callback) -> one: (evtName, callback) ->
@observable[evtName] = { one: [], many: [] } unless @observable[evtName] @observable[evtName] = { one: new Set(), many: new Set() } unless @observable[evtName]
@observable[evtName].one.push callback @observable[evtName].one.push callback
off: (evtName, callback) -> off: (evtName, callback) ->
@ -53,7 +53,7 @@ class Announcer
continue unless me.observable[evt] continue unless me.observable[evt]
for f, i in me.observable[evt].one for f, i in me.observable[evt].one
f data f data
me.observable[evt].one = [] me.observable[evt].one = new Set()
for f, i in me.observable[evt].many for f, i in me.observable[evt].many
f data f data
@ -68,7 +68,7 @@ Ant.OS.announcer =
quota: 0 quota: 0
listeners: {} listeners: {}
on: (e, f, a) -> on: (e, f, a) ->
Ant.OS.announcer.listeners[a.pid] = [] unless Ant.OS.announcer.listeners[a.pid] Ant.OS.announcer.listeners[a.pid] = new Set() unless Ant.OS.announcer.listeners[a.pid]
Ant.OS.announcer.listeners[a.pid].push { e: e, f: f } Ant.OS.announcer.listeners[a.pid].push { e: e, f: f }
Ant.OS.announcer.observable.on e, f Ant.OS.announcer.observable.on e, f
trigger: (e, d) -> Ant.OS.announcer.observable.trigger e, d trigger: (e, d) -> Ant.OS.announcer.observable.trigger e, d

View File

@ -7,6 +7,7 @@ class MenuEntryTag extends Ant.OS.GUI.BaseTag
@setopt "children", undefined @setopt "children", undefined
@setopt "child", undefined @setopt "child", undefined
@setopt "parent", undefined @setopt "parent", undefined
@setopt "rootid", undefined
on_data_changed: (data) -> on_data_changed: (data) ->
@set k, v for k, v of data @set k, v for k, v of data
@ -110,7 +111,7 @@ class SimpleMenuEntryTag extends MenuEntryTag
evt = { id: @aid(), data: e } evt = { id: @aid(), data: e }
e.preventDefault() e.preventDefault()
children = @get("children") children = @get("children")
if @is_root() and @has_children() if @is_root() and @has_children() and not @get "context"
$(@refs.submenu).show() $(@refs.submenu).show()
else else
@submenuoff() @submenuoff()
@ -145,12 +146,32 @@ class MenuTag extends Ant.OS.GUI.BaseTag
@setopt "parent", undefined @setopt "parent", undefined
@setopt "contentag", "afx-menu-entry" @setopt "contentag", "afx-menu-entry"
@setopt "items", [] @setopt "items", []
me = @
@root.show = (e) ->
me.showctxmenu e
showctxmenu: (e) ->
return unless @get "context"
#console.log
$(@root)
.css("top", e.clientY - 15 + "px")
.css("left", e.clientX - 5 + "px")
.show()
isctxmenu: () ->
return @get "context"
mount: () -> mount: () ->
me = @
on_context_changed: (v) -> on_context_changed: (v) ->
$(@refs.container).removeClass("context") $(@refs.container).removeClass("context")
$(@refs.container).addClass("context") if v 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) -> on_items_changed: (data) ->
me = @ me = @
@ -161,6 +182,7 @@ class MenuTag extends Ant.OS.GUI.BaseTag
el[0].uify @observable el[0].uify @observable
el[0].set "data", item el[0].set "data", item
el[0].set "parent", me.get("parent") el[0].set "parent", me.get("parent")
el[0].set "rootid", if me.get("parent") then me.get("parent").get("rootid") else me.aid()
item.domel = el[0] item.domel = el[0]
$("<li>").appendTo(@refs.container).addClass("afx-corner-fix") $("<li>").appendTo(@refs.container).addClass("afx-corner-fix")

View File

@ -1,4 +1,4 @@
<afx-app-window apptitle="Preview" width="650" height="500"> <afx-app-window apptitle="Preview" width="100" height="100">
<afx-hbox> <afx-hbox>
<afx-button data-height="30" toggle = "true" text="__(Read more)" iconclass="fa fa-camera-retro fa-lg" id="button"></afx-button> <afx-button data-height="30" toggle = "true" text="__(Read more)" iconclass="fa fa-camera-retro fa-lg" id="button"></afx-button>
</afx-hbox> </afx-hbox>

View File

@ -33,6 +33,7 @@ class ShowCase extends this.OS.GUI.BaseApplication
console.log tag console.log tag
### ###
openwin: () -> openwin: () ->
me = @
scheme = $.parseHTML """ scheme = $.parseHTML """
<afx-app-window apptitle="Preview" width="650" height="500"> <afx-app-window apptitle="Preview" width="650" height="500">
<afx-vbox> <afx-vbox>
@ -54,7 +55,7 @@ class ShowCase extends this.OS.GUI.BaseApplication
</afx-hbox> </afx-hbox>
<afx-resizer data-height="5" /> <afx-resizer data-height="5" />
<afx-hbox> <afx-hbox>
<afx-list-view data-id="list" dropdown="true" multiselect="false" /> <afx-list-view data-id="list" dropdown="false" multiselect="false" />
</afx-hbox> </afx-hbox>
<afx-hbox data-height="150"> <afx-hbox data-height="150">
<div>box center 3</div> <div>box center 3</div>
@ -63,13 +64,15 @@ class ShowCase extends this.OS.GUI.BaseApplication
</afx-vbox> </afx-vbox>
<afx-vbox data-width="150"> <afx-vbox data-width="150">
<div data-height="grow">box 3</div> <div data-height="grow">box 3</div>
<div data-height="200">box 4</div> <div data-height="200">box 4
</afx-vbox> </afx-vbox>
</afx-hbox> </afx-hbox>
</afx-vbox> </afx-vbox>
</afx-app-window> </afx-app-window>
""" """
ctmenu = $.parseHTML """<afx-menu data-id="mn-context" context="true" style="display:none;" /></div>"""
($ "#desktop").append scheme[0] ($ "#desktop").append scheme[0]
($ "#wrapper").append ctmenu[0]
obj = scheme[0].uify() obj = scheme[0].uify()
bt = $ "[data-id='bttest']", scheme[0] bt = $ "[data-id='bttest']", scheme[0]
bt[0].set "onbtclick", (e) -> bt[0].set "onbtclick", (e) ->
@ -77,9 +80,9 @@ class ShowCase extends this.OS.GUI.BaseApplication
obj.set "resizable", true obj.set "resizable", true
obj.set "minimizable", false obj.set "minimizable", false
obj.observable.on "exit", () -> obj.observable.on "exit", () ->
console.log "exit"
obj.observable.off "*" obj.observable.off "*"
$(obj).remove() $(obj).remove()
me.quit()
obj.observable.on "btclick", (e) -> obj.observable.on "btclick", (e) ->
console.log "button clicked" console.log "button clicked"
@ -98,6 +101,7 @@ class ShowCase extends this.OS.GUI.BaseApplication
list[0].set "onlistselect", (e) -> list[0].set "onlistselect", (e) ->
console.log(e.data.items) console.log(e.data.items)
sw = $ "[data-id='switch']", scheme[0] sw = $ "[data-id='switch']", scheme[0]
sw[0].set "onchange", (e) -> sw[0].set "onchange", (e) ->
console.log e.data console.log e.data
@ -108,6 +112,11 @@ class ShowCase extends this.OS.GUI.BaseApplication
menu = $ "[data-id='menu']", scheme[0] menu = $ "[data-id='menu']", scheme[0]
menu[0].set "items", @menu() menu[0].set "items", @menu()
ctmenu = ctmenu[0].uify(obj.observable)
ctmenu.set "items", @menu()
list[0].contextmenuHandle = (e) ->
console.log e
ctmenu.show e
mnFile:() -> mnFile:() ->
#console.log file #console.log file
me = @ me = @