Nevron Open Vision Documentation
Context Menu

NOV Text Editor lets you fully customize the context menu shown when the user right clicks somewhere in the rich text view. Rich text view's context menu is created by the rich text context menu builder assigned to the ContextMenuBuilder property of the rich text view's selection. This builder contains a list of context menu group builders, each of which is associated with a specific text element and builds the part of the context menu related to this element.

Modifying Group Builders List

You can easily add and remove context menu groups from the builder by using its AddGroup, InsertGroup and RemoveGroup methods. The names of the predefined groups are available as constants in the NRichTextMenuGroup. The following code fragment demonstrates how to remove a context menu group and add a custom one to the rich text context menu builder:

Add and remove group builders
Copy Code
// Get the context menu builder
NRichTextContextMenuBuilder builder = m_RichText.Selection.ContextMenuBuilder;

// Remove the common menu group, which contains commands such as Cut, Copy, Paste, etc.
builder.RemoveGroup(NRichTextMenuGroup.Common);

// Add the custom context menu group
builder.AddGroup(new CustomMenuGroup());
Custom Context Menu Groups

To create a custom context menu group, you should create a class, which inherits NRichTextMenuGroup. In your custom class you should first override the AppliesTo method in order to indicate to which text elements your custom menu group applies. Then you can override the AppendActionsTo and/or the AppendPropertiesTo method to append the actions/properties of the custom context menu group to the menu currently being constructed.

The following example demonstrates how to create a custom rich text context menu group:

Custom rich text context menu group
Copy Code
public class CustomMenuGroup : NRichTextMenuGroup
{
    public CustomMenuGroup()
        : base("Custom")
    {
    }

    public override bool AppliesTo(NTextElement textElement)
    {
        return true;
    }
    public override void AppendActionsTo(NMenu menu, NTextElement textElement)
    {
        // Add the "Copy" command
        menu.Items.Add(CreateMenuItem(Nevron.Nov.Presentation.NResources.Image_Edit_Copy_png, NRichTextView.CopyCommand));

       // Add the custom command
       menu.Items.Add(CreateMenuItem(NResources.Image_Ribbon_16x16_smiley_png, CustomCommand));
    }
}
See Also

UI

Send Feedback