I have following menu for my toolbar:
Is it any simple way to exclude "Text Only" from this menu?
I know it NSToolbarDisplayModeLabelOnly, but did not found place to say don't use it.
My team found solution.
Simple category for NSToolBar.
And this category can be used for add custom items to menu.
NSToolbar+ContextMenu.h
#import <Cocoa/Cocoa.h>
@interface NSToolbar (ContextMenu)
- (void) disableTextOnlyMode;
@end
NSToolbar+ContextMenu.m
#import <AppKit/NSToolbar.h>
#import "NSToolbar+ContextMenu.h"
@implementation NSToolbar (ContextMenu)
- (NSView*) __toolbarView {
return (NSView*)[self valueForKey:@"_toolbarView"];
}
- (void) disableTextOnlyMode {
NSView *toolbarView = [self __toolbarView];
NSMenu *toolbarMenu = toolbarView.menu;
for (NSMenuItem *item in [toolbarMenu.itemArray objectEnumerator]) {
if (item.action == @selector(changeToolbarDisplayMode:) && item.tag == 3) {
[toolbarMenu removeItem:item];
break;
}
}
}
@end