aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-12-03 14:09:15 +0000
committerBibiko <bibiko@eva.mpg.de>2010-12-03 14:09:15 +0000
commit7387efe3ddd3ad7440d54ba1ab10e5806da63ba7 (patch)
tree9ac55cf34aff38cb9734bf80529224b4bc2e5e26
parent5c941dbdd8fb13c0938f03cc7902fa6d7a8a740d (diff)
downloadsequelpro-7387efe3ddd3ad7440d54ba1ab10e5806da63ba7.tar.gz
sequelpro-7387efe3ddd3ad7440d54ba1ab10e5806da63ba7.tar.bz2
sequelpro-7387efe3ddd3ad7440d54ba1ab10e5806da63ba7.zip
• further work on the choosMenuItem [not yet working]
-rw-r--r--Source/SPAppController.m167
-rw-r--r--Source/SPChooseMenuItemDialog.h8
-rw-r--r--Source/SPChooseMenuItemDialog.m64
3 files changed, 160 insertions, 79 deletions
diff --git a/Source/SPAppController.m b/Source/SPAppController.m
index 89a6359c..9b426ec7 100644
--- a/Source/SPAppController.m
+++ b/Source/SPAppController.m
@@ -1413,7 +1413,7 @@
// 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]) {
+ if([bundleKeyEquivalents objectForKey:SPBundleScopeGeneral] || [bundleKeyEquivalents objectForKey:SPBundleScopeDataTable] || [bundleKeyEquivalents objectForKey:SPBundleScopeInputField]) {
stopKeyDownListener = NO;
[self performSelector:@selector(keyDownListener) withObject:nil afterDelay:0.1];
}
@@ -1446,6 +1446,7 @@
*/
- (void)keyDownListener
{
+ return;
NSDictionary *keyEqsGeneral = [bundleKeyEquivalents objectForKey:SPBundleScopeGeneral];
NSDictionary *keyEqsDataTable = [bundleKeyEquivalents objectForKey:SPBundleScopeDataTable];
NSDictionary *keyEqsInputFields = [bundleKeyEquivalents objectForKey:SPBundleScopeInputField];
@@ -1456,86 +1457,96 @@
inMode:NSDefaultRunLoopMode
dequeue:YES];
if(!event) continue;
- if ([event type] == NSKeyDown
- && ![[[[[NSApp mainWindow] firstResponder] class] description] isEqualToString:@"SRRecorderControl"]
- && ![[[NSApp mainWindow] firstResponder] respondsToSelector:@selector(executeBundleItemForDataTable:)]
- && ![[[NSApp mainWindow] firstResponder] respondsToSelector:@selector(executeBundleItemForInputField:)]
- ) {
- // Check Bundle key equivalents due to same equivalents for Data Table scope
- NSString *charactersIgnMod = [event charactersIgnoringModifiers];
- long curFlags = ([event modifierFlags] & (NSShiftKeyMask|NSControlKeyMask|NSAlternateKeyMask|NSCommandKeyMask));
- BOOL found = NO;
- for(NSString *eqs in [keyEqsGeneral allKeys]) {
- NSInteger idx = 0;
- if([[keyEqsInputFields objectForKey:eqs] count] > 1) {
- // TODO
- }
- NSArray *eq = [[keyEqsDataTable objectForKey:eqs] objectAtIndex:idx];
- if(eq && [eq count] && [NSArrayObjectAtIndex(eq,0) isEqualToString:charactersIgnMod] && [NSArrayObjectAtIndex(eq,1) intValue] == curFlags) {
- NSMenuItem *aMenuItem = [[[NSMenuItem alloc] init] autorelease];
- [aMenuItem setTag:0];
- [aMenuItem setToolTip:[eq objectAtIndex:2]];
- [self executeBundleItemForApp:aMenuItem];
- found = YES;
- break;
- }
- }
- if(!found)
- [NSApp sendEvent:event];
- }
- else if ([event type] == NSKeyDown
- && ![[[[[NSApp mainWindow] firstResponder] class] description] isEqualToString:@"SRRecorderControl"]
- && [[[NSApp mainWindow] firstResponder] respondsToSelector:@selector(executeBundleItemForDataTable:)]
- ) {
- // Check Bundle key equivalents due to same equivalents for Data Table scope
- NSString *charactersIgnMod = [event charactersIgnoringModifiers];
- long curFlags = ([event modifierFlags] & (NSShiftKeyMask|NSControlKeyMask|NSAlternateKeyMask|NSCommandKeyMask));
- BOOL found = NO;
- for(NSString *eqs in [keyEqsDataTable allKeys]) {
- NSInteger idx = 0;
- if([[keyEqsInputFields objectForKey:eqs] count] > 1) {
- // TODO
- }
- NSArray *eq = [[keyEqsDataTable objectForKey:eqs] objectAtIndex:idx];
- if(eq && [eq count] && [NSArrayObjectAtIndex(eq,0) isEqualToString:charactersIgnMod] && [NSArrayObjectAtIndex(eq,1) intValue] == curFlags) {
- NSMenuItem *aMenuItem = [[[NSMenuItem alloc] init] autorelease];
- [aMenuItem setTag:0];
- [aMenuItem setToolTip:[eq objectAtIndex:2]];
- [[[NSApp mainWindow] firstResponder] executeBundleItemForDataTable:aMenuItem];
- found = YES;
- break;
- }
- }
- if(!found)
- [NSApp sendEvent:event];
- }
- else if ([event type] == NSKeyDown
- && ![[[[[NSApp mainWindow] firstResponder] class] description] isEqualToString:@"SRRecorderControl"]
- && [[[NSApp mainWindow] firstResponder] respondsToSelector:@selector(executeBundleItemForInputField:)]
- ) {
- // Check Bundle key equivalents due to same equivalents for Data Table scope
+
+ if ([event type] == NSKeyDown && ![[[[[NSApp mainWindow] firstResponder] class] description] isEqualToString:@"SRRecorderControl"]) {
NSString *charactersIgnMod = [event charactersIgnoringModifiers];
long curFlags = ([event modifierFlags] & (NSShiftKeyMask|NSControlKeyMask|NSAlternateKeyMask|NSCommandKeyMask));
- BOOL found = NO;
- for(NSString *eqs in [keyEqsInputFields allKeys]) {
- NSInteger idx = 0;
- if([[keyEqsInputFields objectForKey:eqs] count] > 1) {
- // TODO
- }
- NSArray *eq = [[keyEqsInputFields objectForKey:eqs] objectAtIndex:idx];
- if(eq && [eq count] && [NSArrayObjectAtIndex(eq,0) isEqualToString:charactersIgnMod] && [NSArrayObjectAtIndex(eq,1) intValue] == curFlags) {
- NSMenuItem *aMenuItem = [[[NSMenuItem alloc] init] autorelease];
- [aMenuItem setTag:0];
- [aMenuItem setToolTip:[eq objectAtIndex:2]];
- [[[NSApp mainWindow] firstResponder] executeBundleItemForInputField:aMenuItem];
- found = YES;
- break;
- }
- }
- if(!found)
+
+ 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];
+ }
+ 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];
+ }
+ 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 {
[NSApp sendEvent:event];
- }
- else {
+ }
+ } else {
[NSApp sendEvent:event];
}
usleep(1000);
diff --git a/Source/SPChooseMenuItemDialog.h b/Source/SPChooseMenuItemDialog.h
index 4b6f4a67..e268ab84 100644
--- a/Source/SPChooseMenuItemDialog.h
+++ b/Source/SPChooseMenuItemDialog.h
@@ -28,7 +28,13 @@
@interface SPChooseMenuItemDialog : NSWindow
{
-
+ NSMenu *contextMenu;
+ NSTextView *tv;
}
+@property(readwrite,retain) NSMenu* contextMenu;
+
+- (void)initMeWithOptions:(NSDictionary *)displayOptions;
++ (void)displayMenu:(NSMenu*)theMenu atPosition:(NSPoint)location;
+
@end
diff --git a/Source/SPChooseMenuItemDialog.m b/Source/SPChooseMenuItemDialog.m
index 2dc73077..e966613b 100644
--- a/Source/SPChooseMenuItemDialog.m
+++ b/Source/SPChooseMenuItemDialog.m
@@ -27,4 +27,68 @@
@implementation SPChooseMenuItemDialog
+@synthesize contextMenu;
+
+- (id)init;
+{
+ if(self = [self initWithContentRect:NSMakeRect(10,10,10,10)
+ styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO])
+ {
+ ;
+ }
+ return self;
+}
+
+- (void)dealloc
+{
+ [tv release];
+ [super dealloc];
+}
+
+- (void)initMeWithOptions:(NSDictionary *)displayOptions
+{
+ [self setReleasedWhenClosed:YES];
+ [self setLevel:NSNormalWindowLevel];
+ [self setHidesOnDeactivate:YES];
+ [self setHasShadow:YES];
+ [self setAlphaValue:0.9];
+ tv = [[NSTextView alloc] initWithFrame:NSMakeRect(10,10,10,10)];
+ [self setContentView:tv];
+ [tv setDelegate:self];
+ [tv setEditable:YES];
+}
+
++ (void)displayMenu:(NSMenu*)theMenu atPosition:(NSPoint)location
+{
+
+ SPChooseMenuItemDialog *dialog = [SPChooseMenuItemDialog new];
+ [dialog initMeWithOptions:nil];
+
+ NSMenuItem *returnItem = nil;
+
+ [dialog setContextMenu:theMenu];
+ [dialog setFrameTopLeftPoint:location];
+
+ [dialog orderFront:nil];
+ NSEvent *theEvent = [NSEvent
+ mouseEventWithType:NSRightMouseDown
+ location:NSMakePoint(1,1)
+ modifierFlags:0
+ timestamp:1
+ windowNumber:[dialog windowNumber]
+ context:[NSGraphicsContext currentContext]
+ eventNumber:1
+ clickCount:1
+ pressure:0.0];
+
+ [[NSApplication sharedApplication] postEvent:theEvent atStart:NO];
+
+}
+
+- (NSMenu *)menuForEvent:(NSEvent *)event
+{
+ NSLog(@"asdasdasd");
+ return contextMenu;
+}
+
@end