Home Forums General XMetaL Discussion 2 level entries for right click menu Reply To: 2 level entries for right click menu

Derek Read

Reply to: 2 level entries for right click menu

You will need to use one of the following events:
On_Context_Menu (document level event you would place in your dtdname.mcr file)
On_Application_Document_Context_Menu (application level event to modify the context menu for all document types)

There is currently no way to modify the Context Menu displayed when no documents are open as the events above only fire when you right click in an open document (or Shift+F10 or on a Windows-savvy keyboard the Context Menu key).

You use the Application.ActiveContextMenu object to modify what the Context Menu contains (for details on each object, property and method refer to the XMetaL Developer Programmer's Guide). These properties and methods are essentially the same as those used with the CommandBars object (used for manipulating menus and toolbars).

The following example demonstrates the basics of extending the Context Menu.

[code]if ((ActiveDocument.ViewType == sqViewNormal)||(ActiveDocument.ViewType == sqViewTagsOn)) {
//Extend standard context menu to add an item.
//Adding items to the 'newMenu' object makes 'newMenu' into a container.
        //Doing so means the OnAction property no longer takes effect so that property is not set here.
var newMenu        = Application.ActiveContextMenu.Controls.Add(variantType=5);
newMenu.Caption    = “Top Level Menu Item”;
newMenu.BeginGroup = false; //set to true to add separator between this and rest of menu.
newMenu.FaceId     = 0; //FaceId has no effect when assigned to this type of item. //Add two items to the object called “newMenu” that we created above.
var newOption      = newMenu.Controls.Add(variantType=5);
newOption.Caption  = “Menu Item 1”;
newOption.OnAction = “Your Macro Name 1”;
newOption.BeginGroup = false; //default
newOption.FaceId     = Application.MakeFaceId(“Structure (Custom)”,4,1); var newOption      = newMenu.Controls.Add(variantType=5);
newOption.Caption  = “Menu Item 2”;
newOption.OnAction = “Your Macro Name 2”;
newOption.BeginGroup = false; //default
newOption.FaceId     = Application.MakeFaceId(“Structure (Custom)”,4,2);

The previous example adds a new menu item containing two items whenever the context menu is displayed in TagsOn or Normal view. You could remove the if statement or alter it to meet any other requirement(s) you might have. For example, you may wish to add certain items when Selection.ContainerName="p" but other items when the user is not in that type of element, or you may wish to actually add items when the user is in PlainText view, provided you have a script that runs there (perhaps some basic text manipulation or something).