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 * ====================================================== */
15 using std::istringstream;
28 #pragma implementation
31 #include "lyxlookup.h"
34 #include "bufferlist.h"
35 #include "lyxserver.h"
40 #include "LyXAction.h"
41 #include "insets/inseturl.h"
42 #include "insets/insetlatexaccent.h"
43 #include "insets/insettoc.h"
44 #include "insets/insetlof.h"
45 #include "insets/insetloa.h"
46 #include "insets/insetlot.h"
47 #include "insets/insetref.h"
48 #include "insets/insetparent.h"
49 #include "insets/insetindex.h"
50 #include "insets/insetinclude.h"
51 #include "insets/insetbib.h"
52 #include "insets/insettext.h"
53 #include "insets/insetert.h"
54 #include "insets/insetgraphics.h"
55 #include "insets/insetfoot.h"
56 #include "insets/insettabular.h"
57 #include "mathed/formulamacro.h"
59 #include "spellchecker.h" // RVDK_PATCH_5
60 #include "minibuffer.h"
64 #include "lyx_gui_misc.h"
65 #include "support/filetools.h"
66 #include "support/FileInfo.h"
67 #include "support/syscall.h"
68 #include "support/lstrings.h"
69 #include "support/path.h"
74 #include "trans_mgr.h"
75 #include "ImportLaTeX.h"
76 #include "ImportNoweb.h"
81 #include "bufferview_funcs.h"
86 extern bool cursor_follows_scrollbar;
88 extern void InsertAsciiFile(BufferView *, string const &, bool);
89 extern void math_insert_symbol(char const *);
90 extern Bool math_insert_greek(char const); // why "Bool"?
91 extern BufferList bufferlist;
92 extern LyXServer * lyxserver;
93 extern short greek_kb_flag;
94 extern FD_form_toc * fd_form_toc;
95 extern bool selection_possible;
97 extern kb_keymap * toplevel_keymap;
99 extern void MenuWrite(Buffer *);
100 extern void MenuWriteAs(Buffer *);
101 extern int MenuRunLaTeX(Buffer *);
102 extern int MenuBuildProg(Buffer *);
103 extern int MenuRunChktex(Buffer *);
104 extern bool CreatePostscript(Buffer *, bool);
105 extern void MenuPrint(Buffer *);
106 extern void MenuSendto();
107 extern void QuitLyX();
108 extern void MenuFax(Buffer *);
109 extern void MenuExport(Buffer *, string const &);
110 extern void MenuPasteSelection(char at);
111 extern LyXAction lyxaction;
113 extern tex_accent_struct get_accent(kb_action action);
115 extern void AutoSave(BufferView *);
116 extern void SetUpdateTimer(float timer = 0.3);
117 extern void FreeUpdateTimer();
118 extern bool PreviewDVI(Buffer *);
119 extern bool PreviewPostscript(Buffer *);
120 extern void MenuInsertLabel(char const *);
121 extern void MenuInsertRef();
122 extern void MenuLayoutCharacter();
123 extern void MenuLayoutParagraph();
124 extern void MenuLayoutDocument();
125 extern void MenuLayoutPaper();
126 extern void MenuLayoutTable(int flag);
127 extern void MenuLayoutQuotes();
128 extern void MenuLayoutPreamble();
129 extern void MenuLayoutSave();
130 extern void bulletForm();
132 extern Buffer * NewLyxFile(string const &);
133 extern void LoadLyXFile(string const &);
134 extern void Reconfigure(BufferView *);
136 extern LyXTextClass::size_type current_layout;
137 extern int getISOCodeFromLaTeX(char *);
139 extern void ShowLatexLog();
141 /* === globals =========================================================== */
143 bool LyXFunc::show_sc = true;
146 LyXFunc::LyXFunc(LyXView * o)
150 lyx_dead_action = LFUN_NOACTION;
151 lyx_calling_dead_action = LFUN_NOACTION;
156 // I changed this func slightly. I commented out the ...FinishUndo(),
157 // this means that all places that used to have a moveCursorUpdate, now
158 // have a ...FinishUndo() as the preceeding statement. I have also added
159 // a moveCursorUpdate to some of the functions that updated the cursor, but
160 // that did not show its new position.
162 void LyXFunc::moveCursorUpdate(bool selecting)
164 if (selecting || owner->view()->text->mark_set) {
165 owner->view()->text->SetSelection();
166 owner->view()->toggleToggle();
167 //owner->view()->update(0);
169 //owner->view()->update(-2); // this IS necessary
172 owner->view()->update(0);
173 owner->view()->showCursor();
175 /* ---> Everytime the cursor is moved, show the current font state. */
176 // should this too me moved out of this func?
177 //owner->getMiniBuffer()->Set(CurrentState());
178 owner->view()->setState();
182 int LyXFunc::processKeyEvent(XEvent * ev)
186 XKeyEvent * keyevent = &ev->xkey;
187 KeySym keysym_return;
189 int num_bytes = LyXLookupString(ev, s_r, 10, &keysym_return);
190 s_r[num_bytes] = '\0';
192 if (lyxerr.debugging(Debug::KEY)) {
193 char * tmp = XKeysymToString(keysym_return);
194 string stm = (tmp ? tmp : "");
195 lyxerr << "KeySym is "
198 << keysym_return << "]"
199 << " and num_bytes is "
201 << " the string returned is \""
202 << s_r << '\"' << endl;
204 // Do nothing if we have nothing (JMarc)
205 if (num_bytes == 0 && keysym_return == NoSymbol) {
206 lyxerr[Debug::KEY] << "Empty kbd action (probably composing)"
211 // this function should be used always [asierra060396]
212 UpdatableInset * tli = owner->view()->the_locking_inset;
213 if (owner->view()->available() && tli && (keysym_return==XK_Escape)) {
214 if (tli == tli->GetLockingInset()) {
215 owner->view()->unlockInset(tli);
216 owner->view()->text->CursorRight();
217 moveCursorUpdate(false);
218 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
220 tli->UnlockInsetInInset(owner->view(),
221 tli->GetLockingInset());
226 // Can we be sure that this will work for all X-Windows
227 // implementations? (Lgb)
228 // This code snippet makes lyx ignore some keys. Perhaps
229 // all of them should be explictly mentioned?
230 if((keysym_return >= XK_Shift_L && keysym_return <= XK_Hyper_R)
231 || keysym_return == XK_Mode_switch || keysym_return == 0x0)
234 // Do a one-deep top-level lookup for
235 // cancel and meta-fake keys. RVDK_PATCH_5
236 cancel_meta_seq.reset();
238 int action = cancel_meta_seq.addkey(keysym_return, keyevent->state
239 &(ShiftMask|ControlMask
242 // When not cancel or meta-fake, do the normal lookup.
243 // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
244 // Mostly, meta_fake_bit = 0. RVDK_PATCH_5.
245 if ( (action != LFUN_CANCEL) && (action != LFUN_META_FAKE) ) {
247 // remove Caps Lock and Mod2 as a modifiers
248 action = keyseq.addkey(keysym_return,
249 (keyevent->state | meta_fake_bit)
250 &(ShiftMask|ControlMask
253 // Dont remove this unless you know what you are doing.
256 if (action == 0) action = LFUN_PREFIX;
258 if (lyxerr.debugging(Debug::KEY)) {
264 << num_bytes << "]" << endl;
267 // already here we know if it any point in going further
268 // why not return already here if action == -1 and
269 // num_bytes == 0? (Lgb)
271 if(keyseq.length > 1 || keyseq.length < -1) {
274 owner->getMiniBuffer()->Set(buf);
278 if (keyseq.length < -1) { // unknown key sequence...
282 owner->getMiniBuffer()->Set(_("Unknown sequence:"), buf);
286 char isochar = keyseq.getiso();
287 if (!(keyevent->state&ControlMask) &&
288 !(keyevent->state&Mod1Mask) &&
289 (isochar && keysym_return < 0xF000)) {
292 if (argument.empty()) {
293 lyxerr.debug() << "Empty argument!" << endl;
294 // This can`t possibly be of any use
295 // so we`ll skip the dispatch.
299 if (action == LFUN_SELFINSERT) {
303 bool tmp_sc = show_sc;
305 Dispatch(action, argument.c_str());
312 LyXFunc::func_status LyXFunc::getStatus(int ac) const
315 func_status flag = LyXFunc::OK;
317 Buffer * buf = owner->buffer();
319 if (lyxaction.isPseudoAction(ac))
320 action = lyxaction.retrieveActionArg(ac, argument);
322 action = static_cast<kb_action>(ac);
324 if (action == LFUN_UNKNOWN_ACTION) {
325 setErrorMessage(N_("Unknown action"));
326 return LyXFunc::Unknown;
329 // Check whether we need a buffer
330 if (!lyxaction.funcHasFlag(action, LyXAction::NoBuffer)) {
331 // Yes we need a buffer, do we have one?
334 // Can we use a readonly buffer?
335 if (buf->isReadonly() &&
336 !lyxaction.funcHasFlag(action,
337 LyXAction::ReadOnly)) {
339 setErrorMessage(N_("Document is read-only"));
340 flag |= LyXFunc::Disabled;
344 setErrorMessage(N_("Command not allowed with"
345 "out any document open"));
346 flag |= LyXFunc::Disabled;
350 if (flag & LyXFunc::Disabled)
353 // I would really like to avoid having this switch and rather try to
354 // encode this in the function itself.
355 static bool noLaTeX = lyxrc.latex_command == "none";
356 bool disable = false;
359 disable = noLaTeX || lyxrc.view_dvi_command == "none";
362 disable = noLaTeX || lyxrc.view_ps_command == "none";
369 disable = noLaTeX || lyxrc.print_command == "none";
372 disable = noLaTeX || lyxrc.fax_command == "none";
375 if (argument == "latex")
376 disable = lyxrc.relyx_command == "none";
377 if (argument == "linuxdoc")
378 disable = lyxrc.linuxdoc_to_lyx_command == "none";
381 if (argument == "dvi" || argument == "postscript")
383 if (argument == "html")
384 disable = lyxrc.html_command == "none";
385 if (argument == "html-linuxdoc")
386 disable = lyxrc.linuxdoc_to_html_command == "none";
387 if (argument == "html-docbook")
388 disable = lyxrc.docbook_to_html_command == "none";
391 disable = buf->undostack.empty();
394 disable = buf->redostack.empty();
396 case LFUN_SPELLCHECK:
397 disable = lyxrc.isp_command == "none";
400 disable = lyxrc.chktex_command == "none";
402 case LFUN_LAYOUT_TABLE:
403 disable = ! owner->view()->text->cursor.par->table;
409 flag |= LyXFunc::Disabled;
412 func_status box = LyXFunc::ToggleOff;
413 LyXFont font = owner->view()->text->real_current_font;
416 if (font.emph() == LyXFont::ON)
417 box = LyXFunc::ToggleOn;
420 if (font.noun() == LyXFont::ON)
421 box = LyXFunc::ToggleOn;
424 if (font.series() == LyXFont::BOLD_SERIES)
425 box = LyXFunc::ToggleOn;
428 if (font.latex() == LyXFont::ON)
429 box = LyXFunc::ToggleOn;
442 string LyXFunc::Dispatch(string const & s)
444 // Split command string into command and argument
445 string cmd, line = frontStrip(s);
446 string arg = strip(frontStrip(split(line, cmd, ' ')));
448 return Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
452 string LyXFunc::Dispatch(int ac,
453 char const * do_not_use_this_arg)
458 // we have not done anything wrong yet.
460 dispatch_buffer.erase();
462 // if action is a pseudo-action, we need the real action
463 if (lyxaction.isPseudoAction(ac)) {
465 action = static_cast<kb_action>
466 (lyxaction.retrieveActionArg(ac, tmparg));
470 action = static_cast<kb_action>(ac);
471 if (do_not_use_this_arg)
472 argument = do_not_use_this_arg; // except here
475 selection_possible = false;
477 if (owner->view()->available())
478 owner->view()->hideCursor();
480 // We cannot use this function here
481 if (getStatus(action) & Disabled)
482 goto exit_with_message;
484 commandshortcut.erase();
486 if (lyxrc.display_shortcuts && show_sc) {
487 if (action != LFUN_SELFINSERT) {
488 // Put name of command and list of shortcuts
489 // for it in minibuffer
490 string comname = lyxaction.getActionName(action);
492 int pseudoaction = action;
493 bool argsadded = false;
495 if (!argument.empty()) {
496 // If we have the command with argument,
499 lyxaction.searchActionArg(action,
502 if (pseudoaction == -1) {
503 pseudoaction = action;
505 comname += " " + argument;
510 string shortcuts = toplevel_keymap->findbinding(pseudoaction);
512 if (!shortcuts.empty()) {
513 comname += ": " + shortcuts;
514 } else if (!argsadded) {
515 comname += " " + argument;
518 if (!comname.empty()) {
519 comname = strip(comname);
520 commandshortcut = "(" + comname + ')';
521 owner->getMiniBuffer()->Set(commandshortcut);
522 // Here we could even add a small pause,
523 // to annoy the user and make him learn
525 // No! That will just annoy, not teach
526 // anything. The user will read the messages
527 // if they are interested. (Asger)
532 // If in math mode pass the control to
533 // the math inset [asierra060396]
534 if (owner->view()->available() &&
535 owner->view()->the_locking_inset) {
536 UpdatableInset::RESULT result;
538 || (action == LFUN_UNKNOWN_ACTION
539 && keyseq.length >= -1)) {
540 if (action == LFUN_UNKNOWN_ACTION
541 && argument.empty()) {
542 argument = keyseq.getiso();
544 // Undo/Redo pre 0.13 is a bit tricky for insets.
545 if (action == LFUN_UNDO) {
547 UpdatableInset * inset =
548 owner->view()->the_locking_inset;
549 inset->GetCursorPos(slx, sly);
550 owner->view()->unlockInset(inset);
551 owner->view()->menuUndo();
552 if (owner->view()->text->cursor.par->
553 IsInset(owner->view()->text->cursor.pos)) {
554 inset = static_cast<UpdatableInset*>(
555 owner->view()->text->cursor.par->
556 GetInset(owner->view()->text->
562 inset->Edit(owner->view(),slx,sly,0);
564 } else if (action == LFUN_REDO) {
566 UpdatableInset * inset = owner->view()->
568 inset->GetCursorPos(slx, sly);
569 owner->view()->unlockInset(inset);
570 owner->view()->menuRedo();
571 inset = static_cast<UpdatableInset*>(
572 owner->view()->text->cursor.par->
573 GetInset(owner->view()->text->
576 inset->Edit(owner->view(),slx,sly,0);
578 } else if (((result=owner->view()->the_locking_inset->
579 LocalDispatch(owner->view(), action,
581 UpdatableInset::DISPATCHED) ||
582 (result == UpdatableInset::DISPATCHED_NOUPDATE))
585 setMessage(N_("Text mode"));
587 case LFUN_UNKNOWN_ACTION:
588 case LFUN_BREAKPARAGRAPH:
590 owner->view()->text->CursorRight();
591 owner->view()->setState();
592 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
595 if (!owner->view()->text->cursor.par->isRightToLeftPar()) {
596 owner->view()->text->CursorRight();
597 moveCursorUpdate(false);
598 owner->getMiniBuffer()->
599 Set(CurrentState(owner->view()));
603 if (owner->view()->text->cursor.par->isRightToLeftPar()) {
604 owner->view()->text->CursorRight();
605 moveCursorUpdate(false);
606 owner->getMiniBuffer()->
607 Set(CurrentState(owner->view()));
611 owner->view()->text->CursorDown();
612 moveCursorUpdate(false);
613 owner->getMiniBuffer()->
614 Set(CurrentState(owner->view()));
624 // --- Misc -------------------------------------------
625 case LFUN_WORDFINDFORWARD :
626 case LFUN_WORDFINDBACKWARD : {
627 static string last_search;
628 string searched_string;
630 if (!argument.empty()) {
631 last_search = argument;
632 searched_string = argument;
634 searched_string = last_search;
637 LyXText * ltCur = owner->view()->text ;
639 if (!searched_string.empty() &&
640 ((action == LFUN_WORDFINDBACKWARD) ?
641 ltCur->SearchBackward(searched_string.c_str()) :
642 ltCur->SearchForward(searched_string.c_str()))) {
644 // ??? What is that ???
645 owner->view()->update(-2);
648 // clear the selection (if there is any)
649 owner->view()->toggleSelection();
650 owner->view()->text->ClearSelection();
652 // Move cursor so that successive C-s 's will not stand in place.
653 if( action == LFUN_WORDFINDFORWARD )
654 owner->view()->text->CursorRightOneWord();
655 owner->view()->text->FinishUndo();
656 moveCursorUpdate(false);
659 // set the new selection
660 // SetSelectionOverLenChars(owner->view()->currentBuffer()->text, iLenSelected);
661 owner->view()->toggleSelection(false);
665 // REMOVED : if (owner->view()->getWorkArea()->focus)
666 owner->view()->showCursor();
672 if (owner->view()->available()) {
673 owner->view()->update(-2);
676 keyseq.print(buf, true);
677 owner->getMiniBuffer()->Set(buf, string(), string(), 1);
681 // --- Misc -------------------------------------------
682 case LFUN_EXEC_COMMAND:
683 owner->getMiniBuffer()->ExecCommand();
686 case LFUN_CANCEL: // RVDK_PATCH_5
689 if(owner->view()->available())
690 // cancel any selection
691 Dispatch(LFUN_MARK_OFF, 0);
692 setMessage(N_("Cancel"));
695 case LFUN_META_FAKE: // RVDK_PATCH_5
697 meta_fake_bit = Mod1Mask;
699 keyseq.print(buf, true);
700 string res = string("M-") + buf;
701 setMessage(buf); // RVDK_PATCH_5
705 case LFUN_READ_ONLY_TOGGLE:
706 if (owner->buffer()->lyxvc.inUse()) {
707 owner->buffer()->lyxvc.toggleReadOnly();
709 owner->buffer()->setReadonly(
710 !owner->buffer()->isReadonly());
714 case LFUN_CENTER: // this is center and redraw.
715 owner->view()->center();
719 if (owner->view()->available()) {
720 owner->view()->text->toggleAppendix();
721 owner->view()->update(1);
725 // --- Menus -----------------------------------------------
730 case LFUN_MENUNEWTMPLT:
738 case LFUN_CLOSEBUFFER:
743 owner->getMiniBuffer()->Set(_("Saving document"),
744 MakeDisplayPath(owner->buffer()->fileName()),
746 MenuWrite(owner->buffer());
747 //owner->getMiniBuffer()-> {
748 // Set(_("Document saved as"),
749 // MakeDisplayPath(owner->buffer()->fileName()));
751 //owner->getMiniBuffer()->Set(_("Save failed!"));
755 case LFUN_MENUWRITEAS:
756 MenuWriteAs(owner->buffer());
759 case LFUN_MENURELOAD:
764 PreviewDVI(owner->buffer());
768 PreviewPostscript(owner->buffer());
772 MenuRunLaTeX(owner->buffer());
776 MenuBuildProg(owner->buffer());
780 MenuRunChktex(owner->buffer());
784 CreatePostscript(owner->buffer(), false);
788 MenuPrint(owner->buffer());
792 MenuFax(owner->buffer());
796 MenuExport(owner->buffer(), argument);
809 if (fd_form_toc->form_toc->visible) {
810 fl_raise_form(fd_form_toc->form_toc);
812 static int ow = -1, oh;
813 fl_show_form(fd_form_toc->form_toc,
815 FL_FREE_SIZE, FL_FULLBORDER,
816 _("Table of Contents"));
818 ow = fd_form_toc->form_toc->w;
819 oh = fd_form_toc->form_toc->h;
821 fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
825 case LFUN_TOC_INSERT:
827 Inset * new_inset = new InsetTOC(owner->buffer());
828 if (!owner->view()->insertInset(new_inset, "Standard", true))
833 case LFUN_LOF_INSERT:
835 Inset * new_inset = new InsetLOF(owner->buffer());
836 if (!owner->view()->insertInset(new_inset, "Standard", true))
841 case LFUN_LOA_INSERT:
843 Inset * new_inset = new InsetLOA(owner->buffer());
844 if (!owner->view()->insertInset(new_inset, "Standard", true))
849 case LFUN_LOT_INSERT:
851 Inset * new_inset = new InsetLOT(owner->buffer());
852 if (!owner->view()->insertInset(new_inset, "Standard", true))
865 case LFUN_INSERT_GRAPHICS:
867 Inset * new_inset = new InsetGraphics;
868 if (!owner->view()->insertInset(new_inset))
874 AutoSave(owner->view());
878 owner->view()->menuUndo();
882 owner->view()->menuRedo();
885 case LFUN_MENUSEARCH:
887 // Ok this is one _very_ bad solution, but I think that some
888 // of this will be rewritten as part of GUI indep anyway.
890 static LyXFindReplace FR_;
891 FR_.StartSearch(owner->view());
897 owner->view()->paste();
898 owner->view()->setState();
901 case LFUN_PASTESELECTION:
904 if (argument == "paragraph") asPara = true;
905 MenuPasteSelection(asPara);
910 owner->view()->cut();
914 owner->view()->copy();
917 case LFUN_LAYOUT_COPY:
918 owner->view()->copyEnvironment();
921 case LFUN_LAYOUT_PASTE:
922 owner->view()->pasteEnvironment();
923 owner->view()->setState();
927 owner->view()->gotoError();
930 case LFUN_REMOVEERRORS:
931 if (owner->view()->removeAutoInsets()) {
932 owner->view()->redraw();
933 owner->view()->fitCursor();
934 //owner->view()->updateScrollbar();
939 owner->view()->gotoNote();
943 owner->view()->openStuff();
946 case LFUN_HYPHENATION:
947 owner->view()->hyphenationPoint();
951 owner->view()->ldots();
954 case LFUN_END_OF_SENTENCE:
955 owner->view()->endOfSentenceDot();
958 case LFUN_MENU_SEPARATOR:
959 owner->view()->menuSeparator();
963 owner->view()->hfill();
967 changeDepth(owner->view(), 0);
971 changeDepth(owner->view(), -1);
974 case LFUN_DEPTH_PLUS:
975 changeDepth(owner->view(), 1);
980 owner->view()->setState();
981 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
986 owner->view()->setState();
987 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
994 case LFUN_RECONFIGURE:
995 Reconfigure(owner->view());
999 if (owner->view()->available()
1000 && !owner->view()->text->selection
1001 && owner->view()->text->cursor.par->footnoteflag
1002 != LyXParagraph::NO_FOOTNOTE)
1003 { // only melt footnotes with FOOTMELT, not margins etc
1004 if(owner->view()->text->cursor.par->footnotekind == LyXParagraph::FOOTNOTE)
1005 Melt(owner->view());
1008 Foot(owner->view());
1009 owner->view()->setState();
1012 case LFUN_MARGINMELT:
1013 if (owner->view()->available()
1014 && !owner->view()->text->selection
1015 && owner->view()->text->cursor.par->footnoteflag
1016 != LyXParagraph::NO_FOOTNOTE) {
1017 // only melt margins
1018 if(owner->view()->text->cursor.par->footnotekind == LyXParagraph::MARGIN)
1019 Melt(owner->view());
1021 Margin(owner->view());
1022 owner->view()->setState();
1025 // --- version control -------------------------------
1026 case LFUN_VC_REGISTER:
1028 if (!owner->buffer()->lyxvc.inUse())
1029 owner->buffer()->lyxvc.registrer();
1033 case LFUN_VC_CHECKIN:
1035 if (owner->buffer()->lyxvc.inUse()
1036 && !owner->buffer()->isReadonly())
1037 owner->buffer()->lyxvc.checkIn();
1041 case LFUN_VC_CHECKOUT:
1043 if (owner->buffer()->lyxvc.inUse()
1044 && owner->buffer()->isReadonly())
1045 owner->buffer()->lyxvc.checkOut();
1049 case LFUN_VC_REVERT:
1051 owner->buffer()->lyxvc.revert();
1057 owner->buffer()->lyxvc.undoLast();
1061 case LFUN_VC_HISTORY:
1063 owner->buffer()->lyxvc.showLog();
1067 // --- buffers ----------------------------------------
1069 case LFUN_FILE_INSERT:
1071 MenuInsertLyXFile(argument);
1075 case LFUN_FILE_INSERT_ASCII:
1077 bool asPara = (argument == "paragraph");
1078 InsertAsciiFile(owner->view(), string(), asPara);
1084 // servercmd: argument must be <file>:<template>
1085 Buffer * tmpbuf = NewLyxFile(argument);
1087 owner->view()->buffer(tmpbuf);
1091 case LFUN_FILE_OPEN:
1092 owner->view()->buffer(bufferlist.loadLyXFile(argument));
1095 case LFUN_LATEX_LOG:
1101 lyxerr.debug() << "LFUN_LAYOUTNO: (arg) " << argument << endl;
1102 int sel = strToInt(argument);
1103 lyxerr.debug() << "LFUN_LAYOUTNO: (sel) "<< sel << endl;
1105 // Should this give a setMessage instead?
1107 return string(); // illegal argument
1109 --sel; // sel 1..., but layout 0...
1111 // Pretend we got the name instead.
1112 Dispatch(int(LFUN_LAYOUT),
1113 textclasslist.NameOfLayout(owner->view()
1114 ->buffer()->params.textclass,
1121 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1122 << argument << endl;
1124 // Derive layout number from given argument (string)
1125 // and current buffer's textclass (number). */
1126 LyXTextClassList::ClassList::size_type tclass =
1127 owner->view()->buffer()->params.textclass;
1128 pair <bool, LyXTextClass::size_type> layout =
1129 textclasslist.NumberOfLayout(tclass, argument);
1131 // If the entry is obsolete, use the new one instead.
1133 string obs = textclasslist.Style(tclass,layout.second)
1137 textclasslist.NumberOfLayout(tclass, obs);
1140 // see if we found the layout number:
1141 if (!layout.first) {
1142 setErrorMessage(string(N_("Layout ")) + argument +
1147 if (current_layout != layout.second) {
1148 owner->view()->hideCursor();
1149 current_layout = layout.second;
1150 owner->view()->update(-2);
1151 owner->view()->text->
1152 SetLayout(layout.second);
1153 owner->getToolbar()->combox->
1154 select(owner->view()->
1157 owner->view()->update(1);
1158 owner->view()->setState();
1163 case LFUN_LAYOUT_DOCUMENT:
1164 MenuLayoutDocument();
1167 case LFUN_LAYOUT_PARAGRAPH:
1168 MenuLayoutParagraph();
1171 case LFUN_LAYOUT_CHARACTER:
1172 MenuLayoutCharacter();
1175 case LFUN_LAYOUT_TABLE:
1178 if (argument == "true") flag = 1;
1179 MenuLayoutTable(flag);
1183 case LFUN_LAYOUT_PAPER:
1187 case LFUN_LAYOUT_QUOTES:
1191 case LFUN_LAYOUT_PREAMBLE:
1192 MenuLayoutPreamble();
1195 case LFUN_LAYOUT_SAVE_DEFAULT:
1199 case LFUN_DROP_LAYOUTS_CHOICE:
1200 owner->getToolbar()->combox->Show();
1205 Lang(owner->view(), argument);
1206 owner->view()->setState();
1207 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1212 Emph(owner->view());
1213 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1217 Bold(owner->view());
1218 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1222 Noun(owner->view());
1223 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1227 Code(owner->view());
1228 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1232 Sans(owner->view());
1233 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1237 Roman(owner->view());
1238 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1242 StyleReset(owner->view());
1243 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1246 case LFUN_UNDERLINE:
1247 Underline(owner->view());
1248 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1251 case LFUN_FONT_SIZE:
1252 FontSize(owner->view(), argument);
1253 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1256 case LFUN_FONT_STATE:
1257 setMessage(CurrentState(owner->view()));
1260 case LFUN_UPCASE_WORD:
1261 owner->view()->update(-2);
1263 owner->view()->text->ChangeWordCase(LyXText::text_uppercase);
1264 owner->view()->update(1);
1268 case LFUN_LOWCASE_WORD:
1269 owner->view()->update(-2);
1271 owner->view()->text->ChangeWordCase(LyXText::text_lowercase);
1272 owner->view()->update(1);
1276 case LFUN_CAPITALIZE_WORD:
1277 owner->view()->update(-2);
1279 owner->view()->text->ChangeWordCase(LyXText::text_capitalization);
1280 owner->view()->update(1);
1284 case LFUN_INSERT_LABEL:
1285 MenuInsertLabel(argument.c_str());
1288 case LFUN_INSERT_REF:
1292 case LFUN_REFTOGGLE:
1295 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1298 owner->view()->updateInset(inset, true);
1300 setErrorMessage(N_("No cross-reference to toggle"));
1307 owner->view()->restorePosition();
1313 string label(argument);
1314 if (label.empty()) {
1316 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1318 label = inset->getContents();
1321 if (!label.empty()) {
1322 owner->view()->savePosition();
1323 if (!owner->view()->gotoLabel(label))
1324 WriteAlert(_("Error"),
1325 _("Couldn't find this label"),
1326 _("in current document."));
1331 case LFUN_MENU_OPEN_BY_NAME:
1332 owner->getMenus()->openByName(argument);
1333 break; // RVDK_PATCH_5
1335 case LFUN_SPELLCHECK:
1336 if (lyxrc.isp_command != "none")
1337 ShowSpellChecker(owner->view());
1338 break; // RVDK_PATCH_5
1340 // --- Cursor Movements -----------------------------
1343 LyXText * tmptext = owner->view()->text;
1344 bool is_rtl = tmptext->cursor.par->isRightToLeftPar();
1345 if(!tmptext->mark_set)
1346 owner->view()->beforeChange();
1347 owner->view()->update(-2);
1349 tmptext->CursorLeft();
1350 if (tmptext->cursor.pos < tmptext->cursor.par->Last()
1351 && tmptext->cursor.par->GetChar(tmptext->cursor.pos)
1352 == LyXParagraph::META_INSET
1353 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)
1354 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)->Editable() == Inset::HIGHLY_EDITABLE){
1355 Inset * tmpinset = tmptext->cursor.par->GetInset(tmptext->cursor.pos);
1356 setMessage(tmpinset->EditMessage());
1357 tmpinset->Edit(owner->view(), 0, 0, 0);
1361 tmptext->CursorRight();
1362 owner->view()->text->FinishUndo();
1363 moveCursorUpdate(false);
1364 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1370 // This is soooo ugly. Isn`t it possible to make
1371 // it simpler? (Lgb)
1372 LyXText * txt = owner->view()->text;
1373 bool is_rtl = txt->cursor.par->isRightToLeftPar();
1374 if(!txt->mark_set) owner->view()->beforeChange();
1375 owner->view()->update(-2);
1378 if (txt->cursor.pos < txt->cursor.par->Last()
1379 && txt->cursor.par->GetChar(txt->cursor.pos)
1380 == LyXParagraph::META_INSET
1381 && txt->cursor.par->GetInset(txt->cursor.pos)
1382 && txt->cursor.par->GetInset(txt->cursor.pos)->Editable() == Inset::HIGHLY_EDITABLE) {
1383 Inset * tmpinset = txt->cursor.par->GetInset(txt->cursor.pos);
1384 setMessage(tmpinset->EditMessage());
1385 LyXFont font = txt->GetFont(txt->cursor.par,
1387 tmpinset->Edit(owner->view(),
1388 tmpinset->x() + tmpinset->width(owner->view()->painter(),font),
1389 tmpinset->descent(owner->view()->painter(),font),
1396 owner->view()->text->FinishUndo();
1397 moveCursorUpdate(false);
1398 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1403 if(!owner->view()->text->mark_set) owner->view()->beforeChange();
1404 owner->view()->update(-3);
1405 owner->view()->text->CursorUp();
1406 owner->view()->text->FinishUndo();
1407 moveCursorUpdate(false);
1408 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1412 if(!owner->view()->text->mark_set)
1413 owner->view()->beforeChange();
1414 owner->view()->update(-3);
1415 owner->view()->text->CursorDown();
1416 owner->view()->text->FinishUndo();
1417 moveCursorUpdate(false);
1418 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1421 case LFUN_UP_PARAGRAPH:
1422 if(!owner->view()->text->mark_set)
1423 owner->view()->beforeChange();
1424 owner->view()->update(-3);
1425 owner->view()->text->CursorUpParagraph();
1426 owner->view()->text->FinishUndo();
1427 moveCursorUpdate(false);
1428 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1431 case LFUN_DOWN_PARAGRAPH:
1432 if(!owner->view()->text->mark_set)
1433 owner->view()->beforeChange();
1434 owner->view()->update(-3);
1435 owner->view()->text->CursorDownParagraph();
1436 owner->view()->text->FinishUndo();
1437 moveCursorUpdate(false);
1438 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1442 if(!owner->view()->text->mark_set)
1443 owner->view()->beforeChange();
1444 owner->view()->update(-3);
1445 owner->view()->cursorPrevious();
1446 owner->view()->text->FinishUndo();
1447 moveCursorUpdate(false);
1448 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1452 if(!owner->view()->text->mark_set)
1453 owner->view()->beforeChange();
1454 owner->view()->update(-3);
1455 owner->view()->cursorNext();
1456 owner->view()->text->FinishUndo();
1457 moveCursorUpdate(false);
1458 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1462 if(!owner->view()->text->mark_set)
1463 owner->view()->beforeChange();
1464 owner->view()->update(-2);
1465 owner->view()->text->CursorHome();
1466 owner->view()->text->FinishUndo();
1467 moveCursorUpdate(false);
1468 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1472 if(!owner->view()->text->mark_set)
1473 owner->view()->beforeChange();
1474 owner->view()->update(-2);
1475 owner->view()->text->CursorEnd();
1476 owner->view()->text->FinishUndo();
1477 moveCursorUpdate(false);
1478 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1482 if(!owner->view()->text->mark_set)
1483 owner->view()->beforeChange();
1484 owner->view()->update(-2);
1485 owner->view()->text->CursorTab();
1486 owner->view()->text->FinishUndo();
1487 moveCursorUpdate(false);
1488 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1491 case LFUN_WORDRIGHT:
1492 if(!owner->view()->text->mark_set)
1493 owner->view()->beforeChange();
1494 owner->view()->update(-2);
1495 if (owner->view()->text->cursor.par->isRightToLeftPar())
1496 owner->view()->text->CursorLeftOneWord();
1498 owner->view()->text->CursorRightOneWord();
1499 owner->view()->text->FinishUndo();
1500 moveCursorUpdate(false);
1501 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1505 if(!owner->view()->text->mark_set)
1506 owner->view()->beforeChange();
1507 owner->view()->update(-2);
1508 if (owner->view()->text->cursor.par->isRightToLeftPar())
1509 owner->view()->text->CursorRightOneWord();
1511 owner->view()->text->CursorLeftOneWord();
1512 owner->view()->text->FinishUndo();
1513 moveCursorUpdate(false);
1514 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1517 case LFUN_BEGINNINGBUF:
1518 if(!owner->view()->text->mark_set)
1519 owner->view()->beforeChange();
1520 owner->view()->update(-2);
1521 owner->view()->text->CursorTop();
1522 owner->view()->text->FinishUndo();
1523 moveCursorUpdate(false);
1524 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1528 if(!owner->view()->text->mark_set)
1529 owner->view()->beforeChange();
1530 owner->view()->update(-2);
1531 owner->view()->text->CursorBottom();
1532 owner->view()->text->FinishUndo();
1533 moveCursorUpdate(false);
1534 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1538 /* cursor selection ---------------------------- */
1540 owner->view()->update(-2);
1541 if (owner->view()->text->cursor.par->isRightToLeftPar())
1542 owner->view()->text->CursorLeft();
1544 owner->view()->text->CursorRight();
1545 owner->view()->text->FinishUndo();
1546 moveCursorUpdate(true);
1547 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1551 owner->view()->update(-2);
1552 if (owner->view()->text->cursor.par->isRightToLeftPar())
1553 owner->view()->text->CursorRight();
1555 owner->view()->text->CursorLeft();
1556 owner->view()->text->FinishUndo();
1557 moveCursorUpdate(true);
1558 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1562 owner->view()->update(-2);
1563 owner->view()->text->CursorUp();
1564 owner->view()->text->FinishUndo();
1565 moveCursorUpdate(true);
1566 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1570 owner->view()->update(-2);
1571 owner->view()->text->CursorDown();
1572 owner->view()->text->FinishUndo();
1573 moveCursorUpdate(true);
1574 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1577 case LFUN_UP_PARAGRAPHSEL:
1578 owner->view()->update(-2);
1579 owner->view()->text->CursorUpParagraph();
1580 owner->view()->text->FinishUndo();
1581 moveCursorUpdate(true);
1582 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1585 case LFUN_DOWN_PARAGRAPHSEL:
1586 owner->view()->update(-2);
1587 owner->view()->text->CursorDownParagraph();
1588 owner->view()->text->FinishUndo();
1589 moveCursorUpdate(true);
1590 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1594 owner->view()->update(-2);
1595 owner->view()->cursorPrevious();
1596 owner->view()->text->FinishUndo();
1597 moveCursorUpdate(true);
1598 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1602 owner->view()->update(-2);
1603 owner->view()->cursorNext();
1604 owner->view()->text->FinishUndo();
1605 moveCursorUpdate(true);
1606 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1610 owner->view()->update(-2);
1611 owner->view()->text->CursorHome();
1612 owner->view()->text->FinishUndo();
1613 moveCursorUpdate(true);
1614 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1618 owner->view()->update(-2);
1619 owner->view()->text->CursorEnd();
1620 owner->view()->text->FinishUndo();
1621 moveCursorUpdate(true);
1622 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1625 case LFUN_WORDRIGHTSEL:
1626 owner->view()->update(-2);
1627 if (owner->view()->text->cursor.par->isRightToLeftPar())
1628 owner->view()->text->CursorLeftOneWord();
1630 owner->view()->text->CursorRightOneWord();
1631 owner->view()->text->FinishUndo();
1632 moveCursorUpdate(true);
1633 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1636 case LFUN_WORDLEFTSEL:
1637 owner->view()->update(-2);
1638 if (owner->view()->text->cursor.par->isRightToLeftPar())
1639 owner->view()->text->CursorRightOneWord();
1641 owner->view()->text->CursorLeftOneWord();
1642 owner->view()->text->FinishUndo();
1643 moveCursorUpdate(true);
1644 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1647 case LFUN_BEGINNINGBUFSEL:
1648 owner->view()->update(-2);
1649 owner->view()->text->CursorTop();
1650 owner->view()->text->FinishUndo();
1651 moveCursorUpdate(true);
1652 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1655 case LFUN_ENDBUFSEL:
1656 owner->view()->update(-2);
1657 owner->view()->text->CursorBottom();
1658 owner->view()->text->FinishUndo();
1659 moveCursorUpdate(true);
1660 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1663 // --- text changing commands ------------------------
1664 case LFUN_BREAKLINE:
1665 owner->view()->beforeChange();
1666 owner->view()->text->InsertChar(LyXParagraph::META_NEWLINE);
1667 owner->view()->update(1);
1668 SetUpdateTimer(0.01);
1669 moveCursorUpdate(false);
1672 case LFUN_PROTECTEDSPACE:
1674 LyXLayout const & style =
1675 textclasslist.Style(owner->view()->buffer()->params.textclass,
1676 owner->view()->text->cursor.par->GetLayout());
1678 if (style.free_spacing) {
1679 owner->view()->text->InsertChar(' ');
1680 owner->view()->update(-1);
1682 owner->view()->protectedBlank();
1684 moveCursorUpdate(false);
1689 if(owner->view()->text->mark_set) {
1690 owner->view()->beforeChange();
1691 owner->view()->update(0);
1692 setMessage(N_("Mark removed"));
1694 owner->view()->beforeChange();
1695 owner->view()->text->mark_set = 1;
1696 owner->view()->update(0);
1697 setMessage(N_("Mark set"));
1699 owner->view()->text->sel_cursor =
1700 owner->view()->text->cursor;
1705 if (!owner->view()->text->selection) {
1706 owner->view()->text->Delete();
1707 owner->view()->text->sel_cursor =
1708 owner->view()->text->cursor;
1709 owner->view()->update(1);
1710 // It is possible to make it a lot faster still
1711 // just comment out the lone below...
1712 owner->view()->showCursor();
1714 owner->view()->cut();
1717 moveCursorUpdate(false);
1718 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1719 owner->view()->setState();
1722 case LFUN_DELETE_SKIP:
1724 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1726 LyXCursor cursor = owner->view()->text->cursor;
1729 if (!owner->view()->text->selection) {
1730 if (cursor.pos == cursor.par->Last()) {
1731 owner->view()->text->CursorRight();
1732 cursor = owner->view()->text->cursor;
1734 && !(cursor.par->added_space_top
1735 == VSpace (VSpace::NONE))) {
1736 owner->view()->text->SetParagraph
1737 (cursor.par->line_top,
1738 cursor.par->line_bottom,
1739 cursor.par->pagebreak_top,
1740 cursor.par->pagebreak_bottom,
1741 VSpace(VSpace::NONE),
1742 cursor.par->added_space_bottom,
1744 cursor.par->labelwidthstring, 0);
1745 owner->view()->text->CursorLeft();
1746 owner->view()->update (1);
1748 owner->view()->text->CursorLeft();
1749 owner->view()->text->Delete();
1750 owner->view()->text->sel_cursor =
1751 owner->view()->text->cursor;
1752 owner->view()->update(1);
1755 owner->view()->text->Delete();
1756 owner->view()->text->sel_cursor =
1757 owner->view()->text->cursor;
1758 owner->view()->update(1);
1761 owner->view()->cut();
1767 /* -------> Delete word forward. */
1768 case LFUN_DELETE_WORD_FORWARD:
1769 owner->view()->update(-2);
1771 owner->view()->text->DeleteWordForward();
1772 owner->view()->update( 1 );
1774 moveCursorUpdate(false);
1775 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1778 /* -------> Delete word backward. */
1779 case LFUN_DELETE_WORD_BACKWARD:
1780 owner->view()->update(-2);
1782 owner->view()->text->DeleteWordBackward();
1783 owner->view()->update( 1 );
1785 moveCursorUpdate(false);
1786 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1789 /* -------> Kill to end of line. */
1790 case LFUN_DELETE_LINE_FORWARD:
1792 owner->view()->update(-2);
1793 owner->view()->text->DeleteLineForward();
1794 owner->view()->update( 1 );
1796 moveCursorUpdate(false);
1799 /* -------> Set mark off. */
1801 owner->view()->beforeChange();
1802 owner->view()->update(0);
1803 owner->view()->text->sel_cursor =
1804 owner->view()->text->cursor;
1805 setMessage(N_("Mark off"));
1808 /* -------> Set mark on. */
1810 owner->view()->beforeChange();
1811 owner->view()->text->mark_set = 1;
1812 owner->view()->update( 0 );
1813 owner->view()->text->sel_cursor =
1814 owner->view()->text->cursor;
1815 setMessage(N_("Mark on"));
1818 case LFUN_BACKSPACE:
1821 if (!owner->view()->text->selection) {
1822 if (owner->getIntl()->getTrans()->backspace()) {
1823 owner->view()->text->Backspace();
1824 owner->view()->text->sel_cursor =
1825 owner->view()->text->cursor;
1826 owner->view()->update(1);
1827 // It is possible to make it a lot faster still
1828 // just comment out the lone below...
1829 owner->view()->showCursor();
1832 owner->view()->cut();
1835 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1836 owner->view()->setState();
1840 case LFUN_BACKSPACE_SKIP:
1842 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1844 LyXCursor cursor = owner->view()->text->cursor;
1847 if (!owner->view()->text->selection) {
1849 && !(cursor.par->added_space_top
1850 == VSpace (VSpace::NONE))) {
1851 owner->view()->text->SetParagraph
1852 (cursor.par->line_top,
1853 cursor.par->line_bottom,
1854 cursor.par->pagebreak_top,
1855 cursor.par->pagebreak_bottom,
1856 VSpace(VSpace::NONE), cursor.par->added_space_bottom,
1858 cursor.par->labelwidthstring, 0);
1859 owner->view()->update (1);
1861 owner->view()->text->Backspace();
1862 owner->view()->text->sel_cursor
1864 owner->view()->update(1);
1867 owner->view()->cut();
1872 case LFUN_BREAKPARAGRAPH:
1874 owner->view()->beforeChange();
1875 owner->view()->text->BreakParagraph(0);
1876 owner->view()->update(1);
1877 SetUpdateTimer(0.01);
1878 owner->view()->text->sel_cursor =
1879 owner->view()->text->cursor;
1880 owner->view()->setState();
1881 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1885 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1887 owner->view()->beforeChange();
1888 owner->view()->text->BreakParagraph(1);
1889 owner->view()->update(1);
1890 SetUpdateTimer(0.01);
1891 owner->view()->text->sel_cursor =
1892 owner->view()->text->cursor;
1893 owner->view()->setState();
1894 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1898 case LFUN_BREAKPARAGRAPH_SKIP:
1900 // When at the beginning of a paragraph, remove
1901 // indentation and add a "defskip" at the top.
1902 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
1904 LyXCursor cursor = owner->view()->text->cursor;
1906 owner->view()->beforeChange();
1907 if (cursor.pos == 0) {
1908 if (cursor.par->added_space_top == VSpace(VSpace::NONE)) {
1909 owner->view()->text->SetParagraph
1910 (cursor.par->line_top,
1911 cursor.par->line_bottom,
1912 cursor.par->pagebreak_top,
1913 cursor.par->pagebreak_bottom,
1914 VSpace(VSpace::DEFSKIP), cursor.par->added_space_bottom,
1916 cursor.par->labelwidthstring, 1);
1917 owner->view()->update(1);
1921 owner->view()->text->BreakParagraph(0);
1922 owner->view()->update(1);
1924 SetUpdateTimer(0.01);
1925 owner->view()->text->sel_cursor = cursor;
1926 owner->view()->setState();
1927 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1931 case LFUN_PARAGRAPH_SPACING:
1933 LyXParagraph * par = owner->view()->text->cursor.par;
1934 Spacing::Space cur_spacing = par->spacing.getSpace();
1935 float cur_value = 1.0;
1936 if (cur_spacing == Spacing::Other) {
1937 cur_value = par->spacing.getValue();
1941 istringstream istr(argument);
1943 istrstream istr(argument.c_str());
1947 Spacing::Space new_spacing = cur_spacing;
1948 float new_value = cur_value;
1950 lyxerr << "Missing argument to `paragraph-spacing'"
1952 } else if (tmp == "single") {
1953 new_spacing = Spacing::Single;
1954 } else if (tmp == "onehalf") {
1955 new_spacing = Spacing::Onehalf;
1956 } else if (tmp == "double") {
1957 new_spacing = Spacing::Double;
1958 } else if (tmp == "other") {
1959 new_spacing = Spacing::Other;
1962 lyxerr << "new_value = " << tmpval << endl;
1965 } else if (tmp == "default") {
1966 new_spacing = Spacing::Default;
1968 lyxerr << _("Unknown spacing argument: ")
1969 << argument << endl;
1971 if (cur_spacing != new_spacing || cur_value != new_value) {
1972 par->spacing.set(new_spacing, new_value);
1973 owner->view()->text->RedoParagraph();
1974 owner->view()->update(-1);
1980 owner->view()->beforeChange();
1981 owner->view()->text->InsertChar('\"'); // This " matches the single quote in the code
1982 owner->view()->update(1);
1984 moveCursorUpdate(false);
1990 InsetCommand * new_inset;
1991 if (action == LFUN_HTMLURL)
1992 new_inset = new InsetUrl("htmlurl", "", "");
1994 new_inset = new InsetUrl("url", "", "");
1995 if (owner->view()->insertInset(new_inset))
1996 new_inset->Edit(owner->view(), 0, 0, 0);
2002 case LFUN_INSET_TEXT:
2004 InsetText * new_inset = new InsetText(owner->buffer());
2005 if (owner->view()->insertInset(new_inset))
2006 new_inset->Edit(owner->view(), 0, 0, 0);
2011 case LFUN_INSET_ERT:
2013 InsetERT * new_inset = new InsetERT(owner->buffer());
2014 if (owner->view()->insertInset(new_inset))
2015 new_inset->Edit(owner->view(), 0, 0, 0);
2021 case LFUN_INSET_FOOTNOTE:
2023 InsetFoot * new_inset = new InsetFoot(owner->buffer());
2024 if (owner->view()->insertInset(new_inset))
2025 new_inset->Edit(owner->view(), 0, 0, 0);
2031 case LFUN_INSET_TABULAR:
2034 if (!argument.empty())
2035 sscanf(argument.c_str(),"%d%d",&r,&c);
2036 InsetTabular * new_inset = new InsetTabular(owner->buffer(),r,c);
2037 if (owner->view()->insertInset(new_inset))
2038 new_inset->Edit(owner->view(), 0, 0, 0);
2044 // --- lyxserver commands ----------------------------
2046 case LFUN_CHARATCURSOR:
2048 LyXParagraph::size_type pos =
2049 owner->view()->text->cursor.pos;
2050 if(pos < owner->view()->text->cursor.par->size())
2051 //dispatch_buffer = owner->view()->text->
2052 // cursor.par->text[pos];
2054 owner->view()->text->
2055 cursor.par->GetChar(pos);
2057 dispatch_buffer = "EOF";
2063 tostr(owner->view()->text->cursor.x) + ' '
2064 + tostr(owner->view()->text->cursor.y);
2071 sscanf(argument.c_str(), " %d %ld", &x, &y);
2072 owner->view()->text->SetCursorFromCoordinates(x, y);
2076 case LFUN_GETLAYOUT:
2078 tostr(owner->view()->text->cursor.par->layout);
2083 LyXFont & font = owner->view()->text->current_font;
2084 if(font.shape() == LyXFont::ITALIC_SHAPE)
2085 dispatch_buffer = 'E';
2086 else if(font.shape() == LyXFont::SMALLCAPS_SHAPE)
2087 dispatch_buffer = 'N';
2089 dispatch_buffer = '0';
2096 LyXFont & font = owner->view()->text->current_font;
2097 if(font.latex() == LyXFont::ON)
2098 dispatch_buffer = 'L';
2100 dispatch_buffer = '0';
2105 setMessage(owner->buffer()->fileName());
2106 lyxerr.debug() << "FNAME["
2107 << owner->buffer()->fileName()
2115 dispatch_buffer = buf;
2116 lyxserver->notifyClient(dispatch_buffer);
2120 case LFUN_GOTOFILEROW:
2122 char file_name[100];
2124 sscanf(argument.c_str(), " %s %d", file_name, &row);
2126 // Must replace extension of the file to be .lyx and get full path
2127 string s = ChangeExtension(string(file_name), ".lyx");
2129 // Either change buffer or load the file
2130 if (bufferlist.exists(s))
2131 owner->view()->buffer(bufferlist.getBuffer(s));
2133 owner->view()->buffer(bufferlist.loadLyXFile(s));
2136 owner->view()->setCursorFromRow(row);
2139 owner->view()->center();
2146 int qa = lyxaction.LookupFunc(argument.c_str());
2147 setMessage(lyxaction.helpText(static_cast<kb_action>(qa)));
2151 // --- accented characters ---------------------------
2154 case LFUN_CIRCUMFLEX:
2164 case LFUN_SPECIAL_CARON:
2167 case LFUN_HUNG_UMLAUT:
2173 if (keyseq.length == -1 && keyseq.getiso() != 0)
2174 c = keyseq.getiso();
2176 owner->getIntl()->getTrans()->
2177 deadkey(c, get_accent(action).accent,
2178 owner->view()->text);
2180 // Need to reset, in case the minibuffer calls these
2185 // copied verbatim from do_accent_char
2186 owner->view()->update(1);
2189 owner->view()->text->sel_cursor =
2190 owner->view()->text->cursor;
2194 // --- toolbar ----------------------------------
2195 case LFUN_PUSH_TOOLBAR:
2197 int nth = strToInt(argument);
2198 if (lyxerr.debugging(Debug::TOOLBAR)) {
2199 lyxerr << "LFUN_PUSH_TOOLBAR: argument = `"
2200 << argument << "'\n"
2201 << "LFUN_PUSH_TOOLBAR: nth = `"
2202 << nth << "'" << endl;
2207 setErrorMessage(N_("Push-toolbar needs argument > 0"));
2209 owner->getToolbar()->push(nth);
2214 case LFUN_ADD_TO_TOOLBAR:
2216 if (lyxerr.debugging(Debug::TOOLBAR)) {
2217 lyxerr << "LFUN_ADD_TO_TOOLBAR:"
2218 "argument = `" << argument << '\'' << endl;
2220 string tmp(argument);
2221 //lyxerr <<string("Argument: ") + argument);
2222 //lyxerr <<string("Tmp : ") + tmp);
2225 setErrorMessage(N_("Usage: toolbar-add-to <LyX command>"));
2227 owner->getToolbar()->add(argument, false);
2228 owner->getToolbar()->set();
2233 // --- insert characters ----------------------------------------
2235 // --- Mathed stuff. If we are here, there is no locked inset yet.
2240 if (!greek_kb_flag) {
2242 setMessage(N_("Math greek mode on"));
2249 case LFUN_GREEK_TOGGLE:
2251 greek_kb_flag = greek_kb_flag ? 0 : 2;
2252 if (greek_kb_flag) {
2253 setMessage(N_("Math greek keyboard on"));
2255 setMessage(N_("Math greek keyboard off"));
2260 case LFUN_MATH_DELIM:
2261 case LFUN_INSERT_MATRIX:
2263 if (owner->view()->available()) {
2265 open_new_inset(new InsetFormula(false));
2268 ->LocalDispatch(owner->view(),
2275 case LFUN_INSERT_MATH:
2277 math_insert_symbol(argument.c_str());
2281 case LFUN_MATH_DISPLAY:
2283 if (owner->view()->available())
2284 owner->view()->open_new_inset(new InsetFormula(true));
2288 case LFUN_MATH_MACRO:
2290 if (owner->view()->available()) {
2293 setErrorMessage(N_("Missing argument"));
2295 string s1 = token(s, ' ', 1);
2296 int na = s1.empty() ? 0: atoi(s1.c_str());
2298 open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2304 case LFUN_MATH_MODE: // Open or create a math inset
2307 if (owner->view()->available())
2308 owner->view()->open_new_inset(new InsetFormula);
2309 setMessage(N_("Math editor mode"));
2313 case LFUN_MATH_NUMBER:
2314 case LFUN_MATH_LIMITS:
2316 setErrorMessage(N_("This is only allowed in math mode!"));
2320 case LFUN_INSERT_CITATION:
2322 InsetCitation * new_inset = new InsetCitation();
2324 // The note, if any, must be after the key, delimited
2325 // by a | so both key and remark can have spaces.
2326 if (!argument.empty()) {
2327 string lsarg(argument);
2328 if (contains(lsarg, "|")) {
2329 new_inset->setContents(token(lsarg, '|', 0));
2330 new_inset->setOptions(token(lsarg, '|', 1));
2332 new_inset->setContents(lsarg);
2333 if (!owner->view()->insertInset(new_inset))
2336 if (owner->view()->insertInset(new_inset))
2337 new_inset->Edit(owner->view(), 0, 0, 0);
2344 case LFUN_INSERT_BIBTEX:
2346 // ale970405+lasgoutt970425
2347 // The argument can be up to two tokens separated
2348 // by a space. The first one is the bibstyle.
2349 string lsarg(argument);
2350 string bibstyle = token(lsarg, ' ', 1);
2351 if (bibstyle.empty())
2353 InsetBibtex * new_inset
2354 = new InsetBibtex(token(lsarg, ' ', 0),
2358 if (owner->view()->insertInset(new_inset)) {
2360 new_inset->Edit(owner->view(), 0, 0, 0);
2366 // BibTeX data bases
2367 case LFUN_BIBDB_ADD:
2369 InsetBibtex * inset =
2370 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2372 inset->addDatabase(argument);
2377 case LFUN_BIBDB_DEL:
2379 InsetBibtex * inset =
2380 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2382 inset->delDatabase(argument);
2387 case LFUN_BIBTEX_STYLE:
2389 InsetBibtex * inset =
2390 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2392 inset->setOptions(argument);
2397 case LFUN_INDEX_INSERT:
2398 case LFUN_INDEX_INSERT_LAST:
2400 // Can't do that at the beginning of a paragraph.
2401 if (owner->view()->text->cursor.pos - 1 < 0)
2404 InsetIndex * new_inset = new InsetIndex();
2405 if (!argument.empty()) {
2406 string lsarg(argument);
2407 new_inset->setContents(lsarg);
2408 if (!owner->view()->insertInset(new_inset))
2412 //get the current word for an argument
2413 LyXParagraph::size_type lastpos =
2414 owner->view()->text->cursor.pos - 1;
2415 // Get the current word. note that this must be done
2416 // before inserting the inset, or the inset will
2418 string curstring(owner->view()
2419 ->text->cursor.par->GetWord(lastpos));
2421 //make the new inset and write the current word into it
2422 InsetIndex * new_inset = new InsetIndex();
2424 new_inset->setContents(curstring);
2426 //don't edit it if the call was to INSERT_LAST
2427 if(action != LFUN_INDEX_INSERT_LAST) {
2428 new_inset->Edit(owner->view(), 0, 0, 0);
2430 //it looks blank on the screen unless
2431 //we do something. put it here.
2433 // move the cursor to the returned value of lastpos
2434 // but only for the auto-insert
2435 owner->view()->text->cursor.pos = lastpos;
2438 //put the new inset into the buffer.
2439 // there should be some way of knowing the user
2440 //cancelled & avoiding this, but i don't know how
2441 if (!owner->view()->insertInset(new_inset))
2447 case LFUN_INDEX_PRINT:
2449 Inset * new_inset = new InsetPrintIndex(owner->buffer());
2450 if (!owner->view()->insertInset(new_inset, "Standard", true))
2455 case LFUN_PARENTINSERT:
2457 lyxerr << "arg " << argument << endl;
2458 Inset * new_inset = new InsetParent(argument, owner->buffer());
2459 if (!owner->view()->insertInset(new_inset, "Standard", true))
2464 case LFUN_CHILDINSERT:
2466 Inset * new_inset = new InsetInclude(argument,
2468 if (owner->view()->insertInset(new_inset, "Standard", true))
2469 new_inset->Edit(owner->view(), 0, 0, 0);
2475 case LFUN_CHILDOPEN:
2478 MakeAbsPath(argument,
2479 OnlyPath(owner->buffer()->fileName()));
2480 setMessage(N_("Opening child document ") +
2481 MakeDisplayPath(filename) + "...");
2482 owner->view()->savePosition();
2483 if (bufferlist.exists(filename))
2484 owner->view()->buffer(bufferlist.getBuffer(filename));
2486 owner->view()->buffer(bufferlist.loadLyXFile(filename));
2490 case LFUN_INSERT_NOTE:
2491 owner->view()->insertNote();
2494 case LFUN_INSERTFOOTNOTE:
2496 LyXParagraph::footnote_kind kind;
2497 if (argument == "footnote")
2498 { kind = LyXParagraph::FOOTNOTE; }
2499 else if (argument == "margin")
2500 { kind = LyXParagraph::MARGIN; }
2501 else if (argument == "figure")
2502 { kind = LyXParagraph::FIG; }
2503 else if (argument == "table")
2504 { kind = LyXParagraph::TAB; }
2505 else if (argument == "wide-fig")
2506 { kind = LyXParagraph::WIDE_FIG; }
2507 else if (argument == "wide-tab")
2508 { kind = LyXParagraph::WIDE_TAB; }
2509 else if (argument == "algorithm")
2510 { kind = LyXParagraph::ALGORITHM; }
2512 setErrorMessage(N_("Unknown kind of footnote"));
2515 owner->view()->text->InsertFootnoteEnvironment(kind);
2516 owner->view()->update(1);
2517 owner->view()->setState();
2521 case LFUN_BUFFERBULLETSSELECT:
2525 case LFUN_TOGGLECURSORFOLLOW:
2526 cursor_follows_scrollbar = !cursor_follows_scrollbar;
2529 case LFUN_KMAP_OFF: // keymap off
2530 owner->getIntl()->KeyMapOn(false);
2533 case LFUN_KMAP_PRIM: // primary keymap
2534 owner->getIntl()->KeyMapPrim();
2537 case LFUN_KMAP_SEC: // secondary keymap
2538 owner->getIntl()->KeyMapSec();
2541 case LFUN_KMAP_TOGGLE: // toggle keymap
2542 owner->getIntl()->ToggleKeyMap();
2545 case LFUN_SELFINSERT:
2547 for (string::size_type i = 0; i < argument.length(); ++i) {
2548 owner->view()->text->InsertChar(argument[i]);
2549 // This needs to be in the loop, or else we
2550 // won't break lines correctly. (Asger)
2551 owner->view()->update(1);
2554 owner->view()->text->sel_cursor =
2555 owner->view()->text->cursor;
2556 moveCursorUpdate(false);
2562 // argument contains ';'-terminated commands
2563 while (argument.find(';') != string::npos) {
2565 argument = split(argument, first, ';');
2571 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
2579 now_time_t = time(NULL);
2580 now_tm = localtime(&now_time_t);
2581 (void)setlocale(LC_TIME, "");
2582 if (!argument.empty())
2584 else if (arg.empty())
2585 arg = lyxrc.date_insert_format;
2586 datetmp_len = (int) strftime(datetmp, 32, arg.c_str(), now_tm);
2587 for (int i = 0; i < datetmp_len; i++) {
2588 owner->view()->text->InsertChar(datetmp[i]);
2589 owner->view()->update(1);
2592 owner->view()->text->sel_cursor = owner->view()->text->cursor;
2593 moveCursorUpdate(false);
2597 case LFUN_SAVEPREFERENCES:
2599 Path p(user_lyxdir);
2600 lyxrc.write("preferences");
2604 case LFUN_UNKNOWN_ACTION:
2606 if(!owner->buffer()) {
2608 setErrorMessage(N_("No document open"));
2612 if (owner->buffer()->isReadonly()) {
2614 setErrorMessage(N_("Document is read only"));
2618 if (!argument.empty()) {
2620 /* Automatically delete the currently selected
2621 * text and replace it with what is being
2622 * typed in now. Depends on lyxrc settings
2623 * "auto_region_delete", which defaults to
2626 if ( lyxrc.auto_region_delete ) {
2627 if (owner->view()->text->selection){
2628 owner->view()->text->CutSelection(false);
2629 owner->view()->update(-1);
2633 owner->view()->beforeChange();
2635 for (string::size_type i = 0;
2636 i < argument.length(); ++i) {
2637 if (greek_kb_flag) {
2638 if (!math_insert_greek(argument[i]))
2639 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2641 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2644 owner->view()->update(1);
2647 owner->view()->text->sel_cursor =
2648 owner->view()->text->cursor;
2649 moveCursorUpdate(false);
2652 // why is an "Unknown action" with empty
2653 // argument even dispatched in the first
2654 // place? I`ll probably change that. (Lgb)
2656 setErrorMessage(N_("Unknown action"));
2660 lyxerr << "A truly unknown func!" << endl;
2666 string res = getMessage();
2669 if (!commandshortcut.empty()) {
2670 string newbuf = owner->getMiniBuffer()->GetText();
2671 if (newbuf != commandshortcut) {
2672 owner->getMiniBuffer()->Set(newbuf
2678 owner->getMiniBuffer()->Set(string(_(res.c_str()))
2679 + " " + commandshortcut);
2686 void LyXFunc::setupLocalKeymap()
2688 keyseq.stdmap = keyseq.curmap = toplevel_keymap;
2689 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap;
2693 void LyXFunc::MenuNew(bool fromTemplate)
2695 string fname, initpath = lyxrc.document_path;
2698 if (owner->view()->available()) {
2699 string trypath = owner->buffer()->filepath;
2700 // If directory is writeable, use this as default.
2701 if (IsDirWriteable(trypath) == 1)
2705 ProhibitInput(owner->view());
2706 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
2707 fileDlg.SetButton(1, _("Templates"), lyxrc.template_path);
2708 fname = fileDlg.Select(_("Enter Filename for new document"),
2709 initpath, "*.lyx", _("newfile"));
2710 AllowInput(owner->view());
2712 if (fname.empty()) {
2713 owner->getMiniBuffer()->Set(_("Canceled."));
2714 lyxerr.debug() << "New Document Cancelled." << endl;
2718 // get absolute path of file and make sure the filename ends
2720 string s = MakeAbsPath(fname);
2721 if (!IsLyXFilename(s))
2724 // Check if the document already is open
2725 if (bufferlist.exists(s)){
2726 switch(AskConfirmation(_("Document is already open:"),
2727 MakeDisplayPath(s, 50),
2728 _("Do you want to close that document now?\n"
2729 "('No' will just switch to the open version)")))
2731 case 1: // Yes: close the document
2732 if (!bufferlist.close(bufferlist.getBuffer(s)))
2733 // If close is canceled, we cancel here too.
2736 case 2: // No: switch to the open document
2737 owner->view()->buffer(bufferlist.getBuffer(s));
2739 case 3: // Cancel: Do nothing
2740 owner->getMiniBuffer()->Set(_("Canceled."));
2745 // Check whether the file already exists
2746 if (IsLyXFilename(s)) {
2748 if (fi.readable() &&
2749 AskQuestion(_("File already exists:"),
2750 MakeDisplayPath(s, 50),
2751 _("Do you want to open the document?"))) {
2753 owner->getMiniBuffer()->Set(_("Opening document"),
2754 MakeDisplayPath(s), "...");
2756 owner->view()->buffer(
2757 bufferlist.loadLyXFile(s));
2758 owner->getMiniBuffer()->Set(_("Document"),
2765 // The template stuff
2768 ProhibitInput(owner->view());
2769 fname = fileDlg.Select(_("Choose template"),
2770 lyxrc.template_path,
2773 AllowInput(owner->view());
2776 // find a free buffer
2777 lyxerr.debug() << "Find a free buffer." << endl;
2778 owner->view()->buffer(bufferlist.newFile(s, templname));
2782 void LyXFunc::MenuOpen()
2784 string initpath = lyxrc.document_path;
2787 if (owner->view()->available()) {
2788 string trypath = owner->buffer()->filepath;
2789 // If directory is writeable, use this as default.
2790 if (IsDirWriteable(trypath) == 1)
2795 ProhibitInput(owner->view());
2796 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
2797 fileDlg.SetButton(1, _("Examples"),
2798 AddPath(system_lyxdir, "examples"));
2799 string filename = fileDlg.Select(_("Select Document to Open"),
2801 AllowInput(owner->view());
2803 // check selected filename
2804 if (filename.empty()) {
2805 owner->getMiniBuffer()->Set(_("Canceled."));
2809 // get absolute path of file and make sure the filename ends
2811 filename = MakeAbsPath(filename);
2812 if (!IsLyXFilename(filename))
2816 owner->getMiniBuffer()->Set(_("Opening document"),
2817 MakeDisplayPath(filename), "...");
2818 Buffer * openbuf = bufferlist.loadLyXFile(filename);
2820 owner->view()->buffer(openbuf);
2821 owner->getMiniBuffer()->Set(_("Document"),
2822 MakeDisplayPath(filename),
2825 owner->getMiniBuffer()->Set(_("Could not open document"),
2826 MakeDisplayPath(filename));
2830 // returns filename if file must be imported,
2831 // empty string if either file not found or already loaded
2832 // checks for running without gui are missing.
2834 void LyXFunc::doImportHelper(
2835 string const & file, // filename (possibly empty)
2836 string const & text, // info when asking for filename
2837 string const & pattern, // filetype
2838 bool func(BufferView *, string const &) // the real import function
2841 string filename = file;
2843 if (filename.empty()) { // need user interaction
2844 string initpath = lyxrc.document_path;
2847 if (owner->view()->available()) {
2848 string trypath = owner->buffer()->filepath;
2849 // If directory is writeable, use this as default.
2850 if (IsDirWriteable(trypath) == 1)
2855 ProhibitInput(owner->view());
2856 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
2857 fileDlg.SetButton(1, _("Examples"),
2858 AddPath(system_lyxdir, "examples"));
2859 filename = fileDlg.Select(text, initpath, pattern);
2860 AllowInput(owner->view());
2862 // check selected filename
2863 if (filename.empty())
2864 owner->getMiniBuffer()->Set(_("Canceled."));
2867 // still no filename? abort
2868 if (filename.empty())
2871 // get absolute path of file
2872 filename = MakeAbsPath(filename);
2874 string lyxfile = ChangeExtension(filename, ".lyx");
2876 // Check if the document already is open
2877 if (bufferlist.exists(lyxfile)) {
2878 switch(AskConfirmation(_("Document is already open:"),
2879 MakeDisplayPath(lyxfile, 50),
2880 _("Do you want to close that document now?\n"
2881 "('No' will just switch to the open version)")))
2883 case 1: // Yes: close the document
2884 if (!bufferlist.close(bufferlist.getBuffer(lyxfile)))
2885 // If close is canceled, we cancel here too.
2888 case 2: // No: switch to the open document
2889 owner->view()->buffer(bufferlist.getBuffer(lyxfile));
2891 case 3: // Cancel: Do nothing
2892 owner->getMiniBuffer()->Set(_("Canceled."));
2897 // Check if a LyX document by the same root exists in filesystem
2898 FileInfo f(lyxfile, true);
2899 if (f.exist() && !AskQuestion(_("A document by the name"),
2900 MakeDisplayPath(lyxfile),
2901 _("already exists. Overwrite?"))) {
2902 owner->getMiniBuffer()->Set(_("Canceled."));
2905 // filename should be valid now
2907 // notify user of import ahead
2908 string displaypath = MakeDisplayPath(filename);
2909 owner->view()->buffer(bufferlist.newFile(lyxfile, string()));
2910 owner->getMiniBuffer()->Set(_("Importing"), displaypath, "...");
2912 // call real importer
2913 bool result = func(owner->view(), filename);
2917 owner->getMiniBuffer()->Set(displaypath, _("imported."));
2919 owner->getMiniBuffer()->Set(displaypath, _(": import failed."));
2923 bool doImportASCIIasLines(BufferView * view, string const & filename)
2925 InsertAsciiFile(view, filename, false);
2930 bool doImportASCIIasParagraphs(BufferView * view, string const & filename)
2932 InsertAsciiFile(view, filename, true);
2937 bool doImportLaTeX(BufferView *, string const & filename)
2939 ImportLaTeX myImport(filename);
2940 Buffer * openbuf = myImport.run();
2941 return openbuf != NULL;
2945 bool doImportNoweb(BufferView *, string const & filename)
2947 ImportNoweb myImport(filename);
2948 Buffer * openbuf = myImport.run();
2949 return openbuf != NULL;
2953 bool doImportLinuxDoc(BufferView *, string const & filename)
2956 string tmp = lyxrc.linuxdoc_to_lyx_command + filename;
2960 int result = one.startscript(Systemcalls::System, tmp);
2962 string filename = ChangeExtension(filename, ".lyx");
2963 // File was generated without problems. Load it.
2964 buf = bufferlist.loadLyXFile(filename);
2971 void LyXFunc::MenuInsertLyXFile(string const & filen)
2973 string filename = filen;
2975 if (filename.empty()) {
2976 // Launch a file browser
2977 string initpath = lyxrc.document_path;
2980 if (owner->view()->available()) {
2981 string trypath = owner->buffer()->filepath;
2982 // If directory is writeable, use this as default.
2983 if (IsDirWriteable(trypath) == 1)
2988 ProhibitInput(owner->view());
2989 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
2990 fileDlg.SetButton(1, _("Examples"),
2991 AddPath(system_lyxdir, "examples"));
2992 filename = fileDlg.Select(_("Select Document to Insert"),
2994 AllowInput(owner->view());
2996 // check selected filename
2997 if (filename.empty()) {
2998 owner->getMiniBuffer()->Set(_("Canceled."));
3003 // get absolute path of file and make sure the filename ends
3005 filename = MakeAbsPath(filename);
3006 if (!IsLyXFilename(filename))
3010 owner->getMiniBuffer()->Set(_("Inserting document"),
3011 MakeDisplayPath(filename), "...");
3012 bool res = owner->view()->insertLyXFile(filename);
3014 owner->getMiniBuffer()->Set(_("Document"),
3015 MakeDisplayPath(filename),
3018 owner->getMiniBuffer()->Set(_("Could not insert document"),
3019 MakeDisplayPath(filename));
3023 void LyXFunc::doImport(string const & argument)
3026 string filename = split(argument, type, ' ');
3027 lyxerr.debug() << "LyXFunc::doImport: " << type
3028 << " file: " << filename << endl;
3030 if (type == "latex")
3031 doImportHelper(filename,
3032 _("Select LaTeX file to import"), "*.tex",
3034 else if (type == "ascii")
3035 doImportHelper(filename,
3036 _("Select ASCII file to import"), "*.txt",
3037 doImportASCIIasLines);
3038 else if (type == "asciiparagraph")
3039 doImportHelper(filename,
3040 _("Select ASCII file to import"), "*.txt",
3041 doImportASCIIasParagraphs);
3042 else if (type == "noweb")
3043 doImportHelper(filename,
3044 _("Select NoWeb file to import"), "*.nw",
3046 else if (type == "linuxdoc")
3047 doImportHelper(filename,
3048 _("Select LinuxDoc file to import"), "*.doc",
3051 setErrorMessage(string(N_("Unknown import type: ")) + type);
3054 void LyXFunc::reloadBuffer()
3056 string fn = owner->buffer()->fileName();
3057 if (bufferlist.close(owner->buffer()))
3058 owner->view()->buffer(bufferlist.loadLyXFile(fn));
3062 void LyXFunc::CloseBuffer()
3064 if (bufferlist.close(owner->buffer()) && !quitting) {
3065 if (bufferlist.empty()) {
3066 // need this otherwise SEGV may occur while trying to
3067 // set variables that don't exist
3068 // since there's no current buffer
3069 CloseAllBufferRelatedPopups();
3072 owner->view()->buffer(bufferlist.first());
3078 Inset * LyXFunc::getInsetByCode(Inset::Code code)
3080 LyXCursor cursor = owner->view()->text->cursor;
3081 Buffer * buffer = owner->view()->buffer();
3082 for (Buffer::inset_iterator it = Buffer::inset_iterator(cursor.par,
3084 it != buffer->inset_iterator_end(); ++it) {
3085 if ((*it)->LyxCode() == code)
3092 // Each "owner" should have it's own message method. lyxview and
3093 // the minibuffer would use the minibuffer, but lyxserver would
3094 // send an ERROR signal to its client. Alejandro 970603
3095 // This func is bit problematic when it comes to NLS, to make the
3096 // lyx servers client be language indepenent we must not translate
3097 // strings sent to this func.
3098 void LyXFunc::setErrorMessage(string const & m) const
3100 dispatch_buffer = m;
3105 void LyXFunc::setMessage(string const & m)
3107 dispatch_buffer = m;