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