clipboard functions
Posted: Sun Dec 08, 2019 11:58 pm
Hello,
I am trying this 'navigator.clipboard'
The COPY function seems to work fine
The PASTE function however behaves strangly.
The alertbox reports that PASTE worked, but the procedure returns an unchanged 'none'
The alertbox als seems to pop up after the procedure returns ????
Anyone knows how the handle the async behavier.
I am trying this 'navigator.clipboard'
The COPY function seems to work fine
The PASTE function however behaves strangly.
The alertbox reports that PASTE worked, but the procedure returns an unchanged 'none'
The alertbox als seems to pop up after the procedure returns ????
Anyone knows how the handle the async behavier.
Code: Select all
Enumeration FormGadget
#Editorwindow
#Editorfield
#button_editor_close
#button_editor_edit
#button_editor_copy
#button_editor_paste
#button_clienteditorcopy
EndEnumeration
Procedure setclipboardtext(text.s)
!navigator.clipboard.writeText(v_text)
! .then(() => {
! // Success!
! })
! .catch(err => {
! alert("setclipboard failed:" . err);
! }) ;
EndProcedure
Procedure.s getclipboardtext()
text.s = "none"
! navigator.clipboard.readText()
! .then(v_text => {
! alert(v_text);
! })
! .catch(err => {
! alert("getclipboard failed:" . err);
! }) ;
ProcedureReturn text.s
EndProcedure
Procedure COPY()
setclipboardtext(GetGadgetText(#Editorfield))
EndProcedure
Procedure PASTE()
tmp.s = GetGadgetText(#Editorfield)
SetGadgetText(#Editorfield,tmp + getclipboardtext())
EndProcedure
;EDITOR WINDOW
;============================================================================================================================
OpenWindow(#Editorwindow,10,10,520,520, "COPY / PASTE TEST...",#PB_Window_TitleBar | #PB_Window_AllowSelection)
SetWindowColor(#Editorwindow,RGB(0,0,125))
EditorGadget(#Editorfield,10,10,500,300,#PB_Editor_WordWrap)
ButtonGadget(#button_editor_copy,10,320,500,50,"C O P Y")
ButtonGadget(#button_editor_paste,10,380,500,50, "P A S T E")
SetGadgetText(#Editorfield,GetGadgetText(sourcetextfield))
BindGadgetEvent(#button_editor_copy, @COPY())
BindGadgetEvent(#button_editor_paste, @PASTE())