Window Enablemenuitems event

Xojo2018r4. This happens on MacOS 64-bits, both in Debug and compiled. Haven’t checked Windows behaviour yet.

In the App Enablemenuitems event, I call a short method that enables or disables some of the menuitems.

The first time I click on a menu item, nothing is enabled, which isn’t right. I click on it again, and then things are enabled or disabled as they should be.

This is repeatable, happens the same way every time. The first time the menu is opened, it’s as if the method enabling or disabling the menu items simply wasn’t called; nothing is enabled. The second time things work as they should.

Is this a known issue? Is there a workaround? It’s annoying. I couldn’t find it in feedback.

In the mean time, I tested this on Windows, and the problem does not exist there.

Should this be happening in the app.enablemenuitems event, or one for the visible window?

You’re right, I’ve written it wrong in the subject heading and description of the problem.

The Enablemenuitems event is in fact in the Window.

I’ve corrected the subject of the post, but I can’t edit the original post, unfortunately.

How many windows do you have open?
Maybe another window which lacks such code has ‘owned’ the event first.
What you are seeing is what you get if the App has control, rather than the window.
Maybe if you ensure the window has focus? What kind of window is it?

There is only one window open.

This happens in all of my apps, only on Mac. Exactly as described:

The first time I click on a menu item, nothing is enabled, which is wrong. I click on it again, and then items are enabled or disabled correctly.

is the some “conditional” statement in your enablemenuevent that perhaps isn’t set the first time you click the menu ?

I use this all the time and never had it not work

[quote=430093:@Dave S]is the some “conditional” statement in your enablemenuevent that perhaps isn’t set the first time you click the menu ?

I use this all the time and never had it not work[/quote]


And I know the event is getting called, and the menuitems are getting their enabled properties set as needed. But it doesn’t work.

do the menu items have a HANDLER defined?
If you just create a menu item, but it doesn’t really “do anything” it will not become enabled.

No offense… but there IS a logical explanation, you just haven’t found it…
and if you are going to shoot at every suggestion, then help might become hard to find.
Since none of us have seen a lick of your code, all we can do it suggest things that could contribute to your issue, having no idea if you have or have not considered the suggestion before hand.

and with that … I wish you good luck… and have a nice day

And I’ll bet you $10 it is not a bug…

How many of them, if any, have autoenable on ?

AutoEnable can override manual enabled state settings. It’s not a bug, you need to turn AutoEnable off if you’re going to manually manage the enabled state.

I don’t think so. See the Feedback project.

In the docs for the MenuItem.Enabled event it says: For MenuItems that belong to an App or Window menu, this property should only be set to True in the EnableMenuItems event handler.

I changed your code in EnableMenuItems to the following and it works as you expect.

if CheckBox1.Value then
TestMenu.Enabled = True
TestEnableMe.enabled = True

It works whether AutoEnable is on or off. I always leave it off when I am enabling this way.

You owe Dave $10


The problem appears to be that EnableMenuItems is fired at weird times on Mac, compared to Windows. Like, it fires when inputting keystrokes into a TextField. Why? Who knows, but this must be the reason for the (totally unsubstantiated) recommendation to only set that property to true in the EnabledMenuItems event, which also only seems to be necessary on Mac, since not respecting that recommendation has no effect on Windows.

Yes, you took his bet:

Time to man up.

It’s not surprising that things work different on Windows than the Mac. Also, I’m sure you know that event sequence order is not to be relied on. I do all my coding on the Mac and test on the Mac, then Windows. So I suppose I’ve never had the opportunity to run into this problem.

The main thing is you can make a minor change and you’ll get what you want. This way will work in Windows also.

And… where I’m from, if you tell someone you’ll be happy to take their money, that’s the same as accepting the bet…

HA! Pissing off as requested (but I still think it’s lame) :stuck_out_tongue_winking_eye: