Petr,
listbox.getSelection() returns an array of selected items.
contextMenu.getOpener() is only referring to the same list the context
menu is attached to, so in a simple case it is sufficient to use the
list itself.
This listener deletes the selected items:
delItem.addListener("execute", function(ev) {
var opener = contextMenu.getOpener();
if (listbox.getSelection())
{
var ls = listbox.getSelection();
for (var i=0; i<ls.length; i++)
{
listbox.remove(ls[i]);
}
}
}, this);
The only thing that bothers me is that a right click on an item toggles
its selection (I would expect this only on a left click); I can't say
how to change that behavior.
HTH,
greetings
Stefan
Petr Kobalíček wrote:
> Hi devs,
>
> how to get selected list item when context menu is used? Note that I'm
> using additive selection.
>
> Playground:
>
> http://demo.qooxdoo.org/current/playground/#%7B%22code%22%3A%20%22var%2520doc%2520%253D%2520this.getRoot%28%29%253B%250A%250Avar%2520listbox%2520%253D%2520new%2520qx.ui.form.List%28%29%253B%250A%250Alistbox.set%28%257Bwidth%253A200%252C%2520height%253A150%257D%29%253B%250Alistbox.setSelectionMode%28%2522additive%2522%29%253B%250A%250Adoc.add%28listbox%252C%2520%257Bleft%2520%253A%2520100%252C%2520top%2520%2520%253A%252050%257D%29%253B%250A%250Afor%2520%28var%2520i%2520%253D%25200%253B%2520i%2520%253C%2520100%253B%2520i%252B%252B%29%250A%257B%250A%2520%2520var%2520item%2520%253D%2520new%2520qx.ui.form.ListItem%28%2522Item%2520%2523%2522%2520%252B%2520i%29%253B%250A%2520%2520listbox.add%28item%29%253B%250A%257D%250A%250Avar%2520contextMenu%2520%253D%2520new%2520qx.ui.menu.Menu%28%29%253B%250Avar%2520delItem%2520%253D%2520new%2520qx.ui.menu.Button%28%2522Delete%2522%29%253B%250A%250AdelItem.addListener%28%2522execute%2522%252C%2520function%28ev%29%2520%257B%250A%2520%2520%252
F%2
>
> 52F%2520How%2520to%2520get%2520current%2520list%2520item%253F%2520Opener%2520is%2520listbox.%250A%2520%2520var%2520opener%2520%253D%2520contextMenu.getOpener%28%29%253B%250A%2520%2520alert%28opener%29%253B%250A%257D%252C%2520this%29%253B%250A%250AcontextMenu.add%28delItem%29%253B%250Alistbox.setContextMenu%28contextMenu%29%253B%250A%22%7D
>
> Sample code:
>
> var doc = this.getRoot();
>
> var listbox = new qx.ui.form.List();
>
> listbox.set({width:200, height:150});
> listbox.setSelectionMode("additive");
>
> doc.add(listbox, {left : 100, top : 50});
>
> for (var i = 0; i < 100; i++)
> {
> var item = new qx.ui.form.ListItem("Item #" + i);
> listbox.add(item);
> }
>
> var contextMenu = new qx.ui.menu.Menu();
> var delItem = new qx.ui.menu.Button("Delete");
>
> delItem.addListener("execute", function(ev) {
> // How to get current list item? Opener is listbox.
> var opener = contextMenu.getOpener();
> alert(opener);
> }, this);
>
> contextMenu.add(delItem);
> listbox.setContextMenu(contextMenu);
>
> Thanks for ideas:)
>
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel