[Monodevelop-patches-list] r926 - in trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor: . Gui
commit-watcher at mono-cvs.ximian.com
commit-watcher at mono-cvs.ximian.com
Mon Feb 16 01:31:50 EST 2004
Author: tberman
Date: 2004-02-16 01:31:50 -0500 (Mon, 16 Feb 2004)
New Revision: 926
Modified:
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorView.cs
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Makefile.am
Log:
working code templates, small issues surrounding the tabbing of multilined templates but half is better than none
Modified: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorView.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorView.cs 2004-02-16 04:29:33 UTC (rev 925)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorView.cs 2004-02-16 06:31:50 UTC (rev 926)
@@ -7,6 +7,7 @@
using System.Runtime.InteropServices;
using ICSharpCode.Core.AddIns.Conditions;
using ICSharpCode.Core.AddIns;
+using ICSharpCode.SharpDevelop.Internal.Templates;
using MonoDevelop.SourceEditor.CodeCompletion;
using MonoDevelop.SourceEditor.InsightWindow;
using MonoDevelop.EditorBindings.Properties;
@@ -39,6 +40,7 @@
ShowLineNumbers = true;
ShowLineMarkers = true;
ButtonPressEvent += new ButtonPressEventHandler (buttonPress);
+ buf.PlaceCursor (buf.StartIter);
}
void buttonPress (object o, ButtonPressEventArgs e)
@@ -90,8 +92,24 @@
}
switch ((char)key) {
- //FIXME: ' ' needs to do extra parsing
case ' ':
+ if (1 == 1) {
+ string word = GetWordBeforeCaret();
+ if (word != null) {
+ CodeTemplateGroup templateGroup = CodeTemplateLoader.GetTemplateGroupPerFilename(ParentEditor.DisplayBinding.ContentName);
+
+ if (templateGroup != null) {
+ foreach (CodeTemplate template in templateGroup.Templates) {
+ if (template.Shortcut == word) {
+ InsertTemplate(template);
+ return false;
+ }
+ }
+ }
+ }
+ }
+ goto case '.';
+
case '.':
completionWindow = new CompletionWindow (this, ParentEditor.DisplayBinding.ContentName, new CodeCompletionDataProvider ());
completionWindow.ShowCompletionWindow ((char)key);
@@ -121,7 +139,66 @@
return base.OnKeyPressEvent (ref evnt);
}
+
+ public int FindPrevWordStart (string doc, int offset)
+ {
+ for ( offset-- ; offset >= 0 ; offset--)
+ {
+ if (Char.IsWhiteSpace (doc, offset)) break;
+ }
+ return ++offset;
+ }
+
+ public string GetWordBeforeCaret()
+ {
+ int offset = buf.GetIterAtMark (buf.InsertMark).Offset;
+ int start = FindPrevWordStart (buf.Text, offset);
+ return buf.Text.Substring (start, offset - start);
+ }
+ public int DeleteWordBeforeCaret()
+ {
+ int offset = buf.GetIterAtMark (buf.InsertMark).Offset;
+ int start = FindPrevWordStart (buf.Text, offset);
+ buf.Delete (buf.GetIterAtOffset (start), buf.GetIterAtOffset (offset));
+ return start;
+ }
+
+
+ public void InsertTemplate(CodeTemplate template)
+ {
+ int newCaretOffset = buf.GetIterAtMark (buf.InsertMark).Offset;
+ string word = GetWordBeforeCaret().Trim();
+ if (word.Length > 0) {
+ newCaretOffset = DeleteWordBeforeCaret();
+ }
+ int finalCaretOffset = newCaretOffset;
+
+ for (int i =0; i < template.Text.Length; ++i) {
+ switch (template.Text[i]) {
+ case '|':
+ finalCaretOffset = newCaretOffset;
+ break;
+ case '\r':
+ break;
+ case '\t':
+ buf.InsertAtCursor ('\t'.ToString ());
+ newCaretOffset++;
+ break;
+ case '\n':
+ buf.InsertAtCursor ('\n'.ToString ());
+ newCaretOffset++;
+ break;
+ default:
+ buf.InsertAtCursor (template.Text[i].ToString ());
+ newCaretOffset++;
+ break;
+ }
+ }
+ buf.PlaceCursor (buf.GetIterAtOffset (finalCaretOffset));
+ }
+
+
#region Indentation
public bool IndentSelection ()
{
Modified: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Makefile.am
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Makefile.am 2004-02-16 04:29:33 UTC (rev 925)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Makefile.am 2004-02-16 06:31:50 UTC (rev 926)
@@ -51,7 +51,7 @@
all : $(DLL)
$(DLL) : $(SOURCES)
- mcs $(SOURCES) /out:$(DLL) /t:library \
+ mcs $(SOURCES) /debug /out:$(DLL) /t:library \
/resource:../../../../data/resources/glade/EditorBindings.glade,EditorBindings.glade \
/resource:../../../../data/resources/glade/texteditoraddin.glade,texteditoraddin.glade \
/r:gtk-sharp /r:gdk-sharp $(GTKSOURCEVIEW_SHARP) /r:glib-sharp \
More information about the Monodevelop-patches-list
mailing list