PDA

View Full Version : Disable a contextmenu item


bigBADguy
12-18-2005, 02:10 PM
Since I cannot found the document about contextmenu. Is there anyway to disable/enable menuitem at runtime?

hqm
12-19-2005, 04:46 PM
There were a couple serious bugs in the last release with the context menu. The nightly builds have a new API checked in, with some example code available in the test directory (only ships with the source distro).

Example in test/contextmenu/api.lzx:


<canvas width="100%" height="80%" >
<debug fontsize="12" oninit="setWrapLines(true)"/>

<simplelayout/>

<method event="oninit">
var nm = new LzContextMenu();
var item1 = nm.makeMenuItem('Canvas Hello', function () { Debug.write("Hi, I'm this canvas", this); } );
nm.addItem(item1);
this.setContextMenu(nm);
Debug.write("setting new contextmenu on canvas from api.lzx");
</method>


<view width="100" height="100" bgcolor="#cccccc" name="v1">
<method event="oninit">
var cm = new LzContextMenu();
// Set up a LzDelegate as a callback
var item1 = cm.makeMenuItem('Item1', new LzDelegate(this, "handlerightclick"));
cm.addItem(item1);

var item2 = cm.makeMenuItem('Item2 (disabled)', new LzDelegate(this, "handlerightclick"));
item2.setEnabled(false);
cm.addItem(item2);

var item3 = cm.makeMenuItem('Item3', new LzDelegate(this, "handlerightclick"));
item3.setSeparatorBefore(true);
cm.addItem(item3);

var item4 = cm.makeMenuItem('Show Dialog', new LzDelegate(this, "handlerightclick"));
cm.addItem(item4);
// Menu items generate a "onselect" when they are selected
new LzDelegate(this, "showdialog", item4, "onselect");

this.setContextMenu(cm);

// "onmenuopen" event is to a LzContextMenu soon as the menu gets a mousedown on the right button.
// This gives you a chance to (quickly) rearrange the menu on the fly.
new LzDelegate(this, "menuselected", cm, "onmenuopen");

// "onselect" event is sent to an LzContextMenuItem when it is selected from the menu
new LzDelegate(this, "menuitemselected", item1, "onselect");

Debug.write(cm);
</method>

<method name="menuselected" args="val">
Debug.write("A context menu was opened with a right click, menu = ", val);
</method>

<method name="menuitemselected" args="val">
Debug.write("A right click on an item was detected, item = ", val);
</method>

<method name="handlerightclick" args="val">
Debug.write("handle item handlerightclick, val=", val);
</method>

<method name="showdialog">
md.open();
</method>



</view>




<modaldialog id="md" width="200" height="200">
<simplelayout/>
<text>This is your dialog</text>
<button onclick="md.close()" isdefault="true">OK</button>
</modaldialog>


</canvas>