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;
103 void toggleAndShow(Cursor & cur, Text * text,
104 Font const & font, bool toggleall = true)
106 text->toggleFree(cur, font, toggleall);
108 if (font.language() != ignore_language ||
109 font.number() != Font::IGNORE) {
110 Paragraph & par = cur.paragraph();
111 text->bidi.computeTables(par, cur.buffer(), cur.textRow());
112 if (cur.boundary() !=
113 text->bidi.isBoundary(cur.buffer(), par,
115 text->real_current_font))
116 text->setCursor(cur, cur.pit(), cur.pos(),
117 false, !cur.boundary());
122 void moveCursor(Cursor & cur, bool selecting)
124 if (selecting || cur.mark())
127 cur.bv().switchKeyMap();
131 void finishChange(Cursor & cur, bool selecting)
134 moveCursor(cur, selecting);
138 void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
141 docstring sel = cur.selectionAsString(false);
143 // It may happen that sel is empty but there is a selection
144 replaceSelection(cur);
147 #ifdef ENABLE_ASSERTIONS
148 const int old_pos = cur.pos();
150 cur.insert(new InsetMathHull(hullSimple));
151 BOOST_ASSERT(old_pos == cur.pos());
152 cur.nextInset()->edit(cur, true);
153 // don't do that also for LFUN_MATH_MODE
154 // unless you want end up with always changing
155 // to mathrm when opening an inlined inset --
156 // I really hate "LyXfunc overloading"...
158 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
159 // Avoid an unnecessary undo step if cmd.argument
161 if (!cmd.argument().empty())
162 cur.dispatch(FuncRequest(LFUN_MATH_INSERT,
165 // create a macro if we see "\\newcommand"
166 // somewhere, and an ordinary formula
168 if (sel.find(from_ascii("\\newcommand")) == string::npos
169 && sel.find(from_ascii("\\def")) == string::npos)
171 InsetMathHull * formula = new InsetMathHull;
172 istringstream is(to_utf8(sel));
175 formula->read(cur.buffer(), lex);
176 if (formula->getType() == hullNone)
177 // Don't create pseudo formulas if
178 // delimiters are left out
179 formula->mutate(hullSimple);
182 cur.insert(new MathMacroTemplate(sel));
185 cur.message(from_utf8(N_("Math editor mode")));
194 string const freefont2string()
197 if (font2string(freefont, toggleall, data))
204 void Text::cursorPrevious(Cursor & cur)
206 pos_type cpos = cur.pos();
207 pit_type cpar = cur.pit();
209 int x = cur.x_target();
210 setCursorFromCoordinates(cur, x, 0);
211 cur.dispatch(FuncRequest(cur.selection()? LFUN_UP_SELECT: LFUN_UP));
213 if (cpar == cur.pit() && cpos == cur.pos())
214 // we have a row which is taller than the workarea. The
215 // simplest solution is to move to the previous row instead.
216 cur.dispatch(FuncRequest(cur.selection()? LFUN_UP_SELECT: LFUN_UP));
219 cur.updateFlags(Update::Force | Update::FitCursor);
223 void Text::cursorNext(Cursor & cur)
225 pos_type cpos = cur.pos();
226 pit_type cpar = cur.pit();
228 int x = cur.x_target();
229 setCursorFromCoordinates(cur, x, cur.bv().workHeight() - 1);
230 cur.dispatch(FuncRequest(cur.selection()? LFUN_DOWN_SELECT: LFUN_DOWN));
232 if (cpar == cur.pit() && cpos == cur.pos())
233 // we have a row which is taller than the workarea. The
234 // simplest solution is to move to the next row instead.
236 FuncRequest(cur.selection()? LFUN_DOWN_SELECT: LFUN_DOWN));
239 cur.updateFlags(Update::Force | Update::FitCursor);
245 void specialChar(Cursor & cur, InsetSpecialChar::Kind kind)
248 cap::replaceSelection(cur);
249 cur.insert(new InsetSpecialChar(kind));
254 bool doInsertInset(Cursor & cur, Text * text,
255 FuncRequest const & cmd, bool edit, bool pastesel)
257 Inset * inset = createInset(&cur.bv(), cmd);
263 if (cur.selection()) {
264 lyx::dispatch(FuncRequest(LFUN_CUT));
267 text->insertInset(cur, inset);
270 inset->edit(cur, true);
272 if (gotsel && pastesel) {
273 lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
274 // reset first par to default
275 if (cur.lastpit() != 0 || cur.lastpos() != 0) {
276 Layout_ptr const layout =
277 cur.buffer().params().getTextClass().defaultLayout();
278 cur.text()->paragraphs().begin()->layout(layout);
288 void Text::number(Cursor & cur)
290 Font font(Font::ALL_IGNORE);
291 font.setNumber(Font::TOGGLE);
292 toggleAndShow(cur, this, font);
296 bool Text::isRTL(Buffer const & buffer, Paragraph const & par) const
298 return par.isRightToLeftPar(buffer.params());
302 void Text::dispatch(Cursor & cur, FuncRequest & cmd)
304 LYXERR(Debug::ACTION) << "Text::dispatch: cmd: " << cmd << endl;
306 // FIXME: We use the update flag to indicates wether a singlePar or a
307 // full screen update is needed. We reset it here but shall we restore it
311 BOOST_ASSERT(cur.text() == this);
312 BufferView * bv = &cur.bv();
313 CursorSlice oldTopSlice = cur.top();
314 bool oldBoundary = cur.boundary();
315 bool sel = cur.selection();
316 // Signals that, even if needsUpdate == false, an update of the
317 // cursor paragraph is required
318 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
319 LyXAction::SingleParUpdate);
320 // Signals that a full-screen update is required
321 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
322 LyXAction::NoUpdate) || singleParUpdate);
323 // Remember the old paragraph metric (_outer_ paragraph!)
324 ParagraphMetrics const & pm = cur.bv().parMetrics(
325 cur.bottom().text(), cur.bottom().pit());
326 Dimension olddim = pm.dim();
328 switch (cmd.action) {
330 case LFUN_PARAGRAPH_MOVE_DOWN: {
331 pit_type const pit = cur.pit();
332 recUndo(cur, pit, pit + 1);
334 std::swap(pars_[pit], pars_[pit + 1]);
336 ParIterator begin(cur);
337 // begin.pos() (== cur.pos()) may point beyond the end of the
338 // paragraph referenced by begin. This would cause a crash
342 ParIterator end = boost::next(ParIterator(cur));
343 updateLabels(cur.buffer(), begin, end);
349 case LFUN_PARAGRAPH_MOVE_UP: {
350 pit_type const pit = cur.pit();
351 recUndo(cur, pit - 1, pit);
353 std::swap(pars_[pit], pars_[pit - 1]);
355 ParIterator end = ParIterator(cur);
356 // end.pos() (== cur.pos()) may point beyond the end of the
357 // paragraph referenced by end. This would cause a crash
360 end = boost::next(end);
362 ParIterator begin(cur);
363 updateLabels(cur.buffer(), begin, end);
369 case LFUN_APPENDIX: {
370 Paragraph & par = cur.paragraph();
371 bool start = !par.params().startOfAppendix();
374 #warning The code below only makes sense at top level.
375 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
377 // ensure that we have only one start_of_appendix in this document
378 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
379 if (pars_[tmp].params().startOfAppendix()) {
381 pars_[tmp].params().startOfAppendix(false);
387 par.params().startOfAppendix(start);
389 // we can set the refreshing parameters now
390 updateLabels(cur.buffer());
394 case LFUN_WORD_DELETE_FORWARD:
395 cur.clearSelection();
396 deleteWordForward(cur);
397 finishChange(cur, false);
400 case LFUN_WORD_DELETE_BACKWARD:
401 cur.clearSelection();
402 deleteWordBackward(cur);
403 finishChange(cur, false);
406 case LFUN_LINE_DELETE:
407 cur.clearSelection();
408 deleteLineForward(cur);
409 finishChange(cur, false);
412 case LFUN_BUFFER_BEGIN:
413 case LFUN_BUFFER_BEGIN_SELECT:
414 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
415 if (cur.depth() == 1) {
416 needsUpdate |= cursorTop(cur);
422 case LFUN_BUFFER_END:
423 case LFUN_BUFFER_END_SELECT:
424 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
425 if (cur.depth() == 1) {
426 needsUpdate |= cursorBottom(cur);
432 case LFUN_CHAR_FORWARD:
433 case LFUN_CHAR_FORWARD_SELECT:
434 //lyxerr << BOOST_CURRENT_FUNCTION
435 // << " LFUN_CHAR_FORWARD[SEL]:\n" << cur << endl;
436 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
437 if (reverseDirectionNeeded(cur))
438 needsUpdate |= cursorLeft(cur);
440 needsUpdate |= cursorRight(cur);
442 if (!needsUpdate && oldTopSlice == cur.top()
443 && cur.boundary() == oldBoundary) {
445 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
451 case LFUN_CHAR_BACKWARD:
452 case LFUN_CHAR_BACKWARD_SELECT:
453 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
454 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
455 if (reverseDirectionNeeded(cur))
456 needsUpdate |= cursorRight(cur);
458 needsUpdate |= cursorLeft(cur);
460 if (!needsUpdate && oldTopSlice == cur.top()
461 && cur.boundary() == oldBoundary) {
463 cmd = FuncRequest(LFUN_FINISHED_LEFT);
471 //lyxerr << "handle LFUN_UP[SEL]:\n" << cur << endl;
472 needsUpdate |= cur.selHandle(cmd.action == LFUN_UP_SELECT);
474 needsUpdate |= cursorUp(cur);
476 if (!needsUpdate && oldTopSlice == cur.top()
477 && cur.boundary() == oldBoundary) {
479 cmd = FuncRequest(LFUN_FINISHED_UP);
486 case LFUN_DOWN_SELECT:
487 //lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
488 needsUpdate |= cur.selHandle(cmd.action == LFUN_DOWN_SELECT);
489 needsUpdate |= cursorDown(cur);
491 if (!needsUpdate && oldTopSlice == cur.top() &&
492 cur.boundary() == oldBoundary)
495 cmd = FuncRequest(LFUN_FINISHED_DOWN);
501 case LFUN_PARAGRAPH_UP:
502 case LFUN_PARAGRAPH_UP_SELECT:
503 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
504 needsUpdate |= cursorUpParagraph(cur);
509 case LFUN_PARAGRAPH_DOWN:
510 case LFUN_PARAGRAPH_DOWN_SELECT:
511 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
512 needsUpdate |= cursorDownParagraph(cur);
518 case LFUN_SCREEN_UP_SELECT:
519 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_UP_SELECT);
520 if (cur.pit() == 0 && cur.textRow().pos() == 0) {
522 cmd = FuncRequest(LFUN_FINISHED_UP);
530 case LFUN_SCREEN_DOWN:
531 case LFUN_SCREEN_DOWN_SELECT:
532 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_DOWN_SELECT);
533 if (cur.pit() == cur.lastpit()
534 && cur.textRow().endpos() == cur.lastpos()) {
536 cmd = FuncRequest(LFUN_FINISHED_DOWN);
544 case LFUN_LINE_BEGIN:
545 case LFUN_LINE_BEGIN_SELECT:
546 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
547 needsUpdate |= cursorHome(cur);
551 case LFUN_LINE_END_SELECT:
552 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
553 needsUpdate |= cursorEnd(cur);
558 case LFUN_WORD_FORWARD:
559 case LFUN_WORD_FORWARD_SELECT:
560 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
561 if (reverseDirectionNeeded(cur))
562 needsUpdate |= cursorLeftOneWord(cur);
564 needsUpdate |= cursorRightOneWord(cur);
569 case LFUN_WORD_BACKWARD:
570 case LFUN_WORD_BACKWARD_SELECT:
571 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
572 if (reverseDirectionNeeded(cur))
573 needsUpdate |= cursorRightOneWord(cur);
575 needsUpdate |= cursorLeftOneWord(cur);
580 case LFUN_WORD_SELECT: {
581 selectWord(cur, WHOLE_WORD);
582 finishChange(cur, true);
586 case LFUN_BREAK_LINE: {
587 // Not allowed by LaTeX (labels or empty par)
588 if (cur.pos() > cur.paragraph().beginOfBody()) {
589 // this avoids a double undo
590 // FIXME: should not be needed, ideally
591 if (!cur.selection())
593 cap::replaceSelection(cur);
594 cur.insert(new InsetNewline);
596 moveCursor(cur, false);
601 case LFUN_CHAR_DELETE_FORWARD:
602 if (!cur.selection()) {
603 if (cur.pos() == cur.paragraph().size())
604 // Par boundary, force full-screen update
605 singleParUpdate = false;
606 needsUpdate |= erase(cur);
608 // It is possible to make it a lot faster still
609 // just comment out the line below...
611 cutSelection(cur, true, false);
612 singleParUpdate = false;
614 moveCursor(cur, false);
617 case LFUN_DELETE_FORWARD_SKIP:
618 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
619 if (!cur.selection()) {
620 if (cur.pos() == cur.lastpos()) {
627 cutSelection(cur, true, false);
632 case LFUN_CHAR_DELETE_BACKWARD:
633 if (!cur.selection()) {
634 if (bv->getIntl().getTransManager().backspace()) {
635 // Par boundary, full-screen update
637 singleParUpdate = false;
638 needsUpdate |= backspace(cur);
640 // It is possible to make it a lot faster still
641 // just comment out the line below...
644 cutSelection(cur, true, false);
645 singleParUpdate = false;
650 case LFUN_DELETE_BACKWARD_SKIP:
651 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
652 if (!cur.selection()) {
656 //CursorSlice cur = cursor();
660 cutSelection(cur, true, false);
664 case LFUN_BREAK_PARAGRAPH:
665 cap::replaceSelection(cur);
666 breakParagraph(cur, 0);
671 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
672 cap::replaceSelection(cur);
673 breakParagraph(cur, 1);
678 case LFUN_BREAK_PARAGRAPH_SKIP: {
679 // When at the beginning of a paragraph, remove
680 // indentation. Otherwise, do the same as LFUN_BREAK_PARAGRAPH.
681 cap::replaceSelection(cur);
683 cur.paragraph().params().labelWidthString(docstring());
685 breakParagraph(cur, 0);
691 case LFUN_PARAGRAPH_SPACING: {
692 Paragraph & par = cur.paragraph();
693 Spacing::Space cur_spacing = par.params().spacing().getSpace();
694 string cur_value = "1.0";
695 if (cur_spacing == Spacing::Other)
696 cur_value = par.params().spacing().getValueAsString();
698 istringstream is(to_utf8(cmd.argument()));
701 Spacing::Space new_spacing = cur_spacing;
702 string new_value = cur_value;
704 lyxerr << "Missing argument to `paragraph-spacing'"
706 } else if (tmp == "single") {
707 new_spacing = Spacing::Single;
708 } else if (tmp == "onehalf") {
709 new_spacing = Spacing::Onehalf;
710 } else if (tmp == "double") {
711 new_spacing = Spacing::Double;
712 } else if (tmp == "other") {
713 new_spacing = Spacing::Other;
714 string tmpval = "0.0";
716 lyxerr << "new_value = " << tmpval << endl;
719 } else if (tmp == "default") {
720 new_spacing = Spacing::Default;
722 lyxerr << to_utf8(_("Unknown spacing argument: "))
723 << to_utf8(cmd.argument()) << endl;
725 if (cur_spacing != new_spacing || cur_value != new_value)
726 par.params().spacing(Spacing(new_spacing, new_value));
730 case LFUN_INSET_INSERT: {
732 Inset * inset = createInset(bv, cmd);
734 // FIXME (Abdel 01/02/2006):
735 // What follows would be a partial fix for bug 2154:
736 // http://bugzilla.lyx.org/show_bug.cgi?id=2154
737 // This automatically put the label inset _after_ a
738 // numbered section. It should be possible to extend the mechanism
739 // to any kind of LateX environement.
740 // The correct way to fix that bug would be at LateX generation.
741 // I'll let the code here for reference as it could be used for some
742 // other feature like "automatic labelling".
744 Paragraph & par = pars_[cur.pit()];
745 if (inset->lyxCode() == Inset::LABEL_CODE
746 && par.layout()->labeltype == LABEL_COUNTER) {
747 // Go to the end of the paragraph
748 // Warning: Because of Change-Tracking, the last
749 // position is 'size()' and not 'size()-1':
750 cur.pos() = par.size();
751 // Insert a new paragraph
752 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
756 insertInset(cur, inset);
762 case LFUN_INSET_DISSOLVE:
763 needsUpdate |= dissolveInset(cur);
766 case LFUN_INSET_SETTINGS:
767 cur.inset().showInsetDialog(bv);
770 case LFUN_SPACE_INSERT:
771 if (cur.paragraph().layout()->free_spacing)
772 insertChar(cur, ' ');
774 doInsertInset(cur, this, cmd, false, false);
777 moveCursor(cur, false);
780 case LFUN_HYPHENATION_POINT_INSERT:
781 specialChar(cur, InsetSpecialChar::HYPHENATION);
784 case LFUN_LIGATURE_BREAK_INSERT:
785 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
788 case LFUN_DOTS_INSERT:
789 specialChar(cur, InsetSpecialChar::LDOTS);
792 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
793 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
796 case LFUN_MENU_SEPARATOR_INSERT:
797 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
800 case LFUN_WORD_UPCASE:
801 changeCase(cur, Text::text_uppercase);
804 case LFUN_WORD_LOWCASE:
805 changeCase(cur, Text::text_lowercase);
808 case LFUN_WORD_CAPITALIZE:
809 changeCase(cur, Text::text_capitalization);
812 case LFUN_CHARS_TRANSPOSE:
817 cur.message(_("Paste"));
818 cap::replaceSelection(cur);
819 if (cmd.argument().empty() && !theClipboard().isInternal())
820 pasteClipboard(cur, bv->buffer()->errorList("Paste"));
822 string const arg(to_utf8(cmd.argument()));
823 pasteFromStack(cur, bv->buffer()->errorList("Paste"),
824 isStrUnsignedInt(arg) ?
825 convert<unsigned int>(arg) :
828 bv->buffer()->errors("Paste");
829 cur.clearSelection(); // bug 393
835 cutSelection(cur, true, true);
836 cur.message(_("Cut"));
841 cur.message(_("Copy"));
844 case LFUN_SERVER_GET_XY:
845 cur.message(from_utf8(
846 convert<string>(cursorX(cur.bv(), cur.top(), cur.boundary()))
847 + ' ' + convert<string>(cursorY(cur.bv(), cur.top(), cur.boundary()))));
850 case LFUN_SERVER_SET_XY: {
853 istringstream is(to_utf8(cmd.argument()));
856 lyxerr << "SETXY: Could not parse coordinates in '"
857 << to_utf8(cmd.argument()) << std::endl;
859 setCursorFromCoordinates(cur, x, y);
863 case LFUN_SERVER_GET_FONT:
864 if (current_font.shape() == Font::ITALIC_SHAPE)
865 cur.message(from_ascii("E"));
866 else if (current_font.shape() == Font::SMALLCAPS_SHAPE)
867 cur.message(from_ascii("N"));
869 cur.message(from_ascii("0"));
872 case LFUN_SERVER_GET_LAYOUT:
873 cur.message(from_utf8(cur.paragraph().layout()->name()));
877 string layout = to_ascii(cmd.argument());
878 LYXERR(Debug::INFO) << "LFUN_LAYOUT: (arg) " << layout << endl;
880 // Derive layout number from given argument (string)
881 // and current buffer's textclass (number)
882 TextClass const & tclass = bv->buffer()->params().getTextClass();
884 layout = tclass.defaultLayoutName();
885 bool hasLayout = tclass.hasLayout(layout);
887 // If the entry is obsolete, use the new one instead.
889 string const & obs = tclass[layout]->obsoleted_by();
895 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
896 from_utf8(N_(" not known")));
900 bool change_layout = (current_layout != layout);
902 if (!change_layout && cur.selection() &&
903 cur.selBegin().pit() != cur.selEnd().pit())
905 pit_type spit = cur.selBegin().pit();
906 pit_type epit = cur.selEnd().pit() + 1;
907 while (spit != epit) {
908 if (pars_[spit].layout()->name() != current_layout) {
909 change_layout = true;
917 current_layout = layout;
918 setLayout(cur, layout);
919 // inform the GUI that the layout has changed.
920 bv->layoutChanged(layout);
926 case LFUN_CLIPBOARD_PASTE:
927 cur.clearSelection();
928 pasteClipboard(cur, bv->buffer()->errorList("Paste"),
929 cmd.argument() == "paragraph");
930 bv->buffer()->errors("Paste");
933 case LFUN_PRIMARY_SELECTION_PASTE:
934 pasteString(cur, theSelection().get(),
935 cmd.argument() == "paragraph");
938 case LFUN_UNICODE_INSERT: {
939 if (cmd.argument().empty())
941 docstring hexstring = cmd.argument();
942 if (lyx::support::isHex(hexstring)) {
943 char_type c = lyx::support::hexToInt(hexstring);
944 if (c > 32 && c < 0x10ffff) {
945 lyxerr << "Inserting c: " << c << endl;
946 docstring s = docstring(1, c);
947 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
953 case LFUN_QUOTE_INSERT: {
954 Paragraph & par = cur.paragraph();
955 pos_type pos = cur.pos();
956 BufferParams const & bufparams = bv->buffer()->params();
957 Layout_ptr const & style = par.layout();
958 if (!style->pass_thru
959 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
960 // this avoids a double undo
961 // FIXME: should not be needed, ideally
962 if (!cur.selection())
964 cap::replaceSelection(cur);
969 else if (cur.prevInset() && cur.prevInset()->isSpace())
972 c = par.getChar(pos - 1);
973 string arg = to_utf8(cmd.argument());
975 cur.insert(new InsetQuotes(c,
976 bufparams.quotes_language,
977 InsetQuotes::SingleQ));
979 cur.insert(new InsetQuotes(c,
980 bufparams.quotes_language,
981 InsetQuotes::DoubleQ));
985 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
989 case LFUN_DATE_INSERT:
990 if (cmd.argument().empty())
991 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
992 formatted_time(current_time())));
994 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
995 formatted_time(current_time(), to_utf8(cmd.argument()))));
998 case LFUN_MOUSE_TRIPLE:
999 if (cmd.button() == mouse_button::button1) {
1009 case LFUN_MOUSE_DOUBLE:
1010 if (cmd.button() == mouse_button::button1) {
1011 selectWord(cur, WHOLE_WORD_STRICT);
1016 // Single-click on work area
1017 case LFUN_MOUSE_PRESS: {
1018 // Right click on a footnote flag opens float menu
1019 if (cmd.button() == mouse_button::button3)
1020 cur.clearSelection();
1022 // Middle button press pastes if we have a selection
1023 // We do this here as if the selection was inside an inset
1024 // it could get cleared on the unlocking of the inset so
1025 // we have to check this first
1026 bool paste_internally = false;
1027 if (cmd.button() == mouse_button::button2 && cap::selection()) {
1028 // Copy the selection buffer to the clipboard
1029 // stack, because we want it to appear in the
1030 // "Edit->Paste recent" menu.
1031 cap::copySelectionToStack();
1032 paste_internally = true;
1035 // we have to update after dePM triggered
1036 bool update = bv->mouseSetCursor(cur);
1038 // Insert primary selection with middle mouse
1039 // if there is a local selection in the current buffer,
1041 if (cmd.button() == mouse_button::button2) {
1042 if (paste_internally) {
1043 cap::pasteSelection(cur, bv->buffer()->errorList("Paste"));
1044 bv->buffer()->errors("Paste");
1045 cur.clearSelection(); // bug 393
1049 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
1052 if (!update && cmd.button() == mouse_button::button1) {
1053 needsUpdate = false;
1060 case LFUN_MOUSE_MOTION: {
1061 // Only use motion with button 1
1062 //if (cmd.button() != mouse_button::button1)
1065 // ignore motions deeper nested than the real anchor
1066 Cursor & bvcur = cur.bv().cursor();
1067 if (bvcur.anchor_.hasPart(cur)) {
1068 CursorSlice old = bvcur.top();
1070 int const wh = bv->workHeight();
1071 int const y = std::max(0, std::min(wh - 1, cmd.y));
1073 setCursorFromCoordinates(cur, cmd.x, y);
1074 cur.x_target() = cmd.x;
1076 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1078 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1079 // This is to allow jumping over large insets
1080 if (cur.top() == old) {
1082 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1084 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1087 if (cur.top() == old)
1090 // don't set anchor_
1091 bvcur.setCursor(cur);
1092 bvcur.selection() = true;
1093 //lyxerr << "MOTION: " << bv->cursor() << endl;
1101 case LFUN_MOUSE_RELEASE: {
1102 if (cmd.button() == mouse_button::button2)
1105 if (cmd.button() == mouse_button::button1) {
1106 // if there is new selection, update persistent
1107 // selection, otherwise, single click does not
1108 // clear persistent selection buffer
1109 if (cur.selection()) {
1111 // if double click, cur is moved to the end of word by selectWord
1112 // but bvcur is current mouse position
1113 Cursor & bvcur = cur.bv().cursor();
1114 bvcur.selection() = true;
1115 saveSelection(bvcur);
1117 needsUpdate = false;
1125 case LFUN_SELF_INSERT: {
1126 if (cmd.argument().empty())
1129 // Automatically delete the currently selected
1130 // text and replace it with what is being
1131 // typed in now. Depends on lyxrc settings
1132 // "auto_region_delete", which defaults to
1135 if (lyxrc.auto_region_delete)
1136 if (cur.selection())
1137 cutSelection(cur, false, false);
1139 cur.clearSelection();
1140 Font const old_font = real_current_font;
1142 docstring::const_iterator cit = cmd.argument().begin();
1143 docstring::const_iterator end = cmd.argument().end();
1144 for (; cit != end; ++cit)
1145 bv->getIntl().getTransManager().
1146 translateAndInsert(*cit, this, cur);
1149 moveCursor(cur, false);
1153 case LFUN_URL_INSERT: {
1154 InsetCommandParams p("url");
1155 string const data = InsetCommandMailer::params2string("url", p);
1156 bv->showInsetDialog("url", data, 0);
1160 case LFUN_HTML_INSERT: {
1161 InsetCommandParams p("htmlurl");
1162 string const data = InsetCommandMailer::params2string("url", p);
1163 bv->showInsetDialog("url", data, 0);
1167 case LFUN_LABEL_INSERT: {
1168 InsetCommandParams p("label");
1169 // Try to generate a valid label
1170 p["name"] = (cmd.argument().empty()) ?
1171 cur.getPossibleLabel() :
1173 string const data = InsetCommandMailer::params2string("label", p);
1175 if (cmd.argument().empty()) {
1176 bv->showInsetDialog("label", data, 0);
1178 FuncRequest fr(LFUN_INSET_INSERT, data);
1186 case LFUN_LIST_INSERT:
1187 case LFUN_THEOREM_INSERT:
1189 case LFUN_CAPTION_INSERT:
1190 // Open the inset, and move the current selection
1192 doInsertInset(cur, this, cmd, true, true);
1194 updateLabels(*bv->buffer());
1196 case LFUN_NOTE_INSERT:
1197 case LFUN_CHARSTYLE_INSERT:
1198 case LFUN_BOX_INSERT:
1199 case LFUN_BRANCH_INSERT:
1200 case LFUN_BIBITEM_INSERT:
1201 case LFUN_ERT_INSERT:
1202 case LFUN_LISTING_INSERT:
1203 case LFUN_FOOTNOTE_INSERT:
1204 case LFUN_MARGINALNOTE_INSERT:
1205 case LFUN_OPTIONAL_INSERT:
1206 case LFUN_ENVIRONMENT_INSERT:
1207 // Open the inset, and move the current selection
1209 doInsertInset(cur, this, cmd, true, true);
1213 case LFUN_TABULAR_INSERT:
1214 // if there were no arguments, just open the dialog
1215 if (doInsertInset(cur, this, cmd, false, true))
1218 bv->showDialog("tabularcreate");
1222 case LFUN_FLOAT_INSERT:
1223 case LFUN_FLOAT_WIDE_INSERT:
1224 case LFUN_WRAP_INSERT: {
1225 bool content = cur.selection(); // will some text be moved into the inset?
1227 doInsertInset(cur, this, cmd, true, true);
1229 ParagraphList & pars = cur.text()->paragraphs();
1231 TextClass const & tclass = bv->buffer()->params().getTextClass();
1233 // add a separate paragraph for the caption inset
1234 pars.push_back(Paragraph());
1235 pars.back().setInsetOwner(pars[0].inInset());
1236 pars.back().layout(tclass.defaultLayout());
1238 int cap_pit = pars.size() - 1;
1240 // if an empty inset was created, we create an additional empty
1241 // paragraph at the bottom so that the user can choose where to put
1242 // the graphics (or table).
1244 pars.push_back(Paragraph());
1245 pars.back().setInsetOwner(pars[0].inInset());
1246 pars.back().layout(tclass.defaultLayout());
1250 // reposition the cursor to the caption
1251 cur.pit() = cap_pit;
1253 cur.dispatch(FuncRequest(LFUN_CAPTION_INSERT));
1254 // FIXME: When leaving the Float (or Wrap) inset we should
1255 // delete any empty paragraph left above or below the
1260 case LFUN_INDEX_INSERT:
1261 case LFUN_NOMENCL_INSERT: {
1262 Inset * inset = createInset(&cur.bv(), cmd);
1266 cur.clearSelection();
1267 insertInset(cur, inset);
1268 inset->edit(cur, true);
1269 // Show the dialog for the nomenclature entry, since the
1270 // description entry still needs to be filled in.
1271 if (cmd.action == LFUN_NOMENCL_INSERT)
1272 InsetCommandMailer("nomenclature",
1273 *reinterpret_cast<InsetCommand *>(inset)).showDialog(&cur.bv());
1278 case LFUN_INDEX_PRINT:
1279 case LFUN_NOMENCL_PRINT:
1280 case LFUN_TOC_INSERT:
1281 case LFUN_HFILL_INSERT:
1282 case LFUN_LINE_INSERT:
1283 case LFUN_PAGEBREAK_INSERT:
1284 case LFUN_CLEARPAGE_INSERT:
1285 case LFUN_CLEARDOUBLEPAGE_INSERT:
1287 doInsertInset(cur, this, cmd, false, false);
1291 case LFUN_DEPTH_DECREMENT:
1292 changeDepth(cur, DEC_DEPTH);
1295 case LFUN_DEPTH_INCREMENT:
1296 changeDepth(cur, INC_DEPTH);
1299 case LFUN_MATH_DISPLAY:
1300 mathDispatch(cur, cmd, true);
1303 case LFUN_MATH_IMPORT_SELECTION:
1304 case LFUN_MATH_MODE:
1305 if (cmd.argument() == "on")
1306 // don't pass "on" as argument
1307 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1309 mathDispatch(cur, cmd, false);
1312 case LFUN_MATH_MACRO:
1313 if (cmd.argument().empty())
1314 cur.errorMessage(from_utf8(N_("Missing argument")));
1316 string s = to_utf8(cmd.argument());
1317 string const s1 = token(s, ' ', 1);
1318 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1319 string const s2 = token(s, ' ', 2);
1320 string const type = s2.empty() ? "newcommand" : s2;
1321 cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, from_utf8(type)));
1322 //cur.nextInset()->edit(cur, true);
1326 // passthrough hat and underscore outside mathed:
1327 case LFUN_MATH_SUBSCRIPT:
1328 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1330 case LFUN_MATH_SUPERSCRIPT:
1331 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1334 case LFUN_MATH_INSERT:
1335 case LFUN_MATH_MATRIX:
1336 case LFUN_MATH_DELIM:
1337 case LFUN_MATH_BIGDELIM: {
1338 cur.insert(new InsetMathHull(hullSimple));
1339 cur.dispatch(FuncRequest(LFUN_CHAR_FORWARD));
1340 BOOST_ASSERT(cur.inMathed());
1345 case LFUN_FONT_EMPH: {
1346 Font font(Font::ALL_IGNORE);
1347 font.setEmph(Font::TOGGLE);
1348 toggleAndShow(cur, this, font);
1352 case LFUN_FONT_BOLD: {
1353 Font font(Font::ALL_IGNORE);
1354 font.setSeries(Font::BOLD_SERIES);
1355 toggleAndShow(cur, this, font);
1359 case LFUN_FONT_NOUN: {
1360 Font font(Font::ALL_IGNORE);
1361 font.setNoun(Font::TOGGLE);
1362 toggleAndShow(cur, this, font);
1366 case LFUN_FONT_CODE: {
1367 Font font(Font::ALL_IGNORE);
1368 font.setFamily(Font::TYPEWRITER_FAMILY); // no good
1369 toggleAndShow(cur, this, font);
1373 case LFUN_FONT_SANS: {
1374 Font font(Font::ALL_IGNORE);
1375 font.setFamily(Font::SANS_FAMILY);
1376 toggleAndShow(cur, this, font);
1380 case LFUN_FONT_ROMAN: {
1381 Font font(Font::ALL_IGNORE);
1382 font.setFamily(Font::ROMAN_FAMILY);
1383 toggleAndShow(cur, this, font);
1387 case LFUN_FONT_DEFAULT: {
1388 Font font(Font::ALL_INHERIT, ignore_language);
1389 toggleAndShow(cur, this, font);
1393 case LFUN_FONT_UNDERLINE: {
1394 Font font(Font::ALL_IGNORE);
1395 font.setUnderbar(Font::TOGGLE);
1396 toggleAndShow(cur, this, font);
1400 case LFUN_FONT_SIZE: {
1401 Font font(Font::ALL_IGNORE);
1402 font.setLyXSize(to_utf8(cmd.argument()));
1403 toggleAndShow(cur, this, font);
1407 case LFUN_LANGUAGE: {
1408 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1411 Font font(Font::ALL_IGNORE);
1412 font.setLanguage(lang);
1413 toggleAndShow(cur, this, font);
1418 case LFUN_FONT_FREE_APPLY:
1419 toggleAndShow(cur, this, freefont, toggleall);
1420 cur.message(_("Character set"));
1423 // Set the freefont using the contents of \param data dispatched from
1424 // the frontends and apply it at the current cursor location.
1425 case LFUN_FONT_FREE_UPDATE: {
1428 if (bv_funcs::string2font(to_utf8(cmd.argument()), font, toggle)) {
1431 toggleAndShow(cur, this, freefont, toggleall);
1432 cur.message(_("Character set"));
1437 case LFUN_FINISHED_LEFT:
1438 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1439 if (reverseDirectionNeeded(cur))
1443 case LFUN_FINISHED_RIGHT:
1444 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1445 if (!reverseDirectionNeeded(cur))
1449 case LFUN_FINISHED_UP:
1450 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_UP:\n" << cur << endl;
1454 case LFUN_FINISHED_DOWN:
1455 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_DOWN:\n" << cur << endl;
1459 case LFUN_LAYOUT_PARAGRAPH: {
1461 params2string(cur.paragraph(), data);
1462 data = "show\n" + data;
1463 bv->showDialogWithData("paragraph", data);
1467 case LFUN_PARAGRAPH_UPDATE: {
1469 params2string(cur.paragraph(), data);
1471 // Will the paragraph accept changes from the dialog?
1472 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1474 data = "update " + convert<string>(accept) + '\n' + data;
1475 bv->updateDialog("paragraph", data);
1479 case LFUN_ACCENT_UMLAUT:
1480 case LFUN_ACCENT_CIRCUMFLEX:
1481 case LFUN_ACCENT_GRAVE:
1482 case LFUN_ACCENT_ACUTE:
1483 case LFUN_ACCENT_TILDE:
1484 case LFUN_ACCENT_CEDILLA:
1485 case LFUN_ACCENT_MACRON:
1486 case LFUN_ACCENT_DOT:
1487 case LFUN_ACCENT_UNDERDOT:
1488 case LFUN_ACCENT_UNDERBAR:
1489 case LFUN_ACCENT_CARON:
1490 case LFUN_ACCENT_SPECIAL_CARON:
1491 case LFUN_ACCENT_BREVE:
1492 case LFUN_ACCENT_TIE:
1493 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1494 case LFUN_ACCENT_CIRCLE:
1495 case LFUN_ACCENT_OGONEK:
1496 theLyXFunc().handleKeyFunc(cmd.action);
1497 if (!cmd.argument().empty())
1498 // FIXME: Are all these characters encoded in one byte in utf8?
1499 bv->getIntl().getTransManager()
1500 .translateAndInsert(cmd.argument()[0], this, cur);
1503 case LFUN_FLOAT_LIST: {
1504 TextClass const & tclass = bv->buffer()->params().getTextClass();
1505 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1506 // not quite sure if we want this...
1508 cur.clearSelection();
1509 breakParagraph(cur);
1511 if (cur.lastpos() != 0) {
1513 breakParagraph(cur);
1516 setLayout(cur, tclass.defaultLayoutName());
1517 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, docstring(), 0);
1518 insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1521 lyxerr << "Non-existent float type: "
1522 << to_utf8(cmd.argument()) << endl;
1527 case LFUN_CHANGE_ACCEPT: {
1528 acceptOrRejectChanges(cur, ACCEPT);
1532 case LFUN_CHANGE_REJECT: {
1533 acceptOrRejectChanges(cur, REJECT);
1537 case LFUN_THESAURUS_ENTRY: {
1538 docstring arg = cmd.argument();
1540 arg = cur.selectionAsString(false);
1542 if (arg.size() > 100 || arg.empty()) {
1543 // Get word or selection
1544 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1545 arg = cur.selectionAsString(false);
1548 bv->showDialogWithData("thesaurus", to_utf8(arg));
1552 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1553 // Given data, an encoding of the ParagraphParameters
1554 // generated in the Paragraph dialog, this function sets
1555 // the current paragraph appropriately.
1556 istringstream is(to_utf8(cmd.argument()));
1559 ParagraphParameters params;
1564 params.labelWidthString(),
1566 cur.message(_("Paragraph layout set"));
1571 if (cur.selection()) {
1572 cur.selection() = false;
1576 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1581 LYXERR(Debug::ACTION)
1582 << BOOST_CURRENT_FUNCTION
1583 << ": Command " << cmd
1584 << " not DISPATCHED by Text" << endl;
1589 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1591 // FIXME: The cursor flag is reset two lines below
1592 // so we need to check here if some of the LFUN did touch that.
1593 // for now only Text::erase() and Text::backspace() do that.
1594 // The plan is to verify all the LFUNs and then to remove this
1595 // singleParUpdate boolean altogether.
1596 if (cur.result().update() & Update::Force) {
1597 singleParUpdate = false;
1601 // FIXME: the following code should go in favor of fine grained
1602 // update flag treatment.
1603 if (singleParUpdate) {
1604 // Inserting characters does not change par height
1605 ParagraphMetrics const & pms
1606 = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
1607 if (pms.dim().height()
1608 == olddim.height()) {
1609 // if so, update _only_ this paragraph
1610 cur.updateFlags(Update::SinglePar |
1612 Update::MultiParSel);
1619 && &oldTopSlice.inset() == &cur.inset()
1620 && oldTopSlice.idx() == cur.idx()
1621 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1622 && !cur.selection())
1623 // FIXME: it would be better if we could just do this
1625 //if (cur.result().update() != Update::FitCursor)
1628 // But some LFUNs do not set Update::FitCursor when needed, so we
1629 // do it for all. This is not very harmfull as FitCursor will provoke
1630 // a full redraw only if needed but still, a proper review of all LFUN
1631 // should be done and this needsUpdate boolean can then be removed.
1632 cur.updateFlags(Update::FitCursor);
1634 cur.updateFlags(Update::Force | Update::FitCursor);
1638 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
1639 FuncStatus & flag) const
1641 BOOST_ASSERT(cur.text() == this);
1643 Font const & font = real_current_font;
1645 Inset::Code code = Inset::NO_CODE;
1647 switch (cmd.action) {
1649 case LFUN_DEPTH_DECREMENT:
1650 enable = changeDepthAllowed(cur, DEC_DEPTH);
1653 case LFUN_DEPTH_INCREMENT:
1654 enable = changeDepthAllowed(cur, INC_DEPTH);
1658 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1661 case LFUN_BIBITEM_INSERT:
1662 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO
1666 case LFUN_DIALOG_SHOW_NEW_INSET:
1667 if (cmd.argument() == "bibitem")
1668 code = Inset::BIBITEM_CODE;
1669 else if (cmd.argument() == "bibtex")
1670 code = Inset::BIBTEX_CODE;
1671 else if (cmd.argument() == "box")
1672 code = Inset::BOX_CODE;
1673 else if (cmd.argument() == "branch")
1674 code = Inset::BRANCH_CODE;
1675 else if (cmd.argument() == "citation")
1676 code = Inset::CITE_CODE;
1677 else if (cmd.argument() == "ert")
1678 code = Inset::ERT_CODE;
1679 else if (cmd.argument() == "external")
1680 code = Inset::EXTERNAL_CODE;
1681 else if (cmd.argument() == "float")
1682 code = Inset::FLOAT_CODE;
1683 else if (cmd.argument() == "graphics")
1684 code = Inset::GRAPHICS_CODE;
1685 else if (cmd.argument() == "include")
1686 code = Inset::INCLUDE_CODE;
1687 else if (cmd.argument() == "index")
1688 code = Inset::INDEX_CODE;
1689 else if (cmd.argument() == "nomenclature")
1690 code = Inset::NOMENCL_CODE;
1691 else if (cmd.argument() == "label")
1692 code = Inset::LABEL_CODE;
1693 else if (cmd.argument() == "note")
1694 code = Inset::NOTE_CODE;
1695 else if (cmd.argument() == "ref")
1696 code = Inset::REF_CODE;
1697 else if (cmd.argument() == "toc")
1698 code = Inset::TOC_CODE;
1699 else if (cmd.argument() == "url")
1700 code = Inset::URL_CODE;
1701 else if (cmd.argument() == "vspace")
1702 code = Inset::VSPACE_CODE;
1703 else if (cmd.argument() == "wrap")
1704 code = Inset::WRAP_CODE;
1705 else if (cmd.argument() == "listings")
1706 code = Inset::LISTINGS_CODE;
1709 case LFUN_ERT_INSERT:
1710 code = Inset::ERT_CODE;
1712 case LFUN_LISTING_INSERT:
1713 code = Inset::LISTINGS_CODE;
1715 case LFUN_FOOTNOTE_INSERT:
1716 code = Inset::FOOT_CODE;
1718 case LFUN_TABULAR_INSERT:
1719 code = Inset::TABULAR_CODE;
1721 case LFUN_MARGINALNOTE_INSERT:
1722 code = Inset::MARGIN_CODE;
1724 case LFUN_FLOAT_INSERT:
1725 case LFUN_FLOAT_WIDE_INSERT:
1726 code = Inset::FLOAT_CODE;
1728 case LFUN_WRAP_INSERT:
1729 code = Inset::WRAP_CODE;
1731 case LFUN_FLOAT_LIST:
1732 code = Inset::FLOAT_LIST_CODE;
1735 case LFUN_LIST_INSERT:
1736 code = Inset::LIST_CODE;
1738 case LFUN_THEOREM_INSERT:
1739 code = Inset::THEOREM_CODE;
1742 case LFUN_CAPTION_INSERT:
1743 code = Inset::CAPTION_CODE;
1745 case LFUN_NOTE_INSERT:
1746 code = Inset::NOTE_CODE;
1748 case LFUN_CHARSTYLE_INSERT:
1749 code = Inset::CHARSTYLE_CODE;
1750 if (cur.buffer().params().getTextClass().charstyles().empty())
1753 case LFUN_BOX_INSERT:
1754 code = Inset::BOX_CODE;
1756 case LFUN_BRANCH_INSERT:
1757 code = Inset::BRANCH_CODE;
1758 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1761 case LFUN_LABEL_INSERT:
1762 code = Inset::LABEL_CODE;
1764 case LFUN_OPTIONAL_INSERT:
1765 code = Inset::OPTARG_CODE;
1766 enable = numberOfOptArgs(cur.paragraph())
1767 < cur.paragraph().layout()->optionalargs;
1769 case LFUN_ENVIRONMENT_INSERT:
1770 code = Inset::BOX_CODE;
1772 case LFUN_INDEX_INSERT:
1773 code = Inset::INDEX_CODE;
1775 case LFUN_INDEX_PRINT:
1776 code = Inset::INDEX_PRINT_CODE;
1778 case LFUN_NOMENCL_INSERT:
1779 code = Inset::NOMENCL_CODE;
1781 case LFUN_NOMENCL_PRINT:
1782 code = Inset::NOMENCL_PRINT_CODE;
1784 case LFUN_TOC_INSERT:
1785 code = Inset::TOC_CODE;
1787 case LFUN_HTML_INSERT:
1788 case LFUN_URL_INSERT:
1789 code = Inset::URL_CODE;
1791 case LFUN_QUOTE_INSERT:
1792 // always allow this, since we will inset a raw quote
1793 // if an inset is not allowed.
1795 case LFUN_HYPHENATION_POINT_INSERT:
1796 case LFUN_LIGATURE_BREAK_INSERT:
1797 case LFUN_HFILL_INSERT:
1798 case LFUN_MENU_SEPARATOR_INSERT:
1799 case LFUN_DOTS_INSERT:
1800 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
1801 code = Inset::SPECIALCHAR_CODE;
1803 case LFUN_SPACE_INSERT:
1804 // slight hack: we know this is allowed in math mode
1806 code = Inset::SPACE_CODE;
1809 case LFUN_INSET_MODIFY:
1810 // We need to disable this, because we may get called for a
1812 // InsetTabular::getStatus() -> InsetText::getStatus()
1813 // and we don't handle LFUN_INSET_MODIFY.
1817 case LFUN_FONT_EMPH:
1818 flag.setOnOff(font.emph() == Font::ON);
1821 case LFUN_FONT_NOUN:
1822 flag.setOnOff(font.noun() == Font::ON);
1825 case LFUN_FONT_BOLD:
1826 flag.setOnOff(font.series() == Font::BOLD_SERIES);
1829 case LFUN_FONT_SANS:
1830 flag.setOnOff(font.family() == Font::SANS_FAMILY);
1833 case LFUN_FONT_ROMAN:
1834 flag.setOnOff(font.family() == Font::ROMAN_FAMILY);
1837 case LFUN_FONT_CODE:
1838 flag.setOnOff(font.family() == Font::TYPEWRITER_FAMILY);
1843 enable = cur.selection();
1847 if (cmd.argument().empty()) {
1848 if (theClipboard().isInternal())
1849 enable = cap::numberOfSelections() > 0;
1851 enable = !theClipboard().empty();
1853 string const arg = to_utf8(cmd.argument());
1854 if (isStrUnsignedInt(arg)) {
1855 unsigned int n = convert<unsigned int>(arg);
1856 enable = cap::numberOfSelections() > n;
1863 case LFUN_CLIPBOARD_PASTE:
1864 enable = !theClipboard().empty();
1867 case LFUN_PRIMARY_SELECTION_PASTE:
1868 enable = cur.selection() || !theSelection().empty();
1871 case LFUN_PARAGRAPH_MOVE_UP:
1872 enable = cur.pit() > 0 && !cur.selection();
1875 case LFUN_PARAGRAPH_MOVE_DOWN:
1876 enable = cur.pit() < cur.lastpit() && !cur.selection();
1879 case LFUN_INSET_DISSOLVE:
1880 enable = !isMainText(*cur.bv().buffer()) && cur.inset().nargs() == 1;
1883 case LFUN_CHANGE_ACCEPT:
1884 case LFUN_CHANGE_REJECT:
1885 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
1886 // In principle, these LFUNs should only be enabled if there
1887 // is a change at the current position/in the current selection.
1888 // However, without proper optimizations, this will inevitably
1889 // result in unacceptable performance - just imagine a user who
1890 // wants to select the complete content of a long document.
1894 case LFUN_WORD_DELETE_FORWARD:
1895 case LFUN_WORD_DELETE_BACKWARD:
1896 case LFUN_LINE_DELETE:
1897 case LFUN_WORD_FORWARD:
1898 case LFUN_WORD_BACKWARD:
1899 case LFUN_CHAR_FORWARD:
1900 case LFUN_CHAR_FORWARD_SELECT:
1901 case LFUN_CHAR_BACKWARD:
1902 case LFUN_CHAR_BACKWARD_SELECT:
1904 case LFUN_UP_SELECT:
1906 case LFUN_DOWN_SELECT:
1907 case LFUN_PARAGRAPH_UP_SELECT:
1908 case LFUN_PARAGRAPH_DOWN_SELECT:
1909 case LFUN_SCREEN_UP_SELECT:
1910 case LFUN_SCREEN_DOWN_SELECT:
1911 case LFUN_LINE_BEGIN_SELECT:
1912 case LFUN_LINE_END_SELECT:
1913 case LFUN_WORD_FORWARD_SELECT:
1914 case LFUN_WORD_BACKWARD_SELECT:
1915 case LFUN_WORD_SELECT:
1916 case LFUN_PARAGRAPH_UP:
1917 case LFUN_PARAGRAPH_DOWN:
1918 case LFUN_SCREEN_UP:
1919 case LFUN_SCREEN_DOWN:
1920 case LFUN_LINE_BEGIN:
1922 case LFUN_BREAK_LINE:
1923 case LFUN_CHAR_DELETE_FORWARD:
1924 case LFUN_DELETE_FORWARD_SKIP:
1925 case LFUN_CHAR_DELETE_BACKWARD:
1926 case LFUN_DELETE_BACKWARD_SKIP:
1927 case LFUN_BREAK_PARAGRAPH:
1928 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
1929 case LFUN_BREAK_PARAGRAPH_SKIP:
1930 case LFUN_PARAGRAPH_SPACING:
1931 case LFUN_INSET_INSERT:
1932 case LFUN_WORD_UPCASE:
1933 case LFUN_WORD_LOWCASE:
1934 case LFUN_WORD_CAPITALIZE:
1935 case LFUN_CHARS_TRANSPOSE:
1936 case LFUN_SERVER_GET_XY:
1937 case LFUN_SERVER_SET_XY:
1938 case LFUN_SERVER_GET_FONT:
1939 case LFUN_SERVER_GET_LAYOUT:
1941 case LFUN_DATE_INSERT:
1942 case LFUN_SELF_INSERT:
1943 case LFUN_LINE_INSERT:
1944 case LFUN_PAGEBREAK_INSERT:
1945 case LFUN_CLEARPAGE_INSERT:
1946 case LFUN_CLEARDOUBLEPAGE_INSERT:
1947 case LFUN_MATH_DISPLAY:
1948 case LFUN_MATH_IMPORT_SELECTION:
1949 case LFUN_MATH_MODE:
1950 case LFUN_MATH_MACRO:
1951 case LFUN_MATH_MATRIX:
1952 case LFUN_MATH_DELIM:
1953 case LFUN_MATH_BIGDELIM:
1954 case LFUN_MATH_SUBSCRIPT:
1955 case LFUN_MATH_SUPERSCRIPT:
1956 case LFUN_FONT_DEFAULT:
1957 case LFUN_FONT_UNDERLINE:
1958 case LFUN_FONT_SIZE:
1960 case LFUN_FONT_FREE_APPLY:
1961 case LFUN_FONT_FREE_UPDATE:
1962 case LFUN_LAYOUT_PARAGRAPH:
1963 case LFUN_PARAGRAPH_UPDATE:
1964 case LFUN_ACCENT_UMLAUT:
1965 case LFUN_ACCENT_CIRCUMFLEX:
1966 case LFUN_ACCENT_GRAVE:
1967 case LFUN_ACCENT_ACUTE:
1968 case LFUN_ACCENT_TILDE:
1969 case LFUN_ACCENT_CEDILLA:
1970 case LFUN_ACCENT_MACRON:
1971 case LFUN_ACCENT_DOT:
1972 case LFUN_ACCENT_UNDERDOT:
1973 case LFUN_ACCENT_UNDERBAR:
1974 case LFUN_ACCENT_CARON:
1975 case LFUN_ACCENT_SPECIAL_CARON:
1976 case LFUN_ACCENT_BREVE:
1977 case LFUN_ACCENT_TIE:
1978 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1979 case LFUN_ACCENT_CIRCLE:
1980 case LFUN_ACCENT_OGONEK:
1981 case LFUN_THESAURUS_ENTRY:
1982 case LFUN_PARAGRAPH_PARAMS_APPLY:
1984 case LFUN_BUFFER_END:
1985 case LFUN_BUFFER_BEGIN:
1986 case LFUN_BUFFER_BEGIN_SELECT:
1987 case LFUN_BUFFER_END_SELECT:
1988 case LFUN_UNICODE_INSERT:
1989 // these are handled in our dispatch()
1997 if (code != Inset::NO_CODE
1998 && (cur.empty() || !cur.inset().insetAllowed(code)))
2001 flag.enabled(enable);
2006 void Text::pasteString(Cursor & cur, docstring const & clip,
2009 cur.clearSelection();
2010 if (!clip.empty()) {
2013 insertStringAsParagraphs(cur, clip);
2015 insertStringAsLines(cur, clip);