Battling Menu Enabling

Hi Folks,

I have a menu that I’ve duped and modified for two different window presentation models. On one window, the main menu enables all menu entries with no prompting from me. On the second window, one of the menu options is not enabled.

The menuitem names are the same, the Menu Handlers are the same and autocomplete doesn’t show collisions, and the compile is successful. I even changed the text of one to make sure that the menus are being swapped. The other items in the remaining menus enable and work as expected.

Next, I changed the name of the menuitem under the secondary menu, added it’s name to the EnableMenuItems event and was promptly informed that the new menuitem did not exist.

Is there clear documentation somewhere that discusses the steps required to maintain 4 principle menus - 2 for macOS (one for each window presentation) and a duplicate 2 for Windows and Linux?

Which one?
App or window level?

I have 2 menus that I swap about like this.
One of them has fewer items and would cause this kind of problem if I referred to a missing item.

So if this code is in app.enableMenuItems it may be ‘hitting’ the wrong menu.
It needs to be in the window enablemenuitems event of the window that uses the second menu

1 Like

Have you tried fully qualifying the names?
mbMode1.theItem.Enabled = true
vs
theItem.Enabled = true

That doesn’t seem to be the case.

Yes - same report of the object not existing.

My solution this morning was to delete the problem menu, save, exit, relaunch, load, and then re-create it - same parent menu, same name, same callback, same keyboard shortcut - and it just worked.

More “magic”

1 Like

Well, at least it’s consistent - added new menus and am running into the same issue:

 Begin MenuItem ArchiveDetailsStandaloneOverwriteSetting
     SpecialMenu = 0
     Index = -2147483648
     Text = "Overwrite Setting"
     AutoEnabled = True
     AutoEnable = True
     SubMenu = True
     Visible = True
     Begin MenuItem TapeOverwriteSettingAsk
        SpecialMenu = 0
        Index = -2147483648
        Text = "Ask"
        AutoEnabled = True
        AutoEnable = True
        Visible = True
     End
     Begin MenuItem TapeOverwriteSettingAppend
        SpecialMenu = 0
        Index = -2147483648
        Text = "Append"
        AutoEnabled = True
        AutoEnable = True
        Visible = True
     End
     Begin MenuItem TapeOverwriteSettingOnlyIfBlank
        SpecialMenu = 0
        Index = 1
        Text = "Overwrite Only If Blank"
        AutoEnabled = True
        AutoEnable = True
        Visible = True
     End
     Begin MenuItem TapeOverwriteSettingOverwrite
        SpecialMenu = 0
        Index = 1
        Text = "Overwrite"
        AutoEnabled = True
        AutoEnable = True
        Visible = True
     End
  End

However, any call to the …OnlyIfBlank or …Overwrite items results in the nefarious:

WMain.EnableMenuItems, line 35  This item does not exist
  TapeOverwriteSettingOnlyIfBlank.Enabled = True

The other two items at the TapeOverwriteSettings… level work as expected.

*I think I’ve found a clue - *

The menus that act up all have the large negative “Index” value. The ones that work are all simply “1”.

However, other menus that work have that same “-2147483648” value …

Oops- I got that backwards - the menus with that value are the ones that work. The menus with any other index value are the ones I’m having the problems with. This might explain why deleting the menuitem and then recreating it solved it before.

If they have a real index (not -2147483648 but >= 0) then they are part of a MenuItem Array (which can be very useful!) and so have to be accessed as MenuItemName(index)

The index get passed into the menu handler . Handy for menus of things (like fonts) that are lists where each item is just a different parameter for an action.

-Karen

I fully understand the usefulness of the Index and menu arrays, but I’ve finaly discovered HOW it happens in my case.

When I create a menu that I know what is going to be included, I have already mapped it out on paper. Therefore, I just add the menu and all of its subs at one time, returning to each to populate its properties after the templates are added. This causes a slew of “Unnamed” menuitems and an unrecognized bunch of Index assignments. Back in the REAL.Studio days, I seem to recall that this method created menuitems with names like “Unnamed”, “Unnamed1”, “Unnamed2”, etc. and I didn’t run into this Index issue.

I’ll pay closer attention when I do these bulk additions in the future and clear the Index values where they are not needed.