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

DATATypeDescription
aLinesArrayArray of character strings, one per text line
lInsertLogicalInsert mode when .T., overwrite mode when .F.
lChangedLogicalFlag indicating the text has been modified
cFileNameCharacterFile name associated with the edited document
cTokens1 / cTokens2 / cTokens3CharacterToken lists for three syntax highlighting groups
nClrTok1 / nClrTok2 / nClrTok3NumericText colors for each token group
nClrNumberNumericColor for numeric literals
nClrStringNumericColor for string literals

Methods

MethodDescription
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

See Also