Источник:
http://olondono.blogspot.com/2008/02...-axaxapta.html
==============
In the following sample, I have duplicated the
sysAOT form, and I have overrode the
context method for the tree control. Here the code to show the
system context menu for any selected
treeNode.
X++:
PopupMenu popupMenu;
SysContextMenu sysContextMenu;
int idx = tree.getFirstSelected();
TreeNode treeNode = tree.getItem(idx).data();
// add some custom menu items
int editMenu;
int choice;
;
// current selected treeNode is valid ?
if (treeNode == null)
return;
// create the SysContextMenu for this TreeNode
sysContextMenu = new SysContextMenuTreeNode(treeNode);
// System API call to build the popup menu
popupMenu = sysContextMenu.buildMenu(this.hWnd());
// Add a custom edit menu
popupMenu.insertBreak();
editMenu = popupMenu.insertItem("Edit");
// showing menu
choice = popupMenu.draw();
// Showing and processing this popupMenu
if (!sysContextMenu.runMenu(choice, sysContextMenu))
{
if (choice == editMenu)
{
SysInfoAction_Editor::newOpen(treeNode.treeNodePath()).run();
}
}
But, looking in depth, I found that the
sysAotFind form can be used to get some practical sample on how we can create our custom popup menu. Here an adapted version of that code to the previous
SysAOT2 form(method context within control tree):
X++:
// current selected treeNode
int idx = tree.getFirstSelected();
TreeNode treeNode = tree.getItem(idx).data();
// We want to build, a popup menu, with a custom submenu and another
// sysContextMenu as submenu (add-ins menu item)
PopupMenu popupMenu = new PopupMenu(this.hWnd());
PopupMenu copyMenu = new PopupMenu(this.hWnd(), popupMenu);
PopupMenu subSysContextMenu;
SysContextMenu sysContextMenu;
// Menu options
int open;
int editMethod;
int copyName;
int copyPath;
int copyFullPath;
int copyAll;
int choice;
int find;
;
// current selected treeNode is valid ?
if (treeNode == null)
return;
// create the SysContextMenu for this TreeNode
sysContextMenu = new SysContextMenuTreeNode(treeNode);
//---------------------------------
// Building the menu
open = popupMenu.insertItem("Open");
popupMenu.insertBreak();
editMethod = popupMenu.insertItem("Edit");
copyName = copyMenu.insertItem("Copy Name");
copyPath = copyMenu.insertItem("Copy Path");
copyFullPath = copyMenu.insertItem("Copy FullPath");
copyAll = copyMenu.insertItem("Copy All");
popupMenu.insertPopupMenu("Copy", copyMenu);
popupMenu.insertBreak();
find = popupMenu.insertItem("Find");
popupMenu.insertBreak();
subSysContextMenu = sysContextMenu.buildMenu(this.hWnd(), popupMenu);
popupMenu.insertPopupMenu("Add-ins", subSysContextMenu);
//---------------------------------
// Now, showing the popup menu
choice = popupMenu.draw();
// processing option
if (!sysContextMenu.runMenu(choice, sysContextMenu))
{
switch (choice)
{
case open:
// to implement
break;
case editMethod:
SysInfoAction_Editor::newOpen(treeNode.treeNodePath()).run();
break;
case find:
// to implement
break;
case copyName, copyPath, copyFullPath, copyAll:
// to implement
break;
}
}
Источник:
http://olondono.blogspot.com/2008/02...-axaxapta.html