From c668c662b616ec378f6ff8315055b46acbc923cc Mon Sep 17 00:00:00 2001 From: Bibiko Date: Mon, 3 Jan 2011 12:49:49 +0000 Subject: =?UTF-8?q?=E2=80=A2=20changed=20the=20way=20to=20check=20for=20av?= =?UTF-8?q?ailable=20update=20of=20Default=20Bundles=20-=20perform=20a=20c?= =?UTF-8?q?heck=20only=20if=20the=20revision=20number=20is=20greater=20as?= =?UTF-8?q?=20the=20last=20recorded=20one,=20in=20other=20words=20if=20an?= =?UTF-8?q?=20updated=20version=20of=20Sequel=20Pro=20was=20installed=20an?= =?UTF-8?q?d=20runs=20for=20the=20very=20first=20time?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPAppController.m | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'Source/SPAppController.m') diff --git a/Source/SPAppController.m b/Source/SPAppController.m index 25a181fa..ec853140 100644 --- a/Source/SPAppController.m +++ b/Source/SPAppController.m @@ -1353,19 +1353,17 @@ BOOL processDefaultBundles = NO; NSFileManager *fm = [NSFileManager defaultManager]; - + NSArray *deletedDefaultBundles; - NSMutableArray *updatedDefaultBundles = [NSMutableArray array]; + if([[NSUserDefaults standardUserDefaults] objectForKey:SPBundleDeletedDefaultBundlesKey]) { deletedDefaultBundles = [[[NSUserDefaults standardUserDefaults] objectForKey:SPBundleDeletedDefaultBundlesKey] retain]; } else { deletedDefaultBundles = [[NSArray array] retain]; } - if([[NSUserDefaults standardUserDefaults] objectForKey:SPBundleUpdatedDefaultBundlesKey]) { - [updatedDefaultBundles setArray:[[NSUserDefaults standardUserDefaults] objectForKey:SPBundleUpdatedDefaultBundlesKey]]; - } NSMutableString *infoAboutUpdatedDefaultBundles = [NSMutableString string]; + BOOL doBundleUpdate = ([[NSUserDefaults standardUserDefaults] objectForKey:@"doBundleUpdate"]) ? YES : NO; for(NSString* bundlePath in bundlePaths) { if([bundlePath length]) { @@ -1420,8 +1418,8 @@ // If default Bundle is already install check for possible update, // if so duplicate the modified one by appending (user) and updated it if([installedBundleUUIDs objectForKey:[cmdData objectForKey:SPBundleFileUUIDKey]]) { - if([updatedDefaultBundles containsObject:[cmdData objectForKey:SPBundleFileUUIDKey]]) { - + if(doBundleUpdate) { +NSLog(@"do update"); NSString *oldPath = [NSString stringWithFormat:@"%@/%@/%@", [bundlePaths objectAtIndex:0], bundle, SPBundleFileName]; NSError *readError = nil; NSString *convError = nil; @@ -1496,9 +1494,6 @@ } - // Remove item from update list which will be updated in the Prefs - [updatedDefaultBundles removeObject:[cmdData objectForKey:SPBundleFileUUIDKey]]; - } if (cmdData) [cmdData release]; @@ -1624,9 +1619,10 @@ } [deletedDefaultBundles release]; - - // Synchronize updated Bundles - [[NSUserDefaults standardUserDefaults] setObject:updatedDefaultBundles forKey:SPBundleUpdatedDefaultBundlesKey]; + if(doBundleUpdate) { + [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"doBundleUpdate"]; + [[NSUserDefaults standardUserDefaults] synchronize]; + } // Inform user about default Bundle updates which were modified by the user and re-run Reload Bundles if([infoAboutUpdatedDefaultBundles length]) { -- cgit v1.2.3 From bbab688204b36631e350b80573e38c2dc019f670 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Mon, 3 Jan 2011 12:53:28 +0000 Subject: =?UTF-8?q?=E2=80=A2=20forgot=20to=20remove=20debug=20logs=20of=20?= =?UTF-8?q?previous=20commit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPAppController.m | 152 +++++++++++++++++++++++------------------------ 1 file changed, 75 insertions(+), 77 deletions(-) (limited to 'Source/SPAppController.m') diff --git a/Source/SPAppController.m b/Source/SPAppController.m index ec853140..81932fad 100644 --- a/Source/SPAppController.m +++ b/Source/SPAppController.m @@ -1417,90 +1417,88 @@ // If default Bundle is already install check for possible update, // if so duplicate the modified one by appending (user) and updated it - if([installedBundleUUIDs objectForKey:[cmdData objectForKey:SPBundleFileUUIDKey]]) { - if(doBundleUpdate) { -NSLog(@"do update"); - NSString *oldPath = [NSString stringWithFormat:@"%@/%@/%@", [bundlePaths objectAtIndex:0], bundle, SPBundleFileName]; - NSError *readError = nil; - NSString *convError = nil; - NSPropertyListFormat format; - NSDictionary *cmdData = nil; - - NSData *pData = [NSData dataWithContentsOfFile:oldPath 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.", oldPath); - NSBeep(); - if (cmdData) [cmdData release]; - continue; + if(doBundleUpdate && [installedBundleUUIDs objectForKey:[cmdData objectForKey:SPBundleFileUUIDKey]]) { + + NSString *oldPath = [NSString stringWithFormat:@"%@/%@/%@", [bundlePaths objectAtIndex:0], bundle, SPBundleFileName]; + NSError *readError = nil; + NSString *convError = nil; + NSPropertyListFormat format; + NSDictionary *cmdData = nil; + + NSData *pData = [NSData dataWithContentsOfFile:oldPath 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.", oldPath); + NSBeep(); + if (cmdData) [cmdData release]; + continue; + } else { + NSString *oldBundle = [NSString stringWithFormat:@"%@/%@", [bundlePaths objectAtIndex:0], bundle]; + // Check for modifications + if([cmdData 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)], (NSUInteger)(random() % 35000), SPUserBundleFileExtension]; + if(![[NSFileManager defaultManager] copyItemAtPath:oldBundle toPath:duplicatedBundle error:nil]) { + NSLog(@"Couldn't copy “%@” to update it", bundle); + NSBeep(); + if (cmdData) [cmdData release]; + 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; + } + [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]; + + NSError *error = nil; + NSString *moveToTrashCommand = [NSString stringWithFormat:@"osascript -e 'tell application \"Finder\" to move (POSIX file \"%@\") to the trash'", oldBundle]; + [moveToTrashCommand runBashCommandWithEnvironment: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:[cmdData objectForKey:SPBundleFileUUIDKey]] objectForKey:@"path"]] + defaultButton:NSLocalizedString(@"OK", @"OK button") + alternateButton:nil + otherButton:nil + informativeTextWithFormat:[error localizedDescription]]; + + [alert setAlertStyle:NSCriticalAlertStyle]; + [alert runModal]; + if (cmdData) [cmdData release]; + continue; + } + [infoAboutUpdatedDefaultBundles appendFormat:@"• %@\n", orgName]; } else { - NSString *oldBundle = [NSString stringWithFormat:@"%@/%@", [bundlePaths objectAtIndex:0], bundle]; - // Check for modifications - if([cmdData 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)], (NSUInteger)(random() % 35000), SPUserBundleFileExtension]; - if(![[NSFileManager defaultManager] copyItemAtPath:oldBundle toPath:duplicatedBundle error:nil]) { - NSLog(@"Couldn't copy “%@” to update it", bundle); - NSBeep(); - if (cmdData) [cmdData release]; - 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; - } - [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]; - - NSError *error = nil; - NSString *moveToTrashCommand = [NSString stringWithFormat:@"osascript -e 'tell application \"Finder\" to move (POSIX file \"%@\") to the trash'", oldBundle]; - [moveToTrashCommand runBashCommandWithEnvironment: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:[cmdData objectForKey:SPBundleFileUUIDKey]] objectForKey:@"path"]] - defaultButton:NSLocalizedString(@"OK", @"OK button") - alternateButton:nil - otherButton:nil - informativeTextWithFormat:[error localizedDescription]]; - - [alert setAlertStyle:NSCriticalAlertStyle]; - [alert runModal]; - if (cmdData) [cmdData release]; - 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(); - if (cmdData) [cmdData release]; - continue; - } + // 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(); + if (cmdData) [cmdData release]; + continue; } } - if (cmdData) [cmdData release]; - - } else { - continue; } + + if (cmdData) [cmdData release]; + + } else { + continue; } BOOL isDir; -- cgit v1.2.3 From f7874daaeb147cda239b69330a7819aba5bb3bbc Mon Sep 17 00:00:00 2001 From: Bibiko Date: Mon, 3 Jan 2011 14:11:32 +0000 Subject: =?UTF-8?q?=E2=80=A2=20cleaned=20code=20for=20NSPropertyListSerial?= =?UTF-8?q?ization=20while=20reloadBundles=20(thanks=20to=20emixam=20for?= =?UTF-8?q?=20pointing=20it=20out)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPAppController.m | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) (limited to 'Source/SPAppController.m') diff --git a/Source/SPAppController.m b/Source/SPAppController.m index 81932fad..f13a43f6 100644 --- a/Source/SPAppController.m +++ b/Source/SPAppController.m @@ -1384,8 +1384,8 @@ 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]; + cmdData = [NSPropertyListSerialization propertyListFromData:pData + mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&convError]; if(!cmdData || readError != nil || [convError length] || !(format == NSPropertyListXMLFormat_v1_0 || format == NSPropertyListBinaryFormat_v1_0)) { @@ -1423,27 +1423,25 @@ NSError *readError = nil; NSString *convError = nil; NSPropertyListFormat format; - NSDictionary *cmdData = nil; + NSDictionary *cmdDataOld = nil; - NSData *pData = [NSData dataWithContentsOfFile:oldPath 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)) { + 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(); - if (cmdData) [cmdData release]; continue; } else { NSString *oldBundle = [NSString stringWithFormat:@"%@/%@", [bundlePaths objectAtIndex:0], bundle]; // Check for modifications - if([cmdData objectForKey:SPBundleFileDefaultBundleWasModifiedKey]) { + 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)], (NSUInteger)(random() % 35000), SPUserBundleFileExtension]; if(![[NSFileManager defaultManager] copyItemAtPath:oldBundle toPath:duplicatedBundle error:nil]) { NSLog(@"Couldn't copy “%@” to update it", bundle); NSBeep(); - if (cmdData) [cmdData release]; continue; } NSError *readError1 = nil; @@ -1469,7 +1467,7 @@ [moveToTrashCommand runBashCommandWithEnvironment: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:[cmdData objectForKey:SPBundleFileUUIDKey]] objectForKey:@"path"]] + 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 @@ -1477,7 +1475,6 @@ [alert setAlertStyle:NSCriticalAlertStyle]; [alert runModal]; - if (cmdData) [cmdData release]; continue; } [infoAboutUpdatedDefaultBundles appendFormat:@"• %@\n", orgName]; @@ -1487,7 +1484,6 @@ if(![fm removeItemAtPath:oldBundle error:nil]) { NSLog(@"Couldn't remove “%@” to update it", bundle); NSBeep(); - if (cmdData) [cmdData release]; continue; } @@ -1495,8 +1491,6 @@ } - if (cmdData) [cmdData release]; - } else { continue; } @@ -1601,8 +1595,6 @@ } - if (cmdData) [cmdData release]; - } } -- cgit v1.2.3 From e85f7dfdc240b9e5be2ff4cbe46727f49096f91f Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Mon, 3 Jan 2011 22:58:07 +0000 Subject: - Alter bundle search paths to no longer add a blank location as the first option if the Application support bundles folder does not exist; addresses issues where default bundles are updated in the hard disk root --- Source/SPAppController.m | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'Source/SPAppController.m') diff --git a/Source/SPAppController.m b/Source/SPAppController.m index f13a43f6..99f950a1 100644 --- a/Source/SPAppController.m +++ b/Source/SPAppController.m @@ -1346,10 +1346,11 @@ // Clean menu [menu compatibleRemoveAllItems]; - NSArray *bundlePaths = [NSArray arrayWithObjects: - ([[NSFileManager defaultManager] applicationSupportDirectoryForSubDirectory:SPBundleSupportFolder createIfNotExists:NO error:nil])?:@"", - [NSString stringWithFormat:@"%@/Contents/SharedSupport/Default Bundles", [[NSBundle mainBundle] bundlePath]], - nil]; + // Set up the bundle search paths - always the default bundles directory, and the application support directory if it exists + NSMutableArray *bundlePaths = [NSMutableArray arrayWithCapacity:2]; + NSString *appSupportPath = [[NSFileManager defaultManager] applicationSupportDirectoryForSubDirectory:SPBundleSupportFolder createIfNotExists:NO error:nil]; + if (appSupportPath) [bundlePaths addObject:appSupportPath]; + [bundlePaths addObject:[NSString stringWithFormat:@"%@/Contents/SharedSupport/Default Bundles", [[NSBundle mainBundle] bundlePath]]]; BOOL processDefaultBundles = NO; NSFileManager *fm = [NSFileManager defaultManager]; -- cgit v1.2.3 From 1c085bf3a240935dae3d77c697717d5595ba9584 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Wed, 5 Jan 2011 12:39:53 +0000 Subject: =?UTF-8?q?=E2=80=A2=20fixed=20bug=20for=20copying=20default=20bun?= =?UTF-8?q?dles=20after=20SP=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPAppController.m | 2 -- 1 file changed, 2 deletions(-) (limited to 'Source/SPAppController.m') diff --git a/Source/SPAppController.m b/Source/SPAppController.m index 99f950a1..1cc7eda9 100644 --- a/Source/SPAppController.m +++ b/Source/SPAppController.m @@ -1492,8 +1492,6 @@ } - } else { - continue; } BOOL isDir; -- cgit v1.2.3 From 7415fbd1d1bd93881899732590ceee55d8891aff Mon Sep 17 00:00:00 2001 From: Bibiko Date: Wed, 5 Jan 2011 12:58:02 +0000 Subject: =?UTF-8?q?=E2=80=A2=20further=20fix=20for=20updating=20default=20?= =?UTF-8?q?Bundles=20after=20SP=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPAppController.m | 3 +++ 1 file changed, 3 insertions(+) (limited to 'Source/SPAppController.m') diff --git a/Source/SPAppController.m b/Source/SPAppController.m index 1cc7eda9..ca8c3dcc 100644 --- a/Source/SPAppController.m +++ b/Source/SPAppController.m @@ -1366,6 +1366,9 @@ NSMutableString *infoAboutUpdatedDefaultBundles = [NSMutableString string]; BOOL doBundleUpdate = ([[NSUserDefaults standardUserDefaults] objectForKey:@"doBundleUpdate"]) ? YES : NO; + if(doBundleUpdate && !appSupportPath) + [bundlePaths insertObject:[[NSFileManager defaultManager] applicationSupportDirectoryForSubDirectory:SPBundleSupportFolder createIfNotExists:YES error:nil] atIndex:0]; + for(NSString* bundlePath in bundlePaths) { if([bundlePath length]) { -- cgit v1.2.3 From d9874d3a3188897a9e898ca5cb3aa3c94e2d765a Mon Sep 17 00:00:00 2001 From: Bibiko Date: Wed, 5 Jan 2011 13:15:20 +0000 Subject: =?UTF-8?q?=E2=80=A2=20fixed=20bug=20for=20re-copying=20default=20?= =?UTF-8?q?bundles=20after=20launching=20SP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPAppController.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Source/SPAppController.m') diff --git a/Source/SPAppController.m b/Source/SPAppController.m index ca8c3dcc..c9fc9b01 100644 --- a/Source/SPAppController.m +++ b/Source/SPAppController.m @@ -1405,7 +1405,7 @@ if([cmdData objectForKey:SPBundleFileUUIDKey] && [[cmdData objectForKey:SPBundleFileUUIDKey] length]) { - if(processDefaultBundles) { + if(doBundleUpdate && processDefaultBundles) { // Skip deleted default Bundles BOOL bundleWasDeleted = NO; @@ -1421,7 +1421,7 @@ // If default Bundle is already install check for possible update, // if so duplicate the modified one by appending (user) and updated it - if(doBundleUpdate && [installedBundleUUIDs objectForKey:[cmdData objectForKey:SPBundleFileUUIDKey]]) { + if([installedBundleUUIDs objectForKey:[cmdData objectForKey:SPBundleFileUUIDKey]]) { NSString *oldPath = [NSString stringWithFormat:@"%@/%@/%@", [bundlePaths objectAtIndex:0], bundle, SPBundleFileName]; NSError *readError = nil; -- cgit v1.2.3 From a6bff16b6f7e65cf74376e92d8d60d4572a20e3c Mon Sep 17 00:00:00 2001 From: Bibiko Date: Wed, 5 Jan 2011 18:49:19 +0000 Subject: =?UTF-8?q?=E2=80=A2=20improved=20Default=20Bundle=20management=20?= =?UTF-8?q?for=20installation,=20updating,=20undeletion=20=E2=80=A2=20if?= =?UTF-8?q?=20current=20NSTextView=20is=20not=20set=20to=20NSLeftTextAlign?= =?UTF-8?q?ment=20show=20a=20SPTooltip=20at=20mouse=20location=20until=20w?= =?UTF-8?q?e=20found=20a=20way=20the=20calculate=20the=20caret=20position?= =?UTF-8?q?=20correctly=20since=20[NSLayoutManager=20glyphRangeForCharacte?= =?UTF-8?q?rRange:]=20returns=20a=20wrong=20NSRect?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPAppController.m | 213 +++++++++++++++++++++++++---------------------- 1 file changed, 113 insertions(+), 100 deletions(-) (limited to 'Source/SPAppController.m') diff --git a/Source/SPAppController.m b/Source/SPAppController.m index c9fc9b01..273758ba 100644 --- a/Source/SPAppController.m +++ b/Source/SPAppController.m @@ -1347,28 +1347,36 @@ [menu compatibleRemoveAllItems]; // Set up the bundle search paths - always the default bundles directory, and the application support directory if it exists - NSMutableArray *bundlePaths = [NSMutableArray arrayWithCapacity:2]; - NSString *appSupportPath = [[NSFileManager defaultManager] applicationSupportDirectoryForSubDirectory:SPBundleSupportFolder createIfNotExists:NO error:nil]; - if (appSupportPath) [bundlePaths addObject:appSupportPath]; - [bundlePaths addObject:[NSString stringWithFormat:@"%@/Contents/SharedSupport/Default Bundles", [[NSBundle mainBundle] bundlePath]]]; + NSFileManager *fm = [NSFileManager defaultManager]; + NSError *appPathError = nil; + NSArray *bundlePaths = [NSArray arrayWithObjects: + [fm applicationSupportDirectoryForSubDirectory:SPBundleSupportFolder createIfNotExists:YES error:&appPathError], + [NSString stringWithFormat:@"%@/Contents/SharedSupport/Default Bundles", [[NSBundle mainBundle] bundlePath]], + nil]; + + if(appPathError != nil) { + NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Bundles Installation Error", @"bundles installation error") + defaultButton:NSLocalizedString(@"OK", @"OK button") + alternateButton:nil + otherButton:nil + informativeTextWithFormat:[NSString stringWithFormat:NSLocalizedString(@"Couldn't create Application Support Bundle folder!\nError: %@", @"Couldn't create Application Support Bundle folder!\nError: %@"), [appPathError localizedDescription]]]; + + [alert runModal]; + return; + } BOOL processDefaultBundles = NO; - NSFileManager *fm = [NSFileManager defaultManager]; NSArray *deletedDefaultBundles; - if([[NSUserDefaults standardUserDefaults] objectForKey:SPBundleDeletedDefaultBundlesKey]) { + if([[NSUserDefaults standardUserDefaults] objectForKey:SPBundleDeletedDefaultBundlesKey]) deletedDefaultBundles = [[[NSUserDefaults standardUserDefaults] objectForKey:SPBundleDeletedDefaultBundlesKey] retain]; - } else { + else deletedDefaultBundles = [[NSArray array] retain]; - } NSMutableString *infoAboutUpdatedDefaultBundles = [NSMutableString string]; BOOL doBundleUpdate = ([[NSUserDefaults standardUserDefaults] objectForKey:@"doBundleUpdate"]) ? YES : NO; - if(doBundleUpdate && !appSupportPath) - [bundlePaths insertObject:[[NSFileManager defaultManager] applicationSupportDirectoryForSubDirectory:SPBundleSupportFolder createIfNotExists:YES error:nil] atIndex:0]; - for(NSString* bundlePath in bundlePaths) { if([bundlePath length]) { @@ -1392,35 +1400,37 @@ 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; + } - } else { - if((![cmdData objectForKey:SPBundleFileDisabledKey] || ![[cmdData objectForKey:SPBundleFileDisabledKey] intValue]) - && [cmdData objectForKey:SPBundleFileNameKey] - && [[cmdData objectForKey:SPBundleFileNameKey] length] - && [cmdData objectForKey:SPBundleFileScopeKey]) - { - - if([cmdData objectForKey:SPBundleFileUUIDKey] && [[cmdData objectForKey:SPBundleFileUUIDKey] length]) { - - if(doBundleUpdate && processDefaultBundles) { - - // Skip deleted default Bundles - BOOL bundleWasDeleted = NO; - if([deletedDefaultBundles count]) { - for(NSArray* item in deletedDefaultBundles) { - if([[item objectAtIndex:0] isEqualToString:[cmdData objectForKey:SPBundleFileUUIDKey]]) { - bundleWasDeleted = YES; - break; - } + if((![cmdData objectForKey:SPBundleFileDisabledKey] || ![[cmdData objectForKey:SPBundleFileDisabledKey] intValue]) + && [cmdData objectForKey:SPBundleFileNameKey] + && [[cmdData objectForKey:SPBundleFileNameKey] length] + && [cmdData objectForKey:SPBundleFileScopeKey]) + { + + if([cmdData objectForKey:SPBundleFileUUIDKey] && [[cmdData objectForKey:SPBundleFileUUIDKey] length]) { + + if(processDefaultBundles) { + + // Skip deleted default Bundles + BOOL bundleWasDeleted = NO; + if([deletedDefaultBundles count]) { + for(NSArray* item in deletedDefaultBundles) { + if([[item objectAtIndex:0] isEqualToString:[cmdData objectForKey:SPBundleFileUUIDKey]]) { + bundleWasDeleted = YES; + break; } } - if(bundleWasDeleted) continue; + } + if(bundleWasDeleted) continue; + + // If default Bundle is already install check for possible update, + // if so duplicate the modified one by appending (user) and updated it + if(doBundleUpdate || [installedBundleUUIDs objectForKey:[cmdData objectForKey:SPBundleFileUUIDKey]] == nil) { - // If default Bundle is already install check for possible update, - // if so duplicate the modified one by appending (user) and updated it if([installedBundleUUIDs objectForKey:[cmdData objectForKey:SPBundleFileUUIDKey]]) { NSString *oldPath = [NSString stringWithFormat:@"%@/%@/%@", [bundlePaths objectAtIndex:0], bundle, SPBundleFileName]; @@ -1494,7 +1504,6 @@ } } - } BOOL isDir; @@ -1511,91 +1520,95 @@ continue; } infoPath = [NSString stringWithString:newInfoPath]; - } [installedBundleUUIDs setObject:[NSDictionary dictionaryWithObjectsAndKeys: [NSString stringWithFormat:@"%@ (%@)", bundle, [cmdData objectForKey:SPBundleFileNameKey]], @"name", infoPath, @"path", nil] forKey:[cmdData objectForKey:SPBundleFileUUIDKey]]; + // Remove updated Bundle from already set bundleItems + NSString *anUuid = [cmdData objectForKey:SPBundleFileUUIDKey]; + for(NSDictionary* item in [bundleItems objectForKey:[cmdData objectForKey:SPBundleFileScopeKey]]) { + if([[item objectForKey:SPBundleFileUUIDKey] isEqualToString:anUuid]) { + [[bundleItems objectForKey:[cmdData objectForKey:SPBundleFileScopeKey]] removeObject:item]; + break; + } + } + } else { - NSLog(@"No UUID for %@", bundle); - NSBeep(); - continue; + [installedBundleUUIDs setObject:[NSDictionary dictionaryWithObjectsAndKeys: + [NSString stringWithFormat:@"%@ (%@)", bundle, [cmdData objectForKey:SPBundleFileNameKey]], @"name", + infoPath, @"path", nil] forKey:[cmdData objectForKey:SPBundleFileUUIDKey]]; } - NSArray *scopes = [[cmdData objectForKey:SPBundleFileScopeKey] componentsSeparatedByString:@" "]; - for(NSString *scope in scopes) { + } else { + NSLog(@"No UUID for %@", bundle); + NSBeep(); + continue; + } + + NSString *scope = [cmdData objectForKey:SPBundleFileScopeKey]; - if(![bundleUsedScopes containsObject:scope]) { - [bundleUsedScopes addObject:scope]; - [bundleItems setObject:[NSMutableArray array] forKey:scope]; - [bundleCategories setObject:[NSMutableArray array] forKey:scope]; - [bundleKeyEquivalents setObject:[NSMutableDictionary dictionary] forKey:scope]; - } + if(![bundleUsedScopes containsObject:scope]) { + [bundleUsedScopes addObject:scope]; + [bundleItems setObject:[NSMutableArray array] forKey:scope]; + [bundleCategories setObject:[NSMutableArray array] forKey:scope]; + [bundleKeyEquivalents setObject:[NSMutableDictionary dictionary] forKey:scope]; + } - if([cmdData objectForKey:SPBundleFileCategoryKey] && [[cmdData objectForKey:SPBundleFileCategoryKey] length] && ![[bundleCategories objectForKey:scope] containsObject:[cmdData objectForKey:SPBundleFileCategoryKey]]) - [[bundleCategories objectForKey:scope] addObject:[cmdData objectForKey:SPBundleFileCategoryKey]]; - } + if([cmdData objectForKey:SPBundleFileCategoryKey] && [[cmdData objectForKey:SPBundleFileCategoryKey] length] && ![[bundleCategories objectForKey:scope] containsObject:[cmdData objectForKey:SPBundleFileCategoryKey]]) + [[bundleCategories objectForKey:scope] addObject:[cmdData objectForKey:SPBundleFileCategoryKey]]; + + NSMutableDictionary *aDict = [NSMutableDictionary dictionary]; + [aDict setObject:[cmdData objectForKey:SPBundleFileNameKey] forKey:SPBundleInternLabelKey]; + [aDict setObject:infoPath forKey:SPBundleInternPathToFileKey]; + [aDict setObject:[cmdData objectForKey:SPBundleFileUUIDKey] forKey:SPBundleFileUUIDKey]; + + // Register trigger + if([cmdData objectForKey:SPBundleFileTriggerKey]) { + if(![bundleTriggers objectForKey:[cmdData objectForKey:SPBundleFileTriggerKey]]) + [bundleTriggers setObject:[NSMutableArray array] forKey:[cmdData objectForKey:SPBundleFileTriggerKey]]; + [[bundleTriggers objectForKey:[cmdData objectForKey:SPBundleFileTriggerKey]] addObject: + [NSString stringWithFormat:@"%@|%@|%@", + infoPath, + [cmdData objectForKey:SPBundleFileScopeKey], + ([[cmdData objectForKey:SPBundleFileOutputActionKey] isEqualToString:SPBundleOutputActionShowAsHTML])?[cmdData objectForKey:SPBundleFileUUIDKey]:@""]]; + } - NSMutableDictionary *aDict = [NSMutableDictionary dictionary]; - [aDict setObject:[cmdData objectForKey:SPBundleFileNameKey] forKey:SPBundleInternLabelKey]; - [aDict setObject:infoPath forKey:SPBundleInternPathToFileKey]; - - // Register trigger - if([cmdData objectForKey:SPBundleFileTriggerKey]) { - if(![bundleTriggers objectForKey:[cmdData objectForKey:SPBundleFileTriggerKey]]) - [bundleTriggers setObject:[NSMutableArray array] forKey:[cmdData objectForKey:SPBundleFileTriggerKey]]; - [[bundleTriggers objectForKey:[cmdData objectForKey:SPBundleFileTriggerKey]] addObject: - [NSString stringWithFormat:@"%@|%@|%@", - infoPath, - [cmdData objectForKey:SPBundleFileScopeKey], - ([[cmdData objectForKey:SPBundleFileOutputActionKey] isEqualToString:SPBundleOutputActionShowAsHTML])?[cmdData objectForKey:SPBundleFileUUIDKey]:@""]]; - } + if([cmdData objectForKey:SPBundleFileKeyEquivalentKey] && [[cmdData objectForKey:SPBundleFileKeyEquivalentKey] length]) { - if([cmdData objectForKey:SPBundleFileKeyEquivalentKey] && [[cmdData objectForKey:SPBundleFileKeyEquivalentKey] length]) { - - NSString *theKey = [cmdData objectForKey:SPBundleFileKeyEquivalentKey]; - NSString *theChar = [theKey substringFromIndex:[theKey length]-1]; - NSString *theMods = [theKey substringToIndex:[theKey length]-1]; - NSUInteger mask = 0; - if([theMods rangeOfString:@"^"].length) - mask = mask | NSControlKeyMask; - if([theMods rangeOfString:@"@"].length) - mask = mask | NSCommandKeyMask; - if([theMods rangeOfString:@"~"].length) - mask = mask | NSAlternateKeyMask; - if([theMods rangeOfString:@"$"].length) - mask = mask | NSShiftKeyMask; - for(NSString* scope in scopes) { - if(![[bundleKeyEquivalents objectForKey:scope] objectForKey:[cmdData objectForKey:SPBundleFileKeyEquivalentKey]]) - [[bundleKeyEquivalents objectForKey:scope] setObject:[NSMutableArray array] forKey:[cmdData objectForKey:SPBundleFileKeyEquivalentKey]]; - - [[[bundleKeyEquivalents objectForKey:scope] objectForKey:[cmdData objectForKey:SPBundleFileKeyEquivalentKey]] addObject: - [NSDictionary dictionaryWithObjectsAndKeys: - infoPath, @"path", - [cmdData objectForKey:SPBundleFileNameKey], @"title", - ([cmdData objectForKey:SPBundleFileTooltipKey]) ?: @"", @"tooltip", - nil]]; + NSString *theKey = [cmdData objectForKey:SPBundleFileKeyEquivalentKey]; + NSString *theChar = [theKey substringFromIndex:[theKey length]-1]; + NSString *theMods = [theKey substringToIndex:[theKey length]-1]; + NSUInteger mask = 0; + if([theMods rangeOfString:@"^"].length) mask = mask | NSControlKeyMask; + if([theMods rangeOfString:@"@"].length) mask = mask | NSCommandKeyMask; + if([theMods rangeOfString:@"~"].length) mask = mask | NSAlternateKeyMask; + if([theMods rangeOfString:@"$"].length) mask = mask | NSShiftKeyMask; - } + if(![[bundleKeyEquivalents objectForKey:scope] objectForKey:[cmdData objectForKey:SPBundleFileKeyEquivalentKey]]) + [[bundleKeyEquivalents objectForKey:scope] setObject:[NSMutableArray array] forKey:[cmdData objectForKey:SPBundleFileKeyEquivalentKey]]; - [aDict setObject:[NSArray arrayWithObjects:theChar, [NSNumber numberWithInteger:mask], nil] forKey:SPBundleInternKeyEquivalentKey]; - } + [[[bundleKeyEquivalents objectForKey:scope] objectForKey:[cmdData objectForKey:SPBundleFileKeyEquivalentKey]] addObject: + [NSDictionary dictionaryWithObjectsAndKeys: + infoPath, @"path", + [cmdData objectForKey:SPBundleFileNameKey], @"title", + ([cmdData objectForKey:SPBundleFileTooltipKey]) ?: @"", @"tooltip", + nil]]; - if([cmdData objectForKey:SPBundleFileTooltipKey] && [[cmdData objectForKey:SPBundleFileTooltipKey] length]) - [aDict setObject:[cmdData objectForKey:SPBundleFileTooltipKey] forKey:SPBundleFileTooltipKey]; + [aDict setObject:[NSArray arrayWithObjects:theChar, [NSNumber numberWithInteger:mask], nil] forKey:SPBundleInternKeyEquivalentKey]; + } - if([cmdData objectForKey:SPBundleFileCategoryKey] && [[cmdData objectForKey:SPBundleFileCategoryKey] length]) - [aDict setObject:[cmdData objectForKey:SPBundleFileCategoryKey] forKey:SPBundleFileCategoryKey]; + if([cmdData objectForKey:SPBundleFileTooltipKey] && [[cmdData objectForKey:SPBundleFileTooltipKey] length]) + [aDict setObject:[cmdData objectForKey:SPBundleFileTooltipKey] forKey:SPBundleFileTooltipKey]; - if([cmdData objectForKey:SPBundleFileKeyEquivalentKey] && [[cmdData objectForKey:SPBundleFileKeyEquivalentKey] length]) - [aDict setObject:[cmdData objectForKey:SPBundleFileKeyEquivalentKey] forKey:@"key"]; + if([cmdData objectForKey:SPBundleFileCategoryKey] && [[cmdData objectForKey:SPBundleFileCategoryKey] length]) + [aDict setObject:[cmdData objectForKey:SPBundleFileCategoryKey] forKey:SPBundleFileCategoryKey]; - for(NSString* scope in scopes) - [[bundleItems objectForKey:scope] addObject:aDict]; + if([cmdData objectForKey:SPBundleFileKeyEquivalentKey] && [[cmdData objectForKey:SPBundleFileKeyEquivalentKey] length]) + [aDict setObject:[cmdData objectForKey:SPBundleFileKeyEquivalentKey] forKey:@"key"]; - } + [[bundleItems objectForKey:scope] addObject:aDict]; } } -- cgit v1.2.3 From 9694c8e17e09e067964aef42afb6a7ed67e506e0 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Fri, 7 Jan 2011 07:23:39 +0000 Subject: =?UTF-8?q?=E2=80=A2=20improved=20installation=20routine=20for=20D?= =?UTF-8?q?efault=20Bundles=20=E2=80=A2=20added=20missing=20key=20isDefaul?= =?UTF-8?q?tBundle=20to=20Default=20Bundles?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPAppController.m | 142 ++++++++++++++++++++++------------------------- 1 file changed, 67 insertions(+), 75 deletions(-) (limited to 'Source/SPAppController.m') diff --git a/Source/SPAppController.m b/Source/SPAppController.m index 273758ba..c03a9394 100644 --- a/Source/SPAppController.m +++ b/Source/SPAppController.m @@ -1346,7 +1346,8 @@ // Clean menu [menu compatibleRemoveAllItems]; - // Set up the bundle search paths - always the default bundles directory, and the application support directory if it exists + // Set up the bundle search paths + // First process all in Application Support folder installed ones then Default ones NSFileManager *fm = [NSFileManager defaultManager]; NSError *appPathError = nil; NSArray *bundlePaths = [NSArray arrayWithObjects: @@ -1354,6 +1355,7 @@ [NSString stringWithFormat:@"%@/Contents/SharedSupport/Default Bundles", [[NSBundle mainBundle] bundlePath]], nil]; + // If ~/Library/Application Path/Sequel Pro/Bundles couldn't be created bail if(appPathError != nil) { NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Bundles Installation Error", @"bundles installation error") defaultButton:NSLocalizedString(@"OK", @"OK button") @@ -1427,7 +1429,7 @@ } if(bundleWasDeleted) continue; - // If default Bundle is already install check for possible update, + // If default Bundle is already installed check for possible update, // if so duplicate the modified one by appending (user) and updated it if(doBundleUpdate || [installedBundleUUIDs objectForKey:[cmdData objectForKey:SPBundleFileUUIDKey]] == nil) { @@ -1522,97 +1524,87 @@ infoPath = [NSString stringWithString:newInfoPath]; } - [installedBundleUUIDs setObject:[NSDictionary dictionaryWithObjectsAndKeys: - [NSString stringWithFormat:@"%@ (%@)", bundle, [cmdData objectForKey:SPBundleFileNameKey]], @"name", - infoPath, @"path", nil] forKey:[cmdData objectForKey:SPBundleFileUUIDKey]]; - - // Remove updated Bundle from already set bundleItems - NSString *anUuid = [cmdData objectForKey:SPBundleFileUUIDKey]; - for(NSDictionary* item in [bundleItems objectForKey:[cmdData objectForKey:SPBundleFileScopeKey]]) { - if([[item objectForKey:SPBundleFileUUIDKey] isEqualToString:anUuid]) { - [[bundleItems objectForKey:[cmdData objectForKey:SPBundleFileScopeKey]] removeObject:item]; - break; - } - } - - } else { - [installedBundleUUIDs setObject:[NSDictionary dictionaryWithObjectsAndKeys: - [NSString stringWithFormat:@"%@ (%@)", bundle, [cmdData objectForKey:SPBundleFileNameKey]], @"name", - infoPath, @"path", nil] forKey:[cmdData objectForKey:SPBundleFileUUIDKey]]; } + [installedBundleUUIDs setObject:[NSDictionary dictionaryWithObjectsAndKeys: + [NSString stringWithFormat:@"%@ (%@)", bundle, [cmdData objectForKey:SPBundleFileNameKey]], @"name", + infoPath, @"path", nil] forKey:[cmdData objectForKey:SPBundleFileUUIDKey]]; + } else { NSLog(@"No UUID for %@", bundle); NSBeep(); continue; } - NSString *scope = [cmdData objectForKey:SPBundleFileScopeKey]; - - if(![bundleUsedScopes containsObject:scope]) { - [bundleUsedScopes addObject:scope]; - [bundleItems setObject:[NSMutableArray array] forKey:scope]; - [bundleCategories setObject:[NSMutableArray array] forKey:scope]; - [bundleKeyEquivalents setObject:[NSMutableDictionary dictionary] forKey:scope]; - } + // Register Bundle - do it for default Bundles only while processDefaultBundles + if(![cmdData objectForKey:SPBundleFileIsDefaultBundleKey] || processDefaultBundles) { + NSString *scope = [cmdData objectForKey:SPBundleFileScopeKey]; - if([cmdData objectForKey:SPBundleFileCategoryKey] && [[cmdData objectForKey:SPBundleFileCategoryKey] length] && ![[bundleCategories objectForKey:scope] containsObject:[cmdData objectForKey:SPBundleFileCategoryKey]]) - [[bundleCategories objectForKey:scope] addObject:[cmdData objectForKey:SPBundleFileCategoryKey]]; - - NSMutableDictionary *aDict = [NSMutableDictionary dictionary]; - [aDict setObject:[cmdData objectForKey:SPBundleFileNameKey] forKey:SPBundleInternLabelKey]; - [aDict setObject:infoPath forKey:SPBundleInternPathToFileKey]; - [aDict setObject:[cmdData objectForKey:SPBundleFileUUIDKey] forKey:SPBundleFileUUIDKey]; - - // Register trigger - if([cmdData objectForKey:SPBundleFileTriggerKey]) { - if(![bundleTriggers objectForKey:[cmdData objectForKey:SPBundleFileTriggerKey]]) - [bundleTriggers setObject:[NSMutableArray array] forKey:[cmdData objectForKey:SPBundleFileTriggerKey]]; - [[bundleTriggers objectForKey:[cmdData objectForKey:SPBundleFileTriggerKey]] addObject: - [NSString stringWithFormat:@"%@|%@|%@", - infoPath, - [cmdData objectForKey:SPBundleFileScopeKey], - ([[cmdData objectForKey:SPBundleFileOutputActionKey] isEqualToString:SPBundleOutputActionShowAsHTML])?[cmdData objectForKey:SPBundleFileUUIDKey]:@""]]; - } + // Register scope/category menu structure + if(![bundleUsedScopes containsObject:scope]) { + [bundleUsedScopes addObject:scope]; + [bundleItems setObject:[NSMutableArray array] forKey:scope]; + [bundleCategories setObject:[NSMutableArray array] forKey:scope]; + [bundleKeyEquivalents setObject:[NSMutableDictionary dictionary] forKey:scope]; + } + if([cmdData objectForKey:SPBundleFileCategoryKey] && [[cmdData objectForKey:SPBundleFileCategoryKey] length] && ![[bundleCategories objectForKey:scope] containsObject:[cmdData objectForKey:SPBundleFileCategoryKey]]) + [[bundleCategories objectForKey:scope] addObject:[cmdData objectForKey:SPBundleFileCategoryKey]]; + + NSMutableDictionary *aDict = [NSMutableDictionary dictionary]; + [aDict setObject:[cmdData objectForKey:SPBundleFileNameKey] forKey:SPBundleInternLabelKey]; + [aDict setObject:infoPath forKey:SPBundleInternPathToFileKey]; + + // Register trigger + if([cmdData objectForKey:SPBundleFileTriggerKey]) { + if(![bundleTriggers objectForKey:[cmdData objectForKey:SPBundleFileTriggerKey]]) + [bundleTriggers setObject:[NSMutableArray array] forKey:[cmdData objectForKey:SPBundleFileTriggerKey]]; + [[bundleTriggers objectForKey:[cmdData objectForKey:SPBundleFileTriggerKey]] addObject: + [NSString stringWithFormat:@"%@|%@|%@", + infoPath, + [cmdData objectForKey:SPBundleFileScopeKey], + ([[cmdData objectForKey:SPBundleFileOutputActionKey] isEqualToString:SPBundleOutputActionShowAsHTML])?[cmdData objectForKey:SPBundleFileUUIDKey]:@""]]; + } - if([cmdData objectForKey:SPBundleFileKeyEquivalentKey] && [[cmdData objectForKey:SPBundleFileKeyEquivalentKey] length]) { + // Register key equivalent + if([cmdData objectForKey:SPBundleFileKeyEquivalentKey] && [[cmdData objectForKey:SPBundleFileKeyEquivalentKey] length]) { + + NSString *theKey = [cmdData objectForKey:SPBundleFileKeyEquivalentKey]; + NSString *theChar = [theKey substringFromIndex:[theKey length]-1]; + NSString *theMods = [theKey substringToIndex:[theKey length]-1]; + NSUInteger mask = 0; + if([theMods rangeOfString:@"^"].length) mask = mask | NSControlKeyMask; + if([theMods rangeOfString:@"@"].length) mask = mask | NSCommandKeyMask; + if([theMods rangeOfString:@"~"].length) mask = mask | NSAlternateKeyMask; + if([theMods rangeOfString:@"$"].length) mask = mask | NSShiftKeyMask; + + if(![[bundleKeyEquivalents objectForKey:scope] objectForKey:[cmdData objectForKey:SPBundleFileKeyEquivalentKey]]) + [[bundleKeyEquivalents objectForKey:scope] setObject:[NSMutableArray array] forKey:[cmdData objectForKey:SPBundleFileKeyEquivalentKey]]; + + [[[bundleKeyEquivalents objectForKey:scope] objectForKey:[cmdData objectForKey:SPBundleFileKeyEquivalentKey]] addObject: + [NSDictionary dictionaryWithObjectsAndKeys: + infoPath, @"path", + [cmdData objectForKey:SPBundleFileNameKey], @"title", + ([cmdData objectForKey:SPBundleFileTooltipKey]) ?: @"", @"tooltip", + nil]]; + + [aDict setObject:[NSArray arrayWithObjects:theChar, [NSNumber numberWithInteger:mask], nil] forKey:SPBundleInternKeyEquivalentKey]; + } - NSString *theKey = [cmdData objectForKey:SPBundleFileKeyEquivalentKey]; - NSString *theChar = [theKey substringFromIndex:[theKey length]-1]; - NSString *theMods = [theKey substringToIndex:[theKey length]-1]; - NSUInteger mask = 0; - if([theMods rangeOfString:@"^"].length) mask = mask | NSControlKeyMask; - if([theMods rangeOfString:@"@"].length) mask = mask | NSCommandKeyMask; - if([theMods rangeOfString:@"~"].length) mask = mask | NSAlternateKeyMask; - if([theMods rangeOfString:@"$"].length) mask = mask | NSShiftKeyMask; + if([cmdData objectForKey:SPBundleFileTooltipKey] && [[cmdData objectForKey:SPBundleFileTooltipKey] length]) + [aDict setObject:[cmdData objectForKey:SPBundleFileTooltipKey] forKey:SPBundleFileTooltipKey]; - if(![[bundleKeyEquivalents objectForKey:scope] objectForKey:[cmdData objectForKey:SPBundleFileKeyEquivalentKey]]) - [[bundleKeyEquivalents objectForKey:scope] setObject:[NSMutableArray array] forKey:[cmdData objectForKey:SPBundleFileKeyEquivalentKey]]; + if([cmdData objectForKey:SPBundleFileCategoryKey] && [[cmdData objectForKey:SPBundleFileCategoryKey] length]) + [aDict setObject:[cmdData objectForKey:SPBundleFileCategoryKey] forKey:SPBundleFileCategoryKey]; - [[[bundleKeyEquivalents objectForKey:scope] objectForKey:[cmdData objectForKey:SPBundleFileKeyEquivalentKey]] addObject: - [NSDictionary dictionaryWithObjectsAndKeys: - infoPath, @"path", - [cmdData objectForKey:SPBundleFileNameKey], @"title", - ([cmdData objectForKey:SPBundleFileTooltipKey]) ?: @"", @"tooltip", - nil]]; + if([cmdData objectForKey:SPBundleFileKeyEquivalentKey] && [[cmdData objectForKey:SPBundleFileKeyEquivalentKey] length]) + [aDict setObject:[cmdData objectForKey:SPBundleFileKeyEquivalentKey] forKey:@"key"]; - [aDict setObject:[NSArray arrayWithObjects:theChar, [NSNumber numberWithInteger:mask], nil] forKey:SPBundleInternKeyEquivalentKey]; + [[bundleItems objectForKey:scope] addObject:aDict]; } - - if([cmdData objectForKey:SPBundleFileTooltipKey] && [[cmdData objectForKey:SPBundleFileTooltipKey] length]) - [aDict setObject:[cmdData objectForKey:SPBundleFileTooltipKey] forKey:SPBundleFileTooltipKey]; - - if([cmdData objectForKey:SPBundleFileCategoryKey] && [[cmdData objectForKey:SPBundleFileCategoryKey] length]) - [aDict setObject:[cmdData objectForKey:SPBundleFileCategoryKey] forKey:SPBundleFileCategoryKey]; - - if([cmdData objectForKey:SPBundleFileKeyEquivalentKey] && [[cmdData objectForKey:SPBundleFileKeyEquivalentKey] length]) - [aDict setObject:[cmdData objectForKey:SPBundleFileKeyEquivalentKey] forKey:@"key"]; - - [[bundleItems objectForKey:scope] addObject:aDict]; - } } + // Sort items for menus NSSortDescriptor *sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:SPBundleInternLabelKey ascending:YES] autorelease]; for(NSString* scope in [bundleItems allKeys]) { [[bundleItems objectForKey:scope] sortUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]]; -- cgit v1.2.3 From a9c113a35112f077da922729d26234abf47ccc89 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Fri, 7 Jan 2011 07:57:43 +0000 Subject: =?UTF-8?q?=E2=80=A2=20minor=20code=20cleaning?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPAppController.m | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'Source/SPAppController.m') diff --git a/Source/SPAppController.m b/Source/SPAppController.m index c03a9394..38d8d54c 100644 --- a/Source/SPAppController.m +++ b/Source/SPAppController.m @@ -496,7 +496,7 @@ NSFileManager *fm = [NSFileManager defaultManager]; - NSString *bundlePath = [[NSFileManager defaultManager] applicationSupportDirectoryForSubDirectory:SPBundleSupportFolder error:nil]; + NSString *bundlePath = [fm applicationSupportDirectoryForSubDirectory:SPBundleSupportFolder error:nil]; if(!bundlePath) return; @@ -621,7 +621,12 @@ { NSURL *url = [NSURL URLWithString:[[event paramDescriptorForKeyword:keyDirectObject] stringValue]]; - [self handleEventWithURL:url]; + if(url) + [self handleEventWithURL:url]; + else { + NSBeep(); + NSLog(@"Error in sequelpro URL scheme"); + } } - (void)handleEventWithURL:(NSURL*)url @@ -635,13 +640,14 @@ else parameter = [NSArray array]; + NSFileManager *fm = [NSFileManager defaultManager]; // Handle commands which don't need a connection window if([command isEqualToString:@"chooseItemFromList"]) { NSString *statusFileName = [NSString stringWithFormat:@"%@%@", SPURLSchemeQueryResultStatusPathHeader, (passedProcessID && [passedProcessID length]) ? passedProcessID : @""]; NSString *resultFileName = [NSString stringWithFormat:@"%@%@", SPURLSchemeQueryResultPathHeader, (passedProcessID && [passedProcessID length]) ? passedProcessID : @""]; - [[NSFileManager defaultManager] removeItemAtPath:statusFileName error:nil]; - [[NSFileManager defaultManager] removeItemAtPath:resultFileName error:nil]; + [fm removeItemAtPath:statusFileName error:nil]; + [fm removeItemAtPath:resultFileName error:nil]; NSString *result = @""; NSString *status = @"0"; if([parameter count]) { @@ -695,14 +701,12 @@ [cmdDict setObject:parameter forKey:@"parameter"]; [cmdDict setObject:(passedProcessID)?:@"" forKey:@"id"]; [processDocument handleSchemeCommand:cmdDict]; - return; - } - else { + } else { SPBeginAlertSheet(NSLocalizedString(@"sequelpro URL Scheme Error", @"sequelpro url Scheme Error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [NSApp mainWindow], self, nil, nil, [NSString stringWithFormat:@"%@ “%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [command description], NSLocalizedString(@"sequelpro URL scheme command not supported.", @"sequelpro URL scheme command not supported.")]); - return; } + return; } if(passedProcessID && [passedProcessID length]) { @@ -723,10 +727,10 @@ usleep(5000); - [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@%@", SPURLSchemeQueryResultStatusPathHeader, passedProcessID] error:nil]; - [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@%@", SPURLSchemeQueryResultPathHeader, passedProcessID] error:nil]; - [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@%@", SPURLSchemeQueryResultMetaPathHeader, passedProcessID] error:nil]; - [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@%@", SPURLSchemeQueryInputPathHeader, passedProcessID] error:nil]; + [fm removeItemAtPath:[NSString stringWithFormat:@"%@%@", SPURLSchemeQueryResultStatusPathHeader, passedProcessID] error:nil]; + [fm removeItemAtPath:[NSString stringWithFormat:@"%@%@", SPURLSchemeQueryResultPathHeader, passedProcessID] error:nil]; + [fm removeItemAtPath:[NSString stringWithFormat:@"%@%@", SPURLSchemeQueryResultMetaPathHeader, passedProcessID] error:nil]; + [fm removeItemAtPath:[NSString stringWithFormat:@"%@%@", SPURLSchemeQueryInputPathHeader, passedProcessID] error:nil]; @@ -760,6 +764,7 @@ } if(!infoPath) { + NSLog(@"No path to Bundle command passed"); NSBeep(); return; } @@ -939,8 +944,6 @@ } } - // if(doc && [doc shellVariables]) [env addEntriesFromDictionary:[doc shellVariables]]; - // if(doc) [doc release]; id firstResponder = [[NSApp keyWindow] firstResponder]; if([firstResponder respondsToSelector:@selector(executeBundleItemForInputField:)]) { BOOL selfIsQueryEditor = ([[[firstResponder class] description] isEqualToString:@"SPTextView"]) ; @@ -1324,6 +1327,7 @@ - (IBAction)reloadBundles:(id)sender { + // Force releasing of any HTML output windows for(id c in bundleHTMLOutputController) { if(![[c window] isVisible]) { [c release]; -- cgit v1.2.3 From f682e2ea9ea4f96b1f395ceb166c7d2a59782c9d Mon Sep 17 00:00:00 2001 From: Bibiko Date: Mon, 10 Jan 2011 13:05:15 +0000 Subject: =?UTF-8?q?=E2=80=A2=20changed=20sequelpro=20URL=20command=20Synta?= =?UTF-8?q?xHighlighting=20to=20be=20connection=20independent=20-=20added?= =?UTF-8?q?=20example=20BASH=20script=20at=20http://www.sequelpro.com/docs?= =?UTF-8?q?/URL=5Fscheme=5Fsequelpro://=5FUsage#Use=5FSequel=5FPro=5Fto=5F?= =?UTF-8?q?do=5Fa=5Fsyntax=5Fhighlighting=5Fof=5Fa=5Fgiven=5FSQL=5Fquery?= =?UTF-8?q?=5FHTML=5Fformatted?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPAppController.m | 137 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) (limited to 'Source/SPAppController.m') diff --git a/Source/SPAppController.m b/Source/SPAppController.m index 38d8d54c..0e01c148 100644 --- a/Source/SPAppController.m +++ b/Source/SPAppController.m @@ -42,6 +42,19 @@ #import #import +#import "SPEditorTokens.h" + +#pragma mark lex init + +/* +* Include all the extern variables and prototypes required for flex (used for syntax highlighting) +*/ +extern NSUInteger yylex(); +extern NSUInteger yyuoffset, yyuleng; +typedef struct yy_buffer_state *YY_BUFFER_STATE; +void yy_switch_to_buffer(YY_BUFFER_STATE); +YY_BUFFER_STATE yy_scan_string (const char *); + @implementation SPAppController @synthesize lastBundleBlobFilesDirectory; @@ -665,6 +678,50 @@ return; } + if([command isEqualToString:@"SyntaxHighlighting"]) { + + BOOL isDir; + + NSString *anUUID = (passedProcessID && [passedProcessID length]) ? passedProcessID : @""; + NSString *queryFileName = [NSString stringWithFormat:@"%@%@", SPURLSchemeQueryInputPathHeader, anUUID]; + NSString *resultFileName = [NSString stringWithFormat:@"%@%@", SPURLSchemeQueryResultPathHeader, anUUID]; + NSString *metaFileName = [NSString stringWithFormat:@"%@%@", SPURLSchemeQueryResultMetaPathHeader, anUUID]; + NSString *statusFileName = [NSString stringWithFormat:@"%@%@", SPURLSchemeQueryResultStatusPathHeader, anUUID]; + + NSError *inError = nil; + NSString *query = [NSString stringWithContentsOfFile:queryFileName encoding:NSUTF8StringEncoding error:inError]; + NSString *result = @""; + NSString *status = @"0"; + + if([fm fileExistsAtPath:queryFileName isDirectory:&isDir] && !isDir) { + + if(inError == nil && query && [query length]) { + if([parameter count] > 0) { + if([[parameter lastObject] isEqualToString:@"html"]) + result = [NSString stringWithString:[self doSQLSyntaxHighlightForString:query cssLike:NO]]; + else if([[parameter lastObject] isEqualToString:@"htmlcss"]) + result = [NSString stringWithString:[self doSQLSyntaxHighlightForString:query cssLike:YES]]; + } + } + } + + [fm removeItemAtPath:queryFileName error:nil]; + [fm removeItemAtPath:resultFileName error:nil]; + [fm removeItemAtPath:metaFileName error:nil]; + [fm removeItemAtPath:statusFileName error:nil]; + + if(![result writeToFile:resultFileName atomically:YES encoding:NSUTF8StringEncoding error:nil]) + status = @"1"; + + // write status file as notification that query was finished + BOOL succeed = [status writeToFile:statusFileName atomically:YES encoding:NSUTF8StringEncoding error:nil]; + if(!succeed) { + NSBeep(); + SPBeginAlertSheet(NSLocalizedString(@"BASH Error", @"bash error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [self parentWindow], self, nil, nil, + NSLocalizedString(@"Status file for sequelpro url scheme command couldn't be written!", @"status file for sequelpro url scheme command couldn't be written error message")); + } + return; + } NSString *activeProcessID = [[[[self frontDocumentWindow] delegate] selectedTableDocument] processID]; @@ -749,6 +806,86 @@ } +/** + * Return an HTML formatted string representing the passed SQL string syntax highlighted + */ +- (NSString*)doSQLSyntaxHighlightForString:(NSString*)sqlText cssLike:(BOOL)cssLike +{ + + NSMutableString *sqlHTML = [[[NSMutableString alloc] initWithCapacity:[sqlText length]] autorelease]; + + NSRange textRange = NSMakeRange(0, [sqlText length]); + NSString *tokenColor; + NSString *cssId; + size_t token; + NSRange tokenRange; + + // initialise flex + yyuoffset = 0; yyuleng = 0; + yy_switch_to_buffer(yy_scan_string([sqlText UTF8String])); + BOOL skipFontTag; + + while (token=yylex()){ + skipFontTag = NO; + switch (token) { + case SPT_SINGLE_QUOTED_TEXT: + case SPT_DOUBLE_QUOTED_TEXT: + tokenColor = @"#A7221C"; + cssId = @"sp_sql_quoted"; + break; + case SPT_BACKTICK_QUOTED_TEXT: + tokenColor = @"#001892"; + cssId = @"sp_sql_backtick"; + break; + case SPT_RESERVED_WORD: + tokenColor = @"#0041F6"; + cssId = @"sp_sql_keyword"; + break; + case SPT_NUMERIC: + tokenColor = @"#67350F"; + cssId = @"sp_sql_numeric"; + break; + case SPT_COMMENT: + tokenColor = @"#265C10"; + cssId = @"sp_sql_comment"; + break; + case SPT_VARIABLE: + tokenColor = @"#6C6C6C"; + cssId = @"sp_sql_variable"; + break; + case SPT_WHITESPACE: + skipFontTag = YES; + cssId = @""; + break; + default: + skipFontTag = YES; + cssId = @""; + } + + tokenRange = NSMakeRange(yyuoffset, yyuleng); + + if(skipFontTag) + [sqlHTML appendString:[[sqlText substringWithRange:tokenRange] HTMLEscapeString]]; + else { + if(cssLike) + [sqlHTML appendFormat:@"%@", cssId, [[sqlText substringWithRange:tokenRange] HTMLEscapeString]]; + else + [sqlHTML appendFormat:@"%@", tokenColor, [[sqlText substringWithRange:tokenRange] HTMLEscapeString]]; + } + + } + + // Wrap lines, and replace tabs with spaces + [sqlHTML replaceOccurrencesOfString:@"\n" withString:@"
" options:NSLiteralSearch range:NSMakeRange(0, [sqlHTML length])]; + [sqlHTML replaceOccurrencesOfString:@"\t" withString:@"    " options:NSLiteralSearch range:NSMakeRange(0, [sqlHTML length])]; + + if(sqlHTML) + return sqlHTML; + else + return @""; + +} + - (IBAction)executeBundleItemForApp:(id)sender { -- cgit v1.2.3 From c2fa1986d547f524501a6ee01d95b0f6b0d85af7 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Wed, 12 Jan 2011 14:17:31 +0000 Subject: =?UTF-8?q?=E2=80=A2=20fixed=20issue=20for=20installing=20a=20Bund?= =?UTF-8?q?le=20if=20Sequel=20Pro=20didn't=20run,=20i.e.=20e.g.=20double-c?= =?UTF-8?q?lick=20in=20Finder=20at=20a=20spBundle=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPAppController.m | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'Source/SPAppController.m') diff --git a/Source/SPAppController.m b/Source/SPAppController.m index 0e01c148..ee400a06 100644 --- a/Source/SPAppController.m +++ b/Source/SPAppController.m @@ -552,6 +552,11 @@ YY_BUFFER_STATE yy_scan_string (const char *); 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") -- cgit v1.2.3 From 82fefc621680e1a3a7721b159239595364bd5e55 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Thu, 13 Jan 2011 08:50:41 +0000 Subject: =?UTF-8?q?=E2=80=A2=20fixed=20issue=20while=20updating=20a=20Bund?= =?UTF-8?q?le=20by=20identifying=20it=20via=20UUID=20but=20different=20spB?= =?UTF-8?q?undle=20file=20name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPAppController.m | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'Source/SPAppController.m') diff --git a/Source/SPAppController.m b/Source/SPAppController.m index ee400a06..7f405dba 100644 --- a/Source/SPAppController.m +++ b/Source/SPAppController.m @@ -568,10 +568,11 @@ YY_BUFFER_STATE yy_scan_string (const char *); NSInteger answer = [alert runModal]; if(answer == NSAlertDefaultReturn) { NSError *error = nil; - NSString *moveToTrashCommand = [NSString stringWithFormat:@"osascript -e 'tell application \"Finder\" to move (POSIX file \"%@\") to the trash'", newPath]; + NSString *removePath = [[[installedBundleUUIDs objectForKey:[cmdData objectForKey:SPBundleFileUUIDKey]] objectForKey:@"path"] substringToIndex:([[[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]; [moveToTrashCommand runBashCommandWithEnvironment:nil atCurrentDirectoryPath:nil error:&error]; if(error != nil) { - NSAlert *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."), [[installedBundleUUIDs objectForKey:[cmdData objectForKey:SPBundleFileUUIDKey]] objectForKey:@"path"]] + NSAlert *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 -- cgit v1.2.3 From ae9a0c3c701429a6e0cd379245a4690e1933818a Mon Sep 17 00:00:00 2001 From: Bibiko Date: Thu, 13 Jan 2011 10:51:41 +0000 Subject: =?UTF-8?q?=E2=80=A2=20improved=20error=20handling=20for=20sequelp?= =?UTF-8?q?ro=20URL=20scheme=20commands?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPAppController.m | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'Source/SPAppController.m') diff --git a/Source/SPAppController.m b/Source/SPAppController.m index 7f405dba..3a381fdb 100644 --- a/Source/SPAppController.m +++ b/Source/SPAppController.m @@ -767,9 +767,30 @@ YY_BUFFER_STATE yy_scan_string (const char *); } else { SPBeginAlertSheet(NSLocalizedString(@"sequelpro URL Scheme Error", @"sequelpro url Scheme Error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [NSApp mainWindow], self, nil, nil, [NSString stringWithFormat:@"%@ “%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [command description], NSLocalizedString(@"sequelpro URL scheme command not supported.", @"sequelpro URL scheme command not supported.")]); + + // If command failed notify the file handle hand shake mechanism + NSString *out = @"1"; + NSString *anUUID = @""; + if(command && passedProcessID && [passedProcessID length]) + anUUID = passedProcessID; + else + anUUID = command; + [out writeToFile:[NSString stringWithFormat:@"%@%@", SPURLSchemeQueryResultStatusPathHeader, anUUID] + atomically:YES + encoding:NSUTF8StringEncoding + error:nil]; + + out = @"Error"; + [out writeToFile:[NSString stringWithFormat:@"%@%@", SPURLSchemeQueryResultPathHeader, anUUID] + atomically:YES + encoding:NSUTF8StringEncoding + error:nil]; + } + return; + } if(passedProcessID && [passedProcessID length]) { -- cgit v1.2.3 From c352ef02ae0e81496c9db2b8973a8cdd43669366 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Fri, 14 Jan 2011 16:25:50 +0000 Subject: =?UTF-8?q?=E2=80=A2=20fixed=20issue=20for=20default=20Bundles=20i?= =?UTF-8?q?f=20category=20or=20key=20equivalent=20was=20changed=20by=20the?= =?UTF-8?q?=20user=20=E2=80=A2=20improved=20Format=20SQL=20Bundle=20-=20ad?= =?UTF-8?q?ded=20checking=20for=20empty=20passed=20SQL=20string=20-=20chan?= =?UTF-8?q?ged=20category=20to=20Format?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPAppController.m | 124 +++++++++++++++++++++++++---------------------- 1 file changed, 65 insertions(+), 59 deletions(-) (limited to 'Source/SPAppController.m') diff --git a/Source/SPAppController.m b/Source/SPAppController.m index 3a381fdb..a0e47137 100644 --- a/Source/SPAppController.m +++ b/Source/SPAppController.m @@ -1581,6 +1581,8 @@ YY_BUFFER_STATE yy_scan_string (const char *); && [cmdData objectForKey:SPBundleFileScopeKey]) { + BOOL defaultBundleWasUpdated = NO; + if([cmdData objectForKey:SPBundleFileUUIDKey] && [[cmdData objectForKey:SPBundleFileUUIDKey] length]) { if(processDefaultBundles) { @@ -1690,8 +1692,13 @@ YY_BUFFER_STATE yy_scan_string (const char *); continue; } infoPath = [NSString stringWithString:newInfoPath]; + + defaultBundleWasUpdated = YES; + } + if(!defaultBundleWasUpdated) continue; + } [installedBundleUUIDs setObject:[NSDictionary dictionaryWithObjectsAndKeys: @@ -1704,71 +1711,70 @@ YY_BUFFER_STATE yy_scan_string (const char *); continue; } - // Register Bundle - do it for default Bundles only while processDefaultBundles - if(![cmdData objectForKey:SPBundleFileIsDefaultBundleKey] || processDefaultBundles) { - NSString *scope = [cmdData objectForKey:SPBundleFileScopeKey]; + // Register Bundle + NSString *scope = [cmdData objectForKey:SPBundleFileScopeKey]; - // Register scope/category menu structure - if(![bundleUsedScopes containsObject:scope]) { - [bundleUsedScopes addObject:scope]; - [bundleItems setObject:[NSMutableArray array] forKey:scope]; - [bundleCategories setObject:[NSMutableArray array] forKey:scope]; - [bundleKeyEquivalents setObject:[NSMutableDictionary dictionary] forKey:scope]; - } - if([cmdData objectForKey:SPBundleFileCategoryKey] && [[cmdData objectForKey:SPBundleFileCategoryKey] length] && ![[bundleCategories objectForKey:scope] containsObject:[cmdData objectForKey:SPBundleFileCategoryKey]]) - [[bundleCategories objectForKey:scope] addObject:[cmdData objectForKey:SPBundleFileCategoryKey]]; - - NSMutableDictionary *aDict = [NSMutableDictionary dictionary]; - [aDict setObject:[cmdData objectForKey:SPBundleFileNameKey] forKey:SPBundleInternLabelKey]; - [aDict setObject:infoPath forKey:SPBundleInternPathToFileKey]; - - // Register trigger - if([cmdData objectForKey:SPBundleFileTriggerKey]) { - if(![bundleTriggers objectForKey:[cmdData objectForKey:SPBundleFileTriggerKey]]) - [bundleTriggers setObject:[NSMutableArray array] forKey:[cmdData objectForKey:SPBundleFileTriggerKey]]; - [[bundleTriggers objectForKey:[cmdData objectForKey:SPBundleFileTriggerKey]] addObject: - [NSString stringWithFormat:@"%@|%@|%@", - infoPath, - [cmdData objectForKey:SPBundleFileScopeKey], - ([[cmdData objectForKey:SPBundleFileOutputActionKey] isEqualToString:SPBundleOutputActionShowAsHTML])?[cmdData objectForKey:SPBundleFileUUIDKey]:@""]]; - } + // Register scope/category menu structure + if(![bundleUsedScopes containsObject:scope]) { + [bundleUsedScopes addObject:scope]; + [bundleItems setObject:[NSMutableArray array] forKey:scope]; + [bundleCategories setObject:[NSMutableArray array] forKey:scope]; + [bundleKeyEquivalents setObject:[NSMutableDictionary dictionary] forKey:scope]; + } + if([cmdData objectForKey:SPBundleFileCategoryKey] && [[cmdData objectForKey:SPBundleFileCategoryKey] length] && ![[bundleCategories objectForKey:scope] containsObject:[cmdData objectForKey:SPBundleFileCategoryKey]]) + [[bundleCategories objectForKey:scope] addObject:[cmdData objectForKey:SPBundleFileCategoryKey]]; + + NSMutableDictionary *aDict = [NSMutableDictionary dictionary]; + [aDict setObject:[cmdData objectForKey:SPBundleFileNameKey] forKey:SPBundleInternLabelKey]; + [aDict setObject:infoPath forKey:SPBundleInternPathToFileKey]; + + // Register trigger + if([cmdData objectForKey:SPBundleFileTriggerKey]) { + if(![bundleTriggers objectForKey:[cmdData objectForKey:SPBundleFileTriggerKey]]) + [bundleTriggers setObject:[NSMutableArray array] forKey:[cmdData objectForKey:SPBundleFileTriggerKey]]; + [[bundleTriggers objectForKey:[cmdData objectForKey:SPBundleFileTriggerKey]] addObject: + [NSString stringWithFormat:@"%@|%@|%@", + infoPath, + [cmdData objectForKey:SPBundleFileScopeKey], + ([[cmdData objectForKey:SPBundleFileOutputActionKey] isEqualToString:SPBundleOutputActionShowAsHTML])?[cmdData objectForKey:SPBundleFileUUIDKey]:@""]]; + } - // Register key equivalent - if([cmdData objectForKey:SPBundleFileKeyEquivalentKey] && [[cmdData objectForKey:SPBundleFileKeyEquivalentKey] length]) { - - NSString *theKey = [cmdData objectForKey:SPBundleFileKeyEquivalentKey]; - NSString *theChar = [theKey substringFromIndex:[theKey length]-1]; - NSString *theMods = [theKey substringToIndex:[theKey length]-1]; - NSUInteger mask = 0; - if([theMods rangeOfString:@"^"].length) mask = mask | NSControlKeyMask; - if([theMods rangeOfString:@"@"].length) mask = mask | NSCommandKeyMask; - if([theMods rangeOfString:@"~"].length) mask = mask | NSAlternateKeyMask; - if([theMods rangeOfString:@"$"].length) mask = mask | NSShiftKeyMask; - - if(![[bundleKeyEquivalents objectForKey:scope] objectForKey:[cmdData objectForKey:SPBundleFileKeyEquivalentKey]]) - [[bundleKeyEquivalents objectForKey:scope] setObject:[NSMutableArray array] forKey:[cmdData objectForKey:SPBundleFileKeyEquivalentKey]]; - - [[[bundleKeyEquivalents objectForKey:scope] objectForKey:[cmdData objectForKey:SPBundleFileKeyEquivalentKey]] addObject: - [NSDictionary dictionaryWithObjectsAndKeys: - infoPath, @"path", - [cmdData objectForKey:SPBundleFileNameKey], @"title", - ([cmdData objectForKey:SPBundleFileTooltipKey]) ?: @"", @"tooltip", - nil]]; - - [aDict setObject:[NSArray arrayWithObjects:theChar, [NSNumber numberWithInteger:mask], nil] forKey:SPBundleInternKeyEquivalentKey]; - } + // Register key equivalent + if([cmdData objectForKey:SPBundleFileKeyEquivalentKey] && [[cmdData objectForKey:SPBundleFileKeyEquivalentKey] length]) { + + NSString *theKey = [cmdData objectForKey:SPBundleFileKeyEquivalentKey]; + NSString *theChar = [theKey substringFromIndex:[theKey length]-1]; + NSString *theMods = [theKey substringToIndex:[theKey length]-1]; + NSUInteger mask = 0; + if([theMods rangeOfString:@"^"].length) mask = mask | NSControlKeyMask; + if([theMods rangeOfString:@"@"].length) mask = mask | NSCommandKeyMask; + if([theMods rangeOfString:@"~"].length) mask = mask | NSAlternateKeyMask; + if([theMods rangeOfString:@"$"].length) mask = mask | NSShiftKeyMask; + + if(![[bundleKeyEquivalents objectForKey:scope] objectForKey:[cmdData objectForKey:SPBundleFileKeyEquivalentKey]]) + [[bundleKeyEquivalents objectForKey:scope] setObject:[NSMutableArray array] forKey:[cmdData objectForKey:SPBundleFileKeyEquivalentKey]]; + + [[[bundleKeyEquivalents objectForKey:scope] objectForKey:[cmdData objectForKey:SPBundleFileKeyEquivalentKey]] addObject: + [NSDictionary dictionaryWithObjectsAndKeys: + infoPath, @"path", + [cmdData objectForKey:SPBundleFileNameKey], @"title", + ([cmdData objectForKey:SPBundleFileTooltipKey]) ?: @"", @"tooltip", + nil]]; + + [aDict setObject:[NSArray arrayWithObjects:theChar, [NSNumber numberWithInteger:mask], nil] forKey:SPBundleInternKeyEquivalentKey]; + } - if([cmdData objectForKey:SPBundleFileTooltipKey] && [[cmdData objectForKey:SPBundleFileTooltipKey] length]) - [aDict setObject:[cmdData objectForKey:SPBundleFileTooltipKey] forKey:SPBundleFileTooltipKey]; + if([cmdData objectForKey:SPBundleFileTooltipKey] && [[cmdData objectForKey:SPBundleFileTooltipKey] length]) + [aDict setObject:[cmdData objectForKey:SPBundleFileTooltipKey] forKey:SPBundleFileTooltipKey]; - if([cmdData objectForKey:SPBundleFileCategoryKey] && [[cmdData objectForKey:SPBundleFileCategoryKey] length]) - [aDict setObject:[cmdData objectForKey:SPBundleFileCategoryKey] forKey:SPBundleFileCategoryKey]; + if([cmdData objectForKey:SPBundleFileCategoryKey] && [[cmdData objectForKey:SPBundleFileCategoryKey] length]) + [aDict setObject:[cmdData objectForKey:SPBundleFileCategoryKey] forKey:SPBundleFileCategoryKey]; - if([cmdData objectForKey:SPBundleFileKeyEquivalentKey] && [[cmdData objectForKey:SPBundleFileKeyEquivalentKey] length]) - [aDict setObject:[cmdData objectForKey:SPBundleFileKeyEquivalentKey] forKey:@"key"]; + if([cmdData objectForKey:SPBundleFileKeyEquivalentKey] && [[cmdData objectForKey:SPBundleFileKeyEquivalentKey] length]) + [aDict setObject:[cmdData objectForKey:SPBundleFileKeyEquivalentKey] forKey:@"key"]; + + [[bundleItems objectForKey:scope] addObject:aDict]; - [[bundleItems objectForKey:scope] addObject:aDict]; - } } } -- cgit v1.2.3 From 6e2a43045f6f98c4fabf5a3358c2bdfdda2d6688 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Wed, 19 Jan 2011 12:35:17 +0000 Subject: =?UTF-8?q?=E2=80=A2=20fixed=20issue=20while=20updating=20Default?= =?UTF-8?q?=20Bundles=20for=20key=20equivalent=20=E2=80=A2=20improved=20JS?= =?UTF-8?q?ON=20Bundle=20commands=20-=20got=20rid=20of=20trailing=20whites?= =?UTF-8?q?paces=20inside=20data=20and=20as=20JSON=20object=20-=20added=20?= =?UTF-8?q?error=20handling=20for=20serialization=20a=20JSON=20object=20to?= =?UTF-8?q?=20suppress=20inserting=20of=20"null"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPAppController.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Source/SPAppController.m') diff --git a/Source/SPAppController.m b/Source/SPAppController.m index a0e47137..a38dc631 100644 --- a/Source/SPAppController.m +++ b/Source/SPAppController.m @@ -1754,7 +1754,8 @@ YY_BUFFER_STATE yy_scan_string (const char *); if(![[bundleKeyEquivalents objectForKey:scope] objectForKey:[cmdData objectForKey:SPBundleFileKeyEquivalentKey]]) [[bundleKeyEquivalents objectForKey:scope] setObject:[NSMutableArray array] forKey:[cmdData objectForKey:SPBundleFileKeyEquivalentKey]]; - [[[bundleKeyEquivalents objectForKey:scope] objectForKey:[cmdData objectForKey:SPBundleFileKeyEquivalentKey]] addObject: + if(!doBundleUpdate || (doBundleUpdate && (![[cmdData objectForKey:SPBundleFileIsDefaultBundleKey] boolValue] || processDefaultBundles))) + [[[bundleKeyEquivalents objectForKey:scope] objectForKey:[cmdData objectForKey:SPBundleFileKeyEquivalentKey]] addObject: [NSDictionary dictionaryWithObjectsAndKeys: infoPath, @"path", [cmdData objectForKey:SPBundleFileNameKey], @"title", -- cgit v1.2.3 From 79d5e103501c799c22dcb880e33fed0457d6ccd0 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Thu, 20 Jan 2011 09:10:57 +0000 Subject: =?UTF-8?q?=E2=80=A2=20show=20activity=20pane=20for=20running=20Bu?= =?UTF-8?q?ndle=20process=20automatically=20if=20the=20process=20runs=20lo?= =?UTF-8?q?nger=20than=201=20sec=20and=20hide=20it=20if=20no=20process=20r?= =?UTF-8?q?uns=20anymore=20to=20inform=20the=20user=20better?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPAppController.m | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'Source/SPAppController.m') diff --git a/Source/SPAppController.m b/Source/SPAppController.m index a38dc631..b0f5693e 100644 --- a/Source/SPAppController.m +++ b/Source/SPAppController.m @@ -1166,6 +1166,19 @@ YY_BUFFER_STATE yy_scan_string (const char *); { [runningActivitiesArray addObject:commandDict]; [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:SPActivitiesUpdateNotification object:nil]; + + SPDatabaseDocument* frontMostDoc = [self frontDocument]; + if(frontMostDoc) { + if([runningActivitiesArray count] || [[frontMostDoc runningActivities] count]) + [frontMostDoc performSelector:@selector(setActivityPaneHidden:) withObject:[NSNumber numberWithInteger:0] afterDelay:1.0]; + else { + [NSObject cancelPreviousPerformRequestsWithTarget:frontMostDoc + selector:@selector(setActivityPaneHidden:) + object:[NSNumber numberWithInteger:0]]; + [frontMostDoc setActivityPaneHidden:[NSNumber numberWithInteger:1]]; + } + } + } - (void)removeRegisteredActivity:(NSInteger)pid @@ -1176,7 +1189,20 @@ YY_BUFFER_STATE yy_scan_string (const char *); break; } } + [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:SPActivitiesUpdateNotification object:nil]; + + SPDatabaseDocument* frontMostDoc = [self frontDocument]; + if(frontMostDoc) { + if([runningActivitiesArray count] || [[frontMostDoc runningActivities] count]) + [frontMostDoc performSelector:@selector(setActivityPaneHidden:) withObject:[NSNumber numberWithInteger:0] afterDelay:1.0]; + else { + [NSObject cancelPreviousPerformRequestsWithTarget:frontMostDoc + selector:@selector(setActivityPaneHidden:) + object:[NSNumber numberWithInteger:0]]; + [frontMostDoc setActivityPaneHidden:[NSNumber numberWithInteger:1]]; + } + } } - (NSArray*)runningActivities -- cgit v1.2.3