Loading of user-configurable keys implemented

This commit is contained in:
Frederic Culot 2008-11-09 20:10:18 +00:00
parent f845721828
commit e8f12c65ca
12 changed files with 321 additions and 117 deletions

View File

@ -1,3 +1,10 @@
2008-11-09 Frederic Culot <frederic@culot.org>
* src/io.c (io_load_keys, key_to_ascii): new function
* src/keys.c (keys_assign_binding, keys_remove_binding)
(keys_get_key): new functions
2008-11-08 Frederic Culot <frederic@culot.org> 2008-11-08 Frederic Culot <frederic@culot.org>
* src/keys.[ch]: new files to manage user-definable keybindings * src/keys.[ch]: new files to manage user-definable keybindings

View File

@ -1,4 +1,4 @@
/* $calcurse: calcurse.c,v 1.68 2008/09/21 08:06:43 culot Exp $ */ /* $calcurse: calcurse.c,v 1.69 2008/11/09 20:10:18 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -41,7 +41,7 @@
#include "todo.h" #include "todo.h"
#include "args.h" #include "args.h"
#include "notify.h" #include "notify.h"
#include "keys.h"
/* /*
* Calcurse is a text-based personal organizer which helps keeping track * Calcurse is a text-based personal organizer which helps keeping track
@ -55,7 +55,7 @@ main (int argc, char **argv)
{ {
conf_t conf; conf_t conf;
day_items_nb_t inday; day_items_nb_t inday;
int ch, background, foreground; int background, foreground;
int non_interactive; int non_interactive;
int no_data_file = 1; int no_data_file = 1;
int sav_hilt_app = 0; int sav_hilt_app = 0;
@ -146,6 +146,7 @@ main (int argc, char **argv)
no_data_file = io_check_data_files (); no_data_file = io_check_data_files ();
custom_load_conf (&conf, background); custom_load_conf (&conf, background);
erase_status_bar (); erase_status_bar ();
io_load_keys ();
io_load_todo (); io_load_todo ();
io_load_app (); io_load_app ();
wins_reinit (); wins_reinit ();
@ -161,23 +162,29 @@ main (int argc, char **argv)
/* User input */ /* User input */
for (;;) for (;;)
{ {
int ch, key;
do_update = true; do_update = true;
ch = wgetch (win[STA].p); ch = wgetch (win[STA].p);
switch (ch) key = keys_get_key (ch);
if (key == -1)
key = ch;
switch (key)
{ {
case ERR: case ERR:
do_update = false; do_update = false;
break; break;
case CTRL ('R'): case KEY_GENERIC_REDRAW:
case KEY_RESIZE: case KEY_RESIZE:
do_update = false; do_update = false;
wins_reset (); wins_reset ();
break; break;
case 9: /* The TAB key was hit. */ case KEY_GENERIC_CHANGE_VIEW:
reset_status_page (); reset_status_page ();
/* Save previously highlighted event. */ /* Need to save the previously highlighted event. */
switch (wins_slctd ()) switch (wins_slctd ())
{ {
case TOD: case TOD:
@ -214,17 +221,15 @@ main (int argc, char **argv)
} }
break; break;
case 'O': case KEY_GENERIC_OTHER_CMD:
case 'o':
other_status_page (wins_slctd ()); other_status_page (wins_slctd ());
break; break;
case CTRL ('G'): case KEY_GENERIC_GOTO:
case 'G': case KEY_GENERIC_GOTO_TODAY:
case 'g': /* Goto function */
erase_status_bar (); erase_status_bar ();
calendar_set_current_date (); calendar_set_current_date ();
if (ch == CTRL ('G')) if (ch == KEY_GENERIC_GOTO_TODAY)
calendar_goto_today (); calendar_goto_today ();
else else
calendar_change_day (conf.input_datefmt); calendar_change_day (conf.input_datefmt);
@ -232,16 +237,15 @@ main (int argc, char **argv)
day_changed = true; day_changed = true;
break; break;
case 'V': case KEY_APT_VIEW_ITEM:
case 'v': /* View function */ case KEY_TODO_VIEW_ITEM:
if ((wins_slctd () == APP) && (apoint_hilt () != 0)) if ((wins_slctd () == APP) && (apoint_hilt () != 0))
day_popup_item (); day_popup_item ();
else if ((wins_slctd () == TOD) && (todo_hilt () != 0)) else if ((wins_slctd () == TOD) && (todo_hilt () != 0))
item_in_popup (NULL, NULL, todo_saved_mesg (), _("To do :")); item_in_popup (NULL, NULL, todo_saved_mesg (), _("To do :"));
break; break;
case 'C': case KEY_GENERIC_CONFIG_MENU:
case 'c': /* Configuration menu */
erase_status_bar (); erase_status_bar ();
config_bar (); config_bar ();
while ((ch = wgetch (win[STA].p)) != 'q') while ((ch = wgetch (win[STA].p)) != 'q')
@ -282,19 +286,19 @@ main (int argc, char **argv)
wins_update (); wins_update ();
break; break;
case CTRL ('A'): /* Add an app, whatever panel selected */ case KEY_GENERIC_ADD_APPT:
apoint_add (); apoint_add ();
do_storage = true; do_storage = true;
break; break;
case CTRL ('T'): /* Add a todo, whatever panel selected */ case KEY_GENERIC_ADD_TODO:
todo_new_item (); todo_new_item ();
if (todo_hilt () == 0 && todo_nb () == 1) if (todo_hilt () == 0 && todo_nb () == 1)
todo_hilt_increase (); todo_hilt_increase ();
break; break;
case 'A': case KEY_APT_ADD_ITEM:
case 'a': /* Add an item */ case KEY_TODO_ADD_ITEM:
switch (wins_slctd ()) switch (wins_slctd ())
{ {
case APP: case APP:
@ -311,8 +315,8 @@ main (int argc, char **argv)
} }
break; break;
case 'E': case KEY_APT_EDIT_ITEM:
case 'e': /* Edit an existing item */ case KEY_TODO_EDIT_ITEM:
if (wins_slctd () == APP && apoint_hilt () != 0) if (wins_slctd () == APP && apoint_hilt () != 0)
day_edit_item (&conf); day_edit_item (&conf);
else if (wins_slctd () == TOD && todo_hilt () != 0) else if (wins_slctd () == TOD && todo_hilt () != 0)
@ -320,8 +324,8 @@ main (int argc, char **argv)
do_storage = true; do_storage = true;
break; break;
case 'D': case KEY_APT_DEL_ITEM:
case 'd': /* Delete an item */ case KEY_TODO_DEL_ITEM:
if (wins_slctd () == APP && apoint_hilt () != 0) if (wins_slctd () == APP && apoint_hilt () != 0)
apoint_delete (&conf, &inday.nb_events, &inday.nb_apoints); apoint_delete (&conf, &inday.nb_events, &inday.nb_apoints);
else if (wins_slctd () == TOD && todo_hilt () != 0) else if (wins_slctd () == TOD && todo_hilt () != 0)
@ -329,24 +333,23 @@ main (int argc, char **argv)
do_storage = true; do_storage = true;
break; break;
case 'R': case KEY_APT_REPEAT:
case 'r':
if (wins_slctd () == APP && apoint_hilt () != 0) if (wins_slctd () == APP && apoint_hilt () != 0)
recur_repeat_item (&conf); recur_repeat_item (&conf);
do_storage = true; do_storage = true;
break; break;
case '!': case KEY_APT_FLAG_ITEM:
if (wins_slctd () == APP && apoint_hilt () != 0) if (wins_slctd () == APP && apoint_hilt () != 0)
apoint_switch_notify (); apoint_switch_notify ();
do_storage = true; do_storage = true;
break; break;
case '+': case KEY_TODO_RAISE_PRIORITY:
case '-': case KEY_TODO_LOWER_PRIORITY:
if (wins_slctd () == TOD && todo_hilt () != 0) if (wins_slctd () == TOD && todo_hilt () != 0)
{ {
todo_chg_priority (ch); todo_chg_priority (key);
if (todo_hilt_pos () < 0) if (todo_hilt_pos () < 0)
todo_set_first (todo_hilt ()); todo_set_first (todo_hilt ());
else if (todo_hilt_pos () >= win[TOD].h - 4) else if (todo_hilt_pos () >= win[TOD].h - 4)
@ -354,9 +357,8 @@ main (int argc, char **argv)
} }
break; break;
case 'N': case KEY_APT_EDIT_NOTE:
case 'n': case KEY_TODO_EDIT_NOTE:
/* Attach a note to an item, create it if necessary */
if (wins_slctd () == APP && apoint_hilt () != 0) if (wins_slctd () == APP && apoint_hilt () != 0)
day_edit_note (conf.editor); day_edit_note (conf.editor);
else if (wins_slctd () == TOD && todo_hilt () != 0) else if (wins_slctd () == TOD && todo_hilt () != 0)
@ -364,33 +366,30 @@ main (int argc, char **argv)
do_storage = true; do_storage = true;
break; break;
case '>': case KEY_APT_VIEW_NOTE:
/* View a note previously attached to an item */ case KEY_TODO_VIEW_NOTE:
if (wins_slctd () == APP && apoint_hilt () != 0) if (wins_slctd () == APP && apoint_hilt () != 0)
day_view_note (conf.pager); day_view_note (conf.pager);
else if (wins_slctd () == TOD && todo_hilt () != 0) else if (wins_slctd () == TOD && todo_hilt () != 0)
todo_view_note (conf.pager); todo_view_note (conf.pager);
break; break;
case '?': /* Online help system */ case KEY_GENERIC_HELP:
status_bar (); status_bar ();
help_screen (); help_screen ();
break; break;
case 'S': case KEY_GENERIC_SAVE:
case 's': /* Save function */
io_save_cal (IO_MODE_INTERACTIVE, &conf); io_save_cal (IO_MODE_INTERACTIVE, &conf);
break; break;
case 'I': case KEY_GENERIC_IMPORT:
case 'i': /* Import function */
erase_status_bar (); erase_status_bar ();
io_import_data (IO_MODE_INTERACTIVE, IO_IMPORT_ICAL, &conf, NULL); io_import_data (IO_MODE_INTERACTIVE, IO_IMPORT_ICAL, &conf, NULL);
do_storage = true; do_storage = true;
break; break;
case 'X': case KEY_GENERIC_EXPORT:
case 'x': /* Export function */
erase_status_bar (); erase_status_bar ();
io_export_bar (); io_export_bar ();
while ((ch = wgetch (win[STA].p)) != 'q') while ((ch = wgetch (win[STA].p)) != 'q')
@ -415,11 +414,9 @@ main (int argc, char **argv)
wins_update (); wins_update ();
break; break;
case KEY_RIGHT: case KEY_GENERIC_NEXT_DAY:
case ('L'): case KEY_CAL_NEXT_DAY:
case ('l'): if (wins_slctd () == CAL || key == KEY_GENERIC_NEXT_DAY)
case CTRL ('L'):
if (wins_slctd () == CAL || ch == CTRL ('L'))
{ {
do_storage = true; do_storage = true;
day_changed = true; day_changed = true;
@ -427,11 +424,9 @@ main (int argc, char **argv)
} }
break; break;
case KEY_LEFT: case KEY_GENERIC_PREV_DAY:
case ('H'): case KEY_CAL_PREV_DAY:
case ('h'): if (wins_slctd () == CAL || key == KEY_GENERIC_PREV_DAY)
case CTRL ('H'):
if (wins_slctd () == CAL || ch == CTRL ('H'))
{ {
do_storage = true; do_storage = true;
day_changed = true; day_changed = true;
@ -439,60 +434,62 @@ main (int argc, char **argv)
} }
break; break;
case KEY_UP: case KEY_GENERIC_PREV_WEEK:
case ('K'): case KEY_CAL_PREV_WEEK:
case ('k'): if (wins_slctd () == CAL || key == KEY_GENERIC_PREV_WEEK)
case CTRL ('K'):
if (wins_slctd () == CAL || ch == CTRL ('K'))
{ {
do_storage = true; do_storage = true;
day_changed = true; day_changed = true;
calendar_move (UP); calendar_move (UP);
} }
else break;
{
if ((wins_slctd () == APP) && (apoint_hilt () > 1))
{
apoint_hilt_decrease ();
apoint_scroll_pad_up (inday.nb_events);
}
else if ((wins_slctd () == TOD) && (todo_hilt () > 1))
{
todo_hilt_decrease ();
if (todo_hilt_pos () < 0)
todo_first_decrease ();
}
}
break;
case KEY_DOWN: case KEY_GENERIC_NEXT_WEEK:
case ('J'): case KEY_CAL_NEXT_WEEK:
case ('j'): if (wins_slctd () == CAL || key == KEY_GENERIC_NEXT_WEEK)
case CTRL ('J'):
if (wins_slctd () == CAL || ch == CTRL ('J'))
{ {
do_storage = true; do_storage = true;
day_changed = true; day_changed = true;
calendar_move (DOWN); calendar_move (DOWN);
} }
else break;
{
if ((wins_slctd () == APP) && case KEY_APT_MOVE_UP:
(apoint_hilt () < inday.nb_events + inday.nb_apoints)) if ((wins_slctd () == APP) && (apoint_hilt () > 1))
{ {
apoint_hilt_increase (); apoint_hilt_decrease ();
apoint_scroll_pad_down (inday.nb_events, win[APP].h); apoint_scroll_pad_up (inday.nb_events);
} }
if ((wins_slctd () == TOD) && (todo_hilt () < todo_nb ())) break;
{
todo_hilt_increase (); case KEY_APT_MOVE_DOWN:
if (todo_hilt_pos () == win[TOD].h - 4) if ((wins_slctd () == APP) &&
todo_first_increase (); (apoint_hilt () < inday.nb_events + inday.nb_apoints))
} {
} apoint_hilt_increase ();
apoint_scroll_pad_down (inday.nb_events, win[APP].h);
}
break;
case KEY_TODO_MOVE_UP:
if ((wins_slctd () == TOD) && (todo_hilt () > 1))
{
todo_hilt_decrease ();
if (todo_hilt_pos () < 0)
todo_first_decrease ();
}
break; break;
case '0': case KEY_TODO_MOVE_DOWN:
if ((wins_slctd () == TOD) && (todo_hilt () < todo_nb ()))
{
todo_hilt_increase ();
if (todo_hilt_pos () == win[TOD].h - 4)
todo_first_increase ();
}
break;
case KEY_CAL_START_OF_WEEK:
if (wins_slctd () == CAL) if (wins_slctd () == CAL)
{ {
do_storage = true; do_storage = true;
@ -501,7 +498,7 @@ main (int argc, char **argv)
} }
break; break;
case '$': case KEY_CAL_END_OF_WEEK:
if (wins_slctd () == CAL) if (wins_slctd () == CAL)
{ {
do_storage = true; do_storage = true;
@ -510,8 +507,7 @@ main (int argc, char **argv)
} }
break; break;
case ('Q'): /* Quit calcurse :( */ case KEY_GENERIC_QUIT:
case ('q'):
if (conf.auto_save) if (conf.auto_save)
io_save_cal (IO_MODE_INTERACTIVE, &conf); io_save_cal (IO_MODE_INTERACTIVE, &conf);

View File

@ -1,4 +1,4 @@
/* $calcurse: custom.c,v 1.23 2008/09/21 08:06:43 culot Exp $ */ /* $calcurse: custom.c,v 1.24 2008/11/09 20:10:18 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -227,7 +227,7 @@ custom_load_conf (conf_t *conf, int background)
doupdate (); doupdate ();
wgetch (win[STA].p); wgetch (win[STA].p);
} }
var = 0; var = CUSTOM_CONF_NOVARIABLE;
pthread_mutex_lock (&nbar->mutex); pthread_mutex_lock (&nbar->mutex);
for (;;) for (;;)
{ {

View File

@ -1,4 +1,4 @@
/* $Id: htable.h,v 1.1 2008/11/08 19:05:15 culot Exp $ */ /* $calcurse: htable.h,v 1.2 2008/11/09 20:10:18 culot Exp $ */
/* /*
* Copyright (c) 2008 Frederic Culot <frederic@culot.org> * Copyright (c) 2008 Frederic Culot <frederic@culot.org>

126
src/io.c
View File

@ -1,4 +1,4 @@
/* $calcurse: io.c,v 1.40 2008/09/29 06:27:53 culot Exp $ */ /* $calcurse: io.c,v 1.41 2008/11/09 20:10:18 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -31,6 +31,7 @@
#include <math.h> #include <math.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
#include <ctype.h>
#include "i18n.h" #include "i18n.h"
#include "utils.h" #include "utils.h"
@ -39,6 +40,8 @@
#include "event.h" #include "event.h"
#include "apoint.h" #include "apoint.h"
#include "recur.h" #include "recur.h"
#include "keys.h"
#include "htable.h"
#include "io.h" #include "io.h"
#define ICALDATEFMT "%Y%m%d" #define ICALDATEFMT "%Y%m%d"
@ -77,6 +80,12 @@ typedef struct {
unsigned count; unsigned count;
} ical_rpt_t; } ical_rpt_t;
struct ht_keybindings_s {
char *label;
keys_e key;
HTABLE_ENTRY (ht_keybindings_s);
};
/* Type definition for callbacks to multiple-mode export functions. */ /* Type definition for callbacks to multiple-mode export functions. */
typedef void (*cb_export_t)(FILE *); typedef void (*cb_export_t)(FILE *);
typedef void (*cb_dump_t)(FILE *, long, long, char *); typedef void (*cb_dump_t)(FILE *, long, long, char *);
@ -647,6 +656,7 @@ io_init (char *cfile, char *datadir)
snprintf (path_conf, BUFSIZ, "%s/" CONF_PATH_NAME, home); snprintf (path_conf, BUFSIZ, "%s/" CONF_PATH_NAME, home);
snprintf (path_notes, BUFSIZ, "%s/" NOTES_DIR_NAME, home); snprintf (path_notes, BUFSIZ, "%s/" NOTES_DIR_NAME, home);
snprintf (path_apts, BUFSIZ, "%s/" APTS_PATH_NAME, home); snprintf (path_apts, BUFSIZ, "%s/" APTS_PATH_NAME, home);
snprintf (path_keys, BUFSIZ, "%s/" KEYS_PATH_NAME, home);
} }
else else
{ {
@ -658,6 +668,7 @@ io_init (char *cfile, char *datadir)
snprintf (path_dir, BUFSIZ, "%s/" DIR_NAME, home); snprintf (path_dir, BUFSIZ, "%s/" DIR_NAME, home);
snprintf (path_todo, BUFSIZ, "%s/" TODO_PATH, home); snprintf (path_todo, BUFSIZ, "%s/" TODO_PATH, home);
snprintf (path_conf, BUFSIZ, "%s/" CONF_PATH, home); snprintf (path_conf, BUFSIZ, "%s/" CONF_PATH, home);
snprintf (path_keys, BUFSIZ, "%s/" KEYS_PATH, home);
snprintf (path_notes, BUFSIZ, "%s/" NOTES_DIR, home); snprintf (path_notes, BUFSIZ, "%s/" NOTES_DIR, home);
if (cfile == NULL) if (cfile == NULL)
{ {
@ -1159,6 +1170,115 @@ io_load_todo (void)
todo_set_nb (nb_tod); todo_set_nb (nb_tod);
} }
static void
load_keys_ht_getkey (struct ht_keybindings_s *data, char **key, int *len)
{
*key = data->label;
*len = strlen (data->label);
}
static int
load_keys_ht_compare (struct ht_keybindings_s *data1,
struct ht_keybindings_s *data2)
{
const int KEYLEN = strlen (data1->label);
if (strlen (data2->label) == KEYLEN
&& !memcmp (data1->label, data2->label, KEYLEN))
return 0;
else
return 1;
}
static int
key_to_ascii (char *key)
{
const string_t CONTROL_KEY = STRING_BUILD ("CTRL-");
if (strlen (key) == 1)
return (int)key[0];
else
{
if (!strncmp (key, CONTROL_KEY.str, CONTROL_KEY.len))
return CTRL ((int)key[CONTROL_KEY.len]);
else
return 0;
}
}
/*
* Load user-definable keys from file.
* A hash table is used to speed up loading process in avoiding string
* comparisons.
*/
void
io_load_keys (void)
{
struct ht_keybindings_s keys[NOKEYS];
FILE *keyfp;
char buf[BUFSIZ];
int i;
#define HSIZE 256
HTABLE_HEAD (ht_keybindings, HSIZE, ht_keybindings_s) ht_keys =
HTABLE_INITIALIZER (&ht_keys);
HTABLE_GENERATE (ht_keybindings, ht_keybindings_s, load_keys_ht_getkey,
load_keys_ht_compare);
for (i = 0; i < NOKEYS; i++)
{
keys[i].key = (keys_e)i;
keys[i].label = keys_get_label ((keys_e)i);
HTABLE_INSERT (ht_keybindings, &ht_keys, &keys[i]);
}
keyfp = fopen (path_keys, "r");
while (fgets (buf, BUFSIZ, keyfp) != NULL)
{
char key_label[BUFSIZ], *p;
struct ht_keybindings_s *ht_elm, ht_entry;
const int AWAITED = 1;
for (p = buf; isblank ((int)*p); p++)
;
if (p != buf)
memmove (buf, p, strlen (p));
if (buf[0] == '#')
continue;
if (sscanf (buf, "%s", key_label) != AWAITED)
continue;
ht_entry.label = key_label;
p = buf + strlen (key_label) + 1;
ht_elm = HTABLE_LOOKUP (ht_keybindings, &ht_keys, &ht_entry);
for (;;)
{
char key_ch[BUFSIZ], tmpbuf[BUFSIZ];
while (*p == ' ')
p++;
strncpy (tmpbuf, p, BUFSIZ);
if (sscanf (tmpbuf, "%s", key_ch) == AWAITED)
{
int ch;
char *unknown_key = _("Error reading key: %s");
ch = key_to_ascii (key_ch);
p += strlen (key_ch) + 1;
if (ch == 0)
ERROR_MSG (unknown_key);
else
keys_assign_binding (ch, ht_elm->key);
}
else
break;
}
}
fclose (keyfp);
#undef HSIZE
}
static void static void
check_directory (char *dir, int *missing) check_directory (char *dir, int *missing)
{ {
@ -1218,7 +1338,9 @@ io_check_data_files (void)
check_file (path_todo, &missing); check_file (path_todo, &missing);
check_file (path_apts, &missing); check_file (path_apts, &missing);
check_file (path_conf, &missing); check_file (path_conf, &missing);
return (missing); check_file (path_keys, &missing);
return missing;
} }
/* Draw the startup screen */ /* Draw the startup screen */

View File

@ -1,4 +1,4 @@
/* $calcurse: io.h,v 1.15 2008/09/21 08:06:43 culot Exp $ */ /* $calcurse: io.h,v 1.16 2008/11/09 20:10:18 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -54,6 +54,7 @@ void io_extract_data (char *, const char *, int);
void io_save_cal (io_mode_t, conf_t *); void io_save_cal (io_mode_t, conf_t *);
void io_load_app (void); void io_load_app (void);
void io_load_todo (void); void io_load_todo (void);
void io_load_keys (void);
int io_check_data_files (void); int io_check_data_files (void);
void io_startup_screen (bool, int); void io_startup_screen (bool, int);
void io_export_data (io_mode_t, export_type_t, conf_t *); void io_export_data (io_mode_t, export_type_t, conf_t *);

View File

@ -1,4 +1,4 @@
/* $calcurse: keys.c,v 1.1 2008/11/08 19:05:15 culot Exp $ */ /* $calcurse: keys.c,v 1.2 2008/11/09 20:10:18 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -26,9 +26,21 @@
#include "i18n.h" #include "i18n.h"
#include "utils.h" #include "utils.h"
#include "htable.h"
#include "keys.h" #include "keys.h"
const char *keylabel[NOKEYS] = { #define HTKEYSIZE 512
struct keys_s {
int key;
keys_e action;
HTABLE_ENTRY (keys_s);
};
static HTABLE_HEAD (ht_keys, HTKEYSIZE, keys_s) ht_keys_action =
HTABLE_INITIALIZER (&ht_keys_action);
static char *keylabel[NOKEYS] = {
"generic-help", "generic-help",
"generic-quit", "generic-quit",
"generic-save", "generic-save",
@ -85,10 +97,65 @@ const char *keylabel[NOKEYS] = {
"config-notify-menu" "config-notify-menu"
}; };
char *keys_get_label (keys_e key) static void
ht_getkey (struct keys_s *data, char **key, int *len)
{
*key = (char *)&data->key;
*len = sizeof (int);
}
static int
ht_compare (struct keys_s *data1, struct keys_s *data2)
{
if (data1->key == data2->key)
return 0;
else
return 1;
}
HTABLE_GENERATE (ht_keys, keys_s, ht_getkey, ht_compare);
char *
keys_get_label (keys_e key)
{ {
EXIT_IF (key < 0 || key > NOKEYS, EXIT_IF (key < 0 || key > NOKEYS,
_("FATAL ERROR in keys_get_label: key value out of bounds")); _("FATAL ERROR in keys_get_label: key value out of bounds"));
return keylabel (key); return keylabel[key];
}
int
keys_get_key (int pressed)
{
struct keys_s *key, find;
find.key = pressed;
key = HTABLE_LOOKUP (ht_keys, &ht_keys_action, &find);
if (key)
return (int)key->action;
else
return -1;
}
void
keys_assign_binding (int key, keys_e action)
{
struct keys_s *binding;
binding = malloc (sizeof (struct keys_s));
binding->key = key;
binding->action = action;
HTABLE_INSERT (ht_keys, &ht_keys_action, binding);
}
void
key_remove_binding (int key, keys_e action)
{
struct keys_s find, *removed;
find.key = key;
find.action = action;
removed = HTABLE_REMOVE (ht_keys, &ht_keys_action, &find);
mem_free (removed);
} }

View File

@ -1,4 +1,4 @@
/* $calcurse: keys.h,v 1.1 2008/11/08 19:05:15 culot Exp $ */ /* $calcurse: keys.h,v 1.2 2008/11/09 20:10:18 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -41,7 +41,7 @@ typedef enum
KEY_GENERIC_REDRAW, KEY_GENERIC_REDRAW,
KEY_GENERIC_ADD_APPT, KEY_GENERIC_ADD_APPT,
KEY_GENERIC_ADD_TODO, KEY_GENERIC_ADD_TODO,
KEY_GENERIC_NEXT_ADY, KEY_GENERIC_NEXT_DAY,
KEY_GENERIC_PREV_DAY, KEY_GENERIC_PREV_DAY,
KEY_GENERIC_NEXT_WEEK, KEY_GENERIC_NEXT_WEEK,
KEY_GENERIC_PREV_WEEK, KEY_GENERIC_PREV_WEEK,
@ -74,7 +74,7 @@ typedef enum
KEY_TODO_MOVE_UP, KEY_TODO_MOVE_UP,
KEY_TODO_MOVE_DOWN, KEY_TODO_MOVE_DOWN,
KEY_TODO_EDIT_NOTE, KEY_TODO_EDIT_NOTE,
KEY_TODO_VIEW_BOTE, KEY_TODO_VIEW_NOTE,
KEY_CONFIG_QUIT, KEY_CONFIG_QUIT,
KEY_CONFIG_GENERAL_MENU, KEY_CONFIG_GENERAL_MENU,
@ -86,6 +86,9 @@ typedef enum
} }
keys_e; keys_e;
char *keys_get_label (keys_e); char *keys_get_label (keys_e);
int keys_get_key (int);
void keys_assign_binding (int, keys_e);
void key_remove_binding (int, keys_e);
#endif /* CALCURSE_KEYS_H */ #endif /* CALCURSE_KEYS_H */

View File

@ -1,4 +1,4 @@
/* $calcurse: todo.c,v 1.22 2008/04/19 21:05:15 culot Exp $ */ /* $calcurse: todo.c,v 1.23 2008/11/09 20:10:18 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -30,6 +30,7 @@
#include "utils.h" #include "utils.h"
#include "custom.h" #include "custom.h"
#include "keys.h"
#include "i18n.h" #include "i18n.h"
#include "todo.h" #include "todo.h"
@ -347,11 +348,11 @@ todo_chg_priority (int action)
strncpy (backup_note, backup->note, NOTESIZ + 1); strncpy (backup_note, backup->note, NOTESIZ + 1);
else else
backup_note[0] = '\0'; backup_note[0] = '\0';
if (action == '+') if (action == KEY_TODO_RAISE_PRIORITY)
{ {
(backup_id > 1) ? backup_id-- : do_chg--; (backup_id > 1) ? backup_id-- : do_chg--;
} }
else if (action == '-') else if (action == KEY_TODO_LOWER_PRIORITY)
{ {
(backup_id < 9) ? backup_id++ : do_chg--; (backup_id < 9) ? backup_id++ : do_chg--;
} }

View File

@ -1,4 +1,4 @@
/* $calcurse: utils.h,v 1.36 2008/09/23 17:31:57 culot Exp $ */ /* $calcurse: utils.h,v 1.37 2008/11/09 20:10:18 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -27,7 +27,10 @@
#ifndef CALCURSE_UTILS_H #ifndef CALCURSE_UTILS_H
#define CALCURSE_UTILS_H #define CALCURSE_UTILS_H
#include <stdlib.h>
#include "calendar.h" #include "calendar.h"
#include "vars.h"
#define MAX(x,y) ((x)>(y)?(x):(y)) #define MAX(x,y) ((x)>(y)?(x):(y))
#define MIN(x,y) ((x)<(y)?(x):(y)) #define MIN(x,y) ((x)<(y)?(x):(y))

View File

@ -1,4 +1,4 @@
/* $calcurse: vars.c,v 1.9 2008/09/20 12:47:06 culot Exp $ */ /* $calcurse: vars.c,v 1.10 2008/11/09 20:10:18 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -87,6 +87,7 @@ char path_todo[] = "";
char path_apts[] = ""; char path_apts[] = "";
char path_conf[] = ""; char path_conf[] = "";
char path_notes[] = ""; char path_notes[] = "";
char path_keys[] = "";
/* Variable to handle pads. */ /* Variable to handle pads. */
struct pad_s *apad; struct pad_s *apad;

View File

@ -1,4 +1,4 @@
/* $calcurse: vars.h,v 1.24 2008/09/20 12:47:06 culot Exp $ */ /* $calcurse: vars.h,v 1.25 2008/11/09 20:10:18 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -35,10 +35,12 @@
#define TODO_PATH_NAME "todo" #define TODO_PATH_NAME "todo"
#define APTS_PATH_NAME "apts" #define APTS_PATH_NAME "apts"
#define CONF_PATH_NAME "conf" #define CONF_PATH_NAME "conf"
#define KEYS_PATH_NAME "keys"
#define NOTES_DIR_NAME "notes/" #define NOTES_DIR_NAME "notes/"
#define TODO_PATH DIR_NAME TODO_PATH_NAME #define TODO_PATH DIR_NAME TODO_PATH_NAME
#define APTS_PATH DIR_NAME APTS_PATH_NAME #define APTS_PATH DIR_NAME APTS_PATH_NAME
#define CONF_PATH DIR_NAME CONF_PATH_NAME #define CONF_PATH DIR_NAME CONF_PATH_NAME
#define KEYS_PATH DIR_NAME KEYS_PATH_NAME
#define NOTES_DIR DIR_NAME NOTES_DIR_NAME #define NOTES_DIR DIR_NAME NOTES_DIR_NAME
#define CTRL(x) ((x) & 0x1f) #define CTRL(x) ((x) & 0x1f)
@ -116,6 +118,7 @@ extern char path_dir[BUFSIZ];
extern char path_todo[BUFSIZ]; extern char path_todo[BUFSIZ];
extern char path_apts[BUFSIZ]; extern char path_apts[BUFSIZ];
extern char path_conf[BUFSIZ]; extern char path_conf[BUFSIZ];
extern char path_keys[BUFSIZ];
extern char path_notes[BUFSIZ]; extern char path_notes[BUFSIZ];
extern struct pad_s *apad; extern struct pad_s *apad;
extern struct nbar_s *nbar; extern struct nbar_s *nbar;