From 18cc9ac0ddae467360de6406ad9ff2272472ca30 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Thu, 28 Feb 2013 10:49:14 +0400 Subject: [PATCH] (edit_translate_key): move from editkeys.c into editwidget.c ...and remove editkeys.c since it is empty. Signed-off-by: Andrew Borodin --- src/editor/Makefile.am | 18 +++- src/editor/edit-impl.h | 1 - src/editor/editkeys.c | 197 ---------------------------------------- src/editor/editwidget.c | 143 +++++++++++++++++++++++++++-- 4 files changed, 147 insertions(+), 212 deletions(-) delete mode 100644 src/editor/editkeys.c diff --git a/src/editor/Makefile.am b/src/editor/Makefile.am index abe0ac12b..8f013597a 100644 --- a/src/editor/Makefile.am +++ b/src/editor/Makefile.am @@ -7,11 +7,19 @@ noinst_LTLIBRARIES = endif libedit_la_SOURCES = \ - bookmark.c edit.c editcmd.c editwidget.c editwidget.h \ - editdraw.c editkeys.c \ - editmenu.c editoptions.c edit-impl.h edit.h \ - syntax.c wordproc.c \ - choosesyntax.c etags.c etags.h editcmd_dialogs.c editcmd_dialogs.h + bookmark.c \ + choosesyntax.c \ + edit.c edit.h \ + edit-impl.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 HAVE_GMODULE diff --git a/src/editor/edit-impl.h b/src/editor/edit-impl.h index 4d04bb895..0cf7e52c8 100644 --- a/src/editor/edit-impl.h +++ b/src/editor/edit-impl.h @@ -181,7 +181,6 @@ void edit_menu_cmd (WDialog * h); void user_menu (WEdit * edit, const char *menu_file, int selected_entry); void edit_init_menu (struct WMenuBar *menubar); 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_utf (const WEdit * edit, off_t byte_index, int *char_width); long edit_count_lines (const WEdit * edit, off_t current, off_t upto); diff --git a/src/editor/editkeys.c b/src/editor/editkeys.c deleted file mode 100644 index 45cacec1a..000000000 --- a/src/editor/editkeys.c +++ /dev/null @@ -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 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 . - */ - -/** \file - * \brief Source: editor key translation - */ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#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); -} - -/* --------------------------------------------------------------------------------------------- */ diff --git a/src/editor/editwidget.c b/src/editor/editwidget.c index 6061403d4..808046c29 100644 --- a/src/editor/editwidget.c +++ b/src/editor/editwidget.c @@ -2,12 +2,12 @@ Editor initialisation and callback handler. Copyright (C) 1996, 1997, 1998, 2001, 2002, 2003, 2004, 2005, 2006, - 2007, 2011, 2012 + 2007, 2011, 2012, 2013 The Free Software Foundation, Inc. Written by: Paul Sheer, 1996, 1997 - Andrew Borodin 2012 + Andrew Borodin 2012, 2013 This file is part of the Midnight Commander. @@ -33,15 +33,12 @@ #include -#include -#include -#include -#include -#include #include #include -#include #include +#include +#include +#include #include "lib/global.h" @@ -54,8 +51,11 @@ #include "lib/widget.h" #include "lib/mcconfig.h" #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/filemanager/cmd.h" /* view_other_cmd(), save_setup_cmd() */ #include "src/learn.h" /* learn_keys() */ @@ -809,6 +809,131 @@ edit_dialog_command_execute (WDialog * h, unsigned long command) 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