ILibraryWindowContextMenuExtension Interface

This interface lets you create a plug-in that adds a shortcut (context) menu to the HotDocs library window. When users right-click an item in the library, your plug-in can add commands to the shortcut menu. Specifically, this interface lets you add your own submenu to the existing shortcut menu.

When HotDocs starts up, it attempts to load each registered plug-in. If it finds a plug-in that implements the ILibraryWindowContextMenuExtension interface, HotDocs calls ContextInitialize to load and initialize the plug-in. Then, whenever the user right-clicks a library item, HotDocs calls ContextGetMenuTitle, passing it information about which library entries are selected to determine which, if any, shortcut menus to display. After determining which menus to display, HotDocs calls ContextGetMenuEntry a number of times to retrieve the entries for the submenu. Finally, if the user selects an entry from your submenu, HotDocs calls ContextCommand and passes it the identifier for the command.

Function Description
ContextCommand This function is called when a user selects one of the entries in a custom shortcut menu.
ContextGetMenuEntry This function is called when a user right-clicks an item in the library to display a shortcut menu. HotDocs calls this function repeatedly to get the name of each entry in the custom submenu and stops when the function fails, or when menuText is an empty string ("").
ContextGetMenuTitle This function is called when a user right-clicks an item in the library to display a shortcut menu. HotDocs passes information about the selected library item(s), which can be used to determine which entries to include in the submenu, or how submenu commands should operate. The plug-in can then tell HotDocs the name of the submenu, where it should appear in the shortcut menu, and whether it should be preceded or followed by a separator bar. Finally, the plug-in can also enable or disable the submenu as needed.
ContextInitialize This function is called when HotDocs starts up to determine if it should load the plug-in. If the function fails, HotDocs will not load the plug-in.
ContextLibraryInitialized This function is called when the library is initialized.

Example (Visual C#)

The following Visual C# example implements the HotDocs.ILibraryWindowContextMenuExtension interface:

[ComVisible(true)]
[Guid("12345678-1111-2222-AAAA-DDDDDDDDDDDD")]
public class WindowMenuExt : HotDocs.ILibraryWindowContextMenuExtension
{
    static bool initialized = false;
     
    public void ContextCommand(int commandId)
    {
        if (commandId == cmd1)
            MessageBox.Show("Command 1 selected");
        if (commandId == cmd2)
            MessageBox.Show("Command 2 selected");
    }
     
    public void ContextGetMenuEntry(int menuPosition, ref string menuText, ref bool enabled, ref bool callAgain, int commandId)
    {
        switch (menuPosition)
        {
            case 0:
                menuText = "Command 1";
                cmd1 = commandId;
                enabled = true;
                break;
            case 1:
                menuText = "Command 2";
                cmd2 = commandId;
                enabled = true;
                break;
            default:
                break;
        }
    }
     
    public void ContextGetMenuTitle(string libraryPath, LibraryEntity caretEntry, ref string menuTitle, ref int menuPosition, ref bool enabled, ref bool separatorBefore, ref bool separatorAfter)
    {
        menuTitle = "My Submenu";
        menuPosition = -1;  //Adds the new menu t the bottom of the context menu
    }
     
    public void ContextInitialize()
    {
    }
     
    public void ContextLibraryInitialized()
    {
        if (!initialized)
        {
            //Add Code here
            initialized = true;
        }
    }
     
    [ComRegisterFunction]
    public static void RegisterPlugin(Type t)
    {
        HotDocs.Application app = new HotDocs.Application();
        app.Plugins.Register("{12345678-1111-2222-AAAA-DDDDDDDDDDDD}", "Context Menu", 100, 1);
        System.Runtime.InteropServices.Marshal.ReleaseComObject(app);
    }
     
    [ComUnregisterFunction]
    public static void UnRegisterPlugin(Type t)
    {
        HotDocs.Application app = new HotDocs.Application();
        app.Plugins.Unregister("{12345678-1111-2222-AAAA-DDDDDDDDDDDD}");
        System.Runtime.InteropServices.Marshal.ReleaseComObject(app);
    }
}