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 bool Text::isRTL(Buffer const & buffer, CursorSlice const & sl, bool boundary) const
308 if (boundary && sl.pos() > 0)
311 Paragraph const & par = getPar(sl.pit());
312 return getFont(buffer, par, sl.pos() + correction).isVisibleRightToLeft();
316 void Text::dispatch(Cursor & cur, FuncRequest & cmd)
318 LYXERR(Debug::ACTION) << "Text::dispatch: cmd: " << cmd << endl;
320 // FIXME: We use the update flag to indicates wether a singlePar or a
321 // full screen update is needed. We reset it here but shall we restore it
325 BOOST_ASSERT(cur.text() == this);
326 BufferView * bv = &cur.bv();
327 CursorSlice oldTopSlice = cur.top();
328 bool oldBoundary = cur.boundary();
329 bool sel = cur.selection();
330 // Signals that, even if needsUpdate == false, an update of the
331 // cursor paragraph is required
332 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
333 LyXAction::SingleParUpdate);
334 // Signals that a full-screen update is required
335 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
336 LyXAction::NoUpdate) || singleParUpdate);
337 // Remember the old paragraph metric (_outer_ paragraph!)
338 ParagraphMetrics const & pm = cur.bv().parMetrics(
339 cur.bottom().text(), cur.bottom().pit());
340 Dimension olddim = pm.dim();
342 switch (cmd.action) {
344 case LFUN_PARAGRAPH_MOVE_DOWN: {
345 pit_type const pit = cur.pit();
346 recUndo(cur, pit, pit + 1);
348 std::swap(pars_[pit], pars_[pit + 1]);
350 ParIterator begin(cur);
351 // begin.pos() (== cur.pos()) may point beyond the end of the
352 // paragraph referenced by begin. This would cause a crash
356 ParIterator end = boost::next(ParIterator(cur));
357 updateLabels(cur.buffer(), begin, end);
363 case LFUN_PARAGRAPH_MOVE_UP: {
364 pit_type const pit = cur.pit();
365 recUndo(cur, pit - 1, pit);
367 std::swap(pars_[pit], pars_[pit - 1]);
369 ParIterator end = ParIterator(cur);
370 // end.pos() (== cur.pos()) may point beyond the end of the
371 // paragraph referenced by end. This would cause a crash
374 end = boost::next(end);
376 ParIterator begin(cur);
377 updateLabels(cur.buffer(), begin, end);
383 case LFUN_APPENDIX: {
384 Paragraph & par = cur.paragraph();
385 bool start = !par.params().startOfAppendix();
388 #warning The code below only makes sense at top level.
389 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
391 // ensure that we have only one start_of_appendix in this document
392 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
393 if (pars_[tmp].params().startOfAppendix()) {
395 pars_[tmp].params().startOfAppendix(false);
401 par.params().startOfAppendix(start);
403 // we can set the refreshing parameters now
404 updateLabels(cur.buffer());
408 case LFUN_WORD_DELETE_FORWARD:
409 cur.clearSelection();
410 deleteWordForward(cur);
411 finishChange(cur, false);
414 case LFUN_WORD_DELETE_BACKWARD:
415 cur.clearSelection();
416 deleteWordBackward(cur);
417 finishChange(cur, false);
420 case LFUN_LINE_DELETE:
421 cur.clearSelection();
422 deleteLineForward(cur);
423 finishChange(cur, false);
426 case LFUN_BUFFER_BEGIN:
427 case LFUN_BUFFER_BEGIN_SELECT:
428 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
429 if (cur.depth() == 1) {
430 needsUpdate |= cursorTop(cur);
436 case LFUN_BUFFER_END:
437 case LFUN_BUFFER_END_SELECT:
438 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
439 if (cur.depth() == 1) {
440 needsUpdate |= cursorBottom(cur);
446 case LFUN_CHAR_FORWARD:
447 case LFUN_CHAR_FORWARD_SELECT:
448 //lyxerr << BOOST_CURRENT_FUNCTION
449 // << " LFUN_CHAR_FORWARD[SEL]:\n" << cur << endl;
450 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
451 if (reverseDirectionNeeded(cur))
452 needsUpdate |= cursorLeft(cur);
454 needsUpdate |= cursorRight(cur);
456 if (!needsUpdate && oldTopSlice == cur.top()
457 && cur.boundary() == oldBoundary) {
459 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
465 case LFUN_CHAR_BACKWARD:
466 case LFUN_CHAR_BACKWARD_SELECT:
467 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
468 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
469 if (reverseDirectionNeeded(cur))
470 needsUpdate |= cursorRight(cur);
472 needsUpdate |= cursorLeft(cur);
474 if (!needsUpdate && oldTopSlice == cur.top()
475 && cur.boundary() == oldBoundary) {
477 cmd = FuncRequest(LFUN_FINISHED_LEFT);
484 case LFUN_UP_SELECT: {
485 //lyxerr << "handle LFUN_UP[SEL]:\n" << cur << endl;
486 needsUpdate |= cur.selHandle(cmd.action == LFUN_UP_SELECT);
487 bool const successful = cur.upDownInText(true, needsUpdate);
496 case LFUN_DOWN_SELECT: {
497 //lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
498 needsUpdate |= cur.selHandle(cmd.action == LFUN_DOWN_SELECT);
499 bool const successful = cur.upDownInText(false, needsUpdate);
507 case LFUN_PARAGRAPH_UP:
508 case LFUN_PARAGRAPH_UP_SELECT:
509 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
510 needsUpdate |= cursorUpParagraph(cur);
515 case LFUN_PARAGRAPH_DOWN:
516 case LFUN_PARAGRAPH_DOWN_SELECT:
517 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
518 needsUpdate |= cursorDownParagraph(cur);
524 case LFUN_SCREEN_UP_SELECT:
525 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_UP_SELECT);
526 if (cur.pit() == 0 && cur.textRow().pos() == 0)
535 case LFUN_SCREEN_DOWN:
536 case LFUN_SCREEN_DOWN_SELECT:
537 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_DOWN_SELECT);
538 if (cur.pit() == cur.lastpit()
539 && cur.textRow().endpos() == cur.lastpos())
548 case LFUN_LINE_BEGIN:
549 case LFUN_LINE_BEGIN_SELECT:
550 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
551 needsUpdate |= cursorHome(cur);
555 case LFUN_LINE_END_SELECT:
556 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
557 needsUpdate |= cursorEnd(cur);
562 case LFUN_WORD_FORWARD:
563 case LFUN_WORD_FORWARD_SELECT:
564 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
565 if (reverseDirectionNeeded(cur))
566 needsUpdate |= cursorLeftOneWord(cur);
568 needsUpdate |= cursorRightOneWord(cur);
573 case LFUN_WORD_BACKWARD:
574 case LFUN_WORD_BACKWARD_SELECT:
575 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
576 if (reverseDirectionNeeded(cur))
577 needsUpdate |= cursorRightOneWord(cur);
579 needsUpdate |= cursorLeftOneWord(cur);
584 case LFUN_WORD_SELECT: {
585 selectWord(cur, WHOLE_WORD);
586 finishChange(cur, true);
590 case LFUN_BREAK_LINE: {
591 // Not allowed by LaTeX (labels or empty par)
592 if (cur.pos() > cur.paragraph().beginOfBody()) {
593 // this avoids a double undo
594 // FIXME: should not be needed, ideally
595 if (!cur.selection())
597 cap::replaceSelection(cur);
598 cur.insert(new InsetNewline);
600 moveCursor(cur, false);
605 case LFUN_CHAR_DELETE_FORWARD:
606 if (!cur.selection()) {
607 if (cur.pos() == cur.paragraph().size())
608 // Par boundary, force full-screen update
609 singleParUpdate = false;
610 needsUpdate |= erase(cur);
612 // It is possible to make it a lot faster still
613 // just comment out the line below...
615 cutSelection(cur, true, false);
616 singleParUpdate = false;
618 moveCursor(cur, false);
621 case LFUN_DELETE_FORWARD_SKIP:
622 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
623 if (!cur.selection()) {
624 if (cur.pos() == cur.lastpos()) {
631 cutSelection(cur, true, false);
636 case LFUN_CHAR_DELETE_BACKWARD:
637 if (!cur.selection()) {
638 if (bv->getIntl().getTransManager().backspace()) {
639 // Par boundary, full-screen update
641 singleParUpdate = false;
642 needsUpdate |= backspace(cur);
644 // It is possible to make it a lot faster still
645 // just comment out the line below...
648 cutSelection(cur, true, false);
649 singleParUpdate = false;
654 case LFUN_DELETE_BACKWARD_SKIP:
655 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
656 if (!cur.selection()) {
660 //CursorSlice cur = cursor();
664 cutSelection(cur, true, false);
668 case LFUN_BREAK_PARAGRAPH:
669 cap::replaceSelection(cur);
670 breakParagraph(cur, 0);
675 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
676 cap::replaceSelection(cur);
677 breakParagraph(cur, 1);
682 case LFUN_BREAK_PARAGRAPH_SKIP: {
683 // When at the beginning of a paragraph, remove
684 // indentation. Otherwise, do the same as LFUN_BREAK_PARAGRAPH.
685 cap::replaceSelection(cur);
687 cur.paragraph().params().labelWidthString(docstring());
689 breakParagraph(cur, 0);
695 case LFUN_PARAGRAPH_SPACING: {
696 Paragraph & par = cur.paragraph();
697 Spacing::Space cur_spacing = par.params().spacing().getSpace();
698 string cur_value = "1.0";
699 if (cur_spacing == Spacing::Other)
700 cur_value = par.params().spacing().getValueAsString();
702 istringstream is(to_utf8(cmd.argument()));
705 Spacing::Space new_spacing = cur_spacing;
706 string new_value = cur_value;
708 lyxerr << "Missing argument to `paragraph-spacing'"
710 } else if (tmp == "single") {
711 new_spacing = Spacing::Single;
712 } else if (tmp == "onehalf") {
713 new_spacing = Spacing::Onehalf;
714 } else if (tmp == "double") {
715 new_spacing = Spacing::Double;
716 } else if (tmp == "other") {
717 new_spacing = Spacing::Other;
718 string tmpval = "0.0";
720 lyxerr << "new_value = " << tmpval << endl;
723 } else if (tmp == "default") {
724 new_spacing = Spacing::Default;
726 lyxerr << to_utf8(_("Unknown spacing argument: "))
727 << to_utf8(cmd.argument()) << endl;
729 if (cur_spacing != new_spacing || cur_value != new_value)
730 par.params().spacing(Spacing(new_spacing, new_value));
734 case LFUN_INSET_INSERT: {
736 Inset * inset = createInset(bv, cmd);
738 // FIXME (Abdel 01/02/2006):
739 // What follows would be a partial fix for bug 2154:
740 // http://bugzilla.lyx.org/show_bug.cgi?id=2154
741 // This automatically put the label inset _after_ a
742 // numbered section. It should be possible to extend the mechanism
743 // to any kind of LateX environement.
744 // The correct way to fix that bug would be at LateX generation.
745 // I'll let the code here for reference as it could be used for some
746 // other feature like "automatic labelling".
748 Paragraph & par = pars_[cur.pit()];
749 if (inset->lyxCode() == Inset::LABEL_CODE
750 && par.layout()->labeltype == LABEL_COUNTER) {
751 // Go to the end of the paragraph
752 // Warning: Because of Change-Tracking, the last
753 // position is 'size()' and not 'size()-1':
754 cur.pos() = par.size();
755 // Insert a new paragraph
756 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
760 insertInset(cur, inset);
766 case LFUN_INSET_DISSOLVE:
767 needsUpdate |= dissolveInset(cur);
770 case LFUN_INSET_SETTINGS:
771 cur.inset().showInsetDialog(bv);
774 case LFUN_SPACE_INSERT:
775 if (cur.paragraph().layout()->free_spacing)
776 insertChar(cur, ' ');
778 doInsertInset(cur, this, cmd, false, false);
781 moveCursor(cur, false);
784 case LFUN_HYPHENATION_POINT_INSERT:
785 specialChar(cur, InsetSpecialChar::HYPHENATION);
788 case LFUN_LIGATURE_BREAK_INSERT:
789 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
792 case LFUN_DOTS_INSERT:
793 specialChar(cur, InsetSpecialChar::LDOTS);
796 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
797 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
800 case LFUN_MENU_SEPARATOR_INSERT:
801 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
804 case LFUN_WORD_UPCASE:
805 changeCase(cur, Text::text_uppercase);
808 case LFUN_WORD_LOWCASE:
809 changeCase(cur, Text::text_lowercase);
812 case LFUN_WORD_CAPITALIZE:
813 changeCase(cur, Text::text_capitalization);
816 case LFUN_CHARS_TRANSPOSE:
821 cur.message(_("Paste"));
822 cap::replaceSelection(cur);
823 if (cmd.argument().empty() && !theClipboard().isInternal())
824 pasteClipboard(cur, bv->buffer()->errorList("Paste"));
826 string const arg(to_utf8(cmd.argument()));
827 pasteFromStack(cur, bv->buffer()->errorList("Paste"),
828 isStrUnsignedInt(arg) ?
829 convert<unsigned int>(arg) :
832 bv->buffer()->errors("Paste");
833 cur.clearSelection(); // bug 393
839 cutSelection(cur, true, true);
840 cur.message(_("Cut"));
845 cur.message(_("Copy"));
848 case LFUN_SERVER_GET_XY:
849 cur.message(from_utf8(
850 convert<string>(cursorX(cur.bv(), cur.top(), cur.boundary()))
851 + ' ' + convert<string>(cursorY(cur.bv(), cur.top(), cur.boundary()))));
854 case LFUN_SERVER_SET_XY: {
857 istringstream is(to_utf8(cmd.argument()));
860 lyxerr << "SETXY: Could not parse coordinates in '"
861 << to_utf8(cmd.argument()) << std::endl;
863 setCursorFromCoordinates(cur, x, y);
867 case LFUN_SERVER_GET_FONT:
868 if (current_font.shape() == Font::ITALIC_SHAPE)
869 cur.message(from_ascii("E"));
870 else if (current_font.shape() == Font::SMALLCAPS_SHAPE)
871 cur.message(from_ascii("N"));
873 cur.message(from_ascii("0"));
876 case LFUN_SERVER_GET_LAYOUT:
877 cur.message(from_utf8(cur.paragraph().layout()->name()));
881 string layout = to_ascii(cmd.argument());
882 LYXERR(Debug::INFO) << "LFUN_LAYOUT: (arg) " << layout << endl;
884 // Derive layout number from given argument (string)
885 // and current buffer's textclass (number)
886 TextClass const & tclass = bv->buffer()->params().getTextClass();
888 layout = tclass.defaultLayoutName();
889 bool hasLayout = tclass.hasLayout(layout);
891 // If the entry is obsolete, use the new one instead.
893 string const & obs = tclass[layout]->obsoleted_by();
899 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
900 from_utf8(N_(" not known")));
904 bool change_layout = (current_layout != layout);
906 if (!change_layout && cur.selection() &&
907 cur.selBegin().pit() != cur.selEnd().pit())
909 pit_type spit = cur.selBegin().pit();
910 pit_type epit = cur.selEnd().pit() + 1;
911 while (spit != epit) {
912 if (pars_[spit].layout()->name() != current_layout) {
913 change_layout = true;
921 current_layout = layout;
922 setLayout(cur, layout);
923 // inform the GUI that the layout has changed.
924 bv->layoutChanged(layout);
930 case LFUN_CLIPBOARD_PASTE:
931 cur.clearSelection();
932 pasteClipboard(cur, bv->buffer()->errorList("Paste"),
933 cmd.argument() == "paragraph");
934 bv->buffer()->errors("Paste");
937 case LFUN_PRIMARY_SELECTION_PASTE:
938 pasteString(cur, theSelection().get(),
939 cmd.argument() == "paragraph");
942 case LFUN_UNICODE_INSERT: {
943 if (cmd.argument().empty())
945 docstring hexstring = cmd.argument();
946 if (lyx::support::isHex(hexstring)) {
947 char_type c = lyx::support::hexToInt(hexstring);
948 if (c > 32 && c < 0x10ffff) {
949 lyxerr << "Inserting c: " << c << endl;
950 docstring s = docstring(1, c);
951 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
957 case LFUN_QUOTE_INSERT: {
958 Paragraph & par = cur.paragraph();
959 pos_type pos = cur.pos();
960 BufferParams const & bufparams = bv->buffer()->params();
961 Layout_ptr const & style = par.layout();
962 if (!style->pass_thru
963 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
964 // this avoids a double undo
965 // FIXME: should not be needed, ideally
966 if (!cur.selection())
968 cap::replaceSelection(cur);
973 else if (cur.prevInset() && cur.prevInset()->isSpace())
976 c = par.getChar(pos - 1);
977 string arg = to_utf8(cmd.argument());
979 cur.insert(new InsetQuotes(c,
980 bufparams.quotes_language,
981 InsetQuotes::SingleQ));
983 cur.insert(new InsetQuotes(c,
984 bufparams.quotes_language,
985 InsetQuotes::DoubleQ));
989 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
993 case LFUN_DATE_INSERT:
994 if (cmd.argument().empty())
995 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
996 formatted_time(current_time())));
998 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
999 formatted_time(current_time(), to_utf8(cmd.argument()))));
1002 case LFUN_MOUSE_TRIPLE:
1003 if (cmd.button() == mouse_button::button1) {
1013 case LFUN_MOUSE_DOUBLE:
1014 if (cmd.button() == mouse_button::button1) {
1015 selectWord(cur, WHOLE_WORD_STRICT);
1020 // Single-click on work area
1021 case LFUN_MOUSE_PRESS: {
1022 // Right click on a footnote flag opens float menu
1023 if (cmd.button() == mouse_button::button3)
1024 cur.clearSelection();
1026 // Middle button press pastes if we have a selection
1027 // We do this here as if the selection was inside an inset
1028 // it could get cleared on the unlocking of the inset so
1029 // we have to check this first
1030 bool paste_internally = false;
1031 if (cmd.button() == mouse_button::button2 && cap::selection()) {
1032 // Copy the selection buffer to the clipboard
1033 // stack, because we want it to appear in the
1034 // "Edit->Paste recent" menu.
1035 cap::copySelectionToStack();
1036 paste_internally = true;
1039 // Insert primary selection with middle mouse
1040 // if there is a local selection in the current buffer,
1042 if (cmd.button() == mouse_button::button2) {
1043 if (paste_internally) {
1044 cap::pasteSelection(cur, bv->buffer()->errorList("Paste"));
1045 bv->buffer()->errors("Paste");
1046 cur.clearSelection(); // bug 393
1048 bv->buffer()->markDirty();
1051 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
1054 // we have to update after dePM triggered
1055 bool update = bv->mouseSetCursor(cur);
1057 if (!update && cmd.button() == mouse_button::button1) {
1058 needsUpdate = false;
1065 case LFUN_MOUSE_MOTION: {
1066 // Only use motion with button 1
1067 //if (cmd.button() != mouse_button::button1)
1070 // ignore motions deeper nested than the real anchor
1071 Cursor & bvcur = cur.bv().cursor();
1072 if (bvcur.anchor_.hasPart(cur)) {
1073 CursorSlice old = bvcur.top();
1075 int const wh = bv->workHeight();
1076 int const y = std::max(0, std::min(wh - 1, cmd.y));
1078 setCursorFromCoordinates(cur, cmd.x, y);
1079 cur.setTargetX(cmd.x);
1081 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1083 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1084 // This is to allow jumping over large insets
1085 if (cur.top() == old) {
1087 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1089 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1092 if (cur.top() == old)
1095 // don't set anchor_
1096 bvcur.setCursor(cur);
1097 bvcur.selection() = true;
1098 //lyxerr << "MOTION: " << bv->cursor() << endl;
1106 case LFUN_MOUSE_RELEASE: {
1107 if (cmd.button() == mouse_button::button2)
1110 if (cmd.button() == mouse_button::button1) {
1111 // if there is new selection, update persistent
1112 // selection, otherwise, single click does not
1113 // clear persistent selection buffer
1114 if (cur.selection()) {
1116 // if double click, cur is moved to the end of word by selectWord
1117 // but bvcur is current mouse position
1118 Cursor & bvcur = cur.bv().cursor();
1119 bvcur.selection() = true;
1120 saveSelection(bvcur);
1122 needsUpdate = false;
1130 case LFUN_SELF_INSERT: {
1131 if (cmd.argument().empty())
1134 // Automatically delete the currently selected
1135 // text and replace it with what is being
1136 // typed in now. Depends on lyxrc settings
1137 // "auto_region_delete", which defaults to
1140 if (lyxrc.auto_region_delete)
1141 if (cur.selection())
1142 cutSelection(cur, false, false);
1144 cur.clearSelection();
1145 Font const old_font = real_current_font;
1147 docstring::const_iterator cit = cmd.argument().begin();
1148 docstring::const_iterator end = cmd.argument().end();
1149 for (; cit != end; ++cit)
1150 bv->getIntl().getTransManager().
1151 translateAndInsert(*cit, this, cur);
1154 moveCursor(cur, false);
1158 case LFUN_URL_INSERT: {
1159 InsetCommandParams p("url");
1160 string const data = InsetCommandMailer::params2string("url", p);
1161 bv->showInsetDialog("url", data, 0);
1165 case LFUN_HTML_INSERT: {
1166 InsetCommandParams p("htmlurl");
1167 string const data = InsetCommandMailer::params2string("url", p);
1168 bv->showInsetDialog("url", data, 0);
1172 case LFUN_LABEL_INSERT: {
1173 InsetCommandParams p("label");
1174 // Try to generate a valid label
1175 p["name"] = (cmd.argument().empty()) ?
1176 cur.getPossibleLabel() :
1178 string const data = InsetCommandMailer::params2string("label", p);
1180 if (cmd.argument().empty()) {
1181 bv->showInsetDialog("label", data, 0);
1183 FuncRequest fr(LFUN_INSET_INSERT, data);
1191 case LFUN_LIST_INSERT:
1192 case LFUN_THEOREM_INSERT:
1194 case LFUN_CAPTION_INSERT:
1195 // Open the inset, and move the current selection
1197 doInsertInset(cur, this, cmd, true, true);
1199 updateLabels(*bv->buffer());
1201 case LFUN_NOTE_INSERT:
1202 case LFUN_CHARSTYLE_INSERT:
1203 case LFUN_BOX_INSERT:
1204 case LFUN_BRANCH_INSERT:
1205 case LFUN_BIBITEM_INSERT:
1206 case LFUN_ERT_INSERT:
1207 case LFUN_LISTING_INSERT:
1208 case LFUN_FOOTNOTE_INSERT:
1209 case LFUN_MARGINALNOTE_INSERT:
1210 case LFUN_OPTIONAL_INSERT:
1211 case LFUN_ENVIRONMENT_INSERT:
1212 // Open the inset, and move the current selection
1214 doInsertInset(cur, this, cmd, true, true);
1218 case LFUN_TABULAR_INSERT:
1219 // if there were no arguments, just open the dialog
1220 if (doInsertInset(cur, this, cmd, false, true))
1223 bv->showDialog("tabularcreate");
1227 case LFUN_FLOAT_INSERT:
1228 case LFUN_FLOAT_WIDE_INSERT:
1229 case LFUN_WRAP_INSERT: {
1230 bool content = cur.selection(); // will some text be moved into the inset?
1232 doInsertInset(cur, this, cmd, true, true);
1234 ParagraphList & pars = cur.text()->paragraphs();
1236 TextClass const & tclass = bv->buffer()->params().getTextClass();
1238 // add a separate paragraph for the caption inset
1239 pars.push_back(Paragraph());
1240 pars.back().setInsetOwner(pars[0].inInset());
1241 pars.back().layout(tclass.defaultLayout());
1243 int cap_pit = pars.size() - 1;
1245 // if an empty inset was created, we create an additional empty
1246 // paragraph at the bottom so that the user can choose where to put
1247 // the graphics (or table).
1249 pars.push_back(Paragraph());
1250 pars.back().setInsetOwner(pars[0].inInset());
1251 pars.back().layout(tclass.defaultLayout());
1255 // reposition the cursor to the caption
1256 cur.pit() = cap_pit;
1258 cur.dispatch(FuncRequest(LFUN_CAPTION_INSERT));
1259 // FIXME: When leaving the Float (or Wrap) inset we should
1260 // delete any empty paragraph left above or below the
1265 case LFUN_INDEX_INSERT:
1266 case LFUN_NOMENCL_INSERT: {
1267 Inset * inset = createInset(&cur.bv(), cmd);
1271 cur.clearSelection();
1272 insertInset(cur, inset);
1273 inset->edit(cur, true);
1274 // Show the dialog for the nomenclature entry, since the
1275 // description entry still needs to be filled in.
1276 if (cmd.action == LFUN_NOMENCL_INSERT)
1277 InsetCommandMailer("nomenclature",
1278 *reinterpret_cast<InsetCommand *>(inset)).showDialog(&cur.bv());
1283 case LFUN_INDEX_PRINT:
1284 case LFUN_NOMENCL_PRINT:
1285 case LFUN_TOC_INSERT:
1286 case LFUN_HFILL_INSERT:
1287 case LFUN_LINE_INSERT:
1288 case LFUN_PAGEBREAK_INSERT:
1289 case LFUN_CLEARPAGE_INSERT:
1290 case LFUN_CLEARDOUBLEPAGE_INSERT:
1292 doInsertInset(cur, this, cmd, false, false);
1296 case LFUN_DEPTH_DECREMENT:
1297 changeDepth(cur, DEC_DEPTH);
1300 case LFUN_DEPTH_INCREMENT:
1301 changeDepth(cur, INC_DEPTH);
1304 case LFUN_MATH_DISPLAY:
1305 mathDispatch(cur, cmd, true);
1308 case LFUN_MATH_IMPORT_SELECTION:
1309 case LFUN_MATH_MODE:
1310 if (cmd.argument() == "on")
1311 // don't pass "on" as argument
1312 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1314 mathDispatch(cur, cmd, false);
1317 case LFUN_MATH_MACRO:
1318 if (cmd.argument().empty())
1319 cur.errorMessage(from_utf8(N_("Missing argument")));
1321 string s = to_utf8(cmd.argument());
1322 string const s1 = token(s, ' ', 1);
1323 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1324 string const s2 = token(s, ' ', 2);
1325 string const type = s2.empty() ? "newcommand" : s2;
1326 cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, from_utf8(type)));
1327 //cur.nextInset()->edit(cur, true);
1331 // passthrough hat and underscore outside mathed:
1332 case LFUN_MATH_SUBSCRIPT:
1333 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1335 case LFUN_MATH_SUPERSCRIPT:
1336 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1339 case LFUN_MATH_INSERT:
1340 case LFUN_MATH_MATRIX:
1341 case LFUN_MATH_DELIM:
1342 case LFUN_MATH_BIGDELIM: {
1343 cur.insert(new InsetMathHull(hullSimple));
1344 cur.dispatch(FuncRequest(LFUN_CHAR_FORWARD));
1345 BOOST_ASSERT(cur.inMathed());
1350 case LFUN_FONT_EMPH: {
1351 Font font(Font::ALL_IGNORE);
1352 font.setEmph(Font::TOGGLE);
1353 toggleAndShow(cur, this, font);
1357 case LFUN_FONT_BOLD: {
1358 Font font(Font::ALL_IGNORE);
1359 font.setSeries(Font::BOLD_SERIES);
1360 toggleAndShow(cur, this, font);
1364 case LFUN_FONT_NOUN: {
1365 Font font(Font::ALL_IGNORE);
1366 font.setNoun(Font::TOGGLE);
1367 toggleAndShow(cur, this, font);
1371 case LFUN_FONT_CODE: {
1372 Font font(Font::ALL_IGNORE);
1373 font.setFamily(Font::TYPEWRITER_FAMILY); // no good
1374 toggleAndShow(cur, this, font);
1378 case LFUN_FONT_SANS: {
1379 Font font(Font::ALL_IGNORE);
1380 font.setFamily(Font::SANS_FAMILY);
1381 toggleAndShow(cur, this, font);
1385 case LFUN_FONT_ROMAN: {
1386 Font font(Font::ALL_IGNORE);
1387 font.setFamily(Font::ROMAN_FAMILY);
1388 toggleAndShow(cur, this, font);
1392 case LFUN_FONT_DEFAULT: {
1393 Font font(Font::ALL_INHERIT, ignore_language);
1394 toggleAndShow(cur, this, font);
1398 case LFUN_FONT_UNDERLINE: {
1399 Font font(Font::ALL_IGNORE);
1400 font.setUnderbar(Font::TOGGLE);
1401 toggleAndShow(cur, this, font);
1405 case LFUN_FONT_SIZE: {
1406 Font font(Font::ALL_IGNORE);
1407 font.setLyXSize(to_utf8(cmd.argument()));
1408 toggleAndShow(cur, this, font);
1412 case LFUN_LANGUAGE: {
1413 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1416 Font font(Font::ALL_IGNORE);
1417 font.setLanguage(lang);
1418 toggleAndShow(cur, this, font);
1423 case LFUN_FONT_FREE_APPLY:
1424 toggleAndShow(cur, this, freefont, toggleall);
1425 cur.message(_("Character set"));
1428 // Set the freefont using the contents of \param data dispatched from
1429 // the frontends and apply it at the current cursor location.
1430 case LFUN_FONT_FREE_UPDATE: {
1433 if (bv_funcs::string2font(to_utf8(cmd.argument()), font, toggle)) {
1436 toggleAndShow(cur, this, freefont, toggleall);
1437 cur.message(_("Character set"));
1442 case LFUN_FINISHED_LEFT:
1443 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1444 if (reverseDirectionNeeded(cur))
1448 case LFUN_FINISHED_RIGHT:
1449 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1450 if (!reverseDirectionNeeded(cur))
1454 case LFUN_LAYOUT_PARAGRAPH: {
1456 params2string(cur.paragraph(), data);
1457 data = "show\n" + data;
1458 bv->showDialogWithData("paragraph", data);
1462 case LFUN_PARAGRAPH_UPDATE: {
1464 params2string(cur.paragraph(), data);
1466 // Will the paragraph accept changes from the dialog?
1467 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1469 data = "update " + convert<string>(accept) + '\n' + data;
1470 bv->updateDialog("paragraph", data);
1474 case LFUN_ACCENT_UMLAUT:
1475 case LFUN_ACCENT_CIRCUMFLEX:
1476 case LFUN_ACCENT_GRAVE:
1477 case LFUN_ACCENT_ACUTE:
1478 case LFUN_ACCENT_TILDE:
1479 case LFUN_ACCENT_CEDILLA:
1480 case LFUN_ACCENT_MACRON:
1481 case LFUN_ACCENT_DOT:
1482 case LFUN_ACCENT_UNDERDOT:
1483 case LFUN_ACCENT_UNDERBAR:
1484 case LFUN_ACCENT_CARON:
1485 case LFUN_ACCENT_SPECIAL_CARON:
1486 case LFUN_ACCENT_BREVE:
1487 case LFUN_ACCENT_TIE:
1488 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1489 case LFUN_ACCENT_CIRCLE:
1490 case LFUN_ACCENT_OGONEK:
1491 theLyXFunc().handleKeyFunc(cmd.action);
1492 if (!cmd.argument().empty())
1493 // FIXME: Are all these characters encoded in one byte in utf8?
1494 bv->getIntl().getTransManager()
1495 .translateAndInsert(cmd.argument()[0], this, cur);
1498 case LFUN_FLOAT_LIST: {
1499 TextClass const & tclass = bv->buffer()->params().getTextClass();
1500 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1501 // not quite sure if we want this...
1503 cur.clearSelection();
1504 breakParagraph(cur);
1506 if (cur.lastpos() != 0) {
1508 breakParagraph(cur);
1511 setLayout(cur, tclass.defaultLayoutName());
1512 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, docstring(), 0);
1513 insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1516 lyxerr << "Non-existent float type: "
1517 << to_utf8(cmd.argument()) << endl;
1522 case LFUN_CHANGE_ACCEPT: {
1523 acceptOrRejectChanges(cur, ACCEPT);
1527 case LFUN_CHANGE_REJECT: {
1528 acceptOrRejectChanges(cur, REJECT);
1532 case LFUN_THESAURUS_ENTRY: {
1533 docstring arg = cmd.argument();
1535 arg = cur.selectionAsString(false);
1537 if (arg.size() > 100 || arg.empty()) {
1538 // Get word or selection
1539 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1540 arg = cur.selectionAsString(false);
1543 bv->showDialogWithData("thesaurus", to_utf8(arg));
1547 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1548 // Given data, an encoding of the ParagraphParameters
1549 // generated in the Paragraph dialog, this function sets
1550 // the current paragraph appropriately.
1551 istringstream is(to_utf8(cmd.argument()));
1554 ParagraphParameters params;
1559 params.labelWidthString(),
1561 cur.message(_("Paragraph layout set"));
1566 if (cur.selection()) {
1567 cur.selection() = false;
1571 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1576 LYXERR(Debug::ACTION)
1577 << BOOST_CURRENT_FUNCTION
1578 << ": Command " << cmd
1579 << " not DISPATCHED by Text" << endl;
1584 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1586 // FIXME: The cursor flag is reset two lines below
1587 // so we need to check here if some of the LFUN did touch that.
1588 // for now only Text::erase() and Text::backspace() do that.
1589 // The plan is to verify all the LFUNs and then to remove this
1590 // singleParUpdate boolean altogether.
1591 if (cur.result().update() & Update::Force) {
1592 singleParUpdate = false;
1596 // FIXME: the following code should go in favor of fine grained
1597 // update flag treatment.
1598 if (singleParUpdate) {
1599 // Inserting characters does not change par height
1600 ParagraphMetrics const & pms
1601 = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
1602 if (pms.dim().height()
1603 == olddim.height()) {
1604 // if so, update _only_ this paragraph
1605 cur.updateFlags(Update::SinglePar |
1607 Update::MultiParSel);
1614 && &oldTopSlice.inset() == &cur.inset()
1615 && oldTopSlice.idx() == cur.idx()
1616 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1617 && !cur.selection())
1618 // FIXME: it would be better if we could just do this
1620 //if (cur.result().update() != Update::FitCursor)
1623 // But some LFUNs do not set Update::FitCursor when needed, so we
1624 // do it for all. This is not very harmfull as FitCursor will provoke
1625 // a full redraw only if needed but still, a proper review of all LFUN
1626 // should be done and this needsUpdate boolean can then be removed.
1627 cur.updateFlags(Update::FitCursor);
1629 cur.updateFlags(Update::Force | Update::FitCursor);
1633 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
1634 FuncStatus & flag) const
1636 BOOST_ASSERT(cur.text() == this);
1638 Font const & font = real_current_font;
1640 Inset::Code code = Inset::NO_CODE;
1642 switch (cmd.action) {
1644 case LFUN_DEPTH_DECREMENT:
1645 enable = changeDepthAllowed(cur, DEC_DEPTH);
1648 case LFUN_DEPTH_INCREMENT:
1649 enable = changeDepthAllowed(cur, INC_DEPTH);
1653 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1656 case LFUN_BIBITEM_INSERT:
1657 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO
1661 case LFUN_DIALOG_SHOW_NEW_INSET:
1662 if (cmd.argument() == "bibitem")
1663 code = Inset::BIBITEM_CODE;
1664 else if (cmd.argument() == "bibtex")
1665 code = Inset::BIBTEX_CODE;
1666 else if (cmd.argument() == "box")
1667 code = Inset::BOX_CODE;
1668 else if (cmd.argument() == "branch")
1669 code = Inset::BRANCH_CODE;
1670 else if (cmd.argument() == "citation")
1671 code = Inset::CITE_CODE;
1672 else if (cmd.argument() == "ert")
1673 code = Inset::ERT_CODE;
1674 else if (cmd.argument() == "external")
1675 code = Inset::EXTERNAL_CODE;
1676 else if (cmd.argument() == "float")
1677 code = Inset::FLOAT_CODE;
1678 else if (cmd.argument() == "graphics")
1679 code = Inset::GRAPHICS_CODE;
1680 else if (cmd.argument() == "include")
1681 code = Inset::INCLUDE_CODE;
1682 else if (cmd.argument() == "index")
1683 code = Inset::INDEX_CODE;
1684 else if (cmd.argument() == "nomenclature")
1685 code = Inset::NOMENCL_CODE;
1686 else if (cmd.argument() == "label")
1687 code = Inset::LABEL_CODE;
1688 else if (cmd.argument() == "note")
1689 code = Inset::NOTE_CODE;
1690 else if (cmd.argument() == "ref")
1691 code = Inset::REF_CODE;
1692 else if (cmd.argument() == "toc")
1693 code = Inset::TOC_CODE;
1694 else if (cmd.argument() == "url")
1695 code = Inset::URL_CODE;
1696 else if (cmd.argument() == "vspace")
1697 code = Inset::VSPACE_CODE;
1698 else if (cmd.argument() == "wrap")
1699 code = Inset::WRAP_CODE;
1700 else if (cmd.argument() == "listings")
1701 code = Inset::LISTINGS_CODE;
1704 case LFUN_ERT_INSERT:
1705 code = Inset::ERT_CODE;
1707 case LFUN_LISTING_INSERT:
1708 code = Inset::LISTINGS_CODE;
1710 case LFUN_FOOTNOTE_INSERT:
1711 code = Inset::FOOT_CODE;
1713 case LFUN_TABULAR_INSERT:
1714 code = Inset::TABULAR_CODE;
1716 case LFUN_MARGINALNOTE_INSERT:
1717 code = Inset::MARGIN_CODE;
1719 case LFUN_FLOAT_INSERT:
1720 case LFUN_FLOAT_WIDE_INSERT:
1721 code = Inset::FLOAT_CODE;
1723 case LFUN_WRAP_INSERT:
1724 code = Inset::WRAP_CODE;
1726 case LFUN_FLOAT_LIST:
1727 code = Inset::FLOAT_LIST_CODE;
1730 case LFUN_LIST_INSERT:
1731 code = Inset::LIST_CODE;
1733 case LFUN_THEOREM_INSERT:
1734 code = Inset::THEOREM_CODE;
1737 case LFUN_CAPTION_INSERT:
1738 code = Inset::CAPTION_CODE;
1740 case LFUN_NOTE_INSERT:
1741 code = Inset::NOTE_CODE;
1743 case LFUN_CHARSTYLE_INSERT:
1744 code = Inset::CHARSTYLE_CODE;
1745 if (cur.buffer().params().getTextClass().charstyles().empty())
1748 case LFUN_BOX_INSERT:
1749 code = Inset::BOX_CODE;
1751 case LFUN_BRANCH_INSERT:
1752 code = Inset::BRANCH_CODE;
1753 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1756 case LFUN_LABEL_INSERT:
1757 code = Inset::LABEL_CODE;
1759 case LFUN_OPTIONAL_INSERT:
1760 code = Inset::OPTARG_CODE;
1761 enable = numberOfOptArgs(cur.paragraph())
1762 < cur.paragraph().layout()->optionalargs;
1764 case LFUN_ENVIRONMENT_INSERT:
1765 code = Inset::BOX_CODE;
1767 case LFUN_INDEX_INSERT:
1768 code = Inset::INDEX_CODE;
1770 case LFUN_INDEX_PRINT:
1771 code = Inset::INDEX_PRINT_CODE;
1773 case LFUN_NOMENCL_INSERT:
1774 code = Inset::NOMENCL_CODE;
1776 case LFUN_NOMENCL_PRINT:
1777 code = Inset::NOMENCL_PRINT_CODE;
1779 case LFUN_TOC_INSERT:
1780 code = Inset::TOC_CODE;
1782 case LFUN_HTML_INSERT:
1783 case LFUN_URL_INSERT:
1784 code = Inset::URL_CODE;
1786 case LFUN_QUOTE_INSERT:
1787 // always allow this, since we will inset a raw quote
1788 // if an inset is not allowed.
1790 case LFUN_HYPHENATION_POINT_INSERT:
1791 case LFUN_LIGATURE_BREAK_INSERT:
1792 case LFUN_HFILL_INSERT:
1793 case LFUN_MENU_SEPARATOR_INSERT:
1794 case LFUN_DOTS_INSERT:
1795 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
1796 code = Inset::SPECIALCHAR_CODE;
1798 case LFUN_SPACE_INSERT:
1799 // slight hack: we know this is allowed in math mode
1801 code = Inset::SPACE_CODE;
1804 case LFUN_INSET_MODIFY:
1805 // We need to disable this, because we may get called for a
1807 // InsetTabular::getStatus() -> InsetText::getStatus()
1808 // and we don't handle LFUN_INSET_MODIFY.
1812 case LFUN_FONT_EMPH:
1813 flag.setOnOff(font.emph() == Font::ON);
1816 case LFUN_FONT_NOUN:
1817 flag.setOnOff(font.noun() == Font::ON);
1820 case LFUN_FONT_BOLD:
1821 flag.setOnOff(font.series() == Font::BOLD_SERIES);
1824 case LFUN_FONT_SANS:
1825 flag.setOnOff(font.family() == Font::SANS_FAMILY);
1828 case LFUN_FONT_ROMAN:
1829 flag.setOnOff(font.family() == Font::ROMAN_FAMILY);
1832 case LFUN_FONT_CODE:
1833 flag.setOnOff(font.family() == Font::TYPEWRITER_FAMILY);
1838 enable = cur.selection();
1842 if (cmd.argument().empty()) {
1843 if (theClipboard().isInternal())
1844 enable = cap::numberOfSelections() > 0;
1846 enable = !theClipboard().empty();
1848 string const arg = to_utf8(cmd.argument());
1849 if (isStrUnsignedInt(arg)) {
1850 unsigned int n = convert<unsigned int>(arg);
1851 enable = cap::numberOfSelections() > n;
1858 case LFUN_CLIPBOARD_PASTE:
1859 enable = !theClipboard().empty();
1862 case LFUN_PRIMARY_SELECTION_PASTE:
1863 enable = cur.selection() || !theSelection().empty();
1866 case LFUN_PARAGRAPH_MOVE_UP:
1867 enable = cur.pit() > 0 && !cur.selection();
1870 case LFUN_PARAGRAPH_MOVE_DOWN:
1871 enable = cur.pit() < cur.lastpit() && !cur.selection();
1874 case LFUN_INSET_DISSOLVE:
1875 enable = !isMainText(*cur.bv().buffer()) && cur.inset().nargs() == 1;
1878 case LFUN_CHANGE_ACCEPT:
1879 case LFUN_CHANGE_REJECT:
1880 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
1881 // In principle, these LFUNs should only be enabled if there
1882 // is a change at the current position/in the current selection.
1883 // However, without proper optimizations, this will inevitably
1884 // result in unacceptable performance - just imagine a user who
1885 // wants to select the complete content of a long document.
1889 case LFUN_WORD_DELETE_FORWARD:
1890 case LFUN_WORD_DELETE_BACKWARD:
1891 case LFUN_LINE_DELETE:
1892 case LFUN_WORD_FORWARD:
1893 case LFUN_WORD_BACKWARD:
1894 case LFUN_CHAR_FORWARD:
1895 case LFUN_CHAR_FORWARD_SELECT:
1896 case LFUN_CHAR_BACKWARD:
1897 case LFUN_CHAR_BACKWARD_SELECT:
1899 case LFUN_UP_SELECT:
1901 case LFUN_DOWN_SELECT:
1902 case LFUN_PARAGRAPH_UP_SELECT:
1903 case LFUN_PARAGRAPH_DOWN_SELECT:
1904 case LFUN_SCREEN_UP_SELECT:
1905 case LFUN_SCREEN_DOWN_SELECT:
1906 case LFUN_LINE_BEGIN_SELECT:
1907 case LFUN_LINE_END_SELECT:
1908 case LFUN_WORD_FORWARD_SELECT:
1909 case LFUN_WORD_BACKWARD_SELECT:
1910 case LFUN_WORD_SELECT:
1911 case LFUN_PARAGRAPH_UP:
1912 case LFUN_PARAGRAPH_DOWN:
1913 case LFUN_SCREEN_UP:
1914 case LFUN_SCREEN_DOWN:
1915 case LFUN_LINE_BEGIN:
1917 case LFUN_BREAK_LINE:
1918 case LFUN_CHAR_DELETE_FORWARD:
1919 case LFUN_DELETE_FORWARD_SKIP:
1920 case LFUN_CHAR_DELETE_BACKWARD:
1921 case LFUN_DELETE_BACKWARD_SKIP:
1922 case LFUN_BREAK_PARAGRAPH:
1923 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
1924 case LFUN_BREAK_PARAGRAPH_SKIP:
1925 case LFUN_PARAGRAPH_SPACING:
1926 case LFUN_INSET_INSERT:
1927 case LFUN_WORD_UPCASE:
1928 case LFUN_WORD_LOWCASE:
1929 case LFUN_WORD_CAPITALIZE:
1930 case LFUN_CHARS_TRANSPOSE:
1931 case LFUN_SERVER_GET_XY:
1932 case LFUN_SERVER_SET_XY:
1933 case LFUN_SERVER_GET_FONT:
1934 case LFUN_SERVER_GET_LAYOUT:
1936 case LFUN_DATE_INSERT:
1937 case LFUN_SELF_INSERT:
1938 case LFUN_LINE_INSERT:
1939 case LFUN_PAGEBREAK_INSERT:
1940 case LFUN_CLEARPAGE_INSERT:
1941 case LFUN_CLEARDOUBLEPAGE_INSERT:
1942 case LFUN_MATH_DISPLAY:
1943 case LFUN_MATH_IMPORT_SELECTION:
1944 case LFUN_MATH_MODE:
1945 case LFUN_MATH_MACRO:
1946 case LFUN_MATH_MATRIX:
1947 case LFUN_MATH_DELIM:
1948 case LFUN_MATH_BIGDELIM:
1949 case LFUN_MATH_SUBSCRIPT:
1950 case LFUN_MATH_SUPERSCRIPT:
1951 case LFUN_FONT_DEFAULT:
1952 case LFUN_FONT_UNDERLINE:
1953 case LFUN_FONT_SIZE:
1955 case LFUN_FONT_FREE_APPLY:
1956 case LFUN_FONT_FREE_UPDATE:
1957 case LFUN_LAYOUT_PARAGRAPH:
1958 case LFUN_PARAGRAPH_UPDATE:
1959 case LFUN_ACCENT_UMLAUT:
1960 case LFUN_ACCENT_CIRCUMFLEX:
1961 case LFUN_ACCENT_GRAVE:
1962 case LFUN_ACCENT_ACUTE:
1963 case LFUN_ACCENT_TILDE:
1964 case LFUN_ACCENT_CEDILLA:
1965 case LFUN_ACCENT_MACRON:
1966 case LFUN_ACCENT_DOT:
1967 case LFUN_ACCENT_UNDERDOT:
1968 case LFUN_ACCENT_UNDERBAR:
1969 case LFUN_ACCENT_CARON:
1970 case LFUN_ACCENT_SPECIAL_CARON:
1971 case LFUN_ACCENT_BREVE:
1972 case LFUN_ACCENT_TIE:
1973 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1974 case LFUN_ACCENT_CIRCLE:
1975 case LFUN_ACCENT_OGONEK:
1976 case LFUN_THESAURUS_ENTRY:
1977 case LFUN_PARAGRAPH_PARAMS_APPLY:
1979 case LFUN_BUFFER_END:
1980 case LFUN_BUFFER_BEGIN:
1981 case LFUN_BUFFER_BEGIN_SELECT:
1982 case LFUN_BUFFER_END_SELECT:
1983 case LFUN_UNICODE_INSERT:
1984 // these are handled in our dispatch()
1992 if (code != Inset::NO_CODE
1993 && (cur.empty() || !cur.inset().insetAllowed(code)))
1996 flag.enabled(enable);
2001 void Text::pasteString(Cursor & cur, docstring const & clip,
2004 cur.clearSelection();
2005 if (!clip.empty()) {
2008 insertStringAsParagraphs(cur, clip);
2010 insertStringAsLines(cur, clip);