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