Diagram / Commanding / File Dialogs Customization
In This Topic

    File Dialogs Customization

    In This Topic

    NOV Diagram makes it easy to customize the way files are opened and saved. The following sections give instructions and code examples how to do that.

     Customize the File Formats in the Drawing File Dialogs

    To customize the file formats in the drawing file dialogs, you should:

    1. Create custom classes that inherit from NOpenCommandAction and NSaveAsCommandAction and override the GetFormats method to return only the drawing file formats you want to show in the "Open" and "Save As" file dialogs.

    For example, the following custom commands will show only the Visio Drawing (VSDX) and AutoCAD Drawing Interchange (DXF) file formats:

    Custom Diagram "Open" command action
    Copy Code
    private class CustomOpenCommandAction : NOpenCommandAction
    {
        public CustomOpenCommandAction()
        {
        }
        static CustomOpenCommandAction()
        {
            CustomOpenCommandActionSchema = NSchema.Create(typeof(CustomOpenCommandAction), NOpenCommandActionSchema);
        }
    
        protected override NDrawingFormat[] GetFormats()
        {
            return new NDrawingFormat[]
            {
                NDrawingFormat.Visio,
                NDrawingFormat.VectorAutoCadDxf
            };
        }
    
        public static readonly NSchema CustomOpenCommandActionSchema;
    }
    

     

    Custom Diagram "Save As" command action
    Copy Code
    public class CustomSaveAsCommandAction : NSaveAsCommandAction
    {
        public CustomSaveAsCommandAction()
        {
        }
        static CustomSaveAsCommandAction()
        {
            CustomSaveAsCommandActionSchema = NSchema.Create(typeof(CustomSaveAsCommandAction), NSaveAsCommandActionSchema);
        }
    
        protected override NDrawingFormat[] GetFormats()
        {
            return new NDrawingFormat[]
            {
                NDrawingFormat.Visio,
                NDrawingFormat.VectorAutoCadDxf
            };
        }
    
        public static readonly NSchema CustomSaveAsCommandActionSchema;
    }
    

    2. Replace the Old "Open" and "Save As" Command Actions

    Use the following code to replace the old "Open" and "Save As" command actions of the drawing view with the new custom ones:

    Replacing the "Open" and "Save As" command actions
    Copy Code
    drawingView.Commander.ReplaceCommandAction(new CustomOpenCommandAction());
    drawingView.Commander.ReplaceCommandAction(new CustomSaveAsCommandAction());
    
     Customize the Library Browser's Save Commands

    To customize the library browser's "Save" and "Save As" command actions, you should:

    1. Create a class that inherits NLibrarySaveCommandAction:

    Custom Library Save command action
    Copy Code
    public class CustomSaveLibraryCommandAction : NSaveLibraryCommandAction
    {
          public CustomSaveLibraryCommandAction(bool saveAs)
                 : base(saveAs)
          {
          }
    
          static CustomSaveLibraryCommandAction()
          {
                 CustomSaveLibraryCommandActionSchema = NSchema.Create(typeof(CustomSaveLibraryCommandAction), NSaveLibraryCommandActionSchema);
          }
    
          public override NPromise<bool> SaveAsync(NLibraryView libraryView)
          {
                 if (SaveAs)
                 {
                       NMessageBox.ShowInformation(libraryView.DisplayWindow, "Library save as called.", "Save as");
                 }
                 else
                 {
                       NMessageBox.ShowInformation(libraryView.DisplayWindow, "Library save called.", "Save");
                 }
    
                 return NPromise<bool>.CreateFulfilled(true);
          }
    
          public static readonly NSchema CustomSaveLibraryCommandActionSchema;
    }
    

    2. Replace the old "Save" and "Save As" command actions with the new one:

    Replacing the "Save" and "Save As" library command actions
    Copy Code
    libraryBrowser.Commander.ReplaceCommandAction(new CustomSaveLibraryCommandAction(false));
    libraryBrowser.Commander.ReplaceCommandAction(new CustomSaveLibraryCommandAction(true));