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