Esempio n. 1
0
        public static LispEditor OpenFile(string filePath)
        {
            try
            {
                LispEditor editor = new LispEditor();
                editor.Scintilla.Text = File.ReadAllText(filePath);
                editor.Scintilla.UndoRedo.EmptyUndoBuffer();
                editor.Scintilla.Modified = false;
                editor.Text     = Path.GetFileName(filePath);
                editor.FilePath = filePath;

                OnFileOpened(editor.FilePath, editor.Text, editor);

                return(editor);
            }
            catch (FileNotFoundException)
            {
                ConfigurationManager.RecentFiles.RemoveRecentFile(filePath);
                MessageBox.Show("Cannot open file \"" + filePath + "\". The file was not found.", "File not found",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception)
            {
                MessageBox.Show("Cannot open file \"" + filePath + "\". There was an error opening the file.",
                                "Error opening file",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            return(null);
        }
Esempio n. 2
0
 protected static void OnFileClosed(string file, string name, LispEditor editor)
 {
     if (FileClosed != null)
     {
         FileClosed(null, new FileCommandEventArgs(file, name, editor));
     }
 }
Esempio n. 3
0
        public static bool SaveFile(IWin32Window owner, LispEditor editor)
        {
            if (String.IsNullOrEmpty(editor.FilePath))
            {
                return(SaveFileAs(owner, editor));
            }

            return(Save(editor.FilePath, editor));
        }
Esempio n. 4
0
        public static LispEditor NewFile()
        {
            LispEditor editor = new LispEditor();

            editor.Text = string.Format(CultureInfo.CurrentCulture, "{0}{1}", NEW_DOCUMENT_TEXT, ++newDocumentCount);

            OnFileCreated(null, editor.Text, editor);

            return(editor);
        }
Esempio n. 5
0
        protected static void OnFileSaved(string file, string name, LispEditor editor)
        {
            ConfigurationManager.RecentFiles.AddRecentFile(file);
            ConfigurationManager.Save();

            if (FileSaved != null)
            {
                FileSaved(null, new FileCommandEventArgs(file, name, editor));
            }
        }
Esempio n. 6
0
 public static void Close(LispEditor editor)
 {
     if (editor != null)
     {
         string path = editor.FilePath;
         string name = editor.Text;
         editor.Close();
         OnFileClosed(path, name, editor);
     }
 }
Esempio n. 7
0
 public static void CloseAll(IDockContent[] editors)
 {
     foreach (IDockContent editor in editors)
     {
         LispEditor leditor = editor as LispEditor;
         if (leditor != null)
         {
             string path = leditor.FilePath;
             string name = leditor.Text;
             leditor.Close();
             OnFileClosed(path, name, leditor);
         }
     }
 }
Esempio n. 8
0
        public static bool SaveFileAs(IWin32Window owner, LispEditor editor)
        {
            using (SaveFileDialog saveFileDialog = new SaveFileDialog())
            {
                saveFileDialog.Filter     = Filter;
                saveFileDialog.DefaultExt = DefaultExt;

                if (saveFileDialog.ShowDialog(owner) == DialogResult.OK)
                {
                    return(Save(saveFileDialog.FileName, editor));
                }
            }

            return(false);
        }
Esempio n. 9
0
        public static bool Save(string filePath, LispEditor editor)
        {
            try
            {
                using (FileStream fs = File.Create(filePath))
                    using (BinaryWriter bw = new BinaryWriter(fs))
                        bw.Write(editor.Scintilla.RawText, 0, editor.Scintilla.RawText.Length - 1); // Omit trailing NULL

                editor.FilePath           = filePath;
                editor.Text               = Path.GetFileName(filePath);
                editor.Scintilla.Modified = false;

                OnFileSaved(editor.FilePath, editor.Text, editor);

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Cannot save file \"" + filePath + "\".\nException: " + ex.Message,
                                "Error saving file", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            return(false);
        }
Esempio n. 10
0
 public FileCommandEventArgs(string file, string name, LispEditor editor)
 {
     this.path   = file;
     this.name   = name;
     this.editor = editor;
 }