Is There Any Way to Hide the Context Menu Based on License Status?

In our application there is a context menu, upon clicking which some functionalities are executed. In VAF, we could stop all the things (extension methods, background jobs) running when the license status is not what we are looking for.

But we want to hide the context menu as well, for that we tried calling extension method to check license status. The approach doesn't work properly, like shows or hides the menu sometimes when it shouldn't be shown. 

Is there any good approach to hide the context menu?

  • A custom context menu item?

    In these cases I've called the server (called a vault extension method) when the shellUI starts, then use that as a flag to create/show the context menu item.

  • Calling of vault extension method when shellUI starts. I tried like this - 

    var commandName = "My Command"
    
    function OnNewShellUI(shellUI) {
        shellUI.Vault.ExtensionMethodOperations.ExecuteVaultExtensionMethod(
        "VAFExtensionMethod",
        "",
        function () {
            commandName = "My Modified Command"
        });
    
        shellUI.Events.Register(
            Event_NewNormalShellFrame,
            handleNewNormalShellFrame);
    }
    
    
    function handleNewNormalShellFrame(shellFrame) {
        shellFrame.Events.Register(
            Event_Started,
            getShellFrameStartedHandler(shellFrame));
    }
    
    function getShellFrameStartedHandler(shellFrame) {    
        return function () {
    
            var command = shellFrame.Commands.CreateCustomCommand(commandName);
            shellFrame.Commands.AddCustomCommandToMenu(command, MenuLocation_ContextMenu_Misc2_Top, 1);
            
            shellFrame.Commands.Events.Register(
            Event_CustomCommand,
            function (cmd) {
                if (cmd != command) {
                    return;
                }
    
                return true;
            });
    
        shellFrame.Events.Register(
            Event_NewShellListing,
            getNewShellListingHandler(shellFrame, command));
    
        if (null != shellFrame.Listing) {
            getNewShellListingHandler(shellFrame, command)(shellFrame.Listing);
        }
    };
    }

  • An error message would be helpful, but I guess that the issue is that you need to wait until the shell frame is started (or, at least, the shellUI, but you already have code attached for the shell frame starting) before you call into the vault.

  • My intension is to get My Modified Command as context menu command name. But I get My Command all the time. 

  • I've fixed the issue following your suggestion (create the command after loading the data, not before).

    Thank you so much.

    This is the working code snippet -

    var commandName = "My Command"
    
    function OnNewShellUI(shellUI) {
        shellUI.Events.Register(
            Event_NewNormalShellFrame,
            handleNewNormalShellFrame);
    }
    
    
    function handleNewNormalShellFrame(shellFrame) {
        shellFrame.Events.Register(
            Event_Started,
            getShellFrameStartedHandler(shellFrame));
    }
    
    function getShellFrameStartedHandler(shellFrame) {    
        return function () {
            shellFrame.ShellUI.Vault.Async.ExtensionMethodOperations.ExecuteVaultExtensionMethod(
            "VAFExtensionMethod",
            "",
            function (response) {
                // response will contain modified command name, for exaple "My Modified Command"
                commandName = response
                
                var command = shellFrame.Commands.CreateCustomCommand(commandName);
                shellFrame.Commands.AddCustomCommandToMenu(command, MenuLocation_ContextMenu_Misc2_Top, 1);
            
                shellFrame.Commands.Events.Register(
                Event_CustomCommand,
                function (cmd) {
                    if (cmd != command) {
                        return;
                    }
        
                    return true;
                });
    
                shellFrame.Events.Register(
                    Event_NewShellListing,
                    getNewShellListingHandler(shellFrame, command));
            
                if (null != shellFrame.Listing) {
                    getNewShellListingHandler(shellFrame, command)(shellFrame.Listing);
                }
            });
    };
    }