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