]> git.lyx.org Git - lyx.git/blob - src/LyXAction.C
some more changes
[lyx.git] / src / LyXAction.C
1 /* This file is part of
2  * ======================================================
3  *
4  *           LyX, The Document Processor
5  *
6  *           Copyright 1995 Matthias Ettrich
7  *           Copyright 1995-2001 The LyX Team.
8  *
9  * ====================================================== */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "LyXAction.h"
18 #include "debug.h"
19 #include "gettext.h"
20 #include "support/lstrings.h"
21
22 using std::ostream;
23 using std::endl;
24
25 /*
26      NAMING RULES FOR USER-COMMANDS
27      Here's the set of rules to apply when a new command name is introduced:
28
29      1) Use the object.event order. That is, use `word-forward'
30         instead of `forward-word'.
31      2) Don't introduce an alias for an already named object. Same for events.
32      3) Forward movement or focus is called `forward' (not `right').
33      4) Backward movement or focus is called `backward' (not `left').
34      5) Upward movement of focus is called `up'.
35      6) Downward movement is called `down'.
36      7) The begin of an object is called `begin' (not `start').
37      8) The end of an object is called `end'.
38
39      (May 19 1996, 12:04, RvdK)
40  */
41
42 // These are globals.
43 LyXAction lyxaction;
44
45 // Small helper function
46 inline
47 bool isPseudoAction(int a)
48 {
49         return a > int(LFUN_LASTACTION);
50 }
51
52
53
54 void LyXAction::newFunc(kb_action action, string const & name,
55                         string const & helpText, unsigned int attrib)
56 {
57         lyx_func_map[name] = action;
58         func_info tmpinfo;
59         tmpinfo.name = name;
60         tmpinfo.attrib = attrib;
61         tmpinfo.helpText = helpText;
62         lyx_info_map[action] = tmpinfo;
63 }
64
65
66 void LyXAction::init()
67 {
68         // This function was changed to use the array below in initalization
69         // instead of calling newFunc numerous times because of compilation
70         // times. Since the array is not static we get back the memory it
71         // occupies after the init is completed. It compiles several
72         // magnitudes faster.
73
74         static bool init;
75         if (init) return;
76
77         struct lfun_item {
78                 kb_action action;
79                 char const * name;
80                 char const * helpText;
81                 unsigned int attrib;
82         };
83
84         lfun_item items[] = {
85                 { LFUN_ACUTE, "accent-acute", "", Noop },
86                 { LFUN_BREVE, "accent-breve", "", Noop },
87                 { LFUN_CARON, "accent-caron", "", Noop },
88                 { LFUN_CEDILLA, "accent-cedilla", "", Noop },
89                 { LFUN_CIRCLE, "accent-circle", "", Noop },
90                 { LFUN_CIRCUMFLEX, "accent-circumflex", "", Noop },
91                 { LFUN_DOT, "accent-dot", "", Noop },
92                 { LFUN_GRAVE, "accent-grave", "", Noop },
93                 { LFUN_HUNG_UMLAUT, "accent-hungarian-umlaut", "", Noop },
94                 { LFUN_MACRON, "accent-macron", "", Noop },
95                 { LFUN_OGONEK, "accent-ogonek", "", Noop },
96                 { LFUN_SPECIAL_CARON, "accent-special-caron", "", Noop },
97                 { LFUN_TIE, "accent-tie", "", Noop },
98                 { LFUN_TILDE, "accent-tilde", "", Noop },
99                 { LFUN_UMLAUT, "accent-umlaut", "", Noop },
100                 { LFUN_UNDERBAR, "accent-underbar", "", Noop },
101                 { LFUN_UNDERDOT, "accent-underdot", "", Noop },
102                 { LFUN_VECTOR, "accent-vector", "", Noop },
103                 { LFUN_APPENDIX, "appendix", N_("Insert appendix"), Noop },
104                 { LFUN_APROPOS, "apropos", N_("Describe command"),
105                   NoBuffer|ReadOnly },
106                 { LFUN_LEFTSEL, "backward-select",
107                   N_("Select previous char"), ReadOnly },
108                 { LFUN_BIBDB_ADD, "bibtex-database-add", "", Noop },
109                 { LFUN_BIBDB_DEL, "bibtex-database-del", "", Noop },
110                 { LFUN_INSERT_BIBTEX, "bibtex-insert", N_("Insert bibtex"),
111                   Noop },
112                 { LFUN_BIBTEX_STYLE, "bibtex-style", "", Noop },
113                 { LFUN_BOOKMARK_GOTO, "bookmark-goto", "", ReadOnly },
114                 { LFUN_BOOKMARK_SAVE, "bookmark-save", "", ReadOnly },
115                 { LFUN_BREAKLINE, "break-line", "", Noop },
116                 { LFUN_BREAKPARAGRAPH, "break-paragraph", "", Noop },
117                 { LFUN_BREAKPARAGRAPHKEEPLAYOUT, "break-paragraph-keep-layout",
118                   "", Noop },
119                 { LFUN_BREAKPARAGRAPH_SKIP, "break-paragraph-skip", "", Noop },
120                 { LFUN_BUILDPROG, "build-program",
121                   N_("Build program"), ReadOnly },
122                 { LFUN_AUTOSAVE, "buffer-auto-save", N_("Autosave"), Noop },
123                 { LFUN_BEGINNINGBUF, "buffer-begin",
124                   N_("Go to beginning of document"), ReadOnly },
125                 { LFUN_BEGINNINGBUFSEL, "buffer-begin-select",
126                   N_("Select to beginning of document"), ReadOnly },
127                 { LFUN_CHILD_INSERT, "buffer-child-insert", "", Noop },
128                 { LFUN_CHILDOPEN, "buffer-child-open", "", ReadOnly },
129                 { LFUN_RUNCHKTEX, "buffer-chktex", N_("Check TeX"), ReadOnly },
130                 { LFUN_CLOSEBUFFER, "buffer-close", N_("Close"), ReadOnly },
131                 { LFUN_ENDBUF, "buffer-end",
132                   N_("Go to end of document"), ReadOnly },
133                 { LFUN_ENDBUFSEL, "buffer-end-select",
134                   N_("Select to end of document"), ReadOnly },
135                 { LFUN_EXPORT, "buffer-export", N_("Export to"), ReadOnly },
136                 { LFUN_IMPORT, "buffer-import",
137                   N_("Import document"), NoBuffer },
138                 { LFUN_MENUNEW, "buffer-new", N_("New document") , NoBuffer },
139                 { LFUN_MENUNEWTMPLT,"buffer-new-template",
140                   N_("New document from template"), NoBuffer },
141                 { LFUN_MENUPRINT, "buffer-print", N_("Print"), ReadOnly },
142                 { LFUN_MENURELOAD, "buffer-reload",
143                   N_("Revert to saved"), ReadOnly },
144                 { LFUN_SWITCHBUFFER, "buffer-switch",
145                   N_("Switch to an open document"), ReadOnly },
146                 { LFUN_READ_ONLY_TOGGLE, "buffer-toggle-read-only",
147                   N_("Toggle read-only"), ReadOnly },
148                 { LFUN_UPDATE, "buffer-update", N_("Update"), ReadOnly },
149                 { LFUN_PREVIEW, "buffer-view", N_("View") , ReadOnly },
150                 { LFUN_MENUWRITE, "buffer-write", N_("Save"), ReadOnly },
151                 { LFUN_WRITEAS, "buffer-write-as", N_("Save As"),
152                   ReadOnly },
153                 { LFUN_CANCEL, "cancel", N_("Cancel"), NoBuffer },
154                 { LFUN_INSET_CAPTION, "caption-insert", "", Noop },
155                 { LFUN_LEFT, "char-backward", N_("Go one char back"),
156                   ReadOnly },
157                 { LFUN_RIGHT, "char-forward", N_("Go one char forward"),
158                   ReadOnly },
159                 { LFUN_CITATION_CREATE, "citation-insert",
160                   N_("Insert citation"), Noop },
161                 { LFUN_CITATION_INSERT, "", "internal only", Noop },
162                 { LFUN_EXEC_COMMAND, "command-execute", "", NoBuffer },
163                 { LFUN_PREFIX, "command-prefix",
164                   N_("Execute command"), NoBuffer },
165                 { LFUN_SEQUENCE, "command-sequence", "", NoBuffer },
166                 { LFUN_COPY, "copy", N_("Copy"), ReadOnly },
167                 { LFUN_CUT, "cut", N_("Cut"), Noop },
168                 { LFUN_DATE_INSERT, "date-insert", "", Noop },
169                 { LFUN_BACKSPACE, "delete-backward", "", Noop },
170                 { LFUN_BACKSPACE_SKIP, "delete-backward-skip", "", Noop },
171                 { LFUN_DELETE, "delete-forward", "", Noop },
172                 { LFUN_DELETE_SKIP, "delete-forward-skip", "", Noop },
173                 { LFUN_DEPTH_MIN, "depth-decrement",
174                   N_("Decrement environment depth"), Noop },
175                 { LFUN_DEPTH_PLUS, "depth-increment",
176                   N_("Increment environment depth"), Noop },
177                 { LFUN_LDOTS, "dots-insert", N_("Insert ... dots"), Noop },
178                 { LFUN_DOWN, "down", N_("Go down"), ReadOnly },
179                 { LFUN_DOWNSEL, "down-select",
180                   N_("Select next line"), ReadOnly },
181                 { LFUN_DROP_LAYOUTS_CHOICE, "drop-layouts-choice",
182                   N_("Choose Paragraph Environment"), ReadOnly },
183                 { LFUN_END_OF_SENTENCE, "end-of-sentence-period-insert",
184                   N_("Insert end of sentence period"), Noop },
185                 { LFUN_GOTOERROR, "error-next",
186                   N_("Go to next error"), ReadOnly },
187                 { LFUN_REMOVEERRORS, "error-remove-all",
188                   N_("Remove all error boxes"), ReadOnly },
189                 { LFUN_INSET_ERT, "ert-insert",
190                   N_("Insert a new ERT Inset"), Noop },
191                 { LFUN_INSET_EXTERNAL, "external-insert",
192                   N_("Insert a new external inset"), Noop },
193                 { LFUN_INSET_GRAPHICS, "graphics-insert",
194                   N_("Insert Graphics"), Noop },
195                 { LFUN_FILE_INSERT, "file-insert", "", Noop },
196                 { LFUN_FILE_INSERT_ASCII, "file-insert-ascii", _("Insert ASCII files as lines"), Noop },
197                 { LFUN_FILE_INSERT_ASCII_PARA, "file-insert-ascii-para", _("Insert ASCII file as a paragraph"), Noop },
198                 { LFUN_FILE_NEW, "file-new", "", NoBuffer },
199                 { LFUN_FILE_OPEN, "file-open", _("Open a file"), NoBuffer },
200                 { LFUN_MENUSEARCH, "find-replace", N_("Find & Replace"),
201                   ReadOnly },
202                 { LFUN_INSET_FLOAT, "float-insert", "Insert a Float", Noop },
203                 { LFUN_INSET_WIDE_FLOAT, "float-wide-insert",
204                   "Insert a wide Float", Noop },
205                 { LFUN_BOLD, "font-bold", N_("Toggle bold"), Noop },
206                 { LFUN_CODE, "font-code", N_("Toggle code style"), Noop },
207                 { LFUN_DEFAULT, "font-default", N_("Default font style"),
208                   Noop },
209                 { LFUN_EMPH, "font-emph", N_("Toggle emphasize"), Noop },
210                 { LFUN_FREE, "font-free", N_("Toggle user defined style"),
211                   Noop },
212                 { LFUN_NOUN, "font-noun", N_("Toggle noun style"), Noop },
213                 { LFUN_ROMAN, "font-roman", N_("Toggle roman font style"),
214                   Noop },
215                 { LFUN_SANS, "font-sans", N_("Toggle sans font style"), Noop },
216                 { LFUN_FRAK, "font-frak", N_("Toggle fraktur font style"), Noop },
217                 { LFUN_ITAL, "font-ital", N_("Toggle italic font style"), Noop },
218                 { LFUN_FONT_SIZE, "font-size", N_("Set font size"), Noop },
219                 { LFUN_FONT_STATE, "font-state", N_("Show font state"),
220                   ReadOnly },
221                 { LFUN_UNDERLINE, "font-underline",
222                   N_("Toggle font underline"), Noop },
223                 { LFUN_INSET_FOOTNOTE, "footnote-insert",
224                   N_("Insert Footnote"), Noop },
225                 { LFUN_RIGHTSEL, "forward-select", N_("Select next char"),
226                   ReadOnly },
227                 { LFUN_HFILL, "hfill-insert",
228                   N_("Insert horizontal fill"), Noop },
229                 { LFUN_HELP_OPEN, "help-open", N_("Open a Help file"),
230                   NoBuffer|Argument},
231                 { LFUN_HTMLURL, "html-insert", "", Noop },
232                 { LFUN_HYPHENATION, "hyphenation-point-insert",
233                   N_("Insert hyphenation point"), Noop },
234                 { LFUN_LIGATURE_BREAK, "ligature-break-insert",
235                   N_("Insert ligature break"), Noop },
236                 { LFUN_INDEX_INSERT, "index-insert",
237                   N_("Insert index item"), Noop },
238                 { LFUN_INDEX_PRINT, "index-print", N_("Insert index list"),
239                   Noop },
240                 { LFUN_KMAP_OFF, "keymap-off", N_("Turn off keymap"),
241                   ReadOnly },
242                 { LFUN_KMAP_PRIM, "keymap-primary",
243                   N_("Use primary keymap"), ReadOnly },
244                 { LFUN_KMAP_SEC, "keymap-secondary",
245                   N_("Use secondary keymap"), ReadOnly },
246                 { LFUN_KMAP_TOGGLE, "keymap-toggle", N_("Toggle keymap"),
247                   ReadOnly },
248                 { LFUN_INSERT_LABEL, "label-insert", N_("Insert Label"),
249                   Noop },
250                 { LFUN_LANGUAGE, "language", N_("Change language"), Noop },
251                 { LFUN_LATEX_LOG, "latex-view-log", N_("View LaTeX log"),
252                   ReadOnly },
253                 { LFUN_LAYOUT, "layout", "", Noop },
254                 { LFUN_LAYOUT_CHARACTER, "layout-character", "", Noop },
255                 { LFUN_LAYOUT_COPY, "layout-copy",
256                   N_("Copy paragraph environment type"), Noop },
257                 { LFUN_LAYOUT_DOCUMENT, "layout-document", "", ReadOnly },
258                 { LFUN_LAYOUT_PARAGRAPH, "layout-paragraph", "", ReadOnly },
259                 { LFUN_LAYOUT_PASTE, "layout-paste",
260                   N_("Paste paragraph environment type"), Noop },
261                 { LFUN_LAYOUT_PREAMBLE, "layout-preamble", "", ReadOnly },
262                 { LFUN_LAYOUT_TABULAR, "layout-tabular",
263                   N_("Open the tabular layout"), Noop },
264                 { LFUN_HOME, "line-begin",
265                   N_("Go to beginning of line"), ReadOnly },
266                 { LFUN_HOMESEL, "line-begin-select",
267                   N_("Select to beginning of line"), ReadOnly },
268                 { LFUN_DELETE_LINE_FORWARD, "line-delete-forward", "", Noop },
269                 { LFUN_END, "line-end", N_("Go to end of line"), ReadOnly },
270                 { LFUN_ENDSEL, "line-end-select",
271                   N_("Select to end of line"), ReadOnly },
272 #if 0
273                 { LFUN_INSET_LIST, "list-insert", "", Noop },
274 #endif
275                 { LFUN_QUIT, "lyx-quit", N_("Exit"), NoBuffer },
276                 { LFUN_INSET_MARGINAL, "marginalnote-insert",
277                   N_("Insert Marginalnote"), Noop },
278                 { LFUN_MARK_OFF, "mark-off", "", ReadOnly },
279                 { LFUN_MARK_ON, "mark-on", "", ReadOnly },
280                 { LFUN_SETMARK, "mark-toggle", "", ReadOnly },
281                 { LFUN_MATH, "math", "", Noop },
282                 { LFUN_MATH_DELIM, "math-delim", "", Noop },
283                 { LFUN_MATH_DISPLAY, "math-display", "", Noop },
284                 { LFUN_GREEK, "math-greek", N_("Math Greek"), Noop },
285                 { LFUN_GREEK_TOGGLE, "math-greek-toggle", "", Noop },
286                 { LFUN_INSERT_MATH, "math-insert",
287                   N_("Insert math symbol"), Noop },
288                 { LFUN_SUBSCRIPT, "math-subscript", "", Noop },
289                 { LFUN_SUPERSCRIPT, "math-superscript", "", Noop },
290                 { LFUN_MATH_LIMITS, "math-limits", "", Noop },
291                 { LFUN_MATH_MACRO, "math-macro", "", Noop },
292                 { LFUN_MATH_MUTATE, "math-mutate", "", Noop },
293                 { LFUN_MATH_SPACE, "math-space", "", Noop },
294                 { LFUN_MATH_IMPORT_SELECTION, "math-import-selection", "", Noop },
295                 { LFUN_INSERT_MATRIX, "math-matrix", "", Noop },
296                 { LFUN_MATH_MODE, "math-mode", N_("Math mode"), Noop },
297                 { LFUN_MATH_NONUMBER, "math-nonumber", "", Noop },
298                 { LFUN_MATH_NUMBER, "math-number", "", Noop },
299                 { LFUN_MATH_EXTERN, "math-extern", "", Noop },
300                 { LFUN_MATH_VALIGN, "math-valign", "", Noop },
301                 { LFUN_MATH_HALIGN, "math-halign", "", Noop },
302                 { LFUN_MATH_ROW_INSERT, "math-row-insert", "", Noop },
303                 { LFUN_MATH_ROW_DELETE, "math-row-delete", "", Noop },
304                 { LFUN_MATH_COLUMN_INSERT, "math-column-insert", "", Noop },
305                 { LFUN_MATH_COLUMN_DELETE, "math-column-delete", "", Noop },
306                 { LFUN_MATH_PANEL, "math-panel", "", Noop },
307                 { LFUN_MATH_SIZE, "math-size", "", Noop },
308                 { LFUN_MENU_OPEN_BY_NAME, "menu-open", "", NoBuffer },
309                 { LFUN_MENU_SEPARATOR, "menu-separator-insert", "", Noop },
310                 { LFUN_META_FAKE, "meta-prefix", "", NoBuffer },
311                 { LFUN_INSET_MINIPAGE, "minipage-insert", "", Noop },
312                 { LFUN_INSERT_NOTE, "note-insert", "", Noop },
313                 { LFUN_GOTONOTE, "note-next", "", ReadOnly },
314                 { LFUN_INSET_TOGGLE, "inset-toggle",
315                   N_("toggle inset"), ReadOnly },
316                 { LFUN_DOWN_PARAGRAPH, "paragraph-down",
317                   N_("Go one paragraph down"), ReadOnly },
318                 { LFUN_DOWN_PARAGRAPHSEL, "paragraph-down-select",
319                   N_("Select next paragraph"), ReadOnly },
320                 { LFUN_GOTO_PARAGRAPH, "paragraph-goto",
321                   N_("Go to paragraph"), ReadOnly },
322                 { LFUN_PARAGRAPH_SPACING, "paragraph-spacing", "", Noop },
323                 { LFUN_UP_PARAGRAPH, "paragraph-up",
324                   N_("Go one paragraph up"), ReadOnly },
325                 { LFUN_UP_PARAGRAPHSEL, "paragraph-up-select",
326                   N_("Select previous paragraph"), ReadOnly },
327                 { LFUN_PARENTINSERT, "parent-insert", "", Noop },
328                 { LFUN_PASTE, "paste", N_("Paste") , Noop },
329                 { LFUN_DIALOG_PREFERENCES, "dialog-preferences",
330                   N_("Edit Preferences"), NoBuffer },
331                 { LFUN_SAVEPREFERENCES, "preferences-save",
332                   N_("Save Preferences"), NoBuffer },
333                 { LFUN_PASTESELECTION, "primary-selection-paste", "", Noop },
334                 { LFUN_PROTECTEDSPACE, "protected-space-insert",
335                   N_("Insert protected space"), Noop },
336                 { LFUN_QUOTE, "quote-insert", N_("Insert quote"), Noop },
337                 { LFUN_RECONFIGURE, "reconfigure",
338                   N_("Reconfigure"), NoBuffer },
339                 { LFUN_REDO, "redo", N_("Redo"), Noop },
340                 { LFUN_REF_GOTO, "reference-goto", "", ReadOnly },
341                 { LFUN_REF_INSERT, "reference-insert",
342                   N_("Insert cross reference"), ReadOnly },
343                 { LFUN_REFERENCE_GOTO, "reference-next", "", ReadOnly },
344                 { LFUN_NEXT, "screen-down", "", ReadOnly },
345                 { LFUN_NEXTSEL, "screen-down-select", "", ReadOnly },
346                 { LFUN_SCREEN_FONT_UPDATE, "screen-font-update",
347                   "", NoBuffer },
348                 { LFUN_CENTER, "screen-recenter", "", ReadOnly },
349                 { LFUN_PRIOR, "screen-up", "", ReadOnly },
350                 { LFUN_PRIORSEL, "screen-up-select", "", ReadOnly },
351                 { LFUN_SCROLL_INSET, "inset-scroll", N_("Scroll inset"),
352                   ReadOnly },
353                 { LFUN_SELFINSERT, "self-insert", "", Noop },
354                 { LFUN_CHARATCURSOR, "server-char-after", "", ReadOnly },
355                 { LFUN_GETFONT, "server-get-font", "", ReadOnly },
356                 { LFUN_GETLAYOUT, "server-get-layout", "", ReadOnly },
357                 { LFUN_GETNAME, "server-get-name", "", ReadOnly },
358                 { LFUN_GETTIP, "server-get-tip", "", ReadOnly },
359                 { LFUN_GETXY, "server-get-xy", "", ReadOnly },
360                 { LFUN_GOTOFILEROW, "server-goto-file-row", "", Noop },
361                 { LFUN_NOTIFY, "server-notify", "", ReadOnly },
362                 { LFUN_SETXY, "server-set-xy", "", ReadOnly },
363                 { LFUN_SET_COLOR, "set-color", "", ReadOnly|NoBuffer },
364                 { LFUN_SPELLCHECK, "spellchecker", "", Noop },
365                 { LFUN_SHIFT_TAB, "tab-backward", "", Noop },
366                 { LFUN_TAB, "tab-forward", "", Noop },
367                 { LFUN_TABINSERT, "tab-insert", "", Noop },
368                 { LFUN_DIALOG_TABULAR_INSERT, "dialog-tabular-insert",
369                   N_("Insert Table"), Noop },
370                 { LFUN_TABULAR_FEATURE, "tabular-feature",
371                   N_("Tabular Features"), Noop },
372                 { LFUN_INSET_TABULAR, "tabular-insert",
373                   N_("Insert a new Tabular Inset"), Noop },
374 #if 0
375                 { LFUN_INSET_THEOREM, "theorem-insert", "", Noop },
376 #endif
377                 { LFUN_THESAURUS_ENTRY, "thesaurus-entry", N_("Open thesaurus"), ReadOnly },
378                 { LFUN_TOC_INSERT, "toc-insert",
379                   N_("Insert table of contents"), Noop },
380                 { LFUN_TOCVIEW, "toc-view",
381                   N_("View table of contents"), ReadOnly },
382                 { LFUN_TOGGLECURSORFOLLOW, "toggle-cursor-follows-scrollbar",
383                   N_("Toggle cursor does/doesn't follow the scrollbar"),
384                   ReadOnly },
385                 { LFUN_ADD_TO_TOOLBAR, "toolbar-add-to", "", NoBuffer },
386                 { LFUN_PUSH_TOOLBAR, "toolbar-push", "", NoBuffer },
387                 { LFUN_UNDO, "undo", N_("Undo"), Noop },
388                 { LFUN_UP, "up", "", ReadOnly },
389                 { LFUN_UPSEL, "up-select", "", ReadOnly },
390                 { LFUN_URL, "url-insert", "", Noop },
391                 { LFUN_INSERT_URL, "", "internal only", Noop },
392                 { LFUN_VC_CHECKIN, "vc-check-in", "", ReadOnly },
393                 { LFUN_VC_CHECKOUT, "vc-check-out", "", ReadOnly },
394                 { LFUN_VC_HISTORY, "vc-history", "", ReadOnly },
395                 { LFUN_VC_REGISTER, "vc-register",
396                   N_("Register document under version control"), ReadOnly },
397                 { LFUN_VC_REVERT, "vc-revert", "", ReadOnly },
398                 { LFUN_VC_UNDO, "vc-undo-last", "", ReadOnly },
399                 { LFUN_WORDLEFT, "word-backward", "", ReadOnly },
400                 { LFUN_WORDLEFTSEL, "word-backward-select", "", ReadOnly },
401                 { LFUN_CAPITALIZE_WORD, "word-capitalize", "", Noop },
402                 { LFUN_DELETE_WORD_BACKWARD, "word-delete-backward",
403                   "", Noop },
404                 { LFUN_DELETE_WORD_FORWARD, "word-delete-forward", "", Noop },
405                 { LFUN_WORDFINDBACKWARD, "word-find-backward", "", ReadOnly },
406                 { LFUN_WORDFINDFORWARD, "word-find-forward", "", ReadOnly },
407                 { LFUN_WORDRIGHT, "word-forward", "", ReadOnly },
408                 { LFUN_WORDRIGHTSEL, "word-forward-select", "", ReadOnly },
409                 { LFUN_LOWCASE_WORD, "word-lowcase", "", Noop },
410                 { LFUN_UPCASE_WORD, "word-upcase", "", Noop },
411                 { LFUN_MESSAGE, "message",
412                   N_("Show message in minibuffer"), NoBuffer },
413                 { LFUN_MESSAGE_PUSH, "message-push",
414                   N_("Push old message and show this one in minibuffer"),
415                   NoBuffer },
416                 { LFUN_MESSAGE_POP, "message-pop",
417                   N_("Pop old message and show it in the minibuffer"),
418                   NoBuffer },
419                 { LFUN_TRANSPOSE_CHARS, "chars-transpose", "", Noop },
420                 { LFUN_FLOAT_LIST, "float-list", "Insert a float list", Noop },
421                 { LFUN_ESCAPE, "escape", "", Noop },
422                 { LFUN_HELP_ABOUTLYX, "help-aboutlyx",
423                   N_("Display information about LyX"), NoBuffer },
424                 { LFUN_HELP_TEXINFO, "help-Texinfo",
425                   N_("Display information about the TeX installation"), NoBuffer },
426                 { LFUN_FORKS_SHOW, "show-forks",
427                   N_("Show the processes forked by LyX"), NoBuffer },
428                 { LFUN_FORKS_KILL, "kill-forks",
429                   N_("Kill the forked process with this PID"), NoBuffer },
430                 { LFUN_TOOLTIPS_TOGGLE, "toggle-tooltips", "", NoBuffer },
431                 { LFUN_NOACTION, "", "", Noop }
432         };
433
434         int i = 0;
435         while (items[i].action != LFUN_NOACTION) {
436                 newFunc(items[i].action,
437                         items[i].name,
438                         _(items[i].helpText),
439                         items[i].attrib);
440                 ++i;
441         }
442
443         init = true;
444 }
445
446
447 LyXAction::LyXAction()
448 {
449         init();
450 }
451
452
453 // Search for an existent pseudoaction, return LFUN_UNKNOWN_ACTION
454 // if it doesn't exist.
455 int LyXAction::searchActionArg(kb_action action, string const & arg) const
456 {
457         arg_map::const_iterator pit = lyx_arg_map.find(action);
458
459         if (pit == lyx_arg_map.end()) {
460                 // the action does not have any pseudoactions
461                 lyxerr[Debug::ACTION] << "Action " << action
462                                       << " does not have any pseudo actions."
463                                       << endl;
464                 return LFUN_UNKNOWN_ACTION;
465         }
466
467         arg_item::const_iterator aci = pit->second.find(arg);
468
469         if (aci == pit->second.end()) {
470                 // the action does not have any pseudoactions with this arg
471                 lyxerr[Debug::ACTION]
472                         << "Action " << action
473                         << "does not have any pseudoactions with arg "
474                         << arg << endl;
475                 return LFUN_UNKNOWN_ACTION;
476         }
477
478         // pseudo action exist
479         lyxerr[Debug::ACTION] << "Pseudoaction exist["
480                               << action << '|'
481                               << arg << "] = " << aci->second << endl;
482
483         return aci->second;
484 }
485
486
487 // Returns a pseudo-action given an action and its argument.
488 int LyXAction::getPseudoAction(kb_action action, string const & arg) const
489 {
490         int const psdaction = searchActionArg(action, arg);
491
492         if (isPseudoAction(psdaction)) return psdaction;
493
494         static unsigned int pseudo_counter = LFUN_LASTACTION;
495
496         // Create new pseudo action.
497         pseudo_func tmp_p;
498         tmp_p.action = action;
499         tmp_p.arg = arg;
500         lyx_pseudo_map[++pseudo_counter] = tmp_p;
501
502         // First ensure that the action is in lyx_arg_map;
503         lyx_arg_map[action];
504         // get the arg_item map
505         arg_map::iterator ami = lyx_arg_map.find(action);
506         // put the new pseudo function in it
507         ami->second[arg] = pseudo_counter;
508
509         lyxerr[Debug::ACTION] << "Creating new pseudoaction "
510                               << pseudo_counter << " for [" << action
511                               << '|' << arg << "]\n";
512
513         return pseudo_counter;
514 }
515
516
517 // Retrieves the real action and its argument.
518 // perhaps a pair<kb_action, string> should be returned?
519 kb_action LyXAction::retrieveActionArg(int pseudo, string & arg) const
520 {
521         arg.erase(); // clear it to be sure.
522
523         if (!isPseudoAction(pseudo))
524                 return static_cast<kb_action>(pseudo);
525
526         pseudo_map::const_iterator pit = lyx_pseudo_map.find(pseudo);
527
528         if (pit != lyx_pseudo_map.end()) {
529                 lyxerr[Debug::ACTION] << "Found the pseudoaction: ["
530                                       << pit->second.action << '|'
531                                       << pit->second.arg << "]\n";
532                 arg = pit->second.arg;
533                 return pit->second.action;
534         } else {
535                 lyxerr << "Lyx Error: Unrecognized pseudo-action\n";
536                 return LFUN_UNKNOWN_ACTION;
537         }
538 }
539
540
541 // Returns an action tag from a string.
542 int LyXAction::LookupFunc(string const & func) const
543 {
544         if (func.empty()) return LFUN_NOACTION;
545
546         // split action and arg
547         string actstr;
548         string const argstr = split(func, actstr, ' ');
549         lyxerr[Debug::ACTION] << "Action: " << actstr << '\n';
550         lyxerr[Debug::ACTION] << "Arg   : " << argstr << '\n';
551
552         func_map::const_iterator fit = lyx_func_map.find(actstr);
553
554         if (!argstr.empty() && fit != lyx_func_map.end()) {
555                 // might be pseudo (or create one)
556                 return getPseudoAction(fit->second, argstr);
557         }
558
559         return fit != lyx_func_map.end() ? fit->second : LFUN_UNKNOWN_ACTION;
560 }
561
562
563 //#ifdef WITH_WARNINGS
564 //#warning Not working as it should.
565 //#endif
566 // I have no clue what is wrong with it... (Lgb)
567 int LyXAction::getApproxFunc(string const & func) const
568         // This func should perhaps also be able to return a list of all
569         // actions that has func as a prefix. That should actually be quite
570         // easy, just let it return a vector<int> or something.
571 {
572         int action = LookupFunc(func);
573         if (action == LFUN_UNKNOWN_ACTION) {
574                 // func is not an action, but perhaps it is
575                 // part of one...check if it is prefix if one of the
576                 // actions.
577                 // Checking for prefix is not so simple, but
578                 // using a simple bounding function gives
579                 // a similar result.  [ale 19981103]
580                 func_map::const_iterator fit =
581                         lyx_func_map.lower_bound(func);
582
583                 if (fit != lyx_func_map.end()) {
584                         action =  fit->second;
585                 }
586         } else {  // Go get the next function
587                 func_map::const_iterator fit =
588                         lyx_func_map.upper_bound(func);
589
590                 if (fit != lyx_func_map.end()) {
591                         action =  fit->second;
592                 }
593         }
594
595         return action;
596 }
597
598
599 string const LyXAction::getApproxFuncName(string const & func) const
600 {
601         int const f = getApproxFunc(func);
602         // This will return empty string if f isn't an action.
603         return getActionName(f);
604 }
605
606
607 string const LyXAction::getActionName(int action) const
608 {
609         kb_action ac;
610         string arg;
611
612         ac = retrieveActionArg(action, arg);
613         if (!arg.empty())
614                 arg.insert(0, " ");
615
616         info_map::const_iterator iit = lyx_info_map.find(ac);
617
618         if (iit != lyx_info_map.end()) {
619                 string ret(iit->second.name);
620                 ret += arg;
621                 return ret;
622         } else
623                 return string();
624 }
625
626
627 // Returns one line help associated with a (pseudo)action, i.e. appends
628 // the argument of the action if necessary
629 string const LyXAction::helpText(int pseudoaction) const
630 {
631         string help, arg;
632         kb_action action;
633
634         action = retrieveActionArg(pseudoaction, arg);
635
636         info_map::const_iterator ici = lyx_info_map.find(action);
637         if (ici != lyx_info_map.end()) {
638                 if (lyxerr.debugging(Debug::ACTION)) {
639                         lyxerr << "Action: " << action << '\n';
640                         lyxerr << "   name: "
641                                << ici->second.name << '\n';
642                         lyxerr << " attrib: "
643                                << ici->second.attrib << '\n';
644                         lyxerr << "   help: "
645                                << ici->second.helpText << '\n';
646                 }
647                 help = ici->second.helpText;
648                 // if the is no help text use the name of the func instead.
649                 if (help.empty()) help = ici->second.name;
650         }
651
652         if (help.empty()) {
653                 help = _("No description available!");
654         } else if (!arg.empty()) {
655                 help += ' ';
656                 help += arg;
657         }
658
659         return help;
660 }
661
662
663 bool LyXAction::funcHasFlag(kb_action action,
664                             LyXAction::func_attrib flag) const
665 {
666         info_map::const_iterator ici = lyx_info_map.find(action);
667
668         if (ici != lyx_info_map.end()) {
669                 return ici->second.attrib & flag;
670         } else {
671                 // it really should exist, but...
672                 lyxerr << "LyXAction::funcHasFlag: "
673                         "No info about kb_action: " << action << '\n';
674                 return false;
675         }
676 }
677
678
679 LyXAction::const_func_iterator LyXAction::func_begin() const
680 {
681         return lyx_func_map.begin();
682 }
683
684
685 LyXAction::const_func_iterator LyXAction::func_end() const
686 {
687         return lyx_func_map.end();
688 }
689
690
691 ostream & operator<<(ostream & o, kb_action action)
692 {
693         return o << int(action);
694 }