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"
36 #include "InsetList.h"
40 #include "LyXAction.h"
44 #include "Paragraph.h"
45 #include "paragraph_funcs.h"
46 #include "ParagraphParameters.h"
47 #include "TextMetrics.h"
49 #include "ParIterator.h"
51 #include "frontends/Clipboard.h"
52 #include "frontends/Selection.h"
54 #include "insets/InsetCollapsable.h"
55 #include "insets/InsetCommand.h"
56 #include "insets/InsetFloatList.h"
57 #include "insets/InsetNewline.h"
58 #include "insets/InsetQuotes.h"
59 #include "insets/InsetSpecialChar.h"
60 #include "insets/InsetText.h"
61 #include "insets/InsetInfo.h"
63 #include "support/lstrings.h"
64 #include "support/lyxlib.h"
65 #include "support/convert.h"
66 #include "support/lyxtime.h"
68 #include "mathed/InsetMathHull.h"
69 #include "mathed/MathMacroTemplate.h"
71 #include <boost/current_function.hpp>
78 using std::istringstream;
79 using std::ostringstream;
83 using cap::copySelection;
84 using cap::cutSelection;
85 using cap::pasteFromStack;
86 using cap::pasteClipboard;
87 using cap::replaceSelection;
89 using support::isStrUnsignedInt;
93 static Font freefont(ignore_font);
94 static bool toggleall = false;
96 static void toggleAndShow(Cursor & cur, Text * text,
97 Font const & font, bool toggleall = true)
99 text->toggleFree(cur, font, toggleall);
101 if (font.language() != ignore_language ||
102 font.fontInfo().number() != FONT_IGNORE) {
103 TextMetrics const & tm = cur.bv().textMetrics(text);
104 if (cur.boundary() != tm.isRTLBoundary(cur.pit(),
105 cur.pos(), cur.real_current_font))
106 text->setCursor(cur, cur.pit(), cur.pos(),
107 false, !cur.boundary());
112 static void moveCursor(Cursor & cur, bool selecting)
114 if (selecting || cur.mark())
119 static void finishChange(Cursor & cur, bool selecting)
122 moveCursor(cur, selecting);
126 static void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
129 docstring sel = cur.selectionAsString(false);
131 // It may happen that sel is empty but there is a selection
132 replaceSelection(cur);
135 #ifdef ENABLE_ASSERTIONS
136 const int old_pos = cur.pos();
138 cur.insert(new InsetMathHull(hullSimple));
139 BOOST_ASSERT(old_pos == cur.pos());
140 cur.nextInset()->edit(cur, true);
141 // don't do that also for LFUN_MATH_MODE
142 // unless you want end up with always changing
143 // to mathrm when opening an inlined inset --
144 // I really hate "LyXfunc overloading"...
146 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
147 // Avoid an unnecessary undo step if cmd.argument
149 if (!cmd.argument().empty())
150 cur.dispatch(FuncRequest(LFUN_MATH_INSERT,
153 // create a macro if we see "\\newcommand"
154 // somewhere, and an ordinary formula
156 if (sel.find(from_ascii("\\newcommand")) == string::npos
157 && sel.find(from_ascii("\\def")) == string::npos)
159 InsetMathHull * formula = new InsetMathHull;
160 istringstream is(to_utf8(sel));
163 formula->read(cur.buffer(), lex);
164 if (formula->getType() == hullNone)
165 // Don't create pseudo formulas if
166 // delimiters are left out
167 formula->mutate(hullSimple);
170 cur.insert(new MathMacroTemplate(sel));
173 cur.message(from_utf8(N_("Math editor mode")));
177 static void specialChar(Cursor & cur, InsetSpecialChar::Kind kind)
180 cap::replaceSelection(cur);
181 cur.insert(new InsetSpecialChar(kind));
186 static bool doInsertInset(Cursor & cur, Text * text,
187 FuncRequest const & cmd, bool edit, bool pastesel)
189 Inset * inset = createInset(&cur.bv(), cmd);
194 if (cmd.action == LFUN_INDEX_INSERT) {
195 docstring ds = support::subst(text->getStringToIndex(cur), '\n', ' ');
196 text->insertInset(cur, inset);
198 inset->edit(cur, true);
199 // Now put this into inset
200 static_cast<InsetCollapsable *>(inset)->text_.insertStringAsParagraphs(cur, ds);
203 if (cur.selection()) {
204 lyx::dispatch(FuncRequest(LFUN_CUT));
207 text->insertInset(cur, inset);
210 inset->edit(cur, true);
212 if (gotsel && pastesel) {
213 lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
214 InsetText * insetText = dynamic_cast<InsetText *>(inset);
215 if (insetText && !insetText->allowMultiPar()
216 || cur.lastpit() == 0) {
217 // reset first par to default
218 LayoutPtr const layout =
219 cur.buffer().params().getTextClass().defaultLayout();
220 cur.text()->paragraphs().begin()->layout(layout);
223 // Merge multiple paragraphs -- hack
224 while (cur.lastpit() > 0) {
225 mergeParagraph(cur.buffer().params(),
226 cur.text()->paragraphs(), 0);
229 // reset surrounding par to default
230 docstring const layoutname =
231 cur.buffer().params().getTextClass().defaultLayoutName();
232 cur.leaveInset(*inset);
233 text->setLayout(cur, layoutname);
241 string const freefont2string()
243 return freefont.toString(toggleall);
247 void Text::number(Cursor & cur)
249 FontInfo font = ignore_font;
250 font.setNumber(FONT_TOGGLE);
251 toggleAndShow(cur, this, Font(font));
255 bool Text::isRTL(Buffer const & buffer, Paragraph const & par) const
257 return par.isRTL(buffer.params());
261 void Text::dispatch(Cursor & cur, FuncRequest & cmd)
263 LYXERR(Debug::ACTION) << "Text::dispatch: cmd: " << cmd << endl;
265 // FIXME: We use the update flag to indicates wether a singlePar or a
266 // full screen update is needed. We reset it here but shall we restore it
270 BOOST_ASSERT(cur.text() == this);
271 BufferView * bv = &cur.bv();
272 TextMetrics & tm = cur.bv().textMetrics(this);
273 CursorSlice oldTopSlice = cur.top();
274 bool oldBoundary = cur.boundary();
275 bool sel = cur.selection();
276 // Signals that, even if needsUpdate == false, an update of the
277 // cursor paragraph is required
278 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
279 LyXAction::SingleParUpdate);
280 // Signals that a full-screen update is required
281 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
282 LyXAction::NoUpdate) || singleParUpdate);
283 // Remember the old paragraph metric (_outer_ paragraph!)
284 ParagraphMetrics const & pm = cur.bv().parMetrics(
285 cur.bottom().text(), cur.bottom().pit());
286 Dimension olddim = pm.dim();
288 switch (cmd.action) {
290 case LFUN_PARAGRAPH_MOVE_DOWN: {
291 pit_type const pit = cur.pit();
292 recUndo(cur, pit, pit + 1);
294 std::swap(pars_[pit], pars_[pit + 1]);
295 updateLabels(cur.buffer());
301 case LFUN_PARAGRAPH_MOVE_UP: {
302 pit_type const pit = cur.pit();
303 recUndo(cur, pit - 1, pit);
305 std::swap(pars_[pit], pars_[pit - 1]);
306 updateLabels(cur.buffer());
312 case LFUN_APPENDIX: {
313 Paragraph & par = cur.paragraph();
314 bool start = !par.params().startOfAppendix();
316 // FIXME: The code below only makes sense at top level.
317 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
318 // ensure that we have only one start_of_appendix in this document
319 // FIXME: this don't work for multipart document!
320 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
321 if (pars_[tmp].params().startOfAppendix()) {
323 pars_[tmp].params().startOfAppendix(false);
329 par.params().startOfAppendix(start);
331 // we can set the refreshing parameters now
332 updateLabels(cur.buffer());
336 case LFUN_WORD_DELETE_FORWARD:
337 if (cur.selection()) {
338 cutSelection(cur, true, false);
340 deleteWordForward(cur);
341 finishChange(cur, false);
344 case LFUN_WORD_DELETE_BACKWARD:
345 if (cur.selection()) {
346 cutSelection(cur, true, false);
348 deleteWordBackward(cur);
349 finishChange(cur, false);
352 case LFUN_LINE_DELETE:
353 if (cur.selection()) {
354 cutSelection(cur, true, false);
356 tm.deleteLineForward(cur);
357 finishChange(cur, false);
360 case LFUN_BUFFER_BEGIN:
361 case LFUN_BUFFER_BEGIN_SELECT:
362 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
363 if (cur.depth() == 1) {
364 needsUpdate |= cursorTop(cur);
370 case LFUN_BUFFER_END:
371 case LFUN_BUFFER_END_SELECT:
372 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
373 if (cur.depth() == 1) {
374 needsUpdate |= cursorBottom(cur);
380 case LFUN_CHAR_FORWARD:
381 case LFUN_CHAR_FORWARD_SELECT:
382 //lyxerr << BOOST_CURRENT_FUNCTION
383 // << " LFUN_CHAR_FORWARD[SEL]:\n" << cur << endl;
384 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
385 needsUpdate |= cursorForward(cur);
387 if (!needsUpdate && oldTopSlice == cur.top()
388 && cur.boundary() == oldBoundary) {
390 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
394 case LFUN_CHAR_BACKWARD:
395 case LFUN_CHAR_BACKWARD_SELECT:
396 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
397 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
398 needsUpdate |= cursorBackward(cur);
400 if (!needsUpdate && oldTopSlice == cur.top()
401 && cur.boundary() == oldBoundary) {
403 cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
408 case LFUN_CHAR_LEFT_SELECT:
409 //FIXME: for visual cursor, really move left
410 if (reverseDirectionNeeded(cur)) {
411 lyx::dispatch(FuncRequest(
412 cmd.action == LFUN_CHAR_LEFT_SELECT ?
413 LFUN_CHAR_FORWARD_SELECT : LFUN_CHAR_FORWARD));
415 lyx::dispatch(FuncRequest(
416 cmd.action == LFUN_CHAR_LEFT_SELECT ?
417 LFUN_CHAR_BACKWARD_SELECT : LFUN_CHAR_BACKWARD));
421 case LFUN_CHAR_RIGHT:
422 case LFUN_CHAR_RIGHT_SELECT:
423 //FIXME: for visual cursor, really move right
424 if (reverseDirectionNeeded(cur)) {
425 lyx::dispatch(FuncRequest(
426 cmd.action == LFUN_CHAR_RIGHT_SELECT ?
427 LFUN_CHAR_BACKWARD_SELECT : LFUN_CHAR_BACKWARD));
429 lyx::dispatch(FuncRequest(
430 cmd.action == LFUN_CHAR_RIGHT_SELECT ?
431 LFUN_CHAR_FORWARD_SELECT : LFUN_CHAR_FORWARD));
436 case LFUN_DOWN_SELECT:
439 // stop/start the selection
440 bool select = cmd.action == LFUN_DOWN_SELECT ||
441 cmd.action == LFUN_UP_SELECT;
442 cur.selHandle(select);
444 // move cursor up/down
445 bool up = cmd.action == LFUN_UP_SELECT || cmd.action == LFUN_UP;
446 bool const successful = cur.upDownInText(up, needsUpdate);
448 // notify insets which were left and get their update flags
449 notifyCursorLeaves(cur.beforeDispatchCursor(), cur);
452 // redraw if you leave mathed (for the decorations)
453 needsUpdate |= cur.beforeDispatchCursor().inMathed();
460 case LFUN_PARAGRAPH_UP:
461 case LFUN_PARAGRAPH_UP_SELECT:
462 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
463 needsUpdate |= cursorUpParagraph(cur);
466 case LFUN_PARAGRAPH_DOWN:
467 case LFUN_PARAGRAPH_DOWN_SELECT:
468 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
469 needsUpdate |= cursorDownParagraph(cur);
472 case LFUN_SCREEN_UP_SELECT:
473 needsUpdate |= cur.selHandle(true);
474 if (cur.pit() == 0 && cur.textRow().pos() == 0)
477 tm.cursorPrevious(cur);
481 case LFUN_SCREEN_DOWN_SELECT:
482 needsUpdate |= cur.selHandle(true);
483 if (cur.pit() == cur.lastpit()
484 && cur.textRow().endpos() == cur.lastpos())
491 case LFUN_LINE_BEGIN:
492 case LFUN_LINE_BEGIN_SELECT:
493 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
494 needsUpdate |= tm.cursorHome(cur);
498 case LFUN_LINE_END_SELECT:
499 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
500 needsUpdate |= tm.cursorEnd(cur);
503 case LFUN_WORD_RIGHT:
504 case LFUN_WORD_RIGHT_SELECT:
505 //FIXME: for visual cursor mode, really move right
506 if (reverseDirectionNeeded(cur)) {
507 lyx::dispatch(FuncRequest(
508 cmd.action == LFUN_WORD_RIGHT_SELECT ?
509 LFUN_WORD_BACKWARD_SELECT : LFUN_WORD_BACKWARD));
511 lyx::dispatch(FuncRequest(
512 cmd.action == LFUN_WORD_RIGHT_SELECT ?
513 LFUN_WORD_FORWARD_SELECT : LFUN_WORD_FORWARD));
517 case LFUN_WORD_FORWARD:
518 case LFUN_WORD_FORWARD_SELECT:
519 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
520 needsUpdate |= cursorForwardOneWord(cur);
524 case LFUN_WORD_LEFT_SELECT:
525 //FIXME: for visual cursor mode, really move left
526 if (reverseDirectionNeeded(cur)) {
527 lyx::dispatch(FuncRequest(
528 cmd.action == LFUN_WORD_LEFT_SELECT ?
529 LFUN_WORD_FORWARD_SELECT : LFUN_WORD_FORWARD));
531 lyx::dispatch(FuncRequest(
532 cmd.action == LFUN_WORD_LEFT_SELECT ?
533 LFUN_WORD_BACKWARD_SELECT : LFUN_WORD_BACKWARD));
537 case LFUN_WORD_BACKWARD:
538 case LFUN_WORD_BACKWARD_SELECT:
539 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
540 needsUpdate |= cursorBackwardOneWord(cur);
543 case LFUN_WORD_SELECT: {
544 selectWord(cur, WHOLE_WORD);
545 finishChange(cur, true);
549 case LFUN_BREAK_LINE: {
550 // Not allowed by LaTeX (labels or empty par)
551 if (cur.pos() > cur.paragraph().beginOfBody()) {
552 // this avoids a double undo
553 // FIXME: should not be needed, ideally
554 if (!cur.selection())
556 cap::replaceSelection(cur);
557 cur.insert(new InsetNewline);
559 moveCursor(cur, false);
564 case LFUN_CHAR_DELETE_FORWARD:
565 if (!cur.selection()) {
566 if (cur.pos() == cur.paragraph().size())
567 // Par boundary, force full-screen update
568 singleParUpdate = false;
569 needsUpdate |= erase(cur);
571 // It is possible to make it a lot faster still
572 // just comment out the line below...
574 cutSelection(cur, true, false);
575 singleParUpdate = false;
577 moveCursor(cur, false);
580 case LFUN_DELETE_FORWARD_SKIP:
581 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
582 if (!cur.selection()) {
583 if (cur.pos() == cur.lastpos()) {
590 cutSelection(cur, true, false);
595 case LFUN_CHAR_DELETE_BACKWARD:
596 if (!cur.selection()) {
597 if (bv->getIntl().getTransManager().backspace()) {
598 // Par boundary, full-screen update
600 singleParUpdate = false;
601 needsUpdate |= backspace(cur);
603 // It is possible to make it a lot faster still
604 // just comment out the line below...
607 cutSelection(cur, true, false);
608 singleParUpdate = false;
612 case LFUN_DELETE_BACKWARD_SKIP:
613 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
614 if (!cur.selection()) {
616 //CursorSlice cur = cursor();
620 cutSelection(cur, true, false);
624 case LFUN_BREAK_PARAGRAPH:
625 cap::replaceSelection(cur);
626 breakParagraph(cur, cmd.argument() == "inverse");
630 case LFUN_BREAK_PARAGRAPH_SKIP: {
631 // When at the beginning of a paragraph, remove
632 // indentation. Otherwise, do the same as LFUN_BREAK_PARAGRAPH.
633 cap::replaceSelection(cur);
635 cur.paragraph().params().labelWidthString(docstring());
637 breakParagraph(cur, false);
643 // With the creation of LFUN_PARAGRAPH_PARAMS, this is now redundant,
644 // as its duties can be performed there. Should it be removed??
645 // FIXME For now, it can just dispatch LFUN_PARAGRAPH_PARAMS...
646 case LFUN_PARAGRAPH_SPACING: {
647 Paragraph & par = cur.paragraph();
648 Spacing::Space cur_spacing = par.params().spacing().getSpace();
649 string cur_value = "1.0";
650 if (cur_spacing == Spacing::Other)
651 cur_value = par.params().spacing().getValueAsString();
653 istringstream is(to_utf8(cmd.argument()));
656 Spacing::Space new_spacing = cur_spacing;
657 string new_value = cur_value;
659 lyxerr << "Missing argument to `paragraph-spacing'"
661 } else if (tmp == "single") {
662 new_spacing = Spacing::Single;
663 } else if (tmp == "onehalf") {
664 new_spacing = Spacing::Onehalf;
665 } else if (tmp == "double") {
666 new_spacing = Spacing::Double;
667 } else if (tmp == "other") {
668 new_spacing = Spacing::Other;
669 string tmpval = "0.0";
671 lyxerr << "new_value = " << tmpval << endl;
674 } else if (tmp == "default") {
675 new_spacing = Spacing::Default;
677 lyxerr << to_utf8(_("Unknown spacing argument: "))
678 << to_utf8(cmd.argument()) << endl;
680 if (cur_spacing != new_spacing || cur_value != new_value)
681 par.params().spacing(Spacing(new_spacing, new_value));
685 case LFUN_INSET_INSERT: {
687 Inset * inset = createInset(bv, cmd);
689 // FIXME (Abdel 01/02/2006):
690 // What follows would be a partial fix for bug 2154:
691 // http://bugzilla.lyx.org/show_bug.cgi?id=2154
692 // This automatically put the label inset _after_ a
693 // numbered section. It should be possible to extend the mechanism
694 // to any kind of LateX environement.
695 // The correct way to fix that bug would be at LateX generation.
696 // I'll let the code here for reference as it could be used for some
697 // other feature like "automatic labelling".
699 Paragraph & par = pars_[cur.pit()];
700 if (inset->lyxCode() == LABEL_CODE
701 && par.layout()->labeltype == LABEL_COUNTER) {
702 // Go to the end of the paragraph
703 // Warning: Because of Change-Tracking, the last
704 // position is 'size()' and not 'size()-1':
705 cur.pos() = par.size();
706 // Insert a new paragraph
707 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
712 cutSelection(cur, true, false);
713 insertInset(cur, inset);
719 case LFUN_INSET_DISSOLVE:
720 needsUpdate |= dissolveInset(cur);
723 case LFUN_INSET_SETTINGS:
724 cur.inset().showInsetDialog(bv);
727 case LFUN_SPACE_INSERT:
728 if (cur.paragraph().layout()->free_spacing)
729 insertChar(cur, ' ');
731 doInsertInset(cur, this, cmd, false, false);
734 moveCursor(cur, false);
737 case LFUN_HYPHENATION_POINT_INSERT:
738 specialChar(cur, InsetSpecialChar::HYPHENATION);
741 case LFUN_LIGATURE_BREAK_INSERT:
742 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
745 case LFUN_DOTS_INSERT:
746 specialChar(cur, InsetSpecialChar::LDOTS);
749 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
750 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
753 case LFUN_MENU_SEPARATOR_INSERT:
754 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
757 case LFUN_WORD_UPCASE:
758 changeCase(cur, text_uppercase);
761 case LFUN_WORD_LOWCASE:
762 changeCase(cur, text_lowercase);
765 case LFUN_WORD_CAPITALIZE:
766 changeCase(cur, text_capitalization);
769 case LFUN_CHARS_TRANSPOSE:
774 cur.message(_("Paste"));
775 cap::replaceSelection(cur);
776 if (cmd.argument().empty() && !theClipboard().isInternal())
777 pasteClipboard(cur, bv->buffer().errorList("Paste"));
779 string const arg(to_utf8(cmd.argument()));
780 pasteFromStack(cur, bv->buffer().errorList("Paste"),
781 isStrUnsignedInt(arg) ?
782 convert<unsigned int>(arg) :
785 bv->buffer().errors("Paste");
786 cur.clearSelection(); // bug 393
791 cutSelection(cur, true, true);
792 cur.message(_("Cut"));
797 cur.message(_("Copy"));
800 case LFUN_SERVER_GET_XY:
801 cur.message(from_utf8(
802 convert<string>(tm.cursorX(cur.top(), cur.boundary()))
803 + ' ' + convert<string>(tm.cursorY(cur.top(), cur.boundary()))));
806 case LFUN_SERVER_SET_XY: {
809 istringstream is(to_utf8(cmd.argument()));
812 lyxerr << "SETXY: Could not parse coordinates in '"
813 << to_utf8(cmd.argument()) << std::endl;
815 tm.setCursorFromCoordinates(cur, x, y);
819 case LFUN_SERVER_GET_FONT:
820 if (cur.current_font.fontInfo().shape() == ITALIC_SHAPE)
821 cur.message(from_ascii("E"));
822 else if (cur.current_font.fontInfo().shape() == SMALLCAPS_SHAPE)
823 cur.message(from_ascii("N"));
825 cur.message(from_ascii("0"));
828 case LFUN_SERVER_GET_LAYOUT:
829 cur.message(cur.paragraph().layout()->name());
833 docstring layout = cmd.argument();
834 LYXERR(Debug::INFO) << "LFUN_LAYOUT: (arg) " << to_utf8(layout) << endl;
836 docstring const old_layout = cur.paragraph().layout()->name();
838 // Derive layout number from given argument (string)
839 // and current buffer's textclass (number)
840 TextClass const & tclass = bv->buffer().params().getTextClass();
842 layout = tclass.defaultLayoutName();
843 bool hasLayout = tclass.hasLayout(layout);
845 // If the entry is obsolete, use the new one instead.
847 docstring const & obs = tclass[layout]->obsoleted_by();
853 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
854 from_utf8(N_(" not known")));
858 bool change_layout = (old_layout != layout);
860 if (!change_layout && cur.selection() &&
861 cur.selBegin().pit() != cur.selEnd().pit())
863 pit_type spit = cur.selBegin().pit();
864 pit_type epit = cur.selEnd().pit() + 1;
865 while (spit != epit) {
866 if (pars_[spit].layout()->name() != old_layout) {
867 change_layout = true;
875 setLayout(cur, layout);
880 case LFUN_CLIPBOARD_PASTE:
881 cur.clearSelection();
882 pasteClipboard(cur, bv->buffer().errorList("Paste"),
883 cmd.argument() == "paragraph");
884 bv->buffer().errors("Paste");
887 case LFUN_PRIMARY_SELECTION_PASTE:
888 pasteString(cur, theSelection().get(),
889 cmd.argument() == "paragraph");
892 case LFUN_UNICODE_INSERT: {
893 if (cmd.argument().empty())
895 docstring hexstring = cmd.argument();
896 if (lyx::support::isHex(hexstring)) {
897 char_type c = lyx::support::hexToInt(hexstring);
898 if (c >= 32 && c < 0x10ffff) {
899 lyxerr << "Inserting c: " << c << endl;
900 docstring s = docstring(1, c);
901 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
907 case LFUN_QUOTE_INSERT: {
908 Paragraph & par = cur.paragraph();
909 pos_type pos = cur.pos();
910 BufferParams const & bufparams = bv->buffer().params();
911 LayoutPtr const & style = par.layout();
912 if (!style->pass_thru
913 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
914 // this avoids a double undo
915 // FIXME: should not be needed, ideally
916 if (!cur.selection())
918 cap::replaceSelection(cur);
923 else if (cur.prevInset() && cur.prevInset()->isSpace())
926 c = par.getChar(pos - 1);
927 string arg = to_utf8(cmd.argument());
929 cur.insert(new InsetQuotes(c,
930 bufparams.quotes_language,
931 InsetQuotes::SingleQ));
933 cur.insert(new InsetQuotes(c,
934 bufparams.quotes_language,
935 InsetQuotes::DoubleQ));
939 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
943 case LFUN_DATE_INSERT: {
944 string const format = cmd.argument().empty()
945 ? lyxrc.date_insert_format : to_utf8(cmd.argument());
946 string const time = formatted_time(current_time(), format);
947 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, time));
951 case LFUN_MOUSE_TRIPLE:
952 if (cmd.button() == mouse_button::button1) {
961 case LFUN_MOUSE_DOUBLE:
962 if (cmd.button() == mouse_button::button1) {
963 selectWord(cur, WHOLE_WORD_STRICT);
968 // Single-click on work area
969 case LFUN_MOUSE_PRESS: {
970 // Right click on a footnote flag opens float menu
971 // FIXME: Why should we clear the selection in this case?
972 if (cmd.button() == mouse_button::button3)
973 cur.clearSelection();
975 bool do_selection = cmd.button() == mouse_button::button1
976 && cmd.argument() == "region-select";
978 bool update = bv->mouseSetCursor(cur, do_selection);
980 // Insert primary selection with middle mouse
981 // if there is a local selection in the current buffer,
983 if (cmd.button() == mouse_button::button2) {
984 if (cap::selection()) {
985 // Copy the selection buffer to the clipboard
986 // stack, because we want it to appear in the
987 // "Edit->Paste recent" menu.
988 cap::copySelectionToStack();
990 cap::pasteSelection(bv->cursor(),
991 bv->buffer().errorList("Paste"));
992 bv->buffer().errors("Paste");
993 bv->buffer().markDirty();
994 bv->cursor().finishUndo();
996 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
1000 // we have to update after dEPM triggered
1001 if (!update && cmd.button() == mouse_button::button1) {
1002 needsUpdate = false;
1009 case LFUN_MOUSE_MOTION: {
1010 // Only use motion with button 1
1011 //if (cmd.button() != mouse_button::button1)
1014 // ignore motions deeper nested than the real anchor
1015 Cursor & bvcur = cur.bv().cursor();
1016 if (bvcur.anchor_.hasPart(cur)) {
1017 CursorSlice old = bvcur.top();
1019 int const wh = bv->workHeight();
1020 int const y = std::max(0, std::min(wh - 1, cmd.y));
1022 tm.setCursorFromCoordinates(cur, cmd.x, y);
1023 cur.setTargetX(cmd.x);
1025 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1027 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1028 // This is to allow jumping over large insets
1029 if (cur.top() == old) {
1031 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1033 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1036 if (cur.top() == old)
1039 // don't set anchor_
1040 bvcur.setCursor(cur);
1041 bvcur.selection() = true;
1042 //lyxerr << "MOTION: " << bv->cursor() << endl;
1050 case LFUN_MOUSE_RELEASE: {
1051 if (cmd.button() == mouse_button::button2)
1054 if (cmd.button() == mouse_button::button1) {
1055 // if there is new selection, update persistent
1056 // selection, otherwise, single click does not
1057 // clear persistent selection buffer
1058 if (cur.selection()) {
1060 // if double click, cur is moved to the end of word by selectWord
1061 // but bvcur is current mouse position
1062 Cursor & bvcur = cur.bv().cursor();
1063 bvcur.selection() = true;
1065 needsUpdate = false;
1072 case LFUN_SELF_INSERT: {
1073 if (cmd.argument().empty())
1076 // Automatically delete the currently selected
1077 // text and replace it with what is being
1078 // typed in now. Depends on lyxrc settings
1079 // "auto_region_delete", which defaults to
1082 if (lyxrc.auto_region_delete && cur.selection()) {
1083 cutSelection(cur, false, false);
1084 // When change tracking is set to off, the metrics update
1085 // mechanism correctly detects if a full update is needed or not.
1086 // This detection fails when a selection spans multiple rows and
1087 // change tracking is enabled because the paragraph metrics stays
1088 // the same. In this case, we force the full update:
1089 // (see http://bugzilla.lyx.org/show_bug.cgi?id=3992)
1090 if (cur.buffer().params().trackChanges)
1091 cur.updateFlags(Update::Force);
1094 cur.clearSelection();
1095 Font const old_font = cur.real_current_font;
1097 docstring::const_iterator cit = cmd.argument().begin();
1098 docstring::const_iterator end = cmd.argument().end();
1099 for (; cit != end; ++cit)
1100 bv->translateAndInsert(*cit, this, cur);
1103 moveCursor(cur, false);
1107 case LFUN_HYPERLINK_INSERT: {
1108 InsetCommandParams p(HYPERLINK_CODE);
1110 if (cur.selection()) {
1111 content = cur.selectionAsString(false);
1112 cutSelection(cur, true, false);
1114 p["target"] = (cmd.argument().empty()) ?
1115 content : cmd.argument();
1116 string const data = InsetCommandMailer::params2string("href", p);
1117 if (p["target"].empty()) {
1118 bv->showInsetDialog("href", data, 0);
1120 FuncRequest fr(LFUN_INSET_INSERT, data);
1126 case LFUN_LABEL_INSERT: {
1127 InsetCommandParams p(LABEL_CODE);
1128 // Try to generate a valid label
1129 p["name"] = (cmd.argument().empty()) ?
1130 cur.getPossibleLabel() :
1132 string const data = InsetCommandMailer::params2string("label", p);
1134 if (cmd.argument().empty()) {
1135 bv->showInsetDialog("label", data, 0);
1137 FuncRequest fr(LFUN_INSET_INSERT, data);
1143 case LFUN_INFO_INSERT: {
1144 Inset * inset = createInset(&cur.bv(), cmd);
1147 // if an empty inset is created (cmd.argument() is empty)
1148 // use current selection as parameter.
1149 if (cmd.argument().empty() && cur.selection()) {
1150 // use selected text as info to avoid a separate UI
1151 docstring ds = cur.selectionAsString(false);
1152 cutSelection(cur, true, false);
1153 static_cast<InsetInfo *>(inset)->setInfo(to_utf8(ds));
1155 insertInset(cur, inset);
1160 case LFUN_LIST_INSERT:
1161 case LFUN_THEOREM_INSERT:
1163 case LFUN_CAPTION_INSERT:
1164 // Open the inset, and move the current selection
1166 doInsertInset(cur, this, cmd, true, true);
1168 updateLabels(bv->buffer());
1170 case LFUN_NOTE_INSERT:
1171 case LFUN_FLEX_INSERT:
1172 case LFUN_BOX_INSERT:
1173 case LFUN_BRANCH_INSERT:
1174 case LFUN_BIBITEM_INSERT:
1175 case LFUN_ERT_INSERT:
1176 case LFUN_LISTING_INSERT:
1177 case LFUN_FOOTNOTE_INSERT:
1178 case LFUN_MARGINALNOTE_INSERT:
1179 case LFUN_OPTIONAL_INSERT:
1180 case LFUN_ENVIRONMENT_INSERT:
1181 // Open the inset, and move the current selection
1183 doInsertInset(cur, this, cmd, true, true);
1187 case LFUN_TABULAR_INSERT:
1188 // if there were no arguments, just open the dialog
1189 if (doInsertInset(cur, this, cmd, false, true))
1192 bv->showDialog("tabularcreate");
1196 case LFUN_FLOAT_INSERT:
1197 case LFUN_FLOAT_WIDE_INSERT:
1198 case LFUN_WRAP_INSERT: {
1199 bool content = cur.selection(); // will some text be moved into the inset?
1201 doInsertInset(cur, this, cmd, true, true);
1203 ParagraphList & pars = cur.text()->paragraphs();
1205 TextClass const & tclass = bv->buffer().params().getTextClass();
1207 // add a separate paragraph for the caption inset
1208 pars.push_back(Paragraph());
1209 pars.back().setInsetOwner(pars[0].inInset());
1210 pars.back().layout(tclass.defaultLayout());
1212 int cap_pit = pars.size() - 1;
1214 // if an empty inset was created, we create an additional empty
1215 // paragraph at the bottom so that the user can choose where to put
1216 // the graphics (or table).
1218 pars.push_back(Paragraph());
1219 pars.back().setInsetOwner(pars[0].inInset());
1220 pars.back().layout(tclass.defaultLayout());
1224 // reposition the cursor to the caption
1225 cur.pit() = cap_pit;
1227 // FIXME: This Text/Cursor dispatch handling is a mess!
1228 // We cannot use Cursor::dispatch here it needs access to up to
1230 FuncRequest cmd_caption(LFUN_CAPTION_INSERT);
1231 cur.text()->dispatch(cur, cmd_caption);
1232 cur.updateFlags(Update::Force);
1233 // FIXME: When leaving the Float (or Wrap) inset we should
1234 // delete any empty paragraph left above or below the
1239 case LFUN_INDEX_INSERT:
1240 doInsertInset(cur, this, cmd, true, true);
1243 case LFUN_NOMENCL_INSERT: {
1244 Inset * inset = createInset(&cur.bv(), cmd);
1248 cur.clearSelection();
1249 insertInset(cur, inset);
1250 // Show the dialog for the nomenclature entry, since the
1251 // description entry still needs to be filled in.
1252 if (cmd.action == LFUN_NOMENCL_INSERT)
1253 inset->edit(cur, true);
1258 case LFUN_INDEX_PRINT:
1259 case LFUN_NOMENCL_PRINT:
1260 case LFUN_TOC_INSERT:
1261 case LFUN_HFILL_INSERT:
1262 case LFUN_LINE_INSERT:
1263 case LFUN_PAGEBREAK_INSERT:
1264 case LFUN_CLEARPAGE_INSERT:
1265 case LFUN_CLEARDOUBLEPAGE_INSERT:
1267 doInsertInset(cur, this, cmd, false, false);
1271 case LFUN_DEPTH_DECREMENT:
1272 changeDepth(cur, DEC_DEPTH);
1275 case LFUN_DEPTH_INCREMENT:
1276 changeDepth(cur, INC_DEPTH);
1279 case LFUN_MATH_DISPLAY:
1280 mathDispatch(cur, cmd, true);
1283 case LFUN_MATH_IMPORT_SELECTION:
1284 case LFUN_MATH_MODE:
1285 if (cmd.argument() == "on")
1286 // don't pass "on" as argument
1287 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1289 mathDispatch(cur, cmd, false);
1292 case LFUN_MATH_MACRO:
1293 if (cmd.argument().empty())
1294 cur.errorMessage(from_utf8(N_("Missing argument")));
1296 string s = to_utf8(cmd.argument());
1297 string const s1 = token(s, ' ', 1);
1298 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1299 string const s2 = token(s, ' ', 2);
1300 string const type = s2.empty() ? "newcommand" : s2;
1301 cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, false, from_utf8(type)));
1302 //cur.nextInset()->edit(cur, true);
1306 // passthrough hat and underscore outside mathed:
1307 case LFUN_MATH_SUBSCRIPT:
1308 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1310 case LFUN_MATH_SUPERSCRIPT:
1311 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1314 case LFUN_MATH_INSERT:
1315 case LFUN_MATH_MATRIX:
1316 case LFUN_MATH_DELIM:
1317 case LFUN_MATH_BIGDELIM: {
1318 if (cur.selection())
1319 cur.clearSelection();
1320 // FIXME: instead of the above, this one
1321 // should be used (but it asserts with Bidi enabled)
1322 // cf. http://bugzilla.lyx.org/show_bug.cgi?id=4055
1323 // cap::replaceSelection(cur);
1324 cur.insert(new InsetMathHull(hullSimple));
1325 checkAndActivateInset(cur, true);
1326 BOOST_ASSERT(cur.inMathed());
1331 case LFUN_FONT_EMPH: {
1332 Font font(ignore_font);
1333 font.fontInfo().setEmph(FONT_TOGGLE);
1334 toggleAndShow(cur, this, font);
1338 case LFUN_FONT_BOLD: {
1339 Font font(ignore_font);
1340 font.fontInfo().setSeries(BOLD_SERIES);
1341 toggleAndShow(cur, this, font);
1345 case LFUN_FONT_NOUN: {
1346 Font font(ignore_font);
1347 font.fontInfo().setNoun(FONT_TOGGLE);
1348 toggleAndShow(cur, this, font);
1352 case LFUN_FONT_TYPEWRITER: {
1353 Font font(ignore_font);
1354 font.fontInfo().setFamily(TYPEWRITER_FAMILY); // no good
1355 toggleAndShow(cur, this, font);
1359 case LFUN_FONT_SANS: {
1360 Font font(ignore_font);
1361 font.fontInfo().setFamily(SANS_FAMILY);
1362 toggleAndShow(cur, this, font);
1366 case LFUN_FONT_ROMAN: {
1367 Font font(ignore_font);
1368 font.fontInfo().setFamily(ROMAN_FAMILY);
1369 toggleAndShow(cur, this, font);
1373 case LFUN_FONT_DEFAULT: {
1374 Font font(inherit_font, ignore_language);
1375 toggleAndShow(cur, this, font);
1379 case LFUN_FONT_UNDERLINE: {
1380 Font font(ignore_font);
1381 font.fontInfo().setUnderbar(FONT_TOGGLE);
1382 toggleAndShow(cur, this, font);
1386 case LFUN_FONT_SIZE: {
1387 Font font(ignore_font);
1388 setLyXSize(to_utf8(cmd.argument()), font.fontInfo());
1389 toggleAndShow(cur, this, font);
1393 case LFUN_LANGUAGE: {
1394 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1397 Font font(ignore_font);
1398 font.setLanguage(lang);
1399 toggleAndShow(cur, this, font);
1403 case LFUN_FONT_FREE_APPLY:
1404 toggleAndShow(cur, this, freefont, toggleall);
1405 cur.message(_("Character set"));
1408 // Set the freefont using the contents of \param data dispatched from
1409 // the frontends and apply it at the current cursor location.
1410 case LFUN_FONT_FREE_UPDATE: {
1413 if (font.fromString(to_utf8(cmd.argument()), toggle)) {
1416 toggleAndShow(cur, this, freefont, toggleall);
1417 cur.message(_("Character set"));
1419 lyxerr << "Argument not ok";
1424 case LFUN_FINISHED_LEFT:
1425 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1426 if (reverseDirectionNeeded(cur)) {
1428 cur.setCurrentFont();
1432 case LFUN_FINISHED_RIGHT:
1433 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1434 if (!reverseDirectionNeeded(cur)) {
1436 cur.setCurrentFont();
1440 case LFUN_FINISHED_BACKWARD:
1441 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_BACKWARD:\n" << cur << endl;
1444 case LFUN_FINISHED_FORWARD:
1445 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_FORWARD:\n" << cur << endl;
1447 cur.setCurrentFont();
1450 case LFUN_LAYOUT_PARAGRAPH: {
1452 params2string(cur.paragraph(), data);
1453 data = "show\n" + data;
1454 bv->showDialogWithData("paragraph", data);
1458 case LFUN_PARAGRAPH_UPDATE: {
1460 params2string(cur.paragraph(), data);
1462 // Will the paragraph accept changes from the dialog?
1463 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1465 data = "update " + convert<string>(accept) + '\n' + data;
1466 bv->updateDialog("paragraph", data);
1470 case LFUN_ACCENT_UMLAUT:
1471 case LFUN_ACCENT_CIRCUMFLEX:
1472 case LFUN_ACCENT_GRAVE:
1473 case LFUN_ACCENT_ACUTE:
1474 case LFUN_ACCENT_TILDE:
1475 case LFUN_ACCENT_CEDILLA:
1476 case LFUN_ACCENT_MACRON:
1477 case LFUN_ACCENT_DOT:
1478 case LFUN_ACCENT_UNDERDOT:
1479 case LFUN_ACCENT_UNDERBAR:
1480 case LFUN_ACCENT_CARON:
1481 case LFUN_ACCENT_SPECIAL_CARON:
1482 case LFUN_ACCENT_BREVE:
1483 case LFUN_ACCENT_TIE:
1484 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1485 case LFUN_ACCENT_CIRCLE:
1486 case LFUN_ACCENT_OGONEK:
1487 theLyXFunc().handleKeyFunc(cmd.action);
1488 if (!cmd.argument().empty())
1489 // FIXME: Are all these characters encoded in one byte in utf8?
1490 bv->translateAndInsert(cmd.argument()[0], this, cur);
1493 case LFUN_FLOAT_LIST: {
1494 TextClass const & tclass = bv->buffer().params().getTextClass();
1495 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1497 if (cur.selection())
1498 cutSelection(cur, true, false);
1499 breakParagraph(cur);
1501 if (cur.lastpos() != 0) {
1502 cursorBackward(cur);
1503 breakParagraph(cur);
1506 setLayout(cur, tclass.defaultLayoutName());
1507 ParagraphParameters p;
1508 setParagraphs(cur, p);
1509 insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1512 lyxerr << "Non-existent float type: "
1513 << to_utf8(cmd.argument()) << endl;
1518 case LFUN_CHANGE_ACCEPT: {
1519 acceptOrRejectChanges(cur, ACCEPT);
1523 case LFUN_CHANGE_REJECT: {
1524 acceptOrRejectChanges(cur, REJECT);
1528 case LFUN_THESAURUS_ENTRY: {
1529 docstring arg = cmd.argument();
1531 arg = cur.selectionAsString(false);
1533 if (arg.size() > 100 || arg.empty()) {
1534 // Get word or selection
1535 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1536 arg = cur.selectionAsString(false);
1539 bv->showDialogWithData("thesaurus", to_utf8(arg));
1543 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1544 // Given data, an encoding of the ParagraphParameters
1545 // generated in the Paragraph dialog, this function sets
1546 // the current paragraph, or currently selected paragraphs,
1548 // NOTE: This function overrides all existing settings.
1549 setParagraphs(cur, cmd.argument());
1550 cur.message(_("Paragraph layout set"));
1554 case LFUN_PARAGRAPH_PARAMS: {
1555 // Given data, an encoding of the ParagraphParameters as we'd
1556 // find them in a LyX file, this function modifies the current paragraph,
1557 // or currently selected paragraphs.
1558 // NOTE: This function only modifies, and does not override, existing
1560 setParagraphs(cur, cmd.argument(), true);
1561 cur.message(_("Paragraph layout set"));
1566 if (cur.selection()) {
1567 cur.selection() = false;
1570 // This used to be LFUN_FINISHED_RIGHT, I think FORWARD is more
1571 // correct, but I'm not 100% sure -- dov, 071019
1572 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
1577 LYXERR(Debug::ACTION)
1578 << BOOST_CURRENT_FUNCTION
1579 << ": Command " << cmd
1580 << " not DISPATCHED by Text" << endl;
1585 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1587 // FIXME: The cursor flag is reset two lines below
1588 // so we need to check here if some of the LFUN did touch that.
1589 // for now only Text::erase() and Text::backspace() do that.
1590 // The plan is to verify all the LFUNs and then to remove this
1591 // singleParUpdate boolean altogether.
1592 if (cur.result().update() & Update::Force) {
1593 singleParUpdate = false;
1597 // FIXME: the following code should go in favor of fine grained
1598 // update flag treatment.
1599 if (singleParUpdate) {
1600 // Inserting characters does not change par height
1601 ParagraphMetrics const & pms
1602 = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
1603 if (pms.dim().height()
1604 == olddim.height()) {
1605 // if so, update _only_ this paragraph
1606 cur.updateFlags(Update::SinglePar |
1608 Update::MultiParSel);
1615 && &oldTopSlice.inset() == &cur.inset()
1616 && oldTopSlice.idx() == cur.idx()
1617 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1618 && !cur.selection())
1619 // FIXME: it would be better if we could just do this
1621 //if (cur.result().update() != Update::FitCursor)
1624 // But some LFUNs do not set Update::FitCursor when needed, so we
1625 // do it for all. This is not very harmfull as FitCursor will provoke
1626 // a full redraw only if needed but still, a proper review of all LFUN
1627 // should be done and this needsUpdate boolean can then be removed.
1628 cur.updateFlags(Update::FitCursor);
1630 cur.updateFlags(Update::Force | Update::FitCursor);
1634 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
1635 FuncStatus & flag) const
1637 BOOST_ASSERT(cur.text() == this);
1639 Font const & font = cur.real_current_font;
1640 FontInfo const & fontinfo = font.fontInfo();
1642 InsetCode code = NO_CODE;
1644 switch (cmd.action) {
1646 case LFUN_DEPTH_DECREMENT:
1647 enable = changeDepthAllowed(cur, DEC_DEPTH);
1650 case LFUN_DEPTH_INCREMENT:
1651 enable = changeDepthAllowed(cur, INC_DEPTH);
1655 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1658 case LFUN_BIBITEM_INSERT:
1659 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO
1663 case LFUN_DIALOG_SHOW_NEW_INSET:
1664 if (cmd.argument() == "bibitem")
1665 code = BIBITEM_CODE;
1666 else if (cmd.argument() == "bibtex")
1668 else if (cmd.argument() == "box")
1670 else if (cmd.argument() == "branch")
1672 else if (cmd.argument() == "citation")
1674 else if (cmd.argument() == "ert")
1676 else if (cmd.argument() == "external")
1677 code = EXTERNAL_CODE;
1678 else if (cmd.argument() == "float")
1680 else if (cmd.argument() == "graphics")
1681 code = GRAPHICS_CODE;
1682 else if (cmd.argument() == "href")
1683 code = HYPERLINK_CODE;
1684 else if (cmd.argument() == "include")
1685 code = INCLUDE_CODE;
1686 else if (cmd.argument() == "index")
1688 else if (cmd.argument() == "nomenclature")
1689 code = NOMENCL_CODE;
1690 else if (cmd.argument() == "label")
1692 else if (cmd.argument() == "note")
1694 else if (cmd.argument() == "ref")
1696 else if (cmd.argument() == "toc")
1698 else if (cmd.argument() == "vspace")
1700 else if (cmd.argument() == "wrap")
1702 else if (cmd.argument() == "listings")
1703 code = LISTINGS_CODE;
1706 case LFUN_ERT_INSERT:
1709 case LFUN_LISTING_INSERT:
1710 code = LISTINGS_CODE;
1712 case LFUN_FOOTNOTE_INSERT:
1715 case LFUN_TABULAR_INSERT:
1716 code = TABULAR_CODE;
1718 case LFUN_MARGINALNOTE_INSERT:
1721 case LFUN_FLOAT_INSERT:
1722 case LFUN_FLOAT_WIDE_INSERT:
1725 case LFUN_WRAP_INSERT:
1728 case LFUN_FLOAT_LIST:
1729 code = FLOAT_LIST_CODE;
1732 case LFUN_LIST_INSERT:
1735 case LFUN_THEOREM_INSERT:
1736 code = THEOREM_CODE;
1739 case LFUN_CAPTION_INSERT:
1740 code = CAPTION_CODE;
1742 case LFUN_NOTE_INSERT:
1745 case LFUN_FLEX_INSERT: {
1747 string s = cmd.getArg(0);
1748 InsetLayout il = cur.buffer().params().getTextClass().insetlayout(from_utf8(s));
1749 if (il.lyxtype != "charstyle" &&
1750 il.lyxtype != "custom" &&
1751 il.lyxtype != "element")
1755 case LFUN_BOX_INSERT:
1758 case LFUN_BRANCH_INSERT:
1760 if (cur.buffer().masterBuffer()->params().branchlist().empty())
1763 case LFUN_LABEL_INSERT:
1766 case LFUN_INFO_INSERT:
1769 case LFUN_OPTIONAL_INSERT:
1771 enable = cur.paragraph().insetList().count(OPTARG_CODE)
1772 < cur.paragraph().layout()->optionalargs;
1774 case LFUN_ENVIRONMENT_INSERT:
1777 case LFUN_INDEX_INSERT:
1780 case LFUN_INDEX_PRINT:
1781 code = INDEX_PRINT_CODE;
1783 case LFUN_NOMENCL_INSERT:
1784 code = NOMENCL_CODE;
1786 case LFUN_NOMENCL_PRINT:
1787 code = NOMENCL_PRINT_CODE;
1789 case LFUN_TOC_INSERT:
1792 case LFUN_HYPERLINK_INSERT:
1793 code = HYPERLINK_CODE;
1795 case LFUN_QUOTE_INSERT:
1796 // always allow this, since we will inset a raw quote
1797 // if an inset is not allowed.
1799 case LFUN_HYPHENATION_POINT_INSERT:
1800 case LFUN_LIGATURE_BREAK_INSERT:
1801 case LFUN_HFILL_INSERT:
1802 case LFUN_MENU_SEPARATOR_INSERT:
1803 case LFUN_DOTS_INSERT:
1804 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
1805 code = SPECIALCHAR_CODE;
1807 case LFUN_SPACE_INSERT:
1808 // slight hack: we know this is allowed in math mode
1813 case LFUN_INSET_MODIFY:
1814 // We need to disable this, because we may get called for a
1816 // InsetTabular::getStatus() -> InsetText::getStatus()
1817 // and we don't handle LFUN_INSET_MODIFY.
1821 case LFUN_FONT_EMPH:
1822 flag.setOnOff(fontinfo.emph() == FONT_ON);
1825 case LFUN_FONT_NOUN:
1826 flag.setOnOff(fontinfo.noun() == FONT_ON);
1829 case LFUN_FONT_BOLD:
1830 flag.setOnOff(fontinfo.series() == BOLD_SERIES);
1833 case LFUN_FONT_SANS:
1834 flag.setOnOff(fontinfo.family() == SANS_FAMILY);
1837 case LFUN_FONT_ROMAN:
1838 flag.setOnOff(fontinfo.family() == ROMAN_FAMILY);
1841 case LFUN_FONT_TYPEWRITER:
1842 flag.setOnOff(fontinfo.family() == TYPEWRITER_FAMILY);
1847 enable = cur.selection();
1851 if (cmd.argument().empty()) {
1852 if (theClipboard().isInternal())
1853 enable = cap::numberOfSelections() > 0;
1855 enable = !theClipboard().empty();
1857 string const arg = to_utf8(cmd.argument());
1858 if (isStrUnsignedInt(arg)) {
1859 unsigned int n = convert<unsigned int>(arg);
1860 enable = cap::numberOfSelections() > n;
1867 case LFUN_CLIPBOARD_PASTE:
1868 enable = !theClipboard().empty();
1871 case LFUN_PRIMARY_SELECTION_PASTE:
1872 enable = cur.selection() || !theSelection().empty();
1875 case LFUN_PARAGRAPH_MOVE_UP:
1876 enable = cur.pit() > 0 && !cur.selection();
1879 case LFUN_PARAGRAPH_MOVE_DOWN:
1880 enable = cur.pit() < cur.lastpit() && !cur.selection();
1883 case LFUN_INSET_DISSOLVE:
1884 if (!cmd.argument().empty()) {
1885 InsetLayout il = cur.inset().getLayout(cur.buffer().params());
1886 enable = cur.inset().lyxCode() == FLEX_CODE
1887 && il.lyxtype == to_utf8(cmd.argument());
1889 enable = !isMainText(cur.bv().buffer())
1890 && cur.inset().nargs() == 1;
1894 case LFUN_CHANGE_ACCEPT:
1895 case LFUN_CHANGE_REJECT:
1896 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
1897 // In principle, these LFUNs should only be enabled if there
1898 // is a change at the current position/in the current selection.
1899 // However, without proper optimizations, this will inevitably
1900 // result in unacceptable performance - just imagine a user who
1901 // wants to select the complete content of a long document.
1905 case LFUN_WORD_DELETE_FORWARD:
1906 case LFUN_WORD_DELETE_BACKWARD:
1907 case LFUN_LINE_DELETE:
1908 case LFUN_WORD_FORWARD:
1909 case LFUN_WORD_BACKWARD:
1910 case LFUN_WORD_RIGHT:
1911 case LFUN_WORD_LEFT:
1912 case LFUN_CHAR_FORWARD:
1913 case LFUN_CHAR_FORWARD_SELECT:
1914 case LFUN_CHAR_BACKWARD:
1915 case LFUN_CHAR_BACKWARD_SELECT:
1916 case LFUN_CHAR_LEFT:
1917 case LFUN_CHAR_LEFT_SELECT:
1918 case LFUN_CHAR_RIGHT:
1919 case LFUN_CHAR_RIGHT_SELECT:
1921 case LFUN_UP_SELECT:
1923 case LFUN_DOWN_SELECT:
1924 case LFUN_PARAGRAPH_UP_SELECT:
1925 case LFUN_PARAGRAPH_DOWN_SELECT:
1926 case LFUN_SCREEN_UP_SELECT:
1927 case LFUN_SCREEN_DOWN_SELECT:
1928 case LFUN_LINE_BEGIN_SELECT:
1929 case LFUN_LINE_END_SELECT:
1930 case LFUN_WORD_FORWARD_SELECT:
1931 case LFUN_WORD_BACKWARD_SELECT:
1932 case LFUN_WORD_RIGHT_SELECT:
1933 case LFUN_WORD_LEFT_SELECT:
1934 case LFUN_WORD_SELECT:
1935 case LFUN_PARAGRAPH_UP:
1936 case LFUN_PARAGRAPH_DOWN:
1937 case LFUN_LINE_BEGIN:
1939 case LFUN_BREAK_LINE:
1940 case LFUN_CHAR_DELETE_FORWARD:
1941 case LFUN_DELETE_FORWARD_SKIP:
1942 case LFUN_CHAR_DELETE_BACKWARD:
1943 case LFUN_DELETE_BACKWARD_SKIP:
1944 case LFUN_BREAK_PARAGRAPH:
1945 case LFUN_BREAK_PARAGRAPH_SKIP:
1946 case LFUN_PARAGRAPH_SPACING:
1947 case LFUN_INSET_INSERT:
1948 case LFUN_WORD_UPCASE:
1949 case LFUN_WORD_LOWCASE:
1950 case LFUN_WORD_CAPITALIZE:
1951 case LFUN_CHARS_TRANSPOSE:
1952 case LFUN_SERVER_GET_XY:
1953 case LFUN_SERVER_SET_XY:
1954 case LFUN_SERVER_GET_FONT:
1955 case LFUN_SERVER_GET_LAYOUT:
1957 case LFUN_DATE_INSERT:
1958 case LFUN_SELF_INSERT:
1959 case LFUN_LINE_INSERT:
1960 case LFUN_PAGEBREAK_INSERT:
1961 case LFUN_CLEARPAGE_INSERT:
1962 case LFUN_CLEARDOUBLEPAGE_INSERT:
1963 case LFUN_MATH_DISPLAY:
1964 case LFUN_MATH_IMPORT_SELECTION:
1965 case LFUN_MATH_MODE:
1966 case LFUN_MATH_MACRO:
1967 case LFUN_MATH_MATRIX:
1968 case LFUN_MATH_DELIM:
1969 case LFUN_MATH_BIGDELIM:
1970 case LFUN_MATH_INSERT:
1971 case LFUN_MATH_SUBSCRIPT:
1972 case LFUN_MATH_SUPERSCRIPT:
1973 case LFUN_FONT_DEFAULT:
1974 case LFUN_FONT_UNDERLINE:
1975 case LFUN_FONT_SIZE:
1977 case LFUN_FONT_FREE_APPLY:
1978 case LFUN_FONT_FREE_UPDATE:
1979 case LFUN_LAYOUT_PARAGRAPH:
1980 case LFUN_PARAGRAPH_UPDATE:
1981 case LFUN_ACCENT_UMLAUT:
1982 case LFUN_ACCENT_CIRCUMFLEX:
1983 case LFUN_ACCENT_GRAVE:
1984 case LFUN_ACCENT_ACUTE:
1985 case LFUN_ACCENT_TILDE:
1986 case LFUN_ACCENT_CEDILLA:
1987 case LFUN_ACCENT_MACRON:
1988 case LFUN_ACCENT_DOT:
1989 case LFUN_ACCENT_UNDERDOT:
1990 case LFUN_ACCENT_UNDERBAR:
1991 case LFUN_ACCENT_CARON:
1992 case LFUN_ACCENT_SPECIAL_CARON:
1993 case LFUN_ACCENT_BREVE:
1994 case LFUN_ACCENT_TIE:
1995 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1996 case LFUN_ACCENT_CIRCLE:
1997 case LFUN_ACCENT_OGONEK:
1998 case LFUN_THESAURUS_ENTRY:
1999 case LFUN_PARAGRAPH_PARAMS_APPLY:
2000 case LFUN_PARAGRAPH_PARAMS:
2002 case LFUN_BUFFER_END:
2003 case LFUN_BUFFER_BEGIN:
2004 case LFUN_BUFFER_BEGIN_SELECT:
2005 case LFUN_BUFFER_END_SELECT:
2006 case LFUN_UNICODE_INSERT:
2007 // these are handled in our dispatch()
2016 && (cur.empty() || !cur.inset().insetAllowed(code)))
2019 flag.enabled(enable);
2024 void Text::pasteString(Cursor & cur, docstring const & clip,
2027 cur.clearSelection();
2028 if (!clip.empty()) {
2031 insertStringAsParagraphs(cur, clip);
2033 insertStringAsLines(cur, clip);