How to implement a context-menu
To implement a context-menu you can use a code as showed in the following example:
// set up a command var com = new qx.client.Command; com.addEventListener("execute", function(e){ this.debug("What object i've clicked on?"); // show the opening widget this.debug("e.getData() = " + e.getData().getParentMenu().getOpener()); }, this); // set up the context-menu var cmenu = new qx.ui.menu.Menu; // setup the button and add the command var m_1 = new qx.ui.menu.Button("Show Target", null, com); cmenu.add(m_1); cmenu.addToDocument(); // show the context-menu image.setContextMenu(cmenu); image.addEventListener("contextmenu", function(e) { this.getContextMenu().setLeft(e.getClientX()); this.getContextMenu().setTop(e.getClientY()); // this step is important - set the image as the opening widget this.getContextMenu().setOpener(this); this.getContextMenu().show(); }, image);
The implementation of the context-menu will be rewritten to allow an easier use of this feature. In the new implementation the last section should not be needed. With a correct implementation of the context-menu only the call of
image.setContextMenu(cmenu);
should be needed to setup and use a context-menu.
