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;
414 pit_type const len = distance(start, finish);
415 buf.undo().recordUndo(cur, ATOMIC_UNDO, pit, pit + len - 1);
416 for (; start != finish; ++start) {
417 toclevel = buf.text().getTocLevel(distance(bgn, start));
418 if (toclevel == Layout::NOT_IN_TOC)
420 DocumentClass::const_iterator lit = tc.begin();
421 DocumentClass::const_iterator len = tc.end();
422 for (; lit != len; ++lit) {
423 if (lit->toclevel == (mode == OutlineIn ?
424 toclevel + 1 : toclevel - 1) &&
425 start->layout().labeltype == lit->labeltype) {
426 start->setLayout(*lit);
437 void Text::number(Cursor & cur)
439 FontInfo font = ignore_font;
440 font.setNumber(FONT_TOGGLE);
441 toggleAndShow(cur, this, Font(font, ignore_language));
445 bool Text::isRTL(Paragraph const & par) const
447 Buffer const & buffer = owner_->buffer();
448 return par.isRTL(buffer.params());
452 void Text::dispatch(Cursor & cur, FuncRequest & cmd)
454 LYXERR(Debug::ACTION, "Text::dispatch: cmd: " << cmd);
456 // Dispatch if the cursor is inside the text. It is not the
457 // case for context menus (bug 5797).
458 if (cur.text() != this) {
463 BufferView * bv = &cur.bv();
464 TextMetrics * tm = &bv->textMetrics(this);
465 if (!tm->contains(cur.pit())) {
466 lyx::dispatch(FuncRequest(LFUN_SCREEN_SHOW_CURSOR));
467 tm = &bv->textMetrics(this);
470 // FIXME: We use the update flag to indicates wether a singlePar or a
471 // full screen update is needed. We reset it here but shall we restore it
473 cur.noScreenUpdate();
475 LBUFERR(this == cur.text());
476 CursorSlice const oldTopSlice = cur.top();
477 bool const oldBoundary = cur.boundary();
478 bool const oldSelection = cur.selection();
479 // Signals that, even if needsUpdate == false, an update of the
480 // cursor paragraph is required
481 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action(),
482 LyXAction::SingleParUpdate);
483 // Signals that a full-screen update is required
484 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action(),
485 LyXAction::NoUpdate) || singleParUpdate);
486 bool const last_misspelled = lyxrc.spellcheck_continuously
487 && cur.paragraph().isMisspelled(cur.pos(), true);
489 FuncCode const act = cmd.action();
492 case LFUN_PARAGRAPH_MOVE_DOWN: {
493 pit_type const pit = cur.pit();
494 recUndo(cur, pit, pit + 1);
496 pars_.swap(pit, pit + 1);
498 cur.forceBufferUpdate();
503 case LFUN_PARAGRAPH_MOVE_UP: {
504 pit_type const pit = cur.pit();
505 recUndo(cur, pit - 1, pit);
507 pars_.swap(pit, pit - 1);
510 cur.forceBufferUpdate();
514 case LFUN_APPENDIX: {
515 Paragraph & par = cur.paragraph();
516 bool start = !par.params().startOfAppendix();
518 // FIXME: The code below only makes sense at top level.
519 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
520 // ensure that we have only one start_of_appendix in this document
521 // FIXME: this don't work for multipart document!
522 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
523 if (pars_[tmp].params().startOfAppendix()) {
525 pars_[tmp].params().startOfAppendix(false);
531 par.params().startOfAppendix(start);
533 // we can set the refreshing parameters now
534 cur.forceBufferUpdate();
538 case LFUN_WORD_DELETE_FORWARD:
540 cutSelection(cur, true, false);
542 deleteWordForward(cur);
543 finishChange(cur, false);
546 case LFUN_WORD_DELETE_BACKWARD:
548 cutSelection(cur, true, false);
550 deleteWordBackward(cur);
551 finishChange(cur, false);
554 case LFUN_LINE_DELETE_FORWARD:
556 cutSelection(cur, true, false);
558 tm->deleteLineForward(cur);
559 finishChange(cur, false);
562 case LFUN_BUFFER_BEGIN:
563 case LFUN_BUFFER_BEGIN_SELECT:
564 needsUpdate |= cur.selHandle(act == LFUN_BUFFER_BEGIN_SELECT);
565 if (cur.depth() == 1)
566 needsUpdate |= cursorTop(cur);
569 cur.screenUpdateFlags(Update::FitCursor);
572 case LFUN_BUFFER_END:
573 case LFUN_BUFFER_END_SELECT:
574 needsUpdate |= cur.selHandle(act == LFUN_BUFFER_END_SELECT);
575 if (cur.depth() == 1)
576 needsUpdate |= cursorBottom(cur);
579 cur.screenUpdateFlags(Update::FitCursor);
582 case LFUN_INSET_BEGIN:
583 case LFUN_INSET_BEGIN_SELECT:
584 needsUpdate |= cur.selHandle(act == LFUN_INSET_BEGIN_SELECT);
585 if (cur.depth() == 1 || !cur.top().at_begin())
586 needsUpdate |= cursorTop(cur);
589 cur.screenUpdateFlags(Update::FitCursor);
593 case LFUN_INSET_END_SELECT:
594 needsUpdate |= cur.selHandle(act == LFUN_INSET_END_SELECT);
595 if (cur.depth() == 1 || !cur.top().at_end())
596 needsUpdate |= cursorBottom(cur);
599 cur.screenUpdateFlags(Update::FitCursor);
602 case LFUN_CHAR_FORWARD:
603 case LFUN_CHAR_FORWARD_SELECT:
604 //LYXERR0(" LFUN_CHAR_FORWARD[SEL]:\n" << cur);
605 needsUpdate |= cur.selHandle(act == LFUN_CHAR_FORWARD_SELECT);
606 needsUpdate |= cursorForward(cur);
608 if (!needsUpdate && oldTopSlice == cur.top()
609 && cur.boundary() == oldBoundary) {
611 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
613 // we will probably be moving out the inset, so we should execute
614 // the depm-mechanism, but only when the cursor has a place to
615 // go outside this inset, i.e. in a slice above.
616 if (cur.depth() > 1 && cur.pos() == cur.lastpos()
617 && cur.pit() == cur.lastpit()) {
618 // The cursor hasn't changed yet. To give the
619 // DEPM the possibility of doing something we must
620 // provide it with two different cursors.
622 dummy.pos() = dummy.pit() = 0;
623 if (cur.bv().checkDepm(dummy, cur))
624 cur.forceBufferUpdate();
629 case LFUN_CHAR_BACKWARD:
630 case LFUN_CHAR_BACKWARD_SELECT:
631 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
632 needsUpdate |= cur.selHandle(act == LFUN_CHAR_BACKWARD_SELECT);
633 needsUpdate |= cursorBackward(cur);
635 if (!needsUpdate && oldTopSlice == cur.top()
636 && cur.boundary() == oldBoundary) {
638 cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
640 // we will probably be moving out the inset, so we should execute
641 // the depm-mechanism, but only when the cursor has a place to
642 // go outside this inset, i.e. in a slice above.
643 if (cur.depth() > 1 && cur.pos() == 0 && cur.pit() == 0) {
644 // The cursor hasn't changed yet. To give the
645 // DEPM the possibility of doing something we must
646 // provide it with two different cursors.
648 dummy.pos() = cur.lastpos();
649 dummy.pit() = cur.lastpit();
650 if (cur.bv().checkDepm(dummy, cur))
651 cur.forceBufferUpdate();
657 case LFUN_CHAR_LEFT_SELECT:
658 if (lyxrc.visual_cursor) {
659 needsUpdate |= cur.selHandle(act == LFUN_CHAR_LEFT_SELECT);
660 needsUpdate |= cursorVisLeft(cur);
661 if (!needsUpdate && oldTopSlice == cur.top()
662 && cur.boundary() == oldBoundary) {
664 cmd = FuncRequest(LFUN_FINISHED_LEFT);
667 if (reverseDirectionNeeded(cur)) {
668 cmd.setAction(cmd.action() == LFUN_CHAR_LEFT_SELECT ?
669 LFUN_CHAR_FORWARD_SELECT : LFUN_CHAR_FORWARD);
671 cmd.setAction(cmd.action() == LFUN_CHAR_LEFT_SELECT ?
672 LFUN_CHAR_BACKWARD_SELECT : LFUN_CHAR_BACKWARD);
679 case LFUN_CHAR_RIGHT:
680 case LFUN_CHAR_RIGHT_SELECT:
681 if (lyxrc.visual_cursor) {
682 needsUpdate |= cur.selHandle(cmd.action() == LFUN_CHAR_RIGHT_SELECT);
683 needsUpdate |= cursorVisRight(cur);
684 if (!needsUpdate && oldTopSlice == cur.top()
685 && cur.boundary() == oldBoundary) {
687 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
690 if (reverseDirectionNeeded(cur)) {
691 cmd.setAction(cmd.action() == LFUN_CHAR_RIGHT_SELECT ?
692 LFUN_CHAR_BACKWARD_SELECT : LFUN_CHAR_BACKWARD);
694 cmd.setAction(cmd.action() == LFUN_CHAR_RIGHT_SELECT ?
695 LFUN_CHAR_FORWARD_SELECT : LFUN_CHAR_FORWARD);
704 case LFUN_DOWN_SELECT:
707 // stop/start the selection
708 bool select = cmd.action() == LFUN_DOWN_SELECT ||
709 cmd.action() == LFUN_UP_SELECT;
711 // move cursor up/down
712 bool up = cmd.action() == LFUN_UP_SELECT || cmd.action() == LFUN_UP;
713 bool const atFirstOrLastRow = cur.atFirstOrLastRow(up);
715 if (!atFirstOrLastRow) {
716 needsUpdate |= cur.selHandle(select);
717 cur.upDownInText(up, needsUpdate);
718 needsUpdate |= cur.beforeDispatchCursor().inMathed();
720 // if the cursor cannot be moved up or down do not remove
721 // the selection right now, but wait for the next dispatch.
723 needsUpdate |= cur.selHandle(select);
724 cur.upDownInText(up, needsUpdate);
731 case LFUN_PARAGRAPH_UP:
732 case LFUN_PARAGRAPH_UP_SELECT:
733 needsUpdate |= cur.selHandle(cmd.action() == LFUN_PARAGRAPH_UP_SELECT);
734 needsUpdate |= cursorUpParagraph(cur);
737 case LFUN_PARAGRAPH_DOWN:
738 case LFUN_PARAGRAPH_DOWN_SELECT:
739 needsUpdate |= cur.selHandle(cmd.action() == LFUN_PARAGRAPH_DOWN_SELECT);
740 needsUpdate |= cursorDownParagraph(cur);
743 case LFUN_LINE_BEGIN:
744 case LFUN_LINE_BEGIN_SELECT:
745 needsUpdate |= cur.selHandle(cmd.action() == LFUN_LINE_BEGIN_SELECT);
746 needsUpdate |= tm->cursorHome(cur);
750 case LFUN_LINE_END_SELECT:
751 needsUpdate |= cur.selHandle(cmd.action() == LFUN_LINE_END_SELECT);
752 needsUpdate |= tm->cursorEnd(cur);
755 case LFUN_SECTION_SELECT: {
756 Buffer const & buf = *cur.buffer();
757 pit_type const pit = cur.pit();
758 ParagraphList & pars = buf.text().paragraphs();
759 ParagraphList::iterator bgn = pars.begin();
760 // The first paragraph of the area to be selected:
761 ParagraphList::iterator start = boost::next(bgn, pit);
762 // The final paragraph of area to be selected:
763 ParagraphList::iterator finish = start;
764 ParagraphList::iterator end = pars.end();
766 int const thistoclevel = buf.text().getTocLevel(distance(bgn, start));
767 if (thistoclevel == Layout::NOT_IN_TOC)
771 Cursor const old_cur = cur;
772 needsUpdate |= cur.selHandle(true);
774 // Move out (down) from this section header
778 // Seek the one (on same level) below
779 for (; finish != end; ++finish, ++cur.pit()) {
780 int const toclevel = buf.text().getTocLevel(distance(bgn, finish));
781 if (toclevel != Layout::NOT_IN_TOC && toclevel <= thistoclevel)
784 cur.pos() = cur.lastpos();
786 needsUpdate |= cur != old_cur;
790 case LFUN_WORD_RIGHT:
791 case LFUN_WORD_RIGHT_SELECT:
792 if (lyxrc.visual_cursor) {
793 needsUpdate |= cur.selHandle(cmd.action() == LFUN_WORD_RIGHT_SELECT);
794 needsUpdate |= cursorVisRightOneWord(cur);
795 if (!needsUpdate && oldTopSlice == cur.top()
796 && cur.boundary() == oldBoundary) {
798 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
801 if (reverseDirectionNeeded(cur)) {
802 cmd.setAction(cmd.action() == LFUN_WORD_RIGHT_SELECT ?
803 LFUN_WORD_BACKWARD_SELECT : LFUN_WORD_BACKWARD);
805 cmd.setAction(cmd.action() == LFUN_WORD_RIGHT_SELECT ?
806 LFUN_WORD_FORWARD_SELECT : LFUN_WORD_FORWARD);
813 case LFUN_WORD_FORWARD:
814 case LFUN_WORD_FORWARD_SELECT:
815 needsUpdate |= cur.selHandle(cmd.action() == LFUN_WORD_FORWARD_SELECT);
816 needsUpdate |= cursorForwardOneWord(cur);
818 if (!needsUpdate && oldTopSlice == cur.top()
819 && cur.boundary() == oldBoundary) {
821 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
823 // we will probably be moving out the inset, so we should execute
824 // the depm-mechanism, but only when the cursor has a place to
825 // go outside this inset, i.e. in a slice above.
826 if (cur.depth() > 1 && cur.pos() == cur.lastpos()
827 && cur.pit() == cur.lastpit()) {
828 // The cursor hasn't changed yet. To give the
829 // DEPM the possibility of doing something we must
830 // provide it with two different cursors.
832 dummy.pos() = dummy.pit() = 0;
833 if (cur.bv().checkDepm(dummy, cur))
834 cur.forceBufferUpdate();
840 case LFUN_WORD_LEFT_SELECT:
841 if (lyxrc.visual_cursor) {
842 needsUpdate |= cur.selHandle(cmd.action() == LFUN_WORD_LEFT_SELECT);
843 needsUpdate |= cursorVisLeftOneWord(cur);
844 if (!needsUpdate && oldTopSlice == cur.top()
845 && cur.boundary() == oldBoundary) {
847 cmd = FuncRequest(LFUN_FINISHED_LEFT);
850 if (reverseDirectionNeeded(cur)) {
851 cmd.setAction(cmd.action() == LFUN_WORD_LEFT_SELECT ?
852 LFUN_WORD_FORWARD_SELECT : LFUN_WORD_FORWARD);
854 cmd.setAction(cmd.action() == LFUN_WORD_LEFT_SELECT ?
855 LFUN_WORD_BACKWARD_SELECT : LFUN_WORD_BACKWARD);
862 case LFUN_WORD_BACKWARD:
863 case LFUN_WORD_BACKWARD_SELECT:
864 needsUpdate |= cur.selHandle(cmd.action() == LFUN_WORD_BACKWARD_SELECT);
865 needsUpdate |= cursorBackwardOneWord(cur);
867 if (!needsUpdate && oldTopSlice == cur.top()
868 && cur.boundary() == oldBoundary) {
870 cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
872 // we will probably be moving out the inset, so we should execute
873 // the depm-mechanism, but only when the cursor has a place to
874 // go outside this inset, i.e. in a slice above.
875 if (cur.depth() > 1 && cur.pos() == 0
877 // The cursor hasn't changed yet. To give the
878 // DEPM the possibility of doing something we must
879 // provide it with two different cursors.
881 dummy.pos() = cur.lastpos();
882 dummy.pit() = cur.lastpit();
883 if (cur.bv().checkDepm(dummy, cur))
884 cur.forceBufferUpdate();
889 case LFUN_WORD_SELECT: {
890 selectWord(cur, WHOLE_WORD);
891 finishChange(cur, true);
895 case LFUN_NEWLINE_INSERT: {
896 InsetNewlineParams inp;
897 docstring arg = cmd.argument();
898 if (arg == "linebreak")
899 inp.kind = InsetNewlineParams::LINEBREAK;
901 inp.kind = InsetNewlineParams::NEWLINE;
902 cap::replaceSelection(cur);
904 cur.insert(new InsetNewline(inp));
906 moveCursor(cur, false);
910 case LFUN_TAB_INSERT: {
911 bool const multi_par_selection = cur.selection() &&
912 cur.selBegin().pit() != cur.selEnd().pit();
913 if (multi_par_selection) {
914 // If there is a multi-paragraph selection, a tab is inserted
915 // at the beginning of each paragraph.
916 cur.recordUndoSelection();
917 pit_type const pit_end = cur.selEnd().pit();
918 for (pit_type pit = cur.selBegin().pit(); pit <= pit_end; pit++) {
919 pars_[pit].insertChar(0, '\t',
920 bv->buffer().params().track_changes);
921 // Update the selection pos to make sure the selection does not
922 // change as the inserted tab will increase the logical pos.
923 if (cur.realAnchor().pit() == pit)
924 cur.realAnchor().forwardPos();
925 if (cur.pit() == pit)
930 // Maybe we shouldn't allow tabs within a line, because they
931 // are not (yet) aligned as one might do expect.
932 FuncRequest cmd(LFUN_SELF_INSERT, from_ascii("\t"));
938 case LFUN_TAB_DELETE: {
939 bool const tc = bv->buffer().params().track_changes;
940 if (cur.selection()) {
941 // If there is a selection, a tab (if present) is removed from
942 // the beginning of each paragraph.
943 cur.recordUndoSelection();
944 pit_type const pit_end = cur.selEnd().pit();
945 for (pit_type pit = cur.selBegin().pit(); pit <= pit_end; pit++) {
946 Paragraph & par = paragraphs()[pit];
949 char_type const c = par.getChar(0);
950 if (c == '\t' || c == ' ') {
951 // remove either 1 tab or 4 spaces.
952 int const n = (c == ' ' ? 4 : 1);
953 for (int i = 0; i < n
954 && !par.empty() && par.getChar(0) == c; ++i) {
955 if (cur.pit() == pit)
957 if (cur.realAnchor().pit() == pit
958 && cur.realAnchor().pos() > 0 )
959 cur.realAnchor().backwardPos();
960 par.eraseChar(0, tc);
966 // If there is no selection, try to remove a tab or some spaces
967 // before the position of the cursor.
968 Paragraph & par = paragraphs()[cur.pit()];
969 pos_type const pos = cur.pos();
974 char_type const c = par.getChar(pos - 1);
978 par.eraseChar(cur.pos(), tc);
980 for (int n_spaces = 0;
982 && par.getChar(cur.pos() - 1) == ' '
986 par.eraseChar(cur.pos(), tc);
993 case LFUN_CHAR_DELETE_FORWARD:
994 if (!cur.selection()) {
995 bool was_separator = cur.paragraph().isEnvSeparator(cur.pos());
996 if (cur.pos() == cur.paragraph().size())
997 // Par boundary, force full-screen update
998 singleParUpdate = false;
999 needsUpdate |= erase(cur);
1001 if (was_separator && cur.pos() == cur.paragraph().size()
1002 && (!cur.paragraph().layout().isEnvironment()
1003 || cur.paragraph().size() > 0)) {
1004 // Force full-screen update
1005 singleParUpdate = false;
1006 needsUpdate |= erase(cur);
1009 // It is possible to make it a lot faster still
1010 // just comment out the line below...
1012 cutSelection(cur, true, false);
1013 singleParUpdate = false;
1015 moveCursor(cur, false);
1018 case LFUN_CHAR_DELETE_BACKWARD:
1019 if (!cur.selection()) {
1020 if (bv->getIntl().getTransManager().backspace()) {
1021 bool par_boundary = cur.pos() == 0;
1022 // Par boundary, full-screen update
1024 singleParUpdate = false;
1025 needsUpdate |= backspace(cur);
1027 if (par_boundary && cur.pos() > 0
1028 && cur.paragraph().isEnvSeparator(cur.pos() - 1)) {
1029 needsUpdate |= backspace(cur);
1032 // It is possible to make it a lot faster still
1033 // just comment out the line below...
1036 cutSelection(cur, true, false);
1037 singleParUpdate = false;
1041 case LFUN_PARAGRAPH_BREAK: {
1042 cap::replaceSelection(cur);
1043 pit_type pit = cur.pit();
1044 Paragraph const & par = pars_[pit];
1045 pit_type prev = pit;
1047 if (!pars_[pit - 1].layout().isEnvironment())
1048 prev = depthHook(pit, par.getDepth());
1049 else if (pars_[pit - 1].getDepth() >= par.getDepth())
1052 if (prev < pit && cur.pos() == par.beginOfBody()
1053 && !par.isEnvSeparator(cur.pos())
1054 && !par.layout().isCommand()
1055 && pars_[prev].layout() != par.layout()
1056 && pars_[prev].layout().isEnvironment()) {
1057 if (par.layout().isEnvironment()
1058 && pars_[prev].getDepth() == par.getDepth()) {
1059 docstring const layout = par.layout().name();
1060 DocumentClass const & tc = bv->buffer().params().documentClass();
1061 lyx::dispatch(FuncRequest(LFUN_LAYOUT, tc.plainLayout().name()));
1062 lyx::dispatch(FuncRequest(LFUN_SEPARATOR_INSERT, "parbreak"));
1063 lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_BREAK, "inverse"));
1064 lyx::dispatch(FuncRequest(LFUN_LAYOUT, layout));
1066 lyx::dispatch(FuncRequest(LFUN_SEPARATOR_INSERT, "parbreak"));
1067 breakParagraph(cur);
1069 Font const f(inherit_font, cur.current_font.language());
1070 pars_[cur.pit() - 1].resetFonts(f);
1072 breakParagraph(cur, cmd.argument() == "inverse");
1078 case LFUN_INSET_INSERT: {
1081 // We have to avoid triggering InstantPreview loading
1082 // before inserting into the document. See bug #5626.
1083 bool loaded = bv->buffer().isFullyLoaded();
1084 bv->buffer().setFullyLoaded(false);
1085 Inset * inset = createInset(&bv->buffer(), cmd);
1086 bv->buffer().setFullyLoaded(loaded);
1089 // FIXME (Abdel 01/02/2006):
1090 // What follows would be a partial fix for bug 2154:
1091 // http://www.lyx.org/trac/ticket/2154
1092 // This automatically put the label inset _after_ a
1093 // numbered section. It should be possible to extend the mechanism
1094 // to any kind of LateX environement.
1095 // The correct way to fix that bug would be at LateX generation.
1096 // I'll let the code here for reference as it could be used for some
1097 // other feature like "automatic labelling".
1099 Paragraph & par = pars_[cur.pit()];
1100 if (inset->lyxCode() == LABEL_CODE
1101 && !par.layout().counter.empty() {
1102 // Go to the end of the paragraph
1103 // Warning: Because of Change-Tracking, the last
1104 // position is 'size()' and not 'size()-1':
1105 cur.pos() = par.size();
1106 // Insert a new paragraph
1107 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
1111 if (cur.selection())
1112 cutSelection(cur, true, false);
1114 if (inset->editable() && inset->asInsetText())
1115 inset->edit(cur, true);
1119 // trigger InstantPreview now
1120 if (inset->lyxCode() == EXTERNAL_CODE) {
1121 InsetExternal & ins =
1122 static_cast<InsetExternal &>(*inset);
1123 ins.updatePreview();
1130 case LFUN_INSET_DISSOLVE: {
1131 if (dissolveInset(cur)) {
1133 cur.forceBufferUpdate();
1138 case LFUN_SET_GRAPHICS_GROUP: {
1139 InsetGraphics * ins = graphics::getCurrentGraphicsInset(cur);
1145 string id = to_utf8(cmd.argument());
1146 string grp = graphics::getGroupParams(bv->buffer(), id);
1147 InsetGraphicsParams tmp, inspar = ins->getParams();
1150 inspar.groupId = to_utf8(cmd.argument());
1152 InsetGraphics::string2params(grp, bv->buffer(), tmp);
1153 tmp.filename = inspar.filename;
1157 ins->setParams(inspar);
1160 case LFUN_SPACE_INSERT:
1161 if (cur.paragraph().layout().free_spacing)
1162 insertChar(cur, ' ');
1164 doInsertInset(cur, this, cmd, false, false);
1167 moveCursor(cur, false);
1170 case LFUN_SPECIALCHAR_INSERT: {
1171 string const name = to_utf8(cmd.argument());
1172 if (name == "hyphenation")
1173 specialChar(cur, InsetSpecialChar::HYPHENATION);
1174 else if (name == "ligature-break")
1175 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
1176 else if (name == "slash")
1177 specialChar(cur, InsetSpecialChar::SLASH);
1178 else if (name == "nobreakdash")
1179 specialChar(cur, InsetSpecialChar::NOBREAKDASH);
1180 else if (name == "dots")
1181 specialChar(cur, InsetSpecialChar::LDOTS);
1182 else if (name == "end-of-sentence")
1183 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
1184 else if (name == "menu-separator")
1185 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
1186 else if (name.empty())
1187 lyxerr << "LyX function 'specialchar-insert' needs an argument." << endl;
1189 lyxerr << "Wrong argument for LyX function 'specialchar-insert'." << endl;
1193 case LFUN_IPAMACRO_INSERT: {
1194 string const arg = cmd.getArg(0);
1195 if (arg == "deco") {
1196 // Open the inset, and move the current selection
1198 doInsertInset(cur, this, cmd, true, true);
1200 // Some insets are numbered, others are shown in the outline pane so
1201 // let's update the labels and the toc backend.
1202 cur.forceBufferUpdate();
1205 if (arg == "tone-falling")
1206 ipaChar(cur, InsetIPAChar::TONE_FALLING);
1207 else if (arg == "tone-rising")
1208 ipaChar(cur, InsetIPAChar::TONE_RISING);
1209 else if (arg == "tone-high-rising")
1210 ipaChar(cur, InsetIPAChar::TONE_HIGH_RISING);
1211 else if (arg == "tone-low-rising")
1212 ipaChar(cur, InsetIPAChar::TONE_LOW_RISING);
1213 else if (arg == "tone-high-rising-falling")
1214 ipaChar(cur, InsetIPAChar::TONE_HIGH_RISING_FALLING);
1215 else if (arg.empty())
1216 lyxerr << "LyX function 'ipamacro-insert' needs an argument." << endl;
1218 lyxerr << "Wrong argument for LyX function 'ipamacro-insert'." << endl;
1222 case LFUN_WORD_UPCASE:
1223 changeCase(cur, text_uppercase);
1226 case LFUN_WORD_LOWCASE:
1227 changeCase(cur, text_lowercase);
1230 case LFUN_WORD_CAPITALIZE:
1231 changeCase(cur, text_capitalization);
1234 case LFUN_CHARS_TRANSPOSE:
1235 charsTranspose(cur);
1239 cur.message(_("Paste"));
1240 LASSERT(cur.selBegin().idx() == cur.selEnd().idx(), break);
1241 cap::replaceSelection(cur);
1243 // without argument?
1244 string const arg = to_utf8(cmd.argument());
1246 bool tryGraphics = true;
1247 if (theClipboard().isInternal())
1248 pasteFromStack(cur, bv->buffer().errorList("Paste"), 0);
1249 else if (theClipboard().hasTextContents()) {
1250 if (pasteClipboardText(cur, bv->buffer().errorList("Paste"),
1251 true, Clipboard::AnyTextType))
1252 tryGraphics = false;
1254 if (tryGraphics && theClipboard().hasGraphicsContents())
1255 pasteClipboardGraphics(cur, bv->buffer().errorList("Paste"));
1256 } else if (isStrUnsignedInt(arg)) {
1257 // we have a numerical argument
1258 pasteFromStack(cur, bv->buffer().errorList("Paste"),
1259 convert<unsigned int>(arg));
1260 } else if (arg == "html" || arg == "latex") {
1261 Clipboard::TextType type = (arg == "html") ?
1262 Clipboard::HtmlTextType : Clipboard::LaTeXTextType;
1263 pasteClipboardText(cur, bv->buffer().errorList("Paste"), true, type);
1265 Clipboard::GraphicsType type = Clipboard::AnyGraphicsType;
1267 type = Clipboard::PdfGraphicsType;
1268 else if (arg == "png")
1269 type = Clipboard::PngGraphicsType;
1270 else if (arg == "jpeg")
1271 type = Clipboard::JpegGraphicsType;
1272 else if (arg == "linkback")
1273 type = Clipboard::LinkBackGraphicsType;
1274 else if (arg == "emf")
1275 type = Clipboard::EmfGraphicsType;
1276 else if (arg == "wmf")
1277 type = Clipboard::WmfGraphicsType;
1279 // We used to assert, but couldn't the argument come from, say, the
1280 // minibuffer and just be mistyped?
1281 LYXERR0("Unrecognized graphics type: " << arg);
1283 pasteClipboardGraphics(cur, bv->buffer().errorList("Paste"), type);
1286 bv->buffer().errors("Paste");
1287 cur.clearSelection(); // bug 393
1293 cutSelection(cur, true, true);
1294 cur.message(_("Cut"));
1299 cur.message(_("Copy"));
1302 case LFUN_SERVER_GET_XY:
1303 cur.message(from_utf8(
1304 convert<string>(tm->cursorX(cur.top(), cur.boundary()))
1305 + ' ' + convert<string>(tm->cursorY(cur.top(), cur.boundary()))));
1308 case LFUN_SERVER_SET_XY: {
1311 istringstream is(to_utf8(cmd.argument()));
1314 lyxerr << "SETXY: Could not parse coordinates in '"
1315 << to_utf8(cmd.argument()) << endl;
1317 tm->setCursorFromCoordinates(cur, x, y);
1321 case LFUN_SERVER_GET_LAYOUT:
1322 cur.message(cur.paragraph().layout().name());
1326 docstring layout = cmd.argument();
1327 LYXERR(Debug::INFO, "LFUN_LAYOUT: (arg) " << to_utf8(layout));
1329 Paragraph const & para = cur.paragraph();
1330 docstring const old_layout = para.layout().name();
1331 DocumentClass const & tclass = bv->buffer().params().documentClass();
1334 layout = tclass.defaultLayoutName();
1336 if (owner_->forcePlainLayout())
1337 // in this case only the empty layout is allowed
1338 layout = tclass.plainLayoutName();
1339 else if (para.usePlainLayout()) {
1340 // in this case, default layout maps to empty layout
1341 if (layout == tclass.defaultLayoutName())
1342 layout = tclass.plainLayoutName();
1344 // otherwise, the empty layout maps to the default
1345 if (layout == tclass.plainLayoutName())
1346 layout = tclass.defaultLayoutName();
1349 bool hasLayout = tclass.hasLayout(layout);
1351 // If the entry is obsolete, use the new one instead.
1353 docstring const & obs = tclass[layout].obsoleted_by();
1359 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
1360 from_utf8(N_(" not known")));
1364 bool change_layout = (old_layout != layout);
1366 if (!change_layout && cur.selection() &&
1367 cur.selBegin().pit() != cur.selEnd().pit())
1369 pit_type spit = cur.selBegin().pit();
1370 pit_type epit = cur.selEnd().pit() + 1;
1371 while (spit != epit) {
1372 if (pars_[spit].layout().name() != old_layout) {
1373 change_layout = true;
1381 setLayout(cur, layout);
1383 Layout::LaTeXArgMap args = tclass[layout].args();
1384 Layout::LaTeXArgMap::const_iterator lait = args.begin();
1385 Layout::LaTeXArgMap::const_iterator const laend = args.end();
1386 for (; lait != laend; ++lait) {
1387 Layout::latexarg arg = (*lait).second;
1388 if (arg.autoinsert) {
1389 FuncRequest cmd(LFUN_ARGUMENT_INSERT, (*lait).first);
1397 case LFUN_ENVIRONMENT_SPLIT: {
1398 bool const outer = cmd.argument() == "outer";
1399 Paragraph const & para = cur.paragraph();
1400 docstring layout = para.layout().name();
1401 depth_type split_depth = cur.paragraph().params().depth();
1403 // check if we have an environment in our nesting hierarchy
1404 pit_type pit = cur.pit();
1405 Paragraph cpar = pars_[pit];
1407 if (pit == 0 || cpar.params().depth() == 0)
1411 if (cpar.params().depth() < split_depth
1412 && cpar.layout().isEnvironment()) {
1413 layout = cpar.layout().name();
1414 split_depth = cpar.params().depth();
1419 lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_BREAK));
1421 while (cur.paragraph().params().depth() > split_depth)
1422 lyx::dispatch(FuncRequest(LFUN_DEPTH_DECREMENT));
1424 DocumentClass const & tc = bv->buffer().params().documentClass();
1425 lyx::dispatch(FuncRequest(LFUN_LAYOUT, tc.plainLayout().name()));
1426 lyx::dispatch(FuncRequest(LFUN_SEPARATOR_INSERT, "plain"));
1427 lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_BREAK, "inverse"));
1428 lyx::dispatch(FuncRequest(LFUN_LAYOUT, layout));
1433 case LFUN_CLIPBOARD_PASTE:
1434 cap::replaceSelection(cur);
1435 pasteClipboardText(cur, bv->buffer().errorList("Paste"),
1436 cmd.argument() == "paragraph");
1437 bv->buffer().errors("Paste");
1440 case LFUN_CLIPBOARD_PASTE_SIMPLE:
1441 cap::replaceSelection(cur);
1442 pasteSimpleText(cur, cmd.argument() == "paragraph");
1445 case LFUN_PRIMARY_SELECTION_PASTE:
1446 cap::replaceSelection(cur);
1447 pasteString(cur, theSelection().get(),
1448 cmd.argument() == "paragraph");
1451 case LFUN_SELECTION_PASTE:
1452 // Copy the selection buffer to the clipboard stack,
1453 // because we want it to appear in the "Edit->Paste
1455 cap::replaceSelection(cur);
1456 cap::copySelectionToStack();
1457 cap::pasteSelection(bv->cursor(), bv->buffer().errorList("Paste"));
1458 bv->buffer().errors("Paste");
1461 case LFUN_UNICODE_INSERT: {
1462 if (cmd.argument().empty())
1464 docstring hexstring = cmd.argument();
1465 if (isHex(hexstring)) {
1466 char_type c = hexToInt(hexstring);
1467 if (c >= 32 && c < 0x10ffff) {
1468 lyxerr << "Inserting c: " << c << endl;
1469 docstring s = docstring(1, c);
1470 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
1476 case LFUN_QUOTE_INSERT: {
1477 cap::replaceSelection(cur);
1480 Paragraph const & par = cur.paragraph();
1481 pos_type pos = cur.pos();
1482 // Ignore deleted text before cursor
1483 while (pos > 0 && par.isDeleted(pos - 1))
1486 BufferParams const & bufparams = bv->buffer().params();
1488 par.getFontSettings(bufparams, pos).language()->lang() == "hebrew";
1489 bool const allow_inset_quote = !(par.isPassThru() || hebrew);
1491 string const arg = to_utf8(cmd.argument());
1492 if (allow_inset_quote) {
1494 if (pos > 0 && (!cur.prevInset() || !cur.prevInset()->isSpace()))
1495 c = par.getChar(pos - 1);
1496 InsetQuotes::QuoteTimes const quote_type = (arg == "single")
1497 ? InsetQuotes::SingleQuotes : InsetQuotes::DoubleQuotes;
1498 cur.insert(new InsetQuotes(cur.buffer(), c, quote_type));
1501 // The cursor might have been invalidated by the replaceSelection.
1502 cur.buffer()->changed(true);
1503 string const quote_string = (arg == "single") ? "'" : "\"";
1504 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, quote_string));
1509 case LFUN_DATE_INSERT: {
1510 string const format = cmd.argument().empty()
1511 ? lyxrc.date_insert_format : to_utf8(cmd.argument());
1512 string const time = formatted_time(current_time(), format);
1513 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, time));
1517 case LFUN_MOUSE_TRIPLE:
1518 if (cmd.button() == mouse_button::button1) {
1519 tm->cursorHome(cur);
1527 case LFUN_MOUSE_DOUBLE:
1528 if (cmd.button() == mouse_button::button1) {
1529 selectWord(cur, WHOLE_WORD);
1534 // Single-click on work area
1535 case LFUN_MOUSE_PRESS: {
1536 // We are not marking a selection with the keyboard in any case.
1537 Cursor & bvcur = cur.bv().cursor();
1538 bvcur.setMark(false);
1539 switch (cmd.button()) {
1540 case mouse_button::button1:
1542 if (!bv->mouseSetCursor(cur, cmd.argument() == "region-select"))
1543 cur.screenUpdateFlags(Update::SinglePar | Update::FitCursor);
1544 if (bvcur.wordSelection())
1545 selectWord(bvcur, WHOLE_WORD);
1548 case mouse_button::button2:
1549 // Middle mouse pasting.
1550 bv->mouseSetCursor(cur);
1552 FuncRequest(LFUN_COMMAND_ALTERNATIVES,
1553 "selection-paste ; primary-selection-paste paragraph"));
1554 cur.noScreenUpdate();
1557 case mouse_button::button3: {
1558 // Don't do anything if we right-click a
1559 // selection, a context menu will popup.
1560 if (bvcur.selection() && cur >= bvcur.selectionBegin()
1561 && cur < bvcur.selectionEnd()) {
1562 cur.noScreenUpdate();
1565 if (!bv->mouseSetCursor(cur, false))
1566 cur.screenUpdateFlags(Update::SinglePar | Update::FitCursor);
1572 } // switch (cmd.button())
1575 case LFUN_MOUSE_MOTION: {
1576 // Mouse motion with right or middle mouse do nothing for now.
1577 if (cmd.button() != mouse_button::button1) {
1578 cur.noScreenUpdate();
1581 // ignore motions deeper nested than the real anchor
1582 Cursor & bvcur = cur.bv().cursor();
1583 if (!bvcur.realAnchor().hasPart(cur)) {
1587 CursorSlice old = bvcur.top();
1589 int const wh = bv->workHeight();
1590 int const y = max(0, min(wh - 1, cmd.y()));
1592 tm->setCursorFromCoordinates(cur, cmd.x(), y);
1593 cur.setTargetX(cmd.x());
1595 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1596 else if (cmd.y() < 0)
1597 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1598 // This is to allow jumping over large insets
1599 if (cur.top() == old) {
1601 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1602 else if (cmd.y() < 0)
1603 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1605 // We continue with our existing selection or start a new one, so don't
1606 // reset the anchor.
1607 bvcur.setCursor(cur);
1608 bvcur.setSelection(true);
1609 if (cur.top() == old) {
1610 // We didn't move one iota, so no need to update the screen.
1611 cur.screenUpdateFlags(Update::SinglePar | Update::FitCursor);
1612 //cur.noScreenUpdate();
1618 case LFUN_MOUSE_RELEASE:
1619 switch (cmd.button()) {
1620 case mouse_button::button1:
1621 // Cursor was set at LFUN_MOUSE_PRESS or LFUN_MOUSE_MOTION time.
1622 // If there is a new selection, update persistent selection;
1623 // otherwise, single click does not clear persistent selection
1625 if (cur.selection()) {
1626 // Finish selection. If double click,
1627 // cur is moved to the end of word by
1628 // selectWord but bvcur is current
1630 cur.bv().cursor().setSelection();
1631 // We might have removed an empty but drawn selection
1632 // (probably a margin)
1633 cur.screenUpdateFlags(Update::SinglePar | Update::FitCursor);
1635 cur.noScreenUpdate();
1636 // FIXME: We could try to handle drag and drop of selection here.
1639 case mouse_button::button2:
1640 // Middle mouse pasting is handled at mouse press time,
1641 // see LFUN_MOUSE_PRESS.
1642 cur.noScreenUpdate();
1645 case mouse_button::button3:
1646 // Cursor was set at LFUN_MOUSE_PRESS time.
1647 // FIXME: If there is a selection we could try to handle a special
1648 // drag & drop context menu.
1649 cur.noScreenUpdate();
1652 case mouse_button::none:
1653 case mouse_button::button4:
1654 case mouse_button::button5:
1656 } // switch (cmd.button())
1660 case LFUN_SELF_INSERT: {
1661 if (cmd.argument().empty())
1664 // Automatically delete the currently selected
1665 // text and replace it with what is being
1666 // typed in now. Depends on lyxrc settings
1667 // "auto_region_delete", which defaults to
1670 if (lyxrc.auto_region_delete && cur.selection())
1671 cutSelection(cur, false, false);
1673 cur.clearSelection();
1675 docstring::const_iterator cit = cmd.argument().begin();
1676 docstring::const_iterator const end = cmd.argument().end();
1677 for (; cit != end; ++cit)
1678 bv->translateAndInsert(*cit, this, cur);
1681 moveCursor(cur, false);
1682 cur.markNewWordPosition();
1683 bv->bookmarkEditPosition();
1687 case LFUN_HREF_INSERT: {
1688 // FIXME If we're actually given an argument, shouldn't
1689 // we use it, whether or not we have a selection?
1690 docstring content = cmd.argument();
1691 if (cur.selection()) {
1692 content = cur.selectionAsString(false);
1693 cutSelection(cur, true, false);
1696 InsetCommandParams p(HYPERLINK_CODE);
1697 if (!content.empty()){
1698 // if it looks like a link, we'll put it as target,
1699 // otherwise as name (bug #8792).
1702 // regex_match(to_utf8(content), matches, link_re)
1703 // because smatch stores pointers to the substrings rather
1704 // than making copies of them. And those pointers become
1705 // invalid after regex_match returns, since it is then
1706 // being given a temporary object. (Thanks to Georg for
1707 // figuring that out.)
1708 regex const link_re("^([a-z]+):.*");
1710 string const c = to_utf8(lowercase(content));
1712 if (c.substr(0,7) == "mailto:") {
1713 p["target"] = content;
1714 p["type"] = from_ascii("mailto:");
1715 } else if (regex_match(c, matches, link_re)) {
1716 p["target"] = content;
1717 string protocol = matches.str(1);
1718 if (protocol == "file")
1719 p["type"] = from_ascii("file:");
1721 p["name"] = content;
1723 string const data = InsetCommand::params2string(p);
1725 // we need to have a target. if we already have one, then
1726 // that gets used at the default for the name, too, which
1727 // is probably what is wanted.
1728 if (p["target"].empty()) {
1729 bv->showDialog("href", data);
1731 FuncRequest fr(LFUN_INSET_INSERT, data);
1737 case LFUN_LABEL_INSERT: {
1738 InsetCommandParams p(LABEL_CODE);
1739 // Try to generate a valid label
1740 p["name"] = (cmd.argument().empty()) ?
1741 cur.getPossibleLabel() :
1743 string const data = InsetCommand::params2string(p);
1745 if (cmd.argument().empty()) {
1746 bv->showDialog("label", data);
1748 FuncRequest fr(LFUN_INSET_INSERT, data);
1754 case LFUN_INFO_INSERT: {
1756 if (cmd.argument().empty() && cur.selection()) {
1757 // if command argument is empty use current selection as parameter.
1758 docstring ds = cur.selectionAsString(false);
1759 cutSelection(cur, true, false);
1760 FuncRequest cmd0(cmd, ds);
1761 inset = createInset(cur.buffer(), cmd0);
1763 inset = createInset(cur.buffer(), cmd);
1768 insertInset(cur, inset);
1772 case LFUN_CAPTION_INSERT:
1773 case LFUN_FOOTNOTE_INSERT:
1774 case LFUN_NOTE_INSERT:
1775 case LFUN_BOX_INSERT:
1776 case LFUN_BRANCH_INSERT:
1777 case LFUN_PHANTOM_INSERT:
1778 case LFUN_ERT_INSERT:
1779 case LFUN_LISTING_INSERT:
1780 case LFUN_MARGINALNOTE_INSERT:
1781 case LFUN_ARGUMENT_INSERT:
1782 case LFUN_INDEX_INSERT:
1783 case LFUN_PREVIEW_INSERT:
1784 case LFUN_SCRIPT_INSERT:
1785 case LFUN_IPA_INSERT:
1786 // Open the inset, and move the current selection
1788 doInsertInset(cur, this, cmd, true, true);
1790 // Some insets are numbered, others are shown in the outline pane so
1791 // let's update the labels and the toc backend.
1792 cur.forceBufferUpdate();
1795 case LFUN_FLEX_INSERT: {
1796 // Open the inset, and move the current selection
1798 bool const sel = cur.selection();
1799 doInsertInset(cur, this, cmd, true, true);
1800 // Insert auto-insert arguments
1801 bool autoargs = false;
1802 Layout::LaTeXArgMap args = cur.inset().getLayout().latexargs();
1803 Layout::LaTeXArgMap::const_iterator lait = args.begin();
1804 Layout::LaTeXArgMap::const_iterator const laend = args.end();
1805 for (; lait != laend; ++lait) {
1806 Layout::latexarg arg = (*lait).second;
1807 if (arg.autoinsert) {
1808 // The cursor might have been invalidated by the replaceSelection.
1809 cur.buffer()->changed(true);
1810 FuncRequest cmd(LFUN_ARGUMENT_INSERT, (*lait).first);
1817 cur.leaveInset(cur.inset());
1820 // Some insets are numbered, others are shown in the outline pane so
1821 // let's update the labels and the toc backend.
1822 cur.forceBufferUpdate();
1826 case LFUN_TABULAR_INSERT:
1827 // if there were no arguments, just open the dialog
1828 if (doInsertInset(cur, this, cmd, false, true))
1831 bv->showDialog("tabularcreate");
1835 case LFUN_FLOAT_INSERT:
1836 case LFUN_FLOAT_WIDE_INSERT:
1837 case LFUN_WRAP_INSERT: {
1838 // will some content be moved into the inset?
1839 bool const content = cur.selection();
1840 // does the content consist of multiple paragraphs?
1841 bool const singlepar = (cur.selBegin().pit() == cur.selEnd().pit());
1843 doInsertInset(cur, this, cmd, true, true);
1846 // If some single-par content is moved into the inset,
1847 // doInsertInset puts the cursor outside the inset.
1848 // To insert the caption we put it back into the inset.
1849 // FIXME cleanup doInsertInset to avoid such dances!
1850 if (content && singlepar)
1853 ParagraphList & pars = cur.text()->paragraphs();
1855 DocumentClass const & tclass = bv->buffer().params().documentClass();
1857 // add a separate paragraph for the caption inset
1858 pars.push_back(Paragraph());
1859 pars.back().setInsetOwner(&cur.text()->inset());
1860 pars.back().setPlainOrDefaultLayout(tclass);
1861 int cap_pit = pars.size() - 1;
1863 // if an empty inset was created, we create an additional empty
1864 // paragraph at the bottom so that the user can choose where to put
1865 // the graphics (or table).
1867 pars.push_back(Paragraph());
1868 pars.back().setInsetOwner(&cur.text()->inset());
1869 pars.back().setPlainOrDefaultLayout(tclass);
1872 // reposition the cursor to the caption
1873 cur.pit() = cap_pit;
1875 // FIXME: This Text/Cursor dispatch handling is a mess!
1876 // We cannot use Cursor::dispatch here it needs access to up to
1878 FuncRequest cmd_caption(LFUN_CAPTION_INSERT);
1879 doInsertInset(cur, cur.text(), cmd_caption, true, false);
1880 cur.forceBufferUpdate();
1881 cur.screenUpdateFlags(Update::Force);
1882 // FIXME: When leaving the Float (or Wrap) inset we should
1883 // delete any empty paragraph left above or below the
1888 case LFUN_NOMENCL_INSERT: {
1889 InsetCommandParams p(NOMENCL_CODE);
1890 if (cmd.argument().empty())
1891 p["symbol"] = bv->cursor().innerText()->getStringToIndex(bv->cursor());
1893 p["symbol"] = cmd.argument();
1894 string const data = InsetCommand::params2string(p);
1895 bv->showDialog("nomenclature", data);
1899 case LFUN_INDEX_PRINT: {
1900 InsetCommandParams p(INDEX_PRINT_CODE);
1901 if (cmd.argument().empty())
1902 p["type"] = from_ascii("idx");
1904 p["type"] = cmd.argument();
1905 string const data = InsetCommand::params2string(p);
1906 FuncRequest fr(LFUN_INSET_INSERT, data);
1911 case LFUN_NOMENCL_PRINT:
1912 case LFUN_NEWPAGE_INSERT:
1914 doInsertInset(cur, this, cmd, false, false);
1918 case LFUN_SEPARATOR_INSERT: {
1919 doInsertInset(cur, this, cmd, false, false);
1921 // remove a following space
1922 Paragraph & par = cur.paragraph();
1923 if (cur.pos() != cur.lastpos() && par.isLineSeparator(cur.pos()))
1924 par.eraseChar(cur.pos(), cur.buffer()->params().track_changes);
1928 case LFUN_DEPTH_DECREMENT:
1929 changeDepth(cur, DEC_DEPTH);
1932 case LFUN_DEPTH_INCREMENT:
1933 changeDepth(cur, INC_DEPTH);
1936 case LFUN_MATH_DISPLAY:
1937 mathDispatch(cur, cmd, true);
1940 case LFUN_REGEXP_MODE:
1941 regexpDispatch(cur, cmd);
1944 case LFUN_MATH_MODE:
1945 if (cmd.argument() == "on")
1946 // don't pass "on" as argument
1947 // (it would appear literally in the first cell)
1948 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1950 mathDispatch(cur, cmd, false);
1953 case LFUN_MATH_MACRO:
1954 if (cmd.argument().empty())
1955 cur.errorMessage(from_utf8(N_("Missing argument")));
1958 string s = to_utf8(cmd.argument());
1959 string const s1 = token(s, ' ', 1);
1960 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1961 string const s2 = token(s, ' ', 2);
1962 MacroType type = MacroTypeNewcommand;
1964 type = MacroTypeDef;
1965 MathMacroTemplate * inset = new MathMacroTemplate(cur.buffer(),
1966 from_utf8(token(s, ' ', 0)), nargs, false, type);
1967 inset->setBuffer(bv->buffer());
1968 insertInset(cur, inset);
1970 // enter macro inset and select the name
1972 cur.top().pos() = cur.top().lastpos();
1974 cur.setSelection(true);
1975 cur.top().pos() = 0;
1979 // passthrough hat and underscore outside mathed:
1980 case LFUN_MATH_SUBSCRIPT:
1981 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1983 case LFUN_MATH_SUPERSCRIPT:
1984 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1987 case LFUN_MATH_INSERT:
1988 case LFUN_MATH_AMS_MATRIX:
1989 case LFUN_MATH_MATRIX:
1990 case LFUN_MATH_DELIM:
1991 case LFUN_MATH_BIGDELIM: {
1993 cap::replaceSelection(cur);
1994 cur.insert(new InsetMathHull(cur.buffer(), hullSimple));
1995 checkAndActivateInset(cur, true);
1996 LASSERT(cur.inMathed(), break);
2001 case LFUN_FONT_EMPH: {
2002 Font font(ignore_font, ignore_language);
2003 font.fontInfo().setEmph(FONT_TOGGLE);
2004 toggleAndShow(cur, this, font);
2008 case LFUN_FONT_ITAL: {
2009 Font font(ignore_font, ignore_language);
2010 font.fontInfo().setShape(ITALIC_SHAPE);
2011 toggleAndShow(cur, this, font);
2015 case LFUN_FONT_BOLD:
2016 case LFUN_FONT_BOLDSYMBOL: {
2017 Font font(ignore_font, ignore_language);
2018 font.fontInfo().setSeries(BOLD_SERIES);
2019 toggleAndShow(cur, this, font);
2023 case LFUN_FONT_NOUN: {
2024 Font font(ignore_font, ignore_language);
2025 font.fontInfo().setNoun(FONT_TOGGLE);
2026 toggleAndShow(cur, this, font);
2030 case LFUN_FONT_TYPEWRITER: {
2031 Font font(ignore_font, ignore_language);
2032 font.fontInfo().setFamily(TYPEWRITER_FAMILY); // no good
2033 toggleAndShow(cur, this, font);
2037 case LFUN_FONT_SANS: {
2038 Font font(ignore_font, ignore_language);
2039 font.fontInfo().setFamily(SANS_FAMILY);
2040 toggleAndShow(cur, this, font);
2044 case LFUN_FONT_ROMAN: {
2045 Font font(ignore_font, ignore_language);
2046 font.fontInfo().setFamily(ROMAN_FAMILY);
2047 toggleAndShow(cur, this, font);
2051 case LFUN_FONT_DEFAULT: {
2052 Font font(inherit_font, ignore_language);
2053 toggleAndShow(cur, this, font);
2057 case LFUN_FONT_STRIKEOUT: {
2058 Font font(ignore_font, ignore_language);
2059 font.fontInfo().setStrikeout(FONT_TOGGLE);
2060 toggleAndShow(cur, this, font);
2064 case LFUN_FONT_UNDERUNDERLINE: {
2065 Font font(ignore_font, ignore_language);
2066 font.fontInfo().setUuline(FONT_TOGGLE);
2067 toggleAndShow(cur, this, font);
2071 case LFUN_FONT_UNDERWAVE: {
2072 Font font(ignore_font, ignore_language);
2073 font.fontInfo().setUwave(FONT_TOGGLE);
2074 toggleAndShow(cur, this, font);
2078 case LFUN_FONT_UNDERLINE: {
2079 Font font(ignore_font, ignore_language);
2080 font.fontInfo().setUnderbar(FONT_TOGGLE);
2081 toggleAndShow(cur, this, font);
2085 case LFUN_FONT_SIZE: {
2086 Font font(ignore_font, ignore_language);
2087 setLyXSize(to_utf8(cmd.argument()), font.fontInfo());
2088 toggleAndShow(cur, this, font);
2092 case LFUN_LANGUAGE: {
2093 string const lang_arg = cmd.getArg(0);
2094 bool const reset = (lang_arg.empty() || lang_arg == "reset");
2095 Language const * lang =
2096 reset ? reset_language
2097 : languages.getLanguage(lang_arg);
2098 // we allow reset_language, which is 0, but only if it
2099 // was requested via empty or "reset" arg.
2100 if (!lang && !reset)
2102 bool const toggle = (cmd.getArg(1) != "set");
2103 selectWordWhenUnderCursor(cur, WHOLE_WORD_STRICT);
2104 Font font(ignore_font, lang);
2105 toggleAndShow(cur, this, font, toggle);
2109 case LFUN_TEXTSTYLE_APPLY:
2110 toggleAndShow(cur, this, freefont, toggleall);
2111 cur.message(_("Character set"));
2114 // Set the freefont using the contents of \param data dispatched from
2115 // the frontends and apply it at the current cursor location.
2116 case LFUN_TEXTSTYLE_UPDATE: {
2119 if (font.fromString(to_utf8(cmd.argument()), toggle)) {
2122 toggleAndShow(cur, this, freefont, toggleall);
2123 cur.message(_("Character set"));
2125 lyxerr << "Argument not ok";
2130 case LFUN_FINISHED_LEFT:
2131 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_LEFT:\n" << cur);
2132 // We're leaving an inset, going left. If the inset is LTR, we're
2133 // leaving from the front, so we should not move (remain at --- but
2134 // not in --- the inset). If the inset is RTL, move left, without
2135 // entering the inset itself; i.e., move to after the inset.
2136 if (cur.paragraph().getFontSettings(
2137 cur.bv().buffer().params(), cur.pos()).isRightToLeft())
2138 cursorVisLeft(cur, true);
2141 case LFUN_FINISHED_RIGHT:
2142 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_RIGHT:\n" << cur);
2143 // We're leaving an inset, going right. If the inset is RTL, we're
2144 // leaving from the front, so we should not move (remain at --- but
2145 // not in --- the inset). If the inset is LTR, move right, without
2146 // entering the inset itself; i.e., move to after the inset.
2147 if (!cur.paragraph().getFontSettings(
2148 cur.bv().buffer().params(), cur.pos()).isRightToLeft())
2149 cursorVisRight(cur, true);
2152 case LFUN_FINISHED_BACKWARD:
2153 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_BACKWARD:\n" << cur);
2156 case LFUN_FINISHED_FORWARD:
2157 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_FORWARD:\n" << cur);
2159 cur.setCurrentFont();
2162 case LFUN_LAYOUT_PARAGRAPH: {
2164 params2string(cur.paragraph(), data);
2165 data = "show\n" + data;
2166 bv->showDialog("paragraph", data);
2170 case LFUN_PARAGRAPH_UPDATE: {
2172 params2string(cur.paragraph(), data);
2174 // Will the paragraph accept changes from the dialog?
2176 cur.inset().allowParagraphCustomization(cur.idx());
2178 data = "update " + convert<string>(accept) + '\n' + data;
2179 bv->updateDialog("paragraph", data);
2183 case LFUN_ACCENT_UMLAUT:
2184 case LFUN_ACCENT_CIRCUMFLEX:
2185 case LFUN_ACCENT_GRAVE:
2186 case LFUN_ACCENT_ACUTE:
2187 case LFUN_ACCENT_TILDE:
2188 case LFUN_ACCENT_CEDILLA:
2189 case LFUN_ACCENT_MACRON:
2190 case LFUN_ACCENT_DOT:
2191 case LFUN_ACCENT_UNDERDOT:
2192 case LFUN_ACCENT_UNDERBAR:
2193 case LFUN_ACCENT_CARON:
2194 case LFUN_ACCENT_BREVE:
2195 case LFUN_ACCENT_TIE:
2196 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
2197 case LFUN_ACCENT_CIRCLE:
2198 case LFUN_ACCENT_OGONEK:
2199 theApp()->handleKeyFunc(cmd.action());
2200 if (!cmd.argument().empty())
2201 // FIXME: Are all these characters encoded in one byte in utf8?
2202 bv->translateAndInsert(cmd.argument()[0], this, cur);
2203 cur.screenUpdateFlags(Update::FitCursor);
2206 case LFUN_FLOAT_LIST_INSERT: {
2207 DocumentClass const & tclass = bv->buffer().params().documentClass();
2208 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
2210 if (cur.selection())
2211 cutSelection(cur, true, false);
2212 breakParagraph(cur);
2214 if (cur.lastpos() != 0) {
2215 cursorBackward(cur);
2216 breakParagraph(cur);
2219 docstring const laystr = cur.inset().usePlainLayout() ?
2220 tclass.plainLayoutName() :
2221 tclass.defaultLayoutName();
2222 setLayout(cur, laystr);
2223 ParagraphParameters p;
2224 // FIXME If this call were replaced with one to clearParagraphParams(),
2225 // then we could get rid of this method altogether.
2226 setParagraphs(cur, p);
2227 // FIXME This should be simplified when InsetFloatList takes a
2228 // Buffer in its constructor.
2229 InsetFloatList * ifl = new InsetFloatList(cur.buffer(), to_utf8(cmd.argument()));
2230 ifl->setBuffer(bv->buffer());
2231 insertInset(cur, ifl);
2234 lyxerr << "Non-existent float type: "
2235 << to_utf8(cmd.argument()) << endl;
2240 case LFUN_CHANGE_ACCEPT: {
2241 acceptOrRejectChanges(cur, ACCEPT);
2245 case LFUN_CHANGE_REJECT: {
2246 acceptOrRejectChanges(cur, REJECT);
2250 case LFUN_THESAURUS_ENTRY: {
2251 docstring arg = cmd.argument();
2253 arg = cur.selectionAsString(false);
2255 if (arg.size() > 100 || arg.empty()) {
2256 // Get word or selection
2257 selectWordWhenUnderCursor(cur, WHOLE_WORD);
2258 arg = cur.selectionAsString(false);
2259 arg += " lang=" + from_ascii(cur.getFont().language()->lang());
2262 bv->showDialog("thesaurus", to_utf8(arg));
2266 case LFUN_SPELLING_ADD: {
2267 docstring word = from_utf8(cmd.getArg(0));
2270 word = cur.selectionAsString(false);
2272 if (word.size() > 100 || word.empty()) {
2273 // Get word or selection
2274 selectWordWhenUnderCursor(cur, WHOLE_WORD);
2275 word = cur.selectionAsString(false);
2277 lang = const_cast<Language *>(cur.getFont().language());
2279 lang = const_cast<Language *>(languages.getLanguage(cmd.getArg(1)));
2280 WordLangTuple wl(word, lang);
2281 theSpellChecker()->insert(wl);
2285 case LFUN_SPELLING_IGNORE: {
2286 docstring word = from_utf8(cmd.getArg(0));
2289 word = cur.selectionAsString(false);
2291 if (word.size() > 100 || word.empty()) {
2292 // Get word or selection
2293 selectWordWhenUnderCursor(cur, WHOLE_WORD);
2294 word = cur.selectionAsString(false);
2296 lang = const_cast<Language *>(cur.getFont().language());
2298 lang = const_cast<Language *>(languages.getLanguage(cmd.getArg(1)));
2299 WordLangTuple wl(word, lang);
2300 theSpellChecker()->accept(wl);
2304 case LFUN_SPELLING_REMOVE: {
2305 docstring word = from_utf8(cmd.getArg(0));
2308 word = cur.selectionAsString(false);
2310 if (word.size() > 100 || word.empty()) {
2311 // Get word or selection
2312 selectWordWhenUnderCursor(cur, WHOLE_WORD);
2313 word = cur.selectionAsString(false);
2315 lang = const_cast<Language *>(cur.getFont().language());
2317 lang = const_cast<Language *>(languages.getLanguage(cmd.getArg(1)));
2318 WordLangTuple wl(word, lang);
2319 theSpellChecker()->remove(wl);
2323 case LFUN_PARAGRAPH_PARAMS_APPLY: {
2324 // Given data, an encoding of the ParagraphParameters
2325 // generated in the Paragraph dialog, this function sets
2326 // the current paragraph, or currently selected paragraphs,
2328 // NOTE: This function overrides all existing settings.
2329 setParagraphs(cur, cmd.argument());
2330 cur.message(_("Paragraph layout set"));
2334 case LFUN_PARAGRAPH_PARAMS: {
2335 // Given data, an encoding of the ParagraphParameters as we'd
2336 // find them in a LyX file, this function modifies the current paragraph,
2337 // or currently selected paragraphs.
2338 // NOTE: This function only modifies, and does not override, existing
2340 setParagraphs(cur, cmd.argument(), true);
2341 cur.message(_("Paragraph layout set"));
2346 if (cur.selection()) {
2347 cur.setSelection(false);
2350 // This used to be LFUN_FINISHED_RIGHT, I think FORWARD is more
2351 // correct, but I'm not 100% sure -- dov, 071019
2352 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
2356 case LFUN_OUTLINE_UP:
2357 outline(OutlineUp, cur);
2358 setCursor(cur, cur.pit(), 0);
2359 cur.forceBufferUpdate();
2363 case LFUN_OUTLINE_DOWN:
2364 outline(OutlineDown, cur);
2365 setCursor(cur, cur.pit(), 0);
2366 cur.forceBufferUpdate();
2370 case LFUN_OUTLINE_IN:
2371 outline(OutlineIn, cur);
2372 cur.forceBufferUpdate();
2376 case LFUN_OUTLINE_OUT:
2377 outline(OutlineOut, cur);
2378 cur.forceBufferUpdate();
2382 case LFUN_SERVER_GET_STATISTICS:
2384 DocIterator from, to;
2385 if (cur.selection()) {
2386 from = cur.selectionBegin();
2387 to = cur.selectionEnd();
2389 from = doc_iterator_begin(cur.buffer());
2390 to = doc_iterator_end(cur.buffer());
2393 cur.buffer()->updateStatistics(from, to);
2394 string const arg0 = cmd.getArg(0);
2395 if (arg0 == "words") {
2396 cur.message(convert<docstring>(cur.buffer()->wordCount()));
2397 } else if (arg0 == "chars") {
2398 cur.message(convert<docstring>(cur.buffer()->charCount(false)));
2399 } else if (arg0 == "chars-space") {
2400 cur.message(convert<docstring>(cur.buffer()->charCount(true)));
2402 cur.message(convert<docstring>(cur.buffer()->wordCount()) + " "
2403 + convert<docstring>(cur.buffer()->charCount(false)) + " "
2404 + convert<docstring>(cur.buffer()->charCount(true)));
2410 LYXERR(Debug::ACTION, "Command " << cmd << " not DISPATCHED by Text");
2415 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
2417 if (lyxrc.spellcheck_continuously && !needsUpdate) {
2418 // Check for misspelled text
2419 // The redraw is useful because of the painting of
2420 // misspelled markers depends on the cursor position.
2421 // Trigger a redraw for cursor moves inside misspelled text.
2422 if (!cur.inTexted()) {
2423 // move from regular text to math
2424 needsUpdate = last_misspelled;
2425 } else if (oldTopSlice != cur.top() || oldBoundary != cur.boundary()) {
2426 // move inside regular text
2427 needsUpdate = last_misspelled
2428 || cur.paragraph().isMisspelled(cur.pos(), true);
2432 // FIXME: The cursor flag is reset two lines below
2433 // so we need to check here if some of the LFUN did touch that.
2434 // for now only Text::erase() and Text::backspace() do that.
2435 // The plan is to verify all the LFUNs and then to remove this
2436 // singleParUpdate boolean altogether.
2437 if (cur.result().screenUpdate() & Update::Force) {
2438 singleParUpdate = false;
2442 // FIXME: the following code should go in favor of fine grained
2443 // update flag treatment.
2444 if (singleParUpdate) {
2445 // Inserting characters does not change par height in general. So, try
2446 // to update _only_ this paragraph. BufferView will detect if a full
2447 // metrics update is needed anyway.
2448 cur.screenUpdateFlags(Update::SinglePar | Update::FitCursor);
2452 && &oldTopSlice.inset() == &cur.inset()
2453 && oldTopSlice.idx() == cur.idx()
2454 && !oldSelection // oldSelection is a backup of cur.selection() at the beginning of the function.
2455 && !cur.selection())
2456 // FIXME: it would be better if we could just do this
2458 //if (cur.result().update() != Update::FitCursor)
2459 // cur.noScreenUpdate();
2461 // But some LFUNs do not set Update::FitCursor when needed, so we
2462 // do it for all. This is not very harmfull as FitCursor will provoke
2463 // a full redraw only if needed but still, a proper review of all LFUN
2464 // should be done and this needsUpdate boolean can then be removed.
2465 cur.screenUpdateFlags(Update::FitCursor);
2467 cur.screenUpdateFlags(Update::Force | Update::FitCursor);
2471 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
2472 FuncStatus & flag) const
2474 LBUFERR(this == cur.text());
2476 FontInfo const & fontinfo = cur.real_current_font.fontInfo();
2478 bool allow_in_passthru = false;
2479 InsetCode code = NO_CODE;
2481 switch (cmd.action()) {
2483 case LFUN_DEPTH_DECREMENT:
2484 enable = changeDepthAllowed(cur, DEC_DEPTH);
2487 case LFUN_DEPTH_INCREMENT:
2488 enable = changeDepthAllowed(cur, INC_DEPTH);
2492 // FIXME We really should not allow this to be put, e.g.,
2493 // in a footnote, or in ERT. But it would make sense in a
2494 // branch, so I'm not sure what to do.
2495 flag.setOnOff(cur.paragraph().params().startOfAppendix());
2498 case LFUN_DIALOG_SHOW_NEW_INSET:
2499 if (cmd.argument() == "bibitem")
2500 code = BIBITEM_CODE;
2501 else if (cmd.argument() == "bibtex") {
2503 // not allowed in description items
2504 enable = !inDescriptionItem(cur);
2506 else if (cmd.argument() == "box")
2508 else if (cmd.argument() == "branch")
2510 else if (cmd.argument() == "citation")
2512 else if (cmd.argument() == "ert")
2514 else if (cmd.argument() == "external")
2515 code = EXTERNAL_CODE;
2516 else if (cmd.argument() == "float")
2518 else if (cmd.argument() == "graphics")
2519 code = GRAPHICS_CODE;
2520 else if (cmd.argument() == "href")
2521 code = HYPERLINK_CODE;
2522 else if (cmd.argument() == "include")
2523 code = INCLUDE_CODE;
2524 else if (cmd.argument() == "index")
2526 else if (cmd.argument() == "index_print")
2527 code = INDEX_PRINT_CODE;
2528 else if (cmd.argument() == "listings")
2529 code = LISTINGS_CODE;
2530 else if (cmd.argument() == "mathspace")
2531 code = MATH_HULL_CODE;
2532 else if (cmd.argument() == "nomenclature")
2533 code = NOMENCL_CODE;
2534 else if (cmd.argument() == "nomencl_print")
2535 code = NOMENCL_PRINT_CODE;
2536 else if (cmd.argument() == "label")
2538 else if (cmd.argument() == "line")
2540 else if (cmd.argument() == "note")
2542 else if (cmd.argument() == "phantom")
2543 code = PHANTOM_CODE;
2544 else if (cmd.argument() == "ref")
2546 else if (cmd.argument() == "space")
2548 else if (cmd.argument() == "toc")
2550 else if (cmd.argument() == "vspace")
2552 else if (cmd.argument() == "wrap")
2556 case LFUN_ERT_INSERT:
2559 case LFUN_LISTING_INSERT:
2560 code = LISTINGS_CODE;
2561 // not allowed in description items
2562 enable = !inDescriptionItem(cur);
2564 case LFUN_FOOTNOTE_INSERT:
2567 case LFUN_TABULAR_INSERT:
2568 code = TABULAR_CODE;
2570 case LFUN_MARGINALNOTE_INSERT:
2573 case LFUN_FLOAT_INSERT:
2574 case LFUN_FLOAT_WIDE_INSERT:
2575 // FIXME: If there is a selection, we should check whether there
2576 // are floats in the selection, but this has performance issues, see
2577 // LFUN_CHANGE_ACCEPT/REJECT.
2579 if (inDescriptionItem(cur))
2580 // not allowed in description items
2583 InsetCode const inset_code = cur.inset().lyxCode();
2585 // algorithm floats cannot be put in another float
2586 if (to_utf8(cmd.argument()) == "algorithm") {
2587 enable = inset_code != WRAP_CODE && inset_code != FLOAT_CODE;
2591 // for figures and tables: only allow in another
2592 // float or wrap if it is of the same type and
2593 // not a subfloat already
2594 if(cur.inset().lyxCode() == code) {
2595 InsetFloat const & ins =
2596 static_cast<InsetFloat const &>(cur.inset());
2597 enable = ins.params().type == to_utf8(cmd.argument())
2598 && !ins.params().subfloat;
2599 } else if(cur.inset().lyxCode() == WRAP_CODE) {
2600 InsetWrap const & ins =
2601 static_cast<InsetWrap const &>(cur.inset());
2602 enable = ins.params().type == to_utf8(cmd.argument());
2606 case LFUN_WRAP_INSERT:
2608 // not allowed in description items
2609 enable = !inDescriptionItem(cur);
2611 case LFUN_FLOAT_LIST_INSERT: {
2612 code = FLOAT_LIST_CODE;
2613 // not allowed in description items
2614 enable = !inDescriptionItem(cur);
2616 FloatList const & floats = cur.buffer()->params().documentClass().floats();
2617 FloatList::const_iterator cit = floats[to_ascii(cmd.argument())];
2618 // make sure we know about such floats
2619 if (cit == floats.end() ||
2620 // and that we know how to generate a list of them
2621 (!cit->second.usesFloatPkg() && cit->second.listCommand().empty())) {
2622 flag.setUnknown(true);
2623 // probably not necessary, but...
2629 case LFUN_CAPTION_INSERT: {
2630 code = CAPTION_CODE;
2631 string arg = cmd.getArg(0);
2632 bool varia = arg != "LongTableNoNumber"
2633 && cur.inset().allowsCaptionVariation(arg);
2634 // not allowed in description items,
2635 // and in specific insets
2636 enable = !inDescriptionItem(cur)
2637 && (varia || arg.empty() || arg == "Standard");
2640 case LFUN_NOTE_INSERT:
2642 // in commands (sections etc.) and description items,
2643 // only Notes are allowed
2644 enable = (cmd.argument().empty() || cmd.getArg(0) == "Note" ||
2645 (!cur.paragraph().layout().isCommand()
2646 && !inDescriptionItem(cur)));
2648 case LFUN_FLEX_INSERT: {
2650 string s = cmd.getArg(0);
2652 cur.buffer()->params().documentClass().insetLayout(from_utf8(s));
2653 if (il.lyxtype() != InsetLayout::CHARSTYLE &&
2654 il.lyxtype() != InsetLayout::CUSTOM &&
2655 il.lyxtype() != InsetLayout::ELEMENT &&
2656 il.lyxtype ()!= InsetLayout::STANDARD)
2660 case LFUN_BOX_INSERT:
2663 case LFUN_BRANCH_INSERT:
2665 if (cur.buffer()->masterBuffer()->params().branchlist().empty()
2666 && cur.buffer()->params().branchlist().empty())
2669 case LFUN_IPA_INSERT:
2672 case LFUN_PHANTOM_INSERT:
2673 code = PHANTOM_CODE;
2675 case LFUN_LABEL_INSERT:
2678 case LFUN_INFO_INSERT:
2681 case LFUN_ARGUMENT_INSERT: {
2683 allow_in_passthru = true;
2684 string const arg = cmd.getArg(0);
2689 Layout const & lay = cur.paragraph().layout();
2690 Layout::LaTeXArgMap args = lay.args();
2691 Layout::LaTeXArgMap::const_iterator const lait =
2693 if (lait != args.end()) {
2695 pit_type pit = cur.pit();
2696 pit_type lastpit = cur.pit();
2697 if (lay.isEnvironment() && !prefixIs(arg, "item:")) {
2698 // In a sequence of "merged" environment layouts, we only allow
2699 // non-item arguments once.
2700 lastpit = cur.lastpit();
2701 // get the first paragraph in sequence with this layout
2702 depth_type const current_depth = cur.paragraph().params().depth();
2706 Paragraph cpar = pars_[pit - 1];
2707 if (cpar.layout() == lay && cpar.params().depth() == current_depth)
2713 for (; pit <= lastpit; ++pit) {
2714 if (pars_[pit].layout() != lay)
2716 InsetList::const_iterator it = pars_[pit].insetList().begin();
2717 InsetList::const_iterator end = pars_[pit].insetList().end();
2718 for (; it != end; ++it) {
2719 if (it->inset->lyxCode() == ARG_CODE) {
2720 InsetArgument const * ins =
2721 static_cast<InsetArgument const *>(it->inset);
2722 if (ins->name() == arg) {
2723 // we have this already
2734 case LFUN_INDEX_INSERT:
2737 case LFUN_INDEX_PRINT:
2738 code = INDEX_PRINT_CODE;
2739 // not allowed in description items
2740 enable = !inDescriptionItem(cur);
2742 case LFUN_NOMENCL_INSERT:
2743 if (cur.selIsMultiCell() || cur.selIsMultiLine()) {
2747 code = NOMENCL_CODE;
2749 case LFUN_NOMENCL_PRINT:
2750 code = NOMENCL_PRINT_CODE;
2751 // not allowed in description items
2752 enable = !inDescriptionItem(cur);
2754 case LFUN_HREF_INSERT:
2755 if (cur.selIsMultiCell() || cur.selIsMultiLine()) {
2759 code = HYPERLINK_CODE;
2761 case LFUN_IPAMACRO_INSERT: {
2762 string const arg = cmd.getArg(0);
2764 code = IPADECO_CODE;
2766 code = IPACHAR_CODE;
2769 case LFUN_QUOTE_INSERT:
2770 // always allow this, since we will inset a raw quote
2771 // if an inset is not allowed.
2773 case LFUN_SPECIALCHAR_INSERT:
2774 code = SPECIALCHAR_CODE;
2776 case LFUN_SPACE_INSERT:
2777 // slight hack: we know this is allowed in math mode
2781 case LFUN_PREVIEW_INSERT:
2782 code = PREVIEW_CODE;
2784 case LFUN_SCRIPT_INSERT:
2788 case LFUN_MATH_INSERT:
2789 case LFUN_MATH_AMS_MATRIX:
2790 case LFUN_MATH_MATRIX:
2791 case LFUN_MATH_DELIM:
2792 case LFUN_MATH_BIGDELIM:
2793 case LFUN_MATH_DISPLAY:
2794 case LFUN_MATH_MODE:
2795 case LFUN_MATH_MACRO:
2796 case LFUN_MATH_SUBSCRIPT:
2797 case LFUN_MATH_SUPERSCRIPT:
2798 code = MATH_HULL_CODE;
2801 case LFUN_REGEXP_MODE:
2802 code = MATH_HULL_CODE;
2803 enable = cur.buffer()->isInternal() && !cur.inRegexped();
2806 case LFUN_INSET_MODIFY:
2807 // We need to disable this, because we may get called for a
2809 // InsetTabular::getStatus() -> InsetText::getStatus()
2810 // and we don't handle LFUN_INSET_MODIFY.
2814 case LFUN_FONT_EMPH:
2815 flag.setOnOff(fontinfo.emph() == FONT_ON);
2816 enable = !cur.paragraph().isPassThru();
2819 case LFUN_FONT_ITAL:
2820 flag.setOnOff(fontinfo.shape() == ITALIC_SHAPE);
2821 enable = !cur.paragraph().isPassThru();
2824 case LFUN_FONT_NOUN:
2825 flag.setOnOff(fontinfo.noun() == FONT_ON);
2826 enable = !cur.paragraph().isPassThru();
2829 case LFUN_FONT_BOLD:
2830 case LFUN_FONT_BOLDSYMBOL:
2831 flag.setOnOff(fontinfo.series() == BOLD_SERIES);
2832 enable = !cur.paragraph().isPassThru();
2835 case LFUN_FONT_SANS:
2836 flag.setOnOff(fontinfo.family() == SANS_FAMILY);
2837 enable = !cur.paragraph().isPassThru();
2840 case LFUN_FONT_ROMAN:
2841 flag.setOnOff(fontinfo.family() == ROMAN_FAMILY);
2842 enable = !cur.paragraph().isPassThru();
2845 case LFUN_FONT_TYPEWRITER:
2846 flag.setOnOff(fontinfo.family() == TYPEWRITER_FAMILY);
2847 enable = !cur.paragraph().isPassThru();
2852 enable = cur.selection();
2856 if (cmd.argument().empty()) {
2857 if (theClipboard().isInternal())
2858 enable = cap::numberOfSelections() > 0;
2860 enable = !theClipboard().empty();
2864 // we have an argument
2865 string const arg = to_utf8(cmd.argument());
2866 if (isStrUnsignedInt(arg)) {
2867 // it's a number and therefore means the internal stack
2868 unsigned int n = convert<unsigned int>(arg);
2869 enable = cap::numberOfSelections() > n;
2873 // explicit text type?
2874 if (arg == "html") {
2875 // Do not enable for PlainTextType, since some tidying in the
2876 // frontend is needed for HTML, which is too unsafe for plain text.
2877 enable = theClipboard().hasTextContents(Clipboard::HtmlTextType);
2879 } else if (arg == "latex") {
2880 // LaTeX is usually not available on the clipboard with
2881 // the correct MIME type, but in plain text.
2882 enable = theClipboard().hasTextContents(Clipboard::PlainTextType) ||
2883 theClipboard().hasTextContents(Clipboard::LaTeXTextType);
2887 // explicit graphics type?
2888 Clipboard::GraphicsType type = Clipboard::AnyGraphicsType;
2889 if ((arg == "pdf" && (type = Clipboard::PdfGraphicsType))
2890 || (arg == "png" && (type = Clipboard::PngGraphicsType))
2891 || (arg == "jpeg" && (type = Clipboard::JpegGraphicsType))
2892 || (arg == "linkback" && (type = Clipboard::LinkBackGraphicsType))
2893 || (arg == "emf" && (type = Clipboard::EmfGraphicsType))
2894 || (arg == "wmf" && (type = Clipboard::WmfGraphicsType))) {
2895 enable = theClipboard().hasGraphicsContents(type);
2904 case LFUN_CLIPBOARD_PASTE:
2905 case LFUN_CLIPBOARD_PASTE_SIMPLE:
2906 enable = !theClipboard().empty();
2909 case LFUN_PRIMARY_SELECTION_PASTE:
2910 enable = cur.selection() || !theSelection().empty();
2913 case LFUN_SELECTION_PASTE:
2914 enable = cap::selection();
2917 case LFUN_PARAGRAPH_MOVE_UP:
2918 enable = cur.pit() > 0 && !cur.selection();
2921 case LFUN_PARAGRAPH_MOVE_DOWN:
2922 enable = cur.pit() < cur.lastpit() && !cur.selection();
2925 case LFUN_CHANGE_ACCEPT:
2926 case LFUN_CHANGE_REJECT:
2927 // In principle, these LFUNs should only be enabled if there
2928 // is a change at the current position/in the current selection.
2929 // However, without proper optimizations, this will inevitably
2930 // result in unacceptable performance - just imagine a user who
2931 // wants to select the complete content of a long document.
2932 if (!cur.selection())
2933 enable = cur.paragraph().isChanged(cur.pos());
2935 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
2940 case LFUN_OUTLINE_UP:
2941 case LFUN_OUTLINE_DOWN:
2942 case LFUN_OUTLINE_IN:
2943 case LFUN_OUTLINE_OUT:
2944 // FIXME: LyX is not ready for outlining within inset.
2945 enable = isMainText()
2946 && cur.buffer()->text().getTocLevel(cur.pit()) != Layout::NOT_IN_TOC;
2949 case LFUN_NEWLINE_INSERT:
2950 // LaTeX restrictions (labels or empty par)
2951 enable = !cur.paragraph().isPassThru()
2952 && cur.pos() > cur.paragraph().beginOfBody();
2955 case LFUN_SEPARATOR_INSERT:
2956 // Always enabled for now
2960 case LFUN_TAB_INSERT:
2961 case LFUN_TAB_DELETE:
2962 enable = cur.paragraph().isPassThru();
2965 case LFUN_SET_GRAPHICS_GROUP: {
2966 InsetGraphics * ins = graphics::getCurrentGraphicsInset(cur);
2970 flag.setOnOff(to_utf8(cmd.argument()) == ins->getParams().groupId);
2974 case LFUN_NEWPAGE_INSERT:
2975 // not allowed in description items
2976 code = NEWPAGE_CODE;
2977 enable = !inDescriptionItem(cur);
2980 case LFUN_DATE_INSERT: {
2981 string const format = cmd.argument().empty()
2982 ? lyxrc.date_insert_format : to_utf8(cmd.argument());
2983 enable = support::os::is_valid_strftime(format);
2988 enable = !cur.paragraph().isPassThru();
2989 flag.setOnOff(cmd.getArg(0) == cur.real_current_font.language()->lang());
2992 case LFUN_PARAGRAPH_BREAK:
2993 enable = cur.inset().getLayout().isMultiPar();
2996 case LFUN_SPELLING_ADD:
2997 case LFUN_SPELLING_IGNORE:
2998 case LFUN_SPELLING_REMOVE:
2999 enable = theSpellChecker();
3003 enable = !cur.inset().forcePlainLayout();
3006 case LFUN_ENVIRONMENT_SPLIT: {
3007 if (cmd.argument() == "outer") {
3008 // check if we have an environment in our nesting hierarchy
3010 depth_type const current_depth = cur.paragraph().params().depth();
3011 pit_type pit = cur.pit();
3012 Paragraph cpar = pars_[pit];
3014 if (pit == 0 || cpar.params().depth() == 0)
3018 if (cpar.params().depth() < current_depth)
3019 res = cpar.layout().isEnvironment();
3024 else if (cur.paragraph().layout().isEnvironment()) {
3032 case LFUN_LAYOUT_PARAGRAPH:
3033 case LFUN_PARAGRAPH_PARAMS:
3034 case LFUN_PARAGRAPH_PARAMS_APPLY:
3035 case LFUN_PARAGRAPH_UPDATE:
3036 enable = cur.inset().allowParagraphCustomization();
3039 // FIXME: why are accent lfuns forbidden with pass_thru layouts?
3040 case LFUN_ACCENT_ACUTE:
3041 case LFUN_ACCENT_BREVE:
3042 case LFUN_ACCENT_CARON:
3043 case LFUN_ACCENT_CEDILLA:
3044 case LFUN_ACCENT_CIRCLE:
3045 case LFUN_ACCENT_CIRCUMFLEX:
3046 case LFUN_ACCENT_DOT:
3047 case LFUN_ACCENT_GRAVE:
3048 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
3049 case LFUN_ACCENT_MACRON:
3050 case LFUN_ACCENT_OGONEK:
3051 case LFUN_ACCENT_TIE:
3052 case LFUN_ACCENT_TILDE:
3053 case LFUN_ACCENT_UMLAUT:
3054 case LFUN_ACCENT_UNDERBAR:
3055 case LFUN_ACCENT_UNDERDOT:
3056 case LFUN_FONT_DEFAULT:
3057 case LFUN_FONT_FRAK:
3058 case LFUN_FONT_SIZE:
3059 case LFUN_FONT_STATE:
3060 case LFUN_FONT_UNDERLINE:
3061 case LFUN_FONT_STRIKEOUT:
3062 case LFUN_FONT_UNDERUNDERLINE:
3063 case LFUN_FONT_UNDERWAVE:
3064 case LFUN_TEXTSTYLE_APPLY:
3065 case LFUN_TEXTSTYLE_UPDATE:
3066 enable = !cur.paragraph().isPassThru();
3069 case LFUN_WORD_DELETE_FORWARD:
3070 case LFUN_WORD_DELETE_BACKWARD:
3071 case LFUN_LINE_DELETE_FORWARD:
3072 case LFUN_WORD_FORWARD:
3073 case LFUN_WORD_BACKWARD:
3074 case LFUN_WORD_RIGHT:
3075 case LFUN_WORD_LEFT:
3076 case LFUN_CHAR_FORWARD:
3077 case LFUN_CHAR_FORWARD_SELECT:
3078 case LFUN_CHAR_BACKWARD:
3079 case LFUN_CHAR_BACKWARD_SELECT:
3080 case LFUN_CHAR_LEFT:
3081 case LFUN_CHAR_LEFT_SELECT:
3082 case LFUN_CHAR_RIGHT:
3083 case LFUN_CHAR_RIGHT_SELECT:
3085 case LFUN_UP_SELECT:
3087 case LFUN_DOWN_SELECT:
3088 case LFUN_PARAGRAPH_UP_SELECT:
3089 case LFUN_PARAGRAPH_DOWN_SELECT:
3090 case LFUN_LINE_BEGIN_SELECT:
3091 case LFUN_LINE_END_SELECT:
3092 case LFUN_WORD_FORWARD_SELECT:
3093 case LFUN_WORD_BACKWARD_SELECT:
3094 case LFUN_WORD_RIGHT_SELECT:
3095 case LFUN_WORD_LEFT_SELECT:
3096 case LFUN_WORD_SELECT:
3097 case LFUN_SECTION_SELECT:
3098 case LFUN_BUFFER_BEGIN:
3099 case LFUN_BUFFER_END:
3100 case LFUN_BUFFER_BEGIN_SELECT:
3101 case LFUN_BUFFER_END_SELECT:
3102 case LFUN_INSET_BEGIN:
3103 case LFUN_INSET_END:
3104 case LFUN_INSET_BEGIN_SELECT:
3105 case LFUN_INSET_END_SELECT:
3106 case LFUN_PARAGRAPH_UP:
3107 case LFUN_PARAGRAPH_DOWN:
3108 case LFUN_LINE_BEGIN:
3110 case LFUN_CHAR_DELETE_FORWARD:
3111 case LFUN_CHAR_DELETE_BACKWARD:
3112 case LFUN_WORD_UPCASE:
3113 case LFUN_WORD_LOWCASE:
3114 case LFUN_WORD_CAPITALIZE:
3115 case LFUN_CHARS_TRANSPOSE:
3116 case LFUN_SERVER_GET_XY:
3117 case LFUN_SERVER_SET_XY:
3118 case LFUN_SERVER_GET_LAYOUT:
3119 case LFUN_SELF_INSERT:
3120 case LFUN_UNICODE_INSERT:
3121 case LFUN_THESAURUS_ENTRY:
3123 case LFUN_SERVER_GET_STATISTICS:
3124 // these are handled in our dispatch()
3128 case LFUN_INSET_INSERT: {
3129 string const type = cmd.getArg(0);
3130 if (type == "toc") {
3132 // not allowed in description items
3133 //FIXME: couldn't this be merged in Inset::insetAllowed()?
3134 enable = !inDescriptionItem(cur);
3147 || !cur.inset().insetAllowed(code)
3148 || (cur.paragraph().layout().pass_thru && !allow_in_passthru)))
3151 flag.setEnabled(enable);
3156 void Text::pasteString(Cursor & cur, docstring const & clip,
3159 if (!clip.empty()) {
3162 insertStringAsParagraphs(cur, clip, cur.current_font);
3164 insertStringAsLines(cur, clip, cur.current_font);
3169 // FIXME: an item inset would make things much easier.
3170 bool Text::inDescriptionItem(Cursor & cur) const
3172 Paragraph & par = cur.paragraph();
3173 pos_type const pos = cur.pos();
3174 pos_type const body_pos = par.beginOfBody();
3176 if (par.layout().latextype != LATEX_LIST_ENVIRONMENT
3177 && (par.layout().latextype != LATEX_ITEM_ENVIRONMENT
3178 || par.layout().margintype != MARGIN_FIRST_DYNAMIC))
3181 return (pos < body_pos
3183 && (pos == 0 || par.getChar(pos - 1) != ' ')));