1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * ====================================================== */
15 using std::istringstream;
28 #pragma implementation
31 #include "lyxlookup.h"
34 #include "bufferlist.h"
35 #include "lyxserver.h"
40 #include "LyXAction.h"
41 #include "insets/inseturl.h"
42 #include "insets/insetlatexaccent.h"
43 #include "insets/insettoc.h"
44 #include "insets/insetlof.h"
45 #include "insets/insetloa.h"
46 #include "insets/insetlot.h"
47 #include "insets/insetref.h"
48 #include "insets/insetparent.h"
49 #include "insets/insetindex.h"
50 #include "insets/insetinclude.h"
51 #include "insets/insetbib.h"
52 #include "insets/insettext.h"
53 #include "insets/insetert.h"
54 #include "insets/insetgraphics.h"
55 #include "insets/insetfoot.h"
56 #include "insets/insettabular.h"
57 #include "mathed/formulamacro.h"
59 #include "spellchecker.h" // RVDK_PATCH_5
60 #include "minibuffer.h"
64 #include "lyx_gui_misc.h"
65 #include "support/filetools.h"
66 #include "support/FileInfo.h"
67 #include "support/syscall.h"
68 #include "support/lstrings.h"
69 #include "support/path.h"
74 #include "trans_mgr.h"
75 #include "ImportLaTeX.h"
76 #include "ImportNoweb.h"
81 #include "bufferview_funcs.h"
86 extern bool cursor_follows_scrollbar;
88 extern void InsertAsciiFile(BufferView *, string const &, bool);
89 extern void math_insert_symbol(char const *);
90 extern Bool math_insert_greek(char const); // why "Bool"?
91 extern BufferList bufferlist;
92 extern LyXServer * lyxserver;
93 extern short greek_kb_flag;
94 extern FD_form_toc * fd_form_toc;
95 extern bool selection_possible;
97 extern kb_keymap * toplevel_keymap;
99 extern void MenuWrite(Buffer *);
100 extern void MenuWriteAs(Buffer *);
101 extern int MenuRunLaTeX(Buffer *);
102 extern int MenuBuildProg(Buffer *);
103 extern int MenuRunChktex(Buffer *);
104 extern bool CreatePostscript(Buffer *, bool);
105 extern void MenuPrint(Buffer *);
106 extern void MenuSendto();
107 extern void QuitLyX();
108 extern void MenuFax(Buffer *);
109 extern void MenuExport(Buffer *, string const &);
111 #define XFORMS_CLIPBOARD 1
113 #ifndef XFORMS_CLIPBOARD
114 extern void MenuPasteSelection(char at);
117 extern LyXAction lyxaction;
119 extern tex_accent_struct get_accent(kb_action action);
121 extern void AutoSave(BufferView *);
122 extern void SetUpdateTimer(float timer = 0.3);
123 extern void FreeUpdateTimer();
124 extern bool PreviewDVI(Buffer *);
125 extern bool PreviewPostscript(Buffer *);
126 extern void MenuInsertLabel(char const *);
127 extern void MenuInsertRef();
128 extern void MenuLayoutCharacter();
129 extern void MenuLayoutParagraph();
130 extern void MenuLayoutDocument();
131 extern void MenuLayoutPaper();
132 extern void MenuLayoutTable(int flag);
133 extern void MenuLayoutQuotes();
134 extern void MenuLayoutPreamble();
135 extern void MenuLayoutSave();
136 extern void bulletForm();
138 extern Buffer * NewLyxFile(string const &);
139 extern void LoadLyXFile(string const &);
140 extern void Reconfigure(BufferView *);
142 extern LyXTextClass::size_type current_layout;
143 extern int getISOCodeFromLaTeX(char *);
145 extern void ShowLatexLog();
147 /* === globals =========================================================== */
149 bool LyXFunc::show_sc = true;
152 LyXFunc::LyXFunc(LyXView * o)
156 lyx_dead_action = LFUN_NOACTION;
157 lyx_calling_dead_action = LFUN_NOACTION;
162 // I changed this func slightly. I commented out the ...FinishUndo(),
163 // this means that all places that used to have a moveCursorUpdate, now
164 // have a ...FinishUndo() as the preceeding statement. I have also added
165 // a moveCursorUpdate to some of the functions that updated the cursor, but
166 // that did not show its new position.
168 void LyXFunc::moveCursorUpdate(bool selecting)
170 if (selecting || owner->view()->text->mark_set) {
171 owner->view()->text->SetSelection();
172 owner->view()->toggleToggle();
173 //owner->view()->update(0);
175 //owner->view()->update(-2); // this IS necessary
178 owner->view()->update(0);
179 owner->view()->showCursor();
181 /* ---> Everytime the cursor is moved, show the current font state. */
182 // should this too me moved out of this func?
183 //owner->getMiniBuffer()->Set(CurrentState());
184 owner->view()->setState();
188 int LyXFunc::processKeyEvent(XEvent * ev)
192 XKeyEvent * keyevent = &ev->xkey;
193 KeySym keysym_return;
195 int num_bytes = LyXLookupString(ev, s_r, 10, &keysym_return);
196 s_r[num_bytes] = '\0';
198 if (lyxerr.debugging(Debug::KEY)) {
199 char * tmp = XKeysymToString(keysym_return);
200 string stm = (tmp ? tmp : "");
201 lyxerr << "KeySym is "
204 << keysym_return << "]"
205 << " and num_bytes is "
207 << " the string returned is \""
208 << s_r << '\"' << endl;
210 // Do nothing if we have nothing (JMarc)
211 if (num_bytes == 0 && keysym_return == NoSymbol) {
212 lyxerr[Debug::KEY] << "Empty kbd action (probably composing)"
217 // this function should be used always [asierra060396]
218 UpdatableInset * tli = owner->view()->the_locking_inset;
219 if (owner->view()->available() && tli && (keysym_return==XK_Escape)) {
220 if (tli == tli->GetLockingInset()) {
221 owner->view()->unlockInset(tli);
222 owner->view()->text->CursorRight();
223 moveCursorUpdate(false);
224 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
226 tli->UnlockInsetInInset(owner->view(),
227 tli->GetLockingInset());
232 // Can we be sure that this will work for all X-Windows
233 // implementations? (Lgb)
234 // This code snippet makes lyx ignore some keys. Perhaps
235 // all of them should be explictly mentioned?
236 if((keysym_return >= XK_Shift_L && keysym_return <= XK_Hyper_R)
237 || keysym_return == XK_Mode_switch || keysym_return == 0x0)
240 // Do a one-deep top-level lookup for
241 // cancel and meta-fake keys. RVDK_PATCH_5
242 cancel_meta_seq.reset();
244 int action = cancel_meta_seq.addkey(keysym_return, keyevent->state
245 &(ShiftMask|ControlMask
248 // When not cancel or meta-fake, do the normal lookup.
249 // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
250 // Mostly, meta_fake_bit = 0. RVDK_PATCH_5.
251 if ( (action != LFUN_CANCEL) && (action != LFUN_META_FAKE) ) {
253 // remove Caps Lock and Mod2 as a modifiers
254 action = keyseq.addkey(keysym_return,
255 (keyevent->state | meta_fake_bit)
256 &(ShiftMask|ControlMask
259 // Dont remove this unless you know what you are doing.
262 if (action == 0) action = LFUN_PREFIX;
264 if (lyxerr.debugging(Debug::KEY)) {
270 << num_bytes << "]" << endl;
273 // already here we know if it any point in going further
274 // why not return already here if action == -1 and
275 // num_bytes == 0? (Lgb)
277 if(keyseq.length > 1 || keyseq.length < -1) {
280 owner->getMiniBuffer()->Set(buf);
284 if (keyseq.length < -1) { // unknown key sequence...
288 owner->getMiniBuffer()->Set(_("Unknown sequence:"), buf);
292 char isochar = keyseq.getiso();
293 if (!(keyevent->state&ControlMask) &&
294 !(keyevent->state&Mod1Mask) &&
295 (isochar && keysym_return < 0xF000)) {
298 if (argument.empty()) {
299 lyxerr.debug() << "Empty argument!" << endl;
300 // This can`t possibly be of any use
301 // so we`ll skip the dispatch.
305 if (action == LFUN_SELFINSERT) {
309 bool tmp_sc = show_sc;
311 Dispatch(action, argument.c_str());
318 LyXFunc::func_status LyXFunc::getStatus(int ac) const
321 func_status flag = LyXFunc::OK;
323 Buffer * buf = owner->buffer();
325 if (lyxaction.isPseudoAction(ac))
326 action = lyxaction.retrieveActionArg(ac, argument);
328 action = static_cast<kb_action>(ac);
330 if (action == LFUN_UNKNOWN_ACTION) {
331 setErrorMessage(N_("Unknown action"));
332 return LyXFunc::Unknown;
335 // Check whether we need a buffer
336 if (!lyxaction.funcHasFlag(action, LyXAction::NoBuffer)) {
337 // Yes we need a buffer, do we have one?
340 // Can we use a readonly buffer?
341 if (buf->isReadonly() &&
342 !lyxaction.funcHasFlag(action,
343 LyXAction::ReadOnly)) {
345 setErrorMessage(N_("Document is read-only"));
346 flag |= LyXFunc::Disabled;
350 setErrorMessage(N_("Command not allowed with"
351 "out any document open"));
352 flag |= LyXFunc::Disabled;
356 if (flag & LyXFunc::Disabled)
359 // I would really like to avoid having this switch and rather try to
360 // encode this in the function itself.
361 static bool noLaTeX = lyxrc.latex_command == "none";
362 bool disable = false;
365 disable = noLaTeX || lyxrc.view_dvi_command == "none";
368 disable = noLaTeX || lyxrc.view_ps_command == "none";
375 disable = noLaTeX || lyxrc.print_command == "none";
378 disable = noLaTeX || lyxrc.fax_command == "none";
381 if (argument == "latex")
382 disable = lyxrc.relyx_command == "none";
383 if (argument == "linuxdoc")
384 disable = lyxrc.linuxdoc_to_lyx_command == "none";
387 if (argument == "dvi" || argument == "postscript")
389 if (argument == "html")
390 disable = lyxrc.html_command == "none";
391 if (argument == "html-linuxdoc")
392 disable = lyxrc.linuxdoc_to_html_command == "none";
393 if (argument == "html-docbook")
394 disable = lyxrc.docbook_to_html_command == "none";
397 disable = buf->undostack.empty();
400 disable = buf->redostack.empty();
402 case LFUN_SPELLCHECK:
403 disable = lyxrc.isp_command == "none";
406 disable = lyxrc.chktex_command == "none";
408 case LFUN_LAYOUT_TABLE:
409 disable = ! owner->view()->text->cursor.par->table;
415 flag |= LyXFunc::Disabled;
418 func_status box = LyXFunc::ToggleOff;
419 LyXFont font = owner->view()->text->real_current_font;
422 if (font.emph() == LyXFont::ON)
423 box = LyXFunc::ToggleOn;
426 if (font.noun() == LyXFont::ON)
427 box = LyXFunc::ToggleOn;
430 if (font.series() == LyXFont::BOLD_SERIES)
431 box = LyXFunc::ToggleOn;
434 if (font.latex() == LyXFont::ON)
435 box = LyXFunc::ToggleOn;
448 string LyXFunc::Dispatch(string const & s)
450 // Split command string into command and argument
451 string cmd, line = frontStrip(s);
452 string arg = strip(frontStrip(split(line, cmd, ' ')));
454 return Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
458 string LyXFunc::Dispatch(int ac,
459 char const * do_not_use_this_arg)
464 // we have not done anything wrong yet.
466 dispatch_buffer.erase();
468 // if action is a pseudo-action, we need the real action
469 if (lyxaction.isPseudoAction(ac)) {
471 action = static_cast<kb_action>
472 (lyxaction.retrieveActionArg(ac, tmparg));
476 action = static_cast<kb_action>(ac);
477 if (do_not_use_this_arg)
478 argument = do_not_use_this_arg; // except here
481 selection_possible = false;
483 if (owner->view()->available())
484 owner->view()->hideCursor();
486 // We cannot use this function here
487 if (getStatus(action) & Disabled)
488 goto exit_with_message;
490 commandshortcut.erase();
492 if (lyxrc.display_shortcuts && show_sc) {
493 if (action != LFUN_SELFINSERT) {
494 // Put name of command and list of shortcuts
495 // for it in minibuffer
496 string comname = lyxaction.getActionName(action);
498 int pseudoaction = action;
499 bool argsadded = false;
501 if (!argument.empty()) {
502 // If we have the command with argument,
505 lyxaction.searchActionArg(action,
508 if (pseudoaction == -1) {
509 pseudoaction = action;
511 comname += " " + argument;
516 string shortcuts = toplevel_keymap->findbinding(pseudoaction);
518 if (!shortcuts.empty()) {
519 comname += ": " + shortcuts;
520 } else if (!argsadded) {
521 comname += " " + argument;
524 if (!comname.empty()) {
525 comname = strip(comname);
526 commandshortcut = "(" + comname + ')';
527 owner->getMiniBuffer()->Set(commandshortcut);
528 // Here we could even add a small pause,
529 // to annoy the user and make him learn
531 // No! That will just annoy, not teach
532 // anything. The user will read the messages
533 // if they are interested. (Asger)
538 // If in math mode pass the control to
539 // the math inset [asierra060396]
540 if (owner->view()->available() &&
541 owner->view()->the_locking_inset) {
542 UpdatableInset::RESULT result;
544 || (action == LFUN_UNKNOWN_ACTION
545 && keyseq.length >= -1)) {
546 if (action == LFUN_UNKNOWN_ACTION
547 && argument.empty()) {
548 argument = keyseq.getiso();
550 // Undo/Redo pre 0.13 is a bit tricky for insets.
551 if (action == LFUN_UNDO) {
553 UpdatableInset * inset =
554 owner->view()->the_locking_inset;
555 inset->GetCursorPos(slx, sly);
556 owner->view()->unlockInset(inset);
557 owner->view()->menuUndo();
558 if (owner->view()->text->cursor.par->
559 IsInset(owner->view()->text->cursor.pos)) {
560 inset = static_cast<UpdatableInset*>(
561 owner->view()->text->cursor.par->
562 GetInset(owner->view()->text->
568 inset->Edit(owner->view(),slx,sly,0);
570 } else if (action == LFUN_REDO) {
572 UpdatableInset * inset = owner->view()->
574 inset->GetCursorPos(slx, sly);
575 owner->view()->unlockInset(inset);
576 owner->view()->menuRedo();
577 inset = static_cast<UpdatableInset*>(
578 owner->view()->text->cursor.par->
579 GetInset(owner->view()->text->
582 inset->Edit(owner->view(),slx,sly,0);
584 } else if (((result=owner->view()->the_locking_inset->
585 LocalDispatch(owner->view(), action,
587 UpdatableInset::DISPATCHED) ||
588 (result == UpdatableInset::DISPATCHED_NOUPDATE))
591 setMessage(N_("Text mode"));
593 case LFUN_UNKNOWN_ACTION:
594 case LFUN_BREAKPARAGRAPH:
596 owner->view()->text->CursorRight();
597 owner->view()->setState();
598 owner->getMiniBuffer()->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()));
609 if (owner->view()->text->cursor.par->isRightToLeftPar()) {
610 owner->view()->text->CursorRight();
611 moveCursorUpdate(false);
612 owner->getMiniBuffer()->
613 Set(CurrentState(owner->view()));
617 owner->view()->text->CursorDown();
618 moveCursorUpdate(false);
619 owner->getMiniBuffer()->
620 Set(CurrentState(owner->view()));
630 // --- Misc -------------------------------------------
631 case LFUN_WORDFINDFORWARD :
632 case LFUN_WORDFINDBACKWARD : {
633 static string last_search;
634 string searched_string;
636 if (!argument.empty()) {
637 last_search = argument;
638 searched_string = argument;
640 searched_string = last_search;
643 LyXText * ltCur = owner->view()->text ;
645 if (!searched_string.empty() &&
646 ((action == LFUN_WORDFINDBACKWARD) ?
647 ltCur->SearchBackward(searched_string.c_str()) :
648 ltCur->SearchForward(searched_string.c_str()))) {
650 // ??? What is that ???
651 owner->view()->update(-2);
654 // clear the selection (if there is any)
655 owner->view()->toggleSelection();
656 owner->view()->text->ClearSelection();
658 // Move cursor so that successive C-s 's will not stand in place.
659 if( action == LFUN_WORDFINDFORWARD )
660 owner->view()->text->CursorRightOneWord();
661 owner->view()->text->FinishUndo();
662 moveCursorUpdate(false);
665 // set the new selection
666 // SetSelectionOverLenChars(owner->view()->currentBuffer()->text, iLenSelected);
667 owner->view()->toggleSelection(false);
671 // REMOVED : if (owner->view()->getWorkArea()->focus)
672 owner->view()->showCursor();
678 if (owner->view()->available()) {
679 owner->view()->update(-2);
682 keyseq.print(buf, true);
683 owner->getMiniBuffer()->Set(buf, string(), string(), 1);
687 // --- Misc -------------------------------------------
688 case LFUN_EXEC_COMMAND:
689 owner->getMiniBuffer()->ExecCommand();
692 case LFUN_CANCEL: // RVDK_PATCH_5
695 if(owner->view()->available())
696 // cancel any selection
697 Dispatch(LFUN_MARK_OFF, 0);
698 setMessage(N_("Cancel"));
701 case LFUN_META_FAKE: // RVDK_PATCH_5
703 meta_fake_bit = Mod1Mask;
705 keyseq.print(buf, true);
706 string res = string("M-") + buf;
707 setMessage(buf); // RVDK_PATCH_5
711 case LFUN_READ_ONLY_TOGGLE:
712 if (owner->buffer()->lyxvc.inUse()) {
713 owner->buffer()->lyxvc.toggleReadOnly();
715 owner->buffer()->setReadonly(
716 !owner->buffer()->isReadonly());
720 case LFUN_CENTER: // this is center and redraw.
721 owner->view()->center();
725 if (owner->view()->available()) {
726 owner->view()->text->toggleAppendix();
727 owner->view()->update(1);
731 // --- Menus -----------------------------------------------
736 case LFUN_MENUNEWTMPLT:
744 case LFUN_CLOSEBUFFER:
749 owner->getMiniBuffer()->Set(_("Saving document"),
750 MakeDisplayPath(owner->buffer()->fileName()),
752 MenuWrite(owner->buffer());
753 //owner->getMiniBuffer()-> {
754 // Set(_("Document saved as"),
755 // MakeDisplayPath(owner->buffer()->fileName()));
757 //owner->getMiniBuffer()->Set(_("Save failed!"));
761 case LFUN_MENUWRITEAS:
762 MenuWriteAs(owner->buffer());
765 case LFUN_MENURELOAD:
770 PreviewDVI(owner->buffer());
774 PreviewPostscript(owner->buffer());
778 MenuRunLaTeX(owner->buffer());
782 MenuBuildProg(owner->buffer());
786 MenuRunChktex(owner->buffer());
790 CreatePostscript(owner->buffer(), false);
794 MenuPrint(owner->buffer());
798 MenuFax(owner->buffer());
802 MenuExport(owner->buffer(), argument);
815 if (fd_form_toc->form_toc->visible) {
816 fl_raise_form(fd_form_toc->form_toc);
818 static int ow = -1, oh;
819 fl_show_form(fd_form_toc->form_toc,
821 FL_FREE_SIZE, FL_FULLBORDER,
822 _("Table of Contents"));
824 ow = fd_form_toc->form_toc->w;
825 oh = fd_form_toc->form_toc->h;
827 fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
831 case LFUN_TOC_INSERT:
833 Inset * new_inset = new InsetTOC(owner->buffer());
834 if (!owner->view()->insertInset(new_inset, "Standard", true))
839 case LFUN_LOF_INSERT:
841 Inset * new_inset = new InsetLOF(owner->buffer());
842 if (!owner->view()->insertInset(new_inset, "Standard", true))
847 case LFUN_LOA_INSERT:
849 Inset * new_inset = new InsetLOA(owner->buffer());
850 if (!owner->view()->insertInset(new_inset, "Standard", true))
855 case LFUN_LOT_INSERT:
857 Inset * new_inset = new InsetLOT(owner->buffer());
858 if (!owner->view()->insertInset(new_inset, "Standard", true))
871 case LFUN_INSERT_GRAPHICS:
873 Inset * new_inset = new InsetGraphics;
874 if (!owner->view()->insertInset(new_inset))
880 AutoSave(owner->view());
884 owner->view()->menuUndo();
888 owner->view()->menuRedo();
891 case LFUN_MENUSEARCH:
893 // Ok this is one _very_ bad solution, but I think that some
894 // of this will be rewritten as part of GUI indep anyway.
896 static LyXFindReplace FR_;
897 FR_.StartSearch(owner->view());
902 owner->view()->paste();
903 owner->view()->setState();
906 case LFUN_PASTESELECTION:
909 if (argument == "paragraph") asPara = true;
910 #ifdef XFORMS_CLIPBOARD
911 owner->view()->pasteSelection(asPara);
913 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);
989 owner->view()->setState();
990 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
995 owner->view()->setState();
996 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1000 Melt(owner->view());
1003 case LFUN_RECONFIGURE:
1004 Reconfigure(owner->view());
1008 if (owner->view()->available()
1009 && !owner->view()->text->selection
1010 && owner->view()->text->cursor.par->footnoteflag
1011 != LyXParagraph::NO_FOOTNOTE)
1012 { // only melt footnotes with FOOTMELT, not margins etc
1013 if(owner->view()->text->cursor.par->footnotekind == LyXParagraph::FOOTNOTE)
1014 Melt(owner->view());
1017 Foot(owner->view());
1018 owner->view()->setState();
1021 case LFUN_MARGINMELT:
1022 if (owner->view()->available()
1023 && !owner->view()->text->selection
1024 && owner->view()->text->cursor.par->footnoteflag
1025 != LyXParagraph::NO_FOOTNOTE) {
1026 // only melt margins
1027 if(owner->view()->text->cursor.par->footnotekind == LyXParagraph::MARGIN)
1028 Melt(owner->view());
1030 Margin(owner->view());
1031 owner->view()->setState();
1034 // --- version control -------------------------------
1035 case LFUN_VC_REGISTER:
1037 if (!owner->buffer()->lyxvc.inUse())
1038 owner->buffer()->lyxvc.registrer();
1042 case LFUN_VC_CHECKIN:
1044 if (owner->buffer()->lyxvc.inUse()
1045 && !owner->buffer()->isReadonly())
1046 owner->buffer()->lyxvc.checkIn();
1050 case LFUN_VC_CHECKOUT:
1052 if (owner->buffer()->lyxvc.inUse()
1053 && owner->buffer()->isReadonly())
1054 owner->buffer()->lyxvc.checkOut();
1058 case LFUN_VC_REVERT:
1060 owner->buffer()->lyxvc.revert();
1066 owner->buffer()->lyxvc.undoLast();
1070 case LFUN_VC_HISTORY:
1072 owner->buffer()->lyxvc.showLog();
1076 // --- buffers ----------------------------------------
1078 case LFUN_FILE_INSERT:
1080 MenuInsertLyXFile(argument);
1084 case LFUN_FILE_INSERT_ASCII:
1086 bool asPara = (argument == "paragraph");
1087 InsertAsciiFile(owner->view(), string(), asPara);
1093 // servercmd: argument must be <file>:<template>
1094 Buffer * tmpbuf = NewLyxFile(argument);
1096 owner->view()->buffer(tmpbuf);
1100 case LFUN_FILE_OPEN:
1101 owner->view()->buffer(bufferlist.loadLyXFile(argument));
1104 case LFUN_LATEX_LOG:
1110 lyxerr.debug() << "LFUN_LAYOUTNO: (arg) " << argument << endl;
1111 int sel = strToInt(argument);
1112 lyxerr.debug() << "LFUN_LAYOUTNO: (sel) "<< sel << endl;
1114 // Should this give a setMessage instead?
1116 return string(); // illegal argument
1118 --sel; // sel 1..., but layout 0...
1120 // Pretend we got the name instead.
1121 Dispatch(int(LFUN_LAYOUT),
1122 textclasslist.NameOfLayout(owner->view()
1123 ->buffer()->params.textclass,
1130 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1131 << argument << endl;
1133 // Derive layout number from given argument (string)
1134 // and current buffer's textclass (number). */
1135 LyXTextClassList::ClassList::size_type tclass =
1136 owner->view()->buffer()->params.textclass;
1137 pair <bool, LyXTextClass::size_type> layout =
1138 textclasslist.NumberOfLayout(tclass, argument);
1140 // If the entry is obsolete, use the new one instead.
1142 string obs = textclasslist.Style(tclass,layout.second)
1146 textclasslist.NumberOfLayout(tclass, obs);
1149 // see if we found the layout number:
1150 if (!layout.first) {
1151 setErrorMessage(string(N_("Layout ")) + argument +
1156 if (current_layout != layout.second) {
1157 owner->view()->hideCursor();
1158 current_layout = layout.second;
1159 owner->view()->update(-2);
1160 owner->view()->text->
1161 SetLayout(layout.second);
1162 owner->getToolbar()->combox->
1163 select(owner->view()->
1166 owner->view()->update(1);
1167 owner->view()->setState();
1172 case LFUN_LAYOUT_DOCUMENT:
1173 MenuLayoutDocument();
1176 case LFUN_LAYOUT_PARAGRAPH:
1177 MenuLayoutParagraph();
1180 case LFUN_LAYOUT_CHARACTER:
1181 MenuLayoutCharacter();
1184 case LFUN_LAYOUT_TABLE:
1187 if (argument == "true") flag = 1;
1188 MenuLayoutTable(flag);
1192 case LFUN_LAYOUT_PAPER:
1196 case LFUN_LAYOUT_QUOTES:
1200 case LFUN_LAYOUT_PREAMBLE:
1201 MenuLayoutPreamble();
1204 case LFUN_LAYOUT_SAVE_DEFAULT:
1208 case LFUN_DROP_LAYOUTS_CHOICE:
1209 owner->getToolbar()->combox->Show();
1214 Lang(owner->view(), argument);
1215 owner->view()->setState();
1216 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1221 Emph(owner->view());
1222 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1226 Bold(owner->view());
1227 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1231 Noun(owner->view());
1232 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1236 Code(owner->view());
1237 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1241 Sans(owner->view());
1242 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1246 Roman(owner->view());
1247 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1251 StyleReset(owner->view());
1252 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1255 case LFUN_UNDERLINE:
1256 Underline(owner->view());
1257 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1260 case LFUN_FONT_SIZE:
1261 FontSize(owner->view(), argument);
1262 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1265 case LFUN_FONT_STATE:
1266 setMessage(CurrentState(owner->view()));
1269 case LFUN_UPCASE_WORD:
1270 owner->view()->update(-2);
1272 owner->view()->text->ChangeWordCase(LyXText::text_uppercase);
1273 owner->view()->update(1);
1277 case LFUN_LOWCASE_WORD:
1278 owner->view()->update(-2);
1280 owner->view()->text->ChangeWordCase(LyXText::text_lowercase);
1281 owner->view()->update(1);
1285 case LFUN_CAPITALIZE_WORD:
1286 owner->view()->update(-2);
1288 owner->view()->text->ChangeWordCase(LyXText::text_capitalization);
1289 owner->view()->update(1);
1293 case LFUN_INSERT_LABEL:
1294 MenuInsertLabel(argument.c_str());
1297 case LFUN_INSERT_REF:
1301 case LFUN_REFTOGGLE:
1304 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1307 owner->view()->updateInset(inset, true);
1309 setErrorMessage(N_("No cross-reference to toggle"));
1316 owner->view()->restorePosition();
1322 string label(argument);
1323 if (label.empty()) {
1325 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1327 label = inset->getContents();
1330 if (!label.empty()) {
1331 owner->view()->savePosition();
1332 if (!owner->view()->gotoLabel(label))
1333 WriteAlert(_("Error"),
1334 _("Couldn't find this label"),
1335 _("in current document."));
1340 case LFUN_MENU_OPEN_BY_NAME:
1341 owner->getMenus()->openByName(argument);
1342 break; // RVDK_PATCH_5
1344 case LFUN_SPELLCHECK:
1345 if (lyxrc.isp_command != "none")
1346 ShowSpellChecker(owner->view());
1347 break; // RVDK_PATCH_5
1349 // --- Cursor Movements -----------------------------
1352 LyXText * tmptext = owner->view()->text;
1353 bool is_rtl = tmptext->cursor.par->isRightToLeftPar();
1354 if(!tmptext->mark_set)
1355 owner->view()->beforeChange();
1356 owner->view()->update(-2);
1358 tmptext->CursorLeft();
1359 if (tmptext->cursor.pos < tmptext->cursor.par->Last()
1360 && tmptext->cursor.par->GetChar(tmptext->cursor.pos)
1361 == LyXParagraph::META_INSET
1362 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)
1363 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)->Editable() == Inset::HIGHLY_EDITABLE){
1364 Inset * tmpinset = tmptext->cursor.par->GetInset(tmptext->cursor.pos);
1365 setMessage(tmpinset->EditMessage());
1366 tmpinset->Edit(owner->view(), 0, 0, 0);
1370 tmptext->CursorRight();
1371 owner->view()->text->FinishUndo();
1372 moveCursorUpdate(false);
1373 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1379 // This is soooo ugly. Isn`t it possible to make
1380 // it simpler? (Lgb)
1381 LyXText * txt = owner->view()->text;
1382 bool is_rtl = txt->cursor.par->isRightToLeftPar();
1383 if(!txt->mark_set) owner->view()->beforeChange();
1384 owner->view()->update(-2);
1387 if (txt->cursor.pos < txt->cursor.par->Last()
1388 && txt->cursor.par->GetChar(txt->cursor.pos)
1389 == LyXParagraph::META_INSET
1390 && txt->cursor.par->GetInset(txt->cursor.pos)
1391 && txt->cursor.par->GetInset(txt->cursor.pos)->Editable() == Inset::HIGHLY_EDITABLE) {
1392 Inset * tmpinset = txt->cursor.par->GetInset(txt->cursor.pos);
1393 setMessage(tmpinset->EditMessage());
1394 LyXFont font = txt->GetFont(txt->cursor.par,
1396 tmpinset->Edit(owner->view(),
1397 tmpinset->x() + tmpinset->width(owner->view()->painter(),font),
1398 tmpinset->descent(owner->view()->painter(),font),
1405 owner->view()->text->FinishUndo();
1406 moveCursorUpdate(false);
1407 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1412 if(!owner->view()->text->mark_set) owner->view()->beforeChange();
1413 owner->view()->update(-3);
1414 owner->view()->text->CursorUp();
1415 owner->view()->text->FinishUndo();
1416 moveCursorUpdate(false);
1417 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1421 if(!owner->view()->text->mark_set)
1422 owner->view()->beforeChange();
1423 owner->view()->update(-3);
1424 owner->view()->text->CursorDown();
1425 owner->view()->text->FinishUndo();
1426 moveCursorUpdate(false);
1427 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1430 case LFUN_UP_PARAGRAPH:
1431 if(!owner->view()->text->mark_set)
1432 owner->view()->beforeChange();
1433 owner->view()->update(-3);
1434 owner->view()->text->CursorUpParagraph();
1435 owner->view()->text->FinishUndo();
1436 moveCursorUpdate(false);
1437 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1440 case LFUN_DOWN_PARAGRAPH:
1441 if(!owner->view()->text->mark_set)
1442 owner->view()->beforeChange();
1443 owner->view()->update(-3);
1444 owner->view()->text->CursorDownParagraph();
1445 owner->view()->text->FinishUndo();
1446 moveCursorUpdate(false);
1447 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1451 if(!owner->view()->text->mark_set)
1452 owner->view()->beforeChange();
1453 owner->view()->update(-3);
1454 owner->view()->cursorPrevious();
1455 owner->view()->text->FinishUndo();
1456 moveCursorUpdate(false);
1457 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1461 if(!owner->view()->text->mark_set)
1462 owner->view()->beforeChange();
1463 owner->view()->update(-3);
1464 owner->view()->cursorNext();
1465 owner->view()->text->FinishUndo();
1466 moveCursorUpdate(false);
1467 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1471 if(!owner->view()->text->mark_set)
1472 owner->view()->beforeChange();
1473 owner->view()->update(-2);
1474 owner->view()->text->CursorHome();
1475 owner->view()->text->FinishUndo();
1476 moveCursorUpdate(false);
1477 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1481 if(!owner->view()->text->mark_set)
1482 owner->view()->beforeChange();
1483 owner->view()->update(-2);
1484 owner->view()->text->CursorEnd();
1485 owner->view()->text->FinishUndo();
1486 moveCursorUpdate(false);
1487 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1491 if(!owner->view()->text->mark_set)
1492 owner->view()->beforeChange();
1493 owner->view()->update(-2);
1494 owner->view()->text->CursorTab();
1495 owner->view()->text->FinishUndo();
1496 moveCursorUpdate(false);
1497 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1500 case LFUN_WORDRIGHT:
1501 if(!owner->view()->text->mark_set)
1502 owner->view()->beforeChange();
1503 owner->view()->update(-2);
1504 if (owner->view()->text->cursor.par->isRightToLeftPar())
1505 owner->view()->text->CursorLeftOneWord();
1507 owner->view()->text->CursorRightOneWord();
1508 owner->view()->text->FinishUndo();
1509 moveCursorUpdate(false);
1510 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1514 if(!owner->view()->text->mark_set)
1515 owner->view()->beforeChange();
1516 owner->view()->update(-2);
1517 if (owner->view()->text->cursor.par->isRightToLeftPar())
1518 owner->view()->text->CursorRightOneWord();
1520 owner->view()->text->CursorLeftOneWord();
1521 owner->view()->text->FinishUndo();
1522 moveCursorUpdate(false);
1523 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1526 case LFUN_BEGINNINGBUF:
1527 if(!owner->view()->text->mark_set)
1528 owner->view()->beforeChange();
1529 owner->view()->update(-2);
1530 owner->view()->text->CursorTop();
1531 owner->view()->text->FinishUndo();
1532 moveCursorUpdate(false);
1533 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1537 if(!owner->view()->text->mark_set)
1538 owner->view()->beforeChange();
1539 owner->view()->update(-2);
1540 owner->view()->text->CursorBottom();
1541 owner->view()->text->FinishUndo();
1542 moveCursorUpdate(false);
1543 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1547 /* cursor selection ---------------------------- */
1549 owner->view()->update(-2);
1550 if (owner->view()->text->cursor.par->isRightToLeftPar())
1551 owner->view()->text->CursorLeft();
1553 owner->view()->text->CursorRight();
1554 owner->view()->text->FinishUndo();
1555 moveCursorUpdate(true);
1556 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1560 owner->view()->update(-2);
1561 if (owner->view()->text->cursor.par->isRightToLeftPar())
1562 owner->view()->text->CursorRight();
1564 owner->view()->text->CursorLeft();
1565 owner->view()->text->FinishUndo();
1566 moveCursorUpdate(true);
1567 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1571 owner->view()->update(-2);
1572 owner->view()->text->CursorUp();
1573 owner->view()->text->FinishUndo();
1574 moveCursorUpdate(true);
1575 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1579 owner->view()->update(-2);
1580 owner->view()->text->CursorDown();
1581 owner->view()->text->FinishUndo();
1582 moveCursorUpdate(true);
1583 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1586 case LFUN_UP_PARAGRAPHSEL:
1587 owner->view()->update(-2);
1588 owner->view()->text->CursorUpParagraph();
1589 owner->view()->text->FinishUndo();
1590 moveCursorUpdate(true);
1591 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1594 case LFUN_DOWN_PARAGRAPHSEL:
1595 owner->view()->update(-2);
1596 owner->view()->text->CursorDownParagraph();
1597 owner->view()->text->FinishUndo();
1598 moveCursorUpdate(true);
1599 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1603 owner->view()->update(-2);
1604 owner->view()->cursorPrevious();
1605 owner->view()->text->FinishUndo();
1606 moveCursorUpdate(true);
1607 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1611 owner->view()->update(-2);
1612 owner->view()->cursorNext();
1613 owner->view()->text->FinishUndo();
1614 moveCursorUpdate(true);
1615 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1619 owner->view()->update(-2);
1620 owner->view()->text->CursorHome();
1621 owner->view()->text->FinishUndo();
1622 moveCursorUpdate(true);
1623 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1627 owner->view()->update(-2);
1628 owner->view()->text->CursorEnd();
1629 owner->view()->text->FinishUndo();
1630 moveCursorUpdate(true);
1631 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1634 case LFUN_WORDRIGHTSEL:
1635 owner->view()->update(-2);
1636 if (owner->view()->text->cursor.par->isRightToLeftPar())
1637 owner->view()->text->CursorLeftOneWord();
1639 owner->view()->text->CursorRightOneWord();
1640 owner->view()->text->FinishUndo();
1641 moveCursorUpdate(true);
1642 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1645 case LFUN_WORDLEFTSEL:
1646 owner->view()->update(-2);
1647 if (owner->view()->text->cursor.par->isRightToLeftPar())
1648 owner->view()->text->CursorRightOneWord();
1650 owner->view()->text->CursorLeftOneWord();
1651 owner->view()->text->FinishUndo();
1652 moveCursorUpdate(true);
1653 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1656 case LFUN_BEGINNINGBUFSEL:
1657 owner->view()->update(-2);
1658 owner->view()->text->CursorTop();
1659 owner->view()->text->FinishUndo();
1660 moveCursorUpdate(true);
1661 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1664 case LFUN_ENDBUFSEL:
1665 owner->view()->update(-2);
1666 owner->view()->text->CursorBottom();
1667 owner->view()->text->FinishUndo();
1668 moveCursorUpdate(true);
1669 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1672 // --- text changing commands ------------------------
1673 case LFUN_BREAKLINE:
1674 owner->view()->beforeChange();
1675 owner->view()->text->InsertChar(LyXParagraph::META_NEWLINE);
1676 owner->view()->update(1);
1677 SetUpdateTimer(0.01);
1678 moveCursorUpdate(false);
1681 case LFUN_PROTECTEDSPACE:
1683 LyXLayout const & style =
1684 textclasslist.Style(owner->view()->buffer()->params.textclass,
1685 owner->view()->text->cursor.par->GetLayout());
1687 if (style.free_spacing) {
1688 owner->view()->text->InsertChar(' ');
1689 owner->view()->update(-1);
1691 owner->view()->protectedBlank();
1693 moveCursorUpdate(false);
1698 if(owner->view()->text->mark_set) {
1699 owner->view()->beforeChange();
1700 owner->view()->update(0);
1701 setMessage(N_("Mark removed"));
1703 owner->view()->beforeChange();
1704 owner->view()->text->mark_set = 1;
1705 owner->view()->update(0);
1706 setMessage(N_("Mark set"));
1708 owner->view()->text->sel_cursor =
1709 owner->view()->text->cursor;
1714 if (!owner->view()->text->selection) {
1715 owner->view()->text->Delete();
1716 owner->view()->text->sel_cursor =
1717 owner->view()->text->cursor;
1718 owner->view()->update(1);
1719 // It is possible to make it a lot faster still
1720 // just comment out the lone below...
1721 owner->view()->showCursor();
1723 owner->view()->cut();
1726 moveCursorUpdate(false);
1727 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1728 owner->view()->setState();
1731 case LFUN_DELETE_SKIP:
1733 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1735 LyXCursor cursor = owner->view()->text->cursor;
1738 if (!owner->view()->text->selection) {
1739 if (cursor.pos == cursor.par->Last()) {
1740 owner->view()->text->CursorRight();
1741 cursor = owner->view()->text->cursor;
1743 && !(cursor.par->added_space_top
1744 == VSpace (VSpace::NONE))) {
1745 owner->view()->text->SetParagraph
1746 (cursor.par->line_top,
1747 cursor.par->line_bottom,
1748 cursor.par->pagebreak_top,
1749 cursor.par->pagebreak_bottom,
1750 VSpace(VSpace::NONE),
1751 cursor.par->added_space_bottom,
1753 cursor.par->labelwidthstring, 0);
1754 owner->view()->text->CursorLeft();
1755 owner->view()->update (1);
1757 owner->view()->text->CursorLeft();
1758 owner->view()->text->Delete();
1759 owner->view()->text->sel_cursor =
1760 owner->view()->text->cursor;
1761 owner->view()->update(1);
1764 owner->view()->text->Delete();
1765 owner->view()->text->sel_cursor =
1766 owner->view()->text->cursor;
1767 owner->view()->update(1);
1770 owner->view()->cut();
1776 /* -------> Delete word forward. */
1777 case LFUN_DELETE_WORD_FORWARD:
1778 owner->view()->update(-2);
1780 owner->view()->text->DeleteWordForward();
1781 owner->view()->update( 1 );
1783 moveCursorUpdate(false);
1784 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1787 /* -------> Delete word backward. */
1788 case LFUN_DELETE_WORD_BACKWARD:
1789 owner->view()->update(-2);
1791 owner->view()->text->DeleteWordBackward();
1792 owner->view()->update( 1 );
1794 moveCursorUpdate(false);
1795 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1798 /* -------> Kill to end of line. */
1799 case LFUN_DELETE_LINE_FORWARD:
1801 owner->view()->update(-2);
1802 owner->view()->text->DeleteLineForward();
1803 owner->view()->update( 1 );
1805 moveCursorUpdate(false);
1808 /* -------> Set mark off. */
1810 owner->view()->beforeChange();
1811 owner->view()->update(0);
1812 owner->view()->text->sel_cursor =
1813 owner->view()->text->cursor;
1814 setMessage(N_("Mark off"));
1817 /* -------> Set mark on. */
1819 owner->view()->beforeChange();
1820 owner->view()->text->mark_set = 1;
1821 owner->view()->update( 0 );
1822 owner->view()->text->sel_cursor =
1823 owner->view()->text->cursor;
1824 setMessage(N_("Mark on"));
1827 case LFUN_BACKSPACE:
1830 if (!owner->view()->text->selection) {
1831 if (owner->getIntl()->getTrans()->backspace()) {
1832 owner->view()->text->Backspace();
1833 owner->view()->text->sel_cursor =
1834 owner->view()->text->cursor;
1835 owner->view()->update(1);
1836 // It is possible to make it a lot faster still
1837 // just comment out the lone below...
1838 owner->view()->showCursor();
1841 owner->view()->cut();
1844 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1845 owner->view()->setState();
1849 case LFUN_BACKSPACE_SKIP:
1851 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1853 LyXCursor cursor = owner->view()->text->cursor;
1856 if (!owner->view()->text->selection) {
1858 && !(cursor.par->added_space_top
1859 == VSpace (VSpace::NONE))) {
1860 owner->view()->text->SetParagraph
1861 (cursor.par->line_top,
1862 cursor.par->line_bottom,
1863 cursor.par->pagebreak_top,
1864 cursor.par->pagebreak_bottom,
1865 VSpace(VSpace::NONE), cursor.par->added_space_bottom,
1867 cursor.par->labelwidthstring, 0);
1868 owner->view()->update (1);
1870 owner->view()->text->Backspace();
1871 owner->view()->text->sel_cursor
1873 owner->view()->update(1);
1876 owner->view()->cut();
1881 case LFUN_BREAKPARAGRAPH:
1883 owner->view()->beforeChange();
1884 owner->view()->text->BreakParagraph(0);
1885 owner->view()->update(1);
1886 SetUpdateTimer(0.01);
1887 owner->view()->text->sel_cursor =
1888 owner->view()->text->cursor;
1889 owner->view()->setState();
1890 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1894 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1896 owner->view()->beforeChange();
1897 owner->view()->text->BreakParagraph(1);
1898 owner->view()->update(1);
1899 SetUpdateTimer(0.01);
1900 owner->view()->text->sel_cursor =
1901 owner->view()->text->cursor;
1902 owner->view()->setState();
1903 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1907 case LFUN_BREAKPARAGRAPH_SKIP:
1909 // When at the beginning of a paragraph, remove
1910 // indentation and add a "defskip" at the top.
1911 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
1913 LyXCursor cursor = owner->view()->text->cursor;
1915 owner->view()->beforeChange();
1916 if (cursor.pos == 0) {
1917 if (cursor.par->added_space_top == VSpace(VSpace::NONE)) {
1918 owner->view()->text->SetParagraph
1919 (cursor.par->line_top,
1920 cursor.par->line_bottom,
1921 cursor.par->pagebreak_top,
1922 cursor.par->pagebreak_bottom,
1923 VSpace(VSpace::DEFSKIP), cursor.par->added_space_bottom,
1925 cursor.par->labelwidthstring, 1);
1926 owner->view()->update(1);
1930 owner->view()->text->BreakParagraph(0);
1931 owner->view()->update(1);
1933 SetUpdateTimer(0.01);
1934 owner->view()->text->sel_cursor = cursor;
1935 owner->view()->setState();
1936 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1940 case LFUN_PARAGRAPH_SPACING:
1942 LyXParagraph * par = owner->view()->text->cursor.par;
1943 Spacing::Space cur_spacing = par->spacing.getSpace();
1944 float cur_value = 1.0;
1945 if (cur_spacing == Spacing::Other) {
1946 cur_value = par->spacing.getValue();
1950 istringstream istr(argument);
1952 istrstream istr(argument.c_str());
1956 Spacing::Space new_spacing = cur_spacing;
1957 float new_value = cur_value;
1959 lyxerr << "Missing argument to `paragraph-spacing'"
1961 } else if (tmp == "single") {
1962 new_spacing = Spacing::Single;
1963 } else if (tmp == "onehalf") {
1964 new_spacing = Spacing::Onehalf;
1965 } else if (tmp == "double") {
1966 new_spacing = Spacing::Double;
1967 } else if (tmp == "other") {
1968 new_spacing = Spacing::Other;
1971 lyxerr << "new_value = " << tmpval << endl;
1974 } else if (tmp == "default") {
1975 new_spacing = Spacing::Default;
1977 lyxerr << _("Unknown spacing argument: ")
1978 << argument << endl;
1980 if (cur_spacing != new_spacing || cur_value != new_value) {
1981 par->spacing.set(new_spacing, new_value);
1982 owner->view()->text->RedoParagraph();
1983 owner->view()->update(-1);
1989 owner->view()->beforeChange();
1990 owner->view()->text->InsertChar('\"'); // This " matches the single quote in the code
1991 owner->view()->update(1);
1993 moveCursorUpdate(false);
1999 InsetCommand * new_inset;
2000 if (action == LFUN_HTMLURL)
2001 new_inset = new InsetUrl("htmlurl", "", "");
2003 new_inset = new InsetUrl("url", "", "");
2004 if (owner->view()->insertInset(new_inset))
2005 new_inset->Edit(owner->view(), 0, 0, 0);
2011 case LFUN_INSET_TEXT:
2013 InsetText * new_inset = new InsetText(owner->buffer());
2014 if (owner->view()->insertInset(new_inset))
2015 new_inset->Edit(owner->view(), 0, 0, 0);
2020 case LFUN_INSET_ERT:
2022 InsetERT * new_inset = new InsetERT(owner->buffer());
2023 if (owner->view()->insertInset(new_inset))
2024 new_inset->Edit(owner->view(), 0, 0, 0);
2030 case LFUN_INSET_FOOTNOTE:
2032 InsetFoot * new_inset = new InsetFoot(owner->buffer());
2033 if (owner->view()->insertInset(new_inset))
2034 new_inset->Edit(owner->view(), 0, 0, 0);
2040 case LFUN_INSET_TABULAR:
2043 if (!argument.empty())
2044 sscanf(argument.c_str(),"%d%d",&r,&c);
2045 InsetTabular * new_inset = new InsetTabular(owner->buffer(),r,c);
2046 if (owner->view()->insertInset(new_inset))
2047 new_inset->Edit(owner->view(), 0, 0, 0);
2053 // --- lyxserver commands ----------------------------
2055 case LFUN_CHARATCURSOR:
2057 LyXParagraph::size_type pos =
2058 owner->view()->text->cursor.pos;
2059 if(pos < owner->view()->text->cursor.par->size())
2060 //dispatch_buffer = owner->view()->text->
2061 // cursor.par->text[pos];
2063 owner->view()->text->
2064 cursor.par->GetChar(pos);
2066 dispatch_buffer = "EOF";
2072 tostr(owner->view()->text->cursor.x) + ' '
2073 + tostr(owner->view()->text->cursor.y);
2080 sscanf(argument.c_str(), " %d %ld", &x, &y);
2081 owner->view()->text->SetCursorFromCoordinates(x, y);
2085 case LFUN_GETLAYOUT:
2087 tostr(owner->view()->text->cursor.par->layout);
2092 LyXFont & font = owner->view()->text->current_font;
2093 if(font.shape() == LyXFont::ITALIC_SHAPE)
2094 dispatch_buffer = 'E';
2095 else if(font.shape() == LyXFont::SMALLCAPS_SHAPE)
2096 dispatch_buffer = 'N';
2098 dispatch_buffer = '0';
2105 LyXFont & font = owner->view()->text->current_font;
2106 if(font.latex() == LyXFont::ON)
2107 dispatch_buffer = 'L';
2109 dispatch_buffer = '0';
2114 setMessage(owner->buffer()->fileName());
2115 lyxerr.debug() << "FNAME["
2116 << owner->buffer()->fileName()
2124 dispatch_buffer = buf;
2125 lyxserver->notifyClient(dispatch_buffer);
2129 case LFUN_GOTOFILEROW:
2131 char file_name[100];
2133 sscanf(argument.c_str(), " %s %d", file_name, &row);
2135 // Must replace extension of the file to be .lyx and get full path
2136 string s = ChangeExtension(string(file_name), ".lyx");
2138 // Either change buffer or load the file
2139 if (bufferlist.exists(s))
2140 owner->view()->buffer(bufferlist.getBuffer(s));
2142 owner->view()->buffer(bufferlist.loadLyXFile(s));
2145 owner->view()->setCursorFromRow(row);
2148 owner->view()->center();
2155 int qa = lyxaction.LookupFunc(argument.c_str());
2156 setMessage(lyxaction.helpText(static_cast<kb_action>(qa)));
2160 // --- accented characters ---------------------------
2163 case LFUN_CIRCUMFLEX:
2173 case LFUN_SPECIAL_CARON:
2176 case LFUN_HUNG_UMLAUT:
2182 if (keyseq.length == -1 && keyseq.getiso() != 0)
2183 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()->update(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 if (!owner->view()->insertInset(new_inset))
2345 if (owner->view()->insertInset(new_inset))
2346 new_inset->Edit(owner->view(), 0, 0, 0);
2353 case LFUN_INSERT_BIBTEX:
2355 // ale970405+lasgoutt970425
2356 // The argument can be up to two tokens separated
2357 // by a space. The first one is the bibstyle.
2358 string lsarg(argument);
2359 string bibstyle = token(lsarg, ' ', 1);
2360 if (bibstyle.empty())
2362 InsetBibtex * new_inset
2363 = new InsetBibtex(token(lsarg, ' ', 0),
2367 if (owner->view()->insertInset(new_inset)) {
2369 new_inset->Edit(owner->view(), 0, 0, 0);
2375 // BibTeX data bases
2376 case LFUN_BIBDB_ADD:
2378 InsetBibtex * inset =
2379 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2381 inset->addDatabase(argument);
2386 case LFUN_BIBDB_DEL:
2388 InsetBibtex * inset =
2389 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2391 inset->delDatabase(argument);
2396 case LFUN_BIBTEX_STYLE:
2398 InsetBibtex * inset =
2399 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2401 inset->setOptions(argument);
2406 case LFUN_INDEX_INSERT:
2407 case LFUN_INDEX_INSERT_LAST:
2409 // Can't do that at the beginning of a paragraph.
2410 if (owner->view()->text->cursor.pos - 1 < 0)
2413 InsetIndex * new_inset = new InsetIndex();
2414 if (!argument.empty()) {
2415 string lsarg(argument);
2416 new_inset->setContents(lsarg);
2417 if (!owner->view()->insertInset(new_inset))
2421 //get the current word for an argument
2422 LyXParagraph::size_type lastpos =
2423 owner->view()->text->cursor.pos - 1;
2424 // Get the current word. note that this must be done
2425 // before inserting the inset, or the inset will
2427 string curstring(owner->view()
2428 ->text->cursor.par->GetWord(lastpos));
2430 //make the new inset and write the current word into it
2431 InsetIndex * new_inset = new InsetIndex();
2433 new_inset->setContents(curstring);
2435 //don't edit it if the call was to INSERT_LAST
2436 if(action != LFUN_INDEX_INSERT_LAST) {
2437 new_inset->Edit(owner->view(), 0, 0, 0);
2439 //it looks blank on the screen unless
2440 //we do something. put it here.
2442 // move the cursor to the returned value of lastpos
2443 // but only for the auto-insert
2444 owner->view()->text->cursor.pos = lastpos;
2447 //put the new inset into the buffer.
2448 // there should be some way of knowing the user
2449 //cancelled & avoiding this, but i don't know how
2450 if (!owner->view()->insertInset(new_inset))
2456 case LFUN_INDEX_PRINT:
2458 Inset * new_inset = new InsetPrintIndex(owner->buffer());
2459 if (!owner->view()->insertInset(new_inset, "Standard", true))
2464 case LFUN_PARENTINSERT:
2466 lyxerr << "arg " << argument << endl;
2467 Inset * new_inset = new InsetParent(argument, owner->buffer());
2468 if (!owner->view()->insertInset(new_inset, "Standard", true))
2473 case LFUN_CHILDINSERT:
2475 Inset * new_inset = new InsetInclude(argument,
2477 if (owner->view()->insertInset(new_inset, "Standard", true))
2478 new_inset->Edit(owner->view(), 0, 0, 0);
2484 case LFUN_CHILDOPEN:
2487 MakeAbsPath(argument,
2488 OnlyPath(owner->buffer()->fileName()));
2489 setMessage(N_("Opening child document ") +
2490 MakeDisplayPath(filename) + "...");
2491 owner->view()->savePosition();
2492 if (bufferlist.exists(filename))
2493 owner->view()->buffer(bufferlist.getBuffer(filename));
2495 owner->view()->buffer(bufferlist.loadLyXFile(filename));
2499 case LFUN_INSERT_NOTE:
2500 owner->view()->insertNote();
2503 case LFUN_INSERTFOOTNOTE:
2505 LyXParagraph::footnote_kind kind;
2506 if (argument == "footnote")
2507 { kind = LyXParagraph::FOOTNOTE; }
2508 else if (argument == "margin")
2509 { kind = LyXParagraph::MARGIN; }
2510 else if (argument == "figure")
2511 { kind = LyXParagraph::FIG; }
2512 else if (argument == "table")
2513 { kind = LyXParagraph::TAB; }
2514 else if (argument == "wide-fig")
2515 { kind = LyXParagraph::WIDE_FIG; }
2516 else if (argument == "wide-tab")
2517 { kind = LyXParagraph::WIDE_TAB; }
2518 else if (argument == "algorithm")
2519 { kind = LyXParagraph::ALGORITHM; }
2521 setErrorMessage(N_("Unknown kind of footnote"));
2524 owner->view()->text->InsertFootnoteEnvironment(kind);
2525 owner->view()->update(1);
2526 owner->view()->setState();
2530 case LFUN_BUFFERBULLETSSELECT:
2534 case LFUN_TOGGLECURSORFOLLOW:
2535 cursor_follows_scrollbar = !cursor_follows_scrollbar;
2538 case LFUN_KMAP_OFF: // keymap off
2539 owner->getIntl()->KeyMapOn(false);
2542 case LFUN_KMAP_PRIM: // primary keymap
2543 owner->getIntl()->KeyMapPrim();
2546 case LFUN_KMAP_SEC: // secondary keymap
2547 owner->getIntl()->KeyMapSec();
2550 case LFUN_KMAP_TOGGLE: // toggle keymap
2551 owner->getIntl()->ToggleKeyMap();
2554 case LFUN_SELFINSERT:
2556 for (string::size_type i = 0; i < argument.length(); ++i) {
2557 owner->view()->text->InsertChar(argument[i]);
2558 // This needs to be in the loop, or else we
2559 // won't break lines correctly. (Asger)
2560 owner->view()->update(1);
2563 owner->view()->text->sel_cursor =
2564 owner->view()->text->cursor;
2565 moveCursorUpdate(false);
2571 // argument contains ';'-terminated commands
2572 while (argument.find(';') != string::npos) {
2574 argument = split(argument, first, ';');
2580 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
2588 now_time_t = time(NULL);
2589 now_tm = localtime(&now_time_t);
2590 (void)setlocale(LC_TIME, "");
2591 if (!argument.empty())
2593 else if (arg.empty())
2594 arg = lyxrc.date_insert_format;
2595 datetmp_len = (int) strftime(datetmp, 32, arg.c_str(), now_tm);
2596 for (int i = 0; i < datetmp_len; i++) {
2597 owner->view()->text->InsertChar(datetmp[i]);
2598 owner->view()->update(1);
2601 owner->view()->text->sel_cursor = owner->view()->text->cursor;
2602 moveCursorUpdate(false);
2606 case LFUN_SAVEPREFERENCES:
2608 Path p(user_lyxdir);
2609 lyxrc.write("preferences");
2613 case LFUN_UNKNOWN_ACTION:
2615 if(!owner->buffer()) {
2617 setErrorMessage(N_("No document open"));
2621 if (owner->buffer()->isReadonly()) {
2623 setErrorMessage(N_("Document is read only"));
2627 if (!argument.empty()) {
2629 /* Automatically delete the currently selected
2630 * text and replace it with what is being
2631 * typed in now. Depends on lyxrc settings
2632 * "auto_region_delete", which defaults to
2635 if ( lyxrc.auto_region_delete ) {
2636 if (owner->view()->text->selection){
2637 owner->view()->text->CutSelection(false);
2638 owner->view()->update(-1);
2642 owner->view()->beforeChange();
2644 for (string::size_type i = 0;
2645 i < argument.length(); ++i) {
2646 if (greek_kb_flag) {
2647 if (!math_insert_greek(argument[i]))
2648 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2650 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2653 owner->view()->update(1);
2656 owner->view()->text->sel_cursor =
2657 owner->view()->text->cursor;
2658 moveCursorUpdate(false);
2661 // why is an "Unknown action" with empty
2662 // argument even dispatched in the first
2663 // place? I`ll probably change that. (Lgb)
2665 setErrorMessage(N_("Unknown action"));
2669 lyxerr << "A truly unknown func!" << endl;
2675 string res = getMessage();
2678 if (!commandshortcut.empty()) {
2679 string newbuf = owner->getMiniBuffer()->GetText();
2680 if (newbuf != commandshortcut) {
2681 owner->getMiniBuffer()->Set(newbuf
2687 owner->getMiniBuffer()->Set(string(_(res.c_str()))
2688 + " " + commandshortcut);
2695 void LyXFunc::setupLocalKeymap()
2697 keyseq.stdmap = keyseq.curmap = toplevel_keymap;
2698 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap;
2702 void LyXFunc::MenuNew(bool fromTemplate)
2704 string fname, initpath = lyxrc.document_path;
2707 if (owner->view()->available()) {
2708 string trypath = owner->buffer()->filepath;
2709 // If directory is writeable, use this as default.
2710 if (IsDirWriteable(trypath) == 1)
2714 ProhibitInput(owner->view());
2715 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
2716 fileDlg.SetButton(1, _("Templates"), lyxrc.template_path);
2717 fname = fileDlg.Select(_("Enter Filename for new document"),
2718 initpath, "*.lyx", _("newfile"));
2719 AllowInput(owner->view());
2721 if (fname.empty()) {
2722 owner->getMiniBuffer()->Set(_("Canceled."));
2723 lyxerr.debug() << "New Document Cancelled." << endl;
2727 // get absolute path of file and make sure the filename ends
2729 string s = MakeAbsPath(fname);
2730 if (!IsLyXFilename(s))
2733 // Check if the document already is open
2734 if (bufferlist.exists(s)){
2735 switch(AskConfirmation(_("Document is already open:"),
2736 MakeDisplayPath(s, 50),
2737 _("Do you want to close that document now?\n"
2738 "('No' will just switch to the open version)")))
2740 case 1: // Yes: close the document
2741 if (!bufferlist.close(bufferlist.getBuffer(s)))
2742 // If close is canceled, we cancel here too.
2745 case 2: // No: switch to the open document
2746 owner->view()->buffer(bufferlist.getBuffer(s));
2748 case 3: // Cancel: Do nothing
2749 owner->getMiniBuffer()->Set(_("Canceled."));
2754 // Check whether the file already exists
2755 if (IsLyXFilename(s)) {
2757 if (fi.readable() &&
2758 AskQuestion(_("File already exists:"),
2759 MakeDisplayPath(s, 50),
2760 _("Do you want to open the document?"))) {
2762 owner->getMiniBuffer()->Set(_("Opening document"),
2763 MakeDisplayPath(s), "...");
2765 owner->view()->buffer(
2766 bufferlist.loadLyXFile(s));
2767 owner->getMiniBuffer()->Set(_("Document"),
2774 // The template stuff
2777 ProhibitInput(owner->view());
2778 fname = fileDlg.Select(_("Choose template"),
2779 lyxrc.template_path,
2782 AllowInput(owner->view());
2785 // find a free buffer
2786 lyxerr.debug() << "Find a free buffer." << endl;
2787 owner->view()->buffer(bufferlist.newFile(s, templname));
2791 void LyXFunc::MenuOpen()
2793 string initpath = lyxrc.document_path;
2796 if (owner->view()->available()) {
2797 string trypath = owner->buffer()->filepath;
2798 // If directory is writeable, use this as default.
2799 if (IsDirWriteable(trypath) == 1)
2804 ProhibitInput(owner->view());
2805 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
2806 fileDlg.SetButton(1, _("Examples"),
2807 AddPath(system_lyxdir, "examples"));
2808 string filename = fileDlg.Select(_("Select Document to Open"),
2810 AllowInput(owner->view());
2812 // check selected filename
2813 if (filename.empty()) {
2814 owner->getMiniBuffer()->Set(_("Canceled."));
2818 // get absolute path of file and make sure the filename ends
2820 filename = MakeAbsPath(filename);
2821 if (!IsLyXFilename(filename))
2825 owner->getMiniBuffer()->Set(_("Opening document"),
2826 MakeDisplayPath(filename), "...");
2827 Buffer * openbuf = bufferlist.loadLyXFile(filename);
2829 owner->view()->buffer(openbuf);
2830 owner->getMiniBuffer()->Set(_("Document"),
2831 MakeDisplayPath(filename),
2834 owner->getMiniBuffer()->Set(_("Could not open document"),
2835 MakeDisplayPath(filename));
2839 // returns filename if file must be imported,
2840 // empty string if either file not found or already loaded
2841 // checks for running without gui are missing.
2843 void LyXFunc::doImportHelper(
2844 string const & file, // filename (possibly empty)
2845 string const & text, // info when asking for filename
2846 string const & pattern, // filetype
2847 bool func(BufferView *, string const &) // the real import function
2850 string filename = file;
2852 if (filename.empty()) { // need user interaction
2853 string initpath = lyxrc.document_path;
2856 if (owner->view()->available()) {
2857 string trypath = owner->buffer()->filepath;
2858 // If directory is writeable, use this as default.
2859 if (IsDirWriteable(trypath) == 1)
2864 ProhibitInput(owner->view());
2865 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
2866 fileDlg.SetButton(1, _("Examples"),
2867 AddPath(system_lyxdir, "examples"));
2868 filename = fileDlg.Select(text, initpath, pattern);
2869 AllowInput(owner->view());
2871 // check selected filename
2872 if (filename.empty())
2873 owner->getMiniBuffer()->Set(_("Canceled."));
2876 // still no filename? abort
2877 if (filename.empty())
2880 // get absolute path of file
2881 filename = MakeAbsPath(filename);
2883 string lyxfile = ChangeExtension(filename, ".lyx");
2885 // Check if the document already is open
2886 if (bufferlist.exists(lyxfile)) {
2887 switch(AskConfirmation(_("Document is already open:"),
2888 MakeDisplayPath(lyxfile, 50),
2889 _("Do you want to close that document now?\n"
2890 "('No' will just switch to the open version)")))
2892 case 1: // Yes: close the document
2893 if (!bufferlist.close(bufferlist.getBuffer(lyxfile)))
2894 // If close is canceled, we cancel here too.
2897 case 2: // No: switch to the open document
2898 owner->view()->buffer(bufferlist.getBuffer(lyxfile));
2900 case 3: // Cancel: Do nothing
2901 owner->getMiniBuffer()->Set(_("Canceled."));
2906 // Check if a LyX document by the same root exists in filesystem
2907 FileInfo f(lyxfile, true);
2908 if (f.exist() && !AskQuestion(_("A document by the name"),
2909 MakeDisplayPath(lyxfile),
2910 _("already exists. Overwrite?"))) {
2911 owner->getMiniBuffer()->Set(_("Canceled."));
2914 // filename should be valid now
2916 // notify user of import ahead
2917 string displaypath = MakeDisplayPath(filename);
2918 owner->view()->buffer(bufferlist.newFile(lyxfile, string()));
2919 owner->getMiniBuffer()->Set(_("Importing"), displaypath, "...");
2921 // call real importer
2922 bool result = func(owner->view(), filename);
2926 owner->getMiniBuffer()->Set(displaypath, _("imported."));
2928 owner->getMiniBuffer()->Set(displaypath, _(": import failed."));
2932 bool doImportASCIIasLines(BufferView * view, string const & filename)
2934 InsertAsciiFile(view, filename, false);
2939 bool doImportASCIIasParagraphs(BufferView * view, string const & filename)
2941 InsertAsciiFile(view, filename, true);
2946 bool doImportLaTeX(BufferView *, string const & filename)
2948 ImportLaTeX myImport(filename);
2949 Buffer * openbuf = myImport.run();
2950 return openbuf != NULL;
2954 bool doImportNoweb(BufferView *, string const & filename)
2956 ImportNoweb myImport(filename);
2957 Buffer * openbuf = myImport.run();
2958 return openbuf != NULL;
2962 bool doImportLinuxDoc(BufferView *, string const & filename)
2965 string tmp = lyxrc.linuxdoc_to_lyx_command + filename;
2969 int result = one.startscript(Systemcalls::System, tmp);
2971 string filename = ChangeExtension(filename, ".lyx");
2972 // File was generated without problems. Load it.
2973 buf = bufferlist.loadLyXFile(filename);
2980 void LyXFunc::MenuInsertLyXFile(string const & filen)
2982 string filename = filen;
2984 if (filename.empty()) {
2985 // Launch a file browser
2986 string initpath = lyxrc.document_path;
2989 if (owner->view()->available()) {
2990 string trypath = owner->buffer()->filepath;
2991 // If directory is writeable, use this as default.
2992 if (IsDirWriteable(trypath) == 1)
2997 ProhibitInput(owner->view());
2998 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
2999 fileDlg.SetButton(1, _("Examples"),
3000 AddPath(system_lyxdir, "examples"));
3001 filename = fileDlg.Select(_("Select Document to Insert"),
3003 AllowInput(owner->view());
3005 // check selected filename
3006 if (filename.empty()) {
3007 owner->getMiniBuffer()->Set(_("Canceled."));
3012 // get absolute path of file and make sure the filename ends
3014 filename = MakeAbsPath(filename);
3015 if (!IsLyXFilename(filename))
3019 owner->getMiniBuffer()->Set(_("Inserting document"),
3020 MakeDisplayPath(filename), "...");
3021 bool res = owner->view()->insertLyXFile(filename);
3023 owner->getMiniBuffer()->Set(_("Document"),
3024 MakeDisplayPath(filename),
3027 owner->getMiniBuffer()->Set(_("Could not insert document"),
3028 MakeDisplayPath(filename));
3032 void LyXFunc::doImport(string const & argument)
3035 string filename = split(argument, type, ' ');
3036 lyxerr.debug() << "LyXFunc::doImport: " << type
3037 << " file: " << filename << endl;
3039 if (type == "latex")
3040 doImportHelper(filename,
3041 _("Select LaTeX file to import"), "*.tex",
3043 else if (type == "ascii")
3044 doImportHelper(filename,
3045 _("Select ASCII file to import"), "*.txt",
3046 doImportASCIIasLines);
3047 else if (type == "asciiparagraph")
3048 doImportHelper(filename,
3049 _("Select ASCII file to import"), "*.txt",
3050 doImportASCIIasParagraphs);
3051 else if (type == "noweb")
3052 doImportHelper(filename,
3053 _("Select NoWeb file to import"), "*.nw",
3055 else if (type == "linuxdoc")
3056 doImportHelper(filename,
3057 _("Select LinuxDoc file to import"), "*.doc",
3060 setErrorMessage(string(N_("Unknown import type: ")) + type);
3063 void LyXFunc::reloadBuffer()
3065 string fn = owner->buffer()->fileName();
3066 if (bufferlist.close(owner->buffer()))
3067 owner->view()->buffer(bufferlist.loadLyXFile(fn));
3071 void LyXFunc::CloseBuffer()
3073 if (bufferlist.close(owner->buffer()) && !quitting) {
3074 if (bufferlist.empty()) {
3075 // need this otherwise SEGV may occur while trying to
3076 // set variables that don't exist
3077 // since there's no current buffer
3078 CloseAllBufferRelatedPopups();
3081 owner->view()->buffer(bufferlist.first());
3087 Inset * LyXFunc::getInsetByCode(Inset::Code code)
3089 LyXCursor cursor = owner->view()->text->cursor;
3090 Buffer * buffer = owner->view()->buffer();
3091 for (Buffer::inset_iterator it = Buffer::inset_iterator(cursor.par,
3093 it != buffer->inset_iterator_end(); ++it) {
3094 if ((*it)->LyxCode() == code)
3101 // Each "owner" should have it's own message method. lyxview and
3102 // the minibuffer would use the minibuffer, but lyxserver would
3103 // send an ERROR signal to its client. Alejandro 970603
3104 // This func is bit problematic when it comes to NLS, to make the
3105 // lyx servers client be language indepenent we must not translate
3106 // strings sent to this func.
3107 void LyXFunc::setErrorMessage(string const & m) const
3109 dispatch_buffer = m;
3114 void LyXFunc::setMessage(string const & m)
3116 dispatch_buffer = m;