Nevron Open Vision Documentation
Rich Text Editor / Commanding / Ribbon / Text Ribbon via Code
In This Topic
    Text Ribbon via Code
    In This Topic

    If you are building a cross-platform NOV application, you can't use the Visual Studio designer, so you should customize the ribbon via code.

    NOV Text Editor provides two ways to create a rich text view with ribbon commanding UI.

     Rich Text View with Ribbon Widget

    The easiest way to create a ribbon commanding UI for a drawing view is to use the NRichTextViewWithRibbon widget or drop the NRichTextViewWithRibbonControl to a form/window using the Visual Studio Designer. You can then use the following approaches to modify the ribbon:

    1. Hiding Ribbon Tab Pages and Ribbon Groups

    To hide an element from the ribbon use the corresponding Get... method of the NRichTextViewWithRibbon or the NRichTextViewWithRibbonControl class and set its Visibility property to Collapsed:

    • GetApplicationMenu - gets the ribbon application menu.
    • GetRibbonTabPage - gets the ribbon tab page with a given title.
    • GetRibbonGroup - gets the ribbon group with a given groupTitle in the tab page with a specified pageTitle.
    • GetRibbonSearchBox - gets the ribbon search box.
    • GetRibbonQuickAccessToolbar - gets the ribbon quick access toolbar.
    • GetStatusBar - gets the status bar.

    The following code snippet hides the "Mailings" ribbon tab page and the "Zoom" ribbon group of the "View" ribbon tab page:

    Hide ribbon tab pages and ribbon groups
    Copy Code
    // Hide the "Mailings" ribbon tab page
    nRichTextViewWithRibbonControl1.GetRibbonTabPage(NRichTextRibbonBuilder.TabPageMailingsName)
        .Header.Visibility = ENVisibility.Collapsed;
    
    // Hide the "Zoom" ribbon group of the "View" ribbon tab page
    nRichTextViewWithRibbonControl1.GetRibbonGroup(NRichTextRibbonBuilder.TabPageViewName, NViewTabPageBuilder.GroupZoomName)
        .Visibility = ENVisibility.Collapsed;
    
    Note that instead of using string literals like "View", it is better to use the string constants defined in the NRichTextRibbonBuilder class to get ribbon tab page names as shown in the code snippet above. You should use the constants in the corresponding tab page builder to get ribbon group names, for example, NViewTabPageBuilder.GroupZoomName.

    2. Removing Commands

    To remove all widgets associated with specific commands from the commanding UI, use the RemoveCommands method of the rich text view with ribbon:

    Remove commands
    Copy Code
    // Create an array of commands to remove
    NCommand[] commandsToRemove = new NCommand[] {
        NRichTextView.OpenCommand,
        NRichTextView.OpenUrlCommand,
        NRichTextView.SaveAsCommand,
        NRichTextView.SaveCommand
    };
    
    NRichTextViewWithRibbon richTextWithRibbon = new NRichTextViewWithRibbon();
    richTextWithRibbon.RemoveCommands(commandsToRemove);
    
     Rich Text Ribbon Builder

    You can also create NOV Diagram ribbon commanding UI using the NOV Diagram ribbon builder. This gives you greater flexibility and more ways to customize the NOV Diagram ribbon:

    Creating NOV Rich Text ribbon UI
    Copy Code
    NRichTextRibbonBuilder ribbonBuilder = new NRichTextRibbonBuilder();
    NWidget richTextViewWithRibbon = ribbonBuilder.CreateUI(richTextView);
    

    1. Modifying Ribbon Group Builders Collection

    If you want to remove a given ribbon tab page, you can easily do so by using the Remove method of the TabPageBuilders collection of the rich text ribbon builder. To remove a ribbon group from a tab page, you should use the Remove method of the RibbonGroupBuilders collection of the ribbon group builder.

    The names of all rich text ribbon tab pages are exposed as constants in the NRichTextRibbonBuilder class. Each of the tab page builders exposes as constants the names of its ribbon group builders. The following piece of code demonstrates how to remove the "Clipboard" ribbon group of the "Home" tab page of the rich text ribbon:

    Remove ribbon group
    Copy Code
    NRibbonTabPageBuilder homeTabBuilder = ribbonBuilder.TabPageBuilders[NRichTextRibbonBuilder.TabPageHomeName];
    homeTabBuilder.RibbonGroupBuilders.Remove(NHomeTabPageBuilder.GroupClipboardName);
    

    In order to add or insert your own ribbon group builders, you can use the Add or Insert methods of the RibbonGroupBuilders collection respectively.

    Add custom ribbon group
    Copy Code
    NRibbonTabPageBuilder homeTabBuilder = ribbonBuilder.TabPageBuilders[NRichTextRibbonBuilder.TabPageHomeName];
    homeTabBuilder.RibbonGroupBuilders.Insert(0, new CustomRibbonGroupBuilder());
    

    2. Custom Ribbon Group Builders

    To create a custom ribbon group builder you should create a class, which inherits NRibbonGroupBuilder:

    Custom ribbon group builder
    Copy Code
    public class CustomRibbonGroupBuilder : NRibbonGroupBuilder
    {
        public CustomRibbonGroupBuilder()
            : base("Custom Group", NResources.Image_Ribbon_16x16_smiley_png)
        {
        }
    
        protected override void AddRibbonGroupItems(NRibbonGroupItemCollection items)
        {
            // Add the "Copy" command
            items.Add(CreateRibbonButton(NResources.Image_Ribbon_32x32_clipboard_copy_png,
                Nevron.Nov.Presentation.NResources.Image_Edit_Copy_png, NRichTextView.CopyCommand));
    
            // Add the custom command
            items.Add(CreateRibbonButton(NResources.Image_Ribbon_32x32_smiley_png, NResources.Image_Ribbon_16x16_smiley_png, CustomCommand));
        }
    }
    
    See Also