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 InsetLayout il = inset->getLayout(cur.buffer().params());
213 if (!il.multipar || cur.lastpit() == 0) {
214 // reset first par to default
215 LayoutPtr const layout =
216 cur.buffer().params().getTextClass().defaultLayout();
217 cur.text()->paragraphs().begin()->layout(layout);
220 // Merge multiple paragraphs -- hack
221 while (cur.lastpit() > 0) {
222 mergeParagraph(cur.buffer().params(),
223 cur.text()->paragraphs(), 0);
226 // reset surrounding par to default
227 docstring const layoutname =
228 cur.buffer().params().getTextClass().defaultLayoutName();
229 cur.leaveInset(*inset);
230 text->setLayout(cur, layoutname);
239 string const freefont2string()
241 return freefont.toString(toggleall);
245 void Text::number(Cursor & cur)
247 Font font(Font::ALL_IGNORE);
248 font.setNumber(Font::TOGGLE);
249 toggleAndShow(cur, this, font);
253 bool Text::isRTL(Buffer const & buffer, Paragraph const & par) const
255 return par.isRTL(buffer.params());
259 void Text::dispatch(Cursor & cur, FuncRequest & cmd)
261 LYXERR(Debug::ACTION) << "Text::dispatch: cmd: " << cmd << endl;
263 // FIXME: We use the update flag to indicates wether a singlePar or a
264 // full screen update is needed. We reset it here but shall we restore it
268 BOOST_ASSERT(cur.text() == this);
269 BufferView * bv = &cur.bv();
270 TextMetrics & tm = cur.bv().textMetrics(this);
271 CursorSlice oldTopSlice = cur.top();
272 bool oldBoundary = cur.boundary();
273 bool sel = cur.selection();
274 // Signals that, even if needsUpdate == false, an update of the
275 // cursor paragraph is required
276 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
277 LyXAction::SingleParUpdate);
278 // Signals that a full-screen update is required
279 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
280 LyXAction::NoUpdate) || singleParUpdate);
281 // Remember the old paragraph metric (_outer_ paragraph!)
282 ParagraphMetrics const & pm = cur.bv().parMetrics(
283 cur.bottom().text(), cur.bottom().pit());
284 Dimension olddim = pm.dim();
286 switch (cmd.action) {
288 case LFUN_PARAGRAPH_MOVE_DOWN: {
289 pit_type const pit = cur.pit();
290 recUndo(cur, pit, pit + 1);
292 std::swap(pars_[pit], pars_[pit + 1]);
293 updateLabels(cur.buffer());
299 case LFUN_PARAGRAPH_MOVE_UP: {
300 pit_type const pit = cur.pit();
301 recUndo(cur, pit - 1, pit);
303 std::swap(pars_[pit], pars_[pit - 1]);
304 updateLabels(cur.buffer());
310 case LFUN_APPENDIX: {
311 Paragraph & par = cur.paragraph();
312 bool start = !par.params().startOfAppendix();
314 // FIXME: The code below only makes sense at top level.
315 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
316 // ensure that we have only one start_of_appendix in this document
317 // FIXME: this don't work for multipart document!
318 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
319 if (pars_[tmp].params().startOfAppendix()) {
321 pars_[tmp].params().startOfAppendix(false);
327 par.params().startOfAppendix(start);
329 // we can set the refreshing parameters now
330 updateLabels(cur.buffer());
334 case LFUN_WORD_DELETE_FORWARD:
335 if (cur.selection()) {
336 cutSelection(cur, true, false);
338 deleteWordForward(cur);
339 finishChange(cur, false);
342 case LFUN_WORD_DELETE_BACKWARD:
343 if (cur.selection()) {
344 cutSelection(cur, true, false);
346 deleteWordBackward(cur);
347 finishChange(cur, false);
350 case LFUN_LINE_DELETE:
351 if (cur.selection()) {
352 cutSelection(cur, true, false);
354 tm.deleteLineForward(cur);
355 finishChange(cur, false);
358 case LFUN_BUFFER_BEGIN:
359 case LFUN_BUFFER_BEGIN_SELECT:
360 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
361 if (cur.depth() == 1) {
362 needsUpdate |= cursorTop(cur);
368 case LFUN_BUFFER_END:
369 case LFUN_BUFFER_END_SELECT:
370 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
371 if (cur.depth() == 1) {
372 needsUpdate |= cursorBottom(cur);
378 case LFUN_CHAR_FORWARD:
379 case LFUN_CHAR_FORWARD_SELECT:
380 //lyxerr << BOOST_CURRENT_FUNCTION
381 // << " LFUN_CHAR_FORWARD[SEL]:\n" << cur << endl;
382 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
383 if (reverseDirectionNeeded(cur))
384 needsUpdate |= cursorLeft(cur);
386 needsUpdate |= cursorRight(cur);
388 if (!needsUpdate && oldTopSlice == cur.top()
389 && cur.boundary() == oldBoundary) {
391 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
395 case LFUN_CHAR_BACKWARD:
396 case LFUN_CHAR_BACKWARD_SELECT:
397 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
398 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
399 if (reverseDirectionNeeded(cur))
400 needsUpdate |= cursorRight(cur);
402 needsUpdate |= cursorLeft(cur);
404 if (!needsUpdate && oldTopSlice == cur.top()
405 && cur.boundary() == oldBoundary) {
407 cmd = FuncRequest(LFUN_FINISHED_LEFT);
412 case LFUN_DOWN_SELECT:
415 // stop/start the selection
416 bool select = cmd.action == LFUN_DOWN_SELECT ||
417 cmd.action == LFUN_UP_SELECT;
418 cur.selHandle(select);
420 // move cursor up/down
421 bool up = cmd.action == LFUN_UP_SELECT || cmd.action == LFUN_UP;
422 bool const successful = cur.upDownInText(up, needsUpdate);
424 // notify insets which were left and get their update flags
425 notifyCursorLeaves(cur.beforeDispatchCursor(), cur);
428 // redraw if you leave mathed (for the decorations)
429 needsUpdate |= cur.beforeDispatchCursor().inMathed();
436 case LFUN_PARAGRAPH_UP:
437 case LFUN_PARAGRAPH_UP_SELECT:
438 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
439 needsUpdate |= cursorUpParagraph(cur);
442 case LFUN_PARAGRAPH_DOWN:
443 case LFUN_PARAGRAPH_DOWN_SELECT:
444 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
445 needsUpdate |= cursorDownParagraph(cur);
448 case LFUN_SCREEN_UP_SELECT:
449 needsUpdate |= cur.selHandle(true);
450 if (cur.pit() == 0 && cur.textRow().pos() == 0)
453 tm.cursorPrevious(cur);
457 case LFUN_SCREEN_DOWN_SELECT:
458 needsUpdate |= cur.selHandle(true);
459 if (cur.pit() == cur.lastpit()
460 && cur.textRow().endpos() == cur.lastpos())
467 case LFUN_LINE_BEGIN:
468 case LFUN_LINE_BEGIN_SELECT:
469 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
470 needsUpdate |= tm.cursorHome(cur);
474 case LFUN_LINE_END_SELECT:
475 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
476 needsUpdate |= tm.cursorEnd(cur);
479 case LFUN_WORD_FORWARD:
480 case LFUN_WORD_FORWARD_SELECT:
481 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
482 if (reverseDirectionNeeded(cur))
483 needsUpdate |= cursorLeftOneWord(cur);
485 needsUpdate |= cursorRightOneWord(cur);
488 case LFUN_WORD_BACKWARD:
489 case LFUN_WORD_BACKWARD_SELECT:
490 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
491 if (reverseDirectionNeeded(cur))
492 needsUpdate |= cursorRightOneWord(cur);
494 needsUpdate |= cursorLeftOneWord(cur);
497 case LFUN_WORD_SELECT: {
498 selectWord(cur, WHOLE_WORD);
499 finishChange(cur, true);
503 case LFUN_BREAK_LINE: {
504 // Not allowed by LaTeX (labels or empty par)
505 if (cur.pos() > cur.paragraph().beginOfBody()) {
506 // this avoids a double undo
507 // FIXME: should not be needed, ideally
508 if (!cur.selection())
510 cap::replaceSelection(cur);
511 cur.insert(new InsetNewline);
513 moveCursor(cur, false);
518 case LFUN_CHAR_DELETE_FORWARD:
519 if (!cur.selection()) {
520 if (cur.pos() == cur.paragraph().size())
521 // Par boundary, force full-screen update
522 singleParUpdate = false;
523 needsUpdate |= erase(cur);
525 // It is possible to make it a lot faster still
526 // just comment out the line below...
528 cutSelection(cur, true, false);
529 singleParUpdate = false;
531 moveCursor(cur, false);
534 case LFUN_DELETE_FORWARD_SKIP:
535 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
536 if (!cur.selection()) {
537 if (cur.pos() == cur.lastpos()) {
544 cutSelection(cur, true, false);
549 case LFUN_CHAR_DELETE_BACKWARD:
550 if (!cur.selection()) {
551 if (bv->getIntl().getTransManager().backspace()) {
552 // Par boundary, full-screen update
554 singleParUpdate = false;
555 needsUpdate |= backspace(cur);
557 // It is possible to make it a lot faster still
558 // just comment out the line below...
561 cutSelection(cur, true, false);
562 singleParUpdate = false;
566 case LFUN_DELETE_BACKWARD_SKIP:
567 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
568 if (!cur.selection()) {
570 //CursorSlice cur = cursor();
574 cutSelection(cur, true, false);
578 case LFUN_BREAK_PARAGRAPH:
579 cap::replaceSelection(cur);
580 breakParagraph(cur, cmd.argument() == "inverse");
584 case LFUN_BREAK_PARAGRAPH_SKIP: {
585 // When at the beginning of a paragraph, remove
586 // indentation. Otherwise, do the same as LFUN_BREAK_PARAGRAPH.
587 cap::replaceSelection(cur);
589 cur.paragraph().params().labelWidthString(docstring());
591 breakParagraph(cur, false);
597 // With the creation of LFUN_PARAGRAPH_PARAMS, this is now redundant,
598 // as its duties can be performed there. Should it be removed??
599 // FIXME For now, it can just dispatch LFUN_PARAGRAPH_PARAMS...
600 case LFUN_PARAGRAPH_SPACING: {
601 Paragraph & par = cur.paragraph();
602 Spacing::Space cur_spacing = par.params().spacing().getSpace();
603 string cur_value = "1.0";
604 if (cur_spacing == Spacing::Other)
605 cur_value = par.params().spacing().getValueAsString();
607 istringstream is(to_utf8(cmd.argument()));
610 Spacing::Space new_spacing = cur_spacing;
611 string new_value = cur_value;
613 lyxerr << "Missing argument to `paragraph-spacing'"
615 } else if (tmp == "single") {
616 new_spacing = Spacing::Single;
617 } else if (tmp == "onehalf") {
618 new_spacing = Spacing::Onehalf;
619 } else if (tmp == "double") {
620 new_spacing = Spacing::Double;
621 } else if (tmp == "other") {
622 new_spacing = Spacing::Other;
623 string tmpval = "0.0";
625 lyxerr << "new_value = " << tmpval << endl;
628 } else if (tmp == "default") {
629 new_spacing = Spacing::Default;
631 lyxerr << to_utf8(_("Unknown spacing argument: "))
632 << to_utf8(cmd.argument()) << endl;
634 if (cur_spacing != new_spacing || cur_value != new_value)
635 par.params().spacing(Spacing(new_spacing, new_value));
639 case LFUN_INSET_INSERT: {
641 Inset * inset = createInset(bv, cmd);
643 // FIXME (Abdel 01/02/2006):
644 // What follows would be a partial fix for bug 2154:
645 // http://bugzilla.lyx.org/show_bug.cgi?id=2154
646 // This automatically put the label inset _after_ a
647 // numbered section. It should be possible to extend the mechanism
648 // to any kind of LateX environement.
649 // The correct way to fix that bug would be at LateX generation.
650 // I'll let the code here for reference as it could be used for some
651 // other feature like "automatic labelling".
653 Paragraph & par = pars_[cur.pit()];
654 if (inset->lyxCode() == Inset::LABEL_CODE
655 && par.layout()->labeltype == LABEL_COUNTER) {
656 // Go to the end of the paragraph
657 // Warning: Because of Change-Tracking, the last
658 // position is 'size()' and not 'size()-1':
659 cur.pos() = par.size();
660 // Insert a new paragraph
661 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
666 cutSelection(cur, true, false);
667 insertInset(cur, inset);
673 case LFUN_INSET_DISSOLVE:
674 needsUpdate |= dissolveInset(cur);
677 case LFUN_INSET_SETTINGS:
678 cur.inset().showInsetDialog(bv);
681 case LFUN_SPACE_INSERT:
682 if (cur.paragraph().layout()->free_spacing)
683 insertChar(cur, ' ');
685 doInsertInset(cur, this, cmd, false, false);
688 moveCursor(cur, false);
691 case LFUN_HYPHENATION_POINT_INSERT:
692 specialChar(cur, InsetSpecialChar::HYPHENATION);
695 case LFUN_LIGATURE_BREAK_INSERT:
696 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
699 case LFUN_DOTS_INSERT:
700 specialChar(cur, InsetSpecialChar::LDOTS);
703 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
704 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
707 case LFUN_MENU_SEPARATOR_INSERT:
708 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
711 case LFUN_WORD_UPCASE:
712 changeCase(cur, Text::text_uppercase);
715 case LFUN_WORD_LOWCASE:
716 changeCase(cur, Text::text_lowercase);
719 case LFUN_WORD_CAPITALIZE:
720 changeCase(cur, Text::text_capitalization);
723 case LFUN_CHARS_TRANSPOSE:
728 cur.message(_("Paste"));
729 cap::replaceSelection(cur);
730 if (cmd.argument().empty() && !theClipboard().isInternal())
731 pasteClipboard(cur, bv->buffer().errorList("Paste"));
733 string const arg(to_utf8(cmd.argument()));
734 pasteFromStack(cur, bv->buffer().errorList("Paste"),
735 isStrUnsignedInt(arg) ?
736 convert<unsigned int>(arg) :
739 bv->buffer().errors("Paste");
740 cur.clearSelection(); // bug 393
745 cutSelection(cur, true, true);
746 cur.message(_("Cut"));
751 cur.message(_("Copy"));
754 case LFUN_SERVER_GET_XY:
755 cur.message(from_utf8(
756 convert<string>(tm.cursorX(cur.top(), cur.boundary()))
757 + ' ' + convert<string>(tm.cursorY(cur.top(), cur.boundary()))));
760 case LFUN_SERVER_SET_XY: {
763 istringstream is(to_utf8(cmd.argument()));
766 lyxerr << "SETXY: Could not parse coordinates in '"
767 << to_utf8(cmd.argument()) << std::endl;
769 tm.setCursorFromCoordinates(cur, x, y);
773 case LFUN_SERVER_GET_FONT:
774 if (cur.current_font.shape() == Font::ITALIC_SHAPE)
775 cur.message(from_ascii("E"));
776 else if (cur.current_font.shape() == Font::SMALLCAPS_SHAPE)
777 cur.message(from_ascii("N"));
779 cur.message(from_ascii("0"));
782 case LFUN_SERVER_GET_LAYOUT:
783 cur.message(cur.paragraph().layout()->name());
787 docstring layout = cmd.argument();
788 LYXERR(Debug::INFO) << "LFUN_LAYOUT: (arg) " << to_utf8(layout) << endl;
790 docstring const old_layout = cur.paragraph().layout()->name();
792 // Derive layout number from given argument (string)
793 // and current buffer's textclass (number)
794 TextClass const & tclass = bv->buffer().params().getTextClass();
796 layout = tclass.defaultLayoutName();
797 bool hasLayout = tclass.hasLayout(layout);
799 // If the entry is obsolete, use the new one instead.
801 docstring const & obs = tclass[layout]->obsoleted_by();
807 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
808 from_utf8(N_(" not known")));
812 bool change_layout = (old_layout != layout);
814 if (!change_layout && cur.selection() &&
815 cur.selBegin().pit() != cur.selEnd().pit())
817 pit_type spit = cur.selBegin().pit();
818 pit_type epit = cur.selEnd().pit() + 1;
819 while (spit != epit) {
820 if (pars_[spit].layout()->name() != old_layout) {
821 change_layout = true;
829 setLayout(cur, layout);
834 case LFUN_CLIPBOARD_PASTE:
835 cur.clearSelection();
836 pasteClipboard(cur, bv->buffer().errorList("Paste"),
837 cmd.argument() == "paragraph");
838 bv->buffer().errors("Paste");
841 case LFUN_PRIMARY_SELECTION_PASTE:
842 pasteString(cur, theSelection().get(),
843 cmd.argument() == "paragraph");
846 case LFUN_UNICODE_INSERT: {
847 if (cmd.argument().empty())
849 docstring hexstring = cmd.argument();
850 if (lyx::support::isHex(hexstring)) {
851 char_type c = lyx::support::hexToInt(hexstring);
852 if (c >= 32 && c < 0x10ffff) {
853 lyxerr << "Inserting c: " << c << endl;
854 docstring s = docstring(1, c);
855 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
861 case LFUN_QUOTE_INSERT: {
862 Paragraph & par = cur.paragraph();
863 pos_type pos = cur.pos();
864 BufferParams const & bufparams = bv->buffer().params();
865 LayoutPtr const & style = par.layout();
866 if (!style->pass_thru
867 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
868 // this avoids a double undo
869 // FIXME: should not be needed, ideally
870 if (!cur.selection())
872 cap::replaceSelection(cur);
877 else if (cur.prevInset() && cur.prevInset()->isSpace())
880 c = par.getChar(pos - 1);
881 string arg = to_utf8(cmd.argument());
883 cur.insert(new InsetQuotes(c,
884 bufparams.quotes_language,
885 InsetQuotes::SingleQ));
887 cur.insert(new InsetQuotes(c,
888 bufparams.quotes_language,
889 InsetQuotes::DoubleQ));
893 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
897 case LFUN_DATE_INSERT: {
898 string const format = cmd.argument().empty()
899 ? lyxrc.date_insert_format : to_utf8(cmd.argument());
900 string const time = formatted_time(current_time(), format);
901 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, time));
905 case LFUN_MOUSE_TRIPLE:
906 if (cmd.button() == mouse_button::button1) {
915 case LFUN_MOUSE_DOUBLE:
916 if (cmd.button() == mouse_button::button1) {
917 selectWord(cur, WHOLE_WORD_STRICT);
922 // Single-click on work area
923 case LFUN_MOUSE_PRESS: {
924 // Right click on a footnote flag opens float menu
925 if (cmd.button() == mouse_button::button3)
926 cur.clearSelection();
929 bool update = bv->mouseSetCursor(cur);
931 // Insert primary selection with middle mouse
932 // if there is a local selection in the current buffer,
934 if (cmd.button() == mouse_button::button2) {
935 if (cap::selection()) {
936 // Copy the selection buffer to the clipboard
937 // stack, because we want it to appear in the
938 // "Edit->Paste recent" menu.
939 cap::copySelectionToStack();
941 cap::pasteSelection(bv->cursor(),
942 bv->buffer().errorList("Paste"));
943 bv->buffer().errors("Paste");
944 bv->buffer().markDirty();
947 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
951 // we have to update after dEPM triggered
952 if (!update && cmd.button() == mouse_button::button1) {
960 case LFUN_MOUSE_MOTION: {
961 // Only use motion with button 1
962 //if (cmd.button() != mouse_button::button1)
965 // ignore motions deeper nested than the real anchor
966 Cursor & bvcur = cur.bv().cursor();
967 if (bvcur.anchor_.hasPart(cur)) {
968 CursorSlice old = bvcur.top();
970 int const wh = bv->workHeight();
971 int const y = std::max(0, std::min(wh - 1, cmd.y));
973 tm.setCursorFromCoordinates(cur, cmd.x, y);
974 cur.setTargetX(cmd.x);
976 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
978 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
979 // This is to allow jumping over large insets
980 if (cur.top() == old) {
982 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
984 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
987 if (cur.top() == old)
991 bvcur.setCursor(cur);
992 bvcur.selection() = true;
993 //lyxerr << "MOTION: " << bv->cursor() << endl;
1001 case LFUN_MOUSE_RELEASE: {
1002 if (cmd.button() == mouse_button::button2)
1005 if (cmd.button() == mouse_button::button1) {
1006 // if there is new selection, update persistent
1007 // selection, otherwise, single click does not
1008 // clear persistent selection buffer
1009 if (cur.selection()) {
1011 // if double click, cur is moved to the end of word by selectWord
1012 // but bvcur is current mouse position
1013 Cursor & bvcur = cur.bv().cursor();
1014 bvcur.selection() = true;
1016 needsUpdate = false;
1023 case LFUN_SELF_INSERT: {
1024 if (cmd.argument().empty())
1027 // Automatically delete the currently selected
1028 // text and replace it with what is being
1029 // typed in now. Depends on lyxrc settings
1030 // "auto_region_delete", which defaults to
1033 if (lyxrc.auto_region_delete && cur.selection()) {
1034 cutSelection(cur, false, false);
1035 // When change tracking is set to off, the metrics update
1036 // mechanism correctly detects if a full update is needed or not.
1037 // This detection fails when a selection spans multiple rows and
1038 // change tracking is enabled because the paragraph metrics stays
1039 // the same. In this case, we force the full update:
1040 // (see http://bugzilla.lyx.org/show_bug.cgi?id=3992)
1041 if (cur.buffer().params().trackChanges)
1042 cur.updateFlags(Update::Force);
1045 cur.clearSelection();
1046 Font const old_font = cur.real_current_font;
1048 docstring::const_iterator cit = cmd.argument().begin();
1049 docstring::const_iterator end = cmd.argument().end();
1050 for (; cit != end; ++cit)
1051 bv->translateAndInsert(*cit, this, cur);
1054 moveCursor(cur, false);
1058 case LFUN_URL_INSERT: {
1059 InsetCommandParams p("url");
1061 if (cur.selection()) {
1062 content = cur.selectionAsString(false);
1063 cutSelection(cur, true, false);
1065 p["target"] = (cmd.argument().empty()) ?
1066 content : cmd.argument();
1067 string const data = InsetCommandMailer::params2string("url", p);
1068 if (p["target"].empty()) {
1069 bv->showInsetDialog("url", data, 0);
1071 FuncRequest fr(LFUN_INSET_INSERT, data);
1077 case LFUN_HTML_INSERT: {
1078 InsetCommandParams p("htmlurl");
1080 if (cur.selection()) {
1081 content = cur.selectionAsString(false);
1082 cutSelection(cur, true, false);
1084 p["target"] = (cmd.argument().empty()) ?
1085 content : cmd.argument();
1086 string const data = InsetCommandMailer::params2string("url", p);
1087 if (p["target"].empty()) {
1088 bv->showInsetDialog("url", data, 0);
1090 FuncRequest fr(LFUN_INSET_INSERT, data);
1096 case LFUN_LABEL_INSERT: {
1097 InsetCommandParams p("label");
1098 // Try to generate a valid label
1099 p["name"] = (cmd.argument().empty()) ?
1100 cur.getPossibleLabel() :
1102 string const data = InsetCommandMailer::params2string("label", p);
1104 if (cmd.argument().empty()) {
1105 bv->showInsetDialog("label", data, 0);
1107 FuncRequest fr(LFUN_INSET_INSERT, data);
1115 case LFUN_LIST_INSERT:
1116 case LFUN_THEOREM_INSERT:
1118 case LFUN_CAPTION_INSERT:
1119 // Open the inset, and move the current selection
1121 doInsertInset(cur, this, cmd, true, true);
1123 updateLabels(bv->buffer());
1125 case LFUN_NOTE_INSERT:
1126 case LFUN_FLEX_INSERT:
1127 case LFUN_BOX_INSERT:
1128 case LFUN_BRANCH_INSERT:
1129 case LFUN_BIBITEM_INSERT:
1130 case LFUN_ERT_INSERT:
1131 case LFUN_LISTING_INSERT:
1132 case LFUN_FOOTNOTE_INSERT:
1133 case LFUN_MARGINALNOTE_INSERT:
1134 case LFUN_OPTIONAL_INSERT:
1135 case LFUN_ENVIRONMENT_INSERT:
1136 // Open the inset, and move the current selection
1138 doInsertInset(cur, this, cmd, true, true);
1142 case LFUN_TABULAR_INSERT:
1143 // if there were no arguments, just open the dialog
1144 if (doInsertInset(cur, this, cmd, false, true))
1147 bv->showDialog("tabularcreate");
1151 case LFUN_FLOAT_INSERT:
1152 case LFUN_FLOAT_WIDE_INSERT:
1153 case LFUN_WRAP_INSERT: {
1154 bool content = cur.selection(); // will some text be moved into the inset?
1156 doInsertInset(cur, this, cmd, true, true);
1158 ParagraphList & pars = cur.text()->paragraphs();
1160 TextClass const & tclass = bv->buffer().params().getTextClass();
1162 // add a separate paragraph for the caption inset
1163 pars.push_back(Paragraph());
1164 pars.back().setInsetOwner(pars[0].inInset());
1165 pars.back().layout(tclass.defaultLayout());
1167 int cap_pit = pars.size() - 1;
1169 // if an empty inset was created, we create an additional empty
1170 // paragraph at the bottom so that the user can choose where to put
1171 // the graphics (or table).
1173 pars.push_back(Paragraph());
1174 pars.back().setInsetOwner(pars[0].inInset());
1175 pars.back().layout(tclass.defaultLayout());
1179 // reposition the cursor to the caption
1180 cur.pit() = cap_pit;
1182 // FIXME: This Text/Cursor dispatch handling is a mess!
1183 // We cannot use Cursor::dispatch here it needs access to up to
1185 FuncRequest cmd_caption(LFUN_CAPTION_INSERT);
1186 cur.text()->dispatch(cur, cmd_caption);
1187 cur.updateFlags(Update::Force);
1188 // FIXME: When leaving the Float (or Wrap) inset we should
1189 // delete any empty paragraph left above or below the
1194 case LFUN_INDEX_INSERT:
1195 doInsertInset(cur, this, cmd, true, true);
1198 case LFUN_NOMENCL_INSERT: {
1199 Inset * inset = createInset(&cur.bv(), cmd);
1203 cur.clearSelection();
1204 insertInset(cur, inset);
1205 // Show the dialog for the nomenclature entry, since the
1206 // description entry still needs to be filled in.
1207 if (cmd.action == LFUN_NOMENCL_INSERT)
1208 inset->edit(cur, true);
1213 case LFUN_INDEX_PRINT:
1214 case LFUN_NOMENCL_PRINT:
1215 case LFUN_TOC_INSERT:
1216 case LFUN_HFILL_INSERT:
1217 case LFUN_LINE_INSERT:
1218 case LFUN_PAGEBREAK_INSERT:
1219 case LFUN_CLEARPAGE_INSERT:
1220 case LFUN_CLEARDOUBLEPAGE_INSERT:
1222 doInsertInset(cur, this, cmd, false, false);
1226 case LFUN_DEPTH_DECREMENT:
1227 changeDepth(cur, DEC_DEPTH);
1230 case LFUN_DEPTH_INCREMENT:
1231 changeDepth(cur, INC_DEPTH);
1234 case LFUN_MATH_DISPLAY:
1235 mathDispatch(cur, cmd, true);
1238 case LFUN_MATH_IMPORT_SELECTION:
1239 case LFUN_MATH_MODE:
1240 if (cmd.argument() == "on")
1241 // don't pass "on" as argument
1242 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1244 mathDispatch(cur, cmd, false);
1247 case LFUN_MATH_MACRO:
1248 if (cmd.argument().empty())
1249 cur.errorMessage(from_utf8(N_("Missing argument")));
1251 string s = to_utf8(cmd.argument());
1252 string const s1 = token(s, ' ', 1);
1253 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1254 string const s2 = token(s, ' ', 2);
1255 string const type = s2.empty() ? "newcommand" : s2;
1256 cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, from_utf8(type)));
1257 //cur.nextInset()->edit(cur, true);
1261 // passthrough hat and underscore outside mathed:
1262 case LFUN_MATH_SUBSCRIPT:
1263 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1265 case LFUN_MATH_SUPERSCRIPT:
1266 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1269 case LFUN_MATH_INSERT:
1270 case LFUN_MATH_MATRIX:
1271 case LFUN_MATH_DELIM:
1272 case LFUN_MATH_BIGDELIM: {
1273 if (cur.selection())
1274 cur.clearSelection();
1275 // FIXME: instead of the above, this one
1276 // should be used (but it asserts with Bidi enabled)
1277 // cf. http://bugzilla.lyx.org/show_bug.cgi?id=4055
1278 // cap::replaceSelection(cur);
1279 cur.insert(new InsetMathHull(hullSimple));
1280 checkAndActivateInset(cur, true);
1281 BOOST_ASSERT(cur.inMathed());
1286 case LFUN_FONT_EMPH: {
1287 Font font(Font::ALL_IGNORE);
1288 font.setEmph(Font::TOGGLE);
1289 toggleAndShow(cur, this, font);
1293 case LFUN_FONT_BOLD: {
1294 Font font(Font::ALL_IGNORE);
1295 font.setSeries(Font::BOLD_SERIES);
1296 toggleAndShow(cur, this, font);
1300 case LFUN_FONT_NOUN: {
1301 Font font(Font::ALL_IGNORE);
1302 font.setNoun(Font::TOGGLE);
1303 toggleAndShow(cur, this, font);
1307 case LFUN_FONT_TYPEWRITER: {
1308 Font font(Font::ALL_IGNORE);
1309 font.setFamily(Font::TYPEWRITER_FAMILY); // no good
1310 toggleAndShow(cur, this, font);
1314 case LFUN_FONT_SANS: {
1315 Font font(Font::ALL_IGNORE);
1316 font.setFamily(Font::SANS_FAMILY);
1317 toggleAndShow(cur, this, font);
1321 case LFUN_FONT_ROMAN: {
1322 Font font(Font::ALL_IGNORE);
1323 font.setFamily(Font::ROMAN_FAMILY);
1324 toggleAndShow(cur, this, font);
1328 case LFUN_FONT_DEFAULT: {
1329 Font font(Font::ALL_INHERIT, ignore_language);
1330 toggleAndShow(cur, this, font);
1334 case LFUN_FONT_UNDERLINE: {
1335 Font font(Font::ALL_IGNORE);
1336 font.setUnderbar(Font::TOGGLE);
1337 toggleAndShow(cur, this, font);
1341 case LFUN_FONT_SIZE: {
1342 Font font(Font::ALL_IGNORE);
1343 font.setLyXSize(to_utf8(cmd.argument()));
1344 toggleAndShow(cur, this, font);
1348 case LFUN_LANGUAGE: {
1349 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1352 Font font(Font::ALL_IGNORE);
1353 font.setLanguage(lang);
1354 toggleAndShow(cur, this, font);
1358 case LFUN_FONT_FREE_APPLY:
1359 toggleAndShow(cur, this, freefont, toggleall);
1360 cur.message(_("Character set"));
1363 // Set the freefont using the contents of \param data dispatched from
1364 // the frontends and apply it at the current cursor location.
1365 case LFUN_FONT_FREE_UPDATE: {
1368 if (font.fromString(to_utf8(cmd.argument()), toggle)) {
1371 toggleAndShow(cur, this, freefont, toggleall);
1372 cur.message(_("Character set"));
1377 case LFUN_FINISHED_LEFT:
1378 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1379 if (reverseDirectionNeeded(cur)) {
1381 cur.setCurrentFont();
1385 case LFUN_FINISHED_RIGHT:
1386 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1387 if (!reverseDirectionNeeded(cur)) {
1389 cur.setCurrentFont();
1393 case LFUN_LAYOUT_PARAGRAPH: {
1395 params2string(cur.paragraph(), data);
1396 data = "show\n" + data;
1397 bv->showDialogWithData("paragraph", data);
1401 case LFUN_PARAGRAPH_UPDATE: {
1403 params2string(cur.paragraph(), data);
1405 // Will the paragraph accept changes from the dialog?
1406 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1408 data = "update " + convert<string>(accept) + '\n' + data;
1409 bv->updateDialog("paragraph", data);
1413 case LFUN_ACCENT_UMLAUT:
1414 case LFUN_ACCENT_CIRCUMFLEX:
1415 case LFUN_ACCENT_GRAVE:
1416 case LFUN_ACCENT_ACUTE:
1417 case LFUN_ACCENT_TILDE:
1418 case LFUN_ACCENT_CEDILLA:
1419 case LFUN_ACCENT_MACRON:
1420 case LFUN_ACCENT_DOT:
1421 case LFUN_ACCENT_UNDERDOT:
1422 case LFUN_ACCENT_UNDERBAR:
1423 case LFUN_ACCENT_CARON:
1424 case LFUN_ACCENT_SPECIAL_CARON:
1425 case LFUN_ACCENT_BREVE:
1426 case LFUN_ACCENT_TIE:
1427 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1428 case LFUN_ACCENT_CIRCLE:
1429 case LFUN_ACCENT_OGONEK:
1430 theLyXFunc().handleKeyFunc(cmd.action);
1431 if (!cmd.argument().empty())
1432 // FIXME: Are all these characters encoded in one byte in utf8?
1433 bv->translateAndInsert(cmd.argument()[0], this, cur);
1436 case LFUN_FLOAT_LIST: {
1437 TextClass const & tclass = bv->buffer().params().getTextClass();
1438 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1440 if (cur.selection())
1441 cutSelection(cur, true, false);
1442 breakParagraph(cur);
1444 if (cur.lastpos() != 0) {
1446 breakParagraph(cur);
1449 setLayout(cur, tclass.defaultLayoutName());
1450 ParagraphParameters p;
1451 setParagraphs(cur, p);
1452 insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1455 lyxerr << "Non-existent float type: "
1456 << to_utf8(cmd.argument()) << endl;
1461 case LFUN_CHANGE_ACCEPT: {
1462 acceptOrRejectChanges(cur, ACCEPT);
1466 case LFUN_CHANGE_REJECT: {
1467 acceptOrRejectChanges(cur, REJECT);
1471 case LFUN_THESAURUS_ENTRY: {
1472 docstring arg = cmd.argument();
1474 arg = cur.selectionAsString(false);
1476 if (arg.size() > 100 || arg.empty()) {
1477 // Get word or selection
1478 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1479 arg = cur.selectionAsString(false);
1482 bv->showDialogWithData("thesaurus", to_utf8(arg));
1486 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1487 // Given data, an encoding of the ParagraphParameters
1488 // generated in the Paragraph dialog, this function sets
1489 // the current paragraph, or currently selected paragraphs,
1491 // NOTE: This function overrides all existing settings.
1492 setParagraphs(cur, cmd.argument());
1493 cur.message(_("Paragraph layout set"));
1497 case LFUN_PARAGRAPH_PARAMS: {
1498 // Given data, an encoding of the ParagraphParameters as we'd
1499 // find them in a LyX file, this function modifies the current paragraph,
1500 // or currently selected paragraphs.
1501 // NOTE: This function only modifies, and does not override, existing
1503 setParagraphs(cur, cmd.argument(), true);
1504 cur.message(_("Paragraph layout set"));
1509 if (cur.selection()) {
1510 cur.selection() = false;
1513 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1518 LYXERR(Debug::ACTION)
1519 << BOOST_CURRENT_FUNCTION
1520 << ": Command " << cmd
1521 << " not DISPATCHED by Text" << endl;
1526 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1528 // FIXME: The cursor flag is reset two lines below
1529 // so we need to check here if some of the LFUN did touch that.
1530 // for now only Text::erase() and Text::backspace() do that.
1531 // The plan is to verify all the LFUNs and then to remove this
1532 // singleParUpdate boolean altogether.
1533 if (cur.result().update() & Update::Force) {
1534 singleParUpdate = false;
1538 // FIXME: the following code should go in favor of fine grained
1539 // update flag treatment.
1540 if (singleParUpdate) {
1541 // Inserting characters does not change par height
1542 ParagraphMetrics const & pms
1543 = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
1544 if (pms.dim().height()
1545 == olddim.height()) {
1546 // if so, update _only_ this paragraph
1547 cur.updateFlags(Update::SinglePar |
1549 Update::MultiParSel);
1556 && &oldTopSlice.inset() == &cur.inset()
1557 && oldTopSlice.idx() == cur.idx()
1558 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1559 && !cur.selection())
1560 // FIXME: it would be better if we could just do this
1562 //if (cur.result().update() != Update::FitCursor)
1565 // But some LFUNs do not set Update::FitCursor when needed, so we
1566 // do it for all. This is not very harmfull as FitCursor will provoke
1567 // a full redraw only if needed but still, a proper review of all LFUN
1568 // should be done and this needsUpdate boolean can then be removed.
1569 cur.updateFlags(Update::FitCursor);
1571 cur.updateFlags(Update::Force | Update::FitCursor);
1575 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
1576 FuncStatus & flag) const
1578 BOOST_ASSERT(cur.text() == this);
1580 Font const & font = cur.real_current_font;
1582 Inset::Code code = Inset::NO_CODE;
1584 switch (cmd.action) {
1586 case LFUN_DEPTH_DECREMENT:
1587 enable = changeDepthAllowed(cur, DEC_DEPTH);
1590 case LFUN_DEPTH_INCREMENT:
1591 enable = changeDepthAllowed(cur, INC_DEPTH);
1595 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1598 case LFUN_BIBITEM_INSERT:
1599 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO
1603 case LFUN_DIALOG_SHOW_NEW_INSET:
1604 if (cmd.argument() == "bibitem")
1605 code = Inset::BIBITEM_CODE;
1606 else if (cmd.argument() == "bibtex")
1607 code = Inset::BIBTEX_CODE;
1608 else if (cmd.argument() == "box")
1609 code = Inset::BOX_CODE;
1610 else if (cmd.argument() == "branch")
1611 code = Inset::BRANCH_CODE;
1612 else if (cmd.argument() == "citation")
1613 code = Inset::CITE_CODE;
1614 else if (cmd.argument() == "ert")
1615 code = Inset::ERT_CODE;
1616 else if (cmd.argument() == "external")
1617 code = Inset::EXTERNAL_CODE;
1618 else if (cmd.argument() == "float")
1619 code = Inset::FLOAT_CODE;
1620 else if (cmd.argument() == "graphics")
1621 code = Inset::GRAPHICS_CODE;
1622 else if (cmd.argument() == "include")
1623 code = Inset::INCLUDE_CODE;
1624 else if (cmd.argument() == "index")
1625 code = Inset::INDEX_CODE;
1626 else if (cmd.argument() == "nomenclature")
1627 code = Inset::NOMENCL_CODE;
1628 else if (cmd.argument() == "label")
1629 code = Inset::LABEL_CODE;
1630 else if (cmd.argument() == "note")
1631 code = Inset::NOTE_CODE;
1632 else if (cmd.argument() == "ref")
1633 code = Inset::REF_CODE;
1634 else if (cmd.argument() == "toc")
1635 code = Inset::TOC_CODE;
1636 else if (cmd.argument() == "url")
1637 code = Inset::URL_CODE;
1638 else if (cmd.argument() == "vspace")
1639 code = Inset::VSPACE_CODE;
1640 else if (cmd.argument() == "wrap")
1641 code = Inset::WRAP_CODE;
1642 else if (cmd.argument() == "listings")
1643 code = Inset::LISTINGS_CODE;
1646 case LFUN_ERT_INSERT:
1647 code = Inset::ERT_CODE;
1649 case LFUN_LISTING_INSERT:
1650 code = Inset::LISTINGS_CODE;
1652 case LFUN_FOOTNOTE_INSERT:
1653 code = Inset::FOOT_CODE;
1655 case LFUN_TABULAR_INSERT:
1656 code = Inset::TABULAR_CODE;
1658 case LFUN_MARGINALNOTE_INSERT:
1659 code = Inset::MARGIN_CODE;
1661 case LFUN_FLOAT_INSERT:
1662 case LFUN_FLOAT_WIDE_INSERT:
1663 code = Inset::FLOAT_CODE;
1665 case LFUN_WRAP_INSERT:
1666 code = Inset::WRAP_CODE;
1668 case LFUN_FLOAT_LIST:
1669 code = Inset::FLOAT_LIST_CODE;
1672 case LFUN_LIST_INSERT:
1673 code = Inset::LIST_CODE;
1675 case LFUN_THEOREM_INSERT:
1676 code = Inset::THEOREM_CODE;
1679 case LFUN_CAPTION_INSERT:
1680 code = Inset::CAPTION_CODE;
1682 case LFUN_NOTE_INSERT:
1683 code = Inset::NOTE_CODE;
1685 case LFUN_FLEX_INSERT: {
1686 code = Inset::FLEX_CODE;
1687 string s = cmd.getArg(0);
1688 InsetLayout il = cur.buffer().params().getTextClass().insetlayout(from_utf8(s));
1689 if (il.lyxtype != "charstyle" &&
1690 il.lyxtype != "custom" &&
1691 il.lyxtype != "element")
1695 case LFUN_BOX_INSERT:
1696 code = Inset::BOX_CODE;
1698 case LFUN_BRANCH_INSERT:
1699 code = Inset::BRANCH_CODE;
1700 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1703 case LFUN_LABEL_INSERT:
1704 code = Inset::LABEL_CODE;
1706 case LFUN_OPTIONAL_INSERT:
1707 code = Inset::OPTARG_CODE;
1708 enable = numberOfOptArgs(cur.paragraph())
1709 < cur.paragraph().layout()->optionalargs;
1711 case LFUN_ENVIRONMENT_INSERT:
1712 code = Inset::BOX_CODE;
1714 case LFUN_INDEX_INSERT:
1715 code = Inset::INDEX_CODE;
1717 case LFUN_INDEX_PRINT:
1718 code = Inset::INDEX_PRINT_CODE;
1720 case LFUN_NOMENCL_INSERT:
1721 code = Inset::NOMENCL_CODE;
1723 case LFUN_NOMENCL_PRINT:
1724 code = Inset::NOMENCL_PRINT_CODE;
1726 case LFUN_TOC_INSERT:
1727 code = Inset::TOC_CODE;
1729 case LFUN_HTML_INSERT:
1730 case LFUN_URL_INSERT:
1731 code = Inset::URL_CODE;
1733 case LFUN_QUOTE_INSERT:
1734 // always allow this, since we will inset a raw quote
1735 // if an inset is not allowed.
1737 case LFUN_HYPHENATION_POINT_INSERT:
1738 case LFUN_LIGATURE_BREAK_INSERT:
1739 case LFUN_HFILL_INSERT:
1740 case LFUN_MENU_SEPARATOR_INSERT:
1741 case LFUN_DOTS_INSERT:
1742 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
1743 code = Inset::SPECIALCHAR_CODE;
1745 case LFUN_SPACE_INSERT:
1746 // slight hack: we know this is allowed in math mode
1748 code = Inset::SPACE_CODE;
1751 case LFUN_INSET_MODIFY:
1752 // We need to disable this, because we may get called for a
1754 // InsetTabular::getStatus() -> InsetText::getStatus()
1755 // and we don't handle LFUN_INSET_MODIFY.
1759 case LFUN_FONT_EMPH:
1760 flag.setOnOff(font.emph() == Font::ON);
1763 case LFUN_FONT_NOUN:
1764 flag.setOnOff(font.noun() == Font::ON);
1767 case LFUN_FONT_BOLD:
1768 flag.setOnOff(font.series() == Font::BOLD_SERIES);
1771 case LFUN_FONT_SANS:
1772 flag.setOnOff(font.family() == Font::SANS_FAMILY);
1775 case LFUN_FONT_ROMAN:
1776 flag.setOnOff(font.family() == Font::ROMAN_FAMILY);
1779 case LFUN_FONT_TYPEWRITER:
1780 flag.setOnOff(font.family() == Font::TYPEWRITER_FAMILY);
1785 enable = cur.selection();
1789 if (cmd.argument().empty()) {
1790 if (theClipboard().isInternal())
1791 enable = cap::numberOfSelections() > 0;
1793 enable = !theClipboard().empty();
1795 string const arg = to_utf8(cmd.argument());
1796 if (isStrUnsignedInt(arg)) {
1797 unsigned int n = convert<unsigned int>(arg);
1798 enable = cap::numberOfSelections() > n;
1805 case LFUN_CLIPBOARD_PASTE:
1806 enable = !theClipboard().empty();
1809 case LFUN_PRIMARY_SELECTION_PASTE:
1810 enable = cur.selection() || !theSelection().empty();
1813 case LFUN_PARAGRAPH_MOVE_UP:
1814 enable = cur.pit() > 0 && !cur.selection();
1817 case LFUN_PARAGRAPH_MOVE_DOWN:
1818 enable = cur.pit() < cur.lastpit() && !cur.selection();
1821 case LFUN_INSET_DISSOLVE:
1822 enable = !isMainText(cur.bv().buffer()) && cur.inset().nargs() == 1;
1825 case LFUN_CHANGE_ACCEPT:
1826 case LFUN_CHANGE_REJECT:
1827 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
1828 // In principle, these LFUNs should only be enabled if there
1829 // is a change at the current position/in the current selection.
1830 // However, without proper optimizations, this will inevitably
1831 // result in unacceptable performance - just imagine a user who
1832 // wants to select the complete content of a long document.
1836 case LFUN_WORD_DELETE_FORWARD:
1837 case LFUN_WORD_DELETE_BACKWARD:
1838 case LFUN_LINE_DELETE:
1839 case LFUN_WORD_FORWARD:
1840 case LFUN_WORD_BACKWARD:
1841 case LFUN_CHAR_FORWARD:
1842 case LFUN_CHAR_FORWARD_SELECT:
1843 case LFUN_CHAR_BACKWARD:
1844 case LFUN_CHAR_BACKWARD_SELECT:
1846 case LFUN_UP_SELECT:
1848 case LFUN_DOWN_SELECT:
1849 case LFUN_PARAGRAPH_UP_SELECT:
1850 case LFUN_PARAGRAPH_DOWN_SELECT:
1851 case LFUN_SCREEN_UP_SELECT:
1852 case LFUN_SCREEN_DOWN_SELECT:
1853 case LFUN_LINE_BEGIN_SELECT:
1854 case LFUN_LINE_END_SELECT:
1855 case LFUN_WORD_FORWARD_SELECT:
1856 case LFUN_WORD_BACKWARD_SELECT:
1857 case LFUN_WORD_SELECT:
1858 case LFUN_PARAGRAPH_UP:
1859 case LFUN_PARAGRAPH_DOWN:
1860 case LFUN_LINE_BEGIN:
1862 case LFUN_BREAK_LINE:
1863 case LFUN_CHAR_DELETE_FORWARD:
1864 case LFUN_DELETE_FORWARD_SKIP:
1865 case LFUN_CHAR_DELETE_BACKWARD:
1866 case LFUN_DELETE_BACKWARD_SKIP:
1867 case LFUN_BREAK_PARAGRAPH:
1868 case LFUN_BREAK_PARAGRAPH_SKIP:
1869 case LFUN_PARAGRAPH_SPACING:
1870 case LFUN_INSET_INSERT:
1871 case LFUN_WORD_UPCASE:
1872 case LFUN_WORD_LOWCASE:
1873 case LFUN_WORD_CAPITALIZE:
1874 case LFUN_CHARS_TRANSPOSE:
1875 case LFUN_SERVER_GET_XY:
1876 case LFUN_SERVER_SET_XY:
1877 case LFUN_SERVER_GET_FONT:
1878 case LFUN_SERVER_GET_LAYOUT:
1880 case LFUN_DATE_INSERT:
1881 case LFUN_SELF_INSERT:
1882 case LFUN_LINE_INSERT:
1883 case LFUN_PAGEBREAK_INSERT:
1884 case LFUN_CLEARPAGE_INSERT:
1885 case LFUN_CLEARDOUBLEPAGE_INSERT:
1886 case LFUN_MATH_DISPLAY:
1887 case LFUN_MATH_IMPORT_SELECTION:
1888 case LFUN_MATH_MODE:
1889 case LFUN_MATH_MACRO:
1890 case LFUN_MATH_MATRIX:
1891 case LFUN_MATH_DELIM:
1892 case LFUN_MATH_BIGDELIM:
1893 case LFUN_MATH_INSERT:
1894 case LFUN_MATH_SUBSCRIPT:
1895 case LFUN_MATH_SUPERSCRIPT:
1896 case LFUN_FONT_DEFAULT:
1897 case LFUN_FONT_UNDERLINE:
1898 case LFUN_FONT_SIZE:
1900 case LFUN_FONT_FREE_APPLY:
1901 case LFUN_FONT_FREE_UPDATE:
1902 case LFUN_LAYOUT_PARAGRAPH:
1903 case LFUN_PARAGRAPH_UPDATE:
1904 case LFUN_ACCENT_UMLAUT:
1905 case LFUN_ACCENT_CIRCUMFLEX:
1906 case LFUN_ACCENT_GRAVE:
1907 case LFUN_ACCENT_ACUTE:
1908 case LFUN_ACCENT_TILDE:
1909 case LFUN_ACCENT_CEDILLA:
1910 case LFUN_ACCENT_MACRON:
1911 case LFUN_ACCENT_DOT:
1912 case LFUN_ACCENT_UNDERDOT:
1913 case LFUN_ACCENT_UNDERBAR:
1914 case LFUN_ACCENT_CARON:
1915 case LFUN_ACCENT_SPECIAL_CARON:
1916 case LFUN_ACCENT_BREVE:
1917 case LFUN_ACCENT_TIE:
1918 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1919 case LFUN_ACCENT_CIRCLE:
1920 case LFUN_ACCENT_OGONEK:
1921 case LFUN_THESAURUS_ENTRY:
1922 case LFUN_PARAGRAPH_PARAMS_APPLY:
1923 case LFUN_PARAGRAPH_PARAMS:
1925 case LFUN_BUFFER_END:
1926 case LFUN_BUFFER_BEGIN:
1927 case LFUN_BUFFER_BEGIN_SELECT:
1928 case LFUN_BUFFER_END_SELECT:
1929 case LFUN_UNICODE_INSERT:
1930 // these are handled in our dispatch()
1938 if (code != Inset::NO_CODE
1939 && (cur.empty() || !cur.inset().insetAllowed(code)))
1942 flag.enabled(enable);
1947 void Text::pasteString(Cursor & cur, docstring const & clip,
1950 cur.clearSelection();
1951 if (!clip.empty()) {
1954 insertStringAsParagraphs(cur, clip);
1956 insertStringAsLines(cur, clip);