Yury Apanasik
Yury Apanasik

Reputation: 113

Click event information in context menu callback

There is a possibility to create custom items for viewer's context menu and callback can be registered ('target' property). But click event doesn't passed inside this callback - I need it to get 'ctrl' key state. To fix that I have to override Autodesk.Viewing.Private.ContextMenu.prototype.addCallbackToMenuItem method as 'dirty solution'. Is there any other solution? P.S. Or could you pass 'event' inside 'target' callback inside 'addCallbackToMenuItem' method out-of-the-box? It is not a big change, but it is useful to process meta buttons state

Upvotes: 1

Views: 353

Answers (1)

Bryan Huang
Bryan Huang

Reputation: 5342

Not exactly sure what the hold up is for your need here?

When you register the custom context menu you have access to original mouse event as well as the key press status off the status object:

NOP_VIEWER.registerContextMenuCallback('MyExtensionName', function (menu, status) {

         menu.push({
              title: 'context menu name',
              target: function () {
                  //access mouse event via "status.event"
         }});

      })

EDIT The same event object is available with Autodesk.Viewing.Extensions.ViewerObjectContextMenu.buildMenu

ViewerObjectContextMenu.prototype.buildMenu = function (event, status) {
...

Upvotes: 2

Related Questions