1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
3
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
4
// software and associated documentation files (the "Software"), to deal in the Software
5
// without restriction, including without limitation the rights to use, copy, modify, merge,
6
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7
// to whom the Software is furnished to do so, subject to the following conditions:
9
// The above copyright notice and this permission notice shall be included in all copies or
10
// substantial portions of the Software.
12
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17
// DEALINGS IN THE SOFTWARE.
21
namespace ICSharpCode.NRefactory.Editor
24
/// A document representing a source code file for refactoring.
25
/// Line and column counting starts at 1.
26
/// Offset counting starts at 0.
28
public interface IDocument : ITextSource, IServiceProvider
31
/// Creates an immutable snapshot of this document.
33
IDocument CreateDocumentSnapshot();
36
/// Gets/Sets the text of the whole document..
38
new string Text { get; set; } // hides ITextSource.Text to add the setter
41
/// This event is called directly before a change is applied to the document.
44
/// It is invalid to modify the document within this event handler.
45
/// Aborting the change (by throwing an exception) is likely to cause corruption of data structures
46
/// that listen to the Changing and Changed events.
48
event EventHandler<TextChangeEventArgs> TextChanging;
51
/// This event is called directly after a change is applied to the document.
54
/// It is invalid to modify the document within this event handler.
55
/// Aborting the event handler (by throwing an exception) is likely to cause corruption of data structures
56
/// that listen to the Changing and Changed events.
58
event EventHandler<TextChangeEventArgs> TextChanged;
61
/// This event is called after a group of changes is completed.
63
/// <seealso cref="EndUndoableAction"/>
64
event EventHandler ChangeCompleted;
67
/// Gets the number of lines in the document.
69
int LineCount { get; }
72
/// Gets the document line with the specified number.
74
/// <param name="lineNumber">The number of the line to retrieve. The first line has number 1.</param>
75
IDocumentLine GetLineByNumber(int lineNumber);
78
/// Gets the document line that contains the specified offset.
80
IDocumentLine GetLineByOffset(int offset);
83
/// Gets the offset from a text location.
85
/// <seealso cref="GetLocation"/>
86
int GetOffset(int line, int column);
89
/// Gets the offset from a text location.
91
/// <seealso cref="GetLocation"/>
92
int GetOffset(TextLocation location);
95
/// Gets the location from an offset.
97
/// <seealso cref="GetOffset(TextLocation)"/>
98
TextLocation GetLocation(int offset);
103
/// <param name="offset">The offset at which the text is inserted.</param>
104
/// <param name="text">The new text.</param>
106
/// Anchors positioned exactly at the insertion offset will move according to their movement type.
107
/// For AnchorMovementType.Default, they will move behind the inserted text.
108
/// The caret will also move behind the inserted text.
110
void Insert(int offset, string text);
115
/// <param name="offset">The offset at which the text is inserted.</param>
116
/// <param name="text">The new text.</param>
117
/// <param name="defaultAnchorMovementType">
118
/// Anchors positioned exactly at the insertion offset will move according to the anchor's movement type.
119
/// For AnchorMovementType.Default, they will move according to the movement type specified by this parameter.
120
/// The caret will also move according to the <paramref name="defaultAnchorMovementType"/> parameter.
122
void Insert(int offset, string text, AnchorMovementType defaultAnchorMovementType);
127
/// <param name="offset">Starting offset of the text to be removed.</param>
128
/// <param name="length">Length of the text to be removed.</param>
129
void Remove(int offset, int length);
134
/// <param name="offset">The starting offset of the text to be replaced.</param>
135
/// <param name="length">The length of the text to be replaced.</param>
136
/// <param name="newText">The new text.</param>
137
void Replace(int offset, int length, string newText);
140
/// Make the document combine the following actions into a single
141
/// action for undo purposes.
143
void StartUndoableAction();
146
/// Ends the undoable action started with <see cref="StartUndoableAction"/>.
148
void EndUndoableAction();
151
/// Creates an undo group. Dispose the returned value to close the undo group.
153
/// <returns>An object that closes the undo group when Dispose() is called.</returns>
154
IDisposable OpenUndoGroup();
157
/// Creates a new <see cref="ITextAnchor"/> at the specified offset.
159
/// <inheritdoc cref="ITextAnchor" select="remarks|example"/>
160
ITextAnchor CreateAnchor(int offset);