Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.ExtLibs/HeuristicLab.NRefactory/5.5.0/NRefactory-5.5.0/Editor/IDocument.cs @ 17120

Last change on this file since 17120 was 11700, checked in by jkarder, 10 years ago

#2077: created branch and added first version

File size: 7.8 KB
Line 
1// Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
2//
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:
8//
9// The above copyright notice and this permission notice shall be included in all copies or
10// substantial portions of the Software.
11//
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.
18
19using System;
20
21namespace ICSharpCode.NRefactory.Editor
22{
23  /// <summary>
24  /// A document representing a source code file for refactoring.
25  /// Line and column counting starts at 1.
26  /// Offset counting starts at 0.
27  /// </summary>
28  public interface IDocument : ITextSource, IServiceProvider
29  {
30    /// <summary>
31    /// Creates an immutable snapshot of this document.
32    /// </summary>
33    IDocument CreateDocumentSnapshot();
34   
35    /// <summary>
36    /// Gets/Sets the text of the whole document..
37    /// </summary>
38    new string Text { get; set; } // hides ITextSource.Text to add the setter
39   
40    /// <summary>
41    /// This event is called directly before a change is applied to the document.
42    /// </summary>
43    /// <remarks>
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.
47    /// </remarks>
48    event EventHandler<TextChangeEventArgs> TextChanging;
49   
50    /// <summary>
51    /// This event is called directly after a change is applied to the document.
52    /// </summary>
53    /// <remarks>
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.
57    /// </remarks>
58    event EventHandler<TextChangeEventArgs> TextChanged;
59   
60    /// <summary>
61    /// This event is called after a group of changes is completed.
62    /// </summary>
63    /// <seealso cref="EndUndoableAction"/>
64    event EventHandler ChangeCompleted;
65   
66    /// <summary>
67    /// Gets the number of lines in the document.
68    /// </summary>
69    int LineCount { get; }
70   
71    /// <summary>
72    /// Gets the document line with the specified number.
73    /// </summary>
74    /// <param name="lineNumber">The number of the line to retrieve. The first line has number 1.</param>
75    IDocumentLine GetLineByNumber(int lineNumber);
76   
77    /// <summary>
78    /// Gets the document line that contains the specified offset.
79    /// </summary>
80    IDocumentLine GetLineByOffset(int offset);
81   
82    /// <summary>
83    /// Gets the offset from a text location.
84    /// </summary>
85    /// <seealso cref="GetLocation"/>
86    int GetOffset(int line, int column);
87   
88    /// <summary>
89    /// Gets the offset from a text location.
90    /// </summary>
91    /// <seealso cref="GetLocation"/>
92    int GetOffset(TextLocation location);
93   
94    /// <summary>
95    /// Gets the location from an offset.
96    /// </summary>
97    /// <seealso cref="GetOffset(TextLocation)"/>
98    TextLocation GetLocation(int offset);
99   
100    /// <summary>
101    /// Inserts text.
102    /// </summary>
103    /// <param name="offset">The offset at which the text is inserted.</param>
104    /// <param name="text">The new text.</param>
105    /// <remarks>
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.
109    /// </remarks>
110    void Insert(int offset, string text);
111   
112    /// <summary>
113    /// Inserts text.
114    /// </summary>
115    /// <param name="offset">The offset at which the text is inserted.</param>
116    /// <param name="text">The new text.</param>
117    /// <remarks>
118    /// Anchors positioned exactly at the insertion offset will move according to their movement type.
119    /// For AnchorMovementType.Default, they will move behind the inserted text.
120    /// The caret will also move behind the inserted text.
121    /// </remarks>
122    void Insert(int offset, ITextSource text);
123   
124    /// <summary>
125    /// Inserts text.
126    /// </summary>
127    /// <param name="offset">The offset at which the text is inserted.</param>
128    /// <param name="text">The new text.</param>
129    /// <param name="defaultAnchorMovementType">
130    /// Anchors positioned exactly at the insertion offset will move according to the anchor's movement type.
131    /// For AnchorMovementType.Default, they will move according to the movement type specified by this parameter.
132    /// The caret will also move according to the <paramref name="defaultAnchorMovementType"/> parameter.
133    /// </param>
134    void Insert(int offset, string text, AnchorMovementType defaultAnchorMovementType);
135   
136    /// <summary>
137    /// Inserts text.
138    /// </summary>
139    /// <param name="offset">The offset at which the text is inserted.</param>
140    /// <param name="text">The new text.</param>
141    /// <param name="defaultAnchorMovementType">
142    /// Anchors positioned exactly at the insertion offset will move according to the anchor's movement type.
143    /// For AnchorMovementType.Default, they will move according to the movement type specified by this parameter.
144    /// The caret will also move according to the <paramref name="defaultAnchorMovementType"/> parameter.
145    /// </param>
146    void Insert(int offset, ITextSource text, AnchorMovementType defaultAnchorMovementType);
147   
148    /// <summary>
149    /// Removes text.
150    /// </summary>
151    /// <param name="offset">Starting offset of the text to be removed.</param>
152    /// <param name="length">Length of the text to be removed.</param>
153    void Remove(int offset, int length);
154   
155    /// <summary>
156    /// Replaces text.
157    /// </summary>
158    /// <param name="offset">The starting offset of the text to be replaced.</param>
159    /// <param name="length">The length of the text to be replaced.</param>
160    /// <param name="newText">The new text.</param>
161    void Replace(int offset, int length, string newText);
162   
163    /// <summary>
164    /// Replaces text.
165    /// </summary>
166    /// <param name="offset">The starting offset of the text to be replaced.</param>
167    /// <param name="length">The length of the text to be replaced.</param>
168    /// <param name="newText">The new text.</param>
169    void Replace(int offset, int length, ITextSource newText);
170   
171    /// <summary>
172    /// Make the document combine the following actions into a single
173    /// action for undo purposes.
174    /// </summary>
175    void StartUndoableAction();
176   
177    /// <summary>
178    /// Ends the undoable action started with <see cref="StartUndoableAction"/>.
179    /// </summary>
180    void EndUndoableAction();
181   
182    /// <summary>
183    /// Creates an undo group. Dispose the returned value to close the undo group.
184    /// </summary>
185    /// <returns>An object that closes the undo group when Dispose() is called.</returns>
186    IDisposable OpenUndoGroup();
187   
188    /// <summary>
189    /// Creates a new <see cref="ITextAnchor"/> at the specified offset.
190    /// </summary>
191    /// <inheritdoc cref="ITextAnchor" select="remarks|example"/>
192    ITextAnchor CreateAnchor(int offset);
193   
194    /// <summary>
195    /// Gets the name of the file the document is stored in.
196    /// Could also be a non-existent dummy file name or null if no name has been set.
197    /// </summary>
198    string FileName { get; }
199   
200    /// <summary>
201    /// Fired when the file name of the document changes.
202    /// </summary>
203    event EventHandler FileNameChanged;
204  }
205}
Note: See TracBrowser for help on using the repository browser.