Hello,
I have a situation where users can drag images onto a canvas (from another tabset). Once the image is placed, they need to be able to right click on the image (within the canvas) and get a context menu with choices to duplicate it, delete it or preview it (in another modal screen). I am wondering how the sequence of events works with contextmenu wtihin a canvas. For instance, once the user does a right click on the image widget, they get menu and click on “Preview”. Can I get a handle to the image widget that was clicked on? My perception is that once the user is in menu, the code loses track of the underlying image. Can anyone please help me understand? thanks.
For a context menu, menuItem.click is passed the widget that showed the contextMenu as the “target” parameter.
Still a little unclear
Thanks for the response. I looked at the API. It says target is “for a menu shown as a context menu, the Canvas the menu was shown on. Otherwise the Menu instance of which this MenuItem is a member.” Slightly contradictory to what you said (unless I am misinterpreting). I am just trying to make sure that I get the Image widget, right clicking on which I got the menu (instead of the Canvas that houses the Image widget).
thanks.
Both the docs and the clarification are correct. An Img widget is a Canvas - all SmartClient visual components extend from Canvas.
Thanks a ton
Thank you very much for the clarification. It makes a lot of sense now.
Still missing something?
I was trying to implement this functionality. However, I still don’t understand something.
I have the following code:
isc.Menu.create({
ID:"itemListMenu",
cellHeight:22,
data:[
{title:"Add New",
icon:"demoApp/icon_add.png", submenu: [
{title: "A",
click: function (target, item, menu) {
isc.say ("target name is " + target.src);
return false;
}
},
{title: "B"},
{title: "C"}
]//,
// click:function () {
// itemList.selection.deselectAll();
// itemDetailTabs.selectTab(1);
// itemList.updateDetails();
// }
},
{isSeparator:true},
{title:"Remove",
icon:"demoApp/icon_view.png"},
{title:"Edit",
icon:"demoApp/icon_edit.png"},
{title:"Preview",
icon:"demoApp/icon_delete.png"}
]
})
isc.defineClass("DroppedLogo", "Img").addProperties({
// width:113, height:86,
appImgDir: "MY_Site/",
canDragReposition: true,
keepInParentRect: true,
dragAppearance: "target",
showContextMenu: "this.destroy(); return false;"
})
isc.defineClass("PieceBin", "Canvas").addProperties({
width:870, height:750, overflow:"hidden",
showEdges: true,
edgeSize: 12,
showContextMenu: "return false",
// cellContextClick:"return itemListMenu.showContextMenu()",
canAcceptDrop: true,
dropOver: "if (this.willAcceptDrop()) this.setBackgroundColor('#ffff80')",
dropOut: "this.setBackgroundColor('#ffffff')",
drop: function () {
this.addChild(isc.DroppedLogo.create({
src: "someimage.gif",
showContextMenu: "return itemListMenu.showContextMenu()",
width: myWidth,
height: myHeight,
canDragResize: true,
left: this.getOffsetX()-15-this.edgeSize,
top: this.getOffsetY()-15-this.edgeSize
}))
}
}
})
When I try to print out the src or ID attribute of the Image (after clicking on Title A), it gives me “undefined” or isc_menu_40 (for ID). I was expecting the DroppedLogo’s src or ID.
Can you please tell me what I am missing? thanks.
I figured it out…
I followed the steps listed in another thread in this forum. Basically, I called
showContextMenu: "itemListMenu.currentRecord=this.src; return itemListMenu.showContextMenu()",
within the Img create section. From the menu, I am calling
click: function (target, item, menu) {
isc.say ("target name is " + target.ID + " and currentrecord is " + menu.currentRecord);
return false;
},
This seems to be working. Thanks for your help.