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);
473 needsUpdate |= cur.upDownInText(true);
475 if (!needsUpdate && oldTopSlice == cur.top()
476 && cur.boundary() == oldBoundary)
483 case LFUN_DOWN_SELECT:
484 //lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
485 needsUpdate |= cur.selHandle(cmd.action == LFUN_DOWN_SELECT);
486 needsUpdate |= cur.upDownInText(false);
488 if (!needsUpdate && oldTopSlice == cur.top() &&
489 cur.boundary() == oldBoundary)
495 case LFUN_PARAGRAPH_UP:
496 case LFUN_PARAGRAPH_UP_SELECT:
497 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
498 needsUpdate |= cursorUpParagraph(cur);
503 case LFUN_PARAGRAPH_DOWN:
504 case LFUN_PARAGRAPH_DOWN_SELECT:
505 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
506 needsUpdate |= cursorDownParagraph(cur);
512 case LFUN_SCREEN_UP_SELECT:
513 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_UP_SELECT);
514 if (cur.pit() == 0 && cur.textRow().pos() == 0)
523 case LFUN_SCREEN_DOWN:
524 case LFUN_SCREEN_DOWN_SELECT:
525 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_DOWN_SELECT);
526 if (cur.pit() == cur.lastpit()
527 && cur.textRow().endpos() == cur.lastpos())
536 case LFUN_LINE_BEGIN:
537 case LFUN_LINE_BEGIN_SELECT:
538 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
539 needsUpdate |= cursorHome(cur);
543 case LFUN_LINE_END_SELECT:
544 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
545 needsUpdate |= cursorEnd(cur);
550 case LFUN_WORD_FORWARD:
551 case LFUN_WORD_FORWARD_SELECT:
552 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
553 if (reverseDirectionNeeded(cur))
554 needsUpdate |= cursorLeftOneWord(cur);
556 needsUpdate |= cursorRightOneWord(cur);
561 case LFUN_WORD_BACKWARD:
562 case LFUN_WORD_BACKWARD_SELECT:
563 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
564 if (reverseDirectionNeeded(cur))
565 needsUpdate |= cursorRightOneWord(cur);
567 needsUpdate |= cursorLeftOneWord(cur);
572 case LFUN_WORD_SELECT: {
573 selectWord(cur, WHOLE_WORD);
574 finishChange(cur, true);
578 case LFUN_BREAK_LINE: {
579 // Not allowed by LaTeX (labels or empty par)
580 if (cur.pos() > cur.paragraph().beginOfBody()) {
581 // this avoids a double undo
582 // FIXME: should not be needed, ideally
583 if (!cur.selection())
585 cap::replaceSelection(cur);
586 cur.insert(new InsetNewline);
588 moveCursor(cur, false);
593 case LFUN_CHAR_DELETE_FORWARD:
594 if (!cur.selection()) {
595 if (cur.pos() == cur.paragraph().size())
596 // Par boundary, force full-screen update
597 singleParUpdate = false;
598 needsUpdate |= erase(cur);
600 // It is possible to make it a lot faster still
601 // just comment out the line below...
603 cutSelection(cur, true, false);
604 singleParUpdate = false;
606 moveCursor(cur, false);
609 case LFUN_DELETE_FORWARD_SKIP:
610 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
611 if (!cur.selection()) {
612 if (cur.pos() == cur.lastpos()) {
619 cutSelection(cur, true, false);
624 case LFUN_CHAR_DELETE_BACKWARD:
625 if (!cur.selection()) {
626 if (bv->getIntl().getTransManager().backspace()) {
627 // Par boundary, full-screen update
629 singleParUpdate = false;
630 needsUpdate |= backspace(cur);
632 // It is possible to make it a lot faster still
633 // just comment out the line below...
636 cutSelection(cur, true, false);
637 singleParUpdate = false;
642 case LFUN_DELETE_BACKWARD_SKIP:
643 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
644 if (!cur.selection()) {
648 //CursorSlice cur = cursor();
652 cutSelection(cur, true, false);
656 case LFUN_BREAK_PARAGRAPH:
657 cap::replaceSelection(cur);
658 breakParagraph(cur, 0);
663 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
664 cap::replaceSelection(cur);
665 breakParagraph(cur, 1);
670 case LFUN_BREAK_PARAGRAPH_SKIP: {
671 // When at the beginning of a paragraph, remove
672 // indentation. Otherwise, do the same as LFUN_BREAK_PARAGRAPH.
673 cap::replaceSelection(cur);
675 cur.paragraph().params().labelWidthString(docstring());
677 breakParagraph(cur, 0);
683 case LFUN_PARAGRAPH_SPACING: {
684 Paragraph & par = cur.paragraph();
685 Spacing::Space cur_spacing = par.params().spacing().getSpace();
686 string cur_value = "1.0";
687 if (cur_spacing == Spacing::Other)
688 cur_value = par.params().spacing().getValueAsString();
690 istringstream is(to_utf8(cmd.argument()));
693 Spacing::Space new_spacing = cur_spacing;
694 string new_value = cur_value;
696 lyxerr << "Missing argument to `paragraph-spacing'"
698 } else if (tmp == "single") {
699 new_spacing = Spacing::Single;
700 } else if (tmp == "onehalf") {
701 new_spacing = Spacing::Onehalf;
702 } else if (tmp == "double") {
703 new_spacing = Spacing::Double;
704 } else if (tmp == "other") {
705 new_spacing = Spacing::Other;
706 string tmpval = "0.0";
708 lyxerr << "new_value = " << tmpval << endl;
711 } else if (tmp == "default") {
712 new_spacing = Spacing::Default;
714 lyxerr << to_utf8(_("Unknown spacing argument: "))
715 << to_utf8(cmd.argument()) << endl;
717 if (cur_spacing != new_spacing || cur_value != new_value)
718 par.params().spacing(Spacing(new_spacing, new_value));
722 case LFUN_INSET_INSERT: {
724 Inset * inset = createInset(bv, cmd);
726 // FIXME (Abdel 01/02/2006):
727 // What follows would be a partial fix for bug 2154:
728 // http://bugzilla.lyx.org/show_bug.cgi?id=2154
729 // This automatically put the label inset _after_ a
730 // numbered section. It should be possible to extend the mechanism
731 // to any kind of LateX environement.
732 // The correct way to fix that bug would be at LateX generation.
733 // I'll let the code here for reference as it could be used for some
734 // other feature like "automatic labelling".
736 Paragraph & par = pars_[cur.pit()];
737 if (inset->lyxCode() == Inset::LABEL_CODE
738 && par.layout()->labeltype == LABEL_COUNTER) {
739 // Go to the end of the paragraph
740 // Warning: Because of Change-Tracking, the last
741 // position is 'size()' and not 'size()-1':
742 cur.pos() = par.size();
743 // Insert a new paragraph
744 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
748 insertInset(cur, inset);
754 case LFUN_INSET_DISSOLVE:
755 needsUpdate |= dissolveInset(cur);
758 case LFUN_INSET_SETTINGS:
759 cur.inset().showInsetDialog(bv);
762 case LFUN_SPACE_INSERT:
763 if (cur.paragraph().layout()->free_spacing)
764 insertChar(cur, ' ');
766 doInsertInset(cur, this, cmd, false, false);
769 moveCursor(cur, false);
772 case LFUN_HYPHENATION_POINT_INSERT:
773 specialChar(cur, InsetSpecialChar::HYPHENATION);
776 case LFUN_LIGATURE_BREAK_INSERT:
777 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
780 case LFUN_DOTS_INSERT:
781 specialChar(cur, InsetSpecialChar::LDOTS);
784 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
785 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
788 case LFUN_MENU_SEPARATOR_INSERT:
789 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
792 case LFUN_WORD_UPCASE:
793 changeCase(cur, Text::text_uppercase);
796 case LFUN_WORD_LOWCASE:
797 changeCase(cur, Text::text_lowercase);
800 case LFUN_WORD_CAPITALIZE:
801 changeCase(cur, Text::text_capitalization);
804 case LFUN_CHARS_TRANSPOSE:
809 cur.message(_("Paste"));
810 cap::replaceSelection(cur);
811 if (cmd.argument().empty() && !theClipboard().isInternal())
812 pasteClipboard(cur, bv->buffer()->errorList("Paste"));
814 string const arg(to_utf8(cmd.argument()));
815 pasteFromStack(cur, bv->buffer()->errorList("Paste"),
816 isStrUnsignedInt(arg) ?
817 convert<unsigned int>(arg) :
820 bv->buffer()->errors("Paste");
821 cur.clearSelection(); // bug 393
827 cutSelection(cur, true, true);
828 cur.message(_("Cut"));
833 cur.message(_("Copy"));
836 case LFUN_SERVER_GET_XY:
837 cur.message(from_utf8(
838 convert<string>(cursorX(cur.bv(), cur.top(), cur.boundary()))
839 + ' ' + convert<string>(cursorY(cur.bv(), cur.top(), cur.boundary()))));
842 case LFUN_SERVER_SET_XY: {
845 istringstream is(to_utf8(cmd.argument()));
848 lyxerr << "SETXY: Could not parse coordinates in '"
849 << to_utf8(cmd.argument()) << std::endl;
851 setCursorFromCoordinates(cur, x, y);
855 case LFUN_SERVER_GET_FONT:
856 if (current_font.shape() == Font::ITALIC_SHAPE)
857 cur.message(from_ascii("E"));
858 else if (current_font.shape() == Font::SMALLCAPS_SHAPE)
859 cur.message(from_ascii("N"));
861 cur.message(from_ascii("0"));
864 case LFUN_SERVER_GET_LAYOUT:
865 cur.message(from_utf8(cur.paragraph().layout()->name()));
869 string layout = to_ascii(cmd.argument());
870 LYXERR(Debug::INFO) << "LFUN_LAYOUT: (arg) " << layout << endl;
872 // Derive layout number from given argument (string)
873 // and current buffer's textclass (number)
874 TextClass const & tclass = bv->buffer()->params().getTextClass();
876 layout = tclass.defaultLayoutName();
877 bool hasLayout = tclass.hasLayout(layout);
879 // If the entry is obsolete, use the new one instead.
881 string const & obs = tclass[layout]->obsoleted_by();
887 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
888 from_utf8(N_(" not known")));
892 bool change_layout = (current_layout != layout);
894 if (!change_layout && cur.selection() &&
895 cur.selBegin().pit() != cur.selEnd().pit())
897 pit_type spit = cur.selBegin().pit();
898 pit_type epit = cur.selEnd().pit() + 1;
899 while (spit != epit) {
900 if (pars_[spit].layout()->name() != current_layout) {
901 change_layout = true;
909 current_layout = layout;
910 setLayout(cur, layout);
911 // inform the GUI that the layout has changed.
912 bv->layoutChanged(layout);
918 case LFUN_CLIPBOARD_PASTE:
919 cur.clearSelection();
920 pasteClipboard(cur, bv->buffer()->errorList("Paste"),
921 cmd.argument() == "paragraph");
922 bv->buffer()->errors("Paste");
925 case LFUN_PRIMARY_SELECTION_PASTE:
926 pasteString(cur, theSelection().get(),
927 cmd.argument() == "paragraph");
930 case LFUN_UNICODE_INSERT: {
931 if (cmd.argument().empty())
933 docstring hexstring = cmd.argument();
934 if (lyx::support::isHex(hexstring)) {
935 char_type c = lyx::support::hexToInt(hexstring);
936 if (c > 32 && c < 0x10ffff) {
937 lyxerr << "Inserting c: " << c << endl;
938 docstring s = docstring(1, c);
939 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
945 case LFUN_QUOTE_INSERT: {
946 Paragraph & par = cur.paragraph();
947 pos_type pos = cur.pos();
948 BufferParams const & bufparams = bv->buffer()->params();
949 Layout_ptr const & style = par.layout();
950 if (!style->pass_thru
951 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
952 // this avoids a double undo
953 // FIXME: should not be needed, ideally
954 if (!cur.selection())
956 cap::replaceSelection(cur);
961 else if (cur.prevInset() && cur.prevInset()->isSpace())
964 c = par.getChar(pos - 1);
965 string arg = to_utf8(cmd.argument());
967 cur.insert(new InsetQuotes(c,
968 bufparams.quotes_language,
969 InsetQuotes::SingleQ));
971 cur.insert(new InsetQuotes(c,
972 bufparams.quotes_language,
973 InsetQuotes::DoubleQ));
977 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
981 case LFUN_DATE_INSERT:
982 if (cmd.argument().empty())
983 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
984 formatted_time(current_time())));
986 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
987 formatted_time(current_time(), to_utf8(cmd.argument()))));
990 case LFUN_MOUSE_TRIPLE:
991 if (cmd.button() == mouse_button::button1) {
1001 case LFUN_MOUSE_DOUBLE:
1002 if (cmd.button() == mouse_button::button1) {
1003 selectWord(cur, WHOLE_WORD_STRICT);
1008 // Single-click on work area
1009 case LFUN_MOUSE_PRESS: {
1010 // Right click on a footnote flag opens float menu
1011 if (cmd.button() == mouse_button::button3)
1012 cur.clearSelection();
1014 // Middle button press pastes if we have a selection
1015 // We do this here as if the selection was inside an inset
1016 // it could get cleared on the unlocking of the inset so
1017 // we have to check this first
1018 bool paste_internally = false;
1019 if (cmd.button() == mouse_button::button2 && cap::selection()) {
1020 // Copy the selection buffer to the clipboard
1021 // stack, because we want it to appear in the
1022 // "Edit->Paste recent" menu.
1023 cap::copySelectionToStack();
1024 paste_internally = true;
1027 // we have to update after dePM triggered
1028 bool update = bv->mouseSetCursor(cur);
1030 // Insert primary selection with middle mouse
1031 // if there is a local selection in the current buffer,
1033 if (cmd.button() == mouse_button::button2) {
1034 if (paste_internally) {
1035 cap::pasteSelection(cur, bv->buffer()->errorList("Paste"));
1036 bv->buffer()->errors("Paste");
1037 cur.clearSelection(); // bug 393
1041 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
1044 if (!update && cmd.button() == mouse_button::button1) {
1045 needsUpdate = false;
1052 case LFUN_MOUSE_MOTION: {
1053 // Only use motion with button 1
1054 //if (cmd.button() != mouse_button::button1)
1057 // ignore motions deeper nested than the real anchor
1058 Cursor & bvcur = cur.bv().cursor();
1059 if (bvcur.anchor_.hasPart(cur)) {
1060 CursorSlice old = bvcur.top();
1062 int const wh = bv->workHeight();
1063 int const y = std::max(0, std::min(wh - 1, cmd.y));
1065 setCursorFromCoordinates(cur, cmd.x, y);
1066 cur.setTargetX(cmd.x);
1068 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1070 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1071 // This is to allow jumping over large insets
1072 if (cur.top() == old) {
1074 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1076 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1079 if (cur.top() == old)
1082 // don't set anchor_
1083 bvcur.setCursor(cur);
1084 bvcur.selection() = true;
1085 //lyxerr << "MOTION: " << bv->cursor() << endl;
1093 case LFUN_MOUSE_RELEASE: {
1094 if (cmd.button() == mouse_button::button2)
1097 if (cmd.button() == mouse_button::button1) {
1098 // if there is new selection, update persistent
1099 // selection, otherwise, single click does not
1100 // clear persistent selection buffer
1101 if (cur.selection()) {
1103 // if double click, cur is moved to the end of word by selectWord
1104 // but bvcur is current mouse position
1105 Cursor & bvcur = cur.bv().cursor();
1106 bvcur.selection() = true;
1107 saveSelection(bvcur);
1109 needsUpdate = false;
1117 case LFUN_SELF_INSERT: {
1118 if (cmd.argument().empty())
1121 // Automatically delete the currently selected
1122 // text and replace it with what is being
1123 // typed in now. Depends on lyxrc settings
1124 // "auto_region_delete", which defaults to
1127 if (lyxrc.auto_region_delete)
1128 if (cur.selection())
1129 cutSelection(cur, false, false);
1131 cur.clearSelection();
1132 Font const old_font = real_current_font;
1134 docstring::const_iterator cit = cmd.argument().begin();
1135 docstring::const_iterator end = cmd.argument().end();
1136 for (; cit != end; ++cit)
1137 bv->getIntl().getTransManager().
1138 translateAndInsert(*cit, this, cur);
1141 moveCursor(cur, false);
1145 case LFUN_URL_INSERT: {
1146 InsetCommandParams p("url");
1147 string const data = InsetCommandMailer::params2string("url", p);
1148 bv->showInsetDialog("url", data, 0);
1152 case LFUN_HTML_INSERT: {
1153 InsetCommandParams p("htmlurl");
1154 string const data = InsetCommandMailer::params2string("url", p);
1155 bv->showInsetDialog("url", data, 0);
1159 case LFUN_LABEL_INSERT: {
1160 InsetCommandParams p("label");
1161 // Try to generate a valid label
1162 p["name"] = (cmd.argument().empty()) ?
1163 cur.getPossibleLabel() :
1165 string const data = InsetCommandMailer::params2string("label", p);
1167 if (cmd.argument().empty()) {
1168 bv->showInsetDialog("label", data, 0);
1170 FuncRequest fr(LFUN_INSET_INSERT, data);
1178 case LFUN_LIST_INSERT:
1179 case LFUN_THEOREM_INSERT:
1181 case LFUN_CAPTION_INSERT:
1182 // Open the inset, and move the current selection
1184 doInsertInset(cur, this, cmd, true, true);
1186 updateLabels(*bv->buffer());
1188 case LFUN_NOTE_INSERT:
1189 case LFUN_CHARSTYLE_INSERT:
1190 case LFUN_BOX_INSERT:
1191 case LFUN_BRANCH_INSERT:
1192 case LFUN_BIBITEM_INSERT:
1193 case LFUN_ERT_INSERT:
1194 case LFUN_LISTING_INSERT:
1195 case LFUN_FOOTNOTE_INSERT:
1196 case LFUN_MARGINALNOTE_INSERT:
1197 case LFUN_OPTIONAL_INSERT:
1198 case LFUN_ENVIRONMENT_INSERT:
1199 // Open the inset, and move the current selection
1201 doInsertInset(cur, this, cmd, true, true);
1205 case LFUN_TABULAR_INSERT:
1206 // if there were no arguments, just open the dialog
1207 if (doInsertInset(cur, this, cmd, false, true))
1210 bv->showDialog("tabularcreate");
1214 case LFUN_FLOAT_INSERT:
1215 case LFUN_FLOAT_WIDE_INSERT:
1216 case LFUN_WRAP_INSERT: {
1217 bool content = cur.selection(); // will some text be moved into the inset?
1219 doInsertInset(cur, this, cmd, true, true);
1221 ParagraphList & pars = cur.text()->paragraphs();
1223 TextClass const & tclass = bv->buffer()->params().getTextClass();
1225 // add a separate paragraph for the caption inset
1226 pars.push_back(Paragraph());
1227 pars.back().setInsetOwner(pars[0].inInset());
1228 pars.back().layout(tclass.defaultLayout());
1230 int cap_pit = pars.size() - 1;
1232 // if an empty inset was created, we create an additional empty
1233 // paragraph at the bottom so that the user can choose where to put
1234 // the graphics (or table).
1236 pars.push_back(Paragraph());
1237 pars.back().setInsetOwner(pars[0].inInset());
1238 pars.back().layout(tclass.defaultLayout());
1242 // reposition the cursor to the caption
1243 cur.pit() = cap_pit;
1245 cur.dispatch(FuncRequest(LFUN_CAPTION_INSERT));
1246 // FIXME: When leaving the Float (or Wrap) inset we should
1247 // delete any empty paragraph left above or below the
1252 case LFUN_INDEX_INSERT:
1253 case LFUN_NOMENCL_INSERT: {
1254 Inset * inset = createInset(&cur.bv(), cmd);
1258 cur.clearSelection();
1259 insertInset(cur, inset);
1260 inset->edit(cur, true);
1261 // Show the dialog for the nomenclature entry, since the
1262 // description entry still needs to be filled in.
1263 if (cmd.action == LFUN_NOMENCL_INSERT)
1264 InsetCommandMailer("nomenclature",
1265 *reinterpret_cast<InsetCommand *>(inset)).showDialog(&cur.bv());
1270 case LFUN_INDEX_PRINT:
1271 case LFUN_NOMENCL_PRINT:
1272 case LFUN_TOC_INSERT:
1273 case LFUN_HFILL_INSERT:
1274 case LFUN_LINE_INSERT:
1275 case LFUN_PAGEBREAK_INSERT:
1276 case LFUN_CLEARPAGE_INSERT:
1277 case LFUN_CLEARDOUBLEPAGE_INSERT:
1279 doInsertInset(cur, this, cmd, false, false);
1283 case LFUN_DEPTH_DECREMENT:
1284 changeDepth(cur, DEC_DEPTH);
1287 case LFUN_DEPTH_INCREMENT:
1288 changeDepth(cur, INC_DEPTH);
1291 case LFUN_MATH_DISPLAY:
1292 mathDispatch(cur, cmd, true);
1295 case LFUN_MATH_IMPORT_SELECTION:
1296 case LFUN_MATH_MODE:
1297 if (cmd.argument() == "on")
1298 // don't pass "on" as argument
1299 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1301 mathDispatch(cur, cmd, false);
1304 case LFUN_MATH_MACRO:
1305 if (cmd.argument().empty())
1306 cur.errorMessage(from_utf8(N_("Missing argument")));
1308 string s = to_utf8(cmd.argument());
1309 string const s1 = token(s, ' ', 1);
1310 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1311 string const s2 = token(s, ' ', 2);
1312 string const type = s2.empty() ? "newcommand" : s2;
1313 cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, from_utf8(type)));
1314 //cur.nextInset()->edit(cur, true);
1318 // passthrough hat and underscore outside mathed:
1319 case LFUN_MATH_SUBSCRIPT:
1320 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1322 case LFUN_MATH_SUPERSCRIPT:
1323 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1326 case LFUN_MATH_INSERT:
1327 case LFUN_MATH_MATRIX:
1328 case LFUN_MATH_DELIM:
1329 case LFUN_MATH_BIGDELIM: {
1330 cur.insert(new InsetMathHull(hullSimple));
1331 cur.dispatch(FuncRequest(LFUN_CHAR_FORWARD));
1332 BOOST_ASSERT(cur.inMathed());
1337 case LFUN_FONT_EMPH: {
1338 Font font(Font::ALL_IGNORE);
1339 font.setEmph(Font::TOGGLE);
1340 toggleAndShow(cur, this, font);
1344 case LFUN_FONT_BOLD: {
1345 Font font(Font::ALL_IGNORE);
1346 font.setSeries(Font::BOLD_SERIES);
1347 toggleAndShow(cur, this, font);
1351 case LFUN_FONT_NOUN: {
1352 Font font(Font::ALL_IGNORE);
1353 font.setNoun(Font::TOGGLE);
1354 toggleAndShow(cur, this, font);
1358 case LFUN_FONT_CODE: {
1359 Font font(Font::ALL_IGNORE);
1360 font.setFamily(Font::TYPEWRITER_FAMILY); // no good
1361 toggleAndShow(cur, this, font);
1365 case LFUN_FONT_SANS: {
1366 Font font(Font::ALL_IGNORE);
1367 font.setFamily(Font::SANS_FAMILY);
1368 toggleAndShow(cur, this, font);
1372 case LFUN_FONT_ROMAN: {
1373 Font font(Font::ALL_IGNORE);
1374 font.setFamily(Font::ROMAN_FAMILY);
1375 toggleAndShow(cur, this, font);
1379 case LFUN_FONT_DEFAULT: {
1380 Font font(Font::ALL_INHERIT, ignore_language);
1381 toggleAndShow(cur, this, font);
1385 case LFUN_FONT_UNDERLINE: {
1386 Font font(Font::ALL_IGNORE);
1387 font.setUnderbar(Font::TOGGLE);
1388 toggleAndShow(cur, this, font);
1392 case LFUN_FONT_SIZE: {
1393 Font font(Font::ALL_IGNORE);
1394 font.setLyXSize(to_utf8(cmd.argument()));
1395 toggleAndShow(cur, this, font);
1399 case LFUN_LANGUAGE: {
1400 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1403 Font font(Font::ALL_IGNORE);
1404 font.setLanguage(lang);
1405 toggleAndShow(cur, this, font);
1410 case LFUN_FONT_FREE_APPLY:
1411 toggleAndShow(cur, this, freefont, toggleall);
1412 cur.message(_("Character set"));
1415 // Set the freefont using the contents of \param data dispatched from
1416 // the frontends and apply it at the current cursor location.
1417 case LFUN_FONT_FREE_UPDATE: {
1420 if (bv_funcs::string2font(to_utf8(cmd.argument()), font, toggle)) {
1423 toggleAndShow(cur, this, freefont, toggleall);
1424 cur.message(_("Character set"));
1429 case LFUN_FINISHED_LEFT:
1430 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1431 if (reverseDirectionNeeded(cur))
1435 case LFUN_FINISHED_RIGHT:
1436 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1437 if (!reverseDirectionNeeded(cur))
1441 case LFUN_LAYOUT_PARAGRAPH: {
1443 params2string(cur.paragraph(), data);
1444 data = "show\n" + data;
1445 bv->showDialogWithData("paragraph", data);
1449 case LFUN_PARAGRAPH_UPDATE: {
1451 params2string(cur.paragraph(), data);
1453 // Will the paragraph accept changes from the dialog?
1454 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1456 data = "update " + convert<string>(accept) + '\n' + data;
1457 bv->updateDialog("paragraph", data);
1461 case LFUN_ACCENT_UMLAUT:
1462 case LFUN_ACCENT_CIRCUMFLEX:
1463 case LFUN_ACCENT_GRAVE:
1464 case LFUN_ACCENT_ACUTE:
1465 case LFUN_ACCENT_TILDE:
1466 case LFUN_ACCENT_CEDILLA:
1467 case LFUN_ACCENT_MACRON:
1468 case LFUN_ACCENT_DOT:
1469 case LFUN_ACCENT_UNDERDOT:
1470 case LFUN_ACCENT_UNDERBAR:
1471 case LFUN_ACCENT_CARON:
1472 case LFUN_ACCENT_SPECIAL_CARON:
1473 case LFUN_ACCENT_BREVE:
1474 case LFUN_ACCENT_TIE:
1475 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1476 case LFUN_ACCENT_CIRCLE:
1477 case LFUN_ACCENT_OGONEK:
1478 theLyXFunc().handleKeyFunc(cmd.action);
1479 if (!cmd.argument().empty())
1480 // FIXME: Are all these characters encoded in one byte in utf8?
1481 bv->getIntl().getTransManager()
1482 .translateAndInsert(cmd.argument()[0], this, cur);
1485 case LFUN_FLOAT_LIST: {
1486 TextClass const & tclass = bv->buffer()->params().getTextClass();
1487 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1488 // not quite sure if we want this...
1490 cur.clearSelection();
1491 breakParagraph(cur);
1493 if (cur.lastpos() != 0) {
1495 breakParagraph(cur);
1498 setLayout(cur, tclass.defaultLayoutName());
1499 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, docstring(), 0);
1500 insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1503 lyxerr << "Non-existent float type: "
1504 << to_utf8(cmd.argument()) << endl;
1509 case LFUN_CHANGE_ACCEPT: {
1510 acceptOrRejectChanges(cur, ACCEPT);
1514 case LFUN_CHANGE_REJECT: {
1515 acceptOrRejectChanges(cur, REJECT);
1519 case LFUN_THESAURUS_ENTRY: {
1520 docstring arg = cmd.argument();
1522 arg = cur.selectionAsString(false);
1524 if (arg.size() > 100 || arg.empty()) {
1525 // Get word or selection
1526 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1527 arg = cur.selectionAsString(false);
1530 bv->showDialogWithData("thesaurus", to_utf8(arg));
1534 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1535 // Given data, an encoding of the ParagraphParameters
1536 // generated in the Paragraph dialog, this function sets
1537 // the current paragraph appropriately.
1538 istringstream is(to_utf8(cmd.argument()));
1541 ParagraphParameters params;
1546 params.labelWidthString(),
1548 cur.message(_("Paragraph layout set"));
1553 if (cur.selection()) {
1554 cur.selection() = false;
1558 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1563 LYXERR(Debug::ACTION)
1564 << BOOST_CURRENT_FUNCTION
1565 << ": Command " << cmd
1566 << " not DISPATCHED by Text" << endl;
1571 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1573 // FIXME: The cursor flag is reset two lines below
1574 // so we need to check here if some of the LFUN did touch that.
1575 // for now only Text::erase() and Text::backspace() do that.
1576 // The plan is to verify all the LFUNs and then to remove this
1577 // singleParUpdate boolean altogether.
1578 if (cur.result().update() & Update::Force) {
1579 singleParUpdate = false;
1583 // FIXME: the following code should go in favor of fine grained
1584 // update flag treatment.
1585 if (singleParUpdate) {
1586 // Inserting characters does not change par height
1587 ParagraphMetrics const & pms
1588 = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
1589 if (pms.dim().height()
1590 == olddim.height()) {
1591 // if so, update _only_ this paragraph
1592 cur.updateFlags(Update::SinglePar |
1594 Update::MultiParSel);
1601 && &oldTopSlice.inset() == &cur.inset()
1602 && oldTopSlice.idx() == cur.idx()
1603 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1604 && !cur.selection())
1605 // FIXME: it would be better if we could just do this
1607 //if (cur.result().update() != Update::FitCursor)
1610 // But some LFUNs do not set Update::FitCursor when needed, so we
1611 // do it for all. This is not very harmfull as FitCursor will provoke
1612 // a full redraw only if needed but still, a proper review of all LFUN
1613 // should be done and this needsUpdate boolean can then be removed.
1614 cur.updateFlags(Update::FitCursor);
1616 cur.updateFlags(Update::Force | Update::FitCursor);
1620 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
1621 FuncStatus & flag) const
1623 BOOST_ASSERT(cur.text() == this);
1625 Font const & font = real_current_font;
1627 Inset::Code code = Inset::NO_CODE;
1629 switch (cmd.action) {
1631 case LFUN_DEPTH_DECREMENT:
1632 enable = changeDepthAllowed(cur, DEC_DEPTH);
1635 case LFUN_DEPTH_INCREMENT:
1636 enable = changeDepthAllowed(cur, INC_DEPTH);
1640 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1643 case LFUN_BIBITEM_INSERT:
1644 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO
1648 case LFUN_DIALOG_SHOW_NEW_INSET:
1649 if (cmd.argument() == "bibitem")
1650 code = Inset::BIBITEM_CODE;
1651 else if (cmd.argument() == "bibtex")
1652 code = Inset::BIBTEX_CODE;
1653 else if (cmd.argument() == "box")
1654 code = Inset::BOX_CODE;
1655 else if (cmd.argument() == "branch")
1656 code = Inset::BRANCH_CODE;
1657 else if (cmd.argument() == "citation")
1658 code = Inset::CITE_CODE;
1659 else if (cmd.argument() == "ert")
1660 code = Inset::ERT_CODE;
1661 else if (cmd.argument() == "external")
1662 code = Inset::EXTERNAL_CODE;
1663 else if (cmd.argument() == "float")
1664 code = Inset::FLOAT_CODE;
1665 else if (cmd.argument() == "graphics")
1666 code = Inset::GRAPHICS_CODE;
1667 else if (cmd.argument() == "include")
1668 code = Inset::INCLUDE_CODE;
1669 else if (cmd.argument() == "index")
1670 code = Inset::INDEX_CODE;
1671 else if (cmd.argument() == "nomenclature")
1672 code = Inset::NOMENCL_CODE;
1673 else if (cmd.argument() == "label")
1674 code = Inset::LABEL_CODE;
1675 else if (cmd.argument() == "note")
1676 code = Inset::NOTE_CODE;
1677 else if (cmd.argument() == "ref")
1678 code = Inset::REF_CODE;
1679 else if (cmd.argument() == "toc")
1680 code = Inset::TOC_CODE;
1681 else if (cmd.argument() == "url")
1682 code = Inset::URL_CODE;
1683 else if (cmd.argument() == "vspace")
1684 code = Inset::VSPACE_CODE;
1685 else if (cmd.argument() == "wrap")
1686 code = Inset::WRAP_CODE;
1687 else if (cmd.argument() == "listings")
1688 code = Inset::LISTINGS_CODE;
1691 case LFUN_ERT_INSERT:
1692 code = Inset::ERT_CODE;
1694 case LFUN_LISTING_INSERT:
1695 code = Inset::LISTINGS_CODE;
1697 case LFUN_FOOTNOTE_INSERT:
1698 code = Inset::FOOT_CODE;
1700 case LFUN_TABULAR_INSERT:
1701 code = Inset::TABULAR_CODE;
1703 case LFUN_MARGINALNOTE_INSERT:
1704 code = Inset::MARGIN_CODE;
1706 case LFUN_FLOAT_INSERT:
1707 case LFUN_FLOAT_WIDE_INSERT:
1708 code = Inset::FLOAT_CODE;
1710 case LFUN_WRAP_INSERT:
1711 code = Inset::WRAP_CODE;
1713 case LFUN_FLOAT_LIST:
1714 code = Inset::FLOAT_LIST_CODE;
1717 case LFUN_LIST_INSERT:
1718 code = Inset::LIST_CODE;
1720 case LFUN_THEOREM_INSERT:
1721 code = Inset::THEOREM_CODE;
1724 case LFUN_CAPTION_INSERT:
1725 code = Inset::CAPTION_CODE;
1727 case LFUN_NOTE_INSERT:
1728 code = Inset::NOTE_CODE;
1730 case LFUN_CHARSTYLE_INSERT:
1731 code = Inset::CHARSTYLE_CODE;
1732 if (cur.buffer().params().getTextClass().charstyles().empty())
1735 case LFUN_BOX_INSERT:
1736 code = Inset::BOX_CODE;
1738 case LFUN_BRANCH_INSERT:
1739 code = Inset::BRANCH_CODE;
1740 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1743 case LFUN_LABEL_INSERT:
1744 code = Inset::LABEL_CODE;
1746 case LFUN_OPTIONAL_INSERT:
1747 code = Inset::OPTARG_CODE;
1748 enable = numberOfOptArgs(cur.paragraph())
1749 < cur.paragraph().layout()->optionalargs;
1751 case LFUN_ENVIRONMENT_INSERT:
1752 code = Inset::BOX_CODE;
1754 case LFUN_INDEX_INSERT:
1755 code = Inset::INDEX_CODE;
1757 case LFUN_INDEX_PRINT:
1758 code = Inset::INDEX_PRINT_CODE;
1760 case LFUN_NOMENCL_INSERT:
1761 code = Inset::NOMENCL_CODE;
1763 case LFUN_NOMENCL_PRINT:
1764 code = Inset::NOMENCL_PRINT_CODE;
1766 case LFUN_TOC_INSERT:
1767 code = Inset::TOC_CODE;
1769 case LFUN_HTML_INSERT:
1770 case LFUN_URL_INSERT:
1771 code = Inset::URL_CODE;
1773 case LFUN_QUOTE_INSERT:
1774 // always allow this, since we will inset a raw quote
1775 // if an inset is not allowed.
1777 case LFUN_HYPHENATION_POINT_INSERT:
1778 case LFUN_LIGATURE_BREAK_INSERT:
1779 case LFUN_HFILL_INSERT:
1780 case LFUN_MENU_SEPARATOR_INSERT:
1781 case LFUN_DOTS_INSERT:
1782 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
1783 code = Inset::SPECIALCHAR_CODE;
1785 case LFUN_SPACE_INSERT:
1786 // slight hack: we know this is allowed in math mode
1788 code = Inset::SPACE_CODE;
1791 case LFUN_INSET_MODIFY:
1792 // We need to disable this, because we may get called for a
1794 // InsetTabular::getStatus() -> InsetText::getStatus()
1795 // and we don't handle LFUN_INSET_MODIFY.
1799 case LFUN_FONT_EMPH:
1800 flag.setOnOff(font.emph() == Font::ON);
1803 case LFUN_FONT_NOUN:
1804 flag.setOnOff(font.noun() == Font::ON);
1807 case LFUN_FONT_BOLD:
1808 flag.setOnOff(font.series() == Font::BOLD_SERIES);
1811 case LFUN_FONT_SANS:
1812 flag.setOnOff(font.family() == Font::SANS_FAMILY);
1815 case LFUN_FONT_ROMAN:
1816 flag.setOnOff(font.family() == Font::ROMAN_FAMILY);
1819 case LFUN_FONT_CODE:
1820 flag.setOnOff(font.family() == Font::TYPEWRITER_FAMILY);
1825 enable = cur.selection();
1829 if (cmd.argument().empty()) {
1830 if (theClipboard().isInternal())
1831 enable = cap::numberOfSelections() > 0;
1833 enable = !theClipboard().empty();
1835 string const arg = to_utf8(cmd.argument());
1836 if (isStrUnsignedInt(arg)) {
1837 unsigned int n = convert<unsigned int>(arg);
1838 enable = cap::numberOfSelections() > n;
1845 case LFUN_CLIPBOARD_PASTE:
1846 enable = !theClipboard().empty();
1849 case LFUN_PRIMARY_SELECTION_PASTE:
1850 enable = cur.selection() || !theSelection().empty();
1853 case LFUN_PARAGRAPH_MOVE_UP:
1854 enable = cur.pit() > 0 && !cur.selection();
1857 case LFUN_PARAGRAPH_MOVE_DOWN:
1858 enable = cur.pit() < cur.lastpit() && !cur.selection();
1861 case LFUN_INSET_DISSOLVE:
1862 enable = !isMainText(*cur.bv().buffer()) && cur.inset().nargs() == 1;
1865 case LFUN_CHANGE_ACCEPT:
1866 case LFUN_CHANGE_REJECT:
1867 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
1868 // In principle, these LFUNs should only be enabled if there
1869 // is a change at the current position/in the current selection.
1870 // However, without proper optimizations, this will inevitably
1871 // result in unacceptable performance - just imagine a user who
1872 // wants to select the complete content of a long document.
1876 case LFUN_WORD_DELETE_FORWARD:
1877 case LFUN_WORD_DELETE_BACKWARD:
1878 case LFUN_LINE_DELETE:
1879 case LFUN_WORD_FORWARD:
1880 case LFUN_WORD_BACKWARD:
1881 case LFUN_CHAR_FORWARD:
1882 case LFUN_CHAR_FORWARD_SELECT:
1883 case LFUN_CHAR_BACKWARD:
1884 case LFUN_CHAR_BACKWARD_SELECT:
1886 case LFUN_UP_SELECT:
1888 case LFUN_DOWN_SELECT:
1889 case LFUN_PARAGRAPH_UP_SELECT:
1890 case LFUN_PARAGRAPH_DOWN_SELECT:
1891 case LFUN_SCREEN_UP_SELECT:
1892 case LFUN_SCREEN_DOWN_SELECT:
1893 case LFUN_LINE_BEGIN_SELECT:
1894 case LFUN_LINE_END_SELECT:
1895 case LFUN_WORD_FORWARD_SELECT:
1896 case LFUN_WORD_BACKWARD_SELECT:
1897 case LFUN_WORD_SELECT:
1898 case LFUN_PARAGRAPH_UP:
1899 case LFUN_PARAGRAPH_DOWN:
1900 case LFUN_SCREEN_UP:
1901 case LFUN_SCREEN_DOWN:
1902 case LFUN_LINE_BEGIN:
1904 case LFUN_BREAK_LINE:
1905 case LFUN_CHAR_DELETE_FORWARD:
1906 case LFUN_DELETE_FORWARD_SKIP:
1907 case LFUN_CHAR_DELETE_BACKWARD:
1908 case LFUN_DELETE_BACKWARD_SKIP:
1909 case LFUN_BREAK_PARAGRAPH:
1910 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
1911 case LFUN_BREAK_PARAGRAPH_SKIP:
1912 case LFUN_PARAGRAPH_SPACING:
1913 case LFUN_INSET_INSERT:
1914 case LFUN_WORD_UPCASE:
1915 case LFUN_WORD_LOWCASE:
1916 case LFUN_WORD_CAPITALIZE:
1917 case LFUN_CHARS_TRANSPOSE:
1918 case LFUN_SERVER_GET_XY:
1919 case LFUN_SERVER_SET_XY:
1920 case LFUN_SERVER_GET_FONT:
1921 case LFUN_SERVER_GET_LAYOUT:
1923 case LFUN_DATE_INSERT:
1924 case LFUN_SELF_INSERT:
1925 case LFUN_LINE_INSERT:
1926 case LFUN_PAGEBREAK_INSERT:
1927 case LFUN_CLEARPAGE_INSERT:
1928 case LFUN_CLEARDOUBLEPAGE_INSERT:
1929 case LFUN_MATH_DISPLAY:
1930 case LFUN_MATH_IMPORT_SELECTION:
1931 case LFUN_MATH_MODE:
1932 case LFUN_MATH_MACRO:
1933 case LFUN_MATH_MATRIX:
1934 case LFUN_MATH_DELIM:
1935 case LFUN_MATH_BIGDELIM:
1936 case LFUN_MATH_SUBSCRIPT:
1937 case LFUN_MATH_SUPERSCRIPT:
1938 case LFUN_FONT_DEFAULT:
1939 case LFUN_FONT_UNDERLINE:
1940 case LFUN_FONT_SIZE:
1942 case LFUN_FONT_FREE_APPLY:
1943 case LFUN_FONT_FREE_UPDATE:
1944 case LFUN_LAYOUT_PARAGRAPH:
1945 case LFUN_PARAGRAPH_UPDATE:
1946 case LFUN_ACCENT_UMLAUT:
1947 case LFUN_ACCENT_CIRCUMFLEX:
1948 case LFUN_ACCENT_GRAVE:
1949 case LFUN_ACCENT_ACUTE:
1950 case LFUN_ACCENT_TILDE:
1951 case LFUN_ACCENT_CEDILLA:
1952 case LFUN_ACCENT_MACRON:
1953 case LFUN_ACCENT_DOT:
1954 case LFUN_ACCENT_UNDERDOT:
1955 case LFUN_ACCENT_UNDERBAR:
1956 case LFUN_ACCENT_CARON:
1957 case LFUN_ACCENT_SPECIAL_CARON:
1958 case LFUN_ACCENT_BREVE:
1959 case LFUN_ACCENT_TIE:
1960 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1961 case LFUN_ACCENT_CIRCLE:
1962 case LFUN_ACCENT_OGONEK:
1963 case LFUN_THESAURUS_ENTRY:
1964 case LFUN_PARAGRAPH_PARAMS_APPLY:
1966 case LFUN_BUFFER_END:
1967 case LFUN_BUFFER_BEGIN:
1968 case LFUN_BUFFER_BEGIN_SELECT:
1969 case LFUN_BUFFER_END_SELECT:
1970 case LFUN_UNICODE_INSERT:
1971 // these are handled in our dispatch()
1979 if (code != Inset::NO_CODE
1980 && (cur.empty() || !cur.inset().insetAllowed(code)))
1983 flag.enabled(enable);
1988 void Text::pasteString(Cursor & cur, docstring const & clip,
1991 cur.clearSelection();
1992 if (!clip.empty()) {
1995 insertStringAsParagraphs(cur, clip);
1997 insertStringAsLines(cur, clip);