Skip to content

workspace sdk contextual actions

Andre Lafleur edited this page Apr 20, 2026 · 5 revisions

About contextual actions

Contextual actions appear in right-click context menus throughout Security Desk and Config Tool. They provide context-sensitive operations for entities, tiles, maps, and other UI elements.

Use a contextual action when the operation depends on what the operator right-clicked, such as an entity, a tile, or a map object, rather than on a standalone task or page.

How contextual actions work

  1. Your module creates a ContextualAction or ContextualActionGroup and initializes it with the workspace.
  2. The module retrieves IContextualActionsService from Workspace.Services.
  3. It registers the action or action group with that service.
  4. When the user opens a supported context menu, the framework evaluates whether the action applies to the current context.
  5. If the action is supported, Security Center shows it in the context menu and invokes it when the user selects it.
  6. When the module unloads, it unregisters the action or group.

ContextualAction

Create a contextual action by inheriting from Genetec.Sdk.Workspace.ContextualAction.ContextualAction:

public class MyAction : ContextualAction
{
    public override Guid Id => new Guid("...");

    public override bool CanExecute(ContextualActionContext context) => true;

    public override bool Execute(ContextualActionContext context)
    {
        // Perform action
        return true; // Return true on success
    }
}

ContextualAction members

Member Type Description
Id Guid (abstract) Unique action identifier
Group Guid (virtual) Action group identifier
Priority int (virtual) Sort priority (lower values appear first)
Name string (virtual) Display name
Icon ImageSource (virtual) Menu icon
Workspace Workspace Workspace instance

Abstract methods

Method Returns Description
CanExecute(ContextualActionContext) bool Return true if action is available
Execute(ContextualActionContext) bool Perform the action, return true on success

Context types

The ContextualActionContext parameter indicates where the action was invoked. Check the context type to access relevant data.

ConfigurationContextualActionContext

Actions in Config Tool configuration panels.

Member Type Description
Page Page The currently active configuration page
SelectedEntities IList<Guid> GUIDs of selected entities

AddEntityContextualActionContext

Actions when adding new entities.

EntityBrowserContextualActionContext

Actions in entity browser dialogs and lists.

Property Description
SelectedEntities Currently selected entity GUIDs

MapContextualActionContext

Actions on map surfaces.

Member Type Description
MapId Guid The map GUID
Location GeoCoordinate Click location on map
SelectedEntity Guid First selected entity GUID
SelectedEntities IList<Guid> All selected entity GUIDs
EditMode bool Whether the map is in edit mode
ViewArea GeoBounds Current visible map area

TileContextualActionContext

Actions on tiles in Security Desk.

Member Type Description
State TileState The tile's current state

Access tile content through State.Content which returns a ContentGroup containing the displayed entity.

SystemStatusContextualActionContext

Actions in system status displays.

Registering contextual actions

Register contextual actions using IContextualActionsService:

public class SampleModule : Module
{
    private MyAction m_action;

    public override void Load()
    {
        var service = Workspace.Services.Get<IContextualActionsService>();

        m_action = new MyAction();
        m_action.Initialize(Workspace);
        service.Register(m_action);
    }

    public override void Unload()
    {
        var service = Workspace.Services.Get<IContextualActionsService>();
        service.Unregister(m_action);
    }
}

Action groups

Group related actions together by creating a class that inherits from ContextualActionGroup:

public class MyActionGroup : ContextualActionGroup
{
    public override Guid Id => new Guid("...");

    public override string Name => "My Actions";

    public override int Priority => 100;
}

Register the group with the service:

var service = Workspace.Services.Get<IContextualActionsService>();
service.Register(new MyActionGroup());

You can also use predefined groups from the ContextualActionGroups static class:

  • ContextualActionGroups.Copy
  • ContextualActionGroups.Maintenance
  • ContextualActionGroups.Relation

Set your action's Group property to the group's ID:

public override Guid Group => MyActionGroupId;

Priority ordering

The Priority property controls menu ordering. Lower values appear before higher values. The default is int.MaxValue, placing actions at the end.

public override int Priority => 10; // Appears near top

Conditional availability

Use CanExecute to control when the action appears. Return false to hide the action from the menu entirely.

public override bool CanExecute(ContextualActionContext context)
{
    return context is ConfigurationContextualActionContext configContext
        && configContext.SelectedEntities
            .Select(Workspace.Sdk.GetEntity)
            .All(entity => entity is CustomEntity customEntity
                && customEntity.CustomEntityType == MyCustomEntityTypeId);
}

Accessing context data

Cast the context to the appropriate type to access specific properties:

public override bool Execute(ContextualActionContext context)
{
    if (context is not ConfigurationContextualActionContext configContext)
        return false;

    IEnumerable<Entity> entities = configContext.SelectedEntities
        .Select(Workspace.Sdk.GetEntity)
        .Where(entity => entity is CustomEntity customEntity
            && customEntity.CustomEntityType == MyCustomEntityTypeId);

    foreach (Entity entity in entities)
    {
        // Process each selected entity
    }

    return true;
}

For a complete example, see the ContextualActionSample on GitHub.

See also

Platform SDK

Plugin SDK

Workspace SDK

Media SDK

Macro SDK

Web SDK

Media Gateway

Genetec Web Player

Clone this wiki locally