// Copyright (c) 2010-2013 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;
namespace ICSharpCode.NRefactory.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
{
///
/// Creates an immutable snapshot of this document.
///
IDocument CreateDocumentSnapshot();
///
/// Gets/Sets the text of the whole document..
///
new string Text { get; set; } // hides ITextSource.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 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, ITextSource 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);
///
/// 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, ITextSource 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);
///
/// 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, ITextSource 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);
///
/// Gets the name of the file the document is stored in.
/// Could also be a non-existent dummy file name or null if no name has been set.
///
string FileName { get; }
///
/// Fired when the file name of the document changes.
///
event EventHandler FileNameChanged;
}
}