gnustep / libs-gui

The GNUstep gui library is a library of graphical user interface classes written completely in the Objective-C language; the classes are based upon Apple's Cocoa framework (which came from the OpenStep specification). *** Larger patches require copyright assignment to FSF. please file bugs here. ***
http://www.gnustep.org
GNU General Public License v3.0
279 stars 103 forks source link

NSMenu ignores initWithTitle #218

Open optimisme opened 11 months ago

optimisme commented 11 months ago

This works: NSMenuItem fileMenuItem = [NSMenuItem new]; NSMenu fileMenu = [[NSMenu alloc] initWithTitle:@""]; [fileMenuItem setTitle:@"File"];

But this does not work: NSMenuItem fileMenuItem = [NSMenuItem new]; NSMenu fileMenu = [[NSMenu alloc] initWithTitle:@"File"];

2xsaiko commented 11 months ago

You are doing [fileMenuItem setSubmenu:fileMenu];, right? But even with that, you're right it doesn't work. Though I'm also very new to GNUstep/Cocoa, so I have no idea what is actually supposed to happen.

According to Apple documentation:

This property contains a string value indicating the title of the menu. If the menu is a submenu of the application’s main menu, then the title of the menu appears in the menu bar.

So yeah, it seems to me that the NSMenuItem should inherit the title of the NSMenu. But in setSubmenu: the opposite is happening: https://github.com/gnustep/libs-gui/blob/master/Source/NSMenuItem.m#L241

In any case, this doesn't seem to be related to initWithTitle, but rather that in the top code you're setting the title of the NSMenuItem, in the bottom code you're setting the title of the NSMenu.