3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Asger Alstrup
7 * \author Lars Gullik Bjønnes
8 * \author Alfredo Braunstein
9 * \author Angus Leeming
11 * \author André Pönitz
13 * Full author contact details are available in file CREDITS.
21 #include "BranchList.h"
22 #include "FloatList.h"
23 #include "FuncStatus.h"
25 #include "buffer_funcs.h"
26 #include "BufferParams.h"
27 #include "BufferView.h"
30 #include "CutAndPaste.h"
31 #include "DispatchResult.h"
32 #include "ErrorList.h"
34 #include "FuncRequest.h"
35 #include "InsetList.h"
39 #include "LyXAction.h"
43 #include "Paragraph.h"
44 #include "paragraph_funcs.h"
45 #include "ParagraphParameters.h"
46 #include "TextClass.h"
47 #include "TextMetrics.h"
50 #include "frontends/Application.h"
51 #include "frontends/Clipboard.h"
52 #include "frontends/LyXView.h"
53 #include "frontends/Selection.h"
54 #include "frontends/WorkArea.h"
56 #include "insets/InsetCollapsable.h"
57 #include "insets/InsetCommand.h"
58 #include "insets/InsetExternal.h"
59 #include "insets/InsetFloatList.h"
60 #include "insets/InsetGraphics.h"
61 #include "insets/InsetGraphicsParams.h"
62 #include "insets/InsetNewline.h"
63 #include "insets/InsetQuotes.h"
64 #include "insets/InsetSpecialChar.h"
65 #include "insets/InsetText.h"
67 #include "support/convert.h"
68 #include "support/debug.h"
69 #include "support/gettext.h"
70 #include "support/lstrings.h"
71 #include "support/lyxtime.h"
72 #include "support/os.h"
74 #include "mathed/InsetMathHull.h"
75 #include "mathed/MathMacroTemplate.h"
77 #include <boost/next_prior.hpp>
83 using namespace lyx::support;
87 using cap::copySelection;
88 using cap::cutSelection;
89 using cap::pasteFromStack;
90 using cap::pasteClipboardText;
91 using cap::pasteClipboardGraphics;
92 using cap::replaceSelection;
93 using cap::grabAndEraseSelection;
94 using cap::selClearOrDel;
97 static Font freefont(ignore_font, ignore_language);
98 static bool toggleall = false;
100 static void toggleAndShow(Cursor & cur, Text * text,
101 Font const & font, bool toggleall = true)
103 text->toggleFree(cur, font, toggleall);
105 if (font.language() != ignore_language ||
106 font.fontInfo().number() != FONT_IGNORE) {
107 TextMetrics const & tm = cur.bv().textMetrics(text);
108 if (cur.boundary() != tm.isRTLBoundary(cur.pit(), cur.pos(),
109 cur.real_current_font))
110 text->setCursor(cur, cur.pit(), cur.pos(),
111 false, !cur.boundary());
116 static void moveCursor(Cursor & cur, bool selecting)
118 if (selecting || cur.mark())
123 static void finishChange(Cursor & cur, bool selecting)
126 moveCursor(cur, selecting);
130 static void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
133 docstring sel = cur.selectionAsString(false);
135 // It may happen that sel is empty but there is a selection
136 replaceSelection(cur);
138 // Is this a valid formula?
142 #ifdef ENABLE_ASSERTIONS
143 const int old_pos = cur.pos();
145 cur.insert(new InsetMathHull(hullSimple));
146 #ifdef ENABLE_ASSERTIONS
147 LASSERT(old_pos == cur.pos(), /**/);
149 cur.nextInset()->edit(cur, true);
150 // don't do that also for LFUN_MATH_MODE
151 // unless you want end up with always changing
152 // to mathrm when opening an inlined inset --
153 // I really hate "LyXfunc overloading"...
155 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
156 // Avoid an unnecessary undo step if cmd.argument
158 if (!cmd.argument().empty())
159 cur.dispatch(FuncRequest(LFUN_MATH_INSERT,
162 // create a macro if we see "\\newcommand"
163 // somewhere, and an ordinary formula
165 if (sel.find(from_ascii("\\newcommand")) == string::npos
166 && sel.find(from_ascii("\\newlyxcommand")) == string::npos
167 && sel.find(from_ascii("\\def")) == string::npos)
169 InsetMathHull * formula = new InsetMathHull;
170 string const selstr = to_utf8(sel);
171 istringstream is(selstr);
174 if (!formula->readQuiet(lex)) {
175 // No valid formula, let's try with delims
176 is.str("$" + selstr + "$");
178 if (!formula->readQuiet(lex)) {
179 // Still not valid, leave it as is
188 cur.insert(new MathMacroTemplate(sel));
192 cur.message(from_utf8(N_("Math editor mode")));
194 cur.message(from_utf8(N_("No valid math formula")));
198 void regexpDispatch(Cursor & cur, FuncRequest const & cmd)
200 BOOST_ASSERT(cmd.action == LFUN_REGEXP_MODE);
201 if (cur.inRegexped()) {
202 cur.message(_("Already in regexp mode"));
206 docstring const save_selection = grabAndEraseSelection(cur);
208 // replaceSelection(cur);
210 cur.insert(new InsetMathHull(hullRegexp));
211 cur.nextInset()->edit(cur, true);
212 cur.niceInsert(save_selection);
214 cur.message(_("Regexp editor mode"));
218 static void specialChar(Cursor & cur, InsetSpecialChar::Kind kind)
221 cap::replaceSelection(cur);
222 cur.insert(new InsetSpecialChar(kind));
227 static bool doInsertInset(Cursor & cur, Text * text,
228 FuncRequest const & cmd, bool edit, bool pastesel)
230 Buffer & buffer = cur.bv().buffer();
231 BufferParams const & bparams = buffer.params();
232 Inset * inset = createInset(buffer, cmd);
236 if (InsetCollapsable * ci = inset->asInsetCollapsable())
237 ci->setLayout(bparams);
240 if (cmd.action == LFUN_INDEX_INSERT) {
241 docstring ds = subst(text->getStringToIndex(cur), '\n', ' ');
242 text->insertInset(cur, inset);
244 inset->edit(cur, true);
245 // Now put this into inset
246 static_cast<InsetCollapsable *>(inset)->
247 text().insertStringAsParagraphs(cur, ds);
252 if (cur.selection()) {
253 cutSelection(cur, false, pastesel);
254 cur.clearSelection();
257 text->insertInset(cur, inset);
260 inset->edit(cur, true);
262 if (!gotsel || !pastesel)
265 pasteFromStack(cur, cur.buffer()->errorList("Paste"), 0);
266 cur.buffer()->errors("Paste");
267 cur.clearSelection(); // bug 393
269 InsetText * insetText = dynamic_cast<InsetText *>(inset);
270 if (insetText && (!insetText->allowMultiPar() || cur.lastpit() == 0)) {
271 // reset first par to default
272 cur.text()->paragraphs().begin()
273 ->setPlainOrDefaultLayout(bparams.documentClass());
276 // Merge multiple paragraphs -- hack
277 while (cur.lastpit() > 0)
278 mergeParagraph(bparams, cur.text()->paragraphs(), 0);
279 cur.leaveInset(*inset);
281 cur.leaveInset(*inset);
282 // reset surrounding par to default
283 DocumentClass const & dc = bparams.documentClass();
284 docstring const layoutname = inset->usePlainLayout()
285 ? dc.plainLayoutName()
286 : dc.defaultLayoutName();
287 text->setLayout(cur, layoutname);
294 string const freefont2string()
296 return freefont.toString(toggleall);
300 /// the type of outline operation
302 OutlineUp, // Move this header with text down
303 OutlineDown, // Move this header with text up
304 OutlineIn, // Make this header deeper
305 OutlineOut // Make this header shallower
309 static void outline(OutlineOp mode, Cursor & cur)
311 Buffer & buf = *cur.buffer();
312 pit_type & pit = cur.pit();
313 ParagraphList & pars = buf.text().paragraphs();
314 ParagraphList::iterator const bgn = pars.begin();
315 // The first paragraph of the area to be copied:
316 ParagraphList::iterator start = boost::next(bgn, pit);
317 // The final paragraph of area to be copied:
318 ParagraphList::iterator finish = start;
319 ParagraphList::iterator const end = pars.end();
321 DocumentClass const & tc = buf.params().documentClass();
323 int const thistoclevel = start->layout().toclevel;
326 // Move out (down) from this section header
329 // Seek the one (on same level) below
330 for (; finish != end; ++finish) {
331 toclevel = finish->layout().toclevel;
332 if (toclevel != Layout::NOT_IN_TOC && toclevel <= thistoclevel)
336 // Do we need to set insets' buffer_ members, because we copied
337 // some stuff? We'll assume we do and reset it otherwise.
338 bool setBuffers = true;
342 if (start == pars.begin())
345 ParagraphList::iterator dest = start;
346 // Move out (up) from this header
349 // Search previous same-level header above
352 toclevel = dest->layout().toclevel;
354 && (toclevel == Layout::NOT_IN_TOC
355 || toclevel > thistoclevel));
356 // Not found; do nothing
357 if (toclevel == Layout::NOT_IN_TOC || toclevel > thistoclevel)
359 pit_type const newpit = distance(bgn, dest);
360 pit_type const len = distance(start, finish);
361 pit_type const deletepit = pit + len;
362 buf.undo().recordUndo(cur, ATOMIC_UNDO, newpit, deletepit - 1);
363 pars.insert(dest, start, finish);
364 start = boost::next(pars.begin(), deletepit);
366 pars.erase(start, finish);
373 // Go one down from *this* header:
374 ParagraphList::iterator dest = boost::next(finish, 1);
375 // Go further down to find header to insert in front of:
376 for (; dest != end; ++dest) {
377 toclevel = dest->layout().toclevel;
378 if (toclevel != Layout::NOT_IN_TOC
379 && toclevel <= thistoclevel)
382 // One such was found:
383 pit_type newpit = distance(bgn, dest);
384 pit_type const len = distance(start, finish);
385 buf.undo().recordUndo(cur, ATOMIC_UNDO, pit, newpit - 1);
386 pars.insert(dest, start, finish);
387 start = boost::next(bgn, pit);
389 pars.erase(start, finish);
393 pit_type const len = distance(start, finish);
394 buf.undo().recordUndo(cur, ATOMIC_UNDO, pit, pit + len - 1);
395 for (; start != finish; ++start) {
396 toclevel = start->layout().toclevel;
397 if (toclevel == Layout::NOT_IN_TOC)
399 DocumentClass::const_iterator lit = tc.begin();
400 DocumentClass::const_iterator len = tc.end();
401 for (; lit != len; ++lit) {
402 if (lit->toclevel == toclevel + 1 &&
403 start->layout().labeltype == lit->labeltype) {
404 start->setLayout(*lit);
413 pit_type const len = distance(start, finish);
414 buf.undo().recordUndo(cur, ATOMIC_UNDO, pit, pit + len - 1);
415 for (; start != finish; ++start) {
416 toclevel = start->layout().toclevel;
417 if (toclevel == Layout::NOT_IN_TOC)
419 DocumentClass::const_iterator lit = tc.begin();
420 DocumentClass::const_iterator len = tc.end();
421 for (; lit != len; ++lit) {
422 if (lit->toclevel == toclevel - 1 &&
423 start->layout().labeltype == lit->labeltype) {
424 start->setLayout(*lit);
434 // FIXME This only really needs doing for the newly introduced
435 // paragraphs. Something like:
436 // pit_type const numpars = distance(start, finish);
437 // start = boost::next(bgn, pit);
438 // finish = boost::next(start, numpars);
439 // for (; start != finish; ++start)
440 // start->setBuffer(buf);
441 // But while this seems to work, it is kind of fragile.
442 buf.inset().setBuffer(buf);
446 void Text::number(Cursor & cur)
448 FontInfo font = ignore_font;
449 font.setNumber(FONT_TOGGLE);
450 toggleAndShow(cur, this, Font(font, ignore_language));
454 bool Text::isRTL(Buffer const & buffer, Paragraph const & par) const
456 return par.isRTL(buffer.params());
460 void Text::dispatch(Cursor & cur, FuncRequest & cmd)
462 LYXERR(Debug::ACTION, "Text::dispatch: cmd: " << cmd);
464 BufferView * bv = &cur.bv();
465 TextMetrics & tm = bv->textMetrics(this);
466 if (!tm.contains(cur.pit())) {
467 lyx::dispatch(FuncRequest(LFUN_SCREEN_SHOW_CURSOR));
468 tm = bv->textMetrics(this);
471 // FIXME: We use the update flag to indicates wether a singlePar or a
472 // full screen update is needed. We reset it here but shall we restore it
476 LASSERT(cur.text() == this, /**/);
477 CursorSlice oldTopSlice = cur.top();
478 bool oldBoundary = cur.boundary();
479 bool sel = cur.selection();
480 // Signals that, even if needsUpdate == false, an update of the
481 // cursor paragraph is required
482 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
483 LyXAction::SingleParUpdate);
484 // Signals that a full-screen update is required
485 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
486 LyXAction::NoUpdate) || singleParUpdate);
488 switch (cmd.action) {
490 case LFUN_PARAGRAPH_MOVE_DOWN: {
491 pit_type const pit = cur.pit();
492 recUndo(cur, pit, pit + 1);
494 swap(pars_[pit], pars_[pit + 1]);
495 cur.buffer()->updateLabels();
501 case LFUN_PARAGRAPH_MOVE_UP: {
502 pit_type const pit = cur.pit();
503 recUndo(cur, pit - 1, pit);
505 swap(pars_[pit], pars_[pit - 1]);
506 cur.buffer()->updateLabels();
512 case LFUN_APPENDIX: {
513 Paragraph & par = cur.paragraph();
514 bool start = !par.params().startOfAppendix();
516 // FIXME: The code below only makes sense at top level.
517 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
518 // ensure that we have only one start_of_appendix in this document
519 // FIXME: this don't work for multipart document!
520 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
521 if (pars_[tmp].params().startOfAppendix()) {
523 pars_[tmp].params().startOfAppendix(false);
529 par.params().startOfAppendix(start);
531 // we can set the refreshing parameters now
532 cur.buffer()->updateLabels();
536 case LFUN_WORD_DELETE_FORWARD:
538 cutSelection(cur, true, false);
540 deleteWordForward(cur);
541 finishChange(cur, false);
544 case LFUN_WORD_DELETE_BACKWARD:
546 cutSelection(cur, true, false);
548 deleteWordBackward(cur);
549 finishChange(cur, false);
552 case LFUN_LINE_DELETE:
554 cutSelection(cur, true, false);
556 tm.deleteLineForward(cur);
557 finishChange(cur, false);
560 case LFUN_BUFFER_BEGIN:
561 case LFUN_BUFFER_BEGIN_SELECT:
562 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
563 if (cur.depth() == 1)
564 needsUpdate |= cursorTop(cur);
567 cur.updateFlags(Update::FitCursor);
570 case LFUN_BUFFER_END:
571 case LFUN_BUFFER_END_SELECT:
572 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
573 if (cur.depth() == 1)
574 needsUpdate |= cursorBottom(cur);
577 cur.updateFlags(Update::FitCursor);
580 case LFUN_INSET_BEGIN:
581 case LFUN_INSET_BEGIN_SELECT:
582 needsUpdate |= cur.selHandle(cmd.action == LFUN_INSET_BEGIN_SELECT);
583 if (cur.depth() == 1 || cur.pos() > 0)
584 needsUpdate |= cursorTop(cur);
587 cur.updateFlags(Update::FitCursor);
591 case LFUN_INSET_END_SELECT:
592 needsUpdate |= cur.selHandle(cmd.action == LFUN_INSET_END_SELECT);
593 if (cur.depth() == 1 || cur.pos() < cur.lastpos())
594 needsUpdate |= cursorBottom(cur);
597 cur.updateFlags(Update::FitCursor);
600 case LFUN_CHAR_FORWARD:
601 case LFUN_CHAR_FORWARD_SELECT:
602 //LYXERR0(" LFUN_CHAR_FORWARD[SEL]:\n" << cur);
603 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
604 needsUpdate |= cursorForward(cur);
606 if (!needsUpdate && oldTopSlice == cur.top()
607 && cur.boundary() == oldBoundary) {
609 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
611 // we will probably be moving out the inset, so we should execute
612 // the depm-mechanism, but only when the cursor has a place to
613 // go outside this inset, i.e. in a slice above.
614 if (cur.depth() > 1 && cur.pos() == cur.lastpos()
615 && cur.pit() == cur.lastpit()) {
616 // The cursor hasn't changed yet. To give the
617 // DEPM the possibility of doing something we must
618 // provide it with two different cursors.
620 dummy.pos() = dummy.pit() = 0;
621 cur.bv().checkDepm(dummy, cur);
626 case LFUN_CHAR_BACKWARD:
627 case LFUN_CHAR_BACKWARD_SELECT:
628 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
629 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
630 needsUpdate |= cursorBackward(cur);
632 if (!needsUpdate && oldTopSlice == cur.top()
633 && cur.boundary() == oldBoundary) {
635 cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
637 // we will probably be moving out the inset, so we should execute
638 // the depm-mechanism, but only when the cursor has a place to
639 // go outside this inset, i.e. in a slice above.
640 if (cur.depth() > 1 && cur.pos() == 0 && cur.pit() == 0) {
641 // The cursor hasn't changed yet. To give the
642 // DEPM the possibility of doing something we must
643 // provide it with two different cursors.
645 dummy.pos() = cur.lastpos();
646 dummy.pit() = cur.lastpit();
647 cur.bv().checkDepm(dummy, cur);
653 case LFUN_CHAR_LEFT_SELECT:
654 if (lyxrc.visual_cursor) {
655 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_LEFT_SELECT);
656 needsUpdate |= cursorVisLeft(cur);
657 if (!needsUpdate && oldTopSlice == cur.top()
658 && cur.boundary() == oldBoundary) {
660 cmd = FuncRequest(LFUN_FINISHED_LEFT);
663 if (reverseDirectionNeeded(cur)) {
664 cmd.action = cmd.action == LFUN_CHAR_LEFT_SELECT ?
665 LFUN_CHAR_FORWARD_SELECT : LFUN_CHAR_FORWARD;
667 cmd.action = cmd.action == LFUN_CHAR_LEFT_SELECT ?
668 LFUN_CHAR_BACKWARD_SELECT : LFUN_CHAR_BACKWARD;
675 case LFUN_CHAR_RIGHT:
676 case LFUN_CHAR_RIGHT_SELECT:
677 if (lyxrc.visual_cursor) {
678 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_RIGHT_SELECT);
679 needsUpdate |= cursorVisRight(cur);
680 if (!needsUpdate && oldTopSlice == cur.top()
681 && cur.boundary() == oldBoundary) {
683 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
686 if (reverseDirectionNeeded(cur)) {
687 cmd.action = cmd.action == LFUN_CHAR_RIGHT_SELECT ?
688 LFUN_CHAR_BACKWARD_SELECT : LFUN_CHAR_BACKWARD;
690 cmd.action = cmd.action == LFUN_CHAR_RIGHT_SELECT ?
691 LFUN_CHAR_FORWARD_SELECT : LFUN_CHAR_FORWARD;
700 case LFUN_DOWN_SELECT:
703 // stop/start the selection
704 bool select = cmd.action == LFUN_DOWN_SELECT ||
705 cmd.action == LFUN_UP_SELECT;
707 // move cursor up/down
708 bool up = cmd.action == LFUN_UP_SELECT || cmd.action == LFUN_UP;
709 bool const atFirstOrLastRow = cur.atFirstOrLastRow(up);
711 if (!atFirstOrLastRow) {
712 needsUpdate |= cur.selHandle(select);
713 cur.selHandle(select);
714 cur.upDownInText(up, needsUpdate);
715 needsUpdate |= cur.beforeDispatchCursor().inMathed();
717 // if the cursor cannot be moved up or down do not remove
718 // the selection right now, but wait for the next dispatch.
720 needsUpdate |= cur.selHandle(select);
721 cur.upDownInText(up, needsUpdate);
728 case LFUN_PARAGRAPH_UP:
729 case LFUN_PARAGRAPH_UP_SELECT:
730 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
731 needsUpdate |= cursorUpParagraph(cur);
734 case LFUN_PARAGRAPH_DOWN:
735 case LFUN_PARAGRAPH_DOWN_SELECT:
736 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
737 needsUpdate |= cursorDownParagraph(cur);
740 case LFUN_LINE_BEGIN:
741 case LFUN_LINE_BEGIN_SELECT:
742 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
743 needsUpdate |= tm.cursorHome(cur);
747 case LFUN_LINE_END_SELECT:
748 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
749 needsUpdate |= tm.cursorEnd(cur);
752 case LFUN_SECTION_SELECT: {
753 Buffer const & buf = *cur.buffer();
754 pit_type const pit = cur.pit();
755 ParagraphList & pars = buf.text().paragraphs();
756 ParagraphList::iterator bgn = pars.begin();
757 // The first paragraph of the area to be selected:
758 ParagraphList::iterator start = boost::next(bgn, pit);
759 // The final paragraph of area to be selected:
760 ParagraphList::iterator finish = start;
761 ParagraphList::iterator end = pars.end();
763 int const thistoclevel = start->layout().toclevel;
764 if (thistoclevel == Layout::NOT_IN_TOC)
768 Cursor const old_cur = cur;
769 needsUpdate |= cur.selHandle(true);
771 // Move out (down) from this section header
775 // Seek the one (on same level) below
776 for (; finish != end; ++finish, ++cur.pit()) {
777 int const toclevel = finish->layout().toclevel;
778 if (toclevel != Layout::NOT_IN_TOC && toclevel <= thistoclevel)
781 cur.pos() = cur.lastpos();
783 needsUpdate |= cur != old_cur;
787 case LFUN_WORD_RIGHT:
788 case LFUN_WORD_RIGHT_SELECT:
789 if (lyxrc.visual_cursor) {
790 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_RIGHT_SELECT);
791 needsUpdate |= cursorVisRightOneWord(cur);
792 if (!needsUpdate && oldTopSlice == cur.top()
793 && cur.boundary() == oldBoundary) {
795 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
798 if (reverseDirectionNeeded(cur)) {
799 cmd.action = cmd.action == LFUN_WORD_RIGHT_SELECT ?
800 LFUN_WORD_BACKWARD_SELECT : LFUN_WORD_BACKWARD;
802 cmd.action = cmd.action == LFUN_WORD_RIGHT_SELECT ?
803 LFUN_WORD_FORWARD_SELECT : LFUN_WORD_FORWARD;
810 case LFUN_WORD_FORWARD:
811 case LFUN_WORD_FORWARD_SELECT:
812 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
813 needsUpdate |= cursorForwardOneWord(cur);
817 case LFUN_WORD_LEFT_SELECT:
818 if (lyxrc.visual_cursor) {
819 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_LEFT_SELECT);
820 needsUpdate |= cursorVisLeftOneWord(cur);
821 if (!needsUpdate && oldTopSlice == cur.top()
822 && cur.boundary() == oldBoundary) {
824 cmd = FuncRequest(LFUN_FINISHED_LEFT);
827 if (reverseDirectionNeeded(cur)) {
828 cmd.action = cmd.action == LFUN_WORD_LEFT_SELECT ?
829 LFUN_WORD_FORWARD_SELECT : LFUN_WORD_FORWARD;
831 cmd.action = cmd.action == LFUN_WORD_LEFT_SELECT ?
832 LFUN_WORD_BACKWARD_SELECT : LFUN_WORD_BACKWARD;
839 case LFUN_WORD_BACKWARD:
840 case LFUN_WORD_BACKWARD_SELECT:
841 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
842 needsUpdate |= cursorBackwardOneWord(cur);
845 case LFUN_WORD_SELECT: {
846 selectWord(cur, WHOLE_WORD);
847 finishChange(cur, true);
851 case LFUN_NEWLINE_INSERT: {
852 InsetNewlineParams inp;
853 docstring arg = cmd.argument();
854 // this avoids a double undo
855 // FIXME: should not be needed, ideally
856 if (!cur.selection())
858 cap::replaceSelection(cur);
859 if (arg == "linebreak")
860 inp.kind = InsetNewlineParams::LINEBREAK;
862 inp.kind = InsetNewlineParams::NEWLINE;
863 cur.insert(new InsetNewline(inp));
865 moveCursor(cur, false);
869 case LFUN_CHAR_DELETE_FORWARD:
870 if (!cur.selection()) {
871 if (cur.pos() == cur.paragraph().size())
872 // Par boundary, force full-screen update
873 singleParUpdate = false;
874 needsUpdate |= erase(cur);
876 // It is possible to make it a lot faster still
877 // just comment out the line below...
879 cutSelection(cur, true, false);
880 singleParUpdate = false;
882 moveCursor(cur, false);
885 case LFUN_CHAR_DELETE_BACKWARD:
886 if (!cur.selection()) {
887 if (bv->getIntl().getTransManager().backspace()) {
888 // Par boundary, full-screen update
890 singleParUpdate = false;
891 needsUpdate |= backspace(cur);
893 // It is possible to make it a lot faster still
894 // just comment out the line below...
897 cutSelection(cur, true, false);
898 singleParUpdate = false;
902 case LFUN_BREAK_PARAGRAPH:
903 cap::replaceSelection(cur);
904 breakParagraph(cur, cmd.argument() == "inverse");
909 // With the creation of LFUN_PARAGRAPH_PARAMS, this is now redundant,
910 // as its duties can be performed there. Should it be removed??
911 // FIXME For now, it can just dispatch LFUN_PARAGRAPH_PARAMS...
912 case LFUN_PARAGRAPH_SPACING: {
913 Paragraph & par = cur.paragraph();
914 Spacing::Space cur_spacing = par.params().spacing().getSpace();
915 string cur_value = "1.0";
916 if (cur_spacing == Spacing::Other)
917 cur_value = par.params().spacing().getValueAsString();
919 istringstream is(to_utf8(cmd.argument()));
922 Spacing::Space new_spacing = cur_spacing;
923 string new_value = cur_value;
925 lyxerr << "Missing argument to `paragraph-spacing'"
927 } else if (tmp == "single") {
928 new_spacing = Spacing::Single;
929 } else if (tmp == "onehalf") {
930 new_spacing = Spacing::Onehalf;
931 } else if (tmp == "double") {
932 new_spacing = Spacing::Double;
933 } else if (tmp == "other") {
934 new_spacing = Spacing::Other;
935 string tmpval = "0.0";
937 lyxerr << "new_value = " << tmpval << endl;
940 } else if (tmp == "default") {
941 new_spacing = Spacing::Default;
943 lyxerr << to_utf8(_("Unknown spacing argument: "))
944 << to_utf8(cmd.argument()) << endl;
946 if (cur_spacing != new_spacing || cur_value != new_value)
947 par.params().spacing(Spacing(new_spacing, new_value));
951 case LFUN_INSET_INSERT: {
954 // We have to avoid triggering InstantPreview loading
955 // before inserting into the document. See bug #5626.
956 bool loaded = bv->buffer().isFullyLoaded();
957 bv->buffer().setFullyLoaded(false);
958 Inset * inset = createInset(bv->buffer(), cmd);
959 bv->buffer().setFullyLoaded(loaded);
962 // FIXME (Abdel 01/02/2006):
963 // What follows would be a partial fix for bug 2154:
964 // http://bugzilla.lyx.org/show_bug.cgi?id=2154
965 // This automatically put the label inset _after_ a
966 // numbered section. It should be possible to extend the mechanism
967 // to any kind of LateX environement.
968 // The correct way to fix that bug would be at LateX generation.
969 // I'll let the code here for reference as it could be used for some
970 // other feature like "automatic labelling".
972 Paragraph & par = pars_[cur.pit()];
973 if (inset->lyxCode() == LABEL_CODE
974 && par.layout().labeltype == LABEL_COUNTER) {
975 // Go to the end of the paragraph
976 // Warning: Because of Change-Tracking, the last
977 // position is 'size()' and not 'size()-1':
978 cur.pos() = par.size();
979 // Insert a new paragraph
980 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
985 cutSelection(cur, true, false);
989 // trigger InstantPreview now
990 if (inset->lyxCode() == EXTERNAL_CODE) {
991 InsetExternal & ins =
992 static_cast<InsetExternal &>(*inset);
1000 case LFUN_INSET_DISSOLVE: {
1001 // first, try if there's an inset at cursor
1002 // FIXME: this first part should be moved to
1003 // a LFUN_NEXT_INSET_DISSOLVE, or be called via
1004 // some generic "next-inset inset-dissolve"
1005 Inset * inset = cur.nextInset();
1006 if (inset && inset->isActive()) {
1007 Cursor tmpcur = cur;
1008 tmpcur.pushBackward(*inset);
1009 inset->dispatch(tmpcur, cmd);
1010 if (tmpcur.result().dispatched()) {
1015 // if it did not work, try the underlying inset
1016 if (dissolveInset(cur)) {
1020 // if it did not work, do nothing.
1024 case LFUN_SET_GRAPHICS_GROUP: {
1025 InsetGraphics * ins = graphics::getCurrentGraphicsInset(cur);
1031 string id = to_utf8(cmd.argument());
1032 string grp = graphics::getGroupParams(bv->buffer(), id);
1033 InsetGraphicsParams tmp, inspar = ins->getParams();
1036 inspar.groupId = to_utf8(cmd.argument());
1038 InsetGraphics::string2params(grp, bv->buffer(), tmp);
1039 tmp.filename = inspar.filename;
1043 ins->setParams(inspar);
1046 case LFUN_SPACE_INSERT:
1047 if (cur.paragraph().layout().free_spacing)
1048 insertChar(cur, ' ');
1050 doInsertInset(cur, this, cmd, false, false);
1053 moveCursor(cur, false);
1056 case LFUN_SPECIALCHAR_INSERT: {
1057 string const name = to_utf8(cmd.argument());
1058 if (name == "hyphenation")
1059 specialChar(cur, InsetSpecialChar::HYPHENATION);
1060 else if (name == "ligature-break")
1061 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
1062 else if (name == "slash")
1063 specialChar(cur, InsetSpecialChar::SLASH);
1064 else if (name == "nobreakdash")
1065 specialChar(cur, InsetSpecialChar::NOBREAKDASH);
1066 else if (name == "dots")
1067 specialChar(cur, InsetSpecialChar::LDOTS);
1068 else if (name == "end-of-sentence")
1069 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
1070 else if (name == "menu-separator")
1071 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
1072 else if (name.empty())
1073 lyxerr << "LyX function 'specialchar-insert' needs an argument." << endl;
1075 lyxerr << "Wrong argument for LyX function 'specialchar-insert'." << endl;
1079 case LFUN_WORD_UPCASE:
1080 changeCase(cur, text_uppercase);
1083 case LFUN_WORD_LOWCASE:
1084 changeCase(cur, text_lowercase);
1087 case LFUN_WORD_CAPITALIZE:
1088 changeCase(cur, text_capitalization);
1091 case LFUN_CHARS_TRANSPOSE:
1092 charsTranspose(cur);
1096 cur.message(_("Paste"));
1097 LASSERT(cur.selBegin().idx() == cur.selEnd().idx(), /**/);
1098 cap::replaceSelection(cur);
1100 // without argument?
1101 string const arg = to_utf8(cmd.argument());
1103 if (theClipboard().isInternal())
1104 pasteFromStack(cur, bv->buffer().errorList("Paste"), 0);
1105 else if (theClipboard().hasGraphicsContents()
1106 && !theClipboard().hasTextContents())
1107 pasteClipboardGraphics(cur, bv->buffer().errorList("Paste"));
1109 pasteClipboardText(cur, bv->buffer().errorList("Paste"));
1110 } else if (isStrUnsignedInt(arg)) {
1111 // we have a numerical argument
1112 pasteFromStack(cur, bv->buffer().errorList("Paste"),
1113 convert<unsigned int>(arg));
1115 Clipboard::GraphicsType type = Clipboard::AnyGraphicsType;
1117 type = Clipboard::PdfGraphicsType;
1118 else if (arg == "png")
1119 type = Clipboard::PngGraphicsType;
1120 else if (arg == "jpeg")
1121 type = Clipboard::JpegGraphicsType;
1122 else if (arg == "linkback")
1123 type = Clipboard::LinkBackGraphicsType;
1124 else if (arg == "emf")
1125 type = Clipboard::EmfGraphicsType;
1126 else if (arg == "wmf")
1127 type = Clipboard::WmfGraphicsType;
1130 LASSERT(false, /**/);
1132 pasteClipboardGraphics(cur, bv->buffer().errorList("Paste"), type);
1135 bv->buffer().errors("Paste");
1136 cur.clearSelection(); // bug 393
1142 cutSelection(cur, true, true);
1143 cur.message(_("Cut"));
1148 cur.message(_("Copy"));
1151 case LFUN_SERVER_GET_XY:
1152 cur.message(from_utf8(
1153 convert<string>(tm.cursorX(cur.top(), cur.boundary()))
1154 + ' ' + convert<string>(tm.cursorY(cur.top(), cur.boundary()))));
1157 case LFUN_SERVER_SET_XY: {
1160 istringstream is(to_utf8(cmd.argument()));
1163 lyxerr << "SETXY: Could not parse coordinates in '"
1164 << to_utf8(cmd.argument()) << endl;
1166 tm.setCursorFromCoordinates(cur, x, y);
1170 case LFUN_SERVER_GET_LAYOUT:
1171 cur.message(cur.paragraph().layout().name());
1175 docstring layout = cmd.argument();
1176 LYXERR(Debug::INFO, "LFUN_LAYOUT: (arg) " << to_utf8(layout));
1178 Paragraph const & para = cur.paragraph();
1179 docstring const old_layout = para.layout().name();
1180 DocumentClass const & tclass = bv->buffer().params().documentClass();
1183 layout = tclass.defaultLayoutName();
1185 if (para.forcePlainLayout())
1186 // in this case only the empty layout is allowed
1187 layout = tclass.plainLayoutName();
1188 else if (para.usePlainLayout()) {
1189 // in this case, default layout maps to empty layout
1190 if (layout == tclass.defaultLayoutName())
1191 layout = tclass.plainLayoutName();
1193 // otherwise, the empty layout maps to the default
1194 if (layout == tclass.plainLayoutName())
1195 layout = tclass.defaultLayoutName();
1198 bool hasLayout = tclass.hasLayout(layout);
1200 // If the entry is obsolete, use the new one instead.
1202 docstring const & obs = tclass[layout].obsoleted_by();
1208 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
1209 from_utf8(N_(" not known")));
1213 bool change_layout = (old_layout != layout);
1215 if (!change_layout && cur.selection() &&
1216 cur.selBegin().pit() != cur.selEnd().pit())
1218 pit_type spit = cur.selBegin().pit();
1219 pit_type epit = cur.selEnd().pit() + 1;
1220 while (spit != epit) {
1221 if (pars_[spit].layout().name() != old_layout) {
1222 change_layout = true;
1230 setLayout(cur, layout);
1235 case LFUN_CLIPBOARD_PASTE:
1236 cur.clearSelection();
1237 pasteClipboardText(cur, bv->buffer().errorList("Paste"),
1238 cmd.argument() == "paragraph");
1239 bv->buffer().errors("Paste");
1242 case LFUN_PRIMARY_SELECTION_PASTE:
1243 pasteString(cur, theSelection().get(),
1244 cmd.argument() == "paragraph");
1247 case LFUN_SELECTION_PASTE:
1248 // Copy the selection buffer to the clipboard stack,
1249 // because we want it to appear in the "Edit->Paste
1251 cap::copySelectionToStack();
1252 cap::pasteSelection(bv->cursor(), bv->buffer().errorList("Paste"));
1253 bv->buffer().errors("Paste");
1256 case LFUN_UNICODE_INSERT: {
1257 if (cmd.argument().empty())
1259 docstring hexstring = cmd.argument();
1260 if (isHex(hexstring)) {
1261 char_type c = hexToInt(hexstring);
1262 if (c >= 32 && c < 0x10ffff) {
1263 lyxerr << "Inserting c: " << c << endl;
1264 docstring s = docstring(1, c);
1265 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
1271 case LFUN_QUOTE_INSERT: {
1272 Paragraph & par = cur.paragraph();
1273 pos_type pos = cur.pos();
1274 BufferParams const & bufparams = bv->buffer().params();
1275 Layout const & style = par.layout();
1276 InsetLayout const & ilayout = cur.inset().getLayout(bufparams);
1277 if (!style.pass_thru && !ilayout.isPassThru()
1278 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
1279 // this avoids a double undo
1280 // FIXME: should not be needed, ideally
1281 if (!cur.selection())
1283 cap::replaceSelection(cur);
1288 else if (cur.prevInset() && cur.prevInset()->isSpace())
1291 c = par.getChar(pos - 1);
1292 string arg = to_utf8(cmd.argument());
1293 cur.insert(new InsetQuotes(bv->buffer(), c, (arg == "single")
1294 ? InsetQuotes::SingleQuotes : InsetQuotes::DoubleQuotes));
1298 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
1302 case LFUN_DATE_INSERT: {
1303 string const format = cmd.argument().empty()
1304 ? lyxrc.date_insert_format : to_utf8(cmd.argument());
1305 string const time = formatted_time(current_time(), format);
1306 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, time));
1310 case LFUN_MOUSE_TRIPLE:
1311 if (cmd.button() == mouse_button::button1) {
1320 case LFUN_MOUSE_DOUBLE:
1321 if (cmd.button() == mouse_button::button1) {
1322 selectWord(cur, WHOLE_WORD_STRICT);
1327 // Single-click on work area
1328 case LFUN_MOUSE_PRESS:
1329 // We are not marking a selection with the keyboard in any case.
1330 cur.bv().cursor().setMark(false);
1331 switch (cmd.button()) {
1332 case mouse_button::button1:
1334 if (!bv->mouseSetCursor(cur, cmd.argument() == "region-select"))
1335 cur.updateFlags(Update::SinglePar | Update::FitCursor);
1338 case mouse_button::button2:
1339 // Middle mouse pasting.
1340 bv->mouseSetCursor(cur);
1342 FuncRequest(LFUN_COMMAND_ALTERNATIVES,
1343 "selection-paste ; primary-selection-paste paragraph"));
1347 case mouse_button::button3: {
1348 Cursor const & bvcur = cur.bv().cursor();
1349 // Don't do anything if we right-click a
1350 // selection, a context menu will popup.
1351 if (bvcur.selection() && cur >= bvcur.selectionBegin()
1352 && cur < bvcur.selectionEnd()) {
1356 if (!bv->mouseSetCursor(cur, false))
1357 cur.updateFlags(Update::SinglePar | Update::FitCursor);
1363 } // switch (cmd.button())
1366 case LFUN_MOUSE_MOTION: {
1367 // Mouse motion with right or middle mouse do nothing for now.
1368 if (cmd.button() != mouse_button::button1) {
1372 // ignore motions deeper nested than the real anchor
1373 Cursor & bvcur = cur.bv().cursor();
1374 if (!bvcur.anchor_.hasPart(cur)) {
1378 CursorSlice old = bvcur.top();
1380 int const wh = bv->workHeight();
1381 int const y = max(0, min(wh - 1, cmd.y));
1383 tm.setCursorFromCoordinates(cur, cmd.x, y);
1384 cur.setTargetX(cmd.x);
1386 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1388 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1389 // This is to allow jumping over large insets
1390 if (cur.top() == old) {
1392 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1394 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1396 // We continue with our existing selection or start a new one, so don't
1397 // reset the anchor.
1398 bvcur.setCursor(cur);
1399 bvcur.setSelection(true);
1400 if (cur.top() == old) {
1401 // We didn't move one iota, so no need to update the screen.
1402 cur.updateFlags(Update::SinglePar | Update::FitCursor);
1409 case LFUN_MOUSE_RELEASE:
1410 switch (cmd.button()) {
1411 case mouse_button::button1:
1412 // Cursor was set at LFUN_MOUSE_PRESS or LFUN_MOUSE_MOTION time.
1413 // If there is a new selection, update persistent selection;
1414 // otherwise, single click does not clear persistent selection
1416 if (cur.selection()) {
1417 // Finish selection. If double click,
1418 // cur is moved to the end of word by
1419 // selectWord but bvcur is current
1421 cur.bv().cursor().setSelection();
1422 // We might have removed an empty but drawn selection
1423 // (probably a margin)
1424 cur.updateFlags(Update::SinglePar | Update::FitCursor);
1427 // FIXME: We could try to handle drag and drop of selection here.
1430 case mouse_button::button2:
1431 // Middle mouse pasting is handled at mouse press time,
1432 // see LFUN_MOUSE_PRESS.
1436 case mouse_button::button3:
1437 // Cursor was set at LFUN_MOUSE_PRESS time.
1438 // FIXME: If there is a selection we could try to handle a special
1439 // drag & drop context menu.
1443 case mouse_button::none:
1444 case mouse_button::button4:
1445 case mouse_button::button5:
1447 } // switch (cmd.button())
1451 case LFUN_SELF_INSERT: {
1452 if (cmd.argument().empty())
1455 // Automatically delete the currently selected
1456 // text and replace it with what is being
1457 // typed in now. Depends on lyxrc settings
1458 // "auto_region_delete", which defaults to
1461 if (lyxrc.auto_region_delete && cur.selection())
1462 cutSelection(cur, false, false);
1464 cur.clearSelection();
1466 docstring::const_iterator cit = cmd.argument().begin();
1467 docstring::const_iterator const end = cmd.argument().end();
1468 for (; cit != end; ++cit)
1469 bv->translateAndInsert(*cit, this, cur);
1472 moveCursor(cur, false);
1473 bv->bookmarkEditPosition();
1477 case LFUN_HYPERLINK_INSERT: {
1478 InsetCommandParams p(HYPERLINK_CODE);
1480 if (cur.selection()) {
1481 content = cur.selectionAsString(false);
1482 cutSelection(cur, true, false);
1484 p["target"] = (cmd.argument().empty()) ?
1485 content : cmd.argument();
1486 string const data = InsetCommand::params2string("href", p);
1487 if (p["target"].empty()) {
1488 bv->showDialog("href", data);
1490 FuncRequest fr(LFUN_INSET_INSERT, data);
1496 case LFUN_LABEL_INSERT: {
1497 InsetCommandParams p(LABEL_CODE);
1498 // Try to generate a valid label
1499 p["name"] = (cmd.argument().empty()) ?
1500 cur.getPossibleLabel() :
1502 string const data = InsetCommand::params2string("label", p);
1504 if (cmd.argument().empty()) {
1505 bv->showDialog("label", data);
1507 FuncRequest fr(LFUN_INSET_INSERT, data);
1513 case LFUN_INFO_INSERT: {
1515 if (cmd.argument().empty() && cur.selection()) {
1516 // if command argument is empty use current selection as parameter.
1517 docstring ds = cur.selectionAsString(false);
1518 cutSelection(cur, true, false);
1519 FuncRequest cmd0(cmd, ds);
1520 inset = createInset(cur.bv().buffer(), cmd0);
1522 inset = createInset(cur.bv().buffer(), cmd);
1527 insertInset(cur, inset);
1531 case LFUN_CAPTION_INSERT:
1532 case LFUN_FOOTNOTE_INSERT:
1533 case LFUN_NOTE_INSERT:
1534 case LFUN_FLEX_INSERT:
1535 case LFUN_BOX_INSERT:
1536 case LFUN_BRANCH_INSERT:
1537 case LFUN_PHANTOM_INSERT:
1538 case LFUN_ERT_INSERT:
1539 case LFUN_LISTING_INSERT:
1540 case LFUN_MARGINALNOTE_INSERT:
1541 case LFUN_OPTIONAL_INSERT:
1542 case LFUN_INDEX_INSERT:
1543 // Open the inset, and move the current selection
1545 doInsertInset(cur, this, cmd, true, true);
1547 // Some insets are numbered, others are shown in the outline pane so
1548 // let's update the labels and the toc backend.
1549 bv->buffer().updateLabels();
1552 case LFUN_TABULAR_INSERT:
1553 // if there were no arguments, just open the dialog
1554 if (doInsertInset(cur, this, cmd, false, true))
1557 bv->showDialog("tabularcreate");
1561 case LFUN_FLOAT_INSERT:
1562 case LFUN_FLOAT_WIDE_INSERT:
1563 case LFUN_WRAP_INSERT: {
1564 // will some text be moved into the inset?
1565 bool content = cur.selection();
1567 doInsertInset(cur, this, cmd, true, true);
1570 // If some text is moved into the inset, doInsertInset
1571 // puts the cursor outside the inset. To insert the
1572 // caption we put it back into the inset.
1576 ParagraphList & pars = cur.text()->paragraphs();
1578 DocumentClass const & tclass = bv->buffer().params().documentClass();
1580 // add a separate paragraph for the caption inset
1581 pars.push_back(Paragraph());
1582 pars.back().setInsetOwner(&pars[0].inInset());
1583 pars.back().setPlainOrDefaultLayout(tclass);
1584 int cap_pit = pars.size() - 1;
1586 // if an empty inset was created, we create an additional empty
1587 // paragraph at the bottom so that the user can choose where to put
1588 // the graphics (or table).
1590 pars.push_back(Paragraph());
1591 pars.back().setInsetOwner(&pars[0].inInset());
1592 pars.back().setPlainOrDefaultLayout(tclass);
1595 // reposition the cursor to the caption
1596 cur.pit() = cap_pit;
1598 // FIXME: This Text/Cursor dispatch handling is a mess!
1599 // We cannot use Cursor::dispatch here it needs access to up to
1601 FuncRequest cmd_caption(LFUN_CAPTION_INSERT);
1602 doInsertInset(cur, cur.text(), cmd_caption, true, false);
1603 bv->buffer().updateLabels();
1604 cur.updateFlags(Update::Force);
1605 // FIXME: When leaving the Float (or Wrap) inset we should
1606 // delete any empty paragraph left above or below the
1611 case LFUN_NOMENCL_INSERT: {
1612 InsetCommandParams p(NOMENCL_CODE);
1613 if (cmd.argument().empty())
1614 p["symbol"] = bv->cursor().innerText()->getStringToIndex(bv->cursor());
1616 p["symbol"] = cmd.argument();
1617 string const data = InsetCommand::params2string("nomenclature", p);
1618 bv->showDialog("nomenclature", data);
1622 case LFUN_INDEX_PRINT: {
1623 InsetCommandParams p(INDEX_PRINT_CODE);
1624 if (cmd.argument().empty())
1625 p["type"] = from_ascii("idx");
1627 p["type"] = cmd.argument();
1628 string const data = InsetCommand::params2string("index_print", p);
1629 FuncRequest fr(LFUN_INSET_INSERT, data);
1634 case LFUN_NOMENCL_PRINT:
1635 case LFUN_TOC_INSERT:
1636 case LFUN_LINE_INSERT:
1637 case LFUN_NEWPAGE_INSERT:
1639 doInsertInset(cur, this, cmd, false, false);
1643 case LFUN_DEPTH_DECREMENT:
1644 changeDepth(cur, DEC_DEPTH);
1647 case LFUN_DEPTH_INCREMENT:
1648 changeDepth(cur, INC_DEPTH);
1651 case LFUN_MATH_DISPLAY:
1652 mathDispatch(cur, cmd, true);
1655 case LFUN_REGEXP_MODE:
1656 regexpDispatch(cur, cmd);
1659 case LFUN_MATH_MODE:
1660 if (cmd.argument() == "on")
1661 // don't pass "on" as argument
1662 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1664 mathDispatch(cur, cmd, false);
1667 case LFUN_MATH_MACRO:
1668 if (cmd.argument().empty())
1669 cur.errorMessage(from_utf8(N_("Missing argument")));
1671 string s = to_utf8(cmd.argument());
1672 string const s1 = token(s, ' ', 1);
1673 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1674 string const s2 = token(s, ' ', 2);
1675 MacroType type = MacroTypeNewcommand;
1677 type = MacroTypeDef;
1678 MathMacroTemplate * inset = new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, false, type);
1679 inset->setBuffer(bv->buffer());
1680 insertInset(cur, inset);
1682 // enter macro inset and select the name
1684 cur.top().pos() = cur.top().lastpos();
1686 cur.setSelection(true);
1687 cur.top().pos() = 0;
1691 // passthrough hat and underscore outside mathed:
1692 case LFUN_MATH_SUBSCRIPT:
1693 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1695 case LFUN_MATH_SUPERSCRIPT:
1696 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1699 case LFUN_MATH_INSERT:
1700 case LFUN_MATH_MATRIX:
1701 case LFUN_MATH_DELIM:
1702 case LFUN_MATH_BIGDELIM: {
1704 cap::replaceSelection(cur);
1705 cur.insert(new InsetMathHull(hullSimple));
1706 checkAndActivateInset(cur, true);
1707 LASSERT(cur.inMathed(), /**/);
1712 case LFUN_FONT_EMPH: {
1713 Font font(ignore_font, ignore_language);
1714 font.fontInfo().setEmph(FONT_TOGGLE);
1715 toggleAndShow(cur, this, font);
1719 case LFUN_FONT_ITAL: {
1720 Font font(ignore_font, ignore_language);
1721 font.fontInfo().setShape(ITALIC_SHAPE);
1722 toggleAndShow(cur, this, font);
1726 case LFUN_FONT_BOLD:
1727 case LFUN_FONT_BOLDSYMBOL: {
1728 Font font(ignore_font, ignore_language);
1729 font.fontInfo().setSeries(BOLD_SERIES);
1730 toggleAndShow(cur, this, font);
1734 case LFUN_FONT_NOUN: {
1735 Font font(ignore_font, ignore_language);
1736 font.fontInfo().setNoun(FONT_TOGGLE);
1737 toggleAndShow(cur, this, font);
1741 case LFUN_FONT_TYPEWRITER: {
1742 Font font(ignore_font, ignore_language);
1743 font.fontInfo().setFamily(TYPEWRITER_FAMILY); // no good
1744 toggleAndShow(cur, this, font);
1748 case LFUN_FONT_SANS: {
1749 Font font(ignore_font, ignore_language);
1750 font.fontInfo().setFamily(SANS_FAMILY);
1751 toggleAndShow(cur, this, font);
1755 case LFUN_FONT_ROMAN: {
1756 Font font(ignore_font, ignore_language);
1757 font.fontInfo().setFamily(ROMAN_FAMILY);
1758 toggleAndShow(cur, this, font);
1762 case LFUN_FONT_DEFAULT: {
1763 Font font(inherit_font, ignore_language);
1764 toggleAndShow(cur, this, font);
1768 case LFUN_FONT_STRIKEOUT: {
1769 Font font(ignore_font, ignore_language);
1770 font.fontInfo().setStrikeout(FONT_TOGGLE);
1771 toggleAndShow(cur, this, font);
1775 case LFUN_FONT_UULINE: {
1776 Font font(ignore_font, ignore_language);
1777 font.fontInfo().setUuline(FONT_TOGGLE);
1778 toggleAndShow(cur, this, font);
1782 case LFUN_FONT_UWAVE: {
1783 Font font(ignore_font, ignore_language);
1784 font.fontInfo().setUwave(FONT_TOGGLE);
1785 toggleAndShow(cur, this, font);
1789 case LFUN_FONT_UNDERLINE: {
1790 Font font(ignore_font, ignore_language);
1791 font.fontInfo().setUnderbar(FONT_TOGGLE);
1792 toggleAndShow(cur, this, font);
1796 case LFUN_FONT_SIZE: {
1797 Font font(ignore_font, ignore_language);
1798 setLyXSize(to_utf8(cmd.argument()), font.fontInfo());
1799 toggleAndShow(cur, this, font);
1803 case LFUN_LANGUAGE: {
1804 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1807 Font font(ignore_font, lang);
1808 toggleAndShow(cur, this, font);
1812 case LFUN_TEXTSTYLE_APPLY:
1813 toggleAndShow(cur, this, freefont, toggleall);
1814 cur.message(_("Character set"));
1817 // Set the freefont using the contents of \param data dispatched from
1818 // the frontends and apply it at the current cursor location.
1819 case LFUN_TEXTSTYLE_UPDATE: {
1822 if (font.fromString(to_utf8(cmd.argument()), toggle)) {
1825 toggleAndShow(cur, this, freefont, toggleall);
1826 cur.message(_("Character set"));
1828 lyxerr << "Argument not ok";
1833 case LFUN_FINISHED_LEFT:
1834 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_LEFT:\n" << cur);
1835 // We're leaving an inset, going left. If the inset is LTR, we're
1836 // leaving from the front, so we should not move (remain at --- but
1837 // not in --- the inset). If the inset is RTL, move left, without
1838 // entering the inset itself; i.e., move to after the inset.
1839 if (cur.paragraph().getFontSettings(
1840 cur.bv().buffer().params(), cur.pos()).isRightToLeft())
1841 cursorVisLeft(cur, true);
1844 case LFUN_FINISHED_RIGHT:
1845 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_RIGHT:\n" << cur);
1846 // We're leaving an inset, going right. If the inset is RTL, we're
1847 // leaving from the front, so we should not move (remain at --- but
1848 // not in --- the inset). If the inset is LTR, move right, without
1849 // entering the inset itself; i.e., move to after the inset.
1850 if (!cur.paragraph().getFontSettings(
1851 cur.bv().buffer().params(), cur.pos()).isRightToLeft())
1852 cursorVisRight(cur, true);
1855 case LFUN_FINISHED_BACKWARD:
1856 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_BACKWARD:\n" << cur);
1859 case LFUN_FINISHED_FORWARD:
1860 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_FORWARD:\n" << cur);
1862 cur.setCurrentFont();
1865 case LFUN_LAYOUT_PARAGRAPH: {
1867 params2string(cur.paragraph(), data);
1868 data = "show\n" + data;
1869 bv->showDialog("paragraph", data);
1873 case LFUN_PARAGRAPH_UPDATE: {
1875 params2string(cur.paragraph(), data);
1877 // Will the paragraph accept changes from the dialog?
1879 cur.inset().allowParagraphCustomization(cur.idx());
1881 data = "update " + convert<string>(accept) + '\n' + data;
1882 bv->updateDialog("paragraph", data);
1886 case LFUN_ACCENT_UMLAUT:
1887 case LFUN_ACCENT_CIRCUMFLEX:
1888 case LFUN_ACCENT_GRAVE:
1889 case LFUN_ACCENT_ACUTE:
1890 case LFUN_ACCENT_TILDE:
1891 case LFUN_ACCENT_CEDILLA:
1892 case LFUN_ACCENT_MACRON:
1893 case LFUN_ACCENT_DOT:
1894 case LFUN_ACCENT_UNDERDOT:
1895 case LFUN_ACCENT_UNDERBAR:
1896 case LFUN_ACCENT_CARON:
1897 case LFUN_ACCENT_BREVE:
1898 case LFUN_ACCENT_TIE:
1899 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1900 case LFUN_ACCENT_CIRCLE:
1901 case LFUN_ACCENT_OGONEK:
1902 theLyXFunc().handleKeyFunc(cmd.action);
1903 if (!cmd.argument().empty())
1904 // FIXME: Are all these characters encoded in one byte in utf8?
1905 bv->translateAndInsert(cmd.argument()[0], this, cur);
1908 case LFUN_FLOAT_LIST_INSERT: {
1909 DocumentClass const & tclass = bv->buffer().params().documentClass();
1910 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1912 if (cur.selection())
1913 cutSelection(cur, true, false);
1914 breakParagraph(cur);
1916 if (cur.lastpos() != 0) {
1917 cursorBackward(cur);
1918 breakParagraph(cur);
1921 docstring const laystr = cur.inset().usePlainLayout() ?
1922 tclass.plainLayoutName() :
1923 tclass.defaultLayoutName();
1924 setLayout(cur, laystr);
1925 ParagraphParameters p;
1926 // FIXME If this call were replaced with one to clearParagraphParams(),
1927 // then we could get rid of this method altogether.
1928 setParagraphs(cur, p);
1929 // FIXME This should be simplified when InsetFloatList takes a
1930 // Buffer in its constructor.
1931 InsetFloatList * ifl = new InsetFloatList(to_utf8(cmd.argument()));
1932 ifl->setBuffer(bv->buffer());
1933 insertInset(cur, ifl);
1936 lyxerr << "Non-existent float type: "
1937 << to_utf8(cmd.argument()) << endl;
1942 case LFUN_CHANGE_ACCEPT: {
1943 acceptOrRejectChanges(cur, ACCEPT);
1947 case LFUN_CHANGE_REJECT: {
1948 acceptOrRejectChanges(cur, REJECT);
1952 case LFUN_THESAURUS_ENTRY: {
1953 docstring arg = cmd.argument();
1955 arg = cur.selectionAsString(false);
1957 if (arg.size() > 100 || arg.empty()) {
1958 // Get word or selection
1959 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1960 arg = cur.selectionAsString(false);
1961 arg += " lang=" + from_ascii(cur.getFont().language()->lang());
1964 bv->showDialog("thesaurus", to_utf8(arg));
1968 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1969 // Given data, an encoding of the ParagraphParameters
1970 // generated in the Paragraph dialog, this function sets
1971 // the current paragraph, or currently selected paragraphs,
1973 // NOTE: This function overrides all existing settings.
1974 setParagraphs(cur, cmd.argument());
1975 cur.message(_("Paragraph layout set"));
1979 case LFUN_PARAGRAPH_PARAMS: {
1980 // Given data, an encoding of the ParagraphParameters as we'd
1981 // find them in a LyX file, this function modifies the current paragraph,
1982 // or currently selected paragraphs.
1983 // NOTE: This function only modifies, and does not override, existing
1985 setParagraphs(cur, cmd.argument(), true);
1986 cur.message(_("Paragraph layout set"));
1991 if (cur.selection()) {
1992 cur.setSelection(false);
1995 // This used to be LFUN_FINISHED_RIGHT, I think FORWARD is more
1996 // correct, but I'm not 100% sure -- dov, 071019
1997 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
2001 case LFUN_OUTLINE_UP:
2002 outline(OutlineUp, cur);
2003 setCursor(cur, cur.pit(), 0);
2004 cur.buffer()->updateLabels();
2008 case LFUN_OUTLINE_DOWN:
2009 outline(OutlineDown, cur);
2010 setCursor(cur, cur.pit(), 0);
2011 cur.buffer()->updateLabels();
2015 case LFUN_OUTLINE_IN:
2016 outline(OutlineIn, cur);
2017 cur.buffer()->updateLabels();
2021 case LFUN_OUTLINE_OUT:
2022 outline(OutlineOut, cur);
2023 cur.buffer()->updateLabels();
2028 LYXERR(Debug::ACTION, "Command " << cmd << " not DISPATCHED by Text");
2033 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
2035 // FIXME: The cursor flag is reset two lines below
2036 // so we need to check here if some of the LFUN did touch that.
2037 // for now only Text::erase() and Text::backspace() do that.
2038 // The plan is to verify all the LFUNs and then to remove this
2039 // singleParUpdate boolean altogether.
2040 if (cur.result().update() & Update::Force) {
2041 singleParUpdate = false;
2045 // FIXME: the following code should go in favor of fine grained
2046 // update flag treatment.
2047 if (singleParUpdate) {
2048 // Inserting characters does not change par height in general. So, try
2049 // to update _only_ this paragraph. BufferView will detect if a full
2050 // metrics update is needed anyway.
2051 cur.updateFlags(Update::SinglePar | Update::FitCursor);
2056 && &oldTopSlice.inset() == &cur.inset()
2057 && oldTopSlice.idx() == cur.idx()
2058 && !sel // sel is a backup of cur.selection() at the biginning of the function.
2059 && !cur.selection())
2060 // FIXME: it would be better if we could just do this
2062 //if (cur.result().update() != Update::FitCursor)
2065 // But some LFUNs do not set Update::FitCursor when needed, so we
2066 // do it for all. This is not very harmfull as FitCursor will provoke
2067 // a full redraw only if needed but still, a proper review of all LFUN
2068 // should be done and this needsUpdate boolean can then be removed.
2069 cur.updateFlags(Update::FitCursor);
2071 cur.updateFlags(Update::Force | Update::FitCursor);
2075 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
2076 FuncStatus & flag) const
2078 LASSERT(cur.text() == this, /**/);
2080 FontInfo const & fontinfo = cur.real_current_font.fontInfo();
2082 InsetCode code = NO_CODE;
2084 switch (cmd.action) {
2086 case LFUN_DEPTH_DECREMENT:
2087 enable = changeDepthAllowed(cur, DEC_DEPTH);
2090 case LFUN_DEPTH_INCREMENT:
2091 enable = changeDepthAllowed(cur, INC_DEPTH);
2095 flag.setOnOff(cur.paragraph().params().startOfAppendix());
2098 case LFUN_DIALOG_SHOW_NEW_INSET:
2099 if (cmd.argument() == "bibitem")
2100 code = BIBITEM_CODE;
2101 else if (cmd.argument() == "bibtex") {
2103 // not allowed in description items
2104 enable = !inDescriptionItem(cur);
2106 else if (cmd.argument() == "box")
2108 else if (cmd.argument() == "branch")
2110 else if (cmd.argument() == "citation")
2112 else if (cmd.argument() == "ert")
2114 else if (cmd.argument() == "external")
2115 code = EXTERNAL_CODE;
2116 else if (cmd.argument() == "float")
2118 else if (cmd.argument() == "graphics")
2119 code = GRAPHICS_CODE;
2120 else if (cmd.argument() == "href")
2121 code = HYPERLINK_CODE;
2122 else if (cmd.argument() == "include")
2123 code = INCLUDE_CODE;
2124 else if (cmd.argument() == "index")
2126 else if (cmd.argument() == "index_print")
2127 code = INDEX_PRINT_CODE;
2128 else if (cmd.argument() == "nomenclature")
2129 code = NOMENCL_CODE;
2130 else if (cmd.argument() == "label")
2132 else if (cmd.argument() == "note")
2134 else if (cmd.argument() == "phantom")
2135 code = PHANTOM_CODE;
2136 else if (cmd.argument() == "ref")
2138 else if (cmd.argument() == "space")
2140 else if (cmd.argument() == "toc")
2142 else if (cmd.argument() == "vspace")
2144 else if (cmd.argument() == "wrap")
2146 else if (cmd.argument() == "listings")
2147 code = LISTINGS_CODE;
2150 case LFUN_ERT_INSERT:
2153 case LFUN_LISTING_INSERT:
2154 code = LISTINGS_CODE;
2155 // not allowed in description items
2156 enable = !inDescriptionItem(cur);
2158 case LFUN_FOOTNOTE_INSERT:
2161 case LFUN_TABULAR_INSERT:
2162 code = TABULAR_CODE;
2164 case LFUN_MARGINALNOTE_INSERT:
2167 case LFUN_FLOAT_INSERT:
2168 case LFUN_FLOAT_WIDE_INSERT:
2170 // not allowed in description items
2171 enable = !inDescriptionItem(cur);
2173 case LFUN_WRAP_INSERT:
2175 // not allowed in description items
2176 enable = !inDescriptionItem(cur);
2178 case LFUN_FLOAT_LIST_INSERT:
2179 code = FLOAT_LIST_CODE;
2180 // not allowed in description items
2181 enable = !inDescriptionItem(cur);
2183 case LFUN_CAPTION_INSERT:
2184 code = CAPTION_CODE;
2185 // not allowed in description items
2186 enable = !inDescriptionItem(cur);
2188 case LFUN_NOTE_INSERT:
2190 // in commands (sections etc.) and description items,
2191 // only Notes are allowed
2192 enable = (cmd.argument().empty() || cmd.getArg(0) == "Note" ||
2193 (!cur.paragraph().layout().isCommand()
2194 && !inDescriptionItem(cur)));
2196 case LFUN_FLEX_INSERT: {
2198 string s = cmd.getArg(0);
2200 cur.buffer()->params().documentClass().insetLayout(from_utf8(s));
2201 if (il.lyxtype() != InsetLayout::CHARSTYLE &&
2202 il.lyxtype() != InsetLayout::CUSTOM &&
2203 il.lyxtype() != InsetLayout::ELEMENT &&
2204 il.lyxtype ()!= InsetLayout::STANDARD)
2208 case LFUN_BOX_INSERT:
2211 case LFUN_BRANCH_INSERT:
2213 if (cur.buffer()->masterBuffer()->params().branchlist().empty()
2214 && cur.buffer()->params().branchlist().empty())
2217 case LFUN_PHANTOM_INSERT:
2218 code = PHANTOM_CODE;
2220 case LFUN_LABEL_INSERT:
2223 case LFUN_INFO_INSERT:
2226 case LFUN_OPTIONAL_INSERT:
2228 enable = cur.paragraph().insetList().count(OPTARG_CODE)
2229 < cur.paragraph().layout().optionalargs;
2231 case LFUN_INDEX_INSERT:
2234 case LFUN_INDEX_PRINT:
2235 code = INDEX_PRINT_CODE;
2236 // not allowed in description items
2237 enable = !inDescriptionItem(cur);
2239 case LFUN_NOMENCL_INSERT:
2240 if (cur.selIsMultiCell() || cur.selIsMultiLine()) {
2244 code = NOMENCL_CODE;
2246 case LFUN_NOMENCL_PRINT:
2247 code = NOMENCL_PRINT_CODE;
2248 // not allowed in description items
2249 enable = !inDescriptionItem(cur);
2251 case LFUN_TOC_INSERT:
2253 // not allowed in description items
2254 enable = !inDescriptionItem(cur);
2256 case LFUN_HYPERLINK_INSERT:
2257 if (cur.selIsMultiCell() || cur.selIsMultiLine()) {
2261 code = HYPERLINK_CODE;
2263 case LFUN_QUOTE_INSERT:
2264 // always allow this, since we will inset a raw quote
2265 // if an inset is not allowed.
2267 case LFUN_SPECIALCHAR_INSERT:
2268 code = SPECIALCHAR_CODE;
2270 case LFUN_SPACE_INSERT:
2271 // slight hack: we know this is allowed in math mode
2276 case LFUN_INSET_MODIFY:
2277 // We need to disable this, because we may get called for a
2279 // InsetTabular::getStatus() -> InsetText::getStatus()
2280 // and we don't handle LFUN_INSET_MODIFY.
2284 case LFUN_FONT_EMPH:
2285 flag.setOnOff(fontinfo.emph() == FONT_ON);
2288 case LFUN_FONT_ITAL:
2289 flag.setOnOff(fontinfo.shape() == ITALIC_SHAPE);
2292 case LFUN_FONT_NOUN:
2293 flag.setOnOff(fontinfo.noun() == FONT_ON);
2296 case LFUN_FONT_BOLD:
2297 case LFUN_FONT_BOLDSYMBOL:
2298 flag.setOnOff(fontinfo.series() == BOLD_SERIES);
2301 case LFUN_FONT_SANS:
2302 flag.setOnOff(fontinfo.family() == SANS_FAMILY);
2305 case LFUN_FONT_ROMAN:
2306 flag.setOnOff(fontinfo.family() == ROMAN_FAMILY);
2309 case LFUN_FONT_TYPEWRITER:
2310 flag.setOnOff(fontinfo.family() == TYPEWRITER_FAMILY);
2315 enable = cur.selection();
2319 if (cmd.argument().empty()) {
2320 if (theClipboard().isInternal())
2321 enable = cap::numberOfSelections() > 0;
2323 enable = !theClipboard().empty();
2327 // we have an argument
2328 string const arg = to_utf8(cmd.argument());
2329 if (isStrUnsignedInt(arg)) {
2330 // it's a number and therefore means the internal stack
2331 unsigned int n = convert<unsigned int>(arg);
2332 enable = cap::numberOfSelections() > n;
2336 // explicit graphics type?
2337 Clipboard::GraphicsType type = Clipboard::AnyGraphicsType;
2338 if ((arg == "pdf" && (type = Clipboard::PdfGraphicsType))
2339 || (arg == "png" && (type = Clipboard::PngGraphicsType))
2340 || (arg == "jpeg" && (type = Clipboard::JpegGraphicsType))
2341 || (arg == "linkback" && (type = Clipboard::LinkBackGraphicsType))
2342 || (arg == "emf" && (type = Clipboard::EmfGraphicsType))
2343 || (arg == "wmf" && (type = Clipboard::WmfGraphicsType))) {
2344 enable = theClipboard().hasGraphicsContents(type);
2353 case LFUN_CLIPBOARD_PASTE:
2354 enable = !theClipboard().empty();
2357 case LFUN_PRIMARY_SELECTION_PASTE:
2358 enable = cur.selection() || !theSelection().empty();
2361 case LFUN_SELECTION_PASTE:
2362 enable = cap::selection();
2365 case LFUN_PARAGRAPH_MOVE_UP:
2366 enable = cur.pit() > 0 && !cur.selection();
2369 case LFUN_PARAGRAPH_MOVE_DOWN:
2370 enable = cur.pit() < cur.lastpit() && !cur.selection();
2373 case LFUN_INSET_DISSOLVE:
2374 if (!cmd.argument().empty()) {
2375 InsetLayout const & il = cur.inset().getLayout(cur.buffer()->params());
2376 InsetLayout::InsetLyXType const type =
2377 translateLyXType(to_utf8(cmd.argument()));
2378 enable = cur.inset().lyxCode() == FLEX_CODE
2379 && il.lyxtype() == type;
2381 enable = ((!isMainText(cur.bv().buffer())
2382 && cur.inset().nargs() == 1)
2384 && cur.nextInset()->nargs() == 1));
2388 case LFUN_CHANGE_ACCEPT:
2389 case LFUN_CHANGE_REJECT:
2390 // In principle, these LFUNs should only be enabled if there
2391 // is a change at the current position/in the current selection.
2392 // However, without proper optimizations, this will inevitably
2393 // result in unacceptable performance - just imagine a user who
2394 // wants to select the complete content of a long document.
2395 if (!cur.selection()) {
2396 Change const & change = cur.paragraph().lookupChange(cur.pos());
2397 enable = change.changed();
2399 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
2404 case LFUN_OUTLINE_UP:
2405 case LFUN_OUTLINE_DOWN:
2406 case LFUN_OUTLINE_IN:
2407 case LFUN_OUTLINE_OUT:
2408 // FIXME: LyX is not ready for outlining within inset.
2409 enable = isMainText(cur.bv().buffer())
2410 && cur.paragraph().layout().toclevel != Layout::NOT_IN_TOC;
2413 case LFUN_NEWLINE_INSERT:
2414 // LaTeX restrictions (labels or empty par)
2415 enable = (cur.pos() > cur.paragraph().beginOfBody());
2418 case LFUN_SET_GRAPHICS_GROUP: {
2419 InsetGraphics * ins = graphics::getCurrentGraphicsInset(cur);
2423 flag.setOnOff(to_utf8(cmd.argument()) == ins->getParams().groupId);
2427 case LFUN_NEWPAGE_INSERT:
2428 // not allowed in description items
2429 enable = !inDescriptionItem(cur);
2432 case LFUN_MATH_INSERT:
2433 case LFUN_MATH_MATRIX:
2434 case LFUN_MATH_DELIM:
2435 case LFUN_MATH_BIGDELIM:
2436 // not allowed in ERT, for example.
2437 enable = cur.inset().insetAllowed(MATH_CODE);
2440 case LFUN_DATE_INSERT: {
2441 string const format = cmd.argument().empty()
2442 ? lyxrc.date_insert_format : to_utf8(cmd.argument());
2443 enable = support::os::is_valid_strftime(format);
2447 case LFUN_WORD_DELETE_FORWARD:
2448 case LFUN_WORD_DELETE_BACKWARD:
2449 case LFUN_LINE_DELETE:
2450 case LFUN_WORD_FORWARD:
2451 case LFUN_WORD_BACKWARD:
2452 case LFUN_WORD_RIGHT:
2453 case LFUN_WORD_LEFT:
2454 case LFUN_CHAR_FORWARD:
2455 case LFUN_CHAR_FORWARD_SELECT:
2456 case LFUN_CHAR_BACKWARD:
2457 case LFUN_CHAR_BACKWARD_SELECT:
2458 case LFUN_CHAR_LEFT:
2459 case LFUN_CHAR_LEFT_SELECT:
2460 case LFUN_CHAR_RIGHT:
2461 case LFUN_CHAR_RIGHT_SELECT:
2463 case LFUN_UP_SELECT:
2465 case LFUN_DOWN_SELECT:
2466 case LFUN_PARAGRAPH_UP_SELECT:
2467 case LFUN_PARAGRAPH_DOWN_SELECT:
2468 case LFUN_LINE_BEGIN_SELECT:
2469 case LFUN_LINE_END_SELECT:
2470 case LFUN_WORD_FORWARD_SELECT:
2471 case LFUN_WORD_BACKWARD_SELECT:
2472 case LFUN_WORD_RIGHT_SELECT:
2473 case LFUN_WORD_LEFT_SELECT:
2474 case LFUN_WORD_SELECT:
2475 case LFUN_SECTION_SELECT:
2476 case LFUN_PARAGRAPH_UP:
2477 case LFUN_PARAGRAPH_DOWN:
2478 case LFUN_LINE_BEGIN:
2480 case LFUN_CHAR_DELETE_FORWARD:
2481 case LFUN_CHAR_DELETE_BACKWARD:
2482 case LFUN_BREAK_PARAGRAPH:
2483 case LFUN_PARAGRAPH_SPACING:
2484 case LFUN_INSET_INSERT:
2485 case LFUN_WORD_UPCASE:
2486 case LFUN_WORD_LOWCASE:
2487 case LFUN_WORD_CAPITALIZE:
2488 case LFUN_CHARS_TRANSPOSE:
2489 case LFUN_SERVER_GET_XY:
2490 case LFUN_SERVER_SET_XY:
2491 case LFUN_SERVER_GET_LAYOUT:
2493 case LFUN_SELF_INSERT:
2494 case LFUN_LINE_INSERT:
2495 case LFUN_MATH_DISPLAY:
2496 case LFUN_MATH_MODE:
2497 case LFUN_MATH_MACRO:
2498 case LFUN_MATH_SUBSCRIPT:
2499 case LFUN_MATH_SUPERSCRIPT:
2500 case LFUN_FONT_DEFAULT:
2501 case LFUN_FONT_UNDERLINE:
2502 case LFUN_FONT_STRIKEOUT:
2503 case LFUN_FONT_UULINE:
2504 case LFUN_FONT_UWAVE:
2505 case LFUN_FONT_SIZE:
2507 case LFUN_TEXTSTYLE_APPLY:
2508 case LFUN_TEXTSTYLE_UPDATE:
2509 case LFUN_LAYOUT_PARAGRAPH:
2510 case LFUN_PARAGRAPH_UPDATE:
2511 case LFUN_ACCENT_UMLAUT:
2512 case LFUN_ACCENT_CIRCUMFLEX:
2513 case LFUN_ACCENT_GRAVE:
2514 case LFUN_ACCENT_ACUTE:
2515 case LFUN_ACCENT_TILDE:
2516 case LFUN_ACCENT_CEDILLA:
2517 case LFUN_ACCENT_MACRON:
2518 case LFUN_ACCENT_DOT:
2519 case LFUN_ACCENT_UNDERDOT:
2520 case LFUN_ACCENT_UNDERBAR:
2521 case LFUN_ACCENT_CARON:
2522 case LFUN_ACCENT_BREVE:
2523 case LFUN_ACCENT_TIE:
2524 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
2525 case LFUN_ACCENT_CIRCLE:
2526 case LFUN_ACCENT_OGONEK:
2527 case LFUN_THESAURUS_ENTRY:
2528 case LFUN_PARAGRAPH_PARAMS_APPLY:
2529 case LFUN_PARAGRAPH_PARAMS:
2531 case LFUN_BUFFER_BEGIN:
2532 case LFUN_BUFFER_END:
2533 case LFUN_BUFFER_BEGIN_SELECT:
2534 case LFUN_BUFFER_END_SELECT:
2535 case LFUN_INSET_BEGIN:
2536 case LFUN_INSET_END:
2537 case LFUN_INSET_BEGIN_SELECT:
2538 case LFUN_INSET_END_SELECT:
2539 case LFUN_UNICODE_INSERT:
2540 // these are handled in our dispatch()
2549 && (cur.empty() || !cur.inset().insetAllowed(code)))
2552 flag.setEnabled(enable);
2557 void Text::pasteString(Cursor & cur, docstring const & clip,
2560 cur.clearSelection();
2561 if (!clip.empty()) {
2564 insertStringAsParagraphs(cur, clip);
2566 insertStringAsLines(cur, clip);
2571 // FIXME: an item inset would make things much easier.
2572 bool Text::inDescriptionItem(Cursor & cur) const
2574 Paragraph & par = cur.paragraph();
2575 pos_type const pos = cur.pos();
2576 pos_type const body_pos = par.beginOfBody();
2578 if (par.layout().latextype != LATEX_LIST_ENVIRONMENT
2579 && (par.layout().latextype != LATEX_ITEM_ENVIRONMENT
2580 || par.layout().margintype != MARGIN_FIRST_DYNAMIC))
2583 return (pos < body_pos
2585 && (pos == 0 || par.getChar(pos - 1) != ' ')));