General XMetaL Discussion

XMetaL Community Forum General XMetaL Discussion 2 level entries for right click menu

  • wongsk27

    2 level entries for right click menu

    Participants 2
    Replies 3
    Last Activity 13 years, 4 months ago

    Hi all,

            Is it any way to create 2 level entries for right click menu? at the moment, I can only create 1 level entry for right click menu by using Application.AppendMacro API, however, I cannot think of any way to create 2 level entries.

    -Brian

    Reply

    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);
    }
    ]]>
    [/code]

    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).

    Reply

    mag3737

    Reply to: 2 level entries for right click menu

    (Just a little extra information.) Derek's sample code shows one example of the “manual” way to build up menus (and toolbars) using script in XMetaL. For multi-level menus, it is necessary to follow a procedure like this. The “AppendMacro” is essentially a shortcut for some of this code, but as discovered by Brian it is limited to adding single menu items.

    Reply

    wongsk27

    Reply to: 2 level entries for right click menu

    Hi All,

            Thanks for your information, Derek. I followed your example and have successfully created a new appendMacros function which allow me to create multi-levels “right click menu”. It is a lot better than the original AppendMacro function. Now i can rearrange my right click menu which a better a way.

    Regards,

    -Brian

    Reply

  • You must be logged in to reply to this topic.

Lost Your Password?

Products
Downloads
Support