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 MenuMakeLaTeX(Buffer *);
94 extern void MenuMakeLinuxDoc(Buffer *);
95 extern void MenuMakeDocBook(Buffer *);
96 extern void MenuMakeAscii(Buffer *);
97 extern void MenuPasteSelection(char at);
98 extern LyXAction lyxaction;
100 extern tex_accent_struct get_accent(kb_action action);
102 extern void AutoSave();
103 extern void MenuSearch();
104 extern void CopyCB();
105 extern void CopyEnvironmentCB();
106 extern void PasteEnvironmentCB();
107 extern void GotoNote();
108 extern void NoteCB();
109 extern void OpenStuff();
110 extern void HyphenationPoint();
112 extern void EndOfSentenceDot();
113 extern void MenuSeparator();
115 extern void MenuUndo();
116 extern void MenuRedo();
117 extern void SmallUpdate(signed char);
118 extern void SetUpdateTimer(float timer= 0.3);
119 extern void FreeUpdateTimer();
120 extern bool MenuPreview(Buffer*);
121 extern bool MenuPreviewPS(Buffer*);
122 extern void MenuInsertLabel(char const *);
123 extern void MenuInsertRef();
124 extern void MenuLayoutCharacter();
125 extern void MenuLayoutParagraph();
126 extern void MenuLayoutDocument();
127 extern void MenuLayoutPaper();
128 extern void MenuLayoutTable(int flag);
129 extern void MenuLayoutQuotes();
130 extern void MenuLayoutPreamble();
131 extern void MenuLayoutSave();
132 extern void bulletForm();
134 extern Buffer * NewLyxFile(string const &);
135 extern void LoadLyXFile(string const &);
136 extern void Reconfigure();
138 extern int current_layout;
139 extern int getISOCodeFromLaTeX(char *);
141 extern int UnlockInset(UpdatableInset *);
143 extern void ShowLatexLog();
145 extern void UpdateInset(Inset * inset, bool mark_dirty = true);
147 /* === globals =========================================================== */
149 bool LyXFunc::show_sc = true;
152 LyXFunc::LyXFunc(LyXView * o)
156 lyx_dead_action = LFUN_NOACTION;
157 lyx_calling_dead_action = LFUN_NOACTION;
162 // I changed this func slightly. I commented out the ...FinishUndo(),
163 // this means that all places that used to have a moveCursorUpdate, now
164 // have a ...FinishUndo() as the preceeding statement. I have also added
165 // a moveCursorUpdate to some of the functions that updated the cursor, but
166 // that did not show its new position.
168 void LyXFunc::moveCursorUpdate(bool selecting)
170 if (selecting || owner->buffer()->text->mark_set) {
171 owner->buffer()->text->SetSelection();
172 owner->view()->getScreen()->ToggleToggle();
173 owner->buffer()->update(0);
175 owner->buffer()->update(-2); // this IS necessary
178 owner->view()->getScreen()->ShowCursor();
180 /* ---> Everytime the cursor is moved, show the current font state. */
181 // should this too me moved out of this func?
182 //owner->getMiniBuffer()->Set(CurrentState());
186 int LyXFunc::processKeyEvent(XEvent * ev)
193 XKeyEvent * keyevent = &ev->xkey;
194 KeySym keysym_return;
196 num_bytes = LyXLookupString(ev, s_r, 10, &keysym_return);
198 if (lyxerr.debugging(Debug::KEY)) {
199 lyxerr << "KeySym is "
200 << XKeysymToString(keysym_return)
202 << keysym_return << "]"
203 << " and num_bytes is "
205 << " the string returned is \""
206 << s_r << '\"' << endl;
208 // Do nothing if we have nothing (JMarc)
209 if (num_bytes == 0 && keysym_return == NoSymbol) {
210 lyxerr[Debug::KEY] << "Empty kbd action (probably composing)"
215 // this function should be used always [asierra060396]
216 if (owner->view()->available() &&
217 owner->buffer()->the_locking_inset &&
218 keysym_return == XK_Escape) {
219 UnlockInset(owner->buffer()->the_locking_inset);
220 owner->buffer()->text->CursorRight();
224 // Can we be sure that this will work for all X-Windows
225 // implementations? (Lgb)
226 // This code snippet makes lyx ignore some keys. Perhaps
227 // all of them should be explictly mentioned?
228 if((keysym_return >= XK_Shift_L && keysym_return <= XK_Hyper_R)
229 || keysym_return == XK_Mode_switch || keysym_return == 0x0)
232 // Do a one-deep top-level lookup for
233 // cancel and meta-fake keys. RVDK_PATCH_5
234 cancel_meta_seq.reset();
236 action = cancel_meta_seq.addkey(keysym_return, keyevent->state
237 &(ShiftMask|ControlMask
240 // When not cancel or meta-fake, do the normal lookup.
241 // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
242 // Mostly, meta_fake_bit = 0. RVDK_PATCH_5.
243 if ( (action != LFUN_CANCEL) && (action != LFUN_META_FAKE) ) {
245 // remove Caps Lock and Mod2 as a modifiers
246 action = keyseq.addkey(keysym_return,
247 (keyevent->state | meta_fake_bit)
248 &(ShiftMask|ControlMask
251 // Dont remove this unless you know what you are doing.
254 if (action == 0) action = LFUN_PREFIX;
256 if (lyxerr.debugging(Debug::KEY)) {
258 keyseq.print(buf, 100);
262 << num_bytes << "]" << endl;
265 // already here we know if it any point in going further
266 // why not return already here if action == -1 and
267 // num_bytes == 0? (Lgb)
269 if(keyseq.length>1 || keyseq.length<-1){
271 keyseq.print(buf, 100);
272 owner->getMiniBuffer()->Set(buf);
276 if (keyseq.length<-1) { // unknown key sequence...
279 keyseq.print(buf, 100);
280 owner->getMiniBuffer()->Set(_("Unknown sequence:"), buf);
284 char isochar = keyseq.getiso();
285 if (!(keyevent->state&ControlMask) &&
286 !(keyevent->state&Mod1Mask) &&
287 (isochar && keysym_return < 0xF000)) {
290 if (argument.empty()) {
291 lyxerr.debug() << "Empty argument!" << endl;
292 // This can`t possibly be of any use
293 // so we`ll skip the dispatch.
297 if (action == LFUN_SELFINSERT) {
301 bool tmp_sc = show_sc;
303 Dispatch(action, argument.c_str());
310 LyXFunc::func_status LyXFunc::getStatus(int ac) const
313 func_status flag = LyXFunc::OK;
315 Buffer * buf = owner->buffer();
317 if (lyxaction.isPseudoAction(ac))
318 action = lyxaction.retrieveActionArg(ac, argument);
320 action = static_cast<kb_action>(ac);
322 if (action == LFUN_UNKNOWN_ACTION) {
323 setErrorMessage(N_("Unknown action"));
324 return LyXFunc::Unknown;
327 // Check whether we need a buffer
328 if (!lyxaction.funcHasFlag(action, LyXAction::NoBuffer)) {
329 // Yes we need a buffer, do we have one?
332 // Can we use a readonly buffer?
333 if (buf->isReadonly() &&
334 !lyxaction.funcHasFlag(action,
335 LyXAction::ReadOnly)) {
337 setErrorMessage(N_("Document is read-only"));
338 flag = func_status(flag | LyXFunc::Disabled);
342 setErrorMessage(N_("Command not allowed with"
343 "out any document open"));
344 flag = func_status(flag | LyXFunc::Disabled);
348 if (flag & LyXFunc::Disabled)
351 static bool noLaTeX = lyxrc->latex_command == "none";
352 bool disable = false;
355 disable = noLaTeX || lyxrc->view_dvi_command == "none";
358 disable = noLaTeX || lyxrc->view_ps_command == "none";
365 disable = noLaTeX || lyxrc->print_command == "none";
368 disable = noLaTeX || lyxrc->fax_command == "none";
371 if (argument == "latex")
372 disable = lyxrc->relyx_command == "none";
375 if (argument == "dvi" || argument == "postscript")
377 if (argument == "html")
378 disable = lyxrc->html_command == "none";
381 disable = buf->undostack.empty();
384 disable = buf->redostack.empty();
386 case LFUN_SPELLCHECK:
387 disable = lyxrc->isp_command == "none";
390 disable = lyxrc->chktex_command == "none";
392 case LFUN_LAYOUT_TABLE:
393 disable = ! buf->text->cursor.par->table;
399 flag |= LyXFunc::Disabled;
402 func_status box = LyXFunc::ToggleOff;
403 LyXFont font = buf->text->real_current_font;
406 if (font.emph() == LyXFont::ON)
407 box = LyXFunc::ToggleOn;
410 if (font.noun() == LyXFont::ON)
411 box = LyXFunc::ToggleOn;
414 if (font.series() == LyXFont::BOLD_SERIES)
415 box = LyXFunc::ToggleOn;
418 if (font.latex() == LyXFont::ON)
419 box = LyXFunc::ToggleOn;
433 string LyXFunc::Dispatch(string const & s)
435 // Split command string into command and argument
436 string cmd, line = frontStrip(s);
437 string arg = strip(frontStrip(split(line, cmd, ' ')));
439 return Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
443 string LyXFunc::Dispatch(int ac,
444 char const * do_not_use_this_arg)
449 FL_OBJECT * ob = 0; // This will disapear soon
451 // we have not done anything wrong yet.
453 dispatch_buffer.clear();
455 // if action is a pseudo-action, we need the real action
456 if (lyxaction.isPseudoAction(ac)) {
458 action = static_cast<kb_action>
459 (lyxaction.retrieveActionArg(ac, tmparg));
463 action = static_cast<kb_action>(ac);
464 if (do_not_use_this_arg)
465 argument = do_not_use_this_arg; // except here
468 selection_possible = false;
470 if (owner->view()->available()
471 && owner->view()->getScreen())
472 owner->view()->getScreen()->HideCursor();
474 // We cannot use this function here
475 if (getStatus(action) & Disabled)
476 goto exit_with_message;
478 commandshortcut.clear();
480 if (lyxrc->display_shortcuts && show_sc) {
481 if (action != LFUN_SELFINSERT) {
482 // Put name of command and list of shortcuts
483 // for it in minibuffer
484 string comname = lyxaction.getActionName(action);
486 int pseudoaction = action;
487 bool argsadded = false;
489 if (!argument.empty()) {
490 // If we have the command with argument,
493 lyxaction.searchActionArg(action,
496 if (pseudoaction == -1) {
497 pseudoaction = action;
499 comname += " " + argument;
504 string shortcuts = toplevel_keymap->findbinding(pseudoaction);
506 if (!shortcuts.empty()) {
507 comname += ": " + shortcuts;
508 } else if (!argsadded) {
509 comname += " " + argument;
512 if (!comname.empty()) {
513 comname = strip(comname);
514 commandshortcut = "(" + comname + ')';
515 owner->getMiniBuffer()->Set(commandshortcut);
516 // Here we could even add a small pause,
517 // to annoy the user and make him learn
519 // No! That will just annoy, not teach
520 // anything. The user will read the messages
521 // if they are interested. (Asger)
526 // If in math mode pass the control to
527 // the math inset [asierra060396]
528 if (owner->view()->available() &&
529 owner->buffer()->the_locking_inset) {
531 || (action == LFUN_UNKNOWN_ACTION && keyseq.length>= -1)) {
532 if (action == LFUN_UNKNOWN_ACTION && argument.empty()) {
533 argument = keyseq.getiso();
535 // Undo/Redo pre 0.13 is a bit tricky for insets.
536 if (action == LFUN_UNDO) {
538 UpdatableInset * inset =
539 owner->buffer()->the_locking_inset;
540 inset->GetCursorPos(slx, sly);
543 inset = static_cast<UpdatableInset*>(owner->buffer()->text->cursor.par->GetInset(owner->buffer()->text->cursor.pos));
545 inset->Edit(slx, sly);
548 if (action == LFUN_REDO) {
550 UpdatableInset * inset = owner->buffer()->the_locking_inset;
551 inset->GetCursorPos(slx, sly);
554 inset = static_cast<UpdatableInset*>(owner->buffer()->text->cursor.par->GetInset(owner->buffer()->text->cursor.pos));
556 inset->Edit(slx, sly);
559 if (owner->buffer()->the_locking_inset->LocalDispatch(action, argument.c_str()))
562 setMessage(N_("Text mode"));
563 if (action == LFUN_RIGHT || action == -1)
564 owner->buffer()->text->CursorRight();
565 if (action == LFUN_LEFT || action == LFUN_RIGHT)
572 // --- Misc -------------------------------------------
573 case LFUN_WORDFINDFORWARD :
574 case LFUN_WORDFINDBACKWARD : {
575 static string last_search;
576 string searched_string;
578 if (!argument.empty()) {
579 last_search = argument;
580 searched_string = argument;
582 searched_string = last_search;
585 LyXText * ltCur = owner->view()->buffer()->text ;
587 if (!searched_string.empty() &&
588 ((action == LFUN_WORDFINDBACKWARD) ?
589 ltCur->SearchBackward(searched_string.c_str()) :
590 ltCur->SearchForward(searched_string.c_str()))) {
592 // ??? What is that ???
593 owner->view()->buffer()->update(-2);
596 // clear the selection (if there is any)
597 owner->view()->getScreen()->ToggleSelection();
598 owner->view()->buffer()->text->ClearSelection();
600 // Move cursor so that successive C-s 's will not stand in place.
601 if( action == LFUN_WORDFINDFORWARD )
602 owner->buffer()->text->CursorRightOneWord();
603 owner->buffer()->text->FinishUndo();
604 moveCursorUpdate(false);
607 // set the new selection
608 // SetSelectionOverLenChars(owner->view()->currentBuffer()->text, iLenSelected);
609 owner->view()->getScreen()->ToggleSelection(false);
613 // REMOVED : if (owner->view()->getWorkArea()->focus)
614 owner->view()->getScreen()->ShowCursor();
620 if (owner->view()->available()
621 && owner->view()->getScreen()) {
622 owner->buffer()->update(-2);
625 keyseq.print(buf, 100, true);
626 owner->getMiniBuffer()->Set(buf, string(), string(), 1);
630 // --- Misc -------------------------------------------
631 case LFUN_EXEC_COMMAND:
632 owner->getMiniBuffer()->ExecCommand();
635 case LFUN_CANCEL: // RVDK_PATCH_5
638 if(owner->view()->available())
639 // cancel any selection
640 Dispatch(LFUN_MARK_OFF, 0);
641 setMessage(N_("Cancel"));
644 case LFUN_META_FAKE: // RVDK_PATCH_5
646 meta_fake_bit = Mod1Mask;
648 keyseq.print(buf, 98, true);
649 string res = string("M-") + buf;
650 setMessage(buf); // RVDK_PATCH_5
654 case LFUN_READ_ONLY_TOGGLE:
655 if (owner->buffer()->lyxvc.inUse()) {
656 owner->buffer()->lyxvc.toggleReadOnly();
658 owner->buffer()->setReadonly(
659 !owner->buffer()->isReadonly());
663 case LFUN_CENTER: // this is center and redraw.
665 if (owner->buffer()->text->cursor.y >
666 owner->view()->getWorkArea()->h / 2) {
667 owner->view()->getScreen()->
668 Draw(owner->buffer()->text->cursor.y -
669 owner->view()->getWorkArea()->h/2);
671 owner->view()->getScreen()->
674 owner->buffer()->update(0);
675 owner->view()->redraw();
679 if (owner->view()->available()) {
680 owner->buffer()->text->toggleAppendix();
681 owner->buffer()->update(1);
685 // --- Menus -----------------------------------------------
690 case LFUN_MENUNEWTMPLT:
698 case LFUN_CLOSEBUFFER:
703 MenuWrite(owner->buffer());
706 case LFUN_MENUWRITEAS:
707 MenuWriteAs(owner->buffer());
710 case LFUN_MENURELOAD:
715 MenuPreview(owner->buffer());
719 MenuPreviewPS(owner->buffer());
723 MenuRunLaTeX(owner->buffer());
727 MenuBuildProg(owner->buffer());
731 MenuRunChktex(owner->buffer());
735 MenuRunDvips(owner->buffer(), false);
739 MenuPrint(owner->buffer());
743 MenuFax(owner->buffer());
748 //needs argument as string
749 string extyp = argument;
752 if (extyp == "latex") {
753 // make sure that this buffer is not linuxdoc
754 MenuMakeLaTeX(owner->buffer());
757 else if (extyp == "linuxdoc") {
758 // make sure that this buffer is not latex
759 MenuMakeLinuxDoc(owner->buffer());
762 else if (extyp == "docbook") {
763 // make sure that this buffer is not latex or linuxdoc
764 MenuMakeDocBook(owner->buffer());
767 else if (extyp == "dvi") {
768 // Run LaTeX as "Update dvi..." Bernhard.
769 // We want the dvi in the current directory. This
770 // is achieved by temporarily disabling use of
771 // temp directory. As a side-effect, we get
772 // *.log and *.aux files also. (Asger)
773 bool flag = lyxrc->use_tempdir;
774 lyxrc->use_tempdir = false;
775 MenuRunLaTeX(owner->buffer());
776 lyxrc->use_tempdir = flag;
779 else if (extyp == "postscript") {
780 // Start Print-dialog. Not as good as dvi... Bernhard.
781 MenuPrint(owner->buffer());
782 // Since the MenuPrint is a pop-up, we can't use
783 // the same trick as above. (Asger)
784 // MISSING: Move of ps-file :-(
787 else if (extyp == "ascii") {
788 MenuMakeAscii(owner->buffer());
790 else if (extyp == "custom") {
795 else if (extyp == "html" && lyxrc->html_command != "none") {
796 // First, create LaTeX file
797 MenuMakeLaTeX(owner->buffer());
799 // And now, run the converter
800 string file = owner->buffer()->getFileName();
801 Path path(OnlyPath(file));
802 // the tex file name has to be correct for
803 // latex, but the html file name can be
805 string result = ChangeExtension(file, ".html", false);
806 string infile = owner->buffer()->getLatexName();
807 string tmp = lyxrc->html_command;
808 tmp = subst(tmp, "$$FName", infile);
809 tmp = subst(tmp, "$$OutName", result);
811 int res = one.startscript(Systemcalls::System, tmp);
813 setMessage(N_("Document exported as HTML to file `")
814 + MakeDisplayPath(result) +'\'');
816 setErrorMessage(N_("Unable to convert to HTML the file `")
817 + MakeDisplayPath(infile)
822 setErrorMessage(N_("Unknown export type: ")
830 //needs argument as string
831 string imtyp = argument;
834 if (imtyp == "latex") {
835 doImportLaTeX(false);
838 else if (imtyp == "ascii") {
839 doImportASCII(false);
840 } else if (imtyp == "asciiparagraph") {
843 } else if (imtyp == "noweb") {
846 setErrorMessage(string(N_("Unknown import type: "))
858 if (fd_form_toc->form_toc->visible) {
859 fl_raise_form(fd_form_toc->form_toc);
861 static int ow = -1, oh;
862 fl_show_form(fd_form_toc->form_toc,
864 FL_FREE_SIZE, FL_FULLBORDER,
865 _("Table of Contents"));
867 ow = fd_form_toc->form_toc->w;
868 oh = fd_form_toc->form_toc->h;
870 fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
874 case LFUN_TOC_INSERT:
876 Inset * new_inset = new InsetTOC(owner->buffer());
877 owner->buffer()->insertInset(new_inset, "Standard", true);
881 case LFUN_LOF_INSERT:
883 Inset * new_inset = new InsetLOF(owner->buffer());
884 owner->buffer()->insertInset(new_inset, "Standard", true);
888 case LFUN_LOA_INSERT:
890 Inset * new_inset = new InsetLOA(owner->buffer());
891 owner->buffer()->insertInset(new_inset, "Standard", true);
895 case LFUN_LOT_INSERT:
897 Inset * new_inset = new InsetLOT(owner->buffer());
898 owner->buffer()->insertInset(new_inset, "Standard", true);
922 case LFUN_MENUSEARCH:
930 case LFUN_PASTESELECTION:
933 if (argument == "paragraph") asPara = true;
934 MenuPasteSelection(asPara);
946 case LFUN_LAYOUT_COPY:
950 case LFUN_LAYOUT_PASTE:
951 PasteEnvironmentCB();
955 owner->view()->gotoError();
958 case LFUN_REMOVEERRORS:
959 if (owner->buffer()->removeAutoInsets()) {
960 owner->view()->redraw();
961 owner->view()->fitCursor();
962 owner->view()->updateScrollbar();
974 case LFUN_HYPHENATION:
982 case LFUN_END_OF_SENTENCE:
986 case LFUN_MENU_SEPARATOR:
1002 case LFUN_DEPTH_PLUS:
1018 case LFUN_RECONFIGURE:
1023 if (owner->view()->available()
1024 && !owner->buffer()->text->selection
1025 && owner->buffer()->text->cursor.par->footnoteflag
1026 != LyXParagraph::NO_FOOTNOTE)
1027 { // only melt footnotes with FOOTMELT, not margins etc
1028 if(owner->buffer()->text->cursor.par->footnotekind == LyXParagraph::FOOTNOTE)
1035 case LFUN_MARGINMELT:
1036 if (owner->view()->available()
1037 && !owner->buffer()->text->selection
1038 && owner->buffer()->text->cursor.par->footnoteflag
1039 != LyXParagraph::NO_FOOTNOTE) {
1040 // only melt margins
1041 if(owner->buffer()->text->cursor.par->footnotekind == LyXParagraph::MARGIN)
1048 // --- version control -------------------------------
1049 case LFUN_VC_REGISTER:
1051 if (!owner->buffer()->lyxvc.inUse())
1052 owner->buffer()->lyxvc.registrer();
1056 case LFUN_VC_CHECKIN:
1058 if (owner->buffer()->lyxvc.inUse()
1059 && !owner->buffer()->isReadonly())
1060 owner->buffer()->lyxvc.checkIn();
1064 case LFUN_VC_CHECKOUT:
1066 if (owner->buffer()->lyxvc.inUse()
1067 && owner->buffer()->isReadonly())
1068 owner->buffer()->lyxvc.checkOut();
1072 case LFUN_VC_REVERT:
1074 owner->buffer()->lyxvc.revert();
1080 owner->buffer()->lyxvc.undoLast();
1084 case LFUN_VC_HISTORY:
1086 owner->buffer()->lyxvc.showLog();
1090 // --- buffers ----------------------------------------
1091 case LFUN_PREVBUFFER:
1092 #ifdef WITH_WARNINGS
1093 #warning fix this please
1095 // it is the LyXView or the BufferView that should
1096 // remember the previous buffer, not bufferlist.
1097 // if (owner->view()->available()){
1099 // owner->buffer()->update(-2);
1101 // owner->view()->setBuffer(bufferlist.prev());
1104 // resizeCurrentBufferPseudoExpose();
1107 case LFUN_FILE_INSERT:
1109 MenuInsertLyXFile(argument);
1113 case LFUN_FILE_INSERT_ASCII:
1115 bool asPara = (argument == "paragraph");
1116 InsertAsciiFile(string(), asPara);
1122 // servercmd: argument must be <file>:<template>
1123 Buffer * tmpbuf = NewLyxFile(argument);
1125 owner->view()->buffer(tmpbuf);
1129 case LFUN_FILE_OPEN:
1130 owner->view()->buffer(
1131 bufferlist.loadLyXFile(argument));
1134 case LFUN_LATEX_LOG:
1140 lyxerr.debug() << "LFUN_LAYOUTNO: (arg) " << argument << endl;
1141 int sel = strToInt(argument);
1142 lyxerr.debug() << "LFUN_LAYOUTNO: (sel) "<< sel << endl;
1144 // Should this give a setMessage instead?
1146 return string(); // illegal argument
1148 sel--; // sel 1..., but layout 0...
1150 // Pretend we got the name instead.
1151 Dispatch(int(LFUN_LAYOUT),
1152 textclasslist.NameOfLayout(owner->buffer()->
1161 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1162 << argument << endl;
1164 // Derive layout number from given argument (string)
1165 // and current buffer's textclass (number). */
1167 textclasslist.NumberOfLayout(owner->
1173 // see if we found the layout number:
1174 if (layoutno == -1) {
1175 setErrorMessage(string(N_("Layout ")) + argument +
1180 if (current_layout != layoutno) {
1181 owner->view()->getScreen()->HideCursor();
1182 current_layout = layoutno;
1183 owner->buffer()->update(-2);
1184 owner->buffer()->text->
1185 SetLayout(layoutno);
1186 owner->getToolbar()->combox->
1187 select(owner->buffer()->
1190 owner->buffer()->update(1);
1195 case LFUN_LAYOUT_DOCUMENT:
1196 MenuLayoutDocument();
1199 case LFUN_LAYOUT_PARAGRAPH:
1200 MenuLayoutParagraph();
1203 case LFUN_LAYOUT_CHARACTER:
1204 MenuLayoutCharacter();
1207 case LFUN_LAYOUT_TABLE:
1210 if (argument == "true") flag = 1;
1211 MenuLayoutTable(flag);
1215 case LFUN_LAYOUT_PAPER:
1219 case LFUN_LAYOUT_QUOTES:
1223 case LFUN_LAYOUT_PREAMBLE:
1224 MenuLayoutPreamble();
1227 case LFUN_LAYOUT_SAVE_DEFAULT:
1231 case LFUN_DROP_LAYOUTS_CHOICE:
1232 owner->getToolbar()->combox->Show();
1263 case LFUN_UNDERLINE:
1267 case LFUN_FONT_SIZE:
1268 FontSizeCB(argument);
1271 case LFUN_FONT_STATE:
1272 setMessage(CurrentState());
1275 case LFUN_UPCASE_WORD:
1276 owner->buffer()->update(-2);
1278 owner->buffer()->text->ChangeWordCase(LyXText::text_uppercase);
1279 owner->buffer()->update(1);
1283 case LFUN_LOWCASE_WORD:
1284 owner->buffer()->update(-2);
1286 owner->buffer()->text->ChangeWordCase(LyXText::text_lowercase);
1287 owner->buffer()->update(1);
1291 case LFUN_CAPITALIZE_WORD:
1292 owner->buffer()->update(-2);
1294 owner->buffer()->text->ChangeWordCase(LyXText::text_capitalization);
1295 owner->buffer()->update(1);
1299 case LFUN_INSERT_LABEL:
1300 MenuInsertLabel(argument.c_str());
1303 case LFUN_INSERT_REF:
1307 case LFUN_REFTOGGLE:
1310 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1312 if (inset->getFlag() == InsetRef::REF)
1313 inset->setFlag(InsetRef::PAGE_REF);
1315 inset->setFlag(InsetRef::REF);
1318 setErrorMessage(N_("No cross-reference to toggle"));
1325 owner->view()->restorePosition();
1331 string label(argument);
1332 if (label.empty()) {
1334 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1336 label = inset->getContents();
1339 if (!label.empty()) {
1340 owner->view()->savePosition();
1341 owner->buffer()->gotoLabel(label.c_str());
1346 case LFUN_MENU_OPEN_BY_NAME:
1347 owner->getMenus()->openByName(argument);
1348 break; // RVDK_PATCH_5
1350 case LFUN_SPELLCHECK:
1351 if (lyxrc->isp_command != "none")
1353 break; // RVDK_PATCH_5
1355 // --- Cursor Movements -----------------------------
1358 Buffer * tmpbuffer = owner->buffer();
1359 LyXText * tmptext = owner->buffer()->text;
1360 if(!tmptext->mark_set)
1362 tmpbuffer->update(-2);
1363 if (tmptext->cursor.pos < tmptext->cursor.par->Last()
1364 && tmptext->cursor.par->GetChar(tmptext->cursor.pos)
1365 == LyXParagraph::META_INSET
1366 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)
1367 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)->Editable() == 2){
1368 Inset * tmpinset = tmptext->cursor.par->GetInset(tmptext->cursor.pos);
1369 setMessage(tmpinset->EditMessage());
1370 tmpinset->Edit(0, 0);
1373 tmptext->CursorRight();
1374 owner->buffer()->text->FinishUndo();
1375 moveCursorUpdate(false);
1376 owner->getMiniBuffer()->Set(CurrentState());
1382 // This is soooo ugly. Isn`t it possible to make
1383 // it simpler? (Lgb)
1384 LyXText * txt = owner->buffer()->text;
1385 if(!txt->mark_set) BeforeChange();
1386 owner->buffer()->update(-2);
1388 if (txt->cursor.pos < txt->cursor.par->Last()
1389 && txt->cursor.par->GetChar(txt->cursor.pos)
1390 == LyXParagraph::META_INSET
1391 && txt->cursor.par->GetInset(txt->cursor.pos)
1392 && txt->cursor.par->GetInset(txt->cursor.pos)->Editable() == 2) {
1393 Inset * tmpinset = txt->cursor.par->GetInset(txt->cursor.pos);
1394 setMessage(tmpinset->EditMessage());
1395 tmpinset->Edit(tmpinset->Width(txt->GetFont(txt->cursor.par,
1396 txt->cursor.pos)), 0);
1399 owner->buffer()->text->FinishUndo();
1400 moveCursorUpdate(false);
1401 owner->getMiniBuffer()->Set(CurrentState());
1406 if(!owner->buffer()->text->mark_set) BeforeChange();
1407 owner->buffer()->update(-3);
1408 owner->buffer()->text->CursorUp();
1409 owner->buffer()->text->FinishUndo();
1410 moveCursorUpdate(false);
1411 owner->getMiniBuffer()->Set(CurrentState());
1415 if(!owner->buffer()->text->mark_set)
1417 owner->buffer()->update(-3);
1418 owner->buffer()->text->CursorDown();
1419 owner->buffer()->text->FinishUndo();
1420 moveCursorUpdate(false);
1421 owner->getMiniBuffer()->Set(CurrentState());
1424 case LFUN_UP_PARAGRAPH:
1425 if(!owner->buffer()->text->mark_set)
1427 owner->buffer()->update(-3);
1428 owner->buffer()->text->CursorUpParagraph();
1429 owner->buffer()->text->FinishUndo();
1430 moveCursorUpdate(false);
1431 owner->getMiniBuffer()->Set(CurrentState());
1434 case LFUN_DOWN_PARAGRAPH:
1435 if(!owner->buffer()->text->mark_set)
1437 owner->buffer()->update(-3);
1438 owner->buffer()->text->CursorDownParagraph();
1439 owner->buffer()->text->FinishUndo();
1440 moveCursorUpdate(false);
1441 owner->getMiniBuffer()->Set(CurrentState());
1445 if(!owner->buffer()->text->mark_set)
1447 owner->buffer()->update(-3);
1448 owner->view()->cursorPrevious();
1449 owner->buffer()->text->FinishUndo();
1450 moveCursorUpdate(false);
1451 owner->getMiniBuffer()->Set(CurrentState());
1455 if(!owner->buffer()->text->mark_set)
1457 owner->buffer()->update(-3);
1458 owner->view()->cursorNext();
1459 owner->buffer()->text->FinishUndo();
1460 moveCursorUpdate(false);
1461 owner->getMiniBuffer()->Set(CurrentState());
1465 if(!owner->buffer()->text->mark_set)
1467 owner->buffer()->update(-2);
1468 owner->buffer()->text->CursorHome();
1469 owner->buffer()->text->FinishUndo();
1470 moveCursorUpdate(false);
1471 owner->getMiniBuffer()->Set(CurrentState());
1475 if(!owner->buffer()->text->mark_set)
1477 owner->buffer()->update(-2);
1478 owner->buffer()->text->CursorEnd();
1479 owner->buffer()->text->FinishUndo();
1480 moveCursorUpdate(false);
1481 owner->getMiniBuffer()->Set(CurrentState());
1485 if(!owner->buffer()->text->mark_set)
1487 owner->buffer()->update(-2);
1488 owner->buffer()->text->CursorTab();
1489 owner->buffer()->text->FinishUndo();
1490 moveCursorUpdate(false);
1491 owner->getMiniBuffer()->Set(CurrentState());
1494 case LFUN_WORDRIGHT:
1495 if(!owner->buffer()->text->mark_set)
1497 owner->buffer()->update(-2);
1498 owner->buffer()->text->CursorRightOneWord();
1499 owner->buffer()->text->FinishUndo();
1500 moveCursorUpdate(false);
1501 owner->getMiniBuffer()->Set(CurrentState());
1505 if(!owner->buffer()->text->mark_set)
1507 owner->buffer()->update(-2);
1508 owner->buffer()->text->CursorLeftOneWord();
1509 owner->buffer()->text->FinishUndo();
1510 moveCursorUpdate(false);
1511 owner->getMiniBuffer()->Set(CurrentState());
1514 case LFUN_BEGINNINGBUF:
1515 if(!owner->buffer()->text->mark_set)
1517 owner->buffer()->update(-2);
1518 owner->buffer()->text->CursorTop();
1519 owner->buffer()->text->FinishUndo();
1520 moveCursorUpdate(false);
1521 owner->getMiniBuffer()->Set(CurrentState());
1525 if(!owner->buffer()->text->mark_set)
1527 owner->buffer()->update(-2);
1528 owner->buffer()->text->CursorBottom();
1529 owner->buffer()->text->FinishUndo();
1530 moveCursorUpdate(false);
1531 owner->getMiniBuffer()->Set(CurrentState());
1535 /* cursor selection ---------------------------- */
1537 owner->buffer()->update(-2);
1538 owner->buffer()->text->CursorRight();
1539 owner->buffer()->text->FinishUndo();
1540 moveCursorUpdate(true);
1541 owner->getMiniBuffer()->Set(CurrentState());
1545 owner->buffer()->update(-2);
1546 owner->buffer()->text->CursorLeft();
1547 owner->buffer()->text->FinishUndo();
1548 moveCursorUpdate(true);
1549 owner->getMiniBuffer()->Set(CurrentState());
1553 owner->buffer()->update(-2);
1554 owner->buffer()->text->CursorUp();
1555 owner->buffer()->text->FinishUndo();
1556 moveCursorUpdate(true);
1557 owner->getMiniBuffer()->Set(CurrentState());
1561 owner->buffer()->update(-2);
1562 owner->buffer()->text->CursorDown();
1563 owner->buffer()->text->FinishUndo();
1564 moveCursorUpdate(true);
1565 owner->getMiniBuffer()->Set(CurrentState());
1568 case LFUN_UP_PARAGRAPHSEL:
1569 owner->buffer()->update(-2);
1570 owner->buffer()->text->CursorUpParagraph();
1571 owner->buffer()->text->FinishUndo();
1572 moveCursorUpdate(true);
1573 owner->getMiniBuffer()->Set(CurrentState());
1576 case LFUN_DOWN_PARAGRAPHSEL:
1577 owner->buffer()->update(-2);
1578 owner->buffer()->text->CursorDownParagraph();
1579 owner->buffer()->text->FinishUndo();
1580 moveCursorUpdate(true);
1581 owner->getMiniBuffer()->Set(CurrentState());
1585 owner->buffer()->update(-2);
1586 owner->view()->cursorPrevious();
1587 owner->buffer()->text->FinishUndo();
1588 moveCursorUpdate(true);
1589 owner->getMiniBuffer()->Set(CurrentState());
1593 owner->buffer()->update(-2);
1594 owner->view()->cursorNext();
1595 owner->buffer()->text->FinishUndo();
1596 moveCursorUpdate(true);
1597 owner->getMiniBuffer()->Set(CurrentState());
1601 owner->buffer()->update(-2);
1602 owner->buffer()->text->CursorHome();
1603 owner->buffer()->text->FinishUndo();
1604 moveCursorUpdate(true);
1605 owner->getMiniBuffer()->Set(CurrentState());
1609 owner->buffer()->update(-2);
1610 owner->buffer()->text->CursorEnd();
1611 owner->buffer()->text->FinishUndo();
1612 moveCursorUpdate(true);
1613 owner->getMiniBuffer()->Set(CurrentState());
1616 case LFUN_WORDRIGHTSEL:
1617 owner->buffer()->update(-2);
1618 owner->buffer()->text->CursorRightOneWord();
1619 owner->buffer()->text->FinishUndo();
1620 moveCursorUpdate(true);
1621 owner->getMiniBuffer()->Set(CurrentState());
1624 case LFUN_WORDLEFTSEL:
1625 owner->buffer()->update(-2);
1626 owner->buffer()->text->CursorLeftOneWord();
1627 owner->buffer()->text->FinishUndo();
1628 moveCursorUpdate(true);
1629 owner->getMiniBuffer()->Set(CurrentState());
1632 case LFUN_BEGINNINGBUFSEL:
1633 owner->buffer()->update(-2);
1634 owner->buffer()->text->CursorTop();
1635 owner->buffer()->text->FinishUndo();
1636 moveCursorUpdate(true);
1637 owner->getMiniBuffer()->Set(CurrentState());
1640 case LFUN_ENDBUFSEL:
1641 owner->buffer()->update(-2);
1642 owner->buffer()->text->CursorBottom();
1643 owner->buffer()->text->FinishUndo();
1644 moveCursorUpdate(true);
1645 owner->getMiniBuffer()->Set(CurrentState());
1648 // --- text changing commands ------------------------
1649 case LFUN_BREAKLINE:
1651 owner->buffer()->text->InsertChar(LyXParagraph::META_NEWLINE);
1653 SetUpdateTimer(0.01);
1654 moveCursorUpdate(false);
1657 case LFUN_PROTECTEDSPACE:
1659 owner->buffer()->text->
1660 InsertChar(LyXParagraph::META_PROTECTED_SEPARATOR);
1663 moveCursorUpdate(false);
1667 if(owner->buffer()->text->mark_set) {
1669 owner->buffer()->update(0);
1670 setMessage(N_("Mark removed"));
1673 owner->buffer()->text->mark_set = 1;
1674 owner->buffer()->update(0);
1675 setMessage(N_("Mark set"));
1677 owner->buffer()->text->sel_cursor =
1678 owner->buffer()->text->cursor;
1683 if (!owner->buffer()->text->selection) {
1684 owner->buffer()->text->Delete();
1685 owner->buffer()->text->sel_cursor =
1686 owner->buffer()->text->cursor;
1688 // It is possible to make it a lot faster still
1689 // just comment out the lone below...
1690 owner->view()->getScreen()->ShowCursor();
1697 case LFUN_DELETE_SKIP:
1699 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1701 LyXCursor cursor = owner->buffer()->text->cursor;
1704 if (!owner->buffer()->text->selection) {
1705 if (cursor.pos == cursor.par->Last()) {
1706 owner->buffer()->text->CursorRight();
1707 cursor = owner->buffer()->text->cursor;
1709 && !(cursor.par->added_space_top
1710 == VSpace (VSpace::NONE))) {
1711 owner->buffer()->text->SetParagraph
1712 (cursor.par->line_top,
1713 cursor.par->line_bottom,
1714 cursor.par->pagebreak_top,
1715 cursor.par->pagebreak_bottom,
1716 VSpace(VSpace::NONE),
1717 cursor.par->added_space_bottom,
1719 cursor.par->labelwidthstring, 0);
1720 owner->buffer()->text->CursorLeft();
1721 owner->buffer()->update (1);
1723 owner->buffer()->text->CursorLeft();
1724 owner->buffer()->text->Delete();
1725 owner->buffer()->text->sel_cursor =
1726 owner->buffer()->text->cursor;
1730 owner->buffer()->text->Delete();
1731 owner->buffer()->text->sel_cursor =
1732 owner->buffer()->text->cursor;
1742 /* -------> Delete word forward. */
1743 case LFUN_DELETE_WORD_FORWARD:
1744 owner->buffer()->update(-2);
1746 owner->buffer()->text->DeleteWordForward();
1747 owner->buffer()->update( 1 );
1749 moveCursorUpdate(false);
1752 /* -------> Delete word backward. */
1753 case LFUN_DELETE_WORD_BACKWARD:
1754 owner->buffer()->update(-2);
1756 owner->buffer()->text->DeleteWordBackward();
1757 owner->buffer()->update( 1 );
1759 moveCursorUpdate(false);
1762 /* -------> Kill to end of line. */
1763 case LFUN_DELETE_LINE_FORWARD:
1765 owner->buffer()->update(-2);
1766 owner->buffer()->text->DeleteLineForward();
1767 owner->buffer()->update( 1 );
1769 moveCursorUpdate(false);
1772 /* -------> Set mark off. */
1775 owner->buffer()->update(0);
1776 owner->buffer()->text->sel_cursor =
1777 owner->buffer()->text->cursor;
1778 setMessage(N_("Mark off"));
1781 /* -------> Set mark on. */
1784 owner->buffer()->text->mark_set = 1;
1785 owner->buffer()->update( 0 );
1786 owner->buffer()->text->sel_cursor =
1787 owner->buffer()->text->cursor;
1788 setMessage(N_("Mark on"));
1791 case LFUN_BACKSPACE:
1794 if (!owner->buffer()->text->selection) {
1795 if (owner->getIntl()->getTrans()->backspace()) {
1796 owner->buffer()->text->Backspace();
1797 owner->buffer()->text->sel_cursor =
1798 owner->buffer()->text->cursor;
1800 // It is possible to make it a lot faster still
1801 // just comment out the lone below...
1802 owner->view()->getScreen()->ShowCursor();
1811 case LFUN_BACKSPACE_SKIP:
1813 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1815 LyXCursor cursor = owner->buffer()->text->cursor;
1818 if (!owner->buffer()->text->selection) {
1820 && !(cursor.par->added_space_top
1821 == VSpace (VSpace::NONE))) {
1822 owner->buffer()->text->SetParagraph
1823 (cursor.par->line_top,
1824 cursor.par->line_bottom,
1825 cursor.par->pagebreak_top,
1826 cursor.par->pagebreak_bottom,
1827 VSpace(VSpace::NONE), cursor.par->added_space_bottom,
1829 cursor.par->labelwidthstring, 0);
1830 owner->buffer()->update (1);
1832 owner->buffer()->text->Backspace();
1833 owner->buffer()->text->sel_cursor
1843 case LFUN_BREAKPARAGRAPH:
1846 owner->buffer()->text->BreakParagraph(0);
1848 SetUpdateTimer(0.01);
1849 owner->buffer()->text->sel_cursor =
1850 owner->buffer()->text->cursor;
1854 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1857 owner->buffer()->text->BreakParagraph(1);
1859 SetUpdateTimer(0.01);
1860 owner->buffer()->text->sel_cursor =
1861 owner->buffer()->text->cursor;
1865 case LFUN_BREAKPARAGRAPH_SKIP:
1867 // When at the beginning of a paragraph, remove
1868 // indentation and add a "defskip" at the top.
1869 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
1871 LyXCursor cursor = owner->buffer()->text->cursor;
1874 if (cursor.pos == 0) {
1875 if (cursor.par->added_space_top == VSpace(VSpace::NONE)) {
1876 owner->buffer()->text->SetParagraph
1877 (cursor.par->line_top,
1878 cursor.par->line_bottom,
1879 cursor.par->pagebreak_top,
1880 cursor.par->pagebreak_bottom,
1881 VSpace(VSpace::DEFSKIP), cursor.par->added_space_bottom,
1883 cursor.par->labelwidthstring, 1);
1884 owner->buffer()->update(1);
1888 owner->buffer()->text->BreakParagraph(0);
1891 SetUpdateTimer(0.01);
1892 owner->buffer()->text->sel_cursor = cursor;
1898 owner->buffer()->text->InsertChar('\"'); // This " matches the single quote in the code
1901 moveCursorUpdate(false);
1907 InsetCommand * new_inset;
1908 if (action == LFUN_HTMLURL)
1909 new_inset = new InsetUrl("htmlurl", "", "");
1911 new_inset = new InsetUrl("url", "", "");
1912 owner->buffer()->insertInset(new_inset);
1913 new_inset->Edit(0, 0);
1917 // --- lyxserver commands ----------------------------
1919 case LFUN_CHARATCURSOR:
1921 LyXParagraph::size_type pos =
1922 owner->buffer()->text->cursor.pos;
1923 if(pos < owner->buffer()->text->cursor.par->size())
1924 dispatch_buffer = owner->buffer()->text->
1925 cursor.par->text[pos];
1927 dispatch_buffer = "EOF";
1933 tostr(owner->buffer()->text->cursor.x) + ' '
1934 + tostr(owner->buffer()->text->cursor.y);
1941 sscanf(argument.c_str(), " %d %ld", &x, &y);
1942 owner->buffer()->text->SetCursorFromCoordinates(x, y);
1946 case LFUN_GETLAYOUT:
1948 tostr(owner->buffer()->text->cursor.par->layout);
1953 LyXFont *font = &(owner->buffer()->text->current_font);
1954 if(font->shape() == LyXFont::ITALIC_SHAPE)
1955 dispatch_buffer = 'E';
1956 else if(font->shape() == LyXFont::SMALLCAPS_SHAPE)
1957 dispatch_buffer = 'N';
1959 dispatch_buffer = '0';
1966 LyXFont *font = &(owner->buffer()->text->current_font);
1967 if(font->latex() == LyXFont::ON)
1968 dispatch_buffer = 'L';
1970 dispatch_buffer = '0';
1975 setMessage(owner->buffer()->getFileName());
1976 lyxerr.debug() << "FNAME["
1977 << owner->buffer()->getFileName()
1984 keyseq.print(buf, 100);
1985 dispatch_buffer = buf;
1986 lyxserver->notifyClient(dispatch_buffer);
1990 case LFUN_GOTOFILEROW:
1992 char file_name[100];
1994 sscanf(argument.c_str(), " %s %d", file_name, &row);
1996 // Must replace extension of the file to be .lyx and get full path
1997 string s = ChangeExtension(string(file_name), ".lyx", false);
1999 // Either change buffer or load the file
2000 if (bufferlist.exists(s))
2001 owner->view()->buffer(bufferlist.getBuffer(s));
2003 owner->view()->buffer(bufferlist.loadLyXFile(s));
2006 owner->buffer()->setCursorFromRow(row);
2010 if (owner->buffer()->text->cursor.y >
2011 owner->view()->getWorkArea()->h / 2) {
2012 owner->view()->getScreen()->
2013 Draw(owner->buffer()->text->cursor.y -
2014 owner->view()->getWorkArea()->h/2);
2016 owner->view()->getScreen()->
2019 owner->buffer()->update(0);
2020 owner->view()->redraw();
2027 int qa = lyxaction.LookupFunc(argument.c_str());
2028 setMessage(lyxaction.helpText((kb_action)qa));
2032 // --- accented characters ---------------------------
2035 case LFUN_CIRCUMFLEX:
2045 case LFUN_SPECIAL_CARON:
2048 case LFUN_HUNG_UMLAUT:
2054 if (keyseq.length == -1 && keyseq.getiso()!= 0)
2059 owner->getIntl()->getTrans()->
2060 deadkey(c, get_accent(action).accent,
2061 owner->buffer()->text);
2063 // Need to reset, in case the minibuffer calls these
2068 // copied verbatim from do_accent_char
2071 owner->buffer()->text->sel_cursor =
2072 owner->buffer()->text->cursor;
2076 // --- toolbar ----------------------------------
2077 case LFUN_PUSH_TOOLBAR:
2079 int nth = strToInt(argument);
2080 if (lyxerr.debugging(Debug::TOOLBAR)) {
2081 lyxerr << "LFUN_PUSH_TOOLBAR: argument = `"
2082 << argument << "'\n"
2083 << "LFUN_PUSH_TOOLBAR: nth = `"
2084 << nth << "'" << endl;
2089 setErrorMessage(N_("Push-toolbar needs argument > 0"));
2091 owner->getToolbar()->push(nth);
2096 case LFUN_ADD_TO_TOOLBAR:
2098 if (lyxerr.debugging(Debug::TOOLBAR)) {
2099 lyxerr << "LFUN_ADD_TO_TOOLBAR:"
2100 "argument = `" << argument << '\'' << endl;
2102 string tmp(argument);
2103 //lyxerr <<string("Argument: ") + argument);
2104 //lyxerr <<string("Tmp : ") + tmp);
2107 setErrorMessage(N_("Usage: toolbar-add-to <LyX command>"));
2109 owner->getToolbar()->add(argument, false);
2110 owner->getToolbar()->set();
2115 // --- insert characters ----------------------------------------
2117 case LFUN_INSERT_INSET_LATEX:
2119 Inset *new_inset = new InsetLatex(argument);
2120 owner->buffer()->insertInset(new_inset);
2124 // --- Mathed stuff. If we are here, there is no locked inset yet.
2129 if (!greek_kb_flag) {
2131 setMessage(N_("Math greek mode on"));
2138 case LFUN_GREEK_TOGGLE:
2140 greek_kb_flag = (greek_kb_flag) ? 0: 2;
2141 if (greek_kb_flag) {
2142 setMessage(N_("Math greek keyboard on"));
2144 setMessage(N_("Math greek keyboard off"));
2149 case LFUN_MATH_DELIM:
2150 case LFUN_INSERT_MATRIX:
2152 if (owner->view()->available()) {
2154 open_new_inset(new InsetFormula(false));
2156 the_locking_inset->LocalDispatch(action, argument.c_str());
2161 case LFUN_INSERT_MATH:
2163 math_insert_symbol(argument.c_str());
2167 case LFUN_MATH_DISPLAY:
2169 if (owner->view()->available())
2170 owner->buffer()->open_new_inset(new InsetFormula(true));
2174 case LFUN_MATH_MACRO:
2176 if (owner->view()->available()) {
2179 setErrorMessage(N_("Missing argument"));
2181 string s1 = token(s, ' ', 1);
2182 int na = s1.empty() ? 0: atoi(s1.c_str());
2184 open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2190 case LFUN_MATH_MODE: // Open or create a math inset
2193 if (owner->view()->available())
2194 owner->buffer()->open_new_inset(new InsetFormula);
2195 setMessage(N_("Math editor mode"));
2199 case LFUN_MATH_NUMBER:
2200 case LFUN_MATH_LIMITS:
2202 setErrorMessage(N_("This is only allowed in math mode!"));
2206 case LFUN_INSERT_CITATION:
2208 InsetCitation * new_inset = new InsetCitation();
2210 // The note, if any, must be after the key, delimited
2211 // by a | so both key and remark can have spaces.
2212 if (!argument.empty()) {
2213 string lsarg(argument);
2214 if (contains(lsarg, "|")) {
2215 new_inset->setContents(token(lsarg, '|', 0));
2216 new_inset->setOptions(token(lsarg, '|', 1));
2218 new_inset->setContents(lsarg);
2219 owner->buffer()->insertInset(new_inset);
2221 owner->buffer()->insertInset(new_inset);
2222 new_inset->Edit(0, 0);
2227 case LFUN_INSERT_BIBTEX:
2229 // ale970405+lasgoutt970425
2230 // The argument can be up to two tokens separated
2231 // by a space. The first one is the bibstyle.
2232 string lsarg(argument);
2233 string bibstyle = token(lsarg, ' ', 1);
2234 if (bibstyle.empty())
2236 InsetBibtex * new_inset
2237 = new InsetBibtex(token(lsarg, ' ', 0),
2241 owner->buffer()->insertInset(new_inset);
2242 if (lsarg.empty()) {
2243 new_inset->Edit(0, 0);
2248 // BibTeX data bases
2249 case LFUN_BIBDB_ADD:
2251 InsetBibtex * inset =
2252 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2254 inset->addDatabase(argument);
2259 case LFUN_BIBDB_DEL:
2261 InsetBibtex * inset =
2262 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2264 inset->delDatabase(argument);
2269 case LFUN_BIBTEX_STYLE:
2271 InsetBibtex * inset =
2272 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2274 inset->setOptions(argument);
2279 case LFUN_INDEX_INSERT:
2280 case LFUN_INDEX_INSERT_LAST:
2282 // Can't do that at the beginning of a paragraph.
2283 if (owner->buffer()->text->cursor.pos - 1 <0)
2286 InsetIndex * new_inset = new InsetIndex();
2287 if (!argument.empty()) {
2288 string lsarg(argument);
2289 new_inset->setContents(lsarg);
2290 owner->buffer()->insertInset(new_inset);
2293 //get the current word for an argument
2294 LyXParagraph::size_type lastpos =
2295 owner->buffer()->text->cursor.pos - 1;
2296 // Get the current word. note that this must be done
2297 // before inserting the inset, or the inset will
2299 string curstring(owner->buffer()
2300 ->text->cursor.par->GetWord(lastpos));
2302 //make the new inset and write the current word into it
2303 InsetIndex * new_inset = new InsetIndex();
2305 new_inset->setContents(curstring);
2307 //don't edit it if the call was to INSERT_LAST
2308 if(action!= LFUN_INDEX_INSERT_LAST) {
2309 new_inset->Edit(0, 0);
2311 //it looks blank on the screen unless
2312 //we do something. put it here.
2314 // move the cursor to the returned value of lastpos
2315 // but only for the auto-insert
2316 owner->buffer()->text->cursor.pos= lastpos;
2319 //put the new inset into the buffer.
2320 // there should be some way of knowing the user
2321 //cancelled & avoiding this, but i don't know how
2322 owner->buffer()->insertInset(new_inset);
2327 case LFUN_INDEX_PRINT:
2329 Inset * new_inset = new InsetPrintIndex(owner->buffer());
2330 owner->buffer()->insertInset(new_inset, "Standard", true);
2334 case LFUN_PARENTINSERT:
2336 lyxerr << "arg " << argument << endl;
2337 Inset * new_inset = new InsetParent(argument, owner->buffer());
2338 owner->buffer()->insertInset(new_inset, "Standard", true);
2342 case LFUN_CHILDINSERT:
2344 Inset * new_inset = new InsetInclude(argument,
2346 owner->buffer()->insertInset(new_inset, "Standard", true);
2347 new_inset->Edit(0, 0);
2351 case LFUN_CHILDOPEN:
2354 MakeAbsPath(argument,
2355 OnlyPath(owner->buffer()->getFileName()));
2356 setMessage(N_("Opening child document ") +
2357 MakeDisplayPath(filename) + "...");
2358 owner->view()->savePosition();
2359 if (bufferlist.exists(filename))
2360 owner->view()->buffer(bufferlist.getBuffer(filename));
2362 owner->view()->buffer(bufferlist.loadLyXFile(filename));
2366 case LFUN_INSERT_NOTE:
2370 case LFUN_INSERTFOOTNOTE:
2372 LyXParagraph::footnote_kind kind;
2373 if (argument == "footnote")
2374 { kind = LyXParagraph::FOOTNOTE; }
2375 else if (argument == "margin")
2376 { kind = LyXParagraph::MARGIN; }
2377 else if (argument == "figure")
2378 { kind = LyXParagraph::FIG; }
2379 else if (argument == "table")
2380 { kind = LyXParagraph::TAB; }
2381 else if (argument == "wide-fig")
2382 { kind = LyXParagraph::WIDE_FIG; }
2383 else if (argument == "wide-tab")
2384 { kind = LyXParagraph::WIDE_TAB; }
2385 else if (argument == "algorithm")
2386 { kind = LyXParagraph::ALGORITHM; }
2388 setErrorMessage(N_("Unknown kind of footnote"));
2391 owner->buffer()->text->InsertFootnoteEnvironment(kind);
2392 owner->buffer()->update(1);
2396 case LFUN_BUFFERBULLETSSELECT:
2400 case LFUN_TOGGLECURSORFOLLOW:
2401 cursor_follows_scrollbar = !cursor_follows_scrollbar;
2404 case LFUN_KMAP_OFF: // keymap off
2405 owner->getIntl()->KeyMapOn(false);
2408 case LFUN_KMAP_PRIM: // primary keymap
2409 owner->getIntl()->KeyMapPrim();
2412 case LFUN_KMAP_SEC: // secondary keymap
2413 owner->getIntl()->KeyMapSec();
2416 case LFUN_KMAP_TOGGLE: // toggle keymap
2417 owner->getIntl()->ToggleKeyMap();
2420 case LFUN_SELFINSERT:
2422 for (string::size_type i = 0; i < argument.length(); ++i) {
2423 owner->buffer()->text->InsertChar(argument[i]);
2424 // This needs to be in the loop, or else we
2425 // won't break lines correctly. (Asger)
2429 owner->buffer()->text->sel_cursor =
2430 owner->buffer()->text->cursor;
2431 moveCursorUpdate(false);
2437 // argument contains ';'-terminated commands
2438 while (argument.find(';') != string::npos) {
2440 argument = split(argument, first, ';');
2446 case LFUN_SAVEPREFERENCES:
2448 Path p(user_lyxdir);
2449 lyxrc->write("preferences");
2453 case LFUN_UNKNOWN_ACTION:
2455 if (owner->buffer()->isReadonly()) {
2457 setErrorMessage(N_("Document is read only"));
2461 if (!argument.empty()) {
2463 /* Automatically delete the currently selected
2464 * text and replace it with what is being
2465 * typed in now. Depends on lyxrc settings
2466 * "auto_region_delete", which defaults to
2469 if ( lyxrc->auto_region_delete ) {
2470 if (owner->buffer()->text->selection){
2471 owner->buffer()->text->CutSelection(false);
2472 owner->buffer()->update(-1);
2477 for (string::size_type i = 0;
2478 i < argument.length(); ++i) {
2479 if (greek_kb_flag) {
2480 if (!math_insert_greek(argument[i]))
2481 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->buffer()->text);
2483 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->buffer()->text);
2489 owner->buffer()->text->sel_cursor =
2490 owner->buffer()->text->cursor;
2491 moveCursorUpdate(false);
2494 // why is an "Unknown action" with empty
2495 // argument even dispatched in the first
2496 // place? I`ll probably change that. (Lgb)
2498 setErrorMessage(N_("Unknown action"));
2502 lyxerr << "A truly unknown func!" << endl;
2508 string res = getMessage();
2511 if (!commandshortcut.empty()) {
2512 string newbuf = owner->getMiniBuffer()->GetText();
2513 if (newbuf != commandshortcut) {
2514 owner->getMiniBuffer()->Set(newbuf
2520 owner->getMiniBuffer()->Set(string(_(res.c_str()))
2521 + " " + commandshortcut);
2528 void LyXFunc::setupLocalKeymap()
2530 keyseq.stdmap = keyseq.curmap = toplevel_keymap;
2531 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap;
2535 void LyXFunc::MenuNew(bool fromTemplate)
2537 string fname, initpath = lyxrc->document_path;
2540 if (owner->view()->available()) {
2541 string trypath = owner->buffer()->filepath;
2542 // If directory is writeable, use this as default.
2543 if (IsDirWriteable(trypath) == 1)
2548 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2549 fileDlg.SetButton(1, _("Templates"), lyxrc->template_path);
2550 fname = fileDlg.Select(_("Enter Filename for new document"),
2551 initpath, "*.lyx", _("newfile"));
2554 if (fname.empty()) {
2555 owner->getMiniBuffer()->Set(_("Canceled."));
2556 lyxerr.debug() << "New Document Cancelled." << endl;
2560 // get absolute path of file and make sure the filename ends
2562 string s = MakeAbsPath(fname);
2563 if (!IsLyXFilename(s))
2566 // Check if the document already is open
2567 if (bufferlist.exists(s)){
2568 switch(AskConfirmation(_("Document is already open:"),
2569 MakeDisplayPath(s, 50),
2570 _("Do you want to close that document now?\n"
2571 "('No' will just switch to the open version)")))
2573 case 1: // Yes: close the document
2574 if (!bufferlist.close(bufferlist.getBuffer(s)))
2575 // If close is canceled, we cancel here too.
2578 case 2: // No: switch to the open document
2579 owner->view()->buffer(bufferlist.getBuffer(s));
2581 case 3: // Cancel: Do nothing
2582 owner->getMiniBuffer()->Set(_("Canceled."));
2587 // Check whether the file already exists
2588 if (IsLyXFilename(s)) {
2590 if (fi.readable() &&
2591 AskQuestion(_("File already exists:"),
2592 MakeDisplayPath(s, 50),
2593 _("Do you want to open the document?"))) {
2595 owner->getMiniBuffer()->Set(_("Opening document"),
2596 MakeDisplayPath(s), "...");
2598 owner->view()->buffer(
2599 bufferlist.loadLyXFile(s));
2600 owner->getMiniBuffer()->Set(_("Document"),
2607 // The template stuff
2611 fname = fileDlg.Select(_("Choose template"),
2612 lyxrc->template_path,
2618 // find a free buffer
2619 lyxerr.debug() << "Find a free buffer." << endl;
2620 owner->view()->buffer(bufferlist.newFile(s, templname));
2624 void LyXFunc::MenuOpen()
2626 string initpath = lyxrc->document_path;
2629 if (owner->view()->available()) {
2630 string trypath = owner->buffer()->filepath;
2631 // If directory is writeable, use this as default.
2632 if (IsDirWriteable(trypath) == 1)
2638 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2639 fileDlg.SetButton(1, _("Examples"),
2640 AddPath(system_lyxdir, "examples"));
2641 string filename = fileDlg.Select(_("Select Document to Open"),
2645 // check selected filename
2646 if (filename.empty()) {
2647 owner->getMiniBuffer()->Set(_("Canceled."));
2651 // get absolute path of file and make sure the filename ends
2653 filename = MakeAbsPath(filename);
2654 if (!IsLyXFilename(filename))
2658 owner->getMiniBuffer()->Set(_("Opening document"),
2659 MakeDisplayPath(filename), "...");
2660 Buffer * openbuf = bufferlist.loadLyXFile(filename);
2662 owner->view()->buffer(openbuf);
2663 owner->getMiniBuffer()->Set(_("Document"),
2664 MakeDisplayPath(filename),
2667 owner->getMiniBuffer()->Set(_("Could not open document"),
2668 MakeDisplayPath(filename));
2673 void LyXFunc::doImportASCII(bool linorpar)
2675 string initpath = lyxrc->document_path;
2678 if (owner->view()->available()) {
2679 string trypath = owner->buffer()->filepath;
2680 // If directory is writeable, use this as default.
2681 if (IsDirWriteable(trypath) == 1)
2687 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2688 fileDlg.SetButton(1, _("Examples"),
2689 AddPath(system_lyxdir, "examples"));
2690 string filename = fileDlg.Select(_("Select ASCII file to Import"),
2694 // check selected filename
2695 if (filename.empty()) {
2696 owner->getMiniBuffer()->Set(_("Canceled."));
2700 // get absolute path of file
2701 filename = MakeAbsPath(filename);
2703 string s = ChangeExtension(filename, ".lyx", false);
2705 // Check if the document already is open
2706 if (bufferlist.exists(s)){
2707 switch(AskConfirmation(_("Document is already open:"),
2708 MakeDisplayPath(s, 50),
2709 _("Do you want to close that document now?\n"
2710 "('No' will just switch to the open version)")))
2712 case 1: // Yes: close the document
2713 if (!bufferlist.close(bufferlist.getBuffer(s)))
2714 // If close is canceled, we cancel here too.
2717 case 2: // No: switch to the open document
2718 owner->view()->buffer(bufferlist.getBuffer(s));
2720 case 3: // Cancel: Do nothing
2721 owner->getMiniBuffer()->Set(_("Canceled."));
2726 // Check if a LyX document by the same root exists in filesystem
2727 FileInfo f(s, true);
2728 if (f.exist() && !AskQuestion(_("A document by the name"),
2730 _("already exists. Overwrite?"))) {
2731 owner->getMiniBuffer()->Set(_("Canceled."));
2735 owner->view()->buffer(bufferlist.newFile(s, string()));
2736 owner->getMiniBuffer()->Set(_("Importing ASCII file"),
2737 MakeDisplayPath(filename), "...");
2738 // Insert ASCII file
2739 InsertAsciiFile(filename, linorpar);
2740 owner->getMiniBuffer()->Set(_("ASCII file "),
2741 MakeDisplayPath(filename),
2746 void LyXFunc::doImportLaTeX(bool isnoweb)
2748 string initpath = lyxrc->document_path;
2751 if (owner->view()->available()) {
2752 string trypath = owner->buffer()->filepath;
2753 // If directory is writeable, use this as default.
2754 if (IsDirWriteable(trypath) == 1)
2760 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2761 fileDlg.SetButton(1, _("Examples"),
2762 AddPath(system_lyxdir, "examples"));
2765 filename = fileDlg.Select(_("Select Noweb file to Import"),
2768 filename = fileDlg.Select(_("Select LaTeX file to Import"),
2774 // check selected filename
2775 if (filename.empty()) {
2776 owner->getMiniBuffer()->Set(_("Canceled."));
2780 // get absolute path of file
2781 filename = MakeAbsPath(filename);
2783 // Check if the document already is open
2784 string LyXfilename = ChangeExtension(filename, ".lyx", false);
2785 if (bufferlist.exists(LyXfilename)){
2786 switch(AskConfirmation(_("Document is already open:"),
2787 MakeDisplayPath(LyXfilename, 50),
2788 _("Do you want to close that document now?\n"
2789 "('No' will just switch to the open version)")))
2791 case 1: // Yes: close the document
2792 if (!bufferlist.close(bufferlist.getBuffer(LyXfilename)))
2793 // If close is canceled, we cancel here too.
2796 case 2: // No: switch to the open document
2797 owner->view()->buffer(
2798 bufferlist.getBuffer(LyXfilename));
2800 case 3: // Cancel: Do nothing
2801 owner->getMiniBuffer()->Set(_("Canceled."));
2806 // Check if a LyX document by the same root exists in filesystem
2807 FileInfo f(LyXfilename, true);
2808 if (f.exist() && !AskQuestion(_("A document by the name"),
2809 MakeDisplayPath(LyXfilename),
2810 _("already exists. Overwrite?"))) {
2811 owner->getMiniBuffer()->Set(_("Canceled."));
2818 owner->getMiniBuffer()->Set(_("Importing LaTeX file"),
2819 MakeDisplayPath(filename), "...");
2820 ImportLaTeX myImport(filename);
2821 openbuf = myImport.run();
2823 owner->getMiniBuffer()->Set(_("Importing Noweb file"),
2824 MakeDisplayPath(filename), "...");
2825 ImportNoweb myImport(filename);
2826 openbuf = myImport.run();
2829 owner->view()->buffer(openbuf);
2830 owner->getMiniBuffer()->Set(isnoweb ?
2831 _("Noweb file ") : _("LateX file "),
2832 MakeDisplayPath(filename),
2835 owner->getMiniBuffer()->Set(isnoweb ?
2836 _("Could not import Noweb file") :
2837 _("Could not import LaTeX file"),
2838 MakeDisplayPath(filename));
2843 void LyXFunc::MenuInsertLyXFile(string const & filen)
2845 string filename = filen;
2847 if (filename.empty()) {
2848 // Launch a file browser
2849 string initpath = lyxrc->document_path;
2852 if (owner->view()->available()) {
2853 string trypath = owner->buffer()->filepath;
2854 // If directory is writeable, use this as default.
2855 if (IsDirWriteable(trypath) == 1)
2861 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2862 fileDlg.SetButton(1, _("Examples"),
2863 AddPath(system_lyxdir, "examples"));
2864 filename = fileDlg.Select(_("Select Document to Insert"),
2868 // check selected filename
2869 if (filename.empty()) {
2870 owner->getMiniBuffer()->Set(_("Canceled."));
2875 // get absolute path of file and make sure the filename ends
2877 filename = MakeAbsPath(filename);
2878 if (!IsLyXFilename(filename))
2882 owner->getMiniBuffer()->Set(_("Inserting document"),
2883 MakeDisplayPath(filename), "...");
2884 bool res = owner->buffer()->insertLyXFile(filename);
2886 owner->getMiniBuffer()->Set(_("Document"),
2887 MakeDisplayPath(filename),
2890 owner->getMiniBuffer()->Set(_("Could not insert document"),
2891 MakeDisplayPath(filename));
2896 void LyXFunc::reloadBuffer()
2898 string fn = owner->buffer()->getFileName();
2899 if (bufferlist.close(owner->buffer()))
2900 owner->view()->buffer(bufferlist.loadLyXFile(fn));
2904 void LyXFunc::CloseBuffer()
2906 if (bufferlist.close(owner->buffer()) && !quitting) {
2907 if (bufferlist.empty()) {
2908 // need this otherwise SEGV may occur while trying to
2909 // set variables that don't exist
2910 // since there's no current buffer
2911 CloseAllBufferRelatedPopups();
2914 owner->view()->buffer(bufferlist.first());
2920 Inset * LyXFunc::getInsetByCode(Inset::Code code)
2924 LyXCursor cursor = owner->buffer()->text->cursor;
2925 LyXParagraph::size_type pos = cursor.pos;
2926 LyXParagraph * par = cursor.par;
2928 while (par && !found) {
2929 while ((inset = par->ReturnNextInsetPointer(pos))){
2930 if (inset->LyxCode() == code) {
2938 return (found) ? inset: 0;
2942 // Each "owner" should have it's own message method. lyxview and
2943 // the minibuffer would use the minibuffer, but lyxserver would
2944 // send an ERROR signal to its client. Alejandro 970603
2945 // This func is bit problematic when it comes to NLS, to make the
2946 // lyx servers client be language indepenent we must not translate
2947 // strings sent to this func.
2948 void LyXFunc::setErrorMessage(string const & m) const
2950 dispatch_buffer = m;
2955 void LyXFunc::setMessage(string const & m)
2957 dispatch_buffer = m;