]> git.lyx.org Git - lyx.git/blob - src/LyXAction.C
* Remove LFUN_REF_INSERT.
[lyx.git] / src / LyXAction.C
1 /**
2  * \file LyXAction.C
3  * Copyright 1995-2002 the LyX Team
4  * Read the file COPYING
5  */
6
7 #include <config.h>
8
9 #include "LyXAction.h"
10
11 #include "debug.h"
12 #include "gettext.h"
13 #include "support/lstrings.h"
14
15 using std::ostream;
16 using std::endl;
17 using std::pair;
18 using std::make_pair;
19
20 /*
21      NAMING RULES FOR USER-COMMANDS
22      Here's the set of rules to apply when a new command name is introduced:
23
24      1) Use the object.event order. That is, use `word-forward'
25         instead of `forward-word'.
26      2) Don't introduce an alias for an already named object. Same for events.
27      3) Forward movement or focus is called `forward' (not `right').
28      4) Backward movement or focus is called `backward' (not `left').
29      5) Upward movement of focus is called `up'.
30      6) Downward movement is called `down'.
31      7) The begin of an object is called `begin' (not `start').
32      8) The end of an object is called `end'.
33
34      (May 19 1996, 12:04, RvdK)
35 */
36
37 LyXAction lyxaction;
38
39 namespace {
40
41 /// return true if the given action is a pseudo-action
42 inline bool isPseudoAction(int a)
43 {
44         return a > int(LFUN_LASTACTION);
45 }
46
47 }
48
49
50 void LyXAction::newFunc(kb_action action, string const & name,
51                         string const & helpText, unsigned int attrib)
52 {
53         lyx_func_map[name] = action;
54         func_info tmpinfo;
55         tmpinfo.name = name;
56         tmpinfo.attrib = attrib;
57         tmpinfo.helpText = helpText;
58         lyx_info_map[action] = tmpinfo;
59 }
60
61
62 void LyXAction::init()
63 {
64         // This function was changed to use the array below in initalization
65         // instead of calling newFunc numerous times because of compilation
66         // times. Since the array is not static we get back the memory it
67         // occupies after the init is completed. It compiles several
68         // magnitudes faster.
69
70         static bool init;
71         if (init) return;
72
73         struct ev_item {
74                 kb_action action;
75                 char const * name;
76                 char const * helpText;
77                 unsigned int attrib;
78         };
79
80         ev_item const items[] = {
81                 { LFUN_ACUTE, "accent-acute", "", Noop },
82                 { LFUN_BREVE, "accent-breve", "", Noop },
83                 { LFUN_CARON, "accent-caron", "", Noop },
84                 { LFUN_CEDILLA, "accent-cedilla", "", Noop },
85                 { LFUN_CIRCLE, "accent-circle", "", Noop },
86                 { LFUN_CIRCUMFLEX, "accent-circumflex", "", Noop },
87                 { LFUN_DOT, "accent-dot", "", Noop },
88                 { LFUN_GRAVE, "accent-grave", "", Noop },
89                 { LFUN_HUNG_UMLAUT, "accent-hungarian-umlaut", "", Noop },
90                 { LFUN_MACRON, "accent-macron", "", Noop },
91                 { LFUN_OGONEK, "accent-ogonek", "", Noop },
92                 { LFUN_SPECIAL_CARON, "accent-special-caron", "", Noop },
93                 { LFUN_TIE, "accent-tie", "", Noop },
94                 { LFUN_TILDE, "accent-tilde", "", Noop },
95                 { LFUN_UMLAUT, "accent-umlaut", "", Noop },
96                 { LFUN_UNDERBAR, "accent-underbar", "", Noop },
97                 { LFUN_UNDERDOT, "accent-underdot", "", 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_BOOKMARK_GOTO, "bookmark-goto", "", ReadOnly },
104                 { LFUN_BOOKMARK_SAVE, "bookmark-save", "", ReadOnly },
105                 { LFUN_BREAKLINE, "break-line", "", Noop },
106                 { LFUN_BREAKPARAGRAPH, "break-paragraph", "", Noop },
107                 { LFUN_BREAKPARAGRAPHKEEPLAYOUT, "break-paragraph-keep-layout",
108                   "", Noop },
109                 { LFUN_BREAKPARAGRAPH_SKIP, "break-paragraph-skip", "", Noop },
110                 { LFUN_BUILDPROG, "build-program",
111                   N_("Build program"), ReadOnly },
112                 { LFUN_AUTOSAVE, "buffer-auto-save", N_("Autosave"), Noop },
113                 { LFUN_BEGINNINGBUF, "buffer-begin",
114                   N_("Go to beginning of document"), ReadOnly },
115                 { LFUN_BEGINNINGBUFSEL, "buffer-begin-select",
116                   N_("Select to beginning of document"), ReadOnly },
117                 { LFUN_CHILDOPEN, "buffer-child-open", "", ReadOnly },
118                 { LFUN_RUNCHKTEX, "buffer-chktex", N_("Check TeX"), ReadOnly },
119                 { LFUN_CLOSEBUFFER, "buffer-close", N_("Close"), ReadOnly },
120                 { LFUN_ENDBUF, "buffer-end",
121                   N_("Go to end of document"), ReadOnly },
122                 { LFUN_ENDBUFSEL, "buffer-end-select",
123                   N_("Select to end of document"), ReadOnly },
124                 { LFUN_EXPORT, "buffer-export", N_("Export to"), ReadOnly },
125                 { LFUN_IMPORT, "buffer-import",
126                   N_("Import document"), NoBuffer },
127                 { LFUN_MENUNEW, "buffer-new", N_("New document") , NoBuffer },
128                 { LFUN_MENUNEWTMPLT,"buffer-new-template",
129                   N_("New document from template"), NoBuffer },
130                 { LFUN_MENUPRINT, "buffer-print", N_("Print"), ReadOnly },
131                 { LFUN_MENURELOAD, "buffer-reload",
132                   N_("Revert to saved"), ReadOnly },
133                 { LFUN_SWITCHBUFFER, "buffer-switch",
134                   N_("Switch to an open document"), ReadOnly },
135                 { LFUN_READ_ONLY_TOGGLE, "buffer-toggle-read-only",
136                   N_("Toggle read-only"), ReadOnly },
137                 { LFUN_UPDATE, "buffer-update", N_("Update"), ReadOnly },
138                 { LFUN_PREVIEW, "buffer-view", N_("View") , ReadOnly },
139                 { LFUN_MENUWRITE, "buffer-write", N_("Save"), ReadOnly },
140                 { LFUN_WRITEAS, "buffer-write-as", N_("Save As"),
141                   ReadOnly },
142                 { LFUN_CANCEL, "cancel", N_("Cancel"), NoBuffer },
143                 { LFUN_INSET_CAPTION, "caption-insert", "", Noop },
144                 { LFUN_LEFT, "char-backward", N_("Go one char back"),
145                   ReadOnly },
146                 { LFUN_RIGHT, "char-forward", N_("Go one char forward"),
147                   ReadOnly },
148                 { LFUN_EXEC_COMMAND, "command-execute", "", NoBuffer },
149                 { LFUN_PREFIX, "command-prefix",
150                   N_("Execute command"), NoBuffer },
151                 { LFUN_SEQUENCE, "command-sequence", "", NoBuffer },
152                 { LFUN_COPY, "copy", N_("Copy"), ReadOnly },
153                 { LFUN_CUT, "cut", N_("Cut"), Noop },
154                 { LFUN_DATE_INSERT, "date-insert", "", Noop },
155                 { LFUN_BACKSPACE, "delete-backward", "", Noop },
156                 { LFUN_BACKSPACE_SKIP, "delete-backward-skip", "", Noop },
157                 { LFUN_DELETE, "delete-forward", "", Noop },
158                 { LFUN_DELETE_SKIP, "delete-forward-skip", "", Noop },
159                 { LFUN_DEPTH_MIN, "depth-decrement",
160                   N_("Decrement environment depth"), Noop },
161                 { LFUN_DEPTH_PLUS, "depth-increment",
162                   N_("Increment environment depth"), Noop },
163                 { LFUN_LDOTS, "dots-insert", N_("Insert ... dots"), Noop },
164                 { LFUN_DOWN, "down", N_("Go down"), ReadOnly },
165                 { LFUN_DOWNSEL, "down-select",
166                   N_("Select next line"), ReadOnly },
167                 { LFUN_DROP_LAYOUTS_CHOICE, "drop-layouts-choice",
168                   N_("Choose Paragraph Environment"), ReadOnly },
169                 { LFUN_END_OF_SENTENCE, "end-of-sentence-period-insert",
170                   N_("Insert end of sentence period"), Noop },
171                 { LFUN_GOTOERROR, "error-next",
172                   N_("Go to next error"), ReadOnly },
173                 { LFUN_REMOVEERRORS, "error-remove-all",
174                   N_("Remove all error boxes"), ReadOnly },
175                 { LFUN_INSET_ERT, "ert-insert",
176                   N_("Insert a new ERT Inset"), Noop },
177                 { LFUN_INSET_GRAPHICS, "graphics-insert",
178                   N_("Insert Graphics"), Noop },
179                 { LFUN_FILE_INSERT, "file-insert", "", Noop },
180                 { LFUN_FILE_INSERT_ASCII, "file-insert-ascii", _("Insert ASCII files as lines"), Noop },
181                 { LFUN_FILE_INSERT_ASCII_PARA, "file-insert-ascii-para", _("Insert ASCII file as a paragraph"), Noop },
182                 { LFUN_FILE_NEW, "file-new", "", NoBuffer },
183                 { LFUN_FILE_OPEN, "file-open", N_("Open a file"), NoBuffer },
184                 { LFUN_MENUSEARCH, "find-replace", N_("Find & Replace"),
185                   ReadOnly },
186                 { LFUN_INSET_FLOAT, "float-insert", N_("Insert a Float"), Noop },
187                 { LFUN_INSET_WIDE_FLOAT, "float-wide-insert",
188                   N_("Insert a wide Float"), Noop },
189                 { LFUN_INSET_WRAP, "wrap-insert", N_("Insert a Wrap"), Noop },
190                 { LFUN_BOLD, "font-bold", N_("Toggle bold"), Noop },
191                 { LFUN_CODE, "font-code", N_("Toggle code style"), Noop },
192                 { LFUN_DEFAULT, "font-default", N_("Default font style"),
193                   Noop },
194                 { LFUN_EMPH, "font-emph", N_("Toggle emphasize"), Noop },
195                 { LFUN_FREE, "font-free", N_("Toggle user defined style"),
196                   Noop },
197                 { LFUN_NOUN, "font-noun", N_("Toggle noun style"), Noop },
198                 { LFUN_ROMAN, "font-roman", N_("Toggle roman font style"),
199                   Noop },
200                 { LFUN_SANS, "font-sans", N_("Toggle sans font style"), Noop },
201                 { LFUN_FRAK, "font-frak", N_("Toggle fraktur font style"), Noop },
202                 { LFUN_ITAL, "font-ital", N_("Toggle italic font style"), Noop },
203                 { LFUN_FONT_SIZE, "font-size", N_("Set font size"), Noop },
204                 { LFUN_FONT_STATE, "font-state", N_("Show font state"),
205                   ReadOnly },
206                 { LFUN_UNDERLINE, "font-underline",
207                   N_("Toggle font underline"), Noop },
208                 { LFUN_INSET_FOOTNOTE, "footnote-insert",
209                   N_("Insert Footnote"), Noop },
210                 { LFUN_RIGHTSEL, "forward-select", N_("Select next char"),
211                   ReadOnly },
212                 { LFUN_HFILL, "hfill-insert",
213                   N_("Insert horizontal fill"), Noop },
214                 { LFUN_HELP_OPEN, "help-open", N_("Open a Help file"),
215                   NoBuffer|Argument},
216                 { LFUN_HTMLURL, "html-insert", "", Noop },
217                 { LFUN_HYPHENATION, "hyphenation-point-insert",
218                   N_("Insert hyphenation point"), Noop },
219                 { LFUN_LIGATURE_BREAK, "ligature-break-insert",
220                   N_("Insert ligature break"), Noop },
221                 { LFUN_INDEX_INSERT, "index-insert",
222                   N_("Insert index item"), Noop },
223                 { LFUN_INDEX_PRINT, "index-print", N_("Insert index list"),
224                   Noop },
225                 { LFUN_KMAP_OFF, "keymap-off", N_("Turn off keymap"),
226                   ReadOnly },
227                 { LFUN_KMAP_PRIM, "keymap-primary",
228                   N_("Use primary keymap"), ReadOnly },
229                 { LFUN_KMAP_SEC, "keymap-secondary",
230                   N_("Use secondary keymap"), ReadOnly },
231                 { LFUN_KMAP_TOGGLE, "keymap-toggle", N_("Toggle keymap"),
232                   ReadOnly },
233                 { LFUN_INSERT_LABEL, "label-insert", N_("Insert Label"),
234                   Noop },
235                 { LFUN_INSET_OPTARG, "optional-insert", N_("Insert Optional Argument"),
236                   Noop },
237                 { LFUN_INSERT_BIBITEM, "bibitem-insert",
238                   N_("Insert Bibliography Key"), Noop },
239                 { LFUN_LANGUAGE, "language", N_("Change language"), Noop },
240                 { LFUN_LATEX_LOG, "latex-view-log", N_("View LaTeX log"),
241                   ReadOnly },
242                 { LFUN_LAYOUT, "layout", "", Noop },
243                 { LFUN_LAYOUT_CHARACTER, "layout-character", "", Noop },
244                 { LFUN_LAYOUT_COPY, "layout-copy",
245                   N_("Copy paragraph environment type"), Noop },
246                 { LFUN_LAYOUT_DOCUMENT, "layout-document", "", ReadOnly },
247                 { LFUN_LAYOUT_PARAGRAPH, "layout-paragraph", "", ReadOnly },
248                 { LFUN_LAYOUT_PASTE, "layout-paste",
249                   N_("Paste paragraph environment type"), Noop },
250                 { LFUN_LAYOUT_PREAMBLE, "layout-preamble", "", ReadOnly },
251                 { LFUN_LAYOUT_TABULAR, "layout-tabular",
252                   N_("Open the tabular layout"), Noop },
253                 { LFUN_HOME, "line-begin",
254                   N_("Go to beginning of line"), ReadOnly },
255                 { LFUN_HOMESEL, "line-begin-select",
256                   N_("Select to beginning of line"), ReadOnly },
257                 { LFUN_DELETE_LINE_FORWARD, "line-delete-forward", "", Noop },
258                 { LFUN_END, "line-end", N_("Go to end of line"), ReadOnly },
259                 { LFUN_ENDSEL, "line-end-select",
260                   N_("Select to end of line"), ReadOnly },
261 #if 0
262                 { LFUN_INSET_LIST, "list-insert", "", Noop },
263 #endif
264                 { LFUN_QUIT, "lyx-quit", N_("Exit"), NoBuffer },
265                 { LFUN_INSET_MARGINAL, "marginalnote-insert",
266                   N_("Insert margin note"), Noop },
267                 { LFUN_MARK_OFF, "mark-off", "", ReadOnly },
268                 { LFUN_MARK_ON, "mark-on", "", ReadOnly },
269                 { LFUN_SETMARK, "mark-toggle", "", ReadOnly },
270                 { LFUN_MATH_DELIM, "math-delim", "", Noop },
271                 { LFUN_MATH_DISPLAY, "math-display", "", Noop },
272                 { LFUN_GREEK, "math-greek", N_("Math Greek"), Noop },
273                 { LFUN_GREEK_TOGGLE, "math-greek-toggle", "", Noop },
274                 { LFUN_INSERT_MATH, "math-insert",
275                   N_("Insert math symbol"), Noop },
276                 { LFUN_SUBSCRIPT, "math-subscript", N_("Add subscript"), Noop },
277                 { LFUN_SUPERSCRIPT, "math-superscript", N_("Add superscript"), Noop },
278                 { LFUN_MATH_LIMITS, "math-limits", "", Noop },
279                 { LFUN_MATH_MACRO, "math-macro", "", Noop },
280                 { LFUN_MATH_MUTATE, "math-mutate", "", Noop },
281                 { LFUN_MATH_SPACE, "math-space", "", Noop },
282                 { LFUN_MATH_IMPORT_SELECTION, "math-import-selection", "", Noop },
283                 { LFUN_INSERT_MATRIX, "math-matrix", "", Noop },
284                 { LFUN_MATH_MODE, "math-mode", N_("Math mode"), Noop },
285                 { LFUN_MATH_NONUMBER, "math-nonumber", "", Noop },
286                 { LFUN_MATH_NUMBER, "math-number", "", Noop },
287                 { LFUN_MATH_EXTERN, "math-extern", "", Noop },
288                 { LFUN_MATH_PANEL, "math-panel", "", Noop },
289                 { LFUN_MATH_SIZE, "math-size", "", Noop },
290                 { LFUN_MENU_OPEN_BY_NAME, "menu-open", "", NoBuffer },
291                 { LFUN_MENU_SEPARATOR, "menu-separator-insert", "", Noop },
292                 { LFUN_META_FAKE, "meta-prefix", "", NoBuffer },
293                 { LFUN_INSET_MINIPAGE, "minipage-insert", "", Noop },
294                 { LFUN_INSERT_NOTE, "note-insert", "", Noop },
295                 { LFUN_GOTONOTE, "note-next", "", ReadOnly },
296                 { LFUN_INSET_TOGGLE, "inset-toggle",
297                   N_("toggle inset"), ReadOnly },
298                 { LFUN_DOWN_PARAGRAPH, "paragraph-down",
299                   N_("Go one paragraph down"), ReadOnly },
300                 { LFUN_DOWN_PARAGRAPHSEL, "paragraph-down-select",
301                   N_("Select next paragraph"), ReadOnly },
302                 { LFUN_GOTO_PARAGRAPH, "paragraph-goto",
303                   N_("Go to paragraph"), ReadOnly },
304                 { LFUN_PARAGRAPH_SPACING, "paragraph-spacing", "", Noop },
305                 { LFUN_UP_PARAGRAPH, "paragraph-up",
306                   N_("Go one paragraph up"), ReadOnly },
307                 { LFUN_UP_PARAGRAPHSEL, "paragraph-up-select",
308                   N_("Select previous paragraph"), ReadOnly },
309                 { LFUN_PARENTINSERT, "parent-insert", "", Noop },
310                 { LFUN_PASTE, "paste", N_("Paste") , Noop },
311                 { LFUN_DIALOG_PREFERENCES, "dialog-preferences",
312                   N_("Edit Preferences"), NoBuffer },
313                 { LFUN_SAVEPREFERENCES, "preferences-save",
314                   N_("Save Preferences"), NoBuffer },
315                 { LFUN_PASTESELECTION, "primary-selection-paste", "", Noop },
316                 { LFUN_PROTECTEDSPACE, "protected-space-insert",
317                   N_("Insert protected space"), Noop },
318                 { LFUN_QUOTE, "quote-insert", N_("Insert quote"), Noop },
319                 { LFUN_RECONFIGURE, "reconfigure",
320                   N_("Reconfigure"), NoBuffer },
321                 { LFUN_REDO, "redo", N_("Redo"), Noop },
322                 { LFUN_REF_GOTO, "reference-goto", "", ReadOnly },
323                 { LFUN_REFERENCE_GOTO, "reference-next", "", ReadOnly },
324                 { LFUN_NEXT, "screen-down", "", ReadOnly },
325                 { LFUN_NEXTSEL, "screen-down-select", "", ReadOnly },
326                 { LFUN_SCREEN_FONT_UPDATE, "screen-font-update",
327                   "", NoBuffer },
328                 { LFUN_CENTER, "screen-recenter", "", ReadOnly },
329                 { LFUN_PRIOR, "screen-up", "", ReadOnly },
330                 { LFUN_PRIORSEL, "screen-up-select", "", ReadOnly },
331                 { LFUN_SCROLL_INSET, "inset-scroll", N_("Scroll inset"),
332                   ReadOnly },
333                 { LFUN_SELFINSERT, "self-insert", "", Noop },
334                 { LFUN_CHARATCURSOR, "server-char-after", "", ReadOnly },
335                 { LFUN_GETFONT, "server-get-font", "", ReadOnly },
336                 { LFUN_GETLAYOUT, "server-get-layout", "", ReadOnly },
337                 { LFUN_GETNAME, "server-get-name", "", ReadOnly },
338                 { LFUN_GETTIP, "server-get-tip", "", ReadOnly },
339                 { LFUN_GETXY, "server-get-xy", "", ReadOnly },
340                 { LFUN_GOTOFILEROW, "server-goto-file-row", "", Noop },
341                 { LFUN_NOTIFY, "server-notify", "", ReadOnly },
342                 { LFUN_SETXY, "server-set-xy", "", ReadOnly },
343                 { LFUN_SET_COLOR, "set-color", "", ReadOnly|NoBuffer },
344                 { LFUN_SPELLCHECK, "spellchecker", "", Noop },
345                 { LFUN_SHIFT_TAB, "tab-backward", "", Noop },
346                 { LFUN_TAB, "tab-forward", "", Noop },
347                 { LFUN_TABINSERT, "tab-insert", "", Noop },
348                 { LFUN_TABULAR_INSERT, "tabular-insert", N_("Insert Table"), Noop },
349                 { LFUN_TABULAR_FEATURE, "tabular-feature",
350                   N_("Tabular Features"), Noop },
351 #if 0
352                 { LFUN_INSET_THEOREM, "theorem-insert", "", Noop },
353 #endif
354                 { LFUN_THESAURUS_ENTRY, "thesaurus-entry", N_("Open thesaurus"), ReadOnly },
355                 { LFUN_TOC_INSERT, "toc-insert",
356                   N_("Insert table of contents"), Noop },
357                 { LFUN_TOCVIEW, "toc-view",
358                   N_("View table of contents"), ReadOnly },
359                 { LFUN_TOGGLECURSORFOLLOW, "toggle-cursor-follows-scrollbar",
360                   N_("Toggle cursor does/doesn't follow the scrollbar"),
361                   ReadOnly },
362                 { LFUN_UNDO, "undo", N_("Undo"), Noop },
363                 { LFUN_UP, "up", "", ReadOnly },
364                 { LFUN_UPSEL, "up-select", "", ReadOnly },
365                 { LFUN_URL, "url-insert", "", Noop },
366                 { LFUN_VC_CHECKIN, "vc-check-in", "", ReadOnly },
367                 { LFUN_VC_CHECKOUT, "vc-check-out", "", ReadOnly },
368                 { LFUN_VC_HISTORY, "vc-history", "", ReadOnly },
369                 { LFUN_VC_REGISTER, "vc-register",
370                   N_("Register document under version control"), ReadOnly },
371                 { LFUN_VC_REVERT, "vc-revert", "", ReadOnly },
372                 { LFUN_VC_UNDO, "vc-undo-last", "", ReadOnly },
373                 { LFUN_WORDLEFT, "word-backward", "", ReadOnly },
374                 { LFUN_WORDLEFTSEL, "word-backward-select", "", ReadOnly },
375                 { LFUN_CAPITALIZE_WORD, "word-capitalize", "", Noop },
376                 { LFUN_DELETE_WORD_BACKWARD, "word-delete-backward",
377                   "", Noop },
378                 { LFUN_DELETE_WORD_FORWARD, "word-delete-forward", "", Noop },
379                 { LFUN_WORDFINDBACKWARD, "word-find-backward", "", ReadOnly },
380                 { LFUN_WORDFINDFORWARD, "word-find-forward", "", ReadOnly },
381                 { LFUN_WORDRIGHT, "word-forward", "", ReadOnly },
382                 { LFUN_WORDRIGHTSEL, "word-forward-select", "", ReadOnly },
383                 { LFUN_LOWCASE_WORD, "word-lowcase", "", Noop },
384                 { LFUN_WORDSEL, "word-select", "", ReadOnly },
385                 { LFUN_UPCASE_WORD, "word-upcase", "", Noop },
386                 { LFUN_MESSAGE, "message",
387                   N_("Show message in minibuffer"), NoBuffer },
388                 { LFUN_TRANSPOSE_CHARS, "chars-transpose", "", Noop },
389                 { LFUN_FLOAT_LIST, "float-list", "Insert a float list", Noop },
390                 { LFUN_ESCAPE, "escape", "", Noop },
391                 { LFUN_HELP_ABOUTLYX, "help-aboutlyx",
392                   N_("Display information about LyX"), NoBuffer },
393                 { LFUN_HELP_TEXINFO, "help-Texinfo",
394                   N_("Display information about the TeX installation"), NoBuffer },
395                 { LFUN_FORKS_SHOW, "show-forks",
396                   N_("Show the processes forked by LyX"), NoBuffer },
397                 { LFUN_FORKS_KILL, "kill-forks",
398                   N_("Kill the forked process with this PID"), NoBuffer },
399                 { LFUN_TOOLTIPS_TOGGLE, "toggle-tooltips", "", NoBuffer },
400                 { LFUN_TRACK_CHANGES, "track-changes", N_("Begin tracking changes"), Noop },
401                 { LFUN_MERGE_CHANGES, "merge-changes", N_("Merge changes"), Noop },
402                 { LFUN_ACCEPT_CHANGE, "accept-change", N_("Accept selected change"), Noop },
403                 { LFUN_REJECT_CHANGE, "reject-change", N_("Reject selected change"), Noop },
404                 { LFUN_ACCEPT_ALL_CHANGES, "accept-all-changes", N_("Accept all changes"), Noop },
405                 { LFUN_REJECT_ALL_CHANGES, "reject-all-changes", N_("Reject all changes"), Noop },
406
407                 { LFUN_DIALOG_SHOW_NEW_INSET, "dialog-show-new-inset",
408                   N_("Show the inset's dialog"), Noop },
409                 { LFUN_DIALOG_SHOW_NEW_INSET, "dialog-show-next-inset",
410                   N_("Show the inset's dialog"), Noop },
411                 { LFUN_DIALOG_UPDATE, "dialog-update",
412                   N_("Update the dialog"), Noop },
413                 { LFUN_DIALOG_HIDE, "dialog-hide",
414                   N_("Hide the dialog"), Noop },
415                 { LFUN_DIALOG_DISCONNECT_INSET, "dialog-disconnect-inset",
416                   N_("Disconnect the dialog from the current inset"), Noop },
417                 { LFUN_INSET_APPLY, "inset-apply", "", Noop },
418                 { LFUN_INSET_MODIFY, "", "internal only", Noop },
419                 { LFUN_INSET_DIALOG_UPDATE, "", "internal only", Noop },
420                 { LFUN_NOACTION, "", "", Noop }
421         };
422
423         for (int i = 0; items[i].action != LFUN_NOACTION; ++i) {
424                 newFunc(items[i].action, items[i].name,
425                         _(items[i].helpText), items[i].attrib);
426         }
427
428         init = true;
429 }
430
431
432 LyXAction::LyXAction()
433 {
434         init();
435 }
436
437
438 int LyXAction::searchActionArg(kb_action action, string const & arg) const
439 {
440         arg_map::const_iterator pit = lyx_arg_map.find(action);
441
442         if (pit == lyx_arg_map.end()) {
443                 lyxerr[Debug::ACTION] << "Action " << action
444                                       << " does not have any pseudo actions."
445                                       << endl;
446                 return LFUN_UNKNOWN_ACTION;
447         }
448
449         arg_item::const_iterator aci = pit->second.find(arg);
450
451         if (aci == pit->second.end()) {
452                 lyxerr[Debug::ACTION]
453                         << "Action " << action
454                         << "does not have any pseudoactions with arg "
455                         << arg << endl;
456                 return LFUN_UNKNOWN_ACTION;
457         }
458
459         lyxerr[Debug::ACTION] << "Pseudoaction exists["
460                               << action << '|'
461                               << arg << "] = " << aci->second << endl;
462
463         return aci->second;
464 }
465
466
467 int LyXAction::getPseudoAction(kb_action action, string const & arg)
468 {
469         int const psdaction = searchActionArg(action, arg);
470
471         if (isPseudoAction(psdaction)) return psdaction;
472
473         static unsigned int pseudo_counter = LFUN_LASTACTION;
474
475         // Create new pseudo action.
476         lyx_pseudo_map[++pseudo_counter] = FuncRequest(0, action, arg);
477
478         // First ensure that the action is in lyx_arg_map;
479         lyx_arg_map[action];
480         // get the arg_item map
481         arg_map::iterator ami = lyx_arg_map.find(action);
482         // put the new pseudo function in it
483         ami->second[arg] = pseudo_counter;
484
485         lyxerr[Debug::ACTION] << "Creating new pseudoaction "
486                               << pseudo_counter << " for [" << action
487                               << '|' << arg << "]\n";
488
489         return pseudo_counter;
490 }
491
492
493 FuncRequest LyXAction::retrieveActionArg(int pseudo) const
494 {
495         if (!isPseudoAction(pseudo))
496                 return FuncRequest(static_cast<kb_action>(pseudo));
497
498         pseudo_map::const_iterator pit = lyx_pseudo_map.find(pseudo);
499
500         if (pit != lyx_pseudo_map.end()) {
501                 lyxerr[Debug::ACTION] << "Found the pseudoaction: ["
502                                       << pit->second.action << '|'
503                                       << pit->second.argument << "]\n";
504                 return pit->second;
505         } else {
506                 lyxerr << "Lyx Error: Unrecognized pseudo-action "
507                         << pseudo << endl;
508                 return FuncRequest(LFUN_UNKNOWN_ACTION);
509         }
510 }
511
512
513 // Returns an action tag from a string.
514 int LyXAction::LookupFunc(string const & func)
515 {
516         string const func2 = trim(func);
517         if (func2.empty()) return LFUN_NOACTION;
518
519         // split action and arg
520         string actstr;
521         string const argstr = split(func2, actstr, ' ');
522         lyxerr[Debug::ACTION] << "Action: " << actstr << '\n';
523         lyxerr[Debug::ACTION] << "Arg   : " << argstr << '\n';
524
525         func_map::const_iterator fit = lyx_func_map.find(actstr);
526
527         if (!argstr.empty() && fit != lyx_func_map.end()) {
528                 // might be pseudo (or create one)
529                 return getPseudoAction(fit->second, argstr);
530         }
531
532         return fit != lyx_func_map.end() ? fit->second : LFUN_UNKNOWN_ACTION;
533 }
534
535
536 string const LyXAction::getActionName(int action) const
537 {
538         FuncRequest ev = retrieveActionArg(action);
539         if (!ev.argument.empty())
540                 ev.argument.insert(string::size_type(0), 1, ' ');
541
542         info_map::const_iterator const it = lyx_info_map.find(ev.action);
543
544         if (it != lyx_info_map.end())
545                 return it->second.name + ev.argument;
546         return string();
547 }
548
549
550 string const LyXAction::helpText(int pseudoaction) const
551 {
552         FuncRequest ev = retrieveActionArg(pseudoaction);
553
554         string help;
555
556         info_map::const_iterator ici = lyx_info_map.find(ev.action);
557         if (ici != lyx_info_map.end()) {
558                 if (lyxerr.debugging(Debug::ACTION)) {
559                         lyxerr << "Action: " << ev.action << '\n';
560                         lyxerr << "   name: "
561                                << ici->second.name << '\n';
562                         lyxerr << " attrib: "
563                                << ici->second.attrib << '\n';
564                         lyxerr << "   help: "
565                                << ici->second.helpText << '\n';
566                 }
567                 help = ici->second.helpText;
568                 // if the is no help text use the name of the func instead.
569                 if (help.empty()) help = ici->second.name;
570         }
571
572         if (help.empty()) {
573                 help = _("No description available!");
574         } else if (!ev.argument.empty()) {
575                 help += ' ';
576                 help += ev.argument;
577         }
578
579         return help;
580 }
581
582
583 bool LyXAction::funcHasFlag(kb_action action,
584                             LyXAction::func_attrib flag) const
585 {
586         info_map::const_iterator ici = lyx_info_map.find(action);
587
588         if (ici != lyx_info_map.end()) {
589                 return ici->second.attrib & flag;
590         } else {
591                 // it really should exist, but...
592                 lyxerr << "LyXAction::funcHasFlag: "
593                         "No info about kb_action: " << action << '\n';
594                 return false;
595         }
596 }
597
598
599 LyXAction::const_func_iterator LyXAction::func_begin() const
600 {
601         return lyx_func_map.begin();
602 }
603
604
605 LyXAction::const_func_iterator LyXAction::func_end() const
606 {
607         return lyx_func_map.end();
608 }
609
610
611 ostream & operator<<(ostream & o, kb_action action)
612 {
613         return o << int(action);
614 }