Diagram / Commanding / Commanding Overview
In This Topic

    Commanding Overview

    In This Topic

    As part of the NOV platform, Nevron Diagram is subject to commanding and you can easily build powerful commanding user interfaces around a drawing view. NOV Diagram provides predefined builders for the following command UIs:

    All diagram commands are defined as static readonly fields in the NDrawingView class and you can freely reuse them whenever necessary to create your own commanding UI. All icons used by the predefined diagram ribbon, command bars and context menu builders are also publicly available. They are exposed by the Nevron.Nov.Diagram.NResources static class.

     Custom Command Actions

    If you want to provide additional functionality to your users, you should create your own custom commands and command actions, which inherit from the NDrawingCommandAction class. The following example demonstrates how to create a custom command action that shows a message box when executed. This command action is used in the rest of the topics in this chapter for a custom command added to the commanding UI of the drawing.

    Start by defining a custom command, which you will later use in custom builders. For example, add the following line to a custom type "MyCustomType" in your project:

    Define a custom command
    Copy Code
    public static readonly NCommand CustomCommand = NCommand.Create(typeof(MyCustomType), "CustomCommand", "Custom Command");
    

    After defining a custom command, create a custom command action for it:

    Create a custom command action
    Copy Code
    public class CustomCommandAction : NDrawingCommandAction
    {
        public CustomCommandAction()
        {
        }
    
        static CustomCommandAction()
        {
            CustomCommandActionSchema = NSchema.Create(typeof(CustomCommandAction), NDrawingCommandActionSchema);
        }
    
        public override NCommand GetCommand()
        {
            return MyCustomType.CustomCommand;
        }
    
        public override void Execute(NNode target, object parameter)
        {
            NDrawingView drawingView = GetDrawingView(target);
            NMessageBox.Show("Drawing Custom Command executed!", "Custom Command", ENMessageBoxButtons.OK, ENMessageBoxIcon.Information);
        }
    
        public static readonly NSchema CustomCommandActionSchema;
    }
    

    Finally add the custom command action to the Commander of the drawing view:

    Add a custom command action
    Copy Code
    drawingView.Commander.Add(new CustomCommandAction());
    

    For more information about commanding and command builders, check out the topics in the "See Also" section below.

     Removing Command Actions

    If you want to disable a specific command, you can remove the command action associated with it from the commander. To do that call the Remove method of the commander passing either the command or the command action you want to remove. The following 2 lines of code are equivalent and both remove the "Open" command action, but removing a command action via its command is shorter to write, so we recommend using it.

    Removing command actions via their command
    Copy Code
    drawingView.Commander.Remove(NDrawingView.OpenCommand));
    
    Removing command actions directly
    Copy Code
    drawingView.Commander.Remove(drawingView.Commander.GetCommandAction(NDrawingView.OpenCommand));
    
    See Also