Inserting code into the Editor
Inserting code into the Editor
When using the Color picker from the Tools menu. You can find a color you want and then by just clicking
on the insert color button, it inserts the code right where you left the cursor at in the editor code window.
I would really appreciate learning how to do that. It's a neat feature that I would like to use in some programs
I'm using. I especially like the fact that it places the code right where you want it to be. And from an independently
running program too.
Any advice and code ideas or examples would be greatly appreciated.
Thank you for your help.
on the insert color button, it inserts the code right where you left the cursor at in the editor code window.
I would really appreciate learning how to do that. It's a neat feature that I would like to use in some programs
I'm using. I especially like the fact that it places the code right where you want it to be. And from an independently
running program too.
Any advice and code ideas or examples would be greatly appreciated.
Thank you for your help.
Thanks for your reply, and ...
Woops
your right it's not. I've seen a few color pickers on the forum and even one that I put on the forum myself.
I guess I had those other programs on my mind when I asked the question. and should have thought about it more carefully
before asking that question. I kind of wanted to use my color picker program instead of the default one.
Is there a way that anyone might know of that it may be possible to code, to allow you to take something from one running app and
send it to another app with out manually copying and pasting?
Thanks for your input.
Woops

I guess I had those other programs on my mind when I asked the question. and should have thought about it more carefully
before asking that question. I kind of wanted to use my color picker program instead of the default one.
Is there a way that anyone might know of that it may be possible to code, to allow you to take something from one running app and
send it to another app with out manually copying and pasting?
Thanks for your input.
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Code: Select all
OpenWindow(0,0,0,320,240,"",$CA0001)
CreateGadgetList(WindowID(0))
EditorGadget(0,0,0,320,200)
ButtonGadget(1,120,210,80,20,"Add France")
SetGadgetText(0, "The rain in Spain falls mainly on the plain.")
Repeat
ev = WaitWindowEvent()
Select ev
Case #PB_Event_Gadget
Select EventGadget()
Case 1
SetActiveGadget(0)
SendMessage_(GadgetID(0), #EM_SETSEL, 18,18)
SendMessage_(GadgetID(0), #EM_REPLACESEL, 1, @" and France ")
EndSelect
EndSelect
Until ev = #WM_CLOSE
BERESHEIT
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
If I'm at the screen when a question gets posted, I don't lose too many! Some, but not many.
A scintilla gadget like the current PB editor uses will have its own messages you can send, but afaik it's a subclassed richedit control, so the normal messages should work too. I'm not too up on scintilla atm. It's on the todo list for someday as it looks quite interesting.
A scintilla gadget like the current PB editor uses will have its own messages you can send, but afaik it's a subclassed richedit control, so the normal messages should work too. I'm not too up on scintilla atm. It's on the todo list for someday as it looks quite interesting.
BERESHEIT
http://www.purebasic.fr/english/viewtop ... 6111#25039
Like that code that freak posted, but it doesn't work with editor gadgets with multiple lines, I can't figure out how to edit it to do so.
Like that code that freak posted, but it doesn't work with editor gadgets with multiple lines, I can't figure out how to edit it to do so.
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Code: Select all
Heres the code:
; PureBasic Visual Designer v3.70a Beta
;- Window Constants
;
#Window_0 = 0
;- Gadget Constants
;
#Gadget_1 = 0
#original = 1
#start = 2
Procedure Open_Window_0()
If OpenWindow(#Window_0, 402, 160, 293, 79, "test", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar)
If CreateGadgetList(WindowID(#Window_0))
TextGadget(#Gadget_1, 10, 10, 100, 30, "Enter String and select a piece:")
EditorGadget(#original, 110, 10, 170, 133)
ButtonGadget(#start, 10, 40, 70, 20, "make bold")
EndIf
EndIf
EndProcedure
Open_Window_0()
Repeat
Event = WaitWindowEvent()
If event = #PB_Event_Gadget And EventGadget() = #start
original.s = GetGadgetText(#original) ; get strings from Gadget
new.s = ""
; get selected position from #original Gadget
SendMessage_(GadgetID(#original), #EM_GETSEL, @startpos.l, @endpos.l)
new = Left(original, startpos) ; unselected part on the left
new + "<B>" ; bold mark
new + Mid(original, startpos+1, endpos-startpos) ; marked text
new + "</B>" ; unbold mark
new + Right(original, Len(original)-endpos) ; unselected part on the right
SetGadgetText(#original, new) ; set new text
; set selection again (3 characters right of original position, because we
; added the <b>
SendMessage_(GadgetID(#original), #EM_SETSEL, startpos+3, endpos+3)
setActiveGadget(#original) ; activate Gadget again
EndIf
Until Event = #PB_Event_CloseWindow
End
And then put your cursor between s and a on the last linefdsfdsfjkdjsla
fjdsklfjdsl
dsada
and try entering the bold stuff
doesn't work right here...
I get:
jkjkl
jkl
<B></B>
hjk
I'm not sure what you're after, but try this :
Code: Select all
; PureBasic Visual Designer v3.70a Beta
;- Window Constants
;
#Window_0 = 0
;- Gadget Constants
;
#Gadget_1 = 0
#original = 1
#start = 2
Procedure Open_Window_0()
If OpenWindow(#Window_0, 402, 160, 293, 79, "test", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar)
If CreateGadgetList(WindowID(#Window_0))
TextGadget(#Gadget_1, 10, 10, 100, 30, "Enter String and select a piece:")
EditorGadget(#original, 110, 10, 170, 133)
ButtonGadget(#start, 10, 40, 70, 20, "make bold")
EndIf
EndIf
EndProcedure
Open_Window_0()
Repeat
Event = WaitWindowEvent()
If event = #PB_Event_Gadget And EventGadget() = #start
a$=""
SendMessage_(GadgetID(#original), #EM_GETSEL, @startpos.l, @endpos.l)
If endpos > startpos
a$=Space(endpos-startpos+1)
SendMessage_(GadgetID(#original), #EM_GETSELTEXT, 0, @a$)
EndIf
a$ = "<B>"+a$+"</B>"
SendMessage_(GadgetID(#original), #EM_REPLACESEL, #True, @a$)
SetActiveGadget(#original) ; activate Gadget again
EndIf
Until Event = #PB_Event_CloseWindow
End
I may look like a mule, but I'm not a complete ass.
Try this code selecting a position with the mouse and pasting.
I still would like to know if it's possible to send code from an external app to the editor if it can be done?
Code: Select all
OpenWindow(0,0,0,320,240,"",$CA0001)
CreateGadgetList(WindowID(0))
EditorGadget(0,0,0,320,200)
ButtonGadget(1,60,210,220,20,"use mouse to select a place and press this")
SetGadgetText(0, "The rain in Spain falls mainly on the plain."+Chr(10)+"The rain in France falls mainly on the plain.")
Repeat
ev = WaitWindowEvent()
Select ev
Case #PB_Event_Gadget
SendMessage_(GadgetID(0), #EM_GETSEL, @startpos.l, @endpos.l)
Select EventGadget()
Case 1
a$ = " [I put this here] "
SetActiveGadget(0)
SendMessage_(GadgetID(0), #EM_REPLACESEL, #True, @a$)
EndSelect
EndSelect
Until ev = #WM_CLOSE
Thank you srod and yrreti they both worked perfect.
srod, How do you not know what I was after?
I was trying to enter text at the location of the cursor in a editor gadget. The code freak posted would not work with multi-line text, the string to be added at the cursor's position was not added there correctly.
Matt
Question:
SendMessage_(GadgetID(0), #EM_GETSEL, @startpos.l, @endpos.l)
what is that line doing in yrreti's code? I suppose nothing?
srod, How do you not know what I was after?

I was trying to enter text at the location of the cursor in a editor gadget. The code freak posted would not work with multi-line text, the string to be added at the cursor's position was not added there correctly.
Matt
Question:
SendMessage_(GadgetID(0), #EM_GETSEL, @startpos.l, @endpos.l)
what is that line doing in yrreti's code? I suppose nothing?