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.
21 #include "BranchList.h"
22 #include "FloatList.h"
23 #include "FuncStatus.h"
25 #include "buffer_funcs.h"
26 #include "BufferParams.h"
27 #include "BufferView.h"
29 #include "CutAndPaste.h"
31 #include "DispatchResult.h"
32 #include "ErrorList.h"
34 #include "FuncRequest.h"
36 #include "InsetList.h"
40 #include "LyXAction.h"
44 #include "Paragraph.h"
45 #include "paragraph_funcs.h"
46 #include "ParagraphParameters.h"
47 #include "TextMetrics.h"
49 #include "ParIterator.h"
51 #include "frontends/Clipboard.h"
52 #include "frontends/Selection.h"
54 #include "insets/InsetCollapsable.h"
55 #include "insets/InsetCommand.h"
56 #include "insets/InsetFloatList.h"
57 #include "insets/InsetNewline.h"
58 #include "insets/InsetQuotes.h"
59 #include "insets/InsetSpecialChar.h"
60 #include "insets/InsetText.h"
61 #include "insets/InsetInfo.h"
63 #include "support/lstrings.h"
64 #include "support/lyxlib.h"
65 #include "support/convert.h"
66 #include "support/lyxtime.h"
68 #include "mathed/InsetMathHull.h"
69 #include "mathed/MathMacroTemplate.h"
71 #include <boost/current_function.hpp>
78 using std::istringstream;
79 using std::ostringstream;
83 using cap::copySelection;
84 using cap::cutSelection;
85 using cap::pasteFromStack;
86 using cap::pasteClipboard;
87 using cap::replaceSelection;
89 using support::isStrUnsignedInt;
93 static Font freefont(Font::ALL_IGNORE);
94 static bool toggleall = false;
96 static void toggleAndShow(Cursor & cur, Text * text,
97 Font const & font, bool toggleall = true)
99 text->toggleFree(cur, font, toggleall);
101 if (font.language() != ignore_language ||
102 font.number() != Font::IGNORE) {
103 TextMetrics const & tm = cur.bv().textMetrics(text);
104 if (cur.boundary() != tm.isRTLBoundary(cur.pit(),
105 cur.pos(), cur.real_current_font))
106 text->setCursor(cur, cur.pit(), cur.pos(),
107 false, !cur.boundary());
112 static void moveCursor(Cursor & cur, bool selecting)
114 if (selecting || cur.mark())
119 static void finishChange(Cursor & cur, bool selecting)
122 moveCursor(cur, selecting);
126 static void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
129 docstring sel = cur.selectionAsString(false);
131 // It may happen that sel is empty but there is a selection
132 replaceSelection(cur);
135 #ifdef ENABLE_ASSERTIONS
136 const int old_pos = cur.pos();
138 cur.insert(new InsetMathHull(hullSimple));
139 BOOST_ASSERT(old_pos == cur.pos());
140 cur.nextInset()->edit(cur, true);
141 // don't do that also for LFUN_MATH_MODE
142 // unless you want end up with always changing
143 // to mathrm when opening an inlined inset --
144 // I really hate "LyXfunc overloading"...
146 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
147 // Avoid an unnecessary undo step if cmd.argument
149 if (!cmd.argument().empty())
150 cur.dispatch(FuncRequest(LFUN_MATH_INSERT,
153 // create a macro if we see "\\newcommand"
154 // somewhere, and an ordinary formula
156 if (sel.find(from_ascii("\\newcommand")) == string::npos
157 && sel.find(from_ascii("\\def")) == string::npos)
159 InsetMathHull * formula = new InsetMathHull;
160 istringstream is(to_utf8(sel));
163 formula->read(cur.buffer(), lex);
164 if (formula->getType() == hullNone)
165 // Don't create pseudo formulas if
166 // delimiters are left out
167 formula->mutate(hullSimple);
170 cur.insert(new MathMacroTemplate(sel));
173 cur.message(from_utf8(N_("Math editor mode")));
177 static void specialChar(Cursor & cur, InsetSpecialChar::Kind kind)
180 cap::replaceSelection(cur);
181 cur.insert(new InsetSpecialChar(kind));
186 static bool doInsertInset(Cursor & cur, Text * text,
187 FuncRequest const & cmd, bool edit, bool pastesel)
189 Inset * inset = createInset(&cur.bv(), cmd);
194 if (cmd.action == LFUN_INDEX_INSERT) {
195 docstring ds = support::subst(text->getStringToIndex(cur), '\n', ' ');
196 text->insertInset(cur, inset);
198 inset->edit(cur, true);
199 // Now put this into inset
200 static_cast<InsetCollapsable *>(inset)->text_.insertStringAsParagraphs(cur, ds);
203 if (cur.selection()) {
204 lyx::dispatch(FuncRequest(LFUN_CUT));
207 text->insertInset(cur, inset);
210 inset->edit(cur, true);
212 if (gotsel && pastesel) {
213 lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
214 InsetText * insetText = dynamic_cast<InsetText *>(inset);
215 if (insetText && !insetText->allowMultiPar()
216 || cur.lastpit() == 0) {
217 // reset first par to default
218 LayoutPtr const layout =
219 cur.buffer().params().getTextClass().defaultLayout();
220 cur.text()->paragraphs().begin()->layout(layout);
223 // Merge multiple paragraphs -- hack
224 while (cur.lastpit() > 0) {
225 mergeParagraph(cur.buffer().params(),
226 cur.text()->paragraphs(), 0);
229 // reset surrounding par to default
230 docstring const layoutname =
231 cur.buffer().params().getTextClass().defaultLayoutName();
232 cur.leaveInset(*inset);
233 text->setLayout(cur, layoutname);
241 string const freefont2string()
243 return freefont.toString(toggleall);
247 void Text::number(Cursor & cur)
249 Font font(Font::ALL_IGNORE);
250 font.setNumber(Font::TOGGLE);
251 toggleAndShow(cur, this, font);
255 bool Text::isRTL(Buffer const & buffer, Paragraph const & par) const
257 return par.isRTL(buffer.params());
261 void Text::dispatch(Cursor & cur, FuncRequest & cmd)
263 LYXERR(Debug::ACTION) << "Text::dispatch: cmd: " << cmd << endl;
265 // FIXME: We use the update flag to indicates wether a singlePar or a
266 // full screen update is needed. We reset it here but shall we restore it
270 BOOST_ASSERT(cur.text() == this);
271 BufferView * bv = &cur.bv();
272 TextMetrics & tm = cur.bv().textMetrics(this);
273 CursorSlice oldTopSlice = cur.top();
274 bool oldBoundary = cur.boundary();
275 bool sel = cur.selection();
276 // Signals that, even if needsUpdate == false, an update of the
277 // cursor paragraph is required
278 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
279 LyXAction::SingleParUpdate);
280 // Signals that a full-screen update is required
281 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
282 LyXAction::NoUpdate) || singleParUpdate);
283 // Remember the old paragraph metric (_outer_ paragraph!)
284 ParagraphMetrics const & pm = cur.bv().parMetrics(
285 cur.bottom().text(), cur.bottom().pit());
286 Dimension olddim = pm.dim();
288 switch (cmd.action) {
290 case LFUN_PARAGRAPH_MOVE_DOWN: {
291 pit_type const pit = cur.pit();
292 recUndo(cur, pit, pit + 1);
294 std::swap(pars_[pit], pars_[pit + 1]);
295 updateLabels(cur.buffer());
301 case LFUN_PARAGRAPH_MOVE_UP: {
302 pit_type const pit = cur.pit();
303 recUndo(cur, pit - 1, pit);
305 std::swap(pars_[pit], pars_[pit - 1]);
306 updateLabels(cur.buffer());
312 case LFUN_APPENDIX: {
313 Paragraph & par = cur.paragraph();
314 bool start = !par.params().startOfAppendix();
316 // FIXME: The code below only makes sense at top level.
317 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
318 // ensure that we have only one start_of_appendix in this document
319 // FIXME: this don't work for multipart document!
320 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
321 if (pars_[tmp].params().startOfAppendix()) {
323 pars_[tmp].params().startOfAppendix(false);
329 par.params().startOfAppendix(start);
331 // we can set the refreshing parameters now
332 updateLabels(cur.buffer());
336 case LFUN_WORD_DELETE_FORWARD:
337 if (cur.selection()) {
338 cutSelection(cur, true, false);
340 deleteWordForward(cur);
341 finishChange(cur, false);
344 case LFUN_WORD_DELETE_BACKWARD:
345 if (cur.selection()) {
346 cutSelection(cur, true, false);
348 deleteWordBackward(cur);
349 finishChange(cur, false);
352 case LFUN_LINE_DELETE:
353 if (cur.selection()) {
354 cutSelection(cur, true, false);
356 tm.deleteLineForward(cur);
357 finishChange(cur, false);
360 case LFUN_BUFFER_BEGIN:
361 case LFUN_BUFFER_BEGIN_SELECT:
362 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
363 if (cur.depth() == 1) {
364 needsUpdate |= cursorTop(cur);
370 case LFUN_BUFFER_END:
371 case LFUN_BUFFER_END_SELECT:
372 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
373 if (cur.depth() == 1) {
374 needsUpdate |= cursorBottom(cur);
380 case LFUN_CHAR_FORWARD:
381 case LFUN_CHAR_FORWARD_SELECT:
382 //lyxerr << BOOST_CURRENT_FUNCTION
383 // << " LFUN_CHAR_FORWARD[SEL]:\n" << cur << endl;
384 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
385 needsUpdate |= cursorForward(cur);
387 if (!needsUpdate && oldTopSlice == cur.top()
388 && cur.boundary() == oldBoundary) {
390 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
394 case LFUN_CHAR_BACKWARD:
395 case LFUN_CHAR_BACKWARD_SELECT:
396 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
397 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
398 needsUpdate |= cursorBackward(cur);
400 if (!needsUpdate && oldTopSlice == cur.top()
401 && cur.boundary() == oldBoundary) {
403 cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
408 case LFUN_CHAR_LEFT_SELECT:
409 //FIXME: for visual cursor, really move left
410 if (reverseDirectionNeeded(cur)) {
411 lyx::dispatch(FuncRequest(
412 cmd.action == LFUN_CHAR_LEFT_SELECT ?
413 LFUN_CHAR_FORWARD_SELECT : LFUN_CHAR_FORWARD));
415 lyx::dispatch(FuncRequest(
416 cmd.action == LFUN_CHAR_LEFT_SELECT ?
417 LFUN_CHAR_BACKWARD_SELECT : LFUN_CHAR_BACKWARD));
421 case LFUN_CHAR_RIGHT:
422 case LFUN_CHAR_RIGHT_SELECT:
423 //FIXME: for visual cursor, really move right
424 if (reverseDirectionNeeded(cur)) {
425 lyx::dispatch(FuncRequest(
426 cmd.action == LFUN_CHAR_RIGHT_SELECT ?
427 LFUN_CHAR_BACKWARD_SELECT : LFUN_CHAR_BACKWARD));
429 lyx::dispatch(FuncRequest(
430 cmd.action == LFUN_CHAR_RIGHT_SELECT ?
431 LFUN_CHAR_FORWARD_SELECT : LFUN_CHAR_FORWARD));
436 case LFUN_DOWN_SELECT:
439 // stop/start the selection
440 bool select = cmd.action == LFUN_DOWN_SELECT ||
441 cmd.action == LFUN_UP_SELECT;
442 cur.selHandle(select);
444 // move cursor up/down
445 bool up = cmd.action == LFUN_UP_SELECT || cmd.action == LFUN_UP;
446 bool const successful = cur.upDownInText(up, needsUpdate);
448 // notify insets which were left and get their update flags
449 notifyCursorLeaves(cur.beforeDispatchCursor(), cur);
452 // redraw if you leave mathed (for the decorations)
453 needsUpdate |= cur.beforeDispatchCursor().inMathed();
460 case LFUN_PARAGRAPH_UP:
461 case LFUN_PARAGRAPH_UP_SELECT:
462 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
463 needsUpdate |= cursorUpParagraph(cur);
466 case LFUN_PARAGRAPH_DOWN:
467 case LFUN_PARAGRAPH_DOWN_SELECT:
468 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
469 needsUpdate |= cursorDownParagraph(cur);
472 case LFUN_SCREEN_UP_SELECT:
473 needsUpdate |= cur.selHandle(true);
474 if (cur.pit() == 0 && cur.textRow().pos() == 0)
477 tm.cursorPrevious(cur);
481 case LFUN_SCREEN_DOWN_SELECT:
482 needsUpdate |= cur.selHandle(true);
483 if (cur.pit() == cur.lastpit()
484 && cur.textRow().endpos() == cur.lastpos())
491 case LFUN_LINE_BEGIN:
492 case LFUN_LINE_BEGIN_SELECT:
493 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
494 needsUpdate |= tm.cursorHome(cur);
498 case LFUN_LINE_END_SELECT:
499 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
500 needsUpdate |= tm.cursorEnd(cur);
503 case LFUN_WORD_FORWARD:
504 case LFUN_WORD_FORWARD_SELECT:
505 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
506 if (reverseDirectionNeeded(cur))
507 needsUpdate |= cursorLeftOneWord(cur);
509 needsUpdate |= cursorRightOneWord(cur);
512 case LFUN_WORD_BACKWARD:
513 case LFUN_WORD_BACKWARD_SELECT:
514 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
515 if (reverseDirectionNeeded(cur))
516 needsUpdate |= cursorRightOneWord(cur);
518 needsUpdate |= cursorLeftOneWord(cur);
521 case LFUN_WORD_SELECT: {
522 selectWord(cur, WHOLE_WORD);
523 finishChange(cur, true);
527 case LFUN_BREAK_LINE: {
528 // Not allowed by LaTeX (labels or empty par)
529 if (cur.pos() > cur.paragraph().beginOfBody()) {
530 // this avoids a double undo
531 // FIXME: should not be needed, ideally
532 if (!cur.selection())
534 cap::replaceSelection(cur);
535 cur.insert(new InsetNewline);
537 moveCursor(cur, false);
542 case LFUN_CHAR_DELETE_FORWARD:
543 if (!cur.selection()) {
544 if (cur.pos() == cur.paragraph().size())
545 // Par boundary, force full-screen update
546 singleParUpdate = false;
547 needsUpdate |= erase(cur);
549 // It is possible to make it a lot faster still
550 // just comment out the line below...
552 cutSelection(cur, true, false);
553 singleParUpdate = false;
555 moveCursor(cur, false);
558 case LFUN_DELETE_FORWARD_SKIP:
559 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
560 if (!cur.selection()) {
561 if (cur.pos() == cur.lastpos()) {
568 cutSelection(cur, true, false);
573 case LFUN_CHAR_DELETE_BACKWARD:
574 if (!cur.selection()) {
575 if (bv->getIntl().getTransManager().backspace()) {
576 // Par boundary, full-screen update
578 singleParUpdate = false;
579 needsUpdate |= backspace(cur);
581 // It is possible to make it a lot faster still
582 // just comment out the line below...
585 cutSelection(cur, true, false);
586 singleParUpdate = false;
590 case LFUN_DELETE_BACKWARD_SKIP:
591 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
592 if (!cur.selection()) {
594 //CursorSlice cur = cursor();
598 cutSelection(cur, true, false);
602 case LFUN_BREAK_PARAGRAPH:
603 cap::replaceSelection(cur);
604 breakParagraph(cur, cmd.argument() == "inverse");
608 case LFUN_BREAK_PARAGRAPH_SKIP: {
609 // When at the beginning of a paragraph, remove
610 // indentation. Otherwise, do the same as LFUN_BREAK_PARAGRAPH.
611 cap::replaceSelection(cur);
613 cur.paragraph().params().labelWidthString(docstring());
615 breakParagraph(cur, false);
621 // With the creation of LFUN_PARAGRAPH_PARAMS, this is now redundant,
622 // as its duties can be performed there. Should it be removed??
623 // FIXME For now, it can just dispatch LFUN_PARAGRAPH_PARAMS...
624 case LFUN_PARAGRAPH_SPACING: {
625 Paragraph & par = cur.paragraph();
626 Spacing::Space cur_spacing = par.params().spacing().getSpace();
627 string cur_value = "1.0";
628 if (cur_spacing == Spacing::Other)
629 cur_value = par.params().spacing().getValueAsString();
631 istringstream is(to_utf8(cmd.argument()));
634 Spacing::Space new_spacing = cur_spacing;
635 string new_value = cur_value;
637 lyxerr << "Missing argument to `paragraph-spacing'"
639 } else if (tmp == "single") {
640 new_spacing = Spacing::Single;
641 } else if (tmp == "onehalf") {
642 new_spacing = Spacing::Onehalf;
643 } else if (tmp == "double") {
644 new_spacing = Spacing::Double;
645 } else if (tmp == "other") {
646 new_spacing = Spacing::Other;
647 string tmpval = "0.0";
649 lyxerr << "new_value = " << tmpval << endl;
652 } else if (tmp == "default") {
653 new_spacing = Spacing::Default;
655 lyxerr << to_utf8(_("Unknown spacing argument: "))
656 << to_utf8(cmd.argument()) << endl;
658 if (cur_spacing != new_spacing || cur_value != new_value)
659 par.params().spacing(Spacing(new_spacing, new_value));
663 case LFUN_INSET_INSERT: {
665 Inset * inset = createInset(bv, cmd);
667 // FIXME (Abdel 01/02/2006):
668 // What follows would be a partial fix for bug 2154:
669 // http://bugzilla.lyx.org/show_bug.cgi?id=2154
670 // This automatically put the label inset _after_ a
671 // numbered section. It should be possible to extend the mechanism
672 // to any kind of LateX environement.
673 // The correct way to fix that bug would be at LateX generation.
674 // I'll let the code here for reference as it could be used for some
675 // other feature like "automatic labelling".
677 Paragraph & par = pars_[cur.pit()];
678 if (inset->lyxCode() == LABEL_CODE
679 && par.layout()->labeltype == LABEL_COUNTER) {
680 // Go to the end of the paragraph
681 // Warning: Because of Change-Tracking, the last
682 // position is 'size()' and not 'size()-1':
683 cur.pos() = par.size();
684 // Insert a new paragraph
685 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
690 cutSelection(cur, true, false);
691 insertInset(cur, inset);
697 case LFUN_INSET_DISSOLVE:
698 needsUpdate |= dissolveInset(cur);
701 case LFUN_INSET_SETTINGS:
702 cur.inset().showInsetDialog(bv);
705 case LFUN_SPACE_INSERT:
706 if (cur.paragraph().layout()->free_spacing)
707 insertChar(cur, ' ');
709 doInsertInset(cur, this, cmd, false, false);
712 moveCursor(cur, false);
715 case LFUN_HYPHENATION_POINT_INSERT:
716 specialChar(cur, InsetSpecialChar::HYPHENATION);
719 case LFUN_LIGATURE_BREAK_INSERT:
720 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
723 case LFUN_DOTS_INSERT:
724 specialChar(cur, InsetSpecialChar::LDOTS);
727 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
728 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
731 case LFUN_MENU_SEPARATOR_INSERT:
732 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
735 case LFUN_WORD_UPCASE:
736 changeCase(cur, text_uppercase);
739 case LFUN_WORD_LOWCASE:
740 changeCase(cur, text_lowercase);
743 case LFUN_WORD_CAPITALIZE:
744 changeCase(cur, text_capitalization);
747 case LFUN_CHARS_TRANSPOSE:
752 cur.message(_("Paste"));
753 cap::replaceSelection(cur);
754 if (cmd.argument().empty() && !theClipboard().isInternal())
755 pasteClipboard(cur, bv->buffer().errorList("Paste"));
757 string const arg(to_utf8(cmd.argument()));
758 pasteFromStack(cur, bv->buffer().errorList("Paste"),
759 isStrUnsignedInt(arg) ?
760 convert<unsigned int>(arg) :
763 bv->buffer().errors("Paste");
764 cur.clearSelection(); // bug 393
769 cutSelection(cur, true, true);
770 cur.message(_("Cut"));
775 cur.message(_("Copy"));
778 case LFUN_SERVER_GET_XY:
779 cur.message(from_utf8(
780 convert<string>(tm.cursorX(cur.top(), cur.boundary()))
781 + ' ' + convert<string>(tm.cursorY(cur.top(), cur.boundary()))));
784 case LFUN_SERVER_SET_XY: {
787 istringstream is(to_utf8(cmd.argument()));
790 lyxerr << "SETXY: Could not parse coordinates in '"
791 << to_utf8(cmd.argument()) << std::endl;
793 tm.setCursorFromCoordinates(cur, x, y);
797 case LFUN_SERVER_GET_FONT:
798 if (cur.current_font.shape() == Font::ITALIC_SHAPE)
799 cur.message(from_ascii("E"));
800 else if (cur.current_font.shape() == Font::SMALLCAPS_SHAPE)
801 cur.message(from_ascii("N"));
803 cur.message(from_ascii("0"));
806 case LFUN_SERVER_GET_LAYOUT:
807 cur.message(cur.paragraph().layout()->name());
811 docstring layout = cmd.argument();
812 LYXERR(Debug::INFO) << "LFUN_LAYOUT: (arg) " << to_utf8(layout) << endl;
814 docstring const old_layout = cur.paragraph().layout()->name();
816 // Derive layout number from given argument (string)
817 // and current buffer's textclass (number)
818 TextClass const & tclass = bv->buffer().params().getTextClass();
820 layout = tclass.defaultLayoutName();
821 bool hasLayout = tclass.hasLayout(layout);
823 // If the entry is obsolete, use the new one instead.
825 docstring const & obs = tclass[layout]->obsoleted_by();
831 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
832 from_utf8(N_(" not known")));
836 bool change_layout = (old_layout != layout);
838 if (!change_layout && cur.selection() &&
839 cur.selBegin().pit() != cur.selEnd().pit())
841 pit_type spit = cur.selBegin().pit();
842 pit_type epit = cur.selEnd().pit() + 1;
843 while (spit != epit) {
844 if (pars_[spit].layout()->name() != old_layout) {
845 change_layout = true;
853 setLayout(cur, layout);
858 case LFUN_CLIPBOARD_PASTE:
859 cur.clearSelection();
860 pasteClipboard(cur, bv->buffer().errorList("Paste"),
861 cmd.argument() == "paragraph");
862 bv->buffer().errors("Paste");
865 case LFUN_PRIMARY_SELECTION_PASTE:
866 pasteString(cur, theSelection().get(),
867 cmd.argument() == "paragraph");
870 case LFUN_UNICODE_INSERT: {
871 if (cmd.argument().empty())
873 docstring hexstring = cmd.argument();
874 if (lyx::support::isHex(hexstring)) {
875 char_type c = lyx::support::hexToInt(hexstring);
876 if (c >= 32 && c < 0x10ffff) {
877 lyxerr << "Inserting c: " << c << endl;
878 docstring s = docstring(1, c);
879 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
885 case LFUN_QUOTE_INSERT: {
886 Paragraph & par = cur.paragraph();
887 pos_type pos = cur.pos();
888 BufferParams const & bufparams = bv->buffer().params();
889 LayoutPtr const & style = par.layout();
890 if (!style->pass_thru
891 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
892 // this avoids a double undo
893 // FIXME: should not be needed, ideally
894 if (!cur.selection())
896 cap::replaceSelection(cur);
901 else if (cur.prevInset() && cur.prevInset()->isSpace())
904 c = par.getChar(pos - 1);
905 string arg = to_utf8(cmd.argument());
907 cur.insert(new InsetQuotes(c,
908 bufparams.quotes_language,
909 InsetQuotes::SingleQ));
911 cur.insert(new InsetQuotes(c,
912 bufparams.quotes_language,
913 InsetQuotes::DoubleQ));
917 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
921 case LFUN_DATE_INSERT: {
922 string const format = cmd.argument().empty()
923 ? lyxrc.date_insert_format : to_utf8(cmd.argument());
924 string const time = formatted_time(current_time(), format);
925 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, time));
929 case LFUN_MOUSE_TRIPLE:
930 if (cmd.button() == mouse_button::button1) {
939 case LFUN_MOUSE_DOUBLE:
940 if (cmd.button() == mouse_button::button1) {
941 selectWord(cur, WHOLE_WORD_STRICT);
946 // Single-click on work area
947 case LFUN_MOUSE_PRESS: {
948 // Right click on a footnote flag opens float menu
949 // FIXME: Why should we clear the selection in this case?
950 if (cmd.button() == mouse_button::button3)
951 cur.clearSelection();
953 bool do_selection = cmd.button() == mouse_button::button1
954 && cmd.argument() == "region-select";
956 bool update = bv->mouseSetCursor(cur, do_selection);
958 // Insert primary selection with middle mouse
959 // if there is a local selection in the current buffer,
961 if (cmd.button() == mouse_button::button2) {
962 if (cap::selection()) {
963 // Copy the selection buffer to the clipboard
964 // stack, because we want it to appear in the
965 // "Edit->Paste recent" menu.
966 cap::copySelectionToStack();
968 cap::pasteSelection(bv->cursor(),
969 bv->buffer().errorList("Paste"));
970 bv->buffer().errors("Paste");
971 bv->buffer().markDirty();
972 bv->cursor().finishUndo();
974 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
978 // we have to update after dEPM triggered
979 if (!update && cmd.button() == mouse_button::button1) {
987 case LFUN_MOUSE_MOTION: {
988 // Only use motion with button 1
989 //if (cmd.button() != mouse_button::button1)
992 // ignore motions deeper nested than the real anchor
993 Cursor & bvcur = cur.bv().cursor();
994 if (bvcur.anchor_.hasPart(cur)) {
995 CursorSlice old = bvcur.top();
997 int const wh = bv->workHeight();
998 int const y = std::max(0, std::min(wh - 1, cmd.y));
1000 tm.setCursorFromCoordinates(cur, cmd.x, y);
1001 cur.setTargetX(cmd.x);
1003 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1005 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1006 // This is to allow jumping over large insets
1007 if (cur.top() == old) {
1009 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1011 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1014 if (cur.top() == old)
1017 // don't set anchor_
1018 bvcur.setCursor(cur);
1019 bvcur.selection() = true;
1020 //lyxerr << "MOTION: " << bv->cursor() << endl;
1028 case LFUN_MOUSE_RELEASE: {
1029 if (cmd.button() == mouse_button::button2)
1032 if (cmd.button() == mouse_button::button1) {
1033 // if there is new selection, update persistent
1034 // selection, otherwise, single click does not
1035 // clear persistent selection buffer
1036 if (cur.selection()) {
1038 // if double click, cur is moved to the end of word by selectWord
1039 // but bvcur is current mouse position
1040 Cursor & bvcur = cur.bv().cursor();
1041 bvcur.selection() = true;
1043 needsUpdate = false;
1050 case LFUN_SELF_INSERT: {
1051 if (cmd.argument().empty())
1054 // Automatically delete the currently selected
1055 // text and replace it with what is being
1056 // typed in now. Depends on lyxrc settings
1057 // "auto_region_delete", which defaults to
1060 if (lyxrc.auto_region_delete && cur.selection()) {
1061 cutSelection(cur, false, false);
1062 // When change tracking is set to off, the metrics update
1063 // mechanism correctly detects if a full update is needed or not.
1064 // This detection fails when a selection spans multiple rows and
1065 // change tracking is enabled because the paragraph metrics stays
1066 // the same. In this case, we force the full update:
1067 // (see http://bugzilla.lyx.org/show_bug.cgi?id=3992)
1068 if (cur.buffer().params().trackChanges)
1069 cur.updateFlags(Update::Force);
1072 cur.clearSelection();
1073 Font const old_font = cur.real_current_font;
1075 docstring::const_iterator cit = cmd.argument().begin();
1076 docstring::const_iterator end = cmd.argument().end();
1077 for (; cit != end; ++cit)
1078 bv->translateAndInsert(*cit, this, cur);
1081 moveCursor(cur, false);
1085 case LFUN_HYPERLINK_INSERT: {
1086 InsetCommandParams p(HYPERLINK_CODE);
1088 if (cur.selection()) {
1089 content = cur.selectionAsString(false);
1090 cutSelection(cur, true, false);
1092 p["target"] = (cmd.argument().empty()) ?
1093 content : cmd.argument();
1094 string const data = InsetCommandMailer::params2string("href", p);
1095 if (p["target"].empty()) {
1096 bv->showInsetDialog("href", data, 0);
1098 FuncRequest fr(LFUN_INSET_INSERT, data);
1104 case LFUN_LABEL_INSERT: {
1105 InsetCommandParams p(LABEL_CODE);
1106 // Try to generate a valid label
1107 p["name"] = (cmd.argument().empty()) ?
1108 cur.getPossibleLabel() :
1110 string const data = InsetCommandMailer::params2string("label", p);
1112 if (cmd.argument().empty()) {
1113 bv->showInsetDialog("label", data, 0);
1115 FuncRequest fr(LFUN_INSET_INSERT, data);
1121 case LFUN_INFO_INSERT: {
1122 Inset * inset = createInset(&cur.bv(), cmd);
1125 // if an empty inset is created (cmd.argument() is empty)
1126 // use current selection as parameter.
1127 if (cmd.argument().empty() && cur.selection()) {
1128 // use selected text as info to avoid a separate UI
1129 docstring ds = cur.selectionAsString(false);
1130 cutSelection(cur, true, false);
1131 static_cast<InsetInfo *>(inset)->setInfo(to_utf8(ds));
1133 insertInset(cur, inset);
1138 case LFUN_LIST_INSERT:
1139 case LFUN_THEOREM_INSERT:
1141 case LFUN_CAPTION_INSERT:
1142 // Open the inset, and move the current selection
1144 doInsertInset(cur, this, cmd, true, true);
1146 updateLabels(bv->buffer());
1148 case LFUN_NOTE_INSERT:
1149 case LFUN_FLEX_INSERT:
1150 case LFUN_BOX_INSERT:
1151 case LFUN_BRANCH_INSERT:
1152 case LFUN_BIBITEM_INSERT:
1153 case LFUN_ERT_INSERT:
1154 case LFUN_LISTING_INSERT:
1155 case LFUN_FOOTNOTE_INSERT:
1156 case LFUN_MARGINALNOTE_INSERT:
1157 case LFUN_OPTIONAL_INSERT:
1158 case LFUN_ENVIRONMENT_INSERT:
1159 // Open the inset, and move the current selection
1161 doInsertInset(cur, this, cmd, true, true);
1165 case LFUN_TABULAR_INSERT:
1166 // if there were no arguments, just open the dialog
1167 if (doInsertInset(cur, this, cmd, false, true))
1170 bv->showDialog("tabularcreate");
1174 case LFUN_FLOAT_INSERT:
1175 case LFUN_FLOAT_WIDE_INSERT:
1176 case LFUN_WRAP_INSERT: {
1177 bool content = cur.selection(); // will some text be moved into the inset?
1179 doInsertInset(cur, this, cmd, true, true);
1181 ParagraphList & pars = cur.text()->paragraphs();
1183 TextClass const & tclass = bv->buffer().params().getTextClass();
1185 // add a separate paragraph for the caption inset
1186 pars.push_back(Paragraph());
1187 pars.back().setInsetOwner(pars[0].inInset());
1188 pars.back().layout(tclass.defaultLayout());
1190 int cap_pit = pars.size() - 1;
1192 // if an empty inset was created, we create an additional empty
1193 // paragraph at the bottom so that the user can choose where to put
1194 // the graphics (or table).
1196 pars.push_back(Paragraph());
1197 pars.back().setInsetOwner(pars[0].inInset());
1198 pars.back().layout(tclass.defaultLayout());
1202 // reposition the cursor to the caption
1203 cur.pit() = cap_pit;
1205 // FIXME: This Text/Cursor dispatch handling is a mess!
1206 // We cannot use Cursor::dispatch here it needs access to up to
1208 FuncRequest cmd_caption(LFUN_CAPTION_INSERT);
1209 cur.text()->dispatch(cur, cmd_caption);
1210 cur.updateFlags(Update::Force);
1211 // FIXME: When leaving the Float (or Wrap) inset we should
1212 // delete any empty paragraph left above or below the
1217 case LFUN_INDEX_INSERT:
1218 doInsertInset(cur, this, cmd, true, true);
1221 case LFUN_NOMENCL_INSERT: {
1222 Inset * inset = createInset(&cur.bv(), cmd);
1226 cur.clearSelection();
1227 insertInset(cur, inset);
1228 // Show the dialog for the nomenclature entry, since the
1229 // description entry still needs to be filled in.
1230 if (cmd.action == LFUN_NOMENCL_INSERT)
1231 inset->edit(cur, true);
1236 case LFUN_INDEX_PRINT:
1237 case LFUN_NOMENCL_PRINT:
1238 case LFUN_TOC_INSERT:
1239 case LFUN_HFILL_INSERT:
1240 case LFUN_LINE_INSERT:
1241 case LFUN_PAGEBREAK_INSERT:
1242 case LFUN_CLEARPAGE_INSERT:
1243 case LFUN_CLEARDOUBLEPAGE_INSERT:
1245 doInsertInset(cur, this, cmd, false, false);
1249 case LFUN_DEPTH_DECREMENT:
1250 changeDepth(cur, DEC_DEPTH);
1253 case LFUN_DEPTH_INCREMENT:
1254 changeDepth(cur, INC_DEPTH);
1257 case LFUN_MATH_DISPLAY:
1258 mathDispatch(cur, cmd, true);
1261 case LFUN_MATH_IMPORT_SELECTION:
1262 case LFUN_MATH_MODE:
1263 if (cmd.argument() == "on")
1264 // don't pass "on" as argument
1265 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1267 mathDispatch(cur, cmd, false);
1270 case LFUN_MATH_MACRO:
1271 if (cmd.argument().empty())
1272 cur.errorMessage(from_utf8(N_("Missing argument")));
1274 string s = to_utf8(cmd.argument());
1275 string const s1 = token(s, ' ', 1);
1276 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1277 string const s2 = token(s, ' ', 2);
1278 string const type = s2.empty() ? "newcommand" : s2;
1279 cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, from_utf8(type)));
1280 //cur.nextInset()->edit(cur, true);
1284 // passthrough hat and underscore outside mathed:
1285 case LFUN_MATH_SUBSCRIPT:
1286 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1288 case LFUN_MATH_SUPERSCRIPT:
1289 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1292 case LFUN_MATH_INSERT:
1293 case LFUN_MATH_MATRIX:
1294 case LFUN_MATH_DELIM:
1295 case LFUN_MATH_BIGDELIM: {
1296 if (cur.selection())
1297 cur.clearSelection();
1298 // FIXME: instead of the above, this one
1299 // should be used (but it asserts with Bidi enabled)
1300 // cf. http://bugzilla.lyx.org/show_bug.cgi?id=4055
1301 // cap::replaceSelection(cur);
1302 cur.insert(new InsetMathHull(hullSimple));
1303 checkAndActivateInset(cur, true);
1304 BOOST_ASSERT(cur.inMathed());
1309 case LFUN_FONT_EMPH: {
1310 Font font(Font::ALL_IGNORE);
1311 font.setEmph(Font::TOGGLE);
1312 toggleAndShow(cur, this, font);
1316 case LFUN_FONT_BOLD: {
1317 Font font(Font::ALL_IGNORE);
1318 font.setSeries(Font::BOLD_SERIES);
1319 toggleAndShow(cur, this, font);
1323 case LFUN_FONT_NOUN: {
1324 Font font(Font::ALL_IGNORE);
1325 font.setNoun(Font::TOGGLE);
1326 toggleAndShow(cur, this, font);
1330 case LFUN_FONT_TYPEWRITER: {
1331 Font font(Font::ALL_IGNORE);
1332 font.setFamily(Font::TYPEWRITER_FAMILY); // no good
1333 toggleAndShow(cur, this, font);
1337 case LFUN_FONT_SANS: {
1338 Font font(Font::ALL_IGNORE);
1339 font.setFamily(Font::SANS_FAMILY);
1340 toggleAndShow(cur, this, font);
1344 case LFUN_FONT_ROMAN: {
1345 Font font(Font::ALL_IGNORE);
1346 font.setFamily(Font::ROMAN_FAMILY);
1347 toggleAndShow(cur, this, font);
1351 case LFUN_FONT_DEFAULT: {
1352 Font font(Font::ALL_INHERIT, ignore_language);
1353 toggleAndShow(cur, this, font);
1357 case LFUN_FONT_UNDERLINE: {
1358 Font font(Font::ALL_IGNORE);
1359 font.setUnderbar(Font::TOGGLE);
1360 toggleAndShow(cur, this, font);
1364 case LFUN_FONT_SIZE: {
1365 Font font(Font::ALL_IGNORE);
1366 font.setLyXSize(to_utf8(cmd.argument()));
1367 toggleAndShow(cur, this, font);
1371 case LFUN_LANGUAGE: {
1372 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1375 Font font(Font::ALL_IGNORE);
1376 font.setLanguage(lang);
1377 toggleAndShow(cur, this, font);
1381 case LFUN_FONT_FREE_APPLY:
1382 toggleAndShow(cur, this, freefont, toggleall);
1383 cur.message(_("Character set"));
1386 // Set the freefont using the contents of \param data dispatched from
1387 // the frontends and apply it at the current cursor location.
1388 case LFUN_FONT_FREE_UPDATE: {
1391 if (font.fromString(to_utf8(cmd.argument()), toggle)) {
1394 toggleAndShow(cur, this, freefont, toggleall);
1395 cur.message(_("Character set"));
1400 case LFUN_FINISHED_LEFT:
1401 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1402 if (reverseDirectionNeeded(cur)) {
1404 cur.setCurrentFont();
1408 case LFUN_FINISHED_RIGHT:
1409 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1410 if (!reverseDirectionNeeded(cur)) {
1412 cur.setCurrentFont();
1416 case LFUN_FINISHED_BACKWARD:
1417 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_BACKWARD:\n" << cur << endl;
1420 case LFUN_FINISHED_FORWARD:
1421 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_FORWARD:\n" << cur << endl;
1423 cur.setCurrentFont();
1426 case LFUN_LAYOUT_PARAGRAPH: {
1428 params2string(cur.paragraph(), data);
1429 data = "show\n" + data;
1430 bv->showDialogWithData("paragraph", data);
1434 case LFUN_PARAGRAPH_UPDATE: {
1436 params2string(cur.paragraph(), data);
1438 // Will the paragraph accept changes from the dialog?
1439 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1441 data = "update " + convert<string>(accept) + '\n' + data;
1442 bv->updateDialog("paragraph", data);
1446 case LFUN_ACCENT_UMLAUT:
1447 case LFUN_ACCENT_CIRCUMFLEX:
1448 case LFUN_ACCENT_GRAVE:
1449 case LFUN_ACCENT_ACUTE:
1450 case LFUN_ACCENT_TILDE:
1451 case LFUN_ACCENT_CEDILLA:
1452 case LFUN_ACCENT_MACRON:
1453 case LFUN_ACCENT_DOT:
1454 case LFUN_ACCENT_UNDERDOT:
1455 case LFUN_ACCENT_UNDERBAR:
1456 case LFUN_ACCENT_CARON:
1457 case LFUN_ACCENT_SPECIAL_CARON:
1458 case LFUN_ACCENT_BREVE:
1459 case LFUN_ACCENT_TIE:
1460 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1461 case LFUN_ACCENT_CIRCLE:
1462 case LFUN_ACCENT_OGONEK:
1463 theLyXFunc().handleKeyFunc(cmd.action);
1464 if (!cmd.argument().empty())
1465 // FIXME: Are all these characters encoded in one byte in utf8?
1466 bv->translateAndInsert(cmd.argument()[0], this, cur);
1469 case LFUN_FLOAT_LIST: {
1470 TextClass const & tclass = bv->buffer().params().getTextClass();
1471 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1473 if (cur.selection())
1474 cutSelection(cur, true, false);
1475 breakParagraph(cur);
1477 if (cur.lastpos() != 0) {
1478 cursorBackward(cur);
1479 breakParagraph(cur);
1482 setLayout(cur, tclass.defaultLayoutName());
1483 ParagraphParameters p;
1484 setParagraphs(cur, p);
1485 insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1488 lyxerr << "Non-existent float type: "
1489 << to_utf8(cmd.argument()) << endl;
1494 case LFUN_CHANGE_ACCEPT: {
1495 acceptOrRejectChanges(cur, ACCEPT);
1499 case LFUN_CHANGE_REJECT: {
1500 acceptOrRejectChanges(cur, REJECT);
1504 case LFUN_THESAURUS_ENTRY: {
1505 docstring arg = cmd.argument();
1507 arg = cur.selectionAsString(false);
1509 if (arg.size() > 100 || arg.empty()) {
1510 // Get word or selection
1511 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1512 arg = cur.selectionAsString(false);
1515 bv->showDialogWithData("thesaurus", to_utf8(arg));
1519 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1520 // Given data, an encoding of the ParagraphParameters
1521 // generated in the Paragraph dialog, this function sets
1522 // the current paragraph, or currently selected paragraphs,
1524 // NOTE: This function overrides all existing settings.
1525 setParagraphs(cur, cmd.argument());
1526 cur.message(_("Paragraph layout set"));
1530 case LFUN_PARAGRAPH_PARAMS: {
1531 // Given data, an encoding of the ParagraphParameters as we'd
1532 // find them in a LyX file, this function modifies the current paragraph,
1533 // or currently selected paragraphs.
1534 // NOTE: This function only modifies, and does not override, existing
1536 setParagraphs(cur, cmd.argument(), true);
1537 cur.message(_("Paragraph layout set"));
1542 if (cur.selection()) {
1543 cur.selection() = false;
1546 // This used to be LFUN_FINISHED_RIGHT, I think FORWARD is more
1547 // correct, but I'm not 100% sure -- dov, 071019
1548 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
1553 LYXERR(Debug::ACTION)
1554 << BOOST_CURRENT_FUNCTION
1555 << ": Command " << cmd
1556 << " not DISPATCHED by Text" << endl;
1561 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1563 // FIXME: The cursor flag is reset two lines below
1564 // so we need to check here if some of the LFUN did touch that.
1565 // for now only Text::erase() and Text::backspace() do that.
1566 // The plan is to verify all the LFUNs and then to remove this
1567 // singleParUpdate boolean altogether.
1568 if (cur.result().update() & Update::Force) {
1569 singleParUpdate = false;
1573 // FIXME: the following code should go in favor of fine grained
1574 // update flag treatment.
1575 if (singleParUpdate) {
1576 // Inserting characters does not change par height
1577 ParagraphMetrics const & pms
1578 = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
1579 if (pms.dim().height()
1580 == olddim.height()) {
1581 // if so, update _only_ this paragraph
1582 cur.updateFlags(Update::SinglePar |
1584 Update::MultiParSel);
1591 && &oldTopSlice.inset() == &cur.inset()
1592 && oldTopSlice.idx() == cur.idx()
1593 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1594 && !cur.selection())
1595 // FIXME: it would be better if we could just do this
1597 //if (cur.result().update() != Update::FitCursor)
1600 // But some LFUNs do not set Update::FitCursor when needed, so we
1601 // do it for all. This is not very harmfull as FitCursor will provoke
1602 // a full redraw only if needed but still, a proper review of all LFUN
1603 // should be done and this needsUpdate boolean can then be removed.
1604 cur.updateFlags(Update::FitCursor);
1606 cur.updateFlags(Update::Force | Update::FitCursor);
1610 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
1611 FuncStatus & flag) const
1613 BOOST_ASSERT(cur.text() == this);
1615 Font const & font = cur.real_current_font;
1617 InsetCode code = NO_CODE;
1619 switch (cmd.action) {
1621 case LFUN_DEPTH_DECREMENT:
1622 enable = changeDepthAllowed(cur, DEC_DEPTH);
1625 case LFUN_DEPTH_INCREMENT:
1626 enable = changeDepthAllowed(cur, INC_DEPTH);
1630 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1633 case LFUN_BIBITEM_INSERT:
1634 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO
1638 case LFUN_DIALOG_SHOW_NEW_INSET:
1639 if (cmd.argument() == "bibitem")
1640 code = BIBITEM_CODE;
1641 else if (cmd.argument() == "bibtex")
1643 else if (cmd.argument() == "box")
1645 else if (cmd.argument() == "branch")
1647 else if (cmd.argument() == "citation")
1649 else if (cmd.argument() == "ert")
1651 else if (cmd.argument() == "external")
1652 code = EXTERNAL_CODE;
1653 else if (cmd.argument() == "float")
1655 else if (cmd.argument() == "graphics")
1656 code = GRAPHICS_CODE;
1657 else if (cmd.argument() == "href")
1658 code = HYPERLINK_CODE;
1659 else if (cmd.argument() == "include")
1660 code = INCLUDE_CODE;
1661 else if (cmd.argument() == "index")
1663 else if (cmd.argument() == "nomenclature")
1664 code = NOMENCL_CODE;
1665 else if (cmd.argument() == "label")
1667 else if (cmd.argument() == "note")
1669 else if (cmd.argument() == "ref")
1671 else if (cmd.argument() == "toc")
1673 else if (cmd.argument() == "vspace")
1675 else if (cmd.argument() == "wrap")
1677 else if (cmd.argument() == "listings")
1678 code = LISTINGS_CODE;
1681 case LFUN_ERT_INSERT:
1684 case LFUN_LISTING_INSERT:
1685 code = LISTINGS_CODE;
1687 case LFUN_FOOTNOTE_INSERT:
1690 case LFUN_TABULAR_INSERT:
1691 code = TABULAR_CODE;
1693 case LFUN_MARGINALNOTE_INSERT:
1696 case LFUN_FLOAT_INSERT:
1697 case LFUN_FLOAT_WIDE_INSERT:
1700 case LFUN_WRAP_INSERT:
1703 case LFUN_FLOAT_LIST:
1704 code = FLOAT_LIST_CODE;
1707 case LFUN_LIST_INSERT:
1710 case LFUN_THEOREM_INSERT:
1711 code = THEOREM_CODE;
1714 case LFUN_CAPTION_INSERT:
1715 code = CAPTION_CODE;
1717 case LFUN_NOTE_INSERT:
1720 case LFUN_FLEX_INSERT: {
1722 string s = cmd.getArg(0);
1723 InsetLayout il = cur.buffer().params().getTextClass().insetlayout(from_utf8(s));
1724 if (il.lyxtype != "charstyle" &&
1725 il.lyxtype != "custom" &&
1726 il.lyxtype != "element")
1730 case LFUN_BOX_INSERT:
1733 case LFUN_BRANCH_INSERT:
1735 if (cur.buffer().masterBuffer()->params().branchlist().empty())
1738 case LFUN_LABEL_INSERT:
1741 case LFUN_INFO_INSERT:
1744 case LFUN_OPTIONAL_INSERT:
1746 enable = cur.paragraph().insetList().count(OPTARG_CODE)
1747 < cur.paragraph().layout()->optionalargs;
1749 case LFUN_ENVIRONMENT_INSERT:
1752 case LFUN_INDEX_INSERT:
1755 case LFUN_INDEX_PRINT:
1756 code = INDEX_PRINT_CODE;
1758 case LFUN_NOMENCL_INSERT:
1759 code = NOMENCL_CODE;
1761 case LFUN_NOMENCL_PRINT:
1762 code = NOMENCL_PRINT_CODE;
1764 case LFUN_TOC_INSERT:
1767 case LFUN_HYPERLINK_INSERT:
1768 code = HYPERLINK_CODE;
1770 case LFUN_QUOTE_INSERT:
1771 // always allow this, since we will inset a raw quote
1772 // if an inset is not allowed.
1774 case LFUN_HYPHENATION_POINT_INSERT:
1775 case LFUN_LIGATURE_BREAK_INSERT:
1776 case LFUN_HFILL_INSERT:
1777 case LFUN_MENU_SEPARATOR_INSERT:
1778 case LFUN_DOTS_INSERT:
1779 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
1780 code = SPECIALCHAR_CODE;
1782 case LFUN_SPACE_INSERT:
1783 // slight hack: we know this is allowed in math mode
1788 case LFUN_INSET_MODIFY:
1789 // We need to disable this, because we may get called for a
1791 // InsetTabular::getStatus() -> InsetText::getStatus()
1792 // and we don't handle LFUN_INSET_MODIFY.
1796 case LFUN_FONT_EMPH:
1797 flag.setOnOff(font.emph() == Font::ON);
1800 case LFUN_FONT_NOUN:
1801 flag.setOnOff(font.noun() == Font::ON);
1804 case LFUN_FONT_BOLD:
1805 flag.setOnOff(font.series() == Font::BOLD_SERIES);
1808 case LFUN_FONT_SANS:
1809 flag.setOnOff(font.family() == Font::SANS_FAMILY);
1812 case LFUN_FONT_ROMAN:
1813 flag.setOnOff(font.family() == Font::ROMAN_FAMILY);
1816 case LFUN_FONT_TYPEWRITER:
1817 flag.setOnOff(font.family() == Font::TYPEWRITER_FAMILY);
1822 enable = cur.selection();
1826 if (cmd.argument().empty()) {
1827 if (theClipboard().isInternal())
1828 enable = cap::numberOfSelections() > 0;
1830 enable = !theClipboard().empty();
1832 string const arg = to_utf8(cmd.argument());
1833 if (isStrUnsignedInt(arg)) {
1834 unsigned int n = convert<unsigned int>(arg);
1835 enable = cap::numberOfSelections() > n;
1842 case LFUN_CLIPBOARD_PASTE:
1843 enable = !theClipboard().empty();
1846 case LFUN_PRIMARY_SELECTION_PASTE:
1847 enable = cur.selection() || !theSelection().empty();
1850 case LFUN_PARAGRAPH_MOVE_UP:
1851 enable = cur.pit() > 0 && !cur.selection();
1854 case LFUN_PARAGRAPH_MOVE_DOWN:
1855 enable = cur.pit() < cur.lastpit() && !cur.selection();
1858 case LFUN_INSET_DISSOLVE:
1859 if (!cmd.argument().empty()) {
1860 InsetLayout il = cur.inset().getLayout(cur.buffer().params());
1861 enable = cur.inset().lyxCode() == FLEX_CODE
1862 && il.lyxtype == to_utf8(cmd.argument());
1864 enable = !isMainText(cur.bv().buffer())
1865 && cur.inset().nargs() == 1;
1869 case LFUN_CHANGE_ACCEPT:
1870 case LFUN_CHANGE_REJECT:
1871 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
1872 // In principle, these LFUNs should only be enabled if there
1873 // is a change at the current position/in the current selection.
1874 // However, without proper optimizations, this will inevitably
1875 // result in unacceptable performance - just imagine a user who
1876 // wants to select the complete content of a long document.
1880 case LFUN_WORD_DELETE_FORWARD:
1881 case LFUN_WORD_DELETE_BACKWARD:
1882 case LFUN_LINE_DELETE:
1883 case LFUN_WORD_FORWARD:
1884 case LFUN_WORD_BACKWARD:
1885 case LFUN_CHAR_FORWARD:
1886 case LFUN_CHAR_FORWARD_SELECT:
1887 case LFUN_CHAR_BACKWARD:
1888 case LFUN_CHAR_BACKWARD_SELECT:
1889 case LFUN_CHAR_LEFT:
1890 case LFUN_CHAR_LEFT_SELECT:
1891 case LFUN_CHAR_RIGHT:
1892 case LFUN_CHAR_RIGHT_SELECT:
1894 case LFUN_UP_SELECT:
1896 case LFUN_DOWN_SELECT:
1897 case LFUN_PARAGRAPH_UP_SELECT:
1898 case LFUN_PARAGRAPH_DOWN_SELECT:
1899 case LFUN_SCREEN_UP_SELECT:
1900 case LFUN_SCREEN_DOWN_SELECT:
1901 case LFUN_LINE_BEGIN_SELECT:
1902 case LFUN_LINE_END_SELECT:
1903 case LFUN_WORD_FORWARD_SELECT:
1904 case LFUN_WORD_BACKWARD_SELECT:
1905 case LFUN_WORD_SELECT:
1906 case LFUN_PARAGRAPH_UP:
1907 case LFUN_PARAGRAPH_DOWN:
1908 case LFUN_LINE_BEGIN:
1910 case LFUN_BREAK_LINE:
1911 case LFUN_CHAR_DELETE_FORWARD:
1912 case LFUN_DELETE_FORWARD_SKIP:
1913 case LFUN_CHAR_DELETE_BACKWARD:
1914 case LFUN_DELETE_BACKWARD_SKIP:
1915 case LFUN_BREAK_PARAGRAPH:
1916 case LFUN_BREAK_PARAGRAPH_SKIP:
1917 case LFUN_PARAGRAPH_SPACING:
1918 case LFUN_INSET_INSERT:
1919 case LFUN_WORD_UPCASE:
1920 case LFUN_WORD_LOWCASE:
1921 case LFUN_WORD_CAPITALIZE:
1922 case LFUN_CHARS_TRANSPOSE:
1923 case LFUN_SERVER_GET_XY:
1924 case LFUN_SERVER_SET_XY:
1925 case LFUN_SERVER_GET_FONT:
1926 case LFUN_SERVER_GET_LAYOUT:
1928 case LFUN_DATE_INSERT:
1929 case LFUN_SELF_INSERT:
1930 case LFUN_LINE_INSERT:
1931 case LFUN_PAGEBREAK_INSERT:
1932 case LFUN_CLEARPAGE_INSERT:
1933 case LFUN_CLEARDOUBLEPAGE_INSERT:
1934 case LFUN_MATH_DISPLAY:
1935 case LFUN_MATH_IMPORT_SELECTION:
1936 case LFUN_MATH_MODE:
1937 case LFUN_MATH_MACRO:
1938 case LFUN_MATH_MATRIX:
1939 case LFUN_MATH_DELIM:
1940 case LFUN_MATH_BIGDELIM:
1941 case LFUN_MATH_INSERT:
1942 case LFUN_MATH_SUBSCRIPT:
1943 case LFUN_MATH_SUPERSCRIPT:
1944 case LFUN_FONT_DEFAULT:
1945 case LFUN_FONT_UNDERLINE:
1946 case LFUN_FONT_SIZE:
1948 case LFUN_FONT_FREE_APPLY:
1949 case LFUN_FONT_FREE_UPDATE:
1950 case LFUN_LAYOUT_PARAGRAPH:
1951 case LFUN_PARAGRAPH_UPDATE:
1952 case LFUN_ACCENT_UMLAUT:
1953 case LFUN_ACCENT_CIRCUMFLEX:
1954 case LFUN_ACCENT_GRAVE:
1955 case LFUN_ACCENT_ACUTE:
1956 case LFUN_ACCENT_TILDE:
1957 case LFUN_ACCENT_CEDILLA:
1958 case LFUN_ACCENT_MACRON:
1959 case LFUN_ACCENT_DOT:
1960 case LFUN_ACCENT_UNDERDOT:
1961 case LFUN_ACCENT_UNDERBAR:
1962 case LFUN_ACCENT_CARON:
1963 case LFUN_ACCENT_SPECIAL_CARON:
1964 case LFUN_ACCENT_BREVE:
1965 case LFUN_ACCENT_TIE:
1966 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1967 case LFUN_ACCENT_CIRCLE:
1968 case LFUN_ACCENT_OGONEK:
1969 case LFUN_THESAURUS_ENTRY:
1970 case LFUN_PARAGRAPH_PARAMS_APPLY:
1971 case LFUN_PARAGRAPH_PARAMS:
1973 case LFUN_BUFFER_END:
1974 case LFUN_BUFFER_BEGIN:
1975 case LFUN_BUFFER_BEGIN_SELECT:
1976 case LFUN_BUFFER_END_SELECT:
1977 case LFUN_UNICODE_INSERT:
1978 // these are handled in our dispatch()
1987 && (cur.empty() || !cur.inset().insetAllowed(code)))
1990 flag.enabled(enable);
1995 void Text::pasteString(Cursor & cur, docstring const & clip,
1998 cur.clearSelection();
1999 if (!clip.empty()) {
2002 insertStringAsParagraphs(cur, clip);
2004 insertStringAsLines(cur, clip);