Object class-dependent context menuObject class-dependent context menuRE: Object class-dependent context menuWilfrid Utzhttps://www.adoxx.org/live/c/message_boards/find_message?p_l_id=&messageId=3726312015-09-23T13:03:52Z2015-09-23T13:01:00ZWhen 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:<br /><br /><div class="code"><span class="code-lines">1</span>CC "Application" INSERT_CONTEXT_MENU_ITEM context:Context item:strValue [ pos:strValue ]</div><br />where context can be one of the following:<br />"drawingarea.general" -- General drawing area context menu.<br />"drawingarea.swimlane" -- Drawing area context menu for swimlanes.<br />"drawingarea.mobject" -- Drawing area context menu for modeling objects.<br />"drawingarea.connector" -- Drawing area context menu for connectors.<br />"modelingtable" -- "Tabular modeling" browser context menu.<br />"explorer.db" -- Explorer context menu in "models in database" mode.<br />"explorer.windows" -- Explorer context menu in "opened model windows" mode.<br />"startpage.thumb" -- Start page context menu for a model thumbnail.<br /><br />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.<br /><br />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.<br /><br />An example for such an implementation is shown in the code fragement below, applicable for the "drawingarea.mobject" context.<br /><br /><strong>A. Add the context in "External coupling" library attribute</strong><div class="code"><span class="code-lines">1</span>ON_EVENT "AppInitialized" {<br /><span class="code-lines">2</span> # ...<br /><span class="code-lines">3</span> CC "Application" INSERT_CONTEXT_MENU_ITEM context:"drawingarea.mobject" item:"Context on object"<br /><span class="code-lines">4</span> CC "Application" raw SET_CMI_SELECT_HDL context:"drawingarea.mobject" item:"Context on object" {<br /><span class="code-lines">5</span> EXECUTE file: ("db:\\objectcontext.asc")<br /><span class="code-lines">6</span> }<br /><span class="code-lines">7</span> # ...<br /><span class="code-lines">8</span>}<br /></div><br /><strong>B. Code in "objectcontext.asc"</strong><br /><br /><div class="code"><span class="code-lines"> 1</span># 1. Get all objects selected when triggering the context action<br /><span class="code-lines"> 2</span>CC "Modeling" GET_SELECTED<br /><span class="code-lines"> 3</span>SET lSelectedObjects: (objids)<br /><span class="code-lines"> 4</span># 2. Retrieve class information, and perform action for each class type<br /><span class="code-lines"> 5</span>FOR sObjectID in: (lSelectedObjects) {<br /><span class="code-lines"> 6</span> CC "Core" GET_CLASS_ID objid: ( VAL sObjectID)<br /><span class="code-lines"> 7</span> SET bIsRelation: (isrel)<br /><span class="code-lines"> 8</span> SET nClassID: (classid)<br /><span class="code-lines"> 9</span> IF (bIsRelation) {<br /><span class="code-lines">10</span> # no action performed, as the context is only for classes<br /><span class="code-lines">11</span> }<br /><span class="code-lines">12</span> ELSE {<br /><span class="code-lines">13</span> # get class name<br /><span class="code-lines">14</span> CC "Core" GET_CLASS_NAME classid: (nClassID)<br /><span class="code-lines">15</span> SET sClassName: (classname)<br /><span class="code-lines">16</span> IF (sClassName = "Car") {<br /><span class="code-lines">17</span> CC "AdoScript" INFOBOX ("Found a car with ID: " + sObjectID + "\n\nPerform a specific car action now!")<br /><span class="code-lines">18</span> }<br /><span class="code-lines">19</span> ELSIF (sClassName = "Truck") {<br /><span class="code-lines">20</span> CC "AdoScript" INFOBOX ("Found a truck with ID: " + sObjectID + "\n\nPerform a specific truck action now!") <br /><span class="code-lines">21</span> }<br /><span class="code-lines">22</span> ELSE {<br /><span class="code-lines">23</span> #catch all case<br /><span class="code-lines">24</span> CC "AdoScript" INFOBOX ("No action found for class: " + sClassName + "!\n\nSeems the developer has not though about that case")<br /><span class="code-lines">25</span> }<br /><span class="code-lines">26</span> }<br /><span class="code-lines">27</span>}<br /></div><br />A similar approach can be used for relationclasses. An example implementation can be found in the attached library and AdoScript files.Wilfrid Utz2015-09-23T13:01:00ZObject class-dependent context menuVladimir Shekhovtsovhttps://www.adoxx.org/live/c/message_boards/find_message?p_l_id=&messageId=3726202015-09-23T12:45:59Z2015-09-23T12:45:59ZI am trying to implement the context menu that is going to be shown only for the objects of the particular class, but, according to the documentation, this seems to be not possible:<br />"You cannot constrain the new context menu to a specific class or relationship type. So it is wise to give the menu entry a general name and then adjust the functionality, <br />according to the selected object, within the body of the function. "<br /><br />I have tried to investigate if the workaround like the one used for model-type-specific menus could be used in this case, but, again, this seems to be not <br />possible as well because I was not able to find the event fired on activation of the particular object on a diagram.<br /><br />This is quite an unfortunate restriction for me as I have currently implemented a deployment configuration for my system as a diagram object and wanted to make a context menu for<br />the particular configuration run a script performing the actual deployment. Unfortunately, there are other objects on this diagram which must not support this context menu.<br /><br />Am I missing anything? Are there any workarounds for this "context menu" approach?Vladimir Shekhovtsov2015-09-23T12:45:59Z