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::pasteSelection;
80 using cap::replaceSelection;
82 using support::isStrUnsignedInt;
87 using std::istringstream;
88 using std::ostringstream;
91 extern string current_layout;
97 LyXFont freefont(LyXFont::ALL_IGNORE);
98 bool toggleall = false;
101 void toggleAndShow(LCursor & cur, LyXText * text,
102 LyXFont const & font, bool toggleall = true)
104 text->toggleFree(cur, font, toggleall);
106 if (font.language() != ignore_language ||
107 font.number() != LyXFont::IGNORE) {
108 Paragraph & par = cur.paragraph();
109 text->bidi.computeTables(par, cur.buffer(), cur.textRow());
110 if (cur.boundary() !=
111 text->bidi.isBoundary(cur.buffer(), par,
113 text->real_current_font))
114 text->setCursor(cur, cur.pit(), cur.pos(),
115 false, !cur.boundary());
120 void moveCursor(LCursor & cur, bool selecting)
122 if (selecting || cur.mark())
124 theSelection().haveSelection(cur.selection());
125 cur.bv().switchKeyMap();
129 void finishChange(LCursor & cur, bool selecting)
132 moveCursor(cur, selecting);
136 void mathDispatch(LCursor & cur, FuncRequest const & cmd, bool display)
139 docstring sel = cur.selectionAsString(false);
140 //lyxerr << "selection is: '" << sel << "'" << endl;
142 // It may happen that sel is empty but there is a selection
143 replaceSelection(cur);
146 #ifdef ENABLE_ASSERTIONS
147 const int old_pos = cur.pos();
149 cur.insert(new InsetMathHull(hullSimple));
150 BOOST_ASSERT(old_pos == cur.pos());
151 cur.nextInset()->edit(cur, true);
152 // don't do that also for LFUN_MATH_MODE
153 // unless you want end up with always changing
154 // to mathrm when opening an inlined inset --
155 // I really hate "LyXfunc overloading"...
157 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
158 // Avoid an unnecessary undo step if cmd.argument
160 if (!cmd.argument().empty())
161 cur.dispatch(FuncRequest(LFUN_MATH_INSERT,
164 // create a macro if we see "\\newcommand"
165 // somewhere, and an ordinary formula
167 if (sel.find(from_ascii("\\newcommand")) == string::npos
168 && sel.find(from_ascii("\\def")) == string::npos)
170 InsetMathHull * formula = new InsetMathHull;
171 istringstream is(to_utf8(sel));
174 formula->read(cur.buffer(), lex);
175 if (formula->getType() == hullNone)
176 // Don't create pseudo formulas if
177 // delimiters are left out
178 formula->mutate(hullSimple);
181 cur.insert(new MathMacroTemplate(sel));
184 cur.message(from_utf8(N_("Math editor mode")));
193 string const freefont2string()
196 if (font2string(freefont, toggleall, data))
203 void LyXText::cursorPrevious(LCursor & cur)
205 pos_type cpos = cur.pos();
206 pit_type cpar = cur.pit();
208 int x = cur.x_target();
209 setCursorFromCoordinates(cur, x, 0);
210 cur.dispatch(FuncRequest(cur.selection()? LFUN_UP_SELECT: LFUN_UP));
212 if (cpar == cur.pit() && cpos == cur.pos())
213 // we have a row which is taller than the workarea. The
214 // simplest solution is to move to the previous row instead.
215 cur.dispatch(FuncRequest(cur.selection()? LFUN_UP_SELECT: LFUN_UP));
218 cur.updateFlags(Update::Force | Update::FitCursor);
222 void LyXText::cursorNext(LCursor & cur)
224 pos_type cpos = cur.pos();
225 pit_type cpar = cur.pit();
227 int x = cur.x_target();
228 setCursorFromCoordinates(cur, x, cur.bv().workHeight() - 1);
229 cur.dispatch(FuncRequest(cur.selection()? LFUN_DOWN_SELECT: LFUN_DOWN));
231 if (cpar == cur.pit() && cpos == cur.pos())
232 // we have a row which is taller than the workarea. The
233 // simplest solution is to move to the next row instead.
235 FuncRequest(cur.selection()? LFUN_DOWN_SELECT: LFUN_DOWN));
238 cur.updateFlags(Update::Force | Update::FitCursor);
244 void specialChar(LCursor & cur, InsetSpecialChar::Kind kind)
246 cap::replaceSelection(cur);
247 cur.insert(new InsetSpecialChar(kind));
252 bool doInsertInset(LCursor & cur, LyXText * text,
253 FuncRequest const & cmd, bool edit, bool pastesel)
255 InsetBase * inset = createInset(&cur.bv(), cmd);
261 if (cur.selection()) {
262 lyx::dispatch(FuncRequest(LFUN_CUT));
265 text->insertInset(cur, inset);
268 inset->edit(cur, true);
270 if (gotsel && pastesel) {
271 lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
272 // reset first par to default
273 if (cur.lastpit() != 0 || cur.lastpos() != 0) {
274 LyXLayout_ptr const layout =
275 cur.buffer().params().getLyXTextClass().defaultLayout();
276 cur.text()->paragraphs().begin()->layout(layout);
286 void LyXText::number(LCursor & cur)
288 LyXFont font(LyXFont::ALL_IGNORE);
289 font.setNumber(LyXFont::TOGGLE);
290 toggleAndShow(cur, this, font);
294 bool LyXText::isRTL(Buffer const & buffer, Paragraph const & par) const
296 return par.isRightToLeftPar(buffer.params());
300 void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
302 lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
304 // FIXME: We use the update flag to indicates wether a singlePar or a
305 // full screen update is needed. We reset it here but shall we restore it
309 BOOST_ASSERT(cur.text() == this);
310 BufferView * bv = &cur.bv();
311 CursorSlice oldTopSlice = cur.top();
312 bool oldBoundary = cur.boundary();
313 bool sel = cur.selection();
314 // Signals that, even if needsUpdate == false, an update of the
315 // cursor paragraph is required
316 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
317 LyXAction::SingleParUpdate);
318 // Signals that a full-screen update is required
319 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
320 LyXAction::NoUpdate) || singleParUpdate);
321 // Remember the old paragraph metric (_outer_ paragraph!)
322 ParagraphMetrics const & pm = cur.bv().parMetrics(
323 cur.bottom().text(), cur.bottom().pit());
324 Dimension olddim = pm.dim();
326 switch (cmd.action) {
328 case LFUN_PARAGRAPH_MOVE_DOWN: {
329 pit_type const pit = cur.pit();
330 recUndo(cur, pit, pit + 1);
332 std::swap(pars_[pit], pars_[pit + 1]);
334 ParIterator begin(cur);
336 ParIterator end = boost::next(ParIterator(cur));
337 updateLabels(cur.buffer(), begin, end);
343 case LFUN_PARAGRAPH_MOVE_UP: {
344 pit_type const pit = cur.pit();
345 recUndo(cur, pit - 1, pit);
347 std::swap(pars_[pit], pars_[pit - 1]);
349 ParIterator end = boost::next(ParIterator(cur));
351 ParIterator begin(cur);
352 updateLabels(cur.buffer(), begin, end);
358 case LFUN_APPENDIX: {
359 Paragraph & par = cur.paragraph();
360 bool start = !par.params().startOfAppendix();
363 #warning The code below only makes sense at top level.
364 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
366 // ensure that we have only one start_of_appendix in this document
367 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
368 if (pars_[tmp].params().startOfAppendix()) {
370 pars_[tmp].params().startOfAppendix(false);
376 par.params().startOfAppendix(start);
378 // we can set the refreshing parameters now
379 updateLabels(cur.buffer());
383 case LFUN_WORD_DELETE_FORWARD:
384 cur.clearSelection();
385 deleteWordForward(cur);
386 finishChange(cur, false);
389 case LFUN_WORD_DELETE_BACKWARD:
390 cur.clearSelection();
391 deleteWordBackward(cur);
392 finishChange(cur, false);
395 case LFUN_LINE_DELETE:
396 cur.clearSelection();
397 deleteLineForward(cur);
398 finishChange(cur, false);
401 case LFUN_BUFFER_BEGIN:
402 case LFUN_BUFFER_BEGIN_SELECT:
403 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
404 if (cur.depth() == 1) {
405 needsUpdate |= cursorTop(cur);
411 case LFUN_BUFFER_END:
412 case LFUN_BUFFER_END_SELECT:
413 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
414 if (cur.depth() == 1) {
415 needsUpdate |= cursorBottom(cur);
421 case LFUN_CHAR_FORWARD:
422 case LFUN_CHAR_FORWARD_SELECT:
423 //lyxerr << BOOST_CURRENT_FUNCTION
424 // << " LFUN_CHAR_FORWARD[SEL]:\n" << cur << endl;
425 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
426 if (isRTL(*cur.bv().buffer(), cur.paragraph()))
427 needsUpdate |= cursorLeft(cur);
429 needsUpdate |= cursorRight(cur);
431 if (!needsUpdate && oldTopSlice == cur.top()
432 && cur.boundary() == oldBoundary) {
434 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
438 case LFUN_CHAR_BACKWARD:
439 case LFUN_CHAR_BACKWARD_SELECT:
440 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
441 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
442 if (isRTL(*cur.bv().buffer(), cur.paragraph()))
443 needsUpdate |= cursorRight(cur);
445 needsUpdate |= cursorLeft(cur);
447 if (!needsUpdate && oldTopSlice == cur.top()
448 && cur.boundary() == oldBoundary) {
450 cmd = FuncRequest(LFUN_FINISHED_LEFT);
456 //lyxerr << "handle LFUN_UP[SEL]:\n" << cur << endl;
457 needsUpdate |= cur.selHandle(cmd.action == LFUN_UP_SELECT);
459 needsUpdate |= cursorUp(cur);
461 if (!needsUpdate && oldTopSlice == cur.top()
462 && cur.boundary() == oldBoundary) {
464 cmd = FuncRequest(LFUN_FINISHED_UP);
469 case LFUN_DOWN_SELECT:
470 //lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
471 needsUpdate |= cur.selHandle(cmd.action == LFUN_DOWN_SELECT);
472 needsUpdate |= cursorDown(cur);
474 if (!needsUpdate && oldTopSlice == cur.top() &&
475 cur.boundary() == oldBoundary)
478 cmd = FuncRequest(LFUN_FINISHED_DOWN);
482 case LFUN_PARAGRAPH_UP:
483 case LFUN_PARAGRAPH_UP_SELECT:
484 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
485 needsUpdate |= cursorUpParagraph(cur);
488 case LFUN_PARAGRAPH_DOWN:
489 case LFUN_PARAGRAPH_DOWN_SELECT:
490 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
491 needsUpdate |= cursorDownParagraph(cur);
495 case LFUN_SCREEN_UP_SELECT:
496 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_UP_SELECT);
497 if (cur.pit() == 0 && cur.textRow().pos() == 0) {
499 cmd = FuncRequest(LFUN_FINISHED_UP);
505 case LFUN_SCREEN_DOWN:
506 case LFUN_SCREEN_DOWN_SELECT:
507 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_DOWN_SELECT);
508 if (cur.pit() == cur.lastpit()
509 && cur.textRow().endpos() == cur.lastpos()) {
511 cmd = FuncRequest(LFUN_FINISHED_DOWN);
517 case LFUN_LINE_BEGIN:
518 case LFUN_LINE_BEGIN_SELECT:
519 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
520 needsUpdate |= cursorHome(cur);
524 case LFUN_LINE_END_SELECT:
525 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
526 needsUpdate |= cursorEnd(cur);
529 case LFUN_WORD_FORWARD:
530 case LFUN_WORD_FORWARD_SELECT:
531 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
532 if (isRTL(*cur.bv().buffer(), cur.paragraph()))
533 needsUpdate |= cursorLeftOneWord(cur);
535 needsUpdate |= cursorRightOneWord(cur);
538 case LFUN_WORD_BACKWARD:
539 case LFUN_WORD_BACKWARD_SELECT:
540 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
541 if (isRTL(*cur.bv().buffer(), cur.paragraph()))
542 needsUpdate |= cursorRightOneWord(cur);
544 needsUpdate |= cursorLeftOneWord(cur);
547 case LFUN_WORD_SELECT: {
548 selectWord(cur, WHOLE_WORD);
549 finishChange(cur, true);
553 case LFUN_BREAK_LINE: {
554 // Not allowed by LaTeX (labels or empty par)
555 if (cur.pos() > cur.paragraph().beginOfBody()) {
556 cap::replaceSelection(cur);
557 cur.insert(new InsetNewline);
559 moveCursor(cur, false);
564 case LFUN_CHAR_DELETE_FORWARD:
565 if (!cur.selection()) {
566 if (cur.pos() == cur.paragraph().size())
567 // Par boundary, force full-screen update
568 singleParUpdate = false;
569 needsUpdate |= erase(cur);
571 // It is possible to make it a lot faster still
572 // just comment out the line below...
574 cutSelection(cur, true, false);
575 singleParUpdate = false;
577 moveCursor(cur, false);
580 case LFUN_DELETE_FORWARD_SKIP:
581 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
582 if (!cur.selection()) {
583 if (cur.pos() == cur.lastpos()) {
590 cutSelection(cur, true, false);
595 case LFUN_CHAR_DELETE_BACKWARD:
596 if (!cur.selection()) {
597 if (bv->getIntl().getTransManager().backspace()) {
598 // Par boundary, full-screen update
600 singleParUpdate = false;
601 needsUpdate |= backspace(cur);
603 // It is possible to make it a lot faster still
604 // just comment out the line below...
607 cutSelection(cur, true, false);
608 singleParUpdate = false;
613 case LFUN_DELETE_BACKWARD_SKIP:
614 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
615 if (!cur.selection()) {
619 //CursorSlice cur = cursor();
623 cutSelection(cur, true, false);
627 case LFUN_BREAK_PARAGRAPH:
628 cap::replaceSelection(cur);
629 breakParagraph(cur, 0);
634 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
635 cap::replaceSelection(cur);
636 breakParagraph(cur, 1);
641 case LFUN_BREAK_PARAGRAPH_SKIP: {
642 // When at the beginning of a paragraph, remove
643 // indentation. Otherwise, do the same as LFUN_BREAK_PARAGRAPH.
644 cap::replaceSelection(cur);
646 cur.paragraph().params().labelWidthString(docstring());
648 breakParagraph(cur, 0);
654 case LFUN_PARAGRAPH_SPACING: {
655 Paragraph & par = cur.paragraph();
656 Spacing::Space cur_spacing = par.params().spacing().getSpace();
657 string cur_value = "1.0";
658 if (cur_spacing == Spacing::Other)
659 cur_value = par.params().spacing().getValueAsString();
661 istringstream is(to_utf8(cmd.argument()));
664 Spacing::Space new_spacing = cur_spacing;
665 string new_value = cur_value;
667 lyxerr << "Missing argument to `paragraph-spacing'"
669 } else if (tmp == "single") {
670 new_spacing = Spacing::Single;
671 } else if (tmp == "onehalf") {
672 new_spacing = Spacing::Onehalf;
673 } else if (tmp == "double") {
674 new_spacing = Spacing::Double;
675 } else if (tmp == "other") {
676 new_spacing = Spacing::Other;
677 string tmpval = "0.0";
679 lyxerr << "new_value = " << tmpval << endl;
682 } else if (tmp == "default") {
683 new_spacing = Spacing::Default;
685 lyxerr << to_utf8(_("Unknown spacing argument: "))
686 << to_utf8(cmd.argument()) << endl;
688 if (cur_spacing != new_spacing || cur_value != new_value)
689 par.params().spacing(Spacing(new_spacing, new_value));
693 case LFUN_INSET_INSERT: {
695 InsetBase * inset = createInset(bv, cmd);
697 insertInset(cur, inset);
703 case LFUN_INSET_DISSOLVE:
704 needsUpdate |= dissolveInset(cur);
707 case LFUN_INSET_SETTINGS:
708 cur.inset().showInsetDialog(bv);
711 case LFUN_SPACE_INSERT:
712 if (cur.paragraph().layout()->free_spacing)
713 insertChar(cur, ' ');
715 doInsertInset(cur, this, cmd, false, false);
718 moveCursor(cur, false);
721 case LFUN_HYPHENATION_POINT_INSERT:
722 specialChar(cur, InsetSpecialChar::HYPHENATION);
725 case LFUN_LIGATURE_BREAK_INSERT:
726 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
729 case LFUN_DOTS_INSERT:
730 specialChar(cur, InsetSpecialChar::LDOTS);
733 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
734 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
737 case LFUN_MENU_SEPARATOR_INSERT:
738 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
741 case LFUN_WORD_UPCASE:
742 changeCase(cur, LyXText::text_uppercase);
745 case LFUN_WORD_LOWCASE:
746 changeCase(cur, LyXText::text_lowercase);
749 case LFUN_WORD_CAPITALIZE:
750 changeCase(cur, LyXText::text_capitalization);
753 case LFUN_CHARS_TRANSPOSE:
758 cur.message(_("Paste"));
759 cap::replaceSelection(cur);
760 if (cmd.argument().empty() && !theClipboard().isInternal())
761 pasteString(cur, theClipboard().get(), true);
763 string const arg(to_utf8(cmd.argument()));
764 pasteSelection(cur, bv->buffer()->errorList("Paste"),
765 isStrUnsignedInt(arg) ?
766 convert<unsigned int>(arg) :
768 bv->buffer()->errors("Paste");
770 cur.clearSelection(); // bug 393
776 cutSelection(cur, true, true);
777 cur.message(_("Cut"));
782 cur.message(_("Copy"));
785 case LFUN_SERVER_GET_XY:
786 cur.message(from_utf8(
787 convert<string>(cursorX(cur.bv(), cur.top(), cur.boundary()))
788 + ' ' + convert<string>(cursorY(cur.bv(), cur.top(), cur.boundary()))));
791 case LFUN_SERVER_SET_XY: {
794 istringstream is(to_utf8(cmd.argument()));
797 lyxerr << "SETXY: Could not parse coordinates in '"
798 << to_utf8(cmd.argument()) << std::endl;
800 setCursorFromCoordinates(cur, x, y);
804 case LFUN_SERVER_GET_FONT:
805 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
806 cur.message(from_ascii("E"));
807 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
808 cur.message(from_ascii("N"));
810 cur.message(from_ascii("0"));
813 case LFUN_SERVER_GET_LAYOUT:
814 cur.message(from_utf8(cur.paragraph().layout()->name()));
818 string layout = to_ascii(cmd.argument());
819 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) " << layout << endl;
821 // Derive layout number from given argument (string)
822 // and current buffer's textclass (number)
823 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
825 layout = tclass.defaultLayoutName();
826 bool hasLayout = tclass.hasLayout(layout);
828 // If the entry is obsolete, use the new one instead.
830 string const & obs = tclass[layout]->obsoleted_by();
836 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
837 from_utf8(N_(" not known")));
841 bool change_layout = (current_layout != layout);
843 if (!change_layout && cur.selection() &&
844 cur.selBegin().pit() != cur.selEnd().pit())
846 pit_type spit = cur.selBegin().pit();
847 pit_type epit = cur.selEnd().pit() + 1;
848 while (spit != epit) {
849 if (pars_[spit].layout()->name() != current_layout) {
850 change_layout = true;
858 current_layout = layout;
859 setLayout(cur, layout);
860 // inform the GUI that the layout has changed.
861 bv->layoutChanged(layout);
867 case LFUN_CLIPBOARD_PASTE:
868 pasteString(cur, theClipboard().get(),
869 cmd.argument() == "paragraph");
872 case LFUN_PRIMARY_SELECTION_PASTE:
873 pasteString(cur, theSelection().get(),
874 cmd.argument() == "paragraph");
877 case LFUN_UNICODE_INSERT: {
878 if (cmd.argument().empty())
880 docstring hexstring = cmd.argument();
881 if (lyx::support::isHex(hexstring)) {
882 char_type c = lyx::support::hexToInt(hexstring);
883 if (c > 32 && c < 0x10ffff) {
884 lyxerr << "Inserting c: " << c << endl;
885 docstring s = docstring(1, c);
886 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
892 case LFUN_QUOTE_INSERT: {
893 cap::replaceSelection(cur);
894 Paragraph & par = cur.paragraph();
895 pos_type pos = cur.pos();
899 else if (cur.prevInset() && cur.prevInset()->isSpace())
902 c = par.getChar(pos - 1);
904 LyXLayout_ptr const & style = par.layout();
906 BufferParams const & bufparams = bv->buffer()->params();
907 if (!style->pass_thru
908 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
909 string arg = to_utf8(cmd.argument());
911 cur.insert(new InsetQuotes(c,
912 bufparams.quotes_language,
913 InsetQuotes::SingleQ));
915 cur.insert(new InsetQuotes(c,
916 bufparams.quotes_language,
917 InsetQuotes::DoubleQ));
921 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
925 case LFUN_DATE_INSERT:
926 if (cmd.argument().empty())
927 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
928 formatted_time(current_time())));
930 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
931 formatted_time(current_time(), to_utf8(cmd.argument()))));
934 case LFUN_MOUSE_TRIPLE:
935 if (cmd.button() == mouse_button::button1) {
941 theSelection().haveSelection(cur.selection());
945 case LFUN_MOUSE_DOUBLE:
946 if (cmd.button() == mouse_button::button1) {
947 selectWord(cur, WHOLE_WORD_STRICT);
949 theSelection().haveSelection(cur.selection());
953 // Single-click on work area
954 case LFUN_MOUSE_PRESS: {
955 // Right click on a footnote flag opens float menu
956 if (cmd.button() == mouse_button::button3)
957 cur.clearSelection();
959 // Middle button press pastes if we have a selection
960 // We do this here as if the selection was inside an inset
961 // it could get cleared on the unlocking of the inset so
962 // we have to check this first
963 bool paste_internally = false;
964 if (cmd.button() == mouse_button::button2 && cur.selection()) {
965 // Copy the selection to the clipboard stack. This
966 // is done for two reasons:
967 // - We want it to appear in the "Edit->Paste recent"
969 // - We can then use the normal copy/paste machinery
970 // instead of theSelection().get() to preserve
971 // formatting of the pasted stuff.
972 cap::copySelectionToStack(cur.bv().cursor());
973 paste_internally = true;
976 // we have to update after dePM triggered
977 bool update = bv->mouseSetCursor(cur);
979 // Insert primary selection with middle mouse
980 // if there is a local selection in the current buffer,
982 if (cmd.button() == mouse_button::button2) {
983 if (paste_internally)
984 lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
986 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
989 if (!update && cmd.button() == mouse_button::button1) {
997 case LFUN_MOUSE_MOTION: {
998 // Only use motion with button 1
999 //if (cmd.button() != mouse_button::button1)
1002 // ignore motions deeper nested than the real anchor
1003 LCursor & bvcur = cur.bv().cursor();
1004 if (bvcur.anchor_.hasPart(cur)) {
1005 CursorSlice old = bvcur.top();
1007 int const wh = bv->workHeight();
1008 int const y = std::max(0, std::min(wh - 1, cmd.y));
1010 setCursorFromCoordinates(cur, cmd.x, y);
1011 cur.x_target() = cmd.x;
1013 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1015 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1016 // This is to allow jumping over large insets
1017 if (cur.top() == old) {
1019 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1021 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1024 if (cur.top() == old)
1027 // don't set anchor_
1028 bvcur.setCursor(cur);
1029 bvcur.selection() = true;
1030 //lyxerr << "MOTION: " << bv->cursor() << endl;
1038 case LFUN_MOUSE_RELEASE: {
1039 if (cmd.button() == mouse_button::button2)
1043 if (cmd.button() == mouse_button::button1) {
1044 if (cur.selection())
1045 theSelection().haveSelection(true);
1046 needsUpdate = false;
1054 case LFUN_SELF_INSERT: {
1055 if (cmd.argument().empty())
1058 // Automatically delete the currently selected
1059 // text and replace it with what is being
1060 // typed in now. Depends on lyxrc settings
1061 // "auto_region_delete", which defaults to
1064 if (lyxrc.auto_region_delete) {
1065 if (cur.selection())
1066 cutSelection(cur, false, false);
1067 // cutSelection clears the X selection.
1069 theSelection().haveSelection(false);
1072 cur.clearSelection();
1073 LyXFont const old_font = real_current_font;
1075 docstring::const_iterator cit = cmd.argument().begin();
1076 docstring::const_iterator end = cmd.argument().end();
1077 for (; cit != end; ++cit)
1079 bv->getIntl().getTransManager().
1080 translateAndInsert(*cit, this);
1082 insertChar(bv->cursor(), *cit);
1086 moveCursor(cur, false);
1090 case LFUN_URL_INSERT: {
1091 InsetCommandParams p("url");
1092 string const data = InsetCommandMailer::params2string("url", p);
1093 bv->showInsetDialog("url", data, 0);
1097 case LFUN_HTML_INSERT: {
1098 InsetCommandParams p("htmlurl");
1099 string const data = InsetCommandMailer::params2string("url", p);
1100 bv->showInsetDialog("url", data, 0);
1104 case LFUN_LABEL_INSERT: {
1105 InsetCommandParams p("label");
1106 // Try to generate a valid label
1107 p["name"] = (cmd.argument().empty()) ?
1108 cur.getPossibleLabel() :
1110 string const data = InsetCommandMailer::params2string("label", p);
1112 if (cmd.argument().empty()) {
1113 bv->showInsetDialog("label", data, 0);
1115 FuncRequest fr(LFUN_INSET_INSERT, data);
1123 case LFUN_LIST_INSERT:
1124 case LFUN_THEOREM_INSERT:
1125 case LFUN_CAPTION_INSERT:
1127 case LFUN_NOTE_INSERT:
1128 case LFUN_CHARSTYLE_INSERT:
1129 case LFUN_BOX_INSERT:
1130 case LFUN_BRANCH_INSERT:
1131 case LFUN_BIBITEM_INSERT:
1132 case LFUN_ERT_INSERT:
1133 case LFUN_FOOTNOTE_INSERT:
1134 case LFUN_MARGINALNOTE_INSERT:
1135 case LFUN_OPTIONAL_INSERT:
1136 case LFUN_ENVIRONMENT_INSERT:
1137 // Open the inset, and move the current selection
1139 doInsertInset(cur, this, cmd, true, true);
1143 case LFUN_TABULAR_INSERT:
1144 // if there were no arguments, just open the dialog
1145 if (doInsertInset(cur, this, cmd, false, true))
1148 bv->showDialog("tabularcreate");
1152 case LFUN_FLOAT_INSERT:
1153 case LFUN_FLOAT_WIDE_INSERT:
1154 case LFUN_WRAP_INSERT:
1155 doInsertInset(cur, this, cmd, true, true);
1157 // FIXME: the "Caption" name should not be hardcoded,
1158 // but given by the float definition.
1159 cur.dispatch(FuncRequest(LFUN_LAYOUT, "Caption"));
1162 case LFUN_INDEX_INSERT:
1163 case LFUN_NOMENCL_INSERT: {
1164 InsetBase * inset = createInset(&cur.bv(), cmd);
1169 cur.clearSelection();
1170 insertInset(cur, inset);
1171 inset->edit(cur, true);
1172 // Show the dialog for the nomenclature entry, since the
1173 // description entry still needs to be filled in.
1174 if (cmd.action == LFUN_NOMENCL_INSERT)
1175 InsetCommandMailer("nomenclature",
1176 *reinterpret_cast<InsetCommand *>(inset)).showDialog(&cur.bv());
1181 case LFUN_INDEX_PRINT:
1182 case LFUN_NOMENCL_PRINT:
1183 case LFUN_TOC_INSERT:
1184 case LFUN_HFILL_INSERT:
1185 case LFUN_LINE_INSERT:
1186 case LFUN_PAGEBREAK_INSERT:
1187 case LFUN_CLEARPAGE_INSERT:
1188 case LFUN_CLEARDOUBLEPAGE_INSERT:
1190 doInsertInset(cur, this, cmd, false, false);
1194 case LFUN_DEPTH_DECREMENT:
1195 changeDepth(cur, DEC_DEPTH);
1198 case LFUN_DEPTH_INCREMENT:
1199 changeDepth(cur, INC_DEPTH);
1202 case LFUN_MATH_DISPLAY:
1203 mathDispatch(cur, cmd, true);
1206 case LFUN_MATH_IMPORT_SELECTION:
1207 case LFUN_MATH_MODE:
1208 if (cmd.argument() == "on")
1209 // don't pass "on" as argument
1210 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1212 mathDispatch(cur, cmd, false);
1215 case LFUN_MATH_MACRO:
1216 if (cmd.argument().empty())
1217 cur.errorMessage(from_utf8(N_("Missing argument")));
1219 string s = to_utf8(cmd.argument());
1220 string const s1 = token(s, ' ', 1);
1221 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1222 string const s2 = token(s, ' ', 2);
1223 string const type = s2.empty() ? "newcommand" : s2;
1224 cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, from_utf8(type)));
1225 //cur.nextInset()->edit(cur, true);
1229 // passthrough hat and underscore outside mathed:
1230 case LFUN_MATH_SUBSCRIPT:
1231 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1233 case LFUN_MATH_SUPERSCRIPT:
1234 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1237 case LFUN_MATH_INSERT:
1238 case LFUN_MATH_MATRIX:
1239 case LFUN_MATH_DELIM:
1240 case LFUN_MATH_BIGDELIM: {
1241 cur.insert(new InsetMathHull(hullSimple));
1242 cur.dispatch(FuncRequest(LFUN_CHAR_FORWARD));
1247 case LFUN_FONT_EMPH: {
1248 LyXFont font(LyXFont::ALL_IGNORE);
1249 font.setEmph(LyXFont::TOGGLE);
1250 toggleAndShow(cur, this, font);
1254 case LFUN_FONT_BOLD: {
1255 LyXFont font(LyXFont::ALL_IGNORE);
1256 font.setSeries(LyXFont::BOLD_SERIES);
1257 toggleAndShow(cur, this, font);
1261 case LFUN_FONT_NOUN: {
1262 LyXFont font(LyXFont::ALL_IGNORE);
1263 font.setNoun(LyXFont::TOGGLE);
1264 toggleAndShow(cur, this, font);
1268 case LFUN_FONT_CODE: {
1269 LyXFont font(LyXFont::ALL_IGNORE);
1270 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1271 toggleAndShow(cur, this, font);
1275 case LFUN_FONT_SANS: {
1276 LyXFont font(LyXFont::ALL_IGNORE);
1277 font.setFamily(LyXFont::SANS_FAMILY);
1278 toggleAndShow(cur, this, font);
1282 case LFUN_FONT_ROMAN: {
1283 LyXFont font(LyXFont::ALL_IGNORE);
1284 font.setFamily(LyXFont::ROMAN_FAMILY);
1285 toggleAndShow(cur, this, font);
1289 case LFUN_FONT_DEFAULT: {
1290 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1291 toggleAndShow(cur, this, font);
1295 case LFUN_FONT_UNDERLINE: {
1296 LyXFont font(LyXFont::ALL_IGNORE);
1297 font.setUnderbar(LyXFont::TOGGLE);
1298 toggleAndShow(cur, this, font);
1302 case LFUN_FONT_SIZE: {
1303 LyXFont font(LyXFont::ALL_IGNORE);
1304 font.setLyXSize(to_utf8(cmd.argument()));
1305 toggleAndShow(cur, this, font);
1309 case LFUN_LANGUAGE: {
1310 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1313 LyXFont font(LyXFont::ALL_IGNORE);
1314 font.setLanguage(lang);
1315 toggleAndShow(cur, this, font);
1320 case LFUN_FONT_FREE_APPLY:
1321 toggleAndShow(cur, this, freefont, toggleall);
1322 cur.message(_("Character set"));
1325 // Set the freefont using the contents of \param data dispatched from
1326 // the frontends and apply it at the current cursor location.
1327 case LFUN_FONT_FREE_UPDATE: {
1330 if (bv_funcs::string2font(to_utf8(cmd.argument()), font, toggle)) {
1333 toggleAndShow(cur, this, freefont, toggleall);
1334 cur.message(_("Character set"));
1339 case LFUN_FINISHED_LEFT:
1340 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1343 case LFUN_FINISHED_RIGHT:
1344 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1348 case LFUN_FINISHED_UP:
1349 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_UP:\n" << cur << endl;
1353 case LFUN_FINISHED_DOWN:
1354 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_DOWN:\n" << cur << endl;
1358 case LFUN_LAYOUT_PARAGRAPH: {
1360 params2string(cur.paragraph(), data);
1361 data = "show\n" + data;
1362 bv->showDialogWithData("paragraph", data);
1366 case LFUN_PARAGRAPH_UPDATE: {
1368 params2string(cur.paragraph(), data);
1370 // Will the paragraph accept changes from the dialog?
1371 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1373 data = "update " + convert<string>(accept) + '\n' + data;
1374 bv->updateDialog("paragraph", data);
1378 case LFUN_ACCENT_UMLAUT:
1379 case LFUN_ACCENT_CIRCUMFLEX:
1380 case LFUN_ACCENT_GRAVE:
1381 case LFUN_ACCENT_ACUTE:
1382 case LFUN_ACCENT_TILDE:
1383 case LFUN_ACCENT_CEDILLA:
1384 case LFUN_ACCENT_MACRON:
1385 case LFUN_ACCENT_DOT:
1386 case LFUN_ACCENT_UNDERDOT:
1387 case LFUN_ACCENT_UNDERBAR:
1388 case LFUN_ACCENT_CARON:
1389 case LFUN_ACCENT_SPECIAL_CARON:
1390 case LFUN_ACCENT_BREVE:
1391 case LFUN_ACCENT_TIE:
1392 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1393 case LFUN_ACCENT_CIRCLE:
1394 case LFUN_ACCENT_OGONEK:
1395 theLyXFunc().handleKeyFunc(cmd.action);
1396 if (!cmd.argument().empty())
1397 // FIXME: Are all these characters encoded in one byte in utf8?
1398 bv->getIntl().getTransManager()
1399 .translateAndInsert(cmd.argument()[0], this, cur);
1402 case LFUN_FLOAT_LIST: {
1403 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1404 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1405 // not quite sure if we want this...
1407 cur.clearSelection();
1408 breakParagraph(cur);
1410 if (cur.lastpos() != 0) {
1412 breakParagraph(cur);
1415 setLayout(cur, tclass.defaultLayoutName());
1416 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, docstring(), 0);
1417 insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1420 lyxerr << "Non-existent float type: "
1421 << to_utf8(cmd.argument()) << endl;
1426 case LFUN_CHANGE_ACCEPT: {
1431 case LFUN_CHANGE_REJECT: {
1436 case LFUN_THESAURUS_ENTRY: {
1437 docstring arg = cmd.argument();
1439 arg = cur.selectionAsString(false);
1441 if (arg.size() > 100 || arg.empty()) {
1442 // Get word or selection
1443 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1444 arg = cur.selectionAsString(false);
1447 bv->showDialogWithData("thesaurus", to_utf8(arg));
1451 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1452 // Given data, an encoding of the ParagraphParameters
1453 // generated in the Paragraph dialog, this function sets
1454 // the current paragraph appropriately.
1455 istringstream is(to_utf8(cmd.argument()));
1458 ParagraphParameters params;
1463 params.labelWidthString(),
1465 cur.message(_("Paragraph layout set"));
1470 if (cur.selection()) {
1471 cur.selection() = false;
1474 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1479 lyxerr[Debug::ACTION]
1480 << BOOST_CURRENT_FUNCTION
1481 << ": Command " << cmd
1482 << " not DISPATCHED by LyXText" << endl;
1487 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1489 // FIXME: The cursor flag is reset two lines below
1490 // so we need to check here if some of the LFUN did touch that.
1491 // for now only LyXText::erase() and LyXText::backspace() do that.
1492 // The plan is to verify all the LFUNs and then to remove this
1493 // singleParUpdate boolean altogether.
1494 if (cur.result().update() & Update::Force) {
1495 singleParUpdate = false;
1499 // FIXME: the following code should go in favor of fine grained
1500 // update flag treatment.
1501 if (singleParUpdate) {
1502 // Inserting characters does not change par height
1503 ParagraphMetrics const & pms
1504 = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
1505 if (pms.dim().height()
1506 == olddim.height()) {
1507 // if so, update _only_ this paragraph
1508 cur.updateFlags(Update::SinglePar |
1510 Update::MultiParSel);
1517 && &oldTopSlice.inset() == &cur.inset()
1518 && oldTopSlice.idx() == cur.idx()
1519 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1520 && !cur.selection())
1521 // FIXME: it would be better if we could just do this
1523 //if (cur.result().update() != Update::FitCursor)
1526 // But some LFUNs do not set Update::FitCursor when needed, so we
1527 // do it for all. This is not very harmfull as FitCursor will provoke
1528 // a full redraw only if needed but still, a proper review of all LFUN
1529 // should be done and this needsUpdate boolean can then be removed.
1530 cur.updateFlags(Update::FitCursor);
1532 cur.updateFlags(Update::Force | Update::FitCursor);
1536 bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
1537 FuncStatus & flag) const
1539 BOOST_ASSERT(cur.text() == this);
1541 LyXFont const & font = real_current_font;
1543 InsetBase::Code code = InsetBase::NO_CODE;
1545 switch (cmd.action) {
1547 case LFUN_DEPTH_DECREMENT:
1548 enable = changeDepthAllowed(cur, DEC_DEPTH);
1551 case LFUN_DEPTH_INCREMENT:
1552 enable = changeDepthAllowed(cur, INC_DEPTH);
1556 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1559 case LFUN_BIBITEM_INSERT:
1560 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO);
1563 case LFUN_DIALOG_SHOW_NEW_INSET:
1564 if (cmd.argument() == "bibitem")
1565 code = InsetBase::BIBITEM_CODE;
1566 else if (cmd.argument() == "bibtex")
1567 code = InsetBase::BIBTEX_CODE;
1568 else if (cmd.argument() == "box")
1569 code = InsetBase::BOX_CODE;
1570 else if (cmd.argument() == "branch")
1571 code = InsetBase::BRANCH_CODE;
1572 else if (cmd.argument() == "citation")
1573 code = InsetBase::CITE_CODE;
1574 else if (cmd.argument() == "ert")
1575 code = InsetBase::ERT_CODE;
1576 else if (cmd.argument() == "external")
1577 code = InsetBase::EXTERNAL_CODE;
1578 else if (cmd.argument() == "float")
1579 code = InsetBase::FLOAT_CODE;
1580 else if (cmd.argument() == "graphics")
1581 code = InsetBase::GRAPHICS_CODE;
1582 else if (cmd.argument() == "include")
1583 code = InsetBase::INCLUDE_CODE;
1584 else if (cmd.argument() == "index")
1585 code = InsetBase::INDEX_CODE;
1586 else if (cmd.argument() == "nomenclature")
1587 code = InsetBase::NOMENCL_CODE;
1588 else if (cmd.argument() == "label")
1589 code = InsetBase::LABEL_CODE;
1590 else if (cmd.argument() == "note")
1591 code = InsetBase::NOTE_CODE;
1592 else if (cmd.argument() == "ref")
1593 code = InsetBase::REF_CODE;
1594 else if (cmd.argument() == "toc")
1595 code = InsetBase::TOC_CODE;
1596 else if (cmd.argument() == "url")
1597 code = InsetBase::URL_CODE;
1598 else if (cmd.argument() == "vspace")
1599 code = InsetBase::VSPACE_CODE;
1600 else if (cmd.argument() == "wrap")
1601 code = InsetBase::WRAP_CODE;
1604 case LFUN_ERT_INSERT:
1605 code = InsetBase::ERT_CODE;
1607 case LFUN_FOOTNOTE_INSERT:
1608 code = InsetBase::FOOT_CODE;
1610 case LFUN_TABULAR_INSERT:
1611 code = InsetBase::TABULAR_CODE;
1613 case LFUN_MARGINALNOTE_INSERT:
1614 code = InsetBase::MARGIN_CODE;
1616 case LFUN_FLOAT_INSERT:
1617 case LFUN_FLOAT_WIDE_INSERT:
1618 code = InsetBase::FLOAT_CODE;
1620 case LFUN_WRAP_INSERT:
1621 code = InsetBase::WRAP_CODE;
1623 case LFUN_FLOAT_LIST:
1624 code = InsetBase::FLOAT_LIST_CODE;
1627 case LFUN_LIST_INSERT:
1628 code = InsetBase::LIST_CODE;
1630 case LFUN_THEOREM_INSERT:
1631 code = InsetBase::THEOREM_CODE;
1634 case LFUN_CAPTION_INSERT:
1635 code = InsetBase::CAPTION_CODE;
1637 case LFUN_NOTE_INSERT:
1638 code = InsetBase::NOTE_CODE;
1640 case LFUN_CHARSTYLE_INSERT:
1641 code = InsetBase::CHARSTYLE_CODE;
1642 if (cur.buffer().params().getLyXTextClass().charstyles().empty())
1645 case LFUN_BOX_INSERT:
1646 code = InsetBase::BOX_CODE;
1648 case LFUN_BRANCH_INSERT:
1649 code = InsetBase::BRANCH_CODE;
1650 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1653 case LFUN_LABEL_INSERT:
1654 code = InsetBase::LABEL_CODE;
1656 case LFUN_OPTIONAL_INSERT:
1657 code = InsetBase::OPTARG_CODE;
1658 enable = numberOfOptArgs(cur.paragraph())
1659 < cur.paragraph().layout()->optionalargs;
1661 case LFUN_ENVIRONMENT_INSERT:
1662 code = InsetBase::BOX_CODE;
1664 case LFUN_INDEX_INSERT:
1665 code = InsetBase::INDEX_CODE;
1667 case LFUN_INDEX_PRINT:
1668 code = InsetBase::INDEX_PRINT_CODE;
1670 case LFUN_NOMENCL_INSERT:
1671 code = InsetBase::NOMENCL_CODE;
1673 case LFUN_NOMENCL_PRINT:
1674 code = InsetBase::NOMENCL_PRINT_CODE;
1676 case LFUN_TOC_INSERT:
1677 code = InsetBase::TOC_CODE;
1679 case LFUN_HTML_INSERT:
1680 case LFUN_URL_INSERT:
1681 code = InsetBase::URL_CODE;
1683 case LFUN_QUOTE_INSERT:
1684 // always allow this, since we will inset a raw quote
1685 // if an inset is not allowed.
1687 case LFUN_HYPHENATION_POINT_INSERT:
1688 case LFUN_LIGATURE_BREAK_INSERT:
1689 case LFUN_HFILL_INSERT:
1690 case LFUN_MENU_SEPARATOR_INSERT:
1691 case LFUN_DOTS_INSERT:
1692 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
1693 code = InsetBase::SPECIALCHAR_CODE;
1695 case LFUN_SPACE_INSERT:
1696 // slight hack: we know this is allowed in math mode
1698 code = InsetBase::SPACE_CODE;
1701 case LFUN_INSET_MODIFY:
1702 // We need to disable this, because we may get called for a
1704 // InsetTabular::getStatus() -> InsetText::getStatus()
1705 // and we don't handle LFUN_INSET_MODIFY.
1709 case LFUN_FONT_EMPH:
1710 flag.setOnOff(font.emph() == LyXFont::ON);
1713 case LFUN_FONT_NOUN:
1714 flag.setOnOff(font.noun() == LyXFont::ON);
1717 case LFUN_FONT_BOLD:
1718 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
1721 case LFUN_FONT_SANS:
1722 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
1725 case LFUN_FONT_ROMAN:
1726 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
1729 case LFUN_FONT_CODE:
1730 flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
1735 enable = cur.selection();
1739 if (cmd.argument().empty()) {
1740 if (theClipboard().isInternal())
1741 enable = cap::numberOfSelections() > 0;
1743 enable = !theClipboard().empty();
1745 string const arg = to_utf8(cmd.argument());
1746 if (isStrUnsignedInt(arg)) {
1747 unsigned int n = convert<unsigned int>(arg);
1748 enable = cap::numberOfSelections() > n;
1755 case LFUN_CLIPBOARD_PASTE:
1756 enable = !theClipboard().empty();
1759 case LFUN_PRIMARY_SELECTION_PASTE:
1760 enable = cur.selection() || !theSelection().empty();
1763 case LFUN_PARAGRAPH_MOVE_UP:
1764 enable = cur.pit() > 0 && !cur.selection();
1767 case LFUN_PARAGRAPH_MOVE_DOWN:
1768 enable = cur.pit() < cur.lastpit() && !cur.selection();
1771 case LFUN_INSET_DISSOLVE:
1772 enable = !isMainText(*cur.bv().buffer()) && cur.inset().nargs() == 1;
1775 case LFUN_CHANGE_ACCEPT:
1776 case LFUN_CHANGE_REJECT:
1777 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
1778 // In principle, these LFUNs should only be enabled if there
1779 // is a change at the current position/in the current selection.
1780 // However, without proper optimizations, this will inevitably
1781 // result in unacceptable performance - just imagine a user who
1782 // wants to select the complete content of a long document.
1786 case LFUN_WORD_DELETE_FORWARD:
1787 case LFUN_WORD_DELETE_BACKWARD:
1788 case LFUN_LINE_DELETE:
1789 case LFUN_WORD_FORWARD:
1790 case LFUN_WORD_BACKWARD:
1791 case LFUN_CHAR_FORWARD:
1792 case LFUN_CHAR_FORWARD_SELECT:
1793 case LFUN_CHAR_BACKWARD:
1794 case LFUN_CHAR_BACKWARD_SELECT:
1796 case LFUN_UP_SELECT:
1798 case LFUN_DOWN_SELECT:
1799 case LFUN_PARAGRAPH_UP_SELECT:
1800 case LFUN_PARAGRAPH_DOWN_SELECT:
1801 case LFUN_SCREEN_UP_SELECT:
1802 case LFUN_SCREEN_DOWN_SELECT:
1803 case LFUN_LINE_BEGIN_SELECT:
1804 case LFUN_LINE_END_SELECT:
1805 case LFUN_WORD_FORWARD_SELECT:
1806 case LFUN_WORD_BACKWARD_SELECT:
1807 case LFUN_WORD_SELECT:
1808 case LFUN_PARAGRAPH_UP:
1809 case LFUN_PARAGRAPH_DOWN:
1810 case LFUN_SCREEN_UP:
1811 case LFUN_SCREEN_DOWN:
1812 case LFUN_LINE_BEGIN:
1814 case LFUN_BREAK_LINE:
1815 case LFUN_CHAR_DELETE_FORWARD:
1816 case LFUN_DELETE_FORWARD_SKIP:
1817 case LFUN_CHAR_DELETE_BACKWARD:
1818 case LFUN_DELETE_BACKWARD_SKIP:
1819 case LFUN_BREAK_PARAGRAPH:
1820 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
1821 case LFUN_BREAK_PARAGRAPH_SKIP:
1822 case LFUN_PARAGRAPH_SPACING:
1823 case LFUN_INSET_INSERT:
1824 case LFUN_WORD_UPCASE:
1825 case LFUN_WORD_LOWCASE:
1826 case LFUN_WORD_CAPITALIZE:
1827 case LFUN_CHARS_TRANSPOSE:
1828 case LFUN_SERVER_GET_XY:
1829 case LFUN_SERVER_SET_XY:
1830 case LFUN_SERVER_GET_FONT:
1831 case LFUN_SERVER_GET_LAYOUT:
1833 case LFUN_DATE_INSERT:
1834 case LFUN_SELF_INSERT:
1835 case LFUN_LINE_INSERT:
1836 case LFUN_PAGEBREAK_INSERT:
1837 case LFUN_CLEARPAGE_INSERT:
1838 case LFUN_CLEARDOUBLEPAGE_INSERT:
1839 case LFUN_MATH_DISPLAY:
1840 case LFUN_MATH_IMPORT_SELECTION:
1841 case LFUN_MATH_MODE:
1842 case LFUN_MATH_MACRO:
1843 case LFUN_MATH_MATRIX:
1844 case LFUN_MATH_DELIM:
1845 case LFUN_MATH_BIGDELIM:
1846 case LFUN_MATH_SUBSCRIPT:
1847 case LFUN_MATH_SUPERSCRIPT:
1848 case LFUN_FONT_DEFAULT:
1849 case LFUN_FONT_UNDERLINE:
1850 case LFUN_FONT_SIZE:
1852 case LFUN_FONT_FREE_APPLY:
1853 case LFUN_FONT_FREE_UPDATE:
1854 case LFUN_LAYOUT_PARAGRAPH:
1855 case LFUN_PARAGRAPH_UPDATE:
1856 case LFUN_ACCENT_UMLAUT:
1857 case LFUN_ACCENT_CIRCUMFLEX:
1858 case LFUN_ACCENT_GRAVE:
1859 case LFUN_ACCENT_ACUTE:
1860 case LFUN_ACCENT_TILDE:
1861 case LFUN_ACCENT_CEDILLA:
1862 case LFUN_ACCENT_MACRON:
1863 case LFUN_ACCENT_DOT:
1864 case LFUN_ACCENT_UNDERDOT:
1865 case LFUN_ACCENT_UNDERBAR:
1866 case LFUN_ACCENT_CARON:
1867 case LFUN_ACCENT_SPECIAL_CARON:
1868 case LFUN_ACCENT_BREVE:
1869 case LFUN_ACCENT_TIE:
1870 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1871 case LFUN_ACCENT_CIRCLE:
1872 case LFUN_ACCENT_OGONEK:
1873 case LFUN_THESAURUS_ENTRY:
1874 case LFUN_PARAGRAPH_PARAMS_APPLY:
1876 case LFUN_BUFFER_END:
1877 case LFUN_BUFFER_BEGIN:
1878 case LFUN_BUFFER_BEGIN_SELECT:
1879 case LFUN_BUFFER_END_SELECT:
1880 case LFUN_UNICODE_INSERT:
1881 // these are handled in our dispatch()
1889 if (code != InsetBase::NO_CODE
1890 && (cur.empty() || !cur.inset().insetAllowed(code)))
1893 flag.enabled(enable);
1898 void LyXText::pasteString(LCursor & cur, docstring const & clip,
1901 cur.clearSelection();
1902 if (!clip.empty()) {
1905 insertStringAsParagraphs(cur, clip);
1907 insertStringAsLines(cur, clip);