diff options
author | Bibiko <bibiko@eva.mpg.de> | 2010-11-17 12:08:13 +0000 |
---|---|---|
committer | Bibiko <bibiko@eva.mpg.de> | 2010-11-17 12:08:13 +0000 |
commit | 16d98d9753198d9c654f18351f42131dc74516e1 (patch) | |
tree | b836052c1f92c2a3029494976a22aec4c2f44de3 /Source/SPBundleEditorController.m | |
parent | aa818d39f3437acdc28661700a4b0e5de8096815 (diff) | |
download | sequelpro-16d98d9753198d9c654f18351f42131dc74516e1.tar.gz sequelpro-16d98d9753198d9c654f18351f42131dc74516e1.tar.bz2 sequelpro-16d98d9753198d9c654f18351f42131dc74516e1.zip |
• further work on Bundle Editor
Diffstat (limited to 'Source/SPBundleEditorController.m')
-rw-r--r-- | Source/SPBundleEditorController.m | 172 |
1 files changed, 171 insertions, 1 deletions
diff --git a/Source/SPBundleEditorController.m b/Source/SPBundleEditorController.m index 15cd58c2..cd5de5f9 100644 --- a/Source/SPBundleEditorController.m +++ b/Source/SPBundleEditorController.m @@ -32,7 +32,177 @@ */ - (id)init { - return [super initWithWindowNibName:@"BundleEditor"]; + + if ((self = [super initWithWindowNibName:@"BundleEditor"])) { + + commandBundleArray = [[NSMutableArray alloc] init]; + + } + + return self; + +} + +- (void)dealloc +{ + [commandBundleArray release]; + [super dealloc]; +} + +- (void)awakeFromNib +{ + NSString *bundlePath = [[NSFileManager defaultManager] applicationSupportDirectoryForSubDirectory:SPBundleSupportFolder createIfNotExists:NO error:nil]; + + if(bundlePath) { + NSError *error = nil; + NSArray *foundBundles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:bundlePath error:&error]; + if (foundBundles && [foundBundles count]) { + for(NSString* bundle in foundBundles) { + if(![[[bundle pathExtension] lowercaseString] isEqualToString:[SPUserBundleFileExtension lowercaseString]]) continue; + + 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] retain]; + + if(!cmdData || readError != nil || [convError length] || !(format == NSPropertyListXMLFormat_v1_0 || format == NSPropertyListBinaryFormat_v1_0)) { + NSLog(@"“%@/%@” file couldn't be read.", bundle, SPBundleFileName); + NSBeep(); + if (cmdData) [cmdData release]; + } else { + if([cmdData objectForKey:SPBundleFileNameKey] && [[cmdData objectForKey:SPBundleFileNameKey] length] && [cmdData objectForKey:SPBundleFileScopeKey]) + { + NSMutableDictionary *bundleCommand = [NSMutableDictionary dictionary]; + [bundleCommand addEntriesFromDictionary:cmdData]; + [bundleCommand setObject:[bundle stringByDeletingPathExtension] forKey:@"bundleName"]; + [commandBundleArray addObject:bundleCommand]; + } + if (cmdData) [cmdData release]; + } + } + } + } +} + +- (IBAction)scopeButtonChanged:(id)sender +{ + +} + +- (IBAction)inputPopuButtonChanged:(id)sender +{ + +} + +- (IBAction)duplicateCommandBundle:(id)sender +{ + +} + +- (IBAction)addCommandBundle:(id)sender +{ + +} + +- (IBAction)removeCommandBundle:(id)sender +{ + +} + +- (IBAction)revealCommandBundleInFinder:(id)sender +{ + +} + +- (IBAction)showHelp:(id)sender +{ + +} + +- (BOOL)windowShouldClose:(id)sender +{ + return YES; +} + +#pragma mark - +#pragma mark TableView datasource methods + +/** + * Returns the number of query commandBundleArray. + */ +- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView +{ + return [commandBundleArray count]; +} + +- (BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex +{ + return YES; +} + +/** + * Returns the value for the requested table column and row index. + */ +- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex +{ + + if([[aTableColumn identifier] isEqualToString:@"name"]) { + if(![[commandBundleArray objectAtIndex:rowIndex] objectForKey:@"name"]) return @"..."; + return [[commandBundleArray objectAtIndex:rowIndex] objectForKey:@"bundleName"]; + } + return @""; +} + +/* + * Save favorite names if inline edited (suppress empty names) + */ +- (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex +{ + + if([[aTableColumn identifier] isEqualToString:@"name"]) { + if([anObject isKindOfClass:[NSString class]] && [(NSString *)anObject length]) { + [[commandBundleArray objectAtIndex:rowIndex] setObject:anObject forKey:@"bundleName"]; + } + } + + [commandsTableView reloadData]; +} + +/* + * Changes in the name text field will be saved in data source directly + * to update the table view accordingly + */ +- (void)controlTextDidChange:(NSNotification *)notification +{ + + // Do nothing if no favorite is selected + if([commandsTableView numberOfSelectedRows] < 1) return; + + id object = [notification object]; + + if(object == nameTextField) { + [[commandBundleArray objectAtIndex:[commandsTableView selectedRow]] setObject:[nameTextField stringValue] forKey:@"name"]; + [commandsTableView reloadData]; + } + +} + +#pragma mark - +#pragma mark Menu validation + +/** + * Menu item validation. + */ +- (BOOL)validateMenuItem:(NSMenuItem *)menuItem +{ + + return YES; + } @end |