From 5c941dbdd8fb13c0938f03cc7902fa6d7a8a740d Mon Sep 17 00:00:00 2001 From: Bibiko Date: Fri, 3 Dec 2010 12:32:35 +0000 Subject: =?UTF-8?q?=E2=80=A2=20preparations=20for=20handling=20issue=20if?= =?UTF-8?q?=20user=20assigned=20the=20same=20keyboard=20short-cut=20on=20d?= =?UTF-8?q?ifferent=20Bundle=20commands;=20if=20so=20show=20a=20kind=20of?= =?UTF-8?q?=20a=20context=20menu=20to=20pick=20up=20one=20item;=20this=20w?= =?UTF-8?q?ill=20be=20done=20via=20the=20new=20SPChooseMenuItem=20class=20?= =?UTF-8?q?which=20will=20display=20a=20borderless=20window=20with=20a=20c?= =?UTF-8?q?ontext=20menu=20at=20a=20passed=20location?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPAppController.m | 53 +++++++++++++++++++++++++++++++++++------ Source/SPChooseMenuItemDialog.h | 34 ++++++++++++++++++++++++++ Source/SPChooseMenuItemDialog.m | 30 +++++++++++++++++++++++ 3 files changed, 110 insertions(+), 7 deletions(-) create mode 100644 Source/SPChooseMenuItemDialog.h create mode 100644 Source/SPChooseMenuItemDialog.m (limited to 'Source') diff --git a/Source/SPAppController.m b/Source/SPAppController.m index 2ff780ae..89a6359c 100644 --- a/Source/SPAppController.m +++ b/Source/SPAppController.m @@ -36,6 +36,7 @@ #import "SPTooltip.h" #import "SPBundleHTMLOutputController.h" #import "SPAlertSheets.h" +#import "SPChooseMenuItemDialog.h" #import #import @@ -1275,9 +1276,12 @@ mask = mask | NSAlternateKeyMask; if([theMods rangeOfString:@"$"].length) mask = mask | NSShiftKeyMask; - for(NSString* scope in scopes) - [[bundleKeyEquivalents objectForKey:scope] setObject:[NSArray arrayWithObjects:[theChar lowercaseString], - [NSNumber numberWithInteger:mask], infoPath, nil] forKey:[cmdData objectForKey:SPBundleFileKeyEquivalentKey]]; + 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]]; + } [aDict setObject:[NSArray arrayWithObjects:theChar, [NSNumber numberWithInteger:mask], nil] forKey:SPBundleInternKeyEquivalentKey]; } @@ -1444,6 +1448,7 @@ { NSDictionary *keyEqsGeneral = [bundleKeyEquivalents objectForKey:SPBundleScopeGeneral]; NSDictionary *keyEqsDataTable = [bundleKeyEquivalents objectForKey:SPBundleScopeDataTable]; + NSDictionary *keyEqsInputFields = [bundleKeyEquivalents objectForKey:SPBundleScopeInputField]; while(!stopKeyDownListener) { NSEvent* event = [NSApp nextEventMatchingMask:NSAnyEventMask @@ -1461,8 +1466,12 @@ long curFlags = ([event modifierFlags] & (NSShiftKeyMask|NSControlKeyMask|NSAlternateKeyMask|NSCommandKeyMask)); BOOL found = NO; for(NSString *eqs in [keyEqsGeneral allKeys]) { - NSArray *eq = [keyEqsGeneral objectForKey:eqs]; - if([NSArrayObjectAtIndex(eq,0) isEqualToString:charactersIgnMod] && [NSArrayObjectAtIndex(eq,1) intValue] == curFlags) { + 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]]; @@ -1483,8 +1492,12 @@ long curFlags = ([event modifierFlags] & (NSShiftKeyMask|NSControlKeyMask|NSAlternateKeyMask|NSCommandKeyMask)); BOOL found = NO; for(NSString *eqs in [keyEqsDataTable allKeys]) { - NSArray *eq = [keyEqsDataTable objectForKey:eqs]; - if([NSArrayObjectAtIndex(eq,0) isEqualToString:charactersIgnMod] && [NSArrayObjectAtIndex(eq,1) intValue] == curFlags) { + 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]]; @@ -1496,6 +1509,32 @@ 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 + 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) + [NSApp sendEvent:event]; + } else { [NSApp sendEvent:event]; } diff --git a/Source/SPChooseMenuItemDialog.h b/Source/SPChooseMenuItemDialog.h new file mode 100644 index 00000000..4b6f4a67 --- /dev/null +++ b/Source/SPChooseMenuItemDialog.h @@ -0,0 +1,34 @@ +// +// $Id: SPChooseMenuItemDialog.h 744 2009-05-22 20:00:00Z bibiko $ +// +// SPChooseMenuItemDialog.h +// sequel-pro +// +// Created by Hans-J. Bibiko on Dec 03, 2010. +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// More info at + +#import + + +@interface SPChooseMenuItemDialog : NSWindow + +{ + +} + +@end diff --git a/Source/SPChooseMenuItemDialog.m b/Source/SPChooseMenuItemDialog.m new file mode 100644 index 00000000..2dc73077 --- /dev/null +++ b/Source/SPChooseMenuItemDialog.m @@ -0,0 +1,30 @@ +// +// $Id: SPChooseMenuItemDialog.m 744 2009-05-22 20:00:00Z bibiko $ +// +// SPChooseMenuItemDialog.m +// sequel-pro +// +// Created by Hans-J. Bibiko on Dec 03, 2010. +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// More info at + +#import "SPChooseMenuItemDialog.h" + + +@implementation SPChooseMenuItemDialog + +@end -- cgit v1.2.3