Studio Developer Manual / Version 2010
Table Of ContentsManaged actions are used to reuse the same action instance for different components, for example a button and a menu item, and even for a keyboard shortcut. This not only saves action instances, but can be crucial for keeping action state consistent.
Unlike previous examples, a managed action is not added to a button or menu item directly.
Instead, a managed action is registered by giving it an actionId
and
adding it to the actionList
property of a to a container. To add a managed action
to an existing container, use a Studio plugin rule and the
AddArrayItemsPlugin
with arrayProperty="actionList"
.
Afterwards buttons that are located somewhere below this container may access the action using
an ActionRef
or execute them via a keyboard shortcut. The following
example explains the implementation in detail.
<editor:StudioPlugin xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns="exml:ext.config" xmlns:editor="exml:com.coremedia.cms.editor.sdk.config" xmlns:ui="exml:com.coremedia.ui.config"> <fx:Script><![CDATA[ public static const MY_GLOBAL_ACTION_ID:String = "myGlobalAction"; //... ]]></fx:Script> <editor:rules> <editor:EditorMainView> <editor:plugins> <ui:AddArrayItemsPlugin arrayProperty="actionList"> <ui:items> <local:MyGlobalAction actionId="{MY_GLOBAL_ACTION_ID}"/> </ui:items> </ui:AddArrayItemsPlugin> </editor:plugins> </editor:EditorMainView> ... </editor:rules> </editor:StudioPlugin>
The example shows how MyGlobalAction
is added to the action list of
EditorMainView
(which is the root component of
Studio), using a locally defined constant as its
actionId
. The action is now available for all child components of
Studio, except dialogs which render their own component hierarchy.
Every button that wants to execute this action can now use an ActionRef
with the same actionId
:
<editor:StudioPlugin xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns="exml:ext.config" xmlns:editor="exml:com.coremedia.cms.editor.sdk.config" xmlns:ui="exml:com.coremedia.ui.config"> <fx:Script><![CDATA[ public static const MY_GLOBAL_ACTION_ID:String = "myGlobalAction"; public static const MY_BUTTON_ITEM_ID:String = "myButton"; //... ]]></fx:Script> <editor:rules> <editor:EditorMainView> <editor:plugins> ... <ui:NestedRulesPlugin> <ui:rules> <editor:ActionsToolbar> <editor:plugins> <ui:AddItemsPlugin> <ui:items> <ui:IconButton itemId="{MY_BUTTON_ITEM_ID}"> <ui:baseAction> <ActionRef actionId="{MY_GLOBAL_ACTION_ID}"/> </ui:baseAction> </ui:IconButton> </ui:items> </ui:AddItemsPlugin> </editor:plugins> </editor:ActionsToolbar> </ui:rules> </ui:NestedRulesPlugin> </editor:plugins> </editor:EditorMainView> ... </editor:rules> </editor:StudioPlugin>
Continuing for the previous code, the example above shows how
MyGlobalAction
is plugged into the ActionsToolbar
of Studio. When the button is rendered, the
ActionRef
will look up the action with the corresponding
actionId
in the component hierarchy and replace itself with the actual
action. To ensure that your new action is registered before this look up happens, you have to
use NestedRulesPlugin
as shown in the example code.
For any action with an actionId
, a keyboard shortcut can be defined, which is
described in the next section.