3 using System.Collections;
8 class FileSelector : TextInput {
9 private string filestr;
11 public FileSelector() : base(Directory.GetCurrentDirectory() + System.IO.Path.DirectorySeparatorChar) {
15 protected override void draw(Cairo.Context gr, int width, int height) {
16 base.draw(gr, width, height);
21 gr.LineTo(width, 13.5);
24 if (filestr != null) {
25 Pango.Layout layout = new Pango.Layout(this.PangoContext);
26 layout.Width = Pango.Units.FromPixels(width);
27 layout.FontDescription = Pango.FontDescription.FromString("Courier 12");
28 layout.Wrap = Pango.WrapMode.WordChar;
29 layout.SetMarkup(filestr);
31 Pango.CairoHelper.ShowLayout(gr, layout);
35 [GLib.ConnectBefore()]
36 public override void KeyPress(object o, KeyPressEventArgs args) {
37 base.KeyPress(o, args);
38 switch(args.Event.Key) {
46 private void Complete() {
47 string dir = System.IO.Path.GetDirectoryName(Value);
48 string search = System.IO.Path.GetFileName(Value);
49 string[] files = Directory.GetFileSystemEntries(dir, search + "*");
51 if (files.Length == 1 && Directory.Exists(files[0])) {
52 Value = files[0] + System.IO.Path.DirectorySeparatorChar;
55 } else if (files.Length > 0) {
59 string common = System.IO.Path.GetFileName(files[0]);
61 for (i = 0; i < files.Length; i++) {
62 files[i] = System.IO.Path.GetFileName(files[i]);
63 common = CommonPart(common, files[i]);
66 Value = dir + System.IO.Path.DirectorySeparatorChar + common;
67 cursor = Value.Length;
69 for (i = 0; i < files.Length; i++) {
71 filestr += "<span color=\"#7F7F7F\">" + common + "</span>" + f.Substring(common.Length) + " ";
76 private string CommonPart(string s1, string s2) {
77 CharEnumerator i1 = s1.GetEnumerator();
78 CharEnumerator i2 = s2.GetEnumerator();
81 while (i1.MoveNext() && i2.MoveNext()) {
82 if (i1.Current != i2.Current) break;
85 return s1.Substring(0, c);