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()->gotoError();
982 case LFUN_REMOVEERRORS:
983 if (owner->view()->removeAutoInsets()) {
984 owner->view()->redraw();
985 owner->view()->fitCursor(owner->view()->text);
990 owner->view()->gotoNote();
995 owner->view()->openStuff();
999 case LFUN_HYPHENATION:
1000 owner->view()->hyphenationPoint();
1004 owner->view()->ldots();
1007 case LFUN_END_OF_SENTENCE:
1008 owner->view()->endOfSentenceDot();
1011 case LFUN_MENU_SEPARATOR:
1012 owner->view()->menuSeparator();
1016 owner->view()->hfill();
1020 changeDepth(owner->view(), text, 0);
1023 case LFUN_DEPTH_MIN:
1024 changeDepth(owner->view(), text, -1);
1027 case LFUN_DEPTH_PLUS:
1028 changeDepth(owner->view(), text, 1);
1032 Free(owner->view());
1033 owner->view()->setState();
1039 owner->view()->setState();
1044 Melt(owner->view());
1047 case LFUN_RECONFIGURE:
1048 Reconfigure(owner->view());
1052 if (owner->view()->available()
1053 && !owner->view()->text->selection
1054 && owner->view()->text->cursor.par()->footnoteflag
1055 != LyXParagraph::NO_FOOTNOTE)
1056 { // only melt footnotes with FOOTMELT, not margins etc
1057 if (owner->view()->text->cursor.par()->footnotekind == LyXParagraph::FOOTNOTE)
1058 Melt(owner->view());
1061 Foot(owner->view());
1062 owner->view()->setState();
1065 case LFUN_MARGINMELT:
1066 if (owner->view()->available()
1067 && !owner->view()->text->selection
1068 && owner->view()->text->cursor.par()->footnoteflag
1069 != LyXParagraph::NO_FOOTNOTE) {
1070 // only melt margins
1071 if (owner->view()->text->cursor.par()->footnotekind == LyXParagraph::MARGIN)
1072 Melt(owner->view());
1074 Margin(owner->view());
1075 owner->view()->setState();
1079 case LFUN_FLOATSOPERATE:
1080 if (argument == "openfoot")
1081 owner->view()->allFloats(1,0);
1082 else if (argument == "closefoot")
1083 owner->view()->allFloats(0,0);
1084 else if (argument == "openfig")
1085 owner->view()->allFloats(1,1);
1086 else if (argument == "closefig")
1087 owner->view()->allFloats(0,1);
1090 #warning Find another implementation here (or another lyxfunc)!
1092 case LFUN_HELP_COPYRIGHT:
1093 owner->getDialogs()->showCopyright();
1096 case LFUN_HELP_CREDITS:
1097 owner->getDialogs()->showCredits();
1100 case LFUN_HELP_OPEN: {
1101 string arg = argument;
1103 setErrorMessage(N_("Missing argument"));
1106 ProhibitInput(owner->view());
1107 string fname = i18nLibFileSearch("doc", arg, "lyx");
1108 if (fname.empty()) {
1109 lyxerr << "LyX: unable to find documentation file `"
1110 << arg << "'. Bad installation?" << endl;
1111 AllowInput(owner->view());
1114 owner->getMiniBuffer()->Set(_("Opening help file"),
1115 MakeDisplayPath(fname),"...");
1116 owner->view()->buffer(bufferlist.loadLyXFile(fname,false));
1117 AllowInput(owner->view());
1121 case LFUN_HELP_VERSION: {
1122 ProhibitInput(owner->view());
1123 string msg(_("LyX Version "));
1127 fl_show_message(msg.c_str(),
1128 (_("Library directory: ")
1129 + MakeDisplayPath(system_lyxdir)).c_str(),
1130 (_("User directory: ")
1131 + MakeDisplayPath(user_lyxdir)).c_str());
1132 AllowInput(owner->view());
1136 // --- version control -------------------------------
1137 case LFUN_VC_REGISTER:
1139 if (!owner->buffer()->lyxvc.inUse())
1140 owner->buffer()->lyxvc.registrer();
1144 case LFUN_VC_CHECKIN:
1146 if (owner->buffer()->lyxvc.inUse()
1147 && !owner->buffer()->isReadonly())
1148 owner->buffer()->lyxvc.checkIn();
1152 case LFUN_VC_CHECKOUT:
1154 if (owner->buffer()->lyxvc.inUse()
1155 && owner->buffer()->isReadonly())
1156 owner->buffer()->lyxvc.checkOut();
1160 case LFUN_VC_REVERT:
1162 owner->buffer()->lyxvc.revert();
1168 owner->buffer()->lyxvc.undoLast();
1172 case LFUN_VC_HISTORY:
1174 owner->buffer()->lyxvc.showLog();
1178 // --- buffers ----------------------------------------
1180 case LFUN_SWITCHBUFFER:
1181 owner->view()->buffer(bufferlist.getBuffer(argument));
1185 case LFUN_FILE_INSERT:
1187 MenuInsertLyXFile(argument);
1191 case LFUN_FILE_INSERT_ASCII:
1193 bool asPara = (argument == "paragraph");
1194 InsertAsciiFile(owner->view(), string(), asPara);
1200 // servercmd: argument must be <file>:<template>
1201 Buffer * tmpbuf = NewLyxFile(argument);
1203 owner->view()->buffer(tmpbuf);
1207 case LFUN_FILE_OPEN:
1208 owner->view()->buffer(bufferlist.loadLyXFile(argument));
1211 case LFUN_LATEX_LOG:
1217 lyxerr.debug() << "LFUN_LAYOUTNO: (arg) " << argument << endl;
1218 int sel = strToInt(argument);
1219 lyxerr.debug() << "LFUN_LAYOUTNO: (sel) "<< sel << endl;
1221 // Should this give a setMessage instead?
1223 return string(); // illegal argument
1225 --sel; // sel 1..., but layout 0...
1227 // Pretend we got the name instead.
1228 Dispatch(int(LFUN_LAYOUT),
1229 textclasslist.NameOfLayout(owner->view()
1230 ->buffer()->params.textclass,
1237 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1238 << argument << endl;
1240 // Derive layout number from given argument (string)
1241 // and current buffer's textclass (number). */
1242 LyXTextClassList::ClassList::size_type tclass =
1243 owner->view()->buffer()->params.textclass;
1244 pair <bool, LyXTextClass::size_type> layout =
1245 textclasslist.NumberOfLayout(tclass, argument);
1247 // If the entry is obsolete, use the new one instead.
1249 string obs = textclasslist.Style(tclass,layout.second)
1253 textclasslist.NumberOfLayout(tclass, obs);
1256 // see if we found the layout number:
1257 if (!layout.first) {
1258 setErrorMessage(string(N_("Layout ")) + argument +
1263 if (current_layout != layout.second) {
1264 owner->view()->hideCursor();
1265 current_layout = layout.second;
1266 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1267 owner->view()->text->
1268 SetLayout(owner->view(), layout.second);
1269 owner->setLayout(layout.second);
1270 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1271 owner->view()->setState();
1276 case LFUN_LAYOUT_DOCUMENT:
1277 owner->getDialogs()->showLayoutDocument();
1280 case LFUN_LAYOUT_PARAGRAPH:
1281 #ifdef USE_OLD_PARAGRAPH_LAYOUT
1282 MenuLayoutParagraph();
1284 owner->getDialogs()->showLayoutParagraph();
1288 case LFUN_LAYOUT_CHARACTER:
1289 MenuLayoutCharacter();
1292 case LFUN_LAYOUT_TABULAR:
1293 if (owner->view()->theLockingInset()) {
1294 if (owner->view()->theLockingInset()->LyxCode()==Inset::TABULAR_CODE) {
1295 InsetTabular * inset = static_cast<InsetTabular *>
1296 (owner->view()->theLockingInset());
1297 inset->OpenLayoutDialog(owner->view());
1298 } else if (owner->view()->theLockingInset()->
1299 GetFirstLockingInsetOfType(Inset::TABULAR_CODE)!=0) {
1300 InsetTabular * inset = static_cast<InsetTabular *>(
1301 owner->view()->theLockingInset()->GetFirstLockingInsetOfType(Inset::TABULAR_CODE));
1302 inset->OpenLayoutDialog(owner->view());
1307 case LFUN_LAYOUT_PREAMBLE:
1308 MenuLayoutPreamble();
1311 case LFUN_LAYOUT_SAVE_DEFAULT:
1312 MenuLayoutSave(owner->view());
1315 case LFUN_DROP_LAYOUTS_CHOICE:
1316 owner->getToolbar()->openLayoutList();
1320 Lang(owner->view(), argument);
1321 owner->view()->setState();
1326 Emph(owner->view());
1331 Bold(owner->view());
1336 Noun(owner->view());
1341 Code(owner->view());
1346 Sans(owner->view());
1351 Roman(owner->view());
1356 StyleReset(owner->view());
1360 case LFUN_UNDERLINE:
1361 Underline(owner->view());
1365 case LFUN_FONT_SIZE:
1366 FontSize(owner->view(), argument);
1370 case LFUN_FONT_STATE:
1371 setMessage(CurrentState(owner->view()));
1374 case LFUN_UPCASE_WORD:
1375 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1376 text->ChangeWordCase(owner->view(), LyXText::text_uppercase);
1377 if (text->inset_owner)
1378 owner->view()->updateInset(text->inset_owner, true);
1379 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1382 case LFUN_LOWCASE_WORD:
1383 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1384 text->ChangeWordCase(owner->view(), LyXText::text_lowercase);
1385 if (text->inset_owner)
1386 owner->view()->updateInset(text->inset_owner, true);
1387 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1390 case LFUN_CAPITALIZE_WORD:
1391 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1392 text->ChangeWordCase(owner->view(),
1393 LyXText::text_capitalization);
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_INSERT_LABEL:
1400 MenuInsertLabel(owner->view(), argument);
1403 case LFUN_REF_INSERT:
1404 if (argument.empty()) {
1405 InsetCommandParams p("ref");
1406 owner->getDialogs()->createRef(p.getAsString());
1408 InsetCommandParams p;
1409 p.setFromString(argument);
1411 InsetRef * inset = new InsetRef(p, *owner->buffer());
1412 if (!owner->view()->insertInset(inset))
1415 owner->view()->updateInset(inset, true);
1421 owner->view()->restorePosition();
1427 string label(argument);
1428 if (label.empty()) {
1430 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1432 label = inset->getContents();
1435 if (!label.empty()) {
1436 owner->view()->savePosition();
1437 if (!owner->view()->gotoLabel(label))
1438 WriteAlert(_("Error"),
1439 _("Couldn't find this label"),
1440 _("in current document."));
1445 case LFUN_MENU_OPEN_BY_NAME:
1446 owner->getMenubar()->openByName(argument);
1447 break; // RVDK_PATCH_5
1449 case LFUN_SPELLCHECK:
1450 if (lyxrc.isp_command != "none")
1451 ShowSpellChecker(owner->view());
1452 break; // RVDK_PATCH_5
1454 // --- Cursor Movements -----------------------------
1457 LyXText * tmptext = owner->view()->text;
1458 bool is_rtl = tmptext->cursor.par()->isRightToLeftPar(owner->buffer()->params);
1459 if (!tmptext->mark_set)
1460 owner->view()->beforeChange();
1461 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1463 tmptext->CursorLeft(owner->view(), false);
1464 if (tmptext->cursor.pos() < tmptext->cursor.par()->Last()
1465 && tmptext->cursor.par()->GetChar(tmptext->cursor.pos())
1466 == LyXParagraph::META_INSET
1467 && tmptext->cursor.par()->GetInset(tmptext->cursor.pos())
1468 && tmptext->cursor.par()->GetInset(tmptext->cursor.pos())->Editable() == Inset::HIGHLY_EDITABLE){
1469 Inset * tmpinset = tmptext->cursor.par()->GetInset(tmptext->cursor.pos());
1470 setMessage(tmpinset->EditMessage());
1474 tmptext->GetFont(owner->view()->buffer(),
1475 tmptext->cursor.par(),
1476 tmptext->cursor.pos());
1477 y = tmpinset->descent(owner->view(),font);
1479 tmpinset->Edit(owner->view(), 0, y, 0);
1483 tmptext->CursorRight(owner->view(), false);
1484 owner->view()->text->FinishUndo();
1485 moveCursorUpdate(false);
1492 // This is soooo ugly. Isn`t it possible to make
1493 // it simpler? (Lgb)
1494 LyXText * txt = owner->view()->text;
1495 bool is_rtl = txt->cursor.par()->isRightToLeftPar(owner->buffer()->params);
1496 if (!txt->mark_set) owner->view()->beforeChange();
1497 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1498 LyXCursor cur = txt->cursor;
1500 txt->CursorLeft(owner->view(), false);
1501 if ((is_rtl || cur != txt->cursor) && // only if really moved!
1502 txt->cursor.pos() < txt->cursor.par()->Last() &&
1503 (txt->cursor.par()->GetChar(txt->cursor.pos()) ==
1504 LyXParagraph::META_INSET) &&
1505 txt->cursor.par()->GetInset(txt->cursor.pos()) &&
1506 (txt->cursor.par()->GetInset(txt->cursor.pos())->Editable()
1507 == Inset::HIGHLY_EDITABLE))
1509 Inset * tmpinset = txt->cursor.par()->GetInset(txt->cursor.pos());
1510 setMessage(tmpinset->EditMessage());
1511 LyXFont font = txt->GetFont(owner->view()->buffer(),
1515 : tmpinset->descent(owner->view(),font);
1516 tmpinset->Edit(owner->view(),
1518 tmpinset->width(owner->view(),font),
1523 txt->CursorRight(owner->view(), false);
1525 owner->view()->text->FinishUndo();
1526 moveCursorUpdate(false);
1532 if (!owner->view()->text->mark_set) owner->view()->beforeChange();
1533 owner->view()->update(BufferView::UPDATE);
1534 owner->view()->text->CursorUp(owner->view());
1535 owner->view()->text->FinishUndo();
1536 moveCursorUpdate(false);
1541 if (!owner->view()->text->mark_set)
1542 owner->view()->beforeChange();
1543 owner->view()->update(BufferView::UPDATE);
1544 owner->view()->text->CursorDown(owner->view());
1545 owner->view()->text->FinishUndo();
1546 moveCursorUpdate(false);
1550 case LFUN_UP_PARAGRAPH:
1551 if (!owner->view()->text->mark_set)
1552 owner->view()->beforeChange();
1553 owner->view()->update(BufferView::UPDATE);
1554 owner->view()->text->CursorUpParagraph(owner->view());
1555 owner->view()->text->FinishUndo();
1556 moveCursorUpdate(false);
1560 case LFUN_DOWN_PARAGRAPH:
1561 if (!owner->view()->text->mark_set)
1562 owner->view()->beforeChange();
1563 owner->view()->update(BufferView::UPDATE);
1564 owner->view()->text->CursorDownParagraph(owner->view());
1565 owner->view()->text->FinishUndo();
1566 moveCursorUpdate(false);
1571 if (!text->mark_set)
1572 owner->view()->beforeChange();
1573 owner->view()->update(BufferView::UPDATE);
1574 owner->view()->cursorPrevious(text);
1575 owner->view()->text->FinishUndo();
1576 if (text->inset_owner)
1577 owner->view()->updateInset(text->inset_owner, false);
1579 moveCursorUpdate(false);
1584 if (!text->mark_set)
1585 owner->view()->beforeChange();
1586 owner->view()->update(BufferView::UPDATE);
1587 owner->view()->cursorNext(text);
1588 owner->view()->text->FinishUndo();
1589 if (text->inset_owner)
1590 owner->view()->updateInset(text->inset_owner, false);
1592 moveCursorUpdate(false);
1597 if (!owner->view()->text->mark_set)
1598 owner->view()->beforeChange();
1599 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1600 owner->view()->text->CursorHome(owner->view());
1601 owner->view()->text->FinishUndo();
1602 moveCursorUpdate(false);
1607 if (!owner->view()->text->mark_set)
1608 owner->view()->beforeChange();
1609 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1610 owner->view()->text->CursorEnd(owner->view());
1611 owner->view()->text->FinishUndo();
1612 moveCursorUpdate(false);
1616 case LFUN_SHIFT_TAB:
1618 if (!owner->view()->text->mark_set)
1619 owner->view()->beforeChange();
1620 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1621 owner->view()->text->CursorTab(owner->view());
1622 owner->view()->text->FinishUndo();
1623 moveCursorUpdate(false);
1627 case LFUN_WORDRIGHT:
1628 if (!text->mark_set)
1629 owner->view()->beforeChange();
1630 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1631 if (text->cursor.par()->isRightToLeftPar(owner->buffer()->params))
1632 text->CursorLeftOneWord(owner->view());
1634 text->CursorRightOneWord(owner->view());
1635 owner->view()->text->FinishUndo();
1636 if (text->inset_owner)
1637 owner->view()->updateInset(text->inset_owner, true);
1638 moveCursorUpdate(false);
1643 if (!text->mark_set)
1644 owner->view()->beforeChange();
1645 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1646 if (text->cursor.par()->isRightToLeftPar(owner->buffer()->params))
1647 text->CursorRightOneWord(owner->view());
1649 text->CursorLeftOneWord(owner->view());
1650 owner->view()->text->FinishUndo();
1651 if (text->inset_owner)
1652 owner->view()->updateInset(text->inset_owner, true);
1653 moveCursorUpdate(false);
1657 case LFUN_BEGINNINGBUF:
1658 if (!owner->view()->text->mark_set)
1659 owner->view()->beforeChange();
1660 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1661 owner->view()->text->CursorTop(owner->view());
1662 owner->view()->text->FinishUndo();
1663 moveCursorUpdate(false);
1668 if (!owner->view()->text->mark_set)
1669 owner->view()->beforeChange();
1670 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1671 owner->view()->text->CursorBottom(owner->view());
1672 owner->view()->text->FinishUndo();
1673 moveCursorUpdate(false);
1678 /* cursor selection ---------------------------- */
1680 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1681 if (owner->view()->text->cursor.par()->isRightToLeftPar(owner->buffer()->params))
1682 owner->view()->text->CursorLeft(owner->view());
1684 owner->view()->text->CursorRight(owner->view());
1685 owner->view()->text->FinishUndo();
1686 moveCursorUpdate(true);
1691 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1692 if (owner->view()->text->cursor.par()->isRightToLeftPar(owner->buffer()->params))
1693 owner->view()->text->CursorRight(owner->view());
1695 owner->view()->text->CursorLeft(owner->view());
1696 owner->view()->text->FinishUndo();
1697 moveCursorUpdate(true);
1702 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1703 owner->view()->text->CursorUp(owner->view());
1704 owner->view()->text->FinishUndo();
1705 moveCursorUpdate(true);
1710 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1711 owner->view()->text->CursorDown(owner->view());
1712 owner->view()->text->FinishUndo();
1713 moveCursorUpdate(true);
1717 case LFUN_UP_PARAGRAPHSEL:
1718 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1719 owner->view()->text->CursorUpParagraph(owner->view());
1720 owner->view()->text->FinishUndo();
1721 moveCursorUpdate(true);
1725 case LFUN_DOWN_PARAGRAPHSEL:
1726 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1727 owner->view()->text->CursorDownParagraph(owner->view());
1728 owner->view()->text->FinishUndo();
1729 moveCursorUpdate(true);
1734 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1735 owner->view()->cursorPrevious(text);
1736 owner->view()->text->FinishUndo();
1737 if (text->inset_owner)
1738 owner->view()->updateInset(text->inset_owner, false);
1740 moveCursorUpdate(true);
1745 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1746 owner->view()->cursorNext(text);
1747 owner->view()->text->FinishUndo();
1748 if (text->inset_owner)
1749 owner->view()->updateInset(text->inset_owner, false);
1751 moveCursorUpdate(true);
1756 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1757 owner->view()->text->CursorHome(owner->view());
1758 owner->view()->text->FinishUndo();
1759 moveCursorUpdate(true);
1764 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1765 owner->view()->text->CursorEnd(owner->view());
1766 owner->view()->text->FinishUndo();
1767 moveCursorUpdate(true);
1771 case LFUN_WORDRIGHTSEL:
1772 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1773 if (owner->view()->text->cursor.par()->isRightToLeftPar(owner->buffer()->params))
1774 owner->view()->text->CursorLeftOneWord(owner->view());
1776 owner->view()->text->CursorRightOneWord(owner->view());
1777 owner->view()->text->FinishUndo();
1778 moveCursorUpdate(true);
1782 case LFUN_WORDLEFTSEL:
1783 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1784 if (owner->view()->text->cursor.par()->isRightToLeftPar(owner->buffer()->params))
1785 owner->view()->text->CursorRightOneWord(owner->view());
1787 owner->view()->text->CursorLeftOneWord(owner->view());
1788 owner->view()->text->FinishUndo();
1789 moveCursorUpdate(true);
1793 case LFUN_BEGINNINGBUFSEL:
1794 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1795 owner->view()->text->CursorTop(owner->view());
1796 owner->view()->text->FinishUndo();
1797 moveCursorUpdate(true);
1801 case LFUN_ENDBUFSEL:
1802 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1803 owner->view()->text->CursorBottom(owner->view());
1804 owner->view()->text->FinishUndo();
1805 moveCursorUpdate(true);
1809 // --- text changing commands ------------------------
1810 case LFUN_BREAKLINE:
1811 owner->view()->beforeChange();
1812 owner->view()->text->InsertChar(owner->view(), LyXParagraph::META_NEWLINE);
1813 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1814 moveCursorUpdate(false);
1817 case LFUN_PROTECTEDSPACE:
1819 LyXLayout const & style =
1820 textclasslist.Style(owner->view()->buffer()->params.textclass,
1821 owner->view()->text->cursor.par()->GetLayout());
1823 if (style.free_spacing) {
1824 owner->view()->text->InsertChar(owner->view(), ' ');
1825 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1827 owner->view()->protectedBlank();
1829 moveCursorUpdate(false);
1834 if (text->mark_set) {
1835 owner->view()->beforeChange();
1836 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1837 setMessage(N_("Mark removed"));
1839 owner->view()->beforeChange();
1841 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1842 setMessage(N_("Mark set"));
1844 text->sel_cursor = text->cursor;
1845 if (text->inset_owner)
1846 owner->view()->updateInset(text->inset_owner, true);
1850 if (!owner->view()->text->selection) {
1851 owner->view()->text->Delete(owner->view());
1852 owner->view()->text->sel_cursor =
1853 owner->view()->text->cursor;
1854 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1855 // It is possible to make it a lot faster still
1856 // just comment out the line below...
1857 owner->view()->showCursor();
1859 owner->view()->cut();
1861 moveCursorUpdate(false);
1863 owner->view()->setState();
1866 case LFUN_DELETE_SKIP:
1868 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1870 LyXCursor cursor = owner->view()->text->cursor;
1872 if (!owner->view()->text->selection) {
1873 if (cursor.pos() == cursor.par()->Last()) {
1874 owner->view()->text->CursorRight(owner->view());
1875 cursor = owner->view()->text->cursor;
1876 if (cursor.pos() == 0
1877 && !(cursor.par()->added_space_top
1878 == VSpace (VSpace::NONE))) {
1879 owner->view()->text->SetParagraph
1881 cursor.par()->line_top,
1882 cursor.par()->line_bottom,
1883 cursor.par()->pagebreak_top,
1884 cursor.par()->pagebreak_bottom,
1885 VSpace(VSpace::NONE),
1886 cursor.par()->added_space_bottom,
1887 cursor.par()->align,
1888 cursor.par()->labelwidthstring, 0);
1889 owner->view()->text->CursorLeft(owner->view());
1890 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1892 owner->view()->text->CursorLeft(owner->view());
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()->text->Delete(owner->view());
1900 owner->view()->text->sel_cursor =
1901 owner->view()->text->cursor;
1902 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1905 owner->view()->cut();
1910 /* -------> Delete word forward. */
1911 case LFUN_DELETE_WORD_FORWARD:
1912 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1913 text->DeleteWordForward(owner->view());
1914 if (text->inset_owner)
1915 owner->view()->updateInset(text->inset_owner, true);
1916 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1917 moveCursorUpdate(false);
1921 /* -------> Delete word backward. */
1922 case LFUN_DELETE_WORD_BACKWARD:
1923 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1924 text->DeleteWordBackward(owner->view());
1925 if (text->inset_owner)
1926 owner->view()->updateInset(text->inset_owner, true);
1927 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1928 moveCursorUpdate(false);
1932 /* -------> Kill to end of line. */
1933 case LFUN_DELETE_LINE_FORWARD:
1934 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1935 text->DeleteLineForward(owner->view());
1936 if (text->inset_owner)
1937 owner->view()->updateInset(text->inset_owner, true);
1938 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1939 moveCursorUpdate(false);
1942 /* -------> Set mark off. */
1944 owner->view()->beforeChange();
1945 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1946 text->sel_cursor = text->cursor;
1947 setMessage(N_("Mark off"));
1948 if (text->inset_owner)
1949 owner->view()->updateInset(text->inset_owner, true);
1952 /* -------> Set mark on. */
1954 owner->view()->beforeChange();
1955 owner->view()->text->mark_set = 1;
1956 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1957 text->sel_cursor = text->cursor;
1958 if (text->inset_owner)
1959 owner->view()->updateInset(text->inset_owner, true);
1960 setMessage(N_("Mark on"));
1963 case LFUN_BACKSPACE:
1965 if (!owner->view()->text->selection) {
1967 if (owner->getIntl()->getTrans()->backspace()) {
1969 if (owner->getIntl()->getTrans().backspace()) {
1971 owner->view()->text->Backspace(owner->view());
1972 owner->view()->text->sel_cursor =
1973 owner->view()->text->cursor;
1974 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1975 // It is possible to make it a lot faster still
1976 // just comment out the line below...
1977 owner->view()->showCursor();
1980 owner->view()->cut();
1983 owner->view()->setState();
1987 case LFUN_BACKSPACE_SKIP:
1989 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1991 LyXCursor cursor = owner->view()->text->cursor;
1993 if (!owner->view()->text->selection) {
1994 if (cursor.pos() == 0
1995 && !(cursor.par()->added_space_top
1996 == VSpace (VSpace::NONE))) {
1997 owner->view()->text->SetParagraph
1999 cursor.par()->line_top,
2000 cursor.par()->line_bottom,
2001 cursor.par()->pagebreak_top,
2002 cursor.par()->pagebreak_bottom,
2003 VSpace(VSpace::NONE), cursor.par()->added_space_bottom,
2004 cursor.par()->align,
2005 cursor.par()->labelwidthstring, 0);
2006 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2008 owner->view()->text->Backspace(owner->view());
2009 owner->view()->text->sel_cursor
2011 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2014 owner->view()->cut();
2018 case LFUN_BREAKPARAGRAPH:
2020 owner->view()->beforeChange();
2021 owner->view()->text->BreakParagraph(owner->view(), 0);
2022 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2023 owner->view()->text->sel_cursor =
2024 owner->view()->text->cursor;
2025 owner->view()->setState();
2030 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2032 owner->view()->beforeChange();
2033 owner->view()->text->BreakParagraph(owner->view(), 1);
2034 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2035 owner->view()->text->sel_cursor =
2036 owner->view()->text->cursor;
2037 owner->view()->setState();
2042 case LFUN_BREAKPARAGRAPH_SKIP:
2044 // When at the beginning of a paragraph, remove
2045 // indentation and add a "defskip" at the top.
2046 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2048 LyXCursor cursor = owner->view()->text->cursor;
2050 owner->view()->beforeChange();
2051 if (cursor.pos() == 0) {
2052 if (cursor.par()->added_space_top == VSpace(VSpace::NONE)) {
2053 owner->view()->text->SetParagraph
2055 cursor.par()->line_top,
2056 cursor.par()->line_bottom,
2057 cursor.par()->pagebreak_top,
2058 cursor.par()->pagebreak_bottom,
2059 VSpace(VSpace::DEFSKIP), cursor.par()->added_space_bottom,
2060 cursor.par()->align,
2061 cursor.par()->labelwidthstring, 1);
2062 //owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2066 owner->view()->text->BreakParagraph(owner->view(), 0);
2067 //owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2070 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2071 owner->view()->text->sel_cursor = cursor;
2072 owner->view()->setState();
2077 case LFUN_PARAGRAPH_SPACING:
2079 LyXParagraph * par = owner->view()->text->cursor.par();
2080 Spacing::Space cur_spacing = par->spacing.getSpace();
2081 float cur_value = 1.0;
2082 if (cur_spacing == Spacing::Other) {
2083 cur_value = par->spacing.getValue();
2086 istringstream istr(argument.c_str());
2090 Spacing::Space new_spacing = cur_spacing;
2091 float new_value = cur_value;
2093 lyxerr << "Missing argument to `paragraph-spacing'"
2095 } else if (tmp == "single") {
2096 new_spacing = Spacing::Single;
2097 } else if (tmp == "onehalf") {
2098 new_spacing = Spacing::Onehalf;
2099 } else if (tmp == "double") {
2100 new_spacing = Spacing::Double;
2101 } else if (tmp == "other") {
2102 new_spacing = Spacing::Other;
2105 lyxerr << "new_value = " << tmpval << endl;
2108 } else if (tmp == "default") {
2109 new_spacing = Spacing::Default;
2111 lyxerr << _("Unknown spacing argument: ")
2112 << argument << endl;
2114 if (cur_spacing != new_spacing || cur_value != new_value) {
2115 par->spacing.set(new_spacing, new_value);
2116 owner->view()->text->RedoParagraph(owner->view());
2117 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2123 owner->view()->beforeChange();
2124 owner->view()->text->InsertChar(owner->view(), '\"'); // This " matches the single quote in the code
2125 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2126 moveCursorUpdate(false);
2132 InsetCommandParams p;
2133 if (action == LFUN_HTMLURL)
2134 p.setCmdName("htmlurl");
2136 p.setCmdName("url");
2137 owner->getDialogs()->createUrl( p.getAsString() );
2141 case LFUN_INSERT_URL:
2143 InsetCommandParams p;
2144 p.setFromString( argument );
2146 InsetUrl * inset = new InsetUrl( p );
2147 if (!owner->view()->insertInset(inset))
2150 owner->view()->updateInset( inset, true );
2154 case LFUN_INSET_TEXT:
2156 InsetText * new_inset = new InsetText;
2157 if (owner->view()->insertInset(new_inset))
2158 new_inset->Edit(owner->view(), 0, 0, 0);
2164 case LFUN_INSET_ERT:
2166 InsetERT * new_inset = new InsetERT;
2167 if (owner->view()->insertInset(new_inset))
2168 new_inset->Edit(owner->view(), 0, 0, 0);
2174 case LFUN_INSET_EXTERNAL:
2176 InsetExternal * new_inset = new InsetExternal;
2177 if (owner->view()->insertInset(new_inset))
2178 new_inset->Edit(owner->view(), 0, 0, 0);
2184 case LFUN_INSET_FOOTNOTE:
2186 InsetFoot * new_inset = new InsetFoot;
2187 if (owner->view()->insertInset(new_inset))
2188 new_inset->Edit(owner->view(), 0, 0, 0);
2194 case LFUN_INSET_MARGINAL:
2196 InsetMarginal * new_inset = new InsetMarginal;
2197 if (owner->view()->insertInset(new_inset))
2198 new_inset->Edit(owner->view(), 0, 0, 0);
2204 case LFUN_INSET_MINIPAGE:
2206 InsetMinipage * new_inset = new InsetMinipage;
2207 if (owner->view()->insertInset(new_inset))
2208 new_inset->Edit(owner->view(), 0, 0, 0);
2214 case LFUN_INSET_FLOAT:
2216 // check if the float type exist
2217 if (floatList.typeExist(argument)) {
2218 InsetFloat * new_inset = new InsetFloat(argument);
2219 if (owner->view()->insertInset(new_inset))
2220 new_inset->Edit(owner->view(), 0, 0, 0);
2224 lyxerr << "Non-existant float type: "
2225 << argument << endl;
2231 case LFUN_INSET_LIST:
2233 InsetList * new_inset = new InsetList;
2234 if (owner->view()->insertInset(new_inset))
2235 new_inset->Edit(owner->view(), 0, 0, 0);
2241 case LFUN_INSET_THEOREM:
2243 InsetTheorem * new_inset = new InsetTheorem;
2244 if (owner->view()->insertInset(new_inset))
2245 new_inset->Edit(owner->view(), 0, 0, 0);
2251 case LFUN_INSET_CAPTION:
2253 // Do we have a locking inset...
2254 if (owner->view()->theLockingInset()) {
2255 lyxerr << "Locking inset code: "
2256 << static_cast<int>(owner->view()->theLockingInset()->LyxCode());
2257 InsetCaption * new_inset = new InsetCaption;
2258 new_inset->setOwner(owner->view()->theLockingInset());
2259 new_inset->SetAutoBreakRows(true);
2260 new_inset->SetDrawFrame(0, InsetText::LOCKED);
2261 new_inset->SetFrameColor(0, LColor::footnoteframe);
2262 if (owner->view()->insertInset(new_inset))
2263 new_inset->Edit(owner->view(), 0, 0, 0);
2270 case LFUN_INSET_TABULAR:
2273 if (!argument.empty())
2274 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2275 InsetTabular * new_inset =
2276 new InsetTabular(*owner->buffer(), r, c);
2278 owner->view()->getLyXText()->real_current_font.isRightToLeft();
2279 if (!owner->view()->open_new_inset(new_inset, rtl))
2284 // --- lyxserver commands ----------------------------
2286 case LFUN_CHARATCURSOR:
2288 LyXParagraph::size_type pos =
2289 owner->view()->text->cursor.pos();
2290 if (pos < owner->view()->text->cursor.par()->size())
2291 //dispatch_buffer = owner->view()->text->
2292 // cursor.par()->text[pos];
2294 owner->view()->text->
2295 cursor.par()->GetChar(pos);
2297 dispatch_buffer = "EOF";
2303 tostr(owner->view()->text->cursor.x()) + ' '
2304 + tostr(owner->view()->text->cursor.y());
2311 ::sscanf(argument.c_str(), " %d %d", &x, &y);
2312 owner->view()->text->SetCursorFromCoordinates(owner->view(), x, y);
2316 case LFUN_GETLAYOUT:
2318 tostr(owner->view()->text->cursor.par()->layout);
2323 LyXFont & font = owner->view()->text->current_font;
2324 if (font.shape() == LyXFont::ITALIC_SHAPE)
2325 dispatch_buffer = 'E';
2326 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2327 dispatch_buffer = 'N';
2329 dispatch_buffer = '0';
2336 LyXFont & font = owner->view()->text->current_font;
2337 if (font.latex() == LyXFont::ON)
2338 dispatch_buffer = 'L';
2340 dispatch_buffer = '0';
2345 setMessage(owner->buffer()->fileName());
2346 lyxerr.debug() << "FNAME["
2347 << owner->buffer()->fileName()
2355 dispatch_buffer = buf;
2356 lyxserver->notifyClient(dispatch_buffer);
2360 case LFUN_GOTOFILEROW:
2362 char file_name[100];
2364 ::sscanf(argument.c_str(), " %s %d", file_name, &row);
2366 // Must replace extension of the file to be .lyx and get full path
2367 string s = ChangeExtension(string(file_name), ".lyx");
2369 // Either change buffer or load the file
2370 if (bufferlist.exists(s))
2371 owner->view()->buffer(bufferlist.getBuffer(s));
2373 owner->view()->buffer(bufferlist.loadLyXFile(s));
2376 owner->view()->setCursorFromRow(row);
2379 owner->view()->center();
2383 case LFUN_GOTO_PARAGRAPH:
2385 istringstream istr(argument.c_str());
2389 LyXParagraph * par = owner->view()->text->GetParFromID(id);
2392 owner->view()->text->SetCursor(owner->view(), par, 0);
2393 owner->view()->setState();
2397 owner->view()->center();
2404 int const qa = lyxaction.LookupFunc(argument);
2405 setMessage(lyxaction.helpText(static_cast<kb_action>(qa)));
2409 // --- accented characters ---------------------------
2412 case LFUN_CIRCUMFLEX:
2422 case LFUN_SPECIAL_CARON:
2425 case LFUN_HUNG_UMLAUT:
2431 if (keyseq.length == -1 && keyseq.getiso() != 0)
2432 c = keyseq.getiso();
2435 owner->getIntl()->getTrans()->
2436 deadkey(c, get_accent(action).accent,
2437 owner->view()->text);
2439 owner->getIntl()->getTrans()
2440 .deadkey(c, get_accent(action).accent,
2441 owner->view()->text);
2444 // Need to reset, in case the minibuffer calls these
2449 // copied verbatim from do_accent_char
2450 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2452 owner->view()->text->sel_cursor =
2453 owner->view()->text->cursor;
2457 // --- toolbar ----------------------------------
2458 case LFUN_PUSH_TOOLBAR:
2460 int nth = strToInt(argument);
2462 setErrorMessage(N_("Push-toolbar needs argument > 0"));
2464 owner->getToolbar()->push(nth);
2469 case LFUN_ADD_TO_TOOLBAR:
2471 if (lyxerr.debugging(Debug::GUI)) {
2472 lyxerr << "LFUN_ADD_TO_TOOLBAR:"
2473 "argument = `" << argument << '\'' << endl;
2475 string tmp(argument);
2476 //lyxerr <<string("Argument: ") + argument);
2477 //lyxerr <<string("Tmp : ") + tmp);
2479 setErrorMessage(N_("Usage: toolbar-add-to <LyX command>"));
2481 owner->getToolbar()->add(argument, false);
2482 owner->getToolbar()->set();
2487 // --- insert characters ----------------------------------------
2489 // --- Mathed stuff. If we are here, there is no locked inset yet.
2494 if (!greek_kb_flag) {
2496 setMessage(N_("Math greek mode on"));
2503 case LFUN_GREEK_TOGGLE:
2505 greek_kb_flag = greek_kb_flag ? 0 : 2;
2506 if (greek_kb_flag) {
2507 setMessage(N_("Math greek keyboard on"));
2509 setMessage(N_("Math greek keyboard off"));
2514 case LFUN_MATH_DELIM:
2515 case LFUN_INSERT_MATRIX:
2517 if (owner->view()->available()) {
2519 open_new_inset(new InsetFormula(false)))
2521 owner->view()->theLockingInset()
2522 ->LocalDispatch(owner->view(),
2530 case LFUN_INSERT_MATH:
2532 math_insert_symbol(owner->view(), argument);
2536 case LFUN_MATH_DISPLAY:
2538 if (owner->view()->available())
2539 owner->view()->open_new_inset(new InsetFormula(true));
2543 case LFUN_MATH_MACRO:
2545 if (owner->view()->available()) {
2548 setErrorMessage(N_("Missing argument"));
2550 string const s1 = token(s, ' ', 1);
2551 int const na = s1.empty() ? 0 : lyx::atoi(s1);
2553 open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2559 case LFUN_MATH_MODE: // Open or create a math inset
2561 if (owner->view()->available())
2562 owner->view()->open_new_inset(new InsetFormula);
2563 setMessage(N_("Math editor mode"));
2567 case LFUN_MATH_NUMBER:
2568 case LFUN_MATH_LIMITS:
2570 setErrorMessage(N_("This is only allowed in math mode!"));
2575 case LFUN_MATH_PANEL:
2577 show_symbols_form(this);
2581 case LFUN_CITATION_CREATE:
2583 InsetCommandParams p( "cite" );
2585 if (!argument.empty()) {
2586 // This should be set at source, ie when typing
2587 // "citation-insert foo" in the minibuffer.
2588 // Question: would pybibliographer also need to be
2589 // changed. Suspect so. Leave as-is therefore.
2590 if (contains(argument, "|")) {
2591 p.setContents( token(argument, '|', 0) );
2592 p.setOptions( token(argument, '|', 1) );
2594 p.setContents( argument );
2596 Dispatch(LFUN_CITATION_INSERT, p.getAsString());
2598 owner->getDialogs()->createCitation( p.getAsString() );
2602 case LFUN_CITATION_INSERT:
2604 InsetCommandParams p;
2605 p.setFromString( argument );
2607 InsetCitation * inset = new InsetCitation( p );
2608 if (!owner->view()->insertInset(inset))
2611 owner->view()->updateInset( inset, true );
2615 case LFUN_INSERT_BIBTEX:
2617 // ale970405+lasgoutt970425
2618 // The argument can be up to two tokens separated
2619 // by a space. The first one is the bibstyle.
2620 string const db = token(argument, ' ', 0);
2621 string bibstyle = token(argument, ' ', 1);
2622 if (bibstyle.empty())
2625 InsetCommandParams p( "BibTeX", db, bibstyle );
2626 InsetBibtex * inset = new InsetBibtex(p);
2628 if (owner->view()->insertInset(inset)) {
2629 if (argument.empty())
2630 inset->Edit(owner->view(), 0, 0, 0);
2636 // BibTeX data bases
2637 case LFUN_BIBDB_ADD:
2639 InsetBibtex * inset =
2640 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2642 inset->addDatabase(argument);
2647 case LFUN_BIBDB_DEL:
2649 InsetBibtex * inset =
2650 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2652 inset->delDatabase(argument);
2657 case LFUN_BIBTEX_STYLE:
2659 InsetBibtex * inset =
2660 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2662 inset->setOptions(argument);
2667 case LFUN_INDEX_CREATE:
2669 InsetCommandParams p( "index" );
2671 if (argument.empty()) {
2672 // Get the word immediately preceding the cursor
2673 LyXParagraph::size_type curpos =
2674 owner->view()->text->cursor.pos() - 1;
2678 curstring = owner->view()->text
2679 ->cursor.par()->GetWord(curpos);
2681 p.setContents( curstring );
2683 p.setContents( argument );
2686 owner->getDialogs()->createIndex( p.getAsString() );
2690 case LFUN_INDEX_INSERT:
2692 InsetCommandParams p;
2693 p.setFromString(argument);
2694 InsetIndex * inset = new InsetIndex(p);
2696 if (!owner->view()->insertInset(inset))
2699 owner->view()->updateInset(inset, true);
2703 case LFUN_INDEX_INSERT_LAST:
2705 // Get word immediately preceding the cursor
2706 LyXParagraph::size_type curpos =
2707 owner->view()->text->cursor.pos() - 1;
2708 // Can't do that at the beginning of a paragraph
2709 if (curpos < 0) break;
2711 string const curstring(owner->view()->text
2712 ->cursor.par()->GetWord(curpos));
2714 InsetCommandParams p("index", curstring);
2715 InsetIndex * inset = new InsetIndex(p);
2717 if (!owner->view()->insertInset(inset))
2720 owner->view()->updateInset(inset, true);
2724 case LFUN_INDEX_PRINT:
2726 InsetCommandParams p("printindex");
2727 Inset * inset = new InsetPrintIndex(p);
2728 if (!owner->view()->insertInset(inset, "Standard", true))
2733 case LFUN_PARENTINSERT:
2735 lyxerr << "arg " << argument << endl;
2736 InsetCommandParams p( "lyxparent", argument );
2737 Inset * inset = new InsetParent(p, *owner->buffer());
2738 if (!owner->view()->insertInset(inset, "Standard", true))
2743 case LFUN_CHILDINSERT:
2745 InsetCommandParams p( "Include", argument );
2746 Inset * inset = new InsetInclude(p, *owner->buffer());
2747 if (owner->view()->insertInset(inset, "Standard", true))
2748 inset->Edit(owner->view(), 0, 0, 0);
2754 case LFUN_CHILDOPEN:
2756 string const filename =
2757 MakeAbsPath(argument,
2758 OnlyPath(owner->buffer()->fileName()));
2759 setMessage(N_("Opening child document ") +
2760 MakeDisplayPath(filename) + "...");
2761 owner->view()->savePosition();
2762 if (bufferlist.exists(filename))
2763 owner->view()->buffer(bufferlist.getBuffer(filename));
2765 owner->view()->buffer(bufferlist.loadLyXFile(filename));
2769 case LFUN_INSERT_NOTE:
2770 owner->view()->insertNote();
2773 case LFUN_INSERTFOOTNOTE:
2775 LyXParagraph::footnote_kind kind;
2776 if (argument == "footnote") {
2777 kind = LyXParagraph::FOOTNOTE;
2778 } else if (argument == "margin") {
2779 kind = LyXParagraph::MARGIN;
2780 } else if (argument == "figure") {
2781 kind = LyXParagraph::FIG;
2782 } else if (argument == "table") {
2783 kind = LyXParagraph::TAB;
2784 } else if (argument == "wide-fig") {
2785 kind = LyXParagraph::WIDE_FIG;
2786 } else if (argument == "wide-tab") {
2787 kind = LyXParagraph::WIDE_TAB;
2788 } else if (argument == "algorithm") {
2789 kind = LyXParagraph::ALGORITHM;
2791 setErrorMessage(N_("Unknown kind of footnote"));
2794 owner->view()->text->InsertFootnoteEnvironment(owner->view(), kind);
2795 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2796 owner->view()->setState();
2800 case LFUN_TOGGLECURSORFOLLOW:
2801 lyxrc.cursor_follows_scrollbar = !lyxrc.cursor_follows_scrollbar;
2804 case LFUN_KMAP_OFF: // keymap off
2805 owner->getIntl()->KeyMapOn(false);
2808 case LFUN_KMAP_PRIM: // primary keymap
2809 owner->getIntl()->KeyMapPrim();
2812 case LFUN_KMAP_SEC: // secondary keymap
2813 owner->getIntl()->KeyMapSec();
2816 case LFUN_KMAP_TOGGLE: // toggle keymap
2817 owner->getIntl()->ToggleKeyMap();
2820 case LFUN_SELFINSERT:
2822 LyXFont const old_font(owner->view()->text->real_current_font);
2823 for (string::size_type i = 0; i < argument.length(); ++i) {
2824 owner->view()->text->InsertChar(owner->view(), argument[i]);
2825 // This needs to be in the loop, or else we
2826 // won't break lines correctly. (Asger)
2827 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2829 owner->view()->text->sel_cursor =
2830 owner->view()->text->cursor;
2831 moveCursorUpdate(false);
2833 // real_current_font.number can change so we need to
2834 // update the minibuffer
2835 if (old_font != owner->view()->text->real_current_font)
2842 // argument contains ';'-terminated commands
2843 while (argument.find(';') != string::npos) {
2845 argument = split(argument, first, ';');
2851 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
2855 time_t now_time_t = time(NULL);
2856 now_tm = localtime(&now_time_t);
2857 setlocale(LC_TIME, "");
2859 if (!argument.empty())
2862 arg = lyxrc.date_insert_format;
2864 int const datetmp_len =
2865 ::strftime(datetmp, 32, arg.c_str(), now_tm);
2866 for (int i = 0; i < datetmp_len; i++) {
2867 owner->view()->text->InsertChar(owner->view(), datetmp[i]);
2868 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2871 owner->view()->text->sel_cursor = owner->view()->text->cursor;
2872 moveCursorUpdate(false);
2876 case LFUN_DIALOG_PREFERENCES:
2877 owner->getDialogs()->showPreferences();
2880 case LFUN_SAVEPREFERENCES:
2882 Path p(user_lyxdir);
2883 lyxrc.write("preferences");
2887 case LFUN_SCREEN_FONT_UPDATE:
2889 // handle the screen font changes.
2891 lyxrc.set_font_norm_type();
2892 fontloader.update();
2893 // Of course we should only do the resize and the textcache.clear
2894 // if values really changed...but not very important right now. (Lgb)
2895 // All buffers will need resize
2896 bufferlist.resize();
2897 // We also need to empty the textcache so that
2898 // the buffer will be formatted correctly after
2904 case LFUN_SET_COLOR:
2907 string const x11_name = split(argument, lyx_name, ' ');
2908 if (lyx_name.empty() || x11_name.empty()) {
2910 setErrorMessage(N_("Syntax: set-color <lyx_name>"
2915 if (!lcolor.setColor(lyx_name, x11_name)) {
2916 static string const err1 (N_("Set-color \""));
2917 static string const err2 (
2918 N_("\" failed - color is undefined "
2919 "or may not be redefined"));
2921 setErrorMessage(_(err1) + lyx_name + _(err2));
2924 lyxColorHandler->updateColor(lcolor.getFromLyXName(lyx_name));
2925 owner->view()->redraw();
2929 case LFUN_UNKNOWN_ACTION:
2931 if (!owner->buffer()) {
2933 setErrorMessage(N_("No document open"));
2937 if (owner->buffer()->isReadonly()) {
2939 setErrorMessage(N_("Document is read only"));
2943 if (!argument.empty()) {
2945 /* Automatically delete the currently selected
2946 * text and replace it with what is being
2947 * typed in now. Depends on lyxrc settings
2948 * "auto_region_delete", which defaults to
2951 if (lyxrc.auto_region_delete) {
2952 if (owner->view()->text->selection){
2953 owner->view()->text->CutSelection(owner->view(), false);
2954 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2958 owner->view()->beforeChange();
2959 LyXFont const old_font(owner->view()->text->real_current_font);
2960 for (string::size_type i = 0;
2961 i < argument.length(); ++i) {
2962 if (greek_kb_flag) {
2963 if (!math_insert_greek(owner->view(),
2966 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2968 owner->getIntl()->getTrans().TranslateAndInsert(argument[i], owner->view()->text);
2972 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2974 owner->getIntl()->getTrans().TranslateAndInsert(argument[i], owner->view()->text);
2978 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2980 owner->view()->text->sel_cursor =
2981 owner->view()->text->cursor;
2982 moveCursorUpdate(false);
2984 // real_current_font.number can change so we need to
2985 // update the minibuffer
2986 if (old_font != owner->view()->text->real_current_font)
2990 // why is an "Unknown action" with empty
2991 // argument even dispatched in the first
2992 // place? I`ll probably change that. (Lgb)
2994 setErrorMessage(N_("Unknown action"));
3000 lyxerr << "A truly unknown func!" << endl;
3005 string const res = getMessage();
3008 if (!commandshortcut.empty()) {
3009 string const newbuf =
3010 owner->getMiniBuffer()->GetText();
3011 if (newbuf != commandshortcut) {
3012 owner->getMiniBuffer()->Set(newbuf
3020 msg += commandshortcut;
3021 owner->getMiniBuffer()->Set(msg);
3028 void LyXFunc::setupLocalKeymap()
3030 keyseq.stdmap = keyseq.curmap = toplevel_keymap;
3031 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap;
3035 void LyXFunc::MenuNew(bool fromTemplate)
3037 string initpath = lyxrc.document_path;
3040 if (owner->view()->available()) {
3041 string const trypath = owner->buffer()->filepath;
3042 // If directory is writeable, use this as default.
3043 if (IsDirWriteable(trypath) == 1)
3047 static int newfile_number = 0;
3050 if (lyxrc.new_ask_filename) {
3051 ProhibitInput(owner->view());
3052 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
3053 fileDlg.SetButton(1, _("Templates"), lyxrc.template_path);
3054 string fname = fileDlg.Select(_("Enter Filename for new document"),
3055 initpath, "*.lyx", _("newfile"));
3056 AllowInput(owner->view());
3058 if (fname.empty()) {
3059 owner->getMiniBuffer()->Set(_("Canceled."));
3060 lyxerr.debug() << "New Document Cancelled." << endl;
3064 // get absolute path of file and make sure the filename ends
3066 s = MakeAbsPath(fname);
3067 if (!IsLyXFilename(s))
3070 // Check if the document already is open
3071 if (bufferlist.exists(s)) {
3072 switch (AskConfirmation(_("Document is already open:"),
3073 MakeDisplayPath(s, 50),
3074 _("Do you want to close that document now?\n"
3075 "('No' will just switch to the open version)")))
3077 case 1: // Yes: close the document
3078 if (!bufferlist.close(bufferlist.getBuffer(s)))
3079 // If close is canceled, we cancel here too.
3082 case 2: // No: switch to the open document
3083 owner->view()->buffer(bufferlist.getBuffer(s));
3085 case 3: // Cancel: Do nothing
3086 owner->getMiniBuffer()->Set(_("Canceled."));
3090 // Check whether the file already exists
3091 if (IsLyXFilename(s)) {
3093 if (fi.readable() &&
3094 AskQuestion(_("File already exists:"),
3095 MakeDisplayPath(s, 50),
3096 _("Do you want to open the document?"))) {
3098 owner->getMiniBuffer()->Set(_("Opening document"),
3099 MakeDisplayPath(s), "...");
3100 XFlush(fl_get_display());
3101 owner->view()->buffer(
3102 bufferlist.loadLyXFile(s));
3103 owner->getMiniBuffer()->Set(_("Document"),
3110 s = AddName(lyxrc.document_path,
3111 "newfile" + tostr(++newfile_number) + ".lyx");
3113 while (bufferlist.exists(s) || fi.readable()) {
3115 s = AddName(lyxrc.document_path,
3116 "newfile" + tostr(newfile_number) +
3122 // The template stuff
3125 ProhibitInput(owner->view());
3126 string const fname = fileDlg.Select(_("Choose template"),
3127 lyxrc.template_path,
3129 AllowInput(owner->view());
3130 if (fname.empty()) return;
3134 // find a free buffer
3135 lyxerr.debug() << "Find a free buffer." << endl;
3136 owner->view()->buffer(bufferlist.newFile(s, templname));
3140 void LyXFunc::MenuOpen()
3142 string initpath = lyxrc.document_path;
3145 if (owner->view()->available()) {
3146 string const trypath = owner->buffer()->filepath;
3147 // If directory is writeable, use this as default.
3148 if (IsDirWriteable(trypath) == 1)
3153 ProhibitInput(owner->view());
3154 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
3155 fileDlg.SetButton(1, _("Examples"),
3156 AddPath(system_lyxdir, "examples"));
3157 string filename = fileDlg.Select(_("Select Document to Open"),
3159 AllowInput(owner->view());
3161 // check selected filename
3162 if (filename.empty()) {
3163 owner->getMiniBuffer()->Set(_("Canceled."));
3167 // get absolute path of file and make sure the filename ends
3169 filename = MakeAbsPath(filename);
3170 if (!IsLyXFilename(filename))
3174 owner->getMiniBuffer()->Set(_("Opening document"),
3175 MakeDisplayPath(filename), "...");
3176 Buffer * openbuf = bufferlist.loadLyXFile(filename);
3178 owner->view()->buffer(openbuf);
3179 owner->getMiniBuffer()->Set(_("Document"),
3180 MakeDisplayPath(filename),
3183 owner->getMiniBuffer()->Set(_("Could not open document"),
3184 MakeDisplayPath(filename));
3189 // checks for running without gui are missing.
3190 void LyXFunc::doImport(string const & argument)
3193 string filename = split(argument, format, ' ');
3194 lyxerr.debug() << "LyXFunc::doImport: " << format
3195 << " file: " << filename << endl;
3197 if (filename.empty()) { // need user interaction
3198 string initpath = lyxrc.document_path;
3201 if (owner->view()->available()) {
3202 string const trypath = owner->buffer()->filepath;
3203 // If directory is writeable, use this as default.
3204 if (IsDirWriteable(trypath) == 1)
3209 ProhibitInput(owner->view());
3210 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
3211 fileDlg.SetButton(1, _("Examples"),
3212 AddPath(system_lyxdir, "examples"));
3213 string const text = _("Select ") + formats.PrettyName(format)
3214 + _(" file to import");
3215 string const extension = "*." + formats.Extension(format);
3216 filename = fileDlg.Select(text, initpath, extension);
3217 AllowInput(owner->view());
3219 // check selected filename
3220 if (filename.empty())
3221 owner->getMiniBuffer()->Set(_("Canceled."));
3224 // still no filename? abort
3225 if (filename.empty())
3228 // get absolute path of file
3229 filename = MakeAbsPath(filename);
3231 string const lyxfile = ChangeExtension(filename, ".lyx");
3233 // Check if the document already is open
3234 if (bufferlist.exists(lyxfile)) {
3235 switch (AskConfirmation(_("Document is already open:"),
3236 MakeDisplayPath(lyxfile, 50),
3237 _("Do you want to close that document now?\n"
3238 "('No' will just switch to the open version)")))
3240 case 1: // Yes: close the document
3241 if (!bufferlist.close(bufferlist.getBuffer(lyxfile)))
3242 // If close is canceled, we cancel here too.
3245 case 2: // No: switch to the open document
3246 owner->view()->buffer(bufferlist.getBuffer(lyxfile));
3248 case 3: // Cancel: Do nothing
3249 owner->getMiniBuffer()->Set(_("Canceled."));
3254 // Check if a LyX document by the same root exists in filesystem
3255 FileInfo const f(lyxfile, true);
3256 if (f.exist() && !AskQuestion(_("A document by the name"),
3257 MakeDisplayPath(lyxfile),
3258 _("already exists. Overwrite?"))) {
3259 owner->getMiniBuffer()->Set(_("Canceled."));
3262 // filename should be valid now
3264 Importer::Import(owner, filename, format);
3268 void LyXFunc::MenuInsertLyXFile(string const & filen)
3270 string filename = filen;
3272 if (filename.empty()) {
3273 // Launch a file browser
3274 string initpath = lyxrc.document_path;
3277 if (owner->view()->available()) {
3278 string const trypath = owner->buffer()->filepath;
3279 // If directory is writeable, use this as default.
3280 if (IsDirWriteable(trypath) == 1)
3285 ProhibitInput(owner->view());
3286 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
3287 fileDlg.SetButton(1, _("Examples"),
3288 AddPath(system_lyxdir, "examples"));
3289 filename = fileDlg.Select(_("Select Document to Insert"),
3291 AllowInput(owner->view());
3293 // check selected filename
3294 if (filename.empty()) {
3295 owner->getMiniBuffer()->Set(_("Canceled."));
3300 // get absolute path of file and make sure the filename ends
3302 filename = MakeAbsPath(filename);
3303 if (!IsLyXFilename(filename))
3307 owner->getMiniBuffer()->Set(_("Inserting document"),
3308 MakeDisplayPath(filename), "...");
3309 bool const res = owner->view()->insertLyXFile(filename);
3311 owner->getMiniBuffer()->Set(_("Document"),
3312 MakeDisplayPath(filename),
3315 owner->getMiniBuffer()->Set(_("Could not insert document"),
3316 MakeDisplayPath(filename));
3321 void LyXFunc::reloadBuffer()
3323 string const fn = owner->buffer()->fileName();
3324 if (bufferlist.close(owner->buffer()))
3325 owner->view()->buffer(bufferlist.loadLyXFile(fn));
3329 void LyXFunc::CloseBuffer()
3331 if (bufferlist.close(owner->buffer()) && !quitting) {
3332 if (bufferlist.empty()) {
3333 // need this otherwise SEGV may occur while trying to
3334 // set variables that don't exist
3335 // since there's no current buffer
3336 owner->getDialogs()->hideBufferDependent();
3338 owner->view()->buffer(bufferlist.first());
3344 Inset * LyXFunc::getInsetByCode(Inset::Code code)
3346 LyXCursor cursor = owner->view()->text->cursor;
3347 Buffer * buffer = owner->view()->buffer();
3348 Buffer::inset_iterator it =
3349 find_if(Buffer::inset_iterator(cursor.par(),
3351 buffer->inset_iterator_end(),
3352 compare_memfun(&Inset::LyxCode, code));
3353 return it != buffer->inset_iterator_end() ? (*it) : 0;
3357 // Each "owner" should have it's own message method. lyxview and
3358 // the minibuffer would use the minibuffer, but lyxserver would
3359 // send an ERROR signal to its client. Alejandro 970603
3360 // This func is bit problematic when it comes to NLS, to make the
3361 // lyx servers client be language indepenent we must not translate
3362 // strings sent to this func.
3363 void LyXFunc::setErrorMessage(string const & m) const
3365 dispatch_buffer = m;
3370 void LyXFunc::setMessage(string const & m)
3372 dispatch_buffer = m;