Beispiel #1
0
        public void AddTab()
        {
            RichTextBoxPrintCtrl.RichTextBoxPrintCtrl body = new RichTextBoxPrintCtrl.RichTextBoxPrintCtrl();
            body.Name = "Body";
            body.Dock = DockStyle.Fill;
            body.ContextMenuStrip = contextMenuStrip1;
            body.AcceptsTab = true;
            body.SelectionChanged += body_SelectionChanged;

            TabPage t = new TabPage();
            tabCount += 1;

            String DocText = "Document " + tabCount;
            t.Name = DocText;
            t.Text = DocText;
            t.Controls.Add(body);

            documentTab.TabPages.Add(t);
            documentTab.SelectedIndex = documentTab.TabPages.Count - 1;
            console.Append(GetTime() + "Tab successfully added");
        }
 /// <summary>
 /// Opens a file without the use of a OpenFileDialog
 /// </summary>
 /// <param name="rtbIn"></param>
 /// <param name="filePath"></param>
 /// <returns></returns>
 public string silentOpen(RichTextBoxPrintCtrl.RichTextBoxPrintCtrl rtbIn, string filePath)
 {
     //getCurrentDocument.AppendText(File.ReadAllText(filePath));
     if (filePath.EndsWith(".rtf"))
     {
         rtbIn.LoadFile(filePath, RichTextBoxStreamType.RichText);
     }
     else
     {
         rtbIn.LoadFile(filePath, RichTextBoxStreamType.PlainText);
     }
     addFileToMap(filePath, filePath);
     console.Append(Asys.GetTime() + "Opening file (SilentOpen)");
     return filePath;
 }
        /// <summary>
        /// Saves the current document with a save dialog.
        /// Adds the current document to the Map.
        /// </summary>
        /// <param name="rtbIn"></param>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public string saveAs(RichTextBoxPrintCtrl.RichTextBoxPrintCtrl rtbIn, string fileName)
        {
            saveDialog.FileName = fileName;
            saveDialog.Title = "Save As";

            if (saveDialog.ShowDialog() == DialogResult.OK)
            {
                if (saveDialog.FileName.Length > 0)
                {
                    if (saveDialog.FileName.EndsWith(".rtf"))
                    {
                        rtbIn.SaveFile(saveDialog.FileName, RichTextBoxStreamType.RichText);
                    }
                    else
                    {
                        rtbIn.SaveFile(saveDialog.FileName, RichTextBoxStreamType.PlainText);
                    }
                    addFileToMap(fileName, saveDialog.FileName);
                    console.Append(Asys.GetTime() + "Save Complete");
                    return Path.GetFileName(saveDialog.FileName);
                }
                else { return ""; }
            }
            else { return ""; }
        }
 /// <summary>
 /// Saves the current file to the system if it exists in the Map.
 /// If not, passes params to SaveAs()
 /// </summary>
 /// <param name="rtbIn"></param>
 /// <param name="fileNameIn"></param>
 public string save(RichTextBoxPrintCtrl.RichTextBoxPrintCtrl rtbIn, string fileNameIn)
 {
     string fileName = "";
     if (getFileFromMap(fileNameIn) != "")
     {
         // The file already exists in the Map so save it
         console.Append(Asys.GetTime() + "Instance exists in Map, saving");
         fileName = getFileFromMap(fileNameIn);
         if (fileName.EndsWith(".rtf"))
         {
             rtbIn.SaveFile(fileName, RichTextBoxStreamType.RichText);
         }
         else
         {
             rtbIn.SaveFile(fileName, RichTextBoxStreamType.PlainText);
         }
         console.Append(Asys.GetTime() + "Save Complete (SilentSave)");
         return fileName;
     }
     else
     {
         // The file does not exist in the Map so
         // Send it to SaveAs with the rtb and the initial fileName passed in
         console.Append(Asys.GetTime() + "Instance does not exist in Map! calling saveAs()");
         return saveAs(rtbIn, fileNameIn);
     }
 }
        /// <summary>
        /// Open a file from the filesystem and adds it to the Map.
        /// </summary>
        /// <param name="rtbIn"></param>
        /// <returns>The filename returned by the OpenFileDialog</returns>
        public string open(RichTextBoxPrintCtrl.RichTextBoxPrintCtrl rtbIn)
        {
            if (openDialog.ShowDialog() == DialogResult.OK)
            {
                if (openDialog.FileName.Length > 0)
                {
                    string fileName = Path.GetFileName(openDialog.FileName);

                    if (fileName.EndsWith(".rtf"))
                    {
                        rtbIn.LoadFile(openDialog.FileName, RichTextBoxStreamType.RichText);
                    }
                    else
                    {
                        rtbIn.LoadFile(openDialog.FileName, RichTextBoxStreamType.PlainText);
                    }
                    addFileToMap(openDialog.FileName, openDialog.FileName);
                    console.Append(Asys.GetTime() + "Opening file");
                    return fileName;
                }
                else { return ""; }
            }
            else { return ""; }
        }