[Monodevelop-patches-list] r1253 - in trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor: . CodeCompletion Gui
commit-watcher at mono-cvs.ximian.com
commit-watcher at mono-cvs.ximian.com
Thu Mar 25 22:52:16 EST 2004
Author: tberman
Date: 2004-03-25 22:52:16 -0500 (Thu, 25 Mar 2004)
New Revision: 1253
Modified:
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/ChangeLog
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/CodeCompletionDataProvider.cs
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/CommentCompletionDataProvider.cs
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/CompletionWindow.cs
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/ICompletionDataProvider.cs
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/TemplateCompletionDataProvider.cs
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/TextUtilities.cs
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorView.cs
Log:
wewt, ctrl+space works now :) (btw, test test test)
Modified: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/ChangeLog
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/ChangeLog 2004-03-26 03:16:07 UTC (rev 1252)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/ChangeLog 2004-03-26 03:52:16 UTC (rev 1253)
@@ -1,5 +1,19 @@
2004-03-25 Todd Berman <tberman at sevenl.net>
+ * Gui/SourceEditorView.cs:
+ * CodeCompletion/TextUtilities.cs:
+ * CodeCompletion/CompletionWindow.cs:
+ * CodeCompletion/ICompletionDataProvider.cs:
+ * CodeCompletion/CommentCompletionDataProvider.cs:
+ * CodeCompletion/CodeCompletionDataProvider.cs:
+ * CodeCompletion/TemplateCompletionDataProvider.cs:
+ Lots of changes to allow for ctrl+space code completion
+ activation. Most of the changes revolve around removing the
+ assumption that the completion window is shown when the text
+ insert mark is right after the triggering character.
+
+2004-03-25 Todd Berman <tberman at sevenl.net>
+
* Properties/TextEditorProperties.cs: add a EnableCodeCompletion prop
* Gui/SourceEditorDisplayBinding.cs:
* Gui/SourceEditorView.cs: hookup EnabledCodeCompletion prop
Modified: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/CodeCompletionDataProvider.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/CodeCompletionDataProvider.cs 2004-03-26 03:16:07 UTC (rev 1252)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/CodeCompletionDataProvider.cs 2004-03-26 03:52:16 UTC (rev 1253)
@@ -23,6 +23,8 @@
using MonoDevelop.SourceEditor.Gui;
using Stock = MonoDevelop.Gui.Stock;
+using Gtk;
+
namespace MonoDevelop.SourceEditor.CodeCompletion
{
/// <summary>
@@ -42,7 +44,7 @@
ArrayList completionData = null;
- public ICompletionData[] GenerateCompletionData(string fileName, SourceEditorView textArea, char charTyped)
+ public ICompletionData[] GenerateCompletionData(string fileName, SourceEditorView textArea, char charTyped, TextMark triggerMark)
{
//FIXME: THIS IS A HACK
string lang = "C#";
@@ -51,7 +53,7 @@
completionData = new ArrayList();
this.fileName = fileName;
- Gtk.TextIter insertIter = textArea.Buffer.GetIterAtMark (textArea.Buffer.InsertMark);
+ Gtk.TextIter insertIter = textArea.Buffer.GetIterAtMark (triggerMark);
// the parser works with 1 based coordinates
Modified: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/CommentCompletionDataProvider.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/CommentCompletionDataProvider.cs 2004-03-26 03:16:07 UTC (rev 1252)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/CommentCompletionDataProvider.cs 2004-03-26 03:52:16 UTC (rev 1253)
@@ -63,7 +63,7 @@
return row >= region.BeginLine && (row <= region.EndLine || region.EndLine == -1);
}
- public ICompletionData[] GenerateCompletionData (string fileName, SourceEditorView textArea, char charTyped)
+ public ICompletionData[] GenerateCompletionData (string fileName, SourceEditorView textArea, char charTyped, Gtk.TextMark triggerMark)
{
/*caretLineNumber = textArea.Caret.Line;
caretColumn = textArea.Caret.Column;
Modified: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/CompletionWindow.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/CompletionWindow.cs 2004-03-26 03:16:07 UTC (rev 1252)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/CompletionWindow.cs 2004-03-26 03:52:16 UTC (rev 1253)
@@ -24,21 +24,29 @@
SourceEditorView control;
TreeView listView;
TreeStore store;
- DeclarationViewWindow declarationviewwindow = new DeclarationViewWindow ();
- int insertLength = 0;
+ TextMark triggeringMark;
+ int origOffset;
+ DeclarationViewWindow declarationviewwindow = new DeclarationViewWindow ();
string GetTypedString ()
{
TextIter startIter = control.Buffer.GetIterAtMark (control.Buffer.InsertMark);
- TextIter offsetIter = control.Buffer.GetIterAtOffset (startIter.Offset - insertLength);
+ TextIter offsetIter = control.Buffer.GetIterAtMark (triggeringMark);
return control.Buffer.GetText (offsetIter, startIter, true);
}
-
+
+ int insertLength {
+ get {
+ TextIter startIter = control.Buffer.GetIterAtMark (control.Buffer.InsertMark);
+ return startIter.Offset - origOffset;
+ }
+ }
+
void DeleteInsertion()
{
- if (insertLength > 0) {
- TextIter startIter = control.Buffer.GetIterAtMark (control.Buffer.InsertMark);
- TextIter offsetIter = control.Buffer.GetIterAtOffset (startIter.Offset - insertLength);
+ TextIter startIter = control.Buffer.GetIterAtMark (control.Buffer.InsertMark);
+ TextIter offsetIter = control.Buffer.GetIterAtMark (triggeringMark);
+ if (startIter.Offset > offsetIter.Offset) {
int newPos = offsetIter.Offset;
control.Buffer.Delete (offsetIter, startIter);
control.Buffer.MoveMark (control.Buffer.InsertMark, control.Buffer.GetIterAtOffset (newPos));
@@ -63,8 +71,7 @@
return true;
case (char) Gdk.Key.BackSpace:
control.SimulateKeyPress (ref e);
- insertLength--;
- if (insertLength == -1) {
+ if (insertLength <= -1) {
LostFocusListView (null, null);
}
return true;
@@ -115,11 +122,17 @@
return;
} else {
control.Buffer.InsertAtCursor (val.ToString ());
- ++insertLength;
}
break;
}
-
+
+ ShuffleSelection ();
+
+ ex.RetVal = true;
+ }
+
+ public void ShuffleSelection ()
+ {
// select the current typed word
int lastSelected = -1;
int capitalizationIndex = -1;
@@ -155,7 +168,6 @@
listView.ScrollToCell (path, null, false, 0, 0);
}
- ex.RetVal = true;
}
void InitializeControls ()
@@ -201,8 +213,10 @@
/// <remarks>
/// Shows the filled completion window, if it has no items it isn't shown.
/// </remarks>
- public void ShowCompletionWindow (char firstChar)
+ public void ShowCompletionWindow (char firstChar, TextIter trigIter)
{
+ triggeringMark = control.Buffer.CreateMark (null, trigIter, true);
+ origOffset = trigIter.Offset;
FillList (true, firstChar);
TreeIter iter;
@@ -215,10 +229,10 @@
//Point visualPos = new Point(control.ActiveTextAreaControl.TextArea.TextView.GetDrawingXPos(caretPos.Y, caretPos.X) + control.ActiveTextAreaControl.TextArea.TextView.DrawingPosition.X,
// (int)((1 + caretPos.Y) * control.ActiveTextAreaControl.TextArea.TextView.FontHeight) - control.ActiveTextAreaControl.TextArea.VirtualTop.Y - 1 + control.ActiveTextAreaControl.TextArea.TextView.DrawingPosition.Y);
- Gdk.Rectangle rect = control.GetIterLocation (control.Buffer.GetIterAtMark (control.Buffer.InsertMark));
+ Gdk.Rectangle rect = control.GetIterLocation (control.Buffer.GetIterAtMark (triggeringMark));
int wx, wy;
- control.BufferToWindowCoords (Gtk.TextWindowType.Widget, rect.X + rect.Width, rect.Y + rect.Height, out wx, out wy);
+ control.BufferToWindowCoords (Gtk.TextWindowType.Widget, rect.X /*+ rect.Width*/, rect.Y + rect.Height, out wx, out wy);
int tx, ty;
control.GdkWindow.GetOrigin (out tx, out ty);
@@ -284,8 +298,7 @@
void FillList (bool firstTime, char ch)
{
- ICompletionData[] completionData = completionDataProvider.GenerateCompletionData(fileName, control, ch);
- //Console.WriteLine ("testing");
+ ICompletionData[] completionData = completionDataProvider.GenerateCompletionData(fileName, control, ch, triggeringMark);
if (completionData == null || completionData.Length == 0) {
return;
}
Modified: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/ICompletionDataProvider.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/ICompletionDataProvider.cs 2004-03-26 03:16:07 UTC (rev 1252)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/ICompletionDataProvider.cs 2004-03-26 03:52:16 UTC (rev 1253)
@@ -16,6 +16,6 @@
namespace MonoDevelop.SourceEditor.CodeCompletion {
public interface ICompletionDataProvider {
- ICompletionData[] GenerateCompletionData(string fileName, SourceEditorView textArea, char charTyped);
+ ICompletionData[] GenerateCompletionData(string fileName, SourceEditorView textArea, char charTyped, Gtk.TextMark mark);
}
}
Modified: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/TemplateCompletionDataProvider.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/TemplateCompletionDataProvider.cs 2004-03-26 03:16:07 UTC (rev 1252)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/TemplateCompletionDataProvider.cs 2004-03-26 03:52:16 UTC (rev 1253)
@@ -26,7 +26,7 @@
}
}
- public ICompletionData[] GenerateCompletionData(string fileName, SourceEditorView textArea, char charTyped)
+ public ICompletionData[] GenerateCompletionData(string fileName, SourceEditorView textArea, char charTyped, Gtk.TextMark triggerMark)
{
CodeTemplateGroup templateGroup = CodeTemplateLoader.GetTemplateGroupPerFilename(fileName);
if (templateGroup == null) {
Modified: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/TextUtilities.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/TextUtilities.cs 2004-03-26 03:16:07 UTC (rev 1252)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/TextUtilities.cs 2004-03-26 03:52:16 UTC (rev 1253)
@@ -78,6 +78,7 @@
{
// FIXME: we should actually use GtkTextIter's
string text = textArea.Buffer.Text;
+ int origOffset = offset;
while (offset - 1 > 0) {
switch (text [offset - 1]) {
@@ -143,7 +144,7 @@
done:
// Console.WriteLine("ofs : {0} cart:{1}", offset, document.Caret.Offset);
// Console.WriteLine("return:" + document.GetText(offset, document.Caret.Offset - offset).Trim());
- Gtk.TextIter start_Iter = textArea.Buffer.GetIterAtMark (textArea.Buffer.InsertMark);
+ Gtk.TextIter start_Iter = textArea.Buffer.GetIterAtOffset (origOffset);
Gtk.TextIter offset_Iter = textArea.Buffer.GetIterAtOffset (offset);
return textArea.Buffer.GetText (start_Iter, offset_Iter, false ).Trim();
}
Modified: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorView.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorView.cs 2004-03-26 03:16:07 UTC (rev 1252)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorView.cs 2004-03-26 03:52:16 UTC (rev 1253)
@@ -54,6 +54,8 @@
ShowLineMarkers = true;
ButtonPressEvent += new ButtonPressEventHandler (buttonPress);
buf.PlaceCursor (buf.StartIter);
+ GrabFocus ();
+
}
void buttonPress (object o, ButtonPressEventArgs e)
@@ -125,6 +127,37 @@
{
Gtk.Global.PropagateEvent (this, evnt);
}
+
+ void TriggerCodeComplete ()
+ {
+ TextIter iter = buf.GetIterAtMark (buf.InsertMark);
+ char triggerChar = '.';
+ TextIter triggerIter = TextIter.Zero;
+ do {
+ //FIXME: This code is placeholder until you can
+ //just switch on iter.Char
+ string s = buf.GetText (iter, buf.GetIterAtOffset (iter.Offset + 1), true);
+ switch (s) {
+ case " ":
+ triggerIter = iter;
+ triggerChar = ' ';
+ break;
+ case ".":
+ triggerIter = iter;
+ break;
+ }
+ if (!triggerIter.Equals (TextIter.Zero))
+ break;
+ iter.BackwardChar ();
+ } while (iter.LineOffset != 0);
+
+ if (triggerIter.Equals (TextIter.Zero)) return;
+ triggerIter.ForwardChar ();
+ completionWindow = new CompletionWindow (this, ParentEditor.DisplayBinding.ContentName, new CodeCompletionDataProvider ());
+
+ completionWindow.ShowCompletionWindow (triggerChar, triggerIter);
+ completionWindow.ShuffleSelection ();
+ }
protected override bool OnKeyPressEvent (Gdk.EventKey evnt)
{
@@ -150,6 +183,13 @@
break;
}
break;
+ case Control:
+ switch (key) {
+ case Gdk.Key.space:
+ TriggerCodeComplete ();
+ return true;
+ }
+ break;
}
switch ((char)key) {
@@ -175,7 +215,7 @@
bool retval = base.OnKeyPressEvent (evnt);
if (EnableCodeCompletion) {
completionWindow = new CompletionWindow (this, ParentEditor.DisplayBinding.ContentName, new CodeCompletionDataProvider ());
- completionWindow.ShowCompletionWindow ((char)key);
+ completionWindow.ShowCompletionWindow ((char)key, buf.GetIterAtMark (buf.InsertMark));
}
return retval;
/*case '(':
More information about the Monodevelop-patches-list
mailing list