Search code examples
sdkgenexus

Genexus Extensions SDK - Where can I find the avaliable Menu Context strings?


Im trying to use the Genexus Extensions SDK to place buttons on the IDE, in this case, i want to place it in the "context" menu, avaliable only in objects of type "Webpanel/Webcomponent" and "Transaction", Just like WorkWithPlus does here:

enter image description here

So far, digging up into the avaliable documentation, i've noticed that you need tu put the context type string into the xml tag and the GUID of the package that you're aiming to add the menu item, such as below in GeneXusPackage.package:

enter image description here

The Context ID above will add the item into the "Folder View" Context.

My questions:

  • Where can I find a list with all the possible ID Context strings?
  • What is that package attribute for, where can i get it's possible values?

I am using the SDK for Genexus 16 U11


Solution

  • I'm sorry to say that there is no extensive list of all the menus available. I'd never thought of it until now, and I see how it could be useful, so we'll definitely consider making it part of the SDK so that any package implementor may use it for reference.

    In the meantime, in order to add a new command in the context menu you mentioned, you have to add it to the command group that is listed as part of that menu. That group is KBObjectGrp which is provided by the core shell package whose id is 98121D96-A7D8-468b-9310-B1F468F812AE.

    First define your command in your .package file inside a Commands section:

    <Commands>
      <CommandDefinition id='MyCommand' context='selection'/>
    </Commands>
    

    Then add it to the KBObjectGrp mentioned earlier.

    <Groups>
      <Group refid='KBObjectGrp' package='98121D96-A7D8-468b-9310-B1F468F812AE'>
        <Command refid='MyCommand' />
      </Group>
    </Groups>
    

    Then in order to make your command available only to the objects you said before, you have to code a query handler for the command, that will rule when the command is enabled, disabled, or not visible at all. You can do that in the Initialize method of your package class.

    public override void Initialize(IGxServiceProvider services)
    {
        base.Initialize(services);
    
        CommandKey myCmdKey = new CommandKey(Id, "MyCommand");
        AddCommand(myCmdKey, ExecMyCommand, QueryMyCommand);
    }
    
    private bool QueryMyCommand(CommandData data, ref CommandStatus status)
    {
        var selection = KBObjectSelectionHelper.TryGetKBObjectsFrom(data.Context).ToList();
        status.Visible(selection.Count > 0 && selection.All(obj => obj.Type == ObjClass.Transaction || obj.Type == ObjClass.WebPanel));
        return true;
    }
    
    private bool ExecMyCommand(CommandData data)
    {
        // Your command here
        return true;
    }
    

    I'm using some helper classes here in order to get the objects from the selection, and then a class named ObjClass which exposes the guid of the most common object types. If you feel something isn't clear enough, don't hesitate to reach out.