1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-1999 The LyX Team.
9 * ======================================================*/
18 #pragma implementation
21 #include "definitions.h"
22 #include "lyxlookup.h"
25 #include "bufferlist.h"
26 #include "lyxserver.h"
31 #include "insets/insetlatex.h"
32 #include "insets/inseturl.h"
33 #include "insets/insetlatexaccent.h"
34 #include "insets/insettoc.h"
35 #include "insets/insetlof.h"
36 #include "insets/insetloa.h"
37 #include "insets/insetlot.h"
38 #include "insets/insetref.h"
39 #include "insets/insetparent.h"
40 #include "mathed/formulamacro.h"
42 #include "spellchecker.h" // RVDK_PATCH_5
43 #include "minibuffer.h"
45 #include "insets/insetbib.h"
47 #include "insets/insetindex.h"
48 #include "insets/insetinclude.h"
50 #include "lyx_gui_misc.h"
51 #include "support/filetools.h"
52 #include "support/FileInfo.h"
53 #include "lyxscreen.h"
58 #include "trans_mgr.h"
59 #include "ImportLaTeX.h"
60 #include "ImportNoweb.h"
61 #include "support/syscall.h"
62 #include "support/lstrings.h"
64 extern bool cursor_follows_scrollbar;
66 extern void InsertAsciiFile(string const &, bool);
67 extern void math_insert_symbol(char const*);
68 extern Bool math_insert_greek(char const); // why "Bool"?
69 extern BufferList bufferlist;
70 extern LyXServer *lyxserver;
71 extern short greek_kb_flag;
72 extern FD_form_toc *fd_form_toc;
73 extern bool selection_possible;
75 extern kb_keymap *toplevel_keymap;
77 extern void BeforeChange();
78 extern void MenuWrite(Buffer*);
79 extern void MenuWriteAs(Buffer*);
80 extern int MenuRunLaTeX(Buffer*);
81 extern int MenuBuildProg(Buffer*);
82 extern int MenuRunChktex(Buffer*);
83 extern bool MenuRunDvips(Buffer *,bool);
84 extern void MenuPrint(Buffer*);
85 extern void MenuSendto();
86 extern void QuitLyX();
87 extern void MenuFax(Buffer *);
88 extern void MenuMakeLaTeX(Buffer *);
89 extern void MenuMakeLinuxDoc(Buffer *);
90 extern void MenuMakeDocBook(Buffer *);
91 extern void MenuMakeAscii(Buffer *);
92 extern void MenuPasteSelection(char at);
93 extern LyXAction lyxaction;
95 extern tex_accent_struct get_accent(kb_action action);
97 extern void AutoSave();
98 extern void MenuSearch();
100 extern void CopyEnvironmentCB();
101 extern void PasteEnvironmentCB();
102 extern void GotoNote();
103 extern void NoteCB();
104 extern void OpenStuff();
105 extern void HyphenationPoint();
107 extern void EndOfSentenceDot();
108 extern void MenuSeparator();
110 extern void MenuUndo();
111 extern void MenuRedo();
112 extern void SmallUpdate(signed char);
113 extern void SetUpdateTimer(float timer= 0.3);
114 extern void FreeUpdateTimer();
115 extern bool MenuPreview(Buffer*);
116 extern bool MenuPreviewPS(Buffer*);
117 extern void MenuInsertLabel(const char *);
118 extern void MenuInsertRef();
119 extern void MenuLayoutCharacter();
120 extern void MenuLayoutParagraph();
121 extern void MenuLayoutDocument();
122 extern void MenuLayoutPaper();
123 extern void MenuLayoutTable(int flag);
124 extern void MenuLayoutQuotes();
125 extern void MenuLayoutPreamble();
126 extern void MenuLayoutSave();
127 extern void bulletForm();
129 extern Buffer * NewLyxFile(string const &);
130 extern void LoadLyXFile(string const &);
131 extern void Reconfigure();
133 extern int current_layout;
134 extern int getISOCodeFromLaTeX(char *);
136 extern int UnlockInset(UpdatableInset*);
138 extern void ShowLatexLog();
140 extern void UpdateInset(Inset* inset, bool mark_dirty = true);
142 /* === globals =========================================================== */
144 bool LyXFunc::show_sc = true;
147 LyXFunc::LyXFunc(LyXView *o)
151 lyx_dead_action = LFUN_NOACTION;
152 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->currentBuffer()->text->mark_set) {
171 owner->currentBuffer()->text->SetSelection();
172 owner->currentView()->getScreen()->ToggleToggle();
173 owner->currentBuffer()->update(0);
175 owner->currentBuffer()->update(-2); // this IS necessary
178 owner->currentView()->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->currentView()->available() &&
217 owner->currentBuffer()->the_locking_inset &&
218 keysym_return == XK_Escape) {
219 UnlockInset(owner->currentBuffer()->the_locking_inset);
220 owner->currentBuffer()->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 string LyXFunc::Dispatch(string const &cmd, string const &arg)
312 return Dispatch(lyxaction.LookupFunc(cmd.c_str()),
317 string LyXFunc::Dispatch(int ac,
318 char const *do_not_use_this_arg)
324 FL_OBJECT *ob = 0; // This will disapear soon
326 // we have not done anything wrong yet.
328 dispatch_buffer = string();
330 // if action is a pseudo-action, we need the real action
331 if (lyxaction.isPseudoAction(ac)) {
332 char const *tmparg = 0;
333 action = (kb_action)lyxaction.retrieveActionArg(ac, &tmparg);
337 action = (kb_action)ac;
338 if (do_not_use_this_arg)
339 argument = do_not_use_this_arg; // except here
342 selection_possible = false;
344 if (owner->currentView()->available()
345 && owner->currentView()->getScreen())
346 owner->currentView()->getScreen()->HideCursor();
348 if(!owner->currentView()->available()) {
349 // This lists the allowed funcs when we have no
352 case LFUN_MENU_OPEN_BY_NAME:
355 case LFUN_MENUNEWTMPLT:
358 case LFUN_PUSH_TOOLBAR:
359 case LFUN_ADD_TO_TOOLBAR:
360 case LFUN_EXEC_COMMAND:
361 case LFUN_DROP_LAYOUTS_CHOICE:
365 case LFUN_RECONFIGURE:
371 case LFUN_UNKNOWN_ACTION:
372 setErrorMessage(N_("Unknown action"));
373 goto exit_with_message;
375 setErrorMessage(N_("Command not allowed with"
376 "out any document open"));
377 goto exit_with_message; // action not allowed
381 commandshortcut = string();
383 if (lyxrc->display_shortcuts && show_sc) {
384 if (action != LFUN_SELFINSERT) {
385 // Put name of command and list of shortcuts
386 // for it in minibuffer
387 string comname = lyxaction.getActionName(action);
389 int pseudoaction = action;
390 bool argsadded = false;
392 if (!argument.empty()) {
393 // If we have the command with argument,
396 lyxaction.searchActionArg(action,
399 if (pseudoaction == -1) {
400 pseudoaction = action;
402 comname += " " + argument;
407 string shortcuts = toplevel_keymap->findbinding(pseudoaction);
409 if (!shortcuts.empty()) {
410 comname += ": " + shortcuts;
411 } else if (!argsadded) {
412 comname += " " + argument;
415 if (!comname.empty()) {
416 comname = strip(comname);
417 commandshortcut = "(" + comname + ')';
418 owner->getMiniBuffer()->Set(commandshortcut);
419 // Here we could even add a small pause,
420 // to annoy the user and make him learn
422 // No! That will just annoy, not teach
423 // anything. The user will read the messages
424 // if they are interested. (Asger)
429 // Now that we know which action, if the buffer is RO let's check
430 // whether the action is legal. Alejandro 970603
431 if (owner->currentView()->available() &&
432 owner->currentBuffer()->isReadonly() &&
433 lyxaction.isFuncRO(action)) {
434 setErrorMessage(N_("Document is read-only"));
435 lyxerr.debug() << "Error: Document is read-only." << endl;
436 goto exit_with_message;
439 // If in math mode pass the control to
440 // the math inset [asierra060396]
441 if (owner->currentView()->available() &&
442 owner->currentBuffer()->the_locking_inset) {
443 if (action>1 || (action==LFUN_UNKNOWN_ACTION && keyseq.length>=-1)) {
444 if (action==LFUN_UNKNOWN_ACTION && argument.empty()) {
445 argument = keyseq.getiso();
447 // Undo/Redo pre 0.13 is a bit tricky for insets.
448 if (action==LFUN_UNDO) {
450 UpdatableInset* inset =
451 owner->currentBuffer()->the_locking_inset;
452 inset->GetCursorPos(slx, sly);
455 inset = (UpdatableInset*)owner->currentBuffer()->text->cursor.par->GetInset(owner->currentBuffer()->text->cursor.pos);
457 inset->Edit(slx, sly);
460 if (action==LFUN_REDO) {
462 UpdatableInset* inset = owner->currentBuffer()->the_locking_inset;
463 inset->GetCursorPos(slx, sly);
466 inset = (UpdatableInset*)owner->currentBuffer()->text->cursor.par->GetInset(owner->currentBuffer()->text->cursor.pos);
468 inset->Edit(slx, sly);
471 if (owner->currentBuffer()->the_locking_inset->LocalDispatch(action, argument.c_str()))
474 setMessage(N_("Text mode"));
475 if (action==LFUN_RIGHT || action==-1)
476 owner->currentBuffer()->text->CursorRight();
477 if (action==LFUN_LEFT || action==LFUN_RIGHT)
484 // --- Misc -------------------------------------------
485 case LFUN_WORDFINDFORWARD :
486 case LFUN_WORDFINDBACKWARD : {
488 static string last_search;
489 string searched_string;
491 if (!argument.empty()) {
492 last_search = argument;
493 searched_string = argument;
495 searched_string = last_search;
498 ltCur = owner->currentView()->currentBuffer()->text ;
500 if (!searched_string.empty() &&
501 ( (action == LFUN_WORDFINDBACKWARD) ?
502 ltCur->SearchBackward( searched_string.c_str() ) :
503 ltCur->SearchForward( searched_string.c_str() )
506 // ??? What is that ???
507 owner->currentView()->currentBuffer()->update(-2);
510 // clear the selection (if there is any)
511 owner->currentView()->getScreen()->ToggleSelection();
512 owner->currentView()->currentBuffer()->text->ClearSelection();
514 // Move cursor so that successive C-s 's will not stand in place.
515 if( action == LFUN_WORDFINDFORWARD )
516 owner->currentBuffer()->text->CursorRightOneWord();
517 owner->currentBuffer()->text->FinishUndo();
518 moveCursorUpdate(false);
521 // set the new selection
522 // SetSelectionOverLenChars(owner->currentView()->currentBuffer()->text, iLenSelected);
523 owner->currentView()->getScreen()->ToggleSelection(false);
527 // REMOVED : if (owner->currentView()->getWorkArea()->focus)
528 owner->currentView()->getScreen()->ShowCursor();
534 if (owner->currentView()->available()
535 && owner->currentView()->getScreen()) {
536 owner->currentBuffer()->update(-2);
539 keyseq.print(buf,100, true);
540 owner->getMiniBuffer()->Set(buf, string(), string(), 1);
544 // --- Misc -------------------------------------------
545 case LFUN_EXEC_COMMAND:
546 owner->getMiniBuffer()->ExecCommand();
549 case LFUN_CANCEL: // RVDK_PATCH_5
552 if(owner->currentView()->available())
553 // cancel any selection
554 Dispatch(int(LFUN_MARK_OFF), 0);
555 setMessage(N_("Cancel"));
558 case LFUN_META_FAKE: // RVDK_PATCH_5
560 meta_fake_bit = Mod1Mask;
562 keyseq.print(buf, 98, true);
563 string res = string("M-") + buf;
564 setMessage(buf); // RVDK_PATCH_5
568 case LFUN_READ_ONLY_TOGGLE:
569 if (owner->currentBuffer()->lyxvc.inUse()) {
570 owner->currentBuffer()->lyxvc.toggleReadOnly();
572 owner->currentBuffer()->setReadonly(
573 !owner->currentBuffer()->isReadonly());
577 case LFUN_CENTER: // this is center and redraw.
579 if (owner->currentBuffer()->text->cursor.y >
580 owner->currentView()->getWorkArea()->h / 2) {
581 owner->currentView()->getScreen()->
582 Draw(owner->currentBuffer()->text->cursor.y -
583 owner->currentView()->getWorkArea()->h/2);
585 owner->currentView()->getScreen()->
588 owner->currentBuffer()->update(0);
589 owner->currentView()->redraw();
593 if (owner->currentView()->available()) {
594 owner->currentBuffer()->text->toggleAppendix();
595 owner->currentBuffer()->update(1);
599 // --- Menus -----------------------------------------------
604 case LFUN_MENUNEWTMPLT:
612 case LFUN_CLOSEBUFFER:
617 MenuWrite(owner->currentBuffer());
620 case LFUN_MENUWRITEAS:
621 MenuWriteAs(owner->currentBuffer());
624 case LFUN_MENURELOAD:
629 MenuPreview(owner->currentBuffer());
633 MenuPreviewPS(owner->currentBuffer());
637 MenuRunLaTeX(owner->currentBuffer());
641 MenuBuildProg(owner->currentBuffer());
645 MenuRunChktex(owner->currentBuffer());
649 MenuRunDvips(owner->currentBuffer(), false);
653 MenuPrint(owner->currentBuffer());
657 MenuFax(owner->currentBuffer());
662 //needs argument as string
663 string extyp=argument;
666 if (extyp == "latex") {
667 // make sure that this buffer is not linuxdoc
668 MenuMakeLaTeX(owner->currentBuffer());
671 else if (extyp == "linuxdoc") {
672 // make sure that this buffer is not latex
673 MenuMakeLinuxDoc(owner->currentBuffer());
676 else if (extyp == "docbook") {
677 // make sure that this buffer is not latex or linuxdoc
678 MenuMakeDocBook(owner->currentBuffer());
681 else if (extyp == "dvi") {
682 // Run LaTeX as "Update dvi..." Bernhard.
683 // We want the dvi in the current directory. This
684 // is achieved by temporarily disabling use of
685 // temp directory. As a side-effect, we get
686 // *.log and *.aux files also. (Asger)
687 bool flag = lyxrc->use_tempdir;
688 lyxrc->use_tempdir = false;
689 MenuRunLaTeX(owner->currentBuffer());
690 lyxrc->use_tempdir = flag;
693 else if (extyp == "postscript") {
694 // Start Print-dialog. Not as good as dvi... Bernhard.
695 MenuPrint(owner->currentBuffer());
696 // Since the MenuPrint is a pop-up, we can't use
697 // the same trick as above. (Asger)
698 // MISSING: Move of ps-file :-(
701 else if (extyp == "ascii") {
702 MenuMakeAscii(owner->currentBuffer());
704 else if (extyp == "custom") {
709 else if (extyp == "html") {
710 // First, create LaTeX file
711 MenuMakeLaTeX(owner->currentBuffer());
714 string file = owner->currentBuffer()->getFileName();
715 file = ChangeExtension(file, ".tex", false);
716 string result = ChangeExtension(file, ".html", false);
717 string tmp = lyxrc->tth_command + " < " + file
720 int res = one.startscript(Systemcalls::System, tmp);
723 _("Document exported as HTML to file: ")) + result);
725 setErrorMessage(string(
726 _("An unexpected error occured while converting document to HTML in file:")) + result);
730 setErrorMessage(string(_("Unknown export type: "))
738 //needs argument as string
739 string imtyp=argument;
742 if (imtyp == "latex") {
743 doImportLaTeX(false);
746 else if (imtyp == "ascii") {
747 doImportASCII(false);
748 } else if (imtyp == "asciiparagraph") {
751 } else if (imtyp == "noweb") {
754 setErrorMessage(string(N_("Unknown import type: "))
766 if (fd_form_toc->form_toc->visible) {
767 fl_raise_form(fd_form_toc->form_toc);
769 fl_show_form(fd_form_toc->form_toc,
771 FL_FREE_SIZE, FL_FULLBORDER,
772 _("Table of Contents"));
776 case LFUN_TOC_INSERT:
779 new InsetTOC(owner->currentBuffer());
780 owner->currentBuffer()->insertInset(new_inset,
785 case LFUN_LOF_INSERT:
788 new InsetLOF(owner->currentBuffer());
789 owner->currentBuffer()->insertInset(new_inset,
794 case LFUN_LOA_INSERT:
797 new InsetLOA(owner->currentBuffer());
798 owner->currentBuffer()->insertInset(new_inset,
803 case LFUN_LOT_INSERT:
806 new InsetLOT(owner->currentBuffer());
807 owner->currentBuffer()->insertInset(new_inset,
832 case LFUN_MENUSEARCH:
840 case LFUN_PASTESELECTION:
843 if (string(argument) == "paragraph") asPara = true;
844 MenuPasteSelection(asPara);
856 case LFUN_LAYOUT_COPY:
860 case LFUN_LAYOUT_PASTE:
861 PasteEnvironmentCB();
865 owner->currentView()->gotoError();
868 case LFUN_REMOVEERRORS:
869 if (owner->currentBuffer()->removeAutoInsets()) {
870 owner->currentView()->redraw();
871 owner->currentView()->fitCursor();
872 owner->currentView()->updateScrollbar();
884 case LFUN_HYPHENATION:
892 case LFUN_END_OF_SENTENCE:
896 case LFUN_MENU_SEPARATOR:
912 case LFUN_DEPTH_PLUS:
928 case LFUN_RECONFIGURE:
933 if (owner->currentView()->available()
934 && !owner->currentBuffer()->text->selection
935 && owner->currentBuffer()->text->cursor.par->footnoteflag
936 != LyXParagraph::NO_FOOTNOTE)
937 { // only melt footnotes with FOOTMELT, not margins etc
938 if(owner->currentBuffer()->text->cursor.par->footnotekind == LyXParagraph::FOOTNOTE)
945 case LFUN_MARGINMELT:
946 if (owner->currentView()->available()
947 && !owner->currentBuffer()->text->selection
948 && owner->currentBuffer()->text->cursor.par->footnoteflag
949 != LyXParagraph::NO_FOOTNOTE)
950 { // only melt margins
951 if(owner->currentBuffer()->text->cursor.par->footnotekind == LyXParagraph::MARGIN)
958 // --- version control -------------------------------
959 case LFUN_VC_REGISTER:
961 if (!owner->currentBuffer()->lyxvc.inUse())
962 owner->currentBuffer()->lyxvc.registrer();
966 case LFUN_VC_CHECKIN:
968 if (owner->currentBuffer()->lyxvc.inUse()
969 && !owner->currentBuffer()->isReadonly())
970 owner->currentBuffer()->lyxvc.checkIn();
974 case LFUN_VC_CHECKOUT:
976 if (owner->currentBuffer()->lyxvc.inUse()
977 && owner->currentBuffer()->isReadonly())
978 owner->currentBuffer()->lyxvc.checkOut();
984 owner->currentBuffer()->lyxvc.revert();
990 owner->currentBuffer()->lyxvc.undoLast();
994 case LFUN_VC_HISTORY:
996 owner->currentBuffer()->lyxvc.showLog();
1000 // --- buffers ----------------------------------------
1001 case LFUN_PREVBUFFER:
1002 #ifdef WITH_WARNINGS
1003 #warning fix this please
1005 // it is the LyXView or the BufferView that should
1006 // remember the previous buffer, not bufferlist.
1007 // if (owner->currentView()->available()){
1009 // owner->currentBuffer()->update(-2);
1011 // owner->currentView()->setBuffer(bufferlist.prev());
1013 // owner->currentView()->
1014 // resizeCurrentBufferPseudoExpose();
1017 case LFUN_FILE_INSERT:
1019 MenuInsertLyXFile(argument);
1023 case LFUN_FILE_INSERT_ASCII:
1025 bool asPara = false;
1026 asPara = (string(argument) == "paragraph");
1027 InsertAsciiFile(string(), asPara);
1033 // servercmd: argument must be <file>:<template>
1034 Buffer * tmpbuf = 0;
1035 tmpbuf = NewLyxFile(argument);
1037 owner->currentView()->setBuffer(tmpbuf);
1041 case LFUN_FILE_OPEN:
1042 owner->currentView()->setBuffer(
1043 bufferlist.loadLyXFile(argument));
1046 case LFUN_LATEX_LOG:
1052 lyxerr.debug() << "LFUN_LAYOUTNO: (arg) " << argument << endl;
1053 int sel = strToInt(argument);
1054 lyxerr.debug() << "LFUN_LAYOUTNO: (sel) "<< sel << endl;
1056 // Should this give a setMessage instead?
1058 return string(); // illegal argument
1060 sel--; // sel 1..., but layout 0...
1062 // Pretend we got the name instead.
1063 Dispatch(int(LFUN_LAYOUT),
1064 lyxstyle.NameOfLayout(owner->currentBuffer()->
1073 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1074 << argument << endl;
1076 // Derive layout number from given argument (string)
1077 // and current buffer's textclass (number). */
1080 lyxstyle.NumberOfLayout(owner->
1086 // see if we found the layout number:
1087 if (layoutno == -1) {
1088 setErrorMessage(string(N_("Layout ")) + argument +
1093 if (current_layout != layoutno) {
1094 owner->currentView()->getScreen()->HideCursor();
1095 current_layout = layoutno;
1096 owner->currentBuffer()->update(-2);
1097 owner->currentBuffer()->text->
1098 SetLayout(layoutno);
1099 owner->getToolbar()->combox->
1100 select(owner->currentBuffer()->
1103 owner->currentBuffer()->update(1);
1108 case LFUN_LAYOUT_DOCUMENT:
1109 MenuLayoutDocument();
1112 case LFUN_LAYOUT_PARAGRAPH:
1113 MenuLayoutParagraph();
1116 case LFUN_LAYOUT_CHARACTER:
1117 MenuLayoutCharacter();
1120 case LFUN_LAYOUT_TABLE:
1123 if (string(argument) == "true") flag = 1;
1124 MenuLayoutTable(flag);
1128 case LFUN_LAYOUT_PAPER:
1132 case LFUN_LAYOUT_QUOTES:
1136 case LFUN_LAYOUT_PREAMBLE:
1137 MenuLayoutPreamble();
1140 case LFUN_LAYOUT_SAVE_DEFAULT:
1144 case LFUN_DROP_LAYOUTS_CHOICE:
1145 owner->getToolbar()->combox->Show();
1176 case LFUN_UNDERLINE:
1180 case LFUN_FONT_SIZE:
1181 FontSizeCB(argument);
1184 case LFUN_FONT_STATE:
1185 setMessage(CurrentState());
1188 case LFUN_UPCASE_WORD:
1189 owner->currentBuffer()->update(-2);
1191 owner->currentBuffer()->text->ChangeWordCase(2);
1192 owner->currentBuffer()->update(1);
1196 case LFUN_LOWCASE_WORD:
1197 owner->currentBuffer()->update(-2);
1199 owner->currentBuffer()->text->ChangeWordCase(0);
1200 owner->currentBuffer()->update(1);
1204 case LFUN_CAPITALIZE_WORD:
1205 owner->currentBuffer()->update(-2);
1207 owner->currentBuffer()->text->ChangeWordCase(1);
1208 owner->currentBuffer()->update(1);
1212 case LFUN_INSERT_LABEL:
1213 MenuInsertLabel(argument.c_str());
1216 case LFUN_INSERT_REF:
1220 case LFUN_REFTOGGLE:
1223 (InsetRef*)getInsetByCode(Inset::REF_CODE);
1225 if (inset->getFlag()==InsetRef::REF)
1226 inset->setFlag(InsetRef::PAGE_REF);
1228 inset->setFlag(InsetRef::REF);
1231 setErrorMessage(N_("No cross-reference to toggle"));
1238 owner->currentView()->restorePosition();
1244 string label(argument);
1245 if (label.empty()) {
1247 (InsetRef*)getInsetByCode(Inset::REF_CODE);
1249 label = inset->getContents();
1252 if (!label.empty()) {
1253 owner->currentView()->savePosition();
1254 owner->currentBuffer()->gotoLabel(label.c_str());
1259 case LFUN_MENU_OPEN_BY_NAME:
1260 owner->getMenus()->openByName(argument);
1261 break; // RVDK_PATCH_5
1263 case LFUN_SPELLCHECK:
1264 if (lyxrc->isp_command != "none")
1266 break; // RVDK_PATCH_5
1268 // --- Cursor Movements -----------------------------
1271 Buffer *tmpbuffer = owner->currentBuffer();
1272 LyXText *tmptext = owner->currentBuffer()->text;
1273 if(!tmptext->mark_set)
1275 tmpbuffer->update(-2);
1276 if (tmptext->cursor.pos < tmptext->cursor.par->Last()
1277 && tmptext->cursor.par->GetChar(tmptext->cursor.pos)
1279 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)
1280 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)->Editable()==2){
1281 Inset* tmpinset = tmptext->cursor.par->GetInset(tmptext->cursor.pos);
1282 setMessage(tmpinset->EditMessage());
1283 tmpinset->Edit(0,0);
1286 tmptext->CursorRight();
1287 owner->currentBuffer()->text->FinishUndo();
1288 moveCursorUpdate(false);
1289 owner->getMiniBuffer()->Set(CurrentState());
1295 // This is soooo ugly. Isn`t it possible to make
1296 // it simpler? (Lgb)
1297 LyXText *txt= owner->currentBuffer()->text;
1298 if(!txt->mark_set) BeforeChange();
1299 owner->currentBuffer()->update(-2);
1301 if (txt->cursor.pos < txt->cursor.par->Last()
1302 && txt->cursor.par->GetChar(txt->cursor.pos)
1304 && txt->cursor.par->GetInset(txt->cursor.pos)
1305 && txt->cursor.par->GetInset(txt->cursor.pos)->Editable()==2) {
1306 Inset* tmpinset = txt->cursor.par->GetInset(txt->cursor.pos);
1307 setMessage(tmpinset->EditMessage());
1308 tmpinset->Edit(tmpinset->Width(txt->GetFont(txt->cursor.par,
1309 txt->cursor.pos)),0);
1310 // tmpinset->Edit(-1, 0); // -1 means go rightmost
1313 owner->currentBuffer()->text->FinishUndo();
1314 moveCursorUpdate(false);
1315 owner->getMiniBuffer()->Set(CurrentState());
1320 if(!owner->currentBuffer()->text->mark_set) BeforeChange();
1321 owner->currentBuffer()->update(-3);
1322 owner->currentBuffer()->text->CursorUp();
1323 owner->currentBuffer()->text->FinishUndo();
1324 moveCursorUpdate(false);
1325 owner->getMiniBuffer()->Set(CurrentState());
1329 if(!owner->currentBuffer()->text->mark_set)
1331 owner->currentBuffer()->update(-3);
1332 owner->currentBuffer()->text->CursorDown();
1333 owner->currentBuffer()->text->FinishUndo();
1334 moveCursorUpdate(false);
1335 owner->getMiniBuffer()->Set(CurrentState());
1338 case LFUN_UP_PARAGRAPH:
1339 if(!owner->currentBuffer()->text->mark_set)
1341 owner->currentBuffer()->update(-3);
1342 owner->currentBuffer()->text->CursorUpParagraph();
1343 owner->currentBuffer()->text->FinishUndo();
1344 moveCursorUpdate(false);
1345 owner->getMiniBuffer()->Set(CurrentState());
1348 case LFUN_DOWN_PARAGRAPH:
1349 if(!owner->currentBuffer()->text->mark_set)
1351 owner->currentBuffer()->update(-3);
1352 owner->currentBuffer()->text->CursorDownParagraph();
1353 owner->currentBuffer()->text->FinishUndo();
1354 moveCursorUpdate(false);
1355 owner->getMiniBuffer()->Set(CurrentState());
1359 if(!owner->currentBuffer()->text->mark_set)
1361 owner->currentBuffer()->update(-3);
1362 owner->currentView()->cursorPrevious();
1363 owner->currentBuffer()->text->FinishUndo();
1364 moveCursorUpdate(false);
1365 owner->getMiniBuffer()->Set(CurrentState());
1369 if(!owner->currentBuffer()->text->mark_set)
1371 owner->currentBuffer()->update(-3);
1372 owner->currentView()->cursorNext();
1373 owner->currentBuffer()->text->FinishUndo();
1374 moveCursorUpdate(false);
1375 owner->getMiniBuffer()->Set(CurrentState());
1379 if(!owner->currentBuffer()->text->mark_set)
1381 owner->currentBuffer()->update(-2);
1382 owner->currentBuffer()->text->CursorHome();
1383 owner->currentBuffer()->text->FinishUndo();
1384 moveCursorUpdate(false);
1385 owner->getMiniBuffer()->Set(CurrentState());
1389 if(!owner->currentBuffer()->text->mark_set)
1391 owner->currentBuffer()->update(-2);
1392 owner->currentBuffer()->text->CursorEnd();
1393 owner->currentBuffer()->text->FinishUndo();
1394 moveCursorUpdate(false);
1395 owner->getMiniBuffer()->Set(CurrentState());
1399 if(!owner->currentBuffer()->text->mark_set)
1401 owner->currentBuffer()->update(-2);
1402 owner->currentBuffer()->text->CursorTab();
1403 owner->currentBuffer()->text->FinishUndo();
1404 moveCursorUpdate(false);
1405 owner->getMiniBuffer()->Set(CurrentState());
1408 case LFUN_WORDRIGHT:
1409 if(!owner->currentBuffer()->text->mark_set)
1411 owner->currentBuffer()->update(-2);
1412 owner->currentBuffer()->text->CursorRightOneWord();
1413 owner->currentBuffer()->text->FinishUndo();
1414 moveCursorUpdate(false);
1415 owner->getMiniBuffer()->Set(CurrentState());
1419 if(!owner->currentBuffer()->text->mark_set)
1421 owner->currentBuffer()->update(-2);
1422 owner->currentBuffer()->text->CursorLeftOneWord();
1423 owner->currentBuffer()->text->FinishUndo();
1424 moveCursorUpdate(false);
1425 owner->getMiniBuffer()->Set(CurrentState());
1428 case LFUN_BEGINNINGBUF:
1429 if(!owner->currentBuffer()->text->mark_set)
1431 owner->currentBuffer()->update(-2);
1432 owner->currentBuffer()->text->CursorTop();
1433 owner->currentBuffer()->text->FinishUndo();
1434 moveCursorUpdate(false);
1435 owner->getMiniBuffer()->Set(CurrentState());
1439 if(!owner->currentBuffer()->text->mark_set)
1441 owner->currentBuffer()->update(-2);
1442 owner->currentBuffer()->text->CursorBottom();
1443 owner->currentBuffer()->text->FinishUndo();
1444 moveCursorUpdate(false);
1445 owner->getMiniBuffer()->Set(CurrentState());
1449 /* cursor selection ---------------------------- */
1451 owner->currentBuffer()->update(-2);
1452 owner->currentBuffer()->text->CursorRight();
1453 owner->currentBuffer()->text->FinishUndo();
1454 moveCursorUpdate(true);
1455 owner->getMiniBuffer()->Set(CurrentState());
1459 owner->currentBuffer()->update(-2);
1460 owner->currentBuffer()->text->CursorLeft();
1461 owner->currentBuffer()->text->FinishUndo();
1462 moveCursorUpdate(true);
1463 owner->getMiniBuffer()->Set(CurrentState());
1467 owner->currentBuffer()->update(-2);
1468 owner->currentBuffer()->text->CursorUp();
1469 owner->currentBuffer()->text->FinishUndo();
1470 moveCursorUpdate(true);
1471 owner->getMiniBuffer()->Set(CurrentState());
1475 owner->currentBuffer()->update(-2);
1476 owner->currentBuffer()->text->CursorDown();
1477 owner->currentBuffer()->text->FinishUndo();
1478 moveCursorUpdate(true);
1479 owner->getMiniBuffer()->Set(CurrentState());
1482 case LFUN_UP_PARAGRAPHSEL:
1483 owner->currentBuffer()->update(-2);
1484 owner->currentBuffer()->text->CursorUpParagraph();
1485 owner->currentBuffer()->text->FinishUndo();
1486 moveCursorUpdate(true);
1487 owner->getMiniBuffer()->Set(CurrentState());
1490 case LFUN_DOWN_PARAGRAPHSEL:
1491 owner->currentBuffer()->update(-2);
1492 owner->currentBuffer()->text->CursorDownParagraph();
1493 owner->currentBuffer()->text->FinishUndo();
1494 moveCursorUpdate(true);
1495 owner->getMiniBuffer()->Set(CurrentState());
1499 owner->currentBuffer()->update(-2);
1500 owner->currentView()->cursorPrevious();
1501 owner->currentBuffer()->text->FinishUndo();
1502 moveCursorUpdate(true);
1503 owner->getMiniBuffer()->Set(CurrentState());
1507 owner->currentBuffer()->update(-2);
1508 owner->currentView()->cursorNext();
1509 owner->currentBuffer()->text->FinishUndo();
1510 moveCursorUpdate(true);
1511 owner->getMiniBuffer()->Set(CurrentState());
1515 owner->currentBuffer()->update(-2);
1516 owner->currentBuffer()->text->CursorHome();
1517 owner->currentBuffer()->text->FinishUndo();
1518 moveCursorUpdate(true);
1519 owner->getMiniBuffer()->Set(CurrentState());
1523 owner->currentBuffer()->update(-2);
1524 owner->currentBuffer()->text->CursorEnd();
1525 owner->currentBuffer()->text->FinishUndo();
1526 moveCursorUpdate(true);
1527 owner->getMiniBuffer()->Set(CurrentState());
1530 case LFUN_WORDRIGHTSEL:
1531 owner->currentBuffer()->update(-2);
1532 owner->currentBuffer()->text->CursorRightOneWord();
1533 owner->currentBuffer()->text->FinishUndo();
1534 moveCursorUpdate(true);
1535 owner->getMiniBuffer()->Set(CurrentState());
1538 case LFUN_WORDLEFTSEL:
1539 owner->currentBuffer()->update(-2);
1540 owner->currentBuffer()->text->CursorLeftOneWord();
1541 owner->currentBuffer()->text->FinishUndo();
1542 moveCursorUpdate(true);
1543 owner->getMiniBuffer()->Set(CurrentState());
1546 case LFUN_BEGINNINGBUFSEL:
1547 owner->currentBuffer()->update(-2);
1548 owner->currentBuffer()->text->CursorTop();
1549 owner->currentBuffer()->text->FinishUndo();
1550 moveCursorUpdate(true);
1551 owner->getMiniBuffer()->Set(CurrentState());
1554 case LFUN_ENDBUFSEL:
1555 owner->currentBuffer()->update(-2);
1556 owner->currentBuffer()->text->CursorBottom();
1557 owner->currentBuffer()->text->FinishUndo();
1558 moveCursorUpdate(true);
1559 owner->getMiniBuffer()->Set(CurrentState());
1562 // --- text changing commands ------------------------
1563 case LFUN_BREAKLINE:
1565 owner->currentBuffer()->text->InsertChar(LYX_META_NEWLINE);
1567 SetUpdateTimer(0.01);
1568 moveCursorUpdate(false);
1571 case LFUN_PROTECTEDSPACE:
1573 owner->currentBuffer()->text->
1574 InsertChar(LYX_META_PROTECTED_SEPARATOR);
1577 moveCursorUpdate(false);
1581 if(owner->currentBuffer()->text->mark_set) {
1583 owner->currentBuffer()->update(0);
1584 setMessage(N_("Mark removed"));
1587 owner->currentBuffer()->text->mark_set = 1;
1588 owner->currentBuffer()->update(0);
1589 setMessage(N_("Mark set"));
1591 owner->currentBuffer()->text->sel_cursor =
1592 owner->currentBuffer()->text->cursor;
1597 if (!owner->currentBuffer()->text->selection) {
1598 owner->currentBuffer()->text->Delete();
1599 owner->currentBuffer()->text->sel_cursor =
1600 owner->currentBuffer()->text->cursor;
1602 // It is possible to make it a lot faster still
1603 // just comment out the lone below...
1604 owner->currentView()->getScreen()->ShowCursor();
1611 case LFUN_DELETE_SKIP:
1613 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1615 LyXCursor cursor = owner->currentBuffer()->text->cursor;
1618 if (!owner->currentBuffer()->text->selection) {
1619 if (cursor.pos == cursor.par->Last()) {
1620 owner->currentBuffer()->text->CursorRight();
1621 cursor = owner->currentBuffer()->text->cursor;
1623 && !(cursor.par->added_space_top
1624 == VSpace (VSpace::NONE))) {
1625 owner->currentBuffer()->text->SetParagraph
1626 (cursor.par->line_top,
1627 cursor.par->line_bottom,
1628 cursor.par->pagebreak_top,
1629 cursor.par->pagebreak_bottom,
1630 VSpace(VSpace::NONE),
1631 cursor.par->added_space_bottom,
1633 cursor.par->labelwidthstring, 0);
1634 owner->currentBuffer()->text->CursorLeft();
1635 owner->currentBuffer()->update (1);
1637 owner->currentBuffer()->text->CursorLeft();
1638 owner->currentBuffer()->text->Delete();
1639 owner->currentBuffer()->text->sel_cursor =
1640 owner->currentBuffer()->text->cursor;
1644 owner->currentBuffer()->text->Delete();
1645 owner->currentBuffer()->text->sel_cursor =
1646 owner->currentBuffer()->text->cursor;
1656 /* -------> Delete word forward. */
1657 case LFUN_DELETE_WORD_FORWARD:
1658 owner->currentBuffer()->update(-2);
1660 owner->currentBuffer()->text->DeleteWordForward();
1661 owner->currentBuffer()->update( 1 );
1663 moveCursorUpdate(false);
1666 /* -------> Delete word backward. */
1667 case LFUN_DELETE_WORD_BACKWARD:
1668 owner->currentBuffer()->update(-2);
1670 owner->currentBuffer()->text->DeleteWordBackward();
1671 owner->currentBuffer()->update( 1 );
1673 moveCursorUpdate(false);
1676 /* -------> Kill to end of line. */
1677 case LFUN_DELETE_LINE_FORWARD:
1679 owner->currentBuffer()->update(-2);
1680 owner->currentBuffer()->text->DeleteLineForward();
1681 owner->currentBuffer()->update( 1 );
1683 moveCursorUpdate(false);
1686 /* -------> Set mark off. */
1689 owner->currentBuffer()->update(0);
1690 owner->currentBuffer()->text->sel_cursor =
1691 owner->currentBuffer()->text->cursor;
1692 setMessage(N_("Mark off"));
1695 /* -------> Set mark on. */
1698 owner->currentBuffer()->text->mark_set = 1;
1699 owner->currentBuffer()->update( 0 );
1700 owner->currentBuffer()->text->sel_cursor =
1701 owner->currentBuffer()->text->cursor;
1702 setMessage(N_("Mark on"));
1705 case LFUN_BACKSPACE:
1708 if (!owner->currentBuffer()->text->selection) {
1709 if (owner->getIntl()->getTrans()->backspace()) {
1710 owner->currentBuffer()->text->Backspace();
1711 owner->currentBuffer()->text->sel_cursor =
1712 owner->currentBuffer()->text->cursor;
1714 // It is possible to make it a lot faster still
1715 // just comment out the lone below...
1716 owner->currentView()->getScreen()->ShowCursor();
1725 case LFUN_BACKSPACE_SKIP:
1727 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1729 LyXCursor cursor = owner->currentBuffer()->text->cursor;
1732 if (!owner->currentBuffer()->text->selection) {
1734 && !(cursor.par->added_space_top
1735 == VSpace (VSpace::NONE))) {
1736 owner->currentBuffer()->text->SetParagraph
1737 (cursor.par->line_top,
1738 cursor.par->line_bottom,
1739 cursor.par->pagebreak_top,
1740 cursor.par->pagebreak_bottom,
1741 VSpace(VSpace::NONE), cursor.par->added_space_bottom,
1743 cursor.par->labelwidthstring, 0);
1744 owner->currentBuffer()->update (1);
1746 owner->currentBuffer()->text->Backspace();
1747 owner->currentBuffer()->text->sel_cursor
1757 case LFUN_BREAKPARAGRAPH:
1760 owner->currentBuffer()->text->BreakParagraph(0);
1762 SetUpdateTimer(0.01);
1763 owner->currentBuffer()->text->sel_cursor =
1764 owner->currentBuffer()->text->cursor;
1768 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1771 owner->currentBuffer()->text->BreakParagraph(1);
1773 SetUpdateTimer(0.01);
1774 owner->currentBuffer()->text->sel_cursor =
1775 owner->currentBuffer()->text->cursor;
1779 case LFUN_BREAKPARAGRAPH_SKIP:
1781 // When at the beginning of a paragraph, remove
1782 // indentation and add a "defskip" at the top.
1783 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
1785 LyXCursor cursor = owner->currentBuffer()->text->cursor;
1788 if (cursor.pos == 0) {
1789 if (cursor.par->added_space_top == VSpace(VSpace::NONE)) {
1790 owner->currentBuffer()->text->SetParagraph
1791 (cursor.par->line_top,
1792 cursor.par->line_bottom,
1793 cursor.par->pagebreak_top,
1794 cursor.par->pagebreak_bottom,
1795 VSpace(VSpace::DEFSKIP), cursor.par->added_space_bottom,
1797 cursor.par->labelwidthstring, 1);
1798 owner->currentBuffer()->update(1);
1802 owner->currentBuffer()->text->BreakParagraph(0);
1805 SetUpdateTimer(0.01);
1806 owner->currentBuffer()->text->sel_cursor = cursor;
1812 owner->currentBuffer()->text->InsertChar('\"'); // This " matches the single quote in the code
1815 moveCursorUpdate(false);
1821 InsetCommand *new_inset;
1822 if (action == LFUN_HTMLURL)
1823 new_inset = new InsetUrl("htmlurl", "", "");
1825 new_inset = new InsetUrl("url", "", "");
1826 owner->currentBuffer()->insertInset(new_inset);
1827 new_inset->Edit(0, 0);
1831 // --- lyxserver commands ----------------------------
1833 case LFUN_CHARATCURSOR:
1835 int pos = owner->currentBuffer()->text->cursor.pos;
1836 if(pos < owner->currentBuffer()->text->cursor.par->last)
1837 dispatch_buffer = owner->currentBuffer()->text->
1838 cursor.par->text[pos];
1840 dispatch_buffer = "EOF";
1846 tostr(owner->currentBuffer()->text->cursor.x) + ' '
1847 + tostr(owner->currentBuffer()->text->cursor.y);
1854 sscanf(argument.c_str(), " %d %ld", &x, &y);
1855 owner->currentBuffer()->text->SetCursorFromCoordinates(x, y);
1859 case LFUN_GETLAYOUT:
1861 tostr(owner->currentBuffer()->text->cursor.par->layout);
1866 LyXFont *font = &(owner->currentBuffer()->text->current_font);
1867 if(font->shape() == LyXFont::ITALIC_SHAPE)
1868 dispatch_buffer = 'E';
1869 else if(font->shape() == LyXFont::SMALLCAPS_SHAPE)
1870 dispatch_buffer = 'N';
1872 dispatch_buffer = '0';
1879 LyXFont *font = &(owner->currentBuffer()->text->current_font);
1880 if(font->latex() == LyXFont::ON)
1881 dispatch_buffer = 'L';
1883 dispatch_buffer = '0';
1888 setMessage(owner->currentBuffer()->getFileName());
1889 lyxerr.debug() << "FNAME["
1890 << owner->currentBuffer()->getFileName()
1897 keyseq.print(buf,100);
1898 dispatch_buffer = buf;
1899 lyxserver->notifyClient(dispatch_buffer);
1903 case LFUN_GOTOFILEROW:
1905 char file_name[100];
1907 sscanf(argument.c_str(), " %s %d", file_name, &row);
1909 // Must replace extension of the file to be .lyx and get full path
1910 string s = ChangeExtension(string(file_name), ".lyx", false);
1912 // Either change buffer or load the file
1913 if (bufferlist.exists(s))
1914 owner->currentView()->setBuffer(bufferlist.getBuffer(s));
1916 owner->currentView()->setBuffer(bufferlist.loadLyXFile(s));
1919 owner->currentBuffer()->setCursorFromRow(row);
1923 if (owner->currentBuffer()->text->cursor.y >
1924 owner->currentView()->getWorkArea()->h / 2) {
1925 owner->currentView()->getScreen()->
1926 Draw(owner->currentBuffer()->text->cursor.y -
1927 owner->currentView()->getWorkArea()->h/2);
1929 owner->currentView()->getScreen()->
1932 owner->currentBuffer()->update(0);
1933 owner->currentView()->redraw();
1940 int qa = lyxaction.LookupFunc(argument.c_str());
1941 setMessage(lyxaction.helpText((kb_action)qa));
1945 // --- accented characters ---------------------------
1948 case LFUN_CIRCUMFLEX:
1958 case LFUN_SPECIAL_CARON:
1961 case LFUN_HUNG_UMLAUT:
1967 if (keyseq.length==-1 && keyseq.getiso()!=0)
1972 owner->getIntl()->getTrans()->
1973 deadkey(c, get_accent(action).accent,
1974 owner->currentBuffer()->text);
1976 // Need to reset, in case the minibuffer calls these
1981 // copied verbatim from do_accent_char
1984 owner->currentBuffer()->text->sel_cursor =
1985 owner->currentBuffer()->text->cursor;
1989 // --- toolbar ----------------------------------
1990 case LFUN_PUSH_TOOLBAR:
1992 int nth = strToInt(argument);
1993 if (lyxerr.debugging(Debug::TOOLBAR)) {
1994 lyxerr << "LFUN_PUSH_TOOLBAR: argument = `"
1995 << argument << "'\n"
1996 << "LFUN_PUSH_TOOLBAR: nth = `"
1997 << nth << "'" << endl;
2002 setErrorMessage(N_("Push-toolbar needs argument > 0"));
2004 owner->getToolbar()->push(nth);
2009 case LFUN_ADD_TO_TOOLBAR:
2011 if (lyxerr.debugging(Debug::TOOLBAR)) {
2012 lyxerr << "LFUN_ADD_TO_TOOLBAR:"
2013 "argument = `" << argument << '\'' << endl;
2015 string tmp(argument);
2016 //lyxerr <<string("Argument: ") + argument);
2017 //lyxerr <<string("Tmp : ") + tmp);
2020 setErrorMessage(N_("Usage: toolbar-add-to <LyX command>"));
2022 owner->getToolbar()->add(argument, false);
2023 owner->getToolbar()->set();
2028 // --- insert characters ----------------------------------------
2030 case LFUN_INSERT_INSET_LATEX:
2032 Inset *new_inset = new InsetLatex(argument);
2033 owner->currentBuffer()->insertInset(new_inset);
2037 // --- Mathed stuff. If we are here, there is no locked inset yet.
2042 if (!greek_kb_flag) {
2044 setMessage(N_("Math greek mode on"));
2051 case LFUN_GREEK_TOGGLE:
2053 greek_kb_flag = (greek_kb_flag) ? 0: 2;
2054 if (greek_kb_flag) {
2055 setMessage(N_("Math greek keyboard on"));
2057 setMessage(N_("Math greek keyboard off"));
2062 case LFUN_MATH_DELIM:
2063 case LFUN_INSERT_MATRIX:
2065 if (owner->currentView()->available()) {
2066 owner->currentBuffer()->
2067 open_new_inset(new InsetFormula(false));
2068 owner->currentBuffer()->
2069 the_locking_inset->LocalDispatch(action, argument.c_str());
2074 case LFUN_INSERT_MATH:
2076 math_insert_symbol(argument.c_str());
2080 case LFUN_MATH_DISPLAY:
2082 if (owner->currentView()->available())
2083 owner->currentBuffer()->open_new_inset(new InsetFormula(true));
2087 case LFUN_MATH_MACRO:
2089 if (owner->currentView()->available()) {
2092 setErrorMessage(N_("Missing argument"));
2094 string s1 = token(s, ' ', 1);
2095 int na = s1.empty() ? 0: atoi(s1.c_str());
2096 owner->currentBuffer()->
2097 open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2103 case LFUN_MATH_MODE: // Open or create a math inset
2106 if (owner->currentView()->available())
2107 owner->currentBuffer()->open_new_inset(new InsetFormula);
2108 setMessage(N_("Math editor mode"));
2112 case LFUN_MATH_NUMBER:
2113 case LFUN_MATH_LIMITS:
2115 setErrorMessage(N_("This is only allowed in math mode!"));
2119 case LFUN_INSERT_CITATION:
2121 InsetCitation *new_inset = new InsetCitation();
2123 // The note, if any, must be after the key, delimited
2124 // by a | so both key and remark can have spaces.
2125 if (!argument.empty()) {
2126 string lsarg(argument);
2127 if (contains(lsarg, "|")) {
2128 new_inset->setContents(token(lsarg, '|', 0));
2129 new_inset->setOptions(token(lsarg, '|', 1));
2131 new_inset->setContents(lsarg);
2132 owner->currentBuffer()->insertInset(new_inset);
2134 owner->currentBuffer()->insertInset(new_inset);
2135 new_inset->Edit(0,0);
2140 case LFUN_INSERT_BIBTEX:
2142 // ale970405+lasgoutt970425
2143 // The argument can be up to two tokens separated
2144 // by a space. The first one is the bibstyle.
2145 string lsarg(argument);
2146 string bibstyle = token(lsarg, ' ', 1);
2147 if (bibstyle.empty())
2149 InsetBibtex *new_inset
2150 = new InsetBibtex(token(lsarg, ' ', 0),
2152 owner->currentBuffer());
2154 owner->currentBuffer()->insertInset(new_inset);
2155 if (lsarg.empty()) {
2156 new_inset->Edit(0,0);
2161 // BibTeX data bases
2162 case LFUN_BIBDB_ADD:
2164 InsetBibtex *inset =
2165 (InsetBibtex*)getInsetByCode(Inset::BIBTEX_CODE);
2167 inset->addDatabase(argument);
2172 case LFUN_BIBDB_DEL:
2174 InsetBibtex *inset =
2175 (InsetBibtex*)getInsetByCode(Inset::BIBTEX_CODE);
2177 inset->delDatabase(argument);
2182 case LFUN_BIBTEX_STYLE:
2184 InsetBibtex *inset =
2185 (InsetBibtex*)getInsetByCode(Inset::BIBTEX_CODE);
2187 inset->setOptions(argument);
2192 case LFUN_INDEX_INSERT:
2193 case LFUN_INDEX_INSERT_LAST:
2195 InsetIndex *new_inset = new InsetIndex();
2196 if (!argument.empty()) {
2197 string lsarg(argument);
2198 new_inset->setContents(lsarg);
2199 owner->currentBuffer()->insertInset(new_inset);
2202 //get the current word for an argument
2207 int lastpos =owner->currentBuffer()->text->cursor.pos-1;
2209 //this shouldn't happen, but let's be careful
2210 if (lastpos < 0) lastpos=0;
2212 // get the current word
2213 // note that this must be done before
2214 // inserting the inset, or the inset will break
2216 string curstring(owner->currentBuffer()->text->cursor.par->GetWord(lastpos));
2218 //make the new inset and write the current word into it
2219 InsetIndex *new_inset = new InsetIndex();
2221 new_inset->setContents(curstring);
2223 //don't edit it if the call was to INSERT_LAST
2224 if(action!=LFUN_INDEX_INSERT_LAST) {
2225 new_inset->Edit(0,0);
2227 //it looks blank on the screen unless
2228 //we do something. put it here.
2230 // move the cursor to the returned value of lastpos
2231 // but only for the auto-insert
2232 owner->currentBuffer()->text->cursor.pos=lastpos;
2235 //put the new inset into the buffer.
2236 // there should be some way of knowing the user
2237 //cancelled & avoiding this, but i don't know how
2238 owner->currentBuffer()->insertInset(new_inset);
2243 case LFUN_INDEX_PRINT:
2245 Inset *new_inset = new InsetPrintIndex(owner->currentBuffer());
2246 owner->currentBuffer()->insertInset(new_inset, "Standard", true);
2250 case LFUN_PARENTINSERT:
2252 lyxerr << "arg " << argument << endl;
2253 Inset *new_inset = new InsetParent(argument, owner->currentBuffer());
2254 owner->currentBuffer()->insertInset(new_inset, "Standard", true);
2258 case LFUN_CHILDINSERT:
2260 Inset *new_inset = new InsetInclude(argument,owner->currentBuffer());
2261 owner->currentBuffer()->insertInset(new_inset, "Standard", true);
2262 new_inset->Edit(0,0);
2266 case LFUN_CHILDOPEN:
2268 string filename = MakeAbsPath(argument,
2269 OnlyPath(owner->currentBuffer()->getFileName()));
2270 setMessage(N_("Opening child document ") +
2271 MakeDisplayPath(filename) + "...");
2272 owner->currentView()->savePosition();
2273 if (bufferlist.exists(filename))
2274 owner->currentView()->setBuffer(bufferlist.getBuffer(filename));
2276 owner->currentView()->setBuffer(bufferlist.loadLyXFile(filename));
2280 case LFUN_INSERT_NOTE:
2284 case LFUN_INSERTFOOTNOTE:
2286 LyXParagraph::footnote_kind kind;
2287 if (argument == "footnote")
2288 { kind = LyXParagraph::FOOTNOTE; }
2289 else if (argument == "margin")
2290 { kind = LyXParagraph::MARGIN; }
2291 else if (argument == "figure")
2292 { kind = LyXParagraph::FIG; }
2293 else if (argument == "table")
2294 { kind = LyXParagraph::TAB; }
2295 else if (argument == "wide-fig")
2296 { kind = LyXParagraph::WIDE_FIG; }
2297 else if (argument == "wide-tab")
2298 { kind = LyXParagraph::WIDE_TAB; }
2299 else if (argument == "algorithm")
2300 { kind = LyXParagraph::ALGORITHM; }
2302 setErrorMessage(N_("Unknown kind of footnote"));
2305 owner->currentBuffer()->text->InsertFootnoteEnvironment(kind);
2306 owner->currentBuffer()->update(1);
2310 case LFUN_BUFFERBULLETSSELECT:
2314 case LFUN_TOGGLECURSORFOLLOW:
2315 cursor_follows_scrollbar = !cursor_follows_scrollbar;
2318 case LFUN_KMAP_OFF: // keymap off
2319 owner->getIntl()->KeyMapOn(false);
2322 case LFUN_KMAP_PRIM: // primary keymap
2323 owner->getIntl()->KeyMapPrim();
2326 case LFUN_KMAP_SEC: // secondary keymap
2327 owner->getIntl()->KeyMapSec();
2330 case LFUN_KMAP_TOGGLE: // toggle keymap
2331 owner->getIntl()->ToggleKeyMap();
2334 case LFUN_SELFINSERT:
2336 for (string::size_type i = 0; i < argument.length(); ++i) {
2337 owner->currentBuffer()->text->InsertChar(argument[i]);
2338 // This needs to be in the loop, or else we
2339 // won't break lines correctly. (Asger)
2343 owner->currentBuffer()->text->sel_cursor =
2344 owner->currentBuffer()->text->cursor;
2345 moveCursorUpdate(false);
2349 case LFUN_UNKNOWN_ACTION:
2351 if (owner->currentBuffer()->isReadonly()) {
2353 setErrorMessage(N_("Document is read only"));
2357 if (!argument.empty()) {
2359 /* Automatically delete the currently selected
2360 * text and replace it with what is being
2361 * typed in now. Depends on lyxrc settings
2362 * "auto_region_delete", which defaults to
2365 if ( lyxrc->auto_region_delete ) {
2366 if (owner->currentBuffer()->text->selection){
2367 owner->currentBuffer()->text->CutSelection(false);
2368 owner->currentBuffer()->update(-1);
2373 for (string::size_type i = 0; i < argument.length(); ++i) {
2374 if (greek_kb_flag) {
2375 if (!math_insert_greek(argument[i]))
2376 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->currentBuffer()->text);
2378 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->currentBuffer()->text);
2384 owner->currentBuffer()->text->sel_cursor =
2385 owner->currentBuffer()->text->cursor;
2386 moveCursorUpdate(false);
2389 // why is an "Unknown action" with empty
2390 // argument even dispatched in the first
2391 // place? I`ll probably change that. (Lgb)
2393 setErrorMessage(N_("Unknown action"));
2397 lyxerr << "A truly unknown func!" << endl;
2403 string res=getMessage();
2406 if (!commandshortcut.empty()) {
2407 string newbuf = owner->getMiniBuffer()->GetText();
2408 if (newbuf != commandshortcut) {
2409 owner->getMiniBuffer()->Set(newbuf
2415 owner->getMiniBuffer()->Set(string(_(res.c_str()))
2416 + " " + commandshortcut);
2419 return getMessage();
2423 void LyXFunc::setupLocalKeymap()
2425 keyseq.stdmap = keyseq.curmap = toplevel_keymap;
2426 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap;
2430 void LyXFunc::MenuNew(bool fromTemplate)
2432 string fname, initpath = lyxrc->document_path;
2435 if (owner->currentView()->available()) {
2436 string trypath = owner->currentBuffer()->filepath;
2437 // If directory is writeable, use this as default.
2438 if (IsDirWriteable(trypath) == 1)
2443 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2444 fileDlg.SetButton(1, _("Templates"), lyxrc->template_path);
2445 fname = fileDlg.Select(_("Enter Filename for new document"),
2446 initpath, "*.lyx", _("newfile"));
2449 if (fname.empty()) {
2450 owner->getMiniBuffer()->Set(_("Canceled."));
2451 lyxerr.debug() << "New Document Cancelled." << endl;
2455 // get absolute path of file and make sure the filename ends
2457 string s = MakeAbsPath(fname);
2458 if (!IsLyXFilename(s))
2461 // Check if the document already is open
2462 if (bufferlist.exists(s)){
2463 switch(AskConfirmation(_("Document is already open:"),
2464 MakeDisplayPath(s,50),
2465 _("Do you want to close that document now?\n"
2466 "('No' will just switch to the open version)")))
2468 case 1: // Yes: close the document
2469 if (!bufferlist.close(bufferlist.getBuffer(s)))
2470 // If close is canceled, we cancel here too.
2473 case 2: // No: switch to the open document
2474 owner->currentView()->setBuffer(bufferlist.getBuffer(s));
2476 case 3: // Cancel: Do nothing
2477 owner->getMiniBuffer()->Set(_("Canceled."));
2482 // Check whether the file already exists
2483 if (IsLyXFilename(s)) {
2484 FilePtr myfile(s, FilePtr::read);
2486 AskQuestion(_("File already exists:"),
2487 MakeDisplayPath(s,50),
2488 _("Do you want to open the document?"))) {
2490 owner->getMiniBuffer()->Set(_("Opening document"),
2491 MakeDisplayPath(s), "...");
2493 owner->currentView()->setBuffer(
2494 bufferlist.loadLyXFile(s));
2495 owner->getMiniBuffer()->Set(_("Document"),
2502 // The template stuff
2506 fname = fileDlg.Select(_("Choose template"),
2507 lyxrc->template_path,
2513 // find a free buffer
2514 lyxerr.debug() << "Find a free buffer." << endl;
2515 owner->currentView()->setBuffer(bufferlist.newFile(s,templname));
2519 void LyXFunc::MenuOpen()
2521 string initpath = lyxrc->document_path;
2524 if (owner->currentView()->available()) {
2525 string trypath = owner->currentBuffer()->filepath;
2526 // If directory is writeable, use this as default.
2527 if (IsDirWriteable(trypath) == 1)
2533 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2534 fileDlg.SetButton(1, _("Examples"),
2535 AddPath(system_lyxdir, "examples"));
2536 string filename = fileDlg.Select(_("Select Document to Open"),
2540 // check selected filename
2541 if (filename.empty()) {
2542 owner->getMiniBuffer()->Set(_("Canceled."));
2546 // get absolute path of file and make sure the filename ends
2548 filename = MakeAbsPath(filename);
2549 if (!IsLyXFilename(filename))
2553 owner->getMiniBuffer()->Set(_("Opening document"),
2554 MakeDisplayPath(filename), "...");
2555 Buffer * openbuf = bufferlist.loadLyXFile(filename);
2557 owner->currentView()->setBuffer(openbuf);
2558 owner->getMiniBuffer()->Set(_("Document"),
2559 MakeDisplayPath(filename),
2562 owner->getMiniBuffer()->Set(_("Could not open document"),
2563 MakeDisplayPath(filename));
2568 void LyXFunc::doImportASCII(bool linorpar)
2570 string initpath = lyxrc->document_path;
2573 if (owner->currentView()->available()) {
2574 string trypath = owner->currentBuffer()->filepath;
2575 // If directory is writeable, use this as default.
2576 if (IsDirWriteable(trypath) == 1)
2582 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2583 fileDlg.SetButton(1, _("Examples"),
2584 AddPath(system_lyxdir, "examples"));
2585 string filename = fileDlg.Select(_("Select ASCII file to Import"),
2589 // check selected filename
2590 if (filename.empty()) {
2591 owner->getMiniBuffer()->Set(_("Canceled."));
2595 // get absolute path of file
2596 filename = MakeAbsPath(filename);
2598 string s = ChangeExtension(filename, ".lyx", false);
2600 // Check if the document already is open
2601 if (bufferlist.exists(s)){
2602 switch(AskConfirmation(_("Document is already open:"),
2603 MakeDisplayPath(s,50),
2604 _("Do you want to close that document now?\n"
2605 "('No' will just switch to the open version)")))
2607 case 1: // Yes: close the document
2608 if (!bufferlist.close(bufferlist.getBuffer(s)))
2609 // If close is canceled, we cancel here too.
2612 case 2: // No: switch to the open document
2613 owner->currentView()->setBuffer(bufferlist.getBuffer(s));
2615 case 3: // Cancel: Do nothing
2616 owner->getMiniBuffer()->Set(_("Canceled."));
2621 // Check if a LyX document by the same root exists in filesystem
2622 FileInfo f(s, true);
2623 if (f.exist() && !AskQuestion(_("A document by the name"),
2625 _("already exists. Overwrite?"))) {
2626 owner->getMiniBuffer()->Set(_("Canceled."));
2630 owner->currentView()->setBuffer(bufferlist.newFile(s,string()));
2631 owner->getMiniBuffer()->Set(_("Importing ASCII file"),
2632 MakeDisplayPath(filename), "...");
2633 // Insert ASCII file
2634 InsertAsciiFile(filename,linorpar);
2635 owner->getMiniBuffer()->Set(_("ASCII file "),
2636 MakeDisplayPath(filename),
2641 void LyXFunc::doImportLaTeX(bool isnoweb)
2643 string initpath = lyxrc->document_path;
2646 if (owner->currentView()->available()) {
2647 string trypath = owner->currentBuffer()->filepath;
2648 // If directory is writeable, use this as default.
2649 if (IsDirWriteable(trypath) == 1)
2655 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2656 fileDlg.SetButton(1, _("Examples"),
2657 AddPath(system_lyxdir, "examples"));
2660 filename = fileDlg.Select(_("Select Noweb file to Import"),
2663 filename = fileDlg.Select(_("Select LaTeX file to Import"),
2669 // check selected filename
2670 if (filename.empty()) {
2671 owner->getMiniBuffer()->Set(_("Canceled."));
2675 // get absolute path of file
2676 filename = MakeAbsPath(filename);
2678 // Check if the document already is open
2679 string LyXfilename = ChangeExtension(filename, ".lyx", false);
2680 if (bufferlist.exists(LyXfilename)){
2681 switch(AskConfirmation(_("Document is already open:"),
2682 MakeDisplayPath(LyXfilename,50),
2683 _("Do you want to close that document now?\n"
2684 "('No' will just switch to the open version)")))
2686 case 1: // Yes: close the document
2687 if (!bufferlist.close(bufferlist.getBuffer(LyXfilename)))
2688 // If close is canceled, we cancel here too.
2691 case 2: // No: switch to the open document
2692 owner->currentView()->setBuffer(
2693 bufferlist.getBuffer(LyXfilename));
2695 case 3: // Cancel: Do nothing
2696 owner->getMiniBuffer()->Set(_("Canceled."));
2701 // Check if a LyX document by the same root exists in filesystem
2702 FileInfo f(LyXfilename, true);
2703 if (f.exist() && !AskQuestion(_("A document by the name"),
2704 MakeDisplayPath(LyXfilename),
2705 _("already exists. Overwrite?"))) {
2706 owner->getMiniBuffer()->Set(_("Canceled."));
2713 owner->getMiniBuffer()->Set(_("Importing LaTeX file"),
2714 MakeDisplayPath(filename), "...");
2715 ImportLaTeX myImport(filename);
2716 openbuf = myImport.run();
2718 owner->getMiniBuffer()->Set(_("Importing Noweb file"),
2719 MakeDisplayPath(filename), "...");
2720 ImportNoweb myImport(filename);
2721 openbuf = myImport.run();
2724 owner->currentView()->setBuffer(openbuf);
2725 owner->getMiniBuffer()->Set(isnoweb ?
2726 _("Noweb file ") : _("LateX file "),
2727 MakeDisplayPath(filename),
2730 owner->getMiniBuffer()->Set(isnoweb ?
2731 _("Could not import Noweb file") :
2732 _("Could not import LaTeX file"),
2733 MakeDisplayPath(filename));
2738 void LyXFunc::MenuInsertLyXFile(string const & filen)
2740 string filename = filen;
2742 if (filename.empty()) {
2743 // Launch a file browser
2744 string initpath = lyxrc->document_path;
2747 if (owner->currentView()->available()) {
2748 string trypath = owner->currentBuffer()->filepath;
2749 // If directory is writeable, use this as default.
2750 if (IsDirWriteable(trypath) == 1)
2756 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2757 fileDlg.SetButton(1, _("Examples"),
2758 AddPath(system_lyxdir, "examples"));
2759 filename = fileDlg.Select(_("Select Document to Insert"),
2763 // check selected filename
2764 if (filename.empty()) {
2765 owner->getMiniBuffer()->Set(_("Canceled."));
2770 // get absolute path of file and make sure the filename ends
2772 filename = MakeAbsPath(filename);
2773 if (!IsLyXFilename(filename))
2777 owner->getMiniBuffer()->Set(_("Inserting document"),
2778 MakeDisplayPath(filename), "...");
2779 bool res = owner->currentBuffer()->insertLyXFile(filename);
2781 owner->getMiniBuffer()->Set(_("Document"),
2782 MakeDisplayPath(filename),
2785 owner->getMiniBuffer()->Set(_("Could not insert document"),
2786 MakeDisplayPath(filename));
2791 void LyXFunc::reloadBuffer()
2793 string fn = owner->currentBuffer()->getFileName();
2794 if (bufferlist.close(owner->currentBuffer()))
2795 owner->currentView()->setBuffer(bufferlist.loadLyXFile(fn));
2799 void LyXFunc::CloseBuffer()
2801 if (bufferlist.close(owner->currentBuffer()) && !quitting) {
2802 if (bufferlist.isEmpty()) {
2803 // need this otherwise SEGV may occur while trying to
2804 // set variables that don't exist
2805 // since there's no current buffer
2806 CloseAllBufferRelatedPopups();
2809 owner->currentView()->setBuffer(bufferlist.first());
2815 Inset* LyXFunc::getInsetByCode(Inset::Code code)
2819 LyXCursor cursor = owner->currentBuffer()->text->cursor;
2820 int pos = cursor.pos;
2821 LyXParagraph *par = cursor.par;
2823 while (par && !found) {
2824 while ((inset = par->ReturnNextInsetPointer(pos))){
2825 if (inset->LyxCode()==code) {
2833 return (found) ? inset: 0;
2837 // Each "owner" should have it's own message method. lyxview and
2838 // the minibuffer would use the minibuffer, but lyxserver would
2839 // send an ERROR signal to its client. Alejandro 970603
2840 // This func is bit problematic when it comes to NLS, to make the
2841 // lyx servers client be language indepenent we must not translate
2842 // strings sent to this func.
2843 void LyXFunc::setErrorMessage(string const &m)
2845 dispatch_buffer = m;
2850 void LyXFunc::setMessage(string const & m)
2852 dispatch_buffer = m;