Can't Display Keyboard Shortcuts in Popups

Peter M. Brigham pmbrig at gmail.com
Wed Apr 20 16:14:15 EDT 2016


On Apr 20, 2016, at 2:31 PM, Ray wrote:

> Thanks for the heads-up on the commandKeyDown handler.  I've actually already got that in place, and my software doesn't really use fields so I think it should be good.  If it isn't I'll more than likely see it in testing.
> 
> On 4/20/2016 2:20 PM, Peter M. Brigham wrote:
>> On Apr 20, 2016, at 1:45 PM, Richard Gaskin wrote:
>> 
>>> If this item isn't also in the menu bar, you can put the shortcut into the context menu item but with two downsides:
>>> 
>>> 1. It won't be right-aligned as users are accustomed to seeing.
>>> 
>>> 2. It won't have any functional effect, requiring as Craig noted that
>>>   you also write a commandKeyDown handler, with conditionals within
>>>   it to determine when it should be invoked and when it should be
>>>   ignored.
>> WIth trapping commandkeydown messages, if you're working in the IDE you do have to be sure that you're paying attention to existing commandkey shortcuts. If the user types ctrl-A and the focus is on an editable field then the text of the field will be selected and your own handler won't fire off. If this is a standalone then you have more control.

FWIW, here's a modular way of managing popup menus that I use all the time. It requires about 5 minutes of setup (create a popup menu button, and paste a handler into your library stack) but then to pop up a menu and get the user choice you just do something like:

put popChoose("Audio","Video","Photo") into userChoice
switch userChoice
   ...

-- Peter

Peter M. Brigham
pmbrig at gmail.com

--------

(watch line wraps)

function popChoose
   -- popChoose() is the equivalent of the "answer" command, but for a pop-up list
   -- pops up a list of options, returns the option chosen by the user,
   --    if no option chosen, exits to top
   -- you must have a button "contextualMenu"
   --    button style = menu, menumode = popup, name = "contextualMenu"
   --    the button should be placed in your mainstack or a library stack
   --    button can be made invisible when you're done, if you like
   -- the button script needs only one handler:
   --    on menupick what
   --       set the uSelection of me to what
   --    end menupick
   -- paste this popChoose handler into a suitable stack script,
   --    (mainstack or library) so it's available anywhere --
   --    put the button into same stack for convenience
   -- 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 "parsley" & cr & "sage" & cr & "rosemary" into choiceList
   --     put popChoose(choiceList) into userChoice
   -- or: put popChoose(choice1,choice2,choice3) into userChoice
   -- or: put popChoose("parsley","sage","rosemary","-","thyme") \
      --           into userChoice
   -- if you need the line number of the chosen item, check the dialogdata
   --    after calling popChoose()
   
   constant popChooseStackName = "yourLibraryStack"
   
   repeat with n = 1 to paramcount()
      put param(n) & cr after tList
   end repeat
   delete char -1 of tList
   put empty into u
   set the uSelection of btn "contextualMenu" of stack popChooseStackName to empty
   put tList into btn "contextualMenu" of stack popChooseStackName
   popup btn "contextualMenu" of stack popChooseStackName
   put the menuhistory of btn "contextualMenu" of stack popChooseStackName \
         into lineNbr
   put the uSelection of btn "contextualMenu" of stack popChooseStackName into u
   set the uSelection of btn "contextualMenu" of stack popChooseStackName to empty
   put empty into btn "contextualMenu" of stack popChooseStackName
   -- belt and suspenders, don't leave contents hanging around
   select empty
   if u = empty then exit to top
   -- ie, mouseRelease, no action, otherwise:
   set the dialogdata to lineNbr
   return u
end popChoose






More information about the use-livecode mailing list