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 "lyxscreen.h"
58 #include "trans_mgr.h"
59 #include "ImportLaTeX.h"
60 #include "ImportNoweb.h"
62 extern bool cursor_follows_scrollbar;
64 extern void InsertAsciiFile(string const &, bool);
65 extern void math_insert_symbol(char const*);
66 extern Bool math_insert_greek(char const); // why "Bool"?
67 extern BufferList bufferlist;
68 extern LyXServer *lyxserver;
69 extern short greek_kb_flag;
70 extern FD_form_toc *fd_form_toc;
71 extern bool selection_possible;
73 extern kb_keymap *toplevel_keymap;
75 extern void BeforeChange();
76 extern void MenuWrite(Buffer*);
77 extern void MenuWriteAs(Buffer*);
78 extern int MenuRunLaTeX(Buffer*);
79 extern int MenuBuildProg(Buffer*);
80 extern int MenuRunChktex(Buffer*);
81 extern bool MenuRunDvips(Buffer *,bool);
82 extern void MenuPrint(Buffer*);
83 extern void MenuSendto();
84 extern void QuitLyX();
85 extern void MenuFax(Buffer *);
86 extern void MenuMakeLaTeX(Buffer *);
87 extern void MenuMakeLinuxDoc(Buffer *);
88 extern void MenuMakeDocBook(Buffer *);
89 extern void MenuMakeAscii(Buffer *);
90 extern void MenuPasteSelection(char at);
91 extern LyXAction lyxaction;
93 extern tex_accent_struct get_accent(kb_action action);
95 extern void AutoSave();
96 extern void MenuSearch();
98 extern void CopyEnvironmentCB();
99 extern void PasteEnvironmentCB();
100 extern void GotoNote();
101 extern void NoteCB();
102 extern void OpenStuff();
103 extern void HyphenationPoint();
105 extern void EndOfSentenceDot();
106 extern void MenuSeparator();
108 extern void MenuUndo();
109 extern void MenuRedo();
110 extern void SmallUpdate(signed char);
111 extern void SetUpdateTimer(float timer= 0.3);
112 extern void FreeUpdateTimer();
113 extern bool MenuPreview(Buffer*);
114 extern bool MenuPreviewPS(Buffer*);
115 extern void MenuInsertLabel(const char *);
116 extern void MenuInsertRef();
117 extern void MenuLayoutCharacter();
118 extern void MenuLayoutParagraph();
119 extern void MenuLayoutDocument();
120 extern void MenuLayoutPaper();
121 extern void MenuLayoutTable(int flag);
122 extern void MenuLayoutQuotes();
123 extern void MenuLayoutPreamble();
124 extern void MenuLayoutSave();
125 extern void bulletForm();
127 extern Buffer * NewLyxFile(string const &);
128 extern void LoadLyXFile(string const &);
129 extern void Reconfigure();
131 extern int current_layout;
132 extern int getISOCodeFromLaTeX(char *);
134 extern int UnlockInset(UpdatableInset*);
136 extern void ShowLatexLog();
138 extern void UpdateInset(Inset* inset, bool mark_dirty = true);
140 /* === globals =========================================================== */
142 bool LyXFunc::show_sc = true;
145 LyXFunc::LyXFunc(LyXView *o)
149 lyx_dead_action = LFUN_NOACTION;
150 lyx_calling_dead_action = LFUN_NOACTION;
160 string LyXFunc::argAsString(char const * const argument)
162 string tmp(argument);
165 // get the arg from somewhere else, a popup, or ask for
166 // it in the minibuffer.
168 lyxerr.debug() << "argAsString: <" << tmp << '>' << endl;
173 // I changed this func slightly. I commented out the ...FinishUndo(),
174 // this means that all places that used to have a moveCursorUpdate, now
175 // have a ...FinishUndo() as the preceeding statement. I have also added
176 // a moveCursorUpdate to some of the functions that updated the cursor, but
177 // that did not show its new position.
179 void LyXFunc::moveCursorUpdate(bool selecting)
181 if (selecting || owner->currentBuffer()->text->mark_set) {
182 owner->currentBuffer()->text->SetSelection();
183 owner->currentView()->getScreen()->ToggleToggle();
184 owner->currentBuffer()->update(0);
186 owner->currentBuffer()->update(-2); // this IS necessary
189 owner->currentView()->getScreen()->ShowCursor();
191 /* ---> Everytime the cursor is moved, show the current font state. */
192 // should this too me moved out of this func?
193 //owner->getMiniBuffer()->Set(CurrentState());
197 int LyXFunc::processKeyEvent(XEvent *ev)
204 XKeyEvent *keyevent = &ev->xkey;
205 KeySym keysym_return;
207 num_bytes = LyXLookupString(ev, s_r, 10, &keysym_return);
209 if (lyxerr.debugging(Debug::KEY)) {
210 lyxerr << "KeySym is "
211 << XKeysymToString(keysym_return)
213 << keysym_return << "]"
214 << " and num_bytes is "
216 << " the string returned is \""
217 << s_r << '\"' << endl;
219 // Do nothing if we have nothing (JMarc)
220 if (num_bytes == 0 && keysym_return == NoSymbol) {
221 lyxerr[Debug::KEY] << "Empty kbd action (probably composing)"
226 // this function should be used always [asierra060396]
227 if (owner->currentView()->available() &&
228 owner->currentBuffer()->the_locking_inset &&
229 keysym_return == XK_Escape) {
230 UnlockInset(owner->currentBuffer()->the_locking_inset);
231 owner->currentBuffer()->text->CursorRight();
235 // Can we be sure that this will work for all X-Windows
236 // implementations? (Lgb)
237 // This code snippet makes lyx ignore some keys. Perhaps
238 // all of them should be explictly mentioned?
239 if((keysym_return >= XK_Shift_L && keysym_return <= XK_Hyper_R)
240 || keysym_return == XK_Mode_switch || keysym_return == 0x0)
243 // Do a one-deep top-level lookup for
244 // cancel and meta-fake keys. RVDK_PATCH_5
245 cancel_meta_seq.reset();
247 action = cancel_meta_seq.addkey(keysym_return, keyevent->state
248 &(ShiftMask|ControlMask
251 // When not cancel or meta-fake, do the normal lookup.
252 // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
253 // Mostly, meta_fake_bit = 0. RVDK_PATCH_5.
254 if ( (action != LFUN_CANCEL) && (action != LFUN_META_FAKE) ) {
256 // remove Caps Lock and Mod2 as a modifiers
257 action = keyseq.addkey(keysym_return,
258 (keyevent->state | meta_fake_bit)
259 &(ShiftMask|ControlMask
262 // Dont remove this unless you know what you are doing.
265 if (action == 0) action = LFUN_PREFIX;
267 if (lyxerr.debugging(Debug::KEY)) {
269 keyseq.print(buf,100);
273 << num_bytes << "]" << endl;
276 // already here we know if it any point in going further
277 // why not return already here if action == -1 and
278 // num_bytes == 0? (Lgb)
280 if(keyseq.length>1 || keyseq.length<-1){
282 keyseq.print(buf,100);
283 owner->getMiniBuffer()->Set(buf);
287 if (keyseq.length<-1) { // unknown key sequence...
290 keyseq.print(buf,100);
291 owner->getMiniBuffer()->Set(_("Unknown sequence:"),buf);
295 char isochar = keyseq.getiso();
296 if (!(keyevent->state&ControlMask) &&
297 !(keyevent->state&Mod1Mask) &&
298 (isochar && keysym_return < 0xF000)) {
299 argument = &s_r[0]; // shall this be here
300 argument[0] = isochar;
304 lyxerr.debug() << "Empty argument!" << endl;
305 // This can`t possibly be of any use
306 // so we`ll skip the dispatch.
310 if (action==LFUN_SELFINSERT) {
315 bool tmp_sc = show_sc;
317 Dispatch(action, argument);
320 // Need this for deadkeys (alkis)
322 // ...but that breaks the minibuffer's display of "M-"...
324 #warning How does the deadkeys react to this?
330 string LyXFunc::Dispatch(string const &cmd, string const &arg)
332 return Dispatch(lyxaction.LookupFunc(cmd.c_str()),
337 string LyXFunc::Dispatch(int ac,
338 char const *do_not_use_this_arg)
340 char const * argument = 0;
344 FL_OBJECT *ob = 0; // This will disapear soon
346 // we have not done anything wrong yet.
348 dispatch_buffer = string();
350 // if action is a pseudo-action, we need the real action
351 if (lyxaction.isPseudoAction(ac)) {
352 char const *tmparg = 0;
353 action = (kb_action)lyxaction.retrieveActionArg(ac, &tmparg);
357 action = (kb_action)ac;
358 argument = do_not_use_this_arg; // except here
361 selection_possible = false;
363 if (owner->currentView()->available()
364 && owner->currentView()->getScreen())
365 owner->currentView()->getScreen()->HideCursor();
367 if(!owner->currentView()->available()) {
368 // This lists the allowed funcs when we have no
371 case LFUN_MENU_OPEN_BY_NAME:
374 case LFUN_MENUNEWTMPLT:
377 case LFUN_PUSH_TOOLBAR:
378 case LFUN_ADD_TO_TOOLBAR:
379 case LFUN_EXEC_COMMAND:
380 case LFUN_DROP_LAYOUTS_CHOICE:
384 case LFUN_RECONFIGURE:
390 case LFUN_UNKNOWN_ACTION:
391 setErrorMessage(N_("Unknown action"));
392 goto exit_with_message;
394 setErrorMessage(N_("Command not allowed with"
395 "out any document open"));
396 goto exit_with_message; // action not allowed
400 commandshortcut = string();
402 if (lyxrc->display_shortcuts && show_sc) {
403 if (action != LFUN_SELFINSERT) {
404 // Put name of command and list of shortcuts
405 // for it in minibuffer
406 string comname = lyxaction.getActionName(action);
408 int pseudoaction = action;
409 bool argsadded = false;
414 // If we have the command with argument,
417 lyxaction.searchActionArg(action,
420 if (pseudoaction == -1) {
421 pseudoaction = action;
423 comname += " " + argu;
428 string shortcuts = toplevel_keymap->findbinding(pseudoaction);
430 if (!shortcuts.empty()) {
431 comname += ": " + shortcuts;
432 } else if (!argsadded) {
433 comname += " " + argu;
436 if (!comname.empty()) {
437 comname = strip(comname);
438 commandshortcut = "(" + comname + ')';
439 owner->getMiniBuffer()->Set(commandshortcut);
440 // Here we could even add a small pause,
441 // to annoy the user and make him learn
443 // No! That will just annoy, not teach
444 // anything. The user will read the messages
445 // if they are interested. (Asger)
450 // Now that we know which action, if the buffer is RO let's check
451 // whether the action is legal. Alejandro 970603
452 if (owner->currentView()->available() &&
453 owner->currentBuffer()->isReadonly() &&
454 lyxaction.isFuncRO(action)) {
455 setErrorMessage(N_("Document is read-only"));
456 lyxerr.debug() << "Error: Document is read-only." << endl;
457 goto exit_with_message;
460 // If in math mode pass the control to
461 // the math inset [asierra060396]
462 if (owner->currentView()->available() &&
463 owner->currentBuffer()->the_locking_inset) {
464 if (action>1 || (action==LFUN_UNKNOWN_ACTION && keyseq.length>=-1)) {
466 if (action==LFUN_UNKNOWN_ACTION && !argument) {
467 sprintf(s, "%c", keyseq.getiso());
470 // Undo/Redo pre 0.13 is a bit tricky for insets.
471 if (action==LFUN_UNDO) {
473 UpdatableInset* inset =
474 owner->currentBuffer()->the_locking_inset;
475 inset->GetCursorPos(slx, sly);
478 inset = (UpdatableInset*)owner->currentBuffer()->text->cursor.par->GetInset(owner->currentBuffer()->text->cursor.pos);
480 inset->Edit(slx, sly);
483 if (action==LFUN_REDO) {
485 UpdatableInset* inset = owner->currentBuffer()->the_locking_inset;
486 inset->GetCursorPos(slx, sly);
489 inset = (UpdatableInset*)owner->currentBuffer()->text->cursor.par->GetInset(owner->currentBuffer()->text->cursor.pos);
491 inset->Edit(slx, sly);
494 if (owner->currentBuffer()->the_locking_inset->LocalDispatch(action, argument))
497 setMessage(N_("Text mode"));
498 if (action==LFUN_RIGHT || action==-1)
499 owner->currentBuffer()->text->CursorRight();
500 if (action==LFUN_LEFT || action==LFUN_RIGHT)
507 // --- Misc -------------------------------------------
508 case LFUN_WORDFINDFORWARD :
509 case LFUN_WORDFINDBACKWARD : {
511 static string last_search;
512 string searched_string;
514 string arg = argAsString(argument);
518 searched_string = arg;
520 searched_string = last_search;
523 ltCur = owner->currentView()->currentBuffer()->text ;
525 if (!searched_string.empty() &&
526 ( (action == LFUN_WORDFINDBACKWARD) ?
527 ltCur->SearchBackward( searched_string.c_str() ) :
528 ltCur->SearchForward( searched_string.c_str() )
531 // ??? What is that ???
532 owner->currentView()->currentBuffer()->update(-2);
535 // clear the selection (if there is any)
536 owner->currentView()->getScreen()->ToggleSelection();
537 owner->currentView()->currentBuffer()->text->ClearSelection();
539 // Move cursor so that successive C-s 's will not stand in place.
540 if( action == LFUN_WORDFINDFORWARD )
541 owner->currentBuffer()->text->CursorRightOneWord();
542 owner->currentBuffer()->text->FinishUndo();
543 moveCursorUpdate(false);
546 // set the new selection
547 // SetSelectionOverLenChars(owner->currentView()->currentBuffer()->text, iLenSelected);
548 owner->currentView()->getScreen()->ToggleSelection(false);
552 // REMOVED : if (owner->currentView()->getWorkArea()->focus)
553 owner->currentView()->getScreen()->ShowCursor();
559 if (owner->currentView()->available()
560 && owner->currentView()->getScreen()) {
561 owner->currentBuffer()->update(-2);
564 keyseq.print(buf,100, true);
565 owner->getMiniBuffer()->Set(buf, string(), string(), 1);
569 // --- Misc -------------------------------------------
570 case LFUN_EXEC_COMMAND:
571 owner->getMiniBuffer()->ExecCommand();
574 case LFUN_CANCEL: // RVDK_PATCH_5
577 if(owner->currentView()->available())
578 // cancel any selection
579 Dispatch(int(LFUN_MARK_OFF), 0);
580 setMessage(N_("Cancel"));
583 case LFUN_META_FAKE: // RVDK_PATCH_5
585 meta_fake_bit = Mod1Mask;
587 keyseq.print(buf, 98, true);
588 string res = string("M-") + buf;
589 setMessage(buf); // RVDK_PATCH_5
593 case LFUN_READ_ONLY_TOGGLE:
594 if (owner->currentBuffer()->lyxvc.inUse()) {
595 owner->currentBuffer()->lyxvc.toggleReadOnly();
597 owner->currentBuffer()->setReadonly(
598 !owner->currentBuffer()->isReadonly());
602 case LFUN_CENTER: // this is center and redraw.
604 if (owner->currentBuffer()->text->cursor.y >
605 owner->currentView()->getWorkArea()->h / 2) {
606 owner->currentView()->getScreen()->
607 Draw(owner->currentBuffer()->text->cursor.y -
608 owner->currentView()->getWorkArea()->h/2);
610 owner->currentView()->getScreen()->
613 owner->currentBuffer()->update(0);
614 owner->currentView()->redraw();
618 if (owner->currentView()->available()) {
619 owner->currentBuffer()->text->toggleAppendix();
620 owner->currentBuffer()->update(1);
624 // --- Menus -----------------------------------------------
629 case LFUN_MENUNEWTMPLT:
637 case LFUN_CLOSEBUFFER:
642 MenuWrite(owner->currentBuffer());
645 case LFUN_MENUWRITEAS:
646 MenuWriteAs(owner->currentBuffer());
649 case LFUN_MENURELOAD:
654 MenuPreview(owner->currentBuffer());
658 MenuPreviewPS(owner->currentBuffer());
662 MenuRunLaTeX(owner->currentBuffer());
666 MenuBuildProg(owner->currentBuffer());
670 MenuRunChktex(owner->currentBuffer());
674 MenuRunDvips(owner->currentBuffer(), false);
678 MenuPrint(owner->currentBuffer());
682 MenuFax(owner->currentBuffer());
687 //needs argument as string
688 string extyp=argAsString(argument);
691 if (extyp == "latex") {
692 // make sure that this buffer is not linuxdoc
693 MenuMakeLaTeX(owner->currentBuffer());
696 else if (extyp == "linuxdoc") {
697 // make sure that this buffer is not latex
698 MenuMakeLinuxDoc(owner->currentBuffer());
701 else if (extyp == "docbook") {
702 // make sure that this buffer is not latex or linuxdoc
703 MenuMakeDocBook(owner->currentBuffer());
706 else if (extyp == "dvi") {
707 // Run LaTeX as "Update dvi..." Bernhard.
708 // We want the dvi in the current directory. This
709 // is achieved by temporarily disabling use of
710 // temp directory. As a side-effect, we get
711 // *.log and *.aux files also. (Asger)
712 bool flag = lyxrc->use_tempdir;
713 lyxrc->use_tempdir = false;
714 MenuRunLaTeX(owner->currentBuffer());
715 lyxrc->use_tempdir = flag;
718 else if (extyp == "postscript") {
719 // Start Print-dialog. Not as good as dvi... Bernhard.
720 MenuPrint(owner->currentBuffer());
721 // Since the MenuPrint is a pop-up, we can't use
722 // the same trick as above. (Asger)
723 // MISSING: Move of ps-file :-(
726 else if (extyp == "ascii") {
727 MenuMakeAscii(owner->currentBuffer());
729 else if (extyp == "custom") {
734 setErrorMessage(string(N_("Unknown export type: "))
742 //needs argument as string
743 string imtyp=argAsString(argument);
746 if (imtyp == "latex") {
747 doImportLaTeX(false);
750 else if (imtyp == "ascii") {
751 doImportASCII(false);
752 } else if (imtyp == "asciiparagraph") {
755 } else if (imtyp == "noweb") {
758 setErrorMessage(string(N_("Unknown import type: "))
770 if (fd_form_toc->form_toc->visible) {
771 fl_raise_form(fd_form_toc->form_toc);
773 fl_show_form(fd_form_toc->form_toc,
775 FL_FREE_SIZE, FL_FULLBORDER,
776 _("Table of Contents"));
780 case LFUN_TOC_INSERT:
783 new InsetTOC(owner->currentBuffer());
784 owner->currentBuffer()->insertInset(new_inset,
789 case LFUN_LOF_INSERT:
792 new InsetLOF(owner->currentBuffer());
793 owner->currentBuffer()->insertInset(new_inset,
798 case LFUN_LOA_INSERT:
801 new InsetLOA(owner->currentBuffer());
802 owner->currentBuffer()->insertInset(new_inset,
807 case LFUN_LOT_INSERT:
810 new InsetLOT(owner->currentBuffer());
811 owner->currentBuffer()->insertInset(new_inset,
836 case LFUN_MENUSEARCH:
844 case LFUN_PASTESELECTION:
847 if (string(argument) == "paragraph") asPara = true;
848 MenuPasteSelection(asPara);
860 case LFUN_LAYOUT_COPY:
864 case LFUN_LAYOUT_PASTE:
865 PasteEnvironmentCB();
869 owner->currentView()->gotoError();
872 case LFUN_REMOVEERRORS:
873 if (owner->currentBuffer()->removeAutoInsets()) {
874 owner->currentView()->redraw();
875 owner->currentView()->fitCursor();
876 owner->currentView()->updateScrollbar();
888 case LFUN_HYPHENATION:
896 case LFUN_END_OF_SENTENCE:
900 case LFUN_MENU_SEPARATOR:
916 case LFUN_DEPTH_PLUS:
932 case LFUN_RECONFIGURE:
937 if (owner->currentView()->available()
938 && !owner->currentBuffer()->text->selection
939 && owner->currentBuffer()->text->cursor.par->footnoteflag
940 != LyXParagraph::NO_FOOTNOTE)
941 { // only melt footnotes with FOOTMELT, not margins etc
942 if(owner->currentBuffer()->text->cursor.par->footnotekind == LyXParagraph::FOOTNOTE)
949 case LFUN_MARGINMELT:
950 if (owner->currentView()->available()
951 && !owner->currentBuffer()->text->selection
952 && owner->currentBuffer()->text->cursor.par->footnoteflag
953 != LyXParagraph::NO_FOOTNOTE)
954 { // only melt margins
955 if(owner->currentBuffer()->text->cursor.par->footnotekind == LyXParagraph::MARGIN)
962 // --- version control -------------------------------
963 case LFUN_VC_REGISTER:
965 if (!owner->currentBuffer()->lyxvc.inUse())
966 owner->currentBuffer()->lyxvc.registrer();
970 case LFUN_VC_CHECKIN:
972 if (owner->currentBuffer()->lyxvc.inUse()
973 && !owner->currentBuffer()->isReadonly())
974 owner->currentBuffer()->lyxvc.checkIn();
978 case LFUN_VC_CHECKOUT:
980 if (owner->currentBuffer()->lyxvc.inUse()
981 && owner->currentBuffer()->isReadonly())
982 owner->currentBuffer()->lyxvc.checkOut();
988 owner->currentBuffer()->lyxvc.revert();
994 owner->currentBuffer()->lyxvc.undoLast();
998 case LFUN_VC_HISTORY:
1000 owner->currentBuffer()->lyxvc.showLog();
1004 // --- buffers ----------------------------------------
1005 case LFUN_PREVBUFFER:
1006 #ifdef WITH_WARNINGS
1007 #warning fix this please
1009 // it is the LyXView or the BufferView that should
1010 // remember the previous buffer, not bufferlist.
1011 // if (owner->currentView()->available()){
1013 // owner->currentBuffer()->update(-2);
1015 // owner->currentView()->setBuffer(bufferlist.prev());
1017 // owner->currentView()->
1018 // resizeCurrentBufferPseudoExpose();
1021 case LFUN_FILE_INSERT:
1023 // needs argument as string
1024 string fil = argAsString(argument);
1025 MenuInsertLyXFile(fil);
1029 case LFUN_FILE_INSERT_ASCII:
1031 bool asPara = false;
1032 asPara = (string(argument) == "paragraph");
1033 InsertAsciiFile(string(), asPara);
1039 // servercmd: argument must be <file>:<template>
1040 Buffer * tmpbuf = 0;
1041 tmpbuf = NewLyxFile(argument);
1043 owner->currentView()->setBuffer(tmpbuf);
1047 case LFUN_FILE_OPEN:
1048 owner->currentView()->setBuffer(
1049 bufferlist.loadLyXFile(argument));
1052 case LFUN_LATEX_LOG:
1058 lyxerr.debug() << "LFUN_LAYOUTNO: (arg) " << argument << endl;
1059 int sel = atoi(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 lyxstyle.NameOfLayout(owner->currentBuffer()->
1079 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1080 << argument << endl;
1082 // Derive layout number from given argument (string)
1083 // and current buffer's textclass (number). */
1086 lyxstyle.NumberOfLayout(owner->
1092 // see if we found the layout number:
1093 if (layoutno == -1) {
1094 setErrorMessage(string(N_("Layout ")) + argument +
1099 if (current_layout != layoutno) {
1100 owner->currentView()->getScreen()->HideCursor();
1101 current_layout = layoutno;
1102 owner->currentBuffer()->update(-2);
1103 owner->currentBuffer()->text->
1104 SetLayout(layoutno);
1105 owner->getToolbar()->combox->
1106 select(owner->currentBuffer()->
1109 owner->currentBuffer()->update(1);
1114 case LFUN_LAYOUT_DOCUMENT:
1115 MenuLayoutDocument();
1118 case LFUN_LAYOUT_PARAGRAPH:
1119 MenuLayoutParagraph();
1122 case LFUN_LAYOUT_CHARACTER:
1123 MenuLayoutCharacter();
1126 case LFUN_LAYOUT_TABLE:
1129 if (string(argument) == "true") flag = 1;
1130 MenuLayoutTable(flag);
1134 case LFUN_LAYOUT_PAPER:
1138 case LFUN_LAYOUT_QUOTES:
1142 case LFUN_LAYOUT_PREAMBLE:
1143 MenuLayoutPreamble();
1146 case LFUN_LAYOUT_SAVE_DEFAULT:
1150 case LFUN_DROP_LAYOUTS_CHOICE:
1151 owner->getToolbar()->combox->Show();
1182 case LFUN_UNDERLINE:
1186 case LFUN_FONT_SIZE:
1187 FontSizeCB(argument);
1190 case LFUN_FONT_STATE:
1191 setMessage(CurrentState());
1194 case LFUN_UPCASE_WORD:
1195 owner->currentBuffer()->update(-2);
1197 owner->currentBuffer()->text->ChangeWordCase(2);
1198 owner->currentBuffer()->update(1);
1202 case LFUN_LOWCASE_WORD:
1203 owner->currentBuffer()->update(-2);
1205 owner->currentBuffer()->text->ChangeWordCase(0);
1206 owner->currentBuffer()->update(1);
1210 case LFUN_CAPITALIZE_WORD:
1211 owner->currentBuffer()->update(-2);
1213 owner->currentBuffer()->text->ChangeWordCase(1);
1214 owner->currentBuffer()->update(1);
1218 case LFUN_INSERT_LABEL:
1219 MenuInsertLabel(argument);
1222 case LFUN_INSERT_REF:
1226 case LFUN_REFTOGGLE:
1229 (InsetRef*)getInsetByCode(Inset::REF_CODE);
1231 if (inset->getFlag()==InsetRef::REF)
1232 inset->setFlag(InsetRef::PAGE_REF);
1234 inset->setFlag(InsetRef::REF);
1237 setErrorMessage(N_("No cross-reference to toggle"));
1244 owner->currentView()->restorePosition();
1250 string label(argument);
1251 if (label.empty()) {
1253 (InsetRef*)getInsetByCode(Inset::REF_CODE);
1255 label = inset->getContents();
1258 if (!label.empty()) {
1259 owner->currentView()->savePosition();
1260 owner->currentBuffer()->gotoLabel(label.c_str());
1265 case LFUN_MENU_OPEN_BY_NAME:
1266 owner->getMenus()->openByName(argument);
1267 break; // RVDK_PATCH_5
1269 case LFUN_SPELLCHECK:
1270 if (lyxrc->isp_command != "none")
1272 break; // RVDK_PATCH_5
1274 // --- Cursor Movements -----------------------------
1277 Buffer *tmpbuffer = owner->currentBuffer();
1278 LyXText *tmptext = owner->currentBuffer()->text;
1279 if(!tmptext->mark_set)
1281 tmpbuffer->update(-2);
1282 if (tmptext->cursor.pos < tmptext->cursor.par->Last()
1283 && tmptext->cursor.par->GetChar(tmptext->cursor.pos)
1285 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)
1286 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)->Editable()==2){
1287 Inset* tmpinset = tmptext->cursor.par->GetInset(tmptext->cursor.pos);
1288 setMessage(tmpinset->EditMessage());
1289 tmpinset->Edit(0,0);
1292 tmptext->CursorRight();
1293 owner->currentBuffer()->text->FinishUndo();
1294 moveCursorUpdate(false);
1295 owner->getMiniBuffer()->Set(CurrentState());
1301 // This is soooo ugly. Isn`t it possible to make
1302 // it simpler? (Lgb)
1303 LyXText *txt= owner->currentBuffer()->text;
1304 if(!txt->mark_set) BeforeChange();
1305 owner->currentBuffer()->update(-2);
1307 if (txt->cursor.pos < txt->cursor.par->Last()
1308 && txt->cursor.par->GetChar(txt->cursor.pos)
1310 && txt->cursor.par->GetInset(txt->cursor.pos)
1311 && txt->cursor.par->GetInset(txt->cursor.pos)->Editable()==2) {
1312 Inset* tmpinset = txt->cursor.par->GetInset(txt->cursor.pos);
1313 setMessage(tmpinset->EditMessage());
1314 tmpinset->Edit(tmpinset->Width(txt->GetFont(txt->cursor.par,
1315 txt->cursor.pos)),0);
1316 // tmpinset->Edit(-1, 0); // -1 means go rightmost
1319 owner->currentBuffer()->text->FinishUndo();
1320 moveCursorUpdate(false);
1321 owner->getMiniBuffer()->Set(CurrentState());
1326 if(!owner->currentBuffer()->text->mark_set) BeforeChange();
1327 owner->currentBuffer()->update(-3);
1328 owner->currentBuffer()->text->CursorUp();
1329 owner->currentBuffer()->text->FinishUndo();
1330 moveCursorUpdate(false);
1331 owner->getMiniBuffer()->Set(CurrentState());
1335 if(!owner->currentBuffer()->text->mark_set)
1337 owner->currentBuffer()->update(-3);
1338 owner->currentBuffer()->text->CursorDown();
1339 owner->currentBuffer()->text->FinishUndo();
1340 moveCursorUpdate(false);
1341 owner->getMiniBuffer()->Set(CurrentState());
1344 case LFUN_UP_PARAGRAPH:
1345 if(!owner->currentBuffer()->text->mark_set)
1347 owner->currentBuffer()->update(-3);
1348 owner->currentBuffer()->text->CursorUpParagraph();
1349 owner->currentBuffer()->text->FinishUndo();
1350 moveCursorUpdate(false);
1351 owner->getMiniBuffer()->Set(CurrentState());
1354 case LFUN_DOWN_PARAGRAPH:
1355 if(!owner->currentBuffer()->text->mark_set)
1357 owner->currentBuffer()->update(-3);
1358 owner->currentBuffer()->text->CursorDownParagraph();
1359 owner->currentBuffer()->text->FinishUndo();
1360 moveCursorUpdate(false);
1361 owner->getMiniBuffer()->Set(CurrentState());
1365 if(!owner->currentBuffer()->text->mark_set)
1367 owner->currentBuffer()->update(-3);
1368 owner->currentView()->cursorPrevious();
1369 owner->currentBuffer()->text->FinishUndo();
1370 moveCursorUpdate(false);
1371 owner->getMiniBuffer()->Set(CurrentState());
1375 if(!owner->currentBuffer()->text->mark_set)
1377 owner->currentBuffer()->update(-3);
1378 owner->currentView()->cursorNext();
1379 owner->currentBuffer()->text->FinishUndo();
1380 moveCursorUpdate(false);
1381 owner->getMiniBuffer()->Set(CurrentState());
1385 if(!owner->currentBuffer()->text->mark_set)
1387 owner->currentBuffer()->update(-2);
1388 owner->currentBuffer()->text->CursorHome();
1389 owner->currentBuffer()->text->FinishUndo();
1390 moveCursorUpdate(false);
1391 owner->getMiniBuffer()->Set(CurrentState());
1395 if(!owner->currentBuffer()->text->mark_set)
1397 owner->currentBuffer()->update(-2);
1398 owner->currentBuffer()->text->CursorEnd();
1399 owner->currentBuffer()->text->FinishUndo();
1400 moveCursorUpdate(false);
1401 owner->getMiniBuffer()->Set(CurrentState());
1405 if(!owner->currentBuffer()->text->mark_set)
1407 owner->currentBuffer()->update(-2);
1408 owner->currentBuffer()->text->CursorTab();
1409 owner->currentBuffer()->text->FinishUndo();
1410 moveCursorUpdate(false);
1411 owner->getMiniBuffer()->Set(CurrentState());
1414 case LFUN_WORDRIGHT:
1415 if(!owner->currentBuffer()->text->mark_set)
1417 owner->currentBuffer()->update(-2);
1418 owner->currentBuffer()->text->CursorRightOneWord();
1419 owner->currentBuffer()->text->FinishUndo();
1420 moveCursorUpdate(false);
1421 owner->getMiniBuffer()->Set(CurrentState());
1425 if(!owner->currentBuffer()->text->mark_set)
1427 owner->currentBuffer()->update(-2);
1428 owner->currentBuffer()->text->CursorLeftOneWord();
1429 owner->currentBuffer()->text->FinishUndo();
1430 moveCursorUpdate(false);
1431 owner->getMiniBuffer()->Set(CurrentState());
1434 case LFUN_BEGINNINGBUF:
1435 if(!owner->currentBuffer()->text->mark_set)
1437 owner->currentBuffer()->update(-2);
1438 owner->currentBuffer()->text->CursorTop();
1439 owner->currentBuffer()->text->FinishUndo();
1440 moveCursorUpdate(false);
1441 owner->getMiniBuffer()->Set(CurrentState());
1445 if(!owner->currentBuffer()->text->mark_set)
1447 owner->currentBuffer()->update(-2);
1448 owner->currentBuffer()->text->CursorBottom();
1449 owner->currentBuffer()->text->FinishUndo();
1450 moveCursorUpdate(false);
1451 owner->getMiniBuffer()->Set(CurrentState());
1455 /* cursor selection ---------------------------- */
1457 owner->currentBuffer()->update(-2);
1458 owner->currentBuffer()->text->CursorRight();
1459 owner->currentBuffer()->text->FinishUndo();
1460 moveCursorUpdate(true);
1461 owner->getMiniBuffer()->Set(CurrentState());
1465 owner->currentBuffer()->update(-2);
1466 owner->currentBuffer()->text->CursorLeft();
1467 owner->currentBuffer()->text->FinishUndo();
1468 moveCursorUpdate(true);
1469 owner->getMiniBuffer()->Set(CurrentState());
1473 owner->currentBuffer()->update(-2);
1474 owner->currentBuffer()->text->CursorUp();
1475 owner->currentBuffer()->text->FinishUndo();
1476 moveCursorUpdate(true);
1477 owner->getMiniBuffer()->Set(CurrentState());
1481 owner->currentBuffer()->update(-2);
1482 owner->currentBuffer()->text->CursorDown();
1483 owner->currentBuffer()->text->FinishUndo();
1484 moveCursorUpdate(true);
1485 owner->getMiniBuffer()->Set(CurrentState());
1488 case LFUN_UP_PARAGRAPHSEL:
1489 owner->currentBuffer()->update(-2);
1490 owner->currentBuffer()->text->CursorUpParagraph();
1491 owner->currentBuffer()->text->FinishUndo();
1492 moveCursorUpdate(true);
1493 owner->getMiniBuffer()->Set(CurrentState());
1496 case LFUN_DOWN_PARAGRAPHSEL:
1497 owner->currentBuffer()->update(-2);
1498 owner->currentBuffer()->text->CursorDownParagraph();
1499 owner->currentBuffer()->text->FinishUndo();
1500 moveCursorUpdate(true);
1501 owner->getMiniBuffer()->Set(CurrentState());
1505 owner->currentBuffer()->update(-2);
1506 owner->currentView()->cursorPrevious();
1507 owner->currentBuffer()->text->FinishUndo();
1508 moveCursorUpdate(true);
1509 owner->getMiniBuffer()->Set(CurrentState());
1513 owner->currentBuffer()->update(-2);
1514 owner->currentView()->cursorNext();
1515 owner->currentBuffer()->text->FinishUndo();
1516 moveCursorUpdate(true);
1517 owner->getMiniBuffer()->Set(CurrentState());
1521 owner->currentBuffer()->update(-2);
1522 owner->currentBuffer()->text->CursorHome();
1523 owner->currentBuffer()->text->FinishUndo();
1524 moveCursorUpdate(true);
1525 owner->getMiniBuffer()->Set(CurrentState());
1529 owner->currentBuffer()->update(-2);
1530 owner->currentBuffer()->text->CursorEnd();
1531 owner->currentBuffer()->text->FinishUndo();
1532 moveCursorUpdate(true);
1533 owner->getMiniBuffer()->Set(CurrentState());
1536 case LFUN_WORDRIGHTSEL:
1537 owner->currentBuffer()->update(-2);
1538 owner->currentBuffer()->text->CursorRightOneWord();
1539 owner->currentBuffer()->text->FinishUndo();
1540 moveCursorUpdate(true);
1541 owner->getMiniBuffer()->Set(CurrentState());
1544 case LFUN_WORDLEFTSEL:
1545 owner->currentBuffer()->update(-2);
1546 owner->currentBuffer()->text->CursorLeftOneWord();
1547 owner->currentBuffer()->text->FinishUndo();
1548 moveCursorUpdate(true);
1549 owner->getMiniBuffer()->Set(CurrentState());
1552 case LFUN_BEGINNINGBUFSEL:
1553 owner->currentBuffer()->update(-2);
1554 owner->currentBuffer()->text->CursorTop();
1555 owner->currentBuffer()->text->FinishUndo();
1556 moveCursorUpdate(true);
1557 owner->getMiniBuffer()->Set(CurrentState());
1560 case LFUN_ENDBUFSEL:
1561 owner->currentBuffer()->update(-2);
1562 owner->currentBuffer()->text->CursorBottom();
1563 owner->currentBuffer()->text->FinishUndo();
1564 moveCursorUpdate(true);
1565 owner->getMiniBuffer()->Set(CurrentState());
1568 // --- text changing commands ------------------------
1569 case LFUN_BREAKLINE:
1571 owner->currentBuffer()->text->InsertChar(LYX_META_NEWLINE);
1573 SetUpdateTimer(0.01);
1574 moveCursorUpdate(false);
1577 case LFUN_PROTECTEDSPACE:
1579 owner->currentBuffer()->text->
1580 InsertChar(LYX_META_PROTECTED_SEPARATOR);
1583 moveCursorUpdate(false);
1587 if(owner->currentBuffer()->text->mark_set) {
1589 owner->currentBuffer()->update(0);
1590 setMessage(N_("Mark removed"));
1593 owner->currentBuffer()->text->mark_set = 1;
1594 owner->currentBuffer()->update(0);
1595 setMessage(N_("Mark set"));
1597 owner->currentBuffer()->text->sel_cursor =
1598 owner->currentBuffer()->text->cursor;
1603 if (!owner->currentBuffer()->text->selection) {
1604 owner->currentBuffer()->text->Delete();
1605 owner->currentBuffer()->text->sel_cursor =
1606 owner->currentBuffer()->text->cursor;
1608 // It is possible to make it a lot faster still
1609 // just comment out the lone below...
1610 owner->currentView()->getScreen()->ShowCursor();
1617 case LFUN_DELETE_SKIP:
1619 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1621 LyXCursor cursor = owner->currentBuffer()->text->cursor;
1624 if (!owner->currentBuffer()->text->selection) {
1625 if (cursor.pos == cursor.par->Last()) {
1626 owner->currentBuffer()->text->CursorRight();
1627 cursor = owner->currentBuffer()->text->cursor;
1629 && !(cursor.par->added_space_top
1630 == VSpace (VSpace::NONE))) {
1631 owner->currentBuffer()->text->SetParagraph
1632 (cursor.par->line_top,
1633 cursor.par->line_bottom,
1634 cursor.par->pagebreak_top,
1635 cursor.par->pagebreak_bottom,
1636 VSpace(VSpace::NONE),
1637 cursor.par->added_space_bottom,
1639 cursor.par->labelwidthstring, 0);
1640 owner->currentBuffer()->text->CursorLeft();
1641 owner->currentBuffer()->update (1);
1643 owner->currentBuffer()->text->CursorLeft();
1644 owner->currentBuffer()->text->Delete();
1645 owner->currentBuffer()->text->sel_cursor =
1646 owner->currentBuffer()->text->cursor;
1650 owner->currentBuffer()->text->Delete();
1651 owner->currentBuffer()->text->sel_cursor =
1652 owner->currentBuffer()->text->cursor;
1662 /* -------> Delete word forward. */
1663 case LFUN_DELETE_WORD_FORWARD:
1664 owner->currentBuffer()->update(-2);
1666 owner->currentBuffer()->text->DeleteWordForward();
1667 owner->currentBuffer()->update( 1 );
1669 moveCursorUpdate(false);
1672 /* -------> Delete word backward. */
1673 case LFUN_DELETE_WORD_BACKWARD:
1674 owner->currentBuffer()->update(-2);
1676 owner->currentBuffer()->text->DeleteWordBackward();
1677 owner->currentBuffer()->update( 1 );
1679 moveCursorUpdate(false);
1682 /* -------> Kill to end of line. */
1683 case LFUN_DELETE_LINE_FORWARD:
1685 owner->currentBuffer()->update(-2);
1686 owner->currentBuffer()->text->DeleteLineForward();
1687 owner->currentBuffer()->update( 1 );
1689 moveCursorUpdate(false);
1692 /* -------> Set mark off. */
1695 owner->currentBuffer()->update(0);
1696 owner->currentBuffer()->text->sel_cursor =
1697 owner->currentBuffer()->text->cursor;
1698 setMessage(N_("Mark off"));
1701 /* -------> Set mark on. */
1704 owner->currentBuffer()->text->mark_set = 1;
1705 owner->currentBuffer()->update( 0 );
1706 owner->currentBuffer()->text->sel_cursor =
1707 owner->currentBuffer()->text->cursor;
1708 setMessage(N_("Mark on"));
1711 case LFUN_BACKSPACE:
1714 if (!owner->currentBuffer()->text->selection) {
1715 if (owner->getIntl()->getTrans()->backspace()) {
1716 owner->currentBuffer()->text->Backspace();
1717 owner->currentBuffer()->text->sel_cursor =
1718 owner->currentBuffer()->text->cursor;
1720 // It is possible to make it a lot faster still
1721 // just comment out the lone below...
1722 owner->currentView()->getScreen()->ShowCursor();
1731 case LFUN_BACKSPACE_SKIP:
1733 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1735 LyXCursor cursor = owner->currentBuffer()->text->cursor;
1738 if (!owner->currentBuffer()->text->selection) {
1740 && !(cursor.par->added_space_top
1741 == VSpace (VSpace::NONE))) {
1742 owner->currentBuffer()->text->SetParagraph
1743 (cursor.par->line_top,
1744 cursor.par->line_bottom,
1745 cursor.par->pagebreak_top,
1746 cursor.par->pagebreak_bottom,
1747 VSpace(VSpace::NONE), cursor.par->added_space_bottom,
1749 cursor.par->labelwidthstring, 0);
1750 owner->currentBuffer()->update (1);
1752 owner->currentBuffer()->text->Backspace();
1753 owner->currentBuffer()->text->sel_cursor
1763 case LFUN_BREAKPARAGRAPH:
1766 owner->currentBuffer()->text->BreakParagraph(0);
1768 SetUpdateTimer(0.01);
1769 owner->currentBuffer()->text->sel_cursor =
1770 owner->currentBuffer()->text->cursor;
1774 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1777 owner->currentBuffer()->text->BreakParagraph(1);
1779 SetUpdateTimer(0.01);
1780 owner->currentBuffer()->text->sel_cursor =
1781 owner->currentBuffer()->text->cursor;
1785 case LFUN_BREAKPARAGRAPH_SKIP:
1787 // When at the beginning of a paragraph, remove
1788 // indentation and add a "defskip" at the top.
1789 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
1791 LyXCursor cursor = owner->currentBuffer()->text->cursor;
1794 if (cursor.pos == 0) {
1795 if (cursor.par->added_space_top == VSpace(VSpace::NONE)) {
1796 owner->currentBuffer()->text->SetParagraph
1797 (cursor.par->line_top,
1798 cursor.par->line_bottom,
1799 cursor.par->pagebreak_top,
1800 cursor.par->pagebreak_bottom,
1801 VSpace(VSpace::DEFSKIP), cursor.par->added_space_bottom,
1803 cursor.par->labelwidthstring, 1);
1804 owner->currentBuffer()->update(1);
1808 owner->currentBuffer()->text->BreakParagraph(0);
1811 SetUpdateTimer(0.01);
1812 owner->currentBuffer()->text->sel_cursor = cursor;
1818 owner->currentBuffer()->text->InsertChar('\"'); // This " matches the single quote in the code
1821 moveCursorUpdate(false);
1827 InsetCommand *new_inset;
1828 if (action == LFUN_HTMLURL)
1829 new_inset = new InsetUrl("htmlurl", "", "");
1831 new_inset = new InsetUrl("url", "", "");
1832 owner->currentBuffer()->insertInset(new_inset);
1833 new_inset->Edit(0, 0);
1837 // --- lyxserver commands ----------------------------
1839 case LFUN_CHARATCURSOR:
1841 int pos = owner->currentBuffer()->text->cursor.pos;
1842 if(pos < owner->currentBuffer()->text->cursor.par->last)
1843 dispatch_buffer = owner->currentBuffer()->text->
1844 cursor.par->text[pos];
1846 dispatch_buffer = "EOF";
1852 tostr(owner->currentBuffer()->text->cursor.x) + ' '
1853 + tostr(owner->currentBuffer()->text->cursor.y);
1860 sscanf(argument, " %d %ld", &x, &y);
1861 owner->currentBuffer()->text->SetCursorFromCoordinates(x, y);
1865 case LFUN_GETLAYOUT:
1867 tostr(owner->currentBuffer()->text->cursor.par->layout);
1872 LyXFont *font = &(owner->currentBuffer()->text->current_font);
1873 if(font->shape() == LyXFont::ITALIC_SHAPE)
1874 dispatch_buffer = 'E';
1875 else if(font->shape() == LyXFont::SMALLCAPS_SHAPE)
1876 dispatch_buffer = 'N';
1878 dispatch_buffer = '0';
1885 LyXFont *font = &(owner->currentBuffer()->text->current_font);
1886 if(font->latex() == LyXFont::ON)
1887 dispatch_buffer = 'L';
1889 dispatch_buffer = '0';
1894 setMessage(owner->currentBuffer()->getFileName());
1895 lyxerr.debug() << "FNAME["
1896 << owner->currentBuffer()->getFileName()
1903 keyseq.print(buf,100);
1904 dispatch_buffer = buf;
1905 lyxserver->notifyClient(dispatch_buffer);
1909 case LFUN_GOTOFILEROW:
1911 char file_name[100];
1913 sscanf(argument, " %s %d", file_name, &row);
1915 // Must replace extension of the file to be .lyx and get full path
1916 string s = ChangeExtension(string(file_name), ".lyx", false);
1918 // Either change buffer or load the file
1919 if (bufferlist.exists(s))
1920 owner->currentView()->setBuffer(bufferlist.getBuffer(s));
1922 owner->currentView()->setBuffer(bufferlist.loadLyXFile(s));
1925 owner->currentBuffer()->setCursorFromRow(row);
1929 if (owner->currentBuffer()->text->cursor.y >
1930 owner->currentView()->getWorkArea()->h / 2) {
1931 owner->currentView()->getScreen()->
1932 Draw(owner->currentBuffer()->text->cursor.y -
1933 owner->currentView()->getWorkArea()->h/2);
1935 owner->currentView()->getScreen()->
1938 owner->currentBuffer()->update(0);
1939 owner->currentView()->redraw();
1946 int qa = lyxaction.LookupFunc((const char*)argument);
1947 setMessage(lyxaction.helpText((kb_action)qa));
1951 // --- accented characters ---------------------------
1954 case LFUN_CIRCUMFLEX:
1964 case LFUN_SPECIAL_CARON:
1967 case LFUN_HUNG_UMLAUT:
1973 if (keyseq.length==-1 && keyseq.getiso()!=0)
1978 owner->getIntl()->getTrans()->
1979 deadkey(c, get_accent(action).accent,
1980 owner->currentBuffer()->text);
1982 // Need to reset, in case the minibuffer calls these
1987 // copied verbatim from do_accent_char
1990 owner->currentBuffer()->text->sel_cursor =
1991 owner->currentBuffer()->text->cursor;
1995 // --- toolbar ----------------------------------
1996 case LFUN_PUSH_TOOLBAR:
1998 int nth = atoi(argument);
1999 if (lyxerr.debugging(Debug::TOOLBAR)) {
2000 lyxerr << "LFUN_PUSH_TOOLBAR: argument = `"
2001 << argument << "'\n"
2002 << "LFUN_PUSH_TOOLBAR: nth = `"
2003 << nth << "'" << endl;
2008 setErrorMessage(N_("Push-toolbar needs argument > 0"));
2010 owner->getToolbar()->push(nth);
2015 case LFUN_ADD_TO_TOOLBAR:
2017 if (lyxerr.debugging(Debug::TOOLBAR)) {
2018 lyxerr << "LFUN_ADD_TO_TOOLBAR:"
2019 "argument = `" << argument << '\'' << endl;
2021 string tmp(argument);
2022 //lyxerr <<string("Argument: ") + argument);
2023 //lyxerr <<string("Tmp : ") + tmp);
2026 setErrorMessage(N_("Usage: toolbar-add-to <LyX command>"));
2028 owner->getToolbar()->add(argument, false);
2029 owner->getToolbar()->set();
2034 // --- insert characters ----------------------------------------
2036 case LFUN_INSERT_INSET_LATEX:
2038 Inset *new_inset = new InsetLatex(argument);
2039 owner->currentBuffer()->insertInset(new_inset);
2043 // --- Mathed stuff. If we are here, there is no locked inset yet.
2048 if (!greek_kb_flag) {
2050 setMessage(N_("Math greek mode on"));
2057 case LFUN_GREEK_TOGGLE:
2059 greek_kb_flag = (greek_kb_flag) ? 0: 2;
2060 if (greek_kb_flag) {
2061 setMessage(N_("Math greek keyboard on"));
2063 setMessage(N_("Math greek keyboard off"));
2068 case LFUN_MATH_DELIM:
2069 case LFUN_INSERT_MATRIX:
2071 if (owner->currentView()->available()) {
2072 owner->currentBuffer()->
2073 open_new_inset(new InsetFormula(false));
2074 owner->currentBuffer()->
2075 the_locking_inset->LocalDispatch(action, argument);
2080 case LFUN_INSERT_MATH:
2082 math_insert_symbol(argument);
2086 case LFUN_MATH_DISPLAY:
2088 if (owner->currentView()->available())
2089 owner->currentBuffer()->open_new_inset(new InsetFormula(true));
2093 case LFUN_MATH_MACRO:
2095 if (owner->currentView()->available()) {
2098 setErrorMessage(N_("Missing argument"));
2100 string s1 = token(s, ' ', 1);
2101 int na = s1.empty() ? 0: atoi(s1.c_str());
2102 owner->currentBuffer()->
2103 open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2109 case LFUN_MATH_MODE: // Open or create a math inset
2112 if (owner->currentView()->available())
2113 owner->currentBuffer()->open_new_inset(new InsetFormula);
2114 setMessage(N_("Math editor mode"));
2118 case LFUN_MATH_NUMBER:
2119 case LFUN_MATH_LIMITS:
2121 setErrorMessage(N_("This is only allowed in math mode!"));
2125 case LFUN_INSERT_CITATION:
2127 InsetCitation *new_inset = new InsetCitation();
2129 // The note, if any, must be after the key, delimited
2130 // by a | so both key and remark can have spaces.
2132 string lsarg(argument);
2133 if (contains(lsarg, "|")) {
2134 new_inset->setContents(token(lsarg, '|', 0));
2135 new_inset->setOptions(token(lsarg, '|', 1));
2137 new_inset->setContents(lsarg);
2138 owner->currentBuffer()->insertInset(new_inset);
2140 owner->currentBuffer()->insertInset(new_inset);
2141 new_inset->Edit(0,0);
2146 case LFUN_INSERT_BIBTEX:
2148 // ale970405+lasgoutt970425
2149 // The argument can be up to two tokens separated
2150 // by a space. The first one is the bibstyle.
2151 string lsarg(argument);
2152 string bibstyle = token(lsarg, ' ', 1);
2153 if (bibstyle.empty())
2155 InsetBibtex *new_inset
2156 = new InsetBibtex(token(lsarg, ' ', 0),
2158 owner->currentBuffer());
2160 owner->currentBuffer()->insertInset(new_inset);
2161 if (lsarg.empty()) {
2162 new_inset->Edit(0,0);
2167 // BibTeX data bases
2168 case LFUN_BIBDB_ADD:
2170 InsetBibtex *inset =
2171 (InsetBibtex*)getInsetByCode(Inset::BIBTEX_CODE);
2173 inset->addDatabase(argument);
2178 case LFUN_BIBDB_DEL:
2180 InsetBibtex *inset =
2181 (InsetBibtex*)getInsetByCode(Inset::BIBTEX_CODE);
2183 inset->delDatabase(argument);
2188 case LFUN_BIBTEX_STYLE:
2190 InsetBibtex *inset =
2191 (InsetBibtex*)getInsetByCode(Inset::BIBTEX_CODE);
2193 inset->setOptions(argument);
2198 case LFUN_INDEX_INSERT:
2199 case LFUN_INDEX_INSERT_LAST:
2201 InsetIndex *new_inset = new InsetIndex();
2203 string lsarg(argument);
2204 new_inset->setContents(lsarg);
2205 owner->currentBuffer()->insertInset(new_inset);
2208 //get the current word for an argument
2213 int lastpos =owner->currentBuffer()->text->cursor.pos-1;
2215 //this shouldn't happen, but let's be careful
2216 if (lastpos < 0) lastpos=0;
2218 // get the current word
2219 // note that this must be done before
2220 // inserting the inset, or the inset will break
2222 string curstring(owner->currentBuffer()->text->cursor.par->GetWord(lastpos));
2224 //make the new inset and write the current word into it
2225 InsetIndex *new_inset = new InsetIndex();
2227 new_inset->setContents(curstring);
2229 //don't edit it if the call was to INSERT_LAST
2230 if(action!=LFUN_INDEX_INSERT_LAST) {
2231 new_inset->Edit(0,0);
2233 //it looks blank on the screen unless
2234 //we do something. put it here.
2236 // move the cursor to the returned value of lastpos
2237 // but only for the auto-insert
2238 owner->currentBuffer()->text->cursor.pos=lastpos;
2241 //put the new inset into the buffer.
2242 // there should be some way of knowing the user
2243 //cancelled & avoiding this, but i don't know how
2244 owner->currentBuffer()->insertInset(new_inset);
2249 case LFUN_INDEX_PRINT:
2251 Inset *new_inset = new InsetPrintIndex(owner->currentBuffer());
2252 owner->currentBuffer()->insertInset(new_inset, "Standard", true);
2256 case LFUN_PARENTINSERT:
2258 lyxerr << "arg " << argument << endl;
2259 Inset *new_inset = new InsetParent(argument, owner->currentBuffer());
2260 owner->currentBuffer()->insertInset(new_inset, "Standard", true);
2264 case LFUN_CHILDINSERT:
2266 Inset *new_inset = new InsetInclude(argument,owner->currentBuffer());
2267 owner->currentBuffer()->insertInset(new_inset, "Standard", true);
2268 new_inset->Edit(0,0);
2272 case LFUN_CHILDOPEN:
2274 string filename = MakeAbsPath(argument,
2275 OnlyPath(owner->currentBuffer()->getFileName()));
2276 setMessage(N_("Opening child document ") +
2277 MakeDisplayPath(filename) + "...");
2278 owner->currentView()->savePosition();
2279 if (bufferlist.exists(filename))
2280 owner->currentView()->setBuffer(bufferlist.getBuffer(filename));
2282 owner->currentView()->setBuffer(bufferlist.loadLyXFile(filename));
2286 case LFUN_INSERT_NOTE:
2290 case LFUN_INSERTFOOTNOTE:
2292 LyXParagraph::footnote_kind kind;
2293 string arg = argument;
2294 if (arg == "footnote")
2295 { kind = LyXParagraph::FOOTNOTE; }
2296 else if (arg == "margin")
2297 { kind = LyXParagraph::MARGIN; }
2298 else if (arg == "figure")
2299 { kind = LyXParagraph::FIG; }
2300 else if (arg == "table")
2301 { kind = LyXParagraph::TAB; }
2302 else if (arg == "wide-fig")
2303 { kind = LyXParagraph::WIDE_FIG; }
2304 else if (arg == "wide-tab")
2305 { kind = LyXParagraph::WIDE_TAB; }
2306 else if (arg == "algorithm")
2307 { kind = LyXParagraph::ALGORITHM; }
2309 setErrorMessage(N_("Unknown kind of footnote"));
2312 owner->currentBuffer()->text->InsertFootnoteEnvironment(kind);
2313 owner->currentBuffer()->update(1);
2317 case LFUN_BUFFERBULLETSSELECT:
2321 case LFUN_TOGGLECURSORFOLLOW:
2322 cursor_follows_scrollbar = !cursor_follows_scrollbar;
2325 case LFUN_KMAP_OFF: // keymap off
2326 owner->getIntl()->KeyMapOn(false);
2329 case LFUN_KMAP_PRIM: // primary keymap
2330 owner->getIntl()->KeyMapPrim();
2333 case LFUN_KMAP_SEC: // secondary keymap
2334 owner->getIntl()->KeyMapSec();
2337 case LFUN_KMAP_TOGGLE: // toggle keymap
2338 owner->getIntl()->ToggleKeyMap();
2341 case LFUN_SELFINSERT:
2343 string const text = argument;
2344 for (string::size_type i = 0; i < text.length(); ++i) {
2345 owner->currentBuffer()->text->InsertChar(text[i]);
2346 // This needs to be in the loop, or else we
2347 // won't break lines correctly. (Asger)
2351 owner->currentBuffer()->text->sel_cursor =
2352 owner->currentBuffer()->text->cursor;
2353 moveCursorUpdate(false);
2357 case LFUN_UNKNOWN_ACTION:
2359 if (owner->currentBuffer()->isReadonly()) {
2361 setErrorMessage(N_("Document is read only"));
2367 /* Automatically delete the currently selected
2368 * text and replace it with what is being
2369 * typed in now. Depends on lyxrc settings
2370 * "auto_region_delete", which defaults to
2373 if ( lyxrc->auto_region_delete ) {
2374 if (owner->currentBuffer()->text->selection){
2375 owner->currentBuffer()->text->CutSelection(false);
2376 owner->currentBuffer()->update(-1);
2381 for(char const *p = argument; *p; p++) {
2382 if (greek_kb_flag) {
2383 if (!math_insert_greek(*p))
2384 owner->getIntl()->getTrans()->TranslateAndInsert(*p, owner->currentBuffer()->text);
2386 owner->getIntl()->getTrans()->TranslateAndInsert(*p, owner->currentBuffer()->text);
2392 owner->currentBuffer()->text->sel_cursor =
2393 owner->currentBuffer()->text->cursor;
2394 moveCursorUpdate(false);
2397 // why is an "Unknown action" with empty
2398 // argument even dispatched in the first
2399 // place? I`ll probably change that. (Lgb)
2401 setErrorMessage(N_("Unknown action"));
2405 lyxerr << "A truly unknown func!" << endl;
2411 string res=getMessage();
2414 if (!commandshortcut.empty()) {
2415 string newbuf = owner->getMiniBuffer()->GetText();
2416 if (newbuf != commandshortcut) {
2417 owner->getMiniBuffer()->Set(newbuf
2423 owner->getMiniBuffer()->Set(string(_(res.c_str()))
2424 + " " + commandshortcut);
2427 return getMessage();
2431 void LyXFunc::setupLocalKeymap()
2433 keyseq.stdmap = keyseq.curmap = toplevel_keymap;
2434 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap;
2438 void LyXFunc::MenuNew(bool fromTemplate)
2440 string fname, initpath = lyxrc->document_path;
2443 if (owner->currentView()->available()) {
2444 string trypath = owner->currentBuffer()->filepath;
2445 // If directory is writeable, use this as default.
2446 if (IsDirWriteable(trypath) == 1)
2451 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2452 fileDlg.SetButton(1, _("Templates"), lyxrc->template_path);
2453 fname = fileDlg.Select(_("Enter Filename for new document"),
2454 initpath, "*.lyx", _("newfile"));
2457 if (fname.empty()) {
2458 owner->getMiniBuffer()->Set(_("Canceled."));
2459 lyxerr.debug() << "New Document Cancelled." << endl;
2463 // get absolute path of file and make sure the filename ends
2465 string s = MakeAbsPath(fname);
2466 if (!IsLyXFilename(s))
2469 // Check if the document already is open
2470 if (bufferlist.exists(s)){
2471 switch(AskConfirmation(_("Document is already open:"),
2472 MakeDisplayPath(s,50),
2473 _("Do you want to close that document now?\n"
2474 "('No' will just switch to the open version)")))
2476 case 1: // Yes: close the document
2477 if (!bufferlist.close(bufferlist.getBuffer(s)))
2478 // If close is canceled, we cancel here too.
2481 case 2: // No: switch to the open document
2482 owner->currentView()->setBuffer(bufferlist.getBuffer(s));
2484 case 3: // Cancel: Do nothing
2485 owner->getMiniBuffer()->Set(_("Canceled."));
2490 // Check whether the file already exists
2491 if (IsLyXFilename(s)) {
2492 FilePtr myfile(s, FilePtr::read);
2494 AskQuestion(_("File already exists:"),
2495 MakeDisplayPath(s,50),
2496 _("Do you want to open the document?"))) {
2498 owner->getMiniBuffer()->Set(_("Opening document"),
2499 MakeDisplayPath(s), "...");
2501 owner->currentView()->setBuffer(
2502 bufferlist.loadLyXFile(s));
2503 owner->getMiniBuffer()->Set(_("Document"),
2510 // The template stuff
2514 fname = fileDlg.Select(_("Choose template"),
2515 lyxrc->template_path,
2521 // find a free buffer
2522 lyxerr.debug() << "Find a free buffer." << endl;
2523 owner->currentView()->setBuffer(bufferlist.newFile(s,templname));
2527 void LyXFunc::MenuOpen()
2529 string initpath = lyxrc->document_path;
2532 if (owner->currentView()->available()) {
2533 string trypath = owner->currentBuffer()->filepath;
2534 // If directory is writeable, use this as default.
2535 if (IsDirWriteable(trypath) == 1)
2541 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2542 fileDlg.SetButton(1, _("Examples"),
2543 AddPath(system_lyxdir, "examples"));
2544 string filename = fileDlg.Select(_("Select Document to Open"),
2548 // check selected filename
2549 if (filename.empty()) {
2550 owner->getMiniBuffer()->Set(_("Canceled."));
2554 // get absolute path of file and make sure the filename ends
2556 filename = MakeAbsPath(filename);
2557 if (!IsLyXFilename(filename))
2561 owner->getMiniBuffer()->Set(_("Opening document"),
2562 MakeDisplayPath(filename), "...");
2563 Buffer * openbuf = bufferlist.loadLyXFile(filename);
2565 owner->currentView()->setBuffer(openbuf);
2566 owner->getMiniBuffer()->Set(_("Document"),
2567 MakeDisplayPath(filename),
2570 owner->getMiniBuffer()->Set(_("Could not open document"),
2571 MakeDisplayPath(filename));
2576 void LyXFunc::doImportASCII(bool linorpar)
2578 string initpath = lyxrc->document_path;
2581 if (owner->currentView()->available()) {
2582 string trypath = owner->currentBuffer()->filepath;
2583 // If directory is writeable, use this as default.
2584 if (IsDirWriteable(trypath) == 1)
2590 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2591 fileDlg.SetButton(1, _("Examples"),
2592 AddPath(system_lyxdir, "examples"));
2593 string filename = fileDlg.Select(_("Select ASCII file to Import"),
2597 // check selected filename
2598 if (filename.empty()) {
2599 owner->getMiniBuffer()->Set(_("Canceled."));
2603 // get absolute path of file
2604 filename = MakeAbsPath(filename);
2606 string s = ChangeExtension(filename, ".lyx", false);
2608 // Check if the document already is open
2609 if (bufferlist.exists(s)){
2610 switch(AskConfirmation(_("Document is already open:"),
2611 MakeDisplayPath(s,50),
2612 _("Do you want to close that document now?\n"
2613 "('No' will just switch to the open version)")))
2615 case 1: // Yes: close the document
2616 if (!bufferlist.close(bufferlist.getBuffer(s)))
2617 // If close is canceled, we cancel here too.
2620 case 2: // No: switch to the open document
2621 owner->currentView()->setBuffer(bufferlist.getBuffer(s));
2623 case 3: // Cancel: Do nothing
2624 owner->getMiniBuffer()->Set(_("Canceled."));
2629 // Check if a LyX document by the same root exists in filesystem
2630 FileInfo f(s, true);
2631 if (f.exist() && !AskQuestion(_("A document by the name"),
2633 _("already exists. Overwrite?"))) {
2634 owner->getMiniBuffer()->Set(_("Canceled."));
2638 owner->currentView()->setBuffer(bufferlist.newFile(s,string()));
2639 owner->getMiniBuffer()->Set(_("Importing ASCII file"),
2640 MakeDisplayPath(filename), "...");
2641 // Insert ASCII file
2642 InsertAsciiFile(filename,linorpar);
2643 owner->getMiniBuffer()->Set(_("ASCII file "),
2644 MakeDisplayPath(filename),
2649 void LyXFunc::doImportLaTeX(bool isnoweb)
2651 string initpath = lyxrc->document_path;
2654 if (owner->currentView()->available()) {
2655 string trypath = owner->currentBuffer()->filepath;
2656 // If directory is writeable, use this as default.
2657 if (IsDirWriteable(trypath) == 1)
2663 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2664 fileDlg.SetButton(1, _("Examples"),
2665 AddPath(system_lyxdir, "examples"));
2668 filename = fileDlg.Select(_("Select Noweb file to Import"),
2671 filename = fileDlg.Select(_("Select LaTeX file to Import"),
2677 // check selected filename
2678 if (filename.empty()) {
2679 owner->getMiniBuffer()->Set(_("Canceled."));
2683 // get absolute path of file
2684 filename = MakeAbsPath(filename);
2686 // Check if the document already is open
2687 string LyXfilename = ChangeExtension(filename, ".lyx", false);
2688 if (bufferlist.exists(LyXfilename)){
2689 switch(AskConfirmation(_("Document is already open:"),
2690 MakeDisplayPath(LyXfilename,50),
2691 _("Do you want to close that document now?\n"
2692 "('No' will just switch to the open version)")))
2694 case 1: // Yes: close the document
2695 if (!bufferlist.close(bufferlist.getBuffer(LyXfilename)))
2696 // If close is canceled, we cancel here too.
2699 case 2: // No: switch to the open document
2700 owner->currentView()->setBuffer(
2701 bufferlist.getBuffer(LyXfilename));
2703 case 3: // Cancel: Do nothing
2704 owner->getMiniBuffer()->Set(_("Canceled."));
2709 // Check if a LyX document by the same root exists in filesystem
2710 FileInfo f(LyXfilename, true);
2711 if (f.exist() && !AskQuestion(_("A document by the name"),
2712 MakeDisplayPath(LyXfilename),
2713 _("already exists. Overwrite?"))) {
2714 owner->getMiniBuffer()->Set(_("Canceled."));
2721 owner->getMiniBuffer()->Set(_("Importing LaTeX file"),
2722 MakeDisplayPath(filename), "...");
2723 ImportLaTeX myImport(filename);
2724 openbuf = myImport.run();
2726 owner->getMiniBuffer()->Set(_("Importing Noweb file"),
2727 MakeDisplayPath(filename), "...");
2728 ImportNoweb myImport(filename);
2729 openbuf = myImport.run();
2732 owner->currentView()->setBuffer(openbuf);
2733 owner->getMiniBuffer()->Set(isnoweb ?
2734 _("Noweb file ") : _("LateX file "),
2735 MakeDisplayPath(filename),
2738 owner->getMiniBuffer()->Set(isnoweb ?
2739 _("Could not import Noweb file") :
2740 _("Could not import LaTeX file"),
2741 MakeDisplayPath(filename));
2746 void LyXFunc::MenuInsertLyXFile(string const & filen)
2748 string filename = filen;
2750 if (filename.empty()) {
2751 // Launch a file browser
2752 string initpath = lyxrc->document_path;
2755 if (owner->currentView()->available()) {
2756 string trypath = owner->currentBuffer()->filepath;
2757 // If directory is writeable, use this as default.
2758 if (IsDirWriteable(trypath) == 1)
2764 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2765 fileDlg.SetButton(1, _("Examples"),
2766 AddPath(system_lyxdir, "examples"));
2767 filename = fileDlg.Select(_("Select Document to Insert"),
2771 // check selected filename
2772 if (filename.empty()) {
2773 owner->getMiniBuffer()->Set(_("Canceled."));
2778 // get absolute path of file and make sure the filename ends
2780 filename = MakeAbsPath(filename);
2781 if (!IsLyXFilename(filename))
2785 owner->getMiniBuffer()->Set(_("Inserting document"),
2786 MakeDisplayPath(filename), "...");
2787 bool res = owner->currentBuffer()->insertLyXFile(filename);
2789 owner->getMiniBuffer()->Set(_("Document"),
2790 MakeDisplayPath(filename),
2793 owner->getMiniBuffer()->Set(_("Could not insert document"),
2794 MakeDisplayPath(filename));
2799 void LyXFunc::reloadBuffer()
2801 string fn = owner->currentBuffer()->getFileName();
2802 if (bufferlist.close(owner->currentBuffer()))
2803 owner->currentView()->setBuffer(bufferlist.loadLyXFile(fn));
2807 void LyXFunc::CloseBuffer()
2809 if (bufferlist.close(owner->currentBuffer()) && !quitting) {
2810 if (bufferlist.isEmpty()) {
2811 // need this otherwise SEGV may occur while trying to
2812 // set variables that don't exist
2813 // since there's no current buffer
2814 CloseAllBufferRelatedPopups();
2817 owner->currentView()->setBuffer(bufferlist.first());
2823 Inset* LyXFunc::getInsetByCode(Inset::Code code)
2827 LyXCursor cursor = owner->currentBuffer()->text->cursor;
2828 int pos = cursor.pos;
2829 LyXParagraph *par = cursor.par;
2831 while (par && !found) {
2832 while ((inset = par->ReturnNextInsetPointer(pos))){
2833 if (inset->LyxCode()==code) {
2841 return (found) ? inset: 0;
2845 // Each "owner" should have it's own message method. lyxview and
2846 // the minibuffer would use the minibuffer, but lyxserver would
2847 // send an ERROR signal to its client. Alejandro 970603
2848 // This func is bit problematic when it comes to NLS, to make the
2849 // lyx servers client be language indepenent we must not translate
2850 // strings sent to this func.
2851 void LyXFunc::setErrorMessage(string const &m)
2853 dispatch_buffer = m;
2858 void LyXFunc::setMessage(string const & m)
2860 dispatch_buffer = m;