-/*************************************************************************/
-#pragma mark -
-#pragma mark EVIL HACKERY
-/*************************************************************************/
+@interface ITStatusItemMenuProxy : NSProxy {
+ id <ITStatusItemMenuProvider> menuProvider;
+ ITStatusItem *statusItem;
+ AbsoluteTime cachedTime;
+ NSMenu *menu;
+}
+
+- (id)initWithMenuProvider:(id <ITStatusItemMenuProvider>)provider statusItem:(ITStatusItem *)item;
+
+@end
+
+@implementation ITStatusItemMenuProxy
+
++ (BOOL)respondsToSelector:(SEL)aSelector {
+ if (![super respondsToSelector:aSelector]) {
+ return [NSMenu respondsToSelector:aSelector];
+ }
+ return YES;
+}
+
+- (id)initWithMenuProvider:(id <ITStatusItemMenuProvider>)provider statusItem:(ITStatusItem *)item {
+ menuProvider = [provider retain];
+ statusItem = [item retain];
+ cachedTime = UpTime();
+ menu = nil;
+ return self;
+}
+
+- (void)forwardInvocation:(NSInvocation *)anInvocation {
+ AbsoluteTime diff = SubAbsoluteFromAbsolute(UpTime(),cachedTime);
+
+ if (!menu || diff.lo > 1000000) {
+ [menu release];
+ menu = [[menuProvider menuForStatusItem:statusItem] retain];
+ cachedTime = UpTime();
+ }
+
+ [anInvocation setTarget:menu];
+ [anInvocation invoke];
+}
+
+- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector {
+ return [NSMenu instanceMethodSignatureForSelector:aSelector];
+}