Browse Source

Add ISegment and ITextEditor interfaces.

newNRvisualizers
Daniel Grunwald 15 years ago
parent
commit
21fcd8262f
  1. 2
      ICSharpCode.Editor/IDocument.cs
  2. 22
      ICSharpCode.Editor/IDocumentLine.cs
  3. 30
      ICSharpCode.Editor/ISegment.cs
  4. 6
      ICSharpCode.Editor/ITextBuffer.cs
  5. 100
      ICSharpCode.Editor/ITextEditor.cs
  6. 63
      ICSharpCode.Editor/LinkedElement.cs
  7. 6
      ICSharpCode.Editor/ReadOnlyDocument.cs
  8. 8
      ICSharpCode.Editor/StringTextBuffer.cs

2
ICSharpCode.Editor/IDocument.cs

@ -59,6 +59,7 @@ namespace ICSharpCode.Editor @@ -59,6 +59,7 @@ namespace ICSharpCode.Editor
/// <remarks>
/// Anchors positioned exactly at the insertion offset will move according to their movement type.
/// For AnchorMovementType.Default, they will move behind the inserted text.
/// The caret will also move behind the inserted text.
/// </remarks>
void Insert(int offset, string text);
@ -70,6 +71,7 @@ namespace ICSharpCode.Editor @@ -70,6 +71,7 @@ namespace ICSharpCode.Editor
/// <param name="defaultAnchorMovementType">
/// Anchors positioned exactly at the insertion offset will move according to the anchor's movement type.
/// For AnchorMovementType.Default, they will move according to the movement type specified by this parameter.
/// The caret will also move according to the <paramref name="defaultAnchorMovementType"/> parameter.
/// </param>
void Insert(int offset, string text, AnchorMovementType defaultAnchorMovementType);

22
ICSharpCode.Editor/IDocumentLine.cs

@ -8,23 +8,8 @@ namespace ICSharpCode.Editor @@ -8,23 +8,8 @@ namespace ICSharpCode.Editor
/// <summary>
/// A line inside a <see cref="IDocument"/>.
/// </summary>
public interface IDocumentLine
public interface IDocumentLine : ISegment
{
/// <summary>
/// Gets the starting offset of the line in the document's text.
/// </summary>
int Offset { get; }
/// <summary>
/// Gets the length of this line (=the number of characters on the line).
/// </summary>
int Length { get; }
/// <summary>
/// Gets the ending offset of the line in the document's text (= Offset + Length).
/// </summary>
int EndOffset { get; }
/// <summary>
/// Gets the length of this line, including the line delimiter.
/// </summary>
@ -41,10 +26,5 @@ namespace ICSharpCode.Editor @@ -41,10 +26,5 @@ namespace ICSharpCode.Editor
/// The first line has the number 1.
/// </summary>
int LineNumber { get; }
/// <summary>
/// Gets the text on this line.
/// </summary>
string Text { get; }
}
}

30
ICSharpCode.Editor/ISegment.cs

@ -0,0 +1,30 @@ @@ -0,0 +1,30 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT license (for details please see \doc\license.txt)
using System;
namespace ICSharpCode.Editor
{
/// <summary>
/// An (Offset,Length)-pair.
/// </summary>
public interface ISegment
{
/// <summary>
/// Gets the start offset of the segment.
/// </summary>
int Offset { get; }
/// <summary>
/// Gets the length of the segment.
/// </summary>
/// <remarks>Must not be negative.</remarks>
int Length { get; }
/// <summary>
/// Gets the end offset of the segment.
/// </summary>
/// <remarks>EndOffset = Offset + Length;</remarks>
int EndOffset { get; }
}
}

6
ICSharpCode.Editor/ITextBuffer.cs

@ -77,6 +77,12 @@ namespace ICSharpCode.Editor @@ -77,6 +77,12 @@ namespace ICSharpCode.Editor
/// it doesn't require creating a String object for the whole document.</remarks>
string GetText(int offset, int length);
/// <summary>
/// Retrieves the text for a portion of the document.
/// </summary>
/// <exception cref="ArgumentOutOfRangeException">offset or length is outside the valid range.</exception>
string GetText(ISegment segment);
/// <summary>
/// Gets the index of the first occurrence of any character in the specified array.
/// </summary>

100
ICSharpCode.Editor/ITextEditor.cs

@ -0,0 +1,100 @@ @@ -0,0 +1,100 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT license (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace ICSharpCode.Editor
{
/// <summary>
/// Interface for text editors.
/// </summary>
public interface ITextEditor : IServiceProvider
{
/// <summary>
/// Gets the document that is being edited.
/// </summary>
IDocument Document { get; }
/// <summary>
/// Gets an object that represents the caret inside this text editor.
/// </summary>
ITextEditorCaret Caret { get; }
/// <summary>
/// Sets the caret to the specified line/column and brings the caret into view.
/// </summary>
void JumpTo(int line, int column);
/// <summary>
/// Gets the start offset of the selection.
/// </summary>
int SelectionStart { get; }
/// <summary>
/// Gets the length of the selection.
/// </summary>
int SelectionLength { get; }
/// <summary>
/// Gets/Sets the selected text.
/// </summary>
string SelectedText { get; set; }
/// <summary>
/// Sets the selection.
/// </summary>
/// <param name="selectionStart">Start offset of the selection</param>
/// <param name="selectionLength">Length of the selection</param>
void Select(int selectionStart, int selectionLength);
/// <summary>
/// Shows the specified linked elements, and allows the user to edit them.
/// </summary>
/// <returns>
/// Returns true when the user has finished editing the elements and pressed Return;
/// or false when editing is aborted for any reason.
/// </returns>
/// <remarks>
/// The user can also edit other parts of the document (or other documents) while in link mode.
/// In case of success (true return value), this method will update the offsets of the linked elements
/// to reflect the changes done by the user.
/// If the text editor does not support link mode, it will immediately return false.
/// </remarks>
Task<bool> ShowLinkedElements(IEnumerable<LinkedElement> linkedElements);
}
/// <summary>
/// Represents the caret in a text editor.
/// </summary>
public interface ITextEditorCaret
{
/// <summary>
/// Gets/Sets the caret offset;
/// </summary>
int Offset { get; set; }
/// <summary>
/// Gets/Sets the caret line number.
/// Line numbers are counted starting from 1.
/// </summary>
int Line { get; set; }
/// <summary>
/// Gets/Sets the caret column number.
/// Column numbers are counted starting from 1.
/// </summary>
int Column { get; set; }
/// <summary>
/// Gets/sets the caret location.
/// </summary>
TextLocation Location { get; set; }
/// <summary>
/// Is raised whenever the location of the caret has changed.
/// </summary>
event EventHandler LocationChanged;
}
}

63
ICSharpCode.Editor/LinkedElement.cs

@ -0,0 +1,63 @@ @@ -0,0 +1,63 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT license (for details please see \doc\license.txt)
using System;
namespace ICSharpCode.Editor
{
/// <summary>
/// Represents an element in the text editor that is either editable, or bound to another editable element.
/// Used with <see cref="ITextEditor.ShowLinkedElements"/>
/// </summary>
public class LinkedElement
{
LinkedElement boundTo;
/// <summary>
/// Gets/Sets the start offset of this linked element.
/// </summary>
public int StartOffset { get; set; }
/// <summary>
/// Gets/Sets the end offset of this linked element.
/// </summary>
public int EndOffset { get; set; }
/// <summary>
/// Gets the linked element to which this element is bound.
/// </summary>
public LinkedElement BoundTo {
get { return boundTo; }
}
/// <summary>
/// Gets whether this element is editable. Returns true if this element is not bound.
/// </summary>
public bool IsEditable {
get { return boundTo == null; }
}
/// <summary>
/// Creates a new editable element.
/// </summary>
public LinkedElement(int startOffset, int endOffset)
{
this.StartOffset = startOffset;
this.EndOffset = endOffset;
}
/// <summary>
/// Creates a new element that is bound to <paramref name="boundTo"/>.
/// </summary>
public LinkedElement(int startOffset, int endOffset, LinkedElement boundTo)
{
if (boundTo == null)
throw new ArgumentNullException("boundTo");
this.StartOffset = startOffset;
this.EndOffset = endOffset;
while (boundTo.boundTo != null)
boundTo = boundTo.boundTo;
this.boundTo = boundTo;
}
}
}

6
ICSharpCode.Editor/ReadOnlyDocument.cs

@ -306,6 +306,12 @@ namespace ICSharpCode.Editor @@ -306,6 +306,12 @@ namespace ICSharpCode.Editor
return textBuffer.GetText(offset, length);
}
/// <inheritdoc/>
public string GetText(ISegment segment)
{
return textBuffer.GetText(segment);
}
/// <inheritdoc/>
public int IndexOfAny(char[] anyOf, int startIndex, int count)
{

8
ICSharpCode.Editor/StringTextBuffer.cs

@ -76,6 +76,14 @@ namespace ICSharpCode.Editor @@ -76,6 +76,14 @@ namespace ICSharpCode.Editor
return text.Substring(offset, length);
}
/// <inheritdoc/>
public string GetText(ISegment segment)
{
if (segment == null)
throw new ArgumentNullException("segment");
return text.Substring(segment.Offset, segment.Length);
}
/// <inheritdoc/>
public int IndexOfAny(char[] anyOf, int startIndex, int count)
{

Loading…
Cancel
Save