Cut,Copy,Paste menus

Ron rbarber at yhb.att.ne.jp
Sat Feb 1 03:52:01 EST 2003


Hi Jan
Thanks for the suggestion. I've included the handlers as they were in my
stacks. As you can see, the menuitems only get changed when the menubar is
clicked in. I'll look into locating some of the script in the
selectionchanged message. What do you think?

>> Where should scripts that control the
>> enabling/disabling of menuitems be
>> placed? Obviously, the menu's mousedown message is
>> not the place because it
>> is not activated until I click in the menubar.
>> 
>> All I'm trying to do is provide standard text editor
>> behavior to the stack.
>> Things including but not exclusively:
>> 
>> cursor in a fld - enable past
>> selectedtext - enable cut,copy

> 
> You could add openField and selectionChanged handlers
> to your mainStack script to this effect.
> You'll probably also want to trap the rawKeyDown
> message because no selectionChanged is sent when you
> use the arrowkeys.

This is what I had in my openfield handler:
on openfield
  enable menu 2 --the edit menu
  if the clipboard is "text" then enable menuitem 4 of menu 2 --paste
  else disable menuitem 4 of menu 2
  put word 2 of the selectedfield into thefld
  if therefld is not "" then put fld thefld of the topstack into thetext
  if thetext is not "" then  --check if text is in the fld
    enable menuitem 6 of menu 2 --sel all
    enable menuitem 8 of menu 2 --find
    enable menuitem 8 of menu 1 --export text
    enable menuitem 11 of menu 1 --print text
  end if
  enable menu 4 --format menu
  pass openfield
end openfield

In my menu's mousedown handler I had the following:
-----set up menuitems---------
  put word 2 of the selectedfield into thefld
  if thefld is not "" then  -----The cursor is in a fld--------
    if the clipboard is "text" then enable menuitem 4 of menu 2 --paste
    else disable menuitem 4 of menu 2
    put fld thefld of the topstack into thetext
    put the hold of fld thefld of the topstack into thehold
  end if
  if thetext is not "" then   -------There is some text in the fld-------
    enable menuitem 6 of menu 2 --sel all
    enable menuitem 8 of menu 2 --find
    enable menuitem 8 of menu 1 --export text
    enable menuitem 11 of menu 1 --print text
  else
    disable menuitem 6 of menu 2
    disable menuitem 8 of menu 2
    disable menuitem 8 of menu 1
    disable menuitem 11 of menu 1
  end if
  if thehold <> thetext then
    enable menuitem 6 of menu 1
  else
    disable menuitem 6 of menu 1
  end if

  if the selectedtext is not "" then  -----There is some selected
text--------
    enable menuitem 1 of menu 2 --cut
    enable menuitem 2 of menu 2 --copy
  else
    disable menuitem 1 of menu 2
    disable menuitem 2 of menu 2
  end if




More information about the use-livecode mailing list