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 if (!cur.selection())
125 theSelection().haveSelection(false);
126 cur.bv().switchKeyMap();
130 void finishChange(LCursor & cur, bool selecting)
133 moveCursor(cur, selecting);
137 void mathDispatch(LCursor & cur, FuncRequest const & cmd, bool display)
140 docstring sel = cur.selectionAsString(false);
141 //lyxerr << "selection is: '" << sel << "'" << endl;
143 // It may happen that sel is empty but there is a selection
144 replaceSelection(cur);
147 const int old_pos = cur.pos();
148 cur.insert(new InsetMathHull(hullSimple));
149 BOOST_ASSERT(old_pos == cur.pos());
150 cur.nextInset()->edit(cur, true);
151 // don't do that also for LFUN_MATH_MODE
152 // unless you want end up with always changing
153 // to mathrm when opening an inlined inset --
154 // I really hate "LyXfunc overloading"...
156 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
157 // Avoid an unnecessary undo step if cmd.argument
159 if (!cmd.argument().empty())
160 cur.dispatch(FuncRequest(LFUN_MATH_INSERT,
163 // create a macro if we see "\\newcommand"
164 // somewhere, and an ordinary formula
166 if (sel.find(from_ascii("\\newcommand")) == string::npos
167 && sel.find(from_ascii("\\def")) == string::npos)
169 InsetMathHull * formula = new InsetMathHull;
170 istringstream is(to_utf8(sel));
173 formula->read(cur.buffer(), lex);
174 if (formula->getType() == hullNone)
175 // Don't create pseudo formulas if
176 // delimiters are left out
177 formula->mutate(hullSimple);
180 cur.insert(new MathMacroTemplate(sel));
183 cur.message(from_utf8(N_("Math editor mode")));
192 string const freefont2string()
195 if (font2string(freefont, toggleall, data))
202 void LyXText::cursorPrevious(LCursor & cur)
204 pos_type cpos = cur.pos();
205 pit_type cpar = cur.pit();
207 int x = cur.x_target();
208 setCursorFromCoordinates(cur, x, 0);
209 cur.dispatch(FuncRequest(cur.selection()? LFUN_UP_SELECT: LFUN_UP));
211 if (cpar == cur.pit() && cpos == cur.pos())
212 // we have a row which is taller than the workarea. The
213 // simplest solution is to move to the previous row instead.
214 cur.dispatch(FuncRequest(cur.selection()? LFUN_UP_SELECT: LFUN_UP));
217 cur.updateFlags(Update::Force | Update::FitCursor);
221 void LyXText::cursorNext(LCursor & cur)
223 pos_type cpos = cur.pos();
224 pit_type cpar = cur.pit();
226 int x = cur.x_target();
227 setCursorFromCoordinates(cur, x, cur.bv().workHeight() - 1);
228 cur.dispatch(FuncRequest(cur.selection()? LFUN_DOWN_SELECT: LFUN_DOWN));
230 if (cpar == cur.pit() && cpos == cur.pos())
231 // we have a row which is taller than the workarea. The
232 // simplest solution is to move to the next row instead.
234 FuncRequest(cur.selection()? LFUN_DOWN_SELECT: LFUN_DOWN));
237 cur.updateFlags(Update::Force | Update::FitCursor);
243 void specialChar(LCursor & cur, InsetSpecialChar::Kind kind)
245 cap::replaceSelection(cur);
246 cur.insert(new InsetSpecialChar(kind));
251 bool doInsertInset(LCursor & cur, LyXText * text,
252 FuncRequest const & cmd, bool edit, bool pastesel)
254 InsetBase * inset = createInset(&cur.bv(), cmd);
260 if (cur.selection()) {
261 lyx::dispatch(FuncRequest(LFUN_CUT));
264 text->insertInset(cur, inset);
267 inset->edit(cur, true);
269 if (gotsel && pastesel) {
270 lyx::dispatch(FuncRequest(LFUN_PASTE));
271 // reset first par to default
272 if (cur.lastpit() != 0 || cur.lastpos() != 0) {
273 LyXLayout_ptr const layout =
274 cur.buffer().params().getLyXTextClass().defaultLayout();
275 cur.text()->paragraphs().begin()->layout(layout);
285 void LyXText::number(LCursor & cur)
287 LyXFont font(LyXFont::ALL_IGNORE);
288 font.setNumber(LyXFont::TOGGLE);
289 toggleAndShow(cur, this, font);
293 bool LyXText::isRTL(Buffer const & buffer, Paragraph const & par) const
295 return par.isRightToLeftPar(buffer.params());
299 void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
301 lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
303 // FIXME: We use the update flag to indicates wether a singlePar or a
304 // full screen update is needed. We reset it here but shall we restore it
308 BOOST_ASSERT(cur.text() == this);
309 BufferView * bv = &cur.bv();
310 CursorSlice oldTopSlice = cur.top();
311 bool oldBoundary = cur.boundary();
312 bool sel = cur.selection();
313 // Signals that, even if needsUpdate == false, an update of the
314 // cursor paragraph is required
315 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
316 LyXAction::SingleParUpdate);
317 // Signals that a full-screen update is required
318 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
319 LyXAction::NoUpdate) || singleParUpdate);
320 // Remember the old paragraph metric (_outer_ paragraph!)
321 ParagraphMetrics const & pm = cur.bv().parMetrics(
322 cur.bottom().text(), cur.bottom().pit());
323 Dimension olddim = pm.dim();
325 switch (cmd.action) {
327 case LFUN_PARAGRAPH_MOVE_DOWN: {
328 pit_type const pit = cur.pit();
329 recUndo(cur, pit, pit + 1);
331 std::swap(pars_[pit], pars_[pit + 1]);
333 ParIterator begin(cur);
335 ParIterator end = boost::next(ParIterator(cur));
336 updateLabels(cur.buffer(), begin, end);
342 case LFUN_PARAGRAPH_MOVE_UP: {
343 pit_type const pit = cur.pit();
344 recUndo(cur, pit - 1, pit);
346 std::swap(pars_[pit], pars_[pit - 1]);
348 ParIterator end = boost::next(ParIterator(cur));
350 ParIterator begin(cur);
351 updateLabels(cur.buffer(), begin, end);
357 case LFUN_APPENDIX: {
358 Paragraph & par = cur.paragraph();
359 bool start = !par.params().startOfAppendix();
362 #warning The code below only makes sense at top level.
363 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
365 // ensure that we have only one start_of_appendix in this document
366 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
367 if (pars_[tmp].params().startOfAppendix()) {
369 pars_[tmp].params().startOfAppendix(false);
375 par.params().startOfAppendix(start);
377 // we can set the refreshing parameters now
378 updateLabels(cur.buffer());
382 case LFUN_WORD_DELETE_FORWARD:
383 cur.clearSelection();
384 deleteWordForward(cur);
385 finishChange(cur, false);
388 case LFUN_WORD_DELETE_BACKWARD:
389 cur.clearSelection();
390 deleteWordBackward(cur);
391 finishChange(cur, false);
394 case LFUN_LINE_DELETE:
395 cur.clearSelection();
396 deleteLineForward(cur);
397 finishChange(cur, false);
400 case LFUN_BUFFER_BEGIN:
401 case LFUN_BUFFER_BEGIN_SELECT:
402 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
403 if (cur.depth() == 1) {
404 needsUpdate |= cursorTop(cur);
410 case LFUN_BUFFER_END:
411 case LFUN_BUFFER_END_SELECT:
412 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
413 if (cur.depth() == 1) {
414 needsUpdate |= cursorBottom(cur);
420 case LFUN_CHAR_FORWARD:
421 case LFUN_CHAR_FORWARD_SELECT:
422 //lyxerr << BOOST_CURRENT_FUNCTION
423 // << " LFUN_CHAR_FORWARD[SEL]:\n" << cur << endl;
424 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
425 if (isRTL(*cur.bv().buffer(), cur.paragraph()))
426 needsUpdate |= cursorLeft(cur);
428 needsUpdate |= cursorRight(cur);
430 if (!needsUpdate && oldTopSlice == cur.top()
431 && cur.boundary() == oldBoundary) {
433 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
437 case LFUN_CHAR_BACKWARD:
438 case LFUN_CHAR_BACKWARD_SELECT:
439 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
440 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
441 if (isRTL(*cur.bv().buffer(), cur.paragraph()))
442 needsUpdate |= cursorRight(cur);
444 needsUpdate |= cursorLeft(cur);
446 if (!needsUpdate && oldTopSlice == cur.top()
447 && cur.boundary() == oldBoundary) {
449 cmd = FuncRequest(LFUN_FINISHED_LEFT);
455 //lyxerr << "handle LFUN_UP[SEL]:\n" << cur << endl;
456 needsUpdate |= cur.selHandle(cmd.action == LFUN_UP_SELECT);
458 needsUpdate |= cursorUp(cur);
460 if (!needsUpdate && oldTopSlice == cur.top()
461 && cur.boundary() == oldBoundary) {
463 cmd = FuncRequest(LFUN_FINISHED_UP);
468 case LFUN_DOWN_SELECT:
469 //lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
470 needsUpdate |= cur.selHandle(cmd.action == LFUN_DOWN_SELECT);
471 needsUpdate |= cursorDown(cur);
473 if (!needsUpdate && oldTopSlice == cur.top() &&
474 cur.boundary() == oldBoundary)
477 cmd = FuncRequest(LFUN_FINISHED_DOWN);
481 case LFUN_PARAGRAPH_UP:
482 case LFUN_PARAGRAPH_UP_SELECT:
483 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
484 needsUpdate |= cursorUpParagraph(cur);
487 case LFUN_PARAGRAPH_DOWN:
488 case LFUN_PARAGRAPH_DOWN_SELECT:
489 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
490 needsUpdate |= cursorDownParagraph(cur);
494 case LFUN_SCREEN_UP_SELECT:
495 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_UP_SELECT);
496 if (cur.pit() == 0 && cur.textRow().pos() == 0) {
498 cmd = FuncRequest(LFUN_FINISHED_UP);
504 case LFUN_SCREEN_DOWN:
505 case LFUN_SCREEN_DOWN_SELECT:
506 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_DOWN_SELECT);
507 if (cur.pit() == cur.lastpit()
508 && cur.textRow().endpos() == cur.lastpos()) {
510 cmd = FuncRequest(LFUN_FINISHED_DOWN);
516 case LFUN_LINE_BEGIN:
517 case LFUN_LINE_BEGIN_SELECT:
518 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
519 needsUpdate |= cursorHome(cur);
523 case LFUN_LINE_END_SELECT:
524 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
525 needsUpdate |= cursorEnd(cur);
528 case LFUN_WORD_FORWARD:
529 case LFUN_WORD_FORWARD_SELECT:
530 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
531 if (isRTL(*cur.bv().buffer(), cur.paragraph()))
532 needsUpdate |= cursorLeftOneWord(cur);
534 needsUpdate |= cursorRightOneWord(cur);
537 case LFUN_WORD_BACKWARD:
538 case LFUN_WORD_BACKWARD_SELECT:
539 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
540 if (isRTL(*cur.bv().buffer(), cur.paragraph()))
541 needsUpdate |= cursorRightOneWord(cur);
543 needsUpdate |= cursorLeftOneWord(cur);
546 case LFUN_WORD_SELECT: {
547 selectWord(cur, WHOLE_WORD);
548 finishChange(cur, true);
552 case LFUN_BREAK_LINE: {
553 // Not allowed by LaTeX (labels or empty par)
554 if (cur.pos() > cur.paragraph().beginOfBody()) {
555 cap::replaceSelection(cur);
556 cur.insert(new InsetNewline);
558 moveCursor(cur, false);
563 case LFUN_CHAR_DELETE_FORWARD:
564 if (!cur.selection()) {
565 if (cur.pos() == cur.paragraph().size())
566 // Par boundary, force full-screen update
567 singleParUpdate = false;
568 needsUpdate |= erase(cur);
570 // It is possible to make it a lot faster still
571 // just comment out the line below...
573 cutSelection(cur, true, false);
574 singleParUpdate = false;
576 moveCursor(cur, false);
579 case LFUN_DELETE_FORWARD_SKIP:
580 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
581 if (!cur.selection()) {
582 if (cur.pos() == cur.lastpos()) {
589 cutSelection(cur, true, false);
594 case LFUN_CHAR_DELETE_BACKWARD:
595 if (!cur.selection()) {
596 if (bv->getIntl().getTransManager().backspace()) {
597 // Par boundary, full-screen update
599 singleParUpdate = false;
600 needsUpdate |= backspace(cur);
602 // It is possible to make it a lot faster still
603 // just comment out the line below...
606 cutSelection(cur, true, false);
607 singleParUpdate = false;
612 case LFUN_DELETE_BACKWARD_SKIP:
613 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
614 if (!cur.selection()) {
618 //CursorSlice cur = cursor();
622 cutSelection(cur, true, false);
626 case LFUN_BREAK_PARAGRAPH:
627 cap::replaceSelection(cur);
628 breakParagraph(cur, 0);
633 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
634 cap::replaceSelection(cur);
635 breakParagraph(cur, 1);
640 case LFUN_BREAK_PARAGRAPH_SKIP: {
641 // When at the beginning of a paragraph, remove
642 // indentation. Otherwise, do the same as LFUN_BREAK_PARAGRAPH.
643 cap::replaceSelection(cur);
645 cur.paragraph().params().labelWidthString(docstring());
647 breakParagraph(cur, 0);
653 case LFUN_PARAGRAPH_SPACING: {
654 Paragraph & par = cur.paragraph();
655 Spacing::Space cur_spacing = par.params().spacing().getSpace();
656 string cur_value = "1.0";
657 if (cur_spacing == Spacing::Other)
658 cur_value = par.params().spacing().getValueAsString();
660 istringstream is(to_utf8(cmd.argument()));
663 Spacing::Space new_spacing = cur_spacing;
664 string new_value = cur_value;
666 lyxerr << "Missing argument to `paragraph-spacing'"
668 } else if (tmp == "single") {
669 new_spacing = Spacing::Single;
670 } else if (tmp == "onehalf") {
671 new_spacing = Spacing::Onehalf;
672 } else if (tmp == "double") {
673 new_spacing = Spacing::Double;
674 } else if (tmp == "other") {
675 new_spacing = Spacing::Other;
676 string tmpval = "0.0";
678 lyxerr << "new_value = " << tmpval << endl;
681 } else if (tmp == "default") {
682 new_spacing = Spacing::Default;
684 lyxerr << to_utf8(_("Unknown spacing argument: "))
685 << to_utf8(cmd.argument()) << endl;
687 if (cur_spacing != new_spacing || cur_value != new_value)
688 par.params().spacing(Spacing(new_spacing, new_value));
692 case LFUN_INSET_INSERT: {
694 InsetBase * inset = createInset(bv, cmd);
696 insertInset(cur, inset);
702 case LFUN_INSET_DISSOLVE:
703 needsUpdate |= dissolveInset(cur);
706 case LFUN_INSET_SETTINGS:
707 cur.inset().showInsetDialog(bv);
710 case LFUN_SPACE_INSERT:
711 if (cur.paragraph().layout()->free_spacing)
712 insertChar(cur, ' ');
714 doInsertInset(cur, this, cmd, false, false);
717 moveCursor(cur, false);
720 case LFUN_HYPHENATION_POINT_INSERT:
721 specialChar(cur, InsetSpecialChar::HYPHENATION);
724 case LFUN_LIGATURE_BREAK_INSERT:
725 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
728 case LFUN_DOTS_INSERT:
729 specialChar(cur, InsetSpecialChar::LDOTS);
732 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
733 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
736 case LFUN_MENU_SEPARATOR_INSERT:
737 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
740 case LFUN_WORD_UPCASE:
741 changeCase(cur, LyXText::text_uppercase);
744 case LFUN_WORD_LOWCASE:
745 changeCase(cur, LyXText::text_lowercase);
748 case LFUN_WORD_CAPITALIZE:
749 changeCase(cur, LyXText::text_capitalization);
752 case LFUN_CHARS_TRANSPOSE:
757 cur.message(_("Paste"));
758 cap::replaceSelection(cur);
759 if (isStrUnsignedInt(to_utf8(cmd.argument())))
760 pasteSelection(cur, bv->buffer()->errorList("Paste"),
761 convert<unsigned int>(to_utf8(cmd.argument())));
763 pasteSelection(cur, bv->buffer()->errorList("Paste"),
765 bv->buffer()->errors("Paste");
766 cur.clearSelection(); // bug 393
772 cutSelection(cur, true, true);
773 cur.message(_("Cut"));
778 cur.message(_("Copy"));
781 case LFUN_SERVER_GET_XY:
782 cur.message(from_utf8(
783 convert<string>(cursorX(cur.bv(), cur.top(), cur.boundary()))
784 + ' ' + convert<string>(cursorY(cur.bv(), cur.top(), cur.boundary()))));
787 case LFUN_SERVER_SET_XY: {
790 istringstream is(to_utf8(cmd.argument()));
793 lyxerr << "SETXY: Could not parse coordinates in '"
794 << to_utf8(cmd.argument()) << std::endl;
796 setCursorFromCoordinates(cur, x, y);
800 case LFUN_SERVER_GET_FONT:
801 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
802 cur.message(from_ascii("E"));
803 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
804 cur.message(from_ascii("N"));
806 cur.message(from_ascii("0"));
809 case LFUN_SERVER_GET_LAYOUT:
810 cur.message(from_utf8(cur.paragraph().layout()->name()));
814 string layout = to_ascii(cmd.argument());
815 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) " << layout << endl;
817 // Derive layout number from given argument (string)
818 // and current buffer's textclass (number)
819 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
821 layout = tclass.defaultLayoutName();
822 bool hasLayout = tclass.hasLayout(layout);
824 // If the entry is obsolete, use the new one instead.
826 string const & obs = tclass[layout]->obsoleted_by();
832 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
833 from_utf8(N_(" not known")));
837 bool change_layout = (current_layout != layout);
839 if (!change_layout && cur.selection() &&
840 cur.selBegin().pit() != cur.selEnd().pit())
842 pit_type spit = cur.selBegin().pit();
843 pit_type epit = cur.selEnd().pit() + 1;
844 while (spit != epit) {
845 if (pars_[spit].layout()->name() != current_layout) {
846 change_layout = true;
854 current_layout = layout;
855 setLayout(cur, layout);
856 // inform the GUI that the layout has changed.
857 bv->layoutChanged(layout);
863 case LFUN_CLIPBOARD_PASTE:
864 pasteString(cur, theClipboard().get(), cmd.argument());
867 case LFUN_PRIMARY_SELECTION_PASTE:
868 pasteString(cur, theSelection().get(), cmd.argument());
871 case LFUN_UNICODE_INSERT: {
872 if (cmd.argument().empty())
874 docstring hexstring = cmd.argument();
875 if (lyx::support::isHex(hexstring)) {
876 char_type c = lyx::support::hexToInt(hexstring);
877 if (c > 32 && c < 0x10ffff) {
878 lyxerr << "Inserting c: " << c << endl;
879 docstring s = docstring(1, c);
880 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
886 case LFUN_QUOTE_INSERT: {
887 cap::replaceSelection(cur);
888 Paragraph & par = cur.paragraph();
889 pos_type pos = cur.pos();
893 else if (cur.prevInset() && cur.prevInset()->isSpace())
896 c = par.getChar(pos - 1);
898 LyXLayout_ptr const & style = par.layout();
900 BufferParams const & bufparams = bv->buffer()->params();
901 if (!style->pass_thru
902 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
903 string arg = to_utf8(cmd.argument());
905 cur.insert(new InsetQuotes(c,
906 bufparams.quotes_language,
907 InsetQuotes::SingleQ));
909 cur.insert(new InsetQuotes(c,
910 bufparams.quotes_language,
911 InsetQuotes::DoubleQ));
915 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
919 case LFUN_DATE_INSERT:
920 if (cmd.argument().empty())
921 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
922 formatted_time(current_time())));
924 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
925 formatted_time(current_time(), to_utf8(cmd.argument()))));
928 case LFUN_MOUSE_TRIPLE:
929 if (cmd.button() == mouse_button::button1) {
935 theSelection().haveSelection(cur.selection());
939 case LFUN_MOUSE_DOUBLE:
940 if (cmd.button() == mouse_button::button1) {
941 selectWord(cur, WHOLE_WORD_STRICT);
943 theSelection().haveSelection(cur.selection());
947 // Single-click on work area
948 case LFUN_MOUSE_PRESS: {
949 // Right click on a footnote flag opens float menu
950 if (cmd.button() == mouse_button::button3)
951 cur.clearSelection();
953 // Middle button press pastes if we have a selection
954 // We do this here as if the selection was inside an inset
955 // it could get cleared on the unlocking of the inset so
956 // we have to check this first
957 bool paste_internally = false;
958 if (cmd.button() == mouse_button::button2 && cur.selection()) {
959 lyx::dispatch(FuncRequest(LFUN_COPY));
960 paste_internally = true;
963 // we have to update after dePM triggered
964 bool update = bv->mouseSetCursor(cur);
966 // Insert primary selection with middle mouse
967 // if there is a local selection in the current buffer,
969 if (cmd.button() == mouse_button::button2) {
970 if (paste_internally)
971 lyx::dispatch(FuncRequest(LFUN_PASTE));
973 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
976 if (!update && cmd.button() == mouse_button::button1) {
984 case LFUN_MOUSE_MOTION: {
985 // Only use motion with button 1
986 //if (cmd.button() != mouse_button::button1)
989 // ignore motions deeper nested than the real anchor
990 LCursor & bvcur = cur.bv().cursor();
991 if (bvcur.anchor_.hasPart(cur)) {
992 CursorSlice old = bvcur.top();
994 int const wh = bv->workHeight();
995 int const y = std::max(0, std::min(wh - 1, cmd.y));
997 setCursorFromCoordinates(cur, cmd.x, y);
998 cur.x_target() = cmd.x;
1000 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1002 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1003 // This is to allow jumping over large insets
1004 if (cur.top() == old) {
1006 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1008 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1011 if (cur.top() == old)
1014 // don't set anchor_
1015 bvcur.setCursor(cur);
1016 bvcur.selection() = true;
1017 //lyxerr << "MOTION: " << bv->cursor() << endl;
1025 case LFUN_MOUSE_RELEASE: {
1026 if (cmd.button() == mouse_button::button2)
1030 if (cmd.button() == mouse_button::button1) {
1031 if (cur.selection())
1032 theSelection().haveSelection(cur.selection());
1033 needsUpdate = false;
1041 case LFUN_SELF_INSERT: {
1042 if (cmd.argument().empty())
1045 // Automatically delete the currently selected
1046 // text and replace it with what is being
1047 // typed in now. Depends on lyxrc settings
1048 // "auto_region_delete", which defaults to
1051 if (lyxrc.auto_region_delete) {
1052 if (cur.selection())
1053 cutSelection(cur, false, false);
1054 theSelection().haveSelection(false);
1057 cur.clearSelection();
1058 LyXFont const old_font = real_current_font;
1060 docstring::const_iterator cit = cmd.argument().begin();
1061 docstring::const_iterator end = cmd.argument().end();
1062 for (; cit != end; ++cit)
1064 bv->getIntl().getTransManager().
1065 translateAndInsert(*cit, this);
1067 insertChar(bv->cursor(), *cit);
1071 moveCursor(cur, false);
1075 case LFUN_URL_INSERT: {
1076 InsetCommandParams p("url");
1077 string const data = InsetCommandMailer::params2string("url", p);
1078 bv->showInsetDialog("url", data, 0);
1082 case LFUN_HTML_INSERT: {
1083 InsetCommandParams p("htmlurl");
1084 string const data = InsetCommandMailer::params2string("url", p);
1085 bv->showInsetDialog("url", data, 0);
1089 case LFUN_LABEL_INSERT: {
1090 InsetCommandParams p("label");
1091 // Try to generate a valid label
1092 p["name"] = (cmd.argument().empty()) ?
1093 cur.getPossibleLabel() :
1095 string const data = InsetCommandMailer::params2string("label", p);
1097 if (cmd.argument().empty()) {
1098 bv->showInsetDialog("label", data, 0);
1100 FuncRequest fr(LFUN_INSET_INSERT, data);
1108 case LFUN_LIST_INSERT:
1109 case LFUN_THEOREM_INSERT:
1110 case LFUN_CAPTION_INSERT:
1112 case LFUN_NOTE_INSERT:
1113 case LFUN_CHARSTYLE_INSERT:
1114 case LFUN_BOX_INSERT:
1115 case LFUN_BRANCH_INSERT:
1116 case LFUN_BIBITEM_INSERT:
1117 case LFUN_ERT_INSERT:
1118 case LFUN_FOOTNOTE_INSERT:
1119 case LFUN_MARGINALNOTE_INSERT:
1120 case LFUN_OPTIONAL_INSERT:
1121 case LFUN_ENVIRONMENT_INSERT:
1122 // Open the inset, and move the current selection
1124 doInsertInset(cur, this, cmd, true, true);
1128 case LFUN_TABULAR_INSERT:
1129 // if there were no arguments, just open the dialog
1130 if (doInsertInset(cur, this, cmd, false, true))
1133 bv->showDialog("tabularcreate");
1137 case LFUN_FLOAT_INSERT:
1138 case LFUN_FLOAT_WIDE_INSERT:
1139 case LFUN_WRAP_INSERT:
1140 doInsertInset(cur, this, cmd, true, true);
1142 // FIXME: the "Caption" name should not be hardcoded,
1143 // but given by the float definition.
1144 cur.dispatch(FuncRequest(LFUN_LAYOUT, "Caption"));
1147 case LFUN_INDEX_INSERT:
1148 case LFUN_NOMENCL_INSERT: {
1149 InsetBase * inset = createInset(&cur.bv(), cmd);
1154 cur.clearSelection();
1155 insertInset(cur, inset);
1156 inset->edit(cur, true);
1157 // Show the dialog for the nomenclature entry, since the
1158 // description entry still needs to be filled in.
1159 if (cmd.action == LFUN_NOMENCL_INSERT)
1160 InsetCommandMailer("nomenclature",
1161 *reinterpret_cast<InsetCommand *>(inset)).showDialog(&cur.bv());
1166 case LFUN_INDEX_PRINT:
1167 case LFUN_NOMENCL_PRINT:
1168 case LFUN_TOC_INSERT:
1169 case LFUN_HFILL_INSERT:
1170 case LFUN_LINE_INSERT:
1171 case LFUN_PAGEBREAK_INSERT:
1172 case LFUN_CLEARPAGE_INSERT:
1173 case LFUN_CLEARDOUBLEPAGE_INSERT:
1175 doInsertInset(cur, this, cmd, false, false);
1179 case LFUN_DEPTH_DECREMENT:
1180 changeDepth(cur, DEC_DEPTH);
1183 case LFUN_DEPTH_INCREMENT:
1184 changeDepth(cur, INC_DEPTH);
1187 case LFUN_MATH_DISPLAY:
1188 mathDispatch(cur, cmd, true);
1191 case LFUN_MATH_IMPORT_SELECTION:
1192 case LFUN_MATH_MODE:
1193 if (cmd.argument() == "on")
1194 // don't pass "on" as argument
1195 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1197 mathDispatch(cur, cmd, false);
1200 case LFUN_MATH_MACRO:
1201 if (cmd.argument().empty())
1202 cur.errorMessage(from_utf8(N_("Missing argument")));
1204 string s = to_utf8(cmd.argument());
1205 string const s1 = token(s, ' ', 1);
1206 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1207 string const s2 = token(s, ' ', 2);
1208 string const type = s2.empty() ? "newcommand" : s2;
1209 cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, from_utf8(type)));
1210 //cur.nextInset()->edit(cur, true);
1214 // passthrough hat and underscore outside mathed:
1215 case LFUN_MATH_SUBSCRIPT:
1216 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1218 case LFUN_MATH_SUPERSCRIPT:
1219 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1222 case LFUN_MATH_INSERT:
1223 case LFUN_MATH_MATRIX:
1224 case LFUN_MATH_DELIM:
1225 case LFUN_MATH_BIGDELIM: {
1226 cur.insert(new InsetMathHull(hullSimple));
1227 cur.dispatch(FuncRequest(LFUN_CHAR_FORWARD));
1232 case LFUN_FONT_EMPH: {
1233 LyXFont font(LyXFont::ALL_IGNORE);
1234 font.setEmph(LyXFont::TOGGLE);
1235 toggleAndShow(cur, this, font);
1239 case LFUN_FONT_BOLD: {
1240 LyXFont font(LyXFont::ALL_IGNORE);
1241 font.setSeries(LyXFont::BOLD_SERIES);
1242 toggleAndShow(cur, this, font);
1246 case LFUN_FONT_NOUN: {
1247 LyXFont font(LyXFont::ALL_IGNORE);
1248 font.setNoun(LyXFont::TOGGLE);
1249 toggleAndShow(cur, this, font);
1253 case LFUN_FONT_CODE: {
1254 LyXFont font(LyXFont::ALL_IGNORE);
1255 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1256 toggleAndShow(cur, this, font);
1260 case LFUN_FONT_SANS: {
1261 LyXFont font(LyXFont::ALL_IGNORE);
1262 font.setFamily(LyXFont::SANS_FAMILY);
1263 toggleAndShow(cur, this, font);
1267 case LFUN_FONT_ROMAN: {
1268 LyXFont font(LyXFont::ALL_IGNORE);
1269 font.setFamily(LyXFont::ROMAN_FAMILY);
1270 toggleAndShow(cur, this, font);
1274 case LFUN_FONT_DEFAULT: {
1275 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1276 toggleAndShow(cur, this, font);
1280 case LFUN_FONT_UNDERLINE: {
1281 LyXFont font(LyXFont::ALL_IGNORE);
1282 font.setUnderbar(LyXFont::TOGGLE);
1283 toggleAndShow(cur, this, font);
1287 case LFUN_FONT_SIZE: {
1288 LyXFont font(LyXFont::ALL_IGNORE);
1289 font.setLyXSize(to_utf8(cmd.argument()));
1290 toggleAndShow(cur, this, font);
1294 case LFUN_LANGUAGE: {
1295 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1298 LyXFont font(LyXFont::ALL_IGNORE);
1299 font.setLanguage(lang);
1300 toggleAndShow(cur, this, font);
1305 case LFUN_FONT_FREE_APPLY:
1306 toggleAndShow(cur, this, freefont, toggleall);
1307 cur.message(_("Character set"));
1310 // Set the freefont using the contents of \param data dispatched from
1311 // the frontends and apply it at the current cursor location.
1312 case LFUN_FONT_FREE_UPDATE: {
1315 if (bv_funcs::string2font(to_utf8(cmd.argument()), font, toggle)) {
1318 toggleAndShow(cur, this, freefont, toggleall);
1319 cur.message(_("Character set"));
1324 case LFUN_FINISHED_LEFT:
1325 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1328 case LFUN_FINISHED_RIGHT:
1329 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1333 case LFUN_FINISHED_UP:
1334 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_UP:\n" << cur << endl;
1338 case LFUN_FINISHED_DOWN:
1339 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_DOWN:\n" << cur << endl;
1343 case LFUN_LAYOUT_PARAGRAPH: {
1345 params2string(cur.paragraph(), data);
1346 data = "show\n" + data;
1347 bv->showDialogWithData("paragraph", data);
1351 case LFUN_PARAGRAPH_UPDATE: {
1353 params2string(cur.paragraph(), data);
1355 // Will the paragraph accept changes from the dialog?
1356 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1358 data = "update " + convert<string>(accept) + '\n' + data;
1359 bv->updateDialog("paragraph", data);
1363 case LFUN_ACCENT_UMLAUT:
1364 case LFUN_ACCENT_CIRCUMFLEX:
1365 case LFUN_ACCENT_GRAVE:
1366 case LFUN_ACCENT_ACUTE:
1367 case LFUN_ACCENT_TILDE:
1368 case LFUN_ACCENT_CEDILLA:
1369 case LFUN_ACCENT_MACRON:
1370 case LFUN_ACCENT_DOT:
1371 case LFUN_ACCENT_UNDERDOT:
1372 case LFUN_ACCENT_UNDERBAR:
1373 case LFUN_ACCENT_CARON:
1374 case LFUN_ACCENT_SPECIAL_CARON:
1375 case LFUN_ACCENT_BREVE:
1376 case LFUN_ACCENT_TIE:
1377 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1378 case LFUN_ACCENT_CIRCLE:
1379 case LFUN_ACCENT_OGONEK:
1380 theLyXFunc().handleKeyFunc(cmd.action);
1381 if (!cmd.argument().empty())
1382 // FIXME: Are all these characters encoded in one byte in utf8?
1383 bv->getIntl().getTransManager()
1384 .translateAndInsert(cmd.argument()[0], this, cur);
1387 case LFUN_FLOAT_LIST: {
1388 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1389 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1390 // not quite sure if we want this...
1392 cur.clearSelection();
1393 breakParagraph(cur);
1395 if (cur.lastpos() != 0) {
1397 breakParagraph(cur);
1400 setLayout(cur, tclass.defaultLayoutName());
1401 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, docstring(), 0);
1402 insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1405 lyxerr << "Non-existent float type: "
1406 << to_utf8(cmd.argument()) << endl;
1411 case LFUN_CHANGE_ACCEPT: {
1416 case LFUN_CHANGE_REJECT: {
1421 case LFUN_THESAURUS_ENTRY: {
1422 docstring arg = cmd.argument();
1424 arg = cur.selectionAsString(false);
1426 if (arg.size() > 100 || arg.empty()) {
1427 // Get word or selection
1428 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1429 arg = cur.selectionAsString(false);
1432 bv->showDialogWithData("thesaurus", to_utf8(arg));
1436 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1437 // Given data, an encoding of the ParagraphParameters
1438 // generated in the Paragraph dialog, this function sets
1439 // the current paragraph appropriately.
1440 istringstream is(to_utf8(cmd.argument()));
1443 ParagraphParameters params;
1448 params.labelWidthString(),
1450 cur.message(_("Paragraph layout set"));
1455 if (cur.selection()) {
1456 cur.selection() = false;
1459 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1464 lyxerr[Debug::ACTION]
1465 << BOOST_CURRENT_FUNCTION
1466 << ": Command " << cmd
1467 << " not DISPATCHED by LyXText" << endl;
1472 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1474 // FIXME: The cursor flag is reset two lines below
1475 // so we need to check here if some of the LFUN did touch that.
1476 // for now only LyXText::erase() and LyXText::backspace() do that.
1477 // The plan is to verify all the LFUNs and then to remove this
1478 // singleParUpdate boolean altogether.
1479 if (cur.result().update() & Update::Force) {
1480 singleParUpdate = false;
1484 // FIXME: the following code should go in favor of fine grained
1485 // update flag treatment.
1486 if (singleParUpdate) {
1487 // Inserting characters does not change par height
1488 ParagraphMetrics const & pms
1489 = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
1490 if (pms.dim().height()
1491 == olddim.height()) {
1492 // if so, update _only_ this paragraph
1493 cur.updateFlags(Update::SinglePar |
1495 Update::MultiParSel);
1502 && &oldTopSlice.inset() == &cur.inset()
1503 && oldTopSlice.idx() == cur.idx()
1504 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1505 && !cur.selection())
1506 // FIXME: it would be better if we could just do this
1508 //if (cur.result().update() != Update::FitCursor)
1511 // But some LFUNs do not set Update::FitCursor when needed, so we
1512 // do it for all. This is not very harmfull as FitCursor will provoke
1513 // a full redraw only if needed but still, a proper review of all LFUN
1514 // should be done and this needsUpdate boolean can then be removed.
1515 cur.updateFlags(Update::FitCursor);
1517 cur.updateFlags(Update::Force | Update::FitCursor);
1521 bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
1522 FuncStatus & flag) const
1524 BOOST_ASSERT(cur.text() == this);
1526 LyXFont const & font = real_current_font;
1528 InsetBase::Code code = InsetBase::NO_CODE;
1530 switch (cmd.action) {
1532 case LFUN_DEPTH_DECREMENT:
1533 enable = changeDepthAllowed(cur, DEC_DEPTH);
1536 case LFUN_DEPTH_INCREMENT:
1537 enable = changeDepthAllowed(cur, INC_DEPTH);
1541 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1544 case LFUN_BIBITEM_INSERT:
1545 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO);
1548 case LFUN_DIALOG_SHOW_NEW_INSET:
1549 if (cmd.argument() == "bibitem")
1550 code = InsetBase::BIBITEM_CODE;
1551 else if (cmd.argument() == "bibtex")
1552 code = InsetBase::BIBTEX_CODE;
1553 else if (cmd.argument() == "box")
1554 code = InsetBase::BOX_CODE;
1555 else if (cmd.argument() == "branch")
1556 code = InsetBase::BRANCH_CODE;
1557 else if (cmd.argument() == "citation")
1558 code = InsetBase::CITE_CODE;
1559 else if (cmd.argument() == "ert")
1560 code = InsetBase::ERT_CODE;
1561 else if (cmd.argument() == "external")
1562 code = InsetBase::EXTERNAL_CODE;
1563 else if (cmd.argument() == "float")
1564 code = InsetBase::FLOAT_CODE;
1565 else if (cmd.argument() == "graphics")
1566 code = InsetBase::GRAPHICS_CODE;
1567 else if (cmd.argument() == "include")
1568 code = InsetBase::INCLUDE_CODE;
1569 else if (cmd.argument() == "index")
1570 code = InsetBase::INDEX_CODE;
1571 else if (cmd.argument() == "nomenclature")
1572 code = InsetBase::NOMENCL_CODE;
1573 else if (cmd.argument() == "label")
1574 code = InsetBase::LABEL_CODE;
1575 else if (cmd.argument() == "note")
1576 code = InsetBase::NOTE_CODE;
1577 else if (cmd.argument() == "ref")
1578 code = InsetBase::REF_CODE;
1579 else if (cmd.argument() == "toc")
1580 code = InsetBase::TOC_CODE;
1581 else if (cmd.argument() == "url")
1582 code = InsetBase::URL_CODE;
1583 else if (cmd.argument() == "vspace")
1584 code = InsetBase::VSPACE_CODE;
1585 else if (cmd.argument() == "wrap")
1586 code = InsetBase::WRAP_CODE;
1589 case LFUN_ERT_INSERT:
1590 code = InsetBase::ERT_CODE;
1592 case LFUN_FOOTNOTE_INSERT:
1593 code = InsetBase::FOOT_CODE;
1595 case LFUN_TABULAR_INSERT:
1596 code = InsetBase::TABULAR_CODE;
1598 case LFUN_MARGINALNOTE_INSERT:
1599 code = InsetBase::MARGIN_CODE;
1601 case LFUN_FLOAT_INSERT:
1602 case LFUN_FLOAT_WIDE_INSERT:
1603 code = InsetBase::FLOAT_CODE;
1605 case LFUN_WRAP_INSERT:
1606 code = InsetBase::WRAP_CODE;
1608 case LFUN_FLOAT_LIST:
1609 code = InsetBase::FLOAT_LIST_CODE;
1612 case LFUN_LIST_INSERT:
1613 code = InsetBase::LIST_CODE;
1615 case LFUN_THEOREM_INSERT:
1616 code = InsetBase::THEOREM_CODE;
1619 case LFUN_CAPTION_INSERT:
1620 code = InsetBase::CAPTION_CODE;
1622 case LFUN_NOTE_INSERT:
1623 code = InsetBase::NOTE_CODE;
1625 case LFUN_CHARSTYLE_INSERT:
1626 code = InsetBase::CHARSTYLE_CODE;
1627 if (cur.buffer().params().getLyXTextClass().charstyles().empty())
1630 case LFUN_BOX_INSERT:
1631 code = InsetBase::BOX_CODE;
1633 case LFUN_BRANCH_INSERT:
1634 code = InsetBase::BRANCH_CODE;
1635 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1638 case LFUN_LABEL_INSERT:
1639 code = InsetBase::LABEL_CODE;
1641 case LFUN_OPTIONAL_INSERT:
1642 code = InsetBase::OPTARG_CODE;
1643 enable = numberOfOptArgs(cur.paragraph())
1644 < cur.paragraph().layout()->optionalargs;
1646 case LFUN_ENVIRONMENT_INSERT:
1647 code = InsetBase::BOX_CODE;
1649 case LFUN_INDEX_INSERT:
1650 code = InsetBase::INDEX_CODE;
1652 case LFUN_INDEX_PRINT:
1653 code = InsetBase::INDEX_PRINT_CODE;
1655 case LFUN_NOMENCL_INSERT:
1656 code = InsetBase::NOMENCL_CODE;
1658 case LFUN_NOMENCL_PRINT:
1659 code = InsetBase::NOMENCL_PRINT_CODE;
1661 case LFUN_TOC_INSERT:
1662 code = InsetBase::TOC_CODE;
1664 case LFUN_HTML_INSERT:
1665 case LFUN_URL_INSERT:
1666 code = InsetBase::URL_CODE;
1668 case LFUN_QUOTE_INSERT:
1669 // always allow this, since we will inset a raw quote
1670 // if an inset is not allowed.
1672 case LFUN_HYPHENATION_POINT_INSERT:
1673 case LFUN_LIGATURE_BREAK_INSERT:
1674 case LFUN_HFILL_INSERT:
1675 case LFUN_MENU_SEPARATOR_INSERT:
1676 case LFUN_DOTS_INSERT:
1677 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
1678 code = InsetBase::SPECIALCHAR_CODE;
1680 case LFUN_SPACE_INSERT:
1681 // slight hack: we know this is allowed in math mode
1683 code = InsetBase::SPACE_CODE;
1686 case LFUN_INSET_MODIFY:
1687 // We need to disable this, because we may get called for a
1689 // InsetTabular::getStatus() -> InsetText::getStatus()
1690 // and we don't handle LFUN_INSET_MODIFY.
1694 case LFUN_FONT_EMPH:
1695 flag.setOnOff(font.emph() == LyXFont::ON);
1698 case LFUN_FONT_NOUN:
1699 flag.setOnOff(font.noun() == LyXFont::ON);
1702 case LFUN_FONT_BOLD:
1703 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
1706 case LFUN_FONT_SANS:
1707 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
1710 case LFUN_FONT_ROMAN:
1711 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
1714 case LFUN_FONT_CODE:
1715 flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
1720 enable = cur.selection();
1724 enable = cap::numberOfSelections() > 0;
1727 case LFUN_PARAGRAPH_MOVE_UP:
1728 enable = cur.pit() > 0 && !cur.selection();
1731 case LFUN_PARAGRAPH_MOVE_DOWN:
1732 enable = cur.pit() < cur.lastpit() && !cur.selection();
1735 case LFUN_INSET_DISSOLVE:
1736 enable = !isMainText(*cur.bv().buffer()) && cur.inset().nargs() == 1;
1739 case LFUN_CHANGE_ACCEPT:
1740 case LFUN_CHANGE_REJECT:
1741 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
1742 // In principle, these LFUNs should only be enabled if there
1743 // is a change at the current position/in the current selection.
1744 // However, without proper optimizations, this will inevitably
1745 // result in unacceptable performance - just imagine a user who
1746 // wants to select the complete content of a long document.
1750 case LFUN_WORD_DELETE_FORWARD:
1751 case LFUN_WORD_DELETE_BACKWARD:
1752 case LFUN_LINE_DELETE:
1753 case LFUN_WORD_FORWARD:
1754 case LFUN_WORD_BACKWARD:
1755 case LFUN_CHAR_FORWARD:
1756 case LFUN_CHAR_FORWARD_SELECT:
1757 case LFUN_CHAR_BACKWARD:
1758 case LFUN_CHAR_BACKWARD_SELECT:
1760 case LFUN_UP_SELECT:
1762 case LFUN_DOWN_SELECT:
1763 case LFUN_PARAGRAPH_UP_SELECT:
1764 case LFUN_PARAGRAPH_DOWN_SELECT:
1765 case LFUN_SCREEN_UP_SELECT:
1766 case LFUN_SCREEN_DOWN_SELECT:
1767 case LFUN_LINE_BEGIN_SELECT:
1768 case LFUN_LINE_END_SELECT:
1769 case LFUN_WORD_FORWARD_SELECT:
1770 case LFUN_WORD_BACKWARD_SELECT:
1771 case LFUN_WORD_SELECT:
1772 case LFUN_PARAGRAPH_UP:
1773 case LFUN_PARAGRAPH_DOWN:
1774 case LFUN_SCREEN_UP:
1775 case LFUN_SCREEN_DOWN:
1776 case LFUN_LINE_BEGIN:
1778 case LFUN_BREAK_LINE:
1779 case LFUN_CHAR_DELETE_FORWARD:
1780 case LFUN_DELETE_FORWARD_SKIP:
1781 case LFUN_CHAR_DELETE_BACKWARD:
1782 case LFUN_DELETE_BACKWARD_SKIP:
1783 case LFUN_BREAK_PARAGRAPH:
1784 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
1785 case LFUN_BREAK_PARAGRAPH_SKIP:
1786 case LFUN_PARAGRAPH_SPACING:
1787 case LFUN_INSET_INSERT:
1788 case LFUN_WORD_UPCASE:
1789 case LFUN_WORD_LOWCASE:
1790 case LFUN_WORD_CAPITALIZE:
1791 case LFUN_CHARS_TRANSPOSE:
1792 case LFUN_SERVER_GET_XY:
1793 case LFUN_SERVER_SET_XY:
1794 case LFUN_SERVER_GET_FONT:
1795 case LFUN_SERVER_GET_LAYOUT:
1797 case LFUN_CLIPBOARD_PASTE:
1798 case LFUN_PRIMARY_SELECTION_PASTE:
1799 case LFUN_DATE_INSERT:
1800 case LFUN_SELF_INSERT:
1801 case LFUN_LINE_INSERT:
1802 case LFUN_PAGEBREAK_INSERT:
1803 case LFUN_CLEARPAGE_INSERT:
1804 case LFUN_CLEARDOUBLEPAGE_INSERT:
1805 case LFUN_MATH_DISPLAY:
1806 case LFUN_MATH_IMPORT_SELECTION:
1807 case LFUN_MATH_MODE:
1808 case LFUN_MATH_MACRO:
1809 case LFUN_MATH_MATRIX:
1810 case LFUN_MATH_DELIM:
1811 case LFUN_MATH_BIGDELIM:
1812 case LFUN_MATH_SUBSCRIPT:
1813 case LFUN_MATH_SUPERSCRIPT:
1814 case LFUN_FONT_DEFAULT:
1815 case LFUN_FONT_UNDERLINE:
1816 case LFUN_FONT_SIZE:
1818 case LFUN_FONT_FREE_APPLY:
1819 case LFUN_FONT_FREE_UPDATE:
1820 case LFUN_LAYOUT_PARAGRAPH:
1821 case LFUN_PARAGRAPH_UPDATE:
1822 case LFUN_ACCENT_UMLAUT:
1823 case LFUN_ACCENT_CIRCUMFLEX:
1824 case LFUN_ACCENT_GRAVE:
1825 case LFUN_ACCENT_ACUTE:
1826 case LFUN_ACCENT_TILDE:
1827 case LFUN_ACCENT_CEDILLA:
1828 case LFUN_ACCENT_MACRON:
1829 case LFUN_ACCENT_DOT:
1830 case LFUN_ACCENT_UNDERDOT:
1831 case LFUN_ACCENT_UNDERBAR:
1832 case LFUN_ACCENT_CARON:
1833 case LFUN_ACCENT_SPECIAL_CARON:
1834 case LFUN_ACCENT_BREVE:
1835 case LFUN_ACCENT_TIE:
1836 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1837 case LFUN_ACCENT_CIRCLE:
1838 case LFUN_ACCENT_OGONEK:
1839 case LFUN_THESAURUS_ENTRY:
1840 case LFUN_PARAGRAPH_PARAMS_APPLY:
1842 case LFUN_BUFFER_END:
1843 case LFUN_BUFFER_BEGIN:
1844 case LFUN_BUFFER_BEGIN_SELECT:
1845 case LFUN_BUFFER_END_SELECT:
1846 case LFUN_UNICODE_INSERT:
1847 // these are handled in our dispatch()
1855 if (code != InsetBase::NO_CODE
1856 && (cur.empty() || !cur.inset().insetAllowed(code)))
1859 flag.enabled(enable);
1864 void LyXText::pasteString(LCursor & cur, docstring const & clip,
1865 docstring const & argument)
1867 cur.clearSelection();
1868 if (!clip.empty()) {
1870 if (argument == "paragraph")
1871 insertStringAsParagraphs(cur, clip);
1873 insertStringAsLines(cur, clip);