aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-11-17 12:08:13 +0000
committerBibiko <bibiko@eva.mpg.de>2010-11-17 12:08:13 +0000
commit16d98d9753198d9c654f18351f42131dc74516e1 (patch)
treeb836052c1f92c2a3029494976a22aec4c2f44de3 /Source
parentaa818d39f3437acdc28661700a4b0e5de8096815 (diff)
downloadsequelpro-16d98d9753198d9c654f18351f42131dc74516e1.tar.gz
sequelpro-16d98d9753198d9c654f18351f42131dc74516e1.tar.bz2
sequelpro-16d98d9753198d9c654f18351f42131dc74516e1.zip
• further work on Bundle Editor
Diffstat (limited to 'Source')
-rw-r--r--Source/SPAppController.m2
-rw-r--r--Source/SPBundleEditorController.h29
-rw-r--r--Source/SPBundleEditorController.m172
3 files changed, 201 insertions, 2 deletions
diff --git a/Source/SPAppController.m b/Source/SPAppController.m
index c3698db0..430587a0 100644
--- a/Source/SPAppController.m
+++ b/Source/SPAppController.m
@@ -872,7 +872,7 @@
if(bundlePath) {
NSError *error = nil;
NSArray *foundBundles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:bundlePath error:&error];
- if (foundBundles && [foundBundles count]) {
+ if (foundBundles && [foundBundles count] && error == nil) {
for(NSString* bundle in foundBundles) {
if(![[[bundle pathExtension] lowercaseString] isEqualToString:[SPUserBundleFileExtension lowercaseString]]) continue;
diff --git a/Source/SPBundleEditorController.h b/Source/SPBundleEditorController.h
index 4512cd56..8a2db321 100644
--- a/Source/SPBundleEditorController.h
+++ b/Source/SPBundleEditorController.h
@@ -24,9 +24,38 @@
#import <Cocoa/Cocoa.h>
+@class SRRecorderControl;
@interface SPBundleEditorController : NSWindowController {
+ IBOutlet NSTextView* commandTextView;
+ IBOutlet NSTableView* commandsTableView;
+ IBOutlet NSTextField* nameTextField;
+ IBOutlet NSTextField* tootlipTextField;
+ IBOutlet NSTextField* categoryTextField;
+ IBOutlet NSTextField* fallbackLabelField;
+ IBOutlet NSPopUpButton* inputPopupButton;
+ IBOutlet NSPopUpButton* inputFallbackPopupButton;
+ IBOutlet NSPopUpButton* outputPopupButton;
+ IBOutlet NSButton *editorScopeButton;
+ IBOutlet NSButton *inputFieldScopeButton;
+ IBOutlet NSButton *dataTableScopeButton;
+ IBOutlet NSButton *disableCheckBox;
+ IBOutlet SRRecorderControl *keyEquivalentField;
+
+ IBOutlet NSArrayController *commandBundleArrayController;
+ NSMutableArray *commandBundleArray;
+
+
}
+- (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;
+
+
@end
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