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/LAssert.h"
56 #include "support/syscall.h"
57 #include "support/lstrings.h"
58 #include "support/path.h"
59 #include "lyxscreen.h"
64 #include "trans_mgr.h"
65 #include "ImportLaTeX.h"
66 #include "ImportNoweb.h"
69 extern bool cursor_follows_scrollbar;
71 extern void InsertAsciiFile(string const &, bool);
72 extern void math_insert_symbol(char const *);
73 extern Bool math_insert_greek(char const); // why "Bool"?
74 extern BufferList bufferlist;
75 extern LyXServer * lyxserver;
76 extern short greek_kb_flag;
77 extern FD_form_toc * fd_form_toc;
78 extern bool selection_possible;
80 extern kb_keymap * toplevel_keymap;
82 extern void BeforeChange();
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 MenuRunDvips(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 CopyCB();
102 extern void CopyEnvironmentCB();
103 extern void PasteEnvironmentCB();
104 extern void GotoNote();
105 extern void NoteCB();
106 extern void OpenStuff();
107 extern void HyphenationPoint();
109 extern void EndOfSentenceDot();
110 extern void MenuSeparator();
112 extern void MenuUndo();
113 extern void MenuRedo();
114 extern void SmallUpdate(signed char);
115 extern void SetUpdateTimer(float timer = 0.3);
116 extern void FreeUpdateTimer();
117 extern bool MenuPreview(Buffer *);
118 extern bool MenuPreviewPS(Buffer *);
119 extern void MenuInsertLabel(char const *);
120 extern void MenuInsertRef();
121 extern void MenuLayoutCharacter();
122 extern void MenuLayoutParagraph();
123 extern void MenuLayoutDocument();
124 extern void MenuLayoutPaper();
125 extern void MenuLayoutTable(int flag);
126 extern void MenuLayoutQuotes();
127 extern void MenuLayoutPreamble();
128 extern void MenuLayoutSave();
129 extern void bulletForm();
131 extern Buffer * NewLyxFile(string const &);
132 extern void LoadLyXFile(string const &);
133 extern void Reconfigure();
135 extern int current_layout;
136 extern int getISOCodeFromLaTeX(char *);
138 extern int UnlockInset(UpdatableInset *);
140 extern void ShowLatexLog();
142 extern void UpdateInset(Inset * inset, bool mark_dirty = true);
144 /* === globals =========================================================== */
146 bool LyXFunc::show_sc = true;
149 LyXFunc::LyXFunc(LyXView * o)
153 lyx_dead_action = LFUN_NOACTION;
154 lyx_calling_dead_action = LFUN_NOACTION;
159 // I changed this func slightly. I commented out the ...FinishUndo(),
160 // this means that all places that used to have a moveCursorUpdate, now
161 // have a ...FinishUndo() as the preceeding statement. I have also added
162 // a moveCursorUpdate to some of the functions that updated the cursor, but
163 // that did not show its new position.
165 void LyXFunc::moveCursorUpdate(bool selecting)
167 if (selecting || owner->view()->text->mark_set) {
168 owner->view()->text->SetSelection();
169 owner->view()->getScreen()->ToggleToggle();
170 owner->view()->update(0);
172 owner->view()->update(-2); // this IS necessary
176 owner->view()->getScreen()->ShowCursor();
178 /* ---> Everytime the cursor is moved, show the current font state. */
179 // should this too me moved out of this func?
180 //owner->getMiniBuffer()->Set(CurrentState());
184 int LyXFunc::processKeyEvent(XEvent * ev)
189 XKeyEvent * keyevent = &ev->xkey;
190 KeySym keysym_return;
192 int num_bytes = LyXLookupString(ev, s_r, 10, &keysym_return);
194 if (lyxerr.debugging(Debug::KEY)) {
195 lyxerr << "KeySym is "
196 << XKeysymToString(keysym_return)
198 << keysym_return << "]"
199 << " and num_bytes is "
201 << " the string returned is \""
202 << s_r << '\"' << endl;
204 // Do nothing if we have nothing (JMarc)
205 if (num_bytes == 0 && keysym_return == NoSymbol) {
206 lyxerr[Debug::KEY] << "Empty kbd action (probably composing)"
211 // this function should be used always [asierra060396]
212 if (owner->view()->available() &&
213 owner->buffer()->the_locking_inset &&
214 keysym_return == XK_Escape) {
215 UnlockInset(owner->buffer()->the_locking_inset);
216 owner->view()->text->CursorRight();
220 // Can we be sure that this will work for all X-Windows
221 // implementations? (Lgb)
222 // This code snippet makes lyx ignore some keys. Perhaps
223 // all of them should be explictly mentioned?
224 if((keysym_return >= XK_Shift_L && keysym_return <= XK_Hyper_R)
225 || keysym_return == XK_Mode_switch || keysym_return == 0x0)
228 // Do a one-deep top-level lookup for
229 // cancel and meta-fake keys. RVDK_PATCH_5
230 cancel_meta_seq.reset();
232 int action = cancel_meta_seq.addkey(keysym_return, keyevent->state
233 &(ShiftMask|ControlMask
236 // When not cancel or meta-fake, do the normal lookup.
237 // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
238 // Mostly, meta_fake_bit = 0. RVDK_PATCH_5.
239 if ( (action != LFUN_CANCEL) && (action != LFUN_META_FAKE) ) {
241 // remove Caps Lock and Mod2 as a modifiers
242 action = keyseq.addkey(keysym_return,
243 (keyevent->state | meta_fake_bit)
244 &(ShiftMask|ControlMask
247 // Dont remove this unless you know what you are doing.
250 if (action == 0) action = LFUN_PREFIX;
252 if (lyxerr.debugging(Debug::KEY)) {
258 << num_bytes << "]" << endl;
261 // already here we know if it any point in going further
262 // why not return already here if action == -1 and
263 // num_bytes == 0? (Lgb)
265 if(keyseq.length > 1 || keyseq.length < -1){
268 owner->getMiniBuffer()->Set(buf);
272 if (keyseq.length < -1) { // unknown key sequence...
276 owner->getMiniBuffer()->Set(_("Unknown sequence:"), buf);
280 char isochar = keyseq.getiso();
281 if (!(keyevent->state&ControlMask) &&
282 !(keyevent->state&Mod1Mask) &&
283 (isochar && keysym_return < 0xF000)) {
286 if (argument.empty()) {
287 lyxerr.debug() << "Empty argument!" << endl;
288 // This can`t possibly be of any use
289 // so we`ll skip the dispatch.
293 if (action == LFUN_SELFINSERT) {
297 bool tmp_sc = show_sc;
299 Dispatch(action, argument.c_str());
306 LyXFunc::func_status LyXFunc::getStatus(int ac) const
309 func_status flag = LyXFunc::OK;
311 Buffer * buf = owner->buffer();
313 if (lyxaction.isPseudoAction(ac))
314 action = lyxaction.retrieveActionArg(ac, argument);
316 action = static_cast<kb_action>(ac);
318 if (action == LFUN_UNKNOWN_ACTION) {
319 setErrorMessage(N_("Unknown action"));
320 return LyXFunc::Unknown;
323 // Check whether we need a buffer
324 if (!lyxaction.funcHasFlag(action, LyXAction::NoBuffer)) {
325 // Yes we need a buffer, do we have one?
328 // Can we use a readonly buffer?
329 if (buf->isReadonly() &&
330 !lyxaction.funcHasFlag(action,
331 LyXAction::ReadOnly)) {
333 setErrorMessage(N_("Document is read-only"));
334 flag = func_status(flag | LyXFunc::Disabled);
338 setErrorMessage(N_("Command not allowed with"
339 "out any document open"));
340 flag = func_status(flag | LyXFunc::Disabled);
344 if (flag & LyXFunc::Disabled)
347 static bool noLaTeX = lyxrc->latex_command == "none";
348 bool disable = false;
351 disable = noLaTeX || lyxrc->view_dvi_command == "none";
354 disable = noLaTeX || lyxrc->view_ps_command == "none";
361 disable = noLaTeX || lyxrc->print_command == "none";
364 disable = noLaTeX || lyxrc->fax_command == "none";
367 if (argument == "latex")
368 disable = lyxrc->relyx_command == "none";
371 if (argument == "dvi" || argument == "postscript")
373 if (argument == "html")
374 disable = lyxrc->html_command == "none";
377 disable = buf->undostack.empty();
380 disable = buf->redostack.empty();
382 case LFUN_SPELLCHECK:
383 disable = lyxrc->isp_command == "none";
386 disable = lyxrc->chktex_command == "none";
388 case LFUN_LAYOUT_TABLE:
389 disable = ! owner->view()->text->cursor.par->table;
395 flag |= LyXFunc::Disabled;
398 func_status box = LyXFunc::ToggleOff;
399 LyXFont font = owner->view()->text->real_current_font;
402 if (font.emph() == LyXFont::ON)
403 box = LyXFunc::ToggleOn;
406 if (font.noun() == LyXFont::ON)
407 box = LyXFunc::ToggleOn;
410 if (font.series() == LyXFont::BOLD_SERIES)
411 box = LyXFunc::ToggleOn;
414 if (font.latex() == LyXFont::ON)
415 box = LyXFunc::ToggleOn;
428 string LyXFunc::Dispatch(string const & s)
430 // Split command string into command and argument
431 string cmd, line = frontStrip(s);
432 string arg = strip(frontStrip(split(line, cmd, ' ')));
434 return Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
438 string LyXFunc::Dispatch(int ac,
439 char const * do_not_use_this_arg)
444 FL_OBJECT * ob = 0; // This will disapear soon
446 // we have not done anything wrong yet.
448 dispatch_buffer.clear();
450 // if action is a pseudo-action, we need the real action
451 if (lyxaction.isPseudoAction(ac)) {
453 action = static_cast<kb_action>
454 (lyxaction.retrieveActionArg(ac, tmparg));
458 action = static_cast<kb_action>(ac);
459 if (do_not_use_this_arg)
460 argument = do_not_use_this_arg; // except here
463 selection_possible = false;
465 if (owner->view()->available()
466 && owner->view()->getScreen())
467 owner->view()->getScreen()->HideCursor();
469 // We cannot use this function here
470 if (getStatus(action) & Disabled)
471 goto exit_with_message;
473 commandshortcut.clear();
475 if (lyxrc->display_shortcuts && show_sc) {
476 if (action != LFUN_SELFINSERT) {
477 // Put name of command and list of shortcuts
478 // for it in minibuffer
479 string comname = lyxaction.getActionName(action);
481 int pseudoaction = action;
482 bool argsadded = false;
484 if (!argument.empty()) {
485 // If we have the command with argument,
488 lyxaction.searchActionArg(action,
491 if (pseudoaction == -1) {
492 pseudoaction = action;
494 comname += " " + argument;
499 string shortcuts = toplevel_keymap->findbinding(pseudoaction);
501 if (!shortcuts.empty()) {
502 comname += ": " + shortcuts;
503 } else if (!argsadded) {
504 comname += " " + argument;
507 if (!comname.empty()) {
508 comname = strip(comname);
509 commandshortcut = "(" + comname + ')';
510 owner->getMiniBuffer()->Set(commandshortcut);
511 // Here we could even add a small pause,
512 // to annoy the user and make him learn
514 // No! That will just annoy, not teach
515 // anything. The user will read the messages
516 // if they are interested. (Asger)
521 // If in math mode pass the control to
522 // the math inset [asierra060396]
523 if (owner->view()->available() &&
524 owner->buffer()->the_locking_inset) {
526 || (action == LFUN_UNKNOWN_ACTION
527 && keyseq.length >= -1)) {
528 if (action == LFUN_UNKNOWN_ACTION
529 && argument.empty()) {
530 argument = keyseq.getiso();
532 // Undo/Redo pre 0.13 is a bit tricky for insets.
533 if (action == LFUN_UNDO) {
535 UpdatableInset * inset =
536 owner->buffer()->the_locking_inset;
537 inset->GetCursorPos(slx, sly);
540 inset = static_cast<UpdatableInset*>(owner->view()->text->cursor.par->GetInset(owner->view()->text->cursor.pos));
542 inset->Edit(slx, sly);
545 if (action == LFUN_REDO) {
547 UpdatableInset * inset = owner->buffer()->the_locking_inset;
548 inset->GetCursorPos(slx, sly);
551 inset = static_cast<UpdatableInset*>(owner->view()->text->cursor.par->GetInset(owner->view()->text->cursor.pos));
553 inset->Edit(slx, sly);
556 if (owner->buffer()->the_locking_inset->LocalDispatch(action, argument.c_str()))
559 setMessage(N_("Text mode"));
560 if (action == LFUN_RIGHT || action == -1)
561 owner->view()->text->CursorRight();
562 if (action == LFUN_LEFT || action == LFUN_RIGHT)
569 // --- Misc -------------------------------------------
570 case LFUN_WORDFINDFORWARD :
571 case LFUN_WORDFINDBACKWARD : {
572 static string last_search;
573 string searched_string;
575 if (!argument.empty()) {
576 last_search = argument;
577 searched_string = argument;
579 searched_string = last_search;
582 LyXText * ltCur = owner->view()->text ;
584 if (!searched_string.empty() &&
585 ((action == LFUN_WORDFINDBACKWARD) ?
586 ltCur->SearchBackward(searched_string.c_str()) :
587 ltCur->SearchForward(searched_string.c_str()))) {
589 // ??? What is that ???
590 owner->view()->update(-2);
593 // clear the selection (if there is any)
594 owner->view()->getScreen()->ToggleSelection();
595 owner->view()->text->ClearSelection();
597 // Move cursor so that successive C-s 's will not stand in place.
598 if( action == LFUN_WORDFINDFORWARD )
599 owner->view()->text->CursorRightOneWord();
600 owner->view()->text->FinishUndo();
601 moveCursorUpdate(false);
604 // set the new selection
605 // SetSelectionOverLenChars(owner->view()->currentBuffer()->text, iLenSelected);
606 owner->view()->getScreen()->ToggleSelection(false);
610 // REMOVED : if (owner->view()->getWorkArea()->focus)
611 owner->view()->getScreen()->ShowCursor();
617 if (owner->view()->available()
618 && owner->view()->getScreen()) {
619 owner->view()->update(-2);
622 keyseq.print(buf, true);
623 owner->getMiniBuffer()->Set(buf, string(), string(), 1);
627 // --- Misc -------------------------------------------
628 case LFUN_EXEC_COMMAND:
629 owner->getMiniBuffer()->ExecCommand();
632 case LFUN_CANCEL: // RVDK_PATCH_5
635 if(owner->view()->available())
636 // cancel any selection
637 Dispatch(LFUN_MARK_OFF, 0);
638 setMessage(N_("Cancel"));
641 case LFUN_META_FAKE: // RVDK_PATCH_5
643 meta_fake_bit = Mod1Mask;
645 keyseq.print(buf, true);
646 string res = string("M-") + buf;
647 setMessage(buf); // RVDK_PATCH_5
651 case LFUN_READ_ONLY_TOGGLE:
652 if (owner->buffer()->lyxvc.inUse()) {
653 owner->buffer()->lyxvc.toggleReadOnly();
655 owner->buffer()->setReadonly(
656 !owner->buffer()->isReadonly());
660 case LFUN_CENTER: // this is center and redraw.
662 if (owner->view()->text->cursor.y >
663 owner->view()->getWorkArea()->h / 2) {
664 owner->view()->getScreen()->
665 Draw(owner->view()->text->cursor.y -
666 owner->view()->getWorkArea()->h / 2);
668 owner->view()->getScreen()->
671 owner->view()->update(0);
672 owner->view()->redraw();
676 if (owner->view()->available()) {
677 owner->view()->text->toggleAppendix();
678 owner->view()->update(1);
682 // --- Menus -----------------------------------------------
687 case LFUN_MENUNEWTMPLT:
695 case LFUN_CLOSEBUFFER:
700 MenuWrite(owner->buffer());
703 case LFUN_MENUWRITEAS:
704 MenuWriteAs(owner->buffer());
707 case LFUN_MENURELOAD:
712 MenuPreview(owner->buffer());
716 MenuPreviewPS(owner->buffer());
720 MenuRunLaTeX(owner->buffer());
724 MenuBuildProg(owner->buffer());
728 MenuRunChktex(owner->buffer());
732 MenuRunDvips(owner->buffer(), false);
736 MenuPrint(owner->buffer());
740 MenuFax(owner->buffer());
744 MenuExport(owner->buffer(), argument);
749 //needs argument as string
750 string imtyp = argument;
753 if (imtyp == "latex") {
754 doImportLaTeX(false);
757 else if (imtyp == "ascii") {
758 doImportASCII(false);
759 } else if (imtyp == "asciiparagraph") {
762 } else if (imtyp == "noweb") {
765 setErrorMessage(string(N_("Unknown import type: "))
777 if (fd_form_toc->form_toc->visible) {
778 fl_raise_form(fd_form_toc->form_toc);
780 static int ow = -1, oh;
781 fl_show_form(fd_form_toc->form_toc,
783 FL_FREE_SIZE, FL_FULLBORDER,
784 _("Table of Contents"));
786 ow = fd_form_toc->form_toc->w;
787 oh = fd_form_toc->form_toc->h;
789 fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
793 case LFUN_TOC_INSERT:
795 Inset * new_inset = new InsetTOC(owner->buffer());
796 owner->buffer()->insertInset(new_inset, "Standard", true);
800 case LFUN_LOF_INSERT:
802 Inset * new_inset = new InsetLOF(owner->buffer());
803 owner->buffer()->insertInset(new_inset, "Standard", true);
807 case LFUN_LOA_INSERT:
809 Inset * new_inset = new InsetLOA(owner->buffer());
810 owner->buffer()->insertInset(new_inset, "Standard", true);
814 case LFUN_LOT_INSERT:
816 Inset * new_inset = new InsetLOT(owner->buffer());
817 owner->buffer()->insertInset(new_inset, "Standard", true);
841 case LFUN_MENUSEARCH:
849 case LFUN_PASTESELECTION:
852 if (argument == "paragraph") asPara = true;
853 MenuPasteSelection(asPara);
865 case LFUN_LAYOUT_COPY:
869 case LFUN_LAYOUT_PASTE:
870 PasteEnvironmentCB();
874 owner->view()->gotoError();
877 case LFUN_REMOVEERRORS:
878 if (owner->buffer()->removeAutoInsets()) {
879 owner->view()->redraw();
880 owner->view()->fitCursor();
881 owner->view()->updateScrollbar();
893 case LFUN_HYPHENATION:
901 case LFUN_END_OF_SENTENCE:
905 case LFUN_MENU_SEPARATOR:
921 case LFUN_DEPTH_PLUS:
937 case LFUN_RECONFIGURE:
942 if (owner->view()->available()
943 && !owner->view()->text->selection
944 && owner->view()->text->cursor.par->footnoteflag
945 != LyXParagraph::NO_FOOTNOTE)
946 { // only melt footnotes with FOOTMELT, not margins etc
947 if(owner->view()->text->cursor.par->footnotekind == LyXParagraph::FOOTNOTE)
954 case LFUN_MARGINMELT:
955 if (owner->view()->available()
956 && !owner->view()->text->selection
957 && owner->view()->text->cursor.par->footnoteflag
958 != LyXParagraph::NO_FOOTNOTE) {
960 if(owner->view()->text->cursor.par->footnotekind == LyXParagraph::MARGIN)
967 // --- version control -------------------------------
968 case LFUN_VC_REGISTER:
970 if (!owner->buffer()->lyxvc.inUse())
971 owner->buffer()->lyxvc.registrer();
975 case LFUN_VC_CHECKIN:
977 if (owner->buffer()->lyxvc.inUse()
978 && !owner->buffer()->isReadonly())
979 owner->buffer()->lyxvc.checkIn();
983 case LFUN_VC_CHECKOUT:
985 if (owner->buffer()->lyxvc.inUse()
986 && owner->buffer()->isReadonly())
987 owner->buffer()->lyxvc.checkOut();
993 owner->buffer()->lyxvc.revert();
999 owner->buffer()->lyxvc.undoLast();
1003 case LFUN_VC_HISTORY:
1005 owner->buffer()->lyxvc.showLog();
1009 // --- buffers ----------------------------------------
1010 case LFUN_PREVBUFFER:
1011 #ifdef WITH_WARNINGS
1012 #warning fix this please
1014 // it is the LyXView or the BufferView that should
1015 // remember the previous buffer, not bufferlist.
1016 // if (owner->view()->available()){
1018 // owner->buffer()->update(-2);
1020 // owner->view()->setBuffer(bufferlist.prev());
1023 // resizeCurrentBufferPseudoExpose();
1026 case LFUN_FILE_INSERT:
1028 MenuInsertLyXFile(argument);
1032 case LFUN_FILE_INSERT_ASCII:
1034 bool asPara = (argument == "paragraph");
1035 InsertAsciiFile(string(), asPara);
1041 // servercmd: argument must be <file>:<template>
1042 Buffer * tmpbuf = NewLyxFile(argument);
1044 owner->view()->buffer(tmpbuf);
1048 case LFUN_FILE_OPEN:
1049 owner->view()->buffer(bufferlist.loadLyXFile(argument));
1052 case LFUN_LATEX_LOG:
1058 lyxerr.debug() << "LFUN_LAYOUTNO: (arg) " << argument << endl;
1059 int sel = strToInt(argument);
1060 lyxerr.debug() << "LFUN_LAYOUTNO: (sel) "<< sel << endl;
1062 // Should this give a setMessage instead?
1064 return string(); // illegal argument
1066 sel--; // sel 1..., but layout 0...
1068 // Pretend we got the name instead.
1069 Dispatch(int(LFUN_LAYOUT),
1070 textclasslist.NameOfLayout(owner->view()->
1079 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1080 << argument << endl;
1082 // Derive layout number from given argument (string)
1083 // and current buffer's textclass (number). */
1085 textclasslist.NumberOfLayout(owner->
1091 // see if we found the layout number:
1092 if (layoutno == -1) {
1093 setErrorMessage(string(N_("Layout ")) + argument +
1098 if (current_layout != layoutno) {
1099 owner->view()->getScreen()->HideCursor();
1100 current_layout = layoutno;
1101 owner->view()->update(-2);
1102 owner->view()->text->
1103 SetLayout(layoutno);
1104 owner->getToolbar()->combox->
1105 select(owner->view()->
1108 owner->view()->update(1);
1113 case LFUN_LAYOUT_DOCUMENT:
1114 MenuLayoutDocument();
1117 case LFUN_LAYOUT_PARAGRAPH:
1118 MenuLayoutParagraph();
1121 case LFUN_LAYOUT_CHARACTER:
1122 MenuLayoutCharacter();
1125 case LFUN_LAYOUT_TABLE:
1128 if (argument == "true") flag = 1;
1129 MenuLayoutTable(flag);
1133 case LFUN_LAYOUT_PAPER:
1137 case LFUN_LAYOUT_QUOTES:
1141 case LFUN_LAYOUT_PREAMBLE:
1142 MenuLayoutPreamble();
1145 case LFUN_LAYOUT_SAVE_DEFAULT:
1149 case LFUN_DROP_LAYOUTS_CHOICE:
1150 owner->getToolbar()->combox->Show();
1181 case LFUN_UNDERLINE:
1185 case LFUN_FONT_SIZE:
1186 FontSizeCB(argument);
1189 case LFUN_FONT_STATE:
1190 setMessage(CurrentState());
1193 case LFUN_UPCASE_WORD:
1194 owner->view()->update(-2);
1196 owner->view()->text->ChangeWordCase(LyXText::text_uppercase);
1197 owner->view()->update(1);
1201 case LFUN_LOWCASE_WORD:
1202 owner->view()->update(-2);
1204 owner->view()->text->ChangeWordCase(LyXText::text_lowercase);
1205 owner->view()->update(1);
1209 case LFUN_CAPITALIZE_WORD:
1210 owner->view()->update(-2);
1212 owner->view()->text->ChangeWordCase(LyXText::text_capitalization);
1213 owner->view()->update(1);
1217 case LFUN_INSERT_LABEL:
1218 MenuInsertLabel(argument.c_str());
1221 case LFUN_INSERT_REF:
1225 case LFUN_REFTOGGLE:
1228 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1230 if (inset->getFlag() == InsetRef::REF)
1231 inset->setFlag(InsetRef::PAGE_REF);
1233 inset->setFlag(InsetRef::REF);
1236 setErrorMessage(N_("No cross-reference to toggle"));
1243 owner->view()->restorePosition();
1249 string label(argument);
1250 if (label.empty()) {
1252 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1254 label = inset->getContents();
1257 if (!label.empty()) {
1258 owner->view()->savePosition();
1259 owner->buffer()->gotoLabel(label.c_str());
1264 case LFUN_MENU_OPEN_BY_NAME:
1265 owner->getMenus()->openByName(argument);
1266 break; // RVDK_PATCH_5
1268 case LFUN_SPELLCHECK:
1269 if (lyxrc->isp_command != "none")
1271 break; // RVDK_PATCH_5
1273 // --- Cursor Movements -----------------------------
1276 LyXText * tmptext = owner->view()->text;
1277 if(!tmptext->mark_set)
1279 owner->view()->update(-2);
1280 if (tmptext->cursor.pos < tmptext->cursor.par->Last()
1281 && tmptext->cursor.par->GetChar(tmptext->cursor.pos)
1282 == LyXParagraph::META_INSET
1283 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)
1284 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)->Editable() == 2){
1285 Inset * tmpinset = tmptext->cursor.par->GetInset(tmptext->cursor.pos);
1286 setMessage(tmpinset->EditMessage());
1287 tmpinset->Edit(0, 0);
1290 tmptext->CursorRight();
1291 owner->view()->text->FinishUndo();
1292 moveCursorUpdate(false);
1293 owner->getMiniBuffer()->Set(CurrentState());
1299 // This is soooo ugly. Isn`t it possible to make
1300 // it simpler? (Lgb)
1301 LyXText * txt = owner->view()->text;
1302 if(!txt->mark_set) BeforeChange();
1303 owner->view()->update(-2);
1305 if (txt->cursor.pos < txt->cursor.par->Last()
1306 && txt->cursor.par->GetChar(txt->cursor.pos)
1307 == LyXParagraph::META_INSET
1308 && txt->cursor.par->GetInset(txt->cursor.pos)
1309 && txt->cursor.par->GetInset(txt->cursor.pos)->Editable() == 2) {
1310 Inset * tmpinset = txt->cursor.par->GetInset(txt->cursor.pos);
1311 setMessage(tmpinset->EditMessage());
1312 tmpinset->Edit(tmpinset->Width(txt->GetFont(txt->cursor.par,
1313 txt->cursor.pos)), 0);
1316 owner->view()->text->FinishUndo();
1317 moveCursorUpdate(false);
1318 owner->getMiniBuffer()->Set(CurrentState());
1323 if(!owner->view()->text->mark_set) BeforeChange();
1324 owner->view()->update(-3);
1325 owner->view()->text->CursorUp();
1326 owner->view()->text->FinishUndo();
1327 moveCursorUpdate(false);
1328 owner->getMiniBuffer()->Set(CurrentState());
1332 if(!owner->view()->text->mark_set)
1334 owner->view()->update(-3);
1335 owner->view()->text->CursorDown();
1336 owner->view()->text->FinishUndo();
1337 moveCursorUpdate(false);
1338 owner->getMiniBuffer()->Set(CurrentState());
1341 case LFUN_UP_PARAGRAPH:
1342 if(!owner->view()->text->mark_set)
1344 owner->view()->update(-3);
1345 owner->view()->text->CursorUpParagraph();
1346 owner->view()->text->FinishUndo();
1347 moveCursorUpdate(false);
1348 owner->getMiniBuffer()->Set(CurrentState());
1351 case LFUN_DOWN_PARAGRAPH:
1352 if(!owner->view()->text->mark_set)
1354 owner->view()->update(-3);
1355 owner->view()->text->CursorDownParagraph();
1356 owner->view()->text->FinishUndo();
1357 moveCursorUpdate(false);
1358 owner->getMiniBuffer()->Set(CurrentState());
1362 if(!owner->view()->text->mark_set)
1364 owner->view()->update(-3);
1365 owner->view()->cursorPrevious();
1366 owner->view()->text->FinishUndo();
1367 moveCursorUpdate(false);
1368 owner->getMiniBuffer()->Set(CurrentState());
1372 if(!owner->view()->text->mark_set)
1374 owner->view()->update(-3);
1375 owner->view()->cursorNext();
1376 owner->view()->text->FinishUndo();
1377 moveCursorUpdate(false);
1378 owner->getMiniBuffer()->Set(CurrentState());
1382 if(!owner->view()->text->mark_set)
1384 owner->view()->update(-2);
1385 owner->view()->text->CursorHome();
1386 owner->view()->text->FinishUndo();
1387 moveCursorUpdate(false);
1388 owner->getMiniBuffer()->Set(CurrentState());
1392 if(!owner->view()->text->mark_set)
1394 owner->view()->update(-2);
1395 owner->view()->text->CursorEnd();
1396 owner->view()->text->FinishUndo();
1397 moveCursorUpdate(false);
1398 owner->getMiniBuffer()->Set(CurrentState());
1402 if(!owner->view()->text->mark_set)
1404 owner->view()->update(-2);
1405 owner->view()->text->CursorTab();
1406 owner->view()->text->FinishUndo();
1407 moveCursorUpdate(false);
1408 owner->getMiniBuffer()->Set(CurrentState());
1411 case LFUN_WORDRIGHT:
1412 if(!owner->view()->text->mark_set)
1414 owner->view()->update(-2);
1415 owner->view()->text->CursorRightOneWord();
1416 owner->view()->text->FinishUndo();
1417 moveCursorUpdate(false);
1418 owner->getMiniBuffer()->Set(CurrentState());
1422 if(!owner->view()->text->mark_set)
1424 owner->view()->update(-2);
1425 owner->view()->text->CursorLeftOneWord();
1426 owner->view()->text->FinishUndo();
1427 moveCursorUpdate(false);
1428 owner->getMiniBuffer()->Set(CurrentState());
1431 case LFUN_BEGINNINGBUF:
1432 if(!owner->view()->text->mark_set)
1434 owner->view()->update(-2);
1435 owner->view()->text->CursorTop();
1436 owner->view()->text->FinishUndo();
1437 moveCursorUpdate(false);
1438 owner->getMiniBuffer()->Set(CurrentState());
1442 if(!owner->view()->text->mark_set)
1444 owner->view()->update(-2);
1445 owner->view()->text->CursorBottom();
1446 owner->view()->text->FinishUndo();
1447 moveCursorUpdate(false);
1448 owner->getMiniBuffer()->Set(CurrentState());
1452 /* cursor selection ---------------------------- */
1454 owner->view()->update(-2);
1455 owner->view()->text->CursorRight();
1456 owner->view()->text->FinishUndo();
1457 moveCursorUpdate(true);
1458 owner->getMiniBuffer()->Set(CurrentState());
1462 owner->view()->update(-2);
1463 owner->view()->text->CursorLeft();
1464 owner->view()->text->FinishUndo();
1465 moveCursorUpdate(true);
1466 owner->getMiniBuffer()->Set(CurrentState());
1470 owner->view()->update(-2);
1471 owner->view()->text->CursorUp();
1472 owner->view()->text->FinishUndo();
1473 moveCursorUpdate(true);
1474 owner->getMiniBuffer()->Set(CurrentState());
1478 owner->view()->update(-2);
1479 owner->view()->text->CursorDown();
1480 owner->view()->text->FinishUndo();
1481 moveCursorUpdate(true);
1482 owner->getMiniBuffer()->Set(CurrentState());
1485 case LFUN_UP_PARAGRAPHSEL:
1486 owner->view()->update(-2);
1487 owner->view()->text->CursorUpParagraph();
1488 owner->view()->text->FinishUndo();
1489 moveCursorUpdate(true);
1490 owner->getMiniBuffer()->Set(CurrentState());
1493 case LFUN_DOWN_PARAGRAPHSEL:
1494 owner->view()->update(-2);
1495 owner->view()->text->CursorDownParagraph();
1496 owner->view()->text->FinishUndo();
1497 moveCursorUpdate(true);
1498 owner->getMiniBuffer()->Set(CurrentState());
1502 owner->view()->update(-2);
1503 owner->view()->cursorPrevious();
1504 owner->view()->text->FinishUndo();
1505 moveCursorUpdate(true);
1506 owner->getMiniBuffer()->Set(CurrentState());
1510 owner->view()->update(-2);
1511 owner->view()->cursorNext();
1512 owner->view()->text->FinishUndo();
1513 moveCursorUpdate(true);
1514 owner->getMiniBuffer()->Set(CurrentState());
1518 owner->view()->update(-2);
1519 owner->view()->text->CursorHome();
1520 owner->view()->text->FinishUndo();
1521 moveCursorUpdate(true);
1522 owner->getMiniBuffer()->Set(CurrentState());
1526 owner->view()->update(-2);
1527 owner->view()->text->CursorEnd();
1528 owner->view()->text->FinishUndo();
1529 moveCursorUpdate(true);
1530 owner->getMiniBuffer()->Set(CurrentState());
1533 case LFUN_WORDRIGHTSEL:
1534 owner->view()->update(-2);
1535 owner->view()->text->CursorRightOneWord();
1536 owner->view()->text->FinishUndo();
1537 moveCursorUpdate(true);
1538 owner->getMiniBuffer()->Set(CurrentState());
1541 case LFUN_WORDLEFTSEL:
1542 owner->view()->update(-2);
1543 owner->view()->text->CursorLeftOneWord();
1544 owner->view()->text->FinishUndo();
1545 moveCursorUpdate(true);
1546 owner->getMiniBuffer()->Set(CurrentState());
1549 case LFUN_BEGINNINGBUFSEL:
1550 owner->view()->update(-2);
1551 owner->view()->text->CursorTop();
1552 owner->view()->text->FinishUndo();
1553 moveCursorUpdate(true);
1554 owner->getMiniBuffer()->Set(CurrentState());
1557 case LFUN_ENDBUFSEL:
1558 owner->view()->update(-2);
1559 owner->view()->text->CursorBottom();
1560 owner->view()->text->FinishUndo();
1561 moveCursorUpdate(true);
1562 owner->getMiniBuffer()->Set(CurrentState());
1565 // --- text changing commands ------------------------
1566 case LFUN_BREAKLINE:
1568 owner->view()->text->InsertChar(LyXParagraph::META_NEWLINE);
1570 SetUpdateTimer(0.01);
1571 moveCursorUpdate(false);
1574 case LFUN_PROTECTEDSPACE:
1576 owner->view()->text->
1577 InsertChar(LyXParagraph::META_PROTECTED_SEPARATOR);
1580 moveCursorUpdate(false);
1584 if(owner->view()->text->mark_set) {
1586 owner->view()->update(0);
1587 setMessage(N_("Mark removed"));
1590 owner->view()->text->mark_set = 1;
1591 owner->view()->update(0);
1592 setMessage(N_("Mark set"));
1594 owner->view()->text->sel_cursor =
1595 owner->view()->text->cursor;
1600 if (!owner->view()->text->selection) {
1601 owner->view()->text->Delete();
1602 owner->view()->text->sel_cursor =
1603 owner->view()->text->cursor;
1605 // It is possible to make it a lot faster still
1606 // just comment out the lone below...
1607 owner->view()->getScreen()->ShowCursor();
1614 case LFUN_DELETE_SKIP:
1616 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1618 LyXCursor cursor = owner->view()->text->cursor;
1621 if (!owner->view()->text->selection) {
1622 if (cursor.pos == cursor.par->Last()) {
1623 owner->view()->text->CursorRight();
1624 cursor = owner->view()->text->cursor;
1626 && !(cursor.par->added_space_top
1627 == VSpace (VSpace::NONE))) {
1628 owner->view()->text->SetParagraph
1629 (cursor.par->line_top,
1630 cursor.par->line_bottom,
1631 cursor.par->pagebreak_top,
1632 cursor.par->pagebreak_bottom,
1633 VSpace(VSpace::NONE),
1634 cursor.par->added_space_bottom,
1636 cursor.par->labelwidthstring, 0);
1637 owner->view()->text->CursorLeft();
1638 owner->view()->update (1);
1640 owner->view()->text->CursorLeft();
1641 owner->view()->text->Delete();
1642 owner->view()->text->sel_cursor =
1643 owner->view()->text->cursor;
1647 owner->view()->text->Delete();
1648 owner->view()->text->sel_cursor =
1649 owner->view()->text->cursor;
1659 /* -------> Delete word forward. */
1660 case LFUN_DELETE_WORD_FORWARD:
1661 owner->view()->update(-2);
1663 owner->view()->text->DeleteWordForward();
1664 owner->view()->update( 1 );
1666 moveCursorUpdate(false);
1669 /* -------> Delete word backward. */
1670 case LFUN_DELETE_WORD_BACKWARD:
1671 owner->view()->update(-2);
1673 owner->view()->text->DeleteWordBackward();
1674 owner->view()->update( 1 );
1676 moveCursorUpdate(false);
1679 /* -------> Kill to end of line. */
1680 case LFUN_DELETE_LINE_FORWARD:
1682 owner->view()->update(-2);
1683 owner->view()->text->DeleteLineForward();
1684 owner->view()->update( 1 );
1686 moveCursorUpdate(false);
1689 /* -------> Set mark off. */
1692 owner->view()->update(0);
1693 owner->view()->text->sel_cursor =
1694 owner->view()->text->cursor;
1695 setMessage(N_("Mark off"));
1698 /* -------> Set mark on. */
1701 owner->view()->text->mark_set = 1;
1702 owner->view()->update( 0 );
1703 owner->view()->text->sel_cursor =
1704 owner->view()->text->cursor;
1705 setMessage(N_("Mark on"));
1708 case LFUN_BACKSPACE:
1711 if (!owner->view()->text->selection) {
1712 if (owner->getIntl()->getTrans()->backspace()) {
1713 owner->view()->text->Backspace();
1714 owner->view()->text->sel_cursor =
1715 owner->view()->text->cursor;
1717 // It is possible to make it a lot faster still
1718 // just comment out the lone below...
1719 owner->view()->getScreen()->ShowCursor();
1728 case LFUN_BACKSPACE_SKIP:
1730 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1732 LyXCursor cursor = owner->view()->text->cursor;
1735 if (!owner->view()->text->selection) {
1737 && !(cursor.par->added_space_top
1738 == VSpace (VSpace::NONE))) {
1739 owner->view()->text->SetParagraph
1740 (cursor.par->line_top,
1741 cursor.par->line_bottom,
1742 cursor.par->pagebreak_top,
1743 cursor.par->pagebreak_bottom,
1744 VSpace(VSpace::NONE), cursor.par->added_space_bottom,
1746 cursor.par->labelwidthstring, 0);
1747 owner->view()->update (1);
1749 owner->view()->text->Backspace();
1750 owner->view()->text->sel_cursor
1760 case LFUN_BREAKPARAGRAPH:
1763 owner->view()->text->BreakParagraph(0);
1765 SetUpdateTimer(0.01);
1766 owner->view()->text->sel_cursor =
1767 owner->view()->text->cursor;
1771 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1774 owner->view()->text->BreakParagraph(1);
1776 SetUpdateTimer(0.01);
1777 owner->view()->text->sel_cursor =
1778 owner->view()->text->cursor;
1782 case LFUN_BREAKPARAGRAPH_SKIP:
1784 // When at the beginning of a paragraph, remove
1785 // indentation and add a "defskip" at the top.
1786 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
1788 LyXCursor cursor = owner->view()->text->cursor;
1791 if (cursor.pos == 0) {
1792 if (cursor.par->added_space_top == VSpace(VSpace::NONE)) {
1793 owner->view()->text->SetParagraph
1794 (cursor.par->line_top,
1795 cursor.par->line_bottom,
1796 cursor.par->pagebreak_top,
1797 cursor.par->pagebreak_bottom,
1798 VSpace(VSpace::DEFSKIP), cursor.par->added_space_bottom,
1800 cursor.par->labelwidthstring, 1);
1801 owner->view()->update(1);
1805 owner->view()->text->BreakParagraph(0);
1808 SetUpdateTimer(0.01);
1809 owner->view()->text->sel_cursor = cursor;
1815 owner->view()->text->InsertChar('\"'); // This " matches the single quote in the code
1818 moveCursorUpdate(false);
1824 InsetCommand * new_inset;
1825 if (action == LFUN_HTMLURL)
1826 new_inset = new InsetUrl("htmlurl", "", "");
1828 new_inset = new InsetUrl("url", "", "");
1829 owner->buffer()->insertInset(new_inset);
1830 new_inset->Edit(0, 0);
1834 // --- lyxserver commands ----------------------------
1836 case LFUN_CHARATCURSOR:
1838 LyXParagraph::size_type pos =
1839 owner->view()->text->cursor.pos;
1840 if(pos < owner->view()->text->cursor.par->size())
1841 dispatch_buffer = owner->view()->text->
1842 cursor.par->text[pos];
1844 dispatch_buffer = "EOF";
1850 tostr(owner->view()->text->cursor.x) + ' '
1851 + tostr(owner->view()->text->cursor.y);
1858 sscanf(argument.c_str(), " %d %ld", &x, &y);
1859 owner->view()->text->SetCursorFromCoordinates(x, y);
1863 case LFUN_GETLAYOUT:
1865 tostr(owner->view()->text->cursor.par->layout);
1870 LyXFont * font = &(owner->view()->text->current_font);
1871 if(font->shape() == LyXFont::ITALIC_SHAPE)
1872 dispatch_buffer = 'E';
1873 else if(font->shape() == LyXFont::SMALLCAPS_SHAPE)
1874 dispatch_buffer = 'N';
1876 dispatch_buffer = '0';
1883 LyXFont * font = &(owner->view()->text->current_font);
1884 if(font->latex() == LyXFont::ON)
1885 dispatch_buffer = 'L';
1887 dispatch_buffer = '0';
1892 setMessage(owner->buffer()->fileName());
1893 lyxerr.debug() << "FNAME["
1894 << owner->buffer()->fileName()
1902 dispatch_buffer = buf;
1903 lyxserver->notifyClient(dispatch_buffer);
1907 case LFUN_GOTOFILEROW:
1909 char file_name[100];
1911 sscanf(argument.c_str(), " %s %d", file_name, &row);
1913 // Must replace extension of the file to be .lyx and get full path
1914 string s = ChangeExtension(string(file_name), ".lyx", false);
1916 // Either change buffer or load the file
1917 if (bufferlist.exists(s))
1918 owner->view()->buffer(bufferlist.getBuffer(s));
1920 owner->view()->buffer(bufferlist.loadLyXFile(s));
1923 owner->buffer()->setCursorFromRow(row);
1927 if (owner->view()->text->cursor.y >
1928 owner->view()->getWorkArea()->h / 2) {
1929 owner->view()->getScreen()->
1930 Draw(owner->view()->text->cursor.y -
1931 owner->view()->getWorkArea()->h/2);
1933 owner->view()->getScreen()->
1936 owner->view()->update(0);
1937 owner->view()->redraw();
1944 int qa = lyxaction.LookupFunc(argument.c_str());
1945 setMessage(lyxaction.helpText(static_cast<kb_action>(qa)));
1949 // --- accented characters ---------------------------
1952 case LFUN_CIRCUMFLEX:
1962 case LFUN_SPECIAL_CARON:
1965 case LFUN_HUNG_UMLAUT:
1971 if (keyseq.length == -1 && keyseq.getiso() != 0)
1972 c = keyseq.getiso();
1976 owner->getIntl()->getTrans()->
1977 deadkey(c, get_accent(action).accent,
1978 owner->view()->text);
1980 // Need to reset, in case the minibuffer calls these
1985 // copied verbatim from do_accent_char
1988 owner->view()->text->sel_cursor =
1989 owner->view()->text->cursor;
1993 // --- toolbar ----------------------------------
1994 case LFUN_PUSH_TOOLBAR:
1996 int nth = strToInt(argument);
1997 if (lyxerr.debugging(Debug::TOOLBAR)) {
1998 lyxerr << "LFUN_PUSH_TOOLBAR: argument = `"
1999 << argument << "'\n"
2000 << "LFUN_PUSH_TOOLBAR: nth = `"
2001 << nth << "'" << endl;
2006 setErrorMessage(N_("Push-toolbar needs argument > 0"));
2008 owner->getToolbar()->push(nth);
2013 case LFUN_ADD_TO_TOOLBAR:
2015 if (lyxerr.debugging(Debug::TOOLBAR)) {
2016 lyxerr << "LFUN_ADD_TO_TOOLBAR:"
2017 "argument = `" << argument << '\'' << endl;
2019 string tmp(argument);
2020 //lyxerr <<string("Argument: ") + argument);
2021 //lyxerr <<string("Tmp : ") + tmp);
2024 setErrorMessage(N_("Usage: toolbar-add-to <LyX command>"));
2026 owner->getToolbar()->add(argument, false);
2027 owner->getToolbar()->set();
2032 // --- insert characters ----------------------------------------
2034 case LFUN_INSERT_INSET_LATEX:
2036 Inset * new_inset = new InsetLatex(argument);
2037 owner->buffer()->insertInset(new_inset);
2041 // --- Mathed stuff. If we are here, there is no locked inset yet.
2046 if (!greek_kb_flag) {
2048 setMessage(N_("Math greek mode on"));
2055 case LFUN_GREEK_TOGGLE:
2057 greek_kb_flag = greek_kb_flag ? 0 : 2;
2058 if (greek_kb_flag) {
2059 setMessage(N_("Math greek keyboard on"));
2061 setMessage(N_("Math greek keyboard off"));
2066 case LFUN_MATH_DELIM:
2067 case LFUN_INSERT_MATRIX:
2069 if (owner->view()->available()) {
2071 open_new_inset(new InsetFormula(false));
2073 the_locking_inset->LocalDispatch(action, argument.c_str());
2078 case LFUN_INSERT_MATH:
2080 math_insert_symbol(argument.c_str());
2084 case LFUN_MATH_DISPLAY:
2086 if (owner->view()->available())
2087 owner->buffer()->open_new_inset(new InsetFormula(true));
2091 case LFUN_MATH_MACRO:
2093 if (owner->view()->available()) {
2096 setErrorMessage(N_("Missing argument"));
2098 string s1 = token(s, ' ', 1);
2099 int na = s1.empty() ? 0: atoi(s1.c_str());
2101 open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2107 case LFUN_MATH_MODE: // Open or create a math inset
2110 if (owner->view()->available())
2111 owner->buffer()->open_new_inset(new InsetFormula);
2112 setMessage(N_("Math editor mode"));
2116 case LFUN_MATH_NUMBER:
2117 case LFUN_MATH_LIMITS:
2119 setErrorMessage(N_("This is only allowed in math mode!"));
2123 case LFUN_INSERT_CITATION:
2125 InsetCitation * new_inset = new InsetCitation();
2127 // The note, if any, must be after the key, delimited
2128 // by a | so both key and remark can have spaces.
2129 if (!argument.empty()) {
2130 string lsarg(argument);
2131 if (contains(lsarg, "|")) {
2132 new_inset->setContents(token(lsarg, '|', 0));
2133 new_inset->setOptions(token(lsarg, '|', 1));
2135 new_inset->setContents(lsarg);
2136 owner->buffer()->insertInset(new_inset);
2138 owner->buffer()->insertInset(new_inset);
2139 new_inset->Edit(0, 0);
2144 case LFUN_INSERT_BIBTEX:
2146 // ale970405+lasgoutt970425
2147 // The argument can be up to two tokens separated
2148 // by a space. The first one is the bibstyle.
2149 string lsarg(argument);
2150 string bibstyle = token(lsarg, ' ', 1);
2151 if (bibstyle.empty())
2153 InsetBibtex * new_inset
2154 = new InsetBibtex(token(lsarg, ' ', 0),
2158 owner->buffer()->insertInset(new_inset);
2159 if (lsarg.empty()) {
2160 new_inset->Edit(0, 0);
2165 // BibTeX data bases
2166 case LFUN_BIBDB_ADD:
2168 InsetBibtex * inset =
2169 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2171 inset->addDatabase(argument);
2176 case LFUN_BIBDB_DEL:
2178 InsetBibtex * inset =
2179 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2181 inset->delDatabase(argument);
2186 case LFUN_BIBTEX_STYLE:
2188 InsetBibtex * inset =
2189 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2191 inset->setOptions(argument);
2196 case LFUN_INDEX_INSERT:
2197 case LFUN_INDEX_INSERT_LAST:
2199 // Can't do that at the beginning of a paragraph.
2200 if (owner->view()->text->cursor.pos - 1 < 0)
2203 InsetIndex * new_inset = new InsetIndex();
2204 if (!argument.empty()) {
2205 string lsarg(argument);
2206 new_inset->setContents(lsarg);
2207 owner->buffer()->insertInset(new_inset);
2210 //get the current word for an argument
2211 LyXParagraph::size_type lastpos =
2212 owner->view()->text->cursor.pos - 1;
2213 // Get the current word. note that this must be done
2214 // before inserting the inset, or the inset will
2216 string curstring(owner->view()
2217 ->text->cursor.par->GetWord(lastpos));
2219 //make the new inset and write the current word into it
2220 InsetIndex * new_inset = new InsetIndex();
2222 new_inset->setContents(curstring);
2224 //don't edit it if the call was to INSERT_LAST
2225 if(action != LFUN_INDEX_INSERT_LAST) {
2226 new_inset->Edit(0, 0);
2228 //it looks blank on the screen unless
2229 //we do something. put it here.
2231 // move the cursor to the returned value of lastpos
2232 // but only for the auto-insert
2233 owner->view()->text->cursor.pos = lastpos;
2236 //put the new inset into the buffer.
2237 // there should be some way of knowing the user
2238 //cancelled & avoiding this, but i don't know how
2239 owner->buffer()->insertInset(new_inset);
2244 case LFUN_INDEX_PRINT:
2246 Inset * new_inset = new InsetPrintIndex(owner->buffer());
2247 owner->buffer()->insertInset(new_inset, "Standard", true);
2251 case LFUN_PARENTINSERT:
2253 lyxerr << "arg " << argument << endl;
2254 Inset * new_inset = new InsetParent(argument, owner->buffer());
2255 owner->buffer()->insertInset(new_inset, "Standard", true);
2259 case LFUN_CHILDINSERT:
2261 Inset * new_inset = new InsetInclude(argument,
2263 owner->buffer()->insertInset(new_inset, "Standard", true);
2264 new_inset->Edit(0, 0);
2268 case LFUN_CHILDOPEN:
2271 MakeAbsPath(argument,
2272 OnlyPath(owner->buffer()->fileName()));
2273 setMessage(N_("Opening child document ") +
2274 MakeDisplayPath(filename) + "...");
2275 owner->view()->savePosition();
2276 if (bufferlist.exists(filename))
2277 owner->view()->buffer(bufferlist.getBuffer(filename));
2279 owner->view()->buffer(bufferlist.loadLyXFile(filename));
2283 case LFUN_INSERT_NOTE:
2287 case LFUN_INSERTFOOTNOTE:
2289 LyXParagraph::footnote_kind kind;
2290 if (argument == "footnote")
2291 { kind = LyXParagraph::FOOTNOTE; }
2292 else if (argument == "margin")
2293 { kind = LyXParagraph::MARGIN; }
2294 else if (argument == "figure")
2295 { kind = LyXParagraph::FIG; }
2296 else if (argument == "table")
2297 { kind = LyXParagraph::TAB; }
2298 else if (argument == "wide-fig")
2299 { kind = LyXParagraph::WIDE_FIG; }
2300 else if (argument == "wide-tab")
2301 { kind = LyXParagraph::WIDE_TAB; }
2302 else if (argument == "algorithm")
2303 { kind = LyXParagraph::ALGORITHM; }
2305 setErrorMessage(N_("Unknown kind of footnote"));
2308 owner->view()->text->InsertFootnoteEnvironment(kind);
2309 owner->view()->update(1);
2313 case LFUN_BUFFERBULLETSSELECT:
2317 case LFUN_TOGGLECURSORFOLLOW:
2318 cursor_follows_scrollbar = !cursor_follows_scrollbar;
2321 case LFUN_KMAP_OFF: // keymap off
2322 owner->getIntl()->KeyMapOn(false);
2325 case LFUN_KMAP_PRIM: // primary keymap
2326 owner->getIntl()->KeyMapPrim();
2329 case LFUN_KMAP_SEC: // secondary keymap
2330 owner->getIntl()->KeyMapSec();
2333 case LFUN_KMAP_TOGGLE: // toggle keymap
2334 owner->getIntl()->ToggleKeyMap();
2337 case LFUN_SELFINSERT:
2339 for (string::size_type i = 0; i < argument.length(); ++i) {
2340 owner->view()->text->InsertChar(argument[i]);
2341 // This needs to be in the loop, or else we
2342 // won't break lines correctly. (Asger)
2346 owner->view()->text->sel_cursor =
2347 owner->view()->text->cursor;
2348 moveCursorUpdate(false);
2354 // argument contains ';'-terminated commands
2355 while (argument.find(';') != string::npos) {
2357 argument = split(argument, first, ';');
2363 case LFUN_SAVEPREFERENCES:
2365 Path p(user_lyxdir);
2366 lyxrc->write("preferences");
2370 case LFUN_UNKNOWN_ACTION:
2372 if (owner->buffer()->isReadonly()) {
2374 setErrorMessage(N_("Document is read only"));
2378 if (!argument.empty()) {
2380 /* Automatically delete the currently selected
2381 * text and replace it with what is being
2382 * typed in now. Depends on lyxrc settings
2383 * "auto_region_delete", which defaults to
2386 if ( lyxrc->auto_region_delete ) {
2387 if (owner->view()->text->selection){
2388 owner->view()->text->CutSelection(false);
2389 owner->view()->update(-1);
2394 for (string::size_type i = 0;
2395 i < argument.length(); ++i) {
2396 if (greek_kb_flag) {
2397 if (!math_insert_greek(argument[i]))
2398 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2400 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2406 owner->view()->text->sel_cursor =
2407 owner->view()->text->cursor;
2408 moveCursorUpdate(false);
2411 // why is an "Unknown action" with empty
2412 // argument even dispatched in the first
2413 // place? I`ll probably change that. (Lgb)
2415 setErrorMessage(N_("Unknown action"));
2419 lyxerr << "A truly unknown func!" << endl;
2425 string res = getMessage();
2428 if (!commandshortcut.empty()) {
2429 string newbuf = owner->getMiniBuffer()->GetText();
2430 if (newbuf != commandshortcut) {
2431 owner->getMiniBuffer()->Set(newbuf
2437 owner->getMiniBuffer()->Set(string(_(res.c_str()))
2438 + " " + commandshortcut);
2445 void LyXFunc::setupLocalKeymap()
2447 keyseq.stdmap = keyseq.curmap = toplevel_keymap;
2448 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap;
2452 void LyXFunc::MenuNew(bool fromTemplate)
2454 string fname, initpath = lyxrc->document_path;
2457 if (owner->view()->available()) {
2458 string trypath = owner->buffer()->filepath;
2459 // If directory is writeable, use this as default.
2460 if (IsDirWriteable(trypath) == 1)
2465 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2466 fileDlg.SetButton(1, _("Templates"), lyxrc->template_path);
2467 fname = fileDlg.Select(_("Enter Filename for new document"),
2468 initpath, "*.lyx", _("newfile"));
2471 if (fname.empty()) {
2472 owner->getMiniBuffer()->Set(_("Canceled."));
2473 lyxerr.debug() << "New Document Cancelled." << endl;
2477 // get absolute path of file and make sure the filename ends
2479 string s = MakeAbsPath(fname);
2480 if (!IsLyXFilename(s))
2483 // Check if the document already is open
2484 if (bufferlist.exists(s)){
2485 switch(AskConfirmation(_("Document is already open:"),
2486 MakeDisplayPath(s, 50),
2487 _("Do you want to close that document now?\n"
2488 "('No' will just switch to the open version)")))
2490 case 1: // Yes: close the document
2491 if (!bufferlist.close(bufferlist.getBuffer(s)))
2492 // If close is canceled, we cancel here too.
2495 case 2: // No: switch to the open document
2496 owner->view()->buffer(bufferlist.getBuffer(s));
2498 case 3: // Cancel: Do nothing
2499 owner->getMiniBuffer()->Set(_("Canceled."));
2504 // Check whether the file already exists
2505 if (IsLyXFilename(s)) {
2507 if (fi.readable() &&
2508 AskQuestion(_("File already exists:"),
2509 MakeDisplayPath(s, 50),
2510 _("Do you want to open the document?"))) {
2512 owner->getMiniBuffer()->Set(_("Opening document"),
2513 MakeDisplayPath(s), "...");
2515 owner->view()->buffer(
2516 bufferlist.loadLyXFile(s));
2517 owner->getMiniBuffer()->Set(_("Document"),
2524 // The template stuff
2528 fname = fileDlg.Select(_("Choose template"),
2529 lyxrc->template_path,
2535 // find a free buffer
2536 lyxerr.debug() << "Find a free buffer." << endl;
2537 owner->view()->buffer(bufferlist.newFile(s, templname));
2541 void LyXFunc::MenuOpen()
2543 string initpath = lyxrc->document_path;
2546 if (owner->view()->available()) {
2547 string trypath = owner->buffer()->filepath;
2548 // If directory is writeable, use this as default.
2549 if (IsDirWriteable(trypath) == 1)
2555 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2556 fileDlg.SetButton(1, _("Examples"),
2557 AddPath(system_lyxdir, "examples"));
2558 string filename = fileDlg.Select(_("Select Document to Open"),
2562 // check selected filename
2563 if (filename.empty()) {
2564 owner->getMiniBuffer()->Set(_("Canceled."));
2568 // get absolute path of file and make sure the filename ends
2570 filename = MakeAbsPath(filename);
2571 if (!IsLyXFilename(filename))
2575 owner->getMiniBuffer()->Set(_("Opening document"),
2576 MakeDisplayPath(filename), "...");
2577 Buffer * openbuf = bufferlist.loadLyXFile(filename);
2579 owner->view()->buffer(openbuf);
2580 owner->getMiniBuffer()->Set(_("Document"),
2581 MakeDisplayPath(filename),
2584 owner->getMiniBuffer()->Set(_("Could not open document"),
2585 MakeDisplayPath(filename));
2590 void LyXFunc::doImportASCII(bool linorpar)
2592 string initpath = lyxrc->document_path;
2595 if (owner->view()->available()) {
2596 string trypath = owner->buffer()->filepath;
2597 // If directory is writeable, use this as default.
2598 if (IsDirWriteable(trypath) == 1)
2604 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2605 fileDlg.SetButton(1, _("Examples"),
2606 AddPath(system_lyxdir, "examples"));
2607 string filename = fileDlg.Select(_("Select ASCII file to Import"),
2611 // check selected filename
2612 if (filename.empty()) {
2613 owner->getMiniBuffer()->Set(_("Canceled."));
2617 // get absolute path of file
2618 filename = MakeAbsPath(filename);
2620 string s = ChangeExtension(filename, ".lyx", false);
2622 // Check if the document already is open
2623 if (bufferlist.exists(s)) {
2624 switch(AskConfirmation(_("Document is already open:"),
2625 MakeDisplayPath(s, 50),
2626 _("Do you want to close that document now?\n"
2627 "('No' will just switch to the open version)")))
2629 case 1: // Yes: close the document
2630 if (!bufferlist.close(bufferlist.getBuffer(s)))
2631 // If close is canceled, we cancel here too.
2634 case 2: // No: switch to the open document
2635 owner->view()->buffer(bufferlist.getBuffer(s));
2637 case 3: // Cancel: Do nothing
2638 owner->getMiniBuffer()->Set(_("Canceled."));
2643 // Check if a LyX document by the same root exists in filesystem
2644 FileInfo f(s, true);
2645 if (f.exist() && !AskQuestion(_("A document by the name"),
2647 _("already exists. Overwrite?"))) {
2648 owner->getMiniBuffer()->Set(_("Canceled."));
2652 owner->view()->buffer(bufferlist.newFile(s, string()));
2653 owner->getMiniBuffer()->Set(_("Importing ASCII file"),
2654 MakeDisplayPath(filename), "...");
2655 // Insert ASCII file
2656 InsertAsciiFile(filename, linorpar);
2657 owner->getMiniBuffer()->Set(_("ASCII file "),
2658 MakeDisplayPath(filename),
2663 void LyXFunc::doImportLaTeX(bool isnoweb)
2665 string initpath = lyxrc->document_path;
2668 if (owner->view()->available()) {
2669 string trypath = owner->buffer()->filepath;
2670 // If directory is writeable, use this as default.
2671 if (IsDirWriteable(trypath) == 1)
2677 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2678 fileDlg.SetButton(1, _("Examples"),
2679 AddPath(system_lyxdir, "examples"));
2682 filename = fileDlg.Select(_("Select Noweb file to Import"),
2685 filename = fileDlg.Select(_("Select LaTeX file to Import"),
2691 // check selected filename
2692 if (filename.empty()) {
2693 owner->getMiniBuffer()->Set(_("Canceled."));
2697 // get absolute path of file
2698 filename = MakeAbsPath(filename);
2700 // Check if the document already is open
2701 string LyXfilename = ChangeExtension(filename, ".lyx", false);
2702 if (bufferlist.exists(LyXfilename)){
2703 switch(AskConfirmation(_("Document is already open:"),
2704 MakeDisplayPath(LyXfilename, 50),
2705 _("Do you want to close that document now?\n"
2706 "('No' will just switch to the open version)")))
2708 case 1: // Yes: close the document
2709 if (!bufferlist.close(bufferlist.getBuffer(LyXfilename)))
2710 // If close is canceled, we cancel here too.
2713 case 2: // No: switch to the open document
2714 owner->view()->buffer(
2715 bufferlist.getBuffer(LyXfilename));
2717 case 3: // Cancel: Do nothing
2718 owner->getMiniBuffer()->Set(_("Canceled."));
2723 // Check if a LyX document by the same root exists in filesystem
2724 FileInfo f(LyXfilename, true);
2725 if (f.exist() && !AskQuestion(_("A document by the name"),
2726 MakeDisplayPath(LyXfilename),
2727 _("already exists. Overwrite?"))) {
2728 owner->getMiniBuffer()->Set(_("Canceled."));
2735 owner->getMiniBuffer()->Set(_("Importing LaTeX file"),
2736 MakeDisplayPath(filename), "...");
2737 ImportLaTeX myImport(filename);
2738 openbuf = myImport.run();
2740 owner->getMiniBuffer()->Set(_("Importing Noweb file"),
2741 MakeDisplayPath(filename), "...");
2742 ImportNoweb myImport(filename);
2743 openbuf = myImport.run();
2746 owner->view()->buffer(openbuf);
2747 owner->getMiniBuffer()->Set(isnoweb ?
2748 _("Noweb file ") : _("LateX file "),
2749 MakeDisplayPath(filename),
2752 owner->getMiniBuffer()->Set(isnoweb ?
2753 _("Could not import Noweb file") :
2754 _("Could not import LaTeX file"),
2755 MakeDisplayPath(filename));
2760 void LyXFunc::MenuInsertLyXFile(string const & filen)
2762 string filename = filen;
2764 if (filename.empty()) {
2765 // Launch a file browser
2766 string initpath = lyxrc->document_path;
2769 if (owner->view()->available()) {
2770 string trypath = owner->buffer()->filepath;
2771 // If directory is writeable, use this as default.
2772 if (IsDirWriteable(trypath) == 1)
2778 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2779 fileDlg.SetButton(1, _("Examples"),
2780 AddPath(system_lyxdir, "examples"));
2781 filename = fileDlg.Select(_("Select Document to Insert"),
2785 // check selected filename
2786 if (filename.empty()) {
2787 owner->getMiniBuffer()->Set(_("Canceled."));
2792 // get absolute path of file and make sure the filename ends
2794 filename = MakeAbsPath(filename);
2795 if (!IsLyXFilename(filename))
2799 owner->getMiniBuffer()->Set(_("Inserting document"),
2800 MakeDisplayPath(filename), "...");
2801 bool res = owner->buffer()->insertLyXFile(filename);
2803 owner->getMiniBuffer()->Set(_("Document"),
2804 MakeDisplayPath(filename),
2807 owner->getMiniBuffer()->Set(_("Could not insert document"),
2808 MakeDisplayPath(filename));
2813 void LyXFunc::reloadBuffer()
2815 string fn = owner->buffer()->fileName();
2816 if (bufferlist.close(owner->buffer()))
2817 owner->view()->buffer(bufferlist.loadLyXFile(fn));
2821 void LyXFunc::CloseBuffer()
2823 if (bufferlist.close(owner->buffer()) && !quitting) {
2824 if (bufferlist.empty()) {
2825 // need this otherwise SEGV may occur while trying to
2826 // set variables that don't exist
2827 // since there's no current buffer
2828 CloseAllBufferRelatedPopups();
2831 owner->view()->buffer(bufferlist.first());
2837 Inset * LyXFunc::getInsetByCode(Inset::Code code)
2841 LyXCursor cursor = owner->view()->text->cursor;
2842 LyXParagraph::size_type pos = cursor.pos;
2843 LyXParagraph * par = cursor.par;
2845 while (par && !found) {
2846 while ((inset = par->ReturnNextInsetPointer(pos))){
2847 if (inset->LyxCode() == code) {
2855 return found ? inset : 0;
2859 // Each "owner" should have it's own message method. lyxview and
2860 // the minibuffer would use the minibuffer, but lyxserver would
2861 // send an ERROR signal to its client. Alejandro 970603
2862 // This func is bit problematic when it comes to NLS, to make the
2863 // lyx servers client be language indepenent we must not translate
2864 // strings sent to this func.
2865 void LyXFunc::setErrorMessage(string const & m) const
2867 dispatch_buffer = m;
2872 void LyXFunc::setMessage(string const & m)
2874 dispatch_buffer = m;