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 >
666 owner->view()->getWorkArea()->height() / 2)
668 owner->view()->getScreen()->
669 Draw(owner->view()->text->cursor.y -
670 owner->view()->getWorkArea()->height() / 2
673 owner->view()->getScreen()->
676 owner->view()->update(0);
677 owner->view()->redraw();
681 if (owner->view()->available()) {
682 owner->view()->text->toggleAppendix();
683 owner->view()->update(1);
687 // --- Menus -----------------------------------------------
692 case LFUN_MENUNEWTMPLT:
700 case LFUN_CLOSEBUFFER:
705 MenuWrite(owner->buffer());
708 case LFUN_MENUWRITEAS:
709 MenuWriteAs(owner->buffer());
712 case LFUN_MENURELOAD:
717 PreviewDVI(owner->buffer());
721 PreviewPostscript(owner->buffer());
725 MenuRunLaTeX(owner->buffer());
729 MenuBuildProg(owner->buffer());
733 MenuRunChktex(owner->buffer());
737 CreatePostscript(owner->buffer(), false);
741 MenuPrint(owner->buffer());
745 MenuFax(owner->buffer());
749 MenuExport(owner->buffer(), argument);
754 //needs argument as string
755 string imtyp = argument;
758 if (imtyp == "latex") {
759 doImportLaTeX(false);
762 else if (imtyp == "ascii") {
763 doImportASCII(false);
764 } else if (imtyp == "asciiparagraph") {
767 } else if (imtyp == "noweb") {
770 setErrorMessage(string(N_("Unknown import type: "))
782 if (fd_form_toc->form_toc->visible) {
783 fl_raise_form(fd_form_toc->form_toc);
785 static int ow = -1, oh;
786 fl_show_form(fd_form_toc->form_toc,
788 FL_FREE_SIZE, FL_FULLBORDER,
789 _("Table of Contents"));
791 ow = fd_form_toc->form_toc->w;
792 oh = fd_form_toc->form_toc->h;
794 fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
798 case LFUN_TOC_INSERT:
800 Inset * new_inset = new InsetTOC(owner->buffer());
801 owner->view()->insertInset(new_inset, "Standard", true);
805 case LFUN_LOF_INSERT:
807 Inset * new_inset = new InsetLOF(owner->buffer());
808 owner->view()->insertInset(new_inset, "Standard", true);
812 case LFUN_LOA_INSERT:
814 Inset * new_inset = new InsetLOA(owner->buffer());
815 owner->view()->insertInset(new_inset, "Standard", true);
819 case LFUN_LOT_INSERT:
821 Inset * new_inset = new InsetLOT(owner->buffer());
822 owner->view()->insertInset(new_inset, "Standard", true);
839 owner->view()->menuUndo();
843 owner->view()->menuRedo();
846 case LFUN_MENUSEARCH:
851 owner->view()->paste();
854 case LFUN_PASTESELECTION:
857 if (argument == "paragraph") asPara = true;
858 MenuPasteSelection(asPara);
863 owner->view()->cut();
867 owner->view()->copy();
870 case LFUN_LAYOUT_COPY:
871 owner->view()->copyEnvironment();
874 case LFUN_LAYOUT_PASTE:
875 owner->view()->pasteEnvironment();
879 owner->view()->gotoError();
882 case LFUN_REMOVEERRORS:
883 if (owner->view()->removeAutoInsets()) {
884 owner->view()->redraw();
885 owner->view()->fitCursor();
886 owner->view()->updateScrollbar();
891 owner->view()->gotoNote();
895 owner->view()->openStuff();
898 case LFUN_HYPHENATION:
899 owner->view()->hyphenationPoint();
903 owner->view()->ldots();
906 case LFUN_END_OF_SENTENCE:
907 owner->view()->endOfSentenceDot();
910 case LFUN_MENU_SEPARATOR:
911 owner->view()->menuSeparator();
915 owner->view()->hfill();
919 changeDepth(owner->view(), 0);
923 changeDepth(owner->view(), -1);
926 case LFUN_DEPTH_PLUS:
927 changeDepth(owner->view(), 1);
936 owner->view()->SetState();
937 owner->getMiniBuffer()->Set(CurrentState());
944 case LFUN_RECONFIGURE:
945 Reconfigure(owner->view());
949 if (owner->view()->available()
950 && !owner->view()->text->selection
951 && owner->view()->text->cursor.par->footnoteflag
952 != LyXParagraph::NO_FOOTNOTE)
953 { // only melt footnotes with FOOTMELT, not margins etc
954 if(owner->view()->text->cursor.par->footnotekind == LyXParagraph::FOOTNOTE)
959 owner->view()->SetState();
962 case LFUN_MARGINMELT:
963 if (owner->view()->available()
964 && !owner->view()->text->selection
965 && owner->view()->text->cursor.par->footnoteflag
966 != LyXParagraph::NO_FOOTNOTE) {
968 if(owner->view()->text->cursor.par->footnotekind == LyXParagraph::MARGIN)
971 Margin(owner->view());
972 owner->view()->SetState();
975 // --- version control -------------------------------
976 case LFUN_VC_REGISTER:
978 if (!owner->buffer()->lyxvc.inUse())
979 owner->buffer()->lyxvc.registrer();
983 case LFUN_VC_CHECKIN:
985 if (owner->buffer()->lyxvc.inUse()
986 && !owner->buffer()->isReadonly())
987 owner->buffer()->lyxvc.checkIn();
991 case LFUN_VC_CHECKOUT:
993 if (owner->buffer()->lyxvc.inUse()
994 && owner->buffer()->isReadonly())
995 owner->buffer()->lyxvc.checkOut();
1001 owner->buffer()->lyxvc.revert();
1007 owner->buffer()->lyxvc.undoLast();
1011 case LFUN_VC_HISTORY:
1013 owner->buffer()->lyxvc.showLog();
1017 // --- buffers ----------------------------------------
1019 case LFUN_FILE_INSERT:
1021 MenuInsertLyXFile(argument);
1025 case LFUN_FILE_INSERT_ASCII:
1027 bool asPara = (argument == "paragraph");
1028 InsertAsciiFile(string(), asPara);
1034 // servercmd: argument must be <file>:<template>
1035 Buffer * tmpbuf = NewLyxFile(argument);
1037 owner->view()->buffer(tmpbuf);
1041 case LFUN_FILE_OPEN:
1042 owner->view()->buffer(bufferlist.loadLyXFile(argument));
1045 case LFUN_LATEX_LOG:
1051 lyxerr.debug() << "LFUN_LAYOUTNO: (arg) " << argument << endl;
1052 int sel = strToInt(argument);
1053 lyxerr.debug() << "LFUN_LAYOUTNO: (sel) "<< sel << endl;
1055 // Should this give a setMessage instead?
1057 return string(); // illegal argument
1059 --sel; // sel 1..., but layout 0...
1061 // Pretend we got the name instead.
1062 Dispatch(int(LFUN_LAYOUT),
1063 textclasslist.NameOfLayout(owner->view()->
1072 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1073 << argument << endl;
1075 // Derive layout number from given argument (string)
1076 // and current buffer's textclass (number). */
1077 LyXTextClassList::ClassList::size_type tclass =
1078 owner->view()->text->parameters->textclass;
1079 pair <bool, int> layout =
1080 textclasslist.NumberOfLayout(tclass, argument);
1082 // If the entry is obsolete, use the new one instead.
1084 string obs = textclasslist.Style(tclass,layout.second)
1088 textclasslist.NumberOfLayout(tclass, obs);
1091 // see if we found the layout number:
1092 if (!layout.first) {
1093 setErrorMessage(string(N_("Layout ")) + argument +
1098 if (current_layout != layout.second) {
1099 owner->view()->getScreen()->HideCursor();
1100 current_layout = layout.second;
1101 owner->view()->update(-2);
1102 owner->view()->text->
1103 SetLayout(layout.second);
1104 owner->getToolbar()->combox->
1105 select(owner->view()->
1108 owner->view()->update(1);
1113 case LFUN_LAYOUT_DOCUMENT:
1114 MenuLayoutDocument();
1117 case LFUN_LAYOUT_PARAGRAPH:
1118 MenuLayoutParagraph();
1121 case LFUN_LAYOUT_CHARACTER:
1122 MenuLayoutCharacter();
1125 case LFUN_LAYOUT_TABLE:
1128 if (argument == "true") flag = 1;
1129 MenuLayoutTable(flag);
1133 case LFUN_LAYOUT_PAPER:
1137 case LFUN_LAYOUT_QUOTES:
1141 case LFUN_LAYOUT_PREAMBLE:
1142 MenuLayoutPreamble();
1145 case LFUN_LAYOUT_SAVE_DEFAULT:
1149 case LFUN_DROP_LAYOUTS_CHOICE:
1150 owner->getToolbar()->combox->Show();
1156 owner->view()->SetState();
1157 owner->getMiniBuffer()->Set(CurrentState());
1189 case LFUN_UNDERLINE:
1193 case LFUN_FONT_SIZE:
1197 case LFUN_FONT_STATE:
1198 setMessage(CurrentState());
1201 case LFUN_UPCASE_WORD:
1202 owner->view()->update(-2);
1204 owner->view()->text->ChangeWordCase(LyXText::text_uppercase);
1205 owner->view()->update(1);
1209 case LFUN_LOWCASE_WORD:
1210 owner->view()->update(-2);
1212 owner->view()->text->ChangeWordCase(LyXText::text_lowercase);
1213 owner->view()->update(1);
1217 case LFUN_CAPITALIZE_WORD:
1218 owner->view()->update(-2);
1220 owner->view()->text->ChangeWordCase(LyXText::text_capitalization);
1221 owner->view()->update(1);
1225 case LFUN_INSERT_LABEL:
1226 MenuInsertLabel(argument.c_str());
1229 case LFUN_INSERT_REF:
1233 case LFUN_REFTOGGLE:
1236 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1238 if (inset->getFlag() == InsetRef::REF)
1239 inset->setFlag(InsetRef::PAGE_REF);
1241 inset->setFlag(InsetRef::REF);
1242 UpdateInset(owner->view(), inset);
1244 setErrorMessage(N_("No cross-reference to toggle"));
1251 owner->view()->restorePosition();
1257 string label(argument);
1258 if (label.empty()) {
1260 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1262 label = inset->getContents();
1265 if (!label.empty()) {
1266 owner->view()->savePosition();
1267 owner->view()->gotoLabel(label.c_str());
1272 case LFUN_MENU_OPEN_BY_NAME:
1273 owner->getMenus()->openByName(argument);
1274 break; // RVDK_PATCH_5
1276 case LFUN_SPELLCHECK:
1277 if (lyxrc->isp_command != "none")
1279 break; // RVDK_PATCH_5
1281 // --- Cursor Movements -----------------------------
1284 LyXText * tmptext = owner->view()->text;
1285 LyXDirection direction =
1286 tmptext->cursor.par->getParDirection();
1287 if(!tmptext->mark_set)
1288 owner->view()->beforeChange();
1289 owner->view()->update(-2);
1290 if (direction == LYX_DIR_RIGHT_TO_LEFT)
1291 tmptext->CursorLeft();
1292 if (tmptext->cursor.pos < tmptext->cursor.par->Last()
1293 && tmptext->cursor.par->GetChar(tmptext->cursor.pos)
1294 == LyXParagraph::META_INSET
1295 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)
1296 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)->Editable() == 2){
1297 Inset * tmpinset = tmptext->cursor.par->GetInset(tmptext->cursor.pos);
1298 setMessage(tmpinset->EditMessage());
1299 tmpinset->Edit(0, 0);
1302 if (direction == LYX_DIR_LEFT_TO_RIGHT)
1303 tmptext->CursorRight();
1304 owner->view()->text->FinishUndo();
1305 moveCursorUpdate(false);
1306 owner->getMiniBuffer()->Set(CurrentState());
1313 // This is soooo ugly. Isn`t it possible to make
1314 // it simpler? (Lgb)
1315 LyXText * txt = owner->view()->text;
1316 LyXDirection direction = txt->cursor.par->getParDirection();
1317 if(!txt->mark_set) owner->view()->beforeChange();
1318 owner->view()->update(-2);
1319 if (direction == LYX_DIR_LEFT_TO_RIGHT)
1321 if (txt->cursor.pos < txt->cursor.par->Last()
1322 && txt->cursor.par->GetChar(txt->cursor.pos)
1323 == LyXParagraph::META_INSET
1324 && txt->cursor.par->GetInset(txt->cursor.pos)
1325 && txt->cursor.par->GetInset(txt->cursor.pos)->Editable() == 2) {
1326 Inset * tmpinset = txt->cursor.par->GetInset(txt->cursor.pos);
1327 setMessage(tmpinset->EditMessage());
1328 tmpinset->Edit(tmpinset->width(owner->view()->painter(),
1329 txt->GetFont(txt->cursor.par,
1330 txt->cursor.pos)), 0);
1333 if (direction == LYX_DIR_RIGHT_TO_LEFT)
1336 owner->view()->text->FinishUndo();
1337 moveCursorUpdate(false);
1338 owner->getMiniBuffer()->Set(CurrentState());
1340 // This is soooo ugly. Isn`t it possible to make
1341 // it simpler? (Lgb)
1342 LyXText * txt = owner->view()->text;
1343 LyXDirection direction = txt->cursor.par->getParDirection();
1344 if(!txt->mark_set) owner->view()->beforeChange();
1345 owner->view()->update(-2);
1346 if (direction == LYX_DIR_LEFT_TO_RIGHT)
1348 if (txt->cursor.pos < txt->cursor.par->Last()
1349 && txt->cursor.par->GetChar(txt->cursor.pos)
1350 == LyXParagraph::META_INSET
1351 && txt->cursor.par->GetInset(txt->cursor.pos)
1352 && txt->cursor.par->GetInset(txt->cursor.pos)->Editable() == 2) {
1353 Inset * tmpinset = txt->cursor.par->GetInset(txt->cursor.pos);
1354 setMessage(tmpinset->EditMessage());
1355 tmpinset->Edit(tmpinset->Width(txt->GetFont(txt->cursor.par,
1356 txt->cursor.pos)), 0);
1359 if (direction == LYX_DIR_RIGHT_TO_LEFT)
1362 owner->view()->text->FinishUndo();
1363 moveCursorUpdate(false);
1364 owner->getMiniBuffer()->Set(CurrentState());
1370 if(!owner->view()->text->mark_set) owner->view()->beforeChange();
1371 owner->view()->update(-3);
1372 owner->view()->text->CursorUp();
1373 owner->view()->text->FinishUndo();
1374 moveCursorUpdate(false);
1375 owner->getMiniBuffer()->Set(CurrentState());
1379 if(!owner->view()->text->mark_set)
1380 owner->view()->beforeChange();
1381 owner->view()->update(-3);
1382 owner->view()->text->CursorDown();
1383 owner->view()->text->FinishUndo();
1384 moveCursorUpdate(false);
1385 owner->getMiniBuffer()->Set(CurrentState());
1388 case LFUN_UP_PARAGRAPH:
1389 if(!owner->view()->text->mark_set)
1390 owner->view()->beforeChange();
1391 owner->view()->update(-3);
1392 owner->view()->text->CursorUpParagraph();
1393 owner->view()->text->FinishUndo();
1394 moveCursorUpdate(false);
1395 owner->getMiniBuffer()->Set(CurrentState());
1398 case LFUN_DOWN_PARAGRAPH:
1399 if(!owner->view()->text->mark_set)
1400 owner->view()->beforeChange();
1401 owner->view()->update(-3);
1402 owner->view()->text->CursorDownParagraph();
1403 owner->view()->text->FinishUndo();
1404 moveCursorUpdate(false);
1405 owner->getMiniBuffer()->Set(CurrentState());
1409 if(!owner->view()->text->mark_set)
1410 owner->view()->beforeChange();
1411 owner->view()->update(-3);
1412 owner->view()->cursorPrevious();
1413 owner->view()->text->FinishUndo();
1414 moveCursorUpdate(false);
1415 owner->getMiniBuffer()->Set(CurrentState());
1419 if(!owner->view()->text->mark_set)
1420 owner->view()->beforeChange();
1421 owner->view()->update(-3);
1422 owner->view()->cursorNext();
1423 owner->view()->text->FinishUndo();
1424 moveCursorUpdate(false);
1425 owner->getMiniBuffer()->Set(CurrentState());
1429 if(!owner->view()->text->mark_set)
1430 owner->view()->beforeChange();
1431 owner->view()->update(-2);
1432 owner->view()->text->CursorHome();
1433 owner->view()->text->FinishUndo();
1434 moveCursorUpdate(false);
1435 owner->getMiniBuffer()->Set(CurrentState());
1439 if(!owner->view()->text->mark_set)
1440 owner->view()->beforeChange();
1441 owner->view()->update(-2);
1442 owner->view()->text->CursorEnd();
1443 owner->view()->text->FinishUndo();
1444 moveCursorUpdate(false);
1445 owner->getMiniBuffer()->Set(CurrentState());
1449 if(!owner->view()->text->mark_set)
1450 owner->view()->beforeChange();
1451 owner->view()->update(-2);
1452 owner->view()->text->CursorTab();
1453 owner->view()->text->FinishUndo();
1454 moveCursorUpdate(false);
1455 owner->getMiniBuffer()->Set(CurrentState());
1458 case LFUN_WORDRIGHT:
1459 if(!owner->view()->text->mark_set)
1460 owner->view()->beforeChange();
1461 owner->view()->update(-2);
1462 if (owner->view()->text->cursor.par->getParDirection()
1463 == LYX_DIR_LEFT_TO_RIGHT)
1464 owner->view()->text->CursorRightOneWord();
1466 owner->view()->text->CursorLeftOneWord();
1467 owner->view()->text->FinishUndo();
1468 moveCursorUpdate(false);
1469 owner->getMiniBuffer()->Set(CurrentState());
1473 if(!owner->view()->text->mark_set)
1474 owner->view()->beforeChange();
1475 owner->view()->update(-2);
1476 if (owner->view()->text->cursor.par->getParDirection()
1477 == LYX_DIR_LEFT_TO_RIGHT)
1478 owner->view()->text->CursorLeftOneWord();
1480 owner->view()->text->CursorRightOneWord();
1481 owner->view()->text->FinishUndo();
1482 moveCursorUpdate(false);
1483 owner->getMiniBuffer()->Set(CurrentState());
1486 case LFUN_BEGINNINGBUF:
1487 if(!owner->view()->text->mark_set)
1488 owner->view()->beforeChange();
1489 owner->view()->update(-2);
1490 owner->view()->text->CursorTop();
1491 owner->view()->text->FinishUndo();
1492 moveCursorUpdate(false);
1493 owner->getMiniBuffer()->Set(CurrentState());
1497 if(!owner->view()->text->mark_set)
1498 owner->view()->beforeChange();
1499 owner->view()->update(-2);
1500 owner->view()->text->CursorBottom();
1501 owner->view()->text->FinishUndo();
1502 moveCursorUpdate(false);
1503 owner->getMiniBuffer()->Set(CurrentState());
1507 /* cursor selection ---------------------------- */
1509 owner->view()->update(-2);
1510 if (owner->view()->text->cursor.par->getParDirection()
1511 == LYX_DIR_LEFT_TO_RIGHT)
1512 owner->view()->text->CursorRight();
1514 owner->view()->text->CursorLeft();
1515 owner->view()->text->FinishUndo();
1516 moveCursorUpdate(true);
1517 owner->getMiniBuffer()->Set(CurrentState());
1521 owner->view()->update(-2);
1522 if (owner->view()->text->cursor.par->getParDirection()
1523 == LYX_DIR_LEFT_TO_RIGHT)
1524 owner->view()->text->CursorLeft();
1526 owner->view()->text->CursorRight();
1527 owner->view()->text->FinishUndo();
1528 moveCursorUpdate(true);
1529 owner->getMiniBuffer()->Set(CurrentState());
1533 owner->view()->update(-2);
1534 owner->view()->text->CursorUp();
1535 owner->view()->text->FinishUndo();
1536 moveCursorUpdate(true);
1537 owner->getMiniBuffer()->Set(CurrentState());
1541 owner->view()->update(-2);
1542 owner->view()->text->CursorDown();
1543 owner->view()->text->FinishUndo();
1544 moveCursorUpdate(true);
1545 owner->getMiniBuffer()->Set(CurrentState());
1548 case LFUN_UP_PARAGRAPHSEL:
1549 owner->view()->update(-2);
1550 owner->view()->text->CursorUpParagraph();
1551 owner->view()->text->FinishUndo();
1552 moveCursorUpdate(true);
1553 owner->getMiniBuffer()->Set(CurrentState());
1556 case LFUN_DOWN_PARAGRAPHSEL:
1557 owner->view()->update(-2);
1558 owner->view()->text->CursorDownParagraph();
1559 owner->view()->text->FinishUndo();
1560 moveCursorUpdate(true);
1561 owner->getMiniBuffer()->Set(CurrentState());
1565 owner->view()->update(-2);
1566 owner->view()->cursorPrevious();
1567 owner->view()->text->FinishUndo();
1568 moveCursorUpdate(true);
1569 owner->getMiniBuffer()->Set(CurrentState());
1573 owner->view()->update(-2);
1574 owner->view()->cursorNext();
1575 owner->view()->text->FinishUndo();
1576 moveCursorUpdate(true);
1577 owner->getMiniBuffer()->Set(CurrentState());
1581 owner->view()->update(-2);
1582 owner->view()->text->CursorHome();
1583 owner->view()->text->FinishUndo();
1584 moveCursorUpdate(true);
1585 owner->getMiniBuffer()->Set(CurrentState());
1589 owner->view()->update(-2);
1590 owner->view()->text->CursorEnd();
1591 owner->view()->text->FinishUndo();
1592 moveCursorUpdate(true);
1593 owner->getMiniBuffer()->Set(CurrentState());
1596 case LFUN_WORDRIGHTSEL:
1597 owner->view()->update(-2);
1598 if (owner->view()->text->cursor.par->getParDirection()
1599 == LYX_DIR_LEFT_TO_RIGHT)
1600 owner->view()->text->CursorRightOneWord();
1602 owner->view()->text->CursorLeftOneWord();
1603 owner->view()->text->FinishUndo();
1604 moveCursorUpdate(true);
1605 owner->getMiniBuffer()->Set(CurrentState());
1608 case LFUN_WORDLEFTSEL:
1609 owner->view()->update(-2);
1610 if (owner->view()->text->cursor.par->getParDirection()
1611 == LYX_DIR_LEFT_TO_RIGHT)
1612 owner->view()->text->CursorLeftOneWord();
1614 owner->view()->text->CursorRightOneWord();
1615 owner->view()->text->FinishUndo();
1616 moveCursorUpdate(true);
1617 owner->getMiniBuffer()->Set(CurrentState());
1620 case LFUN_BEGINNINGBUFSEL:
1621 owner->view()->update(-2);
1622 owner->view()->text->CursorTop();
1623 owner->view()->text->FinishUndo();
1624 moveCursorUpdate(true);
1625 owner->getMiniBuffer()->Set(CurrentState());
1628 case LFUN_ENDBUFSEL:
1629 owner->view()->update(-2);
1630 owner->view()->text->CursorBottom();
1631 owner->view()->text->FinishUndo();
1632 moveCursorUpdate(true);
1633 owner->getMiniBuffer()->Set(CurrentState());
1636 // --- text changing commands ------------------------
1637 case LFUN_BREAKLINE:
1638 owner->view()->beforeChange();
1639 owner->view()->text->InsertChar(LyXParagraph::META_NEWLINE);
1640 owner->view()->smallUpdate(1);
1641 SetUpdateTimer(0.01);
1642 moveCursorUpdate(false);
1645 case LFUN_PROTECTEDSPACE:
1646 owner->view()->beforeChange();
1647 owner->view()->text->
1648 InsertChar(LyXParagraph::META_PROTECTED_SEPARATOR);
1649 owner->view()->smallUpdate(1);
1651 moveCursorUpdate(false);
1655 if(owner->view()->text->mark_set) {
1656 owner->view()->beforeChange();
1657 owner->view()->update(0);
1658 setMessage(N_("Mark removed"));
1660 owner->view()->beforeChange();
1661 owner->view()->text->mark_set = 1;
1662 owner->view()->update(0);
1663 setMessage(N_("Mark set"));
1665 owner->view()->text->sel_cursor =
1666 owner->view()->text->cursor;
1671 if (!owner->view()->text->selection) {
1672 owner->view()->text->Delete();
1673 owner->view()->text->sel_cursor =
1674 owner->view()->text->cursor;
1675 owner->view()->smallUpdate(1);
1676 // It is possible to make it a lot faster still
1677 // just comment out the lone below...
1678 owner->view()->getScreen()->ShowCursor();
1680 owner->view()->cut();
1683 moveCursorUpdate(false);
1684 owner->getMiniBuffer()->Set(CurrentState());
1685 owner->view()->SetState();
1688 case LFUN_DELETE_SKIP:
1690 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1692 LyXCursor cursor = owner->view()->text->cursor;
1695 if (!owner->view()->text->selection) {
1696 if (cursor.pos == cursor.par->Last()) {
1697 owner->view()->text->CursorRight();
1698 cursor = owner->view()->text->cursor;
1700 && !(cursor.par->added_space_top
1701 == VSpace (VSpace::NONE))) {
1702 owner->view()->text->SetParagraph
1703 (cursor.par->line_top,
1704 cursor.par->line_bottom,
1705 cursor.par->pagebreak_top,
1706 cursor.par->pagebreak_bottom,
1707 VSpace(VSpace::NONE),
1708 cursor.par->added_space_bottom,
1710 cursor.par->labelwidthstring, 0);
1711 owner->view()->text->CursorLeft();
1712 owner->view()->update (1);
1714 owner->view()->text->CursorLeft();
1715 owner->view()->text->Delete();
1716 owner->view()->text->sel_cursor =
1717 owner->view()->text->cursor;
1718 owner->view()->smallUpdate(1);
1721 owner->view()->text->Delete();
1722 owner->view()->text->sel_cursor =
1723 owner->view()->text->cursor;
1724 owner->view()->smallUpdate(1);
1727 owner->view()->cut();
1733 /* -------> Delete word forward. */
1734 case LFUN_DELETE_WORD_FORWARD:
1735 owner->view()->update(-2);
1737 owner->view()->text->DeleteWordForward();
1738 owner->view()->update( 1 );
1740 moveCursorUpdate(false);
1741 owner->getMiniBuffer()->Set(CurrentState());
1744 /* -------> Delete word backward. */
1745 case LFUN_DELETE_WORD_BACKWARD:
1746 owner->view()->update(-2);
1748 owner->view()->text->DeleteWordBackward();
1749 owner->view()->update( 1 );
1751 moveCursorUpdate(false);
1752 owner->getMiniBuffer()->Set(CurrentState());
1755 /* -------> Kill to end of line. */
1756 case LFUN_DELETE_LINE_FORWARD:
1758 owner->view()->update(-2);
1759 owner->view()->text->DeleteLineForward();
1760 owner->view()->update( 1 );
1762 moveCursorUpdate(false);
1765 /* -------> Set mark off. */
1767 owner->view()->beforeChange();
1768 owner->view()->update(0);
1769 owner->view()->text->sel_cursor =
1770 owner->view()->text->cursor;
1771 setMessage(N_("Mark off"));
1774 /* -------> Set mark on. */
1776 owner->view()->beforeChange();
1777 owner->view()->text->mark_set = 1;
1778 owner->view()->update( 0 );
1779 owner->view()->text->sel_cursor =
1780 owner->view()->text->cursor;
1781 setMessage(N_("Mark on"));
1784 case LFUN_BACKSPACE:
1787 if (!owner->view()->text->selection) {
1788 if (owner->getIntl()->getTrans()->backspace()) {
1789 owner->view()->text->Backspace();
1790 owner->view()->text->sel_cursor =
1791 owner->view()->text->cursor;
1792 owner->view()->smallUpdate(1);
1793 // It is possible to make it a lot faster still
1794 // just comment out the lone below...
1795 owner->view()->getScreen()->ShowCursor();
1798 owner->view()->cut();
1801 owner->getMiniBuffer()->Set(CurrentState());
1802 owner->view()->SetState();
1806 case LFUN_BACKSPACE_SKIP:
1808 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1810 LyXCursor cursor = owner->view()->text->cursor;
1813 if (!owner->view()->text->selection) {
1815 && !(cursor.par->added_space_top
1816 == VSpace (VSpace::NONE))) {
1817 owner->view()->text->SetParagraph
1818 (cursor.par->line_top,
1819 cursor.par->line_bottom,
1820 cursor.par->pagebreak_top,
1821 cursor.par->pagebreak_bottom,
1822 VSpace(VSpace::NONE), cursor.par->added_space_bottom,
1824 cursor.par->labelwidthstring, 0);
1825 owner->view()->update (1);
1827 owner->view()->text->Backspace();
1828 owner->view()->text->sel_cursor
1830 owner->view()->smallUpdate (1);
1833 owner->view()->cut();
1838 case LFUN_BREAKPARAGRAPH:
1840 owner->view()->beforeChange();
1841 owner->view()->text->BreakParagraph(0);
1842 owner->view()->smallUpdate(1);
1843 SetUpdateTimer(0.01);
1844 owner->view()->text->sel_cursor =
1845 owner->view()->text->cursor;
1846 owner->view()->SetState();
1847 owner->getMiniBuffer()->Set(CurrentState());
1851 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1853 owner->view()->beforeChange();
1854 owner->view()->text->BreakParagraph(1);
1855 owner->view()->smallUpdate(1);
1856 SetUpdateTimer(0.01);
1857 owner->view()->text->sel_cursor =
1858 owner->view()->text->cursor;
1859 owner->view()->SetState();
1860 owner->getMiniBuffer()->Set(CurrentState());
1864 case LFUN_BREAKPARAGRAPH_SKIP:
1866 // When at the beginning of a paragraph, remove
1867 // indentation and add a "defskip" at the top.
1868 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
1870 LyXCursor cursor = owner->view()->text->cursor;
1872 owner->view()->beforeChange();
1873 if (cursor.pos == 0) {
1874 if (cursor.par->added_space_top == VSpace(VSpace::NONE)) {
1875 owner->view()->text->SetParagraph
1876 (cursor.par->line_top,
1877 cursor.par->line_bottom,
1878 cursor.par->pagebreak_top,
1879 cursor.par->pagebreak_bottom,
1880 VSpace(VSpace::DEFSKIP), cursor.par->added_space_bottom,
1882 cursor.par->labelwidthstring, 1);
1883 owner->view()->update(1);
1887 owner->view()->text->BreakParagraph(0);
1888 owner->view()->smallUpdate(1);
1890 SetUpdateTimer(0.01);
1891 owner->view()->text->sel_cursor = cursor;
1892 owner->view()->SetState();
1893 owner->getMiniBuffer()->Set(CurrentState());
1898 owner->view()->beforeChange();
1899 owner->view()->text->InsertChar('\"'); // This " matches the single quote in the code
1900 owner->view()->smallUpdate(1);
1902 moveCursorUpdate(false);
1908 InsetCommand * new_inset;
1909 if (action == LFUN_HTMLURL)
1910 new_inset = new InsetUrl("htmlurl", "", "");
1912 new_inset = new InsetUrl("url", "", "");
1913 owner->view()->insertInset(new_inset);
1914 new_inset->Edit(0, 0);
1918 // --- lyxserver commands ----------------------------
1920 case LFUN_CHARATCURSOR:
1922 LyXParagraph::size_type pos =
1923 owner->view()->text->cursor.pos;
1924 if(pos < owner->view()->text->cursor.par->size())
1925 dispatch_buffer = owner->view()->text->
1926 cursor.par->text[pos];
1928 dispatch_buffer = "EOF";
1934 tostr(owner->view()->text->cursor.x) + ' '
1935 + tostr(owner->view()->text->cursor.y);
1942 sscanf(argument.c_str(), " %d %ld", &x, &y);
1943 owner->view()->text->SetCursorFromCoordinates(x, y);
1947 case LFUN_GETLAYOUT:
1949 tostr(owner->view()->text->cursor.par->layout);
1954 LyXFont * font = &(owner->view()->text->current_font);
1955 if(font->shape() == LyXFont::ITALIC_SHAPE)
1956 dispatch_buffer = 'E';
1957 else if(font->shape() == LyXFont::SMALLCAPS_SHAPE)
1958 dispatch_buffer = 'N';
1960 dispatch_buffer = '0';
1967 LyXFont * font = &(owner->view()->text->current_font);
1968 if(font->latex() == LyXFont::ON)
1969 dispatch_buffer = 'L';
1971 dispatch_buffer = '0';
1976 setMessage(owner->buffer()->fileName());
1977 lyxerr.debug() << "FNAME["
1978 << owner->buffer()->fileName()
1986 dispatch_buffer = buf;
1987 lyxserver->notifyClient(dispatch_buffer);
1991 case LFUN_GOTOFILEROW:
1993 char file_name[100];
1995 sscanf(argument.c_str(), " %s %d", file_name, &row);
1997 // Must replace extension of the file to be .lyx and get full path
1998 string s = ChangeExtension(string(file_name), ".lyx", false);
2000 // Either change buffer or load the file
2001 if (bufferlist.exists(s))
2002 owner->view()->buffer(bufferlist.getBuffer(s));
2004 owner->view()->buffer(bufferlist.loadLyXFile(s));
2007 owner->view()->setCursorFromRow(row);
2010 owner->view()->beforeChange();
2011 if (owner->view()->text->cursor.y >
2012 owner->view()->getWorkArea()->height() / 2
2014 owner->view()->getScreen()->
2015 Draw(owner->view()->text->cursor.y -
2016 owner->view()->getWorkArea()->height() / 2
2019 owner->view()->getScreen()->
2022 owner->view()->update(0);
2023 owner->view()->redraw();
2030 int qa = lyxaction.LookupFunc(argument.c_str());
2031 setMessage(lyxaction.helpText(static_cast<kb_action>(qa)));
2035 // --- accented characters ---------------------------
2038 case LFUN_CIRCUMFLEX:
2048 case LFUN_SPECIAL_CARON:
2051 case LFUN_HUNG_UMLAUT:
2057 if (keyseq.length == -1 && keyseq.getiso() != 0)
2058 c = keyseq.getiso();
2062 owner->getIntl()->getTrans()->
2063 deadkey(c, get_accent(action).accent,
2064 owner->view()->text);
2066 // Need to reset, in case the minibuffer calls these
2071 // copied verbatim from do_accent_char
2072 owner->view()->smallUpdate(1);
2074 owner->view()->text->sel_cursor =
2075 owner->view()->text->cursor;
2079 // --- toolbar ----------------------------------
2080 case LFUN_PUSH_TOOLBAR:
2082 int nth = strToInt(argument);
2083 if (lyxerr.debugging(Debug::TOOLBAR)) {
2084 lyxerr << "LFUN_PUSH_TOOLBAR: argument = `"
2085 << argument << "'\n"
2086 << "LFUN_PUSH_TOOLBAR: nth = `"
2087 << nth << "'" << endl;
2092 setErrorMessage(N_("Push-toolbar needs argument > 0"));
2094 owner->getToolbar()->push(nth);
2099 case LFUN_ADD_TO_TOOLBAR:
2101 if (lyxerr.debugging(Debug::TOOLBAR)) {
2102 lyxerr << "LFUN_ADD_TO_TOOLBAR:"
2103 "argument = `" << argument << '\'' << endl;
2105 string tmp(argument);
2106 //lyxerr <<string("Argument: ") + argument);
2107 //lyxerr <<string("Tmp : ") + tmp);
2110 setErrorMessage(N_("Usage: toolbar-add-to <LyX command>"));
2112 owner->getToolbar()->add(argument, false);
2113 owner->getToolbar()->set();
2118 // --- insert characters ----------------------------------------
2120 // --- Mathed stuff. If we are here, there is no locked inset yet.
2125 if (!greek_kb_flag) {
2127 setMessage(N_("Math greek mode on"));
2134 case LFUN_GREEK_TOGGLE:
2136 greek_kb_flag = greek_kb_flag ? 0 : 2;
2137 if (greek_kb_flag) {
2138 setMessage(N_("Math greek keyboard on"));
2140 setMessage(N_("Math greek keyboard off"));
2145 case LFUN_MATH_DELIM:
2146 case LFUN_INSERT_MATRIX:
2148 if (owner->view()->available()) {
2150 open_new_inset(new InsetFormula(false));
2152 the_locking_inset->LocalDispatch(action, argument.c_str());
2157 case LFUN_INSERT_MATH:
2159 math_insert_symbol(argument.c_str());
2163 case LFUN_MATH_DISPLAY:
2165 if (owner->view()->available())
2166 owner->view()->open_new_inset(new InsetFormula(true));
2170 case LFUN_MATH_MACRO:
2172 if (owner->view()->available()) {
2175 setErrorMessage(N_("Missing argument"));
2177 string s1 = token(s, ' ', 1);
2178 int na = s1.empty() ? 0: atoi(s1.c_str());
2180 open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2186 case LFUN_MATH_MODE: // Open or create a math inset
2189 if (owner->view()->available())
2190 owner->view()->open_new_inset(new InsetFormula);
2191 setMessage(N_("Math editor mode"));
2195 case LFUN_MATH_NUMBER:
2196 case LFUN_MATH_LIMITS:
2198 setErrorMessage(N_("This is only allowed in math mode!"));
2202 case LFUN_INSERT_CITATION:
2204 InsetCitation * new_inset = new InsetCitation();
2206 // The note, if any, must be after the key, delimited
2207 // by a | so both key and remark can have spaces.
2208 if (!argument.empty()) {
2209 string lsarg(argument);
2210 if (contains(lsarg, "|")) {
2211 new_inset->setContents(token(lsarg, '|', 0));
2212 new_inset->setOptions(token(lsarg, '|', 1));
2214 new_inset->setContents(lsarg);
2215 owner->view()->insertInset(new_inset);
2217 owner->view()->insertInset(new_inset);
2218 new_inset->Edit(0, 0);
2223 case LFUN_INSERT_BIBTEX:
2225 // ale970405+lasgoutt970425
2226 // The argument can be up to two tokens separated
2227 // by a space. The first one is the bibstyle.
2228 string lsarg(argument);
2229 string bibstyle = token(lsarg, ' ', 1);
2230 if (bibstyle.empty())
2232 InsetBibtex * new_inset
2233 = new InsetBibtex(token(lsarg, ' ', 0),
2237 owner->view()->insertInset(new_inset);
2238 if (lsarg.empty()) {
2239 new_inset->Edit(0, 0);
2244 // BibTeX data bases
2245 case LFUN_BIBDB_ADD:
2247 InsetBibtex * inset =
2248 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2250 inset->addDatabase(argument);
2255 case LFUN_BIBDB_DEL:
2257 InsetBibtex * inset =
2258 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2260 inset->delDatabase(argument);
2265 case LFUN_BIBTEX_STYLE:
2267 InsetBibtex * inset =
2268 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2270 inset->setOptions(argument);
2275 case LFUN_INDEX_INSERT:
2276 case LFUN_INDEX_INSERT_LAST:
2278 // Can't do that at the beginning of a paragraph.
2279 if (owner->view()->text->cursor.pos - 1 < 0)
2282 InsetIndex * new_inset = new InsetIndex();
2283 if (!argument.empty()) {
2284 string lsarg(argument);
2285 new_inset->setContents(lsarg);
2286 owner->view()->insertInset(new_inset);
2289 //get the current word for an argument
2290 LyXParagraph::size_type lastpos =
2291 owner->view()->text->cursor.pos - 1;
2292 // Get the current word. note that this must be done
2293 // before inserting the inset, or the inset will
2295 string curstring(owner->view()
2296 ->text->cursor.par->GetWord(lastpos));
2298 //make the new inset and write the current word into it
2299 InsetIndex * new_inset = new InsetIndex();
2301 new_inset->setContents(curstring);
2303 //don't edit it if the call was to INSERT_LAST
2304 if(action != LFUN_INDEX_INSERT_LAST) {
2305 new_inset->Edit(0, 0);
2307 //it looks blank on the screen unless
2308 //we do something. put it here.
2310 // move the cursor to the returned value of lastpos
2311 // but only for the auto-insert
2312 owner->view()->text->cursor.pos = lastpos;
2315 //put the new inset into the buffer.
2316 // there should be some way of knowing the user
2317 //cancelled & avoiding this, but i don't know how
2318 owner->view()->insertInset(new_inset);
2323 case LFUN_INDEX_PRINT:
2325 Inset * new_inset = new InsetPrintIndex(owner->buffer());
2326 owner->view()->insertInset(new_inset, "Standard", true);
2330 case LFUN_PARENTINSERT:
2332 lyxerr << "arg " << argument << endl;
2333 Inset * new_inset = new InsetParent(argument, owner->buffer());
2334 owner->view()->insertInset(new_inset, "Standard", true);
2338 case LFUN_CHILDINSERT:
2340 Inset * new_inset = new InsetInclude(argument,
2342 owner->view()->insertInset(new_inset, "Standard", true);
2343 new_inset->Edit(0, 0);
2347 case LFUN_CHILDOPEN:
2350 MakeAbsPath(argument,
2351 OnlyPath(owner->buffer()->fileName()));
2352 setMessage(N_("Opening child document ") +
2353 MakeDisplayPath(filename) + "...");
2354 owner->view()->savePosition();
2355 if (bufferlist.exists(filename))
2356 owner->view()->buffer(bufferlist.getBuffer(filename));
2358 owner->view()->buffer(bufferlist.loadLyXFile(filename));
2362 case LFUN_INSERT_NOTE:
2363 owner->view()->insertNote();
2366 case LFUN_INSERTFOOTNOTE:
2368 LyXParagraph::footnote_kind kind;
2369 if (argument == "footnote")
2370 { kind = LyXParagraph::FOOTNOTE; }
2371 else if (argument == "margin")
2372 { kind = LyXParagraph::MARGIN; }
2373 else if (argument == "figure")
2374 { kind = LyXParagraph::FIG; }
2375 else if (argument == "table")
2376 { kind = LyXParagraph::TAB; }
2377 else if (argument == "wide-fig")
2378 { kind = LyXParagraph::WIDE_FIG; }
2379 else if (argument == "wide-tab")
2380 { kind = LyXParagraph::WIDE_TAB; }
2381 else if (argument == "algorithm")
2382 { kind = LyXParagraph::ALGORITHM; }
2384 setErrorMessage(N_("Unknown kind of footnote"));
2387 owner->view()->text->InsertFootnoteEnvironment(kind);
2388 owner->view()->update(1);
2389 owner->view()->SetState();
2393 case LFUN_BUFFERBULLETSSELECT:
2397 case LFUN_TOGGLECURSORFOLLOW:
2398 cursor_follows_scrollbar = !cursor_follows_scrollbar;
2401 case LFUN_KMAP_OFF: // keymap off
2402 owner->getIntl()->KeyMapOn(false);
2405 case LFUN_KMAP_PRIM: // primary keymap
2406 owner->getIntl()->KeyMapPrim();
2409 case LFUN_KMAP_SEC: // secondary keymap
2410 owner->getIntl()->KeyMapSec();
2413 case LFUN_KMAP_TOGGLE: // toggle keymap
2414 owner->getIntl()->ToggleKeyMap();
2417 case LFUN_SELFINSERT:
2419 for (string::size_type i = 0; i < argument.length(); ++i) {
2420 owner->view()->text->InsertChar(argument[i]);
2421 // This needs to be in the loop, or else we
2422 // won't break lines correctly. (Asger)
2423 owner->view()->smallUpdate(1);
2426 owner->view()->text->sel_cursor =
2427 owner->view()->text->cursor;
2428 moveCursorUpdate(false);
2434 // argument contains ';'-terminated commands
2435 while (argument.find(';') != string::npos) {
2437 argument = split(argument, first, ';');
2443 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
2451 now_time_t = time(NULL);
2452 now_tm = localtime(&now_time_t);
2453 (void)setlocale(LC_TIME, "");
2454 if (!argument.empty())
2456 else if (arg.empty())
2457 arg = lyxrc->date_insert_format;
2458 datetmp_len = (int) strftime(datetmp, 32, arg.c_str(), now_tm);
2459 for (int i = 0; i < datetmp_len; i++) {
2460 owner->view()->text->InsertChar(datetmp[i]);
2461 owner->view()->smallUpdate(1);
2464 owner->view()->text->sel_cursor = owner->view()->text->cursor;
2465 moveCursorUpdate(false);
2469 case LFUN_SAVEPREFERENCES:
2471 Path p(user_lyxdir);
2472 lyxrc->write("preferences");
2476 case LFUN_UNKNOWN_ACTION:
2478 if(!owner->buffer()) {
2480 setErrorMessage(N_("No document open"));
2484 if (owner->buffer()->isReadonly()) {
2486 setErrorMessage(N_("Document is read only"));
2490 if (!argument.empty()) {
2492 /* Automatically delete the currently selected
2493 * text and replace it with what is being
2494 * typed in now. Depends on lyxrc settings
2495 * "auto_region_delete", which defaults to
2498 if ( lyxrc->auto_region_delete ) {
2499 if (owner->view()->text->selection){
2500 owner->view()->text->CutSelection(false);
2501 owner->view()->update(-1);
2505 owner->view()->beforeChange();
2506 for (string::size_type i = 0;
2507 i < argument.length(); ++i) {
2508 if (greek_kb_flag) {
2509 if (!math_insert_greek(argument[i]))
2510 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2512 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2515 owner->view()->smallUpdate(1);
2518 owner->view()->text->sel_cursor =
2519 owner->view()->text->cursor;
2520 moveCursorUpdate(false);
2523 // why is an "Unknown action" with empty
2524 // argument even dispatched in the first
2525 // place? I`ll probably change that. (Lgb)
2527 setErrorMessage(N_("Unknown action"));
2531 lyxerr << "A truly unknown func!" << endl;
2537 string res = getMessage();
2540 if (!commandshortcut.empty()) {
2541 string newbuf = owner->getMiniBuffer()->GetText();
2542 if (newbuf != commandshortcut) {
2543 owner->getMiniBuffer()->Set(newbuf
2549 owner->getMiniBuffer()->Set(string(_(res.c_str()))
2550 + " " + commandshortcut);
2557 void LyXFunc::setupLocalKeymap()
2559 keyseq.stdmap = keyseq.curmap = toplevel_keymap;
2560 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap;
2564 void LyXFunc::MenuNew(bool fromTemplate)
2566 string fname, initpath = lyxrc->document_path;
2569 if (owner->view()->available()) {
2570 string trypath = owner->buffer()->filepath;
2571 // If directory is writeable, use this as default.
2572 if (IsDirWriteable(trypath) == 1)
2577 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2578 fileDlg.SetButton(1, _("Templates"), lyxrc->template_path);
2579 fname = fileDlg.Select(_("Enter Filename for new document"),
2580 initpath, "*.lyx", _("newfile"));
2583 if (fname.empty()) {
2584 owner->getMiniBuffer()->Set(_("Canceled."));
2585 lyxerr.debug() << "New Document Cancelled." << endl;
2589 // get absolute path of file and make sure the filename ends
2591 string s = MakeAbsPath(fname);
2592 if (!IsLyXFilename(s))
2595 // Check if the document already is open
2596 if (bufferlist.exists(s)){
2597 switch(AskConfirmation(_("Document is already open:"),
2598 MakeDisplayPath(s, 50),
2599 _("Do you want to close that document now?\n"
2600 "('No' will just switch to the open version)")))
2602 case 1: // Yes: close the document
2603 if (!bufferlist.close(bufferlist.getBuffer(s)))
2604 // If close is canceled, we cancel here too.
2607 case 2: // No: switch to the open document
2608 owner->view()->buffer(bufferlist.getBuffer(s));
2610 case 3: // Cancel: Do nothing
2611 owner->getMiniBuffer()->Set(_("Canceled."));
2616 // Check whether the file already exists
2617 if (IsLyXFilename(s)) {
2619 if (fi.readable() &&
2620 AskQuestion(_("File already exists:"),
2621 MakeDisplayPath(s, 50),
2622 _("Do you want to open the document?"))) {
2624 owner->getMiniBuffer()->Set(_("Opening document"),
2625 MakeDisplayPath(s), "...");
2627 owner->view()->buffer(
2628 bufferlist.loadLyXFile(s));
2629 owner->getMiniBuffer()->Set(_("Document"),
2636 // The template stuff
2640 fname = fileDlg.Select(_("Choose template"),
2641 lyxrc->template_path,
2647 // find a free buffer
2648 lyxerr.debug() << "Find a free buffer." << endl;
2649 owner->view()->buffer(bufferlist.newFile(s, templname));
2653 void LyXFunc::MenuOpen()
2655 string initpath = lyxrc->document_path;
2658 if (owner->view()->available()) {
2659 string trypath = owner->buffer()->filepath;
2660 // If directory is writeable, use this as default.
2661 if (IsDirWriteable(trypath) == 1)
2667 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2668 fileDlg.SetButton(1, _("Examples"),
2669 AddPath(system_lyxdir, "examples"));
2670 string filename = fileDlg.Select(_("Select Document to Open"),
2674 // check selected filename
2675 if (filename.empty()) {
2676 owner->getMiniBuffer()->Set(_("Canceled."));
2680 // get absolute path of file and make sure the filename ends
2682 filename = MakeAbsPath(filename);
2683 if (!IsLyXFilename(filename))
2687 owner->getMiniBuffer()->Set(_("Opening document"),
2688 MakeDisplayPath(filename), "...");
2689 Buffer * openbuf = bufferlist.loadLyXFile(filename);
2691 owner->view()->buffer(openbuf);
2692 owner->getMiniBuffer()->Set(_("Document"),
2693 MakeDisplayPath(filename),
2696 owner->getMiniBuffer()->Set(_("Could not open document"),
2697 MakeDisplayPath(filename));
2702 void LyXFunc::doImportASCII(bool linorpar)
2704 string initpath = lyxrc->document_path;
2707 if (owner->view()->available()) {
2708 string trypath = owner->buffer()->filepath;
2709 // If directory is writeable, use this as default.
2710 if (IsDirWriteable(trypath) == 1)
2716 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2717 fileDlg.SetButton(1, _("Examples"),
2718 AddPath(system_lyxdir, "examples"));
2719 string filename = fileDlg.Select(_("Select ASCII file to Import"),
2723 // check selected filename
2724 if (filename.empty()) {
2725 owner->getMiniBuffer()->Set(_("Canceled."));
2729 // get absolute path of file
2730 filename = MakeAbsPath(filename);
2732 string s = ChangeExtension(filename, ".lyx", false);
2734 // Check if the document already is open
2735 if (bufferlist.exists(s)) {
2736 switch(AskConfirmation(_("Document is already open:"),
2737 MakeDisplayPath(s, 50),
2738 _("Do you want to close that document now?\n"
2739 "('No' will just switch to the open version)")))
2741 case 1: // Yes: close the document
2742 if (!bufferlist.close(bufferlist.getBuffer(s)))
2743 // If close is canceled, we cancel here too.
2746 case 2: // No: switch to the open document
2747 owner->view()->buffer(bufferlist.getBuffer(s));
2749 case 3: // Cancel: Do nothing
2750 owner->getMiniBuffer()->Set(_("Canceled."));
2755 // Check if a LyX document by the same root exists in filesystem
2756 FileInfo f(s, true);
2757 if (f.exist() && !AskQuestion(_("A document by the name"),
2759 _("already exists. Overwrite?"))) {
2760 owner->getMiniBuffer()->Set(_("Canceled."));
2764 owner->view()->buffer(bufferlist.newFile(s, string()));
2765 owner->getMiniBuffer()->Set(_("Importing ASCII file"),
2766 MakeDisplayPath(filename), "...");
2767 // Insert ASCII file
2768 InsertAsciiFile(filename, linorpar);
2769 owner->getMiniBuffer()->Set(_("ASCII file "),
2770 MakeDisplayPath(filename),
2775 void LyXFunc::doImportLaTeX(bool isnoweb)
2777 string initpath = lyxrc->document_path;
2780 if (owner->view()->available()) {
2781 string trypath = owner->buffer()->filepath;
2782 // If directory is writeable, use this as default.
2783 if (IsDirWriteable(trypath) == 1)
2789 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2790 fileDlg.SetButton(1, _("Examples"),
2791 AddPath(system_lyxdir, "examples"));
2794 filename = fileDlg.Select(_("Select Noweb file to Import"),
2797 filename = fileDlg.Select(_("Select LaTeX file to Import"),
2803 // check selected filename
2804 if (filename.empty()) {
2805 owner->getMiniBuffer()->Set(_("Canceled."));
2809 // get absolute path of file
2810 filename = MakeAbsPath(filename);
2812 // Check if the document already is open
2813 string LyXfilename = ChangeExtension(filename, ".lyx", false);
2814 if (bufferlist.exists(LyXfilename)){
2815 switch(AskConfirmation(_("Document is already open:"),
2816 MakeDisplayPath(LyXfilename, 50),
2817 _("Do you want to close that document now?\n"
2818 "('No' will just switch to the open version)")))
2820 case 1: // Yes: close the document
2821 if (!bufferlist.close(bufferlist.getBuffer(LyXfilename)))
2822 // If close is canceled, we cancel here too.
2825 case 2: // No: switch to the open document
2826 owner->view()->buffer(
2827 bufferlist.getBuffer(LyXfilename));
2829 case 3: // Cancel: Do nothing
2830 owner->getMiniBuffer()->Set(_("Canceled."));
2835 // Check if a LyX document by the same root exists in filesystem
2836 FileInfo f(LyXfilename, true);
2837 if (f.exist() && !AskQuestion(_("A document by the name"),
2838 MakeDisplayPath(LyXfilename),
2839 _("already exists. Overwrite?"))) {
2840 owner->getMiniBuffer()->Set(_("Canceled."));
2847 owner->getMiniBuffer()->Set(_("Importing LaTeX file"),
2848 MakeDisplayPath(filename), "...");
2849 ImportLaTeX myImport(filename);
2850 openbuf = myImport.run();
2852 owner->getMiniBuffer()->Set(_("Importing Noweb file"),
2853 MakeDisplayPath(filename), "...");
2854 ImportNoweb myImport(filename);
2855 openbuf = myImport.run();
2858 owner->view()->buffer(openbuf);
2859 owner->getMiniBuffer()->Set(isnoweb ?
2860 _("Noweb file ") : _("LateX file "),
2861 MakeDisplayPath(filename),
2864 owner->getMiniBuffer()->Set(isnoweb ?
2865 _("Could not import Noweb file") :
2866 _("Could not import LaTeX file"),
2867 MakeDisplayPath(filename));
2872 void LyXFunc::MenuInsertLyXFile(string const & filen)
2874 string filename = filen;
2876 if (filename.empty()) {
2877 // Launch a file browser
2878 string initpath = lyxrc->document_path;
2881 if (owner->view()->available()) {
2882 string trypath = owner->buffer()->filepath;
2883 // If directory is writeable, use this as default.
2884 if (IsDirWriteable(trypath) == 1)
2890 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2891 fileDlg.SetButton(1, _("Examples"),
2892 AddPath(system_lyxdir, "examples"));
2893 filename = fileDlg.Select(_("Select Document to Insert"),
2897 // check selected filename
2898 if (filename.empty()) {
2899 owner->getMiniBuffer()->Set(_("Canceled."));
2904 // get absolute path of file and make sure the filename ends
2906 filename = MakeAbsPath(filename);
2907 if (!IsLyXFilename(filename))
2911 owner->getMiniBuffer()->Set(_("Inserting document"),
2912 MakeDisplayPath(filename), "...");
2913 bool res = owner->view()->insertLyXFile(filename);
2915 owner->getMiniBuffer()->Set(_("Document"),
2916 MakeDisplayPath(filename),
2919 owner->getMiniBuffer()->Set(_("Could not insert document"),
2920 MakeDisplayPath(filename));
2925 void LyXFunc::reloadBuffer()
2927 string fn = owner->buffer()->fileName();
2928 if (bufferlist.close(owner->buffer()))
2929 owner->view()->buffer(bufferlist.loadLyXFile(fn));
2933 void LyXFunc::CloseBuffer()
2935 if (bufferlist.close(owner->buffer()) && !quitting) {
2936 if (bufferlist.empty()) {
2937 // need this otherwise SEGV may occur while trying to
2938 // set variables that don't exist
2939 // since there's no current buffer
2940 CloseAllBufferRelatedPopups();
2943 owner->view()->buffer(bufferlist.first());
2949 Inset * LyXFunc::getInsetByCode(Inset::Code code)
2953 LyXCursor cursor = owner->view()->text->cursor;
2954 LyXParagraph::size_type pos = cursor.pos;
2955 LyXParagraph * par = cursor.par;
2957 while (par && !found) {
2958 while ((inset = par->ReturnNextInsetPointer(pos))){
2959 if (inset->LyxCode() == code) {
2967 return found ? inset : 0;
2971 // Each "owner" should have it's own message method. lyxview and
2972 // the minibuffer would use the minibuffer, but lyxserver would
2973 // send an ERROR signal to its client. Alejandro 970603
2974 // This func is bit problematic when it comes to NLS, to make the
2975 // lyx servers client be language indepenent we must not translate
2976 // strings sent to this func.
2977 void LyXFunc::setErrorMessage(string const & m) const
2979 dispatch_buffer = m;
2984 void LyXFunc::setMessage(string const & m)
2986 dispatch_buffer = m;