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()
1121 ->buffer()->params.textclass,
1128 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1129 << argument << endl;
1131 // Derive layout number from given argument (string)
1132 // and current buffer's textclass (number). */
1133 LyXTextClassList::ClassList::size_type tclass =
1134 owner->view()->buffer()->params.textclass;
1135 pair <bool, LyXTextClass::size_type> layout =
1136 textclasslist.NumberOfLayout(tclass, argument);
1138 // If the entry is obsolete, use the new one instead.
1140 string obs = textclasslist.Style(tclass,layout.second)
1144 textclasslist.NumberOfLayout(tclass, obs);
1147 // see if we found the layout number:
1148 if (!layout.first) {
1149 setErrorMessage(string(N_("Layout ")) + argument +
1154 if (current_layout != layout.second) {
1155 owner->view()->hideCursor();
1156 current_layout = layout.second;
1157 owner->view()->update(-2);
1158 owner->view()->text->
1159 SetLayout(layout.second);
1160 owner->getToolbar()->combox->
1161 select(owner->view()->
1164 owner->view()->update(1);
1165 owner->view()->setState();
1170 case LFUN_LAYOUT_DOCUMENT:
1171 MenuLayoutDocument();
1174 case LFUN_LAYOUT_PARAGRAPH:
1175 MenuLayoutParagraph();
1178 case LFUN_LAYOUT_CHARACTER:
1179 MenuLayoutCharacter();
1182 case LFUN_LAYOUT_TABLE:
1185 if (argument == "true") flag = 1;
1186 MenuLayoutTable(flag);
1190 case LFUN_LAYOUT_PAPER:
1194 case LFUN_LAYOUT_QUOTES:
1198 case LFUN_LAYOUT_PREAMBLE:
1199 MenuLayoutPreamble();
1202 case LFUN_LAYOUT_SAVE_DEFAULT:
1206 case LFUN_DROP_LAYOUTS_CHOICE:
1207 owner->getToolbar()->combox->Show();
1212 Lang(owner->view(), argument);
1213 owner->view()->setState();
1214 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1219 Emph(owner->view());
1220 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1224 Bold(owner->view());
1225 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1229 Noun(owner->view());
1230 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1234 Code(owner->view());
1235 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1239 Sans(owner->view());
1240 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1244 Roman(owner->view());
1245 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1249 StyleReset(owner->view());
1250 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1253 case LFUN_UNDERLINE:
1254 Underline(owner->view());
1255 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1258 case LFUN_FONT_SIZE:
1259 FontSize(owner->view(), argument);
1260 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1263 case LFUN_FONT_STATE:
1264 setMessage(CurrentState(owner->view()));
1267 case LFUN_UPCASE_WORD:
1268 owner->view()->update(-2);
1270 owner->view()->text->ChangeWordCase(LyXText::text_uppercase);
1271 owner->view()->update(1);
1275 case LFUN_LOWCASE_WORD:
1276 owner->view()->update(-2);
1278 owner->view()->text->ChangeWordCase(LyXText::text_lowercase);
1279 owner->view()->update(1);
1283 case LFUN_CAPITALIZE_WORD:
1284 owner->view()->update(-2);
1286 owner->view()->text->ChangeWordCase(LyXText::text_capitalization);
1287 owner->view()->update(1);
1291 case LFUN_INSERT_LABEL:
1292 MenuInsertLabel(argument.c_str());
1295 case LFUN_INSERT_REF:
1299 case LFUN_REFTOGGLE:
1302 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1304 if (inset->getFlag() == InsetRef::REF)
1305 inset->setFlag(InsetRef::PAGE_REF);
1307 inset->setFlag(InsetRef::REF);
1308 owner->view()->updateInset(inset, true);
1310 setErrorMessage(N_("No cross-reference to toggle"));
1317 owner->view()->restorePosition();
1323 string label(argument);
1324 if (label.empty()) {
1326 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1328 label = inset->getContents();
1331 if (!label.empty()) {
1332 owner->view()->savePosition();
1333 owner->view()->gotoLabel(label.c_str());
1338 case LFUN_MENU_OPEN_BY_NAME:
1339 owner->getMenus()->openByName(argument);
1340 break; // RVDK_PATCH_5
1342 case LFUN_SPELLCHECK:
1343 if (lyxrc.isp_command != "none")
1344 ShowSpellChecker(owner->view());
1345 break; // RVDK_PATCH_5
1347 // --- Cursor Movements -----------------------------
1350 LyXText * tmptext = owner->view()->text;
1351 bool is_rtl = tmptext->cursor.par->isRightToLeftPar();
1352 if(!tmptext->mark_set)
1353 owner->view()->beforeChange();
1354 owner->view()->update(-2);
1356 tmptext->CursorLeft();
1357 if (tmptext->cursor.pos < tmptext->cursor.par->Last()
1358 && tmptext->cursor.par->GetChar(tmptext->cursor.pos)
1359 == LyXParagraph::META_INSET
1360 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)
1361 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)->Editable() == Inset::HIGHLY_EDITABLE){
1362 Inset * tmpinset = tmptext->cursor.par->GetInset(tmptext->cursor.pos);
1363 setMessage(tmpinset->EditMessage());
1364 tmpinset->Edit(owner->view(), 0, 0, 0);
1368 tmptext->CursorRight();
1369 owner->view()->text->FinishUndo();
1370 moveCursorUpdate(false);
1371 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1377 // This is soooo ugly. Isn`t it possible to make
1378 // it simpler? (Lgb)
1379 LyXText * txt = owner->view()->text;
1380 bool is_rtl = txt->cursor.par->isRightToLeftPar();
1381 if(!txt->mark_set) owner->view()->beforeChange();
1382 owner->view()->update(-2);
1385 if (txt->cursor.pos < txt->cursor.par->Last()
1386 && txt->cursor.par->GetChar(txt->cursor.pos)
1387 == LyXParagraph::META_INSET
1388 && txt->cursor.par->GetInset(txt->cursor.pos)
1389 && txt->cursor.par->GetInset(txt->cursor.pos)->Editable() == Inset::HIGHLY_EDITABLE) {
1390 Inset * tmpinset = txt->cursor.par->GetInset(txt->cursor.pos);
1391 setMessage(tmpinset->EditMessage());
1392 tmpinset->Edit(owner->view(),
1393 tmpinset->width(owner->view()->painter(),
1394 txt->GetFont(txt->cursor.par,
1402 owner->view()->text->FinishUndo();
1403 moveCursorUpdate(false);
1404 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1409 if(!owner->view()->text->mark_set) owner->view()->beforeChange();
1410 owner->view()->update(-3);
1411 owner->view()->text->CursorUp();
1412 owner->view()->text->FinishUndo();
1413 moveCursorUpdate(false);
1414 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1418 if(!owner->view()->text->mark_set)
1419 owner->view()->beforeChange();
1420 owner->view()->update(-3);
1421 owner->view()->text->CursorDown();
1422 owner->view()->text->FinishUndo();
1423 moveCursorUpdate(false);
1424 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1427 case LFUN_UP_PARAGRAPH:
1428 if(!owner->view()->text->mark_set)
1429 owner->view()->beforeChange();
1430 owner->view()->update(-3);
1431 owner->view()->text->CursorUpParagraph();
1432 owner->view()->text->FinishUndo();
1433 moveCursorUpdate(false);
1434 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1437 case LFUN_DOWN_PARAGRAPH:
1438 if(!owner->view()->text->mark_set)
1439 owner->view()->beforeChange();
1440 owner->view()->update(-3);
1441 owner->view()->text->CursorDownParagraph();
1442 owner->view()->text->FinishUndo();
1443 moveCursorUpdate(false);
1444 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1448 if(!owner->view()->text->mark_set)
1449 owner->view()->beforeChange();
1450 owner->view()->update(-3);
1451 owner->view()->cursorPrevious();
1452 owner->view()->text->FinishUndo();
1453 moveCursorUpdate(false);
1454 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1458 if(!owner->view()->text->mark_set)
1459 owner->view()->beforeChange();
1460 owner->view()->update(-3);
1461 owner->view()->cursorNext();
1462 owner->view()->text->FinishUndo();
1463 moveCursorUpdate(false);
1464 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1468 if(!owner->view()->text->mark_set)
1469 owner->view()->beforeChange();
1470 owner->view()->update(-2);
1471 owner->view()->text->CursorHome();
1472 owner->view()->text->FinishUndo();
1473 moveCursorUpdate(false);
1474 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1478 if(!owner->view()->text->mark_set)
1479 owner->view()->beforeChange();
1480 owner->view()->update(-2);
1481 owner->view()->text->CursorEnd();
1482 owner->view()->text->FinishUndo();
1483 moveCursorUpdate(false);
1484 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1488 if(!owner->view()->text->mark_set)
1489 owner->view()->beforeChange();
1490 owner->view()->update(-2);
1491 owner->view()->text->CursorTab();
1492 owner->view()->text->FinishUndo();
1493 moveCursorUpdate(false);
1494 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1497 case LFUN_WORDRIGHT:
1498 if(!owner->view()->text->mark_set)
1499 owner->view()->beforeChange();
1500 owner->view()->update(-2);
1501 if (owner->view()->text->cursor.par->isRightToLeftPar())
1502 owner->view()->text->CursorLeftOneWord();
1504 owner->view()->text->CursorRightOneWord();
1505 owner->view()->text->FinishUndo();
1506 moveCursorUpdate(false);
1507 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1511 if(!owner->view()->text->mark_set)
1512 owner->view()->beforeChange();
1513 owner->view()->update(-2);
1514 if (owner->view()->text->cursor.par->isRightToLeftPar())
1515 owner->view()->text->CursorRightOneWord();
1517 owner->view()->text->CursorLeftOneWord();
1518 owner->view()->text->FinishUndo();
1519 moveCursorUpdate(false);
1520 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1523 case LFUN_BEGINNINGBUF:
1524 if(!owner->view()->text->mark_set)
1525 owner->view()->beforeChange();
1526 owner->view()->update(-2);
1527 owner->view()->text->CursorTop();
1528 owner->view()->text->FinishUndo();
1529 moveCursorUpdate(false);
1530 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1534 if(!owner->view()->text->mark_set)
1535 owner->view()->beforeChange();
1536 owner->view()->update(-2);
1537 owner->view()->text->CursorBottom();
1538 owner->view()->text->FinishUndo();
1539 moveCursorUpdate(false);
1540 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1544 /* cursor selection ---------------------------- */
1546 owner->view()->update(-2);
1547 if (owner->view()->text->cursor.par->isRightToLeftPar())
1548 owner->view()->text->CursorLeft();
1550 owner->view()->text->CursorRight();
1551 owner->view()->text->FinishUndo();
1552 moveCursorUpdate(true);
1553 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1557 owner->view()->update(-2);
1558 if (owner->view()->text->cursor.par->isRightToLeftPar())
1559 owner->view()->text->CursorRight();
1561 owner->view()->text->CursorLeft();
1562 owner->view()->text->FinishUndo();
1563 moveCursorUpdate(true);
1564 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1568 owner->view()->update(-2);
1569 owner->view()->text->CursorUp();
1570 owner->view()->text->FinishUndo();
1571 moveCursorUpdate(true);
1572 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1576 owner->view()->update(-2);
1577 owner->view()->text->CursorDown();
1578 owner->view()->text->FinishUndo();
1579 moveCursorUpdate(true);
1580 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1583 case LFUN_UP_PARAGRAPHSEL:
1584 owner->view()->update(-2);
1585 owner->view()->text->CursorUpParagraph();
1586 owner->view()->text->FinishUndo();
1587 moveCursorUpdate(true);
1588 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1591 case LFUN_DOWN_PARAGRAPHSEL:
1592 owner->view()->update(-2);
1593 owner->view()->text->CursorDownParagraph();
1594 owner->view()->text->FinishUndo();
1595 moveCursorUpdate(true);
1596 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1600 owner->view()->update(-2);
1601 owner->view()->cursorPrevious();
1602 owner->view()->text->FinishUndo();
1603 moveCursorUpdate(true);
1604 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1608 owner->view()->update(-2);
1609 owner->view()->cursorNext();
1610 owner->view()->text->FinishUndo();
1611 moveCursorUpdate(true);
1612 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1616 owner->view()->update(-2);
1617 owner->view()->text->CursorHome();
1618 owner->view()->text->FinishUndo();
1619 moveCursorUpdate(true);
1620 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1624 owner->view()->update(-2);
1625 owner->view()->text->CursorEnd();
1626 owner->view()->text->FinishUndo();
1627 moveCursorUpdate(true);
1628 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1631 case LFUN_WORDRIGHTSEL:
1632 owner->view()->update(-2);
1633 if (owner->view()->text->cursor.par->isRightToLeftPar())
1634 owner->view()->text->CursorLeftOneWord();
1636 owner->view()->text->CursorRightOneWord();
1637 owner->view()->text->FinishUndo();
1638 moveCursorUpdate(true);
1639 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1642 case LFUN_WORDLEFTSEL:
1643 owner->view()->update(-2);
1644 if (owner->view()->text->cursor.par->isRightToLeftPar())
1645 owner->view()->text->CursorRightOneWord();
1647 owner->view()->text->CursorLeftOneWord();
1648 owner->view()->text->FinishUndo();
1649 moveCursorUpdate(true);
1650 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1653 case LFUN_BEGINNINGBUFSEL:
1654 owner->view()->update(-2);
1655 owner->view()->text->CursorTop();
1656 owner->view()->text->FinishUndo();
1657 moveCursorUpdate(true);
1658 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1661 case LFUN_ENDBUFSEL:
1662 owner->view()->update(-2);
1663 owner->view()->text->CursorBottom();
1664 owner->view()->text->FinishUndo();
1665 moveCursorUpdate(true);
1666 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1669 // --- text changing commands ------------------------
1670 case LFUN_BREAKLINE:
1672 owner->view()->beforeChange();
1673 owner->view()->text->InsertChar(LyXParagraph::META_NEWLINE);
1674 owner->view()->smallUpdate(1);
1675 SetUpdateTimer(0.01);
1676 moveCursorUpdate(false);
1678 owner->view()->newline();
1682 case LFUN_PROTECTEDSPACE:
1685 LyXLayout const & style =
1686 textclasslist.Style(owner->view()->buffer()->params.textclass,
1687 owner->view()->text->cursor.par->GetLayout());
1689 if (style.free_spacing) {
1690 owner->view()->text->InsertChar(' ');
1691 owner->view()->update(-1);
1693 owner->view()->protectedBlank();
1695 moveCursorUpdate(false);
1698 owner->view()->beforeChange();
1699 owner->view()->text->
1700 InsertChar(LyXParagraph::META_PROTECTED_SEPARATOR);
1701 owner->view()->smallUpdate(1);
1703 moveCursorUpdate(false);
1708 if(owner->view()->text->mark_set) {
1709 owner->view()->beforeChange();
1710 owner->view()->update(0);
1711 setMessage(N_("Mark removed"));
1713 owner->view()->beforeChange();
1714 owner->view()->text->mark_set = 1;
1715 owner->view()->update(0);
1716 setMessage(N_("Mark set"));
1718 owner->view()->text->sel_cursor =
1719 owner->view()->text->cursor;
1724 if (!owner->view()->text->selection) {
1725 owner->view()->text->Delete();
1726 owner->view()->text->sel_cursor =
1727 owner->view()->text->cursor;
1728 owner->view()->smallUpdate(1);
1729 // It is possible to make it a lot faster still
1730 // just comment out the lone below...
1731 owner->view()->showCursor();
1733 owner->view()->cut();
1736 moveCursorUpdate(false);
1737 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1738 owner->view()->setState();
1741 case LFUN_DELETE_SKIP:
1743 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1745 LyXCursor cursor = owner->view()->text->cursor;
1748 if (!owner->view()->text->selection) {
1749 if (cursor.pos == cursor.par->Last()) {
1750 owner->view()->text->CursorRight();
1751 cursor = owner->view()->text->cursor;
1753 && !(cursor.par->added_space_top
1754 == VSpace (VSpace::NONE))) {
1755 owner->view()->text->SetParagraph
1756 (cursor.par->line_top,
1757 cursor.par->line_bottom,
1758 cursor.par->pagebreak_top,
1759 cursor.par->pagebreak_bottom,
1760 VSpace(VSpace::NONE),
1761 cursor.par->added_space_bottom,
1763 cursor.par->labelwidthstring, 0);
1764 owner->view()->text->CursorLeft();
1765 owner->view()->update (1);
1767 owner->view()->text->CursorLeft();
1768 owner->view()->text->Delete();
1769 owner->view()->text->sel_cursor =
1770 owner->view()->text->cursor;
1771 owner->view()->smallUpdate(1);
1774 owner->view()->text->Delete();
1775 owner->view()->text->sel_cursor =
1776 owner->view()->text->cursor;
1777 owner->view()->smallUpdate(1);
1780 owner->view()->cut();
1786 /* -------> Delete word forward. */
1787 case LFUN_DELETE_WORD_FORWARD:
1788 owner->view()->update(-2);
1790 owner->view()->text->DeleteWordForward();
1791 owner->view()->update( 1 );
1793 moveCursorUpdate(false);
1794 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1797 /* -------> Delete word backward. */
1798 case LFUN_DELETE_WORD_BACKWARD:
1799 owner->view()->update(-2);
1801 owner->view()->text->DeleteWordBackward();
1802 owner->view()->update( 1 );
1804 moveCursorUpdate(false);
1805 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1808 /* -------> Kill to end of line. */
1809 case LFUN_DELETE_LINE_FORWARD:
1811 owner->view()->update(-2);
1812 owner->view()->text->DeleteLineForward();
1813 owner->view()->update( 1 );
1815 moveCursorUpdate(false);
1818 /* -------> Set mark off. */
1820 owner->view()->beforeChange();
1821 owner->view()->update(0);
1822 owner->view()->text->sel_cursor =
1823 owner->view()->text->cursor;
1824 setMessage(N_("Mark off"));
1827 /* -------> Set mark on. */
1829 owner->view()->beforeChange();
1830 owner->view()->text->mark_set = 1;
1831 owner->view()->update( 0 );
1832 owner->view()->text->sel_cursor =
1833 owner->view()->text->cursor;
1834 setMessage(N_("Mark on"));
1837 case LFUN_BACKSPACE:
1840 if (!owner->view()->text->selection) {
1841 if (owner->getIntl()->getTrans()->backspace()) {
1842 owner->view()->text->Backspace();
1843 owner->view()->text->sel_cursor =
1844 owner->view()->text->cursor;
1845 owner->view()->smallUpdate(1);
1846 // It is possible to make it a lot faster still
1847 // just comment out the lone below...
1848 owner->view()->showCursor();
1851 owner->view()->cut();
1854 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1855 owner->view()->setState();
1859 case LFUN_BACKSPACE_SKIP:
1861 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1863 LyXCursor cursor = owner->view()->text->cursor;
1866 if (!owner->view()->text->selection) {
1868 && !(cursor.par->added_space_top
1869 == VSpace (VSpace::NONE))) {
1870 owner->view()->text->SetParagraph
1871 (cursor.par->line_top,
1872 cursor.par->line_bottom,
1873 cursor.par->pagebreak_top,
1874 cursor.par->pagebreak_bottom,
1875 VSpace(VSpace::NONE), cursor.par->added_space_bottom,
1877 cursor.par->labelwidthstring, 0);
1878 owner->view()->update (1);
1880 owner->view()->text->Backspace();
1881 owner->view()->text->sel_cursor
1883 owner->view()->smallUpdate (1);
1886 owner->view()->cut();
1891 case LFUN_BREAKPARAGRAPH:
1893 owner->view()->beforeChange();
1894 owner->view()->text->BreakParagraph(0);
1895 owner->view()->smallUpdate(1);
1896 SetUpdateTimer(0.01);
1897 owner->view()->text->sel_cursor =
1898 owner->view()->text->cursor;
1899 owner->view()->setState();
1900 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1904 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1906 owner->view()->beforeChange();
1907 owner->view()->text->BreakParagraph(1);
1908 owner->view()->smallUpdate(1);
1909 SetUpdateTimer(0.01);
1910 owner->view()->text->sel_cursor =
1911 owner->view()->text->cursor;
1912 owner->view()->setState();
1913 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1917 case LFUN_BREAKPARAGRAPH_SKIP:
1919 // When at the beginning of a paragraph, remove
1920 // indentation and add a "defskip" at the top.
1921 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
1923 LyXCursor cursor = owner->view()->text->cursor;
1925 owner->view()->beforeChange();
1926 if (cursor.pos == 0) {
1927 if (cursor.par->added_space_top == VSpace(VSpace::NONE)) {
1928 owner->view()->text->SetParagraph
1929 (cursor.par->line_top,
1930 cursor.par->line_bottom,
1931 cursor.par->pagebreak_top,
1932 cursor.par->pagebreak_bottom,
1933 VSpace(VSpace::DEFSKIP), cursor.par->added_space_bottom,
1935 cursor.par->labelwidthstring, 1);
1936 owner->view()->update(1);
1940 owner->view()->text->BreakParagraph(0);
1941 owner->view()->smallUpdate(1);
1943 SetUpdateTimer(0.01);
1944 owner->view()->text->sel_cursor = cursor;
1945 owner->view()->setState();
1946 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1950 case LFUN_PARAGRAPH_SPACING:
1952 LyXParagraph * par = owner->view()->text->cursor.par;
1953 Spacing::Space cur_spacing = par->spacing.getSpace();
1954 float cur_value = 1.0;
1955 if (cur_spacing == Spacing::Other) {
1956 cur_value = par->spacing.getValue();
1960 istringstream istr(argument);
1962 istrstream istr(argument.c_str());
1966 Spacing::Space new_spacing = cur_spacing;
1967 float new_value = cur_value;
1969 lyxerr << "Missing argument to `paragraph-spacing'"
1971 } else if (tmp == "single") {
1972 new_spacing = Spacing::Single;
1973 } else if (tmp == "onehalf") {
1974 new_spacing = Spacing::Onehalf;
1975 } else if (tmp == "double") {
1976 new_spacing = Spacing::Double;
1977 } else if (tmp == "other") {
1978 new_spacing = Spacing::Other;
1981 lyxerr << "new_value = " << tmpval << endl;
1984 } else if (tmp == "default") {
1985 new_spacing = Spacing::Default;
1987 lyxerr << _("Unknown spacing argument: ")
1988 << argument << endl;
1990 if (cur_spacing != new_spacing || cur_value != new_value) {
1991 par->spacing.set(new_spacing, new_value);
1992 owner->view()->text->RedoParagraph();
1993 owner->view()->update(-1);
1999 owner->view()->beforeChange();
2000 owner->view()->text->InsertChar('\"'); // This " matches the single quote in the code
2001 owner->view()->smallUpdate(1);
2003 moveCursorUpdate(false);
2009 InsetCommand * new_inset;
2010 if (action == LFUN_HTMLURL)
2011 new_inset = new InsetUrl("htmlurl", "", "");
2013 new_inset = new InsetUrl("url", "", "");
2014 owner->view()->insertInset(new_inset);
2015 new_inset->Edit(owner->view(), 0, 0, 0);
2019 case LFUN_INSET_TEXT:
2021 InsetText * new_inset = new InsetText(owner->buffer());
2022 owner->view()->insertInset(new_inset);
2023 new_inset->Edit(owner->view(), 0, 0, 0);
2027 case LFUN_INSET_NUMBER:
2029 InsetNumber * new_inset = new InsetNumber(owner->buffer());
2030 owner->view()->insertInset(new_inset);
2031 new_inset->Edit(owner->view(), 0, 0, 0);
2035 case LFUN_INSET_ERT:
2037 InsetERT * new_inset = new InsetERT(owner->buffer());
2038 owner->view()->insertInset(new_inset);
2039 new_inset->Edit(owner->view(), 0, 0, 0);
2043 case LFUN_INSET_FOOTNOTE:
2045 InsetFoot * new_inset = new InsetFoot(owner->buffer());
2046 owner->view()->insertInset(new_inset);
2047 new_inset->Edit(owner->view(), 0, 0, 0);
2051 // --- lyxserver commands ----------------------------
2053 case LFUN_CHARATCURSOR:
2055 LyXParagraph::size_type pos =
2056 owner->view()->text->cursor.pos;
2057 if(pos < owner->view()->text->cursor.par->size())
2058 //dispatch_buffer = owner->view()->text->
2059 // cursor.par->text[pos];
2061 owner->view()->text->
2062 cursor.par->GetChar(pos);
2064 dispatch_buffer = "EOF";
2070 tostr(owner->view()->text->cursor.x) + ' '
2071 + tostr(owner->view()->text->cursor.y);
2078 sscanf(argument.c_str(), " %d %ld", &x, &y);
2079 owner->view()->text->SetCursorFromCoordinates(x, y);
2083 case LFUN_GETLAYOUT:
2085 tostr(owner->view()->text->cursor.par->layout);
2090 LyXFont & font = owner->view()->text->current_font;
2091 if(font.shape() == LyXFont::ITALIC_SHAPE)
2092 dispatch_buffer = 'E';
2093 else if(font.shape() == LyXFont::SMALLCAPS_SHAPE)
2094 dispatch_buffer = 'N';
2096 dispatch_buffer = '0';
2103 LyXFont & font = owner->view()->text->current_font;
2104 if(font.latex() == LyXFont::ON)
2105 dispatch_buffer = 'L';
2107 dispatch_buffer = '0';
2112 setMessage(owner->buffer()->fileName());
2113 lyxerr.debug() << "FNAME["
2114 << owner->buffer()->fileName()
2122 dispatch_buffer = buf;
2123 lyxserver->notifyClient(dispatch_buffer);
2127 case LFUN_GOTOFILEROW:
2129 char file_name[100];
2131 sscanf(argument.c_str(), " %s %d", file_name, &row);
2133 // Must replace extension of the file to be .lyx and get full path
2134 string s = ChangeExtension(string(file_name), ".lyx", false);
2136 // Either change buffer or load the file
2137 if (bufferlist.exists(s))
2138 owner->view()->buffer(bufferlist.getBuffer(s));
2140 owner->view()->buffer(bufferlist.loadLyXFile(s));
2143 owner->view()->setCursorFromRow(row);
2146 owner->view()->center();
2153 int qa = lyxaction.LookupFunc(argument.c_str());
2154 setMessage(lyxaction.helpText(static_cast<kb_action>(qa)));
2158 // --- accented characters ---------------------------
2161 case LFUN_CIRCUMFLEX:
2171 case LFUN_SPECIAL_CARON:
2174 case LFUN_HUNG_UMLAUT:
2180 if (keyseq.length == -1 && keyseq.getiso() != 0)
2181 c = keyseq.getiso();
2185 owner->getIntl()->getTrans()->
2186 deadkey(c, get_accent(action).accent,
2187 owner->view()->text);
2189 // Need to reset, in case the minibuffer calls these
2194 // copied verbatim from do_accent_char
2195 owner->view()->smallUpdate(1);
2197 owner->view()->text->sel_cursor =
2198 owner->view()->text->cursor;
2202 // --- toolbar ----------------------------------
2203 case LFUN_PUSH_TOOLBAR:
2205 int nth = strToInt(argument);
2206 if (lyxerr.debugging(Debug::TOOLBAR)) {
2207 lyxerr << "LFUN_PUSH_TOOLBAR: argument = `"
2208 << argument << "'\n"
2209 << "LFUN_PUSH_TOOLBAR: nth = `"
2210 << nth << "'" << endl;
2215 setErrorMessage(N_("Push-toolbar needs argument > 0"));
2217 owner->getToolbar()->push(nth);
2222 case LFUN_ADD_TO_TOOLBAR:
2224 if (lyxerr.debugging(Debug::TOOLBAR)) {
2225 lyxerr << "LFUN_ADD_TO_TOOLBAR:"
2226 "argument = `" << argument << '\'' << endl;
2228 string tmp(argument);
2229 //lyxerr <<string("Argument: ") + argument);
2230 //lyxerr <<string("Tmp : ") + tmp);
2233 setErrorMessage(N_("Usage: toolbar-add-to <LyX command>"));
2235 owner->getToolbar()->add(argument, false);
2236 owner->getToolbar()->set();
2241 // --- insert characters ----------------------------------------
2243 // --- Mathed stuff. If we are here, there is no locked inset yet.
2248 if (!greek_kb_flag) {
2250 setMessage(N_("Math greek mode on"));
2257 case LFUN_GREEK_TOGGLE:
2259 greek_kb_flag = greek_kb_flag ? 0 : 2;
2260 if (greek_kb_flag) {
2261 setMessage(N_("Math greek keyboard on"));
2263 setMessage(N_("Math greek keyboard off"));
2268 case LFUN_MATH_DELIM:
2269 case LFUN_INSERT_MATRIX:
2271 if (owner->view()->available()) {
2273 open_new_inset(new InsetFormula(false));
2276 ->LocalDispatch(owner->view(),
2283 case LFUN_INSERT_MATH:
2285 math_insert_symbol(argument.c_str());
2289 case LFUN_MATH_DISPLAY:
2291 if (owner->view()->available())
2292 owner->view()->open_new_inset(new InsetFormula(true));
2296 case LFUN_MATH_MACRO:
2298 if (owner->view()->available()) {
2301 setErrorMessage(N_("Missing argument"));
2303 string s1 = token(s, ' ', 1);
2304 int na = s1.empty() ? 0: atoi(s1.c_str());
2306 open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2312 case LFUN_MATH_MODE: // Open or create a math inset
2315 if (owner->view()->available())
2316 owner->view()->open_new_inset(new InsetFormula);
2317 setMessage(N_("Math editor mode"));
2321 case LFUN_MATH_NUMBER:
2322 case LFUN_MATH_LIMITS:
2324 setErrorMessage(N_("This is only allowed in math mode!"));
2328 case LFUN_INSERT_CITATION:
2330 InsetCitation * new_inset = new InsetCitation();
2332 // The note, if any, must be after the key, delimited
2333 // by a | so both key and remark can have spaces.
2334 if (!argument.empty()) {
2335 string lsarg(argument);
2336 if (contains(lsarg, "|")) {
2337 new_inset->setContents(token(lsarg, '|', 0));
2338 new_inset->setOptions(token(lsarg, '|', 1));
2340 new_inset->setContents(lsarg);
2341 owner->view()->insertInset(new_inset);
2343 owner->view()->insertInset(new_inset);
2344 new_inset->Edit(owner->view(), 0, 0, 0);
2349 case LFUN_INSERT_BIBTEX:
2351 // ale970405+lasgoutt970425
2352 // The argument can be up to two tokens separated
2353 // by a space. The first one is the bibstyle.
2354 string lsarg(argument);
2355 string bibstyle = token(lsarg, ' ', 1);
2356 if (bibstyle.empty())
2358 InsetBibtex * new_inset
2359 = new InsetBibtex(token(lsarg, ' ', 0),
2363 owner->view()->insertInset(new_inset);
2364 if (lsarg.empty()) {
2365 new_inset->Edit(owner->view(), 0, 0, 0);
2370 // BibTeX data bases
2371 case LFUN_BIBDB_ADD:
2373 InsetBibtex * inset =
2374 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2376 inset->addDatabase(argument);
2381 case LFUN_BIBDB_DEL:
2383 InsetBibtex * inset =
2384 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2386 inset->delDatabase(argument);
2391 case LFUN_BIBTEX_STYLE:
2393 InsetBibtex * inset =
2394 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2396 inset->setOptions(argument);
2401 case LFUN_INDEX_INSERT:
2402 case LFUN_INDEX_INSERT_LAST:
2404 // Can't do that at the beginning of a paragraph.
2405 if (owner->view()->text->cursor.pos - 1 < 0)
2408 InsetIndex * new_inset = new InsetIndex();
2409 if (!argument.empty()) {
2410 string lsarg(argument);
2411 new_inset->setContents(lsarg);
2412 owner->view()->insertInset(new_inset);
2415 //get the current word for an argument
2416 LyXParagraph::size_type lastpos =
2417 owner->view()->text->cursor.pos - 1;
2418 // Get the current word. note that this must be done
2419 // before inserting the inset, or the inset will
2421 string curstring(owner->view()
2422 ->text->cursor.par->GetWord(lastpos));
2424 //make the new inset and write the current word into it
2425 InsetIndex * new_inset = new InsetIndex();
2427 new_inset->setContents(curstring);
2429 //don't edit it if the call was to INSERT_LAST
2430 if(action != LFUN_INDEX_INSERT_LAST) {
2431 new_inset->Edit(owner->view(), 0, 0, 0);
2433 //it looks blank on the screen unless
2434 //we do something. put it here.
2436 // move the cursor to the returned value of lastpos
2437 // but only for the auto-insert
2438 owner->view()->text->cursor.pos = lastpos;
2441 //put the new inset into the buffer.
2442 // there should be some way of knowing the user
2443 //cancelled & avoiding this, but i don't know how
2444 owner->view()->insertInset(new_inset);
2449 case LFUN_INDEX_PRINT:
2451 Inset * new_inset = new InsetPrintIndex(owner->buffer());
2452 owner->view()->insertInset(new_inset, "Standard", true);
2456 case LFUN_PARENTINSERT:
2458 lyxerr << "arg " << argument << endl;
2459 Inset * new_inset = new InsetParent(argument, owner->buffer());
2460 owner->view()->insertInset(new_inset, "Standard", true);
2464 case LFUN_CHILDINSERT:
2466 Inset * new_inset = new InsetInclude(argument,
2468 owner->view()->insertInset(new_inset, "Standard", true);
2469 new_inset->Edit(owner->view(), 0, 0, 0);
2473 case LFUN_CHILDOPEN:
2476 MakeAbsPath(argument,
2477 OnlyPath(owner->buffer()->fileName()));
2478 setMessage(N_("Opening child document ") +
2479 MakeDisplayPath(filename) + "...");
2480 owner->view()->savePosition();
2481 if (bufferlist.exists(filename))
2482 owner->view()->buffer(bufferlist.getBuffer(filename));
2484 owner->view()->buffer(bufferlist.loadLyXFile(filename));
2488 case LFUN_INSERT_NOTE:
2489 owner->view()->insertNote();
2492 case LFUN_INSERTFOOTNOTE:
2494 LyXParagraph::footnote_kind kind;
2495 if (argument == "footnote")
2496 { kind = LyXParagraph::FOOTNOTE; }
2497 else if (argument == "margin")
2498 { kind = LyXParagraph::MARGIN; }
2499 else if (argument == "figure")
2500 { kind = LyXParagraph::FIG; }
2501 else if (argument == "table")
2502 { kind = LyXParagraph::TAB; }
2503 else if (argument == "wide-fig")
2504 { kind = LyXParagraph::WIDE_FIG; }
2505 else if (argument == "wide-tab")
2506 { kind = LyXParagraph::WIDE_TAB; }
2507 else if (argument == "algorithm")
2508 { kind = LyXParagraph::ALGORITHM; }
2510 setErrorMessage(N_("Unknown kind of footnote"));
2513 owner->view()->text->InsertFootnoteEnvironment(kind);
2514 owner->view()->update(1);
2515 owner->view()->setState();
2519 case LFUN_BUFFERBULLETSSELECT:
2523 case LFUN_TOGGLECURSORFOLLOW:
2524 cursor_follows_scrollbar = !cursor_follows_scrollbar;
2527 case LFUN_KMAP_OFF: // keymap off
2528 owner->getIntl()->KeyMapOn(false);
2531 case LFUN_KMAP_PRIM: // primary keymap
2532 owner->getIntl()->KeyMapPrim();
2535 case LFUN_KMAP_SEC: // secondary keymap
2536 owner->getIntl()->KeyMapSec();
2539 case LFUN_KMAP_TOGGLE: // toggle keymap
2540 owner->getIntl()->ToggleKeyMap();
2543 case LFUN_SELFINSERT:
2545 for (string::size_type i = 0; i < argument.length(); ++i) {
2546 owner->view()->text->InsertChar(argument[i]);
2547 // This needs to be in the loop, or else we
2548 // won't break lines correctly. (Asger)
2549 owner->view()->smallUpdate(1);
2552 owner->view()->text->sel_cursor =
2553 owner->view()->text->cursor;
2554 moveCursorUpdate(false);
2560 // argument contains ';'-terminated commands
2561 while (argument.find(';') != string::npos) {
2563 argument = split(argument, first, ';');
2569 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
2577 now_time_t = time(NULL);
2578 now_tm = localtime(&now_time_t);
2579 (void)setlocale(LC_TIME, "");
2580 if (!argument.empty())
2582 else if (arg.empty())
2583 arg = lyxrc.date_insert_format;
2584 datetmp_len = (int) strftime(datetmp, 32, arg.c_str(), now_tm);
2585 for (int i = 0; i < datetmp_len; i++) {
2586 owner->view()->text->InsertChar(datetmp[i]);
2587 owner->view()->smallUpdate(1);
2590 owner->view()->text->sel_cursor = owner->view()->text->cursor;
2591 moveCursorUpdate(false);
2595 case LFUN_SAVEPREFERENCES:
2597 Path p(user_lyxdir);
2598 lyxrc.write("preferences");
2602 case LFUN_UNKNOWN_ACTION:
2604 if(!owner->buffer()) {
2606 setErrorMessage(N_("No document open"));
2610 if (owner->buffer()->isReadonly()) {
2612 setErrorMessage(N_("Document is read only"));
2616 if (!argument.empty()) {
2618 /* Automatically delete the currently selected
2619 * text and replace it with what is being
2620 * typed in now. Depends on lyxrc settings
2621 * "auto_region_delete", which defaults to
2624 if ( lyxrc.auto_region_delete ) {
2625 if (owner->view()->text->selection){
2626 owner->view()->text->CutSelection(false);
2627 owner->view()->update(-1);
2631 owner->view()->beforeChange();
2634 if (isdigit(argument[0]) &&
2635 (lyxrc.number_inset == "true" ||
2636 (lyxrc.number_inset == "rtl" &&
2637 owner->view()->text->real_current_font.isVisibleRightToLeft()
2639 UpdatableInset * tmpinset = new InsetNumber(owner->buffer());
2640 owner->view()->open_new_inset(tmpinset);
2641 tmpinset->LocalDispatch(owner->view(), action,
2647 for (string::size_type i = 0;
2648 i < argument.length(); ++i) {
2649 if (greek_kb_flag) {
2650 if (!math_insert_greek(argument[i]))
2651 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2653 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2656 owner->view()->smallUpdate(1);
2659 owner->view()->text->sel_cursor =
2660 owner->view()->text->cursor;
2661 moveCursorUpdate(false);
2664 // why is an "Unknown action" with empty
2665 // argument even dispatched in the first
2666 // place? I`ll probably change that. (Lgb)
2668 setErrorMessage(N_("Unknown action"));
2672 lyxerr << "A truly unknown func!" << endl;
2678 string res = getMessage();
2681 if (!commandshortcut.empty()) {
2682 string newbuf = owner->getMiniBuffer()->GetText();
2683 if (newbuf != commandshortcut) {
2684 owner->getMiniBuffer()->Set(newbuf
2690 owner->getMiniBuffer()->Set(string(_(res.c_str()))
2691 + " " + commandshortcut);
2698 void LyXFunc::setupLocalKeymap()
2700 keyseq.stdmap = keyseq.curmap = toplevel_keymap;
2701 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap;
2705 void LyXFunc::MenuNew(bool fromTemplate)
2707 string fname, initpath = lyxrc.document_path;
2710 if (owner->view()->available()) {
2711 string trypath = owner->buffer()->filepath;
2712 // If directory is writeable, use this as default.
2713 if (IsDirWriteable(trypath) == 1)
2717 ProhibitInput(owner->view());
2718 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
2719 fileDlg.SetButton(1, _("Templates"), lyxrc.template_path);
2720 fname = fileDlg.Select(_("Enter Filename for new document"),
2721 initpath, "*.lyx", _("newfile"));
2722 AllowInput(owner->view());
2724 if (fname.empty()) {
2725 owner->getMiniBuffer()->Set(_("Canceled."));
2726 lyxerr.debug() << "New Document Cancelled." << endl;
2730 // get absolute path of file and make sure the filename ends
2732 string s = MakeAbsPath(fname);
2733 if (!IsLyXFilename(s))
2736 // Check if the document already is open
2737 if (bufferlist.exists(s)){
2738 switch(AskConfirmation(_("Document is already open:"),
2739 MakeDisplayPath(s, 50),
2740 _("Do you want to close that document now?\n"
2741 "('No' will just switch to the open version)")))
2743 case 1: // Yes: close the document
2744 if (!bufferlist.close(bufferlist.getBuffer(s)))
2745 // If close is canceled, we cancel here too.
2748 case 2: // No: switch to the open document
2749 owner->view()->buffer(bufferlist.getBuffer(s));
2751 case 3: // Cancel: Do nothing
2752 owner->getMiniBuffer()->Set(_("Canceled."));
2757 // Check whether the file already exists
2758 if (IsLyXFilename(s)) {
2760 if (fi.readable() &&
2761 AskQuestion(_("File already exists:"),
2762 MakeDisplayPath(s, 50),
2763 _("Do you want to open the document?"))) {
2765 owner->getMiniBuffer()->Set(_("Opening document"),
2766 MakeDisplayPath(s), "...");
2768 owner->view()->buffer(
2769 bufferlist.loadLyXFile(s));
2770 owner->getMiniBuffer()->Set(_("Document"),
2777 // The template stuff
2780 ProhibitInput(owner->view());
2781 fname = fileDlg.Select(_("Choose template"),
2782 lyxrc.template_path,
2785 AllowInput(owner->view());
2788 // find a free buffer
2789 lyxerr.debug() << "Find a free buffer." << endl;
2790 owner->view()->buffer(bufferlist.newFile(s, templname));
2794 void LyXFunc::MenuOpen()
2796 string initpath = lyxrc.document_path;
2799 if (owner->view()->available()) {
2800 string trypath = owner->buffer()->filepath;
2801 // If directory is writeable, use this as default.
2802 if (IsDirWriteable(trypath) == 1)
2807 ProhibitInput(owner->view());
2808 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
2809 fileDlg.SetButton(1, _("Examples"),
2810 AddPath(system_lyxdir, "examples"));
2811 string filename = fileDlg.Select(_("Select Document to Open"),
2813 AllowInput(owner->view());
2815 // check selected filename
2816 if (filename.empty()) {
2817 owner->getMiniBuffer()->Set(_("Canceled."));
2821 // get absolute path of file and make sure the filename ends
2823 filename = MakeAbsPath(filename);
2824 if (!IsLyXFilename(filename))
2828 owner->getMiniBuffer()->Set(_("Opening document"),
2829 MakeDisplayPath(filename), "...");
2830 Buffer * openbuf = bufferlist.loadLyXFile(filename);
2832 owner->view()->buffer(openbuf);
2833 owner->getMiniBuffer()->Set(_("Document"),
2834 MakeDisplayPath(filename),
2837 owner->getMiniBuffer()->Set(_("Could not open document"),
2838 MakeDisplayPath(filename));
2843 void LyXFunc::doImportASCII(bool linorpar)
2845 string initpath = lyxrc.document_path;
2848 if (owner->view()->available()) {
2849 string trypath = owner->buffer()->filepath;
2850 // If directory is writeable, use this as default.
2851 if (IsDirWriteable(trypath) == 1)
2856 ProhibitInput(owner->view());
2857 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
2858 fileDlg.SetButton(1, _("Examples"),
2859 AddPath(system_lyxdir, "examples"));
2860 string filename = fileDlg.Select(_("Select ASCII file to Import"),
2862 AllowInput(owner->view());
2864 // check selected filename
2865 if (filename.empty()) {
2866 owner->getMiniBuffer()->Set(_("Canceled."));
2870 // get absolute path of file
2871 filename = MakeAbsPath(filename);
2873 string s = ChangeExtension(filename, ".lyx", false);
2875 // Check if the document already is open
2876 if (bufferlist.exists(s)) {
2877 switch(AskConfirmation(_("Document is already open:"),
2878 MakeDisplayPath(s, 50),
2879 _("Do you want to close that document now?\n"
2880 "('No' will just switch to the open version)")))
2882 case 1: // Yes: close the document
2883 if (!bufferlist.close(bufferlist.getBuffer(s)))
2884 // If close is canceled, we cancel here too.
2887 case 2: // No: switch to the open document
2888 owner->view()->buffer(bufferlist.getBuffer(s));
2890 case 3: // Cancel: Do nothing
2891 owner->getMiniBuffer()->Set(_("Canceled."));
2896 // Check if a LyX document by the same root exists in filesystem
2897 FileInfo f(s, true);
2898 if (f.exist() && !AskQuestion(_("A document by the name"),
2900 _("already exists. Overwrite?"))) {
2901 owner->getMiniBuffer()->Set(_("Canceled."));
2905 owner->view()->buffer(bufferlist.newFile(s, string()));
2906 owner->getMiniBuffer()->Set(_("Importing ASCII file"),
2907 MakeDisplayPath(filename), "...");
2908 // Insert ASCII file
2909 InsertAsciiFile(owner->view(), filename, linorpar);
2910 owner->getMiniBuffer()->Set(_("ASCII file "),
2911 MakeDisplayPath(filename),
2916 void LyXFunc::doImportLaTeX(bool isnoweb)
2918 string initpath = lyxrc.document_path;
2921 if (owner->view()->available()) {
2922 string trypath = owner->buffer()->filepath;
2923 // If directory is writeable, use this as default.
2924 if (IsDirWriteable(trypath) == 1)
2929 ProhibitInput(owner->view());
2930 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
2931 fileDlg.SetButton(1, _("Examples"),
2932 AddPath(system_lyxdir, "examples"));
2935 filename = fileDlg.Select(_("Select Noweb file to Import"),
2938 filename = fileDlg.Select(_("Select LaTeX file to Import"),
2942 AllowInput(owner->view());
2944 // check selected filename
2945 if (filename.empty()) {
2946 owner->getMiniBuffer()->Set(_("Canceled."));
2950 // get absolute path of file
2951 filename = MakeAbsPath(filename);
2953 // Check if the document already is open
2954 string LyXfilename = ChangeExtension(filename, ".lyx", false);
2955 if (bufferlist.exists(LyXfilename)){
2956 switch(AskConfirmation(_("Document is already open:"),
2957 MakeDisplayPath(LyXfilename, 50),
2958 _("Do you want to close that document now?\n"
2959 "('No' will just switch to the open version)")))
2961 case 1: // Yes: close the document
2962 if (!bufferlist.close(bufferlist.getBuffer(LyXfilename)))
2963 // If close is canceled, we cancel here too.
2966 case 2: // No: switch to the open document
2967 owner->view()->buffer(
2968 bufferlist.getBuffer(LyXfilename));
2970 case 3: // Cancel: Do nothing
2971 owner->getMiniBuffer()->Set(_("Canceled."));
2976 // Check if a LyX document by the same root exists in filesystem
2977 FileInfo f(LyXfilename, true);
2978 if (f.exist() && !AskQuestion(_("A document by the name"),
2979 MakeDisplayPath(LyXfilename),
2980 _("already exists. Overwrite?"))) {
2981 owner->getMiniBuffer()->Set(_("Canceled."));
2988 owner->getMiniBuffer()->Set(_("Importing LaTeX file"),
2989 MakeDisplayPath(filename), "...");
2990 ImportLaTeX myImport(filename);
2991 openbuf = myImport.run();
2993 owner->getMiniBuffer()->Set(_("Importing Noweb file"),
2994 MakeDisplayPath(filename), "...");
2995 ImportNoweb myImport(filename);
2996 openbuf = myImport.run();
2999 owner->view()->buffer(openbuf);
3000 owner->getMiniBuffer()->Set(isnoweb ?
3001 _("Noweb file ") : _("LateX file "),
3002 MakeDisplayPath(filename),
3005 owner->getMiniBuffer()->Set(isnoweb ?
3006 _("Could not import Noweb file") :
3007 _("Could not import LaTeX file"),
3008 MakeDisplayPath(filename));
3013 void LyXFunc::doImportLinuxDoc()
3015 string initpath = lyxrc.document_path;
3018 if (owner->view()->available()) {
3019 string trypath = owner->buffer()->filepath;
3020 // If directory is writeable, use this as default.
3021 if (IsDirWriteable(trypath) == 1)
3026 ProhibitInput(owner->view());
3027 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
3028 fileDlg.SetButton(1, _("Examples"),
3029 AddPath(system_lyxdir, "examples"));
3031 string filename = fileDlg.Select(_("Select LinuxDoc file to Import"),
3032 initpath, "*.sgml");
3034 AllowInput(owner->view());
3036 // check selected filename
3037 if (filename.empty()) {
3038 owner->getMiniBuffer()->Set(_("Canceled."));
3042 // get absolute path of file
3043 filename = MakeAbsPath(filename);
3045 // Check if the document already is open
3046 string LyXfilename = ChangeExtension(filename, ".lyx", false);
3047 if (bufferlist.exists(LyXfilename)){
3048 switch(AskConfirmation(_("Document is already open:"),
3049 MakeDisplayPath(LyXfilename, 50),
3050 _("Do you want to close that document now?\n"
3051 "('No' will just switch to the open version)")))
3053 case 1: // Yes: close the document
3054 if (!bufferlist.close(bufferlist.getBuffer(LyXfilename)))
3055 // If close is canceled, we cancel here too.
3058 case 2: // No: switch to the open document
3059 owner->view()->buffer(
3060 bufferlist.getBuffer(LyXfilename));
3062 case 3: // Cancel: Do nothing
3063 owner->getMiniBuffer()->Set(_("Canceled."));
3068 // Check if a LyX document by the same root exists in filesystem
3069 FileInfo f(LyXfilename, true);
3070 if (f.exist() && !AskQuestion(_("A document by the name"),
3071 MakeDisplayPath(LyXfilename),
3072 _("already exists. Overwrite?"))) {
3073 owner->getMiniBuffer()->Set(_("Canceled."));
3078 owner->getMiniBuffer()->Set(_("Importing LinuxDoc file"),
3079 MakeDisplayPath(filename), "...");
3082 string tmp = lyxrc.linuxdoc_to_lyx_command + filename;
3086 int result = one.startscript(Systemcalls::System, tmp);
3088 string filename = ChangeExtension(filename, ".lyx", false);
3089 // File was generated without problems. Load it.
3090 buf = bufferlist.loadLyXFile(filename);
3091 owner->view()->buffer(buf);
3092 owner->getMiniBuffer()->Set(_("LinuxDoc file "),
3093 MakeDisplayPath(filename),
3096 owner->getMiniBuffer()->Set(_("Could not import LinuxDoc file"),
3097 MakeDisplayPath(filename));
3102 void LyXFunc::MenuInsertLyXFile(string const & filen)
3104 string filename = filen;
3106 if (filename.empty()) {
3107 // Launch a file browser
3108 string initpath = lyxrc.document_path;
3111 if (owner->view()->available()) {
3112 string trypath = owner->buffer()->filepath;
3113 // If directory is writeable, use this as default.
3114 if (IsDirWriteable(trypath) == 1)
3119 ProhibitInput(owner->view());
3120 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
3121 fileDlg.SetButton(1, _("Examples"),
3122 AddPath(system_lyxdir, "examples"));
3123 filename = fileDlg.Select(_("Select Document to Insert"),
3125 AllowInput(owner->view());
3127 // check selected filename
3128 if (filename.empty()) {
3129 owner->getMiniBuffer()->Set(_("Canceled."));
3134 // get absolute path of file and make sure the filename ends
3136 filename = MakeAbsPath(filename);
3137 if (!IsLyXFilename(filename))
3141 owner->getMiniBuffer()->Set(_("Inserting document"),
3142 MakeDisplayPath(filename), "...");
3143 bool res = owner->view()->insertLyXFile(filename);
3145 owner->getMiniBuffer()->Set(_("Document"),
3146 MakeDisplayPath(filename),
3149 owner->getMiniBuffer()->Set(_("Could not insert document"),
3150 MakeDisplayPath(filename));
3155 void LyXFunc::reloadBuffer()
3157 string fn = owner->buffer()->fileName();
3158 if (bufferlist.close(owner->buffer()))
3159 owner->view()->buffer(bufferlist.loadLyXFile(fn));
3163 void LyXFunc::CloseBuffer()
3165 if (bufferlist.close(owner->buffer()) && !quitting) {
3166 if (bufferlist.empty()) {
3167 // need this otherwise SEGV may occur while trying to
3168 // set variables that don't exist
3169 // since there's no current buffer
3170 CloseAllBufferRelatedPopups();
3173 owner->view()->buffer(bufferlist.first());
3179 Inset * LyXFunc::getInsetByCode(Inset::Code code)
3183 LyXCursor cursor = owner->view()->text->cursor;
3184 LyXParagraph::size_type pos = cursor.pos;
3185 LyXParagraph * par = cursor.par;
3187 while (par && !found) {
3188 while ((inset = par->ReturnNextInsetPointer(pos))){
3189 if (inset->LyxCode() == code) {
3197 return found ? inset : 0;
3201 // Each "owner" should have it's own message method. lyxview and
3202 // the minibuffer would use the minibuffer, but lyxserver would
3203 // send an ERROR signal to its client. Alejandro 970603
3204 // This func is bit problematic when it comes to NLS, to make the
3205 // lyx servers client be language indepenent we must not translate
3206 // strings sent to this func.
3207 void LyXFunc::setErrorMessage(string const & m) const
3209 dispatch_buffer = m;
3214 void LyXFunc::setMessage(string const & m)
3216 dispatch_buffer = m;