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