2

If I instantiate a popup button, I can dismiss it by selecting one of the options or by clicking somewhere else. Is there a good way to dismiss it from a script? I tried setting the menuHistory, but it doesn't seem to have any effect.

mwieder
  • 231
  • 2
  • 6

5 Answers5

6

Mark - if you check the openStacks is the first line empty while the popup menu is displayed? I think it is and then you could test that way.

  • Trevor - Brilliant! That was the missing key. So in my rawKeyDown handler I check for the scrollwheel keyCodes and then [code] if line 1 of the openStacks is empty dispatch "menuPick" to button "PluginMenu" end if [code] – mwieder Mar 14 '13 at 16:52
2

Answering my own question:

I haven't found a good way to determine whether a popup menu button is displayed yet - none of the usual property checks seem to work. But I sidestepped the issue thusly:

in my scrollwheel handler I

dispatch "menuPick" to button "PluginMenu"

Then in the menuPick handler of the PluginMenu button I have

if pItemName is empty then
    lock screen
    put word 2 of the selectedline of field "xyzzy" into tLine
    select after line tLine of field "xyzzy"
    click at the selectedloc
    unlock screen
end if

where pItemName is the normal menuPick parameter. If I could determine when the popup was visible I could limit the menuPick call to just the times when it's on screen, but otherwise the effect is just to click at the end of the line, deselecting the popup if it's on top.

Edit: the scrollwheel handler mentioned above is in the rawKeyUp handler of field "xyzzy".

Edit 2: as mentioned, that should be "rawKeyDown" instead of "rawKeyUp". And as Trevor mentioned, checking line 1 of the openStacks makes it even better:

if line 1 of the openStacks is empty then
    dispatch "menuPick" to button "PluginMenu"
end if
mwieder
  • 231
  • 2
  • 6
  • Are you sure you don't mean rawKeyDown? RawKeyUp doesn't get triggered by the scroll wheel in LC 5.5.4, Windows 8. When the popup menu is open, the scroll wheel doesn't trigger any messages whatsoever. – Mark Mar 13 '13 at 02:37
  • Yep - that is, of course, exactly what I meant. Thanks - getting too excited about solving the problem to type straight. The scroll wheel triggers rawKeyDown messages in the underlying field when the popup menu is open. Don't know about win8, but it works in xp and linux and osx. – mwieder Mar 13 '13 at 04:16
1

It may be that you need to fake your popup menu with a palette stack which closes on suspendStack. That way there's no blocking involved and you can close it whenever you like. You would need to mess with the focus of the field I think after opening the palette so it still has the focus.

Monte Goulding
  • 2,380
  • 1
  • 21
  • 25
1

I just tried clicking a button containing the following script then clicking on a popup button.

on mouseUp
   set the uActive of me to not the uActive of me
   if the uActive of me then send "test" to me in 2000 millisecs
end mouseUp



on test
   put the millisecs
   if the uActive of me then send "test" to me in 2000 millisecs
end test

The popup seems to be modal and blocks the timed routine in the button script. I'm thinking that Monte's idea of faking the popup might be a good one ;)

splash21
  • 799
  • 4
  • 10
  • Hmmm. The popup button I've got doesn't seem to be blocking. The mouse scrollwheel events are passed onto the underlying field and processed with no problems. It's just that the popup stays on the screen, and then of course it's in the wrong place since it didn't scroll with the field data. – mwieder Mar 12 '13 at 21:28
  • 1
    I tried to use the scroll wheel to scroll the text in a scrolling field while a popup menu was open. This didn't work. The menu blocks the scroll events. (On Windows 8). – Mark Mar 13 '13 at 02:31
0

You can't access already open menus by script. However, on Windows, if you open the popup menu with the popup command in a mouseDown handler, the mouseDown handler will run till the end instantly. If you use a stack panel instead of a regular popup menu, you might be able to close the stack panel by script (I haven't tried this). I don't think that this is possible on Mac OS X because menus block any currently running scripts until the menu closes.

Mark
  • 2,380
  • 11
  • 29
  • 49
  • Thanks. I'm not trying to access the open menus. The situation is that the user pops up a menu, and I'd like the popup to go away if the mouse scrollwheels scroll the text underneath. And (as you guessed) it has to be cross-platform. – mwieder Mar 12 '13 at 19:57
  • Closing a menu is also a way of accessing it. Theoretically, you'd do this by script, which is not possible with menus but might be possible with a stack panel (similar to Monte's idea). – Mark Mar 13 '13 at 02:26