1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-1999 The LyX Team.
9 * ======================================================*/
18 #pragma implementation
21 #include "definitions.h"
22 #include "lyxlookup.h"
25 #include "bufferlist.h"
26 #include "lyxserver.h"
31 #include "insets/insetlatex.h"
32 #include "insets/inseturl.h"
33 #include "insets/insetlatexaccent.h"
34 #include "insets/insettoc.h"
35 #include "insets/insetlof.h"
36 #include "insets/insetloa.h"
37 #include "insets/insetlot.h"
38 #include "insets/insetref.h"
39 #include "insets/insetparent.h"
40 #include "mathed/formulamacro.h"
42 #include "spellchecker.h" // RVDK_PATCH_5
43 #include "minibuffer.h"
45 #include "insets/insetbib.h"
47 #include "insets/insetindex.h"
48 #include "insets/insetinclude.h"
50 #include "lyx_gui_misc.h"
51 #include "support/filetools.h"
52 #include "support/FileInfo.h"
53 #include "support/LAssert.h"
54 #include "lyxscreen.h"
59 #include "trans_mgr.h"
60 #include "ImportLaTeX.h"
61 #include "ImportNoweb.h"
62 #include "support/syscall.h"
63 #include "support/lstrings.h"
64 #include "support/path.h"
67 extern bool cursor_follows_scrollbar;
69 extern void InsertAsciiFile(string const &, bool);
70 extern void math_insert_symbol(char const*);
71 extern Bool math_insert_greek(char const); // why "Bool"?
72 extern BufferList bufferlist;
73 extern LyXServer * lyxserver;
74 extern short greek_kb_flag;
75 extern FD_form_toc * fd_form_toc;
76 extern bool selection_possible;
78 extern kb_keymap * toplevel_keymap;
80 extern void BeforeChange();
81 extern void MenuWrite(Buffer*);
82 extern void MenuWriteAs(Buffer*);
83 extern int MenuRunLaTeX(Buffer*);
84 extern int MenuBuildProg(Buffer*);
85 extern int MenuRunChktex(Buffer*);
86 extern bool MenuRunDvips(Buffer *,bool);
87 extern void MenuPrint(Buffer*);
88 extern void MenuSendto();
89 extern void QuitLyX();
90 extern void MenuFax(Buffer *);
91 extern void MenuMakeLaTeX(Buffer *);
92 extern void MenuMakeLinuxDoc(Buffer *);
93 extern void MenuMakeDocBook(Buffer *);
94 extern void MenuMakeAscii(Buffer *);
95 extern void MenuPasteSelection(char at);
96 extern LyXAction lyxaction;
98 extern tex_accent_struct get_accent(kb_action action);
100 extern void AutoSave();
101 extern void MenuSearch();
102 extern void CopyCB();
103 extern void CopyEnvironmentCB();
104 extern void PasteEnvironmentCB();
105 extern void GotoNote();
106 extern void NoteCB();
107 extern void OpenStuff();
108 extern void HyphenationPoint();
110 extern void EndOfSentenceDot();
111 extern void MenuSeparator();
113 extern void MenuUndo();
114 extern void MenuRedo();
115 extern void SmallUpdate(signed char);
116 extern void SetUpdateTimer(float timer= 0.3);
117 extern void FreeUpdateTimer();
118 extern bool MenuPreview(Buffer*);
119 extern bool MenuPreviewPS(Buffer*);
120 extern void MenuInsertLabel(const char *);
121 extern void MenuInsertRef();
122 extern void MenuLayoutCharacter();
123 extern void MenuLayoutParagraph();
124 extern void MenuLayoutDocument();
125 extern void MenuLayoutPaper();
126 extern void MenuLayoutTable(int flag);
127 extern void MenuLayoutQuotes();
128 extern void MenuLayoutPreamble();
129 extern void MenuLayoutSave();
130 extern void bulletForm();
132 extern Buffer * NewLyxFile(string const &);
133 extern void LoadLyXFile(string const &);
134 extern void Reconfigure();
136 extern int current_layout;
137 extern int getISOCodeFromLaTeX(char *);
139 extern int UnlockInset(UpdatableInset*);
141 extern void ShowLatexLog();
143 extern void UpdateInset(Inset* inset, bool mark_dirty = true);
145 /* === globals =========================================================== */
147 bool LyXFunc::show_sc = true;
150 LyXFunc::LyXFunc(LyXView *o)
154 lyx_dead_action = LFUN_NOACTION;
155 lyx_calling_dead_action = LFUN_NOACTION;
165 // I changed this func slightly. I commented out the ...FinishUndo(),
166 // this means that all places that used to have a moveCursorUpdate, now
167 // have a ...FinishUndo() as the preceeding statement. I have also added
168 // a moveCursorUpdate to some of the functions that updated the cursor, but
169 // that did not show its new position.
171 void LyXFunc::moveCursorUpdate(bool selecting)
173 if (selecting || owner->buffer()->text->mark_set) {
174 owner->buffer()->text->SetSelection();
175 owner->currentView()->getScreen()->ToggleToggle();
176 owner->buffer()->update(0);
178 owner->buffer()->update(-2); // this IS necessary
181 owner->currentView()->getScreen()->ShowCursor();
183 /* ---> Everytime the cursor is moved, show the current font state. */
184 // should this too me moved out of this func?
185 //owner->getMiniBuffer()->Set(CurrentState());
189 int LyXFunc::processKeyEvent(XEvent *ev)
196 XKeyEvent *keyevent = &ev->xkey;
197 KeySym keysym_return;
199 num_bytes = LyXLookupString(ev, s_r, 10, &keysym_return);
201 if (lyxerr.debugging(Debug::KEY)) {
202 lyxerr << "KeySym is "
203 << XKeysymToString(keysym_return)
205 << keysym_return << "]"
206 << " and num_bytes is "
208 << " the string returned is \""
209 << s_r << '\"' << endl;
211 // Do nothing if we have nothing (JMarc)
212 if (num_bytes == 0 && keysym_return == NoSymbol) {
213 lyxerr[Debug::KEY] << "Empty kbd action (probably composing)"
218 // this function should be used always [asierra060396]
219 if (owner->currentView()->available() &&
220 owner->buffer()->the_locking_inset &&
221 keysym_return == XK_Escape) {
222 UnlockInset(owner->buffer()->the_locking_inset);
223 owner->buffer()->text->CursorRight();
227 // Can we be sure that this will work for all X-Windows
228 // implementations? (Lgb)
229 // This code snippet makes lyx ignore some keys. Perhaps
230 // all of them should be explictly mentioned?
231 if((keysym_return >= XK_Shift_L && keysym_return <= XK_Hyper_R)
232 || keysym_return == XK_Mode_switch || keysym_return == 0x0)
235 // Do a one-deep top-level lookup for
236 // cancel and meta-fake keys. RVDK_PATCH_5
237 cancel_meta_seq.reset();
239 action = cancel_meta_seq.addkey(keysym_return, keyevent->state
240 &(ShiftMask|ControlMask
243 // When not cancel or meta-fake, do the normal lookup.
244 // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
245 // Mostly, meta_fake_bit = 0. RVDK_PATCH_5.
246 if ( (action != LFUN_CANCEL) && (action != LFUN_META_FAKE) ) {
248 // remove Caps Lock and Mod2 as a modifiers
249 action = keyseq.addkey(keysym_return,
250 (keyevent->state | meta_fake_bit)
251 &(ShiftMask|ControlMask
254 // Dont remove this unless you know what you are doing.
257 if (action == 0) action = LFUN_PREFIX;
259 if (lyxerr.debugging(Debug::KEY)) {
261 keyseq.print(buf,100);
265 << num_bytes << "]" << endl;
268 // already here we know if it any point in going further
269 // why not return already here if action == -1 and
270 // num_bytes == 0? (Lgb)
272 if(keyseq.length>1 || keyseq.length<-1){
274 keyseq.print(buf,100);
275 owner->getMiniBuffer()->Set(buf);
279 if (keyseq.length<-1) { // unknown key sequence...
282 keyseq.print(buf,100);
283 owner->getMiniBuffer()->Set(_("Unknown sequence:"),buf);
287 char isochar = keyseq.getiso();
288 if (!(keyevent->state&ControlMask) &&
289 !(keyevent->state&Mod1Mask) &&
290 (isochar && keysym_return < 0xF000)) {
293 if (argument.empty()) {
294 lyxerr.debug() << "Empty argument!" << endl;
295 // This can`t possibly be of any use
296 // so we`ll skip the dispatch.
300 if (action==LFUN_SELFINSERT) {
304 bool tmp_sc = show_sc;
306 Dispatch(action, argument.c_str());
313 string LyXFunc::Dispatch(string const &cmd, string const &arg)
315 return Dispatch(lyxaction.LookupFunc(cmd.c_str()),
320 string LyXFunc::Dispatch(int ac,
321 char const *do_not_use_this_arg)
327 FL_OBJECT *ob = 0; // This will disapear soon
329 // we have not done anything wrong yet.
331 dispatch_buffer = string();
333 // if action is a pseudo-action, we need the real action
334 if (lyxaction.isPseudoAction(ac)) {
335 char const *tmparg = 0;
336 action = (kb_action)lyxaction.retrieveActionArg(ac, &tmparg);
340 action = (kb_action)ac;
341 if (do_not_use_this_arg)
342 argument = do_not_use_this_arg; // except here
345 selection_possible = false;
347 if (owner->currentView()->available()
348 && owner->currentView()->getScreen())
349 owner->currentView()->getScreen()->HideCursor();
351 if(!owner->currentView()->available()) {
352 // This lists the allowed funcs when we have no
355 case LFUN_MENU_OPEN_BY_NAME:
358 case LFUN_MENUNEWTMPLT:
361 case LFUN_PUSH_TOOLBAR:
362 case LFUN_ADD_TO_TOOLBAR:
363 case LFUN_EXEC_COMMAND:
364 case LFUN_DROP_LAYOUTS_CHOICE:
368 case LFUN_RECONFIGURE:
374 case LFUN_UNKNOWN_ACTION:
375 setErrorMessage(N_("Unknown action"));
376 goto exit_with_message;
378 setErrorMessage(N_("Command not allowed with"
379 "out any document open"));
380 goto exit_with_message; // action not allowed
384 commandshortcut = string();
386 if (lyxrc->display_shortcuts && show_sc) {
387 if (action != LFUN_SELFINSERT) {
388 // Put name of command and list of shortcuts
389 // for it in minibuffer
390 string comname = lyxaction.getActionName(action);
392 int pseudoaction = action;
393 bool argsadded = false;
395 if (!argument.empty()) {
396 // If we have the command with argument,
399 lyxaction.searchActionArg(action,
402 if (pseudoaction == -1) {
403 pseudoaction = action;
405 comname += " " + argument;
410 string shortcuts = toplevel_keymap->findbinding(pseudoaction);
412 if (!shortcuts.empty()) {
413 comname += ": " + shortcuts;
414 } else if (!argsadded) {
415 comname += " " + argument;
418 if (!comname.empty()) {
419 comname = strip(comname);
420 commandshortcut = "(" + comname + ')';
421 owner->getMiniBuffer()->Set(commandshortcut);
422 // Here we could even add a small pause,
423 // to annoy the user and make him learn
425 // No! That will just annoy, not teach
426 // anything. The user will read the messages
427 // if they are interested. (Asger)
432 // Now that we know which action, if the buffer is RO let's check
433 // whether the action is legal. Alejandro 970603
434 if (owner->currentView()->available() &&
435 owner->buffer()->isReadonly() &&
436 lyxaction.isFuncRO(action)) {
437 setErrorMessage(N_("Document is read-only"));
438 lyxerr.debug() << "Error: Document is read-only." << endl;
439 goto exit_with_message;
442 // If in math mode pass the control to
443 // the math inset [asierra060396]
444 if (owner->currentView()->available() &&
445 owner->buffer()->the_locking_inset) {
446 if (action>1 || (action==LFUN_UNKNOWN_ACTION && keyseq.length>=-1)) {
447 if (action==LFUN_UNKNOWN_ACTION && argument.empty()) {
448 argument = keyseq.getiso();
450 // Undo/Redo pre 0.13 is a bit tricky for insets.
451 if (action==LFUN_UNDO) {
453 UpdatableInset* inset =
454 owner->buffer()->the_locking_inset;
455 inset->GetCursorPos(slx, sly);
458 inset = (UpdatableInset*)owner->buffer()->text->cursor.par->GetInset(owner->buffer()->text->cursor.pos);
460 inset->Edit(slx, sly);
463 if (action==LFUN_REDO) {
465 UpdatableInset* inset = owner->buffer()->the_locking_inset;
466 inset->GetCursorPos(slx, sly);
469 inset = (UpdatableInset*)owner->buffer()->text->cursor.par->GetInset(owner->buffer()->text->cursor.pos);
471 inset->Edit(slx, sly);
474 if (owner->buffer()->the_locking_inset->LocalDispatch(action, argument.c_str()))
477 setMessage(N_("Text mode"));
478 if (action==LFUN_RIGHT || action==-1)
479 owner->buffer()->text->CursorRight();
480 if (action==LFUN_LEFT || action==LFUN_RIGHT)
487 // --- Misc -------------------------------------------
488 case LFUN_WORDFINDFORWARD :
489 case LFUN_WORDFINDBACKWARD : {
490 static string last_search;
491 string searched_string;
493 if (!argument.empty()) {
494 last_search = argument;
495 searched_string = argument;
497 searched_string = last_search;
500 LyXText * ltCur = owner->currentView()->buffer()->text ;
502 if (!searched_string.empty() &&
503 ( (action == LFUN_WORDFINDBACKWARD) ?
504 ltCur->SearchBackward( searched_string.c_str() ) :
505 ltCur->SearchForward( searched_string.c_str() )
508 // ??? What is that ???
509 owner->currentView()->buffer()->update(-2);
512 // clear the selection (if there is any)
513 owner->currentView()->getScreen()->ToggleSelection();
514 owner->currentView()->buffer()->text->ClearSelection();
516 // Move cursor so that successive C-s 's will not stand in place.
517 if( action == LFUN_WORDFINDFORWARD )
518 owner->buffer()->text->CursorRightOneWord();
519 owner->buffer()->text->FinishUndo();
520 moveCursorUpdate(false);
523 // set the new selection
524 // SetSelectionOverLenChars(owner->currentView()->currentBuffer()->text, iLenSelected);
525 owner->currentView()->getScreen()->ToggleSelection(false);
529 // REMOVED : if (owner->currentView()->getWorkArea()->focus)
530 owner->currentView()->getScreen()->ShowCursor();
536 if (owner->currentView()->available()
537 && owner->currentView()->getScreen()) {
538 owner->buffer()->update(-2);
541 keyseq.print(buf,100, true);
542 owner->getMiniBuffer()->Set(buf, string(), string(), 1);
546 // --- Misc -------------------------------------------
547 case LFUN_EXEC_COMMAND:
548 owner->getMiniBuffer()->ExecCommand();
551 case LFUN_CANCEL: // RVDK_PATCH_5
554 if(owner->currentView()->available())
555 // cancel any selection
556 Dispatch(int(LFUN_MARK_OFF), 0);
557 setMessage(N_("Cancel"));
560 case LFUN_META_FAKE: // RVDK_PATCH_5
562 meta_fake_bit = Mod1Mask;
564 keyseq.print(buf, 98, true);
565 string res = string("M-") + buf;
566 setMessage(buf); // RVDK_PATCH_5
570 case LFUN_READ_ONLY_TOGGLE:
571 if (owner->buffer()->lyxvc.inUse()) {
572 owner->buffer()->lyxvc.toggleReadOnly();
574 owner->buffer()->setReadonly(
575 !owner->buffer()->isReadonly());
579 case LFUN_CENTER: // this is center and redraw.
581 if (owner->buffer()->text->cursor.y >
582 owner->currentView()->getWorkArea()->h / 2) {
583 owner->currentView()->getScreen()->
584 Draw(owner->buffer()->text->cursor.y -
585 owner->currentView()->getWorkArea()->h/2);
587 owner->currentView()->getScreen()->
590 owner->buffer()->update(0);
591 owner->currentView()->redraw();
595 if (owner->currentView()->available()) {
596 owner->buffer()->text->toggleAppendix();
597 owner->buffer()->update(1);
601 // --- Menus -----------------------------------------------
606 case LFUN_MENUNEWTMPLT:
614 case LFUN_CLOSEBUFFER:
619 MenuWrite(owner->buffer());
622 case LFUN_MENUWRITEAS:
623 MenuWriteAs(owner->buffer());
626 case LFUN_MENURELOAD:
631 MenuPreview(owner->buffer());
635 MenuPreviewPS(owner->buffer());
639 MenuRunLaTeX(owner->buffer());
643 MenuBuildProg(owner->buffer());
647 MenuRunChktex(owner->buffer());
651 MenuRunDvips(owner->buffer(), false);
655 MenuPrint(owner->buffer());
659 MenuFax(owner->buffer());
664 //needs argument as string
665 string extyp=argument;
668 if (extyp == "latex") {
669 // make sure that this buffer is not linuxdoc
670 MenuMakeLaTeX(owner->buffer());
673 else if (extyp == "linuxdoc") {
674 // make sure that this buffer is not latex
675 MenuMakeLinuxDoc(owner->buffer());
678 else if (extyp == "docbook") {
679 // make sure that this buffer is not latex or linuxdoc
680 MenuMakeDocBook(owner->buffer());
683 else if (extyp == "dvi") {
684 // Run LaTeX as "Update dvi..." Bernhard.
685 // We want the dvi in the current directory. This
686 // is achieved by temporarily disabling use of
687 // temp directory. As a side-effect, we get
688 // *.log and *.aux files also. (Asger)
689 bool flag = lyxrc->use_tempdir;
690 lyxrc->use_tempdir = false;
691 MenuRunLaTeX(owner->buffer());
692 lyxrc->use_tempdir = flag;
695 else if (extyp == "postscript") {
696 // Start Print-dialog. Not as good as dvi... Bernhard.
697 MenuPrint(owner->buffer());
698 // Since the MenuPrint is a pop-up, we can't use
699 // the same trick as above. (Asger)
700 // MISSING: Move of ps-file :-(
703 else if (extyp == "ascii") {
704 MenuMakeAscii(owner->buffer());
706 else if (extyp == "custom") {
711 else if (extyp == "html" && lyxrc->html_command != "none") {
712 // First, create LaTeX file
713 MenuMakeLaTeX(owner->buffer());
715 // And now, run the converter
716 string file = owner->buffer()->getFileName();
717 Path path(OnlyPath(file));
718 // the tex file name has to be correct for
719 // latex, but the html file name can be
721 string result = ChangeExtension(file, ".html", false);
722 file = ChangeExtension(SpaceLess(file), ".tex", false);
723 string tmp = lyxrc->html_command;
724 tmp = subst(tmp, "$$FName", file);
725 tmp = subst(tmp, "$$OutName", result);
727 int res = one.startscript(Systemcalls::System, tmp);
729 setMessage(_("Document exported as HTML to file `")
730 + MakeDisplayPath(result) +'\'');
732 setErrorMessage(_("Unable to convert to HTML the file `")
733 + MakeDisplayPath(file)
738 setErrorMessage(_("Unknown export type: ")
746 //needs argument as string
747 string imtyp=argument;
750 if (imtyp == "latex") {
751 doImportLaTeX(false);
754 else if (imtyp == "ascii") {
755 doImportASCII(false);
756 } else if (imtyp == "asciiparagraph") {
759 } else if (imtyp == "noweb") {
762 setErrorMessage(string(N_("Unknown import type: "))
774 if (fd_form_toc->form_toc->visible) {
775 fl_raise_form(fd_form_toc->form_toc);
777 static int ow = -1, oh;
778 fl_show_form(fd_form_toc->form_toc,
780 FL_FREE_SIZE, FL_FULLBORDER,
781 _("Table of Contents"));
783 ow = fd_form_toc->form_toc->w;
784 oh = fd_form_toc->form_toc->h;
786 fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
790 case LFUN_TOC_INSERT:
793 new InsetTOC(owner->buffer());
794 owner->buffer()->insertInset(new_inset,
799 case LFUN_LOF_INSERT:
802 new InsetLOF(owner->buffer());
803 owner->buffer()->insertInset(new_inset,
808 case LFUN_LOA_INSERT:
811 new InsetLOA(owner->buffer());
812 owner->buffer()->insertInset(new_inset,
817 case LFUN_LOT_INSERT:
820 new InsetLOT(owner->buffer());
821 owner->buffer()->insertInset(new_inset,
846 case LFUN_MENUSEARCH:
854 case LFUN_PASTESELECTION:
857 if (string(argument) == "paragraph") asPara = true;
858 MenuPasteSelection(asPara);
870 case LFUN_LAYOUT_COPY:
874 case LFUN_LAYOUT_PASTE:
875 PasteEnvironmentCB();
879 owner->currentView()->gotoError();
882 case LFUN_REMOVEERRORS:
883 if (owner->buffer()->removeAutoInsets()) {
884 owner->currentView()->redraw();
885 owner->currentView()->fitCursor();
886 owner->currentView()->updateScrollbar();
898 case LFUN_HYPHENATION:
906 case LFUN_END_OF_SENTENCE:
910 case LFUN_MENU_SEPARATOR:
926 case LFUN_DEPTH_PLUS:
942 case LFUN_RECONFIGURE:
947 if (owner->currentView()->available()
948 && !owner->buffer()->text->selection
949 && owner->buffer()->text->cursor.par->footnoteflag
950 != LyXParagraph::NO_FOOTNOTE)
951 { // only melt footnotes with FOOTMELT, not margins etc
952 if(owner->buffer()->text->cursor.par->footnotekind == LyXParagraph::FOOTNOTE)
959 case LFUN_MARGINMELT:
960 if (owner->currentView()->available()
961 && !owner->buffer()->text->selection
962 && owner->buffer()->text->cursor.par->footnoteflag
963 != LyXParagraph::NO_FOOTNOTE)
964 { // only melt margins
965 if(owner->buffer()->text->cursor.par->footnotekind == LyXParagraph::MARGIN)
972 // --- version control -------------------------------
973 case LFUN_VC_REGISTER:
975 if (!owner->buffer()->lyxvc.inUse())
976 owner->buffer()->lyxvc.registrer();
980 case LFUN_VC_CHECKIN:
982 if (owner->buffer()->lyxvc.inUse()
983 && !owner->buffer()->isReadonly())
984 owner->buffer()->lyxvc.checkIn();
988 case LFUN_VC_CHECKOUT:
990 if (owner->buffer()->lyxvc.inUse()
991 && owner->buffer()->isReadonly())
992 owner->buffer()->lyxvc.checkOut();
998 owner->buffer()->lyxvc.revert();
1004 owner->buffer()->lyxvc.undoLast();
1008 case LFUN_VC_HISTORY:
1010 owner->buffer()->lyxvc.showLog();
1014 // --- buffers ----------------------------------------
1015 case LFUN_PREVBUFFER:
1016 #ifdef WITH_WARNINGS
1017 #warning fix this please
1019 // it is the LyXView or the BufferView that should
1020 // remember the previous buffer, not bufferlist.
1021 // if (owner->currentView()->available()){
1023 // owner->buffer()->update(-2);
1025 // owner->currentView()->setBuffer(bufferlist.prev());
1027 // owner->currentView()->
1028 // resizeCurrentBufferPseudoExpose();
1031 case LFUN_FILE_INSERT:
1033 MenuInsertLyXFile(argument);
1037 case LFUN_FILE_INSERT_ASCII:
1039 bool asPara = false;
1040 asPara = (string(argument) == "paragraph");
1041 InsertAsciiFile(string(), asPara);
1047 // servercmd: argument must be <file>:<template>
1048 Buffer * tmpbuf = 0;
1049 tmpbuf = NewLyxFile(argument);
1051 owner->currentView()->buffer(tmpbuf);
1055 case LFUN_FILE_OPEN:
1056 owner->currentView()->buffer(
1057 bufferlist.loadLyXFile(argument));
1060 case LFUN_LATEX_LOG:
1066 lyxerr.debug() << "LFUN_LAYOUTNO: (arg) " << argument << endl;
1067 int sel = strToInt(argument);
1068 lyxerr.debug() << "LFUN_LAYOUTNO: (sel) "<< sel << endl;
1070 // Should this give a setMessage instead?
1072 return string(); // illegal argument
1074 sel--; // sel 1..., but layout 0...
1076 // Pretend we got the name instead.
1077 Dispatch(int(LFUN_LAYOUT),
1078 textclasslist.NameOfLayout(owner->buffer()->
1087 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1088 << argument << endl;
1090 // Derive layout number from given argument (string)
1091 // and current buffer's textclass (number). */
1094 textclasslist.NumberOfLayout(owner->
1100 // see if we found the layout number:
1101 if (layoutno == -1) {
1102 setErrorMessage(string(N_("Layout ")) + argument +
1107 if (current_layout != layoutno) {
1108 owner->currentView()->getScreen()->HideCursor();
1109 current_layout = layoutno;
1110 owner->buffer()->update(-2);
1111 owner->buffer()->text->
1112 SetLayout(layoutno);
1113 owner->getToolbar()->combox->
1114 select(owner->buffer()->
1117 owner->buffer()->update(1);
1122 case LFUN_LAYOUT_DOCUMENT:
1123 MenuLayoutDocument();
1126 case LFUN_LAYOUT_PARAGRAPH:
1127 MenuLayoutParagraph();
1130 case LFUN_LAYOUT_CHARACTER:
1131 MenuLayoutCharacter();
1134 case LFUN_LAYOUT_TABLE:
1137 if (string(argument) == "true") flag = 1;
1138 MenuLayoutTable(flag);
1142 case LFUN_LAYOUT_PAPER:
1146 case LFUN_LAYOUT_QUOTES:
1150 case LFUN_LAYOUT_PREAMBLE:
1151 MenuLayoutPreamble();
1154 case LFUN_LAYOUT_SAVE_DEFAULT:
1158 case LFUN_DROP_LAYOUTS_CHOICE:
1159 owner->getToolbar()->combox->Show();
1190 case LFUN_UNDERLINE:
1194 case LFUN_FONT_SIZE:
1195 FontSizeCB(argument);
1198 case LFUN_FONT_STATE:
1199 setMessage(CurrentState());
1202 case LFUN_UPCASE_WORD:
1203 owner->buffer()->update(-2);
1205 owner->buffer()->text->ChangeWordCase(LyXText::text_uppercase);
1206 owner->buffer()->update(1);
1210 case LFUN_LOWCASE_WORD:
1211 owner->buffer()->update(-2);
1213 owner->buffer()->text->ChangeWordCase(LyXText::text_lowercase);
1214 owner->buffer()->update(1);
1218 case LFUN_CAPITALIZE_WORD:
1219 owner->buffer()->update(-2);
1221 owner->buffer()->text->ChangeWordCase(LyXText::text_capitalization);
1222 owner->buffer()->update(1);
1226 case LFUN_INSERT_LABEL:
1227 MenuInsertLabel(argument.c_str());
1230 case LFUN_INSERT_REF:
1234 case LFUN_REFTOGGLE:
1237 (InsetRef*)getInsetByCode(Inset::REF_CODE);
1239 if (inset->getFlag()==InsetRef::REF)
1240 inset->setFlag(InsetRef::PAGE_REF);
1242 inset->setFlag(InsetRef::REF);
1245 setErrorMessage(N_("No cross-reference to toggle"));
1252 owner->currentView()->restorePosition();
1258 string label(argument);
1259 if (label.empty()) {
1261 (InsetRef*)getInsetByCode(Inset::REF_CODE);
1263 label = inset->getContents();
1266 if (!label.empty()) {
1267 owner->currentView()->savePosition();
1268 owner->buffer()->gotoLabel(label.c_str());
1273 case LFUN_MENU_OPEN_BY_NAME:
1274 owner->getMenus()->openByName(argument);
1275 break; // RVDK_PATCH_5
1277 case LFUN_SPELLCHECK:
1278 if (lyxrc->isp_command != "none")
1280 break; // RVDK_PATCH_5
1282 // --- Cursor Movements -----------------------------
1285 Buffer *tmpbuffer = owner->buffer();
1286 LyXText *tmptext = owner->buffer()->text;
1287 if(!tmptext->mark_set)
1289 tmpbuffer->update(-2);
1290 if (tmptext->cursor.pos < tmptext->cursor.par->Last()
1291 && tmptext->cursor.par->GetChar(tmptext->cursor.pos)
1293 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)
1294 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)->Editable()==2){
1295 Inset* tmpinset = tmptext->cursor.par->GetInset(tmptext->cursor.pos);
1296 setMessage(tmpinset->EditMessage());
1297 tmpinset->Edit(0,0);
1300 tmptext->CursorRight();
1301 owner->buffer()->text->FinishUndo();
1302 moveCursorUpdate(false);
1303 owner->getMiniBuffer()->Set(CurrentState());
1309 // This is soooo ugly. Isn`t it possible to make
1310 // it simpler? (Lgb)
1311 LyXText *txt= owner->buffer()->text;
1312 if(!txt->mark_set) BeforeChange();
1313 owner->buffer()->update(-2);
1315 if (txt->cursor.pos < txt->cursor.par->Last()
1316 && txt->cursor.par->GetChar(txt->cursor.pos)
1318 && txt->cursor.par->GetInset(txt->cursor.pos)
1319 && txt->cursor.par->GetInset(txt->cursor.pos)->Editable()==2) {
1320 Inset* tmpinset = txt->cursor.par->GetInset(txt->cursor.pos);
1321 setMessage(tmpinset->EditMessage());
1322 tmpinset->Edit(tmpinset->Width(txt->GetFont(txt->cursor.par,
1323 txt->cursor.pos)),0);
1324 // tmpinset->Edit(-1, 0); // -1 means go rightmost
1327 owner->buffer()->text->FinishUndo();
1328 moveCursorUpdate(false);
1329 owner->getMiniBuffer()->Set(CurrentState());
1334 if(!owner->buffer()->text->mark_set) BeforeChange();
1335 owner->buffer()->update(-3);
1336 owner->buffer()->text->CursorUp();
1337 owner->buffer()->text->FinishUndo();
1338 moveCursorUpdate(false);
1339 owner->getMiniBuffer()->Set(CurrentState());
1343 if(!owner->buffer()->text->mark_set)
1345 owner->buffer()->update(-3);
1346 owner->buffer()->text->CursorDown();
1347 owner->buffer()->text->FinishUndo();
1348 moveCursorUpdate(false);
1349 owner->getMiniBuffer()->Set(CurrentState());
1352 case LFUN_UP_PARAGRAPH:
1353 if(!owner->buffer()->text->mark_set)
1355 owner->buffer()->update(-3);
1356 owner->buffer()->text->CursorUpParagraph();
1357 owner->buffer()->text->FinishUndo();
1358 moveCursorUpdate(false);
1359 owner->getMiniBuffer()->Set(CurrentState());
1362 case LFUN_DOWN_PARAGRAPH:
1363 if(!owner->buffer()->text->mark_set)
1365 owner->buffer()->update(-3);
1366 owner->buffer()->text->CursorDownParagraph();
1367 owner->buffer()->text->FinishUndo();
1368 moveCursorUpdate(false);
1369 owner->getMiniBuffer()->Set(CurrentState());
1373 if(!owner->buffer()->text->mark_set)
1375 owner->buffer()->update(-3);
1376 owner->currentView()->cursorPrevious();
1377 owner->buffer()->text->FinishUndo();
1378 moveCursorUpdate(false);
1379 owner->getMiniBuffer()->Set(CurrentState());
1383 if(!owner->buffer()->text->mark_set)
1385 owner->buffer()->update(-3);
1386 owner->currentView()->cursorNext();
1387 owner->buffer()->text->FinishUndo();
1388 moveCursorUpdate(false);
1389 owner->getMiniBuffer()->Set(CurrentState());
1393 if(!owner->buffer()->text->mark_set)
1395 owner->buffer()->update(-2);
1396 owner->buffer()->text->CursorHome();
1397 owner->buffer()->text->FinishUndo();
1398 moveCursorUpdate(false);
1399 owner->getMiniBuffer()->Set(CurrentState());
1403 if(!owner->buffer()->text->mark_set)
1405 owner->buffer()->update(-2);
1406 owner->buffer()->text->CursorEnd();
1407 owner->buffer()->text->FinishUndo();
1408 moveCursorUpdate(false);
1409 owner->getMiniBuffer()->Set(CurrentState());
1413 if(!owner->buffer()->text->mark_set)
1415 owner->buffer()->update(-2);
1416 owner->buffer()->text->CursorTab();
1417 owner->buffer()->text->FinishUndo();
1418 moveCursorUpdate(false);
1419 owner->getMiniBuffer()->Set(CurrentState());
1422 case LFUN_WORDRIGHT:
1423 if(!owner->buffer()->text->mark_set)
1425 owner->buffer()->update(-2);
1426 owner->buffer()->text->CursorRightOneWord();
1427 owner->buffer()->text->FinishUndo();
1428 moveCursorUpdate(false);
1429 owner->getMiniBuffer()->Set(CurrentState());
1433 if(!owner->buffer()->text->mark_set)
1435 owner->buffer()->update(-2);
1436 owner->buffer()->text->CursorLeftOneWord();
1437 owner->buffer()->text->FinishUndo();
1438 moveCursorUpdate(false);
1439 owner->getMiniBuffer()->Set(CurrentState());
1442 case LFUN_BEGINNINGBUF:
1443 if(!owner->buffer()->text->mark_set)
1445 owner->buffer()->update(-2);
1446 owner->buffer()->text->CursorTop();
1447 owner->buffer()->text->FinishUndo();
1448 moveCursorUpdate(false);
1449 owner->getMiniBuffer()->Set(CurrentState());
1453 if(!owner->buffer()->text->mark_set)
1455 owner->buffer()->update(-2);
1456 owner->buffer()->text->CursorBottom();
1457 owner->buffer()->text->FinishUndo();
1458 moveCursorUpdate(false);
1459 owner->getMiniBuffer()->Set(CurrentState());
1463 /* cursor selection ---------------------------- */
1465 owner->buffer()->update(-2);
1466 owner->buffer()->text->CursorRight();
1467 owner->buffer()->text->FinishUndo();
1468 moveCursorUpdate(true);
1469 owner->getMiniBuffer()->Set(CurrentState());
1473 owner->buffer()->update(-2);
1474 owner->buffer()->text->CursorLeft();
1475 owner->buffer()->text->FinishUndo();
1476 moveCursorUpdate(true);
1477 owner->getMiniBuffer()->Set(CurrentState());
1481 owner->buffer()->update(-2);
1482 owner->buffer()->text->CursorUp();
1483 owner->buffer()->text->FinishUndo();
1484 moveCursorUpdate(true);
1485 owner->getMiniBuffer()->Set(CurrentState());
1489 owner->buffer()->update(-2);
1490 owner->buffer()->text->CursorDown();
1491 owner->buffer()->text->FinishUndo();
1492 moveCursorUpdate(true);
1493 owner->getMiniBuffer()->Set(CurrentState());
1496 case LFUN_UP_PARAGRAPHSEL:
1497 owner->buffer()->update(-2);
1498 owner->buffer()->text->CursorUpParagraph();
1499 owner->buffer()->text->FinishUndo();
1500 moveCursorUpdate(true);
1501 owner->getMiniBuffer()->Set(CurrentState());
1504 case LFUN_DOWN_PARAGRAPHSEL:
1505 owner->buffer()->update(-2);
1506 owner->buffer()->text->CursorDownParagraph();
1507 owner->buffer()->text->FinishUndo();
1508 moveCursorUpdate(true);
1509 owner->getMiniBuffer()->Set(CurrentState());
1513 owner->buffer()->update(-2);
1514 owner->currentView()->cursorPrevious();
1515 owner->buffer()->text->FinishUndo();
1516 moveCursorUpdate(true);
1517 owner->getMiniBuffer()->Set(CurrentState());
1521 owner->buffer()->update(-2);
1522 owner->currentView()->cursorNext();
1523 owner->buffer()->text->FinishUndo();
1524 moveCursorUpdate(true);
1525 owner->getMiniBuffer()->Set(CurrentState());
1529 owner->buffer()->update(-2);
1530 owner->buffer()->text->CursorHome();
1531 owner->buffer()->text->FinishUndo();
1532 moveCursorUpdate(true);
1533 owner->getMiniBuffer()->Set(CurrentState());
1537 owner->buffer()->update(-2);
1538 owner->buffer()->text->CursorEnd();
1539 owner->buffer()->text->FinishUndo();
1540 moveCursorUpdate(true);
1541 owner->getMiniBuffer()->Set(CurrentState());
1544 case LFUN_WORDRIGHTSEL:
1545 owner->buffer()->update(-2);
1546 owner->buffer()->text->CursorRightOneWord();
1547 owner->buffer()->text->FinishUndo();
1548 moveCursorUpdate(true);
1549 owner->getMiniBuffer()->Set(CurrentState());
1552 case LFUN_WORDLEFTSEL:
1553 owner->buffer()->update(-2);
1554 owner->buffer()->text->CursorLeftOneWord();
1555 owner->buffer()->text->FinishUndo();
1556 moveCursorUpdate(true);
1557 owner->getMiniBuffer()->Set(CurrentState());
1560 case LFUN_BEGINNINGBUFSEL:
1561 owner->buffer()->update(-2);
1562 owner->buffer()->text->CursorTop();
1563 owner->buffer()->text->FinishUndo();
1564 moveCursorUpdate(true);
1565 owner->getMiniBuffer()->Set(CurrentState());
1568 case LFUN_ENDBUFSEL:
1569 owner->buffer()->update(-2);
1570 owner->buffer()->text->CursorBottom();
1571 owner->buffer()->text->FinishUndo();
1572 moveCursorUpdate(true);
1573 owner->getMiniBuffer()->Set(CurrentState());
1576 // --- text changing commands ------------------------
1577 case LFUN_BREAKLINE:
1579 owner->buffer()->text->InsertChar(LYX_META_NEWLINE);
1581 SetUpdateTimer(0.01);
1582 moveCursorUpdate(false);
1585 case LFUN_PROTECTEDSPACE:
1587 owner->buffer()->text->
1588 InsertChar(LYX_META_PROTECTED_SEPARATOR);
1591 moveCursorUpdate(false);
1595 if(owner->buffer()->text->mark_set) {
1597 owner->buffer()->update(0);
1598 setMessage(N_("Mark removed"));
1601 owner->buffer()->text->mark_set = 1;
1602 owner->buffer()->update(0);
1603 setMessage(N_("Mark set"));
1605 owner->buffer()->text->sel_cursor =
1606 owner->buffer()->text->cursor;
1611 if (!owner->buffer()->text->selection) {
1612 owner->buffer()->text->Delete();
1613 owner->buffer()->text->sel_cursor =
1614 owner->buffer()->text->cursor;
1616 // It is possible to make it a lot faster still
1617 // just comment out the lone below...
1618 owner->currentView()->getScreen()->ShowCursor();
1625 case LFUN_DELETE_SKIP:
1627 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1629 LyXCursor cursor = owner->buffer()->text->cursor;
1632 if (!owner->buffer()->text->selection) {
1633 if (cursor.pos == cursor.par->Last()) {
1634 owner->buffer()->text->CursorRight();
1635 cursor = owner->buffer()->text->cursor;
1637 && !(cursor.par->added_space_top
1638 == VSpace (VSpace::NONE))) {
1639 owner->buffer()->text->SetParagraph
1640 (cursor.par->line_top,
1641 cursor.par->line_bottom,
1642 cursor.par->pagebreak_top,
1643 cursor.par->pagebreak_bottom,
1644 VSpace(VSpace::NONE),
1645 cursor.par->added_space_bottom,
1647 cursor.par->labelwidthstring, 0);
1648 owner->buffer()->text->CursorLeft();
1649 owner->buffer()->update (1);
1651 owner->buffer()->text->CursorLeft();
1652 owner->buffer()->text->Delete();
1653 owner->buffer()->text->sel_cursor =
1654 owner->buffer()->text->cursor;
1658 owner->buffer()->text->Delete();
1659 owner->buffer()->text->sel_cursor =
1660 owner->buffer()->text->cursor;
1670 /* -------> Delete word forward. */
1671 case LFUN_DELETE_WORD_FORWARD:
1672 owner->buffer()->update(-2);
1674 owner->buffer()->text->DeleteWordForward();
1675 owner->buffer()->update( 1 );
1677 moveCursorUpdate(false);
1680 /* -------> Delete word backward. */
1681 case LFUN_DELETE_WORD_BACKWARD:
1682 owner->buffer()->update(-2);
1684 owner->buffer()->text->DeleteWordBackward();
1685 owner->buffer()->update( 1 );
1687 moveCursorUpdate(false);
1690 /* -------> Kill to end of line. */
1691 case LFUN_DELETE_LINE_FORWARD:
1693 owner->buffer()->update(-2);
1694 owner->buffer()->text->DeleteLineForward();
1695 owner->buffer()->update( 1 );
1697 moveCursorUpdate(false);
1700 /* -------> Set mark off. */
1703 owner->buffer()->update(0);
1704 owner->buffer()->text->sel_cursor =
1705 owner->buffer()->text->cursor;
1706 setMessage(N_("Mark off"));
1709 /* -------> Set mark on. */
1712 owner->buffer()->text->mark_set = 1;
1713 owner->buffer()->update( 0 );
1714 owner->buffer()->text->sel_cursor =
1715 owner->buffer()->text->cursor;
1716 setMessage(N_("Mark on"));
1719 case LFUN_BACKSPACE:
1722 if (!owner->buffer()->text->selection) {
1723 if (owner->getIntl()->getTrans()->backspace()) {
1724 owner->buffer()->text->Backspace();
1725 owner->buffer()->text->sel_cursor =
1726 owner->buffer()->text->cursor;
1728 // It is possible to make it a lot faster still
1729 // just comment out the lone below...
1730 owner->currentView()->getScreen()->ShowCursor();
1739 case LFUN_BACKSPACE_SKIP:
1741 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1743 LyXCursor cursor = owner->buffer()->text->cursor;
1746 if (!owner->buffer()->text->selection) {
1748 && !(cursor.par->added_space_top
1749 == VSpace (VSpace::NONE))) {
1750 owner->buffer()->text->SetParagraph
1751 (cursor.par->line_top,
1752 cursor.par->line_bottom,
1753 cursor.par->pagebreak_top,
1754 cursor.par->pagebreak_bottom,
1755 VSpace(VSpace::NONE), cursor.par->added_space_bottom,
1757 cursor.par->labelwidthstring, 0);
1758 owner->buffer()->update (1);
1760 owner->buffer()->text->Backspace();
1761 owner->buffer()->text->sel_cursor
1771 case LFUN_BREAKPARAGRAPH:
1774 owner->buffer()->text->BreakParagraph(0);
1776 SetUpdateTimer(0.01);
1777 owner->buffer()->text->sel_cursor =
1778 owner->buffer()->text->cursor;
1782 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1785 owner->buffer()->text->BreakParagraph(1);
1787 SetUpdateTimer(0.01);
1788 owner->buffer()->text->sel_cursor =
1789 owner->buffer()->text->cursor;
1793 case LFUN_BREAKPARAGRAPH_SKIP:
1795 // When at the beginning of a paragraph, remove
1796 // indentation and add a "defskip" at the top.
1797 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
1799 LyXCursor cursor = owner->buffer()->text->cursor;
1802 if (cursor.pos == 0) {
1803 if (cursor.par->added_space_top == VSpace(VSpace::NONE)) {
1804 owner->buffer()->text->SetParagraph
1805 (cursor.par->line_top,
1806 cursor.par->line_bottom,
1807 cursor.par->pagebreak_top,
1808 cursor.par->pagebreak_bottom,
1809 VSpace(VSpace::DEFSKIP), cursor.par->added_space_bottom,
1811 cursor.par->labelwidthstring, 1);
1812 owner->buffer()->update(1);
1816 owner->buffer()->text->BreakParagraph(0);
1819 SetUpdateTimer(0.01);
1820 owner->buffer()->text->sel_cursor = cursor;
1826 owner->buffer()->text->InsertChar('\"'); // This " matches the single quote in the code
1829 moveCursorUpdate(false);
1835 InsetCommand *new_inset;
1836 if (action == LFUN_HTMLURL)
1837 new_inset = new InsetUrl("htmlurl", "", "");
1839 new_inset = new InsetUrl("url", "", "");
1840 owner->buffer()->insertInset(new_inset);
1841 new_inset->Edit(0, 0);
1845 // --- lyxserver commands ----------------------------
1847 case LFUN_CHARATCURSOR:
1850 LyXParagraph::size_type pos =
1851 owner->buffer()->text->cursor.pos;
1852 if(pos < owner->buffer()->text->cursor.par->size())
1854 int pos = owner->buffer()->text->cursor.pos;
1855 if(pos < owner->buffer()->text->cursor.par->last)
1857 dispatch_buffer = owner->buffer()->text->
1858 cursor.par->text[pos];
1860 dispatch_buffer = "EOF";
1866 tostr(owner->buffer()->text->cursor.x) + ' '
1867 + tostr(owner->buffer()->text->cursor.y);
1874 sscanf(argument.c_str(), " %d %ld", &x, &y);
1875 owner->buffer()->text->SetCursorFromCoordinates(x, y);
1879 case LFUN_GETLAYOUT:
1881 tostr(owner->buffer()->text->cursor.par->layout);
1886 LyXFont *font = &(owner->buffer()->text->current_font);
1887 if(font->shape() == LyXFont::ITALIC_SHAPE)
1888 dispatch_buffer = 'E';
1889 else if(font->shape() == LyXFont::SMALLCAPS_SHAPE)
1890 dispatch_buffer = 'N';
1892 dispatch_buffer = '0';
1899 LyXFont *font = &(owner->buffer()->text->current_font);
1900 if(font->latex() == LyXFont::ON)
1901 dispatch_buffer = 'L';
1903 dispatch_buffer = '0';
1908 setMessage(owner->buffer()->getFileName());
1909 lyxerr.debug() << "FNAME["
1910 << owner->buffer()->getFileName()
1917 keyseq.print(buf,100);
1918 dispatch_buffer = buf;
1919 lyxserver->notifyClient(dispatch_buffer);
1923 case LFUN_GOTOFILEROW:
1925 char file_name[100];
1927 sscanf(argument.c_str(), " %s %d", file_name, &row);
1929 // Must replace extension of the file to be .lyx and get full path
1930 string s = ChangeExtension(string(file_name), ".lyx", false);
1932 // Either change buffer or load the file
1933 if (bufferlist.exists(s))
1934 owner->currentView()->buffer(bufferlist.getBuffer(s));
1936 owner->currentView()->buffer(bufferlist.loadLyXFile(s));
1939 owner->buffer()->setCursorFromRow(row);
1943 if (owner->buffer()->text->cursor.y >
1944 owner->currentView()->getWorkArea()->h / 2) {
1945 owner->currentView()->getScreen()->
1946 Draw(owner->buffer()->text->cursor.y -
1947 owner->currentView()->getWorkArea()->h/2);
1949 owner->currentView()->getScreen()->
1952 owner->buffer()->update(0);
1953 owner->currentView()->redraw();
1960 int qa = lyxaction.LookupFunc(argument.c_str());
1961 setMessage(lyxaction.helpText((kb_action)qa));
1965 // --- accented characters ---------------------------
1968 case LFUN_CIRCUMFLEX:
1978 case LFUN_SPECIAL_CARON:
1981 case LFUN_HUNG_UMLAUT:
1987 if (keyseq.length==-1 && keyseq.getiso()!=0)
1992 owner->getIntl()->getTrans()->
1993 deadkey(c, get_accent(action).accent,
1994 owner->buffer()->text);
1996 // Need to reset, in case the minibuffer calls these
2001 // copied verbatim from do_accent_char
2004 owner->buffer()->text->sel_cursor =
2005 owner->buffer()->text->cursor;
2009 // --- toolbar ----------------------------------
2010 case LFUN_PUSH_TOOLBAR:
2012 int nth = strToInt(argument);
2013 if (lyxerr.debugging(Debug::TOOLBAR)) {
2014 lyxerr << "LFUN_PUSH_TOOLBAR: argument = `"
2015 << argument << "'\n"
2016 << "LFUN_PUSH_TOOLBAR: nth = `"
2017 << nth << "'" << endl;
2022 setErrorMessage(N_("Push-toolbar needs argument > 0"));
2024 owner->getToolbar()->push(nth);
2029 case LFUN_ADD_TO_TOOLBAR:
2031 if (lyxerr.debugging(Debug::TOOLBAR)) {
2032 lyxerr << "LFUN_ADD_TO_TOOLBAR:"
2033 "argument = `" << argument << '\'' << endl;
2035 string tmp(argument);
2036 //lyxerr <<string("Argument: ") + argument);
2037 //lyxerr <<string("Tmp : ") + tmp);
2040 setErrorMessage(N_("Usage: toolbar-add-to <LyX command>"));
2042 owner->getToolbar()->add(argument, false);
2043 owner->getToolbar()->set();
2048 // --- insert characters ----------------------------------------
2050 case LFUN_INSERT_INSET_LATEX:
2052 Inset *new_inset = new InsetLatex(argument);
2053 owner->buffer()->insertInset(new_inset);
2057 // --- Mathed stuff. If we are here, there is no locked inset yet.
2062 if (!greek_kb_flag) {
2064 setMessage(N_("Math greek mode on"));
2071 case LFUN_GREEK_TOGGLE:
2073 greek_kb_flag = (greek_kb_flag) ? 0: 2;
2074 if (greek_kb_flag) {
2075 setMessage(N_("Math greek keyboard on"));
2077 setMessage(N_("Math greek keyboard off"));
2082 case LFUN_MATH_DELIM:
2083 case LFUN_INSERT_MATRIX:
2085 if (owner->currentView()->available()) {
2087 open_new_inset(new InsetFormula(false));
2089 the_locking_inset->LocalDispatch(action, argument.c_str());
2094 case LFUN_INSERT_MATH:
2096 math_insert_symbol(argument.c_str());
2100 case LFUN_MATH_DISPLAY:
2102 if (owner->currentView()->available())
2103 owner->buffer()->open_new_inset(new InsetFormula(true));
2107 case LFUN_MATH_MACRO:
2109 if (owner->currentView()->available()) {
2112 setErrorMessage(N_("Missing argument"));
2114 string s1 = token(s, ' ', 1);
2115 int na = s1.empty() ? 0: atoi(s1.c_str());
2117 open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2123 case LFUN_MATH_MODE: // Open or create a math inset
2126 if (owner->currentView()->available())
2127 owner->buffer()->open_new_inset(new InsetFormula);
2128 setMessage(N_("Math editor mode"));
2132 case LFUN_MATH_NUMBER:
2133 case LFUN_MATH_LIMITS:
2135 setErrorMessage(N_("This is only allowed in math mode!"));
2139 case LFUN_INSERT_CITATION:
2141 InsetCitation *new_inset = new InsetCitation();
2143 // The note, if any, must be after the key, delimited
2144 // by a | so both key and remark can have spaces.
2145 if (!argument.empty()) {
2146 string lsarg(argument);
2147 if (contains(lsarg, "|")) {
2148 new_inset->setContents(token(lsarg, '|', 0));
2149 new_inset->setOptions(token(lsarg, '|', 1));
2151 new_inset->setContents(lsarg);
2152 owner->buffer()->insertInset(new_inset);
2154 owner->buffer()->insertInset(new_inset);
2155 new_inset->Edit(0,0);
2160 case LFUN_INSERT_BIBTEX:
2162 // ale970405+lasgoutt970425
2163 // The argument can be up to two tokens separated
2164 // by a space. The first one is the bibstyle.
2165 string lsarg(argument);
2166 string bibstyle = token(lsarg, ' ', 1);
2167 if (bibstyle.empty())
2169 InsetBibtex *new_inset
2170 = new InsetBibtex(token(lsarg, ' ', 0),
2174 owner->buffer()->insertInset(new_inset);
2175 if (lsarg.empty()) {
2176 new_inset->Edit(0,0);
2181 // BibTeX data bases
2182 case LFUN_BIBDB_ADD:
2184 InsetBibtex *inset =
2185 (InsetBibtex*)getInsetByCode(Inset::BIBTEX_CODE);
2187 inset->addDatabase(argument);
2192 case LFUN_BIBDB_DEL:
2194 InsetBibtex *inset =
2195 (InsetBibtex*)getInsetByCode(Inset::BIBTEX_CODE);
2197 inset->delDatabase(argument);
2202 case LFUN_BIBTEX_STYLE:
2204 InsetBibtex *inset =
2205 (InsetBibtex*)getInsetByCode(Inset::BIBTEX_CODE);
2207 inset->setOptions(argument);
2212 case LFUN_INDEX_INSERT:
2213 case LFUN_INDEX_INSERT_LAST:
2215 InsetIndex * new_inset = new InsetIndex();
2216 if (!argument.empty()) {
2217 string lsarg(argument);
2218 new_inset->setContents(lsarg);
2219 owner->buffer()->insertInset(new_inset);
2222 //get the current word for an argument
2228 LyXParagraph::size_type lastpos =
2229 owner->buffer()->text->cursor.pos - 1;
2230 // If this can't happen, let's make sure that it really don't
2231 Assert(owner->buffer()->text->cursor.pos - 1 >= 0);
2233 int lastpos =owner->buffer()->text->cursor.pos - 1;
2234 //this shouldn't happen, but let's be careful
2235 if (lastpos < 0) lastpos=0;
2237 // get the current word
2238 // note that this must be done before
2239 // inserting the inset, or the inset will break
2241 string curstring(owner->buffer()
2242 ->text->cursor.par->GetWord(lastpos));
2244 //make the new inset and write the current word into it
2245 InsetIndex * new_inset = new InsetIndex();
2247 new_inset->setContents(curstring);
2249 //don't edit it if the call was to INSERT_LAST
2250 if(action!=LFUN_INDEX_INSERT_LAST) {
2251 new_inset->Edit(0,0);
2253 //it looks blank on the screen unless
2254 //we do something. put it here.
2256 // move the cursor to the returned value of lastpos
2257 // but only for the auto-insert
2258 owner->buffer()->text->cursor.pos=lastpos;
2261 //put the new inset into the buffer.
2262 // there should be some way of knowing the user
2263 //cancelled & avoiding this, but i don't know how
2264 owner->buffer()->insertInset(new_inset);
2269 case LFUN_INDEX_PRINT:
2271 Inset *new_inset = new InsetPrintIndex(owner->buffer());
2272 owner->buffer()->insertInset(new_inset, "Standard", true);
2276 case LFUN_PARENTINSERT:
2278 lyxerr << "arg " << argument << endl;
2279 Inset *new_inset = new InsetParent(argument, owner->buffer());
2280 owner->buffer()->insertInset(new_inset, "Standard", true);
2284 case LFUN_CHILDINSERT:
2286 Inset *new_inset = new InsetInclude(argument,owner->buffer());
2287 owner->buffer()->insertInset(new_inset, "Standard", true);
2288 new_inset->Edit(0,0);
2292 case LFUN_CHILDOPEN:
2294 string filename = MakeAbsPath(argument,
2295 OnlyPath(owner->buffer()->getFileName()));
2296 setMessage(N_("Opening child document ") +
2297 MakeDisplayPath(filename) + "...");
2298 owner->currentView()->savePosition();
2299 if (bufferlist.exists(filename))
2300 owner->currentView()->buffer(bufferlist.getBuffer(filename));
2302 owner->currentView()->buffer(bufferlist.loadLyXFile(filename));
2306 case LFUN_INSERT_NOTE:
2310 case LFUN_INSERTFOOTNOTE:
2312 LyXParagraph::footnote_kind kind;
2313 if (argument == "footnote")
2314 { kind = LyXParagraph::FOOTNOTE; }
2315 else if (argument == "margin")
2316 { kind = LyXParagraph::MARGIN; }
2317 else if (argument == "figure")
2318 { kind = LyXParagraph::FIG; }
2319 else if (argument == "table")
2320 { kind = LyXParagraph::TAB; }
2321 else if (argument == "wide-fig")
2322 { kind = LyXParagraph::WIDE_FIG; }
2323 else if (argument == "wide-tab")
2324 { kind = LyXParagraph::WIDE_TAB; }
2325 else if (argument == "algorithm")
2326 { kind = LyXParagraph::ALGORITHM; }
2328 setErrorMessage(N_("Unknown kind of footnote"));
2331 owner->buffer()->text->InsertFootnoteEnvironment(kind);
2332 owner->buffer()->update(1);
2336 case LFUN_BUFFERBULLETSSELECT:
2340 case LFUN_TOGGLECURSORFOLLOW:
2341 cursor_follows_scrollbar = !cursor_follows_scrollbar;
2344 case LFUN_KMAP_OFF: // keymap off
2345 owner->getIntl()->KeyMapOn(false);
2348 case LFUN_KMAP_PRIM: // primary keymap
2349 owner->getIntl()->KeyMapPrim();
2352 case LFUN_KMAP_SEC: // secondary keymap
2353 owner->getIntl()->KeyMapSec();
2356 case LFUN_KMAP_TOGGLE: // toggle keymap
2357 owner->getIntl()->ToggleKeyMap();
2360 case LFUN_SELFINSERT:
2362 for (string::size_type i = 0; i < argument.length(); ++i) {
2363 owner->buffer()->text->InsertChar(argument[i]);
2364 // This needs to be in the loop, or else we
2365 // won't break lines correctly. (Asger)
2369 owner->buffer()->text->sel_cursor =
2370 owner->buffer()->text->cursor;
2371 moveCursorUpdate(false);
2375 case LFUN_UNKNOWN_ACTION:
2377 if (owner->buffer()->isReadonly()) {
2379 setErrorMessage(N_("Document is read only"));
2383 if (!argument.empty()) {
2385 /* Automatically delete the currently selected
2386 * text and replace it with what is being
2387 * typed in now. Depends on lyxrc settings
2388 * "auto_region_delete", which defaults to
2391 if ( lyxrc->auto_region_delete ) {
2392 if (owner->buffer()->text->selection){
2393 owner->buffer()->text->CutSelection(false);
2394 owner->buffer()->update(-1);
2399 for (string::size_type i = 0; i < argument.length(); ++i) {
2400 if (greek_kb_flag) {
2401 if (!math_insert_greek(argument[i]))
2402 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->buffer()->text);
2404 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->buffer()->text);
2410 owner->buffer()->text->sel_cursor =
2411 owner->buffer()->text->cursor;
2412 moveCursorUpdate(false);
2415 // why is an "Unknown action" with empty
2416 // argument even dispatched in the first
2417 // place? I`ll probably change that. (Lgb)
2419 setErrorMessage(N_("Unknown action"));
2423 lyxerr << "A truly unknown func!" << endl;
2429 string res=getMessage();
2432 if (!commandshortcut.empty()) {
2433 string newbuf = owner->getMiniBuffer()->GetText();
2434 if (newbuf != commandshortcut) {
2435 owner->getMiniBuffer()->Set(newbuf
2441 owner->getMiniBuffer()->Set(string(_(res.c_str()))
2442 + " " + commandshortcut);
2445 return getMessage();
2449 void LyXFunc::setupLocalKeymap()
2451 keyseq.stdmap = keyseq.curmap = toplevel_keymap;
2452 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap;
2456 void LyXFunc::MenuNew(bool fromTemplate)
2458 string fname, initpath = lyxrc->document_path;
2461 if (owner->currentView()->available()) {
2462 string trypath = owner->buffer()->filepath;
2463 // If directory is writeable, use this as default.
2464 if (IsDirWriteable(trypath) == 1)
2469 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2470 fileDlg.SetButton(1, _("Templates"), lyxrc->template_path);
2471 fname = fileDlg.Select(_("Enter Filename for new document"),
2472 initpath, "*.lyx", _("newfile"));
2475 if (fname.empty()) {
2476 owner->getMiniBuffer()->Set(_("Canceled."));
2477 lyxerr.debug() << "New Document Cancelled." << endl;
2481 // get absolute path of file and make sure the filename ends
2483 string s = MakeAbsPath(fname);
2484 if (!IsLyXFilename(s))
2487 // Check if the document already is open
2488 if (bufferlist.exists(s)){
2489 switch(AskConfirmation(_("Document is already open:"),
2490 MakeDisplayPath(s,50),
2491 _("Do you want to close that document now?\n"
2492 "('No' will just switch to the open version)")))
2494 case 1: // Yes: close the document
2495 if (!bufferlist.close(bufferlist.getBuffer(s)))
2496 // If close is canceled, we cancel here too.
2499 case 2: // No: switch to the open document
2500 owner->currentView()->buffer(bufferlist.getBuffer(s));
2502 case 3: // Cancel: Do nothing
2503 owner->getMiniBuffer()->Set(_("Canceled."));
2508 // Check whether the file already exists
2509 if (IsLyXFilename(s)) {
2510 FilePtr myfile(s, FilePtr::read);
2512 AskQuestion(_("File already exists:"),
2513 MakeDisplayPath(s,50),
2514 _("Do you want to open the document?"))) {
2516 owner->getMiniBuffer()->Set(_("Opening document"),
2517 MakeDisplayPath(s), "...");
2519 owner->currentView()->buffer(
2520 bufferlist.loadLyXFile(s));
2521 owner->getMiniBuffer()->Set(_("Document"),
2528 // The template stuff
2532 fname = fileDlg.Select(_("Choose template"),
2533 lyxrc->template_path,
2539 // find a free buffer
2540 lyxerr.debug() << "Find a free buffer." << endl;
2541 owner->currentView()->buffer(bufferlist.newFile(s,templname));
2545 void LyXFunc::MenuOpen()
2547 string initpath = lyxrc->document_path;
2550 if (owner->currentView()->available()) {
2551 string trypath = owner->buffer()->filepath;
2552 // If directory is writeable, use this as default.
2553 if (IsDirWriteable(trypath) == 1)
2559 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2560 fileDlg.SetButton(1, _("Examples"),
2561 AddPath(system_lyxdir, "examples"));
2562 string filename = fileDlg.Select(_("Select Document to Open"),
2566 // check selected filename
2567 if (filename.empty()) {
2568 owner->getMiniBuffer()->Set(_("Canceled."));
2572 // get absolute path of file and make sure the filename ends
2574 filename = MakeAbsPath(filename);
2575 if (!IsLyXFilename(filename))
2579 owner->getMiniBuffer()->Set(_("Opening document"),
2580 MakeDisplayPath(filename), "...");
2581 Buffer * openbuf = bufferlist.loadLyXFile(filename);
2583 owner->currentView()->buffer(openbuf);
2584 owner->getMiniBuffer()->Set(_("Document"),
2585 MakeDisplayPath(filename),
2588 owner->getMiniBuffer()->Set(_("Could not open document"),
2589 MakeDisplayPath(filename));
2594 void LyXFunc::doImportASCII(bool linorpar)
2596 string initpath = lyxrc->document_path;
2599 if (owner->currentView()->available()) {
2600 string trypath = owner->buffer()->filepath;
2601 // If directory is writeable, use this as default.
2602 if (IsDirWriteable(trypath) == 1)
2608 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2609 fileDlg.SetButton(1, _("Examples"),
2610 AddPath(system_lyxdir, "examples"));
2611 string filename = fileDlg.Select(_("Select ASCII file to Import"),
2615 // check selected filename
2616 if (filename.empty()) {
2617 owner->getMiniBuffer()->Set(_("Canceled."));
2621 // get absolute path of file
2622 filename = MakeAbsPath(filename);
2624 string s = ChangeExtension(filename, ".lyx", false);
2626 // Check if the document already is open
2627 if (bufferlist.exists(s)){
2628 switch(AskConfirmation(_("Document is already open:"),
2629 MakeDisplayPath(s,50),
2630 _("Do you want to close that document now?\n"
2631 "('No' will just switch to the open version)")))
2633 case 1: // Yes: close the document
2634 if (!bufferlist.close(bufferlist.getBuffer(s)))
2635 // If close is canceled, we cancel here too.
2638 case 2: // No: switch to the open document
2639 owner->currentView()->buffer(bufferlist.getBuffer(s));
2641 case 3: // Cancel: Do nothing
2642 owner->getMiniBuffer()->Set(_("Canceled."));
2647 // Check if a LyX document by the same root exists in filesystem
2648 FileInfo f(s, true);
2649 if (f.exist() && !AskQuestion(_("A document by the name"),
2651 _("already exists. Overwrite?"))) {
2652 owner->getMiniBuffer()->Set(_("Canceled."));
2656 owner->currentView()->buffer(bufferlist.newFile(s,string()));
2657 owner->getMiniBuffer()->Set(_("Importing ASCII file"),
2658 MakeDisplayPath(filename), "...");
2659 // Insert ASCII file
2660 InsertAsciiFile(filename,linorpar);
2661 owner->getMiniBuffer()->Set(_("ASCII file "),
2662 MakeDisplayPath(filename),
2667 void LyXFunc::doImportLaTeX(bool isnoweb)
2669 string initpath = lyxrc->document_path;
2672 if (owner->currentView()->available()) {
2673 string trypath = owner->buffer()->filepath;
2674 // If directory is writeable, use this as default.
2675 if (IsDirWriteable(trypath) == 1)
2681 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2682 fileDlg.SetButton(1, _("Examples"),
2683 AddPath(system_lyxdir, "examples"));
2686 filename = fileDlg.Select(_("Select Noweb file to Import"),
2689 filename = fileDlg.Select(_("Select LaTeX file to Import"),
2695 // check selected filename
2696 if (filename.empty()) {
2697 owner->getMiniBuffer()->Set(_("Canceled."));
2701 // get absolute path of file
2702 filename = MakeAbsPath(filename);
2704 // Check if the document already is open
2705 string LyXfilename = ChangeExtension(filename, ".lyx", false);
2706 if (bufferlist.exists(LyXfilename)){
2707 switch(AskConfirmation(_("Document is already open:"),
2708 MakeDisplayPath(LyXfilename,50),
2709 _("Do you want to close that document now?\n"
2710 "('No' will just switch to the open version)")))
2712 case 1: // Yes: close the document
2713 if (!bufferlist.close(bufferlist.getBuffer(LyXfilename)))
2714 // If close is canceled, we cancel here too.
2717 case 2: // No: switch to the open document
2718 owner->currentView()->buffer(
2719 bufferlist.getBuffer(LyXfilename));
2721 case 3: // Cancel: Do nothing
2722 owner->getMiniBuffer()->Set(_("Canceled."));
2727 // Check if a LyX document by the same root exists in filesystem
2728 FileInfo f(LyXfilename, true);
2729 if (f.exist() && !AskQuestion(_("A document by the name"),
2730 MakeDisplayPath(LyXfilename),
2731 _("already exists. Overwrite?"))) {
2732 owner->getMiniBuffer()->Set(_("Canceled."));
2739 owner->getMiniBuffer()->Set(_("Importing LaTeX file"),
2740 MakeDisplayPath(filename), "...");
2741 ImportLaTeX myImport(filename);
2742 openbuf = myImport.run();
2744 owner->getMiniBuffer()->Set(_("Importing Noweb file"),
2745 MakeDisplayPath(filename), "...");
2746 ImportNoweb myImport(filename);
2747 openbuf = myImport.run();
2750 owner->currentView()->buffer(openbuf);
2751 owner->getMiniBuffer()->Set(isnoweb ?
2752 _("Noweb file ") : _("LateX file "),
2753 MakeDisplayPath(filename),
2756 owner->getMiniBuffer()->Set(isnoweb ?
2757 _("Could not import Noweb file") :
2758 _("Could not import LaTeX file"),
2759 MakeDisplayPath(filename));
2764 void LyXFunc::MenuInsertLyXFile(string const & filen)
2766 string filename = filen;
2768 if (filename.empty()) {
2769 // Launch a file browser
2770 string initpath = lyxrc->document_path;
2773 if (owner->currentView()->available()) {
2774 string trypath = owner->buffer()->filepath;
2775 // If directory is writeable, use this as default.
2776 if (IsDirWriteable(trypath) == 1)
2782 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2783 fileDlg.SetButton(1, _("Examples"),
2784 AddPath(system_lyxdir, "examples"));
2785 filename = fileDlg.Select(_("Select Document to Insert"),
2789 // check selected filename
2790 if (filename.empty()) {
2791 owner->getMiniBuffer()->Set(_("Canceled."));
2796 // get absolute path of file and make sure the filename ends
2798 filename = MakeAbsPath(filename);
2799 if (!IsLyXFilename(filename))
2803 owner->getMiniBuffer()->Set(_("Inserting document"),
2804 MakeDisplayPath(filename), "...");
2805 bool res = owner->buffer()->insertLyXFile(filename);
2807 owner->getMiniBuffer()->Set(_("Document"),
2808 MakeDisplayPath(filename),
2811 owner->getMiniBuffer()->Set(_("Could not insert document"),
2812 MakeDisplayPath(filename));
2817 void LyXFunc::reloadBuffer()
2819 string fn = owner->buffer()->getFileName();
2820 if (bufferlist.close(owner->buffer()))
2821 owner->currentView()->buffer(bufferlist.loadLyXFile(fn));
2825 void LyXFunc::CloseBuffer()
2827 if (bufferlist.close(owner->buffer()) && !quitting) {
2828 if (bufferlist.empty()) {
2829 // need this otherwise SEGV may occur while trying to
2830 // set variables that don't exist
2831 // since there's no current buffer
2832 CloseAllBufferRelatedPopups();
2835 owner->currentView()->buffer(bufferlist.first());
2841 Inset * LyXFunc::getInsetByCode(Inset::Code code)
2845 LyXCursor cursor = owner->buffer()->text->cursor;
2847 LyXParagraph::size_type pos = cursor.pos;
2849 int pos = cursor.pos;
2851 LyXParagraph * par = cursor.par;
2853 while (par && !found) {
2854 while ((inset = par->ReturnNextInsetPointer(pos))){
2855 if (inset->LyxCode()==code) {
2863 return (found) ? inset: 0;
2867 // Each "owner" should have it's own message method. lyxview and
2868 // the minibuffer would use the minibuffer, but lyxserver would
2869 // send an ERROR signal to its client. Alejandro 970603
2870 // This func is bit problematic when it comes to NLS, to make the
2871 // lyx servers client be language indepenent we must not translate
2872 // strings sent to this func.
2873 void LyXFunc::setErrorMessage(string const &m)
2875 dispatch_buffer = m;
2880 void LyXFunc::setMessage(string const & m)
2882 dispatch_buffer = m;