Esempio n. 1
0
static cb_ret_t
view_handle_key (WDiff *view, int c)
{
    struct display_file *lf = &view->df[view->ord];
    struct display_file *rf = &view->df[view->ord ^ 1];

    c = convert_from_input_c(c);

    switch (c) {
	case 'l':
	    view->display_numbers ^= 1;
	    view->new_frame = 1;
	    return MSG_HANDLED;

	case 'f':
	    view->full ^= 1;
	    view->new_frame = 1;
	    return MSG_HANDLED;

	case '=': /* XXX testing only */
	    if (!view->full) {
		view->bias = 0;
		view->new_frame = 1;
	    }
	    return MSG_HANDLED;

	case '>': /* XXX testing only */
	    if (!view->full) {
		view_compute_split(view, 1);
		view->new_frame = 1;
	    }
	    return MSG_HANDLED;

	case '<': /* XXX testing only */
	    if (!view->full) {
		view_compute_split(view, -1);
		view->new_frame = 1;
	    }
	    return MSG_HANDLED;

	case '+':
	    if (view->subtract) {
		view->subtract--;
		view->new_frame = 1;
	    }
	    return MSG_HANDLED;
	case '-':
	    view->subtract++;
	    view->new_frame = 1;
	    return MSG_HANDLED;

	case '1':
	    lf->move = 1;
	    rf->move ^= 1;
	    return MSG_HANDLED;
	case '2':
	    lf->move ^= 1;
	    rf->move = 1;
	    return MSG_HANDLED;

	case XCTRL('u'): {
	    view->ord ^= 1;
	    return MSG_HANDLED;
	}

	case XCTRL('r'):
	    view_redo(view);
	    return MSG_HANDLED;

	case 'n':
	    find_next_hunk(view);
	    return MSG_HANDLED;

	case 'p':
	    find_prev_hunk(view);
	    return MSG_HANDLED;

	case KEY_DC:
	    view->last_found = -1;
	    return MSG_HANDLED;

	case KEY_F(4):
	    view_edit(view, view->ord);
	    return MSG_HANDLED;

	case KEY_F(14):
	    view_edit(view, view->ord ^ 1);
	    return MSG_HANDLED;

	case KEY_F(17):
	    view_search(view, 1);
	    return MSG_HANDLED;

	case KEY_HOME:
	case ALT ('<'):
	case KEY_M_CTRL | KEY_PPAGE:
	    view->last_found = -1;
	    if (lf->move) lf->offs = 0;
	    if (rf->move) rf->offs = 0;
	    return MSG_HANDLED;

	case KEY_END:
	case ALT ('>'):
	case KEY_M_CTRL | KEY_NPAGE:
	    view->last_found = -1;
	    if (lf->move) lf->offs = view->max - 1;
	    if (rf->move) rf->offs = view->max - 1;
	    return MSG_HANDLED;

	case KEY_UP:
	    if (lf->move) lf->offs -= view->nbytes;
	    if (rf->move) rf->offs -= view->nbytes;
	    return MSG_HANDLED;

	case KEY_DOWN:
	    if (lf->move) lf->offs += view->nbytes;
	    if (rf->move) rf->offs += view->nbytes;
	    return MSG_HANDLED;

	case KEY_NPAGE:
	    if (lf->move) lf->offs += view->pbytes;
	    if (rf->move) rf->offs += view->pbytes;
	    return MSG_HANDLED;

	case KEY_PPAGE:
	    if (lf->move) lf->offs -= view->pbytes;
	    if (rf->move) rf->offs -= view->pbytes;
	    return MSG_HANDLED;

	case KEY_LEFT:
	    if (lf->move) lf->offs--;
	    if (rf->move) rf->offs--;
	    return MSG_HANDLED;

	case KEY_RIGHT:
	    if (lf->move) lf->offs++;
	    if (rf->move) rf->offs++;
	    return MSG_HANDLED;

	case KEY_M_CTRL | KEY_LEFT:
	    if (lf->move) lf->offs -= 16;
	    if (rf->move) rf->offs -= 16;
	    return MSG_HANDLED;

	case KEY_M_CTRL | KEY_RIGHT:
	    if (lf->move) lf->offs += 16;
	    if (rf->move) rf->offs += 16;
	    return MSG_HANDLED;

	case XCTRL('o'):
	    view_other_cmd();
	    return MSG_HANDLED;

	case 't':
	    diff_view(view->file[0], view->file[1]);
	    return MSG_HANDLED;

	case 'q':
	case ESC_CHAR:
	    view->view_quit = 1;
	    return MSG_HANDLED;

	case '\n':
	    return MSG_HANDLED;

#ifdef HAVE_CHARSET
	case XCTRL ('t'):
	    do_select_codepage ();
	    view_update (view);
	    return MSG_HANDLED;
#endif				/* HAVE_CHARSET */
    }

    /* Key not used */
    return MSG_NOT_HANDLED;
}
Esempio n. 2
0
static gboolean
edit_translate_key (WEdit * edit, long x_key, int *cmd, int *ch)
{
    long command = CK_InsertChar;
    int char_for_insertion = -1;

    /* an ordinary insertable character */
    if (!edit->extmod && x_key < 256)
    {
#ifndef HAVE_CHARSET
        if (is_printable (x_key))
        {
            char_for_insertion = x_key;
            goto fin;
        }
#else
        int c;

        if (edit->charpoint >= 4)
        {
            edit->charpoint = 0;
            edit->charbuf[edit->charpoint] = '\0';
        }
        if (edit->charpoint < 4)
        {
            edit->charbuf[edit->charpoint++] = x_key;
            edit->charbuf[edit->charpoint] = '\0';
        }

        /* input from 8-bit locale */
        if (!mc_global.utf8_display)
        {
            /* source in 8-bit codeset */
            c = convert_from_input_c (x_key);

            if (is_printable (c))
            {
                if (!edit->utf8)
                    char_for_insertion = c;
                else
                    char_for_insertion = convert_from_8bit_to_utf_c2 ((char) x_key);
                goto fin;
            }
        }
        else
        {
            /* UTF-8 locale */
            int res;

            res = str_is_valid_char (edit->charbuf, edit->charpoint);
            if (res < 0 && res != -2)
            {
                edit->charpoint = 0;    /* broken multibyte char, skip */
                goto fin;
            }

            if (edit->utf8)
            {
                /* source in UTF-8 codeset */
                if (res < 0)
                {
                    char_for_insertion = x_key;
                    goto fin;
                }

                edit->charbuf[edit->charpoint] = '\0';
                edit->charpoint = 0;
                if (g_unichar_isprint (g_utf8_get_char (edit->charbuf)))
                {
                    char_for_insertion = x_key;
                    goto fin;
                }
            }
            else
            {
                /* 8-bit source */
                if (res < 0)
                {
                    /* not finised multibyte input (in meddle multibyte utf-8 char) */
                    goto fin;
                }

                if (g_unichar_isprint (g_utf8_get_char (edit->charbuf)))
                {
                    c = convert_from_utf_to_current (edit->charbuf);
                    edit->charbuf[0] = '\0';
                    edit->charpoint = 0;
                    char_for_insertion = c;
                    goto fin;
                }

                /* unprinteble utf input, skip it */
                edit->charbuf[0] = '\0';
                edit->charpoint = 0;
            }
        }
#endif /* HAVE_CHARSET */
    }

    /* Commands specific to the key emulation */
    if (edit->extmod)
    {
        edit->extmod = FALSE;
        command = keybind_lookup_keymap_command (editor_x_map, x_key);
    }
    else
        command = keybind_lookup_keymap_command (editor_map, x_key);

    if (command == CK_IgnoreKey)
        command = CK_InsertChar;

  fin:
    *cmd = (int) command;       /* FIXME */
    *ch = char_for_insertion;

    return !(command == CK_InsertChar && char_for_insertion == -1);
}
Esempio n. 3
0
/*
 * Translate the keycode into either 'command' or 'char_for_insertion'.
 * 'command' is one of the editor commands from editcmddef.h.
 */
int
edit_translate_key (WEdit *edit, long x_key, int *cmd, int *ch)
{
    int command = CK_Insert_Char;
    int char_for_insertion = -1;
    int i = 0;
    int extmod = 0;
    const edit_key_map_type *key_map = NULL;

    switch (edit_key_emulation) {
    case EDIT_KEY_EMULATION_NORMAL:
	key_map = cooledit_key_map;
	break;
    case EDIT_KEY_EMULATION_EMACS:
	key_map = emacs_key_map;
	if (x_key == XCTRL ('x')) {
	    int ext_key;
	    ext_key =
		edit_raw_key_query (" Ctrl-X ", _(" Emacs key: "), 0);
	    switch (ext_key) {
	    case 's':
		command = CK_Save;
		goto fin;
	    case 'x':
		command = CK_Exit;
		goto fin;
	    case 'k':
		command = CK_New;
		goto fin;
	    case 'e':
		command =
		    CK_Macro (edit_raw_key_query
			      (_(" Execute Macro "),
			       _(" Press macro hotkey: "), 1));
		if (command == CK_Macro (0))
		    command = CK_Insert_Char;
		goto fin;
	    }
	    goto fin;
	}
	break;

    case EDIT_KEY_EMULATION_USER:
	if (edit->user_map != NULL) {
	    if (edit->extmod && edit->ext_map != NULL) {
		key_map = edit->ext_map;
		extmod = 1;
	    } else {
		key_map = edit->user_map;
	    }
	    edit->extmod = 0;
	} else {
	    key_map = edit->user_map = cooledit_key_map;
	}
	break;
    }
    assert (key_map != NULL);

    /* an ordinary insertable character */
    if (x_key < 256 && !extmod) {
	int c = convert_from_input_c (x_key);

	if (is_printable (c)) {
	    char_for_insertion = c;
	    goto fin;
	}
    }

    /* Commands specific to the key emulation */
    for (i = 0; key_map[i].key != 0 && key_map[i].key != x_key; i++)
	continue;
    if (key_map[i].key != 0) {
	command = key_map[i].command;
	goto fin;
    }

    /* Commands common for the key emulations */
    key_map = common_key_map;
    for (i = 0; key_map[i].key != 0 && key_map[i].key != x_key; i++)
	continue;
    if (key_map[i].key != 0) {
	command = key_map[i].command;
	goto fin;
    }

    /* Function still not found for this key, so try macros */
    /* This allows the same macro to be
       enabled by either eg "ALT('f')" or "XCTRL('f')" or "XCTRL('a'), 'f'" */

    if (x_key & ALT (0)) {	/* is an alt key ? */
	command = CK_Macro (x_key - ALT (0));
	goto fin;
    }
    if (x_key < ' ') {		/* is a ctrl key ? */
	command = CK_Macro (x_key);
	goto fin;
    }
  fin:

    *cmd = command;
    *ch = char_for_insertion;

    if (command == CK_Insert_Char && char_for_insertion == -1) {
	/* unchanged, key has no function here */
	return 0;
    }

    return 1;
}