quicksilver/Quicksilver — pull request #779 by skurfer (2012-03-29 14:46:49+00:00)
Title: managing the source array from plug-ins

No comments on #768 so I’m going ahead with what I think is best. 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;

I looked at maybe using KVO for this, but I don't think it's feasible.

1. We don't want all three instances of `QSSearchObjectView` to observe the array within the action controller. Just the instance for the direct object.
2. The array won't even exist in most action controllers. In fact, Spotlight is the only one at the moment.
3. Even if an action controller had such a property, it probably won't apply to all of the actions it provides.

Better to just let the small number of actions that need this ability send a notification, I think.

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