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 cap::saveSelection(bv->cursor());
1019 // Right click on a footnote flag opens float menu
1020 if (cmd.button() == mouse_button::button3)
1021 cur.clearSelection();
1023 // Middle button press pastes if we have a selection
1024 // We do this here as if the selection was inside an inset
1025 // it could get cleared on the unlocking of the inset so
1026 // we have to check this first
1027 bool paste_internally = false;
1028 if (cmd.button() == mouse_button::button2 && cap::selection()) {
1029 // Copy the selection buffer to the clipboard
1030 // stack, because we want it to appear in the
1031 // "Edit->Paste recent" menu.
1032 cap::copySelectionToStack();
1033 paste_internally = true;
1036 // Insert primary selection with middle mouse
1037 // if there is a local selection in the current buffer,
1039 if (cmd.button() == mouse_button::button2) {
1040 if (paste_internally) {
1041 cap::pasteSelection(cur, bv->buffer()->errorList("Paste"));
1042 bv->buffer()->errors("Paste");
1043 cur.clearSelection(); // bug 393
1044 bv->buffer()->markDirty();
1047 bv->mouseSetCursor(cur);
1048 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
1052 // we have to update after dePM triggered
1053 bool update = bv->mouseSetCursor(cur);
1055 if (!update && cmd.button() == mouse_button::button1) {
1056 needsUpdate = false;
1063 case LFUN_MOUSE_MOTION: {
1064 // Only use motion with button 1
1065 //if (cmd.button() != mouse_button::button1)
1068 // ignore motions deeper nested than the real anchor
1069 Cursor & bvcur = cur.bv().cursor();
1070 if (bvcur.anchor_.hasPart(cur)) {
1071 CursorSlice old = bvcur.top();
1073 int const wh = bv->workHeight();
1074 int const y = std::max(0, std::min(wh - 1, cmd.y));
1076 setCursorFromCoordinates(cur, cmd.x, y);
1077 cur.setTargetX(cmd.x);
1079 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1081 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1082 // This is to allow jumping over large insets
1083 if (cur.top() == old) {
1085 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1087 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1090 if (cur.top() == old)
1093 // don't set anchor_
1094 bvcur.setCursor(cur);
1095 bvcur.selection() = true;
1096 //lyxerr << "MOTION: " << bv->cursor() << endl;
1104 case LFUN_MOUSE_RELEASE: {
1105 if (cmd.button() == mouse_button::button2)
1108 if (cmd.button() == mouse_button::button1) {
1109 // if there is new selection, update persistent
1110 // selection, otherwise, single click does not
1111 // clear persistent selection buffer
1112 if (cur.selection()) {
1114 // if double click, cur is moved to the end of word by selectWord
1115 // but bvcur is current mouse position
1116 Cursor & bvcur = cur.bv().cursor();
1117 bvcur.selection() = true;
1119 needsUpdate = false;
1126 case LFUN_SELF_INSERT: {
1127 if (cmd.argument().empty())
1130 // Automatically delete the currently selected
1131 // text and replace it with what is being
1132 // typed in now. Depends on lyxrc settings
1133 // "auto_region_delete", which defaults to
1136 if (lyxrc.auto_region_delete && cur.selection()) {
1137 cutSelection(cur, false, false);
1138 // When change tracking is set to off, the metrics update
1139 // mechanism correctly detects if a full update is needed or not.
1140 // This detection fails when a selection spans multiple rows and
1141 // change tracking is enabled because the paragraph metrics stays
1142 // the same. In this case, we force the full update:
1143 // (see http://bugzilla.lyx.org/show_bug.cgi?id=3992)
1144 if (cur.buffer().params().trackChanges)
1145 cur.updateFlags(Update::Force);
1148 cur.clearSelection();
1149 Font const old_font = real_current_font;
1151 docstring::const_iterator cit = cmd.argument().begin();
1152 docstring::const_iterator end = cmd.argument().end();
1153 for (; cit != end; ++cit)
1154 bv->translateAndInsert(*cit, this, cur);
1157 moveCursor(cur, false);
1161 case LFUN_URL_INSERT: {
1162 InsetCommandParams p("url");
1164 if (cur.selection()) {
1165 content = cur.selectionAsString(false);
1166 cutSelection(cur, true, false);
1168 p["target"] = (cmd.argument().empty()) ?
1169 content : cmd.argument();
1170 string const data = InsetCommandMailer::params2string("url", p);
1171 if (p["target"].empty()) {
1172 bv->showInsetDialog("url", data, 0);
1174 FuncRequest fr(LFUN_INSET_INSERT, data);
1180 case LFUN_HTML_INSERT: {
1181 InsetCommandParams p("htmlurl");
1183 if (cur.selection()) {
1184 content = cur.selectionAsString(false);
1185 cutSelection(cur, true, false);
1187 p["target"] = (cmd.argument().empty()) ?
1188 content : cmd.argument();
1189 string const data = InsetCommandMailer::params2string("url", p);
1190 if (p["target"].empty()) {
1191 bv->showInsetDialog("url", data, 0);
1193 FuncRequest fr(LFUN_INSET_INSERT, data);
1199 case LFUN_LABEL_INSERT: {
1200 InsetCommandParams p("label");
1201 // Try to generate a valid label
1202 p["name"] = (cmd.argument().empty()) ?
1203 cur.getPossibleLabel() :
1205 string const data = InsetCommandMailer::params2string("label", p);
1207 if (cmd.argument().empty()) {
1208 bv->showInsetDialog("label", data, 0);
1210 FuncRequest fr(LFUN_INSET_INSERT, data);
1218 case LFUN_LIST_INSERT:
1219 case LFUN_THEOREM_INSERT:
1221 case LFUN_CAPTION_INSERT:
1222 // Open the inset, and move the current selection
1224 doInsertInset(cur, this, cmd, true, true);
1226 updateLabels(*bv->buffer());
1228 case LFUN_NOTE_INSERT:
1229 case LFUN_CHARSTYLE_INSERT:
1230 case LFUN_BOX_INSERT:
1231 case LFUN_BRANCH_INSERT:
1232 case LFUN_BIBITEM_INSERT:
1233 case LFUN_ERT_INSERT:
1234 case LFUN_LISTING_INSERT:
1235 case LFUN_FOOTNOTE_INSERT:
1236 case LFUN_MARGINALNOTE_INSERT:
1237 case LFUN_OPTIONAL_INSERT:
1238 case LFUN_ENVIRONMENT_INSERT:
1239 // Open the inset, and move the current selection
1241 doInsertInset(cur, this, cmd, true, true);
1245 case LFUN_TABULAR_INSERT:
1246 // if there were no arguments, just open the dialog
1247 if (doInsertInset(cur, this, cmd, false, true))
1250 bv->showDialog("tabularcreate");
1254 case LFUN_FLOAT_INSERT:
1255 case LFUN_FLOAT_WIDE_INSERT:
1256 case LFUN_WRAP_INSERT: {
1257 bool content = cur.selection(); // will some text be moved into the inset?
1259 doInsertInset(cur, this, cmd, true, true);
1261 ParagraphList & pars = cur.text()->paragraphs();
1263 TextClass const & tclass = bv->buffer()->params().getTextClass();
1265 // add a separate paragraph for the caption inset
1266 pars.push_back(Paragraph());
1267 pars.back().setInsetOwner(pars[0].inInset());
1268 pars.back().layout(tclass.defaultLayout());
1270 int cap_pit = pars.size() - 1;
1272 // if an empty inset was created, we create an additional empty
1273 // paragraph at the bottom so that the user can choose where to put
1274 // the graphics (or table).
1276 pars.push_back(Paragraph());
1277 pars.back().setInsetOwner(pars[0].inInset());
1278 pars.back().layout(tclass.defaultLayout());
1282 // reposition the cursor to the caption
1283 cur.pit() = cap_pit;
1285 cur.dispatch(FuncRequest(LFUN_CAPTION_INSERT));
1286 // FIXME: When leaving the Float (or Wrap) inset we should
1287 // delete any empty paragraph left above or below the
1292 case LFUN_INDEX_INSERT:
1293 case LFUN_NOMENCL_INSERT: {
1294 Inset * inset = createInset(&cur.bv(), cmd);
1298 cur.clearSelection();
1299 insertInset(cur, inset);
1300 inset->edit(cur, true);
1301 // Show the dialog for the nomenclature entry, since the
1302 // description entry still needs to be filled in.
1303 if (cmd.action == LFUN_NOMENCL_INSERT)
1304 InsetCommandMailer("nomenclature",
1305 *reinterpret_cast<InsetCommand *>(inset)).showDialog(&cur.bv());
1310 case LFUN_INDEX_PRINT:
1311 case LFUN_NOMENCL_PRINT:
1312 case LFUN_TOC_INSERT:
1313 case LFUN_HFILL_INSERT:
1314 case LFUN_LINE_INSERT:
1315 case LFUN_PAGEBREAK_INSERT:
1316 case LFUN_CLEARPAGE_INSERT:
1317 case LFUN_CLEARDOUBLEPAGE_INSERT:
1319 doInsertInset(cur, this, cmd, false, false);
1323 case LFUN_DEPTH_DECREMENT:
1324 changeDepth(cur, DEC_DEPTH);
1327 case LFUN_DEPTH_INCREMENT:
1328 changeDepth(cur, INC_DEPTH);
1331 case LFUN_MATH_DISPLAY:
1332 mathDispatch(cur, cmd, true);
1335 case LFUN_MATH_IMPORT_SELECTION:
1336 case LFUN_MATH_MODE:
1337 if (cmd.argument() == "on")
1338 // don't pass "on" as argument
1339 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1341 mathDispatch(cur, cmd, false);
1344 case LFUN_MATH_MACRO:
1345 if (cmd.argument().empty())
1346 cur.errorMessage(from_utf8(N_("Missing argument")));
1348 string s = to_utf8(cmd.argument());
1349 string const s1 = token(s, ' ', 1);
1350 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1351 string const s2 = token(s, ' ', 2);
1352 string const type = s2.empty() ? "newcommand" : s2;
1353 cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, from_utf8(type)));
1354 //cur.nextInset()->edit(cur, true);
1358 // passthrough hat and underscore outside mathed:
1359 case LFUN_MATH_SUBSCRIPT:
1360 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1362 case LFUN_MATH_SUPERSCRIPT:
1363 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1366 case LFUN_MATH_INSERT:
1367 case LFUN_MATH_MATRIX:
1368 case LFUN_MATH_DELIM:
1369 case LFUN_MATH_BIGDELIM: {
1370 if (cur.selection())
1371 cur.clearSelection();
1372 // FIXME: instead of the above, this one
1373 // should be used (but it asserts with Bidi enabled)
1374 // cf. http://bugzilla.lyx.org/show_bug.cgi?id=4055
1375 // cap::replaceSelection(cur);
1376 cur.insert(new InsetMathHull(hullSimple));
1377 checkAndActivateInset(cur, true);
1378 BOOST_ASSERT(cur.inMathed());
1383 case LFUN_FONT_EMPH: {
1384 Font font(Font::ALL_IGNORE);
1385 font.setEmph(Font::TOGGLE);
1386 toggleAndShow(cur, this, font);
1390 case LFUN_FONT_BOLD: {
1391 Font font(Font::ALL_IGNORE);
1392 font.setSeries(Font::BOLD_SERIES);
1393 toggleAndShow(cur, this, font);
1397 case LFUN_FONT_NOUN: {
1398 Font font(Font::ALL_IGNORE);
1399 font.setNoun(Font::TOGGLE);
1400 toggleAndShow(cur, this, font);
1404 case LFUN_FONT_CODE: {
1405 Font font(Font::ALL_IGNORE);
1406 font.setFamily(Font::TYPEWRITER_FAMILY); // no good
1407 toggleAndShow(cur, this, font);
1411 case LFUN_FONT_SANS: {
1412 Font font(Font::ALL_IGNORE);
1413 font.setFamily(Font::SANS_FAMILY);
1414 toggleAndShow(cur, this, font);
1418 case LFUN_FONT_ROMAN: {
1419 Font font(Font::ALL_IGNORE);
1420 font.setFamily(Font::ROMAN_FAMILY);
1421 toggleAndShow(cur, this, font);
1425 case LFUN_FONT_DEFAULT: {
1426 Font font(Font::ALL_INHERIT, ignore_language);
1427 toggleAndShow(cur, this, font);
1431 case LFUN_FONT_UNDERLINE: {
1432 Font font(Font::ALL_IGNORE);
1433 font.setUnderbar(Font::TOGGLE);
1434 toggleAndShow(cur, this, font);
1438 case LFUN_FONT_SIZE: {
1439 Font font(Font::ALL_IGNORE);
1440 font.setLyXSize(to_utf8(cmd.argument()));
1441 toggleAndShow(cur, this, font);
1445 case LFUN_LANGUAGE: {
1446 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1449 Font font(Font::ALL_IGNORE);
1450 font.setLanguage(lang);
1451 toggleAndShow(cur, this, font);
1455 case LFUN_FONT_FREE_APPLY:
1456 toggleAndShow(cur, this, freefont, toggleall);
1457 cur.message(_("Character set"));
1460 // Set the freefont using the contents of \param data dispatched from
1461 // the frontends and apply it at the current cursor location.
1462 case LFUN_FONT_FREE_UPDATE: {
1465 if (bv_funcs::string2font(to_utf8(cmd.argument()), font, toggle)) {
1468 toggleAndShow(cur, this, freefont, toggleall);
1469 cur.message(_("Character set"));
1474 case LFUN_FINISHED_LEFT:
1475 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1476 if (reverseDirectionNeeded(cur))
1480 case LFUN_FINISHED_RIGHT:
1481 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1482 if (!reverseDirectionNeeded(cur))
1486 case LFUN_LAYOUT_PARAGRAPH: {
1488 params2string(cur.paragraph(), data);
1489 data = "show\n" + data;
1490 bv->showDialogWithData("paragraph", data);
1494 case LFUN_PARAGRAPH_UPDATE: {
1496 params2string(cur.paragraph(), data);
1498 // Will the paragraph accept changes from the dialog?
1499 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1501 data = "update " + convert<string>(accept) + '\n' + data;
1502 bv->updateDialog("paragraph", data);
1506 case LFUN_ACCENT_UMLAUT:
1507 case LFUN_ACCENT_CIRCUMFLEX:
1508 case LFUN_ACCENT_GRAVE:
1509 case LFUN_ACCENT_ACUTE:
1510 case LFUN_ACCENT_TILDE:
1511 case LFUN_ACCENT_CEDILLA:
1512 case LFUN_ACCENT_MACRON:
1513 case LFUN_ACCENT_DOT:
1514 case LFUN_ACCENT_UNDERDOT:
1515 case LFUN_ACCENT_UNDERBAR:
1516 case LFUN_ACCENT_CARON:
1517 case LFUN_ACCENT_SPECIAL_CARON:
1518 case LFUN_ACCENT_BREVE:
1519 case LFUN_ACCENT_TIE:
1520 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1521 case LFUN_ACCENT_CIRCLE:
1522 case LFUN_ACCENT_OGONEK:
1523 theLyXFunc().handleKeyFunc(cmd.action);
1524 if (!cmd.argument().empty())
1525 // FIXME: Are all these characters encoded in one byte in utf8?
1526 bv->translateAndInsert(cmd.argument()[0], this, cur);
1529 case LFUN_FLOAT_LIST: {
1530 TextClass const & tclass = bv->buffer()->params().getTextClass();
1531 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1533 if (cur.selection())
1534 cutSelection(cur, true, false);
1535 breakParagraph(cur);
1537 if (cur.lastpos() != 0) {
1539 breakParagraph(cur);
1542 setLayout(cur, tclass.defaultLayoutName());
1543 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, docstring(), 0);
1544 insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1547 lyxerr << "Non-existent float type: "
1548 << to_utf8(cmd.argument()) << endl;
1553 case LFUN_CHANGE_ACCEPT: {
1554 acceptOrRejectChanges(cur, ACCEPT);
1558 case LFUN_CHANGE_REJECT: {
1559 acceptOrRejectChanges(cur, REJECT);
1563 case LFUN_THESAURUS_ENTRY: {
1564 docstring arg = cmd.argument();
1566 arg = cur.selectionAsString(false);
1568 if (arg.size() > 100 || arg.empty()) {
1569 // Get word or selection
1570 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1571 arg = cur.selectionAsString(false);
1574 bv->showDialogWithData("thesaurus", to_utf8(arg));
1578 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1579 // Given data, an encoding of the ParagraphParameters
1580 // generated in the Paragraph dialog, this function sets
1581 // the current paragraph appropriately.
1582 istringstream is(to_utf8(cmd.argument()));
1585 ParagraphParameters params;
1590 params.labelWidthString(),
1592 cur.message(_("Paragraph layout set"));
1597 if (cur.selection()) {
1598 cur.selection() = false;
1601 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1606 LYXERR(Debug::ACTION)
1607 << BOOST_CURRENT_FUNCTION
1608 << ": Command " << cmd
1609 << " not DISPATCHED by Text" << endl;
1614 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1615 theSelection().haveSelection(bv->cursor().selection());
1617 // FIXME: The cursor flag is reset two lines below
1618 // so we need to check here if some of the LFUN did touch that.
1619 // for now only Text::erase() and Text::backspace() do that.
1620 // The plan is to verify all the LFUNs and then to remove this
1621 // singleParUpdate boolean altogether.
1622 if (cur.result().update() & Update::Force) {
1623 singleParUpdate = false;
1627 // FIXME: the following code should go in favor of fine grained
1628 // update flag treatment.
1629 if (singleParUpdate) {
1630 // Inserting characters does not change par height
1631 ParagraphMetrics const & pms
1632 = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
1633 if (pms.dim().height()
1634 == olddim.height()) {
1635 // if so, update _only_ this paragraph
1636 cur.updateFlags(Update::SinglePar |
1638 Update::MultiParSel);
1645 && &oldTopSlice.inset() == &cur.inset()
1646 && oldTopSlice.idx() == cur.idx()
1647 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1648 && !cur.selection())
1649 // FIXME: it would be better if we could just do this
1651 //if (cur.result().update() != Update::FitCursor)
1654 // But some LFUNs do not set Update::FitCursor when needed, so we
1655 // do it for all. This is not very harmfull as FitCursor will provoke
1656 // a full redraw only if needed but still, a proper review of all LFUN
1657 // should be done and this needsUpdate boolean can then be removed.
1658 cur.updateFlags(Update::FitCursor);
1660 cur.updateFlags(Update::Force | Update::FitCursor);
1664 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
1665 FuncStatus & flag) const
1667 BOOST_ASSERT(cur.text() == this);
1669 Font const & font = real_current_font;
1671 Inset::Code code = Inset::NO_CODE;
1673 switch (cmd.action) {
1675 case LFUN_DEPTH_DECREMENT:
1676 enable = changeDepthAllowed(cur, DEC_DEPTH);
1679 case LFUN_DEPTH_INCREMENT:
1680 enable = changeDepthAllowed(cur, INC_DEPTH);
1684 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1687 case LFUN_BIBITEM_INSERT:
1688 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO
1692 case LFUN_DIALOG_SHOW_NEW_INSET:
1693 if (cmd.argument() == "bibitem")
1694 code = Inset::BIBITEM_CODE;
1695 else if (cmd.argument() == "bibtex")
1696 code = Inset::BIBTEX_CODE;
1697 else if (cmd.argument() == "box")
1698 code = Inset::BOX_CODE;
1699 else if (cmd.argument() == "branch")
1700 code = Inset::BRANCH_CODE;
1701 else if (cmd.argument() == "citation")
1702 code = Inset::CITE_CODE;
1703 else if (cmd.argument() == "ert")
1704 code = Inset::ERT_CODE;
1705 else if (cmd.argument() == "external")
1706 code = Inset::EXTERNAL_CODE;
1707 else if (cmd.argument() == "float")
1708 code = Inset::FLOAT_CODE;
1709 else if (cmd.argument() == "graphics")
1710 code = Inset::GRAPHICS_CODE;
1711 else if (cmd.argument() == "include")
1712 code = Inset::INCLUDE_CODE;
1713 else if (cmd.argument() == "index")
1714 code = Inset::INDEX_CODE;
1715 else if (cmd.argument() == "nomenclature")
1716 code = Inset::NOMENCL_CODE;
1717 else if (cmd.argument() == "label")
1718 code = Inset::LABEL_CODE;
1719 else if (cmd.argument() == "note")
1720 code = Inset::NOTE_CODE;
1721 else if (cmd.argument() == "ref")
1722 code = Inset::REF_CODE;
1723 else if (cmd.argument() == "toc")
1724 code = Inset::TOC_CODE;
1725 else if (cmd.argument() == "url")
1726 code = Inset::URL_CODE;
1727 else if (cmd.argument() == "vspace")
1728 code = Inset::VSPACE_CODE;
1729 else if (cmd.argument() == "wrap")
1730 code = Inset::WRAP_CODE;
1731 else if (cmd.argument() == "listings")
1732 code = Inset::LISTINGS_CODE;
1735 case LFUN_ERT_INSERT:
1736 code = Inset::ERT_CODE;
1738 case LFUN_LISTING_INSERT:
1739 code = Inset::LISTINGS_CODE;
1741 case LFUN_FOOTNOTE_INSERT:
1742 code = Inset::FOOT_CODE;
1744 case LFUN_TABULAR_INSERT:
1745 code = Inset::TABULAR_CODE;
1747 case LFUN_MARGINALNOTE_INSERT:
1748 code = Inset::MARGIN_CODE;
1750 case LFUN_FLOAT_INSERT:
1751 case LFUN_FLOAT_WIDE_INSERT:
1752 code = Inset::FLOAT_CODE;
1754 case LFUN_WRAP_INSERT:
1755 code = Inset::WRAP_CODE;
1757 case LFUN_FLOAT_LIST:
1758 code = Inset::FLOAT_LIST_CODE;
1761 case LFUN_LIST_INSERT:
1762 code = Inset::LIST_CODE;
1764 case LFUN_THEOREM_INSERT:
1765 code = Inset::THEOREM_CODE;
1768 case LFUN_CAPTION_INSERT:
1769 code = Inset::CAPTION_CODE;
1771 case LFUN_NOTE_INSERT:
1772 code = Inset::NOTE_CODE;
1774 case LFUN_CHARSTYLE_INSERT:
1775 code = Inset::CHARSTYLE_CODE;
1776 if (cur.buffer().params().getTextClass().charstyles().empty())
1779 case LFUN_BOX_INSERT:
1780 code = Inset::BOX_CODE;
1782 case LFUN_BRANCH_INSERT:
1783 code = Inset::BRANCH_CODE;
1784 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1787 case LFUN_LABEL_INSERT:
1788 code = Inset::LABEL_CODE;
1790 case LFUN_OPTIONAL_INSERT:
1791 code = Inset::OPTARG_CODE;
1792 enable = numberOfOptArgs(cur.paragraph())
1793 < cur.paragraph().layout()->optionalargs;
1795 case LFUN_ENVIRONMENT_INSERT:
1796 code = Inset::BOX_CODE;
1798 case LFUN_INDEX_INSERT:
1799 code = Inset::INDEX_CODE;
1801 case LFUN_INDEX_PRINT:
1802 code = Inset::INDEX_PRINT_CODE;
1804 case LFUN_NOMENCL_INSERT:
1805 code = Inset::NOMENCL_CODE;
1807 case LFUN_NOMENCL_PRINT:
1808 code = Inset::NOMENCL_PRINT_CODE;
1810 case LFUN_TOC_INSERT:
1811 code = Inset::TOC_CODE;
1813 case LFUN_HTML_INSERT:
1814 case LFUN_URL_INSERT:
1815 code = Inset::URL_CODE;
1817 case LFUN_QUOTE_INSERT:
1818 // always allow this, since we will inset a raw quote
1819 // if an inset is not allowed.
1821 case LFUN_HYPHENATION_POINT_INSERT:
1822 case LFUN_LIGATURE_BREAK_INSERT:
1823 case LFUN_HFILL_INSERT:
1824 case LFUN_MENU_SEPARATOR_INSERT:
1825 case LFUN_DOTS_INSERT:
1826 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
1827 code = Inset::SPECIALCHAR_CODE;
1829 case LFUN_SPACE_INSERT:
1830 // slight hack: we know this is allowed in math mode
1832 code = Inset::SPACE_CODE;
1835 case LFUN_INSET_MODIFY:
1836 // We need to disable this, because we may get called for a
1838 // InsetTabular::getStatus() -> InsetText::getStatus()
1839 // and we don't handle LFUN_INSET_MODIFY.
1843 case LFUN_FONT_EMPH:
1844 flag.setOnOff(font.emph() == Font::ON);
1847 case LFUN_FONT_NOUN:
1848 flag.setOnOff(font.noun() == Font::ON);
1851 case LFUN_FONT_BOLD:
1852 flag.setOnOff(font.series() == Font::BOLD_SERIES);
1855 case LFUN_FONT_SANS:
1856 flag.setOnOff(font.family() == Font::SANS_FAMILY);
1859 case LFUN_FONT_ROMAN:
1860 flag.setOnOff(font.family() == Font::ROMAN_FAMILY);
1863 case LFUN_FONT_CODE:
1864 flag.setOnOff(font.family() == Font::TYPEWRITER_FAMILY);
1869 enable = cur.selection();
1873 if (cmd.argument().empty()) {
1874 if (theClipboard().isInternal())
1875 enable = cap::numberOfSelections() > 0;
1877 enable = !theClipboard().empty();
1879 string const arg = to_utf8(cmd.argument());
1880 if (isStrUnsignedInt(arg)) {
1881 unsigned int n = convert<unsigned int>(arg);
1882 enable = cap::numberOfSelections() > n;
1889 case LFUN_CLIPBOARD_PASTE:
1890 enable = !theClipboard().empty();
1893 case LFUN_PRIMARY_SELECTION_PASTE:
1894 enable = cur.selection() || !theSelection().empty();
1897 case LFUN_PARAGRAPH_MOVE_UP:
1898 enable = cur.pit() > 0 && !cur.selection();
1901 case LFUN_PARAGRAPH_MOVE_DOWN:
1902 enable = cur.pit() < cur.lastpit() && !cur.selection();
1905 case LFUN_INSET_DISSOLVE:
1906 enable = !isMainText(*cur.bv().buffer()) && cur.inset().nargs() == 1;
1909 case LFUN_CHANGE_ACCEPT:
1910 case LFUN_CHANGE_REJECT:
1911 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
1912 // In principle, these LFUNs should only be enabled if there
1913 // is a change at the current position/in the current selection.
1914 // However, without proper optimizations, this will inevitably
1915 // result in unacceptable performance - just imagine a user who
1916 // wants to select the complete content of a long document.
1920 case LFUN_WORD_DELETE_FORWARD:
1921 case LFUN_WORD_DELETE_BACKWARD:
1922 case LFUN_LINE_DELETE:
1923 case LFUN_WORD_FORWARD:
1924 case LFUN_WORD_BACKWARD:
1925 case LFUN_CHAR_FORWARD:
1926 case LFUN_CHAR_FORWARD_SELECT:
1927 case LFUN_CHAR_BACKWARD:
1928 case LFUN_CHAR_BACKWARD_SELECT:
1930 case LFUN_UP_SELECT:
1932 case LFUN_DOWN_SELECT:
1933 case LFUN_PARAGRAPH_UP_SELECT:
1934 case LFUN_PARAGRAPH_DOWN_SELECT:
1935 case LFUN_SCREEN_UP_SELECT:
1936 case LFUN_SCREEN_DOWN_SELECT:
1937 case LFUN_LINE_BEGIN_SELECT:
1938 case LFUN_LINE_END_SELECT:
1939 case LFUN_WORD_FORWARD_SELECT:
1940 case LFUN_WORD_BACKWARD_SELECT:
1941 case LFUN_WORD_SELECT:
1942 case LFUN_PARAGRAPH_UP:
1943 case LFUN_PARAGRAPH_DOWN:
1944 case LFUN_SCREEN_UP:
1945 case LFUN_SCREEN_DOWN:
1946 case LFUN_LINE_BEGIN:
1948 case LFUN_BREAK_LINE:
1949 case LFUN_CHAR_DELETE_FORWARD:
1950 case LFUN_DELETE_FORWARD_SKIP:
1951 case LFUN_CHAR_DELETE_BACKWARD:
1952 case LFUN_DELETE_BACKWARD_SKIP:
1953 case LFUN_BREAK_PARAGRAPH:
1954 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
1955 case LFUN_BREAK_PARAGRAPH_SKIP:
1956 case LFUN_PARAGRAPH_SPACING:
1957 case LFUN_INSET_INSERT:
1958 case LFUN_WORD_UPCASE:
1959 case LFUN_WORD_LOWCASE:
1960 case LFUN_WORD_CAPITALIZE:
1961 case LFUN_CHARS_TRANSPOSE:
1962 case LFUN_SERVER_GET_XY:
1963 case LFUN_SERVER_SET_XY:
1964 case LFUN_SERVER_GET_FONT:
1965 case LFUN_SERVER_GET_LAYOUT:
1967 case LFUN_DATE_INSERT:
1968 case LFUN_SELF_INSERT:
1969 case LFUN_LINE_INSERT:
1970 case LFUN_PAGEBREAK_INSERT:
1971 case LFUN_CLEARPAGE_INSERT:
1972 case LFUN_CLEARDOUBLEPAGE_INSERT:
1973 case LFUN_MATH_DISPLAY:
1974 case LFUN_MATH_IMPORT_SELECTION:
1975 case LFUN_MATH_MODE:
1976 case LFUN_MATH_MACRO:
1977 case LFUN_MATH_MATRIX:
1978 case LFUN_MATH_DELIM:
1979 case LFUN_MATH_BIGDELIM:
1980 case LFUN_MATH_INSERT:
1981 case LFUN_MATH_SUBSCRIPT:
1982 case LFUN_MATH_SUPERSCRIPT:
1983 case LFUN_FONT_DEFAULT:
1984 case LFUN_FONT_UNDERLINE:
1985 case LFUN_FONT_SIZE:
1987 case LFUN_FONT_FREE_APPLY:
1988 case LFUN_FONT_FREE_UPDATE:
1989 case LFUN_LAYOUT_PARAGRAPH:
1990 case LFUN_PARAGRAPH_UPDATE:
1991 case LFUN_ACCENT_UMLAUT:
1992 case LFUN_ACCENT_CIRCUMFLEX:
1993 case LFUN_ACCENT_GRAVE:
1994 case LFUN_ACCENT_ACUTE:
1995 case LFUN_ACCENT_TILDE:
1996 case LFUN_ACCENT_CEDILLA:
1997 case LFUN_ACCENT_MACRON:
1998 case LFUN_ACCENT_DOT:
1999 case LFUN_ACCENT_UNDERDOT:
2000 case LFUN_ACCENT_UNDERBAR:
2001 case LFUN_ACCENT_CARON:
2002 case LFUN_ACCENT_SPECIAL_CARON:
2003 case LFUN_ACCENT_BREVE:
2004 case LFUN_ACCENT_TIE:
2005 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
2006 case LFUN_ACCENT_CIRCLE:
2007 case LFUN_ACCENT_OGONEK:
2008 case LFUN_THESAURUS_ENTRY:
2009 case LFUN_PARAGRAPH_PARAMS_APPLY:
2011 case LFUN_BUFFER_END:
2012 case LFUN_BUFFER_BEGIN:
2013 case LFUN_BUFFER_BEGIN_SELECT:
2014 case LFUN_BUFFER_END_SELECT:
2015 case LFUN_UNICODE_INSERT:
2016 // these are handled in our dispatch()
2024 if (code != Inset::NO_CODE
2025 && (cur.empty() || !cur.inset().insetAllowed(code)))
2028 flag.enabled(enable);
2033 void Text::pasteString(Cursor & cur, docstring const & clip,
2036 cur.clearSelection();
2037 if (!clip.empty()) {
2040 insertStringAsParagraphs(cur, clip);
2042 insertStringAsLines(cur, clip);