Plasma Engine  2.0
Loading...
Searching...
No Matches
plActionManager Class Reference

Stores 'actions' (things that can be triggered from UI). More...

#include <ActionManager.h>

Classes

struct  Event
 

Static Public Member Functions

static plActionDescriptorHandle RegisterAction (const plActionDescriptor &desc)
 
static bool UnregisterAction (plActionDescriptorHandle &ref_hAction)
 
static const plActionDescriptorGetActionDescriptor (plActionDescriptorHandle hAction)
 
static plActionDescriptorHandle GetActionHandle (const char *szCategory, const char *szActionName)
 
static plString FindActionCategory (const char *szActionName)
 Searches all action categories for the given action name. Returns the category name in which the action name was found, or an empty string.
 
static plResult ExecuteAction (const char *szCategory, const char *szActionName, const plActionContext &context, const plVariant &value=plVariant())
 Quick way to execute an action from code.
 
static void SaveShortcutAssignment ()
 
static void LoadShortcutAssignment ()
 
static const plIdTable< plActionId, plActionDescriptor * >::ConstIterator GetActionIterator ()
 

Static Public Attributes

static plEvent< const Event & > s_Events
 

Detailed Description

Stores 'actions' (things that can be triggered from UI).

Actions are usually represented by a button in a toolbar, or a menu entry. Actions are unique across the entire application. Each action is registered exactly once, but it may be referenced by many different plActionMap instances, which defines how an action shows up in a window.

Through RegisterAction() / UnregisterAction() an action is added or removed. These functions are usually not called directly, but rather the macros at the top of this file are used (see PL_REGISTER_CATEGORY, PL_REGISTER_MENU, PL_REGISTER_ACTION_X, ...).

Unit tests can call ExecuteAction() to directly invoke an action. Widgets use plActionMap to organize which actions are available in a window, and how they are structured. For instance, the same action can appear in a menu, in a toolbar and a context menu. In each case their location may be different (top-level, in a sub-menu, etc). See plActionMap for details.

Member Function Documentation

◆ ExecuteAction()

plResult plActionManager::ExecuteAction ( const char * szCategory,
const char * szActionName,
const plActionContext & context,
const plVariant & value = plVariant() )
static

Quick way to execute an action from code.

The use case is mostly for unit tests, which need to execute actions directly and without a link dependency on the code that registered the action.

Parameters
szCategoryThe category of the action, ie. under which name the action appears in the Shortcut binding dialog. For example "Scene", "Scene - Cameras", "Scene - Selection", "Assets" etc. This parameter may be nullptr in which case FindActionCategory(szActionName) is used to try to detect the category automatically.
szActionNameThe name (not mapped path) under which the action was registered. For example "Selection.Copy", "Prefabs.ConvertToEngine", "Scene.Camera.SnapObjectToCamera"
contextThe context in which to execute the action. Depending on the plActionScope of the target action, some members are optional. E.g. for document actions, only the m_pDocument member must be specified.
valueOptional value passed through to the plAction::Execute() call. Some actions use it, most don't.
Returns
Returns failure in case the action could not be found.

The documentation for this class was generated from the following files: