TTxtEdit
Source: source/classes/ttxtedit.prg
Inherits from: TControl
TTxtEdit is a source code text editor control with syntax highlighting support. It provides line-oriented editing with insert/overwrite modes, clipboard operations, undo/redo history, find and replace dialogs, and line manipulation commands. Token-based syntax coloring can be customized for different programming languages.
Key DATA Members
| DATA | Type | Description |
|---|---|---|
aLines | Array | Array of character strings, one per text line |
lInsert | Logical | Insert mode when .T., overwrite mode when .F. |
lChanged | Logical | Flag indicating the text has been modified |
cFileName | Character | File name associated with the edited document |
cTokens1 / cTokens2 / cTokens3 | Character | Token lists for three syntax highlighting groups |
nClrTok1 / nClrTok2 / nClrTok3 | Numeric | Text colors for each token group |
nClrNumber | Numeric | Color for numeric literals |
nClrString | Numeric | Color for string literals |
Methods
| Method | Description |
|---|---|
New( nRow, nCol, nW, nH, oWnd ) | Create a new text editor control with position and dimensions |
Load( cFile ) / SaveToFile( cFile ) | Load text from a file or save the current text to a file |
SetText( cText ) / GetText() | Set or retrieve the full editor text content |
Copy() / Cut() / Paste() | Clipboard operations for selected text |
Undo() / Redo() | Undo or redo the last editing action |
Find( cText ) / DlgFind() / DlgGoLine() | Search for text, show find dialog, or go to line dialog |
InsLine() / DelLine() / DupLine() / JoinLine() | Insert, delete, duplicate, or join the current line |
Example: Syntax-Highlighted Editor
#include "FiveWin.ch"
function Main()
local oWnd, oEdit
DEFINE WINDOW oWnd TITLE "Source Editor" SIZE 600, 400
oEdit := TTxtEdit():New( 0, 0, 600, 380, oWnd )
// Harbour syntax tokens
oEdit:cTokens1 := "function|procedure|local|if|else|endif|do|while|return"
oEdit:nClrTok1 := CLR_BLUE
oEdit:cTokens2 := "MAIN|NIL|TRUE|FALSE|.T.|.F."
oEdit:nClrTok2 := CLR_RED
oEdit:nClrNumber := CLR_PURPLE
oEdit:nClrString := CLR_GREEN
oEdit:Load( "source.prg" )
ACTIVATE WINDOW oWnd CENTERED
return nil
Notes
- Syntax highlighting uses three token groups (
cTokens1throughcTokens3) with independently configurable colors. - Tokens are pipe-delimited strings. Each token is matched as a whole word in the source text.
- The
lChangedflag is automatically maintained; check it before closing to prompt for saving. - Use
DlgFind()andDlgGoLine()to provide standard Find and Go To Line dialogs to the user. - The
aLinesarray provides direct access to individual lines for programmatic manipulation.