aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorMax <post@wickenrode.com>2018-01-13 06:06:06 +0100
committerMax <post@wickenrode.com>2018-01-13 06:06:06 +0100
commit9c2f82c0f7326d71070731ce8248f164c00e06aa (patch)
tree19b92ac431187354fc0249ff187030a284a37dab /Source
parentf4ac8ae36e216f2b678e46f7c8f98e5a55c40c76 (diff)
downloadsequelpro-9c2f82c0f7326d71070731ce8248f164c00e06aa.tar.gz
sequelpro-9c2f82c0f7326d71070731ce8248f164c00e06aa.tar.bz2
sequelpro-9c2f82c0f7326d71070731ce8248f164c00e06aa.zip
Replace all calls to deprecated method +propertyListFromData:mutabilityOption:format:errorDescription:
Diffstat (limited to 'Source')
-rw-r--r--Source/GeneratePreviewForURL.m57
-rw-r--r--Source/SPAppController.m609
-rw-r--r--Source/SPBundleEditorController.m65
-rw-r--r--Source/SPContentFilterManager.m44
-rw-r--r--Source/SPCopyTable.m475
-rw-r--r--Source/SPDatabaseDocument.m113
-rw-r--r--Source/SPFieldEditorController.m30
-rw-r--r--Source/SPQueryControllerInitializer.m34
-rw-r--r--Source/SPQueryFavoriteManager.m20
-rw-r--r--Source/SPTableContent.m27
-rw-r--r--Source/SPTextViewAdditions.m433
11 files changed, 1005 insertions, 902 deletions
diff --git a/Source/GeneratePreviewForURL.m b/Source/GeneratePreviewForURL.m
index 9dce1011..511a3f2e 100644
--- a/Source/GeneratePreviewForURL.m
+++ b/Source/GeneratePreviewForURL.m
@@ -145,20 +145,23 @@ void CancelPreviewGeneration(void* thisInterface, QLPreviewRequestRef preview)
#pragma mark -
NSString *PreviewForSPF(NSURL *myURL, NSInteger *previewHeight) {
-
+ NSDictionary *spf = nil;
NSError *readError = nil;
- NSString *convError = nil;
- NSPropertyListFormat format;
- NSString *html = nil;
-
+
// Get spf data as dictionary
- NSData *pData = [NSData dataWithContentsOfFile:[myURL path] options:NSUncachedRead error:&readError];
- NSDictionary *spf = [[NSPropertyListSerialization propertyListFromData:pData
- mutabilityOption:NSPropertyListImmutable
- format:&format
- errorDescription:&convError] retain];
+ NSData *pData = [NSData dataWithContentsOfFile:[myURL path]
+ options:NSUncachedRead
+ error:&readError];
+
+ if(pData && !readError) {
+ spf = [[NSPropertyListSerialization propertyListWithData:pData
+ options:NSPropertyListImmutable
+ format:NULL
+ error:&readError] retain];
+ }
- if(!readError && spf && ![convError length] && (format == NSPropertyListXMLFormat_v1_0 || format == NSPropertyListBinaryFormat_v1_0)) {
+ NSString *html = nil;
+ if(!readError && spf) {
NSString *spfType = [spf objectForKey:SPFFormatKey];
NSString *(*fp)(NSDictionary *spf,NSURL *myURL, NSInteger *previewHeight) = NULL;
// Dispatch different spf formats
@@ -378,16 +381,21 @@ NSString *PreviewForSPFS(NSURL *myURL,NSInteger *previewHeight)
}
NSError *readError = nil;
- NSString *convError = nil;
- NSPropertyListFormat format;
NSDictionary *spf = nil;
// Get info.plist data as dictionary
- NSData *pData = [NSData dataWithContentsOfFile:[NSString stringWithFormat:@"%@/info.plist", [myURL path]] options:NSUncachedRead error:&readError];
- spf = [[NSPropertyListSerialization propertyListFromData:pData
- mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&convError] retain];
+ NSData *pData = [NSData dataWithContentsOfFile:[[myURL path] stringByAppendingPathComponent:@"info.plist"]
+ options:NSUncachedRead
+ error:&readError];
+
+ if(pData && !readError) {
+ spf = [[NSPropertyListSerialization propertyListWithData:pData
+ options:NSPropertyListImmutable
+ format:NULL
+ error:&readError] retain];
+ }
- if(!spf || readError != nil || [convError length] || !(format == NSPropertyListXMLFormat_v1_0 || format == NSPropertyListBinaryFormat_v1_0)) {
+ if(!spf || readError) {
[spf release];
return nil;
}
@@ -434,14 +442,19 @@ NSString *PreviewForSPFS(NSURL *myURL,NSInteger *previewHeight)
continue;
}
// Get info.plist data as dictionary
- NSDictionary *sessionSpf;
+ NSDictionary *sessionSpf = nil;
pData = [NSData dataWithContentsOfFile:spfPath options:NSUncachedRead error:&readError];
- sessionSpf = [[NSPropertyListSerialization propertyListFromData:pData
- mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&convError] retain];
+ if(pData && !readError) {
+ sessionSpf = [[NSPropertyListSerialization propertyListWithData:pData
+ options:NSPropertyListImmutable
+ format:NULL
+ error:&readError] retain];
+ }
- if(!sessionSpf || readError != nil || [convError length] || !(format == NSPropertyListXMLFormat_v1_0 || format == NSPropertyListBinaryFormat_v1_0)) {
+ if(!sessionSpf || readError) {
[spfsHTML appendFormat:@"&nbsp;&nbsp;&nbsp;&nbsp;%@&nbsp;∅", [tab objectForKey:@"path"]];
- } else {
+ }
+ else {
NSString *name = @"••••";
NSString *host = @"••••";
diff --git a/Source/SPAppController.m b/Source/SPAppController.m
index afdfd16f..657af299 100644
--- a/Source/SPAppController.m
+++ b/Source/SPAppController.m
@@ -454,31 +454,37 @@
- (void)openSessionBundleAtPath:(NSString *)filePath
{
- NSError *readError = nil;
- NSString *convError = nil;
- NSPropertyListFormat format;
NSDictionary *spfs = nil;
- NSData *pData = [NSData dataWithContentsOfFile:[NSString stringWithFormat:@"%@/info.plist", filePath] options:NSUncachedRead error:&readError];
-
- spfs = [[NSPropertyListSerialization propertyListFromData:pData
- mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&convError] retain];
-
- if(!spfs || readError != nil || [convError length] || !(format == NSPropertyListXMLFormat_v1_0 || format == NSPropertyListBinaryFormat_v1_0)) {
- NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Error while reading connection data file", @"error while reading connection data file")]
- defaultButton:NSLocalizedString(@"OK", @"OK button")
- alternateButton:nil
- otherButton:nil
- informativeTextWithFormat:NSLocalizedString(@"Connection data file couldn't be read.", @"error while reading connection data file")];
+ {
+ NSError *error = nil;
- [alert setAlertStyle:NSCriticalAlertStyle];
- [alert runModal];
+ NSData *pData = [NSData dataWithContentsOfFile:[filePath stringByAppendingPathComponent:@"info.plist"]
+ options:NSUncachedRead
+ error:&error];
- if (spfs) [spfs release];
+ if(pData && !error) {
+ spfs = [[NSPropertyListSerialization propertyListWithData:pData
+ options:NSPropertyListImmutable
+ format:NULL
+ error:&error] retain];
+ }
- return;
+ if(!spfs || error) {
+ NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Error while reading connection data file", @"error while reading connection data file")
+ defaultButton:NSLocalizedString(@"OK", @"OK button")
+ alternateButton:nil
+ otherButton:nil
+ informativeTextWithFormat:NSLocalizedString(@"Connection data file couldn't be read. (%@)", @"error while reading connection data file"), [error localizedDescription]];
+
+ [alert setAlertStyle:NSCriticalAlertStyle];
+ [alert runModal];
+
+ if (spfs) [spfs release];
+
+ return;
+ }
}
-
if([spfs objectForKey:@"windows"] && [[spfs objectForKey:@"windows"] isKindOfClass:[NSArray class]]) {
NSFileManager *fileManager = [NSFileManager defaultManager];
@@ -639,79 +645,83 @@
}
NSString *newPath = [NSString stringWithFormat:@"%@/%@", bundlePath, [filePath lastPathComponent]];
-
- NSError *readError = nil;
- NSString *convError = nil;
- NSPropertyListFormat format;
+
NSDictionary *cmdData = nil;
- NSString *infoPath = [NSString stringWithFormat:@"%@/%@", filePath, SPBundleFileName];
- NSData *pData = [NSData dataWithContentsOfFile:infoPath options:NSUncachedRead error:&readError];
-
- cmdData = [[NSPropertyListSerialization propertyListFromData:pData
- mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&convError] retain];
-
- if (!cmdData || readError != nil || [convError length] || !(format == NSPropertyListXMLFormat_v1_0 || format == NSPropertyListBinaryFormat_v1_0)) {
- NSLog(@"“%@/%@” file couldn't be read.", filePath, SPBundleFileName);
- NSBeep();
- if (cmdData) [cmdData release];
- return;
- }
- else {
- // Check for installed UUIDs
- if (![cmdData objectForKey:SPBundleFileUUIDKey]) {
- NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Error while installing Bundle", @"Open Files : Bundle : UUID : Error dialog title")]
- defaultButton:NSLocalizedString(@"OK", @"Open Files : Bundle : UUID : OK button")
- alternateButton:nil
- otherButton:nil
- informativeTextWithFormat:NSLocalizedString(@"The Bundle ‘%@’ has no UUID which is necessary to identify installed Bundles.", @"Open Files : Bundle: UUID : UUID-Attribute is missing in bundle's command.plist file"), [filePath lastPathComponent]];
-
- [alert setAlertStyle:NSCriticalAlertStyle];
- [alert runModal];
+ {
+ NSError *error = nil;
+
+ NSString *infoPath = [NSString stringWithFormat:@"%@/%@", filePath, SPBundleFileName];
+ NSData *pData = [NSData dataWithContentsOfFile:infoPath options:NSUncachedRead error:&error];
+
+ if(pData && !error) {
+ cmdData = [[NSPropertyListSerialization propertyListWithData:pData
+ options:NSPropertyListImmutable
+ format:NULL
+ error:&error] retain];
+ }
+
+ if (!cmdData || error) {
+ NSLog(@"“%@/%@” file couldn't be read. (error=%@)", filePath, SPBundleFileName, error);
+ NSBeep();
if (cmdData) [cmdData release];
return;
}
+ }
+
+ // Check for installed UUIDs
+ if (![cmdData objectForKey:SPBundleFileUUIDKey]) {
+ NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Error while installing Bundle", @"Open Files : Bundle : UUID : Error dialog title")]
+ defaultButton:NSLocalizedString(@"OK", @"Open Files : Bundle : UUID : OK button")
+ alternateButton:nil
+ otherButton:nil
+ informativeTextWithFormat:NSLocalizedString(@"The Bundle ‘%@’ has no UUID which is necessary to identify installed Bundles.", @"Open Files : Bundle: UUID : UUID-Attribute is missing in bundle's command.plist file"), [filePath lastPathComponent]];
- // Reload Bundles if Sequel Pro didn't run
- if (![installedBundleUUIDs count]) {
- [self reloadBundles:self];
- }
+ [alert setAlertStyle:NSCriticalAlertStyle];
+ [alert runModal];
+ if (cmdData) [cmdData release];
+ return;
+ }
+
+ // Reload Bundles if Sequel Pro didn't run
+ if (![installedBundleUUIDs count]) {
+ [self reloadBundles:self];
+ }
+
+ if ([[installedBundleUUIDs allKeys] containsObject:[cmdData objectForKey:SPBundleFileUUIDKey]]) {
+ NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Installing Bundle", @"Open Files : Bundle : Already-Installed : 'Update Bundle' question dialog title")]
+ defaultButton:NSLocalizedString(@"Update", @"Open Files : Bundle : Already-Installed : Update button")
+ alternateButton:NSLocalizedString(@"Cancel", @"Open Files : Bundle : Already-Installed : Cancel button")
+ otherButton:nil
+ informativeTextWithFormat:NSLocalizedString(@"A Bundle ‘%@’ is already installed. Do you want to update it?", @"Open Files : Bundle : Already-Installed : 'Update Bundle' question dialog message"), [[installedBundleUUIDs objectForKey:[cmdData objectForKey:SPBundleFileUUIDKey]] objectForKey:@"name"]];
- if ([[installedBundleUUIDs allKeys] containsObject:[cmdData objectForKey:SPBundleFileUUIDKey]]) {
- NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Installing Bundle", @"Open Files : Bundle : Already-Installed : 'Update Bundle' question dialog title")]
- defaultButton:NSLocalizedString(@"Update", @"Open Files : Bundle : Already-Installed : Update button")
- alternateButton:NSLocalizedString(@"Cancel", @"Open Files : Bundle : Already-Installed : Cancel button")
- otherButton:nil
- informativeTextWithFormat:NSLocalizedString(@"A Bundle ‘%@’ is already installed. Do you want to update it?", @"Open Files : Bundle : Already-Installed : 'Update Bundle' question dialog message"), [[installedBundleUUIDs objectForKey:[cmdData objectForKey:SPBundleFileUUIDKey]] objectForKey:@"name"]];
+ [alert setAlertStyle:NSCriticalAlertStyle];
+ NSInteger answer = [alert runModal];
+
+ if (answer == NSAlertDefaultReturn) {
+ NSError *error = nil;
+ NSString *removePath = [[[installedBundleUUIDs objectForKey:[cmdData objectForKey:SPBundleFileUUIDKey]] objectForKey:@"path"] substringToIndex:([(NSString *)[[installedBundleUUIDs objectForKey:[cmdData objectForKey:SPBundleFileUUIDKey]] objectForKey:@"path"] length]-[SPBundleFileName length]-1)];
+ NSString *moveToTrashCommand = [NSString stringWithFormat:@"osascript -e 'tell application \"Finder\" to move (POSIX file \"%@\") to the trash'", removePath];
- [alert setAlertStyle:NSCriticalAlertStyle];
- NSInteger answer = [alert runModal];
+ [SPBundleCommandRunner runBashCommand:moveToTrashCommand withEnvironment:nil atCurrentDirectoryPath:nil error:&error];
- if (answer == NSAlertDefaultReturn) {
- NSError *error = nil;
- NSString *removePath = [[[installedBundleUUIDs objectForKey:[cmdData objectForKey:SPBundleFileUUIDKey]] objectForKey:@"path"] substringToIndex:([(NSString *)[[installedBundleUUIDs objectForKey:[cmdData objectForKey:SPBundleFileUUIDKey]] objectForKey:@"path"] length]-[SPBundleFileName length]-1)];
- NSString *moveToTrashCommand = [NSString stringWithFormat:@"osascript -e 'tell application \"Finder\" to move (POSIX file \"%@\") to the trash'", removePath];
-
- [SPBundleCommandRunner runBashCommand:moveToTrashCommand withEnvironment:nil atCurrentDirectoryPath:nil error:&error];
+ if (error != nil) {
+ alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Error while moving “%@” to Trash.", @"Open Files : Bundle : Already-Installed : Delete-Old-Error : Could not delete old bundle before installing new version."), removePath]
+ defaultButton:NSLocalizedString(@"OK", @"Open Files : Bundle : Already-Installed : Delete-Old-Error : OK button")
+ alternateButton:nil
+ otherButton:nil
+ informativeTextWithFormat:@"%@", [error localizedDescription]];
- if (error != nil) {
- alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Error while moving “%@” to Trash.", @"Open Files : Bundle : Already-Installed : Delete-Old-Error : Could not delete old bundle before installing new version."), removePath]
- defaultButton:NSLocalizedString(@"OK", @"Open Files : Bundle : Already-Installed : Delete-Old-Error : OK button")
- alternateButton:nil
- otherButton:nil
- informativeTextWithFormat:@"%@", [error localizedDescription]];
-
- [alert setAlertStyle:NSCriticalAlertStyle];
- [alert runModal];
- if (cmdData) [cmdData release];
- return;
- }
- }
- else {
+ [alert setAlertStyle:NSCriticalAlertStyle];
+ [alert runModal];
if (cmdData) [cmdData release];
-
return;
}
}
+ else {
+ if (cmdData) [cmdData release];
+
+ return;
+ }
}
if (cmdData) [cmdData release];
@@ -1118,157 +1128,160 @@
return;
}
- NSError *readError = nil;
- NSString *convError = nil;
- NSPropertyListFormat format;
NSDictionary *cmdData = nil;
- NSData *pData = [NSData dataWithContentsOfFile:infoPath options:NSUncachedRead error:&readError];
+ {
+ NSError *error = nil;
+
+ NSData *pData = [NSData dataWithContentsOfFile:infoPath options:NSUncachedRead error:&error];
+
+ if(pData && !error) {
+ cmdData = [[NSPropertyListSerialization propertyListWithData:pData
+ options:NSPropertyListImmutable
+ format:NULL
+ error:&error] retain];
+ }
+
+ if(!cmdData || error) {
+ NSLog(@"“%@” file couldn't be read. (error=%@)", infoPath, error);
+ NSBeep();
+ if (cmdData) [cmdData release];
+ return;
+ }
+ }
- cmdData = [[NSPropertyListSerialization propertyListFromData:pData
- mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&convError] retain];
+ if([cmdData objectForKey:SPBundleFileCommandKey] && [(NSString *)[cmdData objectForKey:SPBundleFileCommandKey] length]) {
- if(!cmdData || readError != nil || [convError length] || !(format == NSPropertyListXMLFormat_v1_0 || format == NSPropertyListBinaryFormat_v1_0)) {
- NSLog(@"“%@” file couldn't be read.", infoPath);
- NSBeep();
- if (cmdData) [cmdData release];
- return;
- } else {
- if([cmdData objectForKey:SPBundleFileCommandKey] && [(NSString *)[cmdData objectForKey:SPBundleFileCommandKey] length]) {
-
- NSString *cmd = [cmdData objectForKey:SPBundleFileCommandKey];
- NSError *err = nil;
- NSString *uuid = [NSString stringWithNewUUID];
- NSString *bundleInputFilePath = [NSString stringWithFormat:@"%@_%@", SPBundleTaskInputFilePath, uuid];
-
- [[NSFileManager defaultManager] removeItemAtPath:bundleInputFilePath error:nil];
-
- NSMutableDictionary *env = [NSMutableDictionary dictionary];
- [env setObject:[infoPath stringByDeletingLastPathComponent] forKey:SPBundleShellVariableBundlePath];
- [env setObject:bundleInputFilePath forKey:SPBundleShellVariableInputFilePath];
- [env setObject:SPBundleScopeGeneral forKey:SPBundleShellVariableBundleScope];
- [env setObject:SPURLSchemeQueryResultPathHeader forKey:SPBundleShellVariableQueryResultFile];
- [env setObject:SPURLSchemeQueryResultStatusPathHeader forKey:SPBundleShellVariableQueryResultStatusFile];
-
- NSString *input = @"";
- NSError *inputFileError = nil;
- if(input == nil) input = @"";
- [input writeToFile:bundleInputFilePath
- atomically:YES
- encoding:NSUTF8StringEncoding
- error:&inputFileError];
-
- if(inputFileError != nil) {
- NSString *errorMessage = [inputFileError localizedDescription];
- SPOnewayAlertSheet(
- NSLocalizedString(@"Bundle Error", @"bundle error"),
- [self frontDocumentWindow],
- [NSString stringWithFormat:@"%@ “%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [cmdData objectForKey:@"name"], errorMessage]
- );
- if (cmdData) [cmdData release];
- return;
- }
+ NSString *cmd = [cmdData objectForKey:SPBundleFileCommandKey];
+ NSError *err = nil;
+ NSString *uuid = [NSString stringWithNewUUID];
+ NSString *bundleInputFilePath = [NSString stringWithFormat:@"%@_%@", SPBundleTaskInputFilePath, uuid];
- NSString *output = [SPBundleCommandRunner runBashCommand:cmd
- withEnvironment:env
- atCurrentDirectoryPath:nil
- callerInstance:self
- contextInfo:[NSDictionary dictionaryWithObjectsAndKeys:
- ([cmdData objectForKey:SPBundleFileNameKey])?:@"-", @"name",
- NSLocalizedString(@"General", @"general menu item label"), @"scope",
- uuid, SPBundleFileInternalexecutionUUID, nil]
- error:&err];
-
- [[NSFileManager defaultManager] removeItemAtPath:bundleInputFilePath error:nil];
-
- NSString *action = SPBundleOutputActionNone;
- if([cmdData objectForKey:SPBundleFileOutputActionKey] && [(NSString *)[cmdData objectForKey:SPBundleFileOutputActionKey] length])
- action = [[cmdData objectForKey:SPBundleFileOutputActionKey] lowercaseString];
-
- // Redirect due exit code
- if(err != nil) {
- if([err code] == SPBundleRedirectActionNone) {
- action = SPBundleOutputActionNone;
- err = nil;
- }
- else if([err code] == SPBundleRedirectActionReplaceSection) {
- action = SPBundleOutputActionReplaceSelection;
- err = nil;
- }
- else if([err code] == SPBundleRedirectActionReplaceContent) {
- action = SPBundleOutputActionReplaceContent;
- err = nil;
- }
- else if([err code] == SPBundleRedirectActionInsertAsText) {
- action = SPBundleOutputActionInsertAsText;
- err = nil;
- }
- else if([err code] == SPBundleRedirectActionInsertAsSnippet) {
- action = SPBundleOutputActionInsertAsSnippet;
- err = nil;
- }
- else if([err code] == SPBundleRedirectActionShowAsHTML) {
- action = SPBundleOutputActionShowAsHTML;
- err = nil;
- }
- else if([err code] == SPBundleRedirectActionShowAsTextTooltip) {
- action = SPBundleOutputActionShowAsTextTooltip;
- err = nil;
- }
- else if([err code] == SPBundleRedirectActionShowAsHTMLTooltip) {
- action = SPBundleOutputActionShowAsHTMLTooltip;
- err = nil;
- }
+ [[NSFileManager defaultManager] removeItemAtPath:bundleInputFilePath error:nil];
+
+ NSMutableDictionary *env = [NSMutableDictionary dictionary];
+ [env setObject:[infoPath stringByDeletingLastPathComponent] forKey:SPBundleShellVariableBundlePath];
+ [env setObject:bundleInputFilePath forKey:SPBundleShellVariableInputFilePath];
+ [env setObject:SPBundleScopeGeneral forKey:SPBundleShellVariableBundleScope];
+ [env setObject:SPURLSchemeQueryResultPathHeader forKey:SPBundleShellVariableQueryResultFile];
+ [env setObject:SPURLSchemeQueryResultStatusPathHeader forKey:SPBundleShellVariableQueryResultStatusFile];
+
+ NSString *input = @"";
+ NSError *inputFileError = nil;
+ if(input == nil) input = @"";
+ [input writeToFile:bundleInputFilePath
+ atomically:YES
+ encoding:NSUTF8StringEncoding
+ error:&inputFileError];
+
+ if(inputFileError != nil) {
+ NSString *errorMessage = [inputFileError localizedDescription];
+ SPOnewayAlertSheet(
+ NSLocalizedString(@"Bundle Error", @"bundle error"),
+ [self frontDocumentWindow],
+ [NSString stringWithFormat:@"%@ “%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [cmdData objectForKey:@"name"], errorMessage]
+ );
+ if (cmdData) [cmdData release];
+ return;
+ }
+
+ NSString *output = [SPBundleCommandRunner runBashCommand:cmd
+ withEnvironment:env
+ atCurrentDirectoryPath:nil
+ callerInstance:self
+ contextInfo:[NSDictionary dictionaryWithObjectsAndKeys:
+ ([cmdData objectForKey:SPBundleFileNameKey])?:@"-", @"name",
+ NSLocalizedString(@"General", @"general menu item label"), @"scope",
+ uuid, SPBundleFileInternalexecutionUUID, nil]
+ error:&err];
+
+ [[NSFileManager defaultManager] removeItemAtPath:bundleInputFilePath error:nil];
+
+ NSString *action = SPBundleOutputActionNone;
+ if([cmdData objectForKey:SPBundleFileOutputActionKey] && [(NSString *)[cmdData objectForKey:SPBundleFileOutputActionKey] length])
+ action = [[cmdData objectForKey:SPBundleFileOutputActionKey] lowercaseString];
+
+ // Redirect due exit code
+ if(err != nil) {
+ if([err code] == SPBundleRedirectActionNone) {
+ action = SPBundleOutputActionNone;
+ err = nil;
+ }
+ else if([err code] == SPBundleRedirectActionReplaceSection) {
+ action = SPBundleOutputActionReplaceSelection;
+ err = nil;
+ }
+ else if([err code] == SPBundleRedirectActionReplaceContent) {
+ action = SPBundleOutputActionReplaceContent;
+ err = nil;
+ }
+ else if([err code] == SPBundleRedirectActionInsertAsText) {
+ action = SPBundleOutputActionInsertAsText;
+ err = nil;
+ }
+ else if([err code] == SPBundleRedirectActionInsertAsSnippet) {
+ action = SPBundleOutputActionInsertAsSnippet;
+ err = nil;
+ }
+ else if([err code] == SPBundleRedirectActionShowAsHTML) {
+ action = SPBundleOutputActionShowAsHTML;
+ err = nil;
+ }
+ else if([err code] == SPBundleRedirectActionShowAsTextTooltip) {
+ action = SPBundleOutputActionShowAsTextTooltip;
+ err = nil;
}
+ else if([err code] == SPBundleRedirectActionShowAsHTMLTooltip) {
+ action = SPBundleOutputActionShowAsHTMLTooltip;
+ err = nil;
+ }
+ }
- if(err == nil && output) {
- if(![action isEqualToString:SPBundleOutputActionNone]) {
- NSPoint pos = [NSEvent mouseLocation];
- pos.y -= 16;
+ if(err == nil && output) {
+ if(![action isEqualToString:SPBundleOutputActionNone]) {
+ NSPoint pos = [NSEvent mouseLocation];
+ pos.y -= 16;
- if([action isEqualToString:SPBundleOutputActionShowAsTextTooltip]) {
- [SPTooltip showWithObject:output atLocation:pos];
- }
+ if([action isEqualToString:SPBundleOutputActionShowAsTextTooltip]) {
+ [SPTooltip showWithObject:output atLocation:pos];
+ }
- else if([action isEqualToString:SPBundleOutputActionShowAsHTMLTooltip]) {
- [SPTooltip showWithObject:output atLocation:pos ofType:@"html"];
- }
+ else if([action isEqualToString:SPBundleOutputActionShowAsHTMLTooltip]) {
+ [SPTooltip showWithObject:output atLocation:pos ofType:@"html"];
+ }
- else if([action isEqualToString:SPBundleOutputActionShowAsHTML]) {
- BOOL correspondingWindowFound = NO;
- for(id win in [NSApp windows]) {
- if([[win delegate] isKindOfClass:[SPBundleHTMLOutputController class]]) {
- if([[[win delegate] windowUUID] isEqualToString:[cmdData objectForKey:SPBundleFileUUIDKey]]) {
- correspondingWindowFound = YES;
- [[win delegate] setDocUUID:uuid];
- [[win delegate] displayHTMLContent:output withOptions:nil];
- break;
- }
+ else if([action isEqualToString:SPBundleOutputActionShowAsHTML]) {
+ BOOL correspondingWindowFound = NO;
+ for(id win in [NSApp windows]) {
+ if([[win delegate] isKindOfClass:[SPBundleHTMLOutputController class]]) {
+ if([[[win delegate] windowUUID] isEqualToString:[cmdData objectForKey:SPBundleFileUUIDKey]]) {
+ correspondingWindowFound = YES;
+ [[win delegate] setDocUUID:uuid];
+ [[win delegate] displayHTMLContent:output withOptions:nil];
+ break;
}
}
- if(!correspondingWindowFound) {
- SPBundleHTMLOutputController *c = [[SPBundleHTMLOutputController alloc] init];
- [c setWindowUUID:[cmdData objectForKey:SPBundleFileUUIDKey]];
- [c setDocUUID:uuid];
- [c displayHTMLContent:output withOptions:nil];
- [SPAppDelegate addHTMLOutputController:c];
- }
+ }
+ if(!correspondingWindowFound) {
+ SPBundleHTMLOutputController *c = [[SPBundleHTMLOutputController alloc] init];
+ [c setWindowUUID:[cmdData objectForKey:SPBundleFileUUIDKey]];
+ [c setDocUUID:uuid];
+ [c displayHTMLContent:output withOptions:nil];
+ [SPAppDelegate addHTMLOutputController:c];
}
}
- } else if([err code] != 9) { // Suppress an error message if command was killed
- NSString *errorMessage = [err localizedDescription];
- SPOnewayAlertSheet(
- NSLocalizedString(@"BASH Error", @"bash error"),
- [NSApp mainWindow],
- [NSString stringWithFormat:@"%@ “%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [cmdData objectForKey:@"name"], errorMessage]
- );
}
-
+ } else if([err code] != 9) { // Suppress an error message if command was killed
+ NSString *errorMessage = [err localizedDescription];
+ SPOnewayAlertSheet(
+ NSLocalizedString(@"BASH Error", @"bash error"),
+ [NSApp mainWindow],
+ [NSString stringWithFormat:@"%@ “%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [cmdData objectForKey:@"name"], errorMessage]
+ );
}
- if (cmdData) [cmdData release];
-
}
+ if (cmdData) [cmdData release];
}
/**
@@ -1623,8 +1636,8 @@
NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Bundles Installation Error", @"bundles installation error")
defaultButton:NSLocalizedString(@"OK", @"OK button")
alternateButton:nil
- otherButton:nil
- informativeTextWithFormat:NSLocalizedString(@"Couldn't create Application Support Bundle folder!\nError: %@", @"Couldn't create Application Support Bundle folder!\nError: %@"), [appPathError localizedDescription]];
+ otherButton:nil
+ informativeTextWithFormat:NSLocalizedString(@"Couldn't create Application Support Bundle folder!\nError: %@", @"Couldn't create Application Support Bundle folder!\nError: %@"), [appPathError localizedDescription]];
[alert runModal];
return;
@@ -1654,20 +1667,25 @@
foundInstalledBundles = YES;
- NSError *readError = nil;
- NSString *convError = nil;
- NSPropertyListFormat format;
- NSDictionary *cmdData = nil;
NSString *infoPath = [NSString stringWithFormat:@"%@/%@/%@", bundlePath, bundle, SPBundleFileName];
- NSData *pData = [NSData dataWithContentsOfFile:infoPath options:NSUncachedRead error:&readError];
-
- cmdData = [NSPropertyListSerialization propertyListFromData:pData
- mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&convError];
-
- if(!cmdData || readError != nil || [convError length] || !(format == NSPropertyListXMLFormat_v1_0 || format == NSPropertyListBinaryFormat_v1_0)) {
- NSLog(@"“%@” file couldn't be read.", infoPath);
- NSBeep();
- continue;
+ NSDictionary *cmdData = nil;
+ {
+ NSError *readError = nil;
+
+ NSData *pData = [NSData dataWithContentsOfFile:infoPath options:NSUncachedRead error:&readError];
+
+ if(pData && !readError) {
+ cmdData = [NSPropertyListSerialization propertyListWithData:pData
+ options:NSPropertyListImmutable
+ format:NULL
+ error:&readError];
+ }
+
+ if(!cmdData || readError) {
+ NSLog(@"“%@” file couldn't be read. (error=%@)", infoPath, readError);
+ NSBeep();
+ continue;
+ }
}
if((![cmdData objectForKey:SPBundleFileDisabledKey] || ![[cmdData objectForKey:SPBundleFileDisabledKey] intValue])
@@ -1699,77 +1717,92 @@
if(doBundleUpdate || [installedBundleUUIDs objectForKey:[cmdData objectForKey:SPBundleFileUUIDKey]] == nil) {
if([installedBundleUUIDs objectForKey:[cmdData objectForKey:SPBundleFileUUIDKey]]) {
-
- NSString *oldPath = [NSString stringWithFormat:@"%@/%@/%@", [bundlePaths objectAtIndex:0], bundle, SPBundleFileName];
- readError = nil;
- convError = nil;
NSDictionary *cmdDataOld = nil;
+ {
+ NSError *readError = nil;
+
+ NSString *oldPath = [NSString stringWithFormat:@"%@/%@/%@", [bundlePaths objectAtIndex:0], bundle, SPBundleFileName];
+ NSData *pDataOld = [NSData dataWithContentsOfFile:oldPath options:NSUncachedRead error:&readError];
+
+ if(pDataOld && !readError) {
+ cmdDataOld = [NSPropertyListSerialization propertyListWithData:pDataOld
+ options:NSPropertyListImmutable
+ format:NULL
+ error:&readError];
+ }
+
+ if(!cmdDataOld || readError) {
+ NSLog(@"“%@” file couldn't be read. (error=%@)", oldPath, readError);
+ NSBeep();
+ continue;
+ }
+ }
- NSData *pDataOld = [NSData dataWithContentsOfFile:oldPath options:NSUncachedRead error:&readError];
- cmdDataOld = [NSPropertyListSerialization propertyListFromData:pDataOld
- mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&convError];
- if(!cmdDataOld || readError != nil || [convError length] || !(format == NSPropertyListXMLFormat_v1_0 || format == NSPropertyListBinaryFormat_v1_0)) {
- NSLog(@"“%@” file couldn't be read.", oldPath);
- NSBeep();
- continue;
- } else {
- NSString *oldBundle = [NSString stringWithFormat:@"%@/%@", [bundlePaths objectAtIndex:0], bundle];
- // Check for modifications
- if([cmdDataOld objectForKey:SPBundleFileDefaultBundleWasModifiedKey]) {
-
- // Duplicate Bundle, change the UUID and rename the menu label
- NSString *duplicatedBundle = [NSString stringWithFormat:@"%@/%@_%ld.%@", [bundlePaths objectAtIndex:0], [bundle substringToIndex:([bundle length] - [SPUserBundleFileExtension length] - 1)], (long)(random() % 35000), SPUserBundleFileExtension];
- if(![[NSFileManager defaultManager] copyItemAtPath:oldBundle toPath:duplicatedBundle error:nil]) {
- NSLog(@"Couldn't copy “%@” to update it", bundle);
- NSBeep();
- continue;
- }
- NSError *readError1 = nil;
- NSString *convError1 = nil;
- NSMutableDictionary *dupData = [NSMutableDictionary dictionary];
- NSString *duplicatedBundleCommand = [NSString stringWithFormat:@"%@/%@", duplicatedBundle, SPBundleFileName];
- NSData *dData = [NSData dataWithContentsOfFile:duplicatedBundleCommand options:NSUncachedRead error:&readError1];
- [dupData setDictionary:[NSPropertyListSerialization propertyListFromData:dData
- mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&convError1]];
-
- if ((!dupData && ![dupData count]) || (readError1 != nil || [convError1 length] || !(format == NSPropertyListXMLFormat_v1_0 || format == NSPropertyListBinaryFormat_v1_0))) {
- NSLog(@"“%@” file couldn't be read.", duplicatedBundleCommand);
- NSBeep();
- continue;
- }
+ NSString *oldBundle = [NSString stringWithFormat:@"%@/%@", [bundlePaths objectAtIndex:0], bundle];
+ // Check for modifications
+ if([cmdDataOld objectForKey:SPBundleFileDefaultBundleWasModifiedKey]) {
+
+ // Duplicate Bundle, change the UUID and rename the menu label
+ NSString *duplicatedBundle = [NSString stringWithFormat:@"%@/%@_%ld.%@", [bundlePaths objectAtIndex:0], [bundle substringToIndex:([bundle length] - [SPUserBundleFileExtension length] - 1)], (long)(random() % 35000), SPUserBundleFileExtension];
+ if(![[NSFileManager defaultManager] copyItemAtPath:oldBundle toPath:duplicatedBundle error:nil]) {
+ NSLog(@"Couldn't copy “%@” to update it", bundle);
+ NSBeep();
+ continue;
+ }
+ NSString *duplicatedBundleCommand = [NSString stringWithFormat:@"%@/%@", duplicatedBundle, SPBundleFileName];
+ NSMutableDictionary *dupData = [NSMutableDictionary dictionary];
+ {
+ NSError *readError = nil;
- [dupData setObject:[NSString stringWithNewUUID] forKey:SPBundleFileUUIDKey];
- NSString *orgName = [dupData objectForKey:SPBundleFileNameKey];
- [dupData setObject:[NSString stringWithFormat:@"%@ (user)", orgName] forKey:SPBundleFileNameKey];
- [dupData removeObjectForKey:SPBundleFileIsDefaultBundleKey];
- [dupData writeToFile:duplicatedBundleCommand atomically:YES];
-
- error = nil;
- NSString *moveToTrashCommand = [NSString stringWithFormat:@"osascript -e 'tell application \"Finder\" to move (POSIX file \"%@\") to the trash'", oldBundle];
+ NSData *dData = [NSData dataWithContentsOfFile:duplicatedBundleCommand options:NSUncachedRead error:&readError];
- [SPBundleCommandRunner runBashCommand:moveToTrashCommand withEnvironment:nil atCurrentDirectoryPath:nil error:&error];
-
- if(error != nil) {
- NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Error while moving “%@” to Trash.", @"error while moving “%@” to trash"), [[installedBundleUUIDs objectForKey:[cmdDataOld objectForKey:SPBundleFileUUIDKey]] objectForKey:@"path"]]
- defaultButton:NSLocalizedString(@"OK", @"OK button")
- alternateButton:nil
- otherButton:nil
- informativeTextWithFormat:@"%@", [error localizedDescription]];
-
- [alert setAlertStyle:NSCriticalAlertStyle];
- [alert runModal];
- continue;
+ if(dData && !readError) {
+ NSDictionary *dDict = [NSPropertyListSerialization propertyListWithData:dData
+ options:NSPropertyListImmutable
+ format:NULL
+ error:&readError];
+
+ if(dDict && !readError) {
+ [dupData setDictionary:dDict];
+ }
}
- [infoAboutUpdatedDefaultBundles appendFormat:@"• %@\n", orgName];
- } else {
- // If no modifications are done simply remove the old one
- if(![fm removeItemAtPath:oldBundle error:nil]) {
- NSLog(@"Couldn't remove “%@” to update it", bundle);
+ if (![dupData count] || readError) {
+ NSLog(@"“%@” file couldn't be read. (error=%@)", duplicatedBundleCommand, readError);
NSBeep();
continue;
}
+ }
+ [dupData setObject:[NSString stringWithNewUUID] forKey:SPBundleFileUUIDKey];
+ NSString *orgName = [dupData objectForKey:SPBundleFileNameKey];
+ [dupData setObject:[NSString stringWithFormat:@"%@ (user)", orgName] forKey:SPBundleFileNameKey];
+ [dupData removeObjectForKey:SPBundleFileIsDefaultBundleKey];
+ [dupData writeToFile:duplicatedBundleCommand atomically:YES];
+
+ error = nil;
+ NSString *moveToTrashCommand = [NSString stringWithFormat:@"osascript -e 'tell application \"Finder\" to move (POSIX file \"%@\") to the trash'", oldBundle];
+
+ [SPBundleCommandRunner runBashCommand:moveToTrashCommand withEnvironment:nil atCurrentDirectoryPath:nil error:&error];
+
+ if(error != nil) {
+ NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Error while moving “%@” to Trash.", @"error while moving “%@” to trash"), [[installedBundleUUIDs objectForKey:[cmdDataOld objectForKey:SPBundleFileUUIDKey]] objectForKey:@"path"]]
+ defaultButton:NSLocalizedString(@"OK", @"OK button")
+ alternateButton:nil
+ otherButton:nil
+ informativeTextWithFormat:@"%@", [error localizedDescription]];
+
+ [alert setAlertStyle:NSCriticalAlertStyle];
+ [alert runModal];
+ continue;
+ }
+ [infoAboutUpdatedDefaultBundles appendFormat:@"• %@\n", orgName];
+ } else {
+ // If no modifications are done simply remove the old one
+ if(![fm removeItemAtPath:oldBundle error:nil]) {
+ NSLog(@"Couldn't remove “%@” to update it", bundle);
+ NSBeep();
+ continue;
}
}
diff --git a/Source/SPBundleEditorController.m b/Source/SPBundleEditorController.m
index ddac2b9e..9d4f43ce 100644
--- a/Source/SPBundleEditorController.m
+++ b/Source/SPBundleEditorController.m
@@ -939,25 +939,31 @@
if(!isNewBundle) {
- NSError *readError = nil;
- NSString *convError = nil;
- NSPropertyListFormat format;
NSDictionary *cmdData = nil;
- NSData *pData = [NSData dataWithContentsOfFile:cmdFilePath options:NSUncachedRead error:&readError];
- cmdData = [[NSPropertyListSerialization propertyListFromData:pData
- mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&convError] retain];
- if(!cmdData || readError != nil || [convError length] || !(format == NSPropertyListXMLFormat_v1_0 || format == NSPropertyListBinaryFormat_v1_0)) {
- NSLog(@"“%@” file couldn't be read.", cmdFilePath);
- NSBeep();
- if (cmdData) [cmdData release];
- return NO;
- } else {
- // Check for changes and return if no changes are found
- if([[saveDict description] isEqualToString:[cmdData description]])
- return YES;
- if([cmdData objectForKey:SPBundleFileIsDefaultBundleKey])
- [saveDict setObject:@YES forKey:SPBundleFileDefaultBundleWasModifiedKey];
+ {
+ NSError *error = nil;
+
+ NSData *pData = [NSData dataWithContentsOfFile:cmdFilePath options:NSUncachedRead error:&error];
+
+ cmdData = [[NSPropertyListSerialization propertyListWithData:pData
+ options:NSPropertyListImmutable
+ format:NULL
+ error:&error] retain];
+
+ if(!cmdData || error) {
+ NSLog(@"“%@” file couldn't be read. (error=%@)", cmdFilePath, error);
+ NSBeep();
+ if (cmdData) [cmdData release];
+ return NO;
+ }
}
+
+ // Check for changes and return if no changes are found
+ if([[saveDict description] isEqualToString:[cmdData description]])
+ return YES;
+ if([cmdData objectForKey:SPBundleFileIsDefaultBundleKey])
+ [saveDict setObject:@YES forKey:SPBundleFileDefaultBundleWasModifiedKey];
+
if (cmdData) [cmdData release];
}
@@ -966,7 +972,6 @@
[saveDict writeToFile:cmdFilePath atomically:YES];
return YES;
-
}
/**
@@ -1642,21 +1647,25 @@
for(NSString* bundle in foundBundles) {
if(![[[bundle pathExtension] lowercaseString] isEqualToString:[SPUserBundleFileExtension lowercaseString]]) continue;
- NSError *readError = nil;
- NSString *convError = nil;
- NSPropertyListFormat format;
NSDictionary *cmdData = nil;
+ NSError *readError = nil;
+
NSString *infoPath = [NSString stringWithFormat:@"%@/%@/%@", bundlePath, bundle, SPBundleFileName];
NSData *pData = [NSData dataWithContentsOfFile:infoPath options:NSUncachedRead error:&readError];
-
- cmdData = [[NSPropertyListSerialization propertyListFromData:pData
- mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&convError] retain];
-
- if(!cmdData || readError != nil || [convError length] || !(format == NSPropertyListXMLFormat_v1_0 || format == NSPropertyListBinaryFormat_v1_0)) {
- NSLog(@"“%@/%@” file couldn't be read.", bundle, SPBundleFileName);
+
+ if(pData && !error) {
+ cmdData = [[NSPropertyListSerialization propertyListWithData:pData
+ options:NSPropertyListImmutable
+ format:NULL
+ error:&readError] retain];
+ }
+
+ if(!cmdData || readError) {
+ NSLog(@"“%@/%@” file couldn't be read. (error=%@)", bundle, SPBundleFileName, readError);
NSBeep();
if (cmdData) [cmdData release];
- } else {
+ }
+ else {
if([cmdData objectForKey:SPBundleFileNameKey] && [[cmdData objectForKey:SPBundleFileNameKey] length] && [cmdData objectForKey:SPBundleFileScopeKey])
{
NSMutableDictionary *bundleCommand = [NSMutableDictionary dictionary];
diff --git a/Source/SPContentFilterManager.m b/Source/SPContentFilterManager.m
index 5dc0c48b..0898d430 100644
--- a/Source/SPContentFilterManager.m
+++ b/Source/SPContentFilterManager.m
@@ -831,30 +831,36 @@ static NSString *SPExportFilterAction = @"SPExportFilter";
if (returnCode == NSOKButton) {
NSString *filename = [[[panel URLs] objectAtIndex:0] path];
- NSError *readError = nil;
- NSString *convError = nil;
- NSPropertyListFormat format;
+
NSInteger insertionIndexStart, insertionIndexEnd;
NSDictionary *spf = nil;
if([[[filename pathExtension] lowercaseString] isEqualToString:SPFileExtensionDefault]) {
- NSData *pData = [NSData dataWithContentsOfFile:filename options:NSUncachedRead error:&readError];
-
- spf = [[NSPropertyListSerialization propertyListFromData:pData
- mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&convError] retain];
-
- if(!spf || readError != nil || [convError length] || !(format == NSPropertyListXMLFormat_v1_0 || format == NSPropertyListBinaryFormat_v1_0)) {
- NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithString:SP_FILE_PARSER_ERROR_TITLE_STRING]
- defaultButton:NSLocalizedString(@"OK", @"OK button")
- alternateButton:nil
- otherButton:nil
- informativeTextWithFormat:NSLocalizedString(@"File couldn't be read.", @"error while reading data file")];
-
- [alert setAlertStyle:NSCriticalAlertStyle];
- [alert runModal];
- if (spf) [spf release];
- return;
+ {
+ NSError *error = nil;
+
+ NSData *pData = [NSData dataWithContentsOfFile:filename options:NSUncachedRead error:&error];
+
+ if(pData && !error) {
+ spf = [[NSPropertyListSerialization propertyListWithData:pData
+ options:NSPropertyListImmutable
+ format:NULL
+ error:&error] retain];
+ }
+
+ if(!spf || error) {
+ NSAlert *alert = [NSAlert alertWithMessageText:SP_FILE_PARSER_ERROR_TITLE_STRING
+ defaultButton:NSLocalizedString(@"OK", @"OK button")
+ alternateButton:nil
+ otherButton:nil
+ informativeTextWithFormat:NSLocalizedString(@"File couldn't be read. (%@)", @"error while reading data file"), [error localizedDescription]];
+
+ [alert setAlertStyle:NSCriticalAlertStyle];
+ [alert runModal];
+ if (spf) [spf release];
+ return;
+ }
}
if([[spf objectForKey:SPContentFilters] objectForKey:filterType] && [[[spf objectForKey:SPContentFilters] objectForKey:filterType] count]) {
diff --git a/Source/SPCopyTable.m b/Source/SPCopyTable.m
index aa77ffbc..5b5c0ae9 100644
--- a/Source/SPCopyTable.m
+++ b/Source/SPCopyTable.m
@@ -1257,275 +1257,280 @@ static const NSInteger kBlobAsImageFile = 4;
return;
}
- NSError *readError = nil;
- NSString *convError = nil;
- NSPropertyListFormat format;
NSDictionary *cmdData = nil;
- NSData *pData = [NSData dataWithContentsOfFile:infoPath options:NSUncachedRead error:&readError];
+ {
+ NSError *error = nil;
+
+ NSData *pData = [NSData dataWithContentsOfFile:infoPath options:NSUncachedRead error:&error];
- cmdData = [[NSPropertyListSerialization propertyListFromData:pData
- mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&convError] retain];
+ if(pData && !error) {
+ cmdData = [[NSPropertyListSerialization propertyListWithData:pData
+ options:NSPropertyListImmutable
+ format:NULL
+ error:&error] retain];
+ }
+
+ if(!cmdData || error) {
+ NSLog(@"“%@” file couldn't be read. (error=%@)", infoPath, error);
+ NSBeep();
+ if (cmdData) [cmdData release];
+ return;
+ }
+ }
- if(!cmdData || readError != nil || [convError length] || !(format == NSPropertyListXMLFormat_v1_0 || format == NSPropertyListBinaryFormat_v1_0)) {
- NSLog(@"“%@” file couldn't be read.", infoPath);
- NSBeep();
- if (cmdData) [cmdData release];
- return;
- } else {
- if([cmdData objectForKey:SPBundleFileCommandKey] && [(NSString *)[cmdData objectForKey:SPBundleFileCommandKey] length]) {
+ if([cmdData objectForKey:SPBundleFileCommandKey] && [(NSString *)[cmdData objectForKey:SPBundleFileCommandKey] length]) {
- NSString *cmd = [cmdData objectForKey:SPBundleFileCommandKey];
- NSString *inputAction = @"";
- NSString *inputFallBackAction = @"";
- NSError *err = nil;
- NSString *uuid = [NSString stringWithNewUUID];
- NSString *bundleInputFilePath = [NSString stringWithFormat:@"%@_%@", SPBundleTaskInputFilePath, uuid];
- NSString *bundleInputTableMetaDataFilePath = [NSString stringWithFormat:@"%@_%@", SPBundleTaskTableMetaDataFilePath, uuid];
+ NSString *cmd = [cmdData objectForKey:SPBundleFileCommandKey];
+ NSString *inputAction = @"";
+ NSString *inputFallBackAction = @"";
+ NSError *err = nil;
+ NSString *uuid = [NSString stringWithNewUUID];
+ NSString *bundleInputFilePath = [NSString stringWithFormat:@"%@_%@", SPBundleTaskInputFilePath, uuid];
+ NSString *bundleInputTableMetaDataFilePath = [NSString stringWithFormat:@"%@_%@", SPBundleTaskTableMetaDataFilePath, uuid];
- [[NSFileManager defaultManager] removeItemAtPath:bundleInputFilePath error:nil];
+ [[NSFileManager defaultManager] removeItemAtPath:bundleInputFilePath error:nil];
- if([cmdData objectForKey:SPBundleFileInputSourceKey])
- inputAction = [[cmdData objectForKey:SPBundleFileInputSourceKey] lowercaseString];
- if([cmdData objectForKey:SPBundleFileInputSourceFallBackKey])
- inputFallBackAction = [[cmdData objectForKey:SPBundleFileInputSourceFallBackKey] lowercaseString];
+ if([cmdData objectForKey:SPBundleFileInputSourceKey])
+ inputAction = [[cmdData objectForKey:SPBundleFileInputSourceKey] lowercaseString];
+ if([cmdData objectForKey:SPBundleFileInputSourceFallBackKey])
+ inputFallBackAction = [[cmdData objectForKey:SPBundleFileInputSourceFallBackKey] lowercaseString];
- NSMutableDictionary *env = [NSMutableDictionary dictionary];
- [env setObject:[infoPath stringByDeletingLastPathComponent] forKey:SPBundleShellVariableBundlePath];
- [env setObject:bundleInputFilePath forKey:SPBundleShellVariableInputFilePath];
+ NSMutableDictionary *env = [NSMutableDictionary dictionary];
+ [env setObject:[infoPath stringByDeletingLastPathComponent] forKey:SPBundleShellVariableBundlePath];
+ [env setObject:bundleInputFilePath forKey:SPBundleShellVariableInputFilePath];
- if ([[self delegate] respondsToSelector:@selector(usedQuery)] && [(id <SPDatabaseContentViewDelegate>)[self delegate] usedQuery]) {
- [env setObject:[(id <SPDatabaseContentViewDelegate>)[self delegate] usedQuery] forKey:SPBundleShellVariableUsedQueryForTable];
- }
+ if ([[self delegate] respondsToSelector:@selector(usedQuery)] && [(id <SPDatabaseContentViewDelegate>)[self delegate] usedQuery]) {
+ [env setObject:[(id <SPDatabaseContentViewDelegate>)[self delegate] usedQuery] forKey:SPBundleShellVariableUsedQueryForTable];
+ }
- [env setObject:bundleInputTableMetaDataFilePath forKey:SPBundleShellVariableInputTableMetaData];
- [env setObject:SPBundleScopeDataTable forKey:SPBundleShellVariableBundleScope];
+ [env setObject:bundleInputTableMetaDataFilePath forKey:SPBundleShellVariableInputTableMetaData];
+ [env setObject:SPBundleScopeDataTable forKey:SPBundleShellVariableBundleScope];
- if([self numberOfSelectedRows]) {
- NSMutableArray *sel = [NSMutableArray array];
- NSIndexSet *selectedRows = [self selectedRowIndexes];
- [selectedRows enumerateIndexesUsingBlock:^(NSUInteger rowIndex, BOOL * _Nonnull stop) {
- [sel addObject:[NSString stringWithFormat:@"%llu", (unsigned long long)rowIndex]];
- }];
- [env setObject:[sel componentsJoinedByString:@"\t"] forKey:SPBundleShellVariableSelectedRowIndices];
- }
+ if([self numberOfSelectedRows]) {
+ NSMutableArray *sel = [NSMutableArray array];
+ NSIndexSet *selectedRows = [self selectedRowIndexes];
+ [selectedRows enumerateIndexesUsingBlock:^(NSUInteger rowIndex, BOOL * _Nonnull stop) {
+ [sel addObject:[NSString stringWithFormat:@"%llu", (unsigned long long)rowIndex]];
+ }];
+ [env setObject:[sel componentsJoinedByString:@"\t"] forKey:SPBundleShellVariableSelectedRowIndices];
+ }
- NSError *inputFileError = nil;
- NSString *input = @"";
- NSInteger blobHandling = kBlobExclude;
- if([cmdData objectForKey:SPBundleFileWithBlobKey]) {
- if([[cmdData objectForKey:SPBundleFileWithBlobKey] isEqualToString:SPBundleInputSourceBlobHandlingExclude])
- blobHandling = kBlobExclude;
- else if([[cmdData objectForKey:SPBundleFileWithBlobKey] isEqualToString:SPBundleInputSourceBlobHandlingInclude])
- blobHandling = kBlobInclude;
- else if([[cmdData objectForKey:SPBundleFileWithBlobKey] isEqualToString:SPBundleInputSourceBlobHandlingImageFileReference])
- blobHandling = kBlobAsImageFile;
- else if([[cmdData objectForKey:SPBundleFileWithBlobKey] isEqualToString:SPBundleInputSourceBlobHandlingFileReference])
- blobHandling = kBlobAsFile;
- }
+ NSError *inputFileError = nil;
+ NSString *input = @"";
+ NSInteger blobHandling = kBlobExclude;
+ if([cmdData objectForKey:SPBundleFileWithBlobKey]) {
+ if([[cmdData objectForKey:SPBundleFileWithBlobKey] isEqualToString:SPBundleInputSourceBlobHandlingExclude])
+ blobHandling = kBlobExclude;
+ else if([[cmdData objectForKey:SPBundleFileWithBlobKey] isEqualToString:SPBundleInputSourceBlobHandlingInclude])
+ blobHandling = kBlobInclude;
+ else if([[cmdData objectForKey:SPBundleFileWithBlobKey] isEqualToString:SPBundleInputSourceBlobHandlingImageFileReference])
+ blobHandling = kBlobAsImageFile;
+ else if([[cmdData objectForKey:SPBundleFileWithBlobKey] isEqualToString:SPBundleInputSourceBlobHandlingFileReference])
+ blobHandling = kBlobAsFile;
+ }
- if(blobHandling != kBlobExclude) {
- NSString *bundleBlobFilePath = [NSString stringWithFormat:@"%@_%@", SPBundleTaskCopyBlobFileDirectory, uuid];
- [env setObject:bundleBlobFilePath forKey:SPBundleShellVariableBlobFileDirectory];
- [self setTmpBlobFileDirectory:bundleBlobFilePath];
- } else {
- [self setTmpBlobFileDirectory:@""];
- }
+ if(blobHandling != kBlobExclude) {
+ NSString *bundleBlobFilePath = [NSString stringWithFormat:@"%@_%@", SPBundleTaskCopyBlobFileDirectory, uuid];
+ [env setObject:bundleBlobFilePath forKey:SPBundleShellVariableBlobFileDirectory];
+ [self setTmpBlobFileDirectory:bundleBlobFilePath];
+ } else {
+ [self setTmpBlobFileDirectory:@""];
+ }
- if([inputAction isEqualToString:SPBundleInputSourceSelectedTableRowsAsTab]) {
- input = [self rowsAsTabStringWithHeaders:YES onlySelectedRows:YES blobHandling:blobHandling];
- }
- else if([inputAction isEqualToString:SPBundleInputSourceSelectedTableRowsAsCsv]) {
- input = [self rowsAsCsvStringWithHeaders:YES onlySelectedRows:YES blobHandling:blobHandling];
- }
- else if([inputAction isEqualToString:SPBundleInputSourceSelectedTableRowsAsSqlInsert]) {
- input = [self rowsAsSqlInsertsOnlySelectedRows:YES];
- }
- else if([inputAction isEqualToString:SPBundleInputSourceTableRowsAsTab]) {
- input = [self rowsAsTabStringWithHeaders:YES onlySelectedRows:NO blobHandling:blobHandling];
- }
- else if([inputAction isEqualToString:SPBundleInputSourceTableRowsAsCsv]) {
- input = [self rowsAsCsvStringWithHeaders:YES onlySelectedRows:NO blobHandling:blobHandling];
- }
- else if([inputAction isEqualToString:SPBundleInputSourceTableRowsAsSqlInsert]) {
- input = [self rowsAsSqlInsertsOnlySelectedRows:NO];
- }
-
- if(input == nil) input = @"";
- [input writeToFile:bundleInputFilePath
- atomically:YES
- encoding:NSUTF8StringEncoding
- error:&inputFileError];
-
- if(inputFileError != nil) {
- NSString *errorMessage = [inputFileError localizedDescription];
- SPOnewayAlertSheet(
- NSLocalizedString(@"Bundle Error", @"bundle error"),
- [self window],
- [NSString stringWithFormat:@"%@ “%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [cmdData objectForKey:@"name"], errorMessage]
- );
- if (cmdData) [cmdData release];
- return;
- }
+ if([inputAction isEqualToString:SPBundleInputSourceSelectedTableRowsAsTab]) {
+ input = [self rowsAsTabStringWithHeaders:YES onlySelectedRows:YES blobHandling:blobHandling];
+ }
+ else if([inputAction isEqualToString:SPBundleInputSourceSelectedTableRowsAsCsv]) {
+ input = [self rowsAsCsvStringWithHeaders:YES onlySelectedRows:YES blobHandling:blobHandling];
+ }
+ else if([inputAction isEqualToString:SPBundleInputSourceSelectedTableRowsAsSqlInsert]) {
+ input = [self rowsAsSqlInsertsOnlySelectedRows:YES];
+ }
+ else if([inputAction isEqualToString:SPBundleInputSourceTableRowsAsTab]) {
+ input = [self rowsAsTabStringWithHeaders:YES onlySelectedRows:NO blobHandling:blobHandling];
+ }
+ else if([inputAction isEqualToString:SPBundleInputSourceTableRowsAsCsv]) {
+ input = [self rowsAsCsvStringWithHeaders:YES onlySelectedRows:NO blobHandling:blobHandling];
+ }
+ else if([inputAction isEqualToString:SPBundleInputSourceTableRowsAsSqlInsert]) {
+ input = [self rowsAsSqlInsertsOnlySelectedRows:NO];
+ }
+
+ if(input == nil) input = @"";
+ [input writeToFile:bundleInputFilePath
+ atomically:YES
+ encoding:NSUTF8StringEncoding
+ error:&inputFileError];
+
+ if(inputFileError != nil) {
+ NSString *errorMessage = [inputFileError localizedDescription];
+ SPOnewayAlertSheet(
+ NSLocalizedString(@"Bundle Error", @"bundle error"),
+ [self window],
+ [NSString stringWithFormat:@"%@ “%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [cmdData objectForKey:@"name"], errorMessage]
+ );
+ if (cmdData) [cmdData release];
+ return;
+ }
- // Create an array of table column mappings for fast iteration
- NSArray *columns = [self tableColumns];
- NSUInteger numColumns = [columns count];
- NSUInteger *columnMappings = calloc(numColumns, sizeof(NSUInteger));
- NSUInteger c;
- for ( c = 0; c < numColumns; c++ )
- columnMappings[c] = (NSUInteger)[[NSArrayObjectAtIndex(columns, c) identifier] integerValue];
-
- NSMutableString *tableMetaData = [NSMutableString string];
- if([[self delegate] isKindOfClass:[SPCustomQuery class]]) {
- [env setObject:@"query" forKey:SPBundleShellVariableDataTableSource];
-
- NSArray *defs = [(id <SPDatabaseContentViewDelegate>)[self delegate] dataColumnDefinitions];
-
- if(defs && [defs count] == numColumns)
- for( c = 0; c < numColumns; c++ ) {
- NSDictionary *col = NSArrayObjectAtIndex(defs, columnMappings[c]);
- [tableMetaData appendFormat:@"%@\t", [col objectForKey:@"type"]];
- [tableMetaData appendFormat:@"%@\t", [col objectForKey:@"typegrouping"]];
- [tableMetaData appendFormat:@"%@\t", ([col objectForKey:@"char_length"]) ? : @""];
- [tableMetaData appendFormat:@"%@\t", [col objectForKey:@"UNSIGNED_FLAG"]];
- [tableMetaData appendFormat:@"%@\t", [col objectForKey:@"AUTO_INCREMENT_FLAG"]];
- [tableMetaData appendFormat:@"%@\t", [col objectForKey:@"PRI_KEY_FLAG"]];
- [tableMetaData appendString:@"\n"];
- }
- }
- else if([[self delegate] isKindOfClass:[SPTableContent class]]) {
- [env setObject:@"content" forKey:SPBundleShellVariableDataTableSource];
-
- NSArray *defs = [(id <SPDatabaseContentViewDelegate>)[self delegate] dataColumnDefinitions];
-
- if(defs && [defs count] == numColumns)
- for( c = 0; c < numColumns; c++ ) {
- NSDictionary *col = NSArrayObjectAtIndex(defs, columnMappings[c]);
- [tableMetaData appendFormat:@"%@\t", [col objectForKey:@"type"]];
- [tableMetaData appendFormat:@"%@\t", [col objectForKey:@"typegrouping"]];
- [tableMetaData appendFormat:@"%@\t", ([col objectForKey:@"length"]) ? : @""];
- [tableMetaData appendFormat:@"%@\t", [col objectForKey:@"unsigned"]];
- [tableMetaData appendFormat:@"%@\t", [col objectForKey:@"autoincrement"]];
- [tableMetaData appendFormat:@"%@\t", ([col objectForKey:@"isprimarykey"]) ? : @"0"];
- [tableMetaData appendFormat:@"%@\n", [col objectForKey:@"comment"]];
- }
- }
- free(columnMappings);
+ // Create an array of table column mappings for fast iteration
+ NSArray *columns = [self tableColumns];
+ NSUInteger numColumns = [columns count];
+ NSUInteger *columnMappings = calloc(numColumns, sizeof(NSUInteger));
+ NSUInteger c;
+ for ( c = 0; c < numColumns; c++ )
+ columnMappings[c] = (NSUInteger)[[NSArrayObjectAtIndex(columns, c) identifier] integerValue];
- inputFileError = nil;
- [tableMetaData writeToFile:bundleInputTableMetaDataFilePath
- atomically:YES
- encoding:NSUTF8StringEncoding
- error:&inputFileError];
+ NSMutableString *tableMetaData = [NSMutableString string];
+ if([[self delegate] isKindOfClass:[SPCustomQuery class]]) {
+ [env setObject:@"query" forKey:SPBundleShellVariableDataTableSource];
- if(inputFileError != nil) {
- NSString *errorMessage = [inputFileError localizedDescription];
- SPOnewayAlertSheet(
- NSLocalizedString(@"Bundle Error", @"bundle error"),
- [self window],
- [NSString stringWithFormat:@"%@ “%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [cmdData objectForKey:@"name"], errorMessage]
- );
- if (cmdData) [cmdData release];
- return;
- }
+ NSArray *defs = [(id <SPDatabaseContentViewDelegate>)[self delegate] dataColumnDefinitions];
+
+ if(defs && [defs count] == numColumns)
+ for( c = 0; c < numColumns; c++ ) {
+ NSDictionary *col = NSArrayObjectAtIndex(defs, columnMappings[c]);
+ [tableMetaData appendFormat:@"%@\t", [col objectForKey:@"type"]];
+ [tableMetaData appendFormat:@"%@\t", [col objectForKey:@"typegrouping"]];
+ [tableMetaData appendFormat:@"%@\t", ([col objectForKey:@"char_length"]) ? : @""];
+ [tableMetaData appendFormat:@"%@\t", [col objectForKey:@"UNSIGNED_FLAG"]];
+ [tableMetaData appendFormat:@"%@\t", [col objectForKey:@"AUTO_INCREMENT_FLAG"]];
+ [tableMetaData appendFormat:@"%@\t", [col objectForKey:@"PRI_KEY_FLAG"]];
+ [tableMetaData appendString:@"\n"];
+ }
+ }
+ else if([[self delegate] isKindOfClass:[SPTableContent class]]) {
+ [env setObject:@"content" forKey:SPBundleShellVariableDataTableSource];
+
+ NSArray *defs = [(id <SPDatabaseContentViewDelegate>)[self delegate] dataColumnDefinitions];
+
+ if(defs && [defs count] == numColumns)
+ for( c = 0; c < numColumns; c++ ) {
+ NSDictionary *col = NSArrayObjectAtIndex(defs, columnMappings[c]);
+ [tableMetaData appendFormat:@"%@\t", [col objectForKey:@"type"]];
+ [tableMetaData appendFormat:@"%@\t", [col objectForKey:@"typegrouping"]];
+ [tableMetaData appendFormat:@"%@\t", ([col objectForKey:@"length"]) ? : @""];
+ [tableMetaData appendFormat:@"%@\t", [col objectForKey:@"unsigned"]];
+ [tableMetaData appendFormat:@"%@\t", [col objectForKey:@"autoincrement"]];
+ [tableMetaData appendFormat:@"%@\t", ([col objectForKey:@"isprimarykey"]) ? : @"0"];
+ [tableMetaData appendFormat:@"%@\n", [col objectForKey:@"comment"]];
+ }
+ }
+ free(columnMappings);
+ inputFileError = nil;
+ [tableMetaData writeToFile:bundleInputTableMetaDataFilePath
+ atomically:YES
+ encoding:NSUTF8StringEncoding
+ error:&inputFileError];
+
+ if(inputFileError != nil) {
+ NSString *errorMessage = [inputFileError localizedDescription];
+ SPOnewayAlertSheet(
+ NSLocalizedString(@"Bundle Error", @"bundle error"),
+ [self window],
+ [NSString stringWithFormat:@"%@ “%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [cmdData objectForKey:@"name"], errorMessage]
+ );
+ if (cmdData) [cmdData release];
+ return;
+ }
- NSString *output = [SPBundleCommandRunner runBashCommand:cmd withEnvironment:env
- atCurrentDirectoryPath:nil
- callerInstance:[SPAppDelegate frontDocument]
- contextInfo:[NSDictionary dictionaryWithObjectsAndKeys:
- ([cmdData objectForKey:SPBundleFileNameKey])?:@"-", @"name",
- NSLocalizedString(@"Data Table", @"data table menu item label"), @"scope",
- uuid, SPBundleFileInternalexecutionUUID, nil]
- error:&err];
- [[NSFileManager defaultManager] removeItemAtPath:bundleInputFilePath error:nil];
+ NSString *output = [SPBundleCommandRunner runBashCommand:cmd withEnvironment:env
+ atCurrentDirectoryPath:nil
+ callerInstance:[SPAppDelegate frontDocument]
+ contextInfo:[NSDictionary dictionaryWithObjectsAndKeys:
+ ([cmdData objectForKey:SPBundleFileNameKey])?:@"-", @"name",
+ NSLocalizedString(@"Data Table", @"data table menu item label"), @"scope",
+ uuid, SPBundleFileInternalexecutionUUID, nil]
+ error:&err];
- NSString *action = SPBundleOutputActionNone;
- if([cmdData objectForKey:SPBundleFileOutputActionKey] && [(NSString *)[cmdData objectForKey:SPBundleFileOutputActionKey] length])
- action = [[cmdData objectForKey:SPBundleFileOutputActionKey] lowercaseString];
+ [[NSFileManager defaultManager] removeItemAtPath:bundleInputFilePath error:nil];
- // Redirect due exit code
- if(err != nil) {
- if([err code] == SPBundleRedirectActionNone) {
- action = SPBundleOutputActionNone;
- err = nil;
- }
- else if([err code] == SPBundleRedirectActionReplaceSection) {
- action = SPBundleOutputActionReplaceSelection;
- err = nil;
- }
- else if([err code] == SPBundleRedirectActionReplaceContent) {
- action = SPBundleOutputActionReplaceContent;
- err = nil;
- }
- else if([err code] == SPBundleRedirectActionInsertAsText) {
- action = SPBundleOutputActionInsertAsText;
- err = nil;
- }
- else if([err code] == SPBundleRedirectActionInsertAsSnippet) {
- action = SPBundleOutputActionInsertAsSnippet;
- err = nil;
- }
- else if([err code] == SPBundleRedirectActionShowAsHTML) {
- action = SPBundleOutputActionShowAsHTML;
- err = nil;
- }
- else if([err code] == SPBundleRedirectActionShowAsTextTooltip) {
- action = SPBundleOutputActionShowAsTextTooltip;
- err = nil;
- }
- else if([err code] == SPBundleRedirectActionShowAsHTMLTooltip) {
- action = SPBundleOutputActionShowAsHTMLTooltip;
- err = nil;
- }
+ NSString *action = SPBundleOutputActionNone;
+ if([cmdData objectForKey:SPBundleFileOutputActionKey] && [(NSString *)[cmdData objectForKey:SPBundleFileOutputActionKey] length])
+ action = [[cmdData objectForKey:SPBundleFileOutputActionKey] lowercaseString];
+
+ // Redirect due exit code
+ if(err != nil) {
+ if([err code] == SPBundleRedirectActionNone) {
+ action = SPBundleOutputActionNone;
+ err = nil;
+ }
+ else if([err code] == SPBundleRedirectActionReplaceSection) {
+ action = SPBundleOutputActionReplaceSelection;
+ err = nil;
+ }
+ else if([err code] == SPBundleRedirectActionReplaceContent) {
+ action = SPBundleOutputActionReplaceContent;
+ err = nil;
+ }
+ else if([err code] == SPBundleRedirectActionInsertAsText) {
+ action = SPBundleOutputActionInsertAsText;
+ err = nil;
+ }
+ else if([err code] == SPBundleRedirectActionInsertAsSnippet) {
+ action = SPBundleOutputActionInsertAsSnippet;
+ err = nil;
+ }
+ else if([err code] == SPBundleRedirectActionShowAsHTML) {
+ action = SPBundleOutputActionShowAsHTML;
+ err = nil;
+ }
+ else if([err code] == SPBundleRedirectActionShowAsTextTooltip) {
+ action = SPBundleOutputActionShowAsTextTooltip;
+ err = nil;
+ }
+ else if([err code] == SPBundleRedirectActionShowAsHTMLTooltip) {
+ action = SPBundleOutputActionShowAsHTMLTooltip;
+ err = nil;
}
+ }
- if(err == nil && output) {
- if(![action isEqualToString:SPBundleOutputActionNone]) {
- NSPoint pos = [NSEvent mouseLocation];
- pos.y -= 16;
+ if(err == nil && output) {
+ if(![action isEqualToString:SPBundleOutputActionNone]) {
+ NSPoint pos = [NSEvent mouseLocation];
+ pos.y -= 16;
- if([action isEqualToString:SPBundleOutputActionShowAsTextTooltip]) {
- [SPTooltip showWithObject:output atLocation:pos];
- }
+ if([action isEqualToString:SPBundleOutputActionShowAsTextTooltip]) {
+ [SPTooltip showWithObject:output atLocation:pos];
+ }
- else if([action isEqualToString:SPBundleOutputActionShowAsHTMLTooltip]) {
- [SPTooltip showWithObject:output atLocation:pos ofType:@"html"];
- }
+ else if([action isEqualToString:SPBundleOutputActionShowAsHTMLTooltip]) {
+ [SPTooltip showWithObject:output atLocation:pos ofType:@"html"];
+ }
- else if([action isEqualToString:SPBundleOutputActionShowAsHTML]) {
- BOOL correspondingWindowFound = NO;
- for(id win in [NSApp windows]) {
- if([[win delegate] isKindOfClass:[SPBundleHTMLOutputController class]]) {
- if([[[win delegate] windowUUID] isEqualToString:[cmdData objectForKey:SPBundleFileUUIDKey]]) {
- correspondingWindowFound = YES;
- [[win delegate] displayHTMLContent:output withOptions:nil];
- break;
- }
+ else if([action isEqualToString:SPBundleOutputActionShowAsHTML]) {
+ BOOL correspondingWindowFound = NO;
+ for(id win in [NSApp windows]) {
+ if([[win delegate] isKindOfClass:[SPBundleHTMLOutputController class]]) {
+ if([[[win delegate] windowUUID] isEqualToString:[cmdData objectForKey:SPBundleFileUUIDKey]]) {
+ correspondingWindowFound = YES;
+ [[win delegate] displayHTMLContent:output withOptions:nil];
+ break;
}
}
- if(!correspondingWindowFound) {
- SPBundleHTMLOutputController *bundleController = [[SPBundleHTMLOutputController alloc] init];
- [bundleController setWindowUUID:[cmdData objectForKey:SPBundleFileUUIDKey]];
- [bundleController displayHTMLContent:output withOptions:nil];
- [SPAppDelegate addHTMLOutputController:bundleController];
- }
+ }
+ if(!correspondingWindowFound) {
+ SPBundleHTMLOutputController *bundleController = [[SPBundleHTMLOutputController alloc] init];
+ [bundleController setWindowUUID:[cmdData objectForKey:SPBundleFileUUIDKey]];
+ [bundleController displayHTMLContent:output withOptions:nil];
+ [SPAppDelegate addHTMLOutputController:bundleController];
}
}
- } else if([err code] != 9) { // Suppress an error message if command was killed
- NSString *errorMessage = [err localizedDescription];
- SPOnewayAlertSheet(
- NSLocalizedString(@"BASH Error", @"bash error"),
- [self window],
- [NSString stringWithFormat:@"%@ “%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [cmdData objectForKey:@"name"], errorMessage]
- );
}
+ } else if([err code] != 9) { // Suppress an error message if command was killed
+ NSString *errorMessage = [err localizedDescription];
+ SPOnewayAlertSheet(
+ NSLocalizedString(@"BASH Error", @"bash error"),
+ [self window],
+ [NSString stringWithFormat:@"%@ “%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [cmdData objectForKey:@"name"], errorMessage]
+ );
}
-
- if (cmdData) [cmdData release];
}
+
+ if (cmdData) [cmdData release];
#endif
}
diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m
index 2a10b900..1d2861c6 100644
--- a/Source/SPDatabaseDocument.m
+++ b/Source/SPDatabaseDocument.m
@@ -3386,36 +3386,42 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0;
NSBeep();
return NO;
}
-
- NSError *readError = nil;
- NSString *convError = nil;
- NSPropertyListFormat format;
+
NSMutableDictionary *spf = [[NSMutableDictionary alloc] init];
-
- NSData *pData = [NSData dataWithContentsOfFile:fileName options:NSUncachedRead error:&readError];
-
- [spf addEntriesFromDictionary:[NSPropertyListSerialization propertyListFromData:pData
- mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&convError]];
-
- if(!spf || ![spf count] || readError != nil || [convError length] || !(format == NSPropertyListXMLFormat_v1_0 || format == NSPropertyListBinaryFormat_v1_0)) {
-
- [SPAlertSheets beginWaitingAlertSheetWithTitle:[NSString stringWithFormat:NSLocalizedString(@"Error while reading connection data file", @"error while reading connection data file")]
- defaultButton:NSLocalizedString(@"OK", @"OK button")
- alternateButton:NSLocalizedString(@"Ignore", @"ignore button")
- otherButton:nil
- alertStyle:NSCriticalAlertStyle
- docWindow:parentWindow
- modalDelegate:self
- didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
- contextInfo:@"saveDocPrefSheetStatus"
- infoText:[NSString stringWithFormat:NSLocalizedString(@"Connection data file “%@” couldn't be read. Please try to save the document under a different name.", @"message error while reading connection data file and suggesting to save it under a differnet name"), [fileName lastPathComponent]]
- returnCode:&saveDocPrefSheetStatus];
-
- if (spf) [spf release];
- if(saveDocPrefSheetStatus == NSAlertAlternateReturn)
- return YES;
-
- return NO;
+ {
+ NSError *error = nil;
+
+ NSData *pData = [NSData dataWithContentsOfFile:fileName options:NSUncachedRead error:&error];
+
+ if(pData && !error) {
+ NSDictionary *pDict = [NSPropertyListSerialization propertyListWithData:pData
+ options:NSPropertyListImmutable
+ format:NULL
+ error:&error];
+
+ if(pDict && !error) {
+ [spf addEntriesFromDictionary:pDict];
+ }
+ }
+
+ if(![spf count] || error) {
+ [SPAlertSheets beginWaitingAlertSheetWithTitle:NSLocalizedString(@"Error while reading connection data file", @"error while reading connection data file")
+ defaultButton:NSLocalizedString(@"OK", @"OK button")
+ alternateButton:NSLocalizedString(@"Ignore", @"ignore button")
+ otherButton:nil
+ alertStyle:NSCriticalAlertStyle
+ docWindow:parentWindow
+ modalDelegate:self
+ didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
+ contextInfo:@"saveDocPrefSheetStatus"
+ infoText:[NSString stringWithFormat:NSLocalizedString(@"Connection data file “%@” couldn't be read. Please try to save the document under a different name.\n\nDetails: %@", @"message error while reading connection data file and suggesting to save it under a differnet name"), [fileName lastPathComponent], [error localizedDescription]]
+ returnCode:&saveDocPrefSheetStatus];
+
+ if(spf) [spf release];
+ if(saveDocPrefSheetStatus == NSAlertAlternateReturn) return YES;
+
+ return NO;
+ }
}
// For dispatching later
@@ -4940,33 +4946,36 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0;
*/
- (BOOL)setStateFromConnectionFile:(NSString *)path
{
- NSError *readError = nil;
- NSString *convError = nil;
- NSPropertyListFormat format;
-
NSString *encryptpw = nil;
NSMutableDictionary *data = nil;
NSDictionary *spf = nil;
-
- // Read the property list data, and unserialize it.
- NSData *pData = [NSData dataWithContentsOfFile:path options:NSUncachedRead error:&readError];
-
- spf = [[NSPropertyListSerialization propertyListFromData:pData
- mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&convError] retain];
-
- if (!spf || readError != nil || [convError length] || !(format == NSPropertyListXMLFormat_v1_0 || format == NSPropertyListBinaryFormat_v1_0)) {
- NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Error while reading connection data file", @"error while reading connection data file")]
- defaultButton:NSLocalizedString(@"OK", @"OK button")
- alternateButton:nil
- otherButton:nil
- informativeTextWithFormat:NSLocalizedString(@"Connection data file couldn't be read.", @"error while reading connection data file")];
-
- [alert setAlertStyle:NSCriticalAlertStyle];
- [alert runModal];
- if (spf) [spf release];
- [self closeAndDisconnect];
- return NO;
+ {
+ NSError *error = nil;
+
+ // Read the property list data, and unserialize it.
+ NSData *pData = [NSData dataWithContentsOfFile:path options:NSUncachedRead error:&error];
+
+ if(pData && !error) {
+ spf = [[NSPropertyListSerialization propertyListWithData:pData
+ options:NSPropertyListImmutable
+ format:NULL
+ error:&error] retain];
+ }
+
+ if (!spf || error) {
+ NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Error while reading connection data file", @"error while reading connection data file")
+ defaultButton:NSLocalizedString(@"OK", @"OK button")
+ alternateButton:nil
+ otherButton:nil
+ informativeTextWithFormat:NSLocalizedString(@"Connection data file couldn't be read. (%@)", @"error while reading connection data file"), [error localizedDescription]];
+
+ [alert setAlertStyle:NSCriticalAlertStyle];
+ [alert runModal];
+ if (spf) [spf release];
+ [self closeAndDisconnect];
+ return NO;
+ }
}
// If the .spf format is unhandled, error.
diff --git a/Source/SPFieldEditorController.m b/Source/SPFieldEditorController.m
index b79355b5..f1212c81 100644
--- a/Source/SPFieldEditorController.m
+++ b/Source/SPFieldEditorController.m
@@ -129,17 +129,27 @@ typedef enum {
// Load default QL types
NSMutableArray *qlTypesItems = [[NSMutableArray alloc] init];
NSError *readError = nil;
- NSString *convError = nil;
- NSPropertyListFormat format;
- NSData *defaultTypeData = [NSData dataWithContentsOfFile:[NSBundle pathForResource:@"EditorQuickLookTypes.plist" ofType:nil inDirectory:[[NSBundle mainBundle] bundlePath]]
- options:NSMappedRead error:&readError];
-
- NSDictionary *defaultQLTypes = [NSPropertyListSerialization propertyListFromData:defaultTypeData
- mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&convError];
- if(defaultQLTypes == nil || readError != nil || convError != nil)
- NSLog(@"Error while reading 'EditorQuickLookTypes.plist':\n%@\n%@", [readError localizedDescription], convError);
- if(defaultQLTypes != nil && [defaultQLTypes objectForKey:@"QuickLookTypes"]) {
+ NSString *filePath = [NSBundle pathForResource:@"EditorQuickLookTypes.plist"
+ ofType:nil
+ inDirectory:[[NSBundle mainBundle] bundlePath]];
+
+ NSData *defaultTypeData = [NSData dataWithContentsOfFile:filePath
+ options:NSMappedRead
+ error:&readError];
+
+ NSDictionary *defaultQLTypes = nil;
+ if(defaultTypeData && !readError) {
+ defaultQLTypes = [NSPropertyListSerialization propertyListWithData:defaultTypeData
+ options:NSPropertyListImmutable
+ format:NULL
+ error:&readError];
+ }
+
+ if(defaultQLTypes == nil || readError ) {
+ NSLog(@"Error while reading 'EditorQuickLookTypes.plist':\n%@", readError);
+ }
+ else if(defaultQLTypes != nil && [defaultQLTypes objectForKey:@"QuickLookTypes"]) {
for(id type in [defaultQLTypes objectForKey:@"QuickLookTypes"]) {
NSMenuItem *aMenuItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithString:[type objectForKey:@"MenuLabel"]] action:NULL keyEquivalent:@""];
[aMenuItem setTag:tag];
diff --git a/Source/SPQueryControllerInitializer.m b/Source/SPQueryControllerInitializer.m
index f8292b37..6dc703ba 100644
--- a/Source/SPQueryControllerInitializer.m
+++ b/Source/SPQueryControllerInitializer.m
@@ -97,24 +97,30 @@ static NSString *SPCompletionTokensSnippetsKey = @"function_argument_snippets";
- (NSError *)loadCompletionLists
{
NSError *readError = nil;
- NSString *convError = nil;
NSString *errorDescription = nil;
- NSPropertyListFormat format;
- NSData *completionTokensData = [NSData dataWithContentsOfFile:
- [NSBundle pathForResource:SPCompletionTokensFilename
- ofType:nil
- inDirectory:[[NSBundle mainBundle] bundlePath]]
- options:NSMappedRead error:&readError];
+ NSString *filePath = [NSBundle pathForResource:SPCompletionTokensFilename
+ ofType:nil
+ inDirectory:[[NSBundle mainBundle] bundlePath]];
+
+ NSData *completionTokensData = [NSData dataWithContentsOfFile:filePath
+ options:NSMappedRead
+ error:&readError];
+
+ NSDictionary *completionPlist = nil;
+ if(completionTokensData && !readError) {
+ NSDictionary *plistDict = [NSPropertyListSerialization propertyListWithData:completionTokensData
+ options:NSPropertyListMutableContainersAndLeaves
+ format:NULL
+ error:&readError];
- NSDictionary *completionPlist = [NSDictionary dictionaryWithDictionary:
- [NSPropertyListSerialization propertyListFromData:completionTokensData
- mutabilityOption:NSPropertyListMutableContainersAndLeaves
- format:&format
- errorDescription:&convError]];
+ if(plistDict && !readError) {
+ completionPlist = [NSDictionary dictionaryWithDictionary:plistDict];
+ }
+ }
- if (completionPlist == nil || readError != nil || convError != nil) {
- errorDescription = [NSString stringWithFormat:@"Error reading '%@': %@, %@", SPCompletionTokensFilename, [readError localizedDescription], convError];
+ if (completionPlist == nil || readError) {
+ errorDescription = [NSString stringWithFormat:@"Error reading '%@': %@", SPCompletionTokensFilename, readError];
}
else {
if ([completionPlist objectForKey:SPCompletionTokensKeywordsKey]) {
diff --git a/Source/SPQueryFavoriteManager.m b/Source/SPQueryFavoriteManager.m
index 63726243..a31c9bd0 100644
--- a/Source/SPQueryFavoriteManager.m
+++ b/Source/SPQueryFavoriteManager.m
@@ -823,8 +823,6 @@
NSString *filename = [[[panel URLs] objectAtIndex:0] path];
NSError *readError = nil;
- NSString *convError = nil;
- NSPropertyListFormat format;
NSInteger insertionIndexStart, insertionIndexEnd;
NSDictionary *spf = nil;
@@ -832,15 +830,19 @@
if([[[filename pathExtension] lowercaseString] isEqualToString:SPFileExtensionDefault]) {
NSData *pData = [NSData dataWithContentsOfFile:filename options:NSUncachedRead error:&readError];
- spf = [[NSPropertyListSerialization propertyListFromData:pData
- mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&convError] retain];
-
- if(!spf || readError != nil || [convError length] || !(format == NSPropertyListXMLFormat_v1_0 || format == NSPropertyListBinaryFormat_v1_0)) {
- NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithString:NSLocalizedString(@"Error while reading data file", @"error while reading data file")]
+ if(pData && !readError) {
+ spf = [[NSPropertyListSerialization propertyListWithData:pData
+ options:NSPropertyListImmutable
+ format:NULL
+ error:&readError] retain];
+ }
+
+ if(!spf || readError) {
+ NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Error while reading data file", @"error while reading data file")
defaultButton:NSLocalizedString(@"OK", @"OK button")
alternateButton:nil
- otherButton:nil
- informativeTextWithFormat:NSLocalizedString(@"File couldn't be read.", @"error while reading data file")];
+ otherButton:nil
+ informativeTextWithFormat:NSLocalizedString(@"File couldn't be read. (%@)", @"error while reading data file"), [readError localizedDescription]];
[alert setAlertStyle:NSCriticalAlertStyle];
[alert runModal];
diff --git a/Source/SPTableContent.m b/Source/SPTableContent.m
index 2366cbf0..fda32232 100644
--- a/Source/SPTableContent.m
+++ b/Source/SPTableContent.m
@@ -181,21 +181,28 @@ static NSString *SPTableFilterSetDefaultOperator = @"SPTableFilterSetDefaultOper
whiteColor = [NSColor whiteColor];
// Init default filters for Content Browser
- contentFilters = nil;
contentFilters = [[NSMutableDictionary alloc] init];
numberOfDefaultFilters = [[NSMutableDictionary alloc] init];
NSError *readError = nil;
- NSString *convError = nil;
- NSPropertyListFormat format;
- NSData *defaultFilterData = [NSData dataWithContentsOfFile:[NSBundle pathForResource:@"ContentFilters.plist" ofType:nil inDirectory:[[NSBundle mainBundle] bundlePath]]
- options:NSMappedRead error:&readError];
-
- [contentFilters setDictionary:[NSPropertyListSerialization propertyListFromData:defaultFilterData
- mutabilityOption:NSPropertyListMutableContainersAndLeaves format:&format errorDescription:&convError]];
+ NSString *filePath = [NSBundle pathForResource:@"ContentFilters.plist" ofType:nil inDirectory:[[NSBundle mainBundle] bundlePath]];
+ NSData *defaultFilterData = [NSData dataWithContentsOfFile:filePath
+ options:NSMappedRead
+ error:&readError];
+
+ if(defaultFilterData && !readError) {
+ NSDictionary *defaultFilterDict = [NSPropertyListSerialization propertyListWithData:defaultFilterData
+ options:NSPropertyListMutableContainersAndLeaves
+ format:NULL
+ error:&readError];
+
+ if(defaultFilterDict && !readError) {
+ [contentFilters setDictionary:defaultFilterDict];
+ }
+ }
- if (contentFilters == nil || readError != nil || convError != nil) {
- NSLog(@"Error while reading 'ContentFilters.plist':\n%@\n%@", [readError localizedDescription], convError);
+ if (readError) {
+ NSLog(@"Error while reading 'ContentFilters.plist':\n%@", readError);
NSBeep();
}
else {
diff --git a/Source/SPTextViewAdditions.m b/Source/SPTextViewAdditions.m
index 88096a8f..c20959de 100644
--- a/Source/SPTextViewAdditions.m
+++ b/Source/SPTextViewAdditions.m
@@ -525,269 +525,272 @@
return;
}
- NSError *readError = nil;
- NSString *convError = nil;
- NSPropertyListFormat format;
NSDictionary *cmdData = nil;
- NSData *pData = [NSData dataWithContentsOfFile:infoPath options:NSUncachedRead error:&readError];
+ {
+ NSError *error = nil;
- cmdData = [[NSPropertyListSerialization propertyListFromData:pData
- mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&convError] retain];
+ NSData *pData = [NSData dataWithContentsOfFile:infoPath options:NSUncachedRead error:&error];
- if(!cmdData || readError != nil || [convError length] || !(format == NSPropertyListXMLFormat_v1_0 || format == NSPropertyListBinaryFormat_v1_0)) {
- NSLog(@"“%@” file couldn't be read.", infoPath);
- NSBeep();
- if (cmdData) [cmdData release];
- return;
- } else {
- if([cmdData objectForKey:SPBundleFileCommandKey] && [(NSString *)[cmdData objectForKey:SPBundleFileCommandKey] length]) {
+ if(!error) {
+ cmdData = [[NSPropertyListSerialization propertyListWithData:pData
+ options:NSPropertyListImmutable
+ format:NULL
+ error:&error] retain];
+ }
+
+ if(!cmdData || error) {
+ NSLog(@"“%@” file couldn't be read. (readError=%@)", infoPath, error);
+ NSBeep();
+ if (cmdData) [cmdData release];
+ return;
+ }
+ }
+
+ if([cmdData objectForKey:SPBundleFileCommandKey] && [(NSString *)[cmdData objectForKey:SPBundleFileCommandKey] length]) {
- NSString *cmd = [cmdData objectForKey:SPBundleFileCommandKey];
- NSString *inputAction = @"";
- NSString *inputFallBackAction = @"";
- NSError *err = nil;
- NSString *uuid = [NSString stringWithNewUUID];
- NSString *bundleInputFilePath = [NSString stringWithFormat:@"%@_%@", SPBundleTaskInputFilePath, uuid];
+ NSString *cmd = [cmdData objectForKey:SPBundleFileCommandKey];
+ NSString *inputAction = @"";
+ NSString *inputFallBackAction = @"";
+ NSError *err = nil;
+ NSString *uuid = [NSString stringWithNewUUID];
+ NSString *bundleInputFilePath = [NSString stringWithFormat:@"%@_%@", SPBundleTaskInputFilePath, uuid];
- NSRange currentWordRange, currentSelectionRange, currentLineRange, currentQueryRange;
+ NSRange currentWordRange, currentSelectionRange, currentLineRange, currentQueryRange;
- [[NSFileManager defaultManager] removeItemAtPath:bundleInputFilePath error:nil];
+ [[NSFileManager defaultManager] removeItemAtPath:bundleInputFilePath error:nil];
- BOOL selfIsQueryEditor = ([[[self class] description] isEqualToString:@"SPTextView"] && [[self delegate] respondsToSelector:@selector(currentQueryRange)]);
+ BOOL selfIsQueryEditor = ([[[self class] description] isEqualToString:@"SPTextView"] && [[self delegate] respondsToSelector:@selector(currentQueryRange)]);
- if([cmdData objectForKey:SPBundleFileInputSourceKey])
- inputAction = [[cmdData objectForKey:SPBundleFileInputSourceKey] lowercaseString];
- if([cmdData objectForKey:SPBundleFileInputSourceFallBackKey])
- inputFallBackAction = [[cmdData objectForKey:SPBundleFileInputSourceFallBackKey] lowercaseString];
+ if([cmdData objectForKey:SPBundleFileInputSourceKey])
+ inputAction = [[cmdData objectForKey:SPBundleFileInputSourceKey] lowercaseString];
+ if([cmdData objectForKey:SPBundleFileInputSourceFallBackKey])
+ inputFallBackAction = [[cmdData objectForKey:SPBundleFileInputSourceFallBackKey] lowercaseString];
- currentSelectionRange = [self selectedRange];
- currentWordRange = [self getRangeForCurrentWord];
- currentLineRange = [[self string] lineRangeForRange:NSMakeRange([self selectedRange].location, 0)];
+ currentSelectionRange = [self selectedRange];
+ currentWordRange = [self getRangeForCurrentWord];
+ currentLineRange = [[self string] lineRangeForRange:NSMakeRange([self selectedRange].location, 0)];
- if(selfIsQueryEditor) {
- currentQueryRange = [(SPCustomQuery*)[self delegate] currentQueryRange];
+ if(selfIsQueryEditor) {
+ currentQueryRange = [(SPCustomQuery*)[self delegate] currentQueryRange];
+ } else {
+ currentQueryRange = currentLineRange;
+ }
+ if(!currentQueryRange.length)
+ currentQueryRange = currentSelectionRange;
+
+ NSRange replaceRange = currentSelectionRange;
+ if([inputAction isEqualToString:SPBundleInputSourceSelectedText]) {
+ if(!currentSelectionRange.length) {
+ if([inputFallBackAction isEqualToString:SPBundleInputSourceCurrentWord])
+ replaceRange = currentWordRange;
+ else if([inputFallBackAction isEqualToString:SPBundleInputSourceCurrentLine])
+ replaceRange = currentLineRange;
+ else if([inputFallBackAction isEqualToString:SPBundleInputSourceCurrentQuery])
+ replaceRange = currentQueryRange;
+ else if([inputFallBackAction isEqualToString:SPBundleInputSourceEntireContent])
+ replaceRange = NSMakeRange(0,[[self string] length]);
} else {
- currentQueryRange = currentLineRange;
+ replaceRange = currentSelectionRange;
}
- if(!currentQueryRange.length)
- currentQueryRange = currentSelectionRange;
-
- NSRange replaceRange = currentSelectionRange;
- if([inputAction isEqualToString:SPBundleInputSourceSelectedText]) {
- if(!currentSelectionRange.length) {
- if([inputFallBackAction isEqualToString:SPBundleInputSourceCurrentWord])
- replaceRange = currentWordRange;
- else if([inputFallBackAction isEqualToString:SPBundleInputSourceCurrentLine])
- replaceRange = currentLineRange;
- else if([inputFallBackAction isEqualToString:SPBundleInputSourceCurrentQuery])
- replaceRange = currentQueryRange;
- else if([inputFallBackAction isEqualToString:SPBundleInputSourceEntireContent])
- replaceRange = NSMakeRange(0,[[self string] length]);
- } else {
- replaceRange = currentSelectionRange;
- }
- }
- else if([inputAction isEqualToString:SPBundleInputSourceEntireContent]) {
- replaceRange = NSMakeRange(0, [[self string] length]);
- }
+ }
+ else if([inputAction isEqualToString:SPBundleInputSourceEntireContent]) {
+ replaceRange = NSMakeRange(0, [[self string] length]);
+ }
- NSMutableDictionary *env = [NSMutableDictionary dictionary];
- [env setObject:[infoPath stringByDeletingLastPathComponent] forKey:SPBundleShellVariableBundlePath];
- [env setObject:bundleInputFilePath forKey:SPBundleShellVariableInputFilePath];
- [env setObject:SPBundleScopeInputField forKey:SPBundleShellVariableBundleScope];
-
- id tableSource = [self delegate];
- if([[[tableSource class] description] isEqualToString:@"SPFieldEditorController"]) {
- NSDictionary *editedFieldInfo = [tableSource editedFieldInfo];
- [env setObject:[editedFieldInfo objectForKey:@"colName"] forKey:SPBundleShellVariableCurrentEditedColumnName];
- if([editedFieldInfo objectForKey:@"tableName"])
- [env setObject:[editedFieldInfo objectForKey:@"tableName"] forKey:SPBundleShellVariableCurrentEditedTable];
- [env setObject:[editedFieldInfo objectForKey:@"usedQuery"] forKey:SPBundleShellVariableUsedQueryForTable];
- [env setObject:[editedFieldInfo objectForKey:@"tableSource"] forKey:SPBundleShellVariableDataTableSource];
- }
- else if([[[tableSource class] description] isEqualToString:@"SPCopyTable"]) {
- NSInteger editedCol = [tableSource editedColumn];
- if(editedCol > -1) {
- NSString *colName = [[[[tableSource tableColumns] objectAtIndex:editedCol] headerCell] stringValue];
- if([[[[tableSource dataSource] class] description] hasSuffix:@"Content"]) {
- [env setObject:[colName description] forKey:SPBundleShellVariableCurrentEditedColumnName];
- [env setObject:@"content" forKey:SPBundleShellVariableDataTableSource];
- } else {
- NSArray *defs = [[tableSource delegate] dataColumnDefinitions];
- for(NSDictionary* col in defs) {
- if([[col objectForKey:@"name"] isEqualToString:colName]) {
- [env setObject:[col objectForKey:@"org_name"] forKey:SPBundleShellVariableCurrentEditedColumnName];
- [env setObject:[col objectForKey:@"org_table"] forKey:SPBundleShellVariableCurrentEditedTable];
- break;
- }
+ NSMutableDictionary *env = [NSMutableDictionary dictionary];
+ [env setObject:[infoPath stringByDeletingLastPathComponent] forKey:SPBundleShellVariableBundlePath];
+ [env setObject:bundleInputFilePath forKey:SPBundleShellVariableInputFilePath];
+ [env setObject:SPBundleScopeInputField forKey:SPBundleShellVariableBundleScope];
+
+ id tableSource = [self delegate];
+ if([[[tableSource class] description] isEqualToString:@"SPFieldEditorController"]) {
+ NSDictionary *editedFieldInfo = [tableSource editedFieldInfo];
+ [env setObject:[editedFieldInfo objectForKey:@"colName"] forKey:SPBundleShellVariableCurrentEditedColumnName];
+ if([editedFieldInfo objectForKey:@"tableName"])
+ [env setObject:[editedFieldInfo objectForKey:@"tableName"] forKey:SPBundleShellVariableCurrentEditedTable];
+ [env setObject:[editedFieldInfo objectForKey:@"usedQuery"] forKey:SPBundleShellVariableUsedQueryForTable];
+ [env setObject:[editedFieldInfo objectForKey:@"tableSource"] forKey:SPBundleShellVariableDataTableSource];
+ }
+ else if([[[tableSource class] description] isEqualToString:@"SPCopyTable"]) {
+ NSInteger editedCol = [tableSource editedColumn];
+ if(editedCol > -1) {
+ NSString *colName = [[[[tableSource tableColumns] objectAtIndex:editedCol] headerCell] stringValue];
+ if([[[[tableSource dataSource] class] description] hasSuffix:@"Content"]) {
+ [env setObject:[colName description] forKey:SPBundleShellVariableCurrentEditedColumnName];
+ [env setObject:@"content" forKey:SPBundleShellVariableDataTableSource];
+ } else {
+ NSArray *defs = [[tableSource delegate] dataColumnDefinitions];
+ for(NSDictionary* col in defs) {
+ if([[col objectForKey:@"name"] isEqualToString:colName]) {
+ [env setObject:[col objectForKey:@"org_name"] forKey:SPBundleShellVariableCurrentEditedColumnName];
+ [env setObject:[col objectForKey:@"org_table"] forKey:SPBundleShellVariableCurrentEditedTable];
+ break;
}
- [env setObject:@"query" forKey:SPBundleShellVariableDataTableSource];
}
- if([[tableSource delegate] respondsToSelector:@selector(usedQuery)] && [[tableSource delegate] usedQuery])
- [env setObject:[[tableSource delegate] usedQuery] forKey:SPBundleShellVariableUsedQueryForTable];
+ [env setObject:@"query" forKey:SPBundleShellVariableDataTableSource];
}
+ if([[tableSource delegate] respondsToSelector:@selector(usedQuery)] && [[tableSource delegate] usedQuery])
+ [env setObject:[[tableSource delegate] usedQuery] forKey:SPBundleShellVariableUsedQueryForTable];
}
+ }
- if(selfIsQueryEditor && [(SPCustomQuery*)[self delegate] currentQueryRange].length)
- [env setObject:[[self string] substringWithRange:[(SPCustomQuery*)[self delegate] currentQueryRange]] forKey:SPBundleShellVariableCurrentQuery];
+ if(selfIsQueryEditor && [(SPCustomQuery*)[self delegate] currentQueryRange].length)
+ [env setObject:[[self string] substringWithRange:[(SPCustomQuery*)[self delegate] currentQueryRange]] forKey:SPBundleShellVariableCurrentQuery];
- if(currentSelectionRange.length)
- [env setObject:[[self string] substringWithRange:currentSelectionRange] forKey:SPBundleShellVariableSelectedText];
+ if(currentSelectionRange.length)
+ [env setObject:[[self string] substringWithRange:currentSelectionRange] forKey:SPBundleShellVariableSelectedText];
- if(currentWordRange.length)
- [env setObject:[[self string] substringWithRange:currentWordRange] forKey:SPBundleShellVariableCurrentWord];
+ if(currentWordRange.length)
+ [env setObject:[[self string] substringWithRange:currentWordRange] forKey:SPBundleShellVariableCurrentWord];
- if(currentLineRange.length)
- [env setObject:[[self string] substringWithRange:currentLineRange] forKey:SPBundleShellVariableCurrentLine];
+ if(currentLineRange.length)
+ [env setObject:[[self string] substringWithRange:currentLineRange] forKey:SPBundleShellVariableCurrentLine];
- [env setObject:NSStringFromRange(replaceRange) forKey:SPBundleShellVariableSelectedTextRange];
+ [env setObject:NSStringFromRange(replaceRange) forKey:SPBundleShellVariableSelectedTextRange];
- NSError *inputFileError = nil;
- NSString *input = [NSString stringWithString:[[self string] substringWithRange:replaceRange]];
+ NSError *inputFileError = nil;
+ NSString *input = [NSString stringWithString:[[self string] substringWithRange:replaceRange]];
- [input writeToFile:bundleInputFilePath
- atomically:YES
- encoding:NSUTF8StringEncoding
- error:&inputFileError];
+ [input writeToFile:bundleInputFilePath
+ atomically:YES
+ encoding:NSUTF8StringEncoding
+ error:&inputFileError];
- if(inputFileError != nil) {
- NSString *errorMessage = [inputFileError localizedDescription];
- SPOnewayAlertSheet(
- NSLocalizedString(@"Bundle Error", @"bundle error"),
- [self window],
- [NSString stringWithFormat:@"%@ “%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [cmdData objectForKey:@"name"], errorMessage]
- );
- if (cmdData) [cmdData release];
- return;
- }
+ if(inputFileError != nil) {
+ NSString *errorMessage = [inputFileError localizedDescription];
+ SPOnewayAlertSheet(
+ NSLocalizedString(@"Bundle Error", @"bundle error"),
+ [self window],
+ [NSString stringWithFormat:@"%@ “%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [cmdData objectForKey:@"name"], errorMessage]
+ );
+ if (cmdData) [cmdData release];
+ return;
+ }
- NSString *output = [SPBundleCommandRunner runBashCommand:cmd withEnvironment:env
- atCurrentDirectoryPath:nil
- callerInstance:[SPAppDelegate frontDocument]
- contextInfo:[NSDictionary dictionaryWithObjectsAndKeys:
- ([cmdData objectForKey:SPBundleFileNameKey])?:@"-", @"name",
- NSLocalizedString(@"Input Field", @"input field menu item label"), @"scope",
- uuid, SPBundleFileInternalexecutionUUID, nil]
- error:&err];
-
- [[NSFileManager defaultManager] removeItemAtPath:bundleInputFilePath error:nil];
-
- NSString *action = SPBundleOutputActionNone;
- if([cmdData objectForKey:SPBundleFileOutputActionKey] && [(NSString *)[cmdData objectForKey:SPBundleFileOutputActionKey] length])
- action = [[cmdData objectForKey:SPBundleFileOutputActionKey] lowercaseString];
-
- // Redirect due exit code
- if(err != nil) {
- if([err code] == SPBundleRedirectActionNone) {
- action = SPBundleOutputActionNone;
- err = nil;
- }
- else if([err code] == SPBundleRedirectActionReplaceSection) {
- action = SPBundleOutputActionReplaceSelection;
- err = nil;
- }
- else if([err code] == SPBundleRedirectActionReplaceContent) {
- action = SPBundleOutputActionReplaceContent;
- err = nil;
- }
- else if([err code] == SPBundleRedirectActionInsertAsText) {
- action = SPBundleOutputActionInsertAsText;
- err = nil;
- }
- else if([err code] == SPBundleRedirectActionInsertAsSnippet) {
- action = SPBundleOutputActionInsertAsSnippet;
- err = nil;
- }
- else if([err code] == SPBundleRedirectActionShowAsHTML) {
- action = SPBundleOutputActionShowAsHTML;
- err = nil;
- }
- else if([err code] == SPBundleRedirectActionShowAsTextTooltip) {
- action = SPBundleOutputActionShowAsTextTooltip;
- err = nil;
- }
- else if([err code] == SPBundleRedirectActionShowAsHTMLTooltip) {
- action = SPBundleOutputActionShowAsHTMLTooltip;
- err = nil;
- }
+ NSString *output = [SPBundleCommandRunner runBashCommand:cmd withEnvironment:env
+ atCurrentDirectoryPath:nil
+ callerInstance:[SPAppDelegate frontDocument]
+ contextInfo:[NSDictionary dictionaryWithObjectsAndKeys:
+ ([cmdData objectForKey:SPBundleFileNameKey])?:@"-", @"name",
+ NSLocalizedString(@"Input Field", @"input field menu item label"), @"scope",
+ uuid, SPBundleFileInternalexecutionUUID, nil]
+ error:&err];
+
+ [[NSFileManager defaultManager] removeItemAtPath:bundleInputFilePath error:nil];
+
+ NSString *action = SPBundleOutputActionNone;
+ if([cmdData objectForKey:SPBundleFileOutputActionKey] && [(NSString *)[cmdData objectForKey:SPBundleFileOutputActionKey] length])
+ action = [[cmdData objectForKey:SPBundleFileOutputActionKey] lowercaseString];
+
+ // Redirect due exit code
+ if(err != nil) {
+ if([err code] == SPBundleRedirectActionNone) {
+ action = SPBundleOutputActionNone;
+ err = nil;
+ }
+ else if([err code] == SPBundleRedirectActionReplaceSection) {
+ action = SPBundleOutputActionReplaceSelection;
+ err = nil;
+ }
+ else if([err code] == SPBundleRedirectActionReplaceContent) {
+ action = SPBundleOutputActionReplaceContent;
+ err = nil;
+ }
+ else if([err code] == SPBundleRedirectActionInsertAsText) {
+ action = SPBundleOutputActionInsertAsText;
+ err = nil;
+ }
+ else if([err code] == SPBundleRedirectActionInsertAsSnippet) {
+ action = SPBundleOutputActionInsertAsSnippet;
+ err = nil;
+ }
+ else if([err code] == SPBundleRedirectActionShowAsHTML) {
+ action = SPBundleOutputActionShowAsHTML;
+ err = nil;
+ }
+ else if([err code] == SPBundleRedirectActionShowAsTextTooltip) {
+ action = SPBundleOutputActionShowAsTextTooltip;
+ err = nil;
+ }
+ else if([err code] == SPBundleRedirectActionShowAsHTMLTooltip) {
+ action = SPBundleOutputActionShowAsHTMLTooltip;
+ err = nil;
}
+ }
- if(err == nil && output) {
- if(![action isEqualToString:SPBundleOutputActionNone]) {
+ if(err == nil && output) {
+ if(![action isEqualToString:SPBundleOutputActionNone]) {
- if([action isEqualToString:SPBundleOutputActionShowAsTextTooltip]) {
- [SPTooltip showWithObject:output];
- }
+ if([action isEqualToString:SPBundleOutputActionShowAsTextTooltip]) {
+ [SPTooltip showWithObject:output];
+ }
- else if([action isEqualToString:SPBundleOutputActionShowAsHTMLTooltip]) {
- [SPTooltip showWithObject:output ofType:@"html"];
- }
+ else if([action isEqualToString:SPBundleOutputActionShowAsHTMLTooltip]) {
+ [SPTooltip showWithObject:output ofType:@"html"];
+ }
- else if([action isEqualToString:SPBundleOutputActionShowAsHTML]) {
- BOOL correspondingWindowFound = NO;
- for(id win in [NSApp windows]) {
- if([[win delegate] isKindOfClass:[SPBundleHTMLOutputController class]]) {
- if([[[win delegate] windowUUID] isEqualToString:[cmdData objectForKey:SPBundleFileUUIDKey]]) {
- correspondingWindowFound = YES;
- [[win delegate] displayHTMLContent:output withOptions:nil];
- break;
- }
+ else if([action isEqualToString:SPBundleOutputActionShowAsHTML]) {
+ BOOL correspondingWindowFound = NO;
+ for(id win in [NSApp windows]) {
+ if([[win delegate] isKindOfClass:[SPBundleHTMLOutputController class]]) {
+ if([[[win delegate] windowUUID] isEqualToString:[cmdData objectForKey:SPBundleFileUUIDKey]]) {
+ correspondingWindowFound = YES;
+ [[win delegate] displayHTMLContent:output withOptions:nil];
+ break;
}
}
- if(!correspondingWindowFound) {
- SPBundleHTMLOutputController *c = [[SPBundleHTMLOutputController alloc] init];
- [c setWindowUUID:[cmdData objectForKey:SPBundleFileUUIDKey]];
- [c displayHTMLContent:output withOptions:nil];
- [SPAppDelegate addHTMLOutputController:c];
- }
}
+ if(!correspondingWindowFound) {
+ SPBundleHTMLOutputController *c = [[SPBundleHTMLOutputController alloc] init];
+ [c setWindowUUID:[cmdData objectForKey:SPBundleFileUUIDKey]];
+ [c displayHTMLContent:output withOptions:nil];
+ [SPAppDelegate addHTMLOutputController:c];
+ }
+ }
- if([self isEditable]) {
-
- if([action isEqualToString:SPBundleOutputActionInsertAsText]) {
- [self insertText:output];
- }
+ if([self isEditable]) {
- else if([action isEqualToString:SPBundleOutputActionInsertAsSnippet]) {
- if([self respondsToSelector:@selector(insertAsSnippet:atRange:)])
- [(SPTextView *)self insertAsSnippet:output atRange:replaceRange];
- else
- [SPTooltip showWithObject:NSLocalizedString(@"Input Field doesn't support insertion of snippets.", @"input field doesn't support insertion of snippets.")];
- }
+ if([action isEqualToString:SPBundleOutputActionInsertAsText]) {
+ [self insertText:output];
+ }
- else if([action isEqualToString:SPBundleOutputActionReplaceContent]) {
- if([[self string] length])
- [self setSelectedRange:NSMakeRange(0, [[self string] length])];
- [self insertText:output];
- }
+ else if([action isEqualToString:SPBundleOutputActionInsertAsSnippet]) {
+ if([self respondsToSelector:@selector(insertAsSnippet:atRange:)])
+ [(SPTextView *)self insertAsSnippet:output atRange:replaceRange];
+ else
+ [SPTooltip showWithObject:NSLocalizedString(@"Input Field doesn't support insertion of snippets.", @"input field doesn't support insertion of snippets.")];
+ }
- else if([action isEqualToString:SPBundleOutputActionReplaceSelection]) {
- NSRange safeRange = NSIntersectionRange(replaceRange, NSMakeRange(0, [[self string] length]));
- [self shouldChangeTextInRange:safeRange replacementString:output];
- [self replaceCharactersInRange:safeRange withString:output];
- }
+ else if([action isEqualToString:SPBundleOutputActionReplaceContent]) {
+ if([[self string] length])
+ [self setSelectedRange:NSMakeRange(0, [[self string] length])];
+ [self insertText:output];
+ }
- } else {
- [SPTooltip showWithObject:NSLocalizedString(@"Input Field is not editable.", @"input field is not editable.")];
+ else if([action isEqualToString:SPBundleOutputActionReplaceSelection]) {
+ NSRange safeRange = NSIntersectionRange(replaceRange, NSMakeRange(0, [[self string] length]));
+ [self shouldChangeTextInRange:safeRange replacementString:output];
+ [self replaceCharactersInRange:safeRange withString:output];
}
+ } else {
+ [SPTooltip showWithObject:NSLocalizedString(@"Input Field is not editable.", @"input field is not editable.")];
}
- } else if([err code] != 9) { // Suppress an error message if command was killed
- NSString *errorMessage = [err localizedDescription];
- SPOnewayAlertSheet(
- NSLocalizedString(@"BASH Error", @"bash error"),
- [self window],
- [NSString stringWithFormat:@"%@ “%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [cmdData objectForKey:@"name"], errorMessage]
- );
- }
+ }
+ } else if([err code] != 9) { // Suppress an error message if command was killed
+ NSString *errorMessage = [err localizedDescription];
+ SPOnewayAlertSheet(
+ NSLocalizedString(@"BASH Error", @"bash error"),
+ [self window],
+ [NSString stringWithFormat:@"%@ “%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [cmdData objectForKey:@"name"], errorMessage]
+ );
}
- if (cmdData) [cmdData release];
-
}
+ if (cmdData) [cmdData release];
}
/**