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 "definitions.h"
22 #include "lyxlookup.h"
25 #include "bufferlist.h"
26 #include "lyxserver.h"
31 #include "insets/insetlatex.h"
32 #include "insets/inseturl.h"
33 #include "insets/insetlatexaccent.h"
34 #include "insets/insettoc.h"
35 #include "insets/insetlof.h"
36 #include "insets/insetloa.h"
37 #include "insets/insetlot.h"
38 #include "insets/insetref.h"
39 #include "insets/insetparent.h"
40 #include "mathed/formulamacro.h"
42 #include "spellchecker.h" // RVDK_PATCH_5
43 #include "minibuffer.h"
45 #include "insets/insetbib.h"
47 #include "insets/insetindex.h"
48 #include "insets/insetinclude.h"
50 #include "lyx_gui_misc.h"
51 #include "support/filetools.h"
52 #include "support/FileInfo.h"
53 #include "support/LAssert.h"
54 #include "lyxscreen.h"
59 #include "trans_mgr.h"
60 #include "ImportLaTeX.h"
61 #include "ImportNoweb.h"
62 #include "support/syscall.h"
63 #include "support/lstrings.h"
66 extern bool cursor_follows_scrollbar;
68 extern void InsertAsciiFile(string const &, bool);
69 extern void math_insert_symbol(char const*);
70 extern Bool math_insert_greek(char const); // why "Bool"?
71 extern BufferList bufferlist;
72 extern LyXServer *lyxserver;
73 extern short greek_kb_flag;
74 extern FD_form_toc *fd_form_toc;
75 extern bool selection_possible;
77 extern kb_keymap *toplevel_keymap;
79 extern void BeforeChange();
80 extern void MenuWrite(Buffer*);
81 extern void MenuWriteAs(Buffer*);
82 extern int MenuRunLaTeX(Buffer*);
83 extern int MenuBuildProg(Buffer*);
84 extern int MenuRunChktex(Buffer*);
85 extern bool MenuRunDvips(Buffer *,bool);
86 extern void MenuPrint(Buffer*);
87 extern void MenuSendto();
88 extern void QuitLyX();
89 extern void MenuFax(Buffer *);
90 extern void MenuMakeLaTeX(Buffer *);
91 extern void MenuMakeLinuxDoc(Buffer *);
92 extern void MenuMakeDocBook(Buffer *);
93 extern void MenuMakeAscii(Buffer *);
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(const char *);
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;
164 // I changed this func slightly. I commented out the ...FinishUndo(),
165 // this means that all places that used to have a moveCursorUpdate, now
166 // have a ...FinishUndo() as the preceeding statement. I have also added
167 // a moveCursorUpdate to some of the functions that updated the cursor, but
168 // that did not show its new position.
170 void LyXFunc::moveCursorUpdate(bool selecting)
172 if (selecting || owner->currentBuffer()->text->mark_set) {
173 owner->currentBuffer()->text->SetSelection();
174 owner->currentView()->getScreen()->ToggleToggle();
175 owner->currentBuffer()->update(0);
177 owner->currentBuffer()->update(-2); // this IS necessary
180 owner->currentView()->getScreen()->ShowCursor();
182 /* ---> Everytime the cursor is moved, show the current font state. */
183 // should this too me moved out of this func?
184 //owner->getMiniBuffer()->Set(CurrentState());
188 int LyXFunc::processKeyEvent(XEvent *ev)
195 XKeyEvent *keyevent = &ev->xkey;
196 KeySym keysym_return;
198 num_bytes = LyXLookupString(ev, s_r, 10, &keysym_return);
200 if (lyxerr.debugging(Debug::KEY)) {
201 lyxerr << "KeySym is "
202 << XKeysymToString(keysym_return)
204 << keysym_return << "]"
205 << " and num_bytes is "
207 << " the string returned is \""
208 << s_r << '\"' << endl;
210 // Do nothing if we have nothing (JMarc)
211 if (num_bytes == 0 && keysym_return == NoSymbol) {
212 lyxerr[Debug::KEY] << "Empty kbd action (probably composing)"
217 // this function should be used always [asierra060396]
218 if (owner->currentView()->available() &&
219 owner->currentBuffer()->the_locking_inset &&
220 keysym_return == XK_Escape) {
221 UnlockInset(owner->currentBuffer()->the_locking_inset);
222 owner->currentBuffer()->text->CursorRight();
226 // Can we be sure that this will work for all X-Windows
227 // implementations? (Lgb)
228 // This code snippet makes lyx ignore some keys. Perhaps
229 // all of them should be explictly mentioned?
230 if((keysym_return >= XK_Shift_L && keysym_return <= XK_Hyper_R)
231 || keysym_return == XK_Mode_switch || keysym_return == 0x0)
234 // Do a one-deep top-level lookup for
235 // cancel and meta-fake keys. RVDK_PATCH_5
236 cancel_meta_seq.reset();
238 action = cancel_meta_seq.addkey(keysym_return, keyevent->state
239 &(ShiftMask|ControlMask
242 // When not cancel or meta-fake, do the normal lookup.
243 // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
244 // Mostly, meta_fake_bit = 0. RVDK_PATCH_5.
245 if ( (action != LFUN_CANCEL) && (action != LFUN_META_FAKE) ) {
247 // remove Caps Lock and Mod2 as a modifiers
248 action = keyseq.addkey(keysym_return,
249 (keyevent->state | meta_fake_bit)
250 &(ShiftMask|ControlMask
253 // Dont remove this unless you know what you are doing.
256 if (action == 0) action = LFUN_PREFIX;
258 if (lyxerr.debugging(Debug::KEY)) {
260 keyseq.print(buf,100);
264 << num_bytes << "]" << endl;
267 // already here we know if it any point in going further
268 // why not return already here if action == -1 and
269 // num_bytes == 0? (Lgb)
271 if(keyseq.length>1 || keyseq.length<-1){
273 keyseq.print(buf,100);
274 owner->getMiniBuffer()->Set(buf);
278 if (keyseq.length<-1) { // unknown key sequence...
281 keyseq.print(buf,100);
282 owner->getMiniBuffer()->Set(_("Unknown sequence:"),buf);
286 char isochar = keyseq.getiso();
287 if (!(keyevent->state&ControlMask) &&
288 !(keyevent->state&Mod1Mask) &&
289 (isochar && keysym_return < 0xF000)) {
292 if (argument.empty()) {
293 lyxerr.debug() << "Empty argument!" << endl;
294 // This can`t possibly be of any use
295 // so we`ll skip the dispatch.
299 if (action==LFUN_SELFINSERT) {
303 bool tmp_sc = show_sc;
305 Dispatch(action, argument.c_str());
312 string LyXFunc::Dispatch(string const &cmd, string const &arg)
314 return Dispatch(lyxaction.LookupFunc(cmd.c_str()),
319 string LyXFunc::Dispatch(int ac,
320 char const *do_not_use_this_arg)
326 FL_OBJECT *ob = 0; // This will disapear soon
328 // we have not done anything wrong yet.
330 dispatch_buffer = string();
332 // if action is a pseudo-action, we need the real action
333 if (lyxaction.isPseudoAction(ac)) {
334 char const *tmparg = 0;
335 action = (kb_action)lyxaction.retrieveActionArg(ac, &tmparg);
339 action = (kb_action)ac;
340 if (do_not_use_this_arg)
341 argument = do_not_use_this_arg; // except here
344 selection_possible = false;
346 if (owner->currentView()->available()
347 && owner->currentView()->getScreen())
348 owner->currentView()->getScreen()->HideCursor();
350 if(!owner->currentView()->available()) {
351 // This lists the allowed funcs when we have no
354 case LFUN_MENU_OPEN_BY_NAME:
357 case LFUN_MENUNEWTMPLT:
360 case LFUN_PUSH_TOOLBAR:
361 case LFUN_ADD_TO_TOOLBAR:
362 case LFUN_EXEC_COMMAND:
363 case LFUN_DROP_LAYOUTS_CHOICE:
367 case LFUN_RECONFIGURE:
373 case LFUN_UNKNOWN_ACTION:
374 setErrorMessage(N_("Unknown action"));
375 goto exit_with_message;
377 setErrorMessage(N_("Command not allowed with"
378 "out any document open"));
379 goto exit_with_message; // action not allowed
383 commandshortcut = string();
385 if (lyxrc->display_shortcuts && show_sc) {
386 if (action != LFUN_SELFINSERT) {
387 // Put name of command and list of shortcuts
388 // for it in minibuffer
389 string comname = lyxaction.getActionName(action);
391 int pseudoaction = action;
392 bool argsadded = false;
394 if (!argument.empty()) {
395 // If we have the command with argument,
398 lyxaction.searchActionArg(action,
401 if (pseudoaction == -1) {
402 pseudoaction = action;
404 comname += " " + argument;
409 string shortcuts = toplevel_keymap->findbinding(pseudoaction);
411 if (!shortcuts.empty()) {
412 comname += ": " + shortcuts;
413 } else if (!argsadded) {
414 comname += " " + argument;
417 if (!comname.empty()) {
418 comname = strip(comname);
419 commandshortcut = "(" + comname + ')';
420 owner->getMiniBuffer()->Set(commandshortcut);
421 // Here we could even add a small pause,
422 // to annoy the user and make him learn
424 // No! That will just annoy, not teach
425 // anything. The user will read the messages
426 // if they are interested. (Asger)
431 // Now that we know which action, if the buffer is RO let's check
432 // whether the action is legal. Alejandro 970603
433 if (owner->currentView()->available() &&
434 owner->currentBuffer()->isReadonly() &&
435 lyxaction.isFuncRO(action)) {
436 setErrorMessage(N_("Document is read-only"));
437 lyxerr.debug() << "Error: Document is read-only." << endl;
438 goto exit_with_message;
441 // If in math mode pass the control to
442 // the math inset [asierra060396]
443 if (owner->currentView()->available() &&
444 owner->currentBuffer()->the_locking_inset) {
445 if (action>1 || (action==LFUN_UNKNOWN_ACTION && keyseq.length>=-1)) {
446 if (action==LFUN_UNKNOWN_ACTION && argument.empty()) {
447 argument = keyseq.getiso();
449 // Undo/Redo pre 0.13 is a bit tricky for insets.
450 if (action==LFUN_UNDO) {
452 UpdatableInset* inset =
453 owner->currentBuffer()->the_locking_inset;
454 inset->GetCursorPos(slx, sly);
457 inset = (UpdatableInset*)owner->currentBuffer()->text->cursor.par->GetInset(owner->currentBuffer()->text->cursor.pos);
459 inset->Edit(slx, sly);
462 if (action==LFUN_REDO) {
464 UpdatableInset* inset = owner->currentBuffer()->the_locking_inset;
465 inset->GetCursorPos(slx, sly);
468 inset = (UpdatableInset*)owner->currentBuffer()->text->cursor.par->GetInset(owner->currentBuffer()->text->cursor.pos);
470 inset->Edit(slx, sly);
473 if (owner->currentBuffer()->the_locking_inset->LocalDispatch(action, argument.c_str()))
476 setMessage(N_("Text mode"));
477 if (action==LFUN_RIGHT || action==-1)
478 owner->currentBuffer()->text->CursorRight();
479 if (action==LFUN_LEFT || action==LFUN_RIGHT)
486 // --- Misc -------------------------------------------
487 case LFUN_WORDFINDFORWARD :
488 case LFUN_WORDFINDBACKWARD : {
490 static string last_search;
491 string searched_string;
493 if (!argument.empty()) {
494 last_search = argument;
495 searched_string = argument;
497 searched_string = last_search;
500 ltCur = owner->currentView()->currentBuffer()->text ;
502 if (!searched_string.empty() &&
503 ( (action == LFUN_WORDFINDBACKWARD) ?
504 ltCur->SearchBackward( searched_string.c_str() ) :
505 ltCur->SearchForward( searched_string.c_str() )
508 // ??? What is that ???
509 owner->currentView()->currentBuffer()->update(-2);
512 // clear the selection (if there is any)
513 owner->currentView()->getScreen()->ToggleSelection();
514 owner->currentView()->currentBuffer()->text->ClearSelection();
516 // Move cursor so that successive C-s 's will not stand in place.
517 if( action == LFUN_WORDFINDFORWARD )
518 owner->currentBuffer()->text->CursorRightOneWord();
519 owner->currentBuffer()->text->FinishUndo();
520 moveCursorUpdate(false);
523 // set the new selection
524 // SetSelectionOverLenChars(owner->currentView()->currentBuffer()->text, iLenSelected);
525 owner->currentView()->getScreen()->ToggleSelection(false);
529 // REMOVED : if (owner->currentView()->getWorkArea()->focus)
530 owner->currentView()->getScreen()->ShowCursor();
536 if (owner->currentView()->available()
537 && owner->currentView()->getScreen()) {
538 owner->currentBuffer()->update(-2);
541 keyseq.print(buf,100, true);
542 owner->getMiniBuffer()->Set(buf, string(), string(), 1);
546 // --- Misc -------------------------------------------
547 case LFUN_EXEC_COMMAND:
548 owner->getMiniBuffer()->ExecCommand();
551 case LFUN_CANCEL: // RVDK_PATCH_5
554 if(owner->currentView()->available())
555 // cancel any selection
556 Dispatch(int(LFUN_MARK_OFF), 0);
557 setMessage(N_("Cancel"));
560 case LFUN_META_FAKE: // RVDK_PATCH_5
562 meta_fake_bit = Mod1Mask;
564 keyseq.print(buf, 98, true);
565 string res = string("M-") + buf;
566 setMessage(buf); // RVDK_PATCH_5
570 case LFUN_READ_ONLY_TOGGLE:
571 if (owner->currentBuffer()->lyxvc.inUse()) {
572 owner->currentBuffer()->lyxvc.toggleReadOnly();
574 owner->currentBuffer()->setReadonly(
575 !owner->currentBuffer()->isReadonly());
579 case LFUN_CENTER: // this is center and redraw.
581 if (owner->currentBuffer()->text->cursor.y >
582 owner->currentView()->getWorkArea()->h / 2) {
583 owner->currentView()->getScreen()->
584 Draw(owner->currentBuffer()->text->cursor.y -
585 owner->currentView()->getWorkArea()->h/2);
587 owner->currentView()->getScreen()->
590 owner->currentBuffer()->update(0);
591 owner->currentView()->redraw();
595 if (owner->currentView()->available()) {
596 owner->currentBuffer()->text->toggleAppendix();
597 owner->currentBuffer()->update(1);
601 // --- Menus -----------------------------------------------
606 case LFUN_MENUNEWTMPLT:
614 case LFUN_CLOSEBUFFER:
619 MenuWrite(owner->currentBuffer());
622 case LFUN_MENUWRITEAS:
623 MenuWriteAs(owner->currentBuffer());
626 case LFUN_MENURELOAD:
631 MenuPreview(owner->currentBuffer());
635 MenuPreviewPS(owner->currentBuffer());
639 MenuRunLaTeX(owner->currentBuffer());
643 MenuBuildProg(owner->currentBuffer());
647 MenuRunChktex(owner->currentBuffer());
651 MenuRunDvips(owner->currentBuffer(), false);
655 MenuPrint(owner->currentBuffer());
659 MenuFax(owner->currentBuffer());
664 //needs argument as string
665 string extyp=argument;
668 if (extyp == "latex") {
669 // make sure that this buffer is not linuxdoc
670 MenuMakeLaTeX(owner->currentBuffer());
673 else if (extyp == "linuxdoc") {
674 // make sure that this buffer is not latex
675 MenuMakeLinuxDoc(owner->currentBuffer());
678 else if (extyp == "docbook") {
679 // make sure that this buffer is not latex or linuxdoc
680 MenuMakeDocBook(owner->currentBuffer());
683 else if (extyp == "dvi") {
684 // Run LaTeX as "Update dvi..." Bernhard.
685 // We want the dvi in the current directory. This
686 // is achieved by temporarily disabling use of
687 // temp directory. As a side-effect, we get
688 // *.log and *.aux files also. (Asger)
689 bool flag = lyxrc->use_tempdir;
690 lyxrc->use_tempdir = false;
691 MenuRunLaTeX(owner->currentBuffer());
692 lyxrc->use_tempdir = flag;
695 else if (extyp == "postscript") {
696 // Start Print-dialog. Not as good as dvi... Bernhard.
697 MenuPrint(owner->currentBuffer());
698 // Since the MenuPrint is a pop-up, we can't use
699 // the same trick as above. (Asger)
700 // MISSING: Move of ps-file :-(
703 else if (extyp == "ascii") {
704 MenuMakeAscii(owner->currentBuffer());
706 else if (extyp == "custom") {
711 else if (extyp == "html") {
712 // First, create LaTeX file
713 MenuMakeLaTeX(owner->currentBuffer());
716 string file = owner->currentBuffer()->getFileName();
717 file = ChangeExtension(file, ".tex", false);
718 string result = ChangeExtension(file, ".html", false);
719 string tmp = lyxrc->tth_command + " < " + file
722 int res = one.startscript(Systemcalls::System, tmp);
725 _("Document exported as HTML to file: ")) + result);
727 setErrorMessage(string(
728 _("An unexpected error occured while converting document to HTML in file:")) + result);
732 setErrorMessage(string(_("Unknown export type: "))
740 //needs argument as string
741 string imtyp=argument;
744 if (imtyp == "latex") {
745 doImportLaTeX(false);
748 else if (imtyp == "ascii") {
749 doImportASCII(false);
750 } else if (imtyp == "asciiparagraph") {
753 } else if (imtyp == "noweb") {
756 setErrorMessage(string(N_("Unknown import type: "))
768 if (fd_form_toc->form_toc->visible) {
769 fl_raise_form(fd_form_toc->form_toc);
771 static int ow = -1, oh;
772 fl_show_form(fd_form_toc->form_toc,
774 FL_FREE_SIZE, FL_FULLBORDER,
775 _("Table of Contents"));
777 ow = fd_form_toc->form_toc->w;
778 oh = fd_form_toc->form_toc->h;
780 fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
784 case LFUN_TOC_INSERT:
787 new InsetTOC(owner->currentBuffer());
788 owner->currentBuffer()->insertInset(new_inset,
793 case LFUN_LOF_INSERT:
796 new InsetLOF(owner->currentBuffer());
797 owner->currentBuffer()->insertInset(new_inset,
802 case LFUN_LOA_INSERT:
805 new InsetLOA(owner->currentBuffer());
806 owner->currentBuffer()->insertInset(new_inset,
811 case LFUN_LOT_INSERT:
814 new InsetLOT(owner->currentBuffer());
815 owner->currentBuffer()->insertInset(new_inset,
840 case LFUN_MENUSEARCH:
848 case LFUN_PASTESELECTION:
851 if (string(argument) == "paragraph") asPara = true;
852 MenuPasteSelection(asPara);
864 case LFUN_LAYOUT_COPY:
868 case LFUN_LAYOUT_PASTE:
869 PasteEnvironmentCB();
873 owner->currentView()->gotoError();
876 case LFUN_REMOVEERRORS:
877 if (owner->currentBuffer()->removeAutoInsets()) {
878 owner->currentView()->redraw();
879 owner->currentView()->fitCursor();
880 owner->currentView()->updateScrollbar();
892 case LFUN_HYPHENATION:
900 case LFUN_END_OF_SENTENCE:
904 case LFUN_MENU_SEPARATOR:
920 case LFUN_DEPTH_PLUS:
936 case LFUN_RECONFIGURE:
941 if (owner->currentView()->available()
942 && !owner->currentBuffer()->text->selection
943 && owner->currentBuffer()->text->cursor.par->footnoteflag
944 != LyXParagraph::NO_FOOTNOTE)
945 { // only melt footnotes with FOOTMELT, not margins etc
946 if(owner->currentBuffer()->text->cursor.par->footnotekind == LyXParagraph::FOOTNOTE)
953 case LFUN_MARGINMELT:
954 if (owner->currentView()->available()
955 && !owner->currentBuffer()->text->selection
956 && owner->currentBuffer()->text->cursor.par->footnoteflag
957 != LyXParagraph::NO_FOOTNOTE)
958 { // only melt margins
959 if(owner->currentBuffer()->text->cursor.par->footnotekind == LyXParagraph::MARGIN)
966 // --- version control -------------------------------
967 case LFUN_VC_REGISTER:
969 if (!owner->currentBuffer()->lyxvc.inUse())
970 owner->currentBuffer()->lyxvc.registrer();
974 case LFUN_VC_CHECKIN:
976 if (owner->currentBuffer()->lyxvc.inUse()
977 && !owner->currentBuffer()->isReadonly())
978 owner->currentBuffer()->lyxvc.checkIn();
982 case LFUN_VC_CHECKOUT:
984 if (owner->currentBuffer()->lyxvc.inUse()
985 && owner->currentBuffer()->isReadonly())
986 owner->currentBuffer()->lyxvc.checkOut();
992 owner->currentBuffer()->lyxvc.revert();
998 owner->currentBuffer()->lyxvc.undoLast();
1002 case LFUN_VC_HISTORY:
1004 owner->currentBuffer()->lyxvc.showLog();
1008 // --- buffers ----------------------------------------
1009 case LFUN_PREVBUFFER:
1010 #ifdef WITH_WARNINGS
1011 #warning fix this please
1013 // it is the LyXView or the BufferView that should
1014 // remember the previous buffer, not bufferlist.
1015 // if (owner->currentView()->available()){
1017 // owner->currentBuffer()->update(-2);
1019 // owner->currentView()->setBuffer(bufferlist.prev());
1021 // owner->currentView()->
1022 // resizeCurrentBufferPseudoExpose();
1025 case LFUN_FILE_INSERT:
1027 MenuInsertLyXFile(argument);
1031 case LFUN_FILE_INSERT_ASCII:
1033 bool asPara = false;
1034 asPara = (string(argument) == "paragraph");
1035 InsertAsciiFile(string(), asPara);
1041 // servercmd: argument must be <file>:<template>
1042 Buffer * tmpbuf = 0;
1043 tmpbuf = NewLyxFile(argument);
1045 owner->currentView()->setBuffer(tmpbuf);
1049 case LFUN_FILE_OPEN:
1050 owner->currentView()->setBuffer(
1051 bufferlist.loadLyXFile(argument));
1054 case LFUN_LATEX_LOG:
1060 lyxerr.debug() << "LFUN_LAYOUTNO: (arg) " << argument << endl;
1061 int sel = strToInt(argument);
1062 lyxerr.debug() << "LFUN_LAYOUTNO: (sel) "<< sel << endl;
1064 // Should this give a setMessage instead?
1066 return string(); // illegal argument
1068 sel--; // sel 1..., but layout 0...
1070 // Pretend we got the name instead.
1071 Dispatch(int(LFUN_LAYOUT),
1072 textclasslist.NameOfLayout(owner->currentBuffer()->
1081 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1082 << argument << endl;
1084 // Derive layout number from given argument (string)
1085 // and current buffer's textclass (number). */
1088 textclasslist.NumberOfLayout(owner->
1094 // see if we found the layout number:
1095 if (layoutno == -1) {
1096 setErrorMessage(string(N_("Layout ")) + argument +
1101 if (current_layout != layoutno) {
1102 owner->currentView()->getScreen()->HideCursor();
1103 current_layout = layoutno;
1104 owner->currentBuffer()->update(-2);
1105 owner->currentBuffer()->text->
1106 SetLayout(layoutno);
1107 owner->getToolbar()->combox->
1108 select(owner->currentBuffer()->
1111 owner->currentBuffer()->update(1);
1116 case LFUN_LAYOUT_DOCUMENT:
1117 MenuLayoutDocument();
1120 case LFUN_LAYOUT_PARAGRAPH:
1121 MenuLayoutParagraph();
1124 case LFUN_LAYOUT_CHARACTER:
1125 MenuLayoutCharacter();
1128 case LFUN_LAYOUT_TABLE:
1131 if (string(argument) == "true") flag = 1;
1132 MenuLayoutTable(flag);
1136 case LFUN_LAYOUT_PAPER:
1140 case LFUN_LAYOUT_QUOTES:
1144 case LFUN_LAYOUT_PREAMBLE:
1145 MenuLayoutPreamble();
1148 case LFUN_LAYOUT_SAVE_DEFAULT:
1152 case LFUN_DROP_LAYOUTS_CHOICE:
1153 owner->getToolbar()->combox->Show();
1184 case LFUN_UNDERLINE:
1188 case LFUN_FONT_SIZE:
1189 FontSizeCB(argument);
1192 case LFUN_FONT_STATE:
1193 setMessage(CurrentState());
1196 case LFUN_UPCASE_WORD:
1197 owner->currentBuffer()->update(-2);
1199 owner->currentBuffer()->text->ChangeWordCase(LyXText::text_uppercase);
1200 owner->currentBuffer()->update(1);
1204 case LFUN_LOWCASE_WORD:
1205 owner->currentBuffer()->update(-2);
1207 owner->currentBuffer()->text->ChangeWordCase(LyXText::text_lowercase);
1208 owner->currentBuffer()->update(1);
1212 case LFUN_CAPITALIZE_WORD:
1213 owner->currentBuffer()->update(-2);
1215 owner->currentBuffer()->text->ChangeWordCase(LyXText::text_capitalization);
1216 owner->currentBuffer()->update(1);
1220 case LFUN_INSERT_LABEL:
1221 MenuInsertLabel(argument.c_str());
1224 case LFUN_INSERT_REF:
1228 case LFUN_REFTOGGLE:
1231 (InsetRef*)getInsetByCode(Inset::REF_CODE);
1233 if (inset->getFlag()==InsetRef::REF)
1234 inset->setFlag(InsetRef::PAGE_REF);
1236 inset->setFlag(InsetRef::REF);
1239 setErrorMessage(N_("No cross-reference to toggle"));
1246 owner->currentView()->restorePosition();
1252 string label(argument);
1253 if (label.empty()) {
1255 (InsetRef*)getInsetByCode(Inset::REF_CODE);
1257 label = inset->getContents();
1260 if (!label.empty()) {
1261 owner->currentView()->savePosition();
1262 owner->currentBuffer()->gotoLabel(label.c_str());
1267 case LFUN_MENU_OPEN_BY_NAME:
1268 owner->getMenus()->openByName(argument);
1269 break; // RVDK_PATCH_5
1271 case LFUN_SPELLCHECK:
1272 if (lyxrc->isp_command != "none")
1274 break; // RVDK_PATCH_5
1276 // --- Cursor Movements -----------------------------
1279 Buffer *tmpbuffer = owner->currentBuffer();
1280 LyXText *tmptext = owner->currentBuffer()->text;
1281 if(!tmptext->mark_set)
1283 tmpbuffer->update(-2);
1284 if (tmptext->cursor.pos < tmptext->cursor.par->Last()
1285 && tmptext->cursor.par->GetChar(tmptext->cursor.pos)
1287 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)
1288 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)->Editable()==2){
1289 Inset* tmpinset = tmptext->cursor.par->GetInset(tmptext->cursor.pos);
1290 setMessage(tmpinset->EditMessage());
1291 tmpinset->Edit(0,0);
1294 tmptext->CursorRight();
1295 owner->currentBuffer()->text->FinishUndo();
1296 moveCursorUpdate(false);
1297 owner->getMiniBuffer()->Set(CurrentState());
1303 // This is soooo ugly. Isn`t it possible to make
1304 // it simpler? (Lgb)
1305 LyXText *txt= owner->currentBuffer()->text;
1306 if(!txt->mark_set) BeforeChange();
1307 owner->currentBuffer()->update(-2);
1309 if (txt->cursor.pos < txt->cursor.par->Last()
1310 && txt->cursor.par->GetChar(txt->cursor.pos)
1312 && txt->cursor.par->GetInset(txt->cursor.pos)
1313 && txt->cursor.par->GetInset(txt->cursor.pos)->Editable()==2) {
1314 Inset* tmpinset = txt->cursor.par->GetInset(txt->cursor.pos);
1315 setMessage(tmpinset->EditMessage());
1316 tmpinset->Edit(tmpinset->Width(txt->GetFont(txt->cursor.par,
1317 txt->cursor.pos)),0);
1318 // tmpinset->Edit(-1, 0); // -1 means go rightmost
1321 owner->currentBuffer()->text->FinishUndo();
1322 moveCursorUpdate(false);
1323 owner->getMiniBuffer()->Set(CurrentState());
1328 if(!owner->currentBuffer()->text->mark_set) BeforeChange();
1329 owner->currentBuffer()->update(-3);
1330 owner->currentBuffer()->text->CursorUp();
1331 owner->currentBuffer()->text->FinishUndo();
1332 moveCursorUpdate(false);
1333 owner->getMiniBuffer()->Set(CurrentState());
1337 if(!owner->currentBuffer()->text->mark_set)
1339 owner->currentBuffer()->update(-3);
1340 owner->currentBuffer()->text->CursorDown();
1341 owner->currentBuffer()->text->FinishUndo();
1342 moveCursorUpdate(false);
1343 owner->getMiniBuffer()->Set(CurrentState());
1346 case LFUN_UP_PARAGRAPH:
1347 if(!owner->currentBuffer()->text->mark_set)
1349 owner->currentBuffer()->update(-3);
1350 owner->currentBuffer()->text->CursorUpParagraph();
1351 owner->currentBuffer()->text->FinishUndo();
1352 moveCursorUpdate(false);
1353 owner->getMiniBuffer()->Set(CurrentState());
1356 case LFUN_DOWN_PARAGRAPH:
1357 if(!owner->currentBuffer()->text->mark_set)
1359 owner->currentBuffer()->update(-3);
1360 owner->currentBuffer()->text->CursorDownParagraph();
1361 owner->currentBuffer()->text->FinishUndo();
1362 moveCursorUpdate(false);
1363 owner->getMiniBuffer()->Set(CurrentState());
1367 if(!owner->currentBuffer()->text->mark_set)
1369 owner->currentBuffer()->update(-3);
1370 owner->currentView()->cursorPrevious();
1371 owner->currentBuffer()->text->FinishUndo();
1372 moveCursorUpdate(false);
1373 owner->getMiniBuffer()->Set(CurrentState());
1377 if(!owner->currentBuffer()->text->mark_set)
1379 owner->currentBuffer()->update(-3);
1380 owner->currentView()->cursorNext();
1381 owner->currentBuffer()->text->FinishUndo();
1382 moveCursorUpdate(false);
1383 owner->getMiniBuffer()->Set(CurrentState());
1387 if(!owner->currentBuffer()->text->mark_set)
1389 owner->currentBuffer()->update(-2);
1390 owner->currentBuffer()->text->CursorHome();
1391 owner->currentBuffer()->text->FinishUndo();
1392 moveCursorUpdate(false);
1393 owner->getMiniBuffer()->Set(CurrentState());
1397 if(!owner->currentBuffer()->text->mark_set)
1399 owner->currentBuffer()->update(-2);
1400 owner->currentBuffer()->text->CursorEnd();
1401 owner->currentBuffer()->text->FinishUndo();
1402 moveCursorUpdate(false);
1403 owner->getMiniBuffer()->Set(CurrentState());
1407 if(!owner->currentBuffer()->text->mark_set)
1409 owner->currentBuffer()->update(-2);
1410 owner->currentBuffer()->text->CursorTab();
1411 owner->currentBuffer()->text->FinishUndo();
1412 moveCursorUpdate(false);
1413 owner->getMiniBuffer()->Set(CurrentState());
1416 case LFUN_WORDRIGHT:
1417 if(!owner->currentBuffer()->text->mark_set)
1419 owner->currentBuffer()->update(-2);
1420 owner->currentBuffer()->text->CursorRightOneWord();
1421 owner->currentBuffer()->text->FinishUndo();
1422 moveCursorUpdate(false);
1423 owner->getMiniBuffer()->Set(CurrentState());
1427 if(!owner->currentBuffer()->text->mark_set)
1429 owner->currentBuffer()->update(-2);
1430 owner->currentBuffer()->text->CursorLeftOneWord();
1431 owner->currentBuffer()->text->FinishUndo();
1432 moveCursorUpdate(false);
1433 owner->getMiniBuffer()->Set(CurrentState());
1436 case LFUN_BEGINNINGBUF:
1437 if(!owner->currentBuffer()->text->mark_set)
1439 owner->currentBuffer()->update(-2);
1440 owner->currentBuffer()->text->CursorTop();
1441 owner->currentBuffer()->text->FinishUndo();
1442 moveCursorUpdate(false);
1443 owner->getMiniBuffer()->Set(CurrentState());
1447 if(!owner->currentBuffer()->text->mark_set)
1449 owner->currentBuffer()->update(-2);
1450 owner->currentBuffer()->text->CursorBottom();
1451 owner->currentBuffer()->text->FinishUndo();
1452 moveCursorUpdate(false);
1453 owner->getMiniBuffer()->Set(CurrentState());
1457 /* cursor selection ---------------------------- */
1459 owner->currentBuffer()->update(-2);
1460 owner->currentBuffer()->text->CursorRight();
1461 owner->currentBuffer()->text->FinishUndo();
1462 moveCursorUpdate(true);
1463 owner->getMiniBuffer()->Set(CurrentState());
1467 owner->currentBuffer()->update(-2);
1468 owner->currentBuffer()->text->CursorLeft();
1469 owner->currentBuffer()->text->FinishUndo();
1470 moveCursorUpdate(true);
1471 owner->getMiniBuffer()->Set(CurrentState());
1475 owner->currentBuffer()->update(-2);
1476 owner->currentBuffer()->text->CursorUp();
1477 owner->currentBuffer()->text->FinishUndo();
1478 moveCursorUpdate(true);
1479 owner->getMiniBuffer()->Set(CurrentState());
1483 owner->currentBuffer()->update(-2);
1484 owner->currentBuffer()->text->CursorDown();
1485 owner->currentBuffer()->text->FinishUndo();
1486 moveCursorUpdate(true);
1487 owner->getMiniBuffer()->Set(CurrentState());
1490 case LFUN_UP_PARAGRAPHSEL:
1491 owner->currentBuffer()->update(-2);
1492 owner->currentBuffer()->text->CursorUpParagraph();
1493 owner->currentBuffer()->text->FinishUndo();
1494 moveCursorUpdate(true);
1495 owner->getMiniBuffer()->Set(CurrentState());
1498 case LFUN_DOWN_PARAGRAPHSEL:
1499 owner->currentBuffer()->update(-2);
1500 owner->currentBuffer()->text->CursorDownParagraph();
1501 owner->currentBuffer()->text->FinishUndo();
1502 moveCursorUpdate(true);
1503 owner->getMiniBuffer()->Set(CurrentState());
1507 owner->currentBuffer()->update(-2);
1508 owner->currentView()->cursorPrevious();
1509 owner->currentBuffer()->text->FinishUndo();
1510 moveCursorUpdate(true);
1511 owner->getMiniBuffer()->Set(CurrentState());
1515 owner->currentBuffer()->update(-2);
1516 owner->currentView()->cursorNext();
1517 owner->currentBuffer()->text->FinishUndo();
1518 moveCursorUpdate(true);
1519 owner->getMiniBuffer()->Set(CurrentState());
1523 owner->currentBuffer()->update(-2);
1524 owner->currentBuffer()->text->CursorHome();
1525 owner->currentBuffer()->text->FinishUndo();
1526 moveCursorUpdate(true);
1527 owner->getMiniBuffer()->Set(CurrentState());
1531 owner->currentBuffer()->update(-2);
1532 owner->currentBuffer()->text->CursorEnd();
1533 owner->currentBuffer()->text->FinishUndo();
1534 moveCursorUpdate(true);
1535 owner->getMiniBuffer()->Set(CurrentState());
1538 case LFUN_WORDRIGHTSEL:
1539 owner->currentBuffer()->update(-2);
1540 owner->currentBuffer()->text->CursorRightOneWord();
1541 owner->currentBuffer()->text->FinishUndo();
1542 moveCursorUpdate(true);
1543 owner->getMiniBuffer()->Set(CurrentState());
1546 case LFUN_WORDLEFTSEL:
1547 owner->currentBuffer()->update(-2);
1548 owner->currentBuffer()->text->CursorLeftOneWord();
1549 owner->currentBuffer()->text->FinishUndo();
1550 moveCursorUpdate(true);
1551 owner->getMiniBuffer()->Set(CurrentState());
1554 case LFUN_BEGINNINGBUFSEL:
1555 owner->currentBuffer()->update(-2);
1556 owner->currentBuffer()->text->CursorTop();
1557 owner->currentBuffer()->text->FinishUndo();
1558 moveCursorUpdate(true);
1559 owner->getMiniBuffer()->Set(CurrentState());
1562 case LFUN_ENDBUFSEL:
1563 owner->currentBuffer()->update(-2);
1564 owner->currentBuffer()->text->CursorBottom();
1565 owner->currentBuffer()->text->FinishUndo();
1566 moveCursorUpdate(true);
1567 owner->getMiniBuffer()->Set(CurrentState());
1570 // --- text changing commands ------------------------
1571 case LFUN_BREAKLINE:
1573 owner->currentBuffer()->text->InsertChar(LYX_META_NEWLINE);
1575 SetUpdateTimer(0.01);
1576 moveCursorUpdate(false);
1579 case LFUN_PROTECTEDSPACE:
1581 owner->currentBuffer()->text->
1582 InsertChar(LYX_META_PROTECTED_SEPARATOR);
1585 moveCursorUpdate(false);
1589 if(owner->currentBuffer()->text->mark_set) {
1591 owner->currentBuffer()->update(0);
1592 setMessage(N_("Mark removed"));
1595 owner->currentBuffer()->text->mark_set = 1;
1596 owner->currentBuffer()->update(0);
1597 setMessage(N_("Mark set"));
1599 owner->currentBuffer()->text->sel_cursor =
1600 owner->currentBuffer()->text->cursor;
1605 if (!owner->currentBuffer()->text->selection) {
1606 owner->currentBuffer()->text->Delete();
1607 owner->currentBuffer()->text->sel_cursor =
1608 owner->currentBuffer()->text->cursor;
1610 // It is possible to make it a lot faster still
1611 // just comment out the lone below...
1612 owner->currentView()->getScreen()->ShowCursor();
1619 case LFUN_DELETE_SKIP:
1621 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1623 LyXCursor cursor = owner->currentBuffer()->text->cursor;
1626 if (!owner->currentBuffer()->text->selection) {
1627 if (cursor.pos == cursor.par->Last()) {
1628 owner->currentBuffer()->text->CursorRight();
1629 cursor = owner->currentBuffer()->text->cursor;
1631 && !(cursor.par->added_space_top
1632 == VSpace (VSpace::NONE))) {
1633 owner->currentBuffer()->text->SetParagraph
1634 (cursor.par->line_top,
1635 cursor.par->line_bottom,
1636 cursor.par->pagebreak_top,
1637 cursor.par->pagebreak_bottom,
1638 VSpace(VSpace::NONE),
1639 cursor.par->added_space_bottom,
1641 cursor.par->labelwidthstring, 0);
1642 owner->currentBuffer()->text->CursorLeft();
1643 owner->currentBuffer()->update (1);
1645 owner->currentBuffer()->text->CursorLeft();
1646 owner->currentBuffer()->text->Delete();
1647 owner->currentBuffer()->text->sel_cursor =
1648 owner->currentBuffer()->text->cursor;
1652 owner->currentBuffer()->text->Delete();
1653 owner->currentBuffer()->text->sel_cursor =
1654 owner->currentBuffer()->text->cursor;
1664 /* -------> Delete word forward. */
1665 case LFUN_DELETE_WORD_FORWARD:
1666 owner->currentBuffer()->update(-2);
1668 owner->currentBuffer()->text->DeleteWordForward();
1669 owner->currentBuffer()->update( 1 );
1671 moveCursorUpdate(false);
1674 /* -------> Delete word backward. */
1675 case LFUN_DELETE_WORD_BACKWARD:
1676 owner->currentBuffer()->update(-2);
1678 owner->currentBuffer()->text->DeleteWordBackward();
1679 owner->currentBuffer()->update( 1 );
1681 moveCursorUpdate(false);
1684 /* -------> Kill to end of line. */
1685 case LFUN_DELETE_LINE_FORWARD:
1687 owner->currentBuffer()->update(-2);
1688 owner->currentBuffer()->text->DeleteLineForward();
1689 owner->currentBuffer()->update( 1 );
1691 moveCursorUpdate(false);
1694 /* -------> Set mark off. */
1697 owner->currentBuffer()->update(0);
1698 owner->currentBuffer()->text->sel_cursor =
1699 owner->currentBuffer()->text->cursor;
1700 setMessage(N_("Mark off"));
1703 /* -------> Set mark on. */
1706 owner->currentBuffer()->text->mark_set = 1;
1707 owner->currentBuffer()->update( 0 );
1708 owner->currentBuffer()->text->sel_cursor =
1709 owner->currentBuffer()->text->cursor;
1710 setMessage(N_("Mark on"));
1713 case LFUN_BACKSPACE:
1716 if (!owner->currentBuffer()->text->selection) {
1717 if (owner->getIntl()->getTrans()->backspace()) {
1718 owner->currentBuffer()->text->Backspace();
1719 owner->currentBuffer()->text->sel_cursor =
1720 owner->currentBuffer()->text->cursor;
1722 // It is possible to make it a lot faster still
1723 // just comment out the lone below...
1724 owner->currentView()->getScreen()->ShowCursor();
1733 case LFUN_BACKSPACE_SKIP:
1735 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1737 LyXCursor cursor = owner->currentBuffer()->text->cursor;
1740 if (!owner->currentBuffer()->text->selection) {
1742 && !(cursor.par->added_space_top
1743 == VSpace (VSpace::NONE))) {
1744 owner->currentBuffer()->text->SetParagraph
1745 (cursor.par->line_top,
1746 cursor.par->line_bottom,
1747 cursor.par->pagebreak_top,
1748 cursor.par->pagebreak_bottom,
1749 VSpace(VSpace::NONE), cursor.par->added_space_bottom,
1751 cursor.par->labelwidthstring, 0);
1752 owner->currentBuffer()->update (1);
1754 owner->currentBuffer()->text->Backspace();
1755 owner->currentBuffer()->text->sel_cursor
1765 case LFUN_BREAKPARAGRAPH:
1768 owner->currentBuffer()->text->BreakParagraph(0);
1770 SetUpdateTimer(0.01);
1771 owner->currentBuffer()->text->sel_cursor =
1772 owner->currentBuffer()->text->cursor;
1776 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1779 owner->currentBuffer()->text->BreakParagraph(1);
1781 SetUpdateTimer(0.01);
1782 owner->currentBuffer()->text->sel_cursor =
1783 owner->currentBuffer()->text->cursor;
1787 case LFUN_BREAKPARAGRAPH_SKIP:
1789 // When at the beginning of a paragraph, remove
1790 // indentation and add a "defskip" at the top.
1791 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
1793 LyXCursor cursor = owner->currentBuffer()->text->cursor;
1796 if (cursor.pos == 0) {
1797 if (cursor.par->added_space_top == VSpace(VSpace::NONE)) {
1798 owner->currentBuffer()->text->SetParagraph
1799 (cursor.par->line_top,
1800 cursor.par->line_bottom,
1801 cursor.par->pagebreak_top,
1802 cursor.par->pagebreak_bottom,
1803 VSpace(VSpace::DEFSKIP), cursor.par->added_space_bottom,
1805 cursor.par->labelwidthstring, 1);
1806 owner->currentBuffer()->update(1);
1810 owner->currentBuffer()->text->BreakParagraph(0);
1813 SetUpdateTimer(0.01);
1814 owner->currentBuffer()->text->sel_cursor = cursor;
1820 owner->currentBuffer()->text->InsertChar('\"'); // This " matches the single quote in the code
1823 moveCursorUpdate(false);
1829 InsetCommand *new_inset;
1830 if (action == LFUN_HTMLURL)
1831 new_inset = new InsetUrl("htmlurl", "", "");
1833 new_inset = new InsetUrl("url", "", "");
1834 owner->currentBuffer()->insertInset(new_inset);
1835 new_inset->Edit(0, 0);
1839 // --- lyxserver commands ----------------------------
1841 case LFUN_CHARATCURSOR:
1844 LyXParagraph::size_type pos =
1845 owner->currentBuffer()->text->cursor.pos;
1846 if(pos < owner->currentBuffer()->text->cursor.par->size())
1848 int pos = owner->currentBuffer()->text->cursor.pos;
1849 if(pos < owner->currentBuffer()->text->cursor.par->last)
1851 dispatch_buffer = owner->currentBuffer()->text->
1852 cursor.par->text[pos];
1854 dispatch_buffer = "EOF";
1860 tostr(owner->currentBuffer()->text->cursor.x) + ' '
1861 + tostr(owner->currentBuffer()->text->cursor.y);
1868 sscanf(argument.c_str(), " %d %ld", &x, &y);
1869 owner->currentBuffer()->text->SetCursorFromCoordinates(x, y);
1873 case LFUN_GETLAYOUT:
1875 tostr(owner->currentBuffer()->text->cursor.par->layout);
1880 LyXFont *font = &(owner->currentBuffer()->text->current_font);
1881 if(font->shape() == LyXFont::ITALIC_SHAPE)
1882 dispatch_buffer = 'E';
1883 else if(font->shape() == LyXFont::SMALLCAPS_SHAPE)
1884 dispatch_buffer = 'N';
1886 dispatch_buffer = '0';
1893 LyXFont *font = &(owner->currentBuffer()->text->current_font);
1894 if(font->latex() == LyXFont::ON)
1895 dispatch_buffer = 'L';
1897 dispatch_buffer = '0';
1902 setMessage(owner->currentBuffer()->getFileName());
1903 lyxerr.debug() << "FNAME["
1904 << owner->currentBuffer()->getFileName()
1911 keyseq.print(buf,100);
1912 dispatch_buffer = buf;
1913 lyxserver->notifyClient(dispatch_buffer);
1917 case LFUN_GOTOFILEROW:
1919 char file_name[100];
1921 sscanf(argument.c_str(), " %s %d", file_name, &row);
1923 // Must replace extension of the file to be .lyx and get full path
1924 string s = ChangeExtension(string(file_name), ".lyx", false);
1926 // Either change buffer or load the file
1927 if (bufferlist.exists(s))
1928 owner->currentView()->setBuffer(bufferlist.getBuffer(s));
1930 owner->currentView()->setBuffer(bufferlist.loadLyXFile(s));
1933 owner->currentBuffer()->setCursorFromRow(row);
1937 if (owner->currentBuffer()->text->cursor.y >
1938 owner->currentView()->getWorkArea()->h / 2) {
1939 owner->currentView()->getScreen()->
1940 Draw(owner->currentBuffer()->text->cursor.y -
1941 owner->currentView()->getWorkArea()->h/2);
1943 owner->currentView()->getScreen()->
1946 owner->currentBuffer()->update(0);
1947 owner->currentView()->redraw();
1954 int qa = lyxaction.LookupFunc(argument.c_str());
1955 setMessage(lyxaction.helpText((kb_action)qa));
1959 // --- accented characters ---------------------------
1962 case LFUN_CIRCUMFLEX:
1972 case LFUN_SPECIAL_CARON:
1975 case LFUN_HUNG_UMLAUT:
1981 if (keyseq.length==-1 && keyseq.getiso()!=0)
1986 owner->getIntl()->getTrans()->
1987 deadkey(c, get_accent(action).accent,
1988 owner->currentBuffer()->text);
1990 // Need to reset, in case the minibuffer calls these
1995 // copied verbatim from do_accent_char
1998 owner->currentBuffer()->text->sel_cursor =
1999 owner->currentBuffer()->text->cursor;
2003 // --- toolbar ----------------------------------
2004 case LFUN_PUSH_TOOLBAR:
2006 int nth = strToInt(argument);
2007 if (lyxerr.debugging(Debug::TOOLBAR)) {
2008 lyxerr << "LFUN_PUSH_TOOLBAR: argument = `"
2009 << argument << "'\n"
2010 << "LFUN_PUSH_TOOLBAR: nth = `"
2011 << nth << "'" << endl;
2016 setErrorMessage(N_("Push-toolbar needs argument > 0"));
2018 owner->getToolbar()->push(nth);
2023 case LFUN_ADD_TO_TOOLBAR:
2025 if (lyxerr.debugging(Debug::TOOLBAR)) {
2026 lyxerr << "LFUN_ADD_TO_TOOLBAR:"
2027 "argument = `" << argument << '\'' << endl;
2029 string tmp(argument);
2030 //lyxerr <<string("Argument: ") + argument);
2031 //lyxerr <<string("Tmp : ") + tmp);
2034 setErrorMessage(N_("Usage: toolbar-add-to <LyX command>"));
2036 owner->getToolbar()->add(argument, false);
2037 owner->getToolbar()->set();
2042 // --- insert characters ----------------------------------------
2044 case LFUN_INSERT_INSET_LATEX:
2046 Inset *new_inset = new InsetLatex(argument);
2047 owner->currentBuffer()->insertInset(new_inset);
2051 // --- Mathed stuff. If we are here, there is no locked inset yet.
2056 if (!greek_kb_flag) {
2058 setMessage(N_("Math greek mode on"));
2065 case LFUN_GREEK_TOGGLE:
2067 greek_kb_flag = (greek_kb_flag) ? 0: 2;
2068 if (greek_kb_flag) {
2069 setMessage(N_("Math greek keyboard on"));
2071 setMessage(N_("Math greek keyboard off"));
2076 case LFUN_MATH_DELIM:
2077 case LFUN_INSERT_MATRIX:
2079 if (owner->currentView()->available()) {
2080 owner->currentBuffer()->
2081 open_new_inset(new InsetFormula(false));
2082 owner->currentBuffer()->
2083 the_locking_inset->LocalDispatch(action, argument.c_str());
2088 case LFUN_INSERT_MATH:
2090 math_insert_symbol(argument.c_str());
2094 case LFUN_MATH_DISPLAY:
2096 if (owner->currentView()->available())
2097 owner->currentBuffer()->open_new_inset(new InsetFormula(true));
2101 case LFUN_MATH_MACRO:
2103 if (owner->currentView()->available()) {
2106 setErrorMessage(N_("Missing argument"));
2108 string s1 = token(s, ' ', 1);
2109 int na = s1.empty() ? 0: atoi(s1.c_str());
2110 owner->currentBuffer()->
2111 open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2117 case LFUN_MATH_MODE: // Open or create a math inset
2120 if (owner->currentView()->available())
2121 owner->currentBuffer()->open_new_inset(new InsetFormula);
2122 setMessage(N_("Math editor mode"));
2126 case LFUN_MATH_NUMBER:
2127 case LFUN_MATH_LIMITS:
2129 setErrorMessage(N_("This is only allowed in math mode!"));
2133 case LFUN_INSERT_CITATION:
2135 InsetCitation *new_inset = new InsetCitation();
2137 // The note, if any, must be after the key, delimited
2138 // by a | so both key and remark can have spaces.
2139 if (!argument.empty()) {
2140 string lsarg(argument);
2141 if (contains(lsarg, "|")) {
2142 new_inset->setContents(token(lsarg, '|', 0));
2143 new_inset->setOptions(token(lsarg, '|', 1));
2145 new_inset->setContents(lsarg);
2146 owner->currentBuffer()->insertInset(new_inset);
2148 owner->currentBuffer()->insertInset(new_inset);
2149 new_inset->Edit(0,0);
2154 case LFUN_INSERT_BIBTEX:
2156 // ale970405+lasgoutt970425
2157 // The argument can be up to two tokens separated
2158 // by a space. The first one is the bibstyle.
2159 string lsarg(argument);
2160 string bibstyle = token(lsarg, ' ', 1);
2161 if (bibstyle.empty())
2163 InsetBibtex *new_inset
2164 = new InsetBibtex(token(lsarg, ' ', 0),
2166 owner->currentBuffer());
2168 owner->currentBuffer()->insertInset(new_inset);
2169 if (lsarg.empty()) {
2170 new_inset->Edit(0,0);
2175 // BibTeX data bases
2176 case LFUN_BIBDB_ADD:
2178 InsetBibtex *inset =
2179 (InsetBibtex*)getInsetByCode(Inset::BIBTEX_CODE);
2181 inset->addDatabase(argument);
2186 case LFUN_BIBDB_DEL:
2188 InsetBibtex *inset =
2189 (InsetBibtex*)getInsetByCode(Inset::BIBTEX_CODE);
2191 inset->delDatabase(argument);
2196 case LFUN_BIBTEX_STYLE:
2198 InsetBibtex *inset =
2199 (InsetBibtex*)getInsetByCode(Inset::BIBTEX_CODE);
2201 inset->setOptions(argument);
2206 case LFUN_INDEX_INSERT:
2207 case LFUN_INDEX_INSERT_LAST:
2209 InsetIndex * new_inset = new InsetIndex();
2210 if (!argument.empty()) {
2211 string lsarg(argument);
2212 new_inset->setContents(lsarg);
2213 owner->currentBuffer()->insertInset(new_inset);
2216 //get the current word for an argument
2222 LyXParagraph::size_type lastpos =
2223 owner->currentBuffer()->text->cursor.pos - 1;
2224 // If this can't happen, let's make sure that it really don't
2225 Assert(owner->currentBuffer()->text->cursor.pos - 1 >= 0);
2227 int lastpos =owner->currentBuffer()->text->cursor.pos - 1;
2228 //this shouldn't happen, but let's be careful
2229 if (lastpos < 0) lastpos=0;
2231 // get the current word
2232 // note that this must be done before
2233 // inserting the inset, or the inset will break
2235 string curstring(owner->currentBuffer()
2236 ->text->cursor.par->GetWord(lastpos));
2238 //make the new inset and write the current word into it
2239 InsetIndex * new_inset = new InsetIndex();
2241 new_inset->setContents(curstring);
2243 //don't edit it if the call was to INSERT_LAST
2244 if(action!=LFUN_INDEX_INSERT_LAST) {
2245 new_inset->Edit(0,0);
2247 //it looks blank on the screen unless
2248 //we do something. put it here.
2250 // move the cursor to the returned value of lastpos
2251 // but only for the auto-insert
2252 owner->currentBuffer()->text->cursor.pos=lastpos;
2255 //put the new inset into the buffer.
2256 // there should be some way of knowing the user
2257 //cancelled & avoiding this, but i don't know how
2258 owner->currentBuffer()->insertInset(new_inset);
2263 case LFUN_INDEX_PRINT:
2265 Inset *new_inset = new InsetPrintIndex(owner->currentBuffer());
2266 owner->currentBuffer()->insertInset(new_inset, "Standard", true);
2270 case LFUN_PARENTINSERT:
2272 lyxerr << "arg " << argument << endl;
2273 Inset *new_inset = new InsetParent(argument, owner->currentBuffer());
2274 owner->currentBuffer()->insertInset(new_inset, "Standard", true);
2278 case LFUN_CHILDINSERT:
2280 Inset *new_inset = new InsetInclude(argument,owner->currentBuffer());
2281 owner->currentBuffer()->insertInset(new_inset, "Standard", true);
2282 new_inset->Edit(0,0);
2286 case LFUN_CHILDOPEN:
2288 string filename = MakeAbsPath(argument,
2289 OnlyPath(owner->currentBuffer()->getFileName()));
2290 setMessage(N_("Opening child document ") +
2291 MakeDisplayPath(filename) + "...");
2292 owner->currentView()->savePosition();
2293 if (bufferlist.exists(filename))
2294 owner->currentView()->setBuffer(bufferlist.getBuffer(filename));
2296 owner->currentView()->setBuffer(bufferlist.loadLyXFile(filename));
2300 case LFUN_INSERT_NOTE:
2304 case LFUN_INSERTFOOTNOTE:
2306 LyXParagraph::footnote_kind kind;
2307 if (argument == "footnote")
2308 { kind = LyXParagraph::FOOTNOTE; }
2309 else if (argument == "margin")
2310 { kind = LyXParagraph::MARGIN; }
2311 else if (argument == "figure")
2312 { kind = LyXParagraph::FIG; }
2313 else if (argument == "table")
2314 { kind = LyXParagraph::TAB; }
2315 else if (argument == "wide-fig")
2316 { kind = LyXParagraph::WIDE_FIG; }
2317 else if (argument == "wide-tab")
2318 { kind = LyXParagraph::WIDE_TAB; }
2319 else if (argument == "algorithm")
2320 { kind = LyXParagraph::ALGORITHM; }
2322 setErrorMessage(N_("Unknown kind of footnote"));
2325 owner->currentBuffer()->text->InsertFootnoteEnvironment(kind);
2326 owner->currentBuffer()->update(1);
2330 case LFUN_BUFFERBULLETSSELECT:
2334 case LFUN_TOGGLECURSORFOLLOW:
2335 cursor_follows_scrollbar = !cursor_follows_scrollbar;
2338 case LFUN_KMAP_OFF: // keymap off
2339 owner->getIntl()->KeyMapOn(false);
2342 case LFUN_KMAP_PRIM: // primary keymap
2343 owner->getIntl()->KeyMapPrim();
2346 case LFUN_KMAP_SEC: // secondary keymap
2347 owner->getIntl()->KeyMapSec();
2350 case LFUN_KMAP_TOGGLE: // toggle keymap
2351 owner->getIntl()->ToggleKeyMap();
2354 case LFUN_SELFINSERT:
2356 for (string::size_type i = 0; i < argument.length(); ++i) {
2357 owner->currentBuffer()->text->InsertChar(argument[i]);
2358 // This needs to be in the loop, or else we
2359 // won't break lines correctly. (Asger)
2363 owner->currentBuffer()->text->sel_cursor =
2364 owner->currentBuffer()->text->cursor;
2365 moveCursorUpdate(false);
2369 case LFUN_UNKNOWN_ACTION:
2371 if (owner->currentBuffer()->isReadonly()) {
2373 setErrorMessage(N_("Document is read only"));
2377 if (!argument.empty()) {
2379 /* Automatically delete the currently selected
2380 * text and replace it with what is being
2381 * typed in now. Depends on lyxrc settings
2382 * "auto_region_delete", which defaults to
2385 if ( lyxrc->auto_region_delete ) {
2386 if (owner->currentBuffer()->text->selection){
2387 owner->currentBuffer()->text->CutSelection(false);
2388 owner->currentBuffer()->update(-1);
2393 for (string::size_type i = 0; i < argument.length(); ++i) {
2394 if (greek_kb_flag) {
2395 if (!math_insert_greek(argument[i]))
2396 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->currentBuffer()->text);
2398 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->currentBuffer()->text);
2404 owner->currentBuffer()->text->sel_cursor =
2405 owner->currentBuffer()->text->cursor;
2406 moveCursorUpdate(false);
2409 // why is an "Unknown action" with empty
2410 // argument even dispatched in the first
2411 // place? I`ll probably change that. (Lgb)
2413 setErrorMessage(N_("Unknown action"));
2417 lyxerr << "A truly unknown func!" << endl;
2423 string res=getMessage();
2426 if (!commandshortcut.empty()) {
2427 string newbuf = owner->getMiniBuffer()->GetText();
2428 if (newbuf != commandshortcut) {
2429 owner->getMiniBuffer()->Set(newbuf
2435 owner->getMiniBuffer()->Set(string(_(res.c_str()))
2436 + " " + commandshortcut);
2439 return getMessage();
2443 void LyXFunc::setupLocalKeymap()
2445 keyseq.stdmap = keyseq.curmap = toplevel_keymap;
2446 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap;
2450 void LyXFunc::MenuNew(bool fromTemplate)
2452 string fname, initpath = lyxrc->document_path;
2455 if (owner->currentView()->available()) {
2456 string trypath = owner->currentBuffer()->filepath;
2457 // If directory is writeable, use this as default.
2458 if (IsDirWriteable(trypath) == 1)
2463 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2464 fileDlg.SetButton(1, _("Templates"), lyxrc->template_path);
2465 fname = fileDlg.Select(_("Enter Filename for new document"),
2466 initpath, "*.lyx", _("newfile"));
2469 if (fname.empty()) {
2470 owner->getMiniBuffer()->Set(_("Canceled."));
2471 lyxerr.debug() << "New Document Cancelled." << endl;
2475 // get absolute path of file and make sure the filename ends
2477 string s = MakeAbsPath(fname);
2478 if (!IsLyXFilename(s))
2481 // Check if the document already is open
2482 if (bufferlist.exists(s)){
2483 switch(AskConfirmation(_("Document is already open:"),
2484 MakeDisplayPath(s,50),
2485 _("Do you want to close that document now?\n"
2486 "('No' will just switch to the open version)")))
2488 case 1: // Yes: close the document
2489 if (!bufferlist.close(bufferlist.getBuffer(s)))
2490 // If close is canceled, we cancel here too.
2493 case 2: // No: switch to the open document
2494 owner->currentView()->setBuffer(bufferlist.getBuffer(s));
2496 case 3: // Cancel: Do nothing
2497 owner->getMiniBuffer()->Set(_("Canceled."));
2502 // Check whether the file already exists
2503 if (IsLyXFilename(s)) {
2504 FilePtr myfile(s, FilePtr::read);
2506 AskQuestion(_("File already exists:"),
2507 MakeDisplayPath(s,50),
2508 _("Do you want to open the document?"))) {
2510 owner->getMiniBuffer()->Set(_("Opening document"),
2511 MakeDisplayPath(s), "...");
2513 owner->currentView()->setBuffer(
2514 bufferlist.loadLyXFile(s));
2515 owner->getMiniBuffer()->Set(_("Document"),
2522 // The template stuff
2526 fname = fileDlg.Select(_("Choose template"),
2527 lyxrc->template_path,
2533 // find a free buffer
2534 lyxerr.debug() << "Find a free buffer." << endl;
2535 owner->currentView()->setBuffer(bufferlist.newFile(s,templname));
2539 void LyXFunc::MenuOpen()
2541 string initpath = lyxrc->document_path;
2544 if (owner->currentView()->available()) {
2545 string trypath = owner->currentBuffer()->filepath;
2546 // If directory is writeable, use this as default.
2547 if (IsDirWriteable(trypath) == 1)
2553 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2554 fileDlg.SetButton(1, _("Examples"),
2555 AddPath(system_lyxdir, "examples"));
2556 string filename = fileDlg.Select(_("Select Document to Open"),
2560 // check selected filename
2561 if (filename.empty()) {
2562 owner->getMiniBuffer()->Set(_("Canceled."));
2566 // get absolute path of file and make sure the filename ends
2568 filename = MakeAbsPath(filename);
2569 if (!IsLyXFilename(filename))
2573 owner->getMiniBuffer()->Set(_("Opening document"),
2574 MakeDisplayPath(filename), "...");
2575 Buffer * openbuf = bufferlist.loadLyXFile(filename);
2577 owner->currentView()->setBuffer(openbuf);
2578 owner->getMiniBuffer()->Set(_("Document"),
2579 MakeDisplayPath(filename),
2582 owner->getMiniBuffer()->Set(_("Could not open document"),
2583 MakeDisplayPath(filename));
2588 void LyXFunc::doImportASCII(bool linorpar)
2590 string initpath = lyxrc->document_path;
2593 if (owner->currentView()->available()) {
2594 string trypath = owner->currentBuffer()->filepath;
2595 // If directory is writeable, use this as default.
2596 if (IsDirWriteable(trypath) == 1)
2602 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2603 fileDlg.SetButton(1, _("Examples"),
2604 AddPath(system_lyxdir, "examples"));
2605 string filename = fileDlg.Select(_("Select ASCII file to Import"),
2609 // check selected filename
2610 if (filename.empty()) {
2611 owner->getMiniBuffer()->Set(_("Canceled."));
2615 // get absolute path of file
2616 filename = MakeAbsPath(filename);
2618 string s = ChangeExtension(filename, ".lyx", false);
2620 // Check if the document already is open
2621 if (bufferlist.exists(s)){
2622 switch(AskConfirmation(_("Document is already open:"),
2623 MakeDisplayPath(s,50),
2624 _("Do you want to close that document now?\n"
2625 "('No' will just switch to the open version)")))
2627 case 1: // Yes: close the document
2628 if (!bufferlist.close(bufferlist.getBuffer(s)))
2629 // If close is canceled, we cancel here too.
2632 case 2: // No: switch to the open document
2633 owner->currentView()->setBuffer(bufferlist.getBuffer(s));
2635 case 3: // Cancel: Do nothing
2636 owner->getMiniBuffer()->Set(_("Canceled."));
2641 // Check if a LyX document by the same root exists in filesystem
2642 FileInfo f(s, true);
2643 if (f.exist() && !AskQuestion(_("A document by the name"),
2645 _("already exists. Overwrite?"))) {
2646 owner->getMiniBuffer()->Set(_("Canceled."));
2650 owner->currentView()->setBuffer(bufferlist.newFile(s,string()));
2651 owner->getMiniBuffer()->Set(_("Importing ASCII file"),
2652 MakeDisplayPath(filename), "...");
2653 // Insert ASCII file
2654 InsertAsciiFile(filename,linorpar);
2655 owner->getMiniBuffer()->Set(_("ASCII file "),
2656 MakeDisplayPath(filename),
2661 void LyXFunc::doImportLaTeX(bool isnoweb)
2663 string initpath = lyxrc->document_path;
2666 if (owner->currentView()->available()) {
2667 string trypath = owner->currentBuffer()->filepath;
2668 // If directory is writeable, use this as default.
2669 if (IsDirWriteable(trypath) == 1)
2675 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2676 fileDlg.SetButton(1, _("Examples"),
2677 AddPath(system_lyxdir, "examples"));
2680 filename = fileDlg.Select(_("Select Noweb file to Import"),
2683 filename = fileDlg.Select(_("Select LaTeX file to Import"),
2689 // check selected filename
2690 if (filename.empty()) {
2691 owner->getMiniBuffer()->Set(_("Canceled."));
2695 // get absolute path of file
2696 filename = MakeAbsPath(filename);
2698 // Check if the document already is open
2699 string LyXfilename = ChangeExtension(filename, ".lyx", false);
2700 if (bufferlist.exists(LyXfilename)){
2701 switch(AskConfirmation(_("Document is already open:"),
2702 MakeDisplayPath(LyXfilename,50),
2703 _("Do you want to close that document now?\n"
2704 "('No' will just switch to the open version)")))
2706 case 1: // Yes: close the document
2707 if (!bufferlist.close(bufferlist.getBuffer(LyXfilename)))
2708 // If close is canceled, we cancel here too.
2711 case 2: // No: switch to the open document
2712 owner->currentView()->setBuffer(
2713 bufferlist.getBuffer(LyXfilename));
2715 case 3: // Cancel: Do nothing
2716 owner->getMiniBuffer()->Set(_("Canceled."));
2721 // Check if a LyX document by the same root exists in filesystem
2722 FileInfo f(LyXfilename, true);
2723 if (f.exist() && !AskQuestion(_("A document by the name"),
2724 MakeDisplayPath(LyXfilename),
2725 _("already exists. Overwrite?"))) {
2726 owner->getMiniBuffer()->Set(_("Canceled."));
2733 owner->getMiniBuffer()->Set(_("Importing LaTeX file"),
2734 MakeDisplayPath(filename), "...");
2735 ImportLaTeX myImport(filename);
2736 openbuf = myImport.run();
2738 owner->getMiniBuffer()->Set(_("Importing Noweb file"),
2739 MakeDisplayPath(filename), "...");
2740 ImportNoweb myImport(filename);
2741 openbuf = myImport.run();
2744 owner->currentView()->setBuffer(openbuf);
2745 owner->getMiniBuffer()->Set(isnoweb ?
2746 _("Noweb file ") : _("LateX file "),
2747 MakeDisplayPath(filename),
2750 owner->getMiniBuffer()->Set(isnoweb ?
2751 _("Could not import Noweb file") :
2752 _("Could not import LaTeX file"),
2753 MakeDisplayPath(filename));
2758 void LyXFunc::MenuInsertLyXFile(string const & filen)
2760 string filename = filen;
2762 if (filename.empty()) {
2763 // Launch a file browser
2764 string initpath = lyxrc->document_path;
2767 if (owner->currentView()->available()) {
2768 string trypath = owner->currentBuffer()->filepath;
2769 // If directory is writeable, use this as default.
2770 if (IsDirWriteable(trypath) == 1)
2776 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2777 fileDlg.SetButton(1, _("Examples"),
2778 AddPath(system_lyxdir, "examples"));
2779 filename = fileDlg.Select(_("Select Document to Insert"),
2783 // check selected filename
2784 if (filename.empty()) {
2785 owner->getMiniBuffer()->Set(_("Canceled."));
2790 // get absolute path of file and make sure the filename ends
2792 filename = MakeAbsPath(filename);
2793 if (!IsLyXFilename(filename))
2797 owner->getMiniBuffer()->Set(_("Inserting document"),
2798 MakeDisplayPath(filename), "...");
2799 bool res = owner->currentBuffer()->insertLyXFile(filename);
2801 owner->getMiniBuffer()->Set(_("Document"),
2802 MakeDisplayPath(filename),
2805 owner->getMiniBuffer()->Set(_("Could not insert document"),
2806 MakeDisplayPath(filename));
2811 void LyXFunc::reloadBuffer()
2813 string fn = owner->currentBuffer()->getFileName();
2814 if (bufferlist.close(owner->currentBuffer()))
2815 owner->currentView()->setBuffer(bufferlist.loadLyXFile(fn));
2819 void LyXFunc::CloseBuffer()
2821 if (bufferlist.close(owner->currentBuffer()) && !quitting) {
2822 if (bufferlist.isEmpty()) {
2823 // need this otherwise SEGV may occur while trying to
2824 // set variables that don't exist
2825 // since there's no current buffer
2826 CloseAllBufferRelatedPopups();
2829 owner->currentView()->setBuffer(bufferlist.first());
2835 Inset * LyXFunc::getInsetByCode(Inset::Code code)
2839 LyXCursor cursor = owner->currentBuffer()->text->cursor;
2841 LyXParagraph::size_type pos = cursor.pos;
2843 int pos = cursor.pos;
2845 LyXParagraph * par = cursor.par;
2847 while (par && !found) {
2848 while ((inset = par->ReturnNextInsetPointer(pos))){
2849 if (inset->LyxCode()==code) {
2857 return (found) ? inset: 0;
2861 // Each "owner" should have it's own message method. lyxview and
2862 // the minibuffer would use the minibuffer, but lyxserver would
2863 // send an ERROR signal to its client. Alejandro 970603
2864 // This func is bit problematic when it comes to NLS, to make the
2865 // lyx servers client be language indepenent we must not translate
2866 // strings sent to this func.
2867 void LyXFunc::setErrorMessage(string const &m)
2869 dispatch_buffer = m;
2874 void LyXFunc::setMessage(string const & m)
2876 dispatch_buffer = m;