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