예제 #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
        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");
        }
예제 #3
0
 public void Setup(ContextFile CurrentFile, ContextSetting Settings, RichTextBox Target)
 {
     CFile       = CurrentFile;
     CSettings   = Settings;
     TextSource  = Target;
     Ready       = true;
     PrinterSets = new PrinterSettings();
 }
예제 #4
0
 /// <summary>
 /// save the file specified by the RTF window contents to the Context
 /// </summary>
 /// <param name="Contents">the RTF window to read text from</param>
 /// <param name="context">contains where to save</param>
 public void Save(System.Windows.Forms.RichTextBox Contents, ContextFile context)
 {
     using (var WriteTo = File.OpenWrite(context.CurrentFile))
     {
         var bytes = GetBytesForSave(Contents);
         WriteTo.Write(bytes, 0, bytes.Length);
     }
 }
예제 #5
0
 public void Save(System.Windows.Forms.RichTextBox Contents, ContextFile context)
 {
     using (var FileOut = File.OpenWrite(context.CurrentFile))
     {
         NoteDocument prep = new NoteDocument();
         prep.EncodingData = StringEncodingData.PLAINTEXT | StringEncodingData.UNICODE_STRING;
         prep.CoreString   = Contents.Text;
         prep.SaveToStream(FileOut);
     }
 }
예제 #6
0
 public void Save(System.Windows.Forms.RichTextBox Contents, ContextFile context)
 {
     using (var Target = ZipFile.Open(context.CurrentFile, ZipArchiveMode.Update))
     {
         ZipArchiveEntry SubTarget = Target.CreateEntry("text\\document\\" + NameFromDoc(context.CurrentFile));
         {
             var data = Encoding.UTF8.GetBytes(Contents.Text);
             using (var SubStream = SubTarget.Open())
             {
                 SubStream.Write(data, 0, data.Length);
             }
         }
     }
 }
예제 #7
0
 /// <summary>
 /// load the specified file into the RTF window
 /// </summary>
 /// <param name="Contents">load the file into this</param>
 /// <param name="context">the context to load from</param>
 public void Load(System.Windows.Forms.RichTextBox Contents, ContextFile context)
 {
     using (var ReadFrom = File.OpenRead(context.CurrentFile))
     {
         var load = GetStringFromFile(ReadFrom);
         if (this.RTF)
         {
             Contents.Rtf = load;
         }
         else
         {
             Contents.Text = load;
         }
     }
 }
예제 #8
0
        public void Load(RichTextBox Contents, ContextFile context)
        {
            bool stringIsUnicode = false;
            bool rtf             = false;

            using (var input = File.OpenRead(context.CurrentFile))
            {
                NoteDocument Data = new NoteDocument(input);

                if (Data.EncodingData.HasFlag(StringEncodingData.ANSI_STRING) ||
                    (Data.EncodingData.HasFlag(StringEncodingData.UNICODE_STRING) == false))
                {
                    stringIsUnicode = false;
                }
                else
                {
                    stringIsUnicode = true;
                }

                if (Data.EncodingData.HasFlag(StringEncodingData.PLAINTEXT) ||
                    (Data.EncodingData.HasFlag(StringEncodingData.RICHTEXT) == false))
                {
                    rtf = false;
                }
                else
                {
                    rtf = true;
                }

                if (rtf)
                {
                    Contents.Rtf = Data.CoreString;
                }
                else
                {
                    Contents.Text = Data.CoreString;
                }
            }
        }
예제 #9
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);
        }
예제 #10
0
 public void Load(System.Windows.Forms.RichTextBox Contents, ContextFile context)
 {
 }