3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Asger Alstrup
7 * \author Lars Gullik Bjønnes
8 * \author Alfredo Braunstein
9 * \author Angus Leeming
11 * \author André Pönitz
13 * Full author contact details are available in file CREDITS.
21 #include "BranchList.h"
22 #include "FloatList.h"
23 #include "FuncStatus.h"
25 #include "buffer_funcs.h"
26 #include "BufferParams.h"
27 #include "BufferView.h"
30 #include "CutAndPaste.h"
31 #include "DispatchResult.h"
32 #include "ErrorList.h"
34 #include "FuncRequest.h"
35 #include "InsetList.h"
39 #include "LyXAction.h"
43 #include "Paragraph.h"
44 #include "ParagraphParameters.h"
45 #include "SpellChecker.h"
46 #include "TextClass.h"
47 #include "TextMetrics.h"
48 #include "WordLangTuple.h"
50 #include "frontends/Application.h"
51 #include "frontends/Clipboard.h"
52 #include "frontends/Selection.h"
54 #include "insets/InsetArgument.h"
55 #include "insets/InsetCollapsable.h"
56 #include "insets/InsetCommand.h"
57 #include "insets/InsetExternal.h"
58 #include "insets/InsetFloat.h"
59 #include "insets/InsetFloatList.h"
60 #include "insets/InsetGraphics.h"
61 #include "insets/InsetGraphicsParams.h"
62 #include "insets/InsetIPAMacro.h"
63 #include "insets/InsetNewline.h"
64 #include "insets/InsetQuotes.h"
65 #include "insets/InsetSpecialChar.h"
66 #include "insets/InsetText.h"
67 #include "insets/InsetWrap.h"
69 #include "support/convert.h"
70 #include "support/debug.h"
71 #include "support/gettext.h"
72 #include "support/lassert.h"
73 #include "support/lstrings.h"
74 #include "support/lyxtime.h"
75 #include "support/os.h"
76 #include "support/regex.h"
78 #include "mathed/InsetMathHull.h"
79 #include "mathed/MathMacroTemplate.h"
81 #include <boost/next_prior.hpp>
87 using namespace lyx::support;
91 using cap::copySelection;
92 using cap::cutSelection;
93 using cap::pasteFromStack;
94 using cap::pasteClipboardText;
95 using cap::pasteClipboardGraphics;
96 using cap::replaceSelection;
97 using cap::grabAndEraseSelection;
98 using cap::selClearOrDel;
99 using cap::pasteSimpleText;
102 static Font freefont(ignore_font, ignore_language);
103 static bool toggleall = false;
105 static void toggleAndShow(Cursor & cur, Text * text,
106 Font const & font, bool toggleall = true)
108 text->toggleFree(cur, font, toggleall);
110 if (font.language() != ignore_language ||
111 font.fontInfo().number() != FONT_IGNORE) {
112 TextMetrics const & tm = cur.bv().textMetrics(text);
113 if (cur.boundary() != tm.isRTLBoundary(cur.pit(), cur.pos(),
114 cur.real_current_font))
115 text->setCursor(cur, cur.pit(), cur.pos(),
116 false, !cur.boundary());
121 static void moveCursor(Cursor & cur, bool selecting)
123 if (selecting || cur.mark())
128 static void finishChange(Cursor & cur, bool selecting)
131 moveCursor(cur, selecting);
135 static void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
138 docstring sel = cur.selectionAsString(false);
140 // It may happen that sel is empty but there is a selection
141 replaceSelection(cur);
143 // Is this a valid formula?
147 #ifdef ENABLE_ASSERTIONS
148 const int old_pos = cur.pos();
150 cur.insert(new InsetMathHull(cur.buffer(), hullSimple));
151 #ifdef ENABLE_ASSERTIONS
152 LATTEST(old_pos == cur.pos());
154 cur.nextInset()->edit(cur, true);
155 // don't do that also for LFUN_MATH_MODE
156 // unless you want end up with always changing
157 // to mathrm when opening an inlined inset --
158 // I really hate "LyXfunc overloading"...
160 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
161 // Avoid an unnecessary undo step if cmd.argument
163 if (!cmd.argument().empty())
164 cur.dispatch(FuncRequest(LFUN_MATH_INSERT,
167 // create a macro if we see "\\newcommand"
168 // somewhere, and an ordinary formula
170 if (sel.find(from_ascii("\\newcommand")) == string::npos
171 && sel.find(from_ascii("\\newlyxcommand")) == string::npos
172 && sel.find(from_ascii("\\def")) == string::npos)
174 InsetMathHull * formula = new InsetMathHull(cur.buffer());
175 string const selstr = to_utf8(sel);
176 istringstream is(selstr);
179 if (!formula->readQuiet(lex)) {
180 // No valid formula, let's try with delims
181 is.str("$" + selstr + "$");
183 if (!formula->readQuiet(lex)) {
184 // Still not valid, leave it as is
193 cur.insert(new MathMacroTemplate(cur.buffer(), sel));
197 cur.message(from_utf8(N_("Math editor mode")));
199 cur.message(from_utf8(N_("No valid math formula")));
203 void regexpDispatch(Cursor & cur, FuncRequest const & cmd)
205 LASSERT(cmd.action() == LFUN_REGEXP_MODE, return);
206 if (cur.inRegexped()) {
207 cur.message(_("Already in regular expression mode"));
211 docstring sel = cur.selectionAsString(false);
213 // It may happen that sel is empty but there is a selection
214 replaceSelection(cur);
216 cur.insert(new InsetMathHull(cur.buffer(), hullRegexp));
217 cur.nextInset()->edit(cur, true);
220 cur.message(_("Regexp editor mode"));
224 static void specialChar(Cursor & cur, InsetSpecialChar::Kind kind)
227 cap::replaceSelection(cur);
228 cur.insert(new InsetSpecialChar(kind));
233 static void ipaChar(Cursor & cur, InsetIPAChar::Kind kind)
236 cap::replaceSelection(cur);
237 cur.insert(new InsetIPAChar(kind));
242 static bool doInsertInset(Cursor & cur, Text * text,
243 FuncRequest const & cmd, bool edit, bool pastesel)
245 Buffer & buffer = cur.bv().buffer();
246 BufferParams const & bparams = buffer.params();
247 Inset * inset = createInset(&buffer, cmd);
251 if (InsetCollapsable * ci = inset->asInsetCollapsable())
252 ci->setButtonLabel();
255 if (cmd.action() == LFUN_INDEX_INSERT) {
256 docstring ds = subst(text->getStringToIndex(cur), '\n', ' ');
257 text->insertInset(cur, inset);
259 inset->edit(cur, true);
260 // Now put this into inset
261 Font const f(inherit_font, cur.current_font.language());
263 cur.text()->insertStringAsLines(cur, ds, f);
264 cur.leaveInset(*inset);
270 if (cur.selection()) {
271 cutSelection(cur, false, pastesel);
272 cur.clearSelection();
275 text->insertInset(cur, inset);
278 inset->edit(cur, true);
280 if (!gotsel || !pastesel)
283 pasteFromStack(cur, cur.buffer()->errorList("Paste"), 0);
284 cur.buffer()->errors("Paste");
285 cur.clearSelection(); // bug 393
287 InsetText * inset_text = inset->asInsetText();
289 inset_text->fixParagraphsFont();
290 if (!inset_text->allowMultiPar() || cur.lastpit() == 0) {
291 // reset first par to default
292 cur.text()->paragraphs().begin()
293 ->setPlainOrDefaultLayout(bparams.documentClass());
296 // Merge multiple paragraphs -- hack
297 while (cur.lastpit() > 0)
298 mergeParagraph(bparams, cur.text()->paragraphs(), 0);
299 if (cmd.action() == LFUN_FLEX_INSERT)
302 cur.leaveInset(*inset);
303 if (cmd.action() == LFUN_PREVIEW_INSERT
304 || cmd.action() == LFUN_IPA_INSERT)
306 notifyCursorLeavesOrEnters(old, cur);
309 cur.leaveInset(*inset);
310 // reset surrounding par to default
311 DocumentClass const & dc = bparams.documentClass();
312 docstring const layoutname = inset->usePlainLayout()
313 ? dc.plainLayoutName()
314 : dc.defaultLayoutName();
315 text->setLayout(cur, layoutname);
321 string const freefont2string()
323 return freefont.toString(toggleall);
327 /// the type of outline operation
329 OutlineUp, // Move this header with text down
330 OutlineDown, // Move this header with text up
331 OutlineIn, // Make this header deeper
332 OutlineOut // Make this header shallower
336 static void outline(OutlineOp mode, Cursor & cur)
338 Buffer & buf = *cur.buffer();
339 pit_type & pit = cur.pit();
340 ParagraphList & pars = buf.text().paragraphs();
341 ParagraphList::iterator const bgn = pars.begin();
342 // The first paragraph of the area to be copied:
343 ParagraphList::iterator start = boost::next(bgn, pit);
344 // The final paragraph of area to be copied:
345 ParagraphList::iterator finish = start;
346 ParagraphList::iterator const end = pars.end();
348 DocumentClass const & tc = buf.params().documentClass();
350 int const thistoclevel = buf.text().getTocLevel(distance(bgn, start));
353 // Move out (down) from this section header
357 // Seek the one (on same level) below
358 for (; finish != end; ++finish) {
359 toclevel = buf.text().getTocLevel(distance(bgn, finish));
360 if (toclevel != Layout::NOT_IN_TOC && toclevel <= thistoclevel)
366 if (start == pars.begin())
369 ParagraphList::iterator dest = start;
370 // Move out (up) from this header
373 // Search previous same-level header above
376 toclevel = buf.text().getTocLevel(distance(bgn, dest));
378 && (toclevel == Layout::NOT_IN_TOC
379 || toclevel > thistoclevel));
380 // Not found; do nothing
381 if (toclevel == Layout::NOT_IN_TOC || toclevel > thistoclevel)
383 pit_type const newpit = distance(bgn, dest);
384 pit_type const len = distance(start, finish);
385 pit_type const deletepit = pit + len;
386 buf.undo().recordUndo(cur, ATOMIC_UNDO, newpit, deletepit - 1);
387 pars.splice(dest, start, finish);
395 // Go one down from *this* header:
396 ParagraphList::iterator dest = boost::next(finish, 1);
397 // Go further down to find header to insert in front of:
398 for (; dest != end; ++dest) {
399 toclevel = buf.text().getTocLevel(distance(bgn, dest));
400 if (toclevel != Layout::NOT_IN_TOC
401 && toclevel <= thistoclevel)
404 // One such was found:
405 pit_type newpit = distance(bgn, dest);
406 buf.undo().recordUndo(cur, ATOMIC_UNDO, pit, newpit - 1);
407 pit_type const len = distance(start, finish);
408 pars.splice(dest, start, finish);
409 cur.pit() = newpit - len;
413 pit_type const len = distance(start, finish);
414 buf.undo().recordUndo(cur, ATOMIC_UNDO, pit, pit + len - 1);
415 for (; start != finish; ++start) {
416 toclevel = buf.text().getTocLevel(distance(bgn, start));
417 if (toclevel == Layout::NOT_IN_TOC)
419 DocumentClass::const_iterator lit = tc.begin();
420 DocumentClass::const_iterator len = tc.end();
421 for (; lit != len; ++lit) {
422 if (lit->toclevel == toclevel + 1 &&
423 start->layout().labeltype == lit->labeltype) {
424 start->setLayout(*lit);
432 pit_type const len = distance(start, finish);
433 buf.undo().recordUndo(cur, ATOMIC_UNDO, pit, pit + len - 1);
434 for (; start != finish; ++start) {
435 toclevel = buf.text().getTocLevel(distance(bgn, start));
436 if (toclevel == Layout::NOT_IN_TOC)
438 DocumentClass::const_iterator lit = tc.begin();
439 DocumentClass::const_iterator len = tc.end();
440 for (; lit != len; ++lit) {
441 if (lit->toclevel == toclevel - 1 &&
442 start->layout().labeltype == lit->labeltype) {
443 start->setLayout(*lit);
454 void Text::number(Cursor & cur)
456 FontInfo font = ignore_font;
457 font.setNumber(FONT_TOGGLE);
458 toggleAndShow(cur, this, Font(font, ignore_language));
462 bool Text::isRTL(Paragraph const & par) const
464 Buffer const & buffer = owner_->buffer();
465 return par.isRTL(buffer.params());
469 void Text::dispatch(Cursor & cur, FuncRequest & cmd)
471 LYXERR(Debug::ACTION, "Text::dispatch: cmd: " << cmd);
473 // Dispatch if the cursor is inside the text. It is not the
474 // case for context menus (bug 5797).
475 if (cur.text() != this) {
480 BufferView * bv = &cur.bv();
481 TextMetrics * tm = &bv->textMetrics(this);
482 if (!tm->contains(cur.pit())) {
483 lyx::dispatch(FuncRequest(LFUN_SCREEN_SHOW_CURSOR));
484 tm = &bv->textMetrics(this);
487 // FIXME: We use the update flag to indicates wether a singlePar or a
488 // full screen update is needed. We reset it here but shall we restore it
490 cur.noScreenUpdate();
492 LBUFERR(this == cur.text());
493 CursorSlice const oldTopSlice = cur.top();
494 bool const oldBoundary = cur.boundary();
495 bool const oldSelection = cur.selection();
496 // Signals that, even if needsUpdate == false, an update of the
497 // cursor paragraph is required
498 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action(),
499 LyXAction::SingleParUpdate);
500 // Signals that a full-screen update is required
501 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action(),
502 LyXAction::NoUpdate) || singleParUpdate);
503 bool const last_misspelled = lyxrc.spellcheck_continuously
504 && cur.paragraph().isMisspelled(cur.pos(), true);
506 FuncCode const act = cmd.action();
509 case LFUN_PARAGRAPH_MOVE_DOWN: {
510 pit_type const pit = cur.pit();
511 recUndo(cur, pit, pit + 1);
513 pars_.swap(pit, pit + 1);
515 cur.forceBufferUpdate();
520 case LFUN_PARAGRAPH_MOVE_UP: {
521 pit_type const pit = cur.pit();
522 recUndo(cur, pit - 1, pit);
524 pars_.swap(pit, pit - 1);
527 cur.forceBufferUpdate();
531 case LFUN_APPENDIX: {
532 Paragraph & par = cur.paragraph();
533 bool start = !par.params().startOfAppendix();
535 // FIXME: The code below only makes sense at top level.
536 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
537 // ensure that we have only one start_of_appendix in this document
538 // FIXME: this don't work for multipart document!
539 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
540 if (pars_[tmp].params().startOfAppendix()) {
542 pars_[tmp].params().startOfAppendix(false);
548 par.params().startOfAppendix(start);
550 // we can set the refreshing parameters now
551 cur.forceBufferUpdate();
555 case LFUN_WORD_DELETE_FORWARD:
557 cutSelection(cur, true, false);
559 deleteWordForward(cur);
560 finishChange(cur, false);
563 case LFUN_WORD_DELETE_BACKWARD:
565 cutSelection(cur, true, false);
567 deleteWordBackward(cur);
568 finishChange(cur, false);
571 case LFUN_LINE_DELETE_FORWARD:
573 cutSelection(cur, true, false);
575 tm->deleteLineForward(cur);
576 finishChange(cur, false);
579 case LFUN_BUFFER_BEGIN:
580 case LFUN_BUFFER_BEGIN_SELECT:
581 needsUpdate |= cur.selHandle(act == LFUN_BUFFER_BEGIN_SELECT);
582 if (cur.depth() == 1)
583 needsUpdate |= cursorTop(cur);
586 cur.screenUpdateFlags(Update::FitCursor);
589 case LFUN_BUFFER_END:
590 case LFUN_BUFFER_END_SELECT:
591 needsUpdate |= cur.selHandle(act == LFUN_BUFFER_END_SELECT);
592 if (cur.depth() == 1)
593 needsUpdate |= cursorBottom(cur);
596 cur.screenUpdateFlags(Update::FitCursor);
599 case LFUN_INSET_BEGIN:
600 case LFUN_INSET_BEGIN_SELECT:
601 needsUpdate |= cur.selHandle(act == LFUN_INSET_BEGIN_SELECT);
602 if (cur.depth() == 1 || !cur.top().at_begin())
603 needsUpdate |= cursorTop(cur);
606 cur.screenUpdateFlags(Update::FitCursor);
610 case LFUN_INSET_END_SELECT:
611 needsUpdate |= cur.selHandle(act == LFUN_INSET_END_SELECT);
612 if (cur.depth() == 1 || !cur.top().at_end())
613 needsUpdate |= cursorBottom(cur);
616 cur.screenUpdateFlags(Update::FitCursor);
619 case LFUN_INSET_SELECT_ALL:
620 if (cur.depth() == 1 || !cur.selection() || !cur.selBegin().at_begin()
621 || !cur.selEnd().at_end()) {
622 needsUpdate |= cur.selHandle(false);
623 needsUpdate |= cursorTop(cur);
624 needsUpdate |= cur.selHandle(true);
625 needsUpdate |= cursorBottom(cur);
628 cur.screenUpdateFlags(Update::FitCursor);
631 case LFUN_CHAR_FORWARD:
632 case LFUN_CHAR_FORWARD_SELECT:
633 //LYXERR0(" LFUN_CHAR_FORWARD[SEL]:\n" << cur);
634 needsUpdate |= cur.selHandle(act == LFUN_CHAR_FORWARD_SELECT);
635 needsUpdate |= cursorForward(cur);
637 if (!needsUpdate && oldTopSlice == cur.top()
638 && cur.boundary() == oldBoundary) {
640 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
642 // we will probably be moving out the inset, so we should execute
643 // the depm-mechanism, but only when the cursor has a place to
644 // go outside this inset, i.e. in a slice above.
645 if (cur.depth() > 1 && cur.pos() == cur.lastpos()
646 && cur.pit() == cur.lastpit()) {
647 // The cursor hasn't changed yet. To give the
648 // DEPM the possibility of doing something we must
649 // provide it with two different cursors.
651 dummy.pos() = dummy.pit() = 0;
652 if (cur.bv().checkDepm(dummy, cur))
653 cur.forceBufferUpdate();
658 case LFUN_CHAR_BACKWARD:
659 case LFUN_CHAR_BACKWARD_SELECT:
660 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
661 needsUpdate |= cur.selHandle(act == LFUN_CHAR_BACKWARD_SELECT);
662 needsUpdate |= cursorBackward(cur);
664 if (!needsUpdate && oldTopSlice == cur.top()
665 && cur.boundary() == oldBoundary) {
667 cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
669 // we will probably be moving out the inset, so we should execute
670 // the depm-mechanism, but only when the cursor has a place to
671 // go outside this inset, i.e. in a slice above.
672 if (cur.depth() > 1 && cur.pos() == 0 && cur.pit() == 0) {
673 // The cursor hasn't changed yet. To give the
674 // DEPM the possibility of doing something we must
675 // provide it with two different cursors.
677 dummy.pos() = cur.lastpos();
678 dummy.pit() = cur.lastpit();
679 if (cur.bv().checkDepm(dummy, cur))
680 cur.forceBufferUpdate();
686 case LFUN_CHAR_LEFT_SELECT:
687 if (lyxrc.visual_cursor) {
688 needsUpdate |= cur.selHandle(act == LFUN_CHAR_LEFT_SELECT);
689 needsUpdate |= cursorVisLeft(cur);
690 if (!needsUpdate && oldTopSlice == cur.top()
691 && cur.boundary() == oldBoundary) {
693 cmd = FuncRequest(LFUN_FINISHED_LEFT);
696 if (reverseDirectionNeeded(cur)) {
697 cmd.setAction(cmd.action() == LFUN_CHAR_LEFT_SELECT ?
698 LFUN_CHAR_FORWARD_SELECT : LFUN_CHAR_FORWARD);
700 cmd.setAction(cmd.action() == LFUN_CHAR_LEFT_SELECT ?
701 LFUN_CHAR_BACKWARD_SELECT : LFUN_CHAR_BACKWARD);
708 case LFUN_CHAR_RIGHT:
709 case LFUN_CHAR_RIGHT_SELECT:
710 if (lyxrc.visual_cursor) {
711 needsUpdate |= cur.selHandle(cmd.action() == LFUN_CHAR_RIGHT_SELECT);
712 needsUpdate |= cursorVisRight(cur);
713 if (!needsUpdate && oldTopSlice == cur.top()
714 && cur.boundary() == oldBoundary) {
716 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
719 if (reverseDirectionNeeded(cur)) {
720 cmd.setAction(cmd.action() == LFUN_CHAR_RIGHT_SELECT ?
721 LFUN_CHAR_BACKWARD_SELECT : LFUN_CHAR_BACKWARD);
723 cmd.setAction(cmd.action() == LFUN_CHAR_RIGHT_SELECT ?
724 LFUN_CHAR_FORWARD_SELECT : LFUN_CHAR_FORWARD);
733 case LFUN_DOWN_SELECT:
736 // stop/start the selection
737 bool select = cmd.action() == LFUN_DOWN_SELECT ||
738 cmd.action() == LFUN_UP_SELECT;
740 // move cursor up/down
741 bool up = cmd.action() == LFUN_UP_SELECT || cmd.action() == LFUN_UP;
742 bool const atFirstOrLastRow = cur.atFirstOrLastRow(up);
744 if (!atFirstOrLastRow) {
745 needsUpdate |= cur.selHandle(select);
746 cur.selHandle(select);
747 cur.upDownInText(up, needsUpdate);
748 needsUpdate |= cur.beforeDispatchCursor().inMathed();
750 // if the cursor cannot be moved up or down do not remove
751 // the selection right now, but wait for the next dispatch.
753 needsUpdate |= cur.selHandle(select);
754 cur.upDownInText(up, needsUpdate);
761 case LFUN_PARAGRAPH_UP:
762 case LFUN_PARAGRAPH_UP_SELECT:
763 needsUpdate |= cur.selHandle(cmd.action() == LFUN_PARAGRAPH_UP_SELECT);
764 needsUpdate |= cursorUpParagraph(cur);
767 case LFUN_PARAGRAPH_DOWN:
768 case LFUN_PARAGRAPH_DOWN_SELECT:
769 needsUpdate |= cur.selHandle(cmd.action() == LFUN_PARAGRAPH_DOWN_SELECT);
770 needsUpdate |= cursorDownParagraph(cur);
773 case LFUN_LINE_BEGIN:
774 case LFUN_LINE_BEGIN_SELECT:
775 needsUpdate |= cur.selHandle(cmd.action() == LFUN_LINE_BEGIN_SELECT);
776 needsUpdate |= tm->cursorHome(cur);
780 case LFUN_LINE_END_SELECT:
781 needsUpdate |= cur.selHandle(cmd.action() == LFUN_LINE_END_SELECT);
782 needsUpdate |= tm->cursorEnd(cur);
785 case LFUN_SECTION_SELECT: {
786 Buffer const & buf = *cur.buffer();
787 pit_type const pit = cur.pit();
788 ParagraphList & pars = buf.text().paragraphs();
789 ParagraphList::iterator bgn = pars.begin();
790 // The first paragraph of the area to be selected:
791 ParagraphList::iterator start = boost::next(bgn, pit);
792 // The final paragraph of area to be selected:
793 ParagraphList::iterator finish = start;
794 ParagraphList::iterator end = pars.end();
796 int const thistoclevel = buf.text().getTocLevel(distance(bgn, start));
797 if (thistoclevel == Layout::NOT_IN_TOC)
801 Cursor const old_cur = cur;
802 needsUpdate |= cur.selHandle(true);
804 // Move out (down) from this section header
808 // Seek the one (on same level) below
809 for (; finish != end; ++finish, ++cur.pit()) {
810 int const toclevel = buf.text().getTocLevel(distance(bgn, finish));
811 if (toclevel != Layout::NOT_IN_TOC && toclevel <= thistoclevel)
814 cur.pos() = cur.lastpos();
816 needsUpdate |= cur != old_cur;
820 case LFUN_WORD_RIGHT:
821 case LFUN_WORD_RIGHT_SELECT:
822 if (lyxrc.visual_cursor) {
823 needsUpdate |= cur.selHandle(cmd.action() == LFUN_WORD_RIGHT_SELECT);
824 needsUpdate |= cursorVisRightOneWord(cur);
825 if (!needsUpdate && oldTopSlice == cur.top()
826 && cur.boundary() == oldBoundary) {
828 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
831 if (reverseDirectionNeeded(cur)) {
832 cmd.setAction(cmd.action() == LFUN_WORD_RIGHT_SELECT ?
833 LFUN_WORD_BACKWARD_SELECT : LFUN_WORD_BACKWARD);
835 cmd.setAction(cmd.action() == LFUN_WORD_RIGHT_SELECT ?
836 LFUN_WORD_FORWARD_SELECT : LFUN_WORD_FORWARD);
843 case LFUN_WORD_FORWARD:
844 case LFUN_WORD_FORWARD_SELECT:
845 needsUpdate |= cur.selHandle(cmd.action() == LFUN_WORD_FORWARD_SELECT);
846 needsUpdate |= cursorForwardOneWord(cur);
848 if (!needsUpdate && oldTopSlice == cur.top()
849 && cur.boundary() == oldBoundary) {
851 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
853 // we will probably be moving out the inset, so we should execute
854 // the depm-mechanism, but only when the cursor has a place to
855 // go outside this inset, i.e. in a slice above.
856 if (cur.depth() > 1 && cur.pos() == cur.lastpos()
857 && cur.pit() == cur.lastpit()) {
858 // The cursor hasn't changed yet. To give the
859 // DEPM the possibility of doing something we must
860 // provide it with two different cursors.
862 dummy.pos() = dummy.pit() = 0;
863 if (cur.bv().checkDepm(dummy, cur))
864 cur.forceBufferUpdate();
870 case LFUN_WORD_LEFT_SELECT:
871 if (lyxrc.visual_cursor) {
872 needsUpdate |= cur.selHandle(cmd.action() == LFUN_WORD_LEFT_SELECT);
873 needsUpdate |= cursorVisLeftOneWord(cur);
874 if (!needsUpdate && oldTopSlice == cur.top()
875 && cur.boundary() == oldBoundary) {
877 cmd = FuncRequest(LFUN_FINISHED_LEFT);
880 if (reverseDirectionNeeded(cur)) {
881 cmd.setAction(cmd.action() == LFUN_WORD_LEFT_SELECT ?
882 LFUN_WORD_FORWARD_SELECT : LFUN_WORD_FORWARD);
884 cmd.setAction(cmd.action() == LFUN_WORD_LEFT_SELECT ?
885 LFUN_WORD_BACKWARD_SELECT : LFUN_WORD_BACKWARD);
892 case LFUN_WORD_BACKWARD:
893 case LFUN_WORD_BACKWARD_SELECT:
894 needsUpdate |= cur.selHandle(cmd.action() == LFUN_WORD_BACKWARD_SELECT);
895 needsUpdate |= cursorBackwardOneWord(cur);
897 if (!needsUpdate && oldTopSlice == cur.top()
898 && cur.boundary() == oldBoundary) {
900 cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
902 // we will probably be moving out the inset, so we should execute
903 // the depm-mechanism, but only when the cursor has a place to
904 // go outside this inset, i.e. in a slice above.
905 if (cur.depth() > 1 && cur.pos() == 0
907 // The cursor hasn't changed yet. To give the
908 // DEPM the possibility of doing something we must
909 // provide it with two different cursors.
911 dummy.pos() = cur.lastpos();
912 dummy.pit() = cur.lastpit();
913 if (cur.bv().checkDepm(dummy, cur))
914 cur.forceBufferUpdate();
919 case LFUN_WORD_SELECT: {
920 selectWord(cur, WHOLE_WORD);
921 finishChange(cur, true);
925 case LFUN_NEWLINE_INSERT: {
926 InsetNewlineParams inp;
927 docstring arg = cmd.argument();
928 if (arg == "linebreak")
929 inp.kind = InsetNewlineParams::LINEBREAK;
931 inp.kind = InsetNewlineParams::NEWLINE;
932 cap::replaceSelection(cur);
934 cur.insert(new InsetNewline(inp));
936 moveCursor(cur, false);
940 case LFUN_TAB_INSERT: {
941 bool const multi_par_selection = cur.selection() &&
942 cur.selBegin().pit() != cur.selEnd().pit();
943 if (multi_par_selection) {
944 // If there is a multi-paragraph selection, a tab is inserted
945 // at the beginning of each paragraph.
946 cur.recordUndoSelection();
947 pit_type const pit_end = cur.selEnd().pit();
948 for (pit_type pit = cur.selBegin().pit(); pit <= pit_end; pit++) {
949 pars_[pit].insertChar(0, '\t',
950 bv->buffer().params().trackChanges);
951 // Update the selection pos to make sure the selection does not
952 // change as the inserted tab will increase the logical pos.
953 if (cur.realAnchor().pit() == pit)
954 cur.realAnchor().forwardPos();
955 if (cur.pit() == pit)
960 // Maybe we shouldn't allow tabs within a line, because they
961 // are not (yet) aligned as one might do expect.
962 FuncRequest cmd(LFUN_SELF_INSERT, from_ascii("\t"));
968 case LFUN_TAB_DELETE: {
969 bool const tc = bv->buffer().params().trackChanges;
970 if (cur.selection()) {
971 // If there is a selection, a tab (if present) is removed from
972 // the beginning of each paragraph.
973 cur.recordUndoSelection();
974 pit_type const pit_end = cur.selEnd().pit();
975 for (pit_type pit = cur.selBegin().pit(); pit <= pit_end; pit++) {
976 Paragraph & par = paragraphs()[pit];
979 char_type const c = par.getChar(0);
980 if (c == '\t' || c == ' ') {
981 // remove either 1 tab or 4 spaces.
982 int const n = (c == ' ' ? 4 : 1);
983 for (int i = 0; i < n
984 && !par.empty() && par.getChar(0) == c; ++i) {
985 if (cur.pit() == pit)
987 if (cur.realAnchor().pit() == pit
988 && cur.realAnchor().pos() > 0 )
989 cur.realAnchor().backwardPos();
990 par.eraseChar(0, tc);
996 // If there is no selection, try to remove a tab or some spaces
997 // before the position of the cursor.
998 Paragraph & par = paragraphs()[cur.pit()];
999 pos_type const pos = cur.pos();
1004 char_type const c = par.getChar(pos - 1);
1008 par.eraseChar(cur.pos(), tc);
1010 for (int n_spaces = 0;
1012 && par.getChar(cur.pos() - 1) == ' '
1016 par.eraseChar(cur.pos(), tc);
1023 case LFUN_CHAR_DELETE_FORWARD:
1024 if (!cur.selection()) {
1025 if (cur.pos() == cur.paragraph().size())
1026 // Par boundary, force full-screen update
1027 singleParUpdate = false;
1028 needsUpdate |= erase(cur);
1030 // It is possible to make it a lot faster still
1031 // just comment out the line below...
1033 cutSelection(cur, true, false);
1034 singleParUpdate = false;
1036 moveCursor(cur, false);
1039 case LFUN_CHAR_DELETE_BACKWARD:
1040 if (!cur.selection()) {
1041 if (bv->getIntl().getTransManager().backspace()) {
1042 // Par boundary, full-screen update
1044 singleParUpdate = false;
1045 needsUpdate |= backspace(cur);
1047 // It is possible to make it a lot faster still
1048 // just comment out the line below...
1051 cutSelection(cur, true, false);
1052 singleParUpdate = false;
1056 case LFUN_PARAGRAPH_BREAK:
1057 cap::replaceSelection(cur);
1058 breakParagraph(cur, cmd.argument() == "inverse");
1062 case LFUN_INSET_INSERT: {
1065 // We have to avoid triggering InstantPreview loading
1066 // before inserting into the document. See bug #5626.
1067 bool loaded = bv->buffer().isFullyLoaded();
1068 bv->buffer().setFullyLoaded(false);
1069 Inset * inset = createInset(&bv->buffer(), cmd);
1070 bv->buffer().setFullyLoaded(loaded);
1073 // FIXME (Abdel 01/02/2006):
1074 // What follows would be a partial fix for bug 2154:
1075 // http://www.lyx.org/trac/ticket/2154
1076 // This automatically put the label inset _after_ a
1077 // numbered section. It should be possible to extend the mechanism
1078 // to any kind of LateX environement.
1079 // The correct way to fix that bug would be at LateX generation.
1080 // I'll let the code here for reference as it could be used for some
1081 // other feature like "automatic labelling".
1083 Paragraph & par = pars_[cur.pit()];
1084 if (inset->lyxCode() == LABEL_CODE
1085 && !par.layout().counter.empty() {
1086 // Go to the end of the paragraph
1087 // Warning: Because of Change-Tracking, the last
1088 // position is 'size()' and not 'size()-1':
1089 cur.pos() = par.size();
1090 // Insert a new paragraph
1091 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
1095 if (cur.selection())
1096 cutSelection(cur, true, false);
1098 if (inset->editable() && inset->asInsetText())
1099 inset->edit(cur, true);
1103 // trigger InstantPreview now
1104 if (inset->lyxCode() == EXTERNAL_CODE) {
1105 InsetExternal & ins =
1106 static_cast<InsetExternal &>(*inset);
1107 ins.updatePreview();
1114 case LFUN_INSET_DISSOLVE: {
1115 if (dissolveInset(cur)) {
1117 cur.forceBufferUpdate();
1122 case LFUN_SET_GRAPHICS_GROUP: {
1123 InsetGraphics * ins = graphics::getCurrentGraphicsInset(cur);
1129 string id = to_utf8(cmd.argument());
1130 string grp = graphics::getGroupParams(bv->buffer(), id);
1131 InsetGraphicsParams tmp, inspar = ins->getParams();
1134 inspar.groupId = to_utf8(cmd.argument());
1136 InsetGraphics::string2params(grp, bv->buffer(), tmp);
1137 tmp.filename = inspar.filename;
1141 ins->setParams(inspar);
1144 case LFUN_SPACE_INSERT:
1145 if (cur.paragraph().layout().free_spacing)
1146 insertChar(cur, ' ');
1148 doInsertInset(cur, this, cmd, false, false);
1151 moveCursor(cur, false);
1154 case LFUN_SPECIALCHAR_INSERT: {
1155 string const name = to_utf8(cmd.argument());
1156 if (name == "hyphenation")
1157 specialChar(cur, InsetSpecialChar::HYPHENATION);
1158 else if (name == "ligature-break")
1159 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
1160 else if (name == "slash")
1161 specialChar(cur, InsetSpecialChar::SLASH);
1162 else if (name == "nobreakdash")
1163 specialChar(cur, InsetSpecialChar::NOBREAKDASH);
1164 else if (name == "dots")
1165 specialChar(cur, InsetSpecialChar::LDOTS);
1166 else if (name == "end-of-sentence")
1167 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
1168 else if (name == "menu-separator")
1169 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
1170 else if (name.empty())
1171 lyxerr << "LyX function 'specialchar-insert' needs an argument." << endl;
1173 lyxerr << "Wrong argument for LyX function 'specialchar-insert'." << endl;
1177 case LFUN_IPAMACRO_INSERT: {
1178 string const arg = cmd.getArg(0);
1179 if (arg == "deco") {
1180 // Open the inset, and move the current selection
1182 doInsertInset(cur, this, cmd, true, true);
1184 // Some insets are numbered, others are shown in the outline pane so
1185 // let's update the labels and the toc backend.
1186 cur.forceBufferUpdate();
1189 if (arg == "tone-falling")
1190 ipaChar(cur, InsetIPAChar::TONE_FALLING);
1191 else if (arg == "tone-rising")
1192 ipaChar(cur, InsetIPAChar::TONE_RISING);
1193 else if (arg == "tone-high-rising")
1194 ipaChar(cur, InsetIPAChar::TONE_HIGH_RISING);
1195 else if (arg == "tone-low-rising")
1196 ipaChar(cur, InsetIPAChar::TONE_LOW_RISING);
1197 else if (arg == "tone-high-rising-falling")
1198 ipaChar(cur, InsetIPAChar::TONE_HIGH_RISING_FALLING);
1199 else if (arg.empty())
1200 lyxerr << "LyX function 'ipamacro-insert' needs an argument." << endl;
1202 lyxerr << "Wrong argument for LyX function 'ipamacro-insert'." << endl;
1206 case LFUN_WORD_UPCASE:
1207 changeCase(cur, text_uppercase);
1210 case LFUN_WORD_LOWCASE:
1211 changeCase(cur, text_lowercase);
1214 case LFUN_WORD_CAPITALIZE:
1215 changeCase(cur, text_capitalization);
1218 case LFUN_CHARS_TRANSPOSE:
1219 charsTranspose(cur);
1223 cur.message(_("Paste"));
1224 LASSERT(cur.selBegin().idx() == cur.selEnd().idx(), break);
1225 cap::replaceSelection(cur);
1227 // without argument?
1228 string const arg = to_utf8(cmd.argument());
1230 bool tryGraphics = true;
1231 if (theClipboard().isInternal())
1232 pasteFromStack(cur, bv->buffer().errorList("Paste"), 0);
1233 else if (theClipboard().hasTextContents()) {
1234 if (pasteClipboardText(cur, bv->buffer().errorList("Paste"),
1235 true, Clipboard::AnyTextType))
1236 tryGraphics = false;
1238 if (tryGraphics && theClipboard().hasGraphicsContents())
1239 pasteClipboardGraphics(cur, bv->buffer().errorList("Paste"));
1240 } else if (isStrUnsignedInt(arg)) {
1241 // we have a numerical argument
1242 pasteFromStack(cur, bv->buffer().errorList("Paste"),
1243 convert<unsigned int>(arg));
1244 } else if (arg == "html" || arg == "latex") {
1245 Clipboard::TextType type = (arg == "html") ?
1246 Clipboard::HtmlTextType : Clipboard::LaTeXTextType;
1247 pasteClipboardText(cur, bv->buffer().errorList("Paste"), true, type);
1249 Clipboard::GraphicsType type = Clipboard::AnyGraphicsType;
1251 type = Clipboard::PdfGraphicsType;
1252 else if (arg == "png")
1253 type = Clipboard::PngGraphicsType;
1254 else if (arg == "jpeg")
1255 type = Clipboard::JpegGraphicsType;
1256 else if (arg == "linkback")
1257 type = Clipboard::LinkBackGraphicsType;
1258 else if (arg == "emf")
1259 type = Clipboard::EmfGraphicsType;
1260 else if (arg == "wmf")
1261 type = Clipboard::WmfGraphicsType;
1263 // We used to assert, but couldn't the argument come from, say, the
1264 // minibuffer and just be mistyped?
1265 LYXERR0("Unrecognized graphics type: " << arg);
1267 pasteClipboardGraphics(cur, bv->buffer().errorList("Paste"), type);
1270 bv->buffer().errors("Paste");
1271 cur.clearSelection(); // bug 393
1277 cutSelection(cur, true, true);
1278 cur.message(_("Cut"));
1283 cur.message(_("Copy"));
1286 case LFUN_SERVER_GET_XY:
1287 cur.message(from_utf8(
1288 convert<string>(tm->cursorX(cur.top(), cur.boundary()))
1289 + ' ' + convert<string>(tm->cursorY(cur.top(), cur.boundary()))));
1292 case LFUN_SERVER_SET_XY: {
1295 istringstream is(to_utf8(cmd.argument()));
1298 lyxerr << "SETXY: Could not parse coordinates in '"
1299 << to_utf8(cmd.argument()) << endl;
1301 tm->setCursorFromCoordinates(cur, x, y);
1305 case LFUN_SERVER_GET_LAYOUT:
1306 cur.message(cur.paragraph().layout().name());
1310 docstring layout = cmd.argument();
1311 LYXERR(Debug::INFO, "LFUN_LAYOUT: (arg) " << to_utf8(layout));
1313 Paragraph const & para = cur.paragraph();
1314 docstring const old_layout = para.layout().name();
1315 DocumentClass const & tclass = bv->buffer().params().documentClass();
1318 layout = tclass.defaultLayoutName();
1320 if (owner_->forcePlainLayout())
1321 // in this case only the empty layout is allowed
1322 layout = tclass.plainLayoutName();
1323 else if (para.usePlainLayout()) {
1324 // in this case, default layout maps to empty layout
1325 if (layout == tclass.defaultLayoutName())
1326 layout = tclass.plainLayoutName();
1328 // otherwise, the empty layout maps to the default
1329 if (layout == tclass.plainLayoutName())
1330 layout = tclass.defaultLayoutName();
1333 bool hasLayout = tclass.hasLayout(layout);
1335 // If the entry is obsolete, use the new one instead.
1337 docstring const & obs = tclass[layout].obsoleted_by();
1343 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
1344 from_utf8(N_(" not known")));
1348 bool change_layout = (old_layout != layout);
1350 if (!change_layout && cur.selection() &&
1351 cur.selBegin().pit() != cur.selEnd().pit())
1353 pit_type spit = cur.selBegin().pit();
1354 pit_type epit = cur.selEnd().pit() + 1;
1355 while (spit != epit) {
1356 if (pars_[spit].layout().name() != old_layout) {
1357 change_layout = true;
1365 setLayout(cur, layout);
1367 Layout::LaTeXArgMap args = tclass[layout].args();
1368 Layout::LaTeXArgMap::const_iterator lait = args.begin();
1369 Layout::LaTeXArgMap::const_iterator const laend = args.end();
1370 for (; lait != laend; ++lait) {
1371 Layout::latexarg arg = (*lait).second;
1372 if (arg.autoinsert) {
1373 FuncRequest cmd(LFUN_ARGUMENT_INSERT, (*lait).first);
1381 case LFUN_ENVIRONMENT_SPLIT: {
1382 bool const outer = cmd.argument() == "outer";
1383 Paragraph const & para = cur.paragraph();
1384 docstring layout = para.layout().name();
1385 depth_type split_depth = cur.paragraph().params().depth();
1387 // check if we have an environment in our nesting hierarchy
1388 pit_type pit = cur.pit();
1389 Paragraph cpar = pars_[pit];
1391 if (pit == 0 || cpar.params().depth() == 0)
1395 if (cpar.params().depth() < split_depth
1396 && cpar.layout().isEnvironment()) {
1397 layout = cpar.layout().name();
1398 split_depth = cpar.params().depth();
1403 lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_BREAK));
1405 while (cur.paragraph().params().depth() > split_depth)
1406 lyx::dispatch(FuncRequest(LFUN_DEPTH_DECREMENT));
1408 bool const morecont = cur.lastpos() > cur.pos();
1409 lyx::dispatch(FuncRequest(LFUN_LAYOUT, "Separator"));
1410 lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_BREAK, "inverse"));
1412 lyx::dispatch(FuncRequest(LFUN_DOWN));
1413 lyx::dispatch(FuncRequest(LFUN_LAYOUT, layout));
1418 case LFUN_CLIPBOARD_PASTE:
1419 cap::replaceSelection(cur);
1420 pasteClipboardText(cur, bv->buffer().errorList("Paste"),
1421 cmd.argument() == "paragraph");
1422 bv->buffer().errors("Paste");
1425 case LFUN_CLIPBOARD_PASTE_SIMPLE:
1426 cap::replaceSelection(cur);
1427 pasteSimpleText(cur, cmd.argument() == "paragraph");
1430 case LFUN_PRIMARY_SELECTION_PASTE:
1431 cap::replaceSelection(cur);
1432 pasteString(cur, theSelection().get(),
1433 cmd.argument() == "paragraph");
1436 case LFUN_SELECTION_PASTE:
1437 // Copy the selection buffer to the clipboard stack,
1438 // because we want it to appear in the "Edit->Paste
1440 cap::replaceSelection(cur);
1441 cap::copySelectionToStack();
1442 cap::pasteSelection(bv->cursor(), bv->buffer().errorList("Paste"));
1443 bv->buffer().errors("Paste");
1446 case LFUN_UNICODE_INSERT: {
1447 if (cmd.argument().empty())
1449 docstring hexstring = cmd.argument();
1450 if (isHex(hexstring)) {
1451 char_type c = hexToInt(hexstring);
1452 if (c >= 32 && c < 0x10ffff) {
1453 lyxerr << "Inserting c: " << c << endl;
1454 docstring s = docstring(1, c);
1455 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
1461 case LFUN_QUOTE_INSERT: {
1462 cap::replaceSelection(cur);
1465 Paragraph const & par = cur.paragraph();
1466 pos_type pos = cur.pos();
1467 // Ignore deleted text before cursor
1468 while (pos > 0 && par.isDeleted(pos - 1))
1471 BufferParams const & bufparams = bv->buffer().params();
1473 par.getFontSettings(bufparams, pos).language()->lang() == "hebrew";
1474 bool const allow_inset_quote = !(par.isPassThru() || hebrew);
1476 if (allow_inset_quote) {
1478 if (pos > 0 && (!cur.prevInset() || !cur.prevInset()->isSpace()))
1479 c = par.getChar(pos - 1);
1480 string const arg = to_utf8(cmd.argument());
1481 InsetQuotes::QuoteTimes const quote_type = (arg == "single")
1482 ? InsetQuotes::SingleQuotes : InsetQuotes::DoubleQuotes;
1483 cur.insert(new InsetQuotes(cur.buffer(), c, quote_type));
1486 // The cursor might have been invalidated by the replaceSelection.
1487 cur.buffer()->changed(true);
1488 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
1493 case LFUN_DATE_INSERT: {
1494 string const format = cmd.argument().empty()
1495 ? lyxrc.date_insert_format : to_utf8(cmd.argument());
1496 string const time = formatted_time(current_time(), format);
1497 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, time));
1501 case LFUN_MOUSE_TRIPLE:
1502 if (cmd.button() == mouse_button::button1) {
1503 tm->cursorHome(cur);
1511 case LFUN_MOUSE_DOUBLE:
1512 if (cmd.button() == mouse_button::button1) {
1513 selectWord(cur, WHOLE_WORD_STRICT);
1518 // Single-click on work area
1519 case LFUN_MOUSE_PRESS: {
1520 // We are not marking a selection with the keyboard in any case.
1521 Cursor & bvcur = cur.bv().cursor();
1522 bvcur.setMark(false);
1523 switch (cmd.button()) {
1524 case mouse_button::button1:
1526 if (!bv->mouseSetCursor(cur, cmd.argument() == "region-select"))
1527 cur.screenUpdateFlags(Update::SinglePar | Update::FitCursor);
1528 if (bvcur.wordSelection())
1529 selectWord(bvcur, WHOLE_WORD);
1532 case mouse_button::button2:
1533 // Middle mouse pasting.
1534 bv->mouseSetCursor(cur);
1536 FuncRequest(LFUN_COMMAND_ALTERNATIVES,
1537 "selection-paste ; primary-selection-paste paragraph"));
1538 cur.noScreenUpdate();
1541 case mouse_button::button3: {
1542 // Don't do anything if we right-click a
1543 // selection, a context menu will popup.
1544 if (bvcur.selection() && cur >= bvcur.selectionBegin()
1545 && cur < bvcur.selectionEnd()) {
1546 cur.noScreenUpdate();
1549 if (!bv->mouseSetCursor(cur, false))
1550 cur.screenUpdateFlags(Update::SinglePar | Update::FitCursor);
1556 } // switch (cmd.button())
1559 case LFUN_MOUSE_MOTION: {
1560 // Mouse motion with right or middle mouse do nothing for now.
1561 if (cmd.button() != mouse_button::button1) {
1562 cur.noScreenUpdate();
1565 // ignore motions deeper nested than the real anchor
1566 Cursor & bvcur = cur.bv().cursor();
1567 if (!bvcur.realAnchor().hasPart(cur)) {
1571 CursorSlice old = bvcur.top();
1573 int const wh = bv->workHeight();
1574 int const y = max(0, min(wh - 1, cmd.y()));
1576 tm->setCursorFromCoordinates(cur, cmd.x(), y);
1577 cur.setTargetX(cmd.x());
1579 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1580 else if (cmd.y() < 0)
1581 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1582 // This is to allow jumping over large insets
1583 if (cur.top() == old) {
1585 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1586 else if (cmd.y() < 0)
1587 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1589 // We continue with our existing selection or start a new one, so don't
1590 // reset the anchor.
1591 bvcur.setCursor(cur);
1592 bvcur.setSelection(true);
1593 if (cur.top() == old) {
1594 // We didn't move one iota, so no need to update the screen.
1595 cur.screenUpdateFlags(Update::SinglePar | Update::FitCursor);
1596 //cur.noScreenUpdate();
1602 case LFUN_MOUSE_RELEASE:
1603 switch (cmd.button()) {
1604 case mouse_button::button1:
1605 // Cursor was set at LFUN_MOUSE_PRESS or LFUN_MOUSE_MOTION time.
1606 // If there is a new selection, update persistent selection;
1607 // otherwise, single click does not clear persistent selection
1609 if (cur.selection()) {
1610 // Finish selection. If double click,
1611 // cur is moved to the end of word by
1612 // selectWord but bvcur is current
1614 cur.bv().cursor().setSelection();
1615 // We might have removed an empty but drawn selection
1616 // (probably a margin)
1617 cur.screenUpdateFlags(Update::SinglePar | Update::FitCursor);
1619 cur.noScreenUpdate();
1620 // FIXME: We could try to handle drag and drop of selection here.
1623 case mouse_button::button2:
1624 // Middle mouse pasting is handled at mouse press time,
1625 // see LFUN_MOUSE_PRESS.
1626 cur.noScreenUpdate();
1629 case mouse_button::button3:
1630 // Cursor was set at LFUN_MOUSE_PRESS time.
1631 // FIXME: If there is a selection we could try to handle a special
1632 // drag & drop context menu.
1633 cur.noScreenUpdate();
1636 case mouse_button::none:
1637 case mouse_button::button4:
1638 case mouse_button::button5:
1640 } // switch (cmd.button())
1644 case LFUN_SELF_INSERT: {
1645 if (cmd.argument().empty())
1648 // Automatically delete the currently selected
1649 // text and replace it with what is being
1650 // typed in now. Depends on lyxrc settings
1651 // "auto_region_delete", which defaults to
1654 if (lyxrc.auto_region_delete && cur.selection())
1655 cutSelection(cur, false, false);
1657 cur.clearSelection();
1659 docstring::const_iterator cit = cmd.argument().begin();
1660 docstring::const_iterator const end = cmd.argument().end();
1661 for (; cit != end; ++cit)
1662 bv->translateAndInsert(*cit, this, cur);
1665 moveCursor(cur, false);
1666 cur.markNewWordPosition();
1667 bv->bookmarkEditPosition();
1671 case LFUN_HREF_INSERT: {
1672 // FIXME If we're actually given an argument, shouldn't
1673 // we use it, whether or not we have a selection?
1674 docstring content = cmd.argument();
1675 if (cur.selection()) {
1676 content = cur.selectionAsString(false);
1677 cutSelection(cur, true, false);
1680 InsetCommandParams p(HYPERLINK_CODE);
1681 if (!content.empty()){
1682 // if it looks like a link, we'll put it as target,
1683 // otherwise as name (bug #8792).
1686 // regex_match(to_utf8(content), matches, link_re)
1687 // because smatch stores pointers to the substrings rather
1688 // than making copies of them. And those pointers become
1689 // invalid after regex_match returns, since it is then
1690 // being given a temporary object. (Thanks to Georg for
1691 // figuring that out.)
1692 regex const link_re("^([a-z]+):.*");
1694 string const c = to_utf8(lowercase(content));
1696 if (c.substr(0,7) == "mailto:") {
1697 p["target"] = content;
1698 p["type"] = from_ascii("mailto:");
1699 } else if (regex_match(c, matches, link_re)) {
1700 p["target"] = content;
1701 string protocol = matches.str(1);
1702 if (protocol == "file")
1703 p["type"] = from_ascii("file:");
1705 p["name"] = content;
1707 string const data = InsetCommand::params2string(p);
1709 // we need to have a target. if we already have one, then
1710 // that gets used at the default for the name, too, which
1711 // is probably what is wanted.
1712 if (p["target"].empty()) {
1713 bv->showDialog("href", data);
1715 FuncRequest fr(LFUN_INSET_INSERT, data);
1721 case LFUN_LABEL_INSERT: {
1722 InsetCommandParams p(LABEL_CODE);
1723 // Try to generate a valid label
1724 p["name"] = (cmd.argument().empty()) ?
1725 cur.getPossibleLabel() :
1727 string const data = InsetCommand::params2string(p);
1729 if (cmd.argument().empty()) {
1730 bv->showDialog("label", data);
1732 FuncRequest fr(LFUN_INSET_INSERT, data);
1738 case LFUN_INFO_INSERT: {
1740 if (cmd.argument().empty() && cur.selection()) {
1741 // if command argument is empty use current selection as parameter.
1742 docstring ds = cur.selectionAsString(false);
1743 cutSelection(cur, true, false);
1744 FuncRequest cmd0(cmd, ds);
1745 inset = createInset(cur.buffer(), cmd0);
1747 inset = createInset(cur.buffer(), cmd);
1752 insertInset(cur, inset);
1756 case LFUN_CAPTION_INSERT:
1757 case LFUN_FOOTNOTE_INSERT:
1758 case LFUN_NOTE_INSERT:
1759 case LFUN_BOX_INSERT:
1760 case LFUN_BRANCH_INSERT:
1761 case LFUN_PHANTOM_INSERT:
1762 case LFUN_ERT_INSERT:
1763 case LFUN_LISTING_INSERT:
1764 case LFUN_MARGINALNOTE_INSERT:
1765 case LFUN_ARGUMENT_INSERT:
1766 case LFUN_INDEX_INSERT:
1767 case LFUN_PREVIEW_INSERT:
1768 case LFUN_SCRIPT_INSERT:
1769 case LFUN_IPA_INSERT:
1770 // Open the inset, and move the current selection
1772 doInsertInset(cur, this, cmd, true, true);
1774 // Some insets are numbered, others are shown in the outline pane so
1775 // let's update the labels and the toc backend.
1776 cur.forceBufferUpdate();
1779 case LFUN_FLEX_INSERT: {
1780 // Open the inset, and move the current selection
1782 bool const sel = cur.selection();
1783 doInsertInset(cur, this, cmd, true, true);
1784 // Insert auto-insert arguments
1785 bool autoargs = false;
1786 Layout::LaTeXArgMap args = cur.inset().getLayout().latexargs();
1787 Layout::LaTeXArgMap::const_iterator lait = args.begin();
1788 Layout::LaTeXArgMap::const_iterator const laend = args.end();
1789 for (; lait != laend; ++lait) {
1790 Layout::latexarg arg = (*lait).second;
1791 if (arg.autoinsert) {
1792 // The cursor might have been invalidated by the replaceSelection.
1793 cur.buffer()->changed(true);
1794 FuncRequest cmd(LFUN_ARGUMENT_INSERT, (*lait).first);
1801 cur.leaveInset(cur.inset());
1804 // Some insets are numbered, others are shown in the outline pane so
1805 // let's update the labels and the toc backend.
1806 cur.forceBufferUpdate();
1810 case LFUN_TABULAR_INSERT:
1811 // if there were no arguments, just open the dialog
1812 if (doInsertInset(cur, this, cmd, false, true))
1815 bv->showDialog("tabularcreate");
1819 case LFUN_FLOAT_INSERT:
1820 case LFUN_FLOAT_WIDE_INSERT:
1821 case LFUN_WRAP_INSERT: {
1822 // will some content be moved into the inset?
1823 bool const content = cur.selection();
1824 // does the content consist of multiple paragraphs?
1825 bool const singlepar = (cur.selBegin().pit() == cur.selEnd().pit());
1827 doInsertInset(cur, this, cmd, true, true);
1830 // If some single-par content is moved into the inset,
1831 // doInsertInset puts the cursor outside the inset.
1832 // To insert the caption we put it back into the inset.
1833 // FIXME cleanup doInsertInset to avoid such dances!
1834 if (content && singlepar)
1837 ParagraphList & pars = cur.text()->paragraphs();
1839 DocumentClass const & tclass = bv->buffer().params().documentClass();
1841 // add a separate paragraph for the caption inset
1842 pars.push_back(Paragraph());
1843 pars.back().setInsetOwner(&cur.text()->inset());
1844 pars.back().setPlainOrDefaultLayout(tclass);
1845 int cap_pit = pars.size() - 1;
1847 // if an empty inset was created, we create an additional empty
1848 // paragraph at the bottom so that the user can choose where to put
1849 // the graphics (or table).
1851 pars.push_back(Paragraph());
1852 pars.back().setInsetOwner(&cur.text()->inset());
1853 pars.back().setPlainOrDefaultLayout(tclass);
1856 // reposition the cursor to the caption
1857 cur.pit() = cap_pit;
1859 // FIXME: This Text/Cursor dispatch handling is a mess!
1860 // We cannot use Cursor::dispatch here it needs access to up to
1862 FuncRequest cmd_caption(LFUN_CAPTION_INSERT);
1863 doInsertInset(cur, cur.text(), cmd_caption, true, false);
1864 cur.forceBufferUpdate();
1865 cur.screenUpdateFlags(Update::Force);
1866 // FIXME: When leaving the Float (or Wrap) inset we should
1867 // delete any empty paragraph left above or below the
1872 case LFUN_NOMENCL_INSERT: {
1873 InsetCommandParams p(NOMENCL_CODE);
1874 if (cmd.argument().empty())
1875 p["symbol"] = bv->cursor().innerText()->getStringToIndex(bv->cursor());
1877 p["symbol"] = cmd.argument();
1878 string const data = InsetCommand::params2string(p);
1879 bv->showDialog("nomenclature", data);
1883 case LFUN_INDEX_PRINT: {
1884 InsetCommandParams p(INDEX_PRINT_CODE);
1885 if (cmd.argument().empty())
1886 p["type"] = from_ascii("idx");
1888 p["type"] = cmd.argument();
1889 string const data = InsetCommand::params2string(p);
1890 FuncRequest fr(LFUN_INSET_INSERT, data);
1895 case LFUN_NOMENCL_PRINT:
1896 case LFUN_NEWPAGE_INSERT:
1898 doInsertInset(cur, this, cmd, false, false);
1902 case LFUN_DEPTH_DECREMENT:
1903 changeDepth(cur, DEC_DEPTH);
1906 case LFUN_DEPTH_INCREMENT:
1907 changeDepth(cur, INC_DEPTH);
1910 case LFUN_MATH_DISPLAY:
1911 mathDispatch(cur, cmd, true);
1914 case LFUN_REGEXP_MODE:
1915 regexpDispatch(cur, cmd);
1918 case LFUN_MATH_MODE:
1919 if (cmd.argument() == "on")
1920 // don't pass "on" as argument
1921 // (it would appear literally in the first cell)
1922 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1924 mathDispatch(cur, cmd, false);
1927 case LFUN_MATH_MACRO:
1928 if (cmd.argument().empty())
1929 cur.errorMessage(from_utf8(N_("Missing argument")));
1932 string s = to_utf8(cmd.argument());
1933 string const s1 = token(s, ' ', 1);
1934 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1935 string const s2 = token(s, ' ', 2);
1936 MacroType type = MacroTypeNewcommand;
1938 type = MacroTypeDef;
1939 MathMacroTemplate * inset = new MathMacroTemplate(cur.buffer(),
1940 from_utf8(token(s, ' ', 0)), nargs, false, type);
1941 inset->setBuffer(bv->buffer());
1942 insertInset(cur, inset);
1944 // enter macro inset and select the name
1946 cur.top().pos() = cur.top().lastpos();
1948 cur.setSelection(true);
1949 cur.top().pos() = 0;
1953 // passthrough hat and underscore outside mathed:
1954 case LFUN_MATH_SUBSCRIPT:
1955 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1957 case LFUN_MATH_SUPERSCRIPT:
1958 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1961 case LFUN_MATH_INSERT:
1962 case LFUN_MATH_AMS_MATRIX:
1963 case LFUN_MATH_MATRIX:
1964 case LFUN_MATH_DELIM:
1965 case LFUN_MATH_BIGDELIM: {
1967 cap::replaceSelection(cur);
1968 cur.insert(new InsetMathHull(cur.buffer(), hullSimple));
1969 checkAndActivateInset(cur, true);
1970 LASSERT(cur.inMathed(), break);
1975 case LFUN_FONT_EMPH: {
1976 Font font(ignore_font, ignore_language);
1977 font.fontInfo().setEmph(FONT_TOGGLE);
1978 toggleAndShow(cur, this, font);
1982 case LFUN_FONT_ITAL: {
1983 Font font(ignore_font, ignore_language);
1984 font.fontInfo().setShape(ITALIC_SHAPE);
1985 toggleAndShow(cur, this, font);
1989 case LFUN_FONT_BOLD:
1990 case LFUN_FONT_BOLDSYMBOL: {
1991 Font font(ignore_font, ignore_language);
1992 font.fontInfo().setSeries(BOLD_SERIES);
1993 toggleAndShow(cur, this, font);
1997 case LFUN_FONT_NOUN: {
1998 Font font(ignore_font, ignore_language);
1999 font.fontInfo().setNoun(FONT_TOGGLE);
2000 toggleAndShow(cur, this, font);
2004 case LFUN_FONT_TYPEWRITER: {
2005 Font font(ignore_font, ignore_language);
2006 font.fontInfo().setFamily(TYPEWRITER_FAMILY); // no good
2007 toggleAndShow(cur, this, font);
2011 case LFUN_FONT_SANS: {
2012 Font font(ignore_font, ignore_language);
2013 font.fontInfo().setFamily(SANS_FAMILY);
2014 toggleAndShow(cur, this, font);
2018 case LFUN_FONT_ROMAN: {
2019 Font font(ignore_font, ignore_language);
2020 font.fontInfo().setFamily(ROMAN_FAMILY);
2021 toggleAndShow(cur, this, font);
2025 case LFUN_FONT_DEFAULT: {
2026 Font font(inherit_font, ignore_language);
2027 toggleAndShow(cur, this, font);
2031 case LFUN_FONT_STRIKEOUT: {
2032 Font font(ignore_font, ignore_language);
2033 font.fontInfo().setStrikeout(FONT_TOGGLE);
2034 toggleAndShow(cur, this, font);
2038 case LFUN_FONT_UNDERUNDERLINE: {
2039 Font font(ignore_font, ignore_language);
2040 font.fontInfo().setUuline(FONT_TOGGLE);
2041 toggleAndShow(cur, this, font);
2045 case LFUN_FONT_UNDERWAVE: {
2046 Font font(ignore_font, ignore_language);
2047 font.fontInfo().setUwave(FONT_TOGGLE);
2048 toggleAndShow(cur, this, font);
2052 case LFUN_FONT_UNDERLINE: {
2053 Font font(ignore_font, ignore_language);
2054 font.fontInfo().setUnderbar(FONT_TOGGLE);
2055 toggleAndShow(cur, this, font);
2059 case LFUN_FONT_SIZE: {
2060 Font font(ignore_font, ignore_language);
2061 setLyXSize(to_utf8(cmd.argument()), font.fontInfo());
2062 toggleAndShow(cur, this, font);
2066 case LFUN_LANGUAGE: {
2067 string const lang_arg = cmd.getArg(0);
2068 bool const reset = (lang_arg.empty() || lang_arg == "reset");
2069 Language const * lang =
2070 reset ? reset_language
2071 : languages.getLanguage(lang_arg);
2072 // we allow reset_language, which is 0, but only if it
2073 // was requested via empty or "reset" arg.
2074 if (!lang && !reset)
2076 bool const toggle = (cmd.getArg(1) != "set");
2077 selectWordWhenUnderCursor(cur, WHOLE_WORD_STRICT);
2078 Font font(ignore_font, lang);
2079 toggleAndShow(cur, this, font, toggle);
2083 case LFUN_TEXTSTYLE_APPLY:
2084 toggleAndShow(cur, this, freefont, toggleall);
2085 cur.message(_("Character set"));
2088 // Set the freefont using the contents of \param data dispatched from
2089 // the frontends and apply it at the current cursor location.
2090 case LFUN_TEXTSTYLE_UPDATE: {
2093 if (font.fromString(to_utf8(cmd.argument()), toggle)) {
2096 toggleAndShow(cur, this, freefont, toggleall);
2097 cur.message(_("Character set"));
2099 lyxerr << "Argument not ok";
2104 case LFUN_FINISHED_LEFT:
2105 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_LEFT:\n" << cur);
2106 // We're leaving an inset, going left. If the inset is LTR, we're
2107 // leaving from the front, so we should not move (remain at --- but
2108 // not in --- the inset). If the inset is RTL, move left, without
2109 // entering the inset itself; i.e., move to after the inset.
2110 if (cur.paragraph().getFontSettings(
2111 cur.bv().buffer().params(), cur.pos()).isRightToLeft())
2112 cursorVisLeft(cur, true);
2115 case LFUN_FINISHED_RIGHT:
2116 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_RIGHT:\n" << cur);
2117 // We're leaving an inset, going right. If the inset is RTL, we're
2118 // leaving from the front, so we should not move (remain at --- but
2119 // not in --- the inset). If the inset is LTR, move right, without
2120 // entering the inset itself; i.e., move to after the inset.
2121 if (!cur.paragraph().getFontSettings(
2122 cur.bv().buffer().params(), cur.pos()).isRightToLeft())
2123 cursorVisRight(cur, true);
2126 case LFUN_FINISHED_BACKWARD:
2127 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_BACKWARD:\n" << cur);
2130 case LFUN_FINISHED_FORWARD:
2131 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_FORWARD:\n" << cur);
2133 cur.setCurrentFont();
2136 case LFUN_LAYOUT_PARAGRAPH: {
2138 params2string(cur.paragraph(), data);
2139 data = "show\n" + data;
2140 bv->showDialog("paragraph", data);
2144 case LFUN_PARAGRAPH_UPDATE: {
2146 params2string(cur.paragraph(), data);
2148 // Will the paragraph accept changes from the dialog?
2150 cur.inset().allowParagraphCustomization(cur.idx());
2152 data = "update " + convert<string>(accept) + '\n' + data;
2153 bv->updateDialog("paragraph", data);
2157 case LFUN_ACCENT_UMLAUT:
2158 case LFUN_ACCENT_CIRCUMFLEX:
2159 case LFUN_ACCENT_GRAVE:
2160 case LFUN_ACCENT_ACUTE:
2161 case LFUN_ACCENT_TILDE:
2162 case LFUN_ACCENT_CEDILLA:
2163 case LFUN_ACCENT_MACRON:
2164 case LFUN_ACCENT_DOT:
2165 case LFUN_ACCENT_UNDERDOT:
2166 case LFUN_ACCENT_UNDERBAR:
2167 case LFUN_ACCENT_CARON:
2168 case LFUN_ACCENT_BREVE:
2169 case LFUN_ACCENT_TIE:
2170 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
2171 case LFUN_ACCENT_CIRCLE:
2172 case LFUN_ACCENT_OGONEK:
2173 theApp()->handleKeyFunc(cmd.action());
2174 if (!cmd.argument().empty())
2175 // FIXME: Are all these characters encoded in one byte in utf8?
2176 bv->translateAndInsert(cmd.argument()[0], this, cur);
2177 cur.screenUpdateFlags(Update::FitCursor);
2180 case LFUN_FLOAT_LIST_INSERT: {
2181 DocumentClass const & tclass = bv->buffer().params().documentClass();
2182 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
2184 if (cur.selection())
2185 cutSelection(cur, true, false);
2186 breakParagraph(cur);
2188 if (cur.lastpos() != 0) {
2189 cursorBackward(cur);
2190 breakParagraph(cur);
2193 docstring const laystr = cur.inset().usePlainLayout() ?
2194 tclass.plainLayoutName() :
2195 tclass.defaultLayoutName();
2196 setLayout(cur, laystr);
2197 ParagraphParameters p;
2198 // FIXME If this call were replaced with one to clearParagraphParams(),
2199 // then we could get rid of this method altogether.
2200 setParagraphs(cur, p);
2201 // FIXME This should be simplified when InsetFloatList takes a
2202 // Buffer in its constructor.
2203 InsetFloatList * ifl = new InsetFloatList(cur.buffer(), to_utf8(cmd.argument()));
2204 ifl->setBuffer(bv->buffer());
2205 insertInset(cur, ifl);
2208 lyxerr << "Non-existent float type: "
2209 << to_utf8(cmd.argument()) << endl;
2214 case LFUN_CHANGE_ACCEPT: {
2215 acceptOrRejectChanges(cur, ACCEPT);
2219 case LFUN_CHANGE_REJECT: {
2220 acceptOrRejectChanges(cur, REJECT);
2224 case LFUN_THESAURUS_ENTRY: {
2225 docstring arg = cmd.argument();
2227 arg = cur.selectionAsString(false);
2229 if (arg.size() > 100 || arg.empty()) {
2230 // Get word or selection
2231 selectWordWhenUnderCursor(cur, WHOLE_WORD);
2232 arg = cur.selectionAsString(false);
2233 arg += " lang=" + from_ascii(cur.getFont().language()->lang());
2236 bv->showDialog("thesaurus", to_utf8(arg));
2240 case LFUN_SPELLING_ADD: {
2241 docstring word = from_utf8(cmd.getArg(0));
2244 word = cur.selectionAsString(false);
2246 if (word.size() > 100 || word.empty()) {
2247 // Get word or selection
2248 selectWordWhenUnderCursor(cur, WHOLE_WORD);
2249 word = cur.selectionAsString(false);
2251 lang = const_cast<Language *>(cur.getFont().language());
2253 lang = const_cast<Language *>(languages.getLanguage(cmd.getArg(1)));
2254 WordLangTuple wl(word, lang);
2255 theSpellChecker()->insert(wl);
2259 case LFUN_SPELLING_IGNORE: {
2260 docstring word = from_utf8(cmd.getArg(0));
2263 word = cur.selectionAsString(false);
2265 if (word.size() > 100 || word.empty()) {
2266 // Get word or selection
2267 selectWordWhenUnderCursor(cur, WHOLE_WORD);
2268 word = cur.selectionAsString(false);
2270 lang = const_cast<Language *>(cur.getFont().language());
2272 lang = const_cast<Language *>(languages.getLanguage(cmd.getArg(1)));
2273 WordLangTuple wl(word, lang);
2274 theSpellChecker()->accept(wl);
2278 case LFUN_SPELLING_REMOVE: {
2279 docstring word = from_utf8(cmd.getArg(0));
2282 word = cur.selectionAsString(false);
2284 if (word.size() > 100 || word.empty()) {
2285 // Get word or selection
2286 selectWordWhenUnderCursor(cur, WHOLE_WORD);
2287 word = cur.selectionAsString(false);
2289 lang = const_cast<Language *>(cur.getFont().language());
2291 lang = const_cast<Language *>(languages.getLanguage(cmd.getArg(1)));
2292 WordLangTuple wl(word, lang);
2293 theSpellChecker()->remove(wl);
2297 case LFUN_PARAGRAPH_PARAMS_APPLY: {
2298 // Given data, an encoding of the ParagraphParameters
2299 // generated in the Paragraph dialog, this function sets
2300 // the current paragraph, or currently selected paragraphs,
2302 // NOTE: This function overrides all existing settings.
2303 setParagraphs(cur, cmd.argument());
2304 cur.message(_("Paragraph layout set"));
2308 case LFUN_PARAGRAPH_PARAMS: {
2309 // Given data, an encoding of the ParagraphParameters as we'd
2310 // find them in a LyX file, this function modifies the current paragraph,
2311 // or currently selected paragraphs.
2312 // NOTE: This function only modifies, and does not override, existing
2314 setParagraphs(cur, cmd.argument(), true);
2315 cur.message(_("Paragraph layout set"));
2320 if (cur.selection()) {
2321 cur.setSelection(false);
2324 // This used to be LFUN_FINISHED_RIGHT, I think FORWARD is more
2325 // correct, but I'm not 100% sure -- dov, 071019
2326 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
2330 case LFUN_OUTLINE_UP:
2331 outline(OutlineUp, cur);
2332 setCursor(cur, cur.pit(), 0);
2333 cur.forceBufferUpdate();
2337 case LFUN_OUTLINE_DOWN:
2338 outline(OutlineDown, cur);
2339 setCursor(cur, cur.pit(), 0);
2340 cur.forceBufferUpdate();
2344 case LFUN_OUTLINE_IN:
2345 outline(OutlineIn, cur);
2346 cur.forceBufferUpdate();
2350 case LFUN_OUTLINE_OUT:
2351 outline(OutlineOut, cur);
2352 cur.forceBufferUpdate();
2357 LYXERR(Debug::ACTION, "Command " << cmd << " not DISPATCHED by Text");
2362 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
2364 if (lyxrc.spellcheck_continuously && !needsUpdate) {
2365 // Check for misspelled text
2366 // The redraw is useful because of the painting of
2367 // misspelled markers depends on the cursor position.
2368 // Trigger a redraw for cursor moves inside misspelled text.
2369 if (!cur.inTexted()) {
2370 // move from regular text to math
2371 needsUpdate = last_misspelled;
2372 } else if (oldTopSlice != cur.top() || oldBoundary != cur.boundary()) {
2373 // move inside regular text
2374 needsUpdate = last_misspelled
2375 || cur.paragraph().isMisspelled(cur.pos(), true);
2379 // FIXME: The cursor flag is reset two lines below
2380 // so we need to check here if some of the LFUN did touch that.
2381 // for now only Text::erase() and Text::backspace() do that.
2382 // The plan is to verify all the LFUNs and then to remove this
2383 // singleParUpdate boolean altogether.
2384 if (cur.result().screenUpdate() & Update::Force) {
2385 singleParUpdate = false;
2389 // FIXME: the following code should go in favor of fine grained
2390 // update flag treatment.
2391 if (singleParUpdate) {
2392 // Inserting characters does not change par height in general. So, try
2393 // to update _only_ this paragraph. BufferView will detect if a full
2394 // metrics update is needed anyway.
2395 cur.screenUpdateFlags(Update::SinglePar | Update::FitCursor);
2399 && &oldTopSlice.inset() == &cur.inset()
2400 && oldTopSlice.idx() == cur.idx()
2401 && !oldSelection // oldSelection is a backup of cur.selection() at the beginning of the function.
2402 && !cur.selection())
2403 // FIXME: it would be better if we could just do this
2405 //if (cur.result().update() != Update::FitCursor)
2406 // cur.noScreenUpdate();
2408 // But some LFUNs do not set Update::FitCursor when needed, so we
2409 // do it for all. This is not very harmfull as FitCursor will provoke
2410 // a full redraw only if needed but still, a proper review of all LFUN
2411 // should be done and this needsUpdate boolean can then be removed.
2412 cur.screenUpdateFlags(Update::FitCursor);
2414 cur.screenUpdateFlags(Update::Force | Update::FitCursor);
2418 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
2419 FuncStatus & flag) const
2421 LBUFERR(this == cur.text());
2423 FontInfo const & fontinfo = cur.real_current_font.fontInfo();
2425 bool allow_in_passthru = false;
2426 InsetCode code = NO_CODE;
2428 switch (cmd.action()) {
2430 case LFUN_DEPTH_DECREMENT:
2431 enable = changeDepthAllowed(cur, DEC_DEPTH);
2434 case LFUN_DEPTH_INCREMENT:
2435 enable = changeDepthAllowed(cur, INC_DEPTH);
2439 // FIXME We really should not allow this to be put, e.g.,
2440 // in a footnote, or in ERT. But it would make sense in a
2441 // branch, so I'm not sure what to do.
2442 flag.setOnOff(cur.paragraph().params().startOfAppendix());
2445 case LFUN_DIALOG_SHOW_NEW_INSET:
2446 if (cmd.argument() == "bibitem")
2447 code = BIBITEM_CODE;
2448 else if (cmd.argument() == "bibtex") {
2450 // not allowed in description items
2451 enable = !inDescriptionItem(cur);
2453 else if (cmd.argument() == "box")
2455 else if (cmd.argument() == "branch")
2457 else if (cmd.argument() == "citation")
2459 else if (cmd.argument() == "ert")
2461 else if (cmd.argument() == "external")
2462 code = EXTERNAL_CODE;
2463 else if (cmd.argument() == "float")
2465 else if (cmd.argument() == "graphics")
2466 code = GRAPHICS_CODE;
2467 else if (cmd.argument() == "href")
2468 code = HYPERLINK_CODE;
2469 else if (cmd.argument() == "include")
2470 code = INCLUDE_CODE;
2471 else if (cmd.argument() == "index")
2473 else if (cmd.argument() == "index_print")
2474 code = INDEX_PRINT_CODE;
2475 else if (cmd.argument() == "nomenclature")
2476 code = NOMENCL_CODE;
2477 else if (cmd.argument() == "nomencl_print")
2478 code = NOMENCL_PRINT_CODE;
2479 else if (cmd.argument() == "label")
2481 else if (cmd.argument() == "line")
2483 else if (cmd.argument() == "note")
2485 else if (cmd.argument() == "phantom")
2486 code = PHANTOM_CODE;
2487 else if (cmd.argument() == "ref")
2489 else if (cmd.argument() == "space")
2491 else if (cmd.argument() == "toc")
2493 else if (cmd.argument() == "vspace")
2495 else if (cmd.argument() == "wrap")
2497 else if (cmd.argument() == "listings")
2498 code = LISTINGS_CODE;
2501 case LFUN_ERT_INSERT:
2504 case LFUN_LISTING_INSERT:
2505 code = LISTINGS_CODE;
2506 // not allowed in description items
2507 enable = !inDescriptionItem(cur);
2509 case LFUN_FOOTNOTE_INSERT:
2512 case LFUN_TABULAR_INSERT:
2513 code = TABULAR_CODE;
2515 case LFUN_MARGINALNOTE_INSERT:
2518 case LFUN_FLOAT_INSERT:
2519 case LFUN_FLOAT_WIDE_INSERT:
2520 // FIXME: If there is a selection, we should check whether there
2521 // are floats in the selection, but this has performance issues, see
2522 // LFUN_CHANGE_ACCEPT/REJECT.
2524 if (inDescriptionItem(cur))
2525 // not allowed in description items
2528 InsetCode const inset_code = cur.inset().lyxCode();
2530 // algorithm floats cannot be put in another float
2531 if (to_utf8(cmd.argument()) == "algorithm") {
2532 enable = inset_code != WRAP_CODE && inset_code != FLOAT_CODE;
2536 // for figures and tables: only allow in another
2537 // float or wrap if it is of the same type and
2538 // not a subfloat already
2539 if(cur.inset().lyxCode() == code) {
2540 InsetFloat const & ins =
2541 static_cast<InsetFloat const &>(cur.inset());
2542 enable = ins.params().type == to_utf8(cmd.argument())
2543 && !ins.params().subfloat;
2544 } else if(cur.inset().lyxCode() == WRAP_CODE) {
2545 InsetWrap const & ins =
2546 static_cast<InsetWrap const &>(cur.inset());
2547 enable = ins.params().type == to_utf8(cmd.argument());
2551 case LFUN_WRAP_INSERT:
2553 // not allowed in description items
2554 enable = !inDescriptionItem(cur);
2556 case LFUN_FLOAT_LIST_INSERT: {
2557 code = FLOAT_LIST_CODE;
2558 // not allowed in description items
2559 enable = !inDescriptionItem(cur);
2561 FloatList const & floats = cur.buffer()->params().documentClass().floats();
2562 FloatList::const_iterator cit = floats[to_ascii(cmd.argument())];
2563 // make sure we know about such floats
2564 if (cit == floats.end() ||
2565 // and that we know how to generate a list of them
2566 (!cit->second.usesFloatPkg() && cit->second.listCommand().empty())) {
2567 flag.setUnknown(true);
2568 // probably not necessary, but...
2574 case LFUN_CAPTION_INSERT: {
2575 code = CAPTION_CODE;
2576 string arg = cmd.getArg(0);
2577 bool varia = arg != "LongTableNoNumber";
2578 if (cur.depth() > 0) {
2579 if (&cur[cur.depth() - 1].inset())
2580 varia = cur[cur.depth() - 1].inset().allowsCaptionVariation(arg);
2582 // not allowed in description items,
2583 // and in specific insets
2584 enable = !inDescriptionItem(cur)
2585 && (varia || arg.empty() || arg == "Standard");
2588 case LFUN_NOTE_INSERT:
2590 // in commands (sections etc.) and description items,
2591 // only Notes are allowed
2592 enable = (cmd.argument().empty() || cmd.getArg(0) == "Note" ||
2593 (!cur.paragraph().layout().isCommand()
2594 && !inDescriptionItem(cur)));
2596 case LFUN_FLEX_INSERT: {
2598 string s = cmd.getArg(0);
2600 cur.buffer()->params().documentClass().insetLayout(from_utf8(s));
2601 if (il.lyxtype() != InsetLayout::CHARSTYLE &&
2602 il.lyxtype() != InsetLayout::CUSTOM &&
2603 il.lyxtype() != InsetLayout::ELEMENT &&
2604 il.lyxtype ()!= InsetLayout::STANDARD)
2608 case LFUN_BOX_INSERT:
2611 case LFUN_BRANCH_INSERT:
2613 if (cur.buffer()->masterBuffer()->params().branchlist().empty()
2614 && cur.buffer()->params().branchlist().empty())
2617 case LFUN_IPA_INSERT:
2620 case LFUN_PHANTOM_INSERT:
2621 code = PHANTOM_CODE;
2623 case LFUN_LABEL_INSERT:
2626 case LFUN_INFO_INSERT:
2629 case LFUN_ARGUMENT_INSERT: {
2631 allow_in_passthru = true;
2632 string const arg = cmd.getArg(0);
2637 Layout const & lay = cur.paragraph().layout();
2638 Layout::LaTeXArgMap args = lay.args();
2639 Layout::LaTeXArgMap::const_iterator const lait =
2641 if (lait != args.end()) {
2643 pit_type pit = cur.pit();
2644 pit_type lastpit = cur.pit();
2645 if (lay.isEnvironment() && !prefixIs(arg, "item:")) {
2646 // In a sequence of "merged" environment layouts, we only allow
2647 // non-item arguments once.
2648 lastpit = cur.lastpit();
2649 // get the first paragraph in sequence with this layout
2650 depth_type const current_depth = cur.paragraph().params().depth();
2654 Paragraph cpar = pars_[pit - 1];
2655 if (cpar.layout() == lay && cpar.params().depth() == current_depth)
2661 for (; pit <= lastpit; ++pit) {
2662 if (pars_[pit].layout() != lay)
2664 InsetList::const_iterator it = pars_[pit].insetList().begin();
2665 InsetList::const_iterator end = pars_[pit].insetList().end();
2666 for (; it != end; ++it) {
2667 if (it->inset->lyxCode() == ARG_CODE) {
2668 InsetArgument const * ins =
2669 static_cast<InsetArgument const *>(it->inset);
2670 if (ins->name() == arg) {
2671 // we have this already
2682 case LFUN_INDEX_INSERT:
2685 case LFUN_INDEX_PRINT:
2686 code = INDEX_PRINT_CODE;
2687 // not allowed in description items
2688 enable = !inDescriptionItem(cur);
2690 case LFUN_NOMENCL_INSERT:
2691 if (cur.selIsMultiCell() || cur.selIsMultiLine()) {
2695 code = NOMENCL_CODE;
2697 case LFUN_NOMENCL_PRINT:
2698 code = NOMENCL_PRINT_CODE;
2699 // not allowed in description items
2700 enable = !inDescriptionItem(cur);
2702 case LFUN_HREF_INSERT:
2703 if (cur.selIsMultiCell() || cur.selIsMultiLine()) {
2707 code = HYPERLINK_CODE;
2709 case LFUN_IPAMACRO_INSERT: {
2710 string const arg = cmd.getArg(0);
2712 code = IPADECO_CODE;
2714 code = IPACHAR_CODE;
2717 case LFUN_QUOTE_INSERT:
2718 // always allow this, since we will inset a raw quote
2719 // if an inset is not allowed.
2721 case LFUN_SPECIALCHAR_INSERT:
2722 code = SPECIALCHAR_CODE;
2724 case LFUN_SPACE_INSERT:
2725 // slight hack: we know this is allowed in math mode
2729 case LFUN_PREVIEW_INSERT:
2730 code = PREVIEW_CODE;
2732 case LFUN_SCRIPT_INSERT:
2736 case LFUN_MATH_INSERT:
2737 case LFUN_MATH_AMS_MATRIX:
2738 case LFUN_MATH_MATRIX:
2739 case LFUN_MATH_DELIM:
2740 case LFUN_MATH_BIGDELIM:
2741 case LFUN_MATH_DISPLAY:
2742 case LFUN_MATH_MODE:
2743 case LFUN_MATH_MACRO:
2744 case LFUN_MATH_SUBSCRIPT:
2745 case LFUN_MATH_SUPERSCRIPT:
2746 code = MATH_HULL_CODE;
2749 case LFUN_REGEXP_MODE:
2750 code = MATH_HULL_CODE;
2751 enable = cur.buffer()->isInternal() && !cur.inRegexped();
2754 case LFUN_INSET_MODIFY:
2755 // We need to disable this, because we may get called for a
2757 // InsetTabular::getStatus() -> InsetText::getStatus()
2758 // and we don't handle LFUN_INSET_MODIFY.
2762 case LFUN_FONT_EMPH:
2763 flag.setOnOff(fontinfo.emph() == FONT_ON);
2764 enable = !cur.paragraph().isPassThru();
2767 case LFUN_FONT_ITAL:
2768 flag.setOnOff(fontinfo.shape() == ITALIC_SHAPE);
2769 enable = !cur.paragraph().isPassThru();
2772 case LFUN_FONT_NOUN:
2773 flag.setOnOff(fontinfo.noun() == FONT_ON);
2774 enable = !cur.paragraph().isPassThru();
2777 case LFUN_FONT_BOLD:
2778 case LFUN_FONT_BOLDSYMBOL:
2779 flag.setOnOff(fontinfo.series() == BOLD_SERIES);
2780 enable = !cur.paragraph().isPassThru();
2783 case LFUN_FONT_SANS:
2784 flag.setOnOff(fontinfo.family() == SANS_FAMILY);
2785 enable = !cur.paragraph().isPassThru();
2788 case LFUN_FONT_ROMAN:
2789 flag.setOnOff(fontinfo.family() == ROMAN_FAMILY);
2790 enable = !cur.paragraph().isPassThru();
2793 case LFUN_FONT_TYPEWRITER:
2794 flag.setOnOff(fontinfo.family() == TYPEWRITER_FAMILY);
2795 enable = !cur.paragraph().isPassThru();
2800 enable = cur.selection();
2804 if (cmd.argument().empty()) {
2805 if (theClipboard().isInternal())
2806 enable = cap::numberOfSelections() > 0;
2808 enable = !theClipboard().empty();
2812 // we have an argument
2813 string const arg = to_utf8(cmd.argument());
2814 if (isStrUnsignedInt(arg)) {
2815 // it's a number and therefore means the internal stack
2816 unsigned int n = convert<unsigned int>(arg);
2817 enable = cap::numberOfSelections() > n;
2821 // explicit text type?
2822 if (arg == "html") {
2823 // Do not enable for PlainTextType, since some tidying in the
2824 // frontend is needed for HTML, which is too unsafe for plain text.
2825 enable = theClipboard().hasTextContents(Clipboard::HtmlTextType);
2827 } else if (arg == "latex") {
2828 // LaTeX is usually not available on the clipboard with
2829 // the correct MIME type, but in plain text.
2830 enable = theClipboard().hasTextContents(Clipboard::PlainTextType) ||
2831 theClipboard().hasTextContents(Clipboard::LaTeXTextType);
2835 // explicit graphics type?
2836 Clipboard::GraphicsType type = Clipboard::AnyGraphicsType;
2837 if ((arg == "pdf" && (type = Clipboard::PdfGraphicsType))
2838 || (arg == "png" && (type = Clipboard::PngGraphicsType))
2839 || (arg == "jpeg" && (type = Clipboard::JpegGraphicsType))
2840 || (arg == "linkback" && (type = Clipboard::LinkBackGraphicsType))
2841 || (arg == "emf" && (type = Clipboard::EmfGraphicsType))
2842 || (arg == "wmf" && (type = Clipboard::WmfGraphicsType))) {
2843 enable = theClipboard().hasGraphicsContents(type);
2852 case LFUN_CLIPBOARD_PASTE:
2853 case LFUN_CLIPBOARD_PASTE_SIMPLE:
2854 enable = !theClipboard().empty();
2857 case LFUN_PRIMARY_SELECTION_PASTE:
2858 enable = cur.selection() || !theSelection().empty();
2861 case LFUN_SELECTION_PASTE:
2862 enable = cap::selection();
2865 case LFUN_PARAGRAPH_MOVE_UP:
2866 enable = cur.pit() > 0 && !cur.selection();
2869 case LFUN_PARAGRAPH_MOVE_DOWN:
2870 enable = cur.pit() < cur.lastpit() && !cur.selection();
2873 case LFUN_CHANGE_ACCEPT:
2874 case LFUN_CHANGE_REJECT:
2875 // In principle, these LFUNs should only be enabled if there
2876 // is a change at the current position/in the current selection.
2877 // However, without proper optimizations, this will inevitably
2878 // result in unacceptable performance - just imagine a user who
2879 // wants to select the complete content of a long document.
2880 if (!cur.selection())
2881 enable = cur.paragraph().isChanged(cur.pos());
2883 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
2888 case LFUN_OUTLINE_UP:
2889 case LFUN_OUTLINE_DOWN:
2890 case LFUN_OUTLINE_IN:
2891 case LFUN_OUTLINE_OUT:
2892 // FIXME: LyX is not ready for outlining within inset.
2893 enable = isMainText()
2894 && cur.buffer()->text().getTocLevel(cur.pit()) != Layout::NOT_IN_TOC;
2897 case LFUN_NEWLINE_INSERT:
2898 // LaTeX restrictions (labels or empty par)
2899 enable = (cur.pos() > cur.paragraph().beginOfBody());
2902 case LFUN_TAB_INSERT:
2903 case LFUN_TAB_DELETE:
2904 enable = cur.paragraph().isPassThru();
2907 case LFUN_SET_GRAPHICS_GROUP: {
2908 InsetGraphics * ins = graphics::getCurrentGraphicsInset(cur);
2912 flag.setOnOff(to_utf8(cmd.argument()) == ins->getParams().groupId);
2916 case LFUN_NEWPAGE_INSERT:
2917 // not allowed in description items
2918 code = NEWPAGE_CODE;
2919 enable = !inDescriptionItem(cur);
2922 case LFUN_DATE_INSERT: {
2923 string const format = cmd.argument().empty()
2924 ? lyxrc.date_insert_format : to_utf8(cmd.argument());
2925 enable = support::os::is_valid_strftime(format);
2930 enable = !cur.paragraph().isPassThru();
2931 flag.setOnOff(cmd.getArg(0) == cur.real_current_font.language()->lang());
2934 case LFUN_PARAGRAPH_BREAK:
2935 enable = cur.inset().getLayout().isMultiPar();
2938 case LFUN_SPELLING_ADD:
2939 case LFUN_SPELLING_IGNORE:
2940 case LFUN_SPELLING_REMOVE:
2941 enable = theSpellChecker();
2945 enable = !cur.inset().forcePlainLayout();
2948 case LFUN_ENVIRONMENT_SPLIT: {
2949 if (!cur.buffer()->params().documentClass().hasLayout(from_ascii("Separator"))) {
2953 if (cmd.argument() == "outer") {
2954 // check if we have an environment in our nesting hierarchy
2956 depth_type const current_depth = cur.paragraph().params().depth();
2957 pit_type pit = cur.pit();
2958 Paragraph cpar = pars_[pit];
2960 if (pit == 0 || cpar.params().depth() == 0)
2964 if (cpar.params().depth() < current_depth)
2965 res = cpar.layout().isEnvironment();
2970 else if (cur.paragraph().layout().isEnvironment()) {
2978 case LFUN_LAYOUT_PARAGRAPH:
2979 case LFUN_PARAGRAPH_PARAMS:
2980 case LFUN_PARAGRAPH_PARAMS_APPLY:
2981 case LFUN_PARAGRAPH_UPDATE:
2982 enable = cur.inset().allowParagraphCustomization();
2985 // FIXME: why are accent lfuns forbidden with pass_thru layouts?
2986 case LFUN_ACCENT_ACUTE:
2987 case LFUN_ACCENT_BREVE:
2988 case LFUN_ACCENT_CARON:
2989 case LFUN_ACCENT_CEDILLA:
2990 case LFUN_ACCENT_CIRCLE:
2991 case LFUN_ACCENT_CIRCUMFLEX:
2992 case LFUN_ACCENT_DOT:
2993 case LFUN_ACCENT_GRAVE:
2994 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
2995 case LFUN_ACCENT_MACRON:
2996 case LFUN_ACCENT_OGONEK:
2997 case LFUN_ACCENT_TIE:
2998 case LFUN_ACCENT_TILDE:
2999 case LFUN_ACCENT_UMLAUT:
3000 case LFUN_ACCENT_UNDERBAR:
3001 case LFUN_ACCENT_UNDERDOT:
3002 case LFUN_FONT_DEFAULT:
3003 case LFUN_FONT_FRAK:
3004 case LFUN_FONT_SIZE:
3005 case LFUN_FONT_STATE:
3006 case LFUN_FONT_UNDERLINE:
3007 case LFUN_FONT_STRIKEOUT:
3008 case LFUN_FONT_UNDERUNDERLINE:
3009 case LFUN_FONT_UNDERWAVE:
3010 case LFUN_TEXTSTYLE_APPLY:
3011 case LFUN_TEXTSTYLE_UPDATE:
3012 enable = !cur.paragraph().isPassThru();
3015 case LFUN_WORD_DELETE_FORWARD:
3016 case LFUN_WORD_DELETE_BACKWARD:
3017 case LFUN_LINE_DELETE_FORWARD:
3018 case LFUN_WORD_FORWARD:
3019 case LFUN_WORD_BACKWARD:
3020 case LFUN_WORD_RIGHT:
3021 case LFUN_WORD_LEFT:
3022 case LFUN_CHAR_FORWARD:
3023 case LFUN_CHAR_FORWARD_SELECT:
3024 case LFUN_CHAR_BACKWARD:
3025 case LFUN_CHAR_BACKWARD_SELECT:
3026 case LFUN_CHAR_LEFT:
3027 case LFUN_CHAR_LEFT_SELECT:
3028 case LFUN_CHAR_RIGHT:
3029 case LFUN_CHAR_RIGHT_SELECT:
3031 case LFUN_UP_SELECT:
3033 case LFUN_DOWN_SELECT:
3034 case LFUN_PARAGRAPH_UP_SELECT:
3035 case LFUN_PARAGRAPH_DOWN_SELECT:
3036 case LFUN_LINE_BEGIN_SELECT:
3037 case LFUN_LINE_END_SELECT:
3038 case LFUN_WORD_FORWARD_SELECT:
3039 case LFUN_WORD_BACKWARD_SELECT:
3040 case LFUN_WORD_RIGHT_SELECT:
3041 case LFUN_WORD_LEFT_SELECT:
3042 case LFUN_WORD_SELECT:
3043 case LFUN_SECTION_SELECT:
3044 case LFUN_BUFFER_BEGIN:
3045 case LFUN_BUFFER_END:
3046 case LFUN_BUFFER_BEGIN_SELECT:
3047 case LFUN_BUFFER_END_SELECT:
3048 case LFUN_INSET_BEGIN:
3049 case LFUN_INSET_END:
3050 case LFUN_INSET_BEGIN_SELECT:
3051 case LFUN_INSET_END_SELECT:
3052 case LFUN_INSET_SELECT_ALL:
3053 case LFUN_PARAGRAPH_UP:
3054 case LFUN_PARAGRAPH_DOWN:
3055 case LFUN_LINE_BEGIN:
3057 case LFUN_CHAR_DELETE_FORWARD:
3058 case LFUN_CHAR_DELETE_BACKWARD:
3059 case LFUN_WORD_UPCASE:
3060 case LFUN_WORD_LOWCASE:
3061 case LFUN_WORD_CAPITALIZE:
3062 case LFUN_CHARS_TRANSPOSE:
3063 case LFUN_SERVER_GET_XY:
3064 case LFUN_SERVER_SET_XY:
3065 case LFUN_SERVER_GET_LAYOUT:
3066 case LFUN_SELF_INSERT:
3067 case LFUN_UNICODE_INSERT:
3068 case LFUN_THESAURUS_ENTRY:
3070 // these are handled in our dispatch()
3074 case LFUN_INSET_INSERT: {
3075 string const type = cmd.getArg(0);
3076 if (type == "toc") {
3078 // not allowed in description items
3079 //FIXME: couldn't this be merged in Inset::insetAllowed()?
3080 enable = !inDescriptionItem(cur);
3093 || !cur.inset().insetAllowed(code)
3094 || (cur.paragraph().layout().pass_thru && !allow_in_passthru)))
3097 flag.setEnabled(enable);
3102 void Text::pasteString(Cursor & cur, docstring const & clip,
3105 if (!clip.empty()) {
3108 insertStringAsParagraphs(cur, clip, cur.current_font);
3110 insertStringAsLines(cur, clip, cur.current_font);
3115 // FIXME: an item inset would make things much easier.
3116 bool Text::inDescriptionItem(Cursor & cur) const
3118 Paragraph & par = cur.paragraph();
3119 pos_type const pos = cur.pos();
3120 pos_type const body_pos = par.beginOfBody();
3122 if (par.layout().latextype != LATEX_LIST_ENVIRONMENT
3123 && (par.layout().latextype != LATEX_ITEM_ENVIRONMENT
3124 || par.layout().margintype != MARGIN_FIRST_DYNAMIC))
3127 return (pos < body_pos
3129 && (pos == 0 || par.getChar(pos - 1) != ' ')));