3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Asger Alstrup
7 * \author Lars Gullik Bjønnes
8 * \author Alfredo Braunstein
9 * \author Angus Leeming
11 * \author André Pönitz
13 * Full author contact details are available in file CREDITS.
20 #include "BranchList.h"
21 #include "FloatList.h"
22 #include "FuncStatus.h"
24 #include "buffer_funcs.h"
25 #include "BufferParams.h"
26 #include "BufferView.h"
27 #include "bufferview_funcs.h"
29 #include "CoordCache.h"
30 #include "CutAndPaste.h"
32 #include "DispatchResult.h"
33 #include "ErrorList.h"
35 #include "FuncRequest.h"
39 #include "LyXAction.h"
44 #include "Paragraph.h"
45 #include "paragraph_funcs.h"
46 #include "ParagraphParameters.h"
49 #include "ParIterator.h"
51 #include "frontends/Clipboard.h"
52 #include "frontends/Selection.h"
54 #include "insets/InsetCommand.h"
55 #include "insets/InsetFloatList.h"
56 #include "insets/InsetNewline.h"
57 #include "insets/InsetQuotes.h"
58 #include "insets/InsetSpecialChar.h"
59 #include "insets/InsetText.h"
61 #include "support/lstrings.h"
62 #include "support/lyxlib.h"
63 #include "support/convert.h"
64 #include "support/lyxtime.h"
66 #include "mathed/InsetMathHull.h"
67 #include "mathed/MathMacroTemplate.h"
69 #include <boost/current_function.hpp>
77 using cap::copySelection;
78 using cap::cutSelection;
79 using cap::pasteFromStack;
80 using cap::pasteClipboard;
81 using cap::replaceSelection;
82 using cap::saveSelection;
84 using support::isStrUnsignedInt;
89 using std::istringstream;
90 using std::ostringstream;
93 extern string current_layout;
99 Font freefont(Font::ALL_IGNORE);
100 bool toggleall = false;
102 void toggleAndShow(Cursor & cur, Text * text,
103 Font const & font, bool toggleall = true)
105 text->toggleFree(cur, font, toggleall);
107 if (font.language() != ignore_language ||
108 font.number() != Font::IGNORE) {
109 Paragraph & par = cur.paragraph();
110 if (cur.boundary() != text->isRTLBoundary(cur.buffer(), par,
111 cur.pos(), text->real_current_font))
112 text->setCursor(cur, cur.pit(), cur.pos(),
113 false, !cur.boundary());
118 void moveCursor(Cursor & cur, bool selecting)
120 if (selecting || cur.mark())
126 void finishChange(Cursor & cur, bool selecting)
129 moveCursor(cur, selecting);
133 void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
136 docstring sel = cur.selectionAsString(false);
138 // It may happen that sel is empty but there is a selection
139 replaceSelection(cur);
142 #ifdef ENABLE_ASSERTIONS
143 const int old_pos = cur.pos();
145 cur.insert(new InsetMathHull(hullSimple));
146 BOOST_ASSERT(old_pos == cur.pos());
147 cur.nextInset()->edit(cur, true);
148 // don't do that also for LFUN_MATH_MODE
149 // unless you want end up with always changing
150 // to mathrm when opening an inlined inset --
151 // I really hate "LyXfunc overloading"...
153 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
154 // Avoid an unnecessary undo step if cmd.argument
156 if (!cmd.argument().empty())
157 cur.dispatch(FuncRequest(LFUN_MATH_INSERT,
160 // create a macro if we see "\\newcommand"
161 // somewhere, and an ordinary formula
163 if (sel.find(from_ascii("\\newcommand")) == string::npos
164 && sel.find(from_ascii("\\def")) == string::npos)
166 InsetMathHull * formula = new InsetMathHull;
167 istringstream is(to_utf8(sel));
170 formula->read(cur.buffer(), lex);
171 if (formula->getType() == hullNone)
172 // Don't create pseudo formulas if
173 // delimiters are left out
174 formula->mutate(hullSimple);
177 cur.insert(new MathMacroTemplate(sel));
180 cur.message(from_utf8(N_("Math editor mode")));
189 string const freefont2string()
192 if (font2string(freefont, toggleall, data))
199 void Text::cursorPrevious(Cursor & cur)
201 pos_type cpos = cur.pos();
202 pit_type cpar = cur.pit();
204 int x = cur.x_target();
205 setCursorFromCoordinates(cur, x, 0);
206 cur.dispatch(FuncRequest(cur.selection()? LFUN_UP_SELECT: LFUN_UP));
208 if (cpar == cur.pit() && cpos == cur.pos())
209 // we have a row which is taller than the workarea. The
210 // simplest solution is to move to the previous row instead.
211 cur.dispatch(FuncRequest(cur.selection()? LFUN_UP_SELECT: LFUN_UP));
214 cur.updateFlags(Update::Force | Update::FitCursor);
218 void Text::cursorNext(Cursor & cur)
220 pos_type cpos = cur.pos();
221 pit_type cpar = cur.pit();
223 int x = cur.x_target();
224 setCursorFromCoordinates(cur, x, cur.bv().workHeight() - 1);
225 cur.dispatch(FuncRequest(cur.selection()? LFUN_DOWN_SELECT: LFUN_DOWN));
227 if (cpar == cur.pit() && cpos == cur.pos())
228 // we have a row which is taller than the workarea. The
229 // simplest solution is to move to the next row instead.
231 FuncRequest(cur.selection()? LFUN_DOWN_SELECT: LFUN_DOWN));
234 cur.updateFlags(Update::Force | Update::FitCursor);
240 void specialChar(Cursor & cur, InsetSpecialChar::Kind kind)
243 cap::replaceSelection(cur);
244 cur.insert(new InsetSpecialChar(kind));
249 bool doInsertInset(Cursor & cur, Text * text,
250 FuncRequest const & cmd, bool edit, bool pastesel)
252 Inset * inset = createInset(&cur.bv(), cmd);
258 if (cur.selection()) {
259 lyx::dispatch(FuncRequest(LFUN_CUT));
262 text->insertInset(cur, inset);
265 inset->edit(cur, true);
267 if (gotsel && pastesel) {
268 lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
269 // reset first par to default
270 if (cur.lastpit() != 0 || cur.lastpos() != 0) {
271 Layout_ptr const layout =
272 cur.buffer().params().getTextClass().defaultLayout();
273 cur.text()->paragraphs().begin()->layout(layout);
283 void Text::number(Cursor & cur)
285 Font font(Font::ALL_IGNORE);
286 font.setNumber(Font::TOGGLE);
287 toggleAndShow(cur, this, font);
291 bool Text::isRTL(Buffer const & buffer, Paragraph const & par) const
293 return par.isRightToLeftPar(buffer.params());
297 bool Text::isRTL(Buffer const & buffer, CursorSlice const & sl, bool boundary) const
299 if (!lyxrc.rtl_support && !sl.text())
303 if (boundary && sl.pos() > 0)
306 Paragraph const & par = getPar(sl.pit());
307 return getFont(buffer, par, sl.pos() + correction).isVisibleRightToLeft();
311 bool Text::isRTLBoundary(Buffer const & buffer, Paragraph const & par,
314 if (!lyxrc.rtl_support)
317 // no RTL boundary at line start
321 bool left = getFont(buffer, par, pos - 1).isVisibleRightToLeft();
323 if (pos == par.size())
324 right = par.isRightToLeftPar(buffer.params());
326 right = getFont(buffer, par, pos).isVisibleRightToLeft();
327 return left != right;
331 bool Text::isRTLBoundary(Buffer const & buffer, Paragraph const & par,
332 pos_type pos, Font const & font) const
334 if (!lyxrc.rtl_support)
337 bool left = font.isVisibleRightToLeft();
339 if (pos == par.size())
340 right = par.isRightToLeftPar(buffer.params());
342 right = getFont(buffer, par, pos).isVisibleRightToLeft();
343 return left != right;
347 void Text::dispatch(Cursor & cur, FuncRequest & cmd)
349 LYXERR(Debug::ACTION) << "Text::dispatch: cmd: " << cmd << endl;
351 // FIXME: We use the update flag to indicates wether a singlePar or a
352 // full screen update is needed. We reset it here but shall we restore it
356 BOOST_ASSERT(cur.text() == this);
357 BufferView * bv = &cur.bv();
358 CursorSlice oldTopSlice = cur.top();
359 bool oldBoundary = cur.boundary();
360 bool sel = cur.selection();
361 // Signals that, even if needsUpdate == false, an update of the
362 // cursor paragraph is required
363 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
364 LyXAction::SingleParUpdate);
365 // Signals that a full-screen update is required
366 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
367 LyXAction::NoUpdate) || singleParUpdate);
368 // Remember the old paragraph metric (_outer_ paragraph!)
369 ParagraphMetrics const & pm = cur.bv().parMetrics(
370 cur.bottom().text(), cur.bottom().pit());
371 Dimension olddim = pm.dim();
373 switch (cmd.action) {
375 case LFUN_PARAGRAPH_MOVE_DOWN: {
376 pit_type const pit = cur.pit();
377 recUndo(cur, pit, pit + 1);
379 std::swap(pars_[pit], pars_[pit + 1]);
381 ParIterator begin(cur);
382 // begin.pos() (== cur.pos()) may point beyond the end of the
383 // paragraph referenced by begin. This would cause a crash
387 ParIterator end = boost::next(ParIterator(cur));
388 updateLabels(cur.buffer(), begin, end);
394 case LFUN_PARAGRAPH_MOVE_UP: {
395 pit_type const pit = cur.pit();
396 recUndo(cur, pit - 1, pit);
398 std::swap(pars_[pit], pars_[pit - 1]);
400 ParIterator end = ParIterator(cur);
401 // end.pos() (== cur.pos()) may point beyond the end of the
402 // paragraph referenced by end. This would cause a crash
405 end = boost::next(end);
407 ParIterator begin(cur);
408 updateLabels(cur.buffer(), begin, end);
414 case LFUN_APPENDIX: {
415 Paragraph & par = cur.paragraph();
416 bool start = !par.params().startOfAppendix();
419 #warning The code below only makes sense at top level.
420 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
422 // ensure that we have only one start_of_appendix in this document
423 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
424 if (pars_[tmp].params().startOfAppendix()) {
426 pars_[tmp].params().startOfAppendix(false);
432 par.params().startOfAppendix(start);
434 // we can set the refreshing parameters now
435 updateLabels(cur.buffer());
439 case LFUN_WORD_DELETE_FORWARD:
440 cur.clearSelection();
441 deleteWordForward(cur);
442 finishChange(cur, false);
445 case LFUN_WORD_DELETE_BACKWARD:
446 cur.clearSelection();
447 deleteWordBackward(cur);
448 finishChange(cur, false);
451 case LFUN_LINE_DELETE:
452 cur.clearSelection();
453 deleteLineForward(cur);
454 finishChange(cur, false);
457 case LFUN_BUFFER_BEGIN:
458 case LFUN_BUFFER_BEGIN_SELECT:
459 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
460 if (cur.depth() == 1) {
461 needsUpdate |= cursorTop(cur);
467 case LFUN_BUFFER_END:
468 case LFUN_BUFFER_END_SELECT:
469 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
470 if (cur.depth() == 1) {
471 needsUpdate |= cursorBottom(cur);
477 case LFUN_CHAR_FORWARD:
478 case LFUN_CHAR_FORWARD_SELECT:
479 //lyxerr << BOOST_CURRENT_FUNCTION
480 // << " LFUN_CHAR_FORWARD[SEL]:\n" << cur << endl;
481 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
482 if (reverseDirectionNeeded(cur))
483 needsUpdate |= cursorLeft(cur);
485 needsUpdate |= cursorRight(cur);
487 if (!needsUpdate && oldTopSlice == cur.top()
488 && cur.boundary() == oldBoundary) {
490 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
491 } else if (cur.selection())
495 case LFUN_CHAR_BACKWARD:
496 case LFUN_CHAR_BACKWARD_SELECT:
497 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
498 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
499 if (reverseDirectionNeeded(cur))
500 needsUpdate |= cursorRight(cur);
502 needsUpdate |= cursorLeft(cur);
504 if (!needsUpdate && oldTopSlice == cur.top()
505 && cur.boundary() == oldBoundary) {
507 cmd = FuncRequest(LFUN_FINISHED_LEFT);
514 case LFUN_DOWN_SELECT:
517 // stop/start the selection
518 bool select = cmd.action == LFUN_DOWN_SELECT ||
519 cmd.action == LFUN_UP_SELECT;
520 cur.selHandle(select);
522 // move cursor up/down
523 bool up = cmd.action == LFUN_UP_SELECT || cmd.action == LFUN_UP;
524 bool const successful = cur.upDownInText(up, needsUpdate);
526 // notify insets which were left and get their update flags
527 notifyCursorLeaves(cur.beforeDispatchCursor(), cur);
530 // redraw if you leave mathed (for the decorations)
531 needsUpdate |= cur.beforeDispatchCursor().inMathed();
535 // save new selection
541 case LFUN_PARAGRAPH_UP:
542 case LFUN_PARAGRAPH_UP_SELECT:
543 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
544 needsUpdate |= cursorUpParagraph(cur);
549 case LFUN_PARAGRAPH_DOWN:
550 case LFUN_PARAGRAPH_DOWN_SELECT:
551 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
552 needsUpdate |= cursorDownParagraph(cur);
558 case LFUN_SCREEN_UP_SELECT:
559 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_UP_SELECT);
560 if (cur.pit() == 0 && cur.textRow().pos() == 0)
569 case LFUN_SCREEN_DOWN:
570 case LFUN_SCREEN_DOWN_SELECT:
571 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_DOWN_SELECT);
572 if (cur.pit() == cur.lastpit()
573 && cur.textRow().endpos() == cur.lastpos())
582 case LFUN_LINE_BEGIN:
583 case LFUN_LINE_BEGIN_SELECT:
584 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
585 needsUpdate |= cursorHome(cur);
589 case LFUN_LINE_END_SELECT:
590 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
591 needsUpdate |= cursorEnd(cur);
596 case LFUN_WORD_FORWARD:
597 case LFUN_WORD_FORWARD_SELECT:
598 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
599 if (reverseDirectionNeeded(cur))
600 needsUpdate |= cursorLeftOneWord(cur);
602 needsUpdate |= cursorRightOneWord(cur);
607 case LFUN_WORD_BACKWARD:
608 case LFUN_WORD_BACKWARD_SELECT:
609 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
610 if (reverseDirectionNeeded(cur))
611 needsUpdate |= cursorRightOneWord(cur);
613 needsUpdate |= cursorLeftOneWord(cur);
618 case LFUN_WORD_SELECT: {
619 selectWord(cur, WHOLE_WORD);
620 finishChange(cur, true);
624 case LFUN_BREAK_LINE: {
625 // Not allowed by LaTeX (labels or empty par)
626 if (cur.pos() > cur.paragraph().beginOfBody()) {
627 // this avoids a double undo
628 // FIXME: should not be needed, ideally
629 if (!cur.selection())
631 cap::replaceSelection(cur);
632 cur.insert(new InsetNewline);
634 moveCursor(cur, false);
639 case LFUN_CHAR_DELETE_FORWARD:
640 if (!cur.selection()) {
641 if (cur.pos() == cur.paragraph().size())
642 // Par boundary, force full-screen update
643 singleParUpdate = false;
644 needsUpdate |= erase(cur);
646 // It is possible to make it a lot faster still
647 // just comment out the line below...
649 cutSelection(cur, true, false);
650 singleParUpdate = false;
652 moveCursor(cur, false);
655 case LFUN_DELETE_FORWARD_SKIP:
656 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
657 if (!cur.selection()) {
658 if (cur.pos() == cur.lastpos()) {
665 cutSelection(cur, true, false);
670 case LFUN_CHAR_DELETE_BACKWARD:
671 if (!cur.selection()) {
672 if (bv->getIntl().getTransManager().backspace()) {
673 // Par boundary, full-screen update
675 singleParUpdate = false;
676 needsUpdate |= backspace(cur);
678 // It is possible to make it a lot faster still
679 // just comment out the line below...
682 cutSelection(cur, true, false);
683 singleParUpdate = false;
687 case LFUN_DELETE_BACKWARD_SKIP:
688 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
689 if (!cur.selection()) {
693 //CursorSlice cur = cursor();
697 cutSelection(cur, true, false);
701 case LFUN_BREAK_PARAGRAPH:
702 cap::replaceSelection(cur);
703 breakParagraph(cur, 0);
707 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
708 cap::replaceSelection(cur);
709 breakParagraph(cur, 1);
713 case LFUN_BREAK_PARAGRAPH_SKIP: {
714 // When at the beginning of a paragraph, remove
715 // indentation. Otherwise, do the same as LFUN_BREAK_PARAGRAPH.
716 cap::replaceSelection(cur);
718 cur.paragraph().params().labelWidthString(docstring());
720 breakParagraph(cur, 0);
725 case LFUN_PARAGRAPH_SPACING: {
726 Paragraph & par = cur.paragraph();
727 Spacing::Space cur_spacing = par.params().spacing().getSpace();
728 string cur_value = "1.0";
729 if (cur_spacing == Spacing::Other)
730 cur_value = par.params().spacing().getValueAsString();
732 istringstream is(to_utf8(cmd.argument()));
735 Spacing::Space new_spacing = cur_spacing;
736 string new_value = cur_value;
738 lyxerr << "Missing argument to `paragraph-spacing'"
740 } else if (tmp == "single") {
741 new_spacing = Spacing::Single;
742 } else if (tmp == "onehalf") {
743 new_spacing = Spacing::Onehalf;
744 } else if (tmp == "double") {
745 new_spacing = Spacing::Double;
746 } else if (tmp == "other") {
747 new_spacing = Spacing::Other;
748 string tmpval = "0.0";
750 lyxerr << "new_value = " << tmpval << endl;
753 } else if (tmp == "default") {
754 new_spacing = Spacing::Default;
756 lyxerr << to_utf8(_("Unknown spacing argument: "))
757 << to_utf8(cmd.argument()) << endl;
759 if (cur_spacing != new_spacing || cur_value != new_value)
760 par.params().spacing(Spacing(new_spacing, new_value));
764 case LFUN_INSET_INSERT: {
766 Inset * inset = createInset(bv, cmd);
768 // FIXME (Abdel 01/02/2006):
769 // What follows would be a partial fix for bug 2154:
770 // http://bugzilla.lyx.org/show_bug.cgi?id=2154
771 // This automatically put the label inset _after_ a
772 // numbered section. It should be possible to extend the mechanism
773 // to any kind of LateX environement.
774 // The correct way to fix that bug would be at LateX generation.
775 // I'll let the code here for reference as it could be used for some
776 // other feature like "automatic labelling".
778 Paragraph & par = pars_[cur.pit()];
779 if (inset->lyxCode() == Inset::LABEL_CODE
780 && par.layout()->labeltype == LABEL_COUNTER) {
781 // Go to the end of the paragraph
782 // Warning: Because of Change-Tracking, the last
783 // position is 'size()' and not 'size()-1':
784 cur.pos() = par.size();
785 // Insert a new paragraph
786 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
790 insertInset(cur, inset);
796 case LFUN_INSET_DISSOLVE:
797 needsUpdate |= dissolveInset(cur);
800 case LFUN_INSET_SETTINGS:
801 cur.inset().showInsetDialog(bv);
804 case LFUN_SPACE_INSERT:
805 if (cur.paragraph().layout()->free_spacing)
806 insertChar(cur, ' ');
808 doInsertInset(cur, this, cmd, false, false);
811 moveCursor(cur, false);
814 case LFUN_HYPHENATION_POINT_INSERT:
815 specialChar(cur, InsetSpecialChar::HYPHENATION);
818 case LFUN_LIGATURE_BREAK_INSERT:
819 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
822 case LFUN_DOTS_INSERT:
823 specialChar(cur, InsetSpecialChar::LDOTS);
826 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
827 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
830 case LFUN_MENU_SEPARATOR_INSERT:
831 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
834 case LFUN_WORD_UPCASE:
835 changeCase(cur, Text::text_uppercase);
838 case LFUN_WORD_LOWCASE:
839 changeCase(cur, Text::text_lowercase);
842 case LFUN_WORD_CAPITALIZE:
843 changeCase(cur, Text::text_capitalization);
846 case LFUN_CHARS_TRANSPOSE:
851 cur.message(_("Paste"));
852 cap::replaceSelection(cur);
853 if (cmd.argument().empty() && !theClipboard().isInternal())
854 pasteClipboard(cur, bv->buffer()->errorList("Paste"));
856 string const arg(to_utf8(cmd.argument()));
857 pasteFromStack(cur, bv->buffer()->errorList("Paste"),
858 isStrUnsignedInt(arg) ?
859 convert<unsigned int>(arg) :
862 bv->buffer()->errors("Paste");
863 cur.clearSelection(); // bug 393
868 cutSelection(cur, true, true);
869 cur.message(_("Cut"));
874 cur.message(_("Copy"));
877 case LFUN_SERVER_GET_XY:
878 cur.message(from_utf8(
879 convert<string>(cursorX(cur.bv(), cur.top(), cur.boundary()))
880 + ' ' + convert<string>(cursorY(cur.bv(), cur.top(), cur.boundary()))));
883 case LFUN_SERVER_SET_XY: {
886 istringstream is(to_utf8(cmd.argument()));
889 lyxerr << "SETXY: Could not parse coordinates in '"
890 << to_utf8(cmd.argument()) << std::endl;
892 setCursorFromCoordinates(cur, x, y);
896 case LFUN_SERVER_GET_FONT:
897 if (current_font.shape() == Font::ITALIC_SHAPE)
898 cur.message(from_ascii("E"));
899 else if (current_font.shape() == Font::SMALLCAPS_SHAPE)
900 cur.message(from_ascii("N"));
902 cur.message(from_ascii("0"));
905 case LFUN_SERVER_GET_LAYOUT:
906 cur.message(from_utf8(cur.paragraph().layout()->name()));
910 string layout = to_ascii(cmd.argument());
911 LYXERR(Debug::INFO) << "LFUN_LAYOUT: (arg) " << layout << endl;
913 // Derive layout number from given argument (string)
914 // and current buffer's textclass (number)
915 TextClass const & tclass = bv->buffer()->params().getTextClass();
917 layout = tclass.defaultLayoutName();
918 bool hasLayout = tclass.hasLayout(layout);
920 // If the entry is obsolete, use the new one instead.
922 string const & obs = tclass[layout]->obsoleted_by();
928 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
929 from_utf8(N_(" not known")));
933 bool change_layout = (current_layout != layout);
935 if (!change_layout && cur.selection() &&
936 cur.selBegin().pit() != cur.selEnd().pit())
938 pit_type spit = cur.selBegin().pit();
939 pit_type epit = cur.selEnd().pit() + 1;
940 while (spit != epit) {
941 if (pars_[spit].layout()->name() != current_layout) {
942 change_layout = true;
950 setLayout(cur, layout);
951 // inform the GUI that the layout has changed.
952 bv->layoutChanged(layout);
957 case LFUN_CLIPBOARD_PASTE:
958 cur.clearSelection();
959 pasteClipboard(cur, bv->buffer()->errorList("Paste"),
960 cmd.argument() == "paragraph");
961 bv->buffer()->errors("Paste");
964 case LFUN_PRIMARY_SELECTION_PASTE:
965 pasteString(cur, theSelection().get(),
966 cmd.argument() == "paragraph");
969 case LFUN_UNICODE_INSERT: {
970 if (cmd.argument().empty())
972 docstring hexstring = cmd.argument();
973 if (lyx::support::isHex(hexstring)) {
974 char_type c = lyx::support::hexToInt(hexstring);
975 if (c >= 32 && c < 0x10ffff) {
976 lyxerr << "Inserting c: " << c << endl;
977 docstring s = docstring(1, c);
978 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
984 case LFUN_QUOTE_INSERT: {
985 Paragraph & par = cur.paragraph();
986 pos_type pos = cur.pos();
987 BufferParams const & bufparams = bv->buffer()->params();
988 Layout_ptr const & style = par.layout();
989 if (!style->pass_thru
990 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
991 // this avoids a double undo
992 // FIXME: should not be needed, ideally
993 if (!cur.selection())
995 cap::replaceSelection(cur);
1000 else if (cur.prevInset() && cur.prevInset()->isSpace())
1003 c = par.getChar(pos - 1);
1004 string arg = to_utf8(cmd.argument());
1005 if (arg == "single")
1006 cur.insert(new InsetQuotes(c,
1007 bufparams.quotes_language,
1008 InsetQuotes::SingleQ));
1010 cur.insert(new InsetQuotes(c,
1011 bufparams.quotes_language,
1012 InsetQuotes::DoubleQ));
1016 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
1020 case LFUN_DATE_INSERT:
1021 if (cmd.argument().empty())
1022 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
1023 formatted_time(current_time())));
1025 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
1026 formatted_time(current_time(), to_utf8(cmd.argument()))));
1029 case LFUN_MOUSE_TRIPLE:
1030 if (cmd.button() == mouse_button::button1) {
1040 case LFUN_MOUSE_DOUBLE:
1041 if (cmd.button() == mouse_button::button1) {
1042 selectWord(cur, WHOLE_WORD_STRICT);
1047 // Single-click on work area
1048 case LFUN_MOUSE_PRESS: {
1049 // Right click on a footnote flag opens float menu
1050 if (cmd.button() == mouse_button::button3)
1051 cur.clearSelection();
1053 // Middle button press pastes if we have a selection
1054 // We do this here as if the selection was inside an inset
1055 // it could get cleared on the unlocking of the inset so
1056 // we have to check this first
1057 bool paste_internally = false;
1058 if (cmd.button() == mouse_button::button2 && cap::selection()) {
1059 // Copy the selection buffer to the clipboard
1060 // stack, because we want it to appear in the
1061 // "Edit->Paste recent" menu.
1062 cap::copySelectionToStack();
1063 paste_internally = true;
1066 // Insert primary selection with middle mouse
1067 // if there is a local selection in the current buffer,
1069 if (cmd.button() == mouse_button::button2) {
1070 if (paste_internally) {
1071 cap::pasteSelection(cur, bv->buffer()->errorList("Paste"));
1072 bv->buffer()->errors("Paste");
1073 cur.clearSelection(); // bug 393
1074 bv->buffer()->markDirty();
1077 bv->mouseSetCursor(cur);
1078 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
1082 // we have to update after dePM triggered
1083 bool update = bv->mouseSetCursor(cur);
1085 if (!update && cmd.button() == mouse_button::button1) {
1086 needsUpdate = false;
1093 case LFUN_MOUSE_MOTION: {
1094 // Only use motion with button 1
1095 //if (cmd.button() != mouse_button::button1)
1098 // ignore motions deeper nested than the real anchor
1099 Cursor & bvcur = cur.bv().cursor();
1100 if (bvcur.anchor_.hasPart(cur)) {
1101 CursorSlice old = bvcur.top();
1103 int const wh = bv->workHeight();
1104 int const y = std::max(0, std::min(wh - 1, cmd.y));
1106 setCursorFromCoordinates(cur, cmd.x, y);
1107 cur.setTargetX(cmd.x);
1109 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1111 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1112 // This is to allow jumping over large insets
1113 if (cur.top() == old) {
1115 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1117 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1120 if (cur.top() == old)
1123 // don't set anchor_
1124 bvcur.setCursor(cur);
1125 bvcur.selection() = true;
1126 //lyxerr << "MOTION: " << bv->cursor() << endl;
1134 case LFUN_MOUSE_RELEASE: {
1135 if (cmd.button() == mouse_button::button2)
1138 if (cmd.button() == mouse_button::button1) {
1139 // if there is new selection, update persistent
1140 // selection, otherwise, single click does not
1141 // clear persistent selection buffer
1142 if (cur.selection()) {
1144 // if double click, cur is moved to the end of word by selectWord
1145 // but bvcur is current mouse position
1146 Cursor & bvcur = cur.bv().cursor();
1147 bvcur.selection() = true;
1148 saveSelection(bvcur);
1150 needsUpdate = false;
1157 case LFUN_SELF_INSERT: {
1158 if (cmd.argument().empty())
1161 // Automatically delete the currently selected
1162 // text and replace it with what is being
1163 // typed in now. Depends on lyxrc settings
1164 // "auto_region_delete", which defaults to
1167 if (lyxrc.auto_region_delete)
1168 if (cur.selection())
1169 cutSelection(cur, false, false);
1171 cur.clearSelection();
1172 Font const old_font = real_current_font;
1174 docstring::const_iterator cit = cmd.argument().begin();
1175 docstring::const_iterator end = cmd.argument().end();
1176 for (; cit != end; ++cit)
1177 bv->translateAndInsert(*cit, this, cur);
1180 moveCursor(cur, false);
1184 case LFUN_URL_INSERT: {
1185 InsetCommandParams p("url");
1186 string const data = InsetCommandMailer::params2string("url", p);
1187 bv->showInsetDialog("url", data, 0);
1191 case LFUN_HTML_INSERT: {
1192 InsetCommandParams p("htmlurl");
1193 string const data = InsetCommandMailer::params2string("url", p);
1194 bv->showInsetDialog("url", data, 0);
1198 case LFUN_LABEL_INSERT: {
1199 InsetCommandParams p("label");
1200 // Try to generate a valid label
1201 p["name"] = (cmd.argument().empty()) ?
1202 cur.getPossibleLabel() :
1204 string const data = InsetCommandMailer::params2string("label", p);
1206 if (cmd.argument().empty()) {
1207 bv->showInsetDialog("label", data, 0);
1209 FuncRequest fr(LFUN_INSET_INSERT, data);
1217 case LFUN_LIST_INSERT:
1218 case LFUN_THEOREM_INSERT:
1220 case LFUN_CAPTION_INSERT:
1221 // Open the inset, and move the current selection
1223 doInsertInset(cur, this, cmd, true, true);
1225 updateLabels(*bv->buffer());
1227 case LFUN_NOTE_INSERT:
1228 case LFUN_CHARSTYLE_INSERT:
1229 case LFUN_BOX_INSERT:
1230 case LFUN_BRANCH_INSERT:
1231 case LFUN_BIBITEM_INSERT:
1232 case LFUN_ERT_INSERT:
1233 case LFUN_LISTING_INSERT:
1234 case LFUN_FOOTNOTE_INSERT:
1235 case LFUN_MARGINALNOTE_INSERT:
1236 case LFUN_OPTIONAL_INSERT:
1237 case LFUN_ENVIRONMENT_INSERT:
1238 // Open the inset, and move the current selection
1240 doInsertInset(cur, this, cmd, true, true);
1244 case LFUN_TABULAR_INSERT:
1245 // if there were no arguments, just open the dialog
1246 if (doInsertInset(cur, this, cmd, false, true))
1249 bv->showDialog("tabularcreate");
1253 case LFUN_FLOAT_INSERT:
1254 case LFUN_FLOAT_WIDE_INSERT:
1255 case LFUN_WRAP_INSERT: {
1256 bool content = cur.selection(); // will some text be moved into the inset?
1258 doInsertInset(cur, this, cmd, true, true);
1260 ParagraphList & pars = cur.text()->paragraphs();
1262 TextClass const & tclass = bv->buffer()->params().getTextClass();
1264 // add a separate paragraph for the caption inset
1265 pars.push_back(Paragraph());
1266 pars.back().setInsetOwner(pars[0].inInset());
1267 pars.back().layout(tclass.defaultLayout());
1269 int cap_pit = pars.size() - 1;
1271 // if an empty inset was created, we create an additional empty
1272 // paragraph at the bottom so that the user can choose where to put
1273 // the graphics (or table).
1275 pars.push_back(Paragraph());
1276 pars.back().setInsetOwner(pars[0].inInset());
1277 pars.back().layout(tclass.defaultLayout());
1281 // reposition the cursor to the caption
1282 cur.pit() = cap_pit;
1284 cur.dispatch(FuncRequest(LFUN_CAPTION_INSERT));
1285 // FIXME: When leaving the Float (or Wrap) inset we should
1286 // delete any empty paragraph left above or below the
1291 case LFUN_INDEX_INSERT:
1292 case LFUN_NOMENCL_INSERT: {
1293 Inset * inset = createInset(&cur.bv(), cmd);
1297 cur.clearSelection();
1298 insertInset(cur, inset);
1299 inset->edit(cur, true);
1300 // Show the dialog for the nomenclature entry, since the
1301 // description entry still needs to be filled in.
1302 if (cmd.action == LFUN_NOMENCL_INSERT)
1303 InsetCommandMailer("nomenclature",
1304 *reinterpret_cast<InsetCommand *>(inset)).showDialog(&cur.bv());
1309 case LFUN_INDEX_PRINT:
1310 case LFUN_NOMENCL_PRINT:
1311 case LFUN_TOC_INSERT:
1312 case LFUN_HFILL_INSERT:
1313 case LFUN_LINE_INSERT:
1314 case LFUN_PAGEBREAK_INSERT:
1315 case LFUN_CLEARPAGE_INSERT:
1316 case LFUN_CLEARDOUBLEPAGE_INSERT:
1318 doInsertInset(cur, this, cmd, false, false);
1322 case LFUN_DEPTH_DECREMENT:
1323 changeDepth(cur, DEC_DEPTH);
1326 case LFUN_DEPTH_INCREMENT:
1327 changeDepth(cur, INC_DEPTH);
1330 case LFUN_MATH_DISPLAY:
1331 mathDispatch(cur, cmd, true);
1334 case LFUN_MATH_IMPORT_SELECTION:
1335 case LFUN_MATH_MODE:
1336 if (cmd.argument() == "on")
1337 // don't pass "on" as argument
1338 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1340 mathDispatch(cur, cmd, false);
1343 case LFUN_MATH_MACRO:
1344 if (cmd.argument().empty())
1345 cur.errorMessage(from_utf8(N_("Missing argument")));
1347 string s = to_utf8(cmd.argument());
1348 string const s1 = token(s, ' ', 1);
1349 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1350 string const s2 = token(s, ' ', 2);
1351 string const type = s2.empty() ? "newcommand" : s2;
1352 cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, from_utf8(type)));
1353 //cur.nextInset()->edit(cur, true);
1357 // passthrough hat and underscore outside mathed:
1358 case LFUN_MATH_SUBSCRIPT:
1359 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1361 case LFUN_MATH_SUPERSCRIPT:
1362 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1365 case LFUN_MATH_INSERT:
1366 case LFUN_MATH_MATRIX:
1367 case LFUN_MATH_DELIM:
1368 case LFUN_MATH_BIGDELIM: {
1369 cur.insert(new InsetMathHull(hullSimple));
1370 checkAndActivateInset(cur, true);
1371 BOOST_ASSERT(cur.inMathed());
1376 case LFUN_FONT_EMPH: {
1377 Font font(Font::ALL_IGNORE);
1378 font.setEmph(Font::TOGGLE);
1379 toggleAndShow(cur, this, font);
1383 case LFUN_FONT_BOLD: {
1384 Font font(Font::ALL_IGNORE);
1385 font.setSeries(Font::BOLD_SERIES);
1386 toggleAndShow(cur, this, font);
1390 case LFUN_FONT_NOUN: {
1391 Font font(Font::ALL_IGNORE);
1392 font.setNoun(Font::TOGGLE);
1393 toggleAndShow(cur, this, font);
1397 case LFUN_FONT_CODE: {
1398 Font font(Font::ALL_IGNORE);
1399 font.setFamily(Font::TYPEWRITER_FAMILY); // no good
1400 toggleAndShow(cur, this, font);
1404 case LFUN_FONT_SANS: {
1405 Font font(Font::ALL_IGNORE);
1406 font.setFamily(Font::SANS_FAMILY);
1407 toggleAndShow(cur, this, font);
1411 case LFUN_FONT_ROMAN: {
1412 Font font(Font::ALL_IGNORE);
1413 font.setFamily(Font::ROMAN_FAMILY);
1414 toggleAndShow(cur, this, font);
1418 case LFUN_FONT_DEFAULT: {
1419 Font font(Font::ALL_INHERIT, ignore_language);
1420 toggleAndShow(cur, this, font);
1424 case LFUN_FONT_UNDERLINE: {
1425 Font font(Font::ALL_IGNORE);
1426 font.setUnderbar(Font::TOGGLE);
1427 toggleAndShow(cur, this, font);
1431 case LFUN_FONT_SIZE: {
1432 Font font(Font::ALL_IGNORE);
1433 font.setLyXSize(to_utf8(cmd.argument()));
1434 toggleAndShow(cur, this, font);
1438 case LFUN_LANGUAGE: {
1439 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1442 Font font(Font::ALL_IGNORE);
1443 font.setLanguage(lang);
1444 toggleAndShow(cur, this, font);
1448 case LFUN_FONT_FREE_APPLY:
1449 toggleAndShow(cur, this, freefont, toggleall);
1450 cur.message(_("Character set"));
1453 // Set the freefont using the contents of \param data dispatched from
1454 // the frontends and apply it at the current cursor location.
1455 case LFUN_FONT_FREE_UPDATE: {
1458 if (bv_funcs::string2font(to_utf8(cmd.argument()), font, toggle)) {
1461 toggleAndShow(cur, this, freefont, toggleall);
1462 cur.message(_("Character set"));
1467 case LFUN_FINISHED_LEFT:
1468 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1469 if (reverseDirectionNeeded(cur))
1473 case LFUN_FINISHED_RIGHT:
1474 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1475 if (!reverseDirectionNeeded(cur))
1479 case LFUN_LAYOUT_PARAGRAPH: {
1481 params2string(cur.paragraph(), data);
1482 data = "show\n" + data;
1483 bv->showDialogWithData("paragraph", data);
1487 case LFUN_PARAGRAPH_UPDATE: {
1489 params2string(cur.paragraph(), data);
1491 // Will the paragraph accept changes from the dialog?
1492 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1494 data = "update " + convert<string>(accept) + '\n' + data;
1495 bv->updateDialog("paragraph", data);
1499 case LFUN_ACCENT_UMLAUT:
1500 case LFUN_ACCENT_CIRCUMFLEX:
1501 case LFUN_ACCENT_GRAVE:
1502 case LFUN_ACCENT_ACUTE:
1503 case LFUN_ACCENT_TILDE:
1504 case LFUN_ACCENT_CEDILLA:
1505 case LFUN_ACCENT_MACRON:
1506 case LFUN_ACCENT_DOT:
1507 case LFUN_ACCENT_UNDERDOT:
1508 case LFUN_ACCENT_UNDERBAR:
1509 case LFUN_ACCENT_CARON:
1510 case LFUN_ACCENT_SPECIAL_CARON:
1511 case LFUN_ACCENT_BREVE:
1512 case LFUN_ACCENT_TIE:
1513 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1514 case LFUN_ACCENT_CIRCLE:
1515 case LFUN_ACCENT_OGONEK:
1516 theLyXFunc().handleKeyFunc(cmd.action);
1517 if (!cmd.argument().empty())
1518 // FIXME: Are all these characters encoded in one byte in utf8?
1519 bv->translateAndInsert(cmd.argument()[0], this, cur);
1522 case LFUN_FLOAT_LIST: {
1523 TextClass const & tclass = bv->buffer()->params().getTextClass();
1524 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1525 // not quite sure if we want this...
1527 cur.clearSelection();
1528 breakParagraph(cur);
1530 if (cur.lastpos() != 0) {
1532 breakParagraph(cur);
1535 setLayout(cur, tclass.defaultLayoutName());
1536 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, docstring(), 0);
1537 insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1540 lyxerr << "Non-existent float type: "
1541 << to_utf8(cmd.argument()) << endl;
1546 case LFUN_CHANGE_ACCEPT: {
1547 acceptOrRejectChanges(cur, ACCEPT);
1551 case LFUN_CHANGE_REJECT: {
1552 acceptOrRejectChanges(cur, REJECT);
1556 case LFUN_THESAURUS_ENTRY: {
1557 docstring arg = cmd.argument();
1559 arg = cur.selectionAsString(false);
1561 if (arg.size() > 100 || arg.empty()) {
1562 // Get word or selection
1563 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1564 arg = cur.selectionAsString(false);
1567 bv->showDialogWithData("thesaurus", to_utf8(arg));
1571 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1572 // Given data, an encoding of the ParagraphParameters
1573 // generated in the Paragraph dialog, this function sets
1574 // the current paragraph appropriately.
1575 istringstream is(to_utf8(cmd.argument()));
1578 ParagraphParameters params;
1583 params.labelWidthString(),
1585 cur.message(_("Paragraph layout set"));
1590 if (cur.selection()) {
1591 cur.selection() = false;
1595 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1600 LYXERR(Debug::ACTION)
1601 << BOOST_CURRENT_FUNCTION
1602 << ": Command " << cmd
1603 << " not DISPATCHED by Text" << endl;
1608 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1610 // FIXME: The cursor flag is reset two lines below
1611 // so we need to check here if some of the LFUN did touch that.
1612 // for now only Text::erase() and Text::backspace() do that.
1613 // The plan is to verify all the LFUNs and then to remove this
1614 // singleParUpdate boolean altogether.
1615 if (cur.result().update() & Update::Force) {
1616 singleParUpdate = false;
1620 // FIXME: the following code should go in favor of fine grained
1621 // update flag treatment.
1622 if (singleParUpdate) {
1623 // Inserting characters does not change par height
1624 ParagraphMetrics const & pms
1625 = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
1626 if (pms.dim().height()
1627 == olddim.height()) {
1628 // if so, update _only_ this paragraph
1629 cur.updateFlags(Update::SinglePar |
1631 Update::MultiParSel);
1638 && &oldTopSlice.inset() == &cur.inset()
1639 && oldTopSlice.idx() == cur.idx()
1640 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1641 && !cur.selection())
1642 // FIXME: it would be better if we could just do this
1644 //if (cur.result().update() != Update::FitCursor)
1647 // But some LFUNs do not set Update::FitCursor when needed, so we
1648 // do it for all. This is not very harmfull as FitCursor will provoke
1649 // a full redraw only if needed but still, a proper review of all LFUN
1650 // should be done and this needsUpdate boolean can then be removed.
1651 cur.updateFlags(Update::FitCursor);
1653 cur.updateFlags(Update::Force | Update::FitCursor);
1657 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
1658 FuncStatus & flag) const
1660 BOOST_ASSERT(cur.text() == this);
1662 Font const & font = real_current_font;
1664 Inset::Code code = Inset::NO_CODE;
1666 switch (cmd.action) {
1668 case LFUN_DEPTH_DECREMENT:
1669 enable = changeDepthAllowed(cur, DEC_DEPTH);
1672 case LFUN_DEPTH_INCREMENT:
1673 enable = changeDepthAllowed(cur, INC_DEPTH);
1677 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1680 case LFUN_BIBITEM_INSERT:
1681 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO
1685 case LFUN_DIALOG_SHOW_NEW_INSET:
1686 if (cmd.argument() == "bibitem")
1687 code = Inset::BIBITEM_CODE;
1688 else if (cmd.argument() == "bibtex")
1689 code = Inset::BIBTEX_CODE;
1690 else if (cmd.argument() == "box")
1691 code = Inset::BOX_CODE;
1692 else if (cmd.argument() == "branch")
1693 code = Inset::BRANCH_CODE;
1694 else if (cmd.argument() == "citation")
1695 code = Inset::CITE_CODE;
1696 else if (cmd.argument() == "ert")
1697 code = Inset::ERT_CODE;
1698 else if (cmd.argument() == "external")
1699 code = Inset::EXTERNAL_CODE;
1700 else if (cmd.argument() == "float")
1701 code = Inset::FLOAT_CODE;
1702 else if (cmd.argument() == "graphics")
1703 code = Inset::GRAPHICS_CODE;
1704 else if (cmd.argument() == "include")
1705 code = Inset::INCLUDE_CODE;
1706 else if (cmd.argument() == "index")
1707 code = Inset::INDEX_CODE;
1708 else if (cmd.argument() == "nomenclature")
1709 code = Inset::NOMENCL_CODE;
1710 else if (cmd.argument() == "label")
1711 code = Inset::LABEL_CODE;
1712 else if (cmd.argument() == "note")
1713 code = Inset::NOTE_CODE;
1714 else if (cmd.argument() == "ref")
1715 code = Inset::REF_CODE;
1716 else if (cmd.argument() == "toc")
1717 code = Inset::TOC_CODE;
1718 else if (cmd.argument() == "url")
1719 code = Inset::URL_CODE;
1720 else if (cmd.argument() == "vspace")
1721 code = Inset::VSPACE_CODE;
1722 else if (cmd.argument() == "wrap")
1723 code = Inset::WRAP_CODE;
1724 else if (cmd.argument() == "listings")
1725 code = Inset::LISTINGS_CODE;
1728 case LFUN_ERT_INSERT:
1729 code = Inset::ERT_CODE;
1731 case LFUN_LISTING_INSERT:
1732 code = Inset::LISTINGS_CODE;
1734 case LFUN_FOOTNOTE_INSERT:
1735 code = Inset::FOOT_CODE;
1737 case LFUN_TABULAR_INSERT:
1738 code = Inset::TABULAR_CODE;
1740 case LFUN_MARGINALNOTE_INSERT:
1741 code = Inset::MARGIN_CODE;
1743 case LFUN_FLOAT_INSERT:
1744 case LFUN_FLOAT_WIDE_INSERT:
1745 code = Inset::FLOAT_CODE;
1747 case LFUN_WRAP_INSERT:
1748 code = Inset::WRAP_CODE;
1750 case LFUN_FLOAT_LIST:
1751 code = Inset::FLOAT_LIST_CODE;
1754 case LFUN_LIST_INSERT:
1755 code = Inset::LIST_CODE;
1757 case LFUN_THEOREM_INSERT:
1758 code = Inset::THEOREM_CODE;
1761 case LFUN_CAPTION_INSERT:
1762 code = Inset::CAPTION_CODE;
1764 case LFUN_NOTE_INSERT:
1765 code = Inset::NOTE_CODE;
1767 case LFUN_CHARSTYLE_INSERT:
1768 code = Inset::CHARSTYLE_CODE;
1769 if (cur.buffer().params().getTextClass().charstyles().empty())
1772 case LFUN_BOX_INSERT:
1773 code = Inset::BOX_CODE;
1775 case LFUN_BRANCH_INSERT:
1776 code = Inset::BRANCH_CODE;
1777 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1780 case LFUN_LABEL_INSERT:
1781 code = Inset::LABEL_CODE;
1783 case LFUN_OPTIONAL_INSERT:
1784 code = Inset::OPTARG_CODE;
1785 enable = numberOfOptArgs(cur.paragraph())
1786 < cur.paragraph().layout()->optionalargs;
1788 case LFUN_ENVIRONMENT_INSERT:
1789 code = Inset::BOX_CODE;
1791 case LFUN_INDEX_INSERT:
1792 code = Inset::INDEX_CODE;
1794 case LFUN_INDEX_PRINT:
1795 code = Inset::INDEX_PRINT_CODE;
1797 case LFUN_NOMENCL_INSERT:
1798 code = Inset::NOMENCL_CODE;
1800 case LFUN_NOMENCL_PRINT:
1801 code = Inset::NOMENCL_PRINT_CODE;
1803 case LFUN_TOC_INSERT:
1804 code = Inset::TOC_CODE;
1806 case LFUN_HTML_INSERT:
1807 case LFUN_URL_INSERT:
1808 code = Inset::URL_CODE;
1810 case LFUN_QUOTE_INSERT:
1811 // always allow this, since we will inset a raw quote
1812 // if an inset is not allowed.
1814 case LFUN_HYPHENATION_POINT_INSERT:
1815 case LFUN_LIGATURE_BREAK_INSERT:
1816 case LFUN_HFILL_INSERT:
1817 case LFUN_MENU_SEPARATOR_INSERT:
1818 case LFUN_DOTS_INSERT:
1819 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
1820 code = Inset::SPECIALCHAR_CODE;
1822 case LFUN_SPACE_INSERT:
1823 // slight hack: we know this is allowed in math mode
1825 code = Inset::SPACE_CODE;
1828 case LFUN_INSET_MODIFY:
1829 // We need to disable this, because we may get called for a
1831 // InsetTabular::getStatus() -> InsetText::getStatus()
1832 // and we don't handle LFUN_INSET_MODIFY.
1836 case LFUN_FONT_EMPH:
1837 flag.setOnOff(font.emph() == Font::ON);
1840 case LFUN_FONT_NOUN:
1841 flag.setOnOff(font.noun() == Font::ON);
1844 case LFUN_FONT_BOLD:
1845 flag.setOnOff(font.series() == Font::BOLD_SERIES);
1848 case LFUN_FONT_SANS:
1849 flag.setOnOff(font.family() == Font::SANS_FAMILY);
1852 case LFUN_FONT_ROMAN:
1853 flag.setOnOff(font.family() == Font::ROMAN_FAMILY);
1856 case LFUN_FONT_CODE:
1857 flag.setOnOff(font.family() == Font::TYPEWRITER_FAMILY);
1862 enable = cur.selection();
1866 if (cmd.argument().empty()) {
1867 if (theClipboard().isInternal())
1868 enable = cap::numberOfSelections() > 0;
1870 enable = !theClipboard().empty();
1872 string const arg = to_utf8(cmd.argument());
1873 if (isStrUnsignedInt(arg)) {
1874 unsigned int n = convert<unsigned int>(arg);
1875 enable = cap::numberOfSelections() > n;
1882 case LFUN_CLIPBOARD_PASTE:
1883 enable = !theClipboard().empty();
1886 case LFUN_PRIMARY_SELECTION_PASTE:
1887 enable = cur.selection() || !theSelection().empty();
1890 case LFUN_PARAGRAPH_MOVE_UP:
1891 enable = cur.pit() > 0 && !cur.selection();
1894 case LFUN_PARAGRAPH_MOVE_DOWN:
1895 enable = cur.pit() < cur.lastpit() && !cur.selection();
1898 case LFUN_INSET_DISSOLVE:
1899 enable = !isMainText(*cur.bv().buffer()) && cur.inset().nargs() == 1;
1902 case LFUN_CHANGE_ACCEPT:
1903 case LFUN_CHANGE_REJECT:
1904 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
1905 // In principle, these LFUNs should only be enabled if there
1906 // is a change at the current position/in the current selection.
1907 // However, without proper optimizations, this will inevitably
1908 // result in unacceptable performance - just imagine a user who
1909 // wants to select the complete content of a long document.
1913 case LFUN_WORD_DELETE_FORWARD:
1914 case LFUN_WORD_DELETE_BACKWARD:
1915 case LFUN_LINE_DELETE:
1916 case LFUN_WORD_FORWARD:
1917 case LFUN_WORD_BACKWARD:
1918 case LFUN_CHAR_FORWARD:
1919 case LFUN_CHAR_FORWARD_SELECT:
1920 case LFUN_CHAR_BACKWARD:
1921 case LFUN_CHAR_BACKWARD_SELECT:
1923 case LFUN_UP_SELECT:
1925 case LFUN_DOWN_SELECT:
1926 case LFUN_PARAGRAPH_UP_SELECT:
1927 case LFUN_PARAGRAPH_DOWN_SELECT:
1928 case LFUN_SCREEN_UP_SELECT:
1929 case LFUN_SCREEN_DOWN_SELECT:
1930 case LFUN_LINE_BEGIN_SELECT:
1931 case LFUN_LINE_END_SELECT:
1932 case LFUN_WORD_FORWARD_SELECT:
1933 case LFUN_WORD_BACKWARD_SELECT:
1934 case LFUN_WORD_SELECT:
1935 case LFUN_PARAGRAPH_UP:
1936 case LFUN_PARAGRAPH_DOWN:
1937 case LFUN_SCREEN_UP:
1938 case LFUN_SCREEN_DOWN:
1939 case LFUN_LINE_BEGIN:
1941 case LFUN_BREAK_LINE:
1942 case LFUN_CHAR_DELETE_FORWARD:
1943 case LFUN_DELETE_FORWARD_SKIP:
1944 case LFUN_CHAR_DELETE_BACKWARD:
1945 case LFUN_DELETE_BACKWARD_SKIP:
1946 case LFUN_BREAK_PARAGRAPH:
1947 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
1948 case LFUN_BREAK_PARAGRAPH_SKIP:
1949 case LFUN_PARAGRAPH_SPACING:
1950 case LFUN_INSET_INSERT:
1951 case LFUN_WORD_UPCASE:
1952 case LFUN_WORD_LOWCASE:
1953 case LFUN_WORD_CAPITALIZE:
1954 case LFUN_CHARS_TRANSPOSE:
1955 case LFUN_SERVER_GET_XY:
1956 case LFUN_SERVER_SET_XY:
1957 case LFUN_SERVER_GET_FONT:
1958 case LFUN_SERVER_GET_LAYOUT:
1960 case LFUN_DATE_INSERT:
1961 case LFUN_SELF_INSERT:
1962 case LFUN_LINE_INSERT:
1963 case LFUN_PAGEBREAK_INSERT:
1964 case LFUN_CLEARPAGE_INSERT:
1965 case LFUN_CLEARDOUBLEPAGE_INSERT:
1966 case LFUN_MATH_DISPLAY:
1967 case LFUN_MATH_IMPORT_SELECTION:
1968 case LFUN_MATH_MODE:
1969 case LFUN_MATH_MACRO:
1970 case LFUN_MATH_MATRIX:
1971 case LFUN_MATH_DELIM:
1972 case LFUN_MATH_BIGDELIM:
1973 case LFUN_MATH_INSERT:
1974 case LFUN_MATH_SUBSCRIPT:
1975 case LFUN_MATH_SUPERSCRIPT:
1976 case LFUN_FONT_DEFAULT:
1977 case LFUN_FONT_UNDERLINE:
1978 case LFUN_FONT_SIZE:
1980 case LFUN_FONT_FREE_APPLY:
1981 case LFUN_FONT_FREE_UPDATE:
1982 case LFUN_LAYOUT_PARAGRAPH:
1983 case LFUN_PARAGRAPH_UPDATE:
1984 case LFUN_ACCENT_UMLAUT:
1985 case LFUN_ACCENT_CIRCUMFLEX:
1986 case LFUN_ACCENT_GRAVE:
1987 case LFUN_ACCENT_ACUTE:
1988 case LFUN_ACCENT_TILDE:
1989 case LFUN_ACCENT_CEDILLA:
1990 case LFUN_ACCENT_MACRON:
1991 case LFUN_ACCENT_DOT:
1992 case LFUN_ACCENT_UNDERDOT:
1993 case LFUN_ACCENT_UNDERBAR:
1994 case LFUN_ACCENT_CARON:
1995 case LFUN_ACCENT_SPECIAL_CARON:
1996 case LFUN_ACCENT_BREVE:
1997 case LFUN_ACCENT_TIE:
1998 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1999 case LFUN_ACCENT_CIRCLE:
2000 case LFUN_ACCENT_OGONEK:
2001 case LFUN_THESAURUS_ENTRY:
2002 case LFUN_PARAGRAPH_PARAMS_APPLY:
2004 case LFUN_BUFFER_END:
2005 case LFUN_BUFFER_BEGIN:
2006 case LFUN_BUFFER_BEGIN_SELECT:
2007 case LFUN_BUFFER_END_SELECT:
2008 case LFUN_UNICODE_INSERT:
2009 // these are handled in our dispatch()
2017 if (code != Inset::NO_CODE
2018 && (cur.empty() || !cur.inset().insetAllowed(code)))
2021 flag.enabled(enable);
2026 void Text::pasteString(Cursor & cur, docstring const & clip,
2029 cur.clearSelection();
2030 if (!clip.empty()) {
2033 insertStringAsParagraphs(cur, clip);
2035 insertStringAsLines(cur, clip);