From 5d987f8fb6c06f9e64dae933638875ecca8634be Mon Sep 17 00:00:00 2001 From: lxsang Date: Fri, 28 Feb 2020 18:59:41 +0100 Subject: [PATCH] multiselect --- src/core/tags/ListViewTag.coffee | 29 +++++++++++++++++++---- src/packages/ShowCase/coffees/main.coffee | 5 +++- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/core/tags/ListViewTag.coffee b/src/core/tags/ListViewTag.coffee index cf8469d..3deca8f 100644 --- a/src/core/tags/ListViewTag.coffee +++ b/src/core/tags/ListViewTag.coffee @@ -71,12 +71,16 @@ class ListViewTag extends Ant.OS.GUI.BaseTag @setopt "itemtag", "afx-list-item" @setopt "multiselect", false @setopt "selectedItem", undefined - @setopt "selectedIndex", -1 + @setopt "selectedItems", [] @items = [] $(@root) .css "display", "flex" .css "flex-direction", "column" + multiselect: () -> + @get "multiselect" + + on_buttons_changed: (v) -> return if @get "dropdown" @@ -94,21 +98,36 @@ class ListViewTag extends Ant.OS.GUI.BaseTag .set "ondbclick", (e) -> me.idbclick e .set "onclick", (e) -> - return if not e.item or e.item is me.selectedItem - e.item.set "selected", true + me.iclick e .set "onselect", (e) -> me.iselect e .set "onclose", (e) -> me.iclose e + iclick: (e) -> + return if not e.item + list = @get("selectedItems") + if @multiselect() and list.includes(e.item) + list.splice(list.indexOf(e.item)) + return e.item.set "selected", false + + e.item.set "selected", true + icontextmenu: (e) -> console.log "context menu", e idbclick: (e) -> console.log "db click", e iselect: (e) -> return unless e.item - @selectedItem.set "selected", false if @selectedItem - @selectedItem = e.item + if @multiselect() + return if @get("selectedItems").includes e.item + @set "selectedItem", e.item + @get("selectedItems").push e.item + e.items = @get("selectedItems") + else + @get("selectedItem").set "selected", false if @get("selectedItem") + @set "selectedItem", e.item + @set "selectedItems", [e.item] @get("onlistselect")(e) iclose: (e) -> diff --git a/src/packages/ShowCase/coffees/main.coffee b/src/packages/ShowCase/coffees/main.coffee index 2315bfe..648dd6a 100644 --- a/src/packages/ShowCase/coffees/main.coffee +++ b/src/packages/ShowCase/coffees/main.coffee @@ -50,7 +50,7 @@ class ShowCase extends this.OS.GUI.BaseApplication - +
box center 3
@@ -90,6 +90,9 @@ class ShowCase extends this.OS.GUI.BaseApplication { text: "some thing 4" }, { text: "some thing 5" } ] + list[0].set "onlistselect", (e) -> + console.log(e.items) + ShowCase.singleton = true this.OS.register "ShowCase", ShowCase \ No newline at end of file