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);
689 // With the creation of LFUN_PARAGRAPH_PARAMS, this is now redundant,
690 // as its duties can be performed there. Should it be removed??
691 // FIXME For now, it can just dispatch LFUN_PARAGRAPH_PARAMS...
692 case LFUN_PARAGRAPH_SPACING: {
693 Paragraph & par = cur.paragraph();
694 Spacing::Space cur_spacing = par.params().spacing().getSpace();
695 string cur_value = "1.0";
696 if (cur_spacing == Spacing::Other)
697 cur_value = par.params().spacing().getValueAsString();
699 istringstream is(to_utf8(cmd.argument()));
702 Spacing::Space new_spacing = cur_spacing;
703 string new_value = cur_value;
705 lyxerr << "Missing argument to `paragraph-spacing'"
707 } else if (tmp == "single") {
708 new_spacing = Spacing::Single;
709 } else if (tmp == "onehalf") {
710 new_spacing = Spacing::Onehalf;
711 } else if (tmp == "double") {
712 new_spacing = Spacing::Double;
713 } else if (tmp == "other") {
714 new_spacing = Spacing::Other;
715 string tmpval = "0.0";
717 lyxerr << "new_value = " << tmpval << endl;
720 } else if (tmp == "default") {
721 new_spacing = Spacing::Default;
723 lyxerr << to_utf8(_("Unknown spacing argument: "))
724 << to_utf8(cmd.argument()) << endl;
726 if (cur_spacing != new_spacing || cur_value != new_value)
727 par.params().spacing(Spacing(new_spacing, new_value));
731 case LFUN_INSET_INSERT: {
733 Inset * inset = createInset(bv, cmd);
735 // FIXME (Abdel 01/02/2006):
736 // What follows would be a partial fix for bug 2154:
737 // http://bugzilla.lyx.org/show_bug.cgi?id=2154
738 // This automatically put the label inset _after_ a
739 // numbered section. It should be possible to extend the mechanism
740 // to any kind of LateX environement.
741 // The correct way to fix that bug would be at LateX generation.
742 // I'll let the code here for reference as it could be used for some
743 // other feature like "automatic labelling".
745 Paragraph & par = pars_[cur.pit()];
746 if (inset->lyxCode() == Inset::LABEL_CODE
747 && par.layout()->labeltype == LABEL_COUNTER) {
748 // Go to the end of the paragraph
749 // Warning: Because of Change-Tracking, the last
750 // position is 'size()' and not 'size()-1':
751 cur.pos() = par.size();
752 // Insert a new paragraph
753 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
758 cutSelection(cur, true, false);
759 insertInset(cur, inset);
765 case LFUN_INSET_DISSOLVE:
766 needsUpdate |= dissolveInset(cur);
769 case LFUN_INSET_SETTINGS:
770 cur.inset().showInsetDialog(bv);
773 case LFUN_SPACE_INSERT:
774 if (cur.paragraph().layout()->free_spacing)
775 insertChar(cur, ' ');
777 doInsertInset(cur, this, cmd, false, false);
780 moveCursor(cur, false);
783 case LFUN_HYPHENATION_POINT_INSERT:
784 specialChar(cur, InsetSpecialChar::HYPHENATION);
787 case LFUN_LIGATURE_BREAK_INSERT:
788 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
791 case LFUN_DOTS_INSERT:
792 specialChar(cur, InsetSpecialChar::LDOTS);
795 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
796 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
799 case LFUN_MENU_SEPARATOR_INSERT:
800 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
803 case LFUN_WORD_UPCASE:
804 changeCase(cur, Text::text_uppercase);
807 case LFUN_WORD_LOWCASE:
808 changeCase(cur, Text::text_lowercase);
811 case LFUN_WORD_CAPITALIZE:
812 changeCase(cur, Text::text_capitalization);
815 case LFUN_CHARS_TRANSPOSE:
820 cur.message(_("Paste"));
821 cap::replaceSelection(cur);
822 if (cmd.argument().empty() && !theClipboard().isInternal())
823 pasteClipboard(cur, bv->buffer().errorList("Paste"));
825 string const arg(to_utf8(cmd.argument()));
826 pasteFromStack(cur, bv->buffer().errorList("Paste"),
827 isStrUnsignedInt(arg) ?
828 convert<unsigned int>(arg) :
831 bv->buffer().errors("Paste");
832 cur.clearSelection(); // bug 393
837 cutSelection(cur, true, true);
838 cur.message(_("Cut"));
843 cur.message(_("Copy"));
846 case LFUN_SERVER_GET_XY:
847 cur.message(from_utf8(
848 convert<string>(cursorX(cur.bv(), cur.top(), cur.boundary()))
849 + ' ' + convert<string>(cursorY(cur.bv(), cur.top(), cur.boundary()))));
852 case LFUN_SERVER_SET_XY: {
855 istringstream is(to_utf8(cmd.argument()));
858 lyxerr << "SETXY: Could not parse coordinates in '"
859 << to_utf8(cmd.argument()) << std::endl;
861 setCursorFromCoordinates(cur, x, y);
865 case LFUN_SERVER_GET_FONT:
866 if (current_font.shape() == Font::ITALIC_SHAPE)
867 cur.message(from_ascii("E"));
868 else if (current_font.shape() == Font::SMALLCAPS_SHAPE)
869 cur.message(from_ascii("N"));
871 cur.message(from_ascii("0"));
874 case LFUN_SERVER_GET_LAYOUT:
875 cur.message(cur.paragraph().layout()->name());
879 docstring layout = cmd.argument();
880 LYXERR(Debug::INFO) << "LFUN_LAYOUT: (arg) " << to_utf8(layout) << endl;
882 // Derive layout number from given argument (string)
883 // and current buffer's textclass (number)
884 TextClass const & tclass = bv->buffer().params().getTextClass();
886 layout = tclass.defaultLayoutName();
887 bool hasLayout = tclass.hasLayout(layout);
889 // If the entry is obsolete, use the new one instead.
891 docstring const & obs = tclass[layout]->obsoleted_by();
897 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
898 from_utf8(N_(" not known")));
902 bool change_layout = (frontend::current_layout != layout);
904 if (!change_layout && cur.selection() &&
905 cur.selBegin().pit() != cur.selEnd().pit())
907 pit_type spit = cur.selBegin().pit();
908 pit_type epit = cur.selEnd().pit() + 1;
909 while (spit != epit) {
910 if (pars_[spit].layout()->name() != frontend::current_layout) {
911 change_layout = true;
919 setLayout(cur, layout);
920 // inform the GUI that the layout has changed.
921 bv->layoutChanged(layout);
926 case LFUN_CLIPBOARD_PASTE:
927 cur.clearSelection();
928 pasteClipboard(cur, bv->buffer().errorList("Paste"),
929 cmd.argument() == "paragraph");
930 bv->buffer().errors("Paste");
933 case LFUN_PRIMARY_SELECTION_PASTE:
934 pasteString(cur, theSelection().get(),
935 cmd.argument() == "paragraph");
938 case LFUN_UNICODE_INSERT: {
939 if (cmd.argument().empty())
941 docstring hexstring = cmd.argument();
942 if (lyx::support::isHex(hexstring)) {
943 char_type c = lyx::support::hexToInt(hexstring);
944 if (c >= 32 && c < 0x10ffff) {
945 lyxerr << "Inserting c: " << c << endl;
946 docstring s = docstring(1, c);
947 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
953 case LFUN_QUOTE_INSERT: {
954 Paragraph & par = cur.paragraph();
955 pos_type pos = cur.pos();
956 BufferParams const & bufparams = bv->buffer().params();
957 Layout_ptr const & style = par.layout();
958 if (!style->pass_thru
959 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
960 // this avoids a double undo
961 // FIXME: should not be needed, ideally
962 if (!cur.selection())
964 cap::replaceSelection(cur);
969 else if (cur.prevInset() && cur.prevInset()->isSpace())
972 c = par.getChar(pos - 1);
973 string arg = to_utf8(cmd.argument());
975 cur.insert(new InsetQuotes(c,
976 bufparams.quotes_language,
977 InsetQuotes::SingleQ));
979 cur.insert(new InsetQuotes(c,
980 bufparams.quotes_language,
981 InsetQuotes::DoubleQ));
985 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
989 case LFUN_DATE_INSERT: {
990 string const format = cmd.argument().empty()
991 ? lyxrc.date_insert_format : to_utf8(cmd.argument());
992 string const time = formatted_time(current_time(), format);
993 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, time));
997 case LFUN_MOUSE_TRIPLE:
998 if (cmd.button() == mouse_button::button1) {
1007 case LFUN_MOUSE_DOUBLE:
1008 if (cmd.button() == mouse_button::button1) {
1009 selectWord(cur, WHOLE_WORD_STRICT);
1014 // Single-click on work area
1015 case LFUN_MOUSE_PRESS: {
1016 // Right click on a footnote flag opens float menu
1017 if (cmd.button() == mouse_button::button3)
1018 cur.clearSelection();
1021 bool update = bv->mouseSetCursor(cur);
1023 // Insert primary selection with middle mouse
1024 // if there is a local selection in the current buffer,
1026 if (cmd.button() == mouse_button::button2) {
1027 if (cap::selection()) {
1028 // Copy the selection buffer to the clipboard
1029 // stack, because we want it to appear in the
1030 // "Edit->Paste recent" menu.
1031 cap::copySelectionToStack();
1033 cap::pasteSelection(bv->cursor(),
1034 bv->buffer().errorList("Paste"));
1035 bv->buffer().errors("Paste");
1036 bv->buffer().markDirty();
1039 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
1043 // we have to update after dEPM triggered
1044 if (!update && cmd.button() == mouse_button::button1) {
1045 needsUpdate = false;
1052 case LFUN_MOUSE_MOTION: {
1053 // Only use motion with button 1
1054 //if (cmd.button() != mouse_button::button1)
1057 // ignore motions deeper nested than the real anchor
1058 Cursor & bvcur = cur.bv().cursor();
1059 if (bvcur.anchor_.hasPart(cur)) {
1060 CursorSlice old = bvcur.top();
1062 int const wh = bv->workHeight();
1063 int const y = std::max(0, std::min(wh - 1, cmd.y));
1065 setCursorFromCoordinates(cur, cmd.x, y);
1066 cur.setTargetX(cmd.x);
1068 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1070 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1071 // This is to allow jumping over large insets
1072 if (cur.top() == old) {
1074 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1076 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1079 if (cur.top() == old)
1082 // don't set anchor_
1083 bvcur.setCursor(cur);
1084 bvcur.selection() = true;
1085 //lyxerr << "MOTION: " << bv->cursor() << endl;
1093 case LFUN_MOUSE_RELEASE: {
1094 if (cmd.button() == mouse_button::button2)
1097 if (cmd.button() == mouse_button::button1) {
1098 // if there is new selection, update persistent
1099 // selection, otherwise, single click does not
1100 // clear persistent selection buffer
1101 if (cur.selection()) {
1103 // if double click, cur is moved to the end of word by selectWord
1104 // but bvcur is current mouse position
1105 Cursor & bvcur = cur.bv().cursor();
1106 bvcur.selection() = true;
1108 needsUpdate = false;
1115 case LFUN_SELF_INSERT: {
1116 if (cmd.argument().empty())
1119 // Automatically delete the currently selected
1120 // text and replace it with what is being
1121 // typed in now. Depends on lyxrc settings
1122 // "auto_region_delete", which defaults to
1125 if (lyxrc.auto_region_delete && cur.selection()) {
1126 cutSelection(cur, false, false);
1127 // When change tracking is set to off, the metrics update
1128 // mechanism correctly detects if a full update is needed or not.
1129 // This detection fails when a selection spans multiple rows and
1130 // change tracking is enabled because the paragraph metrics stays
1131 // the same. In this case, we force the full update:
1132 // (see http://bugzilla.lyx.org/show_bug.cgi?id=3992)
1133 if (cur.buffer().params().trackChanges)
1134 cur.updateFlags(Update::Force);
1137 cur.clearSelection();
1138 Font const old_font = real_current_font;
1140 docstring::const_iterator cit = cmd.argument().begin();
1141 docstring::const_iterator end = cmd.argument().end();
1142 for (; cit != end; ++cit)
1143 bv->translateAndInsert(*cit, this, cur);
1146 moveCursor(cur, false);
1150 case LFUN_URL_INSERT: {
1151 InsetCommandParams p("url");
1153 if (cur.selection()) {
1154 content = cur.selectionAsString(false);
1155 cutSelection(cur, true, false);
1157 p["target"] = (cmd.argument().empty()) ?
1158 content : cmd.argument();
1159 string const data = InsetCommandMailer::params2string("url", p);
1160 if (p["target"].empty()) {
1161 bv->showInsetDialog("url", data, 0);
1163 FuncRequest fr(LFUN_INSET_INSERT, data);
1169 case LFUN_HTML_INSERT: {
1170 InsetCommandParams p("htmlurl");
1172 if (cur.selection()) {
1173 content = cur.selectionAsString(false);
1174 cutSelection(cur, true, false);
1176 p["target"] = (cmd.argument().empty()) ?
1177 content : cmd.argument();
1178 string const data = InsetCommandMailer::params2string("url", p);
1179 if (p["target"].empty()) {
1180 bv->showInsetDialog("url", data, 0);
1182 FuncRequest fr(LFUN_INSET_INSERT, data);
1188 case LFUN_LABEL_INSERT: {
1189 InsetCommandParams p("label");
1190 // Try to generate a valid label
1191 p["name"] = (cmd.argument().empty()) ?
1192 cur.getPossibleLabel() :
1194 string const data = InsetCommandMailer::params2string("label", p);
1196 if (cmd.argument().empty()) {
1197 bv->showInsetDialog("label", data, 0);
1199 FuncRequest fr(LFUN_INSET_INSERT, data);
1207 case LFUN_LIST_INSERT:
1208 case LFUN_THEOREM_INSERT:
1210 case LFUN_CAPTION_INSERT:
1211 // Open the inset, and move the current selection
1213 doInsertInset(cur, this, cmd, true, true);
1215 updateLabels(bv->buffer());
1217 case LFUN_NOTE_INSERT:
1218 case LFUN_CHARSTYLE_INSERT:
1219 case LFUN_BOX_INSERT:
1220 case LFUN_BRANCH_INSERT:
1221 case LFUN_BIBITEM_INSERT:
1222 case LFUN_ERT_INSERT:
1223 case LFUN_LISTING_INSERT:
1224 case LFUN_FOOTNOTE_INSERT:
1225 case LFUN_MARGINALNOTE_INSERT:
1226 case LFUN_OPTIONAL_INSERT:
1227 case LFUN_ENVIRONMENT_INSERT:
1228 // Open the inset, and move the current selection
1230 doInsertInset(cur, this, cmd, true, true);
1234 case LFUN_TABULAR_INSERT:
1235 // if there were no arguments, just open the dialog
1236 if (doInsertInset(cur, this, cmd, false, true))
1239 bv->showDialog("tabularcreate");
1243 case LFUN_FLOAT_INSERT:
1244 case LFUN_FLOAT_WIDE_INSERT:
1245 case LFUN_WRAP_INSERT: {
1246 bool content = cur.selection(); // will some text be moved into the inset?
1248 doInsertInset(cur, this, cmd, true, true);
1250 ParagraphList & pars = cur.text()->paragraphs();
1252 TextClass const & tclass = bv->buffer().params().getTextClass();
1254 // add a separate paragraph for the caption inset
1255 pars.push_back(Paragraph());
1256 pars.back().setInsetOwner(pars[0].inInset());
1257 pars.back().layout(tclass.defaultLayout());
1259 int cap_pit = pars.size() - 1;
1261 // if an empty inset was created, we create an additional empty
1262 // paragraph at the bottom so that the user can choose where to put
1263 // the graphics (or table).
1265 pars.push_back(Paragraph());
1266 pars.back().setInsetOwner(pars[0].inInset());
1267 pars.back().layout(tclass.defaultLayout());
1271 // reposition the cursor to the caption
1272 cur.pit() = cap_pit;
1274 cur.dispatch(FuncRequest(LFUN_CAPTION_INSERT));
1275 // FIXME: When leaving the Float (or Wrap) inset we should
1276 // delete any empty paragraph left above or below the
1281 case LFUN_INDEX_INSERT:
1282 case LFUN_NOMENCL_INSERT: {
1283 Inset * inset = createInset(&cur.bv(), cmd);
1287 cur.clearSelection();
1288 insertInset(cur, inset);
1289 inset->edit(cur, true);
1290 // Show the dialog for the nomenclature entry, since the
1291 // description entry still needs to be filled in.
1292 if (cmd.action == LFUN_NOMENCL_INSERT)
1293 InsetCommandMailer("nomenclature",
1294 *reinterpret_cast<InsetCommand *>(inset)).showDialog(&cur.bv());
1299 case LFUN_INDEX_PRINT:
1300 case LFUN_NOMENCL_PRINT:
1301 case LFUN_TOC_INSERT:
1302 case LFUN_HFILL_INSERT:
1303 case LFUN_LINE_INSERT:
1304 case LFUN_PAGEBREAK_INSERT:
1305 case LFUN_CLEARPAGE_INSERT:
1306 case LFUN_CLEARDOUBLEPAGE_INSERT:
1308 doInsertInset(cur, this, cmd, false, false);
1312 case LFUN_DEPTH_DECREMENT:
1313 changeDepth(cur, DEC_DEPTH);
1316 case LFUN_DEPTH_INCREMENT:
1317 changeDepth(cur, INC_DEPTH);
1320 case LFUN_MATH_DISPLAY:
1321 mathDispatch(cur, cmd, true);
1324 case LFUN_MATH_IMPORT_SELECTION:
1325 case LFUN_MATH_MODE:
1326 if (cmd.argument() == "on")
1327 // don't pass "on" as argument
1328 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1330 mathDispatch(cur, cmd, false);
1333 case LFUN_MATH_MACRO:
1334 if (cmd.argument().empty())
1335 cur.errorMessage(from_utf8(N_("Missing argument")));
1337 string s = to_utf8(cmd.argument());
1338 string const s1 = token(s, ' ', 1);
1339 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1340 string const s2 = token(s, ' ', 2);
1341 string const type = s2.empty() ? "newcommand" : s2;
1342 cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, from_utf8(type)));
1343 //cur.nextInset()->edit(cur, true);
1347 // passthrough hat and underscore outside mathed:
1348 case LFUN_MATH_SUBSCRIPT:
1349 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1351 case LFUN_MATH_SUPERSCRIPT:
1352 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1355 case LFUN_MATH_INSERT:
1356 case LFUN_MATH_MATRIX:
1357 case LFUN_MATH_DELIM:
1358 case LFUN_MATH_BIGDELIM: {
1359 if (cur.selection())
1360 cur.clearSelection();
1361 // FIXME: instead of the above, this one
1362 // should be used (but it asserts with Bidi enabled)
1363 // cf. http://bugzilla.lyx.org/show_bug.cgi?id=4055
1364 // cap::replaceSelection(cur);
1365 cur.insert(new InsetMathHull(hullSimple));
1366 checkAndActivateInset(cur, true);
1367 BOOST_ASSERT(cur.inMathed());
1372 case LFUN_FONT_EMPH: {
1373 Font font(Font::ALL_IGNORE);
1374 font.setEmph(Font::TOGGLE);
1375 toggleAndShow(cur, this, font);
1379 case LFUN_FONT_BOLD: {
1380 Font font(Font::ALL_IGNORE);
1381 font.setSeries(Font::BOLD_SERIES);
1382 toggleAndShow(cur, this, font);
1386 case LFUN_FONT_NOUN: {
1387 Font font(Font::ALL_IGNORE);
1388 font.setNoun(Font::TOGGLE);
1389 toggleAndShow(cur, this, font);
1393 case LFUN_FONT_CODE: {
1394 Font font(Font::ALL_IGNORE);
1395 font.setFamily(Font::TYPEWRITER_FAMILY); // no good
1396 toggleAndShow(cur, this, font);
1400 case LFUN_FONT_SANS: {
1401 Font font(Font::ALL_IGNORE);
1402 font.setFamily(Font::SANS_FAMILY);
1403 toggleAndShow(cur, this, font);
1407 case LFUN_FONT_ROMAN: {
1408 Font font(Font::ALL_IGNORE);
1409 font.setFamily(Font::ROMAN_FAMILY);
1410 toggleAndShow(cur, this, font);
1414 case LFUN_FONT_DEFAULT: {
1415 Font font(Font::ALL_INHERIT, ignore_language);
1416 toggleAndShow(cur, this, font);
1420 case LFUN_FONT_UNDERLINE: {
1421 Font font(Font::ALL_IGNORE);
1422 font.setUnderbar(Font::TOGGLE);
1423 toggleAndShow(cur, this, font);
1427 case LFUN_FONT_SIZE: {
1428 Font font(Font::ALL_IGNORE);
1429 font.setLyXSize(to_utf8(cmd.argument()));
1430 toggleAndShow(cur, this, font);
1434 case LFUN_LANGUAGE: {
1435 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1438 Font font(Font::ALL_IGNORE);
1439 font.setLanguage(lang);
1440 toggleAndShow(cur, this, font);
1444 case LFUN_FONT_FREE_APPLY:
1445 toggleAndShow(cur, this, freefont, toggleall);
1446 cur.message(_("Character set"));
1449 // Set the freefont using the contents of \param data dispatched from
1450 // the frontends and apply it at the current cursor location.
1451 case LFUN_FONT_FREE_UPDATE: {
1454 if (bv_funcs::string2font(to_utf8(cmd.argument()), font, toggle)) {
1457 toggleAndShow(cur, this, freefont, toggleall);
1458 cur.message(_("Character set"));
1463 case LFUN_FINISHED_LEFT:
1464 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1465 if (reverseDirectionNeeded(cur))
1469 case LFUN_FINISHED_RIGHT:
1470 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1471 if (!reverseDirectionNeeded(cur))
1475 case LFUN_LAYOUT_PARAGRAPH: {
1477 params2string(cur.paragraph(), data);
1478 data = "show\n" + data;
1479 bv->showDialogWithData("paragraph", data);
1483 case LFUN_PARAGRAPH_UPDATE: {
1485 params2string(cur.paragraph(), data);
1487 // Will the paragraph accept changes from the dialog?
1488 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1490 data = "update " + convert<string>(accept) + '\n' + data;
1491 bv->updateDialog("paragraph", data);
1495 case LFUN_ACCENT_UMLAUT:
1496 case LFUN_ACCENT_CIRCUMFLEX:
1497 case LFUN_ACCENT_GRAVE:
1498 case LFUN_ACCENT_ACUTE:
1499 case LFUN_ACCENT_TILDE:
1500 case LFUN_ACCENT_CEDILLA:
1501 case LFUN_ACCENT_MACRON:
1502 case LFUN_ACCENT_DOT:
1503 case LFUN_ACCENT_UNDERDOT:
1504 case LFUN_ACCENT_UNDERBAR:
1505 case LFUN_ACCENT_CARON:
1506 case LFUN_ACCENT_SPECIAL_CARON:
1507 case LFUN_ACCENT_BREVE:
1508 case LFUN_ACCENT_TIE:
1509 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1510 case LFUN_ACCENT_CIRCLE:
1511 case LFUN_ACCENT_OGONEK:
1512 theLyXFunc().handleKeyFunc(cmd.action);
1513 if (!cmd.argument().empty())
1514 // FIXME: Are all these characters encoded in one byte in utf8?
1515 bv->translateAndInsert(cmd.argument()[0], this, cur);
1518 case LFUN_FLOAT_LIST: {
1519 TextClass const & tclass = bv->buffer().params().getTextClass();
1520 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1522 if (cur.selection())
1523 cutSelection(cur, true, false);
1524 breakParagraph(cur);
1526 if (cur.lastpos() != 0) {
1528 breakParagraph(cur);
1531 setLayout(cur, tclass.defaultLayoutName());
1532 ParagraphParameters p;
1533 setParagraphs(cur, p);
1534 insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1537 lyxerr << "Non-existent float type: "
1538 << to_utf8(cmd.argument()) << endl;
1543 case LFUN_CHANGE_ACCEPT: {
1544 acceptOrRejectChanges(cur, ACCEPT);
1548 case LFUN_CHANGE_REJECT: {
1549 acceptOrRejectChanges(cur, REJECT);
1553 case LFUN_THESAURUS_ENTRY: {
1554 docstring arg = cmd.argument();
1556 arg = cur.selectionAsString(false);
1558 if (arg.size() > 100 || arg.empty()) {
1559 // Get word or selection
1560 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1561 arg = cur.selectionAsString(false);
1564 bv->showDialogWithData("thesaurus", to_utf8(arg));
1568 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1569 // Given data, an encoding of the ParagraphParameters
1570 // generated in the Paragraph dialog, this function sets
1571 // the current paragraph, or currently selected paragraphs,
1573 // NOTE: This function overrides all existing settings.
1574 setParagraphs(cur, cmd.argument());
1575 cur.message(_("Paragraph layout set"));
1579 case LFUN_PARAGRAPH_PARAMS: {
1580 // Given data, an encoding of the ParagraphParameters as we'd
1581 // find them in a LyX file, this function modifies the current paragraph,
1582 // or currently selected paragraphs.
1583 // NOTE: This function only modifies, and does not override, existing
1585 setParagraphs(cur, cmd.argument(), true);
1586 cur.message(_("Paragraph layout set"));
1591 if (cur.selection()) {
1592 cur.selection() = false;
1595 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1600 LYXERR(Debug::ACTION)
1601 << BOOST_CURRENT_FUNCTION
1602 << ": Command " << cmd
1603 << " not DISPATCHED by Text" << endl;
1608 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1610 // FIXME: The cursor flag is reset two lines below
1611 // so we need to check here if some of the LFUN did touch that.
1612 // for now only Text::erase() and Text::backspace() do that.
1613 // The plan is to verify all the LFUNs and then to remove this
1614 // singleParUpdate boolean altogether.
1615 if (cur.result().update() & Update::Force) {
1616 singleParUpdate = false;
1620 // FIXME: the following code should go in favor of fine grained
1621 // update flag treatment.
1622 if (singleParUpdate) {
1623 // Inserting characters does not change par height
1624 ParagraphMetrics const & pms
1625 = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
1626 if (pms.dim().height()
1627 == olddim.height()) {
1628 // if so, update _only_ this paragraph
1629 cur.updateFlags(Update::SinglePar |
1631 Update::MultiParSel);
1638 && &oldTopSlice.inset() == &cur.inset()
1639 && oldTopSlice.idx() == cur.idx()
1640 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1641 && !cur.selection())
1642 // FIXME: it would be better if we could just do this
1644 //if (cur.result().update() != Update::FitCursor)
1647 // But some LFUNs do not set Update::FitCursor when needed, so we
1648 // do it for all. This is not very harmfull as FitCursor will provoke
1649 // a full redraw only if needed but still, a proper review of all LFUN
1650 // should be done and this needsUpdate boolean can then be removed.
1651 cur.updateFlags(Update::FitCursor);
1653 cur.updateFlags(Update::Force | Update::FitCursor);
1657 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
1658 FuncStatus & flag) const
1660 BOOST_ASSERT(cur.text() == this);
1662 Font const & font = real_current_font;
1664 Inset::Code code = Inset::NO_CODE;
1666 switch (cmd.action) {
1668 case LFUN_DEPTH_DECREMENT:
1669 enable = changeDepthAllowed(cur, DEC_DEPTH);
1672 case LFUN_DEPTH_INCREMENT:
1673 enable = changeDepthAllowed(cur, INC_DEPTH);
1677 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1680 case LFUN_BIBITEM_INSERT:
1681 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO
1685 case LFUN_DIALOG_SHOW_NEW_INSET:
1686 if (cmd.argument() == "bibitem")
1687 code = Inset::BIBITEM_CODE;
1688 else if (cmd.argument() == "bibtex")
1689 code = Inset::BIBTEX_CODE;
1690 else if (cmd.argument() == "box")
1691 code = Inset::BOX_CODE;
1692 else if (cmd.argument() == "branch")
1693 code = Inset::BRANCH_CODE;
1694 else if (cmd.argument() == "citation")
1695 code = Inset::CITE_CODE;
1696 else if (cmd.argument() == "ert")
1697 code = Inset::ERT_CODE;
1698 else if (cmd.argument() == "external")
1699 code = Inset::EXTERNAL_CODE;
1700 else if (cmd.argument() == "float")
1701 code = Inset::FLOAT_CODE;
1702 else if (cmd.argument() == "graphics")
1703 code = Inset::GRAPHICS_CODE;
1704 else if (cmd.argument() == "include")
1705 code = Inset::INCLUDE_CODE;
1706 else if (cmd.argument() == "index")
1707 code = Inset::INDEX_CODE;
1708 else if (cmd.argument() == "nomenclature")
1709 code = Inset::NOMENCL_CODE;
1710 else if (cmd.argument() == "label")
1711 code = Inset::LABEL_CODE;
1712 else if (cmd.argument() == "note")
1713 code = Inset::NOTE_CODE;
1714 else if (cmd.argument() == "ref")
1715 code = Inset::REF_CODE;
1716 else if (cmd.argument() == "toc")
1717 code = Inset::TOC_CODE;
1718 else if (cmd.argument() == "url")
1719 code = Inset::URL_CODE;
1720 else if (cmd.argument() == "vspace")
1721 code = Inset::VSPACE_CODE;
1722 else if (cmd.argument() == "wrap")
1723 code = Inset::WRAP_CODE;
1724 else if (cmd.argument() == "listings")
1725 code = Inset::LISTINGS_CODE;
1728 case LFUN_ERT_INSERT:
1729 code = Inset::ERT_CODE;
1731 case LFUN_LISTING_INSERT:
1732 code = Inset::LISTINGS_CODE;
1734 case LFUN_FOOTNOTE_INSERT:
1735 code = Inset::FOOT_CODE;
1737 case LFUN_TABULAR_INSERT:
1738 code = Inset::TABULAR_CODE;
1740 case LFUN_MARGINALNOTE_INSERT:
1741 code = Inset::MARGIN_CODE;
1743 case LFUN_FLOAT_INSERT:
1744 case LFUN_FLOAT_WIDE_INSERT:
1745 code = Inset::FLOAT_CODE;
1747 case LFUN_WRAP_INSERT:
1748 code = Inset::WRAP_CODE;
1750 case LFUN_FLOAT_LIST:
1751 code = Inset::FLOAT_LIST_CODE;
1754 case LFUN_LIST_INSERT:
1755 code = Inset::LIST_CODE;
1757 case LFUN_THEOREM_INSERT:
1758 code = Inset::THEOREM_CODE;
1761 case LFUN_CAPTION_INSERT:
1762 code = Inset::CAPTION_CODE;
1764 case LFUN_NOTE_INSERT:
1765 code = Inset::NOTE_CODE;
1767 case LFUN_CHARSTYLE_INSERT:
1768 code = Inset::CHARSTYLE_CODE;
1769 if (cur.buffer().params().getTextClass().charstyles().empty())
1772 case LFUN_BOX_INSERT:
1773 code = Inset::BOX_CODE;
1775 case LFUN_BRANCH_INSERT:
1776 code = Inset::BRANCH_CODE;
1777 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1780 case LFUN_LABEL_INSERT:
1781 code = Inset::LABEL_CODE;
1783 case LFUN_OPTIONAL_INSERT:
1784 code = Inset::OPTARG_CODE;
1785 enable = numberOfOptArgs(cur.paragraph())
1786 < cur.paragraph().layout()->optionalargs;
1788 case LFUN_ENVIRONMENT_INSERT:
1789 code = Inset::BOX_CODE;
1791 case LFUN_INDEX_INSERT:
1792 code = Inset::INDEX_CODE;
1794 case LFUN_INDEX_PRINT:
1795 code = Inset::INDEX_PRINT_CODE;
1797 case LFUN_NOMENCL_INSERT:
1798 code = Inset::NOMENCL_CODE;
1800 case LFUN_NOMENCL_PRINT:
1801 code = Inset::NOMENCL_PRINT_CODE;
1803 case LFUN_TOC_INSERT:
1804 code = Inset::TOC_CODE;
1806 case LFUN_HTML_INSERT:
1807 case LFUN_URL_INSERT:
1808 code = Inset::URL_CODE;
1810 case LFUN_QUOTE_INSERT:
1811 // always allow this, since we will inset a raw quote
1812 // if an inset is not allowed.
1814 case LFUN_HYPHENATION_POINT_INSERT:
1815 case LFUN_LIGATURE_BREAK_INSERT:
1816 case LFUN_HFILL_INSERT:
1817 case LFUN_MENU_SEPARATOR_INSERT:
1818 case LFUN_DOTS_INSERT:
1819 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
1820 code = Inset::SPECIALCHAR_CODE;
1822 case LFUN_SPACE_INSERT:
1823 // slight hack: we know this is allowed in math mode
1825 code = Inset::SPACE_CODE;
1828 case LFUN_INSET_MODIFY:
1829 // We need to disable this, because we may get called for a
1831 // InsetTabular::getStatus() -> InsetText::getStatus()
1832 // and we don't handle LFUN_INSET_MODIFY.
1836 case LFUN_FONT_EMPH:
1837 flag.setOnOff(font.emph() == Font::ON);
1840 case LFUN_FONT_NOUN:
1841 flag.setOnOff(font.noun() == Font::ON);
1844 case LFUN_FONT_BOLD:
1845 flag.setOnOff(font.series() == Font::BOLD_SERIES);
1848 case LFUN_FONT_SANS:
1849 flag.setOnOff(font.family() == Font::SANS_FAMILY);
1852 case LFUN_FONT_ROMAN:
1853 flag.setOnOff(font.family() == Font::ROMAN_FAMILY);
1856 case LFUN_FONT_CODE:
1857 flag.setOnOff(font.family() == Font::TYPEWRITER_FAMILY);
1862 enable = cur.selection();
1866 if (cmd.argument().empty()) {
1867 if (theClipboard().isInternal())
1868 enable = cap::numberOfSelections() > 0;
1870 enable = !theClipboard().empty();
1872 string const arg = to_utf8(cmd.argument());
1873 if (isStrUnsignedInt(arg)) {
1874 unsigned int n = convert<unsigned int>(arg);
1875 enable = cap::numberOfSelections() > n;
1882 case LFUN_CLIPBOARD_PASTE:
1883 enable = !theClipboard().empty();
1886 case LFUN_PRIMARY_SELECTION_PASTE:
1887 enable = cur.selection() || !theSelection().empty();
1890 case LFUN_PARAGRAPH_MOVE_UP:
1891 enable = cur.pit() > 0 && !cur.selection();
1894 case LFUN_PARAGRAPH_MOVE_DOWN:
1895 enable = cur.pit() < cur.lastpit() && !cur.selection();
1898 case LFUN_INSET_DISSOLVE:
1899 enable = !isMainText(cur.bv().buffer()) && cur.inset().nargs() == 1;
1902 case LFUN_CHANGE_ACCEPT:
1903 case LFUN_CHANGE_REJECT:
1904 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
1905 // In principle, these LFUNs should only be enabled if there
1906 // is a change at the current position/in the current selection.
1907 // However, without proper optimizations, this will inevitably
1908 // result in unacceptable performance - just imagine a user who
1909 // wants to select the complete content of a long document.
1913 case LFUN_WORD_DELETE_FORWARD:
1914 case LFUN_WORD_DELETE_BACKWARD:
1915 case LFUN_LINE_DELETE:
1916 case LFUN_WORD_FORWARD:
1917 case LFUN_WORD_BACKWARD:
1918 case LFUN_CHAR_FORWARD:
1919 case LFUN_CHAR_FORWARD_SELECT:
1920 case LFUN_CHAR_BACKWARD:
1921 case LFUN_CHAR_BACKWARD_SELECT:
1923 case LFUN_UP_SELECT:
1925 case LFUN_DOWN_SELECT:
1926 case LFUN_PARAGRAPH_UP_SELECT:
1927 case LFUN_PARAGRAPH_DOWN_SELECT:
1928 case LFUN_SCREEN_UP_SELECT:
1929 case LFUN_SCREEN_DOWN_SELECT:
1930 case LFUN_LINE_BEGIN_SELECT:
1931 case LFUN_LINE_END_SELECT:
1932 case LFUN_WORD_FORWARD_SELECT:
1933 case LFUN_WORD_BACKWARD_SELECT:
1934 case LFUN_WORD_SELECT:
1935 case LFUN_PARAGRAPH_UP:
1936 case LFUN_PARAGRAPH_DOWN:
1937 case LFUN_SCREEN_UP:
1938 case LFUN_SCREEN_DOWN:
1939 case LFUN_LINE_BEGIN:
1941 case LFUN_BREAK_LINE:
1942 case LFUN_CHAR_DELETE_FORWARD:
1943 case LFUN_DELETE_FORWARD_SKIP:
1944 case LFUN_CHAR_DELETE_BACKWARD:
1945 case LFUN_DELETE_BACKWARD_SKIP:
1946 case LFUN_BREAK_PARAGRAPH:
1947 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
1948 case LFUN_BREAK_PARAGRAPH_SKIP:
1949 case LFUN_PARAGRAPH_SPACING:
1950 case LFUN_INSET_INSERT:
1951 case LFUN_WORD_UPCASE:
1952 case LFUN_WORD_LOWCASE:
1953 case LFUN_WORD_CAPITALIZE:
1954 case LFUN_CHARS_TRANSPOSE:
1955 case LFUN_SERVER_GET_XY:
1956 case LFUN_SERVER_SET_XY:
1957 case LFUN_SERVER_GET_FONT:
1958 case LFUN_SERVER_GET_LAYOUT:
1960 case LFUN_DATE_INSERT:
1961 case LFUN_SELF_INSERT:
1962 case LFUN_LINE_INSERT:
1963 case LFUN_PAGEBREAK_INSERT:
1964 case LFUN_CLEARPAGE_INSERT:
1965 case LFUN_CLEARDOUBLEPAGE_INSERT:
1966 case LFUN_MATH_DISPLAY:
1967 case LFUN_MATH_IMPORT_SELECTION:
1968 case LFUN_MATH_MODE:
1969 case LFUN_MATH_MACRO:
1970 case LFUN_MATH_MATRIX:
1971 case LFUN_MATH_DELIM:
1972 case LFUN_MATH_BIGDELIM:
1973 case LFUN_MATH_INSERT:
1974 case LFUN_MATH_SUBSCRIPT:
1975 case LFUN_MATH_SUPERSCRIPT:
1976 case LFUN_FONT_DEFAULT:
1977 case LFUN_FONT_UNDERLINE:
1978 case LFUN_FONT_SIZE:
1980 case LFUN_FONT_FREE_APPLY:
1981 case LFUN_FONT_FREE_UPDATE:
1982 case LFUN_LAYOUT_PARAGRAPH:
1983 case LFUN_PARAGRAPH_UPDATE:
1984 case LFUN_ACCENT_UMLAUT:
1985 case LFUN_ACCENT_CIRCUMFLEX:
1986 case LFUN_ACCENT_GRAVE:
1987 case LFUN_ACCENT_ACUTE:
1988 case LFUN_ACCENT_TILDE:
1989 case LFUN_ACCENT_CEDILLA:
1990 case LFUN_ACCENT_MACRON:
1991 case LFUN_ACCENT_DOT:
1992 case LFUN_ACCENT_UNDERDOT:
1993 case LFUN_ACCENT_UNDERBAR:
1994 case LFUN_ACCENT_CARON:
1995 case LFUN_ACCENT_SPECIAL_CARON:
1996 case LFUN_ACCENT_BREVE:
1997 case LFUN_ACCENT_TIE:
1998 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1999 case LFUN_ACCENT_CIRCLE:
2000 case LFUN_ACCENT_OGONEK:
2001 case LFUN_THESAURUS_ENTRY:
2002 case LFUN_PARAGRAPH_PARAMS_APPLY:
2003 case LFUN_PARAGRAPH_PARAMS:
2005 case LFUN_BUFFER_END:
2006 case LFUN_BUFFER_BEGIN:
2007 case LFUN_BUFFER_BEGIN_SELECT:
2008 case LFUN_BUFFER_END_SELECT:
2009 case LFUN_UNICODE_INSERT:
2010 // these are handled in our dispatch()
2018 if (code != Inset::NO_CODE
2019 && (cur.empty() || !cur.inset().insetAllowed(code)))
2022 flag.enabled(enable);
2027 void Text::pasteString(Cursor & cur, docstring const & clip,
2030 cur.clearSelection();
2031 if (!clip.empty()) {
2034 insertStringAsParagraphs(cur, clip);
2036 insertStringAsLines(cur, clip);