Page 1 of 1
How to insert code to IDE on Mac and Linux
Posted: Sat May 23, 2020 9:59 pm
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.
Re: How to insert code to IDE on Mac and Linux
Posted: Sun May 24, 2020 9:34 am
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.
Re: How to insert code to IDE on Mac and Linux
Posted: Sun May 24, 2020 10:54 am
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....
Re: How to insert code to IDE on Mac and Linux
Posted: Sun May 24, 2020 11:53 am
by infratec
As often ... read to fast.
But with a full working example ...
Re: How to insert code to IDE on Mac and Linux
Posted: Sun May 24, 2020 2:13 pm
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?
Re: How to insert code to IDE on Mac and Linux
Posted: Sun Jan 01, 2023 11:38 am
by Wolfram
Hello everybody,
are there any news how to run this on macOS? I have tried Danilo example, but it dose't work.