// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.IO;
using ICSharpCode.AvalonEdit.Document;
namespace ILSpy.Debugger.AvalonEdit.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);
}
///
/// 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);
}
public sealed class StringTextBuffer : AvalonEditTextSourceAdapter
{
public StringTextBuffer(string text)
: base(new StringTextSource(text))
{
}
}
}