Changeset e4d7cb6


Ignore:
Timestamp:
Jun 25, 2011, 3:26:15 AM (6 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.8, release-1.9
Children:
d191f45
Parents:
f9df2f0
git-author:
David Benjamin <davidben@mit.edu> (03/10/11 15:02:58)
git-committer:
David Benjamin <davidben@mit.edu> (06/25/11 03:26:15)
Message:
Replace owl_keymap's list with a GPtrArray
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • keymap.c

    r6829afc re4d7cb6  
    1111  km->name = g_strdup(name);
    1212  km->desc = g_strdup(desc);
    13   owl_list_create(&km->bindings);
     13  km->bindings = g_ptr_array_new();
    1414  km->parent = NULL;
    1515  km->default_fn = default_fn;
     
    2424  g_free(km->name);
    2525  g_free(km->desc);
    26   owl_list_cleanup(&km->bindings, (void (*)(void *))owl_keybinding_delete);
     26  g_ptr_array_foreach(km->bindings, (GFunc)owl_keybinding_delete, NULL);
     27  g_ptr_array_free(km->bindings, true);
    2728}
    2829
     
    3536int owl_keymap_create_binding(owl_keymap *km, const char *keyseq, const char *command, void (*function_fn)(void), const char *desc)
    3637{
    37   owl_keybinding *kb, *curkb;
     38  owl_keybinding *kb;
    3839  int i;
    3940
     
    4445   * otherwise just add this one.
    4546   */
    46   for (i = owl_list_get_size(&km->bindings)-1; i>=0; i--) {
    47     curkb = owl_list_get_element(&km->bindings, i);
    48     if (owl_keybinding_equal(curkb, kb)) {
    49       owl_list_remove_element(&km->bindings, i);
    50       owl_keybinding_delete(curkb);
    51     }
    52   }
    53   owl_list_append_element(&km->bindings, kb);
     47  for (i = km->bindings->len-1; i >= 0; i--) {
     48    if (owl_keybinding_equal(km->bindings->pdata[i], kb)) {
     49      owl_keybinding_delete(g_ptr_array_remove_index(km->bindings, i));
     50    }
     51  }
     52  g_ptr_array_add(km->bindings, kb);
    5453  return 0;
    5554}
     
    5857int owl_keymap_remove_binding(owl_keymap *km, const char *keyseq)
    5958{
    60   owl_keybinding *kb, *curkb;
     59  owl_keybinding *kb;
    6160  int i;
    6261
     
    6564    return -1;
    6665
    67   for (i = owl_list_get_size(&km->bindings)-1; i >= 0; i--) {
    68     curkb = owl_list_get_element(&km->bindings, i);
    69     if (owl_keybinding_equal(curkb, kb)) {
    70       owl_list_remove_element(&km->bindings, i);
    71       owl_keybinding_delete(curkb);
     66  for (i = km->bindings->len-1; i >= 0; i--) {
     67    if (owl_keybinding_equal(km->bindings->pdata[i], kb)) {
     68      owl_keybinding_delete(g_ptr_array_remove_index(km->bindings, i));
    7269      owl_keybinding_delete(kb);
    7370      return(0);
     
    139136static void _owl_keymap_format_bindings(const owl_keymap *km, owl_fmtext *fm)
    140137{
    141   int i, nbindings;
     138  int i;
    142139  const owl_keybinding *kb;
    143140 
    144   nbindings = owl_list_get_size(&km->bindings);
    145   for (i=0; i<nbindings; i++) {
     141  for (i = 0; i < km->bindings->len; i++) {
    146142    char *kbstr;
    147143    const owl_cmd *cmd;
    148144    const char *tmpdesc, *desc = "";
    149145
    150     kb = owl_list_get_element(&km->bindings, i);
     146    kb = km->bindings->pdata[i];
    151147    kbstr = owl_keybinding_tostring(kb);
    152148    owl_fmtext_append_normal(fm, OWL_TABSTR);
     
    274270   * keyhandler and keymap apart.  */
    275271  for (km=kh->active; km; km=km->parent) {
    276     for (i=owl_list_get_size(&km->bindings)-1; i>=0; i--) {
    277       kb = owl_list_get_element(&km->bindings, i);
     272    for (i = km->bindings->len-1; i >= 0; i--) {
     273      kb = km->bindings->pdata[i];
    278274      match = owl_keybinding_match(kb, kh);
    279275      if (match == 1) {         /* subset match */
  • owl.h

    rf9df2f0 re4d7cb6  
    485485  char     *name;               /* name of keymap */
    486486  char     *desc;               /* description */
    487   owl_list  bindings;           /* key bindings */
     487  GPtrArray *bindings;          /* key bindings */
    488488  const struct _owl_keymap *parent;     /* parent */
    489489  void (*default_fn)(owl_input j);      /* default action (takes a keypress) */
Note: See TracChangeset for help on using the changeset viewer.