workspace sdk contextual actions - Genetec/DAP GitHub Wiki
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.
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
}
}| 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 |
| Method | Returns | Description |
|---|---|---|
CanExecute(ContextualActionContext) |
bool | Return true if action is available |
Execute(ContextualActionContext) |
bool | Perform the action, return true on success |
The ContextualActionContext parameter indicates where the action was invoked. Check the context type to access relevant data.
Actions in Config Tool configuration panels.
| Property | Type | Description |
|---|---|---|
Page |
Page | The currently active configuration page |
SelectedEntities |
IList<Guid> | GUIDs of selected entities |
Actions when adding new entities.
Actions in entity browser dialogs and lists.
| Property | Description |
|---|---|
SelectedEntities |
Currently selected entity GUIDs |
Actions on map surfaces.
| Property | 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 |
Actions on tiles in Security Desk.
| Property | Type | Description |
|---|---|---|
State |
TileState | The tile's current state |
Access tile content through State.Content which returns a ContentGroup containing the displayed entity.
Actions in system status displays.
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);
}
}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.CopyContextualActionGroups.MaintenanceContextualActionGroups.Relation
Set your action's Group property to the group's ID:
public override Guid Group => MyActionGroupId;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 topUse 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(ValidateEntity);
}
private bool ValidateEntity(Entity entity)
{
return entity is CustomEntity customEntity && customEntity.CustomEntityType == MyCustomEntityTypeId;
}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(ValidateEntity);
foreach (Entity entity in entities)
{
// Process each selected entity
}
return true;
}For a complete example, see the ContextualActionSample on GitHub.