C# 클래스 AvalonStudio.TextEditor.Document.TextDocument

This class is the main class of the text model. Basically, it is a System.Text.StringBuilder with events.
Thread safety:

However, there is a single method that is thread-safe: CreateSnapshot() (and its overloads).

상속: IDocument, INotifyPropertyChanged
파일 보기 프로젝트 열기: VitalElement/AvalonStudio 1 사용 예제들

공개 메소드들

메소드 설명
BeginUpdate ( ) : void

Begins a group of document changes.

Some events are suspended until EndUpdate is called, and the UndoStack will group all changes into a single action.

Calling BeginUpdate several times increments a counter, only after the appropriate number of EndUpdate calls the events resume their work.

CreateAnchor ( int offset ) : TextAnchor

Creates a new TextAnchor at the specified offset.

CreateDocumentSnapshot ( ) : IDocument
CreateReader ( ) : TextReader
CreateReader ( int offset, int length ) : TextReader
CreateSnapshot ( ) : ITextSource

Creates a snapshot of the current text.

This method returns an immutable snapshot of the document, and may be safely called even when the document's owner thread is concurrently modifying the document.

This special thread-safety guarantee is valid only for TextDocument.CreateSnapshot(), not necessarily for other classes implementing ITextSource.CreateSnapshot().

CreateSnapshot ( int offset, int length ) : ITextSource

Creates a snapshot of a part of the current text.

EndUpdate ( ) : void

Ends a group of document changes.

GetCharAt ( int offset ) : char
GetLineByNumber ( int number ) : DocumentLine

Gets a line by the line number: O(log n)

GetLocation ( int offset ) : TextLocation

Gets the location from an offset.

GetOffset ( TextLocation location ) : int

Gets the offset from a text location.

GetOffset ( int line, int column ) : int

Gets the offset from a text location.

GetText ( ISegment segment ) : string

Retrieves the text for a portion of the document.

GetText ( int offset, int length ) : string
IndexOf ( char c, int startIndex, int count ) : int
IndexOf ( string searchText, int startIndex, int count, System.StringComparison comparisonType ) : int
IndexOfAny ( char anyOf, int startIndex, int count ) : int
Insert ( int offset, ITextSource text ) : void

Inserts 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.

Insert ( int offset, ITextSource text, AnchorMovementType defaultAnchorMovementType ) : void

Inserts text.

Insert ( int offset, string text ) : void

Inserts 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.

Insert ( int offset, string text, AnchorMovementType defaultAnchorMovementType ) : void

Inserts text.

LastIndexOf ( char c, int startIndex, int count ) : int
LastIndexOf ( string searchText, int startIndex, int count, System.StringComparison comparisonType ) : int
Remove ( ISegment segment ) : void

Removes text.

Remove ( int offset, int length ) : void

Removes text.

Replace ( ISegment segment, ITextSource text ) : void

Replaces text.

Replace ( ISegment segment, string text ) : void

Replaces text.

Replace ( int offset, int length, ITextSource text ) : void

Replaces text.

Replace ( int offset, int length, ITextSource text, OffsetChangeMap offsetChangeMap ) : void

Replaces text.

Replace ( int offset, int length, ITextSource text, OffsetChangeMappingType offsetChangeMappingType ) : void

Replaces text.

Replace ( int offset, int length, string text ) : void

Replaces text.

Replace ( int offset, int length, string text, OffsetChangeMap offsetChangeMap ) : void

Replaces text.

Replace ( int offset, int length, string text, OffsetChangeMappingType offsetChangeMappingType ) : void

Replaces text.

RunUpdate ( ) : IDisposable

Immediately calls BeginUpdate(), and returns an IDisposable that calls EndUpdate().

SetOwnerThread ( Thread newOwner ) : void

Transfers ownership of the document to another thread. This method can be used to load a file into a TextDocument on a background thread and then transfer ownership to the UI thread for displaying the document.

The owner can be set to null, which means that no thread can access the document. But, if the document has no owner thread, any thread may take ownership by calling SetOwnerThread.

TextDocument ( ) : System

Create an empty text document.

TextDocument ( IEnumerable initialText ) : System

Create a new text document with the specified initial text.

TextDocument ( ITextSource initialText ) : System

Create a new text document with the specified initial text.

VerifyAccess ( ) : void

Verifies that the current thread is the documents owner thread. Throws an InvalidOperationException if the wrong thread accesses the TextDocument.

The TextDocument class is not thread-safe. A document instance expects to have a single owner thread and will throw an InvalidOperationException when accessed from another thread. It is possible to change the owner thread using the SetOwnerThread method.

WriteTextTo ( TextWriter writer ) : void
WriteTextTo ( TextWriter writer, int offset, int length ) : void

비공개 메소드들

메소드 설명
DebugVerifyAccess ( ) : void
DoReplace ( int offset, int length, ITextSource newText, OffsetChangeMap offsetChangeMap ) : void
FireChangeEvents ( ) : void

Fires TextChanged, TextLengthChanged, LineCountChanged if required.

GetLineByOffset ( int offset ) : DocumentLine
GetLineTreeAsString ( ) : string
GetTextAnchorTreeAsString ( ) : string
GetTextFromTextSource ( ITextSource textSource ) : IEnumerable
IDocument ( ) : IDisposable
IDocument ( int lineNumber ) : IDocumentLine
IDocument ( int offset ) : ITextAnchor
IDocument ( ) : void
IServiceProvider ( Type serviceType ) : object
OnFileNameChanged ( EventArgs e ) : void
OnPropertyChanged ( string propertyName ) : void
ThrowIfRangeInvalid ( int offset, int length ) : void

메소드 상세

BeginUpdate() 공개 메소드

Begins a group of document changes.

Some events are suspended until EndUpdate is called, and the UndoStack will group all changes into a single action.

Calling BeginUpdate several times increments a counter, only after the appropriate number of EndUpdate calls the events resume their work.

public BeginUpdate ( ) : void
리턴 void

CreateAnchor() 공개 메소드

Creates a new TextAnchor at the specified offset.
public CreateAnchor ( int offset ) : TextAnchor
offset int
리턴 TextAnchor

CreateDocumentSnapshot() 공개 메소드

public CreateDocumentSnapshot ( ) : IDocument
리턴 IDocument

CreateReader() 공개 메소드

public CreateReader ( ) : TextReader
리턴 System.IO.TextReader

CreateReader() 공개 메소드

public CreateReader ( int offset, int length ) : TextReader
offset int
length int
리턴 System.IO.TextReader

CreateSnapshot() 공개 메소드

Creates a snapshot of the current text.

This method returns an immutable snapshot of the document, and may be safely called even when the document's owner thread is concurrently modifying the document.

This special thread-safety guarantee is valid only for TextDocument.CreateSnapshot(), not necessarily for other classes implementing ITextSource.CreateSnapshot().

public CreateSnapshot ( ) : ITextSource
리턴 ITextSource

CreateSnapshot() 공개 메소드

Creates a snapshot of a part of the current text.
public CreateSnapshot ( int offset, int length ) : ITextSource
offset int
length int
리턴 ITextSource

EndUpdate() 공개 메소드

Ends a group of document changes.
public EndUpdate ( ) : void
리턴 void

GetCharAt() 공개 메소드

public GetCharAt ( int offset ) : char
offset int
리턴 char

GetLineByNumber() 공개 메소드

Gets a line by the line number: O(log n)
public GetLineByNumber ( int number ) : DocumentLine
number int
리턴 DocumentLine

GetLocation() 공개 메소드

Gets the location from an offset.
public GetLocation ( int offset ) : TextLocation
offset int
리턴 TextLocation

GetOffset() 공개 메소드

Gets the offset from a text location.
public GetOffset ( TextLocation location ) : int
location TextLocation
리턴 int

GetOffset() 공개 메소드

Gets the offset from a text location.
public GetOffset ( int line, int column ) : int
line int
column int
리턴 int

GetText() 공개 메소드

Retrieves the text for a portion of the document.
public GetText ( ISegment segment ) : string
segment ISegment
리턴 string

GetText() 공개 메소드

public GetText ( int offset, int length ) : string
offset int
length int
리턴 string

IndexOf() 공개 메소드

public IndexOf ( char c, int startIndex, int count ) : int
c char
startIndex int
count int
리턴 int

IndexOf() 공개 메소드

public IndexOf ( string searchText, int startIndex, int count, System.StringComparison comparisonType ) : int
searchText string
startIndex int
count int
comparisonType System.StringComparison
리턴 int

IndexOfAny() 공개 메소드

public IndexOfAny ( char anyOf, int startIndex, int count ) : int
anyOf char
startIndex int
count int
리턴 int

Insert() 공개 메소드

Inserts 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.
public Insert ( int offset, ITextSource text ) : void
offset int The offset at which the text is inserted.
text ITextSource The new text.
리턴 void

Insert() 공개 메소드

Inserts text.
public Insert ( int offset, ITextSource text, AnchorMovementType defaultAnchorMovementType ) : void
offset int The offset at which the text is inserted.
text ITextSource The new text.
defaultAnchorMovementType AnchorMovementType /// 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() 공개 메소드

Inserts 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.
public Insert ( int offset, string text ) : void
offset int The offset at which the text is inserted.
text string The new text.
리턴 void

Insert() 공개 메소드

Inserts text.
public Insert ( int offset, string text, AnchorMovementType defaultAnchorMovementType ) : void
offset int The offset at which the text is inserted.
text string The new text.
defaultAnchorMovementType AnchorMovementType /// 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

LastIndexOf() 공개 메소드

public LastIndexOf ( char c, int startIndex, int count ) : int
c char
startIndex int
count int
리턴 int

LastIndexOf() 공개 메소드

public LastIndexOf ( string searchText, int startIndex, int count, System.StringComparison comparisonType ) : int
searchText string
startIndex int
count int
comparisonType System.StringComparison
리턴 int

Remove() 공개 메소드

Removes text.
public Remove ( ISegment segment ) : void
segment ISegment
리턴 void

Remove() 공개 메소드

Removes text.
public Remove ( int offset, int length ) : void
offset int Starting offset of the text to be removed.
length int Length of the text to be removed.
리턴 void

Replace() 공개 메소드

Replaces text.
public Replace ( ISegment segment, ITextSource text ) : void
segment ISegment
text ITextSource
리턴 void

Replace() 공개 메소드

Replaces text.
public Replace ( ISegment segment, string text ) : void
segment ISegment
text string
리턴 void

Replace() 공개 메소드

Replaces text.
public Replace ( int offset, int length, ITextSource text ) : void
offset int The starting offset of the text to be replaced.
length int The length of the text to be replaced.
text ITextSource The new text.
리턴 void

Replace() 공개 메소드

Replaces text.
public Replace ( int offset, int length, ITextSource text, OffsetChangeMap offsetChangeMap ) : void
offset int The starting offset of the text to be replaced.
length int The length of the text to be replaced.
text ITextSource The new text.
offsetChangeMap OffsetChangeMap /// The offsetChangeMap determines how offsets inside the old text are mapped to the new text. /// This affects how the anchors and segments inside the replaced region behave. /// If you pass null (the default when using one of the other overloads), the offsets are changed as /// in OffsetChangeMappingType.Normal mode. /// If you pass OffsetChangeMap.Empty, then everything will stay in its old place /// (OffsetChangeMappingType.CharacterReplace mode). /// The offsetChangeMap must be a valid 'explanation' for the document change. See /// . /// Passing an OffsetChangeMap to the Replace method will automatically freeze it to ensure the thread safety of the /// resulting /// DocumentChangeEventArgs instance. ///
리턴 void

Replace() 공개 메소드

Replaces text.
public Replace ( int offset, int length, ITextSource text, OffsetChangeMappingType offsetChangeMappingType ) : void
offset int The starting offset of the text to be replaced.
length int The length of the text to be replaced.
text ITextSource The new text.
offsetChangeMappingType OffsetChangeMappingType /// The offsetChangeMappingType determines how offsets inside the old text are mapped to the new text. /// This affects how the anchors and segments inside the replaced region behave. ///
리턴 void

Replace() 공개 메소드

Replaces text.
public Replace ( int offset, int length, string text ) : void
offset int The starting offset of the text to be replaced.
length int The length of the text to be replaced.
text string The new text.
리턴 void

Replace() 공개 메소드

Replaces text.
public Replace ( int offset, int length, string text, OffsetChangeMap offsetChangeMap ) : void
offset int The starting offset of the text to be replaced.
length int The length of the text to be replaced.
text string The new text.
offsetChangeMap OffsetChangeMap /// The offsetChangeMap determines how offsets inside the old text are mapped to the new text. /// This affects how the anchors and segments inside the replaced region behave. /// If you pass null (the default when using one of the other overloads), the offsets are changed as /// in OffsetChangeMappingType.Normal mode. /// If you pass OffsetChangeMap.Empty, then everything will stay in its old place /// (OffsetChangeMappingType.CharacterReplace mode). /// The offsetChangeMap must be a valid 'explanation' for the document change. See /// . /// Passing an OffsetChangeMap to the Replace method will automatically freeze it to ensure the thread safety of the /// resulting /// DocumentChangeEventArgs instance. ///
리턴 void

Replace() 공개 메소드

Replaces text.
public Replace ( int offset, int length, string text, OffsetChangeMappingType offsetChangeMappingType ) : void
offset int The starting offset of the text to be replaced.
length int The length of the text to be replaced.
text string The new text.
offsetChangeMappingType OffsetChangeMappingType /// The offsetChangeMappingType determines how offsets inside the old text are mapped to the new text. /// This affects how the anchors and segments inside the replaced region behave. ///
리턴 void

RunUpdate() 공개 메소드

Immediately calls BeginUpdate(), and returns an IDisposable that calls EndUpdate().
public RunUpdate ( ) : IDisposable
리턴 IDisposable

SetOwnerThread() 공개 메소드

Transfers ownership of the document to another thread. This method can be used to load a file into a TextDocument on a background thread and then transfer ownership to the UI thread for displaying the document.

The owner can be set to null, which means that no thread can access the document. But, if the document has no owner thread, any thread may take ownership by calling SetOwnerThread.

public SetOwnerThread ( Thread newOwner ) : void
newOwner Thread
리턴 void

TextDocument() 공개 메소드

Create an empty text document.
public TextDocument ( ) : System
리턴 System

TextDocument() 공개 메소드

Create a new text document with the specified initial text.
public TextDocument ( IEnumerable initialText ) : System
initialText IEnumerable
리턴 System

TextDocument() 공개 메소드

Create a new text document with the specified initial text.
public TextDocument ( ITextSource initialText ) : System
initialText ITextSource
리턴 System

VerifyAccess() 공개 메소드

Verifies that the current thread is the documents owner thread. Throws an InvalidOperationException if the wrong thread accesses the TextDocument.

The TextDocument class is not thread-safe. A document instance expects to have a single owner thread and will throw an InvalidOperationException when accessed from another thread. It is possible to change the owner thread using the SetOwnerThread method.

public VerifyAccess ( ) : void
리턴 void

WriteTextTo() 공개 메소드

public WriteTextTo ( TextWriter writer ) : void
writer System.IO.TextWriter
리턴 void

WriteTextTo() 공개 메소드

public WriteTextTo ( TextWriter writer, int offset, int length ) : void
writer System.IO.TextWriter
offset int
length int
리턴 void