Free cookie consent management tool by TermsFeed Policy Generator

source: branches/CodeEditor/HeuristicLab.ExtLibs/HeuristicLab.NRefactory/5.5.0/NRefactory-5.5.0/Editor/ITextAnchor.cs @ 11700

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

#2077: created branch and added first version

File size: 5.9 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  /// The TextAnchor class references an offset (a position between two characters).
25  /// It automatically updates the offset when text is inserted/removed in front of the anchor.
26  /// </summary>
27  /// <remarks>
28  /// <para>Use the <see cref="ITextAnchor.Offset"/> property to get the offset from a text anchor.
29  /// Use the <see cref="IDocument.CreateAnchor"/> method to create an anchor from an offset.
30  /// </para>
31  /// <para>
32  /// The document will automatically update all text anchors; and because it uses weak references to do so,
33  /// the garbage collector can simply collect the anchor object when you don't need it anymore.
34  /// </para>
35  /// <para>Moreover, the document is able to efficiently update a large number of anchors without having to look
36  /// at each anchor object individually. Updating the offsets of all anchors usually only takes time logarithmic
37  /// to the number of anchors. Retrieving the <see cref="ITextAnchor.Offset"/> property also runs in O(lg N).</para>
38  /// </remarks>
39  /// <example>
40  /// Usage:
41  /// <code>TextAnchor anchor = document.CreateAnchor(offset);
42  /// ChangeMyDocument();
43  /// int newOffset = anchor.Offset;
44  /// </code>
45  /// </example>
46  public interface ITextAnchor
47  {
48    /// <summary>
49    /// Gets the text location of this anchor.
50    /// </summary>
51    /// <exception cref="InvalidOperationException">Thrown when trying to get the Offset from a deleted anchor.</exception>
52    TextLocation Location { get; }
53   
54    /// <summary>
55    /// Gets the offset of the text anchor.
56    /// </summary>
57    /// <exception cref="InvalidOperationException">Thrown when trying to get the Offset from a deleted anchor.</exception>
58    int Offset { get; }
59   
60    /// <summary>
61    /// Controls how the anchor moves.
62    /// </summary>
63    /// <remarks>Anchor movement is ambiguous if text is inserted exactly at the anchor's location.
64    /// Does the anchor stay before the inserted text, or does it move after it?
65    /// The property <see cref="MovementType"/> will be used to determine which of these two options the anchor will choose.
66    /// The default value is <see cref="AnchorMovementType.Default"/>.</remarks>
67    AnchorMovementType MovementType { get; set; }
68   
69    /// <summary>
70    /// <para>
71    /// Specifies whether the anchor survives deletion of the text containing it.
72    /// </para><para>
73    /// <c>false</c>: The anchor is deleted when the a selection that includes the anchor is deleted.
74    /// <c>true</c>: The anchor is not deleted.
75    /// </para>
76    /// </summary>
77    /// <remarks><inheritdoc cref="IsDeleted" /></remarks>
78    bool SurviveDeletion { get; set; }
79   
80    /// <summary>
81    /// Gets whether the anchor was deleted.
82    /// </summary>
83    /// <remarks>
84    /// <para>When a piece of text containing an anchor is removed, then that anchor will be deleted.
85    /// First, the <see cref="IsDeleted"/> property is set to true on all deleted anchors,
86    /// then the <see cref="Deleted"/> events are raised.
87    /// You cannot retrieve the offset from an anchor that has been deleted.</para>
88    /// <para>This deletion behavior might be useful when using anchors for building a bookmark feature,
89    /// but in other cases you want to still be able to use the anchor. For those cases, set <c><see cref="SurviveDeletion"/> = true</c>.</para>
90    /// </remarks>
91    bool IsDeleted { get; }
92   
93    /// <summary>
94    /// Occurs after the anchor was deleted.
95    /// </summary>
96    /// <remarks>
97    /// <inheritdoc cref="IsDeleted" />
98    /// <para>Due to the 'weak reference' nature of text anchors, you will receive
99    /// the Deleted event only while your code holds a reference to the TextAnchor object.
100    /// </para>
101    /// </remarks>
102    event EventHandler Deleted;
103   
104    /// <summary>
105    /// Gets the line number of the anchor.
106    /// </summary>
107    /// <exception cref="InvalidOperationException">Thrown when trying to get the Offset from a deleted anchor.</exception>
108    int Line { get; }
109   
110    /// <summary>
111    /// Gets the column number of this anchor.
112    /// </summary>
113    /// <exception cref="InvalidOperationException">Thrown when trying to get the Offset from a deleted anchor.</exception>
114    int Column { get; }
115  }
116 
117  /// <summary>
118  /// Defines how a text anchor moves.
119  /// </summary>
120  public enum AnchorMovementType
121  {
122    /// <summary>
123    /// When text is inserted at the anchor position, the type of the insertion
124    /// determines where the caret moves to. For normal insertions, the anchor will move
125    /// after the inserted text.
126    /// </summary>
127    Default,
128    /// <summary>
129    /// Behaves like a start marker - when text is inserted at the anchor position, the anchor will stay
130    /// before the inserted text.
131    /// </summary>
132    BeforeInsertion,
133    /// <summary>
134    /// Behave like an end marker - when text is insered at the anchor position, the anchor will move
135    /// after the inserted text.
136    /// </summary>
137    AfterInsertion
138  }
139}
Note: See TracBrowser for help on using the repository browser.