Adding API to ITStatusItem for callbacks to get dynamic menus.
[ITKit.git] / ITStatusItem.m
index b758d5c..561ecf2 100644 (file)
@@ -27,13 +27,13 @@ static BOOL _ITStatusItemShouldKillShadow = NO;
 }
 
 - (id)_initInStatusBar:(NSStatusBar *)statusBar withLength:(float)length withPriority:(int)priority {
-    if ((self = [super _initInStatusBar:statusBar withLength:length withPriority:priority])) {
+       if ((self = [super _initInStatusBar:statusBar withLength:length withPriority:priority])) {
                if (_ITStatusItemShouldKillShadow) {
                        [[(NSButton *)[self _button] cell] setType:NSNullCellType];
                }
-        [self setHighlightMode:YES];
-    }
-    return self;
+           [self setHighlightMode:YES];
+       }
+       return self;
 }
 
 - (NSImage *)alternateImage {
@@ -48,7 +48,24 @@ static BOOL _ITStatusItemShouldKillShadow = NO;
                [(id <_ITStatusItemNSStatusItemPantherCompatability>)super setAlternateImage:image];
                return;
        }
-    [(NSButton *)[self _button] setAlternateImage:image];
+       [(NSButton *)[self _button] setAlternateImage:image];
+}
+
+- (id <ITStatusItemMenuProvider>)menuProvider {
+       return _menuProvider;
+}
+
+- (void)setMenuProvider:(id <ITStatusItemMenuProvider>)provider {
+       [_menuProvider autorelease];
+       _menuProvider = [provider retain];
+}
+
+- (NSMenu *)menu {
+       if (_menuProvider) {
+               return [_menuProvider menuForStatusItem:self];
+       } else {
+               return [super menu];
+       }
 }
 
 @end
\ No newline at end of file