1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-1999 The LyX Team.
9 * ====================================================== */
18 #pragma implementation
21 #include "lyxlookup.h"
24 #include "bufferlist.h"
25 #include "lyxserver.h"
31 #include "insets/insetlatex.h"
33 #include "insets/inseturl.h"
34 #include "insets/insetlatexaccent.h"
35 #include "insets/insettoc.h"
36 #include "insets/insetlof.h"
37 #include "insets/insetloa.h"
38 #include "insets/insetlot.h"
39 #include "insets/insetref.h"
40 #include "insets/insetparent.h"
41 #include "insets/insetindex.h"
42 #include "insets/insetinclude.h"
43 #include "insets/insetbib.h"
44 #include "mathed/formulamacro.h"
46 #include "spellchecker.h" // RVDK_PATCH_5
47 #include "minibuffer.h"
51 #include "lyx_gui_misc.h"
52 #include "support/filetools.h"
53 #include "support/FileInfo.h"
54 #include "support/LAssert.h"
55 #include "support/syscall.h"
56 #include "support/lstrings.h"
57 #include "support/path.h"
58 #include "lyxscreen.h"
63 #include "trans_mgr.h"
64 #include "ImportLaTeX.h"
65 #include "ImportNoweb.h"
68 extern bool cursor_follows_scrollbar;
70 extern void InsertAsciiFile(string const &, bool);
71 extern void math_insert_symbol(char const*);
72 extern Bool math_insert_greek(char const); // why "Bool"?
73 extern BufferList bufferlist;
74 extern LyXServer * lyxserver;
75 extern short greek_kb_flag;
76 extern FD_form_toc * fd_form_toc;
77 extern bool selection_possible;
79 extern kb_keymap * toplevel_keymap;
81 extern void BeforeChange();
82 extern void MenuWrite(Buffer*);
83 extern void MenuWriteAs(Buffer*);
84 extern int MenuRunLaTeX(Buffer*);
85 extern int MenuBuildProg(Buffer*);
86 extern int MenuRunChktex(Buffer*);
87 extern bool MenuRunDvips(Buffer *, bool);
88 extern void MenuPrint(Buffer*);
89 extern void MenuSendto();
90 extern void QuitLyX();
91 extern void MenuFax(Buffer *);
92 extern void MenuMakeLaTeX(Buffer *);
93 extern void MenuMakeLinuxDoc(Buffer *);
94 extern void MenuMakeDocBook(Buffer *);
95 extern void MenuMakeAscii(Buffer *);
96 extern void MenuPasteSelection(char at);
97 extern LyXAction lyxaction;
99 extern tex_accent_struct get_accent(kb_action action);
101 extern void AutoSave();
102 extern void MenuSearch();
103 extern void CopyCB();
104 extern void CopyEnvironmentCB();
105 extern void PasteEnvironmentCB();
106 extern void GotoNote();
107 extern void NoteCB();
108 extern void OpenStuff();
109 extern void HyphenationPoint();
111 extern void EndOfSentenceDot();
112 extern void MenuSeparator();
114 extern void MenuUndo();
115 extern void MenuRedo();
116 extern void SmallUpdate(signed char);
117 extern void SetUpdateTimer(float timer= 0.3);
118 extern void FreeUpdateTimer();
119 extern bool MenuPreview(Buffer*);
120 extern bool MenuPreviewPS(Buffer*);
121 extern void MenuInsertLabel(char const *);
122 extern void MenuInsertRef();
123 extern void MenuLayoutCharacter();
124 extern void MenuLayoutParagraph();
125 extern void MenuLayoutDocument();
126 extern void MenuLayoutPaper();
127 extern void MenuLayoutTable(int flag);
128 extern void MenuLayoutQuotes();
129 extern void MenuLayoutPreamble();
130 extern void MenuLayoutSave();
131 extern void bulletForm();
133 extern Buffer * NewLyxFile(string const &);
134 extern void LoadLyXFile(string const &);
135 extern void Reconfigure();
137 extern int current_layout;
138 extern int getISOCodeFromLaTeX(char *);
140 extern int UnlockInset(UpdatableInset*);
142 extern void ShowLatexLog();
144 extern void UpdateInset(Inset* inset, bool mark_dirty = true);
146 /* === globals =========================================================== */
148 bool LyXFunc::show_sc = true;
151 LyXFunc::LyXFunc(LyXView *o)
155 lyx_dead_action = LFUN_NOACTION;
156 lyx_calling_dead_action = LFUN_NOACTION;
166 // I changed this func slightly. I commented out the ...FinishUndo(),
167 // this means that all places that used to have a moveCursorUpdate, now
168 // have a ...FinishUndo() as the preceeding statement. I have also added
169 // a moveCursorUpdate to some of the functions that updated the cursor, but
170 // that did not show its new position.
172 void LyXFunc::moveCursorUpdate(bool selecting)
174 if (selecting || owner->buffer()->text->mark_set) {
175 owner->buffer()->text->SetSelection();
176 owner->currentView()->getScreen()->ToggleToggle();
177 owner->buffer()->update(0);
179 owner->buffer()->update(-2); // this IS necessary
182 owner->currentView()->getScreen()->ShowCursor();
184 /* ---> Everytime the cursor is moved, show the current font state. */
185 // should this too me moved out of this func?
186 //owner->getMiniBuffer()->Set(CurrentState());
190 int LyXFunc::processKeyEvent(XEvent *ev)
197 XKeyEvent *keyevent = &ev->xkey;
198 KeySym keysym_return;
200 num_bytes = LyXLookupString(ev, s_r, 10, &keysym_return);
202 if (lyxerr.debugging(Debug::KEY)) {
203 lyxerr << "KeySym is "
204 << XKeysymToString(keysym_return)
206 << keysym_return << "]"
207 << " and num_bytes is "
209 << " the string returned is \""
210 << s_r << '\"' << endl;
212 // Do nothing if we have nothing (JMarc)
213 if (num_bytes == 0 && keysym_return == NoSymbol) {
214 lyxerr[Debug::KEY] << "Empty kbd action (probably composing)"
219 // this function should be used always [asierra060396]
220 if (owner->currentView()->available() &&
221 owner->buffer()->the_locking_inset &&
222 keysym_return == XK_Escape) {
223 UnlockInset(owner->buffer()->the_locking_inset);
224 owner->buffer()->text->CursorRight();
228 // Can we be sure that this will work for all X-Windows
229 // implementations? (Lgb)
230 // This code snippet makes lyx ignore some keys. Perhaps
231 // all of them should be explictly mentioned?
232 if((keysym_return >= XK_Shift_L && keysym_return <= XK_Hyper_R)
233 || keysym_return == XK_Mode_switch || keysym_return == 0x0)
236 // Do a one-deep top-level lookup for
237 // cancel and meta-fake keys. RVDK_PATCH_5
238 cancel_meta_seq.reset();
240 action = cancel_meta_seq.addkey(keysym_return, keyevent->state
241 &(ShiftMask|ControlMask
244 // When not cancel or meta-fake, do the normal lookup.
245 // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
246 // Mostly, meta_fake_bit = 0. RVDK_PATCH_5.
247 if ( (action != LFUN_CANCEL) && (action != LFUN_META_FAKE) ) {
249 // remove Caps Lock and Mod2 as a modifiers
250 action = keyseq.addkey(keysym_return,
251 (keyevent->state | meta_fake_bit)
252 &(ShiftMask|ControlMask
255 // Dont remove this unless you know what you are doing.
258 if (action == 0) action = LFUN_PREFIX;
260 if (lyxerr.debugging(Debug::KEY)) {
262 keyseq.print(buf, 100);
266 << num_bytes << "]" << endl;
269 // already here we know if it any point in going further
270 // why not return already here if action == -1 and
271 // num_bytes == 0? (Lgb)
273 if(keyseq.length>1 || keyseq.length<-1){
275 keyseq.print(buf, 100);
276 owner->getMiniBuffer()->Set(buf);
280 if (keyseq.length<-1) { // unknown key sequence...
283 keyseq.print(buf, 100);
284 owner->getMiniBuffer()->Set(_("Unknown sequence:"), buf);
288 char isochar = keyseq.getiso();
289 if (!(keyevent->state&ControlMask) &&
290 !(keyevent->state&Mod1Mask) &&
291 (isochar && keysym_return < 0xF000)) {
294 if (argument.empty()) {
295 lyxerr.debug() << "Empty argument!" << endl;
296 // This can`t possibly be of any use
297 // so we`ll skip the dispatch.
301 if (action == LFUN_SELFINSERT) {
305 bool tmp_sc = show_sc;
307 Dispatch(action, argument.c_str());
314 string LyXFunc::Dispatch(string const& s)
316 // Split command string into command and argument
317 string cmd, line = frontStrip(s);
318 string arg = strip(frontStrip(split(line, cmd, ' ')));
320 return Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
324 string LyXFunc::Dispatch(int ac,
325 char const *do_not_use_this_arg)
331 FL_OBJECT *ob = 0; // This will disapear soon
333 // we have not done anything wrong yet.
335 dispatch_buffer = string();
337 // if action is a pseudo-action, we need the real action
338 if (lyxaction.isPseudoAction(ac)) {
339 char const *tmparg = 0;
340 action = (kb_action)lyxaction.retrieveActionArg(ac, &tmparg);
344 action = (kb_action)ac;
345 if (do_not_use_this_arg)
346 argument = do_not_use_this_arg; // except here
349 selection_possible = false;
351 if (owner->currentView()->available()
352 && owner->currentView()->getScreen())
353 owner->currentView()->getScreen()->HideCursor();
355 if(!owner->currentView()->available()) {
356 // This lists the allowed funcs when we have no
359 case LFUN_MENU_OPEN_BY_NAME:
362 case LFUN_MENUNEWTMPLT:
365 case LFUN_PUSH_TOOLBAR:
366 case LFUN_ADD_TO_TOOLBAR:
367 case LFUN_EXEC_COMMAND:
368 case LFUN_DROP_LAYOUTS_CHOICE:
372 case LFUN_RECONFIGURE:
378 case LFUN_UNKNOWN_ACTION:
379 setErrorMessage(N_("Unknown action"));
380 goto exit_with_message;
382 setErrorMessage(N_("Command not allowed with"
383 "out any document open"));
384 goto exit_with_message; // action not allowed
388 commandshortcut = string();
390 if (lyxrc->display_shortcuts && show_sc) {
391 if (action != LFUN_SELFINSERT) {
392 // Put name of command and list of shortcuts
393 // for it in minibuffer
394 string comname = lyxaction.getActionName(action);
396 int pseudoaction = action;
397 bool argsadded = false;
399 if (!argument.empty()) {
400 // If we have the command with argument,
403 lyxaction.searchActionArg(action,
406 if (pseudoaction == -1) {
407 pseudoaction = action;
409 comname += " " + argument;
414 string shortcuts = toplevel_keymap->findbinding(pseudoaction);
416 if (!shortcuts.empty()) {
417 comname += ": " + shortcuts;
418 } else if (!argsadded) {
419 comname += " " + argument;
422 if (!comname.empty()) {
423 comname = strip(comname);
424 commandshortcut = "(" + comname + ')';
425 owner->getMiniBuffer()->Set(commandshortcut);
426 // Here we could even add a small pause,
427 // to annoy the user and make him learn
429 // No! That will just annoy, not teach
430 // anything. The user will read the messages
431 // if they are interested. (Asger)
436 // Now that we know which action, if the buffer is RO let's check
437 // whether the action is legal. Alejandro 970603
438 if (owner->currentView()->available() &&
439 owner->buffer()->isReadonly() &&
440 lyxaction.isFuncRO(action)) {
441 setErrorMessage(N_("Document is read-only"));
442 lyxerr.debug() << "Error: Document is read-only." << endl;
443 goto exit_with_message;
446 // If in math mode pass the control to
447 // the math inset [asierra060396]
448 if (owner->currentView()->available() &&
449 owner->buffer()->the_locking_inset) {
450 if (action>1 || (action == LFUN_UNKNOWN_ACTION && keyseq.length>= -1)) {
451 if (action == LFUN_UNKNOWN_ACTION && argument.empty()) {
452 argument = keyseq.getiso();
454 // Undo/Redo pre 0.13 is a bit tricky for insets.
455 if (action == LFUN_UNDO) {
457 UpdatableInset* inset =
458 owner->buffer()->the_locking_inset;
459 inset->GetCursorPos(slx, sly);
462 inset = (UpdatableInset*)owner->buffer()->text->cursor.par->GetInset(owner->buffer()->text->cursor.pos);
464 inset->Edit(slx, sly);
467 if (action == LFUN_REDO) {
469 UpdatableInset* inset = owner->buffer()->the_locking_inset;
470 inset->GetCursorPos(slx, sly);
473 inset = (UpdatableInset*)owner->buffer()->text->cursor.par->GetInset(owner->buffer()->text->cursor.pos);
475 inset->Edit(slx, sly);
478 if (owner->buffer()->the_locking_inset->LocalDispatch(action, argument.c_str()))
481 setMessage(N_("Text mode"));
482 if (action == LFUN_RIGHT || action == -1)
483 owner->buffer()->text->CursorRight();
484 if (action == LFUN_LEFT || action == LFUN_RIGHT)
491 // --- Misc -------------------------------------------
492 case LFUN_WORDFINDFORWARD :
493 case LFUN_WORDFINDBACKWARD : {
494 static string last_search;
495 string searched_string;
497 if (!argument.empty()) {
498 last_search = argument;
499 searched_string = argument;
501 searched_string = last_search;
504 LyXText * ltCur = owner->currentView()->buffer()->text ;
506 if (!searched_string.empty() &&
507 ( (action == LFUN_WORDFINDBACKWARD) ?
508 ltCur->SearchBackward( searched_string.c_str() ) :
509 ltCur->SearchForward( searched_string.c_str() )
512 // ??? What is that ???
513 owner->currentView()->buffer()->update(-2);
516 // clear the selection (if there is any)
517 owner->currentView()->getScreen()->ToggleSelection();
518 owner->currentView()->buffer()->text->ClearSelection();
520 // Move cursor so that successive C-s 's will not stand in place.
521 if( action == LFUN_WORDFINDFORWARD )
522 owner->buffer()->text->CursorRightOneWord();
523 owner->buffer()->text->FinishUndo();
524 moveCursorUpdate(false);
527 // set the new selection
528 // SetSelectionOverLenChars(owner->currentView()->currentBuffer()->text, iLenSelected);
529 owner->currentView()->getScreen()->ToggleSelection(false);
533 // REMOVED : if (owner->currentView()->getWorkArea()->focus)
534 owner->currentView()->getScreen()->ShowCursor();
540 if (owner->currentView()->available()
541 && owner->currentView()->getScreen()) {
542 owner->buffer()->update(-2);
545 keyseq.print(buf, 100, true);
546 owner->getMiniBuffer()->Set(buf, string(), string(), 1);
550 // --- Misc -------------------------------------------
551 case LFUN_EXEC_COMMAND:
552 owner->getMiniBuffer()->ExecCommand();
555 case LFUN_CANCEL: // RVDK_PATCH_5
558 if(owner->currentView()->available())
559 // cancel any selection
560 Dispatch(int(LFUN_MARK_OFF), 0);
561 setMessage(N_("Cancel"));
564 case LFUN_META_FAKE: // RVDK_PATCH_5
566 meta_fake_bit = Mod1Mask;
568 keyseq.print(buf, 98, true);
569 string res = string("M-") + buf;
570 setMessage(buf); // RVDK_PATCH_5
574 case LFUN_READ_ONLY_TOGGLE:
575 if (owner->buffer()->lyxvc.inUse()) {
576 owner->buffer()->lyxvc.toggleReadOnly();
578 owner->buffer()->setReadonly(
579 !owner->buffer()->isReadonly());
583 case LFUN_CENTER: // this is center and redraw.
585 if (owner->buffer()->text->cursor.y >
586 owner->currentView()->getWorkArea()->h / 2) {
587 owner->currentView()->getScreen()->
588 Draw(owner->buffer()->text->cursor.y -
589 owner->currentView()->getWorkArea()->h/2);
591 owner->currentView()->getScreen()->
594 owner->buffer()->update(0);
595 owner->currentView()->redraw();
599 if (owner->currentView()->available()) {
600 owner->buffer()->text->toggleAppendix();
601 owner->buffer()->update(1);
605 // --- Menus -----------------------------------------------
610 case LFUN_MENUNEWTMPLT:
618 case LFUN_CLOSEBUFFER:
623 MenuWrite(owner->buffer());
626 case LFUN_MENUWRITEAS:
627 MenuWriteAs(owner->buffer());
630 case LFUN_MENURELOAD:
635 MenuPreview(owner->buffer());
639 MenuPreviewPS(owner->buffer());
643 MenuRunLaTeX(owner->buffer());
647 MenuBuildProg(owner->buffer());
651 MenuRunChktex(owner->buffer());
655 MenuRunDvips(owner->buffer(), false);
659 MenuPrint(owner->buffer());
663 MenuFax(owner->buffer());
668 //needs argument as string
669 string extyp= argument;
672 if (extyp == "latex") {
673 // make sure that this buffer is not linuxdoc
674 MenuMakeLaTeX(owner->buffer());
677 else if (extyp == "linuxdoc") {
678 // make sure that this buffer is not latex
679 MenuMakeLinuxDoc(owner->buffer());
682 else if (extyp == "docbook") {
683 // make sure that this buffer is not latex or linuxdoc
684 MenuMakeDocBook(owner->buffer());
687 else if (extyp == "dvi") {
688 // Run LaTeX as "Update dvi..." Bernhard.
689 // We want the dvi in the current directory. This
690 // is achieved by temporarily disabling use of
691 // temp directory. As a side-effect, we get
692 // *.log and *.aux files also. (Asger)
693 bool flag = lyxrc->use_tempdir;
694 lyxrc->use_tempdir = false;
695 MenuRunLaTeX(owner->buffer());
696 lyxrc->use_tempdir = flag;
699 else if (extyp == "postscript") {
700 // Start Print-dialog. Not as good as dvi... Bernhard.
701 MenuPrint(owner->buffer());
702 // Since the MenuPrint is a pop-up, we can't use
703 // the same trick as above. (Asger)
704 // MISSING: Move of ps-file :-(
707 else if (extyp == "ascii") {
708 MenuMakeAscii(owner->buffer());
710 else if (extyp == "custom") {
715 else if (extyp == "html" && lyxrc->html_command != "none") {
716 // First, create LaTeX file
717 MenuMakeLaTeX(owner->buffer());
719 // And now, run the converter
720 string file = owner->buffer()->getFileName();
721 Path path(OnlyPath(file));
722 // the tex file name has to be correct for
723 // latex, but the html file name can be
725 string result = ChangeExtension(file, ".html", false);
726 file = ChangeExtension(SpaceLess(file), ".tex", false);
727 string tmp = lyxrc->html_command;
728 tmp = subst(tmp, "$$FName", file);
729 tmp = subst(tmp, "$$OutName", result);
731 int res = one.startscript(Systemcalls::System, tmp);
733 setMessage(_("Document exported as HTML to file `")
734 + MakeDisplayPath(result) +'\'');
736 setErrorMessage(_("Unable to convert to HTML the file `")
737 + MakeDisplayPath(file)
742 setErrorMessage(_("Unknown export type: ")
750 //needs argument as string
751 string imtyp= argument;
754 if (imtyp == "latex") {
755 doImportLaTeX(false);
758 else if (imtyp == "ascii") {
759 doImportASCII(false);
760 } else if (imtyp == "asciiparagraph") {
763 } else if (imtyp == "noweb") {
766 setErrorMessage(string(N_("Unknown import type: "))
778 if (fd_form_toc->form_toc->visible) {
779 fl_raise_form(fd_form_toc->form_toc);
781 static int ow = -1, oh;
782 fl_show_form(fd_form_toc->form_toc,
784 FL_FREE_SIZE, FL_FULLBORDER,
785 _("Table of Contents"));
787 ow = fd_form_toc->form_toc->w;
788 oh = fd_form_toc->form_toc->h;
790 fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
794 case LFUN_TOC_INSERT:
797 new InsetTOC(owner->buffer());
798 owner->buffer()->insertInset(new_inset,
803 case LFUN_LOF_INSERT:
806 new InsetLOF(owner->buffer());
807 owner->buffer()->insertInset(new_inset,
812 case LFUN_LOA_INSERT:
815 new InsetLOA(owner->buffer());
816 owner->buffer()->insertInset(new_inset,
821 case LFUN_LOT_INSERT:
824 new InsetLOT(owner->buffer());
825 owner->buffer()->insertInset(new_inset,
850 case LFUN_MENUSEARCH:
858 case LFUN_PASTESELECTION:
861 if (string(argument) == "paragraph") asPara = true;
862 MenuPasteSelection(asPara);
874 case LFUN_LAYOUT_COPY:
878 case LFUN_LAYOUT_PASTE:
879 PasteEnvironmentCB();
883 owner->currentView()->gotoError();
886 case LFUN_REMOVEERRORS:
887 if (owner->buffer()->removeAutoInsets()) {
888 owner->currentView()->redraw();
889 owner->currentView()->fitCursor();
890 owner->currentView()->updateScrollbar();
902 case LFUN_HYPHENATION:
910 case LFUN_END_OF_SENTENCE:
914 case LFUN_MENU_SEPARATOR:
930 case LFUN_DEPTH_PLUS:
946 case LFUN_RECONFIGURE:
951 if (owner->currentView()->available()
952 && !owner->buffer()->text->selection
953 && owner->buffer()->text->cursor.par->footnoteflag
954 != LyXParagraph::NO_FOOTNOTE)
955 { // only melt footnotes with FOOTMELT, not margins etc
956 if(owner->buffer()->text->cursor.par->footnotekind == LyXParagraph::FOOTNOTE)
963 case LFUN_MARGINMELT:
964 if (owner->currentView()->available()
965 && !owner->buffer()->text->selection
966 && owner->buffer()->text->cursor.par->footnoteflag
967 != LyXParagraph::NO_FOOTNOTE)
968 { // only melt margins
969 if(owner->buffer()->text->cursor.par->footnotekind == LyXParagraph::MARGIN)
976 // --- version control -------------------------------
977 case LFUN_VC_REGISTER:
979 if (!owner->buffer()->lyxvc.inUse())
980 owner->buffer()->lyxvc.registrer();
984 case LFUN_VC_CHECKIN:
986 if (owner->buffer()->lyxvc.inUse()
987 && !owner->buffer()->isReadonly())
988 owner->buffer()->lyxvc.checkIn();
992 case LFUN_VC_CHECKOUT:
994 if (owner->buffer()->lyxvc.inUse()
995 && owner->buffer()->isReadonly())
996 owner->buffer()->lyxvc.checkOut();
1000 case LFUN_VC_REVERT:
1002 owner->buffer()->lyxvc.revert();
1008 owner->buffer()->lyxvc.undoLast();
1012 case LFUN_VC_HISTORY:
1014 owner->buffer()->lyxvc.showLog();
1018 // --- buffers ----------------------------------------
1019 case LFUN_PREVBUFFER:
1020 #ifdef WITH_WARNINGS
1021 #warning fix this please
1023 // it is the LyXView or the BufferView that should
1024 // remember the previous buffer, not bufferlist.
1025 // if (owner->currentView()->available()){
1027 // owner->buffer()->update(-2);
1029 // owner->currentView()->setBuffer(bufferlist.prev());
1031 // owner->currentView()->
1032 // resizeCurrentBufferPseudoExpose();
1035 case LFUN_FILE_INSERT:
1037 MenuInsertLyXFile(argument);
1041 case LFUN_FILE_INSERT_ASCII:
1043 bool asPara = false;
1044 asPara = (string(argument) == "paragraph");
1045 InsertAsciiFile(string(), asPara);
1051 // servercmd: argument must be <file>:<template>
1052 Buffer * tmpbuf = 0;
1053 tmpbuf = NewLyxFile(argument);
1055 owner->currentView()->buffer(tmpbuf);
1059 case LFUN_FILE_OPEN:
1060 owner->currentView()->buffer(
1061 bufferlist.loadLyXFile(argument));
1064 case LFUN_LATEX_LOG:
1070 lyxerr.debug() << "LFUN_LAYOUTNO: (arg) " << argument << endl;
1071 int sel = strToInt(argument);
1072 lyxerr.debug() << "LFUN_LAYOUTNO: (sel) "<< sel << endl;
1074 // Should this give a setMessage instead?
1076 return string(); // illegal argument
1078 sel--; // sel 1..., but layout 0...
1080 // Pretend we got the name instead.
1081 Dispatch(int(LFUN_LAYOUT),
1082 textclasslist.NameOfLayout(owner->buffer()->
1091 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1092 << argument << endl;
1094 // Derive layout number from given argument (string)
1095 // and current buffer's textclass (number). */
1098 textclasslist.NumberOfLayout(owner->
1104 // see if we found the layout number:
1105 if (layoutno == -1) {
1106 setErrorMessage(string(N_("Layout ")) + argument +
1111 if (current_layout != layoutno) {
1112 owner->currentView()->getScreen()->HideCursor();
1113 current_layout = layoutno;
1114 owner->buffer()->update(-2);
1115 owner->buffer()->text->
1116 SetLayout(layoutno);
1117 owner->getToolbar()->combox->
1118 select(owner->buffer()->
1121 owner->buffer()->update(1);
1126 case LFUN_LAYOUT_DOCUMENT:
1127 MenuLayoutDocument();
1130 case LFUN_LAYOUT_PARAGRAPH:
1131 MenuLayoutParagraph();
1134 case LFUN_LAYOUT_CHARACTER:
1135 MenuLayoutCharacter();
1138 case LFUN_LAYOUT_TABLE:
1141 if (string(argument) == "true") flag = 1;
1142 MenuLayoutTable(flag);
1146 case LFUN_LAYOUT_PAPER:
1150 case LFUN_LAYOUT_QUOTES:
1154 case LFUN_LAYOUT_PREAMBLE:
1155 MenuLayoutPreamble();
1158 case LFUN_LAYOUT_SAVE_DEFAULT:
1162 case LFUN_DROP_LAYOUTS_CHOICE:
1163 owner->getToolbar()->combox->Show();
1194 case LFUN_UNDERLINE:
1198 case LFUN_FONT_SIZE:
1199 FontSizeCB(argument);
1202 case LFUN_FONT_STATE:
1203 setMessage(CurrentState());
1206 case LFUN_UPCASE_WORD:
1207 owner->buffer()->update(-2);
1209 owner->buffer()->text->ChangeWordCase(LyXText::text_uppercase);
1210 owner->buffer()->update(1);
1214 case LFUN_LOWCASE_WORD:
1215 owner->buffer()->update(-2);
1217 owner->buffer()->text->ChangeWordCase(LyXText::text_lowercase);
1218 owner->buffer()->update(1);
1222 case LFUN_CAPITALIZE_WORD:
1223 owner->buffer()->update(-2);
1225 owner->buffer()->text->ChangeWordCase(LyXText::text_capitalization);
1226 owner->buffer()->update(1);
1230 case LFUN_INSERT_LABEL:
1231 MenuInsertLabel(argument.c_str());
1234 case LFUN_INSERT_REF:
1238 case LFUN_REFTOGGLE:
1241 (InsetRef*)getInsetByCode(Inset::REF_CODE);
1243 if (inset->getFlag() == InsetRef::REF)
1244 inset->setFlag(InsetRef::PAGE_REF);
1246 inset->setFlag(InsetRef::REF);
1249 setErrorMessage(N_("No cross-reference to toggle"));
1256 owner->currentView()->restorePosition();
1262 string label(argument);
1263 if (label.empty()) {
1265 (InsetRef*)getInsetByCode(Inset::REF_CODE);
1267 label = inset->getContents();
1270 if (!label.empty()) {
1271 owner->currentView()->savePosition();
1272 owner->buffer()->gotoLabel(label.c_str());
1277 case LFUN_MENU_OPEN_BY_NAME:
1278 owner->getMenus()->openByName(argument);
1279 break; // RVDK_PATCH_5
1281 case LFUN_SPELLCHECK:
1282 if (lyxrc->isp_command != "none")
1284 break; // RVDK_PATCH_5
1286 // --- Cursor Movements -----------------------------
1289 Buffer *tmpbuffer = owner->buffer();
1290 LyXText *tmptext = owner->buffer()->text;
1291 if(!tmptext->mark_set)
1293 tmpbuffer->update(-2);
1294 if (tmptext->cursor.pos < tmptext->cursor.par->Last()
1295 && tmptext->cursor.par->GetChar(tmptext->cursor.pos)
1296 == LyXParagraph::META_INSET
1297 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)
1298 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)->Editable() == 2){
1299 Inset* tmpinset = tmptext->cursor.par->GetInset(tmptext->cursor.pos);
1300 setMessage(tmpinset->EditMessage());
1301 tmpinset->Edit(0, 0);
1304 tmptext->CursorRight();
1305 owner->buffer()->text->FinishUndo();
1306 moveCursorUpdate(false);
1307 owner->getMiniBuffer()->Set(CurrentState());
1313 // This is soooo ugly. Isn`t it possible to make
1314 // it simpler? (Lgb)
1315 LyXText *txt= owner->buffer()->text;
1316 if(!txt->mark_set) BeforeChange();
1317 owner->buffer()->update(-2);
1319 if (txt->cursor.pos < txt->cursor.par->Last()
1320 && txt->cursor.par->GetChar(txt->cursor.pos)
1321 == LyXParagraph::META_INSET
1322 && txt->cursor.par->GetInset(txt->cursor.pos)
1323 && txt->cursor.par->GetInset(txt->cursor.pos)->Editable() == 2) {
1324 Inset* tmpinset = txt->cursor.par->GetInset(txt->cursor.pos);
1325 setMessage(tmpinset->EditMessage());
1326 tmpinset->Edit(tmpinset->Width(txt->GetFont(txt->cursor.par,
1327 txt->cursor.pos)), 0);
1328 // tmpinset->Edit(-1, 0); // -1 means go rightmost
1331 owner->buffer()->text->FinishUndo();
1332 moveCursorUpdate(false);
1333 owner->getMiniBuffer()->Set(CurrentState());
1338 if(!owner->buffer()->text->mark_set) BeforeChange();
1339 owner->buffer()->update(-3);
1340 owner->buffer()->text->CursorUp();
1341 owner->buffer()->text->FinishUndo();
1342 moveCursorUpdate(false);
1343 owner->getMiniBuffer()->Set(CurrentState());
1347 if(!owner->buffer()->text->mark_set)
1349 owner->buffer()->update(-3);
1350 owner->buffer()->text->CursorDown();
1351 owner->buffer()->text->FinishUndo();
1352 moveCursorUpdate(false);
1353 owner->getMiniBuffer()->Set(CurrentState());
1356 case LFUN_UP_PARAGRAPH:
1357 if(!owner->buffer()->text->mark_set)
1359 owner->buffer()->update(-3);
1360 owner->buffer()->text->CursorUpParagraph();
1361 owner->buffer()->text->FinishUndo();
1362 moveCursorUpdate(false);
1363 owner->getMiniBuffer()->Set(CurrentState());
1366 case LFUN_DOWN_PARAGRAPH:
1367 if(!owner->buffer()->text->mark_set)
1369 owner->buffer()->update(-3);
1370 owner->buffer()->text->CursorDownParagraph();
1371 owner->buffer()->text->FinishUndo();
1372 moveCursorUpdate(false);
1373 owner->getMiniBuffer()->Set(CurrentState());
1377 if(!owner->buffer()->text->mark_set)
1379 owner->buffer()->update(-3);
1380 owner->currentView()->cursorPrevious();
1381 owner->buffer()->text->FinishUndo();
1382 moveCursorUpdate(false);
1383 owner->getMiniBuffer()->Set(CurrentState());
1387 if(!owner->buffer()->text->mark_set)
1389 owner->buffer()->update(-3);
1390 owner->currentView()->cursorNext();
1391 owner->buffer()->text->FinishUndo();
1392 moveCursorUpdate(false);
1393 owner->getMiniBuffer()->Set(CurrentState());
1397 if(!owner->buffer()->text->mark_set)
1399 owner->buffer()->update(-2);
1400 owner->buffer()->text->CursorHome();
1401 owner->buffer()->text->FinishUndo();
1402 moveCursorUpdate(false);
1403 owner->getMiniBuffer()->Set(CurrentState());
1407 if(!owner->buffer()->text->mark_set)
1409 owner->buffer()->update(-2);
1410 owner->buffer()->text->CursorEnd();
1411 owner->buffer()->text->FinishUndo();
1412 moveCursorUpdate(false);
1413 owner->getMiniBuffer()->Set(CurrentState());
1417 if(!owner->buffer()->text->mark_set)
1419 owner->buffer()->update(-2);
1420 owner->buffer()->text->CursorTab();
1421 owner->buffer()->text->FinishUndo();
1422 moveCursorUpdate(false);
1423 owner->getMiniBuffer()->Set(CurrentState());
1426 case LFUN_WORDRIGHT:
1427 if(!owner->buffer()->text->mark_set)
1429 owner->buffer()->update(-2);
1430 owner->buffer()->text->CursorRightOneWord();
1431 owner->buffer()->text->FinishUndo();
1432 moveCursorUpdate(false);
1433 owner->getMiniBuffer()->Set(CurrentState());
1437 if(!owner->buffer()->text->mark_set)
1439 owner->buffer()->update(-2);
1440 owner->buffer()->text->CursorLeftOneWord();
1441 owner->buffer()->text->FinishUndo();
1442 moveCursorUpdate(false);
1443 owner->getMiniBuffer()->Set(CurrentState());
1446 case LFUN_BEGINNINGBUF:
1447 if(!owner->buffer()->text->mark_set)
1449 owner->buffer()->update(-2);
1450 owner->buffer()->text->CursorTop();
1451 owner->buffer()->text->FinishUndo();
1452 moveCursorUpdate(false);
1453 owner->getMiniBuffer()->Set(CurrentState());
1457 if(!owner->buffer()->text->mark_set)
1459 owner->buffer()->update(-2);
1460 owner->buffer()->text->CursorBottom();
1461 owner->buffer()->text->FinishUndo();
1462 moveCursorUpdate(false);
1463 owner->getMiniBuffer()->Set(CurrentState());
1467 /* cursor selection ---------------------------- */
1469 owner->buffer()->update(-2);
1470 owner->buffer()->text->CursorRight();
1471 owner->buffer()->text->FinishUndo();
1472 moveCursorUpdate(true);
1473 owner->getMiniBuffer()->Set(CurrentState());
1477 owner->buffer()->update(-2);
1478 owner->buffer()->text->CursorLeft();
1479 owner->buffer()->text->FinishUndo();
1480 moveCursorUpdate(true);
1481 owner->getMiniBuffer()->Set(CurrentState());
1485 owner->buffer()->update(-2);
1486 owner->buffer()->text->CursorUp();
1487 owner->buffer()->text->FinishUndo();
1488 moveCursorUpdate(true);
1489 owner->getMiniBuffer()->Set(CurrentState());
1493 owner->buffer()->update(-2);
1494 owner->buffer()->text->CursorDown();
1495 owner->buffer()->text->FinishUndo();
1496 moveCursorUpdate(true);
1497 owner->getMiniBuffer()->Set(CurrentState());
1500 case LFUN_UP_PARAGRAPHSEL:
1501 owner->buffer()->update(-2);
1502 owner->buffer()->text->CursorUpParagraph();
1503 owner->buffer()->text->FinishUndo();
1504 moveCursorUpdate(true);
1505 owner->getMiniBuffer()->Set(CurrentState());
1508 case LFUN_DOWN_PARAGRAPHSEL:
1509 owner->buffer()->update(-2);
1510 owner->buffer()->text->CursorDownParagraph();
1511 owner->buffer()->text->FinishUndo();
1512 moveCursorUpdate(true);
1513 owner->getMiniBuffer()->Set(CurrentState());
1517 owner->buffer()->update(-2);
1518 owner->currentView()->cursorPrevious();
1519 owner->buffer()->text->FinishUndo();
1520 moveCursorUpdate(true);
1521 owner->getMiniBuffer()->Set(CurrentState());
1525 owner->buffer()->update(-2);
1526 owner->currentView()->cursorNext();
1527 owner->buffer()->text->FinishUndo();
1528 moveCursorUpdate(true);
1529 owner->getMiniBuffer()->Set(CurrentState());
1533 owner->buffer()->update(-2);
1534 owner->buffer()->text->CursorHome();
1535 owner->buffer()->text->FinishUndo();
1536 moveCursorUpdate(true);
1537 owner->getMiniBuffer()->Set(CurrentState());
1541 owner->buffer()->update(-2);
1542 owner->buffer()->text->CursorEnd();
1543 owner->buffer()->text->FinishUndo();
1544 moveCursorUpdate(true);
1545 owner->getMiniBuffer()->Set(CurrentState());
1548 case LFUN_WORDRIGHTSEL:
1549 owner->buffer()->update(-2);
1550 owner->buffer()->text->CursorRightOneWord();
1551 owner->buffer()->text->FinishUndo();
1552 moveCursorUpdate(true);
1553 owner->getMiniBuffer()->Set(CurrentState());
1556 case LFUN_WORDLEFTSEL:
1557 owner->buffer()->update(-2);
1558 owner->buffer()->text->CursorLeftOneWord();
1559 owner->buffer()->text->FinishUndo();
1560 moveCursorUpdate(true);
1561 owner->getMiniBuffer()->Set(CurrentState());
1564 case LFUN_BEGINNINGBUFSEL:
1565 owner->buffer()->update(-2);
1566 owner->buffer()->text->CursorTop();
1567 owner->buffer()->text->FinishUndo();
1568 moveCursorUpdate(true);
1569 owner->getMiniBuffer()->Set(CurrentState());
1572 case LFUN_ENDBUFSEL:
1573 owner->buffer()->update(-2);
1574 owner->buffer()->text->CursorBottom();
1575 owner->buffer()->text->FinishUndo();
1576 moveCursorUpdate(true);
1577 owner->getMiniBuffer()->Set(CurrentState());
1580 // --- text changing commands ------------------------
1581 case LFUN_BREAKLINE:
1583 owner->buffer()->text->InsertChar(LyXParagraph::META_NEWLINE);
1585 SetUpdateTimer(0.01);
1586 moveCursorUpdate(false);
1589 case LFUN_PROTECTEDSPACE:
1591 owner->buffer()->text->
1592 InsertChar(LyXParagraph::META_PROTECTED_SEPARATOR);
1595 moveCursorUpdate(false);
1599 if(owner->buffer()->text->mark_set) {
1601 owner->buffer()->update(0);
1602 setMessage(N_("Mark removed"));
1605 owner->buffer()->text->mark_set = 1;
1606 owner->buffer()->update(0);
1607 setMessage(N_("Mark set"));
1609 owner->buffer()->text->sel_cursor =
1610 owner->buffer()->text->cursor;
1615 if (!owner->buffer()->text->selection) {
1616 owner->buffer()->text->Delete();
1617 owner->buffer()->text->sel_cursor =
1618 owner->buffer()->text->cursor;
1620 // It is possible to make it a lot faster still
1621 // just comment out the lone below...
1622 owner->currentView()->getScreen()->ShowCursor();
1629 case LFUN_DELETE_SKIP:
1631 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1633 LyXCursor cursor = owner->buffer()->text->cursor;
1636 if (!owner->buffer()->text->selection) {
1637 if (cursor.pos == cursor.par->Last()) {
1638 owner->buffer()->text->CursorRight();
1639 cursor = owner->buffer()->text->cursor;
1641 && !(cursor.par->added_space_top
1642 == VSpace (VSpace::NONE))) {
1643 owner->buffer()->text->SetParagraph
1644 (cursor.par->line_top,
1645 cursor.par->line_bottom,
1646 cursor.par->pagebreak_top,
1647 cursor.par->pagebreak_bottom,
1648 VSpace(VSpace::NONE),
1649 cursor.par->added_space_bottom,
1651 cursor.par->labelwidthstring, 0);
1652 owner->buffer()->text->CursorLeft();
1653 owner->buffer()->update (1);
1655 owner->buffer()->text->CursorLeft();
1656 owner->buffer()->text->Delete();
1657 owner->buffer()->text->sel_cursor =
1658 owner->buffer()->text->cursor;
1662 owner->buffer()->text->Delete();
1663 owner->buffer()->text->sel_cursor =
1664 owner->buffer()->text->cursor;
1674 /* -------> Delete word forward. */
1675 case LFUN_DELETE_WORD_FORWARD:
1676 owner->buffer()->update(-2);
1678 owner->buffer()->text->DeleteWordForward();
1679 owner->buffer()->update( 1 );
1681 moveCursorUpdate(false);
1684 /* -------> Delete word backward. */
1685 case LFUN_DELETE_WORD_BACKWARD:
1686 owner->buffer()->update(-2);
1688 owner->buffer()->text->DeleteWordBackward();
1689 owner->buffer()->update( 1 );
1691 moveCursorUpdate(false);
1694 /* -------> Kill to end of line. */
1695 case LFUN_DELETE_LINE_FORWARD:
1697 owner->buffer()->update(-2);
1698 owner->buffer()->text->DeleteLineForward();
1699 owner->buffer()->update( 1 );
1701 moveCursorUpdate(false);
1704 /* -------> Set mark off. */
1707 owner->buffer()->update(0);
1708 owner->buffer()->text->sel_cursor =
1709 owner->buffer()->text->cursor;
1710 setMessage(N_("Mark off"));
1713 /* -------> Set mark on. */
1716 owner->buffer()->text->mark_set = 1;
1717 owner->buffer()->update( 0 );
1718 owner->buffer()->text->sel_cursor =
1719 owner->buffer()->text->cursor;
1720 setMessage(N_("Mark on"));
1723 case LFUN_BACKSPACE:
1726 if (!owner->buffer()->text->selection) {
1727 if (owner->getIntl()->getTrans()->backspace()) {
1728 owner->buffer()->text->Backspace();
1729 owner->buffer()->text->sel_cursor =
1730 owner->buffer()->text->cursor;
1732 // It is possible to make it a lot faster still
1733 // just comment out the lone below...
1734 owner->currentView()->getScreen()->ShowCursor();
1743 case LFUN_BACKSPACE_SKIP:
1745 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1747 LyXCursor cursor = owner->buffer()->text->cursor;
1750 if (!owner->buffer()->text->selection) {
1752 && !(cursor.par->added_space_top
1753 == VSpace (VSpace::NONE))) {
1754 owner->buffer()->text->SetParagraph
1755 (cursor.par->line_top,
1756 cursor.par->line_bottom,
1757 cursor.par->pagebreak_top,
1758 cursor.par->pagebreak_bottom,
1759 VSpace(VSpace::NONE), cursor.par->added_space_bottom,
1761 cursor.par->labelwidthstring, 0);
1762 owner->buffer()->update (1);
1764 owner->buffer()->text->Backspace();
1765 owner->buffer()->text->sel_cursor
1775 case LFUN_BREAKPARAGRAPH:
1778 owner->buffer()->text->BreakParagraph(0);
1780 SetUpdateTimer(0.01);
1781 owner->buffer()->text->sel_cursor =
1782 owner->buffer()->text->cursor;
1786 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1789 owner->buffer()->text->BreakParagraph(1);
1791 SetUpdateTimer(0.01);
1792 owner->buffer()->text->sel_cursor =
1793 owner->buffer()->text->cursor;
1797 case LFUN_BREAKPARAGRAPH_SKIP:
1799 // When at the beginning of a paragraph, remove
1800 // indentation and add a "defskip" at the top.
1801 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
1803 LyXCursor cursor = owner->buffer()->text->cursor;
1806 if (cursor.pos == 0) {
1807 if (cursor.par->added_space_top == VSpace(VSpace::NONE)) {
1808 owner->buffer()->text->SetParagraph
1809 (cursor.par->line_top,
1810 cursor.par->line_bottom,
1811 cursor.par->pagebreak_top,
1812 cursor.par->pagebreak_bottom,
1813 VSpace(VSpace::DEFSKIP), cursor.par->added_space_bottom,
1815 cursor.par->labelwidthstring, 1);
1816 owner->buffer()->update(1);
1820 owner->buffer()->text->BreakParagraph(0);
1823 SetUpdateTimer(0.01);
1824 owner->buffer()->text->sel_cursor = cursor;
1830 owner->buffer()->text->InsertChar('\"'); // This " matches the single quote in the code
1833 moveCursorUpdate(false);
1839 InsetCommand *new_inset;
1840 if (action == LFUN_HTMLURL)
1841 new_inset = new InsetUrl("htmlurl", "", "");
1843 new_inset = new InsetUrl("url", "", "");
1844 owner->buffer()->insertInset(new_inset);
1845 new_inset->Edit(0, 0);
1849 // --- lyxserver commands ----------------------------
1851 case LFUN_CHARATCURSOR:
1853 LyXParagraph::size_type pos =
1854 owner->buffer()->text->cursor.pos;
1855 if(pos < owner->buffer()->text->cursor.par->size())
1856 dispatch_buffer = owner->buffer()->text->
1857 cursor.par->text[pos];
1859 dispatch_buffer = "EOF";
1865 tostr(owner->buffer()->text->cursor.x) + ' '
1866 + tostr(owner->buffer()->text->cursor.y);
1873 sscanf(argument.c_str(), " %d %ld", &x, &y);
1874 owner->buffer()->text->SetCursorFromCoordinates(x, y);
1878 case LFUN_GETLAYOUT:
1880 tostr(owner->buffer()->text->cursor.par->layout);
1885 LyXFont *font = &(owner->buffer()->text->current_font);
1886 if(font->shape() == LyXFont::ITALIC_SHAPE)
1887 dispatch_buffer = 'E';
1888 else if(font->shape() == LyXFont::SMALLCAPS_SHAPE)
1889 dispatch_buffer = 'N';
1891 dispatch_buffer = '0';
1898 LyXFont *font = &(owner->buffer()->text->current_font);
1899 if(font->latex() == LyXFont::ON)
1900 dispatch_buffer = 'L';
1902 dispatch_buffer = '0';
1907 setMessage(owner->buffer()->getFileName());
1908 lyxerr.debug() << "FNAME["
1909 << owner->buffer()->getFileName()
1916 keyseq.print(buf, 100);
1917 dispatch_buffer = buf;
1918 lyxserver->notifyClient(dispatch_buffer);
1922 case LFUN_GOTOFILEROW:
1924 char file_name[100];
1926 sscanf(argument.c_str(), " %s %d", file_name, &row);
1928 // Must replace extension of the file to be .lyx and get full path
1929 string s = ChangeExtension(string(file_name), ".lyx", false);
1931 // Either change buffer or load the file
1932 if (bufferlist.exists(s))
1933 owner->currentView()->buffer(bufferlist.getBuffer(s));
1935 owner->currentView()->buffer(bufferlist.loadLyXFile(s));
1938 owner->buffer()->setCursorFromRow(row);
1942 if (owner->buffer()->text->cursor.y >
1943 owner->currentView()->getWorkArea()->h / 2) {
1944 owner->currentView()->getScreen()->
1945 Draw(owner->buffer()->text->cursor.y -
1946 owner->currentView()->getWorkArea()->h/2);
1948 owner->currentView()->getScreen()->
1951 owner->buffer()->update(0);
1952 owner->currentView()->redraw();
1959 int qa = lyxaction.LookupFunc(argument.c_str());
1960 setMessage(lyxaction.helpText((kb_action)qa));
1964 // --- accented characters ---------------------------
1967 case LFUN_CIRCUMFLEX:
1977 case LFUN_SPECIAL_CARON:
1980 case LFUN_HUNG_UMLAUT:
1986 if (keyseq.length == -1 && keyseq.getiso()!= 0)
1991 owner->getIntl()->getTrans()->
1992 deadkey(c, get_accent(action).accent,
1993 owner->buffer()->text);
1995 // Need to reset, in case the minibuffer calls these
2000 // copied verbatim from do_accent_char
2003 owner->buffer()->text->sel_cursor =
2004 owner->buffer()->text->cursor;
2008 // --- toolbar ----------------------------------
2009 case LFUN_PUSH_TOOLBAR:
2011 int nth = strToInt(argument);
2012 if (lyxerr.debugging(Debug::TOOLBAR)) {
2013 lyxerr << "LFUN_PUSH_TOOLBAR: argument = `"
2014 << argument << "'\n"
2015 << "LFUN_PUSH_TOOLBAR: nth = `"
2016 << nth << "'" << endl;
2021 setErrorMessage(N_("Push-toolbar needs argument > 0"));
2023 owner->getToolbar()->push(nth);
2028 case LFUN_ADD_TO_TOOLBAR:
2030 if (lyxerr.debugging(Debug::TOOLBAR)) {
2031 lyxerr << "LFUN_ADD_TO_TOOLBAR:"
2032 "argument = `" << argument << '\'' << endl;
2034 string tmp(argument);
2035 //lyxerr <<string("Argument: ") + argument);
2036 //lyxerr <<string("Tmp : ") + tmp);
2039 setErrorMessage(N_("Usage: toolbar-add-to <LyX command>"));
2041 owner->getToolbar()->add(argument, false);
2042 owner->getToolbar()->set();
2047 // --- insert characters ----------------------------------------
2049 case LFUN_INSERT_INSET_LATEX:
2051 Inset *new_inset = new InsetLatex(argument);
2052 owner->buffer()->insertInset(new_inset);
2056 // --- Mathed stuff. If we are here, there is no locked inset yet.
2061 if (!greek_kb_flag) {
2063 setMessage(N_("Math greek mode on"));
2070 case LFUN_GREEK_TOGGLE:
2072 greek_kb_flag = (greek_kb_flag) ? 0: 2;
2073 if (greek_kb_flag) {
2074 setMessage(N_("Math greek keyboard on"));
2076 setMessage(N_("Math greek keyboard off"));
2081 case LFUN_MATH_DELIM:
2082 case LFUN_INSERT_MATRIX:
2084 if (owner->currentView()->available()) {
2086 open_new_inset(new InsetFormula(false));
2088 the_locking_inset->LocalDispatch(action, argument.c_str());
2093 case LFUN_INSERT_MATH:
2095 math_insert_symbol(argument.c_str());
2099 case LFUN_MATH_DISPLAY:
2101 if (owner->currentView()->available())
2102 owner->buffer()->open_new_inset(new InsetFormula(true));
2106 case LFUN_MATH_MACRO:
2108 if (owner->currentView()->available()) {
2111 setErrorMessage(N_("Missing argument"));
2113 string s1 = token(s, ' ', 1);
2114 int na = s1.empty() ? 0: atoi(s1.c_str());
2116 open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2122 case LFUN_MATH_MODE: // Open or create a math inset
2125 if (owner->currentView()->available())
2126 owner->buffer()->open_new_inset(new InsetFormula);
2127 setMessage(N_("Math editor mode"));
2131 case LFUN_MATH_NUMBER:
2132 case LFUN_MATH_LIMITS:
2134 setErrorMessage(N_("This is only allowed in math mode!"));
2138 case LFUN_INSERT_CITATION:
2140 InsetCitation * new_inset = new InsetCitation();
2142 // The note, if any, must be after the key, delimited
2143 // by a | so both key and remark can have spaces.
2144 if (!argument.empty()) {
2145 string lsarg(argument);
2146 if (contains(lsarg, "|")) {
2147 new_inset->setContents(token(lsarg, '|', 0));
2148 new_inset->setOptions(token(lsarg, '|', 1));
2150 new_inset->setContents(lsarg);
2151 owner->buffer()->insertInset(new_inset);
2153 owner->buffer()->insertInset(new_inset);
2154 new_inset->Edit(0, 0);
2159 case LFUN_INSERT_BIBTEX:
2161 // ale970405+lasgoutt970425
2162 // The argument can be up to two tokens separated
2163 // by a space. The first one is the bibstyle.
2164 string lsarg(argument);
2165 string bibstyle = token(lsarg, ' ', 1);
2166 if (bibstyle.empty())
2168 InsetBibtex * new_inset
2169 = new InsetBibtex(token(lsarg, ' ', 0),
2173 owner->buffer()->insertInset(new_inset);
2174 if (lsarg.empty()) {
2175 new_inset->Edit(0, 0);
2180 // BibTeX data bases
2181 case LFUN_BIBDB_ADD:
2183 InsetBibtex * inset =
2184 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2186 inset->addDatabase(argument);
2191 case LFUN_BIBDB_DEL:
2193 InsetBibtex * inset =
2194 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2196 inset->delDatabase(argument);
2201 case LFUN_BIBTEX_STYLE:
2203 InsetBibtex * inset =
2204 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2206 inset->setOptions(argument);
2211 case LFUN_INDEX_INSERT:
2212 case LFUN_INDEX_INSERT_LAST:
2214 InsetIndex * new_inset = new InsetIndex();
2215 if (!argument.empty()) {
2216 string lsarg(argument);
2217 new_inset->setContents(lsarg);
2218 owner->buffer()->insertInset(new_inset);
2221 //get the current word for an argument
2226 LyXParagraph::size_type lastpos =
2227 owner->buffer()->text->cursor.pos - 1;
2228 // If this can't happen, let's make sure that it really don't
2229 Assert(owner->buffer()->text->cursor.pos - 1 >= 0);
2230 // get the current word
2231 // note that this must be done before
2232 // inserting the inset, or the inset will break
2234 string curstring(owner->buffer()
2235 ->text->cursor.par->GetWord(lastpos));
2237 //make the new inset and write the current word into it
2238 InsetIndex * new_inset = new InsetIndex();
2240 new_inset->setContents(curstring);
2242 //don't edit it if the call was to INSERT_LAST
2243 if(action!= LFUN_INDEX_INSERT_LAST) {
2244 new_inset->Edit(0, 0);
2246 //it looks blank on the screen unless
2247 //we do something. put it here.
2249 // move the cursor to the returned value of lastpos
2250 // but only for the auto-insert
2251 owner->buffer()->text->cursor.pos= lastpos;
2254 //put the new inset into the buffer.
2255 // there should be some way of knowing the user
2256 //cancelled & avoiding this, but i don't know how
2257 owner->buffer()->insertInset(new_inset);
2262 case LFUN_INDEX_PRINT:
2264 Inset * new_inset = new InsetPrintIndex(owner->buffer());
2265 owner->buffer()->insertInset(new_inset, "Standard", true);
2269 case LFUN_PARENTINSERT:
2271 lyxerr << "arg " << argument << endl;
2272 Inset * new_inset = new InsetParent(argument, owner->buffer());
2273 owner->buffer()->insertInset(new_inset, "Standard", true);
2277 case LFUN_CHILDINSERT:
2279 Inset * new_inset = new InsetInclude(argument,
2281 owner->buffer()->insertInset(new_inset, "Standard", true);
2282 new_inset->Edit(0, 0);
2286 case LFUN_CHILDOPEN:
2289 MakeAbsPath(argument,
2290 OnlyPath(owner->buffer()->getFileName()));
2291 setMessage(N_("Opening child document ") +
2292 MakeDisplayPath(filename) + "...");
2293 owner->currentView()->savePosition();
2294 if (bufferlist.exists(filename))
2295 owner->currentView()->buffer(bufferlist.getBuffer(filename));
2297 owner->currentView()->buffer(bufferlist.loadLyXFile(filename));
2301 case LFUN_INSERT_NOTE:
2305 case LFUN_INSERTFOOTNOTE:
2307 LyXParagraph::footnote_kind kind;
2308 if (argument == "footnote")
2309 { kind = LyXParagraph::FOOTNOTE; }
2310 else if (argument == "margin")
2311 { kind = LyXParagraph::MARGIN; }
2312 else if (argument == "figure")
2313 { kind = LyXParagraph::FIG; }
2314 else if (argument == "table")
2315 { kind = LyXParagraph::TAB; }
2316 else if (argument == "wide-fig")
2317 { kind = LyXParagraph::WIDE_FIG; }
2318 else if (argument == "wide-tab")
2319 { kind = LyXParagraph::WIDE_TAB; }
2320 else if (argument == "algorithm")
2321 { kind = LyXParagraph::ALGORITHM; }
2323 setErrorMessage(N_("Unknown kind of footnote"));
2326 owner->buffer()->text->InsertFootnoteEnvironment(kind);
2327 owner->buffer()->update(1);
2331 case LFUN_BUFFERBULLETSSELECT:
2335 case LFUN_TOGGLECURSORFOLLOW:
2336 cursor_follows_scrollbar = !cursor_follows_scrollbar;
2339 case LFUN_KMAP_OFF: // keymap off
2340 owner->getIntl()->KeyMapOn(false);
2343 case LFUN_KMAP_PRIM: // primary keymap
2344 owner->getIntl()->KeyMapPrim();
2347 case LFUN_KMAP_SEC: // secondary keymap
2348 owner->getIntl()->KeyMapSec();
2351 case LFUN_KMAP_TOGGLE: // toggle keymap
2352 owner->getIntl()->ToggleKeyMap();
2355 case LFUN_SELFINSERT:
2357 for (string::size_type i = 0; i < argument.length(); ++i) {
2358 owner->buffer()->text->InsertChar(argument[i]);
2359 // This needs to be in the loop, or else we
2360 // won't break lines correctly. (Asger)
2364 owner->buffer()->text->sel_cursor =
2365 owner->buffer()->text->cursor;
2366 moveCursorUpdate(false);
2372 // argument contains ';'-terminated commands
2373 while (argument.find(';') != string::npos) {
2375 argument = split(argument, first, ';');
2381 case LFUN_UNKNOWN_ACTION:
2383 if (owner->buffer()->isReadonly()) {
2385 setErrorMessage(N_("Document is read only"));
2389 if (!argument.empty()) {
2391 /* Automatically delete the currently selected
2392 * text and replace it with what is being
2393 * typed in now. Depends on lyxrc settings
2394 * "auto_region_delete", which defaults to
2397 if ( lyxrc->auto_region_delete ) {
2398 if (owner->buffer()->text->selection){
2399 owner->buffer()->text->CutSelection(false);
2400 owner->buffer()->update(-1);
2405 for (string::size_type i = 0;
2406 i < argument.length(); ++i) {
2407 if (greek_kb_flag) {
2408 if (!math_insert_greek(argument[i]))
2409 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->buffer()->text);
2411 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->buffer()->text);
2417 owner->buffer()->text->sel_cursor =
2418 owner->buffer()->text->cursor;
2419 moveCursorUpdate(false);
2422 // why is an "Unknown action" with empty
2423 // argument even dispatched in the first
2424 // place? I`ll probably change that. (Lgb)
2426 setErrorMessage(N_("Unknown action"));
2430 lyxerr << "A truly unknown func!" << endl;
2436 string res= getMessage();
2439 if (!commandshortcut.empty()) {
2440 string newbuf = owner->getMiniBuffer()->GetText();
2441 if (newbuf != commandshortcut) {
2442 owner->getMiniBuffer()->Set(newbuf
2448 owner->getMiniBuffer()->Set(string(_(res.c_str()))
2449 + " " + commandshortcut);
2452 return getMessage();
2456 void LyXFunc::setupLocalKeymap()
2458 keyseq.stdmap = keyseq.curmap = toplevel_keymap;
2459 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap;
2463 void LyXFunc::MenuNew(bool fromTemplate)
2465 string fname, initpath = lyxrc->document_path;
2468 if (owner->currentView()->available()) {
2469 string trypath = owner->buffer()->filepath;
2470 // If directory is writeable, use this as default.
2471 if (IsDirWriteable(trypath) == 1)
2476 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2477 fileDlg.SetButton(1, _("Templates"), lyxrc->template_path);
2478 fname = fileDlg.Select(_("Enter Filename for new document"),
2479 initpath, "*.lyx", _("newfile"));
2482 if (fname.empty()) {
2483 owner->getMiniBuffer()->Set(_("Canceled."));
2484 lyxerr.debug() << "New Document Cancelled." << endl;
2488 // get absolute path of file and make sure the filename ends
2490 string s = MakeAbsPath(fname);
2491 if (!IsLyXFilename(s))
2494 // Check if the document already is open
2495 if (bufferlist.exists(s)){
2496 switch(AskConfirmation(_("Document is already open:"),
2497 MakeDisplayPath(s, 50),
2498 _("Do you want to close that document now?\n"
2499 "('No' will just switch to the open version)")))
2501 case 1: // Yes: close the document
2502 if (!bufferlist.close(bufferlist.getBuffer(s)))
2503 // If close is canceled, we cancel here too.
2506 case 2: // No: switch to the open document
2507 owner->currentView()->buffer(bufferlist.getBuffer(s));
2509 case 3: // Cancel: Do nothing
2510 owner->getMiniBuffer()->Set(_("Canceled."));
2515 // Check whether the file already exists
2516 if (IsLyXFilename(s)) {
2517 FilePtr myfile(s, FilePtr::read);
2519 AskQuestion(_("File already exists:"),
2520 MakeDisplayPath(s, 50),
2521 _("Do you want to open the document?"))) {
2523 owner->getMiniBuffer()->Set(_("Opening document"),
2524 MakeDisplayPath(s), "...");
2526 owner->currentView()->buffer(
2527 bufferlist.loadLyXFile(s));
2528 owner->getMiniBuffer()->Set(_("Document"),
2535 // The template stuff
2539 fname = fileDlg.Select(_("Choose template"),
2540 lyxrc->template_path,
2546 // find a free buffer
2547 lyxerr.debug() << "Find a free buffer." << endl;
2548 owner->currentView()->buffer(bufferlist.newFile(s, templname));
2552 void LyXFunc::MenuOpen()
2554 string initpath = lyxrc->document_path;
2557 if (owner->currentView()->available()) {
2558 string trypath = owner->buffer()->filepath;
2559 // If directory is writeable, use this as default.
2560 if (IsDirWriteable(trypath) == 1)
2566 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2567 fileDlg.SetButton(1, _("Examples"),
2568 AddPath(system_lyxdir, "examples"));
2569 string filename = fileDlg.Select(_("Select Document to Open"),
2573 // check selected filename
2574 if (filename.empty()) {
2575 owner->getMiniBuffer()->Set(_("Canceled."));
2579 // get absolute path of file and make sure the filename ends
2581 filename = MakeAbsPath(filename);
2582 if (!IsLyXFilename(filename))
2586 owner->getMiniBuffer()->Set(_("Opening document"),
2587 MakeDisplayPath(filename), "...");
2588 Buffer * openbuf = bufferlist.loadLyXFile(filename);
2590 owner->currentView()->buffer(openbuf);
2591 owner->getMiniBuffer()->Set(_("Document"),
2592 MakeDisplayPath(filename),
2595 owner->getMiniBuffer()->Set(_("Could not open document"),
2596 MakeDisplayPath(filename));
2601 void LyXFunc::doImportASCII(bool linorpar)
2603 string initpath = lyxrc->document_path;
2606 if (owner->currentView()->available()) {
2607 string trypath = owner->buffer()->filepath;
2608 // If directory is writeable, use this as default.
2609 if (IsDirWriteable(trypath) == 1)
2615 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2616 fileDlg.SetButton(1, _("Examples"),
2617 AddPath(system_lyxdir, "examples"));
2618 string filename = fileDlg.Select(_("Select ASCII file to Import"),
2622 // check selected filename
2623 if (filename.empty()) {
2624 owner->getMiniBuffer()->Set(_("Canceled."));
2628 // get absolute path of file
2629 filename = MakeAbsPath(filename);
2631 string s = ChangeExtension(filename, ".lyx", false);
2633 // Check if the document already is open
2634 if (bufferlist.exists(s)){
2635 switch(AskConfirmation(_("Document is already open:"),
2636 MakeDisplayPath(s, 50),
2637 _("Do you want to close that document now?\n"
2638 "('No' will just switch to the open version)")))
2640 case 1: // Yes: close the document
2641 if (!bufferlist.close(bufferlist.getBuffer(s)))
2642 // If close is canceled, we cancel here too.
2645 case 2: // No: switch to the open document
2646 owner->currentView()->buffer(bufferlist.getBuffer(s));
2648 case 3: // Cancel: Do nothing
2649 owner->getMiniBuffer()->Set(_("Canceled."));
2654 // Check if a LyX document by the same root exists in filesystem
2655 FileInfo f(s, true);
2656 if (f.exist() && !AskQuestion(_("A document by the name"),
2658 _("already exists. Overwrite?"))) {
2659 owner->getMiniBuffer()->Set(_("Canceled."));
2663 owner->currentView()->buffer(bufferlist.newFile(s, string()));
2664 owner->getMiniBuffer()->Set(_("Importing ASCII file"),
2665 MakeDisplayPath(filename), "...");
2666 // Insert ASCII file
2667 InsertAsciiFile(filename, linorpar);
2668 owner->getMiniBuffer()->Set(_("ASCII file "),
2669 MakeDisplayPath(filename),
2674 void LyXFunc::doImportLaTeX(bool isnoweb)
2676 string initpath = lyxrc->document_path;
2679 if (owner->currentView()->available()) {
2680 string trypath = owner->buffer()->filepath;
2681 // If directory is writeable, use this as default.
2682 if (IsDirWriteable(trypath) == 1)
2688 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2689 fileDlg.SetButton(1, _("Examples"),
2690 AddPath(system_lyxdir, "examples"));
2693 filename = fileDlg.Select(_("Select Noweb file to Import"),
2696 filename = fileDlg.Select(_("Select LaTeX file to Import"),
2702 // check selected filename
2703 if (filename.empty()) {
2704 owner->getMiniBuffer()->Set(_("Canceled."));
2708 // get absolute path of file
2709 filename = MakeAbsPath(filename);
2711 // Check if the document already is open
2712 string LyXfilename = ChangeExtension(filename, ".lyx", false);
2713 if (bufferlist.exists(LyXfilename)){
2714 switch(AskConfirmation(_("Document is already open:"),
2715 MakeDisplayPath(LyXfilename, 50),
2716 _("Do you want to close that document now?\n"
2717 "('No' will just switch to the open version)")))
2719 case 1: // Yes: close the document
2720 if (!bufferlist.close(bufferlist.getBuffer(LyXfilename)))
2721 // If close is canceled, we cancel here too.
2724 case 2: // No: switch to the open document
2725 owner->currentView()->buffer(
2726 bufferlist.getBuffer(LyXfilename));
2728 case 3: // Cancel: Do nothing
2729 owner->getMiniBuffer()->Set(_("Canceled."));
2734 // Check if a LyX document by the same root exists in filesystem
2735 FileInfo f(LyXfilename, true);
2736 if (f.exist() && !AskQuestion(_("A document by the name"),
2737 MakeDisplayPath(LyXfilename),
2738 _("already exists. Overwrite?"))) {
2739 owner->getMiniBuffer()->Set(_("Canceled."));
2746 owner->getMiniBuffer()->Set(_("Importing LaTeX file"),
2747 MakeDisplayPath(filename), "...");
2748 ImportLaTeX myImport(filename);
2749 openbuf = myImport.run();
2751 owner->getMiniBuffer()->Set(_("Importing Noweb file"),
2752 MakeDisplayPath(filename), "...");
2753 ImportNoweb myImport(filename);
2754 openbuf = myImport.run();
2757 owner->currentView()->buffer(openbuf);
2758 owner->getMiniBuffer()->Set(isnoweb ?
2759 _("Noweb file ") : _("LateX file "),
2760 MakeDisplayPath(filename),
2763 owner->getMiniBuffer()->Set(isnoweb ?
2764 _("Could not import Noweb file") :
2765 _("Could not import LaTeX file"),
2766 MakeDisplayPath(filename));
2771 void LyXFunc::MenuInsertLyXFile(string const & filen)
2773 string filename = filen;
2775 if (filename.empty()) {
2776 // Launch a file browser
2777 string initpath = lyxrc->document_path;
2780 if (owner->currentView()->available()) {
2781 string trypath = owner->buffer()->filepath;
2782 // If directory is writeable, use this as default.
2783 if (IsDirWriteable(trypath) == 1)
2789 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2790 fileDlg.SetButton(1, _("Examples"),
2791 AddPath(system_lyxdir, "examples"));
2792 filename = fileDlg.Select(_("Select Document to Insert"),
2796 // check selected filename
2797 if (filename.empty()) {
2798 owner->getMiniBuffer()->Set(_("Canceled."));
2803 // get absolute path of file and make sure the filename ends
2805 filename = MakeAbsPath(filename);
2806 if (!IsLyXFilename(filename))
2810 owner->getMiniBuffer()->Set(_("Inserting document"),
2811 MakeDisplayPath(filename), "...");
2812 bool res = owner->buffer()->insertLyXFile(filename);
2814 owner->getMiniBuffer()->Set(_("Document"),
2815 MakeDisplayPath(filename),
2818 owner->getMiniBuffer()->Set(_("Could not insert document"),
2819 MakeDisplayPath(filename));
2824 void LyXFunc::reloadBuffer()
2826 string fn = owner->buffer()->getFileName();
2827 if (bufferlist.close(owner->buffer()))
2828 owner->currentView()->buffer(bufferlist.loadLyXFile(fn));
2832 void LyXFunc::CloseBuffer()
2834 if (bufferlist.close(owner->buffer()) && !quitting) {
2835 if (bufferlist.empty()) {
2836 // need this otherwise SEGV may occur while trying to
2837 // set variables that don't exist
2838 // since there's no current buffer
2839 CloseAllBufferRelatedPopups();
2842 owner->currentView()->buffer(bufferlist.first());
2848 Inset * LyXFunc::getInsetByCode(Inset::Code code)
2852 LyXCursor cursor = owner->buffer()->text->cursor;
2853 LyXParagraph::size_type pos = cursor.pos;
2854 LyXParagraph * par = cursor.par;
2856 while (par && !found) {
2857 while ((inset = par->ReturnNextInsetPointer(pos))){
2858 if (inset->LyxCode() == code) {
2866 return (found) ? inset: 0;
2870 // Each "owner" should have it's own message method. lyxview and
2871 // the minibuffer would use the minibuffer, but lyxserver would
2872 // send an ERROR signal to its client. Alejandro 970603
2873 // This func is bit problematic when it comes to NLS, to make the
2874 // lyx servers client be language indepenent we must not translate
2875 // strings sent to this func.
2876 void LyXFunc::setErrorMessage(string const &m)
2878 dispatch_buffer = m;
2883 void LyXFunc::setMessage(string const & m)
2885 dispatch_buffer = m;