Customized tools

Just starting out? Need help? Post your questions and find answers here.
User avatar
pf shadoko
Enthusiast
Enthusiast
Posts: 280
Joined: Thu Jul 09, 2015 9:07 am

Customized tools

Post by pf shadoko »

Hello,

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
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: Customized tools

Post by kenmo »

Yes, it's a problem because the IDE's Scintilla cannot read string memory allocated by the tool.

The best way is to probably allocate shared memory using OS functions... someone else could help with that.

But a quick workaround is to temporarily use the clipboard :)

Code: Select all

Procedure test()
  Send(#SCI_BEGINUNDOACTION)
  
  If Send(#SCI_GETSELECTIONEMPTY)
    Cursor.i = Send(#SCI_GETCURRENTPOS)
    Start.i = Send(#SCI_WORDSTARTPOSITION, Cursor, #True)
    Stop.i = Send(#SCI_WORDENDPOSITION, Cursor, #True)
    Send(#SCI_SETSEL, Start, Stop)
  EndIf
    
  PrevText.s = GetClipboardText()
  SetClipboardText("bonjour")
  Send(#SCI_PASTE)
  SetClipboardText(PrevText)
  
  Send(#SCI_ENDUNDOACTION)
EndProcedure
User avatar
pf shadoko
Enthusiast
Enthusiast
Posts: 280
Joined: Thu Jul 09, 2015 9:07 am

Re: Customized tools

Post by pf shadoko »

Thank you for your response
I hope this problem will be solved.
full dialogue with scintilla could be very useful

PS:
to copy text to the cursor position, you can also do this:
send(#EM_REPLACESEL,0, UTF8("bonjour"))
Post Reply