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"
61 #include "support/syscall.h"
62 #include "support/lstrings.h"
64 extern bool cursor_follows_scrollbar;
66 extern void InsertAsciiFile(string const &, bool);
67 extern void math_insert_symbol(char const*);
68 extern Bool math_insert_greek(char const); // why "Bool"?
69 extern BufferList bufferlist;
70 extern LyXServer *lyxserver;
71 extern short greek_kb_flag;
72 extern FD_form_toc *fd_form_toc;
73 extern bool selection_possible;
75 extern kb_keymap *toplevel_keymap;
77 extern void BeforeChange();
78 extern void MenuWrite(Buffer*);
79 extern void MenuWriteAs(Buffer*);
80 extern int MenuRunLaTeX(Buffer*);
81 extern int MenuBuildProg(Buffer*);
82 extern int MenuRunChktex(Buffer*);
83 extern bool MenuRunDvips(Buffer *,bool);
84 extern void MenuPrint(Buffer*);
85 extern void MenuSendto();
86 extern void QuitLyX();
87 extern void MenuFax(Buffer *);
88 extern void MenuMakeLaTeX(Buffer *);
89 extern void MenuMakeLinuxDoc(Buffer *);
90 extern void MenuMakeDocBook(Buffer *);
91 extern void MenuMakeAscii(Buffer *);
92 extern void MenuPasteSelection(char at);
93 extern LyXAction lyxaction;
95 extern tex_accent_struct get_accent(kb_action action);
97 extern void AutoSave();
98 extern void MenuSearch();
100 extern void CopyEnvironmentCB();
101 extern void PasteEnvironmentCB();
102 extern void GotoNote();
103 extern void NoteCB();
104 extern void OpenStuff();
105 extern void HyphenationPoint();
107 extern void EndOfSentenceDot();
108 extern void MenuSeparator();
110 extern void MenuUndo();
111 extern void MenuRedo();
112 extern void SmallUpdate(signed char);
113 extern void SetUpdateTimer(float timer= 0.3);
114 extern void FreeUpdateTimer();
115 extern bool MenuPreview(Buffer*);
116 extern bool MenuPreviewPS(Buffer*);
117 extern void MenuInsertLabel(const char *);
118 extern void MenuInsertRef();
119 extern void MenuLayoutCharacter();
120 extern void MenuLayoutParagraph();
121 extern void MenuLayoutDocument();
122 extern void MenuLayoutPaper();
123 extern void MenuLayoutTable(int flag);
124 extern void MenuLayoutQuotes();
125 extern void MenuLayoutPreamble();
126 extern void MenuLayoutSave();
127 extern void bulletForm();
129 extern Buffer * NewLyxFile(string const &);
130 extern void LoadLyXFile(string const &);
131 extern void Reconfigure();
133 extern int current_layout;
134 extern int getISOCodeFromLaTeX(char *);
136 extern int UnlockInset(UpdatableInset*);
138 extern void ShowLatexLog();
140 extern void UpdateInset(Inset* inset, bool mark_dirty = true);
142 /* === globals =========================================================== */
144 bool LyXFunc::show_sc = true;
147 LyXFunc::LyXFunc(LyXView *o)
151 lyx_dead_action = LFUN_NOACTION;
152 lyx_calling_dead_action = LFUN_NOACTION;
162 // I changed this func slightly. I commented out the ...FinishUndo(),
163 // this means that all places that used to have a moveCursorUpdate, now
164 // have a ...FinishUndo() as the preceeding statement. I have also added
165 // a moveCursorUpdate to some of the functions that updated the cursor, but
166 // that did not show its new position.
168 void LyXFunc::moveCursorUpdate(bool selecting)
170 if (selecting || owner->currentBuffer()->text->mark_set) {
171 owner->currentBuffer()->text->SetSelection();
172 owner->currentView()->getScreen()->ToggleToggle();
173 owner->currentBuffer()->update(0);
175 owner->currentBuffer()->update(-2); // this IS necessary
178 owner->currentView()->getScreen()->ShowCursor();
180 /* ---> Everytime the cursor is moved, show the current font state. */
181 // should this too me moved out of this func?
182 //owner->getMiniBuffer()->Set(CurrentState());
186 int LyXFunc::processKeyEvent(XEvent *ev)
193 XKeyEvent *keyevent = &ev->xkey;
194 KeySym keysym_return;
196 num_bytes = LyXLookupString(ev, s_r, 10, &keysym_return);
198 if (lyxerr.debugging(Debug::KEY)) {
199 lyxerr << "KeySym is "
200 << XKeysymToString(keysym_return)
202 << keysym_return << "]"
203 << " and num_bytes is "
205 << " the string returned is \""
206 << s_r << '\"' << endl;
208 // Do nothing if we have nothing (JMarc)
209 if (num_bytes == 0 && keysym_return == NoSymbol) {
210 lyxerr[Debug::KEY] << "Empty kbd action (probably composing)"
215 // this function should be used always [asierra060396]
216 if (owner->currentView()->available() &&
217 owner->currentBuffer()->the_locking_inset &&
218 keysym_return == XK_Escape) {
219 UnlockInset(owner->currentBuffer()->the_locking_inset);
220 owner->currentBuffer()->text->CursorRight();
224 // Can we be sure that this will work for all X-Windows
225 // implementations? (Lgb)
226 // This code snippet makes lyx ignore some keys. Perhaps
227 // all of them should be explictly mentioned?
228 if((keysym_return >= XK_Shift_L && keysym_return <= XK_Hyper_R)
229 || keysym_return == XK_Mode_switch || keysym_return == 0x0)
232 // Do a one-deep top-level lookup for
233 // cancel and meta-fake keys. RVDK_PATCH_5
234 cancel_meta_seq.reset();
236 action = cancel_meta_seq.addkey(keysym_return, keyevent->state
237 &(ShiftMask|ControlMask
240 // When not cancel or meta-fake, do the normal lookup.
241 // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
242 // Mostly, meta_fake_bit = 0. RVDK_PATCH_5.
243 if ( (action != LFUN_CANCEL) && (action != LFUN_META_FAKE) ) {
245 // remove Caps Lock and Mod2 as a modifiers
246 action = keyseq.addkey(keysym_return,
247 (keyevent->state | meta_fake_bit)
248 &(ShiftMask|ControlMask
251 // Dont remove this unless you know what you are doing.
254 if (action == 0) action = LFUN_PREFIX;
256 if (lyxerr.debugging(Debug::KEY)) {
258 keyseq.print(buf,100);
262 << num_bytes << "]" << endl;
265 // already here we know if it any point in going further
266 // why not return already here if action == -1 and
267 // num_bytes == 0? (Lgb)
269 if(keyseq.length>1 || keyseq.length<-1){
271 keyseq.print(buf,100);
272 owner->getMiniBuffer()->Set(buf);
276 if (keyseq.length<-1) { // unknown key sequence...
279 keyseq.print(buf,100);
280 owner->getMiniBuffer()->Set(_("Unknown sequence:"),buf);
284 char isochar = keyseq.getiso();
285 if (!(keyevent->state&ControlMask) &&
286 !(keyevent->state&Mod1Mask) &&
287 (isochar && keysym_return < 0xF000)) {
290 if (argument.empty()) {
291 lyxerr.debug() << "Empty argument!" << endl;
292 // This can`t possibly be of any use
293 // so we`ll skip the dispatch.
297 if (action==LFUN_SELFINSERT) {
301 bool tmp_sc = show_sc;
303 Dispatch(action, argument.c_str());
310 string LyXFunc::Dispatch(string const &cmd, string const &arg)
312 return Dispatch(lyxaction.LookupFunc(cmd.c_str()),
317 string LyXFunc::Dispatch(int ac,
318 char const *do_not_use_this_arg)
324 FL_OBJECT *ob = 0; // This will disapear soon
326 // we have not done anything wrong yet.
328 dispatch_buffer = string();
330 // if action is a pseudo-action, we need the real action
331 if (lyxaction.isPseudoAction(ac)) {
332 char const *tmparg = 0;
333 action = (kb_action)lyxaction.retrieveActionArg(ac, &tmparg);
337 action = (kb_action)ac;
338 if (do_not_use_this_arg)
339 argument = do_not_use_this_arg; // except here
342 selection_possible = false;
344 if (owner->currentView()->available()
345 && owner->currentView()->getScreen())
346 owner->currentView()->getScreen()->HideCursor();
348 if(!owner->currentView()->available()) {
349 // This lists the allowed funcs when we have no
352 case LFUN_MENU_OPEN_BY_NAME:
355 case LFUN_MENUNEWTMPLT:
358 case LFUN_PUSH_TOOLBAR:
359 case LFUN_ADD_TO_TOOLBAR:
360 case LFUN_EXEC_COMMAND:
361 case LFUN_DROP_LAYOUTS_CHOICE:
365 case LFUN_RECONFIGURE:
371 case LFUN_UNKNOWN_ACTION:
372 setErrorMessage(N_("Unknown action"));
373 goto exit_with_message;
375 setErrorMessage(N_("Command not allowed with"
376 "out any document open"));
377 goto exit_with_message; // action not allowed
381 commandshortcut = string();
383 if (lyxrc->display_shortcuts && show_sc) {
384 if (action != LFUN_SELFINSERT) {
385 // Put name of command and list of shortcuts
386 // for it in minibuffer
387 string comname = lyxaction.getActionName(action);
389 int pseudoaction = action;
390 bool argsadded = false;
392 if (!argument.empty()) {
393 // If we have the command with argument,
396 lyxaction.searchActionArg(action,
399 if (pseudoaction == -1) {
400 pseudoaction = action;
402 comname += " " + argument;
407 string shortcuts = toplevel_keymap->findbinding(pseudoaction);
409 if (!shortcuts.empty()) {
410 comname += ": " + shortcuts;
411 } else if (!argsadded) {
412 comname += " " + argument;
415 if (!comname.empty()) {
416 comname = strip(comname);
417 commandshortcut = "(" + comname + ')';
418 owner->getMiniBuffer()->Set(commandshortcut);
419 // Here we could even add a small pause,
420 // to annoy the user and make him learn
422 // No! That will just annoy, not teach
423 // anything. The user will read the messages
424 // if they are interested. (Asger)
429 // Now that we know which action, if the buffer is RO let's check
430 // whether the action is legal. Alejandro 970603
431 if (owner->currentView()->available() &&
432 owner->currentBuffer()->isReadonly() &&
433 lyxaction.isFuncRO(action)) {
434 setErrorMessage(N_("Document is read-only"));
435 lyxerr.debug() << "Error: Document is read-only." << endl;
436 goto exit_with_message;
439 // If in math mode pass the control to
440 // the math inset [asierra060396]
441 if (owner->currentView()->available() &&
442 owner->currentBuffer()->the_locking_inset) {
443 if (action>1 || (action==LFUN_UNKNOWN_ACTION && keyseq.length>=-1)) {
444 if (action==LFUN_UNKNOWN_ACTION && argument.empty()) {
445 argument = keyseq.getiso();
447 // Undo/Redo pre 0.13 is a bit tricky for insets.
448 if (action==LFUN_UNDO) {
450 UpdatableInset* inset =
451 owner->currentBuffer()->the_locking_inset;
452 inset->GetCursorPos(slx, sly);
455 inset = (UpdatableInset*)owner->currentBuffer()->text->cursor.par->GetInset(owner->currentBuffer()->text->cursor.pos);
457 inset->Edit(slx, sly);
460 if (action==LFUN_REDO) {
462 UpdatableInset* inset = owner->currentBuffer()->the_locking_inset;
463 inset->GetCursorPos(slx, sly);
466 inset = (UpdatableInset*)owner->currentBuffer()->text->cursor.par->GetInset(owner->currentBuffer()->text->cursor.pos);
468 inset->Edit(slx, sly);
471 if (owner->currentBuffer()->the_locking_inset->LocalDispatch(action, argument.c_str()))
474 setMessage(N_("Text mode"));
475 if (action==LFUN_RIGHT || action==-1)
476 owner->currentBuffer()->text->CursorRight();
477 if (action==LFUN_LEFT || action==LFUN_RIGHT)
484 // --- Misc -------------------------------------------
485 case LFUN_WORDFINDFORWARD :
486 case LFUN_WORDFINDBACKWARD : {
488 static string last_search;
489 string searched_string;
491 if (!argument.empty()) {
492 last_search = argument;
493 searched_string = argument;
495 searched_string = last_search;
498 ltCur = owner->currentView()->currentBuffer()->text ;
500 if (!searched_string.empty() &&
501 ( (action == LFUN_WORDFINDBACKWARD) ?
502 ltCur->SearchBackward( searched_string.c_str() ) :
503 ltCur->SearchForward( searched_string.c_str() )
506 // ??? What is that ???
507 owner->currentView()->currentBuffer()->update(-2);
510 // clear the selection (if there is any)
511 owner->currentView()->getScreen()->ToggleSelection();
512 owner->currentView()->currentBuffer()->text->ClearSelection();
514 // Move cursor so that successive C-s 's will not stand in place.
515 if( action == LFUN_WORDFINDFORWARD )
516 owner->currentBuffer()->text->CursorRightOneWord();
517 owner->currentBuffer()->text->FinishUndo();
518 moveCursorUpdate(false);
521 // set the new selection
522 // SetSelectionOverLenChars(owner->currentView()->currentBuffer()->text, iLenSelected);
523 owner->currentView()->getScreen()->ToggleSelection(false);
527 // REMOVED : if (owner->currentView()->getWorkArea()->focus)
528 owner->currentView()->getScreen()->ShowCursor();
534 if (owner->currentView()->available()
535 && owner->currentView()->getScreen()) {
536 owner->currentBuffer()->update(-2);
539 keyseq.print(buf,100, true);
540 owner->getMiniBuffer()->Set(buf, string(), string(), 1);
544 // --- Misc -------------------------------------------
545 case LFUN_EXEC_COMMAND:
546 owner->getMiniBuffer()->ExecCommand();
549 case LFUN_CANCEL: // RVDK_PATCH_5
552 if(owner->currentView()->available())
553 // cancel any selection
554 Dispatch(int(LFUN_MARK_OFF), 0);
555 setMessage(N_("Cancel"));
558 case LFUN_META_FAKE: // RVDK_PATCH_5
560 meta_fake_bit = Mod1Mask;
562 keyseq.print(buf, 98, true);
563 string res = string("M-") + buf;
564 setMessage(buf); // RVDK_PATCH_5
568 case LFUN_READ_ONLY_TOGGLE:
569 if (owner->currentBuffer()->lyxvc.inUse()) {
570 owner->currentBuffer()->lyxvc.toggleReadOnly();
572 owner->currentBuffer()->setReadonly(
573 !owner->currentBuffer()->isReadonly());
577 case LFUN_CENTER: // this is center and redraw.
579 if (owner->currentBuffer()->text->cursor.y >
580 owner->currentView()->getWorkArea()->h / 2) {
581 owner->currentView()->getScreen()->
582 Draw(owner->currentBuffer()->text->cursor.y -
583 owner->currentView()->getWorkArea()->h/2);
585 owner->currentView()->getScreen()->
588 owner->currentBuffer()->update(0);
589 owner->currentView()->redraw();
593 if (owner->currentView()->available()) {
594 owner->currentBuffer()->text->toggleAppendix();
595 owner->currentBuffer()->update(1);
599 // --- Menus -----------------------------------------------
604 case LFUN_MENUNEWTMPLT:
612 case LFUN_CLOSEBUFFER:
617 MenuWrite(owner->currentBuffer());
620 case LFUN_MENUWRITEAS:
621 MenuWriteAs(owner->currentBuffer());
624 case LFUN_MENURELOAD:
629 MenuPreview(owner->currentBuffer());
633 MenuPreviewPS(owner->currentBuffer());
637 MenuRunLaTeX(owner->currentBuffer());
641 MenuBuildProg(owner->currentBuffer());
645 MenuRunChktex(owner->currentBuffer());
649 MenuRunDvips(owner->currentBuffer(), false);
653 MenuPrint(owner->currentBuffer());
657 MenuFax(owner->currentBuffer());
662 //needs argument as string
663 string extyp=argument;
666 if (extyp == "latex") {
667 // make sure that this buffer is not linuxdoc
668 MenuMakeLaTeX(owner->currentBuffer());
671 else if (extyp == "linuxdoc") {
672 // make sure that this buffer is not latex
673 MenuMakeLinuxDoc(owner->currentBuffer());
676 else if (extyp == "docbook") {
677 // make sure that this buffer is not latex or linuxdoc
678 MenuMakeDocBook(owner->currentBuffer());
681 else if (extyp == "dvi") {
682 // Run LaTeX as "Update dvi..." Bernhard.
683 // We want the dvi in the current directory. This
684 // is achieved by temporarily disabling use of
685 // temp directory. As a side-effect, we get
686 // *.log and *.aux files also. (Asger)
687 bool flag = lyxrc->use_tempdir;
688 lyxrc->use_tempdir = false;
689 MenuRunLaTeX(owner->currentBuffer());
690 lyxrc->use_tempdir = flag;
693 else if (extyp == "postscript") {
694 // Start Print-dialog. Not as good as dvi... Bernhard.
695 MenuPrint(owner->currentBuffer());
696 // Since the MenuPrint is a pop-up, we can't use
697 // the same trick as above. (Asger)
698 // MISSING: Move of ps-file :-(
701 else if (extyp == "ascii") {
702 MenuMakeAscii(owner->currentBuffer());
704 else if (extyp == "custom") {
709 else if (extyp == "html") {
710 // First, create LaTeX file
711 MenuMakeLaTeX(owner->currentBuffer());
714 string file = owner->currentBuffer()->getFileName();
715 file = ChangeExtension(file, ".tex", false);
716 string result = ChangeExtension(file, ".html", false);
717 string tmp = lyxrc->tth_command + " < " + file
720 int res = one.startscript(Systemcalls::System, tmp);
723 _("Document exported as HTML to file: ")) + result);
725 setErrorMessage(string(
726 _("An unexpected error occured while converting document to HTML in file:")) + result);
730 setErrorMessage(string(_("Unknown export type: "))
738 //needs argument as string
739 string imtyp=argument;
742 if (imtyp == "latex") {
743 doImportLaTeX(false);
746 else if (imtyp == "ascii") {
747 doImportASCII(false);
748 } else if (imtyp == "asciiparagraph") {
751 } else if (imtyp == "noweb") {
754 setErrorMessage(string(N_("Unknown import type: "))
766 if (fd_form_toc->form_toc->visible) {
767 fl_raise_form(fd_form_toc->form_toc);
769 static int ow = -1, oh;
770 fl_show_form(fd_form_toc->form_toc,
772 FL_FREE_SIZE, FL_FULLBORDER,
773 _("Table of Contents"));
775 ow = fd_form_toc->form_toc->w;
776 oh = fd_form_toc->form_toc->h;
778 fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
782 case LFUN_TOC_INSERT:
785 new InsetTOC(owner->currentBuffer());
786 owner->currentBuffer()->insertInset(new_inset,
791 case LFUN_LOF_INSERT:
794 new InsetLOF(owner->currentBuffer());
795 owner->currentBuffer()->insertInset(new_inset,
800 case LFUN_LOA_INSERT:
803 new InsetLOA(owner->currentBuffer());
804 owner->currentBuffer()->insertInset(new_inset,
809 case LFUN_LOT_INSERT:
812 new InsetLOT(owner->currentBuffer());
813 owner->currentBuffer()->insertInset(new_inset,
838 case LFUN_MENUSEARCH:
846 case LFUN_PASTESELECTION:
849 if (string(argument) == "paragraph") asPara = true;
850 MenuPasteSelection(asPara);
862 case LFUN_LAYOUT_COPY:
866 case LFUN_LAYOUT_PASTE:
867 PasteEnvironmentCB();
871 owner->currentView()->gotoError();
874 case LFUN_REMOVEERRORS:
875 if (owner->currentBuffer()->removeAutoInsets()) {
876 owner->currentView()->redraw();
877 owner->currentView()->fitCursor();
878 owner->currentView()->updateScrollbar();
890 case LFUN_HYPHENATION:
898 case LFUN_END_OF_SENTENCE:
902 case LFUN_MENU_SEPARATOR:
918 case LFUN_DEPTH_PLUS:
934 case LFUN_RECONFIGURE:
939 if (owner->currentView()->available()
940 && !owner->currentBuffer()->text->selection
941 && owner->currentBuffer()->text->cursor.par->footnoteflag
942 != LyXParagraph::NO_FOOTNOTE)
943 { // only melt footnotes with FOOTMELT, not margins etc
944 if(owner->currentBuffer()->text->cursor.par->footnotekind == LyXParagraph::FOOTNOTE)
951 case LFUN_MARGINMELT:
952 if (owner->currentView()->available()
953 && !owner->currentBuffer()->text->selection
954 && owner->currentBuffer()->text->cursor.par->footnoteflag
955 != LyXParagraph::NO_FOOTNOTE)
956 { // only melt margins
957 if(owner->currentBuffer()->text->cursor.par->footnotekind == LyXParagraph::MARGIN)
964 // --- version control -------------------------------
965 case LFUN_VC_REGISTER:
967 if (!owner->currentBuffer()->lyxvc.inUse())
968 owner->currentBuffer()->lyxvc.registrer();
972 case LFUN_VC_CHECKIN:
974 if (owner->currentBuffer()->lyxvc.inUse()
975 && !owner->currentBuffer()->isReadonly())
976 owner->currentBuffer()->lyxvc.checkIn();
980 case LFUN_VC_CHECKOUT:
982 if (owner->currentBuffer()->lyxvc.inUse()
983 && owner->currentBuffer()->isReadonly())
984 owner->currentBuffer()->lyxvc.checkOut();
990 owner->currentBuffer()->lyxvc.revert();
996 owner->currentBuffer()->lyxvc.undoLast();
1000 case LFUN_VC_HISTORY:
1002 owner->currentBuffer()->lyxvc.showLog();
1006 // --- buffers ----------------------------------------
1007 case LFUN_PREVBUFFER:
1008 #ifdef WITH_WARNINGS
1009 #warning fix this please
1011 // it is the LyXView or the BufferView that should
1012 // remember the previous buffer, not bufferlist.
1013 // if (owner->currentView()->available()){
1015 // owner->currentBuffer()->update(-2);
1017 // owner->currentView()->setBuffer(bufferlist.prev());
1019 // owner->currentView()->
1020 // resizeCurrentBufferPseudoExpose();
1023 case LFUN_FILE_INSERT:
1025 MenuInsertLyXFile(argument);
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 = strToInt(argument);
1060 lyxerr.debug() << "LFUN_LAYOUTNO: (sel) "<< sel << endl;
1062 // Should this give a setMessage instead?
1064 return string(); // illegal argument
1066 sel--; // sel 1..., but layout 0...
1068 // Pretend we got the name instead.
1069 Dispatch(int(LFUN_LAYOUT),
1070 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.c_str());
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.c_str(), " %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.c_str(), " %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(argument.c_str());
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 = strToInt(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.c_str());
2080 case LFUN_INSERT_MATH:
2082 math_insert_symbol(argument.c_str());
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.
2131 if (!argument.empty()) {
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();
2202 if (!argument.empty()) {
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 if (argument == "footnote")
2294 { kind = LyXParagraph::FOOTNOTE; }
2295 else if (argument == "margin")
2296 { kind = LyXParagraph::MARGIN; }
2297 else if (argument == "figure")
2298 { kind = LyXParagraph::FIG; }
2299 else if (argument == "table")
2300 { kind = LyXParagraph::TAB; }
2301 else if (argument == "wide-fig")
2302 { kind = LyXParagraph::WIDE_FIG; }
2303 else if (argument == "wide-tab")
2304 { kind = LyXParagraph::WIDE_TAB; }
2305 else if (argument == "algorithm")
2306 { kind = LyXParagraph::ALGORITHM; }
2308 setErrorMessage(N_("Unknown kind of footnote"));
2311 owner->currentBuffer()->text->InsertFootnoteEnvironment(kind);
2312 owner->currentBuffer()->update(1);
2316 case LFUN_BUFFERBULLETSSELECT:
2320 case LFUN_TOGGLECURSORFOLLOW:
2321 cursor_follows_scrollbar = !cursor_follows_scrollbar;
2324 case LFUN_KMAP_OFF: // keymap off
2325 owner->getIntl()->KeyMapOn(false);
2328 case LFUN_KMAP_PRIM: // primary keymap
2329 owner->getIntl()->KeyMapPrim();
2332 case LFUN_KMAP_SEC: // secondary keymap
2333 owner->getIntl()->KeyMapSec();
2336 case LFUN_KMAP_TOGGLE: // toggle keymap
2337 owner->getIntl()->ToggleKeyMap();
2340 case LFUN_SELFINSERT:
2342 for (string::size_type i = 0; i < argument.length(); ++i) {
2343 owner->currentBuffer()->text->InsertChar(argument[i]);
2344 // This needs to be in the loop, or else we
2345 // won't break lines correctly. (Asger)
2349 owner->currentBuffer()->text->sel_cursor =
2350 owner->currentBuffer()->text->cursor;
2351 moveCursorUpdate(false);
2355 case LFUN_UNKNOWN_ACTION:
2357 if (owner->currentBuffer()->isReadonly()) {
2359 setErrorMessage(N_("Document is read only"));
2363 if (!argument.empty()) {
2365 /* Automatically delete the currently selected
2366 * text and replace it with what is being
2367 * typed in now. Depends on lyxrc settings
2368 * "auto_region_delete", which defaults to
2371 if ( lyxrc->auto_region_delete ) {
2372 if (owner->currentBuffer()->text->selection){
2373 owner->currentBuffer()->text->CutSelection(false);
2374 owner->currentBuffer()->update(-1);
2379 for (string::size_type i = 0; i < argument.length(); ++i) {
2380 if (greek_kb_flag) {
2381 if (!math_insert_greek(argument[i]))
2382 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->currentBuffer()->text);
2384 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->currentBuffer()->text);
2390 owner->currentBuffer()->text->sel_cursor =
2391 owner->currentBuffer()->text->cursor;
2392 moveCursorUpdate(false);
2395 // why is an "Unknown action" with empty
2396 // argument even dispatched in the first
2397 // place? I`ll probably change that. (Lgb)
2399 setErrorMessage(N_("Unknown action"));
2403 lyxerr << "A truly unknown func!" << endl;
2409 string res=getMessage();
2412 if (!commandshortcut.empty()) {
2413 string newbuf = owner->getMiniBuffer()->GetText();
2414 if (newbuf != commandshortcut) {
2415 owner->getMiniBuffer()->Set(newbuf
2421 owner->getMiniBuffer()->Set(string(_(res.c_str()))
2422 + " " + commandshortcut);
2425 return getMessage();
2429 void LyXFunc::setupLocalKeymap()
2431 keyseq.stdmap = keyseq.curmap = toplevel_keymap;
2432 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap;
2436 void LyXFunc::MenuNew(bool fromTemplate)
2438 string fname, initpath = lyxrc->document_path;
2441 if (owner->currentView()->available()) {
2442 string trypath = owner->currentBuffer()->filepath;
2443 // If directory is writeable, use this as default.
2444 if (IsDirWriteable(trypath) == 1)
2449 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2450 fileDlg.SetButton(1, _("Templates"), lyxrc->template_path);
2451 fname = fileDlg.Select(_("Enter Filename for new document"),
2452 initpath, "*.lyx", _("newfile"));
2455 if (fname.empty()) {
2456 owner->getMiniBuffer()->Set(_("Canceled."));
2457 lyxerr.debug() << "New Document Cancelled." << endl;
2461 // get absolute path of file and make sure the filename ends
2463 string s = MakeAbsPath(fname);
2464 if (!IsLyXFilename(s))
2467 // Check if the document already is open
2468 if (bufferlist.exists(s)){
2469 switch(AskConfirmation(_("Document is already open:"),
2470 MakeDisplayPath(s,50),
2471 _("Do you want to close that document now?\n"
2472 "('No' will just switch to the open version)")))
2474 case 1: // Yes: close the document
2475 if (!bufferlist.close(bufferlist.getBuffer(s)))
2476 // If close is canceled, we cancel here too.
2479 case 2: // No: switch to the open document
2480 owner->currentView()->setBuffer(bufferlist.getBuffer(s));
2482 case 3: // Cancel: Do nothing
2483 owner->getMiniBuffer()->Set(_("Canceled."));
2488 // Check whether the file already exists
2489 if (IsLyXFilename(s)) {
2490 FilePtr myfile(s, FilePtr::read);
2492 AskQuestion(_("File already exists:"),
2493 MakeDisplayPath(s,50),
2494 _("Do you want to open the document?"))) {
2496 owner->getMiniBuffer()->Set(_("Opening document"),
2497 MakeDisplayPath(s), "...");
2499 owner->currentView()->setBuffer(
2500 bufferlist.loadLyXFile(s));
2501 owner->getMiniBuffer()->Set(_("Document"),
2508 // The template stuff
2512 fname = fileDlg.Select(_("Choose template"),
2513 lyxrc->template_path,
2519 // find a free buffer
2520 lyxerr.debug() << "Find a free buffer." << endl;
2521 owner->currentView()->setBuffer(bufferlist.newFile(s,templname));
2525 void LyXFunc::MenuOpen()
2527 string initpath = lyxrc->document_path;
2530 if (owner->currentView()->available()) {
2531 string trypath = owner->currentBuffer()->filepath;
2532 // If directory is writeable, use this as default.
2533 if (IsDirWriteable(trypath) == 1)
2539 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2540 fileDlg.SetButton(1, _("Examples"),
2541 AddPath(system_lyxdir, "examples"));
2542 string filename = fileDlg.Select(_("Select Document to Open"),
2546 // check selected filename
2547 if (filename.empty()) {
2548 owner->getMiniBuffer()->Set(_("Canceled."));
2552 // get absolute path of file and make sure the filename ends
2554 filename = MakeAbsPath(filename);
2555 if (!IsLyXFilename(filename))
2559 owner->getMiniBuffer()->Set(_("Opening document"),
2560 MakeDisplayPath(filename), "...");
2561 Buffer * openbuf = bufferlist.loadLyXFile(filename);
2563 owner->currentView()->setBuffer(openbuf);
2564 owner->getMiniBuffer()->Set(_("Document"),
2565 MakeDisplayPath(filename),
2568 owner->getMiniBuffer()->Set(_("Could not open document"),
2569 MakeDisplayPath(filename));
2574 void LyXFunc::doImportASCII(bool linorpar)
2576 string initpath = lyxrc->document_path;
2579 if (owner->currentView()->available()) {
2580 string trypath = owner->currentBuffer()->filepath;
2581 // If directory is writeable, use this as default.
2582 if (IsDirWriteable(trypath) == 1)
2588 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2589 fileDlg.SetButton(1, _("Examples"),
2590 AddPath(system_lyxdir, "examples"));
2591 string filename = fileDlg.Select(_("Select ASCII file to Import"),
2595 // check selected filename
2596 if (filename.empty()) {
2597 owner->getMiniBuffer()->Set(_("Canceled."));
2601 // get absolute path of file
2602 filename = MakeAbsPath(filename);
2604 string s = ChangeExtension(filename, ".lyx", false);
2606 // Check if the document already is open
2607 if (bufferlist.exists(s)){
2608 switch(AskConfirmation(_("Document is already open:"),
2609 MakeDisplayPath(s,50),
2610 _("Do you want to close that document now?\n"
2611 "('No' will just switch to the open version)")))
2613 case 1: // Yes: close the document
2614 if (!bufferlist.close(bufferlist.getBuffer(s)))
2615 // If close is canceled, we cancel here too.
2618 case 2: // No: switch to the open document
2619 owner->currentView()->setBuffer(bufferlist.getBuffer(s));
2621 case 3: // Cancel: Do nothing
2622 owner->getMiniBuffer()->Set(_("Canceled."));
2627 // Check if a LyX document by the same root exists in filesystem
2628 FileInfo f(s, true);
2629 if (f.exist() && !AskQuestion(_("A document by the name"),
2631 _("already exists. Overwrite?"))) {
2632 owner->getMiniBuffer()->Set(_("Canceled."));
2636 owner->currentView()->setBuffer(bufferlist.newFile(s,string()));
2637 owner->getMiniBuffer()->Set(_("Importing ASCII file"),
2638 MakeDisplayPath(filename), "...");
2639 // Insert ASCII file
2640 InsertAsciiFile(filename,linorpar);
2641 owner->getMiniBuffer()->Set(_("ASCII file "),
2642 MakeDisplayPath(filename),
2647 void LyXFunc::doImportLaTeX(bool isnoweb)
2649 string initpath = lyxrc->document_path;
2652 if (owner->currentView()->available()) {
2653 string trypath = owner->currentBuffer()->filepath;
2654 // If directory is writeable, use this as default.
2655 if (IsDirWriteable(trypath) == 1)
2661 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2662 fileDlg.SetButton(1, _("Examples"),
2663 AddPath(system_lyxdir, "examples"));
2666 filename = fileDlg.Select(_("Select Noweb file to Import"),
2669 filename = fileDlg.Select(_("Select LaTeX file to Import"),
2675 // check selected filename
2676 if (filename.empty()) {
2677 owner->getMiniBuffer()->Set(_("Canceled."));
2681 // get absolute path of file
2682 filename = MakeAbsPath(filename);
2684 // Check if the document already is open
2685 string LyXfilename = ChangeExtension(filename, ".lyx", false);
2686 if (bufferlist.exists(LyXfilename)){
2687 switch(AskConfirmation(_("Document is already open:"),
2688 MakeDisplayPath(LyXfilename,50),
2689 _("Do you want to close that document now?\n"
2690 "('No' will just switch to the open version)")))
2692 case 1: // Yes: close the document
2693 if (!bufferlist.close(bufferlist.getBuffer(LyXfilename)))
2694 // If close is canceled, we cancel here too.
2697 case 2: // No: switch to the open document
2698 owner->currentView()->setBuffer(
2699 bufferlist.getBuffer(LyXfilename));
2701 case 3: // Cancel: Do nothing
2702 owner->getMiniBuffer()->Set(_("Canceled."));
2707 // Check if a LyX document by the same root exists in filesystem
2708 FileInfo f(LyXfilename, true);
2709 if (f.exist() && !AskQuestion(_("A document by the name"),
2710 MakeDisplayPath(LyXfilename),
2711 _("already exists. Overwrite?"))) {
2712 owner->getMiniBuffer()->Set(_("Canceled."));
2719 owner->getMiniBuffer()->Set(_("Importing LaTeX file"),
2720 MakeDisplayPath(filename), "...");
2721 ImportLaTeX myImport(filename);
2722 openbuf = myImport.run();
2724 owner->getMiniBuffer()->Set(_("Importing Noweb file"),
2725 MakeDisplayPath(filename), "...");
2726 ImportNoweb myImport(filename);
2727 openbuf = myImport.run();
2730 owner->currentView()->setBuffer(openbuf);
2731 owner->getMiniBuffer()->Set(isnoweb ?
2732 _("Noweb file ") : _("LateX file "),
2733 MakeDisplayPath(filename),
2736 owner->getMiniBuffer()->Set(isnoweb ?
2737 _("Could not import Noweb file") :
2738 _("Could not import LaTeX file"),
2739 MakeDisplayPath(filename));
2744 void LyXFunc::MenuInsertLyXFile(string const & filen)
2746 string filename = filen;
2748 if (filename.empty()) {
2749 // Launch a file browser
2750 string initpath = lyxrc->document_path;
2753 if (owner->currentView()->available()) {
2754 string trypath = owner->currentBuffer()->filepath;
2755 // If directory is writeable, use this as default.
2756 if (IsDirWriteable(trypath) == 1)
2762 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2763 fileDlg.SetButton(1, _("Examples"),
2764 AddPath(system_lyxdir, "examples"));
2765 filename = fileDlg.Select(_("Select Document to Insert"),
2769 // check selected filename
2770 if (filename.empty()) {
2771 owner->getMiniBuffer()->Set(_("Canceled."));
2776 // get absolute path of file and make sure the filename ends
2778 filename = MakeAbsPath(filename);
2779 if (!IsLyXFilename(filename))
2783 owner->getMiniBuffer()->Set(_("Inserting document"),
2784 MakeDisplayPath(filename), "...");
2785 bool res = owner->currentBuffer()->insertLyXFile(filename);
2787 owner->getMiniBuffer()->Set(_("Document"),
2788 MakeDisplayPath(filename),
2791 owner->getMiniBuffer()->Set(_("Could not insert document"),
2792 MakeDisplayPath(filename));
2797 void LyXFunc::reloadBuffer()
2799 string fn = owner->currentBuffer()->getFileName();
2800 if (bufferlist.close(owner->currentBuffer()))
2801 owner->currentView()->setBuffer(bufferlist.loadLyXFile(fn));
2805 void LyXFunc::CloseBuffer()
2807 if (bufferlist.close(owner->currentBuffer()) && !quitting) {
2808 if (bufferlist.isEmpty()) {
2809 // need this otherwise SEGV may occur while trying to
2810 // set variables that don't exist
2811 // since there's no current buffer
2812 CloseAllBufferRelatedPopups();
2815 owner->currentView()->setBuffer(bufferlist.first());
2821 Inset* LyXFunc::getInsetByCode(Inset::Code code)
2825 LyXCursor cursor = owner->currentBuffer()->text->cursor;
2826 int pos = cursor.pos;
2827 LyXParagraph *par = cursor.par;
2829 while (par && !found) {
2830 while ((inset = par->ReturnNextInsetPointer(pos))){
2831 if (inset->LyxCode()==code) {
2839 return (found) ? inset: 0;
2843 // Each "owner" should have it's own message method. lyxview and
2844 // the minibuffer would use the minibuffer, but lyxserver would
2845 // send an ERROR signal to its client. Alejandro 970603
2846 // This func is bit problematic when it comes to NLS, to make the
2847 // lyx servers client be language indepenent we must not translate
2848 // strings sent to this func.
2849 void LyXFunc::setErrorMessage(string const &m)
2851 dispatch_buffer = m;
2856 void LyXFunc::setMessage(string const & m)
2858 dispatch_buffer = m;