// 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.IO; namespace ICSharpCode.Editor { /// /// A read-only view on a (potentially mutable) text buffer. /// The IDocument interfaces derives from this interface. /// public interface ITextBuffer { /// /// Gets a version identifier for this text buffer. /// Returns null for unversioned text buffers. /// ITextBufferVersion Version { get; } /// /// Creates an immutable snapshot of this text buffer. /// Unlike all other methods in this interface, this method is thread-safe. /// ITextBuffer CreateSnapshot(); /// /// Creates an immutable snapshot of a part of this text buffer. /// Unlike all other methods in this interface, this method is thread-safe. /// ITextBuffer CreateSnapshot(int offset, int length); /// /// Creates a new TextReader to read from this text buffer. /// TextReader CreateReader(); /// /// Creates a new TextReader to read from this text buffer. /// TextReader CreateReader(int offset, int length); /// /// Gets the total text length. /// /// The length of the text, in characters. /// This is the same as Text.Length, but is more efficient because /// it doesn't require creating a String object. int TextLength { get; } /// /// Gets the whole text as string. /// string Text { get; } /// /// Is raised when the Text property changes. /// event EventHandler TextChanged; /// /// Gets a character at the specified position in the document. /// /// The index of the character to get. /// Offset is outside the valid range (0 to TextLength-1). /// The character at the specified position. /// This is the same as Text[offset], but is more efficient because /// it doesn't require creating a String object. char GetCharAt(int offset); /// /// Retrieves the text for a portion of the document. /// /// offset or length is outside the valid range. /// This is the same as Text.Substring, but is more efficient because /// it doesn't require creating a String object for the whole document. string GetText(int offset, int length); /// /// Retrieves the text for a portion of the document. /// /// offset or length is outside the valid range. string GetText(ISegment segment); /// /// Gets the index of the first occurrence of any character in the specified array. /// /// Characters to search for /// Start index of the search. /// Length of the area to search. /// The first index where any character was found; or -1 if no occurrence was found. int IndexOfAny(char[] anyOf, int startIndex, int count); /* What about: void Insert (int offset, string value); void Remove (int offset, int count); void Remove (ISegment segment); void Replace (int offset, int count, string value); Or more search operations: IEnumerable SearchForward (string pattern, int startIndex); IEnumerable SearchForwardIgnoreCase (string pattern, int startIndex); IEnumerable SearchBackward (string pattern, int startIndex); IEnumerable SearchBackwardIgnoreCase (string pattern, int startIndex); */ } /// /// Represents a version identifier for a text buffer. /// /// /// This is SharpDevelop's equivalent to AvalonEdit ChangeTrackingCheckpoint. /// It is used by the ParserService to efficiently detect whether a document has changed and needs reparsing. /// It is a separate class from ITextBuffer to allow the GC to collect the text buffer while the version checkpoint /// is still in use. /// public interface ITextBufferVersion { /// /// Gets whether this checkpoint belongs to the same document as the other checkpoint. /// bool BelongsToSameDocumentAs(ITextBufferVersion other); /// /// Compares the age of this checkpoint to the other checkpoint. /// /// This method is thread-safe. /// Raised if 'other' belongs to a different document than this version. /// -1 if this version is older than . /// 0 if this version instance represents the same version as . /// 1 if this version is newer than . int CompareAge(ITextBufferVersion other); /// /// Gets the changes from this checkpoint to the other checkpoint. /// If 'other' is older than this checkpoint, reverse changes are calculated. /// /// This method is thread-safe. /// Raised if 'other' belongs to a different document than this checkpoint. IEnumerable GetChangesTo(ITextBufferVersion other); /// /// Calculates where the offset has moved in the other buffer version. /// /// Raised if 'other' belongs to a different document than this checkpoint. int MoveOffsetTo(ITextBufferVersion other, int oldOffset, AnchorMovementType movement); } }