Menu "QUIT" item

I would like to be able to add an item to the menubar that will execute code immediatly when the user selects the “Item” and not open up sub menu items?

Basically the menu item is a “Push Button”
Thanks
jim

Could you elaborate? Reading your subject line and your explanation seem to be in conflict as Quit menu items typically don’t have subitems. Maybe a picture would help?

I also am not quite sure what you mean. Code in the Menu Handler for the menu is execute when the menu is selected without displaying anything else automatically.

More information about menus is here:
https://docs.xojo.com/UserGuide:Desktop_Menus

I’m guessing that he wants an event to happen when the user selects the menu, even if all the user does is look at it when it drops down, and then clicks to deselect the menu - that is even if the user does not select a menu item. BICBW.

Nothing happens when you select a Sub-Menu (with SubMenuItems enabled) and you release the mouse.

First time I saw one asking for that.

What about a SubMenuItem that do that instead ? (same name of the SubMenu)

My interpretation is similar, except I think @Jim McDermott is looking to have the Event happen on the MenuItem in the bar itself, but not open a submenu.

I just tried an example of adding only a “top” MenuItem (called “Click Me” in the following screen-shot) and an Menu Handler, but strangely the handler does nothing (breakpoint was not called either), and I can’t easily see how to identify “which” MenuItem was clicked that triggers the EnableMenuItems Event.

At least that’s what I thought he was looking for.

[quote=489134:@Jim McDermott]I would like to be able to add an item to the menubar that will execute code immediatly when the user selects the “Item” and not open up sub menu items?

Basically the menu item is a “Push Button”
Thanks
jim[/quote]

That is easy!

Just add a menu bar to the proyect or use the default one, Edit it to add your top level item

asign this menu bar to the window in the ispector

In the navigator (left of the IDE) right the window, click add, Menu handler

Select the menu handler and choose your item in the inspector

that is all, just write your code to the handler

If the menuitem in question has a submenu, I don’t believe that you can prevent it from displaying the submenu when clicked. If you create an item in the top menubar and don’t add submenu items to it, you can define a menuhandler for that item. In that case, it will act as if it were a pushbutton in the menubar. Once you add a submenu to it, however, you cannot create a menuhandler for the top item and if you had already created one, it will no longer be called.

At least that’s what happens on Windows.

[quote=489582:@Ivan Tellez]Select the menu handler and choose your item in the inspector

that is all, just write your code to the handler[/quote]

That’s what I tried, but the handler doesn’t appear to fire.

At least not on macOS 10.15.3 using 2019r3.1.

[quote=489585:@Scott Cadillac]That’s what I tried, but the handler doesn’t appear to fire.

At least not on macOS 10.15.3 using 2019r3.1.[/quote]

I tested in windows ad it works. Maybe it is a xojo BUG on macOS

It’s an intentional (macOS) design decision I’m pretty sure. I think there was even originally a note about OPs design request in the way old HIG books. (saying something like “don’t do this”)

Well, I’ll be… it does work on Windows, but not macOS.

That wouldn’t surprise me. I’m pretty sure I have seen this kind of thing in other Windows apps in the past, but maybe not in an Mac app.

Just to be complete, I did search for a similar case in Feedback, but upon not finding anything obvious I tried to submit a “bug” report - but Feedback wouldn’t let me. So I’ll post a link to my example here and see if @Greg O’Lone or @Paul Lefebvre have time to chime-in with their opinion.

MenuBarClick.xojo_binary_project

Note: I also looked at the MenuItem documentation, but I couldn’t find any mention of this particular use-case among the other Mac specific stuff. But maybe I missed it.

I would say it works on macOS but not on Windows, especially because, once you fill and empty the menu, the behaviour differs between before and after (=inconsistency). A menu bar isn’t a toolbar: there are no such things as “buttons” there.

Sorry for not responding eariler.

Scott C’s post yesterday with the picture is exactly what I’m trying to do.

Thanks Scott C for clarifying… :slight_smile:

I am in macOS

Then presumably you can’t do it.