]> git.lyx.org Git - lyx.git/blob - src/LyXAction.C
"ding-dong, the witch is dead!", says John
[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_BUFFER_PRINT, "buffer-print-xtl", N_("Print"),
139                   ReadOnly },
140                 { LFUN_PRINTER_PARAMS_GET, "printer-params-get",
141                   N_("Get the printer parameters"), ReadOnly },
142                 { LFUN_MENUNEW, "buffer-new", N_("New document") , NoBuffer },
143                 { LFUN_MENUNEWTMPLT,"buffer-new-template",
144                   N_("New document from template"), NoBuffer },
145                 { LFUN_MENUPRINT, "buffer-print", N_("Print"), ReadOnly },
146                 { LFUN_MENURELOAD, "buffer-reload",
147                   N_("Revert to saved"), ReadOnly },
148                 { LFUN_SWITCHBUFFER, "buffer-switch", 
149                   N_("Switch to an open document"), ReadOnly },
150                 { LFUN_READ_ONLY_TOGGLE, "buffer-toggle-read-only",
151                   N_("Toggle read-only"), ReadOnly },
152                 { LFUN_UPDATE, "buffer-update", N_("Update"), ReadOnly },
153                 { LFUN_PREVIEW, "buffer-view", N_("View") , ReadOnly },
154                 { LFUN_MENUWRITE, "buffer-write", N_("Save"), ReadOnly },
155                 { LFUN_WRITEAS, "buffer-write-as", N_("Save As"),
156                   ReadOnly },
157                 { LFUN_CANCEL, "cancel", N_("Cancel"), NoBuffer },
158                 { LFUN_INSET_CAPTION, "caption-insert", "", Noop },
159                 { LFUN_LEFT, "char-backward", N_("Go one char back"),
160                   ReadOnly },
161                 { LFUN_RIGHT, "char-forward", N_("Go one char forward"),
162                   ReadOnly },
163                 { LFUN_CITATION_CREATE, "citation-insert",
164                   N_("Insert citation"), Noop },
165                 { LFUN_CITATION_INSERT, "", "internal only", Noop },
166                 { LFUN_EXEC_COMMAND, "command-execute", "", NoBuffer },
167                 { LFUN_PREFIX, "command-prefix",
168                   N_("Execute command"), NoBuffer },
169                 { LFUN_SEQUENCE, "command-sequence", "", Noop },
170                 { LFUN_COPY, "copy", N_("Copy"), ReadOnly },
171                 { LFUN_CUT, "cut", N_("Cut"), Noop },
172                 { LFUN_DATE_INSERT, "date-insert", "", Noop },
173                 { LFUN_BACKSPACE, "delete-backward", "", Noop },
174                 { LFUN_BACKSPACE_SKIP, "delete-backward-skip", "", Noop },
175                 { LFUN_DELETE, "delete-forward", "", Noop },
176                 { LFUN_DELETE_SKIP, "delete-forward-skip", "", Noop },
177                 { LFUN_DEPTH_MIN, "depth-decrement",
178                   N_("Decrement environment depth"), Noop },
179                 { LFUN_DEPTH_PLUS, "depth-increment",
180                   N_("Increment environment depth"), Noop },
181                 { LFUN_DEPTH, "depth-next", 
182                   N_("Change environment depth"), Noop },
183                 { LFUN_LDOTS, "dots-insert", N_("Insert ... dots"), Noop },
184                 { LFUN_DOWN, "down", N_("Go down"), ReadOnly },
185                 { LFUN_DOWNSEL, "down-select",
186                   N_("Select next line"), ReadOnly },
187                 { LFUN_DROP_LAYOUTS_CHOICE, "drop-layouts-choice",
188                   N_("Choose Paragraph Environment"), ReadOnly },
189                 { LFUN_END_OF_SENTENCE, "end-of-sentence-period-insert",
190                   N_("Insert end of sentence period"), Noop },
191                 { LFUN_GOTOERROR, "error-next",
192                   N_("Go to next error"), ReadOnly },
193                 { LFUN_REMOVEERRORS, "error-remove-all",
194                   N_("Remove all error boxes"), ReadOnly },
195                 { LFUN_INSET_ERT, "ert-insert",
196                   N_("Insert a new ERT Inset"), Noop },
197                 { LFUN_INSET_EXTERNAL, "external-insert",
198                   N_("Insert a new external inset"), Noop },
199                 { LFUN_INSET_GRAPHICS, "graphics-insert",
200                   N_("Insert Graphics"), Noop },
201                 { LFUN_FILE_INSERT, "file-insert", "", Noop },
202                 { LFUN_FILE_INSERT_ASCII, "file-insert-ascii", _("Insert ASCII files as lines"), Noop },
203                 { LFUN_FILE_INSERT_ASCII_PARA, "file-insert-ascii-para", _("Insert ASCII file as a paragraph"), Noop },
204                 { LFUN_FILE_NEW, "file-new", "", NoBuffer },
205                 { LFUN_FILE_OPEN, "file-open", _("Open a file"), NoBuffer },
206                 { LFUN_MENUSEARCH, "find-replace", N_("Find & Replace"),
207                   ReadOnly },
208                 { LFUN_INSET_FLOAT, "float-insert", "Insert a Float", Noop },
209                 { LFUN_INSET_WIDE_FLOAT, "float-wide-insert",
210                   "Insert a wide Float", Noop },
211                 { LFUN_BOLD, "font-bold", N_("Toggle bold"), Noop },
212                 { LFUN_CODE, "font-code", N_("Toggle code style"), Noop },
213                 { LFUN_DEFAULT, "font-default", N_("Default font style"),
214                   Noop },
215                 { LFUN_EMPH, "font-emph", N_("Toggle emphasize"), Noop },
216                 { LFUN_FREE, "font-free", N_("Toggle user defined style"),
217                   Noop },
218                 { LFUN_NOUN, "font-noun", N_("Toggle noun style"), Noop },
219                 { LFUN_ROMAN, "font-roman", N_("Toggle roman font style"),
220                   Noop },
221                 { LFUN_SANS, "font-sans", N_("Toggle sans font style"), Noop },
222                 { LFUN_FRAK, "font-frak", N_("Toggle fraktur font style"), Noop },
223                 { LFUN_ITAL, "font-ital", N_("Toggle italic font style"), Noop },
224                 { LFUN_FONT_SIZE, "font-size", N_("Set font size"), Noop },
225                 { LFUN_FONT_STATE, "font-state", N_("Show font state"),
226                   ReadOnly },
227                 { LFUN_UNDERLINE, "font-underline",
228                   N_("Toggle font underline"), Noop },
229                 { LFUN_INSET_FOOTNOTE, "footnote-insert",
230                   N_("Insert Footnote"), Noop },
231                 { LFUN_RIGHTSEL, "forward-select", N_("Select next char"),
232                   ReadOnly },
233                 { LFUN_HFILL, "hfill-insert",
234                   N_("Insert horizontal fill"), Noop },
235                 { LFUN_HELP_OPEN, "help-open", N_("Open a Help file"), 
236                   NoBuffer|Argument},
237                 { LFUN_HTMLURL, "html-insert", "", Noop },
238                 { LFUN_HYPHENATION, "hyphenation-point-insert",
239                   N_("Insert hyphenation point"), Noop },
240                 { LFUN_LIGATURE_BREAK, "ligature-break-insert",
241                   N_("Insert ligature break"), Noop },
242                 { LFUN_INDEX_CREATE, "index-insert",
243                   N_("Insert index item"), Noop },
244                 { LFUN_INDEX_INSERT_LAST, "index-insert-last",
245                   N_("Insert last index item"), Noop },
246                 { LFUN_INDEX_PRINT, "index-print", N_("Insert index list"),
247                   Noop },
248                 { LFUN_KMAP_OFF, "keymap-off", N_("Turn off keymap"),
249                   ReadOnly },
250                 { LFUN_KMAP_PRIM, "keymap-primary",
251                   N_("Use primary keymap"), ReadOnly },
252                 { LFUN_KMAP_SEC, "keymap-secondary",
253                   N_("Use secondary keymap"), ReadOnly },
254                 { LFUN_KMAP_TOGGLE, "keymap-toggle", N_("Toggle keymap"),
255                   ReadOnly },
256                 { LFUN_INSERT_LABEL, "label-insert", N_("Insert Label"),
257                   Noop },
258                 { LFUN_LANGUAGE, "language", N_("Change language"), Noop },
259                 { LFUN_LATEX_LOG, "latex-view-log", N_("View LaTeX log"),
260                   ReadOnly },
261                 { LFUN_LAYOUT, "layout", "", Noop },
262                 { LFUN_LAYOUT_CHARACTER, "layout-character", "", Noop },
263                 { LFUN_LAYOUT_COPY, "layout-copy",
264                   N_("Copy paragraph environment type"), Noop },
265                 { LFUN_LAYOUT_DOCUMENT, "layout-document", "", ReadOnly },
266                 { LFUN_LAYOUT_PARAGRAPH, "layout-paragraph", "", ReadOnly },
267                 { LFUN_LAYOUT_PASTE, "layout-paste",
268                   N_("Paste paragraph environment type"), Noop },
269                 { LFUN_LAYOUT_PREAMBLE, "layout-preamble", "", ReadOnly },
270                 { LFUN_LAYOUT_TABULAR, "layout-tabular",
271                   N_("Open the tabular layout"), Noop },
272                 { LFUN_HOME, "line-begin",
273                   N_("Go to beginning of line"), ReadOnly },
274                 { LFUN_HOMESEL, "line-begin-select",
275                   N_("Select to beginning of line"), ReadOnly },
276                 { LFUN_DELETE_LINE_FORWARD, "line-delete-forward", "", Noop },
277                 { LFUN_END, "line-end", N_("Go to end of line"), ReadOnly },
278                 { LFUN_ENDSEL, "line-end-select",
279                   N_("Select to end of line"), ReadOnly },
280 #if 0
281                 { LFUN_INSET_LIST, "list-insert", "", Noop },
282 #endif
283                 { LFUN_QUIT, "lyx-quit", N_("Exit"), NoBuffer },
284                 { LFUN_INSET_MARGINAL, "marginalnote-insert",
285                   N_("Insert Marginalnote"), Noop },
286                 { LFUN_MARK_OFF, "mark-off", "", ReadOnly },
287                 { LFUN_MARK_ON, "mark-on", "", ReadOnly },
288                 { LFUN_SETMARK, "mark-toggle", "", ReadOnly },
289                 { LFUN_MATH_DELIM, "math-delim", "", Noop },
290                 { LFUN_MATH_DISPLAY, "math-display", "", Noop },
291                 { LFUN_GREEK, "math-greek", N_("Math Greek"), Noop },
292                 { LFUN_GREEK_TOGGLE, "math-greek-toggle", "", Noop },
293                 { LFUN_INSERT_MATH, "math-insert",
294                   N_("Insert math symbol"), Noop },
295                 { LFUN_SUBSCRIPT, "math-subscript", "", Noop },
296                 { LFUN_SUPERSCRIPT, "math-superscript", "", Noop },
297                 { LFUN_MATH_LIMITS, "math-limits", "", Noop },
298                 { LFUN_MATH_MACRO, "math-macro", "", Noop },
299                 { LFUN_MATH_MUTATE, "math-mutate", "", Noop },
300                 { LFUN_MATH_SPACE, "math-space", "", Noop },
301                 { LFUN_MATH_IMPORT_SELECTION, "math-import-selection", "", Noop },
302                 { LFUN_MATH_MACROARG, "math-macro-arg", "", Noop },
303                 { LFUN_INSERT_MATRIX, "math-matrix", "", Noop },
304                 { LFUN_MATH_MODE, "math-mode", N_("Math mode"), Noop },
305                 { LFUN_MATH_NONUMBER, "math-nonumber", "", Noop },
306                 { LFUN_MATH_NUMBER, "math-number", "", Noop },
307                 { LFUN_MATH_EXTERN, "math-extern", "", Noop },
308                 { LFUN_MATH_VALIGN, "math-valign", "", Noop },
309                 { LFUN_MATH_HALIGN, "math-halign", "", Noop },
310                 { LFUN_MATH_ROW_INSERT, "math-row-insert", "", Noop },
311                 { LFUN_MATH_ROW_DELETE, "math-row-delete", "", Noop },
312                 { LFUN_MATH_COLUMN_INSERT, "math-column-insert", "", Noop },
313                 { LFUN_MATH_COLUMN_DELETE, "math-column-delete", "", Noop },
314                 { LFUN_MATH_PANEL, "math-panel", "", Noop },
315                 { LFUN_MATH_SIZE, "math-size", "", Noop },
316                 { LFUN_MENU_OPEN_BY_NAME, "menu-open", "", NoBuffer },
317                 { LFUN_MENU_SEPARATOR, "menu-separator-insert", "", Noop },
318                 { LFUN_META_FAKE, "meta-prefix", "", NoBuffer },
319                 { LFUN_INSET_MINIPAGE, "minipage-insert", "", Noop },
320                 { LFUN_INSERT_NOTE, "note-insert", "", Noop },
321                 { LFUN_GOTONOTE, "note-next", "", ReadOnly },
322                 { LFUN_INSET_TOGGLE, "inset-toggle", 
323                   N_("toggle inset"), ReadOnly },
324                 { LFUN_DOWN_PARAGRAPH, "paragraph-down",
325                   N_("Go one paragraph down"), ReadOnly },
326                 { LFUN_DOWN_PARAGRAPHSEL, "paragraph-down-select",
327                   N_("Select next paragraph"), ReadOnly },
328                 { LFUN_GOTO_PARAGRAPH, "paragraph-goto", 
329                   N_("Go to paragraph"), ReadOnly },
330                 { LFUN_PARAGRAPH_SPACING, "paragraph-spacing", "", Noop },
331                 { LFUN_UP_PARAGRAPH, "paragraph-up",
332                   N_("Go one paragraph up"), ReadOnly },
333                 { LFUN_UP_PARAGRAPHSEL, "paragraph-up-select",
334                   N_("Select previous paragraph"), ReadOnly },
335                 { LFUN_PARENTINSERT, "parent-insert", "", Noop },
336                 { LFUN_PASTE, "paste", N_("Paste") , Noop },
337                 { LFUN_DIALOG_PREFERENCES, "dialog-preferences",
338                   N_("Edit Preferences"), NoBuffer },
339                 { LFUN_SAVEPREFERENCES, "preferences-save",
340                   N_("Save Preferences"), NoBuffer },
341                 { LFUN_PASTESELECTION, "primary-selection-paste", "", Noop },
342                 { LFUN_PROTECTEDSPACE, "protected-space-insert",
343                   N_("Insert protected space"), Noop },
344                 { LFUN_QUOTE, "quote-insert", N_("Insert quote"), Noop },
345                 { LFUN_RECONFIGURE, "reconfigure",
346                   N_("Reconfigure"), NoBuffer },
347                 { LFUN_REDO, "redo", N_("Redo"), Noop },
348                 { LFUN_REF_GOTO, "reference-goto", "", ReadOnly },
349                 { LFUN_REF_INSERT, "reference-insert",
350                   N_("Insert cross reference"), ReadOnly },
351                 { LFUN_REFERENCE_GOTO, "reference-next", "", ReadOnly },
352                 { LFUN_NEXT, "screen-down", "", ReadOnly },
353                 { LFUN_NEXTSEL, "screen-down-select", "", ReadOnly },
354                 { LFUN_SCREEN_FONT_UPDATE, "screen-font-update",
355                   "", NoBuffer },
356                 { LFUN_CENTER, "screen-recenter", "", ReadOnly },
357                 { LFUN_PRIOR, "screen-up", "", ReadOnly },
358                 { LFUN_PRIORSEL, "screen-up-select", "", ReadOnly },
359                 { LFUN_SCROLL_INSET, "inset-scroll", N_("Scroll inset"),
360                   ReadOnly },
361                 { LFUN_SELFINSERT, "self-insert", "", Noop },
362                 { LFUN_CHARATCURSOR, "server-char-after", "", ReadOnly },
363                 { LFUN_GETFONT, "server-get-font", "", ReadOnly },
364                 { LFUN_GETLAYOUT, "server-get-layout", "", ReadOnly },
365                 { LFUN_GETNAME, "server-get-name", "", ReadOnly },
366                 { LFUN_GETTIP, "server-get-tip", "", ReadOnly },
367                 { LFUN_GETXY, "server-get-xy", "", ReadOnly },
368                 { LFUN_GOTOFILEROW, "server-goto-file-row", "", Noop },
369                 { LFUN_NOTIFY, "server-notify", "", ReadOnly },
370                 { LFUN_SETXY, "server-set-xy", "", ReadOnly },
371                 { LFUN_SET_COLOR, "set-color", "", ReadOnly|NoBuffer },
372                 { LFUN_SPELLCHECK, "spellchecker", "", Noop },
373                 { LFUN_SHIFT_TAB, "tab-backward", "", Noop },
374                 { LFUN_TAB, "tab-forward", "", Noop },
375                 { LFUN_TABINSERT, "tab-insert", "", Noop },
376                 { LFUN_DIALOG_TABULAR_INSERT, "dialog-tabular-insert",
377                   N_("Insert Table"), Noop },
378                 { LFUN_TABULAR_FEATURE, "tabular-feature",
379                   N_("Tabular Features"), Noop },
380                 { LFUN_INSET_TABULAR, "tabular-insert",
381                   N_("Insert a new Tabular Inset"), Noop },
382                 { LFUN_INSET_TEXT, "text-insert",
383                   N_("Insert a new Text Inset"), Noop },
384 #if 0
385                 { LFUN_INSET_THEOREM, "theorem-insert", "", Noop },
386 #endif
387                 { LFUN_THESAURUS_ENTRY, "thesaurus-entry", N_("Open thesaurus"), ReadOnly },
388                 { LFUN_TOC_INSERT, "toc-insert",
389                   N_("Insert table of contents"), Noop },
390                 { LFUN_TOCVIEW, "toc-view",
391                   N_("View table of contents"), ReadOnly },
392                 { LFUN_TOGGLECURSORFOLLOW, "toggle-cursor-follows-scrollbar",
393                   N_("Toggle cursor does/doesn't follow the scrollbar"),
394                   ReadOnly },
395                 { LFUN_ADD_TO_TOOLBAR, "toolbar-add-to", "", NoBuffer },
396                 { LFUN_PUSH_TOOLBAR, "toolbar-push", "", NoBuffer },
397                 { LFUN_UNDO, "undo", N_("Undo"), Noop },
398                 { LFUN_UP, "up", "", ReadOnly },
399                 { LFUN_UPSEL, "up-select", "", ReadOnly },
400                 { LFUN_URL, "url-insert", "", Noop },
401                 { LFUN_INSERT_URL, "", "internal only", Noop },
402                 { LFUN_VC_CHECKIN, "vc-check-in", "", ReadOnly },
403                 { LFUN_VC_CHECKOUT, "vc-check-out", "", ReadOnly },
404                 { LFUN_VC_HISTORY, "vc-history", "", ReadOnly },
405                 { LFUN_VC_REGISTER, "vc-register",
406                   N_("Register document under version control"), ReadOnly },
407                 { LFUN_VC_REVERT, "vc-revert", "", ReadOnly },
408                 { LFUN_VC_UNDO, "vc-undo-last", "", ReadOnly },
409                 { LFUN_WORDLEFT, "word-backward", "", ReadOnly },
410                 { LFUN_WORDLEFTSEL, "word-backward-select", "", ReadOnly },
411                 { LFUN_CAPITALIZE_WORD, "word-capitalize", "", Noop },
412                 { LFUN_DELETE_WORD_BACKWARD, "word-delete-backward",
413                   "", Noop },
414                 { LFUN_DELETE_WORD_FORWARD, "word-delete-forward", "", Noop },
415                 { LFUN_WORDFINDBACKWARD, "word-find-backward", "", ReadOnly },
416                 { LFUN_WORDFINDFORWARD, "word-find-forward", "", ReadOnly },
417                 { LFUN_WORDRIGHT, "word-forward", "", ReadOnly },
418                 { LFUN_WORDRIGHTSEL, "word-forward-select", "", ReadOnly },
419                 { LFUN_LOWCASE_WORD, "word-lowcase", "", Noop },
420                 { LFUN_UPCASE_WORD, "word-upcase", "", Noop },
421                 { LFUN_MESSAGE, "message",
422                   N_("Show message in minibuffer"), NoBuffer },
423                 { LFUN_MESSAGE_PUSH, "message-push",
424                   N_("Push old message and show this one in minibuffer"),
425                   NoBuffer },
426                 { LFUN_MESSAGE_POP, "message-pop",
427                   N_("Pop old message and show it in the minibuffer"),
428                   NoBuffer },
429                 { LFUN_TRANSPOSE_CHARS, "chars-transpose", "", Noop },
430                 { LFUN_FLOAT_LIST, "float-list", "Insert a float list", Noop },
431                 { LFUN_ESCAPE, "escape", "", Noop },
432                 { LFUN_HELP_ABOUTLYX, "help-aboutlyx",
433                   N_("Display information about LyX"), NoBuffer },
434                 { LFUN_HELP_TEXINFO, "help-Texinfo",
435                   N_("Display information about the TeX installation"), NoBuffer },
436                 { LFUN_FORKS_SHOW, "show-forks",
437                   N_("Show the processes forked by LyX"), NoBuffer },
438                 { LFUN_FORKS_KILL, "kill-forks",
439                   N_("Kill the forked process with this PID"), NoBuffer },
440                 { LFUN_NOACTION, "", "", Noop }
441         };
442
443         int i = 0;
444         while (items[i].action != LFUN_NOACTION) {
445                 newFunc(items[i].action,
446                         items[i].name,
447                         _(items[i].helpText),
448                         items[i].attrib);
449                 ++i;
450         }
451
452         init = true;
453 }
454
455
456 LyXAction::LyXAction()
457 {
458         init();
459 }
460
461
462 // Search for an existent pseudoaction, return LFUN_UNKNOWN_ACTION
463 // if it doesn't exist.
464 int LyXAction::searchActionArg(kb_action action, string const & arg) const
465 {
466         arg_map::const_iterator pit = lyx_arg_map.find(action);
467
468         if (pit == lyx_arg_map.end()) {
469                 // the action does not have any pseudoactions
470                 lyxerr[Debug::ACTION] << "Action " << action
471                                       << " does not have any pseudo actions."
472                                       << endl;
473                 return LFUN_UNKNOWN_ACTION;
474         }
475
476         arg_item::const_iterator aci = pit->second.find(arg);
477
478         if (aci == pit->second.end()) {
479                 // the action does not have any pseudoactions with this arg
480                 lyxerr[Debug::ACTION] 
481                         << "Action " << action
482                         << "does not have any pseudoactions with arg "
483                         << arg << endl;
484                 return LFUN_UNKNOWN_ACTION;
485         }
486
487         // pseudo action exist
488         lyxerr[Debug::ACTION] << "Pseudoaction exist[" 
489                               << action << '|' 
490                               << arg << "] = " << aci->second << endl;
491
492         return aci->second;
493 }
494
495
496 // Returns a pseudo-action given an action and its argument.
497 int LyXAction::getPseudoAction(kb_action action, string const & arg) const
498 {
499         int const psdaction = searchActionArg(action, arg);
500
501         if (isPseudoAction(psdaction)) return psdaction;
502
503         static unsigned int pseudo_counter = LFUN_LASTACTION;
504
505         // Create new pseudo action.
506         pseudo_func tmp_p;
507         tmp_p.action = action;
508         tmp_p.arg = arg;
509         lyx_pseudo_map[++pseudo_counter] = tmp_p;
510
511         // First ensure that the action is in lyx_arg_map;
512         lyx_arg_map[action];
513         // get the arg_item map
514         arg_map::iterator ami = lyx_arg_map.find(action);
515         // put the new pseudo function in it
516         ami->second[arg] = pseudo_counter;
517
518         lyxerr[Debug::ACTION] << "Creating new pseudoaction "
519                               << pseudo_counter << " for [" << action
520                               << '|' << arg << "]\n";
521         
522         return pseudo_counter;
523 }
524
525
526 // Retrieves the real action and its argument.
527 // perhaps a pair<kb_action, string> should be returned?
528 kb_action LyXAction::retrieveActionArg(int pseudo, string & arg) const
529 {
530         arg.erase(); // clear it to be sure.
531
532         if (!isPseudoAction(pseudo)) 
533                 return static_cast<kb_action>(pseudo);
534         
535         pseudo_map::const_iterator pit = lyx_pseudo_map.find(pseudo);
536
537         if (pit != lyx_pseudo_map.end()) {
538                 lyxerr[Debug::ACTION] << "Found the pseudoaction: ["
539                                       << pit->second.action << '|'
540                                       << pit->second.arg << "]\n";
541                 arg = pit->second.arg;
542                 return pit->second.action;
543         } else {
544                 lyxerr << "Lyx Error: Unrecognized pseudo-action\n";
545                 return LFUN_UNKNOWN_ACTION;
546         }
547 }
548
549
550 // Returns an action tag from a string.
551 int LyXAction::LookupFunc(string const & func) const
552 {
553         if (func.empty()) return LFUN_NOACTION;
554
555         // split action and arg
556         string actstr;
557         string const argstr = split(func, actstr, ' ');
558         lyxerr[Debug::ACTION] << "Action: " << actstr << '\n';
559         lyxerr[Debug::ACTION] << "Arg   : " << argstr << '\n';
560
561         func_map::const_iterator fit = lyx_func_map.find(actstr);
562
563         if (!argstr.empty() && fit != lyx_func_map.end()) {
564                 // might be pseudo (or create one)
565                 return getPseudoAction(fit->second, argstr);
566         }
567
568         return fit != lyx_func_map.end() ? fit->second : LFUN_UNKNOWN_ACTION;
569 }
570
571
572 //#ifdef WITH_WARNINGS
573 //#warning Not working as it should.
574 //#endif
575 // I have no clue what is wrong with it... (Lgb)
576 int LyXAction::getApproxFunc(string const & func) const
577         // This func should perhaps also be able to return a list of all
578         // actions that has func as a prefix. That should actually be quite
579         // easy, just let it return a vector<int> or something.
580 {
581         int action = LookupFunc(func);
582         if (action == LFUN_UNKNOWN_ACTION) {
583                 // func is not an action, but perhaps it is
584                 // part of one...check if it is prefix if one of the
585                 // actions.
586                 // Checking for prefix is not so simple, but
587                 // using a simple bounding function gives
588                 // a similar result.  [ale 19981103]
589                 func_map::const_iterator fit = 
590                         lyx_func_map.lower_bound(func);
591                 
592                 if (fit != lyx_func_map.end()) {
593                         action =  fit->second;
594                 }
595         } else {  // Go get the next function
596                 func_map::const_iterator fit = 
597                         lyx_func_map.upper_bound(func);
598                 
599                 if (fit != lyx_func_map.end()) {
600                         action =  fit->second;
601                 }
602         }
603         
604         return action;
605 }
606
607
608 string const LyXAction::getApproxFuncName(string const & func) const
609 {
610         int const f = getApproxFunc(func);
611         // This will return empty string if f isn't an action.
612         return getActionName(f);
613 }
614
615
616 string const LyXAction::getActionName(int action) const
617 {
618         kb_action ac;
619         string arg;
620
621         ac = retrieveActionArg(action, arg);
622         if (!arg.empty())
623                 arg.insert(0, " ");
624         
625         info_map::const_iterator iit = lyx_info_map.find(ac);
626
627         if (iit != lyx_info_map.end()) {
628                 string ret(iit->second.name);
629                 ret += arg;
630                 return ret;
631         } else 
632                 return string();
633 }
634
635
636 // Returns one line help associated with a (pseudo)action, i.e. appends
637 // the argument of the action if necessary
638 string const LyXAction::helpText(int pseudoaction) const
639 {
640         string help, arg;
641         kb_action action;
642
643         action = retrieveActionArg(pseudoaction, arg);
644
645         info_map::const_iterator ici = lyx_info_map.find(action);
646         if (ici != lyx_info_map.end()) {
647                 if (lyxerr.debugging(Debug::ACTION)) {
648                         lyxerr << "Action: " << action << '\n';
649                         lyxerr << "   name: "
650                                << ici->second.name << '\n';
651                         lyxerr << " attrib: "
652                                << ici->second.attrib << '\n';
653                         lyxerr << "   help: "
654                                << ici->second.helpText << '\n';
655                 }
656                 help = ici->second.helpText;
657                 // if the is no help text use the name of the func instead.
658                 if (help.empty()) help = ici->second.name;
659         }
660
661         if (help.empty()) {
662                 help = _("No description available!");
663         } else if (!arg.empty()) {
664                 help += ' ';
665                 help += arg;
666         }
667
668         return help;
669 }
670
671
672 bool LyXAction::funcHasFlag(kb_action action, 
673                             LyXAction::func_attrib flag) const 
674 {
675         info_map::const_iterator ici = lyx_info_map.find(action);
676
677         if (ici != lyx_info_map.end()) {
678                 return ici->second.attrib & flag;
679         } else {
680                 // it really should exist, but...
681                 lyxerr << "LyXAction::funcHasFlag: "
682                         "No info about kb_action: " << action << '\n';
683                 return false;
684         }
685 }
686
687
688 LyXAction::const_func_iterator LyXAction::func_begin() const 
689 {
690         return lyx_func_map.begin();
691 }
692
693
694 LyXAction::const_func_iterator LyXAction::func_end() const 
695 {
696         return lyx_func_map.end();
697 }
698
699
700 ostream & operator<<(ostream & o, kb_action action)
701 {
702         return o << int(action);
703 }