[Monodevelop-patches-list] r739 - in trunk/MonoDevelop/src: AddIns/DisplayBindings/EditorBindings/FormattingStrategy Libraries/ICSharpCode.TextEditor Libraries/ICSharpCode.TextEditor/src/Document
commit-watcher at mono-cvs.ximian.com
commit-watcher at mono-cvs.ximian.com
Sat Jan 31 20:37:34 EST 2004
Author: benm
Date: 2004-01-31 20:37:34 -0500 (Sat, 31 Jan 2004)
New Revision: 739
Added:
trunk/MonoDevelop/src/AddIns/DisplayBindings/EditorBindings/FormattingStrategy/DefaultFormattingStrategy.cs
Removed:
trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Document/FormattingStrategy/
Modified:
trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/Makefile
Log:
move this
Copied: trunk/MonoDevelop/src/AddIns/DisplayBindings/EditorBindings/FormattingStrategy/DefaultFormattingStrategy.cs (from rev 738, trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Document/FormattingStrategy/DefaultFormattingStrategy.cs)
===================================================================
--- trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Document/FormattingStrategy/DefaultFormattingStrategy.cs 2004-02-01 01:30:26 UTC (rev 738)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/EditorBindings/FormattingStrategy/DefaultFormattingStrategy.cs 2004-02-01 01:37:34 UTC (rev 739)
@@ -0,0 +1,105 @@
+// <file>
+// <copyright see="prj:///doc/copyright.txt"/>
+// <license see="prj:///doc/license.txt"/>
+// <owner name="Mike Krüger" email="mike at icsharpcode.net"/>
+// <version value="$version"/>
+// </file>
+
+using System;
+using System.Collections;
+using System.Text;
+using MonoDevelop.EditorBindings.FormattingStrategy;
+
+namespace ICSharpCode.TextEditor.Document {
+ /// <summary>
+ /// This class handles the auto and smart indenting in the textbuffer while
+ /// you type.
+ /// </summary>
+ public class DefaultFormattingStrategy : IFormattingStrategy {
+ /// <summary>
+ /// returns the whitespaces which are before a non white space character in the line line
+ /// as a string.
+ /// </summary>
+ protected string GetIndentation (IFormattableDocument d, int lineNumber)
+ {
+ string lineText = d.GetLineAsString (lineNumber);
+ StringBuilder whitespaces = new StringBuilder ();
+
+ foreach (char ch in lineText) {
+ if (! Char.IsWhiteSpace (ch))
+ break;
+ whitespaces.Append (ch);
+ }
+
+ return whitespaces.ToString ();
+ }
+
+ /// <summary>
+ /// Could be overwritten to define more complex indenting.
+ /// </summary>
+ protected virtual int AutoIndentLine (IFormattableDocument d, int lineNumber)
+ {
+ string indentation = lineNumber != 0 ? GetIndentation (d, lineNumber - 1) : "";
+
+ if (indentation.Length > 0) {
+ string newLineText = indentation + d.GetLineAsString (lineNumber).Trim ();
+ d.ReplaceLine (lineNumber, newLineText);
+ }
+
+ return indentation.Length;
+ }
+
+ /// <summary>
+ /// Could be overwritten to define more complex indenting.
+ /// </summary>
+ protected virtual int SmartIndentLine (IFormattableDocument d, int line)
+ {
+ return AutoIndentLine (d, line); // smart = autoindent in normal texts
+ }
+
+ /// <summary>
+ /// This function formats a specific line after <code>ch</code> is pressed.
+ /// </summary>
+ /// <returns>
+ /// the caret delta position the caret will be moved this number
+ /// of bytes (e.g. the number of bytes inserted before the caret, or
+ /// removed, if this number is negative)
+ /// </returns>
+ public virtual int FormatLine (IFormattableDocument d, int line, int cursorOffset, char ch)
+ {
+ if (ch == '\n')
+ return IndentLine (d, line);
+
+ return 0;
+ }
+
+ /// <summary>
+ /// This function sets the indentation level in a specific line
+ /// </summary>
+ /// <returns>
+ /// the number of inserted characters.
+ /// </returns>
+ public int IndentLine (IFormattableDocument d, int line)
+ {
+ switch (d.IndentStyle) {
+ case IndentStyle.Auto : return AutoIndentLine (d, line);
+ case IndentStyle.Smart : return SmartIndentLine (d, line);
+ case IndentStyle.None :
+ default : return 0;
+ }
+ }
+
+ /// <summary>
+ /// This function sets the indentlevel in a range of lines.
+ /// </summary>
+ public void IndentLines (IFormattableDocument d, int begin, int end)
+ {
+ d.BeginAtomicUndo ();
+
+ for (int i = begin; i <= end; ++i)
+ IndentLine (d, i);
+
+ d.EndAtomicUndo ();
+ }
+ }
+}
Modified: trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/Makefile
===================================================================
--- trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/Makefile 2004-02-01 01:30:26 UTC (rev 738)
+++ trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/Makefile 2004-02-01 01:37:34 UTC (rev 739)
@@ -85,7 +85,6 @@
./src/Document/DefaultDocument.cs \
./src/Document/IDocument.cs \
./src/Document/AbstractSegment.cs \
-./src/Document/FormattingStrategy/DefaultFormattingStrategy.cs \
./src/Document/TextBufferStrategy/StringTextBufferStrategy.cs \
./src/Document/TextBufferStrategy/GapTextBufferStrategy.cs \
./src/Document/TextBufferStrategy/ITextBufferStrategy.cs \
More information about the Monodevelop-patches-list
mailing list