-
Notifications
You must be signed in to change notification settings - Fork 6
workspace sdk 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.
- Your module creates a
ContextualActionorContextualActionGroupand initializes it with the workspace. - The module retrieves
IContextualActionsServicefromWorkspace.Services. - It registers the action or action group with that service.
- When the user opens a supported context menu, the framework evaluates whether the action applies to the current context.
- If the action is supported, Security Center shows it in the context menu and invokes it when the user selects it.
- When the module unloads, it unregisters the action or group.
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.
| Member | 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.
| 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 |
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.
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(entity => 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(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.
- Overview
- Connecting to Security Center
- SDK certificates
- Referencing SDK assemblies
- SDK compatibility
- Entities
- Entity cache
- Transactions
- Events
- Actions
- Security Desk
- Custom events
- ReportManager
- ReportManager query reference
- DownloadAllRelatedData and StrictResults
- Privileges
- Partitions
- Logging
- Overview
- Certificates
- Lifecycle
- Threading
- State management
- Configuration
- Restricted configuration
- Events
- Queries
- Request manager
- Database
- Entity ownership
- Entity mappings
- Server management
- Custom privileges
- Custom entity types
- Resolving non-SDK assemblies
- Deploying plugins
- .NET 8 support
- Overview
- Certificates
- Creating modules
- Tasks
- Pages
- Components
- Tile extensions
- Services
- Contextual actions
- Options extensions
- Configuration pages
- Monitors
- Shared components
- Commands
- Extending events
- Map extensions
- Timeline providers
- Image extractors
- Credential encoders
- Credential readers
- Cardholder fields extractors
- Badge printers
- Content builders
- Dashboard widgets
- Incidents
- Logon providers
- Pinnable content builders
- Custom report pages
- Overview
- Getting started
- MediaPlayer
- VideoSourceFilter
- MediaExporter
- MediaFile
- G64 converters
- FileCryptingManager
- PlaybackSequenceQuerier
- PlaybackStreamReader
- OverlayFactory
- PtzCoordinatesManager
- AudioTransmitter
- AudioRecorder
- AnalogMonitorController
- Camera blocking
- Overview
- Getting started
- Referencing entities
- Entity operations
- About access control in the Web SDK
- About video in the Web SDK
- Users and user groups
- Partitions
- Custom fields
- Custom card formats
- Actions
- Events and alarms
- Incidents
- Reports
- Tasks
- Macros
- Custom entity types
- System endpoints
- Performance guide
- Reference
- Under the hood
- Troubleshooting