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 "CutAndPaste.h"
31 #include "DispatchResult.h"
32 #include "ErrorList.h"
34 #include "FuncRequest.h"
38 #include "LyXAction.h"
42 #include "Paragraph.h"
43 #include "paragraph_funcs.h"
44 #include "ParagraphParameters.h"
47 #include "ParIterator.h"
49 #include "frontends/Clipboard.h"
50 #include "frontends/Selection.h"
52 #include "insets/InsetCommand.h"
53 #include "insets/InsetFloatList.h"
54 #include "insets/InsetNewline.h"
55 #include "insets/InsetQuotes.h"
56 #include "insets/InsetSpecialChar.h"
57 #include "insets/InsetText.h"
59 #include "support/lstrings.h"
60 #include "support/lyxlib.h"
61 #include "support/convert.h"
62 #include "support/lyxtime.h"
64 #include "mathed/InsetMathHull.h"
65 #include "mathed/MathMacroTemplate.h"
67 #include <boost/current_function.hpp>
74 using std::istringstream;
75 using std::ostringstream;
79 using cap::copySelection;
80 using cap::cutSelection;
81 using cap::pasteFromStack;
82 using cap::pasteClipboard;
83 using cap::replaceSelection;
85 using support::isStrUnsignedInt;
89 extern docstring current_layout;
95 Font freefont(Font::ALL_IGNORE);
96 bool toggleall = false;
98 void toggleAndShow(Cursor & cur, Text * text,
99 Font const & font, bool toggleall = true)
101 text->toggleFree(cur, font, toggleall);
103 if (font.language() != ignore_language ||
104 font.number() != Font::IGNORE) {
105 Paragraph & par = cur.paragraph();
106 if (cur.boundary() != text->isRTLBoundary(cur.buffer(), par,
107 cur.pos(), text->real_current_font))
108 text->setCursor(cur, cur.pit(), cur.pos(),
109 false, !cur.boundary());
114 void moveCursor(Cursor & cur, bool selecting)
116 if (selecting || cur.mark())
121 void finishChange(Cursor & cur, bool selecting)
124 moveCursor(cur, selecting);
128 void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
131 docstring sel = cur.selectionAsString(false);
133 // It may happen that sel is empty but there is a selection
134 replaceSelection(cur);
137 #ifdef ENABLE_ASSERTIONS
138 const int old_pos = cur.pos();
140 cur.insert(new InsetMathHull(hullSimple));
141 BOOST_ASSERT(old_pos == cur.pos());
142 cur.nextInset()->edit(cur, true);
143 // don't do that also for LFUN_MATH_MODE
144 // unless you want end up with always changing
145 // to mathrm when opening an inlined inset --
146 // I really hate "LyXfunc overloading"...
148 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
149 // Avoid an unnecessary undo step if cmd.argument
151 if (!cmd.argument().empty())
152 cur.dispatch(FuncRequest(LFUN_MATH_INSERT,
155 // create a macro if we see "\\newcommand"
156 // somewhere, and an ordinary formula
158 if (sel.find(from_ascii("\\newcommand")) == string::npos
159 && sel.find(from_ascii("\\def")) == string::npos)
161 InsetMathHull * formula = new InsetMathHull;
162 istringstream is(to_utf8(sel));
165 formula->read(cur.buffer(), lex);
166 if (formula->getType() == hullNone)
167 // Don't create pseudo formulas if
168 // delimiters are left out
169 formula->mutate(hullSimple);
172 cur.insert(new MathMacroTemplate(sel));
175 cur.message(from_utf8(N_("Math editor mode")));
184 string const freefont2string()
187 if (font2string(freefont, toggleall, data))
197 void specialChar(Cursor & cur, InsetSpecialChar::Kind kind)
200 cap::replaceSelection(cur);
201 cur.insert(new InsetSpecialChar(kind));
206 bool doInsertInset(Cursor & cur, Text * text,
207 FuncRequest const & cmd, bool edit, bool pastesel)
209 Inset * inset = createInset(&cur.bv(), cmd);
215 if (cur.selection()) {
216 lyx::dispatch(FuncRequest(LFUN_CUT));
219 text->insertInset(cur, inset);
222 inset->edit(cur, true);
224 if (gotsel && pastesel) {
225 lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
226 // reset first par to default
227 if (cur.lastpit() != 0 || cur.lastpos() != 0) {
228 LayoutPtr const layout =
229 cur.buffer().params().getTextClass().defaultLayout();
230 cur.text()->paragraphs().begin()->layout(layout);
240 void Text::number(Cursor & cur)
242 Font font(Font::ALL_IGNORE);
243 font.setNumber(Font::TOGGLE);
244 toggleAndShow(cur, this, font);
248 bool Text::isRTL(Buffer const & buffer, Paragraph const & par) const
250 return par.isRightToLeftPar(buffer.params());
254 bool Text::isRTL(Buffer const & buffer, CursorSlice const & sl, bool boundary) const
256 if (!lyxrc.rtl_support && !sl.text())
260 if (boundary && sl.pos() > 0)
263 Paragraph const & par = getPar(sl.pit());
264 return getFont(buffer, par, sl.pos() + correction).isVisibleRightToLeft();
268 bool Text::isRTLBoundary(Buffer const & buffer, Paragraph const & par,
271 if (!lyxrc.rtl_support)
274 // no RTL boundary at line start
278 bool left = getFont(buffer, par, pos - 1).isVisibleRightToLeft();
280 if (pos == par.size())
281 right = par.isRightToLeftPar(buffer.params());
283 right = getFont(buffer, par, pos).isVisibleRightToLeft();
284 return left != right;
288 bool Text::isRTLBoundary(Buffer const & buffer, Paragraph const & par,
289 pos_type pos, Font const & font) const
291 if (!lyxrc.rtl_support)
294 bool left = font.isVisibleRightToLeft();
296 if (pos == par.size())
297 right = par.isRightToLeftPar(buffer.params());
299 right = getFont(buffer, par, pos).isVisibleRightToLeft();
300 return left != right;
304 void Text::dispatch(Cursor & cur, FuncRequest & cmd)
306 LYXERR(Debug::ACTION) << "Text::dispatch: cmd: " << cmd << endl;
308 // FIXME: We use the update flag to indicates wether a singlePar or a
309 // full screen update is needed. We reset it here but shall we restore it
313 BOOST_ASSERT(cur.text() == this);
314 BufferView * bv = &cur.bv();
315 TextMetrics & tm = cur.bv().textMetrics(this);
316 CursorSlice oldTopSlice = cur.top();
317 bool oldBoundary = cur.boundary();
318 bool sel = cur.selection();
319 // Signals that, even if needsUpdate == false, an update of the
320 // cursor paragraph is required
321 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
322 LyXAction::SingleParUpdate);
323 // Signals that a full-screen update is required
324 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
325 LyXAction::NoUpdate) || singleParUpdate);
326 // Remember the old paragraph metric (_outer_ paragraph!)
327 ParagraphMetrics const & pm = cur.bv().parMetrics(
328 cur.bottom().text(), cur.bottom().pit());
329 Dimension olddim = pm.dim();
331 switch (cmd.action) {
333 case LFUN_PARAGRAPH_MOVE_DOWN: {
334 pit_type const pit = cur.pit();
335 recUndo(cur, pit, pit + 1);
337 std::swap(pars_[pit], pars_[pit + 1]);
338 updateLabels(cur.buffer());
344 case LFUN_PARAGRAPH_MOVE_UP: {
345 pit_type const pit = cur.pit();
346 recUndo(cur, pit - 1, pit);
348 std::swap(pars_[pit], pars_[pit - 1]);
349 updateLabels(cur.buffer());
355 case LFUN_APPENDIX: {
356 Paragraph & par = cur.paragraph();
357 bool start = !par.params().startOfAppendix();
359 // FIXME: The code below only makes sense at top level.
360 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
361 // ensure that we have only one start_of_appendix in this document
362 // FIXME: this don't work for multipart document!
363 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
364 if (pars_[tmp].params().startOfAppendix()) {
366 pars_[tmp].params().startOfAppendix(false);
372 par.params().startOfAppendix(start);
374 // we can set the refreshing parameters now
375 updateLabels(cur.buffer());
379 case LFUN_WORD_DELETE_FORWARD:
380 if (cur.selection()) {
381 cutSelection(cur, true, false);
383 deleteWordForward(cur);
384 finishChange(cur, false);
387 case LFUN_WORD_DELETE_BACKWARD:
388 if (cur.selection()) {
389 cutSelection(cur, true, false);
391 deleteWordBackward(cur);
392 finishChange(cur, false);
395 case LFUN_LINE_DELETE:
396 if (cur.selection()) {
397 cutSelection(cur, true, false);
399 tm.deleteLineForward(cur);
400 finishChange(cur, false);
403 case LFUN_BUFFER_BEGIN:
404 case LFUN_BUFFER_BEGIN_SELECT:
405 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
406 if (cur.depth() == 1) {
407 needsUpdate |= cursorTop(cur);
413 case LFUN_BUFFER_END:
414 case LFUN_BUFFER_END_SELECT:
415 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
416 if (cur.depth() == 1) {
417 needsUpdate |= cursorBottom(cur);
423 case LFUN_CHAR_FORWARD:
424 case LFUN_CHAR_FORWARD_SELECT:
425 //lyxerr << BOOST_CURRENT_FUNCTION
426 // << " LFUN_CHAR_FORWARD[SEL]:\n" << cur << endl;
427 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
428 if (reverseDirectionNeeded(cur))
429 needsUpdate |= cursorLeft(cur);
431 needsUpdate |= cursorRight(cur);
433 if (!needsUpdate && oldTopSlice == cur.top()
434 && cur.boundary() == oldBoundary) {
436 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
440 case LFUN_CHAR_BACKWARD:
441 case LFUN_CHAR_BACKWARD_SELECT:
442 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
443 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
444 if (reverseDirectionNeeded(cur))
445 needsUpdate |= cursorRight(cur);
447 needsUpdate |= cursorLeft(cur);
449 if (!needsUpdate && oldTopSlice == cur.top()
450 && cur.boundary() == oldBoundary) {
452 cmd = FuncRequest(LFUN_FINISHED_LEFT);
457 case LFUN_DOWN_SELECT:
460 // stop/start the selection
461 bool select = cmd.action == LFUN_DOWN_SELECT ||
462 cmd.action == LFUN_UP_SELECT;
463 cur.selHandle(select);
465 // move cursor up/down
466 bool up = cmd.action == LFUN_UP_SELECT || cmd.action == LFUN_UP;
467 bool const successful = cur.upDownInText(up, needsUpdate);
469 // notify insets which were left and get their update flags
470 notifyCursorLeaves(cur.beforeDispatchCursor(), cur);
473 // redraw if you leave mathed (for the decorations)
474 needsUpdate |= cur.beforeDispatchCursor().inMathed();
481 case LFUN_PARAGRAPH_UP:
482 case LFUN_PARAGRAPH_UP_SELECT:
483 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
484 needsUpdate |= cursorUpParagraph(cur);
487 case LFUN_PARAGRAPH_DOWN:
488 case LFUN_PARAGRAPH_DOWN_SELECT:
489 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
490 needsUpdate |= cursorDownParagraph(cur);
494 case LFUN_SCREEN_UP_SELECT:
495 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_UP_SELECT);
496 if (cur.pit() == 0 && cur.textRow().pos() == 0)
499 tm.cursorPrevious(cur);
503 case LFUN_SCREEN_DOWN:
504 case LFUN_SCREEN_DOWN_SELECT:
505 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_DOWN_SELECT);
506 if (cur.pit() == cur.lastpit()
507 && cur.textRow().endpos() == cur.lastpos())
514 case LFUN_LINE_BEGIN:
515 case LFUN_LINE_BEGIN_SELECT:
516 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
517 needsUpdate |= tm.cursorHome(cur);
521 case LFUN_LINE_END_SELECT:
522 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
523 needsUpdate |= tm.cursorEnd(cur);
526 case LFUN_WORD_FORWARD:
527 case LFUN_WORD_FORWARD_SELECT:
528 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
529 if (reverseDirectionNeeded(cur))
530 needsUpdate |= cursorLeftOneWord(cur);
532 needsUpdate |= cursorRightOneWord(cur);
535 case LFUN_WORD_BACKWARD:
536 case LFUN_WORD_BACKWARD_SELECT:
537 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
538 if (reverseDirectionNeeded(cur))
539 needsUpdate |= cursorRightOneWord(cur);
541 needsUpdate |= cursorLeftOneWord(cur);
544 case LFUN_WORD_SELECT: {
545 selectWord(cur, WHOLE_WORD);
546 finishChange(cur, true);
550 case LFUN_BREAK_LINE: {
551 // Not allowed by LaTeX (labels or empty par)
552 if (cur.pos() > cur.paragraph().beginOfBody()) {
553 // this avoids a double undo
554 // FIXME: should not be needed, ideally
555 if (!cur.selection())
557 cap::replaceSelection(cur);
558 cur.insert(new InsetNewline);
560 moveCursor(cur, false);
565 case LFUN_CHAR_DELETE_FORWARD:
566 if (!cur.selection()) {
567 if (cur.pos() == cur.paragraph().size())
568 // Par boundary, force full-screen update
569 singleParUpdate = false;
570 needsUpdate |= erase(cur);
572 // It is possible to make it a lot faster still
573 // just comment out the line below...
575 cutSelection(cur, true, false);
576 singleParUpdate = false;
578 moveCursor(cur, false);
581 case LFUN_DELETE_FORWARD_SKIP:
582 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
583 if (!cur.selection()) {
584 if (cur.pos() == cur.lastpos()) {
591 cutSelection(cur, true, false);
596 case LFUN_CHAR_DELETE_BACKWARD:
597 if (!cur.selection()) {
598 if (bv->getIntl().getTransManager().backspace()) {
599 // Par boundary, full-screen update
601 singleParUpdate = false;
602 needsUpdate |= backspace(cur);
604 // It is possible to make it a lot faster still
605 // just comment out the line below...
608 cutSelection(cur, true, false);
609 singleParUpdate = false;
613 case LFUN_DELETE_BACKWARD_SKIP:
614 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
615 if (!cur.selection()) {
617 //CursorSlice cur = cursor();
621 cutSelection(cur, true, false);
625 case LFUN_BREAK_PARAGRAPH:
626 cap::replaceSelection(cur);
627 breakParagraph(cur, 0);
631 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
632 cap::replaceSelection(cur);
633 breakParagraph(cur, 1);
637 case LFUN_BREAK_PARAGRAPH_SKIP: {
638 // When at the beginning of a paragraph, remove
639 // indentation. Otherwise, do the same as LFUN_BREAK_PARAGRAPH.
640 cap::replaceSelection(cur);
642 cur.paragraph().params().labelWidthString(docstring());
644 breakParagraph(cur, 0);
650 // With the creation of LFUN_PARAGRAPH_PARAMS, this is now redundant,
651 // as its duties can be performed there. Should it be removed??
652 // FIXME For now, it can just dispatch LFUN_PARAGRAPH_PARAMS...
653 case LFUN_PARAGRAPH_SPACING: {
654 Paragraph & par = cur.paragraph();
655 Spacing::Space cur_spacing = par.params().spacing().getSpace();
656 string cur_value = "1.0";
657 if (cur_spacing == Spacing::Other)
658 cur_value = par.params().spacing().getValueAsString();
660 istringstream is(to_utf8(cmd.argument()));
663 Spacing::Space new_spacing = cur_spacing;
664 string new_value = cur_value;
666 lyxerr << "Missing argument to `paragraph-spacing'"
668 } else if (tmp == "single") {
669 new_spacing = Spacing::Single;
670 } else if (tmp == "onehalf") {
671 new_spacing = Spacing::Onehalf;
672 } else if (tmp == "double") {
673 new_spacing = Spacing::Double;
674 } else if (tmp == "other") {
675 new_spacing = Spacing::Other;
676 string tmpval = "0.0";
678 lyxerr << "new_value = " << tmpval << endl;
681 } else if (tmp == "default") {
682 new_spacing = Spacing::Default;
684 lyxerr << to_utf8(_("Unknown spacing argument: "))
685 << to_utf8(cmd.argument()) << endl;
687 if (cur_spacing != new_spacing || cur_value != new_value)
688 par.params().spacing(Spacing(new_spacing, new_value));
692 case LFUN_INSET_INSERT: {
694 Inset * inset = createInset(bv, cmd);
696 // FIXME (Abdel 01/02/2006):
697 // What follows would be a partial fix for bug 2154:
698 // http://bugzilla.lyx.org/show_bug.cgi?id=2154
699 // This automatically put the label inset _after_ a
700 // numbered section. It should be possible to extend the mechanism
701 // to any kind of LateX environement.
702 // The correct way to fix that bug would be at LateX generation.
703 // I'll let the code here for reference as it could be used for some
704 // other feature like "automatic labelling".
706 Paragraph & par = pars_[cur.pit()];
707 if (inset->lyxCode() == Inset::LABEL_CODE
708 && par.layout()->labeltype == LABEL_COUNTER) {
709 // Go to the end of the paragraph
710 // Warning: Because of Change-Tracking, the last
711 // position is 'size()' and not 'size()-1':
712 cur.pos() = par.size();
713 // Insert a new paragraph
714 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
719 cutSelection(cur, true, false);
720 insertInset(cur, inset);
726 case LFUN_INSET_DISSOLVE:
727 needsUpdate |= dissolveInset(cur);
730 case LFUN_INSET_SETTINGS:
731 cur.inset().showInsetDialog(bv);
734 case LFUN_SPACE_INSERT:
735 if (cur.paragraph().layout()->free_spacing)
736 insertChar(cur, ' ');
738 doInsertInset(cur, this, cmd, false, false);
741 moveCursor(cur, false);
744 case LFUN_HYPHENATION_POINT_INSERT:
745 specialChar(cur, InsetSpecialChar::HYPHENATION);
748 case LFUN_LIGATURE_BREAK_INSERT:
749 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
752 case LFUN_DOTS_INSERT:
753 specialChar(cur, InsetSpecialChar::LDOTS);
756 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
757 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
760 case LFUN_MENU_SEPARATOR_INSERT:
761 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
764 case LFUN_WORD_UPCASE:
765 changeCase(cur, Text::text_uppercase);
768 case LFUN_WORD_LOWCASE:
769 changeCase(cur, Text::text_lowercase);
772 case LFUN_WORD_CAPITALIZE:
773 changeCase(cur, Text::text_capitalization);
776 case LFUN_CHARS_TRANSPOSE:
781 cur.message(_("Paste"));
782 cap::replaceSelection(cur);
783 if (cmd.argument().empty() && !theClipboard().isInternal())
784 pasteClipboard(cur, bv->buffer().errorList("Paste"));
786 string const arg(to_utf8(cmd.argument()));
787 pasteFromStack(cur, bv->buffer().errorList("Paste"),
788 isStrUnsignedInt(arg) ?
789 convert<unsigned int>(arg) :
792 bv->buffer().errors("Paste");
793 cur.clearSelection(); // bug 393
798 cutSelection(cur, true, true);
799 cur.message(_("Cut"));
804 cur.message(_("Copy"));
807 case LFUN_SERVER_GET_XY:
808 cur.message(from_utf8(
809 convert<string>(tm.cursorX(cur.top(), cur.boundary()))
810 + ' ' + convert<string>(tm.cursorY(cur.top(), cur.boundary()))));
813 case LFUN_SERVER_SET_XY: {
816 istringstream is(to_utf8(cmd.argument()));
819 lyxerr << "SETXY: Could not parse coordinates in '"
820 << to_utf8(cmd.argument()) << std::endl;
822 tm.setCursorFromCoordinates(cur, x, y);
826 case LFUN_SERVER_GET_FONT:
827 if (current_font.shape() == Font::ITALIC_SHAPE)
828 cur.message(from_ascii("E"));
829 else if (current_font.shape() == Font::SMALLCAPS_SHAPE)
830 cur.message(from_ascii("N"));
832 cur.message(from_ascii("0"));
835 case LFUN_SERVER_GET_LAYOUT:
836 cur.message(cur.paragraph().layout()->name());
840 docstring layout = cmd.argument();
841 LYXERR(Debug::INFO) << "LFUN_LAYOUT: (arg) " << to_utf8(layout) << endl;
843 // Derive layout number from given argument (string)
844 // and current buffer's textclass (number)
845 TextClass const & tclass = bv->buffer().params().getTextClass();
847 layout = tclass.defaultLayoutName();
848 bool hasLayout = tclass.hasLayout(layout);
850 // If the entry is obsolete, use the new one instead.
852 docstring const & obs = tclass[layout]->obsoleted_by();
858 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
859 from_utf8(N_(" not known")));
863 bool change_layout = (frontend::current_layout != layout);
865 if (!change_layout && cur.selection() &&
866 cur.selBegin().pit() != cur.selEnd().pit())
868 pit_type spit = cur.selBegin().pit();
869 pit_type epit = cur.selEnd().pit() + 1;
870 while (spit != epit) {
871 if (pars_[spit].layout()->name() != frontend::current_layout) {
872 change_layout = true;
880 setLayout(cur, layout);
881 // inform the GUI that the layout has changed.
882 bv->layoutChanged(layout);
887 case LFUN_CLIPBOARD_PASTE:
888 cur.clearSelection();
889 pasteClipboard(cur, bv->buffer().errorList("Paste"),
890 cmd.argument() == "paragraph");
891 bv->buffer().errors("Paste");
894 case LFUN_PRIMARY_SELECTION_PASTE:
895 pasteString(cur, theSelection().get(),
896 cmd.argument() == "paragraph");
899 case LFUN_UNICODE_INSERT: {
900 if (cmd.argument().empty())
902 docstring hexstring = cmd.argument();
903 if (lyx::support::isHex(hexstring)) {
904 char_type c = lyx::support::hexToInt(hexstring);
905 if (c >= 32 && c < 0x10ffff) {
906 lyxerr << "Inserting c: " << c << endl;
907 docstring s = docstring(1, c);
908 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
914 case LFUN_QUOTE_INSERT: {
915 Paragraph & par = cur.paragraph();
916 pos_type pos = cur.pos();
917 BufferParams const & bufparams = bv->buffer().params();
918 LayoutPtr const & style = par.layout();
919 if (!style->pass_thru
920 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
921 // this avoids a double undo
922 // FIXME: should not be needed, ideally
923 if (!cur.selection())
925 cap::replaceSelection(cur);
930 else if (cur.prevInset() && cur.prevInset()->isSpace())
933 c = par.getChar(pos - 1);
934 string arg = to_utf8(cmd.argument());
936 cur.insert(new InsetQuotes(c,
937 bufparams.quotes_language,
938 InsetQuotes::SingleQ));
940 cur.insert(new InsetQuotes(c,
941 bufparams.quotes_language,
942 InsetQuotes::DoubleQ));
946 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
950 case LFUN_DATE_INSERT: {
951 string const format = cmd.argument().empty()
952 ? lyxrc.date_insert_format : to_utf8(cmd.argument());
953 string const time = formatted_time(current_time(), format);
954 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, time));
958 case LFUN_MOUSE_TRIPLE:
959 if (cmd.button() == mouse_button::button1) {
968 case LFUN_MOUSE_DOUBLE:
969 if (cmd.button() == mouse_button::button1) {
970 selectWord(cur, WHOLE_WORD_STRICT);
975 // Single-click on work area
976 case LFUN_MOUSE_PRESS: {
977 // Right click on a footnote flag opens float menu
978 if (cmd.button() == mouse_button::button3)
979 cur.clearSelection();
982 bool update = bv->mouseSetCursor(cur);
984 // Insert primary selection with middle mouse
985 // if there is a local selection in the current buffer,
987 if (cmd.button() == mouse_button::button2) {
988 if (cap::selection()) {
989 // Copy the selection buffer to the clipboard
990 // stack, because we want it to appear in the
991 // "Edit->Paste recent" menu.
992 cap::copySelectionToStack();
994 cap::pasteSelection(bv->cursor(),
995 bv->buffer().errorList("Paste"));
996 bv->buffer().errors("Paste");
997 bv->buffer().markDirty();
1000 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
1004 // we have to update after dEPM triggered
1005 if (!update && cmd.button() == mouse_button::button1) {
1006 needsUpdate = false;
1013 case LFUN_MOUSE_MOTION: {
1014 // Only use motion with button 1
1015 //if (cmd.button() != mouse_button::button1)
1018 // ignore motions deeper nested than the real anchor
1019 Cursor & bvcur = cur.bv().cursor();
1020 if (bvcur.anchor_.hasPart(cur)) {
1021 CursorSlice old = bvcur.top();
1023 int const wh = bv->workHeight();
1024 int const y = std::max(0, std::min(wh - 1, cmd.y));
1026 tm.setCursorFromCoordinates(cur, cmd.x, y);
1027 cur.setTargetX(cmd.x);
1029 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1031 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1032 // This is to allow jumping over large insets
1033 if (cur.top() == old) {
1035 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1037 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1040 if (cur.top() == old)
1043 // don't set anchor_
1044 bvcur.setCursor(cur);
1045 bvcur.selection() = true;
1046 //lyxerr << "MOTION: " << bv->cursor() << endl;
1054 case LFUN_MOUSE_RELEASE: {
1055 if (cmd.button() == mouse_button::button2)
1058 if (cmd.button() == mouse_button::button1) {
1059 // if there is new selection, update persistent
1060 // selection, otherwise, single click does not
1061 // clear persistent selection buffer
1062 if (cur.selection()) {
1064 // if double click, cur is moved to the end of word by selectWord
1065 // but bvcur is current mouse position
1066 Cursor & bvcur = cur.bv().cursor();
1067 bvcur.selection() = true;
1069 needsUpdate = false;
1076 case LFUN_SELF_INSERT: {
1077 if (cmd.argument().empty())
1080 // Automatically delete the currently selected
1081 // text and replace it with what is being
1082 // typed in now. Depends on lyxrc settings
1083 // "auto_region_delete", which defaults to
1086 if (lyxrc.auto_region_delete && cur.selection()) {
1087 cutSelection(cur, false, false);
1088 // When change tracking is set to off, the metrics update
1089 // mechanism correctly detects if a full update is needed or not.
1090 // This detection fails when a selection spans multiple rows and
1091 // change tracking is enabled because the paragraph metrics stays
1092 // the same. In this case, we force the full update:
1093 // (see http://bugzilla.lyx.org/show_bug.cgi?id=3992)
1094 if (cur.buffer().params().trackChanges)
1095 cur.updateFlags(Update::Force);
1098 cur.clearSelection();
1099 Font const old_font = real_current_font;
1101 docstring::const_iterator cit = cmd.argument().begin();
1102 docstring::const_iterator end = cmd.argument().end();
1103 for (; cit != end; ++cit)
1104 bv->translateAndInsert(*cit, this, cur);
1107 moveCursor(cur, false);
1111 case LFUN_URL_INSERT: {
1112 InsetCommandParams p("url");
1114 if (cur.selection()) {
1115 content = cur.selectionAsString(false);
1116 cutSelection(cur, true, false);
1118 p["target"] = (cmd.argument().empty()) ?
1119 content : cmd.argument();
1120 string const data = InsetCommandMailer::params2string("url", p);
1121 if (p["target"].empty()) {
1122 bv->showInsetDialog("url", data, 0);
1124 FuncRequest fr(LFUN_INSET_INSERT, data);
1130 case LFUN_HTML_INSERT: {
1131 InsetCommandParams p("htmlurl");
1133 if (cur.selection()) {
1134 content = cur.selectionAsString(false);
1135 cutSelection(cur, true, false);
1137 p["target"] = (cmd.argument().empty()) ?
1138 content : cmd.argument();
1139 string const data = InsetCommandMailer::params2string("url", p);
1140 if (p["target"].empty()) {
1141 bv->showInsetDialog("url", data, 0);
1143 FuncRequest fr(LFUN_INSET_INSERT, data);
1149 case LFUN_LABEL_INSERT: {
1150 InsetCommandParams p("label");
1151 // Try to generate a valid label
1152 p["name"] = (cmd.argument().empty()) ?
1153 cur.getPossibleLabel() :
1155 string const data = InsetCommandMailer::params2string("label", p);
1157 if (cmd.argument().empty()) {
1158 bv->showInsetDialog("label", data, 0);
1160 FuncRequest fr(LFUN_INSET_INSERT, data);
1168 case LFUN_LIST_INSERT:
1169 case LFUN_THEOREM_INSERT:
1171 case LFUN_CAPTION_INSERT:
1172 // Open the inset, and move the current selection
1174 doInsertInset(cur, this, cmd, true, true);
1176 updateLabels(bv->buffer());
1178 case LFUN_NOTE_INSERT:
1179 case LFUN_CHARSTYLE_INSERT:
1180 case LFUN_BOX_INSERT:
1181 case LFUN_BRANCH_INSERT:
1182 case LFUN_BIBITEM_INSERT:
1183 case LFUN_ERT_INSERT:
1184 case LFUN_LISTING_INSERT:
1185 case LFUN_FOOTNOTE_INSERT:
1186 case LFUN_MARGINALNOTE_INSERT:
1187 case LFUN_OPTIONAL_INSERT:
1188 case LFUN_ENVIRONMENT_INSERT:
1189 // Open the inset, and move the current selection
1191 doInsertInset(cur, this, cmd, true, true);
1195 case LFUN_TABULAR_INSERT:
1196 // if there were no arguments, just open the dialog
1197 if (doInsertInset(cur, this, cmd, false, true))
1200 bv->showDialog("tabularcreate");
1204 case LFUN_FLOAT_INSERT:
1205 case LFUN_FLOAT_WIDE_INSERT:
1206 case LFUN_WRAP_INSERT: {
1207 bool content = cur.selection(); // will some text be moved into the inset?
1209 doInsertInset(cur, this, cmd, true, true);
1211 ParagraphList & pars = cur.text()->paragraphs();
1213 TextClass const & tclass = bv->buffer().params().getTextClass();
1215 // add a separate paragraph for the caption inset
1216 pars.push_back(Paragraph());
1217 pars.back().setInsetOwner(pars[0].inInset());
1218 pars.back().layout(tclass.defaultLayout());
1220 int cap_pit = pars.size() - 1;
1222 // if an empty inset was created, we create an additional empty
1223 // paragraph at the bottom so that the user can choose where to put
1224 // the graphics (or table).
1226 pars.push_back(Paragraph());
1227 pars.back().setInsetOwner(pars[0].inInset());
1228 pars.back().layout(tclass.defaultLayout());
1232 // reposition the cursor to the caption
1233 cur.pit() = cap_pit;
1235 // FIXME: This Text/Cursor dispatch handling is a mess!
1236 // We cannot use Cursor::dispatch here it needs access to up to
1238 FuncRequest cmd_caption(LFUN_CAPTION_INSERT);
1239 cur.text()->dispatch(cur, cmd_caption);
1240 cur.updateFlags(Update::Force);
1241 // FIXME: When leaving the Float (or Wrap) inset we should
1242 // delete any empty paragraph left above or below the
1247 case LFUN_INDEX_INSERT:
1248 case LFUN_NOMENCL_INSERT: {
1249 Inset * inset = createInset(&cur.bv(), cmd);
1253 cur.clearSelection();
1254 insertInset(cur, inset);
1255 inset->edit(cur, true);
1256 // Show the dialog for the nomenclature entry, since the
1257 // description entry still needs to be filled in.
1258 if (cmd.action == LFUN_NOMENCL_INSERT)
1259 InsetCommandMailer("nomenclature",
1260 *reinterpret_cast<InsetCommand *>(inset)).showDialog(&cur.bv());
1265 case LFUN_INDEX_PRINT:
1266 case LFUN_NOMENCL_PRINT:
1267 case LFUN_TOC_INSERT:
1268 case LFUN_HFILL_INSERT:
1269 case LFUN_LINE_INSERT:
1270 case LFUN_PAGEBREAK_INSERT:
1271 case LFUN_CLEARPAGE_INSERT:
1272 case LFUN_CLEARDOUBLEPAGE_INSERT:
1274 doInsertInset(cur, this, cmd, false, false);
1278 case LFUN_DEPTH_DECREMENT:
1279 changeDepth(cur, DEC_DEPTH);
1282 case LFUN_DEPTH_INCREMENT:
1283 changeDepth(cur, INC_DEPTH);
1286 case LFUN_MATH_DISPLAY:
1287 mathDispatch(cur, cmd, true);
1290 case LFUN_MATH_IMPORT_SELECTION:
1291 case LFUN_MATH_MODE:
1292 if (cmd.argument() == "on")
1293 // don't pass "on" as argument
1294 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1296 mathDispatch(cur, cmd, false);
1299 case LFUN_MATH_MACRO:
1300 if (cmd.argument().empty())
1301 cur.errorMessage(from_utf8(N_("Missing argument")));
1303 string s = to_utf8(cmd.argument());
1304 string const s1 = token(s, ' ', 1);
1305 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1306 string const s2 = token(s, ' ', 2);
1307 string const type = s2.empty() ? "newcommand" : s2;
1308 cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, from_utf8(type)));
1309 //cur.nextInset()->edit(cur, true);
1313 // passthrough hat and underscore outside mathed:
1314 case LFUN_MATH_SUBSCRIPT:
1315 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1317 case LFUN_MATH_SUPERSCRIPT:
1318 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1321 case LFUN_MATH_INSERT:
1322 case LFUN_MATH_MATRIX:
1323 case LFUN_MATH_DELIM:
1324 case LFUN_MATH_BIGDELIM: {
1325 if (cur.selection())
1326 cur.clearSelection();
1327 // FIXME: instead of the above, this one
1328 // should be used (but it asserts with Bidi enabled)
1329 // cf. http://bugzilla.lyx.org/show_bug.cgi?id=4055
1330 // cap::replaceSelection(cur);
1331 cur.insert(new InsetMathHull(hullSimple));
1332 checkAndActivateInset(cur, true);
1333 BOOST_ASSERT(cur.inMathed());
1338 case LFUN_FONT_EMPH: {
1339 Font font(Font::ALL_IGNORE);
1340 font.setEmph(Font::TOGGLE);
1341 toggleAndShow(cur, this, font);
1345 case LFUN_FONT_BOLD: {
1346 Font font(Font::ALL_IGNORE);
1347 font.setSeries(Font::BOLD_SERIES);
1348 toggleAndShow(cur, this, font);
1352 case LFUN_FONT_NOUN: {
1353 Font font(Font::ALL_IGNORE);
1354 font.setNoun(Font::TOGGLE);
1355 toggleAndShow(cur, this, font);
1359 case LFUN_FONT_CODE: {
1360 Font font(Font::ALL_IGNORE);
1361 font.setFamily(Font::TYPEWRITER_FAMILY); // no good
1362 toggleAndShow(cur, this, font);
1366 case LFUN_FONT_SANS: {
1367 Font font(Font::ALL_IGNORE);
1368 font.setFamily(Font::SANS_FAMILY);
1369 toggleAndShow(cur, this, font);
1373 case LFUN_FONT_ROMAN: {
1374 Font font(Font::ALL_IGNORE);
1375 font.setFamily(Font::ROMAN_FAMILY);
1376 toggleAndShow(cur, this, font);
1380 case LFUN_FONT_DEFAULT: {
1381 Font font(Font::ALL_INHERIT, ignore_language);
1382 toggleAndShow(cur, this, font);
1386 case LFUN_FONT_UNDERLINE: {
1387 Font font(Font::ALL_IGNORE);
1388 font.setUnderbar(Font::TOGGLE);
1389 toggleAndShow(cur, this, font);
1393 case LFUN_FONT_SIZE: {
1394 Font font(Font::ALL_IGNORE);
1395 font.setLyXSize(to_utf8(cmd.argument()));
1396 toggleAndShow(cur, this, font);
1400 case LFUN_LANGUAGE: {
1401 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1404 Font font(Font::ALL_IGNORE);
1405 font.setLanguage(lang);
1406 toggleAndShow(cur, this, font);
1410 case LFUN_FONT_FREE_APPLY:
1411 toggleAndShow(cur, this, freefont, toggleall);
1412 cur.message(_("Character set"));
1415 // Set the freefont using the contents of \param data dispatched from
1416 // the frontends and apply it at the current cursor location.
1417 case LFUN_FONT_FREE_UPDATE: {
1420 if (bv_funcs::string2font(to_utf8(cmd.argument()), font, toggle)) {
1423 toggleAndShow(cur, this, freefont, toggleall);
1424 cur.message(_("Character set"));
1429 case LFUN_FINISHED_LEFT:
1430 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1431 if (reverseDirectionNeeded(cur))
1435 case LFUN_FINISHED_RIGHT:
1436 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1437 if (!reverseDirectionNeeded(cur))
1441 case LFUN_LAYOUT_PARAGRAPH: {
1443 params2string(cur.paragraph(), data);
1444 data = "show\n" + data;
1445 bv->showDialogWithData("paragraph", data);
1449 case LFUN_PARAGRAPH_UPDATE: {
1451 params2string(cur.paragraph(), data);
1453 // Will the paragraph accept changes from the dialog?
1454 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1456 data = "update " + convert<string>(accept) + '\n' + data;
1457 bv->updateDialog("paragraph", data);
1461 case LFUN_ACCENT_UMLAUT:
1462 case LFUN_ACCENT_CIRCUMFLEX:
1463 case LFUN_ACCENT_GRAVE:
1464 case LFUN_ACCENT_ACUTE:
1465 case LFUN_ACCENT_TILDE:
1466 case LFUN_ACCENT_CEDILLA:
1467 case LFUN_ACCENT_MACRON:
1468 case LFUN_ACCENT_DOT:
1469 case LFUN_ACCENT_UNDERDOT:
1470 case LFUN_ACCENT_UNDERBAR:
1471 case LFUN_ACCENT_CARON:
1472 case LFUN_ACCENT_SPECIAL_CARON:
1473 case LFUN_ACCENT_BREVE:
1474 case LFUN_ACCENT_TIE:
1475 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1476 case LFUN_ACCENT_CIRCLE:
1477 case LFUN_ACCENT_OGONEK:
1478 theLyXFunc().handleKeyFunc(cmd.action);
1479 if (!cmd.argument().empty())
1480 // FIXME: Are all these characters encoded in one byte in utf8?
1481 bv->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()))) {
1488 if (cur.selection())
1489 cutSelection(cur, true, false);
1490 breakParagraph(cur);
1492 if (cur.lastpos() != 0) {
1494 breakParagraph(cur);
1497 setLayout(cur, tclass.defaultLayoutName());
1498 ParagraphParameters p;
1499 setParagraphs(cur, p);
1500 insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1503 lyxerr << "Non-existent float type: "
1504 << to_utf8(cmd.argument()) << endl;
1509 case LFUN_CHANGE_ACCEPT: {
1510 acceptOrRejectChanges(cur, ACCEPT);
1514 case LFUN_CHANGE_REJECT: {
1515 acceptOrRejectChanges(cur, REJECT);
1519 case LFUN_THESAURUS_ENTRY: {
1520 docstring arg = cmd.argument();
1522 arg = cur.selectionAsString(false);
1524 if (arg.size() > 100 || arg.empty()) {
1525 // Get word or selection
1526 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1527 arg = cur.selectionAsString(false);
1530 bv->showDialogWithData("thesaurus", to_utf8(arg));
1534 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1535 // Given data, an encoding of the ParagraphParameters
1536 // generated in the Paragraph dialog, this function sets
1537 // the current paragraph, or currently selected paragraphs,
1539 // NOTE: This function overrides all existing settings.
1540 setParagraphs(cur, cmd.argument());
1541 cur.message(_("Paragraph layout set"));
1545 case LFUN_PARAGRAPH_PARAMS: {
1546 // Given data, an encoding of the ParagraphParameters as we'd
1547 // find them in a LyX file, this function modifies the current paragraph,
1548 // or currently selected paragraphs.
1549 // NOTE: This function only modifies, and does not override, existing
1551 setParagraphs(cur, cmd.argument(), true);
1552 cur.message(_("Paragraph layout set"));
1557 if (cur.selection()) {
1558 cur.selection() = false;
1561 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1566 LYXERR(Debug::ACTION)
1567 << BOOST_CURRENT_FUNCTION
1568 << ": Command " << cmd
1569 << " not DISPATCHED by Text" << endl;
1574 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1576 // FIXME: The cursor flag is reset two lines below
1577 // so we need to check here if some of the LFUN did touch that.
1578 // for now only Text::erase() and Text::backspace() do that.
1579 // The plan is to verify all the LFUNs and then to remove this
1580 // singleParUpdate boolean altogether.
1581 if (cur.result().update() & Update::Force) {
1582 singleParUpdate = false;
1586 // FIXME: the following code should go in favor of fine grained
1587 // update flag treatment.
1588 if (singleParUpdate) {
1589 // Inserting characters does not change par height
1590 ParagraphMetrics const & pms
1591 = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
1592 if (pms.dim().height()
1593 == olddim.height()) {
1594 // if so, update _only_ this paragraph
1595 cur.updateFlags(Update::SinglePar |
1597 Update::MultiParSel);
1604 && &oldTopSlice.inset() == &cur.inset()
1605 && oldTopSlice.idx() == cur.idx()
1606 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1607 && !cur.selection())
1608 // FIXME: it would be better if we could just do this
1610 //if (cur.result().update() != Update::FitCursor)
1613 // But some LFUNs do not set Update::FitCursor when needed, so we
1614 // do it for all. This is not very harmfull as FitCursor will provoke
1615 // a full redraw only if needed but still, a proper review of all LFUN
1616 // should be done and this needsUpdate boolean can then be removed.
1617 cur.updateFlags(Update::FitCursor);
1619 cur.updateFlags(Update::Force | Update::FitCursor);
1623 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
1624 FuncStatus & flag) const
1626 BOOST_ASSERT(cur.text() == this);
1628 Font const & font = real_current_font;
1630 Inset::Code code = Inset::NO_CODE;
1632 switch (cmd.action) {
1634 case LFUN_DEPTH_DECREMENT:
1635 enable = changeDepthAllowed(cur, DEC_DEPTH);
1638 case LFUN_DEPTH_INCREMENT:
1639 enable = changeDepthAllowed(cur, INC_DEPTH);
1643 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1646 case LFUN_BIBITEM_INSERT:
1647 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO
1651 case LFUN_DIALOG_SHOW_NEW_INSET:
1652 if (cmd.argument() == "bibitem")
1653 code = Inset::BIBITEM_CODE;
1654 else if (cmd.argument() == "bibtex")
1655 code = Inset::BIBTEX_CODE;
1656 else if (cmd.argument() == "box")
1657 code = Inset::BOX_CODE;
1658 else if (cmd.argument() == "branch")
1659 code = Inset::BRANCH_CODE;
1660 else if (cmd.argument() == "citation")
1661 code = Inset::CITE_CODE;
1662 else if (cmd.argument() == "ert")
1663 code = Inset::ERT_CODE;
1664 else if (cmd.argument() == "external")
1665 code = Inset::EXTERNAL_CODE;
1666 else if (cmd.argument() == "float")
1667 code = Inset::FLOAT_CODE;
1668 else if (cmd.argument() == "graphics")
1669 code = Inset::GRAPHICS_CODE;
1670 else if (cmd.argument() == "include")
1671 code = Inset::INCLUDE_CODE;
1672 else if (cmd.argument() == "index")
1673 code = Inset::INDEX_CODE;
1674 else if (cmd.argument() == "nomenclature")
1675 code = Inset::NOMENCL_CODE;
1676 else if (cmd.argument() == "label")
1677 code = Inset::LABEL_CODE;
1678 else if (cmd.argument() == "note")
1679 code = Inset::NOTE_CODE;
1680 else if (cmd.argument() == "ref")
1681 code = Inset::REF_CODE;
1682 else if (cmd.argument() == "toc")
1683 code = Inset::TOC_CODE;
1684 else if (cmd.argument() == "url")
1685 code = Inset::URL_CODE;
1686 else if (cmd.argument() == "vspace")
1687 code = Inset::VSPACE_CODE;
1688 else if (cmd.argument() == "wrap")
1689 code = Inset::WRAP_CODE;
1690 else if (cmd.argument() == "listings")
1691 code = Inset::LISTINGS_CODE;
1694 case LFUN_ERT_INSERT:
1695 code = Inset::ERT_CODE;
1697 case LFUN_LISTING_INSERT:
1698 code = Inset::LISTINGS_CODE;
1700 case LFUN_FOOTNOTE_INSERT:
1701 code = Inset::FOOT_CODE;
1703 case LFUN_TABULAR_INSERT:
1704 code = Inset::TABULAR_CODE;
1706 case LFUN_MARGINALNOTE_INSERT:
1707 code = Inset::MARGIN_CODE;
1709 case LFUN_FLOAT_INSERT:
1710 case LFUN_FLOAT_WIDE_INSERT:
1711 code = Inset::FLOAT_CODE;
1713 case LFUN_WRAP_INSERT:
1714 code = Inset::WRAP_CODE;
1716 case LFUN_FLOAT_LIST:
1717 code = Inset::FLOAT_LIST_CODE;
1720 case LFUN_LIST_INSERT:
1721 code = Inset::LIST_CODE;
1723 case LFUN_THEOREM_INSERT:
1724 code = Inset::THEOREM_CODE;
1727 case LFUN_CAPTION_INSERT:
1728 code = Inset::CAPTION_CODE;
1730 case LFUN_NOTE_INSERT:
1731 code = Inset::NOTE_CODE;
1733 case LFUN_CHARSTYLE_INSERT:
1734 code = Inset::CHARSTYLE_CODE;
1735 if (cur.buffer().params().getTextClass().insetlayouts().empty())
1738 case LFUN_BOX_INSERT:
1739 code = Inset::BOX_CODE;
1741 case LFUN_BRANCH_INSERT:
1742 code = Inset::BRANCH_CODE;
1743 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1746 case LFUN_LABEL_INSERT:
1747 code = Inset::LABEL_CODE;
1749 case LFUN_OPTIONAL_INSERT:
1750 code = Inset::OPTARG_CODE;
1751 enable = numberOfOptArgs(cur.paragraph())
1752 < cur.paragraph().layout()->optionalargs;
1754 case LFUN_ENVIRONMENT_INSERT:
1755 code = Inset::BOX_CODE;
1757 case LFUN_INDEX_INSERT:
1758 code = Inset::INDEX_CODE;
1760 case LFUN_INDEX_PRINT:
1761 code = Inset::INDEX_PRINT_CODE;
1763 case LFUN_NOMENCL_INSERT:
1764 code = Inset::NOMENCL_CODE;
1766 case LFUN_NOMENCL_PRINT:
1767 code = Inset::NOMENCL_PRINT_CODE;
1769 case LFUN_TOC_INSERT:
1770 code = Inset::TOC_CODE;
1772 case LFUN_HTML_INSERT:
1773 case LFUN_URL_INSERT:
1774 code = Inset::URL_CODE;
1776 case LFUN_QUOTE_INSERT:
1777 // always allow this, since we will inset a raw quote
1778 // if an inset is not allowed.
1780 case LFUN_HYPHENATION_POINT_INSERT:
1781 case LFUN_LIGATURE_BREAK_INSERT:
1782 case LFUN_HFILL_INSERT:
1783 case LFUN_MENU_SEPARATOR_INSERT:
1784 case LFUN_DOTS_INSERT:
1785 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
1786 code = Inset::SPECIALCHAR_CODE;
1788 case LFUN_SPACE_INSERT:
1789 // slight hack: we know this is allowed in math mode
1791 code = Inset::SPACE_CODE;
1794 case LFUN_INSET_MODIFY:
1795 // We need to disable this, because we may get called for a
1797 // InsetTabular::getStatus() -> InsetText::getStatus()
1798 // and we don't handle LFUN_INSET_MODIFY.
1802 case LFUN_FONT_EMPH:
1803 flag.setOnOff(font.emph() == Font::ON);
1806 case LFUN_FONT_NOUN:
1807 flag.setOnOff(font.noun() == Font::ON);
1810 case LFUN_FONT_BOLD:
1811 flag.setOnOff(font.series() == Font::BOLD_SERIES);
1814 case LFUN_FONT_SANS:
1815 flag.setOnOff(font.family() == Font::SANS_FAMILY);
1818 case LFUN_FONT_ROMAN:
1819 flag.setOnOff(font.family() == Font::ROMAN_FAMILY);
1822 case LFUN_FONT_CODE:
1823 flag.setOnOff(font.family() == Font::TYPEWRITER_FAMILY);
1828 enable = cur.selection();
1832 if (cmd.argument().empty()) {
1833 if (theClipboard().isInternal())
1834 enable = cap::numberOfSelections() > 0;
1836 enable = !theClipboard().empty();
1838 string const arg = to_utf8(cmd.argument());
1839 if (isStrUnsignedInt(arg)) {
1840 unsigned int n = convert<unsigned int>(arg);
1841 enable = cap::numberOfSelections() > n;
1848 case LFUN_CLIPBOARD_PASTE:
1849 enable = !theClipboard().empty();
1852 case LFUN_PRIMARY_SELECTION_PASTE:
1853 enable = cur.selection() || !theSelection().empty();
1856 case LFUN_PARAGRAPH_MOVE_UP:
1857 enable = cur.pit() > 0 && !cur.selection();
1860 case LFUN_PARAGRAPH_MOVE_DOWN:
1861 enable = cur.pit() < cur.lastpit() && !cur.selection();
1864 case LFUN_INSET_DISSOLVE:
1865 enable = !isMainText(cur.bv().buffer()) && cur.inset().nargs() == 1;
1868 case LFUN_CHANGE_ACCEPT:
1869 case LFUN_CHANGE_REJECT:
1870 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
1871 // In principle, these LFUNs should only be enabled if there
1872 // is a change at the current position/in the current selection.
1873 // However, without proper optimizations, this will inevitably
1874 // result in unacceptable performance - just imagine a user who
1875 // wants to select the complete content of a long document.
1879 case LFUN_WORD_DELETE_FORWARD:
1880 case LFUN_WORD_DELETE_BACKWARD:
1881 case LFUN_LINE_DELETE:
1882 case LFUN_WORD_FORWARD:
1883 case LFUN_WORD_BACKWARD:
1884 case LFUN_CHAR_FORWARD:
1885 case LFUN_CHAR_FORWARD_SELECT:
1886 case LFUN_CHAR_BACKWARD:
1887 case LFUN_CHAR_BACKWARD_SELECT:
1889 case LFUN_UP_SELECT:
1891 case LFUN_DOWN_SELECT:
1892 case LFUN_PARAGRAPH_UP_SELECT:
1893 case LFUN_PARAGRAPH_DOWN_SELECT:
1894 case LFUN_SCREEN_UP_SELECT:
1895 case LFUN_SCREEN_DOWN_SELECT:
1896 case LFUN_LINE_BEGIN_SELECT:
1897 case LFUN_LINE_END_SELECT:
1898 case LFUN_WORD_FORWARD_SELECT:
1899 case LFUN_WORD_BACKWARD_SELECT:
1900 case LFUN_WORD_SELECT:
1901 case LFUN_PARAGRAPH_UP:
1902 case LFUN_PARAGRAPH_DOWN:
1903 case LFUN_SCREEN_UP:
1904 case LFUN_SCREEN_DOWN:
1905 case LFUN_LINE_BEGIN:
1907 case LFUN_BREAK_LINE:
1908 case LFUN_CHAR_DELETE_FORWARD:
1909 case LFUN_DELETE_FORWARD_SKIP:
1910 case LFUN_CHAR_DELETE_BACKWARD:
1911 case LFUN_DELETE_BACKWARD_SKIP:
1912 case LFUN_BREAK_PARAGRAPH:
1913 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
1914 case LFUN_BREAK_PARAGRAPH_SKIP:
1915 case LFUN_PARAGRAPH_SPACING:
1916 case LFUN_INSET_INSERT:
1917 case LFUN_WORD_UPCASE:
1918 case LFUN_WORD_LOWCASE:
1919 case LFUN_WORD_CAPITALIZE:
1920 case LFUN_CHARS_TRANSPOSE:
1921 case LFUN_SERVER_GET_XY:
1922 case LFUN_SERVER_SET_XY:
1923 case LFUN_SERVER_GET_FONT:
1924 case LFUN_SERVER_GET_LAYOUT:
1926 case LFUN_DATE_INSERT:
1927 case LFUN_SELF_INSERT:
1928 case LFUN_LINE_INSERT:
1929 case LFUN_PAGEBREAK_INSERT:
1930 case LFUN_CLEARPAGE_INSERT:
1931 case LFUN_CLEARDOUBLEPAGE_INSERT:
1932 case LFUN_MATH_DISPLAY:
1933 case LFUN_MATH_IMPORT_SELECTION:
1934 case LFUN_MATH_MODE:
1935 case LFUN_MATH_MACRO:
1936 case LFUN_MATH_MATRIX:
1937 case LFUN_MATH_DELIM:
1938 case LFUN_MATH_BIGDELIM:
1939 case LFUN_MATH_INSERT:
1940 case LFUN_MATH_SUBSCRIPT:
1941 case LFUN_MATH_SUPERSCRIPT:
1942 case LFUN_FONT_DEFAULT:
1943 case LFUN_FONT_UNDERLINE:
1944 case LFUN_FONT_SIZE:
1946 case LFUN_FONT_FREE_APPLY:
1947 case LFUN_FONT_FREE_UPDATE:
1948 case LFUN_LAYOUT_PARAGRAPH:
1949 case LFUN_PARAGRAPH_UPDATE:
1950 case LFUN_ACCENT_UMLAUT:
1951 case LFUN_ACCENT_CIRCUMFLEX:
1952 case LFUN_ACCENT_GRAVE:
1953 case LFUN_ACCENT_ACUTE:
1954 case LFUN_ACCENT_TILDE:
1955 case LFUN_ACCENT_CEDILLA:
1956 case LFUN_ACCENT_MACRON:
1957 case LFUN_ACCENT_DOT:
1958 case LFUN_ACCENT_UNDERDOT:
1959 case LFUN_ACCENT_UNDERBAR:
1960 case LFUN_ACCENT_CARON:
1961 case LFUN_ACCENT_SPECIAL_CARON:
1962 case LFUN_ACCENT_BREVE:
1963 case LFUN_ACCENT_TIE:
1964 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1965 case LFUN_ACCENT_CIRCLE:
1966 case LFUN_ACCENT_OGONEK:
1967 case LFUN_THESAURUS_ENTRY:
1968 case LFUN_PARAGRAPH_PARAMS_APPLY:
1969 case LFUN_PARAGRAPH_PARAMS:
1971 case LFUN_BUFFER_END:
1972 case LFUN_BUFFER_BEGIN:
1973 case LFUN_BUFFER_BEGIN_SELECT:
1974 case LFUN_BUFFER_END_SELECT:
1975 case LFUN_UNICODE_INSERT:
1976 // these are handled in our dispatch()
1984 if (code != Inset::NO_CODE
1985 && (cur.empty() || !cur.inset().insetAllowed(code)))
1988 flag.enabled(enable);
1993 void Text::pasteString(Cursor & cur, docstring const & clip,
1996 cur.clearSelection();
1997 if (!clip.empty()) {
2000 insertStringAsParagraphs(cur, clip);
2002 insertStringAsLines(cur, clip);