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