Finished the OS X menu disabling code.

This commit is contained in:
Pietro Gagliardi 2015-05-03 02:45:59 -04:00
parent 810e2225ea
commit 2a6da36542
2 changed files with 10 additions and 8 deletions

View File

@ -93,20 +93,20 @@ enum {
// therefore, we have to handle enabling of the other options ourselves // therefore, we have to handle enabling of the other options ourselves
- (BOOL)validateMenuItem:(NSMenuItem *)item - (BOOL)validateMenuItem:(NSMenuItem *)item
{ {
struct menuItem *item; struct menuItem *smi;
NSValue *v; NSValue *v;
// disable the special items if they aren't present // disable the special items if they aren't present
if (item == self.quitItem && !self.hasQuit) if (item == self.quitItem && !self->hasQuit)
return NO; return NO;
if (item == self.prefsItem && !self.hasPreferences) if (item == self.preferencesItem && !self->hasPreferences)
return NO; return NO;
if (item == self.aboutItem && !self.hasAbout) if (item == self.aboutItem && !self->hasAbout)
return NO; return NO;
// then poll the item's enabled/disabled state // then poll the item's enabled/disabled state
v = (NSValue *) [self->items objectForKey:sender]; v = (NSValue *) [self->items objectForKey:item];
item = (struct menuItem *) [v pointerValue]; smi = (struct menuItem *) [v pointerValue];
return !item->disabled; return !smi->disabled;
} }
// Cocoa constructs the default application menu by hand for each program; that's what MainMenu.[nx]ib does // Cocoa constructs the default application menu by hand for each program; that's what MainMenu.[nx]ib does

View File

@ -15,7 +15,7 @@
#define macYMargin 20 #define macYMargin 20
// menu.m // menu.m
@interface menuManager : NSObject <NSMenuValidation> { @interface menuManager : NSObject {
// unfortunately NSMutableDictionary copies its keys, meaning we can't use it for pointers // unfortunately NSMutableDictionary copies its keys, meaning we can't use it for pointers
NSMapTable *items; NSMapTable *items;
BOOL hasQuit; BOOL hasQuit;
@ -25,6 +25,8 @@
@property (strong) NSMenuItem *quitItem; @property (strong) NSMenuItem *quitItem;
@property (strong) NSMenuItem *preferencesItem; @property (strong) NSMenuItem *preferencesItem;
@property (strong) NSMenuItem *aboutItem; @property (strong) NSMenuItem *aboutItem;
// NSMenuValidation is only informal (TODO)
- (BOOL)validateMenuItem:(NSMenuItem *)item;
- (NSMenu *)makeMenubar; - (NSMenu *)makeMenubar;
@end @end