3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Asger Alstrup
7 * \author Lars Gullik Bjønnes
8 * \author Alfredo Braunstein
9 * \author Angus Leeming
11 * \author André Pönitz
13 * Full author contact details are available in file CREDITS.
20 #include "BranchList.h"
21 #include "FloatList.h"
22 #include "FuncStatus.h"
24 #include "buffer_funcs.h"
25 #include "BufferParams.h"
26 #include "BufferView.h"
27 #include "bufferview_funcs.h"
29 #include "CoordCache.h"
30 #include "CutAndPaste.h"
32 #include "DispatchResult.h"
33 #include "ErrorList.h"
35 #include "FuncRequest.h"
39 #include "LyXAction.h"
44 #include "Paragraph.h"
45 #include "paragraph_funcs.h"
46 #include "ParagraphParameters.h"
49 #include "ParIterator.h"
51 #include "frontends/Clipboard.h"
52 #include "frontends/Selection.h"
54 #include "insets/InsetCommand.h"
55 #include "insets/InsetFloatList.h"
56 #include "insets/InsetNewline.h"
57 #include "insets/InsetQuotes.h"
58 #include "insets/InsetSpecialChar.h"
59 #include "insets/InsetText.h"
61 #include "support/lstrings.h"
62 #include "support/lyxlib.h"
63 #include "support/convert.h"
64 #include "support/lyxtime.h"
66 #include "mathed/InsetMathHull.h"
67 #include "mathed/MathMacroTemplate.h"
69 #include <boost/current_function.hpp>
76 using std::istringstream;
77 using std::ostringstream;
81 using cap::copySelection;
82 using cap::cutSelection;
83 using cap::pasteFromStack;
84 using cap::pasteClipboard;
85 using cap::replaceSelection;
87 using support::isStrUnsignedInt;
91 extern docstring current_layout;
97 Font freefont(Font::ALL_IGNORE);
98 bool toggleall = false;
100 void toggleAndShow(Cursor & cur, Text * text,
101 Font const & font, bool toggleall = true)
103 text->toggleFree(cur, font, toggleall);
105 if (font.language() != ignore_language ||
106 font.number() != Font::IGNORE) {
107 Paragraph & par = cur.paragraph();
108 if (cur.boundary() != text->isRTLBoundary(cur.buffer(), par,
109 cur.pos(), text->real_current_font))
110 text->setCursor(cur, cur.pit(), cur.pos(),
111 false, !cur.boundary());
116 void moveCursor(Cursor & cur, bool selecting)
118 if (selecting || cur.mark())
123 void finishChange(Cursor & cur, bool selecting)
126 moveCursor(cur, selecting);
130 void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
133 docstring sel = cur.selectionAsString(false);
135 // It may happen that sel is empty but there is a selection
136 replaceSelection(cur);
139 #ifdef ENABLE_ASSERTIONS
140 const int old_pos = cur.pos();
142 cur.insert(new InsetMathHull(hullSimple));
143 BOOST_ASSERT(old_pos == cur.pos());
144 cur.nextInset()->edit(cur, true);
145 // don't do that also for LFUN_MATH_MODE
146 // unless you want end up with always changing
147 // to mathrm when opening an inlined inset --
148 // I really hate "LyXfunc overloading"...
150 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
151 // Avoid an unnecessary undo step if cmd.argument
153 if (!cmd.argument().empty())
154 cur.dispatch(FuncRequest(LFUN_MATH_INSERT,
157 // create a macro if we see "\\newcommand"
158 // somewhere, and an ordinary formula
160 if (sel.find(from_ascii("\\newcommand")) == string::npos
161 && sel.find(from_ascii("\\def")) == string::npos)
163 InsetMathHull * formula = new InsetMathHull;
164 istringstream is(to_utf8(sel));
167 formula->read(cur.buffer(), lex);
168 if (formula->getType() == hullNone)
169 // Don't create pseudo formulas if
170 // delimiters are left out
171 formula->mutate(hullSimple);
174 cur.insert(new MathMacroTemplate(sel));
177 cur.message(from_utf8(N_("Math editor mode")));
186 string const freefont2string()
189 if (font2string(freefont, toggleall, data))
196 void Text::cursorPrevious(Cursor & cur)
198 pos_type cpos = cur.pos();
199 pit_type cpar = cur.pit();
201 int x = cur.x_target();
202 setCursorFromCoordinates(cur, x, 0);
203 cur.dispatch(FuncRequest(cur.selection()? LFUN_UP_SELECT: LFUN_UP));
205 if (cpar == cur.pit() && cpos == cur.pos())
206 // we have a row which is taller than the workarea. The
207 // simplest solution is to move to the previous row instead.
208 cur.dispatch(FuncRequest(cur.selection()? LFUN_UP_SELECT: LFUN_UP));
211 cur.updateFlags(Update::Force | Update::FitCursor);
215 void Text::cursorNext(Cursor & cur)
217 pos_type cpos = cur.pos();
218 pit_type cpar = cur.pit();
220 int x = cur.x_target();
221 setCursorFromCoordinates(cur, x, cur.bv().workHeight() - 1);
222 cur.dispatch(FuncRequest(cur.selection()? LFUN_DOWN_SELECT: LFUN_DOWN));
224 if (cpar == cur.pit() && cpos == cur.pos())
225 // we have a row which is taller than the workarea. The
226 // simplest solution is to move to the next row instead.
228 FuncRequest(cur.selection()? LFUN_DOWN_SELECT: LFUN_DOWN));
231 cur.updateFlags(Update::Force | Update::FitCursor);
237 void specialChar(Cursor & cur, InsetSpecialChar::Kind kind)
240 cap::replaceSelection(cur);
241 cur.insert(new InsetSpecialChar(kind));
246 bool doInsertInset(Cursor & cur, Text * text,
247 FuncRequest const & cmd, bool edit, bool pastesel)
249 Inset * inset = createInset(&cur.bv(), cmd);
255 if (cur.selection()) {
256 lyx::dispatch(FuncRequest(LFUN_CUT));
259 text->insertInset(cur, inset);
262 inset->edit(cur, true);
264 if (gotsel && pastesel) {
265 lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
266 // reset first par to default
267 if (cur.lastpit() != 0 || cur.lastpos() != 0) {
268 LayoutPtr const layout =
269 cur.buffer().params().getTextClass().defaultLayout();
270 cur.text()->paragraphs().begin()->layout(layout);
280 void Text::number(Cursor & cur)
282 Font font(Font::ALL_IGNORE);
283 font.setNumber(Font::TOGGLE);
284 toggleAndShow(cur, this, font);
288 bool Text::isRTL(Buffer const & buffer, Paragraph const & par) const
290 return par.isRightToLeftPar(buffer.params());
294 bool Text::isRTL(Buffer const & buffer, CursorSlice const & sl, bool boundary) const
296 if (!lyxrc.rtl_support && !sl.text())
300 if (boundary && sl.pos() > 0)
303 Paragraph const & par = getPar(sl.pit());
304 return getFont(buffer, par, sl.pos() + correction).isVisibleRightToLeft();
308 bool Text::isRTLBoundary(Buffer const & buffer, Paragraph const & par,
311 if (!lyxrc.rtl_support)
314 // no RTL boundary at line start
318 bool left = getFont(buffer, par, pos - 1).isVisibleRightToLeft();
320 if (pos == par.size())
321 right = par.isRightToLeftPar(buffer.params());
323 right = getFont(buffer, par, pos).isVisibleRightToLeft();
324 return left != right;
328 bool Text::isRTLBoundary(Buffer const & buffer, Paragraph const & par,
329 pos_type pos, Font const & font) const
331 if (!lyxrc.rtl_support)
334 bool left = font.isVisibleRightToLeft();
336 if (pos == par.size())
337 right = par.isRightToLeftPar(buffer.params());
339 right = getFont(buffer, par, pos).isVisibleRightToLeft();
340 return left != right;
344 void Text::dispatch(Cursor & cur, FuncRequest & cmd)
346 LYXERR(Debug::ACTION) << "Text::dispatch: cmd: " << cmd << endl;
348 // FIXME: We use the update flag to indicates wether a singlePar or a
349 // full screen update is needed. We reset it here but shall we restore it
353 BOOST_ASSERT(cur.text() == this);
354 BufferView * bv = &cur.bv();
355 CursorSlice oldTopSlice = cur.top();
356 bool oldBoundary = cur.boundary();
357 bool sel = cur.selection();
358 // Signals that, even if needsUpdate == false, an update of the
359 // cursor paragraph is required
360 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
361 LyXAction::SingleParUpdate);
362 // Signals that a full-screen update is required
363 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
364 LyXAction::NoUpdate) || singleParUpdate);
365 // Remember the old paragraph metric (_outer_ paragraph!)
366 ParagraphMetrics const & pm = cur.bv().parMetrics(
367 cur.bottom().text(), cur.bottom().pit());
368 Dimension olddim = pm.dim();
370 switch (cmd.action) {
372 case LFUN_PARAGRAPH_MOVE_DOWN: {
373 pit_type const pit = cur.pit();
374 recUndo(cur, pit, pit + 1);
376 std::swap(pars_[pit], pars_[pit + 1]);
377 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());
394 case LFUN_APPENDIX: {
395 Paragraph & par = cur.paragraph();
396 bool start = !par.params().startOfAppendix();
398 // FIXME: The code below only makes sense at top level.
399 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
400 // ensure that we have only one start_of_appendix in this document
401 // FIXME: this don't work for multipart 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()) {
656 //CursorSlice cur = cursor();
660 cutSelection(cur, true, false);
664 case LFUN_BREAK_PARAGRAPH:
665 cap::replaceSelection(cur);
666 breakParagraph(cur, 0);
670 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
671 cap::replaceSelection(cur);
672 breakParagraph(cur, 1);
676 case LFUN_BREAK_PARAGRAPH_SKIP: {
677 // When at the beginning of a paragraph, remove
678 // indentation. Otherwise, do the same as LFUN_BREAK_PARAGRAPH.
679 cap::replaceSelection(cur);
681 cur.paragraph().params().labelWidthString(docstring());
683 breakParagraph(cur, 0);
689 // With the creation of LFUN_PARAGRAPH_PARAMS, this is now redundant,
690 // as its duties can be performed there. Should it be removed??
691 // FIXME For now, it can just dispatch LFUN_PARAGRAPH_PARAMS...
692 case LFUN_PARAGRAPH_SPACING: {
693 Paragraph & par = cur.paragraph();
694 Spacing::Space cur_spacing = par.params().spacing().getSpace();
695 string cur_value = "1.0";
696 if (cur_spacing == Spacing::Other)
697 cur_value = par.params().spacing().getValueAsString();
699 istringstream is(to_utf8(cmd.argument()));
702 Spacing::Space new_spacing = cur_spacing;
703 string new_value = cur_value;
705 lyxerr << "Missing argument to `paragraph-spacing'"
707 } else if (tmp == "single") {
708 new_spacing = Spacing::Single;
709 } else if (tmp == "onehalf") {
710 new_spacing = Spacing::Onehalf;
711 } else if (tmp == "double") {
712 new_spacing = Spacing::Double;
713 } else if (tmp == "other") {
714 new_spacing = Spacing::Other;
715 string tmpval = "0.0";
717 lyxerr << "new_value = " << tmpval << endl;
720 } else if (tmp == "default") {
721 new_spacing = Spacing::Default;
723 lyxerr << to_utf8(_("Unknown spacing argument: "))
724 << to_utf8(cmd.argument()) << endl;
726 if (cur_spacing != new_spacing || cur_value != new_value)
727 par.params().spacing(Spacing(new_spacing, new_value));
731 case LFUN_INSET_INSERT: {
733 Inset * inset = createInset(bv, cmd);
735 // FIXME (Abdel 01/02/2006):
736 // What follows would be a partial fix for bug 2154:
737 // http://bugzilla.lyx.org/show_bug.cgi?id=2154
738 // This automatically put the label inset _after_ a
739 // numbered section. It should be possible to extend the mechanism
740 // to any kind of LateX environement.
741 // The correct way to fix that bug would be at LateX generation.
742 // I'll let the code here for reference as it could be used for some
743 // other feature like "automatic labelling".
745 Paragraph & par = pars_[cur.pit()];
746 if (inset->lyxCode() == Inset::LABEL_CODE
747 && par.layout()->labeltype == LABEL_COUNTER) {
748 // Go to the end of the paragraph
749 // Warning: Because of Change-Tracking, the last
750 // position is 'size()' and not 'size()-1':
751 cur.pos() = par.size();
752 // Insert a new paragraph
753 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
758 cutSelection(cur, true, false);
759 insertInset(cur, inset);
765 case LFUN_INSET_DISSOLVE:
766 needsUpdate |= dissolveInset(cur);
769 case LFUN_INSET_SETTINGS:
770 cur.inset().showInsetDialog(bv);
773 case LFUN_SPACE_INSERT:
774 if (cur.paragraph().layout()->free_spacing)
775 insertChar(cur, ' ');
777 doInsertInset(cur, this, cmd, false, false);
780 moveCursor(cur, false);
783 case LFUN_HYPHENATION_POINT_INSERT:
784 specialChar(cur, InsetSpecialChar::HYPHENATION);
787 case LFUN_LIGATURE_BREAK_INSERT:
788 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
791 case LFUN_DOTS_INSERT:
792 specialChar(cur, InsetSpecialChar::LDOTS);
795 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
796 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
799 case LFUN_MENU_SEPARATOR_INSERT:
800 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
803 case LFUN_WORD_UPCASE:
804 changeCase(cur, Text::text_uppercase);
807 case LFUN_WORD_LOWCASE:
808 changeCase(cur, Text::text_lowercase);
811 case LFUN_WORD_CAPITALIZE:
812 changeCase(cur, Text::text_capitalization);
815 case LFUN_CHARS_TRANSPOSE:
820 cur.message(_("Paste"));
821 cap::replaceSelection(cur);
822 if (cmd.argument().empty() && !theClipboard().isInternal())
823 pasteClipboard(cur, bv->buffer().errorList("Paste"));
825 string const arg(to_utf8(cmd.argument()));
826 pasteFromStack(cur, bv->buffer().errorList("Paste"),
827 isStrUnsignedInt(arg) ?
828 convert<unsigned int>(arg) :
831 bv->buffer().errors("Paste");
832 cur.clearSelection(); // bug 393
837 cutSelection(cur, true, true);
838 cur.message(_("Cut"));
843 cur.message(_("Copy"));
846 case LFUN_SERVER_GET_XY:
847 cur.message(from_utf8(
848 convert<string>(cursorX(cur.bv(), cur.top(), cur.boundary()))
849 + ' ' + convert<string>(cursorY(cur.bv(), cur.top(), cur.boundary()))));
852 case LFUN_SERVER_SET_XY: {
855 istringstream is(to_utf8(cmd.argument()));
858 lyxerr << "SETXY: Could not parse coordinates in '"
859 << to_utf8(cmd.argument()) << std::endl;
861 setCursorFromCoordinates(cur, x, y);
865 case LFUN_SERVER_GET_FONT:
866 if (current_font.shape() == Font::ITALIC_SHAPE)
867 cur.message(from_ascii("E"));
868 else if (current_font.shape() == Font::SMALLCAPS_SHAPE)
869 cur.message(from_ascii("N"));
871 cur.message(from_ascii("0"));
874 case LFUN_SERVER_GET_LAYOUT:
875 cur.message(cur.paragraph().layout()->name());
879 docstring layout = cmd.argument();
880 LYXERR(Debug::INFO) << "LFUN_LAYOUT: (arg) " << to_utf8(layout) << endl;
882 // Derive layout number from given argument (string)
883 // and current buffer's textclass (number)
884 TextClass const & tclass = bv->buffer().params().getTextClass();
886 layout = tclass.defaultLayoutName();
887 bool hasLayout = tclass.hasLayout(layout);
889 // If the entry is obsolete, use the new one instead.
891 docstring const & obs = tclass[layout]->obsoleted_by();
897 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
898 from_utf8(N_(" not known")));
902 bool change_layout = (frontend::current_layout != layout);
904 if (!change_layout && cur.selection() &&
905 cur.selBegin().pit() != cur.selEnd().pit())
907 pit_type spit = cur.selBegin().pit();
908 pit_type epit = cur.selEnd().pit() + 1;
909 while (spit != epit) {
910 if (pars_[spit].layout()->name() != frontend::current_layout) {
911 change_layout = true;
919 setLayout(cur, layout);
920 // inform the GUI that the layout has changed.
921 bv->layoutChanged(layout);
926 case LFUN_CLIPBOARD_PASTE:
927 cur.clearSelection();
928 pasteClipboard(cur, bv->buffer().errorList("Paste"),
929 cmd.argument() == "paragraph");
930 bv->buffer().errors("Paste");
933 case LFUN_PRIMARY_SELECTION_PASTE:
934 pasteString(cur, theSelection().get(),
935 cmd.argument() == "paragraph");
938 case LFUN_UNICODE_INSERT: {
939 if (cmd.argument().empty())
941 docstring hexstring = cmd.argument();
942 if (lyx::support::isHex(hexstring)) {
943 char_type c = lyx::support::hexToInt(hexstring);
944 if (c >= 32 && c < 0x10ffff) {
945 lyxerr << "Inserting c: " << c << endl;
946 docstring s = docstring(1, c);
947 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
953 case LFUN_QUOTE_INSERT: {
954 Paragraph & par = cur.paragraph();
955 pos_type pos = cur.pos();
956 BufferParams const & bufparams = bv->buffer().params();
957 LayoutPtr const & style = par.layout();
958 if (!style->pass_thru
959 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
960 // this avoids a double undo
961 // FIXME: should not be needed, ideally
962 if (!cur.selection())
964 cap::replaceSelection(cur);
969 else if (cur.prevInset() && cur.prevInset()->isSpace())
972 c = par.getChar(pos - 1);
973 string arg = to_utf8(cmd.argument());
975 cur.insert(new InsetQuotes(c,
976 bufparams.quotes_language,
977 InsetQuotes::SingleQ));
979 cur.insert(new InsetQuotes(c,
980 bufparams.quotes_language,
981 InsetQuotes::DoubleQ));
985 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
989 case LFUN_DATE_INSERT: {
990 string const format = cmd.argument().empty()
991 ? lyxrc.date_insert_format : to_utf8(cmd.argument());
992 string const time = formatted_time(current_time(), format);
993 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, time));
997 case LFUN_MOUSE_TRIPLE:
998 if (cmd.button() == mouse_button::button1) {
1007 case LFUN_MOUSE_DOUBLE:
1008 if (cmd.button() == mouse_button::button1) {
1009 selectWord(cur, WHOLE_WORD_STRICT);
1014 // Single-click on work area
1015 case LFUN_MOUSE_PRESS: {
1016 // Right click on a footnote flag opens float menu
1017 if (cmd.button() == mouse_button::button3)
1018 cur.clearSelection();
1021 bool update = bv->mouseSetCursor(cur);
1023 // Insert primary selection with middle mouse
1024 // if there is a local selection in the current buffer,
1026 if (cmd.button() == mouse_button::button2) {
1027 if (cap::selection()) {
1028 // Copy the selection buffer to the clipboard
1029 // stack, because we want it to appear in the
1030 // "Edit->Paste recent" menu.
1031 cap::copySelectionToStack();
1033 cap::pasteSelection(bv->cursor(),
1034 bv->buffer().errorList("Paste"));
1035 bv->buffer().errors("Paste");
1036 bv->buffer().markDirty();
1039 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
1043 // we have to update after dEPM triggered
1044 if (!update && cmd.button() == mouse_button::button1) {
1045 needsUpdate = false;
1052 case LFUN_MOUSE_MOTION: {
1053 // Only use motion with button 1
1054 //if (cmd.button() != mouse_button::button1)
1057 // ignore motions deeper nested than the real anchor
1058 Cursor & bvcur = cur.bv().cursor();
1059 if (bvcur.anchor_.hasPart(cur)) {
1060 CursorSlice old = bvcur.top();
1062 int const wh = bv->workHeight();
1063 int const y = std::max(0, std::min(wh - 1, cmd.y));
1065 setCursorFromCoordinates(cur, cmd.x, y);
1066 cur.setTargetX(cmd.x);
1068 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1070 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1071 // This is to allow jumping over large insets
1072 if (cur.top() == old) {
1074 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1076 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1079 if (cur.top() == old)
1082 // don't set anchor_
1083 bvcur.setCursor(cur);
1084 bvcur.selection() = true;
1085 //lyxerr << "MOTION: " << bv->cursor() << endl;
1093 case LFUN_MOUSE_RELEASE: {
1094 if (cmd.button() == mouse_button::button2)
1097 if (cmd.button() == mouse_button::button1) {
1098 // if there is new selection, update persistent
1099 // selection, otherwise, single click does not
1100 // clear persistent selection buffer
1101 if (cur.selection()) {
1103 // if double click, cur is moved to the end of word by selectWord
1104 // but bvcur is current mouse position
1105 Cursor & bvcur = cur.bv().cursor();
1106 bvcur.selection() = true;
1108 needsUpdate = false;
1115 case LFUN_SELF_INSERT: {
1116 if (cmd.argument().empty())
1119 // Automatically delete the currently selected
1120 // text and replace it with what is being
1121 // typed in now. Depends on lyxrc settings
1122 // "auto_region_delete", which defaults to
1125 if (lyxrc.auto_region_delete && cur.selection()) {
1126 cutSelection(cur, false, false);
1127 // When change tracking is set to off, the metrics update
1128 // mechanism correctly detects if a full update is needed or not.
1129 // This detection fails when a selection spans multiple rows and
1130 // change tracking is enabled because the paragraph metrics stays
1131 // the same. In this case, we force the full update:
1132 // (see http://bugzilla.lyx.org/show_bug.cgi?id=3992)
1133 if (cur.buffer().params().trackChanges)
1134 cur.updateFlags(Update::Force);
1137 cur.clearSelection();
1138 Font const old_font = real_current_font;
1140 docstring::const_iterator cit = cmd.argument().begin();
1141 docstring::const_iterator end = cmd.argument().end();
1142 for (; cit != end; ++cit)
1143 bv->translateAndInsert(*cit, this, cur);
1146 moveCursor(cur, false);
1150 case LFUN_URL_INSERT: {
1151 InsetCommandParams p("url");
1153 if (cur.selection()) {
1154 content = cur.selectionAsString(false);
1155 cutSelection(cur, true, false);
1157 p["target"] = (cmd.argument().empty()) ?
1158 content : cmd.argument();
1159 string const data = InsetCommandMailer::params2string("url", p);
1160 if (p["target"].empty()) {
1161 bv->showInsetDialog("url", data, 0);
1163 FuncRequest fr(LFUN_INSET_INSERT, data);
1169 case LFUN_HTML_INSERT: {
1170 InsetCommandParams p("htmlurl");
1172 if (cur.selection()) {
1173 content = cur.selectionAsString(false);
1174 cutSelection(cur, true, false);
1176 p["target"] = (cmd.argument().empty()) ?
1177 content : cmd.argument();
1178 string const data = InsetCommandMailer::params2string("url", p);
1179 if (p["target"].empty()) {
1180 bv->showInsetDialog("url", data, 0);
1182 FuncRequest fr(LFUN_INSET_INSERT, data);
1188 case LFUN_LABEL_INSERT: {
1189 InsetCommandParams p("label");
1190 // Try to generate a valid label
1191 p["name"] = (cmd.argument().empty()) ?
1192 cur.getPossibleLabel() :
1194 string const data = InsetCommandMailer::params2string("label", p);
1196 if (cmd.argument().empty()) {
1197 bv->showInsetDialog("label", data, 0);
1199 FuncRequest fr(LFUN_INSET_INSERT, data);
1207 case LFUN_LIST_INSERT:
1208 case LFUN_THEOREM_INSERT:
1210 case LFUN_CAPTION_INSERT:
1211 // Open the inset, and move the current selection
1213 doInsertInset(cur, this, cmd, true, true);
1215 updateLabels(bv->buffer());
1217 case LFUN_NOTE_INSERT:
1218 case LFUN_CHARSTYLE_INSERT:
1219 case LFUN_BOX_INSERT:
1220 case LFUN_BRANCH_INSERT:
1221 case LFUN_BIBITEM_INSERT:
1222 case LFUN_ERT_INSERT:
1223 case LFUN_LISTING_INSERT:
1224 case LFUN_FOOTNOTE_INSERT:
1225 case LFUN_MARGINALNOTE_INSERT:
1226 case LFUN_OPTIONAL_INSERT:
1227 case LFUN_ENVIRONMENT_INSERT:
1228 // Open the inset, and move the current selection
1230 doInsertInset(cur, this, cmd, true, true);
1234 case LFUN_TABULAR_INSERT:
1235 // if there were no arguments, just open the dialog
1236 if (doInsertInset(cur, this, cmd, false, true))
1239 bv->showDialog("tabularcreate");
1243 case LFUN_FLOAT_INSERT:
1244 case LFUN_FLOAT_WIDE_INSERT:
1245 case LFUN_WRAP_INSERT: {
1246 bool content = cur.selection(); // will some text be moved into the inset?
1248 doInsertInset(cur, this, cmd, true, true);
1250 ParagraphList & pars = cur.text()->paragraphs();
1252 TextClass const & tclass = bv->buffer().params().getTextClass();
1254 // add a separate paragraph for the caption inset
1255 pars.push_back(Paragraph());
1256 pars.back().setInsetOwner(pars[0].inInset());
1257 pars.back().layout(tclass.defaultLayout());
1259 int cap_pit = pars.size() - 1;
1261 // if an empty inset was created, we create an additional empty
1262 // paragraph at the bottom so that the user can choose where to put
1263 // the graphics (or table).
1265 pars.push_back(Paragraph());
1266 pars.back().setInsetOwner(pars[0].inInset());
1267 pars.back().layout(tclass.defaultLayout());
1271 // reposition the cursor to the caption
1272 cur.pit() = cap_pit;
1274 // FIXME: This Text/Cursor dispatch handling is a mess!
1275 // We cannot use Cursor::dispatch here it needs access to up to
1277 FuncRequest cmd_caption(LFUN_CAPTION_INSERT);
1278 cur.text()->dispatch(cur, cmd_caption);
1279 cur.updateFlags(Update::Force);
1280 // FIXME: When leaving the Float (or Wrap) inset we should
1281 // delete any empty paragraph left above or below the
1286 case LFUN_INDEX_INSERT:
1287 case LFUN_NOMENCL_INSERT: {
1288 Inset * inset = createInset(&cur.bv(), cmd);
1292 cur.clearSelection();
1293 insertInset(cur, inset);
1294 inset->edit(cur, true);
1295 // Show the dialog for the nomenclature entry, since the
1296 // description entry still needs to be filled in.
1297 if (cmd.action == LFUN_NOMENCL_INSERT)
1298 InsetCommandMailer("nomenclature",
1299 *reinterpret_cast<InsetCommand *>(inset)).showDialog(&cur.bv());
1304 case LFUN_INDEX_PRINT:
1305 case LFUN_NOMENCL_PRINT:
1306 case LFUN_TOC_INSERT:
1307 case LFUN_HFILL_INSERT:
1308 case LFUN_LINE_INSERT:
1309 case LFUN_PAGEBREAK_INSERT:
1310 case LFUN_CLEARPAGE_INSERT:
1311 case LFUN_CLEARDOUBLEPAGE_INSERT:
1313 doInsertInset(cur, this, cmd, false, false);
1317 case LFUN_DEPTH_DECREMENT:
1318 changeDepth(cur, DEC_DEPTH);
1321 case LFUN_DEPTH_INCREMENT:
1322 changeDepth(cur, INC_DEPTH);
1325 case LFUN_MATH_DISPLAY:
1326 mathDispatch(cur, cmd, true);
1329 case LFUN_MATH_IMPORT_SELECTION:
1330 case LFUN_MATH_MODE:
1331 if (cmd.argument() == "on")
1332 // don't pass "on" as argument
1333 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1335 mathDispatch(cur, cmd, false);
1338 case LFUN_MATH_MACRO:
1339 if (cmd.argument().empty())
1340 cur.errorMessage(from_utf8(N_("Missing argument")));
1342 string s = to_utf8(cmd.argument());
1343 string const s1 = token(s, ' ', 1);
1344 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1345 string const s2 = token(s, ' ', 2);
1346 string const type = s2.empty() ? "newcommand" : s2;
1347 cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, from_utf8(type)));
1348 //cur.nextInset()->edit(cur, true);
1352 // passthrough hat and underscore outside mathed:
1353 case LFUN_MATH_SUBSCRIPT:
1354 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1356 case LFUN_MATH_SUPERSCRIPT:
1357 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1360 case LFUN_MATH_INSERT:
1361 case LFUN_MATH_MATRIX:
1362 case LFUN_MATH_DELIM:
1363 case LFUN_MATH_BIGDELIM: {
1364 if (cur.selection())
1365 cur.clearSelection();
1366 // FIXME: instead of the above, this one
1367 // should be used (but it asserts with Bidi enabled)
1368 // cf. http://bugzilla.lyx.org/show_bug.cgi?id=4055
1369 // cap::replaceSelection(cur);
1370 cur.insert(new InsetMathHull(hullSimple));
1371 checkAndActivateInset(cur, true);
1372 BOOST_ASSERT(cur.inMathed());
1377 case LFUN_FONT_EMPH: {
1378 Font font(Font::ALL_IGNORE);
1379 font.setEmph(Font::TOGGLE);
1380 toggleAndShow(cur, this, font);
1384 case LFUN_FONT_BOLD: {
1385 Font font(Font::ALL_IGNORE);
1386 font.setSeries(Font::BOLD_SERIES);
1387 toggleAndShow(cur, this, font);
1391 case LFUN_FONT_NOUN: {
1392 Font font(Font::ALL_IGNORE);
1393 font.setNoun(Font::TOGGLE);
1394 toggleAndShow(cur, this, font);
1398 case LFUN_FONT_CODE: {
1399 Font font(Font::ALL_IGNORE);
1400 font.setFamily(Font::TYPEWRITER_FAMILY); // no good
1401 toggleAndShow(cur, this, font);
1405 case LFUN_FONT_SANS: {
1406 Font font(Font::ALL_IGNORE);
1407 font.setFamily(Font::SANS_FAMILY);
1408 toggleAndShow(cur, this, font);
1412 case LFUN_FONT_ROMAN: {
1413 Font font(Font::ALL_IGNORE);
1414 font.setFamily(Font::ROMAN_FAMILY);
1415 toggleAndShow(cur, this, font);
1419 case LFUN_FONT_DEFAULT: {
1420 Font font(Font::ALL_INHERIT, ignore_language);
1421 toggleAndShow(cur, this, font);
1425 case LFUN_FONT_UNDERLINE: {
1426 Font font(Font::ALL_IGNORE);
1427 font.setUnderbar(Font::TOGGLE);
1428 toggleAndShow(cur, this, font);
1432 case LFUN_FONT_SIZE: {
1433 Font font(Font::ALL_IGNORE);
1434 font.setLyXSize(to_utf8(cmd.argument()));
1435 toggleAndShow(cur, this, font);
1439 case LFUN_LANGUAGE: {
1440 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1443 Font font(Font::ALL_IGNORE);
1444 font.setLanguage(lang);
1445 toggleAndShow(cur, this, font);
1449 case LFUN_FONT_FREE_APPLY:
1450 toggleAndShow(cur, this, freefont, toggleall);
1451 cur.message(_("Character set"));
1454 // Set the freefont using the contents of \param data dispatched from
1455 // the frontends and apply it at the current cursor location.
1456 case LFUN_FONT_FREE_UPDATE: {
1459 if (bv_funcs::string2font(to_utf8(cmd.argument()), font, toggle)) {
1462 toggleAndShow(cur, this, freefont, toggleall);
1463 cur.message(_("Character set"));
1468 case LFUN_FINISHED_LEFT:
1469 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1470 if (reverseDirectionNeeded(cur))
1474 case LFUN_FINISHED_RIGHT:
1475 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1476 if (!reverseDirectionNeeded(cur))
1480 case LFUN_LAYOUT_PARAGRAPH: {
1482 params2string(cur.paragraph(), data);
1483 data = "show\n" + data;
1484 bv->showDialogWithData("paragraph", data);
1488 case LFUN_PARAGRAPH_UPDATE: {
1490 params2string(cur.paragraph(), data);
1492 // Will the paragraph accept changes from the dialog?
1493 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1495 data = "update " + convert<string>(accept) + '\n' + data;
1496 bv->updateDialog("paragraph", data);
1500 case LFUN_ACCENT_UMLAUT:
1501 case LFUN_ACCENT_CIRCUMFLEX:
1502 case LFUN_ACCENT_GRAVE:
1503 case LFUN_ACCENT_ACUTE:
1504 case LFUN_ACCENT_TILDE:
1505 case LFUN_ACCENT_CEDILLA:
1506 case LFUN_ACCENT_MACRON:
1507 case LFUN_ACCENT_DOT:
1508 case LFUN_ACCENT_UNDERDOT:
1509 case LFUN_ACCENT_UNDERBAR:
1510 case LFUN_ACCENT_CARON:
1511 case LFUN_ACCENT_SPECIAL_CARON:
1512 case LFUN_ACCENT_BREVE:
1513 case LFUN_ACCENT_TIE:
1514 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1515 case LFUN_ACCENT_CIRCLE:
1516 case LFUN_ACCENT_OGONEK:
1517 theLyXFunc().handleKeyFunc(cmd.action);
1518 if (!cmd.argument().empty())
1519 // FIXME: Are all these characters encoded in one byte in utf8?
1520 bv->translateAndInsert(cmd.argument()[0], this, cur);
1523 case LFUN_FLOAT_LIST: {
1524 TextClass const & tclass = bv->buffer().params().getTextClass();
1525 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1527 if (cur.selection())
1528 cutSelection(cur, true, false);
1529 breakParagraph(cur);
1531 if (cur.lastpos() != 0) {
1533 breakParagraph(cur);
1536 setLayout(cur, tclass.defaultLayoutName());
1537 ParagraphParameters p;
1538 setParagraphs(cur, p);
1539 insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1542 lyxerr << "Non-existent float type: "
1543 << to_utf8(cmd.argument()) << endl;
1548 case LFUN_CHANGE_ACCEPT: {
1549 acceptOrRejectChanges(cur, ACCEPT);
1553 case LFUN_CHANGE_REJECT: {
1554 acceptOrRejectChanges(cur, REJECT);
1558 case LFUN_THESAURUS_ENTRY: {
1559 docstring arg = cmd.argument();
1561 arg = cur.selectionAsString(false);
1563 if (arg.size() > 100 || arg.empty()) {
1564 // Get word or selection
1565 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1566 arg = cur.selectionAsString(false);
1569 bv->showDialogWithData("thesaurus", to_utf8(arg));
1573 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1574 // Given data, an encoding of the ParagraphParameters
1575 // generated in the Paragraph dialog, this function sets
1576 // the current paragraph, or currently selected paragraphs,
1578 // NOTE: This function overrides all existing settings.
1579 setParagraphs(cur, cmd.argument());
1580 cur.message(_("Paragraph layout set"));
1584 case LFUN_PARAGRAPH_PARAMS: {
1585 // Given data, an encoding of the ParagraphParameters as we'd
1586 // find them in a LyX file, this function modifies the current paragraph,
1587 // or currently selected paragraphs.
1588 // NOTE: This function only modifies, and does not override, existing
1590 setParagraphs(cur, cmd.argument(), true);
1591 cur.message(_("Paragraph layout set"));
1596 if (cur.selection()) {
1597 cur.selection() = false;
1600 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1605 LYXERR(Debug::ACTION)
1606 << BOOST_CURRENT_FUNCTION
1607 << ": Command " << cmd
1608 << " not DISPATCHED by Text" << endl;
1613 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1615 // FIXME: The cursor flag is reset two lines below
1616 // so we need to check here if some of the LFUN did touch that.
1617 // for now only Text::erase() and Text::backspace() do that.
1618 // The plan is to verify all the LFUNs and then to remove this
1619 // singleParUpdate boolean altogether.
1620 if (cur.result().update() & Update::Force) {
1621 singleParUpdate = false;
1625 // FIXME: the following code should go in favor of fine grained
1626 // update flag treatment.
1627 if (singleParUpdate) {
1628 // Inserting characters does not change par height
1629 ParagraphMetrics const & pms
1630 = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
1631 if (pms.dim().height()
1632 == olddim.height()) {
1633 // if so, update _only_ this paragraph
1634 cur.updateFlags(Update::SinglePar |
1636 Update::MultiParSel);
1643 && &oldTopSlice.inset() == &cur.inset()
1644 && oldTopSlice.idx() == cur.idx()
1645 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1646 && !cur.selection())
1647 // FIXME: it would be better if we could just do this
1649 //if (cur.result().update() != Update::FitCursor)
1652 // But some LFUNs do not set Update::FitCursor when needed, so we
1653 // do it for all. This is not very harmfull as FitCursor will provoke
1654 // a full redraw only if needed but still, a proper review of all LFUN
1655 // should be done and this needsUpdate boolean can then be removed.
1656 cur.updateFlags(Update::FitCursor);
1658 cur.updateFlags(Update::Force | Update::FitCursor);
1662 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
1663 FuncStatus & flag) const
1665 BOOST_ASSERT(cur.text() == this);
1667 Font const & font = real_current_font;
1669 Inset::Code code = Inset::NO_CODE;
1671 switch (cmd.action) {
1673 case LFUN_DEPTH_DECREMENT:
1674 enable = changeDepthAllowed(cur, DEC_DEPTH);
1677 case LFUN_DEPTH_INCREMENT:
1678 enable = changeDepthAllowed(cur, INC_DEPTH);
1682 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1685 case LFUN_BIBITEM_INSERT:
1686 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO
1690 case LFUN_DIALOG_SHOW_NEW_INSET:
1691 if (cmd.argument() == "bibitem")
1692 code = Inset::BIBITEM_CODE;
1693 else if (cmd.argument() == "bibtex")
1694 code = Inset::BIBTEX_CODE;
1695 else if (cmd.argument() == "box")
1696 code = Inset::BOX_CODE;
1697 else if (cmd.argument() == "branch")
1698 code = Inset::BRANCH_CODE;
1699 else if (cmd.argument() == "citation")
1700 code = Inset::CITE_CODE;
1701 else if (cmd.argument() == "ert")
1702 code = Inset::ERT_CODE;
1703 else if (cmd.argument() == "external")
1704 code = Inset::EXTERNAL_CODE;
1705 else if (cmd.argument() == "float")
1706 code = Inset::FLOAT_CODE;
1707 else if (cmd.argument() == "graphics")
1708 code = Inset::GRAPHICS_CODE;
1709 else if (cmd.argument() == "include")
1710 code = Inset::INCLUDE_CODE;
1711 else if (cmd.argument() == "index")
1712 code = Inset::INDEX_CODE;
1713 else if (cmd.argument() == "nomenclature")
1714 code = Inset::NOMENCL_CODE;
1715 else if (cmd.argument() == "label")
1716 code = Inset::LABEL_CODE;
1717 else if (cmd.argument() == "note")
1718 code = Inset::NOTE_CODE;
1719 else if (cmd.argument() == "ref")
1720 code = Inset::REF_CODE;
1721 else if (cmd.argument() == "toc")
1722 code = Inset::TOC_CODE;
1723 else if (cmd.argument() == "url")
1724 code = Inset::URL_CODE;
1725 else if (cmd.argument() == "vspace")
1726 code = Inset::VSPACE_CODE;
1727 else if (cmd.argument() == "wrap")
1728 code = Inset::WRAP_CODE;
1729 else if (cmd.argument() == "listings")
1730 code = Inset::LISTINGS_CODE;
1733 case LFUN_ERT_INSERT:
1734 code = Inset::ERT_CODE;
1736 case LFUN_LISTING_INSERT:
1737 code = Inset::LISTINGS_CODE;
1739 case LFUN_FOOTNOTE_INSERT:
1740 code = Inset::FOOT_CODE;
1742 case LFUN_TABULAR_INSERT:
1743 code = Inset::TABULAR_CODE;
1745 case LFUN_MARGINALNOTE_INSERT:
1746 code = Inset::MARGIN_CODE;
1748 case LFUN_FLOAT_INSERT:
1749 case LFUN_FLOAT_WIDE_INSERT:
1750 code = Inset::FLOAT_CODE;
1752 case LFUN_WRAP_INSERT:
1753 code = Inset::WRAP_CODE;
1755 case LFUN_FLOAT_LIST:
1756 code = Inset::FLOAT_LIST_CODE;
1759 case LFUN_LIST_INSERT:
1760 code = Inset::LIST_CODE;
1762 case LFUN_THEOREM_INSERT:
1763 code = Inset::THEOREM_CODE;
1766 case LFUN_CAPTION_INSERT:
1767 code = Inset::CAPTION_CODE;
1769 case LFUN_NOTE_INSERT:
1770 code = Inset::NOTE_CODE;
1772 case LFUN_CHARSTYLE_INSERT:
1773 code = Inset::CHARSTYLE_CODE;
1774 if (cur.buffer().params().getTextClass().insetlayouts().empty())
1777 case LFUN_BOX_INSERT:
1778 code = Inset::BOX_CODE;
1780 case LFUN_BRANCH_INSERT:
1781 code = Inset::BRANCH_CODE;
1782 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1785 case LFUN_LABEL_INSERT:
1786 code = Inset::LABEL_CODE;
1788 case LFUN_OPTIONAL_INSERT:
1789 code = Inset::OPTARG_CODE;
1790 enable = numberOfOptArgs(cur.paragraph())
1791 < cur.paragraph().layout()->optionalargs;
1793 case LFUN_ENVIRONMENT_INSERT:
1794 code = Inset::BOX_CODE;
1796 case LFUN_INDEX_INSERT:
1797 code = Inset::INDEX_CODE;
1799 case LFUN_INDEX_PRINT:
1800 code = Inset::INDEX_PRINT_CODE;
1802 case LFUN_NOMENCL_INSERT:
1803 code = Inset::NOMENCL_CODE;
1805 case LFUN_NOMENCL_PRINT:
1806 code = Inset::NOMENCL_PRINT_CODE;
1808 case LFUN_TOC_INSERT:
1809 code = Inset::TOC_CODE;
1811 case LFUN_HTML_INSERT:
1812 case LFUN_URL_INSERT:
1813 code = Inset::URL_CODE;
1815 case LFUN_QUOTE_INSERT:
1816 // always allow this, since we will inset a raw quote
1817 // if an inset is not allowed.
1819 case LFUN_HYPHENATION_POINT_INSERT:
1820 case LFUN_LIGATURE_BREAK_INSERT:
1821 case LFUN_HFILL_INSERT:
1822 case LFUN_MENU_SEPARATOR_INSERT:
1823 case LFUN_DOTS_INSERT:
1824 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
1825 code = Inset::SPECIALCHAR_CODE;
1827 case LFUN_SPACE_INSERT:
1828 // slight hack: we know this is allowed in math mode
1830 code = Inset::SPACE_CODE;
1833 case LFUN_INSET_MODIFY:
1834 // We need to disable this, because we may get called for a
1836 // InsetTabular::getStatus() -> InsetText::getStatus()
1837 // and we don't handle LFUN_INSET_MODIFY.
1841 case LFUN_FONT_EMPH:
1842 flag.setOnOff(font.emph() == Font::ON);
1845 case LFUN_FONT_NOUN:
1846 flag.setOnOff(font.noun() == Font::ON);
1849 case LFUN_FONT_BOLD:
1850 flag.setOnOff(font.series() == Font::BOLD_SERIES);
1853 case LFUN_FONT_SANS:
1854 flag.setOnOff(font.family() == Font::SANS_FAMILY);
1857 case LFUN_FONT_ROMAN:
1858 flag.setOnOff(font.family() == Font::ROMAN_FAMILY);
1861 case LFUN_FONT_CODE:
1862 flag.setOnOff(font.family() == Font::TYPEWRITER_FAMILY);
1867 enable = cur.selection();
1871 if (cmd.argument().empty()) {
1872 if (theClipboard().isInternal())
1873 enable = cap::numberOfSelections() > 0;
1875 enable = !theClipboard().empty();
1877 string const arg = to_utf8(cmd.argument());
1878 if (isStrUnsignedInt(arg)) {
1879 unsigned int n = convert<unsigned int>(arg);
1880 enable = cap::numberOfSelections() > n;
1887 case LFUN_CLIPBOARD_PASTE:
1888 enable = !theClipboard().empty();
1891 case LFUN_PRIMARY_SELECTION_PASTE:
1892 enable = cur.selection() || !theSelection().empty();
1895 case LFUN_PARAGRAPH_MOVE_UP:
1896 enable = cur.pit() > 0 && !cur.selection();
1899 case LFUN_PARAGRAPH_MOVE_DOWN:
1900 enable = cur.pit() < cur.lastpit() && !cur.selection();
1903 case LFUN_INSET_DISSOLVE:
1904 enable = !isMainText(cur.bv().buffer()) && cur.inset().nargs() == 1;
1907 case LFUN_CHANGE_ACCEPT:
1908 case LFUN_CHANGE_REJECT:
1909 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
1910 // In principle, these LFUNs should only be enabled if there
1911 // is a change at the current position/in the current selection.
1912 // However, without proper optimizations, this will inevitably
1913 // result in unacceptable performance - just imagine a user who
1914 // wants to select the complete content of a long document.
1918 case LFUN_WORD_DELETE_FORWARD:
1919 case LFUN_WORD_DELETE_BACKWARD:
1920 case LFUN_LINE_DELETE:
1921 case LFUN_WORD_FORWARD:
1922 case LFUN_WORD_BACKWARD:
1923 case LFUN_CHAR_FORWARD:
1924 case LFUN_CHAR_FORWARD_SELECT:
1925 case LFUN_CHAR_BACKWARD:
1926 case LFUN_CHAR_BACKWARD_SELECT:
1928 case LFUN_UP_SELECT:
1930 case LFUN_DOWN_SELECT:
1931 case LFUN_PARAGRAPH_UP_SELECT:
1932 case LFUN_PARAGRAPH_DOWN_SELECT:
1933 case LFUN_SCREEN_UP_SELECT:
1934 case LFUN_SCREEN_DOWN_SELECT:
1935 case LFUN_LINE_BEGIN_SELECT:
1936 case LFUN_LINE_END_SELECT:
1937 case LFUN_WORD_FORWARD_SELECT:
1938 case LFUN_WORD_BACKWARD_SELECT:
1939 case LFUN_WORD_SELECT:
1940 case LFUN_PARAGRAPH_UP:
1941 case LFUN_PARAGRAPH_DOWN:
1942 case LFUN_SCREEN_UP:
1943 case LFUN_SCREEN_DOWN:
1944 case LFUN_LINE_BEGIN:
1946 case LFUN_BREAK_LINE:
1947 case LFUN_CHAR_DELETE_FORWARD:
1948 case LFUN_DELETE_FORWARD_SKIP:
1949 case LFUN_CHAR_DELETE_BACKWARD:
1950 case LFUN_DELETE_BACKWARD_SKIP:
1951 case LFUN_BREAK_PARAGRAPH:
1952 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
1953 case LFUN_BREAK_PARAGRAPH_SKIP:
1954 case LFUN_PARAGRAPH_SPACING:
1955 case LFUN_INSET_INSERT:
1956 case LFUN_WORD_UPCASE:
1957 case LFUN_WORD_LOWCASE:
1958 case LFUN_WORD_CAPITALIZE:
1959 case LFUN_CHARS_TRANSPOSE:
1960 case LFUN_SERVER_GET_XY:
1961 case LFUN_SERVER_SET_XY:
1962 case LFUN_SERVER_GET_FONT:
1963 case LFUN_SERVER_GET_LAYOUT:
1965 case LFUN_DATE_INSERT:
1966 case LFUN_SELF_INSERT:
1967 case LFUN_LINE_INSERT:
1968 case LFUN_PAGEBREAK_INSERT:
1969 case LFUN_CLEARPAGE_INSERT:
1970 case LFUN_CLEARDOUBLEPAGE_INSERT:
1971 case LFUN_MATH_DISPLAY:
1972 case LFUN_MATH_IMPORT_SELECTION:
1973 case LFUN_MATH_MODE:
1974 case LFUN_MATH_MACRO:
1975 case LFUN_MATH_MATRIX:
1976 case LFUN_MATH_DELIM:
1977 case LFUN_MATH_BIGDELIM:
1978 case LFUN_MATH_INSERT:
1979 case LFUN_MATH_SUBSCRIPT:
1980 case LFUN_MATH_SUPERSCRIPT:
1981 case LFUN_FONT_DEFAULT:
1982 case LFUN_FONT_UNDERLINE:
1983 case LFUN_FONT_SIZE:
1985 case LFUN_FONT_FREE_APPLY:
1986 case LFUN_FONT_FREE_UPDATE:
1987 case LFUN_LAYOUT_PARAGRAPH:
1988 case LFUN_PARAGRAPH_UPDATE:
1989 case LFUN_ACCENT_UMLAUT:
1990 case LFUN_ACCENT_CIRCUMFLEX:
1991 case LFUN_ACCENT_GRAVE:
1992 case LFUN_ACCENT_ACUTE:
1993 case LFUN_ACCENT_TILDE:
1994 case LFUN_ACCENT_CEDILLA:
1995 case LFUN_ACCENT_MACRON:
1996 case LFUN_ACCENT_DOT:
1997 case LFUN_ACCENT_UNDERDOT:
1998 case LFUN_ACCENT_UNDERBAR:
1999 case LFUN_ACCENT_CARON:
2000 case LFUN_ACCENT_SPECIAL_CARON:
2001 case LFUN_ACCENT_BREVE:
2002 case LFUN_ACCENT_TIE:
2003 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
2004 case LFUN_ACCENT_CIRCLE:
2005 case LFUN_ACCENT_OGONEK:
2006 case LFUN_THESAURUS_ENTRY:
2007 case LFUN_PARAGRAPH_PARAMS_APPLY:
2008 case LFUN_PARAGRAPH_PARAMS:
2010 case LFUN_BUFFER_END:
2011 case LFUN_BUFFER_BEGIN:
2012 case LFUN_BUFFER_BEGIN_SELECT:
2013 case LFUN_BUFFER_END_SELECT:
2014 case LFUN_UNICODE_INSERT:
2015 // these are handled in our dispatch()
2023 if (code != Inset::NO_CODE
2024 && (cur.empty() || !cur.inset().insetAllowed(code)))
2027 flag.enabled(enable);
2032 void Text::pasteString(Cursor & cur, docstring const & clip,
2035 cur.clearSelection();
2036 if (!clip.empty()) {
2039 insertStringAsParagraphs(cur, clip);
2041 insertStringAsLines(cur, clip);