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"
29 #include "CutAndPaste.h"
30 #include "DispatchResult.h"
31 #include "ErrorList.h"
33 #include "FuncRequest.h"
34 #include "InsetList.h"
38 #include "LyXAction.h"
42 #include "Paragraph.h"
43 #include "paragraph_funcs.h"
44 #include "ParagraphParameters.h"
45 #include "TextClass.h"
46 #include "TextMetrics.h"
49 #include "frontends/Application.h"
50 #include "frontends/Clipboard.h"
51 #include "frontends/LyXView.h"
52 #include "frontends/Selection.h"
53 #include "frontends/WorkArea.h"
55 #include "insets/InsetCollapsable.h"
56 #include "insets/InsetCommand.h"
57 #include "insets/InsetExternal.h"
58 #include "insets/InsetFloatList.h"
59 #include "insets/InsetGraphics.h"
60 #include "insets/InsetGraphicsParams.h"
61 #include "insets/InsetNewline.h"
62 #include "insets/InsetQuotes.h"
63 #include "insets/InsetSpecialChar.h"
64 #include "insets/InsetText.h"
66 #include "support/convert.h"
67 #include "support/debug.h"
68 #include "support/gettext.h"
69 #include "support/lstrings.h"
70 #include "support/lyxtime.h"
72 #include "mathed/InsetMathHull.h"
73 #include "mathed/MathMacroTemplate.h"
75 #include <boost/next_prior.hpp>
81 using namespace lyx::support;
85 using cap::copySelection;
86 using cap::cutSelection;
87 using cap::pasteFromStack;
88 using cap::pasteClipboardText;
89 using cap::pasteClipboardGraphics;
90 using cap::replaceSelection;
91 using cap::grabAndEraseSelection;
92 using cap::selClearOrDel;
95 static Font freefont(ignore_font, ignore_language);
96 static bool toggleall = false;
98 static void toggleAndShow(Cursor & cur, Text * text,
99 Font const & font, bool toggleall = true)
101 text->toggleFree(cur, font, toggleall);
103 if (font.language() != ignore_language ||
104 font.fontInfo().number() != FONT_IGNORE) {
105 TextMetrics const & tm = cur.bv().textMetrics(text);
106 if (cur.boundary() != tm.isRTLBoundary(cur.pit(), cur.pos(),
107 cur.real_current_font))
108 text->setCursor(cur, cur.pit(), cur.pos(),
109 false, !cur.boundary());
114 static void moveCursor(Cursor & cur, bool selecting)
116 if (selecting || cur.mark())
121 static void finishChange(Cursor & cur, bool selecting)
124 moveCursor(cur, selecting);
128 static void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
131 docstring sel = cur.selectionAsString(false);
133 // It may happen that sel is empty but there is a selection
134 replaceSelection(cur);
136 // Is this a valid formula?
140 #ifdef ENABLE_ASSERTIONS
141 const int old_pos = cur.pos();
143 cur.insert(new InsetMathHull(hullSimple));
144 #ifdef ENABLE_ASSERTIONS
145 LASSERT(old_pos == cur.pos(), /**/);
147 cur.nextInset()->edit(cur, true);
148 // don't do that also for LFUN_MATH_MODE
149 // unless you want end up with always changing
150 // to mathrm when opening an inlined inset --
151 // I really hate "LyXfunc overloading"...
153 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
154 // Avoid an unnecessary undo step if cmd.argument
156 if (!cmd.argument().empty())
157 cur.dispatch(FuncRequest(LFUN_MATH_INSERT,
160 // create a macro if we see "\\newcommand"
161 // somewhere, and an ordinary formula
163 if (sel.find(from_ascii("\\newcommand")) == string::npos
164 && sel.find(from_ascii("\\newlyxcommand")) == string::npos
165 && sel.find(from_ascii("\\def")) == string::npos)
167 InsetMathHull * formula = new InsetMathHull;
168 string const selstr = to_utf8(sel);
169 istringstream is(selstr);
172 if (!formula->readQuiet(lex)) {
173 // No valid formula, let's try with delims
174 is.str("$" + selstr + "$");
176 if (!formula->readQuiet(lex)) {
177 // Still not valid, leave it as is
186 cur.insert(new MathMacroTemplate(sel));
190 cur.message(from_utf8(N_("Math editor mode")));
192 cur.message(from_utf8(N_("No valid math formula")));
196 void regexpDispatch(Cursor & cur, FuncRequest const & cmd)
198 BOOST_ASSERT(cmd.action == LFUN_REGEXP_MODE);
199 if (cur.inRegexped()) {
200 cur.message(_("Already in regexp mode"));
204 docstring const save_selection = grabAndEraseSelection(cur);
206 // replaceSelection(cur);
208 cur.insert(new InsetMathHull(hullRegexp));
209 cur.nextInset()->edit(cur, true);
210 cur.niceInsert(save_selection);
212 cur.message(_("Regexp editor mode"));
216 static void specialChar(Cursor & cur, InsetSpecialChar::Kind kind)
219 cap::replaceSelection(cur);
220 cur.insert(new InsetSpecialChar(kind));
225 static bool doInsertInset(Cursor & cur, Text * text,
226 FuncRequest const & cmd, bool edit, bool pastesel)
228 Buffer & buffer = cur.bv().buffer();
229 BufferParams const & bparams = buffer.params();
230 Inset * inset = createInset(buffer, cmd);
234 if (InsetCollapsable * ci = inset->asInsetCollapsable())
235 ci->setLayout(bparams);
238 if (cmd.action == LFUN_INDEX_INSERT) {
239 docstring ds = subst(text->getStringToIndex(cur), '\n', ' ');
240 text->insertInset(cur, inset);
242 inset->edit(cur, true);
243 // Now put this into inset
244 static_cast<InsetCollapsable *>(inset)->
245 text().insertStringAsParagraphs(cur, ds);
250 if (cur.selection()) {
251 cutSelection(cur, false, pastesel);
252 cur.clearSelection();
255 text->insertInset(cur, inset);
258 inset->edit(cur, true);
260 if (!gotsel || !pastesel)
263 pasteFromStack(cur, cur.buffer()->errorList("Paste"), 0);
264 cur.buffer()->errors("Paste");
265 cur.clearSelection(); // bug 393
267 InsetText * insetText = dynamic_cast<InsetText *>(inset);
268 if (insetText && (!insetText->allowMultiPar() || cur.lastpit() == 0)) {
269 // reset first par to default
270 cur.text()->paragraphs().begin()
271 ->setPlainOrDefaultLayout(bparams.documentClass());
274 // Merge multiple paragraphs -- hack
275 while (cur.lastpit() > 0)
276 mergeParagraph(bparams, cur.text()->paragraphs(), 0);
277 cur.leaveInset(*inset);
279 cur.leaveInset(*inset);
280 // reset surrounding par to default
281 DocumentClass const & dc = bparams.documentClass();
282 docstring const layoutname = inset->usePlainLayout()
283 ? dc.plainLayoutName()
284 : dc.defaultLayoutName();
285 text->setLayout(cur, layoutname);
292 string const freefont2string()
294 return freefont.toString(toggleall);
298 /// the type of outline operation
300 OutlineUp, // Move this header with text down
301 OutlineDown, // Move this header with text up
302 OutlineIn, // Make this header deeper
303 OutlineOut // Make this header shallower
307 static void outline(OutlineOp mode, Cursor & cur)
309 Buffer & buf = *cur.buffer();
310 pit_type & pit = cur.pit();
311 ParagraphList & pars = buf.text().paragraphs();
312 ParagraphList::iterator bgn = pars.begin();
313 // The first paragraph of the area to be copied:
314 ParagraphList::iterator start = boost::next(bgn, pit);
315 // The final paragraph of area to be copied:
316 ParagraphList::iterator finish = start;
317 ParagraphList::iterator end = pars.end();
319 DocumentClass const & tc = buf.params().documentClass();
321 int const thistoclevel = start->layout().toclevel;
324 // Move out (down) from this section header
327 // Seek the one (on same level) below
328 for (; finish != end; ++finish) {
329 toclevel = finish->layout().toclevel;
330 if (toclevel != Layout::NOT_IN_TOC && toclevel <= thistoclevel) {
337 if (start == pars.begin())
340 ParagraphList::iterator dest = start;
341 // Move out (up) from this header
344 // Search previous same-level header above
347 toclevel = dest->layout().toclevel;
349 && (toclevel == Layout::NOT_IN_TOC
350 || toclevel > thistoclevel));
351 // Not found; do nothing
352 if (toclevel == Layout::NOT_IN_TOC || toclevel > thistoclevel)
354 pit_type const newpit = distance(bgn, dest);
355 pit_type const len = distance(start, finish);
356 pit_type const deletepit = pit + len;
357 buf.undo().recordUndo(cur, ATOMIC_UNDO, newpit, deletepit - 1);
358 pars.insert(dest, start, finish);
359 start = boost::next(pars.begin(), deletepit);
361 pars.erase(start, finish);
368 // Go one down from *this* header:
369 ParagraphList::iterator dest = boost::next(finish, 1);
370 // Go further down to find header to insert in front of:
371 for (; dest != end; ++dest) {
372 toclevel = dest->layout().toclevel;
373 if (toclevel != Layout::NOT_IN_TOC
374 && toclevel <= thistoclevel) {
378 // One such was found:
379 pit_type newpit = distance(bgn, dest);
380 pit_type const len = distance(start, finish);
381 buf.undo().recordUndo(cur, ATOMIC_UNDO, pit, newpit - 1);
382 pars.insert(dest, start, finish);
383 start = boost::next(bgn, pit);
385 pars.erase(start, finish);
389 pit_type const len = distance(start, finish);
390 buf.undo().recordUndo(cur, ATOMIC_UNDO, pit, pit + len - 1);
391 for (; start != finish; ++start) {
392 toclevel = start->layout().toclevel;
393 if (toclevel == Layout::NOT_IN_TOC)
395 DocumentClass::const_iterator lit = tc.begin();
396 DocumentClass::const_iterator len = tc.end();
397 for (; lit != len; ++lit) {
398 if (lit->toclevel == toclevel + 1 &&
399 start->layout().labeltype == lit->labeltype) {
400 start->setLayout(*lit);
408 pit_type const len = distance(start, finish);
409 buf.undo().recordUndo(cur, ATOMIC_UNDO, pit, pit + len - 1);
410 for (; start != finish; ++start) {
411 toclevel = start->layout().toclevel;
412 if (toclevel == Layout::NOT_IN_TOC)
414 DocumentClass::const_iterator lit = tc.begin();
415 DocumentClass::const_iterator len = tc.end();
416 for (; lit != len; ++lit) {
417 if (lit->toclevel == toclevel - 1 &&
418 start->layout().labeltype == lit->labeltype) {
419 start->setLayout(*lit);
430 void Text::number(Cursor & cur)
432 FontInfo font = ignore_font;
433 font.setNumber(FONT_TOGGLE);
434 toggleAndShow(cur, this, Font(font, ignore_language));
438 bool Text::isRTL(Buffer const & buffer, Paragraph const & par) const
440 return par.isRTL(buffer.params());
444 void Text::dispatch(Cursor & cur, FuncRequest & cmd)
446 LYXERR(Debug::ACTION, "Text::dispatch: cmd: " << cmd);
448 BufferView * bv = &cur.bv();
449 TextMetrics & tm = bv->textMetrics(this);
450 if (!tm.contains(cur.pit())) {
451 lyx::dispatch(FuncRequest(LFUN_SCREEN_RECENTER));
452 tm = bv->textMetrics(this);
455 // FIXME: We use the update flag to indicates wether a singlePar or a
456 // full screen update is needed. We reset it here but shall we restore it
460 LASSERT(cur.text() == this, /**/);
461 CursorSlice oldTopSlice = cur.top();
462 bool oldBoundary = cur.boundary();
463 bool sel = cur.selection();
464 // Signals that, even if needsUpdate == false, an update of the
465 // cursor paragraph is required
466 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
467 LyXAction::SingleParUpdate);
468 // Signals that a full-screen update is required
469 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
470 LyXAction::NoUpdate) || singleParUpdate);
472 switch (cmd.action) {
474 case LFUN_PARAGRAPH_MOVE_DOWN: {
475 pit_type const pit = cur.pit();
476 recUndo(cur, pit, pit + 1);
478 swap(pars_[pit], pars_[pit + 1]);
479 cur.buffer()->updateLabels();
485 case LFUN_PARAGRAPH_MOVE_UP: {
486 pit_type const pit = cur.pit();
487 recUndo(cur, pit - 1, pit);
489 swap(pars_[pit], pars_[pit - 1]);
490 cur.buffer()->updateLabels();
496 case LFUN_APPENDIX: {
497 Paragraph & par = cur.paragraph();
498 bool start = !par.params().startOfAppendix();
500 // FIXME: The code below only makes sense at top level.
501 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
502 // ensure that we have only one start_of_appendix in this document
503 // FIXME: this don't work for multipart document!
504 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
505 if (pars_[tmp].params().startOfAppendix()) {
507 pars_[tmp].params().startOfAppendix(false);
513 par.params().startOfAppendix(start);
515 // we can set the refreshing parameters now
516 cur.buffer()->updateLabels();
520 case LFUN_WORD_DELETE_FORWARD:
522 cutSelection(cur, true, false);
524 deleteWordForward(cur);
525 finishChange(cur, false);
528 case LFUN_WORD_DELETE_BACKWARD:
530 cutSelection(cur, true, false);
532 deleteWordBackward(cur);
533 finishChange(cur, false);
536 case LFUN_LINE_DELETE:
538 cutSelection(cur, true, false);
540 tm.deleteLineForward(cur);
541 finishChange(cur, false);
544 case LFUN_BUFFER_BEGIN:
545 case LFUN_BUFFER_BEGIN_SELECT:
546 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
547 if (cur.depth() == 1)
548 needsUpdate |= cursorTop(cur);
551 cur.updateFlags(Update::FitCursor);
554 case LFUN_BUFFER_END:
555 case LFUN_BUFFER_END_SELECT:
556 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
557 if (cur.depth() == 1)
558 needsUpdate |= cursorBottom(cur);
561 cur.updateFlags(Update::FitCursor);
564 case LFUN_CHAR_FORWARD:
565 case LFUN_CHAR_FORWARD_SELECT:
566 //LYXERR0(" LFUN_CHAR_FORWARD[SEL]:\n" << cur);
567 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
568 needsUpdate |= cursorForward(cur);
570 if (!needsUpdate && oldTopSlice == cur.top()
571 && cur.boundary() == oldBoundary) {
573 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
577 case LFUN_CHAR_BACKWARD:
578 case LFUN_CHAR_BACKWARD_SELECT:
579 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
580 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
581 needsUpdate |= cursorBackward(cur);
583 if (!needsUpdate && oldTopSlice == cur.top()
584 && cur.boundary() == oldBoundary) {
586 cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
591 case LFUN_CHAR_LEFT_SELECT:
592 if (lyxrc.visual_cursor) {
593 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_LEFT_SELECT);
594 needsUpdate |= cursorVisLeft(cur);
595 if (!needsUpdate && oldTopSlice == cur.top()
596 && cur.boundary() == oldBoundary) {
598 cmd = FuncRequest(LFUN_FINISHED_LEFT);
601 if (reverseDirectionNeeded(cur)) {
602 cmd.action = cmd.action == LFUN_CHAR_LEFT_SELECT ?
603 LFUN_CHAR_FORWARD_SELECT : LFUN_CHAR_FORWARD;
605 cmd.action = cmd.action == LFUN_CHAR_LEFT_SELECT ?
606 LFUN_CHAR_BACKWARD_SELECT : LFUN_CHAR_BACKWARD;
613 case LFUN_CHAR_RIGHT:
614 case LFUN_CHAR_RIGHT_SELECT:
615 if (lyxrc.visual_cursor) {
616 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_RIGHT_SELECT);
617 needsUpdate |= cursorVisRight(cur);
618 if (!needsUpdate && oldTopSlice == cur.top()
619 && cur.boundary() == oldBoundary) {
621 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
624 if (reverseDirectionNeeded(cur)) {
625 cmd.action = cmd.action == LFUN_CHAR_RIGHT_SELECT ?
626 LFUN_CHAR_BACKWARD_SELECT : LFUN_CHAR_BACKWARD;
628 cmd.action = cmd.action == LFUN_CHAR_RIGHT_SELECT ?
629 LFUN_CHAR_FORWARD_SELECT : LFUN_CHAR_FORWARD;
638 case LFUN_DOWN_SELECT:
641 // stop/start the selection
642 bool select = cmd.action == LFUN_DOWN_SELECT ||
643 cmd.action == LFUN_UP_SELECT;
645 // move cursor up/down
646 bool up = cmd.action == LFUN_UP_SELECT || cmd.action == LFUN_UP;
647 bool const atFirstOrLastRow = cur.atFirstOrLastRow(up);
649 if (!atFirstOrLastRow) {
650 needsUpdate |= cur.selHandle(select);
651 cur.selHandle(select);
652 cur.upDownInText(up, needsUpdate);
653 needsUpdate |= cur.beforeDispatchCursor().inMathed();
655 // if the cursor cannot be moved up or down do not remove
656 // the selection right now, but wait for the next dispatch.
658 needsUpdate |= cur.selHandle(select);
659 cur.upDownInText(up, needsUpdate);
666 case LFUN_PARAGRAPH_UP:
667 case LFUN_PARAGRAPH_UP_SELECT:
668 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
669 needsUpdate |= cursorUpParagraph(cur);
672 case LFUN_PARAGRAPH_DOWN:
673 case LFUN_PARAGRAPH_DOWN_SELECT:
674 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
675 needsUpdate |= cursorDownParagraph(cur);
678 case LFUN_LINE_BEGIN:
679 case LFUN_LINE_BEGIN_SELECT:
680 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
681 needsUpdate |= tm.cursorHome(cur);
685 case LFUN_LINE_END_SELECT:
686 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
687 needsUpdate |= tm.cursorEnd(cur);
690 case LFUN_WORD_RIGHT:
691 case LFUN_WORD_RIGHT_SELECT:
692 if (lyxrc.visual_cursor) {
693 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_RIGHT_SELECT);
694 needsUpdate |= cursorVisRightOneWord(cur);
695 if (!needsUpdate && oldTopSlice == cur.top()
696 && cur.boundary() == oldBoundary) {
698 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
701 if (reverseDirectionNeeded(cur)) {
702 cmd.action = cmd.action == LFUN_WORD_RIGHT_SELECT ?
703 LFUN_WORD_BACKWARD_SELECT : LFUN_WORD_BACKWARD;
705 cmd.action = cmd.action == LFUN_WORD_RIGHT_SELECT ?
706 LFUN_WORD_FORWARD_SELECT : LFUN_WORD_FORWARD;
713 case LFUN_WORD_FORWARD:
714 case LFUN_WORD_FORWARD_SELECT:
715 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
716 needsUpdate |= cursorForwardOneWord(cur);
720 case LFUN_WORD_LEFT_SELECT:
721 if (lyxrc.visual_cursor) {
722 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_LEFT_SELECT);
723 needsUpdate |= cursorVisLeftOneWord(cur);
724 if (!needsUpdate && oldTopSlice == cur.top()
725 && cur.boundary() == oldBoundary) {
727 cmd = FuncRequest(LFUN_FINISHED_LEFT);
730 if (reverseDirectionNeeded(cur)) {
731 cmd.action = cmd.action == LFUN_WORD_LEFT_SELECT ?
732 LFUN_WORD_FORWARD_SELECT : LFUN_WORD_FORWARD;
734 cmd.action = cmd.action == LFUN_WORD_LEFT_SELECT ?
735 LFUN_WORD_BACKWARD_SELECT : LFUN_WORD_BACKWARD;
742 case LFUN_WORD_BACKWARD:
743 case LFUN_WORD_BACKWARD_SELECT:
744 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
745 needsUpdate |= cursorBackwardOneWord(cur);
748 case LFUN_WORD_SELECT: {
749 selectWord(cur, WHOLE_WORD);
750 finishChange(cur, true);
754 case LFUN_NEWLINE_INSERT: {
755 InsetNewlineParams inp;
756 docstring arg = cmd.argument();
757 // this avoids a double undo
758 // FIXME: should not be needed, ideally
759 if (!cur.selection())
761 cap::replaceSelection(cur);
762 if (arg == "linebreak")
763 inp.kind = InsetNewlineParams::LINEBREAK;
765 inp.kind = InsetNewlineParams::NEWLINE;
766 cur.insert(new InsetNewline(inp));
768 moveCursor(cur, false);
772 case LFUN_CHAR_DELETE_FORWARD:
773 if (!cur.selection()) {
774 if (cur.pos() == cur.paragraph().size())
775 // Par boundary, force full-screen update
776 singleParUpdate = false;
777 needsUpdate |= erase(cur);
779 // It is possible to make it a lot faster still
780 // just comment out the line below...
782 cutSelection(cur, true, false);
783 singleParUpdate = false;
785 moveCursor(cur, false);
788 case LFUN_CHAR_DELETE_BACKWARD:
789 if (!cur.selection()) {
790 if (bv->getIntl().getTransManager().backspace()) {
791 // Par boundary, full-screen update
793 singleParUpdate = false;
794 needsUpdate |= backspace(cur);
796 // It is possible to make it a lot faster still
797 // just comment out the line below...
800 cutSelection(cur, true, false);
801 singleParUpdate = false;
805 case LFUN_BREAK_PARAGRAPH:
806 cap::replaceSelection(cur);
807 breakParagraph(cur, cmd.argument() == "inverse");
812 // With the creation of LFUN_PARAGRAPH_PARAMS, this is now redundant,
813 // as its duties can be performed there. Should it be removed??
814 // FIXME For now, it can just dispatch LFUN_PARAGRAPH_PARAMS...
815 case LFUN_PARAGRAPH_SPACING: {
816 Paragraph & par = cur.paragraph();
817 Spacing::Space cur_spacing = par.params().spacing().getSpace();
818 string cur_value = "1.0";
819 if (cur_spacing == Spacing::Other)
820 cur_value = par.params().spacing().getValueAsString();
822 istringstream is(to_utf8(cmd.argument()));
825 Spacing::Space new_spacing = cur_spacing;
826 string new_value = cur_value;
828 lyxerr << "Missing argument to `paragraph-spacing'"
830 } else if (tmp == "single") {
831 new_spacing = Spacing::Single;
832 } else if (tmp == "onehalf") {
833 new_spacing = Spacing::Onehalf;
834 } else if (tmp == "double") {
835 new_spacing = Spacing::Double;
836 } else if (tmp == "other") {
837 new_spacing = Spacing::Other;
838 string tmpval = "0.0";
840 lyxerr << "new_value = " << tmpval << endl;
843 } else if (tmp == "default") {
844 new_spacing = Spacing::Default;
846 lyxerr << to_utf8(_("Unknown spacing argument: "))
847 << to_utf8(cmd.argument()) << endl;
849 if (cur_spacing != new_spacing || cur_value != new_value)
850 par.params().spacing(Spacing(new_spacing, new_value));
854 case LFUN_INSET_INSERT: {
857 // We have to avoid triggering InstantPreview loading
858 // before inserting into the document. See bug #5626.
859 bool loaded = bv->buffer().isFullyLoaded();
860 bv->buffer().setFullyLoaded(false);
861 Inset * inset = createInset(bv->buffer(), cmd);
862 bv->buffer().setFullyLoaded(loaded);
865 // FIXME (Abdel 01/02/2006):
866 // What follows would be a partial fix for bug 2154:
867 // http://bugzilla.lyx.org/show_bug.cgi?id=2154
868 // This automatically put the label inset _after_ a
869 // numbered section. It should be possible to extend the mechanism
870 // to any kind of LateX environement.
871 // The correct way to fix that bug would be at LateX generation.
872 // I'll let the code here for reference as it could be used for some
873 // other feature like "automatic labelling".
875 Paragraph & par = pars_[cur.pit()];
876 if (inset->lyxCode() == LABEL_CODE
877 && par.layout().labeltype == LABEL_COUNTER) {
878 // Go to the end of the paragraph
879 // Warning: Because of Change-Tracking, the last
880 // position is 'size()' and not 'size()-1':
881 cur.pos() = par.size();
882 // Insert a new paragraph
883 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
888 cutSelection(cur, true, false);
892 // trigger InstantPreview now
893 if (inset->lyxCode() == EXTERNAL_CODE) {
894 InsetExternal & ins =
895 static_cast<InsetExternal &>(*inset);
903 case LFUN_INSET_DISSOLVE: {
904 // first, try if there's an inset at cursor
905 // FIXME: this first part should be moved to
906 // a LFUN_NEXT_INSET_DISSOLVE, or be called via
907 // some generic "next-inset inset-dissolve"
908 Inset * inset = cur.nextInset();
909 if (inset && inset->isActive()) {
911 tmpcur.pushBackward(*inset);
912 inset->dispatch(tmpcur, cmd);
913 if (tmpcur.result().dispatched()) {
918 // if it did not work, try the underlying inset
919 if (dissolveInset(cur)) {
923 // if it did not work, do nothing.
927 case LFUN_INSET_SETTINGS: {
928 Inset & inset = cur.inset();
929 if (cmd.getArg(0) == insetName(inset.lyxCode())) {
930 // This inset dialog has been explicitely requested.
931 inset.showInsetDialog(bv);
934 // else, if there is an inset at the cursor, access this
935 Inset * next_inset = cur.nextInset();
937 next_inset->showInsetDialog(bv);
940 // if not then access the underlying inset.
941 inset.showInsetDialog(bv);
945 case LFUN_SET_GRAPHICS_GROUP: {
946 InsetGraphics * ins = graphics::getCurrentGraphicsInset(cur);
952 string id = to_utf8(cmd.argument());
953 string grp = graphics::getGroupParams(bv->buffer(), id);
954 InsetGraphicsParams tmp, inspar = ins->getParams();
957 inspar.groupId = to_utf8(cmd.argument());
959 InsetGraphics::string2params(grp, bv->buffer(), tmp);
960 tmp.filename = inspar.filename;
964 ins->setParams(inspar);
967 case LFUN_SPACE_INSERT:
968 if (cur.paragraph().layout().free_spacing)
969 insertChar(cur, ' ');
971 doInsertInset(cur, this, cmd, false, false);
974 moveCursor(cur, false);
977 case LFUN_SPECIALCHAR_INSERT: {
978 string const name = to_utf8(cmd.argument());
979 if (name == "hyphenation")
980 specialChar(cur, InsetSpecialChar::HYPHENATION);
981 else if (name == "ligature-break")
982 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
983 else if (name == "slash")
984 specialChar(cur, InsetSpecialChar::SLASH);
985 else if (name == "nobreakdash")
986 specialChar(cur, InsetSpecialChar::NOBREAKDASH);
987 else if (name == "dots")
988 specialChar(cur, InsetSpecialChar::LDOTS);
989 else if (name == "end-of-sentence")
990 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
991 else if (name == "menu-separator")
992 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
993 else if (name.empty())
994 lyxerr << "LyX function 'specialchar-insert' needs an argument." << endl;
996 lyxerr << "Wrong argument for LyX function 'specialchar-insert'." << endl;
1000 case LFUN_WORD_UPCASE:
1001 changeCase(cur, text_uppercase);
1004 case LFUN_WORD_LOWCASE:
1005 changeCase(cur, text_lowercase);
1008 case LFUN_WORD_CAPITALIZE:
1009 changeCase(cur, text_capitalization);
1012 case LFUN_CHARS_TRANSPOSE:
1013 charsTranspose(cur);
1017 cur.message(_("Paste"));
1018 LASSERT(cur.selBegin().idx() == cur.selEnd().idx(), /**/);
1019 cap::replaceSelection(cur);
1021 // without argument?
1022 string const arg = to_utf8(cmd.argument());
1024 if (theClipboard().isInternal())
1025 pasteFromStack(cur, bv->buffer().errorList("Paste"), 0);
1026 else if (theClipboard().hasGraphicsContents()
1027 && !theClipboard().hasTextContents())
1028 pasteClipboardGraphics(cur, bv->buffer().errorList("Paste"));
1030 pasteClipboardText(cur, bv->buffer().errorList("Paste"));
1031 } else if (isStrUnsignedInt(arg)) {
1032 // we have a numerical argument
1033 pasteFromStack(cur, bv->buffer().errorList("Paste"),
1034 convert<unsigned int>(arg));
1036 Clipboard::GraphicsType type = Clipboard::AnyGraphicsType;
1038 type = Clipboard::PdfGraphicsType;
1039 else if (arg == "png")
1040 type = Clipboard::PngGraphicsType;
1041 else if (arg == "jpeg")
1042 type = Clipboard::JpegGraphicsType;
1043 else if (arg == "linkback")
1044 type = Clipboard::LinkBackGraphicsType;
1046 LASSERT(false, /**/);
1048 pasteClipboardGraphics(cur, bv->buffer().errorList("Paste"), type);
1051 bv->buffer().errors("Paste");
1052 cur.clearSelection(); // bug 393
1058 cutSelection(cur, true, true);
1059 cur.message(_("Cut"));
1064 cur.message(_("Copy"));
1067 case LFUN_SERVER_GET_XY:
1068 cur.message(from_utf8(
1069 convert<string>(tm.cursorX(cur.top(), cur.boundary()))
1070 + ' ' + convert<string>(tm.cursorY(cur.top(), cur.boundary()))));
1073 case LFUN_SERVER_SET_XY: {
1076 istringstream is(to_utf8(cmd.argument()));
1079 lyxerr << "SETXY: Could not parse coordinates in '"
1080 << to_utf8(cmd.argument()) << endl;
1082 tm.setCursorFromCoordinates(cur, x, y);
1086 case LFUN_SERVER_GET_LAYOUT:
1087 cur.message(cur.paragraph().layout().name());
1091 docstring layout = cmd.argument();
1092 LYXERR(Debug::INFO, "LFUN_LAYOUT: (arg) " << to_utf8(layout));
1094 Paragraph const & para = cur.paragraph();
1095 docstring const old_layout = para.layout().name();
1096 DocumentClass const & tclass = bv->buffer().params().documentClass();
1099 layout = tclass.defaultLayoutName();
1101 if (para.forcePlainLayout())
1102 // in this case only the empty layout is allowed
1103 layout = tclass.plainLayoutName();
1104 else if (para.usePlainLayout()) {
1105 // in this case, default layout maps to empty layout
1106 if (layout == tclass.defaultLayoutName())
1107 layout = tclass.plainLayoutName();
1109 // otherwise, the empty layout maps to the default
1110 if (layout == tclass.plainLayoutName())
1111 layout = tclass.defaultLayoutName();
1114 bool hasLayout = tclass.hasLayout(layout);
1116 // If the entry is obsolete, use the new one instead.
1118 docstring const & obs = tclass[layout].obsoleted_by();
1124 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
1125 from_utf8(N_(" not known")));
1129 bool change_layout = (old_layout != layout);
1131 if (!change_layout && cur.selection() &&
1132 cur.selBegin().pit() != cur.selEnd().pit())
1134 pit_type spit = cur.selBegin().pit();
1135 pit_type epit = cur.selEnd().pit() + 1;
1136 while (spit != epit) {
1137 if (pars_[spit].layout().name() != old_layout) {
1138 change_layout = true;
1146 setLayout(cur, layout);
1151 case LFUN_CLIPBOARD_PASTE:
1152 cur.clearSelection();
1153 pasteClipboardText(cur, bv->buffer().errorList("Paste"),
1154 cmd.argument() == "paragraph");
1155 bv->buffer().errors("Paste");
1158 case LFUN_PRIMARY_SELECTION_PASTE:
1159 pasteString(cur, theSelection().get(),
1160 cmd.argument() == "paragraph");
1163 case LFUN_SELECTION_PASTE:
1164 // Copy the selection buffer to the clipboard stack,
1165 // because we want it to appear in the "Edit->Paste
1167 cap::copySelectionToStack();
1168 cap::pasteSelection(bv->cursor(), bv->buffer().errorList("Paste"));
1169 bv->buffer().errors("Paste");
1172 case LFUN_UNICODE_INSERT: {
1173 if (cmd.argument().empty())
1175 docstring hexstring = cmd.argument();
1176 if (isHex(hexstring)) {
1177 char_type c = hexToInt(hexstring);
1178 if (c >= 32 && c < 0x10ffff) {
1179 lyxerr << "Inserting c: " << c << endl;
1180 docstring s = docstring(1, c);
1181 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
1187 case LFUN_QUOTE_INSERT: {
1188 Paragraph & par = cur.paragraph();
1189 pos_type pos = cur.pos();
1190 BufferParams const & bufparams = bv->buffer().params();
1191 Layout const & style = par.layout();
1192 if (!style.pass_thru
1193 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
1194 // this avoids a double undo
1195 // FIXME: should not be needed, ideally
1196 if (!cur.selection())
1198 cap::replaceSelection(cur);
1203 else if (cur.prevInset() && cur.prevInset()->isSpace())
1206 c = par.getChar(pos - 1);
1207 string arg = to_utf8(cmd.argument());
1208 cur.insert(new InsetQuotes(bv->buffer(), c, (arg == "single")
1209 ? InsetQuotes::SingleQuotes : InsetQuotes::DoubleQuotes));
1213 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
1217 case LFUN_DATE_INSERT: {
1218 string const format = cmd.argument().empty()
1219 ? lyxrc.date_insert_format : to_utf8(cmd.argument());
1220 string const time = formatted_time(current_time(), format);
1221 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, time));
1225 case LFUN_MOUSE_TRIPLE:
1226 if (cmd.button() == mouse_button::button1) {
1235 case LFUN_MOUSE_DOUBLE:
1236 if (cmd.button() == mouse_button::button1) {
1237 selectWord(cur, WHOLE_WORD_STRICT);
1242 // Single-click on work area
1243 case LFUN_MOUSE_PRESS:
1244 // We are not marking a selection with the keyboard in any case.
1245 cur.bv().cursor().setMark(false);
1246 switch (cmd.button()) {
1247 case mouse_button::button1:
1249 if (!bv->mouseSetCursor(cur, cmd.argument() == "region-select"))
1250 cur.updateFlags(Update::SinglePar | Update::FitCursor);
1253 case mouse_button::button2:
1254 // Middle mouse pasting.
1255 bv->mouseSetCursor(cur);
1257 FuncRequest(LFUN_COMMAND_ALTERNATIVES,
1258 "selection-paste ; primary-selection-paste paragraph"));
1262 case mouse_button::button3: {
1263 Cursor const & bvcur = cur.bv().cursor();
1264 // Don't do anything if we right-click a
1265 // selection, a context menu will popup.
1266 if (bvcur.selection() && cur >= bvcur.selectionBegin()
1267 && cur < bvcur.selectionEnd()) {
1271 if (!bv->mouseSetCursor(cur, false))
1272 cur.updateFlags(Update::SinglePar | Update::FitCursor);
1278 } // switch (cmd.button())
1281 case LFUN_MOUSE_MOTION: {
1282 // Mouse motion with right or middle mouse do nothing for now.
1283 if (cmd.button() != mouse_button::button1) {
1287 // ignore motions deeper nested than the real anchor
1288 Cursor & bvcur = cur.bv().cursor();
1289 if (!bvcur.anchor_.hasPart(cur)) {
1293 CursorSlice old = bvcur.top();
1295 int const wh = bv->workHeight();
1296 int const y = max(0, min(wh - 1, cmd.y));
1298 tm.setCursorFromCoordinates(cur, cmd.x, y);
1299 cur.setTargetX(cmd.x);
1301 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1303 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1304 // This is to allow jumping over large insets
1305 if (cur.top() == old) {
1307 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1309 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1311 // We continue with our existing selection or start a new one, so don't
1312 // reset the anchor.
1313 bvcur.setCursor(cur);
1314 bvcur.setSelection(true);
1315 if (cur.top() == old) {
1316 // We didn't move one iota, so no need to update the screen.
1317 cur.updateFlags(Update::SinglePar | Update::FitCursor);
1324 case LFUN_MOUSE_RELEASE:
1325 switch (cmd.button()) {
1326 case mouse_button::button1:
1327 // Cursor was set at LFUN_MOUSE_PRESS or LFUN_MOUSE_MOTION time.
1328 // If there is a new selection, update persistent selection;
1329 // otherwise, single click does not clear persistent selection
1331 if (cur.selection()) {
1332 // Finish selection. If double click,
1333 // cur is moved to the end of word by
1334 // selectWord but bvcur is current
1336 cur.bv().cursor().setSelection();
1337 // We might have removed an empty but drawn selection
1338 // (probably a margin)
1339 cur.updateFlags(Update::SinglePar | Update::FitCursor);
1342 // FIXME: We could try to handle drag and drop of selection here.
1345 case mouse_button::button2:
1346 // Middle mouse pasting is handled at mouse press time,
1347 // see LFUN_MOUSE_PRESS.
1351 case mouse_button::button3:
1352 // Cursor was set at LFUN_MOUSE_PRESS time.
1353 // FIXME: If there is a selection we could try to handle a special
1354 // drag & drop context menu.
1358 case mouse_button::none:
1359 case mouse_button::button4:
1360 case mouse_button::button5:
1362 } // switch (cmd.button())
1366 case LFUN_SELF_INSERT: {
1367 if (cmd.argument().empty())
1370 // Automatically delete the currently selected
1371 // text and replace it with what is being
1372 // typed in now. Depends on lyxrc settings
1373 // "auto_region_delete", which defaults to
1376 if (lyxrc.auto_region_delete && cur.selection())
1377 cutSelection(cur, false, false);
1379 cur.clearSelection();
1381 docstring::const_iterator cit = cmd.argument().begin();
1382 docstring::const_iterator const end = cmd.argument().end();
1383 for (; cit != end; ++cit)
1384 bv->translateAndInsert(*cit, this, cur);
1387 moveCursor(cur, false);
1391 case LFUN_HYPERLINK_INSERT: {
1392 InsetCommandParams p(HYPERLINK_CODE);
1394 if (cur.selection()) {
1395 content = cur.selectionAsString(false);
1396 cutSelection(cur, true, false);
1398 p["target"] = (cmd.argument().empty()) ?
1399 content : cmd.argument();
1400 string const data = InsetCommand::params2string("href", p);
1401 if (p["target"].empty()) {
1402 bv->showDialog("href", data);
1404 FuncRequest fr(LFUN_INSET_INSERT, data);
1410 case LFUN_LABEL_INSERT: {
1411 InsetCommandParams p(LABEL_CODE);
1412 // Try to generate a valid label
1413 p["name"] = (cmd.argument().empty()) ?
1414 cur.getPossibleLabel() :
1416 string const data = InsetCommand::params2string("label", p);
1418 if (cmd.argument().empty()) {
1419 bv->showDialog("label", data);
1421 FuncRequest fr(LFUN_INSET_INSERT, data);
1427 case LFUN_INFO_INSERT: {
1429 if (cmd.argument().empty() && cur.selection()) {
1430 // if command argument is empty use current selection as parameter.
1431 docstring ds = cur.selectionAsString(false);
1432 cutSelection(cur, true, false);
1433 FuncRequest cmd0(cmd, ds);
1434 inset = createInset(cur.bv().buffer(), cmd0);
1436 inset = createInset(cur.bv().buffer(), cmd);
1440 insertInset(cur, inset);
1444 case LFUN_CAPTION_INSERT:
1445 case LFUN_FOOTNOTE_INSERT:
1446 case LFUN_NOTE_INSERT:
1447 case LFUN_FLEX_INSERT:
1448 case LFUN_BOX_INSERT:
1449 case LFUN_BRANCH_INSERT:
1450 case LFUN_PHANTOM_INSERT:
1451 case LFUN_ERT_INSERT:
1452 case LFUN_LISTING_INSERT:
1453 case LFUN_MARGINALNOTE_INSERT:
1454 case LFUN_OPTIONAL_INSERT:
1455 case LFUN_INDEX_INSERT:
1456 // Open the inset, and move the current selection
1458 doInsertInset(cur, this, cmd, true, true);
1460 // Some insets are numbered, others are shown in the outline pane so
1461 // let's update the labels and the toc backend.
1462 bv->buffer().updateLabels();
1465 case LFUN_TABULAR_INSERT:
1466 // if there were no arguments, just open the dialog
1467 if (doInsertInset(cur, this, cmd, false, true))
1470 bv->showDialog("tabularcreate");
1474 case LFUN_FLOAT_INSERT:
1475 case LFUN_FLOAT_WIDE_INSERT:
1476 case LFUN_WRAP_INSERT: {
1477 // will some text be moved into the inset?
1478 bool content = cur.selection();
1480 doInsertInset(cur, this, cmd, true, true);
1483 // If some text is moved into the inset, doInsertInset
1484 // puts the cursor outside the inset. To insert the
1485 // caption we put it back into the inset.
1489 ParagraphList & pars = cur.text()->paragraphs();
1491 DocumentClass const & tclass = bv->buffer().params().documentClass();
1493 // add a separate paragraph for the caption inset
1494 pars.push_back(Paragraph());
1495 pars.back().setInsetOwner(&pars[0].inInset());
1496 pars.back().setPlainOrDefaultLayout(tclass);
1497 int cap_pit = pars.size() - 1;
1499 // if an empty inset was created, we create an additional empty
1500 // paragraph at the bottom so that the user can choose where to put
1501 // the graphics (or table).
1503 pars.push_back(Paragraph());
1504 pars.back().setInsetOwner(&pars[0].inInset());
1505 pars.back().setPlainOrDefaultLayout(tclass);
1508 // reposition the cursor to the caption
1509 cur.pit() = cap_pit;
1511 // FIXME: This Text/Cursor dispatch handling is a mess!
1512 // We cannot use Cursor::dispatch here it needs access to up to
1514 FuncRequest cmd_caption(LFUN_CAPTION_INSERT);
1515 doInsertInset(cur, cur.text(), cmd_caption, true, false);
1516 bv->buffer().updateLabels();
1517 cur.updateFlags(Update::Force);
1518 // FIXME: When leaving the Float (or Wrap) inset we should
1519 // delete any empty paragraph left above or below the
1524 case LFUN_NOMENCL_INSERT: {
1525 InsetCommandParams p(NOMENCL_CODE);
1526 if (cmd.argument().empty())
1527 p["symbol"] = bv->cursor().innerText()->getStringToIndex(bv->cursor());
1529 p["symbol"] = cmd.argument();
1530 string const data = InsetCommand::params2string("nomenclature", p);
1531 bv->showDialog("nomenclature", data);
1535 case LFUN_INDEX_PRINT:
1536 case LFUN_NOMENCL_PRINT:
1537 case LFUN_TOC_INSERT:
1538 case LFUN_LINE_INSERT:
1539 case LFUN_NEWPAGE_INSERT:
1541 doInsertInset(cur, this, cmd, false, false);
1545 case LFUN_DEPTH_DECREMENT:
1546 changeDepth(cur, DEC_DEPTH);
1549 case LFUN_DEPTH_INCREMENT:
1550 changeDepth(cur, INC_DEPTH);
1553 case LFUN_MATH_DISPLAY:
1554 mathDispatch(cur, cmd, true);
1557 case LFUN_REGEXP_MODE:
1558 regexpDispatch(cur, cmd);
1561 case LFUN_MATH_MODE:
1562 if (cmd.argument() == "on")
1563 // don't pass "on" as argument
1564 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1566 mathDispatch(cur, cmd, false);
1569 case LFUN_MATH_MACRO:
1570 if (cmd.argument().empty())
1571 cur.errorMessage(from_utf8(N_("Missing argument")));
1573 string s = to_utf8(cmd.argument());
1574 string const s1 = token(s, ' ', 1);
1575 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1576 string const s2 = token(s, ' ', 2);
1577 MacroType type = MacroTypeNewcommand;
1579 type = MacroTypeDef;
1580 MathMacroTemplate * inset = new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, false, type);
1581 inset->setBuffer(bv->buffer());
1582 insertInset(cur, inset);
1584 // enter macro inset and select the name
1586 cur.top().pos() = cur.top().lastpos();
1588 cur.setSelection(true);
1589 cur.top().pos() = 0;
1593 // passthrough hat and underscore outside mathed:
1594 case LFUN_MATH_SUBSCRIPT:
1595 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1597 case LFUN_MATH_SUPERSCRIPT:
1598 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1601 case LFUN_MATH_INSERT:
1602 case LFUN_MATH_MATRIX:
1603 case LFUN_MATH_DELIM:
1604 case LFUN_MATH_BIGDELIM: {
1606 cap::replaceSelection(cur);
1607 cur.insert(new InsetMathHull(hullSimple));
1608 checkAndActivateInset(cur, true);
1609 LASSERT(cur.inMathed(), /**/);
1614 case LFUN_FONT_EMPH: {
1615 Font font(ignore_font, ignore_language);
1616 font.fontInfo().setEmph(FONT_TOGGLE);
1617 toggleAndShow(cur, this, font);
1621 case LFUN_FONT_ITAL: {
1622 Font font(ignore_font, ignore_language);
1623 font.fontInfo().setShape(ITALIC_SHAPE);
1624 toggleAndShow(cur, this, font);
1628 case LFUN_FONT_BOLD:
1629 case LFUN_FONT_BOLDSYMBOL: {
1630 Font font(ignore_font, ignore_language);
1631 font.fontInfo().setSeries(BOLD_SERIES);
1632 toggleAndShow(cur, this, font);
1636 case LFUN_FONT_NOUN: {
1637 Font font(ignore_font, ignore_language);
1638 font.fontInfo().setNoun(FONT_TOGGLE);
1639 toggleAndShow(cur, this, font);
1643 case LFUN_FONT_TYPEWRITER: {
1644 Font font(ignore_font, ignore_language);
1645 font.fontInfo().setFamily(TYPEWRITER_FAMILY); // no good
1646 toggleAndShow(cur, this, font);
1650 case LFUN_FONT_SANS: {
1651 Font font(ignore_font, ignore_language);
1652 font.fontInfo().setFamily(SANS_FAMILY);
1653 toggleAndShow(cur, this, font);
1657 case LFUN_FONT_ROMAN: {
1658 Font font(ignore_font, ignore_language);
1659 font.fontInfo().setFamily(ROMAN_FAMILY);
1660 toggleAndShow(cur, this, font);
1664 case LFUN_FONT_DEFAULT: {
1665 Font font(inherit_font, ignore_language);
1666 toggleAndShow(cur, this, font);
1670 case LFUN_FONT_UNDERLINE: {
1671 Font font(ignore_font, ignore_language);
1672 font.fontInfo().setUnderbar(FONT_TOGGLE);
1673 toggleAndShow(cur, this, font);
1677 case LFUN_FONT_SIZE: {
1678 Font font(ignore_font, ignore_language);
1679 setLyXSize(to_utf8(cmd.argument()), font.fontInfo());
1680 toggleAndShow(cur, this, font);
1684 case LFUN_LANGUAGE: {
1685 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1688 Font font(ignore_font, lang);
1689 toggleAndShow(cur, this, font);
1693 case LFUN_TEXTSTYLE_APPLY:
1694 toggleAndShow(cur, this, freefont, toggleall);
1695 cur.message(_("Character set"));
1698 // Set the freefont using the contents of \param data dispatched from
1699 // the frontends and apply it at the current cursor location.
1700 case LFUN_TEXTSTYLE_UPDATE: {
1703 if (font.fromString(to_utf8(cmd.argument()), toggle)) {
1706 toggleAndShow(cur, this, freefont, toggleall);
1707 cur.message(_("Character set"));
1709 lyxerr << "Argument not ok";
1714 case LFUN_FINISHED_LEFT:
1715 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_LEFT:\n" << cur);
1716 // We're leaving an inset, going left. If the inset is LTR, we're
1717 // leaving from the front, so we should not move (remain at --- but
1718 // not in --- the inset). If the inset is RTL, move left, without
1719 // entering the inset itself; i.e., move to after the inset.
1720 if (cur.paragraph().getFontSettings(
1721 cur.bv().buffer().params(), cur.pos()).isRightToLeft())
1722 cursorVisLeft(cur, true);
1725 case LFUN_FINISHED_RIGHT:
1726 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_RIGHT:\n" << cur);
1727 // We're leaving an inset, going right. If the inset is RTL, we're
1728 // leaving from the front, so we should not move (remain at --- but
1729 // not in --- the inset). If the inset is LTR, move right, without
1730 // entering the inset itself; i.e., move to after the inset.
1731 if (!cur.paragraph().getFontSettings(
1732 cur.bv().buffer().params(), cur.pos()).isRightToLeft())
1733 cursorVisRight(cur, true);
1736 case LFUN_FINISHED_BACKWARD:
1737 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_BACKWARD:\n" << cur);
1740 case LFUN_FINISHED_FORWARD:
1741 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_FORWARD:\n" << cur);
1743 cur.setCurrentFont();
1746 case LFUN_LAYOUT_PARAGRAPH: {
1748 params2string(cur.paragraph(), data);
1749 data = "show\n" + data;
1750 bv->showDialog("paragraph", data);
1754 case LFUN_PARAGRAPH_UPDATE: {
1756 params2string(cur.paragraph(), data);
1758 // Will the paragraph accept changes from the dialog?
1760 cur.inset().allowParagraphCustomization(cur.idx());
1762 data = "update " + convert<string>(accept) + '\n' + data;
1763 bv->updateDialog("paragraph", data);
1767 case LFUN_ACCENT_UMLAUT:
1768 case LFUN_ACCENT_CIRCUMFLEX:
1769 case LFUN_ACCENT_GRAVE:
1770 case LFUN_ACCENT_ACUTE:
1771 case LFUN_ACCENT_TILDE:
1772 case LFUN_ACCENT_CEDILLA:
1773 case LFUN_ACCENT_MACRON:
1774 case LFUN_ACCENT_DOT:
1775 case LFUN_ACCENT_UNDERDOT:
1776 case LFUN_ACCENT_UNDERBAR:
1777 case LFUN_ACCENT_CARON:
1778 case LFUN_ACCENT_BREVE:
1779 case LFUN_ACCENT_TIE:
1780 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1781 case LFUN_ACCENT_CIRCLE:
1782 case LFUN_ACCENT_OGONEK:
1783 theLyXFunc().handleKeyFunc(cmd.action);
1784 if (!cmd.argument().empty())
1785 // FIXME: Are all these characters encoded in one byte in utf8?
1786 bv->translateAndInsert(cmd.argument()[0], this, cur);
1789 case LFUN_FLOAT_LIST_INSERT: {
1790 DocumentClass const & tclass = bv->buffer().params().documentClass();
1791 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1793 if (cur.selection())
1794 cutSelection(cur, true, false);
1795 breakParagraph(cur);
1797 if (cur.lastpos() != 0) {
1798 cursorBackward(cur);
1799 breakParagraph(cur);
1802 docstring const laystr = cur.inset().usePlainLayout() ?
1803 tclass.plainLayoutName() :
1804 tclass.defaultLayoutName();
1805 setLayout(cur, laystr);
1806 ParagraphParameters p;
1807 // FIXME If this call were replaced with one to clearParagraphParams(),
1808 // then we could get rid of this method altogether.
1809 setParagraphs(cur, p);
1810 // FIXME This should be simplified when InsetFloatList takes a
1811 // Buffer in its constructor.
1812 InsetFloatList * ifl = new InsetFloatList(to_utf8(cmd.argument()));
1813 ifl->setBuffer(bv->buffer());
1814 insertInset(cur, ifl);
1817 lyxerr << "Non-existent float type: "
1818 << to_utf8(cmd.argument()) << endl;
1823 case LFUN_CHANGE_ACCEPT: {
1824 acceptOrRejectChanges(cur, ACCEPT);
1828 case LFUN_CHANGE_REJECT: {
1829 acceptOrRejectChanges(cur, REJECT);
1833 case LFUN_THESAURUS_ENTRY: {
1834 docstring arg = cmd.argument();
1836 arg = cur.selectionAsString(false);
1838 if (arg.size() > 100 || arg.empty()) {
1839 // Get word or selection
1840 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1841 arg = cur.selectionAsString(false);
1842 arg += " lang=" + from_ascii(cur.getFont().language()->lang());
1845 bv->showDialog("thesaurus", to_utf8(arg));
1849 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1850 // Given data, an encoding of the ParagraphParameters
1851 // generated in the Paragraph dialog, this function sets
1852 // the current paragraph, or currently selected paragraphs,
1854 // NOTE: This function overrides all existing settings.
1855 setParagraphs(cur, cmd.argument());
1856 cur.message(_("Paragraph layout set"));
1860 case LFUN_PARAGRAPH_PARAMS: {
1861 // Given data, an encoding of the ParagraphParameters as we'd
1862 // find them in a LyX file, this function modifies the current paragraph,
1863 // or currently selected paragraphs.
1864 // NOTE: This function only modifies, and does not override, existing
1866 setParagraphs(cur, cmd.argument(), true);
1867 cur.message(_("Paragraph layout set"));
1872 if (cur.selection()) {
1873 cur.setSelection(false);
1876 // This used to be LFUN_FINISHED_RIGHT, I think FORWARD is more
1877 // correct, but I'm not 100% sure -- dov, 071019
1878 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
1882 case LFUN_OUTLINE_UP:
1883 outline(OutlineUp, cur);
1884 setCursor(cur, cur.pit(), 0);
1885 cur.buffer()->updateLabels();
1889 case LFUN_OUTLINE_DOWN:
1890 outline(OutlineDown, cur);
1891 setCursor(cur, cur.pit(), 0);
1892 cur.buffer()->updateLabels();
1896 case LFUN_OUTLINE_IN:
1897 outline(OutlineIn, cur);
1898 cur.buffer()->updateLabels();
1902 case LFUN_OUTLINE_OUT:
1903 outline(OutlineOut, cur);
1904 cur.buffer()->updateLabels();
1909 LYXERR(Debug::ACTION, "Command " << cmd << " not DISPATCHED by Text");
1914 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1916 // FIXME: The cursor flag is reset two lines below
1917 // so we need to check here if some of the LFUN did touch that.
1918 // for now only Text::erase() and Text::backspace() do that.
1919 // The plan is to verify all the LFUNs and then to remove this
1920 // singleParUpdate boolean altogether.
1921 if (cur.result().update() & Update::Force) {
1922 singleParUpdate = false;
1926 // FIXME: the following code should go in favor of fine grained
1927 // update flag treatment.
1928 if (singleParUpdate) {
1929 // Inserting characters does not change par height in general. So, try
1930 // to update _only_ this paragraph. BufferView will detect if a full
1931 // metrics update is needed anyway.
1932 cur.updateFlags(Update::SinglePar | Update::FitCursor);
1937 && &oldTopSlice.inset() == &cur.inset()
1938 && oldTopSlice.idx() == cur.idx()
1939 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1940 && !cur.selection())
1941 // FIXME: it would be better if we could just do this
1943 //if (cur.result().update() != Update::FitCursor)
1946 // But some LFUNs do not set Update::FitCursor when needed, so we
1947 // do it for all. This is not very harmfull as FitCursor will provoke
1948 // a full redraw only if needed but still, a proper review of all LFUN
1949 // should be done and this needsUpdate boolean can then be removed.
1950 cur.updateFlags(Update::FitCursor);
1952 cur.updateFlags(Update::Force | Update::FitCursor);
1956 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
1957 FuncStatus & flag) const
1959 LASSERT(cur.text() == this, /**/);
1961 FontInfo const & fontinfo = cur.real_current_font.fontInfo();
1963 InsetCode code = NO_CODE;
1965 switch (cmd.action) {
1967 case LFUN_DEPTH_DECREMENT:
1968 enable = changeDepthAllowed(cur, DEC_DEPTH);
1971 case LFUN_DEPTH_INCREMENT:
1972 enable = changeDepthAllowed(cur, INC_DEPTH);
1976 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1979 case LFUN_DIALOG_SHOW_NEW_INSET:
1980 if (cmd.argument() == "bibitem")
1981 code = BIBITEM_CODE;
1982 else if (cmd.argument() == "bibtex")
1984 else if (cmd.argument() == "box")
1986 else if (cmd.argument() == "branch")
1988 else if (cmd.argument() == "citation")
1990 else if (cmd.argument() == "ert")
1992 else if (cmd.argument() == "external")
1993 code = EXTERNAL_CODE;
1994 else if (cmd.argument() == "float")
1996 else if (cmd.argument() == "graphics")
1997 code = GRAPHICS_CODE;
1998 else if (cmd.argument() == "href")
1999 code = HYPERLINK_CODE;
2000 else if (cmd.argument() == "include")
2001 code = INCLUDE_CODE;
2002 else if (cmd.argument() == "index")
2004 else if (cmd.argument() == "nomenclature")
2005 code = NOMENCL_CODE;
2006 else if (cmd.argument() == "label")
2008 else if (cmd.argument() == "note")
2010 else if (cmd.argument() == "phantom")
2011 code = PHANTOM_CODE;
2012 else if (cmd.argument() == "ref")
2014 else if (cmd.argument() == "space")
2016 else if (cmd.argument() == "toc")
2018 else if (cmd.argument() == "vspace")
2020 else if (cmd.argument() == "wrap")
2022 else if (cmd.argument() == "listings")
2023 code = LISTINGS_CODE;
2026 case LFUN_ERT_INSERT:
2029 case LFUN_LISTING_INSERT:
2030 code = LISTINGS_CODE;
2031 // not allowed in description items
2032 enable = !inDescriptionItem(cur);
2034 case LFUN_FOOTNOTE_INSERT:
2037 case LFUN_TABULAR_INSERT:
2038 code = TABULAR_CODE;
2040 case LFUN_MARGINALNOTE_INSERT:
2043 case LFUN_FLOAT_INSERT:
2044 case LFUN_FLOAT_WIDE_INSERT:
2046 // not allowed in description items
2047 enable = !inDescriptionItem(cur);
2049 case LFUN_WRAP_INSERT:
2051 // not allowed in description items
2052 enable = !inDescriptionItem(cur);
2054 case LFUN_FLOAT_LIST_INSERT:
2055 code = FLOAT_LIST_CODE;
2057 case LFUN_CAPTION_INSERT:
2058 code = CAPTION_CODE;
2059 // not allowed in description items
2060 enable = !inDescriptionItem(cur);
2062 case LFUN_NOTE_INSERT:
2064 // in commands (sections etc.) and description items,
2065 // only Notes are allowed
2066 enable = (cmd.argument().empty() || cmd.getArg(0) == "Note" ||
2067 (!cur.paragraph().layout().isCommand()
2068 && !inDescriptionItem(cur)));
2070 case LFUN_FLEX_INSERT: {
2072 string s = cmd.getArg(0);
2074 cur.buffer()->params().documentClass().insetLayout(from_utf8(s));
2075 if (il.lyxtype() != InsetLayout::CHARSTYLE &&
2076 il.lyxtype() != InsetLayout::CUSTOM &&
2077 il.lyxtype() != InsetLayout::ELEMENT &&
2078 il.lyxtype ()!= InsetLayout::STANDARD)
2082 case LFUN_BOX_INSERT:
2085 case LFUN_BRANCH_INSERT:
2087 if (cur.buffer()->masterBuffer()->params().branchlist().empty())
2090 case LFUN_PHANTOM_INSERT:
2091 code = PHANTOM_CODE;
2093 case LFUN_LABEL_INSERT:
2096 case LFUN_INFO_INSERT:
2099 case LFUN_OPTIONAL_INSERT:
2101 enable = cur.paragraph().insetList().count(OPTARG_CODE)
2102 < cur.paragraph().layout().optionalargs;
2104 case LFUN_INDEX_INSERT:
2107 case LFUN_INDEX_PRINT:
2108 code = INDEX_PRINT_CODE;
2110 case LFUN_NOMENCL_INSERT:
2111 if (cur.selIsMultiCell() || cur.selIsMultiLine()) {
2115 code = NOMENCL_CODE;
2117 case LFUN_NOMENCL_PRINT:
2118 code = NOMENCL_PRINT_CODE;
2120 case LFUN_TOC_INSERT:
2123 case LFUN_HYPERLINK_INSERT:
2124 if (cur.selIsMultiCell() || cur.selIsMultiLine()) {
2128 code = HYPERLINK_CODE;
2130 case LFUN_QUOTE_INSERT:
2131 // always allow this, since we will inset a raw quote
2132 // if an inset is not allowed.
2134 case LFUN_SPECIALCHAR_INSERT:
2135 code = SPECIALCHAR_CODE;
2137 case LFUN_SPACE_INSERT:
2138 // slight hack: we know this is allowed in math mode
2143 case LFUN_INSET_MODIFY:
2144 // We need to disable this, because we may get called for a
2146 // InsetTabular::getStatus() -> InsetText::getStatus()
2147 // and we don't handle LFUN_INSET_MODIFY.
2151 case LFUN_FONT_EMPH:
2152 flag.setOnOff(fontinfo.emph() == FONT_ON);
2155 case LFUN_FONT_ITAL:
2156 flag.setOnOff(fontinfo.shape() == ITALIC_SHAPE);
2159 case LFUN_FONT_NOUN:
2160 flag.setOnOff(fontinfo.noun() == FONT_ON);
2163 case LFUN_FONT_BOLD:
2164 case LFUN_FONT_BOLDSYMBOL:
2165 flag.setOnOff(fontinfo.series() == BOLD_SERIES);
2168 case LFUN_FONT_SANS:
2169 flag.setOnOff(fontinfo.family() == SANS_FAMILY);
2172 case LFUN_FONT_ROMAN:
2173 flag.setOnOff(fontinfo.family() == ROMAN_FAMILY);
2176 case LFUN_FONT_TYPEWRITER:
2177 flag.setOnOff(fontinfo.family() == TYPEWRITER_FAMILY);
2182 enable = cur.selection();
2186 if (cmd.argument().empty()) {
2187 if (theClipboard().isInternal())
2188 enable = cap::numberOfSelections() > 0;
2190 enable = !theClipboard().empty();
2194 // we have an argument
2195 string const arg = to_utf8(cmd.argument());
2196 if (isStrUnsignedInt(arg)) {
2197 // it's a number and therefore means the internal stack
2198 unsigned int n = convert<unsigned int>(arg);
2199 enable = cap::numberOfSelections() > n;
2203 // explicit graphics type?
2204 if ((arg == "pdf" && theClipboard().hasGraphicsContents(Clipboard::PdfGraphicsType))
2205 || (arg == "png" && theClipboard().hasGraphicsContents(Clipboard::PngGraphicsType))
2206 || (arg == "jpeg" && theClipboard().hasGraphicsContents(Clipboard::JpegGraphicsType))
2207 || (arg == "linkback" && theClipboard().hasGraphicsContents(Clipboard::LinkBackGraphicsType))) {
2217 case LFUN_CLIPBOARD_PASTE:
2218 enable = !theClipboard().empty();
2221 case LFUN_PRIMARY_SELECTION_PASTE:
2222 enable = cur.selection() || !theSelection().empty();
2225 case LFUN_SELECTION_PASTE:
2226 enable = cap::selection();
2229 case LFUN_PARAGRAPH_MOVE_UP:
2230 enable = cur.pit() > 0 && !cur.selection();
2233 case LFUN_PARAGRAPH_MOVE_DOWN:
2234 enable = cur.pit() < cur.lastpit() && !cur.selection();
2237 case LFUN_INSET_DISSOLVE:
2238 if (!cmd.argument().empty()) {
2239 InsetLayout const & il = cur.inset().getLayout(cur.buffer()->params());
2240 InsetLayout::InsetLyXType const type =
2241 translateLyXType(to_utf8(cmd.argument()));
2242 enable = cur.inset().lyxCode() == FLEX_CODE
2243 && il.lyxtype() == type;
2245 enable = ((!isMainText(cur.bv().buffer())
2246 && cur.inset().nargs() == 1)
2248 && cur.nextInset()->nargs() == 1));
2252 case LFUN_CHANGE_ACCEPT:
2253 case LFUN_CHANGE_REJECT:
2254 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
2255 // In principle, these LFUNs should only be enabled if there
2256 // is a change at the current position/in the current selection.
2257 // However, without proper optimizations, this will inevitably
2258 // result in unacceptable performance - just imagine a user who
2259 // wants to select the complete content of a long document.
2263 case LFUN_OUTLINE_UP:
2264 case LFUN_OUTLINE_DOWN:
2265 case LFUN_OUTLINE_IN:
2266 case LFUN_OUTLINE_OUT:
2267 // FIXME: LyX is not ready for outlining within inset.
2268 enable = isMainText(cur.bv().buffer())
2269 && cur.paragraph().layout().toclevel != Layout::NOT_IN_TOC;
2272 case LFUN_NEWLINE_INSERT:
2273 // LaTeX restrictions (labels or empty par)
2274 enable = (cur.pos() > cur.paragraph().beginOfBody());
2277 case LFUN_SET_GRAPHICS_GROUP: {
2278 InsetGraphics * ins = graphics::getCurrentGraphicsInset(cur);
2282 flag.setOnOff(to_utf8(cmd.argument()) == ins->getParams().groupId);
2286 case LFUN_NEWPAGE_INSERT:
2287 // not allowed in description items
2288 enable = !inDescriptionItem(cur);
2291 case LFUN_MATH_INSERT:
2292 case LFUN_MATH_MATRIX:
2293 case LFUN_MATH_DELIM:
2294 case LFUN_MATH_BIGDELIM:
2295 // not allowed in ERT, for example.
2296 enable = cur.inset().insetAllowed(MATH_CODE);
2299 case LFUN_WORD_DELETE_FORWARD:
2300 case LFUN_WORD_DELETE_BACKWARD:
2301 case LFUN_LINE_DELETE:
2302 case LFUN_WORD_FORWARD:
2303 case LFUN_WORD_BACKWARD:
2304 case LFUN_WORD_RIGHT:
2305 case LFUN_WORD_LEFT:
2306 case LFUN_CHAR_FORWARD:
2307 case LFUN_CHAR_FORWARD_SELECT:
2308 case LFUN_CHAR_BACKWARD:
2309 case LFUN_CHAR_BACKWARD_SELECT:
2310 case LFUN_CHAR_LEFT:
2311 case LFUN_CHAR_LEFT_SELECT:
2312 case LFUN_CHAR_RIGHT:
2313 case LFUN_CHAR_RIGHT_SELECT:
2315 case LFUN_UP_SELECT:
2317 case LFUN_DOWN_SELECT:
2318 case LFUN_PARAGRAPH_UP_SELECT:
2319 case LFUN_PARAGRAPH_DOWN_SELECT:
2320 case LFUN_LINE_BEGIN_SELECT:
2321 case LFUN_LINE_END_SELECT:
2322 case LFUN_WORD_FORWARD_SELECT:
2323 case LFUN_WORD_BACKWARD_SELECT:
2324 case LFUN_WORD_RIGHT_SELECT:
2325 case LFUN_WORD_LEFT_SELECT:
2326 case LFUN_WORD_SELECT:
2327 case LFUN_PARAGRAPH_UP:
2328 case LFUN_PARAGRAPH_DOWN:
2329 case LFUN_LINE_BEGIN:
2331 case LFUN_CHAR_DELETE_FORWARD:
2332 case LFUN_CHAR_DELETE_BACKWARD:
2333 case LFUN_BREAK_PARAGRAPH:
2334 case LFUN_PARAGRAPH_SPACING:
2335 case LFUN_INSET_INSERT:
2336 case LFUN_WORD_UPCASE:
2337 case LFUN_WORD_LOWCASE:
2338 case LFUN_WORD_CAPITALIZE:
2339 case LFUN_CHARS_TRANSPOSE:
2340 case LFUN_SERVER_GET_XY:
2341 case LFUN_SERVER_SET_XY:
2342 case LFUN_SERVER_GET_LAYOUT:
2344 case LFUN_DATE_INSERT:
2345 case LFUN_SELF_INSERT:
2346 case LFUN_LINE_INSERT:
2347 case LFUN_MATH_DISPLAY:
2348 case LFUN_MATH_MODE:
2349 case LFUN_MATH_MACRO:
2350 case LFUN_MATH_SUBSCRIPT:
2351 case LFUN_MATH_SUPERSCRIPT:
2352 case LFUN_FONT_DEFAULT:
2353 case LFUN_FONT_UNDERLINE:
2354 case LFUN_FONT_SIZE:
2356 case LFUN_TEXTSTYLE_APPLY:
2357 case LFUN_TEXTSTYLE_UPDATE:
2358 case LFUN_LAYOUT_PARAGRAPH:
2359 case LFUN_PARAGRAPH_UPDATE:
2360 case LFUN_ACCENT_UMLAUT:
2361 case LFUN_ACCENT_CIRCUMFLEX:
2362 case LFUN_ACCENT_GRAVE:
2363 case LFUN_ACCENT_ACUTE:
2364 case LFUN_ACCENT_TILDE:
2365 case LFUN_ACCENT_CEDILLA:
2366 case LFUN_ACCENT_MACRON:
2367 case LFUN_ACCENT_DOT:
2368 case LFUN_ACCENT_UNDERDOT:
2369 case LFUN_ACCENT_UNDERBAR:
2370 case LFUN_ACCENT_CARON:
2371 case LFUN_ACCENT_BREVE:
2372 case LFUN_ACCENT_TIE:
2373 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
2374 case LFUN_ACCENT_CIRCLE:
2375 case LFUN_ACCENT_OGONEK:
2376 case LFUN_THESAURUS_ENTRY:
2377 case LFUN_PARAGRAPH_PARAMS_APPLY:
2378 case LFUN_PARAGRAPH_PARAMS:
2380 case LFUN_BUFFER_END:
2381 case LFUN_BUFFER_BEGIN:
2382 case LFUN_BUFFER_BEGIN_SELECT:
2383 case LFUN_BUFFER_END_SELECT:
2384 case LFUN_UNICODE_INSERT:
2385 // these are handled in our dispatch()
2394 && (cur.empty() || !cur.inset().insetAllowed(code)))
2397 flag.setEnabled(enable);
2402 void Text::pasteString(Cursor & cur, docstring const & clip,
2405 cur.clearSelection();
2406 if (!clip.empty()) {
2409 insertStringAsParagraphs(cur, clip);
2411 insertStringAsLines(cur, clip);
2416 // FIXME: an item inset would make things much easier.
2417 bool Text::inDescriptionItem(Cursor & cur) const
2419 Paragraph & par = cur.paragraph();
2420 pos_type const pos = cur.pos();
2421 pos_type const body_pos = par.beginOfBody();
2423 if (par.layout().latextype != LATEX_LIST_ENVIRONMENT
2424 && (par.layout().latextype != LATEX_ITEM_ENVIRONMENT
2425 || par.layout().margintype != MARGIN_FIRST_DYNAMIC))
2428 return (pos < body_pos
2430 && (pos == 0 || par.getChar(pos - 1) != ' ')));