Exemplo n.º 1
0
 //将文本内容存入文件,限定文件类型
 public void SaveFile(string filepath, RichTextBoxStreamType filetype)
 {
     if (filepath.Length > 0)
     {
         richTextBoxContent.SaveFile(filepath, filetype);
     }
 }
Exemplo n.º 2
0
        private void ArchivoAbrirDoc(FormDocumento FormHijo)
        {
            // Mostrar el diálogo Abrir
            OpenFileDialog DlgAbrir = new OpenFileDialog();

            DlgAbrir.Filter = "ficheros txt (*.txt)|*.txt|ficheros rtf (*.rtf)|*.rtf";
            if (DlgAbrir.ShowDialog() == DialogResult.OK)
            {
                // Obtener el nombre del fichero
                string ruta = DlgAbrir.FileName;
                // Obtener el formato del fichero
                RichTextBoxStreamType formato = RichTextBoxStreamType.PlainText;
                if (DlgAbrir.FilterIndex == 2)
                {
                    formato = RichTextBoxStreamType.RichText;
                }
                // Cargar el fichero
                FormHijo.rtbText.LoadFile(ruta, formato);
                // Mostrar el nombre del fichero en la barra de título
                FormHijo.Text = ruta.Substring(ruta.LastIndexOf("\\") + 1);
                // Mostrar la ruta del fichero en la barra de estado
                this.etbarestPpal.Text = ruta;
                // Aún no ha sido modificado
                FormHijo.rtbText.Modified = false;
            }
        }
Exemplo n.º 3
0
        private void textToEncRTB_DragDrop(object sender, DragEventArgs e)
        {
            string[] paths = e.Data.GetData(DataFormats.FileDrop) as string[];
            if (paths != null && !string.IsNullOrWhiteSpace(paths[0]))
            {
                RichTextBoxStreamType type = RichTextBoxStreamType.PlainText;
                if (paths[0].ToLower().EndsWith(".rtf"))
                {
                    type = RichTextBoxStreamType.RichText;
                }

                RichTextBox rtb = sender as RichTextBox;
                rtb.Clear();
                try
                {
                    rtb.LoadFile(paths[0], type);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, ex.Message, "Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                EncPerformBtnEnabler();
            }
        }
Exemplo n.º 4
0
 //装载文件-数据流
 public void loadFile(System.IO.Stream filename, RichTextBoxStreamType myfiletype)
 {
     if (filename.Length > 0)
     {
         richTextBoxContent.LoadFile(filename, myfiletype);
     }
 }
Exemplo n.º 5
0
        public void Clear()
        {
            DialogResult result;

            if (Changed)
            {
                result = MessageBox.Show("Save changed to " + filename + "?", "WordPad", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);

                if (result == DialogResult.Cancel)
                {
                    return;
                }

                if (result == DialogResult.Yes)
                {
                    Save(false);
                }
            }

            // FIXME - we need a dialog and ask for the document type
            filename = "Document";
            filetype = RichTextBoxStreamType.RichText;
            edit.Clear();
            Changed = false;
        }
Exemplo n.º 6
0
 //将文本内容存入文件,限定文件类型,存入到数据流
 public void SaveFile(System.IO.Stream filename, RichTextBoxStreamType filetype)
 {
     if (filename.Length > 0)
     {
         richTextBoxContent.SaveFile(filename, filetype);
     }
 }
Exemplo n.º 7
0
        private void 打开OCtrlOToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    RichTextBoxStreamType fileType = TrunFileType(openFileDialog.FilterIndex);
                    fileCount++;
                    file           = new FormChild(fileType, openFileDialog.FileName, openFileDialog.FilterIndex);
                    file.MdiParent = this;
                    file.Show();
                    listFormChild.Add(file);
                }
            }
            catch (Exception ex)
            {
                return;
            }

            string str = openFileDialog.FileName;

            string[] sArray = str.Split('\\');
            file.Text = sArray[sArray.Length - 1];

            file.WindowState = FormWindowState.Maximized;
        }
Exemplo n.º 8
0
        public bool OpenFile(string name, RichTextBoxStreamType type)
        {
            if (Changed)
            {
                DialogResult result;

                result = MessageBox.Show("Save changed to " + filename + "?", "WordPad", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);

                if (result == DialogResult.Cancel)
                {
                    return(false);
                }

                if (result == DialogResult.Yes)
                {
                    Save(false);
                }
            }

            filename = name;
            filetype = type;
            edit.LoadFile(filename, filetype);
            AddMRU(filename);
            Changed = false;
            return(true);
        }
Exemplo n.º 9
0
        public void SaveFile(FormChild df)                    //保存文件
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Filter = "文本文件(*.txt)|*.txt|RTF文件|*.rtf|所有文件(*.*)|*.*";

            if (sfd.ShowDialog() == DialogResult.OK)
            {
                RichTextBoxStreamType fileType = TrunFileType(sfd.FilterIndex);
                file.SetFileTypeIndex(sfd.FilterIndex);
                file.SetFilePath(saveFileDialog.InitialDirectory);
                df.Sourse.SaveFile(sfd.FileName, fileType);

                df.SetFilePath(sfd.FileName);
                oldFile = fileType;
            }
            string str = df.GetFilePath();

            string[] sArray = str.Split('\\');
            fileName = sArray[sArray.Length - 1];

            for (int i = 0; i < sArray.Length - 1; i++)
            {
                filePath += sArray[i];
            }
        }
Exemplo n.º 10
0
        //saving delegate method
        private void SaveToolStripMenuItem__Click(object sender, EventArgs e)
        {
            if (this.MdiParent.ActiveMdiChild != this)
            {
                return;
            }

            saveFileDialog.FileName = openFileDialog.FileName;
            //if opening existing file
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                //then a file was selected
                //we need to know the file that needs to be loaded
                //so we need the path
                RichTextBoxStreamType richTextBoxStreamType = RichTextBoxStreamType.RichText;
                if (saveFileDialog.FileName.ToLower().Contains(".txt"))
                {
                    //if its text than load plain text
                    richTextBoxStreamType = RichTextBoxStreamType.PlainText;
                }
                richTextBox.SaveFile(saveFileDialog.FileName, richTextBoxStreamType);

                this.Text = "MyEditor (" + saveFileDialog.FileName + ")";
            }
        }
Exemplo n.º 11
0
        public FormChild(RichTextBoxStreamType fileType, string filePath, int i)
        {
            InitializeComponent();

            this.SetFilePath(filePath);
            this.richTextBox.LoadFile(filePath, fileType);
            this.SetFileTypeIndex(i);
        }
Exemplo n.º 12
0
        private void SetDocumentProperties(string filePathName, RichTextBoxStreamType fileType)
        {
            FileInfo fileInfo = new FileInfo(filePathName);

            this.documentName     = fileInfo.Name;
            this.documentPath     = fileInfo.DirectoryName;
            this.documentFileType = fileType;
        }
Exemplo n.º 13
0
 /// <summary>
 /// Saves the contents of the control to a specific type of file.
 /// </summary>
 /// <param name="path">The name and location of the file to save.</param>
 /// <param name="fileType">One of the control StreamType values.</param>
 public void SaveFile(string path, RichTextBoxStreamType fileType)
 {
     if (T == null)
     {
         return;
     }
     T.SaveFile(path, fileType);
 }
Exemplo n.º 14
0
        public static void SaveFile(RichTextBoxPrintCtrl.RichTextBoxPrint e, string filePath)
        {
            RichTextBoxStreamType ext = Path.GetExtension(filePath) == ".txt" ? RichTextBoxStreamType.PlainText : RichTextBoxStreamType.RichText;

            e.SaveFile(filePath, ext);
            e.Tag      = filePath;
            e.Modified = false;
        }
Exemplo n.º 15
0
 /// <summary>
 /// Saves the contents of the control to an open data stream.
 /// </summary>
 /// <param name="data">The data stream that contains the file to save to.</param>
 /// <param name="fileType">One of the control StreamType values.</param>
 public void SaveFile(System.IO.Stream data, RichTextBoxStreamType fileType)
 {
     if (T == null)
     {
         return;
     }
     T.SaveFile(data, fileType);
 }
Exemplo n.º 16
0
        private void ArchivoGuardar_Click(object sender, EventArgs e)
        {
            // Formulario padre
            FormMDI formPadre = (FormMDI)this.MdiParent;

            // Formulario hijo activo
            FormDocumento FormHijo = this;

            if (FormHijo == null)
            {
                return;
            }

            // Si el texto cambió...
            if (FormHijo.rtbText.Modified)
            {
                // Obtener la ruta actual del fichero
                string ruta = formPadre.etbarestPpal.Text;
                // Obtener el formato actual del fichero
                RichTextBoxStreamType formato = RichTextBoxStreamType.PlainText;
                if (ruta.EndsWith("rtf"))
                {
                    formato = RichTextBoxStreamType.RichText;
                }

                if (FormHijo.Text.StartsWith("Documento"))
                {
                    // Mostrar el diálogo Guardar
                    SaveFileDialog DlgGuardar = new SaveFileDialog();
                    DlgGuardar.Filter =
                        "ficheros txt (*.txt)|*.txt|ficheros rtf (*.rtf)|*.rtf";

                    if (DlgGuardar.ShowDialog() == DialogResult.OK)
                    {
                        // Obtener el nombre del fichero
                        ruta = DlgGuardar.FileName;
                        // Obtener el formato del fichero
                        if (DlgGuardar.FilterIndex == 1)
                        {
                            formato = RichTextBoxStreamType.PlainText;
                        }
                        else if (DlgGuardar.FilterIndex == 2)
                        {
                            formato = RichTextBoxStreamType.RichText;
                        }
                    }
                }

                // Guardar el fichero
                FormHijo.rtbText.SaveFile(ruta, formato);
                // Mostrar el nombre del fichero en la barra de título
                FormHijo.Text = ruta.Substring(ruta.LastIndexOf("\\") + 1);
                // Mostrar la ruta del fichero en la barra de estado
                formPadre.etbarestPpal.Text = ruta;
                // Fichero no modificado
                FormHijo.rtbText.Modified = false;
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Replaces the current document with a new empty document.
        /// </summary>
        private void CreateNewDocument()
        {
            this.richTextBox1.Clear();
            this.documentName     = "Document";
            this.documentPath     = null;
            this.documentFileType = RichTextBoxStreamType.RichText;

            this.RaiseRichTextBoxSelectionChanged();
        }
Exemplo n.º 18
0
        private void SaveDocumentAs(RichTextBoxStreamType fileType)
        {
            string filePathName = this.documentPath + '\\' + this.documentName;

            this.richTextBox1.SaveFile(filePathName, fileType);

            this.recentDocuments.Update(filePathName);

            this.richTextBox1.Modified = false;
        }
Exemplo n.º 19
0
        private void LoadDocument(string filePathName)
        {
            RichTextBoxStreamType streamType = filePathName.EndsWith(".rtf")
                    ? RichTextBoxStreamType.RichText
                    : RichTextBoxStreamType.PlainText;

            this.richTextBox1.LoadFile(filePathName, streamType);
            this.SetDocumentProperties(filePathName, streamType);
            this.recentDocuments.Update(filePathName);
            this.RaiseRichTextBoxSelectionChanged();
        }
Exemplo n.º 20
0
        // Save the file/page to a new file
        private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog sD = new SaveFileDialog();

            if (tabControl1.SelectedTab.Text == "McEditor")
            {
                sD.Filter = "Text Files (.txt)|*.txt|Rich Text Files (.rtf)|*.rtf";
                if (!saveToolStripMenuItem.Enabled)
                {
                    saveToolStripMenuItem.Enabled = true;
                }
                if (sD.ShowDialog() == DialogResult.OK)
                {
                    if (sD.FileName.Length > 0)
                    {
                        string[] tmp = sD.FileName.Split('.');
                        if (tmp[tmp.Length - 1] == "rtf")
                        {
                            fileType = RichTextBoxStreamType.RichText;
                        }
                        else
                        {
                            fileType = RichTextBoxStreamType.PlainText;
                        }
                    }
                    richTextBox1.SaveFile(sD.FileName, fileType);
                }
            }
            else
            {
                sD.Filter = "HTML File (.html)|*.html";
                if (!saveToolStripMenuItem.Enabled)
                {
                    saveToolStripMenuItem.Enabled = true;
                }
                if (sD.ShowDialog() == DialogResult.OK)
                {
                    if (sD.FileName.Length > 0)
                    {
                        string[] tmp = sD.FileName.Split('.');
                        if (tmp[tmp.Length - 1] == "rtf")
                        {
                            fileType = RichTextBoxStreamType.RichText;
                        }
                        else
                        {
                            fileType = RichTextBoxStreamType.PlainText;
                        }
                    }
                    richTextBox1.SaveFile(sD.FileName, fileType);
                }
            }
        }
Exemplo n.º 21
0
        public void LoadFile(string path, RichTextBoxStreamType fileType)
        {
            var readOnly = _richTextBoxInternal.ReadOnly;

            try
            {
                LoadStart(readOnly);
                _richTextBoxInternal.Invoke(RTB_LoadFilePathAndType, path, fileType);
            }
            finally
            {
                LoadEnd(readOnly);
            }
        }
Exemplo n.º 22
0
        public void LoadFile(Stream data, RichTextBoxStreamType fileType)
        {
            var readOnly = _richTextBoxInternal.ReadOnly;

            try
            {
                LoadStart(readOnly);
                _richTextBoxInternal.Invoke(RTB_LoadFileStreamAndType, data, fileType);
            }
            finally
            {
                LoadEnd(readOnly);
            }
        }
Exemplo n.º 23
0
 private void открытьToolStripMenuItem_Click(object sender, EventArgs e)
 {
     openFileDialog.InitialDirectory = "c:\\";
     openFileDialog.InitialDirectory = "Текстовый файл|*.txt|Текст в формате ртф|*.rtf";
     openFileDialog.FilterIndex      = 2;
     openFileDialog.RestoreDirectory = true;
     if (openFileDialog.ShowDialog() == DialogResult.OK)
     {
         RichTextBoxStreamType streamType = openFileDialog.FileName.EndsWith("rtf") ?
                                            RichTextBoxStreamType.RichText : RichTextBoxStreamType.PlainText;
         richTextBox.LoadFile(openFileDialog.FileName, streamType);
         this.Text = openFileDialog.FileName;
     }
 }
Exemplo n.º 24
0
        public async Task LoadFileAsync(Stream data, RichTextBoxStreamType fileType)
        {
            var readOnly = _richTextBoxInternal.ReadOnly;

            try
            {
                LoadStart(readOnly);
                await Task.Run(() => _richTextBoxInternal.Invoke(new Action(() => _richTextBoxInternal.LoadFile(data, fileType))));
            }
            finally
            {
                LoadEnd(readOnly);
            }
        }
Exemplo n.º 25
0
        // Open a file and load in to the application
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!saveToolStripMenuItem.Enabled)
            {
                saveToolStripMenuItem.Enabled = true;
            }
            OpenFileDialog fD = new OpenFileDialog();
            string         custom;

            // Open a file to the web browser
            if (tabControl1.SelectedTab.Text == "McBrowser")
            {
                fD.Filter = "HTML Files (.html)|*.html";
                custom    = "file:///";
                if (fD.ShowDialog() == DialogResult.OK)
                {
                    txbURL.Text = custom + fD.FileName;
                    webBrowser1.Navigate(custom + fD.FileName);
                }
                // Open a file to the text editor
            }
            else
            {
                fD.Filter = "All Files (*.*)|*.*|Text Files (.txt)|*.txt|Rich Text Files (.rtf)|*.rtf";
                if (fD.ShowDialog() == DialogResult.OK)
                {
                    fileName = fD.FileName;
                    string[] customArray = fileName.Split('.');
                    if (customArray[customArray.Length - 1].Equals("txt"))
                    {
                        fileType = RichTextBoxStreamType.PlainText;
                        richTextBox1.LoadFile(fileName, fileType);
                    }
                    else if (customArray[customArray.Length - 1].Equals("rtf"))
                    {
                        fileType = RichTextBoxStreamType.RichText;
                        richTextBox1.LoadFile(fileName, fileType);
                    }
                    else
                    {
                        // Prompt user if incorrect file is chosen
                        MessageBox.Show("Unsupported file type. Please choose a .txt or .rtf file.",
                                        "File Type Error",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    }
                }
            }
        }
Exemplo n.º 26
0
        private void OpenToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                RichTextBoxStreamType richTextBoxStreamType = RichTextBoxStreamType.RichText;

                if (openFileDialog.FileName.ToLower().Contains(".txt"))
                {
                    richTextBoxStreamType = RichTextBoxStreamType.PlainText;
                }
                richTextBox1.LoadFile(openFileDialog.FileName, richTextBoxStreamType);

                this.Text = "MyEditor  (" + openFileDialog.FileName + ")";
            }
        }
Exemplo n.º 27
0
        public RtfBox(string sName, string sFile, RichTextBoxStreamType oType)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            FadeForm(Fade.Up);
            try {
                rtf.LoadFile(sFile, oType);
            } catch (Exception e) {
                rtf.Text = "Error loading " + sFile + "\n" + e;
            }
            this.Text = sName;
        }
Exemplo n.º 28
0
        public RtfBox(string sName, string sFile, RichTextBoxStreamType oType)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            FadeForm(Fade.Up);
            try
            {
                rtf.LoadFile(sFile, oType);
            }
            catch (Exception e)
            {
                rtf.Text = "Error loading " + sFile + "\n" + e;
            }
            this.Text = sName;
        }
Exemplo n.º 29
0
        private void OpenToolStripMenuItem__Click(object sender, EventArgs e)
        {
            //if opening existing file
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                //then a file was selected
                //we need to know the file that needs to be loaded
                //so we need the path
                RichTextBoxStreamType richTextBoxStreamType = RichTextBoxStreamType.RichText;
                if (openFileDialog.FileName.ToLower().Contains(".txt"))
                {
                    //if its text than load plain text
                    richTextBoxStreamType = RichTextBoxStreamType.PlainText;
                }
                richTextBox.LoadFile(openFileDialog.FileName, richTextBoxStreamType);

                this.Text = "MyEditor (" + openFileDialog.FileName + ")";
            }
        }
Exemplo n.º 30
0
        private void LoadDocument(string filePathName)
        {
            RichTextBoxStreamType streamType = filePathName.EndsWith(".rtf")
                    ? RichTextBoxStreamType.RichText
                    : RichTextBoxStreamType.PlainText;

            try
            {
                this.richTextBox1.LoadFile(filePathName, streamType);
                this.SetDocumentProperties(filePathName, streamType);
                this.recentDocuments.Update(filePathName);
                this.RaiseRichTextBoxSelectionChanged();
            }
            catch (IOException e)
            {
                // there is no such file
                MessageBox.Show(e.Message);
            }
        }
Exemplo n.º 31
0
        private void SaveToolStripMenuItem__Click(object sender, EventArgs e)
        {
            if (this.MdiParent.ActiveMdiChild != this)
            {
                return;
            }

            saveFileDialog.FileName = openFileDialog.FileName;
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                RichTextBoxStreamType richTextBoxStreamType = RichTextBoxStreamType.RichText;
                if (saveFileDialog.FileName.ToLower().Contains(".txt"))
                {
                    richTextBoxStreamType = RichTextBoxStreamType.PlainText;
                }
                richTextBox.SaveFile(saveFileDialog.FileName, richTextBoxStreamType);

                this.Text = "MyEditor (" + saveFileDialog.FileName + ")";
            }
        }
Exemplo n.º 32
0
		public void LoadFile(System.IO.Stream data, RichTextBoxStreamType fileType) {
			document.Empty();

			
			// FIXME - ignoring unicode
			if (fileType == RichTextBoxStreamType.PlainText) {
				StringBuilder sb;
				char[] buffer;

				try {
					sb = new StringBuilder ((int) data.Length);
					buffer = new char [1024];
				} catch {
					throw new IOException("Not enough memory to load document");
				}

				StreamReader sr = new StreamReader (data, Encoding.Default, true);
				int charsRead = sr.Read (buffer, 0, buffer.Length);
				while (charsRead > 0) {
					sb.Append (buffer, 0, charsRead);
					charsRead = sr.Read (buffer, 0, buffer.Length);
				}

				// Remove the EOF converted to an extra EOL by the StreamReader
				if (sb.Length > 0 && sb [sb.Length - 1] == '\n')
					sb.Remove (sb.Length - 1, 1);

				base.Text = sb.ToString();
				return;
			}

			InsertRTFFromStream(data, 0, 1);

			document.PositionCaret (document.GetLine (1), 0);
			document.SetSelectionToCaret (true);
			ScrollToCaret ();
		}
Exemplo n.º 33
0
		public WordPad(string file) {
			// Object setup
			changed = false;
			if (file != null) {
				filename = file;
			} else {
				filename = "Document";
			}
			filetype = RichTextBoxStreamType.RichText;

			// UI Setup
			toolbarpanel = new Panel();
			buttons = new ToolBar();
			edit = new RichTextBox();
			formatting = new WordPadFormat(this);
			status = new StatusBar();
			Configuration.Apply(this);	// Call before creating the menu to have MRU loaded
			menu = new WordPadMenu(this, status);

			this.Menu = menu.MainMenu;

			status.TextChanged += new EventHandler (StatusTextChangedHandler);

			edit.HideSelection = false;

			buttons.Appearance = ToolBarAppearance.Flat;
			buttons.TextAlign = ToolBarTextAlign.Right;
			buttons.ButtonSize = new Size(12, 12);
			buttons.Buttons.Add("New");
			buttons.Buttons.Add("Open");
			buttons.Buttons.Add("Save");
			buttons.Divider = false;

			buttons.Location = new Point(0, 0);
			formatting.Location = new Point(0, buttons.Height);
			toolbarpanel.Height = buttons.Height + formatting.Height + 8;
			formatting.Dock = DockStyle.Bottom;

			findbar = new FindBar (edit);
			findbar.Visible = false;

			// Register all required events
			this.Closing += new CancelEventHandler(WordPadClosing);
			edit.TextChanged += new EventHandler(DocumentChanged);

			// Layout
			toolbarpanel.Controls.Add(buttons);
			toolbarpanel.Controls.Add(formatting);

			// Edit must be first to be 'filled' properly
			this.Controls.Add(edit);
			this.Controls.Add(toolbarpanel);
			this.Controls.Add (findbar);
			this.Controls.Add(status);
			
			
			toolbarpanel.Dock = DockStyle.Top;
			status.Dock = DockStyle.Bottom;
			findbar.Dock = DockStyle.Bottom;
			edit.Dock = DockStyle.Fill;

			// Load our file, if any
			if (file != null) {
				OpenFile(file, file.EndsWith("txt") ? RichTextBoxStreamType.PlainText : RichTextBoxStreamType.RichText);
			}
			UpdateTitle();
		}
Exemplo n.º 34
0
 public void LoadFile(string path, RichTextBoxStreamType fileType) {
     //valid values are 0x0 to 0x4
     if (!ClientUtils.IsEnumValid(fileType, (int)fileType, (int)RichTextBoxStreamType.RichText, (int)RichTextBoxStreamType.UnicodePlainText)){
         throw new InvalidEnumArgumentException("fileType", (int)fileType, typeof(RichTextBoxStreamType));
     }
 
     Stream file = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
     try {
         LoadFile(file, fileType);
     }
     finally {
         file.Close();
     }
 }
Exemplo n.º 35
0
 public void SaveFile(string path, RichTextBoxStreamType fileType) {
     //valid values are 0x0 to 0x4
     if (!ClientUtils.IsEnumValid(fileType, (int)fileType, (int)RichTextBoxStreamType.RichText, (int)RichTextBoxStreamType.UnicodePlainText))
     {
         throw new InvalidEnumArgumentException("fileType", (int)fileType, typeof(RichTextBoxStreamType));
     }
     
     Stream file = File.Create(path);
     try {
         SaveFile(file, fileType);
     }
     finally {
         file.Close();
     }
 }
 public void LoadFile(System.IO.Stream data, RichTextBoxStreamType fileType)
 {
 }
Exemplo n.º 37
0
	public void LoadFile(Stream data, RichTextBoxStreamType fileType)
	{
		throw new NotImplementedException("LoadFile");
	}
Exemplo n.º 38
0
		public bool OpenFile(string name, RichTextBoxStreamType type) {
			if (Changed) {
				DialogResult	result;

				result = MessageBox.Show("Save changed to " + filename + "?", "WordPad", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);

				if (result == DialogResult.Cancel) {
					return false;
				}

				if (result == DialogResult.Yes) {
					Save(false);
				}
			}

			filename = name;
			filetype = type;
			edit.LoadFile(filename, filetype);
			AddMRU(filename);
			Changed = false;
			return true;
		}
Exemplo n.º 39
0
 /// <summary>
 /// Loads the contents of an existing data stream into the RichTextBox control.
 /// </summary>
 /// <param name="data">A stream of data to load into the RichTextBox control.</param>
 /// <param name="fileType">One of the RichTextBoxStreamType values.</param>
 public void LoadFile(Stream data, RichTextBoxStreamType fileType)
 {
     _richTextBox.LoadFile(data, fileType);
 }
        public void LoadFile(Stream data, RichTextBoxStreamType fileType)
        {
            int num;
            if (!System.Windows.Forms.ClientUtils.IsEnumValid(fileType, (int) fileType, 0, 4))
            {
                throw new InvalidEnumArgumentException("fileType", (int) fileType, typeof(RichTextBoxStreamType));
            }
            switch (fileType)
            {
                case RichTextBoxStreamType.RichText:
                    num = 2;
                    break;

                case RichTextBoxStreamType.PlainText:
                    this.Rtf = "";
                    num = 1;
                    break;

                case RichTextBoxStreamType.UnicodePlainText:
                    num = 0x11;
                    break;

                default:
                    throw new ArgumentException(System.Windows.Forms.SR.GetString("InvalidFileType"));
            }
            this.StreamIn(data, num);
        }
Exemplo n.º 41
0
 public new void LoadFile(string path, RichTextBoxStreamType fileType)
 {
     rows.MarkedRow = 0;
     this.Refresh();
     base.LoadFile(path, fileType);
 }
Exemplo n.º 42
0
 /// <summary>
 /// Loads a specific type of file into the RichTextBox control. 
 /// </summary>
 /// <param name="path"></param>
 /// <param name="fileType"></param>
 public void LoadFile(string path, RichTextBoxStreamType fileType)
 {
     _RichTextBox.LoadFile(path, fileType);
     UpdateScrollBarsDelayed();
 }
Exemplo n.º 43
0
 /// <summary>
 /// Loads the contents of an existing data stream into the RichTextBox control. 
 /// </summary>
 /// <param name="data"></param>
 /// <param name="fileType"></param>
 public void LoadFile(Stream data, RichTextBoxStreamType fileType)
 {
     _RichTextBox.LoadFile(data, fileType);
     UpdateScrollBarsDelayed();
 }
Exemplo n.º 44
0
 /// <summary>
 /// Saves the contents of the log to a text file
 /// </summary>
 /// <param name="path">The path where the file should be saved</param>
 /// <param name="fileType">The stream type</param>
 public void SaveFile(string path, RichTextBoxStreamType fileType)
 {
     _textBox.SaveFile(path, fileType);
 }
Exemplo n.º 45
0
		public void LoadFile(string path, RichTextBoxStreamType fileType) {
			FileStream	data;

			data = null;


			try {
				data = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 1024);

				LoadFile(data, fileType);
			}
#if !DEBUG
			catch (Exception ex) {
				throw new IOException("Could not open file " + path, ex);
			}
#endif
			finally {
				if (data != null) {
					data.Close();
				}
			}
		}
Exemplo n.º 46
0
 /// <summary>
 /// Loads a specific type of file into the RichTextBox control.
 /// </summary>
 /// <param name="path">The name and location of the file to load into the control.</param>
 /// <param name="fileType">One of the RichTextBoxStreamType values.</param>
 public void LoadFile(string path, RichTextBoxStreamType fileType)
 {
     _richTextBox.LoadFile(path, fileType);
 }
Exemplo n.º 47
0
		public bool Save(bool ask) {
			if ((filename == "Document") || ask) {
				SaveFileDialog	savefile;
				DialogResult	result;

				savefile = new SaveFileDialog();
				savefile.AddExtension = true;
				savefile.CheckFileExists = false;
				savefile.DereferenceLinks = true;
				savefile.DefaultExt = "rtf";
				savefile.Filter = "Rich Text Format (*.rtf)|*.rtf|Text files (*.txt)|*.txt|All files (*.*)|*.*";

				result = savefile.ShowDialog();

				if (result != DialogResult.OK) {
					return false;
				}

				if (savefile.FilterIndex == 1) {
					filetype = RichTextBoxStreamType.RichText;
				} else {
					filetype = RichTextBoxStreamType.PlainText;
				}
				filename = savefile.FileName;
			}

			if (filename == String.Empty) {
				return false;
			}

			edit.SaveFile(filename, filetype);
			Changed = false;
			return true;
		}
Exemplo n.º 48
0
        private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            saveFileDialog1.Filter = SAVE_FILETYPES;

            saveFileDialog1.FileName = Path.GetFileName(m_fileName);
            if (m_fileName.Trim().Equals("") || Path.GetDirectoryName(m_fileName).Equals(""))
            {
                saveFileDialog1.InitialDirectory = Environment.SpecialFolder.MyDocuments.ToString();
            }
            else
            {
                saveFileDialog1.InitialDirectory = Path.GetDirectoryName(m_fileName);
            }
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                m_fileName = saveFileDialog1.FileName;
                Text = m_fileName;
                if (m_fileName.EndsWith(".utxt", StringComparison.OrdinalIgnoreCase))
                {
                    m_fileType = RichTextBoxStreamType.UnicodePlainText;
                }
                else
                {
                    m_fileType=RichTextBoxStreamType.RichText;
                }
                txtRTF.SaveFile(m_fileName, m_fileType);
                txtRTF.Modified = false;
            }
        }
Exemplo n.º 49
0
		public void Clear() {
			DialogResult	result;

			if (Changed) {
				result = MessageBox.Show("Save changed to " + filename + "?", "WordPad", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);

				if (result == DialogResult.Cancel) {
					return;
				}

				if (result == DialogResult.Yes) {
					Save(false);
				}
			}

			// FIXME - we need a dialog and ask for the document type
			filename = "Document";
			filetype = RichTextBoxStreamType.RichText;
			edit.Clear();
			Changed = false;
		}
 public void LoadFile(string path, RichTextBoxStreamType fileType)
 {
     if (!System.Windows.Forms.ClientUtils.IsEnumValid(fileType, (int) fileType, 0, 4))
     {
         throw new InvalidEnumArgumentException("fileType", (int) fileType, typeof(RichTextBoxStreamType));
     }
     Stream data = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
     try
     {
         this.LoadFile(data, fileType);
     }
     finally
     {
         data.Close();
     }
 }
Exemplo n.º 51
0
	public void SaveFile(String path, RichTextBoxStreamType fileType)
	{
		throw new NotImplementedException("SaveFile");
	}
        public void SaveFile(Stream data, RichTextBoxStreamType fileType)
        {
            int num;
            switch (fileType)
            {
                case RichTextBoxStreamType.RichText:
                    num = 2;
                    break;

                case RichTextBoxStreamType.PlainText:
                    num = 1;
                    break;

                case RichTextBoxStreamType.RichNoOleObjs:
                    num = 3;
                    break;

                case RichTextBoxStreamType.TextTextOleObjs:
                    num = 4;
                    break;

                case RichTextBoxStreamType.UnicodePlainText:
                    num = 0x11;
                    break;

                default:
                    throw new InvalidEnumArgumentException("fileType", (int) fileType, typeof(RichTextBoxStreamType));
            }
            this.StreamOut(data, num, true);
        }
Exemplo n.º 53
0
        /// <include file='doc\RichTextBox.uex' path='docs/doc[@for="RichTextBox.SaveFile2"]/*' />
        /// <devdoc>
        ///     Saves the contents of a RichTextBox control to a file.
        /// </devdoc>
        public void SaveFile(Stream data, RichTextBoxStreamType fileType) {
            int flags;
            switch (fileType) {
                case RichTextBoxStreamType.RichText:
                    flags = RichTextBoxConstants.SF_RTF;
                    break;
                case RichTextBoxStreamType.PlainText:
                    flags = RichTextBoxConstants.SF_TEXT;
                    break;
                case RichTextBoxStreamType.UnicodePlainText:
                    flags = RichTextBoxConstants.SF_UNICODE | RichTextBoxConstants.SF_TEXT;
                    break;
                case RichTextBoxStreamType.RichNoOleObjs:
                    flags = RichTextBoxConstants.SF_RTFNOOBJS;
                    break;
                case RichTextBoxStreamType.TextTextOleObjs:
                    flags = RichTextBoxConstants.SF_TEXTIZED;
                    break;
                default:
                    throw new InvalidEnumArgumentException("fileType", (int)fileType, typeof(RichTextBoxStreamType));
            }

            StreamOut(data, flags, true);
        }
Exemplo n.º 54
0
		public void SaveFile(Stream data, RichTextBoxStreamType fileType) {
			Encoding	encoding;
			int		i;
			Byte[]		bytes;


			if (fileType == RichTextBoxStreamType.UnicodePlainText) {
				encoding = Encoding.Unicode;
			} else {
				encoding = Encoding.ASCII;
			}

			switch(fileType) {
				case RichTextBoxStreamType.PlainText: 
				case RichTextBoxStreamType.TextTextOleObjs: 
				case RichTextBoxStreamType.UnicodePlainText: {
					if (!Multiline) {
						bytes = encoding.GetBytes(document.Root.text.ToString());
						data.Write(bytes, 0, bytes.Length);
						return;
					}

					for (i = 1; i < document.Lines; i++) {
						// Normalize the new lines to the system ones
						string line_text = document.GetLine (i).TextWithoutEnding () + Environment.NewLine;
						bytes = encoding.GetBytes(line_text);
						data.Write(bytes, 0, bytes.Length);
					}
					bytes = encoding.GetBytes(document.GetLine(document.Lines).text.ToString());
					data.Write(bytes, 0, bytes.Length);
					return;
				}
			}

			// If we're here we're saving RTF
			Line		start_line;
			Line		end_line;
			StringBuilder	rtf;
			int		current;
			int		total;

			start_line = document.GetLine(1);
			end_line = document.GetLine(document.Lines);
			rtf = GenerateRTF(start_line, 0, end_line, end_line.text.Length);
			total = rtf.Length;
			bytes = new Byte[4096];

			// Let's chunk it so we don't use up all memory...
			for (i = 0; i < total; i += 1024) {
				if ((i + 1024) < total) {
					current = encoding.GetBytes(rtf.ToString(i, 1024), 0, 1024, bytes, 0);
				} else {
					current = total - i;
					current = encoding.GetBytes(rtf.ToString(i, current), 0, current, bytes, 0);
				}
				data.Write(bytes, 0, current);
			}
		}
Exemplo n.º 55
0
        /// <include file='doc\RichTextBox.uex' path='docs/doc[@for="RichTextBox.LoadFile2"]/*' />
        /// <devdoc>
        ///     Loads the contents of a RTF or text into a RichTextBox control.
        /// </devdoc>
        public void LoadFile(Stream data, RichTextBoxStreamType fileType) {
            //valid values are 0x0 to 0x4
            if (!ClientUtils.IsEnumValid(fileType, (int)fileType, (int)RichTextBoxStreamType.RichText, (int)RichTextBoxStreamType.UnicodePlainText))
            {
                throw new InvalidEnumArgumentException("fileType", (int)fileType, typeof(RichTextBoxStreamType));
            }
        
            int flags;
            switch (fileType) {
                case RichTextBoxStreamType.RichText:
                    flags = RichTextBoxConstants.SF_RTF;
                    break;
                case RichTextBoxStreamType.PlainText:
                    this.Rtf = "";
                    flags = RichTextBoxConstants.SF_TEXT;
                    break;
                case RichTextBoxStreamType.UnicodePlainText:
                    flags = RichTextBoxConstants.SF_UNICODE | RichTextBoxConstants.SF_TEXT;
                    break;
                default:
                    throw new ArgumentException(SR.GetString(SR.InvalidFileType));
            }

            StreamIn(data, flags);
        }
Exemplo n.º 56
0
		public void SaveFile(string path, RichTextBoxStreamType fileType) {
			FileStream	data;

			data = null;

//			try {
				data = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None, 1024, false);
				SaveFile(data, fileType);
//			}

//			catch {
//				throw new IOException("Could not write document to file " + path);
//			}

//			finally {
				if (data != null) {
					data.Close();
				}
//			}
		}
 public void SaveFile(string path, RichTextBoxStreamType fileType)
 {
     if (!System.Windows.Forms.ClientUtils.IsEnumValid(fileType, (int) fileType, 0, 4))
     {
         throw new InvalidEnumArgumentException("fileType", (int) fileType, typeof(RichTextBoxStreamType));
     }
     Stream data = File.Create(path);
     try
     {
         this.SaveFile(data, fileType);
     }
     finally
     {
         data.Close();
     }
 }
Exemplo n.º 58
0
 public void SaveToFile(String fileName, RichTextBoxStreamType fileType)
 {
     richTextBox1.SaveFile(fileName, fileType);
 }
Exemplo n.º 59
0
 /// <summary>
 /// Saves the contents of the log to a text file
 /// </summary>
 /// <param name="data">The stream of the data to save</param>
 /// <param name="fileType">The stream type</param>
 public void SaveFile(Stream data, RichTextBoxStreamType fileType)
 {
     _textBox.SaveFile(data, fileType);
 }
Exemplo n.º 60
0
 public void OpenFile(String fileName, RichTextBoxStreamType fileType)
 {
     richTextBox1.LoadFile(fileName, fileType);
 }