make it possible to use KEY_HOME and KEY_END to define new key bindings, and prevent user from assigning a non-recgnized key
This commit is contained in:
parent
9abf70b4a6
commit
c8a1b72027
12
ChangeLog
12
ChangeLog
@ -1,3 +1,15 @@
|
||||
2009-01-24 Frederic Culot <frederic@culot.org>
|
||||
|
||||
* src/keys.c: make it possible to use KEY_HOME and KEY_END to
|
||||
define new key bindings
|
||||
|
||||
* src/keys.c (custom_keys_config): prevent user from assigning a
|
||||
non-recognized key
|
||||
|
||||
* src/utils.c (warnbox): new function
|
||||
|
||||
* src/utils.h (WARN_MSG): new macro
|
||||
|
||||
2009-01-23 Frederic Culot <frederic@culot.org>
|
||||
|
||||
* configure.ac: improve configuration script to be able to link
|
||||
|
28
src/custom.c
28
src/custom.c
@ -1,4 +1,4 @@
|
||||
/* $calcurse: custom.c,v 1.36 2009/01/05 20:12:08 culot Exp $ */
|
||||
/* $calcurse: custom.c,v 1.37 2009/01/24 14:44:25 culot Exp $ */
|
||||
|
||||
/*
|
||||
* Calcurse - text-based organizer
|
||||
@ -1173,7 +1173,7 @@ custom_keys_config (void)
|
||||
{
|
||||
scrollwin_t kwin;
|
||||
int selrow, selelm, firstrow, lastrow, nbrowelm, nbdisplayed;
|
||||
int keyval, used;
|
||||
int keyval, used, not_recognized;
|
||||
char *keystr;
|
||||
WINDOW *grabwin;
|
||||
const int LINESPERKEY = 2;
|
||||
@ -1242,19 +1242,35 @@ custom_keys_config (void)
|
||||
#define WINCOL 50
|
||||
do
|
||||
{
|
||||
used = 0;
|
||||
grabwin = popup (WINROW, WINCOL, (row - WINROW) / 2,
|
||||
(col - WINCOL) / 2,
|
||||
_("Press the key you want to assign to:"),
|
||||
keys_get_label (selrow), 0);
|
||||
keyval = wgetch (grabwin);
|
||||
|
||||
/* First check if this key would be recognized by calcurse. */
|
||||
if (keys_str2int (keys_int2str (keyval)) == -1)
|
||||
{
|
||||
not_recognized = 1;
|
||||
WARN_MSG (_("This key is not yet recognized by calcurse, "
|
||||
"please choose another one."));
|
||||
werase (kwin.pad.p);
|
||||
nbrowelm = print_keys_bindings (kwin.pad.p, selrow, selelm,
|
||||
LINESPERKEY);
|
||||
wins_scrollwin_display (&kwin);
|
||||
continue;
|
||||
}
|
||||
else
|
||||
not_recognized = 0;
|
||||
|
||||
used = keys_assign_binding (keyval, selrow);
|
||||
if (used)
|
||||
{
|
||||
keys_e action;
|
||||
|
||||
action = keys_get_action (keyval);
|
||||
ERROR_MSG (
|
||||
_("This key is already in use for %s, "
|
||||
WARN_MSG (_("This key is already in use for %s, "
|
||||
"please choose another one."),
|
||||
keys_get_label (action));
|
||||
werase (kwin.pad.p);
|
||||
@ -1264,7 +1280,7 @@ custom_keys_config (void)
|
||||
}
|
||||
delwin (grabwin);
|
||||
}
|
||||
while (used);
|
||||
while (used || not_recognized);
|
||||
nbrowelm++;
|
||||
if (selelm < nbrowelm - 1)
|
||||
selelm++;
|
||||
@ -1282,7 +1298,7 @@ custom_keys_config (void)
|
||||
case KEY_GENERIC_QUIT:
|
||||
if (keys_check_missing_bindings () != 0)
|
||||
{
|
||||
ERROR_MSG (_("Some actions do not have any associated "
|
||||
WARN_MSG (_("Some actions do not have any associated "
|
||||
"key bindings!"));
|
||||
}
|
||||
wins_scrollwin_delete (&kwin);
|
||||
|
4
src/io.c
4
src/io.c
@ -1,4 +1,4 @@
|
||||
/* $calcurse: io.c,v 1.56 2009/01/05 20:12:08 culot Exp $ */
|
||||
/* $calcurse: io.c,v 1.57 2009/01/24 14:44:25 culot Exp $ */
|
||||
|
||||
/*
|
||||
* Calcurse - text-based organizer
|
||||
@ -1400,7 +1400,7 @@ io_load_keys (char *pager)
|
||||
if (loaded < NBKEYS)
|
||||
keys_fill_missing ();
|
||||
if (keys_check_missing_bindings ())
|
||||
ERROR_MSG (_("Some actions do not have any associated key bindings!"));
|
||||
WARN_MSG (_("Some actions do not have any associated key bindings!"));
|
||||
#undef HSIZE
|
||||
}
|
||||
|
||||
|
20
src/keys.c
20
src/keys.c
@ -1,8 +1,8 @@
|
||||
/* $calcurse: keys.c,v 1.14 2009/01/03 21:32:11 culot Exp $ */
|
||||
/* $calcurse: keys.c,v 1.15 2009/01/24 14:44:25 culot Exp $ */
|
||||
|
||||
/*
|
||||
* Calcurse - text-based organizer
|
||||
* Copyright (c) 2008 Frederic Culot
|
||||
* Copyright (c) 2008-2009 Frederic Culot
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -111,7 +111,9 @@ dump_intro (FILE *fd)
|
||||
"'C-'.\n"
|
||||
"# The escape, space bar and horizontal Tab key can be specified using\n"
|
||||
"# the 'ESC', 'SPC' and 'TAB' keyword, respectively.\n"
|
||||
"# Arrow keys can also be specified with the UP, DWN, LFT, RGT keywords."
|
||||
"# Arrow keys can also be specified with the UP, DWN, LFT, RGT keywords.\n"
|
||||
"# Last, Home and End keys can be assigned using 'KEY_HOME' and 'KEY_END'\n"
|
||||
"# keywords"
|
||||
"\n#\n"
|
||||
"# A description of what each ACTION keyword is used for is available\n"
|
||||
"# from calcurse online configuration menu.\n");
|
||||
@ -287,6 +289,8 @@ keys_str2int (char *key)
|
||||
const string_t CURSES_KEY_DOWN = STRING_BUILD ("DWN");
|
||||
const string_t CURSES_KEY_LEFT = STRING_BUILD ("LFT");
|
||||
const string_t CURSES_KEY_RIGHT = STRING_BUILD ("RGT");
|
||||
const string_t CURSES_KEY_HOME = STRING_BUILD ("KEY_HOME");
|
||||
const string_t CURSES_KEY_END = STRING_BUILD ("KEY_END");
|
||||
|
||||
if (!key)
|
||||
return -1;
|
||||
@ -312,6 +316,10 @@ keys_str2int (char *key)
|
||||
return KEY_LEFT;
|
||||
else if (!strncmp (key, CURSES_KEY_RIGHT.str, CURSES_KEY_RIGHT.len))
|
||||
return KEY_RIGHT;
|
||||
else if (!strncmp (key, CURSES_KEY_HOME.str, CURSES_KEY_HOME.len))
|
||||
return KEY_HOME;
|
||||
else if (!strncmp (key, CURSES_KEY_END.str, CURSES_KEY_END.len))
|
||||
return KEY_END;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
@ -336,6 +344,10 @@ keys_int2str (int key)
|
||||
return "LFT";
|
||||
case KEY_RIGHT:
|
||||
return "RGT";
|
||||
case KEY_HOME:
|
||||
return "KEY_HOME";
|
||||
case KEY_END:
|
||||
return "KEY_END";
|
||||
default:
|
||||
return (char *)keyname (key);
|
||||
}
|
||||
@ -620,7 +632,7 @@ keys_fill_missing (void)
|
||||
ch = keys_str2int (key_ch);
|
||||
used = keys_assign_binding (ch, i);
|
||||
if (used)
|
||||
ERROR_MSG (_("When adding default key for \"%s\", "
|
||||
WARN_MSG (_("When adding default key for \"%s\", "
|
||||
"\"%s\" was already assigned!"),
|
||||
keydef[i].label, key_ch);
|
||||
p += strlen (key_ch) + 1;
|
||||
|
31
src/utils.c
31
src/utils.c
@ -1,4 +1,4 @@
|
||||
/* $calcurse: utils.c,v 1.67 2009/01/05 20:12:08 culot Exp $ */
|
||||
/* $calcurse: utils.c,v 1.68 2009/01/24 14:44:25 culot Exp $ */
|
||||
|
||||
/*
|
||||
* Calcurse - text-based organizer
|
||||
@ -87,6 +87,9 @@ fatalbox (const char *errmsg)
|
||||
const int MSGLEN = WINCOL - 2;
|
||||
char msg[MSGLEN];
|
||||
|
||||
if (errmsg == 0)
|
||||
return;
|
||||
|
||||
(void)strncpy (msg, errmsg, MSGLEN);
|
||||
errwin = newwin (WINROW, WINCOL, (row - WINROW) / 2, (col - WINCOL) / 2);
|
||||
custom_apply_attr (errwin, ATTR_HIGHEST);
|
||||
@ -101,6 +104,32 @@ fatalbox (const char *errmsg)
|
||||
doupdate ();
|
||||
}
|
||||
|
||||
void
|
||||
warnbox (const char *msg)
|
||||
{
|
||||
WINDOW *warnwin;
|
||||
char *label = "/!\\";
|
||||
const int WINROW = 10;
|
||||
const int WINCOL = col - 2;
|
||||
const int MSGLEN = WINCOL - 2;
|
||||
char displmsg[MSGLEN];
|
||||
|
||||
if (msg == 0)
|
||||
return;
|
||||
|
||||
(void)strncpy (displmsg, msg, MSGLEN);
|
||||
warnwin = newwin (WINROW, WINCOL, (row - WINROW) / 2, (col - WINCOL) / 2);
|
||||
custom_apply_attr (warnwin, ATTR_HIGHEST);
|
||||
box (warnwin, 0, 0);
|
||||
wins_show (warnwin, label);
|
||||
mvwprintw (warnwin, 5, (WINCOL - strlen (displmsg)) / 2, "%s", displmsg);
|
||||
custom_remove_attr (warnwin, ATTR_HIGHEST);
|
||||
wrefresh (warnwin);
|
||||
(void)wgetch (warnwin);
|
||||
delwin (warnwin);
|
||||
doupdate ();
|
||||
}
|
||||
|
||||
/*
|
||||
* Print a message in the status bar.
|
||||
* Message texts for first line and second line are to be provided.
|
||||
|
13
src/utils.h
13
src/utils.h
@ -1,4 +1,4 @@
|
||||
/* $calcurse: utils.h,v 1.43 2009/01/03 21:32:11 culot Exp $ */
|
||||
/* $calcurse: utils.h,v 1.44 2009/01/24 14:44:25 culot Exp $ */
|
||||
|
||||
/*
|
||||
* Calcurse - text-based organizer
|
||||
@ -49,6 +49,16 @@
|
||||
(void)fprintf (stderr, "%s\n", msg); \
|
||||
} while (0)
|
||||
|
||||
#define WARN_MSG(...) do { \
|
||||
char msg[BUFSIZ]; \
|
||||
\
|
||||
(void)snprintf (msg, BUFSIZ, __VA_ARGS__); \
|
||||
if (ui_mode == UI_CURSES) \
|
||||
warnbox (msg); \
|
||||
else \
|
||||
(void)fprintf (stderr, "%s\n", msg); \
|
||||
} while (0)
|
||||
|
||||
#define EXIT(...) do { \
|
||||
ERROR_MSG(__VA_ARGS__); \
|
||||
if (ui_mode == UI_CURSES) \
|
||||
@ -103,6 +113,7 @@ erase_flag_e;
|
||||
|
||||
void exit_calcurse (int);
|
||||
void fatalbox (const char *);
|
||||
void warnbox (const char *);
|
||||
void status_mesg (char *, char *);
|
||||
void erase_window_part (WINDOW *, int, int, int, int);
|
||||
WINDOW *popup (int, int, int, int, char *, char *, int);
|
||||
|
Loading…
x
Reference in New Issue
Block a user