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 "insets/insettext.h"
45 #include "insets/insetert.h"
46 #include "insets/insetgraphics.h"
47 #include "insets/insetfoot.h"
48 #include "mathed/formulamacro.h"
50 #include "spellchecker.h" // RVDK_PATCH_5
51 #include "minibuffer.h"
55 #include "lyx_gui_misc.h"
56 #include "support/filetools.h"
57 #include "support/FileInfo.h"
58 #include "support/syscall.h"
59 #include "support/lstrings.h"
60 #include "support/path.h"
65 #include "trans_mgr.h"
66 #include "ImportLaTeX.h"
67 #include "ImportNoweb.h"
72 extern bool cursor_follows_scrollbar;
74 extern void InsertAsciiFile(string const &, bool);
75 extern void math_insert_symbol(char const *);
76 extern Bool math_insert_greek(char const); // why "Bool"?
77 extern BufferList bufferlist;
78 extern LyXServer * lyxserver;
79 extern short greek_kb_flag;
80 extern FD_form_toc * fd_form_toc;
81 extern bool selection_possible;
83 extern kb_keymap * toplevel_keymap;
85 extern void MenuWrite(Buffer *);
86 extern void MenuWriteAs(Buffer *);
87 extern int MenuRunLaTeX(Buffer *);
88 extern int MenuBuildProg(Buffer *);
89 extern int MenuRunChktex(Buffer *);
90 extern bool CreatePostscript(Buffer *, bool);
91 extern void MenuPrint(Buffer *);
92 extern void MenuSendto();
93 extern void QuitLyX();
94 extern void MenuFax(Buffer *);
95 extern void MenuExport(Buffer *, string const &);
96 extern void MenuPasteSelection(char at);
97 extern LyXAction lyxaction;
99 extern tex_accent_struct get_accent(kb_action action);
101 extern void AutoSave();
102 extern void SetUpdateTimer(float timer = 0.3);
103 extern void FreeUpdateTimer();
104 extern bool PreviewDVI(Buffer *);
105 extern bool PreviewPostscript(Buffer *);
106 extern void MenuInsertLabel(char const *);
107 extern void MenuInsertRef();
108 extern void MenuLayoutCharacter();
109 extern void MenuLayoutParagraph();
110 extern void MenuLayoutDocument();
111 extern void MenuLayoutPaper();
112 extern void MenuLayoutTable(int flag);
113 extern void MenuLayoutQuotes();
114 extern void MenuLayoutPreamble();
115 extern void MenuLayoutSave();
116 extern void bulletForm();
118 extern Buffer * NewLyxFile(string const &);
119 extern void LoadLyXFile(string const &);
120 extern void Reconfigure(BufferView *);
122 extern LyXTextClass::size_type current_layout;
123 extern int getISOCodeFromLaTeX(char *);
125 extern void ShowLatexLog();
127 /* === globals =========================================================== */
129 bool LyXFunc::show_sc = true;
132 LyXFunc::LyXFunc(LyXView * o)
136 lyx_dead_action = LFUN_NOACTION;
137 lyx_calling_dead_action = LFUN_NOACTION;
142 // I changed this func slightly. I commented out the ...FinishUndo(),
143 // this means that all places that used to have a moveCursorUpdate, now
144 // have a ...FinishUndo() as the preceeding statement. I have also added
145 // a moveCursorUpdate to some of the functions that updated the cursor, but
146 // that did not show its new position.
148 void LyXFunc::moveCursorUpdate(bool selecting)
150 if (selecting || owner->view()->text->mark_set) {
151 owner->view()->text->SetSelection();
152 owner->view()->toggleToggle();
153 owner->view()->update(0);
155 owner->view()->update(-2); // this IS necessary
159 owner->view()->showCursor();
161 /* ---> Everytime the cursor is moved, show the current font state. */
162 // should this too me moved out of this func?
163 //owner->getMiniBuffer()->Set(CurrentState());
164 owner->view()->setState();
168 int LyXFunc::processKeyEvent(XEvent * ev)
172 XKeyEvent * keyevent = &ev->xkey;
173 KeySym keysym_return;
175 int num_bytes = LyXLookupString(ev, s_r, 10, &keysym_return);
176 s_r[num_bytes] = '\0';
178 if (lyxerr.debugging(Debug::KEY)) {
179 char * tmp = XKeysymToString(keysym_return);
180 string stm = (tmp ? tmp : "");
181 lyxerr << "KeySym is "
184 << keysym_return << "]"
185 << " and num_bytes is "
187 << " the string returned is \""
188 << s_r << '\"' << endl;
190 // Do nothing if we have nothing (JMarc)
191 if (num_bytes == 0 && keysym_return == NoSymbol) {
192 lyxerr[Debug::KEY] << "Empty kbd action (probably composing)"
197 // this function should be used always [asierra060396]
198 if (owner->view()->available() &&
199 owner->view()->the_locking_inset &&
200 keysym_return == XK_Escape) {
201 owner->view()->unlockInset(owner->view()->the_locking_inset);
202 owner->view()->text->CursorRight();
203 moveCursorUpdate(false);
204 owner->getMiniBuffer()->Set(CurrentState());
208 // Can we be sure that this will work for all X-Windows
209 // implementations? (Lgb)
210 // This code snippet makes lyx ignore some keys. Perhaps
211 // all of them should be explictly mentioned?
212 if((keysym_return >= XK_Shift_L && keysym_return <= XK_Hyper_R)
213 || keysym_return == XK_Mode_switch || keysym_return == 0x0)
216 // Do a one-deep top-level lookup for
217 // cancel and meta-fake keys. RVDK_PATCH_5
218 cancel_meta_seq.reset();
220 int action = cancel_meta_seq.addkey(keysym_return, keyevent->state
221 &(ShiftMask|ControlMask
224 // When not cancel or meta-fake, do the normal lookup.
225 // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
226 // Mostly, meta_fake_bit = 0. RVDK_PATCH_5.
227 if ( (action != LFUN_CANCEL) && (action != LFUN_META_FAKE) ) {
229 // remove Caps Lock and Mod2 as a modifiers
230 action = keyseq.addkey(keysym_return,
231 (keyevent->state | meta_fake_bit)
232 &(ShiftMask|ControlMask
235 // Dont remove this unless you know what you are doing.
238 if (action == 0) action = LFUN_PREFIX;
240 if (lyxerr.debugging(Debug::KEY)) {
246 << num_bytes << "]" << endl;
249 // already here we know if it any point in going further
250 // why not return already here if action == -1 and
251 // num_bytes == 0? (Lgb)
253 if(keyseq.length > 1 || keyseq.length < -1) {
256 owner->getMiniBuffer()->Set(buf);
260 if (keyseq.length < -1) { // unknown key sequence...
264 owner->getMiniBuffer()->Set(_("Unknown sequence:"), buf);
268 char isochar = keyseq.getiso();
269 if (!(keyevent->state&ControlMask) &&
270 !(keyevent->state&Mod1Mask) &&
271 (isochar && keysym_return < 0xF000)) {
274 if (argument.empty()) {
275 lyxerr.debug() << "Empty argument!" << endl;
276 // This can`t possibly be of any use
277 // so we`ll skip the dispatch.
281 if (action == LFUN_SELFINSERT) {
285 bool tmp_sc = show_sc;
287 Dispatch(action, argument.c_str());
294 LyXFunc::func_status LyXFunc::getStatus(int ac) const
297 func_status flag = LyXFunc::OK;
299 Buffer * buf = owner->buffer();
301 if (lyxaction.isPseudoAction(ac))
302 action = lyxaction.retrieveActionArg(ac, argument);
304 action = static_cast<kb_action>(ac);
306 if (action == LFUN_UNKNOWN_ACTION) {
307 setErrorMessage(N_("Unknown action"));
308 return LyXFunc::Unknown;
311 // Check whether we need a buffer
312 if (!lyxaction.funcHasFlag(action, LyXAction::NoBuffer)) {
313 // Yes we need a buffer, do we have one?
316 // Can we use a readonly buffer?
317 if (buf->isReadonly() &&
318 !lyxaction.funcHasFlag(action,
319 LyXAction::ReadOnly)) {
321 setErrorMessage(N_("Document is read-only"));
322 flag |= LyXFunc::Disabled;
326 setErrorMessage(N_("Command not allowed with"
327 "out any document open"));
328 flag |= LyXFunc::Disabled;
332 if (flag & LyXFunc::Disabled)
335 // I would really like to avoid having this switch and rather try to
336 // encode this in the function itself.
337 static bool noLaTeX = lyxrc->latex_command == "none";
338 bool disable = false;
341 disable = noLaTeX || lyxrc->view_dvi_command == "none";
344 disable = noLaTeX || lyxrc->view_ps_command == "none";
351 disable = noLaTeX || lyxrc->print_command == "none";
354 disable = noLaTeX || lyxrc->fax_command == "none";
357 if (argument == "latex")
358 disable = lyxrc->relyx_command == "none";
361 if (argument == "dvi" || argument == "postscript")
363 if (argument == "html")
364 disable = lyxrc->html_command == "none";
367 disable = buf->undostack.empty();
370 disable = buf->redostack.empty();
372 case LFUN_SPELLCHECK:
373 disable = lyxrc->isp_command == "none";
376 disable = lyxrc->chktex_command == "none";
378 case LFUN_LAYOUT_TABLE:
379 disable = ! owner->view()->text->cursor.par->table;
385 flag |= LyXFunc::Disabled;
388 func_status box = LyXFunc::ToggleOff;
389 LyXFont font = owner->view()->text->real_current_font;
392 if (font.emph() == LyXFont::ON)
393 box = LyXFunc::ToggleOn;
396 if (font.noun() == LyXFont::ON)
397 box = LyXFunc::ToggleOn;
400 if (font.series() == LyXFont::BOLD_SERIES)
401 box = LyXFunc::ToggleOn;
404 if (font.latex() == LyXFont::ON)
405 box = LyXFunc::ToggleOn;
408 if (font.direction() == LyXFont::RTL_DIR)
409 box = LyXFunc::ToggleOn;
422 string LyXFunc::Dispatch(string const & s)
424 // Split command string into command and argument
425 string cmd, line = frontStrip(s);
426 string arg = strip(frontStrip(split(line, cmd, ' ')));
428 return Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
432 string LyXFunc::Dispatch(int ac,
433 char const * do_not_use_this_arg)
438 // we have not done anything wrong yet.
440 dispatch_buffer.clear();
442 // if action is a pseudo-action, we need the real action
443 if (lyxaction.isPseudoAction(ac)) {
445 action = static_cast<kb_action>
446 (lyxaction.retrieveActionArg(ac, tmparg));
450 action = static_cast<kb_action>(ac);
451 if (do_not_use_this_arg)
452 argument = do_not_use_this_arg; // except here
455 selection_possible = false;
457 if (owner->view()->available())
458 owner->view()->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*>(
532 owner->view()->text->cursor.par->
533 GetInset(owner->view()->text->
536 inset->Edit(owner->view(),slx,sly,0);
538 } else if (action == LFUN_REDO) {
540 UpdatableInset * inset = owner->view()->
542 inset->GetCursorPos(slx, sly);
543 owner->view()->unlockInset(inset);
544 owner->view()->menuRedo();
545 inset = static_cast<UpdatableInset*>(
546 owner->view()->text->cursor.par->
547 GetInset(owner->view()->text->
550 inset->Edit(owner->view(),slx,sly,0);
552 } else if (owner->view()->the_locking_inset->
553 LocalDispatch(owner->view(), action,
555 UpdatableInset::DISPATCHED)
558 setMessage(N_("Text mode"));
559 LyXDirection direction = owner->view()->text->
560 cursor.par->getParDirection();
561 if ((action == -1) ||
562 ((action == LFUN_RIGHT) &&
563 (direction == LYX_DIR_LEFT_TO_RIGHT))) {
564 owner->view()->text->CursorRight();
565 moveCursorUpdate(false);
566 owner->getMiniBuffer()->
569 if ((action == LFUN_LEFT) &&
570 (direction == LYX_DIR_RIGHT_TO_LEFT)) {
571 owner->view()->text->CursorRight();
572 moveCursorUpdate(false);
573 owner->getMiniBuffer()->
576 if ((action == LFUN_LEFT) ||
577 (action == LFUN_RIGHT))
584 // --- Misc -------------------------------------------
585 case LFUN_WORDFINDFORWARD :
586 case LFUN_WORDFINDBACKWARD : {
587 static string last_search;
588 string searched_string;
590 if (!argument.empty()) {
591 last_search = argument;
592 searched_string = argument;
594 searched_string = last_search;
597 LyXText * ltCur = owner->view()->text ;
599 if (!searched_string.empty() &&
600 ((action == LFUN_WORDFINDBACKWARD) ?
601 ltCur->SearchBackward(searched_string.c_str()) :
602 ltCur->SearchForward(searched_string.c_str()))) {
604 // ??? What is that ???
605 owner->view()->update(-2);
608 // clear the selection (if there is any)
609 owner->view()->toggleSelection();
610 owner->view()->text->ClearSelection();
612 // Move cursor so that successive C-s 's will not stand in place.
613 if( action == LFUN_WORDFINDFORWARD )
614 owner->view()->text->CursorRightOneWord();
615 owner->view()->text->FinishUndo();
616 moveCursorUpdate(false);
619 // set the new selection
620 // SetSelectionOverLenChars(owner->view()->currentBuffer()->text, iLenSelected);
621 owner->view()->toggleSelection(false);
625 // REMOVED : if (owner->view()->getWorkArea()->focus)
626 owner->view()->showCursor();
632 if (owner->view()->available()) {
633 owner->view()->update(-2);
636 keyseq.print(buf, true);
637 owner->getMiniBuffer()->Set(buf, string(), string(), 1);
641 // --- Misc -------------------------------------------
642 case LFUN_EXEC_COMMAND:
643 owner->getMiniBuffer()->ExecCommand();
646 case LFUN_CANCEL: // RVDK_PATCH_5
649 if(owner->view()->available())
650 // cancel any selection
651 Dispatch(LFUN_MARK_OFF, 0);
652 setMessage(N_("Cancel"));
655 case LFUN_META_FAKE: // RVDK_PATCH_5
657 meta_fake_bit = Mod1Mask;
659 keyseq.print(buf, true);
660 string res = string("M-") + buf;
661 setMessage(buf); // RVDK_PATCH_5
665 case LFUN_READ_ONLY_TOGGLE:
666 if (owner->buffer()->lyxvc.inUse()) {
667 owner->buffer()->lyxvc.toggleReadOnly();
669 owner->buffer()->setReadonly(
670 !owner->buffer()->isReadonly());
674 case LFUN_CENTER: // this is center and redraw.
675 owner->view()->center();
679 if (owner->view()->available()) {
680 owner->view()->text->toggleAppendix();
681 owner->view()->update(1);
685 // --- Menus -----------------------------------------------
690 case LFUN_MENUNEWTMPLT:
698 case LFUN_CLOSEBUFFER:
703 owner->getMiniBuffer()->Set(_("Saving document"),
704 MakeDisplayPath(owner->buffer()->fileName()),
706 MenuWrite(owner->buffer());
707 //owner->getMiniBuffer()->
708 // Set(_("Document saved as"),
709 // MakeDisplayPath(owner->buffer()->fileName()));
711 //owner->getMiniBuffer()->Set(_("Save failed!"));
715 case LFUN_MENUWRITEAS:
716 MenuWriteAs(owner->buffer());
719 case LFUN_MENURELOAD:
724 PreviewDVI(owner->buffer());
728 PreviewPostscript(owner->buffer());
732 MenuRunLaTeX(owner->buffer());
736 MenuBuildProg(owner->buffer());
740 MenuRunChktex(owner->buffer());
744 CreatePostscript(owner->buffer(), false);
748 MenuPrint(owner->buffer());
752 MenuFax(owner->buffer());
756 MenuExport(owner->buffer(), argument);
761 //needs argument as string
762 string imtyp = argument;
765 if (imtyp == "latex") {
766 doImportLaTeX(false);
769 else if (imtyp == "ascii") {
770 doImportASCII(false);
771 } else if (imtyp == "asciiparagraph") {
774 } else if (imtyp == "noweb") {
777 setErrorMessage(string(N_("Unknown import type: "))
789 if (fd_form_toc->form_toc->visible) {
790 fl_raise_form(fd_form_toc->form_toc);
792 static int ow = -1, oh;
793 fl_show_form(fd_form_toc->form_toc,
795 FL_FREE_SIZE, FL_FULLBORDER,
796 _("Table of Contents"));
798 ow = fd_form_toc->form_toc->w;
799 oh = fd_form_toc->form_toc->h;
801 fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
805 case LFUN_TOC_INSERT:
807 Inset * new_inset = new InsetTOC(owner->buffer());
808 owner->view()->insertInset(new_inset, "Standard", true);
812 case LFUN_LOF_INSERT:
814 Inset * new_inset = new InsetLOF(owner->buffer());
815 owner->view()->insertInset(new_inset, "Standard", true);
819 case LFUN_LOA_INSERT:
821 Inset * new_inset = new InsetLOA(owner->buffer());
822 owner->view()->insertInset(new_inset, "Standard", true);
826 case LFUN_LOT_INSERT:
828 Inset * new_inset = new InsetLOT(owner->buffer());
829 owner->view()->insertInset(new_inset, "Standard", true);
841 case LFUN_INSERT_GRAPHICS:
843 Inset * new_inset = new InsetGraphics;
844 owner->view()->insertInset(new_inset);
853 owner->view()->menuUndo();
857 owner->view()->menuRedo();
860 case LFUN_MENUSEARCH:
862 // Ok this is one _very_ bad solution, but I think that some
863 // of this will be rewritten as part of GUI indep anyway.
865 static LyXFindReplace FR_;
866 FR_.StartSearch(owner->view());
872 owner->view()->paste();
875 case LFUN_PASTESELECTION:
878 if (argument == "paragraph") asPara = true;
879 MenuPasteSelection(asPara);
884 owner->view()->cut();
888 owner->view()->copy();
891 case LFUN_LAYOUT_COPY:
892 owner->view()->copyEnvironment();
895 case LFUN_LAYOUT_PASTE:
896 owner->view()->pasteEnvironment();
900 owner->view()->gotoError();
903 case LFUN_REMOVEERRORS:
904 if (owner->view()->removeAutoInsets()) {
905 owner->view()->redraw();
906 owner->view()->fitCursor();
907 owner->view()->updateScrollbar();
912 owner->view()->gotoNote();
916 owner->view()->openStuff();
919 case LFUN_HYPHENATION:
920 owner->view()->hyphenationPoint();
924 owner->view()->ldots();
927 case LFUN_END_OF_SENTENCE:
928 owner->view()->endOfSentenceDot();
931 case LFUN_MENU_SEPARATOR:
932 owner->view()->menuSeparator();
936 owner->view()->hfill();
940 changeDepth(owner->view(), 0);
944 changeDepth(owner->view(), -1);
947 case LFUN_DEPTH_PLUS:
948 changeDepth(owner->view(), 1);
957 owner->view()->setState();
958 owner->getMiniBuffer()->Set(CurrentState());
965 case LFUN_RECONFIGURE:
966 Reconfigure(owner->view());
970 if (owner->view()->available()
971 && !owner->view()->text->selection
972 && owner->view()->text->cursor.par->footnoteflag
973 != LyXParagraph::NO_FOOTNOTE)
974 { // only melt footnotes with FOOTMELT, not margins etc
975 if(owner->view()->text->cursor.par->footnotekind == LyXParagraph::FOOTNOTE)
980 owner->view()->setState();
983 case LFUN_MARGINMELT:
984 if (owner->view()->available()
985 && !owner->view()->text->selection
986 && owner->view()->text->cursor.par->footnoteflag
987 != LyXParagraph::NO_FOOTNOTE) {
989 if(owner->view()->text->cursor.par->footnotekind == LyXParagraph::MARGIN)
992 Margin(owner->view());
993 owner->view()->setState();
996 // --- version control -------------------------------
997 case LFUN_VC_REGISTER:
999 if (!owner->buffer()->lyxvc.inUse())
1000 owner->buffer()->lyxvc.registrer();
1004 case LFUN_VC_CHECKIN:
1006 if (owner->buffer()->lyxvc.inUse()
1007 && !owner->buffer()->isReadonly())
1008 owner->buffer()->lyxvc.checkIn();
1012 case LFUN_VC_CHECKOUT:
1014 if (owner->buffer()->lyxvc.inUse()
1015 && owner->buffer()->isReadonly())
1016 owner->buffer()->lyxvc.checkOut();
1020 case LFUN_VC_REVERT:
1022 owner->buffer()->lyxvc.revert();
1028 owner->buffer()->lyxvc.undoLast();
1032 case LFUN_VC_HISTORY:
1034 owner->buffer()->lyxvc.showLog();
1038 // --- buffers ----------------------------------------
1040 case LFUN_FILE_INSERT:
1042 MenuInsertLyXFile(argument);
1046 case LFUN_FILE_INSERT_ASCII:
1048 bool asPara = (argument == "paragraph");
1049 InsertAsciiFile(string(), asPara);
1055 // servercmd: argument must be <file>:<template>
1056 Buffer * tmpbuf = NewLyxFile(argument);
1058 owner->view()->buffer(tmpbuf);
1062 case LFUN_FILE_OPEN:
1063 owner->view()->buffer(bufferlist.loadLyXFile(argument));
1066 case LFUN_LATEX_LOG:
1072 lyxerr.debug() << "LFUN_LAYOUTNO: (arg) " << argument << endl;
1073 int sel = strToInt(argument);
1074 lyxerr.debug() << "LFUN_LAYOUTNO: (sel) "<< sel << endl;
1076 // Should this give a setMessage instead?
1078 return string(); // illegal argument
1080 --sel; // sel 1..., but layout 0...
1082 // Pretend we got the name instead.
1083 Dispatch(int(LFUN_LAYOUT),
1084 textclasslist.NameOfLayout(owner->view()->
1093 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1094 << argument << endl;
1096 // Derive layout number from given argument (string)
1097 // and current buffer's textclass (number). */
1098 LyXTextClassList::ClassList::size_type tclass =
1099 owner->view()->text->parameters->textclass;
1100 pair <bool, LyXTextClass::size_type> layout =
1101 textclasslist.NumberOfLayout(tclass, argument);
1103 // If the entry is obsolete, use the new one instead.
1105 string obs = textclasslist.Style(tclass,layout.second)
1109 textclasslist.NumberOfLayout(tclass, obs);
1112 // see if we found the layout number:
1113 if (!layout.first) {
1114 setErrorMessage(string(N_("Layout ")) + argument +
1119 if (current_layout != layout.second) {
1120 owner->view()->hideCursor();
1121 current_layout = layout.second;
1122 owner->view()->update(-2);
1123 owner->view()->text->
1124 SetLayout(layout.second);
1125 owner->getToolbar()->combox->
1126 select(owner->view()->
1129 owner->view()->update(1);
1134 case LFUN_LAYOUT_DOCUMENT:
1135 MenuLayoutDocument();
1138 case LFUN_LAYOUT_PARAGRAPH:
1139 MenuLayoutParagraph();
1142 case LFUN_LAYOUT_CHARACTER:
1143 MenuLayoutCharacter();
1146 case LFUN_LAYOUT_TABLE:
1149 if (argument == "true") flag = 1;
1150 MenuLayoutTable(flag);
1154 case LFUN_LAYOUT_PAPER:
1158 case LFUN_LAYOUT_QUOTES:
1162 case LFUN_LAYOUT_PREAMBLE:
1163 MenuLayoutPreamble();
1166 case LFUN_LAYOUT_SAVE_DEFAULT:
1170 case LFUN_DROP_LAYOUTS_CHOICE:
1171 owner->getToolbar()->combox->Show();
1177 owner->view()->setState();
1178 owner->getMiniBuffer()->Set(CurrentState());
1210 case LFUN_UNDERLINE:
1214 case LFUN_FONT_SIZE:
1218 case LFUN_FONT_STATE:
1219 setMessage(CurrentState());
1222 case LFUN_UPCASE_WORD:
1223 owner->view()->update(-2);
1225 owner->view()->text->ChangeWordCase(LyXText::text_uppercase);
1226 owner->view()->update(1);
1230 case LFUN_LOWCASE_WORD:
1231 owner->view()->update(-2);
1233 owner->view()->text->ChangeWordCase(LyXText::text_lowercase);
1234 owner->view()->update(1);
1238 case LFUN_CAPITALIZE_WORD:
1239 owner->view()->update(-2);
1241 owner->view()->text->ChangeWordCase(LyXText::text_capitalization);
1242 owner->view()->update(1);
1246 case LFUN_INSERT_LABEL:
1247 MenuInsertLabel(argument.c_str());
1250 case LFUN_INSERT_REF:
1254 case LFUN_REFTOGGLE:
1257 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1259 if (inset->getFlag() == InsetRef::REF)
1260 inset->setFlag(InsetRef::PAGE_REF);
1262 inset->setFlag(InsetRef::REF);
1263 owner->view()->updateInset(inset, true);
1265 setErrorMessage(N_("No cross-reference to toggle"));
1272 owner->view()->restorePosition();
1278 string label(argument);
1279 if (label.empty()) {
1281 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1283 label = inset->getContents();
1286 if (!label.empty()) {
1287 owner->view()->savePosition();
1288 owner->view()->gotoLabel(label.c_str());
1293 case LFUN_MENU_OPEN_BY_NAME:
1294 owner->getMenus()->openByName(argument);
1295 break; // RVDK_PATCH_5
1297 case LFUN_SPELLCHECK:
1298 if (lyxrc->isp_command != "none")
1299 ShowSpellChecker(owner->view());
1300 break; // RVDK_PATCH_5
1302 // --- Cursor Movements -----------------------------
1305 LyXText * tmptext = owner->view()->text;
1306 LyXDirection direction =
1307 tmptext->cursor.par->getParDirection();
1308 if(!tmptext->mark_set)
1309 owner->view()->beforeChange();
1310 owner->view()->update(-2);
1311 if (direction == LYX_DIR_RIGHT_TO_LEFT)
1312 tmptext->CursorLeft();
1313 if (tmptext->cursor.pos < tmptext->cursor.par->Last()
1314 && tmptext->cursor.par->GetChar(tmptext->cursor.pos)
1315 == LyXParagraph::META_INSET
1316 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)
1317 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)->Editable() == Inset::HIGHLY_EDITABLE){
1318 Inset * tmpinset = tmptext->cursor.par->GetInset(tmptext->cursor.pos);
1319 setMessage(tmpinset->EditMessage());
1320 tmpinset->Edit(owner->view(), 0, 0, 0);
1323 if (direction == LYX_DIR_LEFT_TO_RIGHT)
1324 tmptext->CursorRight();
1325 owner->view()->text->FinishUndo();
1326 moveCursorUpdate(false);
1327 owner->getMiniBuffer()->Set(CurrentState());
1333 // This is soooo ugly. Isn`t it possible to make
1334 // it simpler? (Lgb)
1335 LyXText * txt = owner->view()->text;
1336 LyXDirection direction = txt->cursor.par->getParDirection();
1337 if(!txt->mark_set) owner->view()->beforeChange();
1338 owner->view()->update(-2);
1339 if (direction == LYX_DIR_LEFT_TO_RIGHT)
1341 if (txt->cursor.pos < txt->cursor.par->Last()
1342 && txt->cursor.par->GetChar(txt->cursor.pos)
1343 == LyXParagraph::META_INSET
1344 && txt->cursor.par->GetInset(txt->cursor.pos)
1345 && txt->cursor.par->GetInset(txt->cursor.pos)->Editable() == Inset::HIGHLY_EDITABLE) {
1346 Inset * tmpinset = txt->cursor.par->GetInset(txt->cursor.pos);
1347 setMessage(tmpinset->EditMessage());
1348 tmpinset->Edit(owner->view(),
1349 tmpinset->width(owner->view()->painter(),
1350 txt->GetFont(txt->cursor.par,
1355 if (direction == LYX_DIR_RIGHT_TO_LEFT)
1358 owner->view()->text->FinishUndo();
1359 moveCursorUpdate(false);
1360 owner->getMiniBuffer()->Set(CurrentState());
1365 if(!owner->view()->text->mark_set) owner->view()->beforeChange();
1366 owner->view()->update(-3);
1367 owner->view()->text->CursorUp();
1368 owner->view()->text->FinishUndo();
1369 moveCursorUpdate(false);
1370 owner->getMiniBuffer()->Set(CurrentState());
1374 if(!owner->view()->text->mark_set)
1375 owner->view()->beforeChange();
1376 owner->view()->update(-3);
1377 owner->view()->text->CursorDown();
1378 owner->view()->text->FinishUndo();
1379 moveCursorUpdate(false);
1380 owner->getMiniBuffer()->Set(CurrentState());
1383 case LFUN_UP_PARAGRAPH:
1384 if(!owner->view()->text->mark_set)
1385 owner->view()->beforeChange();
1386 owner->view()->update(-3);
1387 owner->view()->text->CursorUpParagraph();
1388 owner->view()->text->FinishUndo();
1389 moveCursorUpdate(false);
1390 owner->getMiniBuffer()->Set(CurrentState());
1393 case LFUN_DOWN_PARAGRAPH:
1394 if(!owner->view()->text->mark_set)
1395 owner->view()->beforeChange();
1396 owner->view()->update(-3);
1397 owner->view()->text->CursorDownParagraph();
1398 owner->view()->text->FinishUndo();
1399 moveCursorUpdate(false);
1400 owner->getMiniBuffer()->Set(CurrentState());
1404 if(!owner->view()->text->mark_set)
1405 owner->view()->beforeChange();
1406 owner->view()->update(-3);
1407 owner->view()->cursorPrevious();
1408 owner->view()->text->FinishUndo();
1409 moveCursorUpdate(false);
1410 owner->getMiniBuffer()->Set(CurrentState());
1414 if(!owner->view()->text->mark_set)
1415 owner->view()->beforeChange();
1416 owner->view()->update(-3);
1417 owner->view()->cursorNext();
1418 owner->view()->text->FinishUndo();
1419 moveCursorUpdate(false);
1420 owner->getMiniBuffer()->Set(CurrentState());
1424 if(!owner->view()->text->mark_set)
1425 owner->view()->beforeChange();
1426 owner->view()->update(-2);
1427 owner->view()->text->CursorHome();
1428 owner->view()->text->FinishUndo();
1429 moveCursorUpdate(false);
1430 owner->getMiniBuffer()->Set(CurrentState());
1434 if(!owner->view()->text->mark_set)
1435 owner->view()->beforeChange();
1436 owner->view()->update(-2);
1437 owner->view()->text->CursorEnd();
1438 owner->view()->text->FinishUndo();
1439 moveCursorUpdate(false);
1440 owner->getMiniBuffer()->Set(CurrentState());
1444 if(!owner->view()->text->mark_set)
1445 owner->view()->beforeChange();
1446 owner->view()->update(-2);
1447 owner->view()->text->CursorTab();
1448 owner->view()->text->FinishUndo();
1449 moveCursorUpdate(false);
1450 owner->getMiniBuffer()->Set(CurrentState());
1453 case LFUN_WORDRIGHT:
1454 if(!owner->view()->text->mark_set)
1455 owner->view()->beforeChange();
1456 owner->view()->update(-2);
1457 if (owner->view()->text->cursor.par->getParDirection()
1458 == LYX_DIR_LEFT_TO_RIGHT)
1459 owner->view()->text->CursorRightOneWord();
1461 owner->view()->text->CursorLeftOneWord();
1462 owner->view()->text->FinishUndo();
1463 moveCursorUpdate(false);
1464 owner->getMiniBuffer()->Set(CurrentState());
1468 if(!owner->view()->text->mark_set)
1469 owner->view()->beforeChange();
1470 owner->view()->update(-2);
1471 if (owner->view()->text->cursor.par->getParDirection()
1472 == LYX_DIR_LEFT_TO_RIGHT)
1473 owner->view()->text->CursorLeftOneWord();
1475 owner->view()->text->CursorRightOneWord();
1476 owner->view()->text->FinishUndo();
1477 moveCursorUpdate(false);
1478 owner->getMiniBuffer()->Set(CurrentState());
1481 case LFUN_BEGINNINGBUF:
1482 if(!owner->view()->text->mark_set)
1483 owner->view()->beforeChange();
1484 owner->view()->update(-2);
1485 owner->view()->text->CursorTop();
1486 owner->view()->text->FinishUndo();
1487 moveCursorUpdate(false);
1488 owner->getMiniBuffer()->Set(CurrentState());
1492 if(!owner->view()->text->mark_set)
1493 owner->view()->beforeChange();
1494 owner->view()->update(-2);
1495 owner->view()->text->CursorBottom();
1496 owner->view()->text->FinishUndo();
1497 moveCursorUpdate(false);
1498 owner->getMiniBuffer()->Set(CurrentState());
1502 /* cursor selection ---------------------------- */
1504 owner->view()->update(-2);
1505 if (owner->view()->text->cursor.par->getParDirection()
1506 == LYX_DIR_LEFT_TO_RIGHT)
1507 owner->view()->text->CursorRight();
1509 owner->view()->text->CursorLeft();
1510 owner->view()->text->FinishUndo();
1511 moveCursorUpdate(true);
1512 owner->getMiniBuffer()->Set(CurrentState());
1516 owner->view()->update(-2);
1517 if (owner->view()->text->cursor.par->getParDirection()
1518 == LYX_DIR_LEFT_TO_RIGHT)
1519 owner->view()->text->CursorLeft();
1521 owner->view()->text->CursorRight();
1522 owner->view()->text->FinishUndo();
1523 moveCursorUpdate(true);
1524 owner->getMiniBuffer()->Set(CurrentState());
1528 owner->view()->update(-2);
1529 owner->view()->text->CursorUp();
1530 owner->view()->text->FinishUndo();
1531 moveCursorUpdate(true);
1532 owner->getMiniBuffer()->Set(CurrentState());
1536 owner->view()->update(-2);
1537 owner->view()->text->CursorDown();
1538 owner->view()->text->FinishUndo();
1539 moveCursorUpdate(true);
1540 owner->getMiniBuffer()->Set(CurrentState());
1543 case LFUN_UP_PARAGRAPHSEL:
1544 owner->view()->update(-2);
1545 owner->view()->text->CursorUpParagraph();
1546 owner->view()->text->FinishUndo();
1547 moveCursorUpdate(true);
1548 owner->getMiniBuffer()->Set(CurrentState());
1551 case LFUN_DOWN_PARAGRAPHSEL:
1552 owner->view()->update(-2);
1553 owner->view()->text->CursorDownParagraph();
1554 owner->view()->text->FinishUndo();
1555 moveCursorUpdate(true);
1556 owner->getMiniBuffer()->Set(CurrentState());
1560 owner->view()->update(-2);
1561 owner->view()->cursorPrevious();
1562 owner->view()->text->FinishUndo();
1563 moveCursorUpdate(true);
1564 owner->getMiniBuffer()->Set(CurrentState());
1568 owner->view()->update(-2);
1569 owner->view()->cursorNext();
1570 owner->view()->text->FinishUndo();
1571 moveCursorUpdate(true);
1572 owner->getMiniBuffer()->Set(CurrentState());
1576 owner->view()->update(-2);
1577 owner->view()->text->CursorHome();
1578 owner->view()->text->FinishUndo();
1579 moveCursorUpdate(true);
1580 owner->getMiniBuffer()->Set(CurrentState());
1584 owner->view()->update(-2);
1585 owner->view()->text->CursorEnd();
1586 owner->view()->text->FinishUndo();
1587 moveCursorUpdate(true);
1588 owner->getMiniBuffer()->Set(CurrentState());
1591 case LFUN_WORDRIGHTSEL:
1592 owner->view()->update(-2);
1593 if (owner->view()->text->cursor.par->getParDirection()
1594 == LYX_DIR_LEFT_TO_RIGHT)
1595 owner->view()->text->CursorRightOneWord();
1597 owner->view()->text->CursorLeftOneWord();
1598 owner->view()->text->FinishUndo();
1599 moveCursorUpdate(true);
1600 owner->getMiniBuffer()->Set(CurrentState());
1603 case LFUN_WORDLEFTSEL:
1604 owner->view()->update(-2);
1605 if (owner->view()->text->cursor.par->getParDirection()
1606 == LYX_DIR_LEFT_TO_RIGHT)
1607 owner->view()->text->CursorLeftOneWord();
1609 owner->view()->text->CursorRightOneWord();
1610 owner->view()->text->FinishUndo();
1611 moveCursorUpdate(true);
1612 owner->getMiniBuffer()->Set(CurrentState());
1615 case LFUN_BEGINNINGBUFSEL:
1616 owner->view()->update(-2);
1617 owner->view()->text->CursorTop();
1618 owner->view()->text->FinishUndo();
1619 moveCursorUpdate(true);
1620 owner->getMiniBuffer()->Set(CurrentState());
1623 case LFUN_ENDBUFSEL:
1624 owner->view()->update(-2);
1625 owner->view()->text->CursorBottom();
1626 owner->view()->text->FinishUndo();
1627 moveCursorUpdate(true);
1628 owner->getMiniBuffer()->Set(CurrentState());
1631 // --- text changing commands ------------------------
1632 case LFUN_BREAKLINE:
1634 owner->view()->beforeChange();
1635 owner->view()->text->InsertChar(LyXParagraph::META_NEWLINE);
1636 owner->view()->smallUpdate(1);
1637 SetUpdateTimer(0.01);
1638 moveCursorUpdate(false);
1640 owner->view()->newline();
1644 case LFUN_PROTECTEDSPACE:
1646 owner->view()->protectedBlank();
1648 owner->view()->beforeChange();
1649 owner->view()->text->
1650 InsertChar(LyXParagraph::META_PROTECTED_SEPARATOR);
1651 owner->view()->smallUpdate(1);
1653 moveCursorUpdate(false);
1658 if(owner->view()->text->mark_set) {
1659 owner->view()->beforeChange();
1660 owner->view()->update(0);
1661 setMessage(N_("Mark removed"));
1663 owner->view()->beforeChange();
1664 owner->view()->text->mark_set = 1;
1665 owner->view()->update(0);
1666 setMessage(N_("Mark set"));
1668 owner->view()->text->sel_cursor =
1669 owner->view()->text->cursor;
1674 if (!owner->view()->text->selection) {
1675 owner->view()->text->Delete();
1676 owner->view()->text->sel_cursor =
1677 owner->view()->text->cursor;
1678 owner->view()->smallUpdate(1);
1679 // It is possible to make it a lot faster still
1680 // just comment out the lone below...
1681 owner->view()->showCursor();
1683 owner->view()->cut();
1686 moveCursorUpdate(false);
1687 owner->getMiniBuffer()->Set(CurrentState());
1688 owner->view()->setState();
1691 case LFUN_DELETE_SKIP:
1693 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1695 LyXCursor cursor = owner->view()->text->cursor;
1698 if (!owner->view()->text->selection) {
1699 if (cursor.pos == cursor.par->Last()) {
1700 owner->view()->text->CursorRight();
1701 cursor = owner->view()->text->cursor;
1703 && !(cursor.par->added_space_top
1704 == VSpace (VSpace::NONE))) {
1705 owner->view()->text->SetParagraph
1706 (cursor.par->line_top,
1707 cursor.par->line_bottom,
1708 cursor.par->pagebreak_top,
1709 cursor.par->pagebreak_bottom,
1710 VSpace(VSpace::NONE),
1711 cursor.par->added_space_bottom,
1713 cursor.par->labelwidthstring, 0);
1714 owner->view()->text->CursorLeft();
1715 owner->view()->update (1);
1717 owner->view()->text->CursorLeft();
1718 owner->view()->text->Delete();
1719 owner->view()->text->sel_cursor =
1720 owner->view()->text->cursor;
1721 owner->view()->smallUpdate(1);
1724 owner->view()->text->Delete();
1725 owner->view()->text->sel_cursor =
1726 owner->view()->text->cursor;
1727 owner->view()->smallUpdate(1);
1730 owner->view()->cut();
1736 /* -------> Delete word forward. */
1737 case LFUN_DELETE_WORD_FORWARD:
1738 owner->view()->update(-2);
1740 owner->view()->text->DeleteWordForward();
1741 owner->view()->update( 1 );
1743 moveCursorUpdate(false);
1744 owner->getMiniBuffer()->Set(CurrentState());
1747 /* -------> Delete word backward. */
1748 case LFUN_DELETE_WORD_BACKWARD:
1749 owner->view()->update(-2);
1751 owner->view()->text->DeleteWordBackward();
1752 owner->view()->update( 1 );
1754 moveCursorUpdate(false);
1755 owner->getMiniBuffer()->Set(CurrentState());
1758 /* -------> Kill to end of line. */
1759 case LFUN_DELETE_LINE_FORWARD:
1761 owner->view()->update(-2);
1762 owner->view()->text->DeleteLineForward();
1763 owner->view()->update( 1 );
1765 moveCursorUpdate(false);
1768 /* -------> Set mark off. */
1770 owner->view()->beforeChange();
1771 owner->view()->update(0);
1772 owner->view()->text->sel_cursor =
1773 owner->view()->text->cursor;
1774 setMessage(N_("Mark off"));
1777 /* -------> Set mark on. */
1779 owner->view()->beforeChange();
1780 owner->view()->text->mark_set = 1;
1781 owner->view()->update( 0 );
1782 owner->view()->text->sel_cursor =
1783 owner->view()->text->cursor;
1784 setMessage(N_("Mark on"));
1787 case LFUN_BACKSPACE:
1790 if (!owner->view()->text->selection) {
1791 if (owner->getIntl()->getTrans()->backspace()) {
1792 owner->view()->text->Backspace();
1793 owner->view()->text->sel_cursor =
1794 owner->view()->text->cursor;
1795 owner->view()->smallUpdate(1);
1796 // It is possible to make it a lot faster still
1797 // just comment out the lone below...
1798 owner->view()->showCursor();
1801 owner->view()->cut();
1804 owner->getMiniBuffer()->Set(CurrentState());
1805 owner->view()->setState();
1809 case LFUN_BACKSPACE_SKIP:
1811 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1813 LyXCursor cursor = owner->view()->text->cursor;
1816 if (!owner->view()->text->selection) {
1818 && !(cursor.par->added_space_top
1819 == VSpace (VSpace::NONE))) {
1820 owner->view()->text->SetParagraph
1821 (cursor.par->line_top,
1822 cursor.par->line_bottom,
1823 cursor.par->pagebreak_top,
1824 cursor.par->pagebreak_bottom,
1825 VSpace(VSpace::NONE), cursor.par->added_space_bottom,
1827 cursor.par->labelwidthstring, 0);
1828 owner->view()->update (1);
1830 owner->view()->text->Backspace();
1831 owner->view()->text->sel_cursor
1833 owner->view()->smallUpdate (1);
1836 owner->view()->cut();
1841 case LFUN_BREAKPARAGRAPH:
1843 owner->view()->beforeChange();
1844 owner->view()->text->BreakParagraph(0);
1845 owner->view()->smallUpdate(1);
1846 SetUpdateTimer(0.01);
1847 owner->view()->text->sel_cursor =
1848 owner->view()->text->cursor;
1849 owner->view()->setState();
1850 owner->getMiniBuffer()->Set(CurrentState());
1854 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1856 owner->view()->beforeChange();
1857 owner->view()->text->BreakParagraph(1);
1858 owner->view()->smallUpdate(1);
1859 SetUpdateTimer(0.01);
1860 owner->view()->text->sel_cursor =
1861 owner->view()->text->cursor;
1862 owner->view()->setState();
1863 owner->getMiniBuffer()->Set(CurrentState());
1867 case LFUN_BREAKPARAGRAPH_SKIP:
1869 // When at the beginning of a paragraph, remove
1870 // indentation and add a "defskip" at the top.
1871 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
1873 LyXCursor cursor = owner->view()->text->cursor;
1875 owner->view()->beforeChange();
1876 if (cursor.pos == 0) {
1877 if (cursor.par->added_space_top == VSpace(VSpace::NONE)) {
1878 owner->view()->text->SetParagraph
1879 (cursor.par->line_top,
1880 cursor.par->line_bottom,
1881 cursor.par->pagebreak_top,
1882 cursor.par->pagebreak_bottom,
1883 VSpace(VSpace::DEFSKIP), cursor.par->added_space_bottom,
1885 cursor.par->labelwidthstring, 1);
1886 owner->view()->update(1);
1890 owner->view()->text->BreakParagraph(0);
1891 owner->view()->smallUpdate(1);
1893 SetUpdateTimer(0.01);
1894 owner->view()->text->sel_cursor = cursor;
1895 owner->view()->setState();
1896 owner->getMiniBuffer()->Set(CurrentState());
1901 owner->view()->beforeChange();
1902 owner->view()->text->InsertChar('\"'); // This " matches the single quote in the code
1903 owner->view()->smallUpdate(1);
1905 moveCursorUpdate(false);
1911 InsetCommand * new_inset;
1912 if (action == LFUN_HTMLURL)
1913 new_inset = new InsetUrl("htmlurl", "", "");
1915 new_inset = new InsetUrl("url", "", "");
1916 owner->view()->insertInset(new_inset);
1917 new_inset->Edit(owner->view(), 0, 0, 0);
1920 case LFUN_INSET_TEXT:
1922 InsetText * new_inset = new InsetText(owner->buffer());
1923 owner->view()->insertInset(new_inset);
1924 new_inset->Edit(owner->view(), 0, 0, 0);
1927 case LFUN_INSET_ERT:
1929 InsetERT * new_inset = new InsetERT(owner->buffer());
1930 owner->view()->insertInset(new_inset);
1931 new_inset->Edit(owner->view(), 0, 0, 0);
1933 case LFUN_INSET_FOOTNOTE:
1935 InsetFoot * new_inset = new InsetFoot(owner->buffer());
1936 owner->view()->insertInset(new_inset);
1937 new_inset->Edit(owner->view(), 0, 0, 0);
1941 // --- lyxserver commands ----------------------------
1943 case LFUN_CHARATCURSOR:
1945 LyXParagraph::size_type pos =
1946 owner->view()->text->cursor.pos;
1947 if(pos < owner->view()->text->cursor.par->size())
1948 dispatch_buffer = owner->view()->text->
1949 cursor.par->text[pos];
1951 dispatch_buffer = "EOF";
1957 tostr(owner->view()->text->cursor.x) + ' '
1958 + tostr(owner->view()->text->cursor.y);
1965 sscanf(argument.c_str(), " %d %ld", &x, &y);
1966 owner->view()->text->SetCursorFromCoordinates(x, y);
1970 case LFUN_GETLAYOUT:
1972 tostr(owner->view()->text->cursor.par->layout);
1977 LyXFont * font = &(owner->view()->text->current_font);
1978 if(font->shape() == LyXFont::ITALIC_SHAPE)
1979 dispatch_buffer = 'E';
1980 else if(font->shape() == LyXFont::SMALLCAPS_SHAPE)
1981 dispatch_buffer = 'N';
1983 dispatch_buffer = '0';
1990 LyXFont * font = &(owner->view()->text->current_font);
1991 if(font->latex() == LyXFont::ON)
1992 dispatch_buffer = 'L';
1994 dispatch_buffer = '0';
1999 setMessage(owner->buffer()->fileName());
2000 lyxerr.debug() << "FNAME["
2001 << owner->buffer()->fileName()
2009 dispatch_buffer = buf;
2010 lyxserver->notifyClient(dispatch_buffer);
2014 case LFUN_GOTOFILEROW:
2016 char file_name[100];
2018 sscanf(argument.c_str(), " %s %d", file_name, &row);
2020 // Must replace extension of the file to be .lyx and get full path
2021 string s = ChangeExtension(string(file_name), ".lyx", false);
2023 // Either change buffer or load the file
2024 if (bufferlist.exists(s))
2025 owner->view()->buffer(bufferlist.getBuffer(s));
2027 owner->view()->buffer(bufferlist.loadLyXFile(s));
2030 owner->view()->setCursorFromRow(row);
2033 owner->view()->center();
2040 int qa = lyxaction.LookupFunc(argument.c_str());
2041 setMessage(lyxaction.helpText(static_cast<kb_action>(qa)));
2045 // --- accented characters ---------------------------
2048 case LFUN_CIRCUMFLEX:
2058 case LFUN_SPECIAL_CARON:
2061 case LFUN_HUNG_UMLAUT:
2067 if (keyseq.length == -1 && keyseq.getiso() != 0)
2068 c = keyseq.getiso();
2072 owner->getIntl()->getTrans()->
2073 deadkey(c, get_accent(action).accent,
2074 owner->view()->text);
2076 // Need to reset, in case the minibuffer calls these
2081 // copied verbatim from do_accent_char
2082 owner->view()->smallUpdate(1);
2084 owner->view()->text->sel_cursor =
2085 owner->view()->text->cursor;
2089 // --- toolbar ----------------------------------
2090 case LFUN_PUSH_TOOLBAR:
2092 int nth = strToInt(argument);
2093 if (lyxerr.debugging(Debug::TOOLBAR)) {
2094 lyxerr << "LFUN_PUSH_TOOLBAR: argument = `"
2095 << argument << "'\n"
2096 << "LFUN_PUSH_TOOLBAR: nth = `"
2097 << nth << "'" << endl;
2102 setErrorMessage(N_("Push-toolbar needs argument > 0"));
2104 owner->getToolbar()->push(nth);
2109 case LFUN_ADD_TO_TOOLBAR:
2111 if (lyxerr.debugging(Debug::TOOLBAR)) {
2112 lyxerr << "LFUN_ADD_TO_TOOLBAR:"
2113 "argument = `" << argument << '\'' << endl;
2115 string tmp(argument);
2116 //lyxerr <<string("Argument: ") + argument);
2117 //lyxerr <<string("Tmp : ") + tmp);
2120 setErrorMessage(N_("Usage: toolbar-add-to <LyX command>"));
2122 owner->getToolbar()->add(argument, false);
2123 owner->getToolbar()->set();
2128 // --- insert characters ----------------------------------------
2130 // --- Mathed stuff. If we are here, there is no locked inset yet.
2135 if (!greek_kb_flag) {
2137 setMessage(N_("Math greek mode on"));
2144 case LFUN_GREEK_TOGGLE:
2146 greek_kb_flag = greek_kb_flag ? 0 : 2;
2147 if (greek_kb_flag) {
2148 setMessage(N_("Math greek keyboard on"));
2150 setMessage(N_("Math greek keyboard off"));
2155 case LFUN_MATH_DELIM:
2156 case LFUN_INSERT_MATRIX:
2158 if (owner->view()->available()) {
2160 open_new_inset(new InsetFormula(false));
2163 ->LocalDispatch(owner->view(),
2170 case LFUN_INSERT_MATH:
2172 math_insert_symbol(argument.c_str());
2176 case LFUN_MATH_DISPLAY:
2178 if (owner->view()->available())
2179 owner->view()->open_new_inset(new InsetFormula(true));
2183 case LFUN_MATH_MACRO:
2185 if (owner->view()->available()) {
2188 setErrorMessage(N_("Missing argument"));
2190 string s1 = token(s, ' ', 1);
2191 int na = s1.empty() ? 0: atoi(s1.c_str());
2193 open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2199 case LFUN_MATH_MODE: // Open or create a math inset
2202 if (owner->view()->available())
2203 owner->view()->open_new_inset(new InsetFormula);
2204 setMessage(N_("Math editor mode"));
2208 case LFUN_MATH_NUMBER:
2209 case LFUN_MATH_LIMITS:
2211 setErrorMessage(N_("This is only allowed in math mode!"));
2215 case LFUN_INSERT_CITATION:
2217 InsetCitation * new_inset = new InsetCitation();
2219 // The note, if any, must be after the key, delimited
2220 // by a | so both key and remark can have spaces.
2221 if (!argument.empty()) {
2222 string lsarg(argument);
2223 if (contains(lsarg, "|")) {
2224 new_inset->setContents(token(lsarg, '|', 0));
2225 new_inset->setOptions(token(lsarg, '|', 1));
2227 new_inset->setContents(lsarg);
2228 owner->view()->insertInset(new_inset);
2230 owner->view()->insertInset(new_inset);
2231 new_inset->Edit(owner->view(), 0, 0, 0);
2236 case LFUN_INSERT_BIBTEX:
2238 // ale970405+lasgoutt970425
2239 // The argument can be up to two tokens separated
2240 // by a space. The first one is the bibstyle.
2241 string lsarg(argument);
2242 string bibstyle = token(lsarg, ' ', 1);
2243 if (bibstyle.empty())
2245 InsetBibtex * new_inset
2246 = new InsetBibtex(token(lsarg, ' ', 0),
2250 owner->view()->insertInset(new_inset);
2251 if (lsarg.empty()) {
2252 new_inset->Edit(owner->view(), 0, 0, 0);
2257 // BibTeX data bases
2258 case LFUN_BIBDB_ADD:
2260 InsetBibtex * inset =
2261 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2263 inset->addDatabase(argument);
2268 case LFUN_BIBDB_DEL:
2270 InsetBibtex * inset =
2271 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2273 inset->delDatabase(argument);
2278 case LFUN_BIBTEX_STYLE:
2280 InsetBibtex * inset =
2281 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2283 inset->setOptions(argument);
2288 case LFUN_INDEX_INSERT:
2289 case LFUN_INDEX_INSERT_LAST:
2291 // Can't do that at the beginning of a paragraph.
2292 if (owner->view()->text->cursor.pos - 1 < 0)
2295 InsetIndex * new_inset = new InsetIndex();
2296 if (!argument.empty()) {
2297 string lsarg(argument);
2298 new_inset->setContents(lsarg);
2299 owner->view()->insertInset(new_inset);
2302 //get the current word for an argument
2303 LyXParagraph::size_type lastpos =
2304 owner->view()->text->cursor.pos - 1;
2305 // Get the current word. note that this must be done
2306 // before inserting the inset, or the inset will
2308 string curstring(owner->view()
2309 ->text->cursor.par->GetWord(lastpos));
2311 //make the new inset and write the current word into it
2312 InsetIndex * new_inset = new InsetIndex();
2314 new_inset->setContents(curstring);
2316 //don't edit it if the call was to INSERT_LAST
2317 if(action != LFUN_INDEX_INSERT_LAST) {
2318 new_inset->Edit(owner->view(), 0, 0, 0);
2320 //it looks blank on the screen unless
2321 //we do something. put it here.
2323 // move the cursor to the returned value of lastpos
2324 // but only for the auto-insert
2325 owner->view()->text->cursor.pos = lastpos;
2328 //put the new inset into the buffer.
2329 // there should be some way of knowing the user
2330 //cancelled & avoiding this, but i don't know how
2331 owner->view()->insertInset(new_inset);
2336 case LFUN_INDEX_PRINT:
2338 Inset * new_inset = new InsetPrintIndex(owner->buffer());
2339 owner->view()->insertInset(new_inset, "Standard", true);
2343 case LFUN_PARENTINSERT:
2345 lyxerr << "arg " << argument << endl;
2346 Inset * new_inset = new InsetParent(argument, owner->buffer());
2347 owner->view()->insertInset(new_inset, "Standard", true);
2351 case LFUN_CHILDINSERT:
2353 Inset * new_inset = new InsetInclude(argument,
2355 owner->view()->insertInset(new_inset, "Standard", true);
2356 new_inset->Edit(owner->view(), 0, 0, 0);
2360 case LFUN_CHILDOPEN:
2363 MakeAbsPath(argument,
2364 OnlyPath(owner->buffer()->fileName()));
2365 setMessage(N_("Opening child document ") +
2366 MakeDisplayPath(filename) + "...");
2367 owner->view()->savePosition();
2368 if (bufferlist.exists(filename))
2369 owner->view()->buffer(bufferlist.getBuffer(filename));
2371 owner->view()->buffer(bufferlist.loadLyXFile(filename));
2375 case LFUN_INSERT_NOTE:
2376 owner->view()->insertNote();
2379 case LFUN_INSERTFOOTNOTE:
2381 LyXParagraph::footnote_kind kind;
2382 if (argument == "footnote")
2383 { kind = LyXParagraph::FOOTNOTE; }
2384 else if (argument == "margin")
2385 { kind = LyXParagraph::MARGIN; }
2386 else if (argument == "figure")
2387 { kind = LyXParagraph::FIG; }
2388 else if (argument == "table")
2389 { kind = LyXParagraph::TAB; }
2390 else if (argument == "wide-fig")
2391 { kind = LyXParagraph::WIDE_FIG; }
2392 else if (argument == "wide-tab")
2393 { kind = LyXParagraph::WIDE_TAB; }
2394 else if (argument == "algorithm")
2395 { kind = LyXParagraph::ALGORITHM; }
2397 setErrorMessage(N_("Unknown kind of footnote"));
2400 owner->view()->text->InsertFootnoteEnvironment(kind);
2401 owner->view()->update(1);
2402 owner->view()->setState();
2406 case LFUN_BUFFERBULLETSSELECT:
2410 case LFUN_TOGGLECURSORFOLLOW:
2411 cursor_follows_scrollbar = !cursor_follows_scrollbar;
2414 case LFUN_KMAP_OFF: // keymap off
2415 owner->getIntl()->KeyMapOn(false);
2418 case LFUN_KMAP_PRIM: // primary keymap
2419 owner->getIntl()->KeyMapPrim();
2422 case LFUN_KMAP_SEC: // secondary keymap
2423 owner->getIntl()->KeyMapSec();
2426 case LFUN_KMAP_TOGGLE: // toggle keymap
2427 owner->getIntl()->ToggleKeyMap();
2430 case LFUN_SELFINSERT:
2432 for (string::size_type i = 0; i < argument.length(); ++i) {
2433 owner->view()->text->InsertChar(argument[i]);
2434 // This needs to be in the loop, or else we
2435 // won't break lines correctly. (Asger)
2436 owner->view()->smallUpdate(1);
2439 owner->view()->text->sel_cursor =
2440 owner->view()->text->cursor;
2441 moveCursorUpdate(false);
2447 // argument contains ';'-terminated commands
2448 while (argument.find(';') != string::npos) {
2450 argument = split(argument, first, ';');
2456 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
2464 now_time_t = time(NULL);
2465 now_tm = localtime(&now_time_t);
2466 (void)setlocale(LC_TIME, "");
2467 if (!argument.empty())
2469 else if (arg.empty())
2470 arg = lyxrc->date_insert_format;
2471 datetmp_len = (int) strftime(datetmp, 32, arg.c_str(), now_tm);
2472 for (int i = 0; i < datetmp_len; i++) {
2473 owner->view()->text->InsertChar(datetmp[i]);
2474 owner->view()->smallUpdate(1);
2477 owner->view()->text->sel_cursor = owner->view()->text->cursor;
2478 moveCursorUpdate(false);
2482 case LFUN_SAVEPREFERENCES:
2484 Path p(user_lyxdir);
2485 lyxrc->write("preferences");
2489 case LFUN_UNKNOWN_ACTION:
2491 if(!owner->buffer()) {
2493 setErrorMessage(N_("No document open"));
2497 if (owner->buffer()->isReadonly()) {
2499 setErrorMessage(N_("Document is read only"));
2503 if (!argument.empty()) {
2505 /* Automatically delete the currently selected
2506 * text and replace it with what is being
2507 * typed in now. Depends on lyxrc settings
2508 * "auto_region_delete", which defaults to
2511 if ( lyxrc->auto_region_delete ) {
2512 if (owner->view()->text->selection){
2513 owner->view()->text->CutSelection(false);
2514 owner->view()->update(-1);
2518 owner->view()->beforeChange();
2519 for (string::size_type i = 0;
2520 i < argument.length(); ++i) {
2521 if (greek_kb_flag) {
2522 if (!math_insert_greek(argument[i]))
2523 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2525 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2528 owner->view()->smallUpdate(1);
2531 owner->view()->text->sel_cursor =
2532 owner->view()->text->cursor;
2533 moveCursorUpdate(false);
2536 // why is an "Unknown action" with empty
2537 // argument even dispatched in the first
2538 // place? I`ll probably change that. (Lgb)
2540 setErrorMessage(N_("Unknown action"));
2544 lyxerr << "A truly unknown func!" << endl;
2550 string res = getMessage();
2553 if (!commandshortcut.empty()) {
2554 string newbuf = owner->getMiniBuffer()->GetText();
2555 if (newbuf != commandshortcut) {
2556 owner->getMiniBuffer()->Set(newbuf
2562 owner->getMiniBuffer()->Set(string(_(res.c_str()))
2563 + " " + commandshortcut);
2570 void LyXFunc::setupLocalKeymap()
2572 keyseq.stdmap = keyseq.curmap = toplevel_keymap;
2573 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap;
2577 void LyXFunc::MenuNew(bool fromTemplate)
2579 string fname, initpath = lyxrc->document_path;
2582 if (owner->view()->available()) {
2583 string trypath = owner->buffer()->filepath;
2584 // If directory is writeable, use this as default.
2585 if (IsDirWriteable(trypath) == 1)
2590 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2591 fileDlg.SetButton(1, _("Templates"), lyxrc->template_path);
2592 fname = fileDlg.Select(_("Enter Filename for new document"),
2593 initpath, "*.lyx", _("newfile"));
2596 if (fname.empty()) {
2597 owner->getMiniBuffer()->Set(_("Canceled."));
2598 lyxerr.debug() << "New Document Cancelled." << endl;
2602 // get absolute path of file and make sure the filename ends
2604 string s = MakeAbsPath(fname);
2605 if (!IsLyXFilename(s))
2608 // Check if the document already is open
2609 if (bufferlist.exists(s)){
2610 switch(AskConfirmation(_("Document is already open:"),
2611 MakeDisplayPath(s, 50),
2612 _("Do you want to close that document now?\n"
2613 "('No' will just switch to the open version)")))
2615 case 1: // Yes: close the document
2616 if (!bufferlist.close(bufferlist.getBuffer(s)))
2617 // If close is canceled, we cancel here too.
2620 case 2: // No: switch to the open document
2621 owner->view()->buffer(bufferlist.getBuffer(s));
2623 case 3: // Cancel: Do nothing
2624 owner->getMiniBuffer()->Set(_("Canceled."));
2629 // Check whether the file already exists
2630 if (IsLyXFilename(s)) {
2632 if (fi.readable() &&
2633 AskQuestion(_("File already exists:"),
2634 MakeDisplayPath(s, 50),
2635 _("Do you want to open the document?"))) {
2637 owner->getMiniBuffer()->Set(_("Opening document"),
2638 MakeDisplayPath(s), "...");
2640 owner->view()->buffer(
2641 bufferlist.loadLyXFile(s));
2642 owner->getMiniBuffer()->Set(_("Document"),
2649 // The template stuff
2653 fname = fileDlg.Select(_("Choose template"),
2654 lyxrc->template_path,
2660 // find a free buffer
2661 lyxerr.debug() << "Find a free buffer." << endl;
2662 owner->view()->buffer(bufferlist.newFile(s, templname));
2666 void LyXFunc::MenuOpen()
2668 string initpath = lyxrc->document_path;
2671 if (owner->view()->available()) {
2672 string trypath = owner->buffer()->filepath;
2673 // If directory is writeable, use this as default.
2674 if (IsDirWriteable(trypath) == 1)
2680 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2681 fileDlg.SetButton(1, _("Examples"),
2682 AddPath(system_lyxdir, "examples"));
2683 string filename = fileDlg.Select(_("Select Document to Open"),
2687 // check selected filename
2688 if (filename.empty()) {
2689 owner->getMiniBuffer()->Set(_("Canceled."));
2693 // get absolute path of file and make sure the filename ends
2695 filename = MakeAbsPath(filename);
2696 if (!IsLyXFilename(filename))
2700 owner->getMiniBuffer()->Set(_("Opening document"),
2701 MakeDisplayPath(filename), "...");
2702 Buffer * openbuf = bufferlist.loadLyXFile(filename);
2704 owner->view()->buffer(openbuf);
2705 owner->getMiniBuffer()->Set(_("Document"),
2706 MakeDisplayPath(filename),
2709 owner->getMiniBuffer()->Set(_("Could not open document"),
2710 MakeDisplayPath(filename));
2715 void LyXFunc::doImportASCII(bool linorpar)
2717 string initpath = lyxrc->document_path;
2720 if (owner->view()->available()) {
2721 string trypath = owner->buffer()->filepath;
2722 // If directory is writeable, use this as default.
2723 if (IsDirWriteable(trypath) == 1)
2729 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2730 fileDlg.SetButton(1, _("Examples"),
2731 AddPath(system_lyxdir, "examples"));
2732 string filename = fileDlg.Select(_("Select ASCII file to Import"),
2736 // check selected filename
2737 if (filename.empty()) {
2738 owner->getMiniBuffer()->Set(_("Canceled."));
2742 // get absolute path of file
2743 filename = MakeAbsPath(filename);
2745 string s = ChangeExtension(filename, ".lyx", false);
2747 // Check if the document already is open
2748 if (bufferlist.exists(s)) {
2749 switch(AskConfirmation(_("Document is already open:"),
2750 MakeDisplayPath(s, 50),
2751 _("Do you want to close that document now?\n"
2752 "('No' will just switch to the open version)")))
2754 case 1: // Yes: close the document
2755 if (!bufferlist.close(bufferlist.getBuffer(s)))
2756 // If close is canceled, we cancel here too.
2759 case 2: // No: switch to the open document
2760 owner->view()->buffer(bufferlist.getBuffer(s));
2762 case 3: // Cancel: Do nothing
2763 owner->getMiniBuffer()->Set(_("Canceled."));
2768 // Check if a LyX document by the same root exists in filesystem
2769 FileInfo f(s, true);
2770 if (f.exist() && !AskQuestion(_("A document by the name"),
2772 _("already exists. Overwrite?"))) {
2773 owner->getMiniBuffer()->Set(_("Canceled."));
2777 owner->view()->buffer(bufferlist.newFile(s, string()));
2778 owner->getMiniBuffer()->Set(_("Importing ASCII file"),
2779 MakeDisplayPath(filename), "...");
2780 // Insert ASCII file
2781 InsertAsciiFile(filename, linorpar);
2782 owner->getMiniBuffer()->Set(_("ASCII file "),
2783 MakeDisplayPath(filename),
2788 void LyXFunc::doImportLaTeX(bool isnoweb)
2790 string initpath = lyxrc->document_path;
2793 if (owner->view()->available()) {
2794 string trypath = owner->buffer()->filepath;
2795 // If directory is writeable, use this as default.
2796 if (IsDirWriteable(trypath) == 1)
2802 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2803 fileDlg.SetButton(1, _("Examples"),
2804 AddPath(system_lyxdir, "examples"));
2807 filename = fileDlg.Select(_("Select Noweb file to Import"),
2810 filename = fileDlg.Select(_("Select LaTeX file to Import"),
2816 // check selected filename
2817 if (filename.empty()) {
2818 owner->getMiniBuffer()->Set(_("Canceled."));
2822 // get absolute path of file
2823 filename = MakeAbsPath(filename);
2825 // Check if the document already is open
2826 string LyXfilename = ChangeExtension(filename, ".lyx", false);
2827 if (bufferlist.exists(LyXfilename)){
2828 switch(AskConfirmation(_("Document is already open:"),
2829 MakeDisplayPath(LyXfilename, 50),
2830 _("Do you want to close that document now?\n"
2831 "('No' will just switch to the open version)")))
2833 case 1: // Yes: close the document
2834 if (!bufferlist.close(bufferlist.getBuffer(LyXfilename)))
2835 // If close is canceled, we cancel here too.
2838 case 2: // No: switch to the open document
2839 owner->view()->buffer(
2840 bufferlist.getBuffer(LyXfilename));
2842 case 3: // Cancel: Do nothing
2843 owner->getMiniBuffer()->Set(_("Canceled."));
2848 // Check if a LyX document by the same root exists in filesystem
2849 FileInfo f(LyXfilename, true);
2850 if (f.exist() && !AskQuestion(_("A document by the name"),
2851 MakeDisplayPath(LyXfilename),
2852 _("already exists. Overwrite?"))) {
2853 owner->getMiniBuffer()->Set(_("Canceled."));
2860 owner->getMiniBuffer()->Set(_("Importing LaTeX file"),
2861 MakeDisplayPath(filename), "...");
2862 ImportLaTeX myImport(filename);
2863 openbuf = myImport.run();
2865 owner->getMiniBuffer()->Set(_("Importing Noweb file"),
2866 MakeDisplayPath(filename), "...");
2867 ImportNoweb myImport(filename);
2868 openbuf = myImport.run();
2871 owner->view()->buffer(openbuf);
2872 owner->getMiniBuffer()->Set(isnoweb ?
2873 _("Noweb file ") : _("LateX file "),
2874 MakeDisplayPath(filename),
2877 owner->getMiniBuffer()->Set(isnoweb ?
2878 _("Could not import Noweb file") :
2879 _("Could not import LaTeX file"),
2880 MakeDisplayPath(filename));
2885 void LyXFunc::MenuInsertLyXFile(string const & filen)
2887 string filename = filen;
2889 if (filename.empty()) {
2890 // Launch a file browser
2891 string initpath = lyxrc->document_path;
2894 if (owner->view()->available()) {
2895 string trypath = owner->buffer()->filepath;
2896 // If directory is writeable, use this as default.
2897 if (IsDirWriteable(trypath) == 1)
2903 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2904 fileDlg.SetButton(1, _("Examples"),
2905 AddPath(system_lyxdir, "examples"));
2906 filename = fileDlg.Select(_("Select Document to Insert"),
2910 // check selected filename
2911 if (filename.empty()) {
2912 owner->getMiniBuffer()->Set(_("Canceled."));
2917 // get absolute path of file and make sure the filename ends
2919 filename = MakeAbsPath(filename);
2920 if (!IsLyXFilename(filename))
2924 owner->getMiniBuffer()->Set(_("Inserting document"),
2925 MakeDisplayPath(filename), "...");
2926 bool res = owner->view()->insertLyXFile(filename);
2928 owner->getMiniBuffer()->Set(_("Document"),
2929 MakeDisplayPath(filename),
2932 owner->getMiniBuffer()->Set(_("Could not insert document"),
2933 MakeDisplayPath(filename));
2938 void LyXFunc::reloadBuffer()
2940 string fn = owner->buffer()->fileName();
2941 if (bufferlist.close(owner->buffer()))
2942 owner->view()->buffer(bufferlist.loadLyXFile(fn));
2946 void LyXFunc::CloseBuffer()
2948 if (bufferlist.close(owner->buffer()) && !quitting) {
2949 if (bufferlist.empty()) {
2950 // need this otherwise SEGV may occur while trying to
2951 // set variables that don't exist
2952 // since there's no current buffer
2953 CloseAllBufferRelatedPopups();
2956 owner->view()->buffer(bufferlist.first());
2962 Inset * LyXFunc::getInsetByCode(Inset::Code code)
2966 LyXCursor cursor = owner->view()->text->cursor;
2967 LyXParagraph::size_type pos = cursor.pos;
2968 LyXParagraph * par = cursor.par;
2970 while (par && !found) {
2971 while ((inset = par->ReturnNextInsetPointer(pos))){
2972 if (inset->LyxCode() == code) {
2980 return found ? inset : 0;
2984 // Each "owner" should have it's own message method. lyxview and
2985 // the minibuffer would use the minibuffer, but lyxserver would
2986 // send an ERROR signal to its client. Alejandro 970603
2987 // This func is bit problematic when it comes to NLS, to make the
2988 // lyx servers client be language indepenent we must not translate
2989 // strings sent to this func.
2990 void LyXFunc::setErrorMessage(string const & m) const
2992 dispatch_buffer = m;
2997 void LyXFunc::setMessage(string const & m)
2999 dispatch_buffer = m;