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 * ======================================================*/
18 #pragma implementation
21 #include "definitions.h"
22 #include "lyxlookup.h"
25 #include "bufferlist.h"
26 #include "lyxserver.h"
31 #include "insets/insetlatex.h"
32 #include "insets/inseturl.h"
33 #include "insets/insetlatexaccent.h"
34 #include "insets/insettoc.h"
35 #include "insets/insetlof.h"
36 #include "insets/insetloa.h"
37 #include "insets/insetlot.h"
38 #include "insets/insetref.h"
39 #include "insets/insetparent.h"
40 #include "mathed/formulamacro.h"
42 #include "spellchecker.h" // RVDK_PATCH_5
43 #include "minibuffer.h"
45 #include "insets/insetbib.h"
47 #include "insets/insetindex.h"
48 #include "insets/insetinclude.h"
50 #include "lyx_gui_misc.h"
51 #include "support/filetools.h"
52 #include "support/FileInfo.h"
53 #include "support/LAssert.h"
54 #include "lyxscreen.h"
59 #include "trans_mgr.h"
60 #include "ImportLaTeX.h"
61 #include "ImportNoweb.h"
62 #include "support/syscall.h"
63 #include "support/lstrings.h"
64 #include "support/path.h"
67 extern bool cursor_follows_scrollbar;
69 extern void InsertAsciiFile(string const &, bool);
70 extern void math_insert_symbol(char const*);
71 extern Bool math_insert_greek(char const); // why "Bool"?
72 extern BufferList bufferlist;
73 extern LyXServer * lyxserver;
74 extern short greek_kb_flag;
75 extern FD_form_toc * fd_form_toc;
76 extern bool selection_possible;
78 extern kb_keymap * toplevel_keymap;
80 extern void BeforeChange();
81 extern void MenuWrite(Buffer*);
82 extern void MenuWriteAs(Buffer*);
83 extern int MenuRunLaTeX(Buffer*);
84 extern int MenuBuildProg(Buffer*);
85 extern int MenuRunChktex(Buffer*);
86 extern bool MenuRunDvips(Buffer *,bool);
87 extern void MenuPrint(Buffer*);
88 extern void MenuSendto();
89 extern void QuitLyX();
90 extern void MenuFax(Buffer *);
91 extern void MenuMakeLaTeX(Buffer *);
92 extern void MenuMakeLinuxDoc(Buffer *);
93 extern void MenuMakeDocBook(Buffer *);
94 extern void MenuMakeAscii(Buffer *);
95 extern void MenuPasteSelection(char at);
96 extern LyXAction lyxaction;
98 extern tex_accent_struct get_accent(kb_action action);
100 extern void AutoSave();
101 extern void MenuSearch();
102 extern void CopyCB();
103 extern void CopyEnvironmentCB();
104 extern void PasteEnvironmentCB();
105 extern void GotoNote();
106 extern void NoteCB();
107 extern void OpenStuff();
108 extern void HyphenationPoint();
110 extern void EndOfSentenceDot();
111 extern void MenuSeparator();
113 extern void MenuUndo();
114 extern void MenuRedo();
115 extern void SmallUpdate(signed char);
116 extern void SetUpdateTimer(float timer= 0.3);
117 extern void FreeUpdateTimer();
118 extern bool MenuPreview(Buffer*);
119 extern bool MenuPreviewPS(Buffer*);
120 extern void MenuInsertLabel(const char *);
121 extern void MenuInsertRef();
122 extern void MenuLayoutCharacter();
123 extern void MenuLayoutParagraph();
124 extern void MenuLayoutDocument();
125 extern void MenuLayoutPaper();
126 extern void MenuLayoutTable(int flag);
127 extern void MenuLayoutQuotes();
128 extern void MenuLayoutPreamble();
129 extern void MenuLayoutSave();
130 extern void bulletForm();
132 extern Buffer * NewLyxFile(string const &);
133 extern void LoadLyXFile(string const &);
134 extern void Reconfigure();
136 extern int current_layout;
137 extern int getISOCodeFromLaTeX(char *);
139 extern int UnlockInset(UpdatableInset*);
141 extern void ShowLatexLog();
143 extern void UpdateInset(Inset* inset, bool mark_dirty = true);
145 /* === globals =========================================================== */
147 bool LyXFunc::show_sc = true;
150 LyXFunc::LyXFunc(LyXView *o)
154 lyx_dead_action = LFUN_NOACTION;
155 lyx_calling_dead_action = LFUN_NOACTION;
165 // I changed this func slightly. I commented out the ...FinishUndo(),
166 // this means that all places that used to have a moveCursorUpdate, now
167 // have a ...FinishUndo() as the preceeding statement. I have also added
168 // a moveCursorUpdate to some of the functions that updated the cursor, but
169 // that did not show its new position.
171 void LyXFunc::moveCursorUpdate(bool selecting)
173 if (selecting || owner->currentBuffer()->text->mark_set) {
174 owner->currentBuffer()->text->SetSelection();
175 owner->currentView()->getScreen()->ToggleToggle();
176 owner->currentBuffer()->update(0);
178 owner->currentBuffer()->update(-2); // this IS necessary
181 owner->currentView()->getScreen()->ShowCursor();
183 /* ---> Everytime the cursor is moved, show the current font state. */
184 // should this too me moved out of this func?
185 //owner->getMiniBuffer()->Set(CurrentState());
189 int LyXFunc::processKeyEvent(XEvent *ev)
196 XKeyEvent *keyevent = &ev->xkey;
197 KeySym keysym_return;
199 num_bytes = LyXLookupString(ev, s_r, 10, &keysym_return);
201 if (lyxerr.debugging(Debug::KEY)) {
202 lyxerr << "KeySym is "
203 << XKeysymToString(keysym_return)
205 << keysym_return << "]"
206 << " and num_bytes is "
208 << " the string returned is \""
209 << s_r << '\"' << endl;
211 // Do nothing if we have nothing (JMarc)
212 if (num_bytes == 0 && keysym_return == NoSymbol) {
213 lyxerr[Debug::KEY] << "Empty kbd action (probably composing)"
218 // this function should be used always [asierra060396]
219 if (owner->currentView()->available() &&
220 owner->currentBuffer()->the_locking_inset &&
221 keysym_return == XK_Escape) {
222 UnlockInset(owner->currentBuffer()->the_locking_inset);
223 owner->currentBuffer()->text->CursorRight();
227 // Can we be sure that this will work for all X-Windows
228 // implementations? (Lgb)
229 // This code snippet makes lyx ignore some keys. Perhaps
230 // all of them should be explictly mentioned?
231 if((keysym_return >= XK_Shift_L && keysym_return <= XK_Hyper_R)
232 || keysym_return == XK_Mode_switch || keysym_return == 0x0)
235 // Do a one-deep top-level lookup for
236 // cancel and meta-fake keys. RVDK_PATCH_5
237 cancel_meta_seq.reset();
239 action = cancel_meta_seq.addkey(keysym_return, keyevent->state
240 &(ShiftMask|ControlMask
243 // When not cancel or meta-fake, do the normal lookup.
244 // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
245 // Mostly, meta_fake_bit = 0. RVDK_PATCH_5.
246 if ( (action != LFUN_CANCEL) && (action != LFUN_META_FAKE) ) {
248 // remove Caps Lock and Mod2 as a modifiers
249 action = keyseq.addkey(keysym_return,
250 (keyevent->state | meta_fake_bit)
251 &(ShiftMask|ControlMask
254 // Dont remove this unless you know what you are doing.
257 if (action == 0) action = LFUN_PREFIX;
259 if (lyxerr.debugging(Debug::KEY)) {
261 keyseq.print(buf,100);
265 << num_bytes << "]" << endl;
268 // already here we know if it any point in going further
269 // why not return already here if action == -1 and
270 // num_bytes == 0? (Lgb)
272 if(keyseq.length>1 || keyseq.length<-1){
274 keyseq.print(buf,100);
275 owner->getMiniBuffer()->Set(buf);
279 if (keyseq.length<-1) { // unknown key sequence...
282 keyseq.print(buf,100);
283 owner->getMiniBuffer()->Set(_("Unknown sequence:"),buf);
287 char isochar = keyseq.getiso();
288 if (!(keyevent->state&ControlMask) &&
289 !(keyevent->state&Mod1Mask) &&
290 (isochar && keysym_return < 0xF000)) {
293 if (argument.empty()) {
294 lyxerr.debug() << "Empty argument!" << endl;
295 // This can`t possibly be of any use
296 // so we`ll skip the dispatch.
300 if (action==LFUN_SELFINSERT) {
304 bool tmp_sc = show_sc;
306 Dispatch(action, argument.c_str());
313 string LyXFunc::Dispatch(string const &cmd, string const &arg)
315 return Dispatch(lyxaction.LookupFunc(cmd.c_str()),
320 string LyXFunc::Dispatch(int ac,
321 char const *do_not_use_this_arg)
327 FL_OBJECT *ob = 0; // This will disapear soon
329 // we have not done anything wrong yet.
331 dispatch_buffer = string();
333 // if action is a pseudo-action, we need the real action
334 if (lyxaction.isPseudoAction(ac)) {
335 char const *tmparg = 0;
336 action = (kb_action)lyxaction.retrieveActionArg(ac, &tmparg);
340 action = (kb_action)ac;
341 if (do_not_use_this_arg)
342 argument = do_not_use_this_arg; // except here
345 selection_possible = false;
347 if (owner->currentView()->available()
348 && owner->currentView()->getScreen())
349 owner->currentView()->getScreen()->HideCursor();
351 if(!owner->currentView()->available()) {
352 // This lists the allowed funcs when we have no
355 case LFUN_MENU_OPEN_BY_NAME:
358 case LFUN_MENUNEWTMPLT:
361 case LFUN_PUSH_TOOLBAR:
362 case LFUN_ADD_TO_TOOLBAR:
363 case LFUN_EXEC_COMMAND:
364 case LFUN_DROP_LAYOUTS_CHOICE:
368 case LFUN_RECONFIGURE:
374 case LFUN_UNKNOWN_ACTION:
375 setErrorMessage(N_("Unknown action"));
376 goto exit_with_message;
378 setErrorMessage(N_("Command not allowed with"
379 "out any document open"));
380 goto exit_with_message; // action not allowed
384 commandshortcut = string();
386 if (lyxrc->display_shortcuts && show_sc) {
387 if (action != LFUN_SELFINSERT) {
388 // Put name of command and list of shortcuts
389 // for it in minibuffer
390 string comname = lyxaction.getActionName(action);
392 int pseudoaction = action;
393 bool argsadded = false;
395 if (!argument.empty()) {
396 // If we have the command with argument,
399 lyxaction.searchActionArg(action,
402 if (pseudoaction == -1) {
403 pseudoaction = action;
405 comname += " " + argument;
410 string shortcuts = toplevel_keymap->findbinding(pseudoaction);
412 if (!shortcuts.empty()) {
413 comname += ": " + shortcuts;
414 } else if (!argsadded) {
415 comname += " " + argument;
418 if (!comname.empty()) {
419 comname = strip(comname);
420 commandshortcut = "(" + comname + ')';
421 owner->getMiniBuffer()->Set(commandshortcut);
422 // Here we could even add a small pause,
423 // to annoy the user and make him learn
425 // No! That will just annoy, not teach
426 // anything. The user will read the messages
427 // if they are interested. (Asger)
432 // Now that we know which action, if the buffer is RO let's check
433 // whether the action is legal. Alejandro 970603
434 if (owner->currentView()->available() &&
435 owner->currentBuffer()->isReadonly() &&
436 lyxaction.isFuncRO(action)) {
437 setErrorMessage(N_("Document is read-only"));
438 lyxerr.debug() << "Error: Document is read-only." << endl;
439 goto exit_with_message;
442 // If in math mode pass the control to
443 // the math inset [asierra060396]
444 if (owner->currentView()->available() &&
445 owner->currentBuffer()->the_locking_inset) {
446 if (action>1 || (action==LFUN_UNKNOWN_ACTION && keyseq.length>=-1)) {
447 if (action==LFUN_UNKNOWN_ACTION && argument.empty()) {
448 argument = keyseq.getiso();
450 // Undo/Redo pre 0.13 is a bit tricky for insets.
451 if (action==LFUN_UNDO) {
453 UpdatableInset* inset =
454 owner->currentBuffer()->the_locking_inset;
455 inset->GetCursorPos(slx, sly);
458 inset = (UpdatableInset*)owner->currentBuffer()->text->cursor.par->GetInset(owner->currentBuffer()->text->cursor.pos);
460 inset->Edit(slx, sly);
463 if (action==LFUN_REDO) {
465 UpdatableInset* inset = owner->currentBuffer()->the_locking_inset;
466 inset->GetCursorPos(slx, sly);
469 inset = (UpdatableInset*)owner->currentBuffer()->text->cursor.par->GetInset(owner->currentBuffer()->text->cursor.pos);
471 inset->Edit(slx, sly);
474 if (owner->currentBuffer()->the_locking_inset->LocalDispatch(action, argument.c_str()))
477 setMessage(N_("Text mode"));
478 if (action==LFUN_RIGHT || action==-1)
479 owner->currentBuffer()->text->CursorRight();
480 if (action==LFUN_LEFT || action==LFUN_RIGHT)
487 // --- Misc -------------------------------------------
488 case LFUN_WORDFINDFORWARD :
489 case LFUN_WORDFINDBACKWARD : {
491 static string last_search;
492 string searched_string;
494 if (!argument.empty()) {
495 last_search = argument;
496 searched_string = argument;
498 searched_string = last_search;
501 ltCur = owner->currentView()->currentBuffer()->text ;
503 if (!searched_string.empty() &&
504 ( (action == LFUN_WORDFINDBACKWARD) ?
505 ltCur->SearchBackward( searched_string.c_str() ) :
506 ltCur->SearchForward( searched_string.c_str() )
509 // ??? What is that ???
510 owner->currentView()->currentBuffer()->update(-2);
513 // clear the selection (if there is any)
514 owner->currentView()->getScreen()->ToggleSelection();
515 owner->currentView()->currentBuffer()->text->ClearSelection();
517 // Move cursor so that successive C-s 's will not stand in place.
518 if( action == LFUN_WORDFINDFORWARD )
519 owner->currentBuffer()->text->CursorRightOneWord();
520 owner->currentBuffer()->text->FinishUndo();
521 moveCursorUpdate(false);
524 // set the new selection
525 // SetSelectionOverLenChars(owner->currentView()->currentBuffer()->text, iLenSelected);
526 owner->currentView()->getScreen()->ToggleSelection(false);
530 // REMOVED : if (owner->currentView()->getWorkArea()->focus)
531 owner->currentView()->getScreen()->ShowCursor();
537 if (owner->currentView()->available()
538 && owner->currentView()->getScreen()) {
539 owner->currentBuffer()->update(-2);
542 keyseq.print(buf,100, true);
543 owner->getMiniBuffer()->Set(buf, string(), string(), 1);
547 // --- Misc -------------------------------------------
548 case LFUN_EXEC_COMMAND:
549 owner->getMiniBuffer()->ExecCommand();
552 case LFUN_CANCEL: // RVDK_PATCH_5
555 if(owner->currentView()->available())
556 // cancel any selection
557 Dispatch(int(LFUN_MARK_OFF), 0);
558 setMessage(N_("Cancel"));
561 case LFUN_META_FAKE: // RVDK_PATCH_5
563 meta_fake_bit = Mod1Mask;
565 keyseq.print(buf, 98, true);
566 string res = string("M-") + buf;
567 setMessage(buf); // RVDK_PATCH_5
571 case LFUN_READ_ONLY_TOGGLE:
572 if (owner->currentBuffer()->lyxvc.inUse()) {
573 owner->currentBuffer()->lyxvc.toggleReadOnly();
575 owner->currentBuffer()->setReadonly(
576 !owner->currentBuffer()->isReadonly());
580 case LFUN_CENTER: // this is center and redraw.
582 if (owner->currentBuffer()->text->cursor.y >
583 owner->currentView()->getWorkArea()->h / 2) {
584 owner->currentView()->getScreen()->
585 Draw(owner->currentBuffer()->text->cursor.y -
586 owner->currentView()->getWorkArea()->h/2);
588 owner->currentView()->getScreen()->
591 owner->currentBuffer()->update(0);
592 owner->currentView()->redraw();
596 if (owner->currentView()->available()) {
597 owner->currentBuffer()->text->toggleAppendix();
598 owner->currentBuffer()->update(1);
602 // --- Menus -----------------------------------------------
607 case LFUN_MENUNEWTMPLT:
615 case LFUN_CLOSEBUFFER:
620 MenuWrite(owner->currentBuffer());
623 case LFUN_MENUWRITEAS:
624 MenuWriteAs(owner->currentBuffer());
627 case LFUN_MENURELOAD:
632 MenuPreview(owner->currentBuffer());
636 MenuPreviewPS(owner->currentBuffer());
640 MenuRunLaTeX(owner->currentBuffer());
644 MenuBuildProg(owner->currentBuffer());
648 MenuRunChktex(owner->currentBuffer());
652 MenuRunDvips(owner->currentBuffer(), false);
656 MenuPrint(owner->currentBuffer());
660 MenuFax(owner->currentBuffer());
665 //needs argument as string
666 string extyp=argument;
669 if (extyp == "latex") {
670 // make sure that this buffer is not linuxdoc
671 MenuMakeLaTeX(owner->currentBuffer());
674 else if (extyp == "linuxdoc") {
675 // make sure that this buffer is not latex
676 MenuMakeLinuxDoc(owner->currentBuffer());
679 else if (extyp == "docbook") {
680 // make sure that this buffer is not latex or linuxdoc
681 MenuMakeDocBook(owner->currentBuffer());
684 else if (extyp == "dvi") {
685 // Run LaTeX as "Update dvi..." Bernhard.
686 // We want the dvi in the current directory. This
687 // is achieved by temporarily disabling use of
688 // temp directory. As a side-effect, we get
689 // *.log and *.aux files also. (Asger)
690 bool flag = lyxrc->use_tempdir;
691 lyxrc->use_tempdir = false;
692 MenuRunLaTeX(owner->currentBuffer());
693 lyxrc->use_tempdir = flag;
696 else if (extyp == "postscript") {
697 // Start Print-dialog. Not as good as dvi... Bernhard.
698 MenuPrint(owner->currentBuffer());
699 // Since the MenuPrint is a pop-up, we can't use
700 // the same trick as above. (Asger)
701 // MISSING: Move of ps-file :-(
704 else if (extyp == "ascii") {
705 MenuMakeAscii(owner->currentBuffer());
707 else if (extyp == "custom") {
712 else if (extyp == "html" && lyxrc->html_command != "none") {
713 // First, create LaTeX file
714 MenuMakeLaTeX(owner->currentBuffer());
716 // And now, run the converter
717 string file = owner->currentBuffer()->getFileName();
718 Path path(OnlyPath(file));
719 // the tex file name has to be correct for
720 // latex, but the html file name can be
722 string result = ChangeExtension(file, ".html", false);
723 file = ChangeExtension(SpaceLess(file), ".tex", false);
724 string tmp = lyxrc->html_command;
725 tmp = subst(tmp, "$$FName", file);
726 tmp = subst(tmp, "$$OutName", result);
728 int res = one.startscript(Systemcalls::System, tmp);
730 setMessage(_("Document exported as HTML to file `")
731 + MakeDisplayPath(result) +'\'');
733 setErrorMessage(_("Unable to convert to HTML the file `")
734 + MakeDisplayPath(file)
739 setErrorMessage(_("Unknown export type: ")
747 //needs argument as string
748 string imtyp=argument;
751 if (imtyp == "latex") {
752 doImportLaTeX(false);
755 else if (imtyp == "ascii") {
756 doImportASCII(false);
757 } else if (imtyp == "asciiparagraph") {
760 } else if (imtyp == "noweb") {
763 setErrorMessage(string(N_("Unknown import type: "))
775 if (fd_form_toc->form_toc->visible) {
776 fl_raise_form(fd_form_toc->form_toc);
778 static int ow = -1, oh;
779 fl_show_form(fd_form_toc->form_toc,
781 FL_FREE_SIZE, FL_FULLBORDER,
782 _("Table of Contents"));
784 ow = fd_form_toc->form_toc->w;
785 oh = fd_form_toc->form_toc->h;
787 fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
791 case LFUN_TOC_INSERT:
794 new InsetTOC(owner->currentBuffer());
795 owner->currentBuffer()->insertInset(new_inset,
800 case LFUN_LOF_INSERT:
803 new InsetLOF(owner->currentBuffer());
804 owner->currentBuffer()->insertInset(new_inset,
809 case LFUN_LOA_INSERT:
812 new InsetLOA(owner->currentBuffer());
813 owner->currentBuffer()->insertInset(new_inset,
818 case LFUN_LOT_INSERT:
821 new InsetLOT(owner->currentBuffer());
822 owner->currentBuffer()->insertInset(new_inset,
847 case LFUN_MENUSEARCH:
855 case LFUN_PASTESELECTION:
858 if (string(argument) == "paragraph") asPara = true;
859 MenuPasteSelection(asPara);
871 case LFUN_LAYOUT_COPY:
875 case LFUN_LAYOUT_PASTE:
876 PasteEnvironmentCB();
880 owner->currentView()->gotoError();
883 case LFUN_REMOVEERRORS:
884 if (owner->currentBuffer()->removeAutoInsets()) {
885 owner->currentView()->redraw();
886 owner->currentView()->fitCursor();
887 owner->currentView()->updateScrollbar();
899 case LFUN_HYPHENATION:
907 case LFUN_END_OF_SENTENCE:
911 case LFUN_MENU_SEPARATOR:
927 case LFUN_DEPTH_PLUS:
943 case LFUN_RECONFIGURE:
948 if (owner->currentView()->available()
949 && !owner->currentBuffer()->text->selection
950 && owner->currentBuffer()->text->cursor.par->footnoteflag
951 != LyXParagraph::NO_FOOTNOTE)
952 { // only melt footnotes with FOOTMELT, not margins etc
953 if(owner->currentBuffer()->text->cursor.par->footnotekind == LyXParagraph::FOOTNOTE)
960 case LFUN_MARGINMELT:
961 if (owner->currentView()->available()
962 && !owner->currentBuffer()->text->selection
963 && owner->currentBuffer()->text->cursor.par->footnoteflag
964 != LyXParagraph::NO_FOOTNOTE)
965 { // only melt margins
966 if(owner->currentBuffer()->text->cursor.par->footnotekind == LyXParagraph::MARGIN)
973 // --- version control -------------------------------
974 case LFUN_VC_REGISTER:
976 if (!owner->currentBuffer()->lyxvc.inUse())
977 owner->currentBuffer()->lyxvc.registrer();
981 case LFUN_VC_CHECKIN:
983 if (owner->currentBuffer()->lyxvc.inUse()
984 && !owner->currentBuffer()->isReadonly())
985 owner->currentBuffer()->lyxvc.checkIn();
989 case LFUN_VC_CHECKOUT:
991 if (owner->currentBuffer()->lyxvc.inUse()
992 && owner->currentBuffer()->isReadonly())
993 owner->currentBuffer()->lyxvc.checkOut();
999 owner->currentBuffer()->lyxvc.revert();
1005 owner->currentBuffer()->lyxvc.undoLast();
1009 case LFUN_VC_HISTORY:
1011 owner->currentBuffer()->lyxvc.showLog();
1015 // --- buffers ----------------------------------------
1016 case LFUN_PREVBUFFER:
1017 #ifdef WITH_WARNINGS
1018 #warning fix this please
1020 // it is the LyXView or the BufferView that should
1021 // remember the previous buffer, not bufferlist.
1022 // if (owner->currentView()->available()){
1024 // owner->currentBuffer()->update(-2);
1026 // owner->currentView()->setBuffer(bufferlist.prev());
1028 // owner->currentView()->
1029 // resizeCurrentBufferPseudoExpose();
1032 case LFUN_FILE_INSERT:
1034 MenuInsertLyXFile(argument);
1038 case LFUN_FILE_INSERT_ASCII:
1040 bool asPara = false;
1041 asPara = (string(argument) == "paragraph");
1042 InsertAsciiFile(string(), asPara);
1048 // servercmd: argument must be <file>:<template>
1049 Buffer * tmpbuf = 0;
1050 tmpbuf = NewLyxFile(argument);
1052 owner->currentView()->setBuffer(tmpbuf);
1056 case LFUN_FILE_OPEN:
1057 owner->currentView()->setBuffer(
1058 bufferlist.loadLyXFile(argument));
1061 case LFUN_LATEX_LOG:
1067 lyxerr.debug() << "LFUN_LAYOUTNO: (arg) " << argument << endl;
1068 int sel = strToInt(argument);
1069 lyxerr.debug() << "LFUN_LAYOUTNO: (sel) "<< sel << endl;
1071 // Should this give a setMessage instead?
1073 return string(); // illegal argument
1075 sel--; // sel 1..., but layout 0...
1077 // Pretend we got the name instead.
1078 Dispatch(int(LFUN_LAYOUT),
1079 textclasslist.NameOfLayout(owner->currentBuffer()->
1088 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1089 << argument << endl;
1091 // Derive layout number from given argument (string)
1092 // and current buffer's textclass (number). */
1095 textclasslist.NumberOfLayout(owner->
1101 // see if we found the layout number:
1102 if (layoutno == -1) {
1103 setErrorMessage(string(N_("Layout ")) + argument +
1108 if (current_layout != layoutno) {
1109 owner->currentView()->getScreen()->HideCursor();
1110 current_layout = layoutno;
1111 owner->currentBuffer()->update(-2);
1112 owner->currentBuffer()->text->
1113 SetLayout(layoutno);
1114 owner->getToolbar()->combox->
1115 select(owner->currentBuffer()->
1118 owner->currentBuffer()->update(1);
1123 case LFUN_LAYOUT_DOCUMENT:
1124 MenuLayoutDocument();
1127 case LFUN_LAYOUT_PARAGRAPH:
1128 MenuLayoutParagraph();
1131 case LFUN_LAYOUT_CHARACTER:
1132 MenuLayoutCharacter();
1135 case LFUN_LAYOUT_TABLE:
1138 if (string(argument) == "true") flag = 1;
1139 MenuLayoutTable(flag);
1143 case LFUN_LAYOUT_PAPER:
1147 case LFUN_LAYOUT_QUOTES:
1151 case LFUN_LAYOUT_PREAMBLE:
1152 MenuLayoutPreamble();
1155 case LFUN_LAYOUT_SAVE_DEFAULT:
1159 case LFUN_DROP_LAYOUTS_CHOICE:
1160 owner->getToolbar()->combox->Show();
1191 case LFUN_UNDERLINE:
1195 case LFUN_FONT_SIZE:
1196 FontSizeCB(argument);
1199 case LFUN_FONT_STATE:
1200 setMessage(CurrentState());
1203 case LFUN_UPCASE_WORD:
1204 owner->currentBuffer()->update(-2);
1206 owner->currentBuffer()->text->ChangeWordCase(LyXText::text_uppercase);
1207 owner->currentBuffer()->update(1);
1211 case LFUN_LOWCASE_WORD:
1212 owner->currentBuffer()->update(-2);
1214 owner->currentBuffer()->text->ChangeWordCase(LyXText::text_lowercase);
1215 owner->currentBuffer()->update(1);
1219 case LFUN_CAPITALIZE_WORD:
1220 owner->currentBuffer()->update(-2);
1222 owner->currentBuffer()->text->ChangeWordCase(LyXText::text_capitalization);
1223 owner->currentBuffer()->update(1);
1227 case LFUN_INSERT_LABEL:
1228 MenuInsertLabel(argument.c_str());
1231 case LFUN_INSERT_REF:
1235 case LFUN_REFTOGGLE:
1238 (InsetRef*)getInsetByCode(Inset::REF_CODE);
1240 if (inset->getFlag()==InsetRef::REF)
1241 inset->setFlag(InsetRef::PAGE_REF);
1243 inset->setFlag(InsetRef::REF);
1246 setErrorMessage(N_("No cross-reference to toggle"));
1253 owner->currentView()->restorePosition();
1259 string label(argument);
1260 if (label.empty()) {
1262 (InsetRef*)getInsetByCode(Inset::REF_CODE);
1264 label = inset->getContents();
1267 if (!label.empty()) {
1268 owner->currentView()->savePosition();
1269 owner->currentBuffer()->gotoLabel(label.c_str());
1274 case LFUN_MENU_OPEN_BY_NAME:
1275 owner->getMenus()->openByName(argument);
1276 break; // RVDK_PATCH_5
1278 case LFUN_SPELLCHECK:
1279 if (lyxrc->isp_command != "none")
1281 break; // RVDK_PATCH_5
1283 // --- Cursor Movements -----------------------------
1286 Buffer *tmpbuffer = owner->currentBuffer();
1287 LyXText *tmptext = owner->currentBuffer()->text;
1288 if(!tmptext->mark_set)
1290 tmpbuffer->update(-2);
1291 if (tmptext->cursor.pos < tmptext->cursor.par->Last()
1292 && tmptext->cursor.par->GetChar(tmptext->cursor.pos)
1294 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)
1295 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)->Editable()==2){
1296 Inset* tmpinset = tmptext->cursor.par->GetInset(tmptext->cursor.pos);
1297 setMessage(tmpinset->EditMessage());
1298 tmpinset->Edit(0,0);
1301 tmptext->CursorRight();
1302 owner->currentBuffer()->text->FinishUndo();
1303 moveCursorUpdate(false);
1304 owner->getMiniBuffer()->Set(CurrentState());
1310 // This is soooo ugly. Isn`t it possible to make
1311 // it simpler? (Lgb)
1312 LyXText *txt= owner->currentBuffer()->text;
1313 if(!txt->mark_set) BeforeChange();
1314 owner->currentBuffer()->update(-2);
1316 if (txt->cursor.pos < txt->cursor.par->Last()
1317 && txt->cursor.par->GetChar(txt->cursor.pos)
1319 && txt->cursor.par->GetInset(txt->cursor.pos)
1320 && txt->cursor.par->GetInset(txt->cursor.pos)->Editable()==2) {
1321 Inset* tmpinset = txt->cursor.par->GetInset(txt->cursor.pos);
1322 setMessage(tmpinset->EditMessage());
1323 tmpinset->Edit(tmpinset->Width(txt->GetFont(txt->cursor.par,
1324 txt->cursor.pos)),0);
1325 // tmpinset->Edit(-1, 0); // -1 means go rightmost
1328 owner->currentBuffer()->text->FinishUndo();
1329 moveCursorUpdate(false);
1330 owner->getMiniBuffer()->Set(CurrentState());
1335 if(!owner->currentBuffer()->text->mark_set) BeforeChange();
1336 owner->currentBuffer()->update(-3);
1337 owner->currentBuffer()->text->CursorUp();
1338 owner->currentBuffer()->text->FinishUndo();
1339 moveCursorUpdate(false);
1340 owner->getMiniBuffer()->Set(CurrentState());
1344 if(!owner->currentBuffer()->text->mark_set)
1346 owner->currentBuffer()->update(-3);
1347 owner->currentBuffer()->text->CursorDown();
1348 owner->currentBuffer()->text->FinishUndo();
1349 moveCursorUpdate(false);
1350 owner->getMiniBuffer()->Set(CurrentState());
1353 case LFUN_UP_PARAGRAPH:
1354 if(!owner->currentBuffer()->text->mark_set)
1356 owner->currentBuffer()->update(-3);
1357 owner->currentBuffer()->text->CursorUpParagraph();
1358 owner->currentBuffer()->text->FinishUndo();
1359 moveCursorUpdate(false);
1360 owner->getMiniBuffer()->Set(CurrentState());
1363 case LFUN_DOWN_PARAGRAPH:
1364 if(!owner->currentBuffer()->text->mark_set)
1366 owner->currentBuffer()->update(-3);
1367 owner->currentBuffer()->text->CursorDownParagraph();
1368 owner->currentBuffer()->text->FinishUndo();
1369 moveCursorUpdate(false);
1370 owner->getMiniBuffer()->Set(CurrentState());
1374 if(!owner->currentBuffer()->text->mark_set)
1376 owner->currentBuffer()->update(-3);
1377 owner->currentView()->cursorPrevious();
1378 owner->currentBuffer()->text->FinishUndo();
1379 moveCursorUpdate(false);
1380 owner->getMiniBuffer()->Set(CurrentState());
1384 if(!owner->currentBuffer()->text->mark_set)
1386 owner->currentBuffer()->update(-3);
1387 owner->currentView()->cursorNext();
1388 owner->currentBuffer()->text->FinishUndo();
1389 moveCursorUpdate(false);
1390 owner->getMiniBuffer()->Set(CurrentState());
1394 if(!owner->currentBuffer()->text->mark_set)
1396 owner->currentBuffer()->update(-2);
1397 owner->currentBuffer()->text->CursorHome();
1398 owner->currentBuffer()->text->FinishUndo();
1399 moveCursorUpdate(false);
1400 owner->getMiniBuffer()->Set(CurrentState());
1404 if(!owner->currentBuffer()->text->mark_set)
1406 owner->currentBuffer()->update(-2);
1407 owner->currentBuffer()->text->CursorEnd();
1408 owner->currentBuffer()->text->FinishUndo();
1409 moveCursorUpdate(false);
1410 owner->getMiniBuffer()->Set(CurrentState());
1414 if(!owner->currentBuffer()->text->mark_set)
1416 owner->currentBuffer()->update(-2);
1417 owner->currentBuffer()->text->CursorTab();
1418 owner->currentBuffer()->text->FinishUndo();
1419 moveCursorUpdate(false);
1420 owner->getMiniBuffer()->Set(CurrentState());
1423 case LFUN_WORDRIGHT:
1424 if(!owner->currentBuffer()->text->mark_set)
1426 owner->currentBuffer()->update(-2);
1427 owner->currentBuffer()->text->CursorRightOneWord();
1428 owner->currentBuffer()->text->FinishUndo();
1429 moveCursorUpdate(false);
1430 owner->getMiniBuffer()->Set(CurrentState());
1434 if(!owner->currentBuffer()->text->mark_set)
1436 owner->currentBuffer()->update(-2);
1437 owner->currentBuffer()->text->CursorLeftOneWord();
1438 owner->currentBuffer()->text->FinishUndo();
1439 moveCursorUpdate(false);
1440 owner->getMiniBuffer()->Set(CurrentState());
1443 case LFUN_BEGINNINGBUF:
1444 if(!owner->currentBuffer()->text->mark_set)
1446 owner->currentBuffer()->update(-2);
1447 owner->currentBuffer()->text->CursorTop();
1448 owner->currentBuffer()->text->FinishUndo();
1449 moveCursorUpdate(false);
1450 owner->getMiniBuffer()->Set(CurrentState());
1454 if(!owner->currentBuffer()->text->mark_set)
1456 owner->currentBuffer()->update(-2);
1457 owner->currentBuffer()->text->CursorBottom();
1458 owner->currentBuffer()->text->FinishUndo();
1459 moveCursorUpdate(false);
1460 owner->getMiniBuffer()->Set(CurrentState());
1464 /* cursor selection ---------------------------- */
1466 owner->currentBuffer()->update(-2);
1467 owner->currentBuffer()->text->CursorRight();
1468 owner->currentBuffer()->text->FinishUndo();
1469 moveCursorUpdate(true);
1470 owner->getMiniBuffer()->Set(CurrentState());
1474 owner->currentBuffer()->update(-2);
1475 owner->currentBuffer()->text->CursorLeft();
1476 owner->currentBuffer()->text->FinishUndo();
1477 moveCursorUpdate(true);
1478 owner->getMiniBuffer()->Set(CurrentState());
1482 owner->currentBuffer()->update(-2);
1483 owner->currentBuffer()->text->CursorUp();
1484 owner->currentBuffer()->text->FinishUndo();
1485 moveCursorUpdate(true);
1486 owner->getMiniBuffer()->Set(CurrentState());
1490 owner->currentBuffer()->update(-2);
1491 owner->currentBuffer()->text->CursorDown();
1492 owner->currentBuffer()->text->FinishUndo();
1493 moveCursorUpdate(true);
1494 owner->getMiniBuffer()->Set(CurrentState());
1497 case LFUN_UP_PARAGRAPHSEL:
1498 owner->currentBuffer()->update(-2);
1499 owner->currentBuffer()->text->CursorUpParagraph();
1500 owner->currentBuffer()->text->FinishUndo();
1501 moveCursorUpdate(true);
1502 owner->getMiniBuffer()->Set(CurrentState());
1505 case LFUN_DOWN_PARAGRAPHSEL:
1506 owner->currentBuffer()->update(-2);
1507 owner->currentBuffer()->text->CursorDownParagraph();
1508 owner->currentBuffer()->text->FinishUndo();
1509 moveCursorUpdate(true);
1510 owner->getMiniBuffer()->Set(CurrentState());
1514 owner->currentBuffer()->update(-2);
1515 owner->currentView()->cursorPrevious();
1516 owner->currentBuffer()->text->FinishUndo();
1517 moveCursorUpdate(true);
1518 owner->getMiniBuffer()->Set(CurrentState());
1522 owner->currentBuffer()->update(-2);
1523 owner->currentView()->cursorNext();
1524 owner->currentBuffer()->text->FinishUndo();
1525 moveCursorUpdate(true);
1526 owner->getMiniBuffer()->Set(CurrentState());
1530 owner->currentBuffer()->update(-2);
1531 owner->currentBuffer()->text->CursorHome();
1532 owner->currentBuffer()->text->FinishUndo();
1533 moveCursorUpdate(true);
1534 owner->getMiniBuffer()->Set(CurrentState());
1538 owner->currentBuffer()->update(-2);
1539 owner->currentBuffer()->text->CursorEnd();
1540 owner->currentBuffer()->text->FinishUndo();
1541 moveCursorUpdate(true);
1542 owner->getMiniBuffer()->Set(CurrentState());
1545 case LFUN_WORDRIGHTSEL:
1546 owner->currentBuffer()->update(-2);
1547 owner->currentBuffer()->text->CursorRightOneWord();
1548 owner->currentBuffer()->text->FinishUndo();
1549 moveCursorUpdate(true);
1550 owner->getMiniBuffer()->Set(CurrentState());
1553 case LFUN_WORDLEFTSEL:
1554 owner->currentBuffer()->update(-2);
1555 owner->currentBuffer()->text->CursorLeftOneWord();
1556 owner->currentBuffer()->text->FinishUndo();
1557 moveCursorUpdate(true);
1558 owner->getMiniBuffer()->Set(CurrentState());
1561 case LFUN_BEGINNINGBUFSEL:
1562 owner->currentBuffer()->update(-2);
1563 owner->currentBuffer()->text->CursorTop();
1564 owner->currentBuffer()->text->FinishUndo();
1565 moveCursorUpdate(true);
1566 owner->getMiniBuffer()->Set(CurrentState());
1569 case LFUN_ENDBUFSEL:
1570 owner->currentBuffer()->update(-2);
1571 owner->currentBuffer()->text->CursorBottom();
1572 owner->currentBuffer()->text->FinishUndo();
1573 moveCursorUpdate(true);
1574 owner->getMiniBuffer()->Set(CurrentState());
1577 // --- text changing commands ------------------------
1578 case LFUN_BREAKLINE:
1580 owner->currentBuffer()->text->InsertChar(LYX_META_NEWLINE);
1582 SetUpdateTimer(0.01);
1583 moveCursorUpdate(false);
1586 case LFUN_PROTECTEDSPACE:
1588 owner->currentBuffer()->text->
1589 InsertChar(LYX_META_PROTECTED_SEPARATOR);
1592 moveCursorUpdate(false);
1596 if(owner->currentBuffer()->text->mark_set) {
1598 owner->currentBuffer()->update(0);
1599 setMessage(N_("Mark removed"));
1602 owner->currentBuffer()->text->mark_set = 1;
1603 owner->currentBuffer()->update(0);
1604 setMessage(N_("Mark set"));
1606 owner->currentBuffer()->text->sel_cursor =
1607 owner->currentBuffer()->text->cursor;
1612 if (!owner->currentBuffer()->text->selection) {
1613 owner->currentBuffer()->text->Delete();
1614 owner->currentBuffer()->text->sel_cursor =
1615 owner->currentBuffer()->text->cursor;
1617 // It is possible to make it a lot faster still
1618 // just comment out the lone below...
1619 owner->currentView()->getScreen()->ShowCursor();
1626 case LFUN_DELETE_SKIP:
1628 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1630 LyXCursor cursor = owner->currentBuffer()->text->cursor;
1633 if (!owner->currentBuffer()->text->selection) {
1634 if (cursor.pos == cursor.par->Last()) {
1635 owner->currentBuffer()->text->CursorRight();
1636 cursor = owner->currentBuffer()->text->cursor;
1638 && !(cursor.par->added_space_top
1639 == VSpace (VSpace::NONE))) {
1640 owner->currentBuffer()->text->SetParagraph
1641 (cursor.par->line_top,
1642 cursor.par->line_bottom,
1643 cursor.par->pagebreak_top,
1644 cursor.par->pagebreak_bottom,
1645 VSpace(VSpace::NONE),
1646 cursor.par->added_space_bottom,
1648 cursor.par->labelwidthstring, 0);
1649 owner->currentBuffer()->text->CursorLeft();
1650 owner->currentBuffer()->update (1);
1652 owner->currentBuffer()->text->CursorLeft();
1653 owner->currentBuffer()->text->Delete();
1654 owner->currentBuffer()->text->sel_cursor =
1655 owner->currentBuffer()->text->cursor;
1659 owner->currentBuffer()->text->Delete();
1660 owner->currentBuffer()->text->sel_cursor =
1661 owner->currentBuffer()->text->cursor;
1671 /* -------> Delete word forward. */
1672 case LFUN_DELETE_WORD_FORWARD:
1673 owner->currentBuffer()->update(-2);
1675 owner->currentBuffer()->text->DeleteWordForward();
1676 owner->currentBuffer()->update( 1 );
1678 moveCursorUpdate(false);
1681 /* -------> Delete word backward. */
1682 case LFUN_DELETE_WORD_BACKWARD:
1683 owner->currentBuffer()->update(-2);
1685 owner->currentBuffer()->text->DeleteWordBackward();
1686 owner->currentBuffer()->update( 1 );
1688 moveCursorUpdate(false);
1691 /* -------> Kill to end of line. */
1692 case LFUN_DELETE_LINE_FORWARD:
1694 owner->currentBuffer()->update(-2);
1695 owner->currentBuffer()->text->DeleteLineForward();
1696 owner->currentBuffer()->update( 1 );
1698 moveCursorUpdate(false);
1701 /* -------> Set mark off. */
1704 owner->currentBuffer()->update(0);
1705 owner->currentBuffer()->text->sel_cursor =
1706 owner->currentBuffer()->text->cursor;
1707 setMessage(N_("Mark off"));
1710 /* -------> Set mark on. */
1713 owner->currentBuffer()->text->mark_set = 1;
1714 owner->currentBuffer()->update( 0 );
1715 owner->currentBuffer()->text->sel_cursor =
1716 owner->currentBuffer()->text->cursor;
1717 setMessage(N_("Mark on"));
1720 case LFUN_BACKSPACE:
1723 if (!owner->currentBuffer()->text->selection) {
1724 if (owner->getIntl()->getTrans()->backspace()) {
1725 owner->currentBuffer()->text->Backspace();
1726 owner->currentBuffer()->text->sel_cursor =
1727 owner->currentBuffer()->text->cursor;
1729 // It is possible to make it a lot faster still
1730 // just comment out the lone below...
1731 owner->currentView()->getScreen()->ShowCursor();
1740 case LFUN_BACKSPACE_SKIP:
1742 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1744 LyXCursor cursor = owner->currentBuffer()->text->cursor;
1747 if (!owner->currentBuffer()->text->selection) {
1749 && !(cursor.par->added_space_top
1750 == VSpace (VSpace::NONE))) {
1751 owner->currentBuffer()->text->SetParagraph
1752 (cursor.par->line_top,
1753 cursor.par->line_bottom,
1754 cursor.par->pagebreak_top,
1755 cursor.par->pagebreak_bottom,
1756 VSpace(VSpace::NONE), cursor.par->added_space_bottom,
1758 cursor.par->labelwidthstring, 0);
1759 owner->currentBuffer()->update (1);
1761 owner->currentBuffer()->text->Backspace();
1762 owner->currentBuffer()->text->sel_cursor
1772 case LFUN_BREAKPARAGRAPH:
1775 owner->currentBuffer()->text->BreakParagraph(0);
1777 SetUpdateTimer(0.01);
1778 owner->currentBuffer()->text->sel_cursor =
1779 owner->currentBuffer()->text->cursor;
1783 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1786 owner->currentBuffer()->text->BreakParagraph(1);
1788 SetUpdateTimer(0.01);
1789 owner->currentBuffer()->text->sel_cursor =
1790 owner->currentBuffer()->text->cursor;
1794 case LFUN_BREAKPARAGRAPH_SKIP:
1796 // When at the beginning of a paragraph, remove
1797 // indentation and add a "defskip" at the top.
1798 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
1800 LyXCursor cursor = owner->currentBuffer()->text->cursor;
1803 if (cursor.pos == 0) {
1804 if (cursor.par->added_space_top == VSpace(VSpace::NONE)) {
1805 owner->currentBuffer()->text->SetParagraph
1806 (cursor.par->line_top,
1807 cursor.par->line_bottom,
1808 cursor.par->pagebreak_top,
1809 cursor.par->pagebreak_bottom,
1810 VSpace(VSpace::DEFSKIP), cursor.par->added_space_bottom,
1812 cursor.par->labelwidthstring, 1);
1813 owner->currentBuffer()->update(1);
1817 owner->currentBuffer()->text->BreakParagraph(0);
1820 SetUpdateTimer(0.01);
1821 owner->currentBuffer()->text->sel_cursor = cursor;
1827 owner->currentBuffer()->text->InsertChar('\"'); // This " matches the single quote in the code
1830 moveCursorUpdate(false);
1836 InsetCommand *new_inset;
1837 if (action == LFUN_HTMLURL)
1838 new_inset = new InsetUrl("htmlurl", "", "");
1840 new_inset = new InsetUrl("url", "", "");
1841 owner->currentBuffer()->insertInset(new_inset);
1842 new_inset->Edit(0, 0);
1846 // --- lyxserver commands ----------------------------
1848 case LFUN_CHARATCURSOR:
1851 LyXParagraph::size_type pos =
1852 owner->currentBuffer()->text->cursor.pos;
1853 if(pos < owner->currentBuffer()->text->cursor.par->size())
1855 int pos = owner->currentBuffer()->text->cursor.pos;
1856 if(pos < owner->currentBuffer()->text->cursor.par->last)
1858 dispatch_buffer = owner->currentBuffer()->text->
1859 cursor.par->text[pos];
1861 dispatch_buffer = "EOF";
1867 tostr(owner->currentBuffer()->text->cursor.x) + ' '
1868 + tostr(owner->currentBuffer()->text->cursor.y);
1875 sscanf(argument.c_str(), " %d %ld", &x, &y);
1876 owner->currentBuffer()->text->SetCursorFromCoordinates(x, y);
1880 case LFUN_GETLAYOUT:
1882 tostr(owner->currentBuffer()->text->cursor.par->layout);
1887 LyXFont *font = &(owner->currentBuffer()->text->current_font);
1888 if(font->shape() == LyXFont::ITALIC_SHAPE)
1889 dispatch_buffer = 'E';
1890 else if(font->shape() == LyXFont::SMALLCAPS_SHAPE)
1891 dispatch_buffer = 'N';
1893 dispatch_buffer = '0';
1900 LyXFont *font = &(owner->currentBuffer()->text->current_font);
1901 if(font->latex() == LyXFont::ON)
1902 dispatch_buffer = 'L';
1904 dispatch_buffer = '0';
1909 setMessage(owner->currentBuffer()->getFileName());
1910 lyxerr.debug() << "FNAME["
1911 << owner->currentBuffer()->getFileName()
1918 keyseq.print(buf,100);
1919 dispatch_buffer = buf;
1920 lyxserver->notifyClient(dispatch_buffer);
1924 case LFUN_GOTOFILEROW:
1926 char file_name[100];
1928 sscanf(argument.c_str(), " %s %d", file_name, &row);
1930 // Must replace extension of the file to be .lyx and get full path
1931 string s = ChangeExtension(string(file_name), ".lyx", false);
1933 // Either change buffer or load the file
1934 if (bufferlist.exists(s))
1935 owner->currentView()->setBuffer(bufferlist.getBuffer(s));
1937 owner->currentView()->setBuffer(bufferlist.loadLyXFile(s));
1940 owner->currentBuffer()->setCursorFromRow(row);
1944 if (owner->currentBuffer()->text->cursor.y >
1945 owner->currentView()->getWorkArea()->h / 2) {
1946 owner->currentView()->getScreen()->
1947 Draw(owner->currentBuffer()->text->cursor.y -
1948 owner->currentView()->getWorkArea()->h/2);
1950 owner->currentView()->getScreen()->
1953 owner->currentBuffer()->update(0);
1954 owner->currentView()->redraw();
1961 int qa = lyxaction.LookupFunc(argument.c_str());
1962 setMessage(lyxaction.helpText((kb_action)qa));
1966 // --- accented characters ---------------------------
1969 case LFUN_CIRCUMFLEX:
1979 case LFUN_SPECIAL_CARON:
1982 case LFUN_HUNG_UMLAUT:
1988 if (keyseq.length==-1 && keyseq.getiso()!=0)
1993 owner->getIntl()->getTrans()->
1994 deadkey(c, get_accent(action).accent,
1995 owner->currentBuffer()->text);
1997 // Need to reset, in case the minibuffer calls these
2002 // copied verbatim from do_accent_char
2005 owner->currentBuffer()->text->sel_cursor =
2006 owner->currentBuffer()->text->cursor;
2010 // --- toolbar ----------------------------------
2011 case LFUN_PUSH_TOOLBAR:
2013 int nth = strToInt(argument);
2014 if (lyxerr.debugging(Debug::TOOLBAR)) {
2015 lyxerr << "LFUN_PUSH_TOOLBAR: argument = `"
2016 << argument << "'\n"
2017 << "LFUN_PUSH_TOOLBAR: nth = `"
2018 << nth << "'" << endl;
2023 setErrorMessage(N_("Push-toolbar needs argument > 0"));
2025 owner->getToolbar()->push(nth);
2030 case LFUN_ADD_TO_TOOLBAR:
2032 if (lyxerr.debugging(Debug::TOOLBAR)) {
2033 lyxerr << "LFUN_ADD_TO_TOOLBAR:"
2034 "argument = `" << argument << '\'' << endl;
2036 string tmp(argument);
2037 //lyxerr <<string("Argument: ") + argument);
2038 //lyxerr <<string("Tmp : ") + tmp);
2041 setErrorMessage(N_("Usage: toolbar-add-to <LyX command>"));
2043 owner->getToolbar()->add(argument, false);
2044 owner->getToolbar()->set();
2049 // --- insert characters ----------------------------------------
2051 case LFUN_INSERT_INSET_LATEX:
2053 Inset *new_inset = new InsetLatex(argument);
2054 owner->currentBuffer()->insertInset(new_inset);
2058 // --- Mathed stuff. If we are here, there is no locked inset yet.
2063 if (!greek_kb_flag) {
2065 setMessage(N_("Math greek mode on"));
2072 case LFUN_GREEK_TOGGLE:
2074 greek_kb_flag = (greek_kb_flag) ? 0: 2;
2075 if (greek_kb_flag) {
2076 setMessage(N_("Math greek keyboard on"));
2078 setMessage(N_("Math greek keyboard off"));
2083 case LFUN_MATH_DELIM:
2084 case LFUN_INSERT_MATRIX:
2086 if (owner->currentView()->available()) {
2087 owner->currentBuffer()->
2088 open_new_inset(new InsetFormula(false));
2089 owner->currentBuffer()->
2090 the_locking_inset->LocalDispatch(action, argument.c_str());
2095 case LFUN_INSERT_MATH:
2097 math_insert_symbol(argument.c_str());
2101 case LFUN_MATH_DISPLAY:
2103 if (owner->currentView()->available())
2104 owner->currentBuffer()->open_new_inset(new InsetFormula(true));
2108 case LFUN_MATH_MACRO:
2110 if (owner->currentView()->available()) {
2113 setErrorMessage(N_("Missing argument"));
2115 string s1 = token(s, ' ', 1);
2116 int na = s1.empty() ? 0: atoi(s1.c_str());
2117 owner->currentBuffer()->
2118 open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2124 case LFUN_MATH_MODE: // Open or create a math inset
2127 if (owner->currentView()->available())
2128 owner->currentBuffer()->open_new_inset(new InsetFormula);
2129 setMessage(N_("Math editor mode"));
2133 case LFUN_MATH_NUMBER:
2134 case LFUN_MATH_LIMITS:
2136 setErrorMessage(N_("This is only allowed in math mode!"));
2140 case LFUN_INSERT_CITATION:
2142 InsetCitation *new_inset = new InsetCitation();
2144 // The note, if any, must be after the key, delimited
2145 // by a | so both key and remark can have spaces.
2146 if (!argument.empty()) {
2147 string lsarg(argument);
2148 if (contains(lsarg, "|")) {
2149 new_inset->setContents(token(lsarg, '|', 0));
2150 new_inset->setOptions(token(lsarg, '|', 1));
2152 new_inset->setContents(lsarg);
2153 owner->currentBuffer()->insertInset(new_inset);
2155 owner->currentBuffer()->insertInset(new_inset);
2156 new_inset->Edit(0,0);
2161 case LFUN_INSERT_BIBTEX:
2163 // ale970405+lasgoutt970425
2164 // The argument can be up to two tokens separated
2165 // by a space. The first one is the bibstyle.
2166 string lsarg(argument);
2167 string bibstyle = token(lsarg, ' ', 1);
2168 if (bibstyle.empty())
2170 InsetBibtex *new_inset
2171 = new InsetBibtex(token(lsarg, ' ', 0),
2173 owner->currentBuffer());
2175 owner->currentBuffer()->insertInset(new_inset);
2176 if (lsarg.empty()) {
2177 new_inset->Edit(0,0);
2182 // BibTeX data bases
2183 case LFUN_BIBDB_ADD:
2185 InsetBibtex *inset =
2186 (InsetBibtex*)getInsetByCode(Inset::BIBTEX_CODE);
2188 inset->addDatabase(argument);
2193 case LFUN_BIBDB_DEL:
2195 InsetBibtex *inset =
2196 (InsetBibtex*)getInsetByCode(Inset::BIBTEX_CODE);
2198 inset->delDatabase(argument);
2203 case LFUN_BIBTEX_STYLE:
2205 InsetBibtex *inset =
2206 (InsetBibtex*)getInsetByCode(Inset::BIBTEX_CODE);
2208 inset->setOptions(argument);
2213 case LFUN_INDEX_INSERT:
2214 case LFUN_INDEX_INSERT_LAST:
2216 InsetIndex * new_inset = new InsetIndex();
2217 if (!argument.empty()) {
2218 string lsarg(argument);
2219 new_inset->setContents(lsarg);
2220 owner->currentBuffer()->insertInset(new_inset);
2223 //get the current word for an argument
2229 LyXParagraph::size_type lastpos =
2230 owner->currentBuffer()->text->cursor.pos - 1;
2231 // If this can't happen, let's make sure that it really don't
2232 Assert(owner->currentBuffer()->text->cursor.pos - 1 >= 0);
2234 int lastpos =owner->currentBuffer()->text->cursor.pos - 1;
2235 //this shouldn't happen, but let's be careful
2236 if (lastpos < 0) lastpos=0;
2238 // get the current word
2239 // note that this must be done before
2240 // inserting the inset, or the inset will break
2242 string curstring(owner->currentBuffer()
2243 ->text->cursor.par->GetWord(lastpos));
2245 //make the new inset and write the current word into it
2246 InsetIndex * new_inset = new InsetIndex();
2248 new_inset->setContents(curstring);
2250 //don't edit it if the call was to INSERT_LAST
2251 if(action!=LFUN_INDEX_INSERT_LAST) {
2252 new_inset->Edit(0,0);
2254 //it looks blank on the screen unless
2255 //we do something. put it here.
2257 // move the cursor to the returned value of lastpos
2258 // but only for the auto-insert
2259 owner->currentBuffer()->text->cursor.pos=lastpos;
2262 //put the new inset into the buffer.
2263 // there should be some way of knowing the user
2264 //cancelled & avoiding this, but i don't know how
2265 owner->currentBuffer()->insertInset(new_inset);
2270 case LFUN_INDEX_PRINT:
2272 Inset *new_inset = new InsetPrintIndex(owner->currentBuffer());
2273 owner->currentBuffer()->insertInset(new_inset, "Standard", true);
2277 case LFUN_PARENTINSERT:
2279 lyxerr << "arg " << argument << endl;
2280 Inset *new_inset = new InsetParent(argument, owner->currentBuffer());
2281 owner->currentBuffer()->insertInset(new_inset, "Standard", true);
2285 case LFUN_CHILDINSERT:
2287 Inset *new_inset = new InsetInclude(argument,owner->currentBuffer());
2288 owner->currentBuffer()->insertInset(new_inset, "Standard", true);
2289 new_inset->Edit(0,0);
2293 case LFUN_CHILDOPEN:
2295 string filename = MakeAbsPath(argument,
2296 OnlyPath(owner->currentBuffer()->getFileName()));
2297 setMessage(N_("Opening child document ") +
2298 MakeDisplayPath(filename) + "...");
2299 owner->currentView()->savePosition();
2300 if (bufferlist.exists(filename))
2301 owner->currentView()->setBuffer(bufferlist.getBuffer(filename));
2303 owner->currentView()->setBuffer(bufferlist.loadLyXFile(filename));
2307 case LFUN_INSERT_NOTE:
2311 case LFUN_INSERTFOOTNOTE:
2313 LyXParagraph::footnote_kind kind;
2314 if (argument == "footnote")
2315 { kind = LyXParagraph::FOOTNOTE; }
2316 else if (argument == "margin")
2317 { kind = LyXParagraph::MARGIN; }
2318 else if (argument == "figure")
2319 { kind = LyXParagraph::FIG; }
2320 else if (argument == "table")
2321 { kind = LyXParagraph::TAB; }
2322 else if (argument == "wide-fig")
2323 { kind = LyXParagraph::WIDE_FIG; }
2324 else if (argument == "wide-tab")
2325 { kind = LyXParagraph::WIDE_TAB; }
2326 else if (argument == "algorithm")
2327 { kind = LyXParagraph::ALGORITHM; }
2329 setErrorMessage(N_("Unknown kind of footnote"));
2332 owner->currentBuffer()->text->InsertFootnoteEnvironment(kind);
2333 owner->currentBuffer()->update(1);
2337 case LFUN_BUFFERBULLETSSELECT:
2341 case LFUN_TOGGLECURSORFOLLOW:
2342 cursor_follows_scrollbar = !cursor_follows_scrollbar;
2345 case LFUN_KMAP_OFF: // keymap off
2346 owner->getIntl()->KeyMapOn(false);
2349 case LFUN_KMAP_PRIM: // primary keymap
2350 owner->getIntl()->KeyMapPrim();
2353 case LFUN_KMAP_SEC: // secondary keymap
2354 owner->getIntl()->KeyMapSec();
2357 case LFUN_KMAP_TOGGLE: // toggle keymap
2358 owner->getIntl()->ToggleKeyMap();
2361 case LFUN_SELFINSERT:
2363 for (string::size_type i = 0; i < argument.length(); ++i) {
2364 owner->currentBuffer()->text->InsertChar(argument[i]);
2365 // This needs to be in the loop, or else we
2366 // won't break lines correctly. (Asger)
2370 owner->currentBuffer()->text->sel_cursor =
2371 owner->currentBuffer()->text->cursor;
2372 moveCursorUpdate(false);
2376 case LFUN_UNKNOWN_ACTION:
2378 if (owner->currentBuffer()->isReadonly()) {
2380 setErrorMessage(N_("Document is read only"));
2384 if (!argument.empty()) {
2386 /* Automatically delete the currently selected
2387 * text and replace it with what is being
2388 * typed in now. Depends on lyxrc settings
2389 * "auto_region_delete", which defaults to
2392 if ( lyxrc->auto_region_delete ) {
2393 if (owner->currentBuffer()->text->selection){
2394 owner->currentBuffer()->text->CutSelection(false);
2395 owner->currentBuffer()->update(-1);
2400 for (string::size_type i = 0; i < argument.length(); ++i) {
2401 if (greek_kb_flag) {
2402 if (!math_insert_greek(argument[i]))
2403 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->currentBuffer()->text);
2405 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->currentBuffer()->text);
2411 owner->currentBuffer()->text->sel_cursor =
2412 owner->currentBuffer()->text->cursor;
2413 moveCursorUpdate(false);
2416 // why is an "Unknown action" with empty
2417 // argument even dispatched in the first
2418 // place? I`ll probably change that. (Lgb)
2420 setErrorMessage(N_("Unknown action"));
2424 lyxerr << "A truly unknown func!" << endl;
2430 string res=getMessage();
2433 if (!commandshortcut.empty()) {
2434 string newbuf = owner->getMiniBuffer()->GetText();
2435 if (newbuf != commandshortcut) {
2436 owner->getMiniBuffer()->Set(newbuf
2442 owner->getMiniBuffer()->Set(string(_(res.c_str()))
2443 + " " + commandshortcut);
2446 return getMessage();
2450 void LyXFunc::setupLocalKeymap()
2452 keyseq.stdmap = keyseq.curmap = toplevel_keymap;
2453 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap;
2457 void LyXFunc::MenuNew(bool fromTemplate)
2459 string fname, initpath = lyxrc->document_path;
2462 if (owner->currentView()->available()) {
2463 string trypath = owner->currentBuffer()->filepath;
2464 // If directory is writeable, use this as default.
2465 if (IsDirWriteable(trypath) == 1)
2470 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2471 fileDlg.SetButton(1, _("Templates"), lyxrc->template_path);
2472 fname = fileDlg.Select(_("Enter Filename for new document"),
2473 initpath, "*.lyx", _("newfile"));
2476 if (fname.empty()) {
2477 owner->getMiniBuffer()->Set(_("Canceled."));
2478 lyxerr.debug() << "New Document Cancelled." << endl;
2482 // get absolute path of file and make sure the filename ends
2484 string s = MakeAbsPath(fname);
2485 if (!IsLyXFilename(s))
2488 // Check if the document already is open
2489 if (bufferlist.exists(s)){
2490 switch(AskConfirmation(_("Document is already open:"),
2491 MakeDisplayPath(s,50),
2492 _("Do you want to close that document now?\n"
2493 "('No' will just switch to the open version)")))
2495 case 1: // Yes: close the document
2496 if (!bufferlist.close(bufferlist.getBuffer(s)))
2497 // If close is canceled, we cancel here too.
2500 case 2: // No: switch to the open document
2501 owner->currentView()->setBuffer(bufferlist.getBuffer(s));
2503 case 3: // Cancel: Do nothing
2504 owner->getMiniBuffer()->Set(_("Canceled."));
2509 // Check whether the file already exists
2510 if (IsLyXFilename(s)) {
2511 FilePtr myfile(s, FilePtr::read);
2513 AskQuestion(_("File already exists:"),
2514 MakeDisplayPath(s,50),
2515 _("Do you want to open the document?"))) {
2517 owner->getMiniBuffer()->Set(_("Opening document"),
2518 MakeDisplayPath(s), "...");
2520 owner->currentView()->setBuffer(
2521 bufferlist.loadLyXFile(s));
2522 owner->getMiniBuffer()->Set(_("Document"),
2529 // The template stuff
2533 fname = fileDlg.Select(_("Choose template"),
2534 lyxrc->template_path,
2540 // find a free buffer
2541 lyxerr.debug() << "Find a free buffer." << endl;
2542 owner->currentView()->setBuffer(bufferlist.newFile(s,templname));
2546 void LyXFunc::MenuOpen()
2548 string initpath = lyxrc->document_path;
2551 if (owner->currentView()->available()) {
2552 string trypath = owner->currentBuffer()->filepath;
2553 // If directory is writeable, use this as default.
2554 if (IsDirWriteable(trypath) == 1)
2560 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2561 fileDlg.SetButton(1, _("Examples"),
2562 AddPath(system_lyxdir, "examples"));
2563 string filename = fileDlg.Select(_("Select Document to Open"),
2567 // check selected filename
2568 if (filename.empty()) {
2569 owner->getMiniBuffer()->Set(_("Canceled."));
2573 // get absolute path of file and make sure the filename ends
2575 filename = MakeAbsPath(filename);
2576 if (!IsLyXFilename(filename))
2580 owner->getMiniBuffer()->Set(_("Opening document"),
2581 MakeDisplayPath(filename), "...");
2582 Buffer * openbuf = bufferlist.loadLyXFile(filename);
2584 owner->currentView()->setBuffer(openbuf);
2585 owner->getMiniBuffer()->Set(_("Document"),
2586 MakeDisplayPath(filename),
2589 owner->getMiniBuffer()->Set(_("Could not open document"),
2590 MakeDisplayPath(filename));
2595 void LyXFunc::doImportASCII(bool linorpar)
2597 string initpath = lyxrc->document_path;
2600 if (owner->currentView()->available()) {
2601 string trypath = owner->currentBuffer()->filepath;
2602 // If directory is writeable, use this as default.
2603 if (IsDirWriteable(trypath) == 1)
2609 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2610 fileDlg.SetButton(1, _("Examples"),
2611 AddPath(system_lyxdir, "examples"));
2612 string filename = fileDlg.Select(_("Select ASCII file to Import"),
2616 // check selected filename
2617 if (filename.empty()) {
2618 owner->getMiniBuffer()->Set(_("Canceled."));
2622 // get absolute path of file
2623 filename = MakeAbsPath(filename);
2625 string s = ChangeExtension(filename, ".lyx", false);
2627 // Check if the document already is open
2628 if (bufferlist.exists(s)){
2629 switch(AskConfirmation(_("Document is already open:"),
2630 MakeDisplayPath(s,50),
2631 _("Do you want to close that document now?\n"
2632 "('No' will just switch to the open version)")))
2634 case 1: // Yes: close the document
2635 if (!bufferlist.close(bufferlist.getBuffer(s)))
2636 // If close is canceled, we cancel here too.
2639 case 2: // No: switch to the open document
2640 owner->currentView()->setBuffer(bufferlist.getBuffer(s));
2642 case 3: // Cancel: Do nothing
2643 owner->getMiniBuffer()->Set(_("Canceled."));
2648 // Check if a LyX document by the same root exists in filesystem
2649 FileInfo f(s, true);
2650 if (f.exist() && !AskQuestion(_("A document by the name"),
2652 _("already exists. Overwrite?"))) {
2653 owner->getMiniBuffer()->Set(_("Canceled."));
2657 owner->currentView()->setBuffer(bufferlist.newFile(s,string()));
2658 owner->getMiniBuffer()->Set(_("Importing ASCII file"),
2659 MakeDisplayPath(filename), "...");
2660 // Insert ASCII file
2661 InsertAsciiFile(filename,linorpar);
2662 owner->getMiniBuffer()->Set(_("ASCII file "),
2663 MakeDisplayPath(filename),
2668 void LyXFunc::doImportLaTeX(bool isnoweb)
2670 string initpath = lyxrc->document_path;
2673 if (owner->currentView()->available()) {
2674 string trypath = owner->currentBuffer()->filepath;
2675 // If directory is writeable, use this as default.
2676 if (IsDirWriteable(trypath) == 1)
2682 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2683 fileDlg.SetButton(1, _("Examples"),
2684 AddPath(system_lyxdir, "examples"));
2687 filename = fileDlg.Select(_("Select Noweb file to Import"),
2690 filename = fileDlg.Select(_("Select LaTeX file to Import"),
2696 // check selected filename
2697 if (filename.empty()) {
2698 owner->getMiniBuffer()->Set(_("Canceled."));
2702 // get absolute path of file
2703 filename = MakeAbsPath(filename);
2705 // Check if the document already is open
2706 string LyXfilename = ChangeExtension(filename, ".lyx", false);
2707 if (bufferlist.exists(LyXfilename)){
2708 switch(AskConfirmation(_("Document is already open:"),
2709 MakeDisplayPath(LyXfilename,50),
2710 _("Do you want to close that document now?\n"
2711 "('No' will just switch to the open version)")))
2713 case 1: // Yes: close the document
2714 if (!bufferlist.close(bufferlist.getBuffer(LyXfilename)))
2715 // If close is canceled, we cancel here too.
2718 case 2: // No: switch to the open document
2719 owner->currentView()->setBuffer(
2720 bufferlist.getBuffer(LyXfilename));
2722 case 3: // Cancel: Do nothing
2723 owner->getMiniBuffer()->Set(_("Canceled."));
2728 // Check if a LyX document by the same root exists in filesystem
2729 FileInfo f(LyXfilename, true);
2730 if (f.exist() && !AskQuestion(_("A document by the name"),
2731 MakeDisplayPath(LyXfilename),
2732 _("already exists. Overwrite?"))) {
2733 owner->getMiniBuffer()->Set(_("Canceled."));
2740 owner->getMiniBuffer()->Set(_("Importing LaTeX file"),
2741 MakeDisplayPath(filename), "...");
2742 ImportLaTeX myImport(filename);
2743 openbuf = myImport.run();
2745 owner->getMiniBuffer()->Set(_("Importing Noweb file"),
2746 MakeDisplayPath(filename), "...");
2747 ImportNoweb myImport(filename);
2748 openbuf = myImport.run();
2751 owner->currentView()->setBuffer(openbuf);
2752 owner->getMiniBuffer()->Set(isnoweb ?
2753 _("Noweb file ") : _("LateX file "),
2754 MakeDisplayPath(filename),
2757 owner->getMiniBuffer()->Set(isnoweb ?
2758 _("Could not import Noweb file") :
2759 _("Could not import LaTeX file"),
2760 MakeDisplayPath(filename));
2765 void LyXFunc::MenuInsertLyXFile(string const & filen)
2767 string filename = filen;
2769 if (filename.empty()) {
2770 // Launch a file browser
2771 string initpath = lyxrc->document_path;
2774 if (owner->currentView()->available()) {
2775 string trypath = owner->currentBuffer()->filepath;
2776 // If directory is writeable, use this as default.
2777 if (IsDirWriteable(trypath) == 1)
2783 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2784 fileDlg.SetButton(1, _("Examples"),
2785 AddPath(system_lyxdir, "examples"));
2786 filename = fileDlg.Select(_("Select Document to Insert"),
2790 // check selected filename
2791 if (filename.empty()) {
2792 owner->getMiniBuffer()->Set(_("Canceled."));
2797 // get absolute path of file and make sure the filename ends
2799 filename = MakeAbsPath(filename);
2800 if (!IsLyXFilename(filename))
2804 owner->getMiniBuffer()->Set(_("Inserting document"),
2805 MakeDisplayPath(filename), "...");
2806 bool res = owner->currentBuffer()->insertLyXFile(filename);
2808 owner->getMiniBuffer()->Set(_("Document"),
2809 MakeDisplayPath(filename),
2812 owner->getMiniBuffer()->Set(_("Could not insert document"),
2813 MakeDisplayPath(filename));
2818 void LyXFunc::reloadBuffer()
2820 string fn = owner->currentBuffer()->getFileName();
2821 if (bufferlist.close(owner->currentBuffer()))
2822 owner->currentView()->setBuffer(bufferlist.loadLyXFile(fn));
2826 void LyXFunc::CloseBuffer()
2828 if (bufferlist.close(owner->currentBuffer()) && !quitting) {
2829 if (bufferlist.empty()) {
2830 // need this otherwise SEGV may occur while trying to
2831 // set variables that don't exist
2832 // since there's no current buffer
2833 CloseAllBufferRelatedPopups();
2836 owner->currentView()->setBuffer(bufferlist.first());
2842 Inset * LyXFunc::getInsetByCode(Inset::Code code)
2846 LyXCursor cursor = owner->currentBuffer()->text->cursor;
2848 LyXParagraph::size_type pos = cursor.pos;
2850 int pos = cursor.pos;
2852 LyXParagraph * par = cursor.par;
2854 while (par && !found) {
2855 while ((inset = par->ReturnNextInsetPointer(pos))){
2856 if (inset->LyxCode()==code) {
2864 return (found) ? inset: 0;
2868 // Each "owner" should have it's own message method. lyxview and
2869 // the minibuffer would use the minibuffer, but lyxserver would
2870 // send an ERROR signal to its client. Alejandro 970603
2871 // This func is bit problematic when it comes to NLS, to make the
2872 // lyx servers client be language indepenent we must not translate
2873 // strings sent to this func.
2874 void LyXFunc::setErrorMessage(string const &m)
2876 dispatch_buffer = m;
2881 void LyXFunc::setMessage(string const & m)
2883 dispatch_buffer = m;