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_INSERTFLOAT,"float-insert",
143 newFunc(LFUN_INSERTFOOTNOTE, "buffer-float-insert", "", Noop);
144 newFunc(LFUN_IMPORT,"buffer-import",
145 _("Import document"), NoBuffer);
146 newFunc(LFUN_BUFFERBULLETSSELECT, "buffer-itemize-bullets-select",
148 newFunc( LFUN_MENUNEW,"buffer-new",
149 _("New document") , NoBuffer);
150 newFunc(LFUN_MENUNEWTMPLT,"buffer-new-template",
151 _("New document from template"), NoBuffer);
152 newFunc(LFUN_MENUOPEN,"buffer-open",
153 _("Open"), NoBuffer);
154 newFunc(LFUN_PREVBUFFER,"buffer-previous",
155 _("Switch to previous document"), ReadOnly);
156 //newFunc(LFUN_SWITCHBUFFER,"buffer-switch",
157 // _("Switch to an open document"), ReadOnly);
158 newFunc(LFUN_MENUPRINT,"buffer-print",
159 _("Print"), ReadOnly);
160 newFunc(LFUN_MENURELOAD,"buffer-reload",
161 _("Revert to saved"), ReadOnly);
162 newFunc(LFUN_READ_ONLY_TOGGLE,"buffer-toggle-read-only",
163 _("Toggle read-only"), ReadOnly);
164 newFunc(LFUN_RUNLATEX,"buffer-typeset",
165 _("Update DVI"), ReadOnly);
166 newFunc(LFUN_RUNDVIPS,"buffer-typeset-ps",
167 _("Update PostScript"), ReadOnly);
168 newFunc(LFUN_PREVIEW,"buffer-view",
169 _("View DVI") , ReadOnly);
170 newFunc(LFUN_PREVIEWPS,"buffer-view-ps",
171 _("View PostScript") , ReadOnly);
172 newFunc(LFUN_MENUWRITE,"buffer-write",
173 _("Save"), ReadOnly);
174 newFunc(LFUN_MENUWRITEAS,"buffer-write-as",
175 _("Save As"), ReadOnly);
176 newFunc(LFUN_CANCEL,"cancel",
177 _("Cancel"), NoBuffer);
178 newFunc(LFUN_LEFT,"char-backward",
179 _("Go one char back"), ReadOnly);
180 newFunc(LFUN_RIGHT,"char-forward",
181 _("Go one char forward"), ReadOnly);
182 newFunc(LFUN_INSERT_CITATION,"citation-insert",
183 _("Insert citation"), Noop);
184 newFunc(LFUN_EXEC_COMMAND,"command-execute",
186 newFunc(LFUN_PREFIX,"command-prefix",
187 _("Execute command"), NoBuffer);
188 newFunc(LFUN_SEQUENCE, "command-sequence", "", Noop);
189 newFunc(LFUN_COPY,"copy",
190 _("Copy"), ReadOnly);
191 newFunc(LFUN_CUT,"cut",
193 newFunc(LFUN_BACKSPACE,"delete-backward",
195 newFunc(LFUN_BACKSPACE_SKIP,"delete-backward-skip",
197 newFunc(LFUN_DELETE,"delete-forward",
199 newFunc(LFUN_DELETE_SKIP,"delete-forward-skip",
201 newFunc(LFUN_DEPTH_MIN,"depth-decrement",
202 _("Decrement environment depth"), Noop);
203 newFunc(LFUN_DEPTH_PLUS,"depth-increment",
204 _("Increment environment depth"), Noop);
205 newFunc(LFUN_DEPTH,"depth-next",
206 _("Change environment depth"), Noop);
207 newFunc(LFUN_LDOTS,"dots-insert",
208 _("Insert ... dots"), Noop);
209 newFunc(LFUN_DOWN,"down",
210 _("Go down"), ReadOnly);
211 newFunc(LFUN_DOWNSEL,"down-select",
212 _("Select next line"), ReadOnly);
213 newFunc(LFUN_DROP_LAYOUTS_CHOICE,"drop-layouts-choice",
214 _("Choose Paragraph Environment"), ReadOnly);
215 newFunc(LFUN_END_OF_SENTENCE,"end-of-sentence-period-insert",
216 _("Insert end of sentence period"), Noop);
217 newFunc(LFUN_GOTOERROR,"error-next",
218 _("Go to next error"), Noop);
219 newFunc(LFUN_REMOVEERRORS,"error-remove-all",
220 _("Remove all error boxes"), ReadOnly);
221 newFunc(LFUN_FIGURE,"figure-insert",
222 _("Insert Figure"), Noop);
223 newFunc(LFUN_FILE_INSERT,"file-insert",
225 newFunc(LFUN_FILE_INSERT_ASCII,"file-insert-ascii",
227 newFunc(LFUN_FILE_NEW,"file-new",
229 newFunc(LFUN_FILE_OPEN,"file-open",
231 newFunc( LFUN_MENUSEARCH,"find-replace",
232 _("Find & Replace") , Noop);
233 newFunc(LFUN_BOLD,"font-bold",
234 _("Toggle bold"), Noop);
235 newFunc(LFUN_CODE,"font-code",
236 _("Toggle code style"), Noop);
237 newFunc(LFUN_DEFAULT,"font-default",
238 _("Default font style"), Noop);
239 newFunc(LFUN_EMPH,"font-emph",
240 _("Toggle emphasize"), Noop);
241 newFunc(LFUN_FREE,"font-free",
242 _("Toggle user defined style"), Noop);
243 newFunc(LFUN_NOUN,"font-noun",
244 _("Toggle noun style"), Noop);
245 newFunc(LFUN_ROMAN,"font-roman",
246 _("Toggle roman font style"), Noop);
247 newFunc(LFUN_SANS,"font-sans",
248 _("Toggle sans font style"), Noop);
249 newFunc(LFUN_FONT_SIZE,"font-size",
250 _("Set font size"), Noop);
251 newFunc(LFUN_FONT_STATE,"font-state",
252 _("Show font state"), ReadOnly);
253 newFunc(LFUN_UNDERLINE,"font-underline",
254 _("Toggle font underline"), Noop);
255 newFunc(LFUN_FOOTMELT,"footnote-insert",
256 _("Insert Footnote"), Noop);
257 newFunc(LFUN_RIGHTSEL,"forward-select",
258 _("Select next char"), ReadOnly);
259 newFunc(LFUN_HFILL,"hfill-insert",
260 _("Insert horizontal fill"), Noop);
261 newFunc(LFUN_HTMLURL,"html-insert",
263 newFunc(LFUN_HYPHENATION,"hyphenation-point-insert",
264 _("Insert hyphenation point"), Noop);
265 newFunc(LFUN_INDEX_INSERT,"index-insert",
266 _("Insert index item"), Noop);
267 newFunc(LFUN_INDEX_INSERT_LAST, "index-insert-last",
268 _("Insert last index item"), Noop);
269 newFunc(LFUN_INDEX_PRINT,"index-print",
270 _("Insert index list"), Noop);
271 newFunc(LFUN_KMAP_OFF,"keymap-off",
272 _("Turn off keymap"), ReadOnly);
273 newFunc(LFUN_KMAP_PRIM,"keymap-primary",
274 _("Use primary keymap"), ReadOnly);
275 newFunc(LFUN_KMAP_SEC,"keymap-secondary",
276 _("Use secondary keymap"), ReadOnly);
277 newFunc(LFUN_KMAP_TOGGLE,"keymap-toggle",
278 _("Toggle keymap"), ReadOnly);
279 newFunc(LFUN_INSERT_LABEL,"label-insert",
280 _("Insert Label"), Noop);
281 newFunc(LFUN_LATEX_LOG,"latex-view-log",
282 _("View LaTeX log"), ReadOnly);
283 newFunc(LFUN_LAYOUT,"layout",
285 newFunc(LFUN_LAYOUT_CHARACTER,"layout-character",
287 newFunc(LFUN_LAYOUT_COPY,"layout-copy",
288 _("Copy paragraph environment type"), Noop);
289 newFunc(LFUN_LAYOUT_DOCUMENT,"layout-document",
291 newFunc(LFUN_LAYOUTNO,"layout-number",
292 "", Noop); // internal only
293 newFunc(LFUN_LAYOUT_PARAGRAPH,"layout-paragraph",
295 newFunc(LFUN_LAYOUT_PAPER, "layout-paper", "", ReadOnly);
296 newFunc(LFUN_LAYOUT_PASTE,"layout-paste",
297 _("Paste paragraph environment type"), Noop);
298 newFunc(LFUN_LAYOUT_PREAMBLE,"layout-preamble",
300 newFunc(LFUN_LAYOUT_QUOTES, "layout-quotes", "", ReadOnly);
301 newFunc(LFUN_LAYOUT_SAVE_DEFAULT, "layout-save-default",
303 newFunc(LFUN_LAYOUT_TABLE,"layout-table",
305 newFunc(LFUN_HOME,"line-begin",
306 _("Go to beginning of line"), ReadOnly);
307 newFunc(LFUN_HOMESEL,"line-begin-select",
308 _("Select to beginning of line"), ReadOnly);
309 newFunc(LFUN_DELETE_LINE_FORWARD,"line-delete-forward",
311 newFunc(LFUN_END,"line-end",
312 _("Go to end of line"), ReadOnly);
313 newFunc(LFUN_ENDSEL,"line-end-select",
314 _("Select to end of line"), ReadOnly);
315 newFunc(LFUN_LOA_INSERT,"loa-insert",
316 _("Insert list of algorithms"), Noop);
317 newFunc(LFUN_LOF_INSERT,"lof-insert",
318 _("Insert list of figures"), Noop);
319 newFunc(LFUN_LOT_INSERT,"lot-insert",
320 _("Insert list of tables"), Noop);
321 newFunc(LFUN_QUIT,"lyx-quit",
322 _("Exit"), NoBuffer);
323 newFunc(LFUN_MARGINMELT,"marginpar-insert",
324 _("Insert Margin note"), Noop);
325 newFunc(LFUN_MARK_OFF,"mark-off",
327 newFunc(LFUN_MARK_ON,"mark-on",
329 newFunc(LFUN_SETMARK,"mark-toggle",
331 newFunc(LFUN_MATH_DELIM,"math-delim",
333 newFunc(LFUN_MATH_DISPLAY,"math-display",
335 newFunc(LFUN_GREEK,"math-greek",
336 _("Math Greek"), Noop);
337 newFunc(LFUN_GREEK_TOGGLE,"math-greek-toggle",
339 newFunc(LFUN_INSERT_MATH,"math-insert",
340 _("Insert math symbol"), Noop);
341 newFunc(LFUN_MATH_LIMITS,"math-limits",
343 newFunc(LFUN_MATH_MACRO,"math-macro",
345 newFunc(LFUN_MATH_MACROARG,"math-macro-arg",
347 newFunc(LFUN_INSERT_MATRIX,"math-matrix",
349 newFunc(LFUN_MATH_MODE,"math-mode",
350 _("Math mode"), Noop);
351 //newFunc(LFUN_MATH_PANEL,"math-panel",
352 // _("Math panel"), Noop);
353 newFunc(LFUN_MATH_NONUMBER,"math-nonumber",
355 newFunc(LFUN_MATH_NUMBER,"math-number",
357 newFunc(LFUN_MATH_SIZE,"math-size",
359 newFunc(LFUN_MELT,"melt",
361 newFunc(LFUN_MENU_OPEN_BY_NAME,"menu-open",
363 newFunc(LFUN_MENU_SEPARATOR, "menu-separator-insert", "", Noop);
364 newFunc(LFUN_META_FAKE,"meta-prefix",
366 newFunc(LFUN_INSERT_NOTE,"note-insert",
368 newFunc(LFUN_GOTONOTE,"note-next",
370 newFunc(LFUN_OPENSTUFF,"open-stuff",
372 newFunc(LFUN_DOWN_PARAGRAPH,"paragraph-down",
373 _("Go one paragraph down"), ReadOnly);
374 newFunc(LFUN_DOWN_PARAGRAPHSEL,"paragraph-down-select",
375 _("Select next paragraph"), ReadOnly);
376 newFunc(LFUN_UP_PARAGRAPH,"paragraph-up",
377 _("Go one paragraph up"), ReadOnly);
378 newFunc(LFUN_UP_PARAGRAPHSEL,"paragraph-up-select",
379 _("Select previous paragraph"), ReadOnly);
380 newFunc(LFUN_PARENTINSERT,"parent-insert",
382 newFunc( LFUN_PASTE,"paste",
384 newFunc(LFUN_PASTESELECTION,"primary-selection-paste",
386 newFunc(LFUN_PROTECTEDSPACE,"protected-space-insert",
387 _("Insert protected space"), Noop);
388 newFunc(LFUN_QUOTE,"quote-insert",
389 _("Insert quote"), Noop);
390 newFunc(LFUN_RECONFIGURE,"reconfigure",
391 _("Reconfigure"), NoBuffer);
392 newFunc(LFUN_REDO,"redo",
394 newFunc(LFUN_REFBACK,"reference-back",
396 newFunc(LFUN_REFGOTO,"reference-goto",
398 newFunc(LFUN_INSERT_REF,"reference-insert",
399 _("Insert cross reference"), Noop);
400 newFunc(LFUN_REFTOGGLE,"reference-toggle",
402 newFunc(LFUN_NEXT,"screen-down",
404 newFunc(LFUN_NEXTSEL,"screen-down-select",
406 newFunc(LFUN_CENTER,"screen-recenter",
408 newFunc(LFUN_PRIOR,"screen-up",
410 newFunc(LFUN_PRIORSEL,"screen-up-select",
412 newFunc(LFUN_SELFINSERT,"self-insert",
414 newFunc(LFUN_CHARATCURSOR,"server-char-after",
416 newFunc(LFUN_GETFONT,"server-get-font",
418 newFunc(LFUN_GETLATEX,"server-get-latex",
420 newFunc(LFUN_GETLAYOUT,"server-get-layout",
422 newFunc(LFUN_GETNAME,"server-get-name",
424 newFunc(LFUN_GETTIP,"server-get-tip",
426 newFunc(LFUN_GETXY,"server-get-xy",
428 newFunc(LFUN_GOTOFILEROW, "server-goto-file-row", "", Noop);
429 newFunc(LFUN_NOTIFY,"server-notify",
431 newFunc(LFUN_SETXY,"server-set-xy",
433 newFunc(LFUN_SPELLCHECK,"spellchecker",
435 newFunc(LFUN_INSERT_MATH,"symbol-insert",
437 newFunc(LFUN_TAB,"tab-forward",
439 newFunc(LFUN_TABINSERT,"tab-insert",
441 newFunc(LFUN_TABLE,"table-insert",
442 _("Insert Table"), Noop);
443 newFunc(LFUN_TEX,"tex-mode",
444 _("Toggle TeX style"), Noop);
445 newFunc(LFUN_TOC_INSERT,"toc-insert",
446 _("Insert table of contents"), Noop);
447 newFunc(LFUN_TOCVIEW,"toc-view",
448 _("View table of contents"), ReadOnly);
449 newFunc(LFUN_TOGGLECURSORFOLLOW,"toggle-cursor-follows-scrollbar",
450 _("Toggle cursor does/doesn't follow the scrollbar"),
452 newFunc(LFUN_ADD_TO_TOOLBAR,"toolbar-add-to",
454 newFunc(LFUN_PUSH_TOOLBAR,"toolbar-push",
456 newFunc(LFUN_UNDO,"undo",
458 newFunc(LFUN_UP,"up",
460 newFunc(LFUN_UPSEL,"up-select",
462 newFunc(LFUN_URL,"url-insert",
464 newFunc(LFUN_VC_CHECKIN,"vc-check-in",
466 newFunc(LFUN_VC_CHECKOUT,"vc-check-out",
468 newFunc(LFUN_VC_HISTORY,"vc-history",
470 newFunc(LFUN_VC_REGISTER,"vc-register",
471 _("Register document under version control"), ReadOnly);
472 newFunc(LFUN_VC_REVERT,"vc-revert",
474 newFunc(LFUN_VC_UNDO,"vc-undo-last",
476 newFunc(LFUN_WORDLEFT,"word-backward",
478 newFunc(LFUN_WORDLEFTSEL,"word-backward-select",
480 newFunc(LFUN_CAPITALIZE_WORD,"word-capitalize",
482 newFunc(LFUN_DELETE_WORD_BACKWARD,"word-delete-backward",
484 newFunc(LFUN_DELETE_WORD_FORWARD,"word-delete-forward",
486 newFunc(LFUN_WORDFINDBACKWARD,"word-find-backward",
488 newFunc(LFUN_WORDFINDFORWARD,"word-find-forward",
490 newFunc(LFUN_WORDRIGHT,"word-forward",
492 newFunc(LFUN_WORDRIGHTSEL,"word-forward-select",
494 newFunc(LFUN_LOWCASE_WORD,"word-lowcase",
496 newFunc(LFUN_UPCASE_WORD,"word-upcase",
503 LyXAction::LyXAction()
509 // Search for an existent pseudoaction, return LFUN_UNKNOWN_ACTION
510 // if it doesn't exist.
511 int LyXAction::searchActionArg(kb_action action, string const & arg) const
513 arg_map::const_iterator pit = lyx_arg_map.find(action);
515 if (pit == lyx_arg_map.end()) {
516 // the action does not have any pseudoactions
517 lyxerr[Debug::ACTION] << "Action " << action
518 << " does not have any pseudo actions.\n";
519 return LFUN_UNKNOWN_ACTION;
522 arg_item::const_iterator aci = (*pit).second.find(arg);
524 if (aci == (*pit).second.end()) {
525 // the action does not have any pseudoactions with this arg
526 lyxerr[Debug::ACTION]
527 << "Action " << action
528 << "does not have any pseudoactions with arg "
530 return LFUN_UNKNOWN_ACTION;
533 // pseudo action exist
534 lyxerr[Debug::ACTION] << "Pseudoaction exist["
536 << arg << "] = " << (*aci).second << '\n';
538 return (*aci).second;
542 // Returns a pseudo-action given an action and its argument.
543 int LyXAction::getPseudoAction(kb_action action, string const & arg) const
545 int psdaction = searchActionArg(action, arg);
547 if (isPseudoAction(psdaction)) return psdaction;
549 static unsigned int pseudo_counter = LFUN_LASTACTION;
551 // Create new pseudo action.
553 tmp_p.action = action;
555 lyx_pseudo_map[++pseudo_counter] = tmp_p;
557 // First ensure that the action is in lyx_arg_map;
559 // get the arg_item map
560 arg_map::iterator ami = lyx_arg_map.find(action);
561 // put the new pseudo function in it
562 (*ami).second[arg] = pseudo_counter;
564 lyxerr[Debug::ACTION] << "Creating new pseudoaction "
565 << pseudo_counter << " for [" << action
566 << '|' << arg << "]\n";
568 return pseudo_counter;
572 // Retrieves the real action and its argument.
573 // perhaps a pair<kb_action, string> should be returned?
574 kb_action LyXAction::retrieveActionArg(int pseudo, string & arg) const
576 pseudo_map::const_iterator pit = lyx_pseudo_map.find(pseudo);
578 if (pit != lyx_pseudo_map.end()) {
579 lyxerr[Debug::ACTION] << "Found the pseudoaction: ["
580 << (*pit).second.action << '|'
581 << (*pit).second.arg << '\n';
582 arg = (*pit).second.arg;
583 return (*pit).second.action;
585 lyxerr << "Lyx Error: Unrecognized pseudo-action\n";
586 return LFUN_UNKNOWN_ACTION;
592 // Returns an action tag from a string.
593 int LyXAction::LookupFunc(string const & func) const
595 if (func.empty()) return LFUN_NOACTION;
597 // split action and arg
599 string argstr = split(func, actstr, ' ');
600 lyxerr[Debug::ACTION] << "Action: " << actstr << '\n';
601 lyxerr[Debug::ACTION] << "Arg : " << argstr << '\n';
603 func_map::const_iterator fit = lyx_func_map.find(actstr);
605 if (!argstr.empty() && fit != lyx_func_map.end()) {
606 // might be pseudo (or create one)
607 return getPseudoAction((*fit).second, argstr);
610 return fit != lyx_func_map.end() ? (*fit).second : LFUN_UNKNOWN_ACTION;
614 #warning Not working as it should.
615 int LyXAction::getApproxFunc(string const & func) const
616 // This func should perhaps also be able to return a list of all
617 // actions that has func as a prefix. That should actually be quite
618 // easy, just let it return a vector<int> or something.
620 int action = LookupFunc(func);
621 if (action == LFUN_UNKNOWN_ACTION) {
622 // func is not an action, but perhaps it is
623 // part of one...check if it is prefix if one of the
625 // Checking for prefix is not so simple, but
626 // using a simple bounding function gives
627 // a similar result. [ale 19981103]
628 func_map::const_iterator fit =
629 lyx_func_map.lower_bound(func);
631 if (fit != lyx_func_map.end()) {
632 action = (*fit).second;
634 } else { // Go get the next function
635 func_map::const_iterator fit =
636 lyx_func_map.upper_bound(func);
638 if (fit != lyx_func_map.end()) {
639 action = (*fit).second;
647 string LyXAction::getApproxFuncName(string const & func) const
649 int f = getApproxFunc(func);
650 // This will return empty string if f isn't an action.
651 return getActionName(f);
655 string LyXAction::getActionName(int action) const
657 info_map::const_iterator iit = lyx_info_map.find((kb_action)action);
659 return iit != lyx_info_map.end() ? (*iit).second.name : string();
663 // Returns one line help associated with a (pseudo)action, i.e. appends
664 // the argument of the action if necessary
665 string LyXAction::helpText(int pseudoaction) const
670 if (isPseudoAction(pseudoaction))
671 action = retrieveActionArg(pseudoaction, arg);
673 action = (kb_action) pseudoaction;
675 info_map::const_iterator ici = lyx_info_map.find(action);
676 if (ici != lyx_info_map.end()) {
677 if (lyxerr.debugging(Debug::ACTION)) {
678 lyxerr << "Action: " << action << '\n';
680 << (*ici).second.name << '\n';
681 lyxerr << " attrib: "
682 << (*ici).second.attrib << '\n';
684 << (*ici).second.helpText << '\n';
686 help = (*ici).second.helpText;
687 // if the is no help text use the name of the func instead.
688 if (help.empty()) help = (*ici).second.name;
692 help = _("No description available!");
693 } else if (!arg.empty()) {
702 bool LyXAction::funcHasFlag(kb_action action,
703 LyXAction::func_attrib flag) const
705 info_map::const_iterator ici = lyx_info_map.find(action);
707 if (ici != lyx_info_map.end()) {
708 return (*ici).second.attrib & flag;
710 // it really should exist, but...
711 lyxerr << "No info about kb_action: " << action << '\n';
718 ostream & operator<<(ostream & o, kb_action action)
720 return o << int(action);