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>
|
2009-01-23 Frederic Culot <frederic@culot.org>
|
||||||
|
|
||||||
* configure.ac: improve configuration script to be able to link
|
* configure.ac: improve configuration script to be able to link
|
||||||
|
32
src/custom.c
32
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
|
* Calcurse - text-based organizer
|
||||||
@ -1173,7 +1173,7 @@ custom_keys_config (void)
|
|||||||
{
|
{
|
||||||
scrollwin_t kwin;
|
scrollwin_t kwin;
|
||||||
int selrow, selelm, firstrow, lastrow, nbrowelm, nbdisplayed;
|
int selrow, selelm, firstrow, lastrow, nbrowelm, nbdisplayed;
|
||||||
int keyval, used;
|
int keyval, used, not_recognized;
|
||||||
char *keystr;
|
char *keystr;
|
||||||
WINDOW *grabwin;
|
WINDOW *grabwin;
|
||||||
const int LINESPERKEY = 2;
|
const int LINESPERKEY = 2;
|
||||||
@ -1242,20 +1242,36 @@ custom_keys_config (void)
|
|||||||
#define WINCOL 50
|
#define WINCOL 50
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
used = 0;
|
||||||
grabwin = popup (WINROW, WINCOL, (row - WINROW) / 2,
|
grabwin = popup (WINROW, WINCOL, (row - WINROW) / 2,
|
||||||
(col - WINCOL) / 2,
|
(col - WINCOL) / 2,
|
||||||
_("Press the key you want to assign to:"),
|
_("Press the key you want to assign to:"),
|
||||||
keys_get_label (selrow), 0);
|
keys_get_label (selrow), 0);
|
||||||
keyval = wgetch (grabwin);
|
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);
|
used = keys_assign_binding (keyval, selrow);
|
||||||
if (used)
|
if (used)
|
||||||
{
|
{
|
||||||
keys_e action;
|
keys_e action;
|
||||||
|
|
||||||
action = keys_get_action (keyval);
|
action = keys_get_action (keyval);
|
||||||
ERROR_MSG (
|
WARN_MSG (_("This key is already in use for %s, "
|
||||||
_("This key is already in use for %s, "
|
"please choose another one."),
|
||||||
"please choose another one."),
|
|
||||||
keys_get_label (action));
|
keys_get_label (action));
|
||||||
werase (kwin.pad.p);
|
werase (kwin.pad.p);
|
||||||
nbrowelm = print_keys_bindings (kwin.pad.p, selrow, selelm,
|
nbrowelm = print_keys_bindings (kwin.pad.p, selrow, selelm,
|
||||||
@ -1264,7 +1280,7 @@ custom_keys_config (void)
|
|||||||
}
|
}
|
||||||
delwin (grabwin);
|
delwin (grabwin);
|
||||||
}
|
}
|
||||||
while (used);
|
while (used || not_recognized);
|
||||||
nbrowelm++;
|
nbrowelm++;
|
||||||
if (selelm < nbrowelm - 1)
|
if (selelm < nbrowelm - 1)
|
||||||
selelm++;
|
selelm++;
|
||||||
@ -1282,8 +1298,8 @@ custom_keys_config (void)
|
|||||||
case KEY_GENERIC_QUIT:
|
case KEY_GENERIC_QUIT:
|
||||||
if (keys_check_missing_bindings () != 0)
|
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!"));
|
"key bindings!"));
|
||||||
}
|
}
|
||||||
wins_scrollwin_delete (&kwin);
|
wins_scrollwin_delete (&kwin);
|
||||||
return;
|
return;
|
||||||
|
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
|
* Calcurse - text-based organizer
|
||||||
@ -1400,7 +1400,7 @@ io_load_keys (char *pager)
|
|||||||
if (loaded < NBKEYS)
|
if (loaded < NBKEYS)
|
||||||
keys_fill_missing ();
|
keys_fill_missing ();
|
||||||
if (keys_check_missing_bindings ())
|
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
|
#undef HSIZE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
24
src/keys.c
24
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
|
* 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
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -111,7 +111,9 @@ dump_intro (FILE *fd)
|
|||||||
"'C-'.\n"
|
"'C-'.\n"
|
||||||
"# The escape, space bar and horizontal Tab key can be specified using\n"
|
"# The escape, space bar and horizontal Tab key can be specified using\n"
|
||||||
"# the 'ESC', 'SPC' and 'TAB' keyword, respectively.\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"
|
"\n#\n"
|
||||||
"# A description of what each ACTION keyword is used for is available\n"
|
"# A description of what each ACTION keyword is used for is available\n"
|
||||||
"# from calcurse online configuration menu.\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_DOWN = STRING_BUILD ("DWN");
|
||||||
const string_t CURSES_KEY_LEFT = STRING_BUILD ("LFT");
|
const string_t CURSES_KEY_LEFT = STRING_BUILD ("LFT");
|
||||||
const string_t CURSES_KEY_RIGHT = STRING_BUILD ("RGT");
|
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)
|
if (!key)
|
||||||
return -1;
|
return -1;
|
||||||
@ -312,6 +316,10 @@ keys_str2int (char *key)
|
|||||||
return KEY_LEFT;
|
return KEY_LEFT;
|
||||||
else if (!strncmp (key, CURSES_KEY_RIGHT.str, CURSES_KEY_RIGHT.len))
|
else if (!strncmp (key, CURSES_KEY_RIGHT.str, CURSES_KEY_RIGHT.len))
|
||||||
return KEY_RIGHT;
|
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
|
else
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -336,6 +344,10 @@ keys_int2str (int key)
|
|||||||
return "LFT";
|
return "LFT";
|
||||||
case KEY_RIGHT:
|
case KEY_RIGHT:
|
||||||
return "RGT";
|
return "RGT";
|
||||||
|
case KEY_HOME:
|
||||||
|
return "KEY_HOME";
|
||||||
|
case KEY_END:
|
||||||
|
return "KEY_END";
|
||||||
default:
|
default:
|
||||||
return (char *)keyname (key);
|
return (char *)keyname (key);
|
||||||
}
|
}
|
||||||
@ -620,9 +632,9 @@ keys_fill_missing (void)
|
|||||||
ch = keys_str2int (key_ch);
|
ch = keys_str2int (key_ch);
|
||||||
used = keys_assign_binding (ch, i);
|
used = keys_assign_binding (ch, i);
|
||||||
if (used)
|
if (used)
|
||||||
ERROR_MSG (_("When adding default key for \"%s\", "
|
WARN_MSG (_("When adding default key for \"%s\", "
|
||||||
"\"%s\" was already assigned!"),
|
"\"%s\" was already assigned!"),
|
||||||
keydef[i].label, key_ch);
|
keydef[i].label, key_ch);
|
||||||
p += strlen (key_ch) + 1;
|
p += strlen (key_ch) + 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
33
src/utils.c
33
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
|
* Calcurse - text-based organizer
|
||||||
@ -81,12 +81,15 @@ fatalbox (const char *errmsg)
|
|||||||
{
|
{
|
||||||
WINDOW *errwin;
|
WINDOW *errwin;
|
||||||
char *label = _("/!\\ INTERNAL ERROR /!\\");
|
char *label = _("/!\\ INTERNAL ERROR /!\\");
|
||||||
char *reportmsg = _("Please report the following bug:");
|
char *reportmsg = _("Please report the following bug:");
|
||||||
const int WINROW = 10;
|
const int WINROW = 10;
|
||||||
const int WINCOL = col - 2;
|
const int WINCOL = col - 2;
|
||||||
const int MSGLEN = WINCOL - 2;
|
const int MSGLEN = WINCOL - 2;
|
||||||
char msg[MSGLEN];
|
char msg[MSGLEN];
|
||||||
|
|
||||||
|
if (errmsg == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
(void)strncpy (msg, errmsg, MSGLEN);
|
(void)strncpy (msg, errmsg, MSGLEN);
|
||||||
errwin = newwin (WINROW, WINCOL, (row - WINROW) / 2, (col - WINCOL) / 2);
|
errwin = newwin (WINROW, WINCOL, (row - WINROW) / 2, (col - WINCOL) / 2);
|
||||||
custom_apply_attr (errwin, ATTR_HIGHEST);
|
custom_apply_attr (errwin, ATTR_HIGHEST);
|
||||||
@ -101,6 +104,32 @@ fatalbox (const char *errmsg)
|
|||||||
doupdate ();
|
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.
|
* Print a message in the status bar.
|
||||||
* Message texts for first line and second line are to be provided.
|
* 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
|
* Calcurse - text-based organizer
|
||||||
@ -49,6 +49,16 @@
|
|||||||
(void)fprintf (stderr, "%s\n", msg); \
|
(void)fprintf (stderr, "%s\n", msg); \
|
||||||
} while (0)
|
} 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 { \
|
#define EXIT(...) do { \
|
||||||
ERROR_MSG(__VA_ARGS__); \
|
ERROR_MSG(__VA_ARGS__); \
|
||||||
if (ui_mode == UI_CURSES) \
|
if (ui_mode == UI_CURSES) \
|
||||||
@ -103,6 +113,7 @@ erase_flag_e;
|
|||||||
|
|
||||||
void exit_calcurse (int);
|
void exit_calcurse (int);
|
||||||
void fatalbox (const char *);
|
void fatalbox (const char *);
|
||||||
|
void warnbox (const char *);
|
||||||
void status_mesg (char *, char *);
|
void status_mesg (char *, char *);
|
||||||
void erase_window_part (WINDOW *, int, int, int, int);
|
void erase_window_part (WINDOW *, int, int, int, int);
|
||||||
WINDOW *popup (int, int, int, int, char *, char *, int);
|
WINDOW *popup (int, int, int, int, char *, char *, int);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user