7
public class TextEditorApp
9
static string openFile = "";
11
private TextEditorApp()
15
public static string OpenFileName {
16
get { return openFile; }
19
public static MainWindow MainWindow {
20
get { return MainWindow.Instance; }
23
public static void OpenFile (string file)
25
using (StreamReader sr = new StreamReader (file)) {
26
MainWindow.View.Buffer.Text = sr.ReadToEnd ();
31
public static void SaveFile ()
34
Gtk.FileChooserDialog fcd = new Gtk.FileChooserDialog ("Save File", null, Gtk.FileChooserAction.Save);
35
fcd.AddButton (Gtk.Stock.Cancel, Gtk.ResponseType.Cancel);
36
fcd.AddButton (Gtk.Stock.Open, Gtk.ResponseType.Ok);
37
fcd.DefaultResponse = Gtk.ResponseType.Ok;
38
fcd.SelectMultiple = false;
40
Gtk.ResponseType response = (Gtk.ResponseType) fcd.Run ();
41
if (response != Gtk.ResponseType.Ok) {
46
SetOpenFile (fcd.Filename);
49
using (StreamWriter sr = new StreamWriter (openFile)) {
50
sr.Write (TextEditorApp.MainWindow.View.Buffer.Text);
54
public static void NewFile (string content)
57
MainWindow.View.Buffer.Text = content;
60
static void SetOpenFile (string file)
64
MainWindow.Title = Path.GetFileName (file);
66
MainWindow.Title = "New File";
68
if (OpenFileChanged != null)
69
OpenFileChanged (null, EventArgs.Empty);
72
public static event EventHandler OpenFileChanged;