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));
453 // FIXME: We use the update flag to indicates wether a singlePar or a
454 // full screen update is needed. We reset it here but shall we restore it
458 LASSERT(cur.text() == this, /**/);
459 CursorSlice oldTopSlice = cur.top();
460 bool oldBoundary = cur.boundary();
461 bool sel = cur.selection();
462 // Signals that, even if needsUpdate == false, an update of the
463 // cursor paragraph is required
464 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
465 LyXAction::SingleParUpdate);
466 // Signals that a full-screen update is required
467 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
468 LyXAction::NoUpdate) || singleParUpdate);
470 switch (cmd.action) {
472 case LFUN_PARAGRAPH_MOVE_DOWN: {
473 pit_type const pit = cur.pit();
474 recUndo(cur, pit, pit + 1);
476 swap(pars_[pit], pars_[pit + 1]);
477 cur.buffer()->updateLabels();
483 case LFUN_PARAGRAPH_MOVE_UP: {
484 pit_type const pit = cur.pit();
485 recUndo(cur, pit - 1, pit);
487 swap(pars_[pit], pars_[pit - 1]);
488 cur.buffer()->updateLabels();
494 case LFUN_APPENDIX: {
495 Paragraph & par = cur.paragraph();
496 bool start = !par.params().startOfAppendix();
498 // FIXME: The code below only makes sense at top level.
499 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
500 // ensure that we have only one start_of_appendix in this document
501 // FIXME: this don't work for multipart document!
502 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
503 if (pars_[tmp].params().startOfAppendix()) {
505 pars_[tmp].params().startOfAppendix(false);
511 par.params().startOfAppendix(start);
513 // we can set the refreshing parameters now
514 cur.buffer()->updateLabels();
518 case LFUN_WORD_DELETE_FORWARD:
520 cutSelection(cur, true, false);
522 deleteWordForward(cur);
523 finishChange(cur, false);
526 case LFUN_WORD_DELETE_BACKWARD:
528 cutSelection(cur, true, false);
530 deleteWordBackward(cur);
531 finishChange(cur, false);
534 case LFUN_LINE_DELETE:
536 cutSelection(cur, true, false);
538 tm.deleteLineForward(cur);
539 finishChange(cur, false);
542 case LFUN_BUFFER_BEGIN:
543 case LFUN_BUFFER_BEGIN_SELECT:
544 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
545 if (cur.depth() == 1)
546 needsUpdate |= cursorTop(cur);
549 cur.updateFlags(Update::FitCursor);
552 case LFUN_BUFFER_END:
553 case LFUN_BUFFER_END_SELECT:
554 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
555 if (cur.depth() == 1)
556 needsUpdate |= cursorBottom(cur);
559 cur.updateFlags(Update::FitCursor);
562 case LFUN_CHAR_FORWARD:
563 case LFUN_CHAR_FORWARD_SELECT:
564 //LYXERR0(" LFUN_CHAR_FORWARD[SEL]:\n" << cur);
565 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
566 needsUpdate |= cursorForward(cur);
568 if (!needsUpdate && oldTopSlice == cur.top()
569 && cur.boundary() == oldBoundary) {
571 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
575 case LFUN_CHAR_BACKWARD:
576 case LFUN_CHAR_BACKWARD_SELECT:
577 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
578 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
579 needsUpdate |= cursorBackward(cur);
581 if (!needsUpdate && oldTopSlice == cur.top()
582 && cur.boundary() == oldBoundary) {
584 cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
589 case LFUN_CHAR_LEFT_SELECT:
590 if (lyxrc.visual_cursor) {
591 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_LEFT_SELECT);
592 needsUpdate |= cursorVisLeft(cur);
593 if (!needsUpdate && oldTopSlice == cur.top()
594 && cur.boundary() == oldBoundary) {
596 cmd = FuncRequest(LFUN_FINISHED_LEFT);
599 if (reverseDirectionNeeded(cur)) {
600 cmd.action = cmd.action == LFUN_CHAR_LEFT_SELECT ?
601 LFUN_CHAR_FORWARD_SELECT : LFUN_CHAR_FORWARD;
603 cmd.action = cmd.action == LFUN_CHAR_LEFT_SELECT ?
604 LFUN_CHAR_BACKWARD_SELECT : LFUN_CHAR_BACKWARD;
611 case LFUN_CHAR_RIGHT:
612 case LFUN_CHAR_RIGHT_SELECT:
613 if (lyxrc.visual_cursor) {
614 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_RIGHT_SELECT);
615 needsUpdate |= cursorVisRight(cur);
616 if (!needsUpdate && oldTopSlice == cur.top()
617 && cur.boundary() == oldBoundary) {
619 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
622 if (reverseDirectionNeeded(cur)) {
623 cmd.action = cmd.action == LFUN_CHAR_RIGHT_SELECT ?
624 LFUN_CHAR_BACKWARD_SELECT : LFUN_CHAR_BACKWARD;
626 cmd.action = cmd.action == LFUN_CHAR_RIGHT_SELECT ?
627 LFUN_CHAR_FORWARD_SELECT : LFUN_CHAR_FORWARD;
636 case LFUN_DOWN_SELECT:
639 // stop/start the selection
640 bool select = cmd.action == LFUN_DOWN_SELECT ||
641 cmd.action == LFUN_UP_SELECT;
643 // move cursor up/down
644 bool up = cmd.action == LFUN_UP_SELECT || cmd.action == LFUN_UP;
645 bool const atFirstOrLastRow = cur.atFirstOrLastRow(up);
647 if (!atFirstOrLastRow) {
648 needsUpdate |= cur.selHandle(select);
649 cur.selHandle(select);
650 cur.upDownInText(up, needsUpdate);
651 needsUpdate |= cur.beforeDispatchCursor().inMathed();
653 // if the cursor cannot be moved up or down do not remove
654 // the selection right now, but wait for the next dispatch.
656 needsUpdate |= cur.selHandle(select);
657 cur.upDownInText(up, needsUpdate);
664 case LFUN_PARAGRAPH_UP:
665 case LFUN_PARAGRAPH_UP_SELECT:
666 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
667 needsUpdate |= cursorUpParagraph(cur);
670 case LFUN_PARAGRAPH_DOWN:
671 case LFUN_PARAGRAPH_DOWN_SELECT:
672 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
673 needsUpdate |= cursorDownParagraph(cur);
676 case LFUN_LINE_BEGIN:
677 case LFUN_LINE_BEGIN_SELECT:
678 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
679 needsUpdate |= tm.cursorHome(cur);
683 case LFUN_LINE_END_SELECT:
684 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
685 needsUpdate |= tm.cursorEnd(cur);
688 case LFUN_WORD_RIGHT:
689 case LFUN_WORD_RIGHT_SELECT:
690 if (lyxrc.visual_cursor) {
691 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_RIGHT_SELECT);
692 needsUpdate |= cursorVisRightOneWord(cur);
693 if (!needsUpdate && oldTopSlice == cur.top()
694 && cur.boundary() == oldBoundary) {
696 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
699 if (reverseDirectionNeeded(cur)) {
700 cmd.action = cmd.action == LFUN_WORD_RIGHT_SELECT ?
701 LFUN_WORD_BACKWARD_SELECT : LFUN_WORD_BACKWARD;
703 cmd.action = cmd.action == LFUN_WORD_RIGHT_SELECT ?
704 LFUN_WORD_FORWARD_SELECT : LFUN_WORD_FORWARD;
711 case LFUN_WORD_FORWARD:
712 case LFUN_WORD_FORWARD_SELECT:
713 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
714 needsUpdate |= cursorForwardOneWord(cur);
718 case LFUN_WORD_LEFT_SELECT:
719 if (lyxrc.visual_cursor) {
720 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_LEFT_SELECT);
721 needsUpdate |= cursorVisLeftOneWord(cur);
722 if (!needsUpdate && oldTopSlice == cur.top()
723 && cur.boundary() == oldBoundary) {
725 cmd = FuncRequest(LFUN_FINISHED_LEFT);
728 if (reverseDirectionNeeded(cur)) {
729 cmd.action = cmd.action == LFUN_WORD_LEFT_SELECT ?
730 LFUN_WORD_FORWARD_SELECT : LFUN_WORD_FORWARD;
732 cmd.action = cmd.action == LFUN_WORD_LEFT_SELECT ?
733 LFUN_WORD_BACKWARD_SELECT : LFUN_WORD_BACKWARD;
740 case LFUN_WORD_BACKWARD:
741 case LFUN_WORD_BACKWARD_SELECT:
742 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
743 needsUpdate |= cursorBackwardOneWord(cur);
746 case LFUN_WORD_SELECT: {
747 selectWord(cur, WHOLE_WORD);
748 finishChange(cur, true);
752 case LFUN_NEWLINE_INSERT: {
753 InsetNewlineParams inp;
754 docstring arg = cmd.argument();
755 // this avoids a double undo
756 // FIXME: should not be needed, ideally
757 if (!cur.selection())
759 cap::replaceSelection(cur);
760 if (arg == "linebreak")
761 inp.kind = InsetNewlineParams::LINEBREAK;
763 inp.kind = InsetNewlineParams::NEWLINE;
764 cur.insert(new InsetNewline(inp));
766 moveCursor(cur, false);
770 case LFUN_CHAR_DELETE_FORWARD:
771 if (!cur.selection()) {
772 if (cur.pos() == cur.paragraph().size())
773 // Par boundary, force full-screen update
774 singleParUpdate = false;
775 needsUpdate |= erase(cur);
777 // It is possible to make it a lot faster still
778 // just comment out the line below...
780 cutSelection(cur, true, false);
781 singleParUpdate = false;
783 moveCursor(cur, false);
786 case LFUN_CHAR_DELETE_BACKWARD:
787 if (!cur.selection()) {
788 if (bv->getIntl().getTransManager().backspace()) {
789 // Par boundary, full-screen update
791 singleParUpdate = false;
792 needsUpdate |= backspace(cur);
794 // It is possible to make it a lot faster still
795 // just comment out the line below...
798 cutSelection(cur, true, false);
799 singleParUpdate = false;
803 case LFUN_BREAK_PARAGRAPH:
804 cap::replaceSelection(cur);
805 breakParagraph(cur, cmd.argument() == "inverse");
810 // With the creation of LFUN_PARAGRAPH_PARAMS, this is now redundant,
811 // as its duties can be performed there. Should it be removed??
812 // FIXME For now, it can just dispatch LFUN_PARAGRAPH_PARAMS...
813 case LFUN_PARAGRAPH_SPACING: {
814 Paragraph & par = cur.paragraph();
815 Spacing::Space cur_spacing = par.params().spacing().getSpace();
816 string cur_value = "1.0";
817 if (cur_spacing == Spacing::Other)
818 cur_value = par.params().spacing().getValueAsString();
820 istringstream is(to_utf8(cmd.argument()));
823 Spacing::Space new_spacing = cur_spacing;
824 string new_value = cur_value;
826 lyxerr << "Missing argument to `paragraph-spacing'"
828 } else if (tmp == "single") {
829 new_spacing = Spacing::Single;
830 } else if (tmp == "onehalf") {
831 new_spacing = Spacing::Onehalf;
832 } else if (tmp == "double") {
833 new_spacing = Spacing::Double;
834 } else if (tmp == "other") {
835 new_spacing = Spacing::Other;
836 string tmpval = "0.0";
838 lyxerr << "new_value = " << tmpval << endl;
841 } else if (tmp == "default") {
842 new_spacing = Spacing::Default;
844 lyxerr << to_utf8(_("Unknown spacing argument: "))
845 << to_utf8(cmd.argument()) << endl;
847 if (cur_spacing != new_spacing || cur_value != new_value)
848 par.params().spacing(Spacing(new_spacing, new_value));
852 case LFUN_INSET_INSERT: {
855 // We have to avoid triggering InstantPreview loading
856 // before inserting into the document. See bug #5626.
857 bool loaded = bv->buffer().isFullyLoaded();
858 bv->buffer().setFullyLoaded(false);
859 Inset * inset = createInset(bv->buffer(), cmd);
860 bv->buffer().setFullyLoaded(loaded);
863 // FIXME (Abdel 01/02/2006):
864 // What follows would be a partial fix for bug 2154:
865 // http://bugzilla.lyx.org/show_bug.cgi?id=2154
866 // This automatically put the label inset _after_ a
867 // numbered section. It should be possible to extend the mechanism
868 // to any kind of LateX environement.
869 // The correct way to fix that bug would be at LateX generation.
870 // I'll let the code here for reference as it could be used for some
871 // other feature like "automatic labelling".
873 Paragraph & par = pars_[cur.pit()];
874 if (inset->lyxCode() == LABEL_CODE
875 && par.layout().labeltype == LABEL_COUNTER) {
876 // Go to the end of the paragraph
877 // Warning: Because of Change-Tracking, the last
878 // position is 'size()' and not 'size()-1':
879 cur.pos() = par.size();
880 // Insert a new paragraph
881 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
886 cutSelection(cur, true, false);
890 // trigger InstantPreview now
891 if (inset->lyxCode() == EXTERNAL_CODE) {
892 InsetExternal & ins =
893 static_cast<InsetExternal &>(*inset);
901 case LFUN_INSET_DISSOLVE: {
902 // first, try if there's an inset at cursor
903 // FIXME: this first part should be moved to
904 // a LFUN_NEXT_INSET_DISSOLVE, or be called via
905 // some generic "next-inset inset-dissolve"
906 Inset * inset = cur.nextInset();
907 if (inset && inset->isActive()) {
909 tmpcur.pushBackward(*inset);
910 inset->dispatch(tmpcur, cmd);
911 if (tmpcur.result().dispatched()) {
916 // if it did not work, try the underlying inset
917 if (dissolveInset(cur)) {
921 // if it did not work, do nothing.
925 case LFUN_INSET_SETTINGS: {
926 Inset & inset = cur.inset();
927 if (cmd.getArg(0) == insetName(inset.lyxCode())) {
928 // This inset dialog has been explicitely requested.
929 inset.showInsetDialog(bv);
932 // else, if there is an inset at the cursor, access this
933 Inset * next_inset = cur.nextInset();
935 next_inset->showInsetDialog(bv);
938 // if not then access the underlying inset.
939 inset.showInsetDialog(bv);
943 case LFUN_SET_GRAPHICS_GROUP: {
944 InsetGraphics * ins = graphics::getCurrentGraphicsInset(cur);
950 string id = to_utf8(cmd.argument());
951 string grp = graphics::getGroupParams(bv->buffer(), id);
952 InsetGraphicsParams tmp, inspar = ins->getParams();
955 inspar.groupId = to_utf8(cmd.argument());
957 InsetGraphics::string2params(grp, bv->buffer(), tmp);
958 tmp.filename = inspar.filename;
962 ins->setParams(inspar);
965 case LFUN_SPACE_INSERT:
966 if (cur.paragraph().layout().free_spacing)
967 insertChar(cur, ' ');
969 doInsertInset(cur, this, cmd, false, false);
972 moveCursor(cur, false);
975 case LFUN_SPECIALCHAR_INSERT: {
976 string const name = to_utf8(cmd.argument());
977 if (name == "hyphenation")
978 specialChar(cur, InsetSpecialChar::HYPHENATION);
979 else if (name == "ligature-break")
980 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
981 else if (name == "slash")
982 specialChar(cur, InsetSpecialChar::SLASH);
983 else if (name == "nobreakdash")
984 specialChar(cur, InsetSpecialChar::NOBREAKDASH);
985 else if (name == "dots")
986 specialChar(cur, InsetSpecialChar::LDOTS);
987 else if (name == "end-of-sentence")
988 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
989 else if (name == "menu-separator")
990 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
991 else if (name.empty())
992 lyxerr << "LyX function 'specialchar-insert' needs an argument." << endl;
994 lyxerr << "Wrong argument for LyX function 'specialchar-insert'." << endl;
998 case LFUN_WORD_UPCASE:
999 changeCase(cur, text_uppercase);
1002 case LFUN_WORD_LOWCASE:
1003 changeCase(cur, text_lowercase);
1006 case LFUN_WORD_CAPITALIZE:
1007 changeCase(cur, text_capitalization);
1010 case LFUN_CHARS_TRANSPOSE:
1011 charsTranspose(cur);
1015 cur.message(_("Paste"));
1016 LASSERT(cur.selBegin().idx() == cur.selEnd().idx(), /**/);
1017 cap::replaceSelection(cur);
1019 // without argument?
1020 string const arg = to_utf8(cmd.argument());
1022 if (theClipboard().isInternal())
1023 pasteFromStack(cur, bv->buffer().errorList("Paste"), 0);
1024 else if (theClipboard().hasGraphicsContents()
1025 && !theClipboard().hasTextContents())
1026 pasteClipboardGraphics(cur, bv->buffer().errorList("Paste"));
1028 pasteClipboardText(cur, bv->buffer().errorList("Paste"));
1029 } else if (isStrUnsignedInt(arg)) {
1030 // we have a numerical argument
1031 pasteFromStack(cur, bv->buffer().errorList("Paste"),
1032 convert<unsigned int>(arg));
1034 Clipboard::GraphicsType type = Clipboard::AnyGraphicsType;
1036 type = Clipboard::PdfGraphicsType;
1037 else if (arg == "png")
1038 type = Clipboard::PngGraphicsType;
1039 else if (arg == "jpeg")
1040 type = Clipboard::JpegGraphicsType;
1041 else if (arg == "linkback")
1042 type = Clipboard::LinkBackGraphicsType;
1044 LASSERT(false, /**/);
1046 pasteClipboardGraphics(cur, bv->buffer().errorList("Paste"), type);
1049 bv->buffer().errors("Paste");
1050 cur.clearSelection(); // bug 393
1056 cutSelection(cur, true, true);
1057 cur.message(_("Cut"));
1062 cur.message(_("Copy"));
1065 case LFUN_SERVER_GET_XY:
1066 cur.message(from_utf8(
1067 convert<string>(tm.cursorX(cur.top(), cur.boundary()))
1068 + ' ' + convert<string>(tm.cursorY(cur.top(), cur.boundary()))));
1071 case LFUN_SERVER_SET_XY: {
1074 istringstream is(to_utf8(cmd.argument()));
1077 lyxerr << "SETXY: Could not parse coordinates in '"
1078 << to_utf8(cmd.argument()) << endl;
1080 tm.setCursorFromCoordinates(cur, x, y);
1084 case LFUN_SERVER_GET_LAYOUT:
1085 cur.message(cur.paragraph().layout().name());
1089 docstring layout = cmd.argument();
1090 LYXERR(Debug::INFO, "LFUN_LAYOUT: (arg) " << to_utf8(layout));
1092 Paragraph const & para = cur.paragraph();
1093 docstring const old_layout = para.layout().name();
1094 DocumentClass const & tclass = bv->buffer().params().documentClass();
1097 layout = tclass.defaultLayoutName();
1099 if (para.forcePlainLayout())
1100 // in this case only the empty layout is allowed
1101 layout = tclass.plainLayoutName();
1102 else if (para.usePlainLayout()) {
1103 // in this case, default layout maps to empty layout
1104 if (layout == tclass.defaultLayoutName())
1105 layout = tclass.plainLayoutName();
1107 // otherwise, the empty layout maps to the default
1108 if (layout == tclass.plainLayoutName())
1109 layout = tclass.defaultLayoutName();
1112 bool hasLayout = tclass.hasLayout(layout);
1114 // If the entry is obsolete, use the new one instead.
1116 docstring const & obs = tclass[layout].obsoleted_by();
1122 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
1123 from_utf8(N_(" not known")));
1127 bool change_layout = (old_layout != layout);
1129 if (!change_layout && cur.selection() &&
1130 cur.selBegin().pit() != cur.selEnd().pit())
1132 pit_type spit = cur.selBegin().pit();
1133 pit_type epit = cur.selEnd().pit() + 1;
1134 while (spit != epit) {
1135 if (pars_[spit].layout().name() != old_layout) {
1136 change_layout = true;
1144 setLayout(cur, layout);
1149 case LFUN_CLIPBOARD_PASTE:
1150 cur.clearSelection();
1151 pasteClipboardText(cur, bv->buffer().errorList("Paste"),
1152 cmd.argument() == "paragraph");
1153 bv->buffer().errors("Paste");
1156 case LFUN_PRIMARY_SELECTION_PASTE:
1157 pasteString(cur, theSelection().get(),
1158 cmd.argument() == "paragraph");
1161 case LFUN_SELECTION_PASTE:
1162 // Copy the selection buffer to the clipboard stack,
1163 // because we want it to appear in the "Edit->Paste
1165 cap::copySelectionToStack();
1166 cap::pasteSelection(bv->cursor(), bv->buffer().errorList("Paste"));
1167 bv->buffer().errors("Paste");
1170 case LFUN_UNICODE_INSERT: {
1171 if (cmd.argument().empty())
1173 docstring hexstring = cmd.argument();
1174 if (isHex(hexstring)) {
1175 char_type c = hexToInt(hexstring);
1176 if (c >= 32 && c < 0x10ffff) {
1177 lyxerr << "Inserting c: " << c << endl;
1178 docstring s = docstring(1, c);
1179 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
1185 case LFUN_QUOTE_INSERT: {
1186 Paragraph & par = cur.paragraph();
1187 pos_type pos = cur.pos();
1188 BufferParams const & bufparams = bv->buffer().params();
1189 Layout const & style = par.layout();
1190 if (!style.pass_thru
1191 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
1192 // this avoids a double undo
1193 // FIXME: should not be needed, ideally
1194 if (!cur.selection())
1196 cap::replaceSelection(cur);
1201 else if (cur.prevInset() && cur.prevInset()->isSpace())
1204 c = par.getChar(pos - 1);
1205 string arg = to_utf8(cmd.argument());
1206 cur.insert(new InsetQuotes(bv->buffer(), c, (arg == "single")
1207 ? InsetQuotes::SingleQuotes : InsetQuotes::DoubleQuotes));
1211 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
1215 case LFUN_DATE_INSERT: {
1216 string const format = cmd.argument().empty()
1217 ? lyxrc.date_insert_format : to_utf8(cmd.argument());
1218 string const time = formatted_time(current_time(), format);
1219 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, time));
1223 case LFUN_MOUSE_TRIPLE:
1224 if (cmd.button() == mouse_button::button1) {
1233 case LFUN_MOUSE_DOUBLE:
1234 if (cmd.button() == mouse_button::button1) {
1235 selectWord(cur, WHOLE_WORD_STRICT);
1240 // Single-click on work area
1241 case LFUN_MOUSE_PRESS:
1242 // We are not marking a selection with the keyboard in any case.
1243 cur.bv().cursor().setMark(false);
1244 switch (cmd.button()) {
1245 case mouse_button::button1:
1247 if (!bv->mouseSetCursor(cur, cmd.argument() == "region-select"))
1248 cur.updateFlags(Update::SinglePar | Update::FitCursor);
1251 case mouse_button::button2:
1252 // Middle mouse pasting.
1253 bv->mouseSetCursor(cur);
1255 FuncRequest(LFUN_COMMAND_ALTERNATIVES,
1256 "selection-paste ; primary-selection-paste paragraph"));
1260 case mouse_button::button3: {
1261 Cursor const & bvcur = cur.bv().cursor();
1262 // Don't do anything if we right-click a
1263 // selection, a context menu will popup.
1264 if (bvcur.selection() && cur >= bvcur.selectionBegin()
1265 && cur < bvcur.selectionEnd()) {
1269 if (!bv->mouseSetCursor(cur, false))
1270 cur.updateFlags(Update::SinglePar | Update::FitCursor);
1276 } // switch (cmd.button())
1279 case LFUN_MOUSE_MOTION: {
1280 // Mouse motion with right or middle mouse do nothing for now.
1281 if (cmd.button() != mouse_button::button1) {
1285 // ignore motions deeper nested than the real anchor
1286 Cursor & bvcur = cur.bv().cursor();
1287 if (!bvcur.anchor_.hasPart(cur)) {
1291 CursorSlice old = bvcur.top();
1293 int const wh = bv->workHeight();
1294 int const y = max(0, min(wh - 1, cmd.y));
1296 tm.setCursorFromCoordinates(cur, cmd.x, y);
1297 cur.setTargetX(cmd.x);
1299 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1301 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1302 // This is to allow jumping over large insets
1303 if (cur.top() == old) {
1305 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1307 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1309 // We continue with our existing selection or start a new one, so don't
1310 // reset the anchor.
1311 bvcur.setCursor(cur);
1312 bvcur.setSelection(true);
1313 if (cur.top() == old) {
1314 // We didn't move one iota, so no need to update the screen.
1315 cur.updateFlags(Update::SinglePar | Update::FitCursor);
1322 case LFUN_MOUSE_RELEASE:
1323 switch (cmd.button()) {
1324 case mouse_button::button1:
1325 // Cursor was set at LFUN_MOUSE_PRESS or LFUN_MOUSE_MOTION time.
1326 // If there is a new selection, update persistent selection;
1327 // otherwise, single click does not clear persistent selection
1329 if (cur.selection()) {
1330 // Finish selection. If double click,
1331 // cur is moved to the end of word by
1332 // selectWord but bvcur is current
1334 cur.bv().cursor().setSelection();
1335 // We might have removed an empty but drawn selection
1336 // (probably a margin)
1337 cur.updateFlags(Update::SinglePar | Update::FitCursor);
1340 // FIXME: We could try to handle drag and drop of selection here.
1343 case mouse_button::button2:
1344 // Middle mouse pasting is handled at mouse press time,
1345 // see LFUN_MOUSE_PRESS.
1349 case mouse_button::button3:
1350 // Cursor was set at LFUN_MOUSE_PRESS time.
1351 // FIXME: If there is a selection we could try to handle a special
1352 // drag & drop context menu.
1356 case mouse_button::none:
1357 case mouse_button::button4:
1358 case mouse_button::button5:
1360 } // switch (cmd.button())
1364 case LFUN_SELF_INSERT: {
1365 if (cmd.argument().empty())
1368 // Automatically delete the currently selected
1369 // text and replace it with what is being
1370 // typed in now. Depends on lyxrc settings
1371 // "auto_region_delete", which defaults to
1374 if (lyxrc.auto_region_delete && cur.selection())
1375 cutSelection(cur, false, false);
1377 cur.clearSelection();
1379 docstring::const_iterator cit = cmd.argument().begin();
1380 docstring::const_iterator const end = cmd.argument().end();
1381 for (; cit != end; ++cit)
1382 bv->translateAndInsert(*cit, this, cur);
1385 moveCursor(cur, false);
1389 case LFUN_HYPERLINK_INSERT: {
1390 InsetCommandParams p(HYPERLINK_CODE);
1392 if (cur.selection()) {
1393 content = cur.selectionAsString(false);
1394 cutSelection(cur, true, false);
1396 p["target"] = (cmd.argument().empty()) ?
1397 content : cmd.argument();
1398 string const data = InsetCommand::params2string("href", p);
1399 if (p["target"].empty()) {
1400 bv->showDialog("href", data);
1402 FuncRequest fr(LFUN_INSET_INSERT, data);
1408 case LFUN_LABEL_INSERT: {
1409 InsetCommandParams p(LABEL_CODE);
1410 // Try to generate a valid label
1411 p["name"] = (cmd.argument().empty()) ?
1412 cur.getPossibleLabel() :
1414 string const data = InsetCommand::params2string("label", p);
1416 if (cmd.argument().empty()) {
1417 bv->showDialog("label", data);
1419 FuncRequest fr(LFUN_INSET_INSERT, data);
1425 case LFUN_INFO_INSERT: {
1427 if (cmd.argument().empty() && cur.selection()) {
1428 // if command argument is empty use current selection as parameter.
1429 docstring ds = cur.selectionAsString(false);
1430 cutSelection(cur, true, false);
1431 FuncRequest cmd0(cmd, ds);
1432 inset = createInset(cur.bv().buffer(), cmd0);
1434 inset = createInset(cur.bv().buffer(), cmd);
1438 insertInset(cur, inset);
1442 case LFUN_CAPTION_INSERT:
1443 case LFUN_FOOTNOTE_INSERT:
1444 case LFUN_NOTE_INSERT:
1445 case LFUN_FLEX_INSERT:
1446 case LFUN_BOX_INSERT:
1447 case LFUN_BRANCH_INSERT:
1448 case LFUN_PHANTOM_INSERT:
1449 case LFUN_ERT_INSERT:
1450 case LFUN_LISTING_INSERT:
1451 case LFUN_MARGINALNOTE_INSERT:
1452 case LFUN_OPTIONAL_INSERT:
1453 case LFUN_INDEX_INSERT:
1454 // Open the inset, and move the current selection
1456 doInsertInset(cur, this, cmd, true, true);
1458 // Some insets are numbered, others are shown in the outline pane so
1459 // let's update the labels and the toc backend.
1460 bv->buffer().updateLabels();
1463 case LFUN_TABULAR_INSERT:
1464 // if there were no arguments, just open the dialog
1465 if (doInsertInset(cur, this, cmd, false, true))
1468 bv->showDialog("tabularcreate");
1472 case LFUN_FLOAT_INSERT:
1473 case LFUN_FLOAT_WIDE_INSERT:
1474 case LFUN_WRAP_INSERT: {
1475 // will some text be moved into the inset?
1476 bool content = cur.selection();
1478 doInsertInset(cur, this, cmd, true, true);
1481 // If some text is moved into the inset, doInsertInset
1482 // puts the cursor outside the inset. To insert the
1483 // caption we put it back into the inset.
1487 ParagraphList & pars = cur.text()->paragraphs();
1489 DocumentClass const & tclass = bv->buffer().params().documentClass();
1491 // add a separate paragraph for the caption inset
1492 pars.push_back(Paragraph());
1493 pars.back().setInsetOwner(&pars[0].inInset());
1494 pars.back().setPlainOrDefaultLayout(tclass);
1495 int cap_pit = pars.size() - 1;
1497 // if an empty inset was created, we create an additional empty
1498 // paragraph at the bottom so that the user can choose where to put
1499 // the graphics (or table).
1501 pars.push_back(Paragraph());
1502 pars.back().setInsetOwner(&pars[0].inInset());
1503 pars.back().setPlainOrDefaultLayout(tclass);
1506 // reposition the cursor to the caption
1507 cur.pit() = cap_pit;
1509 // FIXME: This Text/Cursor dispatch handling is a mess!
1510 // We cannot use Cursor::dispatch here it needs access to up to
1512 FuncRequest cmd_caption(LFUN_CAPTION_INSERT);
1513 doInsertInset(cur, cur.text(), cmd_caption, true, false);
1514 bv->buffer().updateLabels();
1515 cur.updateFlags(Update::Force);
1516 // FIXME: When leaving the Float (or Wrap) inset we should
1517 // delete any empty paragraph left above or below the
1522 case LFUN_NOMENCL_INSERT: {
1523 InsetCommandParams p(NOMENCL_CODE);
1524 if (cmd.argument().empty())
1525 p["symbol"] = bv->cursor().innerText()->getStringToIndex(bv->cursor());
1527 p["symbol"] = cmd.argument();
1528 string const data = InsetCommand::params2string("nomenclature", p);
1529 bv->showDialog("nomenclature", data);
1533 case LFUN_INDEX_PRINT:
1534 case LFUN_NOMENCL_PRINT:
1535 case LFUN_TOC_INSERT:
1536 case LFUN_LINE_INSERT:
1537 case LFUN_NEWPAGE_INSERT:
1539 doInsertInset(cur, this, cmd, false, false);
1543 case LFUN_DEPTH_DECREMENT:
1544 changeDepth(cur, DEC_DEPTH);
1547 case LFUN_DEPTH_INCREMENT:
1548 changeDepth(cur, INC_DEPTH);
1551 case LFUN_MATH_DISPLAY:
1552 mathDispatch(cur, cmd, true);
1555 case LFUN_REGEXP_MODE:
1556 regexpDispatch(cur, cmd);
1559 case LFUN_MATH_MODE:
1560 if (cmd.argument() == "on")
1561 // don't pass "on" as argument
1562 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1564 mathDispatch(cur, cmd, false);
1567 case LFUN_MATH_MACRO:
1568 if (cmd.argument().empty())
1569 cur.errorMessage(from_utf8(N_("Missing argument")));
1571 string s = to_utf8(cmd.argument());
1572 string const s1 = token(s, ' ', 1);
1573 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1574 string const s2 = token(s, ' ', 2);
1575 MacroType type = MacroTypeNewcommand;
1577 type = MacroTypeDef;
1578 MathMacroTemplate * inset = new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, false, type);
1579 inset->setBuffer(bv->buffer());
1580 insertInset(cur, inset);
1582 // enter macro inset and select the name
1584 cur.top().pos() = cur.top().lastpos();
1586 cur.setSelection(true);
1587 cur.top().pos() = 0;
1591 // passthrough hat and underscore outside mathed:
1592 case LFUN_MATH_SUBSCRIPT:
1593 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1595 case LFUN_MATH_SUPERSCRIPT:
1596 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1599 case LFUN_MATH_INSERT:
1600 case LFUN_MATH_MATRIX:
1601 case LFUN_MATH_DELIM:
1602 case LFUN_MATH_BIGDELIM: {
1604 cap::replaceSelection(cur);
1605 cur.insert(new InsetMathHull(hullSimple));
1606 checkAndActivateInset(cur, true);
1607 LASSERT(cur.inMathed(), /**/);
1612 case LFUN_FONT_EMPH: {
1613 Font font(ignore_font, ignore_language);
1614 font.fontInfo().setEmph(FONT_TOGGLE);
1615 toggleAndShow(cur, this, font);
1619 case LFUN_FONT_ITAL: {
1620 Font font(ignore_font, ignore_language);
1621 font.fontInfo().setShape(ITALIC_SHAPE);
1622 toggleAndShow(cur, this, font);
1626 case LFUN_FONT_BOLD:
1627 case LFUN_FONT_BOLDSYMBOL: {
1628 Font font(ignore_font, ignore_language);
1629 font.fontInfo().setSeries(BOLD_SERIES);
1630 toggleAndShow(cur, this, font);
1634 case LFUN_FONT_NOUN: {
1635 Font font(ignore_font, ignore_language);
1636 font.fontInfo().setNoun(FONT_TOGGLE);
1637 toggleAndShow(cur, this, font);
1641 case LFUN_FONT_TYPEWRITER: {
1642 Font font(ignore_font, ignore_language);
1643 font.fontInfo().setFamily(TYPEWRITER_FAMILY); // no good
1644 toggleAndShow(cur, this, font);
1648 case LFUN_FONT_SANS: {
1649 Font font(ignore_font, ignore_language);
1650 font.fontInfo().setFamily(SANS_FAMILY);
1651 toggleAndShow(cur, this, font);
1655 case LFUN_FONT_ROMAN: {
1656 Font font(ignore_font, ignore_language);
1657 font.fontInfo().setFamily(ROMAN_FAMILY);
1658 toggleAndShow(cur, this, font);
1662 case LFUN_FONT_DEFAULT: {
1663 Font font(inherit_font, ignore_language);
1664 toggleAndShow(cur, this, font);
1668 case LFUN_FONT_UNDERLINE: {
1669 Font font(ignore_font, ignore_language);
1670 font.fontInfo().setUnderbar(FONT_TOGGLE);
1671 toggleAndShow(cur, this, font);
1675 case LFUN_FONT_SIZE: {
1676 Font font(ignore_font, ignore_language);
1677 setLyXSize(to_utf8(cmd.argument()), font.fontInfo());
1678 toggleAndShow(cur, this, font);
1682 case LFUN_LANGUAGE: {
1683 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1686 Font font(ignore_font, lang);
1687 toggleAndShow(cur, this, font);
1691 case LFUN_TEXTSTYLE_APPLY:
1692 toggleAndShow(cur, this, freefont, toggleall);
1693 cur.message(_("Character set"));
1696 // Set the freefont using the contents of \param data dispatched from
1697 // the frontends and apply it at the current cursor location.
1698 case LFUN_TEXTSTYLE_UPDATE: {
1701 if (font.fromString(to_utf8(cmd.argument()), toggle)) {
1704 toggleAndShow(cur, this, freefont, toggleall);
1705 cur.message(_("Character set"));
1707 lyxerr << "Argument not ok";
1712 case LFUN_FINISHED_LEFT:
1713 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_LEFT:\n" << cur);
1714 // We're leaving an inset, going left. If the inset is LTR, we're
1715 // leaving from the front, so we should not move (remain at --- but
1716 // not in --- the inset). If the inset is RTL, move left, without
1717 // entering the inset itself; i.e., move to after the inset.
1718 if (cur.paragraph().getFontSettings(
1719 cur.bv().buffer().params(), cur.pos()).isRightToLeft())
1720 cursorVisLeft(cur, true);
1723 case LFUN_FINISHED_RIGHT:
1724 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_RIGHT:\n" << cur);
1725 // We're leaving an inset, going right. If the inset is RTL, we're
1726 // leaving from the front, so we should not move (remain at --- but
1727 // not in --- the inset). If the inset is LTR, move right, without
1728 // entering the inset itself; i.e., move to after the inset.
1729 if (!cur.paragraph().getFontSettings(
1730 cur.bv().buffer().params(), cur.pos()).isRightToLeft())
1731 cursorVisRight(cur, true);
1734 case LFUN_FINISHED_BACKWARD:
1735 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_BACKWARD:\n" << cur);
1738 case LFUN_FINISHED_FORWARD:
1739 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_FORWARD:\n" << cur);
1741 cur.setCurrentFont();
1744 case LFUN_LAYOUT_PARAGRAPH: {
1746 params2string(cur.paragraph(), data);
1747 data = "show\n" + data;
1748 bv->showDialog("paragraph", data);
1752 case LFUN_PARAGRAPH_UPDATE: {
1754 params2string(cur.paragraph(), data);
1756 // Will the paragraph accept changes from the dialog?
1758 cur.inset().allowParagraphCustomization(cur.idx());
1760 data = "update " + convert<string>(accept) + '\n' + data;
1761 bv->updateDialog("paragraph", data);
1765 case LFUN_ACCENT_UMLAUT:
1766 case LFUN_ACCENT_CIRCUMFLEX:
1767 case LFUN_ACCENT_GRAVE:
1768 case LFUN_ACCENT_ACUTE:
1769 case LFUN_ACCENT_TILDE:
1770 case LFUN_ACCENT_CEDILLA:
1771 case LFUN_ACCENT_MACRON:
1772 case LFUN_ACCENT_DOT:
1773 case LFUN_ACCENT_UNDERDOT:
1774 case LFUN_ACCENT_UNDERBAR:
1775 case LFUN_ACCENT_CARON:
1776 case LFUN_ACCENT_BREVE:
1777 case LFUN_ACCENT_TIE:
1778 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1779 case LFUN_ACCENT_CIRCLE:
1780 case LFUN_ACCENT_OGONEK:
1781 theLyXFunc().handleKeyFunc(cmd.action);
1782 if (!cmd.argument().empty())
1783 // FIXME: Are all these characters encoded in one byte in utf8?
1784 bv->translateAndInsert(cmd.argument()[0], this, cur);
1787 case LFUN_FLOAT_LIST_INSERT: {
1788 DocumentClass const & tclass = bv->buffer().params().documentClass();
1789 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1791 if (cur.selection())
1792 cutSelection(cur, true, false);
1793 breakParagraph(cur);
1795 if (cur.lastpos() != 0) {
1796 cursorBackward(cur);
1797 breakParagraph(cur);
1800 docstring const laystr = cur.inset().usePlainLayout() ?
1801 tclass.plainLayoutName() :
1802 tclass.defaultLayoutName();
1803 setLayout(cur, laystr);
1804 ParagraphParameters p;
1805 // FIXME If this call were replaced with one to clearParagraphParams(),
1806 // then we could get rid of this method altogether.
1807 setParagraphs(cur, p);
1808 // FIXME This should be simplified when InsetFloatList takes a
1809 // Buffer in its constructor.
1810 InsetFloatList * ifl = new InsetFloatList(to_utf8(cmd.argument()));
1811 ifl->setBuffer(bv->buffer());
1812 insertInset(cur, ifl);
1815 lyxerr << "Non-existent float type: "
1816 << to_utf8(cmd.argument()) << endl;
1821 case LFUN_CHANGE_ACCEPT: {
1822 acceptOrRejectChanges(cur, ACCEPT);
1826 case LFUN_CHANGE_REJECT: {
1827 acceptOrRejectChanges(cur, REJECT);
1831 case LFUN_THESAURUS_ENTRY: {
1832 docstring arg = cmd.argument();
1834 arg = cur.selectionAsString(false);
1836 if (arg.size() > 100 || arg.empty()) {
1837 // Get word or selection
1838 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1839 arg = cur.selectionAsString(false);
1840 arg += " lang=" + from_ascii(cur.getFont().language()->lang());
1843 bv->showDialog("thesaurus", to_utf8(arg));
1847 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1848 // Given data, an encoding of the ParagraphParameters
1849 // generated in the Paragraph dialog, this function sets
1850 // the current paragraph, or currently selected paragraphs,
1852 // NOTE: This function overrides all existing settings.
1853 setParagraphs(cur, cmd.argument());
1854 cur.message(_("Paragraph layout set"));
1858 case LFUN_PARAGRAPH_PARAMS: {
1859 // Given data, an encoding of the ParagraphParameters as we'd
1860 // find them in a LyX file, this function modifies the current paragraph,
1861 // or currently selected paragraphs.
1862 // NOTE: This function only modifies, and does not override, existing
1864 setParagraphs(cur, cmd.argument(), true);
1865 cur.message(_("Paragraph layout set"));
1870 if (cur.selection()) {
1871 cur.setSelection(false);
1874 // This used to be LFUN_FINISHED_RIGHT, I think FORWARD is more
1875 // correct, but I'm not 100% sure -- dov, 071019
1876 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
1880 case LFUN_OUTLINE_UP:
1881 outline(OutlineUp, cur);
1882 setCursor(cur, cur.pit(), 0);
1883 cur.buffer()->updateLabels();
1887 case LFUN_OUTLINE_DOWN:
1888 outline(OutlineDown, cur);
1889 setCursor(cur, cur.pit(), 0);
1890 cur.buffer()->updateLabels();
1894 case LFUN_OUTLINE_IN:
1895 outline(OutlineIn, cur);
1896 cur.buffer()->updateLabels();
1900 case LFUN_OUTLINE_OUT:
1901 outline(OutlineOut, cur);
1902 cur.buffer()->updateLabels();
1907 LYXERR(Debug::ACTION, "Command " << cmd << " not DISPATCHED by Text");
1912 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1914 // FIXME: The cursor flag is reset two lines below
1915 // so we need to check here if some of the LFUN did touch that.
1916 // for now only Text::erase() and Text::backspace() do that.
1917 // The plan is to verify all the LFUNs and then to remove this
1918 // singleParUpdate boolean altogether.
1919 if (cur.result().update() & Update::Force) {
1920 singleParUpdate = false;
1924 // FIXME: the following code should go in favor of fine grained
1925 // update flag treatment.
1926 if (singleParUpdate) {
1927 // Inserting characters does not change par height in general. So, try
1928 // to update _only_ this paragraph. BufferView will detect if a full
1929 // metrics update is needed anyway.
1930 cur.updateFlags(Update::SinglePar | Update::FitCursor);
1935 && &oldTopSlice.inset() == &cur.inset()
1936 && oldTopSlice.idx() == cur.idx()
1937 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1938 && !cur.selection())
1939 // FIXME: it would be better if we could just do this
1941 //if (cur.result().update() != Update::FitCursor)
1944 // But some LFUNs do not set Update::FitCursor when needed, so we
1945 // do it for all. This is not very harmfull as FitCursor will provoke
1946 // a full redraw only if needed but still, a proper review of all LFUN
1947 // should be done and this needsUpdate boolean can then be removed.
1948 cur.updateFlags(Update::FitCursor);
1950 cur.updateFlags(Update::Force | Update::FitCursor);
1954 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
1955 FuncStatus & flag) const
1957 LASSERT(cur.text() == this, /**/);
1959 FontInfo const & fontinfo = cur.real_current_font.fontInfo();
1961 InsetCode code = NO_CODE;
1963 switch (cmd.action) {
1965 case LFUN_DEPTH_DECREMENT:
1966 enable = changeDepthAllowed(cur, DEC_DEPTH);
1969 case LFUN_DEPTH_INCREMENT:
1970 enable = changeDepthAllowed(cur, INC_DEPTH);
1974 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1977 case LFUN_DIALOG_SHOW_NEW_INSET:
1978 if (cmd.argument() == "bibitem")
1979 code = BIBITEM_CODE;
1980 else if (cmd.argument() == "bibtex")
1982 else if (cmd.argument() == "box")
1984 else if (cmd.argument() == "branch")
1986 else if (cmd.argument() == "citation")
1988 else if (cmd.argument() == "ert")
1990 else if (cmd.argument() == "external")
1991 code = EXTERNAL_CODE;
1992 else if (cmd.argument() == "float")
1994 else if (cmd.argument() == "graphics")
1995 code = GRAPHICS_CODE;
1996 else if (cmd.argument() == "href")
1997 code = HYPERLINK_CODE;
1998 else if (cmd.argument() == "include")
1999 code = INCLUDE_CODE;
2000 else if (cmd.argument() == "index")
2002 else if (cmd.argument() == "nomenclature")
2003 code = NOMENCL_CODE;
2004 else if (cmd.argument() == "label")
2006 else if (cmd.argument() == "note")
2008 else if (cmd.argument() == "phantom")
2009 code = PHANTOM_CODE;
2010 else if (cmd.argument() == "ref")
2012 else if (cmd.argument() == "space")
2014 else if (cmd.argument() == "toc")
2016 else if (cmd.argument() == "vspace")
2018 else if (cmd.argument() == "wrap")
2020 else if (cmd.argument() == "listings")
2021 code = LISTINGS_CODE;
2024 case LFUN_ERT_INSERT:
2027 case LFUN_LISTING_INSERT:
2028 code = LISTINGS_CODE;
2029 // not allowed in description items
2030 enable = !inDescriptionItem(cur);
2032 case LFUN_FOOTNOTE_INSERT:
2035 case LFUN_TABULAR_INSERT:
2036 code = TABULAR_CODE;
2038 case LFUN_MARGINALNOTE_INSERT:
2041 case LFUN_FLOAT_INSERT:
2042 case LFUN_FLOAT_WIDE_INSERT:
2044 // not allowed in description items
2045 enable = !inDescriptionItem(cur);
2047 case LFUN_WRAP_INSERT:
2049 // not allowed in description items
2050 enable = !inDescriptionItem(cur);
2052 case LFUN_FLOAT_LIST_INSERT:
2053 code = FLOAT_LIST_CODE;
2055 case LFUN_CAPTION_INSERT:
2056 code = CAPTION_CODE;
2057 // not allowed in description items
2058 enable = !inDescriptionItem(cur);
2060 case LFUN_NOTE_INSERT:
2062 // in commands (sections etc.) and description items,
2063 // only Notes are allowed
2064 enable = (cmd.argument().empty() || cmd.getArg(0) == "Note" ||
2065 (!cur.paragraph().layout().isCommand()
2066 && !inDescriptionItem(cur)));
2068 case LFUN_FLEX_INSERT: {
2070 string s = cmd.getArg(0);
2072 cur.buffer()->params().documentClass().insetLayout(from_utf8(s));
2073 if (il.lyxtype() != InsetLayout::CHARSTYLE &&
2074 il.lyxtype() != InsetLayout::CUSTOM &&
2075 il.lyxtype() != InsetLayout::ELEMENT &&
2076 il.lyxtype ()!= InsetLayout::STANDARD)
2080 case LFUN_BOX_INSERT:
2083 case LFUN_BRANCH_INSERT:
2085 if (cur.buffer()->masterBuffer()->params().branchlist().empty())
2088 case LFUN_PHANTOM_INSERT:
2089 code = PHANTOM_CODE;
2091 case LFUN_LABEL_INSERT:
2094 case LFUN_INFO_INSERT:
2097 case LFUN_OPTIONAL_INSERT:
2099 enable = cur.paragraph().insetList().count(OPTARG_CODE)
2100 < cur.paragraph().layout().optionalargs;
2102 case LFUN_INDEX_INSERT:
2105 case LFUN_INDEX_PRINT:
2106 code = INDEX_PRINT_CODE;
2108 case LFUN_NOMENCL_INSERT:
2109 if (cur.selIsMultiCell() || cur.selIsMultiLine()) {
2113 code = NOMENCL_CODE;
2115 case LFUN_NOMENCL_PRINT:
2116 code = NOMENCL_PRINT_CODE;
2118 case LFUN_TOC_INSERT:
2121 case LFUN_HYPERLINK_INSERT:
2122 if (cur.selIsMultiCell() || cur.selIsMultiLine()) {
2126 code = HYPERLINK_CODE;
2128 case LFUN_QUOTE_INSERT:
2129 // always allow this, since we will inset a raw quote
2130 // if an inset is not allowed.
2132 case LFUN_SPECIALCHAR_INSERT:
2133 code = SPECIALCHAR_CODE;
2135 case LFUN_SPACE_INSERT:
2136 // slight hack: we know this is allowed in math mode
2141 case LFUN_INSET_MODIFY:
2142 // We need to disable this, because we may get called for a
2144 // InsetTabular::getStatus() -> InsetText::getStatus()
2145 // and we don't handle LFUN_INSET_MODIFY.
2149 case LFUN_FONT_EMPH:
2150 flag.setOnOff(fontinfo.emph() == FONT_ON);
2153 case LFUN_FONT_ITAL:
2154 flag.setOnOff(fontinfo.shape() == ITALIC_SHAPE);
2157 case LFUN_FONT_NOUN:
2158 flag.setOnOff(fontinfo.noun() == FONT_ON);
2161 case LFUN_FONT_BOLD:
2162 case LFUN_FONT_BOLDSYMBOL:
2163 flag.setOnOff(fontinfo.series() == BOLD_SERIES);
2166 case LFUN_FONT_SANS:
2167 flag.setOnOff(fontinfo.family() == SANS_FAMILY);
2170 case LFUN_FONT_ROMAN:
2171 flag.setOnOff(fontinfo.family() == ROMAN_FAMILY);
2174 case LFUN_FONT_TYPEWRITER:
2175 flag.setOnOff(fontinfo.family() == TYPEWRITER_FAMILY);
2180 enable = cur.selection();
2184 if (cmd.argument().empty()) {
2185 if (theClipboard().isInternal())
2186 enable = cap::numberOfSelections() > 0;
2188 enable = !theClipboard().empty();
2192 // we have an argument
2193 string const arg = to_utf8(cmd.argument());
2194 if (isStrUnsignedInt(arg)) {
2195 // it's a number and therefore means the internal stack
2196 unsigned int n = convert<unsigned int>(arg);
2197 enable = cap::numberOfSelections() > n;
2201 // explicit graphics type?
2202 if ((arg == "pdf" && theClipboard().hasGraphicsContents(Clipboard::PdfGraphicsType))
2203 || (arg == "png" && theClipboard().hasGraphicsContents(Clipboard::PngGraphicsType))
2204 || (arg == "jpeg" && theClipboard().hasGraphicsContents(Clipboard::JpegGraphicsType))
2205 || (arg == "linkback" && theClipboard().hasGraphicsContents(Clipboard::LinkBackGraphicsType))) {
2215 case LFUN_CLIPBOARD_PASTE:
2216 enable = !theClipboard().empty();
2219 case LFUN_PRIMARY_SELECTION_PASTE:
2220 enable = cur.selection() || !theSelection().empty();
2223 case LFUN_SELECTION_PASTE:
2224 enable = cap::selection();
2227 case LFUN_PARAGRAPH_MOVE_UP:
2228 enable = cur.pit() > 0 && !cur.selection();
2231 case LFUN_PARAGRAPH_MOVE_DOWN:
2232 enable = cur.pit() < cur.lastpit() && !cur.selection();
2235 case LFUN_INSET_DISSOLVE:
2236 if (!cmd.argument().empty()) {
2237 InsetLayout const & il = cur.inset().getLayout(cur.buffer()->params());
2238 InsetLayout::InsetLyXType const type =
2239 translateLyXType(to_utf8(cmd.argument()));
2240 enable = cur.inset().lyxCode() == FLEX_CODE
2241 && il.lyxtype() == type;
2243 enable = ((!isMainText(cur.bv().buffer())
2244 && cur.inset().nargs() == 1)
2246 && cur.nextInset()->nargs() == 1));
2250 case LFUN_CHANGE_ACCEPT:
2251 case LFUN_CHANGE_REJECT:
2252 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
2253 // In principle, these LFUNs should only be enabled if there
2254 // is a change at the current position/in the current selection.
2255 // However, without proper optimizations, this will inevitably
2256 // result in unacceptable performance - just imagine a user who
2257 // wants to select the complete content of a long document.
2261 case LFUN_OUTLINE_UP:
2262 case LFUN_OUTLINE_DOWN:
2263 case LFUN_OUTLINE_IN:
2264 case LFUN_OUTLINE_OUT:
2265 // FIXME: LyX is not ready for outlining within inset.
2266 enable = isMainText(cur.bv().buffer())
2267 && cur.paragraph().layout().toclevel != Layout::NOT_IN_TOC;
2270 case LFUN_NEWLINE_INSERT:
2271 // LaTeX restrictions (labels or empty par)
2272 enable = (cur.pos() > cur.paragraph().beginOfBody());
2275 case LFUN_SET_GRAPHICS_GROUP: {
2276 InsetGraphics * ins = graphics::getCurrentGraphicsInset(cur);
2280 flag.setOnOff(to_utf8(cmd.argument()) == ins->getParams().groupId);
2284 case LFUN_NEWPAGE_INSERT:
2285 // not allowed in description items
2286 enable = !inDescriptionItem(cur);
2289 case LFUN_WORD_DELETE_FORWARD:
2290 case LFUN_WORD_DELETE_BACKWARD:
2291 case LFUN_LINE_DELETE:
2292 case LFUN_WORD_FORWARD:
2293 case LFUN_WORD_BACKWARD:
2294 case LFUN_WORD_RIGHT:
2295 case LFUN_WORD_LEFT:
2296 case LFUN_CHAR_FORWARD:
2297 case LFUN_CHAR_FORWARD_SELECT:
2298 case LFUN_CHAR_BACKWARD:
2299 case LFUN_CHAR_BACKWARD_SELECT:
2300 case LFUN_CHAR_LEFT:
2301 case LFUN_CHAR_LEFT_SELECT:
2302 case LFUN_CHAR_RIGHT:
2303 case LFUN_CHAR_RIGHT_SELECT:
2305 case LFUN_UP_SELECT:
2307 case LFUN_DOWN_SELECT:
2308 case LFUN_PARAGRAPH_UP_SELECT:
2309 case LFUN_PARAGRAPH_DOWN_SELECT:
2310 case LFUN_LINE_BEGIN_SELECT:
2311 case LFUN_LINE_END_SELECT:
2312 case LFUN_WORD_FORWARD_SELECT:
2313 case LFUN_WORD_BACKWARD_SELECT:
2314 case LFUN_WORD_RIGHT_SELECT:
2315 case LFUN_WORD_LEFT_SELECT:
2316 case LFUN_WORD_SELECT:
2317 case LFUN_PARAGRAPH_UP:
2318 case LFUN_PARAGRAPH_DOWN:
2319 case LFUN_LINE_BEGIN:
2321 case LFUN_CHAR_DELETE_FORWARD:
2322 case LFUN_CHAR_DELETE_BACKWARD:
2323 case LFUN_BREAK_PARAGRAPH:
2324 case LFUN_PARAGRAPH_SPACING:
2325 case LFUN_INSET_INSERT:
2326 case LFUN_WORD_UPCASE:
2327 case LFUN_WORD_LOWCASE:
2328 case LFUN_WORD_CAPITALIZE:
2329 case LFUN_CHARS_TRANSPOSE:
2330 case LFUN_SERVER_GET_XY:
2331 case LFUN_SERVER_SET_XY:
2332 case LFUN_SERVER_GET_LAYOUT:
2334 case LFUN_DATE_INSERT:
2335 case LFUN_SELF_INSERT:
2336 case LFUN_LINE_INSERT:
2337 case LFUN_MATH_DISPLAY:
2338 case LFUN_MATH_MODE:
2339 case LFUN_MATH_MACRO:
2340 case LFUN_MATH_MATRIX:
2341 case LFUN_MATH_DELIM:
2342 case LFUN_MATH_BIGDELIM:
2343 case LFUN_MATH_INSERT:
2344 case LFUN_MATH_SUBSCRIPT:
2345 case LFUN_MATH_SUPERSCRIPT:
2346 case LFUN_FONT_DEFAULT:
2347 case LFUN_FONT_UNDERLINE:
2348 case LFUN_FONT_SIZE:
2350 case LFUN_TEXTSTYLE_APPLY:
2351 case LFUN_TEXTSTYLE_UPDATE:
2352 case LFUN_LAYOUT_PARAGRAPH:
2353 case LFUN_PARAGRAPH_UPDATE:
2354 case LFUN_ACCENT_UMLAUT:
2355 case LFUN_ACCENT_CIRCUMFLEX:
2356 case LFUN_ACCENT_GRAVE:
2357 case LFUN_ACCENT_ACUTE:
2358 case LFUN_ACCENT_TILDE:
2359 case LFUN_ACCENT_CEDILLA:
2360 case LFUN_ACCENT_MACRON:
2361 case LFUN_ACCENT_DOT:
2362 case LFUN_ACCENT_UNDERDOT:
2363 case LFUN_ACCENT_UNDERBAR:
2364 case LFUN_ACCENT_CARON:
2365 case LFUN_ACCENT_BREVE:
2366 case LFUN_ACCENT_TIE:
2367 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
2368 case LFUN_ACCENT_CIRCLE:
2369 case LFUN_ACCENT_OGONEK:
2370 case LFUN_THESAURUS_ENTRY:
2371 case LFUN_PARAGRAPH_PARAMS_APPLY:
2372 case LFUN_PARAGRAPH_PARAMS:
2374 case LFUN_BUFFER_END:
2375 case LFUN_BUFFER_BEGIN:
2376 case LFUN_BUFFER_BEGIN_SELECT:
2377 case LFUN_BUFFER_END_SELECT:
2378 case LFUN_UNICODE_INSERT:
2379 // these are handled in our dispatch()
2388 && (cur.empty() || !cur.inset().insetAllowed(code)))
2391 flag.setEnabled(enable);
2396 void Text::pasteString(Cursor & cur, docstring const & clip,
2399 cur.clearSelection();
2400 if (!clip.empty()) {
2403 insertStringAsParagraphs(cur, clip);
2405 insertStringAsLines(cur, clip);
2410 // FIXME: an item inset would make things much easier.
2411 bool Text::inDescriptionItem(Cursor & cur) const
2413 Paragraph & par = cur.paragraph();
2414 pos_type const pos = cur.pos();
2415 pos_type const body_pos = par.beginOfBody();
2417 if (par.layout().latextype != LATEX_LIST_ENVIRONMENT
2418 && (par.layout().latextype != LATEX_ITEM_ENVIRONMENT
2419 || par.layout().margintype != MARGIN_FIRST_DYNAMIC))
2422 return (pos < body_pos
2424 && (pos == 0 || par.getChar(pos - 1) != ' ')));