Free cookie consent management tool by TermsFeed Policy Generator

source: branches/crossvalidation-2434/HeuristicLab.ExtLibs/HeuristicLab.AvalonEdit/5.0.1/AvalonEdit-5.0.1/Document/ITextAnchor.cs @ 13042

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

#2077: created branch and added first version

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