mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-25 03:51:04 +00:00
Implemented support for describing multi-stroke keybindings using arrays
as keys git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@12870 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
4a7d40c11e
commit
ba83f4d1d6
3 changed files with 58 additions and 4 deletions
|
@ -1,3 +1,11 @@
|
|||
Wed Feb 27 23:50:42 2002 Nicola Pero <n.pero@mi.flashnet.it>
|
||||
|
||||
* Source/GSKeyBindingTable.m ([-bindKey:toAction:]): Implemented
|
||||
support for describing multi-stroke keybindings using arrays as
|
||||
keys.
|
||||
* Source/GSKeyBindingTable.h ([-bindKey:toAction:]): Now accepts
|
||||
an id as key.
|
||||
|
||||
Wed Feb 27 23:27:21 2002 Nicola Pero <n.pero@mi.flashnet.it>
|
||||
|
||||
* Source/GSKeyBindingTable.m ([-bindKey:toAction:]): Modified so
|
||||
|
|
|
@ -94,7 +94,7 @@ struct _GSKeyBinding
|
|||
* normally used by the NSInputManager to bind very special actions
|
||||
* such as Control-q (interpret literally next keystroke)].
|
||||
*/
|
||||
- (void) bindKey: (NSString *)key toAction: (id)action;
|
||||
- (void) bindKey: (id)key toAction: (id)action;
|
||||
|
||||
/* The input manager calls this when it wants to look up a keybinding
|
||||
* in the table. The method returns YES if the keybinding is in the
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
- (void) loadBindingsFromDictionary: (NSDictionary *)dict
|
||||
{
|
||||
NSEnumerator *e;
|
||||
NSString *key;
|
||||
id key;
|
||||
|
||||
e = [dict keyEnumerator];
|
||||
while ((key = [e nextObject]) != nil)
|
||||
|
@ -42,7 +42,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
- (void) bindKey: (NSString *)key toAction: (id)action
|
||||
- (void) bindKey: (id)key toAction: (id)action
|
||||
{
|
||||
unichar character;
|
||||
int modifiers;
|
||||
|
@ -50,8 +50,54 @@
|
|||
GSKeyBindingTable *t = nil;
|
||||
BOOL isTable = NO;
|
||||
int i;
|
||||
|
||||
/* First, try to determine what exactly is key :-) ... it might
|
||||
either be a simple string, "Control-f", or an array,
|
||||
("Control-x", "Control-s"). We implement the case of arrays in
|
||||
terms of the case of strings. */
|
||||
if ([key isKindOfClass: [NSArray class]])
|
||||
{
|
||||
if ([(NSArray *)key count] == 0)
|
||||
{
|
||||
/* Ignore them. */
|
||||
return;
|
||||
}
|
||||
else if ([(NSArray *)key count] == 1)
|
||||
{
|
||||
key = [key objectAtIndex: 0];
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Ok - simply convert that into a temporary dictionary
|
||||
representation and store that. Eg, key ("Control-x",
|
||||
"Control-s", "Control-k") action "moveUp:" gets converted
|
||||
into: key "Control-x" action { "Control-s" = {
|
||||
"Control-k" = "moveUp:"; }; }. */
|
||||
|
||||
/* Now start from the end of the array, and start building
|
||||
the temporary dictionary structure going backwards. */
|
||||
id value = action;
|
||||
int j;
|
||||
|
||||
for (j = [key count] - 1; j > 0; j--)
|
||||
{
|
||||
NSMutableDictionary *tmp = [NSMutableDictionary dictionary];
|
||||
[tmp setObject: value forKey: [key objectAtIndex: j]];
|
||||
value = tmp;
|
||||
}
|
||||
key = [key objectAtIndex: 0];
|
||||
action = value;
|
||||
}
|
||||
}
|
||||
|
||||
if (![NSInputManager parseKey: key
|
||||
|
||||
if (![key isKindOfClass: [NSString class]])
|
||||
{
|
||||
NSLog (@"GSKeyBindingTable - key %@ is not a NSString!", key);
|
||||
return;
|
||||
}
|
||||
|
||||
if (![NSInputManager parseKey: (NSString *)key
|
||||
intoCharacter: &character
|
||||
andModifiers: &modifiers])
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue