Hide a menu in windows

  1. 7 weeks ago

    Richard K

    May 17 Testers, Xojo Pro

    There is alot of confusing information about using menus in xojo. I have a need to hide a menu based on a security context. xojo does not seem to allow that.

    This does not work, nor does using the visible property. The menu still shows up regardless. This code I have in the form.open event

    if App.MyUser.isAdmin then
    AdminMenu.Enable
    AdminMenu.Enabled
    end if

  2. Tim P

    May 17 Testers, Xojo Pro Answer Rochester, NY

    This is all documented https://docs.xojo.com/MenuItem.Visible

  3. Richard K

    May 17 Testers, Xojo Pro

    Its too bad the code is not the same for windows/linux/mac. I would like to use the visible property.

    I have it working in the simple scenario of if a user is an admin. However once you remove a menu, its gone and you cannot add it again, which is a shame.

    Again, it would be good to have a working visible property.

    As this exists I could never implement a logoff scenario as once the AdminMenu is removed it cannot be added in again. To get around that would be an unneeded hassle of having to keep a shadow menu in memory then code to manage that.

    All platforms need the visible property.

  4. Jeff T

    May 17 Midlands of England, Europe
    Edited 7 weeks ago

    Try this:

    if App.MyUser.isAdmin then
    AdminMenu.Enabled = true
    AdminMenu.text = "Some menu text"
    else
    AdminMenu.Enabled = false
    AdminMenu.text = "-"
    end if
  5. Richard K

    May 17 Testers, Xojo Pro

    Jeff,
    Interesting thought, but the menu still works just with a new title. The idea is to keep non-admins out of the config settings for the application. These settings are stored in the database and are system wide settings. Knowing my users I cant have them getting access to those.

  6. Tim P

    May 17 Testers, Xojo Pro Rochester, NY
    Edited 7 weeks ago

    @Richard K However once you remove a menu, its gone and you cannot add it again, which is a shame.

    You can, it's just not quite as easy. If this menu updates frequently, consider creating it in code.

    @Richard K Again, it would be good to have a working visible property.

    My understanding is that it's related to API differences. If it were to happen today, macOS and Linux simply wouldn't be able to remove menus so that the framework would match. We saw this with the updates to the FolderItem API, macOS lost the ability to track a file after it was moved to match the Windows and Linux frameworks.

  7. Jeff T

    May 17 Midlands of England, Europe

    Interesting thought, but the menu still works just with a new title.

    No it doesn't.
    If you set the title to "-" it becomes a separator and unusable.
    themenu.Enabled = false is just a second safety net

or Sign Up to reply!