3

I have following menu for my toolbar:

enter image description here

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.

Volodymyr B.
  • 3,369
  • 2
  • 30
  • 48

1 Answers1

0

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
Volodymyr B.
  • 3,369
  • 2
  • 30
  • 48