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())
126 void finishChange(Cursor & cur, bool selecting)
129 moveCursor(cur, selecting);
133 void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
136 docstring sel = cur.selectionAsString(false);
138 // It may happen that sel is empty but there is a selection
139 replaceSelection(cur);
142 #ifdef ENABLE_ASSERTIONS
143 const int old_pos = cur.pos();
145 cur.insert(new InsetMathHull(hullSimple));
146 BOOST_ASSERT(old_pos == cur.pos());
147 cur.nextInset()->edit(cur, true);
148 // don't do that also for LFUN_MATH_MODE
149 // unless you want end up with always changing
150 // to mathrm when opening an inlined inset --
151 // I really hate "LyXfunc overloading"...
153 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
154 // Avoid an unnecessary undo step if cmd.argument
156 if (!cmd.argument().empty())
157 cur.dispatch(FuncRequest(LFUN_MATH_INSERT,
160 // create a macro if we see "\\newcommand"
161 // somewhere, and an ordinary formula
163 if (sel.find(from_ascii("\\newcommand")) == string::npos
164 && sel.find(from_ascii("\\def")) == string::npos)
166 InsetMathHull * formula = new InsetMathHull;
167 istringstream is(to_utf8(sel));
170 formula->read(cur.buffer(), lex);
171 if (formula->getType() == hullNone)
172 // Don't create pseudo formulas if
173 // delimiters are left out
174 formula->mutate(hullSimple);
177 cur.insert(new MathMacroTemplate(sel));
180 cur.message(from_utf8(N_("Math editor mode")));
189 string const freefont2string()
192 if (font2string(freefont, toggleall, data))
199 void Text::cursorPrevious(Cursor & cur)
201 pos_type cpos = cur.pos();
202 pit_type cpar = cur.pit();
204 int x = cur.x_target();
205 setCursorFromCoordinates(cur, x, 0);
206 cur.dispatch(FuncRequest(cur.selection()? LFUN_UP_SELECT: LFUN_UP));
208 if (cpar == cur.pit() && cpos == cur.pos())
209 // we have a row which is taller than the workarea. The
210 // simplest solution is to move to the previous row instead.
211 cur.dispatch(FuncRequest(cur.selection()? LFUN_UP_SELECT: LFUN_UP));
214 cur.updateFlags(Update::Force | Update::FitCursor);
218 void Text::cursorNext(Cursor & cur)
220 pos_type cpos = cur.pos();
221 pit_type cpar = cur.pit();
223 int x = cur.x_target();
224 setCursorFromCoordinates(cur, x, cur.bv().workHeight() - 1);
225 cur.dispatch(FuncRequest(cur.selection()? LFUN_DOWN_SELECT: LFUN_DOWN));
227 if (cpar == cur.pit() && cpos == cur.pos())
228 // we have a row which is taller than the workarea. The
229 // simplest solution is to move to the next row instead.
231 FuncRequest(cur.selection()? LFUN_DOWN_SELECT: LFUN_DOWN));
234 cur.updateFlags(Update::Force | Update::FitCursor);
240 void specialChar(Cursor & cur, InsetSpecialChar::Kind kind)
243 cap::replaceSelection(cur);
244 cur.insert(new InsetSpecialChar(kind));
249 bool doInsertInset(Cursor & cur, Text * text,
250 FuncRequest const & cmd, bool edit, bool pastesel)
252 Inset * inset = createInset(&cur.bv(), cmd);
258 if (cur.selection()) {
259 lyx::dispatch(FuncRequest(LFUN_CUT));
262 text->insertInset(cur, inset);
265 inset->edit(cur, true);
267 if (gotsel && pastesel) {
268 lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
269 // reset first par to default
270 if (cur.lastpit() != 0 || cur.lastpos() != 0) {
271 Layout_ptr const layout =
272 cur.buffer().params().getTextClass().defaultLayout();
273 cur.text()->paragraphs().begin()->layout(layout);
283 void Text::number(Cursor & cur)
285 Font font(Font::ALL_IGNORE);
286 font.setNumber(Font::TOGGLE);
287 toggleAndShow(cur, this, font);
291 bool Text::isRTL(Buffer const & buffer, Paragraph const & par) const
293 return par.isRightToLeftPar(buffer.params());
297 bool Text::isRTL(Buffer const & buffer, CursorSlice const & sl, bool boundary) const
299 if (!lyxrc.rtl_support && !sl.text())
303 if (boundary && sl.pos() > 0)
306 Paragraph const & par = getPar(sl.pit());
307 return getFont(buffer, par, sl.pos() + correction).isVisibleRightToLeft();
311 bool Text::isRTLBoundary(Buffer const & buffer, Paragraph const & par,
314 if (!lyxrc.rtl_support)
317 // no RTL boundary at line start
321 bool left = getFont(buffer, par, pos - 1).isVisibleRightToLeft();
323 if (pos == par.size())
324 right = par.isRightToLeftPar(buffer.params());
326 right = getFont(buffer, par, pos).isVisibleRightToLeft();
327 return left != right;
331 bool Text::isRTLBoundary(Buffer const & buffer, Paragraph const & par,
332 pos_type pos, Font const & font) const
334 if (!lyxrc.rtl_support)
337 bool left = font.isVisibleRightToLeft();
339 if (pos == par.size())
340 right = par.isRightToLeftPar(buffer.params());
342 right = getFont(buffer, par, pos).isVisibleRightToLeft();
343 return left != right;
347 void Text::dispatch(Cursor & cur, FuncRequest & cmd)
349 LYXERR(Debug::ACTION) << "Text::dispatch: cmd: " << cmd << endl;
351 // FIXME: We use the update flag to indicates wether a singlePar or a
352 // full screen update is needed. We reset it here but shall we restore it
356 BOOST_ASSERT(cur.text() == this);
357 BufferView * bv = &cur.bv();
358 CursorSlice oldTopSlice = cur.top();
359 bool oldBoundary = cur.boundary();
360 bool sel = cur.selection();
361 // Signals that, even if needsUpdate == false, an update of the
362 // cursor paragraph is required
363 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
364 LyXAction::SingleParUpdate);
365 // Signals that a full-screen update is required
366 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
367 LyXAction::NoUpdate) || singleParUpdate);
368 // Remember the old paragraph metric (_outer_ paragraph!)
369 ParagraphMetrics const & pm = cur.bv().parMetrics(
370 cur.bottom().text(), cur.bottom().pit());
371 Dimension olddim = pm.dim();
373 switch (cmd.action) {
375 case LFUN_PARAGRAPH_MOVE_DOWN: {
376 pit_type const pit = cur.pit();
377 recUndo(cur, pit, pit + 1);
379 std::swap(pars_[pit], pars_[pit + 1]);
381 ParIterator begin(cur);
382 // begin.pos() (== cur.pos()) may point beyond the end of the
383 // paragraph referenced by begin. This would cause a crash
387 ParIterator end = boost::next(ParIterator(cur));
388 updateLabels(cur.buffer(), begin, end);
394 case LFUN_PARAGRAPH_MOVE_UP: {
395 pit_type const pit = cur.pit();
396 recUndo(cur, pit - 1, pit);
398 std::swap(pars_[pit], pars_[pit - 1]);
400 ParIterator end = ParIterator(cur);
401 // end.pos() (== cur.pos()) may point beyond the end of the
402 // paragraph referenced by end. This would cause a crash
405 end = boost::next(end);
407 ParIterator begin(cur);
408 updateLabels(cur.buffer(), begin, end);
414 case LFUN_APPENDIX: {
415 Paragraph & par = cur.paragraph();
416 bool start = !par.params().startOfAppendix();
419 #warning The code below only makes sense at top level.
420 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
422 // ensure that we have only one start_of_appendix in this document
423 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
424 if (pars_[tmp].params().startOfAppendix()) {
426 pars_[tmp].params().startOfAppendix(false);
432 par.params().startOfAppendix(start);
434 // we can set the refreshing parameters now
435 updateLabels(cur.buffer());
439 case LFUN_WORD_DELETE_FORWARD:
440 cur.clearSelection();
441 deleteWordForward(cur);
442 finishChange(cur, false);
445 case LFUN_WORD_DELETE_BACKWARD:
446 cur.clearSelection();
447 deleteWordBackward(cur);
448 finishChange(cur, false);
451 case LFUN_LINE_DELETE:
452 cur.clearSelection();
453 deleteLineForward(cur);
454 finishChange(cur, false);
457 case LFUN_BUFFER_BEGIN:
458 case LFUN_BUFFER_BEGIN_SELECT:
459 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
460 if (cur.depth() == 1) {
461 needsUpdate |= cursorTop(cur);
467 case LFUN_BUFFER_END:
468 case LFUN_BUFFER_END_SELECT:
469 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
470 if (cur.depth() == 1) {
471 needsUpdate |= cursorBottom(cur);
477 case LFUN_CHAR_FORWARD:
478 case LFUN_CHAR_FORWARD_SELECT:
479 //lyxerr << BOOST_CURRENT_FUNCTION
480 // << " LFUN_CHAR_FORWARD[SEL]:\n" << cur << endl;
481 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
482 if (reverseDirectionNeeded(cur))
483 needsUpdate |= cursorLeft(cur);
485 needsUpdate |= cursorRight(cur);
487 if (!needsUpdate && oldTopSlice == cur.top()
488 && cur.boundary() == oldBoundary) {
490 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
491 } else if (cur.selection())
495 case LFUN_CHAR_BACKWARD:
496 case LFUN_CHAR_BACKWARD_SELECT:
497 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
498 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
499 if (reverseDirectionNeeded(cur))
500 needsUpdate |= cursorRight(cur);
502 needsUpdate |= cursorLeft(cur);
504 if (!needsUpdate && oldTopSlice == cur.top()
505 && cur.boundary() == oldBoundary) {
507 cmd = FuncRequest(LFUN_FINISHED_LEFT);
514 case LFUN_UP_SELECT: {
515 //lyxerr << "handle LFUN_UP[SEL]:\n" << cur << endl;
516 needsUpdate |= cur.selHandle(cmd.action == LFUN_UP_SELECT);
517 bool const successful = cur.upDownInText(true, needsUpdate);
526 case LFUN_DOWN_SELECT: {
527 //lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
528 needsUpdate |= cur.selHandle(cmd.action == LFUN_DOWN_SELECT);
529 bool const successful = cur.upDownInText(false, needsUpdate);
537 case LFUN_PARAGRAPH_UP:
538 case LFUN_PARAGRAPH_UP_SELECT:
539 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
540 needsUpdate |= cursorUpParagraph(cur);
545 case LFUN_PARAGRAPH_DOWN:
546 case LFUN_PARAGRAPH_DOWN_SELECT:
547 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
548 needsUpdate |= cursorDownParagraph(cur);
554 case LFUN_SCREEN_UP_SELECT:
555 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_UP_SELECT);
556 if (cur.pit() == 0 && cur.textRow().pos() == 0)
565 case LFUN_SCREEN_DOWN:
566 case LFUN_SCREEN_DOWN_SELECT:
567 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_DOWN_SELECT);
568 if (cur.pit() == cur.lastpit()
569 && cur.textRow().endpos() == cur.lastpos())
578 case LFUN_LINE_BEGIN:
579 case LFUN_LINE_BEGIN_SELECT:
580 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
581 needsUpdate |= cursorHome(cur);
585 case LFUN_LINE_END_SELECT:
586 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
587 needsUpdate |= cursorEnd(cur);
592 case LFUN_WORD_FORWARD:
593 case LFUN_WORD_FORWARD_SELECT:
594 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
595 if (reverseDirectionNeeded(cur))
596 needsUpdate |= cursorLeftOneWord(cur);
598 needsUpdate |= cursorRightOneWord(cur);
603 case LFUN_WORD_BACKWARD:
604 case LFUN_WORD_BACKWARD_SELECT:
605 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
606 if (reverseDirectionNeeded(cur))
607 needsUpdate |= cursorRightOneWord(cur);
609 needsUpdate |= cursorLeftOneWord(cur);
614 case LFUN_WORD_SELECT: {
615 selectWord(cur, WHOLE_WORD);
616 finishChange(cur, true);
620 case LFUN_BREAK_LINE: {
621 // Not allowed by LaTeX (labels or empty par)
622 if (cur.pos() > cur.paragraph().beginOfBody()) {
623 // this avoids a double undo
624 // FIXME: should not be needed, ideally
625 if (!cur.selection())
627 cap::replaceSelection(cur);
628 cur.insert(new InsetNewline);
630 moveCursor(cur, false);
635 case LFUN_CHAR_DELETE_FORWARD:
636 if (!cur.selection()) {
637 if (cur.pos() == cur.paragraph().size())
638 // Par boundary, force full-screen update
639 singleParUpdate = false;
640 needsUpdate |= erase(cur);
642 // It is possible to make it a lot faster still
643 // just comment out the line below...
645 cutSelection(cur, true, false);
646 singleParUpdate = false;
648 moveCursor(cur, false);
651 case LFUN_DELETE_FORWARD_SKIP:
652 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
653 if (!cur.selection()) {
654 if (cur.pos() == cur.lastpos()) {
661 cutSelection(cur, true, false);
666 case LFUN_CHAR_DELETE_BACKWARD:
667 if (!cur.selection()) {
668 if (bv->getIntl().getTransManager().backspace()) {
669 // Par boundary, full-screen update
671 singleParUpdate = false;
672 needsUpdate |= backspace(cur);
674 // It is possible to make it a lot faster still
675 // just comment out the line below...
678 cutSelection(cur, true, false);
679 singleParUpdate = false;
683 case LFUN_DELETE_BACKWARD_SKIP:
684 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
685 if (!cur.selection()) {
689 //CursorSlice cur = cursor();
693 cutSelection(cur, true, false);
697 case LFUN_BREAK_PARAGRAPH:
698 cap::replaceSelection(cur);
699 breakParagraph(cur, 0);
703 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
704 cap::replaceSelection(cur);
705 breakParagraph(cur, 1);
709 case LFUN_BREAK_PARAGRAPH_SKIP: {
710 // When at the beginning of a paragraph, remove
711 // indentation. Otherwise, do the same as LFUN_BREAK_PARAGRAPH.
712 cap::replaceSelection(cur);
714 cur.paragraph().params().labelWidthString(docstring());
716 breakParagraph(cur, 0);
721 case LFUN_PARAGRAPH_SPACING: {
722 Paragraph & par = cur.paragraph();
723 Spacing::Space cur_spacing = par.params().spacing().getSpace();
724 string cur_value = "1.0";
725 if (cur_spacing == Spacing::Other)
726 cur_value = par.params().spacing().getValueAsString();
728 istringstream is(to_utf8(cmd.argument()));
731 Spacing::Space new_spacing = cur_spacing;
732 string new_value = cur_value;
734 lyxerr << "Missing argument to `paragraph-spacing'"
736 } else if (tmp == "single") {
737 new_spacing = Spacing::Single;
738 } else if (tmp == "onehalf") {
739 new_spacing = Spacing::Onehalf;
740 } else if (tmp == "double") {
741 new_spacing = Spacing::Double;
742 } else if (tmp == "other") {
743 new_spacing = Spacing::Other;
744 string tmpval = "0.0";
746 lyxerr << "new_value = " << tmpval << endl;
749 } else if (tmp == "default") {
750 new_spacing = Spacing::Default;
752 lyxerr << to_utf8(_("Unknown spacing argument: "))
753 << to_utf8(cmd.argument()) << endl;
755 if (cur_spacing != new_spacing || cur_value != new_value)
756 par.params().spacing(Spacing(new_spacing, new_value));
760 case LFUN_INSET_INSERT: {
762 Inset * inset = createInset(bv, cmd);
764 // FIXME (Abdel 01/02/2006):
765 // What follows would be a partial fix for bug 2154:
766 // http://bugzilla.lyx.org/show_bug.cgi?id=2154
767 // This automatically put the label inset _after_ a
768 // numbered section. It should be possible to extend the mechanism
769 // to any kind of LateX environement.
770 // The correct way to fix that bug would be at LateX generation.
771 // I'll let the code here for reference as it could be used for some
772 // other feature like "automatic labelling".
774 Paragraph & par = pars_[cur.pit()];
775 if (inset->lyxCode() == Inset::LABEL_CODE
776 && par.layout()->labeltype == LABEL_COUNTER) {
777 // Go to the end of the paragraph
778 // Warning: Because of Change-Tracking, the last
779 // position is 'size()' and not 'size()-1':
780 cur.pos() = par.size();
781 // Insert a new paragraph
782 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
786 insertInset(cur, inset);
792 case LFUN_INSET_DISSOLVE:
793 needsUpdate |= dissolveInset(cur);
796 case LFUN_INSET_SETTINGS:
797 cur.inset().showInsetDialog(bv);
800 case LFUN_SPACE_INSERT:
801 if (cur.paragraph().layout()->free_spacing)
802 insertChar(cur, ' ');
804 doInsertInset(cur, this, cmd, false, false);
807 moveCursor(cur, false);
810 case LFUN_HYPHENATION_POINT_INSERT:
811 specialChar(cur, InsetSpecialChar::HYPHENATION);
814 case LFUN_LIGATURE_BREAK_INSERT:
815 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
818 case LFUN_DOTS_INSERT:
819 specialChar(cur, InsetSpecialChar::LDOTS);
822 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
823 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
826 case LFUN_MENU_SEPARATOR_INSERT:
827 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
830 case LFUN_WORD_UPCASE:
831 changeCase(cur, Text::text_uppercase);
834 case LFUN_WORD_LOWCASE:
835 changeCase(cur, Text::text_lowercase);
838 case LFUN_WORD_CAPITALIZE:
839 changeCase(cur, Text::text_capitalization);
842 case LFUN_CHARS_TRANSPOSE:
847 cur.message(_("Paste"));
848 cap::replaceSelection(cur);
849 if (cmd.argument().empty() && !theClipboard().isInternal())
850 pasteClipboard(cur, bv->buffer()->errorList("Paste"));
852 string const arg(to_utf8(cmd.argument()));
853 pasteFromStack(cur, bv->buffer()->errorList("Paste"),
854 isStrUnsignedInt(arg) ?
855 convert<unsigned int>(arg) :
858 bv->buffer()->errors("Paste");
859 cur.clearSelection(); // bug 393
864 cutSelection(cur, true, true);
865 cur.message(_("Cut"));
870 cur.message(_("Copy"));
873 case LFUN_SERVER_GET_XY:
874 cur.message(from_utf8(
875 convert<string>(cursorX(cur.bv(), cur.top(), cur.boundary()))
876 + ' ' + convert<string>(cursorY(cur.bv(), cur.top(), cur.boundary()))));
879 case LFUN_SERVER_SET_XY: {
882 istringstream is(to_utf8(cmd.argument()));
885 lyxerr << "SETXY: Could not parse coordinates in '"
886 << to_utf8(cmd.argument()) << std::endl;
888 setCursorFromCoordinates(cur, x, y);
892 case LFUN_SERVER_GET_FONT:
893 if (current_font.shape() == Font::ITALIC_SHAPE)
894 cur.message(from_ascii("E"));
895 else if (current_font.shape() == Font::SMALLCAPS_SHAPE)
896 cur.message(from_ascii("N"));
898 cur.message(from_ascii("0"));
901 case LFUN_SERVER_GET_LAYOUT:
902 cur.message(from_utf8(cur.paragraph().layout()->name()));
906 string layout = to_ascii(cmd.argument());
907 LYXERR(Debug::INFO) << "LFUN_LAYOUT: (arg) " << layout << endl;
909 // Derive layout number from given argument (string)
910 // and current buffer's textclass (number)
911 TextClass const & tclass = bv->buffer()->params().getTextClass();
913 layout = tclass.defaultLayoutName();
914 bool hasLayout = tclass.hasLayout(layout);
916 // If the entry is obsolete, use the new one instead.
918 string const & obs = tclass[layout]->obsoleted_by();
924 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
925 from_utf8(N_(" not known")));
929 bool change_layout = (current_layout != layout);
931 if (!change_layout && cur.selection() &&
932 cur.selBegin().pit() != cur.selEnd().pit())
934 pit_type spit = cur.selBegin().pit();
935 pit_type epit = cur.selEnd().pit() + 1;
936 while (spit != epit) {
937 if (pars_[spit].layout()->name() != current_layout) {
938 change_layout = true;
946 current_layout = layout;
947 setLayout(cur, layout);
948 // inform the GUI that the layout has changed.
949 bv->layoutChanged(layout);
954 case LFUN_CLIPBOARD_PASTE:
955 cur.clearSelection();
956 pasteClipboard(cur, bv->buffer()->errorList("Paste"),
957 cmd.argument() == "paragraph");
958 bv->buffer()->errors("Paste");
961 case LFUN_PRIMARY_SELECTION_PASTE:
962 pasteString(cur, theSelection().get(),
963 cmd.argument() == "paragraph");
966 case LFUN_UNICODE_INSERT: {
967 if (cmd.argument().empty())
969 docstring hexstring = cmd.argument();
970 if (lyx::support::isHex(hexstring)) {
971 char_type c = lyx::support::hexToInt(hexstring);
972 if (c > 32 && c < 0x10ffff) {
973 lyxerr << "Inserting c: " << c << endl;
974 docstring s = docstring(1, c);
975 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
981 case LFUN_QUOTE_INSERT: {
982 Paragraph & par = cur.paragraph();
983 pos_type pos = cur.pos();
984 BufferParams const & bufparams = bv->buffer()->params();
985 Layout_ptr const & style = par.layout();
986 if (!style->pass_thru
987 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
988 // this avoids a double undo
989 // FIXME: should not be needed, ideally
990 if (!cur.selection())
992 cap::replaceSelection(cur);
997 else if (cur.prevInset() && cur.prevInset()->isSpace())
1000 c = par.getChar(pos - 1);
1001 string arg = to_utf8(cmd.argument());
1002 if (arg == "single")
1003 cur.insert(new InsetQuotes(c,
1004 bufparams.quotes_language,
1005 InsetQuotes::SingleQ));
1007 cur.insert(new InsetQuotes(c,
1008 bufparams.quotes_language,
1009 InsetQuotes::DoubleQ));
1013 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
1017 case LFUN_DATE_INSERT:
1018 if (cmd.argument().empty())
1019 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
1020 formatted_time(current_time())));
1022 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
1023 formatted_time(current_time(), to_utf8(cmd.argument()))));
1026 case LFUN_MOUSE_TRIPLE:
1027 if (cmd.button() == mouse_button::button1) {
1037 case LFUN_MOUSE_DOUBLE:
1038 if (cmd.button() == mouse_button::button1) {
1039 selectWord(cur, WHOLE_WORD_STRICT);
1044 // Single-click on work area
1045 case LFUN_MOUSE_PRESS: {
1046 // Right click on a footnote flag opens float menu
1047 if (cmd.button() == mouse_button::button3)
1048 cur.clearSelection();
1050 // Middle button press pastes if we have a selection
1051 // We do this here as if the selection was inside an inset
1052 // it could get cleared on the unlocking of the inset so
1053 // we have to check this first
1054 bool paste_internally = false;
1055 if (cmd.button() == mouse_button::button2 && cap::selection()) {
1056 // Copy the selection buffer to the clipboard
1057 // stack, because we want it to appear in the
1058 // "Edit->Paste recent" menu.
1059 cap::copySelectionToStack();
1060 paste_internally = true;
1063 // Insert primary selection with middle mouse
1064 // if there is a local selection in the current buffer,
1066 if (cmd.button() == mouse_button::button2) {
1067 if (paste_internally) {
1068 cap::pasteSelection(cur, bv->buffer()->errorList("Paste"));
1069 bv->buffer()->errors("Paste");
1070 cur.clearSelection(); // bug 393
1071 bv->buffer()->markDirty();
1074 bv->mouseSetCursor(cur);
1075 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
1079 // we have to update after dePM triggered
1080 bool update = bv->mouseSetCursor(cur);
1082 if (!update && cmd.button() == mouse_button::button1) {
1083 needsUpdate = false;
1090 case LFUN_MOUSE_MOTION: {
1091 // Only use motion with button 1
1092 //if (cmd.button() != mouse_button::button1)
1095 // ignore motions deeper nested than the real anchor
1096 Cursor & bvcur = cur.bv().cursor();
1097 if (bvcur.anchor_.hasPart(cur)) {
1098 CursorSlice old = bvcur.top();
1100 int const wh = bv->workHeight();
1101 int const y = std::max(0, std::min(wh - 1, cmd.y));
1103 setCursorFromCoordinates(cur, cmd.x, y);
1104 cur.setTargetX(cmd.x);
1106 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1108 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1109 // This is to allow jumping over large insets
1110 if (cur.top() == old) {
1112 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1114 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1117 if (cur.top() == old)
1120 // don't set anchor_
1121 bvcur.setCursor(cur);
1122 bvcur.selection() = true;
1123 //lyxerr << "MOTION: " << bv->cursor() << endl;
1131 case LFUN_MOUSE_RELEASE: {
1132 if (cmd.button() == mouse_button::button2)
1135 if (cmd.button() == mouse_button::button1) {
1136 // if there is new selection, update persistent
1137 // selection, otherwise, single click does not
1138 // clear persistent selection buffer
1139 if (cur.selection()) {
1141 // if double click, cur is moved to the end of word by selectWord
1142 // but bvcur is current mouse position
1143 Cursor & bvcur = cur.bv().cursor();
1144 bvcur.selection() = true;
1145 saveSelection(bvcur);
1147 needsUpdate = false;
1154 case LFUN_SELF_INSERT: {
1155 if (cmd.argument().empty())
1158 // Automatically delete the currently selected
1159 // text and replace it with what is being
1160 // typed in now. Depends on lyxrc settings
1161 // "auto_region_delete", which defaults to
1164 if (lyxrc.auto_region_delete)
1165 if (cur.selection())
1166 cutSelection(cur, false, false);
1168 cur.clearSelection();
1169 Font const old_font = real_current_font;
1171 docstring::const_iterator cit = cmd.argument().begin();
1172 docstring::const_iterator end = cmd.argument().end();
1173 for (; cit != end; ++cit)
1174 bv->translateAndInsert(*cit, this, cur);
1177 moveCursor(cur, false);
1181 case LFUN_URL_INSERT: {
1182 InsetCommandParams p("url");
1183 string const data = InsetCommandMailer::params2string("url", p);
1184 bv->showInsetDialog("url", data, 0);
1188 case LFUN_HTML_INSERT: {
1189 InsetCommandParams p("htmlurl");
1190 string const data = InsetCommandMailer::params2string("url", p);
1191 bv->showInsetDialog("url", data, 0);
1195 case LFUN_LABEL_INSERT: {
1196 InsetCommandParams p("label");
1197 // Try to generate a valid label
1198 p["name"] = (cmd.argument().empty()) ?
1199 cur.getPossibleLabel() :
1201 string const data = InsetCommandMailer::params2string("label", p);
1203 if (cmd.argument().empty()) {
1204 bv->showInsetDialog("label", data, 0);
1206 FuncRequest fr(LFUN_INSET_INSERT, data);
1214 case LFUN_LIST_INSERT:
1215 case LFUN_THEOREM_INSERT:
1217 case LFUN_CAPTION_INSERT:
1218 // Open the inset, and move the current selection
1220 doInsertInset(cur, this, cmd, true, true);
1222 updateLabels(*bv->buffer());
1224 case LFUN_NOTE_INSERT:
1225 case LFUN_CHARSTYLE_INSERT:
1226 case LFUN_BOX_INSERT:
1227 case LFUN_BRANCH_INSERT:
1228 case LFUN_BIBITEM_INSERT:
1229 case LFUN_ERT_INSERT:
1230 case LFUN_LISTING_INSERT:
1231 case LFUN_FOOTNOTE_INSERT:
1232 case LFUN_MARGINALNOTE_INSERT:
1233 case LFUN_OPTIONAL_INSERT:
1234 case LFUN_ENVIRONMENT_INSERT:
1235 // Open the inset, and move the current selection
1237 doInsertInset(cur, this, cmd, true, true);
1241 case LFUN_TABULAR_INSERT:
1242 // if there were no arguments, just open the dialog
1243 if (doInsertInset(cur, this, cmd, false, true))
1246 bv->showDialog("tabularcreate");
1250 case LFUN_FLOAT_INSERT:
1251 case LFUN_FLOAT_WIDE_INSERT:
1252 case LFUN_WRAP_INSERT: {
1253 bool content = cur.selection(); // will some text be moved into the inset?
1255 doInsertInset(cur, this, cmd, true, true);
1257 ParagraphList & pars = cur.text()->paragraphs();
1259 TextClass const & tclass = bv->buffer()->params().getTextClass();
1261 // add a separate paragraph for the caption inset
1262 pars.push_back(Paragraph());
1263 pars.back().setInsetOwner(pars[0].inInset());
1264 pars.back().layout(tclass.defaultLayout());
1266 int cap_pit = pars.size() - 1;
1268 // if an empty inset was created, we create an additional empty
1269 // paragraph at the bottom so that the user can choose where to put
1270 // the graphics (or table).
1272 pars.push_back(Paragraph());
1273 pars.back().setInsetOwner(pars[0].inInset());
1274 pars.back().layout(tclass.defaultLayout());
1278 // reposition the cursor to the caption
1279 cur.pit() = cap_pit;
1281 cur.dispatch(FuncRequest(LFUN_CAPTION_INSERT));
1282 // FIXME: When leaving the Float (or Wrap) inset we should
1283 // delete any empty paragraph left above or below the
1288 case LFUN_INDEX_INSERT:
1289 case LFUN_NOMENCL_INSERT: {
1290 Inset * inset = createInset(&cur.bv(), cmd);
1294 cur.clearSelection();
1295 insertInset(cur, inset);
1296 inset->edit(cur, true);
1297 // Show the dialog for the nomenclature entry, since the
1298 // description entry still needs to be filled in.
1299 if (cmd.action == LFUN_NOMENCL_INSERT)
1300 InsetCommandMailer("nomenclature",
1301 *reinterpret_cast<InsetCommand *>(inset)).showDialog(&cur.bv());
1306 case LFUN_INDEX_PRINT:
1307 case LFUN_NOMENCL_PRINT:
1308 case LFUN_TOC_INSERT:
1309 case LFUN_HFILL_INSERT:
1310 case LFUN_LINE_INSERT:
1311 case LFUN_PAGEBREAK_INSERT:
1312 case LFUN_CLEARPAGE_INSERT:
1313 case LFUN_CLEARDOUBLEPAGE_INSERT:
1315 doInsertInset(cur, this, cmd, false, false);
1319 case LFUN_DEPTH_DECREMENT:
1320 changeDepth(cur, DEC_DEPTH);
1323 case LFUN_DEPTH_INCREMENT:
1324 changeDepth(cur, INC_DEPTH);
1327 case LFUN_MATH_DISPLAY:
1328 mathDispatch(cur, cmd, true);
1331 case LFUN_MATH_IMPORT_SELECTION:
1332 case LFUN_MATH_MODE:
1333 if (cmd.argument() == "on")
1334 // don't pass "on" as argument
1335 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1337 mathDispatch(cur, cmd, false);
1340 case LFUN_MATH_MACRO:
1341 if (cmd.argument().empty())
1342 cur.errorMessage(from_utf8(N_("Missing argument")));
1344 string s = to_utf8(cmd.argument());
1345 string const s1 = token(s, ' ', 1);
1346 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1347 string const s2 = token(s, ' ', 2);
1348 string const type = s2.empty() ? "newcommand" : s2;
1349 cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, from_utf8(type)));
1350 //cur.nextInset()->edit(cur, true);
1354 // passthrough hat and underscore outside mathed:
1355 case LFUN_MATH_SUBSCRIPT:
1356 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1358 case LFUN_MATH_SUPERSCRIPT:
1359 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1362 case LFUN_MATH_INSERT:
1363 case LFUN_MATH_MATRIX:
1364 case LFUN_MATH_DELIM:
1365 case LFUN_MATH_BIGDELIM: {
1366 cur.insert(new InsetMathHull(hullSimple));
1367 checkAndActivateInset(cur, true);
1368 BOOST_ASSERT(cur.inMathed());
1373 case LFUN_FONT_EMPH: {
1374 Font font(Font::ALL_IGNORE);
1375 font.setEmph(Font::TOGGLE);
1376 toggleAndShow(cur, this, font);
1380 case LFUN_FONT_BOLD: {
1381 Font font(Font::ALL_IGNORE);
1382 font.setSeries(Font::BOLD_SERIES);
1383 toggleAndShow(cur, this, font);
1387 case LFUN_FONT_NOUN: {
1388 Font font(Font::ALL_IGNORE);
1389 font.setNoun(Font::TOGGLE);
1390 toggleAndShow(cur, this, font);
1394 case LFUN_FONT_CODE: {
1395 Font font(Font::ALL_IGNORE);
1396 font.setFamily(Font::TYPEWRITER_FAMILY); // no good
1397 toggleAndShow(cur, this, font);
1401 case LFUN_FONT_SANS: {
1402 Font font(Font::ALL_IGNORE);
1403 font.setFamily(Font::SANS_FAMILY);
1404 toggleAndShow(cur, this, font);
1408 case LFUN_FONT_ROMAN: {
1409 Font font(Font::ALL_IGNORE);
1410 font.setFamily(Font::ROMAN_FAMILY);
1411 toggleAndShow(cur, this, font);
1415 case LFUN_FONT_DEFAULT: {
1416 Font font(Font::ALL_INHERIT, ignore_language);
1417 toggleAndShow(cur, this, font);
1421 case LFUN_FONT_UNDERLINE: {
1422 Font font(Font::ALL_IGNORE);
1423 font.setUnderbar(Font::TOGGLE);
1424 toggleAndShow(cur, this, font);
1428 case LFUN_FONT_SIZE: {
1429 Font font(Font::ALL_IGNORE);
1430 font.setLyXSize(to_utf8(cmd.argument()));
1431 toggleAndShow(cur, this, font);
1435 case LFUN_LANGUAGE: {
1436 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1439 Font font(Font::ALL_IGNORE);
1440 font.setLanguage(lang);
1441 toggleAndShow(cur, this, font);
1445 case LFUN_FONT_FREE_APPLY:
1446 toggleAndShow(cur, this, freefont, toggleall);
1447 cur.message(_("Character set"));
1450 // Set the freefont using the contents of \param data dispatched from
1451 // the frontends and apply it at the current cursor location.
1452 case LFUN_FONT_FREE_UPDATE: {
1455 if (bv_funcs::string2font(to_utf8(cmd.argument()), font, toggle)) {
1458 toggleAndShow(cur, this, freefont, toggleall);
1459 cur.message(_("Character set"));
1464 case LFUN_FINISHED_LEFT:
1465 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1466 if (reverseDirectionNeeded(cur))
1470 case LFUN_FINISHED_RIGHT:
1471 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1472 if (!reverseDirectionNeeded(cur))
1476 case LFUN_LAYOUT_PARAGRAPH: {
1478 params2string(cur.paragraph(), data);
1479 data = "show\n" + data;
1480 bv->showDialogWithData("paragraph", data);
1484 case LFUN_PARAGRAPH_UPDATE: {
1486 params2string(cur.paragraph(), data);
1488 // Will the paragraph accept changes from the dialog?
1489 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1491 data = "update " + convert<string>(accept) + '\n' + data;
1492 bv->updateDialog("paragraph", data);
1496 case LFUN_ACCENT_UMLAUT:
1497 case LFUN_ACCENT_CIRCUMFLEX:
1498 case LFUN_ACCENT_GRAVE:
1499 case LFUN_ACCENT_ACUTE:
1500 case LFUN_ACCENT_TILDE:
1501 case LFUN_ACCENT_CEDILLA:
1502 case LFUN_ACCENT_MACRON:
1503 case LFUN_ACCENT_DOT:
1504 case LFUN_ACCENT_UNDERDOT:
1505 case LFUN_ACCENT_UNDERBAR:
1506 case LFUN_ACCENT_CARON:
1507 case LFUN_ACCENT_SPECIAL_CARON:
1508 case LFUN_ACCENT_BREVE:
1509 case LFUN_ACCENT_TIE:
1510 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1511 case LFUN_ACCENT_CIRCLE:
1512 case LFUN_ACCENT_OGONEK:
1513 theLyXFunc().handleKeyFunc(cmd.action);
1514 if (!cmd.argument().empty())
1515 // FIXME: Are all these characters encoded in one byte in utf8?
1516 bv->translateAndInsert(cmd.argument()[0], this, cur);
1519 case LFUN_FLOAT_LIST: {
1520 TextClass const & tclass = bv->buffer()->params().getTextClass();
1521 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1522 // not quite sure if we want this...
1524 cur.clearSelection();
1525 breakParagraph(cur);
1527 if (cur.lastpos() != 0) {
1529 breakParagraph(cur);
1532 setLayout(cur, tclass.defaultLayoutName());
1533 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, docstring(), 0);
1534 insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1537 lyxerr << "Non-existent float type: "
1538 << to_utf8(cmd.argument()) << endl;
1543 case LFUN_CHANGE_ACCEPT: {
1544 acceptOrRejectChanges(cur, ACCEPT);
1548 case LFUN_CHANGE_REJECT: {
1549 acceptOrRejectChanges(cur, REJECT);
1553 case LFUN_THESAURUS_ENTRY: {
1554 docstring arg = cmd.argument();
1556 arg = cur.selectionAsString(false);
1558 if (arg.size() > 100 || arg.empty()) {
1559 // Get word or selection
1560 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1561 arg = cur.selectionAsString(false);
1564 bv->showDialogWithData("thesaurus", to_utf8(arg));
1568 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1569 // Given data, an encoding of the ParagraphParameters
1570 // generated in the Paragraph dialog, this function sets
1571 // the current paragraph appropriately.
1572 istringstream is(to_utf8(cmd.argument()));
1575 ParagraphParameters params;
1580 params.labelWidthString(),
1582 cur.message(_("Paragraph layout set"));
1587 if (cur.selection()) {
1588 cur.selection() = false;
1592 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1597 LYXERR(Debug::ACTION)
1598 << BOOST_CURRENT_FUNCTION
1599 << ": Command " << cmd
1600 << " not DISPATCHED by Text" << endl;
1605 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1607 // FIXME: The cursor flag is reset two lines below
1608 // so we need to check here if some of the LFUN did touch that.
1609 // for now only Text::erase() and Text::backspace() do that.
1610 // The plan is to verify all the LFUNs and then to remove this
1611 // singleParUpdate boolean altogether.
1612 if (cur.result().update() & Update::Force) {
1613 singleParUpdate = false;
1617 // FIXME: the following code should go in favor of fine grained
1618 // update flag treatment.
1619 if (singleParUpdate) {
1620 // Inserting characters does not change par height
1621 ParagraphMetrics const & pms
1622 = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
1623 if (pms.dim().height()
1624 == olddim.height()) {
1625 // if so, update _only_ this paragraph
1626 cur.updateFlags(Update::SinglePar |
1628 Update::MultiParSel);
1635 && &oldTopSlice.inset() == &cur.inset()
1636 && oldTopSlice.idx() == cur.idx()
1637 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1638 && !cur.selection())
1639 // FIXME: it would be better if we could just do this
1641 //if (cur.result().update() != Update::FitCursor)
1644 // But some LFUNs do not set Update::FitCursor when needed, so we
1645 // do it for all. This is not very harmfull as FitCursor will provoke
1646 // a full redraw only if needed but still, a proper review of all LFUN
1647 // should be done and this needsUpdate boolean can then be removed.
1648 cur.updateFlags(Update::FitCursor);
1650 cur.updateFlags(Update::Force | Update::FitCursor);
1654 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
1655 FuncStatus & flag) const
1657 BOOST_ASSERT(cur.text() == this);
1659 Font const & font = real_current_font;
1661 Inset::Code code = Inset::NO_CODE;
1663 switch (cmd.action) {
1665 case LFUN_DEPTH_DECREMENT:
1666 enable = changeDepthAllowed(cur, DEC_DEPTH);
1669 case LFUN_DEPTH_INCREMENT:
1670 enable = changeDepthAllowed(cur, INC_DEPTH);
1674 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1677 case LFUN_BIBITEM_INSERT:
1678 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO
1682 case LFUN_DIALOG_SHOW_NEW_INSET:
1683 if (cmd.argument() == "bibitem")
1684 code = Inset::BIBITEM_CODE;
1685 else if (cmd.argument() == "bibtex")
1686 code = Inset::BIBTEX_CODE;
1687 else if (cmd.argument() == "box")
1688 code = Inset::BOX_CODE;
1689 else if (cmd.argument() == "branch")
1690 code = Inset::BRANCH_CODE;
1691 else if (cmd.argument() == "citation")
1692 code = Inset::CITE_CODE;
1693 else if (cmd.argument() == "ert")
1694 code = Inset::ERT_CODE;
1695 else if (cmd.argument() == "external")
1696 code = Inset::EXTERNAL_CODE;
1697 else if (cmd.argument() == "float")
1698 code = Inset::FLOAT_CODE;
1699 else if (cmd.argument() == "graphics")
1700 code = Inset::GRAPHICS_CODE;
1701 else if (cmd.argument() == "include")
1702 code = Inset::INCLUDE_CODE;
1703 else if (cmd.argument() == "index")
1704 code = Inset::INDEX_CODE;
1705 else if (cmd.argument() == "nomenclature")
1706 code = Inset::NOMENCL_CODE;
1707 else if (cmd.argument() == "label")
1708 code = Inset::LABEL_CODE;
1709 else if (cmd.argument() == "note")
1710 code = Inset::NOTE_CODE;
1711 else if (cmd.argument() == "ref")
1712 code = Inset::REF_CODE;
1713 else if (cmd.argument() == "toc")
1714 code = Inset::TOC_CODE;
1715 else if (cmd.argument() == "url")
1716 code = Inset::URL_CODE;
1717 else if (cmd.argument() == "vspace")
1718 code = Inset::VSPACE_CODE;
1719 else if (cmd.argument() == "wrap")
1720 code = Inset::WRAP_CODE;
1721 else if (cmd.argument() == "listings")
1722 code = Inset::LISTINGS_CODE;
1725 case LFUN_ERT_INSERT:
1726 code = Inset::ERT_CODE;
1728 case LFUN_LISTING_INSERT:
1729 code = Inset::LISTINGS_CODE;
1731 case LFUN_FOOTNOTE_INSERT:
1732 code = Inset::FOOT_CODE;
1734 case LFUN_TABULAR_INSERT:
1735 code = Inset::TABULAR_CODE;
1737 case LFUN_MARGINALNOTE_INSERT:
1738 code = Inset::MARGIN_CODE;
1740 case LFUN_FLOAT_INSERT:
1741 case LFUN_FLOAT_WIDE_INSERT:
1742 code = Inset::FLOAT_CODE;
1744 case LFUN_WRAP_INSERT:
1745 code = Inset::WRAP_CODE;
1747 case LFUN_FLOAT_LIST:
1748 code = Inset::FLOAT_LIST_CODE;
1751 case LFUN_LIST_INSERT:
1752 code = Inset::LIST_CODE;
1754 case LFUN_THEOREM_INSERT:
1755 code = Inset::THEOREM_CODE;
1758 case LFUN_CAPTION_INSERT:
1759 code = Inset::CAPTION_CODE;
1761 case LFUN_NOTE_INSERT:
1762 code = Inset::NOTE_CODE;
1764 case LFUN_CHARSTYLE_INSERT:
1765 code = Inset::CHARSTYLE_CODE;
1766 if (cur.buffer().params().getTextClass().charstyles().empty())
1769 case LFUN_BOX_INSERT:
1770 code = Inset::BOX_CODE;
1772 case LFUN_BRANCH_INSERT:
1773 code = Inset::BRANCH_CODE;
1774 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1777 case LFUN_LABEL_INSERT:
1778 code = Inset::LABEL_CODE;
1780 case LFUN_OPTIONAL_INSERT:
1781 code = Inset::OPTARG_CODE;
1782 enable = numberOfOptArgs(cur.paragraph())
1783 < cur.paragraph().layout()->optionalargs;
1785 case LFUN_ENVIRONMENT_INSERT:
1786 code = Inset::BOX_CODE;
1788 case LFUN_INDEX_INSERT:
1789 code = Inset::INDEX_CODE;
1791 case LFUN_INDEX_PRINT:
1792 code = Inset::INDEX_PRINT_CODE;
1794 case LFUN_NOMENCL_INSERT:
1795 code = Inset::NOMENCL_CODE;
1797 case LFUN_NOMENCL_PRINT:
1798 code = Inset::NOMENCL_PRINT_CODE;
1800 case LFUN_TOC_INSERT:
1801 code = Inset::TOC_CODE;
1803 case LFUN_HTML_INSERT:
1804 case LFUN_URL_INSERT:
1805 code = Inset::URL_CODE;
1807 case LFUN_QUOTE_INSERT:
1808 // always allow this, since we will inset a raw quote
1809 // if an inset is not allowed.
1811 case LFUN_HYPHENATION_POINT_INSERT:
1812 case LFUN_LIGATURE_BREAK_INSERT:
1813 case LFUN_HFILL_INSERT:
1814 case LFUN_MENU_SEPARATOR_INSERT:
1815 case LFUN_DOTS_INSERT:
1816 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
1817 code = Inset::SPECIALCHAR_CODE;
1819 case LFUN_SPACE_INSERT:
1820 // slight hack: we know this is allowed in math mode
1822 code = Inset::SPACE_CODE;
1825 case LFUN_INSET_MODIFY:
1826 // We need to disable this, because we may get called for a
1828 // InsetTabular::getStatus() -> InsetText::getStatus()
1829 // and we don't handle LFUN_INSET_MODIFY.
1833 case LFUN_FONT_EMPH:
1834 flag.setOnOff(font.emph() == Font::ON);
1837 case LFUN_FONT_NOUN:
1838 flag.setOnOff(font.noun() == Font::ON);
1841 case LFUN_FONT_BOLD:
1842 flag.setOnOff(font.series() == Font::BOLD_SERIES);
1845 case LFUN_FONT_SANS:
1846 flag.setOnOff(font.family() == Font::SANS_FAMILY);
1849 case LFUN_FONT_ROMAN:
1850 flag.setOnOff(font.family() == Font::ROMAN_FAMILY);
1853 case LFUN_FONT_CODE:
1854 flag.setOnOff(font.family() == Font::TYPEWRITER_FAMILY);
1859 enable = cur.selection();
1863 if (cmd.argument().empty()) {
1864 if (theClipboard().isInternal())
1865 enable = cap::numberOfSelections() > 0;
1867 enable = !theClipboard().empty();
1869 string const arg = to_utf8(cmd.argument());
1870 if (isStrUnsignedInt(arg)) {
1871 unsigned int n = convert<unsigned int>(arg);
1872 enable = cap::numberOfSelections() > n;
1879 case LFUN_CLIPBOARD_PASTE:
1880 enable = !theClipboard().empty();
1883 case LFUN_PRIMARY_SELECTION_PASTE:
1884 enable = cur.selection() || !theSelection().empty();
1887 case LFUN_PARAGRAPH_MOVE_UP:
1888 enable = cur.pit() > 0 && !cur.selection();
1891 case LFUN_PARAGRAPH_MOVE_DOWN:
1892 enable = cur.pit() < cur.lastpit() && !cur.selection();
1895 case LFUN_INSET_DISSOLVE:
1896 enable = !isMainText(*cur.bv().buffer()) && cur.inset().nargs() == 1;
1899 case LFUN_CHANGE_ACCEPT:
1900 case LFUN_CHANGE_REJECT:
1901 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
1902 // In principle, these LFUNs should only be enabled if there
1903 // is a change at the current position/in the current selection.
1904 // However, without proper optimizations, this will inevitably
1905 // result in unacceptable performance - just imagine a user who
1906 // wants to select the complete content of a long document.
1910 case LFUN_WORD_DELETE_FORWARD:
1911 case LFUN_WORD_DELETE_BACKWARD:
1912 case LFUN_LINE_DELETE:
1913 case LFUN_WORD_FORWARD:
1914 case LFUN_WORD_BACKWARD:
1915 case LFUN_CHAR_FORWARD:
1916 case LFUN_CHAR_FORWARD_SELECT:
1917 case LFUN_CHAR_BACKWARD:
1918 case LFUN_CHAR_BACKWARD_SELECT:
1920 case LFUN_UP_SELECT:
1922 case LFUN_DOWN_SELECT:
1923 case LFUN_PARAGRAPH_UP_SELECT:
1924 case LFUN_PARAGRAPH_DOWN_SELECT:
1925 case LFUN_SCREEN_UP_SELECT:
1926 case LFUN_SCREEN_DOWN_SELECT:
1927 case LFUN_LINE_BEGIN_SELECT:
1928 case LFUN_LINE_END_SELECT:
1929 case LFUN_WORD_FORWARD_SELECT:
1930 case LFUN_WORD_BACKWARD_SELECT:
1931 case LFUN_WORD_SELECT:
1932 case LFUN_PARAGRAPH_UP:
1933 case LFUN_PARAGRAPH_DOWN:
1934 case LFUN_SCREEN_UP:
1935 case LFUN_SCREEN_DOWN:
1936 case LFUN_LINE_BEGIN:
1938 case LFUN_BREAK_LINE:
1939 case LFUN_CHAR_DELETE_FORWARD:
1940 case LFUN_DELETE_FORWARD_SKIP:
1941 case LFUN_CHAR_DELETE_BACKWARD:
1942 case LFUN_DELETE_BACKWARD_SKIP:
1943 case LFUN_BREAK_PARAGRAPH:
1944 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
1945 case LFUN_BREAK_PARAGRAPH_SKIP:
1946 case LFUN_PARAGRAPH_SPACING:
1947 case LFUN_INSET_INSERT:
1948 case LFUN_WORD_UPCASE:
1949 case LFUN_WORD_LOWCASE:
1950 case LFUN_WORD_CAPITALIZE:
1951 case LFUN_CHARS_TRANSPOSE:
1952 case LFUN_SERVER_GET_XY:
1953 case LFUN_SERVER_SET_XY:
1954 case LFUN_SERVER_GET_FONT:
1955 case LFUN_SERVER_GET_LAYOUT:
1957 case LFUN_DATE_INSERT:
1958 case LFUN_SELF_INSERT:
1959 case LFUN_LINE_INSERT:
1960 case LFUN_PAGEBREAK_INSERT:
1961 case LFUN_CLEARPAGE_INSERT:
1962 case LFUN_CLEARDOUBLEPAGE_INSERT:
1963 case LFUN_MATH_DISPLAY:
1964 case LFUN_MATH_IMPORT_SELECTION:
1965 case LFUN_MATH_MODE:
1966 case LFUN_MATH_MACRO:
1967 case LFUN_MATH_MATRIX:
1968 case LFUN_MATH_DELIM:
1969 case LFUN_MATH_BIGDELIM:
1970 case LFUN_MATH_SUBSCRIPT:
1971 case LFUN_MATH_SUPERSCRIPT:
1972 case LFUN_FONT_DEFAULT:
1973 case LFUN_FONT_UNDERLINE:
1974 case LFUN_FONT_SIZE:
1976 case LFUN_FONT_FREE_APPLY:
1977 case LFUN_FONT_FREE_UPDATE:
1978 case LFUN_LAYOUT_PARAGRAPH:
1979 case LFUN_PARAGRAPH_UPDATE:
1980 case LFUN_ACCENT_UMLAUT:
1981 case LFUN_ACCENT_CIRCUMFLEX:
1982 case LFUN_ACCENT_GRAVE:
1983 case LFUN_ACCENT_ACUTE:
1984 case LFUN_ACCENT_TILDE:
1985 case LFUN_ACCENT_CEDILLA:
1986 case LFUN_ACCENT_MACRON:
1987 case LFUN_ACCENT_DOT:
1988 case LFUN_ACCENT_UNDERDOT:
1989 case LFUN_ACCENT_UNDERBAR:
1990 case LFUN_ACCENT_CARON:
1991 case LFUN_ACCENT_SPECIAL_CARON:
1992 case LFUN_ACCENT_BREVE:
1993 case LFUN_ACCENT_TIE:
1994 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1995 case LFUN_ACCENT_CIRCLE:
1996 case LFUN_ACCENT_OGONEK:
1997 case LFUN_THESAURUS_ENTRY:
1998 case LFUN_PARAGRAPH_PARAMS_APPLY:
2000 case LFUN_BUFFER_END:
2001 case LFUN_BUFFER_BEGIN:
2002 case LFUN_BUFFER_BEGIN_SELECT:
2003 case LFUN_BUFFER_END_SELECT:
2004 case LFUN_UNICODE_INSERT:
2005 // these are handled in our dispatch()
2013 if (code != Inset::NO_CODE
2014 && (cur.empty() || !cur.inset().insetAllowed(code)))
2017 flag.enabled(enable);
2022 void Text::pasteString(Cursor & cur, docstring const & clip,
2025 cur.clearSelection();
2026 if (!clip.empty()) {
2029 insertStringAsParagraphs(cur, clip);
2031 insertStringAsLines(cur, clip);