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);
664 //Reset text style to default
665 setFont(cur, LyXFont(LyXFont::ALL_INHERIT), 0);
670 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
671 cap::replaceSelection(cur);
672 breakParagraph(cur, 1);
677 case LFUN_BREAK_PARAGRAPH_SKIP: {
678 // When at the beginning of a paragraph, remove
679 // indentation. Otherwise, do the same as LFUN_BREAK_PARAGRAPH.
680 cap::replaceSelection(cur);
682 cur.paragraph().params().labelWidthString(docstring());
684 breakParagraph(cur, 0);
690 case LFUN_PARAGRAPH_SPACING: {
691 Paragraph & par = cur.paragraph();
692 Spacing::Space cur_spacing = par.params().spacing().getSpace();
693 string cur_value = "1.0";
694 if (cur_spacing == Spacing::Other)
695 cur_value = par.params().spacing().getValueAsString();
697 istringstream is(to_utf8(cmd.argument()));
700 Spacing::Space new_spacing = cur_spacing;
701 string new_value = cur_value;
703 lyxerr << "Missing argument to `paragraph-spacing'"
705 } else if (tmp == "single") {
706 new_spacing = Spacing::Single;
707 } else if (tmp == "onehalf") {
708 new_spacing = Spacing::Onehalf;
709 } else if (tmp == "double") {
710 new_spacing = Spacing::Double;
711 } else if (tmp == "other") {
712 new_spacing = Spacing::Other;
713 string tmpval = "0.0";
715 lyxerr << "new_value = " << tmpval << endl;
718 } else if (tmp == "default") {
719 new_spacing = Spacing::Default;
721 lyxerr << to_utf8(_("Unknown spacing argument: "))
722 << to_utf8(cmd.argument()) << endl;
724 if (cur_spacing != new_spacing || cur_value != new_value)
725 par.params().spacing(Spacing(new_spacing, new_value));
729 case LFUN_INSET_INSERT: {
731 InsetBase * inset = createInset(bv, cmd);
733 // FIXME (Abdel 01/02/2006):
734 // What follows would be a partial fix for bug 2154:
735 // http://bugzilla.lyx.org/show_bug.cgi?id=2154
736 // This automatically put the label inset _after_ a
737 // numbered section. It should be possible to extend the mechanism
738 // to any kind of LateX environement.
739 // The correct way to fix that bug would be at LateX generation.
740 // I'll let the code here for reference as it could be used for some
741 // other feature like "automatic labelling".
743 Paragraph & par = pars_[cur.pit()];
744 if (inset->lyxCode() == InsetBase::LABEL_CODE
745 && par.layout()->labeltype == LABEL_COUNTER) {
746 // Go to the end of the paragraph
747 // Warning: Because of Change-Tracking, the last
748 // position is 'size()' and not 'size()-1':
749 cur.pos() = par.size();
750 // Insert a new paragraph
751 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
755 insertInset(cur, inset);
761 case LFUN_INSET_DISSOLVE:
762 needsUpdate |= dissolveInset(cur);
765 case LFUN_INSET_SETTINGS:
766 cur.inset().showInsetDialog(bv);
769 case LFUN_SPACE_INSERT:
770 if (cur.paragraph().layout()->free_spacing)
771 insertChar(cur, ' ');
773 doInsertInset(cur, this, cmd, false, false);
776 moveCursor(cur, false);
779 case LFUN_HYPHENATION_POINT_INSERT:
780 specialChar(cur, InsetSpecialChar::HYPHENATION);
783 case LFUN_LIGATURE_BREAK_INSERT:
784 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
787 case LFUN_DOTS_INSERT:
788 specialChar(cur, InsetSpecialChar::LDOTS);
791 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
792 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
795 case LFUN_MENU_SEPARATOR_INSERT:
796 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
799 case LFUN_WORD_UPCASE:
800 changeCase(cur, LyXText::text_uppercase);
803 case LFUN_WORD_LOWCASE:
804 changeCase(cur, LyXText::text_lowercase);
807 case LFUN_WORD_CAPITALIZE:
808 changeCase(cur, LyXText::text_capitalization);
811 case LFUN_CHARS_TRANSPOSE:
816 cur.message(_("Paste"));
817 cap::replaceSelection(cur);
818 if (cmd.argument().empty() && !theClipboard().isInternal())
819 pasteClipboard(cur, bv->buffer()->errorList("Paste"));
821 string const arg(to_utf8(cmd.argument()));
822 pasteFromStack(cur, bv->buffer()->errorList("Paste"),
823 isStrUnsignedInt(arg) ?
824 convert<unsigned int>(arg) :
827 bv->buffer()->errors("Paste");
828 cur.clearSelection(); // bug 393
834 cutSelection(cur, true, true);
835 cur.message(_("Cut"));
840 cur.message(_("Copy"));
843 case LFUN_SERVER_GET_XY:
844 cur.message(from_utf8(
845 convert<string>(cursorX(cur.bv(), cur.top(), cur.boundary()))
846 + ' ' + convert<string>(cursorY(cur.bv(), cur.top(), cur.boundary()))));
849 case LFUN_SERVER_SET_XY: {
852 istringstream is(to_utf8(cmd.argument()));
855 lyxerr << "SETXY: Could not parse coordinates in '"
856 << to_utf8(cmd.argument()) << std::endl;
858 setCursorFromCoordinates(cur, x, y);
862 case LFUN_SERVER_GET_FONT:
863 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
864 cur.message(from_ascii("E"));
865 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
866 cur.message(from_ascii("N"));
868 cur.message(from_ascii("0"));
871 case LFUN_SERVER_GET_LAYOUT:
872 cur.message(from_utf8(cur.paragraph().layout()->name()));
876 string layout = to_ascii(cmd.argument());
877 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) " << layout << endl;
879 // Derive layout number from given argument (string)
880 // and current buffer's textclass (number)
881 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
883 layout = tclass.defaultLayoutName();
884 bool hasLayout = tclass.hasLayout(layout);
886 // If the entry is obsolete, use the new one instead.
888 string const & obs = tclass[layout]->obsoleted_by();
894 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
895 from_utf8(N_(" not known")));
899 bool change_layout = (current_layout != layout);
901 if (!change_layout && cur.selection() &&
902 cur.selBegin().pit() != cur.selEnd().pit())
904 pit_type spit = cur.selBegin().pit();
905 pit_type epit = cur.selEnd().pit() + 1;
906 while (spit != epit) {
907 if (pars_[spit].layout()->name() != current_layout) {
908 change_layout = true;
916 current_layout = layout;
917 setLayout(cur, layout);
918 // inform the GUI that the layout has changed.
919 bv->layoutChanged(layout);
925 case LFUN_CLIPBOARD_PASTE:
926 cur.clearSelection();
927 pasteClipboard(cur, bv->buffer()->errorList("Paste"),
928 cmd.argument() == "paragraph");
929 bv->buffer()->errors("Paste");
932 case LFUN_PRIMARY_SELECTION_PASTE:
933 pasteString(cur, theSelection().get(),
934 cmd.argument() == "paragraph");
937 case LFUN_UNICODE_INSERT: {
938 if (cmd.argument().empty())
940 docstring hexstring = cmd.argument();
941 if (lyx::support::isHex(hexstring)) {
942 char_type c = lyx::support::hexToInt(hexstring);
943 if (c > 32 && c < 0x10ffff) {
944 lyxerr << "Inserting c: " << c << endl;
945 docstring s = docstring(1, c);
946 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
952 case LFUN_QUOTE_INSERT: {
953 cap::replaceSelection(cur);
954 Paragraph & par = cur.paragraph();
955 pos_type pos = cur.pos();
959 else if (cur.prevInset() && cur.prevInset()->isSpace())
962 c = par.getChar(pos - 1);
964 LyXLayout_ptr const & style = par.layout();
966 BufferParams const & bufparams = bv->buffer()->params();
967 if (!style->pass_thru
968 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
969 string arg = to_utf8(cmd.argument());
971 cur.insert(new InsetQuotes(c,
972 bufparams.quotes_language,
973 InsetQuotes::SingleQ));
975 cur.insert(new InsetQuotes(c,
976 bufparams.quotes_language,
977 InsetQuotes::DoubleQ));
981 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
985 case LFUN_DATE_INSERT:
986 if (cmd.argument().empty())
987 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
988 formatted_time(current_time())));
990 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
991 formatted_time(current_time(), to_utf8(cmd.argument()))));
994 case LFUN_MOUSE_TRIPLE:
995 if (cmd.button() == mouse_button::button1) {
1005 case LFUN_MOUSE_DOUBLE:
1006 if (cmd.button() == mouse_button::button1) {
1007 selectWord(cur, WHOLE_WORD_STRICT);
1012 // Single-click on work area
1013 case LFUN_MOUSE_PRESS: {
1014 // Right click on a footnote flag opens float menu
1015 if (cmd.button() == mouse_button::button3)
1016 cur.clearSelection();
1018 // Middle button press pastes if we have a selection
1019 // We do this here as if the selection was inside an inset
1020 // it could get cleared on the unlocking of the inset so
1021 // we have to check this first
1022 bool paste_internally = false;
1023 if (cmd.button() == mouse_button::button2 && cap::selection()) {
1024 // Copy the selection buffer to the clipboard
1025 // stack, because we want it to appear in the
1026 // "Edit->Paste recent" menu.
1027 cap::copySelectionToStack();
1028 paste_internally = true;
1031 // we have to update after dePM triggered
1032 bool update = bv->mouseSetCursor(cur);
1034 // Insert primary selection with middle mouse
1035 // if there is a local selection in the current buffer,
1037 if (cmd.button() == mouse_button::button2) {
1038 if (paste_internally) {
1039 cap::pasteSelection(cur, bv->buffer()->errorList("Paste"));
1040 bv->buffer()->errors("Paste");
1041 cur.clearSelection(); // bug 393
1045 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
1048 if (!update && cmd.button() == mouse_button::button1) {
1049 needsUpdate = false;
1056 case LFUN_MOUSE_MOTION: {
1057 // Only use motion with button 1
1058 //if (cmd.button() != mouse_button::button1)
1061 // ignore motions deeper nested than the real anchor
1062 LCursor & bvcur = cur.bv().cursor();
1063 if (bvcur.anchor_.hasPart(cur)) {
1064 CursorSlice old = bvcur.top();
1066 int const wh = bv->workHeight();
1067 int const y = std::max(0, std::min(wh - 1, cmd.y));
1069 setCursorFromCoordinates(cur, cmd.x, y);
1070 cur.x_target() = cmd.x;
1072 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1074 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1075 // This is to allow jumping over large insets
1076 if (cur.top() == old) {
1078 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1080 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1083 if (cur.top() == old)
1086 // don't set anchor_
1087 bvcur.setCursor(cur);
1088 bvcur.selection() = true;
1089 //lyxerr << "MOTION: " << bv->cursor() << endl;
1097 case LFUN_MOUSE_RELEASE: {
1098 if (cmd.button() == mouse_button::button2)
1101 if (cmd.button() == mouse_button::button1) {
1102 // if there is new selection, update persistent
1103 // selection, otherwise, single click does not
1104 // clear persistent selection buffer
1105 if (cur.selection()) {
1107 // if double click, cur is moved to the end of word by selectWord
1108 // but bvcur is current mouse position
1109 LCursor & bvcur = cur.bv().cursor();
1110 bvcur.selection() = true;
1111 saveSelection(bvcur);
1113 needsUpdate = false;
1121 case LFUN_SELF_INSERT: {
1122 if (cmd.argument().empty())
1125 // Automatically delete the currently selected
1126 // text and replace it with what is being
1127 // typed in now. Depends on lyxrc settings
1128 // "auto_region_delete", which defaults to
1131 if (lyxrc.auto_region_delete)
1132 if (cur.selection())
1133 cutSelection(cur, false, false);
1135 cur.clearSelection();
1136 LyXFont const old_font = real_current_font;
1138 docstring::const_iterator cit = cmd.argument().begin();
1139 docstring::const_iterator end = cmd.argument().end();
1140 for (; cit != end; ++cit)
1142 bv->getIntl().getTransManager().
1143 translateAndInsert(*cit, this);
1145 insertChar(bv->cursor(), *cit);
1149 moveCursor(cur, false);
1153 case LFUN_URL_INSERT: {
1154 InsetCommandParams p("url");
1155 string const data = InsetCommandMailer::params2string("url", p);
1156 bv->showInsetDialog("url", data, 0);
1160 case LFUN_HTML_INSERT: {
1161 InsetCommandParams p("htmlurl");
1162 string const data = InsetCommandMailer::params2string("url", p);
1163 bv->showInsetDialog("url", data, 0);
1167 case LFUN_LABEL_INSERT: {
1168 InsetCommandParams p("label");
1169 // Try to generate a valid label
1170 p["name"] = (cmd.argument().empty()) ?
1171 cur.getPossibleLabel() :
1173 string const data = InsetCommandMailer::params2string("label", p);
1175 if (cmd.argument().empty()) {
1176 bv->showInsetDialog("label", data, 0);
1178 FuncRequest fr(LFUN_INSET_INSERT, data);
1186 case LFUN_LIST_INSERT:
1187 case LFUN_THEOREM_INSERT:
1189 case LFUN_CAPTION_INSERT:
1190 // Open the inset, and move the current selection
1192 doInsertInset(cur, this, cmd, true, true);
1194 updateLabels(*bv->buffer());
1196 case LFUN_NOTE_INSERT:
1197 case LFUN_CHARSTYLE_INSERT:
1198 case LFUN_BOX_INSERT:
1199 case LFUN_BRANCH_INSERT:
1200 case LFUN_BIBITEM_INSERT:
1201 case LFUN_ERT_INSERT:
1202 case LFUN_FOOTNOTE_INSERT:
1203 case LFUN_MARGINALNOTE_INSERT:
1204 case LFUN_OPTIONAL_INSERT:
1205 case LFUN_ENVIRONMENT_INSERT:
1206 // Open the inset, and move the current selection
1208 doInsertInset(cur, this, cmd, true, true);
1212 case LFUN_TABULAR_INSERT:
1213 // if there were no arguments, just open the dialog
1214 if (doInsertInset(cur, this, cmd, false, true))
1217 bv->showDialog("tabularcreate");
1221 case LFUN_FLOAT_INSERT:
1222 case LFUN_FLOAT_WIDE_INSERT:
1223 case LFUN_WRAP_INSERT: {
1224 bool content = cur.selection(); // will some text be moved into the inset?
1226 doInsertInset(cur, this, cmd, true, true);
1228 ParagraphList & pars = cur.text()->paragraphs();
1230 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1232 // add a separate paragraph for the caption inset
1233 pars.push_back(Paragraph());
1234 pars.back().setInsetOwner(pars[0].inInset());
1235 pars.back().layout(tclass.defaultLayout());
1237 int cap_pit = pars.size() - 1;
1239 // if an empty inset was created, we create an additional empty
1240 // paragraph at the bottom so that the user can choose where to put
1241 // the graphics (or table).
1243 pars.push_back(Paragraph());
1244 pars.back().setInsetOwner(pars[0].inInset());
1245 pars.back().layout(tclass.defaultLayout());
1249 // reposition the cursor to the caption
1250 cur.pit() = cap_pit;
1252 cur.dispatch(FuncRequest(LFUN_CAPTION_INSERT));
1253 // FIXME: When leaving the Float (or Wrap) inset we should
1254 // delete any empty paragraph left above or below the
1259 case LFUN_INDEX_INSERT:
1260 case LFUN_NOMENCL_INSERT: {
1261 InsetBase * inset = createInset(&cur.bv(), cmd);
1266 cur.clearSelection();
1267 insertInset(cur, inset);
1268 inset->edit(cur, true);
1269 // Show the dialog for the nomenclature entry, since the
1270 // description entry still needs to be filled in.
1271 if (cmd.action == LFUN_NOMENCL_INSERT)
1272 InsetCommandMailer("nomenclature",
1273 *reinterpret_cast<InsetCommand *>(inset)).showDialog(&cur.bv());
1278 case LFUN_INDEX_PRINT:
1279 case LFUN_NOMENCL_PRINT:
1280 case LFUN_TOC_INSERT:
1281 case LFUN_HFILL_INSERT:
1282 case LFUN_LINE_INSERT:
1283 case LFUN_PAGEBREAK_INSERT:
1284 case LFUN_CLEARPAGE_INSERT:
1285 case LFUN_CLEARDOUBLEPAGE_INSERT:
1287 doInsertInset(cur, this, cmd, false, false);
1291 case LFUN_DEPTH_DECREMENT:
1292 changeDepth(cur, DEC_DEPTH);
1295 case LFUN_DEPTH_INCREMENT:
1296 changeDepth(cur, INC_DEPTH);
1299 case LFUN_MATH_DISPLAY:
1300 mathDispatch(cur, cmd, true);
1303 case LFUN_MATH_IMPORT_SELECTION:
1304 case LFUN_MATH_MODE:
1305 if (cmd.argument() == "on")
1306 // don't pass "on" as argument
1307 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1309 mathDispatch(cur, cmd, false);
1312 case LFUN_MATH_MACRO:
1313 if (cmd.argument().empty())
1314 cur.errorMessage(from_utf8(N_("Missing argument")));
1316 string s = to_utf8(cmd.argument());
1317 string const s1 = token(s, ' ', 1);
1318 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1319 string const s2 = token(s, ' ', 2);
1320 string const type = s2.empty() ? "newcommand" : s2;
1321 cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, from_utf8(type)));
1322 //cur.nextInset()->edit(cur, true);
1326 // passthrough hat and underscore outside mathed:
1327 case LFUN_MATH_SUBSCRIPT:
1328 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1330 case LFUN_MATH_SUPERSCRIPT:
1331 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1334 case LFUN_MATH_INSERT:
1335 case LFUN_MATH_MATRIX:
1336 case LFUN_MATH_DELIM:
1337 case LFUN_MATH_BIGDELIM: {
1338 cur.insert(new InsetMathHull(hullSimple));
1339 cur.dispatch(FuncRequest(LFUN_CHAR_FORWARD));
1344 case LFUN_FONT_EMPH: {
1345 LyXFont font(LyXFont::ALL_IGNORE);
1346 font.setEmph(LyXFont::TOGGLE);
1347 toggleAndShow(cur, this, font);
1351 case LFUN_FONT_BOLD: {
1352 LyXFont font(LyXFont::ALL_IGNORE);
1353 font.setSeries(LyXFont::BOLD_SERIES);
1354 toggleAndShow(cur, this, font);
1358 case LFUN_FONT_NOUN: {
1359 LyXFont font(LyXFont::ALL_IGNORE);
1360 font.setNoun(LyXFont::TOGGLE);
1361 toggleAndShow(cur, this, font);
1365 case LFUN_FONT_CODE: {
1366 LyXFont font(LyXFont::ALL_IGNORE);
1367 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1368 toggleAndShow(cur, this, font);
1372 case LFUN_FONT_SANS: {
1373 LyXFont font(LyXFont::ALL_IGNORE);
1374 font.setFamily(LyXFont::SANS_FAMILY);
1375 toggleAndShow(cur, this, font);
1379 case LFUN_FONT_ROMAN: {
1380 LyXFont font(LyXFont::ALL_IGNORE);
1381 font.setFamily(LyXFont::ROMAN_FAMILY);
1382 toggleAndShow(cur, this, font);
1386 case LFUN_FONT_DEFAULT: {
1387 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1388 toggleAndShow(cur, this, font);
1392 case LFUN_FONT_UNDERLINE: {
1393 LyXFont font(LyXFont::ALL_IGNORE);
1394 font.setUnderbar(LyXFont::TOGGLE);
1395 toggleAndShow(cur, this, font);
1399 case LFUN_FONT_SIZE: {
1400 LyXFont font(LyXFont::ALL_IGNORE);
1401 font.setLyXSize(to_utf8(cmd.argument()));
1402 toggleAndShow(cur, this, font);
1406 case LFUN_LANGUAGE: {
1407 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1410 LyXFont font(LyXFont::ALL_IGNORE);
1411 font.setLanguage(lang);
1412 toggleAndShow(cur, this, font);
1417 case LFUN_FONT_FREE_APPLY:
1418 toggleAndShow(cur, this, freefont, toggleall);
1419 cur.message(_("Character set"));
1422 // Set the freefont using the contents of \param data dispatched from
1423 // the frontends and apply it at the current cursor location.
1424 case LFUN_FONT_FREE_UPDATE: {
1427 if (bv_funcs::string2font(to_utf8(cmd.argument()), font, toggle)) {
1430 toggleAndShow(cur, this, freefont, toggleall);
1431 cur.message(_("Character set"));
1436 case LFUN_FINISHED_LEFT:
1437 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1440 case LFUN_FINISHED_RIGHT:
1441 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1445 case LFUN_FINISHED_UP:
1446 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_UP:\n" << cur << endl;
1450 case LFUN_FINISHED_DOWN:
1451 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_DOWN:\n" << cur << endl;
1455 case LFUN_LAYOUT_PARAGRAPH: {
1457 params2string(cur.paragraph(), data);
1458 data = "show\n" + data;
1459 bv->showDialogWithData("paragraph", data);
1463 case LFUN_PARAGRAPH_UPDATE: {
1465 params2string(cur.paragraph(), data);
1467 // Will the paragraph accept changes from the dialog?
1468 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1470 data = "update " + convert<string>(accept) + '\n' + data;
1471 bv->updateDialog("paragraph", data);
1475 case LFUN_ACCENT_UMLAUT:
1476 case LFUN_ACCENT_CIRCUMFLEX:
1477 case LFUN_ACCENT_GRAVE:
1478 case LFUN_ACCENT_ACUTE:
1479 case LFUN_ACCENT_TILDE:
1480 case LFUN_ACCENT_CEDILLA:
1481 case LFUN_ACCENT_MACRON:
1482 case LFUN_ACCENT_DOT:
1483 case LFUN_ACCENT_UNDERDOT:
1484 case LFUN_ACCENT_UNDERBAR:
1485 case LFUN_ACCENT_CARON:
1486 case LFUN_ACCENT_SPECIAL_CARON:
1487 case LFUN_ACCENT_BREVE:
1488 case LFUN_ACCENT_TIE:
1489 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1490 case LFUN_ACCENT_CIRCLE:
1491 case LFUN_ACCENT_OGONEK:
1492 theLyXFunc().handleKeyFunc(cmd.action);
1493 if (!cmd.argument().empty())
1494 // FIXME: Are all these characters encoded in one byte in utf8?
1495 bv->getIntl().getTransManager()
1496 .translateAndInsert(cmd.argument()[0], this, cur);
1499 case LFUN_FLOAT_LIST: {
1500 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1501 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1502 // not quite sure if we want this...
1504 cur.clearSelection();
1505 breakParagraph(cur);
1507 if (cur.lastpos() != 0) {
1509 breakParagraph(cur);
1512 setLayout(cur, tclass.defaultLayoutName());
1513 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, docstring(), 0);
1514 insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1517 lyxerr << "Non-existent float type: "
1518 << to_utf8(cmd.argument()) << endl;
1523 case LFUN_CHANGE_ACCEPT: {
1524 acceptOrRejectChanges(cur, ACCEPT);
1528 case LFUN_CHANGE_REJECT: {
1529 acceptOrRejectChanges(cur, REJECT);
1533 case LFUN_THESAURUS_ENTRY: {
1534 docstring arg = cmd.argument();
1536 arg = cur.selectionAsString(false);
1538 if (arg.size() > 100 || arg.empty()) {
1539 // Get word or selection
1540 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1541 arg = cur.selectionAsString(false);
1544 bv->showDialogWithData("thesaurus", to_utf8(arg));
1548 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1549 // Given data, an encoding of the ParagraphParameters
1550 // generated in the Paragraph dialog, this function sets
1551 // the current paragraph appropriately.
1552 istringstream is(to_utf8(cmd.argument()));
1555 ParagraphParameters params;
1560 params.labelWidthString(),
1562 cur.message(_("Paragraph layout set"));
1567 if (cur.selection()) {
1568 cur.selection() = false;
1572 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1577 lyxerr[Debug::ACTION]
1578 << BOOST_CURRENT_FUNCTION
1579 << ": Command " << cmd
1580 << " not DISPATCHED by LyXText" << endl;
1585 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1587 // FIXME: The cursor flag is reset two lines below
1588 // so we need to check here if some of the LFUN did touch that.
1589 // for now only LyXText::erase() and LyXText::backspace() do that.
1590 // The plan is to verify all the LFUNs and then to remove this
1591 // singleParUpdate boolean altogether.
1592 if (cur.result().update() & Update::Force) {
1593 singleParUpdate = false;
1597 // FIXME: the following code should go in favor of fine grained
1598 // update flag treatment.
1599 if (singleParUpdate) {
1600 // Inserting characters does not change par height
1601 ParagraphMetrics const & pms
1602 = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
1603 if (pms.dim().height()
1604 == olddim.height()) {
1605 // if so, update _only_ this paragraph
1606 cur.updateFlags(Update::SinglePar |
1608 Update::MultiParSel);
1615 && &oldTopSlice.inset() == &cur.inset()
1616 && oldTopSlice.idx() == cur.idx()
1617 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1618 && !cur.selection())
1619 // FIXME: it would be better if we could just do this
1621 //if (cur.result().update() != Update::FitCursor)
1624 // But some LFUNs do not set Update::FitCursor when needed, so we
1625 // do it for all. This is not very harmfull as FitCursor will provoke
1626 // a full redraw only if needed but still, a proper review of all LFUN
1627 // should be done and this needsUpdate boolean can then be removed.
1628 cur.updateFlags(Update::FitCursor);
1630 cur.updateFlags(Update::Force | Update::FitCursor);
1634 bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
1635 FuncStatus & flag) const
1637 BOOST_ASSERT(cur.text() == this);
1639 LyXFont const & font = real_current_font;
1641 InsetBase::Code code = InsetBase::NO_CODE;
1643 switch (cmd.action) {
1645 case LFUN_DEPTH_DECREMENT:
1646 enable = changeDepthAllowed(cur, DEC_DEPTH);
1649 case LFUN_DEPTH_INCREMENT:
1650 enable = changeDepthAllowed(cur, INC_DEPTH);
1654 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1657 case LFUN_BIBITEM_INSERT:
1658 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO);
1661 case LFUN_DIALOG_SHOW_NEW_INSET:
1662 if (cmd.argument() == "bibitem")
1663 code = InsetBase::BIBITEM_CODE;
1664 else if (cmd.argument() == "bibtex")
1665 code = InsetBase::BIBTEX_CODE;
1666 else if (cmd.argument() == "box")
1667 code = InsetBase::BOX_CODE;
1668 else if (cmd.argument() == "branch")
1669 code = InsetBase::BRANCH_CODE;
1670 else if (cmd.argument() == "citation")
1671 code = InsetBase::CITE_CODE;
1672 else if (cmd.argument() == "ert")
1673 code = InsetBase::ERT_CODE;
1674 else if (cmd.argument() == "external")
1675 code = InsetBase::EXTERNAL_CODE;
1676 else if (cmd.argument() == "float")
1677 code = InsetBase::FLOAT_CODE;
1678 else if (cmd.argument() == "graphics")
1679 code = InsetBase::GRAPHICS_CODE;
1680 else if (cmd.argument() == "include")
1681 code = InsetBase::INCLUDE_CODE;
1682 else if (cmd.argument() == "index")
1683 code = InsetBase::INDEX_CODE;
1684 else if (cmd.argument() == "nomenclature")
1685 code = InsetBase::NOMENCL_CODE;
1686 else if (cmd.argument() == "label")
1687 code = InsetBase::LABEL_CODE;
1688 else if (cmd.argument() == "note")
1689 code = InsetBase::NOTE_CODE;
1690 else if (cmd.argument() == "ref")
1691 code = InsetBase::REF_CODE;
1692 else if (cmd.argument() == "toc")
1693 code = InsetBase::TOC_CODE;
1694 else if (cmd.argument() == "url")
1695 code = InsetBase::URL_CODE;
1696 else if (cmd.argument() == "vspace")
1697 code = InsetBase::VSPACE_CODE;
1698 else if (cmd.argument() == "wrap")
1699 code = InsetBase::WRAP_CODE;
1702 case LFUN_ERT_INSERT:
1703 code = InsetBase::ERT_CODE;
1705 case LFUN_FOOTNOTE_INSERT:
1706 code = InsetBase::FOOT_CODE;
1708 case LFUN_TABULAR_INSERT:
1709 code = InsetBase::TABULAR_CODE;
1711 case LFUN_MARGINALNOTE_INSERT:
1712 code = InsetBase::MARGIN_CODE;
1714 case LFUN_FLOAT_INSERT:
1715 case LFUN_FLOAT_WIDE_INSERT:
1716 code = InsetBase::FLOAT_CODE;
1718 case LFUN_WRAP_INSERT:
1719 code = InsetBase::WRAP_CODE;
1721 case LFUN_FLOAT_LIST:
1722 code = InsetBase::FLOAT_LIST_CODE;
1725 case LFUN_LIST_INSERT:
1726 code = InsetBase::LIST_CODE;
1728 case LFUN_THEOREM_INSERT:
1729 code = InsetBase::THEOREM_CODE;
1732 case LFUN_CAPTION_INSERT:
1733 code = InsetBase::CAPTION_CODE;
1735 case LFUN_NOTE_INSERT:
1736 code = InsetBase::NOTE_CODE;
1738 case LFUN_CHARSTYLE_INSERT:
1739 code = InsetBase::CHARSTYLE_CODE;
1740 if (cur.buffer().params().getLyXTextClass().charstyles().empty())
1743 case LFUN_BOX_INSERT:
1744 code = InsetBase::BOX_CODE;
1746 case LFUN_BRANCH_INSERT:
1747 code = InsetBase::BRANCH_CODE;
1748 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1751 case LFUN_LABEL_INSERT:
1752 code = InsetBase::LABEL_CODE;
1754 case LFUN_OPTIONAL_INSERT:
1755 code = InsetBase::OPTARG_CODE;
1756 enable = numberOfOptArgs(cur.paragraph())
1757 < cur.paragraph().layout()->optionalargs;
1759 case LFUN_ENVIRONMENT_INSERT:
1760 code = InsetBase::BOX_CODE;
1762 case LFUN_INDEX_INSERT:
1763 code = InsetBase::INDEX_CODE;
1765 case LFUN_INDEX_PRINT:
1766 code = InsetBase::INDEX_PRINT_CODE;
1768 case LFUN_NOMENCL_INSERT:
1769 code = InsetBase::NOMENCL_CODE;
1771 case LFUN_NOMENCL_PRINT:
1772 code = InsetBase::NOMENCL_PRINT_CODE;
1774 case LFUN_TOC_INSERT:
1775 code = InsetBase::TOC_CODE;
1777 case LFUN_HTML_INSERT:
1778 case LFUN_URL_INSERT:
1779 code = InsetBase::URL_CODE;
1781 case LFUN_QUOTE_INSERT:
1782 // always allow this, since we will inset a raw quote
1783 // if an inset is not allowed.
1785 case LFUN_HYPHENATION_POINT_INSERT:
1786 case LFUN_LIGATURE_BREAK_INSERT:
1787 case LFUN_HFILL_INSERT:
1788 case LFUN_MENU_SEPARATOR_INSERT:
1789 case LFUN_DOTS_INSERT:
1790 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
1791 code = InsetBase::SPECIALCHAR_CODE;
1793 case LFUN_SPACE_INSERT:
1794 // slight hack: we know this is allowed in math mode
1796 code = InsetBase::SPACE_CODE;
1799 case LFUN_INSET_MODIFY:
1800 // We need to disable this, because we may get called for a
1802 // InsetTabular::getStatus() -> InsetText::getStatus()
1803 // and we don't handle LFUN_INSET_MODIFY.
1807 case LFUN_FONT_EMPH:
1808 flag.setOnOff(font.emph() == LyXFont::ON);
1811 case LFUN_FONT_NOUN:
1812 flag.setOnOff(font.noun() == LyXFont::ON);
1815 case LFUN_FONT_BOLD:
1816 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
1819 case LFUN_FONT_SANS:
1820 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
1823 case LFUN_FONT_ROMAN:
1824 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
1827 case LFUN_FONT_CODE:
1828 flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
1833 enable = cur.selection();
1837 if (cmd.argument().empty()) {
1838 if (theClipboard().isInternal())
1839 enable = cap::numberOfSelections() > 0;
1841 enable = !theClipboard().empty();
1843 string const arg = to_utf8(cmd.argument());
1844 if (isStrUnsignedInt(arg)) {
1845 unsigned int n = convert<unsigned int>(arg);
1846 enable = cap::numberOfSelections() > n;
1853 case LFUN_CLIPBOARD_PASTE:
1854 enable = !theClipboard().empty();
1857 case LFUN_PRIMARY_SELECTION_PASTE:
1858 enable = cur.selection() || !theSelection().empty();
1861 case LFUN_PARAGRAPH_MOVE_UP:
1862 enable = cur.pit() > 0 && !cur.selection();
1865 case LFUN_PARAGRAPH_MOVE_DOWN:
1866 enable = cur.pit() < cur.lastpit() && !cur.selection();
1869 case LFUN_INSET_DISSOLVE:
1870 enable = !isMainText(*cur.bv().buffer()) && cur.inset().nargs() == 1;
1873 case LFUN_CHANGE_ACCEPT:
1874 case LFUN_CHANGE_REJECT:
1875 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
1876 // In principle, these LFUNs should only be enabled if there
1877 // is a change at the current position/in the current selection.
1878 // However, without proper optimizations, this will inevitably
1879 // result in unacceptable performance - just imagine a user who
1880 // wants to select the complete content of a long document.
1884 case LFUN_WORD_DELETE_FORWARD:
1885 case LFUN_WORD_DELETE_BACKWARD:
1886 case LFUN_LINE_DELETE:
1887 case LFUN_WORD_FORWARD:
1888 case LFUN_WORD_BACKWARD:
1889 case LFUN_CHAR_FORWARD:
1890 case LFUN_CHAR_FORWARD_SELECT:
1891 case LFUN_CHAR_BACKWARD:
1892 case LFUN_CHAR_BACKWARD_SELECT:
1894 case LFUN_UP_SELECT:
1896 case LFUN_DOWN_SELECT:
1897 case LFUN_PARAGRAPH_UP_SELECT:
1898 case LFUN_PARAGRAPH_DOWN_SELECT:
1899 case LFUN_SCREEN_UP_SELECT:
1900 case LFUN_SCREEN_DOWN_SELECT:
1901 case LFUN_LINE_BEGIN_SELECT:
1902 case LFUN_LINE_END_SELECT:
1903 case LFUN_WORD_FORWARD_SELECT:
1904 case LFUN_WORD_BACKWARD_SELECT:
1905 case LFUN_WORD_SELECT:
1906 case LFUN_PARAGRAPH_UP:
1907 case LFUN_PARAGRAPH_DOWN:
1908 case LFUN_SCREEN_UP:
1909 case LFUN_SCREEN_DOWN:
1910 case LFUN_LINE_BEGIN:
1912 case LFUN_BREAK_LINE:
1913 case LFUN_CHAR_DELETE_FORWARD:
1914 case LFUN_DELETE_FORWARD_SKIP:
1915 case LFUN_CHAR_DELETE_BACKWARD:
1916 case LFUN_DELETE_BACKWARD_SKIP:
1917 case LFUN_BREAK_PARAGRAPH:
1918 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
1919 case LFUN_BREAK_PARAGRAPH_SKIP:
1920 case LFUN_PARAGRAPH_SPACING:
1921 case LFUN_INSET_INSERT:
1922 case LFUN_WORD_UPCASE:
1923 case LFUN_WORD_LOWCASE:
1924 case LFUN_WORD_CAPITALIZE:
1925 case LFUN_CHARS_TRANSPOSE:
1926 case LFUN_SERVER_GET_XY:
1927 case LFUN_SERVER_SET_XY:
1928 case LFUN_SERVER_GET_FONT:
1929 case LFUN_SERVER_GET_LAYOUT:
1931 case LFUN_DATE_INSERT:
1932 case LFUN_SELF_INSERT:
1933 case LFUN_LINE_INSERT:
1934 case LFUN_PAGEBREAK_INSERT:
1935 case LFUN_CLEARPAGE_INSERT:
1936 case LFUN_CLEARDOUBLEPAGE_INSERT:
1937 case LFUN_MATH_DISPLAY:
1938 case LFUN_MATH_IMPORT_SELECTION:
1939 case LFUN_MATH_MODE:
1940 case LFUN_MATH_MACRO:
1941 case LFUN_MATH_MATRIX:
1942 case LFUN_MATH_DELIM:
1943 case LFUN_MATH_BIGDELIM:
1944 case LFUN_MATH_SUBSCRIPT:
1945 case LFUN_MATH_SUPERSCRIPT:
1946 case LFUN_FONT_DEFAULT:
1947 case LFUN_FONT_UNDERLINE:
1948 case LFUN_FONT_SIZE:
1950 case LFUN_FONT_FREE_APPLY:
1951 case LFUN_FONT_FREE_UPDATE:
1952 case LFUN_LAYOUT_PARAGRAPH:
1953 case LFUN_PARAGRAPH_UPDATE:
1954 case LFUN_ACCENT_UMLAUT:
1955 case LFUN_ACCENT_CIRCUMFLEX:
1956 case LFUN_ACCENT_GRAVE:
1957 case LFUN_ACCENT_ACUTE:
1958 case LFUN_ACCENT_TILDE:
1959 case LFUN_ACCENT_CEDILLA:
1960 case LFUN_ACCENT_MACRON:
1961 case LFUN_ACCENT_DOT:
1962 case LFUN_ACCENT_UNDERDOT:
1963 case LFUN_ACCENT_UNDERBAR:
1964 case LFUN_ACCENT_CARON:
1965 case LFUN_ACCENT_SPECIAL_CARON:
1966 case LFUN_ACCENT_BREVE:
1967 case LFUN_ACCENT_TIE:
1968 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1969 case LFUN_ACCENT_CIRCLE:
1970 case LFUN_ACCENT_OGONEK:
1971 case LFUN_THESAURUS_ENTRY:
1972 case LFUN_PARAGRAPH_PARAMS_APPLY:
1974 case LFUN_BUFFER_END:
1975 case LFUN_BUFFER_BEGIN:
1976 case LFUN_BUFFER_BEGIN_SELECT:
1977 case LFUN_BUFFER_END_SELECT:
1978 case LFUN_UNICODE_INSERT:
1979 // these are handled in our dispatch()
1987 if (code != InsetBase::NO_CODE
1988 && (cur.empty() || !cur.inset().insetAllowed(code)))
1991 flag.enabled(enable);
1996 void LyXText::pasteString(LCursor & cur, docstring const & clip,
1999 cur.clearSelection();
2000 if (!clip.empty()) {
2003 insertStringAsParagraphs(cur, clip);
2005 insertStringAsLines(cur, clip);