3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Asger Alstrup
7 * \author Lars Gullik Bjønnes
8 * \author Alfredo Braunstein
9 * \author Angus Leeming
11 * \author André Pönitz
13 * Full author contact details are available in file CREDITS.
20 #include "BranchList.h"
21 #include "FloatList.h"
22 #include "FuncStatus.h"
24 #include "buffer_funcs.h"
25 #include "BufferParams.h"
26 #include "BufferView.h"
27 #include "bufferview_funcs.h"
29 #include "CoordCache.h"
30 #include "CutAndPaste.h"
32 #include "DispatchResult.h"
33 #include "ErrorList.h"
35 #include "FuncRequest.h"
39 #include "LyXAction.h"
44 #include "Paragraph.h"
45 #include "paragraph_funcs.h"
46 #include "ParagraphParameters.h"
49 #include "ParIterator.h"
51 #include "frontends/Clipboard.h"
52 #include "frontends/Selection.h"
54 #include "insets/InsetCommand.h"
55 #include "insets/InsetFloatList.h"
56 #include "insets/InsetNewline.h"
57 #include "insets/InsetQuotes.h"
58 #include "insets/InsetSpecialChar.h"
59 #include "insets/InsetText.h"
61 #include "support/lstrings.h"
62 #include "support/lyxlib.h"
63 #include "support/convert.h"
64 #include "support/lyxtime.h"
66 #include "mathed/InsetMathHull.h"
67 #include "mathed/MathMacroTemplate.h"
69 #include <boost/current_function.hpp>
76 using std::istringstream;
77 using std::ostringstream;
81 using cap::copySelection;
82 using cap::cutSelection;
83 using cap::pasteFromStack;
84 using cap::pasteClipboard;
85 using cap::replaceSelection;
87 using support::isStrUnsignedInt;
91 extern docstring current_layout;
97 Font freefont(Font::ALL_IGNORE);
98 bool toggleall = false;
100 void toggleAndShow(Cursor & cur, Text * text,
101 Font const & font, bool toggleall = true)
103 text->toggleFree(cur, font, toggleall);
105 if (font.language() != ignore_language ||
106 font.number() != Font::IGNORE) {
107 Paragraph & par = cur.paragraph();
108 if (cur.boundary() != text->isRTLBoundary(cur.buffer(), par,
109 cur.pos(), text->real_current_font))
110 text->setCursor(cur, cur.pit(), cur.pos(),
111 false, !cur.boundary());
116 void moveCursor(Cursor & cur, bool selecting)
118 if (selecting || cur.mark())
123 void finishChange(Cursor & cur, bool selecting)
126 moveCursor(cur, selecting);
130 void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
133 docstring sel = cur.selectionAsString(false);
135 // It may happen that sel is empty but there is a selection
136 replaceSelection(cur);
139 #ifdef ENABLE_ASSERTIONS
140 const int old_pos = cur.pos();
142 cur.insert(new InsetMathHull(hullSimple));
143 BOOST_ASSERT(old_pos == cur.pos());
144 cur.nextInset()->edit(cur, true);
145 // don't do that also for LFUN_MATH_MODE
146 // unless you want end up with always changing
147 // to mathrm when opening an inlined inset --
148 // I really hate "LyXfunc overloading"...
150 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
151 // Avoid an unnecessary undo step if cmd.argument
153 if (!cmd.argument().empty())
154 cur.dispatch(FuncRequest(LFUN_MATH_INSERT,
157 // create a macro if we see "\\newcommand"
158 // somewhere, and an ordinary formula
160 if (sel.find(from_ascii("\\newcommand")) == string::npos
161 && sel.find(from_ascii("\\def")) == string::npos)
163 InsetMathHull * formula = new InsetMathHull;
164 istringstream is(to_utf8(sel));
167 formula->read(cur.buffer(), lex);
168 if (formula->getType() == hullNone)
169 // Don't create pseudo formulas if
170 // delimiters are left out
171 formula->mutate(hullSimple);
174 cur.insert(new MathMacroTemplate(sel));
177 cur.message(from_utf8(N_("Math editor mode")));
186 string const freefont2string()
189 if (font2string(freefont, toggleall, data))
196 void Text::cursorPrevious(Cursor & cur)
198 pos_type cpos = cur.pos();
199 pit_type cpar = cur.pit();
201 int x = cur.x_target();
202 setCursorFromCoordinates(cur, x, 0);
203 cur.dispatch(FuncRequest(cur.selection()? LFUN_UP_SELECT: LFUN_UP));
205 if (cpar == cur.pit() && cpos == cur.pos())
206 // we have a row which is taller than the workarea. The
207 // simplest solution is to move to the previous row instead.
208 cur.dispatch(FuncRequest(cur.selection()? LFUN_UP_SELECT: LFUN_UP));
211 cur.updateFlags(Update::Force | Update::FitCursor);
215 void Text::cursorNext(Cursor & cur)
217 pos_type cpos = cur.pos();
218 pit_type cpar = cur.pit();
220 int x = cur.x_target();
221 setCursorFromCoordinates(cur, x, cur.bv().workHeight() - 1);
222 cur.dispatch(FuncRequest(cur.selection()? LFUN_DOWN_SELECT: LFUN_DOWN));
224 if (cpar == cur.pit() && cpos == cur.pos())
225 // we have a row which is taller than the workarea. The
226 // simplest solution is to move to the next row instead.
228 FuncRequest(cur.selection()? LFUN_DOWN_SELECT: LFUN_DOWN));
231 cur.updateFlags(Update::Force | Update::FitCursor);
237 void specialChar(Cursor & cur, InsetSpecialChar::Kind kind)
240 cap::replaceSelection(cur);
241 cur.insert(new InsetSpecialChar(kind));
246 bool doInsertInset(Cursor & cur, Text * text,
247 FuncRequest const & cmd, bool edit, bool pastesel)
249 Inset * inset = createInset(&cur.bv(), cmd);
255 if (cur.selection()) {
256 lyx::dispatch(FuncRequest(LFUN_CUT));
259 text->insertInset(cur, inset);
262 inset->edit(cur, true);
264 if (gotsel && pastesel) {
265 lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
266 // reset first par to default
267 if (cur.lastpit() != 0 || cur.lastpos() != 0) {
268 Layout_ptr const layout =
269 cur.buffer().params().getTextClass().defaultLayout();
270 cur.text()->paragraphs().begin()->layout(layout);
280 void Text::number(Cursor & cur)
282 Font font(Font::ALL_IGNORE);
283 font.setNumber(Font::TOGGLE);
284 toggleAndShow(cur, this, font);
288 bool Text::isRTL(Buffer const & buffer, Paragraph const & par) const
290 return par.isRightToLeftPar(buffer.params());
294 bool Text::isRTL(Buffer const & buffer, CursorSlice const & sl, bool boundary) const
296 if (!lyxrc.rtl_support && !sl.text())
300 if (boundary && sl.pos() > 0)
303 Paragraph const & par = getPar(sl.pit());
304 return getFont(buffer, par, sl.pos() + correction).isVisibleRightToLeft();
308 bool Text::isRTLBoundary(Buffer const & buffer, Paragraph const & par,
311 if (!lyxrc.rtl_support)
314 // no RTL boundary at line start
318 bool left = getFont(buffer, par, pos - 1).isVisibleRightToLeft();
320 if (pos == par.size())
321 right = par.isRightToLeftPar(buffer.params());
323 right = getFont(buffer, par, pos).isVisibleRightToLeft();
324 return left != right;
328 bool Text::isRTLBoundary(Buffer const & buffer, Paragraph const & par,
329 pos_type pos, Font const & font) const
331 if (!lyxrc.rtl_support)
334 bool left = font.isVisibleRightToLeft();
336 if (pos == par.size())
337 right = par.isRightToLeftPar(buffer.params());
339 right = getFont(buffer, par, pos).isVisibleRightToLeft();
340 return left != right;
344 void Text::dispatch(Cursor & cur, FuncRequest & cmd)
346 LYXERR(Debug::ACTION) << "Text::dispatch: cmd: " << cmd << endl;
348 // FIXME: We use the update flag to indicates wether a singlePar or a
349 // full screen update is needed. We reset it here but shall we restore it
353 BOOST_ASSERT(cur.text() == this);
354 BufferView * bv = &cur.bv();
355 CursorSlice oldTopSlice = cur.top();
356 bool oldBoundary = cur.boundary();
357 bool sel = cur.selection();
358 // Signals that, even if needsUpdate == false, an update of the
359 // cursor paragraph is required
360 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
361 LyXAction::SingleParUpdate);
362 // Signals that a full-screen update is required
363 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
364 LyXAction::NoUpdate) || singleParUpdate);
365 // Remember the old paragraph metric (_outer_ paragraph!)
366 ParagraphMetrics const & pm = cur.bv().parMetrics(
367 cur.bottom().text(), cur.bottom().pit());
368 Dimension olddim = pm.dim();
370 switch (cmd.action) {
372 case LFUN_PARAGRAPH_MOVE_DOWN: {
373 pit_type const pit = cur.pit();
374 recUndo(cur, pit, pit + 1);
376 std::swap(pars_[pit], pars_[pit + 1]);
377 updateLabels(cur.buffer());
383 case LFUN_PARAGRAPH_MOVE_UP: {
384 pit_type const pit = cur.pit();
385 recUndo(cur, pit - 1, pit);
387 std::swap(pars_[pit], pars_[pit - 1]);
388 updateLabels(cur.buffer());
394 case LFUN_APPENDIX: {
395 Paragraph & par = cur.paragraph();
396 bool start = !par.params().startOfAppendix();
398 // FIXME: The code below only makes sense at top level.
399 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
400 // ensure that we have only one start_of_appendix in this document
401 // FIXME: this don't work for multipart document!
402 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
403 if (pars_[tmp].params().startOfAppendix()) {
405 pars_[tmp].params().startOfAppendix(false);
411 par.params().startOfAppendix(start);
413 // we can set the refreshing parameters now
414 updateLabels(cur.buffer());
418 case LFUN_WORD_DELETE_FORWARD:
419 if (cur.selection()) {
420 cutSelection(cur, true, false);
422 deleteWordForward(cur);
423 finishChange(cur, false);
426 case LFUN_WORD_DELETE_BACKWARD:
427 if (cur.selection()) {
428 cutSelection(cur, true, false);
430 deleteWordBackward(cur);
431 finishChange(cur, false);
434 case LFUN_LINE_DELETE:
435 if (cur.selection()) {
436 cutSelection(cur, true, false);
438 deleteLineForward(cur);
439 finishChange(cur, false);
442 case LFUN_BUFFER_BEGIN:
443 case LFUN_BUFFER_BEGIN_SELECT:
444 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
445 if (cur.depth() == 1) {
446 needsUpdate |= cursorTop(cur);
452 case LFUN_BUFFER_END:
453 case LFUN_BUFFER_END_SELECT:
454 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
455 if (cur.depth() == 1) {
456 needsUpdate |= cursorBottom(cur);
462 case LFUN_CHAR_FORWARD:
463 case LFUN_CHAR_FORWARD_SELECT:
464 //lyxerr << BOOST_CURRENT_FUNCTION
465 // << " LFUN_CHAR_FORWARD[SEL]:\n" << cur << endl;
466 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
467 if (reverseDirectionNeeded(cur))
468 needsUpdate |= cursorLeft(cur);
470 needsUpdate |= cursorRight(cur);
472 if (!needsUpdate && oldTopSlice == cur.top()
473 && cur.boundary() == oldBoundary) {
475 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
479 case LFUN_CHAR_BACKWARD:
480 case LFUN_CHAR_BACKWARD_SELECT:
481 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
482 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
483 if (reverseDirectionNeeded(cur))
484 needsUpdate |= cursorRight(cur);
486 needsUpdate |= cursorLeft(cur);
488 if (!needsUpdate && oldTopSlice == cur.top()
489 && cur.boundary() == oldBoundary) {
491 cmd = FuncRequest(LFUN_FINISHED_LEFT);
496 case LFUN_DOWN_SELECT:
499 // stop/start the selection
500 bool select = cmd.action == LFUN_DOWN_SELECT ||
501 cmd.action == LFUN_UP_SELECT;
502 cur.selHandle(select);
504 // move cursor up/down
505 bool up = cmd.action == LFUN_UP_SELECT || cmd.action == LFUN_UP;
506 bool const successful = cur.upDownInText(up, needsUpdate);
508 // notify insets which were left and get their update flags
509 notifyCursorLeaves(cur.beforeDispatchCursor(), cur);
512 // redraw if you leave mathed (for the decorations)
513 needsUpdate |= cur.beforeDispatchCursor().inMathed();
520 case LFUN_PARAGRAPH_UP:
521 case LFUN_PARAGRAPH_UP_SELECT:
522 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
523 needsUpdate |= cursorUpParagraph(cur);
526 case LFUN_PARAGRAPH_DOWN:
527 case LFUN_PARAGRAPH_DOWN_SELECT:
528 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
529 needsUpdate |= cursorDownParagraph(cur);
533 case LFUN_SCREEN_UP_SELECT:
534 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_UP_SELECT);
535 if (cur.pit() == 0 && cur.textRow().pos() == 0)
542 case LFUN_SCREEN_DOWN:
543 case LFUN_SCREEN_DOWN_SELECT:
544 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_DOWN_SELECT);
545 if (cur.pit() == cur.lastpit()
546 && cur.textRow().endpos() == cur.lastpos())
553 case LFUN_LINE_BEGIN:
554 case LFUN_LINE_BEGIN_SELECT:
555 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
556 needsUpdate |= cursorHome(cur);
560 case LFUN_LINE_END_SELECT:
561 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
562 needsUpdate |= cursorEnd(cur);
565 case LFUN_WORD_FORWARD:
566 case LFUN_WORD_FORWARD_SELECT:
567 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
568 if (reverseDirectionNeeded(cur))
569 needsUpdate |= cursorLeftOneWord(cur);
571 needsUpdate |= cursorRightOneWord(cur);
574 case LFUN_WORD_BACKWARD:
575 case LFUN_WORD_BACKWARD_SELECT:
576 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
577 if (reverseDirectionNeeded(cur))
578 needsUpdate |= cursorRightOneWord(cur);
580 needsUpdate |= cursorLeftOneWord(cur);
583 case LFUN_WORD_SELECT: {
584 selectWord(cur, WHOLE_WORD);
585 finishChange(cur, true);
589 case LFUN_BREAK_LINE: {
590 // Not allowed by LaTeX (labels or empty par)
591 if (cur.pos() > cur.paragraph().beginOfBody()) {
592 // this avoids a double undo
593 // FIXME: should not be needed, ideally
594 if (!cur.selection())
596 cap::replaceSelection(cur);
597 cur.insert(new InsetNewline);
599 moveCursor(cur, false);
604 case LFUN_CHAR_DELETE_FORWARD:
605 if (!cur.selection()) {
606 if (cur.pos() == cur.paragraph().size())
607 // Par boundary, force full-screen update
608 singleParUpdate = false;
609 needsUpdate |= erase(cur);
611 // It is possible to make it a lot faster still
612 // just comment out the line below...
614 cutSelection(cur, true, false);
615 singleParUpdate = false;
617 moveCursor(cur, false);
620 case LFUN_DELETE_FORWARD_SKIP:
621 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
622 if (!cur.selection()) {
623 if (cur.pos() == cur.lastpos()) {
630 cutSelection(cur, true, false);
635 case LFUN_CHAR_DELETE_BACKWARD:
636 if (!cur.selection()) {
637 if (bv->getIntl().getTransManager().backspace()) {
638 // Par boundary, full-screen update
640 singleParUpdate = false;
641 needsUpdate |= backspace(cur);
643 // It is possible to make it a lot faster still
644 // just comment out the line below...
647 cutSelection(cur, true, false);
648 singleParUpdate = false;
652 case LFUN_DELETE_BACKWARD_SKIP:
653 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
654 if (!cur.selection()) {
656 //CursorSlice cur = cursor();
660 cutSelection(cur, true, false);
664 case LFUN_BREAK_PARAGRAPH:
665 cap::replaceSelection(cur);
666 breakParagraph(cur, 0);
670 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
671 cap::replaceSelection(cur);
672 breakParagraph(cur, 1);
676 case LFUN_BREAK_PARAGRAPH_SKIP: {
677 // When at the beginning of a paragraph, remove
678 // indentation. Otherwise, do the same as LFUN_BREAK_PARAGRAPH.
679 cap::replaceSelection(cur);
681 cur.paragraph().params().labelWidthString(docstring());
683 breakParagraph(cur, 0);
688 case LFUN_PARAGRAPH_SPACING: {
689 Paragraph & par = cur.paragraph();
690 Spacing::Space cur_spacing = par.params().spacing().getSpace();
691 string cur_value = "1.0";
692 if (cur_spacing == Spacing::Other)
693 cur_value = par.params().spacing().getValueAsString();
695 istringstream is(to_utf8(cmd.argument()));
698 Spacing::Space new_spacing = cur_spacing;
699 string new_value = cur_value;
701 lyxerr << "Missing argument to `paragraph-spacing'"
703 } else if (tmp == "single") {
704 new_spacing = Spacing::Single;
705 } else if (tmp == "onehalf") {
706 new_spacing = Spacing::Onehalf;
707 } else if (tmp == "double") {
708 new_spacing = Spacing::Double;
709 } else if (tmp == "other") {
710 new_spacing = Spacing::Other;
711 string tmpval = "0.0";
713 lyxerr << "new_value = " << tmpval << endl;
716 } else if (tmp == "default") {
717 new_spacing = Spacing::Default;
719 lyxerr << to_utf8(_("Unknown spacing argument: "))
720 << to_utf8(cmd.argument()) << endl;
722 if (cur_spacing != new_spacing || cur_value != new_value)
723 par.params().spacing(Spacing(new_spacing, new_value));
727 case LFUN_INSET_INSERT: {
729 Inset * inset = createInset(bv, cmd);
731 // FIXME (Abdel 01/02/2006):
732 // What follows would be a partial fix for bug 2154:
733 // http://bugzilla.lyx.org/show_bug.cgi?id=2154
734 // This automatically put the label inset _after_ a
735 // numbered section. It should be possible to extend the mechanism
736 // to any kind of LateX environement.
737 // The correct way to fix that bug would be at LateX generation.
738 // I'll let the code here for reference as it could be used for some
739 // other feature like "automatic labelling".
741 Paragraph & par = pars_[cur.pit()];
742 if (inset->lyxCode() == Inset::LABEL_CODE
743 && par.layout()->labeltype == LABEL_COUNTER) {
744 // Go to the end of the paragraph
745 // Warning: Because of Change-Tracking, the last
746 // position is 'size()' and not 'size()-1':
747 cur.pos() = par.size();
748 // Insert a new paragraph
749 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
754 cutSelection(cur, true, false);
755 insertInset(cur, inset);
761 case LFUN_INSET_DISSOLVE:
762 needsUpdate |= dissolveInset(cur);
765 case LFUN_INSET_SETTINGS:
766 cur.inset().showInsetDialog(bv);
769 case LFUN_SPACE_INSERT:
770 if (cur.paragraph().layout()->free_spacing)
771 insertChar(cur, ' ');
773 doInsertInset(cur, this, cmd, false, false);
776 moveCursor(cur, false);
779 case LFUN_HYPHENATION_POINT_INSERT:
780 specialChar(cur, InsetSpecialChar::HYPHENATION);
783 case LFUN_LIGATURE_BREAK_INSERT:
784 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
787 case LFUN_DOTS_INSERT:
788 specialChar(cur, InsetSpecialChar::LDOTS);
791 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
792 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
795 case LFUN_MENU_SEPARATOR_INSERT:
796 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
799 case LFUN_WORD_UPCASE:
800 changeCase(cur, Text::text_uppercase);
803 case LFUN_WORD_LOWCASE:
804 changeCase(cur, Text::text_lowercase);
807 case LFUN_WORD_CAPITALIZE:
808 changeCase(cur, Text::text_capitalization);
811 case LFUN_CHARS_TRANSPOSE:
816 cur.message(_("Paste"));
817 cap::replaceSelection(cur);
818 if (cmd.argument().empty() && !theClipboard().isInternal())
819 pasteClipboard(cur, bv->buffer()->errorList("Paste"));
821 string const arg(to_utf8(cmd.argument()));
822 pasteFromStack(cur, bv->buffer()->errorList("Paste"),
823 isStrUnsignedInt(arg) ?
824 convert<unsigned int>(arg) :
827 bv->buffer()->errors("Paste");
828 cur.clearSelection(); // bug 393
833 cutSelection(cur, true, true);
834 cur.message(_("Cut"));
839 cur.message(_("Copy"));
842 case LFUN_SERVER_GET_XY:
843 cur.message(from_utf8(
844 convert<string>(cursorX(cur.bv(), cur.top(), cur.boundary()))
845 + ' ' + convert<string>(cursorY(cur.bv(), cur.top(), cur.boundary()))));
848 case LFUN_SERVER_SET_XY: {
851 istringstream is(to_utf8(cmd.argument()));
854 lyxerr << "SETXY: Could not parse coordinates in '"
855 << to_utf8(cmd.argument()) << std::endl;
857 setCursorFromCoordinates(cur, x, y);
861 case LFUN_SERVER_GET_FONT:
862 if (current_font.shape() == Font::ITALIC_SHAPE)
863 cur.message(from_ascii("E"));
864 else if (current_font.shape() == Font::SMALLCAPS_SHAPE)
865 cur.message(from_ascii("N"));
867 cur.message(from_ascii("0"));
870 case LFUN_SERVER_GET_LAYOUT:
871 cur.message(cur.paragraph().layout()->name());
875 docstring layout = cmd.argument();
876 LYXERR(Debug::INFO) << "LFUN_LAYOUT: (arg) " << to_utf8(layout) << endl;
878 // Derive layout number from given argument (string)
879 // and current buffer's textclass (number)
880 TextClass const & tclass = bv->buffer()->params().getTextClass();
882 layout = tclass.defaultLayoutName();
883 bool hasLayout = tclass.hasLayout(layout);
885 // If the entry is obsolete, use the new one instead.
887 docstring const & obs = tclass[layout]->obsoleted_by();
893 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
894 from_utf8(N_(" not known")));
898 bool change_layout = (frontend::current_layout != layout);
900 if (!change_layout && cur.selection() &&
901 cur.selBegin().pit() != cur.selEnd().pit())
903 pit_type spit = cur.selBegin().pit();
904 pit_type epit = cur.selEnd().pit() + 1;
905 while (spit != epit) {
906 if (pars_[spit].layout()->name() != frontend::current_layout) {
907 change_layout = true;
915 setLayout(cur, layout);
916 // inform the GUI that the layout has changed.
917 bv->layoutChanged(layout);
922 case LFUN_CLIPBOARD_PASTE:
923 cur.clearSelection();
924 pasteClipboard(cur, bv->buffer()->errorList("Paste"),
925 cmd.argument() == "paragraph");
926 bv->buffer()->errors("Paste");
929 case LFUN_PRIMARY_SELECTION_PASTE:
930 pasteString(cur, theSelection().get(),
931 cmd.argument() == "paragraph");
934 case LFUN_UNICODE_INSERT: {
935 if (cmd.argument().empty())
937 docstring hexstring = cmd.argument();
938 if (lyx::support::isHex(hexstring)) {
939 char_type c = lyx::support::hexToInt(hexstring);
940 if (c >= 32 && c < 0x10ffff) {
941 lyxerr << "Inserting c: " << c << endl;
942 docstring s = docstring(1, c);
943 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
949 case LFUN_QUOTE_INSERT: {
950 Paragraph & par = cur.paragraph();
951 pos_type pos = cur.pos();
952 BufferParams const & bufparams = bv->buffer()->params();
953 Layout_ptr const & style = par.layout();
954 if (!style->pass_thru
955 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
956 // this avoids a double undo
957 // FIXME: should not be needed, ideally
958 if (!cur.selection())
960 cap::replaceSelection(cur);
965 else if (cur.prevInset() && cur.prevInset()->isSpace())
968 c = par.getChar(pos - 1);
969 string arg = to_utf8(cmd.argument());
971 cur.insert(new InsetQuotes(c,
972 bufparams.quotes_language,
973 InsetQuotes::SingleQ));
975 cur.insert(new InsetQuotes(c,
976 bufparams.quotes_language,
977 InsetQuotes::DoubleQ));
981 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
985 case LFUN_DATE_INSERT: {
986 string const format = cmd.argument().empty()
987 ? lyxrc.date_insert_format : to_utf8(cmd.argument());
988 string const time = formatted_time(current_time(), format);
989 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, time));
993 case LFUN_MOUSE_TRIPLE:
994 if (cmd.button() == mouse_button::button1) {
1003 case LFUN_MOUSE_DOUBLE:
1004 if (cmd.button() == mouse_button::button1) {
1005 selectWord(cur, WHOLE_WORD_STRICT);
1010 // Single-click on work area
1011 case LFUN_MOUSE_PRESS: {
1012 // Right click on a footnote flag opens float menu
1013 if (cmd.button() == mouse_button::button3)
1014 cur.clearSelection();
1017 bool update = bv->mouseSetCursor(cur);
1019 // Insert primary selection with middle mouse
1020 // if there is a local selection in the current buffer,
1022 if (cmd.button() == mouse_button::button2) {
1023 if (cap::selection()) {
1024 // Copy the selection buffer to the clipboard
1025 // stack, because we want it to appear in the
1026 // "Edit->Paste recent" menu.
1027 cap::copySelectionToStack();
1029 cap::pasteSelection(bv->cursor(),
1030 bv->buffer()->errorList("Paste"));
1031 bv->buffer()->errors("Paste");
1032 bv->buffer()->markDirty();
1035 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
1039 // we have to update after dEPM triggered
1040 if (!update && cmd.button() == mouse_button::button1) {
1041 needsUpdate = false;
1048 case LFUN_MOUSE_MOTION: {
1049 // Only use motion with button 1
1050 //if (cmd.button() != mouse_button::button1)
1053 // ignore motions deeper nested than the real anchor
1054 Cursor & bvcur = cur.bv().cursor();
1055 if (bvcur.anchor_.hasPart(cur)) {
1056 CursorSlice old = bvcur.top();
1058 int const wh = bv->workHeight();
1059 int const y = std::max(0, std::min(wh - 1, cmd.y));
1061 setCursorFromCoordinates(cur, cmd.x, y);
1062 cur.setTargetX(cmd.x);
1064 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1066 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1067 // This is to allow jumping over large insets
1068 if (cur.top() == old) {
1070 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1072 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1075 if (cur.top() == old)
1078 // don't set anchor_
1079 bvcur.setCursor(cur);
1080 bvcur.selection() = true;
1081 //lyxerr << "MOTION: " << bv->cursor() << endl;
1089 case LFUN_MOUSE_RELEASE: {
1090 if (cmd.button() == mouse_button::button2)
1093 if (cmd.button() == mouse_button::button1) {
1094 // if there is new selection, update persistent
1095 // selection, otherwise, single click does not
1096 // clear persistent selection buffer
1097 if (cur.selection()) {
1099 // if double click, cur is moved to the end of word by selectWord
1100 // but bvcur is current mouse position
1101 Cursor & bvcur = cur.bv().cursor();
1102 bvcur.selection() = true;
1104 needsUpdate = false;
1111 case LFUN_SELF_INSERT: {
1112 if (cmd.argument().empty())
1115 // Automatically delete the currently selected
1116 // text and replace it with what is being
1117 // typed in now. Depends on lyxrc settings
1118 // "auto_region_delete", which defaults to
1121 if (lyxrc.auto_region_delete && cur.selection()) {
1122 cutSelection(cur, false, false);
1123 // When change tracking is set to off, the metrics update
1124 // mechanism correctly detects if a full update is needed or not.
1125 // This detection fails when a selection spans multiple rows and
1126 // change tracking is enabled because the paragraph metrics stays
1127 // the same. In this case, we force the full update:
1128 // (see http://bugzilla.lyx.org/show_bug.cgi?id=3992)
1129 if (cur.buffer().params().trackChanges)
1130 cur.updateFlags(Update::Force);
1133 cur.clearSelection();
1134 Font const old_font = real_current_font;
1136 docstring::const_iterator cit = cmd.argument().begin();
1137 docstring::const_iterator end = cmd.argument().end();
1138 for (; cit != end; ++cit)
1139 bv->translateAndInsert(*cit, this, cur);
1142 moveCursor(cur, false);
1146 case LFUN_URL_INSERT: {
1147 InsetCommandParams p("url");
1149 if (cur.selection()) {
1150 content = cur.selectionAsString(false);
1151 cutSelection(cur, true, false);
1153 p["target"] = (cmd.argument().empty()) ?
1154 content : cmd.argument();
1155 string const data = InsetCommandMailer::params2string("url", p);
1156 if (p["target"].empty()) {
1157 bv->showInsetDialog("url", data, 0);
1159 FuncRequest fr(LFUN_INSET_INSERT, data);
1165 case LFUN_HTML_INSERT: {
1166 InsetCommandParams p("htmlurl");
1168 if (cur.selection()) {
1169 content = cur.selectionAsString(false);
1170 cutSelection(cur, true, false);
1172 p["target"] = (cmd.argument().empty()) ?
1173 content : cmd.argument();
1174 string const data = InsetCommandMailer::params2string("url", p);
1175 if (p["target"].empty()) {
1176 bv->showInsetDialog("url", data, 0);
1178 FuncRequest fr(LFUN_INSET_INSERT, data);
1184 case LFUN_LABEL_INSERT: {
1185 InsetCommandParams p("label");
1186 // Try to generate a valid label
1187 p["name"] = (cmd.argument().empty()) ?
1188 cur.getPossibleLabel() :
1190 string const data = InsetCommandMailer::params2string("label", p);
1192 if (cmd.argument().empty()) {
1193 bv->showInsetDialog("label", data, 0);
1195 FuncRequest fr(LFUN_INSET_INSERT, data);
1203 case LFUN_LIST_INSERT:
1204 case LFUN_THEOREM_INSERT:
1206 case LFUN_CAPTION_INSERT:
1207 // Open the inset, and move the current selection
1209 doInsertInset(cur, this, cmd, true, true);
1211 updateLabels(*bv->buffer());
1213 case LFUN_NOTE_INSERT:
1214 case LFUN_CHARSTYLE_INSERT:
1215 case LFUN_BOX_INSERT:
1216 case LFUN_BRANCH_INSERT:
1217 case LFUN_BIBITEM_INSERT:
1218 case LFUN_ERT_INSERT:
1219 case LFUN_LISTING_INSERT:
1220 case LFUN_FOOTNOTE_INSERT:
1221 case LFUN_MARGINALNOTE_INSERT:
1222 case LFUN_OPTIONAL_INSERT:
1223 case LFUN_ENVIRONMENT_INSERT:
1224 // Open the inset, and move the current selection
1226 doInsertInset(cur, this, cmd, true, true);
1230 case LFUN_TABULAR_INSERT:
1231 // if there were no arguments, just open the dialog
1232 if (doInsertInset(cur, this, cmd, false, true))
1235 bv->showDialog("tabularcreate");
1239 case LFUN_FLOAT_INSERT:
1240 case LFUN_FLOAT_WIDE_INSERT:
1241 case LFUN_WRAP_INSERT: {
1242 bool content = cur.selection(); // will some text be moved into the inset?
1244 doInsertInset(cur, this, cmd, true, true);
1246 ParagraphList & pars = cur.text()->paragraphs();
1248 TextClass const & tclass = bv->buffer()->params().getTextClass();
1250 // add a separate paragraph for the caption inset
1251 pars.push_back(Paragraph());
1252 pars.back().setInsetOwner(pars[0].inInset());
1253 pars.back().layout(tclass.defaultLayout());
1255 int cap_pit = pars.size() - 1;
1257 // if an empty inset was created, we create an additional empty
1258 // paragraph at the bottom so that the user can choose where to put
1259 // the graphics (or table).
1261 pars.push_back(Paragraph());
1262 pars.back().setInsetOwner(pars[0].inInset());
1263 pars.back().layout(tclass.defaultLayout());
1267 // reposition the cursor to the caption
1268 cur.pit() = cap_pit;
1270 cur.dispatch(FuncRequest(LFUN_CAPTION_INSERT));
1271 // FIXME: When leaving the Float (or Wrap) inset we should
1272 // delete any empty paragraph left above or below the
1277 case LFUN_INDEX_INSERT:
1278 case LFUN_NOMENCL_INSERT: {
1279 Inset * inset = createInset(&cur.bv(), cmd);
1283 cur.clearSelection();
1284 insertInset(cur, inset);
1285 inset->edit(cur, true);
1286 // Show the dialog for the nomenclature entry, since the
1287 // description entry still needs to be filled in.
1288 if (cmd.action == LFUN_NOMENCL_INSERT)
1289 InsetCommandMailer("nomenclature",
1290 *reinterpret_cast<InsetCommand *>(inset)).showDialog(&cur.bv());
1295 case LFUN_INDEX_PRINT:
1296 case LFUN_NOMENCL_PRINT:
1297 case LFUN_TOC_INSERT:
1298 case LFUN_HFILL_INSERT:
1299 case LFUN_LINE_INSERT:
1300 case LFUN_PAGEBREAK_INSERT:
1301 case LFUN_CLEARPAGE_INSERT:
1302 case LFUN_CLEARDOUBLEPAGE_INSERT:
1304 doInsertInset(cur, this, cmd, false, false);
1308 case LFUN_DEPTH_DECREMENT:
1309 changeDepth(cur, DEC_DEPTH);
1312 case LFUN_DEPTH_INCREMENT:
1313 changeDepth(cur, INC_DEPTH);
1316 case LFUN_MATH_DISPLAY:
1317 mathDispatch(cur, cmd, true);
1320 case LFUN_MATH_IMPORT_SELECTION:
1321 case LFUN_MATH_MODE:
1322 if (cmd.argument() == "on")
1323 // don't pass "on" as argument
1324 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1326 mathDispatch(cur, cmd, false);
1329 case LFUN_MATH_MACRO:
1330 if (cmd.argument().empty())
1331 cur.errorMessage(from_utf8(N_("Missing argument")));
1333 string s = to_utf8(cmd.argument());
1334 string const s1 = token(s, ' ', 1);
1335 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1336 string const s2 = token(s, ' ', 2);
1337 string const type = s2.empty() ? "newcommand" : s2;
1338 cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, from_utf8(type)));
1339 //cur.nextInset()->edit(cur, true);
1343 // passthrough hat and underscore outside mathed:
1344 case LFUN_MATH_SUBSCRIPT:
1345 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1347 case LFUN_MATH_SUPERSCRIPT:
1348 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1351 case LFUN_MATH_INSERT:
1352 case LFUN_MATH_MATRIX:
1353 case LFUN_MATH_DELIM:
1354 case LFUN_MATH_BIGDELIM: {
1355 if (cur.selection())
1356 cur.clearSelection();
1357 // FIXME: instead of the above, this one
1358 // should be used (but it asserts with Bidi enabled)
1359 // cf. http://bugzilla.lyx.org/show_bug.cgi?id=4055
1360 // cap::replaceSelection(cur);
1361 cur.insert(new InsetMathHull(hullSimple));
1362 checkAndActivateInset(cur, true);
1363 BOOST_ASSERT(cur.inMathed());
1368 case LFUN_FONT_EMPH: {
1369 Font font(Font::ALL_IGNORE);
1370 font.setEmph(Font::TOGGLE);
1371 toggleAndShow(cur, this, font);
1375 case LFUN_FONT_BOLD: {
1376 Font font(Font::ALL_IGNORE);
1377 font.setSeries(Font::BOLD_SERIES);
1378 toggleAndShow(cur, this, font);
1382 case LFUN_FONT_NOUN: {
1383 Font font(Font::ALL_IGNORE);
1384 font.setNoun(Font::TOGGLE);
1385 toggleAndShow(cur, this, font);
1389 case LFUN_FONT_CODE: {
1390 Font font(Font::ALL_IGNORE);
1391 font.setFamily(Font::TYPEWRITER_FAMILY); // no good
1392 toggleAndShow(cur, this, font);
1396 case LFUN_FONT_SANS: {
1397 Font font(Font::ALL_IGNORE);
1398 font.setFamily(Font::SANS_FAMILY);
1399 toggleAndShow(cur, this, font);
1403 case LFUN_FONT_ROMAN: {
1404 Font font(Font::ALL_IGNORE);
1405 font.setFamily(Font::ROMAN_FAMILY);
1406 toggleAndShow(cur, this, font);
1410 case LFUN_FONT_DEFAULT: {
1411 Font font(Font::ALL_INHERIT, ignore_language);
1412 toggleAndShow(cur, this, font);
1416 case LFUN_FONT_UNDERLINE: {
1417 Font font(Font::ALL_IGNORE);
1418 font.setUnderbar(Font::TOGGLE);
1419 toggleAndShow(cur, this, font);
1423 case LFUN_FONT_SIZE: {
1424 Font font(Font::ALL_IGNORE);
1425 font.setLyXSize(to_utf8(cmd.argument()));
1426 toggleAndShow(cur, this, font);
1430 case LFUN_LANGUAGE: {
1431 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1434 Font font(Font::ALL_IGNORE);
1435 font.setLanguage(lang);
1436 toggleAndShow(cur, this, font);
1440 case LFUN_FONT_FREE_APPLY:
1441 toggleAndShow(cur, this, freefont, toggleall);
1442 cur.message(_("Character set"));
1445 // Set the freefont using the contents of \param data dispatched from
1446 // the frontends and apply it at the current cursor location.
1447 case LFUN_FONT_FREE_UPDATE: {
1450 if (bv_funcs::string2font(to_utf8(cmd.argument()), font, toggle)) {
1453 toggleAndShow(cur, this, freefont, toggleall);
1454 cur.message(_("Character set"));
1459 case LFUN_FINISHED_LEFT:
1460 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1461 if (reverseDirectionNeeded(cur))
1465 case LFUN_FINISHED_RIGHT:
1466 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1467 if (!reverseDirectionNeeded(cur))
1471 case LFUN_LAYOUT_PARAGRAPH: {
1473 params2string(cur.paragraph(), data);
1474 data = "show\n" + data;
1475 bv->showDialogWithData("paragraph", data);
1479 case LFUN_PARAGRAPH_UPDATE: {
1481 params2string(cur.paragraph(), data);
1483 // Will the paragraph accept changes from the dialog?
1484 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1486 data = "update " + convert<string>(accept) + '\n' + data;
1487 bv->updateDialog("paragraph", data);
1491 case LFUN_ACCENT_UMLAUT:
1492 case LFUN_ACCENT_CIRCUMFLEX:
1493 case LFUN_ACCENT_GRAVE:
1494 case LFUN_ACCENT_ACUTE:
1495 case LFUN_ACCENT_TILDE:
1496 case LFUN_ACCENT_CEDILLA:
1497 case LFUN_ACCENT_MACRON:
1498 case LFUN_ACCENT_DOT:
1499 case LFUN_ACCENT_UNDERDOT:
1500 case LFUN_ACCENT_UNDERBAR:
1501 case LFUN_ACCENT_CARON:
1502 case LFUN_ACCENT_SPECIAL_CARON:
1503 case LFUN_ACCENT_BREVE:
1504 case LFUN_ACCENT_TIE:
1505 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1506 case LFUN_ACCENT_CIRCLE:
1507 case LFUN_ACCENT_OGONEK:
1508 theLyXFunc().handleKeyFunc(cmd.action);
1509 if (!cmd.argument().empty())
1510 // FIXME: Are all these characters encoded in one byte in utf8?
1511 bv->translateAndInsert(cmd.argument()[0], this, cur);
1514 case LFUN_FLOAT_LIST: {
1515 TextClass const & tclass = bv->buffer()->params().getTextClass();
1516 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1518 if (cur.selection())
1519 cutSelection(cur, true, false);
1520 breakParagraph(cur);
1522 if (cur.lastpos() != 0) {
1524 breakParagraph(cur);
1527 setLayout(cur, tclass.defaultLayoutName());
1528 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, docstring(), 0);
1529 insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1532 lyxerr << "Non-existent float type: "
1533 << to_utf8(cmd.argument()) << endl;
1538 case LFUN_CHANGE_ACCEPT: {
1539 acceptOrRejectChanges(cur, ACCEPT);
1543 case LFUN_CHANGE_REJECT: {
1544 acceptOrRejectChanges(cur, REJECT);
1548 case LFUN_THESAURUS_ENTRY: {
1549 docstring arg = cmd.argument();
1551 arg = cur.selectionAsString(false);
1553 if (arg.size() > 100 || arg.empty()) {
1554 // Get word or selection
1555 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1556 arg = cur.selectionAsString(false);
1559 bv->showDialogWithData("thesaurus", to_utf8(arg));
1563 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1564 // Given data, an encoding of the ParagraphParameters
1565 // generated in the Paragraph dialog, this function sets
1566 // the current paragraph appropriately.
1567 istringstream is(to_utf8(cmd.argument()));
1570 ParagraphParameters params;
1575 params.labelWidthString(),
1577 cur.message(_("Paragraph layout set"));
1582 if (cur.selection()) {
1583 cur.selection() = false;
1586 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1591 LYXERR(Debug::ACTION)
1592 << BOOST_CURRENT_FUNCTION
1593 << ": Command " << cmd
1594 << " not DISPATCHED by Text" << endl;
1599 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1601 // FIXME: The cursor flag is reset two lines below
1602 // so we need to check here if some of the LFUN did touch that.
1603 // for now only Text::erase() and Text::backspace() do that.
1604 // The plan is to verify all the LFUNs and then to remove this
1605 // singleParUpdate boolean altogether.
1606 if (cur.result().update() & Update::Force) {
1607 singleParUpdate = false;
1611 // FIXME: the following code should go in favor of fine grained
1612 // update flag treatment.
1613 if (singleParUpdate) {
1614 // Inserting characters does not change par height
1615 ParagraphMetrics const & pms
1616 = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
1617 if (pms.dim().height()
1618 == olddim.height()) {
1619 // if so, update _only_ this paragraph
1620 cur.updateFlags(Update::SinglePar |
1622 Update::MultiParSel);
1629 && &oldTopSlice.inset() == &cur.inset()
1630 && oldTopSlice.idx() == cur.idx()
1631 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1632 && !cur.selection())
1633 // FIXME: it would be better if we could just do this
1635 //if (cur.result().update() != Update::FitCursor)
1638 // But some LFUNs do not set Update::FitCursor when needed, so we
1639 // do it for all. This is not very harmfull as FitCursor will provoke
1640 // a full redraw only if needed but still, a proper review of all LFUN
1641 // should be done and this needsUpdate boolean can then be removed.
1642 cur.updateFlags(Update::FitCursor);
1644 cur.updateFlags(Update::Force | Update::FitCursor);
1648 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
1649 FuncStatus & flag) const
1651 BOOST_ASSERT(cur.text() == this);
1653 Font const & font = real_current_font;
1655 Inset::Code code = Inset::NO_CODE;
1657 switch (cmd.action) {
1659 case LFUN_DEPTH_DECREMENT:
1660 enable = changeDepthAllowed(cur, DEC_DEPTH);
1663 case LFUN_DEPTH_INCREMENT:
1664 enable = changeDepthAllowed(cur, INC_DEPTH);
1668 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1671 case LFUN_BIBITEM_INSERT:
1672 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO
1676 case LFUN_DIALOG_SHOW_NEW_INSET:
1677 if (cmd.argument() == "bibitem")
1678 code = Inset::BIBITEM_CODE;
1679 else if (cmd.argument() == "bibtex")
1680 code = Inset::BIBTEX_CODE;
1681 else if (cmd.argument() == "box")
1682 code = Inset::BOX_CODE;
1683 else if (cmd.argument() == "branch")
1684 code = Inset::BRANCH_CODE;
1685 else if (cmd.argument() == "citation")
1686 code = Inset::CITE_CODE;
1687 else if (cmd.argument() == "ert")
1688 code = Inset::ERT_CODE;
1689 else if (cmd.argument() == "external")
1690 code = Inset::EXTERNAL_CODE;
1691 else if (cmd.argument() == "float")
1692 code = Inset::FLOAT_CODE;
1693 else if (cmd.argument() == "graphics")
1694 code = Inset::GRAPHICS_CODE;
1695 else if (cmd.argument() == "include")
1696 code = Inset::INCLUDE_CODE;
1697 else if (cmd.argument() == "index")
1698 code = Inset::INDEX_CODE;
1699 else if (cmd.argument() == "nomenclature")
1700 code = Inset::NOMENCL_CODE;
1701 else if (cmd.argument() == "label")
1702 code = Inset::LABEL_CODE;
1703 else if (cmd.argument() == "note")
1704 code = Inset::NOTE_CODE;
1705 else if (cmd.argument() == "ref")
1706 code = Inset::REF_CODE;
1707 else if (cmd.argument() == "toc")
1708 code = Inset::TOC_CODE;
1709 else if (cmd.argument() == "url")
1710 code = Inset::URL_CODE;
1711 else if (cmd.argument() == "vspace")
1712 code = Inset::VSPACE_CODE;
1713 else if (cmd.argument() == "wrap")
1714 code = Inset::WRAP_CODE;
1715 else if (cmd.argument() == "listings")
1716 code = Inset::LISTINGS_CODE;
1719 case LFUN_ERT_INSERT:
1720 code = Inset::ERT_CODE;
1722 case LFUN_LISTING_INSERT:
1723 code = Inset::LISTINGS_CODE;
1725 case LFUN_FOOTNOTE_INSERT:
1726 code = Inset::FOOT_CODE;
1728 case LFUN_TABULAR_INSERT:
1729 code = Inset::TABULAR_CODE;
1731 case LFUN_MARGINALNOTE_INSERT:
1732 code = Inset::MARGIN_CODE;
1734 case LFUN_FLOAT_INSERT:
1735 case LFUN_FLOAT_WIDE_INSERT:
1736 code = Inset::FLOAT_CODE;
1738 case LFUN_WRAP_INSERT:
1739 code = Inset::WRAP_CODE;
1741 case LFUN_FLOAT_LIST:
1742 code = Inset::FLOAT_LIST_CODE;
1745 case LFUN_LIST_INSERT:
1746 code = Inset::LIST_CODE;
1748 case LFUN_THEOREM_INSERT:
1749 code = Inset::THEOREM_CODE;
1752 case LFUN_CAPTION_INSERT:
1753 code = Inset::CAPTION_CODE;
1755 case LFUN_NOTE_INSERT:
1756 code = Inset::NOTE_CODE;
1758 case LFUN_CHARSTYLE_INSERT:
1759 code = Inset::CHARSTYLE_CODE;
1760 if (cur.buffer().params().getTextClass().charstyles().empty())
1763 case LFUN_BOX_INSERT:
1764 code = Inset::BOX_CODE;
1766 case LFUN_BRANCH_INSERT:
1767 code = Inset::BRANCH_CODE;
1768 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1771 case LFUN_LABEL_INSERT:
1772 code = Inset::LABEL_CODE;
1774 case LFUN_OPTIONAL_INSERT:
1775 code = Inset::OPTARG_CODE;
1776 enable = numberOfOptArgs(cur.paragraph())
1777 < cur.paragraph().layout()->optionalargs;
1779 case LFUN_ENVIRONMENT_INSERT:
1780 code = Inset::BOX_CODE;
1782 case LFUN_INDEX_INSERT:
1783 code = Inset::INDEX_CODE;
1785 case LFUN_INDEX_PRINT:
1786 code = Inset::INDEX_PRINT_CODE;
1788 case LFUN_NOMENCL_INSERT:
1789 code = Inset::NOMENCL_CODE;
1791 case LFUN_NOMENCL_PRINT:
1792 code = Inset::NOMENCL_PRINT_CODE;
1794 case LFUN_TOC_INSERT:
1795 code = Inset::TOC_CODE;
1797 case LFUN_HTML_INSERT:
1798 case LFUN_URL_INSERT:
1799 code = Inset::URL_CODE;
1801 case LFUN_QUOTE_INSERT:
1802 // always allow this, since we will inset a raw quote
1803 // if an inset is not allowed.
1805 case LFUN_HYPHENATION_POINT_INSERT:
1806 case LFUN_LIGATURE_BREAK_INSERT:
1807 case LFUN_HFILL_INSERT:
1808 case LFUN_MENU_SEPARATOR_INSERT:
1809 case LFUN_DOTS_INSERT:
1810 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
1811 code = Inset::SPECIALCHAR_CODE;
1813 case LFUN_SPACE_INSERT:
1814 // slight hack: we know this is allowed in math mode
1816 code = Inset::SPACE_CODE;
1819 case LFUN_INSET_MODIFY:
1820 // We need to disable this, because we may get called for a
1822 // InsetTabular::getStatus() -> InsetText::getStatus()
1823 // and we don't handle LFUN_INSET_MODIFY.
1827 case LFUN_FONT_EMPH:
1828 flag.setOnOff(font.emph() == Font::ON);
1831 case LFUN_FONT_NOUN:
1832 flag.setOnOff(font.noun() == Font::ON);
1835 case LFUN_FONT_BOLD:
1836 flag.setOnOff(font.series() == Font::BOLD_SERIES);
1839 case LFUN_FONT_SANS:
1840 flag.setOnOff(font.family() == Font::SANS_FAMILY);
1843 case LFUN_FONT_ROMAN:
1844 flag.setOnOff(font.family() == Font::ROMAN_FAMILY);
1847 case LFUN_FONT_CODE:
1848 flag.setOnOff(font.family() == Font::TYPEWRITER_FAMILY);
1853 enable = cur.selection();
1857 if (cmd.argument().empty()) {
1858 if (theClipboard().isInternal())
1859 enable = cap::numberOfSelections() > 0;
1861 enable = !theClipboard().empty();
1863 string const arg = to_utf8(cmd.argument());
1864 if (isStrUnsignedInt(arg)) {
1865 unsigned int n = convert<unsigned int>(arg);
1866 enable = cap::numberOfSelections() > n;
1873 case LFUN_CLIPBOARD_PASTE:
1874 enable = !theClipboard().empty();
1877 case LFUN_PRIMARY_SELECTION_PASTE:
1878 enable = cur.selection() || !theSelection().empty();
1881 case LFUN_PARAGRAPH_MOVE_UP:
1882 enable = cur.pit() > 0 && !cur.selection();
1885 case LFUN_PARAGRAPH_MOVE_DOWN:
1886 enable = cur.pit() < cur.lastpit() && !cur.selection();
1889 case LFUN_INSET_DISSOLVE:
1890 enable = !isMainText(*cur.bv().buffer()) && cur.inset().nargs() == 1;
1893 case LFUN_CHANGE_ACCEPT:
1894 case LFUN_CHANGE_REJECT:
1895 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
1896 // In principle, these LFUNs should only be enabled if there
1897 // is a change at the current position/in the current selection.
1898 // However, without proper optimizations, this will inevitably
1899 // result in unacceptable performance - just imagine a user who
1900 // wants to select the complete content of a long document.
1904 case LFUN_WORD_DELETE_FORWARD:
1905 case LFUN_WORD_DELETE_BACKWARD:
1906 case LFUN_LINE_DELETE:
1907 case LFUN_WORD_FORWARD:
1908 case LFUN_WORD_BACKWARD:
1909 case LFUN_CHAR_FORWARD:
1910 case LFUN_CHAR_FORWARD_SELECT:
1911 case LFUN_CHAR_BACKWARD:
1912 case LFUN_CHAR_BACKWARD_SELECT:
1914 case LFUN_UP_SELECT:
1916 case LFUN_DOWN_SELECT:
1917 case LFUN_PARAGRAPH_UP_SELECT:
1918 case LFUN_PARAGRAPH_DOWN_SELECT:
1919 case LFUN_SCREEN_UP_SELECT:
1920 case LFUN_SCREEN_DOWN_SELECT:
1921 case LFUN_LINE_BEGIN_SELECT:
1922 case LFUN_LINE_END_SELECT:
1923 case LFUN_WORD_FORWARD_SELECT:
1924 case LFUN_WORD_BACKWARD_SELECT:
1925 case LFUN_WORD_SELECT:
1926 case LFUN_PARAGRAPH_UP:
1927 case LFUN_PARAGRAPH_DOWN:
1928 case LFUN_SCREEN_UP:
1929 case LFUN_SCREEN_DOWN:
1930 case LFUN_LINE_BEGIN:
1932 case LFUN_BREAK_LINE:
1933 case LFUN_CHAR_DELETE_FORWARD:
1934 case LFUN_DELETE_FORWARD_SKIP:
1935 case LFUN_CHAR_DELETE_BACKWARD:
1936 case LFUN_DELETE_BACKWARD_SKIP:
1937 case LFUN_BREAK_PARAGRAPH:
1938 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
1939 case LFUN_BREAK_PARAGRAPH_SKIP:
1940 case LFUN_PARAGRAPH_SPACING:
1941 case LFUN_INSET_INSERT:
1942 case LFUN_WORD_UPCASE:
1943 case LFUN_WORD_LOWCASE:
1944 case LFUN_WORD_CAPITALIZE:
1945 case LFUN_CHARS_TRANSPOSE:
1946 case LFUN_SERVER_GET_XY:
1947 case LFUN_SERVER_SET_XY:
1948 case LFUN_SERVER_GET_FONT:
1949 case LFUN_SERVER_GET_LAYOUT:
1951 case LFUN_DATE_INSERT:
1952 case LFUN_SELF_INSERT:
1953 case LFUN_LINE_INSERT:
1954 case LFUN_PAGEBREAK_INSERT:
1955 case LFUN_CLEARPAGE_INSERT:
1956 case LFUN_CLEARDOUBLEPAGE_INSERT:
1957 case LFUN_MATH_DISPLAY:
1958 case LFUN_MATH_IMPORT_SELECTION:
1959 case LFUN_MATH_MODE:
1960 case LFUN_MATH_MACRO:
1961 case LFUN_MATH_MATRIX:
1962 case LFUN_MATH_DELIM:
1963 case LFUN_MATH_BIGDELIM:
1964 case LFUN_MATH_INSERT:
1965 case LFUN_MATH_SUBSCRIPT:
1966 case LFUN_MATH_SUPERSCRIPT:
1967 case LFUN_FONT_DEFAULT:
1968 case LFUN_FONT_UNDERLINE:
1969 case LFUN_FONT_SIZE:
1971 case LFUN_FONT_FREE_APPLY:
1972 case LFUN_FONT_FREE_UPDATE:
1973 case LFUN_LAYOUT_PARAGRAPH:
1974 case LFUN_PARAGRAPH_UPDATE:
1975 case LFUN_ACCENT_UMLAUT:
1976 case LFUN_ACCENT_CIRCUMFLEX:
1977 case LFUN_ACCENT_GRAVE:
1978 case LFUN_ACCENT_ACUTE:
1979 case LFUN_ACCENT_TILDE:
1980 case LFUN_ACCENT_CEDILLA:
1981 case LFUN_ACCENT_MACRON:
1982 case LFUN_ACCENT_DOT:
1983 case LFUN_ACCENT_UNDERDOT:
1984 case LFUN_ACCENT_UNDERBAR:
1985 case LFUN_ACCENT_CARON:
1986 case LFUN_ACCENT_SPECIAL_CARON:
1987 case LFUN_ACCENT_BREVE:
1988 case LFUN_ACCENT_TIE:
1989 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1990 case LFUN_ACCENT_CIRCLE:
1991 case LFUN_ACCENT_OGONEK:
1992 case LFUN_THESAURUS_ENTRY:
1993 case LFUN_PARAGRAPH_PARAMS_APPLY:
1995 case LFUN_BUFFER_END:
1996 case LFUN_BUFFER_BEGIN:
1997 case LFUN_BUFFER_BEGIN_SELECT:
1998 case LFUN_BUFFER_END_SELECT:
1999 case LFUN_UNICODE_INSERT:
2000 // these are handled in our dispatch()
2008 if (code != Inset::NO_CODE
2009 && (cur.empty() || !cur.inset().insetAllowed(code)))
2012 flag.enabled(enable);
2017 void Text::pasteString(Cursor & cur, docstring const & clip,
2020 cur.clearSelection();
2021 if (!clip.empty()) {
2024 insertStringAsParagraphs(cur, clip);
2026 insertStringAsLines(cur, clip);