Rich Text Editor / Commanding / File Dialogs Customization
File Dialogs Customization

NOV Text Editor makes it easy to customize the file formats shown its "Open", "Save As" and "Insert Image" dialogs. The sections below demonstrate how to create custom command actions that customize the file formats and how to replace the old command actions with the new ones. You should create custom command actions only for the dialogs whose file formats you want to change.

 1. Create Custom "Open", "Save As" and "Insert Image" Command Actions

Create custom classes that inherit from NOpenCommandAction, NSaveAsCommandAction and NInsertImageCommandAction and override the GetFormats method to return only the text/image file formats you want to show in the file dialogs.

For example, the following custom commands will show only the Microsoft Word (DOCX) and Rich Text (RTF) file formats:

Custom Rich Text "Open" command action
Copy Code
public class CustomOpenCommandAction : NOpenCommandAction
{
    public CustomOpenCommandAction()
    {
    }
    static CustomOpenCommandAction()
    {
        CustomOpenCommandActionSchema = NSchema.Create(typeof(CustomOpenCommandAction), NOpenCommandActionSchema);
    }

    protected override NTextFormat[] GetFormats()
    {
        return new NTextFormat[]
        {
            new NDocxTextFormat(),
            new NRtfTextFormat()
        };
    }

    public static readonly NSchema CustomOpenCommandActionSchema;
}

 

Custom Rich Text "Save As" command action
Copy Code
public class CustomSaveAsCommandAction : NSaveAsCommandAction
{
    public CustomSaveAsCommandAction()
    {
    }
    static CustomSaveAsCommandAction()
    {
        CustomSaveAsCommandActionSchema = NSchema.Create(typeof(CustomSaveAsCommandAction), NSaveAsCommandActionSchema);
    }

    protected override NTextFormat[] GetFormats()
    {
        return new NTextFormat[]
        {
            new NDocxTextFormat(),
            new NRtfTextFormat()
        };
    }

    public static readonly NSchema CustomSaveAsCommandActionSchema;
}

You can change the file formats shown in the Insert Image dialog in the same way - create a command action that inherits from NInsertImageCommandAction and override its GetFormats method:

Custom Rich Text "Insert Image" command action
Copy Code
private class CustomInsertImageCommandAction : NInsertImageCommandAction
{
    public CustomInsertImageCommandAction()
    {
    }
    static CustomInsertImageCommandAction()
    {
        CustomInsertImageCommandActionSchema = NSchema.Create(typeof(CustomInsertImageCommandAction), NInsertImageCommandActionSchema);
    }

    protected override NImageFormat[] GetFormats()
    {
        return new NImageFormat[]
        {
            NImageFormat.Jpeg,
            NImageFormat.Png
        };
    }

    public static readonly NSchema CustomInsertImageCommandActionSchema;
}
 2. Replace the Old "Open", "Save As" and "Insert Image" Command Actions

Use the following code to replace the old "Open", "Save As" and "Insert Image" command actions of the rich text view with the new custom ones:

Replacing the "Open", "Save As" and "Insert Image" command actions
Copy Code
richTextView.Commander.ReplaceCommandAction(new CustomOpenCommandAction());
richTextView.Commander.ReplaceCommandAction(new CustomSaveAsCommandAction());
richTextView.Commander.ReplaceCommandAction(new CustomInsertImageCommandAction());