Updated loading of keybindings from files - hopefully the final version!

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@13950 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
nico 2002-06-22 18:05:37 +00:00
parent f29ff45de8
commit baa4e705db

View file

@ -339,8 +339,6 @@ static NSInputManager *currentInputManager = nil;
- (NSInputManager *) initWithName: (NSString *)inputServerName - (NSInputManager *) initWithName: (NSString *)inputServerName
host: (NSString *)hostName host: (NSString *)hostName
{ {
NSString *defaultKeyBindings;
NSArray *customKeyBindings;
NSUserDefaults *defaults; NSUserDefaults *defaults;
CREATE_AUTORELEASE_POOL (pool); CREATE_AUTORELEASE_POOL (pool);
@ -391,8 +389,6 @@ static NSInputManager *currentInputManager = nil;
} }
/* FIXME all the following is gonna change. */
/* Normally, when we start up, we load all the keybindings we find /* Normally, when we start up, we load all the keybindings we find
in the following files, in this order: in the following files, in this order:
@ -408,45 +404,47 @@ static NSInputManager *currentInputManager = nil;
with your own. These keybindings are normally used by all your with your own. These keybindings are normally used by all your
applications (this is why they are in 'DefaultKeyBindings'). applications (this is why they are in 'DefaultKeyBindings').
In addition, you can specify a list of additional key bindings You can change this behaviour, by setting the GSKeyBindingsFiles
files to be loaded by setting the GSCustomKeyBindings default to default to something else. The GSKeyBindingsFiles default
an array of file names. We will attempt to load all those contains an array of files which is loaded, in that order. Each
keybindings in a way similar to what we do with the file is searched first in GNUSTEP_SYSTEM_ROOT, then
DefaultKeyBindings. We load them after the default ones, in the GNUSTEP_LOCAL_ROOT, the GNUSTEP_NETWORK_ROOT, then
order you specify. This allows you to have application-specific GNUSTEP_USER_ROOT.
keybindings, where you put different keybindings in different
files, and run different applications with different
GSCustomKeyBindings, telling them to use different keybindings
files.
Last, in special cases you might want to have the Examples -
DefaultKeybindings totally ignored. In this case, you set the
GSDefaultKeyBindings variable to a different filename (different GSKeyBindingsFiles = (DefaultKeyBindings, NicolaKeyBindings);
from 'DefaultKeybindings'). We attempt to load all keybindings
stored in the files with that name where we normally would load will first load DefaultKeyBindings.dict (as by default), then
DefaultKeybindings. */ NicolaKeyBindings.dict.
GSKeyBindingsFiles = (NicolaKeyBindings);
will not load DefaultKeyBindings.dict but only
NicolaKeyBindings.dict.
The default of course is
GSKeyBindingsFiles = (DefaultKeyBindings);
*/
/* First, load the DefaultKeyBindings. */ /* First, load the DefaultKeyBindings. */
defaultKeyBindings = [defaults stringForKey: @"GSDefaultKeyBindings"]; {
NSArray *keyBindingsFiles = [defaults arrayForKey: @"GSKeyBindingsFiles"];
if (defaultKeyBindings == nil)
if (keyBindingsFiles == nil)
{
keyBindingsFiles = [NSArray arrayWithObject: @"DefaultKeyBindings"];
}
{ {
defaultKeyBindings = @"DefaultKeyBindings";
}
[self loadBindingsWithName: defaultKeyBindings];
/* Then, if any, the CustomKeyBindings, in the specified order. */
customKeyBindings = [defaults arrayForKey: @"GSCustomKeyBindings"];
if (customKeyBindings != nil)
{
int i, count = [customKeyBindings count];
Class string = [NSString class]; Class string = [NSString class];
int i;
for (i = 0; i < count; i++)
for (i = 0; i < [keyBindingsFiles count]; i++)
{ {
NSString *filename = [customKeyBindings objectAtIndex: i]; NSString *filename = [keyBindingsFiles objectAtIndex: i];
if ([filename isKindOfClass: string]) if ([filename isKindOfClass: string])
{ {
@ -454,6 +452,17 @@ static NSInputManager *currentInputManager = nil;
} }
} }
} }
}
/* Then, load any manually specified keybinding. */
{
NSDictionary *keyBindings = [defaults dictionaryForKey: @"GSKeyBindings"];
if ([keyBindings isKindOfClass: [NSDictionary class]])
{
[_rootBindingTable loadBindingsFromDictionary: keyBindings];
}
}
RELEASE (pool); RELEASE (pool);