Re: [RFC] Text Input Management System

From:

Nicola Pero

Subject:

Re: [RFC] Text Input Management System

Date:

Fri, 2 Apr 2004 11:56:48 +0100 (BST)

> Hi Nicola,
>
> When I read this first, it really got me mad. But I changed my mind when I
> read the last few lines. So I humbly ask you, please read this to the last
> line.
Ok. Welcome to online discussions :-)
Let me start again and see if I/we can do better this time.
I'm happy you're rewriting everything to support internationalized input,
which the existing code doesn't really support.
That *is* very cool. Thanks for that.
>From what you say, the only thing we have in the old implementation that I
would miss in the new one is the "user-friendly" key descriptions. (I
reiterate: _the only thing_, meaning I'm expecting everything else to be
better, which is a compliment btw). That was the only small detail where
I feel we were doing a bit better than our competition (Apple), so it
would be nice if you could preserve this functionality in your rewriting
... also because you can just cut&paste (&modify/&integrate) the existing
implementation, so there is no need to write a new parser. :-)
I apologize again for the lack of documentation on this existing format,
for the fact that I provided you with the documentation only in our last
emails, and for any misunderstandings this might have caused (NB: keep in
mind you're talking to someone from a completely different culture. If
you feel something I say is rude or aggressive, please reconsider as I've
never meant to be rude or aggressive or to depreciate your work. It might
just be that I present things in a different way - there are a few oceans
and continents between us, and I suspect that that does make a different
perception of how you discuss :-) .).
If you need a more explicit algorithm to do the parsing, I think the
existing code did contain one, anyway here it's a quick hack/sketch of one
(untested, pseudo-code etc) -
NSString *keyDescriptionToParse = (whatever you want to parse);
unsigned int modifierFlag = 0;
/* Loop on the key description string removing all prefixes Shift-,
* Alternate-, etc. until there are no more.
*/
while (1)
{
if ([keyDescriptionToParse hasPrefix: @"Shift-"])
{
modifierFlag &= NSShiftKeyMask;
keyDescriptionToParse = [keyDescriptionToParse substringFromIndex: 6];
}
else if ([keyDescriptionToParse hasPrefix: @"Alternate-"])
{
modifierFlag &= NSAlternateKeyMask;
keyDescriptionToParse = [keyDescriptionToParse substringFromIndex: 10];
}
else if ([keyDescriptionToParse hasPrefix: @"Control-"])
{
modifierFlag &= NSControlKeyMask;
keyDescriptionToParse = [keyDescriptionToParse substringFromIndex: 8];
}
else if ([keyDescriptionToParse hasPrefix: @"Command-"])
{
modifierFlag &= NSCommandKeyMask;
keyDescriptionToParse = [keyDescriptionToParse substringFromIndex: 8];
}
else if ([keyDescriptionToParse hasPrefix: @"NumericPad-"])
{
modifierFlag &= NSNumericPadKeyMask;
keyDescriptionToParse = [keyDescriptionToParse substringFromIndex: 11];
}
else
{
break;
}
}
/* Now modifierFlags contains the flags, and keyDescriptionToParse can be
* further parsed. To parse stuff like PageUp you just look it up in a
* lookup table.
*/
/* Now lookup in a lookup table the string you have. If it matches
* 'PageUp' or 'Home' or any of those, you set the key to
* NSPageUpFunctionKey etc. and finish. Here for example we assume
* the lookup table is a NSDictionary, but could be a hashtable of some
* sort.
*/
NSNumber *keyValue = [lookupTable objectForKey: keyDescriptionToParse];
if (keyValue != nil)
{
key = [keyValue intValue];
FINISH;
}
/* Now you interpret escape sequences and finish if you match. I don't
* remember how that is supposed to work, I think it's \031 or stuff
* like that to indicate the key with value 31 in C.
*/
if ([keyDescriptionToParse hasPrefix: @"\"])
{
key = [[keyDescriptionToParse substringFromIndex: 1] intValue];
if (key != 0)
{
FINISH;
}
}
/* Now you interpret the unicode characters literally. */
key = [keyDescriptionToParse characterAtIndex: 0];
FINISH;
Said that, I do think it's worth to have a key bindings file which is
human readable and that this was the only detail in which we did something
better than Apple, but I'm not going to stop sleeping if we don't have it.
Having exposed my case and suggestion, I think I'll fall into silence
again :-) and leave the decisions to whoever is going to process and
approve your patch.
Thanks for your time.