How to insert code to IDE on Mac and Linux

Just starting out? Need help? Post your questions and find answers here.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8433
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

How to insert code to IDE on Mac and Linux

Post by netmaestro »

Here is a proc I'm using on Windows to insert code to the IDE for an external tool:

Code: Select all

Procedure MakeScintillaText(text.s)
  Static sciText.s
  sciText = Space(StringByteLength(text, #PB_UTF8))
  PokeS(@sciText, text, -1, #PB_UTF8)
  ProcedureReturn @sciText
EndProcedure

Procedure InsertHandler()
  scintilla.i = Val(GetEnvironmentVariable("PB_Tool_Scintilla"))
  If scintilla
    *textBuffer = MakeScintillaText(#CRLF$+"; Code inserted by Vector Curve Designer" +
                                    #CRLF$+GetGadgetText(gadget_output)+#CRLF$ +
                                    "; End of Curve Designer Code"+#CRLF$)
    SendMessage_(scintilla, #EM_REPLACESEL, 0, *textBuffer)
  Else
    MessageRequester("Notice:","Scintilla editor not found!"+#CRLF$+#CRLF$ +
                               "Invoke Curve Designer tool from the PureBasic IDE for this feature.")
  EndIf
EndProcedure
Can someone help with code that will do the same task from MacOS and also Linux? Any help appreciated.
BERESHEIT
infratec
Always Here
Always Here
Posts: 6883
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: How to insert code to IDE on Mac and Linux

Post by infratec »

Why API :?:

This should be crossplatform:

Code: Select all

EnableExplicit


Procedure InsertHandler(SourceGadget.i, TargetScintillaGadget.i)
  
  Protected *textBuffer
  
  If IsGadget(TargetScintillaGadget)
    
    *textBuffer = UTF8(#LF$+"; Code inserted by Vector Curve Designer" +
                       #LF$+GetGadgetText(SourceGadget)+#LF$ +
                       "; End of Curve Designer Code"+#LF$)
    If *textBuffer
      ScintillaSendMessage(TargetScintillaGadget, #SCI_REPLACESEL, #Null, *textBuffer)
      FreeMemory(*textBuffer)
    EndIf
    
  Else
    MessageRequester("Notice:","Scintilla editor not found!"+#LF$+#LF$ +
                               "Invoke Curve Designer tool from the PureBasic IDE for this feature.")
  EndIf
EndProcedure



Define Event.i

InitScintilla()

OpenWindow(0,0,0,400,300,"")
StringGadget(0, 10, 10, 380, 70, "Hello world!")
ScintillaGadget(1, 10, 90, 380, 160, #Null)

ButtonGadget(2, 10, 270, 50, 20, "Replace")

InsertHandler(0, 1)

Repeat 
  Event = WaitWindowEvent()
  
  If event = #PB_Event_Gadget And EventGadget() = 2
    InsertHandler(0, 1)
  EndIf
  
Until Event = #PB_Event_CloseWindow
P.S.: I would have saved me 10 minutes, if you provided a working example.
If 6 of us have to do this, than 1 hour of time is wasted instead of 10 minutes from you.
User avatar
Bisonte
Addict
Addict
Posts: 1233
Joined: Tue Oct 09, 2007 2:15 am

Re: How to insert code to IDE on Mac and Linux

Post by Bisonte »

@Infratec:

You missed the part about the "external tool".
So you don't have the PB_Gadget_Object Number. Only the OS ID of the scintilla....
PureBasic 6.10 LTS (Windows x86/x64) | Windows10 Pro x64 | Asus TUF X570 Gaming Plus | R9 5900X | 64GB RAM | GeForce RTX 3080 TI iChill X4 | HAF XF Evo | build by vannicom​​
English is not my native language... (I often use DeepL to translate my texts.)
infratec
Always Here
Always Here
Posts: 6883
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: How to insert code to IDE on Mac and Linux

Post by infratec »

As often ... read to fast. :oops:

But with a full working example ...
User avatar
Danilo
Addict
Addict
Posts: 3037
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: How to insert code to IDE on Mac and Linux

Post by Danilo »

Bisonte wrote:@Infratec:

You missed the part about the "external tool".
So you don't have the PB_Gadget_Object Number. Only the OS ID of the scintilla....
Maybe it works when importing the external gadgetID into the gadget objects,
so you can use ScintillaSendMessage() with the external scintilla control?

Code: Select all

CompilerIf #PB_Compiler_OS = #PB_OS_Windows
  Import ""
CompilerElse
  ImportC ""
CompilerEndIf
    PB_Object_GetOrAllocateID.i(*Object, ID)
    PB_Gadget_Objects.i
  EndImport
 
EnableExplicit

Procedure.i ImportScintillaID(gadgetID)
    Protected *gadget.Integer = PB_Object_GetOrAllocateID(PB_Gadget_Objects,#PB_Any)
    If *gadget
        *gadget\i = gadgetID
        ProcedureReturn *gadget
    EndIf
EndProcedure


Procedure InsertHandler(SourceGadget.i, TargetScintillaGadget.i)
 
  Protected *textBuffer
 
  If IsGadget(TargetScintillaGadget)
   
    *textBuffer = UTF8(#LF$+"; Code inserted by Vector Curve Designer" +
                       #LF$+GetGadgetText(SourceGadget)+#LF$ +
                       "; End of Curve Designer Code"+#LF$)
    If *textBuffer
      ScintillaSendMessage(TargetScintillaGadget, #SCI_REPLACESEL, #Null, *textBuffer)
      FreeMemory(*textBuffer)
    EndIf
   
  Else
    MessageRequester("Notice:","Scintilla editor not found!"+#LF$+#LF$ +
                               "Invoke Curve Designer tool from the PureBasic IDE for this feature.")
  EndIf
EndProcedure



Define Event.i, scintilla, scintillaID

If InitScintilla()

    OpenWindow(0,0,0,400,300,"")
    StringGadget(0, 10, 10, 380, 70, "Hello world!")
    ScintillaGadget(1, 10, 90, 380, 160, #Null)
   
    ButtonGadget(2, 10, 270, 50, 20, "Replace")
    
    scintillaID = GadgetID(1) ;Val(GetEnvironmentVariable("PB_Tool_Scintilla"))
    
    scintilla = ImportScintillaID( scintillaID )
   
    InsertHandler(0, scintilla)
   
    Repeat
      Event = WaitWindowEvent()
     
      If event = #PB_Event_Gadget And EventGadget() = 2
        InsertHandler(0, scintilla)
      EndIf
     
    Until Event = #PB_Event_CloseWindow
   
EndIf
For security reasons you shouldn't be able to access the memory of other processes easily, but it seems to work on Windows OS?
Wolfram
Enthusiast
Enthusiast
Posts: 568
Joined: Thu May 30, 2013 4:39 pm

Re: How to insert code to IDE on Mac and Linux

Post by Wolfram »

Hello everybody,

are there any news how to run this on macOS? I have tried Danilo example, but it dose't work.
macOS Catalina 10.15.7
Post Reply