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.
21 #include "BranchList.h"
22 #include "FloatList.h"
23 #include "FuncStatus.h"
25 #include "buffer_funcs.h"
26 #include "BufferParams.h"
27 #include "BufferView.h"
28 #include "bufferview_funcs.h"
30 #include "CutAndPaste.h"
32 #include "DispatchResult.h"
33 #include "ErrorList.h"
35 #include "FuncRequest.h"
39 #include "LyXAction.h"
43 #include "Paragraph.h"
44 #include "paragraph_funcs.h"
45 #include "ParagraphParameters.h"
48 #include "ParIterator.h"
50 #include "frontends/Clipboard.h"
51 #include "frontends/Selection.h"
53 #include "insets/InsetCommand.h"
54 #include "insets/InsetFloatList.h"
55 #include "insets/InsetNewline.h"
56 #include "insets/InsetQuotes.h"
57 #include "insets/InsetSpecialChar.h"
58 #include "insets/InsetText.h"
60 #include "support/lstrings.h"
61 #include "support/lyxlib.h"
62 #include "support/convert.h"
63 #include "support/lyxtime.h"
65 #include "mathed/InsetMathHull.h"
66 #include "mathed/MathMacroTemplate.h"
68 #include <boost/current_function.hpp>
75 using std::istringstream;
76 using std::ostringstream;
80 using cap::copySelection;
81 using cap::cutSelection;
82 using cap::pasteFromStack;
83 using cap::pasteClipboard;
84 using cap::replaceSelection;
86 using support::isStrUnsignedInt;
90 extern docstring current_layout;
96 Font freefont(Font::ALL_IGNORE);
97 bool toggleall = false;
99 void toggleAndShow(Cursor & cur, Text * text,
100 Font const & font, bool toggleall = true)
102 text->toggleFree(cur, font, toggleall);
104 if (font.language() != ignore_language ||
105 font.number() != Font::IGNORE) {
106 TextMetrics const & tm = cur.bv().textMetrics(text);
107 if (cur.boundary() != tm.isRTLBoundary(cur.pit(),
108 cur.pos(), cur.real_current_font))
109 text->setCursor(cur, cur.pit(), cur.pos(),
110 false, !cur.boundary());
115 void moveCursor(Cursor & cur, bool selecting)
117 if (selecting || cur.mark())
122 void finishChange(Cursor & cur, bool selecting)
125 moveCursor(cur, selecting);
129 void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
132 docstring sel = cur.selectionAsString(false);
134 // It may happen that sel is empty but there is a selection
135 replaceSelection(cur);
138 #ifdef ENABLE_ASSERTIONS
139 const int old_pos = cur.pos();
141 cur.insert(new InsetMathHull(hullSimple));
142 BOOST_ASSERT(old_pos == cur.pos());
143 cur.nextInset()->edit(cur, true);
144 // don't do that also for LFUN_MATH_MODE
145 // unless you want end up with always changing
146 // to mathrm when opening an inlined inset --
147 // I really hate "LyXfunc overloading"...
149 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
150 // Avoid an unnecessary undo step if cmd.argument
152 if (!cmd.argument().empty())
153 cur.dispatch(FuncRequest(LFUN_MATH_INSERT,
156 // create a macro if we see "\\newcommand"
157 // somewhere, and an ordinary formula
159 if (sel.find(from_ascii("\\newcommand")) == string::npos
160 && sel.find(from_ascii("\\def")) == string::npos)
162 InsetMathHull * formula = new InsetMathHull;
163 istringstream is(to_utf8(sel));
166 formula->read(cur.buffer(), lex);
167 if (formula->getType() == hullNone)
168 // Don't create pseudo formulas if
169 // delimiters are left out
170 formula->mutate(hullSimple);
173 cur.insert(new MathMacroTemplate(sel));
176 cur.message(from_utf8(N_("Math editor mode")));
185 string const freefont2string()
188 if (font2string(freefont, toggleall, data))
198 void specialChar(Cursor & cur, InsetSpecialChar::Kind kind)
201 cap::replaceSelection(cur);
202 cur.insert(new InsetSpecialChar(kind));
207 bool doInsertInset(Cursor & cur, Text * text,
208 FuncRequest const & cmd, bool edit, bool pastesel)
210 Inset * inset = createInset(&cur.bv(), cmd);
216 if (cur.selection()) {
217 lyx::dispatch(FuncRequest(LFUN_CUT));
220 text->insertInset(cur, inset);
223 inset->edit(cur, true);
225 if (gotsel && pastesel) {
226 lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
227 // reset first par to default
228 if (cur.lastpit() != 0 || cur.lastpos() != 0) {
229 LayoutPtr const layout =
230 cur.buffer().params().getTextClass().defaultLayout();
231 cur.text()->paragraphs().begin()->layout(layout);
241 void Text::number(Cursor & cur)
243 Font font(Font::ALL_IGNORE);
244 font.setNumber(Font::TOGGLE);
245 toggleAndShow(cur, this, font);
249 bool Text::isRTL(Buffer const & buffer, Paragraph const & par) const
251 return par.isRTL(buffer.params());
255 void Text::dispatch(Cursor & cur, FuncRequest & cmd)
257 LYXERR(Debug::ACTION) << "Text::dispatch: cmd: " << cmd << endl;
259 // FIXME: We use the update flag to indicates wether a singlePar or a
260 // full screen update is needed. We reset it here but shall we restore it
264 BOOST_ASSERT(cur.text() == this);
265 BufferView * bv = &cur.bv();
266 TextMetrics & tm = cur.bv().textMetrics(this);
267 CursorSlice oldTopSlice = cur.top();
268 bool oldBoundary = cur.boundary();
269 bool sel = cur.selection();
270 // Signals that, even if needsUpdate == false, an update of the
271 // cursor paragraph is required
272 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
273 LyXAction::SingleParUpdate);
274 // Signals that a full-screen update is required
275 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
276 LyXAction::NoUpdate) || singleParUpdate);
277 // Remember the old paragraph metric (_outer_ paragraph!)
278 ParagraphMetrics const & pm = cur.bv().parMetrics(
279 cur.bottom().text(), cur.bottom().pit());
280 Dimension olddim = pm.dim();
282 switch (cmd.action) {
284 case LFUN_PARAGRAPH_MOVE_DOWN: {
285 pit_type const pit = cur.pit();
286 recUndo(cur, pit, pit + 1);
288 std::swap(pars_[pit], pars_[pit + 1]);
289 updateLabels(cur.buffer());
295 case LFUN_PARAGRAPH_MOVE_UP: {
296 pit_type const pit = cur.pit();
297 recUndo(cur, pit - 1, pit);
299 std::swap(pars_[pit], pars_[pit - 1]);
300 updateLabels(cur.buffer());
306 case LFUN_APPENDIX: {
307 Paragraph & par = cur.paragraph();
308 bool start = !par.params().startOfAppendix();
310 // FIXME: The code below only makes sense at top level.
311 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
312 // ensure that we have only one start_of_appendix in this document
313 // FIXME: this don't work for multipart document!
314 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
315 if (pars_[tmp].params().startOfAppendix()) {
317 pars_[tmp].params().startOfAppendix(false);
323 par.params().startOfAppendix(start);
325 // we can set the refreshing parameters now
326 updateLabels(cur.buffer());
330 case LFUN_WORD_DELETE_FORWARD:
331 if (cur.selection()) {
332 cutSelection(cur, true, false);
334 deleteWordForward(cur);
335 finishChange(cur, false);
338 case LFUN_WORD_DELETE_BACKWARD:
339 if (cur.selection()) {
340 cutSelection(cur, true, false);
342 deleteWordBackward(cur);
343 finishChange(cur, false);
346 case LFUN_LINE_DELETE:
347 if (cur.selection()) {
348 cutSelection(cur, true, false);
350 tm.deleteLineForward(cur);
351 finishChange(cur, false);
354 case LFUN_BUFFER_BEGIN:
355 case LFUN_BUFFER_BEGIN_SELECT:
356 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
357 if (cur.depth() == 1) {
358 needsUpdate |= cursorTop(cur);
364 case LFUN_BUFFER_END:
365 case LFUN_BUFFER_END_SELECT:
366 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
367 if (cur.depth() == 1) {
368 needsUpdate |= cursorBottom(cur);
374 case LFUN_CHAR_FORWARD:
375 case LFUN_CHAR_FORWARD_SELECT:
376 //lyxerr << BOOST_CURRENT_FUNCTION
377 // << " LFUN_CHAR_FORWARD[SEL]:\n" << cur << endl;
378 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
379 if (reverseDirectionNeeded(cur))
380 needsUpdate |= cursorLeft(cur);
382 needsUpdate |= cursorRight(cur);
384 if (!needsUpdate && oldTopSlice == cur.top()
385 && cur.boundary() == oldBoundary) {
387 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
391 case LFUN_CHAR_BACKWARD:
392 case LFUN_CHAR_BACKWARD_SELECT:
393 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
394 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
395 if (reverseDirectionNeeded(cur))
396 needsUpdate |= cursorRight(cur);
398 needsUpdate |= cursorLeft(cur);
400 if (!needsUpdate && oldTopSlice == cur.top()
401 && cur.boundary() == oldBoundary) {
403 cmd = FuncRequest(LFUN_FINISHED_LEFT);
408 case LFUN_DOWN_SELECT:
411 // stop/start the selection
412 bool select = cmd.action == LFUN_DOWN_SELECT ||
413 cmd.action == LFUN_UP_SELECT;
414 cur.selHandle(select);
416 // move cursor up/down
417 bool up = cmd.action == LFUN_UP_SELECT || cmd.action == LFUN_UP;
418 bool const successful = cur.upDownInText(up, needsUpdate);
420 // notify insets which were left and get their update flags
421 notifyCursorLeaves(cur.beforeDispatchCursor(), cur);
424 // redraw if you leave mathed (for the decorations)
425 needsUpdate |= cur.beforeDispatchCursor().inMathed();
432 case LFUN_PARAGRAPH_UP:
433 case LFUN_PARAGRAPH_UP_SELECT:
434 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
435 needsUpdate |= cursorUpParagraph(cur);
438 case LFUN_PARAGRAPH_DOWN:
439 case LFUN_PARAGRAPH_DOWN_SELECT:
440 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
441 needsUpdate |= cursorDownParagraph(cur);
444 case LFUN_SCREEN_UP_SELECT:
445 needsUpdate |= cur.selHandle(true);
446 if (cur.pit() == 0 && cur.textRow().pos() == 0)
449 tm.cursorPrevious(cur);
453 case LFUN_SCREEN_DOWN_SELECT:
454 needsUpdate |= cur.selHandle(true);
455 if (cur.pit() == cur.lastpit()
456 && cur.textRow().endpos() == cur.lastpos())
463 case LFUN_LINE_BEGIN:
464 case LFUN_LINE_BEGIN_SELECT:
465 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
466 needsUpdate |= tm.cursorHome(cur);
470 case LFUN_LINE_END_SELECT:
471 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
472 needsUpdate |= tm.cursorEnd(cur);
475 case LFUN_WORD_FORWARD:
476 case LFUN_WORD_FORWARD_SELECT:
477 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
478 if (reverseDirectionNeeded(cur))
479 needsUpdate |= cursorLeftOneWord(cur);
481 needsUpdate |= cursorRightOneWord(cur);
484 case LFUN_WORD_BACKWARD:
485 case LFUN_WORD_BACKWARD_SELECT:
486 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
487 if (reverseDirectionNeeded(cur))
488 needsUpdate |= cursorRightOneWord(cur);
490 needsUpdate |= cursorLeftOneWord(cur);
493 case LFUN_WORD_SELECT: {
494 selectWord(cur, WHOLE_WORD);
495 finishChange(cur, true);
499 case LFUN_BREAK_LINE: {
500 // Not allowed by LaTeX (labels or empty par)
501 if (cur.pos() > cur.paragraph().beginOfBody()) {
502 // this avoids a double undo
503 // FIXME: should not be needed, ideally
504 if (!cur.selection())
506 cap::replaceSelection(cur);
507 cur.insert(new InsetNewline);
509 moveCursor(cur, false);
514 case LFUN_CHAR_DELETE_FORWARD:
515 if (!cur.selection()) {
516 if (cur.pos() == cur.paragraph().size())
517 // Par boundary, force full-screen update
518 singleParUpdate = false;
519 needsUpdate |= erase(cur);
521 // It is possible to make it a lot faster still
522 // just comment out the line below...
524 cutSelection(cur, true, false);
525 singleParUpdate = false;
527 moveCursor(cur, false);
530 case LFUN_DELETE_FORWARD_SKIP:
531 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
532 if (!cur.selection()) {
533 if (cur.pos() == cur.lastpos()) {
540 cutSelection(cur, true, false);
545 case LFUN_CHAR_DELETE_BACKWARD:
546 if (!cur.selection()) {
547 if (bv->getIntl().getTransManager().backspace()) {
548 // Par boundary, full-screen update
550 singleParUpdate = false;
551 needsUpdate |= backspace(cur);
553 // It is possible to make it a lot faster still
554 // just comment out the line below...
557 cutSelection(cur, true, false);
558 singleParUpdate = false;
562 case LFUN_DELETE_BACKWARD_SKIP:
563 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
564 if (!cur.selection()) {
566 //CursorSlice cur = cursor();
570 cutSelection(cur, true, false);
574 case LFUN_BREAK_PARAGRAPH:
575 cap::replaceSelection(cur);
576 breakParagraph(cur, false);
580 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
581 cap::replaceSelection(cur);
582 breakParagraph(cur, true);
586 case LFUN_BREAK_PARAGRAPH_SKIP: {
587 // When at the beginning of a paragraph, remove
588 // indentation. Otherwise, do the same as LFUN_BREAK_PARAGRAPH.
589 cap::replaceSelection(cur);
591 cur.paragraph().params().labelWidthString(docstring());
593 breakParagraph(cur, false);
599 // With the creation of LFUN_PARAGRAPH_PARAMS, this is now redundant,
600 // as its duties can be performed there. Should it be removed??
601 // FIXME For now, it can just dispatch LFUN_PARAGRAPH_PARAMS...
602 case LFUN_PARAGRAPH_SPACING: {
603 Paragraph & par = cur.paragraph();
604 Spacing::Space cur_spacing = par.params().spacing().getSpace();
605 string cur_value = "1.0";
606 if (cur_spacing == Spacing::Other)
607 cur_value = par.params().spacing().getValueAsString();
609 istringstream is(to_utf8(cmd.argument()));
612 Spacing::Space new_spacing = cur_spacing;
613 string new_value = cur_value;
615 lyxerr << "Missing argument to `paragraph-spacing'"
617 } else if (tmp == "single") {
618 new_spacing = Spacing::Single;
619 } else if (tmp == "onehalf") {
620 new_spacing = Spacing::Onehalf;
621 } else if (tmp == "double") {
622 new_spacing = Spacing::Double;
623 } else if (tmp == "other") {
624 new_spacing = Spacing::Other;
625 string tmpval = "0.0";
627 lyxerr << "new_value = " << tmpval << endl;
630 } else if (tmp == "default") {
631 new_spacing = Spacing::Default;
633 lyxerr << to_utf8(_("Unknown spacing argument: "))
634 << to_utf8(cmd.argument()) << endl;
636 if (cur_spacing != new_spacing || cur_value != new_value)
637 par.params().spacing(Spacing(new_spacing, new_value));
641 case LFUN_INSET_INSERT: {
643 Inset * inset = createInset(bv, cmd);
645 // FIXME (Abdel 01/02/2006):
646 // What follows would be a partial fix for bug 2154:
647 // http://bugzilla.lyx.org/show_bug.cgi?id=2154
648 // This automatically put the label inset _after_ a
649 // numbered section. It should be possible to extend the mechanism
650 // to any kind of LateX environement.
651 // The correct way to fix that bug would be at LateX generation.
652 // I'll let the code here for reference as it could be used for some
653 // other feature like "automatic labelling".
655 Paragraph & par = pars_[cur.pit()];
656 if (inset->lyxCode() == Inset::LABEL_CODE
657 && par.layout()->labeltype == LABEL_COUNTER) {
658 // Go to the end of the paragraph
659 // Warning: Because of Change-Tracking, the last
660 // position is 'size()' and not 'size()-1':
661 cur.pos() = par.size();
662 // Insert a new paragraph
663 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
668 cutSelection(cur, true, false);
669 insertInset(cur, inset);
675 case LFUN_INSET_DISSOLVE:
676 needsUpdate |= dissolveInset(cur);
679 case LFUN_INSET_SETTINGS:
680 cur.inset().showInsetDialog(bv);
683 case LFUN_SPACE_INSERT:
684 if (cur.paragraph().layout()->free_spacing)
685 insertChar(cur, ' ');
687 doInsertInset(cur, this, cmd, false, false);
690 moveCursor(cur, false);
693 case LFUN_HYPHENATION_POINT_INSERT:
694 specialChar(cur, InsetSpecialChar::HYPHENATION);
697 case LFUN_LIGATURE_BREAK_INSERT:
698 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
701 case LFUN_DOTS_INSERT:
702 specialChar(cur, InsetSpecialChar::LDOTS);
705 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
706 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
709 case LFUN_MENU_SEPARATOR_INSERT:
710 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
713 case LFUN_WORD_UPCASE:
714 changeCase(cur, Text::text_uppercase);
717 case LFUN_WORD_LOWCASE:
718 changeCase(cur, Text::text_lowercase);
721 case LFUN_WORD_CAPITALIZE:
722 changeCase(cur, Text::text_capitalization);
725 case LFUN_CHARS_TRANSPOSE:
730 cur.message(_("Paste"));
731 cap::replaceSelection(cur);
732 if (cmd.argument().empty() && !theClipboard().isInternal())
733 pasteClipboard(cur, bv->buffer().errorList("Paste"));
735 string const arg(to_utf8(cmd.argument()));
736 pasteFromStack(cur, bv->buffer().errorList("Paste"),
737 isStrUnsignedInt(arg) ?
738 convert<unsigned int>(arg) :
741 bv->buffer().errors("Paste");
742 cur.clearSelection(); // bug 393
747 cutSelection(cur, true, true);
748 cur.message(_("Cut"));
753 cur.message(_("Copy"));
756 case LFUN_SERVER_GET_XY:
757 cur.message(from_utf8(
758 convert<string>(tm.cursorX(cur.top(), cur.boundary()))
759 + ' ' + convert<string>(tm.cursorY(cur.top(), cur.boundary()))));
762 case LFUN_SERVER_SET_XY: {
765 istringstream is(to_utf8(cmd.argument()));
768 lyxerr << "SETXY: Could not parse coordinates in '"
769 << to_utf8(cmd.argument()) << std::endl;
771 tm.setCursorFromCoordinates(cur, x, y);
775 case LFUN_SERVER_GET_FONT:
776 if (cur.current_font.shape() == Font::ITALIC_SHAPE)
777 cur.message(from_ascii("E"));
778 else if (cur.current_font.shape() == Font::SMALLCAPS_SHAPE)
779 cur.message(from_ascii("N"));
781 cur.message(from_ascii("0"));
784 case LFUN_SERVER_GET_LAYOUT:
785 cur.message(cur.paragraph().layout()->name());
789 docstring layout = cmd.argument();
790 LYXERR(Debug::INFO) << "LFUN_LAYOUT: (arg) " << to_utf8(layout) << endl;
792 // Derive layout number from given argument (string)
793 // and current buffer's textclass (number)
794 TextClass const & tclass = bv->buffer().params().getTextClass();
796 layout = tclass.defaultLayoutName();
797 bool hasLayout = tclass.hasLayout(layout);
799 // If the entry is obsolete, use the new one instead.
801 docstring const & obs = tclass[layout]->obsoleted_by();
807 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
808 from_utf8(N_(" not known")));
812 bool change_layout = (frontend::current_layout != layout);
814 if (!change_layout && cur.selection() &&
815 cur.selBegin().pit() != cur.selEnd().pit())
817 pit_type spit = cur.selBegin().pit();
818 pit_type epit = cur.selEnd().pit() + 1;
819 while (spit != epit) {
820 if (pars_[spit].layout()->name() != frontend::current_layout) {
821 change_layout = true;
829 setLayout(cur, layout);
830 // inform the GUI that the layout has changed.
831 bv->layoutChanged(layout);
836 case LFUN_CLIPBOARD_PASTE:
837 cur.clearSelection();
838 pasteClipboard(cur, bv->buffer().errorList("Paste"),
839 cmd.argument() == "paragraph");
840 bv->buffer().errors("Paste");
843 case LFUN_PRIMARY_SELECTION_PASTE:
844 pasteString(cur, theSelection().get(),
845 cmd.argument() == "paragraph");
848 case LFUN_UNICODE_INSERT: {
849 if (cmd.argument().empty())
851 docstring hexstring = cmd.argument();
852 if (lyx::support::isHex(hexstring)) {
853 char_type c = lyx::support::hexToInt(hexstring);
854 if (c >= 32 && c < 0x10ffff) {
855 lyxerr << "Inserting c: " << c << endl;
856 docstring s = docstring(1, c);
857 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
863 case LFUN_QUOTE_INSERT: {
864 Paragraph & par = cur.paragraph();
865 pos_type pos = cur.pos();
866 BufferParams const & bufparams = bv->buffer().params();
867 LayoutPtr const & style = par.layout();
868 if (!style->pass_thru
869 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
870 // this avoids a double undo
871 // FIXME: should not be needed, ideally
872 if (!cur.selection())
874 cap::replaceSelection(cur);
879 else if (cur.prevInset() && cur.prevInset()->isSpace())
882 c = par.getChar(pos - 1);
883 string arg = to_utf8(cmd.argument());
885 cur.insert(new InsetQuotes(c,
886 bufparams.quotes_language,
887 InsetQuotes::SingleQ));
889 cur.insert(new InsetQuotes(c,
890 bufparams.quotes_language,
891 InsetQuotes::DoubleQ));
895 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
899 case LFUN_DATE_INSERT: {
900 string const format = cmd.argument().empty()
901 ? lyxrc.date_insert_format : to_utf8(cmd.argument());
902 string const time = formatted_time(current_time(), format);
903 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, time));
907 case LFUN_MOUSE_TRIPLE:
908 if (cmd.button() == mouse_button::button1) {
917 case LFUN_MOUSE_DOUBLE:
918 if (cmd.button() == mouse_button::button1) {
919 selectWord(cur, WHOLE_WORD_STRICT);
924 // Single-click on work area
925 case LFUN_MOUSE_PRESS: {
926 // Right click on a footnote flag opens float menu
927 if (cmd.button() == mouse_button::button3)
928 cur.clearSelection();
931 bool update = bv->mouseSetCursor(cur);
933 // Insert primary selection with middle mouse
934 // if there is a local selection in the current buffer,
936 if (cmd.button() == mouse_button::button2) {
937 if (cap::selection()) {
938 // Copy the selection buffer to the clipboard
939 // stack, because we want it to appear in the
940 // "Edit->Paste recent" menu.
941 cap::copySelectionToStack();
943 cap::pasteSelection(bv->cursor(),
944 bv->buffer().errorList("Paste"));
945 bv->buffer().errors("Paste");
946 bv->buffer().markDirty();
949 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
953 // we have to update after dEPM triggered
954 if (!update && cmd.button() == mouse_button::button1) {
962 case LFUN_MOUSE_MOTION: {
963 // Only use motion with button 1
964 //if (cmd.button() != mouse_button::button1)
967 // ignore motions deeper nested than the real anchor
968 Cursor & bvcur = cur.bv().cursor();
969 if (bvcur.anchor_.hasPart(cur)) {
970 CursorSlice old = bvcur.top();
972 int const wh = bv->workHeight();
973 int const y = std::max(0, std::min(wh - 1, cmd.y));
975 tm.setCursorFromCoordinates(cur, cmd.x, y);
976 cur.setTargetX(cmd.x);
978 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
980 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
981 // This is to allow jumping over large insets
982 if (cur.top() == old) {
984 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
986 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
989 if (cur.top() == old)
993 bvcur.setCursor(cur);
994 bvcur.selection() = true;
995 //lyxerr << "MOTION: " << bv->cursor() << endl;
1003 case LFUN_MOUSE_RELEASE: {
1004 if (cmd.button() == mouse_button::button2)
1007 if (cmd.button() == mouse_button::button1) {
1008 // if there is new selection, update persistent
1009 // selection, otherwise, single click does not
1010 // clear persistent selection buffer
1011 if (cur.selection()) {
1013 // if double click, cur is moved to the end of word by selectWord
1014 // but bvcur is current mouse position
1015 Cursor & bvcur = cur.bv().cursor();
1016 bvcur.selection() = true;
1018 needsUpdate = false;
1025 case LFUN_SELF_INSERT: {
1026 if (cmd.argument().empty())
1029 // Automatically delete the currently selected
1030 // text and replace it with what is being
1031 // typed in now. Depends on lyxrc settings
1032 // "auto_region_delete", which defaults to
1035 if (lyxrc.auto_region_delete && cur.selection()) {
1036 cutSelection(cur, false, false);
1037 // When change tracking is set to off, the metrics update
1038 // mechanism correctly detects if a full update is needed or not.
1039 // This detection fails when a selection spans multiple rows and
1040 // change tracking is enabled because the paragraph metrics stays
1041 // the same. In this case, we force the full update:
1042 // (see http://bugzilla.lyx.org/show_bug.cgi?id=3992)
1043 if (cur.buffer().params().trackChanges)
1044 cur.updateFlags(Update::Force);
1047 cur.clearSelection();
1048 Font const old_font = cur.real_current_font;
1050 docstring::const_iterator cit = cmd.argument().begin();
1051 docstring::const_iterator end = cmd.argument().end();
1052 for (; cit != end; ++cit)
1053 bv->translateAndInsert(*cit, this, cur);
1056 moveCursor(cur, false);
1060 case LFUN_URL_INSERT: {
1061 InsetCommandParams p("url");
1063 if (cur.selection()) {
1064 content = cur.selectionAsString(false);
1065 cutSelection(cur, true, false);
1067 p["target"] = (cmd.argument().empty()) ?
1068 content : cmd.argument();
1069 string const data = InsetCommandMailer::params2string("url", p);
1070 if (p["target"].empty()) {
1071 bv->showInsetDialog("url", data, 0);
1073 FuncRequest fr(LFUN_INSET_INSERT, data);
1079 case LFUN_HTML_INSERT: {
1080 InsetCommandParams p("htmlurl");
1082 if (cur.selection()) {
1083 content = cur.selectionAsString(false);
1084 cutSelection(cur, true, false);
1086 p["target"] = (cmd.argument().empty()) ?
1087 content : cmd.argument();
1088 string const data = InsetCommandMailer::params2string("url", p);
1089 if (p["target"].empty()) {
1090 bv->showInsetDialog("url", data, 0);
1092 FuncRequest fr(LFUN_INSET_INSERT, data);
1098 case LFUN_LABEL_INSERT: {
1099 InsetCommandParams p("label");
1100 // Try to generate a valid label
1101 p["name"] = (cmd.argument().empty()) ?
1102 cur.getPossibleLabel() :
1104 string const data = InsetCommandMailer::params2string("label", p);
1106 if (cmd.argument().empty()) {
1107 bv->showInsetDialog("label", data, 0);
1109 FuncRequest fr(LFUN_INSET_INSERT, data);
1117 case LFUN_LIST_INSERT:
1118 case LFUN_THEOREM_INSERT:
1120 case LFUN_CAPTION_INSERT:
1121 // Open the inset, and move the current selection
1123 doInsertInset(cur, this, cmd, true, true);
1125 updateLabels(bv->buffer());
1127 case LFUN_NOTE_INSERT:
1128 case LFUN_FLEX_INSERT:
1129 case LFUN_BOX_INSERT:
1130 case LFUN_BRANCH_INSERT:
1131 case LFUN_BIBITEM_INSERT:
1132 case LFUN_ERT_INSERT:
1133 case LFUN_LISTING_INSERT:
1134 case LFUN_FOOTNOTE_INSERT:
1135 case LFUN_MARGINALNOTE_INSERT:
1136 case LFUN_OPTIONAL_INSERT:
1137 case LFUN_ENVIRONMENT_INSERT:
1138 // Open the inset, and move the current selection
1140 doInsertInset(cur, this, cmd, true, true);
1144 case LFUN_TABULAR_INSERT:
1145 // if there were no arguments, just open the dialog
1146 if (doInsertInset(cur, this, cmd, false, true))
1149 bv->showDialog("tabularcreate");
1153 case LFUN_FLOAT_INSERT:
1154 case LFUN_FLOAT_WIDE_INSERT:
1155 case LFUN_WRAP_INSERT: {
1156 bool content = cur.selection(); // will some text be moved into the inset?
1158 doInsertInset(cur, this, cmd, true, true);
1160 ParagraphList & pars = cur.text()->paragraphs();
1162 TextClass const & tclass = bv->buffer().params().getTextClass();
1164 // add a separate paragraph for the caption inset
1165 pars.push_back(Paragraph());
1166 pars.back().setInsetOwner(pars[0].inInset());
1167 pars.back().layout(tclass.defaultLayout());
1169 int cap_pit = pars.size() - 1;
1171 // if an empty inset was created, we create an additional empty
1172 // paragraph at the bottom so that the user can choose where to put
1173 // the graphics (or table).
1175 pars.push_back(Paragraph());
1176 pars.back().setInsetOwner(pars[0].inInset());
1177 pars.back().layout(tclass.defaultLayout());
1181 // reposition the cursor to the caption
1182 cur.pit() = cap_pit;
1184 // FIXME: This Text/Cursor dispatch handling is a mess!
1185 // We cannot use Cursor::dispatch here it needs access to up to
1187 FuncRequest cmd_caption(LFUN_CAPTION_INSERT);
1188 cur.text()->dispatch(cur, cmd_caption);
1189 cur.updateFlags(Update::Force);
1190 // FIXME: When leaving the Float (or Wrap) inset we should
1191 // delete any empty paragraph left above or below the
1196 case LFUN_INDEX_INSERT:
1197 case LFUN_NOMENCL_INSERT: {
1198 Inset * inset = createInset(&cur.bv(), cmd);
1202 cur.clearSelection();
1203 insertInset(cur, inset);
1204 // Show the dialog for the nomenclature entry, since the
1205 // description entry still needs to be filled in.
1206 if (cmd.action == LFUN_NOMENCL_INSERT)
1207 inset->edit(cur, true);
1212 case LFUN_INDEX_PRINT:
1213 case LFUN_NOMENCL_PRINT:
1214 case LFUN_TOC_INSERT:
1215 case LFUN_HFILL_INSERT:
1216 case LFUN_LINE_INSERT:
1217 case LFUN_PAGEBREAK_INSERT:
1218 case LFUN_CLEARPAGE_INSERT:
1219 case LFUN_CLEARDOUBLEPAGE_INSERT:
1221 doInsertInset(cur, this, cmd, false, false);
1225 case LFUN_DEPTH_DECREMENT:
1226 changeDepth(cur, DEC_DEPTH);
1229 case LFUN_DEPTH_INCREMENT:
1230 changeDepth(cur, INC_DEPTH);
1233 case LFUN_MATH_DISPLAY:
1234 mathDispatch(cur, cmd, true);
1237 case LFUN_MATH_IMPORT_SELECTION:
1238 case LFUN_MATH_MODE:
1239 if (cmd.argument() == "on")
1240 // don't pass "on" as argument
1241 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1243 mathDispatch(cur, cmd, false);
1246 case LFUN_MATH_MACRO:
1247 if (cmd.argument().empty())
1248 cur.errorMessage(from_utf8(N_("Missing argument")));
1250 string s = to_utf8(cmd.argument());
1251 string const s1 = token(s, ' ', 1);
1252 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1253 string const s2 = token(s, ' ', 2);
1254 string const type = s2.empty() ? "newcommand" : s2;
1255 cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, from_utf8(type)));
1256 //cur.nextInset()->edit(cur, true);
1260 // passthrough hat and underscore outside mathed:
1261 case LFUN_MATH_SUBSCRIPT:
1262 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1264 case LFUN_MATH_SUPERSCRIPT:
1265 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1268 case LFUN_MATH_INSERT:
1269 case LFUN_MATH_MATRIX:
1270 case LFUN_MATH_DELIM:
1271 case LFUN_MATH_BIGDELIM: {
1272 if (cur.selection())
1273 cur.clearSelection();
1274 // FIXME: instead of the above, this one
1275 // should be used (but it asserts with Bidi enabled)
1276 // cf. http://bugzilla.lyx.org/show_bug.cgi?id=4055
1277 // cap::replaceSelection(cur);
1278 cur.insert(new InsetMathHull(hullSimple));
1279 checkAndActivateInset(cur, true);
1280 BOOST_ASSERT(cur.inMathed());
1285 case LFUN_FONT_EMPH: {
1286 Font font(Font::ALL_IGNORE);
1287 font.setEmph(Font::TOGGLE);
1288 toggleAndShow(cur, this, font);
1292 case LFUN_FONT_BOLD: {
1293 Font font(Font::ALL_IGNORE);
1294 font.setSeries(Font::BOLD_SERIES);
1295 toggleAndShow(cur, this, font);
1299 case LFUN_FONT_NOUN: {
1300 Font font(Font::ALL_IGNORE);
1301 font.setNoun(Font::TOGGLE);
1302 toggleAndShow(cur, this, font);
1306 case LFUN_FONT_TYPEWRITER: {
1307 Font font(Font::ALL_IGNORE);
1308 font.setFamily(Font::TYPEWRITER_FAMILY); // no good
1309 toggleAndShow(cur, this, font);
1313 case LFUN_FONT_SANS: {
1314 Font font(Font::ALL_IGNORE);
1315 font.setFamily(Font::SANS_FAMILY);
1316 toggleAndShow(cur, this, font);
1320 case LFUN_FONT_ROMAN: {
1321 Font font(Font::ALL_IGNORE);
1322 font.setFamily(Font::ROMAN_FAMILY);
1323 toggleAndShow(cur, this, font);
1327 case LFUN_FONT_DEFAULT: {
1328 Font font(Font::ALL_INHERIT, ignore_language);
1329 toggleAndShow(cur, this, font);
1333 case LFUN_FONT_UNDERLINE: {
1334 Font font(Font::ALL_IGNORE);
1335 font.setUnderbar(Font::TOGGLE);
1336 toggleAndShow(cur, this, font);
1340 case LFUN_FONT_SIZE: {
1341 Font font(Font::ALL_IGNORE);
1342 font.setLyXSize(to_utf8(cmd.argument()));
1343 toggleAndShow(cur, this, font);
1347 case LFUN_LANGUAGE: {
1348 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1351 Font font(Font::ALL_IGNORE);
1352 font.setLanguage(lang);
1353 toggleAndShow(cur, this, font);
1357 case LFUN_FONT_FREE_APPLY:
1358 toggleAndShow(cur, this, freefont, toggleall);
1359 cur.message(_("Character set"));
1362 // Set the freefont using the contents of \param data dispatched from
1363 // the frontends and apply it at the current cursor location.
1364 case LFUN_FONT_FREE_UPDATE: {
1367 if (bv_funcs::string2font(to_utf8(cmd.argument()), font, toggle)) {
1370 toggleAndShow(cur, this, freefont, toggleall);
1371 cur.message(_("Character set"));
1376 case LFUN_FINISHED_LEFT:
1377 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1378 if (reverseDirectionNeeded(cur)) {
1380 cur.setCurrentFont();
1384 case LFUN_FINISHED_RIGHT:
1385 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1386 if (!reverseDirectionNeeded(cur)) {
1388 cur.setCurrentFont();
1392 case LFUN_LAYOUT_PARAGRAPH: {
1394 params2string(cur.paragraph(), data);
1395 data = "show\n" + data;
1396 bv->showDialogWithData("paragraph", data);
1400 case LFUN_PARAGRAPH_UPDATE: {
1402 params2string(cur.paragraph(), data);
1404 // Will the paragraph accept changes from the dialog?
1405 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1407 data = "update " + convert<string>(accept) + '\n' + data;
1408 bv->updateDialog("paragraph", data);
1412 case LFUN_ACCENT_UMLAUT:
1413 case LFUN_ACCENT_CIRCUMFLEX:
1414 case LFUN_ACCENT_GRAVE:
1415 case LFUN_ACCENT_ACUTE:
1416 case LFUN_ACCENT_TILDE:
1417 case LFUN_ACCENT_CEDILLA:
1418 case LFUN_ACCENT_MACRON:
1419 case LFUN_ACCENT_DOT:
1420 case LFUN_ACCENT_UNDERDOT:
1421 case LFUN_ACCENT_UNDERBAR:
1422 case LFUN_ACCENT_CARON:
1423 case LFUN_ACCENT_SPECIAL_CARON:
1424 case LFUN_ACCENT_BREVE:
1425 case LFUN_ACCENT_TIE:
1426 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1427 case LFUN_ACCENT_CIRCLE:
1428 case LFUN_ACCENT_OGONEK:
1429 theLyXFunc().handleKeyFunc(cmd.action);
1430 if (!cmd.argument().empty())
1431 // FIXME: Are all these characters encoded in one byte in utf8?
1432 bv->translateAndInsert(cmd.argument()[0], this, cur);
1435 case LFUN_FLOAT_LIST: {
1436 TextClass const & tclass = bv->buffer().params().getTextClass();
1437 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1439 if (cur.selection())
1440 cutSelection(cur, true, false);
1441 breakParagraph(cur);
1443 if (cur.lastpos() != 0) {
1445 breakParagraph(cur);
1448 setLayout(cur, tclass.defaultLayoutName());
1449 ParagraphParameters p;
1450 setParagraphs(cur, p);
1451 insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1454 lyxerr << "Non-existent float type: "
1455 << to_utf8(cmd.argument()) << endl;
1460 case LFUN_CHANGE_ACCEPT: {
1461 acceptOrRejectChanges(cur, ACCEPT);
1465 case LFUN_CHANGE_REJECT: {
1466 acceptOrRejectChanges(cur, REJECT);
1470 case LFUN_THESAURUS_ENTRY: {
1471 docstring arg = cmd.argument();
1473 arg = cur.selectionAsString(false);
1475 if (arg.size() > 100 || arg.empty()) {
1476 // Get word or selection
1477 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1478 arg = cur.selectionAsString(false);
1481 bv->showDialogWithData("thesaurus", to_utf8(arg));
1485 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1486 // Given data, an encoding of the ParagraphParameters
1487 // generated in the Paragraph dialog, this function sets
1488 // the current paragraph, or currently selected paragraphs,
1490 // NOTE: This function overrides all existing settings.
1491 setParagraphs(cur, cmd.argument());
1492 cur.message(_("Paragraph layout set"));
1496 case LFUN_PARAGRAPH_PARAMS: {
1497 // Given data, an encoding of the ParagraphParameters as we'd
1498 // find them in a LyX file, this function modifies the current paragraph,
1499 // or currently selected paragraphs.
1500 // NOTE: This function only modifies, and does not override, existing
1502 setParagraphs(cur, cmd.argument(), true);
1503 cur.message(_("Paragraph layout set"));
1508 if (cur.selection()) {
1509 cur.selection() = false;
1512 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1517 LYXERR(Debug::ACTION)
1518 << BOOST_CURRENT_FUNCTION
1519 << ": Command " << cmd
1520 << " not DISPATCHED by Text" << endl;
1525 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1527 // FIXME: The cursor flag is reset two lines below
1528 // so we need to check here if some of the LFUN did touch that.
1529 // for now only Text::erase() and Text::backspace() do that.
1530 // The plan is to verify all the LFUNs and then to remove this
1531 // singleParUpdate boolean altogether.
1532 if (cur.result().update() & Update::Force) {
1533 singleParUpdate = false;
1537 // FIXME: the following code should go in favor of fine grained
1538 // update flag treatment.
1539 if (singleParUpdate) {
1540 // Inserting characters does not change par height
1541 ParagraphMetrics const & pms
1542 = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
1543 if (pms.dim().height()
1544 == olddim.height()) {
1545 // if so, update _only_ this paragraph
1546 cur.updateFlags(Update::SinglePar |
1548 Update::MultiParSel);
1555 && &oldTopSlice.inset() == &cur.inset()
1556 && oldTopSlice.idx() == cur.idx()
1557 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1558 && !cur.selection())
1559 // FIXME: it would be better if we could just do this
1561 //if (cur.result().update() != Update::FitCursor)
1564 // But some LFUNs do not set Update::FitCursor when needed, so we
1565 // do it for all. This is not very harmfull as FitCursor will provoke
1566 // a full redraw only if needed but still, a proper review of all LFUN
1567 // should be done and this needsUpdate boolean can then be removed.
1568 cur.updateFlags(Update::FitCursor);
1570 cur.updateFlags(Update::Force | Update::FitCursor);
1574 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
1575 FuncStatus & flag) const
1577 BOOST_ASSERT(cur.text() == this);
1579 Font const & font = cur.real_current_font;
1581 Inset::Code code = Inset::NO_CODE;
1583 switch (cmd.action) {
1585 case LFUN_DEPTH_DECREMENT:
1586 enable = changeDepthAllowed(cur, DEC_DEPTH);
1589 case LFUN_DEPTH_INCREMENT:
1590 enable = changeDepthAllowed(cur, INC_DEPTH);
1594 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1597 case LFUN_BIBITEM_INSERT:
1598 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO
1602 case LFUN_DIALOG_SHOW_NEW_INSET:
1603 if (cmd.argument() == "bibitem")
1604 code = Inset::BIBITEM_CODE;
1605 else if (cmd.argument() == "bibtex")
1606 code = Inset::BIBTEX_CODE;
1607 else if (cmd.argument() == "box")
1608 code = Inset::BOX_CODE;
1609 else if (cmd.argument() == "branch")
1610 code = Inset::BRANCH_CODE;
1611 else if (cmd.argument() == "citation")
1612 code = Inset::CITE_CODE;
1613 else if (cmd.argument() == "ert")
1614 code = Inset::ERT_CODE;
1615 else if (cmd.argument() == "external")
1616 code = Inset::EXTERNAL_CODE;
1617 else if (cmd.argument() == "float")
1618 code = Inset::FLOAT_CODE;
1619 else if (cmd.argument() == "graphics")
1620 code = Inset::GRAPHICS_CODE;
1621 else if (cmd.argument() == "include")
1622 code = Inset::INCLUDE_CODE;
1623 else if (cmd.argument() == "index")
1624 code = Inset::INDEX_CODE;
1625 else if (cmd.argument() == "nomenclature")
1626 code = Inset::NOMENCL_CODE;
1627 else if (cmd.argument() == "label")
1628 code = Inset::LABEL_CODE;
1629 else if (cmd.argument() == "note")
1630 code = Inset::NOTE_CODE;
1631 else if (cmd.argument() == "ref")
1632 code = Inset::REF_CODE;
1633 else if (cmd.argument() == "toc")
1634 code = Inset::TOC_CODE;
1635 else if (cmd.argument() == "url")
1636 code = Inset::URL_CODE;
1637 else if (cmd.argument() == "vspace")
1638 code = Inset::VSPACE_CODE;
1639 else if (cmd.argument() == "wrap")
1640 code = Inset::WRAP_CODE;
1641 else if (cmd.argument() == "listings")
1642 code = Inset::LISTINGS_CODE;
1645 case LFUN_ERT_INSERT:
1646 code = Inset::ERT_CODE;
1648 case LFUN_LISTING_INSERT:
1649 code = Inset::LISTINGS_CODE;
1651 case LFUN_FOOTNOTE_INSERT:
1652 code = Inset::FOOT_CODE;
1654 case LFUN_TABULAR_INSERT:
1655 code = Inset::TABULAR_CODE;
1657 case LFUN_MARGINALNOTE_INSERT:
1658 code = Inset::MARGIN_CODE;
1660 case LFUN_FLOAT_INSERT:
1661 case LFUN_FLOAT_WIDE_INSERT:
1662 code = Inset::FLOAT_CODE;
1664 case LFUN_WRAP_INSERT:
1665 code = Inset::WRAP_CODE;
1667 case LFUN_FLOAT_LIST:
1668 code = Inset::FLOAT_LIST_CODE;
1671 case LFUN_LIST_INSERT:
1672 code = Inset::LIST_CODE;
1674 case LFUN_THEOREM_INSERT:
1675 code = Inset::THEOREM_CODE;
1678 case LFUN_CAPTION_INSERT:
1679 code = Inset::CAPTION_CODE;
1681 case LFUN_NOTE_INSERT:
1682 code = Inset::NOTE_CODE;
1684 case LFUN_FLEX_INSERT: {
1685 code = Inset::FLEX_CODE;
1686 string s = cmd.getArg(0);
1687 InsetLayout il = cur.buffer().params().getTextClass().insetlayout(from_utf8(s));
1688 if (il.lyxtype != "charstyle" &&
1689 il.lyxtype != "custom" &&
1690 il.lyxtype != "element")
1694 case LFUN_BOX_INSERT:
1695 code = Inset::BOX_CODE;
1697 case LFUN_BRANCH_INSERT:
1698 code = Inset::BRANCH_CODE;
1699 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1702 case LFUN_LABEL_INSERT:
1703 code = Inset::LABEL_CODE;
1705 case LFUN_OPTIONAL_INSERT:
1706 code = Inset::OPTARG_CODE;
1707 enable = numberOfOptArgs(cur.paragraph())
1708 < cur.paragraph().layout()->optionalargs;
1710 case LFUN_ENVIRONMENT_INSERT:
1711 code = Inset::BOX_CODE;
1713 case LFUN_INDEX_INSERT:
1714 code = Inset::INDEX_CODE;
1716 case LFUN_INDEX_PRINT:
1717 code = Inset::INDEX_PRINT_CODE;
1719 case LFUN_NOMENCL_INSERT:
1720 code = Inset::NOMENCL_CODE;
1722 case LFUN_NOMENCL_PRINT:
1723 code = Inset::NOMENCL_PRINT_CODE;
1725 case LFUN_TOC_INSERT:
1726 code = Inset::TOC_CODE;
1728 case LFUN_HTML_INSERT:
1729 case LFUN_URL_INSERT:
1730 code = Inset::URL_CODE;
1732 case LFUN_QUOTE_INSERT:
1733 // always allow this, since we will inset a raw quote
1734 // if an inset is not allowed.
1736 case LFUN_HYPHENATION_POINT_INSERT:
1737 case LFUN_LIGATURE_BREAK_INSERT:
1738 case LFUN_HFILL_INSERT:
1739 case LFUN_MENU_SEPARATOR_INSERT:
1740 case LFUN_DOTS_INSERT:
1741 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
1742 code = Inset::SPECIALCHAR_CODE;
1744 case LFUN_SPACE_INSERT:
1745 // slight hack: we know this is allowed in math mode
1747 code = Inset::SPACE_CODE;
1750 case LFUN_INSET_MODIFY:
1751 // We need to disable this, because we may get called for a
1753 // InsetTabular::getStatus() -> InsetText::getStatus()
1754 // and we don't handle LFUN_INSET_MODIFY.
1758 case LFUN_FONT_EMPH:
1759 flag.setOnOff(font.emph() == Font::ON);
1762 case LFUN_FONT_NOUN:
1763 flag.setOnOff(font.noun() == Font::ON);
1766 case LFUN_FONT_BOLD:
1767 flag.setOnOff(font.series() == Font::BOLD_SERIES);
1770 case LFUN_FONT_SANS:
1771 flag.setOnOff(font.family() == Font::SANS_FAMILY);
1774 case LFUN_FONT_ROMAN:
1775 flag.setOnOff(font.family() == Font::ROMAN_FAMILY);
1778 case LFUN_FONT_TYPEWRITER:
1779 flag.setOnOff(font.family() == Font::TYPEWRITER_FAMILY);
1784 enable = cur.selection();
1788 if (cmd.argument().empty()) {
1789 if (theClipboard().isInternal())
1790 enable = cap::numberOfSelections() > 0;
1792 enable = !theClipboard().empty();
1794 string const arg = to_utf8(cmd.argument());
1795 if (isStrUnsignedInt(arg)) {
1796 unsigned int n = convert<unsigned int>(arg);
1797 enable = cap::numberOfSelections() > n;
1804 case LFUN_CLIPBOARD_PASTE:
1805 enable = !theClipboard().empty();
1808 case LFUN_PRIMARY_SELECTION_PASTE:
1809 enable = cur.selection() || !theSelection().empty();
1812 case LFUN_PARAGRAPH_MOVE_UP:
1813 enable = cur.pit() > 0 && !cur.selection();
1816 case LFUN_PARAGRAPH_MOVE_DOWN:
1817 enable = cur.pit() < cur.lastpit() && !cur.selection();
1820 case LFUN_INSET_DISSOLVE:
1821 enable = !isMainText(cur.bv().buffer()) && cur.inset().nargs() == 1;
1824 case LFUN_CHANGE_ACCEPT:
1825 case LFUN_CHANGE_REJECT:
1826 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
1827 // In principle, these LFUNs should only be enabled if there
1828 // is a change at the current position/in the current selection.
1829 // However, without proper optimizations, this will inevitably
1830 // result in unacceptable performance - just imagine a user who
1831 // wants to select the complete content of a long document.
1835 case LFUN_WORD_DELETE_FORWARD:
1836 case LFUN_WORD_DELETE_BACKWARD:
1837 case LFUN_LINE_DELETE:
1838 case LFUN_WORD_FORWARD:
1839 case LFUN_WORD_BACKWARD:
1840 case LFUN_CHAR_FORWARD:
1841 case LFUN_CHAR_FORWARD_SELECT:
1842 case LFUN_CHAR_BACKWARD:
1843 case LFUN_CHAR_BACKWARD_SELECT:
1845 case LFUN_UP_SELECT:
1847 case LFUN_DOWN_SELECT:
1848 case LFUN_PARAGRAPH_UP_SELECT:
1849 case LFUN_PARAGRAPH_DOWN_SELECT:
1850 case LFUN_SCREEN_UP_SELECT:
1851 case LFUN_SCREEN_DOWN_SELECT:
1852 case LFUN_LINE_BEGIN_SELECT:
1853 case LFUN_LINE_END_SELECT:
1854 case LFUN_WORD_FORWARD_SELECT:
1855 case LFUN_WORD_BACKWARD_SELECT:
1856 case LFUN_WORD_SELECT:
1857 case LFUN_PARAGRAPH_UP:
1858 case LFUN_PARAGRAPH_DOWN:
1859 case LFUN_LINE_BEGIN:
1861 case LFUN_BREAK_LINE:
1862 case LFUN_CHAR_DELETE_FORWARD:
1863 case LFUN_DELETE_FORWARD_SKIP:
1864 case LFUN_CHAR_DELETE_BACKWARD:
1865 case LFUN_DELETE_BACKWARD_SKIP:
1866 case LFUN_BREAK_PARAGRAPH:
1867 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
1868 case LFUN_BREAK_PARAGRAPH_SKIP:
1869 case LFUN_PARAGRAPH_SPACING:
1870 case LFUN_INSET_INSERT:
1871 case LFUN_WORD_UPCASE:
1872 case LFUN_WORD_LOWCASE:
1873 case LFUN_WORD_CAPITALIZE:
1874 case LFUN_CHARS_TRANSPOSE:
1875 case LFUN_SERVER_GET_XY:
1876 case LFUN_SERVER_SET_XY:
1877 case LFUN_SERVER_GET_FONT:
1878 case LFUN_SERVER_GET_LAYOUT:
1880 case LFUN_DATE_INSERT:
1881 case LFUN_SELF_INSERT:
1882 case LFUN_LINE_INSERT:
1883 case LFUN_PAGEBREAK_INSERT:
1884 case LFUN_CLEARPAGE_INSERT:
1885 case LFUN_CLEARDOUBLEPAGE_INSERT:
1886 case LFUN_MATH_DISPLAY:
1887 case LFUN_MATH_IMPORT_SELECTION:
1888 case LFUN_MATH_MODE:
1889 case LFUN_MATH_MACRO:
1890 case LFUN_MATH_MATRIX:
1891 case LFUN_MATH_DELIM:
1892 case LFUN_MATH_BIGDELIM:
1893 case LFUN_MATH_INSERT:
1894 case LFUN_MATH_SUBSCRIPT:
1895 case LFUN_MATH_SUPERSCRIPT:
1896 case LFUN_FONT_DEFAULT:
1897 case LFUN_FONT_UNDERLINE:
1898 case LFUN_FONT_SIZE:
1900 case LFUN_FONT_FREE_APPLY:
1901 case LFUN_FONT_FREE_UPDATE:
1902 case LFUN_LAYOUT_PARAGRAPH:
1903 case LFUN_PARAGRAPH_UPDATE:
1904 case LFUN_ACCENT_UMLAUT:
1905 case LFUN_ACCENT_CIRCUMFLEX:
1906 case LFUN_ACCENT_GRAVE:
1907 case LFUN_ACCENT_ACUTE:
1908 case LFUN_ACCENT_TILDE:
1909 case LFUN_ACCENT_CEDILLA:
1910 case LFUN_ACCENT_MACRON:
1911 case LFUN_ACCENT_DOT:
1912 case LFUN_ACCENT_UNDERDOT:
1913 case LFUN_ACCENT_UNDERBAR:
1914 case LFUN_ACCENT_CARON:
1915 case LFUN_ACCENT_SPECIAL_CARON:
1916 case LFUN_ACCENT_BREVE:
1917 case LFUN_ACCENT_TIE:
1918 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1919 case LFUN_ACCENT_CIRCLE:
1920 case LFUN_ACCENT_OGONEK:
1921 case LFUN_THESAURUS_ENTRY:
1922 case LFUN_PARAGRAPH_PARAMS_APPLY:
1923 case LFUN_PARAGRAPH_PARAMS:
1925 case LFUN_BUFFER_END:
1926 case LFUN_BUFFER_BEGIN:
1927 case LFUN_BUFFER_BEGIN_SELECT:
1928 case LFUN_BUFFER_END_SELECT:
1929 case LFUN_UNICODE_INSERT:
1930 // these are handled in our dispatch()
1938 if (code != Inset::NO_CODE
1939 && (cur.empty() || !cur.inset().insetAllowed(code)))
1942 flag.enabled(enable);
1947 void Text::pasteString(Cursor & cur, docstring const & clip,
1950 cur.clearSelection();
1951 if (!clip.empty()) {
1954 insertStringAsParagraphs(cur, clip);
1956 insertStringAsLines(cur, clip);