Skip to content
Browse files

Merge pull request #1 from pjrobertson/master

Services Module tidy up
  • Loading branch information...
2 parents a2b3866 + 12c73a6 commit f7d8692cb735fb86a41aa2beb9c317cc270c7984 @skurfer skurfer committed Mar 28, 2012
Showing with 92 additions and 60 deletions.
  1. +2 −0 Info.plist
  2. +79 −58 QSServiceAction.m
  3. +11 −2 QSServicesMenuPlugIn.xcodeproj/project.pbxproj
View
2 Info.plist
@@ -14,6 +14,8 @@
<string>Services Menu Module</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
+ <key>CFBundleShortVersionString</key>
+ <string>1.0.0</string>
<key>CFBundleVersion</key>
<string>C2</string>
<key>NSHumanReadableCopyright</key>
View
137 QSServiceAction.m
@@ -20,6 +20,8 @@
#define NSKeyEquivalentKey @"NSKeyEquivalent"
#define infoPath @"Contents/Info.plist"
+#define kBundleID @"com.blacktree.Quicksilver.QSServicesMenuPlugIn"
+
NSMutableArray *servicesForBundle(NSString *path) {
if (path) {
NSString *dictPath = [path stringByAppendingPathComponent:infoPath];
@@ -31,19 +33,17 @@
NSArray *providersAtPath(NSString *path) {
NSFileManager *manager = [NSFileManager defaultManager];
NSMutableArray *providers = [NSMutableArray arrayWithCapacity:1];
- NSString *itemPath;
- NSArray *subPaths;
- int i;
-
+
path = [path stringByStandardizingPath];
- subPaths = [manager subpathsAtPath:path];
-
- for (i = 0; i < [subPaths count]; i++){
- itemPath = [subPaths objectAtIndex:i];
- if ([itemPath hasSuffix:infoPath]) {
- itemPath = [path stringByAppendingPathComponent:itemPath];
- if ([[NSMutableDictionary dictionaryWithContentsOfFile:itemPath] objectForKey:NSServicesKey]) {
- [providers addObject:[[itemPath stringByDeletingLastPathComponent] stringByDeletingLastPathComponent]];
+ NSArray *subPaths = [manager subpathsAtPath:path];
+ @autoreleasepool {
+ for (NSString *itemPath in subPaths){
+ if ([itemPath hasSuffix:infoPath]) {
+ itemPath = [path stringByAppendingPathComponent:itemPath];
+ NSDictionary *servicesDict = [[NSDictionary dictionaryWithContentsOfFile:itemPath] objectForKey:NSServicesKey];
+ if ([servicesDict count]) {
+ [providers addObject:[[itemPath stringByDeletingLastPathComponent] stringByDeletingLastPathComponent]];
+ }
}
}
}
@@ -52,14 +52,15 @@
NSArray *applicationProviders() {
NSMutableArray *providers = [NSMutableArray arrayWithCapacity:1];
- NSString *itemPath;
- NSArray *apps = [[NSWorkspace sharedWorkspace] allApplications];
- int i;
+
- for (i = 0; i < [apps count]; i++){
- itemPath = [apps objectAtIndex:i];
- if ([[NSMutableDictionary dictionaryWithContentsOfFile:[itemPath stringByAppendingPathComponent:infoPath]] objectForKey:NSServicesKey]) {
- [providers addObject:itemPath];
+ NSArray *apps = [[NSWorkspace sharedWorkspace] allApplications];
+ @autoreleasepool {
+ for (NSString *itemPath in apps){
+ NSDictionary *servicesDict = [[NSDictionary dictionaryWithContentsOfFile:[itemPath stringByAppendingPathComponent:infoPath]] objectForKey:NSServicesKey];
+ if ([servicesDict count]) {
+ [providers addObject:itemPath];
+ }
}
}
return providers;
@@ -76,10 +77,12 @@ + (void)loadServiceActions {
[[QSTaskController sharedInstance] updateTask:@"Load Actions" status:@"Loading Application Services" progress:-1];
NSArray *serviceActions = [QSServiceActions allServiceActions];
- int i;
- for (i = 0; i < [serviceActions count]; i++) {
- [QSExec performSelectorOnMainThread:@selector(addActions:) withObject:[[serviceActions objectAtIndex:i] actions] waitUntilDone:YES];
- }
+
+ @autoreleasepool {
+ for (id individualAction in serviceActions) {
+ [QSExec performSelectorOnMainThread:@selector(addActions:) withObject:[individualAction actions] waitUntilDone:YES];
+ }
+ }
//NSLog(@"Services Loaded");
[[QSTaskController sharedInstance] removeTask:@"Load Actions"];
[pool release];
@@ -95,9 +98,11 @@ + (NSArray *)allServiceActions {
NSArray *providerArray = [providerSet allObjects];
NSMutableArray *actionObjects = [NSMutableArray arrayWithCapacity:[providerArray count]];
- int i;
- for (i = 0; i < [providerArray count]; i++)
- [actionObjects addObject:[[self class] serviceActionsForBundle:[providerArray objectAtIndex:i]]];
+ @autoreleasepool {
+ for (id individualProvider in providerArray) {
+ [actionObjects addObject:[[self class] serviceActionsForBundle:individualProvider]];
+ }
+ }
return actionObjects;
}
@@ -123,29 +128,44 @@ - (NSArray *)actions {
NSMutableArray *newActions = [NSMutableArray arrayWithCapacity:1];
NSImage *icon = [[NSWorkspace sharedWorkspace] iconForFile:serviceBundle];
[icon setSize:NSMakeSize(16, 16)];
+
+ if (![serviceArray count]) {
+ return nil;
+ }
+ NSBundle *servicesBundle = [NSBundle bundleWithIdentifier:kBundleID];
+
+ for (NSDictionary *thisService in serviceArray) {
- int i;
- for (i = 0; i < [serviceArray count]; i++) {
- NSDictionary *thisService = [serviceArray objectAtIndex:i];
NSString *serviceString = [[thisService objectForKey:NSMenuItemKey] objectForKey:DefaultKey];
- NSDictionary *serviceModifications = [modificationsDictionary objectForKey:serviceString];
- if ([[serviceModifications objectForKey:@"disabled"] boolValue])
+ if (!serviceString) {
+ continue;
+ }
+ id serviceModifications = [modificationsDictionary objectForKey:serviceString];
+
+ if ([serviceModifications isKindOfClass:[NSString class]]) {
+ NSLog(@"Couldn't get action for %@ with service string %@",thisService,serviceString);
+ continue;
+ }
+
+ if ([[(NSDictionary *)serviceModifications objectForKey:@"disabled"] boolValue])
continue;
QSAction *serviceAction = [[QSAction alloc] init];
[serviceAction setIdentifier:serviceString];
- if ([serviceModifications objectForKey:@"name"])
- [serviceAction setName:[serviceModifications objectForKey:@"name"]];
+ if ([(NSDictionary *)serviceModifications objectForKey:@"name"])
+ [serviceAction setName:[(NSDictionary *)serviceModifications objectForKey:@"name"]];
NSArray *sendTypes = [thisService objectForKey:NSSendTypesKey];
-
+
if (sendTypes) {
[serviceAction setDirectTypes:sendTypes];
}
+ [serviceAction setBundle:servicesBundle];
[serviceAction setIcon:icon];
+ [serviceAction setIconLoaded:YES];
[serviceAction setProvider:self];
[serviceAction setDisplaysResult:YES];
[serviceAction setDetails:[NSString stringWithFormat:@"A service of %@",[serviceBundle lastPathComponent]]];
@@ -163,23 +183,23 @@ - (NSArray *)validActionsForDirectObject:(QSObject *)dObject indirectObject:(QSO
NSMutableArray *newActions = [NSMutableArray arrayWithCapacity:1];
NSString *menuItem;
- int i;
// NSLog(@"services%@", serviceArray);
- for (i = 0; i < [serviceArray count]; i++) {
- NSDictionary *thisService = [serviceArray objectAtIndex:i];
- menuItem = [[thisService objectForKey:NSMenuItemKey] objectForKey:DefaultKey];
-
- BOOL disabled = [[[modificationsDictionary objectForKey:menuItem] objectForKey:@"disabled"] boolValue];
- if (menuItem && !disabled) {
- NSSet *sendTypes = [NSSet setWithArray:[thisService objectForKey:NSSendTypesKey]];
- NSSet *availableTypes = [NSSet setWithArray:[dObject types]];
+ @autoreleasepool {
+ for (NSDictionary *thisService in serviceArray) {
+ menuItem = [[thisService objectForKey:NSMenuItemKey] objectForKey:DefaultKey];
- // Add if they intersect, but ignore ex
- if ([sendTypes intersectsSet:availableTypes]){
- if (fileType && ![sendTypes containsObject:NSFilenamesPboardType])
- continue;
-
- [newActions addObject:menuItem];
+ BOOL disabled = [[[modificationsDictionary objectForKey:menuItem] objectForKey:@"disabled"] boolValue];
+ if (menuItem && !disabled) {
+ NSSet *sendTypes = [NSSet setWithArray:[thisService objectForKey:NSSendTypesKey]];
+ NSSet *availableTypes = [NSSet setWithArray:[dObject types]];
+
+ // Add if they intersect, but ignore ex
+ if ([sendTypes intersectsSet:availableTypes]){
+ if (fileType && ![sendTypes containsObject:NSFilenamesPboardType])
+ continue;
+
+ [newActions addObject:menuItem];
+ }
}
}
}
@@ -192,15 +212,16 @@ - (QSObject *)performAction:(QSAction *)action directObject:(QSBasicObject *)dOb
NSPasteboard *pboard = [NSPasteboard pasteboardWithUniqueName];
NSDictionary *thisService = nil;
//NSLog(@"perform %@ %@ %@",[action actionDict],serviceArray,self);
- int i;
- for (i = 0; i < [serviceArray count]; i++) {
- thisService = [serviceArray objectAtIndex:i];
- // NSLog(@"'%@' '%@'",[action identifier],[[thisService objectForKey:NSMenuItemKey]objectForKey:DefaultKey]);
-
- if ([[[thisService objectForKey:NSMenuItemKey] objectForKey:DefaultKey] isEqualToString:[action identifier]]) {
- NSArray *sendTypes = [thisService objectForKey:NSSendTypesKey];
- [dObject putOnPasteboard:pboard declareTypes:sendTypes includeDataForTypes:sendTypes];
- break;
+
+ @autoreleasepool {
+ for (thisService in serviceArray) {
+ // NSLog(@"'%@' '%@'",[action identifier],[[thisService objectForKey:NSMenuItemKey]objectForKey:DefaultKey]);
+
+ if ([[[thisService objectForKey:NSMenuItemKey] objectForKey:DefaultKey] isEqualToString:[action identifier]]) {
+ NSArray *sendTypes = [thisService objectForKey:NSSendTypesKey];
+ [dObject putOnPasteboard:pboard declareTypes:sendTypes includeDataForTypes:sendTypes];
+ break;
+ }
}
}
View
13 QSServicesMenuPlugIn.xcodeproj/project.pbxproj
@@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
- objectVersion = 42;
+ objectVersion = 46;
objects = {
/* Begin PBXBuildFile section */
@@ -161,9 +161,16 @@
/* Begin PBXProject section */
0259C573FE90428111CA0C5A /* Project object */ = {
isa = PBXProject;
+ attributes = {
+ LastUpgradeCheck = 0420;
+ };
buildConfigurationList = 7FFF2503085E488600266176 /* Build configuration list for PBXProject "QSServicesMenuPlugIn" */;
- compatibilityVersion = "Xcode 2.4";
+ compatibilityVersion = "Xcode 3.2";
+ developmentRegion = English;
hasScannedForEncodings = 1;
+ knownRegions = (
+ en,
+ );
mainGroup = 0259C574FE90428111CA0C5A /* QSServicesMenuPlugIn */;
projectDirPath = "";
projectRoot = "";
@@ -244,13 +251,15 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 4D308B230F45BCA6009433C0 /* Debug.xcconfig */;
buildSettings = {
+ ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
};
name = Debug;
};
7FFF2505085E488600266176 /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 4D308B290F45BCA6009433C0 /* Release.xcconfig */;
buildSettings = {
+ ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
};
name = Release;
};

0 comments on commit f7d8692

Please sign in to comment.
Something went wrong with that request. Please try again.