Skip to content

Commit

Permalink
While we're at it, rename submap to parent
Browse files Browse the repository at this point in the history
Should be more consistent with other programs.

Signed-off-by: David Benjamin <davidben@mit.edu>
  • Loading branch information
davidben committed May 29, 2010
1 parent 13ebf92 commit 44cc9ab
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion doc/code.txt
Expand Up @@ -85,7 +85,7 @@ keymap: Contains both keymap and keyhandler. A keymap is contains a
bindings in keymaps. It also handles ESC as a prefix for
Meta. At any one time, there is exactly one active
keymap which determines where keybindings are looked for
(along with its submaps).
(along with its parents).

list: Simple list abstraction. (Uses realloc to resize the list.)

Expand Down
28 changes: 14 additions & 14 deletions keymap.c
Expand Up @@ -2,7 +2,7 @@
#include "owl.h"

static void _owl_keymap_format_bindings(const owl_keymap *km, owl_fmtext *fm);
static void _owl_keymap_format_with_submaps(const owl_keymap *km, owl_fmtext *fm);
static void _owl_keymap_format_with_parents(const owl_keymap *km, owl_fmtext *fm);

/* returns 0 on success */
int owl_keymap_init(owl_keymap *km, const char *name, const char *desc, void (*default_fn)(owl_input), void (*prealways_fn)(owl_input), void (*postalways_fn)(owl_input))
Expand All @@ -11,7 +11,7 @@ int owl_keymap_init(owl_keymap *km, const char *name, const char *desc, void (*d
if ((km->name = owl_strdup(name)) == NULL) return(-1);
if ((km->desc = owl_strdup(desc)) == NULL) return(-1);
if (0 != owl_list_create(&km->bindings)) return(-1);
km->submap = NULL;
km->parent = NULL;
km->default_fn = default_fn;
km->prealways_fn = prealways_fn;
km->postalways_fn = postalways_fn;
Expand All @@ -26,9 +26,9 @@ void owl_keymap_cleanup(owl_keymap *km)
owl_list_cleanup(&km->bindings, (void (*)(void *))owl_keybinding_delete);
}

void owl_keymap_set_submap(owl_keymap *km, const owl_keymap *submap)
void owl_keymap_set_parent(owl_keymap *km, const owl_keymap *parent)
{
km->submap = submap;
km->parent = parent;
}

/* creates and adds a key binding */
Expand Down Expand Up @@ -98,9 +98,9 @@ void owl_keymap_get_details(const owl_keymap *km, owl_fmtext *fm, int recurse)
owl_fmtext_append_normal(fm, km->desc);
owl_fmtext_append_normal(fm, "\n");
}
if (km->submap) {
owl_fmtext_append_normal(fm, OWL_TABSTR "Has submap: ");
owl_fmtext_append_normal(fm, km->submap->name);
if (km->parent) {
owl_fmtext_append_normal(fm, OWL_TABSTR "Has parent: ");
owl_fmtext_append_normal(fm, km->parent->name);
owl_fmtext_append_normal(fm, "\n");
}
owl_fmtext_append_normal(fm, "\n");
Expand All @@ -119,17 +119,17 @@ void owl_keymap_get_details(const owl_keymap *km, owl_fmtext *fm, int recurse)

owl_fmtext_append_bold(fm, "\nKey bindings:\n\n");
if (recurse) {
_owl_keymap_format_with_submaps(km, fm);
_owl_keymap_format_with_parents(km, fm);
} else {
_owl_keymap_format_bindings(km, fm);
}
}

static void _owl_keymap_format_with_submaps(const owl_keymap *km, owl_fmtext *fm)
static void _owl_keymap_format_with_parents(const owl_keymap *km, owl_fmtext *fm)
{
while (km) {
_owl_keymap_format_bindings(km, fm);
km = km->submap;
km = km->parent;
if (km) {
owl_fmtext_append_bold(fm, "\nInherited from ");
owl_fmtext_append_bold(fm, km->name);
Expand Down Expand Up @@ -272,17 +272,17 @@ int owl_keyhandler_process(owl_keyhandler *kh, owl_input j)
return(-1);
}

/* deal with the always_fn for the map and submaps */
for (km=kh->active; km; km=km->submap) {
/* deal with the always_fn for the map and parents */
for (km=kh->active; km; km=km->parent) {
if (km->prealways_fn) {
km->prealways_fn(j);
}
}

/* search for a match. goes through active keymap and then
* through submaps... TODO: clean this up so we can pull
* through parents... TODO: clean this up so we can pull
* keyhandler and keymap apart. */
for (km=kh->active; km; km=km->submap) {
for (km=kh->active; km; km=km->parent) {
for (i=owl_list_get_size(&km->bindings)-1; i>=0; i--) {
kb = owl_list_get_element(&km->bindings, i);
match = owl_keybinding_match(kb, kh);
Expand Down
12 changes: 6 additions & 6 deletions keys.c
Expand Up @@ -29,7 +29,7 @@ void owl_keys_setup_keymaps(owl_keyhandler *kh) {
km_editwin = km = owl_keyhandler_create_and_add_keymap(kh, "edit",
"Text editing and command window",
owl_keys_editwin_default, NULL, owl_keys_editwin_postalways);
owl_keymap_set_submap(km_editwin, km_global);
owl_keymap_set_parent(km_editwin, km_global);
/*
BIND_CMD("F1", "help", "");
BIND_CMD("HELP", "help", "");
Expand Down Expand Up @@ -98,7 +98,7 @@ void owl_keys_setup_keymaps(owl_keyhandler *kh) {
km_ew_multi = km = owl_keyhandler_create_and_add_keymap(kh, "editmulti",
"Multi-line text editing",
owl_keys_editwin_default, NULL, owl_keys_editwin_postalways);
owl_keymap_set_submap(km_ew_multi, km_editwin);
owl_keymap_set_parent(km_ew_multi, km_editwin);

BIND_CMD("UP", "edit:move-up-line", "");
BIND_CMD("M-[ A", "edit:move-up-line", "");
Expand Down Expand Up @@ -128,7 +128,7 @@ void owl_keys_setup_keymaps(owl_keyhandler *kh) {
km_ew_onel = km = owl_keyhandler_create_and_add_keymap(kh, "editline",
"Single-line text editing",
owl_keys_editwin_default, NULL, owl_keys_editwin_postalways);
owl_keymap_set_submap(km_ew_onel, km_editwin);
owl_keymap_set_parent(km_ew_onel, km_editwin);

BIND_CMD("C-u", "edit:delete-all", "Clears the entire line");

Expand All @@ -153,7 +153,7 @@ void owl_keys_setup_keymaps(owl_keyhandler *kh) {
km_ew_onel = km = owl_keyhandler_create_and_add_keymap(kh, "editresponse",
"Single-line response to question",
owl_keys_editwin_default, NULL, owl_keys_editwin_postalways);
owl_keymap_set_submap(km_ew_onel, km_editwin);
owl_keymap_set_parent(km_ew_onel, km_editwin);

BIND_CMD("C-u", "edit:delete-all", "Clears the entire line");

Expand All @@ -168,7 +168,7 @@ void owl_keys_setup_keymaps(owl_keyhandler *kh) {
km_viewwin = km = owl_keyhandler_create_and_add_keymap(kh, "popless",
"Pop-up window (eg, help)",
owl_keys_default_invalid, NULL, owl_keys_popless_postalways);
owl_keymap_set_submap(km_viewwin, km_global);
owl_keymap_set_parent(km_viewwin, km_global);

BIND_CMD("SPACE", "popless:scroll-down-page", "");
BIND_CMD("NPAGE", "popless:scroll-down-page", "");
Expand Down Expand Up @@ -221,7 +221,7 @@ void owl_keys_setup_keymaps(owl_keyhandler *kh) {
km_mainwin = km = owl_keyhandler_create_and_add_keymap(kh, "recv",
"Main window / message list",
owl_keys_default_invalid, owl_keys_recwin_prealways, NULL);
owl_keymap_set_submap(km_mainwin, km_global);
owl_keymap_set_parent(km_mainwin, km_global);
BIND_CMD("C-x C-c", "start-command quit", "");
BIND_CMD("F1", "help", "");
BIND_CMD("h", "help", "");
Expand Down
2 changes: 1 addition & 1 deletion owl.h
Expand Up @@ -475,7 +475,7 @@ typedef struct _owl_keymap {
char *name; /* name of keymap */
char *desc; /* description */
owl_list bindings; /* key bindings */
const struct _owl_keymap *submap; /* submap */
const struct _owl_keymap *parent; /* parent */
void (*default_fn)(owl_input j); /* default action (takes a keypress) */
void (*prealways_fn)(owl_input j); /* always called before a keypress is received */
void (*postalways_fn)(owl_input j); /* always called after keypress is processed */
Expand Down

0 comments on commit 44cc9ab

Please sign in to comment.