示例#1
0
        /// <summary>
        /// Open a file
        /// </summary>
        /// <param name="fileName"></param>
        public void OpenFile(string fileName)
        {
            try
            {
                if (File.Exists(fileName))
                {
                    SetStyle(Schemes.GetHighlighterByExtension(Path.GetExtension(fileName)));
                    Editor.Text = "";
                    string openText     = File.ReadAllText(fileName);
                    bool   verifyBinary = false;
                    for (int i = 0; i < openText.Length; i++)
                    {
                        if (openText[i] == '\0')
                        {
                            verifyBinary = true;
                            break;
                        }
                    }
                    if (verifyBinary)
                    {
                        if (MessageBox.Show(LanguageManager.GetText("{BINARYFILE}"), "Binary File", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                        {
                            this.Close();
                        }
                    }
                    Editor.AppendText(openText);

                    Colourise();

                    Editor.UndoRedo.EmptyUndoBuffer();
                    Editor.Modified = false;
                    Icon            = Icon.ExtractAssociatedIcon(fileName);

                    _FileName    = fileName;
                    _BaseTabText = Path.GetFileName(_FileName);
                    TabText      = _BaseTabText;
                    _Modified    = false;
                }
                else
                {
                    MessageBox.Show(String.Format(LanguageManager.GetText("INVALIDFILENAME"), fileName), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex);
            }
        }
示例#2
0
 /// <summary>
 /// Save the document as
 /// </summary>
 /// <returns></returns>
 public bool SaveAs()
 {
     using (SaveFileDialog dialog = new SaveFileDialog())
     {
         dialog.Filter = Schemes.Extensions;
         DialogResult result = dialog.ShowDialog();
         if (result == DialogResult.OK)
         {
             if (!String.IsNullOrEmpty(dialog.FileName))
             {
                 if (Save(dialog.FileName))
                 {
                     SetStyle(Schemes.GetHighlighterByExtension(Path.GetExtension(dialog.FileName)));
                     return(true);
                 }
             }
         }
     }
     return(false);
 }