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/insetnumber.h"
54 #include "insets/insetert.h"
55 #include "insets/insetgraphics.h"
56 #include "insets/insetfoot.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
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.clear();
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.clear();
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) {
537 || (action == LFUN_UNKNOWN_ACTION
538 && keyseq.length >= -1)) {
539 if (action == LFUN_UNKNOWN_ACTION
540 && argument.empty()) {
541 argument = keyseq.getiso();
543 // Undo/Redo pre 0.13 is a bit tricky for insets.
544 if (action == LFUN_UNDO) {
546 UpdatableInset * inset =
547 owner->view()->the_locking_inset;
548 inset->GetCursorPos(slx, sly);
549 owner->view()->unlockInset(inset);
550 owner->view()->menuUndo();
551 if (owner->view()->text->cursor.par->
552 IsInset(owner->view()->text->cursor.pos)) {
553 inset = static_cast<UpdatableInset*>(
554 owner->view()->text->cursor.par->
555 GetInset(owner->view()->text->
561 inset->Edit(owner->view(),slx,sly,0);
563 } else if (action == LFUN_REDO) {
565 UpdatableInset * inset = owner->view()->
567 inset->GetCursorPos(slx, sly);
568 owner->view()->unlockInset(inset);
569 owner->view()->menuRedo();
570 inset = static_cast<UpdatableInset*>(
571 owner->view()->text->cursor.par->
572 GetInset(owner->view()->text->
575 inset->Edit(owner->view(),slx,sly,0);
577 } else if (owner->view()->the_locking_inset->
578 LocalDispatch(owner->view(), action,
580 UpdatableInset::DISPATCHED)
583 setMessage(N_("Text mode"));
585 case LFUN_UNKNOWN_ACTION:
586 case LFUN_BREAKPARAGRAPH:
588 owner->view()->text->CursorRight();
589 owner->view()->setState();
590 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
593 if (!owner->view()->text->cursor.par->isRightToLeftPar()) {
594 owner->view()->text->CursorRight();
595 moveCursorUpdate(false);
596 owner->getMiniBuffer()->
597 Set(CurrentState(owner->view()));
601 if (owner->view()->text->cursor.par->isRightToLeftPar()) {
602 owner->view()->text->CursorRight();
603 moveCursorUpdate(false);
604 owner->getMiniBuffer()->
605 Set(CurrentState(owner->view()));
616 // --- Misc -------------------------------------------
617 case LFUN_WORDFINDFORWARD :
618 case LFUN_WORDFINDBACKWARD : {
619 static string last_search;
620 string searched_string;
622 if (!argument.empty()) {
623 last_search = argument;
624 searched_string = argument;
626 searched_string = last_search;
629 LyXText * ltCur = owner->view()->text ;
631 if (!searched_string.empty() &&
632 ((action == LFUN_WORDFINDBACKWARD) ?
633 ltCur->SearchBackward(searched_string.c_str()) :
634 ltCur->SearchForward(searched_string.c_str()))) {
636 // ??? What is that ???
637 owner->view()->update(-2);
640 // clear the selection (if there is any)
641 owner->view()->toggleSelection();
642 owner->view()->text->ClearSelection();
644 // Move cursor so that successive C-s 's will not stand in place.
645 if( action == LFUN_WORDFINDFORWARD )
646 owner->view()->text->CursorRightOneWord();
647 owner->view()->text->FinishUndo();
648 moveCursorUpdate(false);
651 // set the new selection
652 // SetSelectionOverLenChars(owner->view()->currentBuffer()->text, iLenSelected);
653 owner->view()->toggleSelection(false);
657 // REMOVED : if (owner->view()->getWorkArea()->focus)
658 owner->view()->showCursor();
664 if (owner->view()->available()) {
665 owner->view()->update(-2);
668 keyseq.print(buf, true);
669 owner->getMiniBuffer()->Set(buf, string(), string(), 1);
673 // --- Misc -------------------------------------------
674 case LFUN_EXEC_COMMAND:
675 owner->getMiniBuffer()->ExecCommand();
678 case LFUN_CANCEL: // RVDK_PATCH_5
681 if(owner->view()->available())
682 // cancel any selection
683 Dispatch(LFUN_MARK_OFF, 0);
684 setMessage(N_("Cancel"));
687 case LFUN_META_FAKE: // RVDK_PATCH_5
689 meta_fake_bit = Mod1Mask;
691 keyseq.print(buf, true);
692 string res = string("M-") + buf;
693 setMessage(buf); // RVDK_PATCH_5
697 case LFUN_READ_ONLY_TOGGLE:
698 if (owner->buffer()->lyxvc.inUse()) {
699 owner->buffer()->lyxvc.toggleReadOnly();
701 owner->buffer()->setReadonly(
702 !owner->buffer()->isReadonly());
706 case LFUN_CENTER: // this is center and redraw.
707 owner->view()->center();
711 if (owner->view()->available()) {
712 owner->view()->text->toggleAppendix();
713 owner->view()->update(1);
717 // --- Menus -----------------------------------------------
722 case LFUN_MENUNEWTMPLT:
730 case LFUN_CLOSEBUFFER:
735 owner->getMiniBuffer()->Set(_("Saving document"),
736 MakeDisplayPath(owner->buffer()->fileName()),
738 MenuWrite(owner->buffer());
739 //owner->getMiniBuffer()->
740 // Set(_("Document saved as"),
741 // MakeDisplayPath(owner->buffer()->fileName()));
743 //owner->getMiniBuffer()->Set(_("Save failed!"));
747 case LFUN_MENUWRITEAS:
748 MenuWriteAs(owner->buffer());
751 case LFUN_MENURELOAD:
756 PreviewDVI(owner->buffer());
760 PreviewPostscript(owner->buffer());
764 MenuRunLaTeX(owner->buffer());
768 MenuBuildProg(owner->buffer());
772 MenuRunChktex(owner->buffer());
776 CreatePostscript(owner->buffer(), false);
780 MenuPrint(owner->buffer());
784 MenuFax(owner->buffer());
788 MenuExport(owner->buffer(), argument);
793 //needs argument as string
794 string imtyp = argument;
797 if (imtyp == "latex") {
798 doImportLaTeX(false);
801 else if (imtyp == "ascii") {
802 doImportASCII(false);
803 } else if (imtyp == "asciiparagraph") {
806 } else if (imtyp == "noweb") {
808 } else if (imtyp == "linuxdoc") {
811 setErrorMessage(string(N_("Unknown import type: "))
823 if (fd_form_toc->form_toc->visible) {
824 fl_raise_form(fd_form_toc->form_toc);
826 static int ow = -1, oh;
827 fl_show_form(fd_form_toc->form_toc,
829 FL_FREE_SIZE, FL_FULLBORDER,
830 _("Table of Contents"));
832 ow = fd_form_toc->form_toc->w;
833 oh = fd_form_toc->form_toc->h;
835 fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
839 case LFUN_TOC_INSERT:
841 Inset * new_inset = new InsetTOC(owner->buffer());
842 owner->view()->insertInset(new_inset, "Standard", true);
846 case LFUN_LOF_INSERT:
848 Inset * new_inset = new InsetLOF(owner->buffer());
849 owner->view()->insertInset(new_inset, "Standard", true);
853 case LFUN_LOA_INSERT:
855 Inset * new_inset = new InsetLOA(owner->buffer());
856 owner->view()->insertInset(new_inset, "Standard", true);
860 case LFUN_LOT_INSERT:
862 Inset * new_inset = new InsetLOT(owner->buffer());
863 owner->view()->insertInset(new_inset, "Standard", true);
875 case LFUN_INSERT_GRAPHICS:
877 Inset * new_inset = new InsetGraphics;
878 owner->view()->insertInset(new_inset);
883 AutoSave(owner->view());
887 owner->view()->menuUndo();
891 owner->view()->menuRedo();
894 case LFUN_MENUSEARCH:
896 // Ok this is one _very_ bad solution, but I think that some
897 // of this will be rewritten as part of GUI indep anyway.
899 static LyXFindReplace FR_;
900 FR_.StartSearch(owner->view());
906 owner->view()->paste();
907 owner->view()->setState();
910 case LFUN_PASTESELECTION:
913 if (argument == "paragraph") asPara = true;
914 MenuPasteSelection(asPara);
919 owner->view()->cut();
923 owner->view()->copy();
926 case LFUN_LAYOUT_COPY:
927 owner->view()->copyEnvironment();
930 case LFUN_LAYOUT_PASTE:
931 owner->view()->pasteEnvironment();
932 owner->view()->setState();
936 owner->view()->gotoError();
939 case LFUN_REMOVEERRORS:
940 if (owner->view()->removeAutoInsets()) {
941 owner->view()->redraw();
942 owner->view()->fitCursor();
943 owner->view()->updateScrollbar();
948 owner->view()->gotoNote();
952 owner->view()->openStuff();
955 case LFUN_HYPHENATION:
956 owner->view()->hyphenationPoint();
960 owner->view()->ldots();
963 case LFUN_END_OF_SENTENCE:
964 owner->view()->endOfSentenceDot();
967 case LFUN_MENU_SEPARATOR:
968 owner->view()->menuSeparator();
972 owner->view()->hfill();
976 changeDepth(owner->view(), 0);
980 changeDepth(owner->view(), -1);
983 case LFUN_DEPTH_PLUS:
984 changeDepth(owner->view(), 1);
993 owner->view()->setState();
994 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1001 case LFUN_RECONFIGURE:
1002 Reconfigure(owner->view());
1006 if (owner->view()->available()
1007 && !owner->view()->text->selection
1008 && owner->view()->text->cursor.par->footnoteflag
1009 != LyXParagraph::NO_FOOTNOTE)
1010 { // only melt footnotes with FOOTMELT, not margins etc
1011 if(owner->view()->text->cursor.par->footnotekind == LyXParagraph::FOOTNOTE)
1012 Melt(owner->view());
1015 Foot(owner->view());
1016 owner->view()->setState();
1019 case LFUN_MARGINMELT:
1020 if (owner->view()->available()
1021 && !owner->view()->text->selection
1022 && owner->view()->text->cursor.par->footnoteflag
1023 != LyXParagraph::NO_FOOTNOTE) {
1024 // only melt margins
1025 if(owner->view()->text->cursor.par->footnotekind == LyXParagraph::MARGIN)
1026 Melt(owner->view());
1028 Margin(owner->view());
1029 owner->view()->setState();
1032 // --- version control -------------------------------
1033 case LFUN_VC_REGISTER:
1035 if (!owner->buffer()->lyxvc.inUse())
1036 owner->buffer()->lyxvc.registrer();
1040 case LFUN_VC_CHECKIN:
1042 if (owner->buffer()->lyxvc.inUse()
1043 && !owner->buffer()->isReadonly())
1044 owner->buffer()->lyxvc.checkIn();
1048 case LFUN_VC_CHECKOUT:
1050 if (owner->buffer()->lyxvc.inUse()
1051 && owner->buffer()->isReadonly())
1052 owner->buffer()->lyxvc.checkOut();
1056 case LFUN_VC_REVERT:
1058 owner->buffer()->lyxvc.revert();
1064 owner->buffer()->lyxvc.undoLast();
1068 case LFUN_VC_HISTORY:
1070 owner->buffer()->lyxvc.showLog();
1074 // --- buffers ----------------------------------------
1076 case LFUN_FILE_INSERT:
1078 MenuInsertLyXFile(argument);
1082 case LFUN_FILE_INSERT_ASCII:
1084 bool asPara = (argument == "paragraph");
1085 InsertAsciiFile(owner->view(), string(), asPara);
1091 // servercmd: argument must be <file>:<template>
1092 Buffer * tmpbuf = NewLyxFile(argument);
1094 owner->view()->buffer(tmpbuf);
1098 case LFUN_FILE_OPEN:
1099 owner->view()->buffer(bufferlist.loadLyXFile(argument));
1102 case LFUN_LATEX_LOG:
1108 lyxerr.debug() << "LFUN_LAYOUTNO: (arg) " << argument << endl;
1109 int sel = strToInt(argument);
1110 lyxerr.debug() << "LFUN_LAYOUTNO: (sel) "<< sel << endl;
1112 // Should this give a setMessage instead?
1114 return string(); // illegal argument
1116 --sel; // sel 1..., but layout 0...
1118 // Pretend we got the name instead.
1119 Dispatch(int(LFUN_LAYOUT),
1120 textclasslist.NameOfLayout(owner->view()->
1129 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1130 << argument << endl;
1132 // Derive layout number from given argument (string)
1133 // and current buffer's textclass (number). */
1134 LyXTextClassList::ClassList::size_type tclass =
1135 owner->view()->text->bparams->textclass;
1136 pair <bool, LyXTextClass::size_type> layout =
1137 textclasslist.NumberOfLayout(tclass, argument);
1139 // If the entry is obsolete, use the new one instead.
1141 string obs = textclasslist.Style(tclass,layout.second)
1145 textclasslist.NumberOfLayout(tclass, obs);
1148 // see if we found the layout number:
1149 if (!layout.first) {
1150 setErrorMessage(string(N_("Layout ")) + argument +
1155 if (current_layout != layout.second) {
1156 owner->view()->hideCursor();
1157 current_layout = layout.second;
1158 owner->view()->update(-2);
1159 owner->view()->text->
1160 SetLayout(layout.second);
1161 owner->getToolbar()->combox->
1162 select(owner->view()->
1165 owner->view()->update(1);
1166 owner->view()->setState();
1171 case LFUN_LAYOUT_DOCUMENT:
1172 MenuLayoutDocument();
1175 case LFUN_LAYOUT_PARAGRAPH:
1176 MenuLayoutParagraph();
1179 case LFUN_LAYOUT_CHARACTER:
1180 MenuLayoutCharacter();
1183 case LFUN_LAYOUT_TABLE:
1186 if (argument == "true") flag = 1;
1187 MenuLayoutTable(flag);
1191 case LFUN_LAYOUT_PAPER:
1195 case LFUN_LAYOUT_QUOTES:
1199 case LFUN_LAYOUT_PREAMBLE:
1200 MenuLayoutPreamble();
1203 case LFUN_LAYOUT_SAVE_DEFAULT:
1207 case LFUN_DROP_LAYOUTS_CHOICE:
1208 owner->getToolbar()->combox->Show();
1213 Lang(owner->view(), argument);
1214 owner->view()->setState();
1215 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1220 Emph(owner->view());
1221 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1225 Bold(owner->view());
1226 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1230 Noun(owner->view());
1231 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1235 Code(owner->view());
1236 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1240 Sans(owner->view());
1241 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1245 Roman(owner->view());
1246 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1250 StyleReset(owner->view());
1251 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1254 case LFUN_UNDERLINE:
1255 Underline(owner->view());
1256 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1259 case LFUN_FONT_SIZE:
1260 FontSize(owner->view(), argument);
1261 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1264 case LFUN_FONT_STATE:
1265 setMessage(CurrentState(owner->view()));
1268 case LFUN_UPCASE_WORD:
1269 owner->view()->update(-2);
1271 owner->view()->text->ChangeWordCase(LyXText::text_uppercase);
1272 owner->view()->update(1);
1276 case LFUN_LOWCASE_WORD:
1277 owner->view()->update(-2);
1279 owner->view()->text->ChangeWordCase(LyXText::text_lowercase);
1280 owner->view()->update(1);
1284 case LFUN_CAPITALIZE_WORD:
1285 owner->view()->update(-2);
1287 owner->view()->text->ChangeWordCase(LyXText::text_capitalization);
1288 owner->view()->update(1);
1292 case LFUN_INSERT_LABEL:
1293 MenuInsertLabel(argument.c_str());
1296 case LFUN_INSERT_REF:
1300 case LFUN_REFTOGGLE:
1303 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1305 if (inset->getFlag() == InsetRef::REF)
1306 inset->setFlag(InsetRef::PAGE_REF);
1308 inset->setFlag(InsetRef::REF);
1309 owner->view()->updateInset(inset, true);
1311 setErrorMessage(N_("No cross-reference to toggle"));
1318 owner->view()->restorePosition();
1324 string label(argument);
1325 if (label.empty()) {
1327 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1329 label = inset->getContents();
1332 if (!label.empty()) {
1333 owner->view()->savePosition();
1334 owner->view()->gotoLabel(label.c_str());
1339 case LFUN_MENU_OPEN_BY_NAME:
1340 owner->getMenus()->openByName(argument);
1341 break; // RVDK_PATCH_5
1343 case LFUN_SPELLCHECK:
1344 if (lyxrc.isp_command != "none")
1345 ShowSpellChecker(owner->view());
1346 break; // RVDK_PATCH_5
1348 // --- Cursor Movements -----------------------------
1351 LyXText * tmptext = owner->view()->text;
1352 bool is_rtl = tmptext->cursor.par->isRightToLeftPar();
1353 if(!tmptext->mark_set)
1354 owner->view()->beforeChange();
1355 owner->view()->update(-2);
1357 tmptext->CursorLeft();
1358 if (tmptext->cursor.pos < tmptext->cursor.par->Last()
1359 && tmptext->cursor.par->GetChar(tmptext->cursor.pos)
1360 == LyXParagraph::META_INSET
1361 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)
1362 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)->Editable() == Inset::HIGHLY_EDITABLE){
1363 Inset * tmpinset = tmptext->cursor.par->GetInset(tmptext->cursor.pos);
1364 setMessage(tmpinset->EditMessage());
1365 tmpinset->Edit(owner->view(), 0, 0, 0);
1369 tmptext->CursorRight();
1370 owner->view()->text->FinishUndo();
1371 moveCursorUpdate(false);
1372 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1378 // This is soooo ugly. Isn`t it possible to make
1379 // it simpler? (Lgb)
1380 LyXText * txt = owner->view()->text;
1381 bool is_rtl = txt->cursor.par->isRightToLeftPar();
1382 if(!txt->mark_set) owner->view()->beforeChange();
1383 owner->view()->update(-2);
1386 if (txt->cursor.pos < txt->cursor.par->Last()
1387 && txt->cursor.par->GetChar(txt->cursor.pos)
1388 == LyXParagraph::META_INSET
1389 && txt->cursor.par->GetInset(txt->cursor.pos)
1390 && txt->cursor.par->GetInset(txt->cursor.pos)->Editable() == Inset::HIGHLY_EDITABLE) {
1391 Inset * tmpinset = txt->cursor.par->GetInset(txt->cursor.pos);
1392 setMessage(tmpinset->EditMessage());
1393 tmpinset->Edit(owner->view(),
1394 tmpinset->width(owner->view()->painter(),
1395 txt->GetFont(txt->cursor.par,
1403 owner->view()->text->FinishUndo();
1404 moveCursorUpdate(false);
1405 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1410 if(!owner->view()->text->mark_set) owner->view()->beforeChange();
1411 owner->view()->update(-3);
1412 owner->view()->text->CursorUp();
1413 owner->view()->text->FinishUndo();
1414 moveCursorUpdate(false);
1415 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1419 if(!owner->view()->text->mark_set)
1420 owner->view()->beforeChange();
1421 owner->view()->update(-3);
1422 owner->view()->text->CursorDown();
1423 owner->view()->text->FinishUndo();
1424 moveCursorUpdate(false);
1425 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1428 case LFUN_UP_PARAGRAPH:
1429 if(!owner->view()->text->mark_set)
1430 owner->view()->beforeChange();
1431 owner->view()->update(-3);
1432 owner->view()->text->CursorUpParagraph();
1433 owner->view()->text->FinishUndo();
1434 moveCursorUpdate(false);
1435 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1438 case LFUN_DOWN_PARAGRAPH:
1439 if(!owner->view()->text->mark_set)
1440 owner->view()->beforeChange();
1441 owner->view()->update(-3);
1442 owner->view()->text->CursorDownParagraph();
1443 owner->view()->text->FinishUndo();
1444 moveCursorUpdate(false);
1445 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1449 if(!owner->view()->text->mark_set)
1450 owner->view()->beforeChange();
1451 owner->view()->update(-3);
1452 owner->view()->cursorPrevious();
1453 owner->view()->text->FinishUndo();
1454 moveCursorUpdate(false);
1455 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1459 if(!owner->view()->text->mark_set)
1460 owner->view()->beforeChange();
1461 owner->view()->update(-3);
1462 owner->view()->cursorNext();
1463 owner->view()->text->FinishUndo();
1464 moveCursorUpdate(false);
1465 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1469 if(!owner->view()->text->mark_set)
1470 owner->view()->beforeChange();
1471 owner->view()->update(-2);
1472 owner->view()->text->CursorHome();
1473 owner->view()->text->FinishUndo();
1474 moveCursorUpdate(false);
1475 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1479 if(!owner->view()->text->mark_set)
1480 owner->view()->beforeChange();
1481 owner->view()->update(-2);
1482 owner->view()->text->CursorEnd();
1483 owner->view()->text->FinishUndo();
1484 moveCursorUpdate(false);
1485 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1489 if(!owner->view()->text->mark_set)
1490 owner->view()->beforeChange();
1491 owner->view()->update(-2);
1492 owner->view()->text->CursorTab();
1493 owner->view()->text->FinishUndo();
1494 moveCursorUpdate(false);
1495 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1498 case LFUN_WORDRIGHT:
1499 if(!owner->view()->text->mark_set)
1500 owner->view()->beforeChange();
1501 owner->view()->update(-2);
1502 if (owner->view()->text->cursor.par->isRightToLeftPar())
1503 owner->view()->text->CursorLeftOneWord();
1505 owner->view()->text->CursorRightOneWord();
1506 owner->view()->text->FinishUndo();
1507 moveCursorUpdate(false);
1508 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1512 if(!owner->view()->text->mark_set)
1513 owner->view()->beforeChange();
1514 owner->view()->update(-2);
1515 if (owner->view()->text->cursor.par->isRightToLeftPar())
1516 owner->view()->text->CursorRightOneWord();
1518 owner->view()->text->CursorLeftOneWord();
1519 owner->view()->text->FinishUndo();
1520 moveCursorUpdate(false);
1521 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1524 case LFUN_BEGINNINGBUF:
1525 if(!owner->view()->text->mark_set)
1526 owner->view()->beforeChange();
1527 owner->view()->update(-2);
1528 owner->view()->text->CursorTop();
1529 owner->view()->text->FinishUndo();
1530 moveCursorUpdate(false);
1531 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1535 if(!owner->view()->text->mark_set)
1536 owner->view()->beforeChange();
1537 owner->view()->update(-2);
1538 owner->view()->text->CursorBottom();
1539 owner->view()->text->FinishUndo();
1540 moveCursorUpdate(false);
1541 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1545 /* cursor selection ---------------------------- */
1547 owner->view()->update(-2);
1548 if (owner->view()->text->cursor.par->isRightToLeftPar())
1549 owner->view()->text->CursorLeft();
1551 owner->view()->text->CursorRight();
1552 owner->view()->text->FinishUndo();
1553 moveCursorUpdate(true);
1554 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1558 owner->view()->update(-2);
1559 if (owner->view()->text->cursor.par->isRightToLeftPar())
1560 owner->view()->text->CursorRight();
1562 owner->view()->text->CursorLeft();
1563 owner->view()->text->FinishUndo();
1564 moveCursorUpdate(true);
1565 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1569 owner->view()->update(-2);
1570 owner->view()->text->CursorUp();
1571 owner->view()->text->FinishUndo();
1572 moveCursorUpdate(true);
1573 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1577 owner->view()->update(-2);
1578 owner->view()->text->CursorDown();
1579 owner->view()->text->FinishUndo();
1580 moveCursorUpdate(true);
1581 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1584 case LFUN_UP_PARAGRAPHSEL:
1585 owner->view()->update(-2);
1586 owner->view()->text->CursorUpParagraph();
1587 owner->view()->text->FinishUndo();
1588 moveCursorUpdate(true);
1589 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1592 case LFUN_DOWN_PARAGRAPHSEL:
1593 owner->view()->update(-2);
1594 owner->view()->text->CursorDownParagraph();
1595 owner->view()->text->FinishUndo();
1596 moveCursorUpdate(true);
1597 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1601 owner->view()->update(-2);
1602 owner->view()->cursorPrevious();
1603 owner->view()->text->FinishUndo();
1604 moveCursorUpdate(true);
1605 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1609 owner->view()->update(-2);
1610 owner->view()->cursorNext();
1611 owner->view()->text->FinishUndo();
1612 moveCursorUpdate(true);
1613 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1617 owner->view()->update(-2);
1618 owner->view()->text->CursorHome();
1619 owner->view()->text->FinishUndo();
1620 moveCursorUpdate(true);
1621 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1625 owner->view()->update(-2);
1626 owner->view()->text->CursorEnd();
1627 owner->view()->text->FinishUndo();
1628 moveCursorUpdate(true);
1629 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1632 case LFUN_WORDRIGHTSEL:
1633 owner->view()->update(-2);
1634 if (owner->view()->text->cursor.par->isRightToLeftPar())
1635 owner->view()->text->CursorLeftOneWord();
1637 owner->view()->text->CursorRightOneWord();
1638 owner->view()->text->FinishUndo();
1639 moveCursorUpdate(true);
1640 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1643 case LFUN_WORDLEFTSEL:
1644 owner->view()->update(-2);
1645 if (owner->view()->text->cursor.par->isRightToLeftPar())
1646 owner->view()->text->CursorRightOneWord();
1648 owner->view()->text->CursorLeftOneWord();
1649 owner->view()->text->FinishUndo();
1650 moveCursorUpdate(true);
1651 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1654 case LFUN_BEGINNINGBUFSEL:
1655 owner->view()->update(-2);
1656 owner->view()->text->CursorTop();
1657 owner->view()->text->FinishUndo();
1658 moveCursorUpdate(true);
1659 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1662 case LFUN_ENDBUFSEL:
1663 owner->view()->update(-2);
1664 owner->view()->text->CursorBottom();
1665 owner->view()->text->FinishUndo();
1666 moveCursorUpdate(true);
1667 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1670 // --- text changing commands ------------------------
1671 case LFUN_BREAKLINE:
1673 owner->view()->beforeChange();
1674 owner->view()->text->InsertChar(LyXParagraph::META_NEWLINE);
1675 owner->view()->smallUpdate(1);
1676 SetUpdateTimer(0.01);
1677 moveCursorUpdate(false);
1679 owner->view()->newline();
1683 case LFUN_PROTECTEDSPACE:
1686 LyXLayout const & style =
1687 textclasslist.Style(owner->view()->buffer()->params.textclass,
1688 owner->view()->text->cursor.par->GetLayout());
1690 if (style.free_spacing) {
1691 owner->view()->text->InsertChar(' ');
1692 owner->view()->update(-1);
1694 owner->view()->protectedBlank();
1696 moveCursorUpdate(false);
1699 owner->view()->beforeChange();
1700 owner->view()->text->
1701 InsertChar(LyXParagraph::META_PROTECTED_SEPARATOR);
1702 owner->view()->smallUpdate(1);
1704 moveCursorUpdate(false);
1709 if(owner->view()->text->mark_set) {
1710 owner->view()->beforeChange();
1711 owner->view()->update(0);
1712 setMessage(N_("Mark removed"));
1714 owner->view()->beforeChange();
1715 owner->view()->text->mark_set = 1;
1716 owner->view()->update(0);
1717 setMessage(N_("Mark set"));
1719 owner->view()->text->sel_cursor =
1720 owner->view()->text->cursor;
1725 if (!owner->view()->text->selection) {
1726 owner->view()->text->Delete();
1727 owner->view()->text->sel_cursor =
1728 owner->view()->text->cursor;
1729 owner->view()->smallUpdate(1);
1730 // It is possible to make it a lot faster still
1731 // just comment out the lone below...
1732 owner->view()->showCursor();
1734 owner->view()->cut();
1737 moveCursorUpdate(false);
1738 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1739 owner->view()->setState();
1742 case LFUN_DELETE_SKIP:
1744 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1746 LyXCursor cursor = owner->view()->text->cursor;
1749 if (!owner->view()->text->selection) {
1750 if (cursor.pos == cursor.par->Last()) {
1751 owner->view()->text->CursorRight();
1752 cursor = owner->view()->text->cursor;
1754 && !(cursor.par->added_space_top
1755 == VSpace (VSpace::NONE))) {
1756 owner->view()->text->SetParagraph
1757 (cursor.par->line_top,
1758 cursor.par->line_bottom,
1759 cursor.par->pagebreak_top,
1760 cursor.par->pagebreak_bottom,
1761 VSpace(VSpace::NONE),
1762 cursor.par->added_space_bottom,
1764 cursor.par->labelwidthstring, 0);
1765 owner->view()->text->CursorLeft();
1766 owner->view()->update (1);
1768 owner->view()->text->CursorLeft();
1769 owner->view()->text->Delete();
1770 owner->view()->text->sel_cursor =
1771 owner->view()->text->cursor;
1772 owner->view()->smallUpdate(1);
1775 owner->view()->text->Delete();
1776 owner->view()->text->sel_cursor =
1777 owner->view()->text->cursor;
1778 owner->view()->smallUpdate(1);
1781 owner->view()->cut();
1787 /* -------> Delete word forward. */
1788 case LFUN_DELETE_WORD_FORWARD:
1789 owner->view()->update(-2);
1791 owner->view()->text->DeleteWordForward();
1792 owner->view()->update( 1 );
1794 moveCursorUpdate(false);
1795 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1798 /* -------> Delete word backward. */
1799 case LFUN_DELETE_WORD_BACKWARD:
1800 owner->view()->update(-2);
1802 owner->view()->text->DeleteWordBackward();
1803 owner->view()->update( 1 );
1805 moveCursorUpdate(false);
1806 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1809 /* -------> Kill to end of line. */
1810 case LFUN_DELETE_LINE_FORWARD:
1812 owner->view()->update(-2);
1813 owner->view()->text->DeleteLineForward();
1814 owner->view()->update( 1 );
1816 moveCursorUpdate(false);
1819 /* -------> Set mark off. */
1821 owner->view()->beforeChange();
1822 owner->view()->update(0);
1823 owner->view()->text->sel_cursor =
1824 owner->view()->text->cursor;
1825 setMessage(N_("Mark off"));
1828 /* -------> Set mark on. */
1830 owner->view()->beforeChange();
1831 owner->view()->text->mark_set = 1;
1832 owner->view()->update( 0 );
1833 owner->view()->text->sel_cursor =
1834 owner->view()->text->cursor;
1835 setMessage(N_("Mark on"));
1838 case LFUN_BACKSPACE:
1841 if (!owner->view()->text->selection) {
1842 if (owner->getIntl()->getTrans()->backspace()) {
1843 owner->view()->text->Backspace();
1844 owner->view()->text->sel_cursor =
1845 owner->view()->text->cursor;
1846 owner->view()->smallUpdate(1);
1847 // It is possible to make it a lot faster still
1848 // just comment out the lone below...
1849 owner->view()->showCursor();
1852 owner->view()->cut();
1855 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1856 owner->view()->setState();
1860 case LFUN_BACKSPACE_SKIP:
1862 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1864 LyXCursor cursor = owner->view()->text->cursor;
1867 if (!owner->view()->text->selection) {
1869 && !(cursor.par->added_space_top
1870 == VSpace (VSpace::NONE))) {
1871 owner->view()->text->SetParagraph
1872 (cursor.par->line_top,
1873 cursor.par->line_bottom,
1874 cursor.par->pagebreak_top,
1875 cursor.par->pagebreak_bottom,
1876 VSpace(VSpace::NONE), cursor.par->added_space_bottom,
1878 cursor.par->labelwidthstring, 0);
1879 owner->view()->update (1);
1881 owner->view()->text->Backspace();
1882 owner->view()->text->sel_cursor
1884 owner->view()->smallUpdate (1);
1887 owner->view()->cut();
1892 case LFUN_BREAKPARAGRAPH:
1894 owner->view()->beforeChange();
1895 owner->view()->text->BreakParagraph(0);
1896 owner->view()->smallUpdate(1);
1897 SetUpdateTimer(0.01);
1898 owner->view()->text->sel_cursor =
1899 owner->view()->text->cursor;
1900 owner->view()->setState();
1901 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1905 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1907 owner->view()->beforeChange();
1908 owner->view()->text->BreakParagraph(1);
1909 owner->view()->smallUpdate(1);
1910 SetUpdateTimer(0.01);
1911 owner->view()->text->sel_cursor =
1912 owner->view()->text->cursor;
1913 owner->view()->setState();
1914 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1918 case LFUN_BREAKPARAGRAPH_SKIP:
1920 // When at the beginning of a paragraph, remove
1921 // indentation and add a "defskip" at the top.
1922 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
1924 LyXCursor cursor = owner->view()->text->cursor;
1926 owner->view()->beforeChange();
1927 if (cursor.pos == 0) {
1928 if (cursor.par->added_space_top == VSpace(VSpace::NONE)) {
1929 owner->view()->text->SetParagraph
1930 (cursor.par->line_top,
1931 cursor.par->line_bottom,
1932 cursor.par->pagebreak_top,
1933 cursor.par->pagebreak_bottom,
1934 VSpace(VSpace::DEFSKIP), cursor.par->added_space_bottom,
1936 cursor.par->labelwidthstring, 1);
1937 owner->view()->update(1);
1941 owner->view()->text->BreakParagraph(0);
1942 owner->view()->smallUpdate(1);
1944 SetUpdateTimer(0.01);
1945 owner->view()->text->sel_cursor = cursor;
1946 owner->view()->setState();
1947 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1951 case LFUN_PARAGRAPH_SPACING:
1953 LyXParagraph * par = owner->view()->text->cursor.par;
1954 Spacing::Space cur_spacing = par->spacing.getSpace();
1955 float cur_value = 1.0;
1956 if (cur_spacing == Spacing::Other) {
1957 cur_value = par->spacing.getValue();
1961 istringstream istr(argument);
1963 istrstream istr(argument.c_str());
1967 Spacing::Space new_spacing = cur_spacing;
1968 float new_value = cur_value;
1970 lyxerr << "Missing argument to `paragraph-spacing'"
1972 } else if (tmp == "single") {
1973 new_spacing = Spacing::Single;
1974 } else if (tmp == "onehalf") {
1975 new_spacing = Spacing::Onehalf;
1976 } else if (tmp == "double") {
1977 new_spacing = Spacing::Double;
1978 } else if (tmp == "other") {
1979 new_spacing = Spacing::Other;
1982 lyxerr << "new_value = " << tmpval << endl;
1985 } else if (tmp == "default") {
1986 new_spacing = Spacing::Default;
1988 lyxerr << _("Unknown spacing argument: ")
1989 << argument << endl;
1991 if (cur_spacing != new_spacing || cur_value != new_value) {
1992 par->spacing.set(new_spacing, new_value);
1993 owner->view()->text->RedoParagraph();
1994 owner->view()->update(-1);
2000 owner->view()->beforeChange();
2001 owner->view()->text->InsertChar('\"'); // This " matches the single quote in the code
2002 owner->view()->smallUpdate(1);
2004 moveCursorUpdate(false);
2010 InsetCommand * new_inset;
2011 if (action == LFUN_HTMLURL)
2012 new_inset = new InsetUrl("htmlurl", "", "");
2014 new_inset = new InsetUrl("url", "", "");
2015 owner->view()->insertInset(new_inset);
2016 new_inset->Edit(owner->view(), 0, 0, 0);
2020 case LFUN_INSET_TEXT:
2022 InsetText * new_inset = new InsetText(owner->buffer());
2023 owner->view()->insertInset(new_inset);
2024 new_inset->Edit(owner->view(), 0, 0, 0);
2028 case LFUN_INSET_NUMBER:
2030 InsetNumber * new_inset = new InsetNumber(owner->buffer());
2031 owner->view()->insertInset(new_inset);
2032 new_inset->Edit(owner->view(), 0, 0, 0);
2036 case LFUN_INSET_ERT:
2038 InsetERT * new_inset = new InsetERT(owner->buffer());
2039 owner->view()->insertInset(new_inset);
2040 new_inset->Edit(owner->view(), 0, 0, 0);
2044 case LFUN_INSET_FOOTNOTE:
2046 InsetFoot * new_inset = new InsetFoot(owner->buffer());
2047 owner->view()->insertInset(new_inset);
2048 new_inset->Edit(owner->view(), 0, 0, 0);
2052 // --- lyxserver commands ----------------------------
2054 case LFUN_CHARATCURSOR:
2056 LyXParagraph::size_type pos =
2057 owner->view()->text->cursor.pos;
2058 if(pos < owner->view()->text->cursor.par->size())
2059 //dispatch_buffer = owner->view()->text->
2060 // cursor.par->text[pos];
2062 owner->view()->text->
2063 cursor.par->GetChar(pos);
2065 dispatch_buffer = "EOF";
2071 tostr(owner->view()->text->cursor.x) + ' '
2072 + tostr(owner->view()->text->cursor.y);
2079 sscanf(argument.c_str(), " %d %ld", &x, &y);
2080 owner->view()->text->SetCursorFromCoordinates(x, y);
2084 case LFUN_GETLAYOUT:
2086 tostr(owner->view()->text->cursor.par->layout);
2091 LyXFont & font = owner->view()->text->current_font;
2092 if(font.shape() == LyXFont::ITALIC_SHAPE)
2093 dispatch_buffer = 'E';
2094 else if(font.shape() == LyXFont::SMALLCAPS_SHAPE)
2095 dispatch_buffer = 'N';
2097 dispatch_buffer = '0';
2104 LyXFont & font = owner->view()->text->current_font;
2105 if(font.latex() == LyXFont::ON)
2106 dispatch_buffer = 'L';
2108 dispatch_buffer = '0';
2113 setMessage(owner->buffer()->fileName());
2114 lyxerr.debug() << "FNAME["
2115 << owner->buffer()->fileName()
2123 dispatch_buffer = buf;
2124 lyxserver->notifyClient(dispatch_buffer);
2128 case LFUN_GOTOFILEROW:
2130 char file_name[100];
2132 sscanf(argument.c_str(), " %s %d", file_name, &row);
2134 // Must replace extension of the file to be .lyx and get full path
2135 string s = ChangeExtension(string(file_name), ".lyx", false);
2137 // Either change buffer or load the file
2138 if (bufferlist.exists(s))
2139 owner->view()->buffer(bufferlist.getBuffer(s));
2141 owner->view()->buffer(bufferlist.loadLyXFile(s));
2144 owner->view()->setCursorFromRow(row);
2147 owner->view()->center();
2154 int qa = lyxaction.LookupFunc(argument.c_str());
2155 setMessage(lyxaction.helpText(static_cast<kb_action>(qa)));
2159 // --- accented characters ---------------------------
2162 case LFUN_CIRCUMFLEX:
2172 case LFUN_SPECIAL_CARON:
2175 case LFUN_HUNG_UMLAUT:
2181 if (keyseq.length == -1 && keyseq.getiso() != 0)
2182 c = keyseq.getiso();
2186 owner->getIntl()->getTrans()->
2187 deadkey(c, get_accent(action).accent,
2188 owner->view()->text);
2190 // Need to reset, in case the minibuffer calls these
2195 // copied verbatim from do_accent_char
2196 owner->view()->smallUpdate(1);
2198 owner->view()->text->sel_cursor =
2199 owner->view()->text->cursor;
2203 // --- toolbar ----------------------------------
2204 case LFUN_PUSH_TOOLBAR:
2206 int nth = strToInt(argument);
2207 if (lyxerr.debugging(Debug::TOOLBAR)) {
2208 lyxerr << "LFUN_PUSH_TOOLBAR: argument = `"
2209 << argument << "'\n"
2210 << "LFUN_PUSH_TOOLBAR: nth = `"
2211 << nth << "'" << endl;
2216 setErrorMessage(N_("Push-toolbar needs argument > 0"));
2218 owner->getToolbar()->push(nth);
2223 case LFUN_ADD_TO_TOOLBAR:
2225 if (lyxerr.debugging(Debug::TOOLBAR)) {
2226 lyxerr << "LFUN_ADD_TO_TOOLBAR:"
2227 "argument = `" << argument << '\'' << endl;
2229 string tmp(argument);
2230 //lyxerr <<string("Argument: ") + argument);
2231 //lyxerr <<string("Tmp : ") + tmp);
2234 setErrorMessage(N_("Usage: toolbar-add-to <LyX command>"));
2236 owner->getToolbar()->add(argument, false);
2237 owner->getToolbar()->set();
2242 // --- insert characters ----------------------------------------
2244 // --- Mathed stuff. If we are here, there is no locked inset yet.
2249 if (!greek_kb_flag) {
2251 setMessage(N_("Math greek mode on"));
2258 case LFUN_GREEK_TOGGLE:
2260 greek_kb_flag = greek_kb_flag ? 0 : 2;
2261 if (greek_kb_flag) {
2262 setMessage(N_("Math greek keyboard on"));
2264 setMessage(N_("Math greek keyboard off"));
2269 case LFUN_MATH_DELIM:
2270 case LFUN_INSERT_MATRIX:
2272 if (owner->view()->available()) {
2274 open_new_inset(new InsetFormula(false));
2277 ->LocalDispatch(owner->view(),
2284 case LFUN_INSERT_MATH:
2286 math_insert_symbol(argument.c_str());
2290 case LFUN_MATH_DISPLAY:
2292 if (owner->view()->available())
2293 owner->view()->open_new_inset(new InsetFormula(true));
2297 case LFUN_MATH_MACRO:
2299 if (owner->view()->available()) {
2302 setErrorMessage(N_("Missing argument"));
2304 string s1 = token(s, ' ', 1);
2305 int na = s1.empty() ? 0: atoi(s1.c_str());
2307 open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2313 case LFUN_MATH_MODE: // Open or create a math inset
2316 if (owner->view()->available())
2317 owner->view()->open_new_inset(new InsetFormula);
2318 setMessage(N_("Math editor mode"));
2322 case LFUN_MATH_NUMBER:
2323 case LFUN_MATH_LIMITS:
2325 setErrorMessage(N_("This is only allowed in math mode!"));
2329 case LFUN_INSERT_CITATION:
2331 InsetCitation * new_inset = new InsetCitation();
2333 // The note, if any, must be after the key, delimited
2334 // by a | so both key and remark can have spaces.
2335 if (!argument.empty()) {
2336 string lsarg(argument);
2337 if (contains(lsarg, "|")) {
2338 new_inset->setContents(token(lsarg, '|', 0));
2339 new_inset->setOptions(token(lsarg, '|', 1));
2341 new_inset->setContents(lsarg);
2342 owner->view()->insertInset(new_inset);
2344 owner->view()->insertInset(new_inset);
2345 new_inset->Edit(owner->view(), 0, 0, 0);
2350 case LFUN_INSERT_BIBTEX:
2352 // ale970405+lasgoutt970425
2353 // The argument can be up to two tokens separated
2354 // by a space. The first one is the bibstyle.
2355 string lsarg(argument);
2356 string bibstyle = token(lsarg, ' ', 1);
2357 if (bibstyle.empty())
2359 InsetBibtex * new_inset
2360 = new InsetBibtex(token(lsarg, ' ', 0),
2364 owner->view()->insertInset(new_inset);
2365 if (lsarg.empty()) {
2366 new_inset->Edit(owner->view(), 0, 0, 0);
2371 // BibTeX data bases
2372 case LFUN_BIBDB_ADD:
2374 InsetBibtex * inset =
2375 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2377 inset->addDatabase(argument);
2382 case LFUN_BIBDB_DEL:
2384 InsetBibtex * inset =
2385 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2387 inset->delDatabase(argument);
2392 case LFUN_BIBTEX_STYLE:
2394 InsetBibtex * inset =
2395 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2397 inset->setOptions(argument);
2402 case LFUN_INDEX_INSERT:
2403 case LFUN_INDEX_INSERT_LAST:
2405 // Can't do that at the beginning of a paragraph.
2406 if (owner->view()->text->cursor.pos - 1 < 0)
2409 InsetIndex * new_inset = new InsetIndex();
2410 if (!argument.empty()) {
2411 string lsarg(argument);
2412 new_inset->setContents(lsarg);
2413 owner->view()->insertInset(new_inset);
2416 //get the current word for an argument
2417 LyXParagraph::size_type lastpos =
2418 owner->view()->text->cursor.pos - 1;
2419 // Get the current word. note that this must be done
2420 // before inserting the inset, or the inset will
2422 string curstring(owner->view()
2423 ->text->cursor.par->GetWord(lastpos));
2425 //make the new inset and write the current word into it
2426 InsetIndex * new_inset = new InsetIndex();
2428 new_inset->setContents(curstring);
2430 //don't edit it if the call was to INSERT_LAST
2431 if(action != LFUN_INDEX_INSERT_LAST) {
2432 new_inset->Edit(owner->view(), 0, 0, 0);
2434 //it looks blank on the screen unless
2435 //we do something. put it here.
2437 // move the cursor to the returned value of lastpos
2438 // but only for the auto-insert
2439 owner->view()->text->cursor.pos = lastpos;
2442 //put the new inset into the buffer.
2443 // there should be some way of knowing the user
2444 //cancelled & avoiding this, but i don't know how
2445 owner->view()->insertInset(new_inset);
2450 case LFUN_INDEX_PRINT:
2452 Inset * new_inset = new InsetPrintIndex(owner->buffer());
2453 owner->view()->insertInset(new_inset, "Standard", true);
2457 case LFUN_PARENTINSERT:
2459 lyxerr << "arg " << argument << endl;
2460 Inset * new_inset = new InsetParent(argument, owner->buffer());
2461 owner->view()->insertInset(new_inset, "Standard", true);
2465 case LFUN_CHILDINSERT:
2467 Inset * new_inset = new InsetInclude(argument,
2469 owner->view()->insertInset(new_inset, "Standard", true);
2470 new_inset->Edit(owner->view(), 0, 0, 0);
2474 case LFUN_CHILDOPEN:
2477 MakeAbsPath(argument,
2478 OnlyPath(owner->buffer()->fileName()));
2479 setMessage(N_("Opening child document ") +
2480 MakeDisplayPath(filename) + "...");
2481 owner->view()->savePosition();
2482 if (bufferlist.exists(filename))
2483 owner->view()->buffer(bufferlist.getBuffer(filename));
2485 owner->view()->buffer(bufferlist.loadLyXFile(filename));
2489 case LFUN_INSERT_NOTE:
2490 owner->view()->insertNote();
2493 case LFUN_INSERTFOOTNOTE:
2495 LyXParagraph::footnote_kind kind;
2496 if (argument == "footnote")
2497 { kind = LyXParagraph::FOOTNOTE; }
2498 else if (argument == "margin")
2499 { kind = LyXParagraph::MARGIN; }
2500 else if (argument == "figure")
2501 { kind = LyXParagraph::FIG; }
2502 else if (argument == "table")
2503 { kind = LyXParagraph::TAB; }
2504 else if (argument == "wide-fig")
2505 { kind = LyXParagraph::WIDE_FIG; }
2506 else if (argument == "wide-tab")
2507 { kind = LyXParagraph::WIDE_TAB; }
2508 else if (argument == "algorithm")
2509 { kind = LyXParagraph::ALGORITHM; }
2511 setErrorMessage(N_("Unknown kind of footnote"));
2514 owner->view()->text->InsertFootnoteEnvironment(kind);
2515 owner->view()->update(1);
2516 owner->view()->setState();
2520 case LFUN_BUFFERBULLETSSELECT:
2524 case LFUN_TOGGLECURSORFOLLOW:
2525 cursor_follows_scrollbar = !cursor_follows_scrollbar;
2528 case LFUN_KMAP_OFF: // keymap off
2529 owner->getIntl()->KeyMapOn(false);
2532 case LFUN_KMAP_PRIM: // primary keymap
2533 owner->getIntl()->KeyMapPrim();
2536 case LFUN_KMAP_SEC: // secondary keymap
2537 owner->getIntl()->KeyMapSec();
2540 case LFUN_KMAP_TOGGLE: // toggle keymap
2541 owner->getIntl()->ToggleKeyMap();
2544 case LFUN_SELFINSERT:
2546 for (string::size_type i = 0; i < argument.length(); ++i) {
2547 owner->view()->text->InsertChar(argument[i]);
2548 // This needs to be in the loop, or else we
2549 // won't break lines correctly. (Asger)
2550 owner->view()->smallUpdate(1);
2553 owner->view()->text->sel_cursor =
2554 owner->view()->text->cursor;
2555 moveCursorUpdate(false);
2561 // argument contains ';'-terminated commands
2562 while (argument.find(';') != string::npos) {
2564 argument = split(argument, first, ';');
2570 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
2578 now_time_t = time(NULL);
2579 now_tm = localtime(&now_time_t);
2580 (void)setlocale(LC_TIME, "");
2581 if (!argument.empty())
2583 else if (arg.empty())
2584 arg = lyxrc.date_insert_format;
2585 datetmp_len = (int) strftime(datetmp, 32, arg.c_str(), now_tm);
2586 for (int i = 0; i < datetmp_len; i++) {
2587 owner->view()->text->InsertChar(datetmp[i]);
2588 owner->view()->smallUpdate(1);
2591 owner->view()->text->sel_cursor = owner->view()->text->cursor;
2592 moveCursorUpdate(false);
2596 case LFUN_SAVEPREFERENCES:
2598 Path p(user_lyxdir);
2599 lyxrc.write("preferences");
2603 case LFUN_UNKNOWN_ACTION:
2605 if(!owner->buffer()) {
2607 setErrorMessage(N_("No document open"));
2611 if (owner->buffer()->isReadonly()) {
2613 setErrorMessage(N_("Document is read only"));
2617 if (!argument.empty()) {
2619 /* Automatically delete the currently selected
2620 * text and replace it with what is being
2621 * typed in now. Depends on lyxrc settings
2622 * "auto_region_delete", which defaults to
2625 if ( lyxrc.auto_region_delete ) {
2626 if (owner->view()->text->selection){
2627 owner->view()->text->CutSelection(false);
2628 owner->view()->update(-1);
2632 owner->view()->beforeChange();
2635 if (isdigit(argument[0]) &&
2636 (lyxrc.number_inset == "true" ||
2637 (lyxrc.number_inset == "rtl" &&
2638 owner->view()->text->real_current_font.isVisibleRightToLeft()
2640 UpdatableInset * tmpinset = new InsetNumber(owner->buffer());
2641 owner->view()->open_new_inset(tmpinset);
2642 tmpinset->LocalDispatch(owner->view(), action,
2648 for (string::size_type i = 0;
2649 i < argument.length(); ++i) {
2650 if (greek_kb_flag) {
2651 if (!math_insert_greek(argument[i]))
2652 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2654 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2657 owner->view()->smallUpdate(1);
2660 owner->view()->text->sel_cursor =
2661 owner->view()->text->cursor;
2662 moveCursorUpdate(false);
2665 // why is an "Unknown action" with empty
2666 // argument even dispatched in the first
2667 // place? I`ll probably change that. (Lgb)
2669 setErrorMessage(N_("Unknown action"));
2673 lyxerr << "A truly unknown func!" << endl;
2679 string res = getMessage();
2682 if (!commandshortcut.empty()) {
2683 string newbuf = owner->getMiniBuffer()->GetText();
2684 if (newbuf != commandshortcut) {
2685 owner->getMiniBuffer()->Set(newbuf
2691 owner->getMiniBuffer()->Set(string(_(res.c_str()))
2692 + " " + commandshortcut);
2699 void LyXFunc::setupLocalKeymap()
2701 keyseq.stdmap = keyseq.curmap = toplevel_keymap;
2702 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap;
2706 void LyXFunc::MenuNew(bool fromTemplate)
2708 string fname, initpath = lyxrc.document_path;
2711 if (owner->view()->available()) {
2712 string trypath = owner->buffer()->filepath;
2713 // If directory is writeable, use this as default.
2714 if (IsDirWriteable(trypath) == 1)
2718 ProhibitInput(owner->view());
2719 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
2720 fileDlg.SetButton(1, _("Templates"), lyxrc.template_path);
2721 fname = fileDlg.Select(_("Enter Filename for new document"),
2722 initpath, "*.lyx", _("newfile"));
2723 AllowInput(owner->view());
2725 if (fname.empty()) {
2726 owner->getMiniBuffer()->Set(_("Canceled."));
2727 lyxerr.debug() << "New Document Cancelled." << endl;
2731 // get absolute path of file and make sure the filename ends
2733 string s = MakeAbsPath(fname);
2734 if (!IsLyXFilename(s))
2737 // Check if the document already is open
2738 if (bufferlist.exists(s)){
2739 switch(AskConfirmation(_("Document is already open:"),
2740 MakeDisplayPath(s, 50),
2741 _("Do you want to close that document now?\n"
2742 "('No' will just switch to the open version)")))
2744 case 1: // Yes: close the document
2745 if (!bufferlist.close(bufferlist.getBuffer(s)))
2746 // If close is canceled, we cancel here too.
2749 case 2: // No: switch to the open document
2750 owner->view()->buffer(bufferlist.getBuffer(s));
2752 case 3: // Cancel: Do nothing
2753 owner->getMiniBuffer()->Set(_("Canceled."));
2758 // Check whether the file already exists
2759 if (IsLyXFilename(s)) {
2761 if (fi.readable() &&
2762 AskQuestion(_("File already exists:"),
2763 MakeDisplayPath(s, 50),
2764 _("Do you want to open the document?"))) {
2766 owner->getMiniBuffer()->Set(_("Opening document"),
2767 MakeDisplayPath(s), "...");
2769 owner->view()->buffer(
2770 bufferlist.loadLyXFile(s));
2771 owner->getMiniBuffer()->Set(_("Document"),
2778 // The template stuff
2781 ProhibitInput(owner->view());
2782 fname = fileDlg.Select(_("Choose template"),
2783 lyxrc.template_path,
2786 AllowInput(owner->view());
2789 // find a free buffer
2790 lyxerr.debug() << "Find a free buffer." << endl;
2791 owner->view()->buffer(bufferlist.newFile(s, templname));
2795 void LyXFunc::MenuOpen()
2797 string initpath = lyxrc.document_path;
2800 if (owner->view()->available()) {
2801 string trypath = owner->buffer()->filepath;
2802 // If directory is writeable, use this as default.
2803 if (IsDirWriteable(trypath) == 1)
2808 ProhibitInput(owner->view());
2809 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
2810 fileDlg.SetButton(1, _("Examples"),
2811 AddPath(system_lyxdir, "examples"));
2812 string filename = fileDlg.Select(_("Select Document to Open"),
2814 AllowInput(owner->view());
2816 // check selected filename
2817 if (filename.empty()) {
2818 owner->getMiniBuffer()->Set(_("Canceled."));
2822 // get absolute path of file and make sure the filename ends
2824 filename = MakeAbsPath(filename);
2825 if (!IsLyXFilename(filename))
2829 owner->getMiniBuffer()->Set(_("Opening document"),
2830 MakeDisplayPath(filename), "...");
2831 Buffer * openbuf = bufferlist.loadLyXFile(filename);
2833 owner->view()->buffer(openbuf);
2834 owner->getMiniBuffer()->Set(_("Document"),
2835 MakeDisplayPath(filename),
2838 owner->getMiniBuffer()->Set(_("Could not open document"),
2839 MakeDisplayPath(filename));
2844 void LyXFunc::doImportASCII(bool linorpar)
2846 string initpath = lyxrc.document_path;
2849 if (owner->view()->available()) {
2850 string trypath = owner->buffer()->filepath;
2851 // If directory is writeable, use this as default.
2852 if (IsDirWriteable(trypath) == 1)
2857 ProhibitInput(owner->view());
2858 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
2859 fileDlg.SetButton(1, _("Examples"),
2860 AddPath(system_lyxdir, "examples"));
2861 string filename = fileDlg.Select(_("Select ASCII file to Import"),
2863 AllowInput(owner->view());
2865 // check selected filename
2866 if (filename.empty()) {
2867 owner->getMiniBuffer()->Set(_("Canceled."));
2871 // get absolute path of file
2872 filename = MakeAbsPath(filename);
2874 string s = ChangeExtension(filename, ".lyx", false);
2876 // Check if the document already is open
2877 if (bufferlist.exists(s)) {
2878 switch(AskConfirmation(_("Document is already open:"),
2879 MakeDisplayPath(s, 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(s)))
2885 // If close is canceled, we cancel here too.
2888 case 2: // No: switch to the open document
2889 owner->view()->buffer(bufferlist.getBuffer(s));
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(s, true);
2899 if (f.exist() && !AskQuestion(_("A document by the name"),
2901 _("already exists. Overwrite?"))) {
2902 owner->getMiniBuffer()->Set(_("Canceled."));
2906 owner->view()->buffer(bufferlist.newFile(s, string()));
2907 owner->getMiniBuffer()->Set(_("Importing ASCII file"),
2908 MakeDisplayPath(filename), "...");
2909 // Insert ASCII file
2910 InsertAsciiFile(owner->view(), filename, linorpar);
2911 owner->getMiniBuffer()->Set(_("ASCII file "),
2912 MakeDisplayPath(filename),
2917 void LyXFunc::doImportLaTeX(bool isnoweb)
2919 string initpath = lyxrc.document_path;
2922 if (owner->view()->available()) {
2923 string trypath = owner->buffer()->filepath;
2924 // If directory is writeable, use this as default.
2925 if (IsDirWriteable(trypath) == 1)
2930 ProhibitInput(owner->view());
2931 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
2932 fileDlg.SetButton(1, _("Examples"),
2933 AddPath(system_lyxdir, "examples"));
2936 filename = fileDlg.Select(_("Select Noweb file to Import"),
2939 filename = fileDlg.Select(_("Select LaTeX file to Import"),
2943 AllowInput(owner->view());
2945 // check selected filename
2946 if (filename.empty()) {
2947 owner->getMiniBuffer()->Set(_("Canceled."));
2951 // get absolute path of file
2952 filename = MakeAbsPath(filename);
2954 // Check if the document already is open
2955 string LyXfilename = ChangeExtension(filename, ".lyx", false);
2956 if (bufferlist.exists(LyXfilename)){
2957 switch(AskConfirmation(_("Document is already open:"),
2958 MakeDisplayPath(LyXfilename, 50),
2959 _("Do you want to close that document now?\n"
2960 "('No' will just switch to the open version)")))
2962 case 1: // Yes: close the document
2963 if (!bufferlist.close(bufferlist.getBuffer(LyXfilename)))
2964 // If close is canceled, we cancel here too.
2967 case 2: // No: switch to the open document
2968 owner->view()->buffer(
2969 bufferlist.getBuffer(LyXfilename));
2971 case 3: // Cancel: Do nothing
2972 owner->getMiniBuffer()->Set(_("Canceled."));
2977 // Check if a LyX document by the same root exists in filesystem
2978 FileInfo f(LyXfilename, true);
2979 if (f.exist() && !AskQuestion(_("A document by the name"),
2980 MakeDisplayPath(LyXfilename),
2981 _("already exists. Overwrite?"))) {
2982 owner->getMiniBuffer()->Set(_("Canceled."));
2989 owner->getMiniBuffer()->Set(_("Importing LaTeX file"),
2990 MakeDisplayPath(filename), "...");
2991 ImportLaTeX myImport(filename);
2992 openbuf = myImport.run();
2994 owner->getMiniBuffer()->Set(_("Importing Noweb file"),
2995 MakeDisplayPath(filename), "...");
2996 ImportNoweb myImport(filename);
2997 openbuf = myImport.run();
3000 owner->view()->buffer(openbuf);
3001 owner->getMiniBuffer()->Set(isnoweb ?
3002 _("Noweb file ") : _("LateX file "),
3003 MakeDisplayPath(filename),
3006 owner->getMiniBuffer()->Set(isnoweb ?
3007 _("Could not import Noweb file") :
3008 _("Could not import LaTeX file"),
3009 MakeDisplayPath(filename));
3014 void LyXFunc::doImportLinuxDoc()
3016 string initpath = lyxrc.document_path;
3019 if (owner->view()->available()) {
3020 string trypath = owner->buffer()->filepath;
3021 // If directory is writeable, use this as default.
3022 if (IsDirWriteable(trypath) == 1)
3027 ProhibitInput(owner->view());
3028 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
3029 fileDlg.SetButton(1, _("Examples"),
3030 AddPath(system_lyxdir, "examples"));
3032 string filename = fileDlg.Select(_("Select LinuxDoc file to Import"),
3033 initpath, "*.sgml");
3035 AllowInput(owner->view());
3037 // check selected filename
3038 if (filename.empty()) {
3039 owner->getMiniBuffer()->Set(_("Canceled."));
3043 // get absolute path of file
3044 filename = MakeAbsPath(filename);
3046 // Check if the document already is open
3047 string LyXfilename = ChangeExtension(filename, ".lyx", false);
3048 if (bufferlist.exists(LyXfilename)){
3049 switch(AskConfirmation(_("Document is already open:"),
3050 MakeDisplayPath(LyXfilename, 50),
3051 _("Do you want to close that document now?\n"
3052 "('No' will just switch to the open version)")))
3054 case 1: // Yes: close the document
3055 if (!bufferlist.close(bufferlist.getBuffer(LyXfilename)))
3056 // If close is canceled, we cancel here too.
3059 case 2: // No: switch to the open document
3060 owner->view()->buffer(
3061 bufferlist.getBuffer(LyXfilename));
3063 case 3: // Cancel: Do nothing
3064 owner->getMiniBuffer()->Set(_("Canceled."));
3069 // Check if a LyX document by the same root exists in filesystem
3070 FileInfo f(LyXfilename, true);
3071 if (f.exist() && !AskQuestion(_("A document by the name"),
3072 MakeDisplayPath(LyXfilename),
3073 _("already exists. Overwrite?"))) {
3074 owner->getMiniBuffer()->Set(_("Canceled."));
3079 owner->getMiniBuffer()->Set(_("Importing LinuxDoc file"),
3080 MakeDisplayPath(filename), "...");
3083 string tmp = lyxrc.linuxdoc_to_lyx_command + filename;
3087 int result = one.startscript(Systemcalls::System, tmp);
3089 string filename = ChangeExtension(filename, ".lyx", false);
3090 // File was generated without problems. Load it.
3091 buf = bufferlist.loadLyXFile(filename);
3092 owner->view()->buffer(buf);
3093 owner->getMiniBuffer()->Set(_("LinuxDoc file "),
3094 MakeDisplayPath(filename),
3097 owner->getMiniBuffer()->Set(_("Could not import LinuxDoc file"),
3098 MakeDisplayPath(filename));
3103 void LyXFunc::MenuInsertLyXFile(string const & filen)
3105 string filename = filen;
3107 if (filename.empty()) {
3108 // Launch a file browser
3109 string initpath = lyxrc.document_path;
3112 if (owner->view()->available()) {
3113 string trypath = owner->buffer()->filepath;
3114 // If directory is writeable, use this as default.
3115 if (IsDirWriteable(trypath) == 1)
3120 ProhibitInput(owner->view());
3121 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
3122 fileDlg.SetButton(1, _("Examples"),
3123 AddPath(system_lyxdir, "examples"));
3124 filename = fileDlg.Select(_("Select Document to Insert"),
3126 AllowInput(owner->view());
3128 // check selected filename
3129 if (filename.empty()) {
3130 owner->getMiniBuffer()->Set(_("Canceled."));
3135 // get absolute path of file and make sure the filename ends
3137 filename = MakeAbsPath(filename);
3138 if (!IsLyXFilename(filename))
3142 owner->getMiniBuffer()->Set(_("Inserting document"),
3143 MakeDisplayPath(filename), "...");
3144 bool res = owner->view()->insertLyXFile(filename);
3146 owner->getMiniBuffer()->Set(_("Document"),
3147 MakeDisplayPath(filename),
3150 owner->getMiniBuffer()->Set(_("Could not insert document"),
3151 MakeDisplayPath(filename));
3156 void LyXFunc::reloadBuffer()
3158 string fn = owner->buffer()->fileName();
3159 if (bufferlist.close(owner->buffer()))
3160 owner->view()->buffer(bufferlist.loadLyXFile(fn));
3164 void LyXFunc::CloseBuffer()
3166 if (bufferlist.close(owner->buffer()) && !quitting) {
3167 if (bufferlist.empty()) {
3168 // need this otherwise SEGV may occur while trying to
3169 // set variables that don't exist
3170 // since there's no current buffer
3171 CloseAllBufferRelatedPopups();
3174 owner->view()->buffer(bufferlist.first());
3180 Inset * LyXFunc::getInsetByCode(Inset::Code code)
3184 LyXCursor cursor = owner->view()->text->cursor;
3185 LyXParagraph::size_type pos = cursor.pos;
3186 LyXParagraph * par = cursor.par;
3188 while (par && !found) {
3189 while ((inset = par->ReturnNextInsetPointer(pos))){
3190 if (inset->LyxCode() == code) {
3198 return found ? inset : 0;
3202 // Each "owner" should have it's own message method. lyxview and
3203 // the minibuffer would use the minibuffer, but lyxserver would
3204 // send an ERROR signal to its client. Alejandro 970603
3205 // This func is bit problematic when it comes to NLS, to make the
3206 // lyx servers client be language indepenent we must not translate
3207 // strings sent to this func.
3208 void LyXFunc::setErrorMessage(string const & m) const
3210 dispatch_buffer = m;
3215 void LyXFunc::setMessage(string const & m)
3217 dispatch_buffer = m;