Page 1 of 2
Inserting code into the Editor
Posted: Sun Dec 09, 2007 8:53 pm
by yrreti
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.
Posted: Sun Dec 09, 2007 9:56 pm
by Trond
The colour picker isn't an independently running program.
Posted: Sun Dec 09, 2007 10:56 pm
by yrreti
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.
Posted: Sun Dec 09, 2007 11:05 pm
by Matt
On the same topic,
how can I insert text into an editor gadget at the current cursor's position?
Posted: Sun Dec 09, 2007 11:13 pm
by netmaestro
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
Posted: Sun Dec 09, 2007 11:18 pm
by srod
Beat me by precisely 3.2 seconds!

Posted: Sun Dec 09, 2007 11:22 pm
by Matt
Thanks, yes, I tried that, but
My problem: how do I deal with the returns entered into the editor gadget though.
Try typing, press return a few times, time some more and then try entering it on the 4th line or so.
Posted: Sun Dec 09, 2007 11:22 pm
by netmaestro
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.
Posted: Sun Dec 09, 2007 11:26 pm
by Matt
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.
Posted: Sun Dec 09, 2007 11:44 pm
by netmaestro
Sorry, I don't understand the problem. The same method works here to insert text on one of the empty lines after pressing return a few times.
Posted: Mon Dec 10, 2007 12:08 am
by Matt
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
Try typing this in the box:
fdsfdsfjkdjsla
fjdsklfjdsl
dsada
And then put your cursor between s and a on the last line
and try entering the bold stuff
doesn't work right here...
I get:
jkjkl
jkl
<B></B>
hjk
Posted: Mon Dec 10, 2007 12:24 am
by srod
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
Posted: Mon Dec 10, 2007 1:09 am
by yrreti
Try this code selecting a position with the mouse and pasting.
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
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?
Posted: Mon Dec 10, 2007 2:24 am
by Matt
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?
Posted: Mon Dec 10, 2007 2:59 am
by yrreti
Your right, that line is not needed. It was just some code
from another project that I didn't remove and wasn't sure about.