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"
29 #include "CutAndPaste.h"
31 #include "DispatchResult.h"
32 #include "ErrorList.h"
34 #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/InsetCollapsable.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>
76 using std::istringstream;
77 using std::ostringstream;
81 using cap::copySelection;
82 using cap::cutSelection;
83 using cap::pasteFromStack;
84 using cap::pasteClipboard;
85 using cap::replaceSelection;
87 using support::isStrUnsignedInt;
91 static Font freefont(Font::ALL_IGNORE);
92 static bool toggleall = false;
94 static void toggleAndShow(Cursor & cur, Text * text,
95 Font const & font, bool toggleall = true)
97 text->toggleFree(cur, font, toggleall);
99 if (font.language() != ignore_language ||
100 font.number() != Font::IGNORE) {
101 TextMetrics const & tm = cur.bv().textMetrics(text);
102 if (cur.boundary() != tm.isRTLBoundary(cur.pit(),
103 cur.pos(), cur.real_current_font))
104 text->setCursor(cur, cur.pit(), cur.pos(),
105 false, !cur.boundary());
110 static void moveCursor(Cursor & cur, bool selecting)
112 if (selecting || cur.mark())
117 static void finishChange(Cursor & cur, bool selecting)
120 moveCursor(cur, selecting);
124 static void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
127 docstring sel = cur.selectionAsString(false);
129 // It may happen that sel is empty but there is a selection
130 replaceSelection(cur);
133 #ifdef ENABLE_ASSERTIONS
134 const int old_pos = cur.pos();
136 cur.insert(new InsetMathHull(hullSimple));
137 BOOST_ASSERT(old_pos == cur.pos());
138 cur.nextInset()->edit(cur, true);
139 // don't do that also for LFUN_MATH_MODE
140 // unless you want end up with always changing
141 // to mathrm when opening an inlined inset --
142 // I really hate "LyXfunc overloading"...
144 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
145 // Avoid an unnecessary undo step if cmd.argument
147 if (!cmd.argument().empty())
148 cur.dispatch(FuncRequest(LFUN_MATH_INSERT,
151 // create a macro if we see "\\newcommand"
152 // somewhere, and an ordinary formula
154 if (sel.find(from_ascii("\\newcommand")) == string::npos
155 && sel.find(from_ascii("\\def")) == string::npos)
157 InsetMathHull * formula = new InsetMathHull;
158 istringstream is(to_utf8(sel));
161 formula->read(cur.buffer(), lex);
162 if (formula->getType() == hullNone)
163 // Don't create pseudo formulas if
164 // delimiters are left out
165 formula->mutate(hullSimple);
168 cur.insert(new MathMacroTemplate(sel));
171 cur.message(from_utf8(N_("Math editor mode")));
175 static void specialChar(Cursor & cur, InsetSpecialChar::Kind kind)
178 cap::replaceSelection(cur);
179 cur.insert(new InsetSpecialChar(kind));
184 static bool doInsertInset(Cursor & cur, Text * text,
185 FuncRequest const & cmd, bool edit, bool pastesel)
187 Inset * inset = createInset(&cur.bv(), cmd);
192 if (cmd.action == LFUN_INDEX_INSERT) {
193 docstring ds = support::subst(text->getStringToIndex(cur), '\n', ' ');
194 text->insertInset(cur, inset);
196 inset->edit(cur, true);
197 // Now put this into inset
198 static_cast<InsetCollapsable *>(inset)->text_.insertStringAsParagraphs(cur, ds);
201 if (cur.selection()) {
202 lyx::dispatch(FuncRequest(LFUN_CUT));
205 text->insertInset(cur, inset);
208 inset->edit(cur, true);
210 if (gotsel && pastesel) {
211 lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
212 // reset first par to default
213 if (cur.lastpit() != 0 || cur.lastpos() != 0) {
214 LayoutPtr const layout =
215 cur.buffer().params().getTextClass().defaultLayout();
216 cur.text()->paragraphs().begin()->layout(layout);
224 string const freefont2string()
226 return freefont.toString(toggleall);
230 void Text::number(Cursor & cur)
232 Font font(Font::ALL_IGNORE);
233 font.setNumber(Font::TOGGLE);
234 toggleAndShow(cur, this, font);
238 bool Text::isRTL(Buffer const & buffer, Paragraph const & par) const
240 return par.isRTL(buffer.params());
244 void Text::dispatch(Cursor & cur, FuncRequest & cmd)
246 LYXERR(Debug::ACTION) << "Text::dispatch: cmd: " << cmd << endl;
248 // FIXME: We use the update flag to indicates wether a singlePar or a
249 // full screen update is needed. We reset it here but shall we restore it
253 BOOST_ASSERT(cur.text() == this);
254 BufferView * bv = &cur.bv();
255 TextMetrics & tm = cur.bv().textMetrics(this);
256 CursorSlice oldTopSlice = cur.top();
257 bool oldBoundary = cur.boundary();
258 bool sel = cur.selection();
259 // Signals that, even if needsUpdate == false, an update of the
260 // cursor paragraph is required
261 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
262 LyXAction::SingleParUpdate);
263 // Signals that a full-screen update is required
264 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
265 LyXAction::NoUpdate) || singleParUpdate);
266 // Remember the old paragraph metric (_outer_ paragraph!)
267 ParagraphMetrics const & pm = cur.bv().parMetrics(
268 cur.bottom().text(), cur.bottom().pit());
269 Dimension olddim = pm.dim();
271 switch (cmd.action) {
273 case LFUN_PARAGRAPH_MOVE_DOWN: {
274 pit_type const pit = cur.pit();
275 recUndo(cur, pit, pit + 1);
277 std::swap(pars_[pit], pars_[pit + 1]);
278 updateLabels(cur.buffer());
284 case LFUN_PARAGRAPH_MOVE_UP: {
285 pit_type const pit = cur.pit();
286 recUndo(cur, pit - 1, pit);
288 std::swap(pars_[pit], pars_[pit - 1]);
289 updateLabels(cur.buffer());
295 case LFUN_APPENDIX: {
296 Paragraph & par = cur.paragraph();
297 bool start = !par.params().startOfAppendix();
299 // FIXME: The code below only makes sense at top level.
300 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
301 // ensure that we have only one start_of_appendix in this document
302 // FIXME: this don't work for multipart document!
303 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
304 if (pars_[tmp].params().startOfAppendix()) {
306 pars_[tmp].params().startOfAppendix(false);
312 par.params().startOfAppendix(start);
314 // we can set the refreshing parameters now
315 updateLabels(cur.buffer());
319 case LFUN_WORD_DELETE_FORWARD:
320 if (cur.selection()) {
321 cutSelection(cur, true, false);
323 deleteWordForward(cur);
324 finishChange(cur, false);
327 case LFUN_WORD_DELETE_BACKWARD:
328 if (cur.selection()) {
329 cutSelection(cur, true, false);
331 deleteWordBackward(cur);
332 finishChange(cur, false);
335 case LFUN_LINE_DELETE:
336 if (cur.selection()) {
337 cutSelection(cur, true, false);
339 tm.deleteLineForward(cur);
340 finishChange(cur, false);
343 case LFUN_BUFFER_BEGIN:
344 case LFUN_BUFFER_BEGIN_SELECT:
345 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
346 if (cur.depth() == 1) {
347 needsUpdate |= cursorTop(cur);
353 case LFUN_BUFFER_END:
354 case LFUN_BUFFER_END_SELECT:
355 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
356 if (cur.depth() == 1) {
357 needsUpdate |= cursorBottom(cur);
363 case LFUN_CHAR_FORWARD:
364 case LFUN_CHAR_FORWARD_SELECT:
365 //lyxerr << BOOST_CURRENT_FUNCTION
366 // << " LFUN_CHAR_FORWARD[SEL]:\n" << cur << endl;
367 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
368 if (reverseDirectionNeeded(cur))
369 needsUpdate |= cursorLeft(cur);
371 needsUpdate |= cursorRight(cur);
373 if (!needsUpdate && oldTopSlice == cur.top()
374 && cur.boundary() == oldBoundary) {
376 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
380 case LFUN_CHAR_BACKWARD:
381 case LFUN_CHAR_BACKWARD_SELECT:
382 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
383 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
384 if (reverseDirectionNeeded(cur))
385 needsUpdate |= cursorRight(cur);
387 needsUpdate |= cursorLeft(cur);
389 if (!needsUpdate && oldTopSlice == cur.top()
390 && cur.boundary() == oldBoundary) {
392 cmd = FuncRequest(LFUN_FINISHED_LEFT);
397 case LFUN_DOWN_SELECT:
400 // stop/start the selection
401 bool select = cmd.action == LFUN_DOWN_SELECT ||
402 cmd.action == LFUN_UP_SELECT;
403 cur.selHandle(select);
405 // move cursor up/down
406 bool up = cmd.action == LFUN_UP_SELECT || cmd.action == LFUN_UP;
407 bool const successful = cur.upDownInText(up, needsUpdate);
409 // notify insets which were left and get their update flags
410 notifyCursorLeaves(cur.beforeDispatchCursor(), cur);
413 // redraw if you leave mathed (for the decorations)
414 needsUpdate |= cur.beforeDispatchCursor().inMathed();
421 case LFUN_PARAGRAPH_UP:
422 case LFUN_PARAGRAPH_UP_SELECT:
423 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
424 needsUpdate |= cursorUpParagraph(cur);
427 case LFUN_PARAGRAPH_DOWN:
428 case LFUN_PARAGRAPH_DOWN_SELECT:
429 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
430 needsUpdate |= cursorDownParagraph(cur);
433 case LFUN_SCREEN_UP_SELECT:
434 needsUpdate |= cur.selHandle(true);
435 if (cur.pit() == 0 && cur.textRow().pos() == 0)
438 tm.cursorPrevious(cur);
442 case LFUN_SCREEN_DOWN_SELECT:
443 needsUpdate |= cur.selHandle(true);
444 if (cur.pit() == cur.lastpit()
445 && cur.textRow().endpos() == cur.lastpos())
452 case LFUN_LINE_BEGIN:
453 case LFUN_LINE_BEGIN_SELECT:
454 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
455 needsUpdate |= tm.cursorHome(cur);
459 case LFUN_LINE_END_SELECT:
460 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
461 needsUpdate |= tm.cursorEnd(cur);
464 case LFUN_WORD_FORWARD:
465 case LFUN_WORD_FORWARD_SELECT:
466 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
467 if (reverseDirectionNeeded(cur))
468 needsUpdate |= cursorLeftOneWord(cur);
470 needsUpdate |= cursorRightOneWord(cur);
473 case LFUN_WORD_BACKWARD:
474 case LFUN_WORD_BACKWARD_SELECT:
475 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
476 if (reverseDirectionNeeded(cur))
477 needsUpdate |= cursorRightOneWord(cur);
479 needsUpdate |= cursorLeftOneWord(cur);
482 case LFUN_WORD_SELECT: {
483 selectWord(cur, WHOLE_WORD);
484 finishChange(cur, true);
488 case LFUN_BREAK_LINE: {
489 // Not allowed by LaTeX (labels or empty par)
490 if (cur.pos() > cur.paragraph().beginOfBody()) {
491 // this avoids a double undo
492 // FIXME: should not be needed, ideally
493 if (!cur.selection())
495 cap::replaceSelection(cur);
496 cur.insert(new InsetNewline);
498 moveCursor(cur, false);
503 case LFUN_CHAR_DELETE_FORWARD:
504 if (!cur.selection()) {
505 if (cur.pos() == cur.paragraph().size())
506 // Par boundary, force full-screen update
507 singleParUpdate = false;
508 needsUpdate |= erase(cur);
510 // It is possible to make it a lot faster still
511 // just comment out the line below...
513 cutSelection(cur, true, false);
514 singleParUpdate = false;
516 moveCursor(cur, false);
519 case LFUN_DELETE_FORWARD_SKIP:
520 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
521 if (!cur.selection()) {
522 if (cur.pos() == cur.lastpos()) {
529 cutSelection(cur, true, false);
534 case LFUN_CHAR_DELETE_BACKWARD:
535 if (!cur.selection()) {
536 if (bv->getIntl().getTransManager().backspace()) {
537 // Par boundary, full-screen update
539 singleParUpdate = false;
540 needsUpdate |= backspace(cur);
542 // It is possible to make it a lot faster still
543 // just comment out the line below...
546 cutSelection(cur, true, false);
547 singleParUpdate = false;
551 case LFUN_DELETE_BACKWARD_SKIP:
552 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
553 if (!cur.selection()) {
555 //CursorSlice cur = cursor();
559 cutSelection(cur, true, false);
563 case LFUN_BREAK_PARAGRAPH:
564 cap::replaceSelection(cur);
565 breakParagraph(cur, cmd.argument() == "inverse");
569 case LFUN_BREAK_PARAGRAPH_SKIP: {
570 // When at the beginning of a paragraph, remove
571 // indentation. Otherwise, do the same as LFUN_BREAK_PARAGRAPH.
572 cap::replaceSelection(cur);
574 cur.paragraph().params().labelWidthString(docstring());
576 breakParagraph(cur, false);
582 // With the creation of LFUN_PARAGRAPH_PARAMS, this is now redundant,
583 // as its duties can be performed there. Should it be removed??
584 // FIXME For now, it can just dispatch LFUN_PARAGRAPH_PARAMS...
585 case LFUN_PARAGRAPH_SPACING: {
586 Paragraph & par = cur.paragraph();
587 Spacing::Space cur_spacing = par.params().spacing().getSpace();
588 string cur_value = "1.0";
589 if (cur_spacing == Spacing::Other)
590 cur_value = par.params().spacing().getValueAsString();
592 istringstream is(to_utf8(cmd.argument()));
595 Spacing::Space new_spacing = cur_spacing;
596 string new_value = cur_value;
598 lyxerr << "Missing argument to `paragraph-spacing'"
600 } else if (tmp == "single") {
601 new_spacing = Spacing::Single;
602 } else if (tmp == "onehalf") {
603 new_spacing = Spacing::Onehalf;
604 } else if (tmp == "double") {
605 new_spacing = Spacing::Double;
606 } else if (tmp == "other") {
607 new_spacing = Spacing::Other;
608 string tmpval = "0.0";
610 lyxerr << "new_value = " << tmpval << endl;
613 } else if (tmp == "default") {
614 new_spacing = Spacing::Default;
616 lyxerr << to_utf8(_("Unknown spacing argument: "))
617 << to_utf8(cmd.argument()) << endl;
619 if (cur_spacing != new_spacing || cur_value != new_value)
620 par.params().spacing(Spacing(new_spacing, new_value));
624 case LFUN_INSET_INSERT: {
626 Inset * inset = createInset(bv, cmd);
628 // FIXME (Abdel 01/02/2006):
629 // What follows would be a partial fix for bug 2154:
630 // http://bugzilla.lyx.org/show_bug.cgi?id=2154
631 // This automatically put the label inset _after_ a
632 // numbered section. It should be possible to extend the mechanism
633 // to any kind of LateX environement.
634 // The correct way to fix that bug would be at LateX generation.
635 // I'll let the code here for reference as it could be used for some
636 // other feature like "automatic labelling".
638 Paragraph & par = pars_[cur.pit()];
639 if (inset->lyxCode() == Inset::LABEL_CODE
640 && par.layout()->labeltype == LABEL_COUNTER) {
641 // Go to the end of the paragraph
642 // Warning: Because of Change-Tracking, the last
643 // position is 'size()' and not 'size()-1':
644 cur.pos() = par.size();
645 // Insert a new paragraph
646 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
651 cutSelection(cur, true, false);
652 insertInset(cur, inset);
658 case LFUN_INSET_DISSOLVE:
659 needsUpdate |= dissolveInset(cur);
662 case LFUN_INSET_SETTINGS:
663 cur.inset().showInsetDialog(bv);
666 case LFUN_SPACE_INSERT:
667 if (cur.paragraph().layout()->free_spacing)
668 insertChar(cur, ' ');
670 doInsertInset(cur, this, cmd, false, false);
673 moveCursor(cur, false);
676 case LFUN_HYPHENATION_POINT_INSERT:
677 specialChar(cur, InsetSpecialChar::HYPHENATION);
680 case LFUN_LIGATURE_BREAK_INSERT:
681 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
684 case LFUN_DOTS_INSERT:
685 specialChar(cur, InsetSpecialChar::LDOTS);
688 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
689 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
692 case LFUN_MENU_SEPARATOR_INSERT:
693 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
696 case LFUN_WORD_UPCASE:
697 changeCase(cur, Text::text_uppercase);
700 case LFUN_WORD_LOWCASE:
701 changeCase(cur, Text::text_lowercase);
704 case LFUN_WORD_CAPITALIZE:
705 changeCase(cur, Text::text_capitalization);
708 case LFUN_CHARS_TRANSPOSE:
713 cur.message(_("Paste"));
714 cap::replaceSelection(cur);
715 if (cmd.argument().empty() && !theClipboard().isInternal())
716 pasteClipboard(cur, bv->buffer().errorList("Paste"));
718 string const arg(to_utf8(cmd.argument()));
719 pasteFromStack(cur, bv->buffer().errorList("Paste"),
720 isStrUnsignedInt(arg) ?
721 convert<unsigned int>(arg) :
724 bv->buffer().errors("Paste");
725 cur.clearSelection(); // bug 393
730 cutSelection(cur, true, true);
731 cur.message(_("Cut"));
736 cur.message(_("Copy"));
739 case LFUN_SERVER_GET_XY:
740 cur.message(from_utf8(
741 convert<string>(tm.cursorX(cur.top(), cur.boundary()))
742 + ' ' + convert<string>(tm.cursorY(cur.top(), cur.boundary()))));
745 case LFUN_SERVER_SET_XY: {
748 istringstream is(to_utf8(cmd.argument()));
751 lyxerr << "SETXY: Could not parse coordinates in '"
752 << to_utf8(cmd.argument()) << std::endl;
754 tm.setCursorFromCoordinates(cur, x, y);
758 case LFUN_SERVER_GET_FONT:
759 if (cur.current_font.shape() == Font::ITALIC_SHAPE)
760 cur.message(from_ascii("E"));
761 else if (cur.current_font.shape() == Font::SMALLCAPS_SHAPE)
762 cur.message(from_ascii("N"));
764 cur.message(from_ascii("0"));
767 case LFUN_SERVER_GET_LAYOUT:
768 cur.message(cur.paragraph().layout()->name());
772 docstring layout = cmd.argument();
773 LYXERR(Debug::INFO) << "LFUN_LAYOUT: (arg) " << to_utf8(layout) << endl;
775 docstring const old_layout = cur.paragraph().layout()->name();
777 // Derive layout number from given argument (string)
778 // and current buffer's textclass (number)
779 TextClass const & tclass = bv->buffer().params().getTextClass();
781 layout = tclass.defaultLayoutName();
782 bool hasLayout = tclass.hasLayout(layout);
784 // If the entry is obsolete, use the new one instead.
786 docstring const & obs = tclass[layout]->obsoleted_by();
792 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
793 from_utf8(N_(" not known")));
797 bool change_layout = (old_layout != layout);
799 if (!change_layout && cur.selection() &&
800 cur.selBegin().pit() != cur.selEnd().pit())
802 pit_type spit = cur.selBegin().pit();
803 pit_type epit = cur.selEnd().pit() + 1;
804 while (spit != epit) {
805 if (pars_[spit].layout()->name() != old_layout) {
806 change_layout = true;
814 setLayout(cur, layout);
819 case LFUN_CLIPBOARD_PASTE:
820 cur.clearSelection();
821 pasteClipboard(cur, bv->buffer().errorList("Paste"),
822 cmd.argument() == "paragraph");
823 bv->buffer().errors("Paste");
826 case LFUN_PRIMARY_SELECTION_PASTE:
827 pasteString(cur, theSelection().get(),
828 cmd.argument() == "paragraph");
831 case LFUN_UNICODE_INSERT: {
832 if (cmd.argument().empty())
834 docstring hexstring = cmd.argument();
835 if (lyx::support::isHex(hexstring)) {
836 char_type c = lyx::support::hexToInt(hexstring);
837 if (c >= 32 && c < 0x10ffff) {
838 lyxerr << "Inserting c: " << c << endl;
839 docstring s = docstring(1, c);
840 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
846 case LFUN_QUOTE_INSERT: {
847 Paragraph & par = cur.paragraph();
848 pos_type pos = cur.pos();
849 BufferParams const & bufparams = bv->buffer().params();
850 LayoutPtr const & style = par.layout();
851 if (!style->pass_thru
852 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
853 // this avoids a double undo
854 // FIXME: should not be needed, ideally
855 if (!cur.selection())
857 cap::replaceSelection(cur);
862 else if (cur.prevInset() && cur.prevInset()->isSpace())
865 c = par.getChar(pos - 1);
866 string arg = to_utf8(cmd.argument());
868 cur.insert(new InsetQuotes(c,
869 bufparams.quotes_language,
870 InsetQuotes::SingleQ));
872 cur.insert(new InsetQuotes(c,
873 bufparams.quotes_language,
874 InsetQuotes::DoubleQ));
878 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
882 case LFUN_DATE_INSERT: {
883 string const format = cmd.argument().empty()
884 ? lyxrc.date_insert_format : to_utf8(cmd.argument());
885 string const time = formatted_time(current_time(), format);
886 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, time));
890 case LFUN_MOUSE_TRIPLE:
891 if (cmd.button() == mouse_button::button1) {
900 case LFUN_MOUSE_DOUBLE:
901 if (cmd.button() == mouse_button::button1) {
902 selectWord(cur, WHOLE_WORD_STRICT);
907 // Single-click on work area
908 case LFUN_MOUSE_PRESS: {
909 // Right click on a footnote flag opens float menu
910 if (cmd.button() == mouse_button::button3)
911 cur.clearSelection();
914 bool update = bv->mouseSetCursor(cur);
916 // Insert primary selection with middle mouse
917 // if there is a local selection in the current buffer,
919 if (cmd.button() == mouse_button::button2) {
920 if (cap::selection()) {
921 // Copy the selection buffer to the clipboard
922 // stack, because we want it to appear in the
923 // "Edit->Paste recent" menu.
924 cap::copySelectionToStack();
926 cap::pasteSelection(bv->cursor(),
927 bv->buffer().errorList("Paste"));
928 bv->buffer().errors("Paste");
929 bv->buffer().markDirty();
932 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
936 // we have to update after dEPM triggered
937 if (!update && cmd.button() == mouse_button::button1) {
945 case LFUN_MOUSE_MOTION: {
946 // Only use motion with button 1
947 //if (cmd.button() != mouse_button::button1)
950 // ignore motions deeper nested than the real anchor
951 Cursor & bvcur = cur.bv().cursor();
952 if (bvcur.anchor_.hasPart(cur)) {
953 CursorSlice old = bvcur.top();
955 int const wh = bv->workHeight();
956 int const y = std::max(0, std::min(wh - 1, cmd.y));
958 tm.setCursorFromCoordinates(cur, cmd.x, y);
959 cur.setTargetX(cmd.x);
961 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
963 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
964 // This is to allow jumping over large insets
965 if (cur.top() == old) {
967 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
969 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
972 if (cur.top() == old)
976 bvcur.setCursor(cur);
977 bvcur.selection() = true;
978 //lyxerr << "MOTION: " << bv->cursor() << endl;
986 case LFUN_MOUSE_RELEASE: {
987 if (cmd.button() == mouse_button::button2)
990 if (cmd.button() == mouse_button::button1) {
991 // if there is new selection, update persistent
992 // selection, otherwise, single click does not
993 // clear persistent selection buffer
994 if (cur.selection()) {
996 // if double click, cur is moved to the end of word by selectWord
997 // but bvcur is current mouse position
998 Cursor & bvcur = cur.bv().cursor();
999 bvcur.selection() = true;
1001 needsUpdate = false;
1008 case LFUN_SELF_INSERT: {
1009 if (cmd.argument().empty())
1012 // Automatically delete the currently selected
1013 // text and replace it with what is being
1014 // typed in now. Depends on lyxrc settings
1015 // "auto_region_delete", which defaults to
1018 if (lyxrc.auto_region_delete && cur.selection()) {
1019 cutSelection(cur, false, false);
1020 // When change tracking is set to off, the metrics update
1021 // mechanism correctly detects if a full update is needed or not.
1022 // This detection fails when a selection spans multiple rows and
1023 // change tracking is enabled because the paragraph metrics stays
1024 // the same. In this case, we force the full update:
1025 // (see http://bugzilla.lyx.org/show_bug.cgi?id=3992)
1026 if (cur.buffer().params().trackChanges)
1027 cur.updateFlags(Update::Force);
1030 cur.clearSelection();
1031 Font const old_font = cur.real_current_font;
1033 docstring::const_iterator cit = cmd.argument().begin();
1034 docstring::const_iterator end = cmd.argument().end();
1035 for (; cit != end; ++cit)
1036 bv->translateAndInsert(*cit, this, cur);
1039 moveCursor(cur, false);
1043 case LFUN_URL_INSERT: {
1044 InsetCommandParams p("url");
1046 if (cur.selection()) {
1047 content = cur.selectionAsString(false);
1048 cutSelection(cur, true, false);
1050 p["target"] = (cmd.argument().empty()) ?
1051 content : cmd.argument();
1052 string const data = InsetCommandMailer::params2string("url", p);
1053 if (p["target"].empty()) {
1054 bv->showInsetDialog("url", data, 0);
1056 FuncRequest fr(LFUN_INSET_INSERT, data);
1062 case LFUN_HTML_INSERT: {
1063 InsetCommandParams p("htmlurl");
1065 if (cur.selection()) {
1066 content = cur.selectionAsString(false);
1067 cutSelection(cur, true, false);
1069 p["target"] = (cmd.argument().empty()) ?
1070 content : cmd.argument();
1071 string const data = InsetCommandMailer::params2string("url", p);
1072 if (p["target"].empty()) {
1073 bv->showInsetDialog("url", data, 0);
1075 FuncRequest fr(LFUN_INSET_INSERT, data);
1081 case LFUN_LABEL_INSERT: {
1082 InsetCommandParams p("label");
1083 // Try to generate a valid label
1084 p["name"] = (cmd.argument().empty()) ?
1085 cur.getPossibleLabel() :
1087 string const data = InsetCommandMailer::params2string("label", p);
1089 if (cmd.argument().empty()) {
1090 bv->showInsetDialog("label", data, 0);
1092 FuncRequest fr(LFUN_INSET_INSERT, data);
1100 case LFUN_LIST_INSERT:
1101 case LFUN_THEOREM_INSERT:
1103 case LFUN_CAPTION_INSERT:
1104 // Open the inset, and move the current selection
1106 doInsertInset(cur, this, cmd, true, true);
1108 updateLabels(bv->buffer());
1110 case LFUN_NOTE_INSERT:
1111 case LFUN_FLEX_INSERT:
1112 case LFUN_BOX_INSERT:
1113 case LFUN_BRANCH_INSERT:
1114 case LFUN_BIBITEM_INSERT:
1115 case LFUN_ERT_INSERT:
1116 case LFUN_LISTING_INSERT:
1117 case LFUN_FOOTNOTE_INSERT:
1118 case LFUN_MARGINALNOTE_INSERT:
1119 case LFUN_OPTIONAL_INSERT:
1120 case LFUN_ENVIRONMENT_INSERT:
1121 // Open the inset, and move the current selection
1123 doInsertInset(cur, this, cmd, true, true);
1127 case LFUN_TABULAR_INSERT:
1128 // if there were no arguments, just open the dialog
1129 if (doInsertInset(cur, this, cmd, false, true))
1132 bv->showDialog("tabularcreate");
1136 case LFUN_FLOAT_INSERT:
1137 case LFUN_FLOAT_WIDE_INSERT:
1138 case LFUN_WRAP_INSERT: {
1139 bool content = cur.selection(); // will some text be moved into the inset?
1141 doInsertInset(cur, this, cmd, true, true);
1143 ParagraphList & pars = cur.text()->paragraphs();
1145 TextClass const & tclass = bv->buffer().params().getTextClass();
1147 // add a separate paragraph for the caption inset
1148 pars.push_back(Paragraph());
1149 pars.back().setInsetOwner(pars[0].inInset());
1150 pars.back().layout(tclass.defaultLayout());
1152 int cap_pit = pars.size() - 1;
1154 // if an empty inset was created, we create an additional empty
1155 // paragraph at the bottom so that the user can choose where to put
1156 // the graphics (or table).
1158 pars.push_back(Paragraph());
1159 pars.back().setInsetOwner(pars[0].inInset());
1160 pars.back().layout(tclass.defaultLayout());
1164 // reposition the cursor to the caption
1165 cur.pit() = cap_pit;
1167 // FIXME: This Text/Cursor dispatch handling is a mess!
1168 // We cannot use Cursor::dispatch here it needs access to up to
1170 FuncRequest cmd_caption(LFUN_CAPTION_INSERT);
1171 cur.text()->dispatch(cur, cmd_caption);
1172 cur.updateFlags(Update::Force);
1173 // FIXME: When leaving the Float (or Wrap) inset we should
1174 // delete any empty paragraph left above or below the
1179 case LFUN_INDEX_INSERT:
1180 doInsertInset(cur, this, cmd, true, true);
1183 case LFUN_NOMENCL_INSERT: {
1184 Inset * inset = createInset(&cur.bv(), cmd);
1188 cur.clearSelection();
1189 insertInset(cur, inset);
1190 // Show the dialog for the nomenclature entry, since the
1191 // description entry still needs to be filled in.
1192 if (cmd.action == LFUN_NOMENCL_INSERT)
1193 inset->edit(cur, true);
1198 case LFUN_INDEX_PRINT:
1199 case LFUN_NOMENCL_PRINT:
1200 case LFUN_TOC_INSERT:
1201 case LFUN_HFILL_INSERT:
1202 case LFUN_LINE_INSERT:
1203 case LFUN_PAGEBREAK_INSERT:
1204 case LFUN_CLEARPAGE_INSERT:
1205 case LFUN_CLEARDOUBLEPAGE_INSERT:
1207 doInsertInset(cur, this, cmd, false, false);
1211 case LFUN_DEPTH_DECREMENT:
1212 changeDepth(cur, DEC_DEPTH);
1215 case LFUN_DEPTH_INCREMENT:
1216 changeDepth(cur, INC_DEPTH);
1219 case LFUN_MATH_DISPLAY:
1220 mathDispatch(cur, cmd, true);
1223 case LFUN_MATH_IMPORT_SELECTION:
1224 case LFUN_MATH_MODE:
1225 if (cmd.argument() == "on")
1226 // don't pass "on" as argument
1227 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1229 mathDispatch(cur, cmd, false);
1232 case LFUN_MATH_MACRO:
1233 if (cmd.argument().empty())
1234 cur.errorMessage(from_utf8(N_("Missing argument")));
1236 string s = to_utf8(cmd.argument());
1237 string const s1 = token(s, ' ', 1);
1238 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1239 string const s2 = token(s, ' ', 2);
1240 string const type = s2.empty() ? "newcommand" : s2;
1241 cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, from_utf8(type)));
1242 //cur.nextInset()->edit(cur, true);
1246 // passthrough hat and underscore outside mathed:
1247 case LFUN_MATH_SUBSCRIPT:
1248 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1250 case LFUN_MATH_SUPERSCRIPT:
1251 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1254 case LFUN_MATH_INSERT:
1255 case LFUN_MATH_MATRIX:
1256 case LFUN_MATH_DELIM:
1257 case LFUN_MATH_BIGDELIM: {
1258 if (cur.selection())
1259 cur.clearSelection();
1260 // FIXME: instead of the above, this one
1261 // should be used (but it asserts with Bidi enabled)
1262 // cf. http://bugzilla.lyx.org/show_bug.cgi?id=4055
1263 // cap::replaceSelection(cur);
1264 cur.insert(new InsetMathHull(hullSimple));
1265 checkAndActivateInset(cur, true);
1266 BOOST_ASSERT(cur.inMathed());
1271 case LFUN_FONT_EMPH: {
1272 Font font(Font::ALL_IGNORE);
1273 font.setEmph(Font::TOGGLE);
1274 toggleAndShow(cur, this, font);
1278 case LFUN_FONT_BOLD: {
1279 Font font(Font::ALL_IGNORE);
1280 font.setSeries(Font::BOLD_SERIES);
1281 toggleAndShow(cur, this, font);
1285 case LFUN_FONT_NOUN: {
1286 Font font(Font::ALL_IGNORE);
1287 font.setNoun(Font::TOGGLE);
1288 toggleAndShow(cur, this, font);
1292 case LFUN_FONT_TYPEWRITER: {
1293 Font font(Font::ALL_IGNORE);
1294 font.setFamily(Font::TYPEWRITER_FAMILY); // no good
1295 toggleAndShow(cur, this, font);
1299 case LFUN_FONT_SANS: {
1300 Font font(Font::ALL_IGNORE);
1301 font.setFamily(Font::SANS_FAMILY);
1302 toggleAndShow(cur, this, font);
1306 case LFUN_FONT_ROMAN: {
1307 Font font(Font::ALL_IGNORE);
1308 font.setFamily(Font::ROMAN_FAMILY);
1309 toggleAndShow(cur, this, font);
1313 case LFUN_FONT_DEFAULT: {
1314 Font font(Font::ALL_INHERIT, ignore_language);
1315 toggleAndShow(cur, this, font);
1319 case LFUN_FONT_UNDERLINE: {
1320 Font font(Font::ALL_IGNORE);
1321 font.setUnderbar(Font::TOGGLE);
1322 toggleAndShow(cur, this, font);
1326 case LFUN_FONT_SIZE: {
1327 Font font(Font::ALL_IGNORE);
1328 font.setLyXSize(to_utf8(cmd.argument()));
1329 toggleAndShow(cur, this, font);
1333 case LFUN_LANGUAGE: {
1334 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1337 Font font(Font::ALL_IGNORE);
1338 font.setLanguage(lang);
1339 toggleAndShow(cur, this, font);
1343 case LFUN_FONT_FREE_APPLY:
1344 toggleAndShow(cur, this, freefont, toggleall);
1345 cur.message(_("Character set"));
1348 // Set the freefont using the contents of \param data dispatched from
1349 // the frontends and apply it at the current cursor location.
1350 case LFUN_FONT_FREE_UPDATE: {
1353 if (font.fromString(to_utf8(cmd.argument()), toggle)) {
1356 toggleAndShow(cur, this, freefont, toggleall);
1357 cur.message(_("Character set"));
1362 case LFUN_FINISHED_LEFT:
1363 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1364 if (reverseDirectionNeeded(cur)) {
1366 cur.setCurrentFont();
1370 case LFUN_FINISHED_RIGHT:
1371 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1372 if (!reverseDirectionNeeded(cur)) {
1374 cur.setCurrentFont();
1378 case LFUN_LAYOUT_PARAGRAPH: {
1380 params2string(cur.paragraph(), data);
1381 data = "show\n" + data;
1382 bv->showDialogWithData("paragraph", data);
1386 case LFUN_PARAGRAPH_UPDATE: {
1388 params2string(cur.paragraph(), data);
1390 // Will the paragraph accept changes from the dialog?
1391 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1393 data = "update " + convert<string>(accept) + '\n' + data;
1394 bv->updateDialog("paragraph", data);
1398 case LFUN_ACCENT_UMLAUT:
1399 case LFUN_ACCENT_CIRCUMFLEX:
1400 case LFUN_ACCENT_GRAVE:
1401 case LFUN_ACCENT_ACUTE:
1402 case LFUN_ACCENT_TILDE:
1403 case LFUN_ACCENT_CEDILLA:
1404 case LFUN_ACCENT_MACRON:
1405 case LFUN_ACCENT_DOT:
1406 case LFUN_ACCENT_UNDERDOT:
1407 case LFUN_ACCENT_UNDERBAR:
1408 case LFUN_ACCENT_CARON:
1409 case LFUN_ACCENT_SPECIAL_CARON:
1410 case LFUN_ACCENT_BREVE:
1411 case LFUN_ACCENT_TIE:
1412 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1413 case LFUN_ACCENT_CIRCLE:
1414 case LFUN_ACCENT_OGONEK:
1415 theLyXFunc().handleKeyFunc(cmd.action);
1416 if (!cmd.argument().empty())
1417 // FIXME: Are all these characters encoded in one byte in utf8?
1418 bv->translateAndInsert(cmd.argument()[0], this, cur);
1421 case LFUN_FLOAT_LIST: {
1422 TextClass const & tclass = bv->buffer().params().getTextClass();
1423 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1425 if (cur.selection())
1426 cutSelection(cur, true, false);
1427 breakParagraph(cur);
1429 if (cur.lastpos() != 0) {
1431 breakParagraph(cur);
1434 setLayout(cur, tclass.defaultLayoutName());
1435 ParagraphParameters p;
1436 setParagraphs(cur, p);
1437 insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1440 lyxerr << "Non-existent float type: "
1441 << to_utf8(cmd.argument()) << endl;
1446 case LFUN_CHANGE_ACCEPT: {
1447 acceptOrRejectChanges(cur, ACCEPT);
1451 case LFUN_CHANGE_REJECT: {
1452 acceptOrRejectChanges(cur, REJECT);
1456 case LFUN_THESAURUS_ENTRY: {
1457 docstring arg = cmd.argument();
1459 arg = cur.selectionAsString(false);
1461 if (arg.size() > 100 || arg.empty()) {
1462 // Get word or selection
1463 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1464 arg = cur.selectionAsString(false);
1467 bv->showDialogWithData("thesaurus", to_utf8(arg));
1471 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1472 // Given data, an encoding of the ParagraphParameters
1473 // generated in the Paragraph dialog, this function sets
1474 // the current paragraph, or currently selected paragraphs,
1476 // NOTE: This function overrides all existing settings.
1477 setParagraphs(cur, cmd.argument());
1478 cur.message(_("Paragraph layout set"));
1482 case LFUN_PARAGRAPH_PARAMS: {
1483 // Given data, an encoding of the ParagraphParameters as we'd
1484 // find them in a LyX file, this function modifies the current paragraph,
1485 // or currently selected paragraphs.
1486 // NOTE: This function only modifies, and does not override, existing
1488 setParagraphs(cur, cmd.argument(), true);
1489 cur.message(_("Paragraph layout set"));
1494 if (cur.selection()) {
1495 cur.selection() = false;
1498 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1503 LYXERR(Debug::ACTION)
1504 << BOOST_CURRENT_FUNCTION
1505 << ": Command " << cmd
1506 << " not DISPATCHED by Text" << endl;
1511 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1513 // FIXME: The cursor flag is reset two lines below
1514 // so we need to check here if some of the LFUN did touch that.
1515 // for now only Text::erase() and Text::backspace() do that.
1516 // The plan is to verify all the LFUNs and then to remove this
1517 // singleParUpdate boolean altogether.
1518 if (cur.result().update() & Update::Force) {
1519 singleParUpdate = false;
1523 // FIXME: the following code should go in favor of fine grained
1524 // update flag treatment.
1525 if (singleParUpdate) {
1526 // Inserting characters does not change par height
1527 ParagraphMetrics const & pms
1528 = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
1529 if (pms.dim().height()
1530 == olddim.height()) {
1531 // if so, update _only_ this paragraph
1532 cur.updateFlags(Update::SinglePar |
1534 Update::MultiParSel);
1541 && &oldTopSlice.inset() == &cur.inset()
1542 && oldTopSlice.idx() == cur.idx()
1543 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1544 && !cur.selection())
1545 // FIXME: it would be better if we could just do this
1547 //if (cur.result().update() != Update::FitCursor)
1550 // But some LFUNs do not set Update::FitCursor when needed, so we
1551 // do it for all. This is not very harmfull as FitCursor will provoke
1552 // a full redraw only if needed but still, a proper review of all LFUN
1553 // should be done and this needsUpdate boolean can then be removed.
1554 cur.updateFlags(Update::FitCursor);
1556 cur.updateFlags(Update::Force | Update::FitCursor);
1560 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
1561 FuncStatus & flag) const
1563 BOOST_ASSERT(cur.text() == this);
1565 Font const & font = cur.real_current_font;
1567 Inset::Code code = Inset::NO_CODE;
1569 switch (cmd.action) {
1571 case LFUN_DEPTH_DECREMENT:
1572 enable = changeDepthAllowed(cur, DEC_DEPTH);
1575 case LFUN_DEPTH_INCREMENT:
1576 enable = changeDepthAllowed(cur, INC_DEPTH);
1580 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1583 case LFUN_BIBITEM_INSERT:
1584 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO
1588 case LFUN_DIALOG_SHOW_NEW_INSET:
1589 if (cmd.argument() == "bibitem")
1590 code = Inset::BIBITEM_CODE;
1591 else if (cmd.argument() == "bibtex")
1592 code = Inset::BIBTEX_CODE;
1593 else if (cmd.argument() == "box")
1594 code = Inset::BOX_CODE;
1595 else if (cmd.argument() == "branch")
1596 code = Inset::BRANCH_CODE;
1597 else if (cmd.argument() == "citation")
1598 code = Inset::CITE_CODE;
1599 else if (cmd.argument() == "ert")
1600 code = Inset::ERT_CODE;
1601 else if (cmd.argument() == "external")
1602 code = Inset::EXTERNAL_CODE;
1603 else if (cmd.argument() == "float")
1604 code = Inset::FLOAT_CODE;
1605 else if (cmd.argument() == "graphics")
1606 code = Inset::GRAPHICS_CODE;
1607 else if (cmd.argument() == "include")
1608 code = Inset::INCLUDE_CODE;
1609 else if (cmd.argument() == "index")
1610 code = Inset::INDEX_CODE;
1611 else if (cmd.argument() == "nomenclature")
1612 code = Inset::NOMENCL_CODE;
1613 else if (cmd.argument() == "label")
1614 code = Inset::LABEL_CODE;
1615 else if (cmd.argument() == "note")
1616 code = Inset::NOTE_CODE;
1617 else if (cmd.argument() == "ref")
1618 code = Inset::REF_CODE;
1619 else if (cmd.argument() == "toc")
1620 code = Inset::TOC_CODE;
1621 else if (cmd.argument() == "url")
1622 code = Inset::URL_CODE;
1623 else if (cmd.argument() == "vspace")
1624 code = Inset::VSPACE_CODE;
1625 else if (cmd.argument() == "wrap")
1626 code = Inset::WRAP_CODE;
1627 else if (cmd.argument() == "listings")
1628 code = Inset::LISTINGS_CODE;
1631 case LFUN_ERT_INSERT:
1632 code = Inset::ERT_CODE;
1634 case LFUN_LISTING_INSERT:
1635 code = Inset::LISTINGS_CODE;
1637 case LFUN_FOOTNOTE_INSERT:
1638 code = Inset::FOOT_CODE;
1640 case LFUN_TABULAR_INSERT:
1641 code = Inset::TABULAR_CODE;
1643 case LFUN_MARGINALNOTE_INSERT:
1644 code = Inset::MARGIN_CODE;
1646 case LFUN_FLOAT_INSERT:
1647 case LFUN_FLOAT_WIDE_INSERT:
1648 code = Inset::FLOAT_CODE;
1650 case LFUN_WRAP_INSERT:
1651 code = Inset::WRAP_CODE;
1653 case LFUN_FLOAT_LIST:
1654 code = Inset::FLOAT_LIST_CODE;
1657 case LFUN_LIST_INSERT:
1658 code = Inset::LIST_CODE;
1660 case LFUN_THEOREM_INSERT:
1661 code = Inset::THEOREM_CODE;
1664 case LFUN_CAPTION_INSERT:
1665 code = Inset::CAPTION_CODE;
1667 case LFUN_NOTE_INSERT:
1668 code = Inset::NOTE_CODE;
1670 case LFUN_FLEX_INSERT: {
1671 code = Inset::FLEX_CODE;
1672 string s = cmd.getArg(0);
1673 InsetLayout il = cur.buffer().params().getTextClass().insetlayout(from_utf8(s));
1674 if (il.lyxtype != "charstyle" &&
1675 il.lyxtype != "custom" &&
1676 il.lyxtype != "element")
1680 case LFUN_BOX_INSERT:
1681 code = Inset::BOX_CODE;
1683 case LFUN_BRANCH_INSERT:
1684 code = Inset::BRANCH_CODE;
1685 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1688 case LFUN_LABEL_INSERT:
1689 code = Inset::LABEL_CODE;
1691 case LFUN_OPTIONAL_INSERT:
1692 code = Inset::OPTARG_CODE;
1693 enable = numberOfOptArgs(cur.paragraph())
1694 < cur.paragraph().layout()->optionalargs;
1696 case LFUN_ENVIRONMENT_INSERT:
1697 code = Inset::BOX_CODE;
1699 case LFUN_INDEX_INSERT:
1700 code = Inset::INDEX_CODE;
1702 case LFUN_INDEX_PRINT:
1703 code = Inset::INDEX_PRINT_CODE;
1705 case LFUN_NOMENCL_INSERT:
1706 code = Inset::NOMENCL_CODE;
1708 case LFUN_NOMENCL_PRINT:
1709 code = Inset::NOMENCL_PRINT_CODE;
1711 case LFUN_TOC_INSERT:
1712 code = Inset::TOC_CODE;
1714 case LFUN_HTML_INSERT:
1715 case LFUN_URL_INSERT:
1716 code = Inset::URL_CODE;
1718 case LFUN_QUOTE_INSERT:
1719 // always allow this, since we will inset a raw quote
1720 // if an inset is not allowed.
1722 case LFUN_HYPHENATION_POINT_INSERT:
1723 case LFUN_LIGATURE_BREAK_INSERT:
1724 case LFUN_HFILL_INSERT:
1725 case LFUN_MENU_SEPARATOR_INSERT:
1726 case LFUN_DOTS_INSERT:
1727 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
1728 code = Inset::SPECIALCHAR_CODE;
1730 case LFUN_SPACE_INSERT:
1731 // slight hack: we know this is allowed in math mode
1733 code = Inset::SPACE_CODE;
1736 case LFUN_INSET_MODIFY:
1737 // We need to disable this, because we may get called for a
1739 // InsetTabular::getStatus() -> InsetText::getStatus()
1740 // and we don't handle LFUN_INSET_MODIFY.
1744 case LFUN_FONT_EMPH:
1745 flag.setOnOff(font.emph() == Font::ON);
1748 case LFUN_FONT_NOUN:
1749 flag.setOnOff(font.noun() == Font::ON);
1752 case LFUN_FONT_BOLD:
1753 flag.setOnOff(font.series() == Font::BOLD_SERIES);
1756 case LFUN_FONT_SANS:
1757 flag.setOnOff(font.family() == Font::SANS_FAMILY);
1760 case LFUN_FONT_ROMAN:
1761 flag.setOnOff(font.family() == Font::ROMAN_FAMILY);
1764 case LFUN_FONT_TYPEWRITER:
1765 flag.setOnOff(font.family() == Font::TYPEWRITER_FAMILY);
1770 enable = cur.selection();
1774 if (cmd.argument().empty()) {
1775 if (theClipboard().isInternal())
1776 enable = cap::numberOfSelections() > 0;
1778 enable = !theClipboard().empty();
1780 string const arg = to_utf8(cmd.argument());
1781 if (isStrUnsignedInt(arg)) {
1782 unsigned int n = convert<unsigned int>(arg);
1783 enable = cap::numberOfSelections() > n;
1790 case LFUN_CLIPBOARD_PASTE:
1791 enable = !theClipboard().empty();
1794 case LFUN_PRIMARY_SELECTION_PASTE:
1795 enable = cur.selection() || !theSelection().empty();
1798 case LFUN_PARAGRAPH_MOVE_UP:
1799 enable = cur.pit() > 0 && !cur.selection();
1802 case LFUN_PARAGRAPH_MOVE_DOWN:
1803 enable = cur.pit() < cur.lastpit() && !cur.selection();
1806 case LFUN_INSET_DISSOLVE:
1807 enable = !isMainText(cur.bv().buffer()) && cur.inset().nargs() == 1;
1810 case LFUN_CHANGE_ACCEPT:
1811 case LFUN_CHANGE_REJECT:
1812 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
1813 // In principle, these LFUNs should only be enabled if there
1814 // is a change at the current position/in the current selection.
1815 // However, without proper optimizations, this will inevitably
1816 // result in unacceptable performance - just imagine a user who
1817 // wants to select the complete content of a long document.
1821 case LFUN_WORD_DELETE_FORWARD:
1822 case LFUN_WORD_DELETE_BACKWARD:
1823 case LFUN_LINE_DELETE:
1824 case LFUN_WORD_FORWARD:
1825 case LFUN_WORD_BACKWARD:
1826 case LFUN_CHAR_FORWARD:
1827 case LFUN_CHAR_FORWARD_SELECT:
1828 case LFUN_CHAR_BACKWARD:
1829 case LFUN_CHAR_BACKWARD_SELECT:
1831 case LFUN_UP_SELECT:
1833 case LFUN_DOWN_SELECT:
1834 case LFUN_PARAGRAPH_UP_SELECT:
1835 case LFUN_PARAGRAPH_DOWN_SELECT:
1836 case LFUN_SCREEN_UP_SELECT:
1837 case LFUN_SCREEN_DOWN_SELECT:
1838 case LFUN_LINE_BEGIN_SELECT:
1839 case LFUN_LINE_END_SELECT:
1840 case LFUN_WORD_FORWARD_SELECT:
1841 case LFUN_WORD_BACKWARD_SELECT:
1842 case LFUN_WORD_SELECT:
1843 case LFUN_PARAGRAPH_UP:
1844 case LFUN_PARAGRAPH_DOWN:
1845 case LFUN_LINE_BEGIN:
1847 case LFUN_BREAK_LINE:
1848 case LFUN_CHAR_DELETE_FORWARD:
1849 case LFUN_DELETE_FORWARD_SKIP:
1850 case LFUN_CHAR_DELETE_BACKWARD:
1851 case LFUN_DELETE_BACKWARD_SKIP:
1852 case LFUN_BREAK_PARAGRAPH:
1853 case LFUN_BREAK_PARAGRAPH_SKIP:
1854 case LFUN_PARAGRAPH_SPACING:
1855 case LFUN_INSET_INSERT:
1856 case LFUN_WORD_UPCASE:
1857 case LFUN_WORD_LOWCASE:
1858 case LFUN_WORD_CAPITALIZE:
1859 case LFUN_CHARS_TRANSPOSE:
1860 case LFUN_SERVER_GET_XY:
1861 case LFUN_SERVER_SET_XY:
1862 case LFUN_SERVER_GET_FONT:
1863 case LFUN_SERVER_GET_LAYOUT:
1865 case LFUN_DATE_INSERT:
1866 case LFUN_SELF_INSERT:
1867 case LFUN_LINE_INSERT:
1868 case LFUN_PAGEBREAK_INSERT:
1869 case LFUN_CLEARPAGE_INSERT:
1870 case LFUN_CLEARDOUBLEPAGE_INSERT:
1871 case LFUN_MATH_DISPLAY:
1872 case LFUN_MATH_IMPORT_SELECTION:
1873 case LFUN_MATH_MODE:
1874 case LFUN_MATH_MACRO:
1875 case LFUN_MATH_MATRIX:
1876 case LFUN_MATH_DELIM:
1877 case LFUN_MATH_BIGDELIM:
1878 case LFUN_MATH_INSERT:
1879 case LFUN_MATH_SUBSCRIPT:
1880 case LFUN_MATH_SUPERSCRIPT:
1881 case LFUN_FONT_DEFAULT:
1882 case LFUN_FONT_UNDERLINE:
1883 case LFUN_FONT_SIZE:
1885 case LFUN_FONT_FREE_APPLY:
1886 case LFUN_FONT_FREE_UPDATE:
1887 case LFUN_LAYOUT_PARAGRAPH:
1888 case LFUN_PARAGRAPH_UPDATE:
1889 case LFUN_ACCENT_UMLAUT:
1890 case LFUN_ACCENT_CIRCUMFLEX:
1891 case LFUN_ACCENT_GRAVE:
1892 case LFUN_ACCENT_ACUTE:
1893 case LFUN_ACCENT_TILDE:
1894 case LFUN_ACCENT_CEDILLA:
1895 case LFUN_ACCENT_MACRON:
1896 case LFUN_ACCENT_DOT:
1897 case LFUN_ACCENT_UNDERDOT:
1898 case LFUN_ACCENT_UNDERBAR:
1899 case LFUN_ACCENT_CARON:
1900 case LFUN_ACCENT_SPECIAL_CARON:
1901 case LFUN_ACCENT_BREVE:
1902 case LFUN_ACCENT_TIE:
1903 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1904 case LFUN_ACCENT_CIRCLE:
1905 case LFUN_ACCENT_OGONEK:
1906 case LFUN_THESAURUS_ENTRY:
1907 case LFUN_PARAGRAPH_PARAMS_APPLY:
1908 case LFUN_PARAGRAPH_PARAMS:
1910 case LFUN_BUFFER_END:
1911 case LFUN_BUFFER_BEGIN:
1912 case LFUN_BUFFER_BEGIN_SELECT:
1913 case LFUN_BUFFER_END_SELECT:
1914 case LFUN_UNICODE_INSERT:
1915 // these are handled in our dispatch()
1923 if (code != Inset::NO_CODE
1924 && (cur.empty() || !cur.inset().insetAllowed(code)))
1927 flag.enabled(enable);
1932 void Text::pasteString(Cursor & cur, docstring const & clip,
1935 cur.clearSelection();
1936 if (!clip.empty()) {
1939 insertStringAsParagraphs(cur, clip);
1941 insertStringAsLines(cur, clip);