1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00
This commit is contained in:
Jonas Fonseca 2006-08-13 14:47:46 +02:00 committed by Jonas Fonseca
commit 98e8ba781f
8 changed files with 71 additions and 46 deletions

View File

@ -817,26 +817,41 @@ really_add_keybinding(void *data, unsigned char *keystroke)
struct kbdbind_add_hop *hop = data;
action_id_T action_id;
/* check_keystroke() has parsed @keystroke to @hop->kbd. */
if (keybinding_exists(hop->keymap_id, &hop->kbd, &action_id)
&& action_id != ACT_MAIN_NONE) {
struct kbdbind_add_hop *new_hop;
struct string canonical;
/* Same keystroke for same action, just return. */
if (action_id == hop->action_id) return;
/* @*hop is on the memory_list of the input_dialog,
* which will be closed when this function returns. */
new_hop = new_hop_from(hop);
if (!new_hop) return; /* out of mem */
/* Try to convert the parsed keystroke back to a
* string, so that the "Keystroke already used" box
* displays the same canonical name as the keybinding
* manager does. If something goes wrong here, then
* canonical.length will probably be 0, in which case
* we'll use the original @keystroke string instead. */
if (init_string(&canonical))
add_keystroke_to_string(&canonical, &hop->kbd, 0);
msg_box(new_hop->term, getml(new_hop, NULL), MSGBOX_FREE_TEXT,
N_("Keystroke already used"), ALIGN_CENTER,
msg_text(new_hop->term, N_("The keystroke \"%s\" "
"is currently used for \"%s\".\n"
"Are you sure you want to replace it?"),
keystroke, get_action_name(hop->keymap_id, action_id)),
canonical.length ? canonical.source : keystroke,
get_action_name(hop->keymap_id, action_id)),
new_hop, 2,
N_("~Yes"), really_really_add_keybinding, B_ENTER,
N_("~No"), NULL, B_ESC);
done_string(&canonical); /* safe even if init failed */
return;
}
@ -896,8 +911,7 @@ push_kbdbind_add_button(struct dialog_data *dlg_data,
"Keymap: %s\n"
"\n"
"Keystroke should be written in the format: "
"[Prefix-]Key\n"
"Prefix: Shift, Ctrl, Alt\n"
"[Shift-][Ctrl-][Alt-]Key\n"
"Key: a,b,c,...,1,2,3,...,Space,Up,PageDown,"
"Tab,Enter,Insert,F5,..."
"\n\n"

View File

@ -206,7 +206,7 @@ kbd_nm_lookup(enum keymap_id keymap_id, unsigned char *name)
}
static struct keybinding *
kbd_stroke_lookup(enum keymap_id keymap_id, unsigned char *keystroke_str)
kbd_stroke_lookup(enum keymap_id keymap_id, const unsigned char *keystroke_str)
{
struct term_event_keyboard kbd;
@ -230,7 +230,7 @@ static struct keymap keymap_table[] = {
static struct action *
get_action_from_keystroke(enum keymap_id keymap_id,
unsigned char *keystroke_str)
const unsigned char *keystroke_str)
{
struct keybinding *keybinding = kbd_stroke_lookup(keymap_id,
keystroke_str);
@ -240,7 +240,7 @@ get_action_from_keystroke(enum keymap_id keymap_id,
unsigned char *
get_action_name_from_keystroke(enum keymap_id keymap_id,
unsigned char *keystroke_str)
const unsigned char *keystroke_str)
{
struct action *action = get_action_from_keystroke(keymap_id,
keystroke_str);
@ -355,7 +355,7 @@ static struct key key_table[] = {
};
term_event_key_T
read_key(unsigned char *key_str)
read_key(const unsigned char *key_str)
{
struct key *key;
@ -369,32 +369,42 @@ read_key(unsigned char *key_str)
return KBD_UNDEF;
}
/* Parse the string @s as the name of a keystroke.
* Write the parsed key and modifiers to *@kbd.
* Return >=0 on success, <0 on error. */
int
parse_keystroke(unsigned char *s, struct term_event_keyboard *kbd)
parse_keystroke(const unsigned char *s, struct term_event_keyboard *kbd)
{
if (!strncasecmp(s, "Shift", 5) && (s[5] == '-' || s[5] == '+')) {
/* Shift+a == shiFt-a == Shift-a */
memcpy(s, "Shift-", 6);
kbd->modifier = KBD_MOD_SHIFT;
s += 6;
unsigned char ctrlbuf[2];
} else if (!strncasecmp(s, "Ctrl", 4) && (s[4] == '-' || s[4] == '+')) {
/* Ctrl+a == ctRl-a == Ctrl-a */
memcpy(s, "Ctrl-", 5);
kbd->modifier = KBD_MOD_CTRL;
s += 5;
kbd->modifier = KBD_MOD_NONE;
while (1) {
if (!strncasecmp(s, "Shift", 5) && (s[5] == '-' || s[5] == '+')) {
/* Shift+a == shiFt-a == Shift-a */
kbd->modifier |= KBD_MOD_SHIFT;
s += 6;
} else if (!strncasecmp(s, "Ctrl", 4) && (s[4] == '-' || s[4] == '+')) {
/* Ctrl+a == ctRl-a == Ctrl-a */
kbd->modifier |= KBD_MOD_CTRL;
s += 5;
} else if (!strncasecmp(s, "Alt", 3) && (s[3] == '-' || s[3] == '+')) {
/* Alt+a == aLt-a == Alt-a */
kbd->modifier |= KBD_MOD_ALT;
s += 4;
} else {
/* No modifier. */
break;
}
}
if ((kbd->modifier & KBD_MOD_CTRL) != 0 && s[0] && !s[1]) {
/* Ctrl-a == Ctrl-A */
if (s[0] && !s[1]) s[0] = toupper(s[0]);
} else if (!strncasecmp(s, "Alt", 3) && (s[3] == '-' || s[3] == '+')) {
/* Alt+a == aLt-a == Alt-a */
memcpy(s, "Alt-", 4);
kbd->modifier = KBD_MOD_ALT;
s += 4;
} else {
/* No modifier. */
kbd->modifier = KBD_MOD_NONE;
ctrlbuf[0] = toupper(s[0]);
ctrlbuf[1] = '\0';
s = ctrlbuf;
}
kbd->key = read_key(s);
@ -546,7 +556,7 @@ free_keymaps(struct module *xxx)
#ifdef CONFIG_SCRIPTING
static unsigned char *
bind_key_to_event(unsigned char *ckmap, unsigned char *ckey, int event)
bind_key_to_event(unsigned char *ckmap, const unsigned char *ckey, int event)
{
struct term_event_keyboard kbd;
action_id_T action_id;
@ -568,7 +578,7 @@ bind_key_to_event(unsigned char *ckmap, unsigned char *ckey, int event)
}
int
bind_key_to_event_name(unsigned char *ckmap, unsigned char *ckey,
bind_key_to_event_name(unsigned char *ckmap, const unsigned char *ckey,
unsigned char *event_name, unsigned char **err)
{
int event_id;
@ -863,7 +873,7 @@ get_aliased_action(enum keymap_id keymap_id, unsigned char *action_str)
/* Return 0 when ok, something strange otherwise. */
int
bind_do(unsigned char *keymap_str, unsigned char *keystroke_str,
bind_do(unsigned char *keymap_str, const unsigned char *keystroke_str,
unsigned char *action_str, int is_system_conf)
{
enum keymap_id keymap_id;
@ -887,7 +897,7 @@ bind_do(unsigned char *keymap_str, unsigned char *keystroke_str,
}
unsigned char *
bind_act(unsigned char *keymap_str, unsigned char *keystroke_str)
bind_act(unsigned char *keymap_str, const unsigned char *keystroke_str)
{
enum keymap_id keymap_id;
unsigned char *action;

View File

@ -123,7 +123,7 @@ struct action *get_action(enum keymap_id keymap_id, action_id_T action_id);
unsigned char *get_action_name(enum keymap_id keymap_id, action_id_T action_id);
action_id_T get_action_from_string(enum keymap_id keymap_id, unsigned char *str);
unsigned char *get_action_name_from_keystroke(enum keymap_id keymap_id,
unsigned char *keystroke_str);
const unsigned char *keystroke_str);
static inline unsigned int
action_is_anonymous_safe(enum keymap_id keymap_id, action_id_T action_id)
@ -173,10 +173,10 @@ action_requires_form(enum keymap_id keymap_id, action_id_T action_id)
return action && (action->flags & ACTION_REQUIRE_FORM);
}
term_event_key_T read_key(unsigned char *);
term_event_key_T read_key(const unsigned char *);
unsigned char *get_keymap_name(enum keymap_id);
int parse_keystroke(unsigned char *, struct term_event_keyboard *);
int parse_keystroke(const unsigned char *, struct term_event_keyboard *);
void add_keystroke_to_string(struct string *str, struct term_event_keyboard *kbd, int escape);
/* void add_accesskey_to_string(struct string *str, unicode_val_T accesskey); */
@ -195,12 +195,12 @@ action_id_T kbd_action(enum keymap_id, struct term_event *, int *);
struct keybinding *kbd_ev_lookup(enum keymap_id, struct term_event_keyboard *kbd, int *);
struct keybinding *kbd_nm_lookup(enum keymap_id, unsigned char *);
int bind_do(unsigned char *, unsigned char *, unsigned char *, int);
unsigned char *bind_act(unsigned char *, unsigned char *);
int bind_do(unsigned char *, const unsigned char *, unsigned char *, int);
unsigned char *bind_act(unsigned char *, const unsigned char *);
void bind_config_string(struct string *);
#ifdef CONFIG_SCRIPTING
int bind_key_to_event_name(unsigned char *, unsigned char *, unsigned char *,
int bind_key_to_event_name(unsigned char *, const unsigned char *, unsigned char *,
unsigned char **);
#endif

View File

@ -289,7 +289,7 @@ l_bind_key(LS)
add_format_to_string(&event_name, "lua-run-func %i", ref);
event_id = bind_key_to_event_name((unsigned char *) lua_tostring(S, 1),
(unsigned char *) lua_tostring(S, 2),
(const unsigned char *) lua_tostring(S, 2),
event_name.source, &err);
done_string(&event_name);

View File

@ -17,7 +17,7 @@ static JSBool
keymap_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
{
unsigned char *action_str;
unsigned char *keystroke_str;
const unsigned char *keystroke_str;
int *data = JS_GetPrivate(ctx, obj);
enum keymap_id keymap_id = *data;
@ -64,7 +64,7 @@ keymap_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
int *data = JS_GetPrivate(ctx, obj);
enum keymap_id keymap_id = *data;
unsigned char *keymap_str;
unsigned char *keystroke_str;
const unsigned char *keystroke_str;
/* Ugly fact: we need to get the string from the id to give to bind_do,
* which will of course then convert the string back to an id... */

View File

@ -173,9 +173,9 @@ void in_term(struct terminal *);
* TO DO: Change the event handlers to use unicode_fold_label_case()
* instead. The code that extracts the hotkey from the label string
* will also have to be changed. */
#define check_kbd_label_key(event) (get_kbd_key(event) > ' ' && get_kbd_key(event) <= 0x7F)
#define check_kbd_label_key(event) (get_kbd_key(event) > ' ' && get_kbd_key(event) <= 0x7F && (check_kbd_modifier(event, KBD_MOD_NONE) || check_kbd_modifier(event, KBD_MOD_ALT)))
#else /* !CONFIG_UTF_8 */
#define check_kbd_label_key(event) (get_kbd_key(event) > ' ')
#define check_kbd_label_key(event) (get_kbd_key(event) > ' ' && (check_kbd_modifier(event, KBD_MOD_NONE) || check_kbd_modifier(event, KBD_MOD_ALT)))
#endif /* !CONFIG_UTF_8 */

View File

@ -865,7 +865,7 @@ set_kbd_event(struct interlink_event *ev, int key, int modifier)
default:
if (key < ' ') {
key += 'A' - 1;
modifier = KBD_MOD_CTRL;
modifier |= KBD_MOD_CTRL;
}
}

View File

@ -1170,7 +1170,8 @@ quit:
if (check_kbd_key(ev, KBD_CTRL_C)) goto quit;
if (get_kbd_modifier(ev) & KBD_MOD_ALT) {
/* Ctrl-Alt-F should not open the File menu like Alt-f does. */
if (check_kbd_modifier(ev, KBD_MOD_ALT)) {
struct window *win;
get_kbd_modifier(ev) &= ~KBD_MOD_ALT;