3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Asger Alstrup
7 * \author Lars Gullik Bjønnes
8 * \author Alfredo Braunstein
9 * \author Angus Leeming
11 * \author André Pönitz
13 * Full author contact details are available in file CREDITS.
20 #include "BranchList.h"
21 #include "FloatList.h"
22 #include "FuncStatus.h"
24 #include "buffer_funcs.h"
25 #include "BufferParams.h"
26 #include "BufferView.h"
27 #include "bufferview_funcs.h"
29 #include "CoordCache.h"
30 #include "CutAndPaste.h"
32 #include "DispatchResult.h"
33 #include "ErrorList.h"
35 #include "FuncRequest.h"
39 #include "LyXAction.h"
44 #include "Paragraph.h"
45 #include "paragraph_funcs.h"
46 #include "ParagraphParameters.h"
49 #include "ParIterator.h"
51 #include "frontends/Clipboard.h"
52 #include "frontends/Selection.h"
54 #include "insets/InsetCommand.h"
55 #include "insets/InsetFloatList.h"
56 #include "insets/InsetNewline.h"
57 #include "insets/InsetQuotes.h"
58 #include "insets/InsetSpecialChar.h"
59 #include "insets/InsetText.h"
61 #include "support/lstrings.h"
62 #include "support/lyxlib.h"
63 #include "support/convert.h"
64 #include "support/lyxtime.h"
66 #include "mathed/InsetMathHull.h"
67 #include "mathed/MathMacroTemplate.h"
69 #include <boost/current_function.hpp>
77 using cap::copySelection;
78 using cap::cutSelection;
79 using cap::pasteFromStack;
80 using cap::pasteClipboard;
81 using cap::replaceSelection;
83 using support::isStrUnsignedInt;
88 using std::istringstream;
89 using std::ostringstream;
92 extern string current_layout;
98 Font freefont(Font::ALL_IGNORE);
99 bool toggleall = false;
101 void toggleAndShow(Cursor & cur, Text * text,
102 Font const & font, bool toggleall = true)
104 text->toggleFree(cur, font, toggleall);
106 if (font.language() != ignore_language ||
107 font.number() != Font::IGNORE) {
108 Paragraph & par = cur.paragraph();
109 if (cur.boundary() != text->isRTLBoundary(cur.buffer(), par,
110 cur.pos(), text->real_current_font))
111 text->setCursor(cur, cur.pit(), cur.pos(),
112 false, !cur.boundary());
117 void moveCursor(Cursor & cur, bool selecting)
119 if (selecting || cur.mark())
124 void finishChange(Cursor & cur, bool selecting)
127 moveCursor(cur, selecting);
131 void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
134 docstring sel = cur.selectionAsString(false);
136 // It may happen that sel is empty but there is a selection
137 replaceSelection(cur);
140 #ifdef ENABLE_ASSERTIONS
141 const int old_pos = cur.pos();
143 cur.insert(new InsetMathHull(hullSimple));
144 BOOST_ASSERT(old_pos == cur.pos());
145 cur.nextInset()->edit(cur, true);
146 // don't do that also for LFUN_MATH_MODE
147 // unless you want end up with always changing
148 // to mathrm when opening an inlined inset --
149 // I really hate "LyXfunc overloading"...
151 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
152 // Avoid an unnecessary undo step if cmd.argument
154 if (!cmd.argument().empty())
155 cur.dispatch(FuncRequest(LFUN_MATH_INSERT,
158 // create a macro if we see "\\newcommand"
159 // somewhere, and an ordinary formula
161 if (sel.find(from_ascii("\\newcommand")) == string::npos
162 && sel.find(from_ascii("\\def")) == string::npos)
164 InsetMathHull * formula = new InsetMathHull;
165 istringstream is(to_utf8(sel));
168 formula->read(cur.buffer(), lex);
169 if (formula->getType() == hullNone)
170 // Don't create pseudo formulas if
171 // delimiters are left out
172 formula->mutate(hullSimple);
175 cur.insert(new MathMacroTemplate(sel));
178 cur.message(from_utf8(N_("Math editor mode")));
187 string const freefont2string()
190 if (font2string(freefont, toggleall, data))
197 void Text::cursorPrevious(Cursor & cur)
199 pos_type cpos = cur.pos();
200 pit_type cpar = cur.pit();
202 int x = cur.x_target();
203 setCursorFromCoordinates(cur, x, 0);
204 cur.dispatch(FuncRequest(cur.selection()? LFUN_UP_SELECT: LFUN_UP));
206 if (cpar == cur.pit() && cpos == cur.pos())
207 // we have a row which is taller than the workarea. The
208 // simplest solution is to move to the previous row instead.
209 cur.dispatch(FuncRequest(cur.selection()? LFUN_UP_SELECT: LFUN_UP));
212 cur.updateFlags(Update::Force | Update::FitCursor);
216 void Text::cursorNext(Cursor & cur)
218 pos_type cpos = cur.pos();
219 pit_type cpar = cur.pit();
221 int x = cur.x_target();
222 setCursorFromCoordinates(cur, x, cur.bv().workHeight() - 1);
223 cur.dispatch(FuncRequest(cur.selection()? LFUN_DOWN_SELECT: LFUN_DOWN));
225 if (cpar == cur.pit() && cpos == cur.pos())
226 // we have a row which is taller than the workarea. The
227 // simplest solution is to move to the next row instead.
229 FuncRequest(cur.selection()? LFUN_DOWN_SELECT: LFUN_DOWN));
232 cur.updateFlags(Update::Force | Update::FitCursor);
238 void specialChar(Cursor & cur, InsetSpecialChar::Kind kind)
241 cap::replaceSelection(cur);
242 cur.insert(new InsetSpecialChar(kind));
247 bool doInsertInset(Cursor & cur, Text * text,
248 FuncRequest const & cmd, bool edit, bool pastesel)
250 Inset * inset = createInset(&cur.bv(), cmd);
256 if (cur.selection()) {
257 lyx::dispatch(FuncRequest(LFUN_CUT));
260 text->insertInset(cur, inset);
263 inset->edit(cur, true);
265 if (gotsel && pastesel) {
266 lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
267 // reset first par to default
268 if (cur.lastpit() != 0 || cur.lastpos() != 0) {
269 Layout_ptr const layout =
270 cur.buffer().params().getTextClass().defaultLayout();
271 cur.text()->paragraphs().begin()->layout(layout);
281 void Text::number(Cursor & cur)
283 Font font(Font::ALL_IGNORE);
284 font.setNumber(Font::TOGGLE);
285 toggleAndShow(cur, this, font);
289 bool Text::isRTL(Buffer const & buffer, Paragraph const & par) const
291 return par.isRightToLeftPar(buffer.params());
295 bool Text::isRTL(Buffer const & buffer, CursorSlice const & sl, bool boundary) const
297 if (!lyxrc.rtl_support && !sl.text())
301 if (boundary && sl.pos() > 0)
304 Paragraph const & par = getPar(sl.pit());
305 return getFont(buffer, par, sl.pos() + correction).isVisibleRightToLeft();
309 bool Text::isRTLBoundary(Buffer const & buffer, Paragraph const & par,
312 if (!lyxrc.rtl_support)
315 // no RTL boundary at line start
319 bool left = getFont(buffer, par, pos - 1).isVisibleRightToLeft();
321 if (pos == par.size())
322 right = par.isRightToLeftPar(buffer.params());
324 right = getFont(buffer, par, pos).isVisibleRightToLeft();
325 return left != right;
329 bool Text::isRTLBoundary(Buffer const & buffer, Paragraph const & par,
330 pos_type pos, Font const & font) const
332 if (!lyxrc.rtl_support)
335 bool left = font.isVisibleRightToLeft();
337 if (pos == par.size())
338 right = par.isRightToLeftPar(buffer.params());
340 right = getFont(buffer, par, pos).isVisibleRightToLeft();
341 return left != right;
345 void Text::dispatch(Cursor & cur, FuncRequest & cmd)
347 LYXERR(Debug::ACTION) << "Text::dispatch: cmd: " << cmd << endl;
349 // FIXME: We use the update flag to indicates wether a singlePar or a
350 // full screen update is needed. We reset it here but shall we restore it
354 BOOST_ASSERT(cur.text() == this);
355 BufferView * bv = &cur.bv();
356 CursorSlice oldTopSlice = cur.top();
357 bool oldBoundary = cur.boundary();
358 bool sel = cur.selection();
359 // Signals that, even if needsUpdate == false, an update of the
360 // cursor paragraph is required
361 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
362 LyXAction::SingleParUpdate);
363 // Signals that a full-screen update is required
364 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
365 LyXAction::NoUpdate) || singleParUpdate);
366 // Remember the old paragraph metric (_outer_ paragraph!)
367 ParagraphMetrics const & pm = cur.bv().parMetrics(
368 cur.bottom().text(), cur.bottom().pit());
369 Dimension olddim = pm.dim();
371 switch (cmd.action) {
373 case LFUN_PARAGRAPH_MOVE_DOWN: {
374 pit_type const pit = cur.pit();
375 recUndo(cur, pit, pit + 1);
377 std::swap(pars_[pit], pars_[pit + 1]);
378 updateLabels(cur.buffer());
383 case LFUN_PARAGRAPH_MOVE_UP: {
384 pit_type const pit = cur.pit();
385 recUndo(cur, pit - 1, pit);
387 std::swap(pars_[pit], pars_[pit - 1]);
388 updateLabels(cur.buffer());
393 case LFUN_APPENDIX: {
394 Paragraph & par = cur.paragraph();
395 bool start = !par.params().startOfAppendix();
398 #warning The code below only makes sense at top level.
399 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
401 // ensure that we have only one start_of_appendix in this document
402 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
403 if (pars_[tmp].params().startOfAppendix()) {
405 pars_[tmp].params().startOfAppendix(false);
411 par.params().startOfAppendix(start);
413 // we can set the refreshing parameters now
414 updateLabels(cur.buffer());
418 case LFUN_WORD_DELETE_FORWARD:
419 if (cur.selection()) {
420 cutSelection(cur, true, false);
422 deleteWordForward(cur);
423 finishChange(cur, false);
426 case LFUN_WORD_DELETE_BACKWARD:
427 if (cur.selection()) {
428 cutSelection(cur, true, false);
430 deleteWordBackward(cur);
431 finishChange(cur, false);
434 case LFUN_LINE_DELETE:
435 if (cur.selection()) {
436 cutSelection(cur, true, false);
438 deleteLineForward(cur);
439 finishChange(cur, false);
442 case LFUN_BUFFER_BEGIN:
443 case LFUN_BUFFER_BEGIN_SELECT:
444 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
445 if (cur.depth() == 1) {
446 needsUpdate |= cursorTop(cur);
452 case LFUN_BUFFER_END:
453 case LFUN_BUFFER_END_SELECT:
454 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
455 if (cur.depth() == 1) {
456 needsUpdate |= cursorBottom(cur);
462 case LFUN_CHAR_FORWARD:
463 case LFUN_CHAR_FORWARD_SELECT:
464 //lyxerr << BOOST_CURRENT_FUNCTION
465 // << " LFUN_CHAR_FORWARD[SEL]:\n" << cur << endl;
466 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
467 if (reverseDirectionNeeded(cur))
468 needsUpdate |= cursorLeft(cur);
470 needsUpdate |= cursorRight(cur);
472 if (!needsUpdate && oldTopSlice == cur.top()
473 && cur.boundary() == oldBoundary) {
475 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
479 case LFUN_CHAR_BACKWARD:
480 case LFUN_CHAR_BACKWARD_SELECT:
481 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
482 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
483 if (reverseDirectionNeeded(cur))
484 needsUpdate |= cursorRight(cur);
486 needsUpdate |= cursorLeft(cur);
488 if (!needsUpdate && oldTopSlice == cur.top()
489 && cur.boundary() == oldBoundary) {
491 cmd = FuncRequest(LFUN_FINISHED_LEFT);
496 case LFUN_DOWN_SELECT:
499 // stop/start the selection
500 bool select = cmd.action == LFUN_DOWN_SELECT ||
501 cmd.action == LFUN_UP_SELECT;
502 cur.selHandle(select);
504 // move cursor up/down
505 bool up = cmd.action == LFUN_UP_SELECT || cmd.action == LFUN_UP;
506 bool const successful = cur.upDownInText(up, needsUpdate);
508 // notify insets which were left and get their update flags
509 notifyCursorLeaves(cur.beforeDispatchCursor(), cur);
512 // redraw if you leave mathed (for the decorations)
513 needsUpdate |= cur.beforeDispatchCursor().inMathed();
520 case LFUN_PARAGRAPH_UP:
521 case LFUN_PARAGRAPH_UP_SELECT:
522 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
523 needsUpdate |= cursorUpParagraph(cur);
526 case LFUN_PARAGRAPH_DOWN:
527 case LFUN_PARAGRAPH_DOWN_SELECT:
528 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
529 needsUpdate |= cursorDownParagraph(cur);
533 case LFUN_SCREEN_UP_SELECT:
534 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_UP_SELECT);
535 if (cur.pit() == 0 && cur.textRow().pos() == 0)
542 case LFUN_SCREEN_DOWN:
543 case LFUN_SCREEN_DOWN_SELECT:
544 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_DOWN_SELECT);
545 if (cur.pit() == cur.lastpit()
546 && cur.textRow().endpos() == cur.lastpos())
553 case LFUN_LINE_BEGIN:
554 case LFUN_LINE_BEGIN_SELECT:
555 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
556 needsUpdate |= cursorHome(cur);
560 case LFUN_LINE_END_SELECT:
561 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
562 needsUpdate |= cursorEnd(cur);
565 case LFUN_WORD_FORWARD:
566 case LFUN_WORD_FORWARD_SELECT:
567 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
568 if (reverseDirectionNeeded(cur))
569 needsUpdate |= cursorLeftOneWord(cur);
571 needsUpdate |= cursorRightOneWord(cur);
574 case LFUN_WORD_BACKWARD:
575 case LFUN_WORD_BACKWARD_SELECT:
576 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
577 if (reverseDirectionNeeded(cur))
578 needsUpdate |= cursorRightOneWord(cur);
580 needsUpdate |= cursorLeftOneWord(cur);
583 case LFUN_WORD_SELECT: {
584 selectWord(cur, WHOLE_WORD);
585 finishChange(cur, true);
589 case LFUN_BREAK_LINE: {
590 // Not allowed by LaTeX (labels or empty par)
591 if (cur.pos() > cur.paragraph().beginOfBody()) {
592 // this avoids a double undo
593 // FIXME: should not be needed, ideally
594 if (!cur.selection())
596 cap::replaceSelection(cur);
597 cur.insert(new InsetNewline);
599 moveCursor(cur, false);
604 case LFUN_CHAR_DELETE_FORWARD:
605 if (!cur.selection()) {
606 if (cur.pos() == cur.paragraph().size())
607 // Par boundary, force full-screen update
608 singleParUpdate = false;
609 needsUpdate |= erase(cur);
611 // It is possible to make it a lot faster still
612 // just comment out the line below...
614 cutSelection(cur, true, false);
615 singleParUpdate = false;
617 moveCursor(cur, false);
620 case LFUN_DELETE_FORWARD_SKIP:
621 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
622 if (!cur.selection()) {
623 if (cur.pos() == cur.lastpos()) {
630 cutSelection(cur, true, false);
635 case LFUN_CHAR_DELETE_BACKWARD:
636 if (!cur.selection()) {
637 if (bv->getIntl().getTransManager().backspace()) {
638 // Par boundary, full-screen update
640 singleParUpdate = false;
641 needsUpdate |= backspace(cur);
643 // It is possible to make it a lot faster still
644 // just comment out the line below...
647 cutSelection(cur, true, false);
648 singleParUpdate = false;
652 case LFUN_DELETE_BACKWARD_SKIP:
653 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
654 if (!cur.selection()) {
658 //CursorSlice cur = cursor();
662 cutSelection(cur, true, false);
666 case LFUN_BREAK_PARAGRAPH:
667 cap::replaceSelection(cur);
668 breakParagraph(cur, 0);
672 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
673 cap::replaceSelection(cur);
674 breakParagraph(cur, 1);
678 case LFUN_BREAK_PARAGRAPH_SKIP: {
679 // When at the beginning of a paragraph, remove
680 // indentation. Otherwise, do the same as LFUN_BREAK_PARAGRAPH.
681 cap::replaceSelection(cur);
683 cur.paragraph().params().labelWidthString(docstring());
685 breakParagraph(cur, 0);
690 case LFUN_PARAGRAPH_SPACING: {
691 Paragraph & par = cur.paragraph();
692 Spacing::Space cur_spacing = par.params().spacing().getSpace();
693 string cur_value = "1.0";
694 if (cur_spacing == Spacing::Other)
695 cur_value = par.params().spacing().getValueAsString();
697 istringstream is(to_utf8(cmd.argument()));
700 Spacing::Space new_spacing = cur_spacing;
701 string new_value = cur_value;
703 lyxerr << "Missing argument to `paragraph-spacing'"
705 } else if (tmp == "single") {
706 new_spacing = Spacing::Single;
707 } else if (tmp == "onehalf") {
708 new_spacing = Spacing::Onehalf;
709 } else if (tmp == "double") {
710 new_spacing = Spacing::Double;
711 } else if (tmp == "other") {
712 new_spacing = Spacing::Other;
713 string tmpval = "0.0";
715 lyxerr << "new_value = " << tmpval << endl;
718 } else if (tmp == "default") {
719 new_spacing = Spacing::Default;
721 lyxerr << to_utf8(_("Unknown spacing argument: "))
722 << to_utf8(cmd.argument()) << endl;
724 if (cur_spacing != new_spacing || cur_value != new_value)
725 par.params().spacing(Spacing(new_spacing, new_value));
729 case LFUN_INSET_INSERT: {
731 Inset * inset = createInset(bv, cmd);
733 // FIXME (Abdel 01/02/2006):
734 // What follows would be a partial fix for bug 2154:
735 // http://bugzilla.lyx.org/show_bug.cgi?id=2154
736 // This automatically put the label inset _after_ a
737 // numbered section. It should be possible to extend the mechanism
738 // to any kind of LateX environement.
739 // The correct way to fix that bug would be at LateX generation.
740 // I'll let the code here for reference as it could be used for some
741 // other feature like "automatic labelling".
743 Paragraph & par = pars_[cur.pit()];
744 if (inset->lyxCode() == Inset::LABEL_CODE
745 && par.layout()->labeltype == LABEL_COUNTER) {
746 // Go to the end of the paragraph
747 // Warning: Because of Change-Tracking, the last
748 // position is 'size()' and not 'size()-1':
749 cur.pos() = par.size();
750 // Insert a new paragraph
751 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
755 insertInset(cur, inset);
761 case LFUN_INSET_DISSOLVE:
762 needsUpdate |= dissolveInset(cur);
765 case LFUN_INSET_SETTINGS:
766 cur.inset().showInsetDialog(bv);
769 case LFUN_SPACE_INSERT:
770 if (cur.paragraph().layout()->free_spacing)
771 insertChar(cur, ' ');
773 doInsertInset(cur, this, cmd, false, false);
776 moveCursor(cur, false);
779 case LFUN_HYPHENATION_POINT_INSERT:
780 specialChar(cur, InsetSpecialChar::HYPHENATION);
783 case LFUN_LIGATURE_BREAK_INSERT:
784 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
787 case LFUN_DOTS_INSERT:
788 specialChar(cur, InsetSpecialChar::LDOTS);
791 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
792 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
795 case LFUN_MENU_SEPARATOR_INSERT:
796 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
799 case LFUN_WORD_UPCASE:
800 changeCase(cur, Text::text_uppercase);
803 case LFUN_WORD_LOWCASE:
804 changeCase(cur, Text::text_lowercase);
807 case LFUN_WORD_CAPITALIZE:
808 changeCase(cur, Text::text_capitalization);
811 case LFUN_CHARS_TRANSPOSE:
816 cur.message(_("Paste"));
817 cap::replaceSelection(cur);
818 if (cmd.argument().empty() && !theClipboard().isInternal())
819 pasteClipboard(cur, bv->buffer()->errorList("Paste"));
821 string const arg(to_utf8(cmd.argument()));
822 pasteFromStack(cur, bv->buffer()->errorList("Paste"),
823 isStrUnsignedInt(arg) ?
824 convert<unsigned int>(arg) :
827 bv->buffer()->errors("Paste");
828 cur.clearSelection(); // bug 393
833 cutSelection(cur, true, true);
834 cur.message(_("Cut"));
839 cur.message(_("Copy"));
842 case LFUN_SERVER_GET_XY:
843 cur.message(from_utf8(
844 convert<string>(cursorX(cur.bv(), cur.top(), cur.boundary()))
845 + ' ' + convert<string>(cursorY(cur.bv(), cur.top(), cur.boundary()))));
848 case LFUN_SERVER_SET_XY: {
851 istringstream is(to_utf8(cmd.argument()));
854 lyxerr << "SETXY: Could not parse coordinates in '"
855 << to_utf8(cmd.argument()) << std::endl;
857 setCursorFromCoordinates(cur, x, y);
861 case LFUN_SERVER_GET_FONT:
862 if (current_font.shape() == Font::ITALIC_SHAPE)
863 cur.message(from_ascii("E"));
864 else if (current_font.shape() == Font::SMALLCAPS_SHAPE)
865 cur.message(from_ascii("N"));
867 cur.message(from_ascii("0"));
870 case LFUN_SERVER_GET_LAYOUT:
871 cur.message(from_utf8(cur.paragraph().layout()->name()));
875 string layout = to_ascii(cmd.argument());
876 LYXERR(Debug::INFO) << "LFUN_LAYOUT: (arg) " << layout << endl;
878 // Derive layout number from given argument (string)
879 // and current buffer's textclass (number)
880 TextClass const & tclass = bv->buffer()->params().getTextClass();
882 layout = tclass.defaultLayoutName();
883 bool hasLayout = tclass.hasLayout(layout);
885 // If the entry is obsolete, use the new one instead.
887 string const & obs = tclass[layout]->obsoleted_by();
893 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
894 from_utf8(N_(" not known")));
898 bool change_layout = (current_layout != layout);
900 if (!change_layout && cur.selection() &&
901 cur.selBegin().pit() != cur.selEnd().pit())
903 pit_type spit = cur.selBegin().pit();
904 pit_type epit = cur.selEnd().pit() + 1;
905 while (spit != epit) {
906 if (pars_[spit].layout()->name() != current_layout) {
907 change_layout = true;
915 setLayout(cur, layout);
916 // inform the GUI that the layout has changed.
917 bv->layoutChanged(layout);
922 case LFUN_CLIPBOARD_PASTE:
923 cur.clearSelection();
924 pasteClipboard(cur, bv->buffer()->errorList("Paste"),
925 cmd.argument() == "paragraph");
926 bv->buffer()->errors("Paste");
929 case LFUN_PRIMARY_SELECTION_PASTE:
930 pasteString(cur, theSelection().get(),
931 cmd.argument() == "paragraph");
934 case LFUN_UNICODE_INSERT: {
935 if (cmd.argument().empty())
937 docstring hexstring = cmd.argument();
938 if (lyx::support::isHex(hexstring)) {
939 char_type c = lyx::support::hexToInt(hexstring);
940 if (c >= 32 && c < 0x10ffff) {
941 lyxerr << "Inserting c: " << c << endl;
942 docstring s = docstring(1, c);
943 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
949 case LFUN_QUOTE_INSERT: {
950 Paragraph & par = cur.paragraph();
951 pos_type pos = cur.pos();
952 BufferParams const & bufparams = bv->buffer()->params();
953 Layout_ptr const & style = par.layout();
954 if (!style->pass_thru
955 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
956 // this avoids a double undo
957 // FIXME: should not be needed, ideally
958 if (!cur.selection())
960 cap::replaceSelection(cur);
965 else if (cur.prevInset() && cur.prevInset()->isSpace())
968 c = par.getChar(pos - 1);
969 string arg = to_utf8(cmd.argument());
971 cur.insert(new InsetQuotes(c,
972 bufparams.quotes_language,
973 InsetQuotes::SingleQ));
975 cur.insert(new InsetQuotes(c,
976 bufparams.quotes_language,
977 InsetQuotes::DoubleQ));
981 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
985 case LFUN_DATE_INSERT:
986 if (cmd.argument().empty())
987 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
988 formatted_time(current_time())));
990 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
991 formatted_time(current_time(), to_utf8(cmd.argument()))));
994 case LFUN_MOUSE_TRIPLE:
995 if (cmd.button() == mouse_button::button1) {
1004 case LFUN_MOUSE_DOUBLE:
1005 if (cmd.button() == mouse_button::button1) {
1006 selectWord(cur, WHOLE_WORD_STRICT);
1011 // Single-click on work area
1012 case LFUN_MOUSE_PRESS: {
1013 // Right click on a footnote flag opens float menu
1014 if (cmd.button() == mouse_button::button3)
1015 cur.clearSelection();
1017 // Middle button press pastes if we have a selection
1018 // We do this here as if the selection was inside an inset
1019 // it could get cleared on the unlocking of the inset so
1020 // we have to check this first
1021 bool paste_internally = false;
1022 if (cmd.button() == mouse_button::button2 && cap::selection()) {
1023 // Copy the selection buffer to the clipboard
1024 // stack, because we want it to appear in the
1025 // "Edit->Paste recent" menu.
1026 cap::copySelectionToStack();
1027 paste_internally = true;
1030 // Insert primary selection with middle mouse
1031 // if there is a local selection in the current buffer,
1033 if (cmd.button() == mouse_button::button2) {
1034 if (paste_internally) {
1035 cap::pasteSelection(cur, bv->buffer()->errorList("Paste"));
1036 bv->buffer()->errors("Paste");
1037 cur.clearSelection(); // bug 393
1038 bv->buffer()->markDirty();
1041 bv->mouseSetCursor(cur);
1042 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
1046 // we have to update after dePM triggered
1047 bool update = bv->mouseSetCursor(cur);
1049 if (!update && cmd.button() == mouse_button::button1) {
1050 needsUpdate = false;
1057 case LFUN_MOUSE_MOTION: {
1058 // Only use motion with button 1
1059 //if (cmd.button() != mouse_button::button1)
1062 // ignore motions deeper nested than the real anchor
1063 Cursor & bvcur = cur.bv().cursor();
1064 if (bvcur.anchor_.hasPart(cur)) {
1065 CursorSlice old = bvcur.top();
1067 int const wh = bv->workHeight();
1068 int const y = std::max(0, std::min(wh - 1, cmd.y));
1070 setCursorFromCoordinates(cur, cmd.x, y);
1071 cur.setTargetX(cmd.x);
1073 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1075 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1076 // This is to allow jumping over large insets
1077 if (cur.top() == old) {
1079 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1081 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1084 if (cur.top() == old)
1087 // don't set anchor_
1088 bvcur.setCursor(cur);
1089 bvcur.selection() = true;
1090 //lyxerr << "MOTION: " << bv->cursor() << endl;
1098 case LFUN_MOUSE_RELEASE: {
1099 if (cmd.button() == mouse_button::button2)
1102 if (cmd.button() == mouse_button::button1) {
1103 // if there is new selection, update persistent
1104 // selection, otherwise, single click does not
1105 // clear persistent selection buffer
1106 if (cur.selection()) {
1108 // if double click, cur is moved to the end of word by selectWord
1109 // but bvcur is current mouse position
1110 Cursor & bvcur = cur.bv().cursor();
1111 bvcur.selection() = true;
1113 needsUpdate = false;
1120 case LFUN_SELF_INSERT: {
1121 if (cmd.argument().empty())
1124 // Automatically delete the currently selected
1125 // text and replace it with what is being
1126 // typed in now. Depends on lyxrc settings
1127 // "auto_region_delete", which defaults to
1130 if (lyxrc.auto_region_delete && cur.selection()) {
1131 cutSelection(cur, false, false);
1132 // When change tracking is set to off, the metrics update
1133 // mechanism correctly detects if a full update is needed or not.
1134 // This detection fails when a selection spans multiple rows and
1135 // change tracking is enabled because the paragraph metrics stays
1136 // the same. In this case, we force the full update:
1137 // (see http://bugzilla.lyx.org/show_bug.cgi?id=3992)
1138 if (cur.buffer().params().trackChanges)
1139 cur.updateFlags(Update::Force);
1142 cur.clearSelection();
1143 Font const old_font = real_current_font;
1145 docstring::const_iterator cit = cmd.argument().begin();
1146 docstring::const_iterator end = cmd.argument().end();
1147 for (; cit != end; ++cit)
1148 bv->translateAndInsert(*cit, this, cur);
1151 moveCursor(cur, false);
1155 case LFUN_URL_INSERT: {
1156 InsetCommandParams p("url");
1157 string const data = InsetCommandMailer::params2string("url", p);
1158 bv->showInsetDialog("url", data, 0);
1162 case LFUN_HTML_INSERT: {
1163 InsetCommandParams p("htmlurl");
1164 string const data = InsetCommandMailer::params2string("url", p);
1165 bv->showInsetDialog("url", data, 0);
1169 case LFUN_LABEL_INSERT: {
1170 InsetCommandParams p("label");
1171 // Try to generate a valid label
1172 p["name"] = (cmd.argument().empty()) ?
1173 cur.getPossibleLabel() :
1175 string const data = InsetCommandMailer::params2string("label", p);
1177 if (cmd.argument().empty()) {
1178 bv->showInsetDialog("label", data, 0);
1180 FuncRequest fr(LFUN_INSET_INSERT, data);
1188 case LFUN_LIST_INSERT:
1189 case LFUN_THEOREM_INSERT:
1191 case LFUN_CAPTION_INSERT:
1192 // Open the inset, and move the current selection
1194 doInsertInset(cur, this, cmd, true, true);
1196 updateLabels(*bv->buffer());
1198 case LFUN_NOTE_INSERT:
1199 case LFUN_CHARSTYLE_INSERT:
1200 case LFUN_BOX_INSERT:
1201 case LFUN_BRANCH_INSERT:
1202 case LFUN_BIBITEM_INSERT:
1203 case LFUN_ERT_INSERT:
1204 case LFUN_LISTING_INSERT:
1205 case LFUN_FOOTNOTE_INSERT:
1206 case LFUN_MARGINALNOTE_INSERT:
1207 case LFUN_OPTIONAL_INSERT:
1208 case LFUN_ENVIRONMENT_INSERT:
1209 // Open the inset, and move the current selection
1211 doInsertInset(cur, this, cmd, true, true);
1215 case LFUN_TABULAR_INSERT:
1216 // if there were no arguments, just open the dialog
1217 if (doInsertInset(cur, this, cmd, false, true))
1220 bv->showDialog("tabularcreate");
1224 case LFUN_FLOAT_INSERT:
1225 case LFUN_FLOAT_WIDE_INSERT:
1226 case LFUN_WRAP_INSERT: {
1227 bool content = cur.selection(); // will some text be moved into the inset?
1229 doInsertInset(cur, this, cmd, true, true);
1231 ParagraphList & pars = cur.text()->paragraphs();
1233 TextClass const & tclass = bv->buffer()->params().getTextClass();
1235 // add a separate paragraph for the caption inset
1236 pars.push_back(Paragraph());
1237 pars.back().setInsetOwner(pars[0].inInset());
1238 pars.back().layout(tclass.defaultLayout());
1240 int cap_pit = pars.size() - 1;
1242 // if an empty inset was created, we create an additional empty
1243 // paragraph at the bottom so that the user can choose where to put
1244 // the graphics (or table).
1246 pars.push_back(Paragraph());
1247 pars.back().setInsetOwner(pars[0].inInset());
1248 pars.back().layout(tclass.defaultLayout());
1252 // reposition the cursor to the caption
1253 cur.pit() = cap_pit;
1255 cur.dispatch(FuncRequest(LFUN_CAPTION_INSERT));
1256 // FIXME: When leaving the Float (or Wrap) inset we should
1257 // delete any empty paragraph left above or below the
1262 case LFUN_INDEX_INSERT:
1263 case LFUN_NOMENCL_INSERT: {
1264 Inset * inset = createInset(&cur.bv(), cmd);
1268 cur.clearSelection();
1269 insertInset(cur, inset);
1270 inset->edit(cur, true);
1271 // Show the dialog for the nomenclature entry, since the
1272 // description entry still needs to be filled in.
1273 if (cmd.action == LFUN_NOMENCL_INSERT)
1274 InsetCommandMailer("nomenclature",
1275 *reinterpret_cast<InsetCommand *>(inset)).showDialog(&cur.bv());
1280 case LFUN_INDEX_PRINT:
1281 case LFUN_NOMENCL_PRINT:
1282 case LFUN_TOC_INSERT:
1283 case LFUN_HFILL_INSERT:
1284 case LFUN_LINE_INSERT:
1285 case LFUN_PAGEBREAK_INSERT:
1286 case LFUN_CLEARPAGE_INSERT:
1287 case LFUN_CLEARDOUBLEPAGE_INSERT:
1289 doInsertInset(cur, this, cmd, false, false);
1293 case LFUN_DEPTH_DECREMENT:
1294 changeDepth(cur, DEC_DEPTH);
1297 case LFUN_DEPTH_INCREMENT:
1298 changeDepth(cur, INC_DEPTH);
1301 case LFUN_MATH_DISPLAY:
1302 mathDispatch(cur, cmd, true);
1305 case LFUN_MATH_IMPORT_SELECTION:
1306 case LFUN_MATH_MODE:
1307 if (cmd.argument() == "on")
1308 // don't pass "on" as argument
1309 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1311 mathDispatch(cur, cmd, false);
1314 case LFUN_MATH_MACRO:
1315 if (cmd.argument().empty())
1316 cur.errorMessage(from_utf8(N_("Missing argument")));
1318 string s = to_utf8(cmd.argument());
1319 string const s1 = token(s, ' ', 1);
1320 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1321 string const s2 = token(s, ' ', 2);
1322 string const type = s2.empty() ? "newcommand" : s2;
1323 cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, from_utf8(type)));
1324 //cur.nextInset()->edit(cur, true);
1328 // passthrough hat and underscore outside mathed:
1329 case LFUN_MATH_SUBSCRIPT:
1330 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1332 case LFUN_MATH_SUPERSCRIPT:
1333 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1336 case LFUN_MATH_INSERT:
1337 case LFUN_MATH_MATRIX:
1338 case LFUN_MATH_DELIM:
1339 case LFUN_MATH_BIGDELIM: {
1340 cur.insert(new InsetMathHull(hullSimple));
1341 checkAndActivateInset(cur, true);
1342 BOOST_ASSERT(cur.inMathed());
1347 case LFUN_FONT_EMPH: {
1348 Font font(Font::ALL_IGNORE);
1349 font.setEmph(Font::TOGGLE);
1350 toggleAndShow(cur, this, font);
1354 case LFUN_FONT_BOLD: {
1355 Font font(Font::ALL_IGNORE);
1356 font.setSeries(Font::BOLD_SERIES);
1357 toggleAndShow(cur, this, font);
1361 case LFUN_FONT_NOUN: {
1362 Font font(Font::ALL_IGNORE);
1363 font.setNoun(Font::TOGGLE);
1364 toggleAndShow(cur, this, font);
1368 case LFUN_FONT_CODE: {
1369 Font font(Font::ALL_IGNORE);
1370 font.setFamily(Font::TYPEWRITER_FAMILY); // no good
1371 toggleAndShow(cur, this, font);
1375 case LFUN_FONT_SANS: {
1376 Font font(Font::ALL_IGNORE);
1377 font.setFamily(Font::SANS_FAMILY);
1378 toggleAndShow(cur, this, font);
1382 case LFUN_FONT_ROMAN: {
1383 Font font(Font::ALL_IGNORE);
1384 font.setFamily(Font::ROMAN_FAMILY);
1385 toggleAndShow(cur, this, font);
1389 case LFUN_FONT_DEFAULT: {
1390 Font font(Font::ALL_INHERIT, ignore_language);
1391 toggleAndShow(cur, this, font);
1395 case LFUN_FONT_UNDERLINE: {
1396 Font font(Font::ALL_IGNORE);
1397 font.setUnderbar(Font::TOGGLE);
1398 toggleAndShow(cur, this, font);
1402 case LFUN_FONT_SIZE: {
1403 Font font(Font::ALL_IGNORE);
1404 font.setLyXSize(to_utf8(cmd.argument()));
1405 toggleAndShow(cur, this, font);
1409 case LFUN_LANGUAGE: {
1410 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1413 Font font(Font::ALL_IGNORE);
1414 font.setLanguage(lang);
1415 toggleAndShow(cur, this, font);
1419 case LFUN_FONT_FREE_APPLY:
1420 toggleAndShow(cur, this, freefont, toggleall);
1421 cur.message(_("Character set"));
1424 // Set the freefont using the contents of \param data dispatched from
1425 // the frontends and apply it at the current cursor location.
1426 case LFUN_FONT_FREE_UPDATE: {
1429 if (bv_funcs::string2font(to_utf8(cmd.argument()), font, toggle)) {
1432 toggleAndShow(cur, this, freefont, toggleall);
1433 cur.message(_("Character set"));
1438 case LFUN_FINISHED_LEFT:
1439 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1440 if (reverseDirectionNeeded(cur))
1444 case LFUN_FINISHED_RIGHT:
1445 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1446 if (!reverseDirectionNeeded(cur))
1450 case LFUN_LAYOUT_PARAGRAPH: {
1452 params2string(cur.paragraph(), data);
1453 data = "show\n" + data;
1454 bv->showDialogWithData("paragraph", data);
1458 case LFUN_PARAGRAPH_UPDATE: {
1460 params2string(cur.paragraph(), data);
1462 // Will the paragraph accept changes from the dialog?
1463 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1465 data = "update " + convert<string>(accept) + '\n' + data;
1466 bv->updateDialog("paragraph", data);
1470 case LFUN_ACCENT_UMLAUT:
1471 case LFUN_ACCENT_CIRCUMFLEX:
1472 case LFUN_ACCENT_GRAVE:
1473 case LFUN_ACCENT_ACUTE:
1474 case LFUN_ACCENT_TILDE:
1475 case LFUN_ACCENT_CEDILLA:
1476 case LFUN_ACCENT_MACRON:
1477 case LFUN_ACCENT_DOT:
1478 case LFUN_ACCENT_UNDERDOT:
1479 case LFUN_ACCENT_UNDERBAR:
1480 case LFUN_ACCENT_CARON:
1481 case LFUN_ACCENT_SPECIAL_CARON:
1482 case LFUN_ACCENT_BREVE:
1483 case LFUN_ACCENT_TIE:
1484 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1485 case LFUN_ACCENT_CIRCLE:
1486 case LFUN_ACCENT_OGONEK:
1487 theLyXFunc().handleKeyFunc(cmd.action);
1488 if (!cmd.argument().empty())
1489 // FIXME: Are all these characters encoded in one byte in utf8?
1490 bv->translateAndInsert(cmd.argument()[0], this, cur);
1493 case LFUN_FLOAT_LIST: {
1494 TextClass const & tclass = bv->buffer()->params().getTextClass();
1495 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1496 // not quite sure if we want this...
1498 cur.clearSelection();
1499 breakParagraph(cur);
1501 if (cur.lastpos() != 0) {
1503 breakParagraph(cur);
1506 setLayout(cur, tclass.defaultLayoutName());
1507 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, docstring(), 0);
1508 insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1511 lyxerr << "Non-existent float type: "
1512 << to_utf8(cmd.argument()) << endl;
1517 case LFUN_CHANGE_ACCEPT: {
1518 acceptOrRejectChanges(cur, ACCEPT);
1522 case LFUN_CHANGE_REJECT: {
1523 acceptOrRejectChanges(cur, REJECT);
1527 case LFUN_THESAURUS_ENTRY: {
1528 docstring arg = cmd.argument();
1530 arg = cur.selectionAsString(false);
1532 if (arg.size() > 100 || arg.empty()) {
1533 // Get word or selection
1534 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1535 arg = cur.selectionAsString(false);
1538 bv->showDialogWithData("thesaurus", to_utf8(arg));
1542 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1543 // Given data, an encoding of the ParagraphParameters
1544 // generated in the Paragraph dialog, this function sets
1545 // the current paragraph appropriately.
1546 istringstream is(to_utf8(cmd.argument()));
1549 ParagraphParameters params;
1554 params.labelWidthString(),
1556 cur.message(_("Paragraph layout set"));
1561 if (cur.selection()) {
1562 cur.selection() = false;
1565 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1570 LYXERR(Debug::ACTION)
1571 << BOOST_CURRENT_FUNCTION
1572 << ": Command " << cmd
1573 << " not DISPATCHED by Text" << endl;
1578 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1580 // FIXME: The cursor flag is reset two lines below
1581 // so we need to check here if some of the LFUN did touch that.
1582 // for now only Text::erase() and Text::backspace() do that.
1583 // The plan is to verify all the LFUNs and then to remove this
1584 // singleParUpdate boolean altogether.
1585 if (cur.result().update() & Update::Force) {
1586 singleParUpdate = false;
1590 // FIXME: the following code should go in favor of fine grained
1591 // update flag treatment.
1592 if (singleParUpdate) {
1593 // Inserting characters does not change par height
1594 ParagraphMetrics const & pms
1595 = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
1596 if (pms.dim().height()
1597 == olddim.height()) {
1598 // if so, update _only_ this paragraph
1599 cur.updateFlags(Update::SinglePar |
1601 Update::MultiParSel);
1608 && &oldTopSlice.inset() == &cur.inset()
1609 && oldTopSlice.idx() == cur.idx()
1610 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1611 && !cur.selection())
1612 // FIXME: it would be better if we could just do this
1614 //if (cur.result().update() != Update::FitCursor)
1617 // But some LFUNs do not set Update::FitCursor when needed, so we
1618 // do it for all. This is not very harmfull as FitCursor will provoke
1619 // a full redraw only if needed but still, a proper review of all LFUN
1620 // should be done and this needsUpdate boolean can then be removed.
1621 cur.updateFlags(Update::FitCursor);
1623 cur.updateFlags(Update::Force | Update::FitCursor);
1627 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
1628 FuncStatus & flag) const
1630 BOOST_ASSERT(cur.text() == this);
1632 Font const & font = real_current_font;
1634 Inset::Code code = Inset::NO_CODE;
1636 switch (cmd.action) {
1638 case LFUN_DEPTH_DECREMENT:
1639 enable = changeDepthAllowed(cur, DEC_DEPTH);
1642 case LFUN_DEPTH_INCREMENT:
1643 enable = changeDepthAllowed(cur, INC_DEPTH);
1647 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1650 case LFUN_BIBITEM_INSERT:
1651 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO
1655 case LFUN_DIALOG_SHOW_NEW_INSET:
1656 if (cmd.argument() == "bibitem")
1657 code = Inset::BIBITEM_CODE;
1658 else if (cmd.argument() == "bibtex")
1659 code = Inset::BIBTEX_CODE;
1660 else if (cmd.argument() == "box")
1661 code = Inset::BOX_CODE;
1662 else if (cmd.argument() == "branch")
1663 code = Inset::BRANCH_CODE;
1664 else if (cmd.argument() == "citation")
1665 code = Inset::CITE_CODE;
1666 else if (cmd.argument() == "ert")
1667 code = Inset::ERT_CODE;
1668 else if (cmd.argument() == "external")
1669 code = Inset::EXTERNAL_CODE;
1670 else if (cmd.argument() == "float")
1671 code = Inset::FLOAT_CODE;
1672 else if (cmd.argument() == "graphics")
1673 code = Inset::GRAPHICS_CODE;
1674 else if (cmd.argument() == "include")
1675 code = Inset::INCLUDE_CODE;
1676 else if (cmd.argument() == "index")
1677 code = Inset::INDEX_CODE;
1678 else if (cmd.argument() == "nomenclature")
1679 code = Inset::NOMENCL_CODE;
1680 else if (cmd.argument() == "label")
1681 code = Inset::LABEL_CODE;
1682 else if (cmd.argument() == "note")
1683 code = Inset::NOTE_CODE;
1684 else if (cmd.argument() == "ref")
1685 code = Inset::REF_CODE;
1686 else if (cmd.argument() == "toc")
1687 code = Inset::TOC_CODE;
1688 else if (cmd.argument() == "url")
1689 code = Inset::URL_CODE;
1690 else if (cmd.argument() == "vspace")
1691 code = Inset::VSPACE_CODE;
1692 else if (cmd.argument() == "wrap")
1693 code = Inset::WRAP_CODE;
1694 else if (cmd.argument() == "listings")
1695 code = Inset::LISTINGS_CODE;
1698 case LFUN_ERT_INSERT:
1699 code = Inset::ERT_CODE;
1701 case LFUN_LISTING_INSERT:
1702 code = Inset::LISTINGS_CODE;
1704 case LFUN_FOOTNOTE_INSERT:
1705 code = Inset::FOOT_CODE;
1707 case LFUN_TABULAR_INSERT:
1708 code = Inset::TABULAR_CODE;
1710 case LFUN_MARGINALNOTE_INSERT:
1711 code = Inset::MARGIN_CODE;
1713 case LFUN_FLOAT_INSERT:
1714 case LFUN_FLOAT_WIDE_INSERT:
1715 code = Inset::FLOAT_CODE;
1717 case LFUN_WRAP_INSERT:
1718 code = Inset::WRAP_CODE;
1720 case LFUN_FLOAT_LIST:
1721 code = Inset::FLOAT_LIST_CODE;
1724 case LFUN_LIST_INSERT:
1725 code = Inset::LIST_CODE;
1727 case LFUN_THEOREM_INSERT:
1728 code = Inset::THEOREM_CODE;
1731 case LFUN_CAPTION_INSERT:
1732 code = Inset::CAPTION_CODE;
1734 case LFUN_NOTE_INSERT:
1735 code = Inset::NOTE_CODE;
1737 case LFUN_CHARSTYLE_INSERT:
1738 code = Inset::CHARSTYLE_CODE;
1739 if (cur.buffer().params().getTextClass().charstyles().empty())
1742 case LFUN_BOX_INSERT:
1743 code = Inset::BOX_CODE;
1745 case LFUN_BRANCH_INSERT:
1746 code = Inset::BRANCH_CODE;
1747 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1750 case LFUN_LABEL_INSERT:
1751 code = Inset::LABEL_CODE;
1753 case LFUN_OPTIONAL_INSERT:
1754 code = Inset::OPTARG_CODE;
1755 enable = numberOfOptArgs(cur.paragraph())
1756 < cur.paragraph().layout()->optionalargs;
1758 case LFUN_ENVIRONMENT_INSERT:
1759 code = Inset::BOX_CODE;
1761 case LFUN_INDEX_INSERT:
1762 code = Inset::INDEX_CODE;
1764 case LFUN_INDEX_PRINT:
1765 code = Inset::INDEX_PRINT_CODE;
1767 case LFUN_NOMENCL_INSERT:
1768 code = Inset::NOMENCL_CODE;
1770 case LFUN_NOMENCL_PRINT:
1771 code = Inset::NOMENCL_PRINT_CODE;
1773 case LFUN_TOC_INSERT:
1774 code = Inset::TOC_CODE;
1776 case LFUN_HTML_INSERT:
1777 case LFUN_URL_INSERT:
1778 code = Inset::URL_CODE;
1780 case LFUN_QUOTE_INSERT:
1781 // always allow this, since we will inset a raw quote
1782 // if an inset is not allowed.
1784 case LFUN_HYPHENATION_POINT_INSERT:
1785 case LFUN_LIGATURE_BREAK_INSERT:
1786 case LFUN_HFILL_INSERT:
1787 case LFUN_MENU_SEPARATOR_INSERT:
1788 case LFUN_DOTS_INSERT:
1789 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
1790 code = Inset::SPECIALCHAR_CODE;
1792 case LFUN_SPACE_INSERT:
1793 // slight hack: we know this is allowed in math mode
1795 code = Inset::SPACE_CODE;
1798 case LFUN_INSET_MODIFY:
1799 // We need to disable this, because we may get called for a
1801 // InsetTabular::getStatus() -> InsetText::getStatus()
1802 // and we don't handle LFUN_INSET_MODIFY.
1806 case LFUN_FONT_EMPH:
1807 flag.setOnOff(font.emph() == Font::ON);
1810 case LFUN_FONT_NOUN:
1811 flag.setOnOff(font.noun() == Font::ON);
1814 case LFUN_FONT_BOLD:
1815 flag.setOnOff(font.series() == Font::BOLD_SERIES);
1818 case LFUN_FONT_SANS:
1819 flag.setOnOff(font.family() == Font::SANS_FAMILY);
1822 case LFUN_FONT_ROMAN:
1823 flag.setOnOff(font.family() == Font::ROMAN_FAMILY);
1826 case LFUN_FONT_CODE:
1827 flag.setOnOff(font.family() == Font::TYPEWRITER_FAMILY);
1832 enable = cur.selection();
1836 if (cmd.argument().empty()) {
1837 if (theClipboard().isInternal())
1838 enable = cap::numberOfSelections() > 0;
1840 enable = !theClipboard().empty();
1842 string const arg = to_utf8(cmd.argument());
1843 if (isStrUnsignedInt(arg)) {
1844 unsigned int n = convert<unsigned int>(arg);
1845 enable = cap::numberOfSelections() > n;
1852 case LFUN_CLIPBOARD_PASTE:
1853 enable = !theClipboard().empty();
1856 case LFUN_PRIMARY_SELECTION_PASTE:
1857 enable = cur.selection() || !theSelection().empty();
1860 case LFUN_PARAGRAPH_MOVE_UP:
1861 enable = cur.pit() > 0 && !cur.selection();
1864 case LFUN_PARAGRAPH_MOVE_DOWN:
1865 enable = cur.pit() < cur.lastpit() && !cur.selection();
1868 case LFUN_INSET_DISSOLVE:
1869 enable = !isMainText(*cur.bv().buffer()) && cur.inset().nargs() == 1;
1872 case LFUN_CHANGE_ACCEPT:
1873 case LFUN_CHANGE_REJECT:
1874 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
1875 // In principle, these LFUNs should only be enabled if there
1876 // is a change at the current position/in the current selection.
1877 // However, without proper optimizations, this will inevitably
1878 // result in unacceptable performance - just imagine a user who
1879 // wants to select the complete content of a long document.
1883 case LFUN_WORD_DELETE_FORWARD:
1884 case LFUN_WORD_DELETE_BACKWARD:
1885 case LFUN_LINE_DELETE:
1886 case LFUN_WORD_FORWARD:
1887 case LFUN_WORD_BACKWARD:
1888 case LFUN_CHAR_FORWARD:
1889 case LFUN_CHAR_FORWARD_SELECT:
1890 case LFUN_CHAR_BACKWARD:
1891 case LFUN_CHAR_BACKWARD_SELECT:
1893 case LFUN_UP_SELECT:
1895 case LFUN_DOWN_SELECT:
1896 case LFUN_PARAGRAPH_UP_SELECT:
1897 case LFUN_PARAGRAPH_DOWN_SELECT:
1898 case LFUN_SCREEN_UP_SELECT:
1899 case LFUN_SCREEN_DOWN_SELECT:
1900 case LFUN_LINE_BEGIN_SELECT:
1901 case LFUN_LINE_END_SELECT:
1902 case LFUN_WORD_FORWARD_SELECT:
1903 case LFUN_WORD_BACKWARD_SELECT:
1904 case LFUN_WORD_SELECT:
1905 case LFUN_PARAGRAPH_UP:
1906 case LFUN_PARAGRAPH_DOWN:
1907 case LFUN_SCREEN_UP:
1908 case LFUN_SCREEN_DOWN:
1909 case LFUN_LINE_BEGIN:
1911 case LFUN_BREAK_LINE:
1912 case LFUN_CHAR_DELETE_FORWARD:
1913 case LFUN_DELETE_FORWARD_SKIP:
1914 case LFUN_CHAR_DELETE_BACKWARD:
1915 case LFUN_DELETE_BACKWARD_SKIP:
1916 case LFUN_BREAK_PARAGRAPH:
1917 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
1918 case LFUN_BREAK_PARAGRAPH_SKIP:
1919 case LFUN_PARAGRAPH_SPACING:
1920 case LFUN_INSET_INSERT:
1921 case LFUN_WORD_UPCASE:
1922 case LFUN_WORD_LOWCASE:
1923 case LFUN_WORD_CAPITALIZE:
1924 case LFUN_CHARS_TRANSPOSE:
1925 case LFUN_SERVER_GET_XY:
1926 case LFUN_SERVER_SET_XY:
1927 case LFUN_SERVER_GET_FONT:
1928 case LFUN_SERVER_GET_LAYOUT:
1930 case LFUN_DATE_INSERT:
1931 case LFUN_SELF_INSERT:
1932 case LFUN_LINE_INSERT:
1933 case LFUN_PAGEBREAK_INSERT:
1934 case LFUN_CLEARPAGE_INSERT:
1935 case LFUN_CLEARDOUBLEPAGE_INSERT:
1936 case LFUN_MATH_DISPLAY:
1937 case LFUN_MATH_IMPORT_SELECTION:
1938 case LFUN_MATH_MODE:
1939 case LFUN_MATH_MACRO:
1940 case LFUN_MATH_MATRIX:
1941 case LFUN_MATH_DELIM:
1942 case LFUN_MATH_BIGDELIM:
1943 case LFUN_MATH_INSERT:
1944 case LFUN_MATH_SUBSCRIPT:
1945 case LFUN_MATH_SUPERSCRIPT:
1946 case LFUN_FONT_DEFAULT:
1947 case LFUN_FONT_UNDERLINE:
1948 case LFUN_FONT_SIZE:
1950 case LFUN_FONT_FREE_APPLY:
1951 case LFUN_FONT_FREE_UPDATE:
1952 case LFUN_LAYOUT_PARAGRAPH:
1953 case LFUN_PARAGRAPH_UPDATE:
1954 case LFUN_ACCENT_UMLAUT:
1955 case LFUN_ACCENT_CIRCUMFLEX:
1956 case LFUN_ACCENT_GRAVE:
1957 case LFUN_ACCENT_ACUTE:
1958 case LFUN_ACCENT_TILDE:
1959 case LFUN_ACCENT_CEDILLA:
1960 case LFUN_ACCENT_MACRON:
1961 case LFUN_ACCENT_DOT:
1962 case LFUN_ACCENT_UNDERDOT:
1963 case LFUN_ACCENT_UNDERBAR:
1964 case LFUN_ACCENT_CARON:
1965 case LFUN_ACCENT_SPECIAL_CARON:
1966 case LFUN_ACCENT_BREVE:
1967 case LFUN_ACCENT_TIE:
1968 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1969 case LFUN_ACCENT_CIRCLE:
1970 case LFUN_ACCENT_OGONEK:
1971 case LFUN_THESAURUS_ENTRY:
1972 case LFUN_PARAGRAPH_PARAMS_APPLY:
1974 case LFUN_BUFFER_END:
1975 case LFUN_BUFFER_BEGIN:
1976 case LFUN_BUFFER_BEGIN_SELECT:
1977 case LFUN_BUFFER_END_SELECT:
1978 case LFUN_UNICODE_INSERT:
1979 // these are handled in our dispatch()
1987 if (code != Inset::NO_CODE
1988 && (cur.empty() || !cur.inset().insetAllowed(code)))
1991 flag.enabled(enable);
1996 void Text::pasteString(Cursor & cur, docstring const & clip,
1999 cur.clearSelection();
2000 if (!clip.empty()) {
2003 insertStringAsParagraphs(cur, clip);
2005 insertStringAsLines(cur, clip);