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 * ====================================================== */
23 #pragma implementation
29 #include "bufferlist.h"
30 #include "ColorHandler.h"
31 #include "lyxserver.h"
36 #include "LyXAction.h"
37 #include "insets/inseturl.h"
38 #include "insets/insetlatexaccent.h"
39 #include "insets/insettoc.h"
40 #include "insets/insetref.h"
41 #include "insets/insetparent.h"
42 #include "insets/insetindex.h"
43 #include "insets/insetinclude.h"
44 #include "insets/insetbib.h"
45 #include "insets/insetcite.h"
46 #include "insets/insettext.h"
47 #include "insets/insetert.h"
48 #include "insets/insetexternal.h"
49 #include "insets/insetgraphics.h"
50 #include "insets/insetfoot.h"
51 #include "insets/insetmarginal.h"
52 #include "insets/insetminipage.h"
53 #include "insets/insetfloat.h"
54 #include "insets/insetlist.h"
55 #include "insets/insettabular.h"
56 #include "insets/insettheorem.h"
57 #include "insets/insetcaption.h"
58 #include "mathed/formulamacro.h"
59 #include "spellchecker.h" // RVDK_PATCH_5
60 #include "minibuffer.h"
64 #include "lyx_gui_misc.h"
65 #include "support/filetools.h"
66 #include "support/FileInfo.h"
67 #include "support/syscall.h"
68 #include "support/lstrings.h"
69 #include "support/path.h"
70 #include "support/lyxfunctional.h"
75 #include "trans_mgr.h"
79 #include "bufferview_funcs.h"
80 #include "frontends/Dialogs.h"
81 #include "frontends/Toolbar.h"
82 #include "frontends/Menubar.h"
83 #include "FloatList.h"
84 #include "converter.h"
87 #include "FontLoader.h"
88 #include "TextCache.h"
94 extern void math_insert_symbol(BufferView *, string const &);
95 extern bool math_insert_greek(BufferView *, char);
96 extern BufferList bufferlist;
97 extern LyXServer * lyxserver;
98 extern int greek_kb_flag;
99 extern bool selection_possible;
101 extern kb_keymap * toplevel_keymap;
104 extern void MenuFax(Buffer *);
106 extern void show_symbols_form(LyXFunc *);
108 extern LyXAction lyxaction;
110 extern tex_accent_struct get_accent(kb_action action);
112 extern LyXTextClass::size_type current_layout;
114 extern void ShowLatexLog();
116 /* === globals =========================================================== */
118 bool LyXFunc::show_sc = true;
121 LyXFunc::LyXFunc(LyXView * o)
125 lyx_dead_action = LFUN_NOACTION;
126 lyx_calling_dead_action = LFUN_NOACTION;
131 // I changed this func slightly. I commented out the ...FinishUndo(),
132 // this means that all places that used to have a moveCursorUpdate, now
133 // have a ...FinishUndo() as the preceeding statement. I have also added
134 // a moveCursorUpdate to some of the functions that updated the cursor, but
135 // that did not show its new position.
137 void LyXFunc::moveCursorUpdate(bool selecting)
139 if (selecting || owner->view()->text->mark_set) {
140 owner->view()->text->SetSelection();
141 owner->view()->toggleToggle();
143 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
144 owner->view()->showCursor();
146 /* ---> Everytime the cursor is moved, show the current font state. */
147 // should this too me moved out of this func?
148 //owner->showState();
149 owner->view()->setState();
153 int LyXFunc::processKeySym(KeySym keysym, unsigned int state)
157 if (lyxerr.debugging(Debug::KEY)) {
158 char * tmp = XKeysymToString(keysym);
159 string const stm = (tmp ? tmp : "");
160 lyxerr << "KeySym is "
163 << keysym << "] State is ["
167 // Do nothing if we have nothing (JMarc)
168 if (keysym == NoSymbol) {
169 lyxerr[Debug::KEY] << "Empty kbd action (probably composing)"
175 if (owner->view()->available()) {
176 // this function should be used always [asierra060396]
177 UpdatableInset * tli = owner->view()->theLockingInset();
178 if (tli && (keysym == XK_Escape)) {
179 if (tli == tli->GetLockingInset()) {
180 owner->view()->unlockInset(tli);
181 owner->view()->text->CursorRight(owner->view());
182 moveCursorUpdate(false);
185 tli->UnlockInsetInInset(owner->view(),
186 tli->GetLockingInset(),true);
193 // Can we be sure that this will work for all X-Windows
194 // implementations? (Lgb)
195 // This code snippet makes lyx ignore some keys. Perhaps
196 // all of them should be explictly mentioned?
197 if ((keysym >= XK_Shift_L && keysym <= XK_Hyper_R)
198 || keysym == XK_Mode_switch || keysym == 0x0)
201 // Do a one-deep top-level lookup for
202 // cancel and meta-fake keys. RVDK_PATCH_5
203 cancel_meta_seq.reset();
205 int action = cancel_meta_seq.addkey(keysym, state
206 &(ShiftMask|ControlMask
208 if (lyxerr.debugging(Debug::KEY)) {
209 lyxerr << "action first set to [" << action << "]" << endl;
212 // When not cancel or meta-fake, do the normal lookup.
213 // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
214 // Mostly, meta_fake_bit = 0. RVDK_PATCH_5.
215 if ((action != LFUN_CANCEL) && (action != LFUN_META_FAKE)) {
216 if (lyxerr.debugging(Debug::KEY)) {
217 lyxerr << "meta_fake_bit is [" << meta_fake_bit << "]" << endl;
219 // remove Caps Lock and Mod2 as a modifiers
220 action = keyseq.addkey(keysym,
221 (state | meta_fake_bit)
222 &(ShiftMask|ControlMask
224 if (lyxerr.debugging(Debug::KEY)) {
225 lyxerr << "action now set to [" << action << "]" << endl;
228 // Dont remove this unless you know what you are doing.
231 if (action == 0) action = LFUN_PREFIX;
233 if (lyxerr.debugging(Debug::KEY)) {
242 // already here we know if it any point in going further
243 // why not return already here if action == -1 and
244 // num_bytes == 0? (Lgb)
246 if (keyseq.length > 1 || keyseq.length < -1) {
249 owner->getMiniBuffer()->Set(buf);
253 if (keyseq.length < -1) { // unknown key sequence...
257 owner->getMiniBuffer()->Set(_("Unknown sequence:"), buf);
261 char const isochar = keyseq.getiso();
262 if (!(state & ControlMask) &&
263 !(state & Mod1Mask) &&
264 (isochar && keysym < 0xF000)) {
267 if (argument.empty()) {
268 lyxerr.debug() << "Empty argument!" << endl;
269 // This can`t possibly be of any use
270 // so we`ll skip the dispatch.
273 } else if (action == LFUN_SELFINSERT) {
274 // We must set the argument to the char looked up by
279 xke.send_event = False;
280 xke.display = fl_get_display();
290 xke.keycode = XKeysymToKeycode(fl_get_display(), keysym);
291 xke.same_screen = True;
294 int res = XLookupString(&xke, ret, 10, &tmpkeysym, 0);
295 //Assert(keysym == tmpkeysym);
296 lyxerr[Debug::KEY] << "TmpKeysym ["
297 << tmpkeysym << "]" << endl;
300 argument = string(ret, res);
301 lyxerr[Debug::KEY] << "SelfInsert arg["
302 << argument << "]" << endl;
306 bool tmp_sc = show_sc;
308 Dispatch(action, argument);
315 LyXFunc::func_status LyXFunc::getStatus(int ac) const
318 func_status flag = LyXFunc::OK;
320 Buffer * buf = owner->buffer();
322 if (lyxaction.isPseudoAction(ac))
323 action = lyxaction.retrieveActionArg(ac, argument);
325 action = static_cast<kb_action>(ac);
327 if (action == LFUN_UNKNOWN_ACTION) {
328 setErrorMessage(N_("Unknown action"));
329 return LyXFunc::Unknown;
332 // Check whether we need a buffer
333 if (!lyxaction.funcHasFlag(action, LyXAction::NoBuffer)) {
334 // Yes we need a buffer, do we have one?
337 // Can we use a readonly buffer?
338 if (buf->isReadonly() &&
339 !lyxaction.funcHasFlag(action,
340 LyXAction::ReadOnly)) {
342 setErrorMessage(N_("Document is read-only"));
343 flag |= LyXFunc::Disabled;
347 setErrorMessage(N_("Command not allowed with"
348 "out any document open"));
349 flag |= LyXFunc::Disabled;
354 // I would really like to avoid having this switch and rather try to
355 // encode this in the function itself.
356 bool disable = false;
359 disable = !Exporter::IsExportable(buf, "dvi")
360 || lyxrc.print_command == "none";
364 disable = !Exporter::IsExportable(buf, "ps")
365 || lyxrc.fax_command == "none";
369 disable = argument == "fax" &&
370 !Exporter::IsExportable(buf, argument);
374 disable = buf->undostack.empty();
377 disable = buf->redostack.empty();
379 case LFUN_SPELLCHECK:
380 disable = lyxrc.isp_command == "none";
383 disable = lyxrc.chktex_command == "none";
386 disable = !Exporter::IsExportable(buf, "program");
389 case LFUN_INSERTFOOTNOTE:
391 case LFUN_MARGINMELT:
392 // Disable insertion of floats in a tabular.
394 if (owner->view()->theLockingInset()) {
395 disable = (owner->view()->theLockingInset()->LyxCode() == Inset::TABULAR_CODE) ||
396 owner->view()->theLockingInset()->GetFirstLockingInsetOfType(Inset::TABULAR_CODE);
400 case LFUN_LAYOUT_TABULAR:
402 if (owner->view()->theLockingInset()) {
403 disable = (owner->view()->theLockingInset()->LyxCode() != Inset::TABULAR_CODE) &&
404 !owner->view()->theLockingInset()->GetFirstLockingInsetOfType(Inset::TABULAR_CODE);
408 case LFUN_TABULAR_FEATURE:
410 if (owner->view()->theLockingInset()) {
411 func_status ret = LyXFunc::Disabled;
412 if (owner->view()->theLockingInset()->LyxCode() == Inset::TABULAR_CODE) {
413 ret = static_cast<InsetTabular *>
414 (owner->view()->theLockingInset())->
416 } else if (owner->view()->theLockingInset()->GetFirstLockingInsetOfType(Inset::TABULAR_CODE)) {
417 ret = static_cast<InsetTabular *>
418 (owner->view()->theLockingInset()->
419 GetFirstLockingInsetOfType(Inset::TABULAR_CODE))->
425 static InsetTabular inset(*owner->buffer(), 1, 1);
429 ret = inset.getStatus(argument);
430 if ((ret & LyXFunc::ToggleOn) ||
431 (ret & LyXFunc::ToggleOff))
432 flag |= LyXFunc::ToggleOff;
436 case LFUN_VC_REGISTER:
437 disable = buf->lyxvc.inUse();
439 case LFUN_VC_CHECKIN:
440 disable = !buf->lyxvc.inUse() || buf->isReadonly();
442 case LFUN_VC_CHECKOUT:
443 disable = !buf->lyxvc.inUse() || !buf->isReadonly();
447 case LFUN_VC_HISTORY:
448 disable = !buf->lyxvc.inUse();
451 disable = owner->view()->NoSavedPositions();
457 flag |= LyXFunc::Disabled;
460 func_status box = LyXFunc::ToggleOff;
461 LyXFont const & font =
462 owner->view()->getLyXText()->real_current_font;
465 if (font.emph() == LyXFont::ON)
466 box = LyXFunc::ToggleOn;
469 if (font.noun() == LyXFont::ON)
470 box = LyXFunc::ToggleOn;
473 if (font.series() == LyXFont::BOLD_SERIES)
474 box = LyXFunc::ToggleOn;
477 if (font.latex() == LyXFont::ON)
478 box = LyXFunc::ToggleOn;
491 string const LyXFunc::Dispatch(string const & s)
493 // Split command string into command and argument
495 string line = frontStrip(s);
496 string arg = strip(frontStrip(split(line, cmd, ' ')));
498 return Dispatch(lyxaction.LookupFunc(cmd), arg);
502 string const LyXFunc::Dispatch(int ac,
503 string const & do_not_use_this_arg)
505 lyxerr[Debug::ACTION] << "LyXFunc::Dispatch: action[" << ac
506 <<"] arg[" << do_not_use_this_arg << "]" << endl;
511 // we have not done anything wrong yet.
513 dispatch_buffer.erase();
515 // if action is a pseudo-action, we need the real action
516 if (lyxaction.isPseudoAction(ac)) {
518 action = static_cast<kb_action>
519 (lyxaction.retrieveActionArg(ac, tmparg));
523 action = static_cast<kb_action>(ac);
524 if (!do_not_use_this_arg.empty())
525 argument = do_not_use_this_arg; // except here
528 selection_possible = false;
530 if (owner->view()->available())
531 owner->view()->hideCursor();
533 // We have to do this heare because of te goto below. (Lgb)
534 LyXText * text = owner->view()->getLyXText();
536 // We cannot use this function here
537 if (getStatus(ac) & Disabled)
538 goto exit_with_message;
540 commandshortcut.erase();
542 if (lyxrc.display_shortcuts && show_sc) {
543 if (action != LFUN_SELFINSERT) {
544 // Put name of command and list of shortcuts
545 // for it in minibuffer
546 string comname = lyxaction.getActionName(action);
548 int pseudoaction = action;
549 bool argsadded = false;
551 if (!argument.empty()) {
552 // If we have the command with argument,
555 lyxaction.searchActionArg(action,
558 if (pseudoaction == -1) {
559 pseudoaction = action;
561 comname += " " + argument;
566 string const shortcuts =
567 toplevel_keymap->findbinding(pseudoaction);
569 if (!shortcuts.empty()) {
570 comname += ": " + shortcuts;
571 } else if (!argsadded) {
572 comname += " " + argument;
575 if (!comname.empty()) {
576 comname = strip(comname);
577 commandshortcut = "(" + comname + ')';
578 owner->getMiniBuffer()->Set(commandshortcut);
579 // Here we could even add a small pause,
580 // to annoy the user and make him learn
582 // No! That will just annoy, not teach
583 // anything. The user will read the messages
584 // if they are interested. (Asger)
589 if (owner->view()->available() && owner->view()->theLockingInset()) {
590 UpdatableInset::RESULT result;
591 if ((action > 1) || ((action == LFUN_UNKNOWN_ACTION) &&
592 (keyseq.length >= -1)))
594 if ((action==LFUN_UNKNOWN_ACTION) && argument.empty()){
595 argument = keyseq.getiso();
597 // Undo/Redo pre 0.13 is a bit tricky for insets.
598 if (action == LFUN_UNDO) {
601 UpdatableInset * inset =
602 owner->view()->theLockingInset();
603 inset->GetCursorPos(owner->view(), slx, sly);
604 owner->view()->unlockInset(inset);
605 owner->view()->menuUndo();
606 if (owner->view()->text->cursor.par()->
607 IsInset(owner->view()->text->cursor.pos())) {
608 inset = static_cast<UpdatableInset*>(
609 owner->view()->text->cursor.par()->
610 GetInset(owner->view()->text->
616 inset->Edit(owner->view(),slx,sly,0);
618 } else if (action == LFUN_REDO) {
621 UpdatableInset * inset = owner->view()->
623 inset->GetCursorPos(owner->view(), slx, sly);
624 owner->view()->unlockInset(inset);
625 owner->view()->menuRedo();
626 inset = static_cast<UpdatableInset*>(
627 owner->view()->text->cursor.par()->
628 GetInset(owner->view()->text->
631 inset->Edit(owner->view(),slx,sly,0);
633 } else if (((result=owner->view()->theLockingInset()->
634 LocalDispatch(owner->view(), action,
636 UpdatableInset::DISPATCHED) ||
637 (result == UpdatableInset::DISPATCHED_NOUPDATE))
640 //setMessage(N_("Text mode"));
642 case LFUN_UNKNOWN_ACTION:
643 case LFUN_BREAKPARAGRAPH:
645 owner->view()->text->CursorRight(owner->view());
646 owner->view()->setState();
650 if (!owner->view()->text->cursor.par()->isRightToLeftPar(owner->buffer()->params)) {
651 owner->view()->text->CursorRight(owner->view());
652 moveCursorUpdate(false);
657 if (owner->view()->text->cursor.par()->isRightToLeftPar(owner->buffer()->params)) {
658 owner->view()->text->CursorRight(owner->view());
659 moveCursorUpdate(false);
664 owner->view()->text->CursorDown(owner->view());
665 moveCursorUpdate(false);
676 // --- Misc -------------------------------------------
677 case LFUN_WORDFINDFORWARD :
678 case LFUN_WORDFINDBACKWARD : {
679 static string last_search;
680 string searched_string;
682 if (!argument.empty()) {
683 last_search = argument;
684 searched_string = argument;
686 searched_string = last_search;
689 LyXText * ltCur = owner->view()->text ;
691 if (!searched_string.empty() &&
692 ((action == LFUN_WORDFINDBACKWARD) ?
693 ltCur->SearchBackward(owner->view(), searched_string) :
694 ltCur->SearchForward(owner->view(), searched_string))) {
696 // ??? What is that ???
697 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
700 // clear the selection (if there is any)
701 owner->view()->toggleSelection();
702 owner->view()->text->ClearSelection();
704 // Move cursor so that successive C-s 's will not stand in place.
705 if (action == LFUN_WORDFINDFORWARD )
706 owner->view()->text->CursorRightOneWord(owner->view());
707 owner->view()->text->FinishUndo();
708 moveCursorUpdate(false);
711 // set the new selection
712 // SetSelectionOverLenChars(owner->view()->currentBuffer()->text, iLenSelected);
713 owner->view()->toggleSelection(false);
717 // REMOVED : if (owner->view()->getWorkArea()->focus)
718 owner->view()->showCursor();
724 if (owner->view()->available()) {
725 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
728 keyseq.print(buf, true);
729 owner->getMiniBuffer()->Set(buf, string(), string(), 1);
733 // --- Misc -------------------------------------------
734 case LFUN_EXEC_COMMAND:
735 owner->getMiniBuffer()->PrepareForCommand();
738 case LFUN_CANCEL: // RVDK_PATCH_5
741 if (owner->view()->available())
742 // cancel any selection
743 Dispatch(LFUN_MARK_OFF);
744 setMessage(N_("Cancel"));
747 case LFUN_META_FAKE: // RVDK_PATCH_5
749 meta_fake_bit = Mod1Mask;
751 keyseq.print(buf, true);
752 setMessage(buf); // RVDK_PATCH_5
756 case LFUN_READ_ONLY_TOGGLE:
757 if (owner->buffer()->lyxvc.inUse()) {
758 owner->buffer()->lyxvc.toggleReadOnly();
760 owner->buffer()->setReadonly(
761 !owner->buffer()->isReadonly());
765 case LFUN_CENTER: // this is center and redraw.
766 owner->view()->center();
770 if (owner->view()->available()) {
771 owner->view()->text->toggleAppendix(owner->view());
772 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
776 // --- Menus -----------------------------------------------
781 case LFUN_MENUNEWTMPLT:
789 case LFUN_CLOSEBUFFER:
794 if (!owner->buffer()->isUnnamed()) {
795 owner->getMiniBuffer()->Set(_("Saving document"),
796 MakeDisplayPath(owner->buffer()->fileName()),
798 MenuWrite(owner->view(), owner->buffer());
799 //owner->getMiniBuffer()-> {
800 // Set(_("Document saved as"),
801 // MakeDisplayPath(owner->buffer()->fileName()));
803 //owner->getMiniBuffer()->Set(_("Save failed!"));
806 MenuWriteAs(owner->view(), owner->buffer());
810 case LFUN_MENUWRITEAS:
811 MenuWriteAs(owner->view(), owner->buffer());
814 case LFUN_MENURELOAD:
819 Exporter::Export(owner->buffer(), argument, true);
823 Exporter::Preview(owner->buffer(), argument);
827 Exporter::Export(owner->buffer(), "program", true);
831 MenuRunChktex(owner->buffer());
835 owner->getDialogs()->showPrint();
840 MenuFax(owner->buffer());
845 Exporter::Export(owner->buffer(), argument, false);
861 InsetCommandParams p;
863 if (action == LFUN_TOCVIEW )
864 p.setCmdName( "tableofcontents" );
865 else if (action == LFUN_LOAVIEW )
866 p.setCmdName( "listofalgorithms" );
867 else if (action == LFUN_LOFVIEW )
868 p.setCmdName( "listoffigures" );
870 p.setCmdName( "listoftables" );
872 owner->getDialogs()->createTOC( p.getAsString() );
876 case LFUN_TOC_INSERT:
877 case LFUN_LOA_INSERT:
878 case LFUN_LOF_INSERT:
879 case LFUN_LOT_INSERT:
881 InsetCommandParams p;
883 if (action == LFUN_TOC_INSERT )
884 p.setCmdName( "tableofcontents" );
885 else if (action == LFUN_LOA_INSERT )
886 p.setCmdName( "listofalgorithms" );
887 else if (action == LFUN_LOF_INSERT )
888 p.setCmdName( "listoffigures" );
890 p.setCmdName( "listoftables" );
892 Inset * inset = new InsetTOC( p );
893 if (!owner->view()->insertInset( inset, "Standard", true ) )
898 case LFUN_DIALOG_TABULAR_INSERT:
899 owner->getDialogs()->showTabularCreate();
902 case LFUN_TABULAR_FEATURE:
903 case LFUN_SCROLL_INSET:
904 // this is not handled here as this funktion is only aktive
905 // if we have a locking_inset and that one is (or contains)
913 case LFUN_INSET_GRAPHICS:
915 Inset * new_inset = new InsetGraphics;
916 if (!owner->view()->insertInset(new_inset)) {
919 // this is need because you don't use a inset->Edit()
920 owner->view()->updateInset(new_inset, true);
921 new_inset->Edit(owner->view(), 0, 0, 0);
927 AutoSave(owner->view());
931 owner->view()->menuUndo();
935 owner->view()->menuRedo();
938 case LFUN_MENUSEARCH:
940 // Ok this is one _very_ bad solution, but I think that some
941 // of this will be rewritten as part of GUI indep anyway.
943 static LyXFindReplace FR_;
944 FR_.StartSearch(owner->view());
949 owner->view()->paste();
950 owner->view()->setState();
953 case LFUN_PASTESELECTION:
956 if (argument == "paragraph") asPara = true;
957 owner->view()->pasteClipboard(asPara);
962 owner->view()->cut();
966 owner->view()->copy();
969 case LFUN_LAYOUT_COPY:
970 owner->view()->copyEnvironment();
973 case LFUN_LAYOUT_PASTE:
974 owner->view()->pasteEnvironment();
975 owner->view()->setState();
979 owner->view()->gotoInset(Inset::ERROR_CODE, false);
982 case LFUN_REMOVEERRORS:
983 if (owner->view()->removeAutoInsets()) {
984 owner->view()->redraw();
985 owner->view()->fitCursor(owner->view()->text);
990 owner->view()->gotoInset(Inset::IGNORE_CODE, false);
993 case LFUN_REFERENCE_GOTO:
995 vector<Inset::Code> tmp;
996 tmp.push_back(Inset::LABEL_CODE);
997 tmp.push_back(Inset::REF_CODE);
998 owner->view()->gotoInset(tmp, true);
1003 case LFUN_OPENSTUFF:
1004 owner->view()->openStuff();
1008 case LFUN_HYPHENATION:
1009 owner->view()->hyphenationPoint();
1013 owner->view()->ldots();
1016 case LFUN_END_OF_SENTENCE:
1017 owner->view()->endOfSentenceDot();
1020 case LFUN_MENU_SEPARATOR:
1021 owner->view()->menuSeparator();
1025 owner->view()->hfill();
1029 changeDepth(owner->view(), text, 0);
1032 case LFUN_DEPTH_MIN:
1033 changeDepth(owner->view(), text, -1);
1036 case LFUN_DEPTH_PLUS:
1037 changeDepth(owner->view(), text, 1);
1041 Free(owner->view());
1042 owner->view()->setState();
1048 owner->view()->setState();
1053 Melt(owner->view());
1056 case LFUN_RECONFIGURE:
1057 Reconfigure(owner->view());
1061 if (owner->view()->available()
1062 && !owner->view()->text->selection
1063 && owner->view()->text->cursor.par()->footnoteflag
1064 != LyXParagraph::NO_FOOTNOTE)
1065 { // only melt footnotes with FOOTMELT, not margins etc
1066 if (owner->view()->text->cursor.par()->footnotekind == LyXParagraph::FOOTNOTE)
1067 Melt(owner->view());
1070 Foot(owner->view());
1071 owner->view()->setState();
1074 case LFUN_MARGINMELT:
1075 if (owner->view()->available()
1076 && !owner->view()->text->selection
1077 && owner->view()->text->cursor.par()->footnoteflag
1078 != LyXParagraph::NO_FOOTNOTE) {
1079 // only melt margins
1080 if (owner->view()->text->cursor.par()->footnotekind == LyXParagraph::MARGIN)
1081 Melt(owner->view());
1083 Margin(owner->view());
1084 owner->view()->setState();
1088 case LFUN_FLOATSOPERATE:
1089 if (argument == "openfoot")
1090 owner->view()->allFloats(1,0);
1091 else if (argument == "closefoot")
1092 owner->view()->allFloats(0,0);
1093 else if (argument == "openfig")
1094 owner->view()->allFloats(1,1);
1095 else if (argument == "closefig")
1096 owner->view()->allFloats(0,1);
1099 #warning Find another implementation here (or another lyxfunc)!
1101 case LFUN_HELP_COPYRIGHT:
1102 owner->getDialogs()->showCopyright();
1105 case LFUN_HELP_CREDITS:
1106 owner->getDialogs()->showCredits();
1109 case LFUN_HELP_OPEN: {
1110 string arg = argument;
1112 setErrorMessage(N_("Missing argument"));
1115 ProhibitInput(owner->view());
1116 string fname = i18nLibFileSearch("doc", arg, "lyx");
1117 if (fname.empty()) {
1118 lyxerr << "LyX: unable to find documentation file `"
1119 << arg << "'. Bad installation?" << endl;
1120 AllowInput(owner->view());
1123 owner->getMiniBuffer()->Set(_("Opening help file"),
1124 MakeDisplayPath(fname),"...");
1125 owner->view()->buffer(bufferlist.loadLyXFile(fname,false));
1126 AllowInput(owner->view());
1130 case LFUN_HELP_VERSION: {
1131 ProhibitInput(owner->view());
1132 string msg(_("LyX Version "));
1136 fl_show_message(msg.c_str(),
1137 (_("Library directory: ")
1138 + MakeDisplayPath(system_lyxdir)).c_str(),
1139 (_("User directory: ")
1140 + MakeDisplayPath(user_lyxdir)).c_str());
1141 AllowInput(owner->view());
1145 // --- version control -------------------------------
1146 case LFUN_VC_REGISTER:
1148 if (!owner->buffer()->lyxvc.inUse())
1149 owner->buffer()->lyxvc.registrer();
1153 case LFUN_VC_CHECKIN:
1155 if (owner->buffer()->lyxvc.inUse()
1156 && !owner->buffer()->isReadonly())
1157 owner->buffer()->lyxvc.checkIn();
1161 case LFUN_VC_CHECKOUT:
1163 if (owner->buffer()->lyxvc.inUse()
1164 && owner->buffer()->isReadonly())
1165 owner->buffer()->lyxvc.checkOut();
1169 case LFUN_VC_REVERT:
1171 owner->buffer()->lyxvc.revert();
1177 owner->buffer()->lyxvc.undoLast();
1181 case LFUN_VC_HISTORY:
1183 owner->buffer()->lyxvc.showLog();
1187 // --- buffers ----------------------------------------
1189 case LFUN_SWITCHBUFFER:
1190 owner->view()->buffer(bufferlist.getBuffer(argument));
1194 case LFUN_FILE_INSERT:
1196 MenuInsertLyXFile(argument);
1200 case LFUN_FILE_INSERT_ASCII:
1202 bool asPara = (argument == "paragraph");
1203 InsertAsciiFile(owner->view(), string(), asPara);
1209 // servercmd: argument must be <file>:<template>
1210 Buffer * tmpbuf = NewLyxFile(argument);
1212 owner->view()->buffer(tmpbuf);
1216 case LFUN_FILE_OPEN:
1217 owner->view()->buffer(bufferlist.loadLyXFile(argument));
1220 case LFUN_LATEX_LOG:
1226 lyxerr.debug() << "LFUN_LAYOUTNO: (arg) " << argument << endl;
1227 int sel = strToInt(argument);
1228 lyxerr.debug() << "LFUN_LAYOUTNO: (sel) "<< sel << endl;
1230 // Should this give a setMessage instead?
1232 return string(); // illegal argument
1234 --sel; // sel 1..., but layout 0...
1236 // Pretend we got the name instead.
1237 Dispatch(int(LFUN_LAYOUT),
1238 textclasslist.NameOfLayout(owner->view()
1239 ->buffer()->params.textclass,
1246 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1247 << argument << endl;
1249 // Derive layout number from given argument (string)
1250 // and current buffer's textclass (number). */
1251 LyXTextClassList::ClassList::size_type tclass =
1252 owner->view()->buffer()->params.textclass;
1253 pair <bool, LyXTextClass::size_type> layout =
1254 textclasslist.NumberOfLayout(tclass, argument);
1256 // If the entry is obsolete, use the new one instead.
1258 string obs = textclasslist.Style(tclass,layout.second)
1262 textclasslist.NumberOfLayout(tclass, obs);
1265 // see if we found the layout number:
1266 if (!layout.first) {
1267 setErrorMessage(string(N_("Layout ")) + argument +
1272 if (current_layout != layout.second) {
1273 owner->view()->hideCursor();
1274 current_layout = layout.second;
1275 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1276 owner->view()->text->
1277 SetLayout(owner->view(), layout.second);
1278 owner->setLayout(layout.second);
1279 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1280 owner->view()->setState();
1285 case LFUN_LAYOUT_DOCUMENT:
1286 owner->getDialogs()->showLayoutDocument();
1289 case LFUN_LAYOUT_PARAGRAPH:
1290 #ifdef USE_OLD_PARAGRAPH_LAYOUT
1291 MenuLayoutParagraph();
1293 owner->getDialogs()->showLayoutParagraph();
1297 case LFUN_LAYOUT_CHARACTER:
1298 MenuLayoutCharacter();
1301 case LFUN_LAYOUT_TABULAR:
1302 if (owner->view()->theLockingInset()) {
1303 if (owner->view()->theLockingInset()->LyxCode()==Inset::TABULAR_CODE) {
1304 InsetTabular * inset = static_cast<InsetTabular *>
1305 (owner->view()->theLockingInset());
1306 inset->OpenLayoutDialog(owner->view());
1307 } else if (owner->view()->theLockingInset()->
1308 GetFirstLockingInsetOfType(Inset::TABULAR_CODE)!=0) {
1309 InsetTabular * inset = static_cast<InsetTabular *>(
1310 owner->view()->theLockingInset()->GetFirstLockingInsetOfType(Inset::TABULAR_CODE));
1311 inset->OpenLayoutDialog(owner->view());
1316 case LFUN_LAYOUT_PREAMBLE:
1317 MenuLayoutPreamble();
1320 case LFUN_LAYOUT_SAVE_DEFAULT:
1321 MenuLayoutSave(owner->view());
1324 case LFUN_DROP_LAYOUTS_CHOICE:
1325 owner->getToolbar()->openLayoutList();
1329 Lang(owner->view(), argument);
1330 owner->view()->setState();
1335 Emph(owner->view());
1340 Bold(owner->view());
1345 Noun(owner->view());
1350 Code(owner->view());
1355 Sans(owner->view());
1360 Roman(owner->view());
1365 StyleReset(owner->view());
1369 case LFUN_UNDERLINE:
1370 Underline(owner->view());
1374 case LFUN_FONT_SIZE:
1375 FontSize(owner->view(), argument);
1379 case LFUN_FONT_STATE:
1380 setMessage(CurrentState(owner->view()));
1383 case LFUN_UPCASE_WORD:
1384 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1385 text->ChangeWordCase(owner->view(), LyXText::text_uppercase);
1386 if (text->inset_owner)
1387 owner->view()->updateInset(text->inset_owner, true);
1388 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1391 case LFUN_LOWCASE_WORD:
1392 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1393 text->ChangeWordCase(owner->view(), LyXText::text_lowercase);
1394 if (text->inset_owner)
1395 owner->view()->updateInset(text->inset_owner, true);
1396 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1399 case LFUN_CAPITALIZE_WORD:
1400 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1401 text->ChangeWordCase(owner->view(),
1402 LyXText::text_capitalization);
1403 if (text->inset_owner)
1404 owner->view()->updateInset(text->inset_owner, true);
1405 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1408 case LFUN_INSERT_LABEL:
1409 MenuInsertLabel(owner->view(), argument);
1412 case LFUN_REF_INSERT:
1413 if (argument.empty()) {
1414 InsetCommandParams p("ref");
1415 owner->getDialogs()->createRef(p.getAsString());
1417 InsetCommandParams p;
1418 p.setFromString(argument);
1420 InsetRef * inset = new InsetRef(p, *owner->buffer());
1421 if (!owner->view()->insertInset(inset))
1424 owner->view()->updateInset(inset, true);
1430 owner->view()->restorePosition();
1436 string label(argument);
1437 if (label.empty()) {
1439 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1441 label = inset->getContents();
1444 if (!label.empty()) {
1445 owner->view()->savePosition();
1446 if (!owner->view()->gotoLabel(label))
1447 WriteAlert(_("Error"),
1448 _("Couldn't find this label"),
1449 _("in current document."));
1454 case LFUN_MENU_OPEN_BY_NAME:
1455 owner->getMenubar()->openByName(argument);
1456 break; // RVDK_PATCH_5
1458 case LFUN_SPELLCHECK:
1459 if (lyxrc.isp_command != "none")
1460 ShowSpellChecker(owner->view());
1461 break; // RVDK_PATCH_5
1463 // --- Cursor Movements -----------------------------
1466 LyXText * tmptext = owner->view()->text;
1467 bool is_rtl = tmptext->cursor.par()->isRightToLeftPar(owner->buffer()->params);
1468 if (!tmptext->mark_set)
1469 owner->view()->beforeChange();
1470 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1472 tmptext->CursorLeft(owner->view(), false);
1473 if (tmptext->cursor.pos() < tmptext->cursor.par()->Last()
1474 && tmptext->cursor.par()->GetChar(tmptext->cursor.pos())
1475 == LyXParagraph::META_INSET
1476 && tmptext->cursor.par()->GetInset(tmptext->cursor.pos())
1477 && tmptext->cursor.par()->GetInset(tmptext->cursor.pos())->Editable() == Inset::HIGHLY_EDITABLE){
1478 Inset * tmpinset = tmptext->cursor.par()->GetInset(tmptext->cursor.pos());
1479 setMessage(tmpinset->EditMessage());
1483 tmptext->GetFont(owner->view()->buffer(),
1484 tmptext->cursor.par(),
1485 tmptext->cursor.pos());
1486 y = tmpinset->descent(owner->view(),font);
1488 tmpinset->Edit(owner->view(), 0, y, 0);
1492 tmptext->CursorRight(owner->view(), false);
1493 owner->view()->text->FinishUndo();
1494 moveCursorUpdate(false);
1501 // This is soooo ugly. Isn`t it possible to make
1502 // it simpler? (Lgb)
1503 LyXText * txt = owner->view()->text;
1504 bool is_rtl = txt->cursor.par()->isRightToLeftPar(owner->buffer()->params);
1505 if (!txt->mark_set) owner->view()->beforeChange();
1506 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1507 LyXCursor cur = txt->cursor;
1509 txt->CursorLeft(owner->view(), false);
1510 if ((is_rtl || cur != txt->cursor) && // only if really moved!
1511 txt->cursor.pos() < txt->cursor.par()->Last() &&
1512 (txt->cursor.par()->GetChar(txt->cursor.pos()) ==
1513 LyXParagraph::META_INSET) &&
1514 txt->cursor.par()->GetInset(txt->cursor.pos()) &&
1515 (txt->cursor.par()->GetInset(txt->cursor.pos())->Editable()
1516 == Inset::HIGHLY_EDITABLE))
1518 Inset * tmpinset = txt->cursor.par()->GetInset(txt->cursor.pos());
1519 setMessage(tmpinset->EditMessage());
1520 LyXFont font = txt->GetFont(owner->view()->buffer(),
1524 : tmpinset->descent(owner->view(),font);
1525 tmpinset->Edit(owner->view(),
1527 tmpinset->width(owner->view(),font),
1532 txt->CursorRight(owner->view(), false);
1534 owner->view()->text->FinishUndo();
1535 moveCursorUpdate(false);
1541 if (!owner->view()->text->mark_set) owner->view()->beforeChange();
1542 owner->view()->update(BufferView::UPDATE);
1543 owner->view()->text->CursorUp(owner->view());
1544 owner->view()->text->FinishUndo();
1545 moveCursorUpdate(false);
1550 if (!owner->view()->text->mark_set)
1551 owner->view()->beforeChange();
1552 owner->view()->update(BufferView::UPDATE);
1553 owner->view()->text->CursorDown(owner->view());
1554 owner->view()->text->FinishUndo();
1555 moveCursorUpdate(false);
1559 case LFUN_UP_PARAGRAPH:
1560 if (!owner->view()->text->mark_set)
1561 owner->view()->beforeChange();
1562 owner->view()->update(BufferView::UPDATE);
1563 owner->view()->text->CursorUpParagraph(owner->view());
1564 owner->view()->text->FinishUndo();
1565 moveCursorUpdate(false);
1569 case LFUN_DOWN_PARAGRAPH:
1570 if (!owner->view()->text->mark_set)
1571 owner->view()->beforeChange();
1572 owner->view()->update(BufferView::UPDATE);
1573 owner->view()->text->CursorDownParagraph(owner->view());
1574 owner->view()->text->FinishUndo();
1575 moveCursorUpdate(false);
1580 if (!text->mark_set)
1581 owner->view()->beforeChange();
1582 owner->view()->update(BufferView::UPDATE);
1583 owner->view()->cursorPrevious(text);
1584 owner->view()->text->FinishUndo();
1585 if (text->inset_owner)
1586 owner->view()->updateInset(text->inset_owner, false);
1588 moveCursorUpdate(false);
1593 if (!text->mark_set)
1594 owner->view()->beforeChange();
1595 owner->view()->update(BufferView::UPDATE);
1596 owner->view()->cursorNext(text);
1597 owner->view()->text->FinishUndo();
1598 if (text->inset_owner)
1599 owner->view()->updateInset(text->inset_owner, false);
1601 moveCursorUpdate(false);
1606 if (!owner->view()->text->mark_set)
1607 owner->view()->beforeChange();
1608 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1609 owner->view()->text->CursorHome(owner->view());
1610 owner->view()->text->FinishUndo();
1611 moveCursorUpdate(false);
1616 if (!owner->view()->text->mark_set)
1617 owner->view()->beforeChange();
1618 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1619 owner->view()->text->CursorEnd(owner->view());
1620 owner->view()->text->FinishUndo();
1621 moveCursorUpdate(false);
1625 case LFUN_SHIFT_TAB:
1627 if (!owner->view()->text->mark_set)
1628 owner->view()->beforeChange();
1629 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1630 owner->view()->text->CursorTab(owner->view());
1631 owner->view()->text->FinishUndo();
1632 moveCursorUpdate(false);
1636 case LFUN_WORDRIGHT:
1637 if (!text->mark_set)
1638 owner->view()->beforeChange();
1639 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1640 if (text->cursor.par()->isRightToLeftPar(owner->buffer()->params))
1641 text->CursorLeftOneWord(owner->view());
1643 text->CursorRightOneWord(owner->view());
1644 owner->view()->text->FinishUndo();
1645 if (text->inset_owner)
1646 owner->view()->updateInset(text->inset_owner, true);
1647 moveCursorUpdate(false);
1652 if (!text->mark_set)
1653 owner->view()->beforeChange();
1654 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1655 if (text->cursor.par()->isRightToLeftPar(owner->buffer()->params))
1656 text->CursorRightOneWord(owner->view());
1658 text->CursorLeftOneWord(owner->view());
1659 owner->view()->text->FinishUndo();
1660 if (text->inset_owner)
1661 owner->view()->updateInset(text->inset_owner, true);
1662 moveCursorUpdate(false);
1666 case LFUN_BEGINNINGBUF:
1667 if (!owner->view()->text->mark_set)
1668 owner->view()->beforeChange();
1669 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1670 owner->view()->text->CursorTop(owner->view());
1671 owner->view()->text->FinishUndo();
1672 moveCursorUpdate(false);
1677 if (!owner->view()->text->mark_set)
1678 owner->view()->beforeChange();
1679 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1680 owner->view()->text->CursorBottom(owner->view());
1681 owner->view()->text->FinishUndo();
1682 moveCursorUpdate(false);
1687 /* cursor selection ---------------------------- */
1689 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1690 if (owner->view()->text->cursor.par()->isRightToLeftPar(owner->buffer()->params))
1691 owner->view()->text->CursorLeft(owner->view());
1693 owner->view()->text->CursorRight(owner->view());
1694 owner->view()->text->FinishUndo();
1695 moveCursorUpdate(true);
1700 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1701 if (owner->view()->text->cursor.par()->isRightToLeftPar(owner->buffer()->params))
1702 owner->view()->text->CursorRight(owner->view());
1704 owner->view()->text->CursorLeft(owner->view());
1705 owner->view()->text->FinishUndo();
1706 moveCursorUpdate(true);
1711 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1712 owner->view()->text->CursorUp(owner->view());
1713 owner->view()->text->FinishUndo();
1714 moveCursorUpdate(true);
1719 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1720 owner->view()->text->CursorDown(owner->view());
1721 owner->view()->text->FinishUndo();
1722 moveCursorUpdate(true);
1726 case LFUN_UP_PARAGRAPHSEL:
1727 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1728 owner->view()->text->CursorUpParagraph(owner->view());
1729 owner->view()->text->FinishUndo();
1730 moveCursorUpdate(true);
1734 case LFUN_DOWN_PARAGRAPHSEL:
1735 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1736 owner->view()->text->CursorDownParagraph(owner->view());
1737 owner->view()->text->FinishUndo();
1738 moveCursorUpdate(true);
1743 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1744 owner->view()->cursorPrevious(text);
1745 owner->view()->text->FinishUndo();
1746 if (text->inset_owner)
1747 owner->view()->updateInset(text->inset_owner, false);
1749 moveCursorUpdate(true);
1754 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1755 owner->view()->cursorNext(text);
1756 owner->view()->text->FinishUndo();
1757 if (text->inset_owner)
1758 owner->view()->updateInset(text->inset_owner, false);
1760 moveCursorUpdate(true);
1765 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1766 owner->view()->text->CursorHome(owner->view());
1767 owner->view()->text->FinishUndo();
1768 moveCursorUpdate(true);
1773 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1774 owner->view()->text->CursorEnd(owner->view());
1775 owner->view()->text->FinishUndo();
1776 moveCursorUpdate(true);
1780 case LFUN_WORDRIGHTSEL:
1781 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1782 if (owner->view()->text->cursor.par()->isRightToLeftPar(owner->buffer()->params))
1783 owner->view()->text->CursorLeftOneWord(owner->view());
1785 owner->view()->text->CursorRightOneWord(owner->view());
1786 owner->view()->text->FinishUndo();
1787 moveCursorUpdate(true);
1791 case LFUN_WORDLEFTSEL:
1792 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1793 if (owner->view()->text->cursor.par()->isRightToLeftPar(owner->buffer()->params))
1794 owner->view()->text->CursorRightOneWord(owner->view());
1796 owner->view()->text->CursorLeftOneWord(owner->view());
1797 owner->view()->text->FinishUndo();
1798 moveCursorUpdate(true);
1802 case LFUN_BEGINNINGBUFSEL:
1803 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1804 owner->view()->text->CursorTop(owner->view());
1805 owner->view()->text->FinishUndo();
1806 moveCursorUpdate(true);
1810 case LFUN_ENDBUFSEL:
1811 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1812 owner->view()->text->CursorBottom(owner->view());
1813 owner->view()->text->FinishUndo();
1814 moveCursorUpdate(true);
1818 // --- text changing commands ------------------------
1819 case LFUN_BREAKLINE:
1820 owner->view()->beforeChange();
1821 owner->view()->text->InsertChar(owner->view(), LyXParagraph::META_NEWLINE);
1822 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1823 moveCursorUpdate(false);
1826 case LFUN_PROTECTEDSPACE:
1828 LyXLayout const & style =
1829 textclasslist.Style(owner->view()->buffer()->params.textclass,
1830 owner->view()->text->cursor.par()->GetLayout());
1832 if (style.free_spacing) {
1833 owner->view()->text->InsertChar(owner->view(), ' ');
1834 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1836 owner->view()->protectedBlank();
1838 moveCursorUpdate(false);
1843 if (text->mark_set) {
1844 owner->view()->beforeChange();
1845 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1846 setMessage(N_("Mark removed"));
1848 owner->view()->beforeChange();
1850 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1851 setMessage(N_("Mark set"));
1853 text->sel_cursor = text->cursor;
1854 if (text->inset_owner)
1855 owner->view()->updateInset(text->inset_owner, true);
1859 if (!owner->view()->text->selection) {
1860 owner->view()->text->Delete(owner->view());
1861 owner->view()->text->sel_cursor =
1862 owner->view()->text->cursor;
1863 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1864 // It is possible to make it a lot faster still
1865 // just comment out the line below...
1866 owner->view()->showCursor();
1868 owner->view()->cut();
1870 moveCursorUpdate(false);
1872 owner->view()->setState();
1875 case LFUN_DELETE_SKIP:
1877 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1879 LyXCursor cursor = owner->view()->text->cursor;
1881 if (!owner->view()->text->selection) {
1882 if (cursor.pos() == cursor.par()->Last()) {
1883 owner->view()->text->CursorRight(owner->view());
1884 cursor = owner->view()->text->cursor;
1885 if (cursor.pos() == 0
1886 && !(cursor.par()->added_space_top
1887 == VSpace (VSpace::NONE))) {
1888 owner->view()->text->SetParagraph
1890 cursor.par()->line_top,
1891 cursor.par()->line_bottom,
1892 cursor.par()->pagebreak_top,
1893 cursor.par()->pagebreak_bottom,
1894 VSpace(VSpace::NONE),
1895 cursor.par()->added_space_bottom,
1896 cursor.par()->align,
1897 cursor.par()->labelwidthstring, 0);
1898 owner->view()->text->CursorLeft(owner->view());
1899 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1901 owner->view()->text->CursorLeft(owner->view());
1902 owner->view()->text->Delete(owner->view());
1903 owner->view()->text->sel_cursor =
1904 owner->view()->text->cursor;
1905 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1908 owner->view()->text->Delete(owner->view());
1909 owner->view()->text->sel_cursor =
1910 owner->view()->text->cursor;
1911 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1914 owner->view()->cut();
1919 /* -------> Delete word forward. */
1920 case LFUN_DELETE_WORD_FORWARD:
1921 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1922 text->DeleteWordForward(owner->view());
1923 if (text->inset_owner)
1924 owner->view()->updateInset(text->inset_owner, true);
1925 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1926 moveCursorUpdate(false);
1930 /* -------> Delete word backward. */
1931 case LFUN_DELETE_WORD_BACKWARD:
1932 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1933 text->DeleteWordBackward(owner->view());
1934 if (text->inset_owner)
1935 owner->view()->updateInset(text->inset_owner, true);
1936 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1937 moveCursorUpdate(false);
1941 /* -------> Kill to end of line. */
1942 case LFUN_DELETE_LINE_FORWARD:
1943 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1944 text->DeleteLineForward(owner->view());
1945 if (text->inset_owner)
1946 owner->view()->updateInset(text->inset_owner, true);
1947 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1948 moveCursorUpdate(false);
1951 /* -------> Set mark off. */
1953 owner->view()->beforeChange();
1954 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1955 text->sel_cursor = text->cursor;
1956 setMessage(N_("Mark off"));
1957 if (text->inset_owner)
1958 owner->view()->updateInset(text->inset_owner, true);
1961 /* -------> Set mark on. */
1963 owner->view()->beforeChange();
1964 owner->view()->text->mark_set = 1;
1965 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1966 text->sel_cursor = text->cursor;
1967 if (text->inset_owner)
1968 owner->view()->updateInset(text->inset_owner, true);
1969 setMessage(N_("Mark on"));
1972 case LFUN_BACKSPACE:
1974 if (!owner->view()->text->selection) {
1976 if (owner->getIntl()->getTrans()->backspace()) {
1978 if (owner->getIntl()->getTrans().backspace()) {
1980 owner->view()->text->Backspace(owner->view());
1981 owner->view()->text->sel_cursor =
1982 owner->view()->text->cursor;
1983 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1984 // It is possible to make it a lot faster still
1985 // just comment out the line below...
1986 owner->view()->showCursor();
1989 owner->view()->cut();
1992 owner->view()->setState();
1996 case LFUN_BACKSPACE_SKIP:
1998 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2000 LyXCursor cursor = owner->view()->text->cursor;
2002 if (!owner->view()->text->selection) {
2003 if (cursor.pos() == 0
2004 && !(cursor.par()->added_space_top
2005 == VSpace (VSpace::NONE))) {
2006 owner->view()->text->SetParagraph
2008 cursor.par()->line_top,
2009 cursor.par()->line_bottom,
2010 cursor.par()->pagebreak_top,
2011 cursor.par()->pagebreak_bottom,
2012 VSpace(VSpace::NONE), cursor.par()->added_space_bottom,
2013 cursor.par()->align,
2014 cursor.par()->labelwidthstring, 0);
2015 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2017 owner->view()->text->Backspace(owner->view());
2018 owner->view()->text->sel_cursor
2020 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2023 owner->view()->cut();
2027 case LFUN_BREAKPARAGRAPH:
2029 owner->view()->beforeChange();
2030 owner->view()->text->BreakParagraph(owner->view(), 0);
2031 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2032 owner->view()->text->sel_cursor =
2033 owner->view()->text->cursor;
2034 owner->view()->setState();
2039 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2041 owner->view()->beforeChange();
2042 owner->view()->text->BreakParagraph(owner->view(), 1);
2043 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2044 owner->view()->text->sel_cursor =
2045 owner->view()->text->cursor;
2046 owner->view()->setState();
2051 case LFUN_BREAKPARAGRAPH_SKIP:
2053 // When at the beginning of a paragraph, remove
2054 // indentation and add a "defskip" at the top.
2055 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2057 LyXCursor cursor = owner->view()->text->cursor;
2059 owner->view()->beforeChange();
2060 if (cursor.pos() == 0) {
2061 if (cursor.par()->added_space_top == VSpace(VSpace::NONE)) {
2062 owner->view()->text->SetParagraph
2064 cursor.par()->line_top,
2065 cursor.par()->line_bottom,
2066 cursor.par()->pagebreak_top,
2067 cursor.par()->pagebreak_bottom,
2068 VSpace(VSpace::DEFSKIP), cursor.par()->added_space_bottom,
2069 cursor.par()->align,
2070 cursor.par()->labelwidthstring, 1);
2071 //owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2075 owner->view()->text->BreakParagraph(owner->view(), 0);
2076 //owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2079 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2080 owner->view()->text->sel_cursor = cursor;
2081 owner->view()->setState();
2086 case LFUN_PARAGRAPH_SPACING:
2088 LyXParagraph * par = owner->view()->text->cursor.par();
2089 Spacing::Space cur_spacing = par->spacing.getSpace();
2090 float cur_value = 1.0;
2091 if (cur_spacing == Spacing::Other) {
2092 cur_value = par->spacing.getValue();
2095 istringstream istr(argument.c_str());
2099 Spacing::Space new_spacing = cur_spacing;
2100 float new_value = cur_value;
2102 lyxerr << "Missing argument to `paragraph-spacing'"
2104 } else if (tmp == "single") {
2105 new_spacing = Spacing::Single;
2106 } else if (tmp == "onehalf") {
2107 new_spacing = Spacing::Onehalf;
2108 } else if (tmp == "double") {
2109 new_spacing = Spacing::Double;
2110 } else if (tmp == "other") {
2111 new_spacing = Spacing::Other;
2114 lyxerr << "new_value = " << tmpval << endl;
2117 } else if (tmp == "default") {
2118 new_spacing = Spacing::Default;
2120 lyxerr << _("Unknown spacing argument: ")
2121 << argument << endl;
2123 if (cur_spacing != new_spacing || cur_value != new_value) {
2124 par->spacing.set(new_spacing, new_value);
2125 owner->view()->text->RedoParagraph(owner->view());
2126 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2132 owner->view()->beforeChange();
2133 owner->view()->text->InsertChar(owner->view(), '\"'); // This " matches the single quote in the code
2134 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2135 moveCursorUpdate(false);
2141 InsetCommandParams p;
2142 if (action == LFUN_HTMLURL)
2143 p.setCmdName("htmlurl");
2145 p.setCmdName("url");
2146 owner->getDialogs()->createUrl( p.getAsString() );
2150 case LFUN_INSERT_URL:
2152 InsetCommandParams p;
2153 p.setFromString( argument );
2155 InsetUrl * inset = new InsetUrl( p );
2156 if (!owner->view()->insertInset(inset))
2159 owner->view()->updateInset( inset, true );
2163 case LFUN_INSET_TEXT:
2165 InsetText * new_inset = new InsetText;
2166 if (owner->view()->insertInset(new_inset))
2167 new_inset->Edit(owner->view(), 0, 0, 0);
2173 case LFUN_INSET_ERT:
2175 InsetERT * new_inset = new InsetERT;
2176 if (owner->view()->insertInset(new_inset))
2177 new_inset->Edit(owner->view(), 0, 0, 0);
2183 case LFUN_INSET_EXTERNAL:
2185 InsetExternal * new_inset = new InsetExternal;
2186 if (owner->view()->insertInset(new_inset))
2187 new_inset->Edit(owner->view(), 0, 0, 0);
2193 case LFUN_INSET_FOOTNOTE:
2195 InsetFoot * new_inset = new InsetFoot;
2196 if (owner->view()->insertInset(new_inset))
2197 new_inset->Edit(owner->view(), 0, 0, 0);
2203 case LFUN_INSET_MARGINAL:
2205 InsetMarginal * new_inset = new InsetMarginal;
2206 if (owner->view()->insertInset(new_inset))
2207 new_inset->Edit(owner->view(), 0, 0, 0);
2213 case LFUN_INSET_MINIPAGE:
2215 InsetMinipage * new_inset = new InsetMinipage;
2216 if (owner->view()->insertInset(new_inset))
2217 new_inset->Edit(owner->view(), 0, 0, 0);
2223 case LFUN_INSET_FLOAT:
2225 // check if the float type exist
2226 if (floatList.typeExist(argument)) {
2227 InsetFloat * new_inset = new InsetFloat(argument);
2228 if (owner->view()->insertInset(new_inset))
2229 new_inset->Edit(owner->view(), 0, 0, 0);
2233 lyxerr << "Non-existant float type: "
2234 << argument << endl;
2240 case LFUN_INSET_LIST:
2242 InsetList * new_inset = new InsetList;
2243 if (owner->view()->insertInset(new_inset))
2244 new_inset->Edit(owner->view(), 0, 0, 0);
2250 case LFUN_INSET_THEOREM:
2252 InsetTheorem * new_inset = new InsetTheorem;
2253 if (owner->view()->insertInset(new_inset))
2254 new_inset->Edit(owner->view(), 0, 0, 0);
2260 case LFUN_INSET_CAPTION:
2262 // Do we have a locking inset...
2263 if (owner->view()->theLockingInset()) {
2264 lyxerr << "Locking inset code: "
2265 << static_cast<int>(owner->view()->theLockingInset()->LyxCode());
2266 InsetCaption * new_inset = new InsetCaption;
2267 new_inset->setOwner(owner->view()->theLockingInset());
2268 new_inset->SetAutoBreakRows(true);
2269 new_inset->SetDrawFrame(0, InsetText::LOCKED);
2270 new_inset->SetFrameColor(0, LColor::footnoteframe);
2271 if (owner->view()->insertInset(new_inset))
2272 new_inset->Edit(owner->view(), 0, 0, 0);
2279 case LFUN_INSET_TABULAR:
2282 if (!argument.empty())
2283 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2284 InsetTabular * new_inset =
2285 new InsetTabular(*owner->buffer(), r, c);
2287 owner->view()->getLyXText()->real_current_font.isRightToLeft();
2288 if (!owner->view()->open_new_inset(new_inset, rtl))
2293 // --- lyxserver commands ----------------------------
2295 case LFUN_CHARATCURSOR:
2297 LyXParagraph::size_type pos =
2298 owner->view()->text->cursor.pos();
2299 if (pos < owner->view()->text->cursor.par()->size())
2300 //dispatch_buffer = owner->view()->text->
2301 // cursor.par()->text[pos];
2303 owner->view()->text->
2304 cursor.par()->GetChar(pos);
2306 dispatch_buffer = "EOF";
2312 tostr(owner->view()->text->cursor.x()) + ' '
2313 + tostr(owner->view()->text->cursor.y());
2320 ::sscanf(argument.c_str(), " %d %d", &x, &y);
2321 owner->view()->text->SetCursorFromCoordinates(owner->view(), x, y);
2325 case LFUN_GETLAYOUT:
2327 tostr(owner->view()->text->cursor.par()->layout);
2332 LyXFont & font = owner->view()->text->current_font;
2333 if (font.shape() == LyXFont::ITALIC_SHAPE)
2334 dispatch_buffer = 'E';
2335 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2336 dispatch_buffer = 'N';
2338 dispatch_buffer = '0';
2345 LyXFont & font = owner->view()->text->current_font;
2346 if (font.latex() == LyXFont::ON)
2347 dispatch_buffer = 'L';
2349 dispatch_buffer = '0';
2354 setMessage(owner->buffer()->fileName());
2355 lyxerr.debug() << "FNAME["
2356 << owner->buffer()->fileName()
2364 dispatch_buffer = buf;
2365 lyxserver->notifyClient(dispatch_buffer);
2369 case LFUN_GOTOFILEROW:
2371 char file_name[100];
2373 ::sscanf(argument.c_str(), " %s %d", file_name, &row);
2375 // Must replace extension of the file to be .lyx and get full path
2376 string s = ChangeExtension(string(file_name), ".lyx");
2378 // Either change buffer or load the file
2379 if (bufferlist.exists(s))
2380 owner->view()->buffer(bufferlist.getBuffer(s));
2382 owner->view()->buffer(bufferlist.loadLyXFile(s));
2385 owner->view()->setCursorFromRow(row);
2388 owner->view()->center();
2392 case LFUN_GOTO_PARAGRAPH:
2394 istringstream istr(argument.c_str());
2398 LyXParagraph * par = owner->view()->text->GetParFromID(id);
2401 owner->view()->text->SetCursor(owner->view(), par, 0);
2402 owner->view()->setState();
2406 owner->view()->center();
2413 int const qa = lyxaction.LookupFunc(argument);
2414 setMessage(lyxaction.helpText(static_cast<kb_action>(qa)));
2418 // --- accented characters ---------------------------
2421 case LFUN_CIRCUMFLEX:
2431 case LFUN_SPECIAL_CARON:
2434 case LFUN_HUNG_UMLAUT:
2440 if (keyseq.length == -1 && keyseq.getiso() != 0)
2441 c = keyseq.getiso();
2444 owner->getIntl()->getTrans()->
2445 deadkey(c, get_accent(action).accent,
2446 owner->view()->text);
2448 owner->getIntl()->getTrans()
2449 .deadkey(c, get_accent(action).accent,
2450 owner->view()->text);
2453 // Need to reset, in case the minibuffer calls these
2458 // copied verbatim from do_accent_char
2459 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2461 owner->view()->text->sel_cursor =
2462 owner->view()->text->cursor;
2466 // --- toolbar ----------------------------------
2467 case LFUN_PUSH_TOOLBAR:
2469 int nth = strToInt(argument);
2471 setErrorMessage(N_("Push-toolbar needs argument > 0"));
2473 owner->getToolbar()->push(nth);
2478 case LFUN_ADD_TO_TOOLBAR:
2480 if (lyxerr.debugging(Debug::GUI)) {
2481 lyxerr << "LFUN_ADD_TO_TOOLBAR:"
2482 "argument = `" << argument << '\'' << endl;
2484 string tmp(argument);
2485 //lyxerr <<string("Argument: ") + argument);
2486 //lyxerr <<string("Tmp : ") + tmp);
2488 setErrorMessage(N_("Usage: toolbar-add-to <LyX command>"));
2490 owner->getToolbar()->add(argument, false);
2491 owner->getToolbar()->set();
2496 // --- insert characters ----------------------------------------
2498 // --- Mathed stuff. If we are here, there is no locked inset yet.
2503 if (!greek_kb_flag) {
2505 setMessage(N_("Math greek mode on"));
2512 case LFUN_GREEK_TOGGLE:
2514 greek_kb_flag = greek_kb_flag ? 0 : 2;
2515 if (greek_kb_flag) {
2516 setMessage(N_("Math greek keyboard on"));
2518 setMessage(N_("Math greek keyboard off"));
2523 case LFUN_MATH_DELIM:
2524 case LFUN_INSERT_MATRIX:
2526 if (owner->view()->available()) {
2528 open_new_inset(new InsetFormula(false)))
2530 owner->view()->theLockingInset()
2531 ->LocalDispatch(owner->view(),
2539 case LFUN_INSERT_MATH:
2541 math_insert_symbol(owner->view(), argument);
2545 case LFUN_MATH_DISPLAY:
2547 if (owner->view()->available())
2548 owner->view()->open_new_inset(new InsetFormula(true));
2552 case LFUN_MATH_MACRO:
2554 if (owner->view()->available()) {
2557 setErrorMessage(N_("Missing argument"));
2559 string const s1 = token(s, ' ', 1);
2560 int const na = s1.empty() ? 0 : lyx::atoi(s1);
2562 open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2568 case LFUN_MATH_MODE: // Open or create a math inset
2570 if (owner->view()->available())
2571 owner->view()->open_new_inset(new InsetFormula);
2572 setMessage(N_("Math editor mode"));
2576 case LFUN_MATH_NUMBER:
2577 case LFUN_MATH_LIMITS:
2579 setErrorMessage(N_("This is only allowed in math mode!"));
2584 case LFUN_MATH_PANEL:
2586 show_symbols_form(this);
2590 case LFUN_CITATION_CREATE:
2592 InsetCommandParams p( "cite" );
2594 if (!argument.empty()) {
2595 // This should be set at source, ie when typing
2596 // "citation-insert foo" in the minibuffer.
2597 // Question: would pybibliographer also need to be
2598 // changed. Suspect so. Leave as-is therefore.
2599 if (contains(argument, "|")) {
2600 p.setContents( token(argument, '|', 0) );
2601 p.setOptions( token(argument, '|', 1) );
2603 p.setContents( argument );
2605 Dispatch(LFUN_CITATION_INSERT, p.getAsString());
2607 owner->getDialogs()->createCitation( p.getAsString() );
2611 case LFUN_CITATION_INSERT:
2613 InsetCommandParams p;
2614 p.setFromString( argument );
2616 InsetCitation * inset = new InsetCitation( p );
2617 if (!owner->view()->insertInset(inset))
2620 owner->view()->updateInset( inset, true );
2624 case LFUN_INSERT_BIBTEX:
2626 // ale970405+lasgoutt970425
2627 // The argument can be up to two tokens separated
2628 // by a space. The first one is the bibstyle.
2629 string const db = token(argument, ' ', 0);
2630 string bibstyle = token(argument, ' ', 1);
2631 if (bibstyle.empty())
2634 InsetCommandParams p( "BibTeX", db, bibstyle );
2635 InsetBibtex * inset = new InsetBibtex(p);
2637 if (owner->view()->insertInset(inset)) {
2638 if (argument.empty())
2639 inset->Edit(owner->view(), 0, 0, 0);
2645 // BibTeX data bases
2646 case LFUN_BIBDB_ADD:
2648 InsetBibtex * inset =
2649 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2651 inset->addDatabase(argument);
2656 case LFUN_BIBDB_DEL:
2658 InsetBibtex * inset =
2659 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2661 inset->delDatabase(argument);
2666 case LFUN_BIBTEX_STYLE:
2668 InsetBibtex * inset =
2669 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2671 inset->setOptions(argument);
2676 case LFUN_INDEX_CREATE:
2678 InsetCommandParams p( "index" );
2680 if (argument.empty()) {
2681 // Get the word immediately preceding the cursor
2682 LyXParagraph::size_type curpos =
2683 owner->view()->text->cursor.pos() - 1;
2687 curstring = owner->view()->text
2688 ->cursor.par()->GetWord(curpos);
2690 p.setContents( curstring );
2692 p.setContents( argument );
2695 owner->getDialogs()->createIndex( p.getAsString() );
2699 case LFUN_INDEX_INSERT:
2701 InsetCommandParams p;
2702 p.setFromString(argument);
2703 InsetIndex * inset = new InsetIndex(p);
2705 if (!owner->view()->insertInset(inset))
2708 owner->view()->updateInset(inset, true);
2712 case LFUN_INDEX_INSERT_LAST:
2714 // Get word immediately preceding the cursor
2715 LyXParagraph::size_type curpos =
2716 owner->view()->text->cursor.pos() - 1;
2717 // Can't do that at the beginning of a paragraph
2718 if (curpos < 0) break;
2720 string const curstring(owner->view()->text
2721 ->cursor.par()->GetWord(curpos));
2723 InsetCommandParams p("index", curstring);
2724 InsetIndex * inset = new InsetIndex(p);
2726 if (!owner->view()->insertInset(inset))
2729 owner->view()->updateInset(inset, true);
2733 case LFUN_INDEX_PRINT:
2735 InsetCommandParams p("printindex");
2736 Inset * inset = new InsetPrintIndex(p);
2737 if (!owner->view()->insertInset(inset, "Standard", true))
2742 case LFUN_PARENTINSERT:
2744 lyxerr << "arg " << argument << endl;
2745 InsetCommandParams p( "lyxparent", argument );
2746 Inset * inset = new InsetParent(p, *owner->buffer());
2747 if (!owner->view()->insertInset(inset, "Standard", true))
2752 case LFUN_CHILDINSERT:
2754 InsetCommandParams p( "Include", argument );
2755 Inset * inset = new InsetInclude(p, *owner->buffer());
2756 if (owner->view()->insertInset(inset, "Standard", true))
2757 inset->Edit(owner->view(), 0, 0, 0);
2763 case LFUN_CHILDOPEN:
2765 string const filename =
2766 MakeAbsPath(argument,
2767 OnlyPath(owner->buffer()->fileName()));
2768 setMessage(N_("Opening child document ") +
2769 MakeDisplayPath(filename) + "...");
2770 owner->view()->savePosition();
2771 if (bufferlist.exists(filename))
2772 owner->view()->buffer(bufferlist.getBuffer(filename));
2774 owner->view()->buffer(bufferlist.loadLyXFile(filename));
2778 case LFUN_INSERT_NOTE:
2779 owner->view()->insertNote();
2782 case LFUN_INSERTFOOTNOTE:
2784 LyXParagraph::footnote_kind kind;
2785 if (argument == "footnote") {
2786 kind = LyXParagraph::FOOTNOTE;
2787 } else if (argument == "margin") {
2788 kind = LyXParagraph::MARGIN;
2789 } else if (argument == "figure") {
2790 kind = LyXParagraph::FIG;
2791 } else if (argument == "table") {
2792 kind = LyXParagraph::TAB;
2793 } else if (argument == "wide-fig") {
2794 kind = LyXParagraph::WIDE_FIG;
2795 } else if (argument == "wide-tab") {
2796 kind = LyXParagraph::WIDE_TAB;
2797 } else if (argument == "algorithm") {
2798 kind = LyXParagraph::ALGORITHM;
2800 setErrorMessage(N_("Unknown kind of footnote"));
2803 owner->view()->text->InsertFootnoteEnvironment(owner->view(), kind);
2804 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2805 owner->view()->setState();
2809 case LFUN_TOGGLECURSORFOLLOW:
2810 lyxrc.cursor_follows_scrollbar = !lyxrc.cursor_follows_scrollbar;
2813 case LFUN_KMAP_OFF: // keymap off
2814 owner->getIntl()->KeyMapOn(false);
2817 case LFUN_KMAP_PRIM: // primary keymap
2818 owner->getIntl()->KeyMapPrim();
2821 case LFUN_KMAP_SEC: // secondary keymap
2822 owner->getIntl()->KeyMapSec();
2825 case LFUN_KMAP_TOGGLE: // toggle keymap
2826 owner->getIntl()->ToggleKeyMap();
2829 case LFUN_SELFINSERT:
2831 LyXFont const old_font(owner->view()->text->real_current_font);
2832 for (string::size_type i = 0; i < argument.length(); ++i) {
2833 owner->view()->text->InsertChar(owner->view(), argument[i]);
2834 // This needs to be in the loop, or else we
2835 // won't break lines correctly. (Asger)
2836 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2838 owner->view()->text->sel_cursor =
2839 owner->view()->text->cursor;
2840 moveCursorUpdate(false);
2842 // real_current_font.number can change so we need to
2843 // update the minibuffer
2844 if (old_font != owner->view()->text->real_current_font)
2851 // argument contains ';'-terminated commands
2852 while (argument.find(';') != string::npos) {
2854 argument = split(argument, first, ';');
2860 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
2864 time_t now_time_t = time(NULL);
2865 now_tm = localtime(&now_time_t);
2866 setlocale(LC_TIME, "");
2868 if (!argument.empty())
2871 arg = lyxrc.date_insert_format;
2873 int const datetmp_len =
2874 ::strftime(datetmp, 32, arg.c_str(), now_tm);
2875 for (int i = 0; i < datetmp_len; i++) {
2876 owner->view()->text->InsertChar(owner->view(), datetmp[i]);
2877 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2880 owner->view()->text->sel_cursor = owner->view()->text->cursor;
2881 moveCursorUpdate(false);
2885 case LFUN_DIALOG_PREFERENCES:
2886 owner->getDialogs()->showPreferences();
2889 case LFUN_SAVEPREFERENCES:
2891 Path p(user_lyxdir);
2892 lyxrc.write("preferences");
2896 case LFUN_SCREEN_FONT_UPDATE:
2898 // handle the screen font changes.
2900 lyxrc.set_font_norm_type();
2901 fontloader.update();
2902 // Of course we should only do the resize and the textcache.clear
2903 // if values really changed...but not very important right now. (Lgb)
2904 // All buffers will need resize
2905 bufferlist.resize();
2906 // We also need to empty the textcache so that
2907 // the buffer will be formatted correctly after
2913 case LFUN_SET_COLOR:
2916 string const x11_name = split(argument, lyx_name, ' ');
2917 if (lyx_name.empty() || x11_name.empty()) {
2919 setErrorMessage(N_("Syntax: set-color <lyx_name>"
2924 if (!lcolor.setColor(lyx_name, x11_name)) {
2925 static string const err1 (N_("Set-color \""));
2926 static string const err2 (
2927 N_("\" failed - color is undefined "
2928 "or may not be redefined"));
2930 setErrorMessage(_(err1) + lyx_name + _(err2));
2933 lyxColorHandler->updateColor(lcolor.getFromLyXName(lyx_name));
2934 owner->view()->redraw();
2938 case LFUN_UNKNOWN_ACTION:
2940 if (!owner->buffer()) {
2942 setErrorMessage(N_("No document open"));
2946 if (owner->buffer()->isReadonly()) {
2948 setErrorMessage(N_("Document is read only"));
2952 if (!argument.empty()) {
2954 /* Automatically delete the currently selected
2955 * text and replace it with what is being
2956 * typed in now. Depends on lyxrc settings
2957 * "auto_region_delete", which defaults to
2960 if (lyxrc.auto_region_delete) {
2961 if (owner->view()->text->selection){
2962 owner->view()->text->CutSelection(owner->view(), false);
2963 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2967 owner->view()->beforeChange();
2968 LyXFont const old_font(owner->view()->text->real_current_font);
2969 for (string::size_type i = 0;
2970 i < argument.length(); ++i) {
2971 if (greek_kb_flag) {
2972 if (!math_insert_greek(owner->view(),
2975 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2977 owner->getIntl()->getTrans().TranslateAndInsert(argument[i], owner->view()->text);
2981 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2983 owner->getIntl()->getTrans().TranslateAndInsert(argument[i], owner->view()->text);
2987 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2989 owner->view()->text->sel_cursor =
2990 owner->view()->text->cursor;
2991 moveCursorUpdate(false);
2993 // real_current_font.number can change so we need to
2994 // update the minibuffer
2995 if (old_font != owner->view()->text->real_current_font)
2999 // why is an "Unknown action" with empty
3000 // argument even dispatched in the first
3001 // place? I`ll probably change that. (Lgb)
3003 setErrorMessage(N_("Unknown action"));
3009 lyxerr << "A truly unknown func!" << endl;
3014 string const res = getMessage();
3017 if (!commandshortcut.empty()) {
3018 string const newbuf =
3019 owner->getMiniBuffer()->GetText();
3020 if (newbuf != commandshortcut) {
3021 owner->getMiniBuffer()->Set(newbuf
3029 msg += commandshortcut;
3030 owner->getMiniBuffer()->Set(msg);
3037 void LyXFunc::setupLocalKeymap()
3039 keyseq.stdmap = keyseq.curmap = toplevel_keymap;
3040 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap;
3044 void LyXFunc::MenuNew(bool fromTemplate)
3046 string initpath = lyxrc.document_path;
3049 if (owner->view()->available()) {
3050 string const trypath = owner->buffer()->filepath;
3051 // If directory is writeable, use this as default.
3052 if (IsDirWriteable(trypath) == 1)
3056 static int newfile_number = 0;
3059 if (lyxrc.new_ask_filename) {
3060 ProhibitInput(owner->view());
3061 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
3062 fileDlg.SetButton(1, _("Templates"), lyxrc.template_path);
3063 string fname = fileDlg.Select(_("Enter Filename for new document"),
3064 initpath, "*.lyx", _("newfile"));
3065 AllowInput(owner->view());
3067 if (fname.empty()) {
3068 owner->getMiniBuffer()->Set(_("Canceled."));
3069 lyxerr.debug() << "New Document Cancelled." << endl;
3073 // get absolute path of file and make sure the filename ends
3075 s = MakeAbsPath(fname);
3076 if (!IsLyXFilename(s))
3079 // Check if the document already is open
3080 if (bufferlist.exists(s)) {
3081 switch (AskConfirmation(_("Document is already open:"),
3082 MakeDisplayPath(s, 50),
3083 _("Do you want to close that document now?\n"
3084 "('No' will just switch to the open version)")))
3086 case 1: // Yes: close the document
3087 if (!bufferlist.close(bufferlist.getBuffer(s)))
3088 // If close is canceled, we cancel here too.
3091 case 2: // No: switch to the open document
3092 owner->view()->buffer(bufferlist.getBuffer(s));
3094 case 3: // Cancel: Do nothing
3095 owner->getMiniBuffer()->Set(_("Canceled."));
3099 // Check whether the file already exists
3100 if (IsLyXFilename(s)) {
3102 if (fi.readable() &&
3103 AskQuestion(_("File already exists:"),
3104 MakeDisplayPath(s, 50),
3105 _("Do you want to open the document?"))) {
3107 owner->getMiniBuffer()->Set(_("Opening document"),
3108 MakeDisplayPath(s), "...");
3109 XFlush(fl_get_display());
3110 owner->view()->buffer(
3111 bufferlist.loadLyXFile(s));
3112 owner->getMiniBuffer()->Set(_("Document"),
3119 s = AddName(lyxrc.document_path,
3120 "newfile" + tostr(++newfile_number) + ".lyx");
3122 while (bufferlist.exists(s) || fi.readable()) {
3124 s = AddName(lyxrc.document_path,
3125 "newfile" + tostr(newfile_number) +
3131 // The template stuff
3134 ProhibitInput(owner->view());
3135 string const fname = fileDlg.Select(_("Choose template"),
3136 lyxrc.template_path,
3138 AllowInput(owner->view());
3139 if (fname.empty()) return;
3143 // find a free buffer
3144 lyxerr.debug() << "Find a free buffer." << endl;
3145 owner->view()->buffer(bufferlist.newFile(s, templname));
3149 void LyXFunc::MenuOpen()
3151 string initpath = lyxrc.document_path;
3154 if (owner->view()->available()) {
3155 string const trypath = owner->buffer()->filepath;
3156 // If directory is writeable, use this as default.
3157 if (IsDirWriteable(trypath) == 1)
3162 ProhibitInput(owner->view());
3163 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
3164 fileDlg.SetButton(1, _("Examples"),
3165 AddPath(system_lyxdir, "examples"));
3166 string filename = fileDlg.Select(_("Select Document to Open"),
3168 AllowInput(owner->view());
3170 // check selected filename
3171 if (filename.empty()) {
3172 owner->getMiniBuffer()->Set(_("Canceled."));
3176 // get absolute path of file and make sure the filename ends
3178 filename = MakeAbsPath(filename);
3179 if (!IsLyXFilename(filename))
3183 owner->getMiniBuffer()->Set(_("Opening document"),
3184 MakeDisplayPath(filename), "...");
3185 Buffer * openbuf = bufferlist.loadLyXFile(filename);
3187 owner->view()->buffer(openbuf);
3188 owner->getMiniBuffer()->Set(_("Document"),
3189 MakeDisplayPath(filename),
3192 owner->getMiniBuffer()->Set(_("Could not open document"),
3193 MakeDisplayPath(filename));
3198 // checks for running without gui are missing.
3199 void LyXFunc::doImport(string const & argument)
3202 string filename = split(argument, format, ' ');
3203 lyxerr.debug() << "LyXFunc::doImport: " << format
3204 << " file: " << filename << endl;
3206 if (filename.empty()) { // need user interaction
3207 string initpath = lyxrc.document_path;
3210 if (owner->view()->available()) {
3211 string const trypath = owner->buffer()->filepath;
3212 // If directory is writeable, use this as default.
3213 if (IsDirWriteable(trypath) == 1)
3218 ProhibitInput(owner->view());
3219 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
3220 fileDlg.SetButton(1, _("Examples"),
3221 AddPath(system_lyxdir, "examples"));
3222 string const text = _("Select ") + formats.PrettyName(format)
3223 + _(" file to import");
3224 string const extension = "*." + formats.Extension(format);
3225 filename = fileDlg.Select(text, initpath, extension);
3226 AllowInput(owner->view());
3228 // check selected filename
3229 if (filename.empty())
3230 owner->getMiniBuffer()->Set(_("Canceled."));
3233 // still no filename? abort
3234 if (filename.empty())
3237 // get absolute path of file
3238 filename = MakeAbsPath(filename);
3240 string const lyxfile = ChangeExtension(filename, ".lyx");
3242 // Check if the document already is open
3243 if (bufferlist.exists(lyxfile)) {
3244 switch (AskConfirmation(_("Document is already open:"),
3245 MakeDisplayPath(lyxfile, 50),
3246 _("Do you want to close that document now?\n"
3247 "('No' will just switch to the open version)")))
3249 case 1: // Yes: close the document
3250 if (!bufferlist.close(bufferlist.getBuffer(lyxfile)))
3251 // If close is canceled, we cancel here too.
3254 case 2: // No: switch to the open document
3255 owner->view()->buffer(bufferlist.getBuffer(lyxfile));
3257 case 3: // Cancel: Do nothing
3258 owner->getMiniBuffer()->Set(_("Canceled."));
3263 // Check if a LyX document by the same root exists in filesystem
3264 FileInfo const f(lyxfile, true);
3265 if (f.exist() && !AskQuestion(_("A document by the name"),
3266 MakeDisplayPath(lyxfile),
3267 _("already exists. Overwrite?"))) {
3268 owner->getMiniBuffer()->Set(_("Canceled."));
3271 // filename should be valid now
3273 Importer::Import(owner, filename, format);
3277 void LyXFunc::MenuInsertLyXFile(string const & filen)
3279 string filename = filen;
3281 if (filename.empty()) {
3282 // Launch a file browser
3283 string initpath = lyxrc.document_path;
3286 if (owner->view()->available()) {
3287 string const trypath = owner->buffer()->filepath;
3288 // If directory is writeable, use this as default.
3289 if (IsDirWriteable(trypath) == 1)
3294 ProhibitInput(owner->view());
3295 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
3296 fileDlg.SetButton(1, _("Examples"),
3297 AddPath(system_lyxdir, "examples"));
3298 filename = fileDlg.Select(_("Select Document to Insert"),
3300 AllowInput(owner->view());
3302 // check selected filename
3303 if (filename.empty()) {
3304 owner->getMiniBuffer()->Set(_("Canceled."));
3309 // get absolute path of file and make sure the filename ends
3311 filename = MakeAbsPath(filename);
3312 if (!IsLyXFilename(filename))
3316 owner->getMiniBuffer()->Set(_("Inserting document"),
3317 MakeDisplayPath(filename), "...");
3318 bool const res = owner->view()->insertLyXFile(filename);
3320 owner->getMiniBuffer()->Set(_("Document"),
3321 MakeDisplayPath(filename),
3324 owner->getMiniBuffer()->Set(_("Could not insert document"),
3325 MakeDisplayPath(filename));
3330 void LyXFunc::reloadBuffer()
3332 string const fn = owner->buffer()->fileName();
3333 if (bufferlist.close(owner->buffer()))
3334 owner->view()->buffer(bufferlist.loadLyXFile(fn));
3338 void LyXFunc::CloseBuffer()
3340 if (bufferlist.close(owner->buffer()) && !quitting) {
3341 if (bufferlist.empty()) {
3342 // need this otherwise SEGV may occur while trying to
3343 // set variables that don't exist
3344 // since there's no current buffer
3345 owner->getDialogs()->hideBufferDependent();
3347 owner->view()->buffer(bufferlist.first());
3353 Inset * LyXFunc::getInsetByCode(Inset::Code code)
3355 LyXCursor cursor = owner->view()->text->cursor;
3356 Buffer * buffer = owner->view()->buffer();
3357 Buffer::inset_iterator it =
3358 find_if(Buffer::inset_iterator(cursor.par(),
3360 buffer->inset_iterator_end(),
3361 compare_memfun(&Inset::LyxCode, code));
3362 return it != buffer->inset_iterator_end() ? (*it) : 0;
3366 // Each "owner" should have it's own message method. lyxview and
3367 // the minibuffer would use the minibuffer, but lyxserver would
3368 // send an ERROR signal to its client. Alejandro 970603
3369 // This func is bit problematic when it comes to NLS, to make the
3370 // lyx servers client be language indepenent we must not translate
3371 // strings sent to this func.
3372 void LyXFunc::setErrorMessage(string const & m) const
3374 dispatch_buffer = m;
3379 void LyXFunc::setMessage(string const & m)
3381 dispatch_buffer = m;