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"
39 #include "LyXAction.h"
43 #include "Paragraph.h"
44 #include "paragraph_funcs.h"
45 #include "ParagraphParameters.h"
46 #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 if (reverseDirectionNeeded(cur))
386 needsUpdate |= cursorLeft(cur);
388 needsUpdate |= cursorRight(cur);
390 if (!needsUpdate && oldTopSlice == cur.top()
391 && cur.boundary() == oldBoundary) {
393 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
397 case LFUN_CHAR_BACKWARD:
398 case LFUN_CHAR_BACKWARD_SELECT:
399 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
400 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
401 if (reverseDirectionNeeded(cur))
402 needsUpdate |= cursorRight(cur);
404 needsUpdate |= cursorLeft(cur);
406 if (!needsUpdate && oldTopSlice == cur.top()
407 && cur.boundary() == oldBoundary) {
409 cmd = FuncRequest(LFUN_FINISHED_LEFT);
414 case LFUN_DOWN_SELECT:
417 // stop/start the selection
418 bool select = cmd.action == LFUN_DOWN_SELECT ||
419 cmd.action == LFUN_UP_SELECT;
420 cur.selHandle(select);
422 // move cursor up/down
423 bool up = cmd.action == LFUN_UP_SELECT || cmd.action == LFUN_UP;
424 bool const successful = cur.upDownInText(up, needsUpdate);
426 // notify insets which were left and get their update flags
427 notifyCursorLeaves(cur.beforeDispatchCursor(), cur);
430 // redraw if you leave mathed (for the decorations)
431 needsUpdate |= cur.beforeDispatchCursor().inMathed();
438 case LFUN_PARAGRAPH_UP:
439 case LFUN_PARAGRAPH_UP_SELECT:
440 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
441 needsUpdate |= cursorUpParagraph(cur);
444 case LFUN_PARAGRAPH_DOWN:
445 case LFUN_PARAGRAPH_DOWN_SELECT:
446 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
447 needsUpdate |= cursorDownParagraph(cur);
450 case LFUN_SCREEN_UP_SELECT:
451 needsUpdate |= cur.selHandle(true);
452 if (cur.pit() == 0 && cur.textRow().pos() == 0)
455 tm.cursorPrevious(cur);
459 case LFUN_SCREEN_DOWN_SELECT:
460 needsUpdate |= cur.selHandle(true);
461 if (cur.pit() == cur.lastpit()
462 && cur.textRow().endpos() == cur.lastpos())
469 case LFUN_LINE_BEGIN:
470 case LFUN_LINE_BEGIN_SELECT:
471 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
472 needsUpdate |= tm.cursorHome(cur);
476 case LFUN_LINE_END_SELECT:
477 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
478 needsUpdate |= tm.cursorEnd(cur);
481 case LFUN_WORD_FORWARD:
482 case LFUN_WORD_FORWARD_SELECT:
483 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
484 if (reverseDirectionNeeded(cur))
485 needsUpdate |= cursorLeftOneWord(cur);
487 needsUpdate |= cursorRightOneWord(cur);
490 case LFUN_WORD_BACKWARD:
491 case LFUN_WORD_BACKWARD_SELECT:
492 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
493 if (reverseDirectionNeeded(cur))
494 needsUpdate |= cursorRightOneWord(cur);
496 needsUpdate |= cursorLeftOneWord(cur);
499 case LFUN_WORD_SELECT: {
500 selectWord(cur, WHOLE_WORD);
501 finishChange(cur, true);
505 case LFUN_BREAK_LINE: {
506 // Not allowed by LaTeX (labels or empty par)
507 if (cur.pos() > cur.paragraph().beginOfBody()) {
508 // this avoids a double undo
509 // FIXME: should not be needed, ideally
510 if (!cur.selection())
512 cap::replaceSelection(cur);
513 cur.insert(new InsetNewline);
515 moveCursor(cur, false);
520 case LFUN_CHAR_DELETE_FORWARD:
521 if (!cur.selection()) {
522 if (cur.pos() == cur.paragraph().size())
523 // Par boundary, force full-screen update
524 singleParUpdate = false;
525 needsUpdate |= erase(cur);
527 // It is possible to make it a lot faster still
528 // just comment out the line below...
530 cutSelection(cur, true, false);
531 singleParUpdate = false;
533 moveCursor(cur, false);
536 case LFUN_DELETE_FORWARD_SKIP:
537 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
538 if (!cur.selection()) {
539 if (cur.pos() == cur.lastpos()) {
546 cutSelection(cur, true, false);
551 case LFUN_CHAR_DELETE_BACKWARD:
552 if (!cur.selection()) {
553 if (bv->getIntl().getTransManager().backspace()) {
554 // Par boundary, full-screen update
556 singleParUpdate = false;
557 needsUpdate |= backspace(cur);
559 // It is possible to make it a lot faster still
560 // just comment out the line below...
563 cutSelection(cur, true, false);
564 singleParUpdate = false;
568 case LFUN_DELETE_BACKWARD_SKIP:
569 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
570 if (!cur.selection()) {
572 //CursorSlice cur = cursor();
576 cutSelection(cur, true, false);
580 case LFUN_BREAK_PARAGRAPH:
581 cap::replaceSelection(cur);
582 breakParagraph(cur, cmd.argument() == "inverse");
586 case LFUN_BREAK_PARAGRAPH_SKIP: {
587 // When at the beginning of a paragraph, remove
588 // indentation. Otherwise, do the same as LFUN_BREAK_PARAGRAPH.
589 cap::replaceSelection(cur);
591 cur.paragraph().params().labelWidthString(docstring());
593 breakParagraph(cur, false);
599 // With the creation of LFUN_PARAGRAPH_PARAMS, this is now redundant,
600 // as its duties can be performed there. Should it be removed??
601 // FIXME For now, it can just dispatch LFUN_PARAGRAPH_PARAMS...
602 case LFUN_PARAGRAPH_SPACING: {
603 Paragraph & par = cur.paragraph();
604 Spacing::Space cur_spacing = par.params().spacing().getSpace();
605 string cur_value = "1.0";
606 if (cur_spacing == Spacing::Other)
607 cur_value = par.params().spacing().getValueAsString();
609 istringstream is(to_utf8(cmd.argument()));
612 Spacing::Space new_spacing = cur_spacing;
613 string new_value = cur_value;
615 lyxerr << "Missing argument to `paragraph-spacing'"
617 } else if (tmp == "single") {
618 new_spacing = Spacing::Single;
619 } else if (tmp == "onehalf") {
620 new_spacing = Spacing::Onehalf;
621 } else if (tmp == "double") {
622 new_spacing = Spacing::Double;
623 } else if (tmp == "other") {
624 new_spacing = Spacing::Other;
625 string tmpval = "0.0";
627 lyxerr << "new_value = " << tmpval << endl;
630 } else if (tmp == "default") {
631 new_spacing = Spacing::Default;
633 lyxerr << to_utf8(_("Unknown spacing argument: "))
634 << to_utf8(cmd.argument()) << endl;
636 if (cur_spacing != new_spacing || cur_value != new_value)
637 par.params().spacing(Spacing(new_spacing, new_value));
641 case LFUN_INSET_INSERT: {
643 Inset * inset = createInset(bv, cmd);
645 // FIXME (Abdel 01/02/2006):
646 // What follows would be a partial fix for bug 2154:
647 // http://bugzilla.lyx.org/show_bug.cgi?id=2154
648 // This automatically put the label inset _after_ a
649 // numbered section. It should be possible to extend the mechanism
650 // to any kind of LateX environement.
651 // The correct way to fix that bug would be at LateX generation.
652 // I'll let the code here for reference as it could be used for some
653 // other feature like "automatic labelling".
655 Paragraph & par = pars_[cur.pit()];
656 if (inset->lyxCode() == LABEL_CODE
657 && par.layout()->labeltype == LABEL_COUNTER) {
658 // Go to the end of the paragraph
659 // Warning: Because of Change-Tracking, the last
660 // position is 'size()' and not 'size()-1':
661 cur.pos() = par.size();
662 // Insert a new paragraph
663 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
668 cutSelection(cur, true, false);
669 insertInset(cur, inset);
675 case LFUN_INSET_DISSOLVE:
676 needsUpdate |= dissolveInset(cur);
679 case LFUN_INSET_SETTINGS:
680 cur.inset().showInsetDialog(bv);
683 case LFUN_SPACE_INSERT:
684 if (cur.paragraph().layout()->free_spacing)
685 insertChar(cur, ' ');
687 doInsertInset(cur, this, cmd, false, false);
690 moveCursor(cur, false);
693 case LFUN_HYPHENATION_POINT_INSERT:
694 specialChar(cur, InsetSpecialChar::HYPHENATION);
697 case LFUN_LIGATURE_BREAK_INSERT:
698 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
701 case LFUN_DOTS_INSERT:
702 specialChar(cur, InsetSpecialChar::LDOTS);
705 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
706 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
709 case LFUN_MENU_SEPARATOR_INSERT:
710 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
713 case LFUN_WORD_UPCASE:
714 changeCase(cur, Text::text_uppercase);
717 case LFUN_WORD_LOWCASE:
718 changeCase(cur, Text::text_lowercase);
721 case LFUN_WORD_CAPITALIZE:
722 changeCase(cur, Text::text_capitalization);
725 case LFUN_CHARS_TRANSPOSE:
730 cur.message(_("Paste"));
731 cap::replaceSelection(cur);
732 if (cmd.argument().empty() && !theClipboard().isInternal())
733 pasteClipboard(cur, bv->buffer().errorList("Paste"));
735 string const arg(to_utf8(cmd.argument()));
736 pasteFromStack(cur, bv->buffer().errorList("Paste"),
737 isStrUnsignedInt(arg) ?
738 convert<unsigned int>(arg) :
741 bv->buffer().errors("Paste");
742 cur.clearSelection(); // bug 393
747 cutSelection(cur, true, true);
748 cur.message(_("Cut"));
753 cur.message(_("Copy"));
756 case LFUN_SERVER_GET_XY:
757 cur.message(from_utf8(
758 convert<string>(tm.cursorX(cur.top(), cur.boundary()))
759 + ' ' + convert<string>(tm.cursorY(cur.top(), cur.boundary()))));
762 case LFUN_SERVER_SET_XY: {
765 istringstream is(to_utf8(cmd.argument()));
768 lyxerr << "SETXY: Could not parse coordinates in '"
769 << to_utf8(cmd.argument()) << std::endl;
771 tm.setCursorFromCoordinates(cur, x, y);
775 case LFUN_SERVER_GET_FONT:
776 if (cur.current_font.shape() == Font::ITALIC_SHAPE)
777 cur.message(from_ascii("E"));
778 else if (cur.current_font.shape() == Font::SMALLCAPS_SHAPE)
779 cur.message(from_ascii("N"));
781 cur.message(from_ascii("0"));
784 case LFUN_SERVER_GET_LAYOUT:
785 cur.message(cur.paragraph().layout()->name());
789 docstring layout = cmd.argument();
790 LYXERR(Debug::INFO) << "LFUN_LAYOUT: (arg) " << to_utf8(layout) << endl;
792 docstring const old_layout = cur.paragraph().layout()->name();
794 // Derive layout number from given argument (string)
795 // and current buffer's textclass (number)
796 TextClass const & tclass = bv->buffer().params().getTextClass();
798 layout = tclass.defaultLayoutName();
799 bool hasLayout = tclass.hasLayout(layout);
801 // If the entry is obsolete, use the new one instead.
803 docstring const & obs = tclass[layout]->obsoleted_by();
809 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
810 from_utf8(N_(" not known")));
814 bool change_layout = (old_layout != layout);
816 if (!change_layout && cur.selection() &&
817 cur.selBegin().pit() != cur.selEnd().pit())
819 pit_type spit = cur.selBegin().pit();
820 pit_type epit = cur.selEnd().pit() + 1;
821 while (spit != epit) {
822 if (pars_[spit].layout()->name() != old_layout) {
823 change_layout = true;
831 setLayout(cur, layout);
836 case LFUN_CLIPBOARD_PASTE:
837 cur.clearSelection();
838 pasteClipboard(cur, bv->buffer().errorList("Paste"),
839 cmd.argument() == "paragraph");
840 bv->buffer().errors("Paste");
843 case LFUN_PRIMARY_SELECTION_PASTE:
844 pasteString(cur, theSelection().get(),
845 cmd.argument() == "paragraph");
848 case LFUN_UNICODE_INSERT: {
849 if (cmd.argument().empty())
851 docstring hexstring = cmd.argument();
852 if (lyx::support::isHex(hexstring)) {
853 char_type c = lyx::support::hexToInt(hexstring);
854 if (c >= 32 && c < 0x10ffff) {
855 lyxerr << "Inserting c: " << c << endl;
856 docstring s = docstring(1, c);
857 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
863 case LFUN_QUOTE_INSERT: {
864 Paragraph & par = cur.paragraph();
865 pos_type pos = cur.pos();
866 BufferParams const & bufparams = bv->buffer().params();
867 LayoutPtr const & style = par.layout();
868 if (!style->pass_thru
869 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
870 // this avoids a double undo
871 // FIXME: should not be needed, ideally
872 if (!cur.selection())
874 cap::replaceSelection(cur);
879 else if (cur.prevInset() && cur.prevInset()->isSpace())
882 c = par.getChar(pos - 1);
883 string arg = to_utf8(cmd.argument());
885 cur.insert(new InsetQuotes(c,
886 bufparams.quotes_language,
887 InsetQuotes::SingleQ));
889 cur.insert(new InsetQuotes(c,
890 bufparams.quotes_language,
891 InsetQuotes::DoubleQ));
895 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
899 case LFUN_DATE_INSERT: {
900 string const format = cmd.argument().empty()
901 ? lyxrc.date_insert_format : to_utf8(cmd.argument());
902 string const time = formatted_time(current_time(), format);
903 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, time));
907 case LFUN_MOUSE_TRIPLE:
908 if (cmd.button() == mouse_button::button1) {
917 case LFUN_MOUSE_DOUBLE:
918 if (cmd.button() == mouse_button::button1) {
919 selectWord(cur, WHOLE_WORD_STRICT);
924 // Single-click on work area
925 case LFUN_MOUSE_PRESS: {
926 // Right click on a footnote flag opens float menu
927 // FIXME: Why should we clear the selection in this case?
928 if (cmd.button() == mouse_button::button3)
929 cur.clearSelection();
931 bool do_selection = cmd.button() == mouse_button::button1
932 && cmd.argument() == "region-select";
934 bool update = bv->mouseSetCursor(cur, do_selection);
936 // Insert primary selection with middle mouse
937 // if there is a local selection in the current buffer,
939 if (cmd.button() == mouse_button::button2) {
940 if (cap::selection()) {
941 // Copy the selection buffer to the clipboard
942 // stack, because we want it to appear in the
943 // "Edit->Paste recent" menu.
944 cap::copySelectionToStack();
946 cap::pasteSelection(bv->cursor(),
947 bv->buffer().errorList("Paste"));
948 bv->buffer().errors("Paste");
949 bv->buffer().markDirty();
952 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
956 // we have to update after dEPM triggered
957 if (!update && cmd.button() == mouse_button::button1) {
965 case LFUN_MOUSE_MOTION: {
966 // Only use motion with button 1
967 //if (cmd.button() != mouse_button::button1)
970 // ignore motions deeper nested than the real anchor
971 Cursor & bvcur = cur.bv().cursor();
972 if (bvcur.anchor_.hasPart(cur)) {
973 CursorSlice old = bvcur.top();
975 int const wh = bv->workHeight();
976 int const y = std::max(0, std::min(wh - 1, cmd.y));
978 tm.setCursorFromCoordinates(cur, cmd.x, y);
979 cur.setTargetX(cmd.x);
981 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
983 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
984 // This is to allow jumping over large insets
985 if (cur.top() == old) {
987 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
989 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
992 if (cur.top() == old)
996 bvcur.setCursor(cur);
997 bvcur.selection() = true;
998 //lyxerr << "MOTION: " << bv->cursor() << endl;
1006 case LFUN_MOUSE_RELEASE: {
1007 if (cmd.button() == mouse_button::button2)
1010 if (cmd.button() == mouse_button::button1) {
1011 // if there is new selection, update persistent
1012 // selection, otherwise, single click does not
1013 // clear persistent selection buffer
1014 if (cur.selection()) {
1016 // if double click, cur is moved to the end of word by selectWord
1017 // but bvcur is current mouse position
1018 Cursor & bvcur = cur.bv().cursor();
1019 bvcur.selection() = true;
1021 needsUpdate = false;
1028 case LFUN_SELF_INSERT: {
1029 if (cmd.argument().empty())
1032 // Automatically delete the currently selected
1033 // text and replace it with what is being
1034 // typed in now. Depends on lyxrc settings
1035 // "auto_region_delete", which defaults to
1038 if (lyxrc.auto_region_delete && cur.selection()) {
1039 cutSelection(cur, false, false);
1040 // When change tracking is set to off, the metrics update
1041 // mechanism correctly detects if a full update is needed or not.
1042 // This detection fails when a selection spans multiple rows and
1043 // change tracking is enabled because the paragraph metrics stays
1044 // the same. In this case, we force the full update:
1045 // (see http://bugzilla.lyx.org/show_bug.cgi?id=3992)
1046 if (cur.buffer().params().trackChanges)
1047 cur.updateFlags(Update::Force);
1050 cur.clearSelection();
1051 Font const old_font = cur.real_current_font;
1053 docstring::const_iterator cit = cmd.argument().begin();
1054 docstring::const_iterator end = cmd.argument().end();
1055 for (; cit != end; ++cit)
1056 bv->translateAndInsert(*cit, this, cur);
1059 moveCursor(cur, false);
1063 case LFUN_URL_INSERT: {
1064 InsetCommandParams p("url");
1066 if (cur.selection()) {
1067 content = cur.selectionAsString(false);
1068 cutSelection(cur, true, false);
1070 p["target"] = (cmd.argument().empty()) ?
1071 content : cmd.argument();
1072 string const data = InsetCommandMailer::params2string("url", p);
1073 if (p["target"].empty()) {
1074 bv->showInsetDialog("url", data, 0);
1076 FuncRequest fr(LFUN_INSET_INSERT, data);
1082 case LFUN_HTML_INSERT: {
1083 InsetCommandParams p("htmlurl");
1085 if (cur.selection()) {
1086 content = cur.selectionAsString(false);
1087 cutSelection(cur, true, false);
1089 p["target"] = (cmd.argument().empty()) ?
1090 content : cmd.argument();
1091 string const data = InsetCommandMailer::params2string("url", p);
1092 if (p["target"].empty()) {
1093 bv->showInsetDialog("url", data, 0);
1095 FuncRequest fr(LFUN_INSET_INSERT, data);
1101 case LFUN_LABEL_INSERT: {
1102 InsetCommandParams p("label");
1103 // Try to generate a valid label
1104 p["name"] = (cmd.argument().empty()) ?
1105 cur.getPossibleLabel() :
1107 string const data = InsetCommandMailer::params2string("label", p);
1109 if (cmd.argument().empty()) {
1110 bv->showInsetDialog("label", data, 0);
1112 FuncRequest fr(LFUN_INSET_INSERT, data);
1118 case LFUN_INFO_INSERT: {
1119 if (!cur.selection())
1121 Inset * inset = createInset(&cur.bv(), cmd);
1124 // use selected text as info to avoid a separate UI
1125 docstring ds = cur.selectionAsString(false);
1126 cutSelection(cur, true, false);
1127 insertInset(cur, inset);
1128 static_cast<InsetInfo *>(inset)->setInfo(to_utf8(ds));
1133 case LFUN_LIST_INSERT:
1134 case LFUN_THEOREM_INSERT:
1136 case LFUN_CAPTION_INSERT:
1137 // Open the inset, and move the current selection
1139 doInsertInset(cur, this, cmd, true, true);
1141 updateLabels(bv->buffer());
1143 case LFUN_NOTE_INSERT:
1144 case LFUN_FLEX_INSERT:
1145 case LFUN_BOX_INSERT:
1146 case LFUN_BRANCH_INSERT:
1147 case LFUN_BIBITEM_INSERT:
1148 case LFUN_ERT_INSERT:
1149 case LFUN_LISTING_INSERT:
1150 case LFUN_FOOTNOTE_INSERT:
1151 case LFUN_MARGINALNOTE_INSERT:
1152 case LFUN_OPTIONAL_INSERT:
1153 case LFUN_ENVIRONMENT_INSERT:
1154 // Open the inset, and move the current selection
1156 doInsertInset(cur, this, cmd, true, true);
1160 case LFUN_TABULAR_INSERT:
1161 // if there were no arguments, just open the dialog
1162 if (doInsertInset(cur, this, cmd, false, true))
1165 bv->showDialog("tabularcreate");
1169 case LFUN_FLOAT_INSERT:
1170 case LFUN_FLOAT_WIDE_INSERT:
1171 case LFUN_WRAP_INSERT: {
1172 bool content = cur.selection(); // will some text be moved into the inset?
1174 doInsertInset(cur, this, cmd, true, true);
1176 ParagraphList & pars = cur.text()->paragraphs();
1178 TextClass const & tclass = bv->buffer().params().getTextClass();
1180 // add a separate paragraph for the caption inset
1181 pars.push_back(Paragraph());
1182 pars.back().setInsetOwner(pars[0].inInset());
1183 pars.back().layout(tclass.defaultLayout());
1185 int cap_pit = pars.size() - 1;
1187 // if an empty inset was created, we create an additional empty
1188 // paragraph at the bottom so that the user can choose where to put
1189 // the graphics (or table).
1191 pars.push_back(Paragraph());
1192 pars.back().setInsetOwner(pars[0].inInset());
1193 pars.back().layout(tclass.defaultLayout());
1197 // reposition the cursor to the caption
1198 cur.pit() = cap_pit;
1200 // FIXME: This Text/Cursor dispatch handling is a mess!
1201 // We cannot use Cursor::dispatch here it needs access to up to
1203 FuncRequest cmd_caption(LFUN_CAPTION_INSERT);
1204 cur.text()->dispatch(cur, cmd_caption);
1205 cur.updateFlags(Update::Force);
1206 // FIXME: When leaving the Float (or Wrap) inset we should
1207 // delete any empty paragraph left above or below the
1212 case LFUN_INDEX_INSERT:
1213 doInsertInset(cur, this, cmd, true, true);
1216 case LFUN_NOMENCL_INSERT: {
1217 Inset * inset = createInset(&cur.bv(), cmd);
1221 cur.clearSelection();
1222 insertInset(cur, inset);
1223 // Show the dialog for the nomenclature entry, since the
1224 // description entry still needs to be filled in.
1225 if (cmd.action == LFUN_NOMENCL_INSERT)
1226 inset->edit(cur, true);
1231 case LFUN_INDEX_PRINT:
1232 case LFUN_NOMENCL_PRINT:
1233 case LFUN_TOC_INSERT:
1234 case LFUN_HFILL_INSERT:
1235 case LFUN_LINE_INSERT:
1236 case LFUN_PAGEBREAK_INSERT:
1237 case LFUN_CLEARPAGE_INSERT:
1238 case LFUN_CLEARDOUBLEPAGE_INSERT:
1240 doInsertInset(cur, this, cmd, false, false);
1244 case LFUN_DEPTH_DECREMENT:
1245 changeDepth(cur, DEC_DEPTH);
1248 case LFUN_DEPTH_INCREMENT:
1249 changeDepth(cur, INC_DEPTH);
1252 case LFUN_MATH_DISPLAY:
1253 mathDispatch(cur, cmd, true);
1256 case LFUN_MATH_IMPORT_SELECTION:
1257 case LFUN_MATH_MODE:
1258 if (cmd.argument() == "on")
1259 // don't pass "on" as argument
1260 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1262 mathDispatch(cur, cmd, false);
1265 case LFUN_MATH_MACRO:
1266 if (cmd.argument().empty())
1267 cur.errorMessage(from_utf8(N_("Missing argument")));
1269 string s = to_utf8(cmd.argument());
1270 string const s1 = token(s, ' ', 1);
1271 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1272 string const s2 = token(s, ' ', 2);
1273 string const type = s2.empty() ? "newcommand" : s2;
1274 cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, from_utf8(type)));
1275 //cur.nextInset()->edit(cur, true);
1279 // passthrough hat and underscore outside mathed:
1280 case LFUN_MATH_SUBSCRIPT:
1281 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1283 case LFUN_MATH_SUPERSCRIPT:
1284 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1287 case LFUN_MATH_INSERT:
1288 case LFUN_MATH_MATRIX:
1289 case LFUN_MATH_DELIM:
1290 case LFUN_MATH_BIGDELIM: {
1291 if (cur.selection())
1292 cur.clearSelection();
1293 // FIXME: instead of the above, this one
1294 // should be used (but it asserts with Bidi enabled)
1295 // cf. http://bugzilla.lyx.org/show_bug.cgi?id=4055
1296 // cap::replaceSelection(cur);
1297 cur.insert(new InsetMathHull(hullSimple));
1298 checkAndActivateInset(cur, true);
1299 BOOST_ASSERT(cur.inMathed());
1304 case LFUN_FONT_EMPH: {
1305 Font font(Font::ALL_IGNORE);
1306 font.setEmph(Font::TOGGLE);
1307 toggleAndShow(cur, this, font);
1311 case LFUN_FONT_BOLD: {
1312 Font font(Font::ALL_IGNORE);
1313 font.setSeries(Font::BOLD_SERIES);
1314 toggleAndShow(cur, this, font);
1318 case LFUN_FONT_NOUN: {
1319 Font font(Font::ALL_IGNORE);
1320 font.setNoun(Font::TOGGLE);
1321 toggleAndShow(cur, this, font);
1325 case LFUN_FONT_TYPEWRITER: {
1326 Font font(Font::ALL_IGNORE);
1327 font.setFamily(Font::TYPEWRITER_FAMILY); // no good
1328 toggleAndShow(cur, this, font);
1332 case LFUN_FONT_SANS: {
1333 Font font(Font::ALL_IGNORE);
1334 font.setFamily(Font::SANS_FAMILY);
1335 toggleAndShow(cur, this, font);
1339 case LFUN_FONT_ROMAN: {
1340 Font font(Font::ALL_IGNORE);
1341 font.setFamily(Font::ROMAN_FAMILY);
1342 toggleAndShow(cur, this, font);
1346 case LFUN_FONT_DEFAULT: {
1347 Font font(Font::ALL_INHERIT, ignore_language);
1348 toggleAndShow(cur, this, font);
1352 case LFUN_FONT_UNDERLINE: {
1353 Font font(Font::ALL_IGNORE);
1354 font.setUnderbar(Font::TOGGLE);
1355 toggleAndShow(cur, this, font);
1359 case LFUN_FONT_SIZE: {
1360 Font font(Font::ALL_IGNORE);
1361 font.setLyXSize(to_utf8(cmd.argument()));
1362 toggleAndShow(cur, this, font);
1366 case LFUN_LANGUAGE: {
1367 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1370 Font font(Font::ALL_IGNORE);
1371 font.setLanguage(lang);
1372 toggleAndShow(cur, this, font);
1376 case LFUN_FONT_FREE_APPLY:
1377 toggleAndShow(cur, this, freefont, toggleall);
1378 cur.message(_("Character set"));
1381 // Set the freefont using the contents of \param data dispatched from
1382 // the frontends and apply it at the current cursor location.
1383 case LFUN_FONT_FREE_UPDATE: {
1386 if (font.fromString(to_utf8(cmd.argument()), toggle)) {
1389 toggleAndShow(cur, this, freefont, toggleall);
1390 cur.message(_("Character set"));
1395 case LFUN_FINISHED_LEFT:
1396 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1397 if (reverseDirectionNeeded(cur)) {
1399 cur.setCurrentFont();
1403 case LFUN_FINISHED_RIGHT:
1404 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1405 if (!reverseDirectionNeeded(cur)) {
1407 cur.setCurrentFont();
1411 case LFUN_LAYOUT_PARAGRAPH: {
1413 params2string(cur.paragraph(), data);
1414 data = "show\n" + data;
1415 bv->showDialogWithData("paragraph", data);
1419 case LFUN_PARAGRAPH_UPDATE: {
1421 params2string(cur.paragraph(), data);
1423 // Will the paragraph accept changes from the dialog?
1424 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1426 data = "update " + convert<string>(accept) + '\n' + data;
1427 bv->updateDialog("paragraph", data);
1431 case LFUN_ACCENT_UMLAUT:
1432 case LFUN_ACCENT_CIRCUMFLEX:
1433 case LFUN_ACCENT_GRAVE:
1434 case LFUN_ACCENT_ACUTE:
1435 case LFUN_ACCENT_TILDE:
1436 case LFUN_ACCENT_CEDILLA:
1437 case LFUN_ACCENT_MACRON:
1438 case LFUN_ACCENT_DOT:
1439 case LFUN_ACCENT_UNDERDOT:
1440 case LFUN_ACCENT_UNDERBAR:
1441 case LFUN_ACCENT_CARON:
1442 case LFUN_ACCENT_SPECIAL_CARON:
1443 case LFUN_ACCENT_BREVE:
1444 case LFUN_ACCENT_TIE:
1445 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1446 case LFUN_ACCENT_CIRCLE:
1447 case LFUN_ACCENT_OGONEK:
1448 theLyXFunc().handleKeyFunc(cmd.action);
1449 if (!cmd.argument().empty())
1450 // FIXME: Are all these characters encoded in one byte in utf8?
1451 bv->translateAndInsert(cmd.argument()[0], this, cur);
1454 case LFUN_FLOAT_LIST: {
1455 TextClass const & tclass = bv->buffer().params().getTextClass();
1456 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1458 if (cur.selection())
1459 cutSelection(cur, true, false);
1460 breakParagraph(cur);
1462 if (cur.lastpos() != 0) {
1464 breakParagraph(cur);
1467 setLayout(cur, tclass.defaultLayoutName());
1468 ParagraphParameters p;
1469 setParagraphs(cur, p);
1470 insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1473 lyxerr << "Non-existent float type: "
1474 << to_utf8(cmd.argument()) << endl;
1479 case LFUN_CHANGE_ACCEPT: {
1480 acceptOrRejectChanges(cur, ACCEPT);
1484 case LFUN_CHANGE_REJECT: {
1485 acceptOrRejectChanges(cur, REJECT);
1489 case LFUN_THESAURUS_ENTRY: {
1490 docstring arg = cmd.argument();
1492 arg = cur.selectionAsString(false);
1494 if (arg.size() > 100 || arg.empty()) {
1495 // Get word or selection
1496 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1497 arg = cur.selectionAsString(false);
1500 bv->showDialogWithData("thesaurus", to_utf8(arg));
1504 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1505 // Given data, an encoding of the ParagraphParameters
1506 // generated in the Paragraph dialog, this function sets
1507 // the current paragraph, or currently selected paragraphs,
1509 // NOTE: This function overrides all existing settings.
1510 setParagraphs(cur, cmd.argument());
1511 cur.message(_("Paragraph layout set"));
1515 case LFUN_PARAGRAPH_PARAMS: {
1516 // Given data, an encoding of the ParagraphParameters as we'd
1517 // find them in a LyX file, this function modifies the current paragraph,
1518 // or currently selected paragraphs.
1519 // NOTE: This function only modifies, and does not override, existing
1521 setParagraphs(cur, cmd.argument(), true);
1522 cur.message(_("Paragraph layout set"));
1527 if (cur.selection()) {
1528 cur.selection() = false;
1531 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1536 LYXERR(Debug::ACTION)
1537 << BOOST_CURRENT_FUNCTION
1538 << ": Command " << cmd
1539 << " not DISPATCHED by Text" << endl;
1544 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1546 // FIXME: The cursor flag is reset two lines below
1547 // so we need to check here if some of the LFUN did touch that.
1548 // for now only Text::erase() and Text::backspace() do that.
1549 // The plan is to verify all the LFUNs and then to remove this
1550 // singleParUpdate boolean altogether.
1551 if (cur.result().update() & Update::Force) {
1552 singleParUpdate = false;
1556 // FIXME: the following code should go in favor of fine grained
1557 // update flag treatment.
1558 if (singleParUpdate) {
1559 // Inserting characters does not change par height
1560 ParagraphMetrics const & pms
1561 = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
1562 if (pms.dim().height()
1563 == olddim.height()) {
1564 // if so, update _only_ this paragraph
1565 cur.updateFlags(Update::SinglePar |
1567 Update::MultiParSel);
1574 && &oldTopSlice.inset() == &cur.inset()
1575 && oldTopSlice.idx() == cur.idx()
1576 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1577 && !cur.selection())
1578 // FIXME: it would be better if we could just do this
1580 //if (cur.result().update() != Update::FitCursor)
1583 // But some LFUNs do not set Update::FitCursor when needed, so we
1584 // do it for all. This is not very harmfull as FitCursor will provoke
1585 // a full redraw only if needed but still, a proper review of all LFUN
1586 // should be done and this needsUpdate boolean can then be removed.
1587 cur.updateFlags(Update::FitCursor);
1589 cur.updateFlags(Update::Force | Update::FitCursor);
1593 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
1594 FuncStatus & flag) const
1596 BOOST_ASSERT(cur.text() == this);
1598 Font const & font = cur.real_current_font;
1600 InsetCode code = NO_CODE;
1602 switch (cmd.action) {
1604 case LFUN_DEPTH_DECREMENT:
1605 enable = changeDepthAllowed(cur, DEC_DEPTH);
1608 case LFUN_DEPTH_INCREMENT:
1609 enable = changeDepthAllowed(cur, INC_DEPTH);
1613 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1616 case LFUN_BIBITEM_INSERT:
1617 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO
1621 case LFUN_DIALOG_SHOW_NEW_INSET:
1622 if (cmd.argument() == "bibitem")
1623 code = BIBITEM_CODE;
1624 else if (cmd.argument() == "bibtex")
1626 else if (cmd.argument() == "box")
1628 else if (cmd.argument() == "branch")
1630 else if (cmd.argument() == "citation")
1632 else if (cmd.argument() == "ert")
1634 else if (cmd.argument() == "external")
1635 code = EXTERNAL_CODE;
1636 else if (cmd.argument() == "float")
1638 else if (cmd.argument() == "graphics")
1639 code = GRAPHICS_CODE;
1640 else if (cmd.argument() == "include")
1641 code = INCLUDE_CODE;
1642 else if (cmd.argument() == "index")
1644 else if (cmd.argument() == "nomenclature")
1645 code = NOMENCL_CODE;
1646 else if (cmd.argument() == "label")
1648 else if (cmd.argument() == "note")
1650 else if (cmd.argument() == "ref")
1652 else if (cmd.argument() == "toc")
1654 else if (cmd.argument() == "url")
1656 else if (cmd.argument() == "vspace")
1658 else if (cmd.argument() == "wrap")
1660 else if (cmd.argument() == "listings")
1661 code = LISTINGS_CODE;
1664 case LFUN_ERT_INSERT:
1667 case LFUN_LISTING_INSERT:
1668 code = LISTINGS_CODE;
1670 case LFUN_FOOTNOTE_INSERT:
1673 case LFUN_TABULAR_INSERT:
1674 code = TABULAR_CODE;
1676 case LFUN_MARGINALNOTE_INSERT:
1679 case LFUN_FLOAT_INSERT:
1680 case LFUN_FLOAT_WIDE_INSERT:
1683 case LFUN_WRAP_INSERT:
1686 case LFUN_FLOAT_LIST:
1687 code = FLOAT_LIST_CODE;
1690 case LFUN_LIST_INSERT:
1693 case LFUN_THEOREM_INSERT:
1694 code = THEOREM_CODE;
1697 case LFUN_CAPTION_INSERT:
1698 code = CAPTION_CODE;
1700 case LFUN_NOTE_INSERT:
1703 case LFUN_FLEX_INSERT: {
1705 string s = cmd.getArg(0);
1706 InsetLayout il = cur.buffer().params().getTextClass().insetlayout(from_utf8(s));
1707 if (il.lyxtype != "charstyle" &&
1708 il.lyxtype != "custom" &&
1709 il.lyxtype != "element")
1713 case LFUN_BOX_INSERT:
1716 case LFUN_BRANCH_INSERT:
1718 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1721 case LFUN_LABEL_INSERT:
1724 case LFUN_INFO_INSERT:
1727 case LFUN_OPTIONAL_INSERT:
1729 enable = numberOfOptArgs(cur.paragraph())
1730 < cur.paragraph().layout()->optionalargs;
1732 case LFUN_ENVIRONMENT_INSERT:
1735 case LFUN_INDEX_INSERT:
1738 case LFUN_INDEX_PRINT:
1739 code = INDEX_PRINT_CODE;
1741 case LFUN_NOMENCL_INSERT:
1742 code = NOMENCL_CODE;
1744 case LFUN_NOMENCL_PRINT:
1745 code = NOMENCL_PRINT_CODE;
1747 case LFUN_TOC_INSERT:
1750 case LFUN_HTML_INSERT:
1751 case LFUN_URL_INSERT:
1754 case LFUN_QUOTE_INSERT:
1755 // always allow this, since we will inset a raw quote
1756 // if an inset is not allowed.
1758 case LFUN_HYPHENATION_POINT_INSERT:
1759 case LFUN_LIGATURE_BREAK_INSERT:
1760 case LFUN_HFILL_INSERT:
1761 case LFUN_MENU_SEPARATOR_INSERT:
1762 case LFUN_DOTS_INSERT:
1763 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
1764 code = SPECIALCHAR_CODE;
1766 case LFUN_SPACE_INSERT:
1767 // slight hack: we know this is allowed in math mode
1772 case LFUN_INSET_MODIFY:
1773 // We need to disable this, because we may get called for a
1775 // InsetTabular::getStatus() -> InsetText::getStatus()
1776 // and we don't handle LFUN_INSET_MODIFY.
1780 case LFUN_FONT_EMPH:
1781 flag.setOnOff(font.emph() == Font::ON);
1784 case LFUN_FONT_NOUN:
1785 flag.setOnOff(font.noun() == Font::ON);
1788 case LFUN_FONT_BOLD:
1789 flag.setOnOff(font.series() == Font::BOLD_SERIES);
1792 case LFUN_FONT_SANS:
1793 flag.setOnOff(font.family() == Font::SANS_FAMILY);
1796 case LFUN_FONT_ROMAN:
1797 flag.setOnOff(font.family() == Font::ROMAN_FAMILY);
1800 case LFUN_FONT_TYPEWRITER:
1801 flag.setOnOff(font.family() == Font::TYPEWRITER_FAMILY);
1806 enable = cur.selection();
1810 if (cmd.argument().empty()) {
1811 if (theClipboard().isInternal())
1812 enable = cap::numberOfSelections() > 0;
1814 enable = !theClipboard().empty();
1816 string const arg = to_utf8(cmd.argument());
1817 if (isStrUnsignedInt(arg)) {
1818 unsigned int n = convert<unsigned int>(arg);
1819 enable = cap::numberOfSelections() > n;
1826 case LFUN_CLIPBOARD_PASTE:
1827 enable = !theClipboard().empty();
1830 case LFUN_PRIMARY_SELECTION_PASTE:
1831 enable = cur.selection() || !theSelection().empty();
1834 case LFUN_PARAGRAPH_MOVE_UP:
1835 enable = cur.pit() > 0 && !cur.selection();
1838 case LFUN_PARAGRAPH_MOVE_DOWN:
1839 enable = cur.pit() < cur.lastpit() && !cur.selection();
1842 case LFUN_INSET_DISSOLVE:
1843 if (!cmd.argument().empty()) {
1844 InsetLayout il = cur.inset().getLayout(cur.buffer().params());
1845 enable = (cur.inset().lyxCode() == FLEX_CODE)
1846 && (il.lyxtype == to_utf8(cmd.argument()));
1848 enable = !isMainText(cur.bv().buffer())
1849 && cur.inset().nargs() == 1;
1852 case LFUN_CHANGE_ACCEPT:
1853 case LFUN_CHANGE_REJECT:
1854 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
1855 // In principle, these LFUNs should only be enabled if there
1856 // is a change at the current position/in the current selection.
1857 // However, without proper optimizations, this will inevitably
1858 // result in unacceptable performance - just imagine a user who
1859 // wants to select the complete content of a long document.
1863 case LFUN_WORD_DELETE_FORWARD:
1864 case LFUN_WORD_DELETE_BACKWARD:
1865 case LFUN_LINE_DELETE:
1866 case LFUN_WORD_FORWARD:
1867 case LFUN_WORD_BACKWARD:
1868 case LFUN_CHAR_FORWARD:
1869 case LFUN_CHAR_FORWARD_SELECT:
1870 case LFUN_CHAR_BACKWARD:
1871 case LFUN_CHAR_BACKWARD_SELECT:
1873 case LFUN_UP_SELECT:
1875 case LFUN_DOWN_SELECT:
1876 case LFUN_PARAGRAPH_UP_SELECT:
1877 case LFUN_PARAGRAPH_DOWN_SELECT:
1878 case LFUN_SCREEN_UP_SELECT:
1879 case LFUN_SCREEN_DOWN_SELECT:
1880 case LFUN_LINE_BEGIN_SELECT:
1881 case LFUN_LINE_END_SELECT:
1882 case LFUN_WORD_FORWARD_SELECT:
1883 case LFUN_WORD_BACKWARD_SELECT:
1884 case LFUN_WORD_SELECT:
1885 case LFUN_PARAGRAPH_UP:
1886 case LFUN_PARAGRAPH_DOWN:
1887 case LFUN_LINE_BEGIN:
1889 case LFUN_BREAK_LINE:
1890 case LFUN_CHAR_DELETE_FORWARD:
1891 case LFUN_DELETE_FORWARD_SKIP:
1892 case LFUN_CHAR_DELETE_BACKWARD:
1893 case LFUN_DELETE_BACKWARD_SKIP:
1894 case LFUN_BREAK_PARAGRAPH:
1895 case LFUN_BREAK_PARAGRAPH_SKIP:
1896 case LFUN_PARAGRAPH_SPACING:
1897 case LFUN_INSET_INSERT:
1898 case LFUN_WORD_UPCASE:
1899 case LFUN_WORD_LOWCASE:
1900 case LFUN_WORD_CAPITALIZE:
1901 case LFUN_CHARS_TRANSPOSE:
1902 case LFUN_SERVER_GET_XY:
1903 case LFUN_SERVER_SET_XY:
1904 case LFUN_SERVER_GET_FONT:
1905 case LFUN_SERVER_GET_LAYOUT:
1907 case LFUN_DATE_INSERT:
1908 case LFUN_SELF_INSERT:
1909 case LFUN_LINE_INSERT:
1910 case LFUN_PAGEBREAK_INSERT:
1911 case LFUN_CLEARPAGE_INSERT:
1912 case LFUN_CLEARDOUBLEPAGE_INSERT:
1913 case LFUN_MATH_DISPLAY:
1914 case LFUN_MATH_IMPORT_SELECTION:
1915 case LFUN_MATH_MODE:
1916 case LFUN_MATH_MACRO:
1917 case LFUN_MATH_MATRIX:
1918 case LFUN_MATH_DELIM:
1919 case LFUN_MATH_BIGDELIM:
1920 case LFUN_MATH_INSERT:
1921 case LFUN_MATH_SUBSCRIPT:
1922 case LFUN_MATH_SUPERSCRIPT:
1923 case LFUN_FONT_DEFAULT:
1924 case LFUN_FONT_UNDERLINE:
1925 case LFUN_FONT_SIZE:
1927 case LFUN_FONT_FREE_APPLY:
1928 case LFUN_FONT_FREE_UPDATE:
1929 case LFUN_LAYOUT_PARAGRAPH:
1930 case LFUN_PARAGRAPH_UPDATE:
1931 case LFUN_ACCENT_UMLAUT:
1932 case LFUN_ACCENT_CIRCUMFLEX:
1933 case LFUN_ACCENT_GRAVE:
1934 case LFUN_ACCENT_ACUTE:
1935 case LFUN_ACCENT_TILDE:
1936 case LFUN_ACCENT_CEDILLA:
1937 case LFUN_ACCENT_MACRON:
1938 case LFUN_ACCENT_DOT:
1939 case LFUN_ACCENT_UNDERDOT:
1940 case LFUN_ACCENT_UNDERBAR:
1941 case LFUN_ACCENT_CARON:
1942 case LFUN_ACCENT_SPECIAL_CARON:
1943 case LFUN_ACCENT_BREVE:
1944 case LFUN_ACCENT_TIE:
1945 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1946 case LFUN_ACCENT_CIRCLE:
1947 case LFUN_ACCENT_OGONEK:
1948 case LFUN_THESAURUS_ENTRY:
1949 case LFUN_PARAGRAPH_PARAMS_APPLY:
1950 case LFUN_PARAGRAPH_PARAMS:
1952 case LFUN_BUFFER_END:
1953 case LFUN_BUFFER_BEGIN:
1954 case LFUN_BUFFER_BEGIN_SELECT:
1955 case LFUN_BUFFER_END_SELECT:
1956 case LFUN_UNICODE_INSERT:
1957 // these are handled in our dispatch()
1966 && (cur.empty() || !cur.inset().insetAllowed(code)))
1969 flag.enabled(enable);
1974 void Text::pasteString(Cursor & cur, docstring const & clip,
1977 cur.clearSelection();
1978 if (!clip.empty()) {
1981 insertStringAsParagraphs(cur, clip);
1983 insertStringAsLines(cur, clip);