send menuPick

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

send menuPick

Post by bogs » Sun May 12, 2019 4:17 pm

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...
Selection_001.png
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...
Selection_002.png
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 :wink:
Image

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: send menuPick

Post by Klaus » 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)
...
?

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: send menuPick

Post by bogs » Sun May 12, 2019 4:45 pm

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.
Image

sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm
Location: Alexandria, Virginia

Re: send menuPick

Post by sritcp » Sun May 12, 2019 6:57 pm

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

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: send menuPick

Post by bogs » Sun May 12, 2019 7:38 pm

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)...
Selection_001.png
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 :wink:

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 :roll:
Image

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: send menuPick

Post by bogs » Sun May 12, 2019 10:06 pm

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'.
Image

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: send menuPick

Post by Klaus » Sun May 12, 2019 10:20 pm

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. :-)

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: send menuPick

Post by bogs » Sun May 12, 2019 11:06 pm

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? :D ), but that didn't make it work in this case :(
Image

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: send menuPick

Post by bogs » Mon May 13, 2019 9:03 pm

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 :D
Image

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”