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;
103 extern void show_symbols_form(LyXFunc *);
105 extern LyXAction lyxaction;
107 extern tex_accent_struct get_accent(kb_action action);
109 extern LyXTextClass::size_type current_layout;
111 extern void ShowLatexLog();
113 /* === globals =========================================================== */
115 bool LyXFunc::show_sc = true;
117 LyXFunc::LyXFunc(LyXView * o)
121 lyx_dead_action = LFUN_NOACTION;
122 lyx_calling_dead_action = LFUN_NOACTION;
127 LyXText * LyXFunc::TEXT(bool flag=true) const
130 return owner->view()->text;
131 return owner->view()->getLyXText();
134 // I changed this func slightly. I commented out the ...FinishUndo(),
135 // this means that all places that used to have a moveCursorUpdate, now
136 // have a ...FinishUndo() as the preceeding statement. I have also added
137 // a moveCursorUpdate to some of the functions that updated the cursor, but
138 // that did not show its new position.
140 void LyXFunc::moveCursorUpdate(bool flag, bool selecting)
142 if (selecting || TEXT(flag)->mark_set) {
143 TEXT(flag)->SetSelection(owner->view());
144 if (TEXT(flag)->bv_owner)
145 owner->view()->toggleToggle();
147 owner->view()->update(TEXT(flag), BufferView::SELECT|BufferView::FITCUR);
148 owner->view()->showCursor();
150 /* ---> Everytime the cursor is moved, show the current font state. */
151 // should this too me moved out of this func?
152 //owner->showState();
153 owner->view()->setState();
157 int LyXFunc::processKeySym(KeySym keysym, unsigned int state)
161 if (lyxerr.debugging(Debug::KEY)) {
162 char * tmp = XKeysymToString(keysym);
163 string const stm = (tmp ? tmp : "");
164 lyxerr << "KeySym is "
167 << keysym << "] State is ["
171 // Do nothing if we have nothing (JMarc)
172 if (keysym == NoSymbol) {
173 lyxerr[Debug::KEY] << "Empty kbd action (probably composing)"
179 if (owner->view()->available()) {
180 // this function should be used always [asierra060396]
181 UpdatableInset * tli = owner->view()->theLockingInset();
182 if (tli && (keysym == XK_Escape)) {
183 if (tli == tli->GetLockingInset()) {
184 owner->view()->unlockInset(tli);
185 TEXT()->CursorRight(owner->view());
186 moveCursorUpdate(true, false);
189 tli->UnlockInsetInInset(owner->view(),
190 tli->GetLockingInset(),true);
197 // Can we be sure that this will work for all X-Windows
198 // implementations? (Lgb)
199 // This code snippet makes lyx ignore some keys. Perhaps
200 // all of them should be explictly mentioned?
201 if ((keysym >= XK_Shift_L && keysym <= XK_Hyper_R)
202 || keysym == XK_Mode_switch || keysym == 0x0)
205 // Do a one-deep top-level lookup for
206 // cancel and meta-fake keys. RVDK_PATCH_5
207 cancel_meta_seq.reset();
209 int action = cancel_meta_seq.addkey(keysym, state
210 &(ShiftMask|ControlMask
212 if (lyxerr.debugging(Debug::KEY)) {
213 lyxerr << "action first set to [" << action << "]" << endl;
216 // When not cancel or meta-fake, do the normal lookup.
217 // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
218 // Mostly, meta_fake_bit = 0. RVDK_PATCH_5.
219 if ((action != LFUN_CANCEL) && (action != LFUN_META_FAKE)) {
220 if (lyxerr.debugging(Debug::KEY)) {
221 lyxerr << "meta_fake_bit is [" << meta_fake_bit << "]" << endl;
223 // remove Caps Lock and Mod2 as a modifiers
224 action = keyseq.addkey(keysym,
225 (state | meta_fake_bit)
226 &(ShiftMask|ControlMask
228 if (lyxerr.debugging(Debug::KEY)) {
229 lyxerr << "action now set to [" << action << "]" << endl;
232 // Dont remove this unless you know what you are doing.
235 if (action == 0) action = LFUN_PREFIX;
237 if (lyxerr.debugging(Debug::KEY)) {
246 // already here we know if it any point in going further
247 // why not return already here if action == -1 and
248 // num_bytes == 0? (Lgb)
250 if (keyseq.length > 1 || keyseq.length < -1) {
253 owner->getMiniBuffer()->Set(buf);
257 if (keyseq.length < -1) { // unknown key sequence...
260 owner->getMiniBuffer()->Set(_("Unknown sequence:"), buf);
264 char const isochar = keyseq.getiso();
265 if (!(state & ControlMask) &&
266 !(state & Mod1Mask) &&
267 (isochar && keysym < 0xF000)) {
270 if (argument.empty()) {
271 lyxerr.debug() << "Empty argument!" << endl;
272 // This can`t possibly be of any use
273 // so we`ll skip the dispatch.
276 } else if (action == LFUN_SELFINSERT) {
277 // We must set the argument to the char looked up by
282 xke.send_event = False;
283 xke.display = fl_get_display();
293 xke.keycode = XKeysymToKeycode(fl_get_display(), keysym);
294 xke.same_screen = True;
297 int res = XLookupString(&xke, ret, 10, &tmpkeysym, 0);
298 //Assert(keysym == tmpkeysym);
299 lyxerr[Debug::KEY] << "TmpKeysym ["
300 << tmpkeysym << "]" << endl;
303 argument = string(ret, res);
304 lyxerr[Debug::KEY] << "SelfInsert arg["
305 << argument << "]" << endl;
309 bool tmp_sc = show_sc;
311 Dispatch(action, argument);
318 LyXFunc::func_status LyXFunc::getStatus(int ac) const
321 func_status flag = LyXFunc::OK;
323 Buffer * buf = owner->buffer();
325 if (lyxaction.isPseudoAction(ac))
326 action = lyxaction.retrieveActionArg(ac, argument);
328 action = static_cast<kb_action>(ac);
330 if (action == LFUN_UNKNOWN_ACTION) {
331 setErrorMessage(N_("Unknown action"));
332 return LyXFunc::Unknown;
335 // Check whether we need a buffer
336 if (!lyxaction.funcHasFlag(action, LyXAction::NoBuffer)) {
337 // Yes we need a buffer, do we have one?
340 // Can we use a readonly buffer?
341 if (buf->isReadonly() &&
342 !lyxaction.funcHasFlag(action,
343 LyXAction::ReadOnly)) {
345 setErrorMessage(N_("Document is read-only"));
346 flag |= LyXFunc::Disabled;
350 setErrorMessage(N_("Command not allowed with"
351 "out any document open"));
352 flag |= LyXFunc::Disabled;
357 // I would really like to avoid having this switch and rather try to
358 // encode this in the function itself.
359 bool disable = false;
362 disable = !Exporter::IsExportable(buf, "dvi")
363 || lyxrc.print_command == "none";
366 disable = argument == "fax" &&
367 !Exporter::IsExportable(buf, argument);
370 disable = buf->undostack.empty();
373 disable = buf->redostack.empty();
375 case LFUN_SPELLCHECK:
376 disable = lyxrc.isp_command == "none";
379 disable = lyxrc.chktex_command == "none";
382 disable = !Exporter::IsExportable(buf, "program");
385 case LFUN_INSERTFOOTNOTE:
387 case LFUN_MARGINMELT:
388 // Disable insertion of floats in a tabular.
390 if (owner->view()->theLockingInset()) {
391 disable = (owner->view()->theLockingInset()->LyxCode() == Inset::TABULAR_CODE) ||
392 owner->view()->theLockingInset()->GetFirstLockingInsetOfType(Inset::TABULAR_CODE);
396 case LFUN_LAYOUT_TABULAR:
398 if (owner->view()->theLockingInset()) {
399 disable = (owner->view()->theLockingInset()->LyxCode() != Inset::TABULAR_CODE) &&
400 !owner->view()->theLockingInset()->GetFirstLockingInsetOfType(Inset::TABULAR_CODE);
404 case LFUN_TABULAR_FEATURE:
406 if (owner->view()->theLockingInset()) {
407 func_status ret = LyXFunc::Disabled;
408 if (owner->view()->theLockingInset()->LyxCode() == Inset::TABULAR_CODE) {
409 ret = static_cast<InsetTabular *>
410 (owner->view()->theLockingInset())->
412 } else if (owner->view()->theLockingInset()->GetFirstLockingInsetOfType(Inset::TABULAR_CODE)) {
413 ret = static_cast<InsetTabular *>
414 (owner->view()->theLockingInset()->
415 GetFirstLockingInsetOfType(Inset::TABULAR_CODE))->
421 static InsetTabular inset(*owner->buffer(), 1, 1);
425 ret = inset.getStatus(argument);
426 if ((ret & LyXFunc::ToggleOn) ||
427 (ret & LyXFunc::ToggleOff))
428 flag |= LyXFunc::ToggleOff;
432 case LFUN_VC_REGISTER:
433 disable = buf->lyxvc.inUse();
435 case LFUN_VC_CHECKIN:
436 disable = !buf->lyxvc.inUse() || buf->isReadonly();
438 case LFUN_VC_CHECKOUT:
439 disable = !buf->lyxvc.inUse() || !buf->isReadonly();
443 case LFUN_VC_HISTORY:
444 disable = !buf->lyxvc.inUse();
446 case LFUN_BOOKMARK_GOTO:
447 disable = !owner->view()->
448 isSavedPosition(strToUnsignedInt(argument));
453 flag |= LyXFunc::Disabled;
456 func_status box = LyXFunc::ToggleOff;
457 LyXFont const & font =
458 TEXT(false)->real_current_font;
461 if (font.emph() == LyXFont::ON)
462 box = LyXFunc::ToggleOn;
465 if (font.noun() == LyXFont::ON)
466 box = LyXFunc::ToggleOn;
469 if (font.series() == LyXFont::BOLD_SERIES)
470 box = LyXFunc::ToggleOn;
473 if (font.latex() == LyXFont::ON)
474 box = LyXFunc::ToggleOn;
487 string const LyXFunc::Dispatch(string const & s)
489 // Split command string into command and argument
491 string line = frontStrip(s);
492 string arg = strip(frontStrip(split(line, cmd, ' ')));
494 return Dispatch(lyxaction.LookupFunc(cmd), arg);
498 string const LyXFunc::Dispatch(int ac,
499 string const & do_not_use_this_arg)
501 lyxerr[Debug::ACTION] << "LyXFunc::Dispatch: action[" << ac
502 <<"] arg[" << do_not_use_this_arg << "]" << endl;
507 // we have not done anything wrong yet.
509 dispatch_buffer.erase();
511 // if action is a pseudo-action, we need the real action
512 if (lyxaction.isPseudoAction(ac)) {
514 action = static_cast<kb_action>
515 (lyxaction.retrieveActionArg(ac, tmparg));
519 action = static_cast<kb_action>(ac);
520 if (!do_not_use_this_arg.empty())
521 argument = do_not_use_this_arg; // except here
524 selection_possible = false;
526 if (owner->view()->available())
527 owner->view()->hideCursor();
529 // We cannot use this function here
530 if (getStatus(ac) & Disabled)
531 goto exit_with_message;
533 commandshortcut.erase();
535 if (lyxrc.display_shortcuts && show_sc) {
536 if (action != LFUN_SELFINSERT) {
537 // Put name of command and list of shortcuts
538 // for it in minibuffer
539 string comname = lyxaction.getActionName(action);
541 int pseudoaction = action;
542 bool argsadded = false;
544 if (!argument.empty()) {
545 // If we have the command with argument,
548 lyxaction.searchActionArg(action,
551 if (pseudoaction == -1) {
552 pseudoaction = action;
554 comname += " " + argument;
559 string const shortcuts =
560 toplevel_keymap->findbinding(pseudoaction);
562 if (!shortcuts.empty()) {
563 comname += ": " + shortcuts;
564 } else if (!argsadded) {
565 comname += " " + argument;
568 if (!comname.empty()) {
569 comname = strip(comname);
570 commandshortcut = "(" + comname + ')';
571 owner->getMiniBuffer()->Set(commandshortcut);
572 // Here we could even add a small pause,
573 // to annoy the user and make him learn
575 // No! That will just annoy, not teach
576 // anything. The user will read the messages
577 // if they are interested. (Asger)
582 if (owner->view()->available() && owner->view()->theLockingInset()) {
583 UpdatableInset::RESULT result;
584 if ((action > 1) || ((action == LFUN_UNKNOWN_ACTION) &&
585 (keyseq.length >= -1)))
587 if ((action==LFUN_UNKNOWN_ACTION) && argument.empty()){
588 argument = keyseq.getiso();
590 // Undo/Redo pre 0.13 is a bit tricky for insets.
591 if (action == LFUN_UNDO) {
594 UpdatableInset * inset =
595 owner->view()->theLockingInset();
596 inset->GetCursorPos(owner->view(), slx, sly);
597 owner->view()->unlockInset(inset);
598 owner->view()->menuUndo();
599 if (TEXT()->cursor.par()->
600 IsInset(TEXT()->cursor.pos())) {
601 inset = static_cast<UpdatableInset*>(
602 TEXT()->cursor.par()->
609 inset->Edit(owner->view(),slx,sly,0);
611 } else if (action == LFUN_REDO) {
614 UpdatableInset * inset = owner->view()->
616 inset->GetCursorPos(owner->view(), slx, sly);
617 owner->view()->unlockInset(inset);
618 owner->view()->menuRedo();
619 inset = static_cast<UpdatableInset*>(
620 TEXT()->cursor.par()->
624 inset->Edit(owner->view(),slx,sly,0);
626 } else if (((result=owner->view()->theLockingInset()->
627 LocalDispatch(owner->view(), action,
629 UpdatableInset::DISPATCHED) ||
630 (result == UpdatableInset::DISPATCHED_NOUPDATE))
633 //setMessage(N_("Text mode"));
635 case LFUN_UNKNOWN_ACTION:
636 case LFUN_BREAKPARAGRAPH:
638 TEXT()->CursorRight(owner->view());
639 owner->view()->setState();
643 if (!TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params)) {
644 TEXT()->CursorRight(owner->view());
645 moveCursorUpdate(true, false);
650 if (TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params)) {
651 TEXT()->CursorRight(owner->view());
652 moveCursorUpdate(true, false);
657 TEXT()->CursorDown(owner->view());
658 moveCursorUpdate(true, false);
669 // --- Misc -------------------------------------------
670 case LFUN_WORDFINDFORWARD :
671 case LFUN_WORDFINDBACKWARD : {
672 static string last_search;
673 string searched_string;
675 if (!argument.empty()) {
676 last_search = argument;
677 searched_string = argument;
679 searched_string = last_search;
682 if (!searched_string.empty() &&
683 ((action == LFUN_WORDFINDBACKWARD) ?
684 TEXT()->SearchBackward(owner->view(), searched_string) :
685 TEXT()->SearchForward(owner->view(), searched_string))) {
687 // ??? What is that ???
688 owner->view()->update(TEXT(), BufferView::SELECT|BufferView::FITCUR);
691 // clear the selection (if there is any)
692 owner->view()->toggleSelection();
693 TEXT()->ClearSelection(owner->view());
695 // Move cursor so that successive C-s 's will not stand in place.
696 if (action == LFUN_WORDFINDFORWARD )
697 TEXT()->CursorRightOneWord(owner->view());
698 TEXT()->FinishUndo();
699 moveCursorUpdate(true, false);
702 // set the new selection
703 // SetSelectionOverLenChars(owner->view()->currentBuffer()->text, iLenSelected);
704 owner->view()->toggleSelection(false);
707 // REMOVED : if (owner->view()->getWorkArea()->focus)
708 owner->view()->showCursor();
714 if (owner->view()->available()) {
715 owner->view()->update(TEXT(),
716 BufferView::SELECT|BufferView::FITCUR);
719 keyseq.print(buf, true);
720 owner->getMiniBuffer()->Set(buf, string(), string(), 1);
724 // --- Misc -------------------------------------------
725 case LFUN_EXEC_COMMAND:
726 owner->getMiniBuffer()->PrepareForCommand();
729 case LFUN_CANCEL: // RVDK_PATCH_5
732 if (owner->view()->available())
733 // cancel any selection
734 Dispatch(LFUN_MARK_OFF);
735 setMessage(N_("Cancel"));
738 case LFUN_META_FAKE: // RVDK_PATCH_5
740 meta_fake_bit = Mod1Mask;
742 keyseq.print(buf, true);
743 setMessage(buf); // RVDK_PATCH_5
747 case LFUN_READ_ONLY_TOGGLE:
748 if (owner->buffer()->lyxvc.inUse()) {
749 owner->buffer()->lyxvc.toggleReadOnly();
751 owner->buffer()->setReadonly(
752 !owner->buffer()->isReadonly());
756 case LFUN_CENTER: // this is center and redraw.
757 owner->view()->center();
761 if (owner->view()->available()) {
762 TEXT(false)->toggleAppendix(owner->view());
763 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
767 // --- Menus -----------------------------------------------
772 case LFUN_MENUNEWTMPLT:
780 case LFUN_CLOSEBUFFER:
785 if (!owner->buffer()->isUnnamed()) {
786 owner->getMiniBuffer()->Set(_("Saving document"),
787 MakeDisplayPath(owner->buffer()->fileName()),
789 MenuWrite(owner->view(), owner->buffer());
790 //owner->getMiniBuffer()-> {
791 // Set(_("Document saved as"),
792 // MakeDisplayPath(owner->buffer()->fileName()));
794 //owner->getMiniBuffer()->Set(_("Save failed!"));
797 MenuWriteAs(owner->view(), owner->buffer());
801 case LFUN_MENUWRITEAS:
802 MenuWriteAs(owner->view(), owner->buffer());
805 case LFUN_MENURELOAD:
810 Exporter::Export(owner->buffer(), argument, true);
814 Exporter::Preview(owner->buffer(), argument);
818 Exporter::Export(owner->buffer(), "program", true);
822 MenuRunChktex(owner->buffer());
826 owner->getDialogs()->showPrint();
830 Exporter::Export(owner->buffer(), argument, false);
846 InsetCommandParams p;
848 if (action == LFUN_TOCVIEW )
849 p.setCmdName( "tableofcontents" );
850 else if (action == LFUN_LOAVIEW )
851 p.setCmdName( "listofalgorithms" );
852 else if (action == LFUN_LOFVIEW )
853 p.setCmdName( "listoffigures" );
855 p.setCmdName( "listoftables" );
857 owner->getDialogs()->createTOC( p.getAsString() );
861 case LFUN_TOC_INSERT:
862 case LFUN_LOA_INSERT:
863 case LFUN_LOF_INSERT:
864 case LFUN_LOT_INSERT:
866 InsetCommandParams p;
868 if (action == LFUN_TOC_INSERT )
869 p.setCmdName( "tableofcontents" );
870 else if (action == LFUN_LOA_INSERT )
871 p.setCmdName( "listofalgorithms" );
872 else if (action == LFUN_LOF_INSERT )
873 p.setCmdName( "listoffigures" );
875 p.setCmdName( "listoftables" );
877 Inset * inset = new InsetTOC( p );
878 if (!owner->view()->insertInset( inset, "Standard", true ) )
883 case LFUN_DIALOG_TABULAR_INSERT:
884 owner->getDialogs()->showTabularCreate();
887 case LFUN_TABULAR_FEATURE:
888 case LFUN_SCROLL_INSET:
889 // this is not handled here as this funktion is only aktive
890 // if we have a locking_inset and that one is (or contains)
898 case LFUN_INSET_GRAPHICS:
900 Inset * new_inset = new InsetGraphics;
901 if (!owner->view()->insertInset(new_inset)) {
904 // this is need because you don't use a inset->Edit()
905 owner->view()->updateInset(new_inset, true);
906 new_inset->Edit(owner->view(), 0, 0, 0);
912 AutoSave(owner->view());
916 owner->view()->menuUndo();
920 owner->view()->menuRedo();
923 case LFUN_MENUSEARCH:
925 // Ok this is one _very_ bad solution, but I think that some
926 // of this will be rewritten as part of GUI indep anyway.
928 static LyXFindReplace FR_;
929 FR_.StartSearch(owner->view());
934 owner->view()->paste();
935 owner->view()->setState();
938 case LFUN_PASTESELECTION:
941 if (argument == "paragraph") asPara = true;
942 owner->view()->pasteClipboard(asPara);
947 owner->view()->cut();
951 owner->view()->copy();
954 case LFUN_LAYOUT_COPY:
955 owner->view()->copyEnvironment();
958 case LFUN_LAYOUT_PASTE:
959 owner->view()->pasteEnvironment();
960 owner->view()->setState();
964 owner->view()->gotoInset(Inset::ERROR_CODE, false);
967 case LFUN_REMOVEERRORS:
968 if (owner->view()->removeAutoInsets()) {
969 owner->view()->redraw();
970 owner->view()->fitCursor(TEXT());
975 owner->view()->gotoInset(Inset::IGNORE_CODE, false);
978 case LFUN_REFERENCE_GOTO:
980 vector<Inset::Code> tmp;
981 tmp.push_back(Inset::LABEL_CODE);
982 tmp.push_back(Inset::REF_CODE);
983 owner->view()->gotoInset(tmp, true);
989 owner->view()->openStuff();
993 case LFUN_HYPHENATION:
994 owner->view()->hyphenationPoint();
998 owner->view()->ldots();
1001 case LFUN_END_OF_SENTENCE:
1002 owner->view()->endOfSentenceDot();
1005 case LFUN_MENU_SEPARATOR:
1006 owner->view()->menuSeparator();
1010 owner->view()->hfill();
1014 changeDepth(owner->view(), TEXT(false), 0);
1017 case LFUN_DEPTH_MIN:
1018 changeDepth(owner->view(), TEXT(false), -1);
1021 case LFUN_DEPTH_PLUS:
1022 changeDepth(owner->view(), TEXT(false), 1);
1026 Free(owner->view());
1027 owner->view()->setState();
1033 owner->view()->setState();
1038 Melt(owner->view());
1041 case LFUN_RECONFIGURE:
1042 Reconfigure(owner->view());
1046 if (owner->view()->available()
1047 && !TEXT()->selection
1048 && TEXT()->cursor.par()->footnoteflag
1049 != LyXParagraph::NO_FOOTNOTE)
1050 { // only melt footnotes with FOOTMELT, not margins etc
1051 if (TEXT()->cursor.par()->footnotekind == LyXParagraph::FOOTNOTE)
1052 Melt(owner->view());
1055 Foot(owner->view());
1056 owner->view()->setState();
1059 case LFUN_MARGINMELT:
1060 if (owner->view()->available()
1061 && !TEXT()->selection
1062 && TEXT()->cursor.par()->footnoteflag
1063 != LyXParagraph::NO_FOOTNOTE) {
1064 // only melt margins
1065 if (TEXT()->cursor.par()->footnotekind == LyXParagraph::MARGIN)
1066 Melt(owner->view());
1068 Margin(owner->view());
1069 owner->view()->setState();
1073 case LFUN_FLOATSOPERATE:
1074 if (argument == "openfoot")
1075 owner->view()->allFloats(1,0);
1076 else if (argument == "closefoot")
1077 owner->view()->allFloats(0,0);
1078 else if (argument == "openfig")
1079 owner->view()->allFloats(1,1);
1080 else if (argument == "closefig")
1081 owner->view()->allFloats(0,1);
1084 #warning Find another implementation here (or another lyxfunc)!
1086 case LFUN_HELP_COPYRIGHT:
1087 owner->getDialogs()->showCopyright();
1090 case LFUN_HELP_CREDITS:
1091 owner->getDialogs()->showCredits();
1094 case LFUN_HELP_OPEN: {
1095 string arg = argument;
1097 setErrorMessage(N_("Missing argument"));
1100 ProhibitInput(owner->view());
1101 string fname = i18nLibFileSearch("doc", arg, "lyx");
1102 if (fname.empty()) {
1103 lyxerr << "LyX: unable to find documentation file `"
1104 << arg << "'. Bad installation?" << endl;
1105 AllowInput(owner->view());
1108 owner->getMiniBuffer()->Set(_("Opening help file"),
1109 MakeDisplayPath(fname),"...");
1110 owner->view()->buffer(bufferlist.loadLyXFile(fname,false));
1111 AllowInput(owner->view());
1115 case LFUN_HELP_VERSION: {
1116 ProhibitInput(owner->view());
1117 string msg(_("LyX Version "));
1121 fl_show_message(msg.c_str(),
1122 (_("Library directory: ")
1123 + MakeDisplayPath(system_lyxdir)).c_str(),
1124 (_("User directory: ")
1125 + MakeDisplayPath(user_lyxdir)).c_str());
1126 AllowInput(owner->view());
1130 // --- version control -------------------------------
1131 case LFUN_VC_REGISTER:
1133 if (!owner->buffer()->lyxvc.inUse())
1134 owner->buffer()->lyxvc.registrer();
1138 case LFUN_VC_CHECKIN:
1140 if (owner->buffer()->lyxvc.inUse()
1141 && !owner->buffer()->isReadonly())
1142 owner->buffer()->lyxvc.checkIn();
1146 case LFUN_VC_CHECKOUT:
1148 if (owner->buffer()->lyxvc.inUse()
1149 && owner->buffer()->isReadonly())
1150 owner->buffer()->lyxvc.checkOut();
1154 case LFUN_VC_REVERT:
1156 owner->buffer()->lyxvc.revert();
1162 owner->buffer()->lyxvc.undoLast();
1166 case LFUN_VC_HISTORY:
1168 owner->getDialogs()->showVCLogFile();
1172 // --- buffers ----------------------------------------
1174 case LFUN_SWITCHBUFFER:
1175 owner->view()->buffer(bufferlist.getBuffer(argument));
1179 case LFUN_FILE_INSERT:
1181 MenuInsertLyXFile(argument);
1185 case LFUN_FILE_INSERT_ASCII:
1187 bool asPara = (argument == "paragraph");
1188 InsertAsciiFile(owner->view(), string(), asPara);
1194 // servercmd: argument must be <file>:<template>
1195 Buffer * tmpbuf = NewLyxFile(argument);
1197 owner->view()->buffer(tmpbuf);
1201 case LFUN_FILE_OPEN:
1202 owner->view()->buffer(bufferlist.loadLyXFile(argument));
1205 case LFUN_LATEX_LOG:
1206 owner->getDialogs()->showLogFile();
1211 lyxerr.debug() << "LFUN_LAYOUTNO: (arg) " << argument << endl;
1212 int sel = strToInt(argument);
1213 lyxerr.debug() << "LFUN_LAYOUTNO: (sel) "<< sel << endl;
1215 // Should this give a setMessage instead?
1217 return string(); // illegal argument
1219 --sel; // sel 1..., but layout 0...
1221 // Pretend we got the name instead.
1222 Dispatch(int(LFUN_LAYOUT),
1223 textclasslist.NameOfLayout(owner->view()
1224 ->buffer()->params.textclass,
1231 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1232 << argument << endl;
1234 // Derive layout number from given argument (string)
1235 // and current buffer's textclass (number). */
1236 LyXTextClassList::ClassList::size_type tclass =
1237 owner->view()->buffer()->params.textclass;
1238 pair <bool, LyXTextClass::size_type> layout =
1239 textclasslist.NumberOfLayout(tclass, argument);
1241 // If the entry is obsolete, use the new one instead.
1243 string obs = textclasslist.Style(tclass,layout.second)
1247 textclasslist.NumberOfLayout(tclass, obs);
1250 // see if we found the layout number:
1251 if (!layout.first) {
1252 setErrorMessage(string(N_("Layout ")) + argument +
1257 if (current_layout != layout.second) {
1258 owner->view()->hideCursor();
1259 current_layout = layout.second;
1260 owner->view()->update(TEXT(),
1261 BufferView::SELECT|BufferView::FITCUR);
1263 SetLayout(owner->view(), layout.second);
1264 owner->setLayout(layout.second);
1265 owner->view()->update(TEXT(),
1266 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1267 owner->view()->setState();
1272 case LFUN_LAYOUT_DOCUMENT:
1273 owner->getDialogs()->showLayoutDocument();
1276 case LFUN_LAYOUT_PARAGRAPH:
1277 #ifdef USE_OLD_PARAGRAPH_LAYOUT
1278 MenuLayoutParagraph();
1280 owner->getDialogs()->showLayoutParagraph();
1284 case LFUN_LAYOUT_CHARACTER:
1285 MenuLayoutCharacter();
1288 case LFUN_LAYOUT_TABULAR:
1289 if (owner->view()->theLockingInset()) {
1290 if (owner->view()->theLockingInset()->LyxCode()==Inset::TABULAR_CODE) {
1291 InsetTabular * inset = static_cast<InsetTabular *>
1292 (owner->view()->theLockingInset());
1293 inset->OpenLayoutDialog(owner->view());
1294 } else if (owner->view()->theLockingInset()->
1295 GetFirstLockingInsetOfType(Inset::TABULAR_CODE)!=0) {
1296 InsetTabular * inset = static_cast<InsetTabular *>(
1297 owner->view()->theLockingInset()->GetFirstLockingInsetOfType(Inset::TABULAR_CODE));
1298 inset->OpenLayoutDialog(owner->view());
1303 case LFUN_LAYOUT_PREAMBLE:
1304 owner->getDialogs()->showPreamble();
1307 case LFUN_LAYOUT_SAVE_DEFAULT:
1308 MenuLayoutSave(owner->view());
1311 case LFUN_DROP_LAYOUTS_CHOICE:
1312 owner->getToolbar()->openLayoutList();
1316 Lang(owner->view(), argument);
1317 owner->view()->setState();
1322 Emph(owner->view());
1327 Bold(owner->view());
1332 Noun(owner->view());
1337 Code(owner->view());
1342 Sans(owner->view());
1347 Roman(owner->view());
1352 StyleReset(owner->view());
1356 case LFUN_UNDERLINE:
1357 Underline(owner->view());
1361 case LFUN_FONT_SIZE:
1362 FontSize(owner->view(), argument);
1366 case LFUN_FONT_STATE:
1367 setMessage(CurrentState(owner->view()));
1370 case LFUN_UPCASE_WORD:
1371 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR);
1372 TEXT(false)->ChangeWordCase(owner->view(), LyXText::text_uppercase);
1373 if (TEXT(false)->inset_owner)
1374 owner->view()->updateInset(TEXT(false)->inset_owner, true);
1375 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1378 case LFUN_LOWCASE_WORD:
1379 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR);
1380 TEXT(false)->ChangeWordCase(owner->view(), LyXText::text_lowercase);
1381 if (TEXT(false)->inset_owner)
1382 owner->view()->updateInset(TEXT(false)->inset_owner, true);
1383 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1386 case LFUN_CAPITALIZE_WORD:
1387 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR);
1388 TEXT(false)->ChangeWordCase(owner->view(),
1389 LyXText::text_capitalization);
1390 if (TEXT(false)->inset_owner)
1391 owner->view()->updateInset(TEXT(false)->inset_owner, true);
1392 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1395 case LFUN_INSERT_LABEL:
1396 MenuInsertLabel(owner->view(), argument);
1399 case LFUN_REF_INSERT:
1400 if (argument.empty()) {
1401 InsetCommandParams p("ref");
1402 owner->getDialogs()->createRef(p.getAsString());
1404 InsetCommandParams p;
1405 p.setFromString(argument);
1407 InsetRef * inset = new InsetRef(p, *owner->buffer());
1408 if (!owner->view()->insertInset(inset))
1411 owner->view()->updateInset(inset, true);
1415 case LFUN_BOOKMARK_SAVE:
1416 owner->view()->savePosition(strToUnsignedInt(argument));
1419 case LFUN_BOOKMARK_GOTO:
1420 owner->view()->restorePosition(strToUnsignedInt(argument));
1425 string label(argument);
1426 if (label.empty()) {
1428 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1430 label = inset->getContents();
1431 owner->view()->savePosition(0);
1435 if (!label.empty()) {
1436 //owner->view()->savePosition(0);
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 bool is_rtl = TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params);
1458 if (!TEXT()->mark_set)
1459 owner->view()->beforeChange(TEXT());
1460 owner->view()->update(TEXT(), BufferView::SELECT|BufferView::FITCUR);
1462 TEXT()->CursorLeft(owner->view(), false);
1463 if (TEXT()->cursor.pos() < TEXT()->cursor.par()->Last()
1464 && TEXT()->cursor.par()->GetChar(TEXT()->cursor.pos())
1465 == LyXParagraph::META_INSET
1466 && TEXT()->cursor.par()->GetInset(TEXT()->cursor.pos())
1467 && TEXT()->cursor.par()->GetInset(TEXT()->cursor.pos())->Editable() == Inset::HIGHLY_EDITABLE){
1468 Inset * tmpinset = TEXT()->cursor.par()->GetInset(TEXT()->cursor.pos());
1469 setMessage(tmpinset->EditMessage());
1473 TEXT()->GetFont(owner->view()->buffer(),
1474 TEXT()->cursor.par(),
1475 TEXT()->cursor.pos());
1476 y = tmpinset->descent(owner->view(),font);
1478 tmpinset->Edit(owner->view(), 0, y, 0);
1482 TEXT()->CursorRight(owner->view(), false);
1483 TEXT()->FinishUndo();
1484 moveCursorUpdate(true, false);
1491 // This is soooo ugly. Isn`t it possible to make
1492 // it simpler? (Lgb)
1493 bool is_rtl = TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params);
1494 if (!TEXT()->mark_set)
1495 owner->view()->beforeChange(TEXT());
1496 owner->view()->update(TEXT(), BufferView::SELECT|BufferView::FITCUR);
1497 LyXCursor cur = TEXT()->cursor;
1499 TEXT()->CursorLeft(owner->view(), false);
1500 if ((is_rtl || cur != TEXT()->cursor) && // only if really moved!
1501 TEXT()->cursor.pos() < TEXT()->cursor.par()->Last() &&
1502 (TEXT()->cursor.par()->GetChar(TEXT()->cursor.pos()) ==
1503 LyXParagraph::META_INSET) &&
1504 TEXT()->cursor.par()->GetInset(TEXT()->cursor.pos()) &&
1505 (TEXT()->cursor.par()->GetInset(TEXT()->cursor.pos())->Editable()
1506 == Inset::HIGHLY_EDITABLE))
1508 Inset * tmpinset = TEXT()->cursor.par()->GetInset(TEXT()->cursor.pos());
1509 setMessage(tmpinset->EditMessage());
1510 LyXFont font = TEXT()->GetFont(owner->view()->buffer(),
1511 TEXT()->cursor.par(),
1512 TEXT()->cursor.pos());
1514 : tmpinset->descent(owner->view(),font);
1515 tmpinset->Edit(owner->view(),
1517 tmpinset->width(owner->view(),font),
1522 TEXT()->CursorRight(owner->view(), false);
1524 TEXT()->FinishUndo();
1525 moveCursorUpdate(true, false);
1531 if (!TEXT()->mark_set)
1532 owner->view()->beforeChange(TEXT());
1533 owner->view()->update(TEXT(), BufferView::UPDATE);
1534 TEXT()->CursorUp(owner->view());
1535 TEXT()->FinishUndo();
1536 moveCursorUpdate(true, false);
1541 if (!TEXT()->mark_set)
1542 owner->view()->beforeChange(TEXT());
1543 owner->view()->update(TEXT(), BufferView::UPDATE);
1544 TEXT()->CursorDown(owner->view());
1545 TEXT()->FinishUndo();
1546 moveCursorUpdate(true, false);
1550 case LFUN_UP_PARAGRAPH:
1551 if (!TEXT()->mark_set)
1552 owner->view()->beforeChange(TEXT());
1553 owner->view()->update(TEXT(), BufferView::UPDATE);
1554 TEXT()->CursorUpParagraph(owner->view());
1555 TEXT()->FinishUndo();
1556 moveCursorUpdate(true, false);
1560 case LFUN_DOWN_PARAGRAPH:
1561 if (!TEXT()->mark_set)
1562 owner->view()->beforeChange(TEXT());
1563 owner->view()->update(TEXT(), BufferView::UPDATE);
1564 TEXT()->CursorDownParagraph(owner->view());
1565 TEXT()->FinishUndo();
1566 moveCursorUpdate(true, false);
1571 if (!TEXT(false)->mark_set)
1572 owner->view()->beforeChange(TEXT());
1573 owner->view()->update(TEXT(), BufferView::UPDATE);
1574 owner->view()->cursorPrevious(TEXT(false));
1575 TEXT()->FinishUndo();
1576 moveCursorUpdate(false, false);
1581 if (!TEXT(false)->mark_set)
1582 owner->view()->beforeChange(TEXT());
1583 owner->view()->update(TEXT(), BufferView::UPDATE);
1584 owner->view()->cursorNext(TEXT(false));
1585 TEXT()->FinishUndo();
1586 moveCursorUpdate(false, false);
1591 if (!TEXT()->mark_set)
1592 owner->view()->beforeChange(TEXT());
1593 owner->view()->update(TEXT(), BufferView::SELECT|BufferView::FITCUR);
1594 TEXT()->CursorHome(owner->view());
1595 TEXT()->FinishUndo();
1596 moveCursorUpdate(true, false);
1601 if (!TEXT()->mark_set)
1602 owner->view()->beforeChange(TEXT());
1603 owner->view()->update(TEXT(),
1604 BufferView::SELECT|BufferView::FITCUR);
1605 TEXT()->CursorEnd(owner->view());
1606 TEXT()->FinishUndo();
1607 moveCursorUpdate(true, false);
1611 case LFUN_SHIFT_TAB:
1613 if (!TEXT()->mark_set)
1614 owner->view()->beforeChange(TEXT());
1615 owner->view()->update(TEXT(),
1616 BufferView::SELECT|BufferView::FITCUR);
1617 TEXT()->CursorTab(owner->view());
1618 TEXT()->FinishUndo();
1619 moveCursorUpdate(true, false);
1623 case LFUN_WORDRIGHT:
1624 if (!TEXT(false)->mark_set)
1625 owner->view()->beforeChange(TEXT(false));
1626 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR);
1627 if (TEXT(false)->cursor.par()->isRightToLeftPar(owner->buffer()->params))
1628 TEXT(false)->CursorLeftOneWord(owner->view());
1630 TEXT(false)->CursorRightOneWord(owner->view());
1631 TEXT()->FinishUndo();
1632 moveCursorUpdate(false, false);
1637 if (!TEXT(false)->mark_set)
1638 owner->view()->beforeChange(TEXT(false));
1639 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR);
1640 if (TEXT(false)->cursor.par()->isRightToLeftPar(owner->buffer()->params))
1641 TEXT(false)->CursorRightOneWord(owner->view());
1643 TEXT(false)->CursorLeftOneWord(owner->view());
1644 TEXT()->FinishUndo();
1645 moveCursorUpdate(false, false);
1649 case LFUN_BEGINNINGBUF:
1650 if (!TEXT()->mark_set)
1651 owner->view()->beforeChange(TEXT());
1652 owner->view()->update(TEXT(),
1653 BufferView::SELECT|BufferView::FITCUR);
1654 TEXT()->CursorTop(owner->view());
1655 TEXT()->FinishUndo();
1656 moveCursorUpdate(true, false);
1661 if (!TEXT()->mark_set)
1662 owner->view()->beforeChange(TEXT());
1663 owner->view()->update(TEXT(),
1664 BufferView::SELECT|BufferView::FITCUR);
1665 TEXT()->CursorBottom(owner->view());
1666 TEXT()->FinishUndo();
1667 moveCursorUpdate(true, false);
1672 /* cursor selection ---------------------------- */
1674 owner->view()->update(TEXT(),
1675 BufferView::SELECT|BufferView::FITCUR);
1676 if (TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params))
1677 TEXT()->CursorLeft(owner->view());
1679 TEXT()->CursorRight(owner->view());
1680 TEXT()->FinishUndo();
1681 moveCursorUpdate(true, true);
1686 owner->view()->update(TEXT(),
1687 BufferView::SELECT|BufferView::FITCUR);
1688 if (TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params))
1689 TEXT()->CursorRight(owner->view());
1691 TEXT()->CursorLeft(owner->view());
1692 TEXT()->FinishUndo();
1693 moveCursorUpdate(true, true);
1698 owner->view()->update(TEXT(),
1699 BufferView::SELECT|BufferView::FITCUR);
1700 TEXT()->CursorUp(owner->view());
1701 TEXT()->FinishUndo();
1702 moveCursorUpdate(true, true);
1707 owner->view()->update(TEXT(),
1708 BufferView::SELECT|BufferView::FITCUR);
1709 TEXT()->CursorDown(owner->view());
1710 TEXT()->FinishUndo();
1711 moveCursorUpdate(true, true);
1715 case LFUN_UP_PARAGRAPHSEL:
1716 owner->view()->update(TEXT(),
1717 BufferView::SELECT|BufferView::FITCUR);
1718 TEXT()->CursorUpParagraph(owner->view());
1719 TEXT()->FinishUndo();
1720 moveCursorUpdate(true, true);
1724 case LFUN_DOWN_PARAGRAPHSEL:
1725 owner->view()->update(TEXT(),
1726 BufferView::SELECT|BufferView::FITCUR);
1727 TEXT()->CursorDownParagraph(owner->view());
1728 TEXT()->FinishUndo();
1729 moveCursorUpdate(true, true);
1734 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR);
1735 owner->view()->cursorPrevious(TEXT(false));
1736 TEXT()->FinishUndo();
1737 moveCursorUpdate(false, true);
1742 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR);
1743 owner->view()->cursorNext(TEXT(false));
1744 TEXT()->FinishUndo();
1745 moveCursorUpdate(false, true);
1750 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR);
1751 TEXT(false)->CursorHome(owner->view());
1752 TEXT()->FinishUndo();
1753 moveCursorUpdate(false, true);
1758 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR);
1759 TEXT(false)->CursorEnd(owner->view());
1760 TEXT()->FinishUndo();
1761 moveCursorUpdate(false, true);
1765 case LFUN_WORDRIGHTSEL:
1766 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR);
1767 if (TEXT(false)->cursor.par()->isRightToLeftPar(owner->buffer()->params))
1768 TEXT(false)->CursorLeftOneWord(owner->view());
1770 TEXT(false)->CursorRightOneWord(owner->view());
1771 TEXT()->FinishUndo();
1772 moveCursorUpdate(false, true);
1776 case LFUN_WORDLEFTSEL:
1777 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR);
1778 if (TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params))
1779 TEXT(false)->CursorRightOneWord(owner->view());
1781 TEXT(false)->CursorLeftOneWord(owner->view());
1782 TEXT()->FinishUndo();
1783 moveCursorUpdate(false, true);
1787 case LFUN_BEGINNINGBUFSEL:
1788 if (TEXT(false)->inset_owner)
1790 owner->view()->update(TEXT(), BufferView::SELECT|BufferView::FITCUR);
1791 TEXT()->CursorTop(owner->view());
1792 TEXT()->FinishUndo();
1793 moveCursorUpdate(true, true);
1797 case LFUN_ENDBUFSEL:
1798 if (TEXT(false)->inset_owner)
1800 owner->view()->update(TEXT(),
1801 BufferView::SELECT|BufferView::FITCUR);
1802 TEXT()->CursorBottom(owner->view());
1803 TEXT()->FinishUndo();
1804 moveCursorUpdate(true, true);
1808 // --- text changing commands ------------------------
1809 case LFUN_BREAKLINE:
1810 owner->view()->beforeChange(TEXT());
1811 TEXT()->InsertChar(owner->view(), LyXParagraph::META_NEWLINE);
1812 owner->view()->update(TEXT(),
1813 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1814 moveCursorUpdate(true, false);
1817 case LFUN_PROTECTEDSPACE:
1819 LyXLayout const & style =
1820 textclasslist.Style(owner->view()->buffer()->params.textclass,
1821 TEXT(false)->cursor.par()->GetLayout());
1823 if (style.free_spacing) {
1824 TEXT(false)->InsertChar(owner->view(), ' ');
1825 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1827 owner->view()->protectedBlank(TEXT(false));
1829 moveCursorUpdate(false, false);
1834 if (TEXT(false)->mark_set) {
1835 owner->view()->beforeChange(TEXT(false));
1836 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR);
1837 setMessage(N_("Mark removed"));
1839 owner->view()->beforeChange(TEXT(false));
1840 TEXT(false)->mark_set = 1;
1841 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR);
1842 setMessage(N_("Mark set"));
1844 TEXT(false)->sel_cursor = TEXT(false)->cursor;
1848 if (!TEXT()->selection) {
1849 TEXT()->Delete(owner->view());
1850 TEXT()->sel_cursor =
1852 owner->view()->update(TEXT(),
1853 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1854 // It is possible to make it a lot faster still
1855 // just comment out the line below...
1856 owner->view()->showCursor();
1858 owner->view()->cut();
1860 moveCursorUpdate(true, false);
1862 owner->view()->setState();
1865 case LFUN_DELETE_SKIP:
1867 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1869 LyXCursor cursor = TEXT()->cursor;
1871 if (!TEXT()->selection) {
1872 if (cursor.pos() == cursor.par()->Last()) {
1873 TEXT()->CursorRight(owner->view());
1874 cursor = TEXT()->cursor;
1875 if (cursor.pos() == 0
1876 && !(cursor.par()->added_space_top
1877 == VSpace (VSpace::NONE))) {
1878 TEXT()->SetParagraph
1880 cursor.par()->line_top,
1881 cursor.par()->line_bottom,
1882 cursor.par()->pagebreak_top,
1883 cursor.par()->pagebreak_bottom,
1884 VSpace(VSpace::NONE),
1885 cursor.par()->added_space_bottom,
1886 cursor.par()->align,
1887 cursor.par()->labelwidthstring, 0);
1888 TEXT()->CursorLeft(owner->view());
1889 owner->view()->update(TEXT(),
1890 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1892 TEXT()->CursorLeft(owner->view());
1893 TEXT()->Delete(owner->view());
1894 TEXT()->sel_cursor =
1896 owner->view()->update(TEXT(),
1897 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1900 TEXT()->Delete(owner->view());
1901 TEXT()->sel_cursor =
1903 owner->view()->update(TEXT(),
1904 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1907 owner->view()->cut();
1912 /* -------> Delete word forward. */
1913 case LFUN_DELETE_WORD_FORWARD:
1914 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR);
1915 TEXT(false)->DeleteWordForward(owner->view());
1916 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1917 moveCursorUpdate(false, false);
1921 /* -------> Delete word backward. */
1922 case LFUN_DELETE_WORD_BACKWARD:
1923 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR);
1924 TEXT(false)->DeleteWordBackward(owner->view());
1925 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1926 moveCursorUpdate(false, false);
1930 /* -------> Kill to end of line. */
1931 case LFUN_DELETE_LINE_FORWARD:
1932 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR);
1933 TEXT(false)->DeleteLineForward(owner->view());
1934 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1935 moveCursorUpdate(false, false);
1938 /* -------> Set mark off. */
1940 owner->view()->beforeChange(TEXT(false));
1941 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR);
1942 TEXT(false)->sel_cursor = TEXT(false)->cursor;
1943 setMessage(N_("Mark off"));
1946 /* -------> Set mark on. */
1948 owner->view()->beforeChange(TEXT(false));
1949 TEXT(false)->mark_set = 1;
1950 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR);
1951 TEXT(false)->sel_cursor = TEXT(false)->cursor;
1952 setMessage(N_("Mark on"));
1955 case LFUN_BACKSPACE:
1957 if (!TEXT()->selection) {
1958 if (owner->getIntl()->getTrans().backspace()) {
1959 TEXT()->Backspace(owner->view());
1960 TEXT()->sel_cursor =
1962 owner->view()->update(TEXT(),
1963 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1964 // It is possible to make it a lot faster still
1965 // just comment out the line below...
1966 owner->view()->showCursor();
1969 owner->view()->cut();
1972 owner->view()->setState();
1976 case LFUN_BACKSPACE_SKIP:
1978 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1980 LyXCursor cursor = TEXT()->cursor;
1982 if (!TEXT()->selection) {
1983 if (cursor.pos() == 0
1984 && !(cursor.par()->added_space_top
1985 == VSpace (VSpace::NONE))) {
1986 TEXT()->SetParagraph
1988 cursor.par()->line_top,
1989 cursor.par()->line_bottom,
1990 cursor.par()->pagebreak_top,
1991 cursor.par()->pagebreak_bottom,
1992 VSpace(VSpace::NONE), cursor.par()->added_space_bottom,
1993 cursor.par()->align,
1994 cursor.par()->labelwidthstring, 0);
1995 owner->view()->update(TEXT(),
1996 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1998 TEXT()->Backspace(owner->view());
2001 owner->view()->update(TEXT(),
2002 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2005 owner->view()->cut();
2009 case LFUN_BREAKPARAGRAPH:
2011 owner->view()->beforeChange(TEXT());
2012 TEXT()->BreakParagraph(owner->view(), 0);
2013 owner->view()->update(TEXT(),
2014 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2015 TEXT()->sel_cursor =
2017 owner->view()->setState();
2022 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2024 owner->view()->beforeChange(TEXT());
2025 TEXT()->BreakParagraph(owner->view(), 1);
2026 owner->view()->update(TEXT(),
2027 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2028 TEXT()->sel_cursor =
2030 owner->view()->setState();
2035 case LFUN_BREAKPARAGRAPH_SKIP:
2037 // When at the beginning of a paragraph, remove
2038 // indentation and add a "defskip" at the top.
2039 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2041 LyXCursor cursor = TEXT()->cursor;
2043 owner->view()->beforeChange(TEXT());
2044 if (cursor.pos() == 0) {
2045 if (cursor.par()->added_space_top == VSpace(VSpace::NONE)) {
2046 TEXT()->SetParagraph
2048 cursor.par()->line_top,
2049 cursor.par()->line_bottom,
2050 cursor.par()->pagebreak_top,
2051 cursor.par()->pagebreak_bottom,
2052 VSpace(VSpace::DEFSKIP), cursor.par()->added_space_bottom,
2053 cursor.par()->align,
2054 cursor.par()->labelwidthstring, 1);
2055 //owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2059 TEXT()->BreakParagraph(owner->view(), 0);
2060 //owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2063 owner->view()->update(TEXT(),
2064 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2065 TEXT()->sel_cursor = cursor;
2066 owner->view()->setState();
2071 case LFUN_PARAGRAPH_SPACING:
2073 LyXParagraph * par = TEXT()->cursor.par();
2074 Spacing::Space cur_spacing = par->spacing.getSpace();
2075 float cur_value = 1.0;
2076 if (cur_spacing == Spacing::Other) {
2077 cur_value = par->spacing.getValue();
2080 istringstream istr(argument.c_str());
2084 Spacing::Space new_spacing = cur_spacing;
2085 float new_value = cur_value;
2087 lyxerr << "Missing argument to `paragraph-spacing'"
2089 } else if (tmp == "single") {
2090 new_spacing = Spacing::Single;
2091 } else if (tmp == "onehalf") {
2092 new_spacing = Spacing::Onehalf;
2093 } else if (tmp == "double") {
2094 new_spacing = Spacing::Double;
2095 } else if (tmp == "other") {
2096 new_spacing = Spacing::Other;
2099 lyxerr << "new_value = " << tmpval << endl;
2102 } else if (tmp == "default") {
2103 new_spacing = Spacing::Default;
2105 lyxerr << _("Unknown spacing argument: ")
2106 << argument << endl;
2108 if (cur_spacing != new_spacing || cur_value != new_value) {
2109 par->spacing.set(new_spacing, new_value);
2110 TEXT()->RedoParagraph(owner->view());
2111 owner->view()->update(TEXT(),
2112 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2118 owner->view()->beforeChange(TEXT(false));
2119 TEXT(false)->InsertChar(owner->view(), '\"'); // This " matches the single quote in the code
2120 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2121 moveCursorUpdate(false, false);
2127 InsetCommandParams p;
2128 if (action == LFUN_HTMLURL)
2129 p.setCmdName("htmlurl");
2131 p.setCmdName("url");
2132 owner->getDialogs()->createUrl( p.getAsString() );
2136 case LFUN_INSERT_URL:
2138 InsetCommandParams p;
2139 p.setFromString( argument );
2141 InsetUrl * inset = new InsetUrl( p );
2142 if (!owner->view()->insertInset(inset))
2145 owner->view()->updateInset( inset, true );
2149 case LFUN_INSET_TEXT:
2151 InsetText * new_inset = new InsetText;
2152 if (owner->view()->insertInset(new_inset))
2153 new_inset->Edit(owner->view(), 0, 0, 0);
2159 case LFUN_INSET_ERT:
2161 InsetERT * new_inset = new InsetERT;
2162 if (owner->view()->insertInset(new_inset))
2163 new_inset->Edit(owner->view(), 0, 0, 0);
2169 case LFUN_INSET_EXTERNAL:
2171 InsetExternal * new_inset = new InsetExternal;
2172 if (owner->view()->insertInset(new_inset))
2173 new_inset->Edit(owner->view(), 0, 0, 0);
2179 case LFUN_INSET_FOOTNOTE:
2181 InsetFoot * new_inset = new InsetFoot;
2182 if (owner->view()->insertInset(new_inset))
2183 new_inset->Edit(owner->view(), 0, 0, 0);
2189 case LFUN_INSET_MARGINAL:
2191 InsetMarginal * new_inset = new InsetMarginal;
2192 if (owner->view()->insertInset(new_inset))
2193 new_inset->Edit(owner->view(), 0, 0, 0);
2199 case LFUN_INSET_MINIPAGE:
2201 InsetMinipage * new_inset = new InsetMinipage;
2202 if (owner->view()->insertInset(new_inset))
2203 new_inset->Edit(owner->view(), 0, 0, 0);
2209 case LFUN_INSET_FLOAT:
2211 // check if the float type exist
2212 if (floatList.typeExist(argument)) {
2213 InsetFloat * new_inset = new InsetFloat(argument);
2214 if (owner->view()->insertInset(new_inset))
2215 new_inset->Edit(owner->view(), 0, 0, 0);
2219 lyxerr << "Non-existant float type: "
2220 << argument << endl;
2226 case LFUN_INSET_LIST:
2228 InsetList * new_inset = new InsetList;
2229 if (owner->view()->insertInset(new_inset))
2230 new_inset->Edit(owner->view(), 0, 0, 0);
2236 case LFUN_INSET_THEOREM:
2238 InsetTheorem * new_inset = new InsetTheorem;
2239 if (owner->view()->insertInset(new_inset))
2240 new_inset->Edit(owner->view(), 0, 0, 0);
2246 case LFUN_INSET_CAPTION:
2248 // Do we have a locking inset...
2249 if (owner->view()->theLockingInset()) {
2250 lyxerr << "Locking inset code: "
2251 << static_cast<int>(owner->view()->theLockingInset()->LyxCode());
2252 InsetCaption * new_inset = new InsetCaption;
2253 new_inset->setOwner(owner->view()->theLockingInset());
2254 new_inset->SetAutoBreakRows(true);
2255 new_inset->SetDrawFrame(0, InsetText::LOCKED);
2256 new_inset->SetFrameColor(0, LColor::footnoteframe);
2257 if (owner->view()->insertInset(new_inset))
2258 new_inset->Edit(owner->view(), 0, 0, 0);
2265 case LFUN_INSET_TABULAR:
2268 if (!argument.empty())
2269 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2270 InsetTabular * new_inset =
2271 new InsetTabular(*owner->buffer(), r, c);
2273 TEXT(false)->real_current_font.isRightToLeft();
2274 if (!owner->view()->open_new_inset(new_inset, rtl))
2279 // --- lyxserver commands ----------------------------
2281 case LFUN_CHARATCURSOR:
2283 LyXParagraph::size_type pos =
2284 TEXT()->cursor.pos();
2285 if (pos < TEXT()->cursor.par()->size())
2286 //dispatch_buffer = TEXT()->
2287 // cursor.par()->text[pos];
2290 cursor.par()->GetChar(pos);
2292 dispatch_buffer = "EOF";
2298 tostr(TEXT()->cursor.x()) + ' '
2299 + tostr(TEXT()->cursor.y());
2306 ::sscanf(argument.c_str(), " %d %d", &x, &y);
2307 TEXT()->SetCursorFromCoordinates(owner->view(), x, y);
2311 case LFUN_GETLAYOUT:
2313 tostr(TEXT()->cursor.par()->layout);
2318 LyXFont & font = TEXT()->current_font;
2319 if (font.shape() == LyXFont::ITALIC_SHAPE)
2320 dispatch_buffer = 'E';
2321 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2322 dispatch_buffer = 'N';
2324 dispatch_buffer = '0';
2331 LyXFont & font = TEXT()->current_font;
2332 if (font.latex() == LyXFont::ON)
2333 dispatch_buffer = 'L';
2335 dispatch_buffer = '0';
2340 setMessage(owner->buffer()->fileName());
2341 lyxerr.debug() << "FNAME["
2342 << owner->buffer()->fileName()
2350 dispatch_buffer = buf;
2351 lyxserver->notifyClient(dispatch_buffer);
2355 case LFUN_GOTOFILEROW:
2357 char file_name[100];
2359 ::sscanf(argument.c_str(), " %s %d", file_name, &row);
2361 // Must replace extension of the file to be .lyx and get full path
2362 string s = ChangeExtension(string(file_name), ".lyx");
2364 // Either change buffer or load the file
2365 if (bufferlist.exists(s))
2366 owner->view()->buffer(bufferlist.getBuffer(s));
2368 owner->view()->buffer(bufferlist.loadLyXFile(s));
2371 owner->view()->setCursorFromRow(row);
2374 owner->view()->center();
2378 case LFUN_GOTO_PARAGRAPH:
2380 istringstream istr(argument.c_str());
2384 LyXParagraph * par = TEXT()->GetParFromID(id);
2387 TEXT()->SetCursor(owner->view(), par, 0);
2388 owner->view()->setState();
2392 owner->view()->center();
2399 int const qa = lyxaction.LookupFunc(argument);
2400 setMessage(lyxaction.helpText(static_cast<kb_action>(qa)));
2404 // --- accented characters ---------------------------
2407 case LFUN_CIRCUMFLEX:
2417 case LFUN_SPECIAL_CARON:
2420 case LFUN_HUNG_UMLAUT:
2426 if (keyseq.length == -1 && keyseq.getiso() != 0)
2427 c = keyseq.getiso();
2429 owner->getIntl()->getTrans()
2430 .deadkey(c, get_accent(action).accent,
2433 // Need to reset, in case the minibuffer calls these
2438 // copied verbatim from do_accent_char
2439 owner->view()->update(TEXT(),
2440 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2442 TEXT()->sel_cursor =
2447 // --- toolbar ----------------------------------
2448 case LFUN_PUSH_TOOLBAR:
2450 int nth = strToInt(argument);
2452 setErrorMessage(N_("Push-toolbar needs argument > 0"));
2454 owner->getToolbar()->push(nth);
2459 case LFUN_ADD_TO_TOOLBAR:
2461 if (lyxerr.debugging(Debug::GUI)) {
2462 lyxerr << "LFUN_ADD_TO_TOOLBAR:"
2463 "argument = `" << argument << '\'' << endl;
2465 string tmp(argument);
2466 //lyxerr <<string("Argument: ") + argument);
2467 //lyxerr <<string("Tmp : ") + tmp);
2469 setErrorMessage(N_("Usage: toolbar-add-to <LyX command>"));
2471 owner->getToolbar()->add(argument, false);
2472 owner->getToolbar()->set();
2477 // --- insert characters ----------------------------------------
2479 // --- Mathed stuff. If we are here, there is no locked inset yet.
2484 if (!greek_kb_flag) {
2486 setMessage(N_("Math greek mode on"));
2493 case LFUN_GREEK_TOGGLE:
2495 greek_kb_flag = greek_kb_flag ? 0 : 2;
2496 if (greek_kb_flag) {
2497 setMessage(N_("Math greek keyboard on"));
2499 setMessage(N_("Math greek keyboard off"));
2504 case LFUN_MATH_DELIM:
2505 case LFUN_INSERT_MATRIX:
2507 if (owner->view()->available()) {
2509 open_new_inset(new InsetFormula(false)))
2511 owner->view()->theLockingInset()
2512 ->LocalDispatch(owner->view(),
2520 case LFUN_INSERT_MATH:
2522 math_insert_symbol(owner->view(), argument);
2526 case LFUN_MATH_DISPLAY:
2528 if (owner->view()->available())
2529 owner->view()->open_new_inset(new InsetFormula(true));
2533 case LFUN_MATH_MACRO:
2535 if (owner->view()->available()) {
2538 setErrorMessage(N_("Missing argument"));
2540 string const s1 = token(s, ' ', 1);
2541 int const na = s1.empty() ? 0 : lyx::atoi(s1);
2543 open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2549 case LFUN_MATH_MODE: // Open or create a math inset
2551 if (owner->view()->available())
2552 owner->view()->open_new_inset(new InsetFormula);
2553 setMessage(N_("Math editor mode"));
2557 case LFUN_MATH_NUMBER:
2558 case LFUN_MATH_LIMITS:
2560 setErrorMessage(N_("This is only allowed in math mode!"));
2565 case LFUN_MATH_PANEL:
2567 show_symbols_form(this);
2571 case LFUN_CITATION_CREATE:
2573 InsetCommandParams p( "cite" );
2575 if (!argument.empty()) {
2576 // This should be set at source, ie when typing
2577 // "citation-insert foo" in the minibuffer.
2578 // Question: would pybibliographer also need to be
2579 // changed. Suspect so. Leave as-is therefore.
2580 if (contains(argument, "|")) {
2581 p.setContents( token(argument, '|', 0) );
2582 p.setOptions( token(argument, '|', 1) );
2584 p.setContents( argument );
2586 Dispatch(LFUN_CITATION_INSERT, p.getAsString());
2588 owner->getDialogs()->createCitation( p.getAsString() );
2592 case LFUN_CITATION_INSERT:
2594 InsetCommandParams p;
2595 p.setFromString( argument );
2597 InsetCitation * inset = new InsetCitation( p );
2598 if (!owner->view()->insertInset(inset))
2601 owner->view()->updateInset( inset, true );
2605 case LFUN_INSERT_BIBTEX:
2607 // ale970405+lasgoutt970425
2608 // The argument can be up to two tokens separated
2609 // by a space. The first one is the bibstyle.
2610 string const db = token(argument, ' ', 0);
2611 string bibstyle = token(argument, ' ', 1);
2612 if (bibstyle.empty())
2615 InsetCommandParams p( "BibTeX", db, bibstyle );
2616 InsetBibtex * inset = new InsetBibtex(p);
2618 if (owner->view()->insertInset(inset)) {
2619 if (argument.empty())
2620 inset->Edit(owner->view(), 0, 0, 0);
2626 // BibTeX data bases
2627 case LFUN_BIBDB_ADD:
2629 InsetBibtex * inset =
2630 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2632 inset->addDatabase(argument);
2637 case LFUN_BIBDB_DEL:
2639 InsetBibtex * inset =
2640 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2642 inset->delDatabase(argument);
2647 case LFUN_BIBTEX_STYLE:
2649 InsetBibtex * inset =
2650 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2652 inset->setOptions(argument);
2657 case LFUN_INDEX_CREATE:
2659 InsetCommandParams p( "index" );
2661 if (argument.empty()) {
2662 // Get the word immediately preceding the cursor
2663 LyXParagraph::size_type curpos =
2664 TEXT()->cursor.pos() - 1;
2669 ->cursor.par()->GetWord(curpos);
2671 p.setContents( curstring );
2673 p.setContents( argument );
2676 owner->getDialogs()->createIndex( p.getAsString() );
2680 case LFUN_INDEX_INSERT:
2682 InsetCommandParams p;
2683 p.setFromString(argument);
2684 InsetIndex * inset = new InsetIndex(p);
2686 if (!owner->view()->insertInset(inset))
2689 owner->view()->updateInset(inset, true);
2693 case LFUN_INDEX_INSERT_LAST:
2695 // Get word immediately preceding the cursor
2696 LyXParagraph::size_type curpos =
2697 TEXT()->cursor.pos() - 1;
2698 // Can't do that at the beginning of a paragraph
2699 if (curpos < 0) break;
2701 string const curstring(TEXT()
2702 ->cursor.par()->GetWord(curpos));
2704 InsetCommandParams p("index", curstring);
2705 InsetIndex * inset = new InsetIndex(p);
2707 if (!owner->view()->insertInset(inset))
2710 owner->view()->updateInset(inset, true);
2714 case LFUN_INDEX_PRINT:
2716 InsetCommandParams p("printindex");
2717 Inset * inset = new InsetPrintIndex(p);
2718 if (!owner->view()->insertInset(inset, "Standard", true))
2723 case LFUN_PARENTINSERT:
2725 lyxerr << "arg " << argument << endl;
2726 InsetCommandParams p( "lyxparent", argument );
2727 Inset * inset = new InsetParent(p, *owner->buffer());
2728 if (!owner->view()->insertInset(inset, "Standard", true))
2733 case LFUN_CHILD_CREATE:
2735 InsetCommandParams p("include");
2737 if (!argument.empty()) {
2738 if (contains(argument, "|")) {
2739 p.setContents(token(argument, '|', 0));
2740 p.setOptions(token(argument, '|', 1));
2742 p.setContents(argument);
2743 Dispatch(LFUN_CHILD_INSERT, p.getAsString());
2745 owner->getDialogs()->createInclude(p.getAsString());
2749 case LFUN_CHILD_INSERT:
2751 InsetCommandParams p;
2752 p.setFromString(argument);
2754 InsetInclude * inset = new InsetInclude(p, *owner->buffer());
2755 if (!owner->view()->insertInset(inset))
2758 owner->view()->updateInset(inset, true);
2762 case LFUN_CHILDOPEN:
2764 string const filename =
2765 MakeAbsPath(argument,
2766 OnlyPath(owner->buffer()->fileName()));
2767 setMessage(N_("Opening child document ") +
2768 MakeDisplayPath(filename) + "...");
2769 owner->view()->savePosition(0);
2770 if (bufferlist.exists(filename))
2771 owner->view()->buffer(bufferlist.getBuffer(filename));
2773 owner->view()->buffer(bufferlist.loadLyXFile(filename));
2777 case LFUN_INSERT_NOTE:
2778 owner->view()->insertNote();
2781 case LFUN_INSERTFOOTNOTE:
2783 LyXParagraph::footnote_kind kind;
2784 if (argument == "footnote") {
2785 kind = LyXParagraph::FOOTNOTE;
2786 } else if (argument == "margin") {
2787 kind = LyXParagraph::MARGIN;
2788 } else if (argument == "figure") {
2789 kind = LyXParagraph::FIG;
2790 } else if (argument == "table") {
2791 kind = LyXParagraph::TAB;
2792 } else if (argument == "wide-fig") {
2793 kind = LyXParagraph::WIDE_FIG;
2794 } else if (argument == "wide-tab") {
2795 kind = LyXParagraph::WIDE_TAB;
2796 } else if (argument == "algorithm") {
2797 kind = LyXParagraph::ALGORITHM;
2799 setErrorMessage(N_("Unknown kind of footnote"));
2802 TEXT()->InsertFootnoteEnvironment(owner->view(), kind);
2803 owner->view()->update(TEXT(),
2804 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(TEXT(false)->real_current_font);
2832 for (string::size_type i = 0; i < argument.length(); ++i) {
2833 TEXT(false)->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(TEXT(false),
2837 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2839 TEXT(false)->sel_cursor = TEXT(false)->cursor;
2840 moveCursorUpdate(false, false);
2842 // real_current_font.number can change so we need to
2843 // update the minibuffer
2844 if (old_font != TEXT(false)->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 TEXT()->InsertChar(owner->view(), datetmp[i]);
2877 owner->view()->update(TEXT(),
2878 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2881 TEXT()->sel_cursor = TEXT()->cursor;
2882 moveCursorUpdate(true, false);
2886 case LFUN_DIALOG_PREFERENCES:
2887 owner->getDialogs()->showPreferences();
2890 case LFUN_SAVEPREFERENCES:
2892 Path p(user_lyxdir);
2893 lyxrc.write("preferences");
2897 case LFUN_SCREEN_FONT_UPDATE:
2899 // handle the screen font changes.
2901 lyxrc.set_font_norm_type();
2902 fontloader.update();
2903 // Of course we should only do the resize and the textcache.clear
2904 // if values really changed...but not very important right now. (Lgb)
2905 // All buffers will need resize
2906 bufferlist.resize();
2907 // We also need to empty the textcache so that
2908 // the buffer will be formatted correctly after
2914 case LFUN_SET_COLOR:
2917 string const x11_name = split(argument, lyx_name, ' ');
2918 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"));
2929 setErrorMessage(_(err1) + lyx_name + _(err2));
2932 lyxColorHandler->updateColor(lcolor.getFromLyXName(lyx_name));
2933 owner->view()->redraw();
2937 case LFUN_UNKNOWN_ACTION:
2939 if (!owner->buffer()) {
2940 setErrorMessage(N_("No document open"));
2944 if (owner->buffer()->isReadonly()) {
2945 setErrorMessage(N_("Document is read only"));
2949 if (!argument.empty()) {
2951 /* Automatically delete the currently selected
2952 * text and replace it with what is being
2953 * typed in now. Depends on lyxrc settings
2954 * "auto_region_delete", which defaults to
2957 if (lyxrc.auto_region_delete) {
2958 if (TEXT()->selection){
2959 TEXT()->CutSelection(owner->view(), false);
2960 owner->view()->update(TEXT(),
2961 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2965 owner->view()->beforeChange(TEXT());
2966 LyXFont const old_font(TEXT()->real_current_font);
2967 for (string::size_type i = 0;
2968 i < argument.length(); ++i) {
2969 if (greek_kb_flag) {
2970 if (!math_insert_greek(owner->view(),
2972 owner->getIntl()->getTrans().TranslateAndInsert(argument[i], TEXT());
2974 owner->getIntl()->getTrans().TranslateAndInsert(argument[i], TEXT());
2977 owner->view()->update(TEXT(),
2978 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2980 TEXT()->sel_cursor =
2982 moveCursorUpdate(true, false);
2984 // real_current_font.number can change so we need to
2985 // update the minibuffer
2986 if (old_font != 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)
2993 setErrorMessage(N_("Unknown action"));
2999 lyxerr << "A truly unknown func!" << endl;
3004 string const res = getMessage();
3007 if (!commandshortcut.empty()) {
3008 string const newbuf =
3009 owner->getMiniBuffer()->GetText();
3010 if (newbuf != commandshortcut) {
3011 owner->getMiniBuffer()->Set(newbuf
3019 msg += commandshortcut;
3020 owner->getMiniBuffer()->Set(msg);
3027 void LyXFunc::setupLocalKeymap()
3029 keyseq.stdmap = keyseq.curmap = toplevel_keymap;
3030 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap;
3034 void LyXFunc::MenuNew(bool fromTemplate)
3036 string initpath = lyxrc.document_path;
3039 if (owner->view()->available()) {
3040 string const trypath = owner->buffer()->filepath;
3041 // If directory is writeable, use this as default.
3042 if (IsDirWriteable(trypath) == 1)
3046 static int newfile_number = 0;
3049 if (lyxrc.new_ask_filename) {
3050 ProhibitInput(owner->view());
3051 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
3052 fileDlg.SetButton(1, _("Templates"), lyxrc.template_path);
3053 string fname = fileDlg.Select(_("Enter Filename for new document"),
3054 initpath, "*.lyx", _("newfile"));
3055 AllowInput(owner->view());
3057 if (fname.empty()) {
3058 owner->getMiniBuffer()->Set(_("Canceled."));
3059 lyxerr.debug() << "New Document Cancelled." << endl;
3063 // get absolute path of file and make sure the filename ends
3065 s = MakeAbsPath(fname);
3066 if (!IsLyXFilename(s))
3069 // Check if the document already is open
3070 if (bufferlist.exists(s)) {
3071 switch (AskConfirmation(_("Document is already open:"),
3072 MakeDisplayPath(s, 50),
3073 _("Do you want to close that document now?\n"
3074 "('No' will just switch to the open version)")))
3076 case 1: // Yes: close the document
3077 if (!bufferlist.close(bufferlist.getBuffer(s)))
3078 // If close is canceled, we cancel here too.
3081 case 2: // No: switch to the open document
3082 owner->view()->buffer(bufferlist.getBuffer(s));
3084 case 3: // Cancel: Do nothing
3085 owner->getMiniBuffer()->Set(_("Canceled."));
3089 // Check whether the file already exists
3090 if (IsLyXFilename(s)) {
3092 if (fi.readable() &&
3093 AskQuestion(_("File already exists:"),
3094 MakeDisplayPath(s, 50),
3095 _("Do you want to open the document?"))) {
3097 owner->getMiniBuffer()->Set(_("Opening document"),
3098 MakeDisplayPath(s), "...");
3099 XFlush(fl_get_display());
3100 owner->view()->buffer(
3101 bufferlist.loadLyXFile(s));
3102 owner->getMiniBuffer()->Set(_("Document"),
3109 s = AddName(lyxrc.document_path,
3110 "newfile" + tostr(++newfile_number) + ".lyx");
3112 while (bufferlist.exists(s) || fi.readable()) {
3114 s = AddName(lyxrc.document_path,
3115 "newfile" + tostr(newfile_number) +
3121 // The template stuff
3124 ProhibitInput(owner->view());
3125 string const fname = fileDlg.Select(_("Choose template"),
3126 lyxrc.template_path,
3128 AllowInput(owner->view());
3129 if (fname.empty()) return;
3133 // find a free buffer
3134 lyxerr.debug() << "Find a free buffer." << endl;
3135 owner->view()->buffer(bufferlist.newFile(s, templname));
3139 void LyXFunc::MenuOpen()
3141 string initpath = lyxrc.document_path;
3144 if (owner->view()->available()) {
3145 string const trypath = owner->buffer()->filepath;
3146 // If directory is writeable, use this as default.
3147 if (IsDirWriteable(trypath) == 1)
3152 ProhibitInput(owner->view());
3153 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
3154 fileDlg.SetButton(1, _("Examples"),
3155 AddPath(system_lyxdir, "examples"));
3156 string filename = fileDlg.Select(_("Select Document to Open"),
3158 AllowInput(owner->view());
3160 // check selected filename
3161 if (filename.empty()) {
3162 owner->getMiniBuffer()->Set(_("Canceled."));
3166 // get absolute path of file and make sure the filename ends
3168 filename = MakeAbsPath(filename);
3169 if (!IsLyXFilename(filename))
3173 owner->getMiniBuffer()->Set(_("Opening document"),
3174 MakeDisplayPath(filename), "...");
3175 Buffer * openbuf = bufferlist.loadLyXFile(filename);
3177 owner->view()->buffer(openbuf);
3178 owner->getMiniBuffer()->Set(_("Document"),
3179 MakeDisplayPath(filename),
3182 owner->getMiniBuffer()->Set(_("Could not open document"),
3183 MakeDisplayPath(filename));
3188 // checks for running without gui are missing.
3189 void LyXFunc::doImport(string const & argument)
3192 string filename = split(argument, format, ' ');
3193 lyxerr.debug() << "LyXFunc::doImport: " << format
3194 << " file: " << filename << endl;
3196 if (filename.empty()) { // need user interaction
3197 string initpath = lyxrc.document_path;
3200 if (owner->view()->available()) {
3201 string const trypath = owner->buffer()->filepath;
3202 // If directory is writeable, use this as default.
3203 if (IsDirWriteable(trypath) == 1)
3208 ProhibitInput(owner->view());
3209 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
3210 fileDlg.SetButton(1, _("Examples"),
3211 AddPath(system_lyxdir, "examples"));
3212 string const text = _("Select ") + formats.PrettyName(format)
3213 + _(" file to import");
3214 string const extension = "*." + formats.Extension(format);
3215 filename = fileDlg.Select(text, initpath, extension);
3216 AllowInput(owner->view());
3218 // check selected filename
3219 if (filename.empty())
3220 owner->getMiniBuffer()->Set(_("Canceled."));
3223 // still no filename? abort
3224 if (filename.empty())
3227 // get absolute path of file
3228 filename = MakeAbsPath(filename);
3230 string const lyxfile = ChangeExtension(filename, ".lyx");
3232 // Check if the document already is open
3233 if (bufferlist.exists(lyxfile)) {
3234 switch (AskConfirmation(_("Document is already open:"),
3235 MakeDisplayPath(lyxfile, 50),
3236 _("Do you want to close that document now?\n"
3237 "('No' will just switch to the open version)")))
3239 case 1: // Yes: close the document
3240 if (!bufferlist.close(bufferlist.getBuffer(lyxfile)))
3241 // If close is canceled, we cancel here too.
3244 case 2: // No: switch to the open document
3245 owner->view()->buffer(bufferlist.getBuffer(lyxfile));
3247 case 3: // Cancel: Do nothing
3248 owner->getMiniBuffer()->Set(_("Canceled."));
3253 // Check if a LyX document by the same root exists in filesystem
3254 FileInfo const f(lyxfile, true);
3255 if (f.exist() && !AskQuestion(_("A document by the name"),
3256 MakeDisplayPath(lyxfile),
3257 _("already exists. Overwrite?"))) {
3258 owner->getMiniBuffer()->Set(_("Canceled."));
3261 // filename should be valid now
3263 Importer::Import(owner, filename, format);
3267 void LyXFunc::MenuInsertLyXFile(string const & filen)
3269 string filename = filen;
3271 if (filename.empty()) {
3272 // Launch a file browser
3273 string initpath = lyxrc.document_path;
3276 if (owner->view()->available()) {
3277 string const trypath = owner->buffer()->filepath;
3278 // If directory is writeable, use this as default.
3279 if (IsDirWriteable(trypath) == 1)
3284 ProhibitInput(owner->view());
3285 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
3286 fileDlg.SetButton(1, _("Examples"),
3287 AddPath(system_lyxdir, "examples"));
3288 filename = fileDlg.Select(_("Select Document to Insert"),
3290 AllowInput(owner->view());
3292 // check selected filename
3293 if (filename.empty()) {
3294 owner->getMiniBuffer()->Set(_("Canceled."));
3299 // get absolute path of file and make sure the filename ends
3301 filename = MakeAbsPath(filename);
3302 if (!IsLyXFilename(filename))
3306 owner->getMiniBuffer()->Set(_("Inserting document"),
3307 MakeDisplayPath(filename), "...");
3308 bool const res = owner->view()->insertLyXFile(filename);
3310 owner->getMiniBuffer()->Set(_("Document"),
3311 MakeDisplayPath(filename),
3314 owner->getMiniBuffer()->Set(_("Could not insert document"),
3315 MakeDisplayPath(filename));
3320 void LyXFunc::reloadBuffer()
3322 string const fn = owner->buffer()->fileName();
3323 if (bufferlist.close(owner->buffer()))
3324 owner->view()->buffer(bufferlist.loadLyXFile(fn));
3328 void LyXFunc::CloseBuffer()
3330 if (bufferlist.close(owner->buffer()) && !quitting) {
3331 if (bufferlist.empty()) {
3332 // need this otherwise SEGV may occur while trying to
3333 // set variables that don't exist
3334 // since there's no current buffer
3335 owner->getDialogs()->hideBufferDependent();
3337 owner->view()->buffer(bufferlist.first());
3343 Inset * LyXFunc::getInsetByCode(Inset::Code code)
3345 LyXCursor cursor = TEXT()->cursor;
3346 Buffer * buffer = owner->view()->buffer();
3347 Buffer::inset_iterator it =
3348 find_if(Buffer::inset_iterator(cursor.par(),
3350 buffer->inset_iterator_end(),
3351 compare_memfun(&Inset::LyxCode, code));
3352 return it != buffer->inset_iterator_end() ? (*it) : 0;
3356 // Each "owner" should have it's own message method. lyxview and
3357 // the minibuffer would use the minibuffer, but lyxserver would
3358 // send an ERROR signal to its client. Alejandro 970603
3359 // This func is bit problematic when it comes to NLS, to make the
3360 // lyx servers client be language indepenent we must not translate
3361 // strings sent to this func.
3362 void LyXFunc::setErrorMessage(string const & m) const
3364 dispatch_buffer = m;
3369 void LyXFunc::setMessage(string const & m)
3371 dispatch_buffer = m;