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/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 static Font freefont(Font::ALL_IGNORE);
91 static bool toggleall = false;
93 static void toggleAndShow(Cursor & cur, Text * text,
94 Font const & font, bool toggleall = true)
96 text->toggleFree(cur, font, toggleall);
98 if (font.language() != ignore_language ||
99 font.number() != Font::IGNORE) {
100 TextMetrics const & tm = cur.bv().textMetrics(text);
101 if (cur.boundary() != tm.isRTLBoundary(cur.pit(),
102 cur.pos(), cur.real_current_font))
103 text->setCursor(cur, cur.pit(), cur.pos(),
104 false, !cur.boundary());
109 static void moveCursor(Cursor & cur, bool selecting)
111 if (selecting || cur.mark())
116 static void finishChange(Cursor & cur, bool selecting)
119 moveCursor(cur, selecting);
123 static void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
126 docstring sel = cur.selectionAsString(false);
128 // It may happen that sel is empty but there is a selection
129 replaceSelection(cur);
132 #ifdef ENABLE_ASSERTIONS
133 const int old_pos = cur.pos();
135 cur.insert(new InsetMathHull(hullSimple));
136 BOOST_ASSERT(old_pos == cur.pos());
137 cur.nextInset()->edit(cur, true);
138 // don't do that also for LFUN_MATH_MODE
139 // unless you want end up with always changing
140 // to mathrm when opening an inlined inset --
141 // I really hate "LyXfunc overloading"...
143 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
144 // Avoid an unnecessary undo step if cmd.argument
146 if (!cmd.argument().empty())
147 cur.dispatch(FuncRequest(LFUN_MATH_INSERT,
150 // create a macro if we see "\\newcommand"
151 // somewhere, and an ordinary formula
153 if (sel.find(from_ascii("\\newcommand")) == string::npos
154 && sel.find(from_ascii("\\def")) == string::npos)
156 InsetMathHull * formula = new InsetMathHull;
157 istringstream is(to_utf8(sel));
160 formula->read(cur.buffer(), lex);
161 if (formula->getType() == hullNone)
162 // Don't create pseudo formulas if
163 // delimiters are left out
164 formula->mutate(hullSimple);
167 cur.insert(new MathMacroTemplate(sel));
170 cur.message(from_utf8(N_("Math editor mode")));
174 static void specialChar(Cursor & cur, InsetSpecialChar::Kind kind)
177 cap::replaceSelection(cur);
178 cur.insert(new InsetSpecialChar(kind));
183 static bool doInsertInset(Cursor & cur, Text * text,
184 FuncRequest const & cmd, bool edit, bool pastesel)
186 Inset * inset = createInset(&cur.bv(), cmd);
192 if (cur.selection()) {
193 lyx::dispatch(FuncRequest(LFUN_CUT));
196 text->insertInset(cur, inset);
199 inset->edit(cur, true);
201 if (gotsel && pastesel) {
202 lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
203 // reset first par to default
204 if (cur.lastpit() != 0 || cur.lastpos() != 0) {
205 LayoutPtr const layout =
206 cur.buffer().params().getTextClass().defaultLayout();
207 cur.text()->paragraphs().begin()->layout(layout);
214 string const freefont2string()
216 return freefont.toString(toggleall);
220 void Text::number(Cursor & cur)
222 Font font(Font::ALL_IGNORE);
223 font.setNumber(Font::TOGGLE);
224 toggleAndShow(cur, this, font);
228 bool Text::isRTL(Buffer const & buffer, Paragraph const & par) const
230 return par.isRTL(buffer.params());
234 void Text::dispatch(Cursor & cur, FuncRequest & cmd)
236 LYXERR(Debug::ACTION) << "Text::dispatch: cmd: " << cmd << endl;
238 // FIXME: We use the update flag to indicates wether a singlePar or a
239 // full screen update is needed. We reset it here but shall we restore it
243 BOOST_ASSERT(cur.text() == this);
244 BufferView * bv = &cur.bv();
245 TextMetrics & tm = cur.bv().textMetrics(this);
246 CursorSlice oldTopSlice = cur.top();
247 bool oldBoundary = cur.boundary();
248 bool sel = cur.selection();
249 // Signals that, even if needsUpdate == false, an update of the
250 // cursor paragraph is required
251 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
252 LyXAction::SingleParUpdate);
253 // Signals that a full-screen update is required
254 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
255 LyXAction::NoUpdate) || singleParUpdate);
256 // Remember the old paragraph metric (_outer_ paragraph!)
257 ParagraphMetrics const & pm = cur.bv().parMetrics(
258 cur.bottom().text(), cur.bottom().pit());
259 Dimension olddim = pm.dim();
261 switch (cmd.action) {
263 case LFUN_PARAGRAPH_MOVE_DOWN: {
264 pit_type const pit = cur.pit();
265 recUndo(cur, pit, pit + 1);
267 std::swap(pars_[pit], pars_[pit + 1]);
268 updateLabels(cur.buffer());
274 case LFUN_PARAGRAPH_MOVE_UP: {
275 pit_type const pit = cur.pit();
276 recUndo(cur, pit - 1, pit);
278 std::swap(pars_[pit], pars_[pit - 1]);
279 updateLabels(cur.buffer());
285 case LFUN_APPENDIX: {
286 Paragraph & par = cur.paragraph();
287 bool start = !par.params().startOfAppendix();
289 // FIXME: The code below only makes sense at top level.
290 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
291 // ensure that we have only one start_of_appendix in this document
292 // FIXME: this don't work for multipart document!
293 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
294 if (pars_[tmp].params().startOfAppendix()) {
296 pars_[tmp].params().startOfAppendix(false);
302 par.params().startOfAppendix(start);
304 // we can set the refreshing parameters now
305 updateLabels(cur.buffer());
309 case LFUN_WORD_DELETE_FORWARD:
310 if (cur.selection()) {
311 cutSelection(cur, true, false);
313 deleteWordForward(cur);
314 finishChange(cur, false);
317 case LFUN_WORD_DELETE_BACKWARD:
318 if (cur.selection()) {
319 cutSelection(cur, true, false);
321 deleteWordBackward(cur);
322 finishChange(cur, false);
325 case LFUN_LINE_DELETE:
326 if (cur.selection()) {
327 cutSelection(cur, true, false);
329 tm.deleteLineForward(cur);
330 finishChange(cur, false);
333 case LFUN_BUFFER_BEGIN:
334 case LFUN_BUFFER_BEGIN_SELECT:
335 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
336 if (cur.depth() == 1) {
337 needsUpdate |= cursorTop(cur);
343 case LFUN_BUFFER_END:
344 case LFUN_BUFFER_END_SELECT:
345 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
346 if (cur.depth() == 1) {
347 needsUpdate |= cursorBottom(cur);
353 case LFUN_CHAR_FORWARD:
354 case LFUN_CHAR_FORWARD_SELECT:
355 //lyxerr << BOOST_CURRENT_FUNCTION
356 // << " LFUN_CHAR_FORWARD[SEL]:\n" << cur << endl;
357 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
358 if (reverseDirectionNeeded(cur))
359 needsUpdate |= cursorLeft(cur);
361 needsUpdate |= cursorRight(cur);
363 if (!needsUpdate && oldTopSlice == cur.top()
364 && cur.boundary() == oldBoundary) {
366 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
370 case LFUN_CHAR_BACKWARD:
371 case LFUN_CHAR_BACKWARD_SELECT:
372 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
373 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
374 if (reverseDirectionNeeded(cur))
375 needsUpdate |= cursorRight(cur);
377 needsUpdate |= cursorLeft(cur);
379 if (!needsUpdate && oldTopSlice == cur.top()
380 && cur.boundary() == oldBoundary) {
382 cmd = FuncRequest(LFUN_FINISHED_LEFT);
387 case LFUN_DOWN_SELECT:
390 // stop/start the selection
391 bool select = cmd.action == LFUN_DOWN_SELECT ||
392 cmd.action == LFUN_UP_SELECT;
393 cur.selHandle(select);
395 // move cursor up/down
396 bool up = cmd.action == LFUN_UP_SELECT || cmd.action == LFUN_UP;
397 bool const successful = cur.upDownInText(up, needsUpdate);
399 // notify insets which were left and get their update flags
400 notifyCursorLeaves(cur.beforeDispatchCursor(), cur);
403 // redraw if you leave mathed (for the decorations)
404 needsUpdate |= cur.beforeDispatchCursor().inMathed();
411 case LFUN_PARAGRAPH_UP:
412 case LFUN_PARAGRAPH_UP_SELECT:
413 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
414 needsUpdate |= cursorUpParagraph(cur);
417 case LFUN_PARAGRAPH_DOWN:
418 case LFUN_PARAGRAPH_DOWN_SELECT:
419 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
420 needsUpdate |= cursorDownParagraph(cur);
423 case LFUN_SCREEN_UP_SELECT:
424 needsUpdate |= cur.selHandle(true);
425 if (cur.pit() == 0 && cur.textRow().pos() == 0)
428 tm.cursorPrevious(cur);
432 case LFUN_SCREEN_DOWN_SELECT:
433 needsUpdate |= cur.selHandle(true);
434 if (cur.pit() == cur.lastpit()
435 && cur.textRow().endpos() == cur.lastpos())
442 case LFUN_LINE_BEGIN:
443 case LFUN_LINE_BEGIN_SELECT:
444 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
445 needsUpdate |= tm.cursorHome(cur);
449 case LFUN_LINE_END_SELECT:
450 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
451 needsUpdate |= tm.cursorEnd(cur);
454 case LFUN_WORD_FORWARD:
455 case LFUN_WORD_FORWARD_SELECT:
456 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
457 if (reverseDirectionNeeded(cur))
458 needsUpdate |= cursorLeftOneWord(cur);
460 needsUpdate |= cursorRightOneWord(cur);
463 case LFUN_WORD_BACKWARD:
464 case LFUN_WORD_BACKWARD_SELECT:
465 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
466 if (reverseDirectionNeeded(cur))
467 needsUpdate |= cursorRightOneWord(cur);
469 needsUpdate |= cursorLeftOneWord(cur);
472 case LFUN_WORD_SELECT: {
473 selectWord(cur, WHOLE_WORD);
474 finishChange(cur, true);
478 case LFUN_BREAK_LINE: {
479 // Not allowed by LaTeX (labels or empty par)
480 if (cur.pos() > cur.paragraph().beginOfBody()) {
481 // this avoids a double undo
482 // FIXME: should not be needed, ideally
483 if (!cur.selection())
485 cap::replaceSelection(cur);
486 cur.insert(new InsetNewline);
488 moveCursor(cur, false);
493 case LFUN_CHAR_DELETE_FORWARD:
494 if (!cur.selection()) {
495 if (cur.pos() == cur.paragraph().size())
496 // Par boundary, force full-screen update
497 singleParUpdate = false;
498 needsUpdate |= erase(cur);
500 // It is possible to make it a lot faster still
501 // just comment out the line below...
503 cutSelection(cur, true, false);
504 singleParUpdate = false;
506 moveCursor(cur, false);
509 case LFUN_DELETE_FORWARD_SKIP:
510 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
511 if (!cur.selection()) {
512 if (cur.pos() == cur.lastpos()) {
519 cutSelection(cur, true, false);
524 case LFUN_CHAR_DELETE_BACKWARD:
525 if (!cur.selection()) {
526 if (bv->getIntl().getTransManager().backspace()) {
527 // Par boundary, full-screen update
529 singleParUpdate = false;
530 needsUpdate |= backspace(cur);
532 // It is possible to make it a lot faster still
533 // just comment out the line below...
536 cutSelection(cur, true, false);
537 singleParUpdate = false;
541 case LFUN_DELETE_BACKWARD_SKIP:
542 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
543 if (!cur.selection()) {
545 //CursorSlice cur = cursor();
549 cutSelection(cur, true, false);
553 case LFUN_BREAK_PARAGRAPH:
554 cap::replaceSelection(cur);
555 breakParagraph(cur, false);
559 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
560 cap::replaceSelection(cur);
561 breakParagraph(cur, true);
565 case LFUN_BREAK_PARAGRAPH_SKIP: {
566 // When at the beginning of a paragraph, remove
567 // indentation. Otherwise, do the same as LFUN_BREAK_PARAGRAPH.
568 cap::replaceSelection(cur);
570 cur.paragraph().params().labelWidthString(docstring());
572 breakParagraph(cur, false);
578 // With the creation of LFUN_PARAGRAPH_PARAMS, this is now redundant,
579 // as its duties can be performed there. Should it be removed??
580 // FIXME For now, it can just dispatch LFUN_PARAGRAPH_PARAMS...
581 case LFUN_PARAGRAPH_SPACING: {
582 Paragraph & par = cur.paragraph();
583 Spacing::Space cur_spacing = par.params().spacing().getSpace();
584 string cur_value = "1.0";
585 if (cur_spacing == Spacing::Other)
586 cur_value = par.params().spacing().getValueAsString();
588 istringstream is(to_utf8(cmd.argument()));
591 Spacing::Space new_spacing = cur_spacing;
592 string new_value = cur_value;
594 lyxerr << "Missing argument to `paragraph-spacing'"
596 } else if (tmp == "single") {
597 new_spacing = Spacing::Single;
598 } else if (tmp == "onehalf") {
599 new_spacing = Spacing::Onehalf;
600 } else if (tmp == "double") {
601 new_spacing = Spacing::Double;
602 } else if (tmp == "other") {
603 new_spacing = Spacing::Other;
604 string tmpval = "0.0";
606 lyxerr << "new_value = " << tmpval << endl;
609 } else if (tmp == "default") {
610 new_spacing = Spacing::Default;
612 lyxerr << to_utf8(_("Unknown spacing argument: "))
613 << to_utf8(cmd.argument()) << endl;
615 if (cur_spacing != new_spacing || cur_value != new_value)
616 par.params().spacing(Spacing(new_spacing, new_value));
620 case LFUN_INSET_INSERT: {
622 Inset * inset = createInset(bv, cmd);
624 // FIXME (Abdel 01/02/2006):
625 // What follows would be a partial fix for bug 2154:
626 // http://bugzilla.lyx.org/show_bug.cgi?id=2154
627 // This automatically put the label inset _after_ a
628 // numbered section. It should be possible to extend the mechanism
629 // to any kind of LateX environement.
630 // The correct way to fix that bug would be at LateX generation.
631 // I'll let the code here for reference as it could be used for some
632 // other feature like "automatic labelling".
634 Paragraph & par = pars_[cur.pit()];
635 if (inset->lyxCode() == Inset::LABEL_CODE
636 && par.layout()->labeltype == LABEL_COUNTER) {
637 // Go to the end of the paragraph
638 // Warning: Because of Change-Tracking, the last
639 // position is 'size()' and not 'size()-1':
640 cur.pos() = par.size();
641 // Insert a new paragraph
642 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
647 cutSelection(cur, true, false);
648 insertInset(cur, inset);
654 case LFUN_INSET_DISSOLVE:
655 needsUpdate |= dissolveInset(cur);
658 case LFUN_INSET_SETTINGS:
659 cur.inset().showInsetDialog(bv);
662 case LFUN_SPACE_INSERT:
663 if (cur.paragraph().layout()->free_spacing)
664 insertChar(cur, ' ');
666 doInsertInset(cur, this, cmd, false, false);
669 moveCursor(cur, false);
672 case LFUN_HYPHENATION_POINT_INSERT:
673 specialChar(cur, InsetSpecialChar::HYPHENATION);
676 case LFUN_LIGATURE_BREAK_INSERT:
677 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
680 case LFUN_DOTS_INSERT:
681 specialChar(cur, InsetSpecialChar::LDOTS);
684 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
685 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
688 case LFUN_MENU_SEPARATOR_INSERT:
689 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
692 case LFUN_WORD_UPCASE:
693 changeCase(cur, Text::text_uppercase);
696 case LFUN_WORD_LOWCASE:
697 changeCase(cur, Text::text_lowercase);
700 case LFUN_WORD_CAPITALIZE:
701 changeCase(cur, Text::text_capitalization);
704 case LFUN_CHARS_TRANSPOSE:
709 cur.message(_("Paste"));
710 cap::replaceSelection(cur);
711 if (cmd.argument().empty() && !theClipboard().isInternal())
712 pasteClipboard(cur, bv->buffer().errorList("Paste"));
714 string const arg(to_utf8(cmd.argument()));
715 pasteFromStack(cur, bv->buffer().errorList("Paste"),
716 isStrUnsignedInt(arg) ?
717 convert<unsigned int>(arg) :
720 bv->buffer().errors("Paste");
721 cur.clearSelection(); // bug 393
726 cutSelection(cur, true, true);
727 cur.message(_("Cut"));
732 cur.message(_("Copy"));
735 case LFUN_SERVER_GET_XY:
736 cur.message(from_utf8(
737 convert<string>(tm.cursorX(cur.top(), cur.boundary()))
738 + ' ' + convert<string>(tm.cursorY(cur.top(), cur.boundary()))));
741 case LFUN_SERVER_SET_XY: {
744 istringstream is(to_utf8(cmd.argument()));
747 lyxerr << "SETXY: Could not parse coordinates in '"
748 << to_utf8(cmd.argument()) << std::endl;
750 tm.setCursorFromCoordinates(cur, x, y);
754 case LFUN_SERVER_GET_FONT:
755 if (cur.current_font.shape() == Font::ITALIC_SHAPE)
756 cur.message(from_ascii("E"));
757 else if (cur.current_font.shape() == Font::SMALLCAPS_SHAPE)
758 cur.message(from_ascii("N"));
760 cur.message(from_ascii("0"));
763 case LFUN_SERVER_GET_LAYOUT:
764 cur.message(cur.paragraph().layout()->name());
768 docstring layout = cmd.argument();
769 LYXERR(Debug::INFO) << "LFUN_LAYOUT: (arg) " << to_utf8(layout) << endl;
771 docstring const old_layout = cur.paragraph().layout()->name();
773 // Derive layout number from given argument (string)
774 // and current buffer's textclass (number)
775 TextClass const & tclass = bv->buffer().params().getTextClass();
777 layout = tclass.defaultLayoutName();
778 bool hasLayout = tclass.hasLayout(layout);
780 // If the entry is obsolete, use the new one instead.
782 docstring const & obs = tclass[layout]->obsoleted_by();
788 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
789 from_utf8(N_(" not known")));
793 bool change_layout = (old_layout != layout);
795 if (!change_layout && cur.selection() &&
796 cur.selBegin().pit() != cur.selEnd().pit())
798 pit_type spit = cur.selBegin().pit();
799 pit_type epit = cur.selEnd().pit() + 1;
800 while (spit != epit) {
801 if (pars_[spit].layout()->name() != old_layout) {
802 change_layout = true;
810 setLayout(cur, layout);
815 case LFUN_CLIPBOARD_PASTE:
816 cur.clearSelection();
817 pasteClipboard(cur, bv->buffer().errorList("Paste"),
818 cmd.argument() == "paragraph");
819 bv->buffer().errors("Paste");
822 case LFUN_PRIMARY_SELECTION_PASTE:
823 pasteString(cur, theSelection().get(),
824 cmd.argument() == "paragraph");
827 case LFUN_UNICODE_INSERT: {
828 if (cmd.argument().empty())
830 docstring hexstring = cmd.argument();
831 if (lyx::support::isHex(hexstring)) {
832 char_type c = lyx::support::hexToInt(hexstring);
833 if (c >= 32 && c < 0x10ffff) {
834 lyxerr << "Inserting c: " << c << endl;
835 docstring s = docstring(1, c);
836 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
842 case LFUN_QUOTE_INSERT: {
843 Paragraph & par = cur.paragraph();
844 pos_type pos = cur.pos();
845 BufferParams const & bufparams = bv->buffer().params();
846 LayoutPtr const & style = par.layout();
847 if (!style->pass_thru
848 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
849 // this avoids a double undo
850 // FIXME: should not be needed, ideally
851 if (!cur.selection())
853 cap::replaceSelection(cur);
858 else if (cur.prevInset() && cur.prevInset()->isSpace())
861 c = par.getChar(pos - 1);
862 string arg = to_utf8(cmd.argument());
864 cur.insert(new InsetQuotes(c,
865 bufparams.quotes_language,
866 InsetQuotes::SingleQ));
868 cur.insert(new InsetQuotes(c,
869 bufparams.quotes_language,
870 InsetQuotes::DoubleQ));
874 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
878 case LFUN_DATE_INSERT: {
879 string const format = cmd.argument().empty()
880 ? lyxrc.date_insert_format : to_utf8(cmd.argument());
881 string const time = formatted_time(current_time(), format);
882 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, time));
886 case LFUN_MOUSE_TRIPLE:
887 if (cmd.button() == mouse_button::button1) {
896 case LFUN_MOUSE_DOUBLE:
897 if (cmd.button() == mouse_button::button1) {
898 selectWord(cur, WHOLE_WORD_STRICT);
903 // Single-click on work area
904 case LFUN_MOUSE_PRESS: {
905 // Right click on a footnote flag opens float menu
906 if (cmd.button() == mouse_button::button3)
907 cur.clearSelection();
910 bool update = bv->mouseSetCursor(cur);
912 // Insert primary selection with middle mouse
913 // if there is a local selection in the current buffer,
915 if (cmd.button() == mouse_button::button2) {
916 if (cap::selection()) {
917 // Copy the selection buffer to the clipboard
918 // stack, because we want it to appear in the
919 // "Edit->Paste recent" menu.
920 cap::copySelectionToStack();
922 cap::pasteSelection(bv->cursor(),
923 bv->buffer().errorList("Paste"));
924 bv->buffer().errors("Paste");
925 bv->buffer().markDirty();
928 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
932 // we have to update after dEPM triggered
933 if (!update && cmd.button() == mouse_button::button1) {
941 case LFUN_MOUSE_MOTION: {
942 // Only use motion with button 1
943 //if (cmd.button() != mouse_button::button1)
946 // ignore motions deeper nested than the real anchor
947 Cursor & bvcur = cur.bv().cursor();
948 if (bvcur.anchor_.hasPart(cur)) {
949 CursorSlice old = bvcur.top();
951 int const wh = bv->workHeight();
952 int const y = std::max(0, std::min(wh - 1, cmd.y));
954 tm.setCursorFromCoordinates(cur, cmd.x, y);
955 cur.setTargetX(cmd.x);
957 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
959 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
960 // This is to allow jumping over large insets
961 if (cur.top() == old) {
963 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
965 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
968 if (cur.top() == old)
972 bvcur.setCursor(cur);
973 bvcur.selection() = true;
974 //lyxerr << "MOTION: " << bv->cursor() << endl;
982 case LFUN_MOUSE_RELEASE: {
983 if (cmd.button() == mouse_button::button2)
986 if (cmd.button() == mouse_button::button1) {
987 // if there is new selection, update persistent
988 // selection, otherwise, single click does not
989 // clear persistent selection buffer
990 if (cur.selection()) {
992 // if double click, cur is moved to the end of word by selectWord
993 // but bvcur is current mouse position
994 Cursor & bvcur = cur.bv().cursor();
995 bvcur.selection() = true;
1004 case LFUN_SELF_INSERT: {
1005 if (cmd.argument().empty())
1008 // Automatically delete the currently selected
1009 // text and replace it with what is being
1010 // typed in now. Depends on lyxrc settings
1011 // "auto_region_delete", which defaults to
1014 if (lyxrc.auto_region_delete && cur.selection()) {
1015 cutSelection(cur, false, false);
1016 // When change tracking is set to off, the metrics update
1017 // mechanism correctly detects if a full update is needed or not.
1018 // This detection fails when a selection spans multiple rows and
1019 // change tracking is enabled because the paragraph metrics stays
1020 // the same. In this case, we force the full update:
1021 // (see http://bugzilla.lyx.org/show_bug.cgi?id=3992)
1022 if (cur.buffer().params().trackChanges)
1023 cur.updateFlags(Update::Force);
1026 cur.clearSelection();
1027 Font const old_font = cur.real_current_font;
1029 docstring::const_iterator cit = cmd.argument().begin();
1030 docstring::const_iterator end = cmd.argument().end();
1031 for (; cit != end; ++cit)
1032 bv->translateAndInsert(*cit, this, cur);
1035 moveCursor(cur, false);
1039 case LFUN_URL_INSERT: {
1040 InsetCommandParams p("url");
1042 if (cur.selection()) {
1043 content = cur.selectionAsString(false);
1044 cutSelection(cur, true, false);
1046 p["target"] = (cmd.argument().empty()) ?
1047 content : cmd.argument();
1048 string const data = InsetCommandMailer::params2string("url", p);
1049 if (p["target"].empty()) {
1050 bv->showInsetDialog("url", data, 0);
1052 FuncRequest fr(LFUN_INSET_INSERT, data);
1058 case LFUN_HTML_INSERT: {
1059 InsetCommandParams p("htmlurl");
1061 if (cur.selection()) {
1062 content = cur.selectionAsString(false);
1063 cutSelection(cur, true, false);
1065 p["target"] = (cmd.argument().empty()) ?
1066 content : cmd.argument();
1067 string const data = InsetCommandMailer::params2string("url", p);
1068 if (p["target"].empty()) {
1069 bv->showInsetDialog("url", data, 0);
1071 FuncRequest fr(LFUN_INSET_INSERT, data);
1077 case LFUN_LABEL_INSERT: {
1078 InsetCommandParams p("label");
1079 // Try to generate a valid label
1080 p["name"] = (cmd.argument().empty()) ?
1081 cur.getPossibleLabel() :
1083 string const data = InsetCommandMailer::params2string("label", p);
1085 if (cmd.argument().empty()) {
1086 bv->showInsetDialog("label", data, 0);
1088 FuncRequest fr(LFUN_INSET_INSERT, data);
1096 case LFUN_LIST_INSERT:
1097 case LFUN_THEOREM_INSERT:
1099 case LFUN_CAPTION_INSERT:
1100 // Open the inset, and move the current selection
1102 doInsertInset(cur, this, cmd, true, true);
1104 updateLabels(bv->buffer());
1106 case LFUN_NOTE_INSERT:
1107 case LFUN_FLEX_INSERT:
1108 case LFUN_BOX_INSERT:
1109 case LFUN_BRANCH_INSERT:
1110 case LFUN_BIBITEM_INSERT:
1111 case LFUN_ERT_INSERT:
1112 case LFUN_LISTING_INSERT:
1113 case LFUN_FOOTNOTE_INSERT:
1114 case LFUN_MARGINALNOTE_INSERT:
1115 case LFUN_OPTIONAL_INSERT:
1116 case LFUN_ENVIRONMENT_INSERT:
1117 // Open the inset, and move the current selection
1119 doInsertInset(cur, this, cmd, true, true);
1123 case LFUN_TABULAR_INSERT:
1124 // if there were no arguments, just open the dialog
1125 if (doInsertInset(cur, this, cmd, false, true))
1128 bv->showDialog("tabularcreate");
1132 case LFUN_FLOAT_INSERT:
1133 case LFUN_FLOAT_WIDE_INSERT:
1134 case LFUN_WRAP_INSERT: {
1135 bool content = cur.selection(); // will some text be moved into the inset?
1137 doInsertInset(cur, this, cmd, true, true);
1139 ParagraphList & pars = cur.text()->paragraphs();
1141 TextClass const & tclass = bv->buffer().params().getTextClass();
1143 // add a separate paragraph for the caption inset
1144 pars.push_back(Paragraph());
1145 pars.back().setInsetOwner(pars[0].inInset());
1146 pars.back().layout(tclass.defaultLayout());
1148 int cap_pit = pars.size() - 1;
1150 // if an empty inset was created, we create an additional empty
1151 // paragraph at the bottom so that the user can choose where to put
1152 // the graphics (or table).
1154 pars.push_back(Paragraph());
1155 pars.back().setInsetOwner(pars[0].inInset());
1156 pars.back().layout(tclass.defaultLayout());
1160 // reposition the cursor to the caption
1161 cur.pit() = cap_pit;
1163 // FIXME: This Text/Cursor dispatch handling is a mess!
1164 // We cannot use Cursor::dispatch here it needs access to up to
1166 FuncRequest cmd_caption(LFUN_CAPTION_INSERT);
1167 cur.text()->dispatch(cur, cmd_caption);
1168 cur.updateFlags(Update::Force);
1169 // FIXME: When leaving the Float (or Wrap) inset we should
1170 // delete any empty paragraph left above or below the
1175 case LFUN_INDEX_INSERT:
1176 case LFUN_NOMENCL_INSERT: {
1177 Inset * inset = createInset(&cur.bv(), cmd);
1181 cur.clearSelection();
1182 insertInset(cur, inset);
1183 // Show the dialog for the nomenclature entry, since the
1184 // description entry still needs to be filled in.
1185 if (cmd.action == LFUN_NOMENCL_INSERT)
1186 inset->edit(cur, true);
1191 case LFUN_INDEX_PRINT:
1192 case LFUN_NOMENCL_PRINT:
1193 case LFUN_TOC_INSERT:
1194 case LFUN_HFILL_INSERT:
1195 case LFUN_LINE_INSERT:
1196 case LFUN_PAGEBREAK_INSERT:
1197 case LFUN_CLEARPAGE_INSERT:
1198 case LFUN_CLEARDOUBLEPAGE_INSERT:
1200 doInsertInset(cur, this, cmd, false, false);
1204 case LFUN_DEPTH_DECREMENT:
1205 changeDepth(cur, DEC_DEPTH);
1208 case LFUN_DEPTH_INCREMENT:
1209 changeDepth(cur, INC_DEPTH);
1212 case LFUN_MATH_DISPLAY:
1213 mathDispatch(cur, cmd, true);
1216 case LFUN_MATH_IMPORT_SELECTION:
1217 case LFUN_MATH_MODE:
1218 if (cmd.argument() == "on")
1219 // don't pass "on" as argument
1220 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1222 mathDispatch(cur, cmd, false);
1225 case LFUN_MATH_MACRO:
1226 if (cmd.argument().empty())
1227 cur.errorMessage(from_utf8(N_("Missing argument")));
1229 string s = to_utf8(cmd.argument());
1230 string const s1 = token(s, ' ', 1);
1231 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1232 string const s2 = token(s, ' ', 2);
1233 string const type = s2.empty() ? "newcommand" : s2;
1234 cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, from_utf8(type)));
1235 //cur.nextInset()->edit(cur, true);
1239 // passthrough hat and underscore outside mathed:
1240 case LFUN_MATH_SUBSCRIPT:
1241 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1243 case LFUN_MATH_SUPERSCRIPT:
1244 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1247 case LFUN_MATH_INSERT:
1248 case LFUN_MATH_MATRIX:
1249 case LFUN_MATH_DELIM:
1250 case LFUN_MATH_BIGDELIM: {
1251 if (cur.selection())
1252 cur.clearSelection();
1253 // FIXME: instead of the above, this one
1254 // should be used (but it asserts with Bidi enabled)
1255 // cf. http://bugzilla.lyx.org/show_bug.cgi?id=4055
1256 // cap::replaceSelection(cur);
1257 cur.insert(new InsetMathHull(hullSimple));
1258 checkAndActivateInset(cur, true);
1259 BOOST_ASSERT(cur.inMathed());
1264 case LFUN_FONT_EMPH: {
1265 Font font(Font::ALL_IGNORE);
1266 font.setEmph(Font::TOGGLE);
1267 toggleAndShow(cur, this, font);
1271 case LFUN_FONT_BOLD: {
1272 Font font(Font::ALL_IGNORE);
1273 font.setSeries(Font::BOLD_SERIES);
1274 toggleAndShow(cur, this, font);
1278 case LFUN_FONT_NOUN: {
1279 Font font(Font::ALL_IGNORE);
1280 font.setNoun(Font::TOGGLE);
1281 toggleAndShow(cur, this, font);
1285 case LFUN_FONT_TYPEWRITER: {
1286 Font font(Font::ALL_IGNORE);
1287 font.setFamily(Font::TYPEWRITER_FAMILY); // no good
1288 toggleAndShow(cur, this, font);
1292 case LFUN_FONT_SANS: {
1293 Font font(Font::ALL_IGNORE);
1294 font.setFamily(Font::SANS_FAMILY);
1295 toggleAndShow(cur, this, font);
1299 case LFUN_FONT_ROMAN: {
1300 Font font(Font::ALL_IGNORE);
1301 font.setFamily(Font::ROMAN_FAMILY);
1302 toggleAndShow(cur, this, font);
1306 case LFUN_FONT_DEFAULT: {
1307 Font font(Font::ALL_INHERIT, ignore_language);
1308 toggleAndShow(cur, this, font);
1312 case LFUN_FONT_UNDERLINE: {
1313 Font font(Font::ALL_IGNORE);
1314 font.setUnderbar(Font::TOGGLE);
1315 toggleAndShow(cur, this, font);
1319 case LFUN_FONT_SIZE: {
1320 Font font(Font::ALL_IGNORE);
1321 font.setLyXSize(to_utf8(cmd.argument()));
1322 toggleAndShow(cur, this, font);
1326 case LFUN_LANGUAGE: {
1327 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1330 Font font(Font::ALL_IGNORE);
1331 font.setLanguage(lang);
1332 toggleAndShow(cur, this, font);
1336 case LFUN_FONT_FREE_APPLY:
1337 toggleAndShow(cur, this, freefont, toggleall);
1338 cur.message(_("Character set"));
1341 // Set the freefont using the contents of \param data dispatched from
1342 // the frontends and apply it at the current cursor location.
1343 case LFUN_FONT_FREE_UPDATE: {
1346 if (font.fromString(to_utf8(cmd.argument()), toggle)) {
1349 toggleAndShow(cur, this, freefont, toggleall);
1350 cur.message(_("Character set"));
1355 case LFUN_FINISHED_LEFT:
1356 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1357 if (reverseDirectionNeeded(cur)) {
1359 cur.setCurrentFont();
1363 case LFUN_FINISHED_RIGHT:
1364 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1365 if (!reverseDirectionNeeded(cur)) {
1367 cur.setCurrentFont();
1371 case LFUN_LAYOUT_PARAGRAPH: {
1373 params2string(cur.paragraph(), data);
1374 data = "show\n" + data;
1375 bv->showDialogWithData("paragraph", data);
1379 case LFUN_PARAGRAPH_UPDATE: {
1381 params2string(cur.paragraph(), data);
1383 // Will the paragraph accept changes from the dialog?
1384 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1386 data = "update " + convert<string>(accept) + '\n' + data;
1387 bv->updateDialog("paragraph", data);
1391 case LFUN_ACCENT_UMLAUT:
1392 case LFUN_ACCENT_CIRCUMFLEX:
1393 case LFUN_ACCENT_GRAVE:
1394 case LFUN_ACCENT_ACUTE:
1395 case LFUN_ACCENT_TILDE:
1396 case LFUN_ACCENT_CEDILLA:
1397 case LFUN_ACCENT_MACRON:
1398 case LFUN_ACCENT_DOT:
1399 case LFUN_ACCENT_UNDERDOT:
1400 case LFUN_ACCENT_UNDERBAR:
1401 case LFUN_ACCENT_CARON:
1402 case LFUN_ACCENT_SPECIAL_CARON:
1403 case LFUN_ACCENT_BREVE:
1404 case LFUN_ACCENT_TIE:
1405 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1406 case LFUN_ACCENT_CIRCLE:
1407 case LFUN_ACCENT_OGONEK:
1408 theLyXFunc().handleKeyFunc(cmd.action);
1409 if (!cmd.argument().empty())
1410 // FIXME: Are all these characters encoded in one byte in utf8?
1411 bv->translateAndInsert(cmd.argument()[0], this, cur);
1414 case LFUN_FLOAT_LIST: {
1415 TextClass const & tclass = bv->buffer().params().getTextClass();
1416 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1418 if (cur.selection())
1419 cutSelection(cur, true, false);
1420 breakParagraph(cur);
1422 if (cur.lastpos() != 0) {
1424 breakParagraph(cur);
1427 setLayout(cur, tclass.defaultLayoutName());
1428 ParagraphParameters p;
1429 setParagraphs(cur, p);
1430 insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1433 lyxerr << "Non-existent float type: "
1434 << to_utf8(cmd.argument()) << endl;
1439 case LFUN_CHANGE_ACCEPT: {
1440 acceptOrRejectChanges(cur, ACCEPT);
1444 case LFUN_CHANGE_REJECT: {
1445 acceptOrRejectChanges(cur, REJECT);
1449 case LFUN_THESAURUS_ENTRY: {
1450 docstring arg = cmd.argument();
1452 arg = cur.selectionAsString(false);
1454 if (arg.size() > 100 || arg.empty()) {
1455 // Get word or selection
1456 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1457 arg = cur.selectionAsString(false);
1460 bv->showDialogWithData("thesaurus", to_utf8(arg));
1464 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1465 // Given data, an encoding of the ParagraphParameters
1466 // generated in the Paragraph dialog, this function sets
1467 // the current paragraph, or currently selected paragraphs,
1469 // NOTE: This function overrides all existing settings.
1470 setParagraphs(cur, cmd.argument());
1471 cur.message(_("Paragraph layout set"));
1475 case LFUN_PARAGRAPH_PARAMS: {
1476 // Given data, an encoding of the ParagraphParameters as we'd
1477 // find them in a LyX file, this function modifies the current paragraph,
1478 // or currently selected paragraphs.
1479 // NOTE: This function only modifies, and does not override, existing
1481 setParagraphs(cur, cmd.argument(), true);
1482 cur.message(_("Paragraph layout set"));
1487 if (cur.selection()) {
1488 cur.selection() = false;
1491 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1496 LYXERR(Debug::ACTION)
1497 << BOOST_CURRENT_FUNCTION
1498 << ": Command " << cmd
1499 << " not DISPATCHED by Text" << endl;
1504 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1506 // FIXME: The cursor flag is reset two lines below
1507 // so we need to check here if some of the LFUN did touch that.
1508 // for now only Text::erase() and Text::backspace() do that.
1509 // The plan is to verify all the LFUNs and then to remove this
1510 // singleParUpdate boolean altogether.
1511 if (cur.result().update() & Update::Force) {
1512 singleParUpdate = false;
1516 // FIXME: the following code should go in favor of fine grained
1517 // update flag treatment.
1518 if (singleParUpdate) {
1519 // Inserting characters does not change par height
1520 ParagraphMetrics const & pms
1521 = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
1522 if (pms.dim().height()
1523 == olddim.height()) {
1524 // if so, update _only_ this paragraph
1525 cur.updateFlags(Update::SinglePar |
1527 Update::MultiParSel);
1534 && &oldTopSlice.inset() == &cur.inset()
1535 && oldTopSlice.idx() == cur.idx()
1536 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1537 && !cur.selection())
1538 // FIXME: it would be better if we could just do this
1540 //if (cur.result().update() != Update::FitCursor)
1543 // But some LFUNs do not set Update::FitCursor when needed, so we
1544 // do it for all. This is not very harmfull as FitCursor will provoke
1545 // a full redraw only if needed but still, a proper review of all LFUN
1546 // should be done and this needsUpdate boolean can then be removed.
1547 cur.updateFlags(Update::FitCursor);
1549 cur.updateFlags(Update::Force | Update::FitCursor);
1553 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
1554 FuncStatus & flag) const
1556 BOOST_ASSERT(cur.text() == this);
1558 Font const & font = cur.real_current_font;
1560 Inset::Code code = Inset::NO_CODE;
1562 switch (cmd.action) {
1564 case LFUN_DEPTH_DECREMENT:
1565 enable = changeDepthAllowed(cur, DEC_DEPTH);
1568 case LFUN_DEPTH_INCREMENT:
1569 enable = changeDepthAllowed(cur, INC_DEPTH);
1573 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1576 case LFUN_BIBITEM_INSERT:
1577 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO
1581 case LFUN_DIALOG_SHOW_NEW_INSET:
1582 if (cmd.argument() == "bibitem")
1583 code = Inset::BIBITEM_CODE;
1584 else if (cmd.argument() == "bibtex")
1585 code = Inset::BIBTEX_CODE;
1586 else if (cmd.argument() == "box")
1587 code = Inset::BOX_CODE;
1588 else if (cmd.argument() == "branch")
1589 code = Inset::BRANCH_CODE;
1590 else if (cmd.argument() == "citation")
1591 code = Inset::CITE_CODE;
1592 else if (cmd.argument() == "ert")
1593 code = Inset::ERT_CODE;
1594 else if (cmd.argument() == "external")
1595 code = Inset::EXTERNAL_CODE;
1596 else if (cmd.argument() == "float")
1597 code = Inset::FLOAT_CODE;
1598 else if (cmd.argument() == "graphics")
1599 code = Inset::GRAPHICS_CODE;
1600 else if (cmd.argument() == "include")
1601 code = Inset::INCLUDE_CODE;
1602 else if (cmd.argument() == "index")
1603 code = Inset::INDEX_CODE;
1604 else if (cmd.argument() == "nomenclature")
1605 code = Inset::NOMENCL_CODE;
1606 else if (cmd.argument() == "label")
1607 code = Inset::LABEL_CODE;
1608 else if (cmd.argument() == "note")
1609 code = Inset::NOTE_CODE;
1610 else if (cmd.argument() == "ref")
1611 code = Inset::REF_CODE;
1612 else if (cmd.argument() == "toc")
1613 code = Inset::TOC_CODE;
1614 else if (cmd.argument() == "url")
1615 code = Inset::URL_CODE;
1616 else if (cmd.argument() == "vspace")
1617 code = Inset::VSPACE_CODE;
1618 else if (cmd.argument() == "wrap")
1619 code = Inset::WRAP_CODE;
1620 else if (cmd.argument() == "listings")
1621 code = Inset::LISTINGS_CODE;
1624 case LFUN_ERT_INSERT:
1625 code = Inset::ERT_CODE;
1627 case LFUN_LISTING_INSERT:
1628 code = Inset::LISTINGS_CODE;
1630 case LFUN_FOOTNOTE_INSERT:
1631 code = Inset::FOOT_CODE;
1633 case LFUN_TABULAR_INSERT:
1634 code = Inset::TABULAR_CODE;
1636 case LFUN_MARGINALNOTE_INSERT:
1637 code = Inset::MARGIN_CODE;
1639 case LFUN_FLOAT_INSERT:
1640 case LFUN_FLOAT_WIDE_INSERT:
1641 code = Inset::FLOAT_CODE;
1643 case LFUN_WRAP_INSERT:
1644 code = Inset::WRAP_CODE;
1646 case LFUN_FLOAT_LIST:
1647 code = Inset::FLOAT_LIST_CODE;
1650 case LFUN_LIST_INSERT:
1651 code = Inset::LIST_CODE;
1653 case LFUN_THEOREM_INSERT:
1654 code = Inset::THEOREM_CODE;
1657 case LFUN_CAPTION_INSERT:
1658 code = Inset::CAPTION_CODE;
1660 case LFUN_NOTE_INSERT:
1661 code = Inset::NOTE_CODE;
1663 case LFUN_FLEX_INSERT: {
1664 code = Inset::FLEX_CODE;
1665 string s = cmd.getArg(0);
1666 InsetLayout il = cur.buffer().params().getTextClass().insetlayout(from_utf8(s));
1667 if (il.lyxtype != "charstyle" &&
1668 il.lyxtype != "custom" &&
1669 il.lyxtype != "element")
1673 case LFUN_BOX_INSERT:
1674 code = Inset::BOX_CODE;
1676 case LFUN_BRANCH_INSERT:
1677 code = Inset::BRANCH_CODE;
1678 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1681 case LFUN_LABEL_INSERT:
1682 code = Inset::LABEL_CODE;
1684 case LFUN_OPTIONAL_INSERT:
1685 code = Inset::OPTARG_CODE;
1686 enable = numberOfOptArgs(cur.paragraph())
1687 < cur.paragraph().layout()->optionalargs;
1689 case LFUN_ENVIRONMENT_INSERT:
1690 code = Inset::BOX_CODE;
1692 case LFUN_INDEX_INSERT:
1693 code = Inset::INDEX_CODE;
1695 case LFUN_INDEX_PRINT:
1696 code = Inset::INDEX_PRINT_CODE;
1698 case LFUN_NOMENCL_INSERT:
1699 code = Inset::NOMENCL_CODE;
1701 case LFUN_NOMENCL_PRINT:
1702 code = Inset::NOMENCL_PRINT_CODE;
1704 case LFUN_TOC_INSERT:
1705 code = Inset::TOC_CODE;
1707 case LFUN_HTML_INSERT:
1708 case LFUN_URL_INSERT:
1709 code = Inset::URL_CODE;
1711 case LFUN_QUOTE_INSERT:
1712 // always allow this, since we will inset a raw quote
1713 // if an inset is not allowed.
1715 case LFUN_HYPHENATION_POINT_INSERT:
1716 case LFUN_LIGATURE_BREAK_INSERT:
1717 case LFUN_HFILL_INSERT:
1718 case LFUN_MENU_SEPARATOR_INSERT:
1719 case LFUN_DOTS_INSERT:
1720 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
1721 code = Inset::SPECIALCHAR_CODE;
1723 case LFUN_SPACE_INSERT:
1724 // slight hack: we know this is allowed in math mode
1726 code = Inset::SPACE_CODE;
1729 case LFUN_INSET_MODIFY:
1730 // We need to disable this, because we may get called for a
1732 // InsetTabular::getStatus() -> InsetText::getStatus()
1733 // and we don't handle LFUN_INSET_MODIFY.
1737 case LFUN_FONT_EMPH:
1738 flag.setOnOff(font.emph() == Font::ON);
1741 case LFUN_FONT_NOUN:
1742 flag.setOnOff(font.noun() == Font::ON);
1745 case LFUN_FONT_BOLD:
1746 flag.setOnOff(font.series() == Font::BOLD_SERIES);
1749 case LFUN_FONT_SANS:
1750 flag.setOnOff(font.family() == Font::SANS_FAMILY);
1753 case LFUN_FONT_ROMAN:
1754 flag.setOnOff(font.family() == Font::ROMAN_FAMILY);
1757 case LFUN_FONT_TYPEWRITER:
1758 flag.setOnOff(font.family() == Font::TYPEWRITER_FAMILY);
1763 enable = cur.selection();
1767 if (cmd.argument().empty()) {
1768 if (theClipboard().isInternal())
1769 enable = cap::numberOfSelections() > 0;
1771 enable = !theClipboard().empty();
1773 string const arg = to_utf8(cmd.argument());
1774 if (isStrUnsignedInt(arg)) {
1775 unsigned int n = convert<unsigned int>(arg);
1776 enable = cap::numberOfSelections() > n;
1783 case LFUN_CLIPBOARD_PASTE:
1784 enable = !theClipboard().empty();
1787 case LFUN_PRIMARY_SELECTION_PASTE:
1788 enable = cur.selection() || !theSelection().empty();
1791 case LFUN_PARAGRAPH_MOVE_UP:
1792 enable = cur.pit() > 0 && !cur.selection();
1795 case LFUN_PARAGRAPH_MOVE_DOWN:
1796 enable = cur.pit() < cur.lastpit() && !cur.selection();
1799 case LFUN_INSET_DISSOLVE:
1800 enable = !isMainText(cur.bv().buffer()) && cur.inset().nargs() == 1;
1803 case LFUN_CHANGE_ACCEPT:
1804 case LFUN_CHANGE_REJECT:
1805 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
1806 // In principle, these LFUNs should only be enabled if there
1807 // is a change at the current position/in the current selection.
1808 // However, without proper optimizations, this will inevitably
1809 // result in unacceptable performance - just imagine a user who
1810 // wants to select the complete content of a long document.
1814 case LFUN_WORD_DELETE_FORWARD:
1815 case LFUN_WORD_DELETE_BACKWARD:
1816 case LFUN_LINE_DELETE:
1817 case LFUN_WORD_FORWARD:
1818 case LFUN_WORD_BACKWARD:
1819 case LFUN_CHAR_FORWARD:
1820 case LFUN_CHAR_FORWARD_SELECT:
1821 case LFUN_CHAR_BACKWARD:
1822 case LFUN_CHAR_BACKWARD_SELECT:
1824 case LFUN_UP_SELECT:
1826 case LFUN_DOWN_SELECT:
1827 case LFUN_PARAGRAPH_UP_SELECT:
1828 case LFUN_PARAGRAPH_DOWN_SELECT:
1829 case LFUN_SCREEN_UP_SELECT:
1830 case LFUN_SCREEN_DOWN_SELECT:
1831 case LFUN_LINE_BEGIN_SELECT:
1832 case LFUN_LINE_END_SELECT:
1833 case LFUN_WORD_FORWARD_SELECT:
1834 case LFUN_WORD_BACKWARD_SELECT:
1835 case LFUN_WORD_SELECT:
1836 case LFUN_PARAGRAPH_UP:
1837 case LFUN_PARAGRAPH_DOWN:
1838 case LFUN_LINE_BEGIN:
1840 case LFUN_BREAK_LINE:
1841 case LFUN_CHAR_DELETE_FORWARD:
1842 case LFUN_DELETE_FORWARD_SKIP:
1843 case LFUN_CHAR_DELETE_BACKWARD:
1844 case LFUN_DELETE_BACKWARD_SKIP:
1845 case LFUN_BREAK_PARAGRAPH:
1846 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
1847 case LFUN_BREAK_PARAGRAPH_SKIP:
1848 case LFUN_PARAGRAPH_SPACING:
1849 case LFUN_INSET_INSERT:
1850 case LFUN_WORD_UPCASE:
1851 case LFUN_WORD_LOWCASE:
1852 case LFUN_WORD_CAPITALIZE:
1853 case LFUN_CHARS_TRANSPOSE:
1854 case LFUN_SERVER_GET_XY:
1855 case LFUN_SERVER_SET_XY:
1856 case LFUN_SERVER_GET_FONT:
1857 case LFUN_SERVER_GET_LAYOUT:
1859 case LFUN_DATE_INSERT:
1860 case LFUN_SELF_INSERT:
1861 case LFUN_LINE_INSERT:
1862 case LFUN_PAGEBREAK_INSERT:
1863 case LFUN_CLEARPAGE_INSERT:
1864 case LFUN_CLEARDOUBLEPAGE_INSERT:
1865 case LFUN_MATH_DISPLAY:
1866 case LFUN_MATH_IMPORT_SELECTION:
1867 case LFUN_MATH_MODE:
1868 case LFUN_MATH_MACRO:
1869 case LFUN_MATH_MATRIX:
1870 case LFUN_MATH_DELIM:
1871 case LFUN_MATH_BIGDELIM:
1872 case LFUN_MATH_INSERT:
1873 case LFUN_MATH_SUBSCRIPT:
1874 case LFUN_MATH_SUPERSCRIPT:
1875 case LFUN_FONT_DEFAULT:
1876 case LFUN_FONT_UNDERLINE:
1877 case LFUN_FONT_SIZE:
1879 case LFUN_FONT_FREE_APPLY:
1880 case LFUN_FONT_FREE_UPDATE:
1881 case LFUN_LAYOUT_PARAGRAPH:
1882 case LFUN_PARAGRAPH_UPDATE:
1883 case LFUN_ACCENT_UMLAUT:
1884 case LFUN_ACCENT_CIRCUMFLEX:
1885 case LFUN_ACCENT_GRAVE:
1886 case LFUN_ACCENT_ACUTE:
1887 case LFUN_ACCENT_TILDE:
1888 case LFUN_ACCENT_CEDILLA:
1889 case LFUN_ACCENT_MACRON:
1890 case LFUN_ACCENT_DOT:
1891 case LFUN_ACCENT_UNDERDOT:
1892 case LFUN_ACCENT_UNDERBAR:
1893 case LFUN_ACCENT_CARON:
1894 case LFUN_ACCENT_SPECIAL_CARON:
1895 case LFUN_ACCENT_BREVE:
1896 case LFUN_ACCENT_TIE:
1897 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1898 case LFUN_ACCENT_CIRCLE:
1899 case LFUN_ACCENT_OGONEK:
1900 case LFUN_THESAURUS_ENTRY:
1901 case LFUN_PARAGRAPH_PARAMS_APPLY:
1902 case LFUN_PARAGRAPH_PARAMS:
1904 case LFUN_BUFFER_END:
1905 case LFUN_BUFFER_BEGIN:
1906 case LFUN_BUFFER_BEGIN_SELECT:
1907 case LFUN_BUFFER_END_SELECT:
1908 case LFUN_UNICODE_INSERT:
1909 // these are handled in our dispatch()
1917 if (code != Inset::NO_CODE
1918 && (cur.empty() || !cur.inset().insetAllowed(code)))
1921 flag.enabled(enable);
1926 void Text::pasteString(Cursor & cur, docstring const & clip,
1929 cur.clearSelection();
1930 if (!clip.empty()) {
1933 insertStringAsParagraphs(cur, clip);
1935 insertStringAsLines(cur, clip);