]> git.lyx.org Git - lyx.git/blob - src/LyXAction.C
copy some code over to allow work to start on prefs
[lyx.git] / src / LyXAction.C
1 /**
2  * \file LyXAction.C
3  * Copyright 1995-2002 the LyX Team
4  * Read the file COPYING
5  */
6
7 #include <config.h>
8
9 #ifdef __GNUG__
10 #pragma implementation
11 #endif
12
13 #include "LyXAction.h"
14
15 #include "debug.h"
16 #include "gettext.h"
17 #include "support/lstrings.h"
18
19 using std::ostream;
20 using std::endl;
21 using std::pair;
22 using std::make_pair;
23
24 /*
25      NAMING RULES FOR USER-COMMANDS
26      Here's the set of rules to apply when a new command name is introduced:
27
28      1) Use the object.event order. That is, use `word-forward'
29         instead of `forward-word'.
30      2) Don't introduce an alias for an already named object. Same for events.
31      3) Forward movement or focus is called `forward' (not `right').
32      4) Backward movement or focus is called `backward' (not `left').
33      5) Upward movement of focus is called `up'.
34      6) Downward movement is called `down'.
35      7) The begin of an object is called `begin' (not `start').
36      8) The end of an object is called `end'.
37
38      (May 19 1996, 12:04, RvdK)
39 */
40
41 LyXAction lyxaction;
42
43 namespace {
44
45 /// return true if the given action is a pseudo-action
46 inline bool isPseudoAction(int a)
47 {
48         return a > int(LFUN_LASTACTION);
49 }
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 ev_item {
78                 kb_action action;
79                 char const * name;
80                 char const * helpText;
81                 unsigned int attrib;
82         };
83
84         ev_item const 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", N_("Open a file"), NoBuffer },
200                 { LFUN_MENUSEARCH, "find-replace", N_("Find & Replace"),
201                   ReadOnly },
202                 { LFUN_INSET_FLOAT, "float-insert", N_("Insert a Float"), Noop },
203                 { LFUN_INSET_WIDE_FLOAT, "float-wide-insert",
204                   N_("Insert a wide Float"), Noop },
205                 { LFUN_INSET_WRAP, "wrap-insert", N_("Insert a Wrap"), Noop },
206                 { LFUN_BOLD, "font-bold", N_("Toggle bold"), Noop },
207                 { LFUN_CODE, "font-code", N_("Toggle code style"), Noop },
208                 { LFUN_DEFAULT, "font-default", N_("Default font style"),
209                   Noop },
210                 { LFUN_EMPH, "font-emph", N_("Toggle emphasize"), Noop },
211                 { LFUN_FREE, "font-free", N_("Toggle user defined style"),
212                   Noop },
213                 { LFUN_NOUN, "font-noun", N_("Toggle noun style"), Noop },
214                 { LFUN_ROMAN, "font-roman", N_("Toggle roman font style"),
215                   Noop },
216                 { LFUN_SANS, "font-sans", N_("Toggle sans font style"), Noop },
217                 { LFUN_FRAK, "font-frak", N_("Toggle fraktur font style"), Noop },
218                 { LFUN_ITAL, "font-ital", N_("Toggle italic font style"), Noop },
219                 { LFUN_FONT_SIZE, "font-size", N_("Set font size"), Noop },
220                 { LFUN_FONT_STATE, "font-state", N_("Show font state"),
221                   ReadOnly },
222                 { LFUN_UNDERLINE, "font-underline",
223                   N_("Toggle font underline"), Noop },
224                 { LFUN_INSET_FOOTNOTE, "footnote-insert",
225                   N_("Insert Footnote"), Noop },
226                 { LFUN_RIGHTSEL, "forward-select", N_("Select next char"),
227                   ReadOnly },
228                 { LFUN_HFILL, "hfill-insert",
229                   N_("Insert horizontal fill"), Noop },
230                 { LFUN_HELP_OPEN, "help-open", N_("Open a Help file"),
231                   NoBuffer|Argument},
232                 { LFUN_HTMLURL, "html-insert", "", Noop },
233                 { LFUN_HYPHENATION, "hyphenation-point-insert",
234                   N_("Insert hyphenation point"), Noop },
235                 { LFUN_LIGATURE_BREAK, "ligature-break-insert",
236                   N_("Insert ligature break"), Noop },
237                 { LFUN_INDEX_INSERT, "index-insert",
238                   N_("Insert index item"), Noop },
239                 { LFUN_INDEX_PRINT, "index-print", N_("Insert index list"),
240                   Noop },
241                 { LFUN_KMAP_OFF, "keymap-off", N_("Turn off keymap"),
242                   ReadOnly },
243                 { LFUN_KMAP_PRIM, "keymap-primary",
244                   N_("Use primary keymap"), ReadOnly },
245                 { LFUN_KMAP_SEC, "keymap-secondary",
246                   N_("Use secondary keymap"), ReadOnly },
247                 { LFUN_KMAP_TOGGLE, "keymap-toggle", N_("Toggle keymap"),
248                   ReadOnly },
249                 { LFUN_INSERT_LABEL, "label-insert", N_("Insert Label"),
250                   Noop },
251                 { LFUN_INSET_OPTARG, "optional-insert", N_("Insert Optional Argument"),
252                   Noop },
253                 { LFUN_LANGUAGE, "language", N_("Change language"), Noop },
254                 { LFUN_LATEX_LOG, "latex-view-log", N_("View LaTeX log"),
255                   ReadOnly },
256                 { LFUN_LAYOUT, "layout", "", Noop },
257                 { LFUN_LAYOUT_CHARACTER, "layout-character", "", Noop },
258                 { LFUN_LAYOUT_COPY, "layout-copy",
259                   N_("Copy paragraph environment type"), Noop },
260                 { LFUN_LAYOUT_DOCUMENT, "layout-document", "", ReadOnly },
261                 { LFUN_LAYOUT_PARAGRAPH, "layout-paragraph", "", ReadOnly },
262                 { LFUN_LAYOUT_PASTE, "layout-paste",
263                   N_("Paste paragraph environment type"), Noop },
264                 { LFUN_LAYOUT_PREAMBLE, "layout-preamble", "", ReadOnly },
265                 { LFUN_LAYOUT_TABULAR, "layout-tabular",
266                   N_("Open the tabular layout"), Noop },
267                 { LFUN_HOME, "line-begin",
268                   N_("Go to beginning of line"), ReadOnly },
269                 { LFUN_HOMESEL, "line-begin-select",
270                   N_("Select to beginning of line"), ReadOnly },
271                 { LFUN_DELETE_LINE_FORWARD, "line-delete-forward", "", Noop },
272                 { LFUN_END, "line-end", N_("Go to end of line"), ReadOnly },
273                 { LFUN_ENDSEL, "line-end-select",
274                   N_("Select to end of line"), ReadOnly },
275 #if 0
276                 { LFUN_INSET_LIST, "list-insert", "", Noop },
277 #endif
278                 { LFUN_QUIT, "lyx-quit", N_("Exit"), NoBuffer },
279                 { LFUN_INSET_MARGINAL, "marginalnote-insert",
280                   N_("Insert margin note"), Noop },
281                 { LFUN_MARK_OFF, "mark-off", "", ReadOnly },
282                 { LFUN_MARK_ON, "mark-on", "", ReadOnly },
283                 { LFUN_SETMARK, "mark-toggle", "", ReadOnly },
284                 { LFUN_MATH_DELIM, "math-delim", "", Noop },
285                 { LFUN_MATH_DISPLAY, "math-display", "", Noop },
286                 { LFUN_GREEK, "math-greek", N_("Math Greek"), Noop },
287                 { LFUN_GREEK_TOGGLE, "math-greek-toggle", "", Noop },
288                 { LFUN_INSERT_MATH, "math-insert",
289                   N_("Insert math symbol"), Noop },
290                 { LFUN_SUBSCRIPT, "math-subscript", N_("Add subscript"), Noop },
291                 { LFUN_SUPERSCRIPT, "math-superscript", N_("Add superscript"), Noop },
292                 { LFUN_MATH_LIMITS, "math-limits", "", Noop },
293                 { LFUN_MATH_MACRO, "math-macro", "", Noop },
294                 { LFUN_MATH_MUTATE, "math-mutate", "", Noop },
295                 { LFUN_MATH_SPACE, "math-space", "", Noop },
296                 { LFUN_MATH_IMPORT_SELECTION, "math-import-selection", "", Noop },
297                 { LFUN_INSERT_MATRIX, "math-matrix", "", Noop },
298                 { LFUN_MATH_MODE, "math-mode", N_("Math mode"), Noop },
299                 { LFUN_MATH_NONUMBER, "math-nonumber", "", Noop },
300                 { LFUN_MATH_NUMBER, "math-number", "", Noop },
301                 { LFUN_MATH_EXTERN, "math-extern", "", Noop },
302                 { LFUN_MATH_PANEL, "math-panel", "", Noop },
303                 { LFUN_MATH_SIZE, "math-size", "", Noop },
304                 { LFUN_MENU_OPEN_BY_NAME, "menu-open", "", NoBuffer },
305                 { LFUN_MENU_SEPARATOR, "menu-separator-insert", "", Noop },
306                 { LFUN_META_FAKE, "meta-prefix", "", NoBuffer },
307                 { LFUN_INSET_MINIPAGE, "minipage-insert", "", Noop },
308                 { LFUN_INSERT_NOTE, "note-insert", "", Noop },
309                 { LFUN_GOTONOTE, "note-next", "", ReadOnly },
310                 { LFUN_INSET_TOGGLE, "inset-toggle",
311                   N_("toggle inset"), ReadOnly },
312                 { LFUN_DOWN_PARAGRAPH, "paragraph-down",
313                   N_("Go one paragraph down"), ReadOnly },
314                 { LFUN_DOWN_PARAGRAPHSEL, "paragraph-down-select",
315                   N_("Select next paragraph"), ReadOnly },
316                 { LFUN_GOTO_PARAGRAPH, "paragraph-goto",
317                   N_("Go to paragraph"), ReadOnly },
318                 { LFUN_PARAGRAPH_SPACING, "paragraph-spacing", "", Noop },
319                 { LFUN_UP_PARAGRAPH, "paragraph-up",
320                   N_("Go one paragraph up"), ReadOnly },
321                 { LFUN_UP_PARAGRAPHSEL, "paragraph-up-select",
322                   N_("Select previous paragraph"), ReadOnly },
323                 { LFUN_PARENTINSERT, "parent-insert", "", Noop },
324                 { LFUN_PASTE, "paste", N_("Paste") , Noop },
325                 { LFUN_DIALOG_PREFERENCES, "dialog-preferences",
326                   N_("Edit Preferences"), NoBuffer },
327                 { LFUN_SAVEPREFERENCES, "preferences-save",
328                   N_("Save Preferences"), NoBuffer },
329                 { LFUN_PASTESELECTION, "primary-selection-paste", "", Noop },
330                 { LFUN_PROTECTEDSPACE, "protected-space-insert",
331                   N_("Insert protected space"), Noop },
332                 { LFUN_QUOTE, "quote-insert", N_("Insert quote"), Noop },
333                 { LFUN_RECONFIGURE, "reconfigure",
334                   N_("Reconfigure"), NoBuffer },
335                 { LFUN_REDO, "redo", N_("Redo"), Noop },
336                 { LFUN_REF_GOTO, "reference-goto", "", ReadOnly },
337                 { LFUN_REF_INSERT, "reference-insert",
338                   N_("Insert cross reference"), ReadOnly },
339                 { LFUN_REFERENCE_GOTO, "reference-next", "", ReadOnly },
340                 { LFUN_NEXT, "screen-down", "", ReadOnly },
341                 { LFUN_NEXTSEL, "screen-down-select", "", ReadOnly },
342                 { LFUN_SCREEN_FONT_UPDATE, "screen-font-update",
343                   "", NoBuffer },
344                 { LFUN_CENTER, "screen-recenter", "", ReadOnly },
345                 { LFUN_PRIOR, "screen-up", "", ReadOnly },
346                 { LFUN_PRIORSEL, "screen-up-select", "", ReadOnly },
347                 { LFUN_SCROLL_INSET, "inset-scroll", N_("Scroll inset"),
348                   ReadOnly },
349                 { LFUN_SELFINSERT, "self-insert", "", Noop },
350                 { LFUN_CHARATCURSOR, "server-char-after", "", ReadOnly },
351                 { LFUN_GETFONT, "server-get-font", "", ReadOnly },
352                 { LFUN_GETLAYOUT, "server-get-layout", "", ReadOnly },
353                 { LFUN_GETNAME, "server-get-name", "", ReadOnly },
354                 { LFUN_GETTIP, "server-get-tip", "", ReadOnly },
355                 { LFUN_GETXY, "server-get-xy", "", ReadOnly },
356                 { LFUN_GOTOFILEROW, "server-goto-file-row", "", Noop },
357                 { LFUN_NOTIFY, "server-notify", "", ReadOnly },
358                 { LFUN_SETXY, "server-set-xy", "", ReadOnly },
359                 { LFUN_SET_COLOR, "set-color", "", ReadOnly|NoBuffer },
360                 { LFUN_SPELLCHECK, "spellchecker", "", Noop },
361                 { LFUN_SHIFT_TAB, "tab-backward", "", Noop },
362                 { LFUN_TAB, "tab-forward", "", Noop },
363                 { LFUN_TABINSERT, "tab-insert", "", Noop },
364                 { LFUN_TABULAR_INSERT, "tabular-insert", N_("Insert Table"), Noop },
365                 { LFUN_TABULAR_FEATURE, "tabular-feature",
366                   N_("Tabular Features"), Noop },
367 #if 0
368                 { LFUN_INSET_THEOREM, "theorem-insert", "", Noop },
369 #endif
370                 { LFUN_THESAURUS_ENTRY, "thesaurus-entry", N_("Open thesaurus"), ReadOnly },
371                 { LFUN_TOC_INSERT, "toc-insert",
372                   N_("Insert table of contents"), Noop },
373                 { LFUN_TOCVIEW, "toc-view",
374                   N_("View table of contents"), ReadOnly },
375                 { LFUN_TOGGLECURSORFOLLOW, "toggle-cursor-follows-scrollbar",
376                   N_("Toggle cursor does/doesn't follow the scrollbar"),
377                   ReadOnly },
378                 { LFUN_UNDO, "undo", N_("Undo"), Noop },
379                 { LFUN_UP, "up", "", ReadOnly },
380                 { LFUN_UPSEL, "up-select", "", ReadOnly },
381                 { LFUN_URL, "url-insert", "", Noop },
382                 { LFUN_INSERT_URL, "", "internal only", Noop },
383                 { LFUN_VC_CHECKIN, "vc-check-in", "", ReadOnly },
384                 { LFUN_VC_CHECKOUT, "vc-check-out", "", ReadOnly },
385                 { LFUN_VC_HISTORY, "vc-history", "", ReadOnly },
386                 { LFUN_VC_REGISTER, "vc-register",
387                   N_("Register document under version control"), ReadOnly },
388                 { LFUN_VC_REVERT, "vc-revert", "", ReadOnly },
389                 { LFUN_VC_UNDO, "vc-undo-last", "", ReadOnly },
390                 { LFUN_WORDLEFT, "word-backward", "", ReadOnly },
391                 { LFUN_WORDLEFTSEL, "word-backward-select", "", ReadOnly },
392                 { LFUN_CAPITALIZE_WORD, "word-capitalize", "", Noop },
393                 { LFUN_DELETE_WORD_BACKWARD, "word-delete-backward",
394                   "", Noop },
395                 { LFUN_DELETE_WORD_FORWARD, "word-delete-forward", "", Noop },
396                 { LFUN_WORDFINDBACKWARD, "word-find-backward", "", ReadOnly },
397                 { LFUN_WORDFINDFORWARD, "word-find-forward", "", ReadOnly },
398                 { LFUN_WORDRIGHT, "word-forward", "", ReadOnly },
399                 { LFUN_WORDRIGHTSEL, "word-forward-select", "", ReadOnly },
400                 { LFUN_LOWCASE_WORD, "word-lowcase", "", Noop },
401                 { LFUN_WORDSEL, "word-select", "", ReadOnly },
402                 { LFUN_UPCASE_WORD, "word-upcase", "", Noop },
403                 { LFUN_MESSAGE, "message",
404                   N_("Show message in minibuffer"), NoBuffer },
405                 { LFUN_TRANSPOSE_CHARS, "chars-transpose", "", Noop },
406                 { LFUN_FLOAT_LIST, "float-list", "Insert a float list", Noop },
407                 { LFUN_ESCAPE, "escape", "", Noop },
408                 { LFUN_HELP_ABOUTLYX, "help-aboutlyx",
409                   N_("Display information about LyX"), NoBuffer },
410                 { LFUN_HELP_TEXINFO, "help-Texinfo",
411                   N_("Display information about the TeX installation"), NoBuffer },
412                 { LFUN_FORKS_SHOW, "show-forks",
413                   N_("Show the processes forked by LyX"), NoBuffer },
414                 { LFUN_FORKS_KILL, "kill-forks",
415                   N_("Kill the forked process with this PID"), NoBuffer },
416                 { LFUN_TOOLTIPS_TOGGLE, "toggle-tooltips", "", NoBuffer },
417                 { LFUN_NOACTION, "", "", Noop }
418         };
419
420         for (int i = 0; items[i].action != LFUN_NOACTION; ++i) {
421                 newFunc(items[i].action, items[i].name,
422                         _(items[i].helpText), items[i].attrib);
423         }
424
425         init = true;
426 }
427
428
429 LyXAction::LyXAction()
430 {
431         init();
432 }
433
434
435 int LyXAction::searchActionArg(kb_action action, string const & arg) const
436 {
437         arg_map::const_iterator pit = lyx_arg_map.find(action);
438
439         if (pit == lyx_arg_map.end()) {
440                 lyxerr[Debug::ACTION] << "Action " << action
441                                       << " does not have any pseudo actions."
442                                       << endl;
443                 return LFUN_UNKNOWN_ACTION;
444         }
445
446         arg_item::const_iterator aci = pit->second.find(arg);
447
448         if (aci == pit->second.end()) {
449                 lyxerr[Debug::ACTION]
450                         << "Action " << action
451                         << "does not have any pseudoactions with arg "
452                         << arg << endl;
453                 return LFUN_UNKNOWN_ACTION;
454         }
455
456         lyxerr[Debug::ACTION] << "Pseudoaction exists["
457                               << action << '|'
458                               << arg << "] = " << aci->second << endl;
459
460         return aci->second;
461 }
462
463
464 int LyXAction::getPseudoAction(kb_action action, string const & arg)
465 {
466         int const psdaction = searchActionArg(action, arg);
467
468         if (isPseudoAction(psdaction)) return psdaction;
469
470         static unsigned int pseudo_counter = LFUN_LASTACTION;
471
472         // Create new pseudo action.
473         lyx_pseudo_map[++pseudo_counter] = FuncRequest(0, action, arg);
474
475         // First ensure that the action is in lyx_arg_map;
476         lyx_arg_map[action];
477         // get the arg_item map
478         arg_map::iterator ami = lyx_arg_map.find(action);
479         // put the new pseudo function in it
480         ami->second[arg] = pseudo_counter;
481
482         lyxerr[Debug::ACTION] << "Creating new pseudoaction "
483                               << pseudo_counter << " for [" << action
484                               << '|' << arg << "]\n";
485
486         return pseudo_counter;
487 }
488
489
490 FuncRequest LyXAction::retrieveActionArg(int pseudo) const
491 {
492         if (!isPseudoAction(pseudo))
493                 return FuncRequest(static_cast<kb_action>(pseudo));
494
495         pseudo_map::const_iterator pit = lyx_pseudo_map.find(pseudo);
496
497         if (pit != lyx_pseudo_map.end()) {
498                 lyxerr[Debug::ACTION] << "Found the pseudoaction: ["
499                                       << pit->second.action << '|'
500                                       << pit->second.argument << "]\n";
501                 return pit->second;
502         } else {
503                 lyxerr << "Lyx Error: Unrecognized pseudo-action "
504                         << pseudo << endl;
505                 return FuncRequest(LFUN_UNKNOWN_ACTION);
506         }
507 }
508
509
510 // Returns an action tag from a string.
511 int LyXAction::LookupFunc(string const & func)
512 {
513         string const func2 = trim(func);
514         if (func2.empty()) return LFUN_NOACTION;
515
516         // split action and arg
517         string actstr;
518         string const argstr = split(func2, actstr, ' ');
519         lyxerr[Debug::ACTION] << "Action: " << actstr << '\n';
520         lyxerr[Debug::ACTION] << "Arg   : " << argstr << '\n';
521
522         func_map::const_iterator fit = lyx_func_map.find(actstr);
523
524         if (!argstr.empty() && fit != lyx_func_map.end()) {
525                 // might be pseudo (or create one)
526                 return getPseudoAction(fit->second, argstr);
527         }
528
529         return fit != lyx_func_map.end() ? fit->second : LFUN_UNKNOWN_ACTION;
530 }
531
532
533 string const LyXAction::getActionName(int action) const
534 {
535         FuncRequest ev = retrieveActionArg(action);
536         if (!ev.argument.empty())
537                 ev.argument.insert(0, " ");
538
539         info_map::const_iterator const it = lyx_info_map.find(ev.action);
540
541         if (it != lyx_info_map.end())
542                 return it->second.name + ev.argument;
543         return string();
544 }
545
546
547 string const LyXAction::helpText(int pseudoaction) const
548 {
549         FuncRequest ev = retrieveActionArg(pseudoaction);
550
551         string help;
552  
553         info_map::const_iterator ici = lyx_info_map.find(ev.action);
554         if (ici != lyx_info_map.end()) {
555                 if (lyxerr.debugging(Debug::ACTION)) {
556                         lyxerr << "Action: " << ev.action << '\n';
557                         lyxerr << "   name: "
558                                << ici->second.name << '\n';
559                         lyxerr << " attrib: "
560                                << ici->second.attrib << '\n';
561                         lyxerr << "   help: "
562                                << ici->second.helpText << '\n';
563                 }
564                 help = ici->second.helpText;
565                 // if the is no help text use the name of the func instead.
566                 if (help.empty()) help = ici->second.name;
567         }
568
569         if (help.empty()) {
570                 help = _("No description available!");
571         } else if (!ev.argument.empty()) {
572                 help += ' ';
573                 help += ev.argument;
574         }
575
576         return help;
577 }
578
579
580 bool LyXAction::funcHasFlag(kb_action action,
581                             LyXAction::func_attrib flag) const
582 {
583         info_map::const_iterator ici = lyx_info_map.find(action);
584
585         if (ici != lyx_info_map.end()) {
586                 return ici->second.attrib & flag;
587         } else {
588                 // it really should exist, but...
589                 lyxerr << "LyXAction::funcHasFlag: "
590                         "No info about kb_action: " << action << '\n';
591                 return false;
592         }
593 }
594
595
596 LyXAction::const_func_iterator LyXAction::func_begin() const
597 {
598         return lyx_func_map.begin();
599 }
600
601
602 LyXAction::const_func_iterator LyXAction::func_end() const
603 {
604         return lyx_func_map.end();
605 }
606
607
608 ostream & operator<<(ostream & o, kb_action action)
609 {
610         return o << int(action);
611 }