gr.Operator = Operator.Xor;
gr.NewPath();
- gr.Rectangle(new Cairo.Rectangle((doc.cursor.x - doc.textorigin.x)*fontwidth, (doc.cursor.y - doc.textorigin.y)*fontheight, fontwidth, fontheight));
+ gr.Rectangle((doc.cursor.x - doc.textorigin.x)*fontwidth, (doc.cursor.y - doc.textorigin.y)*fontheight, fontwidth, fontheight);
gr.Fill();
}
while ((line = file.ReadLine()) != null) {
lines.Add(line);
}
+ file.Close();
}
public ArrayList Lines {
if (y == lines.Count - 1) return;
if (x > s.Length)
s = s.PadRight(x);
- lines[y] = s + (String)lines[y+1];
+ lines[y] = s + (string)lines[y+1];
lines.RemoveAt(y+1);
} else if (s.Length == 0 && x == 0) {
lines.RemoveAt(y);
if (y >= lines.Count) return 0;
return ((string)lines[y]).Length;
}
+
+ public void Save(string filename) {
+ StreamWriter file = new StreamWriter(filename);
+ for (int i = 0; i < lines.Count; i++) {
+ file.Write((string)lines[i]);
+ file.Write('\n');
+ }
+ file.Close();
+ }
}
public class TextDocument : IKeyPress {
private TextArray text;
+ public string filename = null;
public Cursor cursor;
public Cursor textorigin;
private int pagewidth, pageheight;
public TextDocument(string filename) {
text = new TextArray(filename);
+ this.filename = filename;
}
public string GetTextWindow() {
string s = "";
for (int i = textorigin.y; textorigin.y + i < text.Lines.Count && i < pageheight; i++) {
- String l = (String)text.Lines[i];
+ string l = (string)text.Lines[i];
s += l.Substring(textorigin.x) + "\n";
}
return s;
text.Insert(cursor.x, cursor.y, (char)c);
cursor.x++;
}
+
+ public void Save() {
+ if (filename == null)
+ throw new InvalidOperationException("Cannot Save() without filename");
+ text.Save(filename);
+ }
+
+ public void Save(string filename) {
+ this.filename = filename;
+ Save();
+ }
}
gr.NewPath();
int h = Pango.Units.ToPixels(layout.FontDescription.Size) + 1;
- gr.Rectangle(new Cairo.Rectangle(cursor*8, 0, 7, h));
+ gr.Rectangle(cursor*8, 0, 7, h);
gr.Fill();
}
[GLib.ConnectBefore ()]
static void KeyPress(object o, KeyPressEventArgs args) {
+ TextInput input;
if ((args.Event.State & Gdk.ModifierType.ControlMask) != 0) {
switch(args.Event.Key) {
case Gdk.Key.n:
display.SetDocument(doc);
break;
case Gdk.Key.o:
- TextInput filename = new FileSelector();
- stack.PackEnd(filename);
- SelectInput(filename);
- filename.Show();
- filename.Selected += delegate(object o2, TextInputEventArgs t) {
+ input = new FileSelector();
+ stack.PackEnd(input);
+ SelectInput(input);
+ input.Show();
+ input.Selected += delegate(object o2, TextInputEventArgs t) {
if (t.Value != null) {
doc = new TextDocument(t.Value);
display.SetDocument(doc);
}
SelectInput(display);
- stack.Remove(filename);
- filename.Destroy();
+ stack.Remove(input);
+ input.Destroy();
};
break;
+ case Gdk.Key.s:
+ if (doc.filename == null) {
+ input = new FileSelector();
+ stack.PackEnd(input);
+ SelectInput(input);
+ input.Show();
+ input.Selected += delegate(object o2, TextInputEventArgs t) {
+ if (t.Value != null) {
+ doc.Save(t.Value);
+ }
+ SelectInput(display);
+ stack.Remove(input);
+ input.Destroy();
+ };
+ } else {
+ doc.Save();
+ }
+ break;
case Gdk.Key.q:
Application.Quit();
break;