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 TextMetrics const & tm = cur.bv().textMetrics(text);
106 if (cur.boundary() != tm.isRTLBoundary(cur.pit(),
107 cur.pos(), cur.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 void Text::dispatch(Cursor & cur, FuncRequest & cmd)
256 LYXERR(Debug::ACTION) << "Text::dispatch: cmd: " << cmd << endl;
258 // FIXME: We use the update flag to indicates wether a singlePar or a
259 // full screen update is needed. We reset it here but shall we restore it
263 BOOST_ASSERT(cur.text() == this);
264 BufferView * bv = &cur.bv();
265 TextMetrics & tm = cur.bv().textMetrics(this);
266 CursorSlice oldTopSlice = cur.top();
267 bool oldBoundary = cur.boundary();
268 bool sel = cur.selection();
269 // Signals that, even if needsUpdate == false, an update of the
270 // cursor paragraph is required
271 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
272 LyXAction::SingleParUpdate);
273 // Signals that a full-screen update is required
274 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
275 LyXAction::NoUpdate) || singleParUpdate);
276 // Remember the old paragraph metric (_outer_ paragraph!)
277 ParagraphMetrics const & pm = cur.bv().parMetrics(
278 cur.bottom().text(), cur.bottom().pit());
279 Dimension olddim = pm.dim();
281 switch (cmd.action) {
283 case LFUN_PARAGRAPH_MOVE_DOWN: {
284 pit_type const pit = cur.pit();
285 recUndo(cur, pit, pit + 1);
287 std::swap(pars_[pit], pars_[pit + 1]);
288 updateLabels(cur.buffer());
294 case LFUN_PARAGRAPH_MOVE_UP: {
295 pit_type const pit = cur.pit();
296 recUndo(cur, pit - 1, pit);
298 std::swap(pars_[pit], pars_[pit - 1]);
299 updateLabels(cur.buffer());
305 case LFUN_APPENDIX: {
306 Paragraph & par = cur.paragraph();
307 bool start = !par.params().startOfAppendix();
309 // FIXME: The code below only makes sense at top level.
310 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
311 // ensure that we have only one start_of_appendix in this document
312 // FIXME: this don't work for multipart document!
313 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
314 if (pars_[tmp].params().startOfAppendix()) {
316 pars_[tmp].params().startOfAppendix(false);
322 par.params().startOfAppendix(start);
324 // we can set the refreshing parameters now
325 updateLabels(cur.buffer());
329 case LFUN_WORD_DELETE_FORWARD:
330 if (cur.selection()) {
331 cutSelection(cur, true, false);
333 deleteWordForward(cur);
334 finishChange(cur, false);
337 case LFUN_WORD_DELETE_BACKWARD:
338 if (cur.selection()) {
339 cutSelection(cur, true, false);
341 deleteWordBackward(cur);
342 finishChange(cur, false);
345 case LFUN_LINE_DELETE:
346 if (cur.selection()) {
347 cutSelection(cur, true, false);
349 tm.deleteLineForward(cur);
350 finishChange(cur, false);
353 case LFUN_BUFFER_BEGIN:
354 case LFUN_BUFFER_BEGIN_SELECT:
355 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
356 if (cur.depth() == 1) {
357 needsUpdate |= cursorTop(cur);
363 case LFUN_BUFFER_END:
364 case LFUN_BUFFER_END_SELECT:
365 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
366 if (cur.depth() == 1) {
367 needsUpdate |= cursorBottom(cur);
373 case LFUN_CHAR_FORWARD:
374 case LFUN_CHAR_FORWARD_SELECT:
375 //lyxerr << BOOST_CURRENT_FUNCTION
376 // << " LFUN_CHAR_FORWARD[SEL]:\n" << cur << endl;
377 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
378 if (reverseDirectionNeeded(cur))
379 needsUpdate |= cursorLeft(cur);
381 needsUpdate |= cursorRight(cur);
383 if (!needsUpdate && oldTopSlice == cur.top()
384 && cur.boundary() == oldBoundary) {
386 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
390 case LFUN_CHAR_BACKWARD:
391 case LFUN_CHAR_BACKWARD_SELECT:
392 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
393 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
394 if (reverseDirectionNeeded(cur))
395 needsUpdate |= cursorRight(cur);
397 needsUpdate |= cursorLeft(cur);
399 if (!needsUpdate && oldTopSlice == cur.top()
400 && cur.boundary() == oldBoundary) {
402 cmd = FuncRequest(LFUN_FINISHED_LEFT);
407 case LFUN_DOWN_SELECT:
410 // stop/start the selection
411 bool select = cmd.action == LFUN_DOWN_SELECT ||
412 cmd.action == LFUN_UP_SELECT;
413 cur.selHandle(select);
415 // move cursor up/down
416 bool up = cmd.action == LFUN_UP_SELECT || cmd.action == LFUN_UP;
417 bool const successful = cur.upDownInText(up, needsUpdate);
419 // notify insets which were left and get their update flags
420 notifyCursorLeaves(cur.beforeDispatchCursor(), cur);
423 // redraw if you leave mathed (for the decorations)
424 needsUpdate |= cur.beforeDispatchCursor().inMathed();
431 case LFUN_PARAGRAPH_UP:
432 case LFUN_PARAGRAPH_UP_SELECT:
433 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
434 needsUpdate |= cursorUpParagraph(cur);
437 case LFUN_PARAGRAPH_DOWN:
438 case LFUN_PARAGRAPH_DOWN_SELECT:
439 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
440 needsUpdate |= cursorDownParagraph(cur);
444 case LFUN_SCREEN_UP_SELECT:
445 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_UP_SELECT);
446 if (cur.pit() == 0 && cur.textRow().pos() == 0)
449 tm.cursorPrevious(cur);
453 case LFUN_SCREEN_DOWN:
454 case LFUN_SCREEN_DOWN_SELECT:
455 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_DOWN_SELECT);
456 if (cur.pit() == cur.lastpit()
457 && cur.textRow().endpos() == cur.lastpos())
464 case LFUN_LINE_BEGIN:
465 case LFUN_LINE_BEGIN_SELECT:
466 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
467 needsUpdate |= tm.cursorHome(cur);
471 case LFUN_LINE_END_SELECT:
472 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
473 needsUpdate |= tm.cursorEnd(cur);
476 case LFUN_WORD_FORWARD:
477 case LFUN_WORD_FORWARD_SELECT:
478 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
479 if (reverseDirectionNeeded(cur))
480 needsUpdate |= cursorLeftOneWord(cur);
482 needsUpdate |= cursorRightOneWord(cur);
485 case LFUN_WORD_BACKWARD:
486 case LFUN_WORD_BACKWARD_SELECT:
487 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
488 if (reverseDirectionNeeded(cur))
489 needsUpdate |= cursorRightOneWord(cur);
491 needsUpdate |= cursorLeftOneWord(cur);
494 case LFUN_WORD_SELECT: {
495 selectWord(cur, WHOLE_WORD);
496 finishChange(cur, true);
500 case LFUN_BREAK_LINE: {
501 // Not allowed by LaTeX (labels or empty par)
502 if (cur.pos() > cur.paragraph().beginOfBody()) {
503 // this avoids a double undo
504 // FIXME: should not be needed, ideally
505 if (!cur.selection())
507 cap::replaceSelection(cur);
508 cur.insert(new InsetNewline);
510 moveCursor(cur, false);
515 case LFUN_CHAR_DELETE_FORWARD:
516 if (!cur.selection()) {
517 if (cur.pos() == cur.paragraph().size())
518 // Par boundary, force full-screen update
519 singleParUpdate = false;
520 needsUpdate |= erase(cur);
522 // It is possible to make it a lot faster still
523 // just comment out the line below...
525 cutSelection(cur, true, false);
526 singleParUpdate = false;
528 moveCursor(cur, false);
531 case LFUN_DELETE_FORWARD_SKIP:
532 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
533 if (!cur.selection()) {
534 if (cur.pos() == cur.lastpos()) {
541 cutSelection(cur, true, false);
546 case LFUN_CHAR_DELETE_BACKWARD:
547 if (!cur.selection()) {
548 if (bv->getIntl().getTransManager().backspace()) {
549 // Par boundary, full-screen update
551 singleParUpdate = false;
552 needsUpdate |= backspace(cur);
554 // It is possible to make it a lot faster still
555 // just comment out the line below...
558 cutSelection(cur, true, false);
559 singleParUpdate = false;
563 case LFUN_DELETE_BACKWARD_SKIP:
564 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
565 if (!cur.selection()) {
567 //CursorSlice cur = cursor();
571 cutSelection(cur, true, false);
575 case LFUN_BREAK_PARAGRAPH:
576 cap::replaceSelection(cur);
577 breakParagraph(cur, 0);
581 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
582 cap::replaceSelection(cur);
583 breakParagraph(cur, 1);
587 case LFUN_BREAK_PARAGRAPH_SKIP: {
588 // When at the beginning of a paragraph, remove
589 // indentation. Otherwise, do the same as LFUN_BREAK_PARAGRAPH.
590 cap::replaceSelection(cur);
592 cur.paragraph().params().labelWidthString(docstring());
594 breakParagraph(cur, 0);
600 // With the creation of LFUN_PARAGRAPH_PARAMS, this is now redundant,
601 // as its duties can be performed there. Should it be removed??
602 // FIXME For now, it can just dispatch LFUN_PARAGRAPH_PARAMS...
603 case LFUN_PARAGRAPH_SPACING: {
604 Paragraph & par = cur.paragraph();
605 Spacing::Space cur_spacing = par.params().spacing().getSpace();
606 string cur_value = "1.0";
607 if (cur_spacing == Spacing::Other)
608 cur_value = par.params().spacing().getValueAsString();
610 istringstream is(to_utf8(cmd.argument()));
613 Spacing::Space new_spacing = cur_spacing;
614 string new_value = cur_value;
616 lyxerr << "Missing argument to `paragraph-spacing'"
618 } else if (tmp == "single") {
619 new_spacing = Spacing::Single;
620 } else if (tmp == "onehalf") {
621 new_spacing = Spacing::Onehalf;
622 } else if (tmp == "double") {
623 new_spacing = Spacing::Double;
624 } else if (tmp == "other") {
625 new_spacing = Spacing::Other;
626 string tmpval = "0.0";
628 lyxerr << "new_value = " << tmpval << endl;
631 } else if (tmp == "default") {
632 new_spacing = Spacing::Default;
634 lyxerr << to_utf8(_("Unknown spacing argument: "))
635 << to_utf8(cmd.argument()) << endl;
637 if (cur_spacing != new_spacing || cur_value != new_value)
638 par.params().spacing(Spacing(new_spacing, new_value));
642 case LFUN_INSET_INSERT: {
644 Inset * inset = createInset(bv, cmd);
646 // FIXME (Abdel 01/02/2006):
647 // What follows would be a partial fix for bug 2154:
648 // http://bugzilla.lyx.org/show_bug.cgi?id=2154
649 // This automatically put the label inset _after_ a
650 // numbered section. It should be possible to extend the mechanism
651 // to any kind of LateX environement.
652 // The correct way to fix that bug would be at LateX generation.
653 // I'll let the code here for reference as it could be used for some
654 // other feature like "automatic labelling".
656 Paragraph & par = pars_[cur.pit()];
657 if (inset->lyxCode() == Inset::LABEL_CODE
658 && par.layout()->labeltype == LABEL_COUNTER) {
659 // Go to the end of the paragraph
660 // Warning: Because of Change-Tracking, the last
661 // position is 'size()' and not 'size()-1':
662 cur.pos() = par.size();
663 // Insert a new paragraph
664 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
669 cutSelection(cur, true, false);
670 insertInset(cur, inset);
676 case LFUN_INSET_DISSOLVE:
677 needsUpdate |= dissolveInset(cur);
680 case LFUN_INSET_SETTINGS:
681 cur.inset().showInsetDialog(bv);
684 case LFUN_SPACE_INSERT:
685 if (cur.paragraph().layout()->free_spacing)
686 insertChar(cur, ' ');
688 doInsertInset(cur, this, cmd, false, false);
691 moveCursor(cur, false);
694 case LFUN_HYPHENATION_POINT_INSERT:
695 specialChar(cur, InsetSpecialChar::HYPHENATION);
698 case LFUN_LIGATURE_BREAK_INSERT:
699 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
702 case LFUN_DOTS_INSERT:
703 specialChar(cur, InsetSpecialChar::LDOTS);
706 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
707 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
710 case LFUN_MENU_SEPARATOR_INSERT:
711 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
714 case LFUN_WORD_UPCASE:
715 changeCase(cur, Text::text_uppercase);
718 case LFUN_WORD_LOWCASE:
719 changeCase(cur, Text::text_lowercase);
722 case LFUN_WORD_CAPITALIZE:
723 changeCase(cur, Text::text_capitalization);
726 case LFUN_CHARS_TRANSPOSE:
731 cur.message(_("Paste"));
732 cap::replaceSelection(cur);
733 if (cmd.argument().empty() && !theClipboard().isInternal())
734 pasteClipboard(cur, bv->buffer().errorList("Paste"));
736 string const arg(to_utf8(cmd.argument()));
737 pasteFromStack(cur, bv->buffer().errorList("Paste"),
738 isStrUnsignedInt(arg) ?
739 convert<unsigned int>(arg) :
742 bv->buffer().errors("Paste");
743 cur.clearSelection(); // bug 393
748 cutSelection(cur, true, true);
749 cur.message(_("Cut"));
754 cur.message(_("Copy"));
757 case LFUN_SERVER_GET_XY:
758 cur.message(from_utf8(
759 convert<string>(tm.cursorX(cur.top(), cur.boundary()))
760 + ' ' + convert<string>(tm.cursorY(cur.top(), cur.boundary()))));
763 case LFUN_SERVER_SET_XY: {
766 istringstream is(to_utf8(cmd.argument()));
769 lyxerr << "SETXY: Could not parse coordinates in '"
770 << to_utf8(cmd.argument()) << std::endl;
772 tm.setCursorFromCoordinates(cur, x, y);
776 case LFUN_SERVER_GET_FONT:
777 if (cur.current_font.shape() == Font::ITALIC_SHAPE)
778 cur.message(from_ascii("E"));
779 else if (cur.current_font.shape() == Font::SMALLCAPS_SHAPE)
780 cur.message(from_ascii("N"));
782 cur.message(from_ascii("0"));
785 case LFUN_SERVER_GET_LAYOUT:
786 cur.message(cur.paragraph().layout()->name());
790 docstring layout = cmd.argument();
791 LYXERR(Debug::INFO) << "LFUN_LAYOUT: (arg) " << to_utf8(layout) << endl;
793 // Derive layout number from given argument (string)
794 // and current buffer's textclass (number)
795 TextClass const & tclass = bv->buffer().params().getTextClass();
797 layout = tclass.defaultLayoutName();
798 bool hasLayout = tclass.hasLayout(layout);
800 // If the entry is obsolete, use the new one instead.
802 docstring const & obs = tclass[layout]->obsoleted_by();
808 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
809 from_utf8(N_(" not known")));
813 bool change_layout = (frontend::current_layout != layout);
815 if (!change_layout && cur.selection() &&
816 cur.selBegin().pit() != cur.selEnd().pit())
818 pit_type spit = cur.selBegin().pit();
819 pit_type epit = cur.selEnd().pit() + 1;
820 while (spit != epit) {
821 if (pars_[spit].layout()->name() != frontend::current_layout) {
822 change_layout = true;
830 setLayout(cur, layout);
831 // inform the GUI that the layout has changed.
832 bv->layoutChanged(layout);
837 case LFUN_CLIPBOARD_PASTE:
838 cur.clearSelection();
839 pasteClipboard(cur, bv->buffer().errorList("Paste"),
840 cmd.argument() == "paragraph");
841 bv->buffer().errors("Paste");
844 case LFUN_PRIMARY_SELECTION_PASTE:
845 pasteString(cur, theSelection().get(),
846 cmd.argument() == "paragraph");
849 case LFUN_UNICODE_INSERT: {
850 if (cmd.argument().empty())
852 docstring hexstring = cmd.argument();
853 if (lyx::support::isHex(hexstring)) {
854 char_type c = lyx::support::hexToInt(hexstring);
855 if (c >= 32 && c < 0x10ffff) {
856 lyxerr << "Inserting c: " << c << endl;
857 docstring s = docstring(1, c);
858 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
864 case LFUN_QUOTE_INSERT: {
865 Paragraph & par = cur.paragraph();
866 pos_type pos = cur.pos();
867 BufferParams const & bufparams = bv->buffer().params();
868 LayoutPtr const & style = par.layout();
869 if (!style->pass_thru
870 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
871 // this avoids a double undo
872 // FIXME: should not be needed, ideally
873 if (!cur.selection())
875 cap::replaceSelection(cur);
880 else if (cur.prevInset() && cur.prevInset()->isSpace())
883 c = par.getChar(pos - 1);
884 string arg = to_utf8(cmd.argument());
886 cur.insert(new InsetQuotes(c,
887 bufparams.quotes_language,
888 InsetQuotes::SingleQ));
890 cur.insert(new InsetQuotes(c,
891 bufparams.quotes_language,
892 InsetQuotes::DoubleQ));
896 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
900 case LFUN_DATE_INSERT: {
901 string const format = cmd.argument().empty()
902 ? lyxrc.date_insert_format : to_utf8(cmd.argument());
903 string const time = formatted_time(current_time(), format);
904 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, time));
908 case LFUN_MOUSE_TRIPLE:
909 if (cmd.button() == mouse_button::button1) {
918 case LFUN_MOUSE_DOUBLE:
919 if (cmd.button() == mouse_button::button1) {
920 selectWord(cur, WHOLE_WORD_STRICT);
925 // Single-click on work area
926 case LFUN_MOUSE_PRESS: {
927 // Right click on a footnote flag opens float menu
928 if (cmd.button() == mouse_button::button3)
929 cur.clearSelection();
932 bool update = bv->mouseSetCursor(cur);
934 // Insert primary selection with middle mouse
935 // if there is a local selection in the current buffer,
937 if (cmd.button() == mouse_button::button2) {
938 if (cap::selection()) {
939 // Copy the selection buffer to the clipboard
940 // stack, because we want it to appear in the
941 // "Edit->Paste recent" menu.
942 cap::copySelectionToStack();
944 cap::pasteSelection(bv->cursor(),
945 bv->buffer().errorList("Paste"));
946 bv->buffer().errors("Paste");
947 bv->buffer().markDirty();
950 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
954 // we have to update after dEPM triggered
955 if (!update && cmd.button() == mouse_button::button1) {
963 case LFUN_MOUSE_MOTION: {
964 // Only use motion with button 1
965 //if (cmd.button() != mouse_button::button1)
968 // ignore motions deeper nested than the real anchor
969 Cursor & bvcur = cur.bv().cursor();
970 if (bvcur.anchor_.hasPart(cur)) {
971 CursorSlice old = bvcur.top();
973 int const wh = bv->workHeight();
974 int const y = std::max(0, std::min(wh - 1, cmd.y));
976 tm.setCursorFromCoordinates(cur, cmd.x, y);
977 cur.setTargetX(cmd.x);
979 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
981 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
982 // This is to allow jumping over large insets
983 if (cur.top() == old) {
985 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
987 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
990 if (cur.top() == old)
994 bvcur.setCursor(cur);
995 bvcur.selection() = true;
996 //lyxerr << "MOTION: " << bv->cursor() << endl;
1004 case LFUN_MOUSE_RELEASE: {
1005 if (cmd.button() == mouse_button::button2)
1008 if (cmd.button() == mouse_button::button1) {
1009 // if there is new selection, update persistent
1010 // selection, otherwise, single click does not
1011 // clear persistent selection buffer
1012 if (cur.selection()) {
1014 // if double click, cur is moved to the end of word by selectWord
1015 // but bvcur is current mouse position
1016 Cursor & bvcur = cur.bv().cursor();
1017 bvcur.selection() = true;
1019 needsUpdate = false;
1026 case LFUN_SELF_INSERT: {
1027 if (cmd.argument().empty())
1030 // Automatically delete the currently selected
1031 // text and replace it with what is being
1032 // typed in now. Depends on lyxrc settings
1033 // "auto_region_delete", which defaults to
1036 if (lyxrc.auto_region_delete && cur.selection()) {
1037 cutSelection(cur, false, false);
1038 // When change tracking is set to off, the metrics update
1039 // mechanism correctly detects if a full update is needed or not.
1040 // This detection fails when a selection spans multiple rows and
1041 // change tracking is enabled because the paragraph metrics stays
1042 // the same. In this case, we force the full update:
1043 // (see http://bugzilla.lyx.org/show_bug.cgi?id=3992)
1044 if (cur.buffer().params().trackChanges)
1045 cur.updateFlags(Update::Force);
1048 cur.clearSelection();
1049 Font const old_font = cur.real_current_font;
1051 docstring::const_iterator cit = cmd.argument().begin();
1052 docstring::const_iterator end = cmd.argument().end();
1053 for (; cit != end; ++cit)
1054 bv->translateAndInsert(*cit, this, cur);
1057 moveCursor(cur, false);
1061 case LFUN_URL_INSERT: {
1062 InsetCommandParams p("url");
1064 if (cur.selection()) {
1065 content = cur.selectionAsString(false);
1066 cutSelection(cur, true, false);
1068 p["target"] = (cmd.argument().empty()) ?
1069 content : cmd.argument();
1070 string const data = InsetCommandMailer::params2string("url", p);
1071 if (p["target"].empty()) {
1072 bv->showInsetDialog("url", data, 0);
1074 FuncRequest fr(LFUN_INSET_INSERT, data);
1080 case LFUN_HTML_INSERT: {
1081 InsetCommandParams p("htmlurl");
1083 if (cur.selection()) {
1084 content = cur.selectionAsString(false);
1085 cutSelection(cur, true, false);
1087 p["target"] = (cmd.argument().empty()) ?
1088 content : cmd.argument();
1089 string const data = InsetCommandMailer::params2string("url", p);
1090 if (p["target"].empty()) {
1091 bv->showInsetDialog("url", data, 0);
1093 FuncRequest fr(LFUN_INSET_INSERT, data);
1099 case LFUN_LABEL_INSERT: {
1100 InsetCommandParams p("label");
1101 // Try to generate a valid label
1102 p["name"] = (cmd.argument().empty()) ?
1103 cur.getPossibleLabel() :
1105 string const data = InsetCommandMailer::params2string("label", p);
1107 if (cmd.argument().empty()) {
1108 bv->showInsetDialog("label", data, 0);
1110 FuncRequest fr(LFUN_INSET_INSERT, data);
1118 case LFUN_LIST_INSERT:
1119 case LFUN_THEOREM_INSERT:
1121 case LFUN_CAPTION_INSERT:
1122 // Open the inset, and move the current selection
1124 doInsertInset(cur, this, cmd, true, true);
1126 updateLabels(bv->buffer());
1128 case LFUN_NOTE_INSERT:
1129 case LFUN_CHARSTYLE_INSERT:
1130 case LFUN_BOX_INSERT:
1131 case LFUN_BRANCH_INSERT:
1132 case LFUN_BIBITEM_INSERT:
1133 case LFUN_ERT_INSERT:
1134 case LFUN_LISTING_INSERT:
1135 case LFUN_FOOTNOTE_INSERT:
1136 case LFUN_MARGINALNOTE_INSERT:
1137 case LFUN_OPTIONAL_INSERT:
1138 case LFUN_ENVIRONMENT_INSERT:
1139 // Open the inset, and move the current selection
1141 doInsertInset(cur, this, cmd, true, true);
1145 case LFUN_TABULAR_INSERT:
1146 // if there were no arguments, just open the dialog
1147 if (doInsertInset(cur, this, cmd, false, true))
1150 bv->showDialog("tabularcreate");
1154 case LFUN_FLOAT_INSERT:
1155 case LFUN_FLOAT_WIDE_INSERT:
1156 case LFUN_WRAP_INSERT: {
1157 bool content = cur.selection(); // will some text be moved into the inset?
1159 doInsertInset(cur, this, cmd, true, true);
1161 ParagraphList & pars = cur.text()->paragraphs();
1163 TextClass const & tclass = bv->buffer().params().getTextClass();
1165 // add a separate paragraph for the caption inset
1166 pars.push_back(Paragraph());
1167 pars.back().setInsetOwner(pars[0].inInset());
1168 pars.back().layout(tclass.defaultLayout());
1170 int cap_pit = pars.size() - 1;
1172 // if an empty inset was created, we create an additional empty
1173 // paragraph at the bottom so that the user can choose where to put
1174 // the graphics (or table).
1176 pars.push_back(Paragraph());
1177 pars.back().setInsetOwner(pars[0].inInset());
1178 pars.back().layout(tclass.defaultLayout());
1182 // reposition the cursor to the caption
1183 cur.pit() = cap_pit;
1185 // FIXME: This Text/Cursor dispatch handling is a mess!
1186 // We cannot use Cursor::dispatch here it needs access to up to
1188 FuncRequest cmd_caption(LFUN_CAPTION_INSERT);
1189 cur.text()->dispatch(cur, cmd_caption);
1190 cur.updateFlags(Update::Force);
1191 // FIXME: When leaving the Float (or Wrap) inset we should
1192 // delete any empty paragraph left above or below the
1197 case LFUN_INDEX_INSERT:
1198 case LFUN_NOMENCL_INSERT: {
1199 Inset * inset = createInset(&cur.bv(), cmd);
1203 cur.clearSelection();
1204 insertInset(cur, inset);
1205 inset->edit(cur, true);
1206 // Show the dialog for the nomenclature entry, since the
1207 // description entry still needs to be filled in.
1208 if (cmd.action == LFUN_NOMENCL_INSERT)
1209 InsetCommandMailer("nomenclature",
1210 *reinterpret_cast<InsetCommand *>(inset)).showDialog(&cur.bv());
1215 case LFUN_INDEX_PRINT:
1216 case LFUN_NOMENCL_PRINT:
1217 case LFUN_TOC_INSERT:
1218 case LFUN_HFILL_INSERT:
1219 case LFUN_LINE_INSERT:
1220 case LFUN_PAGEBREAK_INSERT:
1221 case LFUN_CLEARPAGE_INSERT:
1222 case LFUN_CLEARDOUBLEPAGE_INSERT:
1224 doInsertInset(cur, this, cmd, false, false);
1228 case LFUN_DEPTH_DECREMENT:
1229 changeDepth(cur, DEC_DEPTH);
1232 case LFUN_DEPTH_INCREMENT:
1233 changeDepth(cur, INC_DEPTH);
1236 case LFUN_MATH_DISPLAY:
1237 mathDispatch(cur, cmd, true);
1240 case LFUN_MATH_IMPORT_SELECTION:
1241 case LFUN_MATH_MODE:
1242 if (cmd.argument() == "on")
1243 // don't pass "on" as argument
1244 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1246 mathDispatch(cur, cmd, false);
1249 case LFUN_MATH_MACRO:
1250 if (cmd.argument().empty())
1251 cur.errorMessage(from_utf8(N_("Missing argument")));
1253 string s = to_utf8(cmd.argument());
1254 string const s1 = token(s, ' ', 1);
1255 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1256 string const s2 = token(s, ' ', 2);
1257 string const type = s2.empty() ? "newcommand" : s2;
1258 cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, from_utf8(type)));
1259 //cur.nextInset()->edit(cur, true);
1263 // passthrough hat and underscore outside mathed:
1264 case LFUN_MATH_SUBSCRIPT:
1265 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1267 case LFUN_MATH_SUPERSCRIPT:
1268 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1271 case LFUN_MATH_INSERT:
1272 case LFUN_MATH_MATRIX:
1273 case LFUN_MATH_DELIM:
1274 case LFUN_MATH_BIGDELIM: {
1275 if (cur.selection())
1276 cur.clearSelection();
1277 // FIXME: instead of the above, this one
1278 // should be used (but it asserts with Bidi enabled)
1279 // cf. http://bugzilla.lyx.org/show_bug.cgi?id=4055
1280 // cap::replaceSelection(cur);
1281 cur.insert(new InsetMathHull(hullSimple));
1282 checkAndActivateInset(cur, true);
1283 BOOST_ASSERT(cur.inMathed());
1288 case LFUN_FONT_EMPH: {
1289 Font font(Font::ALL_IGNORE);
1290 font.setEmph(Font::TOGGLE);
1291 toggleAndShow(cur, this, font);
1295 case LFUN_FONT_BOLD: {
1296 Font font(Font::ALL_IGNORE);
1297 font.setSeries(Font::BOLD_SERIES);
1298 toggleAndShow(cur, this, font);
1302 case LFUN_FONT_NOUN: {
1303 Font font(Font::ALL_IGNORE);
1304 font.setNoun(Font::TOGGLE);
1305 toggleAndShow(cur, this, font);
1309 case LFUN_FONT_CODE: {
1310 Font font(Font::ALL_IGNORE);
1311 font.setFamily(Font::TYPEWRITER_FAMILY); // no good
1312 toggleAndShow(cur, this, font);
1316 case LFUN_FONT_SANS: {
1317 Font font(Font::ALL_IGNORE);
1318 font.setFamily(Font::SANS_FAMILY);
1319 toggleAndShow(cur, this, font);
1323 case LFUN_FONT_ROMAN: {
1324 Font font(Font::ALL_IGNORE);
1325 font.setFamily(Font::ROMAN_FAMILY);
1326 toggleAndShow(cur, this, font);
1330 case LFUN_FONT_DEFAULT: {
1331 Font font(Font::ALL_INHERIT, ignore_language);
1332 toggleAndShow(cur, this, font);
1336 case LFUN_FONT_UNDERLINE: {
1337 Font font(Font::ALL_IGNORE);
1338 font.setUnderbar(Font::TOGGLE);
1339 toggleAndShow(cur, this, font);
1343 case LFUN_FONT_SIZE: {
1344 Font font(Font::ALL_IGNORE);
1345 font.setLyXSize(to_utf8(cmd.argument()));
1346 toggleAndShow(cur, this, font);
1350 case LFUN_LANGUAGE: {
1351 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1354 Font font(Font::ALL_IGNORE);
1355 font.setLanguage(lang);
1356 toggleAndShow(cur, this, font);
1360 case LFUN_FONT_FREE_APPLY:
1361 toggleAndShow(cur, this, freefont, toggleall);
1362 cur.message(_("Character set"));
1365 // Set the freefont using the contents of \param data dispatched from
1366 // the frontends and apply it at the current cursor location.
1367 case LFUN_FONT_FREE_UPDATE: {
1370 if (bv_funcs::string2font(to_utf8(cmd.argument()), font, toggle)) {
1373 toggleAndShow(cur, this, freefont, toggleall);
1374 cur.message(_("Character set"));
1379 case LFUN_FINISHED_LEFT:
1380 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1381 if (reverseDirectionNeeded(cur))
1385 case LFUN_FINISHED_RIGHT:
1386 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1387 if (!reverseDirectionNeeded(cur))
1391 case LFUN_LAYOUT_PARAGRAPH: {
1393 params2string(cur.paragraph(), data);
1394 data = "show\n" + data;
1395 bv->showDialogWithData("paragraph", data);
1399 case LFUN_PARAGRAPH_UPDATE: {
1401 params2string(cur.paragraph(), data);
1403 // Will the paragraph accept changes from the dialog?
1404 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1406 data = "update " + convert<string>(accept) + '\n' + data;
1407 bv->updateDialog("paragraph", data);
1411 case LFUN_ACCENT_UMLAUT:
1412 case LFUN_ACCENT_CIRCUMFLEX:
1413 case LFUN_ACCENT_GRAVE:
1414 case LFUN_ACCENT_ACUTE:
1415 case LFUN_ACCENT_TILDE:
1416 case LFUN_ACCENT_CEDILLA:
1417 case LFUN_ACCENT_MACRON:
1418 case LFUN_ACCENT_DOT:
1419 case LFUN_ACCENT_UNDERDOT:
1420 case LFUN_ACCENT_UNDERBAR:
1421 case LFUN_ACCENT_CARON:
1422 case LFUN_ACCENT_SPECIAL_CARON:
1423 case LFUN_ACCENT_BREVE:
1424 case LFUN_ACCENT_TIE:
1425 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1426 case LFUN_ACCENT_CIRCLE:
1427 case LFUN_ACCENT_OGONEK:
1428 theLyXFunc().handleKeyFunc(cmd.action);
1429 if (!cmd.argument().empty())
1430 // FIXME: Are all these characters encoded in one byte in utf8?
1431 bv->translateAndInsert(cmd.argument()[0], this, cur);
1434 case LFUN_FLOAT_LIST: {
1435 TextClass const & tclass = bv->buffer().params().getTextClass();
1436 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1438 if (cur.selection())
1439 cutSelection(cur, true, false);
1440 breakParagraph(cur);
1442 if (cur.lastpos() != 0) {
1444 breakParagraph(cur);
1447 setLayout(cur, tclass.defaultLayoutName());
1448 ParagraphParameters p;
1449 setParagraphs(cur, p);
1450 insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1453 lyxerr << "Non-existent float type: "
1454 << to_utf8(cmd.argument()) << endl;
1459 case LFUN_CHANGE_ACCEPT: {
1460 acceptOrRejectChanges(cur, ACCEPT);
1464 case LFUN_CHANGE_REJECT: {
1465 acceptOrRejectChanges(cur, REJECT);
1469 case LFUN_THESAURUS_ENTRY: {
1470 docstring arg = cmd.argument();
1472 arg = cur.selectionAsString(false);
1474 if (arg.size() > 100 || arg.empty()) {
1475 // Get word or selection
1476 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1477 arg = cur.selectionAsString(false);
1480 bv->showDialogWithData("thesaurus", to_utf8(arg));
1484 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1485 // Given data, an encoding of the ParagraphParameters
1486 // generated in the Paragraph dialog, this function sets
1487 // the current paragraph, or currently selected paragraphs,
1489 // NOTE: This function overrides all existing settings.
1490 setParagraphs(cur, cmd.argument());
1491 cur.message(_("Paragraph layout set"));
1495 case LFUN_PARAGRAPH_PARAMS: {
1496 // Given data, an encoding of the ParagraphParameters as we'd
1497 // find them in a LyX file, this function modifies the current paragraph,
1498 // or currently selected paragraphs.
1499 // NOTE: This function only modifies, and does not override, existing
1501 setParagraphs(cur, cmd.argument(), true);
1502 cur.message(_("Paragraph layout set"));
1507 if (cur.selection()) {
1508 cur.selection() = false;
1511 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1516 LYXERR(Debug::ACTION)
1517 << BOOST_CURRENT_FUNCTION
1518 << ": Command " << cmd
1519 << " not DISPATCHED by Text" << endl;
1524 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1526 // FIXME: The cursor flag is reset two lines below
1527 // so we need to check here if some of the LFUN did touch that.
1528 // for now only Text::erase() and Text::backspace() do that.
1529 // The plan is to verify all the LFUNs and then to remove this
1530 // singleParUpdate boolean altogether.
1531 if (cur.result().update() & Update::Force) {
1532 singleParUpdate = false;
1536 // FIXME: the following code should go in favor of fine grained
1537 // update flag treatment.
1538 if (singleParUpdate) {
1539 // Inserting characters does not change par height
1540 ParagraphMetrics const & pms
1541 = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
1542 if (pms.dim().height()
1543 == olddim.height()) {
1544 // if so, update _only_ this paragraph
1545 cur.updateFlags(Update::SinglePar |
1547 Update::MultiParSel);
1554 && &oldTopSlice.inset() == &cur.inset()
1555 && oldTopSlice.idx() == cur.idx()
1556 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1557 && !cur.selection())
1558 // FIXME: it would be better if we could just do this
1560 //if (cur.result().update() != Update::FitCursor)
1563 // But some LFUNs do not set Update::FitCursor when needed, so we
1564 // do it for all. This is not very harmfull as FitCursor will provoke
1565 // a full redraw only if needed but still, a proper review of all LFUN
1566 // should be done and this needsUpdate boolean can then be removed.
1567 cur.updateFlags(Update::FitCursor);
1569 cur.updateFlags(Update::Force | Update::FitCursor);
1573 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
1574 FuncStatus & flag) const
1576 BOOST_ASSERT(cur.text() == this);
1578 Font const & font = cur.real_current_font;
1580 Inset::Code code = Inset::NO_CODE;
1582 switch (cmd.action) {
1584 case LFUN_DEPTH_DECREMENT:
1585 enable = changeDepthAllowed(cur, DEC_DEPTH);
1588 case LFUN_DEPTH_INCREMENT:
1589 enable = changeDepthAllowed(cur, INC_DEPTH);
1593 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1596 case LFUN_BIBITEM_INSERT:
1597 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO
1601 case LFUN_DIALOG_SHOW_NEW_INSET:
1602 if (cmd.argument() == "bibitem")
1603 code = Inset::BIBITEM_CODE;
1604 else if (cmd.argument() == "bibtex")
1605 code = Inset::BIBTEX_CODE;
1606 else if (cmd.argument() == "box")
1607 code = Inset::BOX_CODE;
1608 else if (cmd.argument() == "branch")
1609 code = Inset::BRANCH_CODE;
1610 else if (cmd.argument() == "citation")
1611 code = Inset::CITE_CODE;
1612 else if (cmd.argument() == "ert")
1613 code = Inset::ERT_CODE;
1614 else if (cmd.argument() == "external")
1615 code = Inset::EXTERNAL_CODE;
1616 else if (cmd.argument() == "float")
1617 code = Inset::FLOAT_CODE;
1618 else if (cmd.argument() == "graphics")
1619 code = Inset::GRAPHICS_CODE;
1620 else if (cmd.argument() == "include")
1621 code = Inset::INCLUDE_CODE;
1622 else if (cmd.argument() == "index")
1623 code = Inset::INDEX_CODE;
1624 else if (cmd.argument() == "nomenclature")
1625 code = Inset::NOMENCL_CODE;
1626 else if (cmd.argument() == "label")
1627 code = Inset::LABEL_CODE;
1628 else if (cmd.argument() == "note")
1629 code = Inset::NOTE_CODE;
1630 else if (cmd.argument() == "ref")
1631 code = Inset::REF_CODE;
1632 else if (cmd.argument() == "toc")
1633 code = Inset::TOC_CODE;
1634 else if (cmd.argument() == "url")
1635 code = Inset::URL_CODE;
1636 else if (cmd.argument() == "vspace")
1637 code = Inset::VSPACE_CODE;
1638 else if (cmd.argument() == "wrap")
1639 code = Inset::WRAP_CODE;
1640 else if (cmd.argument() == "listings")
1641 code = Inset::LISTINGS_CODE;
1644 case LFUN_ERT_INSERT:
1645 code = Inset::ERT_CODE;
1647 case LFUN_LISTING_INSERT:
1648 code = Inset::LISTINGS_CODE;
1650 case LFUN_FOOTNOTE_INSERT:
1651 code = Inset::FOOT_CODE;
1653 case LFUN_TABULAR_INSERT:
1654 code = Inset::TABULAR_CODE;
1656 case LFUN_MARGINALNOTE_INSERT:
1657 code = Inset::MARGIN_CODE;
1659 case LFUN_FLOAT_INSERT:
1660 case LFUN_FLOAT_WIDE_INSERT:
1661 code = Inset::FLOAT_CODE;
1663 case LFUN_WRAP_INSERT:
1664 code = Inset::WRAP_CODE;
1666 case LFUN_FLOAT_LIST:
1667 code = Inset::FLOAT_LIST_CODE;
1670 case LFUN_LIST_INSERT:
1671 code = Inset::LIST_CODE;
1673 case LFUN_THEOREM_INSERT:
1674 code = Inset::THEOREM_CODE;
1677 case LFUN_CAPTION_INSERT:
1678 code = Inset::CAPTION_CODE;
1680 case LFUN_NOTE_INSERT:
1681 code = Inset::NOTE_CODE;
1683 case LFUN_CHARSTYLE_INSERT:
1684 code = Inset::CHARSTYLE_CODE;
1685 if (cur.buffer().params().getTextClass().insetlayouts().empty())
1688 case LFUN_BOX_INSERT:
1689 code = Inset::BOX_CODE;
1691 case LFUN_BRANCH_INSERT:
1692 code = Inset::BRANCH_CODE;
1693 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1696 case LFUN_LABEL_INSERT:
1697 code = Inset::LABEL_CODE;
1699 case LFUN_OPTIONAL_INSERT:
1700 code = Inset::OPTARG_CODE;
1701 enable = numberOfOptArgs(cur.paragraph())
1702 < cur.paragraph().layout()->optionalargs;
1704 case LFUN_ENVIRONMENT_INSERT:
1705 code = Inset::BOX_CODE;
1707 case LFUN_INDEX_INSERT:
1708 code = Inset::INDEX_CODE;
1710 case LFUN_INDEX_PRINT:
1711 code = Inset::INDEX_PRINT_CODE;
1713 case LFUN_NOMENCL_INSERT:
1714 code = Inset::NOMENCL_CODE;
1716 case LFUN_NOMENCL_PRINT:
1717 code = Inset::NOMENCL_PRINT_CODE;
1719 case LFUN_TOC_INSERT:
1720 code = Inset::TOC_CODE;
1722 case LFUN_HTML_INSERT:
1723 case LFUN_URL_INSERT:
1724 code = Inset::URL_CODE;
1726 case LFUN_QUOTE_INSERT:
1727 // always allow this, since we will inset a raw quote
1728 // if an inset is not allowed.
1730 case LFUN_HYPHENATION_POINT_INSERT:
1731 case LFUN_LIGATURE_BREAK_INSERT:
1732 case LFUN_HFILL_INSERT:
1733 case LFUN_MENU_SEPARATOR_INSERT:
1734 case LFUN_DOTS_INSERT:
1735 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
1736 code = Inset::SPECIALCHAR_CODE;
1738 case LFUN_SPACE_INSERT:
1739 // slight hack: we know this is allowed in math mode
1741 code = Inset::SPACE_CODE;
1744 case LFUN_INSET_MODIFY:
1745 // We need to disable this, because we may get called for a
1747 // InsetTabular::getStatus() -> InsetText::getStatus()
1748 // and we don't handle LFUN_INSET_MODIFY.
1752 case LFUN_FONT_EMPH:
1753 flag.setOnOff(font.emph() == Font::ON);
1756 case LFUN_FONT_NOUN:
1757 flag.setOnOff(font.noun() == Font::ON);
1760 case LFUN_FONT_BOLD:
1761 flag.setOnOff(font.series() == Font::BOLD_SERIES);
1764 case LFUN_FONT_SANS:
1765 flag.setOnOff(font.family() == Font::SANS_FAMILY);
1768 case LFUN_FONT_ROMAN:
1769 flag.setOnOff(font.family() == Font::ROMAN_FAMILY);
1772 case LFUN_FONT_CODE:
1773 flag.setOnOff(font.family() == Font::TYPEWRITER_FAMILY);
1778 enable = cur.selection();
1782 if (cmd.argument().empty()) {
1783 if (theClipboard().isInternal())
1784 enable = cap::numberOfSelections() > 0;
1786 enable = !theClipboard().empty();
1788 string const arg = to_utf8(cmd.argument());
1789 if (isStrUnsignedInt(arg)) {
1790 unsigned int n = convert<unsigned int>(arg);
1791 enable = cap::numberOfSelections() > n;
1798 case LFUN_CLIPBOARD_PASTE:
1799 enable = !theClipboard().empty();
1802 case LFUN_PRIMARY_SELECTION_PASTE:
1803 enable = cur.selection() || !theSelection().empty();
1806 case LFUN_PARAGRAPH_MOVE_UP:
1807 enable = cur.pit() > 0 && !cur.selection();
1810 case LFUN_PARAGRAPH_MOVE_DOWN:
1811 enable = cur.pit() < cur.lastpit() && !cur.selection();
1814 case LFUN_INSET_DISSOLVE:
1815 enable = !isMainText(cur.bv().buffer()) && cur.inset().nargs() == 1;
1818 case LFUN_CHANGE_ACCEPT:
1819 case LFUN_CHANGE_REJECT:
1820 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
1821 // In principle, these LFUNs should only be enabled if there
1822 // is a change at the current position/in the current selection.
1823 // However, without proper optimizations, this will inevitably
1824 // result in unacceptable performance - just imagine a user who
1825 // wants to select the complete content of a long document.
1829 case LFUN_WORD_DELETE_FORWARD:
1830 case LFUN_WORD_DELETE_BACKWARD:
1831 case LFUN_LINE_DELETE:
1832 case LFUN_WORD_FORWARD:
1833 case LFUN_WORD_BACKWARD:
1834 case LFUN_CHAR_FORWARD:
1835 case LFUN_CHAR_FORWARD_SELECT:
1836 case LFUN_CHAR_BACKWARD:
1837 case LFUN_CHAR_BACKWARD_SELECT:
1839 case LFUN_UP_SELECT:
1841 case LFUN_DOWN_SELECT:
1842 case LFUN_PARAGRAPH_UP_SELECT:
1843 case LFUN_PARAGRAPH_DOWN_SELECT:
1844 case LFUN_SCREEN_UP_SELECT:
1845 case LFUN_SCREEN_DOWN_SELECT:
1846 case LFUN_LINE_BEGIN_SELECT:
1847 case LFUN_LINE_END_SELECT:
1848 case LFUN_WORD_FORWARD_SELECT:
1849 case LFUN_WORD_BACKWARD_SELECT:
1850 case LFUN_WORD_SELECT:
1851 case LFUN_PARAGRAPH_UP:
1852 case LFUN_PARAGRAPH_DOWN:
1853 case LFUN_SCREEN_UP:
1854 case LFUN_SCREEN_DOWN:
1855 case LFUN_LINE_BEGIN:
1857 case LFUN_BREAK_LINE:
1858 case LFUN_CHAR_DELETE_FORWARD:
1859 case LFUN_DELETE_FORWARD_SKIP:
1860 case LFUN_CHAR_DELETE_BACKWARD:
1861 case LFUN_DELETE_BACKWARD_SKIP:
1862 case LFUN_BREAK_PARAGRAPH:
1863 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
1864 case LFUN_BREAK_PARAGRAPH_SKIP:
1865 case LFUN_PARAGRAPH_SPACING:
1866 case LFUN_INSET_INSERT:
1867 case LFUN_WORD_UPCASE:
1868 case LFUN_WORD_LOWCASE:
1869 case LFUN_WORD_CAPITALIZE:
1870 case LFUN_CHARS_TRANSPOSE:
1871 case LFUN_SERVER_GET_XY:
1872 case LFUN_SERVER_SET_XY:
1873 case LFUN_SERVER_GET_FONT:
1874 case LFUN_SERVER_GET_LAYOUT:
1876 case LFUN_DATE_INSERT:
1877 case LFUN_SELF_INSERT:
1878 case LFUN_LINE_INSERT:
1879 case LFUN_PAGEBREAK_INSERT:
1880 case LFUN_CLEARPAGE_INSERT:
1881 case LFUN_CLEARDOUBLEPAGE_INSERT:
1882 case LFUN_MATH_DISPLAY:
1883 case LFUN_MATH_IMPORT_SELECTION:
1884 case LFUN_MATH_MODE:
1885 case LFUN_MATH_MACRO:
1886 case LFUN_MATH_MATRIX:
1887 case LFUN_MATH_DELIM:
1888 case LFUN_MATH_BIGDELIM:
1889 case LFUN_MATH_INSERT:
1890 case LFUN_MATH_SUBSCRIPT:
1891 case LFUN_MATH_SUPERSCRIPT:
1892 case LFUN_FONT_DEFAULT:
1893 case LFUN_FONT_UNDERLINE:
1894 case LFUN_FONT_SIZE:
1896 case LFUN_FONT_FREE_APPLY:
1897 case LFUN_FONT_FREE_UPDATE:
1898 case LFUN_LAYOUT_PARAGRAPH:
1899 case LFUN_PARAGRAPH_UPDATE:
1900 case LFUN_ACCENT_UMLAUT:
1901 case LFUN_ACCENT_CIRCUMFLEX:
1902 case LFUN_ACCENT_GRAVE:
1903 case LFUN_ACCENT_ACUTE:
1904 case LFUN_ACCENT_TILDE:
1905 case LFUN_ACCENT_CEDILLA:
1906 case LFUN_ACCENT_MACRON:
1907 case LFUN_ACCENT_DOT:
1908 case LFUN_ACCENT_UNDERDOT:
1909 case LFUN_ACCENT_UNDERBAR:
1910 case LFUN_ACCENT_CARON:
1911 case LFUN_ACCENT_SPECIAL_CARON:
1912 case LFUN_ACCENT_BREVE:
1913 case LFUN_ACCENT_TIE:
1914 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1915 case LFUN_ACCENT_CIRCLE:
1916 case LFUN_ACCENT_OGONEK:
1917 case LFUN_THESAURUS_ENTRY:
1918 case LFUN_PARAGRAPH_PARAMS_APPLY:
1919 case LFUN_PARAGRAPH_PARAMS:
1921 case LFUN_BUFFER_END:
1922 case LFUN_BUFFER_BEGIN:
1923 case LFUN_BUFFER_BEGIN_SELECT:
1924 case LFUN_BUFFER_END_SELECT:
1925 case LFUN_UNICODE_INSERT:
1926 // these are handled in our dispatch()
1934 if (code != Inset::NO_CODE
1935 && (cur.empty() || !cur.inset().insetAllowed(code)))
1938 flag.enabled(enable);
1943 void Text::pasteString(Cursor & cur, docstring const & clip,
1946 cur.clearSelection();
1947 if (!clip.empty()) {
1950 insertStringAsParagraphs(cur, clip);
1952 insertStringAsLines(cur, clip);