Page 1 of 1
send menuPick
Posted: Sun May 12, 2019 4:17 pm
by bogs
Ok, I have a problem similar to what hit
rumplestiltskin, and having re-read the entire thread, I'm not sure why.
The card has a menubar created in the menu editor. I have a group of images I am turning into a toolbar, named as you see here...

- I thought I knew what I was doing...
I am using this code to send to the various menus from the messagebox:
Code: Select all
if the short name of the mouseControl is "Save As... File" then
send "menuPick Save As..." to button "File"
else
put the short name of the mouseControl into tmpName
set the itemDelimiter to space
put "send" && quote & "menuPick" && (item 1 of tmpName) & quote && "to button" && quote \
& (item 2 of tmpName) & quote && "of group" && quote & ("txtEdMenu") & quote into tmpCommand
answer tmpCommand
do tmpCommand
end if
When the answer dialog comes up, everything looks as it should as far as I can tell...

- Hmmmm...
...but, while every single other image triggers the appropriate menu item, image "Help" fails to ... help heh.
Even though this is (so far) a single stack and card, even specifying the group as Jacque mentioned in the above linked thread produced no result.
Selecting the menuItem (by adding another else if) worked, but I'd rather know why this code works for everything else but 1 image/menu item.
I did test this all the way up to v9 on Windows, so I am pretty sure it is *not* a -
* Linux thing
* old Lc thing
I'll be looking over bug reports to see if it is a 'bug report' thang

Re: send menuPick
Posted: Sun May 12, 2019 4:25 pm
by Klaus
Maybe somethink like this will do:
Code: Select all
...
dispatch "menupick" to xyz with (the short name of the target)
...
?
Re: send menuPick
Posted: Sun May 12, 2019 4:45 pm
by bogs
Yes that does work, along with select and a number of other variations, but again I'm curious why 'send' does not. From what I understand about send, call, dispatch, etc (which isn't much I grant you), they should all work reasonably on par with this type of command, shouldn't they?
I'm really starting to think it is a bug somehow.
Re: send menuPick
Posted: Sun May 12, 2019 6:57 pm
by sritcp
May be
a) the menuMode property of your "Help" button is empty (i.e., not set to one of "pulldown", etc.), so menuPick doesn't answer
OR
b) menuPick requires a minimum of two items? (your Help button has only one, while File and Edit have many).
Regards,
Sri
Re: send menuPick
Posted: Sun May 12, 2019 7:38 pm
by bogs
Good assumptions Sri, but as I mentioned in the 1st post
bogs wrote: ↑Sun May 12, 2019 4:17 pm
The card has a menubar created in the menu editor.
...which by default creates the menu buttons as pull down and, in the help menu, with 2 items (not counting the separator)...

- Looks right...
and of course, the structure created by autoScript in the tool creates a menuPick handler...
Code: Select all
--The following menuPick handler was generated by the Menu Builder.
on menuPick pWhich
switch pWhich
case "Help"
--Insert script for Help menu item here
answer the custPropContents of this stack titled "Help - Contents"
break
case "About"
--Insert script for About menu item here
answer the custPropAbout of this stack titled "Help - About"
break
end switch
end menuPick
Something else I tried that failed to produce the desired result was changing the 'Help' item to 'Contents', thinking perhaps the 2 help names were creating the conflict, but I didn't really see that as a reason for hope, and it wasn't
Oddly enough, though, this *does* work -
Code: Select all
send "menuPick" && quote & "Help" & quote to button "Help"
send "menuPick" && quote & item 1 of tmpName & quote to button(item 2 of tmpName)
So, now I'm trying to figure out why the 'do' command doesn't seem to do that one combination for the help menu

Re: send menuPick
Posted: Sun May 12, 2019 10:06 pm
by bogs
Created and submitted
bug report 22052, as I didn't find anything else with the exact same symptoms.
I suspect the 2nd item of the send command needs to be in quotes to make sure it is going to work, and that it working for the majority of items as is is a 'fluke'.
Re: send menuPick
Posted: Sun May 12, 2019 10:20 pm
by Klaus
Using a variable with send does also work:
Code: Select all
...
put "Help" into tMenuItem
send "menuPick tMenuItem" to button "Help"
...
Easier than messing with quotes galore.

Re: send menuPick
Posted: Sun May 12, 2019 11:06 pm
by bogs
Well, I put up a small
video to show the way the handler is structured (so far, I plan to skip the 'do' part in the future). You can see the items are already in a variable in this video, so you and I are merging onto the same lane as it were (scary, isn't it?

), but that didn't make it work in this case

Re: send menuPick
Posted: Mon May 13, 2019 9:03 pm
by bogs
Klaus wrote: ↑Sun May 12, 2019 4:25 pm
Maybe somethink like this will do:
Code: Select all
...
dispatch "menupick" to xyz with (the short name of the target)
...
I liked your solution so much I've decided to just go with it. The final handler setup -
Code: Select all
on mouseDown
if word 1 of the target is "image" then set the borderWidth of the target to "3"
end mouseDown
on mouseUp
if word 1 of the target is "image" then set the borderWidth of the last target to "2"
handleImage
end mouseUp
on handleImage
put the short name of the last target into tmpName
set the itemDelimiter to space
put item -1 of tmpName into tmpMenu; delete item -1 of tmpName
dispatch "menuPick" to button tmpMenu with tmpName
end handleImage
It was, as you put it,
Easier than messing with quotes galore.
Thanks again, Klaus, it will be in the next tutorial
