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.upDownInText(up, needsUpdate);
747 needsUpdate |= cur.beforeDispatchCursor().inMathed();
749 // if the cursor cannot be moved up or down do not remove
750 // the selection right now, but wait for the next dispatch.
752 needsUpdate |= cur.selHandle(select);
753 cur.upDownInText(up, needsUpdate);
760 case LFUN_PARAGRAPH_UP:
761 case LFUN_PARAGRAPH_UP_SELECT:
762 needsUpdate |= cur.selHandle(cmd.action() == LFUN_PARAGRAPH_UP_SELECT);
763 needsUpdate |= cursorUpParagraph(cur);
766 case LFUN_PARAGRAPH_DOWN:
767 case LFUN_PARAGRAPH_DOWN_SELECT:
768 needsUpdate |= cur.selHandle(cmd.action() == LFUN_PARAGRAPH_DOWN_SELECT);
769 needsUpdate |= cursorDownParagraph(cur);
772 case LFUN_LINE_BEGIN:
773 case LFUN_LINE_BEGIN_SELECT:
774 needsUpdate |= cur.selHandle(cmd.action() == LFUN_LINE_BEGIN_SELECT);
775 needsUpdate |= tm->cursorHome(cur);
779 case LFUN_LINE_END_SELECT:
780 needsUpdate |= cur.selHandle(cmd.action() == LFUN_LINE_END_SELECT);
781 needsUpdate |= tm->cursorEnd(cur);
784 case LFUN_SECTION_SELECT: {
785 Buffer const & buf = *cur.buffer();
786 pit_type const pit = cur.pit();
787 ParagraphList & pars = buf.text().paragraphs();
788 ParagraphList::iterator bgn = pars.begin();
789 // The first paragraph of the area to be selected:
790 ParagraphList::iterator start = boost::next(bgn, pit);
791 // The final paragraph of area to be selected:
792 ParagraphList::iterator finish = start;
793 ParagraphList::iterator end = pars.end();
795 int const thistoclevel = buf.text().getTocLevel(distance(bgn, start));
796 if (thistoclevel == Layout::NOT_IN_TOC)
800 Cursor const old_cur = cur;
801 needsUpdate |= cur.selHandle(true);
803 // Move out (down) from this section header
807 // Seek the one (on same level) below
808 for (; finish != end; ++finish, ++cur.pit()) {
809 int const toclevel = buf.text().getTocLevel(distance(bgn, finish));
810 if (toclevel != Layout::NOT_IN_TOC && toclevel <= thistoclevel)
813 cur.pos() = cur.lastpos();
815 needsUpdate |= cur != old_cur;
819 case LFUN_WORD_RIGHT:
820 case LFUN_WORD_RIGHT_SELECT:
821 if (lyxrc.visual_cursor) {
822 needsUpdate |= cur.selHandle(cmd.action() == LFUN_WORD_RIGHT_SELECT);
823 needsUpdate |= cursorVisRightOneWord(cur);
824 if (!needsUpdate && oldTopSlice == cur.top()
825 && cur.boundary() == oldBoundary) {
827 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
830 if (reverseDirectionNeeded(cur)) {
831 cmd.setAction(cmd.action() == LFUN_WORD_RIGHT_SELECT ?
832 LFUN_WORD_BACKWARD_SELECT : LFUN_WORD_BACKWARD);
834 cmd.setAction(cmd.action() == LFUN_WORD_RIGHT_SELECT ?
835 LFUN_WORD_FORWARD_SELECT : LFUN_WORD_FORWARD);
842 case LFUN_WORD_FORWARD:
843 case LFUN_WORD_FORWARD_SELECT:
844 needsUpdate |= cur.selHandle(cmd.action() == LFUN_WORD_FORWARD_SELECT);
845 needsUpdate |= cursorForwardOneWord(cur);
847 if (!needsUpdate && oldTopSlice == cur.top()
848 && cur.boundary() == oldBoundary) {
850 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
852 // we will probably be moving out the inset, so we should execute
853 // the depm-mechanism, but only when the cursor has a place to
854 // go outside this inset, i.e. in a slice above.
855 if (cur.depth() > 1 && cur.pos() == cur.lastpos()
856 && cur.pit() == cur.lastpit()) {
857 // The cursor hasn't changed yet. To give the
858 // DEPM the possibility of doing something we must
859 // provide it with two different cursors.
861 dummy.pos() = dummy.pit() = 0;
862 if (cur.bv().checkDepm(dummy, cur))
863 cur.forceBufferUpdate();
869 case LFUN_WORD_LEFT_SELECT:
870 if (lyxrc.visual_cursor) {
871 needsUpdate |= cur.selHandle(cmd.action() == LFUN_WORD_LEFT_SELECT);
872 needsUpdate |= cursorVisLeftOneWord(cur);
873 if (!needsUpdate && oldTopSlice == cur.top()
874 && cur.boundary() == oldBoundary) {
876 cmd = FuncRequest(LFUN_FINISHED_LEFT);
879 if (reverseDirectionNeeded(cur)) {
880 cmd.setAction(cmd.action() == LFUN_WORD_LEFT_SELECT ?
881 LFUN_WORD_FORWARD_SELECT : LFUN_WORD_FORWARD);
883 cmd.setAction(cmd.action() == LFUN_WORD_LEFT_SELECT ?
884 LFUN_WORD_BACKWARD_SELECT : LFUN_WORD_BACKWARD);
891 case LFUN_WORD_BACKWARD:
892 case LFUN_WORD_BACKWARD_SELECT:
893 needsUpdate |= cur.selHandle(cmd.action() == LFUN_WORD_BACKWARD_SELECT);
894 needsUpdate |= cursorBackwardOneWord(cur);
896 if (!needsUpdate && oldTopSlice == cur.top()
897 && cur.boundary() == oldBoundary) {
899 cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
901 // we will probably be moving out the inset, so we should execute
902 // the depm-mechanism, but only when the cursor has a place to
903 // go outside this inset, i.e. in a slice above.
904 if (cur.depth() > 1 && cur.pos() == 0
906 // The cursor hasn't changed yet. To give the
907 // DEPM the possibility of doing something we must
908 // provide it with two different cursors.
910 dummy.pos() = cur.lastpos();
911 dummy.pit() = cur.lastpit();
912 if (cur.bv().checkDepm(dummy, cur))
913 cur.forceBufferUpdate();
918 case LFUN_WORD_SELECT: {
919 selectWord(cur, WHOLE_WORD);
920 finishChange(cur, true);
924 case LFUN_NEWLINE_INSERT: {
925 InsetNewlineParams inp;
926 docstring arg = cmd.argument();
927 if (arg == "linebreak")
928 inp.kind = InsetNewlineParams::LINEBREAK;
930 inp.kind = InsetNewlineParams::NEWLINE;
931 cap::replaceSelection(cur);
933 cur.insert(new InsetNewline(inp));
935 moveCursor(cur, false);
939 case LFUN_TAB_INSERT: {
940 bool const multi_par_selection = cur.selection() &&
941 cur.selBegin().pit() != cur.selEnd().pit();
942 if (multi_par_selection) {
943 // If there is a multi-paragraph selection, a tab is inserted
944 // at the beginning of each paragraph.
945 cur.recordUndoSelection();
946 pit_type const pit_end = cur.selEnd().pit();
947 for (pit_type pit = cur.selBegin().pit(); pit <= pit_end; pit++) {
948 pars_[pit].insertChar(0, '\t',
949 bv->buffer().params().track_changes);
950 // Update the selection pos to make sure the selection does not
951 // change as the inserted tab will increase the logical pos.
952 if (cur.realAnchor().pit() == pit)
953 cur.realAnchor().forwardPos();
954 if (cur.pit() == pit)
959 // Maybe we shouldn't allow tabs within a line, because they
960 // are not (yet) aligned as one might do expect.
961 FuncRequest cmd(LFUN_SELF_INSERT, from_ascii("\t"));
967 case LFUN_TAB_DELETE: {
968 bool const tc = bv->buffer().params().track_changes;
969 if (cur.selection()) {
970 // If there is a selection, a tab (if present) is removed from
971 // the beginning of each paragraph.
972 cur.recordUndoSelection();
973 pit_type const pit_end = cur.selEnd().pit();
974 for (pit_type pit = cur.selBegin().pit(); pit <= pit_end; pit++) {
975 Paragraph & par = paragraphs()[pit];
978 char_type const c = par.getChar(0);
979 if (c == '\t' || c == ' ') {
980 // remove either 1 tab or 4 spaces.
981 int const n = (c == ' ' ? 4 : 1);
982 for (int i = 0; i < n
983 && !par.empty() && par.getChar(0) == c; ++i) {
984 if (cur.pit() == pit)
986 if (cur.realAnchor().pit() == pit
987 && cur.realAnchor().pos() > 0 )
988 cur.realAnchor().backwardPos();
989 par.eraseChar(0, tc);
995 // If there is no selection, try to remove a tab or some spaces
996 // before the position of the cursor.
997 Paragraph & par = paragraphs()[cur.pit()];
998 pos_type const pos = cur.pos();
1003 char_type const c = par.getChar(pos - 1);
1007 par.eraseChar(cur.pos(), tc);
1009 for (int n_spaces = 0;
1011 && par.getChar(cur.pos() - 1) == ' '
1015 par.eraseChar(cur.pos(), tc);
1022 case LFUN_CHAR_DELETE_FORWARD:
1023 if (!cur.selection()) {
1024 bool was_separator = cur.paragraph().isEnvSeparator(cur.pos());
1025 if (cur.pos() == cur.paragraph().size())
1026 // Par boundary, force full-screen update
1027 singleParUpdate = false;
1028 needsUpdate |= erase(cur);
1030 if (was_separator && cur.pos() == cur.paragraph().size()
1031 && (!cur.paragraph().layout().isEnvironment()
1032 || cur.paragraph().size() > 0)) {
1033 // Force full-screen update
1034 singleParUpdate = false;
1035 needsUpdate |= erase(cur);
1038 // It is possible to make it a lot faster still
1039 // just comment out the line below...
1041 cutSelection(cur, true, false);
1042 singleParUpdate = false;
1044 moveCursor(cur, false);
1047 case LFUN_CHAR_DELETE_BACKWARD:
1048 if (!cur.selection()) {
1049 if (bv->getIntl().getTransManager().backspace()) {
1050 bool par_boundary = cur.pos() == 0;
1051 // Par boundary, full-screen update
1053 singleParUpdate = false;
1054 needsUpdate |= backspace(cur);
1056 if (par_boundary && cur.pos() > 0
1057 && cur.paragraph().isEnvSeparator(cur.pos() - 1)) {
1058 needsUpdate |= backspace(cur);
1061 // It is possible to make it a lot faster still
1062 // just comment out the line below...
1065 cutSelection(cur, true, false);
1066 singleParUpdate = false;
1070 case LFUN_PARAGRAPH_BREAK: {
1071 cap::replaceSelection(cur);
1072 pit_type pit = cur.pit();
1073 Paragraph const & par = pars_[pit];
1074 pit_type prev = pit;
1076 if (!pars_[pit - 1].layout().isEnvironment())
1077 prev = depthHook(pit, par.getDepth());
1078 else if (pars_[pit - 1].getDepth() >= par.getDepth())
1081 if (prev < pit && cur.pos() == par.beginOfBody()
1082 && !par.isEnvSeparator(cur.pos())
1083 && !par.layout().isCommand()
1084 && pars_[prev].layout() != par.layout()
1085 && pars_[prev].layout().isEnvironment()) {
1086 if (par.layout().isEnvironment()
1087 && pars_[prev].getDepth() == par.getDepth()) {
1088 docstring const layout = par.layout().name();
1089 DocumentClass const & tc = bv->buffer().params().documentClass();
1090 lyx::dispatch(FuncRequest(LFUN_LAYOUT, tc.plainLayout().name()));
1091 lyx::dispatch(FuncRequest(LFUN_SEPARATOR_INSERT, "parbreak"));
1092 lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_BREAK, "inverse"));
1093 lyx::dispatch(FuncRequest(LFUN_LAYOUT, layout));
1095 lyx::dispatch(FuncRequest(LFUN_SEPARATOR_INSERT, "parbreak"));
1096 breakParagraph(cur);
1098 Font const f(inherit_font, cur.current_font.language());
1099 pars_[cur.pit() - 1].resetFonts(f);
1101 breakParagraph(cur, cmd.argument() == "inverse");
1107 case LFUN_INSET_INSERT: {
1110 // We have to avoid triggering InstantPreview loading
1111 // before inserting into the document. See bug #5626.
1112 bool loaded = bv->buffer().isFullyLoaded();
1113 bv->buffer().setFullyLoaded(false);
1114 Inset * inset = createInset(&bv->buffer(), cmd);
1115 bv->buffer().setFullyLoaded(loaded);
1118 // FIXME (Abdel 01/02/2006):
1119 // What follows would be a partial fix for bug 2154:
1120 // http://www.lyx.org/trac/ticket/2154
1121 // This automatically put the label inset _after_ a
1122 // numbered section. It should be possible to extend the mechanism
1123 // to any kind of LateX environement.
1124 // The correct way to fix that bug would be at LateX generation.
1125 // I'll let the code here for reference as it could be used for some
1126 // other feature like "automatic labelling".
1128 Paragraph & par = pars_[cur.pit()];
1129 if (inset->lyxCode() == LABEL_CODE
1130 && !par.layout().counter.empty() {
1131 // Go to the end of the paragraph
1132 // Warning: Because of Change-Tracking, the last
1133 // position is 'size()' and not 'size()-1':
1134 cur.pos() = par.size();
1135 // Insert a new paragraph
1136 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
1140 if (cur.selection())
1141 cutSelection(cur, true, false);
1143 if (inset->editable() && inset->asInsetText())
1144 inset->edit(cur, true);
1148 // trigger InstantPreview now
1149 if (inset->lyxCode() == EXTERNAL_CODE) {
1150 InsetExternal & ins =
1151 static_cast<InsetExternal &>(*inset);
1152 ins.updatePreview();
1159 case LFUN_INSET_DISSOLVE: {
1160 if (dissolveInset(cur)) {
1162 cur.forceBufferUpdate();
1167 case LFUN_SET_GRAPHICS_GROUP: {
1168 InsetGraphics * ins = graphics::getCurrentGraphicsInset(cur);
1174 string id = to_utf8(cmd.argument());
1175 string grp = graphics::getGroupParams(bv->buffer(), id);
1176 InsetGraphicsParams tmp, inspar = ins->getParams();
1179 inspar.groupId = to_utf8(cmd.argument());
1181 InsetGraphics::string2params(grp, bv->buffer(), tmp);
1182 tmp.filename = inspar.filename;
1186 ins->setParams(inspar);
1189 case LFUN_SPACE_INSERT:
1190 if (cur.paragraph().layout().free_spacing)
1191 insertChar(cur, ' ');
1193 doInsertInset(cur, this, cmd, false, false);
1196 moveCursor(cur, false);
1199 case LFUN_SPECIALCHAR_INSERT: {
1200 string const name = to_utf8(cmd.argument());
1201 if (name == "hyphenation")
1202 specialChar(cur, InsetSpecialChar::HYPHENATION);
1203 else if (name == "ligature-break")
1204 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
1205 else if (name == "slash")
1206 specialChar(cur, InsetSpecialChar::SLASH);
1207 else if (name == "nobreakdash")
1208 specialChar(cur, InsetSpecialChar::NOBREAKDASH);
1209 else if (name == "dots")
1210 specialChar(cur, InsetSpecialChar::LDOTS);
1211 else if (name == "end-of-sentence")
1212 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
1213 else if (name == "menu-separator")
1214 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
1215 else if (name.empty())
1216 lyxerr << "LyX function 'specialchar-insert' needs an argument." << endl;
1218 lyxerr << "Wrong argument for LyX function 'specialchar-insert'." << endl;
1222 case LFUN_IPAMACRO_INSERT: {
1223 string const arg = cmd.getArg(0);
1224 if (arg == "deco") {
1225 // Open the inset, and move the current selection
1227 doInsertInset(cur, this, cmd, true, true);
1229 // Some insets are numbered, others are shown in the outline pane so
1230 // let's update the labels and the toc backend.
1231 cur.forceBufferUpdate();
1234 if (arg == "tone-falling")
1235 ipaChar(cur, InsetIPAChar::TONE_FALLING);
1236 else if (arg == "tone-rising")
1237 ipaChar(cur, InsetIPAChar::TONE_RISING);
1238 else if (arg == "tone-high-rising")
1239 ipaChar(cur, InsetIPAChar::TONE_HIGH_RISING);
1240 else if (arg == "tone-low-rising")
1241 ipaChar(cur, InsetIPAChar::TONE_LOW_RISING);
1242 else if (arg == "tone-high-rising-falling")
1243 ipaChar(cur, InsetIPAChar::TONE_HIGH_RISING_FALLING);
1244 else if (arg.empty())
1245 lyxerr << "LyX function 'ipamacro-insert' needs an argument." << endl;
1247 lyxerr << "Wrong argument for LyX function 'ipamacro-insert'." << endl;
1251 case LFUN_WORD_UPCASE:
1252 changeCase(cur, text_uppercase);
1255 case LFUN_WORD_LOWCASE:
1256 changeCase(cur, text_lowercase);
1259 case LFUN_WORD_CAPITALIZE:
1260 changeCase(cur, text_capitalization);
1263 case LFUN_CHARS_TRANSPOSE:
1264 charsTranspose(cur);
1268 cur.message(_("Paste"));
1269 LASSERT(cur.selBegin().idx() == cur.selEnd().idx(), break);
1270 cap::replaceSelection(cur);
1272 // without argument?
1273 string const arg = to_utf8(cmd.argument());
1275 bool tryGraphics = true;
1276 if (theClipboard().isInternal())
1277 pasteFromStack(cur, bv->buffer().errorList("Paste"), 0);
1278 else if (theClipboard().hasTextContents()) {
1279 if (pasteClipboardText(cur, bv->buffer().errorList("Paste"),
1280 true, Clipboard::AnyTextType))
1281 tryGraphics = false;
1283 if (tryGraphics && theClipboard().hasGraphicsContents())
1284 pasteClipboardGraphics(cur, bv->buffer().errorList("Paste"));
1285 } else if (isStrUnsignedInt(arg)) {
1286 // we have a numerical argument
1287 pasteFromStack(cur, bv->buffer().errorList("Paste"),
1288 convert<unsigned int>(arg));
1289 } else if (arg == "html" || arg == "latex") {
1290 Clipboard::TextType type = (arg == "html") ?
1291 Clipboard::HtmlTextType : Clipboard::LaTeXTextType;
1292 pasteClipboardText(cur, bv->buffer().errorList("Paste"), true, type);
1294 Clipboard::GraphicsType type = Clipboard::AnyGraphicsType;
1296 type = Clipboard::PdfGraphicsType;
1297 else if (arg == "png")
1298 type = Clipboard::PngGraphicsType;
1299 else if (arg == "jpeg")
1300 type = Clipboard::JpegGraphicsType;
1301 else if (arg == "linkback")
1302 type = Clipboard::LinkBackGraphicsType;
1303 else if (arg == "emf")
1304 type = Clipboard::EmfGraphicsType;
1305 else if (arg == "wmf")
1306 type = Clipboard::WmfGraphicsType;
1308 // We used to assert, but couldn't the argument come from, say, the
1309 // minibuffer and just be mistyped?
1310 LYXERR0("Unrecognized graphics type: " << arg);
1312 pasteClipboardGraphics(cur, bv->buffer().errorList("Paste"), type);
1315 bv->buffer().errors("Paste");
1316 cur.clearSelection(); // bug 393
1322 cutSelection(cur, true, true);
1323 cur.message(_("Cut"));
1328 cur.message(_("Copy"));
1331 case LFUN_SERVER_GET_XY:
1332 cur.message(from_utf8(
1333 convert<string>(tm->cursorX(cur.top(), cur.boundary()))
1334 + ' ' + convert<string>(tm->cursorY(cur.top(), cur.boundary()))));
1337 case LFUN_SERVER_SET_XY: {
1340 istringstream is(to_utf8(cmd.argument()));
1343 lyxerr << "SETXY: Could not parse coordinates in '"
1344 << to_utf8(cmd.argument()) << endl;
1346 tm->setCursorFromCoordinates(cur, x, y);
1350 case LFUN_SERVER_GET_LAYOUT:
1351 cur.message(cur.paragraph().layout().name());
1355 docstring layout = cmd.argument();
1356 LYXERR(Debug::INFO, "LFUN_LAYOUT: (arg) " << to_utf8(layout));
1358 Paragraph const & para = cur.paragraph();
1359 docstring const old_layout = para.layout().name();
1360 DocumentClass const & tclass = bv->buffer().params().documentClass();
1363 layout = tclass.defaultLayoutName();
1365 if (owner_->forcePlainLayout())
1366 // in this case only the empty layout is allowed
1367 layout = tclass.plainLayoutName();
1368 else if (para.usePlainLayout()) {
1369 // in this case, default layout maps to empty layout
1370 if (layout == tclass.defaultLayoutName())
1371 layout = tclass.plainLayoutName();
1373 // otherwise, the empty layout maps to the default
1374 if (layout == tclass.plainLayoutName())
1375 layout = tclass.defaultLayoutName();
1378 bool hasLayout = tclass.hasLayout(layout);
1380 // If the entry is obsolete, use the new one instead.
1382 docstring const & obs = tclass[layout].obsoleted_by();
1388 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
1389 from_utf8(N_(" not known")));
1393 bool change_layout = (old_layout != layout);
1395 if (!change_layout && cur.selection() &&
1396 cur.selBegin().pit() != cur.selEnd().pit())
1398 pit_type spit = cur.selBegin().pit();
1399 pit_type epit = cur.selEnd().pit() + 1;
1400 while (spit != epit) {
1401 if (pars_[spit].layout().name() != old_layout) {
1402 change_layout = true;
1410 setLayout(cur, layout);
1412 Layout::LaTeXArgMap args = tclass[layout].args();
1413 Layout::LaTeXArgMap::const_iterator lait = args.begin();
1414 Layout::LaTeXArgMap::const_iterator const laend = args.end();
1415 for (; lait != laend; ++lait) {
1416 Layout::latexarg arg = (*lait).second;
1417 if (arg.autoinsert) {
1418 FuncRequest cmd(LFUN_ARGUMENT_INSERT, (*lait).first);
1426 case LFUN_ENVIRONMENT_SPLIT: {
1427 bool const outer = cmd.argument() == "outer";
1428 Paragraph const & para = cur.paragraph();
1429 docstring layout = para.layout().name();
1430 depth_type split_depth = cur.paragraph().params().depth();
1432 // check if we have an environment in our nesting hierarchy
1433 pit_type pit = cur.pit();
1434 Paragraph cpar = pars_[pit];
1436 if (pit == 0 || cpar.params().depth() == 0)
1440 if (cpar.params().depth() < split_depth
1441 && cpar.layout().isEnvironment()) {
1442 layout = cpar.layout().name();
1443 split_depth = cpar.params().depth();
1448 lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_BREAK));
1450 while (cur.paragraph().params().depth() > split_depth)
1451 lyx::dispatch(FuncRequest(LFUN_DEPTH_DECREMENT));
1453 DocumentClass const & tc = bv->buffer().params().documentClass();
1454 lyx::dispatch(FuncRequest(LFUN_LAYOUT, tc.plainLayout().name()));
1455 lyx::dispatch(FuncRequest(LFUN_SEPARATOR_INSERT, "plain"));
1456 lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_BREAK, "inverse"));
1457 lyx::dispatch(FuncRequest(LFUN_LAYOUT, layout));
1462 case LFUN_CLIPBOARD_PASTE:
1463 cap::replaceSelection(cur);
1464 pasteClipboardText(cur, bv->buffer().errorList("Paste"),
1465 cmd.argument() == "paragraph");
1466 bv->buffer().errors("Paste");
1469 case LFUN_CLIPBOARD_PASTE_SIMPLE:
1470 cap::replaceSelection(cur);
1471 pasteSimpleText(cur, cmd.argument() == "paragraph");
1474 case LFUN_PRIMARY_SELECTION_PASTE:
1475 cap::replaceSelection(cur);
1476 pasteString(cur, theSelection().get(),
1477 cmd.argument() == "paragraph");
1480 case LFUN_SELECTION_PASTE:
1481 // Copy the selection buffer to the clipboard stack,
1482 // because we want it to appear in the "Edit->Paste
1484 cap::replaceSelection(cur);
1485 cap::copySelectionToStack();
1486 cap::pasteSelection(bv->cursor(), bv->buffer().errorList("Paste"));
1487 bv->buffer().errors("Paste");
1490 case LFUN_UNICODE_INSERT: {
1491 if (cmd.argument().empty())
1493 docstring hexstring = cmd.argument();
1494 if (isHex(hexstring)) {
1495 char_type c = hexToInt(hexstring);
1496 if (c >= 32 && c < 0x10ffff) {
1497 lyxerr << "Inserting c: " << c << endl;
1498 docstring s = docstring(1, c);
1499 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
1505 case LFUN_QUOTE_INSERT: {
1506 cap::replaceSelection(cur);
1509 Paragraph const & par = cur.paragraph();
1510 pos_type pos = cur.pos();
1511 // Ignore deleted text before cursor
1512 while (pos > 0 && par.isDeleted(pos - 1))
1515 BufferParams const & bufparams = bv->buffer().params();
1517 par.getFontSettings(bufparams, pos).language()->lang() == "hebrew";
1518 bool const allow_inset_quote = !(par.isPassThru() || hebrew);
1520 string const arg = to_utf8(cmd.argument());
1521 if (allow_inset_quote) {
1523 if (pos > 0 && (!cur.prevInset() || !cur.prevInset()->isSpace()))
1524 c = par.getChar(pos - 1);
1525 InsetQuotes::QuoteTimes const quote_type = (arg == "single")
1526 ? InsetQuotes::SingleQuotes : InsetQuotes::DoubleQuotes;
1527 cur.insert(new InsetQuotes(cur.buffer(), c, quote_type));
1530 // The cursor might have been invalidated by the replaceSelection.
1531 cur.buffer()->changed(true);
1532 string const quote_string = (arg == "single") ? "'" : "\"";
1533 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, quote_string));
1538 case LFUN_DATE_INSERT: {
1539 string const format = cmd.argument().empty()
1540 ? lyxrc.date_insert_format : to_utf8(cmd.argument());
1541 string const time = formatted_time(current_time(), format);
1542 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, time));
1546 case LFUN_MOUSE_TRIPLE:
1547 if (cmd.button() == mouse_button::button1) {
1548 tm->cursorHome(cur);
1556 case LFUN_MOUSE_DOUBLE:
1557 if (cmd.button() == mouse_button::button1) {
1558 selectWord(cur, WHOLE_WORD_STRICT);
1563 // Single-click on work area
1564 case LFUN_MOUSE_PRESS: {
1565 // We are not marking a selection with the keyboard in any case.
1566 Cursor & bvcur = cur.bv().cursor();
1567 bvcur.setMark(false);
1568 switch (cmd.button()) {
1569 case mouse_button::button1:
1571 if (!bv->mouseSetCursor(cur, cmd.argument() == "region-select"))
1572 cur.screenUpdateFlags(Update::SinglePar | Update::FitCursor);
1573 if (bvcur.wordSelection())
1574 selectWord(bvcur, WHOLE_WORD);
1577 case mouse_button::button2:
1578 // Middle mouse pasting.
1579 bv->mouseSetCursor(cur);
1581 FuncRequest(LFUN_COMMAND_ALTERNATIVES,
1582 "selection-paste ; primary-selection-paste paragraph"));
1583 cur.noScreenUpdate();
1586 case mouse_button::button3: {
1587 // Don't do anything if we right-click a
1588 // selection, a context menu will popup.
1589 if (bvcur.selection() && cur >= bvcur.selectionBegin()
1590 && cur < bvcur.selectionEnd()) {
1591 cur.noScreenUpdate();
1594 if (!bv->mouseSetCursor(cur, false))
1595 cur.screenUpdateFlags(Update::SinglePar | Update::FitCursor);
1601 } // switch (cmd.button())
1604 case LFUN_MOUSE_MOTION: {
1605 // Mouse motion with right or middle mouse do nothing for now.
1606 if (cmd.button() != mouse_button::button1) {
1607 cur.noScreenUpdate();
1610 // ignore motions deeper nested than the real anchor
1611 Cursor & bvcur = cur.bv().cursor();
1612 if (!bvcur.realAnchor().hasPart(cur)) {
1616 CursorSlice old = bvcur.top();
1618 int const wh = bv->workHeight();
1619 int const y = max(0, min(wh - 1, cmd.y()));
1621 tm->setCursorFromCoordinates(cur, cmd.x(), y);
1622 cur.setTargetX(cmd.x());
1624 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1625 else if (cmd.y() < 0)
1626 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1627 // This is to allow jumping over large insets
1628 if (cur.top() == old) {
1630 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1631 else if (cmd.y() < 0)
1632 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1634 // We continue with our existing selection or start a new one, so don't
1635 // reset the anchor.
1636 bvcur.setCursor(cur);
1637 bvcur.setSelection(true);
1638 if (cur.top() == old) {
1639 // We didn't move one iota, so no need to update the screen.
1640 cur.screenUpdateFlags(Update::SinglePar | Update::FitCursor);
1641 //cur.noScreenUpdate();
1647 case LFUN_MOUSE_RELEASE:
1648 switch (cmd.button()) {
1649 case mouse_button::button1:
1650 // Cursor was set at LFUN_MOUSE_PRESS or LFUN_MOUSE_MOTION time.
1651 // If there is a new selection, update persistent selection;
1652 // otherwise, single click does not clear persistent selection
1654 if (cur.selection()) {
1655 // Finish selection. If double click,
1656 // cur is moved to the end of word by
1657 // selectWord but bvcur is current
1659 cur.bv().cursor().setSelection();
1660 // We might have removed an empty but drawn selection
1661 // (probably a margin)
1662 cur.screenUpdateFlags(Update::SinglePar | Update::FitCursor);
1664 cur.noScreenUpdate();
1665 // FIXME: We could try to handle drag and drop of selection here.
1668 case mouse_button::button2:
1669 // Middle mouse pasting is handled at mouse press time,
1670 // see LFUN_MOUSE_PRESS.
1671 cur.noScreenUpdate();
1674 case mouse_button::button3:
1675 // Cursor was set at LFUN_MOUSE_PRESS time.
1676 // FIXME: If there is a selection we could try to handle a special
1677 // drag & drop context menu.
1678 cur.noScreenUpdate();
1681 case mouse_button::none:
1682 case mouse_button::button4:
1683 case mouse_button::button5:
1685 } // switch (cmd.button())
1689 case LFUN_SELF_INSERT: {
1690 if (cmd.argument().empty())
1693 // Automatically delete the currently selected
1694 // text and replace it with what is being
1695 // typed in now. Depends on lyxrc settings
1696 // "auto_region_delete", which defaults to
1699 if (lyxrc.auto_region_delete && cur.selection())
1700 cutSelection(cur, false, false);
1702 cur.clearSelection();
1704 docstring::const_iterator cit = cmd.argument().begin();
1705 docstring::const_iterator const end = cmd.argument().end();
1706 for (; cit != end; ++cit)
1707 bv->translateAndInsert(*cit, this, cur);
1710 moveCursor(cur, false);
1711 cur.markNewWordPosition();
1712 bv->bookmarkEditPosition();
1716 case LFUN_HREF_INSERT: {
1717 // FIXME If we're actually given an argument, shouldn't
1718 // we use it, whether or not we have a selection?
1719 docstring content = cmd.argument();
1720 if (cur.selection()) {
1721 content = cur.selectionAsString(false);
1722 cutSelection(cur, true, false);
1725 InsetCommandParams p(HYPERLINK_CODE);
1726 if (!content.empty()){
1727 // if it looks like a link, we'll put it as target,
1728 // otherwise as name (bug #8792).
1731 // regex_match(to_utf8(content), matches, link_re)
1732 // because smatch stores pointers to the substrings rather
1733 // than making copies of them. And those pointers become
1734 // invalid after regex_match returns, since it is then
1735 // being given a temporary object. (Thanks to Georg for
1736 // figuring that out.)
1737 regex const link_re("^([a-z]+):.*");
1739 string const c = to_utf8(lowercase(content));
1741 if (c.substr(0,7) == "mailto:") {
1742 p["target"] = content;
1743 p["type"] = from_ascii("mailto:");
1744 } else if (regex_match(c, matches, link_re)) {
1745 p["target"] = content;
1746 string protocol = matches.str(1);
1747 if (protocol == "file")
1748 p["type"] = from_ascii("file:");
1750 p["name"] = content;
1752 string const data = InsetCommand::params2string(p);
1754 // we need to have a target. if we already have one, then
1755 // that gets used at the default for the name, too, which
1756 // is probably what is wanted.
1757 if (p["target"].empty()) {
1758 bv->showDialog("href", data);
1760 FuncRequest fr(LFUN_INSET_INSERT, data);
1766 case LFUN_LABEL_INSERT: {
1767 InsetCommandParams p(LABEL_CODE);
1768 // Try to generate a valid label
1769 p["name"] = (cmd.argument().empty()) ?
1770 cur.getPossibleLabel() :
1772 string const data = InsetCommand::params2string(p);
1774 if (cmd.argument().empty()) {
1775 bv->showDialog("label", data);
1777 FuncRequest fr(LFUN_INSET_INSERT, data);
1783 case LFUN_INFO_INSERT: {
1785 if (cmd.argument().empty() && cur.selection()) {
1786 // if command argument is empty use current selection as parameter.
1787 docstring ds = cur.selectionAsString(false);
1788 cutSelection(cur, true, false);
1789 FuncRequest cmd0(cmd, ds);
1790 inset = createInset(cur.buffer(), cmd0);
1792 inset = createInset(cur.buffer(), cmd);
1797 insertInset(cur, inset);
1801 case LFUN_CAPTION_INSERT:
1802 case LFUN_FOOTNOTE_INSERT:
1803 case LFUN_NOTE_INSERT:
1804 case LFUN_BOX_INSERT:
1805 case LFUN_BRANCH_INSERT:
1806 case LFUN_PHANTOM_INSERT:
1807 case LFUN_ERT_INSERT:
1808 case LFUN_LISTING_INSERT:
1809 case LFUN_MARGINALNOTE_INSERT:
1810 case LFUN_ARGUMENT_INSERT:
1811 case LFUN_INDEX_INSERT:
1812 case LFUN_PREVIEW_INSERT:
1813 case LFUN_SCRIPT_INSERT:
1814 case LFUN_IPA_INSERT:
1815 // Open the inset, and move the current selection
1817 doInsertInset(cur, this, cmd, true, true);
1819 // Some insets are numbered, others are shown in the outline pane so
1820 // let's update the labels and the toc backend.
1821 cur.forceBufferUpdate();
1824 case LFUN_FLEX_INSERT: {
1825 // Open the inset, and move the current selection
1827 bool const sel = cur.selection();
1828 doInsertInset(cur, this, cmd, true, true);
1829 // Insert auto-insert arguments
1830 bool autoargs = false;
1831 Layout::LaTeXArgMap args = cur.inset().getLayout().latexargs();
1832 Layout::LaTeXArgMap::const_iterator lait = args.begin();
1833 Layout::LaTeXArgMap::const_iterator const laend = args.end();
1834 for (; lait != laend; ++lait) {
1835 Layout::latexarg arg = (*lait).second;
1836 if (arg.autoinsert) {
1837 // The cursor might have been invalidated by the replaceSelection.
1838 cur.buffer()->changed(true);
1839 FuncRequest cmd(LFUN_ARGUMENT_INSERT, (*lait).first);
1846 cur.leaveInset(cur.inset());
1849 // Some insets are numbered, others are shown in the outline pane so
1850 // let's update the labels and the toc backend.
1851 cur.forceBufferUpdate();
1855 case LFUN_TABULAR_INSERT:
1856 // if there were no arguments, just open the dialog
1857 if (doInsertInset(cur, this, cmd, false, true))
1860 bv->showDialog("tabularcreate");
1864 case LFUN_FLOAT_INSERT:
1865 case LFUN_FLOAT_WIDE_INSERT:
1866 case LFUN_WRAP_INSERT: {
1867 // will some content be moved into the inset?
1868 bool const content = cur.selection();
1869 // does the content consist of multiple paragraphs?
1870 bool const singlepar = (cur.selBegin().pit() == cur.selEnd().pit());
1872 doInsertInset(cur, this, cmd, true, true);
1875 // If some single-par content is moved into the inset,
1876 // doInsertInset puts the cursor outside the inset.
1877 // To insert the caption we put it back into the inset.
1878 // FIXME cleanup doInsertInset to avoid such dances!
1879 if (content && singlepar)
1882 ParagraphList & pars = cur.text()->paragraphs();
1884 DocumentClass const & tclass = bv->buffer().params().documentClass();
1886 // add a separate paragraph for the caption inset
1887 pars.push_back(Paragraph());
1888 pars.back().setInsetOwner(&cur.text()->inset());
1889 pars.back().setPlainOrDefaultLayout(tclass);
1890 int cap_pit = pars.size() - 1;
1892 // if an empty inset was created, we create an additional empty
1893 // paragraph at the bottom so that the user can choose where to put
1894 // the graphics (or table).
1896 pars.push_back(Paragraph());
1897 pars.back().setInsetOwner(&cur.text()->inset());
1898 pars.back().setPlainOrDefaultLayout(tclass);
1901 // reposition the cursor to the caption
1902 cur.pit() = cap_pit;
1904 // FIXME: This Text/Cursor dispatch handling is a mess!
1905 // We cannot use Cursor::dispatch here it needs access to up to
1907 FuncRequest cmd_caption(LFUN_CAPTION_INSERT);
1908 doInsertInset(cur, cur.text(), cmd_caption, true, false);
1909 cur.forceBufferUpdate();
1910 cur.screenUpdateFlags(Update::Force);
1911 // FIXME: When leaving the Float (or Wrap) inset we should
1912 // delete any empty paragraph left above or below the
1917 case LFUN_NOMENCL_INSERT: {
1918 InsetCommandParams p(NOMENCL_CODE);
1919 if (cmd.argument().empty())
1920 p["symbol"] = bv->cursor().innerText()->getStringToIndex(bv->cursor());
1922 p["symbol"] = cmd.argument();
1923 string const data = InsetCommand::params2string(p);
1924 bv->showDialog("nomenclature", data);
1928 case LFUN_INDEX_PRINT: {
1929 InsetCommandParams p(INDEX_PRINT_CODE);
1930 if (cmd.argument().empty())
1931 p["type"] = from_ascii("idx");
1933 p["type"] = cmd.argument();
1934 string const data = InsetCommand::params2string(p);
1935 FuncRequest fr(LFUN_INSET_INSERT, data);
1940 case LFUN_NOMENCL_PRINT:
1941 case LFUN_NEWPAGE_INSERT:
1943 doInsertInset(cur, this, cmd, false, false);
1947 case LFUN_SEPARATOR_INSERT: {
1948 doInsertInset(cur, this, cmd, false, false);
1950 // remove a following space
1951 Paragraph & par = cur.paragraph();
1952 if (cur.pos() != cur.lastpos() && par.isLineSeparator(cur.pos()))
1953 par.eraseChar(cur.pos(), cur.buffer()->params().track_changes);
1957 case LFUN_DEPTH_DECREMENT:
1958 changeDepth(cur, DEC_DEPTH);
1961 case LFUN_DEPTH_INCREMENT:
1962 changeDepth(cur, INC_DEPTH);
1965 case LFUN_MATH_DISPLAY:
1966 mathDispatch(cur, cmd, true);
1969 case LFUN_REGEXP_MODE:
1970 regexpDispatch(cur, cmd);
1973 case LFUN_MATH_MODE:
1974 if (cmd.argument() == "on")
1975 // don't pass "on" as argument
1976 // (it would appear literally in the first cell)
1977 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1979 mathDispatch(cur, cmd, false);
1982 case LFUN_MATH_MACRO:
1983 if (cmd.argument().empty())
1984 cur.errorMessage(from_utf8(N_("Missing argument")));
1987 string s = to_utf8(cmd.argument());
1988 string const s1 = token(s, ' ', 1);
1989 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1990 string const s2 = token(s, ' ', 2);
1991 MacroType type = MacroTypeNewcommand;
1993 type = MacroTypeDef;
1994 MathMacroTemplate * inset = new MathMacroTemplate(cur.buffer(),
1995 from_utf8(token(s, ' ', 0)), nargs, false, type);
1996 inset->setBuffer(bv->buffer());
1997 insertInset(cur, inset);
1999 // enter macro inset and select the name
2001 cur.top().pos() = cur.top().lastpos();
2003 cur.setSelection(true);
2004 cur.top().pos() = 0;
2008 // passthrough hat and underscore outside mathed:
2009 case LFUN_MATH_SUBSCRIPT:
2010 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
2012 case LFUN_MATH_SUPERSCRIPT:
2013 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
2016 case LFUN_MATH_INSERT:
2017 case LFUN_MATH_AMS_MATRIX:
2018 case LFUN_MATH_MATRIX:
2019 case LFUN_MATH_DELIM:
2020 case LFUN_MATH_BIGDELIM: {
2022 cap::replaceSelection(cur);
2023 cur.insert(new InsetMathHull(cur.buffer(), hullSimple));
2024 checkAndActivateInset(cur, true);
2025 LASSERT(cur.inMathed(), break);
2030 case LFUN_FONT_EMPH: {
2031 Font font(ignore_font, ignore_language);
2032 font.fontInfo().setEmph(FONT_TOGGLE);
2033 toggleAndShow(cur, this, font);
2037 case LFUN_FONT_ITAL: {
2038 Font font(ignore_font, ignore_language);
2039 font.fontInfo().setShape(ITALIC_SHAPE);
2040 toggleAndShow(cur, this, font);
2044 case LFUN_FONT_BOLD:
2045 case LFUN_FONT_BOLDSYMBOL: {
2046 Font font(ignore_font, ignore_language);
2047 font.fontInfo().setSeries(BOLD_SERIES);
2048 toggleAndShow(cur, this, font);
2052 case LFUN_FONT_NOUN: {
2053 Font font(ignore_font, ignore_language);
2054 font.fontInfo().setNoun(FONT_TOGGLE);
2055 toggleAndShow(cur, this, font);
2059 case LFUN_FONT_TYPEWRITER: {
2060 Font font(ignore_font, ignore_language);
2061 font.fontInfo().setFamily(TYPEWRITER_FAMILY); // no good
2062 toggleAndShow(cur, this, font);
2066 case LFUN_FONT_SANS: {
2067 Font font(ignore_font, ignore_language);
2068 font.fontInfo().setFamily(SANS_FAMILY);
2069 toggleAndShow(cur, this, font);
2073 case LFUN_FONT_ROMAN: {
2074 Font font(ignore_font, ignore_language);
2075 font.fontInfo().setFamily(ROMAN_FAMILY);
2076 toggleAndShow(cur, this, font);
2080 case LFUN_FONT_DEFAULT: {
2081 Font font(inherit_font, ignore_language);
2082 toggleAndShow(cur, this, font);
2086 case LFUN_FONT_STRIKEOUT: {
2087 Font font(ignore_font, ignore_language);
2088 font.fontInfo().setStrikeout(FONT_TOGGLE);
2089 toggleAndShow(cur, this, font);
2093 case LFUN_FONT_UNDERUNDERLINE: {
2094 Font font(ignore_font, ignore_language);
2095 font.fontInfo().setUuline(FONT_TOGGLE);
2096 toggleAndShow(cur, this, font);
2100 case LFUN_FONT_UNDERWAVE: {
2101 Font font(ignore_font, ignore_language);
2102 font.fontInfo().setUwave(FONT_TOGGLE);
2103 toggleAndShow(cur, this, font);
2107 case LFUN_FONT_UNDERLINE: {
2108 Font font(ignore_font, ignore_language);
2109 font.fontInfo().setUnderbar(FONT_TOGGLE);
2110 toggleAndShow(cur, this, font);
2114 case LFUN_FONT_SIZE: {
2115 Font font(ignore_font, ignore_language);
2116 setLyXSize(to_utf8(cmd.argument()), font.fontInfo());
2117 toggleAndShow(cur, this, font);
2121 case LFUN_LANGUAGE: {
2122 string const lang_arg = cmd.getArg(0);
2123 bool const reset = (lang_arg.empty() || lang_arg == "reset");
2124 Language const * lang =
2125 reset ? reset_language
2126 : languages.getLanguage(lang_arg);
2127 // we allow reset_language, which is 0, but only if it
2128 // was requested via empty or "reset" arg.
2129 if (!lang && !reset)
2131 bool const toggle = (cmd.getArg(1) != "set");
2132 selectWordWhenUnderCursor(cur, WHOLE_WORD_STRICT);
2133 Font font(ignore_font, lang);
2134 toggleAndShow(cur, this, font, toggle);
2138 case LFUN_TEXTSTYLE_APPLY:
2139 toggleAndShow(cur, this, freefont, toggleall);
2140 cur.message(_("Character set"));
2143 // Set the freefont using the contents of \param data dispatched from
2144 // the frontends and apply it at the current cursor location.
2145 case LFUN_TEXTSTYLE_UPDATE: {
2148 if (font.fromString(to_utf8(cmd.argument()), toggle)) {
2151 toggleAndShow(cur, this, freefont, toggleall);
2152 cur.message(_("Character set"));
2154 lyxerr << "Argument not ok";
2159 case LFUN_FINISHED_LEFT:
2160 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_LEFT:\n" << cur);
2161 // We're leaving an inset, going left. If the inset is LTR, we're
2162 // leaving from the front, so we should not move (remain at --- but
2163 // not in --- the inset). If the inset is RTL, move left, without
2164 // entering the inset itself; i.e., move to after the inset.
2165 if (cur.paragraph().getFontSettings(
2166 cur.bv().buffer().params(), cur.pos()).isRightToLeft())
2167 cursorVisLeft(cur, true);
2170 case LFUN_FINISHED_RIGHT:
2171 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_RIGHT:\n" << cur);
2172 // We're leaving an inset, going right. If the inset is RTL, we're
2173 // leaving from the front, so we should not move (remain at --- but
2174 // not in --- the inset). If the inset is LTR, move right, without
2175 // entering the inset itself; i.e., move to after the inset.
2176 if (!cur.paragraph().getFontSettings(
2177 cur.bv().buffer().params(), cur.pos()).isRightToLeft())
2178 cursorVisRight(cur, true);
2181 case LFUN_FINISHED_BACKWARD:
2182 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_BACKWARD:\n" << cur);
2185 case LFUN_FINISHED_FORWARD:
2186 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_FORWARD:\n" << cur);
2188 cur.setCurrentFont();
2191 case LFUN_LAYOUT_PARAGRAPH: {
2193 params2string(cur.paragraph(), data);
2194 data = "show\n" + data;
2195 bv->showDialog("paragraph", data);
2199 case LFUN_PARAGRAPH_UPDATE: {
2201 params2string(cur.paragraph(), data);
2203 // Will the paragraph accept changes from the dialog?
2205 cur.inset().allowParagraphCustomization(cur.idx());
2207 data = "update " + convert<string>(accept) + '\n' + data;
2208 bv->updateDialog("paragraph", data);
2212 case LFUN_ACCENT_UMLAUT:
2213 case LFUN_ACCENT_CIRCUMFLEX:
2214 case LFUN_ACCENT_GRAVE:
2215 case LFUN_ACCENT_ACUTE:
2216 case LFUN_ACCENT_TILDE:
2217 case LFUN_ACCENT_CEDILLA:
2218 case LFUN_ACCENT_MACRON:
2219 case LFUN_ACCENT_DOT:
2220 case LFUN_ACCENT_UNDERDOT:
2221 case LFUN_ACCENT_UNDERBAR:
2222 case LFUN_ACCENT_CARON:
2223 case LFUN_ACCENT_BREVE:
2224 case LFUN_ACCENT_TIE:
2225 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
2226 case LFUN_ACCENT_CIRCLE:
2227 case LFUN_ACCENT_OGONEK:
2228 theApp()->handleKeyFunc(cmd.action());
2229 if (!cmd.argument().empty())
2230 // FIXME: Are all these characters encoded in one byte in utf8?
2231 bv->translateAndInsert(cmd.argument()[0], this, cur);
2232 cur.screenUpdateFlags(Update::FitCursor);
2235 case LFUN_FLOAT_LIST_INSERT: {
2236 DocumentClass const & tclass = bv->buffer().params().documentClass();
2237 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
2239 if (cur.selection())
2240 cutSelection(cur, true, false);
2241 breakParagraph(cur);
2243 if (cur.lastpos() != 0) {
2244 cursorBackward(cur);
2245 breakParagraph(cur);
2248 docstring const laystr = cur.inset().usePlainLayout() ?
2249 tclass.plainLayoutName() :
2250 tclass.defaultLayoutName();
2251 setLayout(cur, laystr);
2252 ParagraphParameters p;
2253 // FIXME If this call were replaced with one to clearParagraphParams(),
2254 // then we could get rid of this method altogether.
2255 setParagraphs(cur, p);
2256 // FIXME This should be simplified when InsetFloatList takes a
2257 // Buffer in its constructor.
2258 InsetFloatList * ifl = new InsetFloatList(cur.buffer(), to_utf8(cmd.argument()));
2259 ifl->setBuffer(bv->buffer());
2260 insertInset(cur, ifl);
2263 lyxerr << "Non-existent float type: "
2264 << to_utf8(cmd.argument()) << endl;
2269 case LFUN_CHANGE_ACCEPT: {
2270 acceptOrRejectChanges(cur, ACCEPT);
2274 case LFUN_CHANGE_REJECT: {
2275 acceptOrRejectChanges(cur, REJECT);
2279 case LFUN_THESAURUS_ENTRY: {
2280 docstring arg = cmd.argument();
2282 arg = cur.selectionAsString(false);
2284 if (arg.size() > 100 || arg.empty()) {
2285 // Get word or selection
2286 selectWordWhenUnderCursor(cur, WHOLE_WORD);
2287 arg = cur.selectionAsString(false);
2288 arg += " lang=" + from_ascii(cur.getFont().language()->lang());
2291 bv->showDialog("thesaurus", to_utf8(arg));
2295 case LFUN_SPELLING_ADD: {
2296 docstring word = from_utf8(cmd.getArg(0));
2299 word = cur.selectionAsString(false);
2301 if (word.size() > 100 || word.empty()) {
2302 // Get word or selection
2303 selectWordWhenUnderCursor(cur, WHOLE_WORD);
2304 word = cur.selectionAsString(false);
2306 lang = const_cast<Language *>(cur.getFont().language());
2308 lang = const_cast<Language *>(languages.getLanguage(cmd.getArg(1)));
2309 WordLangTuple wl(word, lang);
2310 theSpellChecker()->insert(wl);
2314 case LFUN_SPELLING_IGNORE: {
2315 docstring word = from_utf8(cmd.getArg(0));
2318 word = cur.selectionAsString(false);
2320 if (word.size() > 100 || word.empty()) {
2321 // Get word or selection
2322 selectWordWhenUnderCursor(cur, WHOLE_WORD);
2323 word = cur.selectionAsString(false);
2325 lang = const_cast<Language *>(cur.getFont().language());
2327 lang = const_cast<Language *>(languages.getLanguage(cmd.getArg(1)));
2328 WordLangTuple wl(word, lang);
2329 theSpellChecker()->accept(wl);
2333 case LFUN_SPELLING_REMOVE: {
2334 docstring word = from_utf8(cmd.getArg(0));
2337 word = cur.selectionAsString(false);
2339 if (word.size() > 100 || word.empty()) {
2340 // Get word or selection
2341 selectWordWhenUnderCursor(cur, WHOLE_WORD);
2342 word = cur.selectionAsString(false);
2344 lang = const_cast<Language *>(cur.getFont().language());
2346 lang = const_cast<Language *>(languages.getLanguage(cmd.getArg(1)));
2347 WordLangTuple wl(word, lang);
2348 theSpellChecker()->remove(wl);
2352 case LFUN_PARAGRAPH_PARAMS_APPLY: {
2353 // Given data, an encoding of the ParagraphParameters
2354 // generated in the Paragraph dialog, this function sets
2355 // the current paragraph, or currently selected paragraphs,
2357 // NOTE: This function overrides all existing settings.
2358 setParagraphs(cur, cmd.argument());
2359 cur.message(_("Paragraph layout set"));
2363 case LFUN_PARAGRAPH_PARAMS: {
2364 // Given data, an encoding of the ParagraphParameters as we'd
2365 // find them in a LyX file, this function modifies the current paragraph,
2366 // or currently selected paragraphs.
2367 // NOTE: This function only modifies, and does not override, existing
2369 setParagraphs(cur, cmd.argument(), true);
2370 cur.message(_("Paragraph layout set"));
2375 if (cur.selection()) {
2376 cur.setSelection(false);
2379 // This used to be LFUN_FINISHED_RIGHT, I think FORWARD is more
2380 // correct, but I'm not 100% sure -- dov, 071019
2381 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
2385 case LFUN_OUTLINE_UP:
2386 outline(OutlineUp, cur);
2387 setCursor(cur, cur.pit(), 0);
2388 cur.forceBufferUpdate();
2392 case LFUN_OUTLINE_DOWN:
2393 outline(OutlineDown, cur);
2394 setCursor(cur, cur.pit(), 0);
2395 cur.forceBufferUpdate();
2399 case LFUN_OUTLINE_IN:
2400 outline(OutlineIn, cur);
2401 cur.forceBufferUpdate();
2405 case LFUN_OUTLINE_OUT:
2406 outline(OutlineOut, cur);
2407 cur.forceBufferUpdate();
2412 LYXERR(Debug::ACTION, "Command " << cmd << " not DISPATCHED by Text");
2417 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
2419 if (lyxrc.spellcheck_continuously && !needsUpdate) {
2420 // Check for misspelled text
2421 // The redraw is useful because of the painting of
2422 // misspelled markers depends on the cursor position.
2423 // Trigger a redraw for cursor moves inside misspelled text.
2424 if (!cur.inTexted()) {
2425 // move from regular text to math
2426 needsUpdate = last_misspelled;
2427 } else if (oldTopSlice != cur.top() || oldBoundary != cur.boundary()) {
2428 // move inside regular text
2429 needsUpdate = last_misspelled
2430 || cur.paragraph().isMisspelled(cur.pos(), true);
2434 // FIXME: The cursor flag is reset two lines below
2435 // so we need to check here if some of the LFUN did touch that.
2436 // for now only Text::erase() and Text::backspace() do that.
2437 // The plan is to verify all the LFUNs and then to remove this
2438 // singleParUpdate boolean altogether.
2439 if (cur.result().screenUpdate() & Update::Force) {
2440 singleParUpdate = false;
2444 // FIXME: the following code should go in favor of fine grained
2445 // update flag treatment.
2446 if (singleParUpdate) {
2447 // Inserting characters does not change par height in general. So, try
2448 // to update _only_ this paragraph. BufferView will detect if a full
2449 // metrics update is needed anyway.
2450 cur.screenUpdateFlags(Update::SinglePar | Update::FitCursor);
2454 && &oldTopSlice.inset() == &cur.inset()
2455 && oldTopSlice.idx() == cur.idx()
2456 && !oldSelection // oldSelection is a backup of cur.selection() at the beginning of the function.
2457 && !cur.selection())
2458 // FIXME: it would be better if we could just do this
2460 //if (cur.result().update() != Update::FitCursor)
2461 // cur.noScreenUpdate();
2463 // But some LFUNs do not set Update::FitCursor when needed, so we
2464 // do it for all. This is not very harmfull as FitCursor will provoke
2465 // a full redraw only if needed but still, a proper review of all LFUN
2466 // should be done and this needsUpdate boolean can then be removed.
2467 cur.screenUpdateFlags(Update::FitCursor);
2469 cur.screenUpdateFlags(Update::Force | Update::FitCursor);
2473 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
2474 FuncStatus & flag) const
2476 LBUFERR(this == cur.text());
2478 FontInfo const & fontinfo = cur.real_current_font.fontInfo();
2480 bool allow_in_passthru = false;
2481 InsetCode code = NO_CODE;
2483 switch (cmd.action()) {
2485 case LFUN_DEPTH_DECREMENT:
2486 enable = changeDepthAllowed(cur, DEC_DEPTH);
2489 case LFUN_DEPTH_INCREMENT:
2490 enable = changeDepthAllowed(cur, INC_DEPTH);
2494 // FIXME We really should not allow this to be put, e.g.,
2495 // in a footnote, or in ERT. But it would make sense in a
2496 // branch, so I'm not sure what to do.
2497 flag.setOnOff(cur.paragraph().params().startOfAppendix());
2500 case LFUN_DIALOG_SHOW_NEW_INSET:
2501 if (cmd.argument() == "bibitem")
2502 code = BIBITEM_CODE;
2503 else if (cmd.argument() == "bibtex") {
2505 // not allowed in description items
2506 enable = !inDescriptionItem(cur);
2508 else if (cmd.argument() == "box")
2510 else if (cmd.argument() == "branch")
2512 else if (cmd.argument() == "citation")
2514 else if (cmd.argument() == "ert")
2516 else if (cmd.argument() == "external")
2517 code = EXTERNAL_CODE;
2518 else if (cmd.argument() == "float")
2520 else if (cmd.argument() == "graphics")
2521 code = GRAPHICS_CODE;
2522 else if (cmd.argument() == "href")
2523 code = HYPERLINK_CODE;
2524 else if (cmd.argument() == "include")
2525 code = INCLUDE_CODE;
2526 else if (cmd.argument() == "index")
2528 else if (cmd.argument() == "index_print")
2529 code = INDEX_PRINT_CODE;
2530 else if (cmd.argument() == "listings")
2531 code = LISTINGS_CODE;
2532 else if (cmd.argument() == "mathspace")
2533 code = MATH_HULL_CODE;
2534 else if (cmd.argument() == "nomenclature")
2535 code = NOMENCL_CODE;
2536 else if (cmd.argument() == "nomencl_print")
2537 code = NOMENCL_PRINT_CODE;
2538 else if (cmd.argument() == "label")
2540 else if (cmd.argument() == "line")
2542 else if (cmd.argument() == "note")
2544 else if (cmd.argument() == "phantom")
2545 code = PHANTOM_CODE;
2546 else if (cmd.argument() == "ref")
2548 else if (cmd.argument() == "space")
2550 else if (cmd.argument() == "toc")
2552 else if (cmd.argument() == "vspace")
2554 else if (cmd.argument() == "wrap")
2558 case LFUN_ERT_INSERT:
2561 case LFUN_LISTING_INSERT:
2562 code = LISTINGS_CODE;
2563 // not allowed in description items
2564 enable = !inDescriptionItem(cur);
2566 case LFUN_FOOTNOTE_INSERT:
2569 case LFUN_TABULAR_INSERT:
2570 code = TABULAR_CODE;
2572 case LFUN_MARGINALNOTE_INSERT:
2575 case LFUN_FLOAT_INSERT:
2576 case LFUN_FLOAT_WIDE_INSERT:
2577 // FIXME: If there is a selection, we should check whether there
2578 // are floats in the selection, but this has performance issues, see
2579 // LFUN_CHANGE_ACCEPT/REJECT.
2581 if (inDescriptionItem(cur))
2582 // not allowed in description items
2585 InsetCode const inset_code = cur.inset().lyxCode();
2587 // algorithm floats cannot be put in another float
2588 if (to_utf8(cmd.argument()) == "algorithm") {
2589 enable = inset_code != WRAP_CODE && inset_code != FLOAT_CODE;
2593 // for figures and tables: only allow in another
2594 // float or wrap if it is of the same type and
2595 // not a subfloat already
2596 if(cur.inset().lyxCode() == code) {
2597 InsetFloat const & ins =
2598 static_cast<InsetFloat const &>(cur.inset());
2599 enable = ins.params().type == to_utf8(cmd.argument())
2600 && !ins.params().subfloat;
2601 } else if(cur.inset().lyxCode() == WRAP_CODE) {
2602 InsetWrap const & ins =
2603 static_cast<InsetWrap const &>(cur.inset());
2604 enable = ins.params().type == to_utf8(cmd.argument());
2608 case LFUN_WRAP_INSERT:
2610 // not allowed in description items
2611 enable = !inDescriptionItem(cur);
2613 case LFUN_FLOAT_LIST_INSERT: {
2614 code = FLOAT_LIST_CODE;
2615 // not allowed in description items
2616 enable = !inDescriptionItem(cur);
2618 FloatList const & floats = cur.buffer()->params().documentClass().floats();
2619 FloatList::const_iterator cit = floats[to_ascii(cmd.argument())];
2620 // make sure we know about such floats
2621 if (cit == floats.end() ||
2622 // and that we know how to generate a list of them
2623 (!cit->second.usesFloatPkg() && cit->second.listCommand().empty())) {
2624 flag.setUnknown(true);
2625 // probably not necessary, but...
2631 case LFUN_CAPTION_INSERT: {
2632 code = CAPTION_CODE;
2633 string arg = cmd.getArg(0);
2634 bool varia = arg != "LongTableNoNumber";
2635 if (cur.depth() > 0) {
2636 if (&cur[cur.depth() - 1].inset())
2637 varia = cur[cur.depth() - 1].inset().allowsCaptionVariation(arg);
2639 // not allowed in description items,
2640 // and in specific insets
2641 enable = !inDescriptionItem(cur)
2642 && (varia || arg.empty() || arg == "Standard");
2645 case LFUN_NOTE_INSERT:
2647 // in commands (sections etc.) and description items,
2648 // only Notes are allowed
2649 enable = (cmd.argument().empty() || cmd.getArg(0) == "Note" ||
2650 (!cur.paragraph().layout().isCommand()
2651 && !inDescriptionItem(cur)));
2653 case LFUN_FLEX_INSERT: {
2655 string s = cmd.getArg(0);
2657 cur.buffer()->params().documentClass().insetLayout(from_utf8(s));
2658 if (il.lyxtype() != InsetLayout::CHARSTYLE &&
2659 il.lyxtype() != InsetLayout::CUSTOM &&
2660 il.lyxtype() != InsetLayout::ELEMENT &&
2661 il.lyxtype ()!= InsetLayout::STANDARD)
2665 case LFUN_BOX_INSERT:
2668 case LFUN_BRANCH_INSERT:
2670 if (cur.buffer()->masterBuffer()->params().branchlist().empty()
2671 && cur.buffer()->params().branchlist().empty())
2674 case LFUN_IPA_INSERT:
2677 case LFUN_PHANTOM_INSERT:
2678 code = PHANTOM_CODE;
2680 case LFUN_LABEL_INSERT:
2683 case LFUN_INFO_INSERT:
2686 case LFUN_ARGUMENT_INSERT: {
2688 allow_in_passthru = true;
2689 string const arg = cmd.getArg(0);
2694 Layout const & lay = cur.paragraph().layout();
2695 Layout::LaTeXArgMap args = lay.args();
2696 Layout::LaTeXArgMap::const_iterator const lait =
2698 if (lait != args.end()) {
2700 pit_type pit = cur.pit();
2701 pit_type lastpit = cur.pit();
2702 if (lay.isEnvironment() && !prefixIs(arg, "item:")) {
2703 // In a sequence of "merged" environment layouts, we only allow
2704 // non-item arguments once.
2705 lastpit = cur.lastpit();
2706 // get the first paragraph in sequence with this layout
2707 depth_type const current_depth = cur.paragraph().params().depth();
2711 Paragraph cpar = pars_[pit - 1];
2712 if (cpar.layout() == lay && cpar.params().depth() == current_depth)
2718 for (; pit <= lastpit; ++pit) {
2719 if (pars_[pit].layout() != lay)
2721 InsetList::const_iterator it = pars_[pit].insetList().begin();
2722 InsetList::const_iterator end = pars_[pit].insetList().end();
2723 for (; it != end; ++it) {
2724 if (it->inset->lyxCode() == ARG_CODE) {
2725 InsetArgument const * ins =
2726 static_cast<InsetArgument const *>(it->inset);
2727 if (ins->name() == arg) {
2728 // we have this already
2739 case LFUN_INDEX_INSERT:
2742 case LFUN_INDEX_PRINT:
2743 code = INDEX_PRINT_CODE;
2744 // not allowed in description items
2745 enable = !inDescriptionItem(cur);
2747 case LFUN_NOMENCL_INSERT:
2748 if (cur.selIsMultiCell() || cur.selIsMultiLine()) {
2752 code = NOMENCL_CODE;
2754 case LFUN_NOMENCL_PRINT:
2755 code = NOMENCL_PRINT_CODE;
2756 // not allowed in description items
2757 enable = !inDescriptionItem(cur);
2759 case LFUN_HREF_INSERT:
2760 if (cur.selIsMultiCell() || cur.selIsMultiLine()) {
2764 code = HYPERLINK_CODE;
2766 case LFUN_IPAMACRO_INSERT: {
2767 string const arg = cmd.getArg(0);
2769 code = IPADECO_CODE;
2771 code = IPACHAR_CODE;
2774 case LFUN_QUOTE_INSERT:
2775 // always allow this, since we will inset a raw quote
2776 // if an inset is not allowed.
2778 case LFUN_SPECIALCHAR_INSERT:
2779 code = SPECIALCHAR_CODE;
2781 case LFUN_SPACE_INSERT:
2782 // slight hack: we know this is allowed in math mode
2786 case LFUN_PREVIEW_INSERT:
2787 code = PREVIEW_CODE;
2789 case LFUN_SCRIPT_INSERT:
2793 case LFUN_MATH_INSERT:
2794 case LFUN_MATH_AMS_MATRIX:
2795 case LFUN_MATH_MATRIX:
2796 case LFUN_MATH_DELIM:
2797 case LFUN_MATH_BIGDELIM:
2798 case LFUN_MATH_DISPLAY:
2799 case LFUN_MATH_MODE:
2800 case LFUN_MATH_MACRO:
2801 case LFUN_MATH_SUBSCRIPT:
2802 case LFUN_MATH_SUPERSCRIPT:
2803 code = MATH_HULL_CODE;
2806 case LFUN_REGEXP_MODE:
2807 code = MATH_HULL_CODE;
2808 enable = cur.buffer()->isInternal() && !cur.inRegexped();
2811 case LFUN_INSET_MODIFY:
2812 // We need to disable this, because we may get called for a
2814 // InsetTabular::getStatus() -> InsetText::getStatus()
2815 // and we don't handle LFUN_INSET_MODIFY.
2819 case LFUN_FONT_EMPH:
2820 flag.setOnOff(fontinfo.emph() == FONT_ON);
2821 enable = !cur.paragraph().isPassThru();
2824 case LFUN_FONT_ITAL:
2825 flag.setOnOff(fontinfo.shape() == ITALIC_SHAPE);
2826 enable = !cur.paragraph().isPassThru();
2829 case LFUN_FONT_NOUN:
2830 flag.setOnOff(fontinfo.noun() == FONT_ON);
2831 enable = !cur.paragraph().isPassThru();
2834 case LFUN_FONT_BOLD:
2835 case LFUN_FONT_BOLDSYMBOL:
2836 flag.setOnOff(fontinfo.series() == BOLD_SERIES);
2837 enable = !cur.paragraph().isPassThru();
2840 case LFUN_FONT_SANS:
2841 flag.setOnOff(fontinfo.family() == SANS_FAMILY);
2842 enable = !cur.paragraph().isPassThru();
2845 case LFUN_FONT_ROMAN:
2846 flag.setOnOff(fontinfo.family() == ROMAN_FAMILY);
2847 enable = !cur.paragraph().isPassThru();
2850 case LFUN_FONT_TYPEWRITER:
2851 flag.setOnOff(fontinfo.family() == TYPEWRITER_FAMILY);
2852 enable = !cur.paragraph().isPassThru();
2857 enable = cur.selection();
2861 if (cmd.argument().empty()) {
2862 if (theClipboard().isInternal())
2863 enable = cap::numberOfSelections() > 0;
2865 enable = !theClipboard().empty();
2869 // we have an argument
2870 string const arg = to_utf8(cmd.argument());
2871 if (isStrUnsignedInt(arg)) {
2872 // it's a number and therefore means the internal stack
2873 unsigned int n = convert<unsigned int>(arg);
2874 enable = cap::numberOfSelections() > n;
2878 // explicit text type?
2879 if (arg == "html") {
2880 // Do not enable for PlainTextType, since some tidying in the
2881 // frontend is needed for HTML, which is too unsafe for plain text.
2882 enable = theClipboard().hasTextContents(Clipboard::HtmlTextType);
2884 } else if (arg == "latex") {
2885 // LaTeX is usually not available on the clipboard with
2886 // the correct MIME type, but in plain text.
2887 enable = theClipboard().hasTextContents(Clipboard::PlainTextType) ||
2888 theClipboard().hasTextContents(Clipboard::LaTeXTextType);
2892 // explicit graphics type?
2893 Clipboard::GraphicsType type = Clipboard::AnyGraphicsType;
2894 if ((arg == "pdf" && (type = Clipboard::PdfGraphicsType))
2895 || (arg == "png" && (type = Clipboard::PngGraphicsType))
2896 || (arg == "jpeg" && (type = Clipboard::JpegGraphicsType))
2897 || (arg == "linkback" && (type = Clipboard::LinkBackGraphicsType))
2898 || (arg == "emf" && (type = Clipboard::EmfGraphicsType))
2899 || (arg == "wmf" && (type = Clipboard::WmfGraphicsType))) {
2900 enable = theClipboard().hasGraphicsContents(type);
2909 case LFUN_CLIPBOARD_PASTE:
2910 case LFUN_CLIPBOARD_PASTE_SIMPLE:
2911 enable = !theClipboard().empty();
2914 case LFUN_PRIMARY_SELECTION_PASTE:
2915 enable = cur.selection() || !theSelection().empty();
2918 case LFUN_SELECTION_PASTE:
2919 enable = cap::selection();
2922 case LFUN_PARAGRAPH_MOVE_UP:
2923 enable = cur.pit() > 0 && !cur.selection();
2926 case LFUN_PARAGRAPH_MOVE_DOWN:
2927 enable = cur.pit() < cur.lastpit() && !cur.selection();
2930 case LFUN_CHANGE_ACCEPT:
2931 case LFUN_CHANGE_REJECT:
2932 // In principle, these LFUNs should only be enabled if there
2933 // is a change at the current position/in the current selection.
2934 // However, without proper optimizations, this will inevitably
2935 // result in unacceptable performance - just imagine a user who
2936 // wants to select the complete content of a long document.
2937 if (!cur.selection())
2938 enable = cur.paragraph().isChanged(cur.pos());
2940 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
2945 case LFUN_OUTLINE_UP:
2946 case LFUN_OUTLINE_DOWN:
2947 case LFUN_OUTLINE_IN:
2948 case LFUN_OUTLINE_OUT:
2949 // FIXME: LyX is not ready for outlining within inset.
2950 enable = isMainText()
2951 && cur.buffer()->text().getTocLevel(cur.pit()) != Layout::NOT_IN_TOC;
2954 case LFUN_NEWLINE_INSERT:
2955 // LaTeX restrictions (labels or empty par)
2956 enable = !cur.paragraph().isPassThru()
2957 && cur.pos() > cur.paragraph().beginOfBody();
2960 case LFUN_SEPARATOR_INSERT:
2961 // Always enabled for now
2965 case LFUN_TAB_INSERT:
2966 case LFUN_TAB_DELETE:
2967 enable = cur.paragraph().isPassThru();
2970 case LFUN_SET_GRAPHICS_GROUP: {
2971 InsetGraphics * ins = graphics::getCurrentGraphicsInset(cur);
2975 flag.setOnOff(to_utf8(cmd.argument()) == ins->getParams().groupId);
2979 case LFUN_NEWPAGE_INSERT:
2980 // not allowed in description items
2981 code = NEWPAGE_CODE;
2982 enable = !inDescriptionItem(cur);
2985 case LFUN_DATE_INSERT: {
2986 string const format = cmd.argument().empty()
2987 ? lyxrc.date_insert_format : to_utf8(cmd.argument());
2988 enable = support::os::is_valid_strftime(format);
2993 enable = !cur.paragraph().isPassThru();
2994 flag.setOnOff(cmd.getArg(0) == cur.real_current_font.language()->lang());
2997 case LFUN_PARAGRAPH_BREAK:
2998 enable = cur.inset().getLayout().isMultiPar();
3001 case LFUN_SPELLING_ADD:
3002 case LFUN_SPELLING_IGNORE:
3003 case LFUN_SPELLING_REMOVE:
3004 enable = theSpellChecker();
3008 enable = !cur.inset().forcePlainLayout();
3011 case LFUN_ENVIRONMENT_SPLIT: {
3012 if (cmd.argument() == "outer") {
3013 // check if we have an environment in our nesting hierarchy
3015 depth_type const current_depth = cur.paragraph().params().depth();
3016 pit_type pit = cur.pit();
3017 Paragraph cpar = pars_[pit];
3019 if (pit == 0 || cpar.params().depth() == 0)
3023 if (cpar.params().depth() < current_depth)
3024 res = cpar.layout().isEnvironment();
3029 else if (cur.paragraph().layout().isEnvironment()) {
3037 case LFUN_LAYOUT_PARAGRAPH:
3038 case LFUN_PARAGRAPH_PARAMS:
3039 case LFUN_PARAGRAPH_PARAMS_APPLY:
3040 case LFUN_PARAGRAPH_UPDATE:
3041 enable = cur.inset().allowParagraphCustomization();
3044 // FIXME: why are accent lfuns forbidden with pass_thru layouts?
3045 case LFUN_ACCENT_ACUTE:
3046 case LFUN_ACCENT_BREVE:
3047 case LFUN_ACCENT_CARON:
3048 case LFUN_ACCENT_CEDILLA:
3049 case LFUN_ACCENT_CIRCLE:
3050 case LFUN_ACCENT_CIRCUMFLEX:
3051 case LFUN_ACCENT_DOT:
3052 case LFUN_ACCENT_GRAVE:
3053 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
3054 case LFUN_ACCENT_MACRON:
3055 case LFUN_ACCENT_OGONEK:
3056 case LFUN_ACCENT_TIE:
3057 case LFUN_ACCENT_TILDE:
3058 case LFUN_ACCENT_UMLAUT:
3059 case LFUN_ACCENT_UNDERBAR:
3060 case LFUN_ACCENT_UNDERDOT:
3061 case LFUN_FONT_DEFAULT:
3062 case LFUN_FONT_FRAK:
3063 case LFUN_FONT_SIZE:
3064 case LFUN_FONT_STATE:
3065 case LFUN_FONT_UNDERLINE:
3066 case LFUN_FONT_STRIKEOUT:
3067 case LFUN_FONT_UNDERUNDERLINE:
3068 case LFUN_FONT_UNDERWAVE:
3069 case LFUN_TEXTSTYLE_APPLY:
3070 case LFUN_TEXTSTYLE_UPDATE:
3071 enable = !cur.paragraph().isPassThru();
3074 case LFUN_WORD_DELETE_FORWARD:
3075 case LFUN_WORD_DELETE_BACKWARD:
3076 case LFUN_LINE_DELETE_FORWARD:
3077 case LFUN_WORD_FORWARD:
3078 case LFUN_WORD_BACKWARD:
3079 case LFUN_WORD_RIGHT:
3080 case LFUN_WORD_LEFT:
3081 case LFUN_CHAR_FORWARD:
3082 case LFUN_CHAR_FORWARD_SELECT:
3083 case LFUN_CHAR_BACKWARD:
3084 case LFUN_CHAR_BACKWARD_SELECT:
3085 case LFUN_CHAR_LEFT:
3086 case LFUN_CHAR_LEFT_SELECT:
3087 case LFUN_CHAR_RIGHT:
3088 case LFUN_CHAR_RIGHT_SELECT:
3090 case LFUN_UP_SELECT:
3092 case LFUN_DOWN_SELECT:
3093 case LFUN_PARAGRAPH_UP_SELECT:
3094 case LFUN_PARAGRAPH_DOWN_SELECT:
3095 case LFUN_LINE_BEGIN_SELECT:
3096 case LFUN_LINE_END_SELECT:
3097 case LFUN_WORD_FORWARD_SELECT:
3098 case LFUN_WORD_BACKWARD_SELECT:
3099 case LFUN_WORD_RIGHT_SELECT:
3100 case LFUN_WORD_LEFT_SELECT:
3101 case LFUN_WORD_SELECT:
3102 case LFUN_SECTION_SELECT:
3103 case LFUN_BUFFER_BEGIN:
3104 case LFUN_BUFFER_END:
3105 case LFUN_BUFFER_BEGIN_SELECT:
3106 case LFUN_BUFFER_END_SELECT:
3107 case LFUN_INSET_BEGIN:
3108 case LFUN_INSET_END:
3109 case LFUN_INSET_BEGIN_SELECT:
3110 case LFUN_INSET_END_SELECT:
3111 case LFUN_INSET_SELECT_ALL:
3112 case LFUN_PARAGRAPH_UP:
3113 case LFUN_PARAGRAPH_DOWN:
3114 case LFUN_LINE_BEGIN:
3116 case LFUN_CHAR_DELETE_FORWARD:
3117 case LFUN_CHAR_DELETE_BACKWARD:
3118 case LFUN_WORD_UPCASE:
3119 case LFUN_WORD_LOWCASE:
3120 case LFUN_WORD_CAPITALIZE:
3121 case LFUN_CHARS_TRANSPOSE:
3122 case LFUN_SERVER_GET_XY:
3123 case LFUN_SERVER_SET_XY:
3124 case LFUN_SERVER_GET_LAYOUT:
3125 case LFUN_SELF_INSERT:
3126 case LFUN_UNICODE_INSERT:
3127 case LFUN_THESAURUS_ENTRY:
3129 // these are handled in our dispatch()
3133 case LFUN_INSET_INSERT: {
3134 string const type = cmd.getArg(0);
3135 if (type == "toc") {
3137 // not allowed in description items
3138 //FIXME: couldn't this be merged in Inset::insetAllowed()?
3139 enable = !inDescriptionItem(cur);
3152 || !cur.inset().insetAllowed(code)
3153 || (cur.paragraph().layout().pass_thru && !allow_in_passthru)))
3156 flag.setEnabled(enable);
3161 void Text::pasteString(Cursor & cur, docstring const & clip,
3164 if (!clip.empty()) {
3167 insertStringAsParagraphs(cur, clip, cur.current_font);
3169 insertStringAsLines(cur, clip, cur.current_font);
3174 // FIXME: an item inset would make things much easier.
3175 bool Text::inDescriptionItem(Cursor & cur) const
3177 Paragraph & par = cur.paragraph();
3178 pos_type const pos = cur.pos();
3179 pos_type const body_pos = par.beginOfBody();
3181 if (par.layout().latextype != LATEX_LIST_ENVIRONMENT
3182 && (par.layout().latextype != LATEX_ITEM_ENVIRONMENT
3183 || par.layout().margintype != MARGIN_FIRST_DYNAMIC))
3186 return (pos < body_pos
3188 && (pos == 0 || par.getChar(pos - 1) != ' ')));