I'm looking for a 开发者_如何学编程way to intercept all dock icon clicks(so I can display various windows in my own way). Is there a way to do this?
Check out [NSDockTilePlugin dockMenu] and see if overriding that takes care of what you want to do.
http://developer.apple.com/library/mac/documentation/AppKit/Reference/NSDockTilePlugIn_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/NSDockTilePlugIn/dockMenu
This worked best for me.
Note that I just wanted to get notified of the dock icon clicked, I did not intend to customize the display of the window list - so it is solves a sligthly smaller problem than the OP had. But since search led me here, I think this answer will help others too.
Within applicationDidFinishLaunching:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationWillEnterForeground:)
name:NSApplicationWillBecomeActiveNotification
object:nil];
Then I get notified here:
- (void)applicationWillEnterForeground:(NSNotification *)application {
// The dock icon was clicked, do your thing.
}
精彩评论