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 * ====================================================== */
20 #pragma implementation
23 #include "lyxlookup.h"
26 #include "bufferlist.h"
27 #include "lyxserver.h"
32 #include "LyXAction.h"
34 #include "insets/insetlatex.h"
36 #include "insets/inseturl.h"
37 #include "insets/insetlatexaccent.h"
38 #include "insets/insettoc.h"
39 #include "insets/insetlof.h"
40 #include "insets/insetloa.h"
41 #include "insets/insetlot.h"
42 #include "insets/insetref.h"
43 #include "insets/insetparent.h"
44 #include "insets/insetindex.h"
45 #include "insets/insetinclude.h"
46 #include "insets/insetbib.h"
47 #include "mathed/formulamacro.h"
49 #include "spellchecker.h" // RVDK_PATCH_5
50 #include "minibuffer.h"
54 #include "lyx_gui_misc.h"
55 #include "support/filetools.h"
56 #include "support/FileInfo.h"
57 #include "support/syscall.h"
58 #include "support/lstrings.h"
59 #include "support/path.h"
60 #include "lyxscreen.h"
65 #include "trans_mgr.h"
66 #include "ImportLaTeX.h"
67 #include "ImportNoweb.h"
70 extern bool cursor_follows_scrollbar;
72 extern void InsertAsciiFile(string const &, bool);
73 extern void math_insert_symbol(char const *);
74 extern Bool math_insert_greek(char const); // why "Bool"?
75 extern BufferList bufferlist;
76 extern LyXServer * lyxserver;
77 extern short greek_kb_flag;
78 extern FD_form_toc * fd_form_toc;
79 extern bool selection_possible;
81 extern kb_keymap * toplevel_keymap;
83 extern void MenuWrite(Buffer *);
84 extern void MenuWriteAs(Buffer *);
85 extern int MenuRunLaTeX(Buffer *);
86 extern int MenuBuildProg(Buffer *);
87 extern int MenuRunChktex(Buffer *);
88 extern bool CreatePostscript(Buffer *, bool);
89 extern void MenuPrint(Buffer *);
90 extern void MenuSendto();
91 extern void QuitLyX();
92 extern void MenuFax(Buffer *);
93 extern void MenuExport(Buffer *, string const &);
94 extern void MenuPasteSelection(char at);
95 extern LyXAction lyxaction;
97 extern tex_accent_struct get_accent(kb_action action);
99 extern void AutoSave();
100 extern void MenuSearch();
101 extern void SetUpdateTimer(float timer = 0.3);
102 extern void FreeUpdateTimer();
103 extern bool PreviewDVI(Buffer *);
104 extern bool PreviewPostscript(Buffer *);
105 extern void MenuInsertLabel(char const *);
106 extern void MenuInsertRef();
107 extern void MenuLayoutCharacter();
108 extern void MenuLayoutParagraph();
109 extern void MenuLayoutDocument();
110 extern void MenuLayoutPaper();
111 extern void MenuLayoutTable(int flag);
112 extern void MenuLayoutQuotes();
113 extern void MenuLayoutPreamble();
114 extern void MenuLayoutSave();
115 extern void bulletForm();
117 extern Buffer * NewLyxFile(string const &);
118 extern void LoadLyXFile(string const &);
119 extern void Reconfigure();
121 extern int current_layout;
122 extern int getISOCodeFromLaTeX(char *);
124 //extern int UnlockInset(UpdatableInset *);
126 extern void ShowLatexLog();
128 extern void UpdateInset(Inset * inset, bool mark_dirty = true);
130 /* === globals =========================================================== */
132 bool LyXFunc::show_sc = true;
135 LyXFunc::LyXFunc(LyXView * o)
139 lyx_dead_action = LFUN_NOACTION;
140 lyx_calling_dead_action = LFUN_NOACTION;
145 // I changed this func slightly. I commented out the ...FinishUndo(),
146 // this means that all places that used to have a moveCursorUpdate, now
147 // have a ...FinishUndo() as the preceeding statement. I have also added
148 // a moveCursorUpdate to some of the functions that updated the cursor, but
149 // that did not show its new position.
151 void LyXFunc::moveCursorUpdate(bool selecting)
153 if (selecting || owner->view()->text->mark_set) {
154 owner->view()->text->SetSelection();
155 owner->view()->getScreen()->ToggleToggle();
156 owner->view()->update(0);
158 owner->view()->update(-2); // this IS necessary
162 owner->view()->getScreen()->ShowCursor();
164 /* ---> Everytime the cursor is moved, show the current font state. */
165 // should this too me moved out of this func?
166 //owner->getMiniBuffer()->Set(CurrentState());
167 owner->view()->SetState();
171 int LyXFunc::processKeyEvent(XEvent * ev)
175 XKeyEvent * keyevent = &ev->xkey;
176 KeySym keysym_return;
178 int num_bytes = LyXLookupString(ev, s_r, 10, &keysym_return);
179 s_r[num_bytes] = '\0';
181 if (lyxerr.debugging(Debug::KEY)) {
182 char * tmp = XKeysymToString(keysym_return);
183 string stm = (tmp ? tmp : "");
184 lyxerr << "KeySym is "
187 << keysym_return << "]"
188 << " and num_bytes is "
190 << " the string returned is \""
191 << s_r << '\"' << endl;
193 // Do nothing if we have nothing (JMarc)
194 if (num_bytes == 0 && keysym_return == NoSymbol) {
195 lyxerr[Debug::KEY] << "Empty kbd action (probably composing)"
200 // this function should be used always [asierra060396]
201 if (owner->view()->available() &&
202 owner->view()->the_locking_inset &&
203 keysym_return == XK_Escape) {
204 owner->view()->unlockInset(owner->view()->the_locking_inset);
205 owner->view()->text->CursorRight();
206 moveCursorUpdate(false);
207 owner->getMiniBuffer()->Set(CurrentState());
211 // Can we be sure that this will work for all X-Windows
212 // implementations? (Lgb)
213 // This code snippet makes lyx ignore some keys. Perhaps
214 // all of them should be explictly mentioned?
215 if((keysym_return >= XK_Shift_L && keysym_return <= XK_Hyper_R)
216 || keysym_return == XK_Mode_switch || keysym_return == 0x0)
219 // Do a one-deep top-level lookup for
220 // cancel and meta-fake keys. RVDK_PATCH_5
221 cancel_meta_seq.reset();
223 int action = cancel_meta_seq.addkey(keysym_return, keyevent->state
224 &(ShiftMask|ControlMask
227 // When not cancel or meta-fake, do the normal lookup.
228 // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
229 // Mostly, meta_fake_bit = 0. RVDK_PATCH_5.
230 if ( (action != LFUN_CANCEL) && (action != LFUN_META_FAKE) ) {
232 // remove Caps Lock and Mod2 as a modifiers
233 action = keyseq.addkey(keysym_return,
234 (keyevent->state | meta_fake_bit)
235 &(ShiftMask|ControlMask
238 // Dont remove this unless you know what you are doing.
241 if (action == 0) action = LFUN_PREFIX;
243 if (lyxerr.debugging(Debug::KEY)) {
249 << num_bytes << "]" << endl;
252 // already here we know if it any point in going further
253 // why not return already here if action == -1 and
254 // num_bytes == 0? (Lgb)
256 if(keyseq.length > 1 || keyseq.length < -1){
259 owner->getMiniBuffer()->Set(buf);
263 if (keyseq.length < -1) { // unknown key sequence...
267 owner->getMiniBuffer()->Set(_("Unknown sequence:"), buf);
271 char isochar = keyseq.getiso();
272 if (!(keyevent->state&ControlMask) &&
273 !(keyevent->state&Mod1Mask) &&
274 (isochar && keysym_return < 0xF000)) {
277 if (argument.empty()) {
278 lyxerr.debug() << "Empty argument!" << endl;
279 // This can`t possibly be of any use
280 // so we`ll skip the dispatch.
284 if (action == LFUN_SELFINSERT) {
288 bool tmp_sc = show_sc;
290 Dispatch(action, argument.c_str());
297 LyXFunc::func_status LyXFunc::getStatus(int ac) const
300 func_status flag = LyXFunc::OK;
302 Buffer * buf = owner->buffer();
304 if (lyxaction.isPseudoAction(ac))
305 action = lyxaction.retrieveActionArg(ac, argument);
307 action = static_cast<kb_action>(ac);
309 if (action == LFUN_UNKNOWN_ACTION) {
310 setErrorMessage(N_("Unknown action"));
311 return LyXFunc::Unknown;
314 // Check whether we need a buffer
315 if (!lyxaction.funcHasFlag(action, LyXAction::NoBuffer)) {
316 // Yes we need a buffer, do we have one?
319 // Can we use a readonly buffer?
320 if (buf->isReadonly() &&
321 !lyxaction.funcHasFlag(action,
322 LyXAction::ReadOnly)) {
324 setErrorMessage(N_("Document is read-only"));
325 flag |= LyXFunc::Disabled;
329 setErrorMessage(N_("Command not allowed with"
330 "out any document open"));
331 flag |= LyXFunc::Disabled;
335 if (flag & LyXFunc::Disabled)
338 // I would really like to avoid having this switch and rather try to
339 // encode this in the function itself.
340 static bool noLaTeX = lyxrc->latex_command == "none";
341 bool disable = false;
344 disable = noLaTeX || lyxrc->view_dvi_command == "none";
347 disable = noLaTeX || lyxrc->view_ps_command == "none";
354 disable = noLaTeX || lyxrc->print_command == "none";
357 disable = noLaTeX || lyxrc->fax_command == "none";
360 if (argument == "latex")
361 disable = lyxrc->relyx_command == "none";
364 if (argument == "dvi" || argument == "postscript")
366 if (argument == "html")
367 disable = lyxrc->html_command == "none";
370 disable = buf->undostack.empty();
373 disable = buf->redostack.empty();
375 case LFUN_SPELLCHECK:
376 disable = lyxrc->isp_command == "none";
379 disable = lyxrc->chktex_command == "none";
381 case LFUN_LAYOUT_TABLE:
382 disable = ! owner->view()->text->cursor.par->table;
388 flag |= LyXFunc::Disabled;
391 func_status box = LyXFunc::ToggleOff;
392 LyXFont font = owner->view()->text->real_current_font;
395 if (font.emph() == LyXFont::ON)
396 box = LyXFunc::ToggleOn;
399 if (font.noun() == LyXFont::ON)
400 box = LyXFunc::ToggleOn;
403 if (font.series() == LyXFont::BOLD_SERIES)
404 box = LyXFunc::ToggleOn;
407 if (font.latex() == LyXFont::ON)
408 box = LyXFunc::ToggleOn;
411 if (font.direction() == LyXFont::RTL_DIR)
412 box = LyXFunc::ToggleOn;
425 string LyXFunc::Dispatch(string const & s)
427 // Split command string into command and argument
428 string cmd, line = frontStrip(s);
429 string arg = strip(frontStrip(split(line, cmd, ' ')));
431 return Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
435 string LyXFunc::Dispatch(int ac,
436 char const * do_not_use_this_arg)
441 FL_OBJECT * ob = 0; // This will disapear soon
443 // we have not done anything wrong yet.
445 dispatch_buffer.clear();
447 // if action is a pseudo-action, we need the real action
448 if (lyxaction.isPseudoAction(ac)) {
450 action = static_cast<kb_action>
451 (lyxaction.retrieveActionArg(ac, tmparg));
455 action = static_cast<kb_action>(ac);
456 if (do_not_use_this_arg)
457 argument = do_not_use_this_arg; // except here
460 selection_possible = false;
462 if (owner->view()->available()
463 && owner->view()->getScreen())
464 owner->view()->getScreen()->HideCursor();
466 // We cannot use this function here
467 if (getStatus(action) & Disabled)
468 goto exit_with_message;
470 commandshortcut.clear();
472 if (lyxrc->display_shortcuts && show_sc) {
473 if (action != LFUN_SELFINSERT) {
474 // Put name of command and list of shortcuts
475 // for it in minibuffer
476 string comname = lyxaction.getActionName(action);
478 int pseudoaction = action;
479 bool argsadded = false;
481 if (!argument.empty()) {
482 // If we have the command with argument,
485 lyxaction.searchActionArg(action,
488 if (pseudoaction == -1) {
489 pseudoaction = action;
491 comname += " " + argument;
496 string shortcuts = toplevel_keymap->findbinding(pseudoaction);
498 if (!shortcuts.empty()) {
499 comname += ": " + shortcuts;
500 } else if (!argsadded) {
501 comname += " " + argument;
504 if (!comname.empty()) {
505 comname = strip(comname);
506 commandshortcut = "(" + comname + ')';
507 owner->getMiniBuffer()->Set(commandshortcut);
508 // Here we could even add a small pause,
509 // to annoy the user and make him learn
511 // No! That will just annoy, not teach
512 // anything. The user will read the messages
513 // if they are interested. (Asger)
518 // If in math mode pass the control to
519 // the math inset [asierra060396]
520 if (owner->view()->available() &&
521 owner->view()->the_locking_inset) {
523 || (action == LFUN_UNKNOWN_ACTION
524 && keyseq.length >= -1)) {
525 if (action == LFUN_UNKNOWN_ACTION
526 && argument.empty()) {
527 argument = keyseq.getiso();
529 // Undo/Redo pre 0.13 is a bit tricky for insets.
530 if (action == LFUN_UNDO) {
532 UpdatableInset * inset =
533 owner->view()->the_locking_inset;
534 inset->GetCursorPos(slx, sly);
535 owner->view()->unlockInset(inset);
536 owner->view()->menuUndo();
537 inset = static_cast<UpdatableInset*>(owner->view()->text->cursor.par->GetInset(owner->view()->text->cursor.pos));
539 inset->Edit(slx, sly);
542 if (action == LFUN_REDO) {
544 UpdatableInset * inset = owner->view()->the_locking_inset;
545 inset->GetCursorPos(slx, sly);
546 owner->view()->unlockInset(inset);
547 owner->view()->menuRedo();
548 inset = static_cast<UpdatableInset*>(owner->view()->text->cursor.par->GetInset(owner->view()->text->cursor.pos));
550 inset->Edit(slx, sly);
553 if (owner->view()->the_locking_inset->LocalDispatch(action, argument.c_str()))
556 setMessage(N_("Text mode"));
557 LyXDirection direction = owner->view()->text->GetParDirection(owner->view()->text->cursor.par);
559 (action == LFUN_RIGHT
560 && direction == LYX_DIR_LEFT_TO_RIGHT)) {
561 owner->view()->text->CursorRight();
562 moveCursorUpdate(false);
563 owner->getMiniBuffer()->Set(CurrentState());
565 if ( action == LFUN_LEFT
566 && direction == LYX_DIR_RIGHT_TO_LEFT) {
567 owner->view()->text->CursorRight();
568 moveCursorUpdate(false);
569 owner->getMiniBuffer()->Set(CurrentState());
571 if (action == LFUN_LEFT || action == LFUN_RIGHT)
578 // --- Misc -------------------------------------------
579 case LFUN_WORDFINDFORWARD :
580 case LFUN_WORDFINDBACKWARD : {
581 static string last_search;
582 string searched_string;
584 if (!argument.empty()) {
585 last_search = argument;
586 searched_string = argument;
588 searched_string = last_search;
591 LyXText * ltCur = owner->view()->text ;
593 if (!searched_string.empty() &&
594 ((action == LFUN_WORDFINDBACKWARD) ?
595 ltCur->SearchBackward(searched_string.c_str()) :
596 ltCur->SearchForward(searched_string.c_str()))) {
598 // ??? What is that ???
599 owner->view()->update(-2);
602 // clear the selection (if there is any)
603 owner->view()->getScreen()->ToggleSelection();
604 owner->view()->text->ClearSelection();
606 // Move cursor so that successive C-s 's will not stand in place.
607 if( action == LFUN_WORDFINDFORWARD )
608 owner->view()->text->CursorRightOneWord();
609 owner->view()->text->FinishUndo();
610 moveCursorUpdate(false);
613 // set the new selection
614 // SetSelectionOverLenChars(owner->view()->currentBuffer()->text, iLenSelected);
615 owner->view()->getScreen()->ToggleSelection(false);
619 // REMOVED : if (owner->view()->getWorkArea()->focus)
620 owner->view()->getScreen()->ShowCursor();
626 if (owner->view()->available()
627 && owner->view()->getScreen()) {
628 owner->view()->update(-2);
631 keyseq.print(buf, true);
632 owner->getMiniBuffer()->Set(buf, string(), string(), 1);
636 // --- Misc -------------------------------------------
637 case LFUN_EXEC_COMMAND:
638 owner->getMiniBuffer()->ExecCommand();
641 case LFUN_CANCEL: // RVDK_PATCH_5
644 if(owner->view()->available())
645 // cancel any selection
646 Dispatch(LFUN_MARK_OFF, 0);
647 setMessage(N_("Cancel"));
650 case LFUN_META_FAKE: // RVDK_PATCH_5
652 meta_fake_bit = Mod1Mask;
654 keyseq.print(buf, true);
655 string res = string("M-") + buf;
656 setMessage(buf); // RVDK_PATCH_5
660 case LFUN_READ_ONLY_TOGGLE:
661 if (owner->buffer()->lyxvc.inUse()) {
662 owner->buffer()->lyxvc.toggleReadOnly();
664 owner->buffer()->setReadonly(
665 !owner->buffer()->isReadonly());
669 case LFUN_CENTER: // this is center and redraw.
670 owner->view()->beforeChange();
671 if (owner->view()->text->cursor.y >
672 owner->view()->getWorkArea()->h / 2) {
673 owner->view()->getScreen()->
674 Draw(owner->view()->text->cursor.y -
675 owner->view()->getWorkArea()->h / 2);
677 owner->view()->getScreen()->
680 owner->view()->update(0);
681 owner->view()->redraw();
685 if (owner->view()->available()) {
686 owner->view()->text->toggleAppendix();
687 owner->view()->update(1);
691 // --- Menus -----------------------------------------------
696 case LFUN_MENUNEWTMPLT:
704 case LFUN_CLOSEBUFFER:
709 MenuWrite(owner->buffer());
712 case LFUN_MENUWRITEAS:
713 MenuWriteAs(owner->buffer());
716 case LFUN_MENURELOAD:
721 PreviewDVI(owner->buffer());
725 PreviewPostscript(owner->buffer());
729 MenuRunLaTeX(owner->buffer());
733 MenuBuildProg(owner->buffer());
737 MenuRunChktex(owner->buffer());
741 CreatePostscript(owner->buffer(), false);
745 MenuPrint(owner->buffer());
749 MenuFax(owner->buffer());
753 MenuExport(owner->buffer(), argument);
758 //needs argument as string
759 string imtyp = argument;
762 if (imtyp == "latex") {
763 doImportLaTeX(false);
766 else if (imtyp == "ascii") {
767 doImportASCII(false);
768 } else if (imtyp == "asciiparagraph") {
771 } else if (imtyp == "noweb") {
774 setErrorMessage(string(N_("Unknown import type: "))
786 if (fd_form_toc->form_toc->visible) {
787 fl_raise_form(fd_form_toc->form_toc);
789 static int ow = -1, oh;
790 fl_show_form(fd_form_toc->form_toc,
792 FL_FREE_SIZE, FL_FULLBORDER,
793 _("Table of Contents"));
795 ow = fd_form_toc->form_toc->w;
796 oh = fd_form_toc->form_toc->h;
798 fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
802 case LFUN_TOC_INSERT:
804 Inset * new_inset = new InsetTOC(owner->buffer());
805 owner->view()->insertInset(new_inset, "Standard", true);
809 case LFUN_LOF_INSERT:
811 Inset * new_inset = new InsetLOF(owner->buffer());
812 owner->view()->insertInset(new_inset, "Standard", true);
816 case LFUN_LOA_INSERT:
818 Inset * new_inset = new InsetLOA(owner->buffer());
819 owner->view()->insertInset(new_inset, "Standard", true);
823 case LFUN_LOT_INSERT:
825 Inset * new_inset = new InsetLOT(owner->buffer());
826 owner->view()->insertInset(new_inset, "Standard", true);
843 owner->view()->menuUndo();
847 owner->view()->menuRedo();
850 case LFUN_MENUSEARCH:
855 owner->view()->paste();
858 case LFUN_PASTESELECTION:
861 if (argument == "paragraph") asPara = true;
862 MenuPasteSelection(asPara);
867 owner->view()->cut();
871 owner->view()->copy();
874 case LFUN_LAYOUT_COPY:
875 owner->view()->copyEnvironment();
878 case LFUN_LAYOUT_PASTE:
879 owner->view()->pasteEnvironment();
883 owner->view()->gotoError();
886 case LFUN_REMOVEERRORS:
887 if (owner->view()->removeAutoInsets()) {
888 owner->view()->redraw();
889 owner->view()->fitCursor();
890 owner->view()->updateScrollbar();
895 owner->view()->gotoNote();
899 owner->view()->openStuff();
902 case LFUN_HYPHENATION:
903 owner->view()->hyphenationPoint();
907 owner->view()->ldots();
910 case LFUN_END_OF_SENTENCE:
911 owner->view()->endOfSentenceDot();
914 case LFUN_MENU_SEPARATOR:
915 owner->view()->menuSeparator();
919 owner->view()->hfill();
930 case LFUN_DEPTH_PLUS:
940 owner->view()->SetState();
941 owner->getMiniBuffer()->Set(CurrentState());
948 case LFUN_RECONFIGURE:
953 if (owner->view()->available()
954 && !owner->view()->text->selection
955 && owner->view()->text->cursor.par->footnoteflag
956 != LyXParagraph::NO_FOOTNOTE)
957 { // only melt footnotes with FOOTMELT, not margins etc
958 if(owner->view()->text->cursor.par->footnotekind == LyXParagraph::FOOTNOTE)
963 owner->view()->SetState();
966 case LFUN_MARGINMELT:
967 if (owner->view()->available()
968 && !owner->view()->text->selection
969 && owner->view()->text->cursor.par->footnoteflag
970 != LyXParagraph::NO_FOOTNOTE) {
972 if(owner->view()->text->cursor.par->footnotekind == LyXParagraph::MARGIN)
977 owner->view()->SetState();
980 // --- version control -------------------------------
981 case LFUN_VC_REGISTER:
983 if (!owner->buffer()->lyxvc.inUse())
984 owner->buffer()->lyxvc.registrer();
988 case LFUN_VC_CHECKIN:
990 if (owner->buffer()->lyxvc.inUse()
991 && !owner->buffer()->isReadonly())
992 owner->buffer()->lyxvc.checkIn();
996 case LFUN_VC_CHECKOUT:
998 if (owner->buffer()->lyxvc.inUse()
999 && owner->buffer()->isReadonly())
1000 owner->buffer()->lyxvc.checkOut();
1004 case LFUN_VC_REVERT:
1006 owner->buffer()->lyxvc.revert();
1012 owner->buffer()->lyxvc.undoLast();
1016 case LFUN_VC_HISTORY:
1018 owner->buffer()->lyxvc.showLog();
1022 // --- buffers ----------------------------------------
1023 case LFUN_PREVBUFFER:
1024 #ifdef WITH_WARNINGS
1025 #warning fix this please
1027 // it is the LyXView or the BufferView that should
1028 // remember the previous buffer, not bufferlist.
1029 // if (owner->view()->available()){
1030 // owner->view()->beforeChange();
1031 // owner->buffer()->update(-2);
1033 // owner->view()->setBuffer(bufferlist.prev());
1036 // resizeCurrentBufferPseudoExpose();
1039 case LFUN_FILE_INSERT:
1041 MenuInsertLyXFile(argument);
1045 case LFUN_FILE_INSERT_ASCII:
1047 bool asPara = (argument == "paragraph");
1048 InsertAsciiFile(string(), asPara);
1054 // servercmd: argument must be <file>:<template>
1055 Buffer * tmpbuf = NewLyxFile(argument);
1057 owner->view()->buffer(tmpbuf);
1061 case LFUN_FILE_OPEN:
1062 owner->view()->buffer(bufferlist.loadLyXFile(argument));
1065 case LFUN_LATEX_LOG:
1071 lyxerr.debug() << "LFUN_LAYOUTNO: (arg) " << argument << endl;
1072 int sel = strToInt(argument);
1073 lyxerr.debug() << "LFUN_LAYOUTNO: (sel) "<< sel << endl;
1075 // Should this give a setMessage instead?
1077 return string(); // illegal argument
1079 --sel; // sel 1..., but layout 0...
1081 // Pretend we got the name instead.
1082 Dispatch(int(LFUN_LAYOUT),
1083 textclasslist.NameOfLayout(owner->view()->
1092 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1093 << argument << endl;
1095 // Derive layout number from given argument (string)
1096 // and current buffer's textclass (number). */
1098 textclasslist.NumberOfLayout(owner->
1104 // see if we found the layout number:
1105 if (layoutno == -1) {
1106 setErrorMessage(string(N_("Layout ")) + argument +
1111 if (current_layout != layoutno) {
1112 owner->view()->getScreen()->HideCursor();
1113 current_layout = layoutno;
1114 owner->view()->update(-2);
1115 owner->view()->text->
1116 SetLayout(layoutno);
1117 owner->getToolbar()->combox->
1118 select(owner->view()->
1121 owner->view()->update(1);
1126 case LFUN_LAYOUT_DOCUMENT:
1127 MenuLayoutDocument();
1130 case LFUN_LAYOUT_PARAGRAPH:
1131 MenuLayoutParagraph();
1134 case LFUN_LAYOUT_CHARACTER:
1135 MenuLayoutCharacter();
1138 case LFUN_LAYOUT_TABLE:
1141 if (argument == "true") flag = 1;
1142 MenuLayoutTable(flag);
1146 case LFUN_LAYOUT_PAPER:
1150 case LFUN_LAYOUT_QUOTES:
1154 case LFUN_LAYOUT_PREAMBLE:
1155 MenuLayoutPreamble();
1158 case LFUN_LAYOUT_SAVE_DEFAULT:
1162 case LFUN_DROP_LAYOUTS_CHOICE:
1163 owner->getToolbar()->combox->Show();
1169 owner->view()->SetState();
1170 owner->getMiniBuffer()->Set(CurrentState());
1202 case LFUN_UNDERLINE:
1206 case LFUN_FONT_SIZE:
1207 FontSizeCB(argument);
1210 case LFUN_FONT_STATE:
1211 setMessage(CurrentState());
1214 case LFUN_UPCASE_WORD:
1215 owner->view()->update(-2);
1217 owner->view()->text->ChangeWordCase(LyXText::text_uppercase);
1218 owner->view()->update(1);
1222 case LFUN_LOWCASE_WORD:
1223 owner->view()->update(-2);
1225 owner->view()->text->ChangeWordCase(LyXText::text_lowercase);
1226 owner->view()->update(1);
1230 case LFUN_CAPITALIZE_WORD:
1231 owner->view()->update(-2);
1233 owner->view()->text->ChangeWordCase(LyXText::text_capitalization);
1234 owner->view()->update(1);
1238 case LFUN_INSERT_LABEL:
1239 MenuInsertLabel(argument.c_str());
1242 case LFUN_INSERT_REF:
1246 case LFUN_REFTOGGLE:
1249 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1251 if (inset->getFlag() == InsetRef::REF)
1252 inset->setFlag(InsetRef::PAGE_REF);
1254 inset->setFlag(InsetRef::REF);
1257 setErrorMessage(N_("No cross-reference to toggle"));
1264 owner->view()->restorePosition();
1270 string label(argument);
1271 if (label.empty()) {
1273 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1275 label = inset->getContents();
1278 if (!label.empty()) {
1279 owner->view()->savePosition();
1280 owner->view()->gotoLabel(label.c_str());
1285 case LFUN_MENU_OPEN_BY_NAME:
1286 owner->getMenus()->openByName(argument);
1287 break; // RVDK_PATCH_5
1289 case LFUN_SPELLCHECK:
1290 if (lyxrc->isp_command != "none")
1292 break; // RVDK_PATCH_5
1294 // --- Cursor Movements -----------------------------
1297 LyXText * tmptext = owner->view()->text;
1298 LyXDirection direction = tmptext->GetParDirection(tmptext->cursor.par);
1299 if(!tmptext->mark_set)
1300 owner->view()->beforeChange();
1301 owner->view()->update(-2);
1302 if (direction == LYX_DIR_RIGHT_TO_LEFT)
1303 tmptext->CursorLeft();
1304 if (tmptext->cursor.pos < tmptext->cursor.par->Last()
1305 && tmptext->cursor.par->GetChar(tmptext->cursor.pos)
1306 == LyXParagraph::META_INSET
1307 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)
1308 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)->Editable() == 2){
1309 Inset * tmpinset = tmptext->cursor.par->GetInset(tmptext->cursor.pos);
1310 setMessage(tmpinset->EditMessage());
1311 tmpinset->Edit(0, 0);
1314 if (direction == LYX_DIR_LEFT_TO_RIGHT)
1315 tmptext->CursorRight();
1316 owner->view()->text->FinishUndo();
1317 moveCursorUpdate(false);
1318 owner->getMiniBuffer()->Set(CurrentState());
1324 // This is soooo ugly. Isn`t it possible to make
1325 // it simpler? (Lgb)
1326 LyXText * txt = owner->view()->text;
1327 LyXDirection direction = txt->GetParDirection(txt->cursor.par);
1328 if(!txt->mark_set) owner->view()->beforeChange();
1329 owner->view()->update(-2);
1330 if (direction == LYX_DIR_LEFT_TO_RIGHT)
1332 if (txt->cursor.pos < txt->cursor.par->Last()
1333 && txt->cursor.par->GetChar(txt->cursor.pos)
1334 == LyXParagraph::META_INSET
1335 && txt->cursor.par->GetInset(txt->cursor.pos)
1336 && txt->cursor.par->GetInset(txt->cursor.pos)->Editable() == 2) {
1337 Inset * tmpinset = txt->cursor.par->GetInset(txt->cursor.pos);
1338 setMessage(tmpinset->EditMessage());
1339 tmpinset->Edit(tmpinset->Width(txt->GetFont(txt->cursor.par,
1340 txt->cursor.pos)), 0);
1343 if (direction == LYX_DIR_RIGHT_TO_LEFT)
1346 owner->view()->text->FinishUndo();
1347 moveCursorUpdate(false);
1348 owner->getMiniBuffer()->Set(CurrentState());
1353 if(!owner->view()->text->mark_set) owner->view()->beforeChange();
1354 owner->view()->update(-3);
1355 owner->view()->text->CursorUp();
1356 owner->view()->text->FinishUndo();
1357 moveCursorUpdate(false);
1358 owner->getMiniBuffer()->Set(CurrentState());
1362 if(!owner->view()->text->mark_set)
1363 owner->view()->beforeChange();
1364 owner->view()->update(-3);
1365 owner->view()->text->CursorDown();
1366 owner->view()->text->FinishUndo();
1367 moveCursorUpdate(false);
1368 owner->getMiniBuffer()->Set(CurrentState());
1371 case LFUN_UP_PARAGRAPH:
1372 if(!owner->view()->text->mark_set)
1373 owner->view()->beforeChange();
1374 owner->view()->update(-3);
1375 owner->view()->text->CursorUpParagraph();
1376 owner->view()->text->FinishUndo();
1377 moveCursorUpdate(false);
1378 owner->getMiniBuffer()->Set(CurrentState());
1381 case LFUN_DOWN_PARAGRAPH:
1382 if(!owner->view()->text->mark_set)
1383 owner->view()->beforeChange();
1384 owner->view()->update(-3);
1385 owner->view()->text->CursorDownParagraph();
1386 owner->view()->text->FinishUndo();
1387 moveCursorUpdate(false);
1388 owner->getMiniBuffer()->Set(CurrentState());
1392 if(!owner->view()->text->mark_set)
1393 owner->view()->beforeChange();
1394 owner->view()->update(-3);
1395 owner->view()->cursorPrevious();
1396 owner->view()->text->FinishUndo();
1397 moveCursorUpdate(false);
1398 owner->getMiniBuffer()->Set(CurrentState());
1402 if(!owner->view()->text->mark_set)
1403 owner->view()->beforeChange();
1404 owner->view()->update(-3);
1405 owner->view()->cursorNext();
1406 owner->view()->text->FinishUndo();
1407 moveCursorUpdate(false);
1408 owner->getMiniBuffer()->Set(CurrentState());
1412 if(!owner->view()->text->mark_set)
1413 owner->view()->beforeChange();
1414 owner->view()->update(-2);
1415 owner->view()->text->CursorHome();
1416 owner->view()->text->FinishUndo();
1417 moveCursorUpdate(false);
1418 owner->getMiniBuffer()->Set(CurrentState());
1422 if(!owner->view()->text->mark_set)
1423 owner->view()->beforeChange();
1424 owner->view()->update(-2);
1425 owner->view()->text->CursorEnd();
1426 owner->view()->text->FinishUndo();
1427 moveCursorUpdate(false);
1428 owner->getMiniBuffer()->Set(CurrentState());
1432 if(!owner->view()->text->mark_set)
1433 owner->view()->beforeChange();
1434 owner->view()->update(-2);
1435 owner->view()->text->CursorTab();
1436 owner->view()->text->FinishUndo();
1437 moveCursorUpdate(false);
1438 owner->getMiniBuffer()->Set(CurrentState());
1441 case LFUN_WORDRIGHT:
1442 if(!owner->view()->text->mark_set)
1443 owner->view()->beforeChange();
1444 owner->view()->update(-2);
1445 if (owner->view()->text->GetParDirection(owner->view()->text->cursor.par)
1446 == LYX_DIR_LEFT_TO_RIGHT)
1447 owner->view()->text->CursorRightOneWord();
1449 owner->view()->text->CursorLeftOneWord();
1450 owner->view()->text->FinishUndo();
1451 moveCursorUpdate(false);
1452 owner->getMiniBuffer()->Set(CurrentState());
1456 if(!owner->view()->text->mark_set)
1457 owner->view()->beforeChange();
1458 owner->view()->update(-2);
1459 if (owner->view()->text->GetParDirection(owner->view()->text->cursor.par)
1460 == LYX_DIR_LEFT_TO_RIGHT)
1461 owner->view()->text->CursorLeftOneWord();
1463 owner->view()->text->CursorRightOneWord();
1464 owner->view()->text->FinishUndo();
1465 moveCursorUpdate(false);
1466 owner->getMiniBuffer()->Set(CurrentState());
1469 case LFUN_BEGINNINGBUF:
1470 if(!owner->view()->text->mark_set)
1471 owner->view()->beforeChange();
1472 owner->view()->update(-2);
1473 owner->view()->text->CursorTop();
1474 owner->view()->text->FinishUndo();
1475 moveCursorUpdate(false);
1476 owner->getMiniBuffer()->Set(CurrentState());
1480 if(!owner->view()->text->mark_set)
1481 owner->view()->beforeChange();
1482 owner->view()->update(-2);
1483 owner->view()->text->CursorBottom();
1484 owner->view()->text->FinishUndo();
1485 moveCursorUpdate(false);
1486 owner->getMiniBuffer()->Set(CurrentState());
1490 /* cursor selection ---------------------------- */
1492 owner->view()->update(-2);
1493 if (owner->view()->text->GetParDirection(owner->view()->text->cursor.par)
1494 == LYX_DIR_LEFT_TO_RIGHT)
1495 owner->view()->text->CursorRight();
1497 owner->view()->text->CursorLeft();
1498 owner->view()->text->FinishUndo();
1499 moveCursorUpdate(true);
1500 owner->getMiniBuffer()->Set(CurrentState());
1504 owner->view()->update(-2);
1505 if (owner->view()->text->GetParDirection(owner->view()->text->cursor.par)
1506 == LYX_DIR_LEFT_TO_RIGHT)
1507 owner->view()->text->CursorLeft();
1509 owner->view()->text->CursorRight();
1510 owner->view()->text->FinishUndo();
1511 moveCursorUpdate(true);
1512 owner->getMiniBuffer()->Set(CurrentState());
1516 owner->view()->update(-2);
1517 owner->view()->text->CursorUp();
1518 owner->view()->text->FinishUndo();
1519 moveCursorUpdate(true);
1520 owner->getMiniBuffer()->Set(CurrentState());
1524 owner->view()->update(-2);
1525 owner->view()->text->CursorDown();
1526 owner->view()->text->FinishUndo();
1527 moveCursorUpdate(true);
1528 owner->getMiniBuffer()->Set(CurrentState());
1531 case LFUN_UP_PARAGRAPHSEL:
1532 owner->view()->update(-2);
1533 owner->view()->text->CursorUpParagraph();
1534 owner->view()->text->FinishUndo();
1535 moveCursorUpdate(true);
1536 owner->getMiniBuffer()->Set(CurrentState());
1539 case LFUN_DOWN_PARAGRAPHSEL:
1540 owner->view()->update(-2);
1541 owner->view()->text->CursorDownParagraph();
1542 owner->view()->text->FinishUndo();
1543 moveCursorUpdate(true);
1544 owner->getMiniBuffer()->Set(CurrentState());
1548 owner->view()->update(-2);
1549 owner->view()->cursorPrevious();
1550 owner->view()->text->FinishUndo();
1551 moveCursorUpdate(true);
1552 owner->getMiniBuffer()->Set(CurrentState());
1556 owner->view()->update(-2);
1557 owner->view()->cursorNext();
1558 owner->view()->text->FinishUndo();
1559 moveCursorUpdate(true);
1560 owner->getMiniBuffer()->Set(CurrentState());
1564 owner->view()->update(-2);
1565 owner->view()->text->CursorHome();
1566 owner->view()->text->FinishUndo();
1567 moveCursorUpdate(true);
1568 owner->getMiniBuffer()->Set(CurrentState());
1572 owner->view()->update(-2);
1573 owner->view()->text->CursorEnd();
1574 owner->view()->text->FinishUndo();
1575 moveCursorUpdate(true);
1576 owner->getMiniBuffer()->Set(CurrentState());
1579 case LFUN_WORDRIGHTSEL:
1580 owner->view()->update(-2);
1581 if (owner->view()->text->GetParDirection(owner->view()->text->cursor.par)
1582 == LYX_DIR_LEFT_TO_RIGHT)
1583 owner->view()->text->CursorRightOneWord();
1585 owner->view()->text->CursorLeftOneWord();
1586 owner->view()->text->FinishUndo();
1587 moveCursorUpdate(true);
1588 owner->getMiniBuffer()->Set(CurrentState());
1591 case LFUN_WORDLEFTSEL:
1592 owner->view()->update(-2);
1593 if (owner->view()->text->GetParDirection(owner->view()->text->cursor.par)
1594 == LYX_DIR_LEFT_TO_RIGHT)
1595 owner->view()->text->CursorLeftOneWord();
1597 owner->view()->text->CursorRightOneWord();
1598 owner->view()->text->FinishUndo();
1599 moveCursorUpdate(true);
1600 owner->getMiniBuffer()->Set(CurrentState());
1603 case LFUN_BEGINNINGBUFSEL:
1604 owner->view()->update(-2);
1605 owner->view()->text->CursorTop();
1606 owner->view()->text->FinishUndo();
1607 moveCursorUpdate(true);
1608 owner->getMiniBuffer()->Set(CurrentState());
1611 case LFUN_ENDBUFSEL:
1612 owner->view()->update(-2);
1613 owner->view()->text->CursorBottom();
1614 owner->view()->text->FinishUndo();
1615 moveCursorUpdate(true);
1616 owner->getMiniBuffer()->Set(CurrentState());
1619 // --- text changing commands ------------------------
1620 case LFUN_BREAKLINE:
1621 owner->view()->beforeChange();
1622 owner->view()->text->InsertChar(LyXParagraph::META_NEWLINE);
1623 owner->view()->smallUpdate(1);
1624 SetUpdateTimer(0.01);
1625 moveCursorUpdate(false);
1628 case LFUN_PROTECTEDSPACE:
1629 owner->view()->beforeChange();
1630 owner->view()->text->
1631 InsertChar(LyXParagraph::META_PROTECTED_SEPARATOR);
1632 owner->view()->smallUpdate(1);
1634 moveCursorUpdate(false);
1638 if(owner->view()->text->mark_set) {
1639 owner->view()->beforeChange();
1640 owner->view()->update(0);
1641 setMessage(N_("Mark removed"));
1643 owner->view()->beforeChange();
1644 owner->view()->text->mark_set = 1;
1645 owner->view()->update(0);
1646 setMessage(N_("Mark set"));
1648 owner->view()->text->sel_cursor =
1649 owner->view()->text->cursor;
1654 if (!owner->view()->text->selection) {
1655 owner->view()->text->Delete();
1656 owner->view()->text->sel_cursor =
1657 owner->view()->text->cursor;
1658 owner->view()->smallUpdate(1);
1659 // It is possible to make it a lot faster still
1660 // just comment out the lone below...
1661 owner->view()->getScreen()->ShowCursor();
1663 owner->view()->cut();
1666 moveCursorUpdate(false);
1667 owner->getMiniBuffer()->Set(CurrentState());
1668 owner->view()->SetState();
1671 case LFUN_DELETE_SKIP:
1673 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1675 LyXCursor cursor = owner->view()->text->cursor;
1678 if (!owner->view()->text->selection) {
1679 if (cursor.pos == cursor.par->Last()) {
1680 owner->view()->text->CursorRight();
1681 cursor = owner->view()->text->cursor;
1683 && !(cursor.par->added_space_top
1684 == VSpace (VSpace::NONE))) {
1685 owner->view()->text->SetParagraph
1686 (cursor.par->line_top,
1687 cursor.par->line_bottom,
1688 cursor.par->pagebreak_top,
1689 cursor.par->pagebreak_bottom,
1690 VSpace(VSpace::NONE),
1691 cursor.par->added_space_bottom,
1693 cursor.par->labelwidthstring, 0);
1694 owner->view()->text->CursorLeft();
1695 owner->view()->update (1);
1697 owner->view()->text->CursorLeft();
1698 owner->view()->text->Delete();
1699 owner->view()->text->sel_cursor =
1700 owner->view()->text->cursor;
1701 owner->view()->smallUpdate(1);
1704 owner->view()->text->Delete();
1705 owner->view()->text->sel_cursor =
1706 owner->view()->text->cursor;
1707 owner->view()->smallUpdate(1);
1710 owner->view()->cut();
1716 /* -------> Delete word forward. */
1717 case LFUN_DELETE_WORD_FORWARD:
1718 owner->view()->update(-2);
1720 owner->view()->text->DeleteWordForward();
1721 owner->view()->update( 1 );
1723 moveCursorUpdate(false);
1724 owner->getMiniBuffer()->Set(CurrentState());
1727 /* -------> Delete word backward. */
1728 case LFUN_DELETE_WORD_BACKWARD:
1729 owner->view()->update(-2);
1731 owner->view()->text->DeleteWordBackward();
1732 owner->view()->update( 1 );
1734 moveCursorUpdate(false);
1735 owner->getMiniBuffer()->Set(CurrentState());
1738 /* -------> Kill to end of line. */
1739 case LFUN_DELETE_LINE_FORWARD:
1741 owner->view()->update(-2);
1742 owner->view()->text->DeleteLineForward();
1743 owner->view()->update( 1 );
1745 moveCursorUpdate(false);
1748 /* -------> Set mark off. */
1750 owner->view()->beforeChange();
1751 owner->view()->update(0);
1752 owner->view()->text->sel_cursor =
1753 owner->view()->text->cursor;
1754 setMessage(N_("Mark off"));
1757 /* -------> Set mark on. */
1759 owner->view()->beforeChange();
1760 owner->view()->text->mark_set = 1;
1761 owner->view()->update( 0 );
1762 owner->view()->text->sel_cursor =
1763 owner->view()->text->cursor;
1764 setMessage(N_("Mark on"));
1767 case LFUN_BACKSPACE:
1770 if (!owner->view()->text->selection) {
1771 if (owner->getIntl()->getTrans()->backspace()) {
1772 owner->view()->text->Backspace();
1773 owner->view()->text->sel_cursor =
1774 owner->view()->text->cursor;
1775 owner->view()->smallUpdate(1);
1776 // It is possible to make it a lot faster still
1777 // just comment out the lone below...
1778 owner->view()->getScreen()->ShowCursor();
1781 owner->view()->cut();
1784 owner->getMiniBuffer()->Set(CurrentState());
1785 owner->view()->SetState();
1789 case LFUN_BACKSPACE_SKIP:
1791 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1793 LyXCursor cursor = owner->view()->text->cursor;
1796 if (!owner->view()->text->selection) {
1798 && !(cursor.par->added_space_top
1799 == VSpace (VSpace::NONE))) {
1800 owner->view()->text->SetParagraph
1801 (cursor.par->line_top,
1802 cursor.par->line_bottom,
1803 cursor.par->pagebreak_top,
1804 cursor.par->pagebreak_bottom,
1805 VSpace(VSpace::NONE), cursor.par->added_space_bottom,
1807 cursor.par->labelwidthstring, 0);
1808 owner->view()->update (1);
1810 owner->view()->text->Backspace();
1811 owner->view()->text->sel_cursor
1813 owner->view()->smallUpdate (1);
1816 owner->view()->cut();
1821 case LFUN_BREAKPARAGRAPH:
1823 owner->view()->beforeChange();
1824 owner->view()->text->BreakParagraph(0);
1825 owner->view()->smallUpdate(1);
1826 SetUpdateTimer(0.01);
1827 owner->view()->text->sel_cursor =
1828 owner->view()->text->cursor;
1829 owner->view()->SetState();
1830 owner->getMiniBuffer()->Set(CurrentState());
1834 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1836 owner->view()->beforeChange();
1837 owner->view()->text->BreakParagraph(1);
1838 owner->view()->smallUpdate(1);
1839 SetUpdateTimer(0.01);
1840 owner->view()->text->sel_cursor =
1841 owner->view()->text->cursor;
1842 owner->view()->SetState();
1843 owner->getMiniBuffer()->Set(CurrentState());
1847 case LFUN_BREAKPARAGRAPH_SKIP:
1849 // When at the beginning of a paragraph, remove
1850 // indentation and add a "defskip" at the top.
1851 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
1853 LyXCursor cursor = owner->view()->text->cursor;
1855 owner->view()->beforeChange();
1856 if (cursor.pos == 0) {
1857 if (cursor.par->added_space_top == VSpace(VSpace::NONE)) {
1858 owner->view()->text->SetParagraph
1859 (cursor.par->line_top,
1860 cursor.par->line_bottom,
1861 cursor.par->pagebreak_top,
1862 cursor.par->pagebreak_bottom,
1863 VSpace(VSpace::DEFSKIP), cursor.par->added_space_bottom,
1865 cursor.par->labelwidthstring, 1);
1866 owner->view()->update(1);
1870 owner->view()->text->BreakParagraph(0);
1871 owner->view()->smallUpdate(1);
1873 SetUpdateTimer(0.01);
1874 owner->view()->text->sel_cursor = cursor;
1875 owner->view()->SetState();
1876 owner->getMiniBuffer()->Set(CurrentState());
1881 owner->view()->beforeChange();
1882 owner->view()->text->InsertChar('\"'); // This " matches the single quote in the code
1883 owner->view()->smallUpdate(1);
1885 moveCursorUpdate(false);
1891 InsetCommand * new_inset;
1892 if (action == LFUN_HTMLURL)
1893 new_inset = new InsetUrl("htmlurl", "", "");
1895 new_inset = new InsetUrl("url", "", "");
1896 owner->view()->insertInset(new_inset);
1897 new_inset->Edit(0, 0);
1901 // --- lyxserver commands ----------------------------
1903 case LFUN_CHARATCURSOR:
1905 LyXParagraph::size_type pos =
1906 owner->view()->text->cursor.pos;
1907 if(pos < owner->view()->text->cursor.par->size())
1908 dispatch_buffer = owner->view()->text->
1909 cursor.par->text[pos];
1911 dispatch_buffer = "EOF";
1917 tostr(owner->view()->text->cursor.x) + ' '
1918 + tostr(owner->view()->text->cursor.y);
1925 sscanf(argument.c_str(), " %d %ld", &x, &y);
1926 owner->view()->text->SetCursorFromCoordinates(x, y);
1930 case LFUN_GETLAYOUT:
1932 tostr(owner->view()->text->cursor.par->layout);
1937 LyXFont * font = &(owner->view()->text->current_font);
1938 if(font->shape() == LyXFont::ITALIC_SHAPE)
1939 dispatch_buffer = 'E';
1940 else if(font->shape() == LyXFont::SMALLCAPS_SHAPE)
1941 dispatch_buffer = 'N';
1943 dispatch_buffer = '0';
1950 LyXFont * font = &(owner->view()->text->current_font);
1951 if(font->latex() == LyXFont::ON)
1952 dispatch_buffer = 'L';
1954 dispatch_buffer = '0';
1959 setMessage(owner->buffer()->fileName());
1960 lyxerr.debug() << "FNAME["
1961 << owner->buffer()->fileName()
1969 dispatch_buffer = buf;
1970 lyxserver->notifyClient(dispatch_buffer);
1974 case LFUN_GOTOFILEROW:
1976 char file_name[100];
1978 sscanf(argument.c_str(), " %s %d", file_name, &row);
1980 // Must replace extension of the file to be .lyx and get full path
1981 string s = ChangeExtension(string(file_name), ".lyx", false);
1983 // Either change buffer or load the file
1984 if (bufferlist.exists(s))
1985 owner->view()->buffer(bufferlist.getBuffer(s));
1987 owner->view()->buffer(bufferlist.loadLyXFile(s));
1990 owner->view()->setCursorFromRow(row);
1993 owner->view()->beforeChange();
1994 if (owner->view()->text->cursor.y >
1995 owner->view()->getWorkArea()->h / 2) {
1996 owner->view()->getScreen()->
1997 Draw(owner->view()->text->cursor.y -
1998 owner->view()->getWorkArea()->h/2);
2000 owner->view()->getScreen()->
2003 owner->view()->update(0);
2004 owner->view()->redraw();
2011 int qa = lyxaction.LookupFunc(argument.c_str());
2012 setMessage(lyxaction.helpText(static_cast<kb_action>(qa)));
2016 // --- accented characters ---------------------------
2019 case LFUN_CIRCUMFLEX:
2029 case LFUN_SPECIAL_CARON:
2032 case LFUN_HUNG_UMLAUT:
2038 if (keyseq.length == -1 && keyseq.getiso() != 0)
2039 c = keyseq.getiso();
2043 owner->getIntl()->getTrans()->
2044 deadkey(c, get_accent(action).accent,
2045 owner->view()->text);
2047 // Need to reset, in case the minibuffer calls these
2052 // copied verbatim from do_accent_char
2053 owner->view()->smallUpdate(1);
2055 owner->view()->text->sel_cursor =
2056 owner->view()->text->cursor;
2060 // --- toolbar ----------------------------------
2061 case LFUN_PUSH_TOOLBAR:
2063 int nth = strToInt(argument);
2064 if (lyxerr.debugging(Debug::TOOLBAR)) {
2065 lyxerr << "LFUN_PUSH_TOOLBAR: argument = `"
2066 << argument << "'\n"
2067 << "LFUN_PUSH_TOOLBAR: nth = `"
2068 << nth << "'" << endl;
2073 setErrorMessage(N_("Push-toolbar needs argument > 0"));
2075 owner->getToolbar()->push(nth);
2080 case LFUN_ADD_TO_TOOLBAR:
2082 if (lyxerr.debugging(Debug::TOOLBAR)) {
2083 lyxerr << "LFUN_ADD_TO_TOOLBAR:"
2084 "argument = `" << argument << '\'' << endl;
2086 string tmp(argument);
2087 //lyxerr <<string("Argument: ") + argument);
2088 //lyxerr <<string("Tmp : ") + tmp);
2091 setErrorMessage(N_("Usage: toolbar-add-to <LyX command>"));
2093 owner->getToolbar()->add(argument, false);
2094 owner->getToolbar()->set();
2099 // --- insert characters ----------------------------------------
2101 case LFUN_INSERT_INSET_LATEX:
2103 Inset * new_inset = new InsetLatex(argument);
2104 owner->buffer()->insertInset(new_inset);
2108 // --- Mathed stuff. If we are here, there is no locked inset yet.
2113 if (!greek_kb_flag) {
2115 setMessage(N_("Math greek mode on"));
2122 case LFUN_GREEK_TOGGLE:
2124 greek_kb_flag = greek_kb_flag ? 0 : 2;
2125 if (greek_kb_flag) {
2126 setMessage(N_("Math greek keyboard on"));
2128 setMessage(N_("Math greek keyboard off"));
2133 case LFUN_MATH_DELIM:
2134 case LFUN_INSERT_MATRIX:
2136 if (owner->view()->available()) {
2138 open_new_inset(new InsetFormula(false));
2140 the_locking_inset->LocalDispatch(action, argument.c_str());
2145 case LFUN_INSERT_MATH:
2147 math_insert_symbol(argument.c_str());
2151 case LFUN_MATH_DISPLAY:
2153 if (owner->view()->available())
2154 owner->view()->open_new_inset(new InsetFormula(true));
2158 case LFUN_MATH_MACRO:
2160 if (owner->view()->available()) {
2163 setErrorMessage(N_("Missing argument"));
2165 string s1 = token(s, ' ', 1);
2166 int na = s1.empty() ? 0: atoi(s1.c_str());
2168 open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2174 case LFUN_MATH_MODE: // Open or create a math inset
2177 if (owner->view()->available())
2178 owner->view()->open_new_inset(new InsetFormula);
2179 setMessage(N_("Math editor mode"));
2183 case LFUN_MATH_NUMBER:
2184 case LFUN_MATH_LIMITS:
2186 setErrorMessage(N_("This is only allowed in math mode!"));
2190 case LFUN_INSERT_CITATION:
2192 InsetCitation * new_inset = new InsetCitation();
2194 // The note, if any, must be after the key, delimited
2195 // by a | so both key and remark can have spaces.
2196 if (!argument.empty()) {
2197 string lsarg(argument);
2198 if (contains(lsarg, "|")) {
2199 new_inset->setContents(token(lsarg, '|', 0));
2200 new_inset->setOptions(token(lsarg, '|', 1));
2202 new_inset->setContents(lsarg);
2203 owner->view()->insertInset(new_inset);
2205 owner->view()->insertInset(new_inset);
2206 new_inset->Edit(0, 0);
2211 case LFUN_INSERT_BIBTEX:
2213 // ale970405+lasgoutt970425
2214 // The argument can be up to two tokens separated
2215 // by a space. The first one is the bibstyle.
2216 string lsarg(argument);
2217 string bibstyle = token(lsarg, ' ', 1);
2218 if (bibstyle.empty())
2220 InsetBibtex * new_inset
2221 = new InsetBibtex(token(lsarg, ' ', 0),
2225 owner->view()->insertInset(new_inset);
2226 if (lsarg.empty()) {
2227 new_inset->Edit(0, 0);
2232 // BibTeX data bases
2233 case LFUN_BIBDB_ADD:
2235 InsetBibtex * inset =
2236 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2238 inset->addDatabase(argument);
2243 case LFUN_BIBDB_DEL:
2245 InsetBibtex * inset =
2246 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2248 inset->delDatabase(argument);
2253 case LFUN_BIBTEX_STYLE:
2255 InsetBibtex * inset =
2256 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2258 inset->setOptions(argument);
2263 case LFUN_INDEX_INSERT:
2264 case LFUN_INDEX_INSERT_LAST:
2266 // Can't do that at the beginning of a paragraph.
2267 if (owner->view()->text->cursor.pos - 1 < 0)
2270 InsetIndex * new_inset = new InsetIndex();
2271 if (!argument.empty()) {
2272 string lsarg(argument);
2273 new_inset->setContents(lsarg);
2274 owner->view()->insertInset(new_inset);
2277 //get the current word for an argument
2278 LyXParagraph::size_type lastpos =
2279 owner->view()->text->cursor.pos - 1;
2280 // Get the current word. note that this must be done
2281 // before inserting the inset, or the inset will
2283 string curstring(owner->view()
2284 ->text->cursor.par->GetWord(lastpos));
2286 //make the new inset and write the current word into it
2287 InsetIndex * new_inset = new InsetIndex();
2289 new_inset->setContents(curstring);
2291 //don't edit it if the call was to INSERT_LAST
2292 if(action != LFUN_INDEX_INSERT_LAST) {
2293 new_inset->Edit(0, 0);
2295 //it looks blank on the screen unless
2296 //we do something. put it here.
2298 // move the cursor to the returned value of lastpos
2299 // but only for the auto-insert
2300 owner->view()->text->cursor.pos = lastpos;
2303 //put the new inset into the buffer.
2304 // there should be some way of knowing the user
2305 //cancelled & avoiding this, but i don't know how
2306 owner->view()->insertInset(new_inset);
2311 case LFUN_INDEX_PRINT:
2313 Inset * new_inset = new InsetPrintIndex(owner->buffer());
2314 owner->view()->insertInset(new_inset, "Standard", true);
2318 case LFUN_PARENTINSERT:
2320 lyxerr << "arg " << argument << endl;
2321 Inset * new_inset = new InsetParent(argument, owner->buffer());
2322 owner->view()->insertInset(new_inset, "Standard", true);
2326 case LFUN_CHILDINSERT:
2328 Inset * new_inset = new InsetInclude(argument,
2330 owner->view()->insertInset(new_inset, "Standard", true);
2331 new_inset->Edit(0, 0);
2335 case LFUN_CHILDOPEN:
2338 MakeAbsPath(argument,
2339 OnlyPath(owner->buffer()->fileName()));
2340 setMessage(N_("Opening child document ") +
2341 MakeDisplayPath(filename) + "...");
2342 owner->view()->savePosition();
2343 if (bufferlist.exists(filename))
2344 owner->view()->buffer(bufferlist.getBuffer(filename));
2346 owner->view()->buffer(bufferlist.loadLyXFile(filename));
2350 case LFUN_INSERT_NOTE:
2351 owner->view()->insertNote();
2354 case LFUN_INSERTFOOTNOTE:
2356 LyXParagraph::footnote_kind kind;
2357 if (argument == "footnote")
2358 { kind = LyXParagraph::FOOTNOTE; }
2359 else if (argument == "margin")
2360 { kind = LyXParagraph::MARGIN; }
2361 else if (argument == "figure")
2362 { kind = LyXParagraph::FIG; }
2363 else if (argument == "table")
2364 { kind = LyXParagraph::TAB; }
2365 else if (argument == "wide-fig")
2366 { kind = LyXParagraph::WIDE_FIG; }
2367 else if (argument == "wide-tab")
2368 { kind = LyXParagraph::WIDE_TAB; }
2369 else if (argument == "algorithm")
2370 { kind = LyXParagraph::ALGORITHM; }
2372 setErrorMessage(N_("Unknown kind of footnote"));
2375 owner->view()->text->InsertFootnoteEnvironment(kind);
2376 owner->view()->update(1);
2377 owner->view()->SetState();
2381 case LFUN_BUFFERBULLETSSELECT:
2385 case LFUN_TOGGLECURSORFOLLOW:
2386 cursor_follows_scrollbar = !cursor_follows_scrollbar;
2389 case LFUN_KMAP_OFF: // keymap off
2390 owner->getIntl()->KeyMapOn(false);
2393 case LFUN_KMAP_PRIM: // primary keymap
2394 owner->getIntl()->KeyMapPrim();
2397 case LFUN_KMAP_SEC: // secondary keymap
2398 owner->getIntl()->KeyMapSec();
2401 case LFUN_KMAP_TOGGLE: // toggle keymap
2402 owner->getIntl()->ToggleKeyMap();
2405 case LFUN_SELFINSERT:
2407 for (string::size_type i = 0; i < argument.length(); ++i) {
2408 owner->view()->text->InsertChar(argument[i]);
2409 // This needs to be in the loop, or else we
2410 // won't break lines correctly. (Asger)
2411 owner->view()->smallUpdate(1);
2414 owner->view()->text->sel_cursor =
2415 owner->view()->text->cursor;
2416 moveCursorUpdate(false);
2422 // argument contains ';'-terminated commands
2423 while (argument.find(';') != string::npos) {
2425 argument = split(argument, first, ';');
2431 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
2439 now_time_t = time(NULL);
2440 now_tm = localtime(&now_time_t);
2441 (void)setlocale(LC_TIME, "");
2442 if (!argument.empty())
2444 else if (arg.empty())
2445 arg = lyxrc->date_insert_format;
2446 datetmp_len = (int) strftime(datetmp, 32, arg.c_str(), now_tm);
2447 for (int i = 0; i < datetmp_len; i++) {
2448 owner->view()->text->InsertChar(datetmp[i]);
2449 owner->view()->smallUpdate(1);
2452 owner->view()->text->sel_cursor = owner->view()->text->cursor;
2453 moveCursorUpdate(false);
2457 case LFUN_SAVEPREFERENCES:
2459 Path p(user_lyxdir);
2460 lyxrc->write("preferences");
2464 case LFUN_UNKNOWN_ACTION:
2466 if(!owner->buffer()) {
2468 setErrorMessage(N_("No document open"));
2472 if (owner->buffer()->isReadonly()) {
2474 setErrorMessage(N_("Document is read only"));
2478 if (!argument.empty()) {
2480 /* Automatically delete the currently selected
2481 * text and replace it with what is being
2482 * typed in now. Depends on lyxrc settings
2483 * "auto_region_delete", which defaults to
2486 if ( lyxrc->auto_region_delete ) {
2487 if (owner->view()->text->selection){
2488 owner->view()->text->CutSelection(false);
2489 owner->view()->update(-1);
2493 owner->view()->beforeChange();
2494 for (string::size_type i = 0;
2495 i < argument.length(); ++i) {
2496 if (greek_kb_flag) {
2497 if (!math_insert_greek(argument[i]))
2498 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2500 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2503 owner->view()->smallUpdate(1);
2506 owner->view()->text->sel_cursor =
2507 owner->view()->text->cursor;
2508 moveCursorUpdate(false);
2511 // why is an "Unknown action" with empty
2512 // argument even dispatched in the first
2513 // place? I`ll probably change that. (Lgb)
2515 setErrorMessage(N_("Unknown action"));
2519 lyxerr << "A truly unknown func!" << endl;
2525 string res = getMessage();
2528 if (!commandshortcut.empty()) {
2529 string newbuf = owner->getMiniBuffer()->GetText();
2530 if (newbuf != commandshortcut) {
2531 owner->getMiniBuffer()->Set(newbuf
2537 owner->getMiniBuffer()->Set(string(_(res.c_str()))
2538 + " " + commandshortcut);
2545 void LyXFunc::setupLocalKeymap()
2547 keyseq.stdmap = keyseq.curmap = toplevel_keymap;
2548 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap;
2552 void LyXFunc::MenuNew(bool fromTemplate)
2554 string fname, initpath = lyxrc->document_path;
2557 if (owner->view()->available()) {
2558 string trypath = owner->buffer()->filepath;
2559 // If directory is writeable, use this as default.
2560 if (IsDirWriteable(trypath) == 1)
2565 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2566 fileDlg.SetButton(1, _("Templates"), lyxrc->template_path);
2567 fname = fileDlg.Select(_("Enter Filename for new document"),
2568 initpath, "*.lyx", _("newfile"));
2571 if (fname.empty()) {
2572 owner->getMiniBuffer()->Set(_("Canceled."));
2573 lyxerr.debug() << "New Document Cancelled." << endl;
2577 // get absolute path of file and make sure the filename ends
2579 string s = MakeAbsPath(fname);
2580 if (!IsLyXFilename(s))
2583 // Check if the document already is open
2584 if (bufferlist.exists(s)){
2585 switch(AskConfirmation(_("Document is already open:"),
2586 MakeDisplayPath(s, 50),
2587 _("Do you want to close that document now?\n"
2588 "('No' will just switch to the open version)")))
2590 case 1: // Yes: close the document
2591 if (!bufferlist.close(bufferlist.getBuffer(s)))
2592 // If close is canceled, we cancel here too.
2595 case 2: // No: switch to the open document
2596 owner->view()->buffer(bufferlist.getBuffer(s));
2598 case 3: // Cancel: Do nothing
2599 owner->getMiniBuffer()->Set(_("Canceled."));
2604 // Check whether the file already exists
2605 if (IsLyXFilename(s)) {
2607 if (fi.readable() &&
2608 AskQuestion(_("File already exists:"),
2609 MakeDisplayPath(s, 50),
2610 _("Do you want to open the document?"))) {
2612 owner->getMiniBuffer()->Set(_("Opening document"),
2613 MakeDisplayPath(s), "...");
2615 owner->view()->buffer(
2616 bufferlist.loadLyXFile(s));
2617 owner->getMiniBuffer()->Set(_("Document"),
2624 // The template stuff
2628 fname = fileDlg.Select(_("Choose template"),
2629 lyxrc->template_path,
2635 // find a free buffer
2636 lyxerr.debug() << "Find a free buffer." << endl;
2637 owner->view()->buffer(bufferlist.newFile(s, templname));
2641 void LyXFunc::MenuOpen()
2643 string initpath = lyxrc->document_path;
2646 if (owner->view()->available()) {
2647 string trypath = owner->buffer()->filepath;
2648 // If directory is writeable, use this as default.
2649 if (IsDirWriteable(trypath) == 1)
2655 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2656 fileDlg.SetButton(1, _("Examples"),
2657 AddPath(system_lyxdir, "examples"));
2658 string filename = fileDlg.Select(_("Select Document to Open"),
2662 // check selected filename
2663 if (filename.empty()) {
2664 owner->getMiniBuffer()->Set(_("Canceled."));
2668 // get absolute path of file and make sure the filename ends
2670 filename = MakeAbsPath(filename);
2671 if (!IsLyXFilename(filename))
2675 owner->getMiniBuffer()->Set(_("Opening document"),
2676 MakeDisplayPath(filename), "...");
2677 Buffer * openbuf = bufferlist.loadLyXFile(filename);
2679 owner->view()->buffer(openbuf);
2680 owner->getMiniBuffer()->Set(_("Document"),
2681 MakeDisplayPath(filename),
2684 owner->getMiniBuffer()->Set(_("Could not open document"),
2685 MakeDisplayPath(filename));
2690 void LyXFunc::doImportASCII(bool linorpar)
2692 string initpath = lyxrc->document_path;
2695 if (owner->view()->available()) {
2696 string trypath = owner->buffer()->filepath;
2697 // If directory is writeable, use this as default.
2698 if (IsDirWriteable(trypath) == 1)
2704 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2705 fileDlg.SetButton(1, _("Examples"),
2706 AddPath(system_lyxdir, "examples"));
2707 string filename = fileDlg.Select(_("Select ASCII file to Import"),
2711 // check selected filename
2712 if (filename.empty()) {
2713 owner->getMiniBuffer()->Set(_("Canceled."));
2717 // get absolute path of file
2718 filename = MakeAbsPath(filename);
2720 string s = ChangeExtension(filename, ".lyx", false);
2722 // Check if the document already is open
2723 if (bufferlist.exists(s)) {
2724 switch(AskConfirmation(_("Document is already open:"),
2725 MakeDisplayPath(s, 50),
2726 _("Do you want to close that document now?\n"
2727 "('No' will just switch to the open version)")))
2729 case 1: // Yes: close the document
2730 if (!bufferlist.close(bufferlist.getBuffer(s)))
2731 // If close is canceled, we cancel here too.
2734 case 2: // No: switch to the open document
2735 owner->view()->buffer(bufferlist.getBuffer(s));
2737 case 3: // Cancel: Do nothing
2738 owner->getMiniBuffer()->Set(_("Canceled."));
2743 // Check if a LyX document by the same root exists in filesystem
2744 FileInfo f(s, true);
2745 if (f.exist() && !AskQuestion(_("A document by the name"),
2747 _("already exists. Overwrite?"))) {
2748 owner->getMiniBuffer()->Set(_("Canceled."));
2752 owner->view()->buffer(bufferlist.newFile(s, string()));
2753 owner->getMiniBuffer()->Set(_("Importing ASCII file"),
2754 MakeDisplayPath(filename), "...");
2755 // Insert ASCII file
2756 InsertAsciiFile(filename, linorpar);
2757 owner->getMiniBuffer()->Set(_("ASCII file "),
2758 MakeDisplayPath(filename),
2763 void LyXFunc::doImportLaTeX(bool isnoweb)
2765 string initpath = lyxrc->document_path;
2768 if (owner->view()->available()) {
2769 string trypath = owner->buffer()->filepath;
2770 // If directory is writeable, use this as default.
2771 if (IsDirWriteable(trypath) == 1)
2777 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2778 fileDlg.SetButton(1, _("Examples"),
2779 AddPath(system_lyxdir, "examples"));
2782 filename = fileDlg.Select(_("Select Noweb file to Import"),
2785 filename = fileDlg.Select(_("Select LaTeX file to Import"),
2791 // check selected filename
2792 if (filename.empty()) {
2793 owner->getMiniBuffer()->Set(_("Canceled."));
2797 // get absolute path of file
2798 filename = MakeAbsPath(filename);
2800 // Check if the document already is open
2801 string LyXfilename = ChangeExtension(filename, ".lyx", false);
2802 if (bufferlist.exists(LyXfilename)){
2803 switch(AskConfirmation(_("Document is already open:"),
2804 MakeDisplayPath(LyXfilename, 50),
2805 _("Do you want to close that document now?\n"
2806 "('No' will just switch to the open version)")))
2808 case 1: // Yes: close the document
2809 if (!bufferlist.close(bufferlist.getBuffer(LyXfilename)))
2810 // If close is canceled, we cancel here too.
2813 case 2: // No: switch to the open document
2814 owner->view()->buffer(
2815 bufferlist.getBuffer(LyXfilename));
2817 case 3: // Cancel: Do nothing
2818 owner->getMiniBuffer()->Set(_("Canceled."));
2823 // Check if a LyX document by the same root exists in filesystem
2824 FileInfo f(LyXfilename, true);
2825 if (f.exist() && !AskQuestion(_("A document by the name"),
2826 MakeDisplayPath(LyXfilename),
2827 _("already exists. Overwrite?"))) {
2828 owner->getMiniBuffer()->Set(_("Canceled."));
2835 owner->getMiniBuffer()->Set(_("Importing LaTeX file"),
2836 MakeDisplayPath(filename), "...");
2837 ImportLaTeX myImport(filename);
2838 openbuf = myImport.run();
2840 owner->getMiniBuffer()->Set(_("Importing Noweb file"),
2841 MakeDisplayPath(filename), "...");
2842 ImportNoweb myImport(filename);
2843 openbuf = myImport.run();
2846 owner->view()->buffer(openbuf);
2847 owner->getMiniBuffer()->Set(isnoweb ?
2848 _("Noweb file ") : _("LateX file "),
2849 MakeDisplayPath(filename),
2852 owner->getMiniBuffer()->Set(isnoweb ?
2853 _("Could not import Noweb file") :
2854 _("Could not import LaTeX file"),
2855 MakeDisplayPath(filename));
2860 void LyXFunc::MenuInsertLyXFile(string const & filen)
2862 string filename = filen;
2864 if (filename.empty()) {
2865 // Launch a file browser
2866 string initpath = lyxrc->document_path;
2869 if (owner->view()->available()) {
2870 string trypath = owner->buffer()->filepath;
2871 // If directory is writeable, use this as default.
2872 if (IsDirWriteable(trypath) == 1)
2878 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2879 fileDlg.SetButton(1, _("Examples"),
2880 AddPath(system_lyxdir, "examples"));
2881 filename = fileDlg.Select(_("Select Document to Insert"),
2885 // check selected filename
2886 if (filename.empty()) {
2887 owner->getMiniBuffer()->Set(_("Canceled."));
2892 // get absolute path of file and make sure the filename ends
2894 filename = MakeAbsPath(filename);
2895 if (!IsLyXFilename(filename))
2899 owner->getMiniBuffer()->Set(_("Inserting document"),
2900 MakeDisplayPath(filename), "...");
2901 bool res = owner->view()->insertLyXFile(filename);
2903 owner->getMiniBuffer()->Set(_("Document"),
2904 MakeDisplayPath(filename),
2907 owner->getMiniBuffer()->Set(_("Could not insert document"),
2908 MakeDisplayPath(filename));
2913 void LyXFunc::reloadBuffer()
2915 string fn = owner->buffer()->fileName();
2916 if (bufferlist.close(owner->buffer()))
2917 owner->view()->buffer(bufferlist.loadLyXFile(fn));
2921 void LyXFunc::CloseBuffer()
2923 if (bufferlist.close(owner->buffer()) && !quitting) {
2924 if (bufferlist.empty()) {
2925 // need this otherwise SEGV may occur while trying to
2926 // set variables that don't exist
2927 // since there's no current buffer
2928 CloseAllBufferRelatedPopups();
2931 owner->view()->buffer(bufferlist.first());
2937 Inset * LyXFunc::getInsetByCode(Inset::Code code)
2941 LyXCursor cursor = owner->view()->text->cursor;
2942 LyXParagraph::size_type pos = cursor.pos;
2943 LyXParagraph * par = cursor.par;
2945 while (par && !found) {
2946 while ((inset = par->ReturnNextInsetPointer(pos))){
2947 if (inset->LyxCode() == code) {
2955 return found ? inset : 0;
2959 // Each "owner" should have it's own message method. lyxview and
2960 // the minibuffer would use the minibuffer, but lyxserver would
2961 // send an ERROR signal to its client. Alejandro 970603
2962 // This func is bit problematic when it comes to NLS, to make the
2963 // lyx servers client be language indepenent we must not translate
2964 // strings sent to this func.
2965 void LyXFunc::setErrorMessage(string const & m) const
2967 dispatch_buffer = m;
2972 void LyXFunc::setMessage(string const & m)
2974 dispatch_buffer = m;