TextDocumentBase Class
Represents a text document.
public abstract class TextDocumentBase : ObservableObjectBase, ITextDocument
- Inheritance:
- object ObservableObjectBase object
- Derived:
- CodeDocument
- Implements:
- ITextDocument
Constructors
TextDocumentBase()
Initializes an instance of the class.
protected TextDocumentBase()
Properties
AutoCharacterCasing
Indicates how to modify the case of text that is inserted into the document.
public 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.
public 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.
public 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.
public 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.
public 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.
public 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.
public 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.
public 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.
public 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.
public 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.
public 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
GetReadOnlyRegions(TextRange)
Returns the collection of read-only region tag snapshot ranges.
protected virtual IEnumerable<TagSnapshotRange<IReadOnlyRegionTag>>? GetReadOnlyRegions(TextRange textRange)
| Parameter | Type | Description |
|---|---|---|
| textRange | TextRange | The text range relative to the current snapshot for which to locate read-only regions. |
Returns
GetTextReplacementInsertText(ITextChangeOperation)
Returns the scrubbed text that should be inserted for an entire text replacement ITextChangeOperation.
protected virtual string? GetTextReplacementInsertText(ITextChangeOperation operation)
| Parameter | Type | Description |
|---|---|---|
| operation | ITextChangeOperation | The ITextChangeOperation containing default text to insert. |
Returns
Remarks
This method can be overridden to scrub the text to insert, such as remove trailing whitespace, etc.
By default it returns a null, meaning to use the unscrubbed InsertedText value.
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.
public 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.
public 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.
public 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.
public 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.
public 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. |
OnFileNameChanged(StringPropertyChangedEventArgs)
Raises the FileNameChanged event.
protected virtual void OnFileNameChanged(StringPropertyChangedEventArgs e)
| Parameter | Type | Description |
|---|---|---|
| e | StringPropertyChangedEventArgs | The event data. |
OnIsModifiedChanged(EventArgs)
Raises the IsModifiedChanged event.
protected virtual void OnIsModifiedChanged(EventArgs e)
| Parameter | Type | Description |
|---|---|---|
| e | EventArgs | The event data. |
OnIsReadOnlyChanged(EventArgs)
Raises the IsReadOnlyChanged event.
protected virtual void OnIsReadOnlyChanged(EventArgs e)
| Parameter | Type | Description |
|---|---|---|
| e | EventArgs | The event data. |
OnTabSizeChanged(EventArgs)
Raises the TabSizeChanged event.
protected virtual void OnTabSizeChanged(EventArgs e)
| Parameter | Type | Description |
|---|---|---|
| e | EventArgs | The event data. |
OnTextChanged(TextSnapshotChangedEventArgs)
Raises the TextChanged event.
protected virtual void OnTextChanged(TextSnapshotChangedEventArgs e)
| Parameter | Type | Description |
|---|---|---|
| e | TextSnapshotChangedEventArgs | The event data. |
OnTextChanging(TextSnapshotChangingEventArgs)
Raises the TextChanging event.
protected virtual void OnTextChanging(TextSnapshotChangingEventArgs e)
| Parameter | Type | Description |
|---|---|---|
| e | TextSnapshotChangingEventArgs | The event data. |
RemoveTextChangedEventHandler(EventHandler<TextSnapshotChangedEventArgs>, EventHandlerPriority)
Removes an event handler for the TextChanged event using the specified priority level.
public 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.
public 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.
public 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.
public 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.
public 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.
public 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.
public 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.
public 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
ResetAutoCharacterCasing()
Resets the AutoCharacterCasing property to its default value.
public void ResetAutoCharacterCasing()
ResetAutoConvertTabsToSpaces()
Resets the AutoConvertTabsToSpaces property to its default value.
public void ResetAutoConvertTabsToSpaces()
ResetFileName()
Resets the FileName property to its default value.
public void ResetFileName()
ResetIsModified()
Resets the IsModified property to its default value.
public void ResetIsModified()
ResetIsReadOnly()
Resets the IsReadOnly property to its default value.
public void ResetIsReadOnly()
ResetTabSize()
Resets the TabSize property to its default value.
public void ResetTabSize()
SaveFile(Stream, Encoding, LineTerminator?)
Saves document text to a Stream using the specified encoding.
public 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.
public 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.
public 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.
public 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.
public 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
ShouldSerializeAutoCharacterCasing()
Indicates whether the AutoCharacterCasing property should be persisted.
public bool ShouldSerializeAutoCharacterCasing()
Returns
- bool:
trueif the property value has changed from its default; otherwise,false.
ShouldSerializeAutoConvertTabsToSpaces()
Indicates whether the AutoConvertTabsToSpaces property should be persisted.
public bool ShouldSerializeAutoConvertTabsToSpaces()
Returns
- bool:
trueif the property value has changed from its default; otherwise,false.
ShouldSerializeFileName()
Indicates whether the FileName property should be persisted.
public bool ShouldSerializeFileName()
Returns
- bool:
trueif the property value has changed from its default; otherwise,false.
ShouldSerializeIsModified()
Indicates whether the IsModified property should be persisted.
public bool ShouldSerializeIsModified()
Returns
- bool:
trueif the property value has changed from its default; otherwise,false.
ShouldSerializeIsReadOnly()
Indicates whether the IsReadOnly property should be persisted.
public bool ShouldSerializeIsReadOnly()
Returns
- bool:
trueif the property value has changed from its default; otherwise,false.
ShouldSerializeTabSize()
Indicates whether the TabSize property should be persisted.
public bool ShouldSerializeTabSize()
Returns
- bool:
trueif the property value has changed from its default; otherwise,false.
Events
FileNameChanged
Occurs after the value of the FileName property has changed.
public 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.
public event EventHandler<TextSnapshotChangedEventArgs> TextChanged
Event Type
TextChanging
Occurs before a text change occurs to this document.
public event EventHandler<TextSnapshotChangingEventArgs> TextChanging
Event Type
Fields
DefaultTabSize
The default number of characters for a tab stop, which is 4.
public const int DefaultTabSize = 4
Inherited Members
- ObservableObjectBase.OnPropertyChanged(string)
- ObservableObjectBase.OnPropertyChanged(PropertyChangedEventArgs)
- ObservableObjectBase.OnPropertyChanging(string)
- ObservableObjectBase.OnPropertyChanging(PropertyChangingEventArgs)
- ObservableObjectBase.SetProperty<T>(ref T, T, string)
- ObservableObjectBase.PropertyChanged
- ObservableObjectBase.PropertyChanging
- object.GetType()
- object.MemberwiseClone()
- object.ToString()
- object.Equals(object)
- object.Equals(object, object)
- object.ReferenceEquals(object, object)
- object.GetHashCode()