Note, for now I punted on the LZX'ified API, (<contextmenu> and <contextmenuitem>) because I couldn't come up with an acceptably elegant way to support that and also have an orthogonal and easy to use API for instantiating the classes manually in script.

---------- Forwarded message ----------
From: Henry Minsky < [EMAIL PROTECTED]>
Date: Nov 29, 2005 8:56 PM
Subject: proposed contextmenu API
To: Elliot Winard <[EMAIL PROTECTED]>

Here's a more fleshed out example of the API  I am working on. There are two
independent ways to get the callback when someone clicks on an item.
You can pass a delegate that will get executed, or you can listen for a "onselectitem"
event from an LzContextMenuItem.

The LzContextMenu itself sends a "onselect" event just when the user right clicks, so you have a little time to dynamically rearrange the menu before it displays.



<canvas width="100%" height="80%" >
  <debug  fontsize="12"/>

  <simplelayout/>

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

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

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

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

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

    this.setContextMenu(cm);

    // "onselect" event is sent as 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, "onselect");

    // "onselectitem" event is sent when an item is selected from the menu
    new LzDelegate(this, "menuitemselected", item1, "onselectitem");

    Debug.write(cm);
  </method>

  <method name="menuselected" args="val">
    Debug.write("A right click on the menu was detected, val= ", val);
  </method>

  <method name="menuitemselected" args="val">
    Debug.write("A right click on an item was detected, val= ", 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 isdefault="true">OK</button>
</modaldialog>


</canvas>



--
Henry Minsky
Software Architect
[EMAIL PROTECTED]

_______________________________________________
Laszlo-dev mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-dev

Reply via email to