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>
76 using std::istringstream;
77 using std::ostringstream;
81 using cap::copySelection;
82 using cap::cutSelection;
83 using cap::pasteFromStack;
84 using cap::pasteClipboard;
85 using cap::replaceSelection;
87 using support::isStrUnsignedInt;
91 extern docstring current_layout;
97 Font freefont(Font::ALL_IGNORE);
98 bool toggleall = false;
100 void toggleAndShow(Cursor & cur, Text * text,
101 Font const & font, bool toggleall = true)
103 text->toggleFree(cur, font, toggleall);
105 if (font.language() != ignore_language ||
106 font.number() != Font::IGNORE) {
107 Paragraph & par = cur.paragraph();
108 if (cur.boundary() != text->isRTLBoundary(cur.buffer(), par,
109 cur.pos(), text->real_current_font))
110 text->setCursor(cur, cur.pit(), cur.pos(),
111 false, !cur.boundary());
116 void moveCursor(Cursor & cur, bool selecting)
118 if (selecting || cur.mark())
123 void finishChange(Cursor & cur, bool selecting)
126 moveCursor(cur, selecting);
130 void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
133 docstring sel = cur.selectionAsString(false);
135 // It may happen that sel is empty but there is a selection
136 replaceSelection(cur);
139 #ifdef ENABLE_ASSERTIONS
140 const int old_pos = cur.pos();
142 cur.insert(new InsetMathHull(hullSimple));
143 BOOST_ASSERT(old_pos == cur.pos());
144 cur.nextInset()->edit(cur, true);
145 // don't do that also for LFUN_MATH_MODE
146 // unless you want end up with always changing
147 // to mathrm when opening an inlined inset --
148 // I really hate "LyXfunc overloading"...
150 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
151 // Avoid an unnecessary undo step if cmd.argument
153 if (!cmd.argument().empty())
154 cur.dispatch(FuncRequest(LFUN_MATH_INSERT,
157 // create a macro if we see "\\newcommand"
158 // somewhere, and an ordinary formula
160 if (sel.find(from_ascii("\\newcommand")) == string::npos
161 && sel.find(from_ascii("\\def")) == string::npos)
163 InsetMathHull * formula = new InsetMathHull;
164 istringstream is(to_utf8(sel));
167 formula->read(cur.buffer(), lex);
168 if (formula->getType() == hullNone)
169 // Don't create pseudo formulas if
170 // delimiters are left out
171 formula->mutate(hullSimple);
174 cur.insert(new MathMacroTemplate(sel));
177 cur.message(from_utf8(N_("Math editor mode")));
186 string const freefont2string()
189 if (font2string(freefont, toggleall, data))
199 void specialChar(Cursor & cur, InsetSpecialChar::Kind kind)
202 cap::replaceSelection(cur);
203 cur.insert(new InsetSpecialChar(kind));
208 bool doInsertInset(Cursor & cur, Text * text,
209 FuncRequest const & cmd, bool edit, bool pastesel)
211 Inset * inset = createInset(&cur.bv(), cmd);
217 if (cur.selection()) {
218 lyx::dispatch(FuncRequest(LFUN_CUT));
221 text->insertInset(cur, inset);
224 inset->edit(cur, true);
226 if (gotsel && pastesel) {
227 lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
228 // reset first par to default
229 if (cur.lastpit() != 0 || cur.lastpos() != 0) {
230 LayoutPtr const layout =
231 cur.buffer().params().getTextClass().defaultLayout();
232 cur.text()->paragraphs().begin()->layout(layout);
242 void Text::number(Cursor & cur)
244 Font font(Font::ALL_IGNORE);
245 font.setNumber(Font::TOGGLE);
246 toggleAndShow(cur, this, font);
250 bool Text::isRTL(Buffer const & buffer, Paragraph const & par) const
252 return par.isRightToLeftPar(buffer.params());
256 bool Text::isRTL(Buffer const & buffer, CursorSlice const & sl, bool boundary) const
258 if (!lyxrc.rtl_support && !sl.text())
262 if (boundary && sl.pos() > 0)
265 Paragraph const & par = getPar(sl.pit());
266 return getFont(buffer, par, sl.pos() + correction).isVisibleRightToLeft();
270 bool Text::isRTLBoundary(Buffer const & buffer, Paragraph const & par,
273 if (!lyxrc.rtl_support)
276 // no RTL boundary at line start
280 bool left = getFont(buffer, par, pos - 1).isVisibleRightToLeft();
282 if (pos == par.size())
283 right = par.isRightToLeftPar(buffer.params());
285 right = getFont(buffer, par, pos).isVisibleRightToLeft();
286 return left != right;
290 bool Text::isRTLBoundary(Buffer const & buffer, Paragraph const & par,
291 pos_type pos, Font const & font) const
293 if (!lyxrc.rtl_support)
296 bool left = font.isVisibleRightToLeft();
298 if (pos == par.size())
299 right = par.isRightToLeftPar(buffer.params());
301 right = getFont(buffer, par, pos).isVisibleRightToLeft();
302 return left != right;
306 void Text::dispatch(Cursor & cur, FuncRequest & cmd)
308 LYXERR(Debug::ACTION) << "Text::dispatch: cmd: " << cmd << endl;
310 // FIXME: We use the update flag to indicates wether a singlePar or a
311 // full screen update is needed. We reset it here but shall we restore it
315 BOOST_ASSERT(cur.text() == this);
316 BufferView * bv = &cur.bv();
317 TextMetrics & tm = cur.bv().textMetrics(this);
318 CursorSlice oldTopSlice = cur.top();
319 bool oldBoundary = cur.boundary();
320 bool sel = cur.selection();
321 // Signals that, even if needsUpdate == false, an update of the
322 // cursor paragraph is required
323 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
324 LyXAction::SingleParUpdate);
325 // Signals that a full-screen update is required
326 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
327 LyXAction::NoUpdate) || singleParUpdate);
328 // Remember the old paragraph metric (_outer_ paragraph!)
329 ParagraphMetrics const & pm = cur.bv().parMetrics(
330 cur.bottom().text(), cur.bottom().pit());
331 Dimension olddim = pm.dim();
333 switch (cmd.action) {
335 case LFUN_PARAGRAPH_MOVE_DOWN: {
336 pit_type const pit = cur.pit();
337 recUndo(cur, pit, pit + 1);
339 std::swap(pars_[pit], pars_[pit + 1]);
340 updateLabels(cur.buffer());
346 case LFUN_PARAGRAPH_MOVE_UP: {
347 pit_type const pit = cur.pit();
348 recUndo(cur, pit - 1, pit);
350 std::swap(pars_[pit], pars_[pit - 1]);
351 updateLabels(cur.buffer());
357 case LFUN_APPENDIX: {
358 Paragraph & par = cur.paragraph();
359 bool start = !par.params().startOfAppendix();
361 // FIXME: The code below only makes sense at top level.
362 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
363 // ensure that we have only one start_of_appendix in this document
364 // FIXME: this don't work for multipart document!
365 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
366 if (pars_[tmp].params().startOfAppendix()) {
368 pars_[tmp].params().startOfAppendix(false);
374 par.params().startOfAppendix(start);
376 // we can set the refreshing parameters now
377 updateLabels(cur.buffer());
381 case LFUN_WORD_DELETE_FORWARD:
382 if (cur.selection()) {
383 cutSelection(cur, true, false);
385 deleteWordForward(cur);
386 finishChange(cur, false);
389 case LFUN_WORD_DELETE_BACKWARD:
390 if (cur.selection()) {
391 cutSelection(cur, true, false);
393 deleteWordBackward(cur);
394 finishChange(cur, false);
397 case LFUN_LINE_DELETE:
398 if (cur.selection()) {
399 cutSelection(cur, true, false);
401 tm.deleteLineForward(cur);
402 finishChange(cur, false);
405 case LFUN_BUFFER_BEGIN:
406 case LFUN_BUFFER_BEGIN_SELECT:
407 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
408 if (cur.depth() == 1) {
409 needsUpdate |= cursorTop(cur);
415 case LFUN_BUFFER_END:
416 case LFUN_BUFFER_END_SELECT:
417 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
418 if (cur.depth() == 1) {
419 needsUpdate |= cursorBottom(cur);
425 case LFUN_CHAR_FORWARD:
426 case LFUN_CHAR_FORWARD_SELECT:
427 //lyxerr << BOOST_CURRENT_FUNCTION
428 // << " LFUN_CHAR_FORWARD[SEL]:\n" << cur << endl;
429 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
430 if (reverseDirectionNeeded(cur))
431 needsUpdate |= cursorLeft(cur);
433 needsUpdate |= cursorRight(cur);
435 if (!needsUpdate && oldTopSlice == cur.top()
436 && cur.boundary() == oldBoundary) {
438 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
442 case LFUN_CHAR_BACKWARD:
443 case LFUN_CHAR_BACKWARD_SELECT:
444 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
445 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
446 if (reverseDirectionNeeded(cur))
447 needsUpdate |= cursorRight(cur);
449 needsUpdate |= cursorLeft(cur);
451 if (!needsUpdate && oldTopSlice == cur.top()
452 && cur.boundary() == oldBoundary) {
454 cmd = FuncRequest(LFUN_FINISHED_LEFT);
459 case LFUN_DOWN_SELECT:
462 // stop/start the selection
463 bool select = cmd.action == LFUN_DOWN_SELECT ||
464 cmd.action == LFUN_UP_SELECT;
465 cur.selHandle(select);
467 // move cursor up/down
468 bool up = cmd.action == LFUN_UP_SELECT || cmd.action == LFUN_UP;
469 bool const successful = cur.upDownInText(up, needsUpdate);
471 // notify insets which were left and get their update flags
472 notifyCursorLeaves(cur.beforeDispatchCursor(), cur);
475 // redraw if you leave mathed (for the decorations)
476 needsUpdate |= cur.beforeDispatchCursor().inMathed();
483 case LFUN_PARAGRAPH_UP:
484 case LFUN_PARAGRAPH_UP_SELECT:
485 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
486 needsUpdate |= cursorUpParagraph(cur);
489 case LFUN_PARAGRAPH_DOWN:
490 case LFUN_PARAGRAPH_DOWN_SELECT:
491 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
492 needsUpdate |= cursorDownParagraph(cur);
496 case LFUN_SCREEN_UP_SELECT:
497 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_UP_SELECT);
498 if (cur.pit() == 0 && cur.textRow().pos() == 0)
501 tm.cursorPrevious(cur);
505 case LFUN_SCREEN_DOWN:
506 case LFUN_SCREEN_DOWN_SELECT:
507 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_DOWN_SELECT);
508 if (cur.pit() == cur.lastpit()
509 && cur.textRow().endpos() == cur.lastpos())
516 case LFUN_LINE_BEGIN:
517 case LFUN_LINE_BEGIN_SELECT:
518 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
519 needsUpdate |= tm.cursorHome(cur);
523 case LFUN_LINE_END_SELECT:
524 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
525 needsUpdate |= tm.cursorEnd(cur);
528 case LFUN_WORD_FORWARD:
529 case LFUN_WORD_FORWARD_SELECT:
530 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
531 if (reverseDirectionNeeded(cur))
532 needsUpdate |= cursorLeftOneWord(cur);
534 needsUpdate |= cursorRightOneWord(cur);
537 case LFUN_WORD_BACKWARD:
538 case LFUN_WORD_BACKWARD_SELECT:
539 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
540 if (reverseDirectionNeeded(cur))
541 needsUpdate |= cursorRightOneWord(cur);
543 needsUpdate |= cursorLeftOneWord(cur);
546 case LFUN_WORD_SELECT: {
547 selectWord(cur, WHOLE_WORD);
548 finishChange(cur, true);
552 case LFUN_BREAK_LINE: {
553 // Not allowed by LaTeX (labels or empty par)
554 if (cur.pos() > cur.paragraph().beginOfBody()) {
555 // this avoids a double undo
556 // FIXME: should not be needed, ideally
557 if (!cur.selection())
559 cap::replaceSelection(cur);
560 cur.insert(new InsetNewline);
562 moveCursor(cur, false);
567 case LFUN_CHAR_DELETE_FORWARD:
568 if (!cur.selection()) {
569 if (cur.pos() == cur.paragraph().size())
570 // Par boundary, force full-screen update
571 singleParUpdate = false;
572 needsUpdate |= erase(cur);
574 // It is possible to make it a lot faster still
575 // just comment out the line below...
577 cutSelection(cur, true, false);
578 singleParUpdate = false;
580 moveCursor(cur, false);
583 case LFUN_DELETE_FORWARD_SKIP:
584 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
585 if (!cur.selection()) {
586 if (cur.pos() == cur.lastpos()) {
593 cutSelection(cur, true, false);
598 case LFUN_CHAR_DELETE_BACKWARD:
599 if (!cur.selection()) {
600 if (bv->getIntl().getTransManager().backspace()) {
601 // Par boundary, full-screen update
603 singleParUpdate = false;
604 needsUpdate |= backspace(cur);
606 // It is possible to make it a lot faster still
607 // just comment out the line below...
610 cutSelection(cur, true, false);
611 singleParUpdate = false;
615 case LFUN_DELETE_BACKWARD_SKIP:
616 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
617 if (!cur.selection()) {
619 //CursorSlice cur = cursor();
623 cutSelection(cur, true, false);
627 case LFUN_BREAK_PARAGRAPH:
628 cap::replaceSelection(cur);
629 breakParagraph(cur, 0);
633 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
634 cap::replaceSelection(cur);
635 breakParagraph(cur, 1);
639 case LFUN_BREAK_PARAGRAPH_SKIP: {
640 // When at the beginning of a paragraph, remove
641 // indentation. Otherwise, do the same as LFUN_BREAK_PARAGRAPH.
642 cap::replaceSelection(cur);
644 cur.paragraph().params().labelWidthString(docstring());
646 breakParagraph(cur, 0);
652 // With the creation of LFUN_PARAGRAPH_PARAMS, this is now redundant,
653 // as its duties can be performed there. Should it be removed??
654 // FIXME For now, it can just dispatch LFUN_PARAGRAPH_PARAMS...
655 case LFUN_PARAGRAPH_SPACING: {
656 Paragraph & par = cur.paragraph();
657 Spacing::Space cur_spacing = par.params().spacing().getSpace();
658 string cur_value = "1.0";
659 if (cur_spacing == Spacing::Other)
660 cur_value = par.params().spacing().getValueAsString();
662 istringstream is(to_utf8(cmd.argument()));
665 Spacing::Space new_spacing = cur_spacing;
666 string new_value = cur_value;
668 lyxerr << "Missing argument to `paragraph-spacing'"
670 } else if (tmp == "single") {
671 new_spacing = Spacing::Single;
672 } else if (tmp == "onehalf") {
673 new_spacing = Spacing::Onehalf;
674 } else if (tmp == "double") {
675 new_spacing = Spacing::Double;
676 } else if (tmp == "other") {
677 new_spacing = Spacing::Other;
678 string tmpval = "0.0";
680 lyxerr << "new_value = " << tmpval << endl;
683 } else if (tmp == "default") {
684 new_spacing = Spacing::Default;
686 lyxerr << to_utf8(_("Unknown spacing argument: "))
687 << to_utf8(cmd.argument()) << endl;
689 if (cur_spacing != new_spacing || cur_value != new_value)
690 par.params().spacing(Spacing(new_spacing, new_value));
694 case LFUN_INSET_INSERT: {
696 Inset * inset = createInset(bv, cmd);
698 // FIXME (Abdel 01/02/2006):
699 // What follows would be a partial fix for bug 2154:
700 // http://bugzilla.lyx.org/show_bug.cgi?id=2154
701 // This automatically put the label inset _after_ a
702 // numbered section. It should be possible to extend the mechanism
703 // to any kind of LateX environement.
704 // The correct way to fix that bug would be at LateX generation.
705 // I'll let the code here for reference as it could be used for some
706 // other feature like "automatic labelling".
708 Paragraph & par = pars_[cur.pit()];
709 if (inset->lyxCode() == Inset::LABEL_CODE
710 && par.layout()->labeltype == LABEL_COUNTER) {
711 // Go to the end of the paragraph
712 // Warning: Because of Change-Tracking, the last
713 // position is 'size()' and not 'size()-1':
714 cur.pos() = par.size();
715 // Insert a new paragraph
716 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
721 cutSelection(cur, true, false);
722 insertInset(cur, inset);
728 case LFUN_INSET_DISSOLVE:
729 needsUpdate |= dissolveInset(cur);
732 case LFUN_INSET_SETTINGS:
733 cur.inset().showInsetDialog(bv);
736 case LFUN_SPACE_INSERT:
737 if (cur.paragraph().layout()->free_spacing)
738 insertChar(cur, ' ');
740 doInsertInset(cur, this, cmd, false, false);
743 moveCursor(cur, false);
746 case LFUN_HYPHENATION_POINT_INSERT:
747 specialChar(cur, InsetSpecialChar::HYPHENATION);
750 case LFUN_LIGATURE_BREAK_INSERT:
751 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
754 case LFUN_DOTS_INSERT:
755 specialChar(cur, InsetSpecialChar::LDOTS);
758 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
759 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
762 case LFUN_MENU_SEPARATOR_INSERT:
763 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
766 case LFUN_WORD_UPCASE:
767 changeCase(cur, Text::text_uppercase);
770 case LFUN_WORD_LOWCASE:
771 changeCase(cur, Text::text_lowercase);
774 case LFUN_WORD_CAPITALIZE:
775 changeCase(cur, Text::text_capitalization);
778 case LFUN_CHARS_TRANSPOSE:
783 cur.message(_("Paste"));
784 cap::replaceSelection(cur);
785 if (cmd.argument().empty() && !theClipboard().isInternal())
786 pasteClipboard(cur, bv->buffer().errorList("Paste"));
788 string const arg(to_utf8(cmd.argument()));
789 pasteFromStack(cur, bv->buffer().errorList("Paste"),
790 isStrUnsignedInt(arg) ?
791 convert<unsigned int>(arg) :
794 bv->buffer().errors("Paste");
795 cur.clearSelection(); // bug 393
800 cutSelection(cur, true, true);
801 cur.message(_("Cut"));
806 cur.message(_("Copy"));
809 case LFUN_SERVER_GET_XY:
810 cur.message(from_utf8(
811 convert<string>(tm.cursorX(cur.top(), cur.boundary()))
812 + ' ' + convert<string>(tm.cursorY(cur.top(), cur.boundary()))));
815 case LFUN_SERVER_SET_XY: {
818 istringstream is(to_utf8(cmd.argument()));
821 lyxerr << "SETXY: Could not parse coordinates in '"
822 << to_utf8(cmd.argument()) << std::endl;
824 tm.setCursorFromCoordinates(cur, x, y);
828 case LFUN_SERVER_GET_FONT:
829 if (current_font.shape() == Font::ITALIC_SHAPE)
830 cur.message(from_ascii("E"));
831 else if (current_font.shape() == Font::SMALLCAPS_SHAPE)
832 cur.message(from_ascii("N"));
834 cur.message(from_ascii("0"));
837 case LFUN_SERVER_GET_LAYOUT:
838 cur.message(cur.paragraph().layout()->name());
842 docstring layout = cmd.argument();
843 LYXERR(Debug::INFO) << "LFUN_LAYOUT: (arg) " << to_utf8(layout) << endl;
845 // Derive layout number from given argument (string)
846 // and current buffer's textclass (number)
847 TextClass const & tclass = bv->buffer().params().getTextClass();
849 layout = tclass.defaultLayoutName();
850 bool hasLayout = tclass.hasLayout(layout);
852 // If the entry is obsolete, use the new one instead.
854 docstring const & obs = tclass[layout]->obsoleted_by();
860 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
861 from_utf8(N_(" not known")));
865 bool change_layout = (frontend::current_layout != layout);
867 if (!change_layout && cur.selection() &&
868 cur.selBegin().pit() != cur.selEnd().pit())
870 pit_type spit = cur.selBegin().pit();
871 pit_type epit = cur.selEnd().pit() + 1;
872 while (spit != epit) {
873 if (pars_[spit].layout()->name() != frontend::current_layout) {
874 change_layout = true;
882 setLayout(cur, layout);
883 // inform the GUI that the layout has changed.
884 bv->layoutChanged(layout);
889 case LFUN_CLIPBOARD_PASTE:
890 cur.clearSelection();
891 pasteClipboard(cur, bv->buffer().errorList("Paste"),
892 cmd.argument() == "paragraph");
893 bv->buffer().errors("Paste");
896 case LFUN_PRIMARY_SELECTION_PASTE:
897 pasteString(cur, theSelection().get(),
898 cmd.argument() == "paragraph");
901 case LFUN_UNICODE_INSERT: {
902 if (cmd.argument().empty())
904 docstring hexstring = cmd.argument();
905 if (lyx::support::isHex(hexstring)) {
906 char_type c = lyx::support::hexToInt(hexstring);
907 if (c >= 32 && c < 0x10ffff) {
908 lyxerr << "Inserting c: " << c << endl;
909 docstring s = docstring(1, c);
910 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
916 case LFUN_QUOTE_INSERT: {
917 Paragraph & par = cur.paragraph();
918 pos_type pos = cur.pos();
919 BufferParams const & bufparams = bv->buffer().params();
920 LayoutPtr const & style = par.layout();
921 if (!style->pass_thru
922 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
923 // this avoids a double undo
924 // FIXME: should not be needed, ideally
925 if (!cur.selection())
927 cap::replaceSelection(cur);
932 else if (cur.prevInset() && cur.prevInset()->isSpace())
935 c = par.getChar(pos - 1);
936 string arg = to_utf8(cmd.argument());
938 cur.insert(new InsetQuotes(c,
939 bufparams.quotes_language,
940 InsetQuotes::SingleQ));
942 cur.insert(new InsetQuotes(c,
943 bufparams.quotes_language,
944 InsetQuotes::DoubleQ));
948 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
952 case LFUN_DATE_INSERT: {
953 string const format = cmd.argument().empty()
954 ? lyxrc.date_insert_format : to_utf8(cmd.argument());
955 string const time = formatted_time(current_time(), format);
956 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, time));
960 case LFUN_MOUSE_TRIPLE:
961 if (cmd.button() == mouse_button::button1) {
970 case LFUN_MOUSE_DOUBLE:
971 if (cmd.button() == mouse_button::button1) {
972 selectWord(cur, WHOLE_WORD_STRICT);
977 // Single-click on work area
978 case LFUN_MOUSE_PRESS: {
979 // Right click on a footnote flag opens float menu
980 if (cmd.button() == mouse_button::button3)
981 cur.clearSelection();
984 bool update = bv->mouseSetCursor(cur);
986 // Insert primary selection with middle mouse
987 // if there is a local selection in the current buffer,
989 if (cmd.button() == mouse_button::button2) {
990 if (cap::selection()) {
991 // Copy the selection buffer to the clipboard
992 // stack, because we want it to appear in the
993 // "Edit->Paste recent" menu.
994 cap::copySelectionToStack();
996 cap::pasteSelection(bv->cursor(),
997 bv->buffer().errorList("Paste"));
998 bv->buffer().errors("Paste");
999 bv->buffer().markDirty();
1002 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
1006 // we have to update after dEPM triggered
1007 if (!update && cmd.button() == mouse_button::button1) {
1008 needsUpdate = false;
1015 case LFUN_MOUSE_MOTION: {
1016 // Only use motion with button 1
1017 //if (cmd.button() != mouse_button::button1)
1020 // ignore motions deeper nested than the real anchor
1021 Cursor & bvcur = cur.bv().cursor();
1022 if (bvcur.anchor_.hasPart(cur)) {
1023 CursorSlice old = bvcur.top();
1025 int const wh = bv->workHeight();
1026 int const y = std::max(0, std::min(wh - 1, cmd.y));
1028 tm.setCursorFromCoordinates(cur, cmd.x, y);
1029 cur.setTargetX(cmd.x);
1031 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1033 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1034 // This is to allow jumping over large insets
1035 if (cur.top() == old) {
1037 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1039 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1042 if (cur.top() == old)
1045 // don't set anchor_
1046 bvcur.setCursor(cur);
1047 bvcur.selection() = true;
1048 //lyxerr << "MOTION: " << bv->cursor() << endl;
1056 case LFUN_MOUSE_RELEASE: {
1057 if (cmd.button() == mouse_button::button2)
1060 if (cmd.button() == mouse_button::button1) {
1061 // if there is new selection, update persistent
1062 // selection, otherwise, single click does not
1063 // clear persistent selection buffer
1064 if (cur.selection()) {
1066 // if double click, cur is moved to the end of word by selectWord
1067 // but bvcur is current mouse position
1068 Cursor & bvcur = cur.bv().cursor();
1069 bvcur.selection() = true;
1071 needsUpdate = false;
1078 case LFUN_SELF_INSERT: {
1079 if (cmd.argument().empty())
1082 // Automatically delete the currently selected
1083 // text and replace it with what is being
1084 // typed in now. Depends on lyxrc settings
1085 // "auto_region_delete", which defaults to
1088 if (lyxrc.auto_region_delete && cur.selection()) {
1089 cutSelection(cur, false, false);
1090 // When change tracking is set to off, the metrics update
1091 // mechanism correctly detects if a full update is needed or not.
1092 // This detection fails when a selection spans multiple rows and
1093 // change tracking is enabled because the paragraph metrics stays
1094 // the same. In this case, we force the full update:
1095 // (see http://bugzilla.lyx.org/show_bug.cgi?id=3992)
1096 if (cur.buffer().params().trackChanges)
1097 cur.updateFlags(Update::Force);
1100 cur.clearSelection();
1101 Font const old_font = real_current_font;
1103 docstring::const_iterator cit = cmd.argument().begin();
1104 docstring::const_iterator end = cmd.argument().end();
1105 for (; cit != end; ++cit)
1106 bv->translateAndInsert(*cit, this, cur);
1109 moveCursor(cur, false);
1113 case LFUN_URL_INSERT: {
1114 InsetCommandParams p("url");
1116 if (cur.selection()) {
1117 content = cur.selectionAsString(false);
1118 cutSelection(cur, true, false);
1120 p["target"] = (cmd.argument().empty()) ?
1121 content : cmd.argument();
1122 string const data = InsetCommandMailer::params2string("url", p);
1123 if (p["target"].empty()) {
1124 bv->showInsetDialog("url", data, 0);
1126 FuncRequest fr(LFUN_INSET_INSERT, data);
1132 case LFUN_HTML_INSERT: {
1133 InsetCommandParams p("htmlurl");
1135 if (cur.selection()) {
1136 content = cur.selectionAsString(false);
1137 cutSelection(cur, true, false);
1139 p["target"] = (cmd.argument().empty()) ?
1140 content : cmd.argument();
1141 string const data = InsetCommandMailer::params2string("url", p);
1142 if (p["target"].empty()) {
1143 bv->showInsetDialog("url", data, 0);
1145 FuncRequest fr(LFUN_INSET_INSERT, data);
1151 case LFUN_LABEL_INSERT: {
1152 InsetCommandParams p("label");
1153 // Try to generate a valid label
1154 p["name"] = (cmd.argument().empty()) ?
1155 cur.getPossibleLabel() :
1157 string const data = InsetCommandMailer::params2string("label", p);
1159 if (cmd.argument().empty()) {
1160 bv->showInsetDialog("label", data, 0);
1162 FuncRequest fr(LFUN_INSET_INSERT, data);
1170 case LFUN_LIST_INSERT:
1171 case LFUN_THEOREM_INSERT:
1173 case LFUN_CAPTION_INSERT:
1174 // Open the inset, and move the current selection
1176 doInsertInset(cur, this, cmd, true, true);
1178 updateLabels(bv->buffer());
1180 case LFUN_NOTE_INSERT:
1181 case LFUN_CHARSTYLE_INSERT:
1182 case LFUN_BOX_INSERT:
1183 case LFUN_BRANCH_INSERT:
1184 case LFUN_BIBITEM_INSERT:
1185 case LFUN_ERT_INSERT:
1186 case LFUN_LISTING_INSERT:
1187 case LFUN_FOOTNOTE_INSERT:
1188 case LFUN_MARGINALNOTE_INSERT:
1189 case LFUN_OPTIONAL_INSERT:
1190 case LFUN_ENVIRONMENT_INSERT:
1191 // Open the inset, and move the current selection
1193 doInsertInset(cur, this, cmd, true, true);
1197 case LFUN_TABULAR_INSERT:
1198 // if there were no arguments, just open the dialog
1199 if (doInsertInset(cur, this, cmd, false, true))
1202 bv->showDialog("tabularcreate");
1206 case LFUN_FLOAT_INSERT:
1207 case LFUN_FLOAT_WIDE_INSERT:
1208 case LFUN_WRAP_INSERT: {
1209 bool content = cur.selection(); // will some text be moved into the inset?
1211 doInsertInset(cur, this, cmd, true, true);
1213 ParagraphList & pars = cur.text()->paragraphs();
1215 TextClass const & tclass = bv->buffer().params().getTextClass();
1217 // add a separate paragraph for the caption inset
1218 pars.push_back(Paragraph());
1219 pars.back().setInsetOwner(pars[0].inInset());
1220 pars.back().layout(tclass.defaultLayout());
1222 int cap_pit = pars.size() - 1;
1224 // if an empty inset was created, we create an additional empty
1225 // paragraph at the bottom so that the user can choose where to put
1226 // the graphics (or table).
1228 pars.push_back(Paragraph());
1229 pars.back().setInsetOwner(pars[0].inInset());
1230 pars.back().layout(tclass.defaultLayout());
1234 // reposition the cursor to the caption
1235 cur.pit() = cap_pit;
1237 // FIXME: This Text/Cursor dispatch handling is a mess!
1238 // We cannot use Cursor::dispatch here it needs access to up to
1240 FuncRequest cmd_caption(LFUN_CAPTION_INSERT);
1241 cur.text()->dispatch(cur, cmd_caption);
1242 cur.updateFlags(Update::Force);
1243 // FIXME: When leaving the Float (or Wrap) inset we should
1244 // delete any empty paragraph left above or below the
1249 case LFUN_INDEX_INSERT:
1250 case LFUN_NOMENCL_INSERT: {
1251 Inset * inset = createInset(&cur.bv(), cmd);
1255 cur.clearSelection();
1256 insertInset(cur, inset);
1257 inset->edit(cur, true);
1258 // Show the dialog for the nomenclature entry, since the
1259 // description entry still needs to be filled in.
1260 if (cmd.action == LFUN_NOMENCL_INSERT)
1261 InsetCommandMailer("nomenclature",
1262 *reinterpret_cast<InsetCommand *>(inset)).showDialog(&cur.bv());
1267 case LFUN_INDEX_PRINT:
1268 case LFUN_NOMENCL_PRINT:
1269 case LFUN_TOC_INSERT:
1270 case LFUN_HFILL_INSERT:
1271 case LFUN_LINE_INSERT:
1272 case LFUN_PAGEBREAK_INSERT:
1273 case LFUN_CLEARPAGE_INSERT:
1274 case LFUN_CLEARDOUBLEPAGE_INSERT:
1276 doInsertInset(cur, this, cmd, false, false);
1280 case LFUN_DEPTH_DECREMENT:
1281 changeDepth(cur, DEC_DEPTH);
1284 case LFUN_DEPTH_INCREMENT:
1285 changeDepth(cur, INC_DEPTH);
1288 case LFUN_MATH_DISPLAY:
1289 mathDispatch(cur, cmd, true);
1292 case LFUN_MATH_IMPORT_SELECTION:
1293 case LFUN_MATH_MODE:
1294 if (cmd.argument() == "on")
1295 // don't pass "on" as argument
1296 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1298 mathDispatch(cur, cmd, false);
1301 case LFUN_MATH_MACRO:
1302 if (cmd.argument().empty())
1303 cur.errorMessage(from_utf8(N_("Missing argument")));
1305 string s = to_utf8(cmd.argument());
1306 string const s1 = token(s, ' ', 1);
1307 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1308 string const s2 = token(s, ' ', 2);
1309 string const type = s2.empty() ? "newcommand" : s2;
1310 cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, from_utf8(type)));
1311 //cur.nextInset()->edit(cur, true);
1315 // passthrough hat and underscore outside mathed:
1316 case LFUN_MATH_SUBSCRIPT:
1317 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1319 case LFUN_MATH_SUPERSCRIPT:
1320 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1323 case LFUN_MATH_INSERT:
1324 case LFUN_MATH_MATRIX:
1325 case LFUN_MATH_DELIM:
1326 case LFUN_MATH_BIGDELIM: {
1327 if (cur.selection())
1328 cur.clearSelection();
1329 // FIXME: instead of the above, this one
1330 // should be used (but it asserts with Bidi enabled)
1331 // cf. http://bugzilla.lyx.org/show_bug.cgi?id=4055
1332 // cap::replaceSelection(cur);
1333 cur.insert(new InsetMathHull(hullSimple));
1334 checkAndActivateInset(cur, true);
1335 BOOST_ASSERT(cur.inMathed());
1340 case LFUN_FONT_EMPH: {
1341 Font font(Font::ALL_IGNORE);
1342 font.setEmph(Font::TOGGLE);
1343 toggleAndShow(cur, this, font);
1347 case LFUN_FONT_BOLD: {
1348 Font font(Font::ALL_IGNORE);
1349 font.setSeries(Font::BOLD_SERIES);
1350 toggleAndShow(cur, this, font);
1354 case LFUN_FONT_NOUN: {
1355 Font font(Font::ALL_IGNORE);
1356 font.setNoun(Font::TOGGLE);
1357 toggleAndShow(cur, this, font);
1361 case LFUN_FONT_CODE: {
1362 Font font(Font::ALL_IGNORE);
1363 font.setFamily(Font::TYPEWRITER_FAMILY); // no good
1364 toggleAndShow(cur, this, font);
1368 case LFUN_FONT_SANS: {
1369 Font font(Font::ALL_IGNORE);
1370 font.setFamily(Font::SANS_FAMILY);
1371 toggleAndShow(cur, this, font);
1375 case LFUN_FONT_ROMAN: {
1376 Font font(Font::ALL_IGNORE);
1377 font.setFamily(Font::ROMAN_FAMILY);
1378 toggleAndShow(cur, this, font);
1382 case LFUN_FONT_DEFAULT: {
1383 Font font(Font::ALL_INHERIT, ignore_language);
1384 toggleAndShow(cur, this, font);
1388 case LFUN_FONT_UNDERLINE: {
1389 Font font(Font::ALL_IGNORE);
1390 font.setUnderbar(Font::TOGGLE);
1391 toggleAndShow(cur, this, font);
1395 case LFUN_FONT_SIZE: {
1396 Font font(Font::ALL_IGNORE);
1397 font.setLyXSize(to_utf8(cmd.argument()));
1398 toggleAndShow(cur, this, font);
1402 case LFUN_LANGUAGE: {
1403 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1406 Font font(Font::ALL_IGNORE);
1407 font.setLanguage(lang);
1408 toggleAndShow(cur, this, font);
1412 case LFUN_FONT_FREE_APPLY:
1413 toggleAndShow(cur, this, freefont, toggleall);
1414 cur.message(_("Character set"));
1417 // Set the freefont using the contents of \param data dispatched from
1418 // the frontends and apply it at the current cursor location.
1419 case LFUN_FONT_FREE_UPDATE: {
1422 if (bv_funcs::string2font(to_utf8(cmd.argument()), font, toggle)) {
1425 toggleAndShow(cur, this, freefont, toggleall);
1426 cur.message(_("Character set"));
1431 case LFUN_FINISHED_LEFT:
1432 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1433 if (reverseDirectionNeeded(cur))
1437 case LFUN_FINISHED_RIGHT:
1438 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1439 if (!reverseDirectionNeeded(cur))
1443 case LFUN_LAYOUT_PARAGRAPH: {
1445 params2string(cur.paragraph(), data);
1446 data = "show\n" + data;
1447 bv->showDialogWithData("paragraph", data);
1451 case LFUN_PARAGRAPH_UPDATE: {
1453 params2string(cur.paragraph(), data);
1455 // Will the paragraph accept changes from the dialog?
1456 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1458 data = "update " + convert<string>(accept) + '\n' + data;
1459 bv->updateDialog("paragraph", data);
1463 case LFUN_ACCENT_UMLAUT:
1464 case LFUN_ACCENT_CIRCUMFLEX:
1465 case LFUN_ACCENT_GRAVE:
1466 case LFUN_ACCENT_ACUTE:
1467 case LFUN_ACCENT_TILDE:
1468 case LFUN_ACCENT_CEDILLA:
1469 case LFUN_ACCENT_MACRON:
1470 case LFUN_ACCENT_DOT:
1471 case LFUN_ACCENT_UNDERDOT:
1472 case LFUN_ACCENT_UNDERBAR:
1473 case LFUN_ACCENT_CARON:
1474 case LFUN_ACCENT_SPECIAL_CARON:
1475 case LFUN_ACCENT_BREVE:
1476 case LFUN_ACCENT_TIE:
1477 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1478 case LFUN_ACCENT_CIRCLE:
1479 case LFUN_ACCENT_OGONEK:
1480 theLyXFunc().handleKeyFunc(cmd.action);
1481 if (!cmd.argument().empty())
1482 // FIXME: Are all these characters encoded in one byte in utf8?
1483 bv->translateAndInsert(cmd.argument()[0], this, cur);
1486 case LFUN_FLOAT_LIST: {
1487 TextClass const & tclass = bv->buffer().params().getTextClass();
1488 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1490 if (cur.selection())
1491 cutSelection(cur, true, false);
1492 breakParagraph(cur);
1494 if (cur.lastpos() != 0) {
1496 breakParagraph(cur);
1499 setLayout(cur, tclass.defaultLayoutName());
1500 ParagraphParameters p;
1501 setParagraphs(cur, p);
1502 insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1505 lyxerr << "Non-existent float type: "
1506 << to_utf8(cmd.argument()) << endl;
1511 case LFUN_CHANGE_ACCEPT: {
1512 acceptOrRejectChanges(cur, ACCEPT);
1516 case LFUN_CHANGE_REJECT: {
1517 acceptOrRejectChanges(cur, REJECT);
1521 case LFUN_THESAURUS_ENTRY: {
1522 docstring arg = cmd.argument();
1524 arg = cur.selectionAsString(false);
1526 if (arg.size() > 100 || arg.empty()) {
1527 // Get word or selection
1528 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1529 arg = cur.selectionAsString(false);
1532 bv->showDialogWithData("thesaurus", to_utf8(arg));
1536 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1537 // Given data, an encoding of the ParagraphParameters
1538 // generated in the Paragraph dialog, this function sets
1539 // the current paragraph, or currently selected paragraphs,
1541 // NOTE: This function overrides all existing settings.
1542 setParagraphs(cur, cmd.argument());
1543 cur.message(_("Paragraph layout set"));
1547 case LFUN_PARAGRAPH_PARAMS: {
1548 // Given data, an encoding of the ParagraphParameters as we'd
1549 // find them in a LyX file, this function modifies the current paragraph,
1550 // or currently selected paragraphs.
1551 // NOTE: This function only modifies, and does not override, existing
1553 setParagraphs(cur, cmd.argument(), true);
1554 cur.message(_("Paragraph layout set"));
1559 if (cur.selection()) {
1560 cur.selection() = false;
1563 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1568 LYXERR(Debug::ACTION)
1569 << BOOST_CURRENT_FUNCTION
1570 << ": Command " << cmd
1571 << " not DISPATCHED by Text" << endl;
1576 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1578 // FIXME: The cursor flag is reset two lines below
1579 // so we need to check here if some of the LFUN did touch that.
1580 // for now only Text::erase() and Text::backspace() do that.
1581 // The plan is to verify all the LFUNs and then to remove this
1582 // singleParUpdate boolean altogether.
1583 if (cur.result().update() & Update::Force) {
1584 singleParUpdate = false;
1588 // FIXME: the following code should go in favor of fine grained
1589 // update flag treatment.
1590 if (singleParUpdate) {
1591 // Inserting characters does not change par height
1592 ParagraphMetrics const & pms
1593 = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
1594 if (pms.dim().height()
1595 == olddim.height()) {
1596 // if so, update _only_ this paragraph
1597 cur.updateFlags(Update::SinglePar |
1599 Update::MultiParSel);
1606 && &oldTopSlice.inset() == &cur.inset()
1607 && oldTopSlice.idx() == cur.idx()
1608 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1609 && !cur.selection())
1610 // FIXME: it would be better if we could just do this
1612 //if (cur.result().update() != Update::FitCursor)
1615 // But some LFUNs do not set Update::FitCursor when needed, so we
1616 // do it for all. This is not very harmfull as FitCursor will provoke
1617 // a full redraw only if needed but still, a proper review of all LFUN
1618 // should be done and this needsUpdate boolean can then be removed.
1619 cur.updateFlags(Update::FitCursor);
1621 cur.updateFlags(Update::Force | Update::FitCursor);
1625 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
1626 FuncStatus & flag) const
1628 BOOST_ASSERT(cur.text() == this);
1630 Font const & font = real_current_font;
1632 Inset::Code code = Inset::NO_CODE;
1634 switch (cmd.action) {
1636 case LFUN_DEPTH_DECREMENT:
1637 enable = changeDepthAllowed(cur, DEC_DEPTH);
1640 case LFUN_DEPTH_INCREMENT:
1641 enable = changeDepthAllowed(cur, INC_DEPTH);
1645 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1648 case LFUN_BIBITEM_INSERT:
1649 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO
1653 case LFUN_DIALOG_SHOW_NEW_INSET:
1654 if (cmd.argument() == "bibitem")
1655 code = Inset::BIBITEM_CODE;
1656 else if (cmd.argument() == "bibtex")
1657 code = Inset::BIBTEX_CODE;
1658 else if (cmd.argument() == "box")
1659 code = Inset::BOX_CODE;
1660 else if (cmd.argument() == "branch")
1661 code = Inset::BRANCH_CODE;
1662 else if (cmd.argument() == "citation")
1663 code = Inset::CITE_CODE;
1664 else if (cmd.argument() == "ert")
1665 code = Inset::ERT_CODE;
1666 else if (cmd.argument() == "external")
1667 code = Inset::EXTERNAL_CODE;
1668 else if (cmd.argument() == "float")
1669 code = Inset::FLOAT_CODE;
1670 else if (cmd.argument() == "graphics")
1671 code = Inset::GRAPHICS_CODE;
1672 else if (cmd.argument() == "include")
1673 code = Inset::INCLUDE_CODE;
1674 else if (cmd.argument() == "index")
1675 code = Inset::INDEX_CODE;
1676 else if (cmd.argument() == "nomenclature")
1677 code = Inset::NOMENCL_CODE;
1678 else if (cmd.argument() == "label")
1679 code = Inset::LABEL_CODE;
1680 else if (cmd.argument() == "note")
1681 code = Inset::NOTE_CODE;
1682 else if (cmd.argument() == "ref")
1683 code = Inset::REF_CODE;
1684 else if (cmd.argument() == "toc")
1685 code = Inset::TOC_CODE;
1686 else if (cmd.argument() == "url")
1687 code = Inset::URL_CODE;
1688 else if (cmd.argument() == "vspace")
1689 code = Inset::VSPACE_CODE;
1690 else if (cmd.argument() == "wrap")
1691 code = Inset::WRAP_CODE;
1692 else if (cmd.argument() == "listings")
1693 code = Inset::LISTINGS_CODE;
1696 case LFUN_ERT_INSERT:
1697 code = Inset::ERT_CODE;
1699 case LFUN_LISTING_INSERT:
1700 code = Inset::LISTINGS_CODE;
1702 case LFUN_FOOTNOTE_INSERT:
1703 code = Inset::FOOT_CODE;
1705 case LFUN_TABULAR_INSERT:
1706 code = Inset::TABULAR_CODE;
1708 case LFUN_MARGINALNOTE_INSERT:
1709 code = Inset::MARGIN_CODE;
1711 case LFUN_FLOAT_INSERT:
1712 case LFUN_FLOAT_WIDE_INSERT:
1713 code = Inset::FLOAT_CODE;
1715 case LFUN_WRAP_INSERT:
1716 code = Inset::WRAP_CODE;
1718 case LFUN_FLOAT_LIST:
1719 code = Inset::FLOAT_LIST_CODE;
1722 case LFUN_LIST_INSERT:
1723 code = Inset::LIST_CODE;
1725 case LFUN_THEOREM_INSERT:
1726 code = Inset::THEOREM_CODE;
1729 case LFUN_CAPTION_INSERT:
1730 code = Inset::CAPTION_CODE;
1732 case LFUN_NOTE_INSERT:
1733 code = Inset::NOTE_CODE;
1735 case LFUN_CHARSTYLE_INSERT:
1736 code = Inset::CHARSTYLE_CODE;
1737 if (cur.buffer().params().getTextClass().insetlayouts().empty())
1740 case LFUN_BOX_INSERT:
1741 code = Inset::BOX_CODE;
1743 case LFUN_BRANCH_INSERT:
1744 code = Inset::BRANCH_CODE;
1745 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1748 case LFUN_LABEL_INSERT:
1749 code = Inset::LABEL_CODE;
1751 case LFUN_OPTIONAL_INSERT:
1752 code = Inset::OPTARG_CODE;
1753 enable = numberOfOptArgs(cur.paragraph())
1754 < cur.paragraph().layout()->optionalargs;
1756 case LFUN_ENVIRONMENT_INSERT:
1757 code = Inset::BOX_CODE;
1759 case LFUN_INDEX_INSERT:
1760 code = Inset::INDEX_CODE;
1762 case LFUN_INDEX_PRINT:
1763 code = Inset::INDEX_PRINT_CODE;
1765 case LFUN_NOMENCL_INSERT:
1766 code = Inset::NOMENCL_CODE;
1768 case LFUN_NOMENCL_PRINT:
1769 code = Inset::NOMENCL_PRINT_CODE;
1771 case LFUN_TOC_INSERT:
1772 code = Inset::TOC_CODE;
1774 case LFUN_HTML_INSERT:
1775 case LFUN_URL_INSERT:
1776 code = Inset::URL_CODE;
1778 case LFUN_QUOTE_INSERT:
1779 // always allow this, since we will inset a raw quote
1780 // if an inset is not allowed.
1782 case LFUN_HYPHENATION_POINT_INSERT:
1783 case LFUN_LIGATURE_BREAK_INSERT:
1784 case LFUN_HFILL_INSERT:
1785 case LFUN_MENU_SEPARATOR_INSERT:
1786 case LFUN_DOTS_INSERT:
1787 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
1788 code = Inset::SPECIALCHAR_CODE;
1790 case LFUN_SPACE_INSERT:
1791 // slight hack: we know this is allowed in math mode
1793 code = Inset::SPACE_CODE;
1796 case LFUN_INSET_MODIFY:
1797 // We need to disable this, because we may get called for a
1799 // InsetTabular::getStatus() -> InsetText::getStatus()
1800 // and we don't handle LFUN_INSET_MODIFY.
1804 case LFUN_FONT_EMPH:
1805 flag.setOnOff(font.emph() == Font::ON);
1808 case LFUN_FONT_NOUN:
1809 flag.setOnOff(font.noun() == Font::ON);
1812 case LFUN_FONT_BOLD:
1813 flag.setOnOff(font.series() == Font::BOLD_SERIES);
1816 case LFUN_FONT_SANS:
1817 flag.setOnOff(font.family() == Font::SANS_FAMILY);
1820 case LFUN_FONT_ROMAN:
1821 flag.setOnOff(font.family() == Font::ROMAN_FAMILY);
1824 case LFUN_FONT_CODE:
1825 flag.setOnOff(font.family() == Font::TYPEWRITER_FAMILY);
1830 enable = cur.selection();
1834 if (cmd.argument().empty()) {
1835 if (theClipboard().isInternal())
1836 enable = cap::numberOfSelections() > 0;
1838 enable = !theClipboard().empty();
1840 string const arg = to_utf8(cmd.argument());
1841 if (isStrUnsignedInt(arg)) {
1842 unsigned int n = convert<unsigned int>(arg);
1843 enable = cap::numberOfSelections() > n;
1850 case LFUN_CLIPBOARD_PASTE:
1851 enable = !theClipboard().empty();
1854 case LFUN_PRIMARY_SELECTION_PASTE:
1855 enable = cur.selection() || !theSelection().empty();
1858 case LFUN_PARAGRAPH_MOVE_UP:
1859 enable = cur.pit() > 0 && !cur.selection();
1862 case LFUN_PARAGRAPH_MOVE_DOWN:
1863 enable = cur.pit() < cur.lastpit() && !cur.selection();
1866 case LFUN_INSET_DISSOLVE:
1867 enable = !isMainText(cur.bv().buffer()) && cur.inset().nargs() == 1;
1870 case LFUN_CHANGE_ACCEPT:
1871 case LFUN_CHANGE_REJECT:
1872 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
1873 // In principle, these LFUNs should only be enabled if there
1874 // is a change at the current position/in the current selection.
1875 // However, without proper optimizations, this will inevitably
1876 // result in unacceptable performance - just imagine a user who
1877 // wants to select the complete content of a long document.
1881 case LFUN_WORD_DELETE_FORWARD:
1882 case LFUN_WORD_DELETE_BACKWARD:
1883 case LFUN_LINE_DELETE:
1884 case LFUN_WORD_FORWARD:
1885 case LFUN_WORD_BACKWARD:
1886 case LFUN_CHAR_FORWARD:
1887 case LFUN_CHAR_FORWARD_SELECT:
1888 case LFUN_CHAR_BACKWARD:
1889 case LFUN_CHAR_BACKWARD_SELECT:
1891 case LFUN_UP_SELECT:
1893 case LFUN_DOWN_SELECT:
1894 case LFUN_PARAGRAPH_UP_SELECT:
1895 case LFUN_PARAGRAPH_DOWN_SELECT:
1896 case LFUN_SCREEN_UP_SELECT:
1897 case LFUN_SCREEN_DOWN_SELECT:
1898 case LFUN_LINE_BEGIN_SELECT:
1899 case LFUN_LINE_END_SELECT:
1900 case LFUN_WORD_FORWARD_SELECT:
1901 case LFUN_WORD_BACKWARD_SELECT:
1902 case LFUN_WORD_SELECT:
1903 case LFUN_PARAGRAPH_UP:
1904 case LFUN_PARAGRAPH_DOWN:
1905 case LFUN_SCREEN_UP:
1906 case LFUN_SCREEN_DOWN:
1907 case LFUN_LINE_BEGIN:
1909 case LFUN_BREAK_LINE:
1910 case LFUN_CHAR_DELETE_FORWARD:
1911 case LFUN_DELETE_FORWARD_SKIP:
1912 case LFUN_CHAR_DELETE_BACKWARD:
1913 case LFUN_DELETE_BACKWARD_SKIP:
1914 case LFUN_BREAK_PARAGRAPH:
1915 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
1916 case LFUN_BREAK_PARAGRAPH_SKIP:
1917 case LFUN_PARAGRAPH_SPACING:
1918 case LFUN_INSET_INSERT:
1919 case LFUN_WORD_UPCASE:
1920 case LFUN_WORD_LOWCASE:
1921 case LFUN_WORD_CAPITALIZE:
1922 case LFUN_CHARS_TRANSPOSE:
1923 case LFUN_SERVER_GET_XY:
1924 case LFUN_SERVER_SET_XY:
1925 case LFUN_SERVER_GET_FONT:
1926 case LFUN_SERVER_GET_LAYOUT:
1928 case LFUN_DATE_INSERT:
1929 case LFUN_SELF_INSERT:
1930 case LFUN_LINE_INSERT:
1931 case LFUN_PAGEBREAK_INSERT:
1932 case LFUN_CLEARPAGE_INSERT:
1933 case LFUN_CLEARDOUBLEPAGE_INSERT:
1934 case LFUN_MATH_DISPLAY:
1935 case LFUN_MATH_IMPORT_SELECTION:
1936 case LFUN_MATH_MODE:
1937 case LFUN_MATH_MACRO:
1938 case LFUN_MATH_MATRIX:
1939 case LFUN_MATH_DELIM:
1940 case LFUN_MATH_BIGDELIM:
1941 case LFUN_MATH_INSERT:
1942 case LFUN_MATH_SUBSCRIPT:
1943 case LFUN_MATH_SUPERSCRIPT:
1944 case LFUN_FONT_DEFAULT:
1945 case LFUN_FONT_UNDERLINE:
1946 case LFUN_FONT_SIZE:
1948 case LFUN_FONT_FREE_APPLY:
1949 case LFUN_FONT_FREE_UPDATE:
1950 case LFUN_LAYOUT_PARAGRAPH:
1951 case LFUN_PARAGRAPH_UPDATE:
1952 case LFUN_ACCENT_UMLAUT:
1953 case LFUN_ACCENT_CIRCUMFLEX:
1954 case LFUN_ACCENT_GRAVE:
1955 case LFUN_ACCENT_ACUTE:
1956 case LFUN_ACCENT_TILDE:
1957 case LFUN_ACCENT_CEDILLA:
1958 case LFUN_ACCENT_MACRON:
1959 case LFUN_ACCENT_DOT:
1960 case LFUN_ACCENT_UNDERDOT:
1961 case LFUN_ACCENT_UNDERBAR:
1962 case LFUN_ACCENT_CARON:
1963 case LFUN_ACCENT_SPECIAL_CARON:
1964 case LFUN_ACCENT_BREVE:
1965 case LFUN_ACCENT_TIE:
1966 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1967 case LFUN_ACCENT_CIRCLE:
1968 case LFUN_ACCENT_OGONEK:
1969 case LFUN_THESAURUS_ENTRY:
1970 case LFUN_PARAGRAPH_PARAMS_APPLY:
1971 case LFUN_PARAGRAPH_PARAMS:
1973 case LFUN_BUFFER_END:
1974 case LFUN_BUFFER_BEGIN:
1975 case LFUN_BUFFER_BEGIN_SELECT:
1976 case LFUN_BUFFER_END_SELECT:
1977 case LFUN_UNICODE_INSERT:
1978 // these are handled in our dispatch()
1986 if (code != Inset::NO_CODE
1987 && (cur.empty() || !cur.inset().insetAllowed(code)))
1990 flag.enabled(enable);
1995 void Text::pasteString(Cursor & cur, docstring const & clip,
1998 cur.clearSelection();
1999 if (!clip.empty()) {
2002 insertStringAsParagraphs(cur, clip);
2004 insertStringAsLines(cur, clip);