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