Try changing the 0 to 1.BarryG wrote:But this doesn't let me press Ctrl+Z to undo the replace, like pasting does. What to do?Code: Select all
SendMessage_(GadgetID(gadget),#EM_REPLACESEL,0,@text$)
Select text / get selection for StringGadget/EditorGadget
Re: Select text / get selection for StringGadget/EditorGadge
Re: Select text / get selection for StringGadget/EditorGadge
Thank you!wombats wrote:Try changing the 0 to 1.
Re: Select text / get selection for StringGadget/EditorGadge
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:
Having the ability to set/get the selection as part of PB would be great.
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
Re: Select text / get selection for StringGadget/EditorGadge
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
http://forums.purebasic.com/french/view ... &view=next
Re: Select text / get selection for StringGadget/EditorGadge
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.IdeasVacuum wrote:Code: Select all
Procedure.s GetSelectedEditorText(iEdId.i)
(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