3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Asger Alstrup
7 * \author Lars Gullik Bjønnes
8 * \author Alfredo Braunstein
9 * \author Angus Leeming
11 * \author André Pönitz
13 * Full author contact details are available in file CREDITS.
20 #include "BranchList.h"
21 #include "FloatList.h"
22 #include "FuncStatus.h"
24 #include "buffer_funcs.h"
25 #include "BufferParams.h"
26 #include "BufferView.h"
27 #include "bufferview_funcs.h"
29 #include "CoordCache.h"
30 #include "CutAndPaste.h"
32 #include "DispatchResult.h"
33 #include "ErrorList.h"
35 #include "FuncRequest.h"
39 #include "LyXAction.h"
44 #include "Paragraph.h"
45 #include "paragraph_funcs.h"
46 #include "ParagraphParameters.h"
49 #include "ParIterator.h"
51 #include "frontends/Clipboard.h"
52 #include "frontends/Selection.h"
54 #include "insets/InsetCommand.h"
55 #include "insets/InsetFloatList.h"
56 #include "insets/InsetNewline.h"
57 #include "insets/InsetQuotes.h"
58 #include "insets/InsetSpecialChar.h"
59 #include "insets/InsetText.h"
61 #include "support/lstrings.h"
62 #include "support/lyxlib.h"
63 #include "support/convert.h"
64 #include "support/lyxtime.h"
66 #include "mathed/InsetMathHull.h"
67 #include "mathed/MathMacroTemplate.h"
69 #include <boost/current_function.hpp>
77 using cap::copySelection;
78 using cap::cutSelection;
79 using cap::pasteFromStack;
80 using cap::pasteClipboard;
81 using cap::replaceSelection;
83 using support::isStrUnsignedInt;
88 using std::istringstream;
89 using std::ostringstream;
92 extern string current_layout;
98 Font freefont(Font::ALL_IGNORE);
99 bool toggleall = false;
101 void toggleAndShow(Cursor & cur, Text * text,
102 Font const & font, bool toggleall = true)
104 text->toggleFree(cur, font, toggleall);
106 if (font.language() != ignore_language ||
107 font.number() != Font::IGNORE) {
108 Paragraph & par = cur.paragraph();
109 if (cur.boundary() != text->isRTLBoundary(cur.buffer(), par,
110 cur.pos(), text->real_current_font))
111 text->setCursor(cur, cur.pit(), cur.pos(),
112 false, !cur.boundary());
117 void moveCursor(Cursor & cur, bool selecting)
119 if (selecting || cur.mark())
124 void finishChange(Cursor & cur, bool selecting)
127 moveCursor(cur, selecting);
131 void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
134 docstring sel = cur.selectionAsString(false);
136 // It may happen that sel is empty but there is a selection
137 replaceSelection(cur);
140 #ifdef ENABLE_ASSERTIONS
141 const int old_pos = cur.pos();
143 cur.insert(new InsetMathHull(hullSimple));
144 BOOST_ASSERT(old_pos == cur.pos());
145 cur.nextInset()->edit(cur, true);
146 // don't do that also for LFUN_MATH_MODE
147 // unless you want end up with always changing
148 // to mathrm when opening an inlined inset --
149 // I really hate "LyXfunc overloading"...
151 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
152 // Avoid an unnecessary undo step if cmd.argument
154 if (!cmd.argument().empty())
155 cur.dispatch(FuncRequest(LFUN_MATH_INSERT,
158 // create a macro if we see "\\newcommand"
159 // somewhere, and an ordinary formula
161 if (sel.find(from_ascii("\\newcommand")) == string::npos
162 && sel.find(from_ascii("\\def")) == string::npos)
164 InsetMathHull * formula = new InsetMathHull;
165 istringstream is(to_utf8(sel));
168 formula->read(cur.buffer(), lex);
169 if (formula->getType() == hullNone)
170 // Don't create pseudo formulas if
171 // delimiters are left out
172 formula->mutate(hullSimple);
175 cur.insert(new MathMacroTemplate(sel));
178 cur.message(from_utf8(N_("Math editor mode")));
187 string const freefont2string()
190 if (font2string(freefont, toggleall, data))
197 void Text::cursorPrevious(Cursor & cur)
199 pos_type cpos = cur.pos();
200 pit_type cpar = cur.pit();
202 int x = cur.x_target();
203 setCursorFromCoordinates(cur, x, 0);
204 cur.dispatch(FuncRequest(cur.selection()? LFUN_UP_SELECT: LFUN_UP));
206 if (cpar == cur.pit() && cpos == cur.pos())
207 // we have a row which is taller than the workarea. The
208 // simplest solution is to move to the previous row instead.
209 cur.dispatch(FuncRequest(cur.selection()? LFUN_UP_SELECT: LFUN_UP));
212 cur.updateFlags(Update::Force | Update::FitCursor);
216 void Text::cursorNext(Cursor & cur)
218 pos_type cpos = cur.pos();
219 pit_type cpar = cur.pit();
221 int x = cur.x_target();
222 setCursorFromCoordinates(cur, x, cur.bv().workHeight() - 1);
223 cur.dispatch(FuncRequest(cur.selection()? LFUN_DOWN_SELECT: LFUN_DOWN));
225 if (cpar == cur.pit() && cpos == cur.pos())
226 // we have a row which is taller than the workarea. The
227 // simplest solution is to move to the next row instead.
229 FuncRequest(cur.selection()? LFUN_DOWN_SELECT: LFUN_DOWN));
232 cur.updateFlags(Update::Force | Update::FitCursor);
238 void specialChar(Cursor & cur, InsetSpecialChar::Kind kind)
241 cap::replaceSelection(cur);
242 cur.insert(new InsetSpecialChar(kind));
247 bool doInsertInset(Cursor & cur, Text * text,
248 FuncRequest const & cmd, bool edit, bool pastesel)
250 Inset * inset = createInset(&cur.bv(), cmd);
256 if (cur.selection()) {
257 lyx::dispatch(FuncRequest(LFUN_CUT));
260 text->insertInset(cur, inset);
263 inset->edit(cur, true);
265 if (gotsel && pastesel) {
266 lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
267 // reset first par to default
268 if (cur.lastpit() != 0 || cur.lastpos() != 0) {
269 Layout_ptr const layout =
270 cur.buffer().params().getTextClass().defaultLayout();
271 cur.text()->paragraphs().begin()->layout(layout);
281 void Text::number(Cursor & cur)
283 Font font(Font::ALL_IGNORE);
284 font.setNumber(Font::TOGGLE);
285 toggleAndShow(cur, this, font);
289 bool Text::isRTL(Buffer const & buffer, Paragraph const & par) const
291 return par.isRightToLeftPar(buffer.params());
295 bool Text::isRTL(Buffer const & buffer, CursorSlice const & sl, bool boundary) const
297 if (!lyxrc.rtl_support && !sl.text())
301 if (boundary && sl.pos() > 0)
304 Paragraph const & par = getPar(sl.pit());
305 return getFont(buffer, par, sl.pos() + correction).isVisibleRightToLeft();
309 bool Text::isRTLBoundary(Buffer const & buffer, Paragraph const & par,
312 if (!lyxrc.rtl_support)
315 // no RTL boundary at line start
319 bool left = getFont(buffer, par, pos - 1).isVisibleRightToLeft();
321 if (pos == par.size())
322 right = par.isRightToLeftPar(buffer.params());
324 right = getFont(buffer, par, pos).isVisibleRightToLeft();
325 return left != right;
329 bool Text::isRTLBoundary(Buffer const & buffer, Paragraph const & par,
330 pos_type pos, Font const & font) const
332 if (!lyxrc.rtl_support)
335 bool left = font.isVisibleRightToLeft();
337 if (pos == par.size())
338 right = par.isRightToLeftPar(buffer.params());
340 right = getFont(buffer, par, pos).isVisibleRightToLeft();
341 return left != right;
345 void Text::dispatch(Cursor & cur, FuncRequest & cmd)
347 LYXERR(Debug::ACTION) << "Text::dispatch: cmd: " << cmd << endl;
349 // FIXME: We use the update flag to indicates wether a singlePar or a
350 // full screen update is needed. We reset it here but shall we restore it
354 BOOST_ASSERT(cur.text() == this);
355 BufferView * bv = &cur.bv();
356 CursorSlice oldTopSlice = cur.top();
357 bool oldBoundary = cur.boundary();
358 bool sel = cur.selection();
359 // Signals that, even if needsUpdate == false, an update of the
360 // cursor paragraph is required
361 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
362 LyXAction::SingleParUpdate);
363 // Signals that a full-screen update is required
364 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
365 LyXAction::NoUpdate) || singleParUpdate);
366 // Remember the old paragraph metric (_outer_ paragraph!)
367 ParagraphMetrics const & pm = cur.bv().parMetrics(
368 cur.bottom().text(), cur.bottom().pit());
369 Dimension olddim = pm.dim();
371 switch (cmd.action) {
373 case LFUN_PARAGRAPH_MOVE_DOWN: {
374 pit_type const pit = cur.pit();
375 recUndo(cur, pit, pit + 1);
377 std::swap(pars_[pit], pars_[pit + 1]);
379 ParIterator begin(cur);
380 // begin.pos() (== cur.pos()) may point beyond the end of the
381 // paragraph referenced by begin. This would cause a crash
385 ParIterator end = boost::next(ParIterator(cur));
386 updateLabels(cur.buffer(), begin, end);
392 case LFUN_PARAGRAPH_MOVE_UP: {
393 pit_type const pit = cur.pit();
394 recUndo(cur, pit - 1, pit);
396 std::swap(pars_[pit], pars_[pit - 1]);
398 ParIterator end = ParIterator(cur);
399 // end.pos() (== cur.pos()) may point beyond the end of the
400 // paragraph referenced by end. This would cause a crash
403 end = boost::next(end);
405 ParIterator begin(cur);
406 updateLabels(cur.buffer(), begin, end);
412 case LFUN_APPENDIX: {
413 Paragraph & par = cur.paragraph();
414 bool start = !par.params().startOfAppendix();
417 #warning The code below only makes sense at top level.
418 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
420 // ensure that we have only one start_of_appendix in this document
421 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
422 if (pars_[tmp].params().startOfAppendix()) {
424 pars_[tmp].params().startOfAppendix(false);
430 par.params().startOfAppendix(start);
432 // we can set the refreshing parameters now
433 updateLabels(cur.buffer());
437 case LFUN_WORD_DELETE_FORWARD:
438 if (cur.selection()) {
439 cutSelection(cur, true, false);
441 deleteWordForward(cur);
442 finishChange(cur, false);
445 case LFUN_WORD_DELETE_BACKWARD:
446 if (cur.selection()) {
447 cutSelection(cur, true, false);
449 deleteWordBackward(cur);
450 finishChange(cur, false);
453 case LFUN_LINE_DELETE:
454 if (cur.selection()) {
455 cutSelection(cur, true, false);
457 deleteLineForward(cur);
458 finishChange(cur, false);
461 case LFUN_BUFFER_BEGIN:
462 case LFUN_BUFFER_BEGIN_SELECT:
463 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
464 if (cur.depth() == 1) {
465 needsUpdate |= cursorTop(cur);
471 case LFUN_BUFFER_END:
472 case LFUN_BUFFER_END_SELECT:
473 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
474 if (cur.depth() == 1) {
475 needsUpdate |= cursorBottom(cur);
481 case LFUN_CHAR_FORWARD:
482 case LFUN_CHAR_FORWARD_SELECT:
483 //lyxerr << BOOST_CURRENT_FUNCTION
484 // << " LFUN_CHAR_FORWARD[SEL]:\n" << cur << endl;
485 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
486 if (reverseDirectionNeeded(cur))
487 needsUpdate |= cursorLeft(cur);
489 needsUpdate |= cursorRight(cur);
491 if (!needsUpdate && oldTopSlice == cur.top()
492 && cur.boundary() == oldBoundary) {
494 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
498 case LFUN_CHAR_BACKWARD:
499 case LFUN_CHAR_BACKWARD_SELECT:
500 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
501 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
502 if (reverseDirectionNeeded(cur))
503 needsUpdate |= cursorRight(cur);
505 needsUpdate |= cursorLeft(cur);
507 if (!needsUpdate && oldTopSlice == cur.top()
508 && cur.boundary() == oldBoundary) {
510 cmd = FuncRequest(LFUN_FINISHED_LEFT);
515 case LFUN_DOWN_SELECT:
518 // stop/start the selection
519 bool select = cmd.action == LFUN_DOWN_SELECT ||
520 cmd.action == LFUN_UP_SELECT;
521 cur.selHandle(select);
523 // move cursor up/down
524 bool up = cmd.action == LFUN_UP_SELECT || cmd.action == LFUN_UP;
525 bool const successful = cur.upDownInText(up, needsUpdate);
527 // notify insets which were left and get their update flags
528 notifyCursorLeaves(cur.beforeDispatchCursor(), cur);
531 // redraw if you leave mathed (for the decorations)
532 needsUpdate |= cur.beforeDispatchCursor().inMathed();
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);
545 case LFUN_PARAGRAPH_DOWN:
546 case LFUN_PARAGRAPH_DOWN_SELECT:
547 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
548 needsUpdate |= cursorDownParagraph(cur);
552 case LFUN_SCREEN_UP_SELECT:
553 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_UP_SELECT);
554 if (cur.pit() == 0 && cur.textRow().pos() == 0)
561 case LFUN_SCREEN_DOWN:
562 case LFUN_SCREEN_DOWN_SELECT:
563 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_DOWN_SELECT);
564 if (cur.pit() == cur.lastpit()
565 && cur.textRow().endpos() == cur.lastpos())
572 case LFUN_LINE_BEGIN:
573 case LFUN_LINE_BEGIN_SELECT:
574 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
575 needsUpdate |= cursorHome(cur);
579 case LFUN_LINE_END_SELECT:
580 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
581 needsUpdate |= cursorEnd(cur);
584 case LFUN_WORD_FORWARD:
585 case LFUN_WORD_FORWARD_SELECT:
586 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
587 if (reverseDirectionNeeded(cur))
588 needsUpdate |= cursorLeftOneWord(cur);
590 needsUpdate |= cursorRightOneWord(cur);
593 case LFUN_WORD_BACKWARD:
594 case LFUN_WORD_BACKWARD_SELECT:
595 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
596 if (reverseDirectionNeeded(cur))
597 needsUpdate |= cursorRightOneWord(cur);
599 needsUpdate |= cursorLeftOneWord(cur);
602 case LFUN_WORD_SELECT: {
603 selectWord(cur, WHOLE_WORD);
604 finishChange(cur, true);
608 case LFUN_BREAK_LINE: {
609 // Not allowed by LaTeX (labels or empty par)
610 if (cur.pos() > cur.paragraph().beginOfBody()) {
611 // this avoids a double undo
612 // FIXME: should not be needed, ideally
613 if (!cur.selection())
615 cap::replaceSelection(cur);
616 cur.insert(new InsetNewline);
618 moveCursor(cur, false);
623 case LFUN_CHAR_DELETE_FORWARD:
624 if (!cur.selection()) {
625 if (cur.pos() == cur.paragraph().size())
626 // Par boundary, force full-screen update
627 singleParUpdate = false;
628 needsUpdate |= erase(cur);
630 // It is possible to make it a lot faster still
631 // just comment out the line below...
633 cutSelection(cur, true, false);
634 singleParUpdate = false;
636 moveCursor(cur, false);
639 case LFUN_DELETE_FORWARD_SKIP:
640 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
641 if (!cur.selection()) {
642 if (cur.pos() == cur.lastpos()) {
649 cutSelection(cur, true, false);
654 case LFUN_CHAR_DELETE_BACKWARD:
655 if (!cur.selection()) {
656 if (bv->getIntl().getTransManager().backspace()) {
657 // Par boundary, full-screen update
659 singleParUpdate = false;
660 needsUpdate |= backspace(cur);
662 // It is possible to make it a lot faster still
663 // just comment out the line below...
666 cutSelection(cur, true, false);
667 singleParUpdate = false;
671 case LFUN_DELETE_BACKWARD_SKIP:
672 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
673 if (!cur.selection()) {
677 //CursorSlice cur = cursor();
681 cutSelection(cur, true, false);
685 case LFUN_BREAK_PARAGRAPH:
686 cap::replaceSelection(cur);
687 breakParagraph(cur, 0);
691 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
692 cap::replaceSelection(cur);
693 breakParagraph(cur, 1);
697 case LFUN_BREAK_PARAGRAPH_SKIP: {
698 // When at the beginning of a paragraph, remove
699 // indentation. Otherwise, do the same as LFUN_BREAK_PARAGRAPH.
700 cap::replaceSelection(cur);
702 cur.paragraph().params().labelWidthString(docstring());
704 breakParagraph(cur, 0);
709 case LFUN_PARAGRAPH_SPACING: {
710 Paragraph & par = cur.paragraph();
711 Spacing::Space cur_spacing = par.params().spacing().getSpace();
712 string cur_value = "1.0";
713 if (cur_spacing == Spacing::Other)
714 cur_value = par.params().spacing().getValueAsString();
716 istringstream is(to_utf8(cmd.argument()));
719 Spacing::Space new_spacing = cur_spacing;
720 string new_value = cur_value;
722 lyxerr << "Missing argument to `paragraph-spacing'"
724 } else if (tmp == "single") {
725 new_spacing = Spacing::Single;
726 } else if (tmp == "onehalf") {
727 new_spacing = Spacing::Onehalf;
728 } else if (tmp == "double") {
729 new_spacing = Spacing::Double;
730 } else if (tmp == "other") {
731 new_spacing = Spacing::Other;
732 string tmpval = "0.0";
734 lyxerr << "new_value = " << tmpval << endl;
737 } else if (tmp == "default") {
738 new_spacing = Spacing::Default;
740 lyxerr << to_utf8(_("Unknown spacing argument: "))
741 << to_utf8(cmd.argument()) << endl;
743 if (cur_spacing != new_spacing || cur_value != new_value)
744 par.params().spacing(Spacing(new_spacing, new_value));
748 case LFUN_INSET_INSERT: {
750 Inset * inset = createInset(bv, cmd);
752 // FIXME (Abdel 01/02/2006):
753 // What follows would be a partial fix for bug 2154:
754 // http://bugzilla.lyx.org/show_bug.cgi?id=2154
755 // This automatically put the label inset _after_ a
756 // numbered section. It should be possible to extend the mechanism
757 // to any kind of LateX environement.
758 // The correct way to fix that bug would be at LateX generation.
759 // I'll let the code here for reference as it could be used for some
760 // other feature like "automatic labelling".
762 Paragraph & par = pars_[cur.pit()];
763 if (inset->lyxCode() == Inset::LABEL_CODE
764 && par.layout()->labeltype == LABEL_COUNTER) {
765 // Go to the end of the paragraph
766 // Warning: Because of Change-Tracking, the last
767 // position is 'size()' and not 'size()-1':
768 cur.pos() = par.size();
769 // Insert a new paragraph
770 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
774 insertInset(cur, inset);
780 case LFUN_INSET_DISSOLVE:
781 needsUpdate |= dissolveInset(cur);
784 case LFUN_INSET_SETTINGS:
785 cur.inset().showInsetDialog(bv);
788 case LFUN_SPACE_INSERT:
789 if (cur.paragraph().layout()->free_spacing)
790 insertChar(cur, ' ');
792 doInsertInset(cur, this, cmd, false, false);
795 moveCursor(cur, false);
798 case LFUN_HYPHENATION_POINT_INSERT:
799 specialChar(cur, InsetSpecialChar::HYPHENATION);
802 case LFUN_LIGATURE_BREAK_INSERT:
803 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
806 case LFUN_DOTS_INSERT:
807 specialChar(cur, InsetSpecialChar::LDOTS);
810 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
811 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
814 case LFUN_MENU_SEPARATOR_INSERT:
815 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
818 case LFUN_WORD_UPCASE:
819 changeCase(cur, Text::text_uppercase);
822 case LFUN_WORD_LOWCASE:
823 changeCase(cur, Text::text_lowercase);
826 case LFUN_WORD_CAPITALIZE:
827 changeCase(cur, Text::text_capitalization);
830 case LFUN_CHARS_TRANSPOSE:
835 cur.message(_("Paste"));
836 cap::replaceSelection(cur);
837 if (cmd.argument().empty() && !theClipboard().isInternal())
838 pasteClipboard(cur, bv->buffer()->errorList("Paste"));
840 string const arg(to_utf8(cmd.argument()));
841 pasteFromStack(cur, bv->buffer()->errorList("Paste"),
842 isStrUnsignedInt(arg) ?
843 convert<unsigned int>(arg) :
846 bv->buffer()->errors("Paste");
847 cur.clearSelection(); // bug 393
852 cutSelection(cur, true, true);
853 cur.message(_("Cut"));
858 cur.message(_("Copy"));
861 case LFUN_SERVER_GET_XY:
862 cur.message(from_utf8(
863 convert<string>(cursorX(cur.bv(), cur.top(), cur.boundary()))
864 + ' ' + convert<string>(cursorY(cur.bv(), cur.top(), cur.boundary()))));
867 case LFUN_SERVER_SET_XY: {
870 istringstream is(to_utf8(cmd.argument()));
873 lyxerr << "SETXY: Could not parse coordinates in '"
874 << to_utf8(cmd.argument()) << std::endl;
876 setCursorFromCoordinates(cur, x, y);
880 case LFUN_SERVER_GET_FONT:
881 if (current_font.shape() == Font::ITALIC_SHAPE)
882 cur.message(from_ascii("E"));
883 else if (current_font.shape() == Font::SMALLCAPS_SHAPE)
884 cur.message(from_ascii("N"));
886 cur.message(from_ascii("0"));
889 case LFUN_SERVER_GET_LAYOUT:
890 cur.message(from_utf8(cur.paragraph().layout()->name()));
894 string layout = to_ascii(cmd.argument());
895 LYXERR(Debug::INFO) << "LFUN_LAYOUT: (arg) " << layout << endl;
897 // Derive layout number from given argument (string)
898 // and current buffer's textclass (number)
899 TextClass const & tclass = bv->buffer()->params().getTextClass();
901 layout = tclass.defaultLayoutName();
902 bool hasLayout = tclass.hasLayout(layout);
904 // If the entry is obsolete, use the new one instead.
906 string const & obs = tclass[layout]->obsoleted_by();
912 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
913 from_utf8(N_(" not known")));
917 bool change_layout = (current_layout != layout);
919 if (!change_layout && cur.selection() &&
920 cur.selBegin().pit() != cur.selEnd().pit())
922 pit_type spit = cur.selBegin().pit();
923 pit_type epit = cur.selEnd().pit() + 1;
924 while (spit != epit) {
925 if (pars_[spit].layout()->name() != current_layout) {
926 change_layout = true;
934 setLayout(cur, layout);
935 // inform the GUI that the layout has changed.
936 bv->layoutChanged(layout);
941 case LFUN_CLIPBOARD_PASTE:
942 cur.clearSelection();
943 pasteClipboard(cur, bv->buffer()->errorList("Paste"),
944 cmd.argument() == "paragraph");
945 bv->buffer()->errors("Paste");
948 case LFUN_PRIMARY_SELECTION_PASTE:
949 pasteString(cur, theSelection().get(),
950 cmd.argument() == "paragraph");
953 case LFUN_UNICODE_INSERT: {
954 if (cmd.argument().empty())
956 docstring hexstring = cmd.argument();
957 if (lyx::support::isHex(hexstring)) {
958 char_type c = lyx::support::hexToInt(hexstring);
959 if (c >= 32 && c < 0x10ffff) {
960 lyxerr << "Inserting c: " << c << endl;
961 docstring s = docstring(1, c);
962 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
968 case LFUN_QUOTE_INSERT: {
969 Paragraph & par = cur.paragraph();
970 pos_type pos = cur.pos();
971 BufferParams const & bufparams = bv->buffer()->params();
972 Layout_ptr const & style = par.layout();
973 if (!style->pass_thru
974 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
975 // this avoids a double undo
976 // FIXME: should not be needed, ideally
977 if (!cur.selection())
979 cap::replaceSelection(cur);
984 else if (cur.prevInset() && cur.prevInset()->isSpace())
987 c = par.getChar(pos - 1);
988 string arg = to_utf8(cmd.argument());
990 cur.insert(new InsetQuotes(c,
991 bufparams.quotes_language,
992 InsetQuotes::SingleQ));
994 cur.insert(new InsetQuotes(c,
995 bufparams.quotes_language,
996 InsetQuotes::DoubleQ));
1000 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
1004 case LFUN_DATE_INSERT:
1005 if (cmd.argument().empty())
1006 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
1007 formatted_time(current_time())));
1009 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
1010 formatted_time(current_time(), to_utf8(cmd.argument()))));
1013 case LFUN_MOUSE_TRIPLE:
1014 if (cmd.button() == mouse_button::button1) {
1023 case LFUN_MOUSE_DOUBLE:
1024 if (cmd.button() == mouse_button::button1) {
1025 selectWord(cur, WHOLE_WORD_STRICT);
1030 // Single-click on work area
1031 case LFUN_MOUSE_PRESS: {
1032 // Right click on a footnote flag opens float menu
1033 if (cmd.button() == mouse_button::button3)
1034 cur.clearSelection();
1036 // Middle button press pastes if we have a selection
1037 // We do this here as if the selection was inside an inset
1038 // it could get cleared on the unlocking of the inset so
1039 // we have to check this first
1040 bool paste_internally = false;
1041 if (cmd.button() == mouse_button::button2 && cap::selection()) {
1042 // Copy the selection buffer to the clipboard
1043 // stack, because we want it to appear in the
1044 // "Edit->Paste recent" menu.
1045 cap::copySelectionToStack();
1046 paste_internally = true;
1049 // Insert primary selection with middle mouse
1050 // if there is a local selection in the current buffer,
1052 if (cmd.button() == mouse_button::button2) {
1053 if (paste_internally) {
1054 cap::pasteSelection(cur, bv->buffer()->errorList("Paste"));
1055 bv->buffer()->errors("Paste");
1056 cur.clearSelection(); // bug 393
1057 bv->buffer()->markDirty();
1060 bv->mouseSetCursor(cur);
1061 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
1065 // we have to update after dePM triggered
1066 bool update = bv->mouseSetCursor(cur);
1068 if (!update && cmd.button() == mouse_button::button1) {
1069 needsUpdate = false;
1076 case LFUN_MOUSE_MOTION: {
1077 // Only use motion with button 1
1078 //if (cmd.button() != mouse_button::button1)
1081 // ignore motions deeper nested than the real anchor
1082 Cursor & bvcur = cur.bv().cursor();
1083 if (bvcur.anchor_.hasPart(cur)) {
1084 CursorSlice old = bvcur.top();
1086 int const wh = bv->workHeight();
1087 int const y = std::max(0, std::min(wh - 1, cmd.y));
1089 setCursorFromCoordinates(cur, cmd.x, y);
1090 cur.setTargetX(cmd.x);
1092 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1094 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1095 // This is to allow jumping over large insets
1096 if (cur.top() == old) {
1098 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1100 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1103 if (cur.top() == old)
1106 // don't set anchor_
1107 bvcur.setCursor(cur);
1108 bvcur.selection() = true;
1109 //lyxerr << "MOTION: " << bv->cursor() << endl;
1117 case LFUN_MOUSE_RELEASE: {
1118 if (cmd.button() == mouse_button::button2)
1121 if (cmd.button() == mouse_button::button1) {
1122 // if there is new selection, update persistent
1123 // selection, otherwise, single click does not
1124 // clear persistent selection buffer
1125 if (cur.selection()) {
1127 // if double click, cur is moved to the end of word by selectWord
1128 // but bvcur is current mouse position
1129 Cursor & bvcur = cur.bv().cursor();
1130 bvcur.selection() = true;
1132 needsUpdate = false;
1139 case LFUN_SELF_INSERT: {
1140 if (cmd.argument().empty())
1143 // Automatically delete the currently selected
1144 // text and replace it with what is being
1145 // typed in now. Depends on lyxrc settings
1146 // "auto_region_delete", which defaults to
1149 if (lyxrc.auto_region_delete && cur.selection()) {
1150 cutSelection(cur, false, false);
1151 // When change tracking is set to off, the metrics update
1152 // mechanism correctly detects if a full update is needed or not.
1153 // This detection fails when a selection spans multiple rows and
1154 // change tracking is enabled because the paragraph metrics stays
1155 // the same. In this case, we force the full update:
1156 // (see http://bugzilla.lyx.org/show_bug.cgi?id=3992)
1157 if (cur.buffer().params().trackChanges)
1158 cur.updateFlags(Update::Force);
1161 cur.clearSelection();
1162 Font const old_font = real_current_font;
1164 docstring::const_iterator cit = cmd.argument().begin();
1165 docstring::const_iterator end = cmd.argument().end();
1166 for (; cit != end; ++cit)
1167 bv->translateAndInsert(*cit, this, cur);
1170 moveCursor(cur, false);
1174 case LFUN_URL_INSERT: {
1175 InsetCommandParams p("url");
1176 string const data = InsetCommandMailer::params2string("url", p);
1177 bv->showInsetDialog("url", data, 0);
1181 case LFUN_HTML_INSERT: {
1182 InsetCommandParams p("htmlurl");
1183 string const data = InsetCommandMailer::params2string("url", p);
1184 bv->showInsetDialog("url", data, 0);
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 cur.insert(new InsetMathHull(hullSimple));
1360 checkAndActivateInset(cur, true);
1361 BOOST_ASSERT(cur.inMathed());
1366 case LFUN_FONT_EMPH: {
1367 Font font(Font::ALL_IGNORE);
1368 font.setEmph(Font::TOGGLE);
1369 toggleAndShow(cur, this, font);
1373 case LFUN_FONT_BOLD: {
1374 Font font(Font::ALL_IGNORE);
1375 font.setSeries(Font::BOLD_SERIES);
1376 toggleAndShow(cur, this, font);
1380 case LFUN_FONT_NOUN: {
1381 Font font(Font::ALL_IGNORE);
1382 font.setNoun(Font::TOGGLE);
1383 toggleAndShow(cur, this, font);
1387 case LFUN_FONT_CODE: {
1388 Font font(Font::ALL_IGNORE);
1389 font.setFamily(Font::TYPEWRITER_FAMILY); // no good
1390 toggleAndShow(cur, this, font);
1394 case LFUN_FONT_SANS: {
1395 Font font(Font::ALL_IGNORE);
1396 font.setFamily(Font::SANS_FAMILY);
1397 toggleAndShow(cur, this, font);
1401 case LFUN_FONT_ROMAN: {
1402 Font font(Font::ALL_IGNORE);
1403 font.setFamily(Font::ROMAN_FAMILY);
1404 toggleAndShow(cur, this, font);
1408 case LFUN_FONT_DEFAULT: {
1409 Font font(Font::ALL_INHERIT, ignore_language);
1410 toggleAndShow(cur, this, font);
1414 case LFUN_FONT_UNDERLINE: {
1415 Font font(Font::ALL_IGNORE);
1416 font.setUnderbar(Font::TOGGLE);
1417 toggleAndShow(cur, this, font);
1421 case LFUN_FONT_SIZE: {
1422 Font font(Font::ALL_IGNORE);
1423 font.setLyXSize(to_utf8(cmd.argument()));
1424 toggleAndShow(cur, this, font);
1428 case LFUN_LANGUAGE: {
1429 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1432 Font font(Font::ALL_IGNORE);
1433 font.setLanguage(lang);
1434 toggleAndShow(cur, this, font);
1438 case LFUN_FONT_FREE_APPLY:
1439 toggleAndShow(cur, this, freefont, toggleall);
1440 cur.message(_("Character set"));
1443 // Set the freefont using the contents of \param data dispatched from
1444 // the frontends and apply it at the current cursor location.
1445 case LFUN_FONT_FREE_UPDATE: {
1448 if (bv_funcs::string2font(to_utf8(cmd.argument()), font, toggle)) {
1451 toggleAndShow(cur, this, freefont, toggleall);
1452 cur.message(_("Character set"));
1457 case LFUN_FINISHED_LEFT:
1458 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1459 if (reverseDirectionNeeded(cur))
1463 case LFUN_FINISHED_RIGHT:
1464 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1465 if (!reverseDirectionNeeded(cur))
1469 case LFUN_LAYOUT_PARAGRAPH: {
1471 params2string(cur.paragraph(), data);
1472 data = "show\n" + data;
1473 bv->showDialogWithData("paragraph", data);
1477 case LFUN_PARAGRAPH_UPDATE: {
1479 params2string(cur.paragraph(), data);
1481 // Will the paragraph accept changes from the dialog?
1482 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1484 data = "update " + convert<string>(accept) + '\n' + data;
1485 bv->updateDialog("paragraph", data);
1489 case LFUN_ACCENT_UMLAUT:
1490 case LFUN_ACCENT_CIRCUMFLEX:
1491 case LFUN_ACCENT_GRAVE:
1492 case LFUN_ACCENT_ACUTE:
1493 case LFUN_ACCENT_TILDE:
1494 case LFUN_ACCENT_CEDILLA:
1495 case LFUN_ACCENT_MACRON:
1496 case LFUN_ACCENT_DOT:
1497 case LFUN_ACCENT_UNDERDOT:
1498 case LFUN_ACCENT_UNDERBAR:
1499 case LFUN_ACCENT_CARON:
1500 case LFUN_ACCENT_SPECIAL_CARON:
1501 case LFUN_ACCENT_BREVE:
1502 case LFUN_ACCENT_TIE:
1503 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1504 case LFUN_ACCENT_CIRCLE:
1505 case LFUN_ACCENT_OGONEK:
1506 theLyXFunc().handleKeyFunc(cmd.action);
1507 if (!cmd.argument().empty())
1508 // FIXME: Are all these characters encoded in one byte in utf8?
1509 bv->translateAndInsert(cmd.argument()[0], this, cur);
1512 case LFUN_FLOAT_LIST: {
1513 TextClass const & tclass = bv->buffer()->params().getTextClass();
1514 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1515 // not quite sure if we want this...
1517 cur.clearSelection();
1518 breakParagraph(cur);
1520 if (cur.lastpos() != 0) {
1522 breakParagraph(cur);
1525 setLayout(cur, tclass.defaultLayoutName());
1526 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, docstring(), 0);
1527 insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1530 lyxerr << "Non-existent float type: "
1531 << to_utf8(cmd.argument()) << endl;
1536 case LFUN_CHANGE_ACCEPT: {
1537 acceptOrRejectChanges(cur, ACCEPT);
1541 case LFUN_CHANGE_REJECT: {
1542 acceptOrRejectChanges(cur, REJECT);
1546 case LFUN_THESAURUS_ENTRY: {
1547 docstring arg = cmd.argument();
1549 arg = cur.selectionAsString(false);
1551 if (arg.size() > 100 || arg.empty()) {
1552 // Get word or selection
1553 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1554 arg = cur.selectionAsString(false);
1557 bv->showDialogWithData("thesaurus", to_utf8(arg));
1561 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1562 // Given data, an encoding of the ParagraphParameters
1563 // generated in the Paragraph dialog, this function sets
1564 // the current paragraph appropriately.
1565 istringstream is(to_utf8(cmd.argument()));
1568 ParagraphParameters params;
1573 params.labelWidthString(),
1575 cur.message(_("Paragraph layout set"));
1580 if (cur.selection()) {
1581 cur.selection() = false;
1584 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1589 LYXERR(Debug::ACTION)
1590 << BOOST_CURRENT_FUNCTION
1591 << ": Command " << cmd
1592 << " not DISPATCHED by Text" << endl;
1597 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1599 // FIXME: The cursor flag is reset two lines below
1600 // so we need to check here if some of the LFUN did touch that.
1601 // for now only Text::erase() and Text::backspace() do that.
1602 // The plan is to verify all the LFUNs and then to remove this
1603 // singleParUpdate boolean altogether.
1604 if (cur.result().update() & Update::Force) {
1605 singleParUpdate = false;
1609 // FIXME: the following code should go in favor of fine grained
1610 // update flag treatment.
1611 if (singleParUpdate) {
1612 // Inserting characters does not change par height
1613 ParagraphMetrics const & pms
1614 = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
1615 if (pms.dim().height()
1616 == olddim.height()) {
1617 // if so, update _only_ this paragraph
1618 cur.updateFlags(Update::SinglePar |
1620 Update::MultiParSel);
1627 && &oldTopSlice.inset() == &cur.inset()
1628 && oldTopSlice.idx() == cur.idx()
1629 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1630 && !cur.selection())
1631 // FIXME: it would be better if we could just do this
1633 //if (cur.result().update() != Update::FitCursor)
1636 // But some LFUNs do not set Update::FitCursor when needed, so we
1637 // do it for all. This is not very harmfull as FitCursor will provoke
1638 // a full redraw only if needed but still, a proper review of all LFUN
1639 // should be done and this needsUpdate boolean can then be removed.
1640 cur.updateFlags(Update::FitCursor);
1642 cur.updateFlags(Update::Force | Update::FitCursor);
1646 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
1647 FuncStatus & flag) const
1649 BOOST_ASSERT(cur.text() == this);
1651 Font const & font = real_current_font;
1653 Inset::Code code = Inset::NO_CODE;
1655 switch (cmd.action) {
1657 case LFUN_DEPTH_DECREMENT:
1658 enable = changeDepthAllowed(cur, DEC_DEPTH);
1661 case LFUN_DEPTH_INCREMENT:
1662 enable = changeDepthAllowed(cur, INC_DEPTH);
1666 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1669 case LFUN_BIBITEM_INSERT:
1670 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO
1674 case LFUN_DIALOG_SHOW_NEW_INSET:
1675 if (cmd.argument() == "bibitem")
1676 code = Inset::BIBITEM_CODE;
1677 else if (cmd.argument() == "bibtex")
1678 code = Inset::BIBTEX_CODE;
1679 else if (cmd.argument() == "box")
1680 code = Inset::BOX_CODE;
1681 else if (cmd.argument() == "branch")
1682 code = Inset::BRANCH_CODE;
1683 else if (cmd.argument() == "citation")
1684 code = Inset::CITE_CODE;
1685 else if (cmd.argument() == "ert")
1686 code = Inset::ERT_CODE;
1687 else if (cmd.argument() == "external")
1688 code = Inset::EXTERNAL_CODE;
1689 else if (cmd.argument() == "float")
1690 code = Inset::FLOAT_CODE;
1691 else if (cmd.argument() == "graphics")
1692 code = Inset::GRAPHICS_CODE;
1693 else if (cmd.argument() == "include")
1694 code = Inset::INCLUDE_CODE;
1695 else if (cmd.argument() == "index")
1696 code = Inset::INDEX_CODE;
1697 else if (cmd.argument() == "nomenclature")
1698 code = Inset::NOMENCL_CODE;
1699 else if (cmd.argument() == "label")
1700 code = Inset::LABEL_CODE;
1701 else if (cmd.argument() == "note")
1702 code = Inset::NOTE_CODE;
1703 else if (cmd.argument() == "ref")
1704 code = Inset::REF_CODE;
1705 else if (cmd.argument() == "toc")
1706 code = Inset::TOC_CODE;
1707 else if (cmd.argument() == "url")
1708 code = Inset::URL_CODE;
1709 else if (cmd.argument() == "vspace")
1710 code = Inset::VSPACE_CODE;
1711 else if (cmd.argument() == "wrap")
1712 code = Inset::WRAP_CODE;
1713 else if (cmd.argument() == "listings")
1714 code = Inset::LISTINGS_CODE;
1717 case LFUN_ERT_INSERT:
1718 code = Inset::ERT_CODE;
1720 case LFUN_LISTING_INSERT:
1721 code = Inset::LISTINGS_CODE;
1723 case LFUN_FOOTNOTE_INSERT:
1724 code = Inset::FOOT_CODE;
1726 case LFUN_TABULAR_INSERT:
1727 code = Inset::TABULAR_CODE;
1729 case LFUN_MARGINALNOTE_INSERT:
1730 code = Inset::MARGIN_CODE;
1732 case LFUN_FLOAT_INSERT:
1733 case LFUN_FLOAT_WIDE_INSERT:
1734 code = Inset::FLOAT_CODE;
1736 case LFUN_WRAP_INSERT:
1737 code = Inset::WRAP_CODE;
1739 case LFUN_FLOAT_LIST:
1740 code = Inset::FLOAT_LIST_CODE;
1743 case LFUN_LIST_INSERT:
1744 code = Inset::LIST_CODE;
1746 case LFUN_THEOREM_INSERT:
1747 code = Inset::THEOREM_CODE;
1750 case LFUN_CAPTION_INSERT:
1751 code = Inset::CAPTION_CODE;
1753 case LFUN_NOTE_INSERT:
1754 code = Inset::NOTE_CODE;
1756 case LFUN_CHARSTYLE_INSERT:
1757 code = Inset::CHARSTYLE_CODE;
1758 if (cur.buffer().params().getTextClass().charstyles().empty())
1761 case LFUN_BOX_INSERT:
1762 code = Inset::BOX_CODE;
1764 case LFUN_BRANCH_INSERT:
1765 code = Inset::BRANCH_CODE;
1766 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1769 case LFUN_LABEL_INSERT:
1770 code = Inset::LABEL_CODE;
1772 case LFUN_OPTIONAL_INSERT:
1773 code = Inset::OPTARG_CODE;
1774 enable = numberOfOptArgs(cur.paragraph())
1775 < cur.paragraph().layout()->optionalargs;
1777 case LFUN_ENVIRONMENT_INSERT:
1778 code = Inset::BOX_CODE;
1780 case LFUN_INDEX_INSERT:
1781 code = Inset::INDEX_CODE;
1783 case LFUN_INDEX_PRINT:
1784 code = Inset::INDEX_PRINT_CODE;
1786 case LFUN_NOMENCL_INSERT:
1787 code = Inset::NOMENCL_CODE;
1789 case LFUN_NOMENCL_PRINT:
1790 code = Inset::NOMENCL_PRINT_CODE;
1792 case LFUN_TOC_INSERT:
1793 code = Inset::TOC_CODE;
1795 case LFUN_HTML_INSERT:
1796 case LFUN_URL_INSERT:
1797 code = Inset::URL_CODE;
1799 case LFUN_QUOTE_INSERT:
1800 // always allow this, since we will inset a raw quote
1801 // if an inset is not allowed.
1803 case LFUN_HYPHENATION_POINT_INSERT:
1804 case LFUN_LIGATURE_BREAK_INSERT:
1805 case LFUN_HFILL_INSERT:
1806 case LFUN_MENU_SEPARATOR_INSERT:
1807 case LFUN_DOTS_INSERT:
1808 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
1809 code = Inset::SPECIALCHAR_CODE;
1811 case LFUN_SPACE_INSERT:
1812 // slight hack: we know this is allowed in math mode
1814 code = Inset::SPACE_CODE;
1817 case LFUN_INSET_MODIFY:
1818 // We need to disable this, because we may get called for a
1820 // InsetTabular::getStatus() -> InsetText::getStatus()
1821 // and we don't handle LFUN_INSET_MODIFY.
1825 case LFUN_FONT_EMPH:
1826 flag.setOnOff(font.emph() == Font::ON);
1829 case LFUN_FONT_NOUN:
1830 flag.setOnOff(font.noun() == Font::ON);
1833 case LFUN_FONT_BOLD:
1834 flag.setOnOff(font.series() == Font::BOLD_SERIES);
1837 case LFUN_FONT_SANS:
1838 flag.setOnOff(font.family() == Font::SANS_FAMILY);
1841 case LFUN_FONT_ROMAN:
1842 flag.setOnOff(font.family() == Font::ROMAN_FAMILY);
1845 case LFUN_FONT_CODE:
1846 flag.setOnOff(font.family() == Font::TYPEWRITER_FAMILY);
1851 enable = cur.selection();
1855 if (cmd.argument().empty()) {
1856 if (theClipboard().isInternal())
1857 enable = cap::numberOfSelections() > 0;
1859 enable = !theClipboard().empty();
1861 string const arg = to_utf8(cmd.argument());
1862 if (isStrUnsignedInt(arg)) {
1863 unsigned int n = convert<unsigned int>(arg);
1864 enable = cap::numberOfSelections() > n;
1871 case LFUN_CLIPBOARD_PASTE:
1872 enable = !theClipboard().empty();
1875 case LFUN_PRIMARY_SELECTION_PASTE:
1876 enable = cur.selection() || !theSelection().empty();
1879 case LFUN_PARAGRAPH_MOVE_UP:
1880 enable = cur.pit() > 0 && !cur.selection();
1883 case LFUN_PARAGRAPH_MOVE_DOWN:
1884 enable = cur.pit() < cur.lastpit() && !cur.selection();
1887 case LFUN_INSET_DISSOLVE:
1888 enable = !isMainText(*cur.bv().buffer()) && cur.inset().nargs() == 1;
1891 case LFUN_CHANGE_ACCEPT:
1892 case LFUN_CHANGE_REJECT:
1893 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
1894 // In principle, these LFUNs should only be enabled if there
1895 // is a change at the current position/in the current selection.
1896 // However, without proper optimizations, this will inevitably
1897 // result in unacceptable performance - just imagine a user who
1898 // wants to select the complete content of a long document.
1902 case LFUN_WORD_DELETE_FORWARD:
1903 case LFUN_WORD_DELETE_BACKWARD:
1904 case LFUN_LINE_DELETE:
1905 case LFUN_WORD_FORWARD:
1906 case LFUN_WORD_BACKWARD:
1907 case LFUN_CHAR_FORWARD:
1908 case LFUN_CHAR_FORWARD_SELECT:
1909 case LFUN_CHAR_BACKWARD:
1910 case LFUN_CHAR_BACKWARD_SELECT:
1912 case LFUN_UP_SELECT:
1914 case LFUN_DOWN_SELECT:
1915 case LFUN_PARAGRAPH_UP_SELECT:
1916 case LFUN_PARAGRAPH_DOWN_SELECT:
1917 case LFUN_SCREEN_UP_SELECT:
1918 case LFUN_SCREEN_DOWN_SELECT:
1919 case LFUN_LINE_BEGIN_SELECT:
1920 case LFUN_LINE_END_SELECT:
1921 case LFUN_WORD_FORWARD_SELECT:
1922 case LFUN_WORD_BACKWARD_SELECT:
1923 case LFUN_WORD_SELECT:
1924 case LFUN_PARAGRAPH_UP:
1925 case LFUN_PARAGRAPH_DOWN:
1926 case LFUN_SCREEN_UP:
1927 case LFUN_SCREEN_DOWN:
1928 case LFUN_LINE_BEGIN:
1930 case LFUN_BREAK_LINE:
1931 case LFUN_CHAR_DELETE_FORWARD:
1932 case LFUN_DELETE_FORWARD_SKIP:
1933 case LFUN_CHAR_DELETE_BACKWARD:
1934 case LFUN_DELETE_BACKWARD_SKIP:
1935 case LFUN_BREAK_PARAGRAPH:
1936 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
1937 case LFUN_BREAK_PARAGRAPH_SKIP:
1938 case LFUN_PARAGRAPH_SPACING:
1939 case LFUN_INSET_INSERT:
1940 case LFUN_WORD_UPCASE:
1941 case LFUN_WORD_LOWCASE:
1942 case LFUN_WORD_CAPITALIZE:
1943 case LFUN_CHARS_TRANSPOSE:
1944 case LFUN_SERVER_GET_XY:
1945 case LFUN_SERVER_SET_XY:
1946 case LFUN_SERVER_GET_FONT:
1947 case LFUN_SERVER_GET_LAYOUT:
1949 case LFUN_DATE_INSERT:
1950 case LFUN_SELF_INSERT:
1951 case LFUN_LINE_INSERT:
1952 case LFUN_PAGEBREAK_INSERT:
1953 case LFUN_CLEARPAGE_INSERT:
1954 case LFUN_CLEARDOUBLEPAGE_INSERT:
1955 case LFUN_MATH_DISPLAY:
1956 case LFUN_MATH_IMPORT_SELECTION:
1957 case LFUN_MATH_MODE:
1958 case LFUN_MATH_MACRO:
1959 case LFUN_MATH_MATRIX:
1960 case LFUN_MATH_DELIM:
1961 case LFUN_MATH_BIGDELIM:
1962 case LFUN_MATH_INSERT:
1963 case LFUN_MATH_SUBSCRIPT:
1964 case LFUN_MATH_SUPERSCRIPT:
1965 case LFUN_FONT_DEFAULT:
1966 case LFUN_FONT_UNDERLINE:
1967 case LFUN_FONT_SIZE:
1969 case LFUN_FONT_FREE_APPLY:
1970 case LFUN_FONT_FREE_UPDATE:
1971 case LFUN_LAYOUT_PARAGRAPH:
1972 case LFUN_PARAGRAPH_UPDATE:
1973 case LFUN_ACCENT_UMLAUT:
1974 case LFUN_ACCENT_CIRCUMFLEX:
1975 case LFUN_ACCENT_GRAVE:
1976 case LFUN_ACCENT_ACUTE:
1977 case LFUN_ACCENT_TILDE:
1978 case LFUN_ACCENT_CEDILLA:
1979 case LFUN_ACCENT_MACRON:
1980 case LFUN_ACCENT_DOT:
1981 case LFUN_ACCENT_UNDERDOT:
1982 case LFUN_ACCENT_UNDERBAR:
1983 case LFUN_ACCENT_CARON:
1984 case LFUN_ACCENT_SPECIAL_CARON:
1985 case LFUN_ACCENT_BREVE:
1986 case LFUN_ACCENT_TIE:
1987 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1988 case LFUN_ACCENT_CIRCLE:
1989 case LFUN_ACCENT_OGONEK:
1990 case LFUN_THESAURUS_ENTRY:
1991 case LFUN_PARAGRAPH_PARAMS_APPLY:
1993 case LFUN_BUFFER_END:
1994 case LFUN_BUFFER_BEGIN:
1995 case LFUN_BUFFER_BEGIN_SELECT:
1996 case LFUN_BUFFER_END_SELECT:
1997 case LFUN_UNICODE_INSERT:
1998 // these are handled in our dispatch()
2006 if (code != Inset::NO_CODE
2007 && (cur.empty() || !cur.inset().insetAllowed(code)))
2010 flag.enabled(enable);
2015 void Text::pasteString(Cursor & cur, docstring const & clip,
2018 cur.clearSelection();
2019 if (!clip.empty()) {
2022 insertStringAsParagraphs(cur, clip);
2024 insertStringAsLines(cur, clip);