3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Asger Alstrup
7 * \author Lars Gullik Bjønnes
8 * \author Alfredo Braunstein
9 * \author Angus Leeming
11 * \author André Pönitz
13 * Full author contact details are available in file CREDITS.
21 #include "BranchList.h"
22 #include "FloatList.h"
23 #include "FuncStatus.h"
25 #include "buffer_funcs.h"
26 #include "BufferParams.h"
27 #include "BufferView.h"
29 #include "CutAndPaste.h"
31 #include "DispatchResult.h"
32 #include "ErrorList.h"
34 #include "FuncRequest.h"
39 #include "LyXAction.h"
43 #include "Paragraph.h"
44 #include "paragraph_funcs.h"
45 #include "ParagraphParameters.h"
48 #include "ParIterator.h"
50 #include "frontends/Clipboard.h"
51 #include "frontends/Selection.h"
53 #include "insets/InsetCommand.h"
54 #include "insets/InsetFloatList.h"
55 #include "insets/InsetNewline.h"
56 #include "insets/InsetQuotes.h"
57 #include "insets/InsetSpecialChar.h"
58 #include "insets/InsetText.h"
60 #include "support/lstrings.h"
61 #include "support/lyxlib.h"
62 #include "support/convert.h"
63 #include "support/lyxtime.h"
65 #include "mathed/InsetMathHull.h"
66 #include "mathed/MathMacroTemplate.h"
68 #include <boost/current_function.hpp>
75 using std::istringstream;
76 using std::ostringstream;
80 using cap::copySelection;
81 using cap::cutSelection;
82 using cap::pasteFromStack;
83 using cap::pasteClipboard;
84 using cap::replaceSelection;
86 using support::isStrUnsignedInt;
90 extern docstring current_layout;
94 static Font freefont(Font::ALL_IGNORE);
95 static bool toggleall = false;
97 static void toggleAndShow(Cursor & cur, Text * text,
98 Font const & font, bool toggleall = true)
100 text->toggleFree(cur, font, toggleall);
102 if (font.language() != ignore_language ||
103 font.number() != Font::IGNORE) {
104 TextMetrics const & tm = cur.bv().textMetrics(text);
105 if (cur.boundary() != tm.isRTLBoundary(cur.pit(),
106 cur.pos(), cur.real_current_font))
107 text->setCursor(cur, cur.pit(), cur.pos(),
108 false, !cur.boundary());
113 static void moveCursor(Cursor & cur, bool selecting)
115 if (selecting || cur.mark())
120 static void finishChange(Cursor & cur, bool selecting)
123 moveCursor(cur, selecting);
127 static void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
130 docstring sel = cur.selectionAsString(false);
132 // It may happen that sel is empty but there is a selection
133 replaceSelection(cur);
136 #ifdef ENABLE_ASSERTIONS
137 const int old_pos = cur.pos();
139 cur.insert(new InsetMathHull(hullSimple));
140 BOOST_ASSERT(old_pos == cur.pos());
141 cur.nextInset()->edit(cur, true);
142 // don't do that also for LFUN_MATH_MODE
143 // unless you want end up with always changing
144 // to mathrm when opening an inlined inset --
145 // I really hate "LyXfunc overloading"...
147 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
148 // Avoid an unnecessary undo step if cmd.argument
150 if (!cmd.argument().empty())
151 cur.dispatch(FuncRequest(LFUN_MATH_INSERT,
154 // create a macro if we see "\\newcommand"
155 // somewhere, and an ordinary formula
157 if (sel.find(from_ascii("\\newcommand")) == string::npos
158 && sel.find(from_ascii("\\def")) == string::npos)
160 InsetMathHull * formula = new InsetMathHull;
161 istringstream is(to_utf8(sel));
164 formula->read(cur.buffer(), lex);
165 if (formula->getType() == hullNone)
166 // Don't create pseudo formulas if
167 // delimiters are left out
168 formula->mutate(hullSimple);
171 cur.insert(new MathMacroTemplate(sel));
174 cur.message(from_utf8(N_("Math editor mode")));
178 static void specialChar(Cursor & cur, InsetSpecialChar::Kind kind)
181 cap::replaceSelection(cur);
182 cur.insert(new InsetSpecialChar(kind));
187 static bool doInsertInset(Cursor & cur, Text * text,
188 FuncRequest const & cmd, bool edit, bool pastesel)
190 Inset * inset = createInset(&cur.bv(), cmd);
196 if (cur.selection()) {
197 lyx::dispatch(FuncRequest(LFUN_CUT));
200 text->insertInset(cur, inset);
203 inset->edit(cur, true);
205 if (gotsel && pastesel) {
206 lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
207 // reset first par to default
208 if (cur.lastpit() != 0 || cur.lastpos() != 0) {
209 LayoutPtr const layout =
210 cur.buffer().params().getTextClass().defaultLayout();
211 cur.text()->paragraphs().begin()->layout(layout);
218 string const freefont2string()
220 return freefont.toString(toggleall);
224 void Text::number(Cursor & cur)
226 Font font(Font::ALL_IGNORE);
227 font.setNumber(Font::TOGGLE);
228 toggleAndShow(cur, this, font);
232 bool Text::isRTL(Buffer const & buffer, Paragraph const & par) const
234 return par.isRTL(buffer.params());
238 void Text::dispatch(Cursor & cur, FuncRequest & cmd)
240 LYXERR(Debug::ACTION) << "Text::dispatch: cmd: " << cmd << endl;
242 // FIXME: We use the update flag to indicates wether a singlePar or a
243 // full screen update is needed. We reset it here but shall we restore it
247 BOOST_ASSERT(cur.text() == this);
248 BufferView * bv = &cur.bv();
249 TextMetrics & tm = cur.bv().textMetrics(this);
250 CursorSlice oldTopSlice = cur.top();
251 bool oldBoundary = cur.boundary();
252 bool sel = cur.selection();
253 // Signals that, even if needsUpdate == false, an update of the
254 // cursor paragraph is required
255 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
256 LyXAction::SingleParUpdate);
257 // Signals that a full-screen update is required
258 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
259 LyXAction::NoUpdate) || singleParUpdate);
260 // Remember the old paragraph metric (_outer_ paragraph!)
261 ParagraphMetrics const & pm = cur.bv().parMetrics(
262 cur.bottom().text(), cur.bottom().pit());
263 Dimension olddim = pm.dim();
265 switch (cmd.action) {
267 case LFUN_PARAGRAPH_MOVE_DOWN: {
268 pit_type const pit = cur.pit();
269 recUndo(cur, pit, pit + 1);
271 std::swap(pars_[pit], pars_[pit + 1]);
272 updateLabels(cur.buffer());
278 case LFUN_PARAGRAPH_MOVE_UP: {
279 pit_type const pit = cur.pit();
280 recUndo(cur, pit - 1, pit);
282 std::swap(pars_[pit], pars_[pit - 1]);
283 updateLabels(cur.buffer());
289 case LFUN_APPENDIX: {
290 Paragraph & par = cur.paragraph();
291 bool start = !par.params().startOfAppendix();
293 // FIXME: The code below only makes sense at top level.
294 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
295 // ensure that we have only one start_of_appendix in this document
296 // FIXME: this don't work for multipart document!
297 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
298 if (pars_[tmp].params().startOfAppendix()) {
300 pars_[tmp].params().startOfAppendix(false);
306 par.params().startOfAppendix(start);
308 // we can set the refreshing parameters now
309 updateLabels(cur.buffer());
313 case LFUN_WORD_DELETE_FORWARD:
314 if (cur.selection()) {
315 cutSelection(cur, true, false);
317 deleteWordForward(cur);
318 finishChange(cur, false);
321 case LFUN_WORD_DELETE_BACKWARD:
322 if (cur.selection()) {
323 cutSelection(cur, true, false);
325 deleteWordBackward(cur);
326 finishChange(cur, false);
329 case LFUN_LINE_DELETE:
330 if (cur.selection()) {
331 cutSelection(cur, true, false);
333 tm.deleteLineForward(cur);
334 finishChange(cur, false);
337 case LFUN_BUFFER_BEGIN:
338 case LFUN_BUFFER_BEGIN_SELECT:
339 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
340 if (cur.depth() == 1) {
341 needsUpdate |= cursorTop(cur);
347 case LFUN_BUFFER_END:
348 case LFUN_BUFFER_END_SELECT:
349 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
350 if (cur.depth() == 1) {
351 needsUpdate |= cursorBottom(cur);
357 case LFUN_CHAR_FORWARD:
358 case LFUN_CHAR_FORWARD_SELECT:
359 //lyxerr << BOOST_CURRENT_FUNCTION
360 // << " LFUN_CHAR_FORWARD[SEL]:\n" << cur << endl;
361 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
362 if (reverseDirectionNeeded(cur))
363 needsUpdate |= cursorLeft(cur);
365 needsUpdate |= cursorRight(cur);
367 if (!needsUpdate && oldTopSlice == cur.top()
368 && cur.boundary() == oldBoundary) {
370 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
374 case LFUN_CHAR_BACKWARD:
375 case LFUN_CHAR_BACKWARD_SELECT:
376 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
377 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
378 if (reverseDirectionNeeded(cur))
379 needsUpdate |= cursorRight(cur);
381 needsUpdate |= cursorLeft(cur);
383 if (!needsUpdate && oldTopSlice == cur.top()
384 && cur.boundary() == oldBoundary) {
386 cmd = FuncRequest(LFUN_FINISHED_LEFT);
391 case LFUN_DOWN_SELECT:
394 // stop/start the selection
395 bool select = cmd.action == LFUN_DOWN_SELECT ||
396 cmd.action == LFUN_UP_SELECT;
397 cur.selHandle(select);
399 // move cursor up/down
400 bool up = cmd.action == LFUN_UP_SELECT || cmd.action == LFUN_UP;
401 bool const successful = cur.upDownInText(up, needsUpdate);
403 // notify insets which were left and get their update flags
404 notifyCursorLeaves(cur.beforeDispatchCursor(), cur);
407 // redraw if you leave mathed (for the decorations)
408 needsUpdate |= cur.beforeDispatchCursor().inMathed();
415 case LFUN_PARAGRAPH_UP:
416 case LFUN_PARAGRAPH_UP_SELECT:
417 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
418 needsUpdate |= cursorUpParagraph(cur);
421 case LFUN_PARAGRAPH_DOWN:
422 case LFUN_PARAGRAPH_DOWN_SELECT:
423 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
424 needsUpdate |= cursorDownParagraph(cur);
427 case LFUN_SCREEN_UP_SELECT:
428 needsUpdate |= cur.selHandle(true);
429 if (cur.pit() == 0 && cur.textRow().pos() == 0)
432 tm.cursorPrevious(cur);
436 case LFUN_SCREEN_DOWN_SELECT:
437 needsUpdate |= cur.selHandle(true);
438 if (cur.pit() == cur.lastpit()
439 && cur.textRow().endpos() == cur.lastpos())
446 case LFUN_LINE_BEGIN:
447 case LFUN_LINE_BEGIN_SELECT:
448 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
449 needsUpdate |= tm.cursorHome(cur);
453 case LFUN_LINE_END_SELECT:
454 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
455 needsUpdate |= tm.cursorEnd(cur);
458 case LFUN_WORD_FORWARD:
459 case LFUN_WORD_FORWARD_SELECT:
460 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
461 if (reverseDirectionNeeded(cur))
462 needsUpdate |= cursorLeftOneWord(cur);
464 needsUpdate |= cursorRightOneWord(cur);
467 case LFUN_WORD_BACKWARD:
468 case LFUN_WORD_BACKWARD_SELECT:
469 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
470 if (reverseDirectionNeeded(cur))
471 needsUpdate |= cursorRightOneWord(cur);
473 needsUpdate |= cursorLeftOneWord(cur);
476 case LFUN_WORD_SELECT: {
477 selectWord(cur, WHOLE_WORD);
478 finishChange(cur, true);
482 case LFUN_BREAK_LINE: {
483 // Not allowed by LaTeX (labels or empty par)
484 if (cur.pos() > cur.paragraph().beginOfBody()) {
485 // this avoids a double undo
486 // FIXME: should not be needed, ideally
487 if (!cur.selection())
489 cap::replaceSelection(cur);
490 cur.insert(new InsetNewline);
492 moveCursor(cur, false);
497 case LFUN_CHAR_DELETE_FORWARD:
498 if (!cur.selection()) {
499 if (cur.pos() == cur.paragraph().size())
500 // Par boundary, force full-screen update
501 singleParUpdate = false;
502 needsUpdate |= erase(cur);
504 // It is possible to make it a lot faster still
505 // just comment out the line below...
507 cutSelection(cur, true, false);
508 singleParUpdate = false;
510 moveCursor(cur, false);
513 case LFUN_DELETE_FORWARD_SKIP:
514 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
515 if (!cur.selection()) {
516 if (cur.pos() == cur.lastpos()) {
523 cutSelection(cur, true, false);
528 case LFUN_CHAR_DELETE_BACKWARD:
529 if (!cur.selection()) {
530 if (bv->getIntl().getTransManager().backspace()) {
531 // Par boundary, full-screen update
533 singleParUpdate = false;
534 needsUpdate |= backspace(cur);
536 // It is possible to make it a lot faster still
537 // just comment out the line below...
540 cutSelection(cur, true, false);
541 singleParUpdate = false;
545 case LFUN_DELETE_BACKWARD_SKIP:
546 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
547 if (!cur.selection()) {
549 //CursorSlice cur = cursor();
553 cutSelection(cur, true, false);
557 case LFUN_BREAK_PARAGRAPH:
558 cap::replaceSelection(cur);
559 breakParagraph(cur, false);
563 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
564 cap::replaceSelection(cur);
565 breakParagraph(cur, true);
569 case LFUN_BREAK_PARAGRAPH_SKIP: {
570 // When at the beginning of a paragraph, remove
571 // indentation. Otherwise, do the same as LFUN_BREAK_PARAGRAPH.
572 cap::replaceSelection(cur);
574 cur.paragraph().params().labelWidthString(docstring());
576 breakParagraph(cur, false);
582 // With the creation of LFUN_PARAGRAPH_PARAMS, this is now redundant,
583 // as its duties can be performed there. Should it be removed??
584 // FIXME For now, it can just dispatch LFUN_PARAGRAPH_PARAMS...
585 case LFUN_PARAGRAPH_SPACING: {
586 Paragraph & par = cur.paragraph();
587 Spacing::Space cur_spacing = par.params().spacing().getSpace();
588 string cur_value = "1.0";
589 if (cur_spacing == Spacing::Other)
590 cur_value = par.params().spacing().getValueAsString();
592 istringstream is(to_utf8(cmd.argument()));
595 Spacing::Space new_spacing = cur_spacing;
596 string new_value = cur_value;
598 lyxerr << "Missing argument to `paragraph-spacing'"
600 } else if (tmp == "single") {
601 new_spacing = Spacing::Single;
602 } else if (tmp == "onehalf") {
603 new_spacing = Spacing::Onehalf;
604 } else if (tmp == "double") {
605 new_spacing = Spacing::Double;
606 } else if (tmp == "other") {
607 new_spacing = Spacing::Other;
608 string tmpval = "0.0";
610 lyxerr << "new_value = " << tmpval << endl;
613 } else if (tmp == "default") {
614 new_spacing = Spacing::Default;
616 lyxerr << to_utf8(_("Unknown spacing argument: "))
617 << to_utf8(cmd.argument()) << endl;
619 if (cur_spacing != new_spacing || cur_value != new_value)
620 par.params().spacing(Spacing(new_spacing, new_value));
624 case LFUN_INSET_INSERT: {
626 Inset * inset = createInset(bv, cmd);
628 // FIXME (Abdel 01/02/2006):
629 // What follows would be a partial fix for bug 2154:
630 // http://bugzilla.lyx.org/show_bug.cgi?id=2154
631 // This automatically put the label inset _after_ a
632 // numbered section. It should be possible to extend the mechanism
633 // to any kind of LateX environement.
634 // The correct way to fix that bug would be at LateX generation.
635 // I'll let the code here for reference as it could be used for some
636 // other feature like "automatic labelling".
638 Paragraph & par = pars_[cur.pit()];
639 if (inset->lyxCode() == Inset::LABEL_CODE
640 && par.layout()->labeltype == LABEL_COUNTER) {
641 // Go to the end of the paragraph
642 // Warning: Because of Change-Tracking, the last
643 // position is 'size()' and not 'size()-1':
644 cur.pos() = par.size();
645 // Insert a new paragraph
646 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
651 cutSelection(cur, true, false);
652 insertInset(cur, inset);
658 case LFUN_INSET_DISSOLVE:
659 needsUpdate |= dissolveInset(cur);
662 case LFUN_INSET_SETTINGS:
663 cur.inset().showInsetDialog(bv);
666 case LFUN_SPACE_INSERT:
667 if (cur.paragraph().layout()->free_spacing)
668 insertChar(cur, ' ');
670 doInsertInset(cur, this, cmd, false, false);
673 moveCursor(cur, false);
676 case LFUN_HYPHENATION_POINT_INSERT:
677 specialChar(cur, InsetSpecialChar::HYPHENATION);
680 case LFUN_LIGATURE_BREAK_INSERT:
681 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
684 case LFUN_DOTS_INSERT:
685 specialChar(cur, InsetSpecialChar::LDOTS);
688 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
689 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
692 case LFUN_MENU_SEPARATOR_INSERT:
693 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
696 case LFUN_WORD_UPCASE:
697 changeCase(cur, Text::text_uppercase);
700 case LFUN_WORD_LOWCASE:
701 changeCase(cur, Text::text_lowercase);
704 case LFUN_WORD_CAPITALIZE:
705 changeCase(cur, Text::text_capitalization);
708 case LFUN_CHARS_TRANSPOSE:
713 cur.message(_("Paste"));
714 cap::replaceSelection(cur);
715 if (cmd.argument().empty() && !theClipboard().isInternal())
716 pasteClipboard(cur, bv->buffer().errorList("Paste"));
718 string const arg(to_utf8(cmd.argument()));
719 pasteFromStack(cur, bv->buffer().errorList("Paste"),
720 isStrUnsignedInt(arg) ?
721 convert<unsigned int>(arg) :
724 bv->buffer().errors("Paste");
725 cur.clearSelection(); // bug 393
730 cutSelection(cur, true, true);
731 cur.message(_("Cut"));
736 cur.message(_("Copy"));
739 case LFUN_SERVER_GET_XY:
740 cur.message(from_utf8(
741 convert<string>(tm.cursorX(cur.top(), cur.boundary()))
742 + ' ' + convert<string>(tm.cursorY(cur.top(), cur.boundary()))));
745 case LFUN_SERVER_SET_XY: {
748 istringstream is(to_utf8(cmd.argument()));
751 lyxerr << "SETXY: Could not parse coordinates in '"
752 << to_utf8(cmd.argument()) << std::endl;
754 tm.setCursorFromCoordinates(cur, x, y);
758 case LFUN_SERVER_GET_FONT:
759 if (cur.current_font.shape() == Font::ITALIC_SHAPE)
760 cur.message(from_ascii("E"));
761 else if (cur.current_font.shape() == Font::SMALLCAPS_SHAPE)
762 cur.message(from_ascii("N"));
764 cur.message(from_ascii("0"));
767 case LFUN_SERVER_GET_LAYOUT:
768 cur.message(cur.paragraph().layout()->name());
772 docstring layout = cmd.argument();
773 LYXERR(Debug::INFO) << "LFUN_LAYOUT: (arg) " << to_utf8(layout) << endl;
775 // Derive layout number from given argument (string)
776 // and current buffer's textclass (number)
777 TextClass const & tclass = bv->buffer().params().getTextClass();
779 layout = tclass.defaultLayoutName();
780 bool hasLayout = tclass.hasLayout(layout);
782 // If the entry is obsolete, use the new one instead.
784 docstring const & obs = tclass[layout]->obsoleted_by();
790 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
791 from_utf8(N_(" not known")));
795 bool change_layout = (frontend::current_layout != layout);
797 if (!change_layout && cur.selection() &&
798 cur.selBegin().pit() != cur.selEnd().pit())
800 pit_type spit = cur.selBegin().pit();
801 pit_type epit = cur.selEnd().pit() + 1;
802 while (spit != epit) {
803 if (pars_[spit].layout()->name() != frontend::current_layout) {
804 change_layout = true;
812 setLayout(cur, layout);
813 // inform the GUI that the layout has changed.
814 bv->layoutChanged(layout);
819 case LFUN_CLIPBOARD_PASTE:
820 cur.clearSelection();
821 pasteClipboard(cur, bv->buffer().errorList("Paste"),
822 cmd.argument() == "paragraph");
823 bv->buffer().errors("Paste");
826 case LFUN_PRIMARY_SELECTION_PASTE:
827 pasteString(cur, theSelection().get(),
828 cmd.argument() == "paragraph");
831 case LFUN_UNICODE_INSERT: {
832 if (cmd.argument().empty())
834 docstring hexstring = cmd.argument();
835 if (lyx::support::isHex(hexstring)) {
836 char_type c = lyx::support::hexToInt(hexstring);
837 if (c >= 32 && c < 0x10ffff) {
838 lyxerr << "Inserting c: " << c << endl;
839 docstring s = docstring(1, c);
840 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
846 case LFUN_QUOTE_INSERT: {
847 Paragraph & par = cur.paragraph();
848 pos_type pos = cur.pos();
849 BufferParams const & bufparams = bv->buffer().params();
850 LayoutPtr const & style = par.layout();
851 if (!style->pass_thru
852 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
853 // this avoids a double undo
854 // FIXME: should not be needed, ideally
855 if (!cur.selection())
857 cap::replaceSelection(cur);
862 else if (cur.prevInset() && cur.prevInset()->isSpace())
865 c = par.getChar(pos - 1);
866 string arg = to_utf8(cmd.argument());
868 cur.insert(new InsetQuotes(c,
869 bufparams.quotes_language,
870 InsetQuotes::SingleQ));
872 cur.insert(new InsetQuotes(c,
873 bufparams.quotes_language,
874 InsetQuotes::DoubleQ));
878 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
882 case LFUN_DATE_INSERT: {
883 string const format = cmd.argument().empty()
884 ? lyxrc.date_insert_format : to_utf8(cmd.argument());
885 string const time = formatted_time(current_time(), format);
886 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, time));
890 case LFUN_MOUSE_TRIPLE:
891 if (cmd.button() == mouse_button::button1) {
900 case LFUN_MOUSE_DOUBLE:
901 if (cmd.button() == mouse_button::button1) {
902 selectWord(cur, WHOLE_WORD_STRICT);
907 // Single-click on work area
908 case LFUN_MOUSE_PRESS: {
909 // Right click on a footnote flag opens float menu
910 if (cmd.button() == mouse_button::button3)
911 cur.clearSelection();
914 bool update = bv->mouseSetCursor(cur);
916 // Insert primary selection with middle mouse
917 // if there is a local selection in the current buffer,
919 if (cmd.button() == mouse_button::button2) {
920 if (cap::selection()) {
921 // Copy the selection buffer to the clipboard
922 // stack, because we want it to appear in the
923 // "Edit->Paste recent" menu.
924 cap::copySelectionToStack();
926 cap::pasteSelection(bv->cursor(),
927 bv->buffer().errorList("Paste"));
928 bv->buffer().errors("Paste");
929 bv->buffer().markDirty();
932 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
936 // we have to update after dEPM triggered
937 if (!update && cmd.button() == mouse_button::button1) {
945 case LFUN_MOUSE_MOTION: {
946 // Only use motion with button 1
947 //if (cmd.button() != mouse_button::button1)
950 // ignore motions deeper nested than the real anchor
951 Cursor & bvcur = cur.bv().cursor();
952 if (bvcur.anchor_.hasPart(cur)) {
953 CursorSlice old = bvcur.top();
955 int const wh = bv->workHeight();
956 int const y = std::max(0, std::min(wh - 1, cmd.y));
958 tm.setCursorFromCoordinates(cur, cmd.x, y);
959 cur.setTargetX(cmd.x);
961 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
963 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
964 // This is to allow jumping over large insets
965 if (cur.top() == old) {
967 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
969 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
972 if (cur.top() == old)
976 bvcur.setCursor(cur);
977 bvcur.selection() = true;
978 //lyxerr << "MOTION: " << bv->cursor() << endl;
986 case LFUN_MOUSE_RELEASE: {
987 if (cmd.button() == mouse_button::button2)
990 if (cmd.button() == mouse_button::button1) {
991 // if there is new selection, update persistent
992 // selection, otherwise, single click does not
993 // clear persistent selection buffer
994 if (cur.selection()) {
996 // if double click, cur is moved to the end of word by selectWord
997 // but bvcur is current mouse position
998 Cursor & bvcur = cur.bv().cursor();
999 bvcur.selection() = true;
1001 needsUpdate = false;
1008 case LFUN_SELF_INSERT: {
1009 if (cmd.argument().empty())
1012 // Automatically delete the currently selected
1013 // text and replace it with what is being
1014 // typed in now. Depends on lyxrc settings
1015 // "auto_region_delete", which defaults to
1018 if (lyxrc.auto_region_delete && cur.selection()) {
1019 cutSelection(cur, false, false);
1020 // When change tracking is set to off, the metrics update
1021 // mechanism correctly detects if a full update is needed or not.
1022 // This detection fails when a selection spans multiple rows and
1023 // change tracking is enabled because the paragraph metrics stays
1024 // the same. In this case, we force the full update:
1025 // (see http://bugzilla.lyx.org/show_bug.cgi?id=3992)
1026 if (cur.buffer().params().trackChanges)
1027 cur.updateFlags(Update::Force);
1030 cur.clearSelection();
1031 Font const old_font = cur.real_current_font;
1033 docstring::const_iterator cit = cmd.argument().begin();
1034 docstring::const_iterator end = cmd.argument().end();
1035 for (; cit != end; ++cit)
1036 bv->translateAndInsert(*cit, this, cur);
1039 moveCursor(cur, false);
1043 case LFUN_URL_INSERT: {
1044 InsetCommandParams p("url");
1046 if (cur.selection()) {
1047 content = cur.selectionAsString(false);
1048 cutSelection(cur, true, false);
1050 p["target"] = (cmd.argument().empty()) ?
1051 content : cmd.argument();
1052 string const data = InsetCommandMailer::params2string("url", p);
1053 if (p["target"].empty()) {
1054 bv->showInsetDialog("url", data, 0);
1056 FuncRequest fr(LFUN_INSET_INSERT, data);
1062 case LFUN_HTML_INSERT: {
1063 InsetCommandParams p("htmlurl");
1065 if (cur.selection()) {
1066 content = cur.selectionAsString(false);
1067 cutSelection(cur, true, false);
1069 p["target"] = (cmd.argument().empty()) ?
1070 content : cmd.argument();
1071 string const data = InsetCommandMailer::params2string("url", p);
1072 if (p["target"].empty()) {
1073 bv->showInsetDialog("url", data, 0);
1075 FuncRequest fr(LFUN_INSET_INSERT, data);
1081 case LFUN_LABEL_INSERT: {
1082 InsetCommandParams p("label");
1083 // Try to generate a valid label
1084 p["name"] = (cmd.argument().empty()) ?
1085 cur.getPossibleLabel() :
1087 string const data = InsetCommandMailer::params2string("label", p);
1089 if (cmd.argument().empty()) {
1090 bv->showInsetDialog("label", data, 0);
1092 FuncRequest fr(LFUN_INSET_INSERT, data);
1100 case LFUN_LIST_INSERT:
1101 case LFUN_THEOREM_INSERT:
1103 case LFUN_CAPTION_INSERT:
1104 // Open the inset, and move the current selection
1106 doInsertInset(cur, this, cmd, true, true);
1108 updateLabels(bv->buffer());
1110 case LFUN_NOTE_INSERT:
1111 case LFUN_FLEX_INSERT:
1112 case LFUN_BOX_INSERT:
1113 case LFUN_BRANCH_INSERT:
1114 case LFUN_BIBITEM_INSERT:
1115 case LFUN_ERT_INSERT:
1116 case LFUN_LISTING_INSERT:
1117 case LFUN_FOOTNOTE_INSERT:
1118 case LFUN_MARGINALNOTE_INSERT:
1119 case LFUN_OPTIONAL_INSERT:
1120 case LFUN_ENVIRONMENT_INSERT:
1121 // Open the inset, and move the current selection
1123 doInsertInset(cur, this, cmd, true, true);
1127 case LFUN_TABULAR_INSERT:
1128 // if there were no arguments, just open the dialog
1129 if (doInsertInset(cur, this, cmd, false, true))
1132 bv->showDialog("tabularcreate");
1136 case LFUN_FLOAT_INSERT:
1137 case LFUN_FLOAT_WIDE_INSERT:
1138 case LFUN_WRAP_INSERT: {
1139 bool content = cur.selection(); // will some text be moved into the inset?
1141 doInsertInset(cur, this, cmd, true, true);
1143 ParagraphList & pars = cur.text()->paragraphs();
1145 TextClass const & tclass = bv->buffer().params().getTextClass();
1147 // add a separate paragraph for the caption inset
1148 pars.push_back(Paragraph());
1149 pars.back().setInsetOwner(pars[0].inInset());
1150 pars.back().layout(tclass.defaultLayout());
1152 int cap_pit = pars.size() - 1;
1154 // if an empty inset was created, we create an additional empty
1155 // paragraph at the bottom so that the user can choose where to put
1156 // the graphics (or table).
1158 pars.push_back(Paragraph());
1159 pars.back().setInsetOwner(pars[0].inInset());
1160 pars.back().layout(tclass.defaultLayout());
1164 // reposition the cursor to the caption
1165 cur.pit() = cap_pit;
1167 // FIXME: This Text/Cursor dispatch handling is a mess!
1168 // We cannot use Cursor::dispatch here it needs access to up to
1170 FuncRequest cmd_caption(LFUN_CAPTION_INSERT);
1171 cur.text()->dispatch(cur, cmd_caption);
1172 cur.updateFlags(Update::Force);
1173 // FIXME: When leaving the Float (or Wrap) inset we should
1174 // delete any empty paragraph left above or below the
1179 case LFUN_INDEX_INSERT:
1180 case LFUN_NOMENCL_INSERT: {
1181 Inset * inset = createInset(&cur.bv(), cmd);
1185 cur.clearSelection();
1186 insertInset(cur, inset);
1187 // Show the dialog for the nomenclature entry, since the
1188 // description entry still needs to be filled in.
1189 if (cmd.action == LFUN_NOMENCL_INSERT)
1190 inset->edit(cur, true);
1195 case LFUN_INDEX_PRINT:
1196 case LFUN_NOMENCL_PRINT:
1197 case LFUN_TOC_INSERT:
1198 case LFUN_HFILL_INSERT:
1199 case LFUN_LINE_INSERT:
1200 case LFUN_PAGEBREAK_INSERT:
1201 case LFUN_CLEARPAGE_INSERT:
1202 case LFUN_CLEARDOUBLEPAGE_INSERT:
1204 doInsertInset(cur, this, cmd, false, false);
1208 case LFUN_DEPTH_DECREMENT:
1209 changeDepth(cur, DEC_DEPTH);
1212 case LFUN_DEPTH_INCREMENT:
1213 changeDepth(cur, INC_DEPTH);
1216 case LFUN_MATH_DISPLAY:
1217 mathDispatch(cur, cmd, true);
1220 case LFUN_MATH_IMPORT_SELECTION:
1221 case LFUN_MATH_MODE:
1222 if (cmd.argument() == "on")
1223 // don't pass "on" as argument
1224 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1226 mathDispatch(cur, cmd, false);
1229 case LFUN_MATH_MACRO:
1230 if (cmd.argument().empty())
1231 cur.errorMessage(from_utf8(N_("Missing argument")));
1233 string s = to_utf8(cmd.argument());
1234 string const s1 = token(s, ' ', 1);
1235 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1236 string const s2 = token(s, ' ', 2);
1237 string const type = s2.empty() ? "newcommand" : s2;
1238 cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, from_utf8(type)));
1239 //cur.nextInset()->edit(cur, true);
1243 // passthrough hat and underscore outside mathed:
1244 case LFUN_MATH_SUBSCRIPT:
1245 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1247 case LFUN_MATH_SUPERSCRIPT:
1248 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1251 case LFUN_MATH_INSERT:
1252 case LFUN_MATH_MATRIX:
1253 case LFUN_MATH_DELIM:
1254 case LFUN_MATH_BIGDELIM: {
1255 if (cur.selection())
1256 cur.clearSelection();
1257 // FIXME: instead of the above, this one
1258 // should be used (but it asserts with Bidi enabled)
1259 // cf. http://bugzilla.lyx.org/show_bug.cgi?id=4055
1260 // cap::replaceSelection(cur);
1261 cur.insert(new InsetMathHull(hullSimple));
1262 checkAndActivateInset(cur, true);
1263 BOOST_ASSERT(cur.inMathed());
1268 case LFUN_FONT_EMPH: {
1269 Font font(Font::ALL_IGNORE);
1270 font.setEmph(Font::TOGGLE);
1271 toggleAndShow(cur, this, font);
1275 case LFUN_FONT_BOLD: {
1276 Font font(Font::ALL_IGNORE);
1277 font.setSeries(Font::BOLD_SERIES);
1278 toggleAndShow(cur, this, font);
1282 case LFUN_FONT_NOUN: {
1283 Font font(Font::ALL_IGNORE);
1284 font.setNoun(Font::TOGGLE);
1285 toggleAndShow(cur, this, font);
1289 case LFUN_FONT_TYPEWRITER: {
1290 Font font(Font::ALL_IGNORE);
1291 font.setFamily(Font::TYPEWRITER_FAMILY); // no good
1292 toggleAndShow(cur, this, font);
1296 case LFUN_FONT_SANS: {
1297 Font font(Font::ALL_IGNORE);
1298 font.setFamily(Font::SANS_FAMILY);
1299 toggleAndShow(cur, this, font);
1303 case LFUN_FONT_ROMAN: {
1304 Font font(Font::ALL_IGNORE);
1305 font.setFamily(Font::ROMAN_FAMILY);
1306 toggleAndShow(cur, this, font);
1310 case LFUN_FONT_DEFAULT: {
1311 Font font(Font::ALL_INHERIT, ignore_language);
1312 toggleAndShow(cur, this, font);
1316 case LFUN_FONT_UNDERLINE: {
1317 Font font(Font::ALL_IGNORE);
1318 font.setUnderbar(Font::TOGGLE);
1319 toggleAndShow(cur, this, font);
1323 case LFUN_FONT_SIZE: {
1324 Font font(Font::ALL_IGNORE);
1325 font.setLyXSize(to_utf8(cmd.argument()));
1326 toggleAndShow(cur, this, font);
1330 case LFUN_LANGUAGE: {
1331 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1334 Font font(Font::ALL_IGNORE);
1335 font.setLanguage(lang);
1336 toggleAndShow(cur, this, font);
1340 case LFUN_FONT_FREE_APPLY:
1341 toggleAndShow(cur, this, freefont, toggleall);
1342 cur.message(_("Character set"));
1345 // Set the freefont using the contents of \param data dispatched from
1346 // the frontends and apply it at the current cursor location.
1347 case LFUN_FONT_FREE_UPDATE: {
1350 if (font.fromString(to_utf8(cmd.argument()), toggle)) {
1353 toggleAndShow(cur, this, freefont, toggleall);
1354 cur.message(_("Character set"));
1359 case LFUN_FINISHED_LEFT:
1360 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1361 if (reverseDirectionNeeded(cur)) {
1363 cur.setCurrentFont();
1367 case LFUN_FINISHED_RIGHT:
1368 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1369 if (!reverseDirectionNeeded(cur)) {
1371 cur.setCurrentFont();
1375 case LFUN_LAYOUT_PARAGRAPH: {
1377 params2string(cur.paragraph(), data);
1378 data = "show\n" + data;
1379 bv->showDialogWithData("paragraph", data);
1383 case LFUN_PARAGRAPH_UPDATE: {
1385 params2string(cur.paragraph(), data);
1387 // Will the paragraph accept changes from the dialog?
1388 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1390 data = "update " + convert<string>(accept) + '\n' + data;
1391 bv->updateDialog("paragraph", data);
1395 case LFUN_ACCENT_UMLAUT:
1396 case LFUN_ACCENT_CIRCUMFLEX:
1397 case LFUN_ACCENT_GRAVE:
1398 case LFUN_ACCENT_ACUTE:
1399 case LFUN_ACCENT_TILDE:
1400 case LFUN_ACCENT_CEDILLA:
1401 case LFUN_ACCENT_MACRON:
1402 case LFUN_ACCENT_DOT:
1403 case LFUN_ACCENT_UNDERDOT:
1404 case LFUN_ACCENT_UNDERBAR:
1405 case LFUN_ACCENT_CARON:
1406 case LFUN_ACCENT_SPECIAL_CARON:
1407 case LFUN_ACCENT_BREVE:
1408 case LFUN_ACCENT_TIE:
1409 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1410 case LFUN_ACCENT_CIRCLE:
1411 case LFUN_ACCENT_OGONEK:
1412 theLyXFunc().handleKeyFunc(cmd.action);
1413 if (!cmd.argument().empty())
1414 // FIXME: Are all these characters encoded in one byte in utf8?
1415 bv->translateAndInsert(cmd.argument()[0], this, cur);
1418 case LFUN_FLOAT_LIST: {
1419 TextClass const & tclass = bv->buffer().params().getTextClass();
1420 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1422 if (cur.selection())
1423 cutSelection(cur, true, false);
1424 breakParagraph(cur);
1426 if (cur.lastpos() != 0) {
1428 breakParagraph(cur);
1431 setLayout(cur, tclass.defaultLayoutName());
1432 ParagraphParameters p;
1433 setParagraphs(cur, p);
1434 insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1437 lyxerr << "Non-existent float type: "
1438 << to_utf8(cmd.argument()) << endl;
1443 case LFUN_CHANGE_ACCEPT: {
1444 acceptOrRejectChanges(cur, ACCEPT);
1448 case LFUN_CHANGE_REJECT: {
1449 acceptOrRejectChanges(cur, REJECT);
1453 case LFUN_THESAURUS_ENTRY: {
1454 docstring arg = cmd.argument();
1456 arg = cur.selectionAsString(false);
1458 if (arg.size() > 100 || arg.empty()) {
1459 // Get word or selection
1460 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1461 arg = cur.selectionAsString(false);
1464 bv->showDialogWithData("thesaurus", to_utf8(arg));
1468 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1469 // Given data, an encoding of the ParagraphParameters
1470 // generated in the Paragraph dialog, this function sets
1471 // the current paragraph, or currently selected paragraphs,
1473 // NOTE: This function overrides all existing settings.
1474 setParagraphs(cur, cmd.argument());
1475 cur.message(_("Paragraph layout set"));
1479 case LFUN_PARAGRAPH_PARAMS: {
1480 // Given data, an encoding of the ParagraphParameters as we'd
1481 // find them in a LyX file, this function modifies the current paragraph,
1482 // or currently selected paragraphs.
1483 // NOTE: This function only modifies, and does not override, existing
1485 setParagraphs(cur, cmd.argument(), true);
1486 cur.message(_("Paragraph layout set"));
1491 if (cur.selection()) {
1492 cur.selection() = false;
1495 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1500 LYXERR(Debug::ACTION)
1501 << BOOST_CURRENT_FUNCTION
1502 << ": Command " << cmd
1503 << " not DISPATCHED by Text" << endl;
1508 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1510 // FIXME: The cursor flag is reset two lines below
1511 // so we need to check here if some of the LFUN did touch that.
1512 // for now only Text::erase() and Text::backspace() do that.
1513 // The plan is to verify all the LFUNs and then to remove this
1514 // singleParUpdate boolean altogether.
1515 if (cur.result().update() & Update::Force) {
1516 singleParUpdate = false;
1520 // FIXME: the following code should go in favor of fine grained
1521 // update flag treatment.
1522 if (singleParUpdate) {
1523 // Inserting characters does not change par height
1524 ParagraphMetrics const & pms
1525 = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
1526 if (pms.dim().height()
1527 == olddim.height()) {
1528 // if so, update _only_ this paragraph
1529 cur.updateFlags(Update::SinglePar |
1531 Update::MultiParSel);
1538 && &oldTopSlice.inset() == &cur.inset()
1539 && oldTopSlice.idx() == cur.idx()
1540 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1541 && !cur.selection())
1542 // FIXME: it would be better if we could just do this
1544 //if (cur.result().update() != Update::FitCursor)
1547 // But some LFUNs do not set Update::FitCursor when needed, so we
1548 // do it for all. This is not very harmfull as FitCursor will provoke
1549 // a full redraw only if needed but still, a proper review of all LFUN
1550 // should be done and this needsUpdate boolean can then be removed.
1551 cur.updateFlags(Update::FitCursor);
1553 cur.updateFlags(Update::Force | Update::FitCursor);
1557 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
1558 FuncStatus & flag) const
1560 BOOST_ASSERT(cur.text() == this);
1562 Font const & font = cur.real_current_font;
1564 Inset::Code code = Inset::NO_CODE;
1566 switch (cmd.action) {
1568 case LFUN_DEPTH_DECREMENT:
1569 enable = changeDepthAllowed(cur, DEC_DEPTH);
1572 case LFUN_DEPTH_INCREMENT:
1573 enable = changeDepthAllowed(cur, INC_DEPTH);
1577 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1580 case LFUN_BIBITEM_INSERT:
1581 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO
1585 case LFUN_DIALOG_SHOW_NEW_INSET:
1586 if (cmd.argument() == "bibitem")
1587 code = Inset::BIBITEM_CODE;
1588 else if (cmd.argument() == "bibtex")
1589 code = Inset::BIBTEX_CODE;
1590 else if (cmd.argument() == "box")
1591 code = Inset::BOX_CODE;
1592 else if (cmd.argument() == "branch")
1593 code = Inset::BRANCH_CODE;
1594 else if (cmd.argument() == "citation")
1595 code = Inset::CITE_CODE;
1596 else if (cmd.argument() == "ert")
1597 code = Inset::ERT_CODE;
1598 else if (cmd.argument() == "external")
1599 code = Inset::EXTERNAL_CODE;
1600 else if (cmd.argument() == "float")
1601 code = Inset::FLOAT_CODE;
1602 else if (cmd.argument() == "graphics")
1603 code = Inset::GRAPHICS_CODE;
1604 else if (cmd.argument() == "include")
1605 code = Inset::INCLUDE_CODE;
1606 else if (cmd.argument() == "index")
1607 code = Inset::INDEX_CODE;
1608 else if (cmd.argument() == "nomenclature")
1609 code = Inset::NOMENCL_CODE;
1610 else if (cmd.argument() == "label")
1611 code = Inset::LABEL_CODE;
1612 else if (cmd.argument() == "note")
1613 code = Inset::NOTE_CODE;
1614 else if (cmd.argument() == "ref")
1615 code = Inset::REF_CODE;
1616 else if (cmd.argument() == "toc")
1617 code = Inset::TOC_CODE;
1618 else if (cmd.argument() == "url")
1619 code = Inset::URL_CODE;
1620 else if (cmd.argument() == "vspace")
1621 code = Inset::VSPACE_CODE;
1622 else if (cmd.argument() == "wrap")
1623 code = Inset::WRAP_CODE;
1624 else if (cmd.argument() == "listings")
1625 code = Inset::LISTINGS_CODE;
1628 case LFUN_ERT_INSERT:
1629 code = Inset::ERT_CODE;
1631 case LFUN_LISTING_INSERT:
1632 code = Inset::LISTINGS_CODE;
1634 case LFUN_FOOTNOTE_INSERT:
1635 code = Inset::FOOT_CODE;
1637 case LFUN_TABULAR_INSERT:
1638 code = Inset::TABULAR_CODE;
1640 case LFUN_MARGINALNOTE_INSERT:
1641 code = Inset::MARGIN_CODE;
1643 case LFUN_FLOAT_INSERT:
1644 case LFUN_FLOAT_WIDE_INSERT:
1645 code = Inset::FLOAT_CODE;
1647 case LFUN_WRAP_INSERT:
1648 code = Inset::WRAP_CODE;
1650 case LFUN_FLOAT_LIST:
1651 code = Inset::FLOAT_LIST_CODE;
1654 case LFUN_LIST_INSERT:
1655 code = Inset::LIST_CODE;
1657 case LFUN_THEOREM_INSERT:
1658 code = Inset::THEOREM_CODE;
1661 case LFUN_CAPTION_INSERT:
1662 code = Inset::CAPTION_CODE;
1664 case LFUN_NOTE_INSERT:
1665 code = Inset::NOTE_CODE;
1667 case LFUN_FLEX_INSERT: {
1668 code = Inset::FLEX_CODE;
1669 string s = cmd.getArg(0);
1670 InsetLayout il = cur.buffer().params().getTextClass().insetlayout(from_utf8(s));
1671 if (il.lyxtype != "charstyle" &&
1672 il.lyxtype != "custom" &&
1673 il.lyxtype != "element")
1677 case LFUN_BOX_INSERT:
1678 code = Inset::BOX_CODE;
1680 case LFUN_BRANCH_INSERT:
1681 code = Inset::BRANCH_CODE;
1682 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1685 case LFUN_LABEL_INSERT:
1686 code = Inset::LABEL_CODE;
1688 case LFUN_OPTIONAL_INSERT:
1689 code = Inset::OPTARG_CODE;
1690 enable = numberOfOptArgs(cur.paragraph())
1691 < cur.paragraph().layout()->optionalargs;
1693 case LFUN_ENVIRONMENT_INSERT:
1694 code = Inset::BOX_CODE;
1696 case LFUN_INDEX_INSERT:
1697 code = Inset::INDEX_CODE;
1699 case LFUN_INDEX_PRINT:
1700 code = Inset::INDEX_PRINT_CODE;
1702 case LFUN_NOMENCL_INSERT:
1703 code = Inset::NOMENCL_CODE;
1705 case LFUN_NOMENCL_PRINT:
1706 code = Inset::NOMENCL_PRINT_CODE;
1708 case LFUN_TOC_INSERT:
1709 code = Inset::TOC_CODE;
1711 case LFUN_HTML_INSERT:
1712 case LFUN_URL_INSERT:
1713 code = Inset::URL_CODE;
1715 case LFUN_QUOTE_INSERT:
1716 // always allow this, since we will inset a raw quote
1717 // if an inset is not allowed.
1719 case LFUN_HYPHENATION_POINT_INSERT:
1720 case LFUN_LIGATURE_BREAK_INSERT:
1721 case LFUN_HFILL_INSERT:
1722 case LFUN_MENU_SEPARATOR_INSERT:
1723 case LFUN_DOTS_INSERT:
1724 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
1725 code = Inset::SPECIALCHAR_CODE;
1727 case LFUN_SPACE_INSERT:
1728 // slight hack: we know this is allowed in math mode
1730 code = Inset::SPACE_CODE;
1733 case LFUN_INSET_MODIFY:
1734 // We need to disable this, because we may get called for a
1736 // InsetTabular::getStatus() -> InsetText::getStatus()
1737 // and we don't handle LFUN_INSET_MODIFY.
1741 case LFUN_FONT_EMPH:
1742 flag.setOnOff(font.emph() == Font::ON);
1745 case LFUN_FONT_NOUN:
1746 flag.setOnOff(font.noun() == Font::ON);
1749 case LFUN_FONT_BOLD:
1750 flag.setOnOff(font.series() == Font::BOLD_SERIES);
1753 case LFUN_FONT_SANS:
1754 flag.setOnOff(font.family() == Font::SANS_FAMILY);
1757 case LFUN_FONT_ROMAN:
1758 flag.setOnOff(font.family() == Font::ROMAN_FAMILY);
1761 case LFUN_FONT_TYPEWRITER:
1762 flag.setOnOff(font.family() == Font::TYPEWRITER_FAMILY);
1767 enable = cur.selection();
1771 if (cmd.argument().empty()) {
1772 if (theClipboard().isInternal())
1773 enable = cap::numberOfSelections() > 0;
1775 enable = !theClipboard().empty();
1777 string const arg = to_utf8(cmd.argument());
1778 if (isStrUnsignedInt(arg)) {
1779 unsigned int n = convert<unsigned int>(arg);
1780 enable = cap::numberOfSelections() > n;
1787 case LFUN_CLIPBOARD_PASTE:
1788 enable = !theClipboard().empty();
1791 case LFUN_PRIMARY_SELECTION_PASTE:
1792 enable = cur.selection() || !theSelection().empty();
1795 case LFUN_PARAGRAPH_MOVE_UP:
1796 enable = cur.pit() > 0 && !cur.selection();
1799 case LFUN_PARAGRAPH_MOVE_DOWN:
1800 enable = cur.pit() < cur.lastpit() && !cur.selection();
1803 case LFUN_INSET_DISSOLVE:
1804 enable = !isMainText(cur.bv().buffer()) && cur.inset().nargs() == 1;
1807 case LFUN_CHANGE_ACCEPT:
1808 case LFUN_CHANGE_REJECT:
1809 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
1810 // In principle, these LFUNs should only be enabled if there
1811 // is a change at the current position/in the current selection.
1812 // However, without proper optimizations, this will inevitably
1813 // result in unacceptable performance - just imagine a user who
1814 // wants to select the complete content of a long document.
1818 case LFUN_WORD_DELETE_FORWARD:
1819 case LFUN_WORD_DELETE_BACKWARD:
1820 case LFUN_LINE_DELETE:
1821 case LFUN_WORD_FORWARD:
1822 case LFUN_WORD_BACKWARD:
1823 case LFUN_CHAR_FORWARD:
1824 case LFUN_CHAR_FORWARD_SELECT:
1825 case LFUN_CHAR_BACKWARD:
1826 case LFUN_CHAR_BACKWARD_SELECT:
1828 case LFUN_UP_SELECT:
1830 case LFUN_DOWN_SELECT:
1831 case LFUN_PARAGRAPH_UP_SELECT:
1832 case LFUN_PARAGRAPH_DOWN_SELECT:
1833 case LFUN_SCREEN_UP_SELECT:
1834 case LFUN_SCREEN_DOWN_SELECT:
1835 case LFUN_LINE_BEGIN_SELECT:
1836 case LFUN_LINE_END_SELECT:
1837 case LFUN_WORD_FORWARD_SELECT:
1838 case LFUN_WORD_BACKWARD_SELECT:
1839 case LFUN_WORD_SELECT:
1840 case LFUN_PARAGRAPH_UP:
1841 case LFUN_PARAGRAPH_DOWN:
1842 case LFUN_LINE_BEGIN:
1844 case LFUN_BREAK_LINE:
1845 case LFUN_CHAR_DELETE_FORWARD:
1846 case LFUN_DELETE_FORWARD_SKIP:
1847 case LFUN_CHAR_DELETE_BACKWARD:
1848 case LFUN_DELETE_BACKWARD_SKIP:
1849 case LFUN_BREAK_PARAGRAPH:
1850 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
1851 case LFUN_BREAK_PARAGRAPH_SKIP:
1852 case LFUN_PARAGRAPH_SPACING:
1853 case LFUN_INSET_INSERT:
1854 case LFUN_WORD_UPCASE:
1855 case LFUN_WORD_LOWCASE:
1856 case LFUN_WORD_CAPITALIZE:
1857 case LFUN_CHARS_TRANSPOSE:
1858 case LFUN_SERVER_GET_XY:
1859 case LFUN_SERVER_SET_XY:
1860 case LFUN_SERVER_GET_FONT:
1861 case LFUN_SERVER_GET_LAYOUT:
1863 case LFUN_DATE_INSERT:
1864 case LFUN_SELF_INSERT:
1865 case LFUN_LINE_INSERT:
1866 case LFUN_PAGEBREAK_INSERT:
1867 case LFUN_CLEARPAGE_INSERT:
1868 case LFUN_CLEARDOUBLEPAGE_INSERT:
1869 case LFUN_MATH_DISPLAY:
1870 case LFUN_MATH_IMPORT_SELECTION:
1871 case LFUN_MATH_MODE:
1872 case LFUN_MATH_MACRO:
1873 case LFUN_MATH_MATRIX:
1874 case LFUN_MATH_DELIM:
1875 case LFUN_MATH_BIGDELIM:
1876 case LFUN_MATH_INSERT:
1877 case LFUN_MATH_SUBSCRIPT:
1878 case LFUN_MATH_SUPERSCRIPT:
1879 case LFUN_FONT_DEFAULT:
1880 case LFUN_FONT_UNDERLINE:
1881 case LFUN_FONT_SIZE:
1883 case LFUN_FONT_FREE_APPLY:
1884 case LFUN_FONT_FREE_UPDATE:
1885 case LFUN_LAYOUT_PARAGRAPH:
1886 case LFUN_PARAGRAPH_UPDATE:
1887 case LFUN_ACCENT_UMLAUT:
1888 case LFUN_ACCENT_CIRCUMFLEX:
1889 case LFUN_ACCENT_GRAVE:
1890 case LFUN_ACCENT_ACUTE:
1891 case LFUN_ACCENT_TILDE:
1892 case LFUN_ACCENT_CEDILLA:
1893 case LFUN_ACCENT_MACRON:
1894 case LFUN_ACCENT_DOT:
1895 case LFUN_ACCENT_UNDERDOT:
1896 case LFUN_ACCENT_UNDERBAR:
1897 case LFUN_ACCENT_CARON:
1898 case LFUN_ACCENT_SPECIAL_CARON:
1899 case LFUN_ACCENT_BREVE:
1900 case LFUN_ACCENT_TIE:
1901 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1902 case LFUN_ACCENT_CIRCLE:
1903 case LFUN_ACCENT_OGONEK:
1904 case LFUN_THESAURUS_ENTRY:
1905 case LFUN_PARAGRAPH_PARAMS_APPLY:
1906 case LFUN_PARAGRAPH_PARAMS:
1908 case LFUN_BUFFER_END:
1909 case LFUN_BUFFER_BEGIN:
1910 case LFUN_BUFFER_BEGIN_SELECT:
1911 case LFUN_BUFFER_END_SELECT:
1912 case LFUN_UNICODE_INSERT:
1913 // these are handled in our dispatch()
1921 if (code != Inset::NO_CODE
1922 && (cur.empty() || !cur.inset().insetAllowed(code)))
1925 flag.enabled(enable);
1930 void Text::pasteString(Cursor & cur, docstring const & clip,
1933 cur.clearSelection();
1934 if (!clip.empty()) {
1937 insertStringAsParagraphs(cur, clip);
1939 insertStringAsLines(cur, clip);