ITextDocument Interface
Provides the base requirements for a text document that provides access to the ITextSnapshot (via CurrentSnapshot) that contains the current text of the document, and allows for text modification.
public interface ITextDocument
Properties
AutoCharacterCasing
Indicates how to modify the case of text that is inserted into the document.
CharacterCasing AutoCharacterCasing { get; set; }
Property Value
- CharacterCasing:
A CharacterCasing indicating the desired case of inserted text.
AutoConvertTabsToSpaces
Indicates whether to convert tabs to spaces when the Tab key is pressed or indenting occurs.
bool AutoConvertTabsToSpaces { get; set; }
Property Value
- bool:
trueif tabs should be converted to spaces when the Tab key is pressed or indenting occurs; otherwise,false. The default value isfalse.
Remarks
The number of spaces inserted is indicated by the TabSize property.
CurrentSnapshot
The ITextSnapshot that contains the current text of the document.
FileName
The name of the file currently loaded in the document.
string? FileName { get; set; }
Property Value
Remarks
This property is automatically set whenever a LoadFile(string, Encoding?) overload is called that accepts a file path.
IsModified
Indicates whether the document has been modified.
bool IsModified { get; set; }
Property Value
- bool:
trueif the document has been modified; otherwise,false.
Remarks
This flag is reset to false when the ActiproSoftware.Text property is set, or when a SaveFile(string, Encoding?, LineTerminator?)
overload is used that accepts a path matching the current FileName property value.
IsReadOnly
Indicates whether the entire document is flagged as read-only.
bool IsReadOnly { get; set; }
Property Value
- bool:
trueif the entire document is flagged as read-only; otherwise,false. The default value isfalse.
Remarks
When read-only, the document's contents should not be editable.
TabSize
The distance in spaces between tab stops.
UndoHistory
An IUndoHistory that provides access to undo and redo functionality for the document.
Methods
AddTextChangedEventHandler(EventHandler<TextSnapshotChangedEventArgs>, EventHandlerPriority)
Adds an event handler for the TextChanged event using the specified priority level.
void AddTextChangedEventHandler(EventHandler<TextSnapshotChangedEventArgs> handler, EventHandlerPriority priority)
| Parameter | Type | Description |
|---|---|---|
| handler | EventHandler<TextSnapshotChangedEventArgs> | The delegate handler. |
| priority | EventHandlerPriority | A EventHandlerPriority specifying the priority level. |
AddTextChangingEventHandler(EventHandler<TextSnapshotChangingEventArgs>, EventHandlerPriority)
Adds an event handler for the TextChanging event using the specified priority level.
void AddTextChangingEventHandler(EventHandler<TextSnapshotChangingEventArgs> handler, EventHandlerPriority priority)
| Parameter | Type | Description |
|---|---|---|
| handler | EventHandler<TextSnapshotChangingEventArgs> | The delegate handler. |
| priority | EventHandlerPriority | A EventHandlerPriority specifying the priority level. |
AppendText(ITextChangeType, string, ITextChangeOptions?)
Appends text to the end of the CurrentSnapshot text and allows for the specification of other options.
bool AppendText(ITextChangeType type, string text, ITextChangeOptions? options = null)
| Parameter | Type | Description |
|---|---|---|
| type | ITextChangeType | An ITextChangeType specifying the type of change. |
| text | string | The text to append to the current contents of the snapshot. |
| options | ITextChangeOptions | The optional ITextChangeOptions for the change. |
Returns
- bool:
trueif a text change was allowed to occur; otherwise,false.
Remarks
This method creates an ITextChange for the current snapshot, adds an append operation, and immediately applies it. If you will be executing multiple text change operations in a row, for improved performance it is recommended that you call the CreateTextChange(ITextChangeType, ITextChangeOptions?) method instead, add operations to the returned ITextChange, and then apply the text change.
See Also
CreateTextChange(ITextChangeType, ITextChangeOptions?)
Creates an ITextChange based on the CurrentSnapshot, whereby any following calls to methods such as ITextChange.ReplaceText(int, int, string) are grouped into the text change as operations and sequentially executed upon a ITextChange.Apply() call.
ITextChange CreateTextChange(ITextChangeType type, ITextChangeOptions? options = null)
| Parameter | Type | Description |
|---|---|---|
| type | ITextChangeType | An ITextChangeType specifying the type of change. |
| options | ITextChangeOptions | The optional ITextChangeOptions for the change. |
Returns
- ITextChange:
The ITextChange that was created.
Remarks
The ITextChange.Apply() method must be called to apply the queued operations to the document.
DeleteText(ITextChangeType, TextRange, ITextChangeOptions?)
Performs a delete text change in the CurrentSnapshot and allows for the specification of other options.
bool DeleteText(ITextChangeType type, TextRange textRange, ITextChangeOptions? options = null)
| Parameter | Type | Description |
|---|---|---|
| type | ITextChangeType | An ITextChangeType specifying the type of change. |
| textRange | TextRange | The TextRange of offsets to delete. |
| options | ITextChangeOptions | The optional ITextChangeOptions for the change. |
Returns
- bool:
trueif a text change was allowed to occur; otherwise,false.
Remarks
This method creates an ITextChange for the current snapshot, adds a delete operation, and immediately applies it. If you will be executing multiple text change operations in a row, for improved performance it is recommended that you call the CreateTextChange(ITextChangeType, ITextChangeOptions?) method instead, add operations to the returned ITextChange, and then apply the text change.
See Also
DeleteText(ITextChangeType, int, int, ITextChangeOptions?)
Performs a delete text change in the CurrentSnapshot and allows for the specification of other options.
bool DeleteText(ITextChangeType type, int offset, int length, ITextChangeOptions? options = null)
| Parameter | Type | Description |
|---|---|---|
| type | ITextChangeType | An ITextChangeType specifying the type of change. |
| offset | int | The starting offset at which to delete. |
| length | int | The number of characters to delete. |
| options | ITextChangeOptions | The optional ITextChangeOptions for the change. |
Returns
- bool:
trueif a text change was allowed to occur; otherwise,false.
Remarks
This method creates an ITextChange for the current snapshot, adds a delete operation, and immediately applies it. If you will be executing multiple text change operations in a row, for improved performance it is recommended that you call the CreateTextChange(ITextChangeType, ITextChangeOptions?) method instead, add operations to the returned ITextChange, and then apply the text change.
See Also
InsertText(ITextChangeType, int, string, ITextChangeOptions?)
Performs an insert text change in the CurrentSnapshot at the specified offset and allows for the specification of other options.
bool InsertText(ITextChangeType type, int offset, string text, ITextChangeOptions? options = null)
| Parameter | Type | Description |
|---|---|---|
| type | ITextChangeType | An ITextChangeType specifying the type of change. |
| offset | int | The offset at which to insert. |
| text | string | The text to insert. |
| options | ITextChangeOptions | The optional ITextChangeOptions for the change. |
Returns
- bool:
trueif a text change was allowed to occur; otherwise,false.
Remarks
This method creates an ITextChange for the current snapshot, adds an insert operation, and immediately applies it. If you will be executing multiple text change operations in a row, for improved performance it is recommended that you call the CreateTextChange(ITextChangeType, ITextChangeOptions?) method instead, add operations to the returned ITextChange, and then apply the text change.
See Also
IsTextRangeReadOnly(TextRange)
Indicates whether any character in the specified TextRange is flagged as read-only.
bool IsTextRangeReadOnly(TextRange textRange)
| Parameter | Type | Description |
|---|---|---|
| textRange | TextRange | The TextRange to examine. |
Returns
LoadFile(Stream, Encoding)
Loads document text from a Stream using the specified encoding.
void LoadFile(Stream stream, Encoding encoding)
| Parameter | Type | Description |
|---|---|---|
| stream | Stream | The Stream from which to load. |
| encoding | Encoding | The Encoding to use when loading the file. |
LoadFile(string, Encoding?)
Loads document text from a file, optionally using a specified encoding.
void LoadFile(string path, Encoding? encoding = null)
| Parameter | Type | Description |
|---|---|---|
| path | string | The full path of the file from which to load. |
| encoding | Encoding | The optional Encoding to use when loading the file, falling back to a default UTF-8 character encoding when not specified. |
Remarks
This method updates the value of the FileName property.
NormalizeLineTerminators(LineTerminator, ITextChangeOptions?)
Normalizes the document's line terminators to the specified LineTerminator.
void NormalizeLineTerminators(LineTerminator targetLineTerminator, ITextChangeOptions? options = null)
| Parameter | Type | Description |
|---|---|---|
| targetLineTerminator | LineTerminator | The LineTerminator to use for normalization. |
| options | ITextChangeOptions | The optional ITextChangeOptions for the change. |
RemoveTextChangedEventHandler(EventHandler<TextSnapshotChangedEventArgs>, EventHandlerPriority)
Removes an event handler for the TextChanged event using the specified priority level.
void RemoveTextChangedEventHandler(EventHandler<TextSnapshotChangedEventArgs> handler, EventHandlerPriority priority)
| Parameter | Type | Description |
|---|---|---|
| handler | EventHandler<TextSnapshotChangedEventArgs> | The delegate handler. |
| priority | EventHandlerPriority | A EventHandlerPriority specifying the priority level. |
RemoveTextChangingEventHandler(EventHandler<TextSnapshotChangingEventArgs>, EventHandlerPriority)
Removes an event handler for the TextChanging event using the specified priority level.
void RemoveTextChangingEventHandler(EventHandler<TextSnapshotChangingEventArgs> handler, EventHandlerPriority priority)
| Parameter | Type | Description |
|---|---|---|
| handler | EventHandler<TextSnapshotChangingEventArgs> | The delegate handler. |
| priority | EventHandlerPriority | A EventHandlerPriority specifying the priority level. |
ReplaceAll(ISearchOptions)
Performs a replace all operation in the CurrentSnapshot.
ISearchResultSet ReplaceAll(ISearchOptions options)
| Parameter | Type | Description |
|---|---|---|
| options | ISearchOptions | The ISearchOptions to use. |
Returns
- ISearchResultSet:
An ISearchResultSet that specifies the result of the operation.
ReplaceAll(ISearchOptions, params TextRange[])
Performs a replace all operation in the CurrentSnapshot over a specific range of the snapshot.
ISearchResultSet ReplaceAll(ISearchOptions options, params TextRange[] searchTextRanges)
| Parameter | Type | Description |
|---|---|---|
| options | ISearchOptions | The ISearchOptions to use. |
| searchTextRanges | TextRange[] | The TextRange array of offsets to search.
If everything should be searched, specify the range |
Returns
- ISearchResultSet:
An ISearchResultSet that specifies the result of the operation.
ReplaceNext(ISearchOptions, int, bool)
Performs a replace next operation in the CurrentSnapshot.
ISearchResultSet ReplaceNext(ISearchOptions options, int startOffset, bool canWrap)
| Parameter | Type | Description |
|---|---|---|
| options | ISearchOptions | The ISearchOptions to use. |
| startOffset | int | The offset at which to start the search. |
| canWrap | bool | Whether the search can wrap at the end of the search text range. |
Returns
- ISearchResultSet:
An ISearchResultSet that specifies the result of the operation.
ReplaceNext(ISearchOptions, int, bool, TextRange)
Performs a replace next operation in the CurrentSnapshot over a specific range of the snapshot.
ISearchResultSet ReplaceNext(ISearchOptions options, int startOffset, bool canWrap, TextRange searchTextRange)
| Parameter | Type | Description |
|---|---|---|
| options | ISearchOptions | The ISearchOptions to use. |
| startOffset | int | The offset at which to start the search. |
| canWrap | bool | Whether the search can wrap at the end of the search text range. |
| searchTextRange | TextRange | The TextRange of offsets to search.
If all should be searched, specify the range |
Returns
- ISearchResultSet:
An ISearchResultSet that specifies the result of the operation.
ReplaceText(ITextChangeType, TextRange, string, ITextChangeOptions?)
Performs a replace text change in the CurrentSnapshot at the specified offset and allows for the specification of other options.
bool ReplaceText(ITextChangeType type, TextRange textRange, string text, ITextChangeOptions? options = null)
| Parameter | Type | Description |
|---|---|---|
| type | ITextChangeType | An ITextChangeType specifying the type of change. |
| textRange | TextRange | The TextRange of offsets to delete. |
| text | string | The text to insert. |
| options | ITextChangeOptions | The optional ITextChangeOptions for the change. |
Returns
- bool:
trueif a text change was allowed to occur; otherwise,false.
Remarks
This method creates an ITextChange for the current snapshot, adds a replace operation, and immediately applies it. If you will be executing multiple text change operations in a row, for improved performance it is recommended that you call the CreateTextChange(ITextChangeType, ITextChangeOptions?) method instead, add operations to the returned ITextChange, and then apply the text change.
See Also
ReplaceText(ITextChangeType, int, int, string, ITextChangeOptions?)
Performs a replace text change in the CurrentSnapshot at the specified offset and allows for the specification of other options.
bool ReplaceText(ITextChangeType type, int offset, int length, string text, ITextChangeOptions? options = null)
| Parameter | Type | Description |
|---|---|---|
| type | ITextChangeType | An ITextChangeType specifying the type of change. |
| offset | int | The offset at which to insert. |
| length | int | The number of characters to delete before inserting the text. |
| text | string | The text to insert. |
| options | ITextChangeOptions | The optional ITextChangeOptions for the change. |
Returns
- bool:
trueif a text change was allowed to occur; otherwise,false.
Remarks
This method creates an ITextChange for the current snapshot, adds a replace operation, and immediately applies it. If you will be executing multiple text change operations in a row, for improved performance it is recommended that you call the CreateTextChange(ITextChangeType, ITextChangeOptions?) method instead, add operations to the returned ITextChange, and then apply the text change.
See Also
SaveFile(Stream, Encoding, LineTerminator?)
Saves document text to a Stream using the specified encoding.
void SaveFile(Stream stream, Encoding encoding, LineTerminator? lineTerminator = null)
| Parameter | Type | Description |
|---|---|---|
| stream | Stream | The Stream to write to. |
| encoding | Encoding | The Encoding to use when loading the file. |
| lineTerminator | LineTerminator? | An optional LineTerminator specified when line ends should be normalized to a certain line terminator in the stream.
Use a |
SaveFile(string, Encoding?, LineTerminator?)
Saves document text to a file, optionally using a specified encoding.
void SaveFile(string path, Encoding? encoding = null, LineTerminator? lineTerminator = null)
| Parameter | Type | Description |
|---|---|---|
| path | string | The full path of the file of which to save. |
| encoding | Encoding | The optional Encoding to use when saving the file, falling back to a default UTF-8 character encoding when not specified. |
| lineTerminator | LineTerminator? | An optional LineTerminator specified when line ends should be normalized to a certain line terminator in the saved file.
Use a |
Remarks
The IsModified property is set to false if the specified file path is the same as the
FileName property's current value.
SetHeaderAndFooterText(string?, string?)
Sets the HeaderText and FooterText, and creates a new snapshot with the results.
bool SetHeaderAndFooterText(string? headerText, string? footerText)
| Parameter | Type | Description |
|---|---|---|
| headerText | string | The new header text value. |
| footerText | string | The new footer text value. |
Returns
- bool:
trueif a text change was allowed to occur; otherwise,false.
SetText(ITextChangeType, string?, ITextChangeOptions?)
Replaces all the text in the CurrentSnapshot and allows for the specification of other options.
bool SetText(ITextChangeType type, string? text, ITextChangeOptions? options = null)
| Parameter | Type | Description |
|---|---|---|
| type | ITextChangeType | An ITextChangeType specifying the type of change. |
| text | string | The text to insert. Pass |
| options | ITextChangeOptions | The optional ITextChangeOptions for the change. |
Returns
- bool:
trueif a text change was allowed to occur; otherwise,false.
Remarks
This method creates an ITextChange for the current snapshot, adds a set text operation, and immediately applies it. If you will be executing multiple text change operations in a row, for improved performance it is recommended that you call the CreateTextChange(ITextChangeType, ITextChangeOptions?) method instead, add operations to the returned ITextChange, and then apply the text change.
See Also
SetText(string?)
Replaces all the text in the CurrentSnapshot and marks the operation as a programmatic replacement.
bool SetText(string? text)
| Parameter | Type | Description |
|---|---|---|
| text | string | The text to insert. Pass |
Returns
- bool:
trueif a text change was allowed to occur; otherwise,false.
Remarks
A programmatic text replacement means that the undo history will be cleared, and any attached editors will reset the caret to offset 0.
This method creates an ITextChange for the current snapshot, adds a set text operation, and immediately applies it. If you will be executing multiple text change operations in a row, for improved performance it is recommended that you call the CreateTextChange(ITextChangeType, ITextChangeOptions?) method instead, add operations to the returned ITextChange, and then apply the text change.
See Also
Events
FileNameChanged
Occurs after the value of the FileName property has changed.
event EventHandler<StringPropertyChangedEventArgs> FileNameChanged
Event Type
IsModifiedChanged
Occurs after the value of the IsModified property has changed.
IsReadOnlyChanged
Occurs after the value of the IsReadOnly property has changed.
TabSizeChanged
Occurs after the value of the TabSize property has changed.
TextChanged
Occurs after a text change occurs to this document.
event EventHandler<TextSnapshotChangedEventArgs> TextChanged
Event Type
TextChanging
Occurs before a text change occurs to this document.
event EventHandler<TextSnapshotChangingEventArgs> TextChanging