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:
1647 LyXLayout const & style =
1648 textclasslist.Style(owner->view()->buffer()->params.textclass,
1649 owner->view()->text->cursor.par->GetLayout());
1651 if (style.free_spacing) {
1652 owner->view()->text->InsertChar(' ');
1653 owner->view()->update(-1);
1655 owner->view()->protectedBlank();
1657 moveCursorUpdate(false);
1660 owner->view()->beforeChange();
1661 owner->view()->text->
1662 InsertChar(LyXParagraph::META_PROTECTED_SEPARATOR);
1663 owner->view()->smallUpdate(1);
1665 moveCursorUpdate(false);
1670 if(owner->view()->text->mark_set) {
1671 owner->view()->beforeChange();
1672 owner->view()->update(0);
1673 setMessage(N_("Mark removed"));
1675 owner->view()->beforeChange();
1676 owner->view()->text->mark_set = 1;
1677 owner->view()->update(0);
1678 setMessage(N_("Mark set"));
1680 owner->view()->text->sel_cursor =
1681 owner->view()->text->cursor;
1686 if (!owner->view()->text->selection) {
1687 owner->view()->text->Delete();
1688 owner->view()->text->sel_cursor =
1689 owner->view()->text->cursor;
1690 owner->view()->smallUpdate(1);
1691 // It is possible to make it a lot faster still
1692 // just comment out the lone below...
1693 owner->view()->showCursor();
1695 owner->view()->cut();
1698 moveCursorUpdate(false);
1699 owner->getMiniBuffer()->Set(CurrentState());
1700 owner->view()->setState();
1703 case LFUN_DELETE_SKIP:
1705 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1707 LyXCursor cursor = owner->view()->text->cursor;
1710 if (!owner->view()->text->selection) {
1711 if (cursor.pos == cursor.par->Last()) {
1712 owner->view()->text->CursorRight();
1713 cursor = owner->view()->text->cursor;
1715 && !(cursor.par->added_space_top
1716 == VSpace (VSpace::NONE))) {
1717 owner->view()->text->SetParagraph
1718 (cursor.par->line_top,
1719 cursor.par->line_bottom,
1720 cursor.par->pagebreak_top,
1721 cursor.par->pagebreak_bottom,
1722 VSpace(VSpace::NONE),
1723 cursor.par->added_space_bottom,
1725 cursor.par->labelwidthstring, 0);
1726 owner->view()->text->CursorLeft();
1727 owner->view()->update (1);
1729 owner->view()->text->CursorLeft();
1730 owner->view()->text->Delete();
1731 owner->view()->text->sel_cursor =
1732 owner->view()->text->cursor;
1733 owner->view()->smallUpdate(1);
1736 owner->view()->text->Delete();
1737 owner->view()->text->sel_cursor =
1738 owner->view()->text->cursor;
1739 owner->view()->smallUpdate(1);
1742 owner->view()->cut();
1748 /* -------> Delete word forward. */
1749 case LFUN_DELETE_WORD_FORWARD:
1750 owner->view()->update(-2);
1752 owner->view()->text->DeleteWordForward();
1753 owner->view()->update( 1 );
1755 moveCursorUpdate(false);
1756 owner->getMiniBuffer()->Set(CurrentState());
1759 /* -------> Delete word backward. */
1760 case LFUN_DELETE_WORD_BACKWARD:
1761 owner->view()->update(-2);
1763 owner->view()->text->DeleteWordBackward();
1764 owner->view()->update( 1 );
1766 moveCursorUpdate(false);
1767 owner->getMiniBuffer()->Set(CurrentState());
1770 /* -------> Kill to end of line. */
1771 case LFUN_DELETE_LINE_FORWARD:
1773 owner->view()->update(-2);
1774 owner->view()->text->DeleteLineForward();
1775 owner->view()->update( 1 );
1777 moveCursorUpdate(false);
1780 /* -------> Set mark off. */
1782 owner->view()->beforeChange();
1783 owner->view()->update(0);
1784 owner->view()->text->sel_cursor =
1785 owner->view()->text->cursor;
1786 setMessage(N_("Mark off"));
1789 /* -------> Set mark on. */
1791 owner->view()->beforeChange();
1792 owner->view()->text->mark_set = 1;
1793 owner->view()->update( 0 );
1794 owner->view()->text->sel_cursor =
1795 owner->view()->text->cursor;
1796 setMessage(N_("Mark on"));
1799 case LFUN_BACKSPACE:
1802 if (!owner->view()->text->selection) {
1803 if (owner->getIntl()->getTrans()->backspace()) {
1804 owner->view()->text->Backspace();
1805 owner->view()->text->sel_cursor =
1806 owner->view()->text->cursor;
1807 owner->view()->smallUpdate(1);
1808 // It is possible to make it a lot faster still
1809 // just comment out the lone below...
1810 owner->view()->showCursor();
1813 owner->view()->cut();
1816 owner->getMiniBuffer()->Set(CurrentState());
1817 owner->view()->setState();
1821 case LFUN_BACKSPACE_SKIP:
1823 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1825 LyXCursor cursor = owner->view()->text->cursor;
1828 if (!owner->view()->text->selection) {
1830 && !(cursor.par->added_space_top
1831 == VSpace (VSpace::NONE))) {
1832 owner->view()->text->SetParagraph
1833 (cursor.par->line_top,
1834 cursor.par->line_bottom,
1835 cursor.par->pagebreak_top,
1836 cursor.par->pagebreak_bottom,
1837 VSpace(VSpace::NONE), cursor.par->added_space_bottom,
1839 cursor.par->labelwidthstring, 0);
1840 owner->view()->update (1);
1842 owner->view()->text->Backspace();
1843 owner->view()->text->sel_cursor
1845 owner->view()->smallUpdate (1);
1848 owner->view()->cut();
1853 case LFUN_BREAKPARAGRAPH:
1855 owner->view()->beforeChange();
1856 owner->view()->text->BreakParagraph(0);
1857 owner->view()->smallUpdate(1);
1858 SetUpdateTimer(0.01);
1859 owner->view()->text->sel_cursor =
1860 owner->view()->text->cursor;
1861 owner->view()->setState();
1862 owner->getMiniBuffer()->Set(CurrentState());
1866 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1868 owner->view()->beforeChange();
1869 owner->view()->text->BreakParagraph(1);
1870 owner->view()->smallUpdate(1);
1871 SetUpdateTimer(0.01);
1872 owner->view()->text->sel_cursor =
1873 owner->view()->text->cursor;
1874 owner->view()->setState();
1875 owner->getMiniBuffer()->Set(CurrentState());
1879 case LFUN_BREAKPARAGRAPH_SKIP:
1881 // When at the beginning of a paragraph, remove
1882 // indentation and add a "defskip" at the top.
1883 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
1885 LyXCursor cursor = owner->view()->text->cursor;
1887 owner->view()->beforeChange();
1888 if (cursor.pos == 0) {
1889 if (cursor.par->added_space_top == VSpace(VSpace::NONE)) {
1890 owner->view()->text->SetParagraph
1891 (cursor.par->line_top,
1892 cursor.par->line_bottom,
1893 cursor.par->pagebreak_top,
1894 cursor.par->pagebreak_bottom,
1895 VSpace(VSpace::DEFSKIP), cursor.par->added_space_bottom,
1897 cursor.par->labelwidthstring, 1);
1898 owner->view()->update(1);
1902 owner->view()->text->BreakParagraph(0);
1903 owner->view()->smallUpdate(1);
1905 SetUpdateTimer(0.01);
1906 owner->view()->text->sel_cursor = cursor;
1907 owner->view()->setState();
1908 owner->getMiniBuffer()->Set(CurrentState());
1913 owner->view()->beforeChange();
1914 owner->view()->text->InsertChar('\"'); // This " matches the single quote in the code
1915 owner->view()->smallUpdate(1);
1917 moveCursorUpdate(false);
1923 InsetCommand * new_inset;
1924 if (action == LFUN_HTMLURL)
1925 new_inset = new InsetUrl("htmlurl", "", "");
1927 new_inset = new InsetUrl("url", "", "");
1928 owner->view()->insertInset(new_inset);
1929 new_inset->Edit(owner->view(), 0, 0, 0);
1932 case LFUN_INSET_TEXT:
1934 InsetText * new_inset = new InsetText(owner->buffer());
1935 owner->view()->insertInset(new_inset);
1936 new_inset->Edit(owner->view(), 0, 0, 0);
1939 case LFUN_INSET_ERT:
1941 InsetERT * new_inset = new InsetERT(owner->buffer());
1942 owner->view()->insertInset(new_inset);
1943 new_inset->Edit(owner->view(), 0, 0, 0);
1946 case LFUN_INSET_FOOTNOTE:
1948 InsetFoot * new_inset = new InsetFoot(owner->buffer());
1949 owner->view()->insertInset(new_inset);
1950 new_inset->Edit(owner->view(), 0, 0, 0);
1954 // --- lyxserver commands ----------------------------
1956 case LFUN_CHARATCURSOR:
1958 LyXParagraph::size_type pos =
1959 owner->view()->text->cursor.pos;
1960 if(pos < owner->view()->text->cursor.par->size())
1961 dispatch_buffer = owner->view()->text->
1962 cursor.par->text[pos];
1964 dispatch_buffer = "EOF";
1970 tostr(owner->view()->text->cursor.x) + ' '
1971 + tostr(owner->view()->text->cursor.y);
1978 sscanf(argument.c_str(), " %d %ld", &x, &y);
1979 owner->view()->text->SetCursorFromCoordinates(x, y);
1983 case LFUN_GETLAYOUT:
1985 tostr(owner->view()->text->cursor.par->layout);
1990 LyXFont * font = &(owner->view()->text->current_font);
1991 if(font->shape() == LyXFont::ITALIC_SHAPE)
1992 dispatch_buffer = 'E';
1993 else if(font->shape() == LyXFont::SMALLCAPS_SHAPE)
1994 dispatch_buffer = 'N';
1996 dispatch_buffer = '0';
2003 LyXFont * font = &(owner->view()->text->current_font);
2004 if(font->latex() == LyXFont::ON)
2005 dispatch_buffer = 'L';
2007 dispatch_buffer = '0';
2012 setMessage(owner->buffer()->fileName());
2013 lyxerr.debug() << "FNAME["
2014 << owner->buffer()->fileName()
2022 dispatch_buffer = buf;
2023 lyxserver->notifyClient(dispatch_buffer);
2027 case LFUN_GOTOFILEROW:
2029 char file_name[100];
2031 sscanf(argument.c_str(), " %s %d", file_name, &row);
2033 // Must replace extension of the file to be .lyx and get full path
2034 string s = ChangeExtension(string(file_name), ".lyx", false);
2036 // Either change buffer or load the file
2037 if (bufferlist.exists(s))
2038 owner->view()->buffer(bufferlist.getBuffer(s));
2040 owner->view()->buffer(bufferlist.loadLyXFile(s));
2043 owner->view()->setCursorFromRow(row);
2046 owner->view()->center();
2053 int qa = lyxaction.LookupFunc(argument.c_str());
2054 setMessage(lyxaction.helpText(static_cast<kb_action>(qa)));
2058 // --- accented characters ---------------------------
2061 case LFUN_CIRCUMFLEX:
2071 case LFUN_SPECIAL_CARON:
2074 case LFUN_HUNG_UMLAUT:
2080 if (keyseq.length == -1 && keyseq.getiso() != 0)
2081 c = keyseq.getiso();
2085 owner->getIntl()->getTrans()->
2086 deadkey(c, get_accent(action).accent,
2087 owner->view()->text);
2089 // Need to reset, in case the minibuffer calls these
2094 // copied verbatim from do_accent_char
2095 owner->view()->smallUpdate(1);
2097 owner->view()->text->sel_cursor =
2098 owner->view()->text->cursor;
2102 // --- toolbar ----------------------------------
2103 case LFUN_PUSH_TOOLBAR:
2105 int nth = strToInt(argument);
2106 if (lyxerr.debugging(Debug::TOOLBAR)) {
2107 lyxerr << "LFUN_PUSH_TOOLBAR: argument = `"
2108 << argument << "'\n"
2109 << "LFUN_PUSH_TOOLBAR: nth = `"
2110 << nth << "'" << endl;
2115 setErrorMessage(N_("Push-toolbar needs argument > 0"));
2117 owner->getToolbar()->push(nth);
2122 case LFUN_ADD_TO_TOOLBAR:
2124 if (lyxerr.debugging(Debug::TOOLBAR)) {
2125 lyxerr << "LFUN_ADD_TO_TOOLBAR:"
2126 "argument = `" << argument << '\'' << endl;
2128 string tmp(argument);
2129 //lyxerr <<string("Argument: ") + argument);
2130 //lyxerr <<string("Tmp : ") + tmp);
2133 setErrorMessage(N_("Usage: toolbar-add-to <LyX command>"));
2135 owner->getToolbar()->add(argument, false);
2136 owner->getToolbar()->set();
2141 // --- insert characters ----------------------------------------
2143 // --- Mathed stuff. If we are here, there is no locked inset yet.
2148 if (!greek_kb_flag) {
2150 setMessage(N_("Math greek mode on"));
2157 case LFUN_GREEK_TOGGLE:
2159 greek_kb_flag = greek_kb_flag ? 0 : 2;
2160 if (greek_kb_flag) {
2161 setMessage(N_("Math greek keyboard on"));
2163 setMessage(N_("Math greek keyboard off"));
2168 case LFUN_MATH_DELIM:
2169 case LFUN_INSERT_MATRIX:
2171 if (owner->view()->available()) {
2173 open_new_inset(new InsetFormula(false));
2176 ->LocalDispatch(owner->view(),
2183 case LFUN_INSERT_MATH:
2185 math_insert_symbol(argument.c_str());
2189 case LFUN_MATH_DISPLAY:
2191 if (owner->view()->available())
2192 owner->view()->open_new_inset(new InsetFormula(true));
2196 case LFUN_MATH_MACRO:
2198 if (owner->view()->available()) {
2201 setErrorMessage(N_("Missing argument"));
2203 string s1 = token(s, ' ', 1);
2204 int na = s1.empty() ? 0: atoi(s1.c_str());
2206 open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2212 case LFUN_MATH_MODE: // Open or create a math inset
2215 if (owner->view()->available())
2216 owner->view()->open_new_inset(new InsetFormula);
2217 setMessage(N_("Math editor mode"));
2221 case LFUN_MATH_NUMBER:
2222 case LFUN_MATH_LIMITS:
2224 setErrorMessage(N_("This is only allowed in math mode!"));
2228 case LFUN_INSERT_CITATION:
2230 InsetCitation * new_inset = new InsetCitation();
2232 // The note, if any, must be after the key, delimited
2233 // by a | so both key and remark can have spaces.
2234 if (!argument.empty()) {
2235 string lsarg(argument);
2236 if (contains(lsarg, "|")) {
2237 new_inset->setContents(token(lsarg, '|', 0));
2238 new_inset->setOptions(token(lsarg, '|', 1));
2240 new_inset->setContents(lsarg);
2241 owner->view()->insertInset(new_inset);
2243 owner->view()->insertInset(new_inset);
2244 new_inset->Edit(owner->view(), 0, 0, 0);
2249 case LFUN_INSERT_BIBTEX:
2251 // ale970405+lasgoutt970425
2252 // The argument can be up to two tokens separated
2253 // by a space. The first one is the bibstyle.
2254 string lsarg(argument);
2255 string bibstyle = token(lsarg, ' ', 1);
2256 if (bibstyle.empty())
2258 InsetBibtex * new_inset
2259 = new InsetBibtex(token(lsarg, ' ', 0),
2263 owner->view()->insertInset(new_inset);
2264 if (lsarg.empty()) {
2265 new_inset->Edit(owner->view(), 0, 0, 0);
2270 // BibTeX data bases
2271 case LFUN_BIBDB_ADD:
2273 InsetBibtex * inset =
2274 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2276 inset->addDatabase(argument);
2281 case LFUN_BIBDB_DEL:
2283 InsetBibtex * inset =
2284 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2286 inset->delDatabase(argument);
2291 case LFUN_BIBTEX_STYLE:
2293 InsetBibtex * inset =
2294 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2296 inset->setOptions(argument);
2301 case LFUN_INDEX_INSERT:
2302 case LFUN_INDEX_INSERT_LAST:
2304 // Can't do that at the beginning of a paragraph.
2305 if (owner->view()->text->cursor.pos - 1 < 0)
2308 InsetIndex * new_inset = new InsetIndex();
2309 if (!argument.empty()) {
2310 string lsarg(argument);
2311 new_inset->setContents(lsarg);
2312 owner->view()->insertInset(new_inset);
2315 //get the current word for an argument
2316 LyXParagraph::size_type lastpos =
2317 owner->view()->text->cursor.pos - 1;
2318 // Get the current word. note that this must be done
2319 // before inserting the inset, or the inset will
2321 string curstring(owner->view()
2322 ->text->cursor.par->GetWord(lastpos));
2324 //make the new inset and write the current word into it
2325 InsetIndex * new_inset = new InsetIndex();
2327 new_inset->setContents(curstring);
2329 //don't edit it if the call was to INSERT_LAST
2330 if(action != LFUN_INDEX_INSERT_LAST) {
2331 new_inset->Edit(owner->view(), 0, 0, 0);
2333 //it looks blank on the screen unless
2334 //we do something. put it here.
2336 // move the cursor to the returned value of lastpos
2337 // but only for the auto-insert
2338 owner->view()->text->cursor.pos = lastpos;
2341 //put the new inset into the buffer.
2342 // there should be some way of knowing the user
2343 //cancelled & avoiding this, but i don't know how
2344 owner->view()->insertInset(new_inset);
2349 case LFUN_INDEX_PRINT:
2351 Inset * new_inset = new InsetPrintIndex(owner->buffer());
2352 owner->view()->insertInset(new_inset, "Standard", true);
2356 case LFUN_PARENTINSERT:
2358 lyxerr << "arg " << argument << endl;
2359 Inset * new_inset = new InsetParent(argument, owner->buffer());
2360 owner->view()->insertInset(new_inset, "Standard", true);
2364 case LFUN_CHILDINSERT:
2366 Inset * new_inset = new InsetInclude(argument,
2368 owner->view()->insertInset(new_inset, "Standard", true);
2369 new_inset->Edit(owner->view(), 0, 0, 0);
2373 case LFUN_CHILDOPEN:
2376 MakeAbsPath(argument,
2377 OnlyPath(owner->buffer()->fileName()));
2378 setMessage(N_("Opening child document ") +
2379 MakeDisplayPath(filename) + "...");
2380 owner->view()->savePosition();
2381 if (bufferlist.exists(filename))
2382 owner->view()->buffer(bufferlist.getBuffer(filename));
2384 owner->view()->buffer(bufferlist.loadLyXFile(filename));
2388 case LFUN_INSERT_NOTE:
2389 owner->view()->insertNote();
2392 case LFUN_INSERTFOOTNOTE:
2394 LyXParagraph::footnote_kind kind;
2395 if (argument == "footnote")
2396 { kind = LyXParagraph::FOOTNOTE; }
2397 else if (argument == "margin")
2398 { kind = LyXParagraph::MARGIN; }
2399 else if (argument == "figure")
2400 { kind = LyXParagraph::FIG; }
2401 else if (argument == "table")
2402 { kind = LyXParagraph::TAB; }
2403 else if (argument == "wide-fig")
2404 { kind = LyXParagraph::WIDE_FIG; }
2405 else if (argument == "wide-tab")
2406 { kind = LyXParagraph::WIDE_TAB; }
2407 else if (argument == "algorithm")
2408 { kind = LyXParagraph::ALGORITHM; }
2410 setErrorMessage(N_("Unknown kind of footnote"));
2413 owner->view()->text->InsertFootnoteEnvironment(kind);
2414 owner->view()->update(1);
2415 owner->view()->setState();
2419 case LFUN_BUFFERBULLETSSELECT:
2423 case LFUN_TOGGLECURSORFOLLOW:
2424 cursor_follows_scrollbar = !cursor_follows_scrollbar;
2427 case LFUN_KMAP_OFF: // keymap off
2428 owner->getIntl()->KeyMapOn(false);
2431 case LFUN_KMAP_PRIM: // primary keymap
2432 owner->getIntl()->KeyMapPrim();
2435 case LFUN_KMAP_SEC: // secondary keymap
2436 owner->getIntl()->KeyMapSec();
2439 case LFUN_KMAP_TOGGLE: // toggle keymap
2440 owner->getIntl()->ToggleKeyMap();
2443 case LFUN_SELFINSERT:
2445 for (string::size_type i = 0; i < argument.length(); ++i) {
2446 owner->view()->text->InsertChar(argument[i]);
2447 // This needs to be in the loop, or else we
2448 // won't break lines correctly. (Asger)
2449 owner->view()->smallUpdate(1);
2452 owner->view()->text->sel_cursor =
2453 owner->view()->text->cursor;
2454 moveCursorUpdate(false);
2460 // argument contains ';'-terminated commands
2461 while (argument.find(';') != string::npos) {
2463 argument = split(argument, first, ';');
2469 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
2477 now_time_t = time(NULL);
2478 now_tm = localtime(&now_time_t);
2479 (void)setlocale(LC_TIME, "");
2480 if (!argument.empty())
2482 else if (arg.empty())
2483 arg = lyxrc->date_insert_format;
2484 datetmp_len = (int) strftime(datetmp, 32, arg.c_str(), now_tm);
2485 for (int i = 0; i < datetmp_len; i++) {
2486 owner->view()->text->InsertChar(datetmp[i]);
2487 owner->view()->smallUpdate(1);
2490 owner->view()->text->sel_cursor = owner->view()->text->cursor;
2491 moveCursorUpdate(false);
2495 case LFUN_SAVEPREFERENCES:
2497 Path p(user_lyxdir);
2498 lyxrc->write("preferences");
2502 case LFUN_UNKNOWN_ACTION:
2504 if(!owner->buffer()) {
2506 setErrorMessage(N_("No document open"));
2510 if (owner->buffer()->isReadonly()) {
2512 setErrorMessage(N_("Document is read only"));
2516 if (!argument.empty()) {
2518 /* Automatically delete the currently selected
2519 * text and replace it with what is being
2520 * typed in now. Depends on lyxrc settings
2521 * "auto_region_delete", which defaults to
2524 if ( lyxrc->auto_region_delete ) {
2525 if (owner->view()->text->selection){
2526 owner->view()->text->CutSelection(false);
2527 owner->view()->update(-1);
2531 owner->view()->beforeChange();
2532 for (string::size_type i = 0;
2533 i < argument.length(); ++i) {
2534 if (greek_kb_flag) {
2535 if (!math_insert_greek(argument[i]))
2536 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2538 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2541 owner->view()->smallUpdate(1);
2544 owner->view()->text->sel_cursor =
2545 owner->view()->text->cursor;
2546 moveCursorUpdate(false);
2549 // why is an "Unknown action" with empty
2550 // argument even dispatched in the first
2551 // place? I`ll probably change that. (Lgb)
2553 setErrorMessage(N_("Unknown action"));
2557 lyxerr << "A truly unknown func!" << endl;
2563 string res = getMessage();
2566 if (!commandshortcut.empty()) {
2567 string newbuf = owner->getMiniBuffer()->GetText();
2568 if (newbuf != commandshortcut) {
2569 owner->getMiniBuffer()->Set(newbuf
2575 owner->getMiniBuffer()->Set(string(_(res.c_str()))
2576 + " " + commandshortcut);
2583 void LyXFunc::setupLocalKeymap()
2585 keyseq.stdmap = keyseq.curmap = toplevel_keymap;
2586 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap;
2590 void LyXFunc::MenuNew(bool fromTemplate)
2592 string fname, initpath = lyxrc->document_path;
2595 if (owner->view()->available()) {
2596 string trypath = owner->buffer()->filepath;
2597 // If directory is writeable, use this as default.
2598 if (IsDirWriteable(trypath) == 1)
2603 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2604 fileDlg.SetButton(1, _("Templates"), lyxrc->template_path);
2605 fname = fileDlg.Select(_("Enter Filename for new document"),
2606 initpath, "*.lyx", _("newfile"));
2609 if (fname.empty()) {
2610 owner->getMiniBuffer()->Set(_("Canceled."));
2611 lyxerr.debug() << "New Document Cancelled." << endl;
2615 // get absolute path of file and make sure the filename ends
2617 string s = MakeAbsPath(fname);
2618 if (!IsLyXFilename(s))
2621 // Check if the document already is open
2622 if (bufferlist.exists(s)){
2623 switch(AskConfirmation(_("Document is already open:"),
2624 MakeDisplayPath(s, 50),
2625 _("Do you want to close that document now?\n"
2626 "('No' will just switch to the open version)")))
2628 case 1: // Yes: close the document
2629 if (!bufferlist.close(bufferlist.getBuffer(s)))
2630 // If close is canceled, we cancel here too.
2633 case 2: // No: switch to the open document
2634 owner->view()->buffer(bufferlist.getBuffer(s));
2636 case 3: // Cancel: Do nothing
2637 owner->getMiniBuffer()->Set(_("Canceled."));
2642 // Check whether the file already exists
2643 if (IsLyXFilename(s)) {
2645 if (fi.readable() &&
2646 AskQuestion(_("File already exists:"),
2647 MakeDisplayPath(s, 50),
2648 _("Do you want to open the document?"))) {
2650 owner->getMiniBuffer()->Set(_("Opening document"),
2651 MakeDisplayPath(s), "...");
2653 owner->view()->buffer(
2654 bufferlist.loadLyXFile(s));
2655 owner->getMiniBuffer()->Set(_("Document"),
2662 // The template stuff
2666 fname = fileDlg.Select(_("Choose template"),
2667 lyxrc->template_path,
2673 // find a free buffer
2674 lyxerr.debug() << "Find a free buffer." << endl;
2675 owner->view()->buffer(bufferlist.newFile(s, templname));
2679 void LyXFunc::MenuOpen()
2681 string initpath = lyxrc->document_path;
2684 if (owner->view()->available()) {
2685 string trypath = owner->buffer()->filepath;
2686 // If directory is writeable, use this as default.
2687 if (IsDirWriteable(trypath) == 1)
2693 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2694 fileDlg.SetButton(1, _("Examples"),
2695 AddPath(system_lyxdir, "examples"));
2696 string filename = fileDlg.Select(_("Select Document to Open"),
2700 // check selected filename
2701 if (filename.empty()) {
2702 owner->getMiniBuffer()->Set(_("Canceled."));
2706 // get absolute path of file and make sure the filename ends
2708 filename = MakeAbsPath(filename);
2709 if (!IsLyXFilename(filename))
2713 owner->getMiniBuffer()->Set(_("Opening document"),
2714 MakeDisplayPath(filename), "...");
2715 Buffer * openbuf = bufferlist.loadLyXFile(filename);
2717 owner->view()->buffer(openbuf);
2718 owner->getMiniBuffer()->Set(_("Document"),
2719 MakeDisplayPath(filename),
2722 owner->getMiniBuffer()->Set(_("Could not open document"),
2723 MakeDisplayPath(filename));
2728 void LyXFunc::doImportASCII(bool linorpar)
2730 string initpath = lyxrc->document_path;
2733 if (owner->view()->available()) {
2734 string trypath = owner->buffer()->filepath;
2735 // If directory is writeable, use this as default.
2736 if (IsDirWriteable(trypath) == 1)
2742 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2743 fileDlg.SetButton(1, _("Examples"),
2744 AddPath(system_lyxdir, "examples"));
2745 string filename = fileDlg.Select(_("Select ASCII file to Import"),
2749 // check selected filename
2750 if (filename.empty()) {
2751 owner->getMiniBuffer()->Set(_("Canceled."));
2755 // get absolute path of file
2756 filename = MakeAbsPath(filename);
2758 string s = ChangeExtension(filename, ".lyx", false);
2760 // Check if the document already is open
2761 if (bufferlist.exists(s)) {
2762 switch(AskConfirmation(_("Document is already open:"),
2763 MakeDisplayPath(s, 50),
2764 _("Do you want to close that document now?\n"
2765 "('No' will just switch to the open version)")))
2767 case 1: // Yes: close the document
2768 if (!bufferlist.close(bufferlist.getBuffer(s)))
2769 // If close is canceled, we cancel here too.
2772 case 2: // No: switch to the open document
2773 owner->view()->buffer(bufferlist.getBuffer(s));
2775 case 3: // Cancel: Do nothing
2776 owner->getMiniBuffer()->Set(_("Canceled."));
2781 // Check if a LyX document by the same root exists in filesystem
2782 FileInfo f(s, true);
2783 if (f.exist() && !AskQuestion(_("A document by the name"),
2785 _("already exists. Overwrite?"))) {
2786 owner->getMiniBuffer()->Set(_("Canceled."));
2790 owner->view()->buffer(bufferlist.newFile(s, string()));
2791 owner->getMiniBuffer()->Set(_("Importing ASCII file"),
2792 MakeDisplayPath(filename), "...");
2793 // Insert ASCII file
2794 InsertAsciiFile(filename, linorpar);
2795 owner->getMiniBuffer()->Set(_("ASCII file "),
2796 MakeDisplayPath(filename),
2801 void LyXFunc::doImportLaTeX(bool isnoweb)
2803 string initpath = lyxrc->document_path;
2806 if (owner->view()->available()) {
2807 string trypath = owner->buffer()->filepath;
2808 // If directory is writeable, use this as default.
2809 if (IsDirWriteable(trypath) == 1)
2815 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2816 fileDlg.SetButton(1, _("Examples"),
2817 AddPath(system_lyxdir, "examples"));
2820 filename = fileDlg.Select(_("Select Noweb file to Import"),
2823 filename = fileDlg.Select(_("Select LaTeX file to Import"),
2829 // check selected filename
2830 if (filename.empty()) {
2831 owner->getMiniBuffer()->Set(_("Canceled."));
2835 // get absolute path of file
2836 filename = MakeAbsPath(filename);
2838 // Check if the document already is open
2839 string LyXfilename = ChangeExtension(filename, ".lyx", false);
2840 if (bufferlist.exists(LyXfilename)){
2841 switch(AskConfirmation(_("Document is already open:"),
2842 MakeDisplayPath(LyXfilename, 50),
2843 _("Do you want to close that document now?\n"
2844 "('No' will just switch to the open version)")))
2846 case 1: // Yes: close the document
2847 if (!bufferlist.close(bufferlist.getBuffer(LyXfilename)))
2848 // If close is canceled, we cancel here too.
2851 case 2: // No: switch to the open document
2852 owner->view()->buffer(
2853 bufferlist.getBuffer(LyXfilename));
2855 case 3: // Cancel: Do nothing
2856 owner->getMiniBuffer()->Set(_("Canceled."));
2861 // Check if a LyX document by the same root exists in filesystem
2862 FileInfo f(LyXfilename, true);
2863 if (f.exist() && !AskQuestion(_("A document by the name"),
2864 MakeDisplayPath(LyXfilename),
2865 _("already exists. Overwrite?"))) {
2866 owner->getMiniBuffer()->Set(_("Canceled."));
2873 owner->getMiniBuffer()->Set(_("Importing LaTeX file"),
2874 MakeDisplayPath(filename), "...");
2875 ImportLaTeX myImport(filename);
2876 openbuf = myImport.run();
2878 owner->getMiniBuffer()->Set(_("Importing Noweb file"),
2879 MakeDisplayPath(filename), "...");
2880 ImportNoweb myImport(filename);
2881 openbuf = myImport.run();
2884 owner->view()->buffer(openbuf);
2885 owner->getMiniBuffer()->Set(isnoweb ?
2886 _("Noweb file ") : _("LateX file "),
2887 MakeDisplayPath(filename),
2890 owner->getMiniBuffer()->Set(isnoweb ?
2891 _("Could not import Noweb file") :
2892 _("Could not import LaTeX file"),
2893 MakeDisplayPath(filename));
2898 void LyXFunc::MenuInsertLyXFile(string const & filen)
2900 string filename = filen;
2902 if (filename.empty()) {
2903 // Launch a file browser
2904 string initpath = lyxrc->document_path;
2907 if (owner->view()->available()) {
2908 string trypath = owner->buffer()->filepath;
2909 // If directory is writeable, use this as default.
2910 if (IsDirWriteable(trypath) == 1)
2916 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2917 fileDlg.SetButton(1, _("Examples"),
2918 AddPath(system_lyxdir, "examples"));
2919 filename = fileDlg.Select(_("Select Document to Insert"),
2923 // check selected filename
2924 if (filename.empty()) {
2925 owner->getMiniBuffer()->Set(_("Canceled."));
2930 // get absolute path of file and make sure the filename ends
2932 filename = MakeAbsPath(filename);
2933 if (!IsLyXFilename(filename))
2937 owner->getMiniBuffer()->Set(_("Inserting document"),
2938 MakeDisplayPath(filename), "...");
2939 bool res = owner->view()->insertLyXFile(filename);
2941 owner->getMiniBuffer()->Set(_("Document"),
2942 MakeDisplayPath(filename),
2945 owner->getMiniBuffer()->Set(_("Could not insert document"),
2946 MakeDisplayPath(filename));
2951 void LyXFunc::reloadBuffer()
2953 string fn = owner->buffer()->fileName();
2954 if (bufferlist.close(owner->buffer()))
2955 owner->view()->buffer(bufferlist.loadLyXFile(fn));
2959 void LyXFunc::CloseBuffer()
2961 if (bufferlist.close(owner->buffer()) && !quitting) {
2962 if (bufferlist.empty()) {
2963 // need this otherwise SEGV may occur while trying to
2964 // set variables that don't exist
2965 // since there's no current buffer
2966 CloseAllBufferRelatedPopups();
2969 owner->view()->buffer(bufferlist.first());
2975 Inset * LyXFunc::getInsetByCode(Inset::Code code)
2979 LyXCursor cursor = owner->view()->text->cursor;
2980 LyXParagraph::size_type pos = cursor.pos;
2981 LyXParagraph * par = cursor.par;
2983 while (par && !found) {
2984 while ((inset = par->ReturnNextInsetPointer(pos))){
2985 if (inset->LyxCode() == code) {
2993 return found ? inset : 0;
2997 // Each "owner" should have it's own message method. lyxview and
2998 // the minibuffer would use the minibuffer, but lyxserver would
2999 // send an ERROR signal to its client. Alejandro 970603
3000 // This func is bit problematic when it comes to NLS, to make the
3001 // lyx servers client be language indepenent we must not translate
3002 // strings sent to this func.
3003 void LyXFunc::setErrorMessage(string const & m) const
3005 dispatch_buffer = m;
3010 void LyXFunc::setMessage(string const & m)
3012 dispatch_buffer = m;