From 3263678eef57c78d7017185eaa2efb9e644c7f29 Mon Sep 17 00:00:00 2001 From: Joseph Spiros Date: Wed, 9 Nov 2005 21:20:26 +0000 Subject: [PATCH] Adding API to ITStatusItem for callbacks to get dynamic menus. --- ITStatusItem.h | 11 ++++++++++- ITStatusItem.m | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/ITStatusItem.h b/ITStatusItem.h index f2f6070..7085c78 100644 --- a/ITStatusItem.h +++ b/ITStatusItem.h @@ -14,8 +14,14 @@ #import -@interface ITStatusItem : NSStatusItem { +@class ITStatusItem; + +@protocol ITStatusItemMenuProvider +- (NSMenu *)menuForStatusItem:(ITStatusItem *)statusItem; +@end +@interface ITStatusItem : NSStatusItem { + id _menuProvider; } - (id)initWithStatusBar:(NSStatusBar *)statusBar withLength:(float)length; @@ -23,4 +29,7 @@ - (NSImage *)alternateImage; - (void)setAlternateImage:(NSImage *)image; +- (id )menuProvider; +- (void)setMenuProvider:(id )provider; + @end \ No newline at end of file diff --git a/ITStatusItem.m b/ITStatusItem.m index ea31d3a..561ecf2 100644 --- a/ITStatusItem.m +++ b/ITStatusItem.m @@ -51,4 +51,21 @@ static BOOL _ITStatusItemShouldKillShadow = NO; [(NSButton *)[self _button] setAlternateImage:image]; } +- (id )menuProvider { + return _menuProvider; +} + +- (void)setMenuProvider:(id )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 -- 2.20.1