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, false);
569 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
570 cap::replaceSelection(cur);
571 breakParagraph(cur, true);
575 case LFUN_BREAK_PARAGRAPH_SKIP: {
576 // When at the beginning of a paragraph, remove
577 // indentation. Otherwise, do the same as LFUN_BREAK_PARAGRAPH.
578 cap::replaceSelection(cur);
580 cur.paragraph().params().labelWidthString(docstring());
582 breakParagraph(cur, false);
588 // With the creation of LFUN_PARAGRAPH_PARAMS, this is now redundant,
589 // as its duties can be performed there. Should it be removed??
590 // FIXME For now, it can just dispatch LFUN_PARAGRAPH_PARAMS...
591 case LFUN_PARAGRAPH_SPACING: {
592 Paragraph & par = cur.paragraph();
593 Spacing::Space cur_spacing = par.params().spacing().getSpace();
594 string cur_value = "1.0";
595 if (cur_spacing == Spacing::Other)
596 cur_value = par.params().spacing().getValueAsString();
598 istringstream is(to_utf8(cmd.argument()));
601 Spacing::Space new_spacing = cur_spacing;
602 string new_value = cur_value;
604 lyxerr << "Missing argument to `paragraph-spacing'"
606 } else if (tmp == "single") {
607 new_spacing = Spacing::Single;
608 } else if (tmp == "onehalf") {
609 new_spacing = Spacing::Onehalf;
610 } else if (tmp == "double") {
611 new_spacing = Spacing::Double;
612 } else if (tmp == "other") {
613 new_spacing = Spacing::Other;
614 string tmpval = "0.0";
616 lyxerr << "new_value = " << tmpval << endl;
619 } else if (tmp == "default") {
620 new_spacing = Spacing::Default;
622 lyxerr << to_utf8(_("Unknown spacing argument: "))
623 << to_utf8(cmd.argument()) << endl;
625 if (cur_spacing != new_spacing || cur_value != new_value)
626 par.params().spacing(Spacing(new_spacing, new_value));
630 case LFUN_INSET_INSERT: {
632 Inset * inset = createInset(bv, cmd);
634 // FIXME (Abdel 01/02/2006):
635 // What follows would be a partial fix for bug 2154:
636 // http://bugzilla.lyx.org/show_bug.cgi?id=2154
637 // This automatically put the label inset _after_ a
638 // numbered section. It should be possible to extend the mechanism
639 // to any kind of LateX environement.
640 // The correct way to fix that bug would be at LateX generation.
641 // I'll let the code here for reference as it could be used for some
642 // other feature like "automatic labelling".
644 Paragraph & par = pars_[cur.pit()];
645 if (inset->lyxCode() == Inset::LABEL_CODE
646 && par.layout()->labeltype == LABEL_COUNTER) {
647 // Go to the end of the paragraph
648 // Warning: Because of Change-Tracking, the last
649 // position is 'size()' and not 'size()-1':
650 cur.pos() = par.size();
651 // Insert a new paragraph
652 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
657 cutSelection(cur, true, false);
658 insertInset(cur, inset);
664 case LFUN_INSET_DISSOLVE:
665 needsUpdate |= dissolveInset(cur);
668 case LFUN_INSET_SETTINGS:
669 cur.inset().showInsetDialog(bv);
672 case LFUN_SPACE_INSERT:
673 if (cur.paragraph().layout()->free_spacing)
674 insertChar(cur, ' ');
676 doInsertInset(cur, this, cmd, false, false);
679 moveCursor(cur, false);
682 case LFUN_HYPHENATION_POINT_INSERT:
683 specialChar(cur, InsetSpecialChar::HYPHENATION);
686 case LFUN_LIGATURE_BREAK_INSERT:
687 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
690 case LFUN_DOTS_INSERT:
691 specialChar(cur, InsetSpecialChar::LDOTS);
694 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
695 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
698 case LFUN_MENU_SEPARATOR_INSERT:
699 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
702 case LFUN_WORD_UPCASE:
703 changeCase(cur, Text::text_uppercase);
706 case LFUN_WORD_LOWCASE:
707 changeCase(cur, Text::text_lowercase);
710 case LFUN_WORD_CAPITALIZE:
711 changeCase(cur, Text::text_capitalization);
714 case LFUN_CHARS_TRANSPOSE:
719 cur.message(_("Paste"));
720 cap::replaceSelection(cur);
721 if (cmd.argument().empty() && !theClipboard().isInternal())
722 pasteClipboard(cur, bv->buffer().errorList("Paste"));
724 string const arg(to_utf8(cmd.argument()));
725 pasteFromStack(cur, bv->buffer().errorList("Paste"),
726 isStrUnsignedInt(arg) ?
727 convert<unsigned int>(arg) :
730 bv->buffer().errors("Paste");
731 cur.clearSelection(); // bug 393
736 cutSelection(cur, true, true);
737 cur.message(_("Cut"));
742 cur.message(_("Copy"));
745 case LFUN_SERVER_GET_XY:
746 cur.message(from_utf8(
747 convert<string>(tm.cursorX(cur.top(), cur.boundary()))
748 + ' ' + convert<string>(tm.cursorY(cur.top(), cur.boundary()))));
751 case LFUN_SERVER_SET_XY: {
754 istringstream is(to_utf8(cmd.argument()));
757 lyxerr << "SETXY: Could not parse coordinates in '"
758 << to_utf8(cmd.argument()) << std::endl;
760 tm.setCursorFromCoordinates(cur, x, y);
764 case LFUN_SERVER_GET_FONT:
765 if (cur.current_font.shape() == Font::ITALIC_SHAPE)
766 cur.message(from_ascii("E"));
767 else if (cur.current_font.shape() == Font::SMALLCAPS_SHAPE)
768 cur.message(from_ascii("N"));
770 cur.message(from_ascii("0"));
773 case LFUN_SERVER_GET_LAYOUT:
774 cur.message(cur.paragraph().layout()->name());
778 docstring layout = cmd.argument();
779 LYXERR(Debug::INFO) << "LFUN_LAYOUT: (arg) " << to_utf8(layout) << endl;
781 docstring const old_layout = cur.paragraph().layout()->name();
783 // Derive layout number from given argument (string)
784 // and current buffer's textclass (number)
785 TextClass const & tclass = bv->buffer().params().getTextClass();
787 layout = tclass.defaultLayoutName();
788 bool hasLayout = tclass.hasLayout(layout);
790 // If the entry is obsolete, use the new one instead.
792 docstring const & obs = tclass[layout]->obsoleted_by();
798 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
799 from_utf8(N_(" not known")));
803 bool change_layout = (old_layout != layout);
805 if (!change_layout && cur.selection() &&
806 cur.selBegin().pit() != cur.selEnd().pit())
808 pit_type spit = cur.selBegin().pit();
809 pit_type epit = cur.selEnd().pit() + 1;
810 while (spit != epit) {
811 if (pars_[spit].layout()->name() != old_layout) {
812 change_layout = true;
820 setLayout(cur, layout);
825 case LFUN_CLIPBOARD_PASTE:
826 cur.clearSelection();
827 pasteClipboard(cur, bv->buffer().errorList("Paste"),
828 cmd.argument() == "paragraph");
829 bv->buffer().errors("Paste");
832 case LFUN_PRIMARY_SELECTION_PASTE:
833 pasteString(cur, theSelection().get(),
834 cmd.argument() == "paragraph");
837 case LFUN_UNICODE_INSERT: {
838 if (cmd.argument().empty())
840 docstring hexstring = cmd.argument();
841 if (lyx::support::isHex(hexstring)) {
842 char_type c = lyx::support::hexToInt(hexstring);
843 if (c >= 32 && c < 0x10ffff) {
844 lyxerr << "Inserting c: " << c << endl;
845 docstring s = docstring(1, c);
846 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
852 case LFUN_QUOTE_INSERT: {
853 Paragraph & par = cur.paragraph();
854 pos_type pos = cur.pos();
855 BufferParams const & bufparams = bv->buffer().params();
856 LayoutPtr const & style = par.layout();
857 if (!style->pass_thru
858 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
859 // this avoids a double undo
860 // FIXME: should not be needed, ideally
861 if (!cur.selection())
863 cap::replaceSelection(cur);
868 else if (cur.prevInset() && cur.prevInset()->isSpace())
871 c = par.getChar(pos - 1);
872 string arg = to_utf8(cmd.argument());
874 cur.insert(new InsetQuotes(c,
875 bufparams.quotes_language,
876 InsetQuotes::SingleQ));
878 cur.insert(new InsetQuotes(c,
879 bufparams.quotes_language,
880 InsetQuotes::DoubleQ));
884 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
888 case LFUN_DATE_INSERT: {
889 string const format = cmd.argument().empty()
890 ? lyxrc.date_insert_format : to_utf8(cmd.argument());
891 string const time = formatted_time(current_time(), format);
892 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, time));
896 case LFUN_MOUSE_TRIPLE:
897 if (cmd.button() == mouse_button::button1) {
906 case LFUN_MOUSE_DOUBLE:
907 if (cmd.button() == mouse_button::button1) {
908 selectWord(cur, WHOLE_WORD_STRICT);
913 // Single-click on work area
914 case LFUN_MOUSE_PRESS: {
915 // Right click on a footnote flag opens float menu
916 if (cmd.button() == mouse_button::button3)
917 cur.clearSelection();
920 bool update = bv->mouseSetCursor(cur);
922 // Insert primary selection with middle mouse
923 // if there is a local selection in the current buffer,
925 if (cmd.button() == mouse_button::button2) {
926 if (cap::selection()) {
927 // Copy the selection buffer to the clipboard
928 // stack, because we want it to appear in the
929 // "Edit->Paste recent" menu.
930 cap::copySelectionToStack();
932 cap::pasteSelection(bv->cursor(),
933 bv->buffer().errorList("Paste"));
934 bv->buffer().errors("Paste");
935 bv->buffer().markDirty();
938 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
942 // we have to update after dEPM triggered
943 if (!update && cmd.button() == mouse_button::button1) {
951 case LFUN_MOUSE_MOTION: {
952 // Only use motion with button 1
953 //if (cmd.button() != mouse_button::button1)
956 // ignore motions deeper nested than the real anchor
957 Cursor & bvcur = cur.bv().cursor();
958 if (bvcur.anchor_.hasPart(cur)) {
959 CursorSlice old = bvcur.top();
961 int const wh = bv->workHeight();
962 int const y = std::max(0, std::min(wh - 1, cmd.y));
964 tm.setCursorFromCoordinates(cur, cmd.x, y);
965 cur.setTargetX(cmd.x);
967 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
969 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
970 // This is to allow jumping over large insets
971 if (cur.top() == old) {
973 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
975 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
978 if (cur.top() == old)
982 bvcur.setCursor(cur);
983 bvcur.selection() = true;
984 //lyxerr << "MOTION: " << bv->cursor() << endl;
992 case LFUN_MOUSE_RELEASE: {
993 if (cmd.button() == mouse_button::button2)
996 if (cmd.button() == mouse_button::button1) {
997 // if there is new selection, update persistent
998 // selection, otherwise, single click does not
999 // clear persistent selection buffer
1000 if (cur.selection()) {
1002 // if double click, cur is moved to the end of word by selectWord
1003 // but bvcur is current mouse position
1004 Cursor & bvcur = cur.bv().cursor();
1005 bvcur.selection() = true;
1007 needsUpdate = false;
1014 case LFUN_SELF_INSERT: {
1015 if (cmd.argument().empty())
1018 // Automatically delete the currently selected
1019 // text and replace it with what is being
1020 // typed in now. Depends on lyxrc settings
1021 // "auto_region_delete", which defaults to
1024 if (lyxrc.auto_region_delete && cur.selection()) {
1025 cutSelection(cur, false, false);
1026 // When change tracking is set to off, the metrics update
1027 // mechanism correctly detects if a full update is needed or not.
1028 // This detection fails when a selection spans multiple rows and
1029 // change tracking is enabled because the paragraph metrics stays
1030 // the same. In this case, we force the full update:
1031 // (see http://bugzilla.lyx.org/show_bug.cgi?id=3992)
1032 if (cur.buffer().params().trackChanges)
1033 cur.updateFlags(Update::Force);
1036 cur.clearSelection();
1037 Font const old_font = cur.real_current_font;
1039 docstring::const_iterator cit = cmd.argument().begin();
1040 docstring::const_iterator end = cmd.argument().end();
1041 for (; cit != end; ++cit)
1042 bv->translateAndInsert(*cit, this, cur);
1045 moveCursor(cur, false);
1049 case LFUN_URL_INSERT: {
1050 InsetCommandParams p("url");
1052 if (cur.selection()) {
1053 content = cur.selectionAsString(false);
1054 cutSelection(cur, true, false);
1056 p["target"] = (cmd.argument().empty()) ?
1057 content : cmd.argument();
1058 string const data = InsetCommandMailer::params2string("url", p);
1059 if (p["target"].empty()) {
1060 bv->showInsetDialog("url", data, 0);
1062 FuncRequest fr(LFUN_INSET_INSERT, data);
1068 case LFUN_HTML_INSERT: {
1069 InsetCommandParams p("htmlurl");
1071 if (cur.selection()) {
1072 content = cur.selectionAsString(false);
1073 cutSelection(cur, true, false);
1075 p["target"] = (cmd.argument().empty()) ?
1076 content : cmd.argument();
1077 string const data = InsetCommandMailer::params2string("url", p);
1078 if (p["target"].empty()) {
1079 bv->showInsetDialog("url", data, 0);
1081 FuncRequest fr(LFUN_INSET_INSERT, data);
1087 case LFUN_LABEL_INSERT: {
1088 InsetCommandParams p("label");
1089 // Try to generate a valid label
1090 p["name"] = (cmd.argument().empty()) ?
1091 cur.getPossibleLabel() :
1093 string const data = InsetCommandMailer::params2string("label", p);
1095 if (cmd.argument().empty()) {
1096 bv->showInsetDialog("label", data, 0);
1098 FuncRequest fr(LFUN_INSET_INSERT, data);
1106 case LFUN_LIST_INSERT:
1107 case LFUN_THEOREM_INSERT:
1109 case LFUN_CAPTION_INSERT:
1110 // Open the inset, and move the current selection
1112 doInsertInset(cur, this, cmd, true, true);
1114 updateLabels(bv->buffer());
1116 case LFUN_NOTE_INSERT:
1117 case LFUN_FLEX_INSERT:
1118 case LFUN_BOX_INSERT:
1119 case LFUN_BRANCH_INSERT:
1120 case LFUN_BIBITEM_INSERT:
1121 case LFUN_ERT_INSERT:
1122 case LFUN_LISTING_INSERT:
1123 case LFUN_FOOTNOTE_INSERT:
1124 case LFUN_MARGINALNOTE_INSERT:
1125 case LFUN_OPTIONAL_INSERT:
1126 case LFUN_ENVIRONMENT_INSERT:
1127 // Open the inset, and move the current selection
1129 doInsertInset(cur, this, cmd, true, true);
1133 case LFUN_TABULAR_INSERT:
1134 // if there were no arguments, just open the dialog
1135 if (doInsertInset(cur, this, cmd, false, true))
1138 bv->showDialog("tabularcreate");
1142 case LFUN_FLOAT_INSERT:
1143 case LFUN_FLOAT_WIDE_INSERT:
1144 case LFUN_WRAP_INSERT: {
1145 bool content = cur.selection(); // will some text be moved into the inset?
1147 doInsertInset(cur, this, cmd, true, true);
1149 ParagraphList & pars = cur.text()->paragraphs();
1151 TextClass const & tclass = bv->buffer().params().getTextClass();
1153 // add a separate paragraph for the caption inset
1154 pars.push_back(Paragraph());
1155 pars.back().setInsetOwner(pars[0].inInset());
1156 pars.back().layout(tclass.defaultLayout());
1158 int cap_pit = pars.size() - 1;
1160 // if an empty inset was created, we create an additional empty
1161 // paragraph at the bottom so that the user can choose where to put
1162 // the graphics (or table).
1164 pars.push_back(Paragraph());
1165 pars.back().setInsetOwner(pars[0].inInset());
1166 pars.back().layout(tclass.defaultLayout());
1170 // reposition the cursor to the caption
1171 cur.pit() = cap_pit;
1173 // FIXME: This Text/Cursor dispatch handling is a mess!
1174 // We cannot use Cursor::dispatch here it needs access to up to
1176 FuncRequest cmd_caption(LFUN_CAPTION_INSERT);
1177 cur.text()->dispatch(cur, cmd_caption);
1178 cur.updateFlags(Update::Force);
1179 // FIXME: When leaving the Float (or Wrap) inset we should
1180 // delete any empty paragraph left above or below the
1185 case LFUN_INDEX_INSERT:
1186 doInsertInset(cur, this, cmd, true, true);
1189 case LFUN_NOMENCL_INSERT: {
1190 Inset * inset = createInset(&cur.bv(), cmd);
1194 cur.clearSelection();
1195 insertInset(cur, inset);
1196 // Show the dialog for the nomenclature entry, since the
1197 // description entry still needs to be filled in.
1198 if (cmd.action == LFUN_NOMENCL_INSERT)
1199 inset->edit(cur, true);
1204 case LFUN_INDEX_PRINT:
1205 case LFUN_NOMENCL_PRINT:
1206 case LFUN_TOC_INSERT:
1207 case LFUN_HFILL_INSERT:
1208 case LFUN_LINE_INSERT:
1209 case LFUN_PAGEBREAK_INSERT:
1210 case LFUN_CLEARPAGE_INSERT:
1211 case LFUN_CLEARDOUBLEPAGE_INSERT:
1213 doInsertInset(cur, this, cmd, false, false);
1217 case LFUN_DEPTH_DECREMENT:
1218 changeDepth(cur, DEC_DEPTH);
1221 case LFUN_DEPTH_INCREMENT:
1222 changeDepth(cur, INC_DEPTH);
1225 case LFUN_MATH_DISPLAY:
1226 mathDispatch(cur, cmd, true);
1229 case LFUN_MATH_IMPORT_SELECTION:
1230 case LFUN_MATH_MODE:
1231 if (cmd.argument() == "on")
1232 // don't pass "on" as argument
1233 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1235 mathDispatch(cur, cmd, false);
1238 case LFUN_MATH_MACRO:
1239 if (cmd.argument().empty())
1240 cur.errorMessage(from_utf8(N_("Missing argument")));
1242 string s = to_utf8(cmd.argument());
1243 string const s1 = token(s, ' ', 1);
1244 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1245 string const s2 = token(s, ' ', 2);
1246 string const type = s2.empty() ? "newcommand" : s2;
1247 cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, from_utf8(type)));
1248 //cur.nextInset()->edit(cur, true);
1252 // passthrough hat and underscore outside mathed:
1253 case LFUN_MATH_SUBSCRIPT:
1254 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1256 case LFUN_MATH_SUPERSCRIPT:
1257 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1260 case LFUN_MATH_INSERT:
1261 case LFUN_MATH_MATRIX:
1262 case LFUN_MATH_DELIM:
1263 case LFUN_MATH_BIGDELIM: {
1264 if (cur.selection())
1265 cur.clearSelection();
1266 // FIXME: instead of the above, this one
1267 // should be used (but it asserts with Bidi enabled)
1268 // cf. http://bugzilla.lyx.org/show_bug.cgi?id=4055
1269 // cap::replaceSelection(cur);
1270 cur.insert(new InsetMathHull(hullSimple));
1271 checkAndActivateInset(cur, true);
1272 BOOST_ASSERT(cur.inMathed());
1277 case LFUN_FONT_EMPH: {
1278 Font font(Font::ALL_IGNORE);
1279 font.setEmph(Font::TOGGLE);
1280 toggleAndShow(cur, this, font);
1284 case LFUN_FONT_BOLD: {
1285 Font font(Font::ALL_IGNORE);
1286 font.setSeries(Font::BOLD_SERIES);
1287 toggleAndShow(cur, this, font);
1291 case LFUN_FONT_NOUN: {
1292 Font font(Font::ALL_IGNORE);
1293 font.setNoun(Font::TOGGLE);
1294 toggleAndShow(cur, this, font);
1298 case LFUN_FONT_TYPEWRITER: {
1299 Font font(Font::ALL_IGNORE);
1300 font.setFamily(Font::TYPEWRITER_FAMILY); // no good
1301 toggleAndShow(cur, this, font);
1305 case LFUN_FONT_SANS: {
1306 Font font(Font::ALL_IGNORE);
1307 font.setFamily(Font::SANS_FAMILY);
1308 toggleAndShow(cur, this, font);
1312 case LFUN_FONT_ROMAN: {
1313 Font font(Font::ALL_IGNORE);
1314 font.setFamily(Font::ROMAN_FAMILY);
1315 toggleAndShow(cur, this, font);
1319 case LFUN_FONT_DEFAULT: {
1320 Font font(Font::ALL_INHERIT, ignore_language);
1321 toggleAndShow(cur, this, font);
1325 case LFUN_FONT_UNDERLINE: {
1326 Font font(Font::ALL_IGNORE);
1327 font.setUnderbar(Font::TOGGLE);
1328 toggleAndShow(cur, this, font);
1332 case LFUN_FONT_SIZE: {
1333 Font font(Font::ALL_IGNORE);
1334 font.setLyXSize(to_utf8(cmd.argument()));
1335 toggleAndShow(cur, this, font);
1339 case LFUN_LANGUAGE: {
1340 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1343 Font font(Font::ALL_IGNORE);
1344 font.setLanguage(lang);
1345 toggleAndShow(cur, this, font);
1349 case LFUN_FONT_FREE_APPLY:
1350 toggleAndShow(cur, this, freefont, toggleall);
1351 cur.message(_("Character set"));
1354 // Set the freefont using the contents of \param data dispatched from
1355 // the frontends and apply it at the current cursor location.
1356 case LFUN_FONT_FREE_UPDATE: {
1359 if (font.fromString(to_utf8(cmd.argument()), toggle)) {
1362 toggleAndShow(cur, this, freefont, toggleall);
1363 cur.message(_("Character set"));
1368 case LFUN_FINISHED_LEFT:
1369 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1370 if (reverseDirectionNeeded(cur)) {
1372 cur.setCurrentFont();
1376 case LFUN_FINISHED_RIGHT:
1377 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1378 if (!reverseDirectionNeeded(cur)) {
1380 cur.setCurrentFont();
1384 case LFUN_LAYOUT_PARAGRAPH: {
1386 params2string(cur.paragraph(), data);
1387 data = "show\n" + data;
1388 bv->showDialogWithData("paragraph", data);
1392 case LFUN_PARAGRAPH_UPDATE: {
1394 params2string(cur.paragraph(), data);
1396 // Will the paragraph accept changes from the dialog?
1397 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1399 data = "update " + convert<string>(accept) + '\n' + data;
1400 bv->updateDialog("paragraph", data);
1404 case LFUN_ACCENT_UMLAUT:
1405 case LFUN_ACCENT_CIRCUMFLEX:
1406 case LFUN_ACCENT_GRAVE:
1407 case LFUN_ACCENT_ACUTE:
1408 case LFUN_ACCENT_TILDE:
1409 case LFUN_ACCENT_CEDILLA:
1410 case LFUN_ACCENT_MACRON:
1411 case LFUN_ACCENT_DOT:
1412 case LFUN_ACCENT_UNDERDOT:
1413 case LFUN_ACCENT_UNDERBAR:
1414 case LFUN_ACCENT_CARON:
1415 case LFUN_ACCENT_SPECIAL_CARON:
1416 case LFUN_ACCENT_BREVE:
1417 case LFUN_ACCENT_TIE:
1418 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1419 case LFUN_ACCENT_CIRCLE:
1420 case LFUN_ACCENT_OGONEK:
1421 theLyXFunc().handleKeyFunc(cmd.action);
1422 if (!cmd.argument().empty())
1423 // FIXME: Are all these characters encoded in one byte in utf8?
1424 bv->translateAndInsert(cmd.argument()[0], this, cur);
1427 case LFUN_FLOAT_LIST: {
1428 TextClass const & tclass = bv->buffer().params().getTextClass();
1429 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1431 if (cur.selection())
1432 cutSelection(cur, true, false);
1433 breakParagraph(cur);
1435 if (cur.lastpos() != 0) {
1437 breakParagraph(cur);
1440 setLayout(cur, tclass.defaultLayoutName());
1441 ParagraphParameters p;
1442 setParagraphs(cur, p);
1443 insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1446 lyxerr << "Non-existent float type: "
1447 << to_utf8(cmd.argument()) << endl;
1452 case LFUN_CHANGE_ACCEPT: {
1453 acceptOrRejectChanges(cur, ACCEPT);
1457 case LFUN_CHANGE_REJECT: {
1458 acceptOrRejectChanges(cur, REJECT);
1462 case LFUN_THESAURUS_ENTRY: {
1463 docstring arg = cmd.argument();
1465 arg = cur.selectionAsString(false);
1467 if (arg.size() > 100 || arg.empty()) {
1468 // Get word or selection
1469 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1470 arg = cur.selectionAsString(false);
1473 bv->showDialogWithData("thesaurus", to_utf8(arg));
1477 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1478 // Given data, an encoding of the ParagraphParameters
1479 // generated in the Paragraph dialog, this function sets
1480 // the current paragraph, or currently selected paragraphs,
1482 // NOTE: This function overrides all existing settings.
1483 setParagraphs(cur, cmd.argument());
1484 cur.message(_("Paragraph layout set"));
1488 case LFUN_PARAGRAPH_PARAMS: {
1489 // Given data, an encoding of the ParagraphParameters as we'd
1490 // find them in a LyX file, this function modifies the current paragraph,
1491 // or currently selected paragraphs.
1492 // NOTE: This function only modifies, and does not override, existing
1494 setParagraphs(cur, cmd.argument(), true);
1495 cur.message(_("Paragraph layout set"));
1500 if (cur.selection()) {
1501 cur.selection() = false;
1504 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1509 LYXERR(Debug::ACTION)
1510 << BOOST_CURRENT_FUNCTION
1511 << ": Command " << cmd
1512 << " not DISPATCHED by Text" << endl;
1517 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1519 // FIXME: The cursor flag is reset two lines below
1520 // so we need to check here if some of the LFUN did touch that.
1521 // for now only Text::erase() and Text::backspace() do that.
1522 // The plan is to verify all the LFUNs and then to remove this
1523 // singleParUpdate boolean altogether.
1524 if (cur.result().update() & Update::Force) {
1525 singleParUpdate = false;
1529 // FIXME: the following code should go in favor of fine grained
1530 // update flag treatment.
1531 if (singleParUpdate) {
1532 // Inserting characters does not change par height
1533 ParagraphMetrics const & pms
1534 = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
1535 if (pms.dim().height()
1536 == olddim.height()) {
1537 // if so, update _only_ this paragraph
1538 cur.updateFlags(Update::SinglePar |
1540 Update::MultiParSel);
1547 && &oldTopSlice.inset() == &cur.inset()
1548 && oldTopSlice.idx() == cur.idx()
1549 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1550 && !cur.selection())
1551 // FIXME: it would be better if we could just do this
1553 //if (cur.result().update() != Update::FitCursor)
1556 // But some LFUNs do not set Update::FitCursor when needed, so we
1557 // do it for all. This is not very harmfull as FitCursor will provoke
1558 // a full redraw only if needed but still, a proper review of all LFUN
1559 // should be done and this needsUpdate boolean can then be removed.
1560 cur.updateFlags(Update::FitCursor);
1562 cur.updateFlags(Update::Force | Update::FitCursor);
1566 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
1567 FuncStatus & flag) const
1569 BOOST_ASSERT(cur.text() == this);
1571 Font const & font = cur.real_current_font;
1573 Inset::Code code = Inset::NO_CODE;
1575 switch (cmd.action) {
1577 case LFUN_DEPTH_DECREMENT:
1578 enable = changeDepthAllowed(cur, DEC_DEPTH);
1581 case LFUN_DEPTH_INCREMENT:
1582 enable = changeDepthAllowed(cur, INC_DEPTH);
1586 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1589 case LFUN_BIBITEM_INSERT:
1590 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO
1594 case LFUN_DIALOG_SHOW_NEW_INSET:
1595 if (cmd.argument() == "bibitem")
1596 code = Inset::BIBITEM_CODE;
1597 else if (cmd.argument() == "bibtex")
1598 code = Inset::BIBTEX_CODE;
1599 else if (cmd.argument() == "box")
1600 code = Inset::BOX_CODE;
1601 else if (cmd.argument() == "branch")
1602 code = Inset::BRANCH_CODE;
1603 else if (cmd.argument() == "citation")
1604 code = Inset::CITE_CODE;
1605 else if (cmd.argument() == "ert")
1606 code = Inset::ERT_CODE;
1607 else if (cmd.argument() == "external")
1608 code = Inset::EXTERNAL_CODE;
1609 else if (cmd.argument() == "float")
1610 code = Inset::FLOAT_CODE;
1611 else if (cmd.argument() == "graphics")
1612 code = Inset::GRAPHICS_CODE;
1613 else if (cmd.argument() == "include")
1614 code = Inset::INCLUDE_CODE;
1615 else if (cmd.argument() == "index")
1616 code = Inset::INDEX_CODE;
1617 else if (cmd.argument() == "nomenclature")
1618 code = Inset::NOMENCL_CODE;
1619 else if (cmd.argument() == "label")
1620 code = Inset::LABEL_CODE;
1621 else if (cmd.argument() == "note")
1622 code = Inset::NOTE_CODE;
1623 else if (cmd.argument() == "ref")
1624 code = Inset::REF_CODE;
1625 else if (cmd.argument() == "toc")
1626 code = Inset::TOC_CODE;
1627 else if (cmd.argument() == "url")
1628 code = Inset::URL_CODE;
1629 else if (cmd.argument() == "vspace")
1630 code = Inset::VSPACE_CODE;
1631 else if (cmd.argument() == "wrap")
1632 code = Inset::WRAP_CODE;
1633 else if (cmd.argument() == "listings")
1634 code = Inset::LISTINGS_CODE;
1637 case LFUN_ERT_INSERT:
1638 code = Inset::ERT_CODE;
1640 case LFUN_LISTING_INSERT:
1641 code = Inset::LISTINGS_CODE;
1643 case LFUN_FOOTNOTE_INSERT:
1644 code = Inset::FOOT_CODE;
1646 case LFUN_TABULAR_INSERT:
1647 code = Inset::TABULAR_CODE;
1649 case LFUN_MARGINALNOTE_INSERT:
1650 code = Inset::MARGIN_CODE;
1652 case LFUN_FLOAT_INSERT:
1653 case LFUN_FLOAT_WIDE_INSERT:
1654 code = Inset::FLOAT_CODE;
1656 case LFUN_WRAP_INSERT:
1657 code = Inset::WRAP_CODE;
1659 case LFUN_FLOAT_LIST:
1660 code = Inset::FLOAT_LIST_CODE;
1663 case LFUN_LIST_INSERT:
1664 code = Inset::LIST_CODE;
1666 case LFUN_THEOREM_INSERT:
1667 code = Inset::THEOREM_CODE;
1670 case LFUN_CAPTION_INSERT:
1671 code = Inset::CAPTION_CODE;
1673 case LFUN_NOTE_INSERT:
1674 code = Inset::NOTE_CODE;
1676 case LFUN_FLEX_INSERT: {
1677 code = Inset::FLEX_CODE;
1678 string s = cmd.getArg(0);
1679 InsetLayout il = cur.buffer().params().getTextClass().insetlayout(from_utf8(s));
1680 if (il.lyxtype != "charstyle" &&
1681 il.lyxtype != "custom" &&
1682 il.lyxtype != "element")
1686 case LFUN_BOX_INSERT:
1687 code = Inset::BOX_CODE;
1689 case LFUN_BRANCH_INSERT:
1690 code = Inset::BRANCH_CODE;
1691 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1694 case LFUN_LABEL_INSERT:
1695 code = Inset::LABEL_CODE;
1697 case LFUN_OPTIONAL_INSERT:
1698 code = Inset::OPTARG_CODE;
1699 enable = numberOfOptArgs(cur.paragraph())
1700 < cur.paragraph().layout()->optionalargs;
1702 case LFUN_ENVIRONMENT_INSERT:
1703 code = Inset::BOX_CODE;
1705 case LFUN_INDEX_INSERT:
1706 code = Inset::INDEX_CODE;
1708 case LFUN_INDEX_PRINT:
1709 code = Inset::INDEX_PRINT_CODE;
1711 case LFUN_NOMENCL_INSERT:
1712 code = Inset::NOMENCL_CODE;
1714 case LFUN_NOMENCL_PRINT:
1715 code = Inset::NOMENCL_PRINT_CODE;
1717 case LFUN_TOC_INSERT:
1718 code = Inset::TOC_CODE;
1720 case LFUN_HTML_INSERT:
1721 case LFUN_URL_INSERT:
1722 code = Inset::URL_CODE;
1724 case LFUN_QUOTE_INSERT:
1725 // always allow this, since we will inset a raw quote
1726 // if an inset is not allowed.
1728 case LFUN_HYPHENATION_POINT_INSERT:
1729 case LFUN_LIGATURE_BREAK_INSERT:
1730 case LFUN_HFILL_INSERT:
1731 case LFUN_MENU_SEPARATOR_INSERT:
1732 case LFUN_DOTS_INSERT:
1733 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
1734 code = Inset::SPECIALCHAR_CODE;
1736 case LFUN_SPACE_INSERT:
1737 // slight hack: we know this is allowed in math mode
1739 code = Inset::SPACE_CODE;
1742 case LFUN_INSET_MODIFY:
1743 // We need to disable this, because we may get called for a
1745 // InsetTabular::getStatus() -> InsetText::getStatus()
1746 // and we don't handle LFUN_INSET_MODIFY.
1750 case LFUN_FONT_EMPH:
1751 flag.setOnOff(font.emph() == Font::ON);
1754 case LFUN_FONT_NOUN:
1755 flag.setOnOff(font.noun() == Font::ON);
1758 case LFUN_FONT_BOLD:
1759 flag.setOnOff(font.series() == Font::BOLD_SERIES);
1762 case LFUN_FONT_SANS:
1763 flag.setOnOff(font.family() == Font::SANS_FAMILY);
1766 case LFUN_FONT_ROMAN:
1767 flag.setOnOff(font.family() == Font::ROMAN_FAMILY);
1770 case LFUN_FONT_TYPEWRITER:
1771 flag.setOnOff(font.family() == Font::TYPEWRITER_FAMILY);
1776 enable = cur.selection();
1780 if (cmd.argument().empty()) {
1781 if (theClipboard().isInternal())
1782 enable = cap::numberOfSelections() > 0;
1784 enable = !theClipboard().empty();
1786 string const arg = to_utf8(cmd.argument());
1787 if (isStrUnsignedInt(arg)) {
1788 unsigned int n = convert<unsigned int>(arg);
1789 enable = cap::numberOfSelections() > n;
1796 case LFUN_CLIPBOARD_PASTE:
1797 enable = !theClipboard().empty();
1800 case LFUN_PRIMARY_SELECTION_PASTE:
1801 enable = cur.selection() || !theSelection().empty();
1804 case LFUN_PARAGRAPH_MOVE_UP:
1805 enable = cur.pit() > 0 && !cur.selection();
1808 case LFUN_PARAGRAPH_MOVE_DOWN:
1809 enable = cur.pit() < cur.lastpit() && !cur.selection();
1812 case LFUN_INSET_DISSOLVE:
1813 enable = !isMainText(cur.bv().buffer()) && cur.inset().nargs() == 1;
1816 case LFUN_CHANGE_ACCEPT:
1817 case LFUN_CHANGE_REJECT:
1818 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
1819 // In principle, these LFUNs should only be enabled if there
1820 // is a change at the current position/in the current selection.
1821 // However, without proper optimizations, this will inevitably
1822 // result in unacceptable performance - just imagine a user who
1823 // wants to select the complete content of a long document.
1827 case LFUN_WORD_DELETE_FORWARD:
1828 case LFUN_WORD_DELETE_BACKWARD:
1829 case LFUN_LINE_DELETE:
1830 case LFUN_WORD_FORWARD:
1831 case LFUN_WORD_BACKWARD:
1832 case LFUN_CHAR_FORWARD:
1833 case LFUN_CHAR_FORWARD_SELECT:
1834 case LFUN_CHAR_BACKWARD:
1835 case LFUN_CHAR_BACKWARD_SELECT:
1837 case LFUN_UP_SELECT:
1839 case LFUN_DOWN_SELECT:
1840 case LFUN_PARAGRAPH_UP_SELECT:
1841 case LFUN_PARAGRAPH_DOWN_SELECT:
1842 case LFUN_SCREEN_UP_SELECT:
1843 case LFUN_SCREEN_DOWN_SELECT:
1844 case LFUN_LINE_BEGIN_SELECT:
1845 case LFUN_LINE_END_SELECT:
1846 case LFUN_WORD_FORWARD_SELECT:
1847 case LFUN_WORD_BACKWARD_SELECT:
1848 case LFUN_WORD_SELECT:
1849 case LFUN_PARAGRAPH_UP:
1850 case LFUN_PARAGRAPH_DOWN:
1851 case LFUN_LINE_BEGIN:
1853 case LFUN_BREAK_LINE:
1854 case LFUN_CHAR_DELETE_FORWARD:
1855 case LFUN_DELETE_FORWARD_SKIP:
1856 case LFUN_CHAR_DELETE_BACKWARD:
1857 case LFUN_DELETE_BACKWARD_SKIP:
1858 case LFUN_BREAK_PARAGRAPH:
1859 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
1860 case LFUN_BREAK_PARAGRAPH_SKIP:
1861 case LFUN_PARAGRAPH_SPACING:
1862 case LFUN_INSET_INSERT:
1863 case LFUN_WORD_UPCASE:
1864 case LFUN_WORD_LOWCASE:
1865 case LFUN_WORD_CAPITALIZE:
1866 case LFUN_CHARS_TRANSPOSE:
1867 case LFUN_SERVER_GET_XY:
1868 case LFUN_SERVER_SET_XY:
1869 case LFUN_SERVER_GET_FONT:
1870 case LFUN_SERVER_GET_LAYOUT:
1872 case LFUN_DATE_INSERT:
1873 case LFUN_SELF_INSERT:
1874 case LFUN_LINE_INSERT:
1875 case LFUN_PAGEBREAK_INSERT:
1876 case LFUN_CLEARPAGE_INSERT:
1877 case LFUN_CLEARDOUBLEPAGE_INSERT:
1878 case LFUN_MATH_DISPLAY:
1879 case LFUN_MATH_IMPORT_SELECTION:
1880 case LFUN_MATH_MODE:
1881 case LFUN_MATH_MACRO:
1882 case LFUN_MATH_MATRIX:
1883 case LFUN_MATH_DELIM:
1884 case LFUN_MATH_BIGDELIM:
1885 case LFUN_MATH_INSERT:
1886 case LFUN_MATH_SUBSCRIPT:
1887 case LFUN_MATH_SUPERSCRIPT:
1888 case LFUN_FONT_DEFAULT:
1889 case LFUN_FONT_UNDERLINE:
1890 case LFUN_FONT_SIZE:
1892 case LFUN_FONT_FREE_APPLY:
1893 case LFUN_FONT_FREE_UPDATE:
1894 case LFUN_LAYOUT_PARAGRAPH:
1895 case LFUN_PARAGRAPH_UPDATE:
1896 case LFUN_ACCENT_UMLAUT:
1897 case LFUN_ACCENT_CIRCUMFLEX:
1898 case LFUN_ACCENT_GRAVE:
1899 case LFUN_ACCENT_ACUTE:
1900 case LFUN_ACCENT_TILDE:
1901 case LFUN_ACCENT_CEDILLA:
1902 case LFUN_ACCENT_MACRON:
1903 case LFUN_ACCENT_DOT:
1904 case LFUN_ACCENT_UNDERDOT:
1905 case LFUN_ACCENT_UNDERBAR:
1906 case LFUN_ACCENT_CARON:
1907 case LFUN_ACCENT_SPECIAL_CARON:
1908 case LFUN_ACCENT_BREVE:
1909 case LFUN_ACCENT_TIE:
1910 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1911 case LFUN_ACCENT_CIRCLE:
1912 case LFUN_ACCENT_OGONEK:
1913 case LFUN_THESAURUS_ENTRY:
1914 case LFUN_PARAGRAPH_PARAMS_APPLY:
1915 case LFUN_PARAGRAPH_PARAMS:
1917 case LFUN_BUFFER_END:
1918 case LFUN_BUFFER_BEGIN:
1919 case LFUN_BUFFER_BEGIN_SELECT:
1920 case LFUN_BUFFER_END_SELECT:
1921 case LFUN_UNICODE_INSERT:
1922 // these are handled in our dispatch()
1930 if (code != Inset::NO_CODE
1931 && (cur.empty() || !cur.inset().insetAllowed(code)))
1934 flag.enabled(enable);
1939 void Text::pasteString(Cursor & cur, docstring const & clip,
1942 cur.clearSelection();
1943 if (!clip.empty()) {
1946 insertStringAsParagraphs(cur, clip);
1948 insertStringAsLines(cur, clip);