TScintilla

Fonte: source/classes/scintila.prg

Hierarchy: TScintillaTControl

TScintilla wraps the Scintilla source code editing component (scintilla.org) for use within FiveWin applications. It provides a full-featured code editor with syntax highlighting, code folding, line numbering, bookmarks, search/replace, undo/redo, and support for multiple lexers including Harbour/xHarbour syntax.

SCINTILLA Command

@ nRow, nCol SCINTILLA oSci SIZE nW, nH OF oWnd FONT oFont LEXER cLexer

Key DATA Members

DATATypeDefaultDescription
cFileNameCharacterCurrently loaded file path
cLexerCharacter0Lexer identifier for syntax highlighting
lMargLinLogical.F.Show line number margin
lFoldingLogical.F.Enable code folding margin
lMarkingLogical.F.Show bookmark/symbol margin
lModifiedLogical.F.Whether the document has unsaved changes
bModifiedBlockCodeblock evaluated when the document modification state changes
cCKeyw1..cCKeyw5ArraySyntax color arrays: each is { nForeColor, nBackColor, nCase } for keyword levels 1–5

Methods

MethodDescription
New( nRow, nCol, nWidth, nHeight, oWnd, nClrT, nClrP, cLex, cDll, bSetup )Constructor. Loads the SciLexer DLL and creates the Scintilla window.
OpenFile( cFileName )Load a file into the editor. Detects UTF-8 BOM automatically.
Save()Save the current content to disk. Prompts for filename if none is set.
Open()Show a file-open dialog and load the selected file.
SetText( cText )Replace the entire editor content with a string.
GetText()Return the entire editor content as a string.
GetLine( nLine )Return the text of a specific 1-based line number.
GetLineCount()Return the total number of lines in the document.
FindText( cText, lForward )Search for text forward or backward from the current position.
SetFont( oFont )Change the editor font at runtime.
Undo()Undo the last editing action.
Redo()Redo a previously undone action.
Copy()Copy the current selection to the clipboard.
Cut()Cut the current selection to the clipboard.
Paste()Paste clipboard content at the cursor position.
SelectAll()Select the entire document content.
Print( oFont )Print the document using TReport with optional line numbers.
MarkerAdd( nLine, nMarker )Add a marker (bookmark) at the specified line.
FoldAllContract()Collapse all foldable code regions.
FoldAllExpand()Expand all folded code regions.
SetColor( nClrText, nClrPane )Set the default text and background colors.

Example: Code Editor

#include "FiveWin.ch"

function Main()

   local oWnd, oSci, oFont

   DEFINE FONT oFont NAME "Consolas" SIZE 0, -12

   DEFINE WINDOW oWnd TITLE "Source Editor" ;
      SIZE 800, 600

   @ 0, 0 SCINTILLA oSci SIZE 800, 570 OF oWnd ;
      FONT oFont LEXER ""

   oSci:lMargLin   := .T.
   oSci:lFolding   := .T.
   oSci:lMarking   := .T.
   oSci:SetUp()

   // Toolbar buttons
   @ 575, 10 BUTTON "&Open" SIZE 50, 20 ;
      ACTION oSci:Open()

   @ 575, 65 BUTTON "&Save" SIZE 50, 20 ;
      ACTION oSci:Save()

   @ 575, 120 BUTTON "&Find" SIZE 50, 20 ;
      ACTION oSci:DlgFindText()

   @ 575, 175 BUTTON "&Undo" SIZE 50, 20 ;
      ACTION oSci:Undo()

   @ 575, 230 BUTTON "&Redo" SIZE 50, 20 ;
      ACTION oSci:Redo()

   @ 575, 620 BUTTON "E&xit" SIZE 50, 20 ;
      ACTION oWnd:End()

   ACTIVATE WINDOW oWnd ;
      VALID ( oSci:End(), oFont:End(), .T. )

return nil

Lexer Configuration

TScintilla supports syntax highlighting via configurable keyword color sets and token-specific color arrays:

DATATypeDescription
cCKeyw1..cCKeyw5ArrayKeyword color sets: { nForeColor, nBackColor, nCase } for keyword levels 1–5
cCStringArrayString literal color: { nForeColor, nBackColor, nCase }
cCNumberArrayNumeric literal color: { nForeColor, nBackColor, nCase }
cCOperatorArrayOperator color: { nForeColor, nBackColor, nCase }
cCCommentArrayComment color (supports multi-line): { nForeColor, nBackColor, nCase }

Each color array contains three elements:

Default colors for Harbour/xHarbour syntax are defined as class data members:

DATA cCComment  INIT { CLR_GRAY,    CLR_WHITE, SC_CASE_MIXED }
DATA cCString   INIT { CLR_HRED,    CLR_WHITE, SC_CASE_MIXED }
DATA cCNumber   INIT { CLR_HBLUE,   CLR_WHITE, SC_CASE_MIXED }
DATA cCOperator INIT { CLR_HBLACK,  CLR_WHITE, SC_CASE_MIXED }
DATA cCKeyw1    INIT { METRO_ORANGE,CLR_WHITE, SC_CASE_MIXED }
DATA cCKeyw2    INIT { CLR_HGREEN,  CLR_WHITE, SC_CASE_MIXED }
DATA cCKeyw3    INIT { CLR_HPURPLE, CLR_WHITE, SC_CASE_MIXED }
DATA cCKeyw4    INIT { CLR_HCYAN,   CLR_WHITE, SC_CASE_MIXED }
DATA cCKeyw5    INIT { CLR_HRED,    CLR_WHITE, SC_CASE_MIXED }

File Encoding Modes

TScintilla supports multiple file encoding modes for reading and saving documents in different character encodings. These are controlled by the nModeSave and nModeLoad data members along with the lBom flag.

ModeConstantDescription
0nModeLoad := 0Normal (ANSI/CP1252) encoding
1nModeLoad := 1 / nModeSave := 1UTF-8 with BOM
2nModeLoad := 2 / nModeSave := 2UTF-8 without BOM
3nModeLoad := 3 / nModeSave := 3UTF-16 Little Endian

Editor Control Comparison

ControlSource FileFeatures
TEditedit.prgBasic edit, multi-line memo mode, no RTF support
TGettget.prgSingle-line input, picture clauses, input validation
TMultiGetmget.prgMulti-line text, no formatting, basic editing
TRichEdittrichedi.prgRTF 2.0 (riched20.dll), basic font/color formatting
TRichEdit5triched5.prgRTF 5.0 (msftedit.dll), tables, images, PDF export
TTxtEditttxtedit.prgSource code display, syntax highlighting, line numbers
TScintillascintila.prgFull IDE-class editor, code folding, lexers, bookmarks, search/replace, multi-encoding

Notes

Veja Também