Table of Contents

Class MenuWithHandler

Namespace
CADability.UserInterface
Assembly
CADability.dll

A simple structure describing a menu or an menu item (without the use of Windows.Forms). If ID is null, this is a main menu, if SubMenus is null, it is a simple menu item. If SubMenus is not null, this structure contains a list of sub-menus. This structure must be converted to a platform dependent menu and displayed accordingly. The selection of the menu item is handled by Target, but it can also be handled directly by setting OnCommand ( and OnUpdateCommand and OnSelected).

public class MenuWithHandler : ICommandHandler
Inheritance
MenuWithHandler
Implements
Inherited Members

Constructors

MenuWithHandler()

Creates an empty menu item without id, text and image. Set ID, Text and Target (or the OnXxx handlers) before use.

public MenuWithHandler()

MenuWithHandler(string, string)

creates a new menu item with the provided menuId. If resourceId is null, the menuId is used as the resourceId. The resourceId specifies the menu text from the string table.

public MenuWithHandler(string menuId, string resourceId = null)

Parameters

menuId string

menu id which is passed on to the OnCommand(string) call

resourceId string

the id of the menu text from the string table

Properties

ID

The id of the menu item, e.g. "MenuId.Edit.Cut". It is passed to OnCommand(string) when the item is clicked. Null for a main menu, "SEPARATOR" for a separator.

public string ID { get; set; }

Property Value

string

ImageIndex

Index of the item's image in the application's button image list, or -1 (the default) for no image. Loaded from the "IconNr" attribute of the menu resource.

public int ImageIndex { get; set; }

Property Value

int

MdiList

True when the menu resource marks the item with MdiList="true" (a Windows.Forms concept for listing the open MDI windows). Not used by CADability.

public bool MdiList { get; }

Property Value

bool

NotSticky

True when the menu resource marks the item with the flag "NotSticky", meant for toolbar buttons that must not stay pressed. CADability itself does not evaluate it.

public bool NotSticky { get; set; }

Property Value

bool

OnCommand

Sets a handler that processes the command when this menu item is clicked. It receives the menu id and returns true if it handled the command. Setting it makes this item its own Target; a handler set here takes precedence over the target. Write-only.

public Func<string, bool> OnCommand { set; }

Property Value

Func<string, bool>

OnSelected

Sets a handler that is notified when this menu item is highlighted (second argument true) or loses the highlight (false), e.g. to show a preview in the view. Setting it makes this item its own Target. Write-only.

public Action<MenuWithHandler, bool> OnSelected { set; }

Property Value

Action<MenuWithHandler, bool>

OnUpdateCommand

Sets a handler that updates the CommandState (enabled, checked) of this menu item before it is shown. It receives the menu id and the state to modify and returns true if it handled the request. Setting it makes this item its own Target. Write-only.

public Func<string, CommandState, bool> OnUpdateCommand { set; }

Property Value

Func<string, CommandState, bool>

Position

The "Position" attribute of the item in the menu resource, meant for ordering when menus are merged; 0 if not given. CADability itself does not evaluate it.

public int Position { get; set; }

Property Value

int

Separator

A new menu item that represents a separator line (id "SEPARATOR", text "-"). Each access returns a new instance.

public static MenuWithHandler Separator { get; }

Property Value

MenuWithHandler

Shortcut

The keyboard shortcut of the item as given by the "Shortcut" attribute of the menu resource, as the name of a value of the Shortcut enumeration (e.g. "CtrlC"), or null. The platform specific menu converts it to a key combination.

public string Shortcut { get; }

Property Value

string

ShowShortcut

True when the shortcut is to be displayed next to the menu text; set together with Shortcut.

public bool ShowShortcut { get; }

Property Value

bool

SubMenus

The items of the sub-menu that opens from this item, or null when the item is a simple command.

public MenuWithHandler[] SubMenus { get; set; }

Property Value

MenuWithHandler[]

Target

The ICommandHandler that receives the click on this item (OnCommand(string)), the request for its state (OnUpdateCommand(string, CommandState)) and the highlight notification (OnSelected(MenuWithHandler, bool)). Menus loaded with LoadMenuDefinition(string, bool, ICommandHandler) get the handler passed there.

public ICommandHandler Target { get; set; }

Property Value

ICommandHandler

Text

The text displayed for the item, usually looked up in the StringTable by the id. "-" for a separator.

public string Text { get; set; }

Property Value

string