3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Asger Alstrup
7 * \author Lars Gullik Bjønnes
8 * \author Alfredo Braunstein
9 * \author Angus Leeming
11 * \author André Pönitz
13 * Full author contact details are available in file CREDITS.
20 #include "BranchList.h"
21 #include "FloatList.h"
22 #include "FuncStatus.h"
24 #include "buffer_funcs.h"
25 #include "BufferParams.h"
26 #include "BufferView.h"
27 #include "bufferview_funcs.h"
29 #include "CoordCache.h"
30 #include "CutAndPaste.h"
32 #include "DispatchResult.h"
33 #include "ErrorList.h"
35 #include "FuncRequest.h"
39 #include "LyXAction.h"
44 #include "Paragraph.h"
45 #include "paragraph_funcs.h"
46 #include "ParagraphParameters.h"
49 #include "ParIterator.h"
51 #include "frontends/Clipboard.h"
52 #include "frontends/Selection.h"
54 #include "insets/InsetCommand.h"
55 #include "insets/InsetFloatList.h"
56 #include "insets/InsetNewline.h"
57 #include "insets/InsetQuotes.h"
58 #include "insets/InsetSpecialChar.h"
59 #include "insets/InsetText.h"
61 #include "support/lstrings.h"
62 #include "support/lyxlib.h"
63 #include "support/convert.h"
64 #include "support/lyxtime.h"
66 #include "mathed/InsetMathHull.h"
67 #include "mathed/MathMacroTemplate.h"
69 #include <boost/current_function.hpp>
77 using cap::copySelection;
78 using cap::cutSelection;
79 using cap::pasteFromStack;
80 using cap::pasteClipboard;
81 using cap::replaceSelection;
82 using cap::saveSelection;
84 using support::isStrUnsignedInt;
89 using std::istringstream;
90 using std::ostringstream;
93 extern string current_layout;
99 Font freefont(Font::ALL_IGNORE);
100 bool toggleall = false;
102 void toggleAndShow(Cursor & cur, Text * text,
103 Font const & font, bool toggleall = true)
105 text->toggleFree(cur, font, toggleall);
107 if (font.language() != ignore_language ||
108 font.number() != Font::IGNORE) {
109 Paragraph & par = cur.paragraph();
110 if (cur.boundary() != text->isRTLBoundary(cur.buffer(), par,
111 cur.pos(), text->real_current_font))
112 text->setCursor(cur, cur.pit(), cur.pos(),
113 false, !cur.boundary());
118 void moveCursor(Cursor & cur, bool selecting)
120 if (selecting || cur.mark())
123 cur.bv().switchKeyMap();
127 void finishChange(Cursor & cur, bool selecting)
130 moveCursor(cur, selecting);
134 void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
137 docstring sel = cur.selectionAsString(false);
139 // It may happen that sel is empty but there is a selection
140 replaceSelection(cur);
143 #ifdef ENABLE_ASSERTIONS
144 const int old_pos = cur.pos();
146 cur.insert(new InsetMathHull(hullSimple));
147 BOOST_ASSERT(old_pos == cur.pos());
148 cur.nextInset()->edit(cur, true);
149 // don't do that also for LFUN_MATH_MODE
150 // unless you want end up with always changing
151 // to mathrm when opening an inlined inset --
152 // I really hate "LyXfunc overloading"...
154 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
155 // Avoid an unnecessary undo step if cmd.argument
157 if (!cmd.argument().empty())
158 cur.dispatch(FuncRequest(LFUN_MATH_INSERT,
161 // create a macro if we see "\\newcommand"
162 // somewhere, and an ordinary formula
164 if (sel.find(from_ascii("\\newcommand")) == string::npos
165 && sel.find(from_ascii("\\def")) == string::npos)
167 InsetMathHull * formula = new InsetMathHull;
168 istringstream is(to_utf8(sel));
171 formula->read(cur.buffer(), lex);
172 if (formula->getType() == hullNone)
173 // Don't create pseudo formulas if
174 // delimiters are left out
175 formula->mutate(hullSimple);
178 cur.insert(new MathMacroTemplate(sel));
181 cur.message(from_utf8(N_("Math editor mode")));
190 string const freefont2string()
193 if (font2string(freefont, toggleall, data))
200 void Text::cursorPrevious(Cursor & cur)
202 pos_type cpos = cur.pos();
203 pit_type cpar = cur.pit();
205 int x = cur.x_target();
206 setCursorFromCoordinates(cur, x, 0);
207 cur.dispatch(FuncRequest(cur.selection()? LFUN_UP_SELECT: LFUN_UP));
209 if (cpar == cur.pit() && cpos == cur.pos())
210 // we have a row which is taller than the workarea. The
211 // simplest solution is to move to the previous row instead.
212 cur.dispatch(FuncRequest(cur.selection()? LFUN_UP_SELECT: LFUN_UP));
215 cur.updateFlags(Update::Force | Update::FitCursor);
219 void Text::cursorNext(Cursor & cur)
221 pos_type cpos = cur.pos();
222 pit_type cpar = cur.pit();
224 int x = cur.x_target();
225 setCursorFromCoordinates(cur, x, cur.bv().workHeight() - 1);
226 cur.dispatch(FuncRequest(cur.selection()? LFUN_DOWN_SELECT: LFUN_DOWN));
228 if (cpar == cur.pit() && cpos == cur.pos())
229 // we have a row which is taller than the workarea. The
230 // simplest solution is to move to the next row instead.
232 FuncRequest(cur.selection()? LFUN_DOWN_SELECT: LFUN_DOWN));
235 cur.updateFlags(Update::Force | Update::FitCursor);
241 void specialChar(Cursor & cur, InsetSpecialChar::Kind kind)
244 cap::replaceSelection(cur);
245 cur.insert(new InsetSpecialChar(kind));
250 bool doInsertInset(Cursor & cur, Text * text,
251 FuncRequest const & cmd, bool edit, bool pastesel)
253 Inset * inset = createInset(&cur.bv(), cmd);
259 if (cur.selection()) {
260 lyx::dispatch(FuncRequest(LFUN_CUT));
263 text->insertInset(cur, inset);
266 inset->edit(cur, true);
268 if (gotsel && pastesel) {
269 lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
270 // reset first par to default
271 if (cur.lastpit() != 0 || cur.lastpos() != 0) {
272 Layout_ptr const layout =
273 cur.buffer().params().getTextClass().defaultLayout();
274 cur.text()->paragraphs().begin()->layout(layout);
284 void Text::number(Cursor & cur)
286 Font font(Font::ALL_IGNORE);
287 font.setNumber(Font::TOGGLE);
288 toggleAndShow(cur, this, font);
292 bool Text::isRTL(Buffer const & buffer, Paragraph const & par) const
294 return par.isRightToLeftPar(buffer.params());
298 bool Text::isRTL(Buffer const & buffer, CursorSlice const & sl, bool boundary) const
300 if (!lyxrc.rtl_support && !sl.text())
304 if (boundary && sl.pos() > 0)
307 Paragraph const & par = getPar(sl.pit());
308 return getFont(buffer, par, sl.pos() + correction).isVisibleRightToLeft();
312 bool Text::isRTLBoundary(Buffer const & buffer, Paragraph const & par,
315 if (!lyxrc.rtl_support)
318 // no RTL boundary at line start
322 bool left = getFont(buffer, par, pos - 1).isVisibleRightToLeft();
324 if (pos == par.size())
325 right = par.isRightToLeftPar(buffer.params());
327 right = getFont(buffer, par, pos).isVisibleRightToLeft();
328 return left != right;
332 bool Text::isRTLBoundary(Buffer const & buffer, Paragraph const & par,
333 pos_type pos, Font const & font) const
335 if (!lyxrc.rtl_support)
338 bool left = font.isVisibleRightToLeft();
340 if (pos == par.size())
341 right = par.isRightToLeftPar(buffer.params());
343 right = getFont(buffer, par, pos).isVisibleRightToLeft();
344 return left != right;
348 void Text::dispatch(Cursor & cur, FuncRequest & cmd)
350 LYXERR(Debug::ACTION) << "Text::dispatch: cmd: " << cmd << endl;
352 // FIXME: We use the update flag to indicates wether a singlePar or a
353 // full screen update is needed. We reset it here but shall we restore it
357 BOOST_ASSERT(cur.text() == this);
358 BufferView * bv = &cur.bv();
359 CursorSlice oldTopSlice = cur.top();
360 bool oldBoundary = cur.boundary();
361 bool sel = cur.selection();
362 // Signals that, even if needsUpdate == false, an update of the
363 // cursor paragraph is required
364 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
365 LyXAction::SingleParUpdate);
366 // Signals that a full-screen update is required
367 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
368 LyXAction::NoUpdate) || singleParUpdate);
369 // Remember the old paragraph metric (_outer_ paragraph!)
370 ParagraphMetrics const & pm = cur.bv().parMetrics(
371 cur.bottom().text(), cur.bottom().pit());
372 Dimension olddim = pm.dim();
374 switch (cmd.action) {
376 case LFUN_PARAGRAPH_MOVE_DOWN: {
377 pit_type const pit = cur.pit();
378 recUndo(cur, pit, pit + 1);
380 std::swap(pars_[pit], pars_[pit + 1]);
382 ParIterator begin(cur);
383 // begin.pos() (== cur.pos()) may point beyond the end of the
384 // paragraph referenced by begin. This would cause a crash
388 ParIterator end = boost::next(ParIterator(cur));
389 updateLabels(cur.buffer(), begin, end);
395 case LFUN_PARAGRAPH_MOVE_UP: {
396 pit_type const pit = cur.pit();
397 recUndo(cur, pit - 1, pit);
399 std::swap(pars_[pit], pars_[pit - 1]);
401 ParIterator end = ParIterator(cur);
402 // end.pos() (== cur.pos()) may point beyond the end of the
403 // paragraph referenced by end. This would cause a crash
406 end = boost::next(end);
408 ParIterator begin(cur);
409 updateLabels(cur.buffer(), begin, end);
415 case LFUN_APPENDIX: {
416 Paragraph & par = cur.paragraph();
417 bool start = !par.params().startOfAppendix();
420 #warning The code below only makes sense at top level.
421 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
423 // ensure that we have only one start_of_appendix in this document
424 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
425 if (pars_[tmp].params().startOfAppendix()) {
427 pars_[tmp].params().startOfAppendix(false);
433 par.params().startOfAppendix(start);
435 // we can set the refreshing parameters now
436 updateLabels(cur.buffer());
440 case LFUN_WORD_DELETE_FORWARD:
441 cur.clearSelection();
442 deleteWordForward(cur);
443 finishChange(cur, false);
446 case LFUN_WORD_DELETE_BACKWARD:
447 cur.clearSelection();
448 deleteWordBackward(cur);
449 finishChange(cur, false);
452 case LFUN_LINE_DELETE:
453 cur.clearSelection();
454 deleteLineForward(cur);
455 finishChange(cur, false);
458 case LFUN_BUFFER_BEGIN:
459 case LFUN_BUFFER_BEGIN_SELECT:
460 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
461 if (cur.depth() == 1) {
462 needsUpdate |= cursorTop(cur);
468 case LFUN_BUFFER_END:
469 case LFUN_BUFFER_END_SELECT:
470 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
471 if (cur.depth() == 1) {
472 needsUpdate |= cursorBottom(cur);
478 case LFUN_CHAR_FORWARD:
479 case LFUN_CHAR_FORWARD_SELECT:
480 //lyxerr << BOOST_CURRENT_FUNCTION
481 // << " LFUN_CHAR_FORWARD[SEL]:\n" << cur << endl;
482 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
483 if (reverseDirectionNeeded(cur))
484 needsUpdate |= cursorLeft(cur);
486 needsUpdate |= cursorRight(cur);
488 if (!needsUpdate && oldTopSlice == cur.top()
489 && cur.boundary() == oldBoundary) {
491 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
497 case LFUN_CHAR_BACKWARD:
498 case LFUN_CHAR_BACKWARD_SELECT:
499 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
500 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
501 if (reverseDirectionNeeded(cur))
502 needsUpdate |= cursorRight(cur);
504 needsUpdate |= cursorLeft(cur);
506 if (!needsUpdate && oldTopSlice == cur.top()
507 && cur.boundary() == oldBoundary) {
509 cmd = FuncRequest(LFUN_FINISHED_LEFT);
516 case LFUN_UP_SELECT: {
517 //lyxerr << "handle LFUN_UP[SEL]:\n" << cur << endl;
518 needsUpdate |= cur.selHandle(cmd.action == LFUN_UP_SELECT);
519 bool const successful = cur.upDownInText(true, needsUpdate);
528 case LFUN_DOWN_SELECT: {
529 //lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
530 needsUpdate |= cur.selHandle(cmd.action == LFUN_DOWN_SELECT);
531 bool const successful = cur.upDownInText(false, needsUpdate);
539 case LFUN_PARAGRAPH_UP:
540 case LFUN_PARAGRAPH_UP_SELECT:
541 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
542 needsUpdate |= cursorUpParagraph(cur);
547 case LFUN_PARAGRAPH_DOWN:
548 case LFUN_PARAGRAPH_DOWN_SELECT:
549 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
550 needsUpdate |= cursorDownParagraph(cur);
556 case LFUN_SCREEN_UP_SELECT:
557 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_UP_SELECT);
558 if (cur.pit() == 0 && cur.textRow().pos() == 0)
567 case LFUN_SCREEN_DOWN:
568 case LFUN_SCREEN_DOWN_SELECT:
569 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_DOWN_SELECT);
570 if (cur.pit() == cur.lastpit()
571 && cur.textRow().endpos() == cur.lastpos())
580 case LFUN_LINE_BEGIN:
581 case LFUN_LINE_BEGIN_SELECT:
582 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
583 needsUpdate |= cursorHome(cur);
587 case LFUN_LINE_END_SELECT:
588 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
589 needsUpdate |= cursorEnd(cur);
594 case LFUN_WORD_FORWARD:
595 case LFUN_WORD_FORWARD_SELECT:
596 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
597 if (reverseDirectionNeeded(cur))
598 needsUpdate |= cursorLeftOneWord(cur);
600 needsUpdate |= cursorRightOneWord(cur);
605 case LFUN_WORD_BACKWARD:
606 case LFUN_WORD_BACKWARD_SELECT:
607 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
608 if (reverseDirectionNeeded(cur))
609 needsUpdate |= cursorRightOneWord(cur);
611 needsUpdate |= cursorLeftOneWord(cur);
616 case LFUN_WORD_SELECT: {
617 selectWord(cur, WHOLE_WORD);
618 finishChange(cur, true);
622 case LFUN_BREAK_LINE: {
623 // Not allowed by LaTeX (labels or empty par)
624 if (cur.pos() > cur.paragraph().beginOfBody()) {
625 // this avoids a double undo
626 // FIXME: should not be needed, ideally
627 if (!cur.selection())
629 cap::replaceSelection(cur);
630 cur.insert(new InsetNewline);
632 moveCursor(cur, false);
637 case LFUN_CHAR_DELETE_FORWARD:
638 if (!cur.selection()) {
639 if (cur.pos() == cur.paragraph().size())
640 // Par boundary, force full-screen update
641 singleParUpdate = false;
642 needsUpdate |= erase(cur);
644 // It is possible to make it a lot faster still
645 // just comment out the line below...
647 cutSelection(cur, true, false);
648 singleParUpdate = false;
650 moveCursor(cur, false);
653 case LFUN_DELETE_FORWARD_SKIP:
654 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
655 if (!cur.selection()) {
656 if (cur.pos() == cur.lastpos()) {
663 cutSelection(cur, true, false);
668 case LFUN_CHAR_DELETE_BACKWARD:
669 if (!cur.selection()) {
670 if (bv->getIntl().getTransManager().backspace()) {
671 // Par boundary, full-screen update
673 singleParUpdate = false;
674 needsUpdate |= backspace(cur);
676 // It is possible to make it a lot faster still
677 // just comment out the line below...
680 cutSelection(cur, true, false);
681 singleParUpdate = false;
686 case LFUN_DELETE_BACKWARD_SKIP:
687 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
688 if (!cur.selection()) {
692 //CursorSlice cur = cursor();
696 cutSelection(cur, true, false);
700 case LFUN_BREAK_PARAGRAPH:
701 cap::replaceSelection(cur);
702 breakParagraph(cur, 0);
707 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
708 cap::replaceSelection(cur);
709 breakParagraph(cur, 1);
714 case LFUN_BREAK_PARAGRAPH_SKIP: {
715 // When at the beginning of a paragraph, remove
716 // indentation. Otherwise, do the same as LFUN_BREAK_PARAGRAPH.
717 cap::replaceSelection(cur);
719 cur.paragraph().params().labelWidthString(docstring());
721 breakParagraph(cur, 0);
727 case LFUN_PARAGRAPH_SPACING: {
728 Paragraph & par = cur.paragraph();
729 Spacing::Space cur_spacing = par.params().spacing().getSpace();
730 string cur_value = "1.0";
731 if (cur_spacing == Spacing::Other)
732 cur_value = par.params().spacing().getValueAsString();
734 istringstream is(to_utf8(cmd.argument()));
737 Spacing::Space new_spacing = cur_spacing;
738 string new_value = cur_value;
740 lyxerr << "Missing argument to `paragraph-spacing'"
742 } else if (tmp == "single") {
743 new_spacing = Spacing::Single;
744 } else if (tmp == "onehalf") {
745 new_spacing = Spacing::Onehalf;
746 } else if (tmp == "double") {
747 new_spacing = Spacing::Double;
748 } else if (tmp == "other") {
749 new_spacing = Spacing::Other;
750 string tmpval = "0.0";
752 lyxerr << "new_value = " << tmpval << endl;
755 } else if (tmp == "default") {
756 new_spacing = Spacing::Default;
758 lyxerr << to_utf8(_("Unknown spacing argument: "))
759 << to_utf8(cmd.argument()) << endl;
761 if (cur_spacing != new_spacing || cur_value != new_value)
762 par.params().spacing(Spacing(new_spacing, new_value));
766 case LFUN_INSET_INSERT: {
768 Inset * inset = createInset(bv, cmd);
770 // FIXME (Abdel 01/02/2006):
771 // What follows would be a partial fix for bug 2154:
772 // http://bugzilla.lyx.org/show_bug.cgi?id=2154
773 // This automatically put the label inset _after_ a
774 // numbered section. It should be possible to extend the mechanism
775 // to any kind of LateX environement.
776 // The correct way to fix that bug would be at LateX generation.
777 // I'll let the code here for reference as it could be used for some
778 // other feature like "automatic labelling".
780 Paragraph & par = pars_[cur.pit()];
781 if (inset->lyxCode() == Inset::LABEL_CODE
782 && par.layout()->labeltype == LABEL_COUNTER) {
783 // Go to the end of the paragraph
784 // Warning: Because of Change-Tracking, the last
785 // position is 'size()' and not 'size()-1':
786 cur.pos() = par.size();
787 // Insert a new paragraph
788 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
792 insertInset(cur, inset);
798 case LFUN_INSET_DISSOLVE:
799 needsUpdate |= dissolveInset(cur);
802 case LFUN_INSET_SETTINGS:
803 cur.inset().showInsetDialog(bv);
806 case LFUN_SPACE_INSERT:
807 if (cur.paragraph().layout()->free_spacing)
808 insertChar(cur, ' ');
810 doInsertInset(cur, this, cmd, false, false);
813 moveCursor(cur, false);
816 case LFUN_HYPHENATION_POINT_INSERT:
817 specialChar(cur, InsetSpecialChar::HYPHENATION);
820 case LFUN_LIGATURE_BREAK_INSERT:
821 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
824 case LFUN_DOTS_INSERT:
825 specialChar(cur, InsetSpecialChar::LDOTS);
828 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
829 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
832 case LFUN_MENU_SEPARATOR_INSERT:
833 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
836 case LFUN_WORD_UPCASE:
837 changeCase(cur, Text::text_uppercase);
840 case LFUN_WORD_LOWCASE:
841 changeCase(cur, Text::text_lowercase);
844 case LFUN_WORD_CAPITALIZE:
845 changeCase(cur, Text::text_capitalization);
848 case LFUN_CHARS_TRANSPOSE:
853 cur.message(_("Paste"));
854 cap::replaceSelection(cur);
855 if (cmd.argument().empty() && !theClipboard().isInternal())
856 pasteClipboard(cur, bv->buffer()->errorList("Paste"));
858 string const arg(to_utf8(cmd.argument()));
859 pasteFromStack(cur, bv->buffer()->errorList("Paste"),
860 isStrUnsignedInt(arg) ?
861 convert<unsigned int>(arg) :
864 bv->buffer()->errors("Paste");
865 cur.clearSelection(); // bug 393
871 cutSelection(cur, true, true);
872 cur.message(_("Cut"));
877 cur.message(_("Copy"));
880 case LFUN_SERVER_GET_XY:
881 cur.message(from_utf8(
882 convert<string>(cursorX(cur.bv(), cur.top(), cur.boundary()))
883 + ' ' + convert<string>(cursorY(cur.bv(), cur.top(), cur.boundary()))));
886 case LFUN_SERVER_SET_XY: {
889 istringstream is(to_utf8(cmd.argument()));
892 lyxerr << "SETXY: Could not parse coordinates in '"
893 << to_utf8(cmd.argument()) << std::endl;
895 setCursorFromCoordinates(cur, x, y);
899 case LFUN_SERVER_GET_FONT:
900 if (current_font.shape() == Font::ITALIC_SHAPE)
901 cur.message(from_ascii("E"));
902 else if (current_font.shape() == Font::SMALLCAPS_SHAPE)
903 cur.message(from_ascii("N"));
905 cur.message(from_ascii("0"));
908 case LFUN_SERVER_GET_LAYOUT:
909 cur.message(from_utf8(cur.paragraph().layout()->name()));
913 string layout = to_ascii(cmd.argument());
914 LYXERR(Debug::INFO) << "LFUN_LAYOUT: (arg) " << layout << endl;
916 // Derive layout number from given argument (string)
917 // and current buffer's textclass (number)
918 TextClass const & tclass = bv->buffer()->params().getTextClass();
920 layout = tclass.defaultLayoutName();
921 bool hasLayout = tclass.hasLayout(layout);
923 // If the entry is obsolete, use the new one instead.
925 string const & obs = tclass[layout]->obsoleted_by();
931 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
932 from_utf8(N_(" not known")));
936 bool change_layout = (current_layout != layout);
938 if (!change_layout && cur.selection() &&
939 cur.selBegin().pit() != cur.selEnd().pit())
941 pit_type spit = cur.selBegin().pit();
942 pit_type epit = cur.selEnd().pit() + 1;
943 while (spit != epit) {
944 if (pars_[spit].layout()->name() != current_layout) {
945 change_layout = true;
953 current_layout = layout;
954 setLayout(cur, layout);
955 // inform the GUI that the layout has changed.
956 bv->layoutChanged(layout);
962 case LFUN_CLIPBOARD_PASTE:
963 cur.clearSelection();
964 pasteClipboard(cur, bv->buffer()->errorList("Paste"),
965 cmd.argument() == "paragraph");
966 bv->buffer()->errors("Paste");
969 case LFUN_PRIMARY_SELECTION_PASTE:
970 pasteString(cur, theSelection().get(),
971 cmd.argument() == "paragraph");
974 case LFUN_UNICODE_INSERT: {
975 if (cmd.argument().empty())
977 docstring hexstring = cmd.argument();
978 if (lyx::support::isHex(hexstring)) {
979 char_type c = lyx::support::hexToInt(hexstring);
980 if (c > 32 && c < 0x10ffff) {
981 lyxerr << "Inserting c: " << c << endl;
982 docstring s = docstring(1, c);
983 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
989 case LFUN_QUOTE_INSERT: {
990 Paragraph & par = cur.paragraph();
991 pos_type pos = cur.pos();
992 BufferParams const & bufparams = bv->buffer()->params();
993 Layout_ptr const & style = par.layout();
994 if (!style->pass_thru
995 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
996 // this avoids a double undo
997 // FIXME: should not be needed, ideally
998 if (!cur.selection())
1000 cap::replaceSelection(cur);
1005 else if (cur.prevInset() && cur.prevInset()->isSpace())
1008 c = par.getChar(pos - 1);
1009 string arg = to_utf8(cmd.argument());
1010 if (arg == "single")
1011 cur.insert(new InsetQuotes(c,
1012 bufparams.quotes_language,
1013 InsetQuotes::SingleQ));
1015 cur.insert(new InsetQuotes(c,
1016 bufparams.quotes_language,
1017 InsetQuotes::DoubleQ));
1021 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
1025 case LFUN_DATE_INSERT:
1026 if (cmd.argument().empty())
1027 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
1028 formatted_time(current_time())));
1030 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
1031 formatted_time(current_time(), to_utf8(cmd.argument()))));
1034 case LFUN_MOUSE_TRIPLE:
1035 if (cmd.button() == mouse_button::button1) {
1045 case LFUN_MOUSE_DOUBLE:
1046 if (cmd.button() == mouse_button::button1) {
1047 selectWord(cur, WHOLE_WORD_STRICT);
1052 // Single-click on work area
1053 case LFUN_MOUSE_PRESS: {
1054 // Right click on a footnote flag opens float menu
1055 if (cmd.button() == mouse_button::button3)
1056 cur.clearSelection();
1058 // Middle button press pastes if we have a selection
1059 // We do this here as if the selection was inside an inset
1060 // it could get cleared on the unlocking of the inset so
1061 // we have to check this first
1062 bool paste_internally = false;
1063 if (cmd.button() == mouse_button::button2 && cap::selection()) {
1064 // Copy the selection buffer to the clipboard
1065 // stack, because we want it to appear in the
1066 // "Edit->Paste recent" menu.
1067 cap::copySelectionToStack();
1068 paste_internally = true;
1071 // Insert primary selection with middle mouse
1072 // if there is a local selection in the current buffer,
1074 if (cmd.button() == mouse_button::button2) {
1075 if (paste_internally) {
1076 cap::pasteSelection(cur, bv->buffer()->errorList("Paste"));
1077 bv->buffer()->errors("Paste");
1078 cur.clearSelection(); // bug 393
1080 bv->buffer()->markDirty();
1083 bv->mouseSetCursor(cur);
1084 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
1088 // we have to update after dePM triggered
1089 bool update = bv->mouseSetCursor(cur);
1091 if (!update && cmd.button() == mouse_button::button1) {
1092 needsUpdate = false;
1099 case LFUN_MOUSE_MOTION: {
1100 // Only use motion with button 1
1101 //if (cmd.button() != mouse_button::button1)
1104 // ignore motions deeper nested than the real anchor
1105 Cursor & bvcur = cur.bv().cursor();
1106 if (bvcur.anchor_.hasPart(cur)) {
1107 CursorSlice old = bvcur.top();
1109 int const wh = bv->workHeight();
1110 int const y = std::max(0, std::min(wh - 1, cmd.y));
1112 setCursorFromCoordinates(cur, cmd.x, y);
1113 cur.setTargetX(cmd.x);
1115 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1117 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1118 // This is to allow jumping over large insets
1119 if (cur.top() == old) {
1121 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1123 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1126 if (cur.top() == old)
1129 // don't set anchor_
1130 bvcur.setCursor(cur);
1131 bvcur.selection() = true;
1132 //lyxerr << "MOTION: " << bv->cursor() << endl;
1140 case LFUN_MOUSE_RELEASE: {
1141 if (cmd.button() == mouse_button::button2)
1144 if (cmd.button() == mouse_button::button1) {
1145 // if there is new selection, update persistent
1146 // selection, otherwise, single click does not
1147 // clear persistent selection buffer
1148 if (cur.selection()) {
1150 // if double click, cur is moved to the end of word by selectWord
1151 // but bvcur is current mouse position
1152 Cursor & bvcur = cur.bv().cursor();
1153 bvcur.selection() = true;
1154 saveSelection(bvcur);
1156 needsUpdate = false;
1164 case LFUN_SELF_INSERT: {
1165 if (cmd.argument().empty())
1168 // Automatically delete the currently selected
1169 // text and replace it with what is being
1170 // typed in now. Depends on lyxrc settings
1171 // "auto_region_delete", which defaults to
1174 if (lyxrc.auto_region_delete)
1175 if (cur.selection())
1176 cutSelection(cur, false, false);
1178 cur.clearSelection();
1179 Font const old_font = real_current_font;
1181 docstring::const_iterator cit = cmd.argument().begin();
1182 docstring::const_iterator end = cmd.argument().end();
1183 for (; cit != end; ++cit)
1184 bv->getIntl().getTransManager().
1185 translateAndInsert(*cit, this, cur);
1188 moveCursor(cur, false);
1192 case LFUN_URL_INSERT: {
1193 InsetCommandParams p("url");
1194 string const data = InsetCommandMailer::params2string("url", p);
1195 bv->showInsetDialog("url", data, 0);
1199 case LFUN_HTML_INSERT: {
1200 InsetCommandParams p("htmlurl");
1201 string const data = InsetCommandMailer::params2string("url", p);
1202 bv->showInsetDialog("url", data, 0);
1206 case LFUN_LABEL_INSERT: {
1207 InsetCommandParams p("label");
1208 // Try to generate a valid label
1209 p["name"] = (cmd.argument().empty()) ?
1210 cur.getPossibleLabel() :
1212 string const data = InsetCommandMailer::params2string("label", p);
1214 if (cmd.argument().empty()) {
1215 bv->showInsetDialog("label", data, 0);
1217 FuncRequest fr(LFUN_INSET_INSERT, data);
1225 case LFUN_LIST_INSERT:
1226 case LFUN_THEOREM_INSERT:
1228 case LFUN_CAPTION_INSERT:
1229 // Open the inset, and move the current selection
1231 doInsertInset(cur, this, cmd, true, true);
1233 updateLabels(*bv->buffer());
1235 case LFUN_NOTE_INSERT:
1236 case LFUN_CHARSTYLE_INSERT:
1237 case LFUN_BOX_INSERT:
1238 case LFUN_BRANCH_INSERT:
1239 case LFUN_BIBITEM_INSERT:
1240 case LFUN_ERT_INSERT:
1241 case LFUN_LISTING_INSERT:
1242 case LFUN_FOOTNOTE_INSERT:
1243 case LFUN_MARGINALNOTE_INSERT:
1244 case LFUN_OPTIONAL_INSERT:
1245 case LFUN_ENVIRONMENT_INSERT:
1246 // Open the inset, and move the current selection
1248 doInsertInset(cur, this, cmd, true, true);
1252 case LFUN_TABULAR_INSERT:
1253 // if there were no arguments, just open the dialog
1254 if (doInsertInset(cur, this, cmd, false, true))
1257 bv->showDialog("tabularcreate");
1261 case LFUN_FLOAT_INSERT:
1262 case LFUN_FLOAT_WIDE_INSERT:
1263 case LFUN_WRAP_INSERT: {
1264 bool content = cur.selection(); // will some text be moved into the inset?
1266 doInsertInset(cur, this, cmd, true, true);
1268 ParagraphList & pars = cur.text()->paragraphs();
1270 TextClass const & tclass = bv->buffer()->params().getTextClass();
1272 // add a separate paragraph for the caption inset
1273 pars.push_back(Paragraph());
1274 pars.back().setInsetOwner(pars[0].inInset());
1275 pars.back().layout(tclass.defaultLayout());
1277 int cap_pit = pars.size() - 1;
1279 // if an empty inset was created, we create an additional empty
1280 // paragraph at the bottom so that the user can choose where to put
1281 // the graphics (or table).
1283 pars.push_back(Paragraph());
1284 pars.back().setInsetOwner(pars[0].inInset());
1285 pars.back().layout(tclass.defaultLayout());
1289 // reposition the cursor to the caption
1290 cur.pit() = cap_pit;
1292 cur.dispatch(FuncRequest(LFUN_CAPTION_INSERT));
1293 // FIXME: When leaving the Float (or Wrap) inset we should
1294 // delete any empty paragraph left above or below the
1299 case LFUN_INDEX_INSERT:
1300 case LFUN_NOMENCL_INSERT: {
1301 Inset * inset = createInset(&cur.bv(), cmd);
1305 cur.clearSelection();
1306 insertInset(cur, inset);
1307 inset->edit(cur, true);
1308 // Show the dialog for the nomenclature entry, since the
1309 // description entry still needs to be filled in.
1310 if (cmd.action == LFUN_NOMENCL_INSERT)
1311 InsetCommandMailer("nomenclature",
1312 *reinterpret_cast<InsetCommand *>(inset)).showDialog(&cur.bv());
1317 case LFUN_INDEX_PRINT:
1318 case LFUN_NOMENCL_PRINT:
1319 case LFUN_TOC_INSERT:
1320 case LFUN_HFILL_INSERT:
1321 case LFUN_LINE_INSERT:
1322 case LFUN_PAGEBREAK_INSERT:
1323 case LFUN_CLEARPAGE_INSERT:
1324 case LFUN_CLEARDOUBLEPAGE_INSERT:
1326 doInsertInset(cur, this, cmd, false, false);
1330 case LFUN_DEPTH_DECREMENT:
1331 changeDepth(cur, DEC_DEPTH);
1334 case LFUN_DEPTH_INCREMENT:
1335 changeDepth(cur, INC_DEPTH);
1338 case LFUN_MATH_DISPLAY:
1339 mathDispatch(cur, cmd, true);
1342 case LFUN_MATH_IMPORT_SELECTION:
1343 case LFUN_MATH_MODE:
1344 if (cmd.argument() == "on")
1345 // don't pass "on" as argument
1346 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1348 mathDispatch(cur, cmd, false);
1351 case LFUN_MATH_MACRO:
1352 if (cmd.argument().empty())
1353 cur.errorMessage(from_utf8(N_("Missing argument")));
1355 string s = to_utf8(cmd.argument());
1356 string const s1 = token(s, ' ', 1);
1357 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1358 string const s2 = token(s, ' ', 2);
1359 string const type = s2.empty() ? "newcommand" : s2;
1360 cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, from_utf8(type)));
1361 //cur.nextInset()->edit(cur, true);
1365 // passthrough hat and underscore outside mathed:
1366 case LFUN_MATH_SUBSCRIPT:
1367 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1369 case LFUN_MATH_SUPERSCRIPT:
1370 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1373 case LFUN_MATH_INSERT:
1374 case LFUN_MATH_MATRIX:
1375 case LFUN_MATH_DELIM:
1376 case LFUN_MATH_BIGDELIM: {
1377 cur.insert(new InsetMathHull(hullSimple));
1378 cur.dispatch(FuncRequest(LFUN_CHAR_FORWARD));
1379 BOOST_ASSERT(cur.inMathed());
1384 case LFUN_FONT_EMPH: {
1385 Font font(Font::ALL_IGNORE);
1386 font.setEmph(Font::TOGGLE);
1387 toggleAndShow(cur, this, font);
1391 case LFUN_FONT_BOLD: {
1392 Font font(Font::ALL_IGNORE);
1393 font.setSeries(Font::BOLD_SERIES);
1394 toggleAndShow(cur, this, font);
1398 case LFUN_FONT_NOUN: {
1399 Font font(Font::ALL_IGNORE);
1400 font.setNoun(Font::TOGGLE);
1401 toggleAndShow(cur, this, font);
1405 case LFUN_FONT_CODE: {
1406 Font font(Font::ALL_IGNORE);
1407 font.setFamily(Font::TYPEWRITER_FAMILY); // no good
1408 toggleAndShow(cur, this, font);
1412 case LFUN_FONT_SANS: {
1413 Font font(Font::ALL_IGNORE);
1414 font.setFamily(Font::SANS_FAMILY);
1415 toggleAndShow(cur, this, font);
1419 case LFUN_FONT_ROMAN: {
1420 Font font(Font::ALL_IGNORE);
1421 font.setFamily(Font::ROMAN_FAMILY);
1422 toggleAndShow(cur, this, font);
1426 case LFUN_FONT_DEFAULT: {
1427 Font font(Font::ALL_INHERIT, ignore_language);
1428 toggleAndShow(cur, this, font);
1432 case LFUN_FONT_UNDERLINE: {
1433 Font font(Font::ALL_IGNORE);
1434 font.setUnderbar(Font::TOGGLE);
1435 toggleAndShow(cur, this, font);
1439 case LFUN_FONT_SIZE: {
1440 Font font(Font::ALL_IGNORE);
1441 font.setLyXSize(to_utf8(cmd.argument()));
1442 toggleAndShow(cur, this, font);
1446 case LFUN_LANGUAGE: {
1447 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1450 Font font(Font::ALL_IGNORE);
1451 font.setLanguage(lang);
1452 toggleAndShow(cur, this, font);
1457 case LFUN_FONT_FREE_APPLY:
1458 toggleAndShow(cur, this, freefont, toggleall);
1459 cur.message(_("Character set"));
1462 // Set the freefont using the contents of \param data dispatched from
1463 // the frontends and apply it at the current cursor location.
1464 case LFUN_FONT_FREE_UPDATE: {
1467 if (bv_funcs::string2font(to_utf8(cmd.argument()), font, toggle)) {
1470 toggleAndShow(cur, this, freefont, toggleall);
1471 cur.message(_("Character set"));
1476 case LFUN_FINISHED_LEFT:
1477 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1478 if (reverseDirectionNeeded(cur))
1482 case LFUN_FINISHED_RIGHT:
1483 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1484 if (!reverseDirectionNeeded(cur))
1488 case LFUN_LAYOUT_PARAGRAPH: {
1490 params2string(cur.paragraph(), data);
1491 data = "show\n" + data;
1492 bv->showDialogWithData("paragraph", data);
1496 case LFUN_PARAGRAPH_UPDATE: {
1498 params2string(cur.paragraph(), data);
1500 // Will the paragraph accept changes from the dialog?
1501 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1503 data = "update " + convert<string>(accept) + '\n' + data;
1504 bv->updateDialog("paragraph", data);
1508 case LFUN_ACCENT_UMLAUT:
1509 case LFUN_ACCENT_CIRCUMFLEX:
1510 case LFUN_ACCENT_GRAVE:
1511 case LFUN_ACCENT_ACUTE:
1512 case LFUN_ACCENT_TILDE:
1513 case LFUN_ACCENT_CEDILLA:
1514 case LFUN_ACCENT_MACRON:
1515 case LFUN_ACCENT_DOT:
1516 case LFUN_ACCENT_UNDERDOT:
1517 case LFUN_ACCENT_UNDERBAR:
1518 case LFUN_ACCENT_CARON:
1519 case LFUN_ACCENT_SPECIAL_CARON:
1520 case LFUN_ACCENT_BREVE:
1521 case LFUN_ACCENT_TIE:
1522 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1523 case LFUN_ACCENT_CIRCLE:
1524 case LFUN_ACCENT_OGONEK:
1525 theLyXFunc().handleKeyFunc(cmd.action);
1526 if (!cmd.argument().empty())
1527 // FIXME: Are all these characters encoded in one byte in utf8?
1528 bv->getIntl().getTransManager()
1529 .translateAndInsert(cmd.argument()[0], this, cur);
1532 case LFUN_FLOAT_LIST: {
1533 TextClass const & tclass = bv->buffer()->params().getTextClass();
1534 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1535 // not quite sure if we want this...
1537 cur.clearSelection();
1538 breakParagraph(cur);
1540 if (cur.lastpos() != 0) {
1542 breakParagraph(cur);
1545 setLayout(cur, tclass.defaultLayoutName());
1546 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, docstring(), 0);
1547 insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1550 lyxerr << "Non-existent float type: "
1551 << to_utf8(cmd.argument()) << endl;
1556 case LFUN_CHANGE_ACCEPT: {
1557 acceptOrRejectChanges(cur, ACCEPT);
1561 case LFUN_CHANGE_REJECT: {
1562 acceptOrRejectChanges(cur, REJECT);
1566 case LFUN_THESAURUS_ENTRY: {
1567 docstring arg = cmd.argument();
1569 arg = cur.selectionAsString(false);
1571 if (arg.size() > 100 || arg.empty()) {
1572 // Get word or selection
1573 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1574 arg = cur.selectionAsString(false);
1577 bv->showDialogWithData("thesaurus", to_utf8(arg));
1581 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1582 // Given data, an encoding of the ParagraphParameters
1583 // generated in the Paragraph dialog, this function sets
1584 // the current paragraph appropriately.
1585 istringstream is(to_utf8(cmd.argument()));
1588 ParagraphParameters params;
1593 params.labelWidthString(),
1595 cur.message(_("Paragraph layout set"));
1600 if (cur.selection()) {
1601 cur.selection() = false;
1605 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1610 LYXERR(Debug::ACTION)
1611 << BOOST_CURRENT_FUNCTION
1612 << ": Command " << cmd
1613 << " not DISPATCHED by Text" << endl;
1618 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1620 // FIXME: The cursor flag is reset two lines below
1621 // so we need to check here if some of the LFUN did touch that.
1622 // for now only Text::erase() and Text::backspace() do that.
1623 // The plan is to verify all the LFUNs and then to remove this
1624 // singleParUpdate boolean altogether.
1625 if (cur.result().update() & Update::Force) {
1626 singleParUpdate = false;
1630 // FIXME: the following code should go in favor of fine grained
1631 // update flag treatment.
1632 if (singleParUpdate) {
1633 // Inserting characters does not change par height
1634 ParagraphMetrics const & pms
1635 = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
1636 if (pms.dim().height()
1637 == olddim.height()) {
1638 // if so, update _only_ this paragraph
1639 cur.updateFlags(Update::SinglePar |
1641 Update::MultiParSel);
1648 && &oldTopSlice.inset() == &cur.inset()
1649 && oldTopSlice.idx() == cur.idx()
1650 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1651 && !cur.selection())
1652 // FIXME: it would be better if we could just do this
1654 //if (cur.result().update() != Update::FitCursor)
1657 // But some LFUNs do not set Update::FitCursor when needed, so we
1658 // do it for all. This is not very harmfull as FitCursor will provoke
1659 // a full redraw only if needed but still, a proper review of all LFUN
1660 // should be done and this needsUpdate boolean can then be removed.
1661 cur.updateFlags(Update::FitCursor);
1663 cur.updateFlags(Update::Force | Update::FitCursor);
1667 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
1668 FuncStatus & flag) const
1670 BOOST_ASSERT(cur.text() == this);
1672 Font const & font = real_current_font;
1674 Inset::Code code = Inset::NO_CODE;
1676 switch (cmd.action) {
1678 case LFUN_DEPTH_DECREMENT:
1679 enable = changeDepthAllowed(cur, DEC_DEPTH);
1682 case LFUN_DEPTH_INCREMENT:
1683 enable = changeDepthAllowed(cur, INC_DEPTH);
1687 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1690 case LFUN_BIBITEM_INSERT:
1691 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO
1695 case LFUN_DIALOG_SHOW_NEW_INSET:
1696 if (cmd.argument() == "bibitem")
1697 code = Inset::BIBITEM_CODE;
1698 else if (cmd.argument() == "bibtex")
1699 code = Inset::BIBTEX_CODE;
1700 else if (cmd.argument() == "box")
1701 code = Inset::BOX_CODE;
1702 else if (cmd.argument() == "branch")
1703 code = Inset::BRANCH_CODE;
1704 else if (cmd.argument() == "citation")
1705 code = Inset::CITE_CODE;
1706 else if (cmd.argument() == "ert")
1707 code = Inset::ERT_CODE;
1708 else if (cmd.argument() == "external")
1709 code = Inset::EXTERNAL_CODE;
1710 else if (cmd.argument() == "float")
1711 code = Inset::FLOAT_CODE;
1712 else if (cmd.argument() == "graphics")
1713 code = Inset::GRAPHICS_CODE;
1714 else if (cmd.argument() == "include")
1715 code = Inset::INCLUDE_CODE;
1716 else if (cmd.argument() == "index")
1717 code = Inset::INDEX_CODE;
1718 else if (cmd.argument() == "nomenclature")
1719 code = Inset::NOMENCL_CODE;
1720 else if (cmd.argument() == "label")
1721 code = Inset::LABEL_CODE;
1722 else if (cmd.argument() == "note")
1723 code = Inset::NOTE_CODE;
1724 else if (cmd.argument() == "ref")
1725 code = Inset::REF_CODE;
1726 else if (cmd.argument() == "toc")
1727 code = Inset::TOC_CODE;
1728 else if (cmd.argument() == "url")
1729 code = Inset::URL_CODE;
1730 else if (cmd.argument() == "vspace")
1731 code = Inset::VSPACE_CODE;
1732 else if (cmd.argument() == "wrap")
1733 code = Inset::WRAP_CODE;
1734 else if (cmd.argument() == "listings")
1735 code = Inset::LISTINGS_CODE;
1738 case LFUN_ERT_INSERT:
1739 code = Inset::ERT_CODE;
1741 case LFUN_LISTING_INSERT:
1742 code = Inset::LISTINGS_CODE;
1744 case LFUN_FOOTNOTE_INSERT:
1745 code = Inset::FOOT_CODE;
1747 case LFUN_TABULAR_INSERT:
1748 code = Inset::TABULAR_CODE;
1750 case LFUN_MARGINALNOTE_INSERT:
1751 code = Inset::MARGIN_CODE;
1753 case LFUN_FLOAT_INSERT:
1754 case LFUN_FLOAT_WIDE_INSERT:
1755 code = Inset::FLOAT_CODE;
1757 case LFUN_WRAP_INSERT:
1758 code = Inset::WRAP_CODE;
1760 case LFUN_FLOAT_LIST:
1761 code = Inset::FLOAT_LIST_CODE;
1764 case LFUN_LIST_INSERT:
1765 code = Inset::LIST_CODE;
1767 case LFUN_THEOREM_INSERT:
1768 code = Inset::THEOREM_CODE;
1771 case LFUN_CAPTION_INSERT:
1772 code = Inset::CAPTION_CODE;
1774 case LFUN_NOTE_INSERT:
1775 code = Inset::NOTE_CODE;
1777 case LFUN_CHARSTYLE_INSERT:
1778 code = Inset::CHARSTYLE_CODE;
1779 if (cur.buffer().params().getTextClass().charstyles().empty())
1782 case LFUN_BOX_INSERT:
1783 code = Inset::BOX_CODE;
1785 case LFUN_BRANCH_INSERT:
1786 code = Inset::BRANCH_CODE;
1787 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1790 case LFUN_LABEL_INSERT:
1791 code = Inset::LABEL_CODE;
1793 case LFUN_OPTIONAL_INSERT:
1794 code = Inset::OPTARG_CODE;
1795 enable = numberOfOptArgs(cur.paragraph())
1796 < cur.paragraph().layout()->optionalargs;
1798 case LFUN_ENVIRONMENT_INSERT:
1799 code = Inset::BOX_CODE;
1801 case LFUN_INDEX_INSERT:
1802 code = Inset::INDEX_CODE;
1804 case LFUN_INDEX_PRINT:
1805 code = Inset::INDEX_PRINT_CODE;
1807 case LFUN_NOMENCL_INSERT:
1808 code = Inset::NOMENCL_CODE;
1810 case LFUN_NOMENCL_PRINT:
1811 code = Inset::NOMENCL_PRINT_CODE;
1813 case LFUN_TOC_INSERT:
1814 code = Inset::TOC_CODE;
1816 case LFUN_HTML_INSERT:
1817 case LFUN_URL_INSERT:
1818 code = Inset::URL_CODE;
1820 case LFUN_QUOTE_INSERT:
1821 // always allow this, since we will inset a raw quote
1822 // if an inset is not allowed.
1824 case LFUN_HYPHENATION_POINT_INSERT:
1825 case LFUN_LIGATURE_BREAK_INSERT:
1826 case LFUN_HFILL_INSERT:
1827 case LFUN_MENU_SEPARATOR_INSERT:
1828 case LFUN_DOTS_INSERT:
1829 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
1830 code = Inset::SPECIALCHAR_CODE;
1832 case LFUN_SPACE_INSERT:
1833 // slight hack: we know this is allowed in math mode
1835 code = Inset::SPACE_CODE;
1838 case LFUN_INSET_MODIFY:
1839 // We need to disable this, because we may get called for a
1841 // InsetTabular::getStatus() -> InsetText::getStatus()
1842 // and we don't handle LFUN_INSET_MODIFY.
1846 case LFUN_FONT_EMPH:
1847 flag.setOnOff(font.emph() == Font::ON);
1850 case LFUN_FONT_NOUN:
1851 flag.setOnOff(font.noun() == Font::ON);
1854 case LFUN_FONT_BOLD:
1855 flag.setOnOff(font.series() == Font::BOLD_SERIES);
1858 case LFUN_FONT_SANS:
1859 flag.setOnOff(font.family() == Font::SANS_FAMILY);
1862 case LFUN_FONT_ROMAN:
1863 flag.setOnOff(font.family() == Font::ROMAN_FAMILY);
1866 case LFUN_FONT_CODE:
1867 flag.setOnOff(font.family() == Font::TYPEWRITER_FAMILY);
1872 enable = cur.selection();
1876 if (cmd.argument().empty()) {
1877 if (theClipboard().isInternal())
1878 enable = cap::numberOfSelections() > 0;
1880 enable = !theClipboard().empty();
1882 string const arg = to_utf8(cmd.argument());
1883 if (isStrUnsignedInt(arg)) {
1884 unsigned int n = convert<unsigned int>(arg);
1885 enable = cap::numberOfSelections() > n;
1892 case LFUN_CLIPBOARD_PASTE:
1893 enable = !theClipboard().empty();
1896 case LFUN_PRIMARY_SELECTION_PASTE:
1897 enable = cur.selection() || !theSelection().empty();
1900 case LFUN_PARAGRAPH_MOVE_UP:
1901 enable = cur.pit() > 0 && !cur.selection();
1904 case LFUN_PARAGRAPH_MOVE_DOWN:
1905 enable = cur.pit() < cur.lastpit() && !cur.selection();
1908 case LFUN_INSET_DISSOLVE:
1909 enable = !isMainText(*cur.bv().buffer()) && cur.inset().nargs() == 1;
1912 case LFUN_CHANGE_ACCEPT:
1913 case LFUN_CHANGE_REJECT:
1914 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
1915 // In principle, these LFUNs should only be enabled if there
1916 // is a change at the current position/in the current selection.
1917 // However, without proper optimizations, this will inevitably
1918 // result in unacceptable performance - just imagine a user who
1919 // wants to select the complete content of a long document.
1923 case LFUN_WORD_DELETE_FORWARD:
1924 case LFUN_WORD_DELETE_BACKWARD:
1925 case LFUN_LINE_DELETE:
1926 case LFUN_WORD_FORWARD:
1927 case LFUN_WORD_BACKWARD:
1928 case LFUN_CHAR_FORWARD:
1929 case LFUN_CHAR_FORWARD_SELECT:
1930 case LFUN_CHAR_BACKWARD:
1931 case LFUN_CHAR_BACKWARD_SELECT:
1933 case LFUN_UP_SELECT:
1935 case LFUN_DOWN_SELECT:
1936 case LFUN_PARAGRAPH_UP_SELECT:
1937 case LFUN_PARAGRAPH_DOWN_SELECT:
1938 case LFUN_SCREEN_UP_SELECT:
1939 case LFUN_SCREEN_DOWN_SELECT:
1940 case LFUN_LINE_BEGIN_SELECT:
1941 case LFUN_LINE_END_SELECT:
1942 case LFUN_WORD_FORWARD_SELECT:
1943 case LFUN_WORD_BACKWARD_SELECT:
1944 case LFUN_WORD_SELECT:
1945 case LFUN_PARAGRAPH_UP:
1946 case LFUN_PARAGRAPH_DOWN:
1947 case LFUN_SCREEN_UP:
1948 case LFUN_SCREEN_DOWN:
1949 case LFUN_LINE_BEGIN:
1951 case LFUN_BREAK_LINE:
1952 case LFUN_CHAR_DELETE_FORWARD:
1953 case LFUN_DELETE_FORWARD_SKIP:
1954 case LFUN_CHAR_DELETE_BACKWARD:
1955 case LFUN_DELETE_BACKWARD_SKIP:
1956 case LFUN_BREAK_PARAGRAPH:
1957 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
1958 case LFUN_BREAK_PARAGRAPH_SKIP:
1959 case LFUN_PARAGRAPH_SPACING:
1960 case LFUN_INSET_INSERT:
1961 case LFUN_WORD_UPCASE:
1962 case LFUN_WORD_LOWCASE:
1963 case LFUN_WORD_CAPITALIZE:
1964 case LFUN_CHARS_TRANSPOSE:
1965 case LFUN_SERVER_GET_XY:
1966 case LFUN_SERVER_SET_XY:
1967 case LFUN_SERVER_GET_FONT:
1968 case LFUN_SERVER_GET_LAYOUT:
1970 case LFUN_DATE_INSERT:
1971 case LFUN_SELF_INSERT:
1972 case LFUN_LINE_INSERT:
1973 case LFUN_PAGEBREAK_INSERT:
1974 case LFUN_CLEARPAGE_INSERT:
1975 case LFUN_CLEARDOUBLEPAGE_INSERT:
1976 case LFUN_MATH_DISPLAY:
1977 case LFUN_MATH_IMPORT_SELECTION:
1978 case LFUN_MATH_MODE:
1979 case LFUN_MATH_MACRO:
1980 case LFUN_MATH_MATRIX:
1981 case LFUN_MATH_DELIM:
1982 case LFUN_MATH_BIGDELIM:
1983 case LFUN_MATH_SUBSCRIPT:
1984 case LFUN_MATH_SUPERSCRIPT:
1985 case LFUN_FONT_DEFAULT:
1986 case LFUN_FONT_UNDERLINE:
1987 case LFUN_FONT_SIZE:
1989 case LFUN_FONT_FREE_APPLY:
1990 case LFUN_FONT_FREE_UPDATE:
1991 case LFUN_LAYOUT_PARAGRAPH:
1992 case LFUN_PARAGRAPH_UPDATE:
1993 case LFUN_ACCENT_UMLAUT:
1994 case LFUN_ACCENT_CIRCUMFLEX:
1995 case LFUN_ACCENT_GRAVE:
1996 case LFUN_ACCENT_ACUTE:
1997 case LFUN_ACCENT_TILDE:
1998 case LFUN_ACCENT_CEDILLA:
1999 case LFUN_ACCENT_MACRON:
2000 case LFUN_ACCENT_DOT:
2001 case LFUN_ACCENT_UNDERDOT:
2002 case LFUN_ACCENT_UNDERBAR:
2003 case LFUN_ACCENT_CARON:
2004 case LFUN_ACCENT_SPECIAL_CARON:
2005 case LFUN_ACCENT_BREVE:
2006 case LFUN_ACCENT_TIE:
2007 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
2008 case LFUN_ACCENT_CIRCLE:
2009 case LFUN_ACCENT_OGONEK:
2010 case LFUN_THESAURUS_ENTRY:
2011 case LFUN_PARAGRAPH_PARAMS_APPLY:
2013 case LFUN_BUFFER_END:
2014 case LFUN_BUFFER_BEGIN:
2015 case LFUN_BUFFER_BEGIN_SELECT:
2016 case LFUN_BUFFER_END_SELECT:
2017 case LFUN_UNICODE_INSERT:
2018 // these are handled in our dispatch()
2026 if (code != Inset::NO_CODE
2027 && (cur.empty() || !cur.inset().insetAllowed(code)))
2030 flag.enabled(enable);
2035 void Text::pasteString(Cursor & cur, docstring const & clip,
2038 cur.clearSelection();
2039 if (!clip.empty()) {
2042 insertStringAsParagraphs(cur, clip);
2044 insertStringAsLines(cur, clip);