quicksilver/Quicksilver — pull request #801 by skurfer (2012-04-08 04:12:10+00:00)
Title: managing the source array from plug-ins

This resolves issues brought up in #768.

I’ve moved the observation of the QSSourceArrayUpdated notification from QSSearchObjectView to QSInterfaceController for several reasons.

1. Much of the behavior triggered by the notification was handled by the interface controller anyway (as is the behavior of the newly added notification).
2. There are up to 6 instances of QSSearchObjectView all responding to this notification, when it only applies to one of them (`dSelector`). There’s only one QSInterfaceController …well, two, but I’ve handled that.
3. This prevents us from having to do awful things like giving the QSSearchObjectView class knowledge of one of it’s specific instances.

Here’s the difference in what a plug-in will need to do.

Before:

#import
[…more code…]
QSInterfaceController *controller = [[NSApp delegate] interfaceController]; // ← compiler warns about this because [NSApp delegate] can’t be cast as a QSController from a plug-in
[controller showArray:someArray];

After:

[[NSNotificationCenter defaultCenter] postNotificationName:@"QSSourceArrayCreated" object:someArray];

To test, put this in an action and watch the results change before your eyes. :-)

NSMutableArray *someArray = [NSMutableArray arrayWithCapacity:1];
QSObject *a = [QSObject objectWithName:@"One"];
QSObject *b = [QSObject objectWithName:@"Two"];
QSObject *c = [QSObject objectWithName:@"Three"];
[someArray addObject:a];
[[NSNotificationCenter defaultCenter] postNotificationName:@"QSSourceArrayCreated" object:someArray];
sleep(2);
[someArray addObject:b];
[[NSNotificationCenter defaultCenter] postNotificationName:@"QSSourceArrayUpdated" object:someArray];
sleep(2);
[someArray addObject:c];
[someArray removeObject:a];
[[NSNotificationCenter defaultCenter] postNotificationName:@"QSSourceArrayUpdated" object:someArray];
return nil;

Reminder to self: Add this notification to the wiki if/when it gets merged.