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 LyXFont freefont(LyXFont::ALL_IGNORE);
100 bool toggleall = false;
103 void toggleAndShow(LCursor & cur, LyXText * text,
104 LyXFont const & font, bool toggleall = true)
106 text->toggleFree(cur, font, toggleall);
108 if (font.language() != ignore_language ||
109 font.number() != LyXFont::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(LCursor & cur, bool selecting)
124 if (selecting || cur.mark())
127 cur.bv().switchKeyMap();
131 void finishChange(LCursor & cur, bool selecting)
134 moveCursor(cur, selecting);
138 void mathDispatch(LCursor & 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 LyXText::cursorPrevious(LCursor & 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 LyXText::cursorNext(LCursor & 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(LCursor & cur, InsetSpecialChar::Kind kind)
247 cap::replaceSelection(cur);
248 cur.insert(new InsetSpecialChar(kind));
253 bool doInsertInset(LCursor & cur, LyXText * text,
254 FuncRequest const & cmd, bool edit, bool pastesel)
256 InsetBase * inset = createInset(&cur.bv(), cmd);
262 if (cur.selection()) {
263 lyx::dispatch(FuncRequest(LFUN_CUT));
266 text->insertInset(cur, inset);
269 inset->edit(cur, true);
271 if (gotsel && pastesel) {
272 lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
273 // reset first par to default
274 if (cur.lastpit() != 0 || cur.lastpos() != 0) {
275 LyXLayout_ptr const layout =
276 cur.buffer().params().getLyXTextClass().defaultLayout();
277 cur.text()->paragraphs().begin()->layout(layout);
287 void LyXText::number(LCursor & cur)
289 LyXFont font(LyXFont::ALL_IGNORE);
290 font.setNumber(LyXFont::TOGGLE);
291 toggleAndShow(cur, this, font);
295 bool LyXText::isRTL(Buffer const & buffer, Paragraph const & par) const
297 return par.isRightToLeftPar(buffer.params());
301 void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
303 lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
305 // FIXME: We use the update flag to indicates wether a singlePar or a
306 // full screen update is needed. We reset it here but shall we restore it
310 BOOST_ASSERT(cur.text() == this);
311 BufferView * bv = &cur.bv();
312 CursorSlice oldTopSlice = cur.top();
313 bool oldBoundary = cur.boundary();
314 bool sel = cur.selection();
315 // Signals that, even if needsUpdate == false, an update of the
316 // cursor paragraph is required
317 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
318 LyXAction::SingleParUpdate);
319 // Signals that a full-screen update is required
320 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
321 LyXAction::NoUpdate) || singleParUpdate);
322 // Remember the old paragraph metric (_outer_ paragraph!)
323 ParagraphMetrics const & pm = cur.bv().parMetrics(
324 cur.bottom().text(), cur.bottom().pit());
325 Dimension olddim = pm.dim();
327 switch (cmd.action) {
329 case LFUN_PARAGRAPH_MOVE_DOWN: {
330 pit_type const pit = cur.pit();
331 recUndo(cur, pit, pit + 1);
333 std::swap(pars_[pit], pars_[pit + 1]);
335 ParIterator begin(cur);
336 // begin.pos() (== cur.pos()) may point beyond the end of the
337 // paragraph referenced by begin. This would cause a crash
341 ParIterator end = boost::next(ParIterator(cur));
342 updateLabels(cur.buffer(), begin, end);
348 case LFUN_PARAGRAPH_MOVE_UP: {
349 pit_type const pit = cur.pit();
350 recUndo(cur, pit - 1, pit);
352 std::swap(pars_[pit], pars_[pit - 1]);
354 ParIterator end = ParIterator(cur);
355 // end.pos() (== cur.pos()) may point beyond the end of the
356 // paragraph referenced by end. This would cause a crash
359 end = boost::next(end);
361 ParIterator begin(cur);
362 updateLabels(cur.buffer(), begin, end);
368 case LFUN_APPENDIX: {
369 Paragraph & par = cur.paragraph();
370 bool start = !par.params().startOfAppendix();
373 #warning The code below only makes sense at top level.
374 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
376 // ensure that we have only one start_of_appendix in this document
377 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
378 if (pars_[tmp].params().startOfAppendix()) {
380 pars_[tmp].params().startOfAppendix(false);
386 par.params().startOfAppendix(start);
388 // we can set the refreshing parameters now
389 updateLabels(cur.buffer());
393 case LFUN_WORD_DELETE_FORWARD:
394 cur.clearSelection();
395 deleteWordForward(cur);
396 finishChange(cur, false);
399 case LFUN_WORD_DELETE_BACKWARD:
400 cur.clearSelection();
401 deleteWordBackward(cur);
402 finishChange(cur, false);
405 case LFUN_LINE_DELETE:
406 cur.clearSelection();
407 deleteLineForward(cur);
408 finishChange(cur, false);
411 case LFUN_BUFFER_BEGIN:
412 case LFUN_BUFFER_BEGIN_SELECT:
413 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
414 if (cur.depth() == 1) {
415 needsUpdate |= cursorTop(cur);
421 case LFUN_BUFFER_END:
422 case LFUN_BUFFER_END_SELECT:
423 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
424 if (cur.depth() == 1) {
425 needsUpdate |= cursorBottom(cur);
431 case LFUN_CHAR_FORWARD:
432 case LFUN_CHAR_FORWARD_SELECT:
433 //lyxerr << BOOST_CURRENT_FUNCTION
434 // << " LFUN_CHAR_FORWARD[SEL]:\n" << cur << endl;
435 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
436 if (isRTL(*cur.bv().buffer(), cur.paragraph()))
437 needsUpdate |= cursorLeft(cur);
439 needsUpdate |= cursorRight(cur);
441 if (!needsUpdate && oldTopSlice == cur.top()
442 && cur.boundary() == oldBoundary) {
444 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
450 case LFUN_CHAR_BACKWARD:
451 case LFUN_CHAR_BACKWARD_SELECT:
452 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
453 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
454 if (isRTL(*cur.bv().buffer(), cur.paragraph()))
455 needsUpdate |= cursorRight(cur);
457 needsUpdate |= cursorLeft(cur);
459 if (!needsUpdate && oldTopSlice == cur.top()
460 && cur.boundary() == oldBoundary) {
462 cmd = FuncRequest(LFUN_FINISHED_LEFT);
470 //lyxerr << "handle LFUN_UP[SEL]:\n" << cur << endl;
471 needsUpdate |= cur.selHandle(cmd.action == LFUN_UP_SELECT);
473 needsUpdate |= cursorUp(cur);
475 if (!needsUpdate && oldTopSlice == cur.top()
476 && cur.boundary() == oldBoundary) {
478 cmd = FuncRequest(LFUN_FINISHED_UP);
485 case LFUN_DOWN_SELECT:
486 //lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
487 needsUpdate |= cur.selHandle(cmd.action == LFUN_DOWN_SELECT);
488 needsUpdate |= cursorDown(cur);
490 if (!needsUpdate && oldTopSlice == cur.top() &&
491 cur.boundary() == oldBoundary)
494 cmd = FuncRequest(LFUN_FINISHED_DOWN);
500 case LFUN_PARAGRAPH_UP:
501 case LFUN_PARAGRAPH_UP_SELECT:
502 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
503 needsUpdate |= cursorUpParagraph(cur);
508 case LFUN_PARAGRAPH_DOWN:
509 case LFUN_PARAGRAPH_DOWN_SELECT:
510 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
511 needsUpdate |= cursorDownParagraph(cur);
517 case LFUN_SCREEN_UP_SELECT:
518 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_UP_SELECT);
519 if (cur.pit() == 0 && cur.textRow().pos() == 0) {
521 cmd = FuncRequest(LFUN_FINISHED_UP);
529 case LFUN_SCREEN_DOWN:
530 case LFUN_SCREEN_DOWN_SELECT:
531 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_DOWN_SELECT);
532 if (cur.pit() == cur.lastpit()
533 && cur.textRow().endpos() == cur.lastpos()) {
535 cmd = FuncRequest(LFUN_FINISHED_DOWN);
543 case LFUN_LINE_BEGIN:
544 case LFUN_LINE_BEGIN_SELECT:
545 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
546 needsUpdate |= cursorHome(cur);
550 case LFUN_LINE_END_SELECT:
551 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
552 needsUpdate |= cursorEnd(cur);
557 case LFUN_WORD_FORWARD:
558 case LFUN_WORD_FORWARD_SELECT:
559 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
560 if (isRTL(*cur.bv().buffer(), cur.paragraph()))
561 needsUpdate |= cursorLeftOneWord(cur);
563 needsUpdate |= cursorRightOneWord(cur);
568 case LFUN_WORD_BACKWARD:
569 case LFUN_WORD_BACKWARD_SELECT:
570 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
571 if (isRTL(*cur.bv().buffer(), cur.paragraph()))
572 needsUpdate |= cursorRightOneWord(cur);
574 needsUpdate |= cursorLeftOneWord(cur);
579 case LFUN_WORD_SELECT: {
580 selectWord(cur, WHOLE_WORD);
581 finishChange(cur, true);
585 case LFUN_BREAK_LINE: {
586 // Not allowed by LaTeX (labels or empty par)
587 if (cur.pos() > cur.paragraph().beginOfBody()) {
588 if (!cur.selection())
590 cap::replaceSelection(cur);
591 cur.insert(new InsetNewline);
593 moveCursor(cur, false);
598 case LFUN_CHAR_DELETE_FORWARD:
599 if (!cur.selection()) {
600 if (cur.pos() == cur.paragraph().size())
601 // Par boundary, force full-screen update
602 singleParUpdate = false;
603 needsUpdate |= erase(cur);
605 // It is possible to make it a lot faster still
606 // just comment out the line below...
608 cutSelection(cur, true, false);
609 singleParUpdate = false;
611 moveCursor(cur, false);
614 case LFUN_DELETE_FORWARD_SKIP:
615 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
616 if (!cur.selection()) {
617 if (cur.pos() == cur.lastpos()) {
624 cutSelection(cur, true, false);
629 case LFUN_CHAR_DELETE_BACKWARD:
630 if (!cur.selection()) {
631 if (bv->getIntl().getTransManager().backspace()) {
632 // Par boundary, full-screen update
634 singleParUpdate = false;
635 needsUpdate |= backspace(cur);
637 // It is possible to make it a lot faster still
638 // just comment out the line below...
641 cutSelection(cur, true, false);
642 singleParUpdate = false;
647 case LFUN_DELETE_BACKWARD_SKIP:
648 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
649 if (!cur.selection()) {
653 //CursorSlice cur = cursor();
657 cutSelection(cur, true, false);
661 case LFUN_BREAK_PARAGRAPH:
662 cap::replaceSelection(cur);
663 breakParagraph(cur, 0);
668 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
669 cap::replaceSelection(cur);
670 breakParagraph(cur, 1);
675 case LFUN_BREAK_PARAGRAPH_SKIP: {
676 // When at the beginning of a paragraph, remove
677 // indentation. Otherwise, do the same as LFUN_BREAK_PARAGRAPH.
678 cap::replaceSelection(cur);
680 cur.paragraph().params().labelWidthString(docstring());
682 breakParagraph(cur, 0);
688 case LFUN_PARAGRAPH_SPACING: {
689 Paragraph & par = cur.paragraph();
690 Spacing::Space cur_spacing = par.params().spacing().getSpace();
691 string cur_value = "1.0";
692 if (cur_spacing == Spacing::Other)
693 cur_value = par.params().spacing().getValueAsString();
695 istringstream is(to_utf8(cmd.argument()));
698 Spacing::Space new_spacing = cur_spacing;
699 string new_value = cur_value;
701 lyxerr << "Missing argument to `paragraph-spacing'"
703 } else if (tmp == "single") {
704 new_spacing = Spacing::Single;
705 } else if (tmp == "onehalf") {
706 new_spacing = Spacing::Onehalf;
707 } else if (tmp == "double") {
708 new_spacing = Spacing::Double;
709 } else if (tmp == "other") {
710 new_spacing = Spacing::Other;
711 string tmpval = "0.0";
713 lyxerr << "new_value = " << tmpval << endl;
716 } else if (tmp == "default") {
717 new_spacing = Spacing::Default;
719 lyxerr << to_utf8(_("Unknown spacing argument: "))
720 << to_utf8(cmd.argument()) << endl;
722 if (cur_spacing != new_spacing || cur_value != new_value)
723 par.params().spacing(Spacing(new_spacing, new_value));
727 case LFUN_INSET_INSERT: {
729 InsetBase * inset = createInset(bv, cmd);
731 // FIXME (Abdel 01/02/2006):
732 // What follows would be a partial fix for bug 2154:
733 // http://bugzilla.lyx.org/show_bug.cgi?id=2154
734 // This automatically put the label inset _after_ a
735 // numbered section. It should be possible to extend the mechanism
736 // to any kind of LateX environement.
737 // The correct way to fix that bug would be at LateX generation.
738 // I'll let the code here for reference as it could be used for some
739 // other feature like "automatic labelling".
741 Paragraph & par = pars_[cur.pit()];
742 if (inset->lyxCode() == InsetBase::LABEL_CODE
743 && par.layout()->labeltype == LABEL_COUNTER) {
744 // Go to the end of the paragraph
745 // Warning: Because of Change-Tracking, the last
746 // position is 'size()' and not 'size()-1':
747 cur.pos() = par.size();
748 // Insert a new paragraph
749 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
753 insertInset(cur, inset);
759 case LFUN_INSET_DISSOLVE:
760 needsUpdate |= dissolveInset(cur);
763 case LFUN_INSET_SETTINGS:
764 cur.inset().showInsetDialog(bv);
767 case LFUN_SPACE_INSERT:
768 if (cur.paragraph().layout()->free_spacing)
769 insertChar(cur, ' ');
771 doInsertInset(cur, this, cmd, false, false);
774 moveCursor(cur, false);
777 case LFUN_HYPHENATION_POINT_INSERT:
778 specialChar(cur, InsetSpecialChar::HYPHENATION);
781 case LFUN_LIGATURE_BREAK_INSERT:
782 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
785 case LFUN_DOTS_INSERT:
786 specialChar(cur, InsetSpecialChar::LDOTS);
789 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
790 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
793 case LFUN_MENU_SEPARATOR_INSERT:
794 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
797 case LFUN_WORD_UPCASE:
798 changeCase(cur, LyXText::text_uppercase);
801 case LFUN_WORD_LOWCASE:
802 changeCase(cur, LyXText::text_lowercase);
805 case LFUN_WORD_CAPITALIZE:
806 changeCase(cur, LyXText::text_capitalization);
809 case LFUN_CHARS_TRANSPOSE:
814 cur.message(_("Paste"));
815 cap::replaceSelection(cur);
816 if (cmd.argument().empty() && !theClipboard().isInternal())
817 pasteClipboard(cur, bv->buffer()->errorList("Paste"));
819 string const arg(to_utf8(cmd.argument()));
820 pasteFromStack(cur, bv->buffer()->errorList("Paste"),
821 isStrUnsignedInt(arg) ?
822 convert<unsigned int>(arg) :
825 bv->buffer()->errors("Paste");
826 cur.clearSelection(); // bug 393
832 cutSelection(cur, true, true);
833 cur.message(_("Cut"));
838 cur.message(_("Copy"));
841 case LFUN_SERVER_GET_XY:
842 cur.message(from_utf8(
843 convert<string>(cursorX(cur.bv(), cur.top(), cur.boundary()))
844 + ' ' + convert<string>(cursorY(cur.bv(), cur.top(), cur.boundary()))));
847 case LFUN_SERVER_SET_XY: {
850 istringstream is(to_utf8(cmd.argument()));
853 lyxerr << "SETXY: Could not parse coordinates in '"
854 << to_utf8(cmd.argument()) << std::endl;
856 setCursorFromCoordinates(cur, x, y);
860 case LFUN_SERVER_GET_FONT:
861 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
862 cur.message(from_ascii("E"));
863 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
864 cur.message(from_ascii("N"));
866 cur.message(from_ascii("0"));
869 case LFUN_SERVER_GET_LAYOUT:
870 cur.message(from_utf8(cur.paragraph().layout()->name()));
874 string layout = to_ascii(cmd.argument());
875 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) " << layout << endl;
877 // Derive layout number from given argument (string)
878 // and current buffer's textclass (number)
879 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
881 layout = tclass.defaultLayoutName();
882 bool hasLayout = tclass.hasLayout(layout);
884 // If the entry is obsolete, use the new one instead.
886 string const & obs = tclass[layout]->obsoleted_by();
892 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
893 from_utf8(N_(" not known")));
897 bool change_layout = (current_layout != layout);
899 if (!change_layout && cur.selection() &&
900 cur.selBegin().pit() != cur.selEnd().pit())
902 pit_type spit = cur.selBegin().pit();
903 pit_type epit = cur.selEnd().pit() + 1;
904 while (spit != epit) {
905 if (pars_[spit].layout()->name() != current_layout) {
906 change_layout = true;
914 current_layout = layout;
915 setLayout(cur, layout);
916 // inform the GUI that the layout has changed.
917 bv->layoutChanged(layout);
923 case LFUN_CLIPBOARD_PASTE:
924 cur.clearSelection();
925 pasteClipboard(cur, bv->buffer()->errorList("Paste"),
926 cmd.argument() == "paragraph");
927 bv->buffer()->errors("Paste");
930 case LFUN_PRIMARY_SELECTION_PASTE:
931 pasteString(cur, theSelection().get(),
932 cmd.argument() == "paragraph");
935 case LFUN_UNICODE_INSERT: {
936 if (cmd.argument().empty())
938 docstring hexstring = cmd.argument();
939 if (lyx::support::isHex(hexstring)) {
940 char_type c = lyx::support::hexToInt(hexstring);
941 if (c > 32 && c < 0x10ffff) {
942 lyxerr << "Inserting c: " << c << endl;
943 docstring s = docstring(1, c);
944 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
950 case LFUN_QUOTE_INSERT: {
951 cap::replaceSelection(cur);
952 Paragraph & par = cur.paragraph();
953 pos_type pos = cur.pos();
957 else if (cur.prevInset() && cur.prevInset()->isSpace())
960 c = par.getChar(pos - 1);
962 LyXLayout_ptr const & style = par.layout();
964 BufferParams const & bufparams = bv->buffer()->params();
965 if (!style->pass_thru
966 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
967 string arg = to_utf8(cmd.argument());
969 cur.insert(new InsetQuotes(c,
970 bufparams.quotes_language,
971 InsetQuotes::SingleQ));
973 cur.insert(new InsetQuotes(c,
974 bufparams.quotes_language,
975 InsetQuotes::DoubleQ));
979 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
983 case LFUN_DATE_INSERT:
984 if (cmd.argument().empty())
985 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
986 formatted_time(current_time())));
988 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
989 formatted_time(current_time(), to_utf8(cmd.argument()))));
992 case LFUN_MOUSE_TRIPLE:
993 if (cmd.button() == mouse_button::button1) {
1003 case LFUN_MOUSE_DOUBLE:
1004 if (cmd.button() == mouse_button::button1) {
1005 selectWord(cur, WHOLE_WORD_STRICT);
1010 // Single-click on work area
1011 case LFUN_MOUSE_PRESS: {
1012 // Right click on a footnote flag opens float menu
1013 if (cmd.button() == mouse_button::button3)
1014 cur.clearSelection();
1016 // Middle button press pastes if we have a selection
1017 // We do this here as if the selection was inside an inset
1018 // it could get cleared on the unlocking of the inset so
1019 // we have to check this first
1020 bool paste_internally = false;
1021 if (cmd.button() == mouse_button::button2 && cap::selection()) {
1022 // Copy the selection buffer to the clipboard
1023 // stack, because we want it to appear in the
1024 // "Edit->Paste recent" menu.
1025 cap::copySelectionToStack();
1026 paste_internally = true;
1029 // we have to update after dePM triggered
1030 bool update = bv->mouseSetCursor(cur);
1032 // Insert primary selection with middle mouse
1033 // if there is a local selection in the current buffer,
1035 if (cmd.button() == mouse_button::button2) {
1036 if (paste_internally) {
1037 cap::pasteSelection(cur, bv->buffer()->errorList("Paste"));
1038 bv->buffer()->errors("Paste");
1039 cur.clearSelection(); // bug 393
1043 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
1046 if (!update && cmd.button() == mouse_button::button1) {
1047 needsUpdate = false;
1054 case LFUN_MOUSE_MOTION: {
1055 // Only use motion with button 1
1056 //if (cmd.button() != mouse_button::button1)
1059 // ignore motions deeper nested than the real anchor
1060 LCursor & bvcur = cur.bv().cursor();
1061 if (bvcur.anchor_.hasPart(cur)) {
1062 CursorSlice old = bvcur.top();
1064 int const wh = bv->workHeight();
1065 int const y = std::max(0, std::min(wh - 1, cmd.y));
1067 setCursorFromCoordinates(cur, cmd.x, y);
1068 cur.x_target() = cmd.x;
1070 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1072 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1073 // This is to allow jumping over large insets
1074 if (cur.top() == old) {
1076 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1078 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1081 if (cur.top() == old)
1084 // don't set anchor_
1085 bvcur.setCursor(cur);
1086 bvcur.selection() = true;
1087 //lyxerr << "MOTION: " << bv->cursor() << endl;
1095 case LFUN_MOUSE_RELEASE: {
1096 if (cmd.button() == mouse_button::button2)
1099 if (cmd.button() == mouse_button::button1) {
1100 // if there is new selection, update persistent
1101 // selection, otherwise, single click does not
1102 // clear persistent selection buffer
1103 if (cur.selection()) {
1105 // if double click, cur is moved to the end of word by selectWord
1106 // but bvcur is current mouse position
1107 LCursor & bvcur = cur.bv().cursor();
1108 bvcur.selection() = true;
1109 saveSelection(bvcur);
1111 needsUpdate = false;
1119 case LFUN_SELF_INSERT: {
1120 if (cmd.argument().empty())
1123 // Automatically delete the currently selected
1124 // text and replace it with what is being
1125 // typed in now. Depends on lyxrc settings
1126 // "auto_region_delete", which defaults to
1129 if (lyxrc.auto_region_delete)
1130 if (cur.selection())
1131 cutSelection(cur, false, false);
1133 cur.clearSelection();
1134 LyXFont const old_font = real_current_font;
1136 docstring::const_iterator cit = cmd.argument().begin();
1137 docstring::const_iterator end = cmd.argument().end();
1138 for (; cit != end; ++cit)
1140 bv->getIntl().getTransManager().
1141 translateAndInsert(*cit, this);
1143 insertChar(bv->cursor(), *cit);
1147 moveCursor(cur, false);
1151 case LFUN_URL_INSERT: {
1152 InsetCommandParams p("url");
1153 string const data = InsetCommandMailer::params2string("url", p);
1154 bv->showInsetDialog("url", data, 0);
1158 case LFUN_HTML_INSERT: {
1159 InsetCommandParams p("htmlurl");
1160 string const data = InsetCommandMailer::params2string("url", p);
1161 bv->showInsetDialog("url", data, 0);
1165 case LFUN_LABEL_INSERT: {
1166 InsetCommandParams p("label");
1167 // Try to generate a valid label
1168 p["name"] = (cmd.argument().empty()) ?
1169 cur.getPossibleLabel() :
1171 string const data = InsetCommandMailer::params2string("label", p);
1173 if (cmd.argument().empty()) {
1174 bv->showInsetDialog("label", data, 0);
1176 FuncRequest fr(LFUN_INSET_INSERT, data);
1184 case LFUN_LIST_INSERT:
1185 case LFUN_THEOREM_INSERT:
1187 case LFUN_CAPTION_INSERT:
1188 // Open the inset, and move the current selection
1190 doInsertInset(cur, this, cmd, true, true);
1192 updateLabels(*bv->buffer());
1194 case LFUN_NOTE_INSERT:
1195 case LFUN_CHARSTYLE_INSERT:
1196 case LFUN_BOX_INSERT:
1197 case LFUN_BRANCH_INSERT:
1198 case LFUN_BIBITEM_INSERT:
1199 case LFUN_ERT_INSERT:
1200 case LFUN_FOOTNOTE_INSERT:
1201 case LFUN_MARGINALNOTE_INSERT:
1202 case LFUN_OPTIONAL_INSERT:
1203 case LFUN_ENVIRONMENT_INSERT:
1204 // Open the inset, and move the current selection
1206 doInsertInset(cur, this, cmd, true, true);
1210 case LFUN_TABULAR_INSERT:
1211 // if there were no arguments, just open the dialog
1212 if (doInsertInset(cur, this, cmd, false, true))
1215 bv->showDialog("tabularcreate");
1219 case LFUN_FLOAT_INSERT:
1220 case LFUN_FLOAT_WIDE_INSERT:
1221 case LFUN_WRAP_INSERT: {
1222 bool content = cur.selection(); // will some text be moved into the inset?
1224 doInsertInset(cur, this, cmd, true, true);
1226 ParagraphList & pars = cur.text()->paragraphs();
1228 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1230 // add a separate paragraph for the caption inset
1231 pars.push_back(Paragraph());
1232 pars.back().setInsetOwner(pars[0].inInset());
1233 pars.back().layout(tclass.defaultLayout());
1235 int cap_pit = pars.size() - 1;
1237 // if an empty inset was created, we create an additional empty
1238 // paragraph at the bottom so that the user can choose where to put
1239 // the graphics (or table).
1241 pars.push_back(Paragraph());
1242 pars.back().setInsetOwner(pars[0].inInset());
1243 pars.back().layout(tclass.defaultLayout());
1247 // reposition the cursor to the caption
1248 cur.pit() = cap_pit;
1250 cur.dispatch(FuncRequest(LFUN_CAPTION_INSERT));
1251 // FIXME: When leaving the Float (or Wrap) inset we should
1252 // delete any empty paragraph left above or below the
1257 case LFUN_INDEX_INSERT:
1258 case LFUN_NOMENCL_INSERT: {
1259 InsetBase * inset = createInset(&cur.bv(), cmd);
1264 cur.clearSelection();
1265 insertInset(cur, inset);
1266 inset->edit(cur, true);
1267 // Show the dialog for the nomenclature entry, since the
1268 // description entry still needs to be filled in.
1269 if (cmd.action == LFUN_NOMENCL_INSERT)
1270 InsetCommandMailer("nomenclature",
1271 *reinterpret_cast<InsetCommand *>(inset)).showDialog(&cur.bv());
1276 case LFUN_INDEX_PRINT:
1277 case LFUN_NOMENCL_PRINT:
1278 case LFUN_TOC_INSERT:
1279 case LFUN_HFILL_INSERT:
1280 case LFUN_LINE_INSERT:
1281 case LFUN_PAGEBREAK_INSERT:
1282 case LFUN_CLEARPAGE_INSERT:
1283 case LFUN_CLEARDOUBLEPAGE_INSERT:
1285 doInsertInset(cur, this, cmd, false, false);
1289 case LFUN_DEPTH_DECREMENT:
1290 changeDepth(cur, DEC_DEPTH);
1293 case LFUN_DEPTH_INCREMENT:
1294 changeDepth(cur, INC_DEPTH);
1297 case LFUN_MATH_DISPLAY:
1298 mathDispatch(cur, cmd, true);
1301 case LFUN_MATH_IMPORT_SELECTION:
1302 case LFUN_MATH_MODE:
1303 if (cmd.argument() == "on")
1304 // don't pass "on" as argument
1305 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1307 mathDispatch(cur, cmd, false);
1310 case LFUN_MATH_MACRO:
1311 if (cmd.argument().empty())
1312 cur.errorMessage(from_utf8(N_("Missing argument")));
1314 string s = to_utf8(cmd.argument());
1315 string const s1 = token(s, ' ', 1);
1316 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1317 string const s2 = token(s, ' ', 2);
1318 string const type = s2.empty() ? "newcommand" : s2;
1319 cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, from_utf8(type)));
1320 //cur.nextInset()->edit(cur, true);
1324 // passthrough hat and underscore outside mathed:
1325 case LFUN_MATH_SUBSCRIPT:
1326 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1328 case LFUN_MATH_SUPERSCRIPT:
1329 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1332 case LFUN_MATH_INSERT:
1333 case LFUN_MATH_MATRIX:
1334 case LFUN_MATH_DELIM:
1335 case LFUN_MATH_BIGDELIM: {
1336 cur.insert(new InsetMathHull(hullSimple));
1337 cur.dispatch(FuncRequest(LFUN_CHAR_FORWARD));
1342 case LFUN_FONT_EMPH: {
1343 LyXFont font(LyXFont::ALL_IGNORE);
1344 font.setEmph(LyXFont::TOGGLE);
1345 toggleAndShow(cur, this, font);
1349 case LFUN_FONT_BOLD: {
1350 LyXFont font(LyXFont::ALL_IGNORE);
1351 font.setSeries(LyXFont::BOLD_SERIES);
1352 toggleAndShow(cur, this, font);
1356 case LFUN_FONT_NOUN: {
1357 LyXFont font(LyXFont::ALL_IGNORE);
1358 font.setNoun(LyXFont::TOGGLE);
1359 toggleAndShow(cur, this, font);
1363 case LFUN_FONT_CODE: {
1364 LyXFont font(LyXFont::ALL_IGNORE);
1365 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1366 toggleAndShow(cur, this, font);
1370 case LFUN_FONT_SANS: {
1371 LyXFont font(LyXFont::ALL_IGNORE);
1372 font.setFamily(LyXFont::SANS_FAMILY);
1373 toggleAndShow(cur, this, font);
1377 case LFUN_FONT_ROMAN: {
1378 LyXFont font(LyXFont::ALL_IGNORE);
1379 font.setFamily(LyXFont::ROMAN_FAMILY);
1380 toggleAndShow(cur, this, font);
1384 case LFUN_FONT_DEFAULT: {
1385 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1386 toggleAndShow(cur, this, font);
1390 case LFUN_FONT_UNDERLINE: {
1391 LyXFont font(LyXFont::ALL_IGNORE);
1392 font.setUnderbar(LyXFont::TOGGLE);
1393 toggleAndShow(cur, this, font);
1397 case LFUN_FONT_SIZE: {
1398 LyXFont font(LyXFont::ALL_IGNORE);
1399 font.setLyXSize(to_utf8(cmd.argument()));
1400 toggleAndShow(cur, this, font);
1404 case LFUN_LANGUAGE: {
1405 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1408 LyXFont font(LyXFont::ALL_IGNORE);
1409 font.setLanguage(lang);
1410 toggleAndShow(cur, this, font);
1415 case LFUN_FONT_FREE_APPLY:
1416 toggleAndShow(cur, this, freefont, toggleall);
1417 cur.message(_("Character set"));
1420 // Set the freefont using the contents of \param data dispatched from
1421 // the frontends and apply it at the current cursor location.
1422 case LFUN_FONT_FREE_UPDATE: {
1425 if (bv_funcs::string2font(to_utf8(cmd.argument()), font, toggle)) {
1428 toggleAndShow(cur, this, freefont, toggleall);
1429 cur.message(_("Character set"));
1434 case LFUN_FINISHED_LEFT:
1435 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1438 case LFUN_FINISHED_RIGHT:
1439 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1443 case LFUN_FINISHED_UP:
1444 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_UP:\n" << cur << endl;
1448 case LFUN_FINISHED_DOWN:
1449 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_DOWN:\n" << cur << endl;
1453 case LFUN_LAYOUT_PARAGRAPH: {
1455 params2string(cur.paragraph(), data);
1456 data = "show\n" + data;
1457 bv->showDialogWithData("paragraph", data);
1461 case LFUN_PARAGRAPH_UPDATE: {
1463 params2string(cur.paragraph(), data);
1465 // Will the paragraph accept changes from the dialog?
1466 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1468 data = "update " + convert<string>(accept) + '\n' + data;
1469 bv->updateDialog("paragraph", data);
1473 case LFUN_ACCENT_UMLAUT:
1474 case LFUN_ACCENT_CIRCUMFLEX:
1475 case LFUN_ACCENT_GRAVE:
1476 case LFUN_ACCENT_ACUTE:
1477 case LFUN_ACCENT_TILDE:
1478 case LFUN_ACCENT_CEDILLA:
1479 case LFUN_ACCENT_MACRON:
1480 case LFUN_ACCENT_DOT:
1481 case LFUN_ACCENT_UNDERDOT:
1482 case LFUN_ACCENT_UNDERBAR:
1483 case LFUN_ACCENT_CARON:
1484 case LFUN_ACCENT_SPECIAL_CARON:
1485 case LFUN_ACCENT_BREVE:
1486 case LFUN_ACCENT_TIE:
1487 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1488 case LFUN_ACCENT_CIRCLE:
1489 case LFUN_ACCENT_OGONEK:
1490 theLyXFunc().handleKeyFunc(cmd.action);
1491 if (!cmd.argument().empty())
1492 // FIXME: Are all these characters encoded in one byte in utf8?
1493 bv->getIntl().getTransManager()
1494 .translateAndInsert(cmd.argument()[0], this, cur);
1497 case LFUN_FLOAT_LIST: {
1498 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1499 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1500 // not quite sure if we want this...
1502 cur.clearSelection();
1503 breakParagraph(cur);
1505 if (cur.lastpos() != 0) {
1507 breakParagraph(cur);
1510 setLayout(cur, tclass.defaultLayoutName());
1511 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, docstring(), 0);
1512 insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1515 lyxerr << "Non-existent float type: "
1516 << to_utf8(cmd.argument()) << endl;
1521 case LFUN_CHANGE_ACCEPT: {
1522 acceptOrRejectChanges(cur, ACCEPT);
1526 case LFUN_CHANGE_REJECT: {
1527 acceptOrRejectChanges(cur, REJECT);
1531 case LFUN_THESAURUS_ENTRY: {
1532 docstring arg = cmd.argument();
1534 arg = cur.selectionAsString(false);
1536 if (arg.size() > 100 || arg.empty()) {
1537 // Get word or selection
1538 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1539 arg = cur.selectionAsString(false);
1542 bv->showDialogWithData("thesaurus", to_utf8(arg));
1546 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1547 // Given data, an encoding of the ParagraphParameters
1548 // generated in the Paragraph dialog, this function sets
1549 // the current paragraph appropriately.
1550 istringstream is(to_utf8(cmd.argument()));
1553 ParagraphParameters params;
1558 params.labelWidthString(),
1560 cur.message(_("Paragraph layout set"));
1565 if (cur.selection()) {
1566 cur.selection() = false;
1570 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1575 lyxerr[Debug::ACTION]
1576 << BOOST_CURRENT_FUNCTION
1577 << ": Command " << cmd
1578 << " not DISPATCHED by LyXText" << endl;
1583 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1585 // FIXME: The cursor flag is reset two lines below
1586 // so we need to check here if some of the LFUN did touch that.
1587 // for now only LyXText::erase() and LyXText::backspace() do that.
1588 // The plan is to verify all the LFUNs and then to remove this
1589 // singleParUpdate boolean altogether.
1590 if (cur.result().update() & Update::Force) {
1591 singleParUpdate = false;
1595 // FIXME: the following code should go in favor of fine grained
1596 // update flag treatment.
1597 if (singleParUpdate) {
1598 // Inserting characters does not change par height
1599 ParagraphMetrics const & pms
1600 = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
1601 if (pms.dim().height()
1602 == olddim.height()) {
1603 // if so, update _only_ this paragraph
1604 cur.updateFlags(Update::SinglePar |
1606 Update::MultiParSel);
1613 && &oldTopSlice.inset() == &cur.inset()
1614 && oldTopSlice.idx() == cur.idx()
1615 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1616 && !cur.selection())
1617 // FIXME: it would be better if we could just do this
1619 //if (cur.result().update() != Update::FitCursor)
1622 // But some LFUNs do not set Update::FitCursor when needed, so we
1623 // do it for all. This is not very harmfull as FitCursor will provoke
1624 // a full redraw only if needed but still, a proper review of all LFUN
1625 // should be done and this needsUpdate boolean can then be removed.
1626 cur.updateFlags(Update::FitCursor);
1628 cur.updateFlags(Update::Force | Update::FitCursor);
1632 bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
1633 FuncStatus & flag) const
1635 BOOST_ASSERT(cur.text() == this);
1637 LyXFont const & font = real_current_font;
1639 InsetBase::Code code = InsetBase::NO_CODE;
1641 switch (cmd.action) {
1643 case LFUN_DEPTH_DECREMENT:
1644 enable = changeDepthAllowed(cur, DEC_DEPTH);
1647 case LFUN_DEPTH_INCREMENT:
1648 enable = changeDepthAllowed(cur, INC_DEPTH);
1652 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1655 case LFUN_BIBITEM_INSERT:
1656 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO);
1659 case LFUN_DIALOG_SHOW_NEW_INSET:
1660 if (cmd.argument() == "bibitem")
1661 code = InsetBase::BIBITEM_CODE;
1662 else if (cmd.argument() == "bibtex")
1663 code = InsetBase::BIBTEX_CODE;
1664 else if (cmd.argument() == "box")
1665 code = InsetBase::BOX_CODE;
1666 else if (cmd.argument() == "branch")
1667 code = InsetBase::BRANCH_CODE;
1668 else if (cmd.argument() == "citation")
1669 code = InsetBase::CITE_CODE;
1670 else if (cmd.argument() == "ert")
1671 code = InsetBase::ERT_CODE;
1672 else if (cmd.argument() == "external")
1673 code = InsetBase::EXTERNAL_CODE;
1674 else if (cmd.argument() == "float")
1675 code = InsetBase::FLOAT_CODE;
1676 else if (cmd.argument() == "graphics")
1677 code = InsetBase::GRAPHICS_CODE;
1678 else if (cmd.argument() == "include")
1679 code = InsetBase::INCLUDE_CODE;
1680 else if (cmd.argument() == "index")
1681 code = InsetBase::INDEX_CODE;
1682 else if (cmd.argument() == "nomenclature")
1683 code = InsetBase::NOMENCL_CODE;
1684 else if (cmd.argument() == "label")
1685 code = InsetBase::LABEL_CODE;
1686 else if (cmd.argument() == "note")
1687 code = InsetBase::NOTE_CODE;
1688 else if (cmd.argument() == "ref")
1689 code = InsetBase::REF_CODE;
1690 else if (cmd.argument() == "toc")
1691 code = InsetBase::TOC_CODE;
1692 else if (cmd.argument() == "url")
1693 code = InsetBase::URL_CODE;
1694 else if (cmd.argument() == "vspace")
1695 code = InsetBase::VSPACE_CODE;
1696 else if (cmd.argument() == "wrap")
1697 code = InsetBase::WRAP_CODE;
1700 case LFUN_ERT_INSERT:
1701 code = InsetBase::ERT_CODE;
1703 case LFUN_FOOTNOTE_INSERT:
1704 code = InsetBase::FOOT_CODE;
1706 case LFUN_TABULAR_INSERT:
1707 code = InsetBase::TABULAR_CODE;
1709 case LFUN_MARGINALNOTE_INSERT:
1710 code = InsetBase::MARGIN_CODE;
1712 case LFUN_FLOAT_INSERT:
1713 case LFUN_FLOAT_WIDE_INSERT:
1714 code = InsetBase::FLOAT_CODE;
1716 case LFUN_WRAP_INSERT:
1717 code = InsetBase::WRAP_CODE;
1719 case LFUN_FLOAT_LIST:
1720 code = InsetBase::FLOAT_LIST_CODE;
1723 case LFUN_LIST_INSERT:
1724 code = InsetBase::LIST_CODE;
1726 case LFUN_THEOREM_INSERT:
1727 code = InsetBase::THEOREM_CODE;
1730 case LFUN_CAPTION_INSERT:
1731 code = InsetBase::CAPTION_CODE;
1733 case LFUN_NOTE_INSERT:
1734 code = InsetBase::NOTE_CODE;
1736 case LFUN_CHARSTYLE_INSERT:
1737 code = InsetBase::CHARSTYLE_CODE;
1738 if (cur.buffer().params().getLyXTextClass().charstyles().empty())
1741 case LFUN_BOX_INSERT:
1742 code = InsetBase::BOX_CODE;
1744 case LFUN_BRANCH_INSERT:
1745 code = InsetBase::BRANCH_CODE;
1746 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1749 case LFUN_LABEL_INSERT:
1750 code = InsetBase::LABEL_CODE;
1752 case LFUN_OPTIONAL_INSERT:
1753 code = InsetBase::OPTARG_CODE;
1754 enable = numberOfOptArgs(cur.paragraph())
1755 < cur.paragraph().layout()->optionalargs;
1757 case LFUN_ENVIRONMENT_INSERT:
1758 code = InsetBase::BOX_CODE;
1760 case LFUN_INDEX_INSERT:
1761 code = InsetBase::INDEX_CODE;
1763 case LFUN_INDEX_PRINT:
1764 code = InsetBase::INDEX_PRINT_CODE;
1766 case LFUN_NOMENCL_INSERT:
1767 code = InsetBase::NOMENCL_CODE;
1769 case LFUN_NOMENCL_PRINT:
1770 code = InsetBase::NOMENCL_PRINT_CODE;
1772 case LFUN_TOC_INSERT:
1773 code = InsetBase::TOC_CODE;
1775 case LFUN_HTML_INSERT:
1776 case LFUN_URL_INSERT:
1777 code = InsetBase::URL_CODE;
1779 case LFUN_QUOTE_INSERT:
1780 // always allow this, since we will inset a raw quote
1781 // if an inset is not allowed.
1783 case LFUN_HYPHENATION_POINT_INSERT:
1784 case LFUN_LIGATURE_BREAK_INSERT:
1785 case LFUN_HFILL_INSERT:
1786 case LFUN_MENU_SEPARATOR_INSERT:
1787 case LFUN_DOTS_INSERT:
1788 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
1789 code = InsetBase::SPECIALCHAR_CODE;
1791 case LFUN_SPACE_INSERT:
1792 // slight hack: we know this is allowed in math mode
1794 code = InsetBase::SPACE_CODE;
1797 case LFUN_INSET_MODIFY:
1798 // We need to disable this, because we may get called for a
1800 // InsetTabular::getStatus() -> InsetText::getStatus()
1801 // and we don't handle LFUN_INSET_MODIFY.
1805 case LFUN_FONT_EMPH:
1806 flag.setOnOff(font.emph() == LyXFont::ON);
1809 case LFUN_FONT_NOUN:
1810 flag.setOnOff(font.noun() == LyXFont::ON);
1813 case LFUN_FONT_BOLD:
1814 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
1817 case LFUN_FONT_SANS:
1818 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
1821 case LFUN_FONT_ROMAN:
1822 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
1825 case LFUN_FONT_CODE:
1826 flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
1831 enable = cur.selection();
1835 if (cmd.argument().empty()) {
1836 if (theClipboard().isInternal())
1837 enable = cap::numberOfSelections() > 0;
1839 enable = !theClipboard().empty();
1841 string const arg = to_utf8(cmd.argument());
1842 if (isStrUnsignedInt(arg)) {
1843 unsigned int n = convert<unsigned int>(arg);
1844 enable = cap::numberOfSelections() > n;
1851 case LFUN_CLIPBOARD_PASTE:
1852 enable = !theClipboard().empty();
1855 case LFUN_PRIMARY_SELECTION_PASTE:
1856 enable = cur.selection() || !theSelection().empty();
1859 case LFUN_PARAGRAPH_MOVE_UP:
1860 enable = cur.pit() > 0 && !cur.selection();
1863 case LFUN_PARAGRAPH_MOVE_DOWN:
1864 enable = cur.pit() < cur.lastpit() && !cur.selection();
1867 case LFUN_INSET_DISSOLVE:
1868 enable = !isMainText(*cur.bv().buffer()) && cur.inset().nargs() == 1;
1871 case LFUN_CHANGE_ACCEPT:
1872 case LFUN_CHANGE_REJECT:
1873 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
1874 // In principle, these LFUNs should only be enabled if there
1875 // is a change at the current position/in the current selection.
1876 // However, without proper optimizations, this will inevitably
1877 // result in unacceptable performance - just imagine a user who
1878 // wants to select the complete content of a long document.
1882 case LFUN_WORD_DELETE_FORWARD:
1883 case LFUN_WORD_DELETE_BACKWARD:
1884 case LFUN_LINE_DELETE:
1885 case LFUN_WORD_FORWARD:
1886 case LFUN_WORD_BACKWARD:
1887 case LFUN_CHAR_FORWARD:
1888 case LFUN_CHAR_FORWARD_SELECT:
1889 case LFUN_CHAR_BACKWARD:
1890 case LFUN_CHAR_BACKWARD_SELECT:
1892 case LFUN_UP_SELECT:
1894 case LFUN_DOWN_SELECT:
1895 case LFUN_PARAGRAPH_UP_SELECT:
1896 case LFUN_PARAGRAPH_DOWN_SELECT:
1897 case LFUN_SCREEN_UP_SELECT:
1898 case LFUN_SCREEN_DOWN_SELECT:
1899 case LFUN_LINE_BEGIN_SELECT:
1900 case LFUN_LINE_END_SELECT:
1901 case LFUN_WORD_FORWARD_SELECT:
1902 case LFUN_WORD_BACKWARD_SELECT:
1903 case LFUN_WORD_SELECT:
1904 case LFUN_PARAGRAPH_UP:
1905 case LFUN_PARAGRAPH_DOWN:
1906 case LFUN_SCREEN_UP:
1907 case LFUN_SCREEN_DOWN:
1908 case LFUN_LINE_BEGIN:
1910 case LFUN_BREAK_LINE:
1911 case LFUN_CHAR_DELETE_FORWARD:
1912 case LFUN_DELETE_FORWARD_SKIP:
1913 case LFUN_CHAR_DELETE_BACKWARD:
1914 case LFUN_DELETE_BACKWARD_SKIP:
1915 case LFUN_BREAK_PARAGRAPH:
1916 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
1917 case LFUN_BREAK_PARAGRAPH_SKIP:
1918 case LFUN_PARAGRAPH_SPACING:
1919 case LFUN_INSET_INSERT:
1920 case LFUN_WORD_UPCASE:
1921 case LFUN_WORD_LOWCASE:
1922 case LFUN_WORD_CAPITALIZE:
1923 case LFUN_CHARS_TRANSPOSE:
1924 case LFUN_SERVER_GET_XY:
1925 case LFUN_SERVER_SET_XY:
1926 case LFUN_SERVER_GET_FONT:
1927 case LFUN_SERVER_GET_LAYOUT:
1929 case LFUN_DATE_INSERT:
1930 case LFUN_SELF_INSERT:
1931 case LFUN_LINE_INSERT:
1932 case LFUN_PAGEBREAK_INSERT:
1933 case LFUN_CLEARPAGE_INSERT:
1934 case LFUN_CLEARDOUBLEPAGE_INSERT:
1935 case LFUN_MATH_DISPLAY:
1936 case LFUN_MATH_IMPORT_SELECTION:
1937 case LFUN_MATH_INSERT:
1938 case LFUN_MATH_MODE:
1939 case LFUN_MATH_MACRO:
1940 case LFUN_MATH_MATRIX:
1941 case LFUN_MATH_DELIM:
1942 case LFUN_MATH_BIGDELIM:
1943 case LFUN_MATH_SUBSCRIPT:
1944 case LFUN_MATH_SUPERSCRIPT:
1945 case LFUN_FONT_DEFAULT:
1946 case LFUN_FONT_UNDERLINE:
1947 case LFUN_FONT_SIZE:
1949 case LFUN_FONT_FREE_APPLY:
1950 case LFUN_FONT_FREE_UPDATE:
1951 case LFUN_LAYOUT_PARAGRAPH:
1952 case LFUN_PARAGRAPH_UPDATE:
1953 case LFUN_ACCENT_UMLAUT:
1954 case LFUN_ACCENT_CIRCUMFLEX:
1955 case LFUN_ACCENT_GRAVE:
1956 case LFUN_ACCENT_ACUTE:
1957 case LFUN_ACCENT_TILDE:
1958 case LFUN_ACCENT_CEDILLA:
1959 case LFUN_ACCENT_MACRON:
1960 case LFUN_ACCENT_DOT:
1961 case LFUN_ACCENT_UNDERDOT:
1962 case LFUN_ACCENT_UNDERBAR:
1963 case LFUN_ACCENT_CARON:
1964 case LFUN_ACCENT_SPECIAL_CARON:
1965 case LFUN_ACCENT_BREVE:
1966 case LFUN_ACCENT_TIE:
1967 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1968 case LFUN_ACCENT_CIRCLE:
1969 case LFUN_ACCENT_OGONEK:
1970 case LFUN_THESAURUS_ENTRY:
1971 case LFUN_PARAGRAPH_PARAMS_APPLY:
1973 case LFUN_BUFFER_END:
1974 case LFUN_BUFFER_BEGIN:
1975 case LFUN_BUFFER_BEGIN_SELECT:
1976 case LFUN_BUFFER_END_SELECT:
1977 case LFUN_UNICODE_INSERT:
1978 // these are handled in our dispatch()
1986 if (code != InsetBase::NO_CODE
1987 && (cur.empty() || !cur.inset().insetAllowed(code)))
1990 flag.enabled(enable);
1995 void LyXText::pasteString(LCursor & cur, docstring const & clip,
1998 cur.clearSelection();
1999 if (!clip.empty()) {
2002 insertStringAsParagraphs(cur, clip);
2004 insertStringAsLines(cur, clip);