Beispiel #1
0
        public static void FileSave(IFormatHandler Handler, string filename)
        {
            if (TargetWindow == null)
            {
                throw new ArgumentNullException("Forgot to set TargetWindow befor call");
            }
            if (Handler != null)
            {
                var NewContext = new ContextFile();
                try
                {
                    NewContext.CurrentFile = filename;

                    Handler.Save(TargetWindow.mainWindowRichText, NewContext);
                }
                catch (IOException e)
                {
                    MessageBox.Show(e.Message, "Error saving file");
                    NewContext = null;
                }

                if (NewContext != null)
                {
                    TargetWindow.CurrentFile = NewContext;
                }
                return;
            }
            throw new ArgumentNullException("handler=null");
        }
Beispiel #2
0
        /// <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");
        }
Beispiel #3
0
        /// <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");
        }
 /// <summary>
 /// Adds a format handler to the dictionary.
 /// </summary>
 /// <param name="handler">The handler to add.</param>
 public void AddFormat(IFormatHandler handler)
 {
     formats.Add(handler.FileExtension, handler);
 }