1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-1999 The LyX Team.
9 * ====================================================== */
14 #pragma implementation
17 #include "LyXAction.h"
20 #include "support/lstrings.h"
23 NAMING RULES FOR USER-COMMANDS
24 Here's the set of rules to apply when a new command name is introduced:
26 1) Use the object.event order. That is, use `word-forward'
27 instead of `forward-word'.
28 2) Don't introduce an alias for an already named object. Same for events.
29 3) Forward movement or focus is called `forward' (not `right').
30 4) Backward movement or focus is called `backward' (not `left').
31 5) Upward movement of focus is called `up'.
32 6) Downward movement is called `down'.
33 7) The begin of an object is called `begin' (not `start').
34 8) The end of an object is called `end'.
36 (May 19 1996, 12:04, RvdK)
43 void LyXAction::newFunc(kb_action action, string const & name,
44 string const & helpText, unsigned int attrib)
46 lyx_func_map[name] = action;
49 tmpinfo.attrib = attrib;
50 tmpinfo.helpText = helpText;
51 lyx_info_map[action] = tmpinfo;
55 void LyXAction::init()
57 static bool init = false;
60 newFunc(LFUN_ACUTE, "accent-acute",
62 newFunc( LFUN_BREVE, "accent-breve",
64 newFunc( LFUN_CARON,"accent-caron",
66 newFunc(LFUN_CEDILLA,"accent-cedilla",
68 newFunc(LFUN_CIRCLE,"accent-circle",
70 newFunc(LFUN_CIRCUMFLEX,"accent-circumflex",
72 newFunc(LFUN_DOT,"accent-dot",
74 newFunc(LFUN_GRAVE,"accent-grave",
76 newFunc(LFUN_HUNG_UMLAUT,"accent-hungarian-umlaut",
78 newFunc(LFUN_MACRON,"accent-macron",
80 newFunc(LFUN_OGONEK,"accent-ogonek",
82 newFunc(LFUN_SPECIAL_CARON,"accent-special-caron",
84 newFunc(LFUN_TIE,"accent-tie",
86 newFunc(LFUN_TILDE,"accent-tilde",
88 newFunc(LFUN_UMLAUT,"accent-umlaut",
90 newFunc(LFUN_UNDERBAR,"accent-underbar",
92 newFunc(LFUN_UNDERDOT,"accent-underdot",
94 newFunc(LFUN_VECTOR,"accent-vector",
96 newFunc(LFUN_APPENDIX,"appendix",
97 _("Insert appendix"), Noop);
98 newFunc(LFUN_APROPOS,"apropos",
99 _("Describe command"), NoBuffer|ReadOnly);
100 newFunc(LFUN_LEFTSEL,"backward-select",
101 _("Select previous char"), ReadOnly);
102 newFunc(LFUN_BIBDB_ADD,"bibtex-database-add",
104 newFunc(LFUN_BIBDB_DEL,"bibtex-database-del",
106 newFunc(LFUN_INSERT_BIBTEX,"bibtex-insert",
107 _("Insert bibtex"), Noop);
108 newFunc(LFUN_BIBTEX_STYLE,"bibtex-style",
110 newFunc(LFUN_BREAKLINE,"break-line",
112 newFunc(LFUN_BREAKPARAGRAPH,"break-paragraph",
114 newFunc(LFUN_BREAKPARAGRAPHKEEPLAYOUT,"break-paragraph-keep-layout",
116 newFunc(LFUN_BREAKPARAGRAPH_SKIP,"break-paragraph-skip",
118 newFunc(LFUN_BUILDPROG, "build-program", _("Build program"), Noop);
119 newFunc(LFUN_AUTOSAVE,"buffer-auto-save",
120 _("Autosave"), Noop);
121 newFunc(LFUN_BEGINNINGBUF,"buffer-begin",
122 _("Go to beginning of document"), ReadOnly);
123 newFunc(LFUN_BEGINNINGBUFSEL,"buffer-begin-select",
124 _("Select to beginning of document"), ReadOnly);
125 newFunc(LFUN_CHILDINSERT,"buffer-child-insert",
127 newFunc(LFUN_CHILDOPEN,"buffer-child-open",
129 newFunc(LFUN_RUNCHKTEX,"buffer-chktex",
130 _("Check TeX"), ReadOnly);
131 newFunc(LFUN_CLOSEBUFFER,"buffer-close",
132 _("Close"), ReadOnly);
133 newFunc(LFUN_ENDBUF,"buffer-end",
134 _("Go to end of document"), ReadOnly);
135 newFunc(LFUN_ENDBUFSEL,"buffer-end-select",
136 _("Select to end of document"), ReadOnly);
137 newFunc(LFUN_EXPORT,"buffer-export",
138 _("Export to"), ReadOnly);
139 newFunc(LFUN_FAX,"buffer-fax",
141 newFunc(LFUN_INSERTFOOTNOTE, "buffer-float-insert", "", Noop);
142 newFunc(LFUN_IMPORT,"buffer-import",
143 _("Import document"), NoBuffer);
144 newFunc(LFUN_BUFFERBULLETSSELECT, "buffer-itemize-bullets-select",
146 newFunc( LFUN_MENUNEW,"buffer-new",
147 _("New document") , NoBuffer);
148 newFunc(LFUN_MENUNEWTMPLT,"buffer-new-template",
149 _("New document from template"), NoBuffer);
150 newFunc(LFUN_MENUOPEN,"buffer-open",
151 _("Open"), NoBuffer);
152 newFunc(LFUN_PREVBUFFER,"buffer-previous",
153 _("Switch to previous document"), ReadOnly);
154 newFunc(LFUN_MENUPRINT,"buffer-print",
155 _("Print"), ReadOnly);
156 newFunc(LFUN_MENURELOAD,"buffer-reload",
157 _("Revert to saved"), ReadOnly);
158 newFunc(LFUN_READ_ONLY_TOGGLE,"buffer-toggle-read-only",
159 _("Toggle read-only"), ReadOnly);
160 newFunc(LFUN_RUNLATEX,"buffer-typeset",
161 _("Update DVI"), ReadOnly);
162 newFunc(LFUN_RUNDVIPS,"buffer-typeset-ps",
163 _("Update PostScript"), ReadOnly);
164 newFunc(LFUN_PREVIEW,"buffer-view",
165 _("View DVI") , ReadOnly);
166 newFunc(LFUN_PREVIEWPS,"buffer-view-ps",
167 _("View PostScript") , ReadOnly);
168 newFunc(LFUN_MENUWRITE,"buffer-write",
169 _("Save"), ReadOnly);
170 newFunc(LFUN_MENUWRITEAS,"buffer-write-as",
171 _("Save As"), ReadOnly);
172 newFunc(LFUN_CANCEL,"cancel",
173 _("Cancel"), NoBuffer);
174 newFunc(LFUN_LEFT,"char-backward",
175 _("Go one char back"), ReadOnly);
176 newFunc(LFUN_RIGHT,"char-forward",
177 _("Go one char forward"), ReadOnly);
178 newFunc(LFUN_INSERT_CITATION,"citation-insert",
179 _("Insert citation"), Noop);
180 newFunc(LFUN_EXEC_COMMAND,"command-execute",
182 newFunc(LFUN_PREFIX,"command-prefix",
183 _("Execute command"), NoBuffer);
184 newFunc(LFUN_SEQUENCE, "command-sequence", "", Noop);
185 newFunc(LFUN_COPY,"copy",
186 _("Copy"), ReadOnly);
187 newFunc(LFUN_CUT,"cut",
189 newFunc(LFUN_BACKSPACE,"delete-backward",
191 newFunc(LFUN_BACKSPACE_SKIP,"delete-backward-skip",
193 newFunc(LFUN_DELETE,"delete-forward",
195 newFunc(LFUN_DELETE_SKIP,"delete-forward-skip",
197 newFunc(LFUN_DEPTH_MIN,"depth-decrement",
198 _("Decrement environment depth"), Noop);
199 newFunc(LFUN_DEPTH_PLUS,"depth-increment",
200 _("Increment environment depth"), Noop);
201 newFunc(LFUN_DEPTH,"depth-next",
202 _("Change environment depth"), Noop);
203 newFunc(LFUN_LDOTS,"dots-insert",
204 _("Insert ... dots"), Noop);
205 newFunc(LFUN_DOWN,"down",
206 _("Go down"), ReadOnly);
207 newFunc(LFUN_DOWNSEL,"down-select",
208 _("Select next line"), ReadOnly);
209 newFunc(LFUN_DROP_LAYOUTS_CHOICE,"drop-layouts-choice",
210 _("Choose Paragraph Environment"), ReadOnly);
211 newFunc(LFUN_END_OF_SENTENCE,"end-of-sentence-period-insert",
212 _("Insert end of sentence period"), Noop);
213 newFunc(LFUN_GOTOERROR,"error-next",
214 _("Go to next error"), Noop);
215 newFunc(LFUN_REMOVEERRORS,"error-remove-all",
216 _("Remove all error boxes"), ReadOnly);
217 newFunc(LFUN_FIGURE,"figure-insert",
218 _("Insert Figure"), Noop);
219 newFunc(LFUN_FILE_INSERT,"file-insert",
221 newFunc(LFUN_FILE_INSERT_ASCII,"file-insert-ascii",
223 newFunc(LFUN_FILE_NEW,"file-new",
225 newFunc(LFUN_FILE_OPEN,"file-open",
227 newFunc( LFUN_MENUSEARCH,"find-replace",
228 _("Find & Replace") , Noop);
229 newFunc(LFUN_BOLD,"font-bold",
230 _("Toggle bold"), Noop);
231 newFunc(LFUN_CODE,"font-code",
232 _("Toggle code style"), Noop);
233 newFunc(LFUN_DEFAULT,"font-default",
234 _("Default font style"), Noop);
235 newFunc(LFUN_EMPH,"font-emph",
236 _("Toggle emphasize"), Noop);
237 newFunc(LFUN_FREE,"font-free",
238 _("Toggle user defined style"), Noop);
239 newFunc(LFUN_NOUN,"font-noun",
240 _("Toggle noun style"), Noop);
241 newFunc(LFUN_ROMAN,"font-roman",
242 _("Toggle roman font style"), Noop);
243 newFunc(LFUN_SANS,"font-sans",
244 _("Toggle sans font style"), Noop);
245 newFunc(LFUN_FONT_SIZE,"font-size",
246 _("Set font size"), Noop);
247 newFunc(LFUN_FONT_STATE,"font-state",
248 _("Show font state"), ReadOnly);
249 newFunc(LFUN_UNDERLINE,"font-underline",
250 _("Toggle font underline"), Noop);
251 newFunc(LFUN_FOOTMELT,"footnote-insert",
252 _("Insert Footnote"), Noop);
253 newFunc(LFUN_RIGHTSEL,"forward-select",
254 _("Select next char"), ReadOnly);
255 newFunc(LFUN_HFILL,"hfill-insert",
256 _("Insert horizontal fill"), Noop);
257 newFunc(LFUN_HTMLURL,"html-insert",
259 newFunc(LFUN_HYPHENATION,"hyphenation-point-insert",
260 _("Insert hyphenation point"), Noop);
261 newFunc(LFUN_INDEX_INSERT,"index-insert",
262 _("Insert index item"), Noop);
263 newFunc(LFUN_INDEX_INSERT_LAST, "index-insert-last",
264 _("Insert last index item"), Noop);
265 newFunc(LFUN_INDEX_PRINT,"index-print",
266 _("Insert index list"), Noop);
267 newFunc(LFUN_KMAP_OFF,"keymap-off",
268 _("Turn off keymap"), ReadOnly);
269 newFunc(LFUN_KMAP_PRIM,"keymap-primary",
270 _("Use primary keymap"), ReadOnly);
271 newFunc(LFUN_KMAP_SEC,"keymap-secondary",
272 _("Use secondary keymap"), ReadOnly);
273 newFunc(LFUN_KMAP_TOGGLE,"keymap-toggle",
274 _("Toggle keymap"), ReadOnly);
275 newFunc(LFUN_INSERT_LABEL,"label-insert",
276 _("Insert Label"), Noop);
277 newFunc(LFUN_LATEX_LOG,"latex-view-log",
278 _("View LaTeX log"), ReadOnly);
279 newFunc(LFUN_LAYOUT,"layout",
281 newFunc(LFUN_LAYOUT_CHARACTER,"layout-character",
283 newFunc(LFUN_LAYOUT_COPY,"layout-copy",
284 _("Copy paragraph environment type"), Noop);
285 newFunc(LFUN_LAYOUT_DOCUMENT,"layout-document",
287 newFunc(LFUN_LAYOUTNO,"layout-number",
288 "", Noop); // internal only
289 newFunc(LFUN_LAYOUT_PARAGRAPH,"layout-paragraph",
291 newFunc(LFUN_LAYOUT_PAPER, "layout-paper", "", ReadOnly);
292 newFunc(LFUN_LAYOUT_PASTE,"layout-paste",
293 _("Paste paragraph environment type"), Noop);
294 newFunc(LFUN_LAYOUT_PREAMBLE,"layout-preamble",
296 newFunc(LFUN_LAYOUT_QUOTES, "layout-quotes", "", ReadOnly);
297 newFunc(LFUN_LAYOUT_SAVE_DEFAULT, "layout-save-default",
299 newFunc(LFUN_LAYOUT_TABLE,"layout-table",
301 newFunc(LFUN_HOME,"line-begin",
302 _("Go to beginning of line"), ReadOnly);
303 newFunc(LFUN_HOMESEL,"line-begin-select",
304 _("Select to beginning of line"), ReadOnly);
305 newFunc(LFUN_DELETE_LINE_FORWARD,"line-delete-forward",
307 newFunc(LFUN_END,"line-end",
308 _("Go to end of line"), ReadOnly);
309 newFunc(LFUN_ENDSEL,"line-end-select",
310 _("Select to end of line"), ReadOnly);
311 newFunc(LFUN_LOA_INSERT,"loa-insert",
312 _("Insert list of algorithms"), Noop);
313 newFunc(LFUN_LOF_INSERT,"lof-insert",
314 _("Insert list of figures"), Noop);
315 newFunc(LFUN_LOT_INSERT,"lot-insert",
316 _("Insert list of tables"), Noop);
317 newFunc(LFUN_QUIT,"lyx-quit",
318 _("Exit"), NoBuffer);
319 newFunc(LFUN_MARGINMELT,"marginpar-insert",
320 _("Insert Margin note"), Noop);
321 newFunc(LFUN_MARK_OFF,"mark-off",
323 newFunc(LFUN_MARK_ON,"mark-on",
325 newFunc(LFUN_SETMARK,"mark-toggle",
327 newFunc(LFUN_MATH_DELIM,"math-delim",
329 newFunc(LFUN_MATH_DISPLAY,"math-display",
331 newFunc(LFUN_GREEK,"math-greek",
332 _("Math Greek"), Noop);
333 newFunc(LFUN_GREEK_TOGGLE,"math-greek-toggle",
335 newFunc(LFUN_INSERT_MATH,"math-insert",
336 _("Insert math symbol"), Noop);
337 newFunc(LFUN_MATH_LIMITS,"math-limits",
339 newFunc(LFUN_MATH_MACRO,"math-macro",
341 newFunc(LFUN_MATH_MACROARG,"math-macro-arg",
343 newFunc(LFUN_INSERT_MATRIX,"math-matrix",
345 newFunc(LFUN_MATH_MODE,"math-mode",
346 _("Math mode"), Noop);
347 newFunc(LFUN_MATH_NONUMBER,"math-nonumber",
349 newFunc(LFUN_MATH_NUMBER,"math-number",
351 newFunc(LFUN_MATH_SIZE,"math-size",
353 newFunc(LFUN_MELT,"melt",
355 newFunc(LFUN_MENU_OPEN_BY_NAME,"menu-open",
357 newFunc(LFUN_MENU_SEPARATOR, "menu-separator-insert", "", Noop);
358 newFunc(LFUN_META_FAKE,"meta-prefix",
360 newFunc(LFUN_INSERT_NOTE,"note-insert",
362 newFunc(LFUN_GOTONOTE,"note-next",
364 newFunc(LFUN_OPENSTUFF,"open-stuff",
366 newFunc(LFUN_DOWN_PARAGRAPH,"paragraph-down",
367 _("Go one paragraph down"), ReadOnly);
368 newFunc(LFUN_DOWN_PARAGRAPHSEL,"paragraph-down-select",
369 _("Select next paragraph"), ReadOnly);
370 newFunc(LFUN_UP_PARAGRAPH,"paragraph-up",
371 _("Go one paragraph up"), ReadOnly);
372 newFunc(LFUN_UP_PARAGRAPHSEL,"paragraph-up-select",
373 _("Select previous paragraph"), ReadOnly);
374 newFunc(LFUN_PARENTINSERT,"parent-insert",
376 newFunc(LFUN_PASTE,"paste",
378 newFunc(LFUN_SAVEPREFERENCES, "preferences-save",
379 "Save Preferences", NoBuffer);
380 newFunc(LFUN_PASTESELECTION,"primary-selection-paste",
382 newFunc(LFUN_PROTECTEDSPACE,"protected-space-insert",
383 _("Insert protected space"), Noop);
384 newFunc(LFUN_QUOTE,"quote-insert",
385 _("Insert quote"), Noop);
386 newFunc(LFUN_RECONFIGURE,"reconfigure",
387 _("Reconfigure"), NoBuffer);
388 newFunc(LFUN_REDO,"redo",
390 newFunc(LFUN_REFBACK,"reference-back",
392 newFunc(LFUN_REFGOTO,"reference-goto",
394 newFunc(LFUN_INSERT_REF,"reference-insert",
395 _("Insert cross reference"), Noop);
396 newFunc(LFUN_REFTOGGLE,"reference-toggle",
398 newFunc(LFUN_NEXT,"screen-down",
400 newFunc(LFUN_NEXTSEL,"screen-down-select",
402 newFunc(LFUN_CENTER,"screen-recenter",
404 newFunc(LFUN_PRIOR,"screen-up",
406 newFunc(LFUN_PRIORSEL,"screen-up-select",
408 newFunc(LFUN_SELFINSERT,"self-insert",
410 newFunc(LFUN_CHARATCURSOR,"server-char-after",
412 newFunc(LFUN_GETFONT,"server-get-font",
414 newFunc(LFUN_GETLATEX,"server-get-latex",
416 newFunc(LFUN_GETLAYOUT,"server-get-layout",
418 newFunc(LFUN_GETNAME,"server-get-name",
420 newFunc(LFUN_GETTIP,"server-get-tip",
422 newFunc(LFUN_GETXY,"server-get-xy",
424 newFunc(LFUN_GOTOFILEROW, "server-goto-file-row", "", Noop);
425 newFunc(LFUN_NOTIFY,"server-notify",
427 newFunc(LFUN_SETXY,"server-set-xy",
429 newFunc(LFUN_SPELLCHECK,"spellchecker",
431 newFunc(LFUN_INSERT_MATH,"symbol-insert",
433 newFunc(LFUN_TAB,"tab-forward",
435 newFunc(LFUN_TABINSERT,"tab-insert",
437 newFunc(LFUN_TABLE,"table-insert",
438 _("Insert Table"), Noop);
439 newFunc(LFUN_TEX,"tex-mode",
440 _("Toggle TeX style"), Noop);
441 newFunc(LFUN_TOC_INSERT,"toc-insert",
442 _("Insert table of contents"), Noop);
443 newFunc(LFUN_TOCVIEW,"toc-view",
444 _("View table of contents"), ReadOnly);
445 newFunc(LFUN_TOGGLECURSORFOLLOW,"toggle-cursor-follows-scrollbar",
446 _("Toggle cursor does/doesn't follow the scrollbar"),
448 newFunc(LFUN_ADD_TO_TOOLBAR,"toolbar-add-to",
450 newFunc(LFUN_PUSH_TOOLBAR,"toolbar-push",
452 newFunc(LFUN_UNDO,"undo",
454 newFunc(LFUN_UP,"up",
456 newFunc(LFUN_UPSEL,"up-select",
458 newFunc(LFUN_URL,"url-insert",
460 newFunc(LFUN_VC_CHECKIN,"vc-check-in",
462 newFunc(LFUN_VC_CHECKOUT,"vc-check-out",
464 newFunc(LFUN_VC_HISTORY,"vc-history",
466 newFunc(LFUN_VC_REGISTER,"vc-register",
467 _("Register document under version control"), ReadOnly);
468 newFunc(LFUN_VC_REVERT,"vc-revert",
470 newFunc(LFUN_VC_UNDO,"vc-undo-last",
472 newFunc(LFUN_WORDLEFT,"word-backward",
474 newFunc(LFUN_WORDLEFTSEL,"word-backward-select",
476 newFunc(LFUN_CAPITALIZE_WORD,"word-capitalize",
478 newFunc(LFUN_DELETE_WORD_BACKWARD,"word-delete-backward",
480 newFunc(LFUN_DELETE_WORD_FORWARD,"word-delete-forward",
482 newFunc(LFUN_WORDFINDBACKWARD,"word-find-backward",
484 newFunc(LFUN_WORDFINDFORWARD,"word-find-forward",
486 newFunc(LFUN_WORDRIGHT,"word-forward",
488 newFunc(LFUN_WORDRIGHTSEL,"word-forward-select",
490 newFunc(LFUN_LOWCASE_WORD,"word-lowcase",
492 newFunc(LFUN_UPCASE_WORD,"word-upcase",
499 LyXAction::LyXAction()
505 // Search for an existent pseudoaction, return LFUN_UNKNOWN_ACTION
506 // if it doesn't exist.
507 int LyXAction::searchActionArg(kb_action action, string const & arg) const
509 arg_map::const_iterator pit = lyx_arg_map.find(action);
511 if (pit == lyx_arg_map.end()) {
512 // the action does not have any pseudoactions
513 lyxerr[Debug::ACTION] << "Action " << action
514 << " does not have any pseudo actions.\n";
515 return LFUN_UNKNOWN_ACTION;
518 arg_item::const_iterator aci = (*pit).second.find(arg);
520 if (aci == (*pit).second.end()) {
521 // the action does not have any pseudoactions with this arg
522 lyxerr[Debug::ACTION]
523 << "Action " << action
524 << "does not have any pseudoactions with arg "
526 return LFUN_UNKNOWN_ACTION;
529 // pseudo action exist
530 lyxerr[Debug::ACTION] << "Pseudoaction exist["
532 << arg << "] = " << (*aci).second << '\n';
534 return (*aci).second;
538 // Returns a pseudo-action given an action and its argument.
539 int LyXAction::getPseudoAction(kb_action action, string const & arg) const
541 int psdaction = searchActionArg(action, arg);
543 if (isPseudoAction(psdaction)) return psdaction;
545 static unsigned int pseudo_counter = LFUN_LASTACTION;
547 // Create new pseudo action.
549 tmp_p.action = action;
551 lyx_pseudo_map[++pseudo_counter] = tmp_p;
553 // First ensure that the action is in lyx_arg_map;
555 // get the arg_item map
556 arg_map::iterator ami = lyx_arg_map.find(action);
557 // put the new pseudo function in it
558 (*ami).second[arg] = pseudo_counter;
560 lyxerr[Debug::ACTION] << "Creating new pseudoaction "
561 << pseudo_counter << " for [" << action
562 << '|' << arg << "]\n";
564 return pseudo_counter;
568 // Retrieves the real action and its argument.
569 // perhaps a pair<kb_action, string> should be returned?
570 kb_action LyXAction::retrieveActionArg(int pseudo, string & arg) const
572 pseudo_map::const_iterator pit = lyx_pseudo_map.find(pseudo);
574 if (pit != lyx_pseudo_map.end()) {
575 lyxerr[Debug::ACTION] << "Found the pseudoaction: ["
576 << (*pit).second.action << '|'
577 << (*pit).second.arg << '\n';
578 arg = (*pit).second.arg;
579 return (*pit).second.action;
581 lyxerr << "Lyx Error: Unrecognized pseudo-action\n";
582 return LFUN_UNKNOWN_ACTION;
588 // Returns an action tag from a string.
589 int LyXAction::LookupFunc(string const & func) const
591 if (func.empty()) return LFUN_NOACTION;
593 // split action and arg
595 string argstr = split(func, actstr, ' ');
596 lyxerr[Debug::ACTION] << "Action: " << actstr << '\n';
597 lyxerr[Debug::ACTION] << "Arg : " << argstr << '\n';
599 func_map::const_iterator fit = lyx_func_map.find(actstr);
601 if (!argstr.empty() && fit != lyx_func_map.end()) {
602 // might be pseudo (or create one)
603 return getPseudoAction((*fit).second, argstr);
606 return fit != lyx_func_map.end() ? (*fit).second : LFUN_UNKNOWN_ACTION;
611 #warning Not working as it should.
613 int LyXAction::getApproxFunc(string const & func) const
614 // This func should perhaps also be able to return a list of all
615 // actions that has func as a prefix. That should actually be quite
616 // easy, just let it return a vector<int> or something.
618 int action = LookupFunc(func);
619 if (action == LFUN_UNKNOWN_ACTION) {
620 // func is not an action, but perhaps it is
621 // part of one...check if it is prefix if one of the
623 // Checking for prefix is not so simple, but
624 // using a simple bounding function gives
625 // a similar result. [ale 19981103]
626 func_map::const_iterator fit =
627 lyx_func_map.lower_bound(func);
629 if (fit != lyx_func_map.end()) {
630 action = (*fit).second;
632 } else { // Go get the next function
633 func_map::const_iterator fit =
634 lyx_func_map.upper_bound(func);
636 if (fit != lyx_func_map.end()) {
637 action = (*fit).second;
645 string LyXAction::getApproxFuncName(string const & func) const
647 int f = getApproxFunc(func);
648 // This will return empty string if f isn't an action.
649 return getActionName(f);
653 string LyXAction::getActionName(int action) const
655 info_map::const_iterator iit = lyx_info_map.find((kb_action)action);
657 return iit != lyx_info_map.end() ? (*iit).second.name : string();
661 // Returns one line help associated with a (pseudo)action, i.e. appends
662 // the argument of the action if necessary
663 string LyXAction::helpText(int pseudoaction) const
668 if (isPseudoAction(pseudoaction))
669 action = retrieveActionArg(pseudoaction, arg);
671 action = (kb_action) pseudoaction;
673 info_map::const_iterator ici = lyx_info_map.find(action);
674 if (ici != lyx_info_map.end()) {
675 if (lyxerr.debugging(Debug::ACTION)) {
676 lyxerr << "Action: " << action << '\n';
678 << (*ici).second.name << '\n';
679 lyxerr << " attrib: "
680 << (*ici).second.attrib << '\n';
682 << (*ici).second.helpText << '\n';
684 help = (*ici).second.helpText;
685 // if the is no help text use the name of the func instead.
686 if (help.empty()) help = (*ici).second.name;
690 help = _("No description available!");
691 } else if (!arg.empty()) {
700 bool LyXAction::funcHasFlag(kb_action action,
701 LyXAction::func_attrib flag) const
703 info_map::const_iterator ici = lyx_info_map.find(action);
705 if (ici != lyx_info_map.end()) {
706 return (*ici).second.attrib & flag;
708 // it really should exist, but...
709 lyxerr << "No info about kb_action: " << action << '\n';
716 ostream & operator<<(ostream & o, kb_action action)
718 return o << int(action);