Page 2 of 2
Re: Select text / get selection for StringGadget/EditorGadge
Posted: Sun Sep 22, 2019 5:59 am
by wombats
BarryG wrote:Code: Select all
SendMessage_(GadgetID(gadget),#EM_REPLACESEL,0,@text$)
But this doesn't let me press Ctrl+Z to undo the replace, like pasting does. What to do?
Try changing the 0 to 1.
Re: Select text / get selection for StringGadget/EditorGadge
Posted: Sun Sep 22, 2019 8:10 am
by BarryG
wombats wrote:Try changing the 0 to 1.
Thank you!
Re: Select text / get selection for StringGadget/EditorGadge
Posted: Sat Oct 26, 2019 5:09 pm
by wombats
This is possible across Windows, macOS and GTK with API, but there isn't a way to set the selection (aside from selecting all of it) with QtScript on Qt. We can
get the selection, however:
Code: Select all
CompilerIf Subsystem("qt")
Runtime Procedure OnSelectionChanged()
Protected txt.s
txt = QtScript("gadget(0).selectedText")
SetGadgetText(1, txt)
EndProcedure
If OpenWindow(0, 0, 0, 320, 100, "FrameGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
StringGadget(0, 10, 10, 300, 25, "hello")
TextGadget(1, 10, 40, 300, 30, "")
QtScript(~"gadget(0).selectionChanged.connect(function() { runtime.call(\"OnSelectionChanged()\"); })")
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
CompilerElse
MessageRequester("", "Qt subsystem required.")
CompilerEndIf
Having the ability to set/get the selection as part of PB would be great.
Re: Select text / get selection for StringGadget/EditorGadge
Posted: Tue Oct 13, 2020 7:59 pm
by Olli
Also
vera gave a code, thanking the root coder of this tip. (thank you vera and omi !)
http://forums.purebasic.com/french/view ... &view=next
Re: Select text / get selection for StringGadget/EditorGadge
Posted: Sun Jan 31, 2021 10:07 am
by BarryG
IdeasVacuum wrote:Code: Select all
Procedure.s GetSelectedEditorText(iEdId.i)
IdeasVacuum, your code doesn't seem to work anymore. Look at below. Any fix? Note: I'd like this to work with multi-line StringGadgets, too.
(And can Fred please finally add these features to the next release?)
Code: Select all
Procedure.s GetSelectedEditorText(iEdId.i)
Protected sSelected.s, Range.CHARRANGE, iSize.i
SendMessage_(GadgetID(iEdId), #EM_EXGETSEL, 0, Range)
iSize = (Range\cpMax - Range\cpMin)
sSelected = Space((iSize * 2) + 1)
SendMessage_(GadgetID(iEdId),#EM_GETSELTEXT, 0, sSelected)
ProcedureReturn(sSelected)
EndProcedure
OpenWindow(0,200,200,300,50,"test",#PB_Window_SystemMenu)
StringGadget(0,10,10,280,25,"Select one of these words and see Debug output")
Repeat
ev=WaitWindowEvent()
If ev=#WM_LBUTTONUP
Debug ">"+GetSelectedEditorText(0)+"<"
EndIf
Until ev=#PB_Event_CloseWindow