Menu Items Dimming for No Apparent Reason

I’m stumped. I have several custom menu items in my application that have been working fine for weeks now. I used to have separate menu items for editing a row in each of two different tables. That is, I had an item for editing the selected row in table 1, and an item for editing the selected row in table 2. (I had to do that because of I need double-clickability of my rows, so they’re set to uneditable - the menu items change the underlying data.)

Tonight I decided to combine those two into a single menu item. The code called by the menu item would then check to see which table is active at the moment, and edit the selected row in that table. Here’s what I added:

set theFirstResponder to first responder of window "mainWindow"
if the name of theFirstResponder is "firstTableView" then
	[...old code for edit row in first table copied to here...]
end if
if the name of theFirstResponder is "secondTableView" then
	[...old code for edit row in second table copied to here...]
end if                

I made no other changes to the code. And it works beautifully.

But now I can only select the edit menu item twice. Thereafter, it and all my other custom menu items become disabled.

I have no code that deals with disabling these menu items. Nor for enabling them, for that matter.

This now happens every time the program is launched. No matter what, you get two edits, then the menu items all become dimmed.

Since my code isn’t doing the disabling, and since I didn’t change anything at all other than adding the code above, what could possibly be causing all those menu items to dim out? Again, they never did this before this change, and now it doesn’t matter which table is edited (and therefore which set of copied code is run), it always happens.

I tried going back to a previously saved nib file, making the same changes to it (deleting one of the edit items, changing the title of the other and renaming it). I got the same result.

Any ideas?

-Joe

Could it have something to do with the auto enables items? Maybe you checked or unchecked it in IB. And you might clean it. It starts acting wacky sometimes after doing a lot of deleting.

gl,

How does one clean a NIB? I’ve run the “clean all targets” process in XCode. Is there something I should be doing in IB?

Auto enables: These items are in the Edit menu, and that menu is of course set to “auto enables items”, but I don’t see much choice. Am I missing something?

Thanks,

-Joe

Hi Ransom,

You have a choice of setting the ‘auto enables items’ to true or false or in IB to check or uncheck it in the attributes pane for your menu. I was thinking that it might be unchecked.

gl,

It was checked, which is what I need it to be for the text view’s sake. So, I decided to enable my items by hand every time the user chooses one. Silly, I know, but it works.

There should be some way to say “Don’t auto-manage these menu items, even though they’re in an auto-managed menu.” Otherwise, the only other choice is to make a special menu for all your application’s items, even if they conceptually belong under File or Edit.

Oh, well.

Thanks again for the help, Kel!

-Joe

Hi Ransom,

You’re welcome.

Actually there is something I was reading about in the reference about the edit menu. It’s a little vague though:

auto enables items
Access: read/write
Class: boolean
Should the menu auto enable its items? default is true; you can set this value in
Interface Builder; however, your application has no convenient way of enabling
and disabling menu items on standard application menus (such as the File and
Edit menus), so setting this property to false for those menus is not
recommended; to read more about Cocoa’s underlying support for menu
enabling, see NSMenu and NSMenuValidation

I wonder what is the inconvenient way.

gl,

Did you do it like this? Connect a ‘update menu item’ handler to each of your custom edit menu item. This will always enable:

on update menu item theObject
return true – enables the menu item in the edit menu
end update menu item

gl,

Ah! No, I didn’t do it that way. That’s much more efficient. Thank you!

-Joe