0

I have a weird "bug". I'm creating an "Edit" menu for my Mac OSX application. It shall contain copy, paste, select all et.c. I have solved the functionality by simply connecting the appropriate selectors in the first responer to the menues.

I connect my paste menuitem to paste: I connect my copy menuutem to copy:

This work great, and I am able to copy and paste using both the menu and shortcuts associated with them.

However, when connecting to the copy: selector of the first responer, two new menu options appear at the bottom: "Dictations" and "Special Character".

How do I remove them? I am creating the menus in Interface Builder in a xib-file.

Sunkas
  • 9,542
  • 6
  • 62
  • 102
  • 1
    Please don't remove those menu items. You personally may have no use for them, but other Mac users expect those menu items to be available. – chrstphrchvz Mar 04 '19 at 09:26

2 Answers2

0

Solved it by manually removing the submenus from code:

- (void)windowDidLoad {
    [super windowDidLoad];
    [self presentModalViewController:self.bookshelfController withData:nil];

    [self removeLastMenuItemsOfRedigeraMenu];
}

-(void)removeLastMenuItemsOfRedigeraMenu
{

    NSMenu *mainMenu = [NSApp mainMenu];
    for (NSMenuItem* subMenu in mainMenu.itemArray)
    {
        if ([subMenu.title isEqualToString:@"Redigera"])
        {
            NSArray *array = subMenu.submenu.itemArray;
            for (int i = (int)array.count-1; i >= 0; i--)
            {
                if (i >= 11)
                {
                    [subMenu.submenu removeItem:[array objectAtIndex:i]];
                }
            }
        }
    }
}

Please post if you have a better answer

Sunkas
  • 9,542
  • 6
  • 62
  • 102
-1

You can change the name of the menu item to any other, and through the awakeFromNib back with the name you want.

Something like:

    [_editMenuItem.submenu setTitle:NSLocalizedString(@"Edit",NULL)];

It only adds these menus when the title is "edit" on any of the supported languages​​. But just when loading the interface, then (awakeFromNib) can already put the name again.

Wallacy
  • 59
  • 5
  • I don't get what you mean. My title is never "edit". It is always "Redigera" (swedish for "edit"). You suggest that setting the editMenu from code removes the "Dictations" and "Special Character"? – Sunkas Nov 11 '13 at 13:03
  • 1
    @Sunkas Because "Redigera" is a swedish for "edit" and this behavior occurs in translations for "edit" too. Just rename for "someName" in xib and return to "Redigera" after load will works fine. For exemple: My "edit" menu is "Editar" (Portuguese), if i call with this name will apear "Dictations" and "Special Character". So, I renamed this menu title to "someName" and on awakeFromNib I changed to "Editar" again. – Wallacy Nov 19 '13 at 12:49