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())
123 cur.bv().switchKeyMap();
127 void finishChange(Cursor & cur, bool selecting)
130 moveCursor(cur, selecting);
134 void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
137 docstring sel = cur.selectionAsString(false);
139 // It may happen that sel is empty but there is a selection
140 replaceSelection(cur);
143 #ifdef ENABLE_ASSERTIONS
144 const int old_pos = cur.pos();
146 cur.insert(new InsetMathHull(hullSimple));
147 BOOST_ASSERT(old_pos == cur.pos());
148 cur.nextInset()->edit(cur, true);
149 // don't do that also for LFUN_MATH_MODE
150 // unless you want end up with always changing
151 // to mathrm when opening an inlined inset --
152 // I really hate "LyXfunc overloading"...
154 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
155 // Avoid an unnecessary undo step if cmd.argument
157 if (!cmd.argument().empty())
158 cur.dispatch(FuncRequest(LFUN_MATH_INSERT,
161 // create a macro if we see "\\newcommand"
162 // somewhere, and an ordinary formula
164 if (sel.find(from_ascii("\\newcommand")) == string::npos
165 && sel.find(from_ascii("\\def")) == string::npos)
167 InsetMathHull * formula = new InsetMathHull;
168 istringstream is(to_utf8(sel));
171 formula->read(cur.buffer(), lex);
172 if (formula->getType() == hullNone)
173 // Don't create pseudo formulas if
174 // delimiters are left out
175 formula->mutate(hullSimple);
178 cur.insert(new MathMacroTemplate(sel));
181 cur.message(from_utf8(N_("Math editor mode")));
190 string const freefont2string()
193 if (font2string(freefont, toggleall, data))
200 void Text::cursorPrevious(Cursor & cur)
202 pos_type cpos = cur.pos();
203 pit_type cpar = cur.pit();
205 int x = cur.x_target();
206 setCursorFromCoordinates(cur, x, 0);
207 cur.dispatch(FuncRequest(cur.selection()? LFUN_UP_SELECT: LFUN_UP));
209 if (cpar == cur.pit() && cpos == cur.pos())
210 // we have a row which is taller than the workarea. The
211 // simplest solution is to move to the previous row instead.
212 cur.dispatch(FuncRequest(cur.selection()? LFUN_UP_SELECT: LFUN_UP));
215 cur.updateFlags(Update::Force | Update::FitCursor);
219 void Text::cursorNext(Cursor & cur)
221 pos_type cpos = cur.pos();
222 pit_type cpar = cur.pit();
224 int x = cur.x_target();
225 setCursorFromCoordinates(cur, x, cur.bv().workHeight() - 1);
226 cur.dispatch(FuncRequest(cur.selection()? LFUN_DOWN_SELECT: LFUN_DOWN));
228 if (cpar == cur.pit() && cpos == cur.pos())
229 // we have a row which is taller than the workarea. The
230 // simplest solution is to move to the next row instead.
232 FuncRequest(cur.selection()? LFUN_DOWN_SELECT: LFUN_DOWN));
235 cur.updateFlags(Update::Force | Update::FitCursor);
241 void specialChar(Cursor & cur, InsetSpecialChar::Kind kind)
244 cap::replaceSelection(cur);
245 cur.insert(new InsetSpecialChar(kind));
250 bool doInsertInset(Cursor & cur, Text * text,
251 FuncRequest const & cmd, bool edit, bool pastesel)
253 Inset * inset = createInset(&cur.bv(), cmd);
259 if (cur.selection()) {
260 lyx::dispatch(FuncRequest(LFUN_CUT));
263 text->insertInset(cur, inset);
266 inset->edit(cur, true);
268 if (gotsel && pastesel) {
269 lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
270 // reset first par to default
271 if (cur.lastpit() != 0 || cur.lastpos() != 0) {
272 Layout_ptr const layout =
273 cur.buffer().params().getTextClass().defaultLayout();
274 cur.text()->paragraphs().begin()->layout(layout);
284 void Text::number(Cursor & cur)
286 Font font(Font::ALL_IGNORE);
287 font.setNumber(Font::TOGGLE);
288 toggleAndShow(cur, this, font);
292 bool Text::isRTL(Buffer const & buffer, Paragraph const & par) const
294 return par.isRightToLeftPar(buffer.params());
298 bool Text::isRTL(Buffer const & buffer, CursorSlice const & sl, bool boundary) const
300 if (!lyxrc.rtl_support && !sl.text())
304 if (boundary && sl.pos() > 0)
307 Paragraph const & par = getPar(sl.pit());
308 return getFont(buffer, par, sl.pos() + correction).isVisibleRightToLeft();
312 bool Text::isRTLBoundary(Buffer const & buffer, Paragraph const & par,
315 if (!lyxrc.rtl_support)
318 // no RTL boundary at line start
322 bool left = getFont(buffer, par, pos - 1).isVisibleRightToLeft();
324 if (pos == par.size())
325 right = par.isRightToLeftPar(buffer.params());
327 right = getFont(buffer, par, pos).isVisibleRightToLeft();
328 return left != right;
332 bool Text::isRTLBoundary(Buffer const & buffer, Paragraph const & par,
333 pos_type pos, Font const & font) const
335 if (!lyxrc.rtl_support)
338 bool left = font.isVisibleRightToLeft();
340 if (pos == par.size())
341 right = par.isRightToLeftPar(buffer.params());
343 right = getFont(buffer, par, pos).isVisibleRightToLeft();
344 return left != right;
348 void Text::dispatch(Cursor & cur, FuncRequest & cmd)
350 LYXERR(Debug::ACTION) << "Text::dispatch: cmd: " << cmd << endl;
352 // FIXME: We use the update flag to indicates wether a singlePar or a
353 // full screen update is needed. We reset it here but shall we restore it
357 BOOST_ASSERT(cur.text() == this);
358 BufferView * bv = &cur.bv();
359 CursorSlice oldTopSlice = cur.top();
360 bool oldBoundary = cur.boundary();
361 bool sel = cur.selection();
362 // Signals that, even if needsUpdate == false, an update of the
363 // cursor paragraph is required
364 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
365 LyXAction::SingleParUpdate);
366 // Signals that a full-screen update is required
367 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
368 LyXAction::NoUpdate) || singleParUpdate);
369 // Remember the old paragraph metric (_outer_ paragraph!)
370 ParagraphMetrics const & pm = cur.bv().parMetrics(
371 cur.bottom().text(), cur.bottom().pit());
372 Dimension olddim = pm.dim();
374 switch (cmd.action) {
376 case LFUN_PARAGRAPH_MOVE_DOWN: {
377 pit_type const pit = cur.pit();
378 recUndo(cur, pit, pit + 1);
380 std::swap(pars_[pit], pars_[pit + 1]);
382 ParIterator begin(cur);
383 // begin.pos() (== cur.pos()) may point beyond the end of the
384 // paragraph referenced by begin. This would cause a crash
388 ParIterator end = boost::next(ParIterator(cur));
389 updateLabels(cur.buffer(), begin, end);
395 case LFUN_PARAGRAPH_MOVE_UP: {
396 pit_type const pit = cur.pit();
397 recUndo(cur, pit - 1, pit);
399 std::swap(pars_[pit], pars_[pit - 1]);
401 ParIterator end = ParIterator(cur);
402 // end.pos() (== cur.pos()) may point beyond the end of the
403 // paragraph referenced by end. This would cause a crash
406 end = boost::next(end);
408 ParIterator begin(cur);
409 updateLabels(cur.buffer(), begin, end);
415 case LFUN_APPENDIX: {
416 Paragraph & par = cur.paragraph();
417 bool start = !par.params().startOfAppendix();
420 #warning The code below only makes sense at top level.
421 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
423 // ensure that we have only one start_of_appendix in this document
424 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
425 if (pars_[tmp].params().startOfAppendix()) {
427 pars_[tmp].params().startOfAppendix(false);
433 par.params().startOfAppendix(start);
435 // we can set the refreshing parameters now
436 updateLabels(cur.buffer());
440 case LFUN_WORD_DELETE_FORWARD:
441 cur.clearSelection();
442 deleteWordForward(cur);
443 finishChange(cur, false);
446 case LFUN_WORD_DELETE_BACKWARD:
447 cur.clearSelection();
448 deleteWordBackward(cur);
449 finishChange(cur, false);
452 case LFUN_LINE_DELETE:
453 cur.clearSelection();
454 deleteLineForward(cur);
455 finishChange(cur, false);
458 case LFUN_BUFFER_BEGIN:
459 case LFUN_BUFFER_BEGIN_SELECT:
460 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
461 if (cur.depth() == 1) {
462 needsUpdate |= cursorTop(cur);
468 case LFUN_BUFFER_END:
469 case LFUN_BUFFER_END_SELECT:
470 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
471 if (cur.depth() == 1) {
472 needsUpdate |= cursorBottom(cur);
478 case LFUN_CHAR_FORWARD:
479 case LFUN_CHAR_FORWARD_SELECT:
480 //lyxerr << BOOST_CURRENT_FUNCTION
481 // << " LFUN_CHAR_FORWARD[SEL]:\n" << cur << endl;
482 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
483 if (reverseDirectionNeeded(cur))
484 needsUpdate |= cursorLeft(cur);
486 needsUpdate |= cursorRight(cur);
488 if (!needsUpdate && oldTopSlice == cur.top()
489 && cur.boundary() == oldBoundary) {
491 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
492 } else if (cur.selection())
496 case LFUN_CHAR_BACKWARD:
497 case LFUN_CHAR_BACKWARD_SELECT:
498 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
499 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
500 if (reverseDirectionNeeded(cur))
501 needsUpdate |= cursorRight(cur);
503 needsUpdate |= cursorLeft(cur);
505 if (!needsUpdate && oldTopSlice == cur.top()
506 && cur.boundary() == oldBoundary) {
508 cmd = FuncRequest(LFUN_FINISHED_LEFT);
515 case LFUN_UP_SELECT: {
516 //lyxerr << "handle LFUN_UP[SEL]:\n" << cur << endl;
517 needsUpdate |= cur.selHandle(cmd.action == LFUN_UP_SELECT);
518 bool const successful = cur.upDownInText(true, needsUpdate);
527 case LFUN_DOWN_SELECT: {
528 //lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
529 needsUpdate |= cur.selHandle(cmd.action == LFUN_DOWN_SELECT);
530 bool const successful = cur.upDownInText(false, needsUpdate);
538 case LFUN_PARAGRAPH_UP:
539 case LFUN_PARAGRAPH_UP_SELECT:
540 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
541 needsUpdate |= cursorUpParagraph(cur);
546 case LFUN_PARAGRAPH_DOWN:
547 case LFUN_PARAGRAPH_DOWN_SELECT:
548 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
549 needsUpdate |= cursorDownParagraph(cur);
555 case LFUN_SCREEN_UP_SELECT:
556 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_UP_SELECT);
557 if (cur.pit() == 0 && cur.textRow().pos() == 0)
566 case LFUN_SCREEN_DOWN:
567 case LFUN_SCREEN_DOWN_SELECT:
568 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_DOWN_SELECT);
569 if (cur.pit() == cur.lastpit()
570 && cur.textRow().endpos() == cur.lastpos())
579 case LFUN_LINE_BEGIN:
580 case LFUN_LINE_BEGIN_SELECT:
581 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
582 needsUpdate |= cursorHome(cur);
586 case LFUN_LINE_END_SELECT:
587 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
588 needsUpdate |= cursorEnd(cur);
593 case LFUN_WORD_FORWARD:
594 case LFUN_WORD_FORWARD_SELECT:
595 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
596 if (reverseDirectionNeeded(cur))
597 needsUpdate |= cursorLeftOneWord(cur);
599 needsUpdate |= cursorRightOneWord(cur);
604 case LFUN_WORD_BACKWARD:
605 case LFUN_WORD_BACKWARD_SELECT:
606 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
607 if (reverseDirectionNeeded(cur))
608 needsUpdate |= cursorRightOneWord(cur);
610 needsUpdate |= cursorLeftOneWord(cur);
615 case LFUN_WORD_SELECT: {
616 selectWord(cur, WHOLE_WORD);
617 finishChange(cur, true);
621 case LFUN_BREAK_LINE: {
622 // Not allowed by LaTeX (labels or empty par)
623 if (cur.pos() > cur.paragraph().beginOfBody()) {
624 // this avoids a double undo
625 // FIXME: should not be needed, ideally
626 if (!cur.selection())
628 cap::replaceSelection(cur);
629 cur.insert(new InsetNewline);
631 moveCursor(cur, false);
636 case LFUN_CHAR_DELETE_FORWARD:
637 if (!cur.selection()) {
638 if (cur.pos() == cur.paragraph().size())
639 // Par boundary, force full-screen update
640 singleParUpdate = false;
641 needsUpdate |= erase(cur);
643 // It is possible to make it a lot faster still
644 // just comment out the line below...
646 cutSelection(cur, true, false);
647 singleParUpdate = false;
649 moveCursor(cur, false);
652 case LFUN_DELETE_FORWARD_SKIP:
653 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
654 if (!cur.selection()) {
655 if (cur.pos() == cur.lastpos()) {
662 cutSelection(cur, true, false);
667 case LFUN_CHAR_DELETE_BACKWARD:
668 if (!cur.selection()) {
669 if (bv->getIntl().getTransManager().backspace()) {
670 // Par boundary, full-screen update
672 singleParUpdate = false;
673 needsUpdate |= backspace(cur);
675 // It is possible to make it a lot faster still
676 // just comment out the line below...
679 cutSelection(cur, true, false);
680 singleParUpdate = false;
685 case LFUN_DELETE_BACKWARD_SKIP:
686 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
687 if (!cur.selection()) {
691 //CursorSlice cur = cursor();
695 cutSelection(cur, true, false);
699 case LFUN_BREAK_PARAGRAPH:
700 cap::replaceSelection(cur);
701 breakParagraph(cur, 0);
706 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
707 cap::replaceSelection(cur);
708 breakParagraph(cur, 1);
713 case LFUN_BREAK_PARAGRAPH_SKIP: {
714 // When at the beginning of a paragraph, remove
715 // indentation. Otherwise, do the same as LFUN_BREAK_PARAGRAPH.
716 cap::replaceSelection(cur);
718 cur.paragraph().params().labelWidthString(docstring());
720 breakParagraph(cur, 0);
726 case LFUN_PARAGRAPH_SPACING: {
727 Paragraph & par = cur.paragraph();
728 Spacing::Space cur_spacing = par.params().spacing().getSpace();
729 string cur_value = "1.0";
730 if (cur_spacing == Spacing::Other)
731 cur_value = par.params().spacing().getValueAsString();
733 istringstream is(to_utf8(cmd.argument()));
736 Spacing::Space new_spacing = cur_spacing;
737 string new_value = cur_value;
739 lyxerr << "Missing argument to `paragraph-spacing'"
741 } else if (tmp == "single") {
742 new_spacing = Spacing::Single;
743 } else if (tmp == "onehalf") {
744 new_spacing = Spacing::Onehalf;
745 } else if (tmp == "double") {
746 new_spacing = Spacing::Double;
747 } else if (tmp == "other") {
748 new_spacing = Spacing::Other;
749 string tmpval = "0.0";
751 lyxerr << "new_value = " << tmpval << endl;
754 } else if (tmp == "default") {
755 new_spacing = Spacing::Default;
757 lyxerr << to_utf8(_("Unknown spacing argument: "))
758 << to_utf8(cmd.argument()) << endl;
760 if (cur_spacing != new_spacing || cur_value != new_value)
761 par.params().spacing(Spacing(new_spacing, new_value));
765 case LFUN_INSET_INSERT: {
767 Inset * inset = createInset(bv, cmd);
769 // FIXME (Abdel 01/02/2006):
770 // What follows would be a partial fix for bug 2154:
771 // http://bugzilla.lyx.org/show_bug.cgi?id=2154
772 // This automatically put the label inset _after_ a
773 // numbered section. It should be possible to extend the mechanism
774 // to any kind of LateX environement.
775 // The correct way to fix that bug would be at LateX generation.
776 // I'll let the code here for reference as it could be used for some
777 // other feature like "automatic labelling".
779 Paragraph & par = pars_[cur.pit()];
780 if (inset->lyxCode() == Inset::LABEL_CODE
781 && par.layout()->labeltype == LABEL_COUNTER) {
782 // Go to the end of the paragraph
783 // Warning: Because of Change-Tracking, the last
784 // position is 'size()' and not 'size()-1':
785 cur.pos() = par.size();
786 // Insert a new paragraph
787 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
791 insertInset(cur, inset);
797 case LFUN_INSET_DISSOLVE:
798 needsUpdate |= dissolveInset(cur);
801 case LFUN_INSET_SETTINGS:
802 cur.inset().showInsetDialog(bv);
805 case LFUN_SPACE_INSERT:
806 if (cur.paragraph().layout()->free_spacing)
807 insertChar(cur, ' ');
809 doInsertInset(cur, this, cmd, false, false);
812 moveCursor(cur, false);
815 case LFUN_HYPHENATION_POINT_INSERT:
816 specialChar(cur, InsetSpecialChar::HYPHENATION);
819 case LFUN_LIGATURE_BREAK_INSERT:
820 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
823 case LFUN_DOTS_INSERT:
824 specialChar(cur, InsetSpecialChar::LDOTS);
827 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
828 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
831 case LFUN_MENU_SEPARATOR_INSERT:
832 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
835 case LFUN_WORD_UPCASE:
836 changeCase(cur, Text::text_uppercase);
839 case LFUN_WORD_LOWCASE:
840 changeCase(cur, Text::text_lowercase);
843 case LFUN_WORD_CAPITALIZE:
844 changeCase(cur, Text::text_capitalization);
847 case LFUN_CHARS_TRANSPOSE:
852 cur.message(_("Paste"));
853 cap::replaceSelection(cur);
854 if (cmd.argument().empty() && !theClipboard().isInternal())
855 pasteClipboard(cur, bv->buffer()->errorList("Paste"));
857 string const arg(to_utf8(cmd.argument()));
858 pasteFromStack(cur, bv->buffer()->errorList("Paste"),
859 isStrUnsignedInt(arg) ?
860 convert<unsigned int>(arg) :
863 bv->buffer()->errors("Paste");
864 cur.clearSelection(); // bug 393
870 cutSelection(cur, true, true);
871 cur.message(_("Cut"));
876 cur.message(_("Copy"));
879 case LFUN_SERVER_GET_XY:
880 cur.message(from_utf8(
881 convert<string>(cursorX(cur.bv(), cur.top(), cur.boundary()))
882 + ' ' + convert<string>(cursorY(cur.bv(), cur.top(), cur.boundary()))));
885 case LFUN_SERVER_SET_XY: {
888 istringstream is(to_utf8(cmd.argument()));
891 lyxerr << "SETXY: Could not parse coordinates in '"
892 << to_utf8(cmd.argument()) << std::endl;
894 setCursorFromCoordinates(cur, x, y);
898 case LFUN_SERVER_GET_FONT:
899 if (current_font.shape() == Font::ITALIC_SHAPE)
900 cur.message(from_ascii("E"));
901 else if (current_font.shape() == Font::SMALLCAPS_SHAPE)
902 cur.message(from_ascii("N"));
904 cur.message(from_ascii("0"));
907 case LFUN_SERVER_GET_LAYOUT:
908 cur.message(from_utf8(cur.paragraph().layout()->name()));
912 string layout = to_ascii(cmd.argument());
913 LYXERR(Debug::INFO) << "LFUN_LAYOUT: (arg) " << layout << endl;
915 // Derive layout number from given argument (string)
916 // and current buffer's textclass (number)
917 TextClass const & tclass = bv->buffer()->params().getTextClass();
919 layout = tclass.defaultLayoutName();
920 bool hasLayout = tclass.hasLayout(layout);
922 // If the entry is obsolete, use the new one instead.
924 string const & obs = tclass[layout]->obsoleted_by();
930 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
931 from_utf8(N_(" not known")));
935 bool change_layout = (current_layout != layout);
937 if (!change_layout && cur.selection() &&
938 cur.selBegin().pit() != cur.selEnd().pit())
940 pit_type spit = cur.selBegin().pit();
941 pit_type epit = cur.selEnd().pit() + 1;
942 while (spit != epit) {
943 if (pars_[spit].layout()->name() != current_layout) {
944 change_layout = true;
952 current_layout = layout;
953 setLayout(cur, layout);
954 // inform the GUI that the layout has changed.
955 bv->layoutChanged(layout);
961 case LFUN_CLIPBOARD_PASTE:
962 cur.clearSelection();
963 pasteClipboard(cur, bv->buffer()->errorList("Paste"),
964 cmd.argument() == "paragraph");
965 bv->buffer()->errors("Paste");
968 case LFUN_PRIMARY_SELECTION_PASTE:
969 pasteString(cur, theSelection().get(),
970 cmd.argument() == "paragraph");
973 case LFUN_UNICODE_INSERT: {
974 if (cmd.argument().empty())
976 docstring hexstring = cmd.argument();
977 if (lyx::support::isHex(hexstring)) {
978 char_type c = lyx::support::hexToInt(hexstring);
979 if (c > 32 && c < 0x10ffff) {
980 lyxerr << "Inserting c: " << c << endl;
981 docstring s = docstring(1, c);
982 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
988 case LFUN_QUOTE_INSERT: {
989 Paragraph & par = cur.paragraph();
990 pos_type pos = cur.pos();
991 BufferParams const & bufparams = bv->buffer()->params();
992 Layout_ptr const & style = par.layout();
993 if (!style->pass_thru
994 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
995 // this avoids a double undo
996 // FIXME: should not be needed, ideally
997 if (!cur.selection())
999 cap::replaceSelection(cur);
1004 else if (cur.prevInset() && cur.prevInset()->isSpace())
1007 c = par.getChar(pos - 1);
1008 string arg = to_utf8(cmd.argument());
1009 if (arg == "single")
1010 cur.insert(new InsetQuotes(c,
1011 bufparams.quotes_language,
1012 InsetQuotes::SingleQ));
1014 cur.insert(new InsetQuotes(c,
1015 bufparams.quotes_language,
1016 InsetQuotes::DoubleQ));
1020 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
1024 case LFUN_DATE_INSERT:
1025 if (cmd.argument().empty())
1026 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
1027 formatted_time(current_time())));
1029 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
1030 formatted_time(current_time(), to_utf8(cmd.argument()))));
1033 case LFUN_MOUSE_TRIPLE:
1034 if (cmd.button() == mouse_button::button1) {
1044 case LFUN_MOUSE_DOUBLE:
1045 if (cmd.button() == mouse_button::button1) {
1046 selectWord(cur, WHOLE_WORD_STRICT);
1051 // Single-click on work area
1052 case LFUN_MOUSE_PRESS: {
1053 // Right click on a footnote flag opens float menu
1054 if (cmd.button() == mouse_button::button3)
1055 cur.clearSelection();
1057 // Middle button press pastes if we have a selection
1058 // We do this here as if the selection was inside an inset
1059 // it could get cleared on the unlocking of the inset so
1060 // we have to check this first
1061 bool paste_internally = false;
1062 if (cmd.button() == mouse_button::button2 && cap::selection()) {
1063 // Copy the selection buffer to the clipboard
1064 // stack, because we want it to appear in the
1065 // "Edit->Paste recent" menu.
1066 cap::copySelectionToStack();
1067 paste_internally = true;
1070 // Insert primary selection with middle mouse
1071 // if there is a local selection in the current buffer,
1073 if (cmd.button() == mouse_button::button2) {
1074 if (paste_internally) {
1075 cap::pasteSelection(cur, bv->buffer()->errorList("Paste"));
1076 bv->buffer()->errors("Paste");
1077 cur.clearSelection(); // bug 393
1079 bv->buffer()->markDirty();
1082 bv->mouseSetCursor(cur);
1083 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
1087 // we have to update after dePM triggered
1088 bool update = bv->mouseSetCursor(cur);
1090 if (!update && cmd.button() == mouse_button::button1) {
1091 needsUpdate = false;
1098 case LFUN_MOUSE_MOTION: {
1099 // Only use motion with button 1
1100 //if (cmd.button() != mouse_button::button1)
1103 // ignore motions deeper nested than the real anchor
1104 Cursor & bvcur = cur.bv().cursor();
1105 if (bvcur.anchor_.hasPart(cur)) {
1106 CursorSlice old = bvcur.top();
1108 int const wh = bv->workHeight();
1109 int const y = std::max(0, std::min(wh - 1, cmd.y));
1111 setCursorFromCoordinates(cur, cmd.x, y);
1112 cur.setTargetX(cmd.x);
1114 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1116 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1117 // This is to allow jumping over large insets
1118 if (cur.top() == old) {
1120 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1122 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1125 if (cur.top() == old)
1128 // don't set anchor_
1129 bvcur.setCursor(cur);
1130 bvcur.selection() = true;
1131 //lyxerr << "MOTION: " << bv->cursor() << endl;
1139 case LFUN_MOUSE_RELEASE: {
1140 if (cmd.button() == mouse_button::button2)
1143 if (cmd.button() == mouse_button::button1) {
1144 // if there is new selection, update persistent
1145 // selection, otherwise, single click does not
1146 // clear persistent selection buffer
1147 if (cur.selection()) {
1149 // if double click, cur is moved to the end of word by selectWord
1150 // but bvcur is current mouse position
1151 Cursor & bvcur = cur.bv().cursor();
1152 bvcur.selection() = true;
1153 saveSelection(bvcur);
1155 needsUpdate = false;
1163 case LFUN_SELF_INSERT: {
1164 if (cmd.argument().empty())
1167 // Automatically delete the currently selected
1168 // text and replace it with what is being
1169 // typed in now. Depends on lyxrc settings
1170 // "auto_region_delete", which defaults to
1173 if (lyxrc.auto_region_delete)
1174 if (cur.selection())
1175 cutSelection(cur, false, false);
1177 cur.clearSelection();
1178 Font const old_font = real_current_font;
1180 docstring::const_iterator cit = cmd.argument().begin();
1181 docstring::const_iterator end = cmd.argument().end();
1182 for (; cit != end; ++cit)
1183 bv->getIntl().getTransManager().
1184 translateAndInsert(*cit, this, cur);
1187 moveCursor(cur, false);
1191 case LFUN_URL_INSERT: {
1192 InsetCommandParams p("url");
1193 string const data = InsetCommandMailer::params2string("url", p);
1194 bv->showInsetDialog("url", data, 0);
1198 case LFUN_HTML_INSERT: {
1199 InsetCommandParams p("htmlurl");
1200 string const data = InsetCommandMailer::params2string("url", p);
1201 bv->showInsetDialog("url", data, 0);
1205 case LFUN_LABEL_INSERT: {
1206 InsetCommandParams p("label");
1207 // Try to generate a valid label
1208 p["name"] = (cmd.argument().empty()) ?
1209 cur.getPossibleLabel() :
1211 string const data = InsetCommandMailer::params2string("label", p);
1213 if (cmd.argument().empty()) {
1214 bv->showInsetDialog("label", data, 0);
1216 FuncRequest fr(LFUN_INSET_INSERT, data);
1224 case LFUN_LIST_INSERT:
1225 case LFUN_THEOREM_INSERT:
1227 case LFUN_CAPTION_INSERT:
1228 // Open the inset, and move the current selection
1230 doInsertInset(cur, this, cmd, true, true);
1232 updateLabels(*bv->buffer());
1234 case LFUN_NOTE_INSERT:
1235 case LFUN_CHARSTYLE_INSERT:
1236 case LFUN_BOX_INSERT:
1237 case LFUN_BRANCH_INSERT:
1238 case LFUN_BIBITEM_INSERT:
1239 case LFUN_ERT_INSERT:
1240 case LFUN_LISTING_INSERT:
1241 case LFUN_FOOTNOTE_INSERT:
1242 case LFUN_MARGINALNOTE_INSERT:
1243 case LFUN_OPTIONAL_INSERT:
1244 case LFUN_ENVIRONMENT_INSERT:
1245 // Open the inset, and move the current selection
1247 doInsertInset(cur, this, cmd, true, true);
1251 case LFUN_TABULAR_INSERT:
1252 // if there were no arguments, just open the dialog
1253 if (doInsertInset(cur, this, cmd, false, true))
1256 bv->showDialog("tabularcreate");
1260 case LFUN_FLOAT_INSERT:
1261 case LFUN_FLOAT_WIDE_INSERT:
1262 case LFUN_WRAP_INSERT: {
1263 bool content = cur.selection(); // will some text be moved into the inset?
1265 doInsertInset(cur, this, cmd, true, true);
1267 ParagraphList & pars = cur.text()->paragraphs();
1269 TextClass const & tclass = bv->buffer()->params().getTextClass();
1271 // add a separate paragraph for the caption inset
1272 pars.push_back(Paragraph());
1273 pars.back().setInsetOwner(pars[0].inInset());
1274 pars.back().layout(tclass.defaultLayout());
1276 int cap_pit = pars.size() - 1;
1278 // if an empty inset was created, we create an additional empty
1279 // paragraph at the bottom so that the user can choose where to put
1280 // the graphics (or table).
1282 pars.push_back(Paragraph());
1283 pars.back().setInsetOwner(pars[0].inInset());
1284 pars.back().layout(tclass.defaultLayout());
1288 // reposition the cursor to the caption
1289 cur.pit() = cap_pit;
1291 cur.dispatch(FuncRequest(LFUN_CAPTION_INSERT));
1292 // FIXME: When leaving the Float (or Wrap) inset we should
1293 // delete any empty paragraph left above or below the
1298 case LFUN_INDEX_INSERT:
1299 case LFUN_NOMENCL_INSERT: {
1300 Inset * inset = createInset(&cur.bv(), cmd);
1304 cur.clearSelection();
1305 insertInset(cur, inset);
1306 inset->edit(cur, true);
1307 // Show the dialog for the nomenclature entry, since the
1308 // description entry still needs to be filled in.
1309 if (cmd.action == LFUN_NOMENCL_INSERT)
1310 InsetCommandMailer("nomenclature",
1311 *reinterpret_cast<InsetCommand *>(inset)).showDialog(&cur.bv());
1316 case LFUN_INDEX_PRINT:
1317 case LFUN_NOMENCL_PRINT:
1318 case LFUN_TOC_INSERT:
1319 case LFUN_HFILL_INSERT:
1320 case LFUN_LINE_INSERT:
1321 case LFUN_PAGEBREAK_INSERT:
1322 case LFUN_CLEARPAGE_INSERT:
1323 case LFUN_CLEARDOUBLEPAGE_INSERT:
1325 doInsertInset(cur, this, cmd, false, false);
1329 case LFUN_DEPTH_DECREMENT:
1330 changeDepth(cur, DEC_DEPTH);
1333 case LFUN_DEPTH_INCREMENT:
1334 changeDepth(cur, INC_DEPTH);
1337 case LFUN_MATH_DISPLAY:
1338 mathDispatch(cur, cmd, true);
1341 case LFUN_MATH_IMPORT_SELECTION:
1342 case LFUN_MATH_MODE:
1343 if (cmd.argument() == "on")
1344 // don't pass "on" as argument
1345 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1347 mathDispatch(cur, cmd, false);
1350 case LFUN_MATH_MACRO:
1351 if (cmd.argument().empty())
1352 cur.errorMessage(from_utf8(N_("Missing argument")));
1354 string s = to_utf8(cmd.argument());
1355 string const s1 = token(s, ' ', 1);
1356 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1357 string const s2 = token(s, ' ', 2);
1358 string const type = s2.empty() ? "newcommand" : s2;
1359 cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, from_utf8(type)));
1360 //cur.nextInset()->edit(cur, true);
1364 // passthrough hat and underscore outside mathed:
1365 case LFUN_MATH_SUBSCRIPT:
1366 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1368 case LFUN_MATH_SUPERSCRIPT:
1369 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1372 case LFUN_MATH_INSERT:
1373 case LFUN_MATH_MATRIX:
1374 case LFUN_MATH_DELIM:
1375 case LFUN_MATH_BIGDELIM: {
1376 cur.insert(new InsetMathHull(hullSimple));
1377 cur.dispatch(FuncRequest(LFUN_CHAR_FORWARD));
1378 BOOST_ASSERT(cur.inMathed());
1383 case LFUN_FONT_EMPH: {
1384 Font font(Font::ALL_IGNORE);
1385 font.setEmph(Font::TOGGLE);
1386 toggleAndShow(cur, this, font);
1390 case LFUN_FONT_BOLD: {
1391 Font font(Font::ALL_IGNORE);
1392 font.setSeries(Font::BOLD_SERIES);
1393 toggleAndShow(cur, this, font);
1397 case LFUN_FONT_NOUN: {
1398 Font font(Font::ALL_IGNORE);
1399 font.setNoun(Font::TOGGLE);
1400 toggleAndShow(cur, this, font);
1404 case LFUN_FONT_CODE: {
1405 Font font(Font::ALL_IGNORE);
1406 font.setFamily(Font::TYPEWRITER_FAMILY); // no good
1407 toggleAndShow(cur, this, font);
1411 case LFUN_FONT_SANS: {
1412 Font font(Font::ALL_IGNORE);
1413 font.setFamily(Font::SANS_FAMILY);
1414 toggleAndShow(cur, this, font);
1418 case LFUN_FONT_ROMAN: {
1419 Font font(Font::ALL_IGNORE);
1420 font.setFamily(Font::ROMAN_FAMILY);
1421 toggleAndShow(cur, this, font);
1425 case LFUN_FONT_DEFAULT: {
1426 Font font(Font::ALL_INHERIT, ignore_language);
1427 toggleAndShow(cur, this, font);
1431 case LFUN_FONT_UNDERLINE: {
1432 Font font(Font::ALL_IGNORE);
1433 font.setUnderbar(Font::TOGGLE);
1434 toggleAndShow(cur, this, font);
1438 case LFUN_FONT_SIZE: {
1439 Font font(Font::ALL_IGNORE);
1440 font.setLyXSize(to_utf8(cmd.argument()));
1441 toggleAndShow(cur, this, font);
1445 case LFUN_LANGUAGE: {
1446 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1449 Font font(Font::ALL_IGNORE);
1450 font.setLanguage(lang);
1451 toggleAndShow(cur, this, font);
1456 case LFUN_FONT_FREE_APPLY:
1457 toggleAndShow(cur, this, freefont, toggleall);
1458 cur.message(_("Character set"));
1461 // Set the freefont using the contents of \param data dispatched from
1462 // the frontends and apply it at the current cursor location.
1463 case LFUN_FONT_FREE_UPDATE: {
1466 if (bv_funcs::string2font(to_utf8(cmd.argument()), font, toggle)) {
1469 toggleAndShow(cur, this, freefont, toggleall);
1470 cur.message(_("Character set"));
1475 case LFUN_FINISHED_LEFT:
1476 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1477 if (reverseDirectionNeeded(cur))
1481 case LFUN_FINISHED_RIGHT:
1482 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1483 if (!reverseDirectionNeeded(cur))
1487 case LFUN_LAYOUT_PARAGRAPH: {
1489 params2string(cur.paragraph(), data);
1490 data = "show\n" + data;
1491 bv->showDialogWithData("paragraph", data);
1495 case LFUN_PARAGRAPH_UPDATE: {
1497 params2string(cur.paragraph(), data);
1499 // Will the paragraph accept changes from the dialog?
1500 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1502 data = "update " + convert<string>(accept) + '\n' + data;
1503 bv->updateDialog("paragraph", data);
1507 case LFUN_ACCENT_UMLAUT:
1508 case LFUN_ACCENT_CIRCUMFLEX:
1509 case LFUN_ACCENT_GRAVE:
1510 case LFUN_ACCENT_ACUTE:
1511 case LFUN_ACCENT_TILDE:
1512 case LFUN_ACCENT_CEDILLA:
1513 case LFUN_ACCENT_MACRON:
1514 case LFUN_ACCENT_DOT:
1515 case LFUN_ACCENT_UNDERDOT:
1516 case LFUN_ACCENT_UNDERBAR:
1517 case LFUN_ACCENT_CARON:
1518 case LFUN_ACCENT_SPECIAL_CARON:
1519 case LFUN_ACCENT_BREVE:
1520 case LFUN_ACCENT_TIE:
1521 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1522 case LFUN_ACCENT_CIRCLE:
1523 case LFUN_ACCENT_OGONEK:
1524 theLyXFunc().handleKeyFunc(cmd.action);
1525 if (!cmd.argument().empty())
1526 // FIXME: Are all these characters encoded in one byte in utf8?
1527 bv->getIntl().getTransManager()
1528 .translateAndInsert(cmd.argument()[0], this, cur);
1531 case LFUN_FLOAT_LIST: {
1532 TextClass const & tclass = bv->buffer()->params().getTextClass();
1533 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1534 // not quite sure if we want this...
1536 cur.clearSelection();
1537 breakParagraph(cur);
1539 if (cur.lastpos() != 0) {
1541 breakParagraph(cur);
1544 setLayout(cur, tclass.defaultLayoutName());
1545 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, docstring(), 0);
1546 insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1549 lyxerr << "Non-existent float type: "
1550 << to_utf8(cmd.argument()) << endl;
1555 case LFUN_CHANGE_ACCEPT: {
1556 acceptOrRejectChanges(cur, ACCEPT);
1560 case LFUN_CHANGE_REJECT: {
1561 acceptOrRejectChanges(cur, REJECT);
1565 case LFUN_THESAURUS_ENTRY: {
1566 docstring arg = cmd.argument();
1568 arg = cur.selectionAsString(false);
1570 if (arg.size() > 100 || arg.empty()) {
1571 // Get word or selection
1572 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1573 arg = cur.selectionAsString(false);
1576 bv->showDialogWithData("thesaurus", to_utf8(arg));
1580 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1581 // Given data, an encoding of the ParagraphParameters
1582 // generated in the Paragraph dialog, this function sets
1583 // the current paragraph appropriately.
1584 istringstream is(to_utf8(cmd.argument()));
1587 ParagraphParameters params;
1592 params.labelWidthString(),
1594 cur.message(_("Paragraph layout set"));
1599 if (cur.selection()) {
1600 cur.selection() = false;
1604 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1609 LYXERR(Debug::ACTION)
1610 << BOOST_CURRENT_FUNCTION
1611 << ": Command " << cmd
1612 << " not DISPATCHED by Text" << endl;
1617 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1619 // FIXME: The cursor flag is reset two lines below
1620 // so we need to check here if some of the LFUN did touch that.
1621 // for now only Text::erase() and Text::backspace() do that.
1622 // The plan is to verify all the LFUNs and then to remove this
1623 // singleParUpdate boolean altogether.
1624 if (cur.result().update() & Update::Force) {
1625 singleParUpdate = false;
1629 // FIXME: the following code should go in favor of fine grained
1630 // update flag treatment.
1631 if (singleParUpdate) {
1632 // Inserting characters does not change par height
1633 ParagraphMetrics const & pms
1634 = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
1635 if (pms.dim().height()
1636 == olddim.height()) {
1637 // if so, update _only_ this paragraph
1638 cur.updateFlags(Update::SinglePar |
1640 Update::MultiParSel);
1647 && &oldTopSlice.inset() == &cur.inset()
1648 && oldTopSlice.idx() == cur.idx()
1649 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1650 && !cur.selection())
1651 // FIXME: it would be better if we could just do this
1653 //if (cur.result().update() != Update::FitCursor)
1656 // But some LFUNs do not set Update::FitCursor when needed, so we
1657 // do it for all. This is not very harmfull as FitCursor will provoke
1658 // a full redraw only if needed but still, a proper review of all LFUN
1659 // should be done and this needsUpdate boolean can then be removed.
1660 cur.updateFlags(Update::FitCursor);
1662 cur.updateFlags(Update::Force | Update::FitCursor);
1666 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
1667 FuncStatus & flag) const
1669 BOOST_ASSERT(cur.text() == this);
1671 Font const & font = real_current_font;
1673 Inset::Code code = Inset::NO_CODE;
1675 switch (cmd.action) {
1677 case LFUN_DEPTH_DECREMENT:
1678 enable = changeDepthAllowed(cur, DEC_DEPTH);
1681 case LFUN_DEPTH_INCREMENT:
1682 enable = changeDepthAllowed(cur, INC_DEPTH);
1686 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1689 case LFUN_BIBITEM_INSERT:
1690 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO
1694 case LFUN_DIALOG_SHOW_NEW_INSET:
1695 if (cmd.argument() == "bibitem")
1696 code = Inset::BIBITEM_CODE;
1697 else if (cmd.argument() == "bibtex")
1698 code = Inset::BIBTEX_CODE;
1699 else if (cmd.argument() == "box")
1700 code = Inset::BOX_CODE;
1701 else if (cmd.argument() == "branch")
1702 code = Inset::BRANCH_CODE;
1703 else if (cmd.argument() == "citation")
1704 code = Inset::CITE_CODE;
1705 else if (cmd.argument() == "ert")
1706 code = Inset::ERT_CODE;
1707 else if (cmd.argument() == "external")
1708 code = Inset::EXTERNAL_CODE;
1709 else if (cmd.argument() == "float")
1710 code = Inset::FLOAT_CODE;
1711 else if (cmd.argument() == "graphics")
1712 code = Inset::GRAPHICS_CODE;
1713 else if (cmd.argument() == "include")
1714 code = Inset::INCLUDE_CODE;
1715 else if (cmd.argument() == "index")
1716 code = Inset::INDEX_CODE;
1717 else if (cmd.argument() == "nomenclature")
1718 code = Inset::NOMENCL_CODE;
1719 else if (cmd.argument() == "label")
1720 code = Inset::LABEL_CODE;
1721 else if (cmd.argument() == "note")
1722 code = Inset::NOTE_CODE;
1723 else if (cmd.argument() == "ref")
1724 code = Inset::REF_CODE;
1725 else if (cmd.argument() == "toc")
1726 code = Inset::TOC_CODE;
1727 else if (cmd.argument() == "url")
1728 code = Inset::URL_CODE;
1729 else if (cmd.argument() == "vspace")
1730 code = Inset::VSPACE_CODE;
1731 else if (cmd.argument() == "wrap")
1732 code = Inset::WRAP_CODE;
1733 else if (cmd.argument() == "listings")
1734 code = Inset::LISTINGS_CODE;
1737 case LFUN_ERT_INSERT:
1738 code = Inset::ERT_CODE;
1740 case LFUN_LISTING_INSERT:
1741 code = Inset::LISTINGS_CODE;
1743 case LFUN_FOOTNOTE_INSERT:
1744 code = Inset::FOOT_CODE;
1746 case LFUN_TABULAR_INSERT:
1747 code = Inset::TABULAR_CODE;
1749 case LFUN_MARGINALNOTE_INSERT:
1750 code = Inset::MARGIN_CODE;
1752 case LFUN_FLOAT_INSERT:
1753 case LFUN_FLOAT_WIDE_INSERT:
1754 code = Inset::FLOAT_CODE;
1756 case LFUN_WRAP_INSERT:
1757 code = Inset::WRAP_CODE;
1759 case LFUN_FLOAT_LIST:
1760 code = Inset::FLOAT_LIST_CODE;
1763 case LFUN_LIST_INSERT:
1764 code = Inset::LIST_CODE;
1766 case LFUN_THEOREM_INSERT:
1767 code = Inset::THEOREM_CODE;
1770 case LFUN_CAPTION_INSERT:
1771 code = Inset::CAPTION_CODE;
1773 case LFUN_NOTE_INSERT:
1774 code = Inset::NOTE_CODE;
1776 case LFUN_CHARSTYLE_INSERT:
1777 code = Inset::CHARSTYLE_CODE;
1778 if (cur.buffer().params().getTextClass().charstyles().empty())
1781 case LFUN_BOX_INSERT:
1782 code = Inset::BOX_CODE;
1784 case LFUN_BRANCH_INSERT:
1785 code = Inset::BRANCH_CODE;
1786 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1789 case LFUN_LABEL_INSERT:
1790 code = Inset::LABEL_CODE;
1792 case LFUN_OPTIONAL_INSERT:
1793 code = Inset::OPTARG_CODE;
1794 enable = numberOfOptArgs(cur.paragraph())
1795 < cur.paragraph().layout()->optionalargs;
1797 case LFUN_ENVIRONMENT_INSERT:
1798 code = Inset::BOX_CODE;
1800 case LFUN_INDEX_INSERT:
1801 code = Inset::INDEX_CODE;
1803 case LFUN_INDEX_PRINT:
1804 code = Inset::INDEX_PRINT_CODE;
1806 case LFUN_NOMENCL_INSERT:
1807 code = Inset::NOMENCL_CODE;
1809 case LFUN_NOMENCL_PRINT:
1810 code = Inset::NOMENCL_PRINT_CODE;
1812 case LFUN_TOC_INSERT:
1813 code = Inset::TOC_CODE;
1815 case LFUN_HTML_INSERT:
1816 case LFUN_URL_INSERT:
1817 code = Inset::URL_CODE;
1819 case LFUN_QUOTE_INSERT:
1820 // always allow this, since we will inset a raw quote
1821 // if an inset is not allowed.
1823 case LFUN_HYPHENATION_POINT_INSERT:
1824 case LFUN_LIGATURE_BREAK_INSERT:
1825 case LFUN_HFILL_INSERT:
1826 case LFUN_MENU_SEPARATOR_INSERT:
1827 case LFUN_DOTS_INSERT:
1828 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
1829 code = Inset::SPECIALCHAR_CODE;
1831 case LFUN_SPACE_INSERT:
1832 // slight hack: we know this is allowed in math mode
1834 code = Inset::SPACE_CODE;
1837 case LFUN_INSET_MODIFY:
1838 // We need to disable this, because we may get called for a
1840 // InsetTabular::getStatus() -> InsetText::getStatus()
1841 // and we don't handle LFUN_INSET_MODIFY.
1845 case LFUN_FONT_EMPH:
1846 flag.setOnOff(font.emph() == Font::ON);
1849 case LFUN_FONT_NOUN:
1850 flag.setOnOff(font.noun() == Font::ON);
1853 case LFUN_FONT_BOLD:
1854 flag.setOnOff(font.series() == Font::BOLD_SERIES);
1857 case LFUN_FONT_SANS:
1858 flag.setOnOff(font.family() == Font::SANS_FAMILY);
1861 case LFUN_FONT_ROMAN:
1862 flag.setOnOff(font.family() == Font::ROMAN_FAMILY);
1865 case LFUN_FONT_CODE:
1866 flag.setOnOff(font.family() == Font::TYPEWRITER_FAMILY);
1871 enable = cur.selection();
1875 if (cmd.argument().empty()) {
1876 if (theClipboard().isInternal())
1877 enable = cap::numberOfSelections() > 0;
1879 enable = !theClipboard().empty();
1881 string const arg = to_utf8(cmd.argument());
1882 if (isStrUnsignedInt(arg)) {
1883 unsigned int n = convert<unsigned int>(arg);
1884 enable = cap::numberOfSelections() > n;
1891 case LFUN_CLIPBOARD_PASTE:
1892 enable = !theClipboard().empty();
1895 case LFUN_PRIMARY_SELECTION_PASTE:
1896 enable = cur.selection() || !theSelection().empty();
1899 case LFUN_PARAGRAPH_MOVE_UP:
1900 enable = cur.pit() > 0 && !cur.selection();
1903 case LFUN_PARAGRAPH_MOVE_DOWN:
1904 enable = cur.pit() < cur.lastpit() && !cur.selection();
1907 case LFUN_INSET_DISSOLVE:
1908 enable = !isMainText(*cur.bv().buffer()) && cur.inset().nargs() == 1;
1911 case LFUN_CHANGE_ACCEPT:
1912 case LFUN_CHANGE_REJECT:
1913 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
1914 // In principle, these LFUNs should only be enabled if there
1915 // is a change at the current position/in the current selection.
1916 // However, without proper optimizations, this will inevitably
1917 // result in unacceptable performance - just imagine a user who
1918 // wants to select the complete content of a long document.
1922 case LFUN_WORD_DELETE_FORWARD:
1923 case LFUN_WORD_DELETE_BACKWARD:
1924 case LFUN_LINE_DELETE:
1925 case LFUN_WORD_FORWARD:
1926 case LFUN_WORD_BACKWARD:
1927 case LFUN_CHAR_FORWARD:
1928 case LFUN_CHAR_FORWARD_SELECT:
1929 case LFUN_CHAR_BACKWARD:
1930 case LFUN_CHAR_BACKWARD_SELECT:
1932 case LFUN_UP_SELECT:
1934 case LFUN_DOWN_SELECT:
1935 case LFUN_PARAGRAPH_UP_SELECT:
1936 case LFUN_PARAGRAPH_DOWN_SELECT:
1937 case LFUN_SCREEN_UP_SELECT:
1938 case LFUN_SCREEN_DOWN_SELECT:
1939 case LFUN_LINE_BEGIN_SELECT:
1940 case LFUN_LINE_END_SELECT:
1941 case LFUN_WORD_FORWARD_SELECT:
1942 case LFUN_WORD_BACKWARD_SELECT:
1943 case LFUN_WORD_SELECT:
1944 case LFUN_PARAGRAPH_UP:
1945 case LFUN_PARAGRAPH_DOWN:
1946 case LFUN_SCREEN_UP:
1947 case LFUN_SCREEN_DOWN:
1948 case LFUN_LINE_BEGIN:
1950 case LFUN_BREAK_LINE:
1951 case LFUN_CHAR_DELETE_FORWARD:
1952 case LFUN_DELETE_FORWARD_SKIP:
1953 case LFUN_CHAR_DELETE_BACKWARD:
1954 case LFUN_DELETE_BACKWARD_SKIP:
1955 case LFUN_BREAK_PARAGRAPH:
1956 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
1957 case LFUN_BREAK_PARAGRAPH_SKIP:
1958 case LFUN_PARAGRAPH_SPACING:
1959 case LFUN_INSET_INSERT:
1960 case LFUN_WORD_UPCASE:
1961 case LFUN_WORD_LOWCASE:
1962 case LFUN_WORD_CAPITALIZE:
1963 case LFUN_CHARS_TRANSPOSE:
1964 case LFUN_SERVER_GET_XY:
1965 case LFUN_SERVER_SET_XY:
1966 case LFUN_SERVER_GET_FONT:
1967 case LFUN_SERVER_GET_LAYOUT:
1969 case LFUN_DATE_INSERT:
1970 case LFUN_SELF_INSERT:
1971 case LFUN_LINE_INSERT:
1972 case LFUN_PAGEBREAK_INSERT:
1973 case LFUN_CLEARPAGE_INSERT:
1974 case LFUN_CLEARDOUBLEPAGE_INSERT:
1975 case LFUN_MATH_DISPLAY:
1976 case LFUN_MATH_IMPORT_SELECTION:
1977 case LFUN_MATH_MODE:
1978 case LFUN_MATH_MACRO:
1979 case LFUN_MATH_MATRIX:
1980 case LFUN_MATH_DELIM:
1981 case LFUN_MATH_BIGDELIM:
1982 case LFUN_MATH_SUBSCRIPT:
1983 case LFUN_MATH_SUPERSCRIPT:
1984 case LFUN_FONT_DEFAULT:
1985 case LFUN_FONT_UNDERLINE:
1986 case LFUN_FONT_SIZE:
1988 case LFUN_FONT_FREE_APPLY:
1989 case LFUN_FONT_FREE_UPDATE:
1990 case LFUN_LAYOUT_PARAGRAPH:
1991 case LFUN_PARAGRAPH_UPDATE:
1992 case LFUN_ACCENT_UMLAUT:
1993 case LFUN_ACCENT_CIRCUMFLEX:
1994 case LFUN_ACCENT_GRAVE:
1995 case LFUN_ACCENT_ACUTE:
1996 case LFUN_ACCENT_TILDE:
1997 case LFUN_ACCENT_CEDILLA:
1998 case LFUN_ACCENT_MACRON:
1999 case LFUN_ACCENT_DOT:
2000 case LFUN_ACCENT_UNDERDOT:
2001 case LFUN_ACCENT_UNDERBAR:
2002 case LFUN_ACCENT_CARON:
2003 case LFUN_ACCENT_SPECIAL_CARON:
2004 case LFUN_ACCENT_BREVE:
2005 case LFUN_ACCENT_TIE:
2006 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
2007 case LFUN_ACCENT_CIRCLE:
2008 case LFUN_ACCENT_OGONEK:
2009 case LFUN_THESAURUS_ENTRY:
2010 case LFUN_PARAGRAPH_PARAMS_APPLY:
2012 case LFUN_BUFFER_END:
2013 case LFUN_BUFFER_BEGIN:
2014 case LFUN_BUFFER_BEGIN_SELECT:
2015 case LFUN_BUFFER_END_SELECT:
2016 case LFUN_UNICODE_INSERT:
2017 // these are handled in our dispatch()
2025 if (code != Inset::NO_CODE
2026 && (cur.empty() || !cur.inset().insetAllowed(code)))
2029 flag.enabled(enable);
2034 void Text::pasteString(Cursor & cur, docstring const & clip,
2037 cur.clearSelection();
2038 if (!clip.empty()) {
2041 insertStringAsParagraphs(cur, clip);
2043 insertStringAsLines(cur, clip);