/// <summary> /// Load a file via the chosen handler without invoking the dialog to choose /// </summary> /// <param name="Handler">handler to user (format)</param> /// <param name="filename">target file</param> /// <param name="ContextId">Set the title bar to this format</param> public static void FileLoad(IFormatHandler Handler, string filename, SupportedFileHandleFormats ContextId) { if (TargetWindow == null) { throw new ArgumentNullException("Forgot to set TargetWindow befor call"); } if (Handler != null) { var NewContext = new ContextFile { CurrentFile = filename }; try { Handler.Load(TargetWindow.mainWindowRichText, NewContext); } catch (IOException e) { MessageBox.Show(e.Message, "Error loading file. Message is " + e.Message); NewContext = null; } if (NewContext != null) { TargetWindow.CurrentFile = NewContext; NewContext.Format = ContextId; TargetWindow.mainWindowRichText.Modified = false; NewContext.UpdateContextTitle(TargetWindow); } return; } throw new ArgumentNullException("handler=null"); }
/// <summary> /// The event that loads the file from a OpenDialog /// </summary> /// <param name="Handler"></param> /// <param name="sender"></param> /// <param name="e"></param> #pragma warning disable IDE0060 // Remove unused parameter private static void InternalFileOk_Read(IFormatHandler Handler, object sender, CancelEventArgs e) #pragma warning restore IDE0060 // Remove unused parameter { if (Handler != null) { if (TargetWindow.CurrentFile == null) { TargetWindow.CurrentFile = new ContextFile(); } if (string.IsNullOrEmpty(TargetWindow.CurrentFile.CurrentFile)) { TargetWindow.CurrentFile.CurrentFile = ((FileDialog)sender).FileName; } Handler.Load(TargetWindow.mainWindowRichText, TargetWindow.CurrentFile); TargetWindow.CurrentFile.UpdateContextTitle(TargetWindow); return; } throw new ArgumentNullException("handler=null"); }