Skip to content

Commit

Permalink
Merge pull request #494 from pjrobertson/commaTrickEjectAction
Browse files Browse the repository at this point in the history
Small bug fixes
  • Loading branch information
skurfer committed Oct 13, 2011
2 parents 5a8f489 + 9b2031a commit d8b4bdc
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 34 deletions.
67 changes: 41 additions & 26 deletions Quicksilver/Code-QuickStepCore/QSCommand.m
Expand Up @@ -283,20 +283,31 @@ - (void)setIndirectObject:(QSObject*)newObject {

- (QSAction *)aObject {
QSAction *action = aObject;
if (!action) {
action = [QSAction actionWithIdentifier:[[self commandDict] objectForKey:@"actionID"]];
[self setActionObject:action];
}
if (!action) {
action = [QSAction actionWithDictionary:[[self commandDict] objectForKey:@"actionArchive"]];
[self setActionObject:action];
if (action) {
return action;
}

NSDictionary *cmdDict = [self commandDict];

action = [QSAction actionWithIdentifier:[cmdDict objectForKey:@"actionID"]];

if (!action) {
action = [QSAction actionWithDictionary:[cmdDict objectForKey:@"actionArchive"]];
}

if (!action) {
NSLog(@"Warning: no action object for Command %@\nCommand Dictionary: %@", self, cmdDict);
}
else {
[self setActionObject:action];
}

return action;
}

- (QSObject *)dObject {
QSObject *object = dObject;
// If we have the object, do not go through numerous 'if(!object)' before returning
// Return the object if it already exists
if (object) {
return object;
}
Expand All @@ -306,25 +317,28 @@ - (QSObject *)dObject {

if (directID) {
object = [QSObject objectWithIdentifier:directID];
// For cases where the command has a directID/directArchive, but it's corresponding object hasn't already been created (i.e. *not* in the catalog)
if (!object) {
// sniffs the string to create a new object
object = [QSObject objectWithString:directID];
}
}
}

if (!object) {
object = [QSObject objectWithDictionary:[[self commandDict] objectForKey:@"directArchive"]];
object = [QSObject objectWithDictionary:[cmdDict objectForKey:@"directArchive"]];
}


if (!object)
if (!object) {
object = [QSObject fileObjectWithPath:[QSRez pathWithLocatorInformation:[cmdDict objectForKey:@"directResource"]]];
}

// For cases where the command has a directID/directArchive, but it's corresponding object hasn't already been created (i.e. *not* in the catalog)
if (!object && directID) {
// sniffs the string to create a new object
object = [QSObject objectWithString:directID];
}


// For cases where we really can't determine the object
if (!object) {
NSLog(@"Warning: no direct object for Command %@\nCommand Dictionary: %@", self, cmdDict);
}
if (object) {
else {
[self setDirectObject:object];
}
return object;
Expand All @@ -338,24 +352,25 @@ - (QSObject *)iObject {

NSDictionary *cmdDict = [self commandDict];
NSString *indirectID = [cmdDict objectForKey:@"indirectID"];

if (indirectID) {
object = [QSObject objectWithIdentifier:indirectID];
if (!object) {
// For cases where the object doesn't exist
if (!object) {
// create an object by sniffing the string
object = [QSObject objectWithString:indirectID];
}
}
}

if (!object) {
object = [QSObject objectWithDictionary:[[self commandDict] objectForKey:@"indirectArchive"]];
object = [QSObject objectWithDictionary:[cmdDict objectForKey:@"indirectArchive"]];
}

if (!object) {
object = [QSObject fileObjectWithPath:[QSRez pathWithLocatorInformation:[cmdDict objectForKey:@"indirectResource"]]];
}

// For cases where the object doesn't exist (not in the catalog)
if (!object && indirectID) {
// create an object by sniffing the string
object = [QSObject objectWithString:indirectID];
}

if (object) {
[self setIndirectObject:object];
}
Expand Down
Expand Up @@ -236,23 +236,43 @@ - (NSArray *)actions {
}

- (NSArray *)validActionsForDirectObject:(QSObject *)dObject indirectObject:(QSObject *)iObject {
if ([[[dObject singleFilePath] stringByStandardizingPath] hasPrefix:@"/Volumes/"])
NSArray *paths = [dObject arrayForType:QSFilePathType];
BOOL valid = NO;
if (paths)
{
valid = YES;
for (NSString *path in paths) {
if (![[path stringByStandardizingPath] hasPrefix:@"/Volumes/"]) {
valid = NO;
break;
}
}
}
if (valid)
return [NSArray arrayWithObject:kDiskEjectAction];
else
else {
return nil;
}
}

- (QSObject *)performAction:(QSAction *)action directObject:(QSBasicObject *)dObject indirectObject:(QSBasicObject *)iObject {
NSString *firstFile = [dObject singleFilePath];
if ([[[NSWorkspace sharedWorkspace] mountedLocalVolumePaths] containsObject:[[dObject singleFilePath] stringByStandardizingPath]]) {
if (![[NSWorkspace sharedWorkspace] unmountAndEjectDeviceAtPath:firstFile]) {
NSDictionary *errorDict;
NSAppleScript *script = [[NSAppleScript alloc] initWithSource:[NSString stringWithFormat:@"tell application \"Finder\" to eject disk \"%@\"", [[NSFileManager defaultManager] displayNameAtPath:firstFile]]];
NSWorkspace *ws = [NSWorkspace sharedWorkspace];
for (NSString *mountedVolume in [dObject arrayForType:QSFilePathType]) {
if ([[ws mountedLocalVolumePaths] containsObject:[mountedVolume stringByStandardizingPath]]) {
NSError *err = nil;
if (![ws unmountAndEjectDeviceAtURL:[NSURL fileURLWithPath:mountedVolume] error:&err]) {
NSLog(@"Error unmounting: %@\nTrying to use Finder (via Applescript)",err);
NSDictionary *errorDict = nil;
NSAppleScript *script = [[NSAppleScript alloc] initWithSource:[NSString stringWithFormat:@"tell application \"Finder\" to eject disk \"%@\"", [[NSFileManager defaultManager] displayNameAtPath:mountedVolume]]];
[script executeAndReturnError:&errorDict];
[script release];
if (errorDict) NSBeep();
if (errorDict) {
NSBeep();
NSLog(@"Error: %@",errorDict);
}
}
}
}
return nil;
}

Expand Down

0 comments on commit d8b4bdc

Please sign in to comment.