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