I don't understand why I should create a lexer. If I don’t understand, then even if it’s easy to do, I won’t be able to do it, because I don’t think it’s necessary to create a lexer if it exists. If it works this way, then this order of things will have to be accepted.
Code: Select all
EnableExplicit
Define NbLexers, *Buffer, i, k, *Text, File$, PureBasicLexer, w, h
Procedure.s ReadFileToVar(Path$)
Protected id_file, Format, Text$
id_file = ReadFile(#PB_Any, Path$)
If id_file
Format = ReadStringFormat(id_file)
Text$ = ReadString(id_file, Format | #PB_File_IgnoreEOL)
CloseFile(id_file)
EndIf
ProcedureReturn Text$
EndProcedure
File$ = OpenFileRequester("OpenFileRequester", GetCurrentDirectory(), "*.htm|*.htm|*.pb|*.pb;*.pbi", 0)
If Asc(File$)
; If Not (Right(File$, 3) = ".pb" Or Right(File$, 4) = ".pbi")
; File$ + ".pb"
; EndIf
If FileSize(File$) < 0
End
EndIf
Else
End
EndIf
Prototype.i CreateLexerProto(name.p - utf8)
Prototype.i GetLexerCountProto()
Prototype GetLexerNameProto(index.i, *BufferName, *BufferNameLength)
If OpenLibrary(0, "Lexilla.dll")
Define CreateLexer.CreateLexerProto = GetFunction(0, "CreateLexer")
Define GetLexerCount.GetLexerCountProto = GetFunction(0, "GetLexerCount")
Define GetLexerName.GetLexerNameProto = GetFunction(0, "GetLexerName")
If CreateLexer = 0 Or GetLexerCount = 0 Or GetLexerName = 0
Debug "Invalid Lexilla lib"
End
EndIf
EndIf
; List all available lexers
;
NbLexers = GetLexerCount()
; Debug "NbLexers: "+NbLexers
*Buffer = AllocateMemory(128)
For k = 0 To NbLexers - 1
GetLexerName(k, *Buffer, MemorySize(*Buffer))
; Debug PeekS(*Buffer, MemorySize(*Buffer), #PB_UTF8)
; If PeekS(*Buffer, MemorySize(*Buffer), #PB_UTF8) = "hypertext"
; Debug k
; EndIf
Next
FreeMemory(*Buffer)
ExamineDesktops()
w = DesktopWidth(0)
h = DesktopHeight(0)
If OpenWindow(0, 0, 0, w, h - 40, "ScintillaGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If Not InitScintilla()
End
EndIf
ScintillaGadget(0, 10, 10, w - 20, h - 60, 0)
ScintillaSendMessage(0, #SCI_STYLESETSIZE, #STYLE_DEFAULT, 12) ; font size
ScintillaSendMessage(0, #SCI_STYLECLEARALL)
ScintillaSendMessage(0, #SCI_STYLESETBACK, #STYLE_DEFAULT, $3f3f3f)
ScintillaSendMessage(0, #SCI_SETSELBACK, 1, $a0a0a0) ; the background color of the selection
ScintillaSendMessage(0, #SCI_SETSELALPHA, 100) ; transparency of the selection
For i = 0 To 32
ScintillaSendMessage(0, #SCI_STYLESETBACK, i, $3f3f3f)
ScintillaSendMessage(0, #SCI_STYLESETFORE, i, $999999) ; default text color
Next
PureBasicLexer = CreateLexer("hypertext")
ScintillaSendMessage(0, #SCI_SETILEXER, 0, PureBasicLexer)
; HTML
ScintillaSendMessage(0, #SCI_STYLESETFORE, 1, $FF9F00) ; Comments
ScintillaSendMessage(0, #SCI_STYLESETFORE, 2, $9CCBEB) ; Numbers
ScintillaSendMessage(0, #SCI_STYLESETFORE, 3, $8080FF) ; Keyword1
ScintillaSendMessage(0, #SCI_STYLESETFORE, 4, $999999) ; Lines
ScintillaSendMessage(0, #SCI_STYLESETFORE, 6, $72ADC0) ; Operators
ScintillaSendMessage(0, #SCI_STYLESETFORE, 7, $F78865) ; Keyword Identifier
ScintillaSendMessage(0, #SCI_STYLESETFORE, 10, $72ADC0); Keyword2
ScintillaSendMessage(0, #SCI_STYLESETFORE, 11, $FF8000); Keyword3
ScintillaSendMessage(0, #SCI_STYLESETFORE, 12, $71AE71); Keyword4
ScintillaSendMessage(0, #SCI_STYLESETFORE, 13, $DE98D9); Constants
ScintillaSendMessage(0, #SCI_STYLESETFORE, 15, $00FFFF); Label
ScintillaSendMessage(0, #SCI_STYLESETFORE, 16, $8080FF); Error
ScintillaSendMessage(0, #SCI_STYLESETFORE, 17, $D3D08C); Hexnumber
ScintillaSendMessage(0, #SCI_STYLESETFORE, 18, $D3D08C); Binnumber
; PureBasic
; ScintillaSendMessage(0, #SCI_STYLESETFORE, 1, $71AE71) ; Comments
; ScintillaSendMessage(0, #SCI_STYLESETFORE, 2, $9CCBEB) ; Numbers
; ScintillaSendMessage(0, #SCI_STYLESETFORE, 3, $FF9F00) ; Keyword1
; ScintillaSendMessage(0, #SCI_STYLESETFORE, 4, $999999) ; Lines
; ScintillaSendMessage(0, #SCI_STYLESETFORE, 6, $8080FF) ; Operators
; ScintillaSendMessage(0, #SCI_STYLESETFORE, 7, $72ADC0) ; Keyword Identifier
; ScintillaSendMessage(0, #SCI_STYLESETFORE, 10, $FF9F00); Keyword2
; ScintillaSendMessage(0, #SCI_STYLESETFORE, 11, $FF8000); Keyword3
; ScintillaSendMessage(0, #SCI_STYLESETFORE, 12, $F78865); Keyword4
; ScintillaSendMessage(0, #SCI_STYLESETFORE, 13, $DE98D9); Constants
; ScintillaSendMessage(0, #SCI_STYLESETFORE, 15, $00FFFF); Label
; ScintillaSendMessage(0, #SCI_STYLESETFORE, 16, $8080FF); Error
; ScintillaSendMessage(0, #SCI_STYLESETFORE, 17, $D3D08C); Hexnumber
; ScintillaSendMessage(0, #SCI_STYLESETFORE, 18, $D3D08C); Binnumber
; Set the text to the ScintillaGadget
*Text = UTF8(ReadFileToVar(File$))
ScintillaSendMessage(0, #SCI_SETTEXT, 0, *Text)
FreeMemory(*Text) ; The buffer made by UTF8() has to be freed, to avoid memory leak
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf