2
/******************************************************************************
3
* MODULE : edit_keyboard.cpp
4
* DESCRIPTION: Keyboard handling
5
* COPYRIGHT : (C) 1999 Joris van der Hoeven
6
*******************************************************************************
7
* This software falls under the GNU general public license and comes WITHOUT
8
* ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for more details.
9
* If you don't have this file, write to the Free Software Foundation, Inc.,
10
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
11
******************************************************************************/
13
#include "edit_interface.hpp"
14
#include "analyze.hpp"
15
#include "tm_buffer.hpp"
17
/******************************************************************************
19
******************************************************************************/
22
edit_interface_rep::get_input_mode () {
27
edit_interface_rep::set_input_mode (int mode) {
28
sh_s = string (""); // avoids keyboard shorthands when
29
sh_len= 0; // using the menu between two keystrokes
31
if ((mode == INPUT_NORMAL) && (input_mode != INPUT_NORMAL)) {
33
completions= array<string> ();
39
edit_interface_rep::set_input_normal () {
40
set_input_mode (INPUT_NORMAL);
44
edit_interface_rep::in_normal_mode () {
45
return input_mode == INPUT_NORMAL;
49
edit_interface_rep::in_search_mode () {
50
return input_mode == INPUT_SEARCH;
54
edit_interface_rep::in_replace_mode () {
55
return input_mode == INPUT_REPLACE;
59
edit_interface_rep::in_spell_mode () {
60
return input_mode == INPUT_SPELL;
63
/******************************************************************************
65
******************************************************************************/
68
edit_interface_rep::try_shortcut (string comb) {
74
sv->get_keycomb (comb, status, cmd, shorth, help);
75
if ((status & 1) == 1) {
77
tp= path_add (tp, -sh_len);
85
if ((status & 2) == 2) {
88
tp= path_add (tp, -sh_len);
89
if (sh_len>0) remove (tp, sh_len);
91
if (N(shorth)>0) insert_tree (shorth);
93
string rew= sv->kbd_post_rewrite (sh_s);
94
if (N(help)>0) set_message (help, rew);
95
else set_message ("keyboard shorthand: " * rew, shorth);
102
simplify_key_press (string key) {
103
while ((N(key) >= 5) && (key(0,3) == "Mod") && (key[4] == '-') &&
104
(key[3] >= '1') && (key[3] <= '5')) key= key (5, N(key));
105
if (key == "space") key= " ";
110
edit_interface_rep::key_press (string key) {
111
if (input_mode != INPUT_NORMAL)
112
key= simplify_key_press (key);
113
switch (input_mode) {
117
if (search_keypress (key)) return;
120
if (replace_keypress (key)) return;
123
if (spell_keypress (key)) return;
126
if (complete_keypress (key)) return;
131
string new_sh= N(sh_s)==0? key: sh_s * " " * key;
132
if (try_shortcut (new_sh)) return;
136
if (try_shortcut (key)) return;
139
string rew= sv->kbd_post_rewrite (key);
141
int i ((unsigned char) rew[0]);
142
if (((i>=32) && (i<=127)) ||
143
((i>=128) && (i <=255))) insert_tree (rew);
150
edit_interface_rep::emulate_keyboard (string keys, string action) {
154
for (i=1; i<N(s); i++)
155
if (s[i]==' ') break;
156
key_press (s (0, i));
161
set_message ("You can also obtain#" * action *
162
"#by typing#" * keys, action);
165
/******************************************************************************
167
******************************************************************************/
170
edit_interface_rep::show_keymaps () {
171
fatal_error ("no longer supported", "edit_interface_rep::show_keymaps");
175
edit_interface_rep::handle_keypress (keypress_event ev) {
176
call ("lazy-in-mode-force");
177
buf->mark_undo_block ();
179
notify_change (THE_DECORATIONS);
183
edit_interface_rep::handle_keyboard_focus (keyboard_focus_event ev) {
185
notify_change (THE_FOCUS);
187
focus_on_this_editor ();
188
notify_change (THE_DECORATIONS);