[Monodevelop-patches-list] r738 - in trunk/MonoDevelop/src: AddIns/BackendBindings/CSharpBinding AddIns/BackendBindings/CSharpBinding/FormattingStrategy AddIns/DisplayBindings/EditorBindings AddIns/DisplayBindings/EditorBindings/FormattingStrategy AddIns/DisplayBindings/TextEditor AddIns/DisplayBindings/TextEditor/Commands AddIns/DisplayBindings/TextEditor/Gui/Editor AddIns/DisplayBindings/TextEditor/Gui/OptionPanels Libraries/ICSharpCode.TextEditor Libraries/ICSharpCode.TextEditor/src/Actions Libraries/ICSharpCode.TextEditor/src/Document Libraries/ICSharpCode.TextEditor/src/Document/FormattingStrategy Libraries/ICSharpCode.TextEditor/src/Gui Libraries/ICSharpCode.TextEditor/src/Undo

commit-watcher at mono-cvs.ximian.com commit-watcher at mono-cvs.ximian.com
Sat Jan 31 20:30:26 EST 2004


Author: benm
Date: 2004-01-31 20:30:26 -0500 (Sat, 31 Jan 2004)
New Revision: 738

Added:
   trunk/MonoDevelop/src/AddIns/DisplayBindings/EditorBindings/FormattingStrategy/
   trunk/MonoDevelop/src/AddIns/DisplayBindings/EditorBindings/FormattingStrategy/IFormattableDocument.cs
   trunk/MonoDevelop/src/AddIns/DisplayBindings/EditorBindings/FormattingStrategy/IFormattingStrategy.cs
   trunk/MonoDevelop/src/AddIns/DisplayBindings/EditorBindings/FormattingStrategy/IndentStyle.cs
Removed:
   trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Document/FormattingStrategy/IFormattingStrategy.cs
Modified:
   trunk/MonoDevelop/src/AddIns/BackendBindings/CSharpBinding/FormattingStrategy/CSharpFormattingStrategy.cs
   trunk/MonoDevelop/src/AddIns/BackendBindings/CSharpBinding/Makefile
   trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Commands/CodeActions.cs
   trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Gui/Editor/SharpDevelopTextAreaControl.cs
   trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Gui/Editor/SharpDevelopTextEditorProperties.cs
   trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Gui/OptionPanels/BehaviorTextEditorPanel.cs
   trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Makefile
   trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/XmlFormattingStrategy.cs
   trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/Makefile
   trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Actions/MiscActions.cs
   trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Document/DefaultDocument.cs
   trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Document/DefaultTextEditorProperties.cs
   trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Document/FormattingStrategy/DefaultFormattingStrategy.cs
   trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Document/IDocument.cs
   trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Document/ITextEditorProperties.cs
   trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Gui/TextEditorControlBase.cs
   trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Undo/UndoStack.cs
Log:
Huge refactoring, step 2 to getting smart indent in the new editor

Modified: trunk/MonoDevelop/src/AddIns/BackendBindings/CSharpBinding/FormattingStrategy/CSharpFormattingStrategy.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/BackendBindings/CSharpBinding/FormattingStrategy/CSharpFormattingStrategy.cs	2004-01-31 21:28:04 UTC (rev 737)
+++ trunk/MonoDevelop/src/AddIns/BackendBindings/CSharpBinding/FormattingStrategy/CSharpFormattingStrategy.cs	2004-02-01 01:30:26 UTC (rev 738)
@@ -17,6 +17,8 @@
 using ICSharpCode.Core.Services;
 using ICSharpCode.SharpDevelop.Services;
 
+using MonoDevelop.EditorBindings.FormattingStrategy;
+
 namespace CSharpBinding.FormattingStrategy {
 	/// <summary>
 	/// This class handles the auto and smart indenting in the textbuffer while
@@ -27,59 +29,56 @@
 		/// <summary>
 		/// Define CSharp specific smart indenting for a line :)
 		/// </summary>
-		protected override int SmartIndentLine (IDocument d, int lineNr)
+		protected override int SmartIndentLine (IFormattableDocument d, int lineNr)
 		{
 			if (lineNr > 0) {
-				LineSegment lineAbove = d.GetLineSegment (lineNr - 1);
-				string  lineAboveText = d.GetText (lineAbove.Offset, lineAbove.Length).Trim ();
+				string  lineAboveText = d.GetLineAsString (lineNr - 1).Trim ();
+				string  curLineText = d.GetLineAsString (lineNr).Trim ();
 				
-				LineSegment curLine = d.GetLineSegment (lineNr);
-				string  curLineText = d.GetText (curLine.Offset, curLine.Length).Trim ();
-				
 				if ((lineAboveText.EndsWith (")") && curLineText.StartsWith ("{")) ||       // after for, while, etc.
 				    (lineAboveText.EndsWith ("else") && curLineText.StartsWith ("{")))      // after else
 				{
 					string indentation = GetIndentation (d, lineNr - 1);
-					d.Replace (curLine.Offset, curLine.Length, indentation + curLineText);
+					d.ReplaceLine (lineNr, indentation + curLineText);
 					return indentation.Length;
 				}
 				
 				// indent closing bracket.
 				if (curLineText.StartsWith ("}")) {
-					int closingBracketOffset = TextUtilities.SearchBracketBackward (d, curLine.Offset + d.GetText (curLine.Offset, curLine.Length).IndexOf ('}') - 1, '{', '}');
+					int openLine;
+					int closingBracketOffset = d.GetClosingBraceForLine (lineNr, out openLine);
 					
 					// no closing bracket found -> autoindent
 					if (closingBracketOffset == -1)
 						return AutoIndentLine (d, lineNr);
 					
-					string indentation = GetIndentation (d, d.GetLineNumberForOffset (closingBracketOffset));
+					string indentation = GetIndentation (d, openLine);
 					
-					d.Replace (curLine.Offset, curLine.Length, indentation + curLineText);
+					d.ReplaceLine (lineNr, indentation + curLineText);
 					return indentation.Length;
 				}
 				
 				// expression ended, reset to valid indent.
 				if (lineAboveText.EndsWith (";")) {
-					int closingBracketOffset = TextUtilities.SearchBracketBackward (d, curLine.Offset + d.GetText (curLine.Offset, curLine.Length).IndexOf ('}') - 1, '{', '}');
+					int openLine;
+					int closingBracketOffset = d.GetClosingBraceForLine (lineNr, out openLine);
 					
 					// no closing bracket found -> autoindent
 					if (closingBracketOffset == -1)
 						return AutoIndentLine (d, lineNr);
 					
-					int closingBracketLineNr = d.GetLineNumberForOffset (closingBracketOffset);
-					LineSegment closingBracketLine = d.GetLineSegment (closingBracketLineNr);
-					string  closingBracketLineText = d.GetText (closingBracketLine.Offset, closingBracketLine.Length).Trim ();
+					string closingBracketLineText = d.GetLineAsString (openLine).Trim ();
 					
-					string indentation = GetIndentation (d, closingBracketLineNr);
+					string indentation = GetIndentation (d, openLine);
 					
 					// special handling for switch statement formatting.
 					if (closingBracketLineText.StartsWith ("switch")) {
 						if (! (lineAboveText.StartsWith ("break;") || lineAboveText.StartsWith ("goto") || lineAboveText.StartsWith ("return")))
-							indentation += ICSharpCode.TextEditor.Actions.Tab.GetIndentationString (d);
+							indentation += d.IndentString;
 					}
-					indentation += ICSharpCode.TextEditor.Actions.Tab.GetIndentationString (d);
+					indentation += d.IndentString;
 					
-					d.Replace (curLine.Offset, curLine.Length, indentation + curLineText);
+					d.ReplaceLine (lineNr, indentation + curLineText);
 					return indentation.Length;
 				}
 				
@@ -90,8 +89,8 @@
 				     lineAboveText.StartsWith ("while") ||
 				     lineAboveText.StartsWith ("for"))) ||
 				     lineAboveText.EndsWith ("else")) {
-						string indentation = GetIndentation (d, lineNr - 1) + ICSharpCode.TextEditor.Actions.Tab.GetIndentationString (d);
-						d.Replace (curLine.Offset, curLine.Length, indentation + curLineText);
+						string indentation = GetIndentation (d, lineNr - 1) + d.IndentString;
+						d.ReplaceLine (lineNr, indentation + curLineText);
 						return indentation.Length;
 				} else {
 					// try to indent linewrap
@@ -113,7 +112,7 @@
 						for (int i = 0; i <= bracketIndex; ++i)
 							indentation += " ";
 						
-						d.Replace (curLine.Offset, curLine.Length, indentation + curLineText);
+						d.ReplaceLine (lineNr, indentation + curLineText);
 						return indentation.Length;
 					}
 				}
@@ -178,12 +177,12 @@
 			return curlyCounter > 0;
 		}
 		
-		bool IsInsideStringOrComment (IDocument d, LineSegment curLine, int cursorOffset)
+		bool IsInsideStringOrComment (IFormattableDocument d, int curLineOffset, int cursorOffset)
 		{
 			// scan cur line if it is inside a string or single line comment (//)
 			bool isInsideString  = false;
 			
-			for (int i = curLine.Offset; i < cursorOffset; ++i) {
+			for (int i = curLineOffset; i < cursorOffset; ++i) {
 				char ch = d.GetCharAt (i);
 				if (ch == '"')
 					isInsideString = !isInsideString;
@@ -195,12 +194,12 @@
 			return isInsideString;
 		}
 
-		bool IsInsideDocumentationComment (IDocument d, LineSegment curLine, int cursorOffset)
+		bool IsInsideDocumentationComment (IFormattableDocument d, int curLineOffset, int cursorOffset)
 		{
 			// scan cur line if it is inside a string or single line comment (//)
 			bool isInsideString  = false;
 			
-			for (int i = curLine.Offset; i < cursorOffset; ++i) {
+			for (int i = curLineOffset; i < cursorOffset; ++i) {
 				char ch = d.GetCharAt (i);
 				if (ch == '"')
 					isInsideString = !isInsideString;
@@ -215,19 +214,19 @@
 		}
 		
 		// used for comment tag formater/inserter
-		public override int FormatLine (IDocument d, int lineNr, int cursorOffset, char ch)
+		public override int FormatLine (IFormattableDocument d, int lineNr, int cursorOffset, char ch)
 		{
-			LineSegment curLine   = d.GetLineSegment (lineNr);
-			LineSegment lineAbove = lineNr > 0 ? d.GetLineSegment (lineNr - 1) : null;
+			int curLineOffset, curLineLength;
+			d.GetLineLengthInfo (lineNr, out curLineOffset, out curLineLength);
 			
-			if (ch != '\n' && ch != '>' && IsInsideStringOrComment (d, curLine, cursorOffset))
+			if (ch != '\n' && ch != '>' && IsInsideStringOrComment (d, curLineOffset, cursorOffset))
 				return 0;
 			
 			switch (ch) {
 				case '>':
-					if (IsInsideDocumentationComment (d, curLine, cursorOffset)) {
-						string curLineText  = d.GetText (curLine.Offset, curLine.Length);
-						int column = cursorOffset - curLine.Offset;
+					if (IsInsideDocumentationComment (d, curLineOffset, cursorOffset)) {
+						string curLineText  = d.GetLineAsString (lineNr);
+						int column = cursorOffset - curLineOffset;
 						int index = Math.Min (column - 1, curLineText.Length - 1);
 						if (curLineText [index] == '/')
 							break;
@@ -268,19 +267,18 @@
 					if (lineNr <= 0)
 						return IndentLine (d, lineNr);
 					
-					if (d.TextEditorProperties.AutoInsertCurlyBracket) {
-						string oldLineText = TextUtilities.GetLineAsString (d, lineNr - 1);
+					if (d.AutoInsertCurlyBracket) {
+						string oldLineText = d.GetLineAsString (lineNr - 1);
 						if (oldLineText.EndsWith ("{") && NeedCurlyBracket (d.TextContent)) {
 							d.Insert (cursorOffset, "\n}");
 							IndentLine (d, lineNr + 1);
 						}
 					}
 					
-					string  lineAboveText = d.GetText (lineAbove.Offset, lineAbove.Length);
+					string  lineAboveText = d.GetLineAsString (lineNr - 1);
 					
-					LineSegment    nextLine      = lineNr + 1 < d.TotalNumberOfLines ? d.GetLineSegment (lineNr + 1) : null;
-					string  nextLineText  = lineNr + 1 < d.TotalNumberOfLines ? d.GetText (nextLine.Offset, nextLine.Length) : "";
-					
+
+#if NON_PORTABLE_CODE
 					if (lineAbove.HighlightSpanStack != null && lineAbove.HighlightSpanStack.Count > 0) {				
 						if (!((Span)lineAbove.HighlightSpanStack.Peek ()).StopEOL) {	// case for /* style comments
 							int index = lineAboveText.IndexOf ("/*");
@@ -304,6 +302,9 @@
 								return indentation.Length + 2;
 							}
 						} else {
+							LineSegment nextLine = lineNr + 1 < d.TotalNumberOfLines ? d.GetLineSegment (lineNr + 1) : null;
+							string  nextLineText  = lineNr + 1 < d.TotalNumberOfLines ? d.GetText (nextLine.Offset, nextLine.Length) : "";
+							
 							// don't handle // lines, because they're only one lined comments
 							int indexAbove = lineAboveText.IndexOf ("///");
 							int indexNext  = nextLineText.IndexOf ("///");
@@ -318,6 +319,7 @@
 							}
 						}
 					}
+#endif
 					return IndentLine (d, lineNr);
 			}
 			return 0;

Modified: trunk/MonoDevelop/src/AddIns/BackendBindings/CSharpBinding/Makefile
===================================================================
--- trunk/MonoDevelop/src/AddIns/BackendBindings/CSharpBinding/Makefile	2004-01-31 21:28:04 UTC (rev 737)
+++ trunk/MonoDevelop/src/AddIns/BackendBindings/CSharpBinding/Makefile	2004-02-01 01:30:26 UTC (rev 738)
@@ -33,6 +33,7 @@
 	@ mcs /debug /out:$(DLL) /target:library /r:System.Drawing.dll \
 		/r:../../../../build/bin/MonoDevelop.Core.dll \
 		/r:../../../../build/bin/MonoDevelop.TextEditor.dll \
+		/r:../../../../build/bin/MonoDevelop.EditorBindings.dll \
 		/r:../../../../build/bin/MonoDevelop.Base.dll \
 		/r:../../../../build/bin/ICSharpCode.SharpRefactory.dll \
 		/r:gtk-sharp.dll \

Added: trunk/MonoDevelop/src/AddIns/DisplayBindings/EditorBindings/FormattingStrategy/IFormattableDocument.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/EditorBindings/FormattingStrategy/IFormattableDocument.cs	2004-01-31 21:28:04 UTC (rev 737)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/EditorBindings/FormattingStrategy/IFormattableDocument.cs	2004-02-01 01:30:26 UTC (rev 738)
@@ -0,0 +1,23 @@
+namespace MonoDevelop.EditorBindings.FormattingStrategy {
+	public interface IFormattableDocument {
+		string GetLineAsString (int ln);
+		
+		void BeginAtomicUndo ();
+		void EndAtomicUndo ();
+		void ReplaceLine (int ln, string txt);
+		
+		IndentStyle IndentStyle { get; }
+		bool AutoInsertCurlyBracket { get; }
+		
+		string TextContent { get; }
+		int TextLength { get; }
+		char GetCharAt (int offset);
+		void Insert (int offset, string text);
+		
+		string IndentString { get ; }
+		
+		int GetClosingBraceForLine (int ln, out int openingLine);
+		void GetLineLengthInfo (int ln, out int offset, out int len);
+		
+	}
+}

Copied: trunk/MonoDevelop/src/AddIns/DisplayBindings/EditorBindings/FormattingStrategy/IFormattingStrategy.cs (from rev 737, trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Document/FormattingStrategy/IFormattingStrategy.cs)
===================================================================
--- trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Document/FormattingStrategy/IFormattingStrategy.cs	2004-01-31 21:28:04 UTC (rev 737)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/EditorBindings/FormattingStrategy/IFormattingStrategy.cs	2004-02-01 01:30:26 UTC (rev 738)
@@ -0,0 +1,32 @@
+namespace MonoDevelop.EditorBindings.FormattingStrategy {
+	/// <summary>
+	/// This interface handles the auto and smart indenting and formating
+	/// in the document while  you type. Language bindings could overwrite this 
+	/// interface and define their own indentation/formating.
+	/// </summary>
+	public interface IFormattingStrategy {
+		
+		/// <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>
+		int FormatLine (IFormattableDocument d, int line, int caretOffset, char charTyped);
+		
+		/// <summary>
+		/// This function sets the indentation level in a specific line
+		/// </summary>
+		/// <returns>
+		/// the number of inserted characters.
+		/// </returns>
+		int IndentLine (IFormattableDocument d, int line);
+		
+		/// <summary>
+		/// This function sets the indentlevel in a range of lines.
+		/// </summary>
+		void IndentLines (IFormattableDocument d, int begin, int end);
+	}	
+}

Added: trunk/MonoDevelop/src/AddIns/DisplayBindings/EditorBindings/FormattingStrategy/IndentStyle.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/EditorBindings/FormattingStrategy/IndentStyle.cs	2004-01-31 21:28:04 UTC (rev 737)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/EditorBindings/FormattingStrategy/IndentStyle.cs	2004-02-01 01:30:26 UTC (rev 738)
@@ -0,0 +1,22 @@
+namespace MonoDevelop.EditorBindings.FormattingStrategy {
+	/// <summary>
+	/// Describes the indent style
+	/// </summary>
+	public enum IndentStyle {
+		/// <summary>
+		/// No indentation occurs
+		/// </summary>
+		None,
+		
+		/// <summary>
+		/// The indentation from the line above will be
+		/// taken to indent the curent line
+		/// </summary>
+		Auto, 
+		
+		/// <summary>
+		/// Inteligent, context sensitive indentation will occur
+		/// </summary>
+		Smart
+	}
+}

Modified: trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Commands/CodeActions.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Commands/CodeActions.cs	2004-01-31 21:28:04 UTC (rev 737)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Commands/CodeActions.cs	2004-02-01 01:30:26 UTC (rev 738)
@@ -30,6 +30,8 @@
 using SharpDevelop.Internal.Parser;
 using ICSharpCode.SharpDevelop.Services;
 
+using MonoDevelop.EditorBindings.FormattingStrategy;
+
 namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands
 {
 	public class GenerateCodeAction : AbstractMenuCommand

Modified: trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Gui/Editor/SharpDevelopTextAreaControl.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Gui/Editor/SharpDevelopTextAreaControl.cs	2004-01-31 21:28:04 UTC (rev 737)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Gui/Editor/SharpDevelopTextAreaControl.cs	2004-02-01 01:30:26 UTC (rev 738)
@@ -24,6 +24,7 @@
 using ICSharpCode.TextEditor.Gui.InsightWindow;
 using ICSharpCode.TextEditor.Gui.CompletionWindow;
 
+using MonoDevelop.EditorBindings.FormattingStrategy;
 
 namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
 {

Modified: trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Gui/Editor/SharpDevelopTextEditorProperties.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Gui/Editor/SharpDevelopTextEditorProperties.cs	2004-01-31 21:28:04 UTC (rev 737)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Gui/Editor/SharpDevelopTextEditorProperties.cs	2004-02-01 01:30:26 UTC (rev 738)
@@ -11,6 +11,8 @@
 
 using Pango;
 
+using MonoDevelop.EditorBindings.FormattingStrategy;
+
 namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
 {
 	public class SharpDevelopTextEditorProperties : ITextEditorProperties

Modified: trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Gui/OptionPanels/BehaviorTextEditorPanel.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Gui/OptionPanels/BehaviorTextEditorPanel.cs	2004-01-31 21:28:04 UTC (rev 737)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Gui/OptionPanels/BehaviorTextEditorPanel.cs	2004-02-01 01:30:26 UTC (rev 738)
@@ -21,6 +21,7 @@
 using ICSharpCode.SharpDevelop.Gui.Dialogs;
 
 using Gtk;
+using MonoDevelop.EditorBindings.FormattingStrategy;
 
 namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.OptionPanels
 {

Modified: trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Makefile
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Makefile	2004-01-31 21:28:04 UTC (rev 737)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Makefile	2004-02-01 01:30:26 UTC (rev 738)
@@ -70,6 +70,7 @@
 		/r:../../../../build/bin/MonoDevelop.Core.dll \
 		/r:../../../../build/bin/MonoDevelop.TextEditor.dll \
 		/r:../../../../build/bin/MonoDevelop.Base.dll \
+		/r:../../../../build/bin/MonoDevelop.EditorBindings.dll \
 		/r:System.DirectoryServices.dll /r:pango-sharp.dll /r:glade-sharp.dll \
 		/r:../../../../build/bin/MonoDevelop.Gui.Widgets.dll \
 		/r:glib-sharp.dll \

Modified: trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/XmlFormattingStrategy.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/XmlFormattingStrategy.cs	2004-01-31 21:28:04 UTC (rev 737)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/XmlFormattingStrategy.cs	2004-02-01 01:30:26 UTC (rev 738)
@@ -17,6 +17,8 @@
 using ICSharpCode.TextEditor.Actions;
 using ICSharpCode.TextEditor;
 
+using MonoDevelop.EditorBindings.FormattingStrategy;
+
 namespace ICSharpCode.SharpDevelop.DefaultEditor
 {
 	/// <summary>
@@ -25,7 +27,7 @@
 	/// </summary>
 	public class XmlFormattingStrategy : DefaultFormattingStrategy
 	{
-		public override int FormatLine(IDocument d, int lineNr, int caretOffset, char charTyped) // used for comment tag formater/inserter
+		public override int FormatLine(IFormattableDocument d, int lineNr, int caretOffset, char charTyped) // used for comment tag formater/inserter
 		{
 			try {
 				if (charTyped == '>') {

Modified: trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/Makefile
===================================================================
--- trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/Makefile	2004-01-31 21:28:04 UTC (rev 737)
+++ trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/Makefile	2004-02-01 01:30:26 UTC (rev 738)
@@ -86,7 +86,6 @@
 ./src/Document/IDocument.cs \
 ./src/Document/AbstractSegment.cs \
 ./src/Document/FormattingStrategy/DefaultFormattingStrategy.cs \
-./src/Document/FormattingStrategy/IFormattingStrategy.cs \
 ./src/Document/TextBufferStrategy/StringTextBufferStrategy.cs \
 ./src/Document/TextBufferStrategy/GapTextBufferStrategy.cs \
 ./src/Document/TextBufferStrategy/ITextBufferStrategy.cs \
@@ -99,8 +98,15 @@
 ./src/Document/DocumentFactory.cs \
 
 DLL=../../../build/bin/MonoDevelop.TextEditor.dll
+REFS= \
+ /r:System.Drawing.dll \
+ /r:gtk-sharp.dll \
+ /r:glib-sharp.dll \
+ /r:gdk-sharp.dll \
+ /r:pango-sharp.dll \
+ /r:../../../build/bin/MonoDevelop.EditorBindings.dll
 
 all: $(DLL)
 
 $(DLL): $(SOURCES)
-	@ mcs /debug /out:$(DLL) /target:library /r:System.Drawing.dll /define:GTK /r:gtk-sharp.dll /r:glib-sharp.dll /r:gdk-sharp.dll /r:pango-sharp.dll /resource:data/syntaxmodes/SyntaxModes.xml,SyntaxModes.xml /resource:data/syntaxmodes/CSharp-Mode.xshd,CSharp-Mode.xshd /resource:data/Mode.xsd,Mode.xsd /resource:data/syntaxmodes/ASPX.xshd,ASPX.xshd /resource:data/syntaxmodes/BAT-Mode.xshd,BAT-Mode.xshd /resource:data/syntaxmodes/CPP-Mode.xshd,CPP-Modes.xshd /resource:data/syntaxmodes/Coco-Mode.xshd,Coco-Mode.xshd /resource:data/syntaxmodes/HTML-Mode.xshd,HTML-Mode.xshd /resource:data/syntaxmodes/Java-Mode.xshd,Java-Mode.xshd /resource:data/syntaxmodes/JavaScript-Mode.xshd,JavaScript-Mode.xshd /resource:data/syntaxmodes/PHP-Mode.xshd,PHP-Mode.xshd /resource:data/syntaxmodes/Tex-Mode.xshd,Tex-Mode.xshd /resource:data/syntaxmodes/VBNET-Mode.xshd,VBNET-Mode.xshd /resource:data/syntaxmodes/XML-Mode.xshd,XML-Mode.xshd /resource:data/RightArrow.cur,RightArrow.cur $(SOURCES)
+	@ mcs /debug /out:$@ /target:library $(REFS) /define:GTK /resource:data/syntaxmodes/SyntaxModes.xml,SyntaxModes.xml /resource:data/syntaxmodes/CSharp-Mode.xshd,CSharp-Mode.xshd /resource:data/Mode.xsd,Mode.xsd /resource:data/syntaxmodes/ASPX.xshd,ASPX.xshd /resource:data/syntaxmodes/BAT-Mode.xshd,BAT-Mode.xshd /resource:data/syntaxmodes/CPP-Mode.xshd,CPP-Modes.xshd /resource:data/syntaxmodes/Coco-Mode.xshd,Coco-Mode.xshd /resource:data/syntaxmodes/HTML-Mode.xshd,HTML-Mode.xshd /resource:data/syntaxmodes/Java-Mode.xshd,Java-Mode.xshd /resource:data/syntaxmodes/JavaScript-Mode.xshd,JavaScript-Mode.xshd /resource:data/syntaxmodes/PHP-Mode.xshd,PHP-Mode.xshd /resource:data/syntaxmodes/Tex-Mode.xshd,Tex-Mode.xshd /resource:data/syntaxmodes/VBNET-Mode.xshd,VBNET-Mode.xshd /resource:data/syntaxmodes/XML-Mode.xshd,XML-Mode.xshd /resource:data/RightArrow.cur,RightArrow.cur $(SOURCES)

Modified: trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Actions/MiscActions.cs
===================================================================
--- trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Actions/MiscActions.cs	2004-01-31 21:28:04 UTC (rev 737)
+++ trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Actions/MiscActions.cs	2004-02-01 01:30:26 UTC (rev 738)
@@ -17,14 +17,7 @@
 	{
 		public static string GetIndentationString(IDocument document)
 		{
-			StringBuilder indent = new StringBuilder();
-			
-			if (document.TextEditorProperties.ConvertTabsToSpaces) {
-				indent.Append(new String(' ', document.TextEditorProperties.TabIndent));
-			} else {
-				indent.Append('\t');
-			}
-			return indent.ToString();
+			return document.IndentString;
 		}
 		
 		void InsertTabs(IDocument document, ISelection selection, int y1, int y2)

Modified: trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Document/DefaultDocument.cs
===================================================================
--- trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Document/DefaultDocument.cs	2004-01-31 21:28:04 UTC (rev 737)
+++ trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Document/DefaultDocument.cs	2004-02-01 01:30:26 UTC (rev 738)
@@ -13,6 +13,8 @@
 
 using ICSharpCode.TextEditor.Undo;
 
+using MonoDevelop.EditorBindings.FormattingStrategy;
+
 namespace ICSharpCode.TextEditor.Document
 {
 	/// <summary>
@@ -31,27 +33,6 @@
 	}
 	
 	/// <summary>
-	/// Describes the indent style
-	/// </summary>
-	public enum IndentStyle {
-		/// <summary>
-		/// No indentation occurs
-		/// </summary>
-		None,
-		
-		/// <summary>
-		/// The indentation from the line above will be
-		/// taken to indent the curent line
-		/// </summary>
-		Auto, 
-		
-		/// <summary>
-		/// Inteligent, context sensitive indentation will occur
-		/// </summary>
-		Smart
-	}
-	
-	/// <summary>
 	/// Describes the bracket highlighting style
 	/// </summary>
 	public enum BracketHighlightingStyle {
@@ -379,5 +360,67 @@
 		
 		public event EventHandler UpdateCommited;
 		public event EventHandler TextContentChanged;
+			
+#region IFormattableDocument
+		public string GetLineAsString (int ln)
+		{
+			LineSegment line = GetLineSegment (ln);
+			return GetText (line.Offset, line.Length);
+		}
+		
+		int atomic_begin_level = 0;
+		int atomic_undo_level = 0;
+		
+		public void BeginAtomicUndo ()
+		{
+			if (atomic_undo_level ++ == 0)
+				atomic_begin_level = UndoStack.UndoCount;
+		}
+		
+		public void EndAtomicUndo ()
+		{
+			if (-- atomic_undo_level == 0) {
+				UndoStack.UndoLast (UndoStack.UndoCount - atomic_begin_level);
+				atomic_begin_level = 0;
+			}
+		}
+		
+		public void ReplaceLine (int ln, string txt)
+		{
+			LineSegment l = GetLineSegment (ln);
+			Replace (l.Offset, l.Length, txt);
+		}
+		
+		public IndentStyle IndentStyle {
+			get {
+				return TextEditorProperties.IndentStyle;
+			}
+		}
+		
+		public string IndentString {
+			get {
+				return TextEditorProperties.ConvertTabsToSpaces ? new string (' ', TextEditorProperties.TabIndent) : "\t";
+			}
+		}
+		
+		public int GetClosingBraceForLine (int ln, out int openingLine)
+		{
+			int offset = TextUtilities.SearchBracketBackward (this, GetLineSegment (ln).Offset - 1, '{', '}');
+			
+			openingLine = offset == -1 ? -1 : GetLineNumberForOffset (offset);
+			return offset;
+		}
+		
+		public bool AutoInsertCurlyBracket {
+			get { return TextEditorProperties.AutoInsertCurlyBracket; }			
+		}
+		
+		public void GetLineLengthInfo (int ln, out int offset, out int len)
+		{
+			LineSegment l = GetLineSegment (ln);
+			offset = l.Offset;
+			len = l.Length;
+		}
+#endregion
 	}
 }

Modified: trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Document/DefaultTextEditorProperties.cs
===================================================================
--- trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Document/DefaultTextEditorProperties.cs	2004-01-31 21:28:04 UTC (rev 737)
+++ trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Document/DefaultTextEditorProperties.cs	2004-02-01 01:30:26 UTC (rev 738)
@@ -2,6 +2,8 @@
 using System.Drawing;
 using System.Text;
 
+using MonoDevelop.EditorBindings.FormattingStrategy;
+
 namespace ICSharpCode.TextEditor.Document
 {
 	public class DefaultTextEditorProperties : ITextEditorProperties

Modified: trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Document/FormattingStrategy/DefaultFormattingStrategy.cs
===================================================================
--- trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Document/FormattingStrategy/DefaultFormattingStrategy.cs	2004-01-31 21:28:04 UTC (rev 737)
+++ trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Document/FormattingStrategy/DefaultFormattingStrategy.cs	2004-02-01 01:30:26 UTC (rev 738)
@@ -9,8 +9,8 @@
 using System.Collections;
 using System.Drawing;
 using System.Text;
+using MonoDevelop.EditorBindings.FormattingStrategy;
 
-
 namespace ICSharpCode.TextEditor.Document {
 	/// <summary>
 	/// This class handles the auto and smart indenting in the textbuffer while
@@ -21,12 +21,9 @@
 		/// returns the whitespaces which are before a non white space character in the line line
 		/// as a string.
 		/// </summary>
-		protected string GetIndentation (IDocument d, int lineNumber)
+		protected string GetIndentation (IFormattableDocument d, int lineNumber)
 		{
-			if (lineNumber < 0 || lineNumber > d.TotalNumberOfLines)
-				throw new ArgumentOutOfRangeException ("lineNumber");
-			
-			string lineText = TextUtilities.GetLineAsString (d, lineNumber);
+			string lineText = d.GetLineAsString (lineNumber);
 			StringBuilder whitespaces = new StringBuilder ();
 			
 			foreach (char ch in lineText) {
@@ -41,14 +38,13 @@
 		/// <summary>
 		/// Could be overwritten to define more complex indenting.
 		/// </summary>
-		protected virtual int AutoIndentLine (IDocument d, int lineNumber)
+		protected virtual int AutoIndentLine (IFormattableDocument d, int lineNumber)
 		{
 			string indentation = lineNumber != 0 ? GetIndentation (d, lineNumber - 1) : "";
 			
 			if (indentation.Length > 0) {
-				string newLineText = indentation + TextUtilities.GetLineAsString (d, lineNumber).Trim ();
-				LineSegment oldLine = d.GetLineSegment (lineNumber);
-				d.Replace (oldLine.Offset, oldLine.Length, newLineText);
+				string newLineText = indentation + d.GetLineAsString (lineNumber).Trim ();
+				d.ReplaceLine (lineNumber, newLineText);
 			}
 			
 			return indentation.Length;
@@ -57,7 +53,7 @@
 		/// <summary>
 		/// Could be overwritten to define more complex indenting.
 		/// </summary>
-		protected virtual int SmartIndentLine (IDocument d, int line)
+		protected virtual int SmartIndentLine (IFormattableDocument d, int line)
 		{
 			return AutoIndentLine (d, line); // smart = autoindent in normal texts
 		}
@@ -70,7 +66,7 @@
 		/// of bytes (e.g. the number of bytes inserted before the caret, or
 		/// removed, if this number is negative)
 		/// </returns>
-		public virtual int FormatLine (IDocument d, int line, int cursorOffset, char ch)
+		public virtual int FormatLine (IFormattableDocument d, int line, int cursorOffset, char ch)
 		{
 			if (ch == '\n')
 				return IndentLine (d, line);
@@ -84,9 +80,9 @@
 		/// <returns>
 		/// the number of inserted characters.
 		/// </returns>
-		public int IndentLine (IDocument d, int line)
+		public int IndentLine (IFormattableDocument d, int line)
 		{
-			switch (d.TextEditorProperties.IndentStyle) {
+			switch (d.IndentStyle) {
 				case IndentStyle.Auto  : return AutoIndentLine (d, line);
 				case IndentStyle.Smart : return SmartIndentLine (d, line);
 				case IndentStyle.None  :
@@ -97,17 +93,14 @@
 		/// <summary>
 		/// This function sets the indentlevel in a range of lines.
 		/// </summary>
-		public void IndentLines (IDocument d, int begin, int end)
+		public void IndentLines (IFormattableDocument d, int begin, int end)
 		{
-			int redocounter = 0;
+			d.BeginAtomicUndo ();
 			
-			for (int i = begin; i <= end; ++i) {
-				if (IndentLine(d, i) > 0)
-					++redocounter;
-			}
+			for (int i = begin; i <= end; ++i)
+				IndentLine (d, i);
 			
-			if (redocounter > 0)
-				d.UndoStack.UndoLast(redocounter);
+			d.EndAtomicUndo ();
 		}
 	}
 }

Deleted: trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Document/FormattingStrategy/IFormattingStrategy.cs
===================================================================
--- trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Document/FormattingStrategy/IFormattingStrategy.cs	2004-01-31 21:28:04 UTC (rev 737)
+++ trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Document/FormattingStrategy/IFormattingStrategy.cs	2004-02-01 01:30:26 UTC (rev 738)
@@ -1,43 +0,0 @@
-// <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.Drawing;
-using System.Text;
-
-namespace ICSharpCode.TextEditor.Document {
-	/// <summary>
-	/// This interface handles the auto and smart indenting and formating
-	/// in the document while  you type. Language bindings could overwrite this 
-	/// interface and define their own indentation/formating.
-	/// </summary>
-	public interface IFormattingStrategy {
-		/// <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>
-		int FormatLine (IDocument d, int line, int caretOffset, char charTyped);
-		
-		/// <summary>
-		/// This function sets the indentation level in a specific line
-		/// </summary>
-		/// <returns>
-		/// the number of inserted characters.
-		/// </returns>
-		int IndentLine (IDocument d, int line);
-		
-		/// <summary>
-		/// This function sets the indentlevel in a range of lines.
-		/// </summary>
-		void IndentLines (IDocument d, int begin, int end);
-	}	
-}

Modified: trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Document/IDocument.cs
===================================================================
--- trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Document/IDocument.cs	2004-01-31 21:28:04 UTC (rev 737)
+++ trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Document/IDocument.cs	2004-02-01 01:30:26 UTC (rev 738)
@@ -9,6 +9,7 @@
 using System.Drawing;
 
 using ICSharpCode.TextEditor.Undo;
+using MonoDevelop.EditorBindings.FormattingStrategy;
 
 namespace ICSharpCode.TextEditor.Document
 {
@@ -16,7 +17,7 @@
 	/// This interface represents a container which holds a text sequence and
 	/// all necessary information about it. It is used as the base for a text editor.
 	/// </summary>
-	public interface IDocument
+	public interface IDocument : IFormattableDocument
 	{
 		ITextEditorProperties TextEditorProperties {
 			get;

Modified: trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Document/ITextEditorProperties.cs
===================================================================
--- trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Document/ITextEditorProperties.cs	2004-01-31 21:28:04 UTC (rev 737)
+++ trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Document/ITextEditorProperties.cs	2004-02-01 01:30:26 UTC (rev 738)
@@ -2,6 +2,8 @@
 using System.Drawing;
 using System.Text;
 
+using MonoDevelop.EditorBindings.FormattingStrategy;
+
 namespace ICSharpCode.TextEditor.Document
 {
 	public interface ITextEditorProperties

Modified: trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Gui/TextEditorControlBase.cs
===================================================================
--- trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Gui/TextEditorControlBase.cs	2004-01-31 21:28:04 UTC (rev 737)
+++ trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Gui/TextEditorControlBase.cs	2004-02-01 01:30:26 UTC (rev 738)
@@ -16,6 +16,8 @@
 
 using ICSharpCode.TextEditor.Document;
 using ICSharpCode.TextEditor.Actions;
+
+using MonoDevelop.EditorBindings.FormattingStrategy;
  
 namespace ICSharpCode.TextEditor
 {

Modified: trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Undo/UndoStack.cs
===================================================================
--- trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Undo/UndoStack.cs	2004-01-31 21:28:04 UTC (rev 737)
+++ trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Undo/UndoStack.cs	2004-02-01 01:30:26 UTC (rev 738)
@@ -55,13 +55,16 @@
 			}
 		}
 		
+		public int UndoCount { get { return undostack.Count; } }
+		
 		/// <summary>
 		/// You call this method to pool the last x operations from the undo stack
 		/// to make 1 operation from it.
 		/// </summary>
 		public void UndoLast(int x)
 		{
-			undostack.Push(new UndoQueue(this, x));
+			if (x > 0)
+				undostack.Push(new UndoQueue(this, x));
 		}
 		
 		/// <summary>




More information about the Monodevelop-patches-list mailing list