Class TextSource
Represents class that provides interface between edited text and Edit control.
[ToolboxBitmap(typeof(TextEditor), "Images.TextSource.bmp")]
public class TextSource : Component, IComponent, IDisposable, ITextSource, IEdit, INavigate, IUndo, ITextNotify, INotify, IUpdate, INotifier, ITextImport, IImport, ITextExport, IExport, IHyperText, ISpelling, IBraceMatching, ITextParsing, ITextSnippets, ITextErrors, ITextThread, ICodeActions, INotifyPropertyChanged
- Inheritance
-
TextSource
- Implements
- Derived
Examples
Here is how to declare a TextSource from the C# code:
using System;
using System.Windows;
using Alternet.Editor.Wpf;
public partial class MainWindow : Window
{
private void Window_Loaded(object sender, RoutedEventArgs e)
{
var textSource = new TextSource();
textSource.LoadFile("myfile.txt");
textSource.MoveToLine(textSource.Lines.Count - 1);
textSource.NewLine();
}
}
Here is how to declare a TextSource from the Visual Basic code:
Imports System
Imports System.Windows
Imports Alternet.Editor.Wpf
Partial Public Class MainWindow
Inherits Window
Private Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
Dim textSource = New TextSource()
textSource.LoadFile("myfile.txt")
textSource.MoveToLine(textSource.Lines.Count - 1)
textSource.NewLine()
End Sub
End Class
Remarks
TextSource is a non-visual component designed to store and manipulate text content displayed in the TextEditor control. TextSource allows you to separate data from visual controls and provides features like multiple views of the text.

Here are some of the essential features provided by the TextSource:
- Text editing
- Navigation
- Importing and Exporting
- Undo and Redo
- HyperText handling
- Integrating with spell-checker engines
- Handling matching braces
- Integrating with ISyntaxParser for text parsing
Constructors
- TextSource()
Initializes a new instance of the
TextSourceclass with default settings.
- TextSource(IContainer)
Initializes a new instance of the
TextSourceclass with specified container.
Properties
- ActiveEdit
Gets or sets an object that represent currently active (focused)
TextEditorcontrol linked to the text source.
- AutoInsertSnippet
Gets or sets current
ICodeSnippetRangeobject.
- BookMarks
Represents an object that implements
IBookMarksinterface holding collection ofIBookMarkobjects each determining particular bookmark within the text source.
- BracesOptions
Gets or sets options specifying appearance and behavior of matching braces within Edit control.
- CheckSpelling
Gets or sets a value indicating whether the document can check spelling for its content.
- ClosingBraces
Gets or sets an array of characters each one representing a closing brace.
- CodeSnippets
Gets or sets
ICodeSnippetRangeListfor Edit control.
- CurrentSnippet
Gets or sets the current
ICodeSnippetRangeobject.
- Edits
Represents a collection of
TextEditorcontrols linked to the text source.
- FileName
Gets or sets the name of the file that holds text source content.
- FirstChanged
Represents index of the first changed line.
- HasSpelling
Gets boolean value indicating that editor has external spell checker assigned.
- HighlightHyperText
Gets or sets a value indicating whether hypertext in the text should be highlighted.
- HighlightMatchingBlocks
Specifies that edit control should highlight found block matches.
- HighlightReferences
Specifies that edit control should highlight find references.
- IndentOptions
Gets or sets
Alternet.Editor.TextSource.IndentOptionsfor this class, allowing to customize behavior of Edit control when user presses Enter to insert new text line.
- LastChanged
Represents index of the last changed line.
- Lexer
Gets or sets an object that can perform lexical analysis of the text source content.
- LineStyles
Represents an object that implements
ILineStylesinterface holding collection of line styles for this document.
- LineTerminator
Gets or sets a string value that terminates line.
- Lines
Represents the object that implements
ITextStringsinterface containing collection of strings determining text source content.
- MatchingBlocks
Gets or sets
IRangeListof matching begin/end blocks for Edit control.
- MaxLength
Specifies the maximum number of characters that can be entered into the edit control.
- Modified
Gets or sets a value indicating whether the control's text content is modified.
- ModifiedLineRegions
Gets modified lines information, grouped in regions.
- ModifiedLines
Gets modified lines information.
- NavigateOptions
Gets or sets navigating options.
- OpenBraces
Gets or sets an array of characters each one representing an open brace.
- OptimizedForMemory
Specifies whether internal text representation should optimized memory usage.
- Overwrite
Gets or sets a value indicating whether the inserted text overwrites existing text.
- ParserLine
Gets the line currently parsed by the attached Lexer, when text source performs syntax parsing of the text.
- Position
Gets or sets current position within the control's text content.
- PrevPosition
Gets previous position within the control's text content.
- ReadOnly
Gets or sets a value indicating whether the control's content is read-only.
- RedoList
Provides an indexed access to redo data.
- References
Gets or sets
IRangeListof found references for Edit control.
- SearchResults
Gets or sets
IRangeListof search results for Edit control.
- SelectBlockRect
Represents a rectangular block of selected text.
- SelectedWords
Gets or sets
IRangeListof selected words for Edit control.
- SingleLineMode
Gets or sets a value indicating whether the control accepts only one line of the text.
- SpellDelimiterString
Gets or sets
Delimitersas a single string.
- SpellDelimiters
Gets or sets an array of chars used to separate words in a text.
- SpellTable
Represents a hash table containing delimiters.
- State
Gets or sets last changes to the text stored in the text source.
- Strings
Gets or sets text source content in the form of string array.
- StructureGuideLines
Represents a syntax errors collection.
- SymbolReference
Gets or sets
IRangeof the symbol reference for Edit control.
- SyntaxErrors
Represents a syntax errors collection.
- Text
Gets or sets text source content as a single string with the individual strings delimited by carriage returns.
- ThreadAction
Returns method executed in thread when parsing.
- UndoLimit
Gets or sets a value that limits number of undo operations.
- UndoList
Provides an indexed access to undo data.
- UndoOptions
Gets or sets options for undo and redo operations.
- UndoUpdateCount
Keeps track of calls to
BeginUndoUpdateandEndUndoUpdateso that they can be nested.
- UpdateCount
Keeps track of calls to
BeginUpdateandEndUpdateso that they can be nested.
- UrlTable
Represents hash table containing hyper-text characters.
Methods
- AbsolutePositionToTextPoint(int)
Converts given absolute position to position as Point value.
- AddNotifier(INotifier)
Adds new handler to respond for notification.
- AddUndo(UndoOperation, object)
Stores undo operation in the appropriate list.
- BeginUndoUpdate()
Allows to consider number of undo redo operations as single operation, until calling
EndUndoUpdatemethod.
- BeginUpdate()
Prevents object state updating until calling
EndUpdatemethod.
- BeginUpdate(UpdateReason)
Prevents object state updating until calling
EndUpdatemethod.
- BeginUpdateSnippet()
Prevents the Edit control from updating snippets until the
EndUpdateSnippetmethod is called.
- BreakLine(bool)
Breaks current line into two lines.
- CanRedo()
Indicating whether the redo operation can be performed.
- CanUndo()
Indicating whether the undo operation can be performed.
- Clear()
Clears content of the
TextSource
- ClearRedo()
Clears list of redo operations.
- ClearUndo()
Clears list of undo operations.
- CreateStringItem(string)
Create a new
IStringItemobject containing specified text.
- DeleteBlock(Rectangle, bool)
Deletes a specified block of characters.
- DeleteBlock(int, bool)
Deletes a specified block of characters.
- DeleteLeft(int, bool)
Deletes a specified number of characters to the left of the active point.
- DeleteRight(int, bool)
Deletes a specified number of characters to the right of the active point.
- DisablePositionUpdate()
Prevents notification of changing of caret position until calling
EnablePositionUpdatemethod.
- DisableUndo()
Disables recording of undo/redo operations. EnableUndo()
- DisableUpdate()
Prevents object state updating until calling
EnableUpdatemethod.
- Dispose(bool)
Releases the unmanaged resources used by the Component and optionally releases the managed resources.
- EnablePositionUpdate()
Re-enables notification of changing of caret position that was turn of by calling
DisablePositionUpdatemethod.
- EnableUndo()
Re-enables recording of undo/redo operations, that was turn of by calling
DisableUndomethod. DisableUndo()
- EnableUpdate()
Re-enables object state updating, that was turn of by calling
DisableUpdatemethod. Using DisableUpdate/EnableUpdate to prevent notifying about updating the object state.
- EndUndoUpdate()
Ends undo block, that was started by
BeginUndoUpdatemethod.
- EndUpdate()
Re-enables object state updating, that was turn of by calling
BeginUpdatemethod.
- EndUpdateSnippet()
Resumes updating snippets after updating is suspended by the
BeginUpdateSnippetmethod.
- FindClosingBrace(ref Point)
Locates closing brace.
- FindClosingBrace(ref int, ref int)
Locates closing brace.
- FindCodeActions(Point, Point, Point, ISyntaxError, bool)
Locates and highlights available code fixes and code refactors for given position in the texts.
- FindOpenBrace(ref Point)
Locates open brace.
- FindOpenBrace(ref int, ref int)
Locates open brace.
- FormatText()
Tries to format and outline
TextSourcetext using attachedLexer.
- FormatText(bool, bool)
Tries to format and outline
Indicates if parsing should be performed without instantiating parser thread. Indicates if attached editors should be notified on reparsingTextSourcetext using attachedLexer.
- GetCharIndexFromPosition(Point)
Converts given Point value to the index of character.
- GetCodeFixes(ISyntaxError, bool)
Gets code fixes for a given syntax error.
- GetCodeFixesAsync(ISyntaxError, bool, CancellationToken)
Gets code fixes for a given syntax error in async mode.
- GetCodeSnippetRangeAt(Point)
Locates code snippet at specified position.
- GetFlowDocument(FlowDocumentExportOptions)
Gets FlowDocument object describes TextSource content accordingly to specified settings.
- GetIndentString()
Gets indentation string at current position.
- GetPositionFromCharIndex(int)
Converts given character index to position as Point value.
- GetStructureGuideLines(int, IList<IRange>)
Gets list of guide lines.
- GetSyntaxErrorAt(int, int)
Gets syntax error at specified position.
- HasCodeFixes(ISyntaxError, bool)
Determines if code fixes are available for a given syntax error.
- HasCodeFixesAsync(ISyntaxError, bool, CancellationToken)
Determines if code fixes are available for a given syntax error in async mode.
- HighlightBraces()
Highlights braces containing caret position. UnhighlightBraces()
- HighlightCodeActions()
When implemented by a class, highlights code fixes/refactors if needed.
- HighlightCodeSnippets()
Highlights code snippets using appropriate style.
- HighlightSyntaxErrors()
Highlights syntax errors.
- IndentLine()
Inserts spaces to the start of the current line. Number of spaces is calculated from indent options or
SyntaxParserif assigned.
- IndentLine(string, bool)
Inserts white space to the start of the current line.
white space string Indicates if the change needs to be translated to the parser
- Insert(string, bool)
Inserts the given string at the specified location.
- InsertBlock(ITextStrings, bool)
Inserts the given string collection at the specified location.
- InsertBlock(string, bool)
Inserts the given string at the specified location.
- InsertBlock(string[], bool)
Inserts the given string array at the specified location.
- InsertBlock(string[], bool, bool)
Inserts the given string array at the specified location.
- InsertFromFile(string)
Inserts the file text content at the specified location.
- InvalidateSyntaxErrors()
Invalidates highlighting of syntax errors.
- IsContentDivider(int)
Gets boolean value indicating whether text content is divided at given line.
- IsHyperText(string)
Indicates whether given text represents hypertext.
- IsWordCorrect(string)
Checks whether spelling for the given word is correct.
- IsWordCorrect(string, Point)
When implemented by a class, checks whether spelling for the given word is correct.
- LineIsHidden(int)
Determines whether the given line is readonly.
- LineIsModified(int)
Indicates whether specified line already modified.
- LineIsModified(int, out bool)
Indicates whether specified line already modified.
- LineIsReadonly(int)
Determines whether the given line is readonly.
- LinesChanged(int, int)
Specifies range of lines that was changed.
- LinesChanged(int, int, bool)
Specifies range of lines that was changed.
- LoadFile(string)
Loads the contents of the specified file.
- LoadFile(string, IStringImport)
Loads content from the given file with specified importer.
- LoadFile(string, IStringImport, Encoding)
Loads content from the given file with specified importer and specific encoding.
- LoadFile(string, Encoding)
Loads the contents of the specified file with specified encoding.
- LoadStream(Stream)
Loads the contents of the specified stream.
- LoadStream(Stream, IStringImport)
Loads the text content from the given stream with specified importer.
- LoadStream(Stream, IStringImport, Encoding)
Loads the text content from the given stream with specified importer.
- LoadStream(Stream, Encoding)
Loads the contents of the specified stream.
- LoadStream(TextReader)
Loads the contents of the specified stream.
- LoadStream(TextReader, IStringImport)
Loads the contents of the specified stream.
- MoveTo(Point)
Moves the current position to the given position.
- MoveTo(int, int)
Moves the current position to the given position.
- MoveToChar(int)
Moves the current position to the specified character in the current line.
- MoveToLine(int)
Moves the current position to the specified line.
- MoveToLine(int, int)
Moves the current position to the specified line.
- Navigate(int, int)
Moves current position by the given offset value.
- NeedAdvancedFormatText()
Indicates whether
ITextSourceshould format indetnation and spaces upon text pasting or auto-completing.
- NeedAutoComplete()
Indicates whether
ITextSourceshould try to autocomplete statements.
- NeedCacheIndent()
Indicates whether
ITextSourcecan reuse previous indentation.
- NeedCodeCompletion()
Indicates whether
ITextSourcecan provide code completion operation for its content.
- NeedCodeCompletionTabs(CodeCompletionType)
Indicates code completion content can be filtered based on its priority.
- NeedCodeFixes()
Indicates whether
ITextSourcecan provide code fixes operation for its content.
- NeedCodeRefactors()
Indicates whether
ITextSourcecan provide code fixes operation for its content.
- NeedContentDividers()
Indicates whether
ITextSourcecan proceed syntax errors in its content.
- NeedFormatText()
Indicates whether
ITextSourcecan format its content.
- NeedFormatTextOnLineChange()
Indicates whether
ITextSourceshould format spaces and case when changing the current line.
- NeedIndentText()
Indicates whether
ITextSourcecan indent its content.
- NeedOutlineText()
Indicates whether
ITextSourcecan outline its content.
- NeedParse()
Indicates whether syntax parsing can be performed for the text, or some of formatting text elements, such as urls or braces, should be highlighted.
- NeedQuickInfoTips()
Indicates whether
ITextSourcecan obtain short description for syntax tokens within its content.
- NeedReparseText()
Indicates whether
ITextSourcecan perform syntax analysis of its content.
- NeedReparseTextOnLineChange()
Indicates whether
ITextSourceshould replace text when changing the current line.
- NeedStructureGuideLines()
Indicates whether
ITextSourcecan proceed syntax errors in its content.
- NeedSyntaxErrors()
Indicates whether
ITextSourcecan proceed syntax errors in its content.
- NeedWorkInThread()
Indicates whether
ITextSourcecan perform syntax analysis in thread.
- NewLine()
Inserts a line break at the current position.
- NewLine(ref string, bool)
Inserts a line break at the current position with indentation.
- NewLineAbove()
Inserts a line break above the current position.
- NewLineBelow()
Inserts a line break below the current position.
- Notification(object, EventArgs)
Updates control's content according to parameters of notification.
- Notify(EventArgs)
Notifies all notifiers about changing source state.
- ParseString(int)
Perform lexical analysis of the specified string.
- ParseStrings(int, int)
Perform lexical analysis specified strings.
- ParseToString(int)
Perform lexical analysis of specified strings.
- PositionIsReadonly(Point)
Determines whether the text at given position is readonly.
- ProcessAutoComplete(out string)
Inserts end-of-block code fragment if needed.
- Redo()
Performs the last redo operation.
- RemoveNotifier(INotifier)
Exclude specified handler from notification handlers list.
- ResetBracesOptions()
Resets the
BracesOptionsto its default value.
- ResetCheckSpelling()
Resets the
CheckSpellingto the default value.
- ResetClosingBraces()
Resets the
ClosingBracesto its default value.
- ResetHighlightHyperText()
Resets
HighlightHyperTextto the default value.
- ResetIndentOptions()
Resets the
IndentOptionsto the default value.
- ResetMaxLength()
Resets the
MaxLengthto the default value.
- ResetModified()
Resets the
Modifiedto the default value.
- ResetNavigateOptions()
Resets the
NavigateOptionsto the default value.
- ResetOpenBraces()
Resets the
OpenBracesto its default value.
- ResetOverWrite()
Resets the
OverWriteto the default value.
- ResetReadOnly()
Resets the
ReadOnlyto the default value.
- ResetSingleLineMode()
Resets the
SingleLineModeto the default value.
- ResetSpellDelimiters()
Resets the
SpellDelimitersto the default value.
- ResetUndoLimit()
Resets the
UndoLimitto the default value.
- ResetUndoOptions()
Resets the
UndoOptionsto the default value.
- RestorePosition(int)
Restores position from stored position list by given index.
- RestorePositionWithUndo(int)
Restores position from stored position list by given index.
- SaveFile(string)
Saves text content to the specific file.
- SaveFile(string, IStringExport)
Saves text content to the specific file with specific exporter.
- SaveFile(string, IStringExport, Encoding)
Saves text content to the specific file with specific exporter and encoding.
- SaveFile(string, Encoding)
Saves text content to the specific file with specific encoding.
- SaveStream(Stream)
Saves the text content to the specified stream.
- SaveStream(Stream, IStringExport)
Saves the text content to the specified stream.
- SaveStream(Stream, IStringExport, Encoding)
Saves the text content to the specified stream.
- SaveStream(Stream, Encoding)
Saves the text content to the specified stream.
- SaveStream(TextWriter)
Saves the text content to the specified stream.
- SaveStream(TextWriter, IStringExport)
Saves the text content to the specified stream.
- SetLastParsed(int)
Updates the last parsed line and resets first changed line to it's default value.
- SetLineHidden(int, bool)
Sets readonly state for the given line.
- SetLineHidden(int[], bool)
Sets readonly state for the given line.
- SetLineReadonly(int, bool)
Sets readonly state for the given line.
- SetLineReadonly(int[], bool)
Sets readonly state for the given line.
- SetLineState(int[], ItemState, bool)
Sets item state for the given line.
- SetNavigateOptions(NavigateOptions)
Sets navigating options without validating position.
- StartThread(ThreadProc, ThreadProc, ThreadProc, ThreadProc, ThreadProc)
Executes action in thread.
- StopThread(ThreadProc, bool)
Aborts executing action in thread.
- StorePosition(Point)
Stores given position to stored position list.
- StorePosition(Point, bool)
Stores given position to stored position list.
- StorePositionWithUndo(Point)
Stores given position to stored position list preserving it for undo.
- SupportsAsyncParsing()
Indicates whether
ITextSourcecan perform syntax analysis asynchronously.
- TempHighlightBraces(Rectangle[])
Temporary highlights all text within the area specified by rects. TempUnhighlightBraces()
- TempHighlightMatchingBlocks()
Highlights block match.
- TempHighlightReferences()
Highlights found references.
- TempHighlightSearchResults(IRangeList)
Highlights search results.
- TempHighlightSelectedWords(IRangeList)
Highlights selected words.
- TempUnhighlightBraces()
Cancels text highlighting turned on using
TempHighlightBracesTempHighlightBraces(Rectangle[])
- TempUnhighlightBraces(bool)
Unhighlights temporary braces areas.
- TempUnhighlightReferences()
Unhighlights references highlighted with previous call of TempHighlightReferences.
- TempUnhighlightSearchResults()
Unhighlights search results highlighted with previous call of TempHighlightSearchResults.
- TempUnhighlightSelectedWords()
Unhighlights selected words highlighted with previous call of TempHighlightSelectedWords.
- TextPointToAbsolutePosition(Point)
Converts given Point value to the absolute position.
- UnBreakLine(bool)
Concatenates lines at current position.
- Undo(IUndoData, bool)
Performs the single undo operation.
- Undo(bool)
Performs the last undo operation.
- UnhighlightBraces()
Unhighlights braces containing caret position. HighlightBraces()
- UnhighlightBraces(bool)
Unhighlights braces.
- UnhighlightCodeSnippets()
Removes highlighting from code snippets and clears snippet collection.
- UnhighlightSyntaxErrors()
Removes syntax errors highlighting.
- Update()
Updates an object state.
- ValidatePosition(ref Point)
Validates given position within control's text content.
Events
- HyperText
Occurs when a control needs checking whether some string represents hypertext.
- PropertyChanged
Occurs when a property value changes.
- UndoEvent
Occurs when undo/redo operation performed.
- WordSpell
Occurs when spelling of some word within the text needs checking.