3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Asger Alstrup
7 * \author Lars Gullik Bjønnes
8 * \author Alfredo Braunstein
9 * \author Angus Leeming
11 * \author André Pönitz
13 * Full author contact details are available in file CREDITS.
20 #include "BranchList.h"
21 #include "FloatList.h"
22 #include "FuncStatus.h"
24 #include "buffer_funcs.h"
25 #include "BufferParams.h"
26 #include "BufferView.h"
27 #include "bufferview_funcs.h"
29 #include "CoordCache.h"
30 #include "CutAndPaste.h"
32 #include "DispatchResult.h"
33 #include "ErrorList.h"
35 #include "FuncRequest.h"
39 #include "LyXAction.h"
44 #include "Paragraph.h"
45 #include "paragraph_funcs.h"
46 #include "ParagraphParameters.h"
49 #include "ParIterator.h"
51 #include "frontends/Clipboard.h"
52 #include "frontends/Selection.h"
54 #include "insets/InsetCommand.h"
55 #include "insets/InsetFloatList.h"
56 #include "insets/InsetNewline.h"
57 #include "insets/InsetQuotes.h"
58 #include "insets/InsetSpecialChar.h"
59 #include "insets/InsetText.h"
61 #include "support/lstrings.h"
62 #include "support/lyxlib.h"
63 #include "support/convert.h"
64 #include "support/lyxtime.h"
66 #include "mathed/InsetMathHull.h"
67 #include "mathed/MathMacroTemplate.h"
69 #include <boost/current_function.hpp>
77 using cap::copySelection;
78 using cap::cutSelection;
79 using cap::pasteFromStack;
80 using cap::pasteClipboard;
81 using cap::replaceSelection;
83 using support::isStrUnsignedInt;
88 using std::istringstream;
89 using std::ostringstream;
92 extern docstring current_layout;
98 Font freefont(Font::ALL_IGNORE);
99 bool toggleall = false;
101 void toggleAndShow(Cursor & cur, Text * text,
102 Font const & font, bool toggleall = true)
104 text->toggleFree(cur, font, toggleall);
106 if (font.language() != ignore_language ||
107 font.number() != Font::IGNORE) {
108 Paragraph & par = cur.paragraph();
109 if (cur.boundary() != text->isRTLBoundary(cur.buffer(), par,
110 cur.pos(), text->real_current_font))
111 text->setCursor(cur, cur.pit(), cur.pos(),
112 false, !cur.boundary());
117 void moveCursor(Cursor & cur, bool selecting)
119 if (selecting || cur.mark())
124 void finishChange(Cursor & cur, bool selecting)
127 moveCursor(cur, selecting);
131 void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
134 docstring sel = cur.selectionAsString(false);
136 // It may happen that sel is empty but there is a selection
137 replaceSelection(cur);
140 #ifdef ENABLE_ASSERTIONS
141 const int old_pos = cur.pos();
143 cur.insert(new InsetMathHull(hullSimple));
144 BOOST_ASSERT(old_pos == cur.pos());
145 cur.nextInset()->edit(cur, true);
146 // don't do that also for LFUN_MATH_MODE
147 // unless you want end up with always changing
148 // to mathrm when opening an inlined inset --
149 // I really hate "LyXfunc overloading"...
151 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
152 // Avoid an unnecessary undo step if cmd.argument
154 if (!cmd.argument().empty())
155 cur.dispatch(FuncRequest(LFUN_MATH_INSERT,
158 // create a macro if we see "\\newcommand"
159 // somewhere, and an ordinary formula
161 if (sel.find(from_ascii("\\newcommand")) == string::npos
162 && sel.find(from_ascii("\\def")) == string::npos)
164 InsetMathHull * formula = new InsetMathHull;
165 istringstream is(to_utf8(sel));
168 formula->read(cur.buffer(), lex);
169 if (formula->getType() == hullNone)
170 // Don't create pseudo formulas if
171 // delimiters are left out
172 formula->mutate(hullSimple);
175 cur.insert(new MathMacroTemplate(sel));
178 cur.message(from_utf8(N_("Math editor mode")));
187 string const freefont2string()
190 if (font2string(freefont, toggleall, data))
197 void Text::cursorPrevious(Cursor & cur)
199 pos_type cpos = cur.pos();
200 pit_type cpar = cur.pit();
202 int x = cur.x_target();
203 setCursorFromCoordinates(cur, x, 0);
204 cur.dispatch(FuncRequest(cur.selection()? LFUN_UP_SELECT: LFUN_UP));
206 if (cpar == cur.pit() && cpos == cur.pos())
207 // we have a row which is taller than the workarea. The
208 // simplest solution is to move to the previous row instead.
209 cur.dispatch(FuncRequest(cur.selection()? LFUN_UP_SELECT: LFUN_UP));
212 cur.updateFlags(Update::Force | Update::FitCursor);
216 void Text::cursorNext(Cursor & cur)
218 pos_type cpos = cur.pos();
219 pit_type cpar = cur.pit();
221 int x = cur.x_target();
222 setCursorFromCoordinates(cur, x, cur.bv().workHeight() - 1);
223 cur.dispatch(FuncRequest(cur.selection()? LFUN_DOWN_SELECT: LFUN_DOWN));
225 if (cpar == cur.pit() && cpos == cur.pos())
226 // we have a row which is taller than the workarea. The
227 // simplest solution is to move to the next row instead.
229 FuncRequest(cur.selection()? LFUN_DOWN_SELECT: LFUN_DOWN));
232 cur.updateFlags(Update::Force | Update::FitCursor);
238 void specialChar(Cursor & cur, InsetSpecialChar::Kind kind)
241 cap::replaceSelection(cur);
242 cur.insert(new InsetSpecialChar(kind));
247 bool doInsertInset(Cursor & cur, Text * text,
248 FuncRequest const & cmd, bool edit, bool pastesel)
250 Inset * inset = createInset(&cur.bv(), cmd);
256 if (cur.selection()) {
257 lyx::dispatch(FuncRequest(LFUN_CUT));
260 text->insertInset(cur, inset);
263 inset->edit(cur, true);
265 if (gotsel && pastesel) {
266 lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
267 // reset first par to default
268 if (cur.lastpit() != 0 || cur.lastpos() != 0) {
269 Layout_ptr const layout =
270 cur.buffer().params().getTextClass().defaultLayout();
271 cur.text()->paragraphs().begin()->layout(layout);
281 void Text::number(Cursor & cur)
283 Font font(Font::ALL_IGNORE);
284 font.setNumber(Font::TOGGLE);
285 toggleAndShow(cur, this, font);
289 bool Text::isRTL(Buffer const & buffer, Paragraph const & par) const
291 return par.isRightToLeftPar(buffer.params());
295 bool Text::isRTL(Buffer const & buffer, CursorSlice const & sl, bool boundary) const
297 if (!lyxrc.rtl_support && !sl.text())
301 if (boundary && sl.pos() > 0)
304 Paragraph const & par = getPar(sl.pit());
305 return getFont(buffer, par, sl.pos() + correction).isVisibleRightToLeft();
309 bool Text::isRTLBoundary(Buffer const & buffer, Paragraph const & par,
312 if (!lyxrc.rtl_support)
315 // no RTL boundary at line start
319 bool left = getFont(buffer, par, pos - 1).isVisibleRightToLeft();
321 if (pos == par.size())
322 right = par.isRightToLeftPar(buffer.params());
324 right = getFont(buffer, par, pos).isVisibleRightToLeft();
325 return left != right;
329 bool Text::isRTLBoundary(Buffer const & buffer, Paragraph const & par,
330 pos_type pos, Font const & font) const
332 if (!lyxrc.rtl_support)
335 bool left = font.isVisibleRightToLeft();
337 if (pos == par.size())
338 right = par.isRightToLeftPar(buffer.params());
340 right = getFont(buffer, par, pos).isVisibleRightToLeft();
341 return left != right;
345 void Text::dispatch(Cursor & cur, FuncRequest & cmd)
347 LYXERR(Debug::ACTION) << "Text::dispatch: cmd: " << cmd << endl;
349 // FIXME: We use the update flag to indicates wether a singlePar or a
350 // full screen update is needed. We reset it here but shall we restore it
354 BOOST_ASSERT(cur.text() == this);
355 BufferView * bv = &cur.bv();
356 CursorSlice oldTopSlice = cur.top();
357 bool oldBoundary = cur.boundary();
358 bool sel = cur.selection();
359 // Signals that, even if needsUpdate == false, an update of the
360 // cursor paragraph is required
361 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
362 LyXAction::SingleParUpdate);
363 // Signals that a full-screen update is required
364 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
365 LyXAction::NoUpdate) || singleParUpdate);
366 // Remember the old paragraph metric (_outer_ paragraph!)
367 ParagraphMetrics const & pm = cur.bv().parMetrics(
368 cur.bottom().text(), cur.bottom().pit());
369 Dimension olddim = pm.dim();
371 switch (cmd.action) {
373 case LFUN_PARAGRAPH_MOVE_DOWN: {
374 pit_type const pit = cur.pit();
375 recUndo(cur, pit, pit + 1);
377 std::swap(pars_[pit], pars_[pit + 1]);
378 updateLabels(cur.buffer());
384 case LFUN_PARAGRAPH_MOVE_UP: {
385 pit_type const pit = cur.pit();
386 recUndo(cur, pit - 1, pit);
388 std::swap(pars_[pit], pars_[pit - 1]);
389 updateLabels(cur.buffer());
395 case LFUN_APPENDIX: {
396 Paragraph & par = cur.paragraph();
397 bool start = !par.params().startOfAppendix();
399 // FIXME: The code below only makes sense at top level.
400 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
401 // ensure that we have only one start_of_appendix in this document
402 // FIXME: this don't work for multipart document!
403 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
404 if (pars_[tmp].params().startOfAppendix()) {
406 pars_[tmp].params().startOfAppendix(false);
412 par.params().startOfAppendix(start);
414 // we can set the refreshing parameters now
415 updateLabels(cur.buffer());
419 case LFUN_WORD_DELETE_FORWARD:
420 if (cur.selection()) {
421 cutSelection(cur, true, false);
423 deleteWordForward(cur);
424 finishChange(cur, false);
427 case LFUN_WORD_DELETE_BACKWARD:
428 if (cur.selection()) {
429 cutSelection(cur, true, false);
431 deleteWordBackward(cur);
432 finishChange(cur, false);
435 case LFUN_LINE_DELETE:
436 if (cur.selection()) {
437 cutSelection(cur, true, false);
439 deleteLineForward(cur);
440 finishChange(cur, false);
443 case LFUN_BUFFER_BEGIN:
444 case LFUN_BUFFER_BEGIN_SELECT:
445 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
446 if (cur.depth() == 1) {
447 needsUpdate |= cursorTop(cur);
453 case LFUN_BUFFER_END:
454 case LFUN_BUFFER_END_SELECT:
455 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
456 if (cur.depth() == 1) {
457 needsUpdate |= cursorBottom(cur);
463 case LFUN_CHAR_FORWARD:
464 case LFUN_CHAR_FORWARD_SELECT:
465 //lyxerr << BOOST_CURRENT_FUNCTION
466 // << " LFUN_CHAR_FORWARD[SEL]:\n" << cur << endl;
467 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
468 if (reverseDirectionNeeded(cur))
469 needsUpdate |= cursorLeft(cur);
471 needsUpdate |= cursorRight(cur);
473 if (!needsUpdate && oldTopSlice == cur.top()
474 && cur.boundary() == oldBoundary) {
476 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
480 case LFUN_CHAR_BACKWARD:
481 case LFUN_CHAR_BACKWARD_SELECT:
482 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
483 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
484 if (reverseDirectionNeeded(cur))
485 needsUpdate |= cursorRight(cur);
487 needsUpdate |= cursorLeft(cur);
489 if (!needsUpdate && oldTopSlice == cur.top()
490 && cur.boundary() == oldBoundary) {
492 cmd = FuncRequest(LFUN_FINISHED_LEFT);
497 case LFUN_DOWN_SELECT:
500 // stop/start the selection
501 bool select = cmd.action == LFUN_DOWN_SELECT ||
502 cmd.action == LFUN_UP_SELECT;
503 cur.selHandle(select);
505 // move cursor up/down
506 bool up = cmd.action == LFUN_UP_SELECT || cmd.action == LFUN_UP;
507 bool const successful = cur.upDownInText(up, needsUpdate);
509 // notify insets which were left and get their update flags
510 notifyCursorLeaves(cur.beforeDispatchCursor(), cur);
513 // redraw if you leave mathed (for the decorations)
514 needsUpdate |= cur.beforeDispatchCursor().inMathed();
521 case LFUN_PARAGRAPH_UP:
522 case LFUN_PARAGRAPH_UP_SELECT:
523 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
524 needsUpdate |= cursorUpParagraph(cur);
527 case LFUN_PARAGRAPH_DOWN:
528 case LFUN_PARAGRAPH_DOWN_SELECT:
529 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
530 needsUpdate |= cursorDownParagraph(cur);
534 case LFUN_SCREEN_UP_SELECT:
535 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_UP_SELECT);
536 if (cur.pit() == 0 && cur.textRow().pos() == 0)
543 case LFUN_SCREEN_DOWN:
544 case LFUN_SCREEN_DOWN_SELECT:
545 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_DOWN_SELECT);
546 if (cur.pit() == cur.lastpit()
547 && cur.textRow().endpos() == cur.lastpos())
554 case LFUN_LINE_BEGIN:
555 case LFUN_LINE_BEGIN_SELECT:
556 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
557 needsUpdate |= cursorHome(cur);
561 case LFUN_LINE_END_SELECT:
562 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
563 needsUpdate |= cursorEnd(cur);
566 case LFUN_WORD_FORWARD:
567 case LFUN_WORD_FORWARD_SELECT:
568 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
569 if (reverseDirectionNeeded(cur))
570 needsUpdate |= cursorLeftOneWord(cur);
572 needsUpdate |= cursorRightOneWord(cur);
575 case LFUN_WORD_BACKWARD:
576 case LFUN_WORD_BACKWARD_SELECT:
577 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
578 if (reverseDirectionNeeded(cur))
579 needsUpdate |= cursorRightOneWord(cur);
581 needsUpdate |= cursorLeftOneWord(cur);
584 case LFUN_WORD_SELECT: {
585 selectWord(cur, WHOLE_WORD);
586 finishChange(cur, true);
590 case LFUN_BREAK_LINE: {
591 // Not allowed by LaTeX (labels or empty par)
592 if (cur.pos() > cur.paragraph().beginOfBody()) {
593 // this avoids a double undo
594 // FIXME: should not be needed, ideally
595 if (!cur.selection())
597 cap::replaceSelection(cur);
598 cur.insert(new InsetNewline);
600 moveCursor(cur, false);
605 case LFUN_CHAR_DELETE_FORWARD:
606 if (!cur.selection()) {
607 if (cur.pos() == cur.paragraph().size())
608 // Par boundary, force full-screen update
609 singleParUpdate = false;
610 needsUpdate |= erase(cur);
612 // It is possible to make it a lot faster still
613 // just comment out the line below...
615 cutSelection(cur, true, false);
616 singleParUpdate = false;
618 moveCursor(cur, false);
621 case LFUN_DELETE_FORWARD_SKIP:
622 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
623 if (!cur.selection()) {
624 if (cur.pos() == cur.lastpos()) {
631 cutSelection(cur, true, false);
636 case LFUN_CHAR_DELETE_BACKWARD:
637 if (!cur.selection()) {
638 if (bv->getIntl().getTransManager().backspace()) {
639 // Par boundary, full-screen update
641 singleParUpdate = false;
642 needsUpdate |= backspace(cur);
644 // It is possible to make it a lot faster still
645 // just comment out the line below...
648 cutSelection(cur, true, false);
649 singleParUpdate = false;
653 case LFUN_DELETE_BACKWARD_SKIP:
654 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
655 if (!cur.selection()) {
657 //CursorSlice cur = cursor();
661 cutSelection(cur, true, false);
665 case LFUN_BREAK_PARAGRAPH:
666 cap::replaceSelection(cur);
667 breakParagraph(cur, 0);
671 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
672 cap::replaceSelection(cur);
673 breakParagraph(cur, 1);
677 case LFUN_BREAK_PARAGRAPH_SKIP: {
678 // When at the beginning of a paragraph, remove
679 // indentation. Otherwise, do the same as LFUN_BREAK_PARAGRAPH.
680 cap::replaceSelection(cur);
682 cur.paragraph().params().labelWidthString(docstring());
684 breakParagraph(cur, 0);
689 case LFUN_PARAGRAPH_SPACING: {
690 Paragraph & par = cur.paragraph();
691 Spacing::Space cur_spacing = par.params().spacing().getSpace();
692 string cur_value = "1.0";
693 if (cur_spacing == Spacing::Other)
694 cur_value = par.params().spacing().getValueAsString();
696 istringstream is(to_utf8(cmd.argument()));
699 Spacing::Space new_spacing = cur_spacing;
700 string new_value = cur_value;
702 lyxerr << "Missing argument to `paragraph-spacing'"
704 } else if (tmp == "single") {
705 new_spacing = Spacing::Single;
706 } else if (tmp == "onehalf") {
707 new_spacing = Spacing::Onehalf;
708 } else if (tmp == "double") {
709 new_spacing = Spacing::Double;
710 } else if (tmp == "other") {
711 new_spacing = Spacing::Other;
712 string tmpval = "0.0";
714 lyxerr << "new_value = " << tmpval << endl;
717 } else if (tmp == "default") {
718 new_spacing = Spacing::Default;
720 lyxerr << to_utf8(_("Unknown spacing argument: "))
721 << to_utf8(cmd.argument()) << endl;
723 if (cur_spacing != new_spacing || cur_value != new_value)
724 par.params().spacing(Spacing(new_spacing, new_value));
728 case LFUN_INSET_INSERT: {
730 Inset * inset = createInset(bv, cmd);
732 // FIXME (Abdel 01/02/2006):
733 // What follows would be a partial fix for bug 2154:
734 // http://bugzilla.lyx.org/show_bug.cgi?id=2154
735 // This automatically put the label inset _after_ a
736 // numbered section. It should be possible to extend the mechanism
737 // to any kind of LateX environement.
738 // The correct way to fix that bug would be at LateX generation.
739 // I'll let the code here for reference as it could be used for some
740 // other feature like "automatic labelling".
742 Paragraph & par = pars_[cur.pit()];
743 if (inset->lyxCode() == Inset::LABEL_CODE
744 && par.layout()->labeltype == LABEL_COUNTER) {
745 // Go to the end of the paragraph
746 // Warning: Because of Change-Tracking, the last
747 // position is 'size()' and not 'size()-1':
748 cur.pos() = par.size();
749 // Insert a new paragraph
750 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
755 cutSelection(cur, true, false);
756 insertInset(cur, inset);
762 case LFUN_INSET_DISSOLVE:
763 needsUpdate |= dissolveInset(cur);
766 case LFUN_INSET_SETTINGS:
767 cur.inset().showInsetDialog(bv);
770 case LFUN_SPACE_INSERT:
771 if (cur.paragraph().layout()->free_spacing)
772 insertChar(cur, ' ');
774 doInsertInset(cur, this, cmd, false, false);
777 moveCursor(cur, false);
780 case LFUN_HYPHENATION_POINT_INSERT:
781 specialChar(cur, InsetSpecialChar::HYPHENATION);
784 case LFUN_LIGATURE_BREAK_INSERT:
785 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
788 case LFUN_DOTS_INSERT:
789 specialChar(cur, InsetSpecialChar::LDOTS);
792 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
793 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
796 case LFUN_MENU_SEPARATOR_INSERT:
797 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
800 case LFUN_WORD_UPCASE:
801 changeCase(cur, Text::text_uppercase);
804 case LFUN_WORD_LOWCASE:
805 changeCase(cur, Text::text_lowercase);
808 case LFUN_WORD_CAPITALIZE:
809 changeCase(cur, Text::text_capitalization);
812 case LFUN_CHARS_TRANSPOSE:
817 cur.message(_("Paste"));
818 cap::replaceSelection(cur);
819 if (cmd.argument().empty() && !theClipboard().isInternal())
820 pasteClipboard(cur, bv->buffer()->errorList("Paste"));
822 string const arg(to_utf8(cmd.argument()));
823 pasteFromStack(cur, bv->buffer()->errorList("Paste"),
824 isStrUnsignedInt(arg) ?
825 convert<unsigned int>(arg) :
828 bv->buffer()->errors("Paste");
829 cur.clearSelection(); // bug 393
834 cutSelection(cur, true, true);
835 cur.message(_("Cut"));
840 cur.message(_("Copy"));
843 case LFUN_SERVER_GET_XY:
844 cur.message(from_utf8(
845 convert<string>(cursorX(cur.bv(), cur.top(), cur.boundary()))
846 + ' ' + convert<string>(cursorY(cur.bv(), cur.top(), cur.boundary()))));
849 case LFUN_SERVER_SET_XY: {
852 istringstream is(to_utf8(cmd.argument()));
855 lyxerr << "SETXY: Could not parse coordinates in '"
856 << to_utf8(cmd.argument()) << std::endl;
858 setCursorFromCoordinates(cur, x, y);
862 case LFUN_SERVER_GET_FONT:
863 if (current_font.shape() == Font::ITALIC_SHAPE)
864 cur.message(from_ascii("E"));
865 else if (current_font.shape() == Font::SMALLCAPS_SHAPE)
866 cur.message(from_ascii("N"));
868 cur.message(from_ascii("0"));
871 case LFUN_SERVER_GET_LAYOUT:
872 cur.message(cur.paragraph().layout()->name());
876 docstring layout = cmd.argument();
877 LYXERR(Debug::INFO) << "LFUN_LAYOUT: (arg) " << to_utf8(layout) << endl;
879 // Derive layout number from given argument (string)
880 // and current buffer's textclass (number)
881 TextClass const & tclass = bv->buffer()->params().getTextClass();
883 layout = tclass.defaultLayoutName();
884 bool hasLayout = tclass.hasLayout(layout);
886 // If the entry is obsolete, use the new one instead.
888 docstring const & obs = tclass[layout]->obsoleted_by();
894 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
895 from_utf8(N_(" not known")));
899 bool change_layout = (current_layout != layout);
901 if (!change_layout && cur.selection() &&
902 cur.selBegin().pit() != cur.selEnd().pit())
904 pit_type spit = cur.selBegin().pit();
905 pit_type epit = cur.selEnd().pit() + 1;
906 while (spit != epit) {
907 if (pars_[spit].layout()->name() != current_layout) {
908 change_layout = true;
916 setLayout(cur, layout);
917 // inform the GUI that the layout has changed.
918 bv->layoutChanged(layout);
923 case LFUN_CLIPBOARD_PASTE:
924 cur.clearSelection();
925 pasteClipboard(cur, bv->buffer()->errorList("Paste"),
926 cmd.argument() == "paragraph");
927 bv->buffer()->errors("Paste");
930 case LFUN_PRIMARY_SELECTION_PASTE:
931 pasteString(cur, theSelection().get(),
932 cmd.argument() == "paragraph");
935 case LFUN_UNICODE_INSERT: {
936 if (cmd.argument().empty())
938 docstring hexstring = cmd.argument();
939 if (lyx::support::isHex(hexstring)) {
940 char_type c = lyx::support::hexToInt(hexstring);
941 if (c >= 32 && c < 0x10ffff) {
942 lyxerr << "Inserting c: " << c << endl;
943 docstring s = docstring(1, c);
944 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
950 case LFUN_QUOTE_INSERT: {
951 Paragraph & par = cur.paragraph();
952 pos_type pos = cur.pos();
953 BufferParams const & bufparams = bv->buffer()->params();
954 Layout_ptr const & style = par.layout();
955 if (!style->pass_thru
956 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
957 // this avoids a double undo
958 // FIXME: should not be needed, ideally
959 if (!cur.selection())
961 cap::replaceSelection(cur);
966 else if (cur.prevInset() && cur.prevInset()->isSpace())
969 c = par.getChar(pos - 1);
970 string arg = to_utf8(cmd.argument());
972 cur.insert(new InsetQuotes(c,
973 bufparams.quotes_language,
974 InsetQuotes::SingleQ));
976 cur.insert(new InsetQuotes(c,
977 bufparams.quotes_language,
978 InsetQuotes::DoubleQ));
982 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
986 case LFUN_DATE_INSERT: {
987 string const format = cmd.argument().empty()
988 ? lyxrc.date_insert_format : to_utf8(cmd.argument());
989 string const time = formatted_time(current_time(), format);
990 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, time));
994 case LFUN_MOUSE_TRIPLE:
995 if (cmd.button() == mouse_button::button1) {
1004 case LFUN_MOUSE_DOUBLE:
1005 if (cmd.button() == mouse_button::button1) {
1006 selectWord(cur, WHOLE_WORD_STRICT);
1011 // Single-click on work area
1012 case LFUN_MOUSE_PRESS: {
1013 // Right click on a footnote flag opens float menu
1014 if (cmd.button() == mouse_button::button3)
1015 cur.clearSelection();
1018 bool update = bv->mouseSetCursor(cur);
1020 // Insert primary selection with middle mouse
1021 // if there is a local selection in the current buffer,
1023 if (cmd.button() == mouse_button::button2) {
1024 if (cap::selection()) {
1025 // Copy the selection buffer to the clipboard
1026 // stack, because we want it to appear in the
1027 // "Edit->Paste recent" menu.
1028 cap::copySelectionToStack();
1030 cap::pasteSelection(bv->cursor(),
1031 bv->buffer()->errorList("Paste"));
1032 bv->buffer()->errors("Paste");
1033 bv->buffer()->markDirty();
1036 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
1040 // we have to update after dEPM triggered
1041 if (!update && cmd.button() == mouse_button::button1) {
1042 needsUpdate = false;
1049 case LFUN_MOUSE_MOTION: {
1050 // Only use motion with button 1
1051 //if (cmd.button() != mouse_button::button1)
1054 // ignore motions deeper nested than the real anchor
1055 Cursor & bvcur = cur.bv().cursor();
1056 if (bvcur.anchor_.hasPart(cur)) {
1057 CursorSlice old = bvcur.top();
1059 int const wh = bv->workHeight();
1060 int const y = std::max(0, std::min(wh - 1, cmd.y));
1062 setCursorFromCoordinates(cur, cmd.x, y);
1063 cur.setTargetX(cmd.x);
1065 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1067 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1068 // This is to allow jumping over large insets
1069 if (cur.top() == old) {
1071 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1073 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1076 if (cur.top() == old)
1079 // don't set anchor_
1080 bvcur.setCursor(cur);
1081 bvcur.selection() = true;
1082 //lyxerr << "MOTION: " << bv->cursor() << endl;
1090 case LFUN_MOUSE_RELEASE: {
1091 if (cmd.button() == mouse_button::button2)
1094 if (cmd.button() == mouse_button::button1) {
1095 // if there is new selection, update persistent
1096 // selection, otherwise, single click does not
1097 // clear persistent selection buffer
1098 if (cur.selection()) {
1100 // if double click, cur is moved to the end of word by selectWord
1101 // but bvcur is current mouse position
1102 Cursor & bvcur = cur.bv().cursor();
1103 bvcur.selection() = true;
1105 needsUpdate = false;
1112 case LFUN_SELF_INSERT: {
1113 if (cmd.argument().empty())
1116 // Automatically delete the currently selected
1117 // text and replace it with what is being
1118 // typed in now. Depends on lyxrc settings
1119 // "auto_region_delete", which defaults to
1122 if (lyxrc.auto_region_delete && cur.selection()) {
1123 cutSelection(cur, false, false);
1124 // When change tracking is set to off, the metrics update
1125 // mechanism correctly detects if a full update is needed or not.
1126 // This detection fails when a selection spans multiple rows and
1127 // change tracking is enabled because the paragraph metrics stays
1128 // the same. In this case, we force the full update:
1129 // (see http://bugzilla.lyx.org/show_bug.cgi?id=3992)
1130 if (cur.buffer().params().trackChanges)
1131 cur.updateFlags(Update::Force);
1134 cur.clearSelection();
1135 Font const old_font = real_current_font;
1137 docstring::const_iterator cit = cmd.argument().begin();
1138 docstring::const_iterator end = cmd.argument().end();
1139 for (; cit != end; ++cit)
1140 bv->translateAndInsert(*cit, this, cur);
1143 moveCursor(cur, false);
1147 case LFUN_URL_INSERT: {
1148 InsetCommandParams p("url");
1150 if (cur.selection()) {
1151 content = cur.selectionAsString(false);
1152 cutSelection(cur, true, false);
1154 p["target"] = (cmd.argument().empty()) ?
1155 content : cmd.argument();
1156 string const data = InsetCommandMailer::params2string("url", p);
1157 if (p["target"].empty()) {
1158 bv->showInsetDialog("url", data, 0);
1160 FuncRequest fr(LFUN_INSET_INSERT, data);
1166 case LFUN_HTML_INSERT: {
1167 InsetCommandParams p("htmlurl");
1169 if (cur.selection()) {
1170 content = cur.selectionAsString(false);
1171 cutSelection(cur, true, false);
1173 p["target"] = (cmd.argument().empty()) ?
1174 content : cmd.argument();
1175 string const data = InsetCommandMailer::params2string("url", p);
1176 if (p["target"].empty()) {
1177 bv->showInsetDialog("url", data, 0);
1179 FuncRequest fr(LFUN_INSET_INSERT, data);
1185 case LFUN_LABEL_INSERT: {
1186 InsetCommandParams p("label");
1187 // Try to generate a valid label
1188 p["name"] = (cmd.argument().empty()) ?
1189 cur.getPossibleLabel() :
1191 string const data = InsetCommandMailer::params2string("label", p);
1193 if (cmd.argument().empty()) {
1194 bv->showInsetDialog("label", data, 0);
1196 FuncRequest fr(LFUN_INSET_INSERT, data);
1204 case LFUN_LIST_INSERT:
1205 case LFUN_THEOREM_INSERT:
1207 case LFUN_CAPTION_INSERT:
1208 // Open the inset, and move the current selection
1210 doInsertInset(cur, this, cmd, true, true);
1212 updateLabels(*bv->buffer());
1214 case LFUN_NOTE_INSERT:
1215 case LFUN_CHARSTYLE_INSERT:
1216 case LFUN_BOX_INSERT:
1217 case LFUN_BRANCH_INSERT:
1218 case LFUN_BIBITEM_INSERT:
1219 case LFUN_ERT_INSERT:
1220 case LFUN_LISTING_INSERT:
1221 case LFUN_FOOTNOTE_INSERT:
1222 case LFUN_MARGINALNOTE_INSERT:
1223 case LFUN_OPTIONAL_INSERT:
1224 case LFUN_ENVIRONMENT_INSERT:
1225 // Open the inset, and move the current selection
1227 doInsertInset(cur, this, cmd, true, true);
1231 case LFUN_TABULAR_INSERT:
1232 // if there were no arguments, just open the dialog
1233 if (doInsertInset(cur, this, cmd, false, true))
1236 bv->showDialog("tabularcreate");
1240 case LFUN_FLOAT_INSERT:
1241 case LFUN_FLOAT_WIDE_INSERT:
1242 case LFUN_WRAP_INSERT: {
1243 bool content = cur.selection(); // will some text be moved into the inset?
1245 doInsertInset(cur, this, cmd, true, true);
1247 ParagraphList & pars = cur.text()->paragraphs();
1249 TextClass const & tclass = bv->buffer()->params().getTextClass();
1251 // add a separate paragraph for the caption inset
1252 pars.push_back(Paragraph());
1253 pars.back().setInsetOwner(pars[0].inInset());
1254 pars.back().layout(tclass.defaultLayout());
1256 int cap_pit = pars.size() - 1;
1258 // if an empty inset was created, we create an additional empty
1259 // paragraph at the bottom so that the user can choose where to put
1260 // the graphics (or table).
1262 pars.push_back(Paragraph());
1263 pars.back().setInsetOwner(pars[0].inInset());
1264 pars.back().layout(tclass.defaultLayout());
1268 // reposition the cursor to the caption
1269 cur.pit() = cap_pit;
1271 cur.dispatch(FuncRequest(LFUN_CAPTION_INSERT));
1272 // FIXME: When leaving the Float (or Wrap) inset we should
1273 // delete any empty paragraph left above or below the
1278 case LFUN_INDEX_INSERT:
1279 case LFUN_NOMENCL_INSERT: {
1280 Inset * inset = createInset(&cur.bv(), cmd);
1284 cur.clearSelection();
1285 insertInset(cur, inset);
1286 inset->edit(cur, true);
1287 // Show the dialog for the nomenclature entry, since the
1288 // description entry still needs to be filled in.
1289 if (cmd.action == LFUN_NOMENCL_INSERT)
1290 InsetCommandMailer("nomenclature",
1291 *reinterpret_cast<InsetCommand *>(inset)).showDialog(&cur.bv());
1296 case LFUN_INDEX_PRINT:
1297 case LFUN_NOMENCL_PRINT:
1298 case LFUN_TOC_INSERT:
1299 case LFUN_HFILL_INSERT:
1300 case LFUN_LINE_INSERT:
1301 case LFUN_PAGEBREAK_INSERT:
1302 case LFUN_CLEARPAGE_INSERT:
1303 case LFUN_CLEARDOUBLEPAGE_INSERT:
1305 doInsertInset(cur, this, cmd, false, false);
1309 case LFUN_DEPTH_DECREMENT:
1310 changeDepth(cur, DEC_DEPTH);
1313 case LFUN_DEPTH_INCREMENT:
1314 changeDepth(cur, INC_DEPTH);
1317 case LFUN_MATH_DISPLAY:
1318 mathDispatch(cur, cmd, true);
1321 case LFUN_MATH_IMPORT_SELECTION:
1322 case LFUN_MATH_MODE:
1323 if (cmd.argument() == "on")
1324 // don't pass "on" as argument
1325 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1327 mathDispatch(cur, cmd, false);
1330 case LFUN_MATH_MACRO:
1331 if (cmd.argument().empty())
1332 cur.errorMessage(from_utf8(N_("Missing argument")));
1334 string s = to_utf8(cmd.argument());
1335 string const s1 = token(s, ' ', 1);
1336 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1337 string const s2 = token(s, ' ', 2);
1338 string const type = s2.empty() ? "newcommand" : s2;
1339 cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, from_utf8(type)));
1340 //cur.nextInset()->edit(cur, true);
1344 // passthrough hat and underscore outside mathed:
1345 case LFUN_MATH_SUBSCRIPT:
1346 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1348 case LFUN_MATH_SUPERSCRIPT:
1349 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1352 case LFUN_MATH_INSERT:
1353 case LFUN_MATH_MATRIX:
1354 case LFUN_MATH_DELIM:
1355 case LFUN_MATH_BIGDELIM: {
1356 if (cur.selection())
1357 cur.clearSelection();
1358 // FIXME: instead of the above, this one
1359 // should be used (but it asserts with Bidi enabled)
1360 // cf. http://bugzilla.lyx.org/show_bug.cgi?id=4055
1361 // cap::replaceSelection(cur);
1362 cur.insert(new InsetMathHull(hullSimple));
1363 checkAndActivateInset(cur, true);
1364 BOOST_ASSERT(cur.inMathed());
1369 case LFUN_FONT_EMPH: {
1370 Font font(Font::ALL_IGNORE);
1371 font.setEmph(Font::TOGGLE);
1372 toggleAndShow(cur, this, font);
1376 case LFUN_FONT_BOLD: {
1377 Font font(Font::ALL_IGNORE);
1378 font.setSeries(Font::BOLD_SERIES);
1379 toggleAndShow(cur, this, font);
1383 case LFUN_FONT_NOUN: {
1384 Font font(Font::ALL_IGNORE);
1385 font.setNoun(Font::TOGGLE);
1386 toggleAndShow(cur, this, font);
1390 case LFUN_FONT_CODE: {
1391 Font font(Font::ALL_IGNORE);
1392 font.setFamily(Font::TYPEWRITER_FAMILY); // no good
1393 toggleAndShow(cur, this, font);
1397 case LFUN_FONT_SANS: {
1398 Font font(Font::ALL_IGNORE);
1399 font.setFamily(Font::SANS_FAMILY);
1400 toggleAndShow(cur, this, font);
1404 case LFUN_FONT_ROMAN: {
1405 Font font(Font::ALL_IGNORE);
1406 font.setFamily(Font::ROMAN_FAMILY);
1407 toggleAndShow(cur, this, font);
1411 case LFUN_FONT_DEFAULT: {
1412 Font font(Font::ALL_INHERIT, ignore_language);
1413 toggleAndShow(cur, this, font);
1417 case LFUN_FONT_UNDERLINE: {
1418 Font font(Font::ALL_IGNORE);
1419 font.setUnderbar(Font::TOGGLE);
1420 toggleAndShow(cur, this, font);
1424 case LFUN_FONT_SIZE: {
1425 Font font(Font::ALL_IGNORE);
1426 font.setLyXSize(to_utf8(cmd.argument()));
1427 toggleAndShow(cur, this, font);
1431 case LFUN_LANGUAGE: {
1432 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1435 Font font(Font::ALL_IGNORE);
1436 font.setLanguage(lang);
1437 toggleAndShow(cur, this, font);
1441 case LFUN_FONT_FREE_APPLY:
1442 toggleAndShow(cur, this, freefont, toggleall);
1443 cur.message(_("Character set"));
1446 // Set the freefont using the contents of \param data dispatched from
1447 // the frontends and apply it at the current cursor location.
1448 case LFUN_FONT_FREE_UPDATE: {
1451 if (bv_funcs::string2font(to_utf8(cmd.argument()), font, toggle)) {
1454 toggleAndShow(cur, this, freefont, toggleall);
1455 cur.message(_("Character set"));
1460 case LFUN_FINISHED_LEFT:
1461 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1462 if (reverseDirectionNeeded(cur))
1466 case LFUN_FINISHED_RIGHT:
1467 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1468 if (!reverseDirectionNeeded(cur))
1472 case LFUN_LAYOUT_PARAGRAPH: {
1474 params2string(cur.paragraph(), data);
1475 data = "show\n" + data;
1476 bv->showDialogWithData("paragraph", data);
1480 case LFUN_PARAGRAPH_UPDATE: {
1482 params2string(cur.paragraph(), data);
1484 // Will the paragraph accept changes from the dialog?
1485 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1487 data = "update " + convert<string>(accept) + '\n' + data;
1488 bv->updateDialog("paragraph", data);
1492 case LFUN_ACCENT_UMLAUT:
1493 case LFUN_ACCENT_CIRCUMFLEX:
1494 case LFUN_ACCENT_GRAVE:
1495 case LFUN_ACCENT_ACUTE:
1496 case LFUN_ACCENT_TILDE:
1497 case LFUN_ACCENT_CEDILLA:
1498 case LFUN_ACCENT_MACRON:
1499 case LFUN_ACCENT_DOT:
1500 case LFUN_ACCENT_UNDERDOT:
1501 case LFUN_ACCENT_UNDERBAR:
1502 case LFUN_ACCENT_CARON:
1503 case LFUN_ACCENT_SPECIAL_CARON:
1504 case LFUN_ACCENT_BREVE:
1505 case LFUN_ACCENT_TIE:
1506 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1507 case LFUN_ACCENT_CIRCLE:
1508 case LFUN_ACCENT_OGONEK:
1509 theLyXFunc().handleKeyFunc(cmd.action);
1510 if (!cmd.argument().empty())
1511 // FIXME: Are all these characters encoded in one byte in utf8?
1512 bv->translateAndInsert(cmd.argument()[0], this, cur);
1515 case LFUN_FLOAT_LIST: {
1516 TextClass const & tclass = bv->buffer()->params().getTextClass();
1517 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1519 if (cur.selection())
1520 cutSelection(cur, true, false);
1521 breakParagraph(cur);
1523 if (cur.lastpos() != 0) {
1525 breakParagraph(cur);
1528 setLayout(cur, tclass.defaultLayoutName());
1529 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, docstring(), 0);
1530 insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1533 lyxerr << "Non-existent float type: "
1534 << to_utf8(cmd.argument()) << endl;
1539 case LFUN_CHANGE_ACCEPT: {
1540 acceptOrRejectChanges(cur, ACCEPT);
1544 case LFUN_CHANGE_REJECT: {
1545 acceptOrRejectChanges(cur, REJECT);
1549 case LFUN_THESAURUS_ENTRY: {
1550 docstring arg = cmd.argument();
1552 arg = cur.selectionAsString(false);
1554 if (arg.size() > 100 || arg.empty()) {
1555 // Get word or selection
1556 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1557 arg = cur.selectionAsString(false);
1560 bv->showDialogWithData("thesaurus", to_utf8(arg));
1564 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1565 // Given data, an encoding of the ParagraphParameters
1566 // generated in the Paragraph dialog, this function sets
1567 // the current paragraph appropriately.
1568 istringstream is(to_utf8(cmd.argument()));
1571 ParagraphParameters params;
1576 params.labelWidthString(),
1578 cur.message(_("Paragraph layout set"));
1583 if (cur.selection()) {
1584 cur.selection() = false;
1587 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1592 LYXERR(Debug::ACTION)
1593 << BOOST_CURRENT_FUNCTION
1594 << ": Command " << cmd
1595 << " not DISPATCHED by Text" << endl;
1600 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1602 // FIXME: The cursor flag is reset two lines below
1603 // so we need to check here if some of the LFUN did touch that.
1604 // for now only Text::erase() and Text::backspace() do that.
1605 // The plan is to verify all the LFUNs and then to remove this
1606 // singleParUpdate boolean altogether.
1607 if (cur.result().update() & Update::Force) {
1608 singleParUpdate = false;
1612 // FIXME: the following code should go in favor of fine grained
1613 // update flag treatment.
1614 if (singleParUpdate) {
1615 // Inserting characters does not change par height
1616 ParagraphMetrics const & pms
1617 = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
1618 if (pms.dim().height()
1619 == olddim.height()) {
1620 // if so, update _only_ this paragraph
1621 cur.updateFlags(Update::SinglePar |
1623 Update::MultiParSel);
1630 && &oldTopSlice.inset() == &cur.inset()
1631 && oldTopSlice.idx() == cur.idx()
1632 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1633 && !cur.selection())
1634 // FIXME: it would be better if we could just do this
1636 //if (cur.result().update() != Update::FitCursor)
1639 // But some LFUNs do not set Update::FitCursor when needed, so we
1640 // do it for all. This is not very harmfull as FitCursor will provoke
1641 // a full redraw only if needed but still, a proper review of all LFUN
1642 // should be done and this needsUpdate boolean can then be removed.
1643 cur.updateFlags(Update::FitCursor);
1645 cur.updateFlags(Update::Force | Update::FitCursor);
1649 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
1650 FuncStatus & flag) const
1652 BOOST_ASSERT(cur.text() == this);
1654 Font const & font = real_current_font;
1656 Inset::Code code = Inset::NO_CODE;
1658 switch (cmd.action) {
1660 case LFUN_DEPTH_DECREMENT:
1661 enable = changeDepthAllowed(cur, DEC_DEPTH);
1664 case LFUN_DEPTH_INCREMENT:
1665 enable = changeDepthAllowed(cur, INC_DEPTH);
1669 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1672 case LFUN_BIBITEM_INSERT:
1673 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO
1677 case LFUN_DIALOG_SHOW_NEW_INSET:
1678 if (cmd.argument() == "bibitem")
1679 code = Inset::BIBITEM_CODE;
1680 else if (cmd.argument() == "bibtex")
1681 code = Inset::BIBTEX_CODE;
1682 else if (cmd.argument() == "box")
1683 code = Inset::BOX_CODE;
1684 else if (cmd.argument() == "branch")
1685 code = Inset::BRANCH_CODE;
1686 else if (cmd.argument() == "citation")
1687 code = Inset::CITE_CODE;
1688 else if (cmd.argument() == "ert")
1689 code = Inset::ERT_CODE;
1690 else if (cmd.argument() == "external")
1691 code = Inset::EXTERNAL_CODE;
1692 else if (cmd.argument() == "float")
1693 code = Inset::FLOAT_CODE;
1694 else if (cmd.argument() == "graphics")
1695 code = Inset::GRAPHICS_CODE;
1696 else if (cmd.argument() == "include")
1697 code = Inset::INCLUDE_CODE;
1698 else if (cmd.argument() == "index")
1699 code = Inset::INDEX_CODE;
1700 else if (cmd.argument() == "nomenclature")
1701 code = Inset::NOMENCL_CODE;
1702 else if (cmd.argument() == "label")
1703 code = Inset::LABEL_CODE;
1704 else if (cmd.argument() == "note")
1705 code = Inset::NOTE_CODE;
1706 else if (cmd.argument() == "ref")
1707 code = Inset::REF_CODE;
1708 else if (cmd.argument() == "toc")
1709 code = Inset::TOC_CODE;
1710 else if (cmd.argument() == "url")
1711 code = Inset::URL_CODE;
1712 else if (cmd.argument() == "vspace")
1713 code = Inset::VSPACE_CODE;
1714 else if (cmd.argument() == "wrap")
1715 code = Inset::WRAP_CODE;
1716 else if (cmd.argument() == "listings")
1717 code = Inset::LISTINGS_CODE;
1720 case LFUN_ERT_INSERT:
1721 code = Inset::ERT_CODE;
1723 case LFUN_LISTING_INSERT:
1724 code = Inset::LISTINGS_CODE;
1726 case LFUN_FOOTNOTE_INSERT:
1727 code = Inset::FOOT_CODE;
1729 case LFUN_TABULAR_INSERT:
1730 code = Inset::TABULAR_CODE;
1732 case LFUN_MARGINALNOTE_INSERT:
1733 code = Inset::MARGIN_CODE;
1735 case LFUN_FLOAT_INSERT:
1736 case LFUN_FLOAT_WIDE_INSERT:
1737 code = Inset::FLOAT_CODE;
1739 case LFUN_WRAP_INSERT:
1740 code = Inset::WRAP_CODE;
1742 case LFUN_FLOAT_LIST:
1743 code = Inset::FLOAT_LIST_CODE;
1746 case LFUN_LIST_INSERT:
1747 code = Inset::LIST_CODE;
1749 case LFUN_THEOREM_INSERT:
1750 code = Inset::THEOREM_CODE;
1753 case LFUN_CAPTION_INSERT:
1754 code = Inset::CAPTION_CODE;
1756 case LFUN_NOTE_INSERT:
1757 code = Inset::NOTE_CODE;
1759 case LFUN_CHARSTYLE_INSERT:
1760 code = Inset::CHARSTYLE_CODE;
1761 if (cur.buffer().params().getTextClass().charstyles().empty())
1764 case LFUN_BOX_INSERT:
1765 code = Inset::BOX_CODE;
1767 case LFUN_BRANCH_INSERT:
1768 code = Inset::BRANCH_CODE;
1769 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1772 case LFUN_LABEL_INSERT:
1773 code = Inset::LABEL_CODE;
1775 case LFUN_OPTIONAL_INSERT:
1776 code = Inset::OPTARG_CODE;
1777 enable = numberOfOptArgs(cur.paragraph())
1778 < cur.paragraph().layout()->optionalargs;
1780 case LFUN_ENVIRONMENT_INSERT:
1781 code = Inset::BOX_CODE;
1783 case LFUN_INDEX_INSERT:
1784 code = Inset::INDEX_CODE;
1786 case LFUN_INDEX_PRINT:
1787 code = Inset::INDEX_PRINT_CODE;
1789 case LFUN_NOMENCL_INSERT:
1790 code = Inset::NOMENCL_CODE;
1792 case LFUN_NOMENCL_PRINT:
1793 code = Inset::NOMENCL_PRINT_CODE;
1795 case LFUN_TOC_INSERT:
1796 code = Inset::TOC_CODE;
1798 case LFUN_HTML_INSERT:
1799 case LFUN_URL_INSERT:
1800 code = Inset::URL_CODE;
1802 case LFUN_QUOTE_INSERT:
1803 // always allow this, since we will inset a raw quote
1804 // if an inset is not allowed.
1806 case LFUN_HYPHENATION_POINT_INSERT:
1807 case LFUN_LIGATURE_BREAK_INSERT:
1808 case LFUN_HFILL_INSERT:
1809 case LFUN_MENU_SEPARATOR_INSERT:
1810 case LFUN_DOTS_INSERT:
1811 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
1812 code = Inset::SPECIALCHAR_CODE;
1814 case LFUN_SPACE_INSERT:
1815 // slight hack: we know this is allowed in math mode
1817 code = Inset::SPACE_CODE;
1820 case LFUN_INSET_MODIFY:
1821 // We need to disable this, because we may get called for a
1823 // InsetTabular::getStatus() -> InsetText::getStatus()
1824 // and we don't handle LFUN_INSET_MODIFY.
1828 case LFUN_FONT_EMPH:
1829 flag.setOnOff(font.emph() == Font::ON);
1832 case LFUN_FONT_NOUN:
1833 flag.setOnOff(font.noun() == Font::ON);
1836 case LFUN_FONT_BOLD:
1837 flag.setOnOff(font.series() == Font::BOLD_SERIES);
1840 case LFUN_FONT_SANS:
1841 flag.setOnOff(font.family() == Font::SANS_FAMILY);
1844 case LFUN_FONT_ROMAN:
1845 flag.setOnOff(font.family() == Font::ROMAN_FAMILY);
1848 case LFUN_FONT_CODE:
1849 flag.setOnOff(font.family() == Font::TYPEWRITER_FAMILY);
1854 enable = cur.selection();
1858 if (cmd.argument().empty()) {
1859 if (theClipboard().isInternal())
1860 enable = cap::numberOfSelections() > 0;
1862 enable = !theClipboard().empty();
1864 string const arg = to_utf8(cmd.argument());
1865 if (isStrUnsignedInt(arg)) {
1866 unsigned int n = convert<unsigned int>(arg);
1867 enable = cap::numberOfSelections() > n;
1874 case LFUN_CLIPBOARD_PASTE:
1875 enable = !theClipboard().empty();
1878 case LFUN_PRIMARY_SELECTION_PASTE:
1879 enable = cur.selection() || !theSelection().empty();
1882 case LFUN_PARAGRAPH_MOVE_UP:
1883 enable = cur.pit() > 0 && !cur.selection();
1886 case LFUN_PARAGRAPH_MOVE_DOWN:
1887 enable = cur.pit() < cur.lastpit() && !cur.selection();
1890 case LFUN_INSET_DISSOLVE:
1891 enable = !isMainText(*cur.bv().buffer()) && cur.inset().nargs() == 1;
1894 case LFUN_CHANGE_ACCEPT:
1895 case LFUN_CHANGE_REJECT:
1896 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
1897 // In principle, these LFUNs should only be enabled if there
1898 // is a change at the current position/in the current selection.
1899 // However, without proper optimizations, this will inevitably
1900 // result in unacceptable performance - just imagine a user who
1901 // wants to select the complete content of a long document.
1905 case LFUN_WORD_DELETE_FORWARD:
1906 case LFUN_WORD_DELETE_BACKWARD:
1907 case LFUN_LINE_DELETE:
1908 case LFUN_WORD_FORWARD:
1909 case LFUN_WORD_BACKWARD:
1910 case LFUN_CHAR_FORWARD:
1911 case LFUN_CHAR_FORWARD_SELECT:
1912 case LFUN_CHAR_BACKWARD:
1913 case LFUN_CHAR_BACKWARD_SELECT:
1915 case LFUN_UP_SELECT:
1917 case LFUN_DOWN_SELECT:
1918 case LFUN_PARAGRAPH_UP_SELECT:
1919 case LFUN_PARAGRAPH_DOWN_SELECT:
1920 case LFUN_SCREEN_UP_SELECT:
1921 case LFUN_SCREEN_DOWN_SELECT:
1922 case LFUN_LINE_BEGIN_SELECT:
1923 case LFUN_LINE_END_SELECT:
1924 case LFUN_WORD_FORWARD_SELECT:
1925 case LFUN_WORD_BACKWARD_SELECT:
1926 case LFUN_WORD_SELECT:
1927 case LFUN_PARAGRAPH_UP:
1928 case LFUN_PARAGRAPH_DOWN:
1929 case LFUN_SCREEN_UP:
1930 case LFUN_SCREEN_DOWN:
1931 case LFUN_LINE_BEGIN:
1933 case LFUN_BREAK_LINE:
1934 case LFUN_CHAR_DELETE_FORWARD:
1935 case LFUN_DELETE_FORWARD_SKIP:
1936 case LFUN_CHAR_DELETE_BACKWARD:
1937 case LFUN_DELETE_BACKWARD_SKIP:
1938 case LFUN_BREAK_PARAGRAPH:
1939 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
1940 case LFUN_BREAK_PARAGRAPH_SKIP:
1941 case LFUN_PARAGRAPH_SPACING:
1942 case LFUN_INSET_INSERT:
1943 case LFUN_WORD_UPCASE:
1944 case LFUN_WORD_LOWCASE:
1945 case LFUN_WORD_CAPITALIZE:
1946 case LFUN_CHARS_TRANSPOSE:
1947 case LFUN_SERVER_GET_XY:
1948 case LFUN_SERVER_SET_XY:
1949 case LFUN_SERVER_GET_FONT:
1950 case LFUN_SERVER_GET_LAYOUT:
1952 case LFUN_DATE_INSERT:
1953 case LFUN_SELF_INSERT:
1954 case LFUN_LINE_INSERT:
1955 case LFUN_PAGEBREAK_INSERT:
1956 case LFUN_CLEARPAGE_INSERT:
1957 case LFUN_CLEARDOUBLEPAGE_INSERT:
1958 case LFUN_MATH_DISPLAY:
1959 case LFUN_MATH_IMPORT_SELECTION:
1960 case LFUN_MATH_MODE:
1961 case LFUN_MATH_MACRO:
1962 case LFUN_MATH_MATRIX:
1963 case LFUN_MATH_DELIM:
1964 case LFUN_MATH_BIGDELIM:
1965 case LFUN_MATH_INSERT:
1966 case LFUN_MATH_SUBSCRIPT:
1967 case LFUN_MATH_SUPERSCRIPT:
1968 case LFUN_FONT_DEFAULT:
1969 case LFUN_FONT_UNDERLINE:
1970 case LFUN_FONT_SIZE:
1972 case LFUN_FONT_FREE_APPLY:
1973 case LFUN_FONT_FREE_UPDATE:
1974 case LFUN_LAYOUT_PARAGRAPH:
1975 case LFUN_PARAGRAPH_UPDATE:
1976 case LFUN_ACCENT_UMLAUT:
1977 case LFUN_ACCENT_CIRCUMFLEX:
1978 case LFUN_ACCENT_GRAVE:
1979 case LFUN_ACCENT_ACUTE:
1980 case LFUN_ACCENT_TILDE:
1981 case LFUN_ACCENT_CEDILLA:
1982 case LFUN_ACCENT_MACRON:
1983 case LFUN_ACCENT_DOT:
1984 case LFUN_ACCENT_UNDERDOT:
1985 case LFUN_ACCENT_UNDERBAR:
1986 case LFUN_ACCENT_CARON:
1987 case LFUN_ACCENT_SPECIAL_CARON:
1988 case LFUN_ACCENT_BREVE:
1989 case LFUN_ACCENT_TIE:
1990 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1991 case LFUN_ACCENT_CIRCLE:
1992 case LFUN_ACCENT_OGONEK:
1993 case LFUN_THESAURUS_ENTRY:
1994 case LFUN_PARAGRAPH_PARAMS_APPLY:
1996 case LFUN_BUFFER_END:
1997 case LFUN_BUFFER_BEGIN:
1998 case LFUN_BUFFER_BEGIN_SELECT:
1999 case LFUN_BUFFER_END_SELECT:
2000 case LFUN_UNICODE_INSERT:
2001 // these are handled in our dispatch()
2009 if (code != Inset::NO_CODE
2010 && (cur.empty() || !cur.inset().insetAllowed(code)))
2013 flag.enabled(enable);
2018 void Text::pasteString(Cursor & cur, docstring const & clip,
2021 cur.clearSelection();
2022 if (!clip.empty()) {
2025 insertStringAsParagraphs(cur, clip);
2027 insertStringAsLines(cur, clip);