Scripting Cut/Copy/Paste in custom menus

Kay C Lan lan.kc.macmail at gmail.com
Sun Sep 14 22:41:35 EDT 2014


On Sun, Sep 14, 2014 at 2:22 PM, Paul Hibbert <paulhibbert at mac.com> wrote:

>
> Tested in LC 5.5.5 + 6.6.2 & 7.0(rc1) on Mac OS X 10.9.3
>
> Cutting, or pasting within a field then tabbing out does trigger a closeField message, but "Copy" doesn't, possibly because the field didn't change even though the field still closed on tab, it does trigger an exitField.
>

Test this - and it's been this way ever since I can remember - Rev
1.1.1. What Bob is complaining about is, Create a New stack, 2 fields,
in the second field put:

on closeFiield
   beep
end closeField.

Type a couple of chars into the first field. Use the IDE built in Copy
and Paste commands. Copy a different char from the first field and
Paste into the 2nd. Then press Tab. LC will Beep as expected.

Now use the Menu Builder to create an OS X Menu for you, tick the box
to Set as stack Menu Bar, have it auto build the script for you, and
then open if for Edit and fill it as you would for Copy, Paste, and
Clear. It should look something like this:

--The following menuPick handler was generated by the Menu Builder.
on menuPick pWhich
   --breakpoint
   switch pWhich
      case "Cut"
         --Insert script for Cut menu item here
         break
      case "Copy"
         set the clipboardData["Text"] to the selectedText of the focusedObject
         break
      case "Paste"
         put clipboardData["text"] into the focusedObject
         break
      case "Clear"
         put empty into the focusedObject
         break
      case "Preferences"
         --Insert script for Preferences menu item here
         break
   end switch
end menuPick

Do exactly the same as you did before. After you Paste and Tab or
Clear and Tab LC will NOT Beep.

Jacque mentions the textChange message but this is a message not a
property and frankly I have a problem with using a message or Jacques
solution (although it might be prefectly fine for what you are doing)
because it means LC will go ahead and do things BEFORE you've asked it
to do so. i.e in the above example I can get LC to beep but it's
BEFORE I've tabbed out.

To me, in the first instance, using the IDE Copy, Paste, and Clear I'm
assuming an inbuilt property is being set so LC knows the field is
dirty and so correctly triggers the closeField message on Tab -
unfortunately I have no idea what that property is so I can't  use it.
So I use a simple workaround of creating my own Custom Property to do
the same thing - the big difference though is I have to test my dirty
custom prop in an exitField message.

--The following menuPick handler was generated by the Menu Builder.
on menuPick pWhich
   --breakpoint
   switch pWhich
      case "Cut"
         --Insert script for Cut menu item here
         break
      case "Copy"
         set the clipboardData["Text"] to the selectedText of the focusedObject
         break
      case "Paste"
         put clipboardData["text"] into the focusedObject
         set the cIsFldDirty of the focusedObject  to true --*****
         break
      case "Clear"
         put empty into the focusedObject
         set the cIsFldDirty of the focusedObject  to true --*****
         break
      case "Preferences"
         --Insert script for Preferences menu item here
         break
   end switch
end menuPick

Place in any effected fields you want to check>:

on closeField
   --do what you need to here
   beep
end closeField

on exitField
   if (the cIsFldDirty of me = true) then --*****
      --content change by paste/clear so do closefield
      set the cIsFldDirty of me to false --*****
      send closeField to me
   else
      --content hasn't changed
      --probably don't need to do anything
   end if
end exitField

If you do not have to do this in Win or Linux, then maybe it's a BUG
for OS X but as I say it's work this way for as long as I can
remember.




More information about the use-livecode mailing list