3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Asger Alstrup
7 * \author Lars Gullik Bjønnes
8 * \author Alfredo Braunstein
9 * \author Angus Leeming
11 * \author André Pönitz
13 * Full author contact details are available in file CREDITS.
20 #include "BranchList.h"
21 #include "FloatList.h"
22 #include "FuncStatus.h"
24 #include "buffer_funcs.h"
25 #include "BufferParams.h"
26 #include "BufferView.h"
27 #include "bufferview_funcs.h"
29 #include "CoordCache.h"
30 #include "CutAndPaste.h"
32 #include "DispatchResult.h"
33 #include "ErrorList.h"
35 #include "FuncRequest.h"
39 #include "LyXAction.h"
44 #include "Paragraph.h"
45 #include "paragraph_funcs.h"
46 #include "ParagraphParameters.h"
49 #include "ParIterator.h"
51 #include "frontends/Clipboard.h"
52 #include "frontends/Selection.h"
54 #include "insets/InsetCommand.h"
55 #include "insets/InsetFloatList.h"
56 #include "insets/InsetNewline.h"
57 #include "insets/InsetQuotes.h"
58 #include "insets/InsetSpecialChar.h"
59 #include "insets/InsetText.h"
61 #include "support/lstrings.h"
62 #include "support/lyxlib.h"
63 #include "support/convert.h"
64 #include "support/lyxtime.h"
66 #include "mathed/InsetMathHull.h"
67 #include "mathed/MathMacroTemplate.h"
69 #include <boost/current_function.hpp>
77 using cap::copySelection;
78 using cap::cutSelection;
79 using cap::pasteFromStack;
80 using cap::pasteClipboard;
81 using cap::replaceSelection;
82 using cap::saveSelection;
84 using support::isStrUnsignedInt;
89 using std::istringstream;
90 using std::ostringstream;
93 extern string current_layout;
99 Font freefont(Font::ALL_IGNORE);
100 bool toggleall = false;
103 void toggleAndShow(Cursor & cur, Text * text,
104 Font const & font, bool toggleall = true)
106 text->toggleFree(cur, font, toggleall);
108 if (font.language() != ignore_language ||
109 font.number() != Font::IGNORE) {
110 Paragraph & par = cur.paragraph();
111 text->bidi.computeTables(par, cur.buffer(), cur.textRow());
112 if (cur.boundary() !=
113 text->bidi.isBoundary(cur.buffer(), par,
115 text->real_current_font))
116 text->setCursor(cur, cur.pit(), cur.pos(),
117 false, !cur.boundary());
122 void moveCursor(Cursor & cur, bool selecting)
124 if (selecting || cur.mark())
127 cur.bv().switchKeyMap();
131 void finishChange(Cursor & cur, bool selecting)
134 moveCursor(cur, selecting);
138 void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
141 docstring sel = cur.selectionAsString(false);
143 // It may happen that sel is empty but there is a selection
144 replaceSelection(cur);
147 #ifdef ENABLE_ASSERTIONS
148 const int old_pos = cur.pos();
150 cur.insert(new InsetMathHull(hullSimple));
151 BOOST_ASSERT(old_pos == cur.pos());
152 cur.nextInset()->edit(cur, true);
153 // don't do that also for LFUN_MATH_MODE
154 // unless you want end up with always changing
155 // to mathrm when opening an inlined inset --
156 // I really hate "LyXfunc overloading"...
158 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
159 // Avoid an unnecessary undo step if cmd.argument
161 if (!cmd.argument().empty())
162 cur.dispatch(FuncRequest(LFUN_MATH_INSERT,
165 // create a macro if we see "\\newcommand"
166 // somewhere, and an ordinary formula
168 if (sel.find(from_ascii("\\newcommand")) == string::npos
169 && sel.find(from_ascii("\\def")) == string::npos)
171 InsetMathHull * formula = new InsetMathHull;
172 istringstream is(to_utf8(sel));
175 formula->read(cur.buffer(), lex);
176 if (formula->getType() == hullNone)
177 // Don't create pseudo formulas if
178 // delimiters are left out
179 formula->mutate(hullSimple);
182 cur.insert(new MathMacroTemplate(sel));
185 cur.message(from_utf8(N_("Math editor mode")));
194 string const freefont2string()
197 if (font2string(freefont, toggleall, data))
204 void Text::cursorPrevious(Cursor & cur)
206 pos_type cpos = cur.pos();
207 pit_type cpar = cur.pit();
209 int x = cur.x_target();
210 setCursorFromCoordinates(cur, x, 0);
211 cur.dispatch(FuncRequest(cur.selection()? LFUN_UP_SELECT: LFUN_UP));
213 if (cpar == cur.pit() && cpos == cur.pos())
214 // we have a row which is taller than the workarea. The
215 // simplest solution is to move to the previous row instead.
216 cur.dispatch(FuncRequest(cur.selection()? LFUN_UP_SELECT: LFUN_UP));
219 cur.updateFlags(Update::Force | Update::FitCursor);
223 void Text::cursorNext(Cursor & cur)
225 pos_type cpos = cur.pos();
226 pit_type cpar = cur.pit();
228 int x = cur.x_target();
229 setCursorFromCoordinates(cur, x, cur.bv().workHeight() - 1);
230 cur.dispatch(FuncRequest(cur.selection()? LFUN_DOWN_SELECT: LFUN_DOWN));
232 if (cpar == cur.pit() && cpos == cur.pos())
233 // we have a row which is taller than the workarea. The
234 // simplest solution is to move to the next row instead.
236 FuncRequest(cur.selection()? LFUN_DOWN_SELECT: LFUN_DOWN));
239 cur.updateFlags(Update::Force | Update::FitCursor);
245 void specialChar(Cursor & cur, InsetSpecialChar::Kind kind)
248 cap::replaceSelection(cur);
249 cur.insert(new InsetSpecialChar(kind));
254 bool doInsertInset(Cursor & cur, Text * text,
255 FuncRequest const & cmd, bool edit, bool pastesel)
257 Inset * inset = createInset(&cur.bv(), cmd);
263 if (cur.selection()) {
264 lyx::dispatch(FuncRequest(LFUN_CUT));
267 text->insertInset(cur, inset);
270 inset->edit(cur, true);
272 if (gotsel && pastesel) {
273 lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
274 // reset first par to default
275 if (cur.lastpit() != 0 || cur.lastpos() != 0) {
276 Layout_ptr const layout =
277 cur.buffer().params().getTextClass().defaultLayout();
278 cur.text()->paragraphs().begin()->layout(layout);
288 void Text::number(Cursor & cur)
290 Font font(Font::ALL_IGNORE);
291 font.setNumber(Font::TOGGLE);
292 toggleAndShow(cur, this, font);
296 bool Text::isRTL(Buffer const & buffer, Paragraph const & par) const
298 return par.isRightToLeftPar(buffer.params());
302 void Text::dispatch(Cursor & cur, FuncRequest & cmd)
304 LYXERR(Debug::ACTION) << "Text::dispatch: cmd: " << cmd << endl;
306 // FIXME: We use the update flag to indicates wether a singlePar or a
307 // full screen update is needed. We reset it here but shall we restore it
311 BOOST_ASSERT(cur.text() == this);
312 BufferView * bv = &cur.bv();
313 CursorSlice oldTopSlice = cur.top();
314 bool oldBoundary = cur.boundary();
315 bool sel = cur.selection();
316 // Signals that, even if needsUpdate == false, an update of the
317 // cursor paragraph is required
318 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
319 LyXAction::SingleParUpdate);
320 // Signals that a full-screen update is required
321 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
322 LyXAction::NoUpdate) || singleParUpdate);
323 // Remember the old paragraph metric (_outer_ paragraph!)
324 ParagraphMetrics const & pm = cur.bv().parMetrics(
325 cur.bottom().text(), cur.bottom().pit());
326 Dimension olddim = pm.dim();
328 switch (cmd.action) {
330 case LFUN_PARAGRAPH_MOVE_DOWN: {
331 pit_type const pit = cur.pit();
332 recUndo(cur, pit, pit + 1);
334 std::swap(pars_[pit], pars_[pit + 1]);
336 ParIterator begin(cur);
337 // begin.pos() (== cur.pos()) may point beyond the end of the
338 // paragraph referenced by begin. This would cause a crash
342 ParIterator end = boost::next(ParIterator(cur));
343 updateLabels(cur.buffer(), begin, end);
349 case LFUN_PARAGRAPH_MOVE_UP: {
350 pit_type const pit = cur.pit();
351 recUndo(cur, pit - 1, pit);
353 std::swap(pars_[pit], pars_[pit - 1]);
355 ParIterator end = ParIterator(cur);
356 // end.pos() (== cur.pos()) may point beyond the end of the
357 // paragraph referenced by end. This would cause a crash
360 end = boost::next(end);
362 ParIterator begin(cur);
363 updateLabels(cur.buffer(), begin, end);
369 case LFUN_APPENDIX: {
370 Paragraph & par = cur.paragraph();
371 bool start = !par.params().startOfAppendix();
374 #warning The code below only makes sense at top level.
375 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
377 // ensure that we have only one start_of_appendix in this document
378 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
379 if (pars_[tmp].params().startOfAppendix()) {
381 pars_[tmp].params().startOfAppendix(false);
387 par.params().startOfAppendix(start);
389 // we can set the refreshing parameters now
390 updateLabels(cur.buffer());
394 case LFUN_WORD_DELETE_FORWARD:
395 cur.clearSelection();
396 deleteWordForward(cur);
397 finishChange(cur, false);
400 case LFUN_WORD_DELETE_BACKWARD:
401 cur.clearSelection();
402 deleteWordBackward(cur);
403 finishChange(cur, false);
406 case LFUN_LINE_DELETE:
407 cur.clearSelection();
408 deleteLineForward(cur);
409 finishChange(cur, false);
412 case LFUN_BUFFER_BEGIN:
413 case LFUN_BUFFER_BEGIN_SELECT:
414 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
415 if (cur.depth() == 1) {
416 needsUpdate |= cursorTop(cur);
422 case LFUN_BUFFER_END:
423 case LFUN_BUFFER_END_SELECT:
424 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
425 if (cur.depth() == 1) {
426 needsUpdate |= cursorBottom(cur);
432 case LFUN_CHAR_FORWARD:
433 case LFUN_CHAR_FORWARD_SELECT:
434 //lyxerr << BOOST_CURRENT_FUNCTION
435 // << " LFUN_CHAR_FORWARD[SEL]:\n" << cur << endl;
436 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
437 if (reverseDirectionNeeded(cur))
438 needsUpdate |= cursorLeft(cur);
440 needsUpdate |= cursorRight(cur);
442 if (!needsUpdate && oldTopSlice == cur.top()
443 && cur.boundary() == oldBoundary) {
445 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
451 case LFUN_CHAR_BACKWARD:
452 case LFUN_CHAR_BACKWARD_SELECT:
453 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
454 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
455 if (reverseDirectionNeeded(cur))
456 needsUpdate |= cursorRight(cur);
458 needsUpdate |= cursorLeft(cur);
460 if (!needsUpdate && oldTopSlice == cur.top()
461 && cur.boundary() == oldBoundary) {
463 cmd = FuncRequest(LFUN_FINISHED_LEFT);
471 //lyxerr << "handle LFUN_UP[SEL]:\n" << cur << endl;
472 needsUpdate |= cur.selHandle(cmd.action == LFUN_UP_SELECT);
474 needsUpdate |= cursorUp(cur);
476 if (!needsUpdate && oldTopSlice == cur.top()
477 && cur.boundary() == oldBoundary) {
479 cmd = FuncRequest(LFUN_FINISHED_UP);
486 case LFUN_DOWN_SELECT:
487 //lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
488 needsUpdate |= cur.selHandle(cmd.action == LFUN_DOWN_SELECT);
489 needsUpdate |= cursorDown(cur);
491 if (!needsUpdate && oldTopSlice == cur.top() &&
492 cur.boundary() == oldBoundary)
495 cmd = FuncRequest(LFUN_FINISHED_DOWN);
501 case LFUN_PARAGRAPH_UP:
502 case LFUN_PARAGRAPH_UP_SELECT:
503 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
504 needsUpdate |= cursorUpParagraph(cur);
509 case LFUN_PARAGRAPH_DOWN:
510 case LFUN_PARAGRAPH_DOWN_SELECT:
511 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
512 needsUpdate |= cursorDownParagraph(cur);
518 case LFUN_SCREEN_UP_SELECT:
519 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_UP_SELECT);
520 if (cur.pit() == 0 && cur.textRow().pos() == 0) {
522 cmd = FuncRequest(LFUN_FINISHED_UP);
530 case LFUN_SCREEN_DOWN:
531 case LFUN_SCREEN_DOWN_SELECT:
532 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_DOWN_SELECT);
533 if (cur.pit() == cur.lastpit()
534 && cur.textRow().endpos() == cur.lastpos()) {
536 cmd = FuncRequest(LFUN_FINISHED_DOWN);
544 case LFUN_LINE_BEGIN:
545 case LFUN_LINE_BEGIN_SELECT:
546 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
547 needsUpdate |= cursorHome(cur);
551 case LFUN_LINE_END_SELECT:
552 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
553 needsUpdate |= cursorEnd(cur);
558 case LFUN_WORD_FORWARD:
559 case LFUN_WORD_FORWARD_SELECT:
560 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
561 if (reverseDirectionNeeded(cur))
562 needsUpdate |= cursorLeftOneWord(cur);
564 needsUpdate |= cursorRightOneWord(cur);
569 case LFUN_WORD_BACKWARD:
570 case LFUN_WORD_BACKWARD_SELECT:
571 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
572 if (reverseDirectionNeeded(cur))
573 needsUpdate |= cursorRightOneWord(cur);
575 needsUpdate |= cursorLeftOneWord(cur);
580 case LFUN_WORD_SELECT: {
581 selectWord(cur, WHOLE_WORD);
582 finishChange(cur, true);
586 case LFUN_BREAK_LINE: {
587 // Not allowed by LaTeX (labels or empty par)
588 if (cur.pos() > cur.paragraph().beginOfBody()) {
589 // this avoids a double undo
590 // FIXME: should not be needed, ideally
591 if (!cur.selection())
593 cap::replaceSelection(cur);
594 cur.insert(new InsetNewline);
596 moveCursor(cur, false);
601 case LFUN_CHAR_DELETE_FORWARD:
602 if (!cur.selection()) {
603 if (cur.pos() == cur.paragraph().size())
604 // Par boundary, force full-screen update
605 singleParUpdate = false;
606 needsUpdate |= erase(cur);
608 // It is possible to make it a lot faster still
609 // just comment out the line below...
611 cutSelection(cur, true, false);
612 singleParUpdate = false;
614 moveCursor(cur, false);
617 case LFUN_DELETE_FORWARD_SKIP:
618 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
619 if (!cur.selection()) {
620 if (cur.pos() == cur.lastpos()) {
627 cutSelection(cur, true, false);
632 case LFUN_CHAR_DELETE_BACKWARD:
633 if (!cur.selection()) {
634 if (bv->getIntl().getTransManager().backspace()) {
635 // Par boundary, full-screen update
637 singleParUpdate = false;
638 needsUpdate |= backspace(cur);
640 // It is possible to make it a lot faster still
641 // just comment out the line below...
644 cutSelection(cur, true, false);
645 singleParUpdate = false;
650 case LFUN_DELETE_BACKWARD_SKIP:
651 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
652 if (!cur.selection()) {
656 //CursorSlice cur = cursor();
660 cutSelection(cur, true, false);
664 case LFUN_BREAK_PARAGRAPH:
665 cap::replaceSelection(cur);
666 breakParagraph(cur, 0);
671 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
672 cap::replaceSelection(cur);
673 breakParagraph(cur, 1);
678 case LFUN_BREAK_PARAGRAPH_SKIP: {
679 // When at the beginning of a paragraph, remove
680 // indentation. Otherwise, do the same as LFUN_BREAK_PARAGRAPH.
681 cap::replaceSelection(cur);
683 cur.paragraph().params().labelWidthString(docstring());
685 breakParagraph(cur, 0);
691 case LFUN_PARAGRAPH_SPACING: {
692 Paragraph & par = cur.paragraph();
693 Spacing::Space cur_spacing = par.params().spacing().getSpace();
694 string cur_value = "1.0";
695 if (cur_spacing == Spacing::Other)
696 cur_value = par.params().spacing().getValueAsString();
698 istringstream is(to_utf8(cmd.argument()));
701 Spacing::Space new_spacing = cur_spacing;
702 string new_value = cur_value;
704 lyxerr << "Missing argument to `paragraph-spacing'"
706 } else if (tmp == "single") {
707 new_spacing = Spacing::Single;
708 } else if (tmp == "onehalf") {
709 new_spacing = Spacing::Onehalf;
710 } else if (tmp == "double") {
711 new_spacing = Spacing::Double;
712 } else if (tmp == "other") {
713 new_spacing = Spacing::Other;
714 string tmpval = "0.0";
716 lyxerr << "new_value = " << tmpval << endl;
719 } else if (tmp == "default") {
720 new_spacing = Spacing::Default;
722 lyxerr << to_utf8(_("Unknown spacing argument: "))
723 << to_utf8(cmd.argument()) << endl;
725 if (cur_spacing != new_spacing || cur_value != new_value)
726 par.params().spacing(Spacing(new_spacing, new_value));
730 case LFUN_INSET_INSERT: {
732 Inset * inset = createInset(bv, cmd);
734 // FIXME (Abdel 01/02/2006):
735 // What follows would be a partial fix for bug 2154:
736 // http://bugzilla.lyx.org/show_bug.cgi?id=2154
737 // This automatically put the label inset _after_ a
738 // numbered section. It should be possible to extend the mechanism
739 // to any kind of LateX environement.
740 // The correct way to fix that bug would be at LateX generation.
741 // I'll let the code here for reference as it could be used for some
742 // other feature like "automatic labelling".
744 Paragraph & par = pars_[cur.pit()];
745 if (inset->lyxCode() == Inset::LABEL_CODE
746 && par.layout()->labeltype == LABEL_COUNTER) {
747 // Go to the end of the paragraph
748 // Warning: Because of Change-Tracking, the last
749 // position is 'size()' and not 'size()-1':
750 cur.pos() = par.size();
751 // Insert a new paragraph
752 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
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
835 cutSelection(cur, true, true);
836 cur.message(_("Cut"));
841 cur.message(_("Copy"));
844 case LFUN_SERVER_GET_XY:
845 cur.message(from_utf8(
846 convert<string>(cursorX(cur.bv(), cur.top(), cur.boundary()))
847 + ' ' + convert<string>(cursorY(cur.bv(), cur.top(), cur.boundary()))));
850 case LFUN_SERVER_SET_XY: {
853 istringstream is(to_utf8(cmd.argument()));
856 lyxerr << "SETXY: Could not parse coordinates in '"
857 << to_utf8(cmd.argument()) << std::endl;
859 setCursorFromCoordinates(cur, x, y);
863 case LFUN_SERVER_GET_FONT:
864 if (current_font.shape() == Font::ITALIC_SHAPE)
865 cur.message(from_ascii("E"));
866 else if (current_font.shape() == Font::SMALLCAPS_SHAPE)
867 cur.message(from_ascii("N"));
869 cur.message(from_ascii("0"));
872 case LFUN_SERVER_GET_LAYOUT:
873 cur.message(from_utf8(cur.paragraph().layout()->name()));
877 string layout = to_ascii(cmd.argument());
878 LYXERR(Debug::INFO) << "LFUN_LAYOUT: (arg) " << layout << endl;
880 // Derive layout number from given argument (string)
881 // and current buffer's textclass (number)
882 TextClass const & tclass = bv->buffer()->params().getTextClass();
884 layout = tclass.defaultLayoutName();
885 bool hasLayout = tclass.hasLayout(layout);
887 // If the entry is obsolete, use the new one instead.
889 string const & obs = tclass[layout]->obsoleted_by();
895 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
896 from_utf8(N_(" not known")));
900 bool change_layout = (current_layout != layout);
902 if (!change_layout && cur.selection() &&
903 cur.selBegin().pit() != cur.selEnd().pit())
905 pit_type spit = cur.selBegin().pit();
906 pit_type epit = cur.selEnd().pit() + 1;
907 while (spit != epit) {
908 if (pars_[spit].layout()->name() != current_layout) {
909 change_layout = true;
917 current_layout = layout;
918 setLayout(cur, layout);
919 // inform the GUI that the layout has changed.
920 bv->layoutChanged(layout);
926 case LFUN_CLIPBOARD_PASTE:
927 cur.clearSelection();
928 pasteClipboard(cur, bv->buffer()->errorList("Paste"),
929 cmd.argument() == "paragraph");
930 bv->buffer()->errors("Paste");
933 case LFUN_PRIMARY_SELECTION_PASTE:
934 pasteString(cur, theSelection().get(),
935 cmd.argument() == "paragraph");
938 case LFUN_UNICODE_INSERT: {
939 if (cmd.argument().empty())
941 docstring hexstring = cmd.argument();
942 if (lyx::support::isHex(hexstring)) {
943 char_type c = lyx::support::hexToInt(hexstring);
944 if (c > 32 && c < 0x10ffff) {
945 lyxerr << "Inserting c: " << c << endl;
946 docstring s = docstring(1, c);
947 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
953 case LFUN_QUOTE_INSERT: {
954 Paragraph & par = cur.paragraph();
955 pos_type pos = cur.pos();
956 BufferParams const & bufparams = bv->buffer()->params();
957 Layout_ptr const & style = par.layout();
958 if (!style->pass_thru
959 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
960 // this avoids a double undo
961 // FIXME: should not be needed, ideally
962 if (!cur.selection())
964 cap::replaceSelection(cur);
969 else if (cur.prevInset() && cur.prevInset()->isSpace())
972 c = par.getChar(pos - 1);
973 string arg = to_utf8(cmd.argument());
975 cur.insert(new InsetQuotes(c,
976 bufparams.quotes_language,
977 InsetQuotes::SingleQ));
979 cur.insert(new InsetQuotes(c,
980 bufparams.quotes_language,
981 InsetQuotes::DoubleQ));
985 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
989 case LFUN_DATE_INSERT:
990 if (cmd.argument().empty())
991 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
992 formatted_time(current_time())));
994 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
995 formatted_time(current_time(), to_utf8(cmd.argument()))));
998 case LFUN_MOUSE_TRIPLE:
999 if (cmd.button() == mouse_button::button1) {
1009 case LFUN_MOUSE_DOUBLE:
1010 if (cmd.button() == mouse_button::button1) {
1011 selectWord(cur, WHOLE_WORD_STRICT);
1016 // Single-click on work area
1017 case LFUN_MOUSE_PRESS: {
1018 // Right click on a footnote flag opens float menu
1019 if (cmd.button() == mouse_button::button3)
1020 cur.clearSelection();
1022 // Middle button press pastes if we have a selection
1023 // We do this here as if the selection was inside an inset
1024 // it could get cleared on the unlocking of the inset so
1025 // we have to check this first
1026 bool paste_internally = false;
1027 if (cmd.button() == mouse_button::button2 && cap::selection()) {
1028 // Copy the selection buffer to the clipboard
1029 // stack, because we want it to appear in the
1030 // "Edit->Paste recent" menu.
1031 cap::copySelectionToStack();
1032 paste_internally = true;
1035 // we have to update after dePM triggered
1036 bool update = bv->mouseSetCursor(cur);
1038 // Insert primary selection with middle mouse
1039 // if there is a local selection in the current buffer,
1041 if (cmd.button() == mouse_button::button2) {
1042 if (paste_internally) {
1043 cap::pasteSelection(cur, bv->buffer()->errorList("Paste"));
1044 bv->buffer()->errors("Paste");
1045 cur.clearSelection(); // bug 393
1049 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
1052 if (!update && cmd.button() == mouse_button::button1) {
1053 needsUpdate = false;
1060 case LFUN_MOUSE_MOTION: {
1061 // Only use motion with button 1
1062 //if (cmd.button() != mouse_button::button1)
1065 // ignore motions deeper nested than the real anchor
1066 Cursor & bvcur = cur.bv().cursor();
1067 if (bvcur.anchor_.hasPart(cur)) {
1068 CursorSlice old = bvcur.top();
1070 int const wh = bv->workHeight();
1071 int const y = std::max(0, std::min(wh - 1, cmd.y));
1073 setCursorFromCoordinates(cur, cmd.x, y);
1074 cur.x_target() = cmd.x;
1076 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1078 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1079 // This is to allow jumping over large insets
1080 if (cur.top() == old) {
1082 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1084 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1087 if (cur.top() == old)
1090 // don't set anchor_
1091 bvcur.setCursor(cur);
1092 bvcur.selection() = true;
1093 //lyxerr << "MOTION: " << bv->cursor() << endl;
1101 case LFUN_MOUSE_RELEASE: {
1102 if (cmd.button() == mouse_button::button2)
1105 if (cmd.button() == mouse_button::button1) {
1106 // if there is new selection, update persistent
1107 // selection, otherwise, single click does not
1108 // clear persistent selection buffer
1109 if (cur.selection()) {
1111 // if double click, cur is moved to the end of word by selectWord
1112 // but bvcur is current mouse position
1113 Cursor & bvcur = cur.bv().cursor();
1114 bvcur.selection() = true;
1115 saveSelection(bvcur);
1117 needsUpdate = false;
1125 case LFUN_SELF_INSERT: {
1126 if (cmd.argument().empty())
1129 // Automatically delete the currently selected
1130 // text and replace it with what is being
1131 // typed in now. Depends on lyxrc settings
1132 // "auto_region_delete", which defaults to
1135 if (lyxrc.auto_region_delete)
1136 if (cur.selection())
1137 cutSelection(cur, false, false);
1139 cur.clearSelection();
1140 Font const old_font = real_current_font;
1142 docstring::const_iterator cit = cmd.argument().begin();
1143 docstring::const_iterator end = cmd.argument().end();
1144 for (; cit != end; ++cit)
1145 bv->getIntl().getTransManager().
1146 translateAndInsert(*cit, this, cur);
1149 moveCursor(cur, false);
1153 case LFUN_URL_INSERT: {
1154 InsetCommandParams p("url");
1155 string const data = InsetCommandMailer::params2string("url", p);
1156 bv->showInsetDialog("url", data, 0);
1160 case LFUN_HTML_INSERT: {
1161 InsetCommandParams p("htmlurl");
1162 string const data = InsetCommandMailer::params2string("url", p);
1163 bv->showInsetDialog("url", data, 0);
1167 case LFUN_LABEL_INSERT: {
1168 InsetCommandParams p("label");
1169 // Try to generate a valid label
1170 p["name"] = (cmd.argument().empty()) ?
1171 cur.getPossibleLabel() :
1173 string const data = InsetCommandMailer::params2string("label", p);
1175 if (cmd.argument().empty()) {
1176 bv->showInsetDialog("label", data, 0);
1178 FuncRequest fr(LFUN_INSET_INSERT, data);
1186 case LFUN_LIST_INSERT:
1187 case LFUN_THEOREM_INSERT:
1189 case LFUN_CAPTION_INSERT:
1190 // Open the inset, and move the current selection
1192 doInsertInset(cur, this, cmd, true, true);
1194 updateLabels(*bv->buffer());
1196 case LFUN_NOTE_INSERT:
1197 case LFUN_CHARSTYLE_INSERT:
1198 case LFUN_BOX_INSERT:
1199 case LFUN_BRANCH_INSERT:
1200 case LFUN_BIBITEM_INSERT:
1201 case LFUN_ERT_INSERT:
1202 case LFUN_LISTING_INSERT:
1203 case LFUN_FOOTNOTE_INSERT:
1204 case LFUN_MARGINALNOTE_INSERT:
1205 case LFUN_OPTIONAL_INSERT:
1206 case LFUN_ENVIRONMENT_INSERT:
1207 // Open the inset, and move the current selection
1209 doInsertInset(cur, this, cmd, true, true);
1213 case LFUN_TABULAR_INSERT:
1214 // if there were no arguments, just open the dialog
1215 if (doInsertInset(cur, this, cmd, false, true))
1218 bv->showDialog("tabularcreate");
1222 case LFUN_FLOAT_INSERT:
1223 case LFUN_FLOAT_WIDE_INSERT:
1224 case LFUN_WRAP_INSERT: {
1225 bool content = cur.selection(); // will some text be moved into the inset?
1227 doInsertInset(cur, this, cmd, true, true);
1229 ParagraphList & pars = cur.text()->paragraphs();
1231 TextClass const & tclass = bv->buffer()->params().getTextClass();
1233 // add a separate paragraph for the caption inset
1234 pars.push_back(Paragraph());
1235 pars.back().setInsetOwner(pars[0].inInset());
1236 pars.back().layout(tclass.defaultLayout());
1238 int cap_pit = pars.size() - 1;
1240 // if an empty inset was created, we create an additional empty
1241 // paragraph at the bottom so that the user can choose where to put
1242 // the graphics (or table).
1244 pars.push_back(Paragraph());
1245 pars.back().setInsetOwner(pars[0].inInset());
1246 pars.back().layout(tclass.defaultLayout());
1250 // reposition the cursor to the caption
1251 cur.pit() = cap_pit;
1253 cur.dispatch(FuncRequest(LFUN_CAPTION_INSERT));
1254 // FIXME: When leaving the Float (or Wrap) inset we should
1255 // delete any empty paragraph left above or below the
1260 case LFUN_INDEX_INSERT:
1261 case LFUN_NOMENCL_INSERT: {
1262 Inset * inset = createInset(&cur.bv(), cmd);
1266 cur.clearSelection();
1267 insertInset(cur, inset);
1268 inset->edit(cur, true);
1269 // Show the dialog for the nomenclature entry, since the
1270 // description entry still needs to be filled in.
1271 if (cmd.action == LFUN_NOMENCL_INSERT)
1272 InsetCommandMailer("nomenclature",
1273 *reinterpret_cast<InsetCommand *>(inset)).showDialog(&cur.bv());
1278 case LFUN_INDEX_PRINT:
1279 case LFUN_NOMENCL_PRINT:
1280 case LFUN_TOC_INSERT:
1281 case LFUN_HFILL_INSERT:
1282 case LFUN_LINE_INSERT:
1283 case LFUN_PAGEBREAK_INSERT:
1284 case LFUN_CLEARPAGE_INSERT:
1285 case LFUN_CLEARDOUBLEPAGE_INSERT:
1287 doInsertInset(cur, this, cmd, false, false);
1291 case LFUN_DEPTH_DECREMENT:
1292 changeDepth(cur, DEC_DEPTH);
1295 case LFUN_DEPTH_INCREMENT:
1296 changeDepth(cur, INC_DEPTH);
1299 case LFUN_MATH_DISPLAY:
1300 mathDispatch(cur, cmd, true);
1303 case LFUN_MATH_IMPORT_SELECTION:
1304 case LFUN_MATH_MODE:
1305 if (cmd.argument() == "on")
1306 // don't pass "on" as argument
1307 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1309 mathDispatch(cur, cmd, false);
1312 case LFUN_MATH_MACRO:
1313 if (cmd.argument().empty())
1314 cur.errorMessage(from_utf8(N_("Missing argument")));
1316 string s = to_utf8(cmd.argument());
1317 string const s1 = token(s, ' ', 1);
1318 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1319 string const s2 = token(s, ' ', 2);
1320 string const type = s2.empty() ? "newcommand" : s2;
1321 cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, from_utf8(type)));
1322 //cur.nextInset()->edit(cur, true);
1326 // passthrough hat and underscore outside mathed:
1327 case LFUN_MATH_SUBSCRIPT:
1328 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1330 case LFUN_MATH_SUPERSCRIPT:
1331 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1334 case LFUN_MATH_INSERT:
1335 case LFUN_MATH_MATRIX:
1336 case LFUN_MATH_DELIM:
1337 case LFUN_MATH_BIGDELIM: {
1338 cur.insert(new InsetMathHull(hullSimple));
1339 cur.dispatch(FuncRequest(LFUN_CHAR_FORWARD));
1344 case LFUN_FONT_EMPH: {
1345 Font font(Font::ALL_IGNORE);
1346 font.setEmph(Font::TOGGLE);
1347 toggleAndShow(cur, this, font);
1351 case LFUN_FONT_BOLD: {
1352 Font font(Font::ALL_IGNORE);
1353 font.setSeries(Font::BOLD_SERIES);
1354 toggleAndShow(cur, this, font);
1358 case LFUN_FONT_NOUN: {
1359 Font font(Font::ALL_IGNORE);
1360 font.setNoun(Font::TOGGLE);
1361 toggleAndShow(cur, this, font);
1365 case LFUN_FONT_CODE: {
1366 Font font(Font::ALL_IGNORE);
1367 font.setFamily(Font::TYPEWRITER_FAMILY); // no good
1368 toggleAndShow(cur, this, font);
1372 case LFUN_FONT_SANS: {
1373 Font font(Font::ALL_IGNORE);
1374 font.setFamily(Font::SANS_FAMILY);
1375 toggleAndShow(cur, this, font);
1379 case LFUN_FONT_ROMAN: {
1380 Font font(Font::ALL_IGNORE);
1381 font.setFamily(Font::ROMAN_FAMILY);
1382 toggleAndShow(cur, this, font);
1386 case LFUN_FONT_DEFAULT: {
1387 Font font(Font::ALL_INHERIT, ignore_language);
1388 toggleAndShow(cur, this, font);
1392 case LFUN_FONT_UNDERLINE: {
1393 Font font(Font::ALL_IGNORE);
1394 font.setUnderbar(Font::TOGGLE);
1395 toggleAndShow(cur, this, font);
1399 case LFUN_FONT_SIZE: {
1400 Font font(Font::ALL_IGNORE);
1401 font.setLyXSize(to_utf8(cmd.argument()));
1402 toggleAndShow(cur, this, font);
1406 case LFUN_LANGUAGE: {
1407 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1410 Font font(Font::ALL_IGNORE);
1411 font.setLanguage(lang);
1412 toggleAndShow(cur, this, font);
1417 case LFUN_FONT_FREE_APPLY:
1418 toggleAndShow(cur, this, freefont, toggleall);
1419 cur.message(_("Character set"));
1422 // Set the freefont using the contents of \param data dispatched from
1423 // the frontends and apply it at the current cursor location.
1424 case LFUN_FONT_FREE_UPDATE: {
1427 if (bv_funcs::string2font(to_utf8(cmd.argument()), font, toggle)) {
1430 toggleAndShow(cur, this, freefont, toggleall);
1431 cur.message(_("Character set"));
1436 case LFUN_FINISHED_LEFT:
1437 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1438 if (reverseDirectionNeeded(cur))
1442 case LFUN_FINISHED_RIGHT:
1443 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1444 if (!reverseDirectionNeeded(cur))
1448 case LFUN_FINISHED_UP:
1449 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_UP:\n" << cur << endl;
1453 case LFUN_FINISHED_DOWN:
1454 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_DOWN:\n" << cur << endl;
1458 case LFUN_LAYOUT_PARAGRAPH: {
1460 params2string(cur.paragraph(), data);
1461 data = "show\n" + data;
1462 bv->showDialogWithData("paragraph", data);
1466 case LFUN_PARAGRAPH_UPDATE: {
1468 params2string(cur.paragraph(), data);
1470 // Will the paragraph accept changes from the dialog?
1471 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1473 data = "update " + convert<string>(accept) + '\n' + data;
1474 bv->updateDialog("paragraph", data);
1478 case LFUN_ACCENT_UMLAUT:
1479 case LFUN_ACCENT_CIRCUMFLEX:
1480 case LFUN_ACCENT_GRAVE:
1481 case LFUN_ACCENT_ACUTE:
1482 case LFUN_ACCENT_TILDE:
1483 case LFUN_ACCENT_CEDILLA:
1484 case LFUN_ACCENT_MACRON:
1485 case LFUN_ACCENT_DOT:
1486 case LFUN_ACCENT_UNDERDOT:
1487 case LFUN_ACCENT_UNDERBAR:
1488 case LFUN_ACCENT_CARON:
1489 case LFUN_ACCENT_SPECIAL_CARON:
1490 case LFUN_ACCENT_BREVE:
1491 case LFUN_ACCENT_TIE:
1492 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1493 case LFUN_ACCENT_CIRCLE:
1494 case LFUN_ACCENT_OGONEK:
1495 theLyXFunc().handleKeyFunc(cmd.action);
1496 if (!cmd.argument().empty())
1497 // FIXME: Are all these characters encoded in one byte in utf8?
1498 bv->getIntl().getTransManager()
1499 .translateAndInsert(cmd.argument()[0], this, cur);
1502 case LFUN_FLOAT_LIST: {
1503 TextClass const & tclass = bv->buffer()->params().getTextClass();
1504 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1505 // not quite sure if we want this...
1507 cur.clearSelection();
1508 breakParagraph(cur);
1510 if (cur.lastpos() != 0) {
1512 breakParagraph(cur);
1515 setLayout(cur, tclass.defaultLayoutName());
1516 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, docstring(), 0);
1517 insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1520 lyxerr << "Non-existent float type: "
1521 << to_utf8(cmd.argument()) << endl;
1526 case LFUN_CHANGE_ACCEPT: {
1527 acceptOrRejectChanges(cur, ACCEPT);
1531 case LFUN_CHANGE_REJECT: {
1532 acceptOrRejectChanges(cur, REJECT);
1536 case LFUN_THESAURUS_ENTRY: {
1537 docstring arg = cmd.argument();
1539 arg = cur.selectionAsString(false);
1541 if (arg.size() > 100 || arg.empty()) {
1542 // Get word or selection
1543 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1544 arg = cur.selectionAsString(false);
1547 bv->showDialogWithData("thesaurus", to_utf8(arg));
1551 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1552 // Given data, an encoding of the ParagraphParameters
1553 // generated in the Paragraph dialog, this function sets
1554 // the current paragraph appropriately.
1555 istringstream is(to_utf8(cmd.argument()));
1558 ParagraphParameters params;
1563 params.labelWidthString(),
1565 cur.message(_("Paragraph layout set"));
1570 if (cur.selection()) {
1571 cur.selection() = false;
1575 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1580 LYXERR(Debug::ACTION)
1581 << BOOST_CURRENT_FUNCTION
1582 << ": Command " << cmd
1583 << " not DISPATCHED by Text" << endl;
1588 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1590 // FIXME: The cursor flag is reset two lines below
1591 // so we need to check here if some of the LFUN did touch that.
1592 // for now only Text::erase() and Text::backspace() do that.
1593 // The plan is to verify all the LFUNs and then to remove this
1594 // singleParUpdate boolean altogether.
1595 if (cur.result().update() & Update::Force) {
1596 singleParUpdate = false;
1600 // FIXME: the following code should go in favor of fine grained
1601 // update flag treatment.
1602 if (singleParUpdate) {
1603 // Inserting characters does not change par height
1604 ParagraphMetrics const & pms
1605 = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
1606 if (pms.dim().height()
1607 == olddim.height()) {
1608 // if so, update _only_ this paragraph
1609 cur.updateFlags(Update::SinglePar |
1611 Update::MultiParSel);
1618 && &oldTopSlice.inset() == &cur.inset()
1619 && oldTopSlice.idx() == cur.idx()
1620 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1621 && !cur.selection())
1622 // FIXME: it would be better if we could just do this
1624 //if (cur.result().update() != Update::FitCursor)
1627 // But some LFUNs do not set Update::FitCursor when needed, so we
1628 // do it for all. This is not very harmfull as FitCursor will provoke
1629 // a full redraw only if needed but still, a proper review of all LFUN
1630 // should be done and this needsUpdate boolean can then be removed.
1631 cur.updateFlags(Update::FitCursor);
1633 cur.updateFlags(Update::Force | Update::FitCursor);
1637 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
1638 FuncStatus & flag) const
1640 BOOST_ASSERT(cur.text() == this);
1642 Font const & font = real_current_font;
1644 Inset::Code code = Inset::NO_CODE;
1646 switch (cmd.action) {
1648 case LFUN_DEPTH_DECREMENT:
1649 enable = changeDepthAllowed(cur, DEC_DEPTH);
1652 case LFUN_DEPTH_INCREMENT:
1653 enable = changeDepthAllowed(cur, INC_DEPTH);
1657 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1660 case LFUN_BIBITEM_INSERT:
1661 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO
1665 case LFUN_DIALOG_SHOW_NEW_INSET:
1666 if (cmd.argument() == "bibitem")
1667 code = Inset::BIBITEM_CODE;
1668 else if (cmd.argument() == "bibtex")
1669 code = Inset::BIBTEX_CODE;
1670 else if (cmd.argument() == "box")
1671 code = Inset::BOX_CODE;
1672 else if (cmd.argument() == "branch")
1673 code = Inset::BRANCH_CODE;
1674 else if (cmd.argument() == "citation")
1675 code = Inset::CITE_CODE;
1676 else if (cmd.argument() == "ert")
1677 code = Inset::ERT_CODE;
1678 else if (cmd.argument() == "external")
1679 code = Inset::EXTERNAL_CODE;
1680 else if (cmd.argument() == "float")
1681 code = Inset::FLOAT_CODE;
1682 else if (cmd.argument() == "graphics")
1683 code = Inset::GRAPHICS_CODE;
1684 else if (cmd.argument() == "include")
1685 code = Inset::INCLUDE_CODE;
1686 else if (cmd.argument() == "index")
1687 code = Inset::INDEX_CODE;
1688 else if (cmd.argument() == "nomenclature")
1689 code = Inset::NOMENCL_CODE;
1690 else if (cmd.argument() == "label")
1691 code = Inset::LABEL_CODE;
1692 else if (cmd.argument() == "note")
1693 code = Inset::NOTE_CODE;
1694 else if (cmd.argument() == "ref")
1695 code = Inset::REF_CODE;
1696 else if (cmd.argument() == "toc")
1697 code = Inset::TOC_CODE;
1698 else if (cmd.argument() == "url")
1699 code = Inset::URL_CODE;
1700 else if (cmd.argument() == "vspace")
1701 code = Inset::VSPACE_CODE;
1702 else if (cmd.argument() == "wrap")
1703 code = Inset::WRAP_CODE;
1704 else if (cmd.argument() == "listings")
1705 code = Inset::LISTINGS_CODE;
1708 case LFUN_ERT_INSERT:
1709 code = Inset::ERT_CODE;
1711 case LFUN_LISTING_INSERT:
1712 code = Inset::LISTINGS_CODE;
1714 case LFUN_FOOTNOTE_INSERT:
1715 code = Inset::FOOT_CODE;
1717 case LFUN_TABULAR_INSERT:
1718 code = Inset::TABULAR_CODE;
1720 case LFUN_MARGINALNOTE_INSERT:
1721 code = Inset::MARGIN_CODE;
1723 case LFUN_FLOAT_INSERT:
1724 case LFUN_FLOAT_WIDE_INSERT:
1725 code = Inset::FLOAT_CODE;
1727 case LFUN_WRAP_INSERT:
1728 code = Inset::WRAP_CODE;
1730 case LFUN_FLOAT_LIST:
1731 code = Inset::FLOAT_LIST_CODE;
1734 case LFUN_LIST_INSERT:
1735 code = Inset::LIST_CODE;
1737 case LFUN_THEOREM_INSERT:
1738 code = Inset::THEOREM_CODE;
1741 case LFUN_CAPTION_INSERT:
1742 code = Inset::CAPTION_CODE;
1744 case LFUN_NOTE_INSERT:
1745 code = Inset::NOTE_CODE;
1747 case LFUN_CHARSTYLE_INSERT:
1748 code = Inset::CHARSTYLE_CODE;
1749 if (cur.buffer().params().getTextClass().charstyles().empty())
1752 case LFUN_BOX_INSERT:
1753 code = Inset::BOX_CODE;
1755 case LFUN_BRANCH_INSERT:
1756 code = Inset::BRANCH_CODE;
1757 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1760 case LFUN_LABEL_INSERT:
1761 code = Inset::LABEL_CODE;
1763 case LFUN_OPTIONAL_INSERT:
1764 code = Inset::OPTARG_CODE;
1765 enable = numberOfOptArgs(cur.paragraph())
1766 < cur.paragraph().layout()->optionalargs;
1768 case LFUN_ENVIRONMENT_INSERT:
1769 code = Inset::BOX_CODE;
1771 case LFUN_INDEX_INSERT:
1772 code = Inset::INDEX_CODE;
1774 case LFUN_INDEX_PRINT:
1775 code = Inset::INDEX_PRINT_CODE;
1777 case LFUN_NOMENCL_INSERT:
1778 code = Inset::NOMENCL_CODE;
1780 case LFUN_NOMENCL_PRINT:
1781 code = Inset::NOMENCL_PRINT_CODE;
1783 case LFUN_TOC_INSERT:
1784 code = Inset::TOC_CODE;
1786 case LFUN_HTML_INSERT:
1787 case LFUN_URL_INSERT:
1788 code = Inset::URL_CODE;
1790 case LFUN_QUOTE_INSERT:
1791 // always allow this, since we will inset a raw quote
1792 // if an inset is not allowed.
1794 case LFUN_HYPHENATION_POINT_INSERT:
1795 case LFUN_LIGATURE_BREAK_INSERT:
1796 case LFUN_HFILL_INSERT:
1797 case LFUN_MENU_SEPARATOR_INSERT:
1798 case LFUN_DOTS_INSERT:
1799 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
1800 code = Inset::SPECIALCHAR_CODE;
1802 case LFUN_SPACE_INSERT:
1803 // slight hack: we know this is allowed in math mode
1805 code = Inset::SPACE_CODE;
1808 case LFUN_INSET_MODIFY:
1809 // We need to disable this, because we may get called for a
1811 // InsetTabular::getStatus() -> InsetText::getStatus()
1812 // and we don't handle LFUN_INSET_MODIFY.
1816 case LFUN_FONT_EMPH:
1817 flag.setOnOff(font.emph() == Font::ON);
1820 case LFUN_FONT_NOUN:
1821 flag.setOnOff(font.noun() == Font::ON);
1824 case LFUN_FONT_BOLD:
1825 flag.setOnOff(font.series() == Font::BOLD_SERIES);
1828 case LFUN_FONT_SANS:
1829 flag.setOnOff(font.family() == Font::SANS_FAMILY);
1832 case LFUN_FONT_ROMAN:
1833 flag.setOnOff(font.family() == Font::ROMAN_FAMILY);
1836 case LFUN_FONT_CODE:
1837 flag.setOnOff(font.family() == Font::TYPEWRITER_FAMILY);
1842 enable = cur.selection();
1846 if (cmd.argument().empty()) {
1847 if (theClipboard().isInternal())
1848 enable = cap::numberOfSelections() > 0;
1850 enable = !theClipboard().empty();
1852 string const arg = to_utf8(cmd.argument());
1853 if (isStrUnsignedInt(arg)) {
1854 unsigned int n = convert<unsigned int>(arg);
1855 enable = cap::numberOfSelections() > n;
1862 case LFUN_CLIPBOARD_PASTE:
1863 enable = !theClipboard().empty();
1866 case LFUN_PRIMARY_SELECTION_PASTE:
1867 enable = cur.selection() || !theSelection().empty();
1870 case LFUN_PARAGRAPH_MOVE_UP:
1871 enable = cur.pit() > 0 && !cur.selection();
1874 case LFUN_PARAGRAPH_MOVE_DOWN:
1875 enable = cur.pit() < cur.lastpit() && !cur.selection();
1878 case LFUN_INSET_DISSOLVE:
1879 enable = !isMainText(*cur.bv().buffer()) && cur.inset().nargs() == 1;
1882 case LFUN_CHANGE_ACCEPT:
1883 case LFUN_CHANGE_REJECT:
1884 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
1885 // In principle, these LFUNs should only be enabled if there
1886 // is a change at the current position/in the current selection.
1887 // However, without proper optimizations, this will inevitably
1888 // result in unacceptable performance - just imagine a user who
1889 // wants to select the complete content of a long document.
1893 case LFUN_WORD_DELETE_FORWARD:
1894 case LFUN_WORD_DELETE_BACKWARD:
1895 case LFUN_LINE_DELETE:
1896 case LFUN_WORD_FORWARD:
1897 case LFUN_WORD_BACKWARD:
1898 case LFUN_CHAR_FORWARD:
1899 case LFUN_CHAR_FORWARD_SELECT:
1900 case LFUN_CHAR_BACKWARD:
1901 case LFUN_CHAR_BACKWARD_SELECT:
1903 case LFUN_UP_SELECT:
1905 case LFUN_DOWN_SELECT:
1906 case LFUN_PARAGRAPH_UP_SELECT:
1907 case LFUN_PARAGRAPH_DOWN_SELECT:
1908 case LFUN_SCREEN_UP_SELECT:
1909 case LFUN_SCREEN_DOWN_SELECT:
1910 case LFUN_LINE_BEGIN_SELECT:
1911 case LFUN_LINE_END_SELECT:
1912 case LFUN_WORD_FORWARD_SELECT:
1913 case LFUN_WORD_BACKWARD_SELECT:
1914 case LFUN_WORD_SELECT:
1915 case LFUN_PARAGRAPH_UP:
1916 case LFUN_PARAGRAPH_DOWN:
1917 case LFUN_SCREEN_UP:
1918 case LFUN_SCREEN_DOWN:
1919 case LFUN_LINE_BEGIN:
1921 case LFUN_BREAK_LINE:
1922 case LFUN_CHAR_DELETE_FORWARD:
1923 case LFUN_DELETE_FORWARD_SKIP:
1924 case LFUN_CHAR_DELETE_BACKWARD:
1925 case LFUN_DELETE_BACKWARD_SKIP:
1926 case LFUN_BREAK_PARAGRAPH:
1927 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
1928 case LFUN_BREAK_PARAGRAPH_SKIP:
1929 case LFUN_PARAGRAPH_SPACING:
1930 case LFUN_INSET_INSERT:
1931 case LFUN_WORD_UPCASE:
1932 case LFUN_WORD_LOWCASE:
1933 case LFUN_WORD_CAPITALIZE:
1934 case LFUN_CHARS_TRANSPOSE:
1935 case LFUN_SERVER_GET_XY:
1936 case LFUN_SERVER_SET_XY:
1937 case LFUN_SERVER_GET_FONT:
1938 case LFUN_SERVER_GET_LAYOUT:
1940 case LFUN_DATE_INSERT:
1941 case LFUN_SELF_INSERT:
1942 case LFUN_LINE_INSERT:
1943 case LFUN_PAGEBREAK_INSERT:
1944 case LFUN_CLEARPAGE_INSERT:
1945 case LFUN_CLEARDOUBLEPAGE_INSERT:
1946 case LFUN_MATH_DISPLAY:
1947 case LFUN_MATH_IMPORT_SELECTION:
1948 case LFUN_MATH_MODE:
1949 case LFUN_MATH_MACRO:
1950 case LFUN_MATH_MATRIX:
1951 case LFUN_MATH_DELIM:
1952 case LFUN_MATH_BIGDELIM:
1953 case LFUN_MATH_SUBSCRIPT:
1954 case LFUN_MATH_SUPERSCRIPT:
1955 case LFUN_FONT_DEFAULT:
1956 case LFUN_FONT_UNDERLINE:
1957 case LFUN_FONT_SIZE:
1959 case LFUN_FONT_FREE_APPLY:
1960 case LFUN_FONT_FREE_UPDATE:
1961 case LFUN_LAYOUT_PARAGRAPH:
1962 case LFUN_PARAGRAPH_UPDATE:
1963 case LFUN_ACCENT_UMLAUT:
1964 case LFUN_ACCENT_CIRCUMFLEX:
1965 case LFUN_ACCENT_GRAVE:
1966 case LFUN_ACCENT_ACUTE:
1967 case LFUN_ACCENT_TILDE:
1968 case LFUN_ACCENT_CEDILLA:
1969 case LFUN_ACCENT_MACRON:
1970 case LFUN_ACCENT_DOT:
1971 case LFUN_ACCENT_UNDERDOT:
1972 case LFUN_ACCENT_UNDERBAR:
1973 case LFUN_ACCENT_CARON:
1974 case LFUN_ACCENT_SPECIAL_CARON:
1975 case LFUN_ACCENT_BREVE:
1976 case LFUN_ACCENT_TIE:
1977 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1978 case LFUN_ACCENT_CIRCLE:
1979 case LFUN_ACCENT_OGONEK:
1980 case LFUN_THESAURUS_ENTRY:
1981 case LFUN_PARAGRAPH_PARAMS_APPLY:
1983 case LFUN_BUFFER_END:
1984 case LFUN_BUFFER_BEGIN:
1985 case LFUN_BUFFER_BEGIN_SELECT:
1986 case LFUN_BUFFER_END_SELECT:
1987 case LFUN_UNICODE_INSERT:
1988 // these are handled in our dispatch()
1996 if (code != Inset::NO_CODE
1997 && (cur.empty() || !cur.inset().insetAllowed(code)))
2000 flag.enabled(enable);
2005 void Text::pasteString(Cursor & cur, docstring const & clip,
2008 cur.clearSelection();
2009 if (!clip.empty()) {
2012 insertStringAsParagraphs(cur, clip);
2014 insertStringAsLines(cur, clip);