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