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 * ====================================================== */
20 #pragma implementation
23 #include "lyxlookup.h"
26 #include "bufferlist.h"
27 #include "lyxserver.h"
32 #include "LyXAction.h"
34 #include "insets/insetlatex.h"
36 #include "insets/inseturl.h"
37 #include "insets/insetlatexaccent.h"
38 #include "insets/insettoc.h"
39 #include "insets/insetlof.h"
40 #include "insets/insetloa.h"
41 #include "insets/insetlot.h"
42 #include "insets/insetref.h"
43 #include "insets/insetparent.h"
44 #include "insets/insetindex.h"
45 #include "insets/insetinclude.h"
46 #include "insets/insetbib.h"
47 #include "mathed/formulamacro.h"
49 #include "spellchecker.h" // RVDK_PATCH_5
50 #include "minibuffer.h"
54 #include "lyx_gui_misc.h"
55 #include "support/filetools.h"
56 #include "support/FileInfo.h"
57 #include "support/syscall.h"
58 #include "support/lstrings.h"
59 #include "support/path.h"
60 #include "lyxscreen.h"
65 #include "trans_mgr.h"
66 #include "ImportLaTeX.h"
67 #include "ImportNoweb.h"
70 extern bool cursor_follows_scrollbar;
72 extern void InsertAsciiFile(string const &, bool);
73 extern void math_insert_symbol(char const *);
74 extern Bool math_insert_greek(char const); // why "Bool"?
75 extern BufferList bufferlist;
76 extern LyXServer * lyxserver;
77 extern short greek_kb_flag;
78 extern FD_form_toc * fd_form_toc;
79 extern bool selection_possible;
81 extern kb_keymap * toplevel_keymap;
83 extern void MenuWrite(Buffer *);
84 extern void MenuWriteAs(Buffer *);
85 extern int MenuRunLaTeX(Buffer *);
86 extern int MenuBuildProg(Buffer *);
87 extern int MenuRunChktex(Buffer *);
88 extern bool CreatePostscript(Buffer *, bool);
89 extern void MenuPrint(Buffer *);
90 extern void MenuSendto();
91 extern void QuitLyX();
92 extern void MenuFax(Buffer *);
93 extern void MenuExport(Buffer *, string const &);
94 extern void MenuPasteSelection(char at);
95 extern LyXAction lyxaction;
97 extern tex_accent_struct get_accent(kb_action action);
99 extern void AutoSave();
100 extern void MenuSearch();
101 extern void SetUpdateTimer(float timer = 0.3);
102 extern void FreeUpdateTimer();
103 extern bool PreviewDVI(Buffer *);
104 extern bool PreviewPostscript(Buffer *);
105 extern void MenuInsertLabel(char const *);
106 extern void MenuInsertRef();
107 extern void MenuLayoutCharacter();
108 extern void MenuLayoutParagraph();
109 extern void MenuLayoutDocument();
110 extern void MenuLayoutPaper();
111 extern void MenuLayoutTable(int flag);
112 extern void MenuLayoutQuotes();
113 extern void MenuLayoutPreamble();
114 extern void MenuLayoutSave();
115 extern void bulletForm();
117 extern Buffer * NewLyxFile(string const &);
118 extern void LoadLyXFile(string const &);
119 extern void Reconfigure();
121 extern int current_layout;
122 extern int getISOCodeFromLaTeX(char *);
124 //extern int UnlockInset(UpdatableInset *);
126 extern void ShowLatexLog();
128 extern void UpdateInset(Inset * inset, bool mark_dirty = true);
130 /* === globals =========================================================== */
132 bool LyXFunc::show_sc = true;
135 LyXFunc::LyXFunc(LyXView * o)
139 lyx_dead_action = LFUN_NOACTION;
140 lyx_calling_dead_action = LFUN_NOACTION;
145 // I changed this func slightly. I commented out the ...FinishUndo(),
146 // this means that all places that used to have a moveCursorUpdate, now
147 // have a ...FinishUndo() as the preceeding statement. I have also added
148 // a moveCursorUpdate to some of the functions that updated the cursor, but
149 // that did not show its new position.
151 void LyXFunc::moveCursorUpdate(bool selecting)
153 if (selecting || owner->view()->text->mark_set) {
154 owner->view()->text->SetSelection();
155 owner->view()->getScreen()->ToggleToggle();
156 owner->view()->update(0);
158 owner->view()->update(-2); // this IS necessary
162 owner->view()->getScreen()->ShowCursor();
164 /* ---> Everytime the cursor is moved, show the current font state. */
165 // should this too me moved out of this func?
166 //owner->getMiniBuffer()->Set(CurrentState());
170 int LyXFunc::processKeyEvent(XEvent * ev)
174 XKeyEvent * keyevent = &ev->xkey;
175 KeySym keysym_return;
177 int num_bytes = LyXLookupString(ev, s_r, 10, &keysym_return);
178 s_r[num_bytes] = '\0';
180 if (lyxerr.debugging(Debug::KEY)) {
181 char * tmp = XKeysymToString(keysym_return);
182 string stm = (tmp ? tmp : "");
183 lyxerr << "KeySym is "
186 << keysym_return << "]"
187 << " and num_bytes is "
189 << " the string returned is \""
190 << s_r << '\"' << endl;
192 // Do nothing if we have nothing (JMarc)
193 if (num_bytes == 0 && keysym_return == NoSymbol) {
194 lyxerr[Debug::KEY] << "Empty kbd action (probably composing)"
199 // this function should be used always [asierra060396]
200 if (owner->view()->available() &&
201 owner->view()->the_locking_inset &&
202 keysym_return == XK_Escape) {
203 owner->view()->unlockInset(owner->view()->the_locking_inset);
204 owner->view()->text->CursorRight();
208 // Can we be sure that this will work for all X-Windows
209 // implementations? (Lgb)
210 // This code snippet makes lyx ignore some keys. Perhaps
211 // all of them should be explictly mentioned?
212 if((keysym_return >= XK_Shift_L && keysym_return <= XK_Hyper_R)
213 || keysym_return == XK_Mode_switch || keysym_return == 0x0)
216 // Do a one-deep top-level lookup for
217 // cancel and meta-fake keys. RVDK_PATCH_5
218 cancel_meta_seq.reset();
220 int action = cancel_meta_seq.addkey(keysym_return, keyevent->state
221 &(ShiftMask|ControlMask
224 // When not cancel or meta-fake, do the normal lookup.
225 // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
226 // Mostly, meta_fake_bit = 0. RVDK_PATCH_5.
227 if ( (action != LFUN_CANCEL) && (action != LFUN_META_FAKE) ) {
229 // remove Caps Lock and Mod2 as a modifiers
230 action = keyseq.addkey(keysym_return,
231 (keyevent->state | meta_fake_bit)
232 &(ShiftMask|ControlMask
235 // Dont remove this unless you know what you are doing.
238 if (action == 0) action = LFUN_PREFIX;
240 if (lyxerr.debugging(Debug::KEY)) {
246 << num_bytes << "]" << endl;
249 // already here we know if it any point in going further
250 // why not return already here if action == -1 and
251 // num_bytes == 0? (Lgb)
253 if(keyseq.length > 1 || keyseq.length < -1){
256 owner->getMiniBuffer()->Set(buf);
260 if (keyseq.length < -1) { // unknown key sequence...
264 owner->getMiniBuffer()->Set(_("Unknown sequence:"), buf);
268 char isochar = keyseq.getiso();
269 if (!(keyevent->state&ControlMask) &&
270 !(keyevent->state&Mod1Mask) &&
271 (isochar && keysym_return < 0xF000)) {
274 if (argument.empty()) {
275 lyxerr.debug() << "Empty argument!" << endl;
276 // This can`t possibly be of any use
277 // so we`ll skip the dispatch.
281 if (action == LFUN_SELFINSERT) {
285 bool tmp_sc = show_sc;
287 Dispatch(action, argument.c_str());
294 LyXFunc::func_status LyXFunc::getStatus(int ac) const
297 func_status flag = LyXFunc::OK;
299 Buffer * buf = owner->buffer();
301 if (lyxaction.isPseudoAction(ac))
302 action = lyxaction.retrieveActionArg(ac, argument);
304 action = static_cast<kb_action>(ac);
306 if (action == LFUN_UNKNOWN_ACTION) {
307 setErrorMessage(N_("Unknown action"));
308 return LyXFunc::Unknown;
311 // Check whether we need a buffer
312 if (!lyxaction.funcHasFlag(action, LyXAction::NoBuffer)) {
313 // Yes we need a buffer, do we have one?
316 // Can we use a readonly buffer?
317 if (buf->isReadonly() &&
318 !lyxaction.funcHasFlag(action,
319 LyXAction::ReadOnly)) {
321 setErrorMessage(N_("Document is read-only"));
322 flag |= LyXFunc::Disabled;
326 setErrorMessage(N_("Command not allowed with"
327 "out any document open"));
328 flag |= LyXFunc::Disabled;
332 if (flag & LyXFunc::Disabled)
335 // I would really like to avoid having this switch and rather try to
336 // encode this in the function itself.
337 static bool noLaTeX = lyxrc->latex_command == "none";
338 bool disable = false;
341 disable = noLaTeX || lyxrc->view_dvi_command == "none";
344 disable = noLaTeX || lyxrc->view_ps_command == "none";
351 disable = noLaTeX || lyxrc->print_command == "none";
354 disable = noLaTeX || lyxrc->fax_command == "none";
357 if (argument == "latex")
358 disable = lyxrc->relyx_command == "none";
361 if (argument == "dvi" || argument == "postscript")
363 if (argument == "html")
364 disable = lyxrc->html_command == "none";
367 disable = buf->undostack.empty();
370 disable = buf->redostack.empty();
372 case LFUN_SPELLCHECK:
373 disable = lyxrc->isp_command == "none";
376 disable = lyxrc->chktex_command == "none";
378 case LFUN_LAYOUT_TABLE:
379 disable = ! owner->view()->text->cursor.par->table;
385 flag |= LyXFunc::Disabled;
388 func_status box = LyXFunc::ToggleOff;
389 LyXFont font = owner->view()->text->real_current_font;
392 if (font.emph() == LyXFont::ON)
393 box = LyXFunc::ToggleOn;
396 if (font.noun() == LyXFont::ON)
397 box = LyXFunc::ToggleOn;
400 if (font.series() == LyXFont::BOLD_SERIES)
401 box = LyXFunc::ToggleOn;
404 if (font.latex() == LyXFont::ON)
405 box = LyXFunc::ToggleOn;
418 string LyXFunc::Dispatch(string const & s)
420 // Split command string into command and argument
421 string cmd, line = frontStrip(s);
422 string arg = strip(frontStrip(split(line, cmd, ' ')));
424 return Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
428 string LyXFunc::Dispatch(int ac,
429 char const * do_not_use_this_arg)
434 FL_OBJECT * ob = 0; // This will disapear soon
436 // we have not done anything wrong yet.
438 dispatch_buffer.clear();
440 // if action is a pseudo-action, we need the real action
441 if (lyxaction.isPseudoAction(ac)) {
443 action = static_cast<kb_action>
444 (lyxaction.retrieveActionArg(ac, tmparg));
448 action = static_cast<kb_action>(ac);
449 if (do_not_use_this_arg)
450 argument = do_not_use_this_arg; // except here
453 selection_possible = false;
455 if (owner->view()->available()
456 && owner->view()->getScreen())
457 owner->view()->getScreen()->HideCursor();
459 // We cannot use this function here
460 if (getStatus(action) & Disabled)
461 goto exit_with_message;
463 commandshortcut.clear();
465 if (lyxrc->display_shortcuts && show_sc) {
466 if (action != LFUN_SELFINSERT) {
467 // Put name of command and list of shortcuts
468 // for it in minibuffer
469 string comname = lyxaction.getActionName(action);
471 int pseudoaction = action;
472 bool argsadded = false;
474 if (!argument.empty()) {
475 // If we have the command with argument,
478 lyxaction.searchActionArg(action,
481 if (pseudoaction == -1) {
482 pseudoaction = action;
484 comname += " " + argument;
489 string shortcuts = toplevel_keymap->findbinding(pseudoaction);
491 if (!shortcuts.empty()) {
492 comname += ": " + shortcuts;
493 } else if (!argsadded) {
494 comname += " " + argument;
497 if (!comname.empty()) {
498 comname = strip(comname);
499 commandshortcut = "(" + comname + ')';
500 owner->getMiniBuffer()->Set(commandshortcut);
501 // Here we could even add a small pause,
502 // to annoy the user and make him learn
504 // No! That will just annoy, not teach
505 // anything. The user will read the messages
506 // if they are interested. (Asger)
511 // If in math mode pass the control to
512 // the math inset [asierra060396]
513 if (owner->view()->available() &&
514 owner->view()->the_locking_inset) {
516 || (action == LFUN_UNKNOWN_ACTION
517 && keyseq.length >= -1)) {
518 if (action == LFUN_UNKNOWN_ACTION
519 && argument.empty()) {
520 argument = keyseq.getiso();
522 // Undo/Redo pre 0.13 is a bit tricky for insets.
523 if (action == LFUN_UNDO) {
525 UpdatableInset * inset =
526 owner->view()->the_locking_inset;
527 inset->GetCursorPos(slx, sly);
528 owner->view()->unlockInset(inset);
529 owner->view()->menuUndo();
530 inset = static_cast<UpdatableInset*>(owner->view()->text->cursor.par->GetInset(owner->view()->text->cursor.pos));
532 inset->Edit(slx, sly);
535 if (action == LFUN_REDO) {
537 UpdatableInset * inset = owner->view()->the_locking_inset;
538 inset->GetCursorPos(slx, sly);
539 owner->view()->unlockInset(inset);
540 owner->view()->menuRedo();
541 inset = static_cast<UpdatableInset*>(owner->view()->text->cursor.par->GetInset(owner->view()->text->cursor.pos));
543 inset->Edit(slx, sly);
546 if (owner->view()->the_locking_inset->LocalDispatch(action, argument.c_str()))
549 setMessage(N_("Text mode"));
550 if (action == LFUN_RIGHT || action == -1)
551 owner->view()->text->CursorRight();
552 if (action == LFUN_LEFT || action == LFUN_RIGHT)
559 // --- Misc -------------------------------------------
560 case LFUN_WORDFINDFORWARD :
561 case LFUN_WORDFINDBACKWARD : {
562 static string last_search;
563 string searched_string;
565 if (!argument.empty()) {
566 last_search = argument;
567 searched_string = argument;
569 searched_string = last_search;
572 LyXText * ltCur = owner->view()->text ;
574 if (!searched_string.empty() &&
575 ((action == LFUN_WORDFINDBACKWARD) ?
576 ltCur->SearchBackward(searched_string.c_str()) :
577 ltCur->SearchForward(searched_string.c_str()))) {
579 // ??? What is that ???
580 owner->view()->update(-2);
583 // clear the selection (if there is any)
584 owner->view()->getScreen()->ToggleSelection();
585 owner->view()->text->ClearSelection();
587 // Move cursor so that successive C-s 's will not stand in place.
588 if( action == LFUN_WORDFINDFORWARD )
589 owner->view()->text->CursorRightOneWord();
590 owner->view()->text->FinishUndo();
591 moveCursorUpdate(false);
594 // set the new selection
595 // SetSelectionOverLenChars(owner->view()->currentBuffer()->text, iLenSelected);
596 owner->view()->getScreen()->ToggleSelection(false);
600 // REMOVED : if (owner->view()->getWorkArea()->focus)
601 owner->view()->getScreen()->ShowCursor();
607 if (owner->view()->available()
608 && owner->view()->getScreen()) {
609 owner->view()->update(-2);
612 keyseq.print(buf, true);
613 owner->getMiniBuffer()->Set(buf, string(), string(), 1);
617 // --- Misc -------------------------------------------
618 case LFUN_EXEC_COMMAND:
619 owner->getMiniBuffer()->ExecCommand();
622 case LFUN_CANCEL: // RVDK_PATCH_5
625 if(owner->view()->available())
626 // cancel any selection
627 Dispatch(LFUN_MARK_OFF, 0);
628 setMessage(N_("Cancel"));
631 case LFUN_META_FAKE: // RVDK_PATCH_5
633 meta_fake_bit = Mod1Mask;
635 keyseq.print(buf, true);
636 string res = string("M-") + buf;
637 setMessage(buf); // RVDK_PATCH_5
641 case LFUN_READ_ONLY_TOGGLE:
642 if (owner->buffer()->lyxvc.inUse()) {
643 owner->buffer()->lyxvc.toggleReadOnly();
645 owner->buffer()->setReadonly(
646 !owner->buffer()->isReadonly());
650 case LFUN_CENTER: // this is center and redraw.
651 owner->view()->beforeChange();
652 if (owner->view()->text->cursor.y >
653 owner->view()->getWorkArea()->h / 2) {
654 owner->view()->getScreen()->
655 Draw(owner->view()->text->cursor.y -
656 owner->view()->getWorkArea()->h / 2);
658 owner->view()->getScreen()->
661 owner->view()->update(0);
662 owner->view()->redraw();
666 if (owner->view()->available()) {
667 owner->view()->text->toggleAppendix();
668 owner->view()->update(1);
672 // --- Menus -----------------------------------------------
677 case LFUN_MENUNEWTMPLT:
685 case LFUN_CLOSEBUFFER:
690 MenuWrite(owner->buffer());
693 case LFUN_MENUWRITEAS:
694 MenuWriteAs(owner->buffer());
697 case LFUN_MENURELOAD:
702 PreviewDVI(owner->buffer());
706 PreviewPostscript(owner->buffer());
710 MenuRunLaTeX(owner->buffer());
714 MenuBuildProg(owner->buffer());
718 MenuRunChktex(owner->buffer());
722 CreatePostscript(owner->buffer(), false);
726 MenuPrint(owner->buffer());
730 MenuFax(owner->buffer());
734 MenuExport(owner->buffer(), argument);
739 //needs argument as string
740 string imtyp = argument;
743 if (imtyp == "latex") {
744 doImportLaTeX(false);
747 else if (imtyp == "ascii") {
748 doImportASCII(false);
749 } else if (imtyp == "asciiparagraph") {
752 } else if (imtyp == "noweb") {
755 setErrorMessage(string(N_("Unknown import type: "))
767 if (fd_form_toc->form_toc->visible) {
768 fl_raise_form(fd_form_toc->form_toc);
770 static int ow = -1, oh;
771 fl_show_form(fd_form_toc->form_toc,
773 FL_FREE_SIZE, FL_FULLBORDER,
774 _("Table of Contents"));
776 ow = fd_form_toc->form_toc->w;
777 oh = fd_form_toc->form_toc->h;
779 fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
783 case LFUN_TOC_INSERT:
785 Inset * new_inset = new InsetTOC(owner->buffer());
786 owner->view()->insertInset(new_inset, "Standard", true);
790 case LFUN_LOF_INSERT:
792 Inset * new_inset = new InsetLOF(owner->buffer());
793 owner->view()->insertInset(new_inset, "Standard", true);
797 case LFUN_LOA_INSERT:
799 Inset * new_inset = new InsetLOA(owner->buffer());
800 owner->view()->insertInset(new_inset, "Standard", true);
804 case LFUN_LOT_INSERT:
806 Inset * new_inset = new InsetLOT(owner->buffer());
807 owner->view()->insertInset(new_inset, "Standard", true);
824 owner->view()->menuUndo();
828 owner->view()->menuRedo();
831 case LFUN_MENUSEARCH:
836 owner->view()->paste();
839 case LFUN_PASTESELECTION:
842 if (argument == "paragraph") asPara = true;
843 MenuPasteSelection(asPara);
848 owner->view()->cut();
852 owner->view()->copy();
855 case LFUN_LAYOUT_COPY:
856 owner->view()->copyEnvironment();
859 case LFUN_LAYOUT_PASTE:
860 owner->view()->pasteEnvironment();
864 owner->view()->gotoError();
867 case LFUN_REMOVEERRORS:
868 if (owner->view()->removeAutoInsets()) {
869 owner->view()->redraw();
870 owner->view()->fitCursor();
871 owner->view()->updateScrollbar();
876 owner->view()->gotoNote();
880 owner->view()->openStuff();
883 case LFUN_HYPHENATION:
884 owner->view()->hyphenationPoint();
888 owner->view()->ldots();
891 case LFUN_END_OF_SENTENCE:
892 owner->view()->endOfSentenceDot();
895 case LFUN_MENU_SEPARATOR:
896 owner->view()->menuSeparator();
900 owner->view()->hfill();
911 case LFUN_DEPTH_PLUS:
927 case LFUN_RECONFIGURE:
932 if (owner->view()->available()
933 && !owner->view()->text->selection
934 && owner->view()->text->cursor.par->footnoteflag
935 != LyXParagraph::NO_FOOTNOTE)
936 { // only melt footnotes with FOOTMELT, not margins etc
937 if(owner->view()->text->cursor.par->footnotekind == LyXParagraph::FOOTNOTE)
944 case LFUN_MARGINMELT:
945 if (owner->view()->available()
946 && !owner->view()->text->selection
947 && owner->view()->text->cursor.par->footnoteflag
948 != LyXParagraph::NO_FOOTNOTE) {
950 if(owner->view()->text->cursor.par->footnotekind == LyXParagraph::MARGIN)
957 // --- version control -------------------------------
958 case LFUN_VC_REGISTER:
960 if (!owner->buffer()->lyxvc.inUse())
961 owner->buffer()->lyxvc.registrer();
965 case LFUN_VC_CHECKIN:
967 if (owner->buffer()->lyxvc.inUse()
968 && !owner->buffer()->isReadonly())
969 owner->buffer()->lyxvc.checkIn();
973 case LFUN_VC_CHECKOUT:
975 if (owner->buffer()->lyxvc.inUse()
976 && owner->buffer()->isReadonly())
977 owner->buffer()->lyxvc.checkOut();
983 owner->buffer()->lyxvc.revert();
989 owner->buffer()->lyxvc.undoLast();
993 case LFUN_VC_HISTORY:
995 owner->buffer()->lyxvc.showLog();
999 // --- buffers ----------------------------------------
1000 case LFUN_PREVBUFFER:
1001 #ifdef WITH_WARNINGS
1002 #warning fix this please
1004 // it is the LyXView or the BufferView that should
1005 // remember the previous buffer, not bufferlist.
1006 // if (owner->view()->available()){
1007 // owner->view()->beforeChange();
1008 // owner->buffer()->update(-2);
1010 // owner->view()->setBuffer(bufferlist.prev());
1013 // resizeCurrentBufferPseudoExpose();
1016 case LFUN_FILE_INSERT:
1018 MenuInsertLyXFile(argument);
1022 case LFUN_FILE_INSERT_ASCII:
1024 bool asPara = (argument == "paragraph");
1025 InsertAsciiFile(string(), asPara);
1031 // servercmd: argument must be <file>:<template>
1032 Buffer * tmpbuf = NewLyxFile(argument);
1034 owner->view()->buffer(tmpbuf);
1038 case LFUN_FILE_OPEN:
1039 owner->view()->buffer(bufferlist.loadLyXFile(argument));
1042 case LFUN_LATEX_LOG:
1048 lyxerr.debug() << "LFUN_LAYOUTNO: (arg) " << argument << endl;
1049 int sel = strToInt(argument);
1050 lyxerr.debug() << "LFUN_LAYOUTNO: (sel) "<< sel << endl;
1052 // Should this give a setMessage instead?
1054 return string(); // illegal argument
1056 --sel; // sel 1..., but layout 0...
1058 // Pretend we got the name instead.
1059 Dispatch(int(LFUN_LAYOUT),
1060 textclasslist.NameOfLayout(owner->view()->
1069 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1070 << argument << endl;
1072 // Derive layout number from given argument (string)
1073 // and current buffer's textclass (number). */
1075 textclasslist.NumberOfLayout(owner->
1081 // see if we found the layout number:
1082 if (layoutno == -1) {
1083 setErrorMessage(string(N_("Layout ")) + argument +
1088 if (current_layout != layoutno) {
1089 owner->view()->getScreen()->HideCursor();
1090 current_layout = layoutno;
1091 owner->view()->update(-2);
1092 owner->view()->text->
1093 SetLayout(layoutno);
1094 owner->getToolbar()->combox->
1095 select(owner->view()->
1098 owner->view()->update(1);
1103 case LFUN_LAYOUT_DOCUMENT:
1104 MenuLayoutDocument();
1107 case LFUN_LAYOUT_PARAGRAPH:
1108 MenuLayoutParagraph();
1111 case LFUN_LAYOUT_CHARACTER:
1112 MenuLayoutCharacter();
1115 case LFUN_LAYOUT_TABLE:
1118 if (argument == "true") flag = 1;
1119 MenuLayoutTable(flag);
1123 case LFUN_LAYOUT_PAPER:
1127 case LFUN_LAYOUT_QUOTES:
1131 case LFUN_LAYOUT_PREAMBLE:
1132 MenuLayoutPreamble();
1135 case LFUN_LAYOUT_SAVE_DEFAULT:
1139 case LFUN_DROP_LAYOUTS_CHOICE:
1140 owner->getToolbar()->combox->Show();
1171 case LFUN_UNDERLINE:
1175 case LFUN_FONT_SIZE:
1176 FontSizeCB(argument);
1179 case LFUN_FONT_STATE:
1180 setMessage(CurrentState());
1183 case LFUN_UPCASE_WORD:
1184 owner->view()->update(-2);
1186 owner->view()->text->ChangeWordCase(LyXText::text_uppercase);
1187 owner->view()->update(1);
1191 case LFUN_LOWCASE_WORD:
1192 owner->view()->update(-2);
1194 owner->view()->text->ChangeWordCase(LyXText::text_lowercase);
1195 owner->view()->update(1);
1199 case LFUN_CAPITALIZE_WORD:
1200 owner->view()->update(-2);
1202 owner->view()->text->ChangeWordCase(LyXText::text_capitalization);
1203 owner->view()->update(1);
1207 case LFUN_INSERT_LABEL:
1208 MenuInsertLabel(argument.c_str());
1211 case LFUN_INSERT_REF:
1215 case LFUN_REFTOGGLE:
1218 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1220 if (inset->getFlag() == InsetRef::REF)
1221 inset->setFlag(InsetRef::PAGE_REF);
1223 inset->setFlag(InsetRef::REF);
1226 setErrorMessage(N_("No cross-reference to toggle"));
1233 owner->view()->restorePosition();
1239 string label(argument);
1240 if (label.empty()) {
1242 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1244 label = inset->getContents();
1247 if (!label.empty()) {
1248 owner->view()->savePosition();
1249 owner->view()->gotoLabel(label.c_str());
1254 case LFUN_MENU_OPEN_BY_NAME:
1255 owner->getMenus()->openByName(argument);
1256 break; // RVDK_PATCH_5
1258 case LFUN_SPELLCHECK:
1259 if (lyxrc->isp_command != "none")
1261 break; // RVDK_PATCH_5
1263 // --- Cursor Movements -----------------------------
1266 LyXText * tmptext = owner->view()->text;
1267 if(!tmptext->mark_set)
1268 owner->view()->beforeChange();
1269 owner->view()->update(-2);
1270 if (tmptext->cursor.pos < tmptext->cursor.par->Last()
1271 && tmptext->cursor.par->GetChar(tmptext->cursor.pos)
1272 == LyXParagraph::META_INSET
1273 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)
1274 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)->Editable() == 2){
1275 Inset * tmpinset = tmptext->cursor.par->GetInset(tmptext->cursor.pos);
1276 setMessage(tmpinset->EditMessage());
1277 tmpinset->Edit(0, 0);
1280 tmptext->CursorRight();
1281 owner->view()->text->FinishUndo();
1282 moveCursorUpdate(false);
1283 owner->getMiniBuffer()->Set(CurrentState());
1289 // This is soooo ugly. Isn`t it possible to make
1290 // it simpler? (Lgb)
1291 LyXText * txt = owner->view()->text;
1292 if(!txt->mark_set) owner->view()->beforeChange();
1293 owner->view()->update(-2);
1295 if (txt->cursor.pos < txt->cursor.par->Last()
1296 && txt->cursor.par->GetChar(txt->cursor.pos)
1297 == LyXParagraph::META_INSET
1298 && txt->cursor.par->GetInset(txt->cursor.pos)
1299 && txt->cursor.par->GetInset(txt->cursor.pos)->Editable() == 2) {
1300 Inset * tmpinset = txt->cursor.par->GetInset(txt->cursor.pos);
1301 setMessage(tmpinset->EditMessage());
1302 tmpinset->Edit(tmpinset->Width(txt->GetFont(txt->cursor.par,
1303 txt->cursor.pos)), 0);
1306 owner->view()->text->FinishUndo();
1307 moveCursorUpdate(false);
1308 owner->getMiniBuffer()->Set(CurrentState());
1313 if(!owner->view()->text->mark_set) owner->view()->beforeChange();
1314 owner->view()->update(-3);
1315 owner->view()->text->CursorUp();
1316 owner->view()->text->FinishUndo();
1317 moveCursorUpdate(false);
1318 owner->getMiniBuffer()->Set(CurrentState());
1322 if(!owner->view()->text->mark_set)
1323 owner->view()->beforeChange();
1324 owner->view()->update(-3);
1325 owner->view()->text->CursorDown();
1326 owner->view()->text->FinishUndo();
1327 moveCursorUpdate(false);
1328 owner->getMiniBuffer()->Set(CurrentState());
1331 case LFUN_UP_PARAGRAPH:
1332 if(!owner->view()->text->mark_set)
1333 owner->view()->beforeChange();
1334 owner->view()->update(-3);
1335 owner->view()->text->CursorUpParagraph();
1336 owner->view()->text->FinishUndo();
1337 moveCursorUpdate(false);
1338 owner->getMiniBuffer()->Set(CurrentState());
1341 case LFUN_DOWN_PARAGRAPH:
1342 if(!owner->view()->text->mark_set)
1343 owner->view()->beforeChange();
1344 owner->view()->update(-3);
1345 owner->view()->text->CursorDownParagraph();
1346 owner->view()->text->FinishUndo();
1347 moveCursorUpdate(false);
1348 owner->getMiniBuffer()->Set(CurrentState());
1352 if(!owner->view()->text->mark_set)
1353 owner->view()->beforeChange();
1354 owner->view()->update(-3);
1355 owner->view()->cursorPrevious();
1356 owner->view()->text->FinishUndo();
1357 moveCursorUpdate(false);
1358 owner->getMiniBuffer()->Set(CurrentState());
1362 if(!owner->view()->text->mark_set)
1363 owner->view()->beforeChange();
1364 owner->view()->update(-3);
1365 owner->view()->cursorNext();
1366 owner->view()->text->FinishUndo();
1367 moveCursorUpdate(false);
1368 owner->getMiniBuffer()->Set(CurrentState());
1372 if(!owner->view()->text->mark_set)
1373 owner->view()->beforeChange();
1374 owner->view()->update(-2);
1375 owner->view()->text->CursorHome();
1376 owner->view()->text->FinishUndo();
1377 moveCursorUpdate(false);
1378 owner->getMiniBuffer()->Set(CurrentState());
1382 if(!owner->view()->text->mark_set)
1383 owner->view()->beforeChange();
1384 owner->view()->update(-2);
1385 owner->view()->text->CursorEnd();
1386 owner->view()->text->FinishUndo();
1387 moveCursorUpdate(false);
1388 owner->getMiniBuffer()->Set(CurrentState());
1392 if(!owner->view()->text->mark_set)
1393 owner->view()->beforeChange();
1394 owner->view()->update(-2);
1395 owner->view()->text->CursorTab();
1396 owner->view()->text->FinishUndo();
1397 moveCursorUpdate(false);
1398 owner->getMiniBuffer()->Set(CurrentState());
1401 case LFUN_WORDRIGHT:
1402 if(!owner->view()->text->mark_set)
1403 owner->view()->beforeChange();
1404 owner->view()->update(-2);
1405 owner->view()->text->CursorRightOneWord();
1406 owner->view()->text->FinishUndo();
1407 moveCursorUpdate(false);
1408 owner->getMiniBuffer()->Set(CurrentState());
1412 if(!owner->view()->text->mark_set)
1413 owner->view()->beforeChange();
1414 owner->view()->update(-2);
1415 owner->view()->text->CursorLeftOneWord();
1416 owner->view()->text->FinishUndo();
1417 moveCursorUpdate(false);
1418 owner->getMiniBuffer()->Set(CurrentState());
1421 case LFUN_BEGINNINGBUF:
1422 if(!owner->view()->text->mark_set)
1423 owner->view()->beforeChange();
1424 owner->view()->update(-2);
1425 owner->view()->text->CursorTop();
1426 owner->view()->text->FinishUndo();
1427 moveCursorUpdate(false);
1428 owner->getMiniBuffer()->Set(CurrentState());
1432 if(!owner->view()->text->mark_set)
1433 owner->view()->beforeChange();
1434 owner->view()->update(-2);
1435 owner->view()->text->CursorBottom();
1436 owner->view()->text->FinishUndo();
1437 moveCursorUpdate(false);
1438 owner->getMiniBuffer()->Set(CurrentState());
1442 /* cursor selection ---------------------------- */
1444 owner->view()->update(-2);
1445 owner->view()->text->CursorRight();
1446 owner->view()->text->FinishUndo();
1447 moveCursorUpdate(true);
1448 owner->getMiniBuffer()->Set(CurrentState());
1452 owner->view()->update(-2);
1453 owner->view()->text->CursorLeft();
1454 owner->view()->text->FinishUndo();
1455 moveCursorUpdate(true);
1456 owner->getMiniBuffer()->Set(CurrentState());
1460 owner->view()->update(-2);
1461 owner->view()->text->CursorUp();
1462 owner->view()->text->FinishUndo();
1463 moveCursorUpdate(true);
1464 owner->getMiniBuffer()->Set(CurrentState());
1468 owner->view()->update(-2);
1469 owner->view()->text->CursorDown();
1470 owner->view()->text->FinishUndo();
1471 moveCursorUpdate(true);
1472 owner->getMiniBuffer()->Set(CurrentState());
1475 case LFUN_UP_PARAGRAPHSEL:
1476 owner->view()->update(-2);
1477 owner->view()->text->CursorUpParagraph();
1478 owner->view()->text->FinishUndo();
1479 moveCursorUpdate(true);
1480 owner->getMiniBuffer()->Set(CurrentState());
1483 case LFUN_DOWN_PARAGRAPHSEL:
1484 owner->view()->update(-2);
1485 owner->view()->text->CursorDownParagraph();
1486 owner->view()->text->FinishUndo();
1487 moveCursorUpdate(true);
1488 owner->getMiniBuffer()->Set(CurrentState());
1492 owner->view()->update(-2);
1493 owner->view()->cursorPrevious();
1494 owner->view()->text->FinishUndo();
1495 moveCursorUpdate(true);
1496 owner->getMiniBuffer()->Set(CurrentState());
1500 owner->view()->update(-2);
1501 owner->view()->cursorNext();
1502 owner->view()->text->FinishUndo();
1503 moveCursorUpdate(true);
1504 owner->getMiniBuffer()->Set(CurrentState());
1508 owner->view()->update(-2);
1509 owner->view()->text->CursorHome();
1510 owner->view()->text->FinishUndo();
1511 moveCursorUpdate(true);
1512 owner->getMiniBuffer()->Set(CurrentState());
1516 owner->view()->update(-2);
1517 owner->view()->text->CursorEnd();
1518 owner->view()->text->FinishUndo();
1519 moveCursorUpdate(true);
1520 owner->getMiniBuffer()->Set(CurrentState());
1523 case LFUN_WORDRIGHTSEL:
1524 owner->view()->update(-2);
1525 owner->view()->text->CursorRightOneWord();
1526 owner->view()->text->FinishUndo();
1527 moveCursorUpdate(true);
1528 owner->getMiniBuffer()->Set(CurrentState());
1531 case LFUN_WORDLEFTSEL:
1532 owner->view()->update(-2);
1533 owner->view()->text->CursorLeftOneWord();
1534 owner->view()->text->FinishUndo();
1535 moveCursorUpdate(true);
1536 owner->getMiniBuffer()->Set(CurrentState());
1539 case LFUN_BEGINNINGBUFSEL:
1540 owner->view()->update(-2);
1541 owner->view()->text->CursorTop();
1542 owner->view()->text->FinishUndo();
1543 moveCursorUpdate(true);
1544 owner->getMiniBuffer()->Set(CurrentState());
1547 case LFUN_ENDBUFSEL:
1548 owner->view()->update(-2);
1549 owner->view()->text->CursorBottom();
1550 owner->view()->text->FinishUndo();
1551 moveCursorUpdate(true);
1552 owner->getMiniBuffer()->Set(CurrentState());
1555 // --- text changing commands ------------------------
1556 case LFUN_BREAKLINE:
1557 owner->view()->beforeChange();
1558 owner->view()->text->InsertChar(LyXParagraph::META_NEWLINE);
1559 owner->view()->smallUpdate(1);
1560 SetUpdateTimer(0.01);
1561 moveCursorUpdate(false);
1564 case LFUN_PROTECTEDSPACE:
1565 owner->view()->beforeChange();
1566 owner->view()->text->
1567 InsertChar(LyXParagraph::META_PROTECTED_SEPARATOR);
1568 owner->view()->smallUpdate(1);
1570 moveCursorUpdate(false);
1574 if(owner->view()->text->mark_set) {
1575 owner->view()->beforeChange();
1576 owner->view()->update(0);
1577 setMessage(N_("Mark removed"));
1579 owner->view()->beforeChange();
1580 owner->view()->text->mark_set = 1;
1581 owner->view()->update(0);
1582 setMessage(N_("Mark set"));
1584 owner->view()->text->sel_cursor =
1585 owner->view()->text->cursor;
1590 if (!owner->view()->text->selection) {
1591 owner->view()->text->Delete();
1592 owner->view()->text->sel_cursor =
1593 owner->view()->text->cursor;
1594 owner->view()->smallUpdate(1);
1595 // It is possible to make it a lot faster still
1596 // just comment out the lone below...
1597 owner->view()->getScreen()->ShowCursor();
1599 owner->view()->cut();
1604 case LFUN_DELETE_SKIP:
1606 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1608 LyXCursor cursor = owner->view()->text->cursor;
1611 if (!owner->view()->text->selection) {
1612 if (cursor.pos == cursor.par->Last()) {
1613 owner->view()->text->CursorRight();
1614 cursor = owner->view()->text->cursor;
1616 && !(cursor.par->added_space_top
1617 == VSpace (VSpace::NONE))) {
1618 owner->view()->text->SetParagraph
1619 (cursor.par->line_top,
1620 cursor.par->line_bottom,
1621 cursor.par->pagebreak_top,
1622 cursor.par->pagebreak_bottom,
1623 VSpace(VSpace::NONE),
1624 cursor.par->added_space_bottom,
1626 cursor.par->labelwidthstring, 0);
1627 owner->view()->text->CursorLeft();
1628 owner->view()->update (1);
1630 owner->view()->text->CursorLeft();
1631 owner->view()->text->Delete();
1632 owner->view()->text->sel_cursor =
1633 owner->view()->text->cursor;
1634 owner->view()->smallUpdate(1);
1637 owner->view()->text->Delete();
1638 owner->view()->text->sel_cursor =
1639 owner->view()->text->cursor;
1640 owner->view()->smallUpdate(1);
1643 owner->view()->cut();
1649 /* -------> Delete word forward. */
1650 case LFUN_DELETE_WORD_FORWARD:
1651 owner->view()->update(-2);
1653 owner->view()->text->DeleteWordForward();
1654 owner->view()->update( 1 );
1656 moveCursorUpdate(false);
1659 /* -------> Delete word backward. */
1660 case LFUN_DELETE_WORD_BACKWARD:
1661 owner->view()->update(-2);
1663 owner->view()->text->DeleteWordBackward();
1664 owner->view()->update( 1 );
1666 moveCursorUpdate(false);
1669 /* -------> Kill to end of line. */
1670 case LFUN_DELETE_LINE_FORWARD:
1672 owner->view()->update(-2);
1673 owner->view()->text->DeleteLineForward();
1674 owner->view()->update( 1 );
1676 moveCursorUpdate(false);
1679 /* -------> Set mark off. */
1681 owner->view()->beforeChange();
1682 owner->view()->update(0);
1683 owner->view()->text->sel_cursor =
1684 owner->view()->text->cursor;
1685 setMessage(N_("Mark off"));
1688 /* -------> Set mark on. */
1690 owner->view()->beforeChange();
1691 owner->view()->text->mark_set = 1;
1692 owner->view()->update( 0 );
1693 owner->view()->text->sel_cursor =
1694 owner->view()->text->cursor;
1695 setMessage(N_("Mark on"));
1698 case LFUN_BACKSPACE:
1701 if (!owner->view()->text->selection) {
1702 if (owner->getIntl()->getTrans()->backspace()) {
1703 owner->view()->text->Backspace();
1704 owner->view()->text->sel_cursor =
1705 owner->view()->text->cursor;
1706 owner->view()->smallUpdate(1);
1707 // It is possible to make it a lot faster still
1708 // just comment out the lone below...
1709 owner->view()->getScreen()->ShowCursor();
1712 owner->view()->cut();
1718 case LFUN_BACKSPACE_SKIP:
1720 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1722 LyXCursor cursor = owner->view()->text->cursor;
1725 if (!owner->view()->text->selection) {
1727 && !(cursor.par->added_space_top
1728 == VSpace (VSpace::NONE))) {
1729 owner->view()->text->SetParagraph
1730 (cursor.par->line_top,
1731 cursor.par->line_bottom,
1732 cursor.par->pagebreak_top,
1733 cursor.par->pagebreak_bottom,
1734 VSpace(VSpace::NONE), cursor.par->added_space_bottom,
1736 cursor.par->labelwidthstring, 0);
1737 owner->view()->update (1);
1739 owner->view()->text->Backspace();
1740 owner->view()->text->sel_cursor
1742 owner->view()->smallUpdate (1);
1745 owner->view()->cut();
1750 case LFUN_BREAKPARAGRAPH:
1752 owner->view()->beforeChange();
1753 owner->view()->text->BreakParagraph(0);
1754 owner->view()->smallUpdate(1);
1755 SetUpdateTimer(0.01);
1756 owner->view()->text->sel_cursor =
1757 owner->view()->text->cursor;
1761 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1763 owner->view()->beforeChange();
1764 owner->view()->text->BreakParagraph(1);
1765 owner->view()->smallUpdate(1);
1766 SetUpdateTimer(0.01);
1767 owner->view()->text->sel_cursor =
1768 owner->view()->text->cursor;
1772 case LFUN_BREAKPARAGRAPH_SKIP:
1774 // When at the beginning of a paragraph, remove
1775 // indentation and add a "defskip" at the top.
1776 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
1778 LyXCursor cursor = owner->view()->text->cursor;
1780 owner->view()->beforeChange();
1781 if (cursor.pos == 0) {
1782 if (cursor.par->added_space_top == VSpace(VSpace::NONE)) {
1783 owner->view()->text->SetParagraph
1784 (cursor.par->line_top,
1785 cursor.par->line_bottom,
1786 cursor.par->pagebreak_top,
1787 cursor.par->pagebreak_bottom,
1788 VSpace(VSpace::DEFSKIP), cursor.par->added_space_bottom,
1790 cursor.par->labelwidthstring, 1);
1791 owner->view()->update(1);
1795 owner->view()->text->BreakParagraph(0);
1796 owner->view()->smallUpdate(1);
1798 SetUpdateTimer(0.01);
1799 owner->view()->text->sel_cursor = cursor;
1804 owner->view()->beforeChange();
1805 owner->view()->text->InsertChar('\"'); // This " matches the single quote in the code
1806 owner->view()->smallUpdate(1);
1808 moveCursorUpdate(false);
1814 InsetCommand * new_inset;
1815 if (action == LFUN_HTMLURL)
1816 new_inset = new InsetUrl("htmlurl", "", "");
1818 new_inset = new InsetUrl("url", "", "");
1819 owner->view()->insertInset(new_inset);
1820 new_inset->Edit(0, 0);
1824 // --- lyxserver commands ----------------------------
1826 case LFUN_CHARATCURSOR:
1828 LyXParagraph::size_type pos =
1829 owner->view()->text->cursor.pos;
1830 if(pos < owner->view()->text->cursor.par->size())
1831 dispatch_buffer = owner->view()->text->
1832 cursor.par->text[pos];
1834 dispatch_buffer = "EOF";
1840 tostr(owner->view()->text->cursor.x) + ' '
1841 + tostr(owner->view()->text->cursor.y);
1848 sscanf(argument.c_str(), " %d %ld", &x, &y);
1849 owner->view()->text->SetCursorFromCoordinates(x, y);
1853 case LFUN_GETLAYOUT:
1855 tostr(owner->view()->text->cursor.par->layout);
1860 LyXFont * font = &(owner->view()->text->current_font);
1861 if(font->shape() == LyXFont::ITALIC_SHAPE)
1862 dispatch_buffer = 'E';
1863 else if(font->shape() == LyXFont::SMALLCAPS_SHAPE)
1864 dispatch_buffer = 'N';
1866 dispatch_buffer = '0';
1873 LyXFont * font = &(owner->view()->text->current_font);
1874 if(font->latex() == LyXFont::ON)
1875 dispatch_buffer = 'L';
1877 dispatch_buffer = '0';
1882 setMessage(owner->buffer()->fileName());
1883 lyxerr.debug() << "FNAME["
1884 << owner->buffer()->fileName()
1892 dispatch_buffer = buf;
1893 lyxserver->notifyClient(dispatch_buffer);
1897 case LFUN_GOTOFILEROW:
1899 char file_name[100];
1901 sscanf(argument.c_str(), " %s %d", file_name, &row);
1903 // Must replace extension of the file to be .lyx and get full path
1904 string s = ChangeExtension(string(file_name), ".lyx", false);
1906 // Either change buffer or load the file
1907 if (bufferlist.exists(s))
1908 owner->view()->buffer(bufferlist.getBuffer(s));
1910 owner->view()->buffer(bufferlist.loadLyXFile(s));
1913 owner->view()->setCursorFromRow(row);
1916 owner->view()->beforeChange();
1917 if (owner->view()->text->cursor.y >
1918 owner->view()->getWorkArea()->h / 2) {
1919 owner->view()->getScreen()->
1920 Draw(owner->view()->text->cursor.y -
1921 owner->view()->getWorkArea()->h/2);
1923 owner->view()->getScreen()->
1926 owner->view()->update(0);
1927 owner->view()->redraw();
1934 int qa = lyxaction.LookupFunc(argument.c_str());
1935 setMessage(lyxaction.helpText(static_cast<kb_action>(qa)));
1939 // --- accented characters ---------------------------
1942 case LFUN_CIRCUMFLEX:
1952 case LFUN_SPECIAL_CARON:
1955 case LFUN_HUNG_UMLAUT:
1961 if (keyseq.length == -1 && keyseq.getiso() != 0)
1962 c = keyseq.getiso();
1966 owner->getIntl()->getTrans()->
1967 deadkey(c, get_accent(action).accent,
1968 owner->view()->text);
1970 // Need to reset, in case the minibuffer calls these
1975 // copied verbatim from do_accent_char
1976 owner->view()->smallUpdate(1);
1978 owner->view()->text->sel_cursor =
1979 owner->view()->text->cursor;
1983 // --- toolbar ----------------------------------
1984 case LFUN_PUSH_TOOLBAR:
1986 int nth = strToInt(argument);
1987 if (lyxerr.debugging(Debug::TOOLBAR)) {
1988 lyxerr << "LFUN_PUSH_TOOLBAR: argument = `"
1989 << argument << "'\n"
1990 << "LFUN_PUSH_TOOLBAR: nth = `"
1991 << nth << "'" << endl;
1996 setErrorMessage(N_("Push-toolbar needs argument > 0"));
1998 owner->getToolbar()->push(nth);
2003 case LFUN_ADD_TO_TOOLBAR:
2005 if (lyxerr.debugging(Debug::TOOLBAR)) {
2006 lyxerr << "LFUN_ADD_TO_TOOLBAR:"
2007 "argument = `" << argument << '\'' << endl;
2009 string tmp(argument);
2010 //lyxerr <<string("Argument: ") + argument);
2011 //lyxerr <<string("Tmp : ") + tmp);
2014 setErrorMessage(N_("Usage: toolbar-add-to <LyX command>"));
2016 owner->getToolbar()->add(argument, false);
2017 owner->getToolbar()->set();
2022 // --- insert characters ----------------------------------------
2024 case LFUN_INSERT_INSET_LATEX:
2026 Inset * new_inset = new InsetLatex(argument);
2027 owner->buffer()->insertInset(new_inset);
2031 // --- Mathed stuff. If we are here, there is no locked inset yet.
2036 if (!greek_kb_flag) {
2038 setMessage(N_("Math greek mode on"));
2045 case LFUN_GREEK_TOGGLE:
2047 greek_kb_flag = greek_kb_flag ? 0 : 2;
2048 if (greek_kb_flag) {
2049 setMessage(N_("Math greek keyboard on"));
2051 setMessage(N_("Math greek keyboard off"));
2056 case LFUN_MATH_DELIM:
2057 case LFUN_INSERT_MATRIX:
2059 if (owner->view()->available()) {
2061 open_new_inset(new InsetFormula(false));
2063 the_locking_inset->LocalDispatch(action, argument.c_str());
2068 case LFUN_INSERT_MATH:
2070 math_insert_symbol(argument.c_str());
2074 case LFUN_MATH_DISPLAY:
2076 if (owner->view()->available())
2077 owner->view()->open_new_inset(new InsetFormula(true));
2081 case LFUN_MATH_MACRO:
2083 if (owner->view()->available()) {
2086 setErrorMessage(N_("Missing argument"));
2088 string s1 = token(s, ' ', 1);
2089 int na = s1.empty() ? 0: atoi(s1.c_str());
2091 open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2097 case LFUN_MATH_MODE: // Open or create a math inset
2100 if (owner->view()->available())
2101 owner->view()->open_new_inset(new InsetFormula);
2102 setMessage(N_("Math editor mode"));
2106 case LFUN_MATH_NUMBER:
2107 case LFUN_MATH_LIMITS:
2109 setErrorMessage(N_("This is only allowed in math mode!"));
2113 case LFUN_INSERT_CITATION:
2115 InsetCitation * new_inset = new InsetCitation();
2117 // The note, if any, must be after the key, delimited
2118 // by a | so both key and remark can have spaces.
2119 if (!argument.empty()) {
2120 string lsarg(argument);
2121 if (contains(lsarg, "|")) {
2122 new_inset->setContents(token(lsarg, '|', 0));
2123 new_inset->setOptions(token(lsarg, '|', 1));
2125 new_inset->setContents(lsarg);
2126 owner->view()->insertInset(new_inset);
2128 owner->view()->insertInset(new_inset);
2129 new_inset->Edit(0, 0);
2134 case LFUN_INSERT_BIBTEX:
2136 // ale970405+lasgoutt970425
2137 // The argument can be up to two tokens separated
2138 // by a space. The first one is the bibstyle.
2139 string lsarg(argument);
2140 string bibstyle = token(lsarg, ' ', 1);
2141 if (bibstyle.empty())
2143 InsetBibtex * new_inset
2144 = new InsetBibtex(token(lsarg, ' ', 0),
2148 owner->view()->insertInset(new_inset);
2149 if (lsarg.empty()) {
2150 new_inset->Edit(0, 0);
2155 // BibTeX data bases
2156 case LFUN_BIBDB_ADD:
2158 InsetBibtex * inset =
2159 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2161 inset->addDatabase(argument);
2166 case LFUN_BIBDB_DEL:
2168 InsetBibtex * inset =
2169 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2171 inset->delDatabase(argument);
2176 case LFUN_BIBTEX_STYLE:
2178 InsetBibtex * inset =
2179 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2181 inset->setOptions(argument);
2186 case LFUN_INDEX_INSERT:
2187 case LFUN_INDEX_INSERT_LAST:
2189 // Can't do that at the beginning of a paragraph.
2190 if (owner->view()->text->cursor.pos - 1 < 0)
2193 InsetIndex * new_inset = new InsetIndex();
2194 if (!argument.empty()) {
2195 string lsarg(argument);
2196 new_inset->setContents(lsarg);
2197 owner->view()->insertInset(new_inset);
2200 //get the current word for an argument
2201 LyXParagraph::size_type lastpos =
2202 owner->view()->text->cursor.pos - 1;
2203 // Get the current word. note that this must be done
2204 // before inserting the inset, or the inset will
2206 string curstring(owner->view()
2207 ->text->cursor.par->GetWord(lastpos));
2209 //make the new inset and write the current word into it
2210 InsetIndex * new_inset = new InsetIndex();
2212 new_inset->setContents(curstring);
2214 //don't edit it if the call was to INSERT_LAST
2215 if(action != LFUN_INDEX_INSERT_LAST) {
2216 new_inset->Edit(0, 0);
2218 //it looks blank on the screen unless
2219 //we do something. put it here.
2221 // move the cursor to the returned value of lastpos
2222 // but only for the auto-insert
2223 owner->view()->text->cursor.pos = lastpos;
2226 //put the new inset into the buffer.
2227 // there should be some way of knowing the user
2228 //cancelled & avoiding this, but i don't know how
2229 owner->view()->insertInset(new_inset);
2234 case LFUN_INDEX_PRINT:
2236 Inset * new_inset = new InsetPrintIndex(owner->buffer());
2237 owner->view()->insertInset(new_inset, "Standard", true);
2241 case LFUN_PARENTINSERT:
2243 lyxerr << "arg " << argument << endl;
2244 Inset * new_inset = new InsetParent(argument, owner->buffer());
2245 owner->view()->insertInset(new_inset, "Standard", true);
2249 case LFUN_CHILDINSERT:
2251 Inset * new_inset = new InsetInclude(argument,
2253 owner->view()->insertInset(new_inset, "Standard", true);
2254 new_inset->Edit(0, 0);
2258 case LFUN_CHILDOPEN:
2261 MakeAbsPath(argument,
2262 OnlyPath(owner->buffer()->fileName()));
2263 setMessage(N_("Opening child document ") +
2264 MakeDisplayPath(filename) + "...");
2265 owner->view()->savePosition();
2266 if (bufferlist.exists(filename))
2267 owner->view()->buffer(bufferlist.getBuffer(filename));
2269 owner->view()->buffer(bufferlist.loadLyXFile(filename));
2273 case LFUN_INSERT_NOTE:
2274 owner->view()->insertNote();
2277 case LFUN_INSERTFOOTNOTE:
2279 LyXParagraph::footnote_kind kind;
2280 if (argument == "footnote")
2281 { kind = LyXParagraph::FOOTNOTE; }
2282 else if (argument == "margin")
2283 { kind = LyXParagraph::MARGIN; }
2284 else if (argument == "figure")
2285 { kind = LyXParagraph::FIG; }
2286 else if (argument == "table")
2287 { kind = LyXParagraph::TAB; }
2288 else if (argument == "wide-fig")
2289 { kind = LyXParagraph::WIDE_FIG; }
2290 else if (argument == "wide-tab")
2291 { kind = LyXParagraph::WIDE_TAB; }
2292 else if (argument == "algorithm")
2293 { kind = LyXParagraph::ALGORITHM; }
2295 setErrorMessage(N_("Unknown kind of footnote"));
2298 owner->view()->text->InsertFootnoteEnvironment(kind);
2299 owner->view()->update(1);
2303 case LFUN_BUFFERBULLETSSELECT:
2307 case LFUN_TOGGLECURSORFOLLOW:
2308 cursor_follows_scrollbar = !cursor_follows_scrollbar;
2311 case LFUN_KMAP_OFF: // keymap off
2312 owner->getIntl()->KeyMapOn(false);
2315 case LFUN_KMAP_PRIM: // primary keymap
2316 owner->getIntl()->KeyMapPrim();
2319 case LFUN_KMAP_SEC: // secondary keymap
2320 owner->getIntl()->KeyMapSec();
2323 case LFUN_KMAP_TOGGLE: // toggle keymap
2324 owner->getIntl()->ToggleKeyMap();
2327 case LFUN_SELFINSERT:
2329 for (string::size_type i = 0; i < argument.length(); ++i) {
2330 owner->view()->text->InsertChar(argument[i]);
2331 // This needs to be in the loop, or else we
2332 // won't break lines correctly. (Asger)
2333 owner->view()->smallUpdate(1);
2336 owner->view()->text->sel_cursor =
2337 owner->view()->text->cursor;
2338 moveCursorUpdate(false);
2344 // argument contains ';'-terminated commands
2345 while (argument.find(';') != string::npos) {
2347 argument = split(argument, first, ';');
2353 case LFUN_INSERT_DATE: // jdblair: insert-date cmd
2361 now_time_t = time(NULL);
2362 now_tm = localtime(&now_time_t);
2363 (void)setlocale(LC_TIME, "");
2364 if (!argument.empty())
2366 else if (arg.empty())
2367 arg = lyxrc->insert_date_format;
2368 datetmp_len = (int) strftime(datetmp, 32, arg.c_str(), now_tm);
2369 for (int i = 0; i < datetmp_len; i++) {
2370 owner->view()->text->InsertChar(datetmp[i]);
2371 owner->view()->smallUpdate(1);
2374 owner->view()->text->sel_cursor = owner->view()->text->cursor;
2375 moveCursorUpdate(false);
2379 case LFUN_SAVEPREFERENCES:
2381 Path p(user_lyxdir);
2382 lyxrc->write("preferences");
2386 case LFUN_UNKNOWN_ACTION:
2388 if(!owner->buffer()) {
2390 setErrorMessage(N_("No document open"));
2394 if (owner->buffer()->isReadonly()) {
2396 setErrorMessage(N_("Document is read only"));
2400 if (!argument.empty()) {
2402 /* Automatically delete the currently selected
2403 * text and replace it with what is being
2404 * typed in now. Depends on lyxrc settings
2405 * "auto_region_delete", which defaults to
2408 if ( lyxrc->auto_region_delete ) {
2409 if (owner->view()->text->selection){
2410 owner->view()->text->CutSelection(false);
2411 owner->view()->update(-1);
2415 owner->view()->beforeChange();
2416 for (string::size_type i = 0;
2417 i < argument.length(); ++i) {
2418 if (greek_kb_flag) {
2419 if (!math_insert_greek(argument[i]))
2420 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2422 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2425 owner->view()->smallUpdate(1);
2428 owner->view()->text->sel_cursor =
2429 owner->view()->text->cursor;
2430 moveCursorUpdate(false);
2433 // why is an "Unknown action" with empty
2434 // argument even dispatched in the first
2435 // place? I`ll probably change that. (Lgb)
2437 setErrorMessage(N_("Unknown action"));
2441 lyxerr << "A truly unknown func!" << endl;
2447 string res = getMessage();
2450 if (!commandshortcut.empty()) {
2451 string newbuf = owner->getMiniBuffer()->GetText();
2452 if (newbuf != commandshortcut) {
2453 owner->getMiniBuffer()->Set(newbuf
2459 owner->getMiniBuffer()->Set(string(_(res.c_str()))
2460 + " " + commandshortcut);
2467 void LyXFunc::setupLocalKeymap()
2469 keyseq.stdmap = keyseq.curmap = toplevel_keymap;
2470 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap;
2474 void LyXFunc::MenuNew(bool fromTemplate)
2476 string fname, initpath = lyxrc->document_path;
2479 if (owner->view()->available()) {
2480 string trypath = owner->buffer()->filepath;
2481 // If directory is writeable, use this as default.
2482 if (IsDirWriteable(trypath) == 1)
2487 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2488 fileDlg.SetButton(1, _("Templates"), lyxrc->template_path);
2489 fname = fileDlg.Select(_("Enter Filename for new document"),
2490 initpath, "*.lyx", _("newfile"));
2493 if (fname.empty()) {
2494 owner->getMiniBuffer()->Set(_("Canceled."));
2495 lyxerr.debug() << "New Document Cancelled." << endl;
2499 // get absolute path of file and make sure the filename ends
2501 string s = MakeAbsPath(fname);
2502 if (!IsLyXFilename(s))
2505 // Check if the document already is open
2506 if (bufferlist.exists(s)){
2507 switch(AskConfirmation(_("Document is already open:"),
2508 MakeDisplayPath(s, 50),
2509 _("Do you want to close that document now?\n"
2510 "('No' will just switch to the open version)")))
2512 case 1: // Yes: close the document
2513 if (!bufferlist.close(bufferlist.getBuffer(s)))
2514 // If close is canceled, we cancel here too.
2517 case 2: // No: switch to the open document
2518 owner->view()->buffer(bufferlist.getBuffer(s));
2520 case 3: // Cancel: Do nothing
2521 owner->getMiniBuffer()->Set(_("Canceled."));
2526 // Check whether the file already exists
2527 if (IsLyXFilename(s)) {
2529 if (fi.readable() &&
2530 AskQuestion(_("File already exists:"),
2531 MakeDisplayPath(s, 50),
2532 _("Do you want to open the document?"))) {
2534 owner->getMiniBuffer()->Set(_("Opening document"),
2535 MakeDisplayPath(s), "...");
2537 owner->view()->buffer(
2538 bufferlist.loadLyXFile(s));
2539 owner->getMiniBuffer()->Set(_("Document"),
2546 // The template stuff
2550 fname = fileDlg.Select(_("Choose template"),
2551 lyxrc->template_path,
2557 // find a free buffer
2558 lyxerr.debug() << "Find a free buffer." << endl;
2559 owner->view()->buffer(bufferlist.newFile(s, templname));
2563 void LyXFunc::MenuOpen()
2565 string initpath = lyxrc->document_path;
2568 if (owner->view()->available()) {
2569 string trypath = owner->buffer()->filepath;
2570 // If directory is writeable, use this as default.
2571 if (IsDirWriteable(trypath) == 1)
2577 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2578 fileDlg.SetButton(1, _("Examples"),
2579 AddPath(system_lyxdir, "examples"));
2580 string filename = fileDlg.Select(_("Select Document to Open"),
2584 // check selected filename
2585 if (filename.empty()) {
2586 owner->getMiniBuffer()->Set(_("Canceled."));
2590 // get absolute path of file and make sure the filename ends
2592 filename = MakeAbsPath(filename);
2593 if (!IsLyXFilename(filename))
2597 owner->getMiniBuffer()->Set(_("Opening document"),
2598 MakeDisplayPath(filename), "...");
2599 Buffer * openbuf = bufferlist.loadLyXFile(filename);
2601 owner->view()->buffer(openbuf);
2602 owner->getMiniBuffer()->Set(_("Document"),
2603 MakeDisplayPath(filename),
2606 owner->getMiniBuffer()->Set(_("Could not open document"),
2607 MakeDisplayPath(filename));
2612 void LyXFunc::doImportASCII(bool linorpar)
2614 string initpath = lyxrc->document_path;
2617 if (owner->view()->available()) {
2618 string trypath = owner->buffer()->filepath;
2619 // If directory is writeable, use this as default.
2620 if (IsDirWriteable(trypath) == 1)
2626 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2627 fileDlg.SetButton(1, _("Examples"),
2628 AddPath(system_lyxdir, "examples"));
2629 string filename = fileDlg.Select(_("Select ASCII file to Import"),
2633 // check selected filename
2634 if (filename.empty()) {
2635 owner->getMiniBuffer()->Set(_("Canceled."));
2639 // get absolute path of file
2640 filename = MakeAbsPath(filename);
2642 string s = ChangeExtension(filename, ".lyx", false);
2644 // Check if the document already is open
2645 if (bufferlist.exists(s)) {
2646 switch(AskConfirmation(_("Document is already open:"),
2647 MakeDisplayPath(s, 50),
2648 _("Do you want to close that document now?\n"
2649 "('No' will just switch to the open version)")))
2651 case 1: // Yes: close the document
2652 if (!bufferlist.close(bufferlist.getBuffer(s)))
2653 // If close is canceled, we cancel here too.
2656 case 2: // No: switch to the open document
2657 owner->view()->buffer(bufferlist.getBuffer(s));
2659 case 3: // Cancel: Do nothing
2660 owner->getMiniBuffer()->Set(_("Canceled."));
2665 // Check if a LyX document by the same root exists in filesystem
2666 FileInfo f(s, true);
2667 if (f.exist() && !AskQuestion(_("A document by the name"),
2669 _("already exists. Overwrite?"))) {
2670 owner->getMiniBuffer()->Set(_("Canceled."));
2674 owner->view()->buffer(bufferlist.newFile(s, string()));
2675 owner->getMiniBuffer()->Set(_("Importing ASCII file"),
2676 MakeDisplayPath(filename), "...");
2677 // Insert ASCII file
2678 InsertAsciiFile(filename, linorpar);
2679 owner->getMiniBuffer()->Set(_("ASCII file "),
2680 MakeDisplayPath(filename),
2685 void LyXFunc::doImportLaTeX(bool isnoweb)
2687 string initpath = lyxrc->document_path;
2690 if (owner->view()->available()) {
2691 string trypath = owner->buffer()->filepath;
2692 // If directory is writeable, use this as default.
2693 if (IsDirWriteable(trypath) == 1)
2699 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2700 fileDlg.SetButton(1, _("Examples"),
2701 AddPath(system_lyxdir, "examples"));
2704 filename = fileDlg.Select(_("Select Noweb file to Import"),
2707 filename = fileDlg.Select(_("Select LaTeX file to Import"),
2713 // check selected filename
2714 if (filename.empty()) {
2715 owner->getMiniBuffer()->Set(_("Canceled."));
2719 // get absolute path of file
2720 filename = MakeAbsPath(filename);
2722 // Check if the document already is open
2723 string LyXfilename = ChangeExtension(filename, ".lyx", false);
2724 if (bufferlist.exists(LyXfilename)){
2725 switch(AskConfirmation(_("Document is already open:"),
2726 MakeDisplayPath(LyXfilename, 50),
2727 _("Do you want to close that document now?\n"
2728 "('No' will just switch to the open version)")))
2730 case 1: // Yes: close the document
2731 if (!bufferlist.close(bufferlist.getBuffer(LyXfilename)))
2732 // If close is canceled, we cancel here too.
2735 case 2: // No: switch to the open document
2736 owner->view()->buffer(
2737 bufferlist.getBuffer(LyXfilename));
2739 case 3: // Cancel: Do nothing
2740 owner->getMiniBuffer()->Set(_("Canceled."));
2745 // Check if a LyX document by the same root exists in filesystem
2746 FileInfo f(LyXfilename, true);
2747 if (f.exist() && !AskQuestion(_("A document by the name"),
2748 MakeDisplayPath(LyXfilename),
2749 _("already exists. Overwrite?"))) {
2750 owner->getMiniBuffer()->Set(_("Canceled."));
2757 owner->getMiniBuffer()->Set(_("Importing LaTeX file"),
2758 MakeDisplayPath(filename), "...");
2759 ImportLaTeX myImport(filename);
2760 openbuf = myImport.run();
2762 owner->getMiniBuffer()->Set(_("Importing Noweb file"),
2763 MakeDisplayPath(filename), "...");
2764 ImportNoweb myImport(filename);
2765 openbuf = myImport.run();
2768 owner->view()->buffer(openbuf);
2769 owner->getMiniBuffer()->Set(isnoweb ?
2770 _("Noweb file ") : _("LateX file "),
2771 MakeDisplayPath(filename),
2774 owner->getMiniBuffer()->Set(isnoweb ?
2775 _("Could not import Noweb file") :
2776 _("Could not import LaTeX file"),
2777 MakeDisplayPath(filename));
2782 void LyXFunc::MenuInsertLyXFile(string const & filen)
2784 string filename = filen;
2786 if (filename.empty()) {
2787 // Launch a file browser
2788 string initpath = lyxrc->document_path;
2791 if (owner->view()->available()) {
2792 string trypath = owner->buffer()->filepath;
2793 // If directory is writeable, use this as default.
2794 if (IsDirWriteable(trypath) == 1)
2800 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2801 fileDlg.SetButton(1, _("Examples"),
2802 AddPath(system_lyxdir, "examples"));
2803 filename = fileDlg.Select(_("Select Document to Insert"),
2807 // check selected filename
2808 if (filename.empty()) {
2809 owner->getMiniBuffer()->Set(_("Canceled."));
2814 // get absolute path of file and make sure the filename ends
2816 filename = MakeAbsPath(filename);
2817 if (!IsLyXFilename(filename))
2821 owner->getMiniBuffer()->Set(_("Inserting document"),
2822 MakeDisplayPath(filename), "...");
2823 bool res = owner->view()->insertLyXFile(filename);
2825 owner->getMiniBuffer()->Set(_("Document"),
2826 MakeDisplayPath(filename),
2829 owner->getMiniBuffer()->Set(_("Could not insert document"),
2830 MakeDisplayPath(filename));
2835 void LyXFunc::reloadBuffer()
2837 string fn = owner->buffer()->fileName();
2838 if (bufferlist.close(owner->buffer()))
2839 owner->view()->buffer(bufferlist.loadLyXFile(fn));
2843 void LyXFunc::CloseBuffer()
2845 if (bufferlist.close(owner->buffer()) && !quitting) {
2846 if (bufferlist.empty()) {
2847 // need this otherwise SEGV may occur while trying to
2848 // set variables that don't exist
2849 // since there's no current buffer
2850 CloseAllBufferRelatedPopups();
2853 owner->view()->buffer(bufferlist.first());
2859 Inset * LyXFunc::getInsetByCode(Inset::Code code)
2863 LyXCursor cursor = owner->view()->text->cursor;
2864 LyXParagraph::size_type pos = cursor.pos;
2865 LyXParagraph * par = cursor.par;
2867 while (par && !found) {
2868 while ((inset = par->ReturnNextInsetPointer(pos))){
2869 if (inset->LyxCode() == code) {
2877 return found ? inset : 0;
2881 // Each "owner" should have it's own message method. lyxview and
2882 // the minibuffer would use the minibuffer, but lyxserver would
2883 // send an ERROR signal to its client. Alejandro 970603
2884 // This func is bit problematic when it comes to NLS, to make the
2885 // lyx servers client be language indepenent we must not translate
2886 // strings sent to this func.
2887 void LyXFunc::setErrorMessage(string const & m) const
2889 dispatch_buffer = m;
2894 void LyXFunc::setMessage(string const & m)
2896 dispatch_buffer = m;