Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • keymap.c

    r8a921b5 r44cc9ab  
    11#include <string.h>
    22#include "owl.h"
     3
     4static void _owl_keymap_format_bindings(const owl_keymap *km, owl_fmtext *fm);
     5static void _owl_keymap_format_with_parents(const owl_keymap *km, owl_fmtext *fm);
    36
    47/* returns 0 on success */
     
    912  if ((km->desc = owl_strdup(desc)) == NULL) return(-1);
    1013  if (0 != owl_list_create(&km->bindings)) return(-1);
    11   km->submap = NULL;
     14  km->parent = NULL;
    1215  km->default_fn = default_fn;
    1316  km->prealways_fn = prealways_fn;
     
    2427}
    2528
    26 void owl_keymap_set_submap(owl_keymap *km, const owl_keymap *submap)
    27 {
    28   km->submap = submap;
     29void owl_keymap_set_parent(owl_keymap *km, const owl_keymap *parent)
     30{
     31  km->parent = parent;
    2932}
    3033
     
    8689
    8790/* Appends details about the keymap to fm */
    88 void owl_keymap_get_details(const owl_keymap *km, owl_fmtext *fm)
    89 {
    90   int i, nbindings;
    91   const owl_keybinding *kb;
    92  
     91void owl_keymap_get_details(const owl_keymap *km, owl_fmtext *fm, int recurse)
     92{
    9393  owl_fmtext_append_bold(fm, "KEYMAP - ");
    9494  owl_fmtext_append_bold(fm, km->name);
     
    9999    owl_fmtext_append_normal(fm, "\n");
    100100  }
    101   if (km->submap) {
    102     owl_fmtext_append_normal(fm, OWL_TABSTR "Has submap: ");
    103     owl_fmtext_append_normal(fm, km->submap->name);
     101  if (km->parent) {
     102    owl_fmtext_append_normal(fm, OWL_TABSTR "Has parent: ");
     103    owl_fmtext_append_normal(fm, km->parent->name);
    104104    owl_fmtext_append_normal(fm, "\n");
    105105  }
     
    119119
    120120  owl_fmtext_append_bold(fm, "\nKey bindings:\n\n"); 
     121  if (recurse) {
     122    _owl_keymap_format_with_parents(km, fm);
     123  } else {
     124    _owl_keymap_format_bindings(km, fm);
     125  }
     126}
     127
     128static void _owl_keymap_format_with_parents(const owl_keymap *km, owl_fmtext *fm)
     129{
     130  while (km) {
     131    _owl_keymap_format_bindings(km, fm);
     132    km = km->parent;
     133    if (km) {
     134      owl_fmtext_append_bold(fm, "\nInherited from ");
     135      owl_fmtext_append_bold(fm, km->name);
     136      owl_fmtext_append_bold(fm, ":\n\n");
     137    }
     138  }
     139}
     140
     141static void _owl_keymap_format_bindings(const owl_keymap *km, owl_fmtext *fm)
     142{
     143  int i, nbindings;
     144  const owl_keybinding *kb;
     145 
    121146  nbindings = owl_list_get_size(&km->bindings);
    122147  for (i=0; i<nbindings; i++) {
     
    248273  }
    249274
    250   /* deal with the always_fn for the map and submaps */
    251   for (km=kh->active; km; km=km->submap) {
     275  /* deal with the always_fn for the map and parents */
     276  for (km=kh->active; km; km=km->parent) {
    252277    if (km->prealways_fn) {
    253278      km->prealways_fn(j);
     
    256281
    257282  /* search for a match.  goes through active keymap and then
    258    * through submaps... TODO:  clean this up so we can pull
     283   * through parents... TODO:  clean this up so we can pull
    259284   * keyhandler and keymap apart.  */
    260   for (km=kh->active; km; km=km->submap) {
     285  for (km=kh->active; km; km=km->parent) {
    261286    for (i=owl_list_get_size(&km->bindings)-1; i>=0; i--) {
    262287      kb = owl_list_get_element(&km->bindings, i);
Note: See TracChangeset for help on using the changeset viewer.