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
Gets or sets 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
Gets or sets whether to convert tabs to spaces when the Tab key is pressed or indenting occurs.
bool AutoConvertTabsToSpaces { get; set; }
Property Value
- bool:
true
if 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
Gets the ITextSnapshot that contains the current text of the document.
ITextSnapshot CurrentSnapshot { get; }
Property Value
- ITextSnapshot:
The ITextSnapshot that contains the current text of the document.
FileName
Gets or sets the name of the file currently loaded in the document.
string FileName { get; set; }
Property Value
- string:
The name of the file currently loaded in the document.
Remarks
This property is automatically set whenever a LoadFile(string) overload is called that accepts a file path.
IsModified
Gets or sets whether the document has been modified.
bool IsModified { get; set; }
Property Value
- bool:
true
if 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, LineTerminator)
overload is used that accepts a path matching the current FileName property value.
IsReadOnly
Gets or sets whether the entire document is flagged as read-only.
bool IsReadOnly { get; set; }
Property Value
- bool:
true
if 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
Gets or sets the distance in spaces between tab stops.
int TabSize { get; set; }
Property Value
- int:
The distance in spaces between tab stops. The default value is
4
spaces.
UndoHistory
Gets an IUndoHistory that provides access to undo and redo functionality for the document.
IUndoHistory UndoHistory { get; }
Property Value
- IUndoHistory:
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)
Appends text to the end of the CurrentSnapshot text.
bool AppendText(ITextChangeType type, string text)
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. |
Returns
- bool:
true
if 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) method instead, add operations to the returned ITextChange, and then apply the text change.
See Also
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)
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 ITextChangeOptions for the change. |
Returns
- bool:
true
if 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)
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)
Parameter | Type | Description |
---|---|---|
type | ITextChangeType | An ITextChangeType specifying the type of change. |
Returns
- ITextChange:
The ITextChange that was created.
Remarks
The ITextChange.Apply() method must be called to apply the queued operations to the document.
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)
Parameter | Type | Description |
---|---|---|
type | ITextChangeType | An ITextChangeType specifying the type of change. |
options | ITextChangeOptions | The 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)
Performs a delete text change in the CurrentSnapshot.
bool DeleteText(ITextChangeType type, TextRange textRange)
Parameter | Type | Description |
---|---|---|
type | ITextChangeType | An ITextChangeType specifying the type of change. |
textRange | TextRange | The TextRange of offsets to delete. |
Returns
- bool:
true
if 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) method instead, add operations to the returned ITextChange, and then apply the text change.
See Also
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)
Parameter | Type | Description |
---|---|---|
type | ITextChangeType | An ITextChangeType specifying the type of change. |
textRange | TextRange | The TextRange of offsets to delete. |
options | ITextChangeOptions | The ITextChangeOptions for the change. |
Returns
- bool:
true
if 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)
Performs a delete text change in the CurrentSnapshot.
bool DeleteText(ITextChangeType type, int offset, int length)
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. |
Returns
- bool:
true
if 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) 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)
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 ITextChangeOptions for the change. |
Returns
- bool:
true
if 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)
Performs an insert text change in the CurrentSnapshot at the specified offset.
bool InsertText(ITextChangeType type, int offset, string text)
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. |
Returns
- bool:
true
if 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) 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)
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 ITextChangeOptions for the change. |
Returns
- bool:
true
if 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)
Returns 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.
LineTerminator 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. |
Returns
- LineTerminator:
A LineTerminator indicating the line terminator of the file that was loaded.
LoadFile(string)
Loads document text from a file, using the default UTF-8 character encoding.
LineTerminator LoadFile(string path)
Parameter | Type | Description |
---|---|---|
path | string | The full path of the file from which to load. |
Returns
- LineTerminator:
A LineTerminator indicating the line terminator of the file that was loaded.
Remarks
This method updates the value of the FileName property.
LoadFile(string, Encoding)
Loads document text from a file using the specified encoding.
LineTerminator LoadFile(string path, Encoding encoding)
Parameter | Type | Description |
---|---|---|
path | string | The full path of the file from which to load. |
encoding | Encoding | The Encoding to use when loading the file. |
Returns
- LineTerminator:
A LineTerminator indicating the line terminator of the file that was loaded.
Remarks
This method updates the value of the FileName property.
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)
Performs a replace text change in the CurrentSnapshot at the specified offset.
bool ReplaceText(ITextChangeType type, TextRange textRange, string text)
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. |
Returns
- bool:
true
if 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) method instead, add operations to the returned ITextChange, and then apply the text change.
See Also
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)
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 ITextChangeOptions for the change. |
Returns
- bool:
true
if 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)
Performs a replace text change in the CurrentSnapshot at the specified offset.
bool ReplaceText(ITextChangeType type, int offset, int length, string text)
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. |
Returns
- bool:
true
if 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) 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)
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 ITextChangeOptions for the change. |
Returns
- bool:
true
if 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)
Parameter | Type | Description |
---|---|---|
stream | Stream | The Stream to write to. |
encoding | Encoding | The Encoding to use when loading the file. |
lineTerminator | LineTerminator | A LineTerminator specifying the output format. |
SaveFile(string, LineTerminator)
Saves document text to a UTF-8 encoded file.
void SaveFile(string path, LineTerminator lineTerminator)
Parameter | Type | Description |
---|---|---|
path | string | The full path of the file of which to save. |
lineTerminator | LineTerminator | A LineTerminator specifying the output format. |
Remarks
The IsModified property is set to false
if the specified file path is the same as the
FileName property's current value.
SaveFile(string, Encoding, LineTerminator)
Saves document text to a file using the specified encoding.
void SaveFile(string path, Encoding encoding, LineTerminator lineTerminator)
Parameter | Type | Description |
---|---|---|
path | string | The full path of the file of which to save. |
encoding | Encoding | The Encoding to use when saving the file. |
lineTerminator | LineTerminator | A LineTerminator specifying the output format. |
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:
true
if a text change was allowed to occur; otherwise,false
.
SetText(ITextChangeType, string)
Replaces all the text in the CurrentSnapshot.
bool SetText(ITextChangeType type, string text)
Parameter | Type | Description |
---|---|---|
type | ITextChangeType | An ITextChangeType specifying the type of change. |
text | string | The text to insert. Pass an empty string to "clear" the snapshot text. |
Returns
- bool:
true
if 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) method instead, add operations to the returned ITextChange, and then apply the text change.
See Also
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)
Parameter | Type | Description |
---|---|---|
type | ITextChangeType | An ITextChangeType specifying the type of change. |
text | string | The text to insert. Pass an empty string to "clear" the snapshot text. |
options | ITextChangeOptions | The ITextChangeOptions for the change. |
Returns
- bool:
true
if 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 an empty string to "clear" the snapshot text. |
Returns
- bool:
true
if 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) 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