• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Bug in NSToolbar MenuFormRepresentation?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bug in NSToolbar MenuFormRepresentation?


  • Subject: Bug in NSToolbar MenuFormRepresentation?
  • From: Arved von Brasch <email@hidden>
  • Date: Mon, 20 Mar 2006 09:58:46 +1100

Hi,

I have an NSToolbar with a custom view of a single choice 2 segment segmentation control. I created it a MenuFormRepresentation with two NSMenuItems, where one option should be in the NSOnState at any one time which matches the currently selected menu option. Sometimes one of the choices is disabled. In this case I delete the second menu item because I couldn't get the item to grey out with setEnabled: NO.

Anyway, the bug I've noticed is when the toolbar is in text only mode. In this case, one of the menu items will not lose it's NSOnState image when it is set to NSOffState. This does not occur when the menu is overflowed.

Here is my toggling code:

...
NSSegmentedControl *viewModeOutlet; // Segmented control in activeViewItem
NSToolbarItem *activeViewItem; // instance of the toolbar item, only exists when item is in toolbar
...


- (void)validateActiveViewItem {
if (activeViewItem != nil) {
if (iconViewAllowed == YES) {
[viewModeOutlet setEnabled: YES forSegment: 1];
}
else {
[viewModeOutlet setEnabled: NO forSegment: 1];
}

NSMenu *submenu = [[activeViewItem menuFormRepresentation] submenu];
if ([submenu itemWithTitle: @"Icon View"] != nil && iconViewAllowed == NO) {
[submenu removeItem: [submenu itemWithTitle: @"Icon View"]];
}
if ([submenu itemWithTitle: @"Icon View"] == nil && iconViewAllowed == YES) {
NSMenuItem *iconItem = [[[NSMenuItem alloc] initWithTitle: @"Icon View" action: @selector(toolbarView:) keyEquivalent: @""] autorelease];
[submenu addItem: iconItem];
[iconItem setTarget: self];
}

if (viewMode == AGListViewMode) {
[viewModeOutlet setSelectedSegment: 0];
[[submenu itemWithTitle: @"List View"] setState: NSOnState];
// Check if second menu item exists
if ([submenu itemWithTitle: @"Icon View"] != nil) {
[[submenu itemWithTitle: @"Icon View"] setState: NSOffState]; // This line seems to be problem...
}
}
if (viewMode == AGIconViewMode) {
// Second menu item must always exist
[viewModeOutlet setSelectedSegment: 1];
[[submenu itemWithTitle: @"Icon View"] setState: NSOnState];
[[submenu itemWithTitle: @"List View"] setState: NSOffState];
}
}
}


When the inactive segment control, or alternate menu item is selected, the viewMode is toggled between the two states. If icons are not allowed, then iconViewAllowed is NO, otherwise it is YES. When the toolbar is in text view mode, setting NSOffState where indicated, doesn't clear the menu item of it's tick, unless the menu is part of the overflow toolbar. Using NSLog, I've determined that the line always gets called correctly, and so the NSMenuItem should always be set to off. Indeed, if the Toolbar item is then overflowed by shrinking the window, the menu item displays correctly in the overflow menu.

Is this a bug, or have I done something wrong? I can't think of a good work around, if it is a bug. Any ideas?
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
  • Prev by Date: Conditional Display Pattern
  • Next by Date: Accessing NSTableView bindings' datasource
  • Previous by thread: Conditional Display Pattern
  • Next by thread: Accessing NSTableView bindings' datasource
  • Index(es):
    • Date
    • Thread