On Fri, 4 Jul 2008 15:26:28 +0100, Nick Treleaven nick.treleaven@btinternet.com wrote:
On Fri, 4 Jul 2008 15:08:27 +0100 Nick Treleaven nick.treleaven@btinternet.com wrote:
...
To solve this, we could have the GEANY_KEYS_ commands share a single enum, but unsorted so we can append items as needed. All the group enums could be moved into keybindings.c, renaming them so all the existing code works without changes. The only function that would need updating would be keybindings_send_command(), plus storing the GEANY_KEYS_ enum value in each keybinding struct, so that function can find the callback.
To be clearer, user code would change, but not much of keybindings.c would require changes. As an example:
keybindings.h: enum CommonKeyIds {..., GEANY_KEYS_SOME_COMMAND, ...}
keybindings.c: enum KeyGroups {..., KEY_GROUP_SOME, ...} enum SomeGroupOrder {..., KEYS_SOME_COMMAND, ...}
keygroups[KEY_GROUP_SOME]->keys[KEYS_SOME_COMMAND]->id = GEANY_KEYS_SOME_COMMAND;
Then keybindings_send_command() would search for that id in keygroups[x]->keys[y]. Although that's a relatively slow search algorithm, it probably wouldn't matter here. If necessary it could be optimized to use a hash/lookup table.
My first thought was the search algorithm wouldn't matter at all as we don't have that many keybindings. But indeed, we have 110 (!) keybindings. Anyway, 100 integer comparisons aren't that expensive and should be ok at least for now. As you said, it could be improved later.
Regards, Enrico