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);
470 case LFUN_UP_SELECT: {
471 //lyxerr << "handle LFUN_UP[SEL]:\n" << cur << endl;
472 needsUpdate |= cur.selHandle(cmd.action == LFUN_UP_SELECT);
473 bool const successful = cur.upDownInText(true, needsUpdate);
482 case LFUN_DOWN_SELECT: {
483 //lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
484 needsUpdate |= cur.selHandle(cmd.action == LFUN_DOWN_SELECT);
485 bool const successful = cur.upDownInText(false, needsUpdate);
493 case LFUN_PARAGRAPH_UP:
494 case LFUN_PARAGRAPH_UP_SELECT:
495 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
496 needsUpdate |= cursorUpParagraph(cur);
501 case LFUN_PARAGRAPH_DOWN:
502 case LFUN_PARAGRAPH_DOWN_SELECT:
503 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
504 needsUpdate |= cursorDownParagraph(cur);
510 case LFUN_SCREEN_UP_SELECT:
511 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_UP_SELECT);
512 if (cur.pit() == 0 && cur.textRow().pos() == 0)
521 case LFUN_SCREEN_DOWN:
522 case LFUN_SCREEN_DOWN_SELECT:
523 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_DOWN_SELECT);
524 if (cur.pit() == cur.lastpit()
525 && cur.textRow().endpos() == cur.lastpos())
534 case LFUN_LINE_BEGIN:
535 case LFUN_LINE_BEGIN_SELECT:
536 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
537 needsUpdate |= cursorHome(cur);
541 case LFUN_LINE_END_SELECT:
542 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
543 needsUpdate |= cursorEnd(cur);
548 case LFUN_WORD_FORWARD:
549 case LFUN_WORD_FORWARD_SELECT:
550 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
551 if (reverseDirectionNeeded(cur))
552 needsUpdate |= cursorLeftOneWord(cur);
554 needsUpdate |= cursorRightOneWord(cur);
559 case LFUN_WORD_BACKWARD:
560 case LFUN_WORD_BACKWARD_SELECT:
561 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
562 if (reverseDirectionNeeded(cur))
563 needsUpdate |= cursorRightOneWord(cur);
565 needsUpdate |= cursorLeftOneWord(cur);
570 case LFUN_WORD_SELECT: {
571 selectWord(cur, WHOLE_WORD);
572 finishChange(cur, true);
576 case LFUN_BREAK_LINE: {
577 // Not allowed by LaTeX (labels or empty par)
578 if (cur.pos() > cur.paragraph().beginOfBody()) {
579 // this avoids a double undo
580 // FIXME: should not be needed, ideally
581 if (!cur.selection())
583 cap::replaceSelection(cur);
584 cur.insert(new InsetNewline);
586 moveCursor(cur, false);
591 case LFUN_CHAR_DELETE_FORWARD:
592 if (!cur.selection()) {
593 if (cur.pos() == cur.paragraph().size())
594 // Par boundary, force full-screen update
595 singleParUpdate = false;
596 needsUpdate |= erase(cur);
598 // It is possible to make it a lot faster still
599 // just comment out the line below...
601 cutSelection(cur, true, false);
602 singleParUpdate = false;
604 moveCursor(cur, false);
607 case LFUN_DELETE_FORWARD_SKIP:
608 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
609 if (!cur.selection()) {
610 if (cur.pos() == cur.lastpos()) {
617 cutSelection(cur, true, false);
622 case LFUN_CHAR_DELETE_BACKWARD:
623 if (!cur.selection()) {
624 if (bv->getIntl().getTransManager().backspace()) {
625 // Par boundary, full-screen update
627 singleParUpdate = false;
628 needsUpdate |= backspace(cur);
630 // It is possible to make it a lot faster still
631 // just comment out the line below...
634 cutSelection(cur, true, false);
635 singleParUpdate = false;
640 case LFUN_DELETE_BACKWARD_SKIP:
641 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
642 if (!cur.selection()) {
646 //CursorSlice cur = cursor();
650 cutSelection(cur, true, false);
654 case LFUN_BREAK_PARAGRAPH:
655 cap::replaceSelection(cur);
656 breakParagraph(cur, 0);
661 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
662 cap::replaceSelection(cur);
663 breakParagraph(cur, 1);
668 case LFUN_BREAK_PARAGRAPH_SKIP: {
669 // When at the beginning of a paragraph, remove
670 // indentation. Otherwise, do the same as LFUN_BREAK_PARAGRAPH.
671 cap::replaceSelection(cur);
673 cur.paragraph().params().labelWidthString(docstring());
675 breakParagraph(cur, 0);
681 case LFUN_PARAGRAPH_SPACING: {
682 Paragraph & par = cur.paragraph();
683 Spacing::Space cur_spacing = par.params().spacing().getSpace();
684 string cur_value = "1.0";
685 if (cur_spacing == Spacing::Other)
686 cur_value = par.params().spacing().getValueAsString();
688 istringstream is(to_utf8(cmd.argument()));
691 Spacing::Space new_spacing = cur_spacing;
692 string new_value = cur_value;
694 lyxerr << "Missing argument to `paragraph-spacing'"
696 } else if (tmp == "single") {
697 new_spacing = Spacing::Single;
698 } else if (tmp == "onehalf") {
699 new_spacing = Spacing::Onehalf;
700 } else if (tmp == "double") {
701 new_spacing = Spacing::Double;
702 } else if (tmp == "other") {
703 new_spacing = Spacing::Other;
704 string tmpval = "0.0";
706 lyxerr << "new_value = " << tmpval << endl;
709 } else if (tmp == "default") {
710 new_spacing = Spacing::Default;
712 lyxerr << to_utf8(_("Unknown spacing argument: "))
713 << to_utf8(cmd.argument()) << endl;
715 if (cur_spacing != new_spacing || cur_value != new_value)
716 par.params().spacing(Spacing(new_spacing, new_value));
720 case LFUN_INSET_INSERT: {
722 Inset * inset = createInset(bv, cmd);
724 // FIXME (Abdel 01/02/2006):
725 // What follows would be a partial fix for bug 2154:
726 // http://bugzilla.lyx.org/show_bug.cgi?id=2154
727 // This automatically put the label inset _after_ a
728 // numbered section. It should be possible to extend the mechanism
729 // to any kind of LateX environement.
730 // The correct way to fix that bug would be at LateX generation.
731 // I'll let the code here for reference as it could be used for some
732 // other feature like "automatic labelling".
734 Paragraph & par = pars_[cur.pit()];
735 if (inset->lyxCode() == Inset::LABEL_CODE
736 && par.layout()->labeltype == LABEL_COUNTER) {
737 // Go to the end of the paragraph
738 // Warning: Because of Change-Tracking, the last
739 // position is 'size()' and not 'size()-1':
740 cur.pos() = par.size();
741 // Insert a new paragraph
742 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
746 insertInset(cur, inset);
752 case LFUN_INSET_DISSOLVE:
753 needsUpdate |= dissolveInset(cur);
756 case LFUN_INSET_SETTINGS:
757 cur.inset().showInsetDialog(bv);
760 case LFUN_SPACE_INSERT:
761 if (cur.paragraph().layout()->free_spacing)
762 insertChar(cur, ' ');
764 doInsertInset(cur, this, cmd, false, false);
767 moveCursor(cur, false);
770 case LFUN_HYPHENATION_POINT_INSERT:
771 specialChar(cur, InsetSpecialChar::HYPHENATION);
774 case LFUN_LIGATURE_BREAK_INSERT:
775 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
778 case LFUN_DOTS_INSERT:
779 specialChar(cur, InsetSpecialChar::LDOTS);
782 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
783 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
786 case LFUN_MENU_SEPARATOR_INSERT:
787 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
790 case LFUN_WORD_UPCASE:
791 changeCase(cur, Text::text_uppercase);
794 case LFUN_WORD_LOWCASE:
795 changeCase(cur, Text::text_lowercase);
798 case LFUN_WORD_CAPITALIZE:
799 changeCase(cur, Text::text_capitalization);
802 case LFUN_CHARS_TRANSPOSE:
807 cur.message(_("Paste"));
808 cap::replaceSelection(cur);
809 if (cmd.argument().empty() && !theClipboard().isInternal())
810 pasteClipboard(cur, bv->buffer()->errorList("Paste"));
812 string const arg(to_utf8(cmd.argument()));
813 pasteFromStack(cur, bv->buffer()->errorList("Paste"),
814 isStrUnsignedInt(arg) ?
815 convert<unsigned int>(arg) :
818 bv->buffer()->errors("Paste");
819 cur.clearSelection(); // bug 393
825 cutSelection(cur, true, true);
826 cur.message(_("Cut"));
831 cur.message(_("Copy"));
834 case LFUN_SERVER_GET_XY:
835 cur.message(from_utf8(
836 convert<string>(cursorX(cur.bv(), cur.top(), cur.boundary()))
837 + ' ' + convert<string>(cursorY(cur.bv(), cur.top(), cur.boundary()))));
840 case LFUN_SERVER_SET_XY: {
843 istringstream is(to_utf8(cmd.argument()));
846 lyxerr << "SETXY: Could not parse coordinates in '"
847 << to_utf8(cmd.argument()) << std::endl;
849 setCursorFromCoordinates(cur, x, y);
853 case LFUN_SERVER_GET_FONT:
854 if (current_font.shape() == Font::ITALIC_SHAPE)
855 cur.message(from_ascii("E"));
856 else if (current_font.shape() == Font::SMALLCAPS_SHAPE)
857 cur.message(from_ascii("N"));
859 cur.message(from_ascii("0"));
862 case LFUN_SERVER_GET_LAYOUT:
863 cur.message(from_utf8(cur.paragraph().layout()->name()));
867 string layout = to_ascii(cmd.argument());
868 LYXERR(Debug::INFO) << "LFUN_LAYOUT: (arg) " << layout << endl;
870 // Derive layout number from given argument (string)
871 // and current buffer's textclass (number)
872 TextClass const & tclass = bv->buffer()->params().getTextClass();
874 layout = tclass.defaultLayoutName();
875 bool hasLayout = tclass.hasLayout(layout);
877 // If the entry is obsolete, use the new one instead.
879 string const & obs = tclass[layout]->obsoleted_by();
885 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
886 from_utf8(N_(" not known")));
890 bool change_layout = (current_layout != layout);
892 if (!change_layout && cur.selection() &&
893 cur.selBegin().pit() != cur.selEnd().pit())
895 pit_type spit = cur.selBegin().pit();
896 pit_type epit = cur.selEnd().pit() + 1;
897 while (spit != epit) {
898 if (pars_[spit].layout()->name() != current_layout) {
899 change_layout = true;
907 current_layout = layout;
908 setLayout(cur, layout);
909 // inform the GUI that the layout has changed.
910 bv->layoutChanged(layout);
916 case LFUN_CLIPBOARD_PASTE:
917 cur.clearSelection();
918 pasteClipboard(cur, bv->buffer()->errorList("Paste"),
919 cmd.argument() == "paragraph");
920 bv->buffer()->errors("Paste");
923 case LFUN_PRIMARY_SELECTION_PASTE:
924 pasteString(cur, theSelection().get(),
925 cmd.argument() == "paragraph");
928 case LFUN_UNICODE_INSERT: {
929 if (cmd.argument().empty())
931 docstring hexstring = cmd.argument();
932 if (lyx::support::isHex(hexstring)) {
933 char_type c = lyx::support::hexToInt(hexstring);
934 if (c > 32 && c < 0x10ffff) {
935 lyxerr << "Inserting c: " << c << endl;
936 docstring s = docstring(1, c);
937 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
943 case LFUN_QUOTE_INSERT: {
944 Paragraph & par = cur.paragraph();
945 pos_type pos = cur.pos();
946 BufferParams const & bufparams = bv->buffer()->params();
947 Layout_ptr const & style = par.layout();
948 if (!style->pass_thru
949 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
950 // this avoids a double undo
951 // FIXME: should not be needed, ideally
952 if (!cur.selection())
954 cap::replaceSelection(cur);
959 else if (cur.prevInset() && cur.prevInset()->isSpace())
962 c = par.getChar(pos - 1);
963 string arg = to_utf8(cmd.argument());
965 cur.insert(new InsetQuotes(c,
966 bufparams.quotes_language,
967 InsetQuotes::SingleQ));
969 cur.insert(new InsetQuotes(c,
970 bufparams.quotes_language,
971 InsetQuotes::DoubleQ));
975 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
979 case LFUN_DATE_INSERT:
980 if (cmd.argument().empty())
981 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
982 formatted_time(current_time())));
984 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
985 formatted_time(current_time(), to_utf8(cmd.argument()))));
988 case LFUN_MOUSE_TRIPLE:
989 if (cmd.button() == mouse_button::button1) {
999 case LFUN_MOUSE_DOUBLE:
1000 if (cmd.button() == mouse_button::button1) {
1001 selectWord(cur, WHOLE_WORD_STRICT);
1006 // Single-click on work area
1007 case LFUN_MOUSE_PRESS: {
1008 // Right click on a footnote flag opens float menu
1009 if (cmd.button() == mouse_button::button3)
1010 cur.clearSelection();
1012 // Middle button press pastes if we have a selection
1013 // We do this here as if the selection was inside an inset
1014 // it could get cleared on the unlocking of the inset so
1015 // we have to check this first
1016 bool paste_internally = false;
1017 if (cmd.button() == mouse_button::button2 && cap::selection()) {
1018 // Copy the selection buffer to the clipboard
1019 // stack, because we want it to appear in the
1020 // "Edit->Paste recent" menu.
1021 cap::copySelectionToStack();
1022 paste_internally = true;
1025 // Insert primary selection with middle mouse
1026 // if there is a local selection in the current buffer,
1028 if (cmd.button() == mouse_button::button2) {
1029 if (paste_internally) {
1030 cap::pasteSelection(cur, bv->buffer()->errorList("Paste"));
1031 bv->buffer()->errors("Paste");
1032 cur.clearSelection(); // bug 393
1034 bv->buffer()->markDirty();
1037 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
1040 // we have to update after dePM triggered
1041 bool update = bv->mouseSetCursor(cur);
1043 if (!update && cmd.button() == mouse_button::button1) {
1044 needsUpdate = false;
1051 case LFUN_MOUSE_MOTION: {
1052 // Only use motion with button 1
1053 //if (cmd.button() != mouse_button::button1)
1056 // ignore motions deeper nested than the real anchor
1057 Cursor & bvcur = cur.bv().cursor();
1058 if (bvcur.anchor_.hasPart(cur)) {
1059 CursorSlice old = bvcur.top();
1061 int const wh = bv->workHeight();
1062 int const y = std::max(0, std::min(wh - 1, cmd.y));
1064 setCursorFromCoordinates(cur, cmd.x, y);
1065 cur.setTargetX(cmd.x);
1067 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1069 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1070 // This is to allow jumping over large insets
1071 if (cur.top() == old) {
1073 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1075 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1078 if (cur.top() == old)
1081 // don't set anchor_
1082 bvcur.setCursor(cur);
1083 bvcur.selection() = true;
1084 //lyxerr << "MOTION: " << bv->cursor() << endl;
1092 case LFUN_MOUSE_RELEASE: {
1093 if (cmd.button() == mouse_button::button2)
1096 if (cmd.button() == mouse_button::button1) {
1097 // if there is new selection, update persistent
1098 // selection, otherwise, single click does not
1099 // clear persistent selection buffer
1100 if (cur.selection()) {
1102 // if double click, cur is moved to the end of word by selectWord
1103 // but bvcur is current mouse position
1104 Cursor & bvcur = cur.bv().cursor();
1105 bvcur.selection() = true;
1106 saveSelection(bvcur);
1108 needsUpdate = false;
1116 case LFUN_SELF_INSERT: {
1117 if (cmd.argument().empty())
1120 // Automatically delete the currently selected
1121 // text and replace it with what is being
1122 // typed in now. Depends on lyxrc settings
1123 // "auto_region_delete", which defaults to
1126 if (lyxrc.auto_region_delete)
1127 if (cur.selection())
1128 cutSelection(cur, false, false);
1130 cur.clearSelection();
1131 Font const old_font = real_current_font;
1133 docstring::const_iterator cit = cmd.argument().begin();
1134 docstring::const_iterator end = cmd.argument().end();
1135 for (; cit != end; ++cit)
1136 bv->getIntl().getTransManager().
1137 translateAndInsert(*cit, this, cur);
1140 moveCursor(cur, false);
1144 case LFUN_URL_INSERT: {
1145 InsetCommandParams p("url");
1146 string const data = InsetCommandMailer::params2string("url", p);
1147 bv->showInsetDialog("url", data, 0);
1151 case LFUN_HTML_INSERT: {
1152 InsetCommandParams p("htmlurl");
1153 string const data = InsetCommandMailer::params2string("url", p);
1154 bv->showInsetDialog("url", data, 0);
1158 case LFUN_LABEL_INSERT: {
1159 InsetCommandParams p("label");
1160 // Try to generate a valid label
1161 p["name"] = (cmd.argument().empty()) ?
1162 cur.getPossibleLabel() :
1164 string const data = InsetCommandMailer::params2string("label", p);
1166 if (cmd.argument().empty()) {
1167 bv->showInsetDialog("label", data, 0);
1169 FuncRequest fr(LFUN_INSET_INSERT, data);
1177 case LFUN_LIST_INSERT:
1178 case LFUN_THEOREM_INSERT:
1180 case LFUN_CAPTION_INSERT:
1181 // Open the inset, and move the current selection
1183 doInsertInset(cur, this, cmd, true, true);
1185 updateLabels(*bv->buffer());
1187 case LFUN_NOTE_INSERT:
1188 case LFUN_CHARSTYLE_INSERT:
1189 case LFUN_BOX_INSERT:
1190 case LFUN_BRANCH_INSERT:
1191 case LFUN_BIBITEM_INSERT:
1192 case LFUN_ERT_INSERT:
1193 case LFUN_LISTING_INSERT:
1194 case LFUN_FOOTNOTE_INSERT:
1195 case LFUN_MARGINALNOTE_INSERT:
1196 case LFUN_OPTIONAL_INSERT:
1197 case LFUN_ENVIRONMENT_INSERT:
1198 // Open the inset, and move the current selection
1200 doInsertInset(cur, this, cmd, true, true);
1204 case LFUN_TABULAR_INSERT:
1205 // if there were no arguments, just open the dialog
1206 if (doInsertInset(cur, this, cmd, false, true))
1209 bv->showDialog("tabularcreate");
1213 case LFUN_FLOAT_INSERT:
1214 case LFUN_FLOAT_WIDE_INSERT:
1215 case LFUN_WRAP_INSERT: {
1216 bool content = cur.selection(); // will some text be moved into the inset?
1218 doInsertInset(cur, this, cmd, true, true);
1220 ParagraphList & pars = cur.text()->paragraphs();
1222 TextClass const & tclass = bv->buffer()->params().getTextClass();
1224 // add a separate paragraph for the caption inset
1225 pars.push_back(Paragraph());
1226 pars.back().setInsetOwner(pars[0].inInset());
1227 pars.back().layout(tclass.defaultLayout());
1229 int cap_pit = pars.size() - 1;
1231 // if an empty inset was created, we create an additional empty
1232 // paragraph at the bottom so that the user can choose where to put
1233 // the graphics (or table).
1235 pars.push_back(Paragraph());
1236 pars.back().setInsetOwner(pars[0].inInset());
1237 pars.back().layout(tclass.defaultLayout());
1241 // reposition the cursor to the caption
1242 cur.pit() = cap_pit;
1244 cur.dispatch(FuncRequest(LFUN_CAPTION_INSERT));
1245 // FIXME: When leaving the Float (or Wrap) inset we should
1246 // delete any empty paragraph left above or below the
1251 case LFUN_INDEX_INSERT:
1252 case LFUN_NOMENCL_INSERT: {
1253 Inset * inset = createInset(&cur.bv(), cmd);
1257 cur.clearSelection();
1258 insertInset(cur, inset);
1259 inset->edit(cur, true);
1260 // Show the dialog for the nomenclature entry, since the
1261 // description entry still needs to be filled in.
1262 if (cmd.action == LFUN_NOMENCL_INSERT)
1263 InsetCommandMailer("nomenclature",
1264 *reinterpret_cast<InsetCommand *>(inset)).showDialog(&cur.bv());
1269 case LFUN_INDEX_PRINT:
1270 case LFUN_NOMENCL_PRINT:
1271 case LFUN_TOC_INSERT:
1272 case LFUN_HFILL_INSERT:
1273 case LFUN_LINE_INSERT:
1274 case LFUN_PAGEBREAK_INSERT:
1275 case LFUN_CLEARPAGE_INSERT:
1276 case LFUN_CLEARDOUBLEPAGE_INSERT:
1278 doInsertInset(cur, this, cmd, false, false);
1282 case LFUN_DEPTH_DECREMENT:
1283 changeDepth(cur, DEC_DEPTH);
1286 case LFUN_DEPTH_INCREMENT:
1287 changeDepth(cur, INC_DEPTH);
1290 case LFUN_MATH_DISPLAY:
1291 mathDispatch(cur, cmd, true);
1294 case LFUN_MATH_IMPORT_SELECTION:
1295 case LFUN_MATH_MODE:
1296 if (cmd.argument() == "on")
1297 // don't pass "on" as argument
1298 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1300 mathDispatch(cur, cmd, false);
1303 case LFUN_MATH_MACRO:
1304 if (cmd.argument().empty())
1305 cur.errorMessage(from_utf8(N_("Missing argument")));
1307 string s = to_utf8(cmd.argument());
1308 string const s1 = token(s, ' ', 1);
1309 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1310 string const s2 = token(s, ' ', 2);
1311 string const type = s2.empty() ? "newcommand" : s2;
1312 cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, from_utf8(type)));
1313 //cur.nextInset()->edit(cur, true);
1317 // passthrough hat and underscore outside mathed:
1318 case LFUN_MATH_SUBSCRIPT:
1319 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1321 case LFUN_MATH_SUPERSCRIPT:
1322 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1325 case LFUN_MATH_INSERT:
1326 case LFUN_MATH_MATRIX:
1327 case LFUN_MATH_DELIM:
1328 case LFUN_MATH_BIGDELIM: {
1329 cur.insert(new InsetMathHull(hullSimple));
1330 cur.dispatch(FuncRequest(LFUN_CHAR_FORWARD));
1331 BOOST_ASSERT(cur.inMathed());
1336 case LFUN_FONT_EMPH: {
1337 Font font(Font::ALL_IGNORE);
1338 font.setEmph(Font::TOGGLE);
1339 toggleAndShow(cur, this, font);
1343 case LFUN_FONT_BOLD: {
1344 Font font(Font::ALL_IGNORE);
1345 font.setSeries(Font::BOLD_SERIES);
1346 toggleAndShow(cur, this, font);
1350 case LFUN_FONT_NOUN: {
1351 Font font(Font::ALL_IGNORE);
1352 font.setNoun(Font::TOGGLE);
1353 toggleAndShow(cur, this, font);
1357 case LFUN_FONT_CODE: {
1358 Font font(Font::ALL_IGNORE);
1359 font.setFamily(Font::TYPEWRITER_FAMILY); // no good
1360 toggleAndShow(cur, this, font);
1364 case LFUN_FONT_SANS: {
1365 Font font(Font::ALL_IGNORE);
1366 font.setFamily(Font::SANS_FAMILY);
1367 toggleAndShow(cur, this, font);
1371 case LFUN_FONT_ROMAN: {
1372 Font font(Font::ALL_IGNORE);
1373 font.setFamily(Font::ROMAN_FAMILY);
1374 toggleAndShow(cur, this, font);
1378 case LFUN_FONT_DEFAULT: {
1379 Font font(Font::ALL_INHERIT, ignore_language);
1380 toggleAndShow(cur, this, font);
1384 case LFUN_FONT_UNDERLINE: {
1385 Font font(Font::ALL_IGNORE);
1386 font.setUnderbar(Font::TOGGLE);
1387 toggleAndShow(cur, this, font);
1391 case LFUN_FONT_SIZE: {
1392 Font font(Font::ALL_IGNORE);
1393 font.setLyXSize(to_utf8(cmd.argument()));
1394 toggleAndShow(cur, this, font);
1398 case LFUN_LANGUAGE: {
1399 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1402 Font font(Font::ALL_IGNORE);
1403 font.setLanguage(lang);
1404 toggleAndShow(cur, this, font);
1409 case LFUN_FONT_FREE_APPLY:
1410 toggleAndShow(cur, this, freefont, toggleall);
1411 cur.message(_("Character set"));
1414 // Set the freefont using the contents of \param data dispatched from
1415 // the frontends and apply it at the current cursor location.
1416 case LFUN_FONT_FREE_UPDATE: {
1419 if (bv_funcs::string2font(to_utf8(cmd.argument()), font, toggle)) {
1422 toggleAndShow(cur, this, freefont, toggleall);
1423 cur.message(_("Character set"));
1428 case LFUN_FINISHED_LEFT:
1429 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1430 if (reverseDirectionNeeded(cur))
1434 case LFUN_FINISHED_RIGHT:
1435 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1436 if (!reverseDirectionNeeded(cur))
1440 case LFUN_LAYOUT_PARAGRAPH: {
1442 params2string(cur.paragraph(), data);
1443 data = "show\n" + data;
1444 bv->showDialogWithData("paragraph", data);
1448 case LFUN_PARAGRAPH_UPDATE: {
1450 params2string(cur.paragraph(), data);
1452 // Will the paragraph accept changes from the dialog?
1453 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1455 data = "update " + convert<string>(accept) + '\n' + data;
1456 bv->updateDialog("paragraph", data);
1460 case LFUN_ACCENT_UMLAUT:
1461 case LFUN_ACCENT_CIRCUMFLEX:
1462 case LFUN_ACCENT_GRAVE:
1463 case LFUN_ACCENT_ACUTE:
1464 case LFUN_ACCENT_TILDE:
1465 case LFUN_ACCENT_CEDILLA:
1466 case LFUN_ACCENT_MACRON:
1467 case LFUN_ACCENT_DOT:
1468 case LFUN_ACCENT_UNDERDOT:
1469 case LFUN_ACCENT_UNDERBAR:
1470 case LFUN_ACCENT_CARON:
1471 case LFUN_ACCENT_SPECIAL_CARON:
1472 case LFUN_ACCENT_BREVE:
1473 case LFUN_ACCENT_TIE:
1474 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1475 case LFUN_ACCENT_CIRCLE:
1476 case LFUN_ACCENT_OGONEK:
1477 theLyXFunc().handleKeyFunc(cmd.action);
1478 if (!cmd.argument().empty())
1479 // FIXME: Are all these characters encoded in one byte in utf8?
1480 bv->getIntl().getTransManager()
1481 .translateAndInsert(cmd.argument()[0], this, cur);
1484 case LFUN_FLOAT_LIST: {
1485 TextClass const & tclass = bv->buffer()->params().getTextClass();
1486 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1487 // not quite sure if we want this...
1489 cur.clearSelection();
1490 breakParagraph(cur);
1492 if (cur.lastpos() != 0) {
1494 breakParagraph(cur);
1497 setLayout(cur, tclass.defaultLayoutName());
1498 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, docstring(), 0);
1499 insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1502 lyxerr << "Non-existent float type: "
1503 << to_utf8(cmd.argument()) << endl;
1508 case LFUN_CHANGE_ACCEPT: {
1509 acceptOrRejectChanges(cur, ACCEPT);
1513 case LFUN_CHANGE_REJECT: {
1514 acceptOrRejectChanges(cur, REJECT);
1518 case LFUN_THESAURUS_ENTRY: {
1519 docstring arg = cmd.argument();
1521 arg = cur.selectionAsString(false);
1523 if (arg.size() > 100 || arg.empty()) {
1524 // Get word or selection
1525 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1526 arg = cur.selectionAsString(false);
1529 bv->showDialogWithData("thesaurus", to_utf8(arg));
1533 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1534 // Given data, an encoding of the ParagraphParameters
1535 // generated in the Paragraph dialog, this function sets
1536 // the current paragraph appropriately.
1537 istringstream is(to_utf8(cmd.argument()));
1540 ParagraphParameters params;
1545 params.labelWidthString(),
1547 cur.message(_("Paragraph layout set"));
1552 if (cur.selection()) {
1553 cur.selection() = false;
1557 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1562 LYXERR(Debug::ACTION)
1563 << BOOST_CURRENT_FUNCTION
1564 << ": Command " << cmd
1565 << " not DISPATCHED by Text" << endl;
1570 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1572 // FIXME: The cursor flag is reset two lines below
1573 // so we need to check here if some of the LFUN did touch that.
1574 // for now only Text::erase() and Text::backspace() do that.
1575 // The plan is to verify all the LFUNs and then to remove this
1576 // singleParUpdate boolean altogether.
1577 if (cur.result().update() & Update::Force) {
1578 singleParUpdate = false;
1582 // FIXME: the following code should go in favor of fine grained
1583 // update flag treatment.
1584 if (singleParUpdate) {
1585 // Inserting characters does not change par height
1586 ParagraphMetrics const & pms
1587 = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
1588 if (pms.dim().height()
1589 == olddim.height()) {
1590 // if so, update _only_ this paragraph
1591 cur.updateFlags(Update::SinglePar |
1593 Update::MultiParSel);
1600 && &oldTopSlice.inset() == &cur.inset()
1601 && oldTopSlice.idx() == cur.idx()
1602 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1603 && !cur.selection())
1604 // FIXME: it would be better if we could just do this
1606 //if (cur.result().update() != Update::FitCursor)
1609 // But some LFUNs do not set Update::FitCursor when needed, so we
1610 // do it for all. This is not very harmfull as FitCursor will provoke
1611 // a full redraw only if needed but still, a proper review of all LFUN
1612 // should be done and this needsUpdate boolean can then be removed.
1613 cur.updateFlags(Update::FitCursor);
1615 cur.updateFlags(Update::Force | Update::FitCursor);
1619 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
1620 FuncStatus & flag) const
1622 BOOST_ASSERT(cur.text() == this);
1624 Font const & font = real_current_font;
1626 Inset::Code code = Inset::NO_CODE;
1628 switch (cmd.action) {
1630 case LFUN_DEPTH_DECREMENT:
1631 enable = changeDepthAllowed(cur, DEC_DEPTH);
1634 case LFUN_DEPTH_INCREMENT:
1635 enable = changeDepthAllowed(cur, INC_DEPTH);
1639 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1642 case LFUN_BIBITEM_INSERT:
1643 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO
1647 case LFUN_DIALOG_SHOW_NEW_INSET:
1648 if (cmd.argument() == "bibitem")
1649 code = Inset::BIBITEM_CODE;
1650 else if (cmd.argument() == "bibtex")
1651 code = Inset::BIBTEX_CODE;
1652 else if (cmd.argument() == "box")
1653 code = Inset::BOX_CODE;
1654 else if (cmd.argument() == "branch")
1655 code = Inset::BRANCH_CODE;
1656 else if (cmd.argument() == "citation")
1657 code = Inset::CITE_CODE;
1658 else if (cmd.argument() == "ert")
1659 code = Inset::ERT_CODE;
1660 else if (cmd.argument() == "external")
1661 code = Inset::EXTERNAL_CODE;
1662 else if (cmd.argument() == "float")
1663 code = Inset::FLOAT_CODE;
1664 else if (cmd.argument() == "graphics")
1665 code = Inset::GRAPHICS_CODE;
1666 else if (cmd.argument() == "include")
1667 code = Inset::INCLUDE_CODE;
1668 else if (cmd.argument() == "index")
1669 code = Inset::INDEX_CODE;
1670 else if (cmd.argument() == "nomenclature")
1671 code = Inset::NOMENCL_CODE;
1672 else if (cmd.argument() == "label")
1673 code = Inset::LABEL_CODE;
1674 else if (cmd.argument() == "note")
1675 code = Inset::NOTE_CODE;
1676 else if (cmd.argument() == "ref")
1677 code = Inset::REF_CODE;
1678 else if (cmd.argument() == "toc")
1679 code = Inset::TOC_CODE;
1680 else if (cmd.argument() == "url")
1681 code = Inset::URL_CODE;
1682 else if (cmd.argument() == "vspace")
1683 code = Inset::VSPACE_CODE;
1684 else if (cmd.argument() == "wrap")
1685 code = Inset::WRAP_CODE;
1686 else if (cmd.argument() == "listings")
1687 code = Inset::LISTINGS_CODE;
1690 case LFUN_ERT_INSERT:
1691 code = Inset::ERT_CODE;
1693 case LFUN_LISTING_INSERT:
1694 code = Inset::LISTINGS_CODE;
1696 case LFUN_FOOTNOTE_INSERT:
1697 code = Inset::FOOT_CODE;
1699 case LFUN_TABULAR_INSERT:
1700 code = Inset::TABULAR_CODE;
1702 case LFUN_MARGINALNOTE_INSERT:
1703 code = Inset::MARGIN_CODE;
1705 case LFUN_FLOAT_INSERT:
1706 case LFUN_FLOAT_WIDE_INSERT:
1707 code = Inset::FLOAT_CODE;
1709 case LFUN_WRAP_INSERT:
1710 code = Inset::WRAP_CODE;
1712 case LFUN_FLOAT_LIST:
1713 code = Inset::FLOAT_LIST_CODE;
1716 case LFUN_LIST_INSERT:
1717 code = Inset::LIST_CODE;
1719 case LFUN_THEOREM_INSERT:
1720 code = Inset::THEOREM_CODE;
1723 case LFUN_CAPTION_INSERT:
1724 code = Inset::CAPTION_CODE;
1726 case LFUN_NOTE_INSERT:
1727 code = Inset::NOTE_CODE;
1729 case LFUN_CHARSTYLE_INSERT:
1730 code = Inset::CHARSTYLE_CODE;
1731 if (cur.buffer().params().getTextClass().charstyles().empty())
1734 case LFUN_BOX_INSERT:
1735 code = Inset::BOX_CODE;
1737 case LFUN_BRANCH_INSERT:
1738 code = Inset::BRANCH_CODE;
1739 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1742 case LFUN_LABEL_INSERT:
1743 code = Inset::LABEL_CODE;
1745 case LFUN_OPTIONAL_INSERT:
1746 code = Inset::OPTARG_CODE;
1747 enable = numberOfOptArgs(cur.paragraph())
1748 < cur.paragraph().layout()->optionalargs;
1750 case LFUN_ENVIRONMENT_INSERT:
1751 code = Inset::BOX_CODE;
1753 case LFUN_INDEX_INSERT:
1754 code = Inset::INDEX_CODE;
1756 case LFUN_INDEX_PRINT:
1757 code = Inset::INDEX_PRINT_CODE;
1759 case LFUN_NOMENCL_INSERT:
1760 code = Inset::NOMENCL_CODE;
1762 case LFUN_NOMENCL_PRINT:
1763 code = Inset::NOMENCL_PRINT_CODE;
1765 case LFUN_TOC_INSERT:
1766 code = Inset::TOC_CODE;
1768 case LFUN_HTML_INSERT:
1769 case LFUN_URL_INSERT:
1770 code = Inset::URL_CODE;
1772 case LFUN_QUOTE_INSERT:
1773 // always allow this, since we will inset a raw quote
1774 // if an inset is not allowed.
1776 case LFUN_HYPHENATION_POINT_INSERT:
1777 case LFUN_LIGATURE_BREAK_INSERT:
1778 case LFUN_HFILL_INSERT:
1779 case LFUN_MENU_SEPARATOR_INSERT:
1780 case LFUN_DOTS_INSERT:
1781 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
1782 code = Inset::SPECIALCHAR_CODE;
1784 case LFUN_SPACE_INSERT:
1785 // slight hack: we know this is allowed in math mode
1787 code = Inset::SPACE_CODE;
1790 case LFUN_INSET_MODIFY:
1791 // We need to disable this, because we may get called for a
1793 // InsetTabular::getStatus() -> InsetText::getStatus()
1794 // and we don't handle LFUN_INSET_MODIFY.
1798 case LFUN_FONT_EMPH:
1799 flag.setOnOff(font.emph() == Font::ON);
1802 case LFUN_FONT_NOUN:
1803 flag.setOnOff(font.noun() == Font::ON);
1806 case LFUN_FONT_BOLD:
1807 flag.setOnOff(font.series() == Font::BOLD_SERIES);
1810 case LFUN_FONT_SANS:
1811 flag.setOnOff(font.family() == Font::SANS_FAMILY);
1814 case LFUN_FONT_ROMAN:
1815 flag.setOnOff(font.family() == Font::ROMAN_FAMILY);
1818 case LFUN_FONT_CODE:
1819 flag.setOnOff(font.family() == Font::TYPEWRITER_FAMILY);
1824 enable = cur.selection();
1828 if (cmd.argument().empty()) {
1829 if (theClipboard().isInternal())
1830 enable = cap::numberOfSelections() > 0;
1832 enable = !theClipboard().empty();
1834 string const arg = to_utf8(cmd.argument());
1835 if (isStrUnsignedInt(arg)) {
1836 unsigned int n = convert<unsigned int>(arg);
1837 enable = cap::numberOfSelections() > n;
1844 case LFUN_CLIPBOARD_PASTE:
1845 enable = !theClipboard().empty();
1848 case LFUN_PRIMARY_SELECTION_PASTE:
1849 enable = cur.selection() || !theSelection().empty();
1852 case LFUN_PARAGRAPH_MOVE_UP:
1853 enable = cur.pit() > 0 && !cur.selection();
1856 case LFUN_PARAGRAPH_MOVE_DOWN:
1857 enable = cur.pit() < cur.lastpit() && !cur.selection();
1860 case LFUN_INSET_DISSOLVE:
1861 enable = !isMainText(*cur.bv().buffer()) && cur.inset().nargs() == 1;
1864 case LFUN_CHANGE_ACCEPT:
1865 case LFUN_CHANGE_REJECT:
1866 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
1867 // In principle, these LFUNs should only be enabled if there
1868 // is a change at the current position/in the current selection.
1869 // However, without proper optimizations, this will inevitably
1870 // result in unacceptable performance - just imagine a user who
1871 // wants to select the complete content of a long document.
1875 case LFUN_WORD_DELETE_FORWARD:
1876 case LFUN_WORD_DELETE_BACKWARD:
1877 case LFUN_LINE_DELETE:
1878 case LFUN_WORD_FORWARD:
1879 case LFUN_WORD_BACKWARD:
1880 case LFUN_CHAR_FORWARD:
1881 case LFUN_CHAR_FORWARD_SELECT:
1882 case LFUN_CHAR_BACKWARD:
1883 case LFUN_CHAR_BACKWARD_SELECT:
1885 case LFUN_UP_SELECT:
1887 case LFUN_DOWN_SELECT:
1888 case LFUN_PARAGRAPH_UP_SELECT:
1889 case LFUN_PARAGRAPH_DOWN_SELECT:
1890 case LFUN_SCREEN_UP_SELECT:
1891 case LFUN_SCREEN_DOWN_SELECT:
1892 case LFUN_LINE_BEGIN_SELECT:
1893 case LFUN_LINE_END_SELECT:
1894 case LFUN_WORD_FORWARD_SELECT:
1895 case LFUN_WORD_BACKWARD_SELECT:
1896 case LFUN_WORD_SELECT:
1897 case LFUN_PARAGRAPH_UP:
1898 case LFUN_PARAGRAPH_DOWN:
1899 case LFUN_SCREEN_UP:
1900 case LFUN_SCREEN_DOWN:
1901 case LFUN_LINE_BEGIN:
1903 case LFUN_BREAK_LINE:
1904 case LFUN_CHAR_DELETE_FORWARD:
1905 case LFUN_DELETE_FORWARD_SKIP:
1906 case LFUN_CHAR_DELETE_BACKWARD:
1907 case LFUN_DELETE_BACKWARD_SKIP:
1908 case LFUN_BREAK_PARAGRAPH:
1909 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
1910 case LFUN_BREAK_PARAGRAPH_SKIP:
1911 case LFUN_PARAGRAPH_SPACING:
1912 case LFUN_INSET_INSERT:
1913 case LFUN_WORD_UPCASE:
1914 case LFUN_WORD_LOWCASE:
1915 case LFUN_WORD_CAPITALIZE:
1916 case LFUN_CHARS_TRANSPOSE:
1917 case LFUN_SERVER_GET_XY:
1918 case LFUN_SERVER_SET_XY:
1919 case LFUN_SERVER_GET_FONT:
1920 case LFUN_SERVER_GET_LAYOUT:
1922 case LFUN_DATE_INSERT:
1923 case LFUN_SELF_INSERT:
1924 case LFUN_LINE_INSERT:
1925 case LFUN_PAGEBREAK_INSERT:
1926 case LFUN_CLEARPAGE_INSERT:
1927 case LFUN_CLEARDOUBLEPAGE_INSERT:
1928 case LFUN_MATH_DISPLAY:
1929 case LFUN_MATH_IMPORT_SELECTION:
1930 case LFUN_MATH_MODE:
1931 case LFUN_MATH_MACRO:
1932 case LFUN_MATH_MATRIX:
1933 case LFUN_MATH_DELIM:
1934 case LFUN_MATH_BIGDELIM:
1935 case LFUN_MATH_SUBSCRIPT:
1936 case LFUN_MATH_SUPERSCRIPT:
1937 case LFUN_FONT_DEFAULT:
1938 case LFUN_FONT_UNDERLINE:
1939 case LFUN_FONT_SIZE:
1941 case LFUN_FONT_FREE_APPLY:
1942 case LFUN_FONT_FREE_UPDATE:
1943 case LFUN_LAYOUT_PARAGRAPH:
1944 case LFUN_PARAGRAPH_UPDATE:
1945 case LFUN_ACCENT_UMLAUT:
1946 case LFUN_ACCENT_CIRCUMFLEX:
1947 case LFUN_ACCENT_GRAVE:
1948 case LFUN_ACCENT_ACUTE:
1949 case LFUN_ACCENT_TILDE:
1950 case LFUN_ACCENT_CEDILLA:
1951 case LFUN_ACCENT_MACRON:
1952 case LFUN_ACCENT_DOT:
1953 case LFUN_ACCENT_UNDERDOT:
1954 case LFUN_ACCENT_UNDERBAR:
1955 case LFUN_ACCENT_CARON:
1956 case LFUN_ACCENT_SPECIAL_CARON:
1957 case LFUN_ACCENT_BREVE:
1958 case LFUN_ACCENT_TIE:
1959 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1960 case LFUN_ACCENT_CIRCLE:
1961 case LFUN_ACCENT_OGONEK:
1962 case LFUN_THESAURUS_ENTRY:
1963 case LFUN_PARAGRAPH_PARAMS_APPLY:
1965 case LFUN_BUFFER_END:
1966 case LFUN_BUFFER_BEGIN:
1967 case LFUN_BUFFER_BEGIN_SELECT:
1968 case LFUN_BUFFER_END_SELECT:
1969 case LFUN_UNICODE_INSERT:
1970 // these are handled in our dispatch()
1978 if (code != Inset::NO_CODE
1979 && (cur.empty() || !cur.inset().insetAllowed(code)))
1982 flag.enabled(enable);
1987 void Text::pasteString(Cursor & cur, docstring const & clip,
1990 cur.clearSelection();
1991 if (!clip.empty()) {
1994 insertStringAsParagraphs(cur, clip);
1996 insertStringAsLines(cur, clip);