1
1

(edit_translate_key): move from editkeys.c into editwidget.c

...and remove editkeys.c since it is empty.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Этот коммит содержится в:
Andrew Borodin 2013-02-28 10:49:14 +04:00
родитель a85fc3367e
Коммит 18cc9ac0dd
4 изменённых файлов: 147 добавлений и 212 удалений

Просмотреть файл

@ -7,11 +7,19 @@ noinst_LTLIBRARIES =
endif endif
libedit_la_SOURCES = \ libedit_la_SOURCES = \
bookmark.c edit.c editcmd.c editwidget.c editwidget.h \ bookmark.c \
editdraw.c editkeys.c \ choosesyntax.c \
editmenu.c editoptions.c edit-impl.h edit.h \ edit.c edit.h \
syntax.c wordproc.c \ edit-impl.h \
choosesyntax.c etags.c etags.h editcmd_dialogs.c editcmd_dialogs.h editcmd.c \
editcmd_dialogs.c editcmd_dialogs.h \
editdraw.c \
editmenu.c \
editoptions.c \
editwidget.c editwidget.h \
etags.c etags.h \
syntax.c \
wordproc.c
if USE_ASPELL if USE_ASPELL
if HAVE_GMODULE if HAVE_GMODULE

Просмотреть файл

@ -181,7 +181,6 @@ void edit_menu_cmd (WDialog * h);
void user_menu (WEdit * edit, const char *menu_file, int selected_entry); void user_menu (WEdit * edit, const char *menu_file, int selected_entry);
void edit_init_menu (struct WMenuBar *menubar); void edit_init_menu (struct WMenuBar *menubar);
void edit_save_mode_cmd (void); void edit_save_mode_cmd (void);
gboolean edit_translate_key (WEdit * edit, long x_key, int *cmd, int *ch);
int edit_get_byte (const WEdit * edit, off_t byte_index); int edit_get_byte (const WEdit * edit, off_t byte_index);
int edit_get_utf (const WEdit * edit, off_t byte_index, int *char_width); int edit_get_utf (const WEdit * edit, off_t byte_index, int *char_width);
long edit_count_lines (const WEdit * edit, off_t current, off_t upto); long edit_count_lines (const WEdit * edit, off_t current, off_t upto);

Просмотреть файл

@ -1,197 +0,0 @@
/*
Editor key translation.
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
2005, 2006, 2007, 2011, 2012
The Free Software Foundation, Inc.
Written by:
Paul Sheer, 1996, 1997
Andrew Borodin <aborodin@vmail.ru> 2012
This file is part of the Midnight Commander.
The Midnight Commander is free software: you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the License,
or (at your option) any later version.
The Midnight Commander is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/** \file
* \brief Source: editor key translation
*/
#include <config.h>
#include <stdio.h>
#include <stdarg.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <sys/stat.h>
#include <stdlib.h>
#include "lib/global.h"
#include "lib/tty/tty.h" /* keys */
#include "lib/tty/key.h" /* KEY_M_SHIFT */
#include "lib/strutil.h" /* str_isutf8 () */
#include "lib/util.h" /* is_printable() */
#ifdef HAVE_CHARSET
#include "lib/charsets.h"
#endif
#include "edit-impl.h"
#include "editwidget.h" /* WEdit */
#include "editcmd_dialogs.h"
#include "src/keybind-defaults.h" /* keybind_lookup_keymap_command() */
/*** global variables ****************************************************************************/
/*** file scope macro definitions ****************************************************************/
/*** file scope type declarations ****************************************************************/
/*** file scope variables ************************************************************************/
/*** file scope functions ************************************************************************/
/* --------------------------------------------------------------------------------------------- */
/* --------------------------------------------------------------------------------------------- */
/*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */
/*
* Translate the keycode into either 'command' or 'char_for_insertion'.
* 'command' is one of the editor commands from cmddef.h.
*/
gboolean
edit_translate_key (WEdit * edit, long x_key, int *cmd, int *ch)
{
unsigned long command = (unsigned long) 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 ((unsigned 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 == (unsigned long) CK_InsertChar && char_for_insertion == -1);
}
/* --------------------------------------------------------------------------------------------- */

Просмотреть файл

@ -2,12 +2,12 @@
Editor initialisation and callback handler. Editor initialisation and callback handler.
Copyright (C) 1996, 1997, 1998, 2001, 2002, 2003, 2004, 2005, 2006, Copyright (C) 1996, 1997, 1998, 2001, 2002, 2003, 2004, 2005, 2006,
2007, 2011, 2012 2007, 2011, 2012, 2013
The Free Software Foundation, Inc. The Free Software Foundation, Inc.
Written by: Written by:
Paul Sheer, 1996, 1997 Paul Sheer, 1996, 1997
Andrew Borodin <aborodin@vmail.ru> 2012 Andrew Borodin <aborodin@vmail.ru> 2012, 2013
This file is part of the Midnight Commander. This file is part of the Midnight Commander.
@ -33,15 +33,12 @@
#include <config.h> #include <config.h>
#include <stdio.h>
#include <stdarg.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h> #include <ctype.h>
#include <errno.h> #include <errno.h>
#include <sys/stat.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include "lib/global.h" #include "lib/global.h"
@ -54,8 +51,11 @@
#include "lib/widget.h" #include "lib/widget.h"
#include "lib/mcconfig.h" #include "lib/mcconfig.h"
#include "lib/event.h" /* mc_event_raise() */ #include "lib/event.h" /* mc_event_raise() */
#ifdef HAVE_CHARSET
#include "lib/charsets.h"
#endif
#include "src/keybind-defaults.h" #include "src/keybind-defaults.h" /* keybind_lookup_keymap_command() */
#include "src/setup.h" /* home_dir */ #include "src/setup.h" /* home_dir */
#include "src/filemanager/cmd.h" /* view_other_cmd(), save_setup_cmd() */ #include "src/filemanager/cmd.h" /* view_other_cmd(), save_setup_cmd() */
#include "src/learn.h" /* learn_keys() */ #include "src/learn.h" /* learn_keys() */
@ -809,6 +809,131 @@ edit_dialog_command_execute (WDialog * h, unsigned long command)
return ret; return ret;
} }
/* --------------------------------------------------------------------------------------------- */
/*
* Translate the keycode into either 'command' or 'char_for_insertion'.
* 'command' is one of the editor commands from cmddef.h.
*/
static gboolean
edit_translate_key (WEdit * edit, long x_key, int *cmd, int *ch)
{
unsigned long command = (unsigned long) 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 ((unsigned 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 == (unsigned long) CK_InsertChar && char_for_insertion == -1);
}
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
static inline void static inline void