Skip to content

Menu Integration

Return menu items in GetInfo.menus. The host builds the menus once, when the plugin loads.

Menus =
[
    new MenuItem
    {
        Id = "my-search",
        Label = "&Search...",
        Location = "plugin",
        RequiresOpenProject = true,
    },
]

Both hosts add a top-level menu to the main menu bar, placed after Help and captioned with GetInfo.name. Items with Location = "plugin" go there. Before a plugin loads, HydroSym shows this menu bar entry as a hidden placeholder named "Plugin"; you never see that caption once your plugin is loaded.

Field Behaviour
id Must be unique. Passed back in OnMenuAction and GetMenuItemState.
type action (default) or separator. A separator has no id registration; its other fields are ignored.
label Caption. & marks the accelerator key; write && for a literal ampersand.
location plugin, file, or tools (case-insensitive). See below.
requiresOpenProject Initial enabled state, and the fallback when GetMenuItemState returns no entry for this id.

Location values

Location Where the item appears
plugin Under the top-level menu named after your plugin
file In the File menu
tools In the Tools menu

HydroSym treats an empty Location as plugin. HydroMan skips items with an empty Location. Both hosts skip items with any other value (including toolbar and context:iborder, which appear in the schema but are not implemented). A skipped item is never created and never appears in GetMenuItemState.

OnMenuAction returns void. Call Host API methods from the handler. If the handler throws, the host shows the error in a dialog: HydroSym as a plain message box, HydroMan as an error dialog. The text is Plugin error: [OnMenuAction] <your message>.

GetMenuItemState

The host asks for the state of all registered items and applies enabled, checked, and label (label only when non-empty). Items missing from states fall back to requiresOpenProject. If your override returns null or throws, every item falls back the same way, and the error is logged without a dialog.

Enabled is a plain bool that defaults to false, so set it explicitly for every item you return.

public override GetMenuItemStateResponse GetMenuItemState(GetMenuItemStateRequest request)
{
    bool hasProject = request.Context.ProjectPath != null;

    return new GetMenuItemStateResponse
    {
        States = new Dictionary<string, MenuItemState>
        {
            ["my-search"] = new() { Enabled = hasProject },
        }
    };
}

Hosts populate ProjectPath only (the active schematic or manifold; null when none is open). The other PluginContext fields (ProjectId, selection IDs) are never sent and deserialize as null.

The host calls GetMenuItemState:

  • once when the menus are built at load time,
  • after a project is opened or closed,
  • whenever a main menu bar menu is about to show (HydroMan: any menu on the main window, and when the plugin menu is clicked),
  • after each OnMenuAction.

Settings

Set HasSettings = true in GetInfo. The host appends a separator and a Settings... item to your plugin menu and calls ShowSettings when it is clicked. Do not declare this item in Menus.

The Settings item is added only if the plugin menu exists, so declare at least one Location = "plugin" item.

Return RestartRequired = true to have the host show a message asking the user to restart. The host does not restart itself or prompt for it.

ParentWindowHandle is an int HWND. NativeWindowWrapper is not in the SDK; copy it if you parent a WinForms dialog:

internal sealed class NativeWindowWrapper(IntPtr handle) : IWin32Window
{
    public IntPtr Handle { get; } = handle;
}

public override ShowSettingsResponse? ShowSettings(ShowSettingsRequest request)
{
    var owner = new NativeWindowWrapper((IntPtr)request.ParentWindowHandle);
    using var dialog = new MySettingsForm(request.ConfigPath);
    dialog.ShowDialog(owner);
    return dialog.RestartRequired
        ? new ShowSettingsResponse { RestartRequired = true }
        : null;
}

Add <UseWindowsForms>true</UseWindowsForms> to the .csproj.

API schema: ShowSettings (HydroSym) ยท ShowSettings (HydroMan).