Auto enable Cut, Copy, Paste menu items

Richard Gaskin ambassador at fourthworld.com
Thu Sep 14 20:03:57 EDT 2006


Bill Vlahos wrote:

> Oh now that is the most ridiculously, wonderfully, and embarrassingly 
> easy thing to do.
> 
> Here it is:
> on mouseDown -- Put in button "Edit" of menubar group of stack
>    -- This example assumes text in fields not other clipboard types
>    if the selectedText is empty then -- nothing selected
>      disable menuItem 1 of me -- Cut
>      disable menuItem 2 of me -- Copy
>    else -- text is selected
>      enable menuItem 1 of me -- Cut
>      enable menuItem 2 of me -- Copy
>    end if
>    if the clipboard is "text" then -- Is there text in the clipboard?
>      enable menuItem 3 of me -- Paste
>    else -- Either no text in clipboard or data type of clipboard is not 
> text
>      disable menuItem 3 of me -- Paste
>    end if
> end mouseDown

There are two issues with the above:

1. On a Mac the individual menu buttons do not receive a mouseDown 
message when they're in the current menu bar.  But the menuGroup object 
does get a mouseDown, so just put the handler there (modified of course 
for the object change).

2. The strategy of updating menu items when they become visible to the 
user (mouseDown) is how many frameworks, like the ol' Think Class 
Library, work.  But in Rev this is problematic once we consider keyboard 
shortcuts.

For example, if you disable the Paste item when the user mouses down on 
the Edit menu and the clipboard is empty, and then later the user has 
something on the clipboard and attempts to use Cmd-V to paste it, the 
command key won't trigger the menu item because it's still disabled.

So while I used to use the update-prior-to-display method, these days I 
tend to use an update-when-the-triggering-action-first-happens method.

In the same example above, I would modify the contents of the Edit menu 
based on global handlers in a frontScript that monitor selectionChanged 
and related actions, and in any handlers that can affect menu updates 
such as enabling Paste after a Cut or Copy is performed, etc.

It might make things simpler if Rev had a way to interpret keyboard 
shortcuts, recognize that they're part of the current menu set, and 
trigger a mouseDown event in response so you could take the simple path 
of using the update-prior-to-display method.  Anyone know if such a 
feature request has been submitted to Bugzilla?  I couldn't find one....

--
  Richard Gaskin
  Managing Editor, revJournal
  _______________________________________________________
  Rev tips, tutorials and more: http://www.revJournal.com



More information about the use-livecode mailing list