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"
30 #include "LyXAction.h"
32 #include "insets/insetlatex.h"
34 #include "insets/inseturl.h"
35 #include "insets/insetlatexaccent.h"
36 #include "insets/insettoc.h"
37 #include "insets/insetlof.h"
38 #include "insets/insetloa.h"
39 #include "insets/insetlot.h"
40 #include "insets/insetref.h"
41 #include "insets/insetparent.h"
42 #include "insets/insetindex.h"
43 #include "insets/insetinclude.h"
44 #include "insets/insetbib.h"
45 #include "mathed/formulamacro.h"
47 #include "spellchecker.h" // RVDK_PATCH_5
48 #include "minibuffer.h"
52 #include "lyx_gui_misc.h"
53 #include "support/filetools.h"
54 #include "support/FileInfo.h"
55 #include "support/LAssert.h"
56 #include "support/syscall.h"
57 #include "support/lstrings.h"
58 #include "support/path.h"
59 #include "lyxscreen.h"
64 #include "trans_mgr.h"
65 #include "ImportLaTeX.h"
66 #include "ImportNoweb.h"
69 extern bool cursor_follows_scrollbar;
71 extern void InsertAsciiFile(string const &, bool);
72 extern void math_insert_symbol(char const*);
73 extern Bool math_insert_greek(char const); // why "Bool"?
74 extern BufferList bufferlist;
75 extern LyXServer * lyxserver;
76 extern short greek_kb_flag;
77 extern FD_form_toc * fd_form_toc;
78 extern bool selection_possible;
80 extern kb_keymap * toplevel_keymap;
82 extern void BeforeChange();
83 extern void MenuWrite(Buffer*);
84 extern void MenuWriteAs(Buffer*);
85 extern int MenuRunLaTeX(Buffer*);
86 extern int MenuBuildProg(Buffer*);
87 extern int MenuRunChktex(Buffer*);
88 extern bool MenuRunDvips(Buffer *, bool);
89 extern void MenuPrint(Buffer*);
90 extern void MenuSendto();
91 extern void QuitLyX();
92 extern void MenuFax(Buffer *);
93 extern void MenuExport(Buffer *,string const &);
94 extern void MenuPasteSelection(char at);
95 extern LyXAction lyxaction;
97 extern tex_accent_struct get_accent(kb_action action);
99 extern void AutoSave();
100 extern void MenuSearch();
101 extern void CopyCB();
102 extern void CopyEnvironmentCB();
103 extern void PasteEnvironmentCB();
104 extern void GotoNote();
105 extern void NoteCB();
106 extern void OpenStuff();
107 extern void HyphenationPoint();
109 extern void EndOfSentenceDot();
110 extern void MenuSeparator();
112 extern void MenuUndo();
113 extern void MenuRedo();
114 extern void SmallUpdate(signed char);
115 extern void SetUpdateTimer(float timer= 0.3);
116 extern void FreeUpdateTimer();
117 extern bool MenuPreview(Buffer*);
118 extern bool MenuPreviewPS(Buffer*);
119 extern void MenuInsertLabel(char const *);
120 extern void MenuInsertRef();
121 extern void MenuLayoutCharacter();
122 extern void MenuLayoutParagraph();
123 extern void MenuLayoutDocument();
124 extern void MenuLayoutPaper();
125 extern void MenuLayoutTable(int flag);
126 extern void MenuLayoutQuotes();
127 extern void MenuLayoutPreamble();
128 extern void MenuLayoutSave();
129 extern void bulletForm();
131 extern Buffer * NewLyxFile(string const &);
132 extern void LoadLyXFile(string const &);
133 extern void Reconfigure();
135 extern int current_layout;
136 extern int getISOCodeFromLaTeX(char *);
138 extern int UnlockInset(UpdatableInset *);
140 extern void ShowLatexLog();
142 extern void UpdateInset(Inset * inset, bool mark_dirty = true);
144 /* === globals =========================================================== */
146 bool LyXFunc::show_sc = true;
149 LyXFunc::LyXFunc(LyXView * o)
153 lyx_dead_action = LFUN_NOACTION;
154 lyx_calling_dead_action = LFUN_NOACTION;
159 // I changed this func slightly. I commented out the ...FinishUndo(),
160 // this means that all places that used to have a moveCursorUpdate, now
161 // have a ...FinishUndo() as the preceeding statement. I have also added
162 // a moveCursorUpdate to some of the functions that updated the cursor, but
163 // that did not show its new position.
165 void LyXFunc::moveCursorUpdate(bool selecting)
168 if (selecting || owner->view()->text->mark_set) {
169 owner->view()->text->SetSelection();
170 owner->view()->getScreen()->ToggleToggle();
171 owner->view()->update(0);
173 owner->view()->update(-2); // this IS necessary
177 if (selecting || owner->buffer()->text->mark_set) {
178 owner->buffer()->text->SetSelection();
179 owner->view()->getScreen()->ToggleToggle();
180 owner->buffer()->update(0);
182 owner->buffer()->update(-2); // this IS necessary
186 owner->view()->getScreen()->ShowCursor();
188 /* ---> Everytime the cursor is moved, show the current font state. */
189 // should this too me moved out of this func?
190 //owner->getMiniBuffer()->Set(CurrentState());
194 int LyXFunc::processKeyEvent(XEvent * ev)
201 XKeyEvent * keyevent = &ev->xkey;
202 KeySym keysym_return;
204 num_bytes = LyXLookupString(ev, s_r, 10, &keysym_return);
206 if (lyxerr.debugging(Debug::KEY)) {
207 lyxerr << "KeySym is "
208 << XKeysymToString(keysym_return)
210 << keysym_return << "]"
211 << " and num_bytes is "
213 << " the string returned is \""
214 << s_r << '\"' << endl;
216 // Do nothing if we have nothing (JMarc)
217 if (num_bytes == 0 && keysym_return == NoSymbol) {
218 lyxerr[Debug::KEY] << "Empty kbd action (probably composing)"
223 // this function should be used always [asierra060396]
224 if (owner->view()->available() &&
225 owner->buffer()->the_locking_inset &&
226 keysym_return == XK_Escape) {
227 UnlockInset(owner->buffer()->the_locking_inset);
229 owner->view()->text->CursorRight();
231 owner->buffer()->text->CursorRight();
236 // Can we be sure that this will work for all X-Windows
237 // implementations? (Lgb)
238 // This code snippet makes lyx ignore some keys. Perhaps
239 // all of them should be explictly mentioned?
240 if((keysym_return >= XK_Shift_L && keysym_return <= XK_Hyper_R)
241 || keysym_return == XK_Mode_switch || keysym_return == 0x0)
244 // Do a one-deep top-level lookup for
245 // cancel and meta-fake keys. RVDK_PATCH_5
246 cancel_meta_seq.reset();
248 action = cancel_meta_seq.addkey(keysym_return, keyevent->state
249 &(ShiftMask|ControlMask
252 // When not cancel or meta-fake, do the normal lookup.
253 // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
254 // Mostly, meta_fake_bit = 0. RVDK_PATCH_5.
255 if ( (action != LFUN_CANCEL) && (action != LFUN_META_FAKE) ) {
257 // remove Caps Lock and Mod2 as a modifiers
258 action = keyseq.addkey(keysym_return,
259 (keyevent->state | meta_fake_bit)
260 &(ShiftMask|ControlMask
263 // Dont remove this unless you know what you are doing.
266 if (action == 0) action = LFUN_PREFIX;
268 if (lyxerr.debugging(Debug::KEY)) {
270 keyseq.print(buf, 100);
274 << num_bytes << "]" << endl;
277 // already here we know if it any point in going further
278 // why not return already here if action == -1 and
279 // num_bytes == 0? (Lgb)
281 if(keyseq.length>1 || keyseq.length<-1){
283 keyseq.print(buf, 100);
284 owner->getMiniBuffer()->Set(buf);
288 if (keyseq.length<-1) { // unknown key sequence...
291 keyseq.print(buf, 100);
292 owner->getMiniBuffer()->Set(_("Unknown sequence:"), buf);
296 char isochar = keyseq.getiso();
297 if (!(keyevent->state&ControlMask) &&
298 !(keyevent->state&Mod1Mask) &&
299 (isochar && keysym_return < 0xF000)) {
302 if (argument.empty()) {
303 lyxerr.debug() << "Empty argument!" << endl;
304 // This can`t possibly be of any use
305 // so we`ll skip the dispatch.
309 if (action == LFUN_SELFINSERT) {
313 bool tmp_sc = show_sc;
315 Dispatch(action, argument.c_str());
322 LyXFunc::func_status LyXFunc::getStatus(int ac) const
325 func_status flag = LyXFunc::OK;
327 Buffer * buf = owner->buffer();
329 if (lyxaction.isPseudoAction(ac))
330 action = lyxaction.retrieveActionArg(ac, argument);
332 action = static_cast<kb_action>(ac);
334 if (action == LFUN_UNKNOWN_ACTION) {
335 setErrorMessage(N_("Unknown action"));
336 return LyXFunc::Unknown;
339 // Check whether we need a buffer
340 if (!lyxaction.funcHasFlag(action, LyXAction::NoBuffer)) {
341 // Yes we need a buffer, do we have one?
344 // Can we use a readonly buffer?
345 if (buf->isReadonly() &&
346 !lyxaction.funcHasFlag(action,
347 LyXAction::ReadOnly)) {
349 setErrorMessage(N_("Document is read-only"));
350 flag = func_status(flag | LyXFunc::Disabled);
354 setErrorMessage(N_("Command not allowed with"
355 "out any document open"));
356 flag = func_status(flag | LyXFunc::Disabled);
360 if (flag & LyXFunc::Disabled)
363 static bool noLaTeX = lyxrc->latex_command == "none";
364 bool disable = false;
367 disable = noLaTeX || lyxrc->view_dvi_command == "none";
370 disable = noLaTeX || lyxrc->view_ps_command == "none";
377 disable = noLaTeX || lyxrc->print_command == "none";
380 disable = noLaTeX || lyxrc->fax_command == "none";
383 if (argument == "latex")
384 disable = lyxrc->relyx_command == "none";
387 if (argument == "dvi" || argument == "postscript")
389 if (argument == "html")
390 disable = lyxrc->html_command == "none";
393 disable = buf->undostack.empty();
396 disable = buf->redostack.empty();
398 case LFUN_SPELLCHECK:
399 disable = lyxrc->isp_command == "none";
402 disable = lyxrc->chktex_command == "none";
404 case LFUN_LAYOUT_TABLE:
406 disable = ! owner->view()->text->cursor.par->table;
408 disable = ! buf->text->cursor.par->table;
415 flag |= LyXFunc::Disabled;
418 func_status box = LyXFunc::ToggleOff;
420 LyXFont font = owner->view()->text->real_current_font;
422 LyXFont font = buf->text->real_current_font;
426 if (font.emph() == LyXFont::ON)
427 box = LyXFunc::ToggleOn;
430 if (font.noun() == LyXFont::ON)
431 box = LyXFunc::ToggleOn;
434 if (font.series() == LyXFont::BOLD_SERIES)
435 box = LyXFunc::ToggleOn;
438 if (font.latex() == LyXFont::ON)
439 box = LyXFunc::ToggleOn;
453 string LyXFunc::Dispatch(string const & s)
455 // Split command string into command and argument
456 string cmd, line = frontStrip(s);
457 string arg = strip(frontStrip(split(line, cmd, ' ')));
459 return Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
464 string LyXFunc::Dispatch(int ac,
465 char const * do_not_use_this_arg)
470 FL_OBJECT * ob = 0; // This will disapear soon
472 // we have not done anything wrong yet.
474 dispatch_buffer.clear();
476 // if action is a pseudo-action, we need the real action
477 if (lyxaction.isPseudoAction(ac)) {
479 action = static_cast<kb_action>
480 (lyxaction.retrieveActionArg(ac, tmparg));
484 action = static_cast<kb_action>(ac);
485 if (do_not_use_this_arg)
486 argument = do_not_use_this_arg; // except here
489 selection_possible = false;
491 if (owner->view()->available()
492 && owner->view()->getScreen())
493 owner->view()->getScreen()->HideCursor();
495 // We cannot use this function here
496 if (getStatus(action) & Disabled)
497 goto exit_with_message;
499 commandshortcut.clear();
501 if (lyxrc->display_shortcuts && show_sc) {
502 if (action != LFUN_SELFINSERT) {
503 // Put name of command and list of shortcuts
504 // for it in minibuffer
505 string comname = lyxaction.getActionName(action);
507 int pseudoaction = action;
508 bool argsadded = false;
510 if (!argument.empty()) {
511 // If we have the command with argument,
514 lyxaction.searchActionArg(action,
517 if (pseudoaction == -1) {
518 pseudoaction = action;
520 comname += " " + argument;
525 string shortcuts = toplevel_keymap->findbinding(pseudoaction);
527 if (!shortcuts.empty()) {
528 comname += ": " + shortcuts;
529 } else if (!argsadded) {
530 comname += " " + argument;
533 if (!comname.empty()) {
534 comname = strip(comname);
535 commandshortcut = "(" + comname + ')';
536 owner->getMiniBuffer()->Set(commandshortcut);
537 // Here we could even add a small pause,
538 // to annoy the user and make him learn
540 // No! That will just annoy, not teach
541 // anything. The user will read the messages
542 // if they are interested. (Asger)
547 // If in math mode pass the control to
548 // the math inset [asierra060396]
549 if (owner->view()->available() &&
550 owner->buffer()->the_locking_inset) {
552 || (action == LFUN_UNKNOWN_ACTION && keyseq.length>= -1)) {
553 if (action == LFUN_UNKNOWN_ACTION && argument.empty()) {
554 argument = keyseq.getiso();
556 // Undo/Redo pre 0.13 is a bit tricky for insets.
557 if (action == LFUN_UNDO) {
559 UpdatableInset * inset =
560 owner->buffer()->the_locking_inset;
561 inset->GetCursorPos(slx, sly);
564 inset = static_cast<UpdatableInset*>(owner->view()->text->cursor.par->GetInset(owner->view()->text->cursor.pos));
566 inset->Edit(slx, sly);
569 if (action == LFUN_REDO) {
571 UpdatableInset * inset = owner->buffer()->the_locking_inset;
572 inset->GetCursorPos(slx, sly);
575 inset = static_cast<UpdatableInset*>(owner->view()->text->cursor.par->GetInset(owner->view()->text->cursor.pos));
577 inset->Edit(slx, sly);
580 if (owner->buffer()->the_locking_inset->LocalDispatch(action, argument.c_str()))
583 setMessage(N_("Text mode"));
584 if (action == LFUN_RIGHT || action == -1)
585 owner->view()->text->CursorRight();
586 if (action == LFUN_LEFT || action == LFUN_RIGHT)
593 // --- Misc -------------------------------------------
594 case LFUN_WORDFINDFORWARD :
595 case LFUN_WORDFINDBACKWARD : {
596 static string last_search;
597 string searched_string;
599 if (!argument.empty()) {
600 last_search = argument;
601 searched_string = argument;
603 searched_string = last_search;
606 LyXText * ltCur = owner->view()->text ;
608 if (!searched_string.empty() &&
609 ((action == LFUN_WORDFINDBACKWARD) ?
610 ltCur->SearchBackward(searched_string.c_str()) :
611 ltCur->SearchForward(searched_string.c_str()))) {
613 // ??? What is that ???
614 owner->view()->update(-2);
617 // clear the selection (if there is any)
618 owner->view()->getScreen()->ToggleSelection();
619 owner->view()->text->ClearSelection();
621 // Move cursor so that successive C-s 's will not stand in place.
622 if( action == LFUN_WORDFINDFORWARD )
623 owner->view()->text->CursorRightOneWord();
624 owner->view()->text->FinishUndo();
625 moveCursorUpdate(false);
628 // set the new selection
629 // SetSelectionOverLenChars(owner->view()->currentBuffer()->text, iLenSelected);
630 owner->view()->getScreen()->ToggleSelection(false);
634 // REMOVED : if (owner->view()->getWorkArea()->focus)
635 owner->view()->getScreen()->ShowCursor();
641 if (owner->view()->available()
642 && owner->view()->getScreen()) {
643 owner->view()->update(-2);
646 keyseq.print(buf, 100, true);
647 owner->getMiniBuffer()->Set(buf, string(), string(), 1);
651 // --- Misc -------------------------------------------
652 case LFUN_EXEC_COMMAND:
653 owner->getMiniBuffer()->ExecCommand();
656 case LFUN_CANCEL: // RVDK_PATCH_5
659 if(owner->view()->available())
660 // cancel any selection
661 Dispatch(LFUN_MARK_OFF, 0);
662 setMessage(N_("Cancel"));
665 case LFUN_META_FAKE: // RVDK_PATCH_5
667 meta_fake_bit = Mod1Mask;
669 keyseq.print(buf, 98, true);
670 string res = string("M-") + buf;
671 setMessage(buf); // RVDK_PATCH_5
675 case LFUN_READ_ONLY_TOGGLE:
676 if (owner->buffer()->lyxvc.inUse()) {
677 owner->buffer()->lyxvc.toggleReadOnly();
679 owner->buffer()->setReadonly(
680 !owner->buffer()->isReadonly());
684 case LFUN_CENTER: // this is center and redraw.
686 if (owner->view()->text->cursor.y >
687 owner->view()->getWorkArea()->h / 2) {
688 owner->view()->getScreen()->
689 Draw(owner->view()->text->cursor.y -
690 owner->view()->getWorkArea()->h/2);
692 owner->view()->getScreen()->
695 owner->view()->update(0);
696 owner->view()->redraw();
700 if (owner->view()->available()) {
701 owner->view()->text->toggleAppendix();
702 owner->view()->update(1);
706 // --- Menus -----------------------------------------------
711 case LFUN_MENUNEWTMPLT:
719 case LFUN_CLOSEBUFFER:
724 MenuWrite(owner->buffer());
727 case LFUN_MENUWRITEAS:
728 MenuWriteAs(owner->buffer());
731 case LFUN_MENURELOAD:
736 MenuPreview(owner->buffer());
740 MenuPreviewPS(owner->buffer());
744 MenuRunLaTeX(owner->buffer());
748 MenuBuildProg(owner->buffer());
752 MenuRunChktex(owner->buffer());
756 MenuRunDvips(owner->buffer(), false);
760 MenuPrint(owner->buffer());
764 MenuFax(owner->buffer());
768 MenuExport(owner->buffer(), argument);
773 //needs argument as string
774 string imtyp = argument;
777 if (imtyp == "latex") {
778 doImportLaTeX(false);
781 else if (imtyp == "ascii") {
782 doImportASCII(false);
783 } else if (imtyp == "asciiparagraph") {
786 } else if (imtyp == "noweb") {
789 setErrorMessage(string(N_("Unknown import type: "))
801 if (fd_form_toc->form_toc->visible) {
802 fl_raise_form(fd_form_toc->form_toc);
804 static int ow = -1, oh;
805 fl_show_form(fd_form_toc->form_toc,
807 FL_FREE_SIZE, FL_FULLBORDER,
808 _("Table of Contents"));
810 ow = fd_form_toc->form_toc->w;
811 oh = fd_form_toc->form_toc->h;
813 fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
817 case LFUN_TOC_INSERT:
819 Inset * new_inset = new InsetTOC(owner->buffer());
820 owner->buffer()->insertInset(new_inset, "Standard", true);
824 case LFUN_LOF_INSERT:
826 Inset * new_inset = new InsetLOF(owner->buffer());
827 owner->buffer()->insertInset(new_inset, "Standard", true);
831 case LFUN_LOA_INSERT:
833 Inset * new_inset = new InsetLOA(owner->buffer());
834 owner->buffer()->insertInset(new_inset, "Standard", true);
838 case LFUN_LOT_INSERT:
840 Inset * new_inset = new InsetLOT(owner->buffer());
841 owner->buffer()->insertInset(new_inset, "Standard", true);
865 case LFUN_MENUSEARCH:
873 case LFUN_PASTESELECTION:
876 if (argument == "paragraph") asPara = true;
877 MenuPasteSelection(asPara);
889 case LFUN_LAYOUT_COPY:
893 case LFUN_LAYOUT_PASTE:
894 PasteEnvironmentCB();
898 owner->view()->gotoError();
901 case LFUN_REMOVEERRORS:
902 if (owner->buffer()->removeAutoInsets()) {
903 owner->view()->redraw();
904 owner->view()->fitCursor();
905 owner->view()->updateScrollbar();
917 case LFUN_HYPHENATION:
925 case LFUN_END_OF_SENTENCE:
929 case LFUN_MENU_SEPARATOR:
945 case LFUN_DEPTH_PLUS:
961 case LFUN_RECONFIGURE:
966 if (owner->view()->available()
967 && !owner->view()->text->selection
968 && owner->view()->text->cursor.par->footnoteflag
969 != LyXParagraph::NO_FOOTNOTE)
970 { // only melt footnotes with FOOTMELT, not margins etc
971 if(owner->view()->text->cursor.par->footnotekind == LyXParagraph::FOOTNOTE)
978 case LFUN_MARGINMELT:
979 if (owner->view()->available()
980 && !owner->view()->text->selection
981 && owner->view()->text->cursor.par->footnoteflag
982 != LyXParagraph::NO_FOOTNOTE) {
984 if(owner->view()->text->cursor.par->footnotekind == LyXParagraph::MARGIN)
991 // --- version control -------------------------------
992 case LFUN_VC_REGISTER:
994 if (!owner->buffer()->lyxvc.inUse())
995 owner->buffer()->lyxvc.registrer();
999 case LFUN_VC_CHECKIN:
1001 if (owner->buffer()->lyxvc.inUse()
1002 && !owner->buffer()->isReadonly())
1003 owner->buffer()->lyxvc.checkIn();
1007 case LFUN_VC_CHECKOUT:
1009 if (owner->buffer()->lyxvc.inUse()
1010 && owner->buffer()->isReadonly())
1011 owner->buffer()->lyxvc.checkOut();
1015 case LFUN_VC_REVERT:
1017 owner->buffer()->lyxvc.revert();
1023 owner->buffer()->lyxvc.undoLast();
1027 case LFUN_VC_HISTORY:
1029 owner->buffer()->lyxvc.showLog();
1033 // --- buffers ----------------------------------------
1034 case LFUN_PREVBUFFER:
1035 #ifdef WITH_WARNINGS
1036 #warning fix this please
1038 // it is the LyXView or the BufferView that should
1039 // remember the previous buffer, not bufferlist.
1040 // if (owner->view()->available()){
1042 // owner->buffer()->update(-2);
1044 // owner->view()->setBuffer(bufferlist.prev());
1047 // resizeCurrentBufferPseudoExpose();
1050 case LFUN_FILE_INSERT:
1052 MenuInsertLyXFile(argument);
1056 case LFUN_FILE_INSERT_ASCII:
1058 bool asPara = (argument == "paragraph");
1059 InsertAsciiFile(string(), asPara);
1065 // servercmd: argument must be <file>:<template>
1066 Buffer * tmpbuf = NewLyxFile(argument);
1068 owner->view()->buffer(tmpbuf);
1072 case LFUN_FILE_OPEN:
1073 owner->view()->buffer(
1074 bufferlist.loadLyXFile(argument));
1077 case LFUN_LATEX_LOG:
1083 lyxerr.debug() << "LFUN_LAYOUTNO: (arg) " << argument << endl;
1084 int sel = strToInt(argument);
1085 lyxerr.debug() << "LFUN_LAYOUTNO: (sel) "<< sel << endl;
1087 // Should this give a setMessage instead?
1089 return string(); // illegal argument
1091 sel--; // sel 1..., but layout 0...
1093 // Pretend we got the name instead.
1094 Dispatch(int(LFUN_LAYOUT),
1095 textclasslist.NameOfLayout(owner->view()->
1104 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1105 << argument << endl;
1107 // Derive layout number from given argument (string)
1108 // and current buffer's textclass (number). */
1110 textclasslist.NumberOfLayout(owner->
1116 // see if we found the layout number:
1117 if (layoutno == -1) {
1118 setErrorMessage(string(N_("Layout ")) + argument +
1123 if (current_layout != layoutno) {
1124 owner->view()->getScreen()->HideCursor();
1125 current_layout = layoutno;
1126 owner->view()->update(-2);
1127 owner->view()->text->
1128 SetLayout(layoutno);
1129 owner->getToolbar()->combox->
1130 select(owner->view()->
1133 owner->view()->update(1);
1138 case LFUN_LAYOUT_DOCUMENT:
1139 MenuLayoutDocument();
1142 case LFUN_LAYOUT_PARAGRAPH:
1143 MenuLayoutParagraph();
1146 case LFUN_LAYOUT_CHARACTER:
1147 MenuLayoutCharacter();
1150 case LFUN_LAYOUT_TABLE:
1153 if (argument == "true") flag = 1;
1154 MenuLayoutTable(flag);
1158 case LFUN_LAYOUT_PAPER:
1162 case LFUN_LAYOUT_QUOTES:
1166 case LFUN_LAYOUT_PREAMBLE:
1167 MenuLayoutPreamble();
1170 case LFUN_LAYOUT_SAVE_DEFAULT:
1174 case LFUN_DROP_LAYOUTS_CHOICE:
1175 owner->getToolbar()->combox->Show();
1206 case LFUN_UNDERLINE:
1210 case LFUN_FONT_SIZE:
1211 FontSizeCB(argument);
1214 case LFUN_FONT_STATE:
1215 setMessage(CurrentState());
1218 case LFUN_UPCASE_WORD:
1219 owner->view()->update(-2);
1221 owner->view()->text->ChangeWordCase(LyXText::text_uppercase);
1222 owner->view()->update(1);
1226 case LFUN_LOWCASE_WORD:
1227 owner->view()->update(-2);
1229 owner->view()->text->ChangeWordCase(LyXText::text_lowercase);
1230 owner->view()->update(1);
1234 case LFUN_CAPITALIZE_WORD:
1235 owner->view()->update(-2);
1237 owner->view()->text->ChangeWordCase(LyXText::text_capitalization);
1238 owner->view()->update(1);
1242 case LFUN_INSERT_LABEL:
1243 MenuInsertLabel(argument.c_str());
1246 case LFUN_INSERT_REF:
1250 case LFUN_REFTOGGLE:
1253 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1255 if (inset->getFlag() == InsetRef::REF)
1256 inset->setFlag(InsetRef::PAGE_REF);
1258 inset->setFlag(InsetRef::REF);
1261 setErrorMessage(N_("No cross-reference to toggle"));
1268 owner->view()->restorePosition();
1274 string label(argument);
1275 if (label.empty()) {
1277 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1279 label = inset->getContents();
1282 if (!label.empty()) {
1283 owner->view()->savePosition();
1284 owner->buffer()->gotoLabel(label.c_str());
1289 case LFUN_MENU_OPEN_BY_NAME:
1290 owner->getMenus()->openByName(argument);
1291 break; // RVDK_PATCH_5
1293 case LFUN_SPELLCHECK:
1294 if (lyxrc->isp_command != "none")
1296 break; // RVDK_PATCH_5
1298 // --- Cursor Movements -----------------------------
1301 LyXText * tmptext = owner->view()->text;
1302 if(!tmptext->mark_set)
1304 owner->view()->update(-2);
1305 if (tmptext->cursor.pos < tmptext->cursor.par->Last()
1306 && tmptext->cursor.par->GetChar(tmptext->cursor.pos)
1307 == LyXParagraph::META_INSET
1308 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)
1309 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)->Editable() == 2){
1310 Inset * tmpinset = tmptext->cursor.par->GetInset(tmptext->cursor.pos);
1311 setMessage(tmpinset->EditMessage());
1312 tmpinset->Edit(0, 0);
1315 tmptext->CursorRight();
1316 owner->view()->text->FinishUndo();
1317 moveCursorUpdate(false);
1318 owner->getMiniBuffer()->Set(CurrentState());
1324 // This is soooo ugly. Isn`t it possible to make
1325 // it simpler? (Lgb)
1326 LyXText * txt = owner->view()->text;
1327 if(!txt->mark_set) BeforeChange();
1328 owner->view()->update(-2);
1330 if (txt->cursor.pos < txt->cursor.par->Last()
1331 && txt->cursor.par->GetChar(txt->cursor.pos)
1332 == LyXParagraph::META_INSET
1333 && txt->cursor.par->GetInset(txt->cursor.pos)
1334 && txt->cursor.par->GetInset(txt->cursor.pos)->Editable() == 2) {
1335 Inset * tmpinset = txt->cursor.par->GetInset(txt->cursor.pos);
1336 setMessage(tmpinset->EditMessage());
1337 tmpinset->Edit(tmpinset->Width(txt->GetFont(txt->cursor.par,
1338 txt->cursor.pos)), 0);
1341 owner->view()->text->FinishUndo();
1342 moveCursorUpdate(false);
1343 owner->getMiniBuffer()->Set(CurrentState());
1348 if(!owner->view()->text->mark_set) BeforeChange();
1349 owner->view()->update(-3);
1350 owner->view()->text->CursorUp();
1351 owner->view()->text->FinishUndo();
1352 moveCursorUpdate(false);
1353 owner->getMiniBuffer()->Set(CurrentState());
1357 if(!owner->view()->text->mark_set)
1359 owner->view()->update(-3);
1360 owner->view()->text->CursorDown();
1361 owner->view()->text->FinishUndo();
1362 moveCursorUpdate(false);
1363 owner->getMiniBuffer()->Set(CurrentState());
1366 case LFUN_UP_PARAGRAPH:
1367 if(!owner->view()->text->mark_set)
1369 owner->view()->update(-3);
1370 owner->view()->text->CursorUpParagraph();
1371 owner->view()->text->FinishUndo();
1372 moveCursorUpdate(false);
1373 owner->getMiniBuffer()->Set(CurrentState());
1376 case LFUN_DOWN_PARAGRAPH:
1377 if(!owner->view()->text->mark_set)
1379 owner->view()->update(-3);
1380 owner->view()->text->CursorDownParagraph();
1381 owner->view()->text->FinishUndo();
1382 moveCursorUpdate(false);
1383 owner->getMiniBuffer()->Set(CurrentState());
1387 if(!owner->view()->text->mark_set)
1389 owner->view()->update(-3);
1390 owner->view()->cursorPrevious();
1391 owner->view()->text->FinishUndo();
1392 moveCursorUpdate(false);
1393 owner->getMiniBuffer()->Set(CurrentState());
1397 if(!owner->view()->text->mark_set)
1399 owner->view()->update(-3);
1400 owner->view()->cursorNext();
1401 owner->view()->text->FinishUndo();
1402 moveCursorUpdate(false);
1403 owner->getMiniBuffer()->Set(CurrentState());
1407 if(!owner->view()->text->mark_set)
1409 owner->view()->update(-2);
1410 owner->view()->text->CursorHome();
1411 owner->view()->text->FinishUndo();
1412 moveCursorUpdate(false);
1413 owner->getMiniBuffer()->Set(CurrentState());
1417 if(!owner->view()->text->mark_set)
1419 owner->view()->update(-2);
1420 owner->view()->text->CursorEnd();
1421 owner->view()->text->FinishUndo();
1422 moveCursorUpdate(false);
1423 owner->getMiniBuffer()->Set(CurrentState());
1427 if(!owner->view()->text->mark_set)
1429 owner->view()->update(-2);
1430 owner->view()->text->CursorTab();
1431 owner->view()->text->FinishUndo();
1432 moveCursorUpdate(false);
1433 owner->getMiniBuffer()->Set(CurrentState());
1436 case LFUN_WORDRIGHT:
1437 if(!owner->view()->text->mark_set)
1439 owner->view()->update(-2);
1440 owner->view()->text->CursorRightOneWord();
1441 owner->view()->text->FinishUndo();
1442 moveCursorUpdate(false);
1443 owner->getMiniBuffer()->Set(CurrentState());
1447 if(!owner->view()->text->mark_set)
1449 owner->view()->update(-2);
1450 owner->view()->text->CursorLeftOneWord();
1451 owner->view()->text->FinishUndo();
1452 moveCursorUpdate(false);
1453 owner->getMiniBuffer()->Set(CurrentState());
1456 case LFUN_BEGINNINGBUF:
1457 if(!owner->view()->text->mark_set)
1459 owner->view()->update(-2);
1460 owner->view()->text->CursorTop();
1461 owner->view()->text->FinishUndo();
1462 moveCursorUpdate(false);
1463 owner->getMiniBuffer()->Set(CurrentState());
1467 if(!owner->view()->text->mark_set)
1469 owner->view()->update(-2);
1470 owner->view()->text->CursorBottom();
1471 owner->view()->text->FinishUndo();
1472 moveCursorUpdate(false);
1473 owner->getMiniBuffer()->Set(CurrentState());
1477 /* cursor selection ---------------------------- */
1479 owner->view()->update(-2);
1480 owner->view()->text->CursorRight();
1481 owner->view()->text->FinishUndo();
1482 moveCursorUpdate(true);
1483 owner->getMiniBuffer()->Set(CurrentState());
1487 owner->view()->update(-2);
1488 owner->view()->text->CursorLeft();
1489 owner->view()->text->FinishUndo();
1490 moveCursorUpdate(true);
1491 owner->getMiniBuffer()->Set(CurrentState());
1495 owner->view()->update(-2);
1496 owner->view()->text->CursorUp();
1497 owner->view()->text->FinishUndo();
1498 moveCursorUpdate(true);
1499 owner->getMiniBuffer()->Set(CurrentState());
1503 owner->view()->update(-2);
1504 owner->view()->text->CursorDown();
1505 owner->view()->text->FinishUndo();
1506 moveCursorUpdate(true);
1507 owner->getMiniBuffer()->Set(CurrentState());
1510 case LFUN_UP_PARAGRAPHSEL:
1511 owner->view()->update(-2);
1512 owner->view()->text->CursorUpParagraph();
1513 owner->view()->text->FinishUndo();
1514 moveCursorUpdate(true);
1515 owner->getMiniBuffer()->Set(CurrentState());
1518 case LFUN_DOWN_PARAGRAPHSEL:
1519 owner->view()->update(-2);
1520 owner->view()->text->CursorDownParagraph();
1521 owner->view()->text->FinishUndo();
1522 moveCursorUpdate(true);
1523 owner->getMiniBuffer()->Set(CurrentState());
1527 owner->view()->update(-2);
1528 owner->view()->cursorPrevious();
1529 owner->view()->text->FinishUndo();
1530 moveCursorUpdate(true);
1531 owner->getMiniBuffer()->Set(CurrentState());
1535 owner->view()->update(-2);
1536 owner->view()->cursorNext();
1537 owner->view()->text->FinishUndo();
1538 moveCursorUpdate(true);
1539 owner->getMiniBuffer()->Set(CurrentState());
1543 owner->view()->update(-2);
1544 owner->view()->text->CursorHome();
1545 owner->view()->text->FinishUndo();
1546 moveCursorUpdate(true);
1547 owner->getMiniBuffer()->Set(CurrentState());
1551 owner->view()->update(-2);
1552 owner->view()->text->CursorEnd();
1553 owner->view()->text->FinishUndo();
1554 moveCursorUpdate(true);
1555 owner->getMiniBuffer()->Set(CurrentState());
1558 case LFUN_WORDRIGHTSEL:
1559 owner->view()->update(-2);
1560 owner->view()->text->CursorRightOneWord();
1561 owner->view()->text->FinishUndo();
1562 moveCursorUpdate(true);
1563 owner->getMiniBuffer()->Set(CurrentState());
1566 case LFUN_WORDLEFTSEL:
1567 owner->view()->update(-2);
1568 owner->view()->text->CursorLeftOneWord();
1569 owner->view()->text->FinishUndo();
1570 moveCursorUpdate(true);
1571 owner->getMiniBuffer()->Set(CurrentState());
1574 case LFUN_BEGINNINGBUFSEL:
1575 owner->view()->update(-2);
1576 owner->view()->text->CursorTop();
1577 owner->view()->text->FinishUndo();
1578 moveCursorUpdate(true);
1579 owner->getMiniBuffer()->Set(CurrentState());
1582 case LFUN_ENDBUFSEL:
1583 owner->view()->update(-2);
1584 owner->view()->text->CursorBottom();
1585 owner->view()->text->FinishUndo();
1586 moveCursorUpdate(true);
1587 owner->getMiniBuffer()->Set(CurrentState());
1590 // --- text changing commands ------------------------
1591 case LFUN_BREAKLINE:
1593 owner->view()->text->InsertChar(LyXParagraph::META_NEWLINE);
1595 SetUpdateTimer(0.01);
1596 moveCursorUpdate(false);
1599 case LFUN_PROTECTEDSPACE:
1601 owner->view()->text->
1602 InsertChar(LyXParagraph::META_PROTECTED_SEPARATOR);
1605 moveCursorUpdate(false);
1609 if(owner->view()->text->mark_set) {
1611 owner->view()->update(0);
1612 setMessage(N_("Mark removed"));
1615 owner->view()->text->mark_set = 1;
1616 owner->view()->update(0);
1617 setMessage(N_("Mark set"));
1619 owner->view()->text->sel_cursor =
1620 owner->view()->text->cursor;
1625 if (!owner->view()->text->selection) {
1626 owner->view()->text->Delete();
1627 owner->view()->text->sel_cursor =
1628 owner->view()->text->cursor;
1630 // It is possible to make it a lot faster still
1631 // just comment out the lone below...
1632 owner->view()->getScreen()->ShowCursor();
1639 case LFUN_DELETE_SKIP:
1641 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1643 LyXCursor cursor = owner->view()->text->cursor;
1646 if (!owner->view()->text->selection) {
1647 if (cursor.pos == cursor.par->Last()) {
1648 owner->view()->text->CursorRight();
1649 cursor = owner->view()->text->cursor;
1651 && !(cursor.par->added_space_top
1652 == VSpace (VSpace::NONE))) {
1653 owner->view()->text->SetParagraph
1654 (cursor.par->line_top,
1655 cursor.par->line_bottom,
1656 cursor.par->pagebreak_top,
1657 cursor.par->pagebreak_bottom,
1658 VSpace(VSpace::NONE),
1659 cursor.par->added_space_bottom,
1661 cursor.par->labelwidthstring, 0);
1662 owner->view()->text->CursorLeft();
1663 owner->view()->update (1);
1665 owner->view()->text->CursorLeft();
1666 owner->view()->text->Delete();
1667 owner->view()->text->sel_cursor =
1668 owner->view()->text->cursor;
1672 owner->view()->text->Delete();
1673 owner->view()->text->sel_cursor =
1674 owner->view()->text->cursor;
1684 /* -------> Delete word forward. */
1685 case LFUN_DELETE_WORD_FORWARD:
1686 owner->view()->update(-2);
1688 owner->view()->text->DeleteWordForward();
1689 owner->view()->update( 1 );
1691 moveCursorUpdate(false);
1694 /* -------> Delete word backward. */
1695 case LFUN_DELETE_WORD_BACKWARD:
1696 owner->view()->update(-2);
1698 owner->view()->text->DeleteWordBackward();
1699 owner->view()->update( 1 );
1701 moveCursorUpdate(false);
1704 /* -------> Kill to end of line. */
1705 case LFUN_DELETE_LINE_FORWARD:
1707 owner->view()->update(-2);
1708 owner->view()->text->DeleteLineForward();
1709 owner->view()->update( 1 );
1711 moveCursorUpdate(false);
1714 /* -------> Set mark off. */
1717 owner->view()->update(0);
1718 owner->view()->text->sel_cursor =
1719 owner->view()->text->cursor;
1720 setMessage(N_("Mark off"));
1723 /* -------> Set mark on. */
1726 owner->view()->text->mark_set = 1;
1727 owner->view()->update( 0 );
1728 owner->view()->text->sel_cursor =
1729 owner->view()->text->cursor;
1730 setMessage(N_("Mark on"));
1733 case LFUN_BACKSPACE:
1736 if (!owner->view()->text->selection) {
1737 if (owner->getIntl()->getTrans()->backspace()) {
1738 owner->view()->text->Backspace();
1739 owner->view()->text->sel_cursor =
1740 owner->view()->text->cursor;
1742 // It is possible to make it a lot faster still
1743 // just comment out the lone below...
1744 owner->view()->getScreen()->ShowCursor();
1753 case LFUN_BACKSPACE_SKIP:
1755 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1757 LyXCursor cursor = owner->view()->text->cursor;
1760 if (!owner->view()->text->selection) {
1762 && !(cursor.par->added_space_top
1763 == VSpace (VSpace::NONE))) {
1764 owner->view()->text->SetParagraph
1765 (cursor.par->line_top,
1766 cursor.par->line_bottom,
1767 cursor.par->pagebreak_top,
1768 cursor.par->pagebreak_bottom,
1769 VSpace(VSpace::NONE), cursor.par->added_space_bottom,
1771 cursor.par->labelwidthstring, 0);
1772 owner->view()->update (1);
1774 owner->view()->text->Backspace();
1775 owner->view()->text->sel_cursor
1785 case LFUN_BREAKPARAGRAPH:
1788 owner->view()->text->BreakParagraph(0);
1790 SetUpdateTimer(0.01);
1791 owner->view()->text->sel_cursor =
1792 owner->view()->text->cursor;
1796 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1799 owner->view()->text->BreakParagraph(1);
1801 SetUpdateTimer(0.01);
1802 owner->view()->text->sel_cursor =
1803 owner->view()->text->cursor;
1807 case LFUN_BREAKPARAGRAPH_SKIP:
1809 // When at the beginning of a paragraph, remove
1810 // indentation and add a "defskip" at the top.
1811 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
1813 LyXCursor cursor = owner->view()->text->cursor;
1816 if (cursor.pos == 0) {
1817 if (cursor.par->added_space_top == VSpace(VSpace::NONE)) {
1818 owner->view()->text->SetParagraph
1819 (cursor.par->line_top,
1820 cursor.par->line_bottom,
1821 cursor.par->pagebreak_top,
1822 cursor.par->pagebreak_bottom,
1823 VSpace(VSpace::DEFSKIP), cursor.par->added_space_bottom,
1825 cursor.par->labelwidthstring, 1);
1826 owner->view()->update(1);
1830 owner->view()->text->BreakParagraph(0);
1833 SetUpdateTimer(0.01);
1834 owner->view()->text->sel_cursor = cursor;
1840 owner->view()->text->InsertChar('\"'); // This " matches the single quote in the code
1843 moveCursorUpdate(false);
1849 InsetCommand * new_inset;
1850 if (action == LFUN_HTMLURL)
1851 new_inset = new InsetUrl("htmlurl", "", "");
1853 new_inset = new InsetUrl("url", "", "");
1854 owner->buffer()->insertInset(new_inset);
1855 new_inset->Edit(0, 0);
1859 // --- lyxserver commands ----------------------------
1861 case LFUN_CHARATCURSOR:
1863 LyXParagraph::size_type pos =
1864 owner->view()->text->cursor.pos;
1865 if(pos < owner->view()->text->cursor.par->size())
1866 dispatch_buffer = owner->view()->text->
1867 cursor.par->text[pos];
1869 dispatch_buffer = "EOF";
1875 tostr(owner->view()->text->cursor.x) + ' '
1876 + tostr(owner->view()->text->cursor.y);
1883 sscanf(argument.c_str(), " %d %ld", &x, &y);
1884 owner->view()->text->SetCursorFromCoordinates(x, y);
1888 case LFUN_GETLAYOUT:
1890 tostr(owner->view()->text->cursor.par->layout);
1895 LyXFont *font = &(owner->view()->text->current_font);
1896 if(font->shape() == LyXFont::ITALIC_SHAPE)
1897 dispatch_buffer = 'E';
1898 else if(font->shape() == LyXFont::SMALLCAPS_SHAPE)
1899 dispatch_buffer = 'N';
1901 dispatch_buffer = '0';
1908 LyXFont *font = &(owner->view()->text->current_font);
1909 if(font->latex() == LyXFont::ON)
1910 dispatch_buffer = 'L';
1912 dispatch_buffer = '0';
1917 setMessage(owner->buffer()->fileName());
1918 lyxerr.debug() << "FNAME["
1919 << owner->buffer()->fileName()
1926 keyseq.print(buf, 100);
1927 dispatch_buffer = buf;
1928 lyxserver->notifyClient(dispatch_buffer);
1932 case LFUN_GOTOFILEROW:
1934 char file_name[100];
1936 sscanf(argument.c_str(), " %s %d", file_name, &row);
1938 // Must replace extension of the file to be .lyx and get full path
1939 string s = ChangeExtension(string(file_name), ".lyx", false);
1941 // Either change buffer or load the file
1942 if (bufferlist.exists(s))
1943 owner->view()->buffer(bufferlist.getBuffer(s));
1945 owner->view()->buffer(bufferlist.loadLyXFile(s));
1948 owner->buffer()->setCursorFromRow(row);
1952 if (owner->view()->text->cursor.y >
1953 owner->view()->getWorkArea()->h / 2) {
1954 owner->view()->getScreen()->
1955 Draw(owner->view()->text->cursor.y -
1956 owner->view()->getWorkArea()->h/2);
1958 owner->view()->getScreen()->
1961 owner->view()->update(0);
1962 owner->view()->redraw();
1969 int qa = lyxaction.LookupFunc(argument.c_str());
1970 setMessage(lyxaction.helpText(static_cast<kb_action>(qa)));
1974 // --- accented characters ---------------------------
1977 case LFUN_CIRCUMFLEX:
1987 case LFUN_SPECIAL_CARON:
1990 case LFUN_HUNG_UMLAUT:
1996 if (keyseq.length == -1 && keyseq.getiso()!= 0)
2001 owner->getIntl()->getTrans()->
2002 deadkey(c, get_accent(action).accent,
2003 owner->view()->text);
2005 // Need to reset, in case the minibuffer calls these
2010 // copied verbatim from do_accent_char
2013 owner->view()->text->sel_cursor =
2014 owner->view()->text->cursor;
2018 // --- toolbar ----------------------------------
2019 case LFUN_PUSH_TOOLBAR:
2021 int nth = strToInt(argument);
2022 if (lyxerr.debugging(Debug::TOOLBAR)) {
2023 lyxerr << "LFUN_PUSH_TOOLBAR: argument = `"
2024 << argument << "'\n"
2025 << "LFUN_PUSH_TOOLBAR: nth = `"
2026 << nth << "'" << endl;
2031 setErrorMessage(N_("Push-toolbar needs argument > 0"));
2033 owner->getToolbar()->push(nth);
2038 case LFUN_ADD_TO_TOOLBAR:
2040 if (lyxerr.debugging(Debug::TOOLBAR)) {
2041 lyxerr << "LFUN_ADD_TO_TOOLBAR:"
2042 "argument = `" << argument << '\'' << endl;
2044 string tmp(argument);
2045 //lyxerr <<string("Argument: ") + argument);
2046 //lyxerr <<string("Tmp : ") + tmp);
2049 setErrorMessage(N_("Usage: toolbar-add-to <LyX command>"));
2051 owner->getToolbar()->add(argument, false);
2052 owner->getToolbar()->set();
2057 // --- insert characters ----------------------------------------
2059 case LFUN_INSERT_INSET_LATEX:
2061 Inset *new_inset = new InsetLatex(argument);
2062 owner->buffer()->insertInset(new_inset);
2066 // --- Mathed stuff. If we are here, there is no locked inset yet.
2071 if (!greek_kb_flag) {
2073 setMessage(N_("Math greek mode on"));
2080 case LFUN_GREEK_TOGGLE:
2082 greek_kb_flag = (greek_kb_flag) ? 0: 2;
2083 if (greek_kb_flag) {
2084 setMessage(N_("Math greek keyboard on"));
2086 setMessage(N_("Math greek keyboard off"));
2091 case LFUN_MATH_DELIM:
2092 case LFUN_INSERT_MATRIX:
2094 if (owner->view()->available()) {
2096 open_new_inset(new InsetFormula(false));
2098 the_locking_inset->LocalDispatch(action, argument.c_str());
2103 case LFUN_INSERT_MATH:
2105 math_insert_symbol(argument.c_str());
2109 case LFUN_MATH_DISPLAY:
2111 if (owner->view()->available())
2112 owner->buffer()->open_new_inset(new InsetFormula(true));
2116 case LFUN_MATH_MACRO:
2118 if (owner->view()->available()) {
2121 setErrorMessage(N_("Missing argument"));
2123 string s1 = token(s, ' ', 1);
2124 int na = s1.empty() ? 0: atoi(s1.c_str());
2126 open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2132 case LFUN_MATH_MODE: // Open or create a math inset
2135 if (owner->view()->available())
2136 owner->buffer()->open_new_inset(new InsetFormula);
2137 setMessage(N_("Math editor mode"));
2141 case LFUN_MATH_NUMBER:
2142 case LFUN_MATH_LIMITS:
2144 setErrorMessage(N_("This is only allowed in math mode!"));
2148 case LFUN_INSERT_CITATION:
2150 InsetCitation * new_inset = new InsetCitation();
2152 // The note, if any, must be after the key, delimited
2153 // by a | so both key and remark can have spaces.
2154 if (!argument.empty()) {
2155 string lsarg(argument);
2156 if (contains(lsarg, "|")) {
2157 new_inset->setContents(token(lsarg, '|', 0));
2158 new_inset->setOptions(token(lsarg, '|', 1));
2160 new_inset->setContents(lsarg);
2161 owner->buffer()->insertInset(new_inset);
2163 owner->buffer()->insertInset(new_inset);
2164 new_inset->Edit(0, 0);
2169 case LFUN_INSERT_BIBTEX:
2171 // ale970405+lasgoutt970425
2172 // The argument can be up to two tokens separated
2173 // by a space. The first one is the bibstyle.
2174 string lsarg(argument);
2175 string bibstyle = token(lsarg, ' ', 1);
2176 if (bibstyle.empty())
2178 InsetBibtex * new_inset
2179 = new InsetBibtex(token(lsarg, ' ', 0),
2183 owner->buffer()->insertInset(new_inset);
2184 if (lsarg.empty()) {
2185 new_inset->Edit(0, 0);
2190 // BibTeX data bases
2191 case LFUN_BIBDB_ADD:
2193 InsetBibtex * inset =
2194 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2196 inset->addDatabase(argument);
2201 case LFUN_BIBDB_DEL:
2203 InsetBibtex * inset =
2204 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2206 inset->delDatabase(argument);
2211 case LFUN_BIBTEX_STYLE:
2213 InsetBibtex * inset =
2214 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2216 inset->setOptions(argument);
2221 case LFUN_INDEX_INSERT:
2222 case LFUN_INDEX_INSERT_LAST:
2224 // Can't do that at the beginning of a paragraph.
2225 if (owner->view()->text->cursor.pos - 1 <0)
2228 InsetIndex * new_inset = new InsetIndex();
2229 if (!argument.empty()) {
2230 string lsarg(argument);
2231 new_inset->setContents(lsarg);
2232 owner->buffer()->insertInset(new_inset);
2235 //get the current word for an argument
2236 LyXParagraph::size_type lastpos =
2237 owner->view()->text->cursor.pos - 1;
2238 // Get the current word. note that this must be done
2239 // before inserting the inset, or the inset will
2241 string curstring(owner->view()
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->view()->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,
2288 owner->buffer()->insertInset(new_inset, "Standard", true);
2289 new_inset->Edit(0, 0);
2293 case LFUN_CHILDOPEN:
2296 MakeAbsPath(argument,
2297 OnlyPath(owner->buffer()->fileName()));
2298 setMessage(N_("Opening child document ") +
2299 MakeDisplayPath(filename) + "...");
2300 owner->view()->savePosition();
2301 if (bufferlist.exists(filename))
2302 owner->view()->buffer(bufferlist.getBuffer(filename));
2304 owner->view()->buffer(bufferlist.loadLyXFile(filename));
2308 case LFUN_INSERT_NOTE:
2312 case LFUN_INSERTFOOTNOTE:
2314 LyXParagraph::footnote_kind kind;
2315 if (argument == "footnote")
2316 { kind = LyXParagraph::FOOTNOTE; }
2317 else if (argument == "margin")
2318 { kind = LyXParagraph::MARGIN; }
2319 else if (argument == "figure")
2320 { kind = LyXParagraph::FIG; }
2321 else if (argument == "table")
2322 { kind = LyXParagraph::TAB; }
2323 else if (argument == "wide-fig")
2324 { kind = LyXParagraph::WIDE_FIG; }
2325 else if (argument == "wide-tab")
2326 { kind = LyXParagraph::WIDE_TAB; }
2327 else if (argument == "algorithm")
2328 { kind = LyXParagraph::ALGORITHM; }
2330 setErrorMessage(N_("Unknown kind of footnote"));
2333 owner->view()->text->InsertFootnoteEnvironment(kind);
2334 owner->view()->update(1);
2338 case LFUN_BUFFERBULLETSSELECT:
2342 case LFUN_TOGGLECURSORFOLLOW:
2343 cursor_follows_scrollbar = !cursor_follows_scrollbar;
2346 case LFUN_KMAP_OFF: // keymap off
2347 owner->getIntl()->KeyMapOn(false);
2350 case LFUN_KMAP_PRIM: // primary keymap
2351 owner->getIntl()->KeyMapPrim();
2354 case LFUN_KMAP_SEC: // secondary keymap
2355 owner->getIntl()->KeyMapSec();
2358 case LFUN_KMAP_TOGGLE: // toggle keymap
2359 owner->getIntl()->ToggleKeyMap();
2362 case LFUN_SELFINSERT:
2364 for (string::size_type i = 0; i < argument.length(); ++i) {
2365 owner->view()->text->InsertChar(argument[i]);
2366 // This needs to be in the loop, or else we
2367 // won't break lines correctly. (Asger)
2371 owner->view()->text->sel_cursor =
2372 owner->view()->text->cursor;
2373 moveCursorUpdate(false);
2379 // argument contains ';'-terminated commands
2380 while (argument.find(';') != string::npos) {
2382 argument = split(argument, first, ';');
2388 case LFUN_SAVEPREFERENCES:
2390 Path p(user_lyxdir);
2391 lyxrc->write("preferences");
2395 case LFUN_UNKNOWN_ACTION:
2397 if (owner->buffer()->isReadonly()) {
2399 setErrorMessage(N_("Document is read only"));
2403 if (!argument.empty()) {
2405 /* Automatically delete the currently selected
2406 * text and replace it with what is being
2407 * typed in now. Depends on lyxrc settings
2408 * "auto_region_delete", which defaults to
2411 if ( lyxrc->auto_region_delete ) {
2412 if (owner->view()->text->selection){
2413 owner->view()->text->CutSelection(false);
2414 owner->view()->update(-1);
2419 for (string::size_type i = 0;
2420 i < argument.length(); ++i) {
2421 if (greek_kb_flag) {
2422 if (!math_insert_greek(argument[i]))
2423 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2425 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2431 owner->view()->text->sel_cursor =
2432 owner->view()->text->cursor;
2433 moveCursorUpdate(false);
2436 // why is an "Unknown action" with empty
2437 // argument even dispatched in the first
2438 // place? I`ll probably change that. (Lgb)
2440 setErrorMessage(N_("Unknown action"));
2444 lyxerr << "A truly unknown func!" << endl;
2450 string res = getMessage();
2453 if (!commandshortcut.empty()) {
2454 string newbuf = owner->getMiniBuffer()->GetText();
2455 if (newbuf != commandshortcut) {
2456 owner->getMiniBuffer()->Set(newbuf
2462 owner->getMiniBuffer()->Set(string(_(res.c_str()))
2463 + " " + commandshortcut);
2469 string LyXFunc::Dispatch(int ac,
2470 char const * do_not_use_this_arg)
2475 FL_OBJECT * ob = 0; // This will disapear soon
2477 // we have not done anything wrong yet.
2479 dispatch_buffer.clear();
2481 // if action is a pseudo-action, we need the real action
2482 if (lyxaction.isPseudoAction(ac)) {
2484 action = static_cast<kb_action>
2485 (lyxaction.retrieveActionArg(ac, tmparg));
2486 if (!tmparg.empty())
2489 action = static_cast<kb_action>(ac);
2490 if (do_not_use_this_arg)
2491 argument = do_not_use_this_arg; // except here
2494 selection_possible = false;
2496 if (owner->view()->available()
2497 && owner->view()->getScreen())
2498 owner->view()->getScreen()->HideCursor();
2500 // We cannot use this function here
2501 if (getStatus(action) & Disabled)
2502 goto exit_with_message;
2504 commandshortcut.clear();
2506 if (lyxrc->display_shortcuts && show_sc) {
2507 if (action != LFUN_SELFINSERT) {
2508 // Put name of command and list of shortcuts
2509 // for it in minibuffer
2510 string comname = lyxaction.getActionName(action);
2512 int pseudoaction = action;
2513 bool argsadded = false;
2515 if (!argument.empty()) {
2516 // If we have the command with argument,
2519 lyxaction.searchActionArg(action,
2522 if (pseudoaction == -1) {
2523 pseudoaction = action;
2525 comname += " " + argument;
2530 string shortcuts = toplevel_keymap->findbinding(pseudoaction);
2532 if (!shortcuts.empty()) {
2533 comname += ": " + shortcuts;
2534 } else if (!argsadded) {
2535 comname += " " + argument;
2538 if (!comname.empty()) {
2539 comname = strip(comname);
2540 commandshortcut = "(" + comname + ')';
2541 owner->getMiniBuffer()->Set(commandshortcut);
2542 // Here we could even add a small pause,
2543 // to annoy the user and make him learn
2545 // No! That will just annoy, not teach
2546 // anything. The user will read the messages
2547 // if they are interested. (Asger)
2552 // If in math mode pass the control to
2553 // the math inset [asierra060396]
2554 if (owner->view()->available() &&
2555 owner->buffer()->the_locking_inset) {
2557 || (action == LFUN_UNKNOWN_ACTION && keyseq.length>= -1)) {
2558 if (action == LFUN_UNKNOWN_ACTION && argument.empty()) {
2559 argument = keyseq.getiso();
2561 // Undo/Redo pre 0.13 is a bit tricky for insets.
2562 if (action == LFUN_UNDO) {
2564 UpdatableInset * inset =
2565 owner->buffer()->the_locking_inset;
2566 inset->GetCursorPos(slx, sly);
2569 inset = static_cast<UpdatableInset*>(owner->buffer()->text->cursor.par->GetInset(owner->buffer()->text->cursor.pos));
2571 inset->Edit(slx, sly);
2574 if (action == LFUN_REDO) {
2576 UpdatableInset * inset = owner->buffer()->the_locking_inset;
2577 inset->GetCursorPos(slx, sly);
2580 inset = static_cast<UpdatableInset*>(owner->buffer()->text->cursor.par->GetInset(owner->buffer()->text->cursor.pos));
2582 inset->Edit(slx, sly);
2585 if (owner->buffer()->the_locking_inset->LocalDispatch(action, argument.c_str()))
2588 setMessage(N_("Text mode"));
2589 if (action == LFUN_RIGHT || action == -1)
2590 owner->buffer()->text->CursorRight();
2591 if (action == LFUN_LEFT || action == LFUN_RIGHT)
2598 // --- Misc -------------------------------------------
2599 case LFUN_WORDFINDFORWARD :
2600 case LFUN_WORDFINDBACKWARD : {
2601 static string last_search;
2602 string searched_string;
2604 if (!argument.empty()) {
2605 last_search = argument;
2606 searched_string = argument;
2608 searched_string = last_search;
2611 LyXText * ltCur = owner->view()->buffer()->text ;
2613 if (!searched_string.empty() &&
2614 ((action == LFUN_WORDFINDBACKWARD) ?
2615 ltCur->SearchBackward(searched_string.c_str()) :
2616 ltCur->SearchForward(searched_string.c_str()))) {
2618 // ??? What is that ???
2619 owner->view()->buffer()->update(-2);
2622 // clear the selection (if there is any)
2623 owner->view()->getScreen()->ToggleSelection();
2624 owner->view()->buffer()->text->ClearSelection();
2626 // Move cursor so that successive C-s 's will not stand in place.
2627 if( action == LFUN_WORDFINDFORWARD )
2628 owner->buffer()->text->CursorRightOneWord();
2629 owner->buffer()->text->FinishUndo();
2630 moveCursorUpdate(false);
2633 // set the new selection
2634 // SetSelectionOverLenChars(owner->view()->currentBuffer()->text, iLenSelected);
2635 owner->view()->getScreen()->ToggleSelection(false);
2639 // REMOVED : if (owner->view()->getWorkArea()->focus)
2640 owner->view()->getScreen()->ShowCursor();
2646 if (owner->view()->available()
2647 && owner->view()->getScreen()) {
2648 owner->buffer()->update(-2);
2651 keyseq.print(buf, 100, true);
2652 owner->getMiniBuffer()->Set(buf, string(), string(), 1);
2656 // --- Misc -------------------------------------------
2657 case LFUN_EXEC_COMMAND:
2658 owner->getMiniBuffer()->ExecCommand();
2661 case LFUN_CANCEL: // RVDK_PATCH_5
2664 if(owner->view()->available())
2665 // cancel any selection
2666 Dispatch(LFUN_MARK_OFF, 0);
2667 setMessage(N_("Cancel"));
2670 case LFUN_META_FAKE: // RVDK_PATCH_5
2672 meta_fake_bit = Mod1Mask;
2674 keyseq.print(buf, 98, true);
2675 string res = string("M-") + buf;
2676 setMessage(buf); // RVDK_PATCH_5
2680 case LFUN_READ_ONLY_TOGGLE:
2681 if (owner->buffer()->lyxvc.inUse()) {
2682 owner->buffer()->lyxvc.toggleReadOnly();
2684 owner->buffer()->setReadonly(
2685 !owner->buffer()->isReadonly());
2689 case LFUN_CENTER: // this is center and redraw.
2691 if (owner->buffer()->text->cursor.y >
2692 owner->view()->getWorkArea()->h / 2) {
2693 owner->view()->getScreen()->
2694 Draw(owner->buffer()->text->cursor.y -
2695 owner->view()->getWorkArea()->h/2);
2697 owner->view()->getScreen()->
2700 owner->buffer()->update(0);
2701 owner->view()->redraw();
2705 if (owner->view()->available()) {
2706 owner->buffer()->text->toggleAppendix();
2707 owner->buffer()->update(1);
2711 // --- Menus -----------------------------------------------
2716 case LFUN_MENUNEWTMPLT:
2724 case LFUN_CLOSEBUFFER:
2728 case LFUN_MENUWRITE:
2729 MenuWrite(owner->buffer());
2732 case LFUN_MENUWRITEAS:
2733 MenuWriteAs(owner->buffer());
2736 case LFUN_MENURELOAD:
2741 MenuPreview(owner->buffer());
2744 case LFUN_PREVIEWPS:
2745 MenuPreviewPS(owner->buffer());
2749 MenuRunLaTeX(owner->buffer());
2752 case LFUN_BUILDPROG:
2753 MenuBuildProg(owner->buffer());
2756 case LFUN_RUNCHKTEX:
2757 MenuRunChktex(owner->buffer());
2761 MenuRunDvips(owner->buffer(), false);
2764 case LFUN_MENUPRINT:
2765 MenuPrint(owner->buffer());
2769 MenuFax(owner->buffer());
2774 //needs argument as string
2775 string extyp = argument;
2778 if (extyp == "latex") {
2779 // make sure that this buffer is not linuxdoc
2780 MenuMakeLaTeX(owner->buffer());
2783 else if (extyp == "linuxdoc") {
2784 // make sure that this buffer is not latex
2785 MenuMakeLinuxDoc(owner->buffer());
2788 else if (extyp == "docbook") {
2789 // make sure that this buffer is not latex or linuxdoc
2790 MenuMakeDocBook(owner->buffer());
2793 else if (extyp == "dvi") {
2794 // Run LaTeX as "Update dvi..." Bernhard.
2795 // We want the dvi in the current directory. This
2796 // is achieved by temporarily disabling use of
2797 // temp directory. As a side-effect, we get
2798 // *.log and *.aux files also. (Asger)
2799 bool flag = lyxrc->use_tempdir;
2800 lyxrc->use_tempdir = false;
2801 MenuRunLaTeX(owner->buffer());
2802 lyxrc->use_tempdir = flag;
2805 else if (extyp == "postscript") {
2806 // Start Print-dialog. Not as good as dvi... Bernhard.
2807 MenuPrint(owner->buffer());
2808 // Since the MenuPrint is a pop-up, we can't use
2809 // the same trick as above. (Asger)
2810 // MISSING: Move of ps-file :-(
2813 else if (extyp == "ascii") {
2814 MenuMakeAscii(owner->buffer());
2816 else if (extyp == "custom") {
2821 else if (extyp == "html" && lyxrc->html_command != "none") {
2822 // First, create LaTeX file
2823 MenuMakeLaTeX(owner->buffer());
2825 // And now, run the converter
2826 string file = owner->buffer()->getFileName();
2827 Path path(OnlyPath(file));
2828 // the tex file name has to be correct for
2829 // latex, but the html file name can be
2831 string result = ChangeExtension(file, ".html", false);
2832 string infile = owner->buffer()->getLatexName();
2833 string tmp = lyxrc->html_command;
2834 tmp = subst(tmp, "$$FName", infile);
2835 tmp = subst(tmp, "$$OutName", result);
2837 int res = one.startscript(Systemcalls::System, tmp);
2839 setMessage(N_("Document exported as HTML to file `")
2840 + MakeDisplayPath(result) +'\'');
2842 setErrorMessage(N_("Unable to convert to HTML the file `")
2843 + MakeDisplayPath(infile)
2848 setErrorMessage(N_("Unknown export type: ")
2856 //needs argument as string
2857 string imtyp = argument;
2860 if (imtyp == "latex") {
2861 doImportLaTeX(false);
2864 else if (imtyp == "ascii") {
2865 doImportASCII(false);
2866 } else if (imtyp == "asciiparagraph") {
2867 doImportASCII(true);
2869 } else if (imtyp == "noweb") {
2870 doImportLaTeX(true);
2872 setErrorMessage(string(N_("Unknown import type: "))
2884 if (fd_form_toc->form_toc->visible) {
2885 fl_raise_form(fd_form_toc->form_toc);
2887 static int ow = -1, oh;
2888 fl_show_form(fd_form_toc->form_toc,
2890 FL_FREE_SIZE, FL_FULLBORDER,
2891 _("Table of Contents"));
2893 ow = fd_form_toc->form_toc->w;
2894 oh = fd_form_toc->form_toc->h;
2896 fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
2900 case LFUN_TOC_INSERT:
2902 Inset * new_inset = new InsetTOC(owner->buffer());
2903 owner->buffer()->insertInset(new_inset, "Standard", true);
2907 case LFUN_LOF_INSERT:
2909 Inset * new_inset = new InsetLOF(owner->buffer());
2910 owner->buffer()->insertInset(new_inset, "Standard", true);
2914 case LFUN_LOA_INSERT:
2916 Inset * new_inset = new InsetLOA(owner->buffer());
2917 owner->buffer()->insertInset(new_inset, "Standard", true);
2921 case LFUN_LOT_INSERT:
2923 Inset * new_inset = new InsetLOT(owner->buffer());
2924 owner->buffer()->insertInset(new_inset, "Standard", true);
2948 case LFUN_MENUSEARCH:
2956 case LFUN_PASTESELECTION:
2958 bool asPara = false;
2959 if (argument == "paragraph") asPara = true;
2960 MenuPasteSelection(asPara);
2972 case LFUN_LAYOUT_COPY:
2973 CopyEnvironmentCB();
2976 case LFUN_LAYOUT_PASTE:
2977 PasteEnvironmentCB();
2980 case LFUN_GOTOERROR:
2981 owner->view()->gotoError();
2984 case LFUN_REMOVEERRORS:
2985 if (owner->buffer()->removeAutoInsets()) {
2986 owner->view()->redraw();
2987 owner->view()->fitCursor();
2988 owner->view()->updateScrollbar();
2996 case LFUN_OPENSTUFF:
3000 case LFUN_HYPHENATION:
3008 case LFUN_END_OF_SENTENCE:
3012 case LFUN_MENU_SEPARATOR:
3024 case LFUN_DEPTH_MIN:
3028 case LFUN_DEPTH_PLUS:
3044 case LFUN_RECONFIGURE:
3049 if (owner->view()->available()
3050 && !owner->buffer()->text->selection
3051 && owner->buffer()->text->cursor.par->footnoteflag
3052 != LyXParagraph::NO_FOOTNOTE)
3053 { // only melt footnotes with FOOTMELT, not margins etc
3054 if(owner->buffer()->text->cursor.par->footnotekind == LyXParagraph::FOOTNOTE)
3061 case LFUN_MARGINMELT:
3062 if (owner->view()->available()
3063 && !owner->buffer()->text->selection
3064 && owner->buffer()->text->cursor.par->footnoteflag
3065 != LyXParagraph::NO_FOOTNOTE) {
3066 // only melt margins
3067 if(owner->buffer()->text->cursor.par->footnotekind == LyXParagraph::MARGIN)
3074 // --- version control -------------------------------
3075 case LFUN_VC_REGISTER:
3077 if (!owner->buffer()->lyxvc.inUse())
3078 owner->buffer()->lyxvc.registrer();
3082 case LFUN_VC_CHECKIN:
3084 if (owner->buffer()->lyxvc.inUse()
3085 && !owner->buffer()->isReadonly())
3086 owner->buffer()->lyxvc.checkIn();
3090 case LFUN_VC_CHECKOUT:
3092 if (owner->buffer()->lyxvc.inUse()
3093 && owner->buffer()->isReadonly())
3094 owner->buffer()->lyxvc.checkOut();
3098 case LFUN_VC_REVERT:
3100 owner->buffer()->lyxvc.revert();
3106 owner->buffer()->lyxvc.undoLast();
3110 case LFUN_VC_HISTORY:
3112 owner->buffer()->lyxvc.showLog();
3116 // --- buffers ----------------------------------------
3117 case LFUN_PREVBUFFER:
3118 #ifdef WITH_WARNINGS
3119 #warning fix this please
3121 // it is the LyXView or the BufferView that should
3122 // remember the previous buffer, not bufferlist.
3123 // if (owner->view()->available()){
3125 // owner->buffer()->update(-2);
3127 // owner->view()->setBuffer(bufferlist.prev());
3130 // resizeCurrentBufferPseudoExpose();
3133 case LFUN_FILE_INSERT:
3135 MenuInsertLyXFile(argument);
3139 case LFUN_FILE_INSERT_ASCII:
3141 bool asPara = (argument == "paragraph");
3142 InsertAsciiFile(string(), asPara);
3148 // servercmd: argument must be <file>:<template>
3149 Buffer * tmpbuf = NewLyxFile(argument);
3151 owner->view()->buffer(tmpbuf);
3155 case LFUN_FILE_OPEN:
3156 owner->view()->buffer(
3157 bufferlist.loadLyXFile(argument));
3160 case LFUN_LATEX_LOG:
3166 lyxerr.debug() << "LFUN_LAYOUTNO: (arg) " << argument << endl;
3167 int sel = strToInt(argument);
3168 lyxerr.debug() << "LFUN_LAYOUTNO: (sel) "<< sel << endl;
3170 // Should this give a setMessage instead?
3172 return string(); // illegal argument
3174 sel--; // sel 1..., but layout 0...
3176 // Pretend we got the name instead.
3177 Dispatch(int(LFUN_LAYOUT),
3178 textclasslist.NameOfLayout(owner->buffer()->
3187 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
3188 << argument << endl;
3190 // Derive layout number from given argument (string)
3191 // and current buffer's textclass (number). */
3193 textclasslist.NumberOfLayout(owner->
3199 // see if we found the layout number:
3200 if (layoutno == -1) {
3201 setErrorMessage(string(N_("Layout ")) + argument +
3206 if (current_layout != layoutno) {
3207 owner->view()->getScreen()->HideCursor();
3208 current_layout = layoutno;
3209 owner->buffer()->update(-2);
3210 owner->buffer()->text->
3211 SetLayout(layoutno);
3212 owner->getToolbar()->combox->
3213 select(owner->buffer()->
3216 owner->buffer()->update(1);
3221 case LFUN_LAYOUT_DOCUMENT:
3222 MenuLayoutDocument();
3225 case LFUN_LAYOUT_PARAGRAPH:
3226 MenuLayoutParagraph();
3229 case LFUN_LAYOUT_CHARACTER:
3230 MenuLayoutCharacter();
3233 case LFUN_LAYOUT_TABLE:
3236 if (argument == "true") flag = 1;
3237 MenuLayoutTable(flag);
3241 case LFUN_LAYOUT_PAPER:
3245 case LFUN_LAYOUT_QUOTES:
3249 case LFUN_LAYOUT_PREAMBLE:
3250 MenuLayoutPreamble();
3253 case LFUN_LAYOUT_SAVE_DEFAULT:
3257 case LFUN_DROP_LAYOUTS_CHOICE:
3258 owner->getToolbar()->combox->Show();
3289 case LFUN_UNDERLINE:
3293 case LFUN_FONT_SIZE:
3294 FontSizeCB(argument);
3297 case LFUN_FONT_STATE:
3298 setMessage(CurrentState());
3301 case LFUN_UPCASE_WORD:
3302 owner->buffer()->update(-2);
3304 owner->buffer()->text->ChangeWordCase(LyXText::text_uppercase);
3305 owner->buffer()->update(1);
3309 case LFUN_LOWCASE_WORD:
3310 owner->buffer()->update(-2);
3312 owner->buffer()->text->ChangeWordCase(LyXText::text_lowercase);
3313 owner->buffer()->update(1);
3317 case LFUN_CAPITALIZE_WORD:
3318 owner->buffer()->update(-2);
3320 owner->buffer()->text->ChangeWordCase(LyXText::text_capitalization);
3321 owner->buffer()->update(1);
3325 case LFUN_INSERT_LABEL:
3326 MenuInsertLabel(argument.c_str());
3329 case LFUN_INSERT_REF:
3333 case LFUN_REFTOGGLE:
3336 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
3338 if (inset->getFlag() == InsetRef::REF)
3339 inset->setFlag(InsetRef::PAGE_REF);
3341 inset->setFlag(InsetRef::REF);
3344 setErrorMessage(N_("No cross-reference to toggle"));
3351 owner->view()->restorePosition();
3357 string label(argument);
3358 if (label.empty()) {
3360 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
3362 label = inset->getContents();
3365 if (!label.empty()) {
3366 owner->view()->savePosition();
3367 owner->buffer()->gotoLabel(label.c_str());
3372 case LFUN_MENU_OPEN_BY_NAME:
3373 owner->getMenus()->openByName(argument);
3374 break; // RVDK_PATCH_5
3376 case LFUN_SPELLCHECK:
3377 if (lyxrc->isp_command != "none")
3379 break; // RVDK_PATCH_5
3381 // --- Cursor Movements -----------------------------
3384 Buffer * tmpbuffer = owner->buffer();
3385 LyXText * tmptext = owner->buffer()->text;
3386 if(!tmptext->mark_set)
3388 tmpbuffer->update(-2);
3389 if (tmptext->cursor.pos < tmptext->cursor.par->Last()
3390 && tmptext->cursor.par->GetChar(tmptext->cursor.pos)
3391 == LyXParagraph::META_INSET
3392 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)
3393 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)->Editable() == 2){
3394 Inset * tmpinset = tmptext->cursor.par->GetInset(tmptext->cursor.pos);
3395 setMessage(tmpinset->EditMessage());
3396 tmpinset->Edit(0, 0);
3399 tmptext->CursorRight();
3400 owner->buffer()->text->FinishUndo();
3401 moveCursorUpdate(false);
3402 owner->getMiniBuffer()->Set(CurrentState());
3408 // This is soooo ugly. Isn`t it possible to make
3409 // it simpler? (Lgb)
3410 LyXText * txt = owner->buffer()->text;
3411 if(!txt->mark_set) BeforeChange();
3412 owner->buffer()->update(-2);
3414 if (txt->cursor.pos < txt->cursor.par->Last()
3415 && txt->cursor.par->GetChar(txt->cursor.pos)
3416 == LyXParagraph::META_INSET
3417 && txt->cursor.par->GetInset(txt->cursor.pos)
3418 && txt->cursor.par->GetInset(txt->cursor.pos)->Editable() == 2) {
3419 Inset * tmpinset = txt->cursor.par->GetInset(txt->cursor.pos);
3420 setMessage(tmpinset->EditMessage());
3421 tmpinset->Edit(tmpinset->Width(txt->GetFont(txt->cursor.par,
3422 txt->cursor.pos)), 0);
3425 owner->buffer()->text->FinishUndo();
3426 moveCursorUpdate(false);
3427 owner->getMiniBuffer()->Set(CurrentState());
3432 if(!owner->buffer()->text->mark_set) BeforeChange();
3433 owner->buffer()->update(-3);
3434 owner->buffer()->text->CursorUp();
3435 owner->buffer()->text->FinishUndo();
3436 moveCursorUpdate(false);
3437 owner->getMiniBuffer()->Set(CurrentState());
3441 if(!owner->buffer()->text->mark_set)
3443 owner->buffer()->update(-3);
3444 owner->buffer()->text->CursorDown();
3445 owner->buffer()->text->FinishUndo();
3446 moveCursorUpdate(false);
3447 owner->getMiniBuffer()->Set(CurrentState());
3450 case LFUN_UP_PARAGRAPH:
3451 if(!owner->buffer()->text->mark_set)
3453 owner->buffer()->update(-3);
3454 owner->buffer()->text->CursorUpParagraph();
3455 owner->buffer()->text->FinishUndo();
3456 moveCursorUpdate(false);
3457 owner->getMiniBuffer()->Set(CurrentState());
3460 case LFUN_DOWN_PARAGRAPH:
3461 if(!owner->buffer()->text->mark_set)
3463 owner->buffer()->update(-3);
3464 owner->buffer()->text->CursorDownParagraph();
3465 owner->buffer()->text->FinishUndo();
3466 moveCursorUpdate(false);
3467 owner->getMiniBuffer()->Set(CurrentState());
3471 if(!owner->buffer()->text->mark_set)
3473 owner->buffer()->update(-3);
3474 owner->view()->cursorPrevious();
3475 owner->buffer()->text->FinishUndo();
3476 moveCursorUpdate(false);
3477 owner->getMiniBuffer()->Set(CurrentState());
3481 if(!owner->buffer()->text->mark_set)
3483 owner->buffer()->update(-3);
3484 owner->view()->cursorNext();
3485 owner->buffer()->text->FinishUndo();
3486 moveCursorUpdate(false);
3487 owner->getMiniBuffer()->Set(CurrentState());
3491 if(!owner->buffer()->text->mark_set)
3493 owner->buffer()->update(-2);
3494 owner->buffer()->text->CursorHome();
3495 owner->buffer()->text->FinishUndo();
3496 moveCursorUpdate(false);
3497 owner->getMiniBuffer()->Set(CurrentState());
3501 if(!owner->buffer()->text->mark_set)
3503 owner->buffer()->update(-2);
3504 owner->buffer()->text->CursorEnd();
3505 owner->buffer()->text->FinishUndo();
3506 moveCursorUpdate(false);
3507 owner->getMiniBuffer()->Set(CurrentState());
3511 if(!owner->buffer()->text->mark_set)
3513 owner->buffer()->update(-2);
3514 owner->buffer()->text->CursorTab();
3515 owner->buffer()->text->FinishUndo();
3516 moveCursorUpdate(false);
3517 owner->getMiniBuffer()->Set(CurrentState());
3520 case LFUN_WORDRIGHT:
3521 if(!owner->buffer()->text->mark_set)
3523 owner->buffer()->update(-2);
3524 owner->buffer()->text->CursorRightOneWord();
3525 owner->buffer()->text->FinishUndo();
3526 moveCursorUpdate(false);
3527 owner->getMiniBuffer()->Set(CurrentState());
3531 if(!owner->buffer()->text->mark_set)
3533 owner->buffer()->update(-2);
3534 owner->buffer()->text->CursorLeftOneWord();
3535 owner->buffer()->text->FinishUndo();
3536 moveCursorUpdate(false);
3537 owner->getMiniBuffer()->Set(CurrentState());
3540 case LFUN_BEGINNINGBUF:
3541 if(!owner->buffer()->text->mark_set)
3543 owner->buffer()->update(-2);
3544 owner->buffer()->text->CursorTop();
3545 owner->buffer()->text->FinishUndo();
3546 moveCursorUpdate(false);
3547 owner->getMiniBuffer()->Set(CurrentState());
3551 if(!owner->buffer()->text->mark_set)
3553 owner->buffer()->update(-2);
3554 owner->buffer()->text->CursorBottom();
3555 owner->buffer()->text->FinishUndo();
3556 moveCursorUpdate(false);
3557 owner->getMiniBuffer()->Set(CurrentState());
3561 /* cursor selection ---------------------------- */
3563 owner->buffer()->update(-2);
3564 owner->buffer()->text->CursorRight();
3565 owner->buffer()->text->FinishUndo();
3566 moveCursorUpdate(true);
3567 owner->getMiniBuffer()->Set(CurrentState());
3571 owner->buffer()->update(-2);
3572 owner->buffer()->text->CursorLeft();
3573 owner->buffer()->text->FinishUndo();
3574 moveCursorUpdate(true);
3575 owner->getMiniBuffer()->Set(CurrentState());
3579 owner->buffer()->update(-2);
3580 owner->buffer()->text->CursorUp();
3581 owner->buffer()->text->FinishUndo();
3582 moveCursorUpdate(true);
3583 owner->getMiniBuffer()->Set(CurrentState());
3587 owner->buffer()->update(-2);
3588 owner->buffer()->text->CursorDown();
3589 owner->buffer()->text->FinishUndo();
3590 moveCursorUpdate(true);
3591 owner->getMiniBuffer()->Set(CurrentState());
3594 case LFUN_UP_PARAGRAPHSEL:
3595 owner->buffer()->update(-2);
3596 owner->buffer()->text->CursorUpParagraph();
3597 owner->buffer()->text->FinishUndo();
3598 moveCursorUpdate(true);
3599 owner->getMiniBuffer()->Set(CurrentState());
3602 case LFUN_DOWN_PARAGRAPHSEL:
3603 owner->buffer()->update(-2);
3604 owner->buffer()->text->CursorDownParagraph();
3605 owner->buffer()->text->FinishUndo();
3606 moveCursorUpdate(true);
3607 owner->getMiniBuffer()->Set(CurrentState());
3611 owner->buffer()->update(-2);
3612 owner->view()->cursorPrevious();
3613 owner->buffer()->text->FinishUndo();
3614 moveCursorUpdate(true);
3615 owner->getMiniBuffer()->Set(CurrentState());
3619 owner->buffer()->update(-2);
3620 owner->view()->cursorNext();
3621 owner->buffer()->text->FinishUndo();
3622 moveCursorUpdate(true);
3623 owner->getMiniBuffer()->Set(CurrentState());
3627 owner->buffer()->update(-2);
3628 owner->buffer()->text->CursorHome();
3629 owner->buffer()->text->FinishUndo();
3630 moveCursorUpdate(true);
3631 owner->getMiniBuffer()->Set(CurrentState());
3635 owner->buffer()->update(-2);
3636 owner->buffer()->text->CursorEnd();
3637 owner->buffer()->text->FinishUndo();
3638 moveCursorUpdate(true);
3639 owner->getMiniBuffer()->Set(CurrentState());
3642 case LFUN_WORDRIGHTSEL:
3643 owner->buffer()->update(-2);
3644 owner->buffer()->text->CursorRightOneWord();
3645 owner->buffer()->text->FinishUndo();
3646 moveCursorUpdate(true);
3647 owner->getMiniBuffer()->Set(CurrentState());
3650 case LFUN_WORDLEFTSEL:
3651 owner->buffer()->update(-2);
3652 owner->buffer()->text->CursorLeftOneWord();
3653 owner->buffer()->text->FinishUndo();
3654 moveCursorUpdate(true);
3655 owner->getMiniBuffer()->Set(CurrentState());
3658 case LFUN_BEGINNINGBUFSEL:
3659 owner->buffer()->update(-2);
3660 owner->buffer()->text->CursorTop();
3661 owner->buffer()->text->FinishUndo();
3662 moveCursorUpdate(true);
3663 owner->getMiniBuffer()->Set(CurrentState());
3666 case LFUN_ENDBUFSEL:
3667 owner->buffer()->update(-2);
3668 owner->buffer()->text->CursorBottom();
3669 owner->buffer()->text->FinishUndo();
3670 moveCursorUpdate(true);
3671 owner->getMiniBuffer()->Set(CurrentState());
3674 // --- text changing commands ------------------------
3675 case LFUN_BREAKLINE:
3677 owner->buffer()->text->InsertChar(LyXParagraph::META_NEWLINE);
3679 SetUpdateTimer(0.01);
3680 moveCursorUpdate(false);
3683 case LFUN_PROTECTEDSPACE:
3685 owner->buffer()->text->
3686 InsertChar(LyXParagraph::META_PROTECTED_SEPARATOR);
3689 moveCursorUpdate(false);
3693 if(owner->buffer()->text->mark_set) {
3695 owner->buffer()->update(0);
3696 setMessage(N_("Mark removed"));
3699 owner->buffer()->text->mark_set = 1;
3700 owner->buffer()->update(0);
3701 setMessage(N_("Mark set"));
3703 owner->buffer()->text->sel_cursor =
3704 owner->buffer()->text->cursor;
3709 if (!owner->buffer()->text->selection) {
3710 owner->buffer()->text->Delete();
3711 owner->buffer()->text->sel_cursor =
3712 owner->buffer()->text->cursor;
3714 // It is possible to make it a lot faster still
3715 // just comment out the lone below...
3716 owner->view()->getScreen()->ShowCursor();
3723 case LFUN_DELETE_SKIP:
3725 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
3727 LyXCursor cursor = owner->buffer()->text->cursor;
3730 if (!owner->buffer()->text->selection) {
3731 if (cursor.pos == cursor.par->Last()) {
3732 owner->buffer()->text->CursorRight();
3733 cursor = owner->buffer()->text->cursor;
3735 && !(cursor.par->added_space_top
3736 == VSpace (VSpace::NONE))) {
3737 owner->buffer()->text->SetParagraph
3738 (cursor.par->line_top,
3739 cursor.par->line_bottom,
3740 cursor.par->pagebreak_top,
3741 cursor.par->pagebreak_bottom,
3742 VSpace(VSpace::NONE),
3743 cursor.par->added_space_bottom,
3745 cursor.par->labelwidthstring, 0);
3746 owner->buffer()->text->CursorLeft();
3747 owner->buffer()->update (1);
3749 owner->buffer()->text->CursorLeft();
3750 owner->buffer()->text->Delete();
3751 owner->buffer()->text->sel_cursor =
3752 owner->buffer()->text->cursor;
3756 owner->buffer()->text->Delete();
3757 owner->buffer()->text->sel_cursor =
3758 owner->buffer()->text->cursor;
3768 /* -------> Delete word forward. */
3769 case LFUN_DELETE_WORD_FORWARD:
3770 owner->buffer()->update(-2);
3772 owner->buffer()->text->DeleteWordForward();
3773 owner->buffer()->update( 1 );
3775 moveCursorUpdate(false);
3778 /* -------> Delete word backward. */
3779 case LFUN_DELETE_WORD_BACKWARD:
3780 owner->buffer()->update(-2);
3782 owner->buffer()->text->DeleteWordBackward();
3783 owner->buffer()->update( 1 );
3785 moveCursorUpdate(false);
3788 /* -------> Kill to end of line. */
3789 case LFUN_DELETE_LINE_FORWARD:
3791 owner->buffer()->update(-2);
3792 owner->buffer()->text->DeleteLineForward();
3793 owner->buffer()->update( 1 );
3795 moveCursorUpdate(false);
3798 /* -------> Set mark off. */
3801 owner->buffer()->update(0);
3802 owner->buffer()->text->sel_cursor =
3803 owner->buffer()->text->cursor;
3804 setMessage(N_("Mark off"));
3807 /* -------> Set mark on. */
3810 owner->buffer()->text->mark_set = 1;
3811 owner->buffer()->update( 0 );
3812 owner->buffer()->text->sel_cursor =
3813 owner->buffer()->text->cursor;
3814 setMessage(N_("Mark on"));
3817 case LFUN_BACKSPACE:
3820 if (!owner->buffer()->text->selection) {
3821 if (owner->getIntl()->getTrans()->backspace()) {
3822 owner->buffer()->text->Backspace();
3823 owner->buffer()->text->sel_cursor =
3824 owner->buffer()->text->cursor;
3826 // It is possible to make it a lot faster still
3827 // just comment out the lone below...
3828 owner->view()->getScreen()->ShowCursor();
3837 case LFUN_BACKSPACE_SKIP:
3839 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
3841 LyXCursor cursor = owner->buffer()->text->cursor;
3844 if (!owner->buffer()->text->selection) {
3846 && !(cursor.par->added_space_top
3847 == VSpace (VSpace::NONE))) {
3848 owner->buffer()->text->SetParagraph
3849 (cursor.par->line_top,
3850 cursor.par->line_bottom,
3851 cursor.par->pagebreak_top,
3852 cursor.par->pagebreak_bottom,
3853 VSpace(VSpace::NONE), cursor.par->added_space_bottom,
3855 cursor.par->labelwidthstring, 0);
3856 owner->buffer()->update (1);
3858 owner->buffer()->text->Backspace();
3859 owner->buffer()->text->sel_cursor
3869 case LFUN_BREAKPARAGRAPH:
3872 owner->buffer()->text->BreakParagraph(0);
3874 SetUpdateTimer(0.01);
3875 owner->buffer()->text->sel_cursor =
3876 owner->buffer()->text->cursor;
3880 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
3883 owner->buffer()->text->BreakParagraph(1);
3885 SetUpdateTimer(0.01);
3886 owner->buffer()->text->sel_cursor =
3887 owner->buffer()->text->cursor;
3891 case LFUN_BREAKPARAGRAPH_SKIP:
3893 // When at the beginning of a paragraph, remove
3894 // indentation and add a "defskip" at the top.
3895 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
3897 LyXCursor cursor = owner->buffer()->text->cursor;
3900 if (cursor.pos == 0) {
3901 if (cursor.par->added_space_top == VSpace(VSpace::NONE)) {
3902 owner->buffer()->text->SetParagraph
3903 (cursor.par->line_top,
3904 cursor.par->line_bottom,
3905 cursor.par->pagebreak_top,
3906 cursor.par->pagebreak_bottom,
3907 VSpace(VSpace::DEFSKIP), cursor.par->added_space_bottom,
3909 cursor.par->labelwidthstring, 1);
3910 owner->buffer()->update(1);
3914 owner->buffer()->text->BreakParagraph(0);
3917 SetUpdateTimer(0.01);
3918 owner->buffer()->text->sel_cursor = cursor;
3924 owner->buffer()->text->InsertChar('\"'); // This " matches the single quote in the code
3927 moveCursorUpdate(false);
3933 InsetCommand * new_inset;
3934 if (action == LFUN_HTMLURL)
3935 new_inset = new InsetUrl("htmlurl", "", "");
3937 new_inset = new InsetUrl("url", "", "");
3938 owner->buffer()->insertInset(new_inset);
3939 new_inset->Edit(0, 0);
3943 // --- lyxserver commands ----------------------------
3945 case LFUN_CHARATCURSOR:
3947 LyXParagraph::size_type pos =
3948 owner->buffer()->text->cursor.pos;
3949 if(pos < owner->buffer()->text->cursor.par->size())
3950 dispatch_buffer = owner->buffer()->text->
3951 cursor.par->text[pos];
3953 dispatch_buffer = "EOF";
3959 tostr(owner->buffer()->text->cursor.x) + ' '
3960 + tostr(owner->buffer()->text->cursor.y);
3967 sscanf(argument.c_str(), " %d %ld", &x, &y);
3968 owner->buffer()->text->SetCursorFromCoordinates(x, y);
3972 case LFUN_GETLAYOUT:
3974 tostr(owner->buffer()->text->cursor.par->layout);
3979 LyXFont *font = &(owner->buffer()->text->current_font);
3980 if(font->shape() == LyXFont::ITALIC_SHAPE)
3981 dispatch_buffer = 'E';
3982 else if(font->shape() == LyXFont::SMALLCAPS_SHAPE)
3983 dispatch_buffer = 'N';
3985 dispatch_buffer = '0';
3992 LyXFont *font = &(owner->buffer()->text->current_font);
3993 if(font->latex() == LyXFont::ON)
3994 dispatch_buffer = 'L';
3996 dispatch_buffer = '0';
4001 setMessage(owner->buffer()->getFileName());
4002 lyxerr.debug() << "FNAME["
4003 << owner->buffer()->getFileName()
4010 keyseq.print(buf, 100);
4011 dispatch_buffer = buf;
4012 lyxserver->notifyClient(dispatch_buffer);
4016 case LFUN_GOTOFILEROW:
4018 char file_name[100];
4020 sscanf(argument.c_str(), " %s %d", file_name, &row);
4022 // Must replace extension of the file to be .lyx and get full path
4023 string s = ChangeExtension(string(file_name), ".lyx", false);
4025 // Either change buffer or load the file
4026 if (bufferlist.exists(s))
4027 owner->view()->buffer(bufferlist.getBuffer(s));
4029 owner->view()->buffer(bufferlist.loadLyXFile(s));
4032 owner->buffer()->setCursorFromRow(row);
4036 if (owner->buffer()->text->cursor.y >
4037 owner->view()->getWorkArea()->h / 2) {
4038 owner->view()->getScreen()->
4039 Draw(owner->buffer()->text->cursor.y -
4040 owner->view()->getWorkArea()->h/2);
4042 owner->view()->getScreen()->
4045 owner->buffer()->update(0);
4046 owner->view()->redraw();
4053 int qa = lyxaction.LookupFunc(argument.c_str());
4054 setMessage(lyxaction.helpText((kb_action)qa));
4058 // --- accented characters ---------------------------
4061 case LFUN_CIRCUMFLEX:
4071 case LFUN_SPECIAL_CARON:
4074 case LFUN_HUNG_UMLAUT:
4080 if (keyseq.length == -1 && keyseq.getiso()!= 0)
4085 owner->getIntl()->getTrans()->
4086 deadkey(c, get_accent(action).accent,
4087 owner->buffer()->text);
4089 // Need to reset, in case the minibuffer calls these
4094 // copied verbatim from do_accent_char
4097 owner->buffer()->text->sel_cursor =
4098 owner->buffer()->text->cursor;
4102 // --- toolbar ----------------------------------
4103 case LFUN_PUSH_TOOLBAR:
4105 int nth = strToInt(argument);
4106 if (lyxerr.debugging(Debug::TOOLBAR)) {
4107 lyxerr << "LFUN_PUSH_TOOLBAR: argument = `"
4108 << argument << "'\n"
4109 << "LFUN_PUSH_TOOLBAR: nth = `"
4110 << nth << "'" << endl;
4115 setErrorMessage(N_("Push-toolbar needs argument > 0"));
4117 owner->getToolbar()->push(nth);
4122 case LFUN_ADD_TO_TOOLBAR:
4124 if (lyxerr.debugging(Debug::TOOLBAR)) {
4125 lyxerr << "LFUN_ADD_TO_TOOLBAR:"
4126 "argument = `" << argument << '\'' << endl;
4128 string tmp(argument);
4129 //lyxerr <<string("Argument: ") + argument);
4130 //lyxerr <<string("Tmp : ") + tmp);
4133 setErrorMessage(N_("Usage: toolbar-add-to <LyX command>"));
4135 owner->getToolbar()->add(argument, false);
4136 owner->getToolbar()->set();
4141 // --- insert characters ----------------------------------------
4143 case LFUN_INSERT_INSET_LATEX:
4145 Inset *new_inset = new InsetLatex(argument);
4146 owner->buffer()->insertInset(new_inset);
4150 // --- Mathed stuff. If we are here, there is no locked inset yet.
4155 if (!greek_kb_flag) {
4157 setMessage(N_("Math greek mode on"));
4164 case LFUN_GREEK_TOGGLE:
4166 greek_kb_flag = (greek_kb_flag) ? 0: 2;
4167 if (greek_kb_flag) {
4168 setMessage(N_("Math greek keyboard on"));
4170 setMessage(N_("Math greek keyboard off"));
4175 case LFUN_MATH_DELIM:
4176 case LFUN_INSERT_MATRIX:
4178 if (owner->view()->available()) {
4180 open_new_inset(new InsetFormula(false));
4182 the_locking_inset->LocalDispatch(action, argument.c_str());
4187 case LFUN_INSERT_MATH:
4189 math_insert_symbol(argument.c_str());
4193 case LFUN_MATH_DISPLAY:
4195 if (owner->view()->available())
4196 owner->buffer()->open_new_inset(new InsetFormula(true));
4200 case LFUN_MATH_MACRO:
4202 if (owner->view()->available()) {
4205 setErrorMessage(N_("Missing argument"));
4207 string s1 = token(s, ' ', 1);
4208 int na = s1.empty() ? 0: atoi(s1.c_str());
4210 open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
4216 case LFUN_MATH_MODE: // Open or create a math inset
4219 if (owner->view()->available())
4220 owner->buffer()->open_new_inset(new InsetFormula);
4221 setMessage(N_("Math editor mode"));
4225 case LFUN_MATH_NUMBER:
4226 case LFUN_MATH_LIMITS:
4228 setErrorMessage(N_("This is only allowed in math mode!"));
4232 case LFUN_INSERT_CITATION:
4234 InsetCitation * new_inset = new InsetCitation();
4236 // The note, if any, must be after the key, delimited
4237 // by a | so both key and remark can have spaces.
4238 if (!argument.empty()) {
4239 string lsarg(argument);
4240 if (contains(lsarg, "|")) {
4241 new_inset->setContents(token(lsarg, '|', 0));
4242 new_inset->setOptions(token(lsarg, '|', 1));
4244 new_inset->setContents(lsarg);
4245 owner->buffer()->insertInset(new_inset);
4247 owner->buffer()->insertInset(new_inset);
4248 new_inset->Edit(0, 0);
4253 case LFUN_INSERT_BIBTEX:
4255 // ale970405+lasgoutt970425
4256 // The argument can be up to two tokens separated
4257 // by a space. The first one is the bibstyle.
4258 string lsarg(argument);
4259 string bibstyle = token(lsarg, ' ', 1);
4260 if (bibstyle.empty())
4262 InsetBibtex * new_inset
4263 = new InsetBibtex(token(lsarg, ' ', 0),
4267 owner->buffer()->insertInset(new_inset);
4268 if (lsarg.empty()) {
4269 new_inset->Edit(0, 0);
4274 // BibTeX data bases
4275 case LFUN_BIBDB_ADD:
4277 InsetBibtex * inset =
4278 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
4280 inset->addDatabase(argument);
4285 case LFUN_BIBDB_DEL:
4287 InsetBibtex * inset =
4288 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
4290 inset->delDatabase(argument);
4295 case LFUN_BIBTEX_STYLE:
4297 InsetBibtex * inset =
4298 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
4300 inset->setOptions(argument);
4305 case LFUN_INDEX_INSERT:
4306 case LFUN_INDEX_INSERT_LAST:
4308 // Can't do that at the beginning of a paragraph.
4309 if (owner->buffer()->text->cursor.pos - 1 <0)
4312 InsetIndex * new_inset = new InsetIndex();
4313 if (!argument.empty()) {
4314 string lsarg(argument);
4315 new_inset->setContents(lsarg);
4316 owner->buffer()->insertInset(new_inset);
4319 //get the current word for an argument
4320 LyXParagraph::size_type lastpos =
4321 owner->buffer()->text->cursor.pos - 1;
4322 // Get the current word. note that this must be done
4323 // before inserting the inset, or the inset will
4325 string curstring(owner->buffer()
4326 ->text->cursor.par->GetWord(lastpos));
4328 //make the new inset and write the current word into it
4329 InsetIndex * new_inset = new InsetIndex();
4331 new_inset->setContents(curstring);
4333 //don't edit it if the call was to INSERT_LAST
4334 if(action!= LFUN_INDEX_INSERT_LAST) {
4335 new_inset->Edit(0, 0);
4337 //it looks blank on the screen unless
4338 //we do something. put it here.
4340 // move the cursor to the returned value of lastpos
4341 // but only for the auto-insert
4342 owner->buffer()->text->cursor.pos= lastpos;
4345 //put the new inset into the buffer.
4346 // there should be some way of knowing the user
4347 //cancelled & avoiding this, but i don't know how
4348 owner->buffer()->insertInset(new_inset);
4353 case LFUN_INDEX_PRINT:
4355 Inset * new_inset = new InsetPrintIndex(owner->buffer());
4356 owner->buffer()->insertInset(new_inset, "Standard", true);
4360 case LFUN_PARENTINSERT:
4362 lyxerr << "arg " << argument << endl;
4363 Inset * new_inset = new InsetParent(argument, owner->buffer());
4364 owner->buffer()->insertInset(new_inset, "Standard", true);
4368 case LFUN_CHILDINSERT:
4370 Inset * new_inset = new InsetInclude(argument,
4372 owner->buffer()->insertInset(new_inset, "Standard", true);
4373 new_inset->Edit(0, 0);
4377 case LFUN_CHILDOPEN:
4380 MakeAbsPath(argument,
4381 OnlyPath(owner->buffer()->getFileName()));
4382 setMessage(N_("Opening child document ") +
4383 MakeDisplayPath(filename) + "...");
4384 owner->view()->savePosition();
4385 if (bufferlist.exists(filename))
4386 owner->view()->buffer(bufferlist.getBuffer(filename));
4388 owner->view()->buffer(bufferlist.loadLyXFile(filename));
4392 case LFUN_INSERT_NOTE:
4396 case LFUN_INSERTFOOTNOTE:
4398 LyXParagraph::footnote_kind kind;
4399 if (argument == "footnote")
4400 { kind = LyXParagraph::FOOTNOTE; }
4401 else if (argument == "margin")
4402 { kind = LyXParagraph::MARGIN; }
4403 else if (argument == "figure")
4404 { kind = LyXParagraph::FIG; }
4405 else if (argument == "table")
4406 { kind = LyXParagraph::TAB; }
4407 else if (argument == "wide-fig")
4408 { kind = LyXParagraph::WIDE_FIG; }
4409 else if (argument == "wide-tab")
4410 { kind = LyXParagraph::WIDE_TAB; }
4411 else if (argument == "algorithm")
4412 { kind = LyXParagraph::ALGORITHM; }
4414 setErrorMessage(N_("Unknown kind of footnote"));
4417 owner->buffer()->text->InsertFootnoteEnvironment(kind);
4418 owner->buffer()->update(1);
4422 case LFUN_BUFFERBULLETSSELECT:
4426 case LFUN_TOGGLECURSORFOLLOW:
4427 cursor_follows_scrollbar = !cursor_follows_scrollbar;
4430 case LFUN_KMAP_OFF: // keymap off
4431 owner->getIntl()->KeyMapOn(false);
4434 case LFUN_KMAP_PRIM: // primary keymap
4435 owner->getIntl()->KeyMapPrim();
4438 case LFUN_KMAP_SEC: // secondary keymap
4439 owner->getIntl()->KeyMapSec();
4442 case LFUN_KMAP_TOGGLE: // toggle keymap
4443 owner->getIntl()->ToggleKeyMap();
4446 case LFUN_SELFINSERT:
4448 for (string::size_type i = 0; i < argument.length(); ++i) {
4449 owner->buffer()->text->InsertChar(argument[i]);
4450 // This needs to be in the loop, or else we
4451 // won't break lines correctly. (Asger)
4455 owner->buffer()->text->sel_cursor =
4456 owner->buffer()->text->cursor;
4457 moveCursorUpdate(false);
4463 // argument contains ';'-terminated commands
4464 while (argument.find(';') != string::npos) {
4466 argument = split(argument, first, ';');
4472 case LFUN_SAVEPREFERENCES:
4474 Path p(user_lyxdir);
4475 lyxrc->write("preferences");
4479 case LFUN_UNKNOWN_ACTION:
4481 if (owner->buffer()->isReadonly()) {
4483 setErrorMessage(N_("Document is read only"));
4487 if (!argument.empty()) {
4489 /* Automatically delete the currently selected
4490 * text and replace it with what is being
4491 * typed in now. Depends on lyxrc settings
4492 * "auto_region_delete", which defaults to
4495 if ( lyxrc->auto_region_delete ) {
4496 if (owner->buffer()->text->selection){
4497 owner->buffer()->text->CutSelection(false);
4498 owner->buffer()->update(-1);
4503 for (string::size_type i = 0;
4504 i < argument.length(); ++i) {
4505 if (greek_kb_flag) {
4506 if (!math_insert_greek(argument[i]))
4507 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->buffer()->text);
4509 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->buffer()->text);
4515 owner->buffer()->text->sel_cursor =
4516 owner->buffer()->text->cursor;
4517 moveCursorUpdate(false);
4520 // why is an "Unknown action" with empty
4521 // argument even dispatched in the first
4522 // place? I`ll probably change that. (Lgb)
4524 setErrorMessage(N_("Unknown action"));
4528 lyxerr << "A truly unknown func!" << endl;
4534 string res = getMessage();
4537 if (!commandshortcut.empty()) {
4538 string newbuf = owner->getMiniBuffer()->GetText();
4539 if (newbuf != commandshortcut) {
4540 owner->getMiniBuffer()->Set(newbuf
4546 owner->getMiniBuffer()->Set(string(_(res.c_str()))
4547 + " " + commandshortcut);
4554 void LyXFunc::setupLocalKeymap()
4556 keyseq.stdmap = keyseq.curmap = toplevel_keymap;
4557 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap;
4561 void LyXFunc::MenuNew(bool fromTemplate)
4563 string fname, initpath = lyxrc->document_path;
4566 if (owner->view()->available()) {
4567 string trypath = owner->buffer()->filepath;
4568 // If directory is writeable, use this as default.
4569 if (IsDirWriteable(trypath) == 1)
4574 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
4575 fileDlg.SetButton(1, _("Templates"), lyxrc->template_path);
4576 fname = fileDlg.Select(_("Enter Filename for new document"),
4577 initpath, "*.lyx", _("newfile"));
4580 if (fname.empty()) {
4581 owner->getMiniBuffer()->Set(_("Canceled."));
4582 lyxerr.debug() << "New Document Cancelled." << endl;
4586 // get absolute path of file and make sure the filename ends
4588 string s = MakeAbsPath(fname);
4589 if (!IsLyXFilename(s))
4592 // Check if the document already is open
4593 if (bufferlist.exists(s)){
4594 switch(AskConfirmation(_("Document is already open:"),
4595 MakeDisplayPath(s, 50),
4596 _("Do you want to close that document now?\n"
4597 "('No' will just switch to the open version)")))
4599 case 1: // Yes: close the document
4600 if (!bufferlist.close(bufferlist.getBuffer(s)))
4601 // If close is canceled, we cancel here too.
4604 case 2: // No: switch to the open document
4605 owner->view()->buffer(bufferlist.getBuffer(s));
4607 case 3: // Cancel: Do nothing
4608 owner->getMiniBuffer()->Set(_("Canceled."));
4613 // Check whether the file already exists
4614 if (IsLyXFilename(s)) {
4616 if (fi.readable() &&
4617 AskQuestion(_("File already exists:"),
4618 MakeDisplayPath(s, 50),
4619 _("Do you want to open the document?"))) {
4621 owner->getMiniBuffer()->Set(_("Opening document"),
4622 MakeDisplayPath(s), "...");
4624 owner->view()->buffer(
4625 bufferlist.loadLyXFile(s));
4626 owner->getMiniBuffer()->Set(_("Document"),
4633 // The template stuff
4637 fname = fileDlg.Select(_("Choose template"),
4638 lyxrc->template_path,
4644 // find a free buffer
4645 lyxerr.debug() << "Find a free buffer." << endl;
4646 owner->view()->buffer(bufferlist.newFile(s, templname));
4650 void LyXFunc::MenuOpen()
4652 string initpath = lyxrc->document_path;
4655 if (owner->view()->available()) {
4656 string trypath = owner->buffer()->filepath;
4657 // If directory is writeable, use this as default.
4658 if (IsDirWriteable(trypath) == 1)
4664 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
4665 fileDlg.SetButton(1, _("Examples"),
4666 AddPath(system_lyxdir, "examples"));
4667 string filename = fileDlg.Select(_("Select Document to Open"),
4671 // check selected filename
4672 if (filename.empty()) {
4673 owner->getMiniBuffer()->Set(_("Canceled."));
4677 // get absolute path of file and make sure the filename ends
4679 filename = MakeAbsPath(filename);
4680 if (!IsLyXFilename(filename))
4684 owner->getMiniBuffer()->Set(_("Opening document"),
4685 MakeDisplayPath(filename), "...");
4686 Buffer * openbuf = bufferlist.loadLyXFile(filename);
4688 owner->view()->buffer(openbuf);
4689 owner->getMiniBuffer()->Set(_("Document"),
4690 MakeDisplayPath(filename),
4693 owner->getMiniBuffer()->Set(_("Could not open document"),
4694 MakeDisplayPath(filename));
4699 void LyXFunc::doImportASCII(bool linorpar)
4701 string initpath = lyxrc->document_path;
4704 if (owner->view()->available()) {
4705 string trypath = owner->buffer()->filepath;
4706 // If directory is writeable, use this as default.
4707 if (IsDirWriteable(trypath) == 1)
4713 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
4714 fileDlg.SetButton(1, _("Examples"),
4715 AddPath(system_lyxdir, "examples"));
4716 string filename = fileDlg.Select(_("Select ASCII file to Import"),
4720 // check selected filename
4721 if (filename.empty()) {
4722 owner->getMiniBuffer()->Set(_("Canceled."));
4726 // get absolute path of file
4727 filename = MakeAbsPath(filename);
4729 string s = ChangeExtension(filename, ".lyx", false);
4731 // Check if the document already is open
4732 if (bufferlist.exists(s)){
4733 switch(AskConfirmation(_("Document is already open:"),
4734 MakeDisplayPath(s, 50),
4735 _("Do you want to close that document now?\n"
4736 "('No' will just switch to the open version)")))
4738 case 1: // Yes: close the document
4739 if (!bufferlist.close(bufferlist.getBuffer(s)))
4740 // If close is canceled, we cancel here too.
4743 case 2: // No: switch to the open document
4744 owner->view()->buffer(bufferlist.getBuffer(s));
4746 case 3: // Cancel: Do nothing
4747 owner->getMiniBuffer()->Set(_("Canceled."));
4752 // Check if a LyX document by the same root exists in filesystem
4753 FileInfo f(s, true);
4754 if (f.exist() && !AskQuestion(_("A document by the name"),
4756 _("already exists. Overwrite?"))) {
4757 owner->getMiniBuffer()->Set(_("Canceled."));
4761 owner->view()->buffer(bufferlist.newFile(s, string()));
4762 owner->getMiniBuffer()->Set(_("Importing ASCII file"),
4763 MakeDisplayPath(filename), "...");
4764 // Insert ASCII file
4765 InsertAsciiFile(filename, linorpar);
4766 owner->getMiniBuffer()->Set(_("ASCII file "),
4767 MakeDisplayPath(filename),
4772 void LyXFunc::doImportLaTeX(bool isnoweb)
4774 string initpath = lyxrc->document_path;
4777 if (owner->view()->available()) {
4778 string trypath = owner->buffer()->filepath;
4779 // If directory is writeable, use this as default.
4780 if (IsDirWriteable(trypath) == 1)
4786 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
4787 fileDlg.SetButton(1, _("Examples"),
4788 AddPath(system_lyxdir, "examples"));
4791 filename = fileDlg.Select(_("Select Noweb file to Import"),
4794 filename = fileDlg.Select(_("Select LaTeX file to Import"),
4800 // check selected filename
4801 if (filename.empty()) {
4802 owner->getMiniBuffer()->Set(_("Canceled."));
4806 // get absolute path of file
4807 filename = MakeAbsPath(filename);
4809 // Check if the document already is open
4810 string LyXfilename = ChangeExtension(filename, ".lyx", false);
4811 if (bufferlist.exists(LyXfilename)){
4812 switch(AskConfirmation(_("Document is already open:"),
4813 MakeDisplayPath(LyXfilename, 50),
4814 _("Do you want to close that document now?\n"
4815 "('No' will just switch to the open version)")))
4817 case 1: // Yes: close the document
4818 if (!bufferlist.close(bufferlist.getBuffer(LyXfilename)))
4819 // If close is canceled, we cancel here too.
4822 case 2: // No: switch to the open document
4823 owner->view()->buffer(
4824 bufferlist.getBuffer(LyXfilename));
4826 case 3: // Cancel: Do nothing
4827 owner->getMiniBuffer()->Set(_("Canceled."));
4832 // Check if a LyX document by the same root exists in filesystem
4833 FileInfo f(LyXfilename, true);
4834 if (f.exist() && !AskQuestion(_("A document by the name"),
4835 MakeDisplayPath(LyXfilename),
4836 _("already exists. Overwrite?"))) {
4837 owner->getMiniBuffer()->Set(_("Canceled."));
4844 owner->getMiniBuffer()->Set(_("Importing LaTeX file"),
4845 MakeDisplayPath(filename), "...");
4846 ImportLaTeX myImport(filename);
4847 openbuf = myImport.run();
4849 owner->getMiniBuffer()->Set(_("Importing Noweb file"),
4850 MakeDisplayPath(filename), "...");
4851 ImportNoweb myImport(filename);
4852 openbuf = myImport.run();
4855 owner->view()->buffer(openbuf);
4856 owner->getMiniBuffer()->Set(isnoweb ?
4857 _("Noweb file ") : _("LateX file "),
4858 MakeDisplayPath(filename),
4861 owner->getMiniBuffer()->Set(isnoweb ?
4862 _("Could not import Noweb file") :
4863 _("Could not import LaTeX file"),
4864 MakeDisplayPath(filename));
4869 void LyXFunc::MenuInsertLyXFile(string const & filen)
4871 string filename = filen;
4873 if (filename.empty()) {
4874 // Launch a file browser
4875 string initpath = lyxrc->document_path;
4878 if (owner->view()->available()) {
4879 string trypath = owner->buffer()->filepath;
4880 // If directory is writeable, use this as default.
4881 if (IsDirWriteable(trypath) == 1)
4887 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
4888 fileDlg.SetButton(1, _("Examples"),
4889 AddPath(system_lyxdir, "examples"));
4890 filename = fileDlg.Select(_("Select Document to Insert"),
4894 // check selected filename
4895 if (filename.empty()) {
4896 owner->getMiniBuffer()->Set(_("Canceled."));
4901 // get absolute path of file and make sure the filename ends
4903 filename = MakeAbsPath(filename);
4904 if (!IsLyXFilename(filename))
4908 owner->getMiniBuffer()->Set(_("Inserting document"),
4909 MakeDisplayPath(filename), "...");
4910 bool res = owner->buffer()->insertLyXFile(filename);
4912 owner->getMiniBuffer()->Set(_("Document"),
4913 MakeDisplayPath(filename),
4916 owner->getMiniBuffer()->Set(_("Could not insert document"),
4917 MakeDisplayPath(filename));
4922 void LyXFunc::reloadBuffer()
4924 string fn = owner->buffer()->fileName();
4925 if (bufferlist.close(owner->buffer()))
4926 owner->view()->buffer(bufferlist.loadLyXFile(fn));
4930 void LyXFunc::CloseBuffer()
4932 if (bufferlist.close(owner->buffer()) && !quitting) {
4933 if (bufferlist.empty()) {
4934 // need this otherwise SEGV may occur while trying to
4935 // set variables that don't exist
4936 // since there's no current buffer
4937 CloseAllBufferRelatedPopups();
4940 owner->view()->buffer(bufferlist.first());
4946 Inset * LyXFunc::getInsetByCode(Inset::Code code)
4951 LyXCursor cursor = owner->view()->text->cursor;
4953 LyXCursor cursor = owner->buffer()->text->cursor;
4955 LyXParagraph::size_type pos = cursor.pos;
4956 LyXParagraph * par = cursor.par;
4958 while (par && !found) {
4959 while ((inset = par->ReturnNextInsetPointer(pos))){
4960 if (inset->LyxCode() == code) {
4968 return (found) ? inset: 0;
4972 // Each "owner" should have it's own message method. lyxview and
4973 // the minibuffer would use the minibuffer, but lyxserver would
4974 // send an ERROR signal to its client. Alejandro 970603
4975 // This func is bit problematic when it comes to NLS, to make the
4976 // lyx servers client be language indepenent we must not translate
4977 // strings sent to this func.
4978 void LyXFunc::setErrorMessage(string const & m) const
4980 dispatch_buffer = m;
4985 void LyXFunc::setMessage(string const & m)
4987 dispatch_buffer = m;