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.
20 #include "BranchList.h"
21 #include "FloatList.h"
22 #include "FuncStatus.h"
24 #include "buffer_funcs.h"
25 #include "BufferParams.h"
26 #include "BufferView.h"
27 #include "bufferview_funcs.h"
29 #include "CoordCache.h"
30 #include "CutAndPaste.h"
32 #include "DispatchResult.h"
33 #include "ErrorList.h"
35 #include "FuncRequest.h"
39 #include "LyXAction.h"
44 #include "Paragraph.h"
45 #include "paragraph_funcs.h"
46 #include "ParagraphParameters.h"
49 #include "ParIterator.h"
51 #include "frontends/Clipboard.h"
52 #include "frontends/Selection.h"
54 #include "insets/InsetCommand.h"
55 #include "insets/InsetFloatList.h"
56 #include "insets/InsetNewline.h"
57 #include "insets/InsetQuotes.h"
58 #include "insets/InsetSpecialChar.h"
59 #include "insets/InsetText.h"
61 #include "support/lstrings.h"
62 #include "support/lyxlib.h"
63 #include "support/convert.h"
64 #include "support/lyxtime.h"
66 #include "mathed/InsetMathHull.h"
67 #include "mathed/MathMacroTemplate.h"
69 #include <boost/current_function.hpp>
77 using cap::copySelection;
78 using cap::cutSelection;
79 using cap::pasteFromStack;
80 using cap::pasteClipboard;
81 using cap::replaceSelection;
82 using cap::saveSelection;
84 using support::isStrUnsignedInt;
89 using std::istringstream;
90 using std::ostringstream;
93 extern string current_layout;
99 Font freefont(Font::ALL_IGNORE);
100 bool toggleall = false;
102 void toggleAndShow(Cursor & cur, Text * text,
103 Font const & font, bool toggleall = true)
105 text->toggleFree(cur, font, toggleall);
107 if (font.language() != ignore_language ||
108 font.number() != Font::IGNORE) {
109 Paragraph & par = cur.paragraph();
110 if (cur.boundary() != text->isRTLBoundary(cur.buffer(), par,
111 cur.pos(), text->real_current_font))
112 text->setCursor(cur, cur.pit(), cur.pos(),
113 false, !cur.boundary());
118 void moveCursor(Cursor & cur, bool selecting)
120 if (selecting || cur.mark())
125 void finishChange(Cursor & cur, bool selecting)
128 moveCursor(cur, selecting);
132 void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
135 docstring sel = cur.selectionAsString(false);
137 // It may happen that sel is empty but there is a selection
138 replaceSelection(cur);
141 #ifdef ENABLE_ASSERTIONS
142 const int old_pos = cur.pos();
144 cur.insert(new InsetMathHull(hullSimple));
145 BOOST_ASSERT(old_pos == cur.pos());
146 cur.nextInset()->edit(cur, true);
147 // don't do that also for LFUN_MATH_MODE
148 // unless you want end up with always changing
149 // to mathrm when opening an inlined inset --
150 // I really hate "LyXfunc overloading"...
152 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
153 // Avoid an unnecessary undo step if cmd.argument
155 if (!cmd.argument().empty())
156 cur.dispatch(FuncRequest(LFUN_MATH_INSERT,
159 // create a macro if we see "\\newcommand"
160 // somewhere, and an ordinary formula
162 if (sel.find(from_ascii("\\newcommand")) == string::npos
163 && sel.find(from_ascii("\\def")) == string::npos)
165 InsetMathHull * formula = new InsetMathHull;
166 istringstream is(to_utf8(sel));
169 formula->read(cur.buffer(), lex);
170 if (formula->getType() == hullNone)
171 // Don't create pseudo formulas if
172 // delimiters are left out
173 formula->mutate(hullSimple);
176 cur.insert(new MathMacroTemplate(sel));
179 cur.message(from_utf8(N_("Math editor mode")));
188 string const freefont2string()
191 if (font2string(freefont, toggleall, data))
198 void Text::cursorPrevious(Cursor & cur)
200 pos_type cpos = cur.pos();
201 pit_type cpar = cur.pit();
203 int x = cur.x_target();
204 setCursorFromCoordinates(cur, x, 0);
205 cur.dispatch(FuncRequest(cur.selection()? LFUN_UP_SELECT: LFUN_UP));
207 if (cpar == cur.pit() && cpos == cur.pos())
208 // we have a row which is taller than the workarea. The
209 // simplest solution is to move to the previous row instead.
210 cur.dispatch(FuncRequest(cur.selection()? LFUN_UP_SELECT: LFUN_UP));
213 cur.updateFlags(Update::Force | Update::FitCursor);
217 void Text::cursorNext(Cursor & cur)
219 pos_type cpos = cur.pos();
220 pit_type cpar = cur.pit();
222 int x = cur.x_target();
223 setCursorFromCoordinates(cur, x, cur.bv().workHeight() - 1);
224 cur.dispatch(FuncRequest(cur.selection()? LFUN_DOWN_SELECT: LFUN_DOWN));
226 if (cpar == cur.pit() && cpos == cur.pos())
227 // we have a row which is taller than the workarea. The
228 // simplest solution is to move to the next row instead.
230 FuncRequest(cur.selection()? LFUN_DOWN_SELECT: LFUN_DOWN));
233 cur.updateFlags(Update::Force | Update::FitCursor);
239 void specialChar(Cursor & cur, InsetSpecialChar::Kind kind)
242 cap::replaceSelection(cur);
243 cur.insert(new InsetSpecialChar(kind));
248 bool doInsertInset(Cursor & cur, Text * text,
249 FuncRequest const & cmd, bool edit, bool pastesel)
251 Inset * inset = createInset(&cur.bv(), cmd);
257 if (cur.selection()) {
258 lyx::dispatch(FuncRequest(LFUN_CUT));
261 text->insertInset(cur, inset);
264 inset->edit(cur, true);
266 if (gotsel && pastesel) {
267 lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
268 // reset first par to default
269 if (cur.lastpit() != 0 || cur.lastpos() != 0) {
270 Layout_ptr const layout =
271 cur.buffer().params().getTextClass().defaultLayout();
272 cur.text()->paragraphs().begin()->layout(layout);
282 void Text::number(Cursor & cur)
284 Font font(Font::ALL_IGNORE);
285 font.setNumber(Font::TOGGLE);
286 toggleAndShow(cur, this, font);
290 bool Text::isRTL(Buffer const & buffer, Paragraph const & par) const
292 return par.isRightToLeftPar(buffer.params());
296 bool Text::isRTL(Buffer const & buffer, CursorSlice const & sl, bool boundary) const
298 if (!lyxrc.rtl_support && !sl.text())
302 if (boundary && sl.pos() > 0)
305 Paragraph const & par = getPar(sl.pit());
306 return getFont(buffer, par, sl.pos() + correction).isVisibleRightToLeft();
310 bool Text::isRTLBoundary(Buffer const & buffer, Paragraph const & par,
313 if (!lyxrc.rtl_support)
316 // no RTL boundary at line start
320 bool left = getFont(buffer, par, pos - 1).isVisibleRightToLeft();
322 if (pos == par.size())
323 right = par.isRightToLeftPar(buffer.params());
325 right = getFont(buffer, par, pos).isVisibleRightToLeft();
326 return left != right;
330 bool Text::isRTLBoundary(Buffer const & buffer, Paragraph const & par,
331 pos_type pos, Font const & font) const
333 if (!lyxrc.rtl_support)
336 bool left = font.isVisibleRightToLeft();
338 if (pos == par.size())
339 right = par.isRightToLeftPar(buffer.params());
341 right = getFont(buffer, par, pos).isVisibleRightToLeft();
342 return left != right;
346 void Text::dispatch(Cursor & cur, FuncRequest & cmd)
348 LYXERR(Debug::ACTION) << "Text::dispatch: cmd: " << cmd << endl;
350 // FIXME: We use the update flag to indicates wether a singlePar or a
351 // full screen update is needed. We reset it here but shall we restore it
355 BOOST_ASSERT(cur.text() == this);
356 BufferView * bv = &cur.bv();
357 CursorSlice oldTopSlice = cur.top();
358 bool oldBoundary = cur.boundary();
359 bool sel = cur.selection();
360 // Signals that, even if needsUpdate == false, an update of the
361 // cursor paragraph is required
362 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
363 LyXAction::SingleParUpdate);
364 // Signals that a full-screen update is required
365 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
366 LyXAction::NoUpdate) || singleParUpdate);
367 // Remember the old paragraph metric (_outer_ paragraph!)
368 ParagraphMetrics const & pm = cur.bv().parMetrics(
369 cur.bottom().text(), cur.bottom().pit());
370 Dimension olddim = pm.dim();
372 switch (cmd.action) {
374 case LFUN_PARAGRAPH_MOVE_DOWN: {
375 pit_type const pit = cur.pit();
376 recUndo(cur, pit, pit + 1);
378 std::swap(pars_[pit], pars_[pit + 1]);
380 ParIterator begin(cur);
381 // begin.pos() (== cur.pos()) may point beyond the end of the
382 // paragraph referenced by begin. This would cause a crash
386 ParIterator end = boost::next(ParIterator(cur));
387 updateLabels(cur.buffer(), begin, end);
393 case LFUN_PARAGRAPH_MOVE_UP: {
394 pit_type const pit = cur.pit();
395 recUndo(cur, pit - 1, pit);
397 std::swap(pars_[pit], pars_[pit - 1]);
399 ParIterator end = ParIterator(cur);
400 // end.pos() (== cur.pos()) may point beyond the end of the
401 // paragraph referenced by end. This would cause a crash
404 end = boost::next(end);
406 ParIterator begin(cur);
407 updateLabels(cur.buffer(), begin, end);
413 case LFUN_APPENDIX: {
414 Paragraph & par = cur.paragraph();
415 bool start = !par.params().startOfAppendix();
418 #warning The code below only makes sense at top level.
419 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
421 // ensure that we have only one start_of_appendix in this document
422 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
423 if (pars_[tmp].params().startOfAppendix()) {
425 pars_[tmp].params().startOfAppendix(false);
431 par.params().startOfAppendix(start);
433 // we can set the refreshing parameters now
434 updateLabels(cur.buffer());
438 case LFUN_WORD_DELETE_FORWARD:
439 cur.clearSelection();
440 deleteWordForward(cur);
441 finishChange(cur, false);
444 case LFUN_WORD_DELETE_BACKWARD:
445 cur.clearSelection();
446 deleteWordBackward(cur);
447 finishChange(cur, false);
450 case LFUN_LINE_DELETE:
451 cur.clearSelection();
452 deleteLineForward(cur);
453 finishChange(cur, false);
456 case LFUN_BUFFER_BEGIN:
457 case LFUN_BUFFER_BEGIN_SELECT:
458 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
459 if (cur.depth() == 1) {
460 needsUpdate |= cursorTop(cur);
466 case LFUN_BUFFER_END:
467 case LFUN_BUFFER_END_SELECT:
468 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
469 if (cur.depth() == 1) {
470 needsUpdate |= cursorBottom(cur);
476 case LFUN_CHAR_FORWARD:
477 case LFUN_CHAR_FORWARD_SELECT:
478 //lyxerr << BOOST_CURRENT_FUNCTION
479 // << " LFUN_CHAR_FORWARD[SEL]:\n" << cur << endl;
480 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
481 if (reverseDirectionNeeded(cur))
482 needsUpdate |= cursorLeft(cur);
484 needsUpdate |= cursorRight(cur);
486 if (!needsUpdate && oldTopSlice == cur.top()
487 && cur.boundary() == oldBoundary) {
489 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
493 case LFUN_CHAR_BACKWARD:
494 case LFUN_CHAR_BACKWARD_SELECT:
495 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
496 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
497 if (reverseDirectionNeeded(cur))
498 needsUpdate |= cursorRight(cur);
500 needsUpdate |= cursorLeft(cur);
502 if (!needsUpdate && oldTopSlice == cur.top()
503 && cur.boundary() == oldBoundary) {
505 cmd = FuncRequest(LFUN_FINISHED_LEFT);
510 case LFUN_DOWN_SELECT:
513 // stop/start the selection
514 bool select = cmd.action == LFUN_DOWN_SELECT ||
515 cmd.action == LFUN_UP_SELECT;
516 cur.selHandle(select);
518 // move cursor up/down
519 bool up = cmd.action == LFUN_UP_SELECT || cmd.action == LFUN_UP;
520 bool const successful = cur.upDownInText(up, needsUpdate);
522 // notify insets which were left and get their update flags
523 notifyCursorLeaves(cur.beforeDispatchCursor(), cur);
526 // redraw if you leave mathed (for the decorations)
527 needsUpdate |= cur.beforeDispatchCursor().inMathed();
534 case LFUN_PARAGRAPH_UP:
535 case LFUN_PARAGRAPH_UP_SELECT:
536 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
537 needsUpdate |= cursorUpParagraph(cur);
540 case LFUN_PARAGRAPH_DOWN:
541 case LFUN_PARAGRAPH_DOWN_SELECT:
542 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
543 needsUpdate |= cursorDownParagraph(cur);
547 case LFUN_SCREEN_UP_SELECT:
548 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_UP_SELECT);
549 if (cur.pit() == 0 && cur.textRow().pos() == 0)
556 case LFUN_SCREEN_DOWN:
557 case LFUN_SCREEN_DOWN_SELECT:
558 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_DOWN_SELECT);
559 if (cur.pit() == cur.lastpit()
560 && cur.textRow().endpos() == cur.lastpos())
567 case LFUN_LINE_BEGIN:
568 case LFUN_LINE_BEGIN_SELECT:
569 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
570 needsUpdate |= cursorHome(cur);
574 case LFUN_LINE_END_SELECT:
575 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
576 needsUpdate |= cursorEnd(cur);
579 case LFUN_WORD_FORWARD:
580 case LFUN_WORD_FORWARD_SELECT:
581 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
582 if (reverseDirectionNeeded(cur))
583 needsUpdate |= cursorLeftOneWord(cur);
585 needsUpdate |= cursorRightOneWord(cur);
588 case LFUN_WORD_BACKWARD:
589 case LFUN_WORD_BACKWARD_SELECT:
590 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
591 if (reverseDirectionNeeded(cur))
592 needsUpdate |= cursorRightOneWord(cur);
594 needsUpdate |= cursorLeftOneWord(cur);
597 case LFUN_WORD_SELECT: {
598 selectWord(cur, WHOLE_WORD);
599 finishChange(cur, true);
603 case LFUN_BREAK_LINE: {
604 // Not allowed by LaTeX (labels or empty par)
605 if (cur.pos() > cur.paragraph().beginOfBody()) {
606 // this avoids a double undo
607 // FIXME: should not be needed, ideally
608 if (!cur.selection())
610 cap::replaceSelection(cur);
611 cur.insert(new InsetNewline);
613 moveCursor(cur, false);
618 case LFUN_CHAR_DELETE_FORWARD:
619 if (!cur.selection()) {
620 if (cur.pos() == cur.paragraph().size())
621 // Par boundary, force full-screen update
622 singleParUpdate = false;
623 needsUpdate |= erase(cur);
625 // It is possible to make it a lot faster still
626 // just comment out the line below...
628 cutSelection(cur, true, false);
629 singleParUpdate = false;
631 moveCursor(cur, false);
634 case LFUN_DELETE_FORWARD_SKIP:
635 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
636 if (!cur.selection()) {
637 if (cur.pos() == cur.lastpos()) {
644 cutSelection(cur, true, false);
649 case LFUN_CHAR_DELETE_BACKWARD:
650 if (!cur.selection()) {
651 if (bv->getIntl().getTransManager().backspace()) {
652 // Par boundary, full-screen update
654 singleParUpdate = false;
655 needsUpdate |= backspace(cur);
657 // It is possible to make it a lot faster still
658 // just comment out the line below...
661 cutSelection(cur, true, false);
662 singleParUpdate = false;
666 case LFUN_DELETE_BACKWARD_SKIP:
667 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
668 if (!cur.selection()) {
672 //CursorSlice cur = cursor();
676 cutSelection(cur, true, false);
680 case LFUN_BREAK_PARAGRAPH:
681 cap::replaceSelection(cur);
682 breakParagraph(cur, 0);
686 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
687 cap::replaceSelection(cur);
688 breakParagraph(cur, 1);
692 case LFUN_BREAK_PARAGRAPH_SKIP: {
693 // When at the beginning of a paragraph, remove
694 // indentation. Otherwise, do the same as LFUN_BREAK_PARAGRAPH.
695 cap::replaceSelection(cur);
697 cur.paragraph().params().labelWidthString(docstring());
699 breakParagraph(cur, 0);
704 case LFUN_PARAGRAPH_SPACING: {
705 Paragraph & par = cur.paragraph();
706 Spacing::Space cur_spacing = par.params().spacing().getSpace();
707 string cur_value = "1.0";
708 if (cur_spacing == Spacing::Other)
709 cur_value = par.params().spacing().getValueAsString();
711 istringstream is(to_utf8(cmd.argument()));
714 Spacing::Space new_spacing = cur_spacing;
715 string new_value = cur_value;
717 lyxerr << "Missing argument to `paragraph-spacing'"
719 } else if (tmp == "single") {
720 new_spacing = Spacing::Single;
721 } else if (tmp == "onehalf") {
722 new_spacing = Spacing::Onehalf;
723 } else if (tmp == "double") {
724 new_spacing = Spacing::Double;
725 } else if (tmp == "other") {
726 new_spacing = Spacing::Other;
727 string tmpval = "0.0";
729 lyxerr << "new_value = " << tmpval << endl;
732 } else if (tmp == "default") {
733 new_spacing = Spacing::Default;
735 lyxerr << to_utf8(_("Unknown spacing argument: "))
736 << to_utf8(cmd.argument()) << endl;
738 if (cur_spacing != new_spacing || cur_value != new_value)
739 par.params().spacing(Spacing(new_spacing, new_value));
743 case LFUN_INSET_INSERT: {
745 Inset * inset = createInset(bv, cmd);
747 // FIXME (Abdel 01/02/2006):
748 // What follows would be a partial fix for bug 2154:
749 // http://bugzilla.lyx.org/show_bug.cgi?id=2154
750 // This automatically put the label inset _after_ a
751 // numbered section. It should be possible to extend the mechanism
752 // to any kind of LateX environement.
753 // The correct way to fix that bug would be at LateX generation.
754 // I'll let the code here for reference as it could be used for some
755 // other feature like "automatic labelling".
757 Paragraph & par = pars_[cur.pit()];
758 if (inset->lyxCode() == Inset::LABEL_CODE
759 && par.layout()->labeltype == LABEL_COUNTER) {
760 // Go to the end of the paragraph
761 // Warning: Because of Change-Tracking, the last
762 // position is 'size()' and not 'size()-1':
763 cur.pos() = par.size();
764 // Insert a new paragraph
765 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
769 insertInset(cur, inset);
775 case LFUN_INSET_DISSOLVE:
776 needsUpdate |= dissolveInset(cur);
779 case LFUN_INSET_SETTINGS:
780 cur.inset().showInsetDialog(bv);
783 case LFUN_SPACE_INSERT:
784 if (cur.paragraph().layout()->free_spacing)
785 insertChar(cur, ' ');
787 doInsertInset(cur, this, cmd, false, false);
790 moveCursor(cur, false);
793 case LFUN_HYPHENATION_POINT_INSERT:
794 specialChar(cur, InsetSpecialChar::HYPHENATION);
797 case LFUN_LIGATURE_BREAK_INSERT:
798 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
801 case LFUN_DOTS_INSERT:
802 specialChar(cur, InsetSpecialChar::LDOTS);
805 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
806 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
809 case LFUN_MENU_SEPARATOR_INSERT:
810 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
813 case LFUN_WORD_UPCASE:
814 changeCase(cur, Text::text_uppercase);
817 case LFUN_WORD_LOWCASE:
818 changeCase(cur, Text::text_lowercase);
821 case LFUN_WORD_CAPITALIZE:
822 changeCase(cur, Text::text_capitalization);
825 case LFUN_CHARS_TRANSPOSE:
830 cur.message(_("Paste"));
831 cap::replaceSelection(cur);
832 if (cmd.argument().empty() && !theClipboard().isInternal())
833 pasteClipboard(cur, bv->buffer()->errorList("Paste"));
835 string const arg(to_utf8(cmd.argument()));
836 pasteFromStack(cur, bv->buffer()->errorList("Paste"),
837 isStrUnsignedInt(arg) ?
838 convert<unsigned int>(arg) :
841 bv->buffer()->errors("Paste");
842 cur.clearSelection(); // bug 393
847 cutSelection(cur, true, true);
848 cur.message(_("Cut"));
853 cur.message(_("Copy"));
856 case LFUN_SERVER_GET_XY:
857 cur.message(from_utf8(
858 convert<string>(cursorX(cur.bv(), cur.top(), cur.boundary()))
859 + ' ' + convert<string>(cursorY(cur.bv(), cur.top(), cur.boundary()))));
862 case LFUN_SERVER_SET_XY: {
865 istringstream is(to_utf8(cmd.argument()));
868 lyxerr << "SETXY: Could not parse coordinates in '"
869 << to_utf8(cmd.argument()) << std::endl;
871 setCursorFromCoordinates(cur, x, y);
875 case LFUN_SERVER_GET_FONT:
876 if (current_font.shape() == Font::ITALIC_SHAPE)
877 cur.message(from_ascii("E"));
878 else if (current_font.shape() == Font::SMALLCAPS_SHAPE)
879 cur.message(from_ascii("N"));
881 cur.message(from_ascii("0"));
884 case LFUN_SERVER_GET_LAYOUT:
885 cur.message(from_utf8(cur.paragraph().layout()->name()));
889 string layout = to_ascii(cmd.argument());
890 LYXERR(Debug::INFO) << "LFUN_LAYOUT: (arg) " << layout << endl;
892 // Derive layout number from given argument (string)
893 // and current buffer's textclass (number)
894 TextClass const & tclass = bv->buffer()->params().getTextClass();
896 layout = tclass.defaultLayoutName();
897 bool hasLayout = tclass.hasLayout(layout);
899 // If the entry is obsolete, use the new one instead.
901 string const & obs = tclass[layout]->obsoleted_by();
907 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
908 from_utf8(N_(" not known")));
912 bool change_layout = (current_layout != layout);
914 if (!change_layout && cur.selection() &&
915 cur.selBegin().pit() != cur.selEnd().pit())
917 pit_type spit = cur.selBegin().pit();
918 pit_type epit = cur.selEnd().pit() + 1;
919 while (spit != epit) {
920 if (pars_[spit].layout()->name() != current_layout) {
921 change_layout = true;
929 setLayout(cur, layout);
930 // inform the GUI that the layout has changed.
931 bv->layoutChanged(layout);
936 case LFUN_CLIPBOARD_PASTE:
937 cur.clearSelection();
938 pasteClipboard(cur, bv->buffer()->errorList("Paste"),
939 cmd.argument() == "paragraph");
940 bv->buffer()->errors("Paste");
943 case LFUN_PRIMARY_SELECTION_PASTE:
944 pasteString(cur, theSelection().get(),
945 cmd.argument() == "paragraph");
948 case LFUN_UNICODE_INSERT: {
949 if (cmd.argument().empty())
951 docstring hexstring = cmd.argument();
952 if (lyx::support::isHex(hexstring)) {
953 char_type c = lyx::support::hexToInt(hexstring);
954 if (c >= 32 && c < 0x10ffff) {
955 lyxerr << "Inserting c: " << c << endl;
956 docstring s = docstring(1, c);
957 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
963 case LFUN_QUOTE_INSERT: {
964 Paragraph & par = cur.paragraph();
965 pos_type pos = cur.pos();
966 BufferParams const & bufparams = bv->buffer()->params();
967 Layout_ptr const & style = par.layout();
968 if (!style->pass_thru
969 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
970 // this avoids a double undo
971 // FIXME: should not be needed, ideally
972 if (!cur.selection())
974 cap::replaceSelection(cur);
979 else if (cur.prevInset() && cur.prevInset()->isSpace())
982 c = par.getChar(pos - 1);
983 string arg = to_utf8(cmd.argument());
985 cur.insert(new InsetQuotes(c,
986 bufparams.quotes_language,
987 InsetQuotes::SingleQ));
989 cur.insert(new InsetQuotes(c,
990 bufparams.quotes_language,
991 InsetQuotes::DoubleQ));
995 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
999 case LFUN_DATE_INSERT:
1000 if (cmd.argument().empty())
1001 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
1002 formatted_time(current_time())));
1004 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
1005 formatted_time(current_time(), to_utf8(cmd.argument()))));
1008 case LFUN_MOUSE_TRIPLE:
1009 if (cmd.button() == mouse_button::button1) {
1018 case LFUN_MOUSE_DOUBLE:
1019 if (cmd.button() == mouse_button::button1) {
1020 selectWord(cur, WHOLE_WORD_STRICT);
1025 // Single-click on work area
1026 case LFUN_MOUSE_PRESS: {
1027 // Right click on a footnote flag opens float menu
1028 if (cmd.button() == mouse_button::button3)
1029 cur.clearSelection();
1031 // Middle button press pastes if we have a selection
1032 // We do this here as if the selection was inside an inset
1033 // it could get cleared on the unlocking of the inset so
1034 // we have to check this first
1035 bool paste_internally = false;
1036 if (cmd.button() == mouse_button::button2 && cap::selection()) {
1037 // Copy the selection buffer to the clipboard
1038 // stack, because we want it to appear in the
1039 // "Edit->Paste recent" menu.
1040 cap::copySelectionToStack();
1041 paste_internally = true;
1044 // Insert primary selection with middle mouse
1045 // if there is a local selection in the current buffer,
1047 if (cmd.button() == mouse_button::button2) {
1048 if (paste_internally) {
1049 cap::pasteSelection(cur, bv->buffer()->errorList("Paste"));
1050 bv->buffer()->errors("Paste");
1051 cur.clearSelection(); // bug 393
1052 bv->buffer()->markDirty();
1055 bv->mouseSetCursor(cur);
1056 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
1060 // we have to update after dePM triggered
1061 bool update = bv->mouseSetCursor(cur);
1063 if (!update && cmd.button() == mouse_button::button1) {
1064 needsUpdate = false;
1071 case LFUN_MOUSE_MOTION: {
1072 // Only use motion with button 1
1073 //if (cmd.button() != mouse_button::button1)
1076 // ignore motions deeper nested than the real anchor
1077 Cursor & bvcur = cur.bv().cursor();
1078 if (bvcur.anchor_.hasPart(cur)) {
1079 CursorSlice old = bvcur.top();
1081 int const wh = bv->workHeight();
1082 int const y = std::max(0, std::min(wh - 1, cmd.y));
1084 setCursorFromCoordinates(cur, cmd.x, y);
1085 cur.setTargetX(cmd.x);
1087 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1089 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1090 // This is to allow jumping over large insets
1091 if (cur.top() == old) {
1093 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1095 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1098 if (cur.top() == old)
1101 // don't set anchor_
1102 bvcur.setCursor(cur);
1103 bvcur.selection() = true;
1104 //lyxerr << "MOTION: " << bv->cursor() << endl;
1112 case LFUN_MOUSE_RELEASE: {
1113 if (cmd.button() == mouse_button::button2)
1116 if (cmd.button() == mouse_button::button1) {
1117 // if there is new selection, update persistent
1118 // selection, otherwise, single click does not
1119 // clear persistent selection buffer
1120 if (cur.selection()) {
1122 // if double click, cur is moved to the end of word by selectWord
1123 // but bvcur is current mouse position
1124 Cursor & bvcur = cur.bv().cursor();
1125 bvcur.selection() = true;
1127 needsUpdate = false;
1134 case LFUN_SELF_INSERT: {
1135 if (cmd.argument().empty())
1138 // Automatically delete the currently selected
1139 // text and replace it with what is being
1140 // typed in now. Depends on lyxrc settings
1141 // "auto_region_delete", which defaults to
1144 if (lyxrc.auto_region_delete)
1145 if (cur.selection())
1146 cutSelection(cur, false, false);
1148 cur.clearSelection();
1149 Font const old_font = real_current_font;
1151 docstring::const_iterator cit = cmd.argument().begin();
1152 docstring::const_iterator end = cmd.argument().end();
1153 for (; cit != end; ++cit)
1154 bv->translateAndInsert(*cit, this, cur);
1157 moveCursor(cur, false);
1161 case LFUN_URL_INSERT: {
1162 InsetCommandParams p("url");
1163 string const data = InsetCommandMailer::params2string("url", p);
1164 bv->showInsetDialog("url", data, 0);
1168 case LFUN_HTML_INSERT: {
1169 InsetCommandParams p("htmlurl");
1170 string const data = InsetCommandMailer::params2string("url", p);
1171 bv->showInsetDialog("url", data, 0);
1175 case LFUN_LABEL_INSERT: {
1176 InsetCommandParams p("label");
1177 // Try to generate a valid label
1178 p["name"] = (cmd.argument().empty()) ?
1179 cur.getPossibleLabel() :
1181 string const data = InsetCommandMailer::params2string("label", p);
1183 if (cmd.argument().empty()) {
1184 bv->showInsetDialog("label", data, 0);
1186 FuncRequest fr(LFUN_INSET_INSERT, data);
1194 case LFUN_LIST_INSERT:
1195 case LFUN_THEOREM_INSERT:
1197 case LFUN_CAPTION_INSERT:
1198 // Open the inset, and move the current selection
1200 doInsertInset(cur, this, cmd, true, true);
1202 updateLabels(*bv->buffer());
1204 case LFUN_NOTE_INSERT:
1205 case LFUN_CHARSTYLE_INSERT:
1206 case LFUN_BOX_INSERT:
1207 case LFUN_BRANCH_INSERT:
1208 case LFUN_BIBITEM_INSERT:
1209 case LFUN_ERT_INSERT:
1210 case LFUN_LISTING_INSERT:
1211 case LFUN_FOOTNOTE_INSERT:
1212 case LFUN_MARGINALNOTE_INSERT:
1213 case LFUN_OPTIONAL_INSERT:
1214 case LFUN_ENVIRONMENT_INSERT:
1215 // Open the inset, and move the current selection
1217 doInsertInset(cur, this, cmd, true, true);
1221 case LFUN_TABULAR_INSERT:
1222 // if there were no arguments, just open the dialog
1223 if (doInsertInset(cur, this, cmd, false, true))
1226 bv->showDialog("tabularcreate");
1230 case LFUN_FLOAT_INSERT:
1231 case LFUN_FLOAT_WIDE_INSERT:
1232 case LFUN_WRAP_INSERT: {
1233 bool content = cur.selection(); // will some text be moved into the inset?
1235 doInsertInset(cur, this, cmd, true, true);
1237 ParagraphList & pars = cur.text()->paragraphs();
1239 TextClass const & tclass = bv->buffer()->params().getTextClass();
1241 // add a separate paragraph for the caption inset
1242 pars.push_back(Paragraph());
1243 pars.back().setInsetOwner(pars[0].inInset());
1244 pars.back().layout(tclass.defaultLayout());
1246 int cap_pit = pars.size() - 1;
1248 // if an empty inset was created, we create an additional empty
1249 // paragraph at the bottom so that the user can choose where to put
1250 // the graphics (or table).
1252 pars.push_back(Paragraph());
1253 pars.back().setInsetOwner(pars[0].inInset());
1254 pars.back().layout(tclass.defaultLayout());
1258 // reposition the cursor to the caption
1259 cur.pit() = cap_pit;
1261 cur.dispatch(FuncRequest(LFUN_CAPTION_INSERT));
1262 // FIXME: When leaving the Float (or Wrap) inset we should
1263 // delete any empty paragraph left above or below the
1268 case LFUN_INDEX_INSERT:
1269 case LFUN_NOMENCL_INSERT: {
1270 Inset * inset = createInset(&cur.bv(), cmd);
1274 cur.clearSelection();
1275 insertInset(cur, inset);
1276 inset->edit(cur, true);
1277 // Show the dialog for the nomenclature entry, since the
1278 // description entry still needs to be filled in.
1279 if (cmd.action == LFUN_NOMENCL_INSERT)
1280 InsetCommandMailer("nomenclature",
1281 *reinterpret_cast<InsetCommand *>(inset)).showDialog(&cur.bv());
1286 case LFUN_INDEX_PRINT:
1287 case LFUN_NOMENCL_PRINT:
1288 case LFUN_TOC_INSERT:
1289 case LFUN_HFILL_INSERT:
1290 case LFUN_LINE_INSERT:
1291 case LFUN_PAGEBREAK_INSERT:
1292 case LFUN_CLEARPAGE_INSERT:
1293 case LFUN_CLEARDOUBLEPAGE_INSERT:
1295 doInsertInset(cur, this, cmd, false, false);
1299 case LFUN_DEPTH_DECREMENT:
1300 changeDepth(cur, DEC_DEPTH);
1303 case LFUN_DEPTH_INCREMENT:
1304 changeDepth(cur, INC_DEPTH);
1307 case LFUN_MATH_DISPLAY:
1308 mathDispatch(cur, cmd, true);
1311 case LFUN_MATH_IMPORT_SELECTION:
1312 case LFUN_MATH_MODE:
1313 if (cmd.argument() == "on")
1314 // don't pass "on" as argument
1315 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1317 mathDispatch(cur, cmd, false);
1320 case LFUN_MATH_MACRO:
1321 if (cmd.argument().empty())
1322 cur.errorMessage(from_utf8(N_("Missing argument")));
1324 string s = to_utf8(cmd.argument());
1325 string const s1 = token(s, ' ', 1);
1326 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1327 string const s2 = token(s, ' ', 2);
1328 string const type = s2.empty() ? "newcommand" : s2;
1329 cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, from_utf8(type)));
1330 //cur.nextInset()->edit(cur, true);
1334 // passthrough hat and underscore outside mathed:
1335 case LFUN_MATH_SUBSCRIPT:
1336 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1338 case LFUN_MATH_SUPERSCRIPT:
1339 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1342 case LFUN_MATH_INSERT:
1343 case LFUN_MATH_MATRIX:
1344 case LFUN_MATH_DELIM:
1345 case LFUN_MATH_BIGDELIM: {
1346 cur.insert(new InsetMathHull(hullSimple));
1347 checkAndActivateInset(cur, true);
1348 BOOST_ASSERT(cur.inMathed());
1353 case LFUN_FONT_EMPH: {
1354 Font font(Font::ALL_IGNORE);
1355 font.setEmph(Font::TOGGLE);
1356 toggleAndShow(cur, this, font);
1360 case LFUN_FONT_BOLD: {
1361 Font font(Font::ALL_IGNORE);
1362 font.setSeries(Font::BOLD_SERIES);
1363 toggleAndShow(cur, this, font);
1367 case LFUN_FONT_NOUN: {
1368 Font font(Font::ALL_IGNORE);
1369 font.setNoun(Font::TOGGLE);
1370 toggleAndShow(cur, this, font);
1374 case LFUN_FONT_CODE: {
1375 Font font(Font::ALL_IGNORE);
1376 font.setFamily(Font::TYPEWRITER_FAMILY); // no good
1377 toggleAndShow(cur, this, font);
1381 case LFUN_FONT_SANS: {
1382 Font font(Font::ALL_IGNORE);
1383 font.setFamily(Font::SANS_FAMILY);
1384 toggleAndShow(cur, this, font);
1388 case LFUN_FONT_ROMAN: {
1389 Font font(Font::ALL_IGNORE);
1390 font.setFamily(Font::ROMAN_FAMILY);
1391 toggleAndShow(cur, this, font);
1395 case LFUN_FONT_DEFAULT: {
1396 Font font(Font::ALL_INHERIT, ignore_language);
1397 toggleAndShow(cur, this, font);
1401 case LFUN_FONT_UNDERLINE: {
1402 Font font(Font::ALL_IGNORE);
1403 font.setUnderbar(Font::TOGGLE);
1404 toggleAndShow(cur, this, font);
1408 case LFUN_FONT_SIZE: {
1409 Font font(Font::ALL_IGNORE);
1410 font.setLyXSize(to_utf8(cmd.argument()));
1411 toggleAndShow(cur, this, font);
1415 case LFUN_LANGUAGE: {
1416 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1419 Font font(Font::ALL_IGNORE);
1420 font.setLanguage(lang);
1421 toggleAndShow(cur, this, font);
1425 case LFUN_FONT_FREE_APPLY:
1426 toggleAndShow(cur, this, freefont, toggleall);
1427 cur.message(_("Character set"));
1430 // Set the freefont using the contents of \param data dispatched from
1431 // the frontends and apply it at the current cursor location.
1432 case LFUN_FONT_FREE_UPDATE: {
1435 if (bv_funcs::string2font(to_utf8(cmd.argument()), font, toggle)) {
1438 toggleAndShow(cur, this, freefont, toggleall);
1439 cur.message(_("Character set"));
1444 case LFUN_FINISHED_LEFT:
1445 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1446 if (reverseDirectionNeeded(cur))
1450 case LFUN_FINISHED_RIGHT:
1451 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1452 if (!reverseDirectionNeeded(cur))
1456 case LFUN_LAYOUT_PARAGRAPH: {
1458 params2string(cur.paragraph(), data);
1459 data = "show\n" + data;
1460 bv->showDialogWithData("paragraph", data);
1464 case LFUN_PARAGRAPH_UPDATE: {
1466 params2string(cur.paragraph(), data);
1468 // Will the paragraph accept changes from the dialog?
1469 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1471 data = "update " + convert<string>(accept) + '\n' + data;
1472 bv->updateDialog("paragraph", data);
1476 case LFUN_ACCENT_UMLAUT:
1477 case LFUN_ACCENT_CIRCUMFLEX:
1478 case LFUN_ACCENT_GRAVE:
1479 case LFUN_ACCENT_ACUTE:
1480 case LFUN_ACCENT_TILDE:
1481 case LFUN_ACCENT_CEDILLA:
1482 case LFUN_ACCENT_MACRON:
1483 case LFUN_ACCENT_DOT:
1484 case LFUN_ACCENT_UNDERDOT:
1485 case LFUN_ACCENT_UNDERBAR:
1486 case LFUN_ACCENT_CARON:
1487 case LFUN_ACCENT_SPECIAL_CARON:
1488 case LFUN_ACCENT_BREVE:
1489 case LFUN_ACCENT_TIE:
1490 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1491 case LFUN_ACCENT_CIRCLE:
1492 case LFUN_ACCENT_OGONEK:
1493 theLyXFunc().handleKeyFunc(cmd.action);
1494 if (!cmd.argument().empty())
1495 // FIXME: Are all these characters encoded in one byte in utf8?
1496 bv->translateAndInsert(cmd.argument()[0], this, cur);
1499 case LFUN_FLOAT_LIST: {
1500 TextClass const & tclass = bv->buffer()->params().getTextClass();
1501 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1502 // not quite sure if we want this...
1504 cur.clearSelection();
1505 breakParagraph(cur);
1507 if (cur.lastpos() != 0) {
1509 breakParagraph(cur);
1512 setLayout(cur, tclass.defaultLayoutName());
1513 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, docstring(), 0);
1514 insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1517 lyxerr << "Non-existent float type: "
1518 << to_utf8(cmd.argument()) << endl;
1523 case LFUN_CHANGE_ACCEPT: {
1524 acceptOrRejectChanges(cur, ACCEPT);
1528 case LFUN_CHANGE_REJECT: {
1529 acceptOrRejectChanges(cur, REJECT);
1533 case LFUN_THESAURUS_ENTRY: {
1534 docstring arg = cmd.argument();
1536 arg = cur.selectionAsString(false);
1538 if (arg.size() > 100 || arg.empty()) {
1539 // Get word or selection
1540 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1541 arg = cur.selectionAsString(false);
1544 bv->showDialogWithData("thesaurus", to_utf8(arg));
1548 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1549 // Given data, an encoding of the ParagraphParameters
1550 // generated in the Paragraph dialog, this function sets
1551 // the current paragraph appropriately.
1552 istringstream is(to_utf8(cmd.argument()));
1555 ParagraphParameters params;
1560 params.labelWidthString(),
1562 cur.message(_("Paragraph layout set"));
1567 if (cur.selection()) {
1568 cur.selection() = false;
1571 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1576 LYXERR(Debug::ACTION)
1577 << BOOST_CURRENT_FUNCTION
1578 << ": Command " << cmd
1579 << " not DISPATCHED by Text" << endl;
1584 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1586 // FIXME: The cursor flag is reset two lines below
1587 // so we need to check here if some of the LFUN did touch that.
1588 // for now only Text::erase() and Text::backspace() do that.
1589 // The plan is to verify all the LFUNs and then to remove this
1590 // singleParUpdate boolean altogether.
1591 if (cur.result().update() & Update::Force) {
1592 singleParUpdate = false;
1596 // FIXME: the following code should go in favor of fine grained
1597 // update flag treatment.
1598 if (singleParUpdate) {
1599 // Inserting characters does not change par height
1600 ParagraphMetrics const & pms
1601 = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
1602 if (pms.dim().height()
1603 == olddim.height()) {
1604 // if so, update _only_ this paragraph
1605 cur.updateFlags(Update::SinglePar |
1607 Update::MultiParSel);
1614 && &oldTopSlice.inset() == &cur.inset()
1615 && oldTopSlice.idx() == cur.idx()
1616 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1617 && !cur.selection())
1618 // FIXME: it would be better if we could just do this
1620 //if (cur.result().update() != Update::FitCursor)
1623 // But some LFUNs do not set Update::FitCursor when needed, so we
1624 // do it for all. This is not very harmfull as FitCursor will provoke
1625 // a full redraw only if needed but still, a proper review of all LFUN
1626 // should be done and this needsUpdate boolean can then be removed.
1627 cur.updateFlags(Update::FitCursor);
1629 cur.updateFlags(Update::Force | Update::FitCursor);
1633 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
1634 FuncStatus & flag) const
1636 BOOST_ASSERT(cur.text() == this);
1638 Font const & font = real_current_font;
1640 Inset::Code code = Inset::NO_CODE;
1642 switch (cmd.action) {
1644 case LFUN_DEPTH_DECREMENT:
1645 enable = changeDepthAllowed(cur, DEC_DEPTH);
1648 case LFUN_DEPTH_INCREMENT:
1649 enable = changeDepthAllowed(cur, INC_DEPTH);
1653 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1656 case LFUN_BIBITEM_INSERT:
1657 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO
1661 case LFUN_DIALOG_SHOW_NEW_INSET:
1662 if (cmd.argument() == "bibitem")
1663 code = Inset::BIBITEM_CODE;
1664 else if (cmd.argument() == "bibtex")
1665 code = Inset::BIBTEX_CODE;
1666 else if (cmd.argument() == "box")
1667 code = Inset::BOX_CODE;
1668 else if (cmd.argument() == "branch")
1669 code = Inset::BRANCH_CODE;
1670 else if (cmd.argument() == "citation")
1671 code = Inset::CITE_CODE;
1672 else if (cmd.argument() == "ert")
1673 code = Inset::ERT_CODE;
1674 else if (cmd.argument() == "external")
1675 code = Inset::EXTERNAL_CODE;
1676 else if (cmd.argument() == "float")
1677 code = Inset::FLOAT_CODE;
1678 else if (cmd.argument() == "graphics")
1679 code = Inset::GRAPHICS_CODE;
1680 else if (cmd.argument() == "include")
1681 code = Inset::INCLUDE_CODE;
1682 else if (cmd.argument() == "index")
1683 code = Inset::INDEX_CODE;
1684 else if (cmd.argument() == "nomenclature")
1685 code = Inset::NOMENCL_CODE;
1686 else if (cmd.argument() == "label")
1687 code = Inset::LABEL_CODE;
1688 else if (cmd.argument() == "note")
1689 code = Inset::NOTE_CODE;
1690 else if (cmd.argument() == "ref")
1691 code = Inset::REF_CODE;
1692 else if (cmd.argument() == "toc")
1693 code = Inset::TOC_CODE;
1694 else if (cmd.argument() == "url")
1695 code = Inset::URL_CODE;
1696 else if (cmd.argument() == "vspace")
1697 code = Inset::VSPACE_CODE;
1698 else if (cmd.argument() == "wrap")
1699 code = Inset::WRAP_CODE;
1700 else if (cmd.argument() == "listings")
1701 code = Inset::LISTINGS_CODE;
1704 case LFUN_ERT_INSERT:
1705 code = Inset::ERT_CODE;
1707 case LFUN_LISTING_INSERT:
1708 code = Inset::LISTINGS_CODE;
1710 case LFUN_FOOTNOTE_INSERT:
1711 code = Inset::FOOT_CODE;
1713 case LFUN_TABULAR_INSERT:
1714 code = Inset::TABULAR_CODE;
1716 case LFUN_MARGINALNOTE_INSERT:
1717 code = Inset::MARGIN_CODE;
1719 case LFUN_FLOAT_INSERT:
1720 case LFUN_FLOAT_WIDE_INSERT:
1721 code = Inset::FLOAT_CODE;
1723 case LFUN_WRAP_INSERT:
1724 code = Inset::WRAP_CODE;
1726 case LFUN_FLOAT_LIST:
1727 code = Inset::FLOAT_LIST_CODE;
1730 case LFUN_LIST_INSERT:
1731 code = Inset::LIST_CODE;
1733 case LFUN_THEOREM_INSERT:
1734 code = Inset::THEOREM_CODE;
1737 case LFUN_CAPTION_INSERT:
1738 code = Inset::CAPTION_CODE;
1740 case LFUN_NOTE_INSERT:
1741 code = Inset::NOTE_CODE;
1743 case LFUN_CHARSTYLE_INSERT:
1744 code = Inset::CHARSTYLE_CODE;
1745 if (cur.buffer().params().getTextClass().charstyles().empty())
1748 case LFUN_BOX_INSERT:
1749 code = Inset::BOX_CODE;
1751 case LFUN_BRANCH_INSERT:
1752 code = Inset::BRANCH_CODE;
1753 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1756 case LFUN_LABEL_INSERT:
1757 code = Inset::LABEL_CODE;
1759 case LFUN_OPTIONAL_INSERT:
1760 code = Inset::OPTARG_CODE;
1761 enable = numberOfOptArgs(cur.paragraph())
1762 < cur.paragraph().layout()->optionalargs;
1764 case LFUN_ENVIRONMENT_INSERT:
1765 code = Inset::BOX_CODE;
1767 case LFUN_INDEX_INSERT:
1768 code = Inset::INDEX_CODE;
1770 case LFUN_INDEX_PRINT:
1771 code = Inset::INDEX_PRINT_CODE;
1773 case LFUN_NOMENCL_INSERT:
1774 code = Inset::NOMENCL_CODE;
1776 case LFUN_NOMENCL_PRINT:
1777 code = Inset::NOMENCL_PRINT_CODE;
1779 case LFUN_TOC_INSERT:
1780 code = Inset::TOC_CODE;
1782 case LFUN_HTML_INSERT:
1783 case LFUN_URL_INSERT:
1784 code = Inset::URL_CODE;
1786 case LFUN_QUOTE_INSERT:
1787 // always allow this, since we will inset a raw quote
1788 // if an inset is not allowed.
1790 case LFUN_HYPHENATION_POINT_INSERT:
1791 case LFUN_LIGATURE_BREAK_INSERT:
1792 case LFUN_HFILL_INSERT:
1793 case LFUN_MENU_SEPARATOR_INSERT:
1794 case LFUN_DOTS_INSERT:
1795 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
1796 code = Inset::SPECIALCHAR_CODE;
1798 case LFUN_SPACE_INSERT:
1799 // slight hack: we know this is allowed in math mode
1801 code = Inset::SPACE_CODE;
1804 case LFUN_INSET_MODIFY:
1805 // We need to disable this, because we may get called for a
1807 // InsetTabular::getStatus() -> InsetText::getStatus()
1808 // and we don't handle LFUN_INSET_MODIFY.
1812 case LFUN_FONT_EMPH:
1813 flag.setOnOff(font.emph() == Font::ON);
1816 case LFUN_FONT_NOUN:
1817 flag.setOnOff(font.noun() == Font::ON);
1820 case LFUN_FONT_BOLD:
1821 flag.setOnOff(font.series() == Font::BOLD_SERIES);
1824 case LFUN_FONT_SANS:
1825 flag.setOnOff(font.family() == Font::SANS_FAMILY);
1828 case LFUN_FONT_ROMAN:
1829 flag.setOnOff(font.family() == Font::ROMAN_FAMILY);
1832 case LFUN_FONT_CODE:
1833 flag.setOnOff(font.family() == Font::TYPEWRITER_FAMILY);
1838 enable = cur.selection();
1842 if (cmd.argument().empty()) {
1843 if (theClipboard().isInternal())
1844 enable = cap::numberOfSelections() > 0;
1846 enable = !theClipboard().empty();
1848 string const arg = to_utf8(cmd.argument());
1849 if (isStrUnsignedInt(arg)) {
1850 unsigned int n = convert<unsigned int>(arg);
1851 enable = cap::numberOfSelections() > n;
1858 case LFUN_CLIPBOARD_PASTE:
1859 enable = !theClipboard().empty();
1862 case LFUN_PRIMARY_SELECTION_PASTE:
1863 enable = cur.selection() || !theSelection().empty();
1866 case LFUN_PARAGRAPH_MOVE_UP:
1867 enable = cur.pit() > 0 && !cur.selection();
1870 case LFUN_PARAGRAPH_MOVE_DOWN:
1871 enable = cur.pit() < cur.lastpit() && !cur.selection();
1874 case LFUN_INSET_DISSOLVE:
1875 enable = !isMainText(*cur.bv().buffer()) && cur.inset().nargs() == 1;
1878 case LFUN_CHANGE_ACCEPT:
1879 case LFUN_CHANGE_REJECT:
1880 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
1881 // In principle, these LFUNs should only be enabled if there
1882 // is a change at the current position/in the current selection.
1883 // However, without proper optimizations, this will inevitably
1884 // result in unacceptable performance - just imagine a user who
1885 // wants to select the complete content of a long document.
1889 case LFUN_WORD_DELETE_FORWARD:
1890 case LFUN_WORD_DELETE_BACKWARD:
1891 case LFUN_LINE_DELETE:
1892 case LFUN_WORD_FORWARD:
1893 case LFUN_WORD_BACKWARD:
1894 case LFUN_CHAR_FORWARD:
1895 case LFUN_CHAR_FORWARD_SELECT:
1896 case LFUN_CHAR_BACKWARD:
1897 case LFUN_CHAR_BACKWARD_SELECT:
1899 case LFUN_UP_SELECT:
1901 case LFUN_DOWN_SELECT:
1902 case LFUN_PARAGRAPH_UP_SELECT:
1903 case LFUN_PARAGRAPH_DOWN_SELECT:
1904 case LFUN_SCREEN_UP_SELECT:
1905 case LFUN_SCREEN_DOWN_SELECT:
1906 case LFUN_LINE_BEGIN_SELECT:
1907 case LFUN_LINE_END_SELECT:
1908 case LFUN_WORD_FORWARD_SELECT:
1909 case LFUN_WORD_BACKWARD_SELECT:
1910 case LFUN_WORD_SELECT:
1911 case LFUN_PARAGRAPH_UP:
1912 case LFUN_PARAGRAPH_DOWN:
1913 case LFUN_SCREEN_UP:
1914 case LFUN_SCREEN_DOWN:
1915 case LFUN_LINE_BEGIN:
1917 case LFUN_BREAK_LINE:
1918 case LFUN_CHAR_DELETE_FORWARD:
1919 case LFUN_DELETE_FORWARD_SKIP:
1920 case LFUN_CHAR_DELETE_BACKWARD:
1921 case LFUN_DELETE_BACKWARD_SKIP:
1922 case LFUN_BREAK_PARAGRAPH:
1923 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
1924 case LFUN_BREAK_PARAGRAPH_SKIP:
1925 case LFUN_PARAGRAPH_SPACING:
1926 case LFUN_INSET_INSERT:
1927 case LFUN_WORD_UPCASE:
1928 case LFUN_WORD_LOWCASE:
1929 case LFUN_WORD_CAPITALIZE:
1930 case LFUN_CHARS_TRANSPOSE:
1931 case LFUN_SERVER_GET_XY:
1932 case LFUN_SERVER_SET_XY:
1933 case LFUN_SERVER_GET_FONT:
1934 case LFUN_SERVER_GET_LAYOUT:
1936 case LFUN_DATE_INSERT:
1937 case LFUN_SELF_INSERT:
1938 case LFUN_LINE_INSERT:
1939 case LFUN_PAGEBREAK_INSERT:
1940 case LFUN_CLEARPAGE_INSERT:
1941 case LFUN_CLEARDOUBLEPAGE_INSERT:
1942 case LFUN_MATH_DISPLAY:
1943 case LFUN_MATH_IMPORT_SELECTION:
1944 case LFUN_MATH_MODE:
1945 case LFUN_MATH_MACRO:
1946 case LFUN_MATH_MATRIX:
1947 case LFUN_MATH_DELIM:
1948 case LFUN_MATH_BIGDELIM:
1949 case LFUN_MATH_INSERT:
1950 case LFUN_MATH_SUBSCRIPT:
1951 case LFUN_MATH_SUPERSCRIPT:
1952 case LFUN_FONT_DEFAULT:
1953 case LFUN_FONT_UNDERLINE:
1954 case LFUN_FONT_SIZE:
1956 case LFUN_FONT_FREE_APPLY:
1957 case LFUN_FONT_FREE_UPDATE:
1958 case LFUN_LAYOUT_PARAGRAPH:
1959 case LFUN_PARAGRAPH_UPDATE:
1960 case LFUN_ACCENT_UMLAUT:
1961 case LFUN_ACCENT_CIRCUMFLEX:
1962 case LFUN_ACCENT_GRAVE:
1963 case LFUN_ACCENT_ACUTE:
1964 case LFUN_ACCENT_TILDE:
1965 case LFUN_ACCENT_CEDILLA:
1966 case LFUN_ACCENT_MACRON:
1967 case LFUN_ACCENT_DOT:
1968 case LFUN_ACCENT_UNDERDOT:
1969 case LFUN_ACCENT_UNDERBAR:
1970 case LFUN_ACCENT_CARON:
1971 case LFUN_ACCENT_SPECIAL_CARON:
1972 case LFUN_ACCENT_BREVE:
1973 case LFUN_ACCENT_TIE:
1974 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1975 case LFUN_ACCENT_CIRCLE:
1976 case LFUN_ACCENT_OGONEK:
1977 case LFUN_THESAURUS_ENTRY:
1978 case LFUN_PARAGRAPH_PARAMS_APPLY:
1980 case LFUN_BUFFER_END:
1981 case LFUN_BUFFER_BEGIN:
1982 case LFUN_BUFFER_BEGIN_SELECT:
1983 case LFUN_BUFFER_END_SELECT:
1984 case LFUN_UNICODE_INSERT:
1985 // these are handled in our dispatch()
1993 if (code != Inset::NO_CODE
1994 && (cur.empty() || !cur.inset().insetAllowed(code)))
1997 flag.enabled(enable);
2002 void Text::pasteString(Cursor & cur, docstring const & clip,
2005 cur.clearSelection();
2006 if (!clip.empty()) {
2009 insertStringAsParagraphs(cur, clip);
2011 insertStringAsLines(cur, clip);