2
using System.Collections.Generic;
3
using System.ComponentModel;
8
using System.Windows.Forms;
9
using TextEditorSWF.ExtensionModel;
13
namespace TextEditorSWF
15
public partial class TextEditor : Form
21
InitializeComponent ();
23
// Create the main menu and the toolbar
25
foreach (ToolStripItem item in CommandManager.GetMainMenuItems ())
26
menuStrip.Items.Add (item);
27
foreach (ToolStripItem item in CommandManager.GetToolbarItems ())
28
toolStrip.Items.Add (item);
31
internal void Initialize ()
33
// Initialize the editor extensions. Must be done after setting Program.MainWindow since
34
// extensions may use it
35
foreach (EditorExtension ext in AddinManager.GetExtensionObjects<EditorExtension> ())
42
public RichTextBox Editor
44
get { return richTextBox; }
48
/// Saves the file to disk, asking for location if the file is unsaved
50
public void SaveFile ()
52
if (currentFile == null) {
53
SaveFileDialog dlg = new SaveFileDialog ();
54
if (dlg.ShowDialog (this) != DialogResult.OK)
56
currentFile = dlg.FileName;
59
SaveFile (currentFile);
63
/// Saves the file to the specified location
65
public void SaveFile (string file)
67
File.WriteAllText (file, richTextBox.Text);
69
// Notify editor extensions
70
foreach (EditorExtension ext in AddinManager.GetExtensionObjects<EditorExtension> ())
71
ext.OnSaveFile (file);
77
public void NewFile ()
79
richTextBox.Text = "";
82
// Notify editor extensions
83
foreach (EditorExtension ext in AddinManager.GetExtensionObjects<EditorExtension> ())
88
/// Open a new file. Will ask for the file name in a dialog.
90
public void OpenFile ()
92
OpenFileDialog dlg = new OpenFileDialog ();
93
if (dlg.ShowDialog () == DialogResult.OK)
94
OpenFile (dlg.FileName);
99
/// Open the specified file in the text editor
101
public void OpenFile (string file)
103
richTextBox.Text = File.ReadAllText (file);
106
// Notify editor extensions
107
foreach (EditorExtension ext in AddinManager.GetExtensionObjects<EditorExtension> ())
108
ext.OnLoadFile (file);