3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Asger Alstrup
7 * \author Lars Gullik Bjønnes
8 * \author Alfredo Braunstein
9 * \author Angus Leeming
11 * \author André Pönitz
13 * Full author contact details are available in file CREDITS.
20 #include "BranchList.h"
21 #include "FloatList.h"
22 #include "FuncStatus.h"
24 #include "buffer_funcs.h"
25 #include "BufferParams.h"
26 #include "BufferView.h"
27 #include "bufferview_funcs.h"
29 #include "CoordCache.h"
30 #include "CutAndPaste.h"
32 #include "DispatchResult.h"
33 #include "ErrorList.h"
35 #include "FuncRequest.h"
39 #include "LyXAction.h"
44 #include "Paragraph.h"
45 #include "paragraph_funcs.h"
46 #include "ParagraphParameters.h"
49 #include "ParIterator.h"
51 #include "frontends/Clipboard.h"
52 #include "frontends/Selection.h"
54 #include "insets/InsetCommand.h"
55 #include "insets/InsetFloatList.h"
56 #include "insets/InsetNewline.h"
57 #include "insets/InsetQuotes.h"
58 #include "insets/InsetSpecialChar.h"
59 #include "insets/InsetText.h"
61 #include "support/lstrings.h"
62 #include "support/lyxlib.h"
63 #include "support/convert.h"
64 #include "support/lyxtime.h"
66 #include "mathed/InsetMathHull.h"
67 #include "mathed/MathMacroTemplate.h"
69 #include <boost/current_function.hpp>
77 using cap::copySelection;
78 using cap::cutSelection;
79 using cap::pasteFromStack;
80 using cap::pasteClipboard;
81 using cap::replaceSelection;
83 using support::isStrUnsignedInt;
88 using std::istringstream;
89 using std::ostringstream;
92 extern docstring current_layout;
98 Font freefont(Font::ALL_IGNORE);
99 bool toggleall = false;
101 void toggleAndShow(Cursor & cur, Text * text,
102 Font const & font, bool toggleall = true)
104 text->toggleFree(cur, font, toggleall);
106 if (font.language() != ignore_language ||
107 font.number() != Font::IGNORE) {
108 Paragraph & par = cur.paragraph();
109 if (cur.boundary() != text->isRTLBoundary(cur.buffer(), par,
110 cur.pos(), text->real_current_font))
111 text->setCursor(cur, cur.pit(), cur.pos(),
112 false, !cur.boundary());
117 void moveCursor(Cursor & cur, bool selecting)
119 if (selecting || cur.mark())
124 void finishChange(Cursor & cur, bool selecting)
127 moveCursor(cur, selecting);
131 void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
134 docstring sel = cur.selectionAsString(false);
136 // It may happen that sel is empty but there is a selection
137 replaceSelection(cur);
140 #ifdef ENABLE_ASSERTIONS
141 const int old_pos = cur.pos();
143 cur.insert(new InsetMathHull(hullSimple));
144 BOOST_ASSERT(old_pos == cur.pos());
145 cur.nextInset()->edit(cur, true);
146 // don't do that also for LFUN_MATH_MODE
147 // unless you want end up with always changing
148 // to mathrm when opening an inlined inset --
149 // I really hate "LyXfunc overloading"...
151 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
152 // Avoid an unnecessary undo step if cmd.argument
154 if (!cmd.argument().empty())
155 cur.dispatch(FuncRequest(LFUN_MATH_INSERT,
158 // create a macro if we see "\\newcommand"
159 // somewhere, and an ordinary formula
161 if (sel.find(from_ascii("\\newcommand")) == string::npos
162 && sel.find(from_ascii("\\def")) == string::npos)
164 InsetMathHull * formula = new InsetMathHull;
165 istringstream is(to_utf8(sel));
168 formula->read(cur.buffer(), lex);
169 if (formula->getType() == hullNone)
170 // Don't create pseudo formulas if
171 // delimiters are left out
172 formula->mutate(hullSimple);
175 cur.insert(new MathMacroTemplate(sel));
178 cur.message(from_utf8(N_("Math editor mode")));
187 string const freefont2string()
190 if (font2string(freefont, toggleall, data))
197 void Text::cursorPrevious(Cursor & cur)
199 pos_type cpos = cur.pos();
200 pit_type cpar = cur.pit();
202 int x = cur.x_target();
203 setCursorFromCoordinates(cur, x, 0);
204 cur.dispatch(FuncRequest(cur.selection()? LFUN_UP_SELECT: LFUN_UP));
206 if (cpar == cur.pit() && cpos == cur.pos())
207 // we have a row which is taller than the workarea. The
208 // simplest solution is to move to the previous row instead.
209 cur.dispatch(FuncRequest(cur.selection()? LFUN_UP_SELECT: LFUN_UP));
212 cur.updateFlags(Update::Force | Update::FitCursor);
216 void Text::cursorNext(Cursor & cur)
218 pos_type cpos = cur.pos();
219 pit_type cpar = cur.pit();
221 int x = cur.x_target();
222 setCursorFromCoordinates(cur, x, cur.bv().workHeight() - 1);
223 cur.dispatch(FuncRequest(cur.selection()? LFUN_DOWN_SELECT: LFUN_DOWN));
225 if (cpar == cur.pit() && cpos == cur.pos())
226 // we have a row which is taller than the workarea. The
227 // simplest solution is to move to the next row instead.
229 FuncRequest(cur.selection()? LFUN_DOWN_SELECT: LFUN_DOWN));
232 cur.updateFlags(Update::Force | Update::FitCursor);
238 void specialChar(Cursor & cur, InsetSpecialChar::Kind kind)
241 cap::replaceSelection(cur);
242 cur.insert(new InsetSpecialChar(kind));
247 bool doInsertInset(Cursor & cur, Text * text,
248 FuncRequest const & cmd, bool edit, bool pastesel)
250 Inset * inset = createInset(&cur.bv(), cmd);
256 if (cur.selection()) {
257 lyx::dispatch(FuncRequest(LFUN_CUT));
260 text->insertInset(cur, inset);
263 inset->edit(cur, true);
265 if (gotsel && pastesel) {
266 lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
267 // reset first par to default
268 if (cur.lastpit() != 0 || cur.lastpos() != 0) {
269 Layout_ptr const layout =
270 cur.buffer().params().getTextClass().defaultLayout();
271 cur.text()->paragraphs().begin()->layout(layout);
281 void Text::number(Cursor & cur)
283 Font font(Font::ALL_IGNORE);
284 font.setNumber(Font::TOGGLE);
285 toggleAndShow(cur, this, font);
289 bool Text::isRTL(Buffer const & buffer, Paragraph const & par) const
291 return par.isRightToLeftPar(buffer.params());
295 bool Text::isRTL(Buffer const & buffer, CursorSlice const & sl, bool boundary) const
297 if (!lyxrc.rtl_support && !sl.text())
301 if (boundary && sl.pos() > 0)
304 Paragraph const & par = getPar(sl.pit());
305 return getFont(buffer, par, sl.pos() + correction).isVisibleRightToLeft();
309 bool Text::isRTLBoundary(Buffer const & buffer, Paragraph const & par,
312 if (!lyxrc.rtl_support)
315 // no RTL boundary at line start
319 bool left = getFont(buffer, par, pos - 1).isVisibleRightToLeft();
321 if (pos == par.size())
322 right = par.isRightToLeftPar(buffer.params());
324 right = getFont(buffer, par, pos).isVisibleRightToLeft();
325 return left != right;
329 bool Text::isRTLBoundary(Buffer const & buffer, Paragraph const & par,
330 pos_type pos, Font const & font) const
332 if (!lyxrc.rtl_support)
335 bool left = font.isVisibleRightToLeft();
337 if (pos == par.size())
338 right = par.isRightToLeftPar(buffer.params());
340 right = getFont(buffer, par, pos).isVisibleRightToLeft();
341 return left != right;
345 void Text::dispatch(Cursor & cur, FuncRequest & cmd)
347 LYXERR(Debug::ACTION) << "Text::dispatch: cmd: " << cmd << endl;
349 // FIXME: We use the update flag to indicates wether a singlePar or a
350 // full screen update is needed. We reset it here but shall we restore it
354 BOOST_ASSERT(cur.text() == this);
355 BufferView * bv = &cur.bv();
356 CursorSlice oldTopSlice = cur.top();
357 bool oldBoundary = cur.boundary();
358 bool sel = cur.selection();
359 // Signals that, even if needsUpdate == false, an update of the
360 // cursor paragraph is required
361 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
362 LyXAction::SingleParUpdate);
363 // Signals that a full-screen update is required
364 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
365 LyXAction::NoUpdate) || singleParUpdate);
366 // Remember the old paragraph metric (_outer_ paragraph!)
367 ParagraphMetrics const & pm = cur.bv().parMetrics(
368 cur.bottom().text(), cur.bottom().pit());
369 Dimension olddim = pm.dim();
371 switch (cmd.action) {
373 case LFUN_PARAGRAPH_MOVE_DOWN: {
374 pit_type const pit = cur.pit();
375 recUndo(cur, pit, pit + 1);
377 std::swap(pars_[pit], pars_[pit + 1]);
378 updateLabels(cur.buffer());
384 case LFUN_PARAGRAPH_MOVE_UP: {
385 pit_type const pit = cur.pit();
386 recUndo(cur, pit - 1, pit);
388 std::swap(pars_[pit], pars_[pit - 1]);
389 updateLabels(cur.buffer());
395 case LFUN_APPENDIX: {
396 Paragraph & par = cur.paragraph();
397 bool start = !par.params().startOfAppendix();
400 #warning The code below only makes sense at top level.
401 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
403 // ensure that we have only one start_of_appendix in this document
404 // FIXME: this don't work for multipart document!
405 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
406 if (pars_[tmp].params().startOfAppendix()) {
408 pars_[tmp].params().startOfAppendix(false);
414 par.params().startOfAppendix(start);
416 // we can set the refreshing parameters now
417 updateLabels(cur.buffer());
421 case LFUN_WORD_DELETE_FORWARD:
422 if (cur.selection()) {
423 cutSelection(cur, true, false);
425 deleteWordForward(cur);
426 finishChange(cur, false);
429 case LFUN_WORD_DELETE_BACKWARD:
430 if (cur.selection()) {
431 cutSelection(cur, true, false);
433 deleteWordBackward(cur);
434 finishChange(cur, false);
437 case LFUN_LINE_DELETE:
438 if (cur.selection()) {
439 cutSelection(cur, true, false);
441 deleteLineForward(cur);
442 finishChange(cur, false);
445 case LFUN_BUFFER_BEGIN:
446 case LFUN_BUFFER_BEGIN_SELECT:
447 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
448 if (cur.depth() == 1) {
449 needsUpdate |= cursorTop(cur);
455 case LFUN_BUFFER_END:
456 case LFUN_BUFFER_END_SELECT:
457 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
458 if (cur.depth() == 1) {
459 needsUpdate |= cursorBottom(cur);
465 case LFUN_CHAR_FORWARD:
466 case LFUN_CHAR_FORWARD_SELECT:
467 //lyxerr << BOOST_CURRENT_FUNCTION
468 // << " LFUN_CHAR_FORWARD[SEL]:\n" << cur << endl;
469 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
470 if (reverseDirectionNeeded(cur))
471 needsUpdate |= cursorLeft(cur);
473 needsUpdate |= cursorRight(cur);
475 if (!needsUpdate && oldTopSlice == cur.top()
476 && cur.boundary() == oldBoundary) {
478 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
482 case LFUN_CHAR_BACKWARD:
483 case LFUN_CHAR_BACKWARD_SELECT:
484 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
485 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
486 if (reverseDirectionNeeded(cur))
487 needsUpdate |= cursorRight(cur);
489 needsUpdate |= cursorLeft(cur);
491 if (!needsUpdate && oldTopSlice == cur.top()
492 && cur.boundary() == oldBoundary) {
494 cmd = FuncRequest(LFUN_FINISHED_LEFT);
499 case LFUN_DOWN_SELECT:
502 // stop/start the selection
503 bool select = cmd.action == LFUN_DOWN_SELECT ||
504 cmd.action == LFUN_UP_SELECT;
505 cur.selHandle(select);
507 // move cursor up/down
508 bool up = cmd.action == LFUN_UP_SELECT || cmd.action == LFUN_UP;
509 bool const successful = cur.upDownInText(up, needsUpdate);
511 // notify insets which were left and get their update flags
512 notifyCursorLeaves(cur.beforeDispatchCursor(), cur);
515 // redraw if you leave mathed (for the decorations)
516 needsUpdate |= cur.beforeDispatchCursor().inMathed();
523 case LFUN_PARAGRAPH_UP:
524 case LFUN_PARAGRAPH_UP_SELECT:
525 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
526 needsUpdate |= cursorUpParagraph(cur);
529 case LFUN_PARAGRAPH_DOWN:
530 case LFUN_PARAGRAPH_DOWN_SELECT:
531 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
532 needsUpdate |= cursorDownParagraph(cur);
536 case LFUN_SCREEN_UP_SELECT:
537 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_UP_SELECT);
538 if (cur.pit() == 0 && cur.textRow().pos() == 0)
545 case LFUN_SCREEN_DOWN:
546 case LFUN_SCREEN_DOWN_SELECT:
547 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_DOWN_SELECT);
548 if (cur.pit() == cur.lastpit()
549 && cur.textRow().endpos() == cur.lastpos())
556 case LFUN_LINE_BEGIN:
557 case LFUN_LINE_BEGIN_SELECT:
558 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
559 needsUpdate |= cursorHome(cur);
563 case LFUN_LINE_END_SELECT:
564 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
565 needsUpdate |= cursorEnd(cur);
568 case LFUN_WORD_FORWARD:
569 case LFUN_WORD_FORWARD_SELECT:
570 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
571 if (reverseDirectionNeeded(cur))
572 needsUpdate |= cursorLeftOneWord(cur);
574 needsUpdate |= cursorRightOneWord(cur);
577 case LFUN_WORD_BACKWARD:
578 case LFUN_WORD_BACKWARD_SELECT:
579 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
580 if (reverseDirectionNeeded(cur))
581 needsUpdate |= cursorRightOneWord(cur);
583 needsUpdate |= cursorLeftOneWord(cur);
586 case LFUN_WORD_SELECT: {
587 selectWord(cur, WHOLE_WORD);
588 finishChange(cur, true);
592 case LFUN_BREAK_LINE: {
593 // Not allowed by LaTeX (labels or empty par)
594 if (cur.pos() > cur.paragraph().beginOfBody()) {
595 // this avoids a double undo
596 // FIXME: should not be needed, ideally
597 if (!cur.selection())
599 cap::replaceSelection(cur);
600 cur.insert(new InsetNewline);
602 moveCursor(cur, false);
607 case LFUN_CHAR_DELETE_FORWARD:
608 if (!cur.selection()) {
609 if (cur.pos() == cur.paragraph().size())
610 // Par boundary, force full-screen update
611 singleParUpdate = false;
612 needsUpdate |= erase(cur);
614 // It is possible to make it a lot faster still
615 // just comment out the line below...
617 cutSelection(cur, true, false);
618 singleParUpdate = false;
620 moveCursor(cur, false);
623 case LFUN_DELETE_FORWARD_SKIP:
624 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
625 if (!cur.selection()) {
626 if (cur.pos() == cur.lastpos()) {
633 cutSelection(cur, true, false);
638 case LFUN_CHAR_DELETE_BACKWARD:
639 if (!cur.selection()) {
640 if (bv->getIntl().getTransManager().backspace()) {
641 // Par boundary, full-screen update
643 singleParUpdate = false;
644 needsUpdate |= backspace(cur);
646 // It is possible to make it a lot faster still
647 // just comment out the line below...
650 cutSelection(cur, true, false);
651 singleParUpdate = false;
655 case LFUN_DELETE_BACKWARD_SKIP:
656 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
657 if (!cur.selection()) {
661 //CursorSlice cur = cursor();
665 cutSelection(cur, true, false);
669 case LFUN_BREAK_PARAGRAPH:
670 cap::replaceSelection(cur);
671 breakParagraph(cur, 0);
675 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
676 cap::replaceSelection(cur);
677 breakParagraph(cur, 1);
681 case LFUN_BREAK_PARAGRAPH_SKIP: {
682 // When at the beginning of a paragraph, remove
683 // indentation. Otherwise, do the same as LFUN_BREAK_PARAGRAPH.
684 cap::replaceSelection(cur);
686 cur.paragraph().params().labelWidthString(docstring());
688 breakParagraph(cur, 0);
693 case LFUN_PARAGRAPH_SPACING: {
694 Paragraph & par = cur.paragraph();
695 Spacing::Space cur_spacing = par.params().spacing().getSpace();
696 string cur_value = "1.0";
697 if (cur_spacing == Spacing::Other)
698 cur_value = par.params().spacing().getValueAsString();
700 istringstream is(to_utf8(cmd.argument()));
703 Spacing::Space new_spacing = cur_spacing;
704 string new_value = cur_value;
706 lyxerr << "Missing argument to `paragraph-spacing'"
708 } else if (tmp == "single") {
709 new_spacing = Spacing::Single;
710 } else if (tmp == "onehalf") {
711 new_spacing = Spacing::Onehalf;
712 } else if (tmp == "double") {
713 new_spacing = Spacing::Double;
714 } else if (tmp == "other") {
715 new_spacing = Spacing::Other;
716 string tmpval = "0.0";
718 lyxerr << "new_value = " << tmpval << endl;
721 } else if (tmp == "default") {
722 new_spacing = Spacing::Default;
724 lyxerr << to_utf8(_("Unknown spacing argument: "))
725 << to_utf8(cmd.argument()) << endl;
727 if (cur_spacing != new_spacing || cur_value != new_value)
728 par.params().spacing(Spacing(new_spacing, new_value));
732 case LFUN_INSET_INSERT: {
734 Inset * inset = createInset(bv, cmd);
736 // FIXME (Abdel 01/02/2006):
737 // What follows would be a partial fix for bug 2154:
738 // http://bugzilla.lyx.org/show_bug.cgi?id=2154
739 // This automatically put the label inset _after_ a
740 // numbered section. It should be possible to extend the mechanism
741 // to any kind of LateX environement.
742 // The correct way to fix that bug would be at LateX generation.
743 // I'll let the code here for reference as it could be used for some
744 // other feature like "automatic labelling".
746 Paragraph & par = pars_[cur.pit()];
747 if (inset->lyxCode() == Inset::LABEL_CODE
748 && par.layout()->labeltype == LABEL_COUNTER) {
749 // Go to the end of the paragraph
750 // Warning: Because of Change-Tracking, the last
751 // position is 'size()' and not 'size()-1':
752 cur.pos() = par.size();
753 // Insert a new paragraph
754 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
759 cutSelection(cur, true, false);
760 insertInset(cur, inset);
766 case LFUN_INSET_DISSOLVE:
767 needsUpdate |= dissolveInset(cur);
770 case LFUN_INSET_SETTINGS:
771 cur.inset().showInsetDialog(bv);
774 case LFUN_SPACE_INSERT:
775 if (cur.paragraph().layout()->free_spacing)
776 insertChar(cur, ' ');
778 doInsertInset(cur, this, cmd, false, false);
781 moveCursor(cur, false);
784 case LFUN_HYPHENATION_POINT_INSERT:
785 specialChar(cur, InsetSpecialChar::HYPHENATION);
788 case LFUN_LIGATURE_BREAK_INSERT:
789 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
792 case LFUN_DOTS_INSERT:
793 specialChar(cur, InsetSpecialChar::LDOTS);
796 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
797 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
800 case LFUN_MENU_SEPARATOR_INSERT:
801 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
804 case LFUN_WORD_UPCASE:
805 changeCase(cur, Text::text_uppercase);
808 case LFUN_WORD_LOWCASE:
809 changeCase(cur, Text::text_lowercase);
812 case LFUN_WORD_CAPITALIZE:
813 changeCase(cur, Text::text_capitalization);
816 case LFUN_CHARS_TRANSPOSE:
821 cur.message(_("Paste"));
822 cap::replaceSelection(cur);
823 if (cmd.argument().empty() && !theClipboard().isInternal())
824 pasteClipboard(cur, bv->buffer()->errorList("Paste"));
826 string const arg(to_utf8(cmd.argument()));
827 pasteFromStack(cur, bv->buffer()->errorList("Paste"),
828 isStrUnsignedInt(arg) ?
829 convert<unsigned int>(arg) :
832 bv->buffer()->errors("Paste");
833 cur.clearSelection(); // bug 393
838 cutSelection(cur, true, true);
839 cur.message(_("Cut"));
844 cur.message(_("Copy"));
847 case LFUN_SERVER_GET_XY:
848 cur.message(from_utf8(
849 convert<string>(cursorX(cur.bv(), cur.top(), cur.boundary()))
850 + ' ' + convert<string>(cursorY(cur.bv(), cur.top(), cur.boundary()))));
853 case LFUN_SERVER_SET_XY: {
856 istringstream is(to_utf8(cmd.argument()));
859 lyxerr << "SETXY: Could not parse coordinates in '"
860 << to_utf8(cmd.argument()) << std::endl;
862 setCursorFromCoordinates(cur, x, y);
866 case LFUN_SERVER_GET_FONT:
867 if (current_font.shape() == Font::ITALIC_SHAPE)
868 cur.message(from_ascii("E"));
869 else if (current_font.shape() == Font::SMALLCAPS_SHAPE)
870 cur.message(from_ascii("N"));
872 cur.message(from_ascii("0"));
875 case LFUN_SERVER_GET_LAYOUT:
876 cur.message(cur.paragraph().layout()->name());
880 docstring layout = cmd.argument();
881 LYXERR(Debug::INFO) << "LFUN_LAYOUT: (arg) " << to_utf8(layout) << endl;
883 // Derive layout number from given argument (string)
884 // and current buffer's textclass (number)
885 TextClass const & tclass = bv->buffer()->params().getTextClass();
887 layout = tclass.defaultLayoutName();
888 bool hasLayout = tclass.hasLayout(layout);
890 // If the entry is obsolete, use the new one instead.
892 docstring const & obs = tclass[layout]->obsoleted_by();
898 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
899 from_utf8(N_(" not known")));
903 bool change_layout = (current_layout != layout);
905 if (!change_layout && cur.selection() &&
906 cur.selBegin().pit() != cur.selEnd().pit())
908 pit_type spit = cur.selBegin().pit();
909 pit_type epit = cur.selEnd().pit() + 1;
910 while (spit != epit) {
911 if (pars_[spit].layout()->name() != current_layout) {
912 change_layout = true;
920 setLayout(cur, layout);
921 // inform the GUI that the layout has changed.
922 bv->layoutChanged(layout);
927 case LFUN_CLIPBOARD_PASTE:
928 cur.clearSelection();
929 pasteClipboard(cur, bv->buffer()->errorList("Paste"),
930 cmd.argument() == "paragraph");
931 bv->buffer()->errors("Paste");
934 case LFUN_PRIMARY_SELECTION_PASTE:
935 pasteString(cur, theSelection().get(),
936 cmd.argument() == "paragraph");
939 case LFUN_UNICODE_INSERT: {
940 if (cmd.argument().empty())
942 docstring hexstring = cmd.argument();
943 if (lyx::support::isHex(hexstring)) {
944 char_type c = lyx::support::hexToInt(hexstring);
945 if (c >= 32 && c < 0x10ffff) {
946 lyxerr << "Inserting c: " << c << endl;
947 docstring s = docstring(1, c);
948 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
954 case LFUN_QUOTE_INSERT: {
955 Paragraph & par = cur.paragraph();
956 pos_type pos = cur.pos();
957 BufferParams const & bufparams = bv->buffer()->params();
958 Layout_ptr const & style = par.layout();
959 if (!style->pass_thru
960 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
961 // this avoids a double undo
962 // FIXME: should not be needed, ideally
963 if (!cur.selection())
965 cap::replaceSelection(cur);
970 else if (cur.prevInset() && cur.prevInset()->isSpace())
973 c = par.getChar(pos - 1);
974 string arg = to_utf8(cmd.argument());
976 cur.insert(new InsetQuotes(c,
977 bufparams.quotes_language,
978 InsetQuotes::SingleQ));
980 cur.insert(new InsetQuotes(c,
981 bufparams.quotes_language,
982 InsetQuotes::DoubleQ));
986 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
990 case LFUN_DATE_INSERT:
991 if (cmd.argument().empty())
992 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
993 formatted_time(current_time())));
995 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
996 formatted_time(current_time(), to_utf8(cmd.argument()))));
999 case LFUN_MOUSE_TRIPLE:
1000 if (cmd.button() == mouse_button::button1) {
1009 case LFUN_MOUSE_DOUBLE:
1010 if (cmd.button() == mouse_button::button1) {
1011 selectWord(cur, WHOLE_WORD_STRICT);
1016 // Single-click on work area
1017 case LFUN_MOUSE_PRESS: {
1018 // Right click on a footnote flag opens float menu
1019 if (cmd.button() == mouse_button::button3)
1020 cur.clearSelection();
1023 bool update = bv->mouseSetCursor(cur);
1025 // Insert primary selection with middle mouse
1026 // if there is a local selection in the current buffer,
1028 if (cmd.button() == mouse_button::button2) {
1029 if (cap::selection()) {
1030 // Copy the selection buffer to the clipboard
1031 // stack, because we want it to appear in the
1032 // "Edit->Paste recent" menu.
1033 cap::copySelectionToStack();
1035 cap::pasteSelection(bv->cursor(),
1036 bv->buffer()->errorList("Paste"));
1037 bv->buffer()->errors("Paste");
1038 bv->buffer()->markDirty();
1041 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
1045 // we have to update after dEPM triggered
1046 if (!update && cmd.button() == mouse_button::button1) {
1047 needsUpdate = false;
1054 case LFUN_MOUSE_MOTION: {
1055 // Only use motion with button 1
1056 //if (cmd.button() != mouse_button::button1)
1059 // ignore motions deeper nested than the real anchor
1060 Cursor & bvcur = cur.bv().cursor();
1061 if (bvcur.anchor_.hasPart(cur)) {
1062 CursorSlice old = bvcur.top();
1064 int const wh = bv->workHeight();
1065 int const y = std::max(0, std::min(wh - 1, cmd.y));
1067 setCursorFromCoordinates(cur, cmd.x, y);
1068 cur.setTargetX(cmd.x);
1070 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1072 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1073 // This is to allow jumping over large insets
1074 if (cur.top() == old) {
1076 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1078 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1081 if (cur.top() == old)
1084 // don't set anchor_
1085 bvcur.setCursor(cur);
1086 bvcur.selection() = true;
1087 //lyxerr << "MOTION: " << bv->cursor() << endl;
1095 case LFUN_MOUSE_RELEASE: {
1096 if (cmd.button() == mouse_button::button2)
1099 if (cmd.button() == mouse_button::button1) {
1100 // if there is new selection, update persistent
1101 // selection, otherwise, single click does not
1102 // clear persistent selection buffer
1103 if (cur.selection()) {
1105 // if double click, cur is moved to the end of word by selectWord
1106 // but bvcur is current mouse position
1107 Cursor & bvcur = cur.bv().cursor();
1108 bvcur.selection() = true;
1110 needsUpdate = false;
1117 case LFUN_SELF_INSERT: {
1118 if (cmd.argument().empty())
1121 // Automatically delete the currently selected
1122 // text and replace it with what is being
1123 // typed in now. Depends on lyxrc settings
1124 // "auto_region_delete", which defaults to
1127 if (lyxrc.auto_region_delete && cur.selection()) {
1128 cutSelection(cur, false, false);
1129 // When change tracking is set to off, the metrics update
1130 // mechanism correctly detects if a full update is needed or not.
1131 // This detection fails when a selection spans multiple rows and
1132 // change tracking is enabled because the paragraph metrics stays
1133 // the same. In this case, we force the full update:
1134 // (see http://bugzilla.lyx.org/show_bug.cgi?id=3992)
1135 if (cur.buffer().params().trackChanges)
1136 cur.updateFlags(Update::Force);
1139 cur.clearSelection();
1140 Font const old_font = real_current_font;
1142 docstring::const_iterator cit = cmd.argument().begin();
1143 docstring::const_iterator end = cmd.argument().end();
1144 for (; cit != end; ++cit)
1145 bv->translateAndInsert(*cit, this, cur);
1148 moveCursor(cur, false);
1152 case LFUN_URL_INSERT: {
1153 InsetCommandParams p("url");
1155 if (cur.selection()) {
1156 content = cur.selectionAsString(false);
1157 cutSelection(cur, true, false);
1159 p["target"] = (cmd.argument().empty()) ?
1160 content : cmd.argument();
1161 string const data = InsetCommandMailer::params2string("url", p);
1162 if (p["target"].empty()) {
1163 bv->showInsetDialog("url", data, 0);
1165 FuncRequest fr(LFUN_INSET_INSERT, data);
1171 case LFUN_HTML_INSERT: {
1172 InsetCommandParams p("htmlurl");
1174 if (cur.selection()) {
1175 content = cur.selectionAsString(false);
1176 cutSelection(cur, true, false);
1178 p["target"] = (cmd.argument().empty()) ?
1179 content : cmd.argument();
1180 string const data = InsetCommandMailer::params2string("url", p);
1181 if (p["target"].empty()) {
1182 bv->showInsetDialog("url", data, 0);
1184 FuncRequest fr(LFUN_INSET_INSERT, data);
1190 case LFUN_LABEL_INSERT: {
1191 InsetCommandParams p("label");
1192 // Try to generate a valid label
1193 p["name"] = (cmd.argument().empty()) ?
1194 cur.getPossibleLabel() :
1196 string const data = InsetCommandMailer::params2string("label", p);
1198 if (cmd.argument().empty()) {
1199 bv->showInsetDialog("label", data, 0);
1201 FuncRequest fr(LFUN_INSET_INSERT, data);
1209 case LFUN_LIST_INSERT:
1210 case LFUN_THEOREM_INSERT:
1212 case LFUN_CAPTION_INSERT:
1213 // Open the inset, and move the current selection
1215 doInsertInset(cur, this, cmd, true, true);
1217 updateLabels(*bv->buffer());
1219 case LFUN_NOTE_INSERT:
1220 case LFUN_CHARSTYLE_INSERT:
1221 case LFUN_BOX_INSERT:
1222 case LFUN_BRANCH_INSERT:
1223 case LFUN_BIBITEM_INSERT:
1224 case LFUN_ERT_INSERT:
1225 case LFUN_LISTING_INSERT:
1226 case LFUN_FOOTNOTE_INSERT:
1227 case LFUN_MARGINALNOTE_INSERT:
1228 case LFUN_OPTIONAL_INSERT:
1229 case LFUN_ENVIRONMENT_INSERT:
1230 // Open the inset, and move the current selection
1232 doInsertInset(cur, this, cmd, true, true);
1236 case LFUN_TABULAR_INSERT:
1237 // if there were no arguments, just open the dialog
1238 if (doInsertInset(cur, this, cmd, false, true))
1241 bv->showDialog("tabularcreate");
1245 case LFUN_FLOAT_INSERT:
1246 case LFUN_FLOAT_WIDE_INSERT:
1247 case LFUN_WRAP_INSERT: {
1248 bool content = cur.selection(); // will some text be moved into the inset?
1250 doInsertInset(cur, this, cmd, true, true);
1252 ParagraphList & pars = cur.text()->paragraphs();
1254 TextClass const & tclass = bv->buffer()->params().getTextClass();
1256 // add a separate paragraph for the caption inset
1257 pars.push_back(Paragraph());
1258 pars.back().setInsetOwner(pars[0].inInset());
1259 pars.back().layout(tclass.defaultLayout());
1261 int cap_pit = pars.size() - 1;
1263 // if an empty inset was created, we create an additional empty
1264 // paragraph at the bottom so that the user can choose where to put
1265 // the graphics (or table).
1267 pars.push_back(Paragraph());
1268 pars.back().setInsetOwner(pars[0].inInset());
1269 pars.back().layout(tclass.defaultLayout());
1273 // reposition the cursor to the caption
1274 cur.pit() = cap_pit;
1276 cur.dispatch(FuncRequest(LFUN_CAPTION_INSERT));
1277 // FIXME: When leaving the Float (or Wrap) inset we should
1278 // delete any empty paragraph left above or below the
1283 case LFUN_INDEX_INSERT:
1284 case LFUN_NOMENCL_INSERT: {
1285 Inset * inset = createInset(&cur.bv(), cmd);
1289 cur.clearSelection();
1290 insertInset(cur, inset);
1291 inset->edit(cur, true);
1292 // Show the dialog for the nomenclature entry, since the
1293 // description entry still needs to be filled in.
1294 if (cmd.action == LFUN_NOMENCL_INSERT)
1295 InsetCommandMailer("nomenclature",
1296 *reinterpret_cast<InsetCommand *>(inset)).showDialog(&cur.bv());
1301 case LFUN_INDEX_PRINT:
1302 case LFUN_NOMENCL_PRINT:
1303 case LFUN_TOC_INSERT:
1304 case LFUN_HFILL_INSERT:
1305 case LFUN_LINE_INSERT:
1306 case LFUN_PAGEBREAK_INSERT:
1307 case LFUN_CLEARPAGE_INSERT:
1308 case LFUN_CLEARDOUBLEPAGE_INSERT:
1310 doInsertInset(cur, this, cmd, false, false);
1314 case LFUN_DEPTH_DECREMENT:
1315 changeDepth(cur, DEC_DEPTH);
1318 case LFUN_DEPTH_INCREMENT:
1319 changeDepth(cur, INC_DEPTH);
1322 case LFUN_MATH_DISPLAY:
1323 mathDispatch(cur, cmd, true);
1326 case LFUN_MATH_IMPORT_SELECTION:
1327 case LFUN_MATH_MODE:
1328 if (cmd.argument() == "on")
1329 // don't pass "on" as argument
1330 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1332 mathDispatch(cur, cmd, false);
1335 case LFUN_MATH_MACRO:
1336 if (cmd.argument().empty())
1337 cur.errorMessage(from_utf8(N_("Missing argument")));
1339 string s = to_utf8(cmd.argument());
1340 string const s1 = token(s, ' ', 1);
1341 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1342 string const s2 = token(s, ' ', 2);
1343 string const type = s2.empty() ? "newcommand" : s2;
1344 cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, from_utf8(type)));
1345 //cur.nextInset()->edit(cur, true);
1349 // passthrough hat and underscore outside mathed:
1350 case LFUN_MATH_SUBSCRIPT:
1351 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1353 case LFUN_MATH_SUPERSCRIPT:
1354 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1357 case LFUN_MATH_INSERT:
1358 case LFUN_MATH_MATRIX:
1359 case LFUN_MATH_DELIM:
1360 case LFUN_MATH_BIGDELIM: {
1361 if (cur.selection())
1362 cur.clearSelection();
1363 // FIXME: instead of the above, this one
1364 // should be used (but it asserts with Bidi enabled)
1365 // cf. http://bugzilla.lyx.org/show_bug.cgi?id=4055
1366 // cap::replaceSelection(cur);
1367 cur.insert(new InsetMathHull(hullSimple));
1368 checkAndActivateInset(cur, true);
1369 BOOST_ASSERT(cur.inMathed());
1374 case LFUN_FONT_EMPH: {
1375 Font font(Font::ALL_IGNORE);
1376 font.setEmph(Font::TOGGLE);
1377 toggleAndShow(cur, this, font);
1381 case LFUN_FONT_BOLD: {
1382 Font font(Font::ALL_IGNORE);
1383 font.setSeries(Font::BOLD_SERIES);
1384 toggleAndShow(cur, this, font);
1388 case LFUN_FONT_NOUN: {
1389 Font font(Font::ALL_IGNORE);
1390 font.setNoun(Font::TOGGLE);
1391 toggleAndShow(cur, this, font);
1395 case LFUN_FONT_CODE: {
1396 Font font(Font::ALL_IGNORE);
1397 font.setFamily(Font::TYPEWRITER_FAMILY); // no good
1398 toggleAndShow(cur, this, font);
1402 case LFUN_FONT_SANS: {
1403 Font font(Font::ALL_IGNORE);
1404 font.setFamily(Font::SANS_FAMILY);
1405 toggleAndShow(cur, this, font);
1409 case LFUN_FONT_ROMAN: {
1410 Font font(Font::ALL_IGNORE);
1411 font.setFamily(Font::ROMAN_FAMILY);
1412 toggleAndShow(cur, this, font);
1416 case LFUN_FONT_DEFAULT: {
1417 Font font(Font::ALL_INHERIT, ignore_language);
1418 toggleAndShow(cur, this, font);
1422 case LFUN_FONT_UNDERLINE: {
1423 Font font(Font::ALL_IGNORE);
1424 font.setUnderbar(Font::TOGGLE);
1425 toggleAndShow(cur, this, font);
1429 case LFUN_FONT_SIZE: {
1430 Font font(Font::ALL_IGNORE);
1431 font.setLyXSize(to_utf8(cmd.argument()));
1432 toggleAndShow(cur, this, font);
1436 case LFUN_LANGUAGE: {
1437 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1440 Font font(Font::ALL_IGNORE);
1441 font.setLanguage(lang);
1442 toggleAndShow(cur, this, font);
1446 case LFUN_FONT_FREE_APPLY:
1447 toggleAndShow(cur, this, freefont, toggleall);
1448 cur.message(_("Character set"));
1451 // Set the freefont using the contents of \param data dispatched from
1452 // the frontends and apply it at the current cursor location.
1453 case LFUN_FONT_FREE_UPDATE: {
1456 if (bv_funcs::string2font(to_utf8(cmd.argument()), font, toggle)) {
1459 toggleAndShow(cur, this, freefont, toggleall);
1460 cur.message(_("Character set"));
1465 case LFUN_FINISHED_LEFT:
1466 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1467 if (reverseDirectionNeeded(cur))
1471 case LFUN_FINISHED_RIGHT:
1472 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1473 if (!reverseDirectionNeeded(cur))
1477 case LFUN_LAYOUT_PARAGRAPH: {
1479 params2string(cur.paragraph(), data);
1480 data = "show\n" + data;
1481 bv->showDialogWithData("paragraph", data);
1485 case LFUN_PARAGRAPH_UPDATE: {
1487 params2string(cur.paragraph(), data);
1489 // Will the paragraph accept changes from the dialog?
1490 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1492 data = "update " + convert<string>(accept) + '\n' + data;
1493 bv->updateDialog("paragraph", data);
1497 case LFUN_ACCENT_UMLAUT:
1498 case LFUN_ACCENT_CIRCUMFLEX:
1499 case LFUN_ACCENT_GRAVE:
1500 case LFUN_ACCENT_ACUTE:
1501 case LFUN_ACCENT_TILDE:
1502 case LFUN_ACCENT_CEDILLA:
1503 case LFUN_ACCENT_MACRON:
1504 case LFUN_ACCENT_DOT:
1505 case LFUN_ACCENT_UNDERDOT:
1506 case LFUN_ACCENT_UNDERBAR:
1507 case LFUN_ACCENT_CARON:
1508 case LFUN_ACCENT_SPECIAL_CARON:
1509 case LFUN_ACCENT_BREVE:
1510 case LFUN_ACCENT_TIE:
1511 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1512 case LFUN_ACCENT_CIRCLE:
1513 case LFUN_ACCENT_OGONEK:
1514 theLyXFunc().handleKeyFunc(cmd.action);
1515 if (!cmd.argument().empty())
1516 // FIXME: Are all these characters encoded in one byte in utf8?
1517 bv->translateAndInsert(cmd.argument()[0], this, cur);
1520 case LFUN_FLOAT_LIST: {
1521 TextClass const & tclass = bv->buffer()->params().getTextClass();
1522 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1524 if (cur.selection())
1525 cutSelection(cur, true, false);
1526 breakParagraph(cur);
1528 if (cur.lastpos() != 0) {
1530 breakParagraph(cur);
1533 setLayout(cur, tclass.defaultLayoutName());
1534 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, docstring(), 0);
1535 insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1538 lyxerr << "Non-existent float type: "
1539 << to_utf8(cmd.argument()) << endl;
1544 case LFUN_CHANGE_ACCEPT: {
1545 acceptOrRejectChanges(cur, ACCEPT);
1549 case LFUN_CHANGE_REJECT: {
1550 acceptOrRejectChanges(cur, REJECT);
1554 case LFUN_THESAURUS_ENTRY: {
1555 docstring arg = cmd.argument();
1557 arg = cur.selectionAsString(false);
1559 if (arg.size() > 100 || arg.empty()) {
1560 // Get word or selection
1561 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1562 arg = cur.selectionAsString(false);
1565 bv->showDialogWithData("thesaurus", to_utf8(arg));
1569 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1570 // Given data, an encoding of the ParagraphParameters
1571 // generated in the Paragraph dialog, this function sets
1572 // the current paragraph appropriately.
1573 istringstream is(to_utf8(cmd.argument()));
1576 ParagraphParameters params;
1581 params.labelWidthString(),
1583 cur.message(_("Paragraph layout set"));
1588 if (cur.selection()) {
1589 cur.selection() = false;
1592 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1597 LYXERR(Debug::ACTION)
1598 << BOOST_CURRENT_FUNCTION
1599 << ": Command " << cmd
1600 << " not DISPATCHED by Text" << endl;
1605 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1606 theSelection().haveSelection(bv->cursor().selection());
1608 // FIXME: The cursor flag is reset two lines below
1609 // so we need to check here if some of the LFUN did touch that.
1610 // for now only Text::erase() and Text::backspace() do that.
1611 // The plan is to verify all the LFUNs and then to remove this
1612 // singleParUpdate boolean altogether.
1613 if (cur.result().update() & Update::Force) {
1614 singleParUpdate = false;
1618 // FIXME: the following code should go in favor of fine grained
1619 // update flag treatment.
1620 if (singleParUpdate) {
1621 // Inserting characters does not change par height
1622 ParagraphMetrics const & pms
1623 = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
1624 if (pms.dim().height()
1625 == olddim.height()) {
1626 // if so, update _only_ this paragraph
1627 cur.updateFlags(Update::SinglePar |
1629 Update::MultiParSel);
1636 && &oldTopSlice.inset() == &cur.inset()
1637 && oldTopSlice.idx() == cur.idx()
1638 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1639 && !cur.selection())
1640 // FIXME: it would be better if we could just do this
1642 //if (cur.result().update() != Update::FitCursor)
1645 // But some LFUNs do not set Update::FitCursor when needed, so we
1646 // do it for all. This is not very harmfull as FitCursor will provoke
1647 // a full redraw only if needed but still, a proper review of all LFUN
1648 // should be done and this needsUpdate boolean can then be removed.
1649 cur.updateFlags(Update::FitCursor);
1651 cur.updateFlags(Update::Force | Update::FitCursor);
1655 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
1656 FuncStatus & flag) const
1658 BOOST_ASSERT(cur.text() == this);
1660 Font const & font = real_current_font;
1662 Inset::Code code = Inset::NO_CODE;
1664 switch (cmd.action) {
1666 case LFUN_DEPTH_DECREMENT:
1667 enable = changeDepthAllowed(cur, DEC_DEPTH);
1670 case LFUN_DEPTH_INCREMENT:
1671 enable = changeDepthAllowed(cur, INC_DEPTH);
1675 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1678 case LFUN_BIBITEM_INSERT:
1679 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO
1683 case LFUN_DIALOG_SHOW_NEW_INSET:
1684 if (cmd.argument() == "bibitem")
1685 code = Inset::BIBITEM_CODE;
1686 else if (cmd.argument() == "bibtex")
1687 code = Inset::BIBTEX_CODE;
1688 else if (cmd.argument() == "box")
1689 code = Inset::BOX_CODE;
1690 else if (cmd.argument() == "branch")
1691 code = Inset::BRANCH_CODE;
1692 else if (cmd.argument() == "citation")
1693 code = Inset::CITE_CODE;
1694 else if (cmd.argument() == "ert")
1695 code = Inset::ERT_CODE;
1696 else if (cmd.argument() == "external")
1697 code = Inset::EXTERNAL_CODE;
1698 else if (cmd.argument() == "float")
1699 code = Inset::FLOAT_CODE;
1700 else if (cmd.argument() == "graphics")
1701 code = Inset::GRAPHICS_CODE;
1702 else if (cmd.argument() == "include")
1703 code = Inset::INCLUDE_CODE;
1704 else if (cmd.argument() == "index")
1705 code = Inset::INDEX_CODE;
1706 else if (cmd.argument() == "nomenclature")
1707 code = Inset::NOMENCL_CODE;
1708 else if (cmd.argument() == "label")
1709 code = Inset::LABEL_CODE;
1710 else if (cmd.argument() == "note")
1711 code = Inset::NOTE_CODE;
1712 else if (cmd.argument() == "ref")
1713 code = Inset::REF_CODE;
1714 else if (cmd.argument() == "toc")
1715 code = Inset::TOC_CODE;
1716 else if (cmd.argument() == "url")
1717 code = Inset::URL_CODE;
1718 else if (cmd.argument() == "vspace")
1719 code = Inset::VSPACE_CODE;
1720 else if (cmd.argument() == "wrap")
1721 code = Inset::WRAP_CODE;
1722 else if (cmd.argument() == "listings")
1723 code = Inset::LISTINGS_CODE;
1726 case LFUN_ERT_INSERT:
1727 code = Inset::ERT_CODE;
1729 case LFUN_LISTING_INSERT:
1730 code = Inset::LISTINGS_CODE;
1732 case LFUN_FOOTNOTE_INSERT:
1733 code = Inset::FOOT_CODE;
1735 case LFUN_TABULAR_INSERT:
1736 code = Inset::TABULAR_CODE;
1738 case LFUN_MARGINALNOTE_INSERT:
1739 code = Inset::MARGIN_CODE;
1741 case LFUN_FLOAT_INSERT:
1742 case LFUN_FLOAT_WIDE_INSERT:
1743 code = Inset::FLOAT_CODE;
1745 case LFUN_WRAP_INSERT:
1746 code = Inset::WRAP_CODE;
1748 case LFUN_FLOAT_LIST:
1749 code = Inset::FLOAT_LIST_CODE;
1752 case LFUN_LIST_INSERT:
1753 code = Inset::LIST_CODE;
1755 case LFUN_THEOREM_INSERT:
1756 code = Inset::THEOREM_CODE;
1759 case LFUN_CAPTION_INSERT:
1760 code = Inset::CAPTION_CODE;
1762 case LFUN_NOTE_INSERT:
1763 code = Inset::NOTE_CODE;
1765 case LFUN_CHARSTYLE_INSERT:
1766 code = Inset::CHARSTYLE_CODE;
1767 if (cur.buffer().params().getTextClass().charstyles().empty())
1770 case LFUN_BOX_INSERT:
1771 code = Inset::BOX_CODE;
1773 case LFUN_BRANCH_INSERT:
1774 code = Inset::BRANCH_CODE;
1775 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1778 case LFUN_LABEL_INSERT:
1779 code = Inset::LABEL_CODE;
1781 case LFUN_OPTIONAL_INSERT:
1782 code = Inset::OPTARG_CODE;
1783 enable = numberOfOptArgs(cur.paragraph())
1784 < cur.paragraph().layout()->optionalargs;
1786 case LFUN_ENVIRONMENT_INSERT:
1787 code = Inset::BOX_CODE;
1789 case LFUN_INDEX_INSERT:
1790 code = Inset::INDEX_CODE;
1792 case LFUN_INDEX_PRINT:
1793 code = Inset::INDEX_PRINT_CODE;
1795 case LFUN_NOMENCL_INSERT:
1796 code = Inset::NOMENCL_CODE;
1798 case LFUN_NOMENCL_PRINT:
1799 code = Inset::NOMENCL_PRINT_CODE;
1801 case LFUN_TOC_INSERT:
1802 code = Inset::TOC_CODE;
1804 case LFUN_HTML_INSERT:
1805 case LFUN_URL_INSERT:
1806 code = Inset::URL_CODE;
1808 case LFUN_QUOTE_INSERT:
1809 // always allow this, since we will inset a raw quote
1810 // if an inset is not allowed.
1812 case LFUN_HYPHENATION_POINT_INSERT:
1813 case LFUN_LIGATURE_BREAK_INSERT:
1814 case LFUN_HFILL_INSERT:
1815 case LFUN_MENU_SEPARATOR_INSERT:
1816 case LFUN_DOTS_INSERT:
1817 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
1818 code = Inset::SPECIALCHAR_CODE;
1820 case LFUN_SPACE_INSERT:
1821 // slight hack: we know this is allowed in math mode
1823 code = Inset::SPACE_CODE;
1826 case LFUN_INSET_MODIFY:
1827 // We need to disable this, because we may get called for a
1829 // InsetTabular::getStatus() -> InsetText::getStatus()
1830 // and we don't handle LFUN_INSET_MODIFY.
1834 case LFUN_FONT_EMPH:
1835 flag.setOnOff(font.emph() == Font::ON);
1838 case LFUN_FONT_NOUN:
1839 flag.setOnOff(font.noun() == Font::ON);
1842 case LFUN_FONT_BOLD:
1843 flag.setOnOff(font.series() == Font::BOLD_SERIES);
1846 case LFUN_FONT_SANS:
1847 flag.setOnOff(font.family() == Font::SANS_FAMILY);
1850 case LFUN_FONT_ROMAN:
1851 flag.setOnOff(font.family() == Font::ROMAN_FAMILY);
1854 case LFUN_FONT_CODE:
1855 flag.setOnOff(font.family() == Font::TYPEWRITER_FAMILY);
1860 enable = cur.selection();
1864 if (cmd.argument().empty()) {
1865 if (theClipboard().isInternal())
1866 enable = cap::numberOfSelections() > 0;
1868 enable = !theClipboard().empty();
1870 string const arg = to_utf8(cmd.argument());
1871 if (isStrUnsignedInt(arg)) {
1872 unsigned int n = convert<unsigned int>(arg);
1873 enable = cap::numberOfSelections() > n;
1880 case LFUN_CLIPBOARD_PASTE:
1881 enable = !theClipboard().empty();
1884 case LFUN_PRIMARY_SELECTION_PASTE:
1885 enable = cur.selection() || !theSelection().empty();
1888 case LFUN_PARAGRAPH_MOVE_UP:
1889 enable = cur.pit() > 0 && !cur.selection();
1892 case LFUN_PARAGRAPH_MOVE_DOWN:
1893 enable = cur.pit() < cur.lastpit() && !cur.selection();
1896 case LFUN_INSET_DISSOLVE:
1897 enable = !isMainText(*cur.bv().buffer()) && cur.inset().nargs() == 1;
1900 case LFUN_CHANGE_ACCEPT:
1901 case LFUN_CHANGE_REJECT:
1902 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
1903 // In principle, these LFUNs should only be enabled if there
1904 // is a change at the current position/in the current selection.
1905 // However, without proper optimizations, this will inevitably
1906 // result in unacceptable performance - just imagine a user who
1907 // wants to select the complete content of a long document.
1911 case LFUN_WORD_DELETE_FORWARD:
1912 case LFUN_WORD_DELETE_BACKWARD:
1913 case LFUN_LINE_DELETE:
1914 case LFUN_WORD_FORWARD:
1915 case LFUN_WORD_BACKWARD:
1916 case LFUN_CHAR_FORWARD:
1917 case LFUN_CHAR_FORWARD_SELECT:
1918 case LFUN_CHAR_BACKWARD:
1919 case LFUN_CHAR_BACKWARD_SELECT:
1921 case LFUN_UP_SELECT:
1923 case LFUN_DOWN_SELECT:
1924 case LFUN_PARAGRAPH_UP_SELECT:
1925 case LFUN_PARAGRAPH_DOWN_SELECT:
1926 case LFUN_SCREEN_UP_SELECT:
1927 case LFUN_SCREEN_DOWN_SELECT:
1928 case LFUN_LINE_BEGIN_SELECT:
1929 case LFUN_LINE_END_SELECT:
1930 case LFUN_WORD_FORWARD_SELECT:
1931 case LFUN_WORD_BACKWARD_SELECT:
1932 case LFUN_WORD_SELECT:
1933 case LFUN_PARAGRAPH_UP:
1934 case LFUN_PARAGRAPH_DOWN:
1935 case LFUN_SCREEN_UP:
1936 case LFUN_SCREEN_DOWN:
1937 case LFUN_LINE_BEGIN:
1939 case LFUN_BREAK_LINE:
1940 case LFUN_CHAR_DELETE_FORWARD:
1941 case LFUN_DELETE_FORWARD_SKIP:
1942 case LFUN_CHAR_DELETE_BACKWARD:
1943 case LFUN_DELETE_BACKWARD_SKIP:
1944 case LFUN_BREAK_PARAGRAPH:
1945 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
1946 case LFUN_BREAK_PARAGRAPH_SKIP:
1947 case LFUN_PARAGRAPH_SPACING:
1948 case LFUN_INSET_INSERT:
1949 case LFUN_WORD_UPCASE:
1950 case LFUN_WORD_LOWCASE:
1951 case LFUN_WORD_CAPITALIZE:
1952 case LFUN_CHARS_TRANSPOSE:
1953 case LFUN_SERVER_GET_XY:
1954 case LFUN_SERVER_SET_XY:
1955 case LFUN_SERVER_GET_FONT:
1956 case LFUN_SERVER_GET_LAYOUT:
1958 case LFUN_DATE_INSERT:
1959 case LFUN_SELF_INSERT:
1960 case LFUN_LINE_INSERT:
1961 case LFUN_PAGEBREAK_INSERT:
1962 case LFUN_CLEARPAGE_INSERT:
1963 case LFUN_CLEARDOUBLEPAGE_INSERT:
1964 case LFUN_MATH_DISPLAY:
1965 case LFUN_MATH_IMPORT_SELECTION:
1966 case LFUN_MATH_MODE:
1967 case LFUN_MATH_MACRO:
1968 case LFUN_MATH_MATRIX:
1969 case LFUN_MATH_DELIM:
1970 case LFUN_MATH_BIGDELIM:
1971 case LFUN_MATH_INSERT:
1972 case LFUN_MATH_SUBSCRIPT:
1973 case LFUN_MATH_SUPERSCRIPT:
1974 case LFUN_FONT_DEFAULT:
1975 case LFUN_FONT_UNDERLINE:
1976 case LFUN_FONT_SIZE:
1978 case LFUN_FONT_FREE_APPLY:
1979 case LFUN_FONT_FREE_UPDATE:
1980 case LFUN_LAYOUT_PARAGRAPH:
1981 case LFUN_PARAGRAPH_UPDATE:
1982 case LFUN_ACCENT_UMLAUT:
1983 case LFUN_ACCENT_CIRCUMFLEX:
1984 case LFUN_ACCENT_GRAVE:
1985 case LFUN_ACCENT_ACUTE:
1986 case LFUN_ACCENT_TILDE:
1987 case LFUN_ACCENT_CEDILLA:
1988 case LFUN_ACCENT_MACRON:
1989 case LFUN_ACCENT_DOT:
1990 case LFUN_ACCENT_UNDERDOT:
1991 case LFUN_ACCENT_UNDERBAR:
1992 case LFUN_ACCENT_CARON:
1993 case LFUN_ACCENT_SPECIAL_CARON:
1994 case LFUN_ACCENT_BREVE:
1995 case LFUN_ACCENT_TIE:
1996 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1997 case LFUN_ACCENT_CIRCLE:
1998 case LFUN_ACCENT_OGONEK:
1999 case LFUN_THESAURUS_ENTRY:
2000 case LFUN_PARAGRAPH_PARAMS_APPLY:
2002 case LFUN_BUFFER_END:
2003 case LFUN_BUFFER_BEGIN:
2004 case LFUN_BUFFER_BEGIN_SELECT:
2005 case LFUN_BUFFER_END_SELECT:
2006 case LFUN_UNICODE_INSERT:
2007 // these are handled in our dispatch()
2015 if (code != Inset::NO_CODE
2016 && (cur.empty() || !cur.inset().insetAllowed(code)))
2019 flag.enabled(enable);
2024 void Text::pasteString(Cursor & cur, docstring const & clip,
2027 cur.clearSelection();
2028 if (!clip.empty()) {
2031 insertStringAsParagraphs(cur, clip);
2033 insertStringAsLines(cur, clip);