aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPAppController.m
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-12-06 08:58:38 +0000
committerBibiko <bibiko@eva.mpg.de>2010-12-06 08:58:38 +0000
commitdbbcc4144a7abef479ae9982563ed3a1cbdb725c (patch)
treedada74139078c8eaf3f33875993a73b4317b5e4d /Source/SPAppController.m
parent3de284fa904c295f306ec047fc29289399424836 (diff)
downloadsequelpro-dbbcc4144a7abef479ae9982563ed3a1cbdb725c.tar.gz
sequelpro-dbbcc4144a7abef479ae9982563ed3a1cbdb725c.tar.bz2
sequelpro-dbbcc4144a7abef479ae9982563ed3a1cbdb725c.zip
• finished implementation of SPChooseMenuItemDialog
• simplified bundle command handling and handling for bundle commands which have the same key equivalent to be able to group similar bundle commands • minor code improvements
Diffstat (limited to 'Source/SPAppController.m')
-rw-r--r--Source/SPAppController.m234
1 files changed, 105 insertions, 129 deletions
diff --git a/Source/SPAppController.m b/Source/SPAppController.m
index 9b426ec7..e4f632f4 100644
--- a/Source/SPAppController.m
+++ b/Source/SPAppController.m
@@ -43,6 +43,8 @@
@implementation SPAppController
+@synthesize lastBundleBlobFilesDirectory;
+
/**
* Initialise the application's main controller, setting itself as the app delegate.
*/
@@ -51,6 +53,7 @@
if ((self = [super init])) {
_sessionURL = nil;
aboutController = nil;
+ lastBundleBlobFilesDirectory = nil;
_spfSessionDocData = [[NSMutableDictionary alloc] init];
bundleItems = [[NSMutableDictionary alloc] initWithCapacity:1];
@@ -62,8 +65,6 @@
installedBundleUUIDs = [[NSMutableDictionary alloc] initWithCapacity:1];
runningActivitiesArray = [[NSMutableArray alloc] init];
- stopKeyDownListener = YES;
-
[NSApp setDelegate:self];
}
@@ -862,6 +863,7 @@
- (void)registerActivity:(NSDictionary*)commandDict
{
[runningActivitiesArray addObject:commandDict];
+ [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:SPActivitiesUpdateNotification object:nil];
}
- (void)removeRegisteredActivity:(NSInteger)pid
@@ -872,6 +874,7 @@
break;
}
}
+ [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:SPActivitiesUpdateNotification object:nil];
}
- (NSArray*)runningActivities
@@ -1192,8 +1195,6 @@
}
}
- stopKeyDownListener = YES;
-
BOOL foundInstalledBundles = NO;
[bundleItems removeAllObjects];
@@ -1279,9 +1280,18 @@
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:
- [NSArray arrayWithObjects:[theChar lowercaseString], [NSNumber numberWithInteger:mask], infoPath, [cmdData objectForKey:SPBundleFileNameKey], nil]];
+ [NSArray arrayWithObjects:
+ [theChar lowercaseString],
+ [NSNumber numberWithInteger:mask],
+ infoPath,
+ [cmdData objectForKey:SPBundleFileNameKey],
+ ([cmdData objectForKey:SPBundleFileTooltipKey]) ?: @"",
+ nil]];
+
}
+
[aDict setObject:[NSArray arrayWithObjects:theChar, [NSNumber numberWithInteger:mask], nil] forKey:SPBundleInternKeyEquivalentKey];
}
@@ -1294,6 +1304,7 @@
if([cmdData objectForKey:SPBundleFileCategoryKey] && [[cmdData objectForKey:SPBundleFileCategoryKey] length])
[aDict setObject:[cmdData objectForKey:SPBundleFileCategoryKey] forKey:SPBundleFileCategoryKey];
+ [aDict setObject:[cmdData objectForKey:SPBundleFileKeyEquivalentKey] forKey:@"key"];
for(NSString* scope in scopes)
[[bundleItems objectForKey:scope] addObject:aDict];
}
@@ -1398,7 +1409,9 @@
[mItem setToolTip:[item objectForKey:SPBundleFileTooltipKey]];
[mItem setTag:1000000 + i++];
- [mItem setRepresentedObject:scope];
+ [mItem setRepresentedObject:[NSDictionary dictionaryWithObjectsAndKeys:
+ scope, @"scope",
+ [item objectForKey:@"key"], @"key", nil]];
if([item objectForKey:SPBundleFileCategoryKey]) {
[[categoryMenus objectAtIndex:[bundleCategories indexOfObject:[item objectForKey:SPBundleFileCategoryKey]]] addItem:mItem];
@@ -1411,145 +1424,105 @@
k++;
}
- // Start General keyDown Listener if there're assigned Bundle commands
- // due to possible same key equivalent settings for differnet scopes
- if([bundleKeyEquivalents objectForKey:SPBundleScopeGeneral] || [bundleKeyEquivalents objectForKey:SPBundleScopeDataTable] || [bundleKeyEquivalents objectForKey:SPBundleScopeInputField]) {
- stopKeyDownListener = NO;
- [self performSelector:@selector(keyDownListener) withObject:nil afterDelay:0.1];
- }
-
-
}
/**
- * Action for any Bundle menu menuItem
+ * Action for any Bundle menu menuItem; show menuItem dialog if user pressed key equivalent
+ * which is assigned to more than one bundle command inside the same scope
*/
- (IBAction)bundleCommandDispatcher:(id)sender
{
- NSString *scope = [sender representedObject];
+
+ BOOL checkForKeyEquivalents = ([[NSApp currentEvent] type] == NSKeyDown) ? YES : NO;
+
+ NSString *scope = [[sender representedObject] objectForKey:@"scope"];
+ NSString *keyEqKey = [[sender representedObject] objectForKey:@"key"];
+ NSDictionary *assignedKeyEquivalents = [bundleKeyEquivalents objectForKey:scope];
+
id firstResponder = [[NSApp mainWindow] firstResponder];
+
if([scope isEqualToString:SPBundleScopeInputField] && [firstResponder respondsToSelector:@selector(executeBundleItemForInputField:)]) {
- [firstResponder executeBundleItemForInputField:sender];
+ if(checkForKeyEquivalents && [assignedKeyEquivalents objectForKey:keyEqKey]) {
+ NSInteger idx = 0;
+ if([[assignedKeyEquivalents objectForKey:keyEqKey] count] > 1) {
+ NSMutableArray *m = [NSMutableArray array];
+ NSInteger cnt = 0;
+ for(id i in [assignedKeyEquivalents objectForKey:keyEqKey]) {
+ [m addObject:[NSDictionary dictionaryWithObjectsAndKeys:
+ [i objectAtIndex:3], @"title",
+ [i objectAtIndex:4], @"tooltip",
+ nil]];
+ }
+ idx = [SPChooseMenuItemDialog withItems:m atPosition:[NSEvent mouseLocation]];
+ }
+ if(idx > -1) {
+ NSArray *eq = [[assignedKeyEquivalents objectForKey:keyEqKey] objectAtIndex:idx];
+ if(eq && [eq count]) {
+ NSMenuItem *aMenuItem = [[[NSMenuItem alloc] init] autorelease];
+ [aMenuItem setTag:0];
+ [aMenuItem setToolTip:[eq objectAtIndex:2]];
+ [[[NSApp mainWindow] firstResponder] executeBundleItemForInputField:aMenuItem];
+ }
+ }
+ } else {
+ [firstResponder executeBundleItemForInputField:sender];
+ }
}
else if([scope isEqualToString:SPBundleScopeDataTable] && [firstResponder respondsToSelector:@selector(executeBundleItemForDataTable:)]) {
- [firstResponder executeBundleItemForDataTable:sender];
- }
- else if([scope isEqualToString:SPBundleScopeGeneral]) {
- [self executeBundleItemForApp:sender];
- } else {
- NSBeep();
- }
-}
-
-/**
- * Listener for Bundle key equivalent due to same assigned equivalents
- */
-- (void)keyDownListener
-{
- return;
- NSDictionary *keyEqsGeneral = [bundleKeyEquivalents objectForKey:SPBundleScopeGeneral];
- NSDictionary *keyEqsDataTable = [bundleKeyEquivalents objectForKey:SPBundleScopeDataTable];
- NSDictionary *keyEqsInputFields = [bundleKeyEquivalents objectForKey:SPBundleScopeInputField];
-
- while(!stopKeyDownListener) {
- NSEvent* event = [NSApp nextEventMatchingMask:NSAnyEventMask
- untilDate:[NSDate distantFuture]
- inMode:NSDefaultRunLoopMode
- dequeue:YES];
- if(!event) continue;
-
- if ([event type] == NSKeyDown && ![[[[[NSApp mainWindow] firstResponder] class] description] isEqualToString:@"SRRecorderControl"]) {
- NSString *charactersIgnMod = [event charactersIgnoringModifiers];
- long curFlags = ([event modifierFlags] & (NSShiftKeyMask|NSControlKeyMask|NSAlternateKeyMask|NSCommandKeyMask));
-
- NSMutableString *keyEqKey = [NSMutableString string];
- [keyEqKey setString:@""];
- if(curFlags & NSControlKeyMask)
- [keyEqKey appendString:@"^"];
- if(curFlags & NSAlternateKeyMask)
- [keyEqKey appendString:@"~"];
- if(curFlags & NSShiftKeyMask)
- [keyEqKey appendString:@"$"];
- if(curFlags & NSCommandKeyMask)
- [keyEqKey appendString:@"@"];
- [keyEqKey appendString:[charactersIgnMod lowercaseString]];
-
- if (![[[NSApp mainWindow] firstResponder] respondsToSelector:@selector(executeBundleItemForDataTable:)]
- && ![[[NSApp mainWindow] firstResponder] respondsToSelector:@selector(executeBundleItemForInputField:)]) {
- BOOL found = NO;
- if([keyEqsGeneral objectForKey:keyEqKey]) {
- NSInteger idx = 0;
- if([[keyEqsInputFields objectForKey:keyEqKey] count] > 1) {
- // TODO
- } else {
- NSArray *eq = [[keyEqsInputFields objectForKey:keyEqKey] objectAtIndex:idx];
- if(eq && [eq count]) {
- NSMenuItem *aMenuItem = [[[NSMenuItem alloc] init] autorelease];
- [aMenuItem setTag:0];
- [aMenuItem setToolTip:[eq objectAtIndex:2]];
- [[[NSApp mainWindow] firstResponder] executeBundleItemForInputField:aMenuItem];
- found = YES;
- }
- }
- }
- if(!found)
- [NSApp sendEvent:event];
+ if(checkForKeyEquivalents && [assignedKeyEquivalents objectForKey:keyEqKey]) {
+ NSInteger idx = 0;
+ if([[assignedKeyEquivalents objectForKey:keyEqKey] count] > 1) {
+ NSMutableArray *m = [NSMutableArray array];
+ NSInteger cnt = 0;
+ for(id i in [assignedKeyEquivalents objectForKey:keyEqKey]) {
+ [m addObject:[NSDictionary dictionaryWithObjectsAndKeys:
+ [i objectAtIndex:3], @"title",
+ [i objectAtIndex:4], @"tooltip",
+ nil]];
+ }
+ idx = [SPChooseMenuItemDialog withItems:m atPosition:[NSEvent mouseLocation]];
}
- else if ([[[NSApp mainWindow] firstResponder] respondsToSelector:@selector(executeBundleItemForDataTable:)]) {
- BOOL found = NO;
- if([keyEqsDataTable objectForKey:keyEqKey]) {
- NSInteger idx = 0;
- if([[keyEqsInputFields objectForKey:keyEqKey] count] > 1) {
- // TODO
- } else {
- NSArray *eq = [[keyEqsInputFields objectForKey:keyEqKey] objectAtIndex:idx];
- if(eq && [eq count]) {
- NSMenuItem *aMenuItem = [[[NSMenuItem alloc] init] autorelease];
- [aMenuItem setTag:0];
- [aMenuItem setToolTip:[eq objectAtIndex:2]];
- [[[NSApp mainWindow] firstResponder] executeBundleItemForInputField:aMenuItem];
- found = YES;
- }
- }
- }
- if(!found)
- [NSApp sendEvent:event];
+ if(idx > -1) {
+ NSArray *eq = [[assignedKeyEquivalents objectForKey:keyEqKey] objectAtIndex:idx];
+ if(eq && [eq count]) {
+ NSMenuItem *aMenuItem = [[[NSMenuItem alloc] init] autorelease];
+ [aMenuItem setTag:0];
+ [aMenuItem setToolTip:[eq objectAtIndex:2]];
+ [[[NSApp mainWindow] firstResponder] executeBundleItemForDataTable:aMenuItem];
+ }
}
- else if ([[[NSApp mainWindow] firstResponder] respondsToSelector:@selector(executeBundleItemForInputField:)]) {
- BOOL found = NO;
- NSLog(@"%@", keyEqKey);
- if([keyEqsInputFields objectForKey:keyEqKey]) {
- NSInteger idx = 0;
- if([[keyEqsInputFields objectForKey:keyEqKey] count] > 1) {
- NSMenu *m = [[[NSMenu alloc] init] autorelease];
- NSInteger cnt = 0;
- for(id i in [keyEqsInputFields objectForKey:keyEqKey]) {
- NSMenuItem *aMenuItem = [[[NSMenuItem alloc] initWithTitle:[i objectAtIndex:2] action:nil keyEquivalent:@""] autorelease];
- [m addItem:aMenuItem];
- }
- [SPChooseMenuItemDialog displayMenu:m atPosition:[NSEvent mouseLocation]];
- found = YES;
- } else {
- NSArray *eq = [[keyEqsInputFields objectForKey:keyEqKey] objectAtIndex:idx];
- if(eq && [eq count]) {
- NSMenuItem *aMenuItem = [[[NSMenuItem alloc] init] autorelease];
- [aMenuItem setTag:0];
- [aMenuItem setToolTip:[eq objectAtIndex:2]];
- [[[NSApp mainWindow] firstResponder] executeBundleItemForInputField:aMenuItem];
- found = YES;
- }
- }
- }
- if(!found)
- [NSApp sendEvent:event];
+ } else {
+ [firstResponder executeBundleItemForDataTable:sender];
+ }
+ }
+ else if([scope isEqualToString:SPBundleScopeGeneral]) {
+ if(checkForKeyEquivalents && [assignedKeyEquivalents objectForKey:keyEqKey]) {
+ NSInteger idx = 0;
+ if([[assignedKeyEquivalents objectForKey:keyEqKey] count] > 1) {
+ NSMutableArray *m = [NSMutableArray array];
+ NSInteger cnt = 0;
+ for(id i in [assignedKeyEquivalents objectForKey:keyEqKey]) {
+ [m addObject:[NSDictionary dictionaryWithObjectsAndKeys:
+ [i objectAtIndex:3], @"title",
+ [i objectAtIndex:4], @"tooltip",
+ nil]];
+ }
+ idx = [SPChooseMenuItemDialog withItems:m atPosition:[NSEvent mouseLocation]];
}
- else {
- [NSApp sendEvent:event];
+ if(idx > -1) {
+ NSArray *eq = [[assignedKeyEquivalents objectForKey:keyEqKey] objectAtIndex:idx];
+ if(eq && [eq count]) {
+ NSMenuItem *aMenuItem = [[[NSMenuItem alloc] init] autorelease];
+ [aMenuItem setTag:0];
+ [aMenuItem setToolTip:[eq objectAtIndex:2]];
+ [[[NSApp mainWindow] firstResponder] executeBundleItemForApp:aMenuItem];
+ }
}
} else {
- [NSApp sendEvent:event];
+ [self executeBundleItemForApp:sender];
}
- usleep(1000);
+ } else {
+ NSBeep();
}
}
@@ -1733,6 +1706,9 @@
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
{
+ if(lastBundleBlobFilesDirectory != nil)
+ [[NSFileManager defaultManager] removeItemAtPath:lastBundleBlobFilesDirectory error:nil];
+
// Kill all registered BASH commands
for (NSWindow *aWindow in [NSApp orderedWindows]) {
if([[aWindow windowController] isMemberOfClass:[SPWindowController class]]) {