Context Menus - the look of the thing

Peter M. Brigham pmbrig at
Sat May 11 09:31:39 EDT 2013

Here's a modular solution. Create a popup button named "contextualMenu", and put the following script into it:

on menupick what
  set the uSelection of me to what
end menupick

Put the button in a library stack, and add the following to the library script:

function popChoose
   -- paste the "contextualMenu" button into your mainstack or a library stack
   --    make it invisible when you're done, if you want
   -- enter the short name of the stack containing the button
   --    into the constant declaration below
   -- popChoose() can accept a cr-delimited list of choices
   -- or a comma-delimited list
   -- eg: put choice1 & cr & choice2 & cr & choice3 into choiceList
   --     put popChoose(choiceList) into userChoice
   -- or: put popChoose(choice1,choice2,choice3) into userChoice
   -- or: put popChoose("Vera","Chuck","Dave") into userChoice
   constant pStackName = "stackContainingContextualMenuButton"
   put the params into tList
   put offset("(",tList) into q
   delete char 1 to q of tList
   delete char -1 of tList
   replace comma & space & quote with comma & quote in tList
   replace quote & comma & quote with cr in tList
   if char 1 of tList = quote then delete char 1 of tList
   if char -1 of tList = quote then delete char -1 of tList
   put empty into u
   set the uSelection of btn "contextualMenu" of stack pStackName to empty
   put tList into btn "contextualMenu" of stack pStackName
   popup btn "contextualMenu" of stack pStackName
   put the uSelection of btn "contextualMenu" of stack pStackName into u
   set the uSelection of btn "contextualMenu" of stack pStackName to empty
   put empty into btn "contextualMenu" of stack pStackName
   -- belt and suspenders, don't leave contents hanging around
   select empty
   if u = empty then
      exit to top
      -- equivalent of mouseRelease, no action
   end if
   return u
end popChoose

Then whenever you need a popup contextual menu, just call it with

put popChoose("Vera","Chuck","Dave","-","Lovely Rita","Nowhere Man") into userChoice

You can construct the parameter list on the fly, depending on the context, then just

put popChoose (choiceList) into userChoice

-- Peter

Peter M. Brigham
pmbrig at

On May 9, 2013, at 4:18 PM, J. Landman Gay wrote:

> On 5/9/13 2:54 PM, Graham Samuel wrote:
>> What I want is a single 'mouseDown' handler in my mainstack
>> that checks if the right mouse button had been pressed in an editable
>> field and then provides Edit-menu type services to that field (the
>> target). Could I use a button menu for that?
> Sure, easily.
> Create an option button and put the menu you want into its contents. Put a corresponding menupick handler in its script. Hide the button.
> In the field where you check for a right-click, just use "popup <name of btn>". That's about it. The button script can either execute commands directly ("copy", "paste") or it can call out to a custom handler in the message path.
> -- 
> Jacqueline Landman Gay         |     jacque at
> HyperActive Software           |
> _______________________________________________
> use-livecode mailing list
> use-livecode at
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:

More information about the use-livecode mailing list