Edit menu recipe?

Richard Gaskin ambassador at fourthworld.com
Fri Aug 20 12:04:42 EDT 2004


J. Landman Gay wrote:

> On 8/20/04 7:19 AM, Frank Leahy wrote:
> 
>> Does anyone have an edit menu recipe they'd like to share?  I've got 
>> one that works for the main stack, but doesn't seem to work for other 
>> stacks. 
> 
> 
> My Edit menus tend to be very simple most of the time, because the 
> functionality I usually need is is already built in. It looks like all 
> you are working with is text; if that is the case, then you don't need 
> to do any more than this:
> 
> on menuPick which
>   switch which
>   case "Cut"
>     cut
>     break
>   case "Copy"
>     copy
>     break
>   case "Paste"
>     paste
>     break
>   case "Undo"
>     undo
>     break
>   case "select all"
>     if the selectedField <> ""
>     then select text of the selectedField
>     break
>   end switch
> end menuPick
> 
> The engine automatically handles all the text operations. If you want to 
> manage the editing of objects, then it gets more complicated. But not 
> many apps need to do that, and it looks like all you need is text 
> manipulation.

The built-in cut, copy, paste, and undo commands also work for most 
pointer tool operations (i.e., working with selected objects).

If one's picky about minimizing typing, because most of those are 
handled by the engine you can use the case block's fall-through feature 
to trim the code -- this version also handles "Select All" for objects:

on menuPick which
    switch which
    case "Cut"
    case "Copy"
    case "Paste"
    case "Undo"
      do which
      break
    case "select all"
      if the selectedField <> "" then
        select text of the selectedField
      else if "pointer" is in the tool then
        lock screen
        set the defaultStack to the topStack
        repeat with i = 1 to the number of layers
          if the visible of control i or the showInvisibles
          then set the selected of control i to true
          add the number of layers in control i to i
        end repeat
        unlock screen
      end if
      break
    end switch
end menuPick


-- 
  Richard Gaskin
  Fourth World Media Corporation
  ___________________________________________________________
  Ambassador at FourthWorld.com       http://www.FourthWorld.com


More information about the use-livecode mailing list