Page 1 of 1
'pasteKey' message
Posted: Fri Aug 09, 2013 6:28 pm
by lohill
Does the pasteKey message work? U would like to capture some clipboardData and do some processing on it before it shows up in the field. As a test I have put the code below in the script of a particular field. The script does not get executed when I paste into that field. Any ideas on how to do this?
on pasteKey
put the clipboarddata into tData
answer tData
end pasteKey
Thanks,
Larry
Re: 'pasteKey' message
Posted: Fri Aug 09, 2013 10:48 pm
by dunbarx
It works. But the IDE traps it, so you have to suspend development tools to use it yourself. See the dictionary entry.
Craig Newman
Re: 'pasteKey' message
Posted: Sat Aug 10, 2013 12:00 am
by lohill
Thanks Craig,
I read the dictionary for pasteKey and if I did the 'suspend development tools' correctly it still did not work for me. Does the fact that I have an Edit Menu with a choice for paste have any effect?
Larry
Re: 'pasteKey' message
Posted: Sat Aug 10, 2013 2:23 am
by dunbarx
Must be. Can you pass the "pasteKey" message in the menu button script and check again?
I made a field with this script:
Code: Select all
on pastekey
put the clipboardData && random(99) into me
end pastekey
Suspend development tools, get some text into the clipboard and paste a few times. Works.
Craig
Re: 'pasteKey' message
Posted: Sat Aug 10, 2013 5:59 pm
by lohill
Craig,
Interesting situation because your suggestion definitely works on a test stack with a test field. I tried passing the "pasteKey" message in the menu button script of my stack. The 'compiler' would not accept "pass pasteKey" or "pass 'pasteKey'". I tried pass menu pick pWhich to no avail. Finally I tried: dispatch "pasteKey" to field "RadiScript" and it did work. The problem with that is that I don't want 'pasteKey' sent to that specific field every time someone pastes into some other field. Is there a way to get around that?
Regards,
Larry
Re: 'pasteKey' message
Posted: Sat Aug 10, 2013 9:26 pm
by lohill
Craig,
I also learned that dispatch "pasteKey" to field "RadiScreen" works whether or not I have suspended the development tools. Now if I can get my field not to worry about the message at inappropriate times.
Larry
Re: 'pasteKey' message
Posted: Sat Aug 10, 2013 9:37 pm
by dunbarx
Nice workaround.
Explicitly sending the message gives it its own life. Nothing wrong with taking that tack all the way.
Craig
Re: 'pasteKey' message
Posted: Sat Aug 10, 2013 11:41 pm
by lohill
It has too much life! When I paste in another field that data seems to end up in my Radiscript field as well. How can I determine what field I was in when the pastKey was sent?
Larry
Re: 'pasteKey' message
Posted: Sat Aug 10, 2013 11:58 pm
by dunbarx
Hi.
This is all solvable with "targets" and the like. But sometimes rethinking is called for when things get convoluted or overdependent.
What are your scripts?
Craig
Re: 'pasteKey' message
Posted: Mon Aug 12, 2013 6:00 pm
by lohill
Hi Craig,
I'm sorry I took so long to get back. I messed around with 'target' for a while and couldn't get anywhere. I finally have come up with this that I think is working OK even though it is not very pretty. It seems that no matter how ugly I make it LiveCode doesn't seem to have any problems handling it. Here are parts of the code for what I now have:
Global variable declared in stack script: gScreenField
In button Edit for the stack:
case "Paste"
If the clipboard is "text" then paste
dispatch "pasteSpecial" to card "Screens"
break
In Script of card "Screens::
on pasteSpecial
global gScreenField
if gScreenField ="Radiscript" then
dispatch "pasteSpecial" to field "RadiScript"
end if
end pasteSpecial
In the script for field "Radiscript" of card "Screens"
on openField
global gScreenField
put the short name of me into gScreenField
end openField
on pasteSpecial
put the clipboarddata into tData
replace tab with space in tData
replace " " with space in tData
repeat with i=1 to number of lines of tData
put line i of tData into tLine
repeat
If char 1 of tLine=space then
put empty into char 1 of tLine
else
exit repeat
end if
put tLine into line i of tData
end repeat
end repeat
put tData into me
end pasteSpecial
Thanks for the all the suggestions. It is nice having you experts around.
Regards,
Larry
P.S. Is there a place that explains how to format these forum responses since the buttons for Code and Quote don't work?
Re: 'pasteKey' message
Posted: Mon Aug 12, 2013 7:56 pm
by dunbarx
Hi.
Glad you have a working gadget. In the end, that is what matters. You can always trim and tweak.
Since the code button is broken, manually add "
Code: Select all
" before your script, and "[/code}" after. This is all those buttons do, similar to a macro that writes text and places the cursor between those tags. The "quote" button would be handled similarly. I am not sure of the tags.
[quote]I will experiment right now with etc.[/quote]
Craig
Re: 'pasteKey' message
Posted: Mon Aug 12, 2013 7:57 pm
by dunbarx
OK, so it is the same format, just substitute "quote" for "code"
Craig