1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * ====================================================== */
14 #pragma implementation
17 #include "LyXAction.h"
20 #include "support/lstrings.h"
22 // only to get access to NEW_INSETS and NEW_TABULAR
23 #include "lyxparagraph.h"
30 NAMING RULES FOR USER-COMMANDS
31 Here's the set of rules to apply when a new command name is introduced:
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'.
43 (May 19 1996, 12:04, RvdK)
49 void LyXAction::newFunc(kb_action action, string const & name,
50 string const & helpText, unsigned int attrib)
52 lyx_func_map[name] = action;
55 tmpinfo.attrib = attrib;
56 tmpinfo.helpText = helpText;
57 lyx_info_map[action] = tmpinfo;
64 char const * helpText;
68 void LyXAction::init()
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
76 static bool init = false;
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"),
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"),
107 { LFUN_BIBTEX_STYLE, "bibtex-style", "", Noop },
108 { LFUN_BREAKLINE, "break-line", "", Noop },
109 { LFUN_BREAKPARAGRAPH, "break-paragraph", "", Noop },
110 { LFUN_BREAKPARAGRAPHKEEPLAYOUT, "break-paragraph-keep-layout",
112 { LFUN_BREAKPARAGRAPH_SKIP, "break-paragraph-skip", "", Noop },
113 { LFUN_BUILDPROG, "build-program",
114 N_("Build program"), ReadOnly },
115 { LFUN_AUTOSAVE, "buffer-auto-save", N_("Autosave"), Noop },
116 { LFUN_BEGINNINGBUF, "buffer-begin",
117 N_("Go to beginning of document"), ReadOnly },
118 { LFUN_BEGINNINGBUFSEL, "buffer-begin-select",
119 N_("Select to beginning of document"), ReadOnly },
120 { LFUN_CHILDINSERT, "buffer-child-insert", "", Noop },
121 { LFUN_CHILDOPEN, "buffer-child-open", "", ReadOnly },
122 { LFUN_RUNCHKTEX, "buffer-chktex", N_("Check TeX"), ReadOnly },
123 { LFUN_CLOSEBUFFER, "buffer-close", N_("Close"), ReadOnly },
124 { LFUN_ENDBUF, "buffer-end",
125 N_("Go to end of document"), ReadOnly },
126 { LFUN_ENDBUFSEL, "buffer-end-select",
127 N_("Select to end of document"), ReadOnly },
128 { LFUN_EXPORT, "buffer-export", N_("Export to"), ReadOnly },
129 { LFUN_FAX, "buffer-fax", N_("Fax"), ReadOnly },
131 { LFUN_INSERTFOOTNOTE, "buffer-float-insert", "", Noop },
133 { LFUN_IMPORT, "buffer-import",
134 N_("Import document"), NoBuffer },
135 { LFUN_BUFFERBULLETSSELECT, "buffer-itemize-bullets-select",
137 { LFUN_BUFFER_PRINT, "buffer-print-xtl", N_("Print"),
139 { LFUN_PRINTER_PARAMS_GET, "printer-params-get",
140 N_("Get the printer parameters"), ReadOnly },
141 { LFUN_MENUNEW, "buffer-new", N_("New document") , NoBuffer },
142 { LFUN_MENUNEWTMPLT,"buffer-new-template",
143 N_("New document from template"), NoBuffer },
144 { LFUN_MENUOPEN, "buffer-open", N_("Open"), NoBuffer },
145 { LFUN_MENUPRINT, "buffer-print", N_("Print"), ReadOnly },
146 { LFUN_MENURELOAD, "buffer-reload",
147 N_("Revert to saved"), ReadOnly },
148 { LFUN_SWITCHBUFFER, "buffer-switch",
149 N_("Switch to an open document"), ReadOnly },
150 { LFUN_READ_ONLY_TOGGLE, "buffer-toggle-read-only",
151 N_("Toggle read-only"), ReadOnly },
152 { LFUN_RUNLATEX, "buffer-typeset", N_("Update DVI"),
154 { LFUN_RUNDVIPS, "buffer-typeset-ps",
155 N_("Update PostScript"), ReadOnly },
156 { LFUN_PREVIEW, "buffer-view", N_("View DVI") , ReadOnly },
157 { LFUN_PREVIEWPS, "buffer-view-ps",
158 N_("View PostScript") , ReadOnly },
159 { LFUN_MENUWRITE, "buffer-write", N_("Save"), ReadOnly },
160 { LFUN_MENUWRITEAS, "buffer-write-as", N_("Save As"),
162 { LFUN_CANCEL, "cancel", N_("Cancel"), NoBuffer },
163 { LFUN_LEFT, "char-backward", N_("Go one char back"),
165 { LFUN_RIGHT, "char-forward", N_("Go one char forward"),
167 { LFUN_CITATION_CREATE, "citation-insert",
168 N_("Insert citation"), Noop },
169 { LFUN_EXEC_COMMAND, "command-execute", "", NoBuffer },
170 { LFUN_PREFIX, "command-prefix",
171 N_("Execute command"), NoBuffer },
172 { LFUN_SEQUENCE, "command-sequence", "", Noop },
173 { LFUN_COPY, "copy", N_("Copy"), ReadOnly },
174 { LFUN_CUT, "cut", N_("Cut"), Noop },
175 { LFUN_BACKSPACE, "delete-backward", "", Noop },
176 { LFUN_BACKSPACE_SKIP, "delete-backward-skip", "", Noop },
177 { LFUN_DELETE, "delete-forward", "", Noop },
178 { LFUN_DELETE_SKIP, "delete-forward-skip", "", Noop },
179 { LFUN_DEPTH_MIN, "depth-decrement",
180 N_("Decrement environment depth"), Noop },
181 { LFUN_DEPTH_PLUS, "depth-increment",
182 N_("Increment environment depth"), Noop },
183 { LFUN_DEPTH, "depth-next",
184 N_("Change environment depth"), Noop },
185 { LFUN_LDOTS, "dots-insert", N_("Insert ... dots"), Noop },
186 { LFUN_DOWN, "down", N_("Go down"), ReadOnly },
187 { LFUN_DOWNSEL, "down-select",
188 N_("Select next line"), ReadOnly },
189 { LFUN_DROP_LAYOUTS_CHOICE, "drop-layouts-choice",
190 N_("Choose Paragraph Environment"), ReadOnly },
191 { LFUN_END_OF_SENTENCE, "end-of-sentence-period-insert",
192 N_("Insert end of sentence period"), Noop },
193 { LFUN_GOTOERROR, "error-next", N_("Go to next error"), Noop },
194 { LFUN_REMOVEERRORS, "error-remove-all",
195 N_("Remove all error boxes"), ReadOnly },
196 { LFUN_INSET_ERT, "ert-insert",
197 N_("Insert a new ERT Inset"), Noop },
198 { LFUN_INSET_EXTERNAL, "external-insert",
199 N_("Insert a new external inset"), Noop },
200 { LFUN_FIGURE, "figure-insert", N_("Insert Figure"), Noop },
201 { LFUN_INSET_GRAPHICS, "graphics-insert",
202 N_("Insert Graphics"), Noop },
203 { LFUN_FILE_INSERT, "file-insert", "", Noop },
204 { LFUN_FILE_INSERT_ASCII, "file-insert-ascii", "", Noop },
205 { LFUN_FILE_NEW, "file-new", "", NoBuffer },
206 { LFUN_FILE_OPEN, "file-open", "", NoBuffer },
207 { LFUN_MENUSEARCH, "find-replace", N_("Find & Replace"),
209 { LFUN_BOLD, "font-bold", N_("Toggle bold"), Noop },
210 { LFUN_CODE, "font-code", N_("Toggle code style"), Noop },
211 { LFUN_DEFAULT, "font-default", N_("Default font style"),
213 { LFUN_EMPH, "font-emph", N_("Toggle emphasize"), Noop },
214 { LFUN_FREE, "font-free", N_("Toggle user defined style"),
216 { LFUN_NOUN, "font-noun", N_("Toggle noun style"), Noop },
217 { LFUN_ROMAN, "font-roman", N_("Toggle roman font style"),
219 { LFUN_SANS, "font-sans", N_("Toggle sans font style"), Noop },
220 { LFUN_FONT_SIZE, "font-size", N_("Set font size"), Noop },
221 { LFUN_FONT_STATE, "font-state", N_("Show font state"),
223 { LFUN_UNDERLINE, "font-underline",
224 N_("Toggle font underline"), Noop },
226 { LFUN_FOOTMELT, "footnote-insert", N_("Insert Footnote"),
229 { LFUN_INSET_FOOTNOTE, "footnote-insert",
230 N_("Insert Footnote"), Noop },
232 { LFUN_INSET_MARGINAL, "marginalnote-insert",
233 N_("Insert Marginalnote"), Noop },
234 { LFUN_RIGHTSEL, "forward-select", N_("Select next char"),
236 { LFUN_HFILL, "hfill-insert",
237 N_("Insert horizontal fill"), Noop },
238 { LFUN_HELP_COPYRIGHT, "help-copyright",
239 N_("Display copyright information"), NoBuffer },
240 { LFUN_HELP_CREDITS, "help-credits",
241 N_("Show the list of people who helped writing LyX"),
243 { LFUN_HELP_OPEN, "help-open", N_("Open a Help file"),
245 { LFUN_HELP_VERSION, "help-version",
246 N_("Show the actual LyX version"), NoBuffer},
247 { LFUN_HTMLURL, "html-insert", "", Noop },
248 { LFUN_HYPHENATION, "hyphenation-point-insert",
249 N_("Insert hyphenation point"), Noop },
250 { LFUN_INDEX_CREATE, "index-insert",
251 N_("Insert index item"), Noop },
252 { LFUN_INDEX_INSERT_LAST, "index-insert-last",
253 N_("Insert last index item"), Noop },
254 { LFUN_INDEX_PRINT, "index-print", N_("Insert index list"),
256 { LFUN_KMAP_OFF, "keymap-off", N_("Turn off keymap"),
258 { LFUN_KMAP_PRIM, "keymap-primary",
259 N_("Use primary keymap"), ReadOnly },
260 { LFUN_KMAP_SEC, "keymap-secondary",
261 N_("Use secondary keymap"), ReadOnly },
262 { LFUN_KMAP_TOGGLE, "keymap-toggle", N_("Toggle keymap"),
264 { LFUN_INSERT_LABEL, "label-insert", N_("Insert Label"),
266 { LFUN_LANGUAGE, "language", N_("Change language"), Noop },
267 { LFUN_LATEX_LOG, "latex-view-log", N_("View LaTeX log"),
269 { LFUN_LAYOUT, "layout", "", Noop },
270 { LFUN_LAYOUT_CHARACTER, "layout-character", "", Noop },
271 { LFUN_LAYOUT_COPY, "layout-copy",
272 N_("Copy paragraph environment type"), Noop },
273 { LFUN_LAYOUT_DOCUMENT, "layout-document", "", ReadOnly },
274 { LFUN_LAYOUTNO, "layout-number", "", Noop }, // internal only
275 { LFUN_LAYOUT_PARAGRAPH, "layout-paragraph", "", ReadOnly },
276 { LFUN_LAYOUT_PAPER, "layout-paper", "", ReadOnly },
277 { LFUN_LAYOUT_PASTE, "layout-paste",
278 N_("Paste paragraph environment type"), Noop },
279 { LFUN_LAYOUT_PREAMBLE, "layout-preamble", "", ReadOnly },
280 { LFUN_LAYOUT_QUOTES, "layout-quotes", "", ReadOnly },
281 { LFUN_LAYOUT_SAVE_DEFAULT, "layout-save-default", "",
283 { LFUN_LAYOUT_TABLE, "layout-table",
284 N_("Open the table layout"), Noop },
285 { LFUN_LAYOUT_TABULAR, "layout-tabular",
286 N_("Open the tabular layout"), Noop },
287 { LFUN_HOME, "line-begin",
288 N_("Go to beginning of line"), ReadOnly },
289 { LFUN_HOMESEL, "line-begin-select",
290 N_("Select to beginning of line"), ReadOnly },
291 { LFUN_DELETE_LINE_FORWARD, "line-delete-forward", "", Noop },
292 { LFUN_END, "line-end", N_("Go to end of line"), ReadOnly },
293 { LFUN_ENDSEL, "line-end-select",
294 N_("Select to end of line"), ReadOnly },
295 { LFUN_LOA_INSERT, "loa-insert",
296 N_("Insert list of algorithms"), Noop },
297 { LFUN_LOAVIEW, "loa-view",
298 N_("View list of algorithms"), ReadOnly },
299 { LFUN_LOF_INSERT, "lof-insert",
300 N_("Insert list of figures"), Noop },
301 { LFUN_LOFVIEW, "lof-view",
302 N_("View list of figures"), ReadOnly },
303 { LFUN_LOT_INSERT, "lot-insert",
304 N_("Insert list of tables"), Noop },
305 { LFUN_LOTVIEW, "lot-view",
306 N_("View list of tables"), ReadOnly },
307 { LFUN_QUIT, "lyx-quit", N_("Exit"), NoBuffer },
309 { LFUN_MARGINMELT, "marginpar-insert",
310 N_("Insert Margin note"), Noop },
312 { LFUN_MARK_OFF, "mark-off", "", ReadOnly },
313 { LFUN_MARK_ON, "mark-on", "", ReadOnly },
314 { LFUN_SETMARK, "mark-toggle", "", ReadOnly },
315 { LFUN_MATH_DELIM, "math-delim", "", Noop },
316 { LFUN_MATH_DISPLAY, "math-display", "", Noop },
317 { LFUN_GREEK, "math-greek", N_("Math Greek"), Noop },
318 { LFUN_GREEK_TOGGLE, "math-greek-toggle", "", Noop },
319 { LFUN_INSERT_MATH, "math-insert",
320 N_("Insert math symbol"), Noop },
321 { LFUN_MATH_LIMITS, "math-limits", "", Noop },
322 { LFUN_MATH_MACRO, "math-macro", "", Noop },
323 { LFUN_MATH_MACROARG, "math-macro-arg", "", Noop },
324 { LFUN_INSERT_MATRIX, "math-matrix", "", Noop },
325 { LFUN_MATH_MODE, "math-mode", N_("Math mode"), Noop },
326 { LFUN_MATH_NONUMBER, "math-nonumber", "", Noop },
327 { LFUN_MATH_NUMBER, "math-number", "", Noop },
328 { LFUN_MATH_PANEL, "math-panel", "", Noop },
329 { LFUN_MATH_SIZE, "math-size", "", Noop },
330 { LFUN_MELT, "melt", N_("Melt"), Noop },
331 { LFUN_MENU_OPEN_BY_NAME, "menu-open", "", NoBuffer },
332 { LFUN_MENU_SEPARATOR, "menu-separator-insert", "", Noop },
333 { LFUN_META_FAKE, "meta-prefix", "", NoBuffer },
334 { LFUN_INSERT_NOTE, "note-insert", "", Noop },
335 { LFUN_GOTONOTE, "note-next", "", ReadOnly },
336 { LFUN_OPENSTUFF, "open-stuff", "", ReadOnly },
337 { LFUN_DOWN_PARAGRAPH, "paragraph-down",
338 N_("Go one paragraph down"), ReadOnly },
339 { LFUN_DOWN_PARAGRAPHSEL, "paragraph-down-select",
340 N_("Select next paragraph"), ReadOnly },
341 { LFUN_UP_PARAGRAPH, "paragraph-up",
342 N_("Go one paragraph up"), ReadOnly },
343 { LFUN_UP_PARAGRAPHSEL, "paragraph-up-select",
344 N_("Select previous paragraph"), ReadOnly },
345 { LFUN_PARENTINSERT, "parent-insert", "", Noop },
346 { LFUN_PASTE, "paste", N_("Paste") , Noop },
347 { LFUN_DIALOG_PREFERENCES, "dialog-preferences",
348 N_("Edit Preferences"), NoBuffer },
349 { LFUN_SAVEPREFERENCES, "preferences-save",
350 N_("Save Preferences"), NoBuffer },
351 { LFUN_PASTESELECTION, "primary-selection-paste", "", Noop },
352 { LFUN_PROTECTEDSPACE, "protected-space-insert",
353 N_("Insert protected space"), Noop },
354 { LFUN_QUOTE, "quote-insert", N_("Insert quote"), Noop },
355 { LFUN_RECONFIGURE, "reconfigure",
356 N_("Reconfigure"), NoBuffer },
357 { LFUN_REDO, "redo", N_("Redo"), Noop },
358 { LFUN_REFBACK, "reference-back", "", ReadOnly },
359 { LFUN_REFGOTO, "reference-goto", "", ReadOnly },
360 { LFUN_INSERT_REF, "reference-insert",
361 N_("Insert cross reference"), ReadOnly },
362 { LFUN_REFTOGGLE, "reference-toggle", "", Noop },
363 { LFUN_NEXT, "screen-down", "", ReadOnly },
364 { LFUN_NEXTSEL, "screen-down-select", "", ReadOnly },
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"),
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_SPELLCHECK, "spellchecker", "", Noop },
382 { LFUN_INSERT_MATH, "symbol-insert", "", Noop },
383 { LFUN_SHIFT_TAB, "tab-backward", "", Noop },
384 { LFUN_TAB, "tab-forward", "", Noop },
385 { LFUN_TABINSERT, "tab-insert", "", Noop },
387 { LFUN_TABLE, "table-insert", N_("Insert Table"), Noop },
389 { LFUN_TABULAR_FEATURE, "tabular-feature",
390 N_("Tabular Features"), Noop },
391 { LFUN_INSET_TABULAR, "tabular-insert",
392 N_("Insert a new Tabular Inset"), Noop },
393 { LFUN_TEX, "tex-mode", N_("Toggle TeX style"), Noop },
394 { LFUN_INSET_TEXT, "text-insert",
395 N_("Insert a new Text Inset"), 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"),
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_VC_CHECKIN, "vc-check-in", "", ReadOnly },
410 { LFUN_VC_CHECKOUT, "vc-check-out", "", ReadOnly },
411 { LFUN_VC_HISTORY, "vc-history", "", ReadOnly },
412 { LFUN_VC_REGISTER, "vc-register",
413 N_("Register document under version control"), ReadOnly },
414 { LFUN_VC_REVERT, "vc-revert", "", ReadOnly },
415 { LFUN_VC_UNDO, "vc-undo-last", "", ReadOnly },
416 { LFUN_WORDLEFT, "word-backward", "", ReadOnly },
417 { LFUN_WORDLEFTSEL, "word-backward-select", "", ReadOnly },
418 { LFUN_CAPITALIZE_WORD, "word-capitalize", "", Noop },
419 { LFUN_DELETE_WORD_BACKWARD, "word-delete-backward",
421 { LFUN_DELETE_WORD_FORWARD, "word-delete-forward", "", Noop },
422 { LFUN_WORDFINDBACKWARD, "word-find-backward", "", ReadOnly },
423 { LFUN_WORDFINDFORWARD, "word-find-forward", "", ReadOnly },
424 { LFUN_WORDRIGHT, "word-forward", "", ReadOnly },
425 { LFUN_WORDRIGHTSEL, "word-forward-select", "", ReadOnly },
426 { LFUN_LOWCASE_WORD, "word-lowcase", "", Noop },
427 { LFUN_UPCASE_WORD, "word-upcase", "", Noop },
428 { LFUN_DATE_INSERT, "date-insert", "", Noop },
429 { LFUN_PARAGRAPH_SPACING, "paragraph-spacing", "", Noop },
430 { LFUN_SET_COLOR, "set-color", "", Noop },
431 { LFUN_INSET_MINIPAGE, "minipage-insert", "", Noop },
432 { LFUN_INSET_FLOAT, "float-insert", "", Noop },
433 { LFUN_INSET_LIST, "list-insert", "", Noop },
434 { LFUN_INSET_THEOREM, "theorem-insert", "", Noop },
435 { LFUN_INSET_CAPTION, "caption-insert", "", Noop },
436 { LFUN_NOACTION, "", "", Noop }
440 while (items[i].action != LFUN_NOACTION) {
441 newFunc(items[i].action,
443 _(items[i].helpText),
452 LyXAction::LyXAction()
458 // Search for an existent pseudoaction, return LFUN_UNKNOWN_ACTION
459 // if it doesn't exist.
460 int LyXAction::searchActionArg(kb_action action, string const & arg) const
462 arg_map::const_iterator pit = lyx_arg_map.find(action);
464 if (pit == lyx_arg_map.end()) {
465 // the action does not have any pseudoactions
466 lyxerr[Debug::ACTION] << "Action " << action
467 << " does not have any pseudo actions."
469 return LFUN_UNKNOWN_ACTION;
472 arg_item::const_iterator aci = (*pit).second.find(arg);
474 if (aci == (*pit).second.end()) {
475 // the action does not have any pseudoactions with this arg
476 lyxerr[Debug::ACTION]
477 << "Action " << action
478 << "does not have any pseudoactions with arg "
480 return LFUN_UNKNOWN_ACTION;
483 // pseudo action exist
484 lyxerr[Debug::ACTION] << "Pseudoaction exist["
486 << arg << "] = " << (*aci).second << endl;
488 return (*aci).second;
492 // Returns a pseudo-action given an action and its argument.
493 int LyXAction::getPseudoAction(kb_action action, string const & arg) const
495 int psdaction = searchActionArg(action, arg);
497 if (isPseudoAction(psdaction)) return psdaction;
499 static unsigned int pseudo_counter = LFUN_LASTACTION;
501 // Create new pseudo action.
503 tmp_p.action = action;
505 lyx_pseudo_map[++pseudo_counter] = tmp_p;
507 // First ensure that the action is in lyx_arg_map;
509 // get the arg_item map
510 arg_map::iterator ami = lyx_arg_map.find(action);
511 // put the new pseudo function in it
512 (*ami).second[arg] = pseudo_counter;
514 lyxerr[Debug::ACTION] << "Creating new pseudoaction "
515 << pseudo_counter << " for [" << action
516 << '|' << arg << "]\n";
518 return pseudo_counter;
522 // Retrieves the real action and its argument.
523 // perhaps a pair<kb_action, string> should be returned?
524 kb_action LyXAction::retrieveActionArg(int pseudo, string & arg) const
526 pseudo_map::const_iterator pit = lyx_pseudo_map.find(pseudo);
528 if (pit != lyx_pseudo_map.end()) {
529 lyxerr[Debug::ACTION] << "Found the pseudoaction: ["
530 << (*pit).second.action << '|'
531 << (*pit).second.arg << '\n';
532 arg = (*pit).second.arg;
533 return (*pit).second.action;
535 lyxerr << "Lyx Error: Unrecognized pseudo-action\n";
536 return LFUN_UNKNOWN_ACTION;
542 // Returns an action tag from a string.
543 int LyXAction::LookupFunc(string const & func) const
545 if (func.empty()) return LFUN_NOACTION;
547 // split action and arg
549 string argstr = split(func, actstr, ' ');
550 lyxerr[Debug::ACTION] << "Action: " << actstr << '\n';
551 lyxerr[Debug::ACTION] << "Arg : " << argstr << '\n';
553 func_map::const_iterator fit = lyx_func_map.find(actstr);
555 if (!argstr.empty() && fit != lyx_func_map.end()) {
556 // might be pseudo (or create one)
557 return getPseudoAction((*fit).second, argstr);
560 return fit != lyx_func_map.end() ? (*fit).second : LFUN_UNKNOWN_ACTION;
564 //#ifdef WITH_WARNINGS
565 //#warning Not working as it should.
567 // I have no clue what is wrong with it... (Lgb)
568 int LyXAction::getApproxFunc(string const & func) const
569 // This func should perhaps also be able to return a list of all
570 // actions that has func as a prefix. That should actually be quite
571 // easy, just let it return a vector<int> or something.
573 int action = LookupFunc(func);
574 if (action == LFUN_UNKNOWN_ACTION) {
575 // func is not an action, but perhaps it is
576 // part of one...check if it is prefix if one of the
578 // Checking for prefix is not so simple, but
579 // using a simple bounding function gives
580 // a similar result. [ale 19981103]
581 func_map::const_iterator fit =
582 lyx_func_map.lower_bound(func);
584 if (fit != lyx_func_map.end()) {
585 action = (*fit).second;
587 } else { // Go get the next function
588 func_map::const_iterator fit =
589 lyx_func_map.upper_bound(func);
591 if (fit != lyx_func_map.end()) {
592 action = (*fit).second;
600 string LyXAction::getApproxFuncName(string const & func) const
602 int f = getApproxFunc(func);
603 // This will return empty string if f isn't an action.
604 return getActionName(f);
608 string LyXAction::getActionName(int action) const
612 if (isPseudoAction(action)) {
613 ac = retrieveActionArg(action, arg);
617 ac = static_cast<kb_action>(action);
619 info_map::const_iterator iit = lyx_info_map.find(ac);
621 if (iit != lyx_info_map.end())
622 return (*iit).second.name + arg;
628 // Returns one line help associated with a (pseudo)action, i.e. appends
629 // the argument of the action if necessary
630 string LyXAction::helpText(int pseudoaction) const
635 if (isPseudoAction(pseudoaction))
636 action = retrieveActionArg(pseudoaction, arg);
638 action = static_cast<kb_action>(pseudoaction);
640 info_map::const_iterator ici = lyx_info_map.find(action);
641 if (ici != lyx_info_map.end()) {
642 if (lyxerr.debugging(Debug::ACTION)) {
643 lyxerr << "Action: " << action << '\n';
645 << (*ici).second.name << '\n';
646 lyxerr << " attrib: "
647 << (*ici).second.attrib << '\n';
649 << (*ici).second.helpText << '\n';
651 help = (*ici).second.helpText;
652 // if the is no help text use the name of the func instead.
653 if (help.empty()) help = (*ici).second.name;
657 help = _("No description available!");
658 } else if (!arg.empty()) {
667 bool LyXAction::funcHasFlag(kb_action action,
668 LyXAction::func_attrib flag) const
670 info_map::const_iterator ici = lyx_info_map.find(action);
672 if (ici != lyx_info_map.end()) {
673 return (*ici).second.attrib & flag;
675 // it really should exist, but...
676 lyxerr << "LyXAction::funcHasFlag: "
677 "No info about kb_action: " << action << '\n';
684 ostream & operator<<(ostream & o, kb_action action)
686 return o << int(action);