DesktopMenuItem works with shortcut even if the menu is not visible

Although the DesktopMenuItem is not visible, the defined shortcut works and executes the Menu Handler …

This seems to me to be a bug or is this expected behavior?

Xojo version 2024 R 2.1 and previous versions
macos Sonoma 14.6

TestMenu.xojo_binary_project.zip (6.2 KB)

By “the DesktopMenuItem is not visible” do you mean:

  1. The menu that the item is on is not visible

  2. The menu is visible but the item is not on it

  3. The item is visible on the menu but greyed-out

?

The menu is completely invisible.

AdministratorMenu.Visible = false

And the AdministratorMenu has a submenu “Values”.

So both invisible. But the shortcut at “Values” executes the menu handler.

Perhaps it need to have:

AdministratorMenu.enabled = False

to disable the shortcut(s) (it’s a while since I did menus).

(Assuming that is what you want).

3 Likes

Thanks Tim, but that’s not my point. If a menu is not visible, the associated shortcut should not work either.
Otherwise, it’s a bug to me - unless I’m overlooking something that makes such behavior necessary.

Well, you changed the visibility not the enabled state, so I’m not sold on this argument.

Enabled = false if you don’t want something to be enabled.

2 Likes

Have-you searched in the Human Interface Guidelines ?

A Human Interface Guideline for an object that is not visible?
That sounds strange to me.

Apple writes about an unavailable menu item: An unavailable menu item often appears dimmed and doesn’t respond to interactions.

Should a non-visible MenuItem then react to interaction?

Anyway. Many thanks for the interesting points of view. I’ll just set the menuitems to not enabled and not visible.

There are times you don’t want the Edit menu to be visible, but you still want Copy/Cut/Paste to work in textfields. Visible and Enabled should be two distinct attributes.

1 Like

Hmm, good point. Now I know that it can also have advantages to differentiate between Visible and Enabled.

You’ve both convinced me now.

Can I say I’m not convinced?

And I tried for myself, to check. My results show that a menu item responds only when it’s both enabled and visible.

Steps I used to reproduce:
• Blank project
• Add a menu item in the “Edit” menu, with a shortcut of “T” (⌘T) and named “EditTest”.
• Add a menu handler for “EditTest”:

self.Title=System.Ticks.ToString
Return True

• Add this in the window’s KeyDown event (quickly written):

if key="E" then EditTest.Enabled=not EditTest.Enabled
if key="V" then EditTest.Visible=not EditTest.Visible

if key="D" or key="V" then
  self.Title=if(EditTest.Enabled,"E","D")+if(EditTest.Visible,"V","I")
  Return True
end if

• Run the app
• Only when EditTest is both enabled and visible (i.e. the window’s title is “EV” in this example) does Command-T work and shows System.Ticks in the window’s titlebar.

And… I expect it that way. The same behaviour like, say, default push buttons, which won’t react when they’re hidden.

1 Like

Note to self: always start with the sample that the OP provides.

I can reproduce the behavior with macOS 14.6.1 (⌘L works when visible and not visible)
I can’t reproduce the behavior with macOS 13.6.9 (works as expected, not visible = ⌘L doesn’t work. Menu visible = ⌘L works)

Maybe someone can test and see if this a Xojo or Apple bug?

Of course you can say that.

Under my stated conditions the shortcut also works if visible=false.

See also:

Many thanks, Alberto, for the extended test. It helps for a better understanding.

Finally someone who understands me. :smiley:

2 Likes

Curiously, my tests were made in 14.6.1 as well, but results are different.

Did you test the code from first post?
Just to make sure we did the same tests.
If not, can you upload your test code so I can run it in my 14.6.1 macbook?

No, the test I made is “straight to the fact”, to avoid possible bugs that the original code might have added. It’s explained in post number 11: DesktopMenuItem works with shortcut even if the menu is not visible - #11 by Arnaud_N
Please try it as well.

But not to my fact. Sorry.

Your code test only a submenu. It shows that a submenu shortcut won’t work, if submenu.visible=false. That is as expected as you wrote.

But my code shows, that a submenu shortcut works if parentmenu.visible=false

Only if you set submenu.enabled=false it won’t work. But that was not my question.

You are using a menu item under Edit. Your test does not follow OP’s sample code.

OP is using a new top menu ‘Administrator’ then a menu item under it with a shortcut.

You can test instead of creating EditTest, create Administrator menu then under it the Test.

And change visible for Administrator (not the Test menu item within it), this way:

  • under macOS <> 14.x the shortcut will not work (at least macOS 13.6.9 tested)
  • und macOS 14.x the shortcut will work

Well, you wrote this in your original post:

Which is misleading, IMO, and appears to be about the menu item itself.

Now, I can see that when the top menu is invisible, the menu item continues to work.

1 Like