Browse Source
			
			
			
			
				
		git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@3205 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
				 22 changed files with 357 additions and 499 deletions
			
			
		@ -1,217 +0,0 @@
				@@ -1,217 +0,0 @@
					 | 
				
			||||
// <file>
 | 
				
			||||
//     <copyright see="prj:///doc/copyright.txt"/>
 | 
				
			||||
//     <license see="prj:///doc/license.txt"/>
 | 
				
			||||
//     <owner name="Ivo Kovacka" email="ivok@internet.sk"/>
 | 
				
			||||
//     <version>$Revision$</version>
 | 
				
			||||
// </file>
 | 
				
			||||
 | 
				
			||||
using System; | 
				
			||||
using System.Collections.Generic; | 
				
			||||
using System.Drawing; | 
				
			||||
 | 
				
			||||
namespace ICSharpCode.TextEditor.Document | 
				
			||||
{ | 
				
			||||
	/// <summary>
 | 
				
			||||
	/// This class is used to store a pair of lineNr and its color
 | 
				
			||||
	/// </summary>
 | 
				
			||||
	public class CustomLine | 
				
			||||
	{ | 
				
			||||
		public int    StartLineNr; | 
				
			||||
		public int    EndLineNr; | 
				
			||||
		public Color  Color; | 
				
			||||
		public bool   ReadOnly; | 
				
			||||
 | 
				
			||||
		public CustomLine(int lineNr, Color customColor, bool readOnly) | 
				
			||||
		{ | 
				
			||||
			this.StartLineNr = this.EndLineNr = lineNr; | 
				
			||||
			this.Color  = customColor; | 
				
			||||
			this.ReadOnly = readOnly; | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		public CustomLine(int startLineNr, int endLineNr, Color customColor, bool readOnly) | 
				
			||||
		{ | 
				
			||||
			this.StartLineNr = startLineNr; | 
				
			||||
			this.EndLineNr = endLineNr; | 
				
			||||
			this.Color  = customColor; | 
				
			||||
			this.ReadOnly = readOnly; | 
				
			||||
		} | 
				
			||||
	} | 
				
			||||
		 | 
				
			||||
	/// <summary>
 | 
				
			||||
	/// This class handles the bookmarks for a buffer
 | 
				
			||||
	/// </summary>
 | 
				
			||||
	public class CustomLineManager : ICustomLineManager | 
				
			||||
	{ | 
				
			||||
		List<CustomLine> lines = new List<CustomLine>(); | 
				
			||||
		 | 
				
			||||
		/// <summary>
 | 
				
			||||
		/// Creates a new instance of <see cref="CustomLineManager"/>
 | 
				
			||||
		/// </summary>
 | 
				
			||||
		internal CustomLineManager(LineManager lineTracker) | 
				
			||||
		{ | 
				
			||||
			lineTracker.LineCountChanged += MoveIndices; | 
				
			||||
		} | 
				
			||||
 | 
				
			||||
		/// <value>
 | 
				
			||||
		/// Contains all custom lines 
 | 
				
			||||
		/// </value>
 | 
				
			||||
		public List<CustomLine> CustomLines { | 
				
			||||
			get { | 
				
			||||
				return lines; | 
				
			||||
			} | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		/// <remarks>
 | 
				
			||||
		/// Returns the Color if the line <code>lineNr</code> has custom bg color
 | 
				
			||||
		/// otherwise returns <code>defaultColor</code>
 | 
				
			||||
		/// </remarks>
 | 
				
			||||
		public Color GetCustomColor(int lineNr, Color defaultColor) | 
				
			||||
		{ | 
				
			||||
			foreach(CustomLine line in lines) | 
				
			||||
				if (line.StartLineNr <= lineNr && line.EndLineNr >= lineNr) | 
				
			||||
					return line.Color; | 
				
			||||
			return defaultColor; | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		/// <remarks>
 | 
				
			||||
		/// Returns the ReadOnly if the line <code>lineNr</code> is custom 
 | 
				
			||||
		/// otherwise returns <code>default</code>
 | 
				
			||||
		/// </remarks>
 | 
				
			||||
		public bool IsReadOnly(int lineNr, bool defaultReadOnly) | 
				
			||||
		{ | 
				
			||||
			foreach(CustomLine line in lines) | 
				
			||||
				if (line.StartLineNr <= lineNr && line.EndLineNr >= lineNr) | 
				
			||||
					return line.ReadOnly; | 
				
			||||
			return defaultReadOnly; | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		/// <remarks>
 | 
				
			||||
		/// Returns true if <code>selection</code> is read only
 | 
				
			||||
		/// </remarks>
 | 
				
			||||
		public bool IsReadOnly(ISelection selection, bool defaultReadOnly) | 
				
			||||
		{ | 
				
			||||
			int startLine = selection.StartPosition.Y; | 
				
			||||
			int endLine = selection.EndPosition.Y; | 
				
			||||
			foreach (CustomLine customLine in lines) { | 
				
			||||
				if (customLine.ReadOnly == false) | 
				
			||||
					continue; | 
				
			||||
				if (startLine < customLine.StartLineNr && endLine < customLine.StartLineNr) | 
				
			||||
					continue; | 
				
			||||
				if (startLine > customLine.EndLineNr && endLine > customLine.EndLineNr) | 
				
			||||
					continue; | 
				
			||||
				return true; | 
				
			||||
			} | 
				
			||||
			return defaultReadOnly; | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		/// <remarks>
 | 
				
			||||
		/// Clears all custom lines
 | 
				
			||||
		/// </remarks>
 | 
				
			||||
		public void Clear() | 
				
			||||
		{ | 
				
			||||
			OnBeforeChanged(); | 
				
			||||
			lines.Clear(); | 
				
			||||
			OnChanged(); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		/// <remarks>
 | 
				
			||||
		/// Is fired before the change
 | 
				
			||||
		/// </remarks>
 | 
				
			||||
		public event EventHandler BeforeChanged; | 
				
			||||
		 | 
				
			||||
		/// <remarks>
 | 
				
			||||
		/// Is fired after the change
 | 
				
			||||
		/// </remarks>
 | 
				
			||||
		public event EventHandler Changed; | 
				
			||||
		 | 
				
			||||
	 | 
				
			||||
		 | 
				
			||||
		void OnChanged()  | 
				
			||||
		{ | 
				
			||||
			if (Changed != null) { | 
				
			||||
				Changed(this, null); | 
				
			||||
			} | 
				
			||||
		} | 
				
			||||
		void OnBeforeChanged()  | 
				
			||||
		{ | 
				
			||||
			if (BeforeChanged != null) { | 
				
			||||
				BeforeChanged(this, null); | 
				
			||||
			} | 
				
			||||
		} | 
				
			||||
			 | 
				
			||||
		/// <remarks>
 | 
				
			||||
		/// Set Custom Line at the line <code>lineNr</code>
 | 
				
			||||
		/// </remarks>
 | 
				
			||||
		public void AddCustomLine(int lineNr, Color customColor, bool readOnly) | 
				
			||||
		{ | 
				
			||||
			OnBeforeChanged(); | 
				
			||||
			lines.Add(new CustomLine(lineNr, customColor, readOnly)); | 
				
			||||
			OnChanged(); | 
				
			||||
		} | 
				
			||||
 | 
				
			||||
		/// <remarks>
 | 
				
			||||
		/// Add Custom Lines from the line <code>startLineNr</code> to the line <code>endLineNr</code>
 | 
				
			||||
		/// </remarks>
 | 
				
			||||
		public void AddCustomLine(int startLineNr, int endLineNr, Color customColor, bool readOnly) | 
				
			||||
		{ | 
				
			||||
			OnBeforeChanged(); | 
				
			||||
			lines.Add(new CustomLine(startLineNr, endLineNr, customColor, readOnly)); | 
				
			||||
			OnChanged(); | 
				
			||||
		} | 
				
			||||
 | 
				
			||||
		/// <remarks>
 | 
				
			||||
		/// Remove Custom Line at the line <code>lineNr</code>
 | 
				
			||||
		/// </remarks>
 | 
				
			||||
		public void RemoveCustomLine(int lineNr) | 
				
			||||
		{ | 
				
			||||
			for (int i = 0; i < lines.Count; ++i) { | 
				
			||||
				if (((CustomLine)lines[i]).StartLineNr <= lineNr && ((CustomLine)lines[i]).EndLineNr >= lineNr) { | 
				
			||||
					OnBeforeChanged(); | 
				
			||||
					lines.RemoveAt(i); | 
				
			||||
					OnChanged(); | 
				
			||||
					return; | 
				
			||||
				} | 
				
			||||
			} | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		/// <summary>
 | 
				
			||||
		/// This method moves all indices from index upward count lines
 | 
				
			||||
		/// (useful for deletion/insertion of text)
 | 
				
			||||
		/// </summary>
 | 
				
			||||
		void MoveIndices(object sender, LineCountChangeEventArgs e) | 
				
			||||
		{ | 
				
			||||
			bool changed = false; | 
				
			||||
			OnBeforeChanged(); | 
				
			||||
			for (int i = 0; i < lines.Count; ++i) { | 
				
			||||
				int startLineNr = ((CustomLine)lines[i]).StartLineNr; | 
				
			||||
				int endLineNr = ((CustomLine)lines[i]).EndLineNr; | 
				
			||||
				if (e.LineStart >= startLineNr && e.LineStart < endLineNr) { | 
				
			||||
					changed = true; | 
				
			||||
					((CustomLine)lines[i]).EndLineNr += e.LinesMoved; | 
				
			||||
				}  | 
				
			||||
				else if (e.LineStart < startLineNr) { | 
				
			||||
					((CustomLine)lines[i]).StartLineNr += e.LinesMoved; | 
				
			||||
					((CustomLine)lines[i]).EndLineNr += e.LinesMoved; | 
				
			||||
				}  | 
				
			||||
				else { | 
				
			||||
				} | 
				
			||||
/* | 
				
			||||
				if (e.LinesMoved < 0 && lineNr == e.LineStart) { | 
				
			||||
					lines.RemoveAt(i); | 
				
			||||
					--i; | 
				
			||||
					changed = true; | 
				
			||||
				} else if (lineNr > e.LineStart + 1 || (e.LinesMoved < 0 && lineNr > e.LineStart))  { | 
				
			||||
					changed = true; | 
				
			||||
					((CustomLine)lines[i]).StartLineNr += e.LinesMoved; | 
				
			||||
					((CustomLine)lines[i]).EndLineNr += e.LinesMoved; | 
				
			||||
				} | 
				
			||||
*/ | 
				
			||||
			} | 
				
			||||
			 | 
				
			||||
			if (changed) { | 
				
			||||
				OnChanged(); | 
				
			||||
			} | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
	} | 
				
			||||
} | 
				
			||||
@ -1,72 +0,0 @@
				@@ -1,72 +0,0 @@
					 | 
				
			||||
// <file>
 | 
				
			||||
//     <copyright see="prj:///doc/copyright.txt"/>
 | 
				
			||||
//     <license see="prj:///doc/license.txt"/>
 | 
				
			||||
//     <owner name="Ivo Kovacka" email="ivok@internet.sk"/>
 | 
				
			||||
//     <version>$Revision$</version>
 | 
				
			||||
// </file>
 | 
				
			||||
 | 
				
			||||
using System; | 
				
			||||
using System.Collections.Generic; | 
				
			||||
using System.Drawing; | 
				
			||||
 | 
				
			||||
namespace ICSharpCode.TextEditor.Document | 
				
			||||
{ | 
				
			||||
	/// <summary>
 | 
				
			||||
	/// This class handles the custom lines for a buffer
 | 
				
			||||
	/// </summary>
 | 
				
			||||
	public interface ICustomLineManager | 
				
			||||
	{ | 
				
			||||
		/// <value>
 | 
				
			||||
		/// Contains all custom lines 
 | 
				
			||||
		/// </value>
 | 
				
			||||
		List<CustomLine> CustomLines { | 
				
			||||
			get; | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		/// <remarks>
 | 
				
			||||
		/// Returns the Color if the line <code>lineNr</code> has custom bg color
 | 
				
			||||
		/// otherwise returns <code>defaultColor</code>
 | 
				
			||||
		/// </remarks>
 | 
				
			||||
		Color GetCustomColor(int lineNr, Color defaultColor); | 
				
			||||
		 | 
				
			||||
		/// <remarks>
 | 
				
			||||
		/// Returns true if the line <code>lineNr</code> is read only
 | 
				
			||||
		/// </remarks>
 | 
				
			||||
		bool IsReadOnly(int lineNr, bool defaultReadOnly); | 
				
			||||
 | 
				
			||||
		/// <remarks>
 | 
				
			||||
		/// Returns true if <code>selection</code> is read only
 | 
				
			||||
		/// </remarks>
 | 
				
			||||
		bool IsReadOnly(ISelection selection, bool defaultReadOnly); | 
				
			||||
 | 
				
			||||
		/// <remarks>
 | 
				
			||||
		/// Add Custom Line at the line <code>lineNr</code>
 | 
				
			||||
		/// </remarks>
 | 
				
			||||
		void AddCustomLine(int lineNr, Color customColor, bool readOnly); | 
				
			||||
		 | 
				
			||||
		/// <remarks>
 | 
				
			||||
		/// Add Custom Lines from the line <code>startLineNr</code> to the line <code>endLineNr</code>
 | 
				
			||||
		/// </remarks>
 | 
				
			||||
		void AddCustomLine(int startLineNr,  int endLineNr, Color customColor, bool readOnly); | 
				
			||||
		 | 
				
			||||
		/// <remarks>
 | 
				
			||||
		/// Remove Custom Line at the line <code>lineNr</code>
 | 
				
			||||
		/// </remarks>
 | 
				
			||||
		void RemoveCustomLine(int lineNr); | 
				
			||||
		 | 
				
			||||
		/// <remarks>
 | 
				
			||||
		/// Clears all custom color lines
 | 
				
			||||
		/// </remarks>
 | 
				
			||||
		void Clear(); | 
				
			||||
		 | 
				
			||||
		/// <remarks>
 | 
				
			||||
		/// Is fired before the change
 | 
				
			||||
		/// </remarks>
 | 
				
			||||
		event EventHandler BeforeChanged; | 
				
			||||
		 | 
				
			||||
		/// <remarks>
 | 
				
			||||
		/// Is fired after the change
 | 
				
			||||
		/// </remarks>
 | 
				
			||||
		event EventHandler Changed; | 
				
			||||
	} | 
				
			||||
} | 
				
			||||
@ -0,0 +1,165 @@
				@@ -0,0 +1,165 @@
					 | 
				
			||||
// <file>
 | 
				
			||||
//     <copyright see="prj:///doc/copyright.txt"/>
 | 
				
			||||
//     <license see="prj:///doc/license.txt"/>
 | 
				
			||||
//     <author name="Daniel Grunwald"/>
 | 
				
			||||
//     <version>$Revision$</version>
 | 
				
			||||
// </file>
 | 
				
			||||
 | 
				
			||||
using ICSharpCode.TextEditor.Document; | 
				
			||||
using System; | 
				
			||||
using NUnit.Framework; | 
				
			||||
using NUnit.Framework.SyntaxHelpers; | 
				
			||||
 | 
				
			||||
namespace ICSharpCode.TextEditor.Tests | 
				
			||||
{ | 
				
			||||
	[TestFixture] | 
				
			||||
	public class TextMarkerTests | 
				
			||||
	{ | 
				
			||||
		IDocument document; | 
				
			||||
		TextMarker marker; | 
				
			||||
		 | 
				
			||||
		[SetUp] | 
				
			||||
		public void SetUp() | 
				
			||||
		{ | 
				
			||||
			document = new DocumentFactory().CreateDocument(); | 
				
			||||
			document.TextContent = "0123456789"; | 
				
			||||
			marker = new TextMarker(3, 3, TextMarkerType.Underlined); | 
				
			||||
			document.MarkerStrategy.AddMarker(marker); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		[Test] | 
				
			||||
		public void RemoveTextBeforeMarker() | 
				
			||||
		{ | 
				
			||||
			document.Remove(1, 1); | 
				
			||||
			Assert.AreEqual(1, document.MarkerStrategy.GetMarkers(0, document.TextLength).Count); | 
				
			||||
			Assert.AreEqual("345", document.GetText(marker)); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		[Test] | 
				
			||||
		public void RemoveTextImmediatelyBeforeMarker() | 
				
			||||
		{ | 
				
			||||
			document.Remove(2, 1); | 
				
			||||
			Assert.AreEqual(1, document.MarkerStrategy.GetMarkers(0, document.TextLength).Count); | 
				
			||||
			Assert.AreEqual("345", document.GetText(marker)); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		[Test] | 
				
			||||
		public void RemoveTextBeforeMarkerIntoMarker() | 
				
			||||
		{ | 
				
			||||
			document.Remove(2, 2); | 
				
			||||
			Assert.AreEqual(1, document.MarkerStrategy.GetMarkers(0, document.TextLength).Count); | 
				
			||||
			Assert.AreEqual("45", document.GetText(marker)); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		[Test] | 
				
			||||
		public void RemoveTextBeforeMarkerUntilMarkerEnd() | 
				
			||||
		{ | 
				
			||||
			document.Remove(2, 4); | 
				
			||||
			Assert.AreEqual(0, document.MarkerStrategy.GetMarkers(0, document.TextLength).Count); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		[Test] | 
				
			||||
		public void RemoveTextBeforeMarkerOverMarkerEnd() | 
				
			||||
		{ | 
				
			||||
			document.Remove(2, 5); | 
				
			||||
			Assert.AreEqual(0, document.MarkerStrategy.GetMarkers(0, document.TextLength).Count); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		[Test] | 
				
			||||
		public void RemoveTextFromMarkerStartIntoMarker() | 
				
			||||
		{ | 
				
			||||
			document.Remove(3, 1); | 
				
			||||
			Assert.AreEqual(1, document.MarkerStrategy.GetMarkers(0, document.TextLength).Count); | 
				
			||||
			Assert.AreEqual("45", document.GetText(marker)); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		[Test] | 
				
			||||
		public void RemoveTextFromMarkerStartUntilMarkerEnd() | 
				
			||||
		{ | 
				
			||||
			document.Remove(3, 3); | 
				
			||||
			Assert.AreEqual(0, document.MarkerStrategy.GetMarkers(0, document.TextLength).Count); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		[Test] | 
				
			||||
		public void RemoveTextFromMarkerStartOverMarkerEnd() | 
				
			||||
		{ | 
				
			||||
			document.Remove(3, 4); | 
				
			||||
			Assert.AreEqual(0, document.MarkerStrategy.GetMarkers(0, document.TextLength).Count); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		[Test] | 
				
			||||
		public void RemoveTextInsideMarker() | 
				
			||||
		{ | 
				
			||||
			document.Remove(4, 1); | 
				
			||||
			Assert.AreEqual(1, document.MarkerStrategy.GetMarkers(0, document.TextLength).Count); | 
				
			||||
			Assert.AreEqual("35", document.GetText(marker)); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		[Test] | 
				
			||||
		public void RemoveTextInsideMarkerUntilMarkerEnd() | 
				
			||||
		{ | 
				
			||||
			document.Remove(4, 2); | 
				
			||||
			Assert.AreEqual(1, document.MarkerStrategy.GetMarkers(0, document.TextLength).Count); | 
				
			||||
			Assert.AreEqual("3", document.GetText(marker)); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		[Test] | 
				
			||||
		public void RemoveTextInsideMarkerOverMarkerEnd() | 
				
			||||
		{ | 
				
			||||
			document.Remove(4, 3); | 
				
			||||
			Assert.AreEqual(1, document.MarkerStrategy.GetMarkers(0, document.TextLength).Count); | 
				
			||||
			Assert.AreEqual("3", document.GetText(marker)); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		[Test] | 
				
			||||
		public void RemoveTextImmediatelyAfterMarker() | 
				
			||||
		{ | 
				
			||||
			document.Remove(6, 1); | 
				
			||||
			Assert.AreEqual(1, document.MarkerStrategy.GetMarkers(0, document.TextLength).Count); | 
				
			||||
			Assert.AreEqual("345", document.GetText(marker)); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		[Test] | 
				
			||||
		public void RemoveTextAfterMarker() | 
				
			||||
		{ | 
				
			||||
			document.Remove(7, 1); | 
				
			||||
			Assert.AreEqual(1, document.MarkerStrategy.GetMarkers(0, document.TextLength).Count); | 
				
			||||
			Assert.AreEqual("345", document.GetText(marker)); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		[Test] | 
				
			||||
		public void InsertTextBeforeMarker() | 
				
			||||
		{ | 
				
			||||
			document.Insert(1, "ab"); | 
				
			||||
			Assert.AreEqual("345", document.GetText(marker)); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		[Test] | 
				
			||||
		public void InsertTextImmediatelyBeforeMarker() | 
				
			||||
		{ | 
				
			||||
			document.Insert(3, "ab"); | 
				
			||||
			Assert.AreEqual("345", document.GetText(marker)); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		[Test] | 
				
			||||
		public void InsertTextInsideMarker() | 
				
			||||
		{ | 
				
			||||
			document.Insert(4, "ab"); | 
				
			||||
			Assert.AreEqual("3ab45", document.GetText(marker)); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		[Test] | 
				
			||||
		public void InsertTextImmediatelyAfterMarker() | 
				
			||||
		{ | 
				
			||||
			document.Insert(6, "ab"); | 
				
			||||
			Assert.AreEqual("345", document.GetText(marker)); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		[Test] | 
				
			||||
		public void InsertTextAfterMarker() | 
				
			||||
		{ | 
				
			||||
			document.Insert(7, "ab"); | 
				
			||||
			Assert.AreEqual("345", document.GetText(marker)); | 
				
			||||
		} | 
				
			||||
	} | 
				
			||||
} | 
				
			||||
					Loading…
					
					
				
		Reference in new issue