1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-1999 The LyX Team.
9 * ====================================================== */
18 #pragma implementation
21 #include "lyxlookup.h"
24 #include "bufferlist.h"
25 #include "lyxserver.h"
30 #include "LyXAction.h"
32 #include "insets/insetlatex.h"
34 #include "insets/inseturl.h"
35 #include "insets/insetlatexaccent.h"
36 #include "insets/insettoc.h"
37 #include "insets/insetlof.h"
38 #include "insets/insetloa.h"
39 #include "insets/insetlot.h"
40 #include "insets/insetref.h"
41 #include "insets/insetparent.h"
42 #include "insets/insetindex.h"
43 #include "insets/insetinclude.h"
44 #include "insets/insetbib.h"
45 #include "mathed/formulamacro.h"
47 #include "spellchecker.h" // RVDK_PATCH_5
48 #include "minibuffer.h"
52 #include "lyx_gui_misc.h"
53 #include "support/filetools.h"
54 #include "support/FileInfo.h"
55 #include "support/syscall.h"
56 #include "support/lstrings.h"
57 #include "support/path.h"
58 #include "lyxscreen.h"
63 #include "trans_mgr.h"
64 #include "ImportLaTeX.h"
65 #include "ImportNoweb.h"
68 extern bool cursor_follows_scrollbar;
70 extern void InsertAsciiFile(string const &, bool);
71 extern void math_insert_symbol(char const *);
72 extern Bool math_insert_greek(char const); // why "Bool"?
73 extern BufferList bufferlist;
74 extern LyXServer * lyxserver;
75 extern short greek_kb_flag;
76 extern FD_form_toc * fd_form_toc;
77 extern bool selection_possible;
79 extern kb_keymap * toplevel_keymap;
81 extern void MenuWrite(Buffer *);
82 extern void MenuWriteAs(Buffer *);
83 extern int MenuRunLaTeX(Buffer *);
84 extern int MenuBuildProg(Buffer *);
85 extern int MenuRunChktex(Buffer *);
86 extern bool CreatePostscript(Buffer *, bool);
87 extern void MenuPrint(Buffer *);
88 extern void MenuSendto();
89 extern void QuitLyX();
90 extern void MenuFax(Buffer *);
91 extern void MenuExport(Buffer *, string const &);
92 extern void MenuPasteSelection(char at);
93 extern LyXAction lyxaction;
95 extern tex_accent_struct get_accent(kb_action action);
97 extern void AutoSave();
98 extern void MenuSearch();
99 extern void SetUpdateTimer(float timer = 0.3);
100 extern void FreeUpdateTimer();
101 extern bool PreviewDVI(Buffer *);
102 extern bool PreviewPostscript(Buffer *);
103 extern void MenuInsertLabel(char const *);
104 extern void MenuInsertRef();
105 extern void MenuLayoutCharacter();
106 extern void MenuLayoutParagraph();
107 extern void MenuLayoutDocument();
108 extern void MenuLayoutPaper();
109 extern void MenuLayoutTable(int flag);
110 extern void MenuLayoutQuotes();
111 extern void MenuLayoutPreamble();
112 extern void MenuLayoutSave();
113 extern void bulletForm();
115 extern Buffer * NewLyxFile(string const &);
116 extern void LoadLyXFile(string const &);
117 extern void Reconfigure();
119 extern int current_layout;
120 extern int getISOCodeFromLaTeX(char *);
122 //extern int UnlockInset(UpdatableInset *);
124 extern void ShowLatexLog();
126 extern void UpdateInset(Inset * inset, bool mark_dirty = true);
128 /* === globals =========================================================== */
130 bool LyXFunc::show_sc = true;
133 LyXFunc::LyXFunc(LyXView * o)
137 lyx_dead_action = LFUN_NOACTION;
138 lyx_calling_dead_action = LFUN_NOACTION;
143 // I changed this func slightly. I commented out the ...FinishUndo(),
144 // this means that all places that used to have a moveCursorUpdate, now
145 // have a ...FinishUndo() as the preceeding statement. I have also added
146 // a moveCursorUpdate to some of the functions that updated the cursor, but
147 // that did not show its new position.
149 void LyXFunc::moveCursorUpdate(bool selecting)
151 if (selecting || owner->view()->text->mark_set) {
152 owner->view()->text->SetSelection();
153 owner->view()->getScreen()->ToggleToggle();
154 owner->view()->update(0);
156 owner->view()->update(-2); // this IS necessary
160 owner->view()->getScreen()->ShowCursor();
162 /* ---> Everytime the cursor is moved, show the current font state. */
163 // should this too me moved out of this func?
164 //owner->getMiniBuffer()->Set(CurrentState());
168 int LyXFunc::processKeyEvent(XEvent * ev)
172 XKeyEvent * keyevent = &ev->xkey;
173 KeySym keysym_return;
175 int num_bytes = LyXLookupString(ev, s_r, 10, &keysym_return);
176 s_r[num_bytes] = '\0';
178 if (lyxerr.debugging(Debug::KEY)) {
179 char * tmp = XKeysymToString(keysym_return);
180 string stm = (tmp ? tmp : "");
181 lyxerr << "KeySym is "
184 << keysym_return << "]"
185 << " and num_bytes is "
187 << " the string returned is \""
188 << s_r << '\"' << endl;
190 // Do nothing if we have nothing (JMarc)
191 if (num_bytes == 0 && keysym_return == NoSymbol) {
192 lyxerr[Debug::KEY] << "Empty kbd action (probably composing)"
197 // this function should be used always [asierra060396]
198 if (owner->view()->available() &&
199 owner->view()->the_locking_inset &&
200 keysym_return == XK_Escape) {
201 owner->view()->unlockInset(owner->view()->the_locking_inset);
202 owner->view()->text->CursorRight();
206 // Can we be sure that this will work for all X-Windows
207 // implementations? (Lgb)
208 // This code snippet makes lyx ignore some keys. Perhaps
209 // all of them should be explictly mentioned?
210 if((keysym_return >= XK_Shift_L && keysym_return <= XK_Hyper_R)
211 || keysym_return == XK_Mode_switch || keysym_return == 0x0)
214 // Do a one-deep top-level lookup for
215 // cancel and meta-fake keys. RVDK_PATCH_5
216 cancel_meta_seq.reset();
218 int action = cancel_meta_seq.addkey(keysym_return, keyevent->state
219 &(ShiftMask|ControlMask
222 // When not cancel or meta-fake, do the normal lookup.
223 // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
224 // Mostly, meta_fake_bit = 0. RVDK_PATCH_5.
225 if ( (action != LFUN_CANCEL) && (action != LFUN_META_FAKE) ) {
227 // remove Caps Lock and Mod2 as a modifiers
228 action = keyseq.addkey(keysym_return,
229 (keyevent->state | meta_fake_bit)
230 &(ShiftMask|ControlMask
233 // Dont remove this unless you know what you are doing.
236 if (action == 0) action = LFUN_PREFIX;
238 if (lyxerr.debugging(Debug::KEY)) {
244 << num_bytes << "]" << endl;
247 // already here we know if it any point in going further
248 // why not return already here if action == -1 and
249 // num_bytes == 0? (Lgb)
251 if(keyseq.length > 1 || keyseq.length < -1){
254 owner->getMiniBuffer()->Set(buf);
258 if (keyseq.length < -1) { // unknown key sequence...
262 owner->getMiniBuffer()->Set(_("Unknown sequence:"), buf);
266 char isochar = keyseq.getiso();
267 if (!(keyevent->state&ControlMask) &&
268 !(keyevent->state&Mod1Mask) &&
269 (isochar && keysym_return < 0xF000)) {
272 if (argument.empty()) {
273 lyxerr.debug() << "Empty argument!" << endl;
274 // This can`t possibly be of any use
275 // so we`ll skip the dispatch.
279 if (action == LFUN_SELFINSERT) {
283 bool tmp_sc = show_sc;
285 Dispatch(action, argument.c_str());
292 LyXFunc::func_status LyXFunc::getStatus(int ac) const
295 func_status flag = LyXFunc::OK;
297 Buffer * buf = owner->buffer();
299 if (lyxaction.isPseudoAction(ac))
300 action = lyxaction.retrieveActionArg(ac, argument);
302 action = static_cast<kb_action>(ac);
304 if (action == LFUN_UNKNOWN_ACTION) {
305 setErrorMessage(N_("Unknown action"));
306 return LyXFunc::Unknown;
309 // Check whether we need a buffer
310 if (!lyxaction.funcHasFlag(action, LyXAction::NoBuffer)) {
311 // Yes we need a buffer, do we have one?
314 // Can we use a readonly buffer?
315 if (buf->isReadonly() &&
316 !lyxaction.funcHasFlag(action,
317 LyXAction::ReadOnly)) {
319 setErrorMessage(N_("Document is read-only"));
320 flag |= LyXFunc::Disabled;
324 setErrorMessage(N_("Command not allowed with"
325 "out any document open"));
326 flag |= LyXFunc::Disabled;
330 if (flag & LyXFunc::Disabled)
333 // I would really like to avoid having this switch and rather try to
334 // encode this in the function itself.
335 static bool noLaTeX = lyxrc->latex_command == "none";
336 bool disable = false;
339 disable = noLaTeX || lyxrc->view_dvi_command == "none";
342 disable = noLaTeX || lyxrc->view_ps_command == "none";
349 disable = noLaTeX || lyxrc->print_command == "none";
352 disable = noLaTeX || lyxrc->fax_command == "none";
355 if (argument == "latex")
356 disable = lyxrc->relyx_command == "none";
359 if (argument == "dvi" || argument == "postscript")
361 if (argument == "html")
362 disable = lyxrc->html_command == "none";
365 disable = buf->undostack.empty();
368 disable = buf->redostack.empty();
370 case LFUN_SPELLCHECK:
371 disable = lyxrc->isp_command == "none";
374 disable = lyxrc->chktex_command == "none";
376 case LFUN_LAYOUT_TABLE:
377 disable = ! owner->view()->text->cursor.par->table;
383 flag |= LyXFunc::Disabled;
386 func_status box = LyXFunc::ToggleOff;
387 LyXFont font = owner->view()->text->real_current_font;
390 if (font.emph() == LyXFont::ON)
391 box = LyXFunc::ToggleOn;
394 if (font.noun() == LyXFont::ON)
395 box = LyXFunc::ToggleOn;
398 if (font.series() == LyXFont::BOLD_SERIES)
399 box = LyXFunc::ToggleOn;
402 if (font.latex() == LyXFont::ON)
403 box = LyXFunc::ToggleOn;
416 string LyXFunc::Dispatch(string const & s)
418 // Split command string into command and argument
419 string cmd, line = frontStrip(s);
420 string arg = strip(frontStrip(split(line, cmd, ' ')));
422 return Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
426 string LyXFunc::Dispatch(int ac,
427 char const * do_not_use_this_arg)
432 FL_OBJECT * ob = 0; // This will disapear soon
434 // we have not done anything wrong yet.
436 dispatch_buffer.clear();
438 // if action is a pseudo-action, we need the real action
439 if (lyxaction.isPseudoAction(ac)) {
441 action = static_cast<kb_action>
442 (lyxaction.retrieveActionArg(ac, tmparg));
446 action = static_cast<kb_action>(ac);
447 if (do_not_use_this_arg)
448 argument = do_not_use_this_arg; // except here
451 selection_possible = false;
453 if (owner->view()->available()
454 && owner->view()->getScreen())
455 owner->view()->getScreen()->HideCursor();
457 // We cannot use this function here
458 if (getStatus(action) & Disabled)
459 goto exit_with_message;
461 commandshortcut.clear();
463 if (lyxrc->display_shortcuts && show_sc) {
464 if (action != LFUN_SELFINSERT) {
465 // Put name of command and list of shortcuts
466 // for it in minibuffer
467 string comname = lyxaction.getActionName(action);
469 int pseudoaction = action;
470 bool argsadded = false;
472 if (!argument.empty()) {
473 // If we have the command with argument,
476 lyxaction.searchActionArg(action,
479 if (pseudoaction == -1) {
480 pseudoaction = action;
482 comname += " " + argument;
487 string shortcuts = toplevel_keymap->findbinding(pseudoaction);
489 if (!shortcuts.empty()) {
490 comname += ": " + shortcuts;
491 } else if (!argsadded) {
492 comname += " " + argument;
495 if (!comname.empty()) {
496 comname = strip(comname);
497 commandshortcut = "(" + comname + ')';
498 owner->getMiniBuffer()->Set(commandshortcut);
499 // Here we could even add a small pause,
500 // to annoy the user and make him learn
502 // No! That will just annoy, not teach
503 // anything. The user will read the messages
504 // if they are interested. (Asger)
509 // If in math mode pass the control to
510 // the math inset [asierra060396]
511 if (owner->view()->available() &&
512 owner->view()->the_locking_inset) {
514 || (action == LFUN_UNKNOWN_ACTION
515 && keyseq.length >= -1)) {
516 if (action == LFUN_UNKNOWN_ACTION
517 && argument.empty()) {
518 argument = keyseq.getiso();
520 // Undo/Redo pre 0.13 is a bit tricky for insets.
521 if (action == LFUN_UNDO) {
523 UpdatableInset * inset =
524 owner->view()->the_locking_inset;
525 inset->GetCursorPos(slx, sly);
526 owner->view()->unlockInset(inset);
527 owner->view()->menuUndo();
528 inset = static_cast<UpdatableInset*>(owner->view()->text->cursor.par->GetInset(owner->view()->text->cursor.pos));
530 inset->Edit(slx, sly);
533 if (action == LFUN_REDO) {
535 UpdatableInset * inset = owner->view()->the_locking_inset;
536 inset->GetCursorPos(slx, sly);
537 owner->view()->unlockInset(inset);
538 owner->view()->menuRedo();
539 inset = static_cast<UpdatableInset*>(owner->view()->text->cursor.par->GetInset(owner->view()->text->cursor.pos));
541 inset->Edit(slx, sly);
544 if (owner->view()->the_locking_inset->LocalDispatch(action, argument.c_str()))
547 setMessage(N_("Text mode"));
548 if (action == LFUN_RIGHT || action == -1)
549 owner->view()->text->CursorRight();
550 if (action == LFUN_LEFT || action == LFUN_RIGHT)
557 // --- Misc -------------------------------------------
558 case LFUN_WORDFINDFORWARD :
559 case LFUN_WORDFINDBACKWARD : {
560 static string last_search;
561 string searched_string;
563 if (!argument.empty()) {
564 last_search = argument;
565 searched_string = argument;
567 searched_string = last_search;
570 LyXText * ltCur = owner->view()->text ;
572 if (!searched_string.empty() &&
573 ((action == LFUN_WORDFINDBACKWARD) ?
574 ltCur->SearchBackward(searched_string.c_str()) :
575 ltCur->SearchForward(searched_string.c_str()))) {
577 // ??? What is that ???
578 owner->view()->update(-2);
581 // clear the selection (if there is any)
582 owner->view()->getScreen()->ToggleSelection();
583 owner->view()->text->ClearSelection();
585 // Move cursor so that successive C-s 's will not stand in place.
586 if( action == LFUN_WORDFINDFORWARD )
587 owner->view()->text->CursorRightOneWord();
588 owner->view()->text->FinishUndo();
589 moveCursorUpdate(false);
592 // set the new selection
593 // SetSelectionOverLenChars(owner->view()->currentBuffer()->text, iLenSelected);
594 owner->view()->getScreen()->ToggleSelection(false);
598 // REMOVED : if (owner->view()->getWorkArea()->focus)
599 owner->view()->getScreen()->ShowCursor();
605 if (owner->view()->available()
606 && owner->view()->getScreen()) {
607 owner->view()->update(-2);
610 keyseq.print(buf, true);
611 owner->getMiniBuffer()->Set(buf, string(), string(), 1);
615 // --- Misc -------------------------------------------
616 case LFUN_EXEC_COMMAND:
617 owner->getMiniBuffer()->ExecCommand();
620 case LFUN_CANCEL: // RVDK_PATCH_5
623 if(owner->view()->available())
624 // cancel any selection
625 Dispatch(LFUN_MARK_OFF, 0);
626 setMessage(N_("Cancel"));
629 case LFUN_META_FAKE: // RVDK_PATCH_5
631 meta_fake_bit = Mod1Mask;
633 keyseq.print(buf, true);
634 string res = string("M-") + buf;
635 setMessage(buf); // RVDK_PATCH_5
639 case LFUN_READ_ONLY_TOGGLE:
640 if (owner->buffer()->lyxvc.inUse()) {
641 owner->buffer()->lyxvc.toggleReadOnly();
643 owner->buffer()->setReadonly(
644 !owner->buffer()->isReadonly());
648 case LFUN_CENTER: // this is center and redraw.
649 owner->view()->beforeChange();
650 if (owner->view()->text->cursor.y >
651 owner->view()->getWorkArea()->h / 2) {
652 owner->view()->getScreen()->
653 Draw(owner->view()->text->cursor.y -
654 owner->view()->getWorkArea()->h / 2);
656 owner->view()->getScreen()->
659 owner->view()->update(0);
660 owner->view()->redraw();
664 if (owner->view()->available()) {
665 owner->view()->text->toggleAppendix();
666 owner->view()->update(1);
670 // --- Menus -----------------------------------------------
675 case LFUN_MENUNEWTMPLT:
683 case LFUN_CLOSEBUFFER:
688 MenuWrite(owner->buffer());
691 case LFUN_MENUWRITEAS:
692 MenuWriteAs(owner->buffer());
695 case LFUN_MENURELOAD:
700 PreviewDVI(owner->buffer());
704 PreviewPostscript(owner->buffer());
708 MenuRunLaTeX(owner->buffer());
712 MenuBuildProg(owner->buffer());
716 MenuRunChktex(owner->buffer());
720 CreatePostscript(owner->buffer(), false);
724 MenuPrint(owner->buffer());
728 MenuFax(owner->buffer());
732 MenuExport(owner->buffer(), argument);
737 //needs argument as string
738 string imtyp = argument;
741 if (imtyp == "latex") {
742 doImportLaTeX(false);
745 else if (imtyp == "ascii") {
746 doImportASCII(false);
747 } else if (imtyp == "asciiparagraph") {
750 } else if (imtyp == "noweb") {
753 setErrorMessage(string(N_("Unknown import type: "))
765 if (fd_form_toc->form_toc->visible) {
766 fl_raise_form(fd_form_toc->form_toc);
768 static int ow = -1, oh;
769 fl_show_form(fd_form_toc->form_toc,
771 FL_FREE_SIZE, FL_FULLBORDER,
772 _("Table of Contents"));
774 ow = fd_form_toc->form_toc->w;
775 oh = fd_form_toc->form_toc->h;
777 fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
781 case LFUN_TOC_INSERT:
783 Inset * new_inset = new InsetTOC(owner->buffer());
784 owner->view()->insertInset(new_inset, "Standard", true);
788 case LFUN_LOF_INSERT:
790 Inset * new_inset = new InsetLOF(owner->buffer());
791 owner->view()->insertInset(new_inset, "Standard", true);
795 case LFUN_LOA_INSERT:
797 Inset * new_inset = new InsetLOA(owner->buffer());
798 owner->view()->insertInset(new_inset, "Standard", true);
802 case LFUN_LOT_INSERT:
804 Inset * new_inset = new InsetLOT(owner->buffer());
805 owner->view()->insertInset(new_inset, "Standard", true);
822 owner->view()->menuUndo();
826 owner->view()->menuRedo();
829 case LFUN_MENUSEARCH:
834 owner->view()->paste();
837 case LFUN_PASTESELECTION:
840 if (argument == "paragraph") asPara = true;
841 MenuPasteSelection(asPara);
846 owner->view()->cut();
850 owner->view()->copy();
853 case LFUN_LAYOUT_COPY:
854 owner->view()->copyEnvironment();
857 case LFUN_LAYOUT_PASTE:
858 owner->view()->pasteEnvironment();
862 owner->view()->gotoError();
865 case LFUN_REMOVEERRORS:
866 if (owner->view()->removeAutoInsets()) {
867 owner->view()->redraw();
868 owner->view()->fitCursor();
869 owner->view()->updateScrollbar();
874 owner->view()->gotoNote();
878 owner->view()->openStuff();
881 case LFUN_HYPHENATION:
882 owner->view()->hyphenationPoint();
886 owner->view()->ldots();
889 case LFUN_END_OF_SENTENCE:
890 owner->view()->endOfSentenceDot();
893 case LFUN_MENU_SEPARATOR:
894 owner->view()->menuSeparator();
898 owner->view()->hfill();
909 case LFUN_DEPTH_PLUS:
925 case LFUN_RECONFIGURE:
930 if (owner->view()->available()
931 && !owner->view()->text->selection
932 && owner->view()->text->cursor.par->footnoteflag
933 != LyXParagraph::NO_FOOTNOTE)
934 { // only melt footnotes with FOOTMELT, not margins etc
935 if(owner->view()->text->cursor.par->footnotekind == LyXParagraph::FOOTNOTE)
942 case LFUN_MARGINMELT:
943 if (owner->view()->available()
944 && !owner->view()->text->selection
945 && owner->view()->text->cursor.par->footnoteflag
946 != LyXParagraph::NO_FOOTNOTE) {
948 if(owner->view()->text->cursor.par->footnotekind == LyXParagraph::MARGIN)
955 // --- version control -------------------------------
956 case LFUN_VC_REGISTER:
958 if (!owner->buffer()->lyxvc.inUse())
959 owner->buffer()->lyxvc.registrer();
963 case LFUN_VC_CHECKIN:
965 if (owner->buffer()->lyxvc.inUse()
966 && !owner->buffer()->isReadonly())
967 owner->buffer()->lyxvc.checkIn();
971 case LFUN_VC_CHECKOUT:
973 if (owner->buffer()->lyxvc.inUse()
974 && owner->buffer()->isReadonly())
975 owner->buffer()->lyxvc.checkOut();
981 owner->buffer()->lyxvc.revert();
987 owner->buffer()->lyxvc.undoLast();
991 case LFUN_VC_HISTORY:
993 owner->buffer()->lyxvc.showLog();
997 // --- buffers ----------------------------------------
998 case LFUN_PREVBUFFER:
1000 #warning fix this please
1002 // it is the LyXView or the BufferView that should
1003 // remember the previous buffer, not bufferlist.
1004 // if (owner->view()->available()){
1005 // owner->view()->beforeChange();
1006 // owner->buffer()->update(-2);
1008 // owner->view()->setBuffer(bufferlist.prev());
1011 // resizeCurrentBufferPseudoExpose();
1014 case LFUN_FILE_INSERT:
1016 MenuInsertLyXFile(argument);
1020 case LFUN_FILE_INSERT_ASCII:
1022 bool asPara = (argument == "paragraph");
1023 InsertAsciiFile(string(), asPara);
1029 // servercmd: argument must be <file>:<template>
1030 Buffer * tmpbuf = NewLyxFile(argument);
1032 owner->view()->buffer(tmpbuf);
1036 case LFUN_FILE_OPEN:
1037 owner->view()->buffer(bufferlist.loadLyXFile(argument));
1040 case LFUN_LATEX_LOG:
1046 lyxerr.debug() << "LFUN_LAYOUTNO: (arg) " << argument << endl;
1047 int sel = strToInt(argument);
1048 lyxerr.debug() << "LFUN_LAYOUTNO: (sel) "<< sel << endl;
1050 // Should this give a setMessage instead?
1052 return string(); // illegal argument
1054 --sel; // sel 1..., but layout 0...
1056 // Pretend we got the name instead.
1057 Dispatch(int(LFUN_LAYOUT),
1058 textclasslist.NameOfLayout(owner->view()->
1067 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1068 << argument << endl;
1070 // Derive layout number from given argument (string)
1071 // and current buffer's textclass (number). */
1073 textclasslist.NumberOfLayout(owner->
1079 // see if we found the layout number:
1080 if (layoutno == -1) {
1081 setErrorMessage(string(N_("Layout ")) + argument +
1086 if (current_layout != layoutno) {
1087 owner->view()->getScreen()->HideCursor();
1088 current_layout = layoutno;
1089 owner->view()->update(-2);
1090 owner->view()->text->
1091 SetLayout(layoutno);
1092 owner->getToolbar()->combox->
1093 select(owner->view()->
1096 owner->view()->update(1);
1101 case LFUN_LAYOUT_DOCUMENT:
1102 MenuLayoutDocument();
1105 case LFUN_LAYOUT_PARAGRAPH:
1106 MenuLayoutParagraph();
1109 case LFUN_LAYOUT_CHARACTER:
1110 MenuLayoutCharacter();
1113 case LFUN_LAYOUT_TABLE:
1116 if (argument == "true") flag = 1;
1117 MenuLayoutTable(flag);
1121 case LFUN_LAYOUT_PAPER:
1125 case LFUN_LAYOUT_QUOTES:
1129 case LFUN_LAYOUT_PREAMBLE:
1130 MenuLayoutPreamble();
1133 case LFUN_LAYOUT_SAVE_DEFAULT:
1137 case LFUN_DROP_LAYOUTS_CHOICE:
1138 owner->getToolbar()->combox->Show();
1169 case LFUN_UNDERLINE:
1173 case LFUN_FONT_SIZE:
1174 FontSizeCB(argument);
1177 case LFUN_FONT_STATE:
1178 setMessage(CurrentState());
1181 case LFUN_UPCASE_WORD:
1182 owner->view()->update(-2);
1184 owner->view()->text->ChangeWordCase(LyXText::text_uppercase);
1185 owner->view()->update(1);
1189 case LFUN_LOWCASE_WORD:
1190 owner->view()->update(-2);
1192 owner->view()->text->ChangeWordCase(LyXText::text_lowercase);
1193 owner->view()->update(1);
1197 case LFUN_CAPITALIZE_WORD:
1198 owner->view()->update(-2);
1200 owner->view()->text->ChangeWordCase(LyXText::text_capitalization);
1201 owner->view()->update(1);
1205 case LFUN_INSERT_LABEL:
1206 MenuInsertLabel(argument.c_str());
1209 case LFUN_INSERT_REF:
1213 case LFUN_REFTOGGLE:
1216 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1218 if (inset->getFlag() == InsetRef::REF)
1219 inset->setFlag(InsetRef::PAGE_REF);
1221 inset->setFlag(InsetRef::REF);
1224 setErrorMessage(N_("No cross-reference to toggle"));
1231 owner->view()->restorePosition();
1237 string label(argument);
1238 if (label.empty()) {
1240 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1242 label = inset->getContents();
1245 if (!label.empty()) {
1246 owner->view()->savePosition();
1247 owner->view()->gotoLabel(label.c_str());
1252 case LFUN_MENU_OPEN_BY_NAME:
1253 owner->getMenus()->openByName(argument);
1254 break; // RVDK_PATCH_5
1256 case LFUN_SPELLCHECK:
1257 if (lyxrc->isp_command != "none")
1259 break; // RVDK_PATCH_5
1261 // --- Cursor Movements -----------------------------
1264 LyXText * tmptext = owner->view()->text;
1265 if(!tmptext->mark_set)
1266 owner->view()->beforeChange();
1267 owner->view()->update(-2);
1268 if (tmptext->cursor.pos < tmptext->cursor.par->Last()
1269 && tmptext->cursor.par->GetChar(tmptext->cursor.pos)
1270 == LyXParagraph::META_INSET
1271 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)
1272 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)->Editable() == 2){
1273 Inset * tmpinset = tmptext->cursor.par->GetInset(tmptext->cursor.pos);
1274 setMessage(tmpinset->EditMessage());
1275 tmpinset->Edit(0, 0);
1278 tmptext->CursorRight();
1279 owner->view()->text->FinishUndo();
1280 moveCursorUpdate(false);
1281 owner->getMiniBuffer()->Set(CurrentState());
1287 // This is soooo ugly. Isn`t it possible to make
1288 // it simpler? (Lgb)
1289 LyXText * txt = owner->view()->text;
1290 if(!txt->mark_set) owner->view()->beforeChange();
1291 owner->view()->update(-2);
1293 if (txt->cursor.pos < txt->cursor.par->Last()
1294 && txt->cursor.par->GetChar(txt->cursor.pos)
1295 == LyXParagraph::META_INSET
1296 && txt->cursor.par->GetInset(txt->cursor.pos)
1297 && txt->cursor.par->GetInset(txt->cursor.pos)->Editable() == 2) {
1298 Inset * tmpinset = txt->cursor.par->GetInset(txt->cursor.pos);
1299 setMessage(tmpinset->EditMessage());
1300 tmpinset->Edit(tmpinset->Width(txt->GetFont(txt->cursor.par,
1301 txt->cursor.pos)), 0);
1304 owner->view()->text->FinishUndo();
1305 moveCursorUpdate(false);
1306 owner->getMiniBuffer()->Set(CurrentState());
1311 if(!owner->view()->text->mark_set) owner->view()->beforeChange();
1312 owner->view()->update(-3);
1313 owner->view()->text->CursorUp();
1314 owner->view()->text->FinishUndo();
1315 moveCursorUpdate(false);
1316 owner->getMiniBuffer()->Set(CurrentState());
1320 if(!owner->view()->text->mark_set)
1321 owner->view()->beforeChange();
1322 owner->view()->update(-3);
1323 owner->view()->text->CursorDown();
1324 owner->view()->text->FinishUndo();
1325 moveCursorUpdate(false);
1326 owner->getMiniBuffer()->Set(CurrentState());
1329 case LFUN_UP_PARAGRAPH:
1330 if(!owner->view()->text->mark_set)
1331 owner->view()->beforeChange();
1332 owner->view()->update(-3);
1333 owner->view()->text->CursorUpParagraph();
1334 owner->view()->text->FinishUndo();
1335 moveCursorUpdate(false);
1336 owner->getMiniBuffer()->Set(CurrentState());
1339 case LFUN_DOWN_PARAGRAPH:
1340 if(!owner->view()->text->mark_set)
1341 owner->view()->beforeChange();
1342 owner->view()->update(-3);
1343 owner->view()->text->CursorDownParagraph();
1344 owner->view()->text->FinishUndo();
1345 moveCursorUpdate(false);
1346 owner->getMiniBuffer()->Set(CurrentState());
1350 if(!owner->view()->text->mark_set)
1351 owner->view()->beforeChange();
1352 owner->view()->update(-3);
1353 owner->view()->cursorPrevious();
1354 owner->view()->text->FinishUndo();
1355 moveCursorUpdate(false);
1356 owner->getMiniBuffer()->Set(CurrentState());
1360 if(!owner->view()->text->mark_set)
1361 owner->view()->beforeChange();
1362 owner->view()->update(-3);
1363 owner->view()->cursorNext();
1364 owner->view()->text->FinishUndo();
1365 moveCursorUpdate(false);
1366 owner->getMiniBuffer()->Set(CurrentState());
1370 if(!owner->view()->text->mark_set)
1371 owner->view()->beforeChange();
1372 owner->view()->update(-2);
1373 owner->view()->text->CursorHome();
1374 owner->view()->text->FinishUndo();
1375 moveCursorUpdate(false);
1376 owner->getMiniBuffer()->Set(CurrentState());
1380 if(!owner->view()->text->mark_set)
1381 owner->view()->beforeChange();
1382 owner->view()->update(-2);
1383 owner->view()->text->CursorEnd();
1384 owner->view()->text->FinishUndo();
1385 moveCursorUpdate(false);
1386 owner->getMiniBuffer()->Set(CurrentState());
1390 if(!owner->view()->text->mark_set)
1391 owner->view()->beforeChange();
1392 owner->view()->update(-2);
1393 owner->view()->text->CursorTab();
1394 owner->view()->text->FinishUndo();
1395 moveCursorUpdate(false);
1396 owner->getMiniBuffer()->Set(CurrentState());
1399 case LFUN_WORDRIGHT:
1400 if(!owner->view()->text->mark_set)
1401 owner->view()->beforeChange();
1402 owner->view()->update(-2);
1403 owner->view()->text->CursorRightOneWord();
1404 owner->view()->text->FinishUndo();
1405 moveCursorUpdate(false);
1406 owner->getMiniBuffer()->Set(CurrentState());
1410 if(!owner->view()->text->mark_set)
1411 owner->view()->beforeChange();
1412 owner->view()->update(-2);
1413 owner->view()->text->CursorLeftOneWord();
1414 owner->view()->text->FinishUndo();
1415 moveCursorUpdate(false);
1416 owner->getMiniBuffer()->Set(CurrentState());
1419 case LFUN_BEGINNINGBUF:
1420 if(!owner->view()->text->mark_set)
1421 owner->view()->beforeChange();
1422 owner->view()->update(-2);
1423 owner->view()->text->CursorTop();
1424 owner->view()->text->FinishUndo();
1425 moveCursorUpdate(false);
1426 owner->getMiniBuffer()->Set(CurrentState());
1430 if(!owner->view()->text->mark_set)
1431 owner->view()->beforeChange();
1432 owner->view()->update(-2);
1433 owner->view()->text->CursorBottom();
1434 owner->view()->text->FinishUndo();
1435 moveCursorUpdate(false);
1436 owner->getMiniBuffer()->Set(CurrentState());
1440 /* cursor selection ---------------------------- */
1442 owner->view()->update(-2);
1443 owner->view()->text->CursorRight();
1444 owner->view()->text->FinishUndo();
1445 moveCursorUpdate(true);
1446 owner->getMiniBuffer()->Set(CurrentState());
1450 owner->view()->update(-2);
1451 owner->view()->text->CursorLeft();
1452 owner->view()->text->FinishUndo();
1453 moveCursorUpdate(true);
1454 owner->getMiniBuffer()->Set(CurrentState());
1458 owner->view()->update(-2);
1459 owner->view()->text->CursorUp();
1460 owner->view()->text->FinishUndo();
1461 moveCursorUpdate(true);
1462 owner->getMiniBuffer()->Set(CurrentState());
1466 owner->view()->update(-2);
1467 owner->view()->text->CursorDown();
1468 owner->view()->text->FinishUndo();
1469 moveCursorUpdate(true);
1470 owner->getMiniBuffer()->Set(CurrentState());
1473 case LFUN_UP_PARAGRAPHSEL:
1474 owner->view()->update(-2);
1475 owner->view()->text->CursorUpParagraph();
1476 owner->view()->text->FinishUndo();
1477 moveCursorUpdate(true);
1478 owner->getMiniBuffer()->Set(CurrentState());
1481 case LFUN_DOWN_PARAGRAPHSEL:
1482 owner->view()->update(-2);
1483 owner->view()->text->CursorDownParagraph();
1484 owner->view()->text->FinishUndo();
1485 moveCursorUpdate(true);
1486 owner->getMiniBuffer()->Set(CurrentState());
1490 owner->view()->update(-2);
1491 owner->view()->cursorPrevious();
1492 owner->view()->text->FinishUndo();
1493 moveCursorUpdate(true);
1494 owner->getMiniBuffer()->Set(CurrentState());
1498 owner->view()->update(-2);
1499 owner->view()->cursorNext();
1500 owner->view()->text->FinishUndo();
1501 moveCursorUpdate(true);
1502 owner->getMiniBuffer()->Set(CurrentState());
1506 owner->view()->update(-2);
1507 owner->view()->text->CursorHome();
1508 owner->view()->text->FinishUndo();
1509 moveCursorUpdate(true);
1510 owner->getMiniBuffer()->Set(CurrentState());
1514 owner->view()->update(-2);
1515 owner->view()->text->CursorEnd();
1516 owner->view()->text->FinishUndo();
1517 moveCursorUpdate(true);
1518 owner->getMiniBuffer()->Set(CurrentState());
1521 case LFUN_WORDRIGHTSEL:
1522 owner->view()->update(-2);
1523 owner->view()->text->CursorRightOneWord();
1524 owner->view()->text->FinishUndo();
1525 moveCursorUpdate(true);
1526 owner->getMiniBuffer()->Set(CurrentState());
1529 case LFUN_WORDLEFTSEL:
1530 owner->view()->update(-2);
1531 owner->view()->text->CursorLeftOneWord();
1532 owner->view()->text->FinishUndo();
1533 moveCursorUpdate(true);
1534 owner->getMiniBuffer()->Set(CurrentState());
1537 case LFUN_BEGINNINGBUFSEL:
1538 owner->view()->update(-2);
1539 owner->view()->text->CursorTop();
1540 owner->view()->text->FinishUndo();
1541 moveCursorUpdate(true);
1542 owner->getMiniBuffer()->Set(CurrentState());
1545 case LFUN_ENDBUFSEL:
1546 owner->view()->update(-2);
1547 owner->view()->text->CursorBottom();
1548 owner->view()->text->FinishUndo();
1549 moveCursorUpdate(true);
1550 owner->getMiniBuffer()->Set(CurrentState());
1553 // --- text changing commands ------------------------
1554 case LFUN_BREAKLINE:
1555 owner->view()->beforeChange();
1556 owner->view()->text->InsertChar(LyXParagraph::META_NEWLINE);
1557 owner->view()->smallUpdate(1);
1558 SetUpdateTimer(0.01);
1559 moveCursorUpdate(false);
1562 case LFUN_PROTECTEDSPACE:
1563 owner->view()->beforeChange();
1564 owner->view()->text->
1565 InsertChar(LyXParagraph::META_PROTECTED_SEPARATOR);
1566 owner->view()->smallUpdate(1);
1568 moveCursorUpdate(false);
1572 if(owner->view()->text->mark_set) {
1573 owner->view()->beforeChange();
1574 owner->view()->update(0);
1575 setMessage(N_("Mark removed"));
1577 owner->view()->beforeChange();
1578 owner->view()->text->mark_set = 1;
1579 owner->view()->update(0);
1580 setMessage(N_("Mark set"));
1582 owner->view()->text->sel_cursor =
1583 owner->view()->text->cursor;
1588 if (!owner->view()->text->selection) {
1589 owner->view()->text->Delete();
1590 owner->view()->text->sel_cursor =
1591 owner->view()->text->cursor;
1592 owner->view()->smallUpdate(1);
1593 // It is possible to make it a lot faster still
1594 // just comment out the lone below...
1595 owner->view()->getScreen()->ShowCursor();
1597 owner->view()->cut();
1602 case LFUN_DELETE_SKIP:
1604 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1606 LyXCursor cursor = owner->view()->text->cursor;
1609 if (!owner->view()->text->selection) {
1610 if (cursor.pos == cursor.par->Last()) {
1611 owner->view()->text->CursorRight();
1612 cursor = owner->view()->text->cursor;
1614 && !(cursor.par->added_space_top
1615 == VSpace (VSpace::NONE))) {
1616 owner->view()->text->SetParagraph
1617 (cursor.par->line_top,
1618 cursor.par->line_bottom,
1619 cursor.par->pagebreak_top,
1620 cursor.par->pagebreak_bottom,
1621 VSpace(VSpace::NONE),
1622 cursor.par->added_space_bottom,
1624 cursor.par->labelwidthstring, 0);
1625 owner->view()->text->CursorLeft();
1626 owner->view()->update (1);
1628 owner->view()->text->CursorLeft();
1629 owner->view()->text->Delete();
1630 owner->view()->text->sel_cursor =
1631 owner->view()->text->cursor;
1632 owner->view()->smallUpdate(1);
1635 owner->view()->text->Delete();
1636 owner->view()->text->sel_cursor =
1637 owner->view()->text->cursor;
1638 owner->view()->smallUpdate(1);
1641 owner->view()->cut();
1647 /* -------> Delete word forward. */
1648 case LFUN_DELETE_WORD_FORWARD:
1649 owner->view()->update(-2);
1651 owner->view()->text->DeleteWordForward();
1652 owner->view()->update( 1 );
1654 moveCursorUpdate(false);
1657 /* -------> Delete word backward. */
1658 case LFUN_DELETE_WORD_BACKWARD:
1659 owner->view()->update(-2);
1661 owner->view()->text->DeleteWordBackward();
1662 owner->view()->update( 1 );
1664 moveCursorUpdate(false);
1667 /* -------> Kill to end of line. */
1668 case LFUN_DELETE_LINE_FORWARD:
1670 owner->view()->update(-2);
1671 owner->view()->text->DeleteLineForward();
1672 owner->view()->update( 1 );
1674 moveCursorUpdate(false);
1677 /* -------> Set mark off. */
1679 owner->view()->beforeChange();
1680 owner->view()->update(0);
1681 owner->view()->text->sel_cursor =
1682 owner->view()->text->cursor;
1683 setMessage(N_("Mark off"));
1686 /* -------> Set mark on. */
1688 owner->view()->beforeChange();
1689 owner->view()->text->mark_set = 1;
1690 owner->view()->update( 0 );
1691 owner->view()->text->sel_cursor =
1692 owner->view()->text->cursor;
1693 setMessage(N_("Mark on"));
1696 case LFUN_BACKSPACE:
1699 if (!owner->view()->text->selection) {
1700 if (owner->getIntl()->getTrans()->backspace()) {
1701 owner->view()->text->Backspace();
1702 owner->view()->text->sel_cursor =
1703 owner->view()->text->cursor;
1704 owner->view()->smallUpdate(1);
1705 // It is possible to make it a lot faster still
1706 // just comment out the lone below...
1707 owner->view()->getScreen()->ShowCursor();
1710 owner->view()->cut();
1716 case LFUN_BACKSPACE_SKIP:
1718 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1720 LyXCursor cursor = owner->view()->text->cursor;
1723 if (!owner->view()->text->selection) {
1725 && !(cursor.par->added_space_top
1726 == VSpace (VSpace::NONE))) {
1727 owner->view()->text->SetParagraph
1728 (cursor.par->line_top,
1729 cursor.par->line_bottom,
1730 cursor.par->pagebreak_top,
1731 cursor.par->pagebreak_bottom,
1732 VSpace(VSpace::NONE), cursor.par->added_space_bottom,
1734 cursor.par->labelwidthstring, 0);
1735 owner->view()->update (1);
1737 owner->view()->text->Backspace();
1738 owner->view()->text->sel_cursor
1740 owner->view()->smallUpdate (1);
1743 owner->view()->cut();
1748 case LFUN_BREAKPARAGRAPH:
1750 owner->view()->beforeChange();
1751 owner->view()->text->BreakParagraph(0);
1752 owner->view()->smallUpdate(1);
1753 SetUpdateTimer(0.01);
1754 owner->view()->text->sel_cursor =
1755 owner->view()->text->cursor;
1759 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1761 owner->view()->beforeChange();
1762 owner->view()->text->BreakParagraph(1);
1763 owner->view()->smallUpdate(1);
1764 SetUpdateTimer(0.01);
1765 owner->view()->text->sel_cursor =
1766 owner->view()->text->cursor;
1770 case LFUN_BREAKPARAGRAPH_SKIP:
1772 // When at the beginning of a paragraph, remove
1773 // indentation and add a "defskip" at the top.
1774 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
1776 LyXCursor cursor = owner->view()->text->cursor;
1778 owner->view()->beforeChange();
1779 if (cursor.pos == 0) {
1780 if (cursor.par->added_space_top == VSpace(VSpace::NONE)) {
1781 owner->view()->text->SetParagraph
1782 (cursor.par->line_top,
1783 cursor.par->line_bottom,
1784 cursor.par->pagebreak_top,
1785 cursor.par->pagebreak_bottom,
1786 VSpace(VSpace::DEFSKIP), cursor.par->added_space_bottom,
1788 cursor.par->labelwidthstring, 1);
1789 owner->view()->update(1);
1793 owner->view()->text->BreakParagraph(0);
1794 owner->view()->smallUpdate(1);
1796 SetUpdateTimer(0.01);
1797 owner->view()->text->sel_cursor = cursor;
1802 owner->view()->beforeChange();
1803 owner->view()->text->InsertChar('\"'); // This " matches the single quote in the code
1804 owner->view()->smallUpdate(1);
1806 moveCursorUpdate(false);
1812 InsetCommand * new_inset;
1813 if (action == LFUN_HTMLURL)
1814 new_inset = new InsetUrl("htmlurl", "", "");
1816 new_inset = new InsetUrl("url", "", "");
1817 owner->view()->insertInset(new_inset);
1818 new_inset->Edit(0, 0);
1822 // --- lyxserver commands ----------------------------
1824 case LFUN_CHARATCURSOR:
1826 LyXParagraph::size_type pos =
1827 owner->view()->text->cursor.pos;
1828 if(pos < owner->view()->text->cursor.par->size())
1829 dispatch_buffer = owner->view()->text->
1830 cursor.par->text[pos];
1832 dispatch_buffer = "EOF";
1838 tostr(owner->view()->text->cursor.x) + ' '
1839 + tostr(owner->view()->text->cursor.y);
1846 sscanf(argument.c_str(), " %d %ld", &x, &y);
1847 owner->view()->text->SetCursorFromCoordinates(x, y);
1851 case LFUN_GETLAYOUT:
1853 tostr(owner->view()->text->cursor.par->layout);
1858 LyXFont * font = &(owner->view()->text->current_font);
1859 if(font->shape() == LyXFont::ITALIC_SHAPE)
1860 dispatch_buffer = 'E';
1861 else if(font->shape() == LyXFont::SMALLCAPS_SHAPE)
1862 dispatch_buffer = 'N';
1864 dispatch_buffer = '0';
1871 LyXFont * font = &(owner->view()->text->current_font);
1872 if(font->latex() == LyXFont::ON)
1873 dispatch_buffer = 'L';
1875 dispatch_buffer = '0';
1880 setMessage(owner->buffer()->fileName());
1881 lyxerr.debug() << "FNAME["
1882 << owner->buffer()->fileName()
1890 dispatch_buffer = buf;
1891 lyxserver->notifyClient(dispatch_buffer);
1895 case LFUN_GOTOFILEROW:
1897 char file_name[100];
1899 sscanf(argument.c_str(), " %s %d", file_name, &row);
1901 // Must replace extension of the file to be .lyx and get full path
1902 string s = ChangeExtension(string(file_name), ".lyx", false);
1904 // Either change buffer or load the file
1905 if (bufferlist.exists(s))
1906 owner->view()->buffer(bufferlist.getBuffer(s));
1908 owner->view()->buffer(bufferlist.loadLyXFile(s));
1911 owner->view()->setCursorFromRow(row);
1914 owner->view()->beforeChange();
1915 if (owner->view()->text->cursor.y >
1916 owner->view()->getWorkArea()->h / 2) {
1917 owner->view()->getScreen()->
1918 Draw(owner->view()->text->cursor.y -
1919 owner->view()->getWorkArea()->h/2);
1921 owner->view()->getScreen()->
1924 owner->view()->update(0);
1925 owner->view()->redraw();
1932 int qa = lyxaction.LookupFunc(argument.c_str());
1933 setMessage(lyxaction.helpText(static_cast<kb_action>(qa)));
1937 // --- accented characters ---------------------------
1940 case LFUN_CIRCUMFLEX:
1950 case LFUN_SPECIAL_CARON:
1953 case LFUN_HUNG_UMLAUT:
1959 if (keyseq.length == -1 && keyseq.getiso() != 0)
1960 c = keyseq.getiso();
1964 owner->getIntl()->getTrans()->
1965 deadkey(c, get_accent(action).accent,
1966 owner->view()->text);
1968 // Need to reset, in case the minibuffer calls these
1973 // copied verbatim from do_accent_char
1974 owner->view()->smallUpdate(1);
1976 owner->view()->text->sel_cursor =
1977 owner->view()->text->cursor;
1981 // --- toolbar ----------------------------------
1982 case LFUN_PUSH_TOOLBAR:
1984 int nth = strToInt(argument);
1985 if (lyxerr.debugging(Debug::TOOLBAR)) {
1986 lyxerr << "LFUN_PUSH_TOOLBAR: argument = `"
1987 << argument << "'\n"
1988 << "LFUN_PUSH_TOOLBAR: nth = `"
1989 << nth << "'" << endl;
1994 setErrorMessage(N_("Push-toolbar needs argument > 0"));
1996 owner->getToolbar()->push(nth);
2001 case LFUN_ADD_TO_TOOLBAR:
2003 if (lyxerr.debugging(Debug::TOOLBAR)) {
2004 lyxerr << "LFUN_ADD_TO_TOOLBAR:"
2005 "argument = `" << argument << '\'' << endl;
2007 string tmp(argument);
2008 //lyxerr <<string("Argument: ") + argument);
2009 //lyxerr <<string("Tmp : ") + tmp);
2012 setErrorMessage(N_("Usage: toolbar-add-to <LyX command>"));
2014 owner->getToolbar()->add(argument, false);
2015 owner->getToolbar()->set();
2020 // --- insert characters ----------------------------------------
2022 case LFUN_INSERT_INSET_LATEX:
2024 Inset * new_inset = new InsetLatex(argument);
2025 owner->buffer()->insertInset(new_inset);
2029 // --- Mathed stuff. If we are here, there is no locked inset yet.
2034 if (!greek_kb_flag) {
2036 setMessage(N_("Math greek mode on"));
2043 case LFUN_GREEK_TOGGLE:
2045 greek_kb_flag = greek_kb_flag ? 0 : 2;
2046 if (greek_kb_flag) {
2047 setMessage(N_("Math greek keyboard on"));
2049 setMessage(N_("Math greek keyboard off"));
2054 case LFUN_MATH_DELIM:
2055 case LFUN_INSERT_MATRIX:
2057 if (owner->view()->available()) {
2059 open_new_inset(new InsetFormula(false));
2061 the_locking_inset->LocalDispatch(action, argument.c_str());
2066 case LFUN_INSERT_MATH:
2068 math_insert_symbol(argument.c_str());
2072 case LFUN_MATH_DISPLAY:
2074 if (owner->view()->available())
2075 owner->view()->open_new_inset(new InsetFormula(true));
2079 case LFUN_MATH_MACRO:
2081 if (owner->view()->available()) {
2084 setErrorMessage(N_("Missing argument"));
2086 string s1 = token(s, ' ', 1);
2087 int na = s1.empty() ? 0: atoi(s1.c_str());
2089 open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2095 case LFUN_MATH_MODE: // Open or create a math inset
2098 if (owner->view()->available())
2099 owner->view()->open_new_inset(new InsetFormula);
2100 setMessage(N_("Math editor mode"));
2104 case LFUN_MATH_NUMBER:
2105 case LFUN_MATH_LIMITS:
2107 setErrorMessage(N_("This is only allowed in math mode!"));
2111 case LFUN_INSERT_CITATION:
2113 InsetCitation * new_inset = new InsetCitation();
2115 // The note, if any, must be after the key, delimited
2116 // by a | so both key and remark can have spaces.
2117 if (!argument.empty()) {
2118 string lsarg(argument);
2119 if (contains(lsarg, "|")) {
2120 new_inset->setContents(token(lsarg, '|', 0));
2121 new_inset->setOptions(token(lsarg, '|', 1));
2123 new_inset->setContents(lsarg);
2124 owner->view()->insertInset(new_inset);
2126 owner->view()->insertInset(new_inset);
2127 new_inset->Edit(0, 0);
2132 case LFUN_INSERT_BIBTEX:
2134 // ale970405+lasgoutt970425
2135 // The argument can be up to two tokens separated
2136 // by a space. The first one is the bibstyle.
2137 string lsarg(argument);
2138 string bibstyle = token(lsarg, ' ', 1);
2139 if (bibstyle.empty())
2141 InsetBibtex * new_inset
2142 = new InsetBibtex(token(lsarg, ' ', 0),
2146 owner->view()->insertInset(new_inset);
2147 if (lsarg.empty()) {
2148 new_inset->Edit(0, 0);
2153 // BibTeX data bases
2154 case LFUN_BIBDB_ADD:
2156 InsetBibtex * inset =
2157 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2159 inset->addDatabase(argument);
2164 case LFUN_BIBDB_DEL:
2166 InsetBibtex * inset =
2167 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2169 inset->delDatabase(argument);
2174 case LFUN_BIBTEX_STYLE:
2176 InsetBibtex * inset =
2177 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2179 inset->setOptions(argument);
2184 case LFUN_INDEX_INSERT:
2185 case LFUN_INDEX_INSERT_LAST:
2187 // Can't do that at the beginning of a paragraph.
2188 if (owner->view()->text->cursor.pos - 1 < 0)
2191 InsetIndex * new_inset = new InsetIndex();
2192 if (!argument.empty()) {
2193 string lsarg(argument);
2194 new_inset->setContents(lsarg);
2195 owner->view()->insertInset(new_inset);
2198 //get the current word for an argument
2199 LyXParagraph::size_type lastpos =
2200 owner->view()->text->cursor.pos - 1;
2201 // Get the current word. note that this must be done
2202 // before inserting the inset, or the inset will
2204 string curstring(owner->view()
2205 ->text->cursor.par->GetWord(lastpos));
2207 //make the new inset and write the current word into it
2208 InsetIndex * new_inset = new InsetIndex();
2210 new_inset->setContents(curstring);
2212 //don't edit it if the call was to INSERT_LAST
2213 if(action != LFUN_INDEX_INSERT_LAST) {
2214 new_inset->Edit(0, 0);
2216 //it looks blank on the screen unless
2217 //we do something. put it here.
2219 // move the cursor to the returned value of lastpos
2220 // but only for the auto-insert
2221 owner->view()->text->cursor.pos = lastpos;
2224 //put the new inset into the buffer.
2225 // there should be some way of knowing the user
2226 //cancelled & avoiding this, but i don't know how
2227 owner->view()->insertInset(new_inset);
2232 case LFUN_INDEX_PRINT:
2234 Inset * new_inset = new InsetPrintIndex(owner->buffer());
2235 owner->view()->insertInset(new_inset, "Standard", true);
2239 case LFUN_PARENTINSERT:
2241 lyxerr << "arg " << argument << endl;
2242 Inset * new_inset = new InsetParent(argument, owner->buffer());
2243 owner->view()->insertInset(new_inset, "Standard", true);
2247 case LFUN_CHILDINSERT:
2249 Inset * new_inset = new InsetInclude(argument,
2251 owner->view()->insertInset(new_inset, "Standard", true);
2252 new_inset->Edit(0, 0);
2256 case LFUN_CHILDOPEN:
2259 MakeAbsPath(argument,
2260 OnlyPath(owner->buffer()->fileName()));
2261 setMessage(N_("Opening child document ") +
2262 MakeDisplayPath(filename) + "...");
2263 owner->view()->savePosition();
2264 if (bufferlist.exists(filename))
2265 owner->view()->buffer(bufferlist.getBuffer(filename));
2267 owner->view()->buffer(bufferlist.loadLyXFile(filename));
2271 case LFUN_INSERT_NOTE:
2272 owner->view()->insertNote();
2275 case LFUN_INSERTFOOTNOTE:
2277 LyXParagraph::footnote_kind kind;
2278 if (argument == "footnote")
2279 { kind = LyXParagraph::FOOTNOTE; }
2280 else if (argument == "margin")
2281 { kind = LyXParagraph::MARGIN; }
2282 else if (argument == "figure")
2283 { kind = LyXParagraph::FIG; }
2284 else if (argument == "table")
2285 { kind = LyXParagraph::TAB; }
2286 else if (argument == "wide-fig")
2287 { kind = LyXParagraph::WIDE_FIG; }
2288 else if (argument == "wide-tab")
2289 { kind = LyXParagraph::WIDE_TAB; }
2290 else if (argument == "algorithm")
2291 { kind = LyXParagraph::ALGORITHM; }
2293 setErrorMessage(N_("Unknown kind of footnote"));
2296 owner->view()->text->InsertFootnoteEnvironment(kind);
2297 owner->view()->update(1);
2301 case LFUN_BUFFERBULLETSSELECT:
2305 case LFUN_TOGGLECURSORFOLLOW:
2306 cursor_follows_scrollbar = !cursor_follows_scrollbar;
2309 case LFUN_KMAP_OFF: // keymap off
2310 owner->getIntl()->KeyMapOn(false);
2313 case LFUN_KMAP_PRIM: // primary keymap
2314 owner->getIntl()->KeyMapPrim();
2317 case LFUN_KMAP_SEC: // secondary keymap
2318 owner->getIntl()->KeyMapSec();
2321 case LFUN_KMAP_TOGGLE: // toggle keymap
2322 owner->getIntl()->ToggleKeyMap();
2325 case LFUN_SELFINSERT:
2327 for (string::size_type i = 0; i < argument.length(); ++i) {
2328 owner->view()->text->InsertChar(argument[i]);
2329 // This needs to be in the loop, or else we
2330 // won't break lines correctly. (Asger)
2331 owner->view()->smallUpdate(1);
2334 owner->view()->text->sel_cursor =
2335 owner->view()->text->cursor;
2336 moveCursorUpdate(false);
2342 // argument contains ';'-terminated commands
2343 while (argument.find(';') != string::npos) {
2345 argument = split(argument, first, ';');
2351 case LFUN_SAVEPREFERENCES:
2353 Path p(user_lyxdir);
2354 lyxrc->write("preferences");
2358 case LFUN_UNKNOWN_ACTION:
2360 if(!owner->buffer()) {
2362 setErrorMessage(N_("No document open"));
2366 if (owner->buffer()->isReadonly()) {
2368 setErrorMessage(N_("Document is read only"));
2372 if (!argument.empty()) {
2374 /* Automatically delete the currently selected
2375 * text and replace it with what is being
2376 * typed in now. Depends on lyxrc settings
2377 * "auto_region_delete", which defaults to
2380 if ( lyxrc->auto_region_delete ) {
2381 if (owner->view()->text->selection){
2382 owner->view()->text->CutSelection(false);
2383 owner->view()->update(-1);
2387 owner->view()->beforeChange();
2388 for (string::size_type i = 0;
2389 i < argument.length(); ++i) {
2390 if (greek_kb_flag) {
2391 if (!math_insert_greek(argument[i]))
2392 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2394 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2397 owner->view()->smallUpdate(1);
2400 owner->view()->text->sel_cursor =
2401 owner->view()->text->cursor;
2402 moveCursorUpdate(false);
2405 // why is an "Unknown action" with empty
2406 // argument even dispatched in the first
2407 // place? I`ll probably change that. (Lgb)
2409 setErrorMessage(N_("Unknown action"));
2413 lyxerr << "A truly unknown func!" << endl;
2419 string res = getMessage();
2422 if (!commandshortcut.empty()) {
2423 string newbuf = owner->getMiniBuffer()->GetText();
2424 if (newbuf != commandshortcut) {
2425 owner->getMiniBuffer()->Set(newbuf
2431 owner->getMiniBuffer()->Set(string(_(res.c_str()))
2432 + " " + commandshortcut);
2439 void LyXFunc::setupLocalKeymap()
2441 keyseq.stdmap = keyseq.curmap = toplevel_keymap;
2442 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap;
2446 void LyXFunc::MenuNew(bool fromTemplate)
2448 string fname, initpath = lyxrc->document_path;
2451 if (owner->view()->available()) {
2452 string trypath = owner->buffer()->filepath;
2453 // If directory is writeable, use this as default.
2454 if (IsDirWriteable(trypath) == 1)
2459 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2460 fileDlg.SetButton(1, _("Templates"), lyxrc->template_path);
2461 fname = fileDlg.Select(_("Enter Filename for new document"),
2462 initpath, "*.lyx", _("newfile"));
2465 if (fname.empty()) {
2466 owner->getMiniBuffer()->Set(_("Canceled."));
2467 lyxerr.debug() << "New Document Cancelled." << endl;
2471 // get absolute path of file and make sure the filename ends
2473 string s = MakeAbsPath(fname);
2474 if (!IsLyXFilename(s))
2477 // Check if the document already is open
2478 if (bufferlist.exists(s)){
2479 switch(AskConfirmation(_("Document is already open:"),
2480 MakeDisplayPath(s, 50),
2481 _("Do you want to close that document now?\n"
2482 "('No' will just switch to the open version)")))
2484 case 1: // Yes: close the document
2485 if (!bufferlist.close(bufferlist.getBuffer(s)))
2486 // If close is canceled, we cancel here too.
2489 case 2: // No: switch to the open document
2490 owner->view()->buffer(bufferlist.getBuffer(s));
2492 case 3: // Cancel: Do nothing
2493 owner->getMiniBuffer()->Set(_("Canceled."));
2498 // Check whether the file already exists
2499 if (IsLyXFilename(s)) {
2501 if (fi.readable() &&
2502 AskQuestion(_("File already exists:"),
2503 MakeDisplayPath(s, 50),
2504 _("Do you want to open the document?"))) {
2506 owner->getMiniBuffer()->Set(_("Opening document"),
2507 MakeDisplayPath(s), "...");
2509 owner->view()->buffer(
2510 bufferlist.loadLyXFile(s));
2511 owner->getMiniBuffer()->Set(_("Document"),
2518 // The template stuff
2522 fname = fileDlg.Select(_("Choose template"),
2523 lyxrc->template_path,
2529 // find a free buffer
2530 lyxerr.debug() << "Find a free buffer." << endl;
2531 owner->view()->buffer(bufferlist.newFile(s, templname));
2535 void LyXFunc::MenuOpen()
2537 string initpath = lyxrc->document_path;
2540 if (owner->view()->available()) {
2541 string trypath = owner->buffer()->filepath;
2542 // If directory is writeable, use this as default.
2543 if (IsDirWriteable(trypath) == 1)
2549 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2550 fileDlg.SetButton(1, _("Examples"),
2551 AddPath(system_lyxdir, "examples"));
2552 string filename = fileDlg.Select(_("Select Document to Open"),
2556 // check selected filename
2557 if (filename.empty()) {
2558 owner->getMiniBuffer()->Set(_("Canceled."));
2562 // get absolute path of file and make sure the filename ends
2564 filename = MakeAbsPath(filename);
2565 if (!IsLyXFilename(filename))
2569 owner->getMiniBuffer()->Set(_("Opening document"),
2570 MakeDisplayPath(filename), "...");
2571 Buffer * openbuf = bufferlist.loadLyXFile(filename);
2573 owner->view()->buffer(openbuf);
2574 owner->getMiniBuffer()->Set(_("Document"),
2575 MakeDisplayPath(filename),
2578 owner->getMiniBuffer()->Set(_("Could not open document"),
2579 MakeDisplayPath(filename));
2584 void LyXFunc::doImportASCII(bool linorpar)
2586 string initpath = lyxrc->document_path;
2589 if (owner->view()->available()) {
2590 string trypath = owner->buffer()->filepath;
2591 // If directory is writeable, use this as default.
2592 if (IsDirWriteable(trypath) == 1)
2598 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2599 fileDlg.SetButton(1, _("Examples"),
2600 AddPath(system_lyxdir, "examples"));
2601 string filename = fileDlg.Select(_("Select ASCII file to Import"),
2605 // check selected filename
2606 if (filename.empty()) {
2607 owner->getMiniBuffer()->Set(_("Canceled."));
2611 // get absolute path of file
2612 filename = MakeAbsPath(filename);
2614 string s = ChangeExtension(filename, ".lyx", false);
2616 // Check if the document already is open
2617 if (bufferlist.exists(s)) {
2618 switch(AskConfirmation(_("Document is already open:"),
2619 MakeDisplayPath(s, 50),
2620 _("Do you want to close that document now?\n"
2621 "('No' will just switch to the open version)")))
2623 case 1: // Yes: close the document
2624 if (!bufferlist.close(bufferlist.getBuffer(s)))
2625 // If close is canceled, we cancel here too.
2628 case 2: // No: switch to the open document
2629 owner->view()->buffer(bufferlist.getBuffer(s));
2631 case 3: // Cancel: Do nothing
2632 owner->getMiniBuffer()->Set(_("Canceled."));
2637 // Check if a LyX document by the same root exists in filesystem
2638 FileInfo f(s, true);
2639 if (f.exist() && !AskQuestion(_("A document by the name"),
2641 _("already exists. Overwrite?"))) {
2642 owner->getMiniBuffer()->Set(_("Canceled."));
2646 owner->view()->buffer(bufferlist.newFile(s, string()));
2647 owner->getMiniBuffer()->Set(_("Importing ASCII file"),
2648 MakeDisplayPath(filename), "...");
2649 // Insert ASCII file
2650 InsertAsciiFile(filename, linorpar);
2651 owner->getMiniBuffer()->Set(_("ASCII file "),
2652 MakeDisplayPath(filename),
2657 void LyXFunc::doImportLaTeX(bool isnoweb)
2659 string initpath = lyxrc->document_path;
2662 if (owner->view()->available()) {
2663 string trypath = owner->buffer()->filepath;
2664 // If directory is writeable, use this as default.
2665 if (IsDirWriteable(trypath) == 1)
2671 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2672 fileDlg.SetButton(1, _("Examples"),
2673 AddPath(system_lyxdir, "examples"));
2676 filename = fileDlg.Select(_("Select Noweb file to Import"),
2679 filename = fileDlg.Select(_("Select LaTeX file to Import"),
2685 // check selected filename
2686 if (filename.empty()) {
2687 owner->getMiniBuffer()->Set(_("Canceled."));
2691 // get absolute path of file
2692 filename = MakeAbsPath(filename);
2694 // Check if the document already is open
2695 string LyXfilename = ChangeExtension(filename, ".lyx", false);
2696 if (bufferlist.exists(LyXfilename)){
2697 switch(AskConfirmation(_("Document is already open:"),
2698 MakeDisplayPath(LyXfilename, 50),
2699 _("Do you want to close that document now?\n"
2700 "('No' will just switch to the open version)")))
2702 case 1: // Yes: close the document
2703 if (!bufferlist.close(bufferlist.getBuffer(LyXfilename)))
2704 // If close is canceled, we cancel here too.
2707 case 2: // No: switch to the open document
2708 owner->view()->buffer(
2709 bufferlist.getBuffer(LyXfilename));
2711 case 3: // Cancel: Do nothing
2712 owner->getMiniBuffer()->Set(_("Canceled."));
2717 // Check if a LyX document by the same root exists in filesystem
2718 FileInfo f(LyXfilename, true);
2719 if (f.exist() && !AskQuestion(_("A document by the name"),
2720 MakeDisplayPath(LyXfilename),
2721 _("already exists. Overwrite?"))) {
2722 owner->getMiniBuffer()->Set(_("Canceled."));
2729 owner->getMiniBuffer()->Set(_("Importing LaTeX file"),
2730 MakeDisplayPath(filename), "...");
2731 ImportLaTeX myImport(filename);
2732 openbuf = myImport.run();
2734 owner->getMiniBuffer()->Set(_("Importing Noweb file"),
2735 MakeDisplayPath(filename), "...");
2736 ImportNoweb myImport(filename);
2737 openbuf = myImport.run();
2740 owner->view()->buffer(openbuf);
2741 owner->getMiniBuffer()->Set(isnoweb ?
2742 _("Noweb file ") : _("LateX file "),
2743 MakeDisplayPath(filename),
2746 owner->getMiniBuffer()->Set(isnoweb ?
2747 _("Could not import Noweb file") :
2748 _("Could not import LaTeX file"),
2749 MakeDisplayPath(filename));
2754 void LyXFunc::MenuInsertLyXFile(string const & filen)
2756 string filename = filen;
2758 if (filename.empty()) {
2759 // Launch a file browser
2760 string initpath = lyxrc->document_path;
2763 if (owner->view()->available()) {
2764 string trypath = owner->buffer()->filepath;
2765 // If directory is writeable, use this as default.
2766 if (IsDirWriteable(trypath) == 1)
2772 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2773 fileDlg.SetButton(1, _("Examples"),
2774 AddPath(system_lyxdir, "examples"));
2775 filename = fileDlg.Select(_("Select Document to Insert"),
2779 // check selected filename
2780 if (filename.empty()) {
2781 owner->getMiniBuffer()->Set(_("Canceled."));
2786 // get absolute path of file and make sure the filename ends
2788 filename = MakeAbsPath(filename);
2789 if (!IsLyXFilename(filename))
2793 owner->getMiniBuffer()->Set(_("Inserting document"),
2794 MakeDisplayPath(filename), "...");
2795 bool res = owner->view()->insertLyXFile(filename);
2797 owner->getMiniBuffer()->Set(_("Document"),
2798 MakeDisplayPath(filename),
2801 owner->getMiniBuffer()->Set(_("Could not insert document"),
2802 MakeDisplayPath(filename));
2807 void LyXFunc::reloadBuffer()
2809 string fn = owner->buffer()->fileName();
2810 if (bufferlist.close(owner->buffer()))
2811 owner->view()->buffer(bufferlist.loadLyXFile(fn));
2815 void LyXFunc::CloseBuffer()
2817 if (bufferlist.close(owner->buffer()) && !quitting) {
2818 if (bufferlist.empty()) {
2819 // need this otherwise SEGV may occur while trying to
2820 // set variables that don't exist
2821 // since there's no current buffer
2822 CloseAllBufferRelatedPopups();
2825 owner->view()->buffer(bufferlist.first());
2831 Inset * LyXFunc::getInsetByCode(Inset::Code code)
2835 LyXCursor cursor = owner->view()->text->cursor;
2836 LyXParagraph::size_type pos = cursor.pos;
2837 LyXParagraph * par = cursor.par;
2839 while (par && !found) {
2840 while ((inset = par->ReturnNextInsetPointer(pos))){
2841 if (inset->LyxCode() == code) {
2849 return found ? inset : 0;
2853 // Each "owner" should have it's own message method. lyxview and
2854 // the minibuffer would use the minibuffer, but lyxserver would
2855 // send an ERROR signal to its client. Alejandro 970603
2856 // This func is bit problematic when it comes to NLS, to make the
2857 // lyx servers client be language indepenent we must not translate
2858 // strings sent to this func.
2859 void LyXFunc::setErrorMessage(string const & m) const
2861 dispatch_buffer = m;
2866 void LyXFunc::setMessage(string const & m)
2868 dispatch_buffer = m;