コード例 #1
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");
        }
コード例 #2
0
 private void MainWindowRichText_TextChanged(object sender, EventArgs e)
 {
     if (CurrentFile.HasChanged == false)
     {
         CurrentFile.HasChanged = true;
         CurrentFile.UpdateContextTitle(this);
     }
 }
コード例 #3
0
        private void NewToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (CurrentFile.HasChanged)
            {
                switch (MessageBox.Show(Path.GetFileName(CurrentFile.CurrentFile) + " has changed. Save Changes?", "Save Changes?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question))
                {
                case DialogResult.Cancel:
                {
                    return;
                }

                case DialogResult.Yes:
                {
                    if (CurrentFile.FileExists)
                    {
                        FileHandling.FileSave(FileHandling.GetHandlerClassInstance(CurrentFile.Format), CurrentFile.CurrentFile);
                    }
                    else
                    {
                        using (var SaveDialog = FileHandling.GetOpenDialogForHandler(CurrentFile.Format))
                        {
                        }
                    }
                }
                break;

                case DialogResult.No:
                    break;

                default: throw new Exception("Someone forgot to add code for different DialogResult in File->New");
                }
            }

            CurrentFile = new ContextFile();
            CurrentFile.UpdateContextTitle(this);
        }