diff options
author | Miguel de Icaza <miguel@gnome.org> | 2009-09-08 06:15:18 +0400 |
---|---|---|
committer | Miguel de Icaza <miguel@gnome.org> | 2009-09-08 06:15:18 +0400 |
commit | 2ed491ad1807dd589f988395bc71ba5763c7b1d1 (patch) | |
tree | a05c6cf0f1255d9bd0add1f9a56efbf9d8a482e3 /gsharp | |
parent | 894df04823d9daa845d542aaaa5216a3b949fc21 (diff) |
2009-09-07 Miguel de Icaza <miguel@novell.com>
* Shell.cs: Add poor man's autocompletion to GSharp.
I probably should copy the way MonoDevelop pops up the completion
window to be right.
svn path=/trunk/mono-tools/; revision=141481
Diffstat (limited to 'gsharp')
-rw-r--r-- | gsharp/ChangeLog | 7 | ||||
-rw-r--r-- | gsharp/Shell.cs | 59 |
2 files changed, 62 insertions, 4 deletions
diff --git a/gsharp/ChangeLog b/gsharp/ChangeLog index da9c633d..88ad5db8 100644 --- a/gsharp/ChangeLog +++ b/gsharp/ChangeLog @@ -1,3 +1,10 @@ +2009-09-07 Miguel de Icaza <miguel@novell.com> + + * Shell.cs: Add poor man's autocompletion to GSharp. + + I probably should copy the way MonoDevelop pops up the completion + window to be right. + 2008-12-18 Miguel de Icaza <miguel@novell.com> * gtk-gui/Mono.CSharp.Gui.MainWindow.cs: Change hierarchy so that we can diff --git a/gsharp/Shell.cs b/gsharp/Shell.cs index dc0314f7..2fcf5435 100644 --- a/gsharp/Shell.cs +++ b/gsharp/Shell.cs @@ -257,6 +257,51 @@ namespace Mono.CSharp.Gui Buffer.MoveMark(Buffer.SelectionBound, InputLineBegin); } return true; + + case Gdk.Key.Tab: + string saved_text = InputLine; + string prefix; + string [] completions = Evaluator.GetCompletions (LineUntilCursor, out prefix); + if (completions == null) + return true; + + if (completions.Length == 1){ + TextIter cursor = Cursor; + Buffer.Insert (ref cursor, completions [0]); + return true; + } + + Console.WriteLine (); + foreach (var s in completions){ + Console.Write (prefix); + Console.Write (s); + Console.Write (" "); + } + // Insert a new line before we evaluate. + end = Buffer.EndIter; + Buffer.InsertWithTagsByName (ref end, "\n", "Stdout"); + ShowPrompt (false); + InputLine = saved_text; +#if false + Gtk.TextIter start = Cursor; + if (prefix.Length != 0) + MoveVisually (ref start, -prefix.Length); + int x, y; + GdkWindow.GetOrigin (out x, out y); + var r = GetIterLocation (start); + x += r.X; + y += r.Y; + var w = new Gtk.Window (WindowType.Popup); + w.SetUposition (x, y); + w.SetUsize (100, 100); + foreach (var s in completions){ + Console.WriteLine ("{0}[{1}]", prefix, s); + } + w.ShowAll (); + Console.WriteLine ("Position: x={0} y={1}", x + r.X, y +r.Y); +#endif + return true; + default: break; } @@ -348,19 +393,19 @@ namespace Mono.CSharp.Gui Buffer.InsertWithTagsByName (ref end, err, "Error"); } - private TextIter InputLineBegin { + TextIter InputLineBegin { get { return Buffer.GetIterAtMark(end_of_last_processing); } } - private TextIter InputLineEnd { + TextIter InputLineEnd { get { return Buffer.EndIter; } } - private TextIter Cursor { + TextIter Cursor { get { return Buffer.GetIterAtMark(Buffer.InsertMark); } } - private string InputLine { + string InputLine { get { return Buffer.GetText(InputLineBegin, InputLineEnd, false); } set { TextIter start = InputLineBegin; @@ -372,6 +417,12 @@ namespace Mono.CSharp.Gui } } + string LineUntilCursor { + get { + return Buffer.GetText (InputLineBegin, Cursor, false); + } + } + static void p (TextWriter output, string s) { output.Write (s); |