1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * ====================================================== */
15 using std::istringstream;
28 #pragma implementation
32 #include "lyxlookup.h"
35 #include "bufferlist.h"
36 #include "ColorHandler.h"
37 #include "lyxserver.h"
42 #include "LyXAction.h"
43 #include "insets/inseturl.h"
44 #include "insets/insetlatexaccent.h"
45 #include "insets/insettoc.h"
46 #include "insets/insetref.h"
47 #include "insets/insetparent.h"
48 #include "insets/insetindex.h"
49 #include "insets/insetinclude.h"
50 #include "insets/insetbib.h"
51 #include "insets/insetcite.h"
52 #include "insets/insettext.h"
53 #include "insets/insetert.h"
54 #include "insets/insetexternal.h"
55 #include "insets/insetgraphics.h"
56 #include "insets/insetfoot.h"
57 #include "insets/insetmarginal.h"
58 #include "insets/insetminipage.h"
59 #include "insets/insetfloat.h"
60 #include "insets/insetlist.h"
61 #include "insets/insettabular.h"
62 #include "insets/insettheorem.h"
63 #include "insets/insetcaption.h"
64 #include "mathed/formulamacro.h"
65 #include "spellchecker.h" // RVDK_PATCH_5
66 #include "minibuffer.h"
70 #include "lyx_gui_misc.h"
71 #include "support/filetools.h"
72 #include "support/FileInfo.h"
73 #include "support/syscall.h"
74 #include "support/lstrings.h"
75 #include "support/path.h"
80 #include "trans_mgr.h"
81 #include "ImportLaTeX.h"
82 #include "ImportNoweb.h"
86 #include "bufferview_funcs.h"
87 #include "frontends/Dialogs.h"
88 #include "frontends/Toolbar.h"
90 #include "frontends/Menubar.h"
94 #include "FloatList.h"
99 extern bool cursor_follows_scrollbar;
101 extern void InsertAsciiFile(BufferView *, string const &, bool);
102 extern void math_insert_symbol(char const *);
103 extern bool math_insert_greek(char);
104 extern BufferList bufferlist;
105 extern LyXServer * lyxserver;
106 extern int greek_kb_flag;
107 extern bool selection_possible;
109 extern kb_keymap * toplevel_keymap;
111 extern void MenuWrite(Buffer *);
112 extern bool MenuWriteAs(Buffer *);
113 extern int MenuRunLaTeX(Buffer *);
114 extern int MenuBuildProg(Buffer *);
115 extern int MenuRunChktex(Buffer *);
116 extern bool CreatePostscript(Buffer *, bool);
117 extern void MenuPrint(Buffer *);
118 extern void MenuSendto();
119 extern void QuitLyX();
120 extern void MenuFax(Buffer *);
121 extern void MenuExport(Buffer *, string const &);
122 extern void show_symbols_form(LyXFunc *);
124 extern LyXAction lyxaction;
126 extern tex_accent_struct get_accent(kb_action action);
128 extern void AutoSave(BufferView *);
129 extern bool PreviewDVI(Buffer *);
130 extern bool PreviewPostscript(Buffer *);
131 extern void MenuInsertLabel(char const *);
132 extern void MenuInsertRef();
133 extern void MenuLayoutCharacter();
134 extern void MenuLayoutParagraph();
135 extern void MenuLayoutDocument();
136 extern void MenuLayoutPaper();
137 extern void MenuLayoutTable(int flag);
138 extern void MenuLayoutQuotes();
139 extern void MenuLayoutPreamble();
140 extern void MenuLayoutSave();
141 extern void bulletForm();
143 extern Buffer * NewLyxFile(string const &);
144 extern void LoadLyXFile(string const &);
145 extern void Reconfigure(BufferView *);
147 extern LyXTextClass::size_type current_layout;
148 extern int getISOCodeFromLaTeX(char *);
150 extern void ShowLatexLog();
152 /* === globals =========================================================== */
154 bool LyXFunc::show_sc = true;
157 LyXFunc::LyXFunc(LyXView * o)
161 lyx_dead_action = LFUN_NOACTION;
162 lyx_calling_dead_action = LFUN_NOACTION;
167 // I changed this func slightly. I commented out the ...FinishUndo(),
168 // this means that all places that used to have a moveCursorUpdate, now
169 // have a ...FinishUndo() as the preceeding statement. I have also added
170 // a moveCursorUpdate to some of the functions that updated the cursor, but
171 // that did not show its new position.
173 void LyXFunc::moveCursorUpdate(bool selecting)
175 if (selecting || owner->view()->text->mark_set) {
176 owner->view()->text->SetSelection();
177 owner->view()->toggleToggle();
179 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
180 owner->view()->showCursor();
182 /* ---> Everytime the cursor is moved, show the current font state. */
183 // should this too me moved out of this func?
184 //owner->showState();
185 owner->view()->setState();
189 int LyXFunc::processKeyEvent(XEvent * ev)
193 XKeyEvent * keyevent = &ev->xkey;
194 KeySym keysym_return = 0;
196 int num_bytes = LyXLookupString(ev, s_r, 10, &keysym_return);
197 s_r[num_bytes] = '\0';
199 if (lyxerr.debugging(Debug::KEY)) {
200 char * tmp = XKeysymToString(keysym_return);
201 string stm = (tmp ? tmp : "");
202 lyxerr << "KeySym is "
205 << keysym_return << "]"
206 << " and num_bytes is "
208 << " the string returned is \""
209 << s_r << '\"' << endl;
211 // Do nothing if we have nothing (JMarc)
212 if (num_bytes == 0 && keysym_return == NoSymbol) {
213 lyxerr[Debug::KEY] << "Empty kbd action (probably composing)"
218 // this function should be used always [asierra060396]
219 UpdatableInset * tli = owner->view()->the_locking_inset;
220 if (owner->view()->available() && tli && (keysym_return==XK_Escape)) {
221 if (tli == tli->GetLockingInset()) {
222 owner->view()->unlockInset(tli);
223 owner->view()->text->CursorRight(owner->view());
224 moveCursorUpdate(false);
227 tli->UnlockInsetInInset(owner->view(),
228 tli->GetLockingInset(),true);
233 // Can we be sure that this will work for all X-Windows
234 // implementations? (Lgb)
235 // This code snippet makes lyx ignore some keys. Perhaps
236 // all of them should be explictly mentioned?
237 if((keysym_return >= XK_Shift_L && keysym_return <= XK_Hyper_R)
238 || keysym_return == XK_Mode_switch || keysym_return == 0x0)
241 // Do a one-deep top-level lookup for
242 // cancel and meta-fake keys. RVDK_PATCH_5
243 cancel_meta_seq.reset();
245 int action = cancel_meta_seq.addkey(keysym_return, keyevent->state
246 &(ShiftMask|ControlMask
249 // When not cancel or meta-fake, do the normal lookup.
250 // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
251 // Mostly, meta_fake_bit = 0. RVDK_PATCH_5.
252 if ( (action != LFUN_CANCEL) && (action != LFUN_META_FAKE) ) {
254 // remove Caps Lock and Mod2 as a modifiers
255 action = keyseq.addkey(keysym_return,
256 (keyevent->state | meta_fake_bit)
257 &(ShiftMask|ControlMask
260 // Dont remove this unless you know what you are doing.
263 if (action == 0) action = LFUN_PREFIX;
265 if (lyxerr.debugging(Debug::KEY)) {
271 << num_bytes << "]" << endl;
274 // already here we know if it any point in going further
275 // why not return already here if action == -1 and
276 // num_bytes == 0? (Lgb)
278 if(keyseq.length > 1 || keyseq.length < -1) {
281 owner->getMiniBuffer()->Set(buf);
285 if (keyseq.length < -1) { // unknown key sequence...
289 owner->getMiniBuffer()->Set(_("Unknown sequence:"), buf);
293 char isochar = keyseq.getiso();
294 if (!(keyevent->state&ControlMask) &&
295 !(keyevent->state&Mod1Mask) &&
296 (isochar && keysym_return < 0xF000)) {
299 if (argument.empty()) {
300 lyxerr.debug() << "Empty argument!" << endl;
301 // This can`t possibly be of any use
302 // so we`ll skip the dispatch.
306 if (action == LFUN_SELFINSERT) {
310 bool tmp_sc = show_sc;
312 Dispatch(action, argument.c_str());
319 LyXFunc::func_status LyXFunc::getStatus(int ac) const
322 func_status flag = LyXFunc::OK;
324 Buffer * buf = owner->buffer();
326 if (lyxaction.isPseudoAction(ac))
327 action = lyxaction.retrieveActionArg(ac, argument);
329 action = static_cast<kb_action>(ac);
331 if (action == LFUN_UNKNOWN_ACTION) {
332 setErrorMessage(N_("Unknown action"));
333 return LyXFunc::Unknown;
336 // Check whether we need a buffer
337 if (!lyxaction.funcHasFlag(action, LyXAction::NoBuffer)) {
338 // Yes we need a buffer, do we have one?
341 // Can we use a readonly buffer?
342 if (buf->isReadonly() &&
343 !lyxaction.funcHasFlag(action,
344 LyXAction::ReadOnly)) {
346 setErrorMessage(N_("Document is read-only"));
347 flag |= LyXFunc::Disabled;
351 setErrorMessage(N_("Command not allowed with"
352 "out any document open"));
353 flag |= LyXFunc::Disabled;
358 // I would really like to avoid having this switch and rather try to
359 // encode this in the function itself.
360 static bool noLaTeX = lyxrc.latex_command == "none";
361 bool disable = false;
364 disable = noLaTeX || lyxrc.view_dvi_command == "none";
367 disable = noLaTeX || lyxrc.view_ps_command == "none";
374 disable = noLaTeX || lyxrc.print_command == "none";
377 disable = noLaTeX || lyxrc.fax_command == "none";
380 if (argument == "latex" || argument == "noweb")
381 disable = lyxrc.relyx_command == "none";
382 else if (argument == "linuxdoc")
383 disable = lyxrc.linuxdoc_to_lyx_command == "none";
386 if (argument == "latex")
387 disable = (! buf->isLatex() && ! buf->isLiterate()) ;
388 else if (argument == "linuxdoc")
389 disable = ! buf->isLinuxDoc();
390 else if (argument == "docbook")
391 disable = ! buf->isDocBook();
392 else if (argument == "dvi" || argument == "postscript")
394 else if (argument == "html")
395 disable = (buf->isLinuxDoc()
396 && lyxrc.linuxdoc_to_html_command == "none")
398 && lyxrc.docbook_to_html_command == "none")
399 || (! buf->isLinuxDoc() && ! buf->isDocBook()
400 && lyxrc.html_command == "none");
401 else if (argument == "custom")
402 disable = (! buf->isLatex() && ! buf->isLiterate());
405 disable = buf->undostack.empty();
408 disable = buf->redostack.empty();
410 case LFUN_SPELLCHECK:
411 disable = lyxrc.isp_command == "none";
414 disable = lyxrc.chktex_command == "none";
417 disable = (lyxrc.literate_command == "none"
418 || ! buf->isLiterate());
422 case LFUN_LAYOUT_TABLE:
423 disable = ! owner->view()->text->cursor.par()->table;
426 case LFUN_LAYOUT_TABULAR:
428 if (owner->view()->the_locking_inset) {
429 disable = (owner->view()->the_locking_inset->LyxCode() != Inset::TABULAR_CODE) &&
430 !owner->view()->the_locking_inset->GetFirstLockingInsetOfType(Inset::TABULAR_CODE);
434 case LFUN_TABULAR_FEATURE:
436 if (owner->view()->the_locking_inset) {
438 if (owner->view()->the_locking_inset->LyxCode() == Inset::TABULAR_CODE) {
439 ret = static_cast<InsetTabular *>
440 (owner->view()->the_locking_inset)->
442 } else if (owner->view()->the_locking_inset->GetFirstLockingInsetOfType(Inset::TABULAR_CODE)) {
443 ret = static_cast<InsetTabular *>
444 (owner->view()->the_locking_inset->
445 GetFirstLockingInsetOfType(Inset::TABULAR_CODE))->
456 flag |= LyXFunc::ToggleOn;
460 flag |= LyXFunc::ToggleOff;
466 case LFUN_VC_REGISTER:
467 disable = buf->lyxvc.inUse();
469 case LFUN_VC_CHECKIN:
470 disable = !buf->lyxvc.inUse() || buf->isReadonly();
472 case LFUN_VC_CHECKOUT:
473 disable = !buf->lyxvc.inUse() || !buf->isReadonly();
477 case LFUN_VC_HISTORY:
478 disable = !buf->lyxvc.inUse();
484 flag |= LyXFunc::Disabled;
487 func_status box = LyXFunc::ToggleOff;
488 LyXFont font = owner->view()->text->real_current_font;
491 if (font.emph() == LyXFont::ON)
492 box = LyXFunc::ToggleOn;
495 if (font.noun() == LyXFont::ON)
496 box = LyXFunc::ToggleOn;
499 if (font.series() == LyXFont::BOLD_SERIES)
500 box = LyXFunc::ToggleOn;
503 if (font.latex() == LyXFont::ON)
504 box = LyXFunc::ToggleOn;
517 string LyXFunc::Dispatch(string const & s)
519 // Split command string into command and argument
520 string cmd, line = frontStrip(s);
521 string arg = strip(frontStrip(split(line, cmd, ' ')));
523 return Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
527 string LyXFunc::Dispatch(int ac,
528 char const * do_not_use_this_arg)
533 // we have not done anything wrong yet.
535 dispatch_buffer.erase();
537 // if action is a pseudo-action, we need the real action
538 if (lyxaction.isPseudoAction(ac)) {
540 action = static_cast<kb_action>
541 (lyxaction.retrieveActionArg(ac, tmparg));
545 action = static_cast<kb_action>(ac);
546 if (do_not_use_this_arg)
547 argument = do_not_use_this_arg; // except here
550 selection_possible = false;
552 if (owner->view()->available())
553 owner->view()->hideCursor();
555 // We cannot use this function here
556 if (getStatus(ac) & Disabled)
557 goto exit_with_message;
559 commandshortcut.erase();
561 if (lyxrc.display_shortcuts && show_sc) {
562 if (action != LFUN_SELFINSERT) {
563 // Put name of command and list of shortcuts
564 // for it in minibuffer
565 string comname = lyxaction.getActionName(action);
567 int pseudoaction = action;
568 bool argsadded = false;
570 if (!argument.empty()) {
571 // If we have the command with argument,
574 lyxaction.searchActionArg(action,
577 if (pseudoaction == -1) {
578 pseudoaction = action;
580 comname += " " + argument;
585 string shortcuts = toplevel_keymap->findbinding(pseudoaction);
587 if (!shortcuts.empty()) {
588 comname += ": " + shortcuts;
589 } else if (!argsadded) {
590 comname += " " + argument;
593 if (!comname.empty()) {
594 comname = strip(comname);
595 commandshortcut = "(" + comname + ')';
596 owner->getMiniBuffer()->Set(commandshortcut);
597 // Here we could even add a small pause,
598 // to annoy the user and make him learn
600 // No! That will just annoy, not teach
601 // anything. The user will read the messages
602 // if they are interested. (Asger)
607 // If in math mode pass the control to
608 // the math inset [asierra060396]
609 if (owner->view()->available() &&
610 owner->view()->the_locking_inset) {
611 UpdatableInset::RESULT result;
612 if ((action > 1) || ((action == LFUN_UNKNOWN_ACTION) &&
613 (keyseq.length >= -1)))
615 if ((action==LFUN_UNKNOWN_ACTION) && argument.empty()){
616 argument = keyseq.getiso();
618 // Undo/Redo pre 0.13 is a bit tricky for insets.
619 if (action == LFUN_UNDO) {
621 UpdatableInset * inset =
622 owner->view()->the_locking_inset;
623 inset->GetCursorPos(owner->view(), slx, sly);
624 owner->view()->unlockInset(inset);
625 owner->view()->menuUndo();
626 if (owner->view()->text->cursor.par()->
627 IsInset(owner->view()->text->cursor.pos())) {
628 inset = static_cast<UpdatableInset*>(
629 owner->view()->text->cursor.par()->
630 GetInset(owner->view()->text->
636 inset->Edit(owner->view(),slx,sly,0);
638 } else if (action == LFUN_REDO) {
640 UpdatableInset * inset = owner->view()->
642 inset->GetCursorPos(owner->view(), slx, sly);
643 owner->view()->unlockInset(inset);
644 owner->view()->menuRedo();
645 inset = static_cast<UpdatableInset*>(
646 owner->view()->text->cursor.par()->
647 GetInset(owner->view()->text->
650 inset->Edit(owner->view(),slx,sly,0);
652 } else if (((result=owner->view()->the_locking_inset->
653 LocalDispatch(owner->view(), action,
655 UpdatableInset::DISPATCHED) ||
656 (result == UpdatableInset::DISPATCHED_NOUPDATE))
659 setMessage(N_("Text mode"));
661 case LFUN_UNKNOWN_ACTION:
662 case LFUN_BREAKPARAGRAPH:
664 owner->view()->text->CursorRight(owner->view());
665 owner->view()->setState();
669 if (!owner->view()->text->cursor.par()->isRightToLeftPar(owner->buffer()->params)) {
670 owner->view()->text->CursorRight(owner->view());
671 moveCursorUpdate(false);
676 if (owner->view()->text->cursor.par()->isRightToLeftPar(owner->buffer()->params)) {
677 owner->view()->text->CursorRight(owner->view());
678 moveCursorUpdate(false);
683 owner->view()->text->CursorDown(owner->view());
684 moveCursorUpdate(false);
695 // --- Misc -------------------------------------------
696 case LFUN_WORDFINDFORWARD :
697 case LFUN_WORDFINDBACKWARD : {
698 static string last_search;
699 string searched_string;
701 if (!argument.empty()) {
702 last_search = argument;
703 searched_string = argument;
705 searched_string = last_search;
708 LyXText * ltCur = owner->view()->text ;
710 if (!searched_string.empty() &&
711 ((action == LFUN_WORDFINDBACKWARD) ?
712 ltCur->SearchBackward(owner->view(), searched_string.c_str()) :
713 ltCur->SearchForward(owner->view(), searched_string.c_str()))) {
715 // ??? What is that ???
716 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
719 // clear the selection (if there is any)
720 owner->view()->toggleSelection();
721 owner->view()->text->ClearSelection();
723 // Move cursor so that successive C-s 's will not stand in place.
724 if( action == LFUN_WORDFINDFORWARD )
725 owner->view()->text->CursorRightOneWord(owner->view());
726 owner->view()->text->FinishUndo();
727 moveCursorUpdate(false);
730 // set the new selection
731 // SetSelectionOverLenChars(owner->view()->currentBuffer()->text, iLenSelected);
732 owner->view()->toggleSelection(false);
736 // REMOVED : if (owner->view()->getWorkArea()->focus)
737 owner->view()->showCursor();
743 if (owner->view()->available()) {
744 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
747 keyseq.print(buf, true);
748 owner->getMiniBuffer()->Set(buf, string(), string(), 1);
752 // --- Misc -------------------------------------------
753 case LFUN_EXEC_COMMAND:
754 owner->getMiniBuffer()->ExecCommand();
757 case LFUN_CANCEL: // RVDK_PATCH_5
760 if(owner->view()->available())
761 // cancel any selection
762 Dispatch(LFUN_MARK_OFF, 0);
763 setMessage(N_("Cancel"));
766 case LFUN_META_FAKE: // RVDK_PATCH_5
768 meta_fake_bit = Mod1Mask;
770 keyseq.print(buf, true);
771 string res = string("M-") + buf;
772 setMessage(buf); // RVDK_PATCH_5
776 case LFUN_READ_ONLY_TOGGLE:
777 if (owner->buffer()->lyxvc.inUse()) {
778 owner->buffer()->lyxvc.toggleReadOnly();
780 owner->buffer()->setReadonly(
781 !owner->buffer()->isReadonly());
785 case LFUN_CENTER: // this is center and redraw.
786 owner->view()->center();
790 if (owner->view()->available()) {
791 owner->view()->text->toggleAppendix(owner->view());
792 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
796 // --- Menus -----------------------------------------------
801 case LFUN_MENUNEWTMPLT:
809 case LFUN_CLOSEBUFFER:
814 if (!owner->buffer()->isUnnamed()) {
815 owner->getMiniBuffer()->Set(_("Saving document"),
816 MakeDisplayPath(owner->buffer()->fileName()),
818 MenuWrite(owner->buffer());
819 //owner->getMiniBuffer()-> {
820 // Set(_("Document saved as"),
821 // MakeDisplayPath(owner->buffer()->fileName()));
823 //owner->getMiniBuffer()->Set(_("Save failed!"));
826 MenuWriteAs(owner->buffer());
830 case LFUN_MENUWRITEAS:
831 MenuWriteAs(owner->buffer());
834 case LFUN_MENURELOAD:
839 PreviewDVI(owner->buffer());
843 PreviewPostscript(owner->buffer());
847 MenuRunLaTeX(owner->buffer());
851 MenuBuildProg(owner->buffer());
855 MenuRunChktex(owner->buffer());
859 CreatePostscript(owner->buffer(), false);
863 owner->getDialogs()->showPrint();
867 MenuFax(owner->buffer());
871 MenuExport(owner->buffer(), argument);
887 InsetCommandParams p;
889 if( action == LFUN_TOCVIEW )
890 p.setCmdName( "tableofcontents" );
891 else if( action == LFUN_LOAVIEW )
892 p.setCmdName( "listofalgorithms" );
893 else if( action == LFUN_LOFVIEW )
894 p.setCmdName( "listoffigures" );
896 p.setCmdName( "listoftables" );
898 owner->getDialogs()->createTOC( p.getAsString() );
902 case LFUN_TOC_INSERT:
903 case LFUN_LOA_INSERT:
904 case LFUN_LOF_INSERT:
905 case LFUN_LOT_INSERT:
907 InsetCommandParams p;
909 if( action == LFUN_TOC_INSERT )
910 p.setCmdName( "tableofcontents" );
911 else if( action == LFUN_LOA_INSERT )
912 p.setCmdName( "listofalgorithms" );
913 else if( action == LFUN_LOF_INSERT )
914 p.setCmdName( "listoffigures" );
916 p.setCmdName( "listoftables" );
918 Inset * inset = new InsetTOC( p );
919 if( !owner->view()->insertInset( inset, "Standard", true ) )
928 owner->getDialogs()->showTabularCreate();
932 case LFUN_TABULAR_FEATURE:
933 // this is not handled here as this funktion is only aktive
934 // if we have a locking_inset and that one is (or contains)
942 case LFUN_INSET_GRAPHICS:
944 Inset * new_inset = new InsetGraphics;
945 if (!owner->view()->insertInset(new_inset)) {
948 // this is need because you don't use a inset->Edit()
949 owner->view()->updateInset(new_inset, true);
955 AutoSave(owner->view());
959 owner->view()->menuUndo();
963 owner->view()->menuRedo();
966 case LFUN_MENUSEARCH:
968 // Ok this is one _very_ bad solution, but I think that some
969 // of this will be rewritten as part of GUI indep anyway.
971 static LyXFindReplace FR_;
972 FR_.StartSearch(owner->view());
977 owner->view()->paste();
978 owner->view()->setState();
981 case LFUN_PASTESELECTION:
984 if (argument == "paragraph") asPara = true;
985 owner->view()->pasteClipboard(asPara);
990 owner->view()->cut();
994 owner->view()->copy();
997 case LFUN_LAYOUT_COPY:
998 owner->view()->copyEnvironment();
1001 case LFUN_LAYOUT_PASTE:
1002 owner->view()->pasteEnvironment();
1003 owner->view()->setState();
1006 case LFUN_GOTOERROR:
1007 owner->view()->gotoError();
1010 case LFUN_REMOVEERRORS:
1011 if (owner->view()->removeAutoInsets()) {
1012 owner->view()->redraw();
1013 owner->view()->fitCursor();
1014 //owner->view()->updateScrollbar();
1019 owner->view()->gotoNote();
1023 case LFUN_OPENSTUFF:
1024 owner->view()->openStuff();
1028 case LFUN_HYPHENATION:
1029 owner->view()->hyphenationPoint();
1033 owner->view()->ldots();
1036 case LFUN_END_OF_SENTENCE:
1037 owner->view()->endOfSentenceDot();
1040 case LFUN_MENU_SEPARATOR:
1041 owner->view()->menuSeparator();
1045 owner->view()->hfill();
1049 changeDepth(owner->view(), 0);
1052 case LFUN_DEPTH_MIN:
1053 changeDepth(owner->view(), -1);
1056 case LFUN_DEPTH_PLUS:
1057 changeDepth(owner->view(), 1);
1061 Free(owner->view());
1062 owner->view()->setState();
1068 owner->view()->setState();
1073 Melt(owner->view());
1076 case LFUN_RECONFIGURE:
1077 Reconfigure(owner->view());
1081 if (owner->view()->available()
1082 && !owner->view()->text->selection
1083 && owner->view()->text->cursor.par()->footnoteflag
1084 != LyXParagraph::NO_FOOTNOTE)
1085 { // only melt footnotes with FOOTMELT, not margins etc
1086 if(owner->view()->text->cursor.par()->footnotekind == LyXParagraph::FOOTNOTE)
1087 Melt(owner->view());
1090 Foot(owner->view());
1091 owner->view()->setState();
1094 case LFUN_MARGINMELT:
1095 if (owner->view()->available()
1096 && !owner->view()->text->selection
1097 && owner->view()->text->cursor.par()->footnoteflag
1098 != LyXParagraph::NO_FOOTNOTE) {
1099 // only melt margins
1100 if(owner->view()->text->cursor.par()->footnotekind == LyXParagraph::MARGIN)
1101 Melt(owner->view());
1103 Margin(owner->view());
1104 owner->view()->setState();
1107 case LFUN_HELP_COPYRIGHT:
1108 owner->getDialogs()->showCopyright();
1111 case LFUN_HELP_CREDITS:
1112 owner->getDialogs()->showCredits();
1115 case LFUN_HELP_OPEN: {
1116 string arg = argument;
1118 setErrorMessage(N_("Missing argument"));
1121 ProhibitInput(owner->view());
1122 string fname = i18nLibFileSearch("doc", arg, "lyx");
1123 if (fname.empty()) {
1124 lyxerr << "LyX: unable to find documentation file `"
1125 << arg << "'. Bad installation?" << endl;
1126 AllowInput(owner->view());
1129 owner->getMiniBuffer()->Set(_("Opening help file"),
1130 MakeDisplayPath(fname),"...");
1131 owner->view()->buffer(bufferlist.loadLyXFile(fname,false));
1132 AllowInput(owner->view());
1136 case LFUN_HELP_VERSION:
1137 ProhibitInput(owner->view());
1138 fl_show_message((string(_("LyX Version ")) + LYX_VERSION
1139 + _(" of ") + LYX_RELEASE).c_str(),
1140 (_("Library directory: ")
1141 + MakeDisplayPath(system_lyxdir)).c_str(),
1142 (_("User directory: ")
1143 + MakeDisplayPath(user_lyxdir)).c_str());
1144 AllowInput(owner->view());
1147 // --- version control -------------------------------
1148 case LFUN_VC_REGISTER:
1150 if (!owner->buffer()->lyxvc.inUse())
1151 owner->buffer()->lyxvc.registrer();
1155 case LFUN_VC_CHECKIN:
1157 if (owner->buffer()->lyxvc.inUse()
1158 && !owner->buffer()->isReadonly())
1159 owner->buffer()->lyxvc.checkIn();
1163 case LFUN_VC_CHECKOUT:
1165 if (owner->buffer()->lyxvc.inUse()
1166 && owner->buffer()->isReadonly())
1167 owner->buffer()->lyxvc.checkOut();
1171 case LFUN_VC_REVERT:
1173 owner->buffer()->lyxvc.revert();
1179 owner->buffer()->lyxvc.undoLast();
1183 case LFUN_VC_HISTORY:
1185 owner->buffer()->lyxvc.showLog();
1189 // --- buffers ----------------------------------------
1191 case LFUN_SWITCHBUFFER:
1192 owner->view()->buffer(bufferlist.getBuffer(argument));
1196 case LFUN_FILE_INSERT:
1198 MenuInsertLyXFile(argument);
1202 case LFUN_FILE_INSERT_ASCII:
1204 bool asPara = (argument == "paragraph");
1205 InsertAsciiFile(owner->view(), string(), asPara);
1211 // servercmd: argument must be <file>:<template>
1212 Buffer * tmpbuf = NewLyxFile(argument);
1214 owner->view()->buffer(tmpbuf);
1218 case LFUN_FILE_OPEN:
1219 owner->view()->buffer(bufferlist.loadLyXFile(argument));
1222 case LFUN_LATEX_LOG:
1228 lyxerr.debug() << "LFUN_LAYOUTNO: (arg) " << argument << endl;
1229 int sel = strToInt(argument);
1230 lyxerr.debug() << "LFUN_LAYOUTNO: (sel) "<< sel << endl;
1232 // Should this give a setMessage instead?
1234 return string(); // illegal argument
1236 --sel; // sel 1..., but layout 0...
1238 // Pretend we got the name instead.
1239 Dispatch(int(LFUN_LAYOUT),
1240 textclasslist.NameOfLayout(owner->view()
1241 ->buffer()->params.textclass,
1248 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1249 << argument << endl;
1251 // Derive layout number from given argument (string)
1252 // and current buffer's textclass (number). */
1253 LyXTextClassList::ClassList::size_type tclass =
1254 owner->view()->buffer()->params.textclass;
1255 pair <bool, LyXTextClass::size_type> layout =
1256 textclasslist.NumberOfLayout(tclass, argument);
1258 // If the entry is obsolete, use the new one instead.
1260 string obs = textclasslist.Style(tclass,layout.second)
1264 textclasslist.NumberOfLayout(tclass, obs);
1267 // see if we found the layout number:
1268 if (!layout.first) {
1269 setErrorMessage(string(N_("Layout ")) + argument +
1274 if (current_layout != layout.second) {
1275 owner->view()->hideCursor();
1276 current_layout = layout.second;
1277 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1278 owner->view()->text->
1279 SetLayout(owner->view(), layout.second);
1280 owner->setLayout(layout.second);
1281 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1282 owner->view()->setState();
1287 case LFUN_LAYOUT_DOCUMENT:
1288 MenuLayoutDocument();
1291 case LFUN_LAYOUT_PARAGRAPH:
1292 MenuLayoutParagraph();
1295 case LFUN_LAYOUT_CHARACTER:
1296 MenuLayoutCharacter();
1299 case LFUN_LAYOUT_TABLE:
1302 if (argument == "true") flag = 1;
1303 MenuLayoutTable(flag);
1307 case LFUN_LAYOUT_TABULAR:
1308 if (owner->view()->the_locking_inset) {
1309 if (owner->view()->the_locking_inset->LyxCode()==Inset::TABULAR_CODE) {
1310 InsetTabular * inset = static_cast<InsetTabular *>
1311 (owner->view()->the_locking_inset);
1312 inset->OpenLayoutDialog(owner->view());
1313 } else if (owner->view()->the_locking_inset->
1314 GetFirstLockingInsetOfType(Inset::TABULAR_CODE)!=0) {
1315 InsetTabular * inset = static_cast<InsetTabular *>(
1316 owner->view()->the_locking_inset->GetFirstLockingInsetOfType(Inset::TABULAR_CODE));
1317 inset->OpenLayoutDialog(owner->view());
1322 case LFUN_LAYOUT_PAPER:
1326 case LFUN_LAYOUT_QUOTES:
1330 case LFUN_LAYOUT_PREAMBLE:
1331 MenuLayoutPreamble();
1334 case LFUN_LAYOUT_SAVE_DEFAULT:
1338 case LFUN_DROP_LAYOUTS_CHOICE:
1339 owner->getToolbar()->openLayoutList();
1343 Lang(owner->view(), argument);
1344 owner->view()->setState();
1349 Emph(owner->view());
1354 Bold(owner->view());
1359 Noun(owner->view());
1364 Code(owner->view());
1369 Sans(owner->view());
1374 Roman(owner->view());
1379 StyleReset(owner->view());
1383 case LFUN_UNDERLINE:
1384 Underline(owner->view());
1388 case LFUN_FONT_SIZE:
1389 FontSize(owner->view(), argument);
1393 case LFUN_FONT_STATE:
1394 setMessage(CurrentState(owner->view()));
1397 case LFUN_UPCASE_WORD:
1398 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1399 owner->view()->text->ChangeWordCase(owner->view(),
1400 LyXText::text_uppercase);
1401 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1404 case LFUN_LOWCASE_WORD:
1405 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1406 owner->view()->text->ChangeWordCase(owner->view(),
1407 LyXText::text_lowercase);
1408 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1411 case LFUN_CAPITALIZE_WORD:
1412 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1413 owner->view()->text->ChangeWordCase(owner->view(),
1414 LyXText::text_capitalization);
1415 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1418 case LFUN_INSERT_LABEL:
1419 MenuInsertLabel(argument.c_str());
1422 case LFUN_INSERT_REF:
1426 case LFUN_REFTOGGLE:
1429 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1432 owner->view()->updateInset(inset, true);
1434 setErrorMessage(N_("No cross-reference to toggle"));
1441 owner->view()->restorePosition();
1447 string label(argument);
1448 if (label.empty()) {
1450 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1452 label = inset->getContents();
1455 if (!label.empty()) {
1456 owner->view()->savePosition();
1457 if (!owner->view()->gotoLabel(label))
1458 WriteAlert(_("Error"),
1459 _("Couldn't find this label"),
1460 _("in current document."));
1465 case LFUN_MENU_OPEN_BY_NAME:
1467 owner->getMenubar()->openByName(argument);
1469 owner->getMenus()->openByName(argument);
1471 break; // RVDK_PATCH_5
1473 case LFUN_SPELLCHECK:
1474 if (lyxrc.isp_command != "none")
1475 ShowSpellChecker(owner->view());
1476 break; // RVDK_PATCH_5
1478 // --- Cursor Movements -----------------------------
1481 LyXText * tmptext = owner->view()->text;
1482 bool is_rtl = tmptext->cursor.par()->isRightToLeftPar(owner->buffer()->params);
1483 if(!tmptext->mark_set)
1484 owner->view()->beforeChange();
1485 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1487 tmptext->CursorLeft(owner->view(), false);
1488 if (tmptext->cursor.pos() < tmptext->cursor.par()->Last()
1489 && tmptext->cursor.par()->GetChar(tmptext->cursor.pos())
1490 == LyXParagraph::META_INSET
1491 && tmptext->cursor.par()->GetInset(tmptext->cursor.pos())
1492 && tmptext->cursor.par()->GetInset(tmptext->cursor.pos())->Editable() == Inset::HIGHLY_EDITABLE){
1493 Inset * tmpinset = tmptext->cursor.par()->GetInset(tmptext->cursor.pos());
1494 setMessage(tmpinset->EditMessage());
1495 tmpinset->Edit(owner->view(), 0, 0, 0);
1499 tmptext->CursorRight(owner->view(), false);
1500 owner->view()->text->FinishUndo();
1501 moveCursorUpdate(false);
1508 // This is soooo ugly. Isn`t it possible to make
1509 // it simpler? (Lgb)
1510 LyXText * txt = owner->view()->text;
1511 bool is_rtl = txt->cursor.par()->isRightToLeftPar(owner->buffer()->params);
1512 if(!txt->mark_set) owner->view()->beforeChange();
1513 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1515 txt->CursorLeft(owner->view(), false);
1516 if (txt->cursor.pos() < txt->cursor.par()->Last()
1517 && txt->cursor.par()->GetChar(txt->cursor.pos())
1518 == LyXParagraph::META_INSET
1519 && txt->cursor.par()->GetInset(txt->cursor.pos())
1520 && txt->cursor.par()->GetInset(txt->cursor.pos())->Editable() == Inset::HIGHLY_EDITABLE) {
1521 Inset * tmpinset = txt->cursor.par()->GetInset(txt->cursor.pos());
1522 setMessage(tmpinset->EditMessage());
1523 LyXFont font = txt->GetFont(owner->view()->buffer(),
1526 tmpinset->Edit(owner->view(),
1528 tmpinset->width(owner->view(),font),
1529 tmpinset->descent(owner->view(),font),
1534 txt->CursorRight(owner->view(), false);
1536 owner->view()->text->FinishUndo();
1537 moveCursorUpdate(false);
1543 if(!owner->view()->text->mark_set) owner->view()->beforeChange();
1544 owner->view()->update(BufferView::UPDATE);
1545 owner->view()->text->CursorUp(owner->view());
1546 owner->view()->text->FinishUndo();
1547 moveCursorUpdate(false);
1552 if(!owner->view()->text->mark_set)
1553 owner->view()->beforeChange();
1554 owner->view()->update(BufferView::UPDATE);
1555 owner->view()->text->CursorDown(owner->view());
1556 owner->view()->text->FinishUndo();
1557 moveCursorUpdate(false);
1561 case LFUN_UP_PARAGRAPH:
1562 if(!owner->view()->text->mark_set)
1563 owner->view()->beforeChange();
1564 owner->view()->update(BufferView::UPDATE);
1565 owner->view()->text->CursorUpParagraph(owner->view());
1566 owner->view()->text->FinishUndo();
1567 moveCursorUpdate(false);
1571 case LFUN_DOWN_PARAGRAPH:
1572 if(!owner->view()->text->mark_set)
1573 owner->view()->beforeChange();
1574 owner->view()->update(BufferView::UPDATE);
1575 owner->view()->text->CursorDownParagraph(owner->view());
1576 owner->view()->text->FinishUndo();
1577 moveCursorUpdate(false);
1582 if(!owner->view()->text->mark_set)
1583 owner->view()->beforeChange();
1584 owner->view()->update(BufferView::UPDATE);
1585 owner->view()->cursorPrevious();
1586 owner->view()->text->FinishUndo();
1587 moveCursorUpdate(false);
1592 if(!owner->view()->text->mark_set)
1593 owner->view()->beforeChange();
1594 owner->view()->update(BufferView::UPDATE);
1595 owner->view()->cursorNext();
1596 owner->view()->text->FinishUndo();
1597 moveCursorUpdate(false);
1602 if(!owner->view()->text->mark_set)
1603 owner->view()->beforeChange();
1604 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1605 owner->view()->text->CursorHome(owner->view());
1606 owner->view()->text->FinishUndo();
1607 moveCursorUpdate(false);
1612 if(!owner->view()->text->mark_set)
1613 owner->view()->beforeChange();
1614 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1615 owner->view()->text->CursorEnd(owner->view());
1616 owner->view()->text->FinishUndo();
1617 moveCursorUpdate(false);
1621 case LFUN_SHIFT_TAB:
1623 if(!owner->view()->text->mark_set)
1624 owner->view()->beforeChange();
1625 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1626 owner->view()->text->CursorTab(owner->view());
1627 owner->view()->text->FinishUndo();
1628 moveCursorUpdate(false);
1632 case LFUN_WORDRIGHT:
1633 if(!owner->view()->text->mark_set)
1634 owner->view()->beforeChange();
1635 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1636 if (owner->view()->text->cursor.par()->isRightToLeftPar(owner->buffer()->params))
1637 owner->view()->text->CursorLeftOneWord(owner->view());
1639 owner->view()->text->CursorRightOneWord(owner->view());
1640 owner->view()->text->FinishUndo();
1641 moveCursorUpdate(false);
1646 if(!owner->view()->text->mark_set)
1647 owner->view()->beforeChange();
1648 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1649 if (owner->view()->text->cursor.par()->isRightToLeftPar(owner->buffer()->params))
1650 owner->view()->text->CursorRightOneWord(owner->view());
1652 owner->view()->text->CursorLeftOneWord(owner->view());
1653 owner->view()->text->FinishUndo();
1654 moveCursorUpdate(false);
1658 case LFUN_BEGINNINGBUF:
1659 if(!owner->view()->text->mark_set)
1660 owner->view()->beforeChange();
1661 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1662 owner->view()->text->CursorTop(owner->view());
1663 owner->view()->text->FinishUndo();
1664 moveCursorUpdate(false);
1669 if(!owner->view()->text->mark_set)
1670 owner->view()->beforeChange();
1671 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1672 owner->view()->text->CursorBottom(owner->view());
1673 owner->view()->text->FinishUndo();
1674 moveCursorUpdate(false);
1679 /* cursor selection ---------------------------- */
1681 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1682 if (owner->view()->text->cursor.par()->isRightToLeftPar(owner->buffer()->params))
1683 owner->view()->text->CursorLeft(owner->view());
1685 owner->view()->text->CursorRight(owner->view());
1686 owner->view()->text->FinishUndo();
1687 moveCursorUpdate(true);
1692 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1693 if (owner->view()->text->cursor.par()->isRightToLeftPar(owner->buffer()->params))
1694 owner->view()->text->CursorRight(owner->view());
1696 owner->view()->text->CursorLeft(owner->view());
1697 owner->view()->text->FinishUndo();
1698 moveCursorUpdate(true);
1703 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1704 owner->view()->text->CursorUp(owner->view());
1705 owner->view()->text->FinishUndo();
1706 moveCursorUpdate(true);
1711 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1712 owner->view()->text->CursorDown(owner->view());
1713 owner->view()->text->FinishUndo();
1714 moveCursorUpdate(true);
1718 case LFUN_UP_PARAGRAPHSEL:
1719 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1720 owner->view()->text->CursorUpParagraph(owner->view());
1721 owner->view()->text->FinishUndo();
1722 moveCursorUpdate(true);
1726 case LFUN_DOWN_PARAGRAPHSEL:
1727 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1728 owner->view()->text->CursorDownParagraph(owner->view());
1729 owner->view()->text->FinishUndo();
1730 moveCursorUpdate(true);
1735 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1736 owner->view()->cursorPrevious();
1737 owner->view()->text->FinishUndo();
1738 moveCursorUpdate(true);
1743 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1744 owner->view()->cursorNext();
1745 owner->view()->text->FinishUndo();
1746 moveCursorUpdate(true);
1751 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1752 owner->view()->text->CursorHome(owner->view());
1753 owner->view()->text->FinishUndo();
1754 moveCursorUpdate(true);
1759 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1760 owner->view()->text->CursorEnd(owner->view());
1761 owner->view()->text->FinishUndo();
1762 moveCursorUpdate(true);
1766 case LFUN_WORDRIGHTSEL:
1767 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1768 if (owner->view()->text->cursor.par()->isRightToLeftPar(owner->buffer()->params))
1769 owner->view()->text->CursorLeftOneWord(owner->view());
1771 owner->view()->text->CursorRightOneWord(owner->view());
1772 owner->view()->text->FinishUndo();
1773 moveCursorUpdate(true);
1777 case LFUN_WORDLEFTSEL:
1778 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1779 if (owner->view()->text->cursor.par()->isRightToLeftPar(owner->buffer()->params))
1780 owner->view()->text->CursorRightOneWord(owner->view());
1782 owner->view()->text->CursorLeftOneWord(owner->view());
1783 owner->view()->text->FinishUndo();
1784 moveCursorUpdate(true);
1788 case LFUN_BEGINNINGBUFSEL:
1789 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1790 owner->view()->text->CursorTop(owner->view());
1791 owner->view()->text->FinishUndo();
1792 moveCursorUpdate(true);
1796 case LFUN_ENDBUFSEL:
1797 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1798 owner->view()->text->CursorBottom(owner->view());
1799 owner->view()->text->FinishUndo();
1800 moveCursorUpdate(true);
1804 // --- text changing commands ------------------------
1805 case LFUN_BREAKLINE:
1806 owner->view()->beforeChange();
1807 owner->view()->text->InsertChar(owner->view(), LyXParagraph::META_NEWLINE);
1808 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1809 moveCursorUpdate(false);
1812 case LFUN_PROTECTEDSPACE:
1814 LyXLayout const & style =
1815 textclasslist.Style(owner->view()->buffer()->params.textclass,
1816 owner->view()->text->cursor.par()->GetLayout());
1818 if (style.free_spacing) {
1819 owner->view()->text->InsertChar(owner->view(), ' ');
1820 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1822 owner->view()->protectedBlank();
1824 moveCursorUpdate(false);
1829 if(owner->view()->text->mark_set) {
1830 owner->view()->beforeChange();
1831 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1832 setMessage(N_("Mark removed"));
1834 owner->view()->beforeChange();
1835 owner->view()->text->mark_set = 1;
1836 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1837 setMessage(N_("Mark set"));
1839 owner->view()->text->sel_cursor =
1840 owner->view()->text->cursor;
1844 if (!owner->view()->text->selection) {
1845 owner->view()->text->Delete(owner->view());
1846 owner->view()->text->sel_cursor =
1847 owner->view()->text->cursor;
1848 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1849 // It is possible to make it a lot faster still
1850 // just comment out the lone below...
1851 owner->view()->showCursor();
1853 owner->view()->cut();
1855 moveCursorUpdate(false);
1857 owner->view()->setState();
1860 case LFUN_DELETE_SKIP:
1862 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1864 LyXCursor cursor = owner->view()->text->cursor;
1866 if (!owner->view()->text->selection) {
1867 if (cursor.pos() == cursor.par()->Last()) {
1868 owner->view()->text->CursorRight(owner->view());
1869 cursor = owner->view()->text->cursor;
1870 if (cursor.pos() == 0
1871 && !(cursor.par()->added_space_top
1872 == VSpace (VSpace::NONE))) {
1873 owner->view()->text->SetParagraph
1875 cursor.par()->line_top,
1876 cursor.par()->line_bottom,
1877 cursor.par()->pagebreak_top,
1878 cursor.par()->pagebreak_bottom,
1879 VSpace(VSpace::NONE),
1880 cursor.par()->added_space_bottom,
1881 cursor.par()->align,
1882 cursor.par()->labelwidthstring, 0);
1883 owner->view()->text->CursorLeft(owner->view());
1884 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1886 owner->view()->text->CursorLeft(owner->view());
1887 owner->view()->text->Delete(owner->view());
1888 owner->view()->text->sel_cursor =
1889 owner->view()->text->cursor;
1890 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1893 owner->view()->text->Delete(owner->view());
1894 owner->view()->text->sel_cursor =
1895 owner->view()->text->cursor;
1896 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1899 owner->view()->cut();
1904 /* -------> Delete word forward. */
1905 case LFUN_DELETE_WORD_FORWARD:
1906 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1907 owner->view()->text->DeleteWordForward(owner->view());
1908 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1909 moveCursorUpdate(false);
1913 /* -------> Delete word backward. */
1914 case LFUN_DELETE_WORD_BACKWARD:
1915 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1916 owner->view()->text->DeleteWordBackward(owner->view());
1917 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1918 moveCursorUpdate(false);
1922 /* -------> Kill to end of line. */
1923 case LFUN_DELETE_LINE_FORWARD:
1924 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1925 owner->view()->text->DeleteLineForward(owner->view());
1926 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1927 moveCursorUpdate(false);
1930 /* -------> Set mark off. */
1932 owner->view()->beforeChange();
1933 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1934 owner->view()->text->sel_cursor =
1935 owner->view()->text->cursor;
1936 setMessage(N_("Mark off"));
1939 /* -------> Set mark on. */
1941 owner->view()->beforeChange();
1942 owner->view()->text->mark_set = 1;
1943 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1944 owner->view()->text->sel_cursor =
1945 owner->view()->text->cursor;
1946 setMessage(N_("Mark on"));
1949 case LFUN_BACKSPACE:
1951 if (!owner->view()->text->selection) {
1952 if (owner->getIntl()->getTrans()->backspace()) {
1953 owner->view()->text->Backspace(owner->view());
1954 owner->view()->text->sel_cursor =
1955 owner->view()->text->cursor;
1956 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1957 // It is possible to make it a lot faster still
1958 // just comment out the lone below...
1959 owner->view()->showCursor();
1962 owner->view()->cut();
1965 owner->view()->setState();
1969 case LFUN_BACKSPACE_SKIP:
1971 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1973 LyXCursor cursor = owner->view()->text->cursor;
1975 if (!owner->view()->text->selection) {
1976 if (cursor.pos() == 0
1977 && !(cursor.par()->added_space_top
1978 == VSpace (VSpace::NONE))) {
1979 owner->view()->text->SetParagraph
1981 cursor.par()->line_top,
1982 cursor.par()->line_bottom,
1983 cursor.par()->pagebreak_top,
1984 cursor.par()->pagebreak_bottom,
1985 VSpace(VSpace::NONE), cursor.par()->added_space_bottom,
1986 cursor.par()->align,
1987 cursor.par()->labelwidthstring, 0);
1988 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1990 owner->view()->text->Backspace(owner->view());
1991 owner->view()->text->sel_cursor
1993 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1996 owner->view()->cut();
2000 case LFUN_BREAKPARAGRAPH:
2002 owner->view()->beforeChange();
2003 owner->view()->text->BreakParagraph(owner->view(), 0);
2004 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2005 owner->view()->text->sel_cursor =
2006 owner->view()->text->cursor;
2007 owner->view()->setState();
2012 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2014 owner->view()->beforeChange();
2015 owner->view()->text->BreakParagraph(owner->view(), 1);
2016 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2017 owner->view()->text->sel_cursor =
2018 owner->view()->text->cursor;
2019 owner->view()->setState();
2024 case LFUN_BREAKPARAGRAPH_SKIP:
2026 // When at the beginning of a paragraph, remove
2027 // indentation and add a "defskip" at the top.
2028 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2030 LyXCursor cursor = owner->view()->text->cursor;
2032 owner->view()->beforeChange();
2033 if (cursor.pos() == 0) {
2034 if (cursor.par()->added_space_top == VSpace(VSpace::NONE)) {
2035 owner->view()->text->SetParagraph
2037 cursor.par()->line_top,
2038 cursor.par()->line_bottom,
2039 cursor.par()->pagebreak_top,
2040 cursor.par()->pagebreak_bottom,
2041 VSpace(VSpace::DEFSKIP), cursor.par()->added_space_bottom,
2042 cursor.par()->align,
2043 cursor.par()->labelwidthstring, 1);
2044 //owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2048 owner->view()->text->BreakParagraph(owner->view(), 0);
2049 //owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2052 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2053 owner->view()->text->sel_cursor = cursor;
2054 owner->view()->setState();
2059 case LFUN_PARAGRAPH_SPACING:
2061 LyXParagraph * par = owner->view()->text->cursor.par();
2062 Spacing::Space cur_spacing = par->spacing.getSpace();
2063 float cur_value = 1.0;
2064 if (cur_spacing == Spacing::Other) {
2065 cur_value = par->spacing.getValue();
2069 istringstream istr(argument);
2071 istrstream istr(argument.c_str());
2075 Spacing::Space new_spacing = cur_spacing;
2076 float new_value = cur_value;
2078 lyxerr << "Missing argument to `paragraph-spacing'"
2080 } else if (tmp == "single") {
2081 new_spacing = Spacing::Single;
2082 } else if (tmp == "onehalf") {
2083 new_spacing = Spacing::Onehalf;
2084 } else if (tmp == "double") {
2085 new_spacing = Spacing::Double;
2086 } else if (tmp == "other") {
2087 new_spacing = Spacing::Other;
2090 lyxerr << "new_value = " << tmpval << endl;
2093 } else if (tmp == "default") {
2094 new_spacing = Spacing::Default;
2096 lyxerr << _("Unknown spacing argument: ")
2097 << argument << endl;
2099 if (cur_spacing != new_spacing || cur_value != new_value) {
2100 par->spacing.set(new_spacing, new_value);
2101 owner->view()->text->RedoParagraph(owner->view());
2102 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2108 owner->view()->beforeChange();
2109 owner->view()->text->InsertChar(owner->view(), '\"'); // This " matches the single quote in the code
2110 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2111 moveCursorUpdate(false);
2117 InsetCommandParams p;
2118 if (action == LFUN_HTMLURL)
2119 p.setCmdName("htmlurl");
2121 p.setCmdName("url");
2122 owner->getDialogs()->createUrl( p.getAsString() );
2126 case LFUN_INSERT_URL:
2128 InsetCommandParams p;
2129 p.setFromString( argument );
2131 InsetUrl * inset = new InsetUrl( p );
2132 if (!owner->view()->insertInset(inset))
2135 owner->view()->updateInset( inset, true );
2139 case LFUN_INSET_TEXT:
2141 InsetText * new_inset = new InsetText;
2142 if (owner->view()->insertInset(new_inset))
2143 new_inset->Edit(owner->view(), 0, 0, 0);
2149 case LFUN_INSET_ERT:
2151 InsetERT * new_inset = new InsetERT;
2152 if (owner->view()->insertInset(new_inset))
2153 new_inset->Edit(owner->view(), 0, 0, 0);
2159 case LFUN_INSET_EXTERNAL:
2161 InsetExternal * new_inset = new InsetExternal;
2162 if (owner->view()->insertInset(new_inset))
2163 new_inset->Edit(owner->view(), 0, 0, 0);
2169 case LFUN_INSET_FOOTNOTE:
2171 InsetFoot * new_inset = new InsetFoot;
2172 if (owner->view()->insertInset(new_inset))
2173 new_inset->Edit(owner->view(), 0, 0, 0);
2179 case LFUN_INSET_MARGINAL:
2181 InsetMarginal * new_inset = new InsetMarginal;
2182 if (owner->view()->insertInset(new_inset))
2183 new_inset->Edit(owner->view(), 0, 0, 0);
2189 case LFUN_INSET_MINIPAGE:
2191 InsetMinipage * new_inset = new InsetMinipage;
2192 if (owner->view()->insertInset(new_inset))
2193 new_inset->Edit(owner->view(), 0, 0, 0);
2199 case LFUN_INSET_FLOAT:
2201 // check if the float type exist
2202 if (floatList.typeExist(argument)) {
2203 InsetFloat * new_inset = new InsetFloat(argument);
2204 if (owner->view()->insertInset(new_inset))
2205 new_inset->Edit(owner->view(), 0, 0, 0);
2209 lyxerr << "Non-existant float type: "
2210 << argument << endl;
2216 case LFUN_INSET_LIST:
2218 InsetList * new_inset = new InsetList;
2219 if (owner->view()->insertInset(new_inset))
2220 new_inset->Edit(owner->view(), 0, 0, 0);
2226 case LFUN_INSET_THEOREM:
2228 InsetTheorem * new_inset = new InsetTheorem;
2229 if (owner->view()->insertInset(new_inset))
2230 new_inset->Edit(owner->view(), 0, 0, 0);
2236 case LFUN_INSET_CAPTION:
2238 // Do we have a locking inset...
2239 if (owner->view()->the_locking_inset) {
2240 lyxerr << "Locking inset code: "
2241 << static_cast<int>(owner->view()->the_locking_inset->LyxCode());
2242 InsetCaption * new_inset = new InsetCaption;
2243 new_inset->setOwner(owner->view()->the_locking_inset);
2244 new_inset->SetAutoBreakRows(true);
2245 new_inset->SetDrawFrame(0, InsetText::LOCKED);
2246 new_inset->SetFrameColor(0, LColor::footnoteframe);
2247 if (owner->view()->insertInset(new_inset))
2248 new_inset->Edit(owner->view(), 0, 0, 0);
2255 case LFUN_INSET_TABULAR:
2258 if (!argument.empty())
2259 sscanf(argument.c_str(),"%d%d", &r, &c);
2260 InsetTabular * new_inset =
2261 new InsetTabular(owner->buffer(), r, c);
2262 if (owner->view()->insertInset(new_inset))
2263 new_inset->Edit(owner->view(), 0, 0, 0);
2269 // --- lyxserver commands ----------------------------
2271 case LFUN_CHARATCURSOR:
2273 LyXParagraph::size_type pos =
2274 owner->view()->text->cursor.pos();
2275 if(pos < owner->view()->text->cursor.par()->size())
2276 //dispatch_buffer = owner->view()->text->
2277 // cursor.par()->text[pos];
2279 owner->view()->text->
2280 cursor.par()->GetChar(pos);
2282 dispatch_buffer = "EOF";
2288 tostr(owner->view()->text->cursor.x()) + ' '
2289 + tostr(owner->view()->text->cursor.y());
2296 sscanf(argument.c_str(), " %d %ld", &x, &y);
2297 owner->view()->text->SetCursorFromCoordinates(owner->view(), x, y);
2301 case LFUN_GETLAYOUT:
2303 tostr(owner->view()->text->cursor.par()->layout);
2308 LyXFont & font = owner->view()->text->current_font;
2309 if(font.shape() == LyXFont::ITALIC_SHAPE)
2310 dispatch_buffer = 'E';
2311 else if(font.shape() == LyXFont::SMALLCAPS_SHAPE)
2312 dispatch_buffer = 'N';
2314 dispatch_buffer = '0';
2321 LyXFont & font = owner->view()->text->current_font;
2322 if(font.latex() == LyXFont::ON)
2323 dispatch_buffer = 'L';
2325 dispatch_buffer = '0';
2330 setMessage(owner->buffer()->fileName());
2331 lyxerr.debug() << "FNAME["
2332 << owner->buffer()->fileName()
2340 dispatch_buffer = buf;
2341 lyxserver->notifyClient(dispatch_buffer);
2345 case LFUN_GOTOFILEROW:
2347 char file_name[100];
2349 sscanf(argument.c_str(), " %s %d", file_name, &row);
2351 // Must replace extension of the file to be .lyx and get full path
2352 string s = ChangeExtension(string(file_name), ".lyx");
2354 // Either change buffer or load the file
2355 if (bufferlist.exists(s))
2356 owner->view()->buffer(bufferlist.getBuffer(s));
2358 owner->view()->buffer(bufferlist.loadLyXFile(s));
2361 owner->view()->setCursorFromRow(row);
2364 owner->view()->center();
2371 int qa = lyxaction.LookupFunc(argument.c_str());
2372 setMessage(lyxaction.helpText(static_cast<kb_action>(qa)));
2376 // --- accented characters ---------------------------
2379 case LFUN_CIRCUMFLEX:
2389 case LFUN_SPECIAL_CARON:
2392 case LFUN_HUNG_UMLAUT:
2398 if (keyseq.length == -1 && keyseq.getiso() != 0)
2399 c = keyseq.getiso();
2401 owner->getIntl()->getTrans()->
2402 deadkey(c, get_accent(action).accent,
2403 owner->view()->text);
2405 // Need to reset, in case the minibuffer calls these
2410 // copied verbatim from do_accent_char
2411 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2413 owner->view()->text->sel_cursor =
2414 owner->view()->text->cursor;
2418 // --- toolbar ----------------------------------
2419 case LFUN_PUSH_TOOLBAR:
2421 int nth = strToInt(argument);
2423 setErrorMessage(N_("Push-toolbar needs argument > 0"));
2425 owner->getToolbar()->push(nth);
2430 case LFUN_ADD_TO_TOOLBAR:
2432 if (lyxerr.debugging(Debug::GUI)) {
2433 lyxerr << "LFUN_ADD_TO_TOOLBAR:"
2434 "argument = `" << argument << '\'' << endl;
2436 string tmp(argument);
2437 //lyxerr <<string("Argument: ") + argument);
2438 //lyxerr <<string("Tmp : ") + tmp);
2440 setErrorMessage(N_("Usage: toolbar-add-to <LyX command>"));
2442 owner->getToolbar()->add(argument, false);
2443 owner->getToolbar()->set();
2448 // --- insert characters ----------------------------------------
2450 // --- Mathed stuff. If we are here, there is no locked inset yet.
2455 if (!greek_kb_flag) {
2457 setMessage(N_("Math greek mode on"));
2464 case LFUN_GREEK_TOGGLE:
2466 greek_kb_flag = greek_kb_flag ? 0 : 2;
2467 if (greek_kb_flag) {
2468 setMessage(N_("Math greek keyboard on"));
2470 setMessage(N_("Math greek keyboard off"));
2475 case LFUN_MATH_DELIM:
2476 case LFUN_INSERT_MATRIX:
2478 if (owner->view()->available()) {
2480 open_new_inset(new InsetFormula(false));
2483 ->LocalDispatch(owner->view(),
2490 case LFUN_INSERT_MATH:
2492 math_insert_symbol(argument.c_str());
2496 case LFUN_MATH_DISPLAY:
2498 if (owner->view()->available())
2499 owner->view()->open_new_inset(new InsetFormula(true));
2503 case LFUN_MATH_MACRO:
2505 if (owner->view()->available()) {
2508 setErrorMessage(N_("Missing argument"));
2510 string s1 = token(s, ' ', 1);
2511 int na = s1.empty() ? 0: atoi(s1.c_str());
2513 open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2519 case LFUN_MATH_MODE: // Open or create a math inset
2521 if (owner->view()->available())
2522 owner->view()->open_new_inset(new InsetFormula);
2523 setMessage(N_("Math editor mode"));
2527 case LFUN_MATH_NUMBER:
2528 case LFUN_MATH_LIMITS:
2530 setErrorMessage(N_("This is only allowed in math mode!"));
2535 case LFUN_MATH_PANEL:
2537 show_symbols_form(this);
2541 case LFUN_CREATE_CITATION:
2543 // Should do this "at source"
2544 InsetCommandParams p;
2545 p.setCmdName( "cite" );
2547 if (contains(argument, "|")) {
2548 p.setContents( token(argument, '|', 0) );
2549 p.setOptions( token(argument, '|', 1) );
2551 p.setContents( argument );
2554 owner->getDialogs()->createCitation( p.getAsString() );
2558 case LFUN_INSERT_CITATION:
2560 InsetCommandParams p;
2561 p.setFromString( argument );
2563 InsetCitation * inset = new InsetCitation( p );
2564 if (!owner->view()->insertInset(inset))
2567 owner->view()->updateInset( inset, true );
2571 case LFUN_INSERT_BIBTEX:
2573 // ale970405+lasgoutt970425
2574 // The argument can be up to two tokens separated
2575 // by a space. The first one is the bibstyle.
2576 string lsarg(argument);
2577 string bibstyle = token(lsarg, ' ', 1);
2578 if (bibstyle.empty())
2580 InsetBibtex * new_inset
2581 = new InsetBibtex(token(lsarg, ' ', 0),
2585 if (owner->view()->insertInset(new_inset)) {
2587 new_inset->Edit(owner->view(), 0, 0, 0);
2593 // BibTeX data bases
2594 case LFUN_BIBDB_ADD:
2596 InsetBibtex * inset =
2597 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2599 inset->addDatabase(argument);
2604 case LFUN_BIBDB_DEL:
2606 InsetBibtex * inset =
2607 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2609 inset->delDatabase(argument);
2614 case LFUN_BIBTEX_STYLE:
2616 InsetBibtex * inset =
2617 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2619 inset->setOptions(argument);
2624 case LFUN_INDEX_INSERT:
2625 case LFUN_INDEX_INSERT_LAST:
2627 // Can't do that at the beginning of a paragraph.
2628 if (owner->view()->text->cursor.pos() - 1 < 0)
2631 InsetIndex * new_inset = new InsetIndex();
2632 if (!argument.empty()) {
2633 string lsarg(argument);
2634 new_inset->setContents(lsarg);
2635 if (!owner->view()->insertInset(new_inset))
2639 //get the current word for an argument
2640 LyXParagraph::size_type lastpos =
2641 owner->view()->text->cursor.pos() - 1;
2642 // Get the current word. note that this must be done
2643 // before inserting the inset, or the inset will
2645 string curstring(owner->view()
2646 ->text->cursor.par()->GetWord(lastpos));
2648 //make the new inset and write the current word into it
2649 InsetIndex * new_inset = new InsetIndex();
2651 new_inset->setContents(curstring);
2653 //don't edit it if the call was to INSERT_LAST
2654 if(action != LFUN_INDEX_INSERT_LAST) {
2655 new_inset->Edit(owner->view(), 0, 0, 0);
2657 //it looks blank on the screen unless
2658 //we do something. put it here.
2660 // move the cursor to the returned value of lastpos
2661 // but only for the auto-insert
2662 owner->view()->text->cursor.pos(lastpos);
2665 //put the new inset into the buffer.
2666 // there should be some way of knowing the user
2667 //cancelled & avoiding this, but i don't know how
2668 if (!owner->view()->insertInset(new_inset))
2674 case LFUN_INDEX_PRINT:
2676 Inset * new_inset = new InsetPrintIndex(owner->buffer());
2677 if (!owner->view()->insertInset(new_inset, "Standard", true))
2682 case LFUN_PARENTINSERT:
2684 lyxerr << "arg " << argument << endl;
2685 Inset * new_inset = new InsetParent(argument, owner->buffer());
2686 if (!owner->view()->insertInset(new_inset, "Standard", true))
2691 case LFUN_CHILDINSERT:
2693 Inset * new_inset = new InsetInclude(argument,
2695 if (owner->view()->insertInset(new_inset, "Standard", true))
2696 new_inset->Edit(owner->view(), 0, 0, 0);
2702 case LFUN_CHILDOPEN:
2705 MakeAbsPath(argument,
2706 OnlyPath(owner->buffer()->fileName()));
2707 setMessage(N_("Opening child document ") +
2708 MakeDisplayPath(filename) + "...");
2709 owner->view()->savePosition();
2710 if (bufferlist.exists(filename))
2711 owner->view()->buffer(bufferlist.getBuffer(filename));
2713 owner->view()->buffer(bufferlist.loadLyXFile(filename));
2717 case LFUN_INSERT_NOTE:
2718 owner->view()->insertNote();
2721 case LFUN_INSERTFOOTNOTE:
2723 LyXParagraph::footnote_kind kind;
2724 if (argument == "footnote")
2725 { kind = LyXParagraph::FOOTNOTE; }
2726 else if (argument == "margin")
2727 { kind = LyXParagraph::MARGIN; }
2728 else if (argument == "figure")
2729 { kind = LyXParagraph::FIG; }
2730 else if (argument == "table")
2731 { kind = LyXParagraph::TAB; }
2732 else if (argument == "wide-fig")
2733 { kind = LyXParagraph::WIDE_FIG; }
2734 else if (argument == "wide-tab")
2735 { kind = LyXParagraph::WIDE_TAB; }
2736 else if (argument == "algorithm")
2737 { kind = LyXParagraph::ALGORITHM; }
2739 setErrorMessage(N_("Unknown kind of footnote"));
2742 owner->view()->text->InsertFootnoteEnvironment(owner->view(), kind);
2743 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2744 owner->view()->setState();
2748 case LFUN_BUFFERBULLETSSELECT:
2752 case LFUN_TOGGLECURSORFOLLOW:
2753 cursor_follows_scrollbar = !cursor_follows_scrollbar;
2756 case LFUN_KMAP_OFF: // keymap off
2757 owner->getIntl()->KeyMapOn(false);
2760 case LFUN_KMAP_PRIM: // primary keymap
2761 owner->getIntl()->KeyMapPrim();
2764 case LFUN_KMAP_SEC: // secondary keymap
2765 owner->getIntl()->KeyMapSec();
2768 case LFUN_KMAP_TOGGLE: // toggle keymap
2769 owner->getIntl()->ToggleKeyMap();
2772 case LFUN_SELFINSERT:
2774 for (string::size_type i = 0; i < argument.length(); ++i) {
2775 owner->view()->text->InsertChar(owner->view(), argument[i]);
2776 // This needs to be in the loop, or else we
2777 // won't break lines correctly. (Asger)
2778 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2780 owner->view()->text->sel_cursor =
2781 owner->view()->text->cursor;
2782 moveCursorUpdate(false);
2788 // argument contains ';'-terminated commands
2789 while (argument.find(';') != string::npos) {
2791 argument = split(argument, first, ';');
2797 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
2801 time_t now_time_t = time(NULL);
2802 now_tm = localtime(&now_time_t);
2803 setlocale(LC_TIME, "");
2805 if (!argument.empty())
2808 arg = lyxrc.date_insert_format;
2810 int datetmp_len = strftime(datetmp, 32, arg.c_str(), now_tm);
2811 for (int i = 0; i < datetmp_len; i++) {
2812 owner->view()->text->InsertChar(owner->view(), datetmp[i]);
2813 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2816 owner->view()->text->sel_cursor = owner->view()->text->cursor;
2817 moveCursorUpdate(false);
2821 case LFUN_DIALOG_PREFERENCES:
2822 owner->getDialogs()->showPreferences();
2825 case LFUN_SAVEPREFERENCES:
2827 Path p(user_lyxdir);
2828 lyxrc.write("preferences");
2832 case LFUN_SET_COLOR:
2834 string lyx_name, x11_name;
2835 x11_name = split(argument, lyx_name, ' ');
2836 if (lyx_name.empty() || x11_name.empty()) {
2838 setErrorMessage(N_("Syntax: set-color <lyx_name>"
2843 if (!lcolor.setColor(lyx_name, x11_name)) {
2844 static string err1 (N_("Set-color \""));
2845 static string err2 (N_("\" failed - color is undefined "
2846 "or may not be redefined"));
2848 setErrorMessage(err1 + lyx_name + err2);
2851 lyxColorHandler->updateColor(lcolor.getFromLyXName(lyx_name));
2852 owner->view()->redraw();
2856 case LFUN_UNKNOWN_ACTION:
2858 if(!owner->buffer()) {
2860 setErrorMessage(N_("No document open"));
2864 if (owner->buffer()->isReadonly()) {
2866 setErrorMessage(N_("Document is read only"));
2870 if (!argument.empty()) {
2872 /* Automatically delete the currently selected
2873 * text and replace it with what is being
2874 * typed in now. Depends on lyxrc settings
2875 * "auto_region_delete", which defaults to
2878 if ( lyxrc.auto_region_delete ) {
2879 if (owner->view()->text->selection){
2880 owner->view()->text->CutSelection(owner->view(), false);
2881 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2885 owner->view()->beforeChange();
2887 for (string::size_type i = 0;
2888 i < argument.length(); ++i) {
2889 if (greek_kb_flag) {
2890 if (!math_insert_greek(argument[i]))
2891 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2893 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2896 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2898 owner->view()->text->sel_cursor =
2899 owner->view()->text->cursor;
2900 moveCursorUpdate(false);
2903 // why is an "Unknown action" with empty
2904 // argument even dispatched in the first
2905 // place? I`ll probably change that. (Lgb)
2907 setErrorMessage(N_("Unknown action"));
2911 lyxerr << "A truly unknown func!" << endl;
2917 string res = getMessage();
2920 if (!commandshortcut.empty()) {
2921 string newbuf = owner->getMiniBuffer()->GetText();
2922 if (newbuf != commandshortcut) {
2923 owner->getMiniBuffer()->Set(newbuf
2929 owner->getMiniBuffer()->Set(string(_(res.c_str()))
2930 + " " + commandshortcut);
2937 void LyXFunc::setupLocalKeymap()
2939 keyseq.stdmap = keyseq.curmap = toplevel_keymap;
2940 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap;
2944 void LyXFunc::MenuNew(bool fromTemplate)
2946 string fname, initpath = lyxrc.document_path;
2949 if (owner->view()->available()) {
2950 string trypath = owner->buffer()->filepath;
2951 // If directory is writeable, use this as default.
2952 if (IsDirWriteable(trypath) == 1)
2956 #ifdef NEW_WITH_FILENAME
2957 ProhibitInput(owner->view());
2958 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
2959 fileDlg.SetButton(1, _("Templates"), lyxrc.template_path);
2960 fname = fileDlg.Select(_("Enter Filename for new document"),
2961 initpath, "*.lyx", _("newfile"));
2962 AllowInput(owner->view());
2964 if (fname.empty()) {
2965 owner->getMiniBuffer()->Set(_("Canceled."));
2966 lyxerr.debug() << "New Document Cancelled." << endl;
2970 // get absolute path of file and make sure the filename ends
2972 string s = MakeAbsPath(fname);
2973 if (!IsLyXFilename(s))
2976 // Check if the document already is open
2977 if (bufferlist.exists(s)) {
2978 switch(AskConfirmation(_("Document is already open:"),
2979 MakeDisplayPath(s, 50),
2980 _("Do you want to close that document now?\n"
2981 "('No' will just switch to the open version)")))
2983 case 1: // Yes: close the document
2984 if (!bufferlist.close(bufferlist.getBuffer(s)))
2985 // If close is canceled, we cancel here too.
2988 case 2: // No: switch to the open document
2989 owner->view()->buffer(bufferlist.getBuffer(s));
2991 case 3: // Cancel: Do nothing
2992 owner->getMiniBuffer()->Set(_("Canceled."));
2997 // Check whether the file already exists
2998 if (IsLyXFilename(s)) {
3000 if (fi.readable() &&
3001 AskQuestion(_("File already exists:"),
3002 MakeDisplayPath(s, 50),
3003 _("Do you want to open the document?"))) {
3005 owner->getMiniBuffer()->Set(_("Opening document"),
3006 MakeDisplayPath(s), "...");
3008 owner->view()->buffer(
3009 bufferlist.loadLyXFile(s));
3010 owner->getMiniBuffer()->Set(_("Document"),
3017 static int newfile_number = 0;
3018 string s = "/lyx/dummy/dirname/newfile ["+tostr(++newfile_number)+"]";
3020 while (bufferlist.exists(s) || fi.readable()) {
3022 s = "/lyx/dummy/dirname/newfile ["+tostr(newfile_number)+"]";
3027 // The template stuff
3030 ProhibitInput(owner->view());
3031 fname = fileDlg.Select(_("Choose template"),
3032 lyxrc.template_path,
3035 AllowInput(owner->view());
3038 // find a free buffer
3039 lyxerr.debug() << "Find a free buffer." << endl;
3040 owner->view()->buffer(bufferlist.newFile(s, templname));
3044 void LyXFunc::MenuOpen()
3046 string initpath = lyxrc.document_path;
3049 if (owner->view()->available()) {
3050 string trypath = owner->buffer()->filepath;
3051 // If directory is writeable, use this as default.
3052 if (IsDirWriteable(trypath) == 1)
3057 ProhibitInput(owner->view());
3058 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
3059 fileDlg.SetButton(1, _("Examples"),
3060 AddPath(system_lyxdir, "examples"));
3061 string filename = fileDlg.Select(_("Select Document to Open"),
3063 AllowInput(owner->view());
3065 // check selected filename
3066 if (filename.empty()) {
3067 owner->getMiniBuffer()->Set(_("Canceled."));
3071 // get absolute path of file and make sure the filename ends
3073 filename = MakeAbsPath(filename);
3074 if (!IsLyXFilename(filename))
3078 owner->getMiniBuffer()->Set(_("Opening document"),
3079 MakeDisplayPath(filename), "...");
3080 Buffer * openbuf = bufferlist.loadLyXFile(filename);
3082 owner->view()->buffer(openbuf);
3083 owner->getMiniBuffer()->Set(_("Document"),
3084 MakeDisplayPath(filename),
3087 owner->getMiniBuffer()->Set(_("Could not open document"),
3088 MakeDisplayPath(filename));
3092 // returns filename if file must be imported,
3093 // empty string if either file not found or already loaded
3094 // checks for running without gui are missing.
3096 void LyXFunc::doImportHelper(
3097 string const & file, // filename (possibly empty)
3098 string const & text, // info when asking for filename
3099 string const & pattern, // filetype
3100 bool func(BufferView *, string const &) // the real import function
3103 string filename = file;
3105 if (filename.empty()) { // need user interaction
3106 string initpath = lyxrc.document_path;
3109 if (owner->view()->available()) {
3110 string trypath = owner->buffer()->filepath;
3111 // If directory is writeable, use this as default.
3112 if (IsDirWriteable(trypath) == 1)
3117 ProhibitInput(owner->view());
3118 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
3119 fileDlg.SetButton(1, _("Examples"),
3120 AddPath(system_lyxdir, "examples"));
3121 filename = fileDlg.Select(text, initpath, pattern);
3122 AllowInput(owner->view());
3124 // check selected filename
3125 if (filename.empty())
3126 owner->getMiniBuffer()->Set(_("Canceled."));
3129 // still no filename? abort
3130 if (filename.empty())
3133 // get absolute path of file
3134 filename = MakeAbsPath(filename);
3136 string lyxfile = ChangeExtension(filename, ".lyx");
3138 // Check if the document already is open
3139 if (bufferlist.exists(lyxfile)) {
3140 switch(AskConfirmation(_("Document is already open:"),
3141 MakeDisplayPath(lyxfile, 50),
3142 _("Do you want to close that document now?\n"
3143 "('No' will just switch to the open version)")))
3145 case 1: // Yes: close the document
3146 if (!bufferlist.close(bufferlist.getBuffer(lyxfile)))
3147 // If close is canceled, we cancel here too.
3150 case 2: // No: switch to the open document
3151 owner->view()->buffer(bufferlist.getBuffer(lyxfile));
3153 case 3: // Cancel: Do nothing
3154 owner->getMiniBuffer()->Set(_("Canceled."));
3159 // Check if a LyX document by the same root exists in filesystem
3160 FileInfo f(lyxfile, true);
3161 if (f.exist() && !AskQuestion(_("A document by the name"),
3162 MakeDisplayPath(lyxfile),
3163 _("already exists. Overwrite?"))) {
3164 owner->getMiniBuffer()->Set(_("Canceled."));
3167 // filename should be valid now
3169 // notify user of import ahead
3170 string displaypath = MakeDisplayPath(filename);
3171 owner->getMiniBuffer()->Set(_("Importing"), displaypath, "...");
3173 // call real importer
3174 bool result = func(owner->view(), filename);
3178 owner->getMiniBuffer()->Set(displaypath, _("imported."));
3180 owner->getMiniBuffer()->Set(displaypath, _(": import failed."));
3184 bool doImportASCIIasLines(BufferView * view, string const & filename)
3186 view->buffer(bufferlist.newFile(filename, string()));
3187 InsertAsciiFile(view, filename, false);
3192 bool doImportASCIIasParagraphs(BufferView * view, string const & filename)
3194 view->buffer(bufferlist.newFile(filename, string()));
3195 InsertAsciiFile(view, filename, true);
3200 bool doImportLaTeX(BufferView * view, string const & filename)
3202 ImportLaTeX myImport(filename);
3203 Buffer * openbuf = myImport.run();
3205 view->buffer(openbuf);
3213 bool doImportNoweb(BufferView * view, string const & filename)
3215 ImportNoweb myImport(filename);
3216 Buffer * openbuf = myImport.run();
3218 view->buffer(openbuf);
3226 bool doImportLinuxDoc(BufferView *, string const & filename)
3229 string tmp = lyxrc.linuxdoc_to_lyx_command + filename;
3233 int result = one.startscript(Systemcalls::System, tmp);
3235 string filename = ChangeExtension(filename, ".lyx");
3236 // File was generated without problems. Load it.
3237 buf = bufferlist.loadLyXFile(filename);
3244 void LyXFunc::MenuInsertLyXFile(string const & filen)
3246 string filename = filen;
3248 if (filename.empty()) {
3249 // Launch a file browser
3250 string initpath = lyxrc.document_path;
3253 if (owner->view()->available()) {
3254 string trypath = owner->buffer()->filepath;
3255 // If directory is writeable, use this as default.
3256 if (IsDirWriteable(trypath) == 1)
3261 ProhibitInput(owner->view());
3262 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
3263 fileDlg.SetButton(1, _("Examples"),
3264 AddPath(system_lyxdir, "examples"));
3265 filename = fileDlg.Select(_("Select Document to Insert"),
3267 AllowInput(owner->view());
3269 // check selected filename
3270 if (filename.empty()) {
3271 owner->getMiniBuffer()->Set(_("Canceled."));
3276 // get absolute path of file and make sure the filename ends
3278 filename = MakeAbsPath(filename);
3279 if (!IsLyXFilename(filename))
3283 owner->getMiniBuffer()->Set(_("Inserting document"),
3284 MakeDisplayPath(filename), "...");
3285 bool res = owner->view()->insertLyXFile(filename);
3287 owner->getMiniBuffer()->Set(_("Document"),
3288 MakeDisplayPath(filename),
3291 owner->getMiniBuffer()->Set(_("Could not insert document"),
3292 MakeDisplayPath(filename));
3296 void LyXFunc::doImport(string const & argument)
3299 string filename = split(argument, type, ' ');
3300 lyxerr.debug() << "LyXFunc::doImport: " << type
3301 << " file: " << filename << endl;
3303 if (type == "latex")
3304 doImportHelper(filename,
3305 _("Select LaTeX file to import"), "*.tex",
3307 else if (type == "ascii")
3308 doImportHelper(filename,
3309 _("Select ASCII file to import"), "*.txt",
3310 doImportASCIIasLines);
3311 else if (type == "asciiparagraph")
3312 doImportHelper(filename,
3313 _("Select ASCII file to import"), "*.txt",
3314 doImportASCIIasParagraphs);
3315 else if (type == "noweb")
3316 doImportHelper(filename,
3317 _("Select NoWeb file to import"), "*.nw",
3319 else if (type == "linuxdoc")
3320 doImportHelper(filename,
3321 _("Select LinuxDoc file to import"), "*.doc",
3324 setErrorMessage(string(N_("Unknown import type: ")) + type);
3327 void LyXFunc::reloadBuffer()
3329 string fn = owner->buffer()->fileName();
3330 if (bufferlist.close(owner->buffer()))
3331 owner->view()->buffer(bufferlist.loadLyXFile(fn));
3335 void LyXFunc::CloseBuffer()
3337 if (bufferlist.close(owner->buffer()) && !quitting) {
3338 if (bufferlist.empty()) {
3339 // need this otherwise SEGV may occur while trying to
3340 // set variables that don't exist
3341 // since there's no current buffer
3342 owner->getDialogs()->hideBufferDependent();
3345 owner->view()->buffer(bufferlist.first());
3351 Inset * LyXFunc::getInsetByCode(Inset::Code code)
3353 LyXCursor cursor = owner->view()->text->cursor;
3354 Buffer * buffer = owner->view()->buffer();
3355 for (Buffer::inset_iterator it = Buffer::inset_iterator(cursor.par(),
3357 it != buffer->inset_iterator_end(); ++it) {
3358 if ((*it)->LyxCode() == code)
3365 // Each "owner" should have it's own message method. lyxview and
3366 // the minibuffer would use the minibuffer, but lyxserver would
3367 // send an ERROR signal to its client. Alejandro 970603
3368 // This func is bit problematic when it comes to NLS, to make the
3369 // lyx servers client be language indepenent we must not translate
3370 // strings sent to this func.
3371 void LyXFunc::setErrorMessage(string const & m) const
3373 dispatch_buffer = m;
3378 void LyXFunc::setMessage(string const & m)
3380 dispatch_buffer = m;