Permalink
Browse files

add a new `isProxyObject` method to QSObject

This ensures that we use a consistent test across the codebase, and saves a fair amount of typing.
  • Loading branch information...
1 parent 8eb7869 commit e6f80fedc3b5615a5a32b5bff9af81233cf96360 @skurfer committed Nov 27, 2012
@@ -545,7 +545,7 @@ - (id)resolveProxyObject:(id)proxy {
} else {
QSObject *object = [[[self interfaceController] dSelector] objectValue];
if ([object isEqual:proxy]) return [[[self interfaceController] dSelector] previousObjectValue];
- if ([object isKindOfClass:[QSProxyObject class]]) return nil;
+ if ([object isProxyObject]) return nil;
return object;
}
return nil;
@@ -310,7 +310,7 @@ - (QSObject *)performOnDirectObject:(QSObject *)dObject indirectObject:(QSObject
if (!provider) {
provider = [QSReg getClassInstance:class];
}
- if ([[dObject primaryType] isEqualToString:QSProxyType]) {
+ if ([dObject isProxyObject]) {
dObject = (QSObject *)[dObject resolvedObject];
}
if ([[dict objectForKey:kActionSplitPluralArguments] boolValue] && [dObject count] > 1) {
@@ -475,7 +475,7 @@ - (void)executeWithIndirect:(id)indirectObject {
}
- (NSArray *)validIndirects {
- QSObject *directObject = [[[self dObject] primaryType] isEqualToString:QSProxyType] ? (QSObject *)[[self dObject] resolvedObject] : [self dObject];
+ QSObject *directObject = [[self dObject] isProxyObject] ? (QSObject *)[[self dObject] resolvedObject] : [self dObject];
NSArray *indirects = [[[self aObject] provider] validIndirectObjectsForAction:[[self aObject] identifier] directObject:directObject];
if ([indirects count] >1 && [[indirects objectAtIndex:1] isKindOfClass:[NSArray class]]) indirects = [indirects objectAtIndex:1];
if ([indirects count] == 1 && [[indirects objectAtIndex:0] containsType:QSTextProxyType]) {
@@ -287,7 +287,7 @@ - (NSArray *)rankedActionsForDirectObject:(QSObject *)dObject indirectObject:(QS
actions = (NSMutableArray *)[[dObject handler] actionsForDirectObject:dObject indirectObject:iObject];
BOOL bypassValidation =
- (bypass && [dObject isKindOfClass:[QSProxyObject class]] && [(QSProxyObject *)dObject bypassValidation]);
+ (bypass && [dObject isProxyObject] && [(QSProxyObject *)dObject bypassValidation]);
if (bypassValidation) {
//NSLog(@"bypass? %@ %@", dObject, NSStringFromClass([dObject class]) );
@@ -393,7 +393,7 @@ - (NSArray *)validActionsForDirectObject:(QSObject *)dObject indirectObject:(QSO
- (NSArray *)validIndirectObjectsForAction:(NSString *)action directObject:(QSObject *)dObject {
QSActionProvider *actionObject = [[actionIdentifiers objectForKey:action] objectForKey:kActionClass];
// NSLog(@"actionobject %@", actionObject);
- QSObject *directObject = [[dObject primaryType] isEqualToString:QSProxyType] ? (QSObject *)[dObject resolvedObject] : dObject;
+ QSObject *directObject = [dObject isProxyObject] ? (QSObject *)[dObject resolvedObject] : dObject;
return [actionObject validIndirectObjectsForAction:action directObject:directObject];
}
@@ -137,6 +137,7 @@ extern NSSize QSMaxIconSize;
- (NSMutableDictionary *)cache;
- (void)setCache:(NSMutableDictionary *)aCache;
+- (BOOL)isProxyObject;
@end
@@ -434,7 +434,7 @@ - (id)primaryObject {return itemForKey([self primaryType]);}
- (id)_safeObjectForType:(id)aKey {
id object = [data objectForKey:aKey];
- if (!object && [[self primaryType] isEqualToString:QSProxyType])
+ if (!object && [self isProxyObject])
object = [[self resolvedObject] arrayForType:aKey];
return object;
#if 0
@@ -568,6 +568,11 @@ - (NSUInteger) primaryCount {
return [self count];
}
+- (BOOL)isProxyObject
+{
+ return [self isKindOfClass:[QSProxyObject class]];
+}
+
@end
@implementation QSObject (Hierarchy)
@@ -16,7 +16,7 @@ @implementation QSProxyObjectHandler
- (NSString *)detailsOfObject:(QSObject *)object {
NSString *details = nil;
- id provider = ( [object isKindOfClass:[QSProxyObject class]] ? [(QSProxyObject*)object proxyProvider] : nil );
+ id provider = ( [object isProxyObject] ? [(QSProxyObject*)object proxyProvider] : nil );
if (provider && [provider respondsToSelector:@selector(detailsOfObject:)]) {
details = [provider detailsOfObject:object];
}
@@ -27,7 +27,7 @@ - (NSString *)detailsOfObject:(QSObject *)object {
- (NSString *)identifierForObject:(QSObject*)object {
NSString *identifier = nil;
- id provider = ( [object isKindOfClass:[QSProxyObject class]] ? [(QSProxyObject*)object proxyProvider] : nil );
+ id provider = ( [object isProxyObject] ? [(QSProxyObject*)object proxyProvider] : nil );
if (provider && [provider respondsToSelector:@selector(identifierForObject:)]) {
identifier = [provider identifierForObject:object];
}
@@ -38,7 +38,7 @@ - (NSString *)identifierForObject:(QSObject*)object {
- (BOOL)loadChildrenForObject:(QSObject *)object {
BOOL loaded = NO;
- id provider = ( [object isKindOfClass:[QSProxyObject class]] ? [(QSProxyObject*)object proxyProvider] : nil );
+ id provider = ( [object isProxyObject] ? [(QSProxyObject*)object proxyProvider] : nil );
if (provider && [provider respondsToSelector:@selector(loadChildrenForObject:)]) {
loaded = [provider loadChildrenForObject:object];
}
@@ -349,7 +349,7 @@ - (void)updateIndirectObjects {
id actionProvider = [aObj provider];
NSArray *indirects = nil;
if (actionProvider && [actionProvider respondsToSelector:@selector(validIndirectObjectsForAction:directObject:)]) {
- QSObject *directObject = [[[dSelector objectValue] primaryType] isEqualToString:QSProxyType] ? (QSObject *)[[dSelector objectValue] resolvedObject] : [dSelector objectValue];
+ QSObject *directObject = [[dSelector objectValue] isProxyObject] ? (QSObject *)[[dSelector objectValue] resolvedObject] : [dSelector objectValue];
indirects = [actionProvider validIndirectObjectsForAction:[aObj identifier] directObject:directObject];
}
// If the validIndirectObjectsForAction... method hasn't been implemented, attempt to get valid indirects from the action's 'indirectTypes'
@@ -1860,7 +1860,7 @@ - (BOOL)canQuicklookCurrentObject {
object = [(QSRankedObject *)object object];
}
// resolve proxy objects
- if ([object isKindOfClass:[QSProxyObject class]]) {
+ if ([object isProxyObject]) {
object = [(QSProxyObject *)object resolvedObject];
}
if ([object validPaths] || [[object primaryType] isEqualToString:QSURLType]) {

0 comments on commit e6f80fe

Please sign in to comment.