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"
63 #include "support/path.h"
65 extern bool cursor_follows_scrollbar;
67 extern void InsertAsciiFile(string const &, bool);
68 extern void math_insert_symbol(char const*);
69 extern Bool math_insert_greek(char const); // why "Bool"?
70 extern BufferList bufferlist;
71 extern LyXServer *lyxserver;
72 extern short greek_kb_flag;
73 extern FD_form_toc *fd_form_toc;
74 extern bool selection_possible;
76 extern kb_keymap *toplevel_keymap;
78 extern void BeforeChange();
79 extern void MenuWrite(Buffer*);
80 extern void MenuWriteAs(Buffer*);
81 extern int MenuRunLaTeX(Buffer*);
82 extern int MenuBuildProg(Buffer*);
83 extern int MenuRunChktex(Buffer*);
84 extern bool MenuRunDvips(Buffer *,bool);
85 extern void MenuPrint(Buffer*);
86 extern void MenuSendto();
87 extern void QuitLyX();
88 extern void MenuFax(Buffer *);
89 extern void MenuMakeLaTeX(Buffer *);
90 extern void MenuMakeLinuxDoc(Buffer *);
91 extern void MenuMakeDocBook(Buffer *);
92 extern void MenuMakeAscii(Buffer *);
93 extern void MenuPasteSelection(char at);
94 extern LyXAction lyxaction;
96 extern tex_accent_struct get_accent(kb_action action);
98 extern void AutoSave();
99 extern void MenuSearch();
100 extern void CopyCB();
101 extern void CopyEnvironmentCB();
102 extern void PasteEnvironmentCB();
103 extern void GotoNote();
104 extern void NoteCB();
105 extern void OpenStuff();
106 extern void HyphenationPoint();
108 extern void EndOfSentenceDot();
109 extern void MenuSeparator();
111 extern void MenuUndo();
112 extern void MenuRedo();
113 extern void SmallUpdate(signed char);
114 extern void SetUpdateTimer(float timer= 0.3);
115 extern void FreeUpdateTimer();
116 extern bool MenuPreview(Buffer*);
117 extern bool MenuPreviewPS(Buffer*);
118 extern void MenuInsertLabel(const char *);
119 extern void MenuInsertRef();
120 extern void MenuLayoutCharacter();
121 extern void MenuLayoutParagraph();
122 extern void MenuLayoutDocument();
123 extern void MenuLayoutPaper();
124 extern void MenuLayoutTable(int flag);
125 extern void MenuLayoutQuotes();
126 extern void MenuLayoutPreamble();
127 extern void MenuLayoutSave();
128 extern void bulletForm();
130 extern Buffer * NewLyxFile(string const &);
131 extern void LoadLyXFile(string const &);
132 extern void Reconfigure();
134 extern int current_layout;
135 extern int getISOCodeFromLaTeX(char *);
137 extern int UnlockInset(UpdatableInset*);
139 extern void ShowLatexLog();
141 extern void UpdateInset(Inset* inset, bool mark_dirty = true);
143 /* === globals =========================================================== */
145 bool LyXFunc::show_sc = true;
148 LyXFunc::LyXFunc(LyXView *o)
152 lyx_dead_action = LFUN_NOACTION;
153 lyx_calling_dead_action = LFUN_NOACTION;
163 // I changed this func slightly. I commented out the ...FinishUndo(),
164 // this means that all places that used to have a moveCursorUpdate, now
165 // have a ...FinishUndo() as the preceeding statement. I have also added
166 // a moveCursorUpdate to some of the functions that updated the cursor, but
167 // that did not show its new position.
169 void LyXFunc::moveCursorUpdate(bool selecting)
171 if (selecting || owner->currentBuffer()->text->mark_set) {
172 owner->currentBuffer()->text->SetSelection();
173 owner->currentView()->getScreen()->ToggleToggle();
174 owner->currentBuffer()->update(0);
176 owner->currentBuffer()->update(-2); // this IS necessary
179 owner->currentView()->getScreen()->ShowCursor();
181 /* ---> Everytime the cursor is moved, show the current font state. */
182 // should this too me moved out of this func?
183 //owner->getMiniBuffer()->Set(CurrentState());
187 int LyXFunc::processKeyEvent(XEvent *ev)
194 XKeyEvent *keyevent = &ev->xkey;
195 KeySym keysym_return;
197 num_bytes = LyXLookupString(ev, s_r, 10, &keysym_return);
199 if (lyxerr.debugging(Debug::KEY)) {
200 lyxerr << "KeySym is "
201 << XKeysymToString(keysym_return)
203 << keysym_return << "]"
204 << " and num_bytes is "
206 << " the string returned is \""
207 << s_r << '\"' << endl;
209 // Do nothing if we have nothing (JMarc)
210 if (num_bytes == 0 && keysym_return == NoSymbol) {
211 lyxerr[Debug::KEY] << "Empty kbd action (probably composing)"
216 // this function should be used always [asierra060396]
217 if (owner->currentView()->available() &&
218 owner->currentBuffer()->the_locking_inset &&
219 keysym_return == XK_Escape) {
220 UnlockInset(owner->currentBuffer()->the_locking_inset);
221 owner->currentBuffer()->text->CursorRight();
225 // Can we be sure that this will work for all X-Windows
226 // implementations? (Lgb)
227 // This code snippet makes lyx ignore some keys. Perhaps
228 // all of them should be explictly mentioned?
229 if((keysym_return >= XK_Shift_L && keysym_return <= XK_Hyper_R)
230 || keysym_return == XK_Mode_switch || keysym_return == 0x0)
233 // Do a one-deep top-level lookup for
234 // cancel and meta-fake keys. RVDK_PATCH_5
235 cancel_meta_seq.reset();
237 action = cancel_meta_seq.addkey(keysym_return, keyevent->state
238 &(ShiftMask|ControlMask
241 // When not cancel or meta-fake, do the normal lookup.
242 // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
243 // Mostly, meta_fake_bit = 0. RVDK_PATCH_5.
244 if ( (action != LFUN_CANCEL) && (action != LFUN_META_FAKE) ) {
246 // remove Caps Lock and Mod2 as a modifiers
247 action = keyseq.addkey(keysym_return,
248 (keyevent->state | meta_fake_bit)
249 &(ShiftMask|ControlMask
252 // Dont remove this unless you know what you are doing.
255 if (action == 0) action = LFUN_PREFIX;
257 if (lyxerr.debugging(Debug::KEY)) {
259 keyseq.print(buf,100);
263 << num_bytes << "]" << endl;
266 // already here we know if it any point in going further
267 // why not return already here if action == -1 and
268 // num_bytes == 0? (Lgb)
270 if(keyseq.length>1 || keyseq.length<-1){
272 keyseq.print(buf,100);
273 owner->getMiniBuffer()->Set(buf);
277 if (keyseq.length<-1) { // unknown key sequence...
280 keyseq.print(buf,100);
281 owner->getMiniBuffer()->Set(_("Unknown sequence:"),buf);
285 char isochar = keyseq.getiso();
286 if (!(keyevent->state&ControlMask) &&
287 !(keyevent->state&Mod1Mask) &&
288 (isochar && keysym_return < 0xF000)) {
291 if (argument.empty()) {
292 lyxerr.debug() << "Empty argument!" << endl;
293 // This can`t possibly be of any use
294 // so we`ll skip the dispatch.
298 if (action==LFUN_SELFINSERT) {
302 bool tmp_sc = show_sc;
304 Dispatch(action, argument.c_str());
311 string LyXFunc::Dispatch(string const &cmd, string const &arg)
313 return Dispatch(lyxaction.LookupFunc(cmd.c_str()),
318 string LyXFunc::Dispatch(int ac,
319 char const *do_not_use_this_arg)
325 FL_OBJECT *ob = 0; // This will disapear soon
327 // we have not done anything wrong yet.
329 dispatch_buffer = string();
331 // if action is a pseudo-action, we need the real action
332 if (lyxaction.isPseudoAction(ac)) {
333 char const *tmparg = 0;
334 action = (kb_action)lyxaction.retrieveActionArg(ac, &tmparg);
338 action = (kb_action)ac;
339 if (do_not_use_this_arg)
340 argument = do_not_use_this_arg; // except here
343 selection_possible = false;
345 if (owner->currentView()->available()
346 && owner->currentView()->getScreen())
347 owner->currentView()->getScreen()->HideCursor();
349 if(!owner->currentView()->available()) {
350 // This lists the allowed funcs when we have no
353 case LFUN_MENU_OPEN_BY_NAME:
356 case LFUN_MENUNEWTMPLT:
359 case LFUN_PUSH_TOOLBAR:
360 case LFUN_ADD_TO_TOOLBAR:
361 case LFUN_EXEC_COMMAND:
362 case LFUN_DROP_LAYOUTS_CHOICE:
366 case LFUN_RECONFIGURE:
372 case LFUN_UNKNOWN_ACTION:
373 setErrorMessage(N_("Unknown action"));
374 goto exit_with_message;
376 setErrorMessage(N_("Command not allowed with"
377 "out any document open"));
378 goto exit_with_message; // action not allowed
382 commandshortcut = string();
384 if (lyxrc->display_shortcuts && show_sc) {
385 if (action != LFUN_SELFINSERT) {
386 // Put name of command and list of shortcuts
387 // for it in minibuffer
388 string comname = lyxaction.getActionName(action);
390 int pseudoaction = action;
391 bool argsadded = false;
393 if (!argument.empty()) {
394 // If we have the command with argument,
397 lyxaction.searchActionArg(action,
400 if (pseudoaction == -1) {
401 pseudoaction = action;
403 comname += " " + argument;
408 string shortcuts = toplevel_keymap->findbinding(pseudoaction);
410 if (!shortcuts.empty()) {
411 comname += ": " + shortcuts;
412 } else if (!argsadded) {
413 comname += " " + argument;
416 if (!comname.empty()) {
417 comname = strip(comname);
418 commandshortcut = "(" + comname + ')';
419 owner->getMiniBuffer()->Set(commandshortcut);
420 // Here we could even add a small pause,
421 // to annoy the user and make him learn
423 // No! That will just annoy, not teach
424 // anything. The user will read the messages
425 // if they are interested. (Asger)
430 // Now that we know which action, if the buffer is RO let's check
431 // whether the action is legal. Alejandro 970603
432 if (owner->currentView()->available() &&
433 owner->currentBuffer()->isReadonly() &&
434 lyxaction.isFuncRO(action)) {
435 setErrorMessage(N_("Document is read-only"));
436 lyxerr.debug() << "Error: Document is read-only." << endl;
437 goto exit_with_message;
440 // If in math mode pass the control to
441 // the math inset [asierra060396]
442 if (owner->currentView()->available() &&
443 owner->currentBuffer()->the_locking_inset) {
444 if (action>1 || (action==LFUN_UNKNOWN_ACTION && keyseq.length>=-1)) {
445 if (action==LFUN_UNKNOWN_ACTION && argument.empty()) {
446 argument = keyseq.getiso();
448 // Undo/Redo pre 0.13 is a bit tricky for insets.
449 if (action==LFUN_UNDO) {
451 UpdatableInset* inset =
452 owner->currentBuffer()->the_locking_inset;
453 inset->GetCursorPos(slx, sly);
456 inset = (UpdatableInset*)owner->currentBuffer()->text->cursor.par->GetInset(owner->currentBuffer()->text->cursor.pos);
458 inset->Edit(slx, sly);
461 if (action==LFUN_REDO) {
463 UpdatableInset* inset = owner->currentBuffer()->the_locking_inset;
464 inset->GetCursorPos(slx, sly);
467 inset = (UpdatableInset*)owner->currentBuffer()->text->cursor.par->GetInset(owner->currentBuffer()->text->cursor.pos);
469 inset->Edit(slx, sly);
472 if (owner->currentBuffer()->the_locking_inset->LocalDispatch(action, argument.c_str()))
475 setMessage(N_("Text mode"));
476 if (action==LFUN_RIGHT || action==-1)
477 owner->currentBuffer()->text->CursorRight();
478 if (action==LFUN_LEFT || action==LFUN_RIGHT)
485 // --- Misc -------------------------------------------
486 case LFUN_WORDFINDFORWARD :
487 case LFUN_WORDFINDBACKWARD : {
489 static string last_search;
490 string searched_string;
492 if (!argument.empty()) {
493 last_search = argument;
494 searched_string = argument;
496 searched_string = last_search;
499 ltCur = owner->currentView()->currentBuffer()->text ;
501 if (!searched_string.empty() &&
502 ( (action == LFUN_WORDFINDBACKWARD) ?
503 ltCur->SearchBackward( searched_string.c_str() ) :
504 ltCur->SearchForward( searched_string.c_str() )
507 // ??? What is that ???
508 owner->currentView()->currentBuffer()->update(-2);
511 // clear the selection (if there is any)
512 owner->currentView()->getScreen()->ToggleSelection();
513 owner->currentView()->currentBuffer()->text->ClearSelection();
515 // Move cursor so that successive C-s 's will not stand in place.
516 if( action == LFUN_WORDFINDFORWARD )
517 owner->currentBuffer()->text->CursorRightOneWord();
518 owner->currentBuffer()->text->FinishUndo();
519 moveCursorUpdate(false);
522 // set the new selection
523 // SetSelectionOverLenChars(owner->currentView()->currentBuffer()->text, iLenSelected);
524 owner->currentView()->getScreen()->ToggleSelection(false);
528 // REMOVED : if (owner->currentView()->getWorkArea()->focus)
529 owner->currentView()->getScreen()->ShowCursor();
535 if (owner->currentView()->available()
536 && owner->currentView()->getScreen()) {
537 owner->currentBuffer()->update(-2);
540 keyseq.print(buf,100, true);
541 owner->getMiniBuffer()->Set(buf, string(), string(), 1);
545 // --- Misc -------------------------------------------
546 case LFUN_EXEC_COMMAND:
547 owner->getMiniBuffer()->ExecCommand();
550 case LFUN_CANCEL: // RVDK_PATCH_5
553 if(owner->currentView()->available())
554 // cancel any selection
555 Dispatch(int(LFUN_MARK_OFF), 0);
556 setMessage(N_("Cancel"));
559 case LFUN_META_FAKE: // RVDK_PATCH_5
561 meta_fake_bit = Mod1Mask;
563 keyseq.print(buf, 98, true);
564 string res = string("M-") + buf;
565 setMessage(buf); // RVDK_PATCH_5
569 case LFUN_READ_ONLY_TOGGLE:
570 if (owner->currentBuffer()->lyxvc.inUse()) {
571 owner->currentBuffer()->lyxvc.toggleReadOnly();
573 owner->currentBuffer()->setReadonly(
574 !owner->currentBuffer()->isReadonly());
578 case LFUN_CENTER: // this is center and redraw.
580 if (owner->currentBuffer()->text->cursor.y >
581 owner->currentView()->getWorkArea()->h / 2) {
582 owner->currentView()->getScreen()->
583 Draw(owner->currentBuffer()->text->cursor.y -
584 owner->currentView()->getWorkArea()->h/2);
586 owner->currentView()->getScreen()->
589 owner->currentBuffer()->update(0);
590 owner->currentView()->redraw();
594 if (owner->currentView()->available()) {
595 owner->currentBuffer()->text->toggleAppendix();
596 owner->currentBuffer()->update(1);
600 // --- Menus -----------------------------------------------
605 case LFUN_MENUNEWTMPLT:
613 case LFUN_CLOSEBUFFER:
618 MenuWrite(owner->currentBuffer());
621 case LFUN_MENUWRITEAS:
622 MenuWriteAs(owner->currentBuffer());
625 case LFUN_MENURELOAD:
630 MenuPreview(owner->currentBuffer());
634 MenuPreviewPS(owner->currentBuffer());
638 MenuRunLaTeX(owner->currentBuffer());
642 MenuBuildProg(owner->currentBuffer());
646 MenuRunChktex(owner->currentBuffer());
650 MenuRunDvips(owner->currentBuffer(), false);
654 MenuPrint(owner->currentBuffer());
658 MenuFax(owner->currentBuffer());
663 //needs argument as string
664 string extyp=argument;
667 if (extyp == "latex") {
668 // make sure that this buffer is not linuxdoc
669 MenuMakeLaTeX(owner->currentBuffer());
672 else if (extyp == "linuxdoc") {
673 // make sure that this buffer is not latex
674 MenuMakeLinuxDoc(owner->currentBuffer());
677 else if (extyp == "docbook") {
678 // make sure that this buffer is not latex or linuxdoc
679 MenuMakeDocBook(owner->currentBuffer());
682 else if (extyp == "dvi") {
683 // Run LaTeX as "Update dvi..." Bernhard.
684 // We want the dvi in the current directory. This
685 // is achieved by temporarily disabling use of
686 // temp directory. As a side-effect, we get
687 // *.log and *.aux files also. (Asger)
688 bool flag = lyxrc->use_tempdir;
689 lyxrc->use_tempdir = false;
690 MenuRunLaTeX(owner->currentBuffer());
691 lyxrc->use_tempdir = flag;
694 else if (extyp == "postscript") {
695 // Start Print-dialog. Not as good as dvi... Bernhard.
696 MenuPrint(owner->currentBuffer());
697 // Since the MenuPrint is a pop-up, we can't use
698 // the same trick as above. (Asger)
699 // MISSING: Move of ps-file :-(
702 else if (extyp == "ascii") {
703 MenuMakeAscii(owner->currentBuffer());
705 else if (extyp == "custom") {
710 else if (extyp == "html" && lyxrc->html_command != "none") {
711 // First, create LaTeX file
712 MenuMakeLaTeX(owner->currentBuffer());
714 // And now, run the converter
715 string file = owner->currentBuffer()->getFileName();
716 Path path(OnlyPath(file));
717 // the tex file name has to be correct for
718 // latex, but the html file name can be
720 string result = ChangeExtension(file, ".html", false);
721 file = ChangeExtension(SpaceLess(file), ".tex", false);
722 string tmp = lyxrc->html_command;
723 tmp = subst(tmp, "$$FName", file);
724 tmp = subst(tmp, "$$OutName", result);
726 int res = one.startscript(Systemcalls::System, tmp);
728 setMessage(_("Document exported as HTML to file `")
729 + MakeDisplayPath(result) +'\'');
731 setErrorMessage(_("Unable to convert to HTML the file `")
732 + MakeDisplayPath(file)
737 setErrorMessage(_("Unknown export type: ")
745 //needs argument as string
746 string imtyp=argument;
749 if (imtyp == "latex") {
750 doImportLaTeX(false);
753 else if (imtyp == "ascii") {
754 doImportASCII(false);
755 } else if (imtyp == "asciiparagraph") {
758 } else if (imtyp == "noweb") {
761 setErrorMessage(string(N_("Unknown import type: "))
773 if (fd_form_toc->form_toc->visible) {
774 fl_raise_form(fd_form_toc->form_toc);
776 static int ow = -1, oh;
777 fl_show_form(fd_form_toc->form_toc,
779 FL_FREE_SIZE, FL_FULLBORDER,
780 _("Table of Contents"));
782 ow = fd_form_toc->form_toc->w;
783 oh = fd_form_toc->form_toc->h;
785 fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
789 case LFUN_TOC_INSERT:
792 new InsetTOC(owner->currentBuffer());
793 owner->currentBuffer()->insertInset(new_inset,
798 case LFUN_LOF_INSERT:
801 new InsetLOF(owner->currentBuffer());
802 owner->currentBuffer()->insertInset(new_inset,
807 case LFUN_LOA_INSERT:
810 new InsetLOA(owner->currentBuffer());
811 owner->currentBuffer()->insertInset(new_inset,
816 case LFUN_LOT_INSERT:
819 new InsetLOT(owner->currentBuffer());
820 owner->currentBuffer()->insertInset(new_inset,
845 case LFUN_MENUSEARCH:
853 case LFUN_PASTESELECTION:
856 if (string(argument) == "paragraph") asPara = true;
857 MenuPasteSelection(asPara);
869 case LFUN_LAYOUT_COPY:
873 case LFUN_LAYOUT_PASTE:
874 PasteEnvironmentCB();
878 owner->currentView()->gotoError();
881 case LFUN_REMOVEERRORS:
882 if (owner->currentBuffer()->removeAutoInsets()) {
883 owner->currentView()->redraw();
884 owner->currentView()->fitCursor();
885 owner->currentView()->updateScrollbar();
897 case LFUN_HYPHENATION:
905 case LFUN_END_OF_SENTENCE:
909 case LFUN_MENU_SEPARATOR:
925 case LFUN_DEPTH_PLUS:
941 case LFUN_RECONFIGURE:
946 if (owner->currentView()->available()
947 && !owner->currentBuffer()->text->selection
948 && owner->currentBuffer()->text->cursor.par->footnoteflag
949 != LyXParagraph::NO_FOOTNOTE)
950 { // only melt footnotes with FOOTMELT, not margins etc
951 if(owner->currentBuffer()->text->cursor.par->footnotekind == LyXParagraph::FOOTNOTE)
958 case LFUN_MARGINMELT:
959 if (owner->currentView()->available()
960 && !owner->currentBuffer()->text->selection
961 && owner->currentBuffer()->text->cursor.par->footnoteflag
962 != LyXParagraph::NO_FOOTNOTE)
963 { // only melt margins
964 if(owner->currentBuffer()->text->cursor.par->footnotekind == LyXParagraph::MARGIN)
971 // --- version control -------------------------------
972 case LFUN_VC_REGISTER:
974 if (!owner->currentBuffer()->lyxvc.inUse())
975 owner->currentBuffer()->lyxvc.registrer();
979 case LFUN_VC_CHECKIN:
981 if (owner->currentBuffer()->lyxvc.inUse()
982 && !owner->currentBuffer()->isReadonly())
983 owner->currentBuffer()->lyxvc.checkIn();
987 case LFUN_VC_CHECKOUT:
989 if (owner->currentBuffer()->lyxvc.inUse()
990 && owner->currentBuffer()->isReadonly())
991 owner->currentBuffer()->lyxvc.checkOut();
997 owner->currentBuffer()->lyxvc.revert();
1003 owner->currentBuffer()->lyxvc.undoLast();
1007 case LFUN_VC_HISTORY:
1009 owner->currentBuffer()->lyxvc.showLog();
1013 // --- buffers ----------------------------------------
1014 case LFUN_PREVBUFFER:
1015 #ifdef WITH_WARNINGS
1016 #warning fix this please
1018 // it is the LyXView or the BufferView that should
1019 // remember the previous buffer, not bufferlist.
1020 // if (owner->currentView()->available()){
1022 // owner->currentBuffer()->update(-2);
1024 // owner->currentView()->setBuffer(bufferlist.prev());
1026 // owner->currentView()->
1027 // resizeCurrentBufferPseudoExpose();
1030 case LFUN_FILE_INSERT:
1032 MenuInsertLyXFile(argument);
1036 case LFUN_FILE_INSERT_ASCII:
1038 bool asPara = false;
1039 asPara = (string(argument) == "paragraph");
1040 InsertAsciiFile(string(), asPara);
1046 // servercmd: argument must be <file>:<template>
1047 Buffer * tmpbuf = 0;
1048 tmpbuf = NewLyxFile(argument);
1050 owner->currentView()->setBuffer(tmpbuf);
1054 case LFUN_FILE_OPEN:
1055 owner->currentView()->setBuffer(
1056 bufferlist.loadLyXFile(argument));
1059 case LFUN_LATEX_LOG:
1065 lyxerr.debug() << "LFUN_LAYOUTNO: (arg) " << argument << endl;
1066 int sel = strToInt(argument);
1067 lyxerr.debug() << "LFUN_LAYOUTNO: (sel) "<< sel << endl;
1069 // Should this give a setMessage instead?
1071 return string(); // illegal argument
1073 sel--; // sel 1..., but layout 0...
1075 // Pretend we got the name instead.
1076 Dispatch(int(LFUN_LAYOUT),
1077 lyxstyle.NameOfLayout(owner->currentBuffer()->
1086 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1087 << argument << endl;
1089 // Derive layout number from given argument (string)
1090 // and current buffer's textclass (number). */
1093 lyxstyle.NumberOfLayout(owner->
1099 // see if we found the layout number:
1100 if (layoutno == -1) {
1101 setErrorMessage(string(N_("Layout ")) + argument +
1106 if (current_layout != layoutno) {
1107 owner->currentView()->getScreen()->HideCursor();
1108 current_layout = layoutno;
1109 owner->currentBuffer()->update(-2);
1110 owner->currentBuffer()->text->
1111 SetLayout(layoutno);
1112 owner->getToolbar()->combox->
1113 select(owner->currentBuffer()->
1116 owner->currentBuffer()->update(1);
1121 case LFUN_LAYOUT_DOCUMENT:
1122 MenuLayoutDocument();
1125 case LFUN_LAYOUT_PARAGRAPH:
1126 MenuLayoutParagraph();
1129 case LFUN_LAYOUT_CHARACTER:
1130 MenuLayoutCharacter();
1133 case LFUN_LAYOUT_TABLE:
1136 if (string(argument) == "true") flag = 1;
1137 MenuLayoutTable(flag);
1141 case LFUN_LAYOUT_PAPER:
1145 case LFUN_LAYOUT_QUOTES:
1149 case LFUN_LAYOUT_PREAMBLE:
1150 MenuLayoutPreamble();
1153 case LFUN_LAYOUT_SAVE_DEFAULT:
1157 case LFUN_DROP_LAYOUTS_CHOICE:
1158 owner->getToolbar()->combox->Show();
1189 case LFUN_UNDERLINE:
1193 case LFUN_FONT_SIZE:
1194 FontSizeCB(argument);
1197 case LFUN_FONT_STATE:
1198 setMessage(CurrentState());
1201 case LFUN_UPCASE_WORD:
1202 owner->currentBuffer()->update(-2);
1204 owner->currentBuffer()->text->ChangeWordCase(2);
1205 owner->currentBuffer()->update(1);
1209 case LFUN_LOWCASE_WORD:
1210 owner->currentBuffer()->update(-2);
1212 owner->currentBuffer()->text->ChangeWordCase(0);
1213 owner->currentBuffer()->update(1);
1217 case LFUN_CAPITALIZE_WORD:
1218 owner->currentBuffer()->update(-2);
1220 owner->currentBuffer()->text->ChangeWordCase(1);
1221 owner->currentBuffer()->update(1);
1225 case LFUN_INSERT_LABEL:
1226 MenuInsertLabel(argument.c_str());
1229 case LFUN_INSERT_REF:
1233 case LFUN_REFTOGGLE:
1236 (InsetRef*)getInsetByCode(Inset::REF_CODE);
1238 if (inset->getFlag()==InsetRef::REF)
1239 inset->setFlag(InsetRef::PAGE_REF);
1241 inset->setFlag(InsetRef::REF);
1244 setErrorMessage(N_("No cross-reference to toggle"));
1251 owner->currentView()->restorePosition();
1257 string label(argument);
1258 if (label.empty()) {
1260 (InsetRef*)getInsetByCode(Inset::REF_CODE);
1262 label = inset->getContents();
1265 if (!label.empty()) {
1266 owner->currentView()->savePosition();
1267 owner->currentBuffer()->gotoLabel(label.c_str());
1272 case LFUN_MENU_OPEN_BY_NAME:
1273 owner->getMenus()->openByName(argument);
1274 break; // RVDK_PATCH_5
1276 case LFUN_SPELLCHECK:
1277 if (lyxrc->isp_command != "none")
1279 break; // RVDK_PATCH_5
1281 // --- Cursor Movements -----------------------------
1284 Buffer *tmpbuffer = owner->currentBuffer();
1285 LyXText *tmptext = owner->currentBuffer()->text;
1286 if(!tmptext->mark_set)
1288 tmpbuffer->update(-2);
1289 if (tmptext->cursor.pos < tmptext->cursor.par->Last()
1290 && tmptext->cursor.par->GetChar(tmptext->cursor.pos)
1292 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)
1293 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)->Editable()==2){
1294 Inset* tmpinset = tmptext->cursor.par->GetInset(tmptext->cursor.pos);
1295 setMessage(tmpinset->EditMessage());
1296 tmpinset->Edit(0,0);
1299 tmptext->CursorRight();
1300 owner->currentBuffer()->text->FinishUndo();
1301 moveCursorUpdate(false);
1302 owner->getMiniBuffer()->Set(CurrentState());
1308 // This is soooo ugly. Isn`t it possible to make
1309 // it simpler? (Lgb)
1310 LyXText *txt= owner->currentBuffer()->text;
1311 if(!txt->mark_set) BeforeChange();
1312 owner->currentBuffer()->update(-2);
1314 if (txt->cursor.pos < txt->cursor.par->Last()
1315 && txt->cursor.par->GetChar(txt->cursor.pos)
1317 && txt->cursor.par->GetInset(txt->cursor.pos)
1318 && txt->cursor.par->GetInset(txt->cursor.pos)->Editable()==2) {
1319 Inset* tmpinset = txt->cursor.par->GetInset(txt->cursor.pos);
1320 setMessage(tmpinset->EditMessage());
1321 tmpinset->Edit(tmpinset->Width(txt->GetFont(txt->cursor.par,
1322 txt->cursor.pos)),0);
1323 // tmpinset->Edit(-1, 0); // -1 means go rightmost
1326 owner->currentBuffer()->text->FinishUndo();
1327 moveCursorUpdate(false);
1328 owner->getMiniBuffer()->Set(CurrentState());
1333 if(!owner->currentBuffer()->text->mark_set) BeforeChange();
1334 owner->currentBuffer()->update(-3);
1335 owner->currentBuffer()->text->CursorUp();
1336 owner->currentBuffer()->text->FinishUndo();
1337 moveCursorUpdate(false);
1338 owner->getMiniBuffer()->Set(CurrentState());
1342 if(!owner->currentBuffer()->text->mark_set)
1344 owner->currentBuffer()->update(-3);
1345 owner->currentBuffer()->text->CursorDown();
1346 owner->currentBuffer()->text->FinishUndo();
1347 moveCursorUpdate(false);
1348 owner->getMiniBuffer()->Set(CurrentState());
1351 case LFUN_UP_PARAGRAPH:
1352 if(!owner->currentBuffer()->text->mark_set)
1354 owner->currentBuffer()->update(-3);
1355 owner->currentBuffer()->text->CursorUpParagraph();
1356 owner->currentBuffer()->text->FinishUndo();
1357 moveCursorUpdate(false);
1358 owner->getMiniBuffer()->Set(CurrentState());
1361 case LFUN_DOWN_PARAGRAPH:
1362 if(!owner->currentBuffer()->text->mark_set)
1364 owner->currentBuffer()->update(-3);
1365 owner->currentBuffer()->text->CursorDownParagraph();
1366 owner->currentBuffer()->text->FinishUndo();
1367 moveCursorUpdate(false);
1368 owner->getMiniBuffer()->Set(CurrentState());
1372 if(!owner->currentBuffer()->text->mark_set)
1374 owner->currentBuffer()->update(-3);
1375 owner->currentView()->cursorPrevious();
1376 owner->currentBuffer()->text->FinishUndo();
1377 moveCursorUpdate(false);
1378 owner->getMiniBuffer()->Set(CurrentState());
1382 if(!owner->currentBuffer()->text->mark_set)
1384 owner->currentBuffer()->update(-3);
1385 owner->currentView()->cursorNext();
1386 owner->currentBuffer()->text->FinishUndo();
1387 moveCursorUpdate(false);
1388 owner->getMiniBuffer()->Set(CurrentState());
1392 if(!owner->currentBuffer()->text->mark_set)
1394 owner->currentBuffer()->update(-2);
1395 owner->currentBuffer()->text->CursorHome();
1396 owner->currentBuffer()->text->FinishUndo();
1397 moveCursorUpdate(false);
1398 owner->getMiniBuffer()->Set(CurrentState());
1402 if(!owner->currentBuffer()->text->mark_set)
1404 owner->currentBuffer()->update(-2);
1405 owner->currentBuffer()->text->CursorEnd();
1406 owner->currentBuffer()->text->FinishUndo();
1407 moveCursorUpdate(false);
1408 owner->getMiniBuffer()->Set(CurrentState());
1412 if(!owner->currentBuffer()->text->mark_set)
1414 owner->currentBuffer()->update(-2);
1415 owner->currentBuffer()->text->CursorTab();
1416 owner->currentBuffer()->text->FinishUndo();
1417 moveCursorUpdate(false);
1418 owner->getMiniBuffer()->Set(CurrentState());
1421 case LFUN_WORDRIGHT:
1422 if(!owner->currentBuffer()->text->mark_set)
1424 owner->currentBuffer()->update(-2);
1425 owner->currentBuffer()->text->CursorRightOneWord();
1426 owner->currentBuffer()->text->FinishUndo();
1427 moveCursorUpdate(false);
1428 owner->getMiniBuffer()->Set(CurrentState());
1432 if(!owner->currentBuffer()->text->mark_set)
1434 owner->currentBuffer()->update(-2);
1435 owner->currentBuffer()->text->CursorLeftOneWord();
1436 owner->currentBuffer()->text->FinishUndo();
1437 moveCursorUpdate(false);
1438 owner->getMiniBuffer()->Set(CurrentState());
1441 case LFUN_BEGINNINGBUF:
1442 if(!owner->currentBuffer()->text->mark_set)
1444 owner->currentBuffer()->update(-2);
1445 owner->currentBuffer()->text->CursorTop();
1446 owner->currentBuffer()->text->FinishUndo();
1447 moveCursorUpdate(false);
1448 owner->getMiniBuffer()->Set(CurrentState());
1452 if(!owner->currentBuffer()->text->mark_set)
1454 owner->currentBuffer()->update(-2);
1455 owner->currentBuffer()->text->CursorBottom();
1456 owner->currentBuffer()->text->FinishUndo();
1457 moveCursorUpdate(false);
1458 owner->getMiniBuffer()->Set(CurrentState());
1462 /* cursor selection ---------------------------- */
1464 owner->currentBuffer()->update(-2);
1465 owner->currentBuffer()->text->CursorRight();
1466 owner->currentBuffer()->text->FinishUndo();
1467 moveCursorUpdate(true);
1468 owner->getMiniBuffer()->Set(CurrentState());
1472 owner->currentBuffer()->update(-2);
1473 owner->currentBuffer()->text->CursorLeft();
1474 owner->currentBuffer()->text->FinishUndo();
1475 moveCursorUpdate(true);
1476 owner->getMiniBuffer()->Set(CurrentState());
1480 owner->currentBuffer()->update(-2);
1481 owner->currentBuffer()->text->CursorUp();
1482 owner->currentBuffer()->text->FinishUndo();
1483 moveCursorUpdate(true);
1484 owner->getMiniBuffer()->Set(CurrentState());
1488 owner->currentBuffer()->update(-2);
1489 owner->currentBuffer()->text->CursorDown();
1490 owner->currentBuffer()->text->FinishUndo();
1491 moveCursorUpdate(true);
1492 owner->getMiniBuffer()->Set(CurrentState());
1495 case LFUN_UP_PARAGRAPHSEL:
1496 owner->currentBuffer()->update(-2);
1497 owner->currentBuffer()->text->CursorUpParagraph();
1498 owner->currentBuffer()->text->FinishUndo();
1499 moveCursorUpdate(true);
1500 owner->getMiniBuffer()->Set(CurrentState());
1503 case LFUN_DOWN_PARAGRAPHSEL:
1504 owner->currentBuffer()->update(-2);
1505 owner->currentBuffer()->text->CursorDownParagraph();
1506 owner->currentBuffer()->text->FinishUndo();
1507 moveCursorUpdate(true);
1508 owner->getMiniBuffer()->Set(CurrentState());
1512 owner->currentBuffer()->update(-2);
1513 owner->currentView()->cursorPrevious();
1514 owner->currentBuffer()->text->FinishUndo();
1515 moveCursorUpdate(true);
1516 owner->getMiniBuffer()->Set(CurrentState());
1520 owner->currentBuffer()->update(-2);
1521 owner->currentView()->cursorNext();
1522 owner->currentBuffer()->text->FinishUndo();
1523 moveCursorUpdate(true);
1524 owner->getMiniBuffer()->Set(CurrentState());
1528 owner->currentBuffer()->update(-2);
1529 owner->currentBuffer()->text->CursorHome();
1530 owner->currentBuffer()->text->FinishUndo();
1531 moveCursorUpdate(true);
1532 owner->getMiniBuffer()->Set(CurrentState());
1536 owner->currentBuffer()->update(-2);
1537 owner->currentBuffer()->text->CursorEnd();
1538 owner->currentBuffer()->text->FinishUndo();
1539 moveCursorUpdate(true);
1540 owner->getMiniBuffer()->Set(CurrentState());
1543 case LFUN_WORDRIGHTSEL:
1544 owner->currentBuffer()->update(-2);
1545 owner->currentBuffer()->text->CursorRightOneWord();
1546 owner->currentBuffer()->text->FinishUndo();
1547 moveCursorUpdate(true);
1548 owner->getMiniBuffer()->Set(CurrentState());
1551 case LFUN_WORDLEFTSEL:
1552 owner->currentBuffer()->update(-2);
1553 owner->currentBuffer()->text->CursorLeftOneWord();
1554 owner->currentBuffer()->text->FinishUndo();
1555 moveCursorUpdate(true);
1556 owner->getMiniBuffer()->Set(CurrentState());
1559 case LFUN_BEGINNINGBUFSEL:
1560 owner->currentBuffer()->update(-2);
1561 owner->currentBuffer()->text->CursorTop();
1562 owner->currentBuffer()->text->FinishUndo();
1563 moveCursorUpdate(true);
1564 owner->getMiniBuffer()->Set(CurrentState());
1567 case LFUN_ENDBUFSEL:
1568 owner->currentBuffer()->update(-2);
1569 owner->currentBuffer()->text->CursorBottom();
1570 owner->currentBuffer()->text->FinishUndo();
1571 moveCursorUpdate(true);
1572 owner->getMiniBuffer()->Set(CurrentState());
1575 // --- text changing commands ------------------------
1576 case LFUN_BREAKLINE:
1578 owner->currentBuffer()->text->InsertChar(LYX_META_NEWLINE);
1580 SetUpdateTimer(0.01);
1581 moveCursorUpdate(false);
1584 case LFUN_PROTECTEDSPACE:
1586 owner->currentBuffer()->text->
1587 InsertChar(LYX_META_PROTECTED_SEPARATOR);
1590 moveCursorUpdate(false);
1594 if(owner->currentBuffer()->text->mark_set) {
1596 owner->currentBuffer()->update(0);
1597 setMessage(N_("Mark removed"));
1600 owner->currentBuffer()->text->mark_set = 1;
1601 owner->currentBuffer()->update(0);
1602 setMessage(N_("Mark set"));
1604 owner->currentBuffer()->text->sel_cursor =
1605 owner->currentBuffer()->text->cursor;
1610 if (!owner->currentBuffer()->text->selection) {
1611 owner->currentBuffer()->text->Delete();
1612 owner->currentBuffer()->text->sel_cursor =
1613 owner->currentBuffer()->text->cursor;
1615 // It is possible to make it a lot faster still
1616 // just comment out the lone below...
1617 owner->currentView()->getScreen()->ShowCursor();
1624 case LFUN_DELETE_SKIP:
1626 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1628 LyXCursor cursor = owner->currentBuffer()->text->cursor;
1631 if (!owner->currentBuffer()->text->selection) {
1632 if (cursor.pos == cursor.par->Last()) {
1633 owner->currentBuffer()->text->CursorRight();
1634 cursor = owner->currentBuffer()->text->cursor;
1636 && !(cursor.par->added_space_top
1637 == VSpace (VSpace::NONE))) {
1638 owner->currentBuffer()->text->SetParagraph
1639 (cursor.par->line_top,
1640 cursor.par->line_bottom,
1641 cursor.par->pagebreak_top,
1642 cursor.par->pagebreak_bottom,
1643 VSpace(VSpace::NONE),
1644 cursor.par->added_space_bottom,
1646 cursor.par->labelwidthstring, 0);
1647 owner->currentBuffer()->text->CursorLeft();
1648 owner->currentBuffer()->update (1);
1650 owner->currentBuffer()->text->CursorLeft();
1651 owner->currentBuffer()->text->Delete();
1652 owner->currentBuffer()->text->sel_cursor =
1653 owner->currentBuffer()->text->cursor;
1657 owner->currentBuffer()->text->Delete();
1658 owner->currentBuffer()->text->sel_cursor =
1659 owner->currentBuffer()->text->cursor;
1669 /* -------> Delete word forward. */
1670 case LFUN_DELETE_WORD_FORWARD:
1671 owner->currentBuffer()->update(-2);
1673 owner->currentBuffer()->text->DeleteWordForward();
1674 owner->currentBuffer()->update( 1 );
1676 moveCursorUpdate(false);
1679 /* -------> Delete word backward. */
1680 case LFUN_DELETE_WORD_BACKWARD:
1681 owner->currentBuffer()->update(-2);
1683 owner->currentBuffer()->text->DeleteWordBackward();
1684 owner->currentBuffer()->update( 1 );
1686 moveCursorUpdate(false);
1689 /* -------> Kill to end of line. */
1690 case LFUN_DELETE_LINE_FORWARD:
1692 owner->currentBuffer()->update(-2);
1693 owner->currentBuffer()->text->DeleteLineForward();
1694 owner->currentBuffer()->update( 1 );
1696 moveCursorUpdate(false);
1699 /* -------> Set mark off. */
1702 owner->currentBuffer()->update(0);
1703 owner->currentBuffer()->text->sel_cursor =
1704 owner->currentBuffer()->text->cursor;
1705 setMessage(N_("Mark off"));
1708 /* -------> Set mark on. */
1711 owner->currentBuffer()->text->mark_set = 1;
1712 owner->currentBuffer()->update( 0 );
1713 owner->currentBuffer()->text->sel_cursor =
1714 owner->currentBuffer()->text->cursor;
1715 setMessage(N_("Mark on"));
1718 case LFUN_BACKSPACE:
1721 if (!owner->currentBuffer()->text->selection) {
1722 if (owner->getIntl()->getTrans()->backspace()) {
1723 owner->currentBuffer()->text->Backspace();
1724 owner->currentBuffer()->text->sel_cursor =
1725 owner->currentBuffer()->text->cursor;
1727 // It is possible to make it a lot faster still
1728 // just comment out the lone below...
1729 owner->currentView()->getScreen()->ShowCursor();
1738 case LFUN_BACKSPACE_SKIP:
1740 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1742 LyXCursor cursor = owner->currentBuffer()->text->cursor;
1745 if (!owner->currentBuffer()->text->selection) {
1747 && !(cursor.par->added_space_top
1748 == VSpace (VSpace::NONE))) {
1749 owner->currentBuffer()->text->SetParagraph
1750 (cursor.par->line_top,
1751 cursor.par->line_bottom,
1752 cursor.par->pagebreak_top,
1753 cursor.par->pagebreak_bottom,
1754 VSpace(VSpace::NONE), cursor.par->added_space_bottom,
1756 cursor.par->labelwidthstring, 0);
1757 owner->currentBuffer()->update (1);
1759 owner->currentBuffer()->text->Backspace();
1760 owner->currentBuffer()->text->sel_cursor
1770 case LFUN_BREAKPARAGRAPH:
1773 owner->currentBuffer()->text->BreakParagraph(0);
1775 SetUpdateTimer(0.01);
1776 owner->currentBuffer()->text->sel_cursor =
1777 owner->currentBuffer()->text->cursor;
1781 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1784 owner->currentBuffer()->text->BreakParagraph(1);
1786 SetUpdateTimer(0.01);
1787 owner->currentBuffer()->text->sel_cursor =
1788 owner->currentBuffer()->text->cursor;
1792 case LFUN_BREAKPARAGRAPH_SKIP:
1794 // When at the beginning of a paragraph, remove
1795 // indentation and add a "defskip" at the top.
1796 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
1798 LyXCursor cursor = owner->currentBuffer()->text->cursor;
1801 if (cursor.pos == 0) {
1802 if (cursor.par->added_space_top == VSpace(VSpace::NONE)) {
1803 owner->currentBuffer()->text->SetParagraph
1804 (cursor.par->line_top,
1805 cursor.par->line_bottom,
1806 cursor.par->pagebreak_top,
1807 cursor.par->pagebreak_bottom,
1808 VSpace(VSpace::DEFSKIP), cursor.par->added_space_bottom,
1810 cursor.par->labelwidthstring, 1);
1811 owner->currentBuffer()->update(1);
1815 owner->currentBuffer()->text->BreakParagraph(0);
1818 SetUpdateTimer(0.01);
1819 owner->currentBuffer()->text->sel_cursor = cursor;
1825 owner->currentBuffer()->text->InsertChar('\"'); // This " matches the single quote in the code
1828 moveCursorUpdate(false);
1834 InsetCommand *new_inset;
1835 if (action == LFUN_HTMLURL)
1836 new_inset = new InsetUrl("htmlurl", "", "");
1838 new_inset = new InsetUrl("url", "", "");
1839 owner->currentBuffer()->insertInset(new_inset);
1840 new_inset->Edit(0, 0);
1844 // --- lyxserver commands ----------------------------
1846 case LFUN_CHARATCURSOR:
1848 int pos = owner->currentBuffer()->text->cursor.pos;
1849 if(pos < owner->currentBuffer()->text->cursor.par->last)
1850 dispatch_buffer = owner->currentBuffer()->text->
1851 cursor.par->text[pos];
1853 dispatch_buffer = "EOF";
1859 tostr(owner->currentBuffer()->text->cursor.x) + ' '
1860 + tostr(owner->currentBuffer()->text->cursor.y);
1867 sscanf(argument.c_str(), " %d %ld", &x, &y);
1868 owner->currentBuffer()->text->SetCursorFromCoordinates(x, y);
1872 case LFUN_GETLAYOUT:
1874 tostr(owner->currentBuffer()->text->cursor.par->layout);
1879 LyXFont *font = &(owner->currentBuffer()->text->current_font);
1880 if(font->shape() == LyXFont::ITALIC_SHAPE)
1881 dispatch_buffer = 'E';
1882 else if(font->shape() == LyXFont::SMALLCAPS_SHAPE)
1883 dispatch_buffer = 'N';
1885 dispatch_buffer = '0';
1892 LyXFont *font = &(owner->currentBuffer()->text->current_font);
1893 if(font->latex() == LyXFont::ON)
1894 dispatch_buffer = 'L';
1896 dispatch_buffer = '0';
1901 setMessage(owner->currentBuffer()->getFileName());
1902 lyxerr.debug() << "FNAME["
1903 << owner->currentBuffer()->getFileName()
1910 keyseq.print(buf,100);
1911 dispatch_buffer = buf;
1912 lyxserver->notifyClient(dispatch_buffer);
1916 case LFUN_GOTOFILEROW:
1918 char file_name[100];
1920 sscanf(argument.c_str(), " %s %d", file_name, &row);
1922 // Must replace extension of the file to be .lyx and get full path
1923 string s = ChangeExtension(string(file_name), ".lyx", false);
1925 // Either change buffer or load the file
1926 if (bufferlist.exists(s))
1927 owner->currentView()->setBuffer(bufferlist.getBuffer(s));
1929 owner->currentView()->setBuffer(bufferlist.loadLyXFile(s));
1932 owner->currentBuffer()->setCursorFromRow(row);
1936 if (owner->currentBuffer()->text->cursor.y >
1937 owner->currentView()->getWorkArea()->h / 2) {
1938 owner->currentView()->getScreen()->
1939 Draw(owner->currentBuffer()->text->cursor.y -
1940 owner->currentView()->getWorkArea()->h/2);
1942 owner->currentView()->getScreen()->
1945 owner->currentBuffer()->update(0);
1946 owner->currentView()->redraw();
1953 int qa = lyxaction.LookupFunc(argument.c_str());
1954 setMessage(lyxaction.helpText((kb_action)qa));
1958 // --- accented characters ---------------------------
1961 case LFUN_CIRCUMFLEX:
1971 case LFUN_SPECIAL_CARON:
1974 case LFUN_HUNG_UMLAUT:
1980 if (keyseq.length==-1 && keyseq.getiso()!=0)
1985 owner->getIntl()->getTrans()->
1986 deadkey(c, get_accent(action).accent,
1987 owner->currentBuffer()->text);
1989 // Need to reset, in case the minibuffer calls these
1994 // copied verbatim from do_accent_char
1997 owner->currentBuffer()->text->sel_cursor =
1998 owner->currentBuffer()->text->cursor;
2002 // --- toolbar ----------------------------------
2003 case LFUN_PUSH_TOOLBAR:
2005 int nth = strToInt(argument);
2006 if (lyxerr.debugging(Debug::TOOLBAR)) {
2007 lyxerr << "LFUN_PUSH_TOOLBAR: argument = `"
2008 << argument << "'\n"
2009 << "LFUN_PUSH_TOOLBAR: nth = `"
2010 << nth << "'" << endl;
2015 setErrorMessage(N_("Push-toolbar needs argument > 0"));
2017 owner->getToolbar()->push(nth);
2022 case LFUN_ADD_TO_TOOLBAR:
2024 if (lyxerr.debugging(Debug::TOOLBAR)) {
2025 lyxerr << "LFUN_ADD_TO_TOOLBAR:"
2026 "argument = `" << argument << '\'' << endl;
2028 string tmp(argument);
2029 //lyxerr <<string("Argument: ") + argument);
2030 //lyxerr <<string("Tmp : ") + tmp);
2033 setErrorMessage(N_("Usage: toolbar-add-to <LyX command>"));
2035 owner->getToolbar()->add(argument, false);
2036 owner->getToolbar()->set();
2041 // --- insert characters ----------------------------------------
2043 case LFUN_INSERT_INSET_LATEX:
2045 Inset *new_inset = new InsetLatex(argument);
2046 owner->currentBuffer()->insertInset(new_inset);
2050 // --- Mathed stuff. If we are here, there is no locked inset yet.
2055 if (!greek_kb_flag) {
2057 setMessage(N_("Math greek mode on"));
2064 case LFUN_GREEK_TOGGLE:
2066 greek_kb_flag = (greek_kb_flag) ? 0: 2;
2067 if (greek_kb_flag) {
2068 setMessage(N_("Math greek keyboard on"));
2070 setMessage(N_("Math greek keyboard off"));
2075 case LFUN_MATH_DELIM:
2076 case LFUN_INSERT_MATRIX:
2078 if (owner->currentView()->available()) {
2079 owner->currentBuffer()->
2080 open_new_inset(new InsetFormula(false));
2081 owner->currentBuffer()->
2082 the_locking_inset->LocalDispatch(action, argument.c_str());
2087 case LFUN_INSERT_MATH:
2089 math_insert_symbol(argument.c_str());
2093 case LFUN_MATH_DISPLAY:
2095 if (owner->currentView()->available())
2096 owner->currentBuffer()->open_new_inset(new InsetFormula(true));
2100 case LFUN_MATH_MACRO:
2102 if (owner->currentView()->available()) {
2105 setErrorMessage(N_("Missing argument"));
2107 string s1 = token(s, ' ', 1);
2108 int na = s1.empty() ? 0: atoi(s1.c_str());
2109 owner->currentBuffer()->
2110 open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2116 case LFUN_MATH_MODE: // Open or create a math inset
2119 if (owner->currentView()->available())
2120 owner->currentBuffer()->open_new_inset(new InsetFormula);
2121 setMessage(N_("Math editor mode"));
2125 case LFUN_MATH_NUMBER:
2126 case LFUN_MATH_LIMITS:
2128 setErrorMessage(N_("This is only allowed in math mode!"));
2132 case LFUN_INSERT_CITATION:
2134 InsetCitation *new_inset = new InsetCitation();
2136 // The note, if any, must be after the key, delimited
2137 // by a | so both key and remark can have spaces.
2138 if (!argument.empty()) {
2139 string lsarg(argument);
2140 if (contains(lsarg, "|")) {
2141 new_inset->setContents(token(lsarg, '|', 0));
2142 new_inset->setOptions(token(lsarg, '|', 1));
2144 new_inset->setContents(lsarg);
2145 owner->currentBuffer()->insertInset(new_inset);
2147 owner->currentBuffer()->insertInset(new_inset);
2148 new_inset->Edit(0,0);
2153 case LFUN_INSERT_BIBTEX:
2155 // ale970405+lasgoutt970425
2156 // The argument can be up to two tokens separated
2157 // by a space. The first one is the bibstyle.
2158 string lsarg(argument);
2159 string bibstyle = token(lsarg, ' ', 1);
2160 if (bibstyle.empty())
2162 InsetBibtex *new_inset
2163 = new InsetBibtex(token(lsarg, ' ', 0),
2165 owner->currentBuffer());
2167 owner->currentBuffer()->insertInset(new_inset);
2168 if (lsarg.empty()) {
2169 new_inset->Edit(0,0);
2174 // BibTeX data bases
2175 case LFUN_BIBDB_ADD:
2177 InsetBibtex *inset =
2178 (InsetBibtex*)getInsetByCode(Inset::BIBTEX_CODE);
2180 inset->addDatabase(argument);
2185 case LFUN_BIBDB_DEL:
2187 InsetBibtex *inset =
2188 (InsetBibtex*)getInsetByCode(Inset::BIBTEX_CODE);
2190 inset->delDatabase(argument);
2195 case LFUN_BIBTEX_STYLE:
2197 InsetBibtex *inset =
2198 (InsetBibtex*)getInsetByCode(Inset::BIBTEX_CODE);
2200 inset->setOptions(argument);
2205 case LFUN_INDEX_INSERT:
2206 case LFUN_INDEX_INSERT_LAST:
2208 InsetIndex *new_inset = new InsetIndex();
2209 if (!argument.empty()) {
2210 string lsarg(argument);
2211 new_inset->setContents(lsarg);
2212 owner->currentBuffer()->insertInset(new_inset);
2215 //get the current word for an argument
2220 int lastpos =owner->currentBuffer()->text->cursor.pos-1;
2222 //this shouldn't happen, but let's be careful
2223 if (lastpos < 0) lastpos=0;
2225 // get the current word
2226 // note that this must be done before
2227 // inserting the inset, or the inset will break
2229 string curstring(owner->currentBuffer()->text->cursor.par->GetWord(lastpos));
2231 //make the new inset and write the current word into it
2232 InsetIndex *new_inset = new InsetIndex();
2234 new_inset->setContents(curstring);
2236 //don't edit it if the call was to INSERT_LAST
2237 if(action!=LFUN_INDEX_INSERT_LAST) {
2238 new_inset->Edit(0,0);
2240 //it looks blank on the screen unless
2241 //we do something. put it here.
2243 // move the cursor to the returned value of lastpos
2244 // but only for the auto-insert
2245 owner->currentBuffer()->text->cursor.pos=lastpos;
2248 //put the new inset into the buffer.
2249 // there should be some way of knowing the user
2250 //cancelled & avoiding this, but i don't know how
2251 owner->currentBuffer()->insertInset(new_inset);
2256 case LFUN_INDEX_PRINT:
2258 Inset *new_inset = new InsetPrintIndex(owner->currentBuffer());
2259 owner->currentBuffer()->insertInset(new_inset, "Standard", true);
2263 case LFUN_PARENTINSERT:
2265 lyxerr << "arg " << argument << endl;
2266 Inset *new_inset = new InsetParent(argument, owner->currentBuffer());
2267 owner->currentBuffer()->insertInset(new_inset, "Standard", true);
2271 case LFUN_CHILDINSERT:
2273 Inset *new_inset = new InsetInclude(argument,owner->currentBuffer());
2274 owner->currentBuffer()->insertInset(new_inset, "Standard", true);
2275 new_inset->Edit(0,0);
2279 case LFUN_CHILDOPEN:
2281 string filename = MakeAbsPath(argument,
2282 OnlyPath(owner->currentBuffer()->getFileName()));
2283 setMessage(N_("Opening child document ") +
2284 MakeDisplayPath(filename) + "...");
2285 owner->currentView()->savePosition();
2286 if (bufferlist.exists(filename))
2287 owner->currentView()->setBuffer(bufferlist.getBuffer(filename));
2289 owner->currentView()->setBuffer(bufferlist.loadLyXFile(filename));
2293 case LFUN_INSERT_NOTE:
2297 case LFUN_INSERTFOOTNOTE:
2299 LyXParagraph::footnote_kind kind;
2300 if (argument == "footnote")
2301 { kind = LyXParagraph::FOOTNOTE; }
2302 else if (argument == "margin")
2303 { kind = LyXParagraph::MARGIN; }
2304 else if (argument == "figure")
2305 { kind = LyXParagraph::FIG; }
2306 else if (argument == "table")
2307 { kind = LyXParagraph::TAB; }
2308 else if (argument == "wide-fig")
2309 { kind = LyXParagraph::WIDE_FIG; }
2310 else if (argument == "wide-tab")
2311 { kind = LyXParagraph::WIDE_TAB; }
2312 else if (argument == "algorithm")
2313 { kind = LyXParagraph::ALGORITHM; }
2315 setErrorMessage(N_("Unknown kind of footnote"));
2318 owner->currentBuffer()->text->InsertFootnoteEnvironment(kind);
2319 owner->currentBuffer()->update(1);
2323 case LFUN_BUFFERBULLETSSELECT:
2327 case LFUN_TOGGLECURSORFOLLOW:
2328 cursor_follows_scrollbar = !cursor_follows_scrollbar;
2331 case LFUN_KMAP_OFF: // keymap off
2332 owner->getIntl()->KeyMapOn(false);
2335 case LFUN_KMAP_PRIM: // primary keymap
2336 owner->getIntl()->KeyMapPrim();
2339 case LFUN_KMAP_SEC: // secondary keymap
2340 owner->getIntl()->KeyMapSec();
2343 case LFUN_KMAP_TOGGLE: // toggle keymap
2344 owner->getIntl()->ToggleKeyMap();
2347 case LFUN_SELFINSERT:
2349 for (string::size_type i = 0; i < argument.length(); ++i) {
2350 owner->currentBuffer()->text->InsertChar(argument[i]);
2351 // This needs to be in the loop, or else we
2352 // won't break lines correctly. (Asger)
2356 owner->currentBuffer()->text->sel_cursor =
2357 owner->currentBuffer()->text->cursor;
2358 moveCursorUpdate(false);
2362 case LFUN_UNKNOWN_ACTION:
2364 if (owner->currentBuffer()->isReadonly()) {
2366 setErrorMessage(N_("Document is read only"));
2370 if (!argument.empty()) {
2372 /* Automatically delete the currently selected
2373 * text and replace it with what is being
2374 * typed in now. Depends on lyxrc settings
2375 * "auto_region_delete", which defaults to
2378 if ( lyxrc->auto_region_delete ) {
2379 if (owner->currentBuffer()->text->selection){
2380 owner->currentBuffer()->text->CutSelection(false);
2381 owner->currentBuffer()->update(-1);
2386 for (string::size_type i = 0; i < argument.length(); ++i) {
2387 if (greek_kb_flag) {
2388 if (!math_insert_greek(argument[i]))
2389 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->currentBuffer()->text);
2391 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->currentBuffer()->text);
2397 owner->currentBuffer()->text->sel_cursor =
2398 owner->currentBuffer()->text->cursor;
2399 moveCursorUpdate(false);
2402 // why is an "Unknown action" with empty
2403 // argument even dispatched in the first
2404 // place? I`ll probably change that. (Lgb)
2406 setErrorMessage(N_("Unknown action"));
2410 lyxerr << "A truly unknown func!" << endl;
2416 string res=getMessage();
2419 if (!commandshortcut.empty()) {
2420 string newbuf = owner->getMiniBuffer()->GetText();
2421 if (newbuf != commandshortcut) {
2422 owner->getMiniBuffer()->Set(newbuf
2428 owner->getMiniBuffer()->Set(string(_(res.c_str()))
2429 + " " + commandshortcut);
2432 return getMessage();
2436 void LyXFunc::setupLocalKeymap()
2438 keyseq.stdmap = keyseq.curmap = toplevel_keymap;
2439 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap;
2443 void LyXFunc::MenuNew(bool fromTemplate)
2445 string fname, initpath = lyxrc->document_path;
2448 if (owner->currentView()->available()) {
2449 string trypath = owner->currentBuffer()->filepath;
2450 // If directory is writeable, use this as default.
2451 if (IsDirWriteable(trypath) == 1)
2456 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2457 fileDlg.SetButton(1, _("Templates"), lyxrc->template_path);
2458 fname = fileDlg.Select(_("Enter Filename for new document"),
2459 initpath, "*.lyx", _("newfile"));
2462 if (fname.empty()) {
2463 owner->getMiniBuffer()->Set(_("Canceled."));
2464 lyxerr.debug() << "New Document Cancelled." << endl;
2468 // get absolute path of file and make sure the filename ends
2470 string s = MakeAbsPath(fname);
2471 if (!IsLyXFilename(s))
2474 // Check if the document already is open
2475 if (bufferlist.exists(s)){
2476 switch(AskConfirmation(_("Document is already open:"),
2477 MakeDisplayPath(s,50),
2478 _("Do you want to close that document now?\n"
2479 "('No' will just switch to the open version)")))
2481 case 1: // Yes: close the document
2482 if (!bufferlist.close(bufferlist.getBuffer(s)))
2483 // If close is canceled, we cancel here too.
2486 case 2: // No: switch to the open document
2487 owner->currentView()->setBuffer(bufferlist.getBuffer(s));
2489 case 3: // Cancel: Do nothing
2490 owner->getMiniBuffer()->Set(_("Canceled."));
2495 // Check whether the file already exists
2496 if (IsLyXFilename(s)) {
2497 FilePtr myfile(s, FilePtr::read);
2499 AskQuestion(_("File already exists:"),
2500 MakeDisplayPath(s,50),
2501 _("Do you want to open the document?"))) {
2503 owner->getMiniBuffer()->Set(_("Opening document"),
2504 MakeDisplayPath(s), "...");
2506 owner->currentView()->setBuffer(
2507 bufferlist.loadLyXFile(s));
2508 owner->getMiniBuffer()->Set(_("Document"),
2515 // The template stuff
2519 fname = fileDlg.Select(_("Choose template"),
2520 lyxrc->template_path,
2526 // find a free buffer
2527 lyxerr.debug() << "Find a free buffer." << endl;
2528 owner->currentView()->setBuffer(bufferlist.newFile(s,templname));
2532 void LyXFunc::MenuOpen()
2534 string initpath = lyxrc->document_path;
2537 if (owner->currentView()->available()) {
2538 string trypath = owner->currentBuffer()->filepath;
2539 // If directory is writeable, use this as default.
2540 if (IsDirWriteable(trypath) == 1)
2546 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2547 fileDlg.SetButton(1, _("Examples"),
2548 AddPath(system_lyxdir, "examples"));
2549 string filename = fileDlg.Select(_("Select Document to Open"),
2553 // check selected filename
2554 if (filename.empty()) {
2555 owner->getMiniBuffer()->Set(_("Canceled."));
2559 // get absolute path of file and make sure the filename ends
2561 filename = MakeAbsPath(filename);
2562 if (!IsLyXFilename(filename))
2566 owner->getMiniBuffer()->Set(_("Opening document"),
2567 MakeDisplayPath(filename), "...");
2568 Buffer * openbuf = bufferlist.loadLyXFile(filename);
2570 owner->currentView()->setBuffer(openbuf);
2571 owner->getMiniBuffer()->Set(_("Document"),
2572 MakeDisplayPath(filename),
2575 owner->getMiniBuffer()->Set(_("Could not open document"),
2576 MakeDisplayPath(filename));
2581 void LyXFunc::doImportASCII(bool linorpar)
2583 string initpath = lyxrc->document_path;
2586 if (owner->currentView()->available()) {
2587 string trypath = owner->currentBuffer()->filepath;
2588 // If directory is writeable, use this as default.
2589 if (IsDirWriteable(trypath) == 1)
2595 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2596 fileDlg.SetButton(1, _("Examples"),
2597 AddPath(system_lyxdir, "examples"));
2598 string filename = fileDlg.Select(_("Select ASCII file to Import"),
2602 // check selected filename
2603 if (filename.empty()) {
2604 owner->getMiniBuffer()->Set(_("Canceled."));
2608 // get absolute path of file
2609 filename = MakeAbsPath(filename);
2611 string s = ChangeExtension(filename, ".lyx", false);
2613 // Check if the document already is open
2614 if (bufferlist.exists(s)){
2615 switch(AskConfirmation(_("Document is already open:"),
2616 MakeDisplayPath(s,50),
2617 _("Do you want to close that document now?\n"
2618 "('No' will just switch to the open version)")))
2620 case 1: // Yes: close the document
2621 if (!bufferlist.close(bufferlist.getBuffer(s)))
2622 // If close is canceled, we cancel here too.
2625 case 2: // No: switch to the open document
2626 owner->currentView()->setBuffer(bufferlist.getBuffer(s));
2628 case 3: // Cancel: Do nothing
2629 owner->getMiniBuffer()->Set(_("Canceled."));
2634 // Check if a LyX document by the same root exists in filesystem
2635 FileInfo f(s, true);
2636 if (f.exist() && !AskQuestion(_("A document by the name"),
2638 _("already exists. Overwrite?"))) {
2639 owner->getMiniBuffer()->Set(_("Canceled."));
2643 owner->currentView()->setBuffer(bufferlist.newFile(s,string()));
2644 owner->getMiniBuffer()->Set(_("Importing ASCII file"),
2645 MakeDisplayPath(filename), "...");
2646 // Insert ASCII file
2647 InsertAsciiFile(filename,linorpar);
2648 owner->getMiniBuffer()->Set(_("ASCII file "),
2649 MakeDisplayPath(filename),
2654 void LyXFunc::doImportLaTeX(bool isnoweb)
2656 string initpath = lyxrc->document_path;
2659 if (owner->currentView()->available()) {
2660 string trypath = owner->currentBuffer()->filepath;
2661 // If directory is writeable, use this as default.
2662 if (IsDirWriteable(trypath) == 1)
2668 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2669 fileDlg.SetButton(1, _("Examples"),
2670 AddPath(system_lyxdir, "examples"));
2673 filename = fileDlg.Select(_("Select Noweb file to Import"),
2676 filename = fileDlg.Select(_("Select LaTeX file to Import"),
2682 // check selected filename
2683 if (filename.empty()) {
2684 owner->getMiniBuffer()->Set(_("Canceled."));
2688 // get absolute path of file
2689 filename = MakeAbsPath(filename);
2691 // Check if the document already is open
2692 string LyXfilename = ChangeExtension(filename, ".lyx", false);
2693 if (bufferlist.exists(LyXfilename)){
2694 switch(AskConfirmation(_("Document is already open:"),
2695 MakeDisplayPath(LyXfilename,50),
2696 _("Do you want to close that document now?\n"
2697 "('No' will just switch to the open version)")))
2699 case 1: // Yes: close the document
2700 if (!bufferlist.close(bufferlist.getBuffer(LyXfilename)))
2701 // If close is canceled, we cancel here too.
2704 case 2: // No: switch to the open document
2705 owner->currentView()->setBuffer(
2706 bufferlist.getBuffer(LyXfilename));
2708 case 3: // Cancel: Do nothing
2709 owner->getMiniBuffer()->Set(_("Canceled."));
2714 // Check if a LyX document by the same root exists in filesystem
2715 FileInfo f(LyXfilename, true);
2716 if (f.exist() && !AskQuestion(_("A document by the name"),
2717 MakeDisplayPath(LyXfilename),
2718 _("already exists. Overwrite?"))) {
2719 owner->getMiniBuffer()->Set(_("Canceled."));
2726 owner->getMiniBuffer()->Set(_("Importing LaTeX file"),
2727 MakeDisplayPath(filename), "...");
2728 ImportLaTeX myImport(filename);
2729 openbuf = myImport.run();
2731 owner->getMiniBuffer()->Set(_("Importing Noweb file"),
2732 MakeDisplayPath(filename), "...");
2733 ImportNoweb myImport(filename);
2734 openbuf = myImport.run();
2737 owner->currentView()->setBuffer(openbuf);
2738 owner->getMiniBuffer()->Set(isnoweb ?
2739 _("Noweb file ") : _("LateX file "),
2740 MakeDisplayPath(filename),
2743 owner->getMiniBuffer()->Set(isnoweb ?
2744 _("Could not import Noweb file") :
2745 _("Could not import LaTeX file"),
2746 MakeDisplayPath(filename));
2751 void LyXFunc::MenuInsertLyXFile(string const & filen)
2753 string filename = filen;
2755 if (filename.empty()) {
2756 // Launch a file browser
2757 string initpath = lyxrc->document_path;
2760 if (owner->currentView()->available()) {
2761 string trypath = owner->currentBuffer()->filepath;
2762 // If directory is writeable, use this as default.
2763 if (IsDirWriteable(trypath) == 1)
2769 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2770 fileDlg.SetButton(1, _("Examples"),
2771 AddPath(system_lyxdir, "examples"));
2772 filename = fileDlg.Select(_("Select Document to Insert"),
2776 // check selected filename
2777 if (filename.empty()) {
2778 owner->getMiniBuffer()->Set(_("Canceled."));
2783 // get absolute path of file and make sure the filename ends
2785 filename = MakeAbsPath(filename);
2786 if (!IsLyXFilename(filename))
2790 owner->getMiniBuffer()->Set(_("Inserting document"),
2791 MakeDisplayPath(filename), "...");
2792 bool res = owner->currentBuffer()->insertLyXFile(filename);
2794 owner->getMiniBuffer()->Set(_("Document"),
2795 MakeDisplayPath(filename),
2798 owner->getMiniBuffer()->Set(_("Could not insert document"),
2799 MakeDisplayPath(filename));
2804 void LyXFunc::reloadBuffer()
2806 string fn = owner->currentBuffer()->getFileName();
2807 if (bufferlist.close(owner->currentBuffer()))
2808 owner->currentView()->setBuffer(bufferlist.loadLyXFile(fn));
2812 void LyXFunc::CloseBuffer()
2814 if (bufferlist.close(owner->currentBuffer()) && !quitting) {
2815 if (bufferlist.isEmpty()) {
2816 // need this otherwise SEGV may occur while trying to
2817 // set variables that don't exist
2818 // since there's no current buffer
2819 CloseAllBufferRelatedPopups();
2822 owner->currentView()->setBuffer(bufferlist.first());
2828 Inset* LyXFunc::getInsetByCode(Inset::Code code)
2832 LyXCursor cursor = owner->currentBuffer()->text->cursor;
2833 int pos = cursor.pos;
2834 LyXParagraph *par = cursor.par;
2836 while (par && !found) {
2837 while ((inset = par->ReturnNextInsetPointer(pos))){
2838 if (inset->LyxCode()==code) {
2846 return (found) ? inset: 0;
2850 // Each "owner" should have it's own message method. lyxview and
2851 // the minibuffer would use the minibuffer, but lyxserver would
2852 // send an ERROR signal to its client. Alejandro 970603
2853 // This func is bit problematic when it comes to NLS, to make the
2854 // lyx servers client be language indepenent we must not translate
2855 // strings sent to this func.
2856 void LyXFunc::setErrorMessage(string const &m)
2858 dispatch_buffer = m;
2863 void LyXFunc::setMessage(string const & m)
2865 dispatch_buffer = m;