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