The environment variable "PB_TOOL_Scintilla" allows to control the PB editor
I started with the idea of making a small tool to propose the constants associated with the procedure parameters
but scintilla is not easy to tame, as soon as there is something he doesn't like, the editor crashes.
below, my test program:
its purpose is simply to read the intstruction on which the cursor is located and replace it with "hello".
to simplify my task (especially because of the untimely crashes), I made myself a test mode (defined in the 1st line)
if #test=1:
in this mode I create a scintillaGadget and I do my tests with
the function is executed when I click on the test button
otherwise:
you need to create an executable that should be defined as a custom tool
the function is executed via a keyboard shortcut
(see doc PB)
problem:
some functions of Scintilla work from the gadget (test mode) but not from the editor
in the example below SCI_ADDTEXT leads to a crash
Probably a character encoding or pointer/memory address problem.
So, I'm asking for help from the specialists of Scintilla.
Code: Select all
#test=1
CompilerIf #test
InitScintilla()
Declare test()
OpenWindow(0,0,0,800,600,"",#PB_Window_ScreenCentered):SetWindowColor(0,$aaaaaa)
ButtonGadget(1,10,5,80,20,"test"):BindGadgetEvent(1,@ test())
ScintillaGadget(0,10,30,780,560,0)
ScintillaSendMessage(0, #SCI_SETTEXT, 0, UTF8(~"azerty\n123456:789:0123\nqsdfg"))
Procedure Send(Message, *wParam = #Null, *lParam = #Null)
ProcedureReturn ScintillaSendMessage(0, Message, *wParam, *lParam)
EndProcedure
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
CompilerElse
Global PB_TOOL_Scintilla.i = Val(GetEnvironmentVariable("PB_TOOL_Scintilla")):If (PB_TOOL_Scintilla=0):End:EndIf
CompilerSelect (#PB_Compiler_OS)
CompilerCase (#PB_OS_Windows)
Procedure Send(Message, *wParam = #Null, *lParam = #Null)
ProcedureReturn SendMessage_(PB_TOOL_Scintilla, Message, *wParam, *lParam)
;Protected val:SendMessageTimeout_(PB_TOOL_Scintilla, Message, *wParam, *lParam, #SMTO_ABORTIFHUNG, 2000, @ val):ProcedureReturn val
EndProcedure
; pour les autres...
CompilerEndSelect
CompilerEndIf
Procedure test()
Protected p,pi,pf,l,c.a,txt.s
l=send(#SCI_GETLENGTH)
p=Send(#SCI_GETSELECTIONSTART) -1
pi=p
While pi>=0
c=send(#SCI_GETCHARAT, pi)
If c=10 Or c=13 Or c=58:Break:EndIf
txt=Chr(c)+txt
pi-1
Wend
pf=p+1
While pf<l
c=send(#SCI_GETCHARAT, pf)
If c=10 Or c=13 Or c=58:Break:EndIf
txt+Chr(c)
pf+1
Wend
MessageRequester("","txt: "+txt)
send(#SCI_DELETERANGE,pi+1,pf-pi-1)
txt="bonjour"
send(#SCI_ADDTEXT,Len(Txt), UTF8(txt))
EndProcedure
If ProgramParameter(0)="test":test():EndIf