1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * ====================================================== */
20 #pragma implementation
23 #include "lyxlookup.h"
26 #include "bufferlist.h"
27 #include "lyxserver.h"
32 #include "LyXAction.h"
33 #include "insets/inseturl.h"
34 #include "insets/insetlatexaccent.h"
35 #include "insets/insettoc.h"
36 #include "insets/insetlof.h"
37 #include "insets/insetloa.h"
38 #include "insets/insetlot.h"
39 #include "insets/insetref.h"
40 #include "insets/insetparent.h"
41 #include "insets/insetindex.h"
42 #include "insets/insetinclude.h"
43 #include "insets/insetbib.h"
44 #include "mathed/formulamacro.h"
46 #include "spellchecker.h" // RVDK_PATCH_5
47 #include "minibuffer.h"
51 #include "lyx_gui_misc.h"
52 #include "support/filetools.h"
53 #include "support/FileInfo.h"
54 #include "support/syscall.h"
55 #include "support/lstrings.h"
56 #include "support/path.h"
57 #include "lyxscreen.h"
62 #include "trans_mgr.h"
63 #include "ImportLaTeX.h"
64 #include "ImportNoweb.h"
68 extern bool cursor_follows_scrollbar;
70 extern void InsertAsciiFile(string const &, bool);
71 extern void math_insert_symbol(char const *);
72 extern Bool math_insert_greek(char const); // why "Bool"?
73 extern BufferList bufferlist;
74 extern LyXServer * lyxserver;
75 extern short greek_kb_flag;
76 extern FD_form_toc * fd_form_toc;
77 extern bool selection_possible;
79 extern kb_keymap * toplevel_keymap;
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 CreatePostscript(Buffer *, bool);
87 extern void MenuPrint(Buffer *);
88 extern void MenuSendto();
89 extern void QuitLyX();
90 extern void MenuFax(Buffer *);
91 extern void MenuExport(Buffer *, string const &);
92 extern void MenuPasteSelection(char at);
93 extern LyXAction lyxaction;
95 extern tex_accent_struct get_accent(kb_action action);
97 extern void AutoSave();
98 extern void MenuSearch();
99 extern void SetUpdateTimer(float timer = 0.3);
100 extern void FreeUpdateTimer();
101 extern bool PreviewDVI(Buffer *);
102 extern bool PreviewPostscript(Buffer *);
103 extern void MenuInsertLabel(char const *);
104 extern void MenuInsertRef();
105 extern void MenuLayoutCharacter();
106 extern void MenuLayoutParagraph();
107 extern void MenuLayoutDocument();
108 extern void MenuLayoutPaper();
109 extern void MenuLayoutTable(int flag);
110 extern void MenuLayoutQuotes();
111 extern void MenuLayoutPreamble();
112 extern void MenuLayoutSave();
113 extern void bulletForm();
115 extern Buffer * NewLyxFile(string const &);
116 extern void LoadLyXFile(string const &);
117 extern void Reconfigure(BufferView *);
119 extern int current_layout;
120 extern int getISOCodeFromLaTeX(char *);
122 extern void ShowLatexLog();
124 extern void UpdateInset(BufferView *, Inset * inset, bool mark_dirty = true);
126 /* === globals =========================================================== */
128 bool LyXFunc::show_sc = true;
131 LyXFunc::LyXFunc(LyXView * o)
135 lyx_dead_action = LFUN_NOACTION;
136 lyx_calling_dead_action = LFUN_NOACTION;
141 // I changed this func slightly. I commented out the ...FinishUndo(),
142 // this means that all places that used to have a moveCursorUpdate, now
143 // have a ...FinishUndo() as the preceeding statement. I have also added
144 // a moveCursorUpdate to some of the functions that updated the cursor, but
145 // that did not show its new position.
147 void LyXFunc::moveCursorUpdate(bool selecting)
149 if (selecting || owner->view()->text->mark_set) {
150 owner->view()->text->SetSelection();
151 owner->view()->getScreen()->ToggleToggle();
152 owner->view()->update(0);
154 owner->view()->update(-2); // this IS necessary
158 owner->view()->getScreen()->ShowCursor();
160 /* ---> Everytime the cursor is moved, show the current font state. */
161 // should this too me moved out of this func?
162 //owner->getMiniBuffer()->Set(CurrentState());
163 owner->view()->SetState();
167 int LyXFunc::processKeyEvent(XEvent * ev)
171 XKeyEvent * keyevent = &ev->xkey;
172 KeySym keysym_return;
174 int num_bytes = LyXLookupString(ev, s_r, 10, &keysym_return);
175 s_r[num_bytes] = '\0';
177 if (lyxerr.debugging(Debug::KEY)) {
178 char * tmp = XKeysymToString(keysym_return);
179 string stm = (tmp ? tmp : "");
180 lyxerr << "KeySym is "
183 << keysym_return << "]"
184 << " and num_bytes is "
186 << " the string returned is \""
187 << s_r << '\"' << endl;
189 // Do nothing if we have nothing (JMarc)
190 if (num_bytes == 0 && keysym_return == NoSymbol) {
191 lyxerr[Debug::KEY] << "Empty kbd action (probably composing)"
196 // this function should be used always [asierra060396]
197 if (owner->view()->available() &&
198 owner->view()->the_locking_inset &&
199 keysym_return == XK_Escape) {
200 owner->view()->unlockInset(owner->view()->the_locking_inset);
201 owner->view()->text->CursorRight();
202 moveCursorUpdate(false);
203 owner->getMiniBuffer()->Set(CurrentState());
207 // Can we be sure that this will work for all X-Windows
208 // implementations? (Lgb)
209 // This code snippet makes lyx ignore some keys. Perhaps
210 // all of them should be explictly mentioned?
211 if((keysym_return >= XK_Shift_L && keysym_return <= XK_Hyper_R)
212 || keysym_return == XK_Mode_switch || keysym_return == 0x0)
215 // Do a one-deep top-level lookup for
216 // cancel and meta-fake keys. RVDK_PATCH_5
217 cancel_meta_seq.reset();
219 int action = cancel_meta_seq.addkey(keysym_return, keyevent->state
220 &(ShiftMask|ControlMask
223 // When not cancel or meta-fake, do the normal lookup.
224 // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
225 // Mostly, meta_fake_bit = 0. RVDK_PATCH_5.
226 if ( (action != LFUN_CANCEL) && (action != LFUN_META_FAKE) ) {
228 // remove Caps Lock and Mod2 as a modifiers
229 action = keyseq.addkey(keysym_return,
230 (keyevent->state | meta_fake_bit)
231 &(ShiftMask|ControlMask
234 // Dont remove this unless you know what you are doing.
237 if (action == 0) action = LFUN_PREFIX;
239 if (lyxerr.debugging(Debug::KEY)) {
245 << num_bytes << "]" << endl;
248 // already here we know if it any point in going further
249 // why not return already here if action == -1 and
250 // num_bytes == 0? (Lgb)
252 if(keyseq.length > 1 || keyseq.length < -1) {
255 owner->getMiniBuffer()->Set(buf);
259 if (keyseq.length < -1) { // unknown key sequence...
263 owner->getMiniBuffer()->Set(_("Unknown sequence:"), buf);
267 char isochar = keyseq.getiso();
268 if (!(keyevent->state&ControlMask) &&
269 !(keyevent->state&Mod1Mask) &&
270 (isochar && keysym_return < 0xF000)) {
273 if (argument.empty()) {
274 lyxerr.debug() << "Empty argument!" << endl;
275 // This can`t possibly be of any use
276 // so we`ll skip the dispatch.
280 if (action == LFUN_SELFINSERT) {
284 bool tmp_sc = show_sc;
286 Dispatch(action, argument.c_str());
293 LyXFunc::func_status LyXFunc::getStatus(int ac) const
296 func_status flag = LyXFunc::OK;
298 Buffer * buf = owner->buffer();
300 if (lyxaction.isPseudoAction(ac))
301 action = lyxaction.retrieveActionArg(ac, argument);
303 action = static_cast<kb_action>(ac);
305 if (action == LFUN_UNKNOWN_ACTION) {
306 setErrorMessage(N_("Unknown action"));
307 return LyXFunc::Unknown;
310 // Check whether we need a buffer
311 if (!lyxaction.funcHasFlag(action, LyXAction::NoBuffer)) {
312 // Yes we need a buffer, do we have one?
315 // Can we use a readonly buffer?
316 if (buf->isReadonly() &&
317 !lyxaction.funcHasFlag(action,
318 LyXAction::ReadOnly)) {
320 setErrorMessage(N_("Document is read-only"));
321 flag |= LyXFunc::Disabled;
325 setErrorMessage(N_("Command not allowed with"
326 "out any document open"));
327 flag |= LyXFunc::Disabled;
331 if (flag & LyXFunc::Disabled)
334 // I would really like to avoid having this switch and rather try to
335 // encode this in the function itself.
336 static bool noLaTeX = lyxrc->latex_command == "none";
337 bool disable = false;
340 disable = noLaTeX || lyxrc->view_dvi_command == "none";
343 disable = noLaTeX || lyxrc->view_ps_command == "none";
350 disable = noLaTeX || lyxrc->print_command == "none";
353 disable = noLaTeX || lyxrc->fax_command == "none";
356 if (argument == "latex")
357 disable = lyxrc->relyx_command == "none";
360 if (argument == "dvi" || argument == "postscript")
362 if (argument == "html")
363 disable = lyxrc->html_command == "none";
366 disable = buf->undostack.empty();
369 disable = buf->redostack.empty();
371 case LFUN_SPELLCHECK:
372 disable = lyxrc->isp_command == "none";
375 disable = lyxrc->chktex_command == "none";
377 case LFUN_LAYOUT_TABLE:
378 disable = ! owner->view()->text->cursor.par->table;
384 flag |= LyXFunc::Disabled;
387 func_status box = LyXFunc::ToggleOff;
388 LyXFont font = owner->view()->text->real_current_font;
391 if (font.emph() == LyXFont::ON)
392 box = LyXFunc::ToggleOn;
395 if (font.noun() == LyXFont::ON)
396 box = LyXFunc::ToggleOn;
399 if (font.series() == LyXFont::BOLD_SERIES)
400 box = LyXFunc::ToggleOn;
403 if (font.latex() == LyXFont::ON)
404 box = LyXFunc::ToggleOn;
407 if (font.direction() == LyXFont::RTL_DIR)
408 box = LyXFunc::ToggleOn;
421 string LyXFunc::Dispatch(string const & s)
423 // Split command string into command and argument
424 string cmd, line = frontStrip(s);
425 string arg = strip(frontStrip(split(line, cmd, ' ')));
427 return Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
431 string LyXFunc::Dispatch(int ac,
432 char const * do_not_use_this_arg)
437 // we have not done anything wrong yet.
439 dispatch_buffer.clear();
441 // if action is a pseudo-action, we need the real action
442 if (lyxaction.isPseudoAction(ac)) {
444 action = static_cast<kb_action>
445 (lyxaction.retrieveActionArg(ac, tmparg));
449 action = static_cast<kb_action>(ac);
450 if (do_not_use_this_arg)
451 argument = do_not_use_this_arg; // except here
454 selection_possible = false;
456 if (owner->view()->available()
457 && owner->view()->getScreen())
458 owner->view()->getScreen()->HideCursor();
460 // We cannot use this function here
461 if (getStatus(action) & Disabled)
462 goto exit_with_message;
464 commandshortcut.clear();
466 if (lyxrc->display_shortcuts && show_sc) {
467 if (action != LFUN_SELFINSERT) {
468 // Put name of command and list of shortcuts
469 // for it in minibuffer
470 string comname = lyxaction.getActionName(action);
472 int pseudoaction = action;
473 bool argsadded = false;
475 if (!argument.empty()) {
476 // If we have the command with argument,
479 lyxaction.searchActionArg(action,
482 if (pseudoaction == -1) {
483 pseudoaction = action;
485 comname += " " + argument;
490 string shortcuts = toplevel_keymap->findbinding(pseudoaction);
492 if (!shortcuts.empty()) {
493 comname += ": " + shortcuts;
494 } else if (!argsadded) {
495 comname += " " + argument;
498 if (!comname.empty()) {
499 comname = strip(comname);
500 commandshortcut = "(" + comname + ')';
501 owner->getMiniBuffer()->Set(commandshortcut);
502 // Here we could even add a small pause,
503 // to annoy the user and make him learn
505 // No! That will just annoy, not teach
506 // anything. The user will read the messages
507 // if they are interested. (Asger)
512 // If in math mode pass the control to
513 // the math inset [asierra060396]
514 if (owner->view()->available() &&
515 owner->view()->the_locking_inset) {
517 || (action == LFUN_UNKNOWN_ACTION
518 && keyseq.length >= -1)) {
519 if (action == LFUN_UNKNOWN_ACTION
520 && argument.empty()) {
521 argument = keyseq.getiso();
523 // Undo/Redo pre 0.13 is a bit tricky for insets.
524 if (action == LFUN_UNDO) {
526 UpdatableInset * inset =
527 owner->view()->the_locking_inset;
528 inset->GetCursorPos(slx, sly);
529 owner->view()->unlockInset(inset);
530 owner->view()->menuUndo();
531 inset = static_cast<UpdatableInset*>(owner->view()->text->cursor.par->GetInset(owner->view()->text->cursor.pos));
533 inset->Edit(slx, sly);
536 if (action == LFUN_REDO) {
538 UpdatableInset * inset = owner->view()->the_locking_inset;
539 inset->GetCursorPos(slx, sly);
540 owner->view()->unlockInset(inset);
541 owner->view()->menuRedo();
542 inset = static_cast<UpdatableInset*>(owner->view()->text->cursor.par->GetInset(owner->view()->text->cursor.pos));
544 inset->Edit(slx, sly);
547 if (owner->view()->the_locking_inset->LocalDispatch(action, argument.c_str()))
550 setMessage(N_("Text mode"));
551 LyXDirection direction = owner->view()->text->cursor.par->getParDirection();
553 (action == LFUN_RIGHT
554 && direction == LYX_DIR_LEFT_TO_RIGHT)) {
555 owner->view()->text->CursorRight();
556 moveCursorUpdate(false);
557 owner->getMiniBuffer()->Set(CurrentState());
559 if ( action == LFUN_LEFT
560 && direction == LYX_DIR_RIGHT_TO_LEFT) {
561 owner->view()->text->CursorRight();
562 moveCursorUpdate(false);
563 owner->getMiniBuffer()->Set(CurrentState());
565 if (action == LFUN_LEFT || action == LFUN_RIGHT)
572 // --- Misc -------------------------------------------
573 case LFUN_WORDFINDFORWARD :
574 case LFUN_WORDFINDBACKWARD : {
575 static string last_search;
576 string searched_string;
578 if (!argument.empty()) {
579 last_search = argument;
580 searched_string = argument;
582 searched_string = last_search;
585 LyXText * ltCur = owner->view()->text ;
587 if (!searched_string.empty() &&
588 ((action == LFUN_WORDFINDBACKWARD) ?
589 ltCur->SearchBackward(searched_string.c_str()) :
590 ltCur->SearchForward(searched_string.c_str()))) {
592 // ??? What is that ???
593 owner->view()->update(-2);
596 // clear the selection (if there is any)
597 owner->view()->getScreen()->ToggleSelection();
598 owner->view()->text->ClearSelection();
600 // Move cursor so that successive C-s 's will not stand in place.
601 if( action == LFUN_WORDFINDFORWARD )
602 owner->view()->text->CursorRightOneWord();
603 owner->view()->text->FinishUndo();
604 moveCursorUpdate(false);
607 // set the new selection
608 // SetSelectionOverLenChars(owner->view()->currentBuffer()->text, iLenSelected);
609 owner->view()->getScreen()->ToggleSelection(false);
613 // REMOVED : if (owner->view()->getWorkArea()->focus)
614 owner->view()->getScreen()->ShowCursor();
620 if (owner->view()->available()
621 && owner->view()->getScreen()) {
622 owner->view()->update(-2);
625 keyseq.print(buf, true);
626 owner->getMiniBuffer()->Set(buf, string(), string(), 1);
630 // --- Misc -------------------------------------------
631 case LFUN_EXEC_COMMAND:
632 owner->getMiniBuffer()->ExecCommand();
635 case LFUN_CANCEL: // RVDK_PATCH_5
638 if(owner->view()->available())
639 // cancel any selection
640 Dispatch(LFUN_MARK_OFF, 0);
641 setMessage(N_("Cancel"));
644 case LFUN_META_FAKE: // RVDK_PATCH_5
646 meta_fake_bit = Mod1Mask;
648 keyseq.print(buf, true);
649 string res = string("M-") + buf;
650 setMessage(buf); // RVDK_PATCH_5
654 case LFUN_READ_ONLY_TOGGLE:
655 if (owner->buffer()->lyxvc.inUse()) {
656 owner->buffer()->lyxvc.toggleReadOnly();
658 owner->buffer()->setReadonly(
659 !owner->buffer()->isReadonly());
663 case LFUN_CENTER: // this is center and redraw.
664 owner->view()->beforeChange();
665 if (owner->view()->text->cursor.y >
667 owner->view()->getWorkArea()->height() / 2)
669 owner->view()->getWorkArea()->h / 2)
672 owner->view()->getScreen()->
673 Draw(owner->view()->text->cursor.y -
675 owner->view()->getWorkArea()->height() / 2
677 owner->view()->getWorkArea()->h / 2
681 owner->view()->getScreen()->
684 owner->view()->update(0);
685 owner->view()->redraw();
689 if (owner->view()->available()) {
690 owner->view()->text->toggleAppendix();
691 owner->view()->update(1);
695 // --- Menus -----------------------------------------------
700 case LFUN_MENUNEWTMPLT:
708 case LFUN_CLOSEBUFFER:
713 MenuWrite(owner->buffer());
716 case LFUN_MENUWRITEAS:
717 MenuWriteAs(owner->buffer());
720 case LFUN_MENURELOAD:
725 PreviewDVI(owner->buffer());
729 PreviewPostscript(owner->buffer());
733 MenuRunLaTeX(owner->buffer());
737 MenuBuildProg(owner->buffer());
741 MenuRunChktex(owner->buffer());
745 CreatePostscript(owner->buffer(), false);
749 MenuPrint(owner->buffer());
753 MenuFax(owner->buffer());
757 MenuExport(owner->buffer(), argument);
762 //needs argument as string
763 string imtyp = argument;
766 if (imtyp == "latex") {
767 doImportLaTeX(false);
770 else if (imtyp == "ascii") {
771 doImportASCII(false);
772 } else if (imtyp == "asciiparagraph") {
775 } else if (imtyp == "noweb") {
778 setErrorMessage(string(N_("Unknown import type: "))
790 if (fd_form_toc->form_toc->visible) {
791 fl_raise_form(fd_form_toc->form_toc);
793 static int ow = -1, oh;
794 fl_show_form(fd_form_toc->form_toc,
796 FL_FREE_SIZE, FL_FULLBORDER,
797 _("Table of Contents"));
799 ow = fd_form_toc->form_toc->w;
800 oh = fd_form_toc->form_toc->h;
802 fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
806 case LFUN_TOC_INSERT:
808 Inset * new_inset = new InsetTOC(owner->buffer());
809 owner->view()->insertInset(new_inset, "Standard", true);
813 case LFUN_LOF_INSERT:
815 Inset * new_inset = new InsetLOF(owner->buffer());
816 owner->view()->insertInset(new_inset, "Standard", true);
820 case LFUN_LOA_INSERT:
822 Inset * new_inset = new InsetLOA(owner->buffer());
823 owner->view()->insertInset(new_inset, "Standard", true);
827 case LFUN_LOT_INSERT:
829 Inset * new_inset = new InsetLOT(owner->buffer());
830 owner->view()->insertInset(new_inset, "Standard", true);
847 owner->view()->menuUndo();
851 owner->view()->menuRedo();
854 case LFUN_MENUSEARCH:
859 owner->view()->paste();
862 case LFUN_PASTESELECTION:
865 if (argument == "paragraph") asPara = true;
866 MenuPasteSelection(asPara);
871 owner->view()->cut();
875 owner->view()->copy();
878 case LFUN_LAYOUT_COPY:
879 owner->view()->copyEnvironment();
882 case LFUN_LAYOUT_PASTE:
883 owner->view()->pasteEnvironment();
887 owner->view()->gotoError();
890 case LFUN_REMOVEERRORS:
891 if (owner->view()->removeAutoInsets()) {
892 owner->view()->redraw();
893 owner->view()->fitCursor();
894 owner->view()->updateScrollbar();
899 owner->view()->gotoNote();
903 owner->view()->openStuff();
906 case LFUN_HYPHENATION:
907 owner->view()->hyphenationPoint();
911 owner->view()->ldots();
914 case LFUN_END_OF_SENTENCE:
915 owner->view()->endOfSentenceDot();
918 case LFUN_MENU_SEPARATOR:
919 owner->view()->menuSeparator();
923 owner->view()->hfill();
927 changeDepth(owner->view(), 0);
931 changeDepth(owner->view(), -1);
934 case LFUN_DEPTH_PLUS:
935 changeDepth(owner->view(), 1);
944 owner->view()->SetState();
945 owner->getMiniBuffer()->Set(CurrentState());
952 case LFUN_RECONFIGURE:
953 Reconfigure(owner->view());
957 if (owner->view()->available()
958 && !owner->view()->text->selection
959 && owner->view()->text->cursor.par->footnoteflag
960 != LyXParagraph::NO_FOOTNOTE)
961 { // only melt footnotes with FOOTMELT, not margins etc
962 if(owner->view()->text->cursor.par->footnotekind == LyXParagraph::FOOTNOTE)
967 owner->view()->SetState();
970 case LFUN_MARGINMELT:
971 if (owner->view()->available()
972 && !owner->view()->text->selection
973 && owner->view()->text->cursor.par->footnoteflag
974 != LyXParagraph::NO_FOOTNOTE) {
976 if(owner->view()->text->cursor.par->footnotekind == LyXParagraph::MARGIN)
979 Margin(owner->view());
980 owner->view()->SetState();
983 // --- version control -------------------------------
984 case LFUN_VC_REGISTER:
986 if (!owner->buffer()->lyxvc.inUse())
987 owner->buffer()->lyxvc.registrer();
991 case LFUN_VC_CHECKIN:
993 if (owner->buffer()->lyxvc.inUse()
994 && !owner->buffer()->isReadonly())
995 owner->buffer()->lyxvc.checkIn();
999 case LFUN_VC_CHECKOUT:
1001 if (owner->buffer()->lyxvc.inUse()
1002 && owner->buffer()->isReadonly())
1003 owner->buffer()->lyxvc.checkOut();
1007 case LFUN_VC_REVERT:
1009 owner->buffer()->lyxvc.revert();
1015 owner->buffer()->lyxvc.undoLast();
1019 case LFUN_VC_HISTORY:
1021 owner->buffer()->lyxvc.showLog();
1025 // --- buffers ----------------------------------------
1027 case LFUN_FILE_INSERT:
1029 MenuInsertLyXFile(argument);
1033 case LFUN_FILE_INSERT_ASCII:
1035 bool asPara = (argument == "paragraph");
1036 InsertAsciiFile(string(), asPara);
1042 // servercmd: argument must be <file>:<template>
1043 Buffer * tmpbuf = NewLyxFile(argument);
1045 owner->view()->buffer(tmpbuf);
1049 case LFUN_FILE_OPEN:
1050 owner->view()->buffer(bufferlist.loadLyXFile(argument));
1053 case LFUN_LATEX_LOG:
1059 lyxerr.debug() << "LFUN_LAYOUTNO: (arg) " << argument << endl;
1060 int sel = strToInt(argument);
1061 lyxerr.debug() << "LFUN_LAYOUTNO: (sel) "<< sel << endl;
1063 // Should this give a setMessage instead?
1065 return string(); // illegal argument
1067 --sel; // sel 1..., but layout 0...
1069 // Pretend we got the name instead.
1070 Dispatch(int(LFUN_LAYOUT),
1071 textclasslist.NameOfLayout(owner->view()->
1080 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1081 << argument << endl;
1083 // Derive layout number from given argument (string)
1084 // and current buffer's textclass (number). */
1086 textclasslist.NumberOfLayout(owner->
1092 // see if we found the layout number:
1093 if (layoutno == -1) {
1094 setErrorMessage(string(N_("Layout ")) + argument +
1099 if (current_layout != layoutno) {
1100 owner->view()->getScreen()->HideCursor();
1101 current_layout = layoutno;
1102 owner->view()->update(-2);
1103 owner->view()->text->
1104 SetLayout(layoutno);
1105 owner->getToolbar()->combox->
1106 select(owner->view()->
1109 owner->view()->update(1);
1114 case LFUN_LAYOUT_DOCUMENT:
1115 MenuLayoutDocument();
1118 case LFUN_LAYOUT_PARAGRAPH:
1119 MenuLayoutParagraph();
1122 case LFUN_LAYOUT_CHARACTER:
1123 MenuLayoutCharacter();
1126 case LFUN_LAYOUT_TABLE:
1129 if (argument == "true") flag = 1;
1130 MenuLayoutTable(flag);
1134 case LFUN_LAYOUT_PAPER:
1138 case LFUN_LAYOUT_QUOTES:
1142 case LFUN_LAYOUT_PREAMBLE:
1143 MenuLayoutPreamble();
1146 case LFUN_LAYOUT_SAVE_DEFAULT:
1150 case LFUN_DROP_LAYOUTS_CHOICE:
1151 owner->getToolbar()->combox->Show();
1157 owner->view()->SetState();
1158 owner->getMiniBuffer()->Set(CurrentState());
1190 case LFUN_UNDERLINE:
1194 case LFUN_FONT_SIZE:
1198 case LFUN_FONT_STATE:
1199 setMessage(CurrentState());
1202 case LFUN_UPCASE_WORD:
1203 owner->view()->update(-2);
1205 owner->view()->text->ChangeWordCase(LyXText::text_uppercase);
1206 owner->view()->update(1);
1210 case LFUN_LOWCASE_WORD:
1211 owner->view()->update(-2);
1213 owner->view()->text->ChangeWordCase(LyXText::text_lowercase);
1214 owner->view()->update(1);
1218 case LFUN_CAPITALIZE_WORD:
1219 owner->view()->update(-2);
1221 owner->view()->text->ChangeWordCase(LyXText::text_capitalization);
1222 owner->view()->update(1);
1226 case LFUN_INSERT_LABEL:
1227 MenuInsertLabel(argument.c_str());
1230 case LFUN_INSERT_REF:
1234 case LFUN_REFTOGGLE:
1237 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1239 if (inset->getFlag() == InsetRef::REF)
1240 inset->setFlag(InsetRef::PAGE_REF);
1242 inset->setFlag(InsetRef::REF);
1243 UpdateInset(owner->view(), inset);
1245 setErrorMessage(N_("No cross-reference to toggle"));
1252 owner->view()->restorePosition();
1258 string label(argument);
1259 if (label.empty()) {
1261 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1263 label = inset->getContents();
1266 if (!label.empty()) {
1267 owner->view()->savePosition();
1268 owner->view()->gotoLabel(label.c_str());
1273 case LFUN_MENU_OPEN_BY_NAME:
1274 owner->getMenus()->openByName(argument);
1275 break; // RVDK_PATCH_5
1277 case LFUN_SPELLCHECK:
1278 if (lyxrc->isp_command != "none")
1280 break; // RVDK_PATCH_5
1282 // --- Cursor Movements -----------------------------
1285 LyXText * tmptext = owner->view()->text;
1286 LyXDirection direction =
1287 tmptext->cursor.par->getParDirection();
1288 if(!tmptext->mark_set)
1289 owner->view()->beforeChange();
1290 owner->view()->update(-2);
1291 if (direction == LYX_DIR_RIGHT_TO_LEFT)
1292 tmptext->CursorLeft();
1293 if (tmptext->cursor.pos < tmptext->cursor.par->Last()
1294 && tmptext->cursor.par->GetChar(tmptext->cursor.pos)
1295 == LyXParagraph::META_INSET
1296 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)
1297 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)->Editable() == 2){
1298 Inset * tmpinset = tmptext->cursor.par->GetInset(tmptext->cursor.pos);
1299 setMessage(tmpinset->EditMessage());
1300 tmpinset->Edit(0, 0);
1303 if (direction == LYX_DIR_LEFT_TO_RIGHT)
1304 tmptext->CursorRight();
1305 owner->view()->text->FinishUndo();
1306 moveCursorUpdate(false);
1307 owner->getMiniBuffer()->Set(CurrentState());
1314 // This is soooo ugly. Isn`t it possible to make
1315 // it simpler? (Lgb)
1316 LyXText * txt = owner->view()->text;
1317 LyXDirection direction = txt->cursor.par->getParDirection();
1318 if(!txt->mark_set) owner->view()->beforeChange();
1319 owner->view()->update(-2);
1320 if (direction == LYX_DIR_LEFT_TO_RIGHT)
1322 if (txt->cursor.pos < txt->cursor.par->Last()
1323 && txt->cursor.par->GetChar(txt->cursor.pos)
1324 == LyXParagraph::META_INSET
1325 && txt->cursor.par->GetInset(txt->cursor.pos)
1326 && txt->cursor.par->GetInset(txt->cursor.pos)->Editable() == 2) {
1327 Inset * tmpinset = txt->cursor.par->GetInset(txt->cursor.pos);
1328 setMessage(tmpinset->EditMessage());
1329 tmpinset->Edit(tmpinset->width(owner->view()->painter(),
1330 txt->GetFont(txt->cursor.par,
1331 txt->cursor.pos)), 0);
1334 if (direction == LYX_DIR_RIGHT_TO_LEFT)
1337 owner->view()->text->FinishUndo();
1338 moveCursorUpdate(false);
1339 owner->getMiniBuffer()->Set(CurrentState());
1341 // This is soooo ugly. Isn`t it possible to make
1342 // it simpler? (Lgb)
1343 LyXText * txt = owner->view()->text;
1344 LyXDirection direction = txt->cursor.par->getParDirection();
1345 if(!txt->mark_set) owner->view()->beforeChange();
1346 owner->view()->update(-2);
1347 if (direction == LYX_DIR_LEFT_TO_RIGHT)
1349 if (txt->cursor.pos < txt->cursor.par->Last()
1350 && txt->cursor.par->GetChar(txt->cursor.pos)
1351 == LyXParagraph::META_INSET
1352 && txt->cursor.par->GetInset(txt->cursor.pos)
1353 && txt->cursor.par->GetInset(txt->cursor.pos)->Editable() == 2) {
1354 Inset * tmpinset = txt->cursor.par->GetInset(txt->cursor.pos);
1355 setMessage(tmpinset->EditMessage());
1356 tmpinset->Edit(tmpinset->Width(txt->GetFont(txt->cursor.par,
1357 txt->cursor.pos)), 0);
1360 if (direction == LYX_DIR_RIGHT_TO_LEFT)
1363 owner->view()->text->FinishUndo();
1364 moveCursorUpdate(false);
1365 owner->getMiniBuffer()->Set(CurrentState());
1371 if(!owner->view()->text->mark_set) owner->view()->beforeChange();
1372 owner->view()->update(-3);
1373 owner->view()->text->CursorUp();
1374 owner->view()->text->FinishUndo();
1375 moveCursorUpdate(false);
1376 owner->getMiniBuffer()->Set(CurrentState());
1380 if(!owner->view()->text->mark_set)
1381 owner->view()->beforeChange();
1382 owner->view()->update(-3);
1383 owner->view()->text->CursorDown();
1384 owner->view()->text->FinishUndo();
1385 moveCursorUpdate(false);
1386 owner->getMiniBuffer()->Set(CurrentState());
1389 case LFUN_UP_PARAGRAPH:
1390 if(!owner->view()->text->mark_set)
1391 owner->view()->beforeChange();
1392 owner->view()->update(-3);
1393 owner->view()->text->CursorUpParagraph();
1394 owner->view()->text->FinishUndo();
1395 moveCursorUpdate(false);
1396 owner->getMiniBuffer()->Set(CurrentState());
1399 case LFUN_DOWN_PARAGRAPH:
1400 if(!owner->view()->text->mark_set)
1401 owner->view()->beforeChange();
1402 owner->view()->update(-3);
1403 owner->view()->text->CursorDownParagraph();
1404 owner->view()->text->FinishUndo();
1405 moveCursorUpdate(false);
1406 owner->getMiniBuffer()->Set(CurrentState());
1410 if(!owner->view()->text->mark_set)
1411 owner->view()->beforeChange();
1412 owner->view()->update(-3);
1413 owner->view()->cursorPrevious();
1414 owner->view()->text->FinishUndo();
1415 moveCursorUpdate(false);
1416 owner->getMiniBuffer()->Set(CurrentState());
1420 if(!owner->view()->text->mark_set)
1421 owner->view()->beforeChange();
1422 owner->view()->update(-3);
1423 owner->view()->cursorNext();
1424 owner->view()->text->FinishUndo();
1425 moveCursorUpdate(false);
1426 owner->getMiniBuffer()->Set(CurrentState());
1430 if(!owner->view()->text->mark_set)
1431 owner->view()->beforeChange();
1432 owner->view()->update(-2);
1433 owner->view()->text->CursorHome();
1434 owner->view()->text->FinishUndo();
1435 moveCursorUpdate(false);
1436 owner->getMiniBuffer()->Set(CurrentState());
1440 if(!owner->view()->text->mark_set)
1441 owner->view()->beforeChange();
1442 owner->view()->update(-2);
1443 owner->view()->text->CursorEnd();
1444 owner->view()->text->FinishUndo();
1445 moveCursorUpdate(false);
1446 owner->getMiniBuffer()->Set(CurrentState());
1450 if(!owner->view()->text->mark_set)
1451 owner->view()->beforeChange();
1452 owner->view()->update(-2);
1453 owner->view()->text->CursorTab();
1454 owner->view()->text->FinishUndo();
1455 moveCursorUpdate(false);
1456 owner->getMiniBuffer()->Set(CurrentState());
1459 case LFUN_WORDRIGHT:
1460 if(!owner->view()->text->mark_set)
1461 owner->view()->beforeChange();
1462 owner->view()->update(-2);
1463 if (owner->view()->text->cursor.par->getParDirection()
1464 == LYX_DIR_LEFT_TO_RIGHT)
1465 owner->view()->text->CursorRightOneWord();
1467 owner->view()->text->CursorLeftOneWord();
1468 owner->view()->text->FinishUndo();
1469 moveCursorUpdate(false);
1470 owner->getMiniBuffer()->Set(CurrentState());
1474 if(!owner->view()->text->mark_set)
1475 owner->view()->beforeChange();
1476 owner->view()->update(-2);
1477 if (owner->view()->text->cursor.par->getParDirection()
1478 == LYX_DIR_LEFT_TO_RIGHT)
1479 owner->view()->text->CursorLeftOneWord();
1481 owner->view()->text->CursorRightOneWord();
1482 owner->view()->text->FinishUndo();
1483 moveCursorUpdate(false);
1484 owner->getMiniBuffer()->Set(CurrentState());
1487 case LFUN_BEGINNINGBUF:
1488 if(!owner->view()->text->mark_set)
1489 owner->view()->beforeChange();
1490 owner->view()->update(-2);
1491 owner->view()->text->CursorTop();
1492 owner->view()->text->FinishUndo();
1493 moveCursorUpdate(false);
1494 owner->getMiniBuffer()->Set(CurrentState());
1498 if(!owner->view()->text->mark_set)
1499 owner->view()->beforeChange();
1500 owner->view()->update(-2);
1501 owner->view()->text->CursorBottom();
1502 owner->view()->text->FinishUndo();
1503 moveCursorUpdate(false);
1504 owner->getMiniBuffer()->Set(CurrentState());
1508 /* cursor selection ---------------------------- */
1510 owner->view()->update(-2);
1511 if (owner->view()->text->cursor.par->getParDirection()
1512 == LYX_DIR_LEFT_TO_RIGHT)
1513 owner->view()->text->CursorRight();
1515 owner->view()->text->CursorLeft();
1516 owner->view()->text->FinishUndo();
1517 moveCursorUpdate(true);
1518 owner->getMiniBuffer()->Set(CurrentState());
1522 owner->view()->update(-2);
1523 if (owner->view()->text->cursor.par->getParDirection()
1524 == LYX_DIR_LEFT_TO_RIGHT)
1525 owner->view()->text->CursorLeft();
1527 owner->view()->text->CursorRight();
1528 owner->view()->text->FinishUndo();
1529 moveCursorUpdate(true);
1530 owner->getMiniBuffer()->Set(CurrentState());
1534 owner->view()->update(-2);
1535 owner->view()->text->CursorUp();
1536 owner->view()->text->FinishUndo();
1537 moveCursorUpdate(true);
1538 owner->getMiniBuffer()->Set(CurrentState());
1542 owner->view()->update(-2);
1543 owner->view()->text->CursorDown();
1544 owner->view()->text->FinishUndo();
1545 moveCursorUpdate(true);
1546 owner->getMiniBuffer()->Set(CurrentState());
1549 case LFUN_UP_PARAGRAPHSEL:
1550 owner->view()->update(-2);
1551 owner->view()->text->CursorUpParagraph();
1552 owner->view()->text->FinishUndo();
1553 moveCursorUpdate(true);
1554 owner->getMiniBuffer()->Set(CurrentState());
1557 case LFUN_DOWN_PARAGRAPHSEL:
1558 owner->view()->update(-2);
1559 owner->view()->text->CursorDownParagraph();
1560 owner->view()->text->FinishUndo();
1561 moveCursorUpdate(true);
1562 owner->getMiniBuffer()->Set(CurrentState());
1566 owner->view()->update(-2);
1567 owner->view()->cursorPrevious();
1568 owner->view()->text->FinishUndo();
1569 moveCursorUpdate(true);
1570 owner->getMiniBuffer()->Set(CurrentState());
1574 owner->view()->update(-2);
1575 owner->view()->cursorNext();
1576 owner->view()->text->FinishUndo();
1577 moveCursorUpdate(true);
1578 owner->getMiniBuffer()->Set(CurrentState());
1582 owner->view()->update(-2);
1583 owner->view()->text->CursorHome();
1584 owner->view()->text->FinishUndo();
1585 moveCursorUpdate(true);
1586 owner->getMiniBuffer()->Set(CurrentState());
1590 owner->view()->update(-2);
1591 owner->view()->text->CursorEnd();
1592 owner->view()->text->FinishUndo();
1593 moveCursorUpdate(true);
1594 owner->getMiniBuffer()->Set(CurrentState());
1597 case LFUN_WORDRIGHTSEL:
1598 owner->view()->update(-2);
1599 if (owner->view()->text->cursor.par->getParDirection()
1600 == LYX_DIR_LEFT_TO_RIGHT)
1601 owner->view()->text->CursorRightOneWord();
1603 owner->view()->text->CursorLeftOneWord();
1604 owner->view()->text->FinishUndo();
1605 moveCursorUpdate(true);
1606 owner->getMiniBuffer()->Set(CurrentState());
1609 case LFUN_WORDLEFTSEL:
1610 owner->view()->update(-2);
1611 if (owner->view()->text->cursor.par->getParDirection()
1612 == LYX_DIR_LEFT_TO_RIGHT)
1613 owner->view()->text->CursorLeftOneWord();
1615 owner->view()->text->CursorRightOneWord();
1616 owner->view()->text->FinishUndo();
1617 moveCursorUpdate(true);
1618 owner->getMiniBuffer()->Set(CurrentState());
1621 case LFUN_BEGINNINGBUFSEL:
1622 owner->view()->update(-2);
1623 owner->view()->text->CursorTop();
1624 owner->view()->text->FinishUndo();
1625 moveCursorUpdate(true);
1626 owner->getMiniBuffer()->Set(CurrentState());
1629 case LFUN_ENDBUFSEL:
1630 owner->view()->update(-2);
1631 owner->view()->text->CursorBottom();
1632 owner->view()->text->FinishUndo();
1633 moveCursorUpdate(true);
1634 owner->getMiniBuffer()->Set(CurrentState());
1637 // --- text changing commands ------------------------
1638 case LFUN_BREAKLINE:
1639 owner->view()->beforeChange();
1640 owner->view()->text->InsertChar(LyXParagraph::META_NEWLINE);
1641 owner->view()->smallUpdate(1);
1642 SetUpdateTimer(0.01);
1643 moveCursorUpdate(false);
1646 case LFUN_PROTECTEDSPACE:
1647 owner->view()->beforeChange();
1648 owner->view()->text->
1649 InsertChar(LyXParagraph::META_PROTECTED_SEPARATOR);
1650 owner->view()->smallUpdate(1);
1652 moveCursorUpdate(false);
1656 if(owner->view()->text->mark_set) {
1657 owner->view()->beforeChange();
1658 owner->view()->update(0);
1659 setMessage(N_("Mark removed"));
1661 owner->view()->beforeChange();
1662 owner->view()->text->mark_set = 1;
1663 owner->view()->update(0);
1664 setMessage(N_("Mark set"));
1666 owner->view()->text->sel_cursor =
1667 owner->view()->text->cursor;
1672 if (!owner->view()->text->selection) {
1673 owner->view()->text->Delete();
1674 owner->view()->text->sel_cursor =
1675 owner->view()->text->cursor;
1676 owner->view()->smallUpdate(1);
1677 // It is possible to make it a lot faster still
1678 // just comment out the lone below...
1679 owner->view()->getScreen()->ShowCursor();
1681 owner->view()->cut();
1684 moveCursorUpdate(false);
1685 owner->getMiniBuffer()->Set(CurrentState());
1686 owner->view()->SetState();
1689 case LFUN_DELETE_SKIP:
1691 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1693 LyXCursor cursor = owner->view()->text->cursor;
1696 if (!owner->view()->text->selection) {
1697 if (cursor.pos == cursor.par->Last()) {
1698 owner->view()->text->CursorRight();
1699 cursor = owner->view()->text->cursor;
1701 && !(cursor.par->added_space_top
1702 == VSpace (VSpace::NONE))) {
1703 owner->view()->text->SetParagraph
1704 (cursor.par->line_top,
1705 cursor.par->line_bottom,
1706 cursor.par->pagebreak_top,
1707 cursor.par->pagebreak_bottom,
1708 VSpace(VSpace::NONE),
1709 cursor.par->added_space_bottom,
1711 cursor.par->labelwidthstring, 0);
1712 owner->view()->text->CursorLeft();
1713 owner->view()->update (1);
1715 owner->view()->text->CursorLeft();
1716 owner->view()->text->Delete();
1717 owner->view()->text->sel_cursor =
1718 owner->view()->text->cursor;
1719 owner->view()->smallUpdate(1);
1722 owner->view()->text->Delete();
1723 owner->view()->text->sel_cursor =
1724 owner->view()->text->cursor;
1725 owner->view()->smallUpdate(1);
1728 owner->view()->cut();
1734 /* -------> Delete word forward. */
1735 case LFUN_DELETE_WORD_FORWARD:
1736 owner->view()->update(-2);
1738 owner->view()->text->DeleteWordForward();
1739 owner->view()->update( 1 );
1741 moveCursorUpdate(false);
1742 owner->getMiniBuffer()->Set(CurrentState());
1745 /* -------> Delete word backward. */
1746 case LFUN_DELETE_WORD_BACKWARD:
1747 owner->view()->update(-2);
1749 owner->view()->text->DeleteWordBackward();
1750 owner->view()->update( 1 );
1752 moveCursorUpdate(false);
1753 owner->getMiniBuffer()->Set(CurrentState());
1756 /* -------> Kill to end of line. */
1757 case LFUN_DELETE_LINE_FORWARD:
1759 owner->view()->update(-2);
1760 owner->view()->text->DeleteLineForward();
1761 owner->view()->update( 1 );
1763 moveCursorUpdate(false);
1766 /* -------> Set mark off. */
1768 owner->view()->beforeChange();
1769 owner->view()->update(0);
1770 owner->view()->text->sel_cursor =
1771 owner->view()->text->cursor;
1772 setMessage(N_("Mark off"));
1775 /* -------> Set mark on. */
1777 owner->view()->beforeChange();
1778 owner->view()->text->mark_set = 1;
1779 owner->view()->update( 0 );
1780 owner->view()->text->sel_cursor =
1781 owner->view()->text->cursor;
1782 setMessage(N_("Mark on"));
1785 case LFUN_BACKSPACE:
1788 if (!owner->view()->text->selection) {
1789 if (owner->getIntl()->getTrans()->backspace()) {
1790 owner->view()->text->Backspace();
1791 owner->view()->text->sel_cursor =
1792 owner->view()->text->cursor;
1793 owner->view()->smallUpdate(1);
1794 // It is possible to make it a lot faster still
1795 // just comment out the lone below...
1796 owner->view()->getScreen()->ShowCursor();
1799 owner->view()->cut();
1802 owner->getMiniBuffer()->Set(CurrentState());
1803 owner->view()->SetState();
1807 case LFUN_BACKSPACE_SKIP:
1809 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1811 LyXCursor cursor = owner->view()->text->cursor;
1814 if (!owner->view()->text->selection) {
1816 && !(cursor.par->added_space_top
1817 == VSpace (VSpace::NONE))) {
1818 owner->view()->text->SetParagraph
1819 (cursor.par->line_top,
1820 cursor.par->line_bottom,
1821 cursor.par->pagebreak_top,
1822 cursor.par->pagebreak_bottom,
1823 VSpace(VSpace::NONE), cursor.par->added_space_bottom,
1825 cursor.par->labelwidthstring, 0);
1826 owner->view()->update (1);
1828 owner->view()->text->Backspace();
1829 owner->view()->text->sel_cursor
1831 owner->view()->smallUpdate (1);
1834 owner->view()->cut();
1839 case LFUN_BREAKPARAGRAPH:
1841 owner->view()->beforeChange();
1842 owner->view()->text->BreakParagraph(0);
1843 owner->view()->smallUpdate(1);
1844 SetUpdateTimer(0.01);
1845 owner->view()->text->sel_cursor =
1846 owner->view()->text->cursor;
1847 owner->view()->SetState();
1848 owner->getMiniBuffer()->Set(CurrentState());
1852 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1854 owner->view()->beforeChange();
1855 owner->view()->text->BreakParagraph(1);
1856 owner->view()->smallUpdate(1);
1857 SetUpdateTimer(0.01);
1858 owner->view()->text->sel_cursor =
1859 owner->view()->text->cursor;
1860 owner->view()->SetState();
1861 owner->getMiniBuffer()->Set(CurrentState());
1865 case LFUN_BREAKPARAGRAPH_SKIP:
1867 // When at the beginning of a paragraph, remove
1868 // indentation and add a "defskip" at the top.
1869 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
1871 LyXCursor cursor = owner->view()->text->cursor;
1873 owner->view()->beforeChange();
1874 if (cursor.pos == 0) {
1875 if (cursor.par->added_space_top == VSpace(VSpace::NONE)) {
1876 owner->view()->text->SetParagraph
1877 (cursor.par->line_top,
1878 cursor.par->line_bottom,
1879 cursor.par->pagebreak_top,
1880 cursor.par->pagebreak_bottom,
1881 VSpace(VSpace::DEFSKIP), cursor.par->added_space_bottom,
1883 cursor.par->labelwidthstring, 1);
1884 owner->view()->update(1);
1888 owner->view()->text->BreakParagraph(0);
1889 owner->view()->smallUpdate(1);
1891 SetUpdateTimer(0.01);
1892 owner->view()->text->sel_cursor = cursor;
1893 owner->view()->SetState();
1894 owner->getMiniBuffer()->Set(CurrentState());
1899 owner->view()->beforeChange();
1900 owner->view()->text->InsertChar('\"'); // This " matches the single quote in the code
1901 owner->view()->smallUpdate(1);
1903 moveCursorUpdate(false);
1909 InsetCommand * new_inset;
1910 if (action == LFUN_HTMLURL)
1911 new_inset = new InsetUrl("htmlurl", "", "");
1913 new_inset = new InsetUrl("url", "", "");
1914 owner->view()->insertInset(new_inset);
1915 new_inset->Edit(0, 0);
1919 // --- lyxserver commands ----------------------------
1921 case LFUN_CHARATCURSOR:
1923 LyXParagraph::size_type pos =
1924 owner->view()->text->cursor.pos;
1925 if(pos < owner->view()->text->cursor.par->size())
1926 dispatch_buffer = owner->view()->text->
1927 cursor.par->text[pos];
1929 dispatch_buffer = "EOF";
1935 tostr(owner->view()->text->cursor.x) + ' '
1936 + tostr(owner->view()->text->cursor.y);
1943 sscanf(argument.c_str(), " %d %ld", &x, &y);
1944 owner->view()->text->SetCursorFromCoordinates(x, y);
1948 case LFUN_GETLAYOUT:
1950 tostr(owner->view()->text->cursor.par->layout);
1955 LyXFont * font = &(owner->view()->text->current_font);
1956 if(font->shape() == LyXFont::ITALIC_SHAPE)
1957 dispatch_buffer = 'E';
1958 else if(font->shape() == LyXFont::SMALLCAPS_SHAPE)
1959 dispatch_buffer = 'N';
1961 dispatch_buffer = '0';
1968 LyXFont * font = &(owner->view()->text->current_font);
1969 if(font->latex() == LyXFont::ON)
1970 dispatch_buffer = 'L';
1972 dispatch_buffer = '0';
1977 setMessage(owner->buffer()->fileName());
1978 lyxerr.debug() << "FNAME["
1979 << owner->buffer()->fileName()
1987 dispatch_buffer = buf;
1988 lyxserver->notifyClient(dispatch_buffer);
1992 case LFUN_GOTOFILEROW:
1994 char file_name[100];
1996 sscanf(argument.c_str(), " %s %d", file_name, &row);
1998 // Must replace extension of the file to be .lyx and get full path
1999 string s = ChangeExtension(string(file_name), ".lyx", false);
2001 // Either change buffer or load the file
2002 if (bufferlist.exists(s))
2003 owner->view()->buffer(bufferlist.getBuffer(s));
2005 owner->view()->buffer(bufferlist.loadLyXFile(s));
2008 owner->view()->setCursorFromRow(row);
2011 owner->view()->beforeChange();
2012 if (owner->view()->text->cursor.y >
2014 owner->view()->getWorkArea()->height() / 2
2016 owner->view()->getWorkArea()->h / 2
2019 owner->view()->getScreen()->
2020 Draw(owner->view()->text->cursor.y -
2022 owner->view()->getWorkArea()->height() / 2
2024 owner->view()->getWorkArea()->h / 2
2028 owner->view()->getScreen()->
2031 owner->view()->update(0);
2032 owner->view()->redraw();
2039 int qa = lyxaction.LookupFunc(argument.c_str());
2040 setMessage(lyxaction.helpText(static_cast<kb_action>(qa)));
2044 // --- accented characters ---------------------------
2047 case LFUN_CIRCUMFLEX:
2057 case LFUN_SPECIAL_CARON:
2060 case LFUN_HUNG_UMLAUT:
2066 if (keyseq.length == -1 && keyseq.getiso() != 0)
2067 c = keyseq.getiso();
2071 owner->getIntl()->getTrans()->
2072 deadkey(c, get_accent(action).accent,
2073 owner->view()->text);
2075 // Need to reset, in case the minibuffer calls these
2080 // copied verbatim from do_accent_char
2081 owner->view()->smallUpdate(1);
2083 owner->view()->text->sel_cursor =
2084 owner->view()->text->cursor;
2088 // --- toolbar ----------------------------------
2089 case LFUN_PUSH_TOOLBAR:
2091 int nth = strToInt(argument);
2092 if (lyxerr.debugging(Debug::TOOLBAR)) {
2093 lyxerr << "LFUN_PUSH_TOOLBAR: argument = `"
2094 << argument << "'\n"
2095 << "LFUN_PUSH_TOOLBAR: nth = `"
2096 << nth << "'" << endl;
2101 setErrorMessage(N_("Push-toolbar needs argument > 0"));
2103 owner->getToolbar()->push(nth);
2108 case LFUN_ADD_TO_TOOLBAR:
2110 if (lyxerr.debugging(Debug::TOOLBAR)) {
2111 lyxerr << "LFUN_ADD_TO_TOOLBAR:"
2112 "argument = `" << argument << '\'' << endl;
2114 string tmp(argument);
2115 //lyxerr <<string("Argument: ") + argument);
2116 //lyxerr <<string("Tmp : ") + tmp);
2119 setErrorMessage(N_("Usage: toolbar-add-to <LyX command>"));
2121 owner->getToolbar()->add(argument, false);
2122 owner->getToolbar()->set();
2127 // --- insert characters ----------------------------------------
2129 // --- Mathed stuff. If we are here, there is no locked inset yet.
2134 if (!greek_kb_flag) {
2136 setMessage(N_("Math greek mode on"));
2143 case LFUN_GREEK_TOGGLE:
2145 greek_kb_flag = greek_kb_flag ? 0 : 2;
2146 if (greek_kb_flag) {
2147 setMessage(N_("Math greek keyboard on"));
2149 setMessage(N_("Math greek keyboard off"));
2154 case LFUN_MATH_DELIM:
2155 case LFUN_INSERT_MATRIX:
2157 if (owner->view()->available()) {
2159 open_new_inset(new InsetFormula(false));
2161 the_locking_inset->LocalDispatch(action, argument.c_str());
2166 case LFUN_INSERT_MATH:
2168 math_insert_symbol(argument.c_str());
2172 case LFUN_MATH_DISPLAY:
2174 if (owner->view()->available())
2175 owner->view()->open_new_inset(new InsetFormula(true));
2179 case LFUN_MATH_MACRO:
2181 if (owner->view()->available()) {
2184 setErrorMessage(N_("Missing argument"));
2186 string s1 = token(s, ' ', 1);
2187 int na = s1.empty() ? 0: atoi(s1.c_str());
2189 open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2195 case LFUN_MATH_MODE: // Open or create a math inset
2198 if (owner->view()->available())
2199 owner->view()->open_new_inset(new InsetFormula);
2200 setMessage(N_("Math editor mode"));
2204 case LFUN_MATH_NUMBER:
2205 case LFUN_MATH_LIMITS:
2207 setErrorMessage(N_("This is only allowed in math mode!"));
2211 case LFUN_INSERT_CITATION:
2213 InsetCitation * new_inset = new InsetCitation();
2215 // The note, if any, must be after the key, delimited
2216 // by a | so both key and remark can have spaces.
2217 if (!argument.empty()) {
2218 string lsarg(argument);
2219 if (contains(lsarg, "|")) {
2220 new_inset->setContents(token(lsarg, '|', 0));
2221 new_inset->setOptions(token(lsarg, '|', 1));
2223 new_inset->setContents(lsarg);
2224 owner->view()->insertInset(new_inset);
2226 owner->view()->insertInset(new_inset);
2227 new_inset->Edit(0, 0);
2232 case LFUN_INSERT_BIBTEX:
2234 // ale970405+lasgoutt970425
2235 // The argument can be up to two tokens separated
2236 // by a space. The first one is the bibstyle.
2237 string lsarg(argument);
2238 string bibstyle = token(lsarg, ' ', 1);
2239 if (bibstyle.empty())
2241 InsetBibtex * new_inset
2242 = new InsetBibtex(token(lsarg, ' ', 0),
2246 owner->view()->insertInset(new_inset);
2247 if (lsarg.empty()) {
2248 new_inset->Edit(0, 0);
2253 // BibTeX data bases
2254 case LFUN_BIBDB_ADD:
2256 InsetBibtex * inset =
2257 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2259 inset->addDatabase(argument);
2264 case LFUN_BIBDB_DEL:
2266 InsetBibtex * inset =
2267 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2269 inset->delDatabase(argument);
2274 case LFUN_BIBTEX_STYLE:
2276 InsetBibtex * inset =
2277 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2279 inset->setOptions(argument);
2284 case LFUN_INDEX_INSERT:
2285 case LFUN_INDEX_INSERT_LAST:
2287 // Can't do that at the beginning of a paragraph.
2288 if (owner->view()->text->cursor.pos - 1 < 0)
2291 InsetIndex * new_inset = new InsetIndex();
2292 if (!argument.empty()) {
2293 string lsarg(argument);
2294 new_inset->setContents(lsarg);
2295 owner->view()->insertInset(new_inset);
2298 //get the current word for an argument
2299 LyXParagraph::size_type lastpos =
2300 owner->view()->text->cursor.pos - 1;
2301 // Get the current word. note that this must be done
2302 // before inserting the inset, or the inset will
2304 string curstring(owner->view()
2305 ->text->cursor.par->GetWord(lastpos));
2307 //make the new inset and write the current word into it
2308 InsetIndex * new_inset = new InsetIndex();
2310 new_inset->setContents(curstring);
2312 //don't edit it if the call was to INSERT_LAST
2313 if(action != LFUN_INDEX_INSERT_LAST) {
2314 new_inset->Edit(0, 0);
2316 //it looks blank on the screen unless
2317 //we do something. put it here.
2319 // move the cursor to the returned value of lastpos
2320 // but only for the auto-insert
2321 owner->view()->text->cursor.pos = lastpos;
2324 //put the new inset into the buffer.
2325 // there should be some way of knowing the user
2326 //cancelled & avoiding this, but i don't know how
2327 owner->view()->insertInset(new_inset);
2332 case LFUN_INDEX_PRINT:
2334 Inset * new_inset = new InsetPrintIndex(owner->buffer());
2335 owner->view()->insertInset(new_inset, "Standard", true);
2339 case LFUN_PARENTINSERT:
2341 lyxerr << "arg " << argument << endl;
2342 Inset * new_inset = new InsetParent(argument, owner->buffer());
2343 owner->view()->insertInset(new_inset, "Standard", true);
2347 case LFUN_CHILDINSERT:
2349 Inset * new_inset = new InsetInclude(argument,
2351 owner->view()->insertInset(new_inset, "Standard", true);
2352 new_inset->Edit(0, 0);
2356 case LFUN_CHILDOPEN:
2359 MakeAbsPath(argument,
2360 OnlyPath(owner->buffer()->fileName()));
2361 setMessage(N_("Opening child document ") +
2362 MakeDisplayPath(filename) + "...");
2363 owner->view()->savePosition();
2364 if (bufferlist.exists(filename))
2365 owner->view()->buffer(bufferlist.getBuffer(filename));
2367 owner->view()->buffer(bufferlist.loadLyXFile(filename));
2371 case LFUN_INSERT_NOTE:
2372 owner->view()->insertNote();
2375 case LFUN_INSERTFOOTNOTE:
2377 LyXParagraph::footnote_kind kind;
2378 if (argument == "footnote")
2379 { kind = LyXParagraph::FOOTNOTE; }
2380 else if (argument == "margin")
2381 { kind = LyXParagraph::MARGIN; }
2382 else if (argument == "figure")
2383 { kind = LyXParagraph::FIG; }
2384 else if (argument == "table")
2385 { kind = LyXParagraph::TAB; }
2386 else if (argument == "wide-fig")
2387 { kind = LyXParagraph::WIDE_FIG; }
2388 else if (argument == "wide-tab")
2389 { kind = LyXParagraph::WIDE_TAB; }
2390 else if (argument == "algorithm")
2391 { kind = LyXParagraph::ALGORITHM; }
2393 setErrorMessage(N_("Unknown kind of footnote"));
2396 owner->view()->text->InsertFootnoteEnvironment(kind);
2397 owner->view()->update(1);
2398 owner->view()->SetState();
2402 case LFUN_BUFFERBULLETSSELECT:
2406 case LFUN_TOGGLECURSORFOLLOW:
2407 cursor_follows_scrollbar = !cursor_follows_scrollbar;
2410 case LFUN_KMAP_OFF: // keymap off
2411 owner->getIntl()->KeyMapOn(false);
2414 case LFUN_KMAP_PRIM: // primary keymap
2415 owner->getIntl()->KeyMapPrim();
2418 case LFUN_KMAP_SEC: // secondary keymap
2419 owner->getIntl()->KeyMapSec();
2422 case LFUN_KMAP_TOGGLE: // toggle keymap
2423 owner->getIntl()->ToggleKeyMap();
2426 case LFUN_SELFINSERT:
2428 for (string::size_type i = 0; i < argument.length(); ++i) {
2429 owner->view()->text->InsertChar(argument[i]);
2430 // This needs to be in the loop, or else we
2431 // won't break lines correctly. (Asger)
2432 owner->view()->smallUpdate(1);
2435 owner->view()->text->sel_cursor =
2436 owner->view()->text->cursor;
2437 moveCursorUpdate(false);
2443 // argument contains ';'-terminated commands
2444 while (argument.find(';') != string::npos) {
2446 argument = split(argument, first, ';');
2452 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
2460 now_time_t = time(NULL);
2461 now_tm = localtime(&now_time_t);
2462 (void)setlocale(LC_TIME, "");
2463 if (!argument.empty())
2465 else if (arg.empty())
2466 arg = lyxrc->date_insert_format;
2467 datetmp_len = (int) strftime(datetmp, 32, arg.c_str(), now_tm);
2468 for (int i = 0; i < datetmp_len; i++) {
2469 owner->view()->text->InsertChar(datetmp[i]);
2470 owner->view()->smallUpdate(1);
2473 owner->view()->text->sel_cursor = owner->view()->text->cursor;
2474 moveCursorUpdate(false);
2478 case LFUN_SAVEPREFERENCES:
2480 Path p(user_lyxdir);
2481 lyxrc->write("preferences");
2485 case LFUN_UNKNOWN_ACTION:
2487 if(!owner->buffer()) {
2489 setErrorMessage(N_("No document open"));
2493 if (owner->buffer()->isReadonly()) {
2495 setErrorMessage(N_("Document is read only"));
2499 if (!argument.empty()) {
2501 /* Automatically delete the currently selected
2502 * text and replace it with what is being
2503 * typed in now. Depends on lyxrc settings
2504 * "auto_region_delete", which defaults to
2507 if ( lyxrc->auto_region_delete ) {
2508 if (owner->view()->text->selection){
2509 owner->view()->text->CutSelection(false);
2510 owner->view()->update(-1);
2514 owner->view()->beforeChange();
2515 for (string::size_type i = 0;
2516 i < argument.length(); ++i) {
2517 if (greek_kb_flag) {
2518 if (!math_insert_greek(argument[i]))
2519 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2521 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2524 owner->view()->smallUpdate(1);
2527 owner->view()->text->sel_cursor =
2528 owner->view()->text->cursor;
2529 moveCursorUpdate(false);
2532 // why is an "Unknown action" with empty
2533 // argument even dispatched in the first
2534 // place? I`ll probably change that. (Lgb)
2536 setErrorMessage(N_("Unknown action"));
2540 lyxerr << "A truly unknown func!" << endl;
2546 string res = getMessage();
2549 if (!commandshortcut.empty()) {
2550 string newbuf = owner->getMiniBuffer()->GetText();
2551 if (newbuf != commandshortcut) {
2552 owner->getMiniBuffer()->Set(newbuf
2558 owner->getMiniBuffer()->Set(string(_(res.c_str()))
2559 + " " + commandshortcut);
2566 void LyXFunc::setupLocalKeymap()
2568 keyseq.stdmap = keyseq.curmap = toplevel_keymap;
2569 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap;
2573 void LyXFunc::MenuNew(bool fromTemplate)
2575 string fname, initpath = lyxrc->document_path;
2578 if (owner->view()->available()) {
2579 string trypath = owner->buffer()->filepath;
2580 // If directory is writeable, use this as default.
2581 if (IsDirWriteable(trypath) == 1)
2586 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2587 fileDlg.SetButton(1, _("Templates"), lyxrc->template_path);
2588 fname = fileDlg.Select(_("Enter Filename for new document"),
2589 initpath, "*.lyx", _("newfile"));
2592 if (fname.empty()) {
2593 owner->getMiniBuffer()->Set(_("Canceled."));
2594 lyxerr.debug() << "New Document Cancelled." << endl;
2598 // get absolute path of file and make sure the filename ends
2600 string s = MakeAbsPath(fname);
2601 if (!IsLyXFilename(s))
2604 // Check if the document already is open
2605 if (bufferlist.exists(s)){
2606 switch(AskConfirmation(_("Document is already open:"),
2607 MakeDisplayPath(s, 50),
2608 _("Do you want to close that document now?\n"
2609 "('No' will just switch to the open version)")))
2611 case 1: // Yes: close the document
2612 if (!bufferlist.close(bufferlist.getBuffer(s)))
2613 // If close is canceled, we cancel here too.
2616 case 2: // No: switch to the open document
2617 owner->view()->buffer(bufferlist.getBuffer(s));
2619 case 3: // Cancel: Do nothing
2620 owner->getMiniBuffer()->Set(_("Canceled."));
2625 // Check whether the file already exists
2626 if (IsLyXFilename(s)) {
2628 if (fi.readable() &&
2629 AskQuestion(_("File already exists:"),
2630 MakeDisplayPath(s, 50),
2631 _("Do you want to open the document?"))) {
2633 owner->getMiniBuffer()->Set(_("Opening document"),
2634 MakeDisplayPath(s), "...");
2636 owner->view()->buffer(
2637 bufferlist.loadLyXFile(s));
2638 owner->getMiniBuffer()->Set(_("Document"),
2645 // The template stuff
2649 fname = fileDlg.Select(_("Choose template"),
2650 lyxrc->template_path,
2656 // find a free buffer
2657 lyxerr.debug() << "Find a free buffer." << endl;
2658 owner->view()->buffer(bufferlist.newFile(s, templname));
2662 void LyXFunc::MenuOpen()
2664 string initpath = lyxrc->document_path;
2667 if (owner->view()->available()) {
2668 string trypath = owner->buffer()->filepath;
2669 // If directory is writeable, use this as default.
2670 if (IsDirWriteable(trypath) == 1)
2676 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2677 fileDlg.SetButton(1, _("Examples"),
2678 AddPath(system_lyxdir, "examples"));
2679 string filename = fileDlg.Select(_("Select Document to Open"),
2683 // check selected filename
2684 if (filename.empty()) {
2685 owner->getMiniBuffer()->Set(_("Canceled."));
2689 // get absolute path of file and make sure the filename ends
2691 filename = MakeAbsPath(filename);
2692 if (!IsLyXFilename(filename))
2696 owner->getMiniBuffer()->Set(_("Opening document"),
2697 MakeDisplayPath(filename), "...");
2698 Buffer * openbuf = bufferlist.loadLyXFile(filename);
2700 owner->view()->buffer(openbuf);
2701 owner->getMiniBuffer()->Set(_("Document"),
2702 MakeDisplayPath(filename),
2705 owner->getMiniBuffer()->Set(_("Could not open document"),
2706 MakeDisplayPath(filename));
2711 void LyXFunc::doImportASCII(bool linorpar)
2713 string initpath = lyxrc->document_path;
2716 if (owner->view()->available()) {
2717 string trypath = owner->buffer()->filepath;
2718 // If directory is writeable, use this as default.
2719 if (IsDirWriteable(trypath) == 1)
2725 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2726 fileDlg.SetButton(1, _("Examples"),
2727 AddPath(system_lyxdir, "examples"));
2728 string filename = fileDlg.Select(_("Select ASCII file to Import"),
2732 // check selected filename
2733 if (filename.empty()) {
2734 owner->getMiniBuffer()->Set(_("Canceled."));
2738 // get absolute path of file
2739 filename = MakeAbsPath(filename);
2741 string s = ChangeExtension(filename, ".lyx", false);
2743 // Check if the document already is open
2744 if (bufferlist.exists(s)) {
2745 switch(AskConfirmation(_("Document is already open:"),
2746 MakeDisplayPath(s, 50),
2747 _("Do you want to close that document now?\n"
2748 "('No' will just switch to the open version)")))
2750 case 1: // Yes: close the document
2751 if (!bufferlist.close(bufferlist.getBuffer(s)))
2752 // If close is canceled, we cancel here too.
2755 case 2: // No: switch to the open document
2756 owner->view()->buffer(bufferlist.getBuffer(s));
2758 case 3: // Cancel: Do nothing
2759 owner->getMiniBuffer()->Set(_("Canceled."));
2764 // Check if a LyX document by the same root exists in filesystem
2765 FileInfo f(s, true);
2766 if (f.exist() && !AskQuestion(_("A document by the name"),
2768 _("already exists. Overwrite?"))) {
2769 owner->getMiniBuffer()->Set(_("Canceled."));
2773 owner->view()->buffer(bufferlist.newFile(s, string()));
2774 owner->getMiniBuffer()->Set(_("Importing ASCII file"),
2775 MakeDisplayPath(filename), "...");
2776 // Insert ASCII file
2777 InsertAsciiFile(filename, linorpar);
2778 owner->getMiniBuffer()->Set(_("ASCII file "),
2779 MakeDisplayPath(filename),
2784 void LyXFunc::doImportLaTeX(bool isnoweb)
2786 string initpath = lyxrc->document_path;
2789 if (owner->view()->available()) {
2790 string trypath = owner->buffer()->filepath;
2791 // If directory is writeable, use this as default.
2792 if (IsDirWriteable(trypath) == 1)
2798 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2799 fileDlg.SetButton(1, _("Examples"),
2800 AddPath(system_lyxdir, "examples"));
2803 filename = fileDlg.Select(_("Select Noweb file to Import"),
2806 filename = fileDlg.Select(_("Select LaTeX file to Import"),
2812 // check selected filename
2813 if (filename.empty()) {
2814 owner->getMiniBuffer()->Set(_("Canceled."));
2818 // get absolute path of file
2819 filename = MakeAbsPath(filename);
2821 // Check if the document already is open
2822 string LyXfilename = ChangeExtension(filename, ".lyx", false);
2823 if (bufferlist.exists(LyXfilename)){
2824 switch(AskConfirmation(_("Document is already open:"),
2825 MakeDisplayPath(LyXfilename, 50),
2826 _("Do you want to close that document now?\n"
2827 "('No' will just switch to the open version)")))
2829 case 1: // Yes: close the document
2830 if (!bufferlist.close(bufferlist.getBuffer(LyXfilename)))
2831 // If close is canceled, we cancel here too.
2834 case 2: // No: switch to the open document
2835 owner->view()->buffer(
2836 bufferlist.getBuffer(LyXfilename));
2838 case 3: // Cancel: Do nothing
2839 owner->getMiniBuffer()->Set(_("Canceled."));
2844 // Check if a LyX document by the same root exists in filesystem
2845 FileInfo f(LyXfilename, true);
2846 if (f.exist() && !AskQuestion(_("A document by the name"),
2847 MakeDisplayPath(LyXfilename),
2848 _("already exists. Overwrite?"))) {
2849 owner->getMiniBuffer()->Set(_("Canceled."));
2856 owner->getMiniBuffer()->Set(_("Importing LaTeX file"),
2857 MakeDisplayPath(filename), "...");
2858 ImportLaTeX myImport(filename);
2859 openbuf = myImport.run();
2861 owner->getMiniBuffer()->Set(_("Importing Noweb file"),
2862 MakeDisplayPath(filename), "...");
2863 ImportNoweb myImport(filename);
2864 openbuf = myImport.run();
2867 owner->view()->buffer(openbuf);
2868 owner->getMiniBuffer()->Set(isnoweb ?
2869 _("Noweb file ") : _("LateX file "),
2870 MakeDisplayPath(filename),
2873 owner->getMiniBuffer()->Set(isnoweb ?
2874 _("Could not import Noweb file") :
2875 _("Could not import LaTeX file"),
2876 MakeDisplayPath(filename));
2881 void LyXFunc::MenuInsertLyXFile(string const & filen)
2883 string filename = filen;
2885 if (filename.empty()) {
2886 // Launch a file browser
2887 string initpath = lyxrc->document_path;
2890 if (owner->view()->available()) {
2891 string trypath = owner->buffer()->filepath;
2892 // If directory is writeable, use this as default.
2893 if (IsDirWriteable(trypath) == 1)
2899 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2900 fileDlg.SetButton(1, _("Examples"),
2901 AddPath(system_lyxdir, "examples"));
2902 filename = fileDlg.Select(_("Select Document to Insert"),
2906 // check selected filename
2907 if (filename.empty()) {
2908 owner->getMiniBuffer()->Set(_("Canceled."));
2913 // get absolute path of file and make sure the filename ends
2915 filename = MakeAbsPath(filename);
2916 if (!IsLyXFilename(filename))
2920 owner->getMiniBuffer()->Set(_("Inserting document"),
2921 MakeDisplayPath(filename), "...");
2922 bool res = owner->view()->insertLyXFile(filename);
2924 owner->getMiniBuffer()->Set(_("Document"),
2925 MakeDisplayPath(filename),
2928 owner->getMiniBuffer()->Set(_("Could not insert document"),
2929 MakeDisplayPath(filename));
2934 void LyXFunc::reloadBuffer()
2936 string fn = owner->buffer()->fileName();
2937 if (bufferlist.close(owner->buffer()))
2938 owner->view()->buffer(bufferlist.loadLyXFile(fn));
2942 void LyXFunc::CloseBuffer()
2944 if (bufferlist.close(owner->buffer()) && !quitting) {
2945 if (bufferlist.empty()) {
2946 // need this otherwise SEGV may occur while trying to
2947 // set variables that don't exist
2948 // since there's no current buffer
2949 CloseAllBufferRelatedPopups();
2952 owner->view()->buffer(bufferlist.first());
2958 Inset * LyXFunc::getInsetByCode(Inset::Code code)
2962 LyXCursor cursor = owner->view()->text->cursor;
2963 LyXParagraph::size_type pos = cursor.pos;
2964 LyXParagraph * par = cursor.par;
2966 while (par && !found) {
2967 while ((inset = par->ReturnNextInsetPointer(pos))){
2968 if (inset->LyxCode() == code) {
2976 return found ? inset : 0;
2980 // Each "owner" should have it's own message method. lyxview and
2981 // the minibuffer would use the minibuffer, but lyxserver would
2982 // send an ERROR signal to its client. Alejandro 970603
2983 // This func is bit problematic when it comes to NLS, to make the
2984 // lyx servers client be language indepenent we must not translate
2985 // strings sent to this func.
2986 void LyXFunc::setErrorMessage(string const & m) const
2988 dispatch_buffer = m;
2993 void LyXFunc::setMessage(string const & m)
2995 dispatch_buffer = m;