When defining context menus, it is not possible to define a context entry specifically for one class or relation but only for abstract tool "types. The AdoScript code to add a context entry and support context definitions are listed below:
1CC "Application" INSERT_CONTEXT_MENU_ITEM context:Context item:strValue [ pos:strValue ]
where context can be one of the following:
"drawingarea.general" -- General drawing area context menu.
"drawingarea.swimlane" -- Drawing area context menu for swimlanes.
"drawingarea.mobject" -- Drawing area context menu for modeling objects.
"drawingarea.connector" -- Drawing area context menu for connectors.
"modelingtable" -- "Tabular modeling" browser context menu.
"explorer.db" -- Explorer context menu in "models in database" mode.
"explorer.windows" -- Explorer context menu in "opened model windows" mode.
"startpage.thumb" -- Start page context menu for a model thumbnail.
The menu name is specified with item. If the item shall be placed in a submenu, the parts of the item path are separated by TAB ("\t") characters, e.g. "New\tModelgroup...". A separator can be inserted by using "-" as item name.
To accomplish the behaviour to distinguish between types, you can implement a mechanim retrieve all selected elements, iterate through them and distinguish between specific classes.
An example for such an implementation is shown in the code fragement below, applicable for the "drawingarea.mobject" context.
A. Add the context in "External coupling" library attribute1ON_EVENT "AppInitialized" {
2 # ...
3 CC "Application" INSERT_CONTEXT_MENU_ITEM context:"drawingarea.mobject" item:"Context on object"
4 CC "Application" raw SET_CMI_SELECT_HDL context:"drawingarea.mobject" item:"Context on object" {
5 EXECUTE file: ("db:\\objectcontext.asc")
6 }
7 # ...
8}
B. Code in "objectcontext.asc" 1# 1. Get all objects selected when triggering the context action
2CC "Modeling" GET_SELECTED
3SET lSelectedObjects: (objids)
4# 2. Retrieve class information, and perform action for each class type
5FOR sObjectID in: (lSelectedObjects) {
6 CC "Core" GET_CLASS_ID objid: ( VAL sObjectID)
7 SET bIsRelation: (isrel)
8 SET nClassID: (classid)
9 IF (bIsRelation) {
10 # no action performed, as the context is only for classes
11 }
12 ELSE {
13 # get class name
14 CC "Core" GET_CLASS_NAME classid: (nClassID)
15 SET sClassName: (classname)
16 IF (sClassName = "Car") {
17 CC "AdoScript" INFOBOX ("Found a car with ID: " + sObjectID + "\n\nPerform a specific car action now!")
18 }
19 ELSIF (sClassName = "Truck") {
20 CC "AdoScript" INFOBOX ("Found a truck with ID: " + sObjectID + "\n\nPerform a specific truck action now!")
21 }
22 ELSE {
23 #catch all case
24 CC "AdoScript" INFOBOX ("No action found for class: " + sClassName + "!\n\nSeems the developer has not though about that case")
25 }
26 }
27}
A similar approach can be used for relationclasses. An example implementation can be found in the attached library and AdoScript files.