// 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
{
///
/// A document representing a source code file for refactoring.
/// Line and column counting starts at 1.
/// Offset counting starts at 0.
///
public interface IDocument : ITextSource, IServiceProvider
{
///
/// Gets/Sets the text of the whole document..
///
new string Text { get; set; } // hides TextBuffer.Text to add the setter
///
/// This event is called directly before a change is applied to the document.
///
///
/// It is invalid to modify the document within this event handler.
/// Aborting the change (by throwing an exception) is likely to cause corruption of data structures
/// that listen to the Changing and Changed events.
///
event EventHandler TextChanging;
///
/// This event is called directly after a change is applied to the document.
///
///
/// It is invalid to modify the document within this event handler.
/// Aborting the event handler (by throwing an exception) is likely to cause corruption of data structures
/// that listen to the Changing and Changed events.
///
event EventHandler TextChanged;
///
/// This event is called after a group of changes is completed.
///
///
event EventHandler ChangeCompleted;
///
/// Gets the number of lines in the document.
///
int LineCount { get; }
///
/// Gets the document line with the specified number.
///
/// The number of the line to retrieve. The first line has number 1.
IDocumentLine GetLineByNumber(int lineNumber);
///
/// Gets the document line that contains the specified offset.
///
IDocumentLine GetLineByOffset(int offset);
///
/// Gets the offset from a text location.
///
///
int GetOffset(int line, int column);
///
/// Gets the offset from a text location.
///
///
int GetOffset(TextLocation location);
///
/// Gets the location from an offset.
///
///
TextLocation GetLocation(int offset);
///
/// Inserts text.
///
/// The offset at which the text is inserted.
/// The new text.
///
/// 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.
///
void Insert(int offset, string text);
///
/// Inserts text.
///
/// The offset at which the text is inserted.
/// The new text.
///
/// 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 parameter.
///
void Insert(int offset, string text, AnchorMovementType defaultAnchorMovementType);
///
/// Removes text.
///
/// Starting offset of the text to be removed.
/// Length of the text to be removed.
void Remove(int offset, int length);
///
/// Replaces text.
///
/// The starting offset of the text to be replaced.
/// The length of the text to be replaced.
/// The new text.
void Replace(int offset, int length, string newText);
///
/// Make the document combine the following actions into a single
/// action for undo purposes.
///
void StartUndoableAction();
///
/// Ends the undoable action started with .
///
void EndUndoableAction();
///
/// Creates an undo group. Dispose the returned value to close the undo group.
///
/// An object that closes the undo group when Dispose() is called.
IDisposable OpenUndoGroup();
///
/// Creates a new at the specified offset.
///
///
ITextAnchor CreateAnchor(int offset);
}
}