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.
20 #include "BranchList.h"
21 #include "FloatList.h"
22 #include "FuncStatus.h"
24 #include "buffer_funcs.h"
25 #include "bufferparams.h"
26 #include "BufferView.h"
27 #include "bufferview_funcs.h"
29 #include "coordcache.h"
30 #include "CutAndPaste.h"
32 #include "dispatchresult.h"
33 #include "errorlist.h"
35 #include "funcrequest.h"
39 #include "LyXAction.h"
44 #include "paragraph.h"
45 #include "paragraph_funcs.h"
46 #include "ParagraphParameters.h"
49 #include "pariterator.h"
51 #include "frontends/Clipboard.h"
52 #include "frontends/Selection.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>
77 using cap::copySelection;
78 using cap::cutSelection;
79 using cap::pasteClipboard;
80 using cap::pasteSelection;
81 using cap::replaceSelection;
83 using support::isStrUnsignedInt;
88 using std::istringstream;
89 using std::ostringstream;
92 extern string current_layout;
98 LyXFont freefont(LyXFont::ALL_IGNORE);
99 bool toggleall = false;
102 void toggleAndShow(LCursor & cur, LyXText * text,
103 LyXFont const & font, bool toggleall = true)
105 text->toggleFree(cur, font, toggleall);
107 if (font.language() != ignore_language ||
108 font.number() != LyXFont::IGNORE) {
109 Paragraph & par = cur.paragraph();
110 text->bidi.computeTables(par, cur.buffer(), cur.textRow());
111 if (cur.boundary() !=
112 text->bidi.isBoundary(cur.buffer(), par,
114 text->real_current_font))
115 text->setCursor(cur, cur.pit(), cur.pos(),
116 false, !cur.boundary());
121 void moveCursor(LCursor & cur, bool selecting)
123 if (selecting || cur.mark())
125 theSelection().haveSelection(cur.selection());
126 cur.bv().switchKeyMap();
130 void finishChange(LCursor & cur, bool selecting)
133 moveCursor(cur, selecting);
137 void mathDispatch(LCursor & cur, FuncRequest const & cmd, bool display)
140 docstring sel = cur.selectionAsString(false);
141 //lyxerr << "selection is: '" << sel << "'" << endl;
143 // It may happen that sel is empty but there is a selection
144 replaceSelection(cur);
147 #ifdef ENABLE_ASSERTIONS
148 const int old_pos = cur.pos();
150 cur.insert(new InsetMathHull(hullSimple));
151 BOOST_ASSERT(old_pos == cur.pos());
152 cur.nextInset()->edit(cur, true);
153 // don't do that also for LFUN_MATH_MODE
154 // unless you want end up with always changing
155 // to mathrm when opening an inlined inset --
156 // I really hate "LyXfunc overloading"...
158 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
159 // Avoid an unnecessary undo step if cmd.argument
161 if (!cmd.argument().empty())
162 cur.dispatch(FuncRequest(LFUN_MATH_INSERT,
165 // create a macro if we see "\\newcommand"
166 // somewhere, and an ordinary formula
168 if (sel.find(from_ascii("\\newcommand")) == string::npos
169 && sel.find(from_ascii("\\def")) == string::npos)
171 InsetMathHull * formula = new InsetMathHull;
172 istringstream is(to_utf8(sel));
175 formula->read(cur.buffer(), lex);
176 if (formula->getType() == hullNone)
177 // Don't create pseudo formulas if
178 // delimiters are left out
179 formula->mutate(hullSimple);
182 cur.insert(new MathMacroTemplate(sel));
185 cur.message(from_utf8(N_("Math editor mode")));
194 string const freefont2string()
197 if (font2string(freefont, toggleall, data))
204 void LyXText::cursorPrevious(LCursor & cur)
206 pos_type cpos = cur.pos();
207 pit_type cpar = cur.pit();
209 int x = cur.x_target();
210 setCursorFromCoordinates(cur, x, 0);
211 cur.dispatch(FuncRequest(cur.selection()? LFUN_UP_SELECT: LFUN_UP));
213 if (cpar == cur.pit() && cpos == cur.pos())
214 // we have a row which is taller than the workarea. The
215 // simplest solution is to move to the previous row instead.
216 cur.dispatch(FuncRequest(cur.selection()? LFUN_UP_SELECT: LFUN_UP));
219 cur.updateFlags(Update::Force | Update::FitCursor);
223 void LyXText::cursorNext(LCursor & cur)
225 pos_type cpos = cur.pos();
226 pit_type cpar = cur.pit();
228 int x = cur.x_target();
229 setCursorFromCoordinates(cur, x, cur.bv().workHeight() - 1);
230 cur.dispatch(FuncRequest(cur.selection()? LFUN_DOWN_SELECT: LFUN_DOWN));
232 if (cpar == cur.pit() && cpos == cur.pos())
233 // we have a row which is taller than the workarea. The
234 // simplest solution is to move to the next row instead.
236 FuncRequest(cur.selection()? LFUN_DOWN_SELECT: LFUN_DOWN));
239 cur.updateFlags(Update::Force | Update::FitCursor);
245 void specialChar(LCursor & cur, InsetSpecialChar::Kind kind)
247 cap::replaceSelection(cur);
248 cur.insert(new InsetSpecialChar(kind));
253 bool doInsertInset(LCursor & cur, LyXText * text,
254 FuncRequest const & cmd, bool edit, bool pastesel)
256 InsetBase * inset = createInset(&cur.bv(), cmd);
262 if (cur.selection()) {
263 lyx::dispatch(FuncRequest(LFUN_CUT));
266 text->insertInset(cur, inset);
269 inset->edit(cur, true);
271 if (gotsel && pastesel) {
272 lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
273 // reset first par to default
274 if (cur.lastpit() != 0 || cur.lastpos() != 0) {
275 LyXLayout_ptr const layout =
276 cur.buffer().params().getLyXTextClass().defaultLayout();
277 cur.text()->paragraphs().begin()->layout(layout);
287 void LyXText::number(LCursor & cur)
289 LyXFont font(LyXFont::ALL_IGNORE);
290 font.setNumber(LyXFont::TOGGLE);
291 toggleAndShow(cur, this, font);
295 bool LyXText::isRTL(Buffer const & buffer, Paragraph const & par) const
297 return par.isRightToLeftPar(buffer.params());
301 void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
303 lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
305 // FIXME: We use the update flag to indicates wether a singlePar or a
306 // full screen update is needed. We reset it here but shall we restore it
310 BOOST_ASSERT(cur.text() == this);
311 BufferView * bv = &cur.bv();
312 CursorSlice oldTopSlice = cur.top();
313 bool oldBoundary = cur.boundary();
314 bool sel = cur.selection();
315 // Signals that, even if needsUpdate == false, an update of the
316 // cursor paragraph is required
317 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
318 LyXAction::SingleParUpdate);
319 // Signals that a full-screen update is required
320 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
321 LyXAction::NoUpdate) || singleParUpdate);
322 // Remember the old paragraph metric (_outer_ paragraph!)
323 ParagraphMetrics const & pm = cur.bv().parMetrics(
324 cur.bottom().text(), cur.bottom().pit());
325 Dimension olddim = pm.dim();
327 switch (cmd.action) {
329 case LFUN_PARAGRAPH_MOVE_DOWN: {
330 pit_type const pit = cur.pit();
331 recUndo(cur, pit, pit + 1);
333 std::swap(pars_[pit], pars_[pit + 1]);
335 ParIterator begin(cur);
337 ParIterator end = boost::next(ParIterator(cur));
338 updateLabels(cur.buffer(), begin, end);
344 case LFUN_PARAGRAPH_MOVE_UP: {
345 pit_type const pit = cur.pit();
346 recUndo(cur, pit - 1, pit);
348 std::swap(pars_[pit], pars_[pit - 1]);
350 ParIterator end = boost::next(ParIterator(cur));
352 ParIterator begin(cur);
353 updateLabels(cur.buffer(), begin, end);
359 case LFUN_APPENDIX: {
360 Paragraph & par = cur.paragraph();
361 bool start = !par.params().startOfAppendix();
364 #warning The code below only makes sense at top level.
365 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
367 // ensure that we have only one start_of_appendix in this document
368 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
369 if (pars_[tmp].params().startOfAppendix()) {
371 pars_[tmp].params().startOfAppendix(false);
377 par.params().startOfAppendix(start);
379 // we can set the refreshing parameters now
380 updateLabels(cur.buffer());
384 case LFUN_WORD_DELETE_FORWARD:
385 cur.clearSelection();
386 deleteWordForward(cur);
387 finishChange(cur, false);
390 case LFUN_WORD_DELETE_BACKWARD:
391 cur.clearSelection();
392 deleteWordBackward(cur);
393 finishChange(cur, false);
396 case LFUN_LINE_DELETE:
397 cur.clearSelection();
398 deleteLineForward(cur);
399 finishChange(cur, false);
402 case LFUN_BUFFER_BEGIN:
403 case LFUN_BUFFER_BEGIN_SELECT:
404 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
405 if (cur.depth() == 1) {
406 needsUpdate |= cursorTop(cur);
412 case LFUN_BUFFER_END:
413 case LFUN_BUFFER_END_SELECT:
414 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
415 if (cur.depth() == 1) {
416 needsUpdate |= cursorBottom(cur);
422 case LFUN_CHAR_FORWARD:
423 case LFUN_CHAR_FORWARD_SELECT:
424 //lyxerr << BOOST_CURRENT_FUNCTION
425 // << " LFUN_CHAR_FORWARD[SEL]:\n" << cur << endl;
426 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
427 if (isRTL(*cur.bv().buffer(), cur.paragraph()))
428 needsUpdate |= cursorLeft(cur);
430 needsUpdate |= cursorRight(cur);
432 if (!needsUpdate && oldTopSlice == cur.top()
433 && cur.boundary() == oldBoundary) {
435 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
439 case LFUN_CHAR_BACKWARD:
440 case LFUN_CHAR_BACKWARD_SELECT:
441 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
442 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
443 if (isRTL(*cur.bv().buffer(), cur.paragraph()))
444 needsUpdate |= cursorRight(cur);
446 needsUpdate |= cursorLeft(cur);
448 if (!needsUpdate && oldTopSlice == cur.top()
449 && cur.boundary() == oldBoundary) {
451 cmd = FuncRequest(LFUN_FINISHED_LEFT);
457 //lyxerr << "handle LFUN_UP[SEL]:\n" << cur << endl;
458 needsUpdate |= cur.selHandle(cmd.action == LFUN_UP_SELECT);
460 needsUpdate |= cursorUp(cur);
462 if (!needsUpdate && oldTopSlice == cur.top()
463 && cur.boundary() == oldBoundary) {
465 cmd = FuncRequest(LFUN_FINISHED_UP);
470 case LFUN_DOWN_SELECT:
471 //lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
472 needsUpdate |= cur.selHandle(cmd.action == LFUN_DOWN_SELECT);
473 needsUpdate |= cursorDown(cur);
475 if (!needsUpdate && oldTopSlice == cur.top() &&
476 cur.boundary() == oldBoundary)
479 cmd = FuncRequest(LFUN_FINISHED_DOWN);
483 case LFUN_PARAGRAPH_UP:
484 case LFUN_PARAGRAPH_UP_SELECT:
485 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
486 needsUpdate |= cursorUpParagraph(cur);
489 case LFUN_PARAGRAPH_DOWN:
490 case LFUN_PARAGRAPH_DOWN_SELECT:
491 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
492 needsUpdate |= cursorDownParagraph(cur);
496 case LFUN_SCREEN_UP_SELECT:
497 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_UP_SELECT);
498 if (cur.pit() == 0 && cur.textRow().pos() == 0) {
500 cmd = FuncRequest(LFUN_FINISHED_UP);
506 case LFUN_SCREEN_DOWN:
507 case LFUN_SCREEN_DOWN_SELECT:
508 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_DOWN_SELECT);
509 if (cur.pit() == cur.lastpit()
510 && cur.textRow().endpos() == cur.lastpos()) {
512 cmd = FuncRequest(LFUN_FINISHED_DOWN);
518 case LFUN_LINE_BEGIN:
519 case LFUN_LINE_BEGIN_SELECT:
520 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
521 needsUpdate |= cursorHome(cur);
525 case LFUN_LINE_END_SELECT:
526 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
527 needsUpdate |= cursorEnd(cur);
530 case LFUN_WORD_FORWARD:
531 case LFUN_WORD_FORWARD_SELECT:
532 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
533 if (isRTL(*cur.bv().buffer(), cur.paragraph()))
534 needsUpdate |= cursorLeftOneWord(cur);
536 needsUpdate |= cursorRightOneWord(cur);
539 case LFUN_WORD_BACKWARD:
540 case LFUN_WORD_BACKWARD_SELECT:
541 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
542 if (isRTL(*cur.bv().buffer(), cur.paragraph()))
543 needsUpdate |= cursorRightOneWord(cur);
545 needsUpdate |= cursorLeftOneWord(cur);
548 case LFUN_WORD_SELECT: {
549 selectWord(cur, WHOLE_WORD);
550 finishChange(cur, true);
554 case LFUN_BREAK_LINE: {
555 // Not allowed by LaTeX (labels or empty par)
556 if (cur.pos() > cur.paragraph().beginOfBody()) {
557 if (!cur.selection())
559 cap::replaceSelection(cur);
560 cur.insert(new InsetNewline);
562 moveCursor(cur, false);
567 case LFUN_CHAR_DELETE_FORWARD:
568 if (!cur.selection()) {
569 if (cur.pos() == cur.paragraph().size())
570 // Par boundary, force full-screen update
571 singleParUpdate = false;
572 needsUpdate |= erase(cur);
574 // It is possible to make it a lot faster still
575 // just comment out the line below...
577 cutSelection(cur, true, false);
578 singleParUpdate = false;
580 moveCursor(cur, false);
583 case LFUN_DELETE_FORWARD_SKIP:
584 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
585 if (!cur.selection()) {
586 if (cur.pos() == cur.lastpos()) {
593 cutSelection(cur, true, false);
598 case LFUN_CHAR_DELETE_BACKWARD:
599 if (!cur.selection()) {
600 if (bv->getIntl().getTransManager().backspace()) {
601 // Par boundary, full-screen update
603 singleParUpdate = false;
604 needsUpdate |= backspace(cur);
606 // It is possible to make it a lot faster still
607 // just comment out the line below...
610 cutSelection(cur, true, false);
611 singleParUpdate = false;
616 case LFUN_DELETE_BACKWARD_SKIP:
617 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
618 if (!cur.selection()) {
622 //CursorSlice cur = cursor();
626 cutSelection(cur, true, false);
630 case LFUN_BREAK_PARAGRAPH:
631 cap::replaceSelection(cur);
632 breakParagraph(cur, 0);
637 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
638 cap::replaceSelection(cur);
639 breakParagraph(cur, 1);
644 case LFUN_BREAK_PARAGRAPH_SKIP: {
645 // When at the beginning of a paragraph, remove
646 // indentation. Otherwise, do the same as LFUN_BREAK_PARAGRAPH.
647 cap::replaceSelection(cur);
649 cur.paragraph().params().labelWidthString(docstring());
651 breakParagraph(cur, 0);
657 case LFUN_PARAGRAPH_SPACING: {
658 Paragraph & par = cur.paragraph();
659 Spacing::Space cur_spacing = par.params().spacing().getSpace();
660 string cur_value = "1.0";
661 if (cur_spacing == Spacing::Other)
662 cur_value = par.params().spacing().getValueAsString();
664 istringstream is(to_utf8(cmd.argument()));
667 Spacing::Space new_spacing = cur_spacing;
668 string new_value = cur_value;
670 lyxerr << "Missing argument to `paragraph-spacing'"
672 } else if (tmp == "single") {
673 new_spacing = Spacing::Single;
674 } else if (tmp == "onehalf") {
675 new_spacing = Spacing::Onehalf;
676 } else if (tmp == "double") {
677 new_spacing = Spacing::Double;
678 } else if (tmp == "other") {
679 new_spacing = Spacing::Other;
680 string tmpval = "0.0";
682 lyxerr << "new_value = " << tmpval << endl;
685 } else if (tmp == "default") {
686 new_spacing = Spacing::Default;
688 lyxerr << to_utf8(_("Unknown spacing argument: "))
689 << to_utf8(cmd.argument()) << endl;
691 if (cur_spacing != new_spacing || cur_value != new_value)
692 par.params().spacing(Spacing(new_spacing, new_value));
696 case LFUN_INSET_INSERT: {
698 InsetBase * inset = createInset(bv, cmd);
700 Paragraph & par = pars_[cur.pit()];
701 // FIXME (Abdel 01/02/2006:
702 // What follows is a partial fix for bug 2154:
703 // http://bugzilla.lyx.org/show_bug.cgi?id=2154
704 // This will automatically put the label inset _after_ a
705 // numbered section. It is possible to extend the mechanism
706 // to any kind of LateX environement.
707 if (inset->lyxCode() == InsetBase::LABEL_CODE
708 && par.layout()->labeltype == LABEL_COUNTER) {
709 // Go to the end of the paragraph
710 // Warning: Because of Change-Tracking, the last
711 // position is 'size()' and not 'size()-1':
712 cur.pos() = par.size();
713 // Insert a new paragraph
714 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
717 insertInset(cur, inset);
723 case LFUN_INSET_DISSOLVE:
724 needsUpdate |= dissolveInset(cur);
727 case LFUN_INSET_SETTINGS:
728 cur.inset().showInsetDialog(bv);
731 case LFUN_SPACE_INSERT:
732 if (cur.paragraph().layout()->free_spacing)
733 insertChar(cur, ' ');
735 doInsertInset(cur, this, cmd, false, false);
738 moveCursor(cur, false);
741 case LFUN_HYPHENATION_POINT_INSERT:
742 specialChar(cur, InsetSpecialChar::HYPHENATION);
745 case LFUN_LIGATURE_BREAK_INSERT:
746 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
749 case LFUN_DOTS_INSERT:
750 specialChar(cur, InsetSpecialChar::LDOTS);
753 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
754 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
757 case LFUN_MENU_SEPARATOR_INSERT:
758 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
761 case LFUN_WORD_UPCASE:
762 changeCase(cur, LyXText::text_uppercase);
765 case LFUN_WORD_LOWCASE:
766 changeCase(cur, LyXText::text_lowercase);
769 case LFUN_WORD_CAPITALIZE:
770 changeCase(cur, LyXText::text_capitalization);
773 case LFUN_CHARS_TRANSPOSE:
778 cur.message(_("Paste"));
779 cap::replaceSelection(cur);
780 if (cmd.argument().empty() && !theClipboard().isInternal())
781 pasteClipboard(cur, bv->buffer()->errorList("Paste"));
783 string const arg(to_utf8(cmd.argument()));
784 pasteSelection(cur, bv->buffer()->errorList("Paste"),
785 isStrUnsignedInt(arg) ?
786 convert<unsigned int>(arg) :
789 bv->buffer()->errors("Paste");
790 cur.clearSelection(); // bug 393
796 cutSelection(cur, true, true);
797 cur.message(_("Cut"));
802 cur.message(_("Copy"));
805 case LFUN_SERVER_GET_XY:
806 cur.message(from_utf8(
807 convert<string>(cursorX(cur.bv(), cur.top(), cur.boundary()))
808 + ' ' + convert<string>(cursorY(cur.bv(), cur.top(), cur.boundary()))));
811 case LFUN_SERVER_SET_XY: {
814 istringstream is(to_utf8(cmd.argument()));
817 lyxerr << "SETXY: Could not parse coordinates in '"
818 << to_utf8(cmd.argument()) << std::endl;
820 setCursorFromCoordinates(cur, x, y);
824 case LFUN_SERVER_GET_FONT:
825 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
826 cur.message(from_ascii("E"));
827 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
828 cur.message(from_ascii("N"));
830 cur.message(from_ascii("0"));
833 case LFUN_SERVER_GET_LAYOUT:
834 cur.message(from_utf8(cur.paragraph().layout()->name()));
838 string layout = to_ascii(cmd.argument());
839 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) " << layout << endl;
841 // Derive layout number from given argument (string)
842 // and current buffer's textclass (number)
843 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
845 layout = tclass.defaultLayoutName();
846 bool hasLayout = tclass.hasLayout(layout);
848 // If the entry is obsolete, use the new one instead.
850 string const & obs = tclass[layout]->obsoleted_by();
856 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
857 from_utf8(N_(" not known")));
861 bool change_layout = (current_layout != layout);
863 if (!change_layout && cur.selection() &&
864 cur.selBegin().pit() != cur.selEnd().pit())
866 pit_type spit = cur.selBegin().pit();
867 pit_type epit = cur.selEnd().pit() + 1;
868 while (spit != epit) {
869 if (pars_[spit].layout()->name() != current_layout) {
870 change_layout = true;
878 current_layout = layout;
879 setLayout(cur, layout);
880 // inform the GUI that the layout has changed.
881 bv->layoutChanged(layout);
887 case LFUN_CLIPBOARD_PASTE:
888 cur.clearSelection();
889 pasteClipboard(cur, bv->buffer()->errorList("Paste"),
890 cmd.argument() == "paragraph");
891 bv->buffer()->errors("Paste");
894 case LFUN_PRIMARY_SELECTION_PASTE:
895 pasteString(cur, theSelection().get(),
896 cmd.argument() == "paragraph");
899 case LFUN_UNICODE_INSERT: {
900 if (cmd.argument().empty())
902 docstring hexstring = cmd.argument();
903 if (lyx::support::isHex(hexstring)) {
904 char_type c = lyx::support::hexToInt(hexstring);
905 if (c > 32 && c < 0x10ffff) {
906 lyxerr << "Inserting c: " << c << endl;
907 docstring s = docstring(1, c);
908 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
914 case LFUN_QUOTE_INSERT: {
915 cap::replaceSelection(cur);
916 Paragraph & par = cur.paragraph();
917 pos_type pos = cur.pos();
921 else if (cur.prevInset() && cur.prevInset()->isSpace())
924 c = par.getChar(pos - 1);
926 LyXLayout_ptr const & style = par.layout();
928 BufferParams const & bufparams = bv->buffer()->params();
929 if (!style->pass_thru
930 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
931 string arg = to_utf8(cmd.argument());
933 cur.insert(new InsetQuotes(c,
934 bufparams.quotes_language,
935 InsetQuotes::SingleQ));
937 cur.insert(new InsetQuotes(c,
938 bufparams.quotes_language,
939 InsetQuotes::DoubleQ));
943 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
947 case LFUN_DATE_INSERT:
948 if (cmd.argument().empty())
949 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
950 formatted_time(current_time())));
952 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
953 formatted_time(current_time(), to_utf8(cmd.argument()))));
956 case LFUN_MOUSE_TRIPLE:
957 if (cmd.button() == mouse_button::button1) {
963 theSelection().haveSelection(cur.selection());
967 case LFUN_MOUSE_DOUBLE:
968 if (cmd.button() == mouse_button::button1) {
969 selectWord(cur, WHOLE_WORD_STRICT);
971 theSelection().haveSelection(cur.selection());
975 // Single-click on work area
976 case LFUN_MOUSE_PRESS: {
977 // Right click on a footnote flag opens float menu
978 if (cmd.button() == mouse_button::button3)
979 cur.clearSelection();
981 // Middle button press pastes if we have a selection
982 // We do this here as if the selection was inside an inset
983 // it could get cleared on the unlocking of the inset so
984 // we have to check this first
985 bool paste_internally = false;
986 if (cmd.button() == mouse_button::button2 && cur.selection()) {
987 // Copy the selection to the clipboard stack. This
988 // is done for two reasons:
989 // - We want it to appear in the "Edit->Paste recent"
991 // - We can then use the normal copy/paste machinery
992 // instead of theSelection().get() to preserve
993 // formatting of the pasted stuff.
994 cap::copySelectionToStack(cur.bv().cursor());
995 paste_internally = true;
998 // we have to update after dePM triggered
999 bool update = bv->mouseSetCursor(cur);
1001 // Insert primary selection with middle mouse
1002 // if there is a local selection in the current buffer,
1004 if (cmd.button() == mouse_button::button2) {
1005 if (paste_internally)
1006 lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
1008 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
1011 if (!update && cmd.button() == mouse_button::button1) {
1012 needsUpdate = false;
1019 case LFUN_MOUSE_MOTION: {
1020 // Only use motion with button 1
1021 //if (cmd.button() != mouse_button::button1)
1024 // ignore motions deeper nested than the real anchor
1025 LCursor & bvcur = cur.bv().cursor();
1026 if (bvcur.anchor_.hasPart(cur)) {
1027 CursorSlice old = bvcur.top();
1029 int const wh = bv->workHeight();
1030 int const y = std::max(0, std::min(wh - 1, cmd.y));
1032 setCursorFromCoordinates(cur, cmd.x, y);
1033 cur.x_target() = cmd.x;
1035 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1037 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1038 // This is to allow jumping over large insets
1039 if (cur.top() == old) {
1041 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1043 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1046 if (cur.top() == old)
1049 // don't set anchor_
1050 bvcur.setCursor(cur);
1051 bvcur.selection() = true;
1052 //lyxerr << "MOTION: " << bv->cursor() << endl;
1060 case LFUN_MOUSE_RELEASE: {
1061 if (cmd.button() == mouse_button::button2)
1065 if (cmd.button() == mouse_button::button1) {
1066 if (cur.selection())
1067 theSelection().haveSelection(true);
1068 needsUpdate = false;
1076 case LFUN_SELF_INSERT: {
1077 if (cmd.argument().empty())
1080 // Automatically delete the currently selected
1081 // text and replace it with what is being
1082 // typed in now. Depends on lyxrc settings
1083 // "auto_region_delete", which defaults to
1086 if (lyxrc.auto_region_delete) {
1087 if (cur.selection())
1088 cutSelection(cur, false, false);
1089 // cutSelection clears the X selection.
1091 theSelection().haveSelection(false);
1094 cur.clearSelection();
1095 LyXFont const old_font = real_current_font;
1097 docstring::const_iterator cit = cmd.argument().begin();
1098 docstring::const_iterator end = cmd.argument().end();
1099 for (; cit != end; ++cit)
1101 bv->getIntl().getTransManager().
1102 translateAndInsert(*cit, this);
1104 insertChar(bv->cursor(), *cit);
1108 moveCursor(cur, false);
1112 case LFUN_URL_INSERT: {
1113 InsetCommandParams p("url");
1114 string const data = InsetCommandMailer::params2string("url", p);
1115 bv->showInsetDialog("url", data, 0);
1119 case LFUN_HTML_INSERT: {
1120 InsetCommandParams p("htmlurl");
1121 string const data = InsetCommandMailer::params2string("url", p);
1122 bv->showInsetDialog("url", data, 0);
1126 case LFUN_LABEL_INSERT: {
1127 InsetCommandParams p("label");
1128 // Try to generate a valid label
1129 p["name"] = (cmd.argument().empty()) ?
1130 cur.getPossibleLabel() :
1132 string const data = InsetCommandMailer::params2string("label", p);
1134 if (cmd.argument().empty()) {
1135 bv->showInsetDialog("label", data, 0);
1137 FuncRequest fr(LFUN_INSET_INSERT, data);
1145 case LFUN_LIST_INSERT:
1146 case LFUN_THEOREM_INSERT:
1148 case LFUN_CAPTION_INSERT:
1149 // Open the inset, and move the current selection
1151 doInsertInset(cur, this, cmd, true, true);
1153 updateLabels(*bv->buffer());
1155 case LFUN_NOTE_INSERT:
1156 case LFUN_CHARSTYLE_INSERT:
1157 case LFUN_BOX_INSERT:
1158 case LFUN_BRANCH_INSERT:
1159 case LFUN_BIBITEM_INSERT:
1160 case LFUN_ERT_INSERT:
1161 case LFUN_FOOTNOTE_INSERT:
1162 case LFUN_MARGINALNOTE_INSERT:
1163 case LFUN_OPTIONAL_INSERT:
1164 case LFUN_ENVIRONMENT_INSERT:
1165 // Open the inset, and move the current selection
1167 doInsertInset(cur, this, cmd, true, true);
1171 case LFUN_TABULAR_INSERT:
1172 // if there were no arguments, just open the dialog
1173 if (doInsertInset(cur, this, cmd, false, true))
1176 bv->showDialog("tabularcreate");
1180 case LFUN_FLOAT_INSERT:
1181 case LFUN_FLOAT_WIDE_INSERT:
1182 case LFUN_WRAP_INSERT: {
1183 doInsertInset(cur, this, cmd, true, true);
1185 ParagraphList & pars = cur.text()->paragraphs();
1186 // We create two additional empty paragraphs so that the
1187 // user can choose where to put the graphics (or table).
1188 pars.push_back(pars[0]);
1189 pars.push_back(pars[0]);
1190 // Now that we have three paragraphs, we reposition the cursor
1191 // at the beginning of the second one.
1194 cur.dispatch(FuncRequest(LFUN_CAPTION_INSERT));
1195 // FIXME: When leaving the Float (or Wrap) inset we should
1196 // delete any empty paragraph left above or below the
1201 case LFUN_INDEX_INSERT:
1202 case LFUN_NOMENCL_INSERT: {
1203 InsetBase * inset = createInset(&cur.bv(), cmd);
1208 cur.clearSelection();
1209 insertInset(cur, inset);
1210 inset->edit(cur, true);
1211 // Show the dialog for the nomenclature entry, since the
1212 // description entry still needs to be filled in.
1213 if (cmd.action == LFUN_NOMENCL_INSERT)
1214 InsetCommandMailer("nomenclature",
1215 *reinterpret_cast<InsetCommand *>(inset)).showDialog(&cur.bv());
1220 case LFUN_INDEX_PRINT:
1221 case LFUN_NOMENCL_PRINT:
1222 case LFUN_TOC_INSERT:
1223 case LFUN_HFILL_INSERT:
1224 case LFUN_LINE_INSERT:
1225 case LFUN_PAGEBREAK_INSERT:
1226 case LFUN_CLEARPAGE_INSERT:
1227 case LFUN_CLEARDOUBLEPAGE_INSERT:
1229 doInsertInset(cur, this, cmd, false, false);
1233 case LFUN_DEPTH_DECREMENT:
1234 changeDepth(cur, DEC_DEPTH);
1237 case LFUN_DEPTH_INCREMENT:
1238 changeDepth(cur, INC_DEPTH);
1241 case LFUN_MATH_DISPLAY:
1242 mathDispatch(cur, cmd, true);
1245 case LFUN_MATH_IMPORT_SELECTION:
1246 case LFUN_MATH_MODE:
1247 if (cmd.argument() == "on")
1248 // don't pass "on" as argument
1249 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1251 mathDispatch(cur, cmd, false);
1254 case LFUN_MATH_MACRO:
1255 if (cmd.argument().empty())
1256 cur.errorMessage(from_utf8(N_("Missing argument")));
1258 string s = to_utf8(cmd.argument());
1259 string const s1 = token(s, ' ', 1);
1260 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1261 string const s2 = token(s, ' ', 2);
1262 string const type = s2.empty() ? "newcommand" : s2;
1263 cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, from_utf8(type)));
1264 //cur.nextInset()->edit(cur, true);
1268 // passthrough hat and underscore outside mathed:
1269 case LFUN_MATH_SUBSCRIPT:
1270 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1272 case LFUN_MATH_SUPERSCRIPT:
1273 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1276 case LFUN_MATH_INSERT:
1277 case LFUN_MATH_MATRIX:
1278 case LFUN_MATH_DELIM:
1279 case LFUN_MATH_BIGDELIM: {
1280 cur.insert(new InsetMathHull(hullSimple));
1281 cur.dispatch(FuncRequest(LFUN_CHAR_FORWARD));
1286 case LFUN_FONT_EMPH: {
1287 LyXFont font(LyXFont::ALL_IGNORE);
1288 font.setEmph(LyXFont::TOGGLE);
1289 toggleAndShow(cur, this, font);
1293 case LFUN_FONT_BOLD: {
1294 LyXFont font(LyXFont::ALL_IGNORE);
1295 font.setSeries(LyXFont::BOLD_SERIES);
1296 toggleAndShow(cur, this, font);
1300 case LFUN_FONT_NOUN: {
1301 LyXFont font(LyXFont::ALL_IGNORE);
1302 font.setNoun(LyXFont::TOGGLE);
1303 toggleAndShow(cur, this, font);
1307 case LFUN_FONT_CODE: {
1308 LyXFont font(LyXFont::ALL_IGNORE);
1309 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1310 toggleAndShow(cur, this, font);
1314 case LFUN_FONT_SANS: {
1315 LyXFont font(LyXFont::ALL_IGNORE);
1316 font.setFamily(LyXFont::SANS_FAMILY);
1317 toggleAndShow(cur, this, font);
1321 case LFUN_FONT_ROMAN: {
1322 LyXFont font(LyXFont::ALL_IGNORE);
1323 font.setFamily(LyXFont::ROMAN_FAMILY);
1324 toggleAndShow(cur, this, font);
1328 case LFUN_FONT_DEFAULT: {
1329 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1330 toggleAndShow(cur, this, font);
1334 case LFUN_FONT_UNDERLINE: {
1335 LyXFont font(LyXFont::ALL_IGNORE);
1336 font.setUnderbar(LyXFont::TOGGLE);
1337 toggleAndShow(cur, this, font);
1341 case LFUN_FONT_SIZE: {
1342 LyXFont font(LyXFont::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 LyXFont font(LyXFont::ALL_IGNORE);
1353 font.setLanguage(lang);
1354 toggleAndShow(cur, this, font);
1359 case LFUN_FONT_FREE_APPLY:
1360 toggleAndShow(cur, this, freefont, toggleall);
1361 cur.message(_("Character set"));
1364 // Set the freefont using the contents of \param data dispatched from
1365 // the frontends and apply it at the current cursor location.
1366 case LFUN_FONT_FREE_UPDATE: {
1369 if (bv_funcs::string2font(to_utf8(cmd.argument()), font, toggle)) {
1372 toggleAndShow(cur, this, freefont, toggleall);
1373 cur.message(_("Character set"));
1378 case LFUN_FINISHED_LEFT:
1379 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1382 case LFUN_FINISHED_RIGHT:
1383 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1387 case LFUN_FINISHED_UP:
1388 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_UP:\n" << cur << endl;
1392 case LFUN_FINISHED_DOWN:
1393 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_DOWN:\n" << cur << endl;
1397 case LFUN_LAYOUT_PARAGRAPH: {
1399 params2string(cur.paragraph(), data);
1400 data = "show\n" + data;
1401 bv->showDialogWithData("paragraph", data);
1405 case LFUN_PARAGRAPH_UPDATE: {
1407 params2string(cur.paragraph(), data);
1409 // Will the paragraph accept changes from the dialog?
1410 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1412 data = "update " + convert<string>(accept) + '\n' + data;
1413 bv->updateDialog("paragraph", data);
1417 case LFUN_ACCENT_UMLAUT:
1418 case LFUN_ACCENT_CIRCUMFLEX:
1419 case LFUN_ACCENT_GRAVE:
1420 case LFUN_ACCENT_ACUTE:
1421 case LFUN_ACCENT_TILDE:
1422 case LFUN_ACCENT_CEDILLA:
1423 case LFUN_ACCENT_MACRON:
1424 case LFUN_ACCENT_DOT:
1425 case LFUN_ACCENT_UNDERDOT:
1426 case LFUN_ACCENT_UNDERBAR:
1427 case LFUN_ACCENT_CARON:
1428 case LFUN_ACCENT_SPECIAL_CARON:
1429 case LFUN_ACCENT_BREVE:
1430 case LFUN_ACCENT_TIE:
1431 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1432 case LFUN_ACCENT_CIRCLE:
1433 case LFUN_ACCENT_OGONEK:
1434 theLyXFunc().handleKeyFunc(cmd.action);
1435 if (!cmd.argument().empty())
1436 // FIXME: Are all these characters encoded in one byte in utf8?
1437 bv->getIntl().getTransManager()
1438 .translateAndInsert(cmd.argument()[0], this, cur);
1441 case LFUN_FLOAT_LIST: {
1442 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1443 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1444 // not quite sure if we want this...
1446 cur.clearSelection();
1447 breakParagraph(cur);
1449 if (cur.lastpos() != 0) {
1451 breakParagraph(cur);
1454 setLayout(cur, tclass.defaultLayoutName());
1455 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, docstring(), 0);
1456 insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1459 lyxerr << "Non-existent float type: "
1460 << to_utf8(cmd.argument()) << endl;
1465 case LFUN_CHANGE_ACCEPT: {
1466 acceptOrRejectChanges(cur, ACCEPT);
1470 case LFUN_CHANGE_REJECT: {
1471 acceptOrRejectChanges(cur, REJECT);
1475 case LFUN_THESAURUS_ENTRY: {
1476 docstring arg = cmd.argument();
1478 arg = cur.selectionAsString(false);
1480 if (arg.size() > 100 || arg.empty()) {
1481 // Get word or selection
1482 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1483 arg = cur.selectionAsString(false);
1486 bv->showDialogWithData("thesaurus", to_utf8(arg));
1490 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1491 // Given data, an encoding of the ParagraphParameters
1492 // generated in the Paragraph dialog, this function sets
1493 // the current paragraph appropriately.
1494 istringstream is(to_utf8(cmd.argument()));
1497 ParagraphParameters params;
1502 params.labelWidthString(),
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 LyXText" << 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 LyXText::erase() and LyXText::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 LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
1576 FuncStatus & flag) const
1578 BOOST_ASSERT(cur.text() == this);
1580 LyXFont const & font = real_current_font;
1582 InsetBase::Code code = InsetBase::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);
1602 case LFUN_DIALOG_SHOW_NEW_INSET:
1603 if (cmd.argument() == "bibitem")
1604 code = InsetBase::BIBITEM_CODE;
1605 else if (cmd.argument() == "bibtex")
1606 code = InsetBase::BIBTEX_CODE;
1607 else if (cmd.argument() == "box")
1608 code = InsetBase::BOX_CODE;
1609 else if (cmd.argument() == "branch")
1610 code = InsetBase::BRANCH_CODE;
1611 else if (cmd.argument() == "citation")
1612 code = InsetBase::CITE_CODE;
1613 else if (cmd.argument() == "ert")
1614 code = InsetBase::ERT_CODE;
1615 else if (cmd.argument() == "external")
1616 code = InsetBase::EXTERNAL_CODE;
1617 else if (cmd.argument() == "float")
1618 code = InsetBase::FLOAT_CODE;
1619 else if (cmd.argument() == "graphics")
1620 code = InsetBase::GRAPHICS_CODE;
1621 else if (cmd.argument() == "include")
1622 code = InsetBase::INCLUDE_CODE;
1623 else if (cmd.argument() == "index")
1624 code = InsetBase::INDEX_CODE;
1625 else if (cmd.argument() == "nomenclature")
1626 code = InsetBase::NOMENCL_CODE;
1627 else if (cmd.argument() == "label")
1628 code = InsetBase::LABEL_CODE;
1629 else if (cmd.argument() == "note")
1630 code = InsetBase::NOTE_CODE;
1631 else if (cmd.argument() == "ref")
1632 code = InsetBase::REF_CODE;
1633 else if (cmd.argument() == "toc")
1634 code = InsetBase::TOC_CODE;
1635 else if (cmd.argument() == "url")
1636 code = InsetBase::URL_CODE;
1637 else if (cmd.argument() == "vspace")
1638 code = InsetBase::VSPACE_CODE;
1639 else if (cmd.argument() == "wrap")
1640 code = InsetBase::WRAP_CODE;
1643 case LFUN_ERT_INSERT:
1644 code = InsetBase::ERT_CODE;
1646 case LFUN_FOOTNOTE_INSERT:
1647 code = InsetBase::FOOT_CODE;
1649 case LFUN_TABULAR_INSERT:
1650 code = InsetBase::TABULAR_CODE;
1652 case LFUN_MARGINALNOTE_INSERT:
1653 code = InsetBase::MARGIN_CODE;
1655 case LFUN_FLOAT_INSERT:
1656 case LFUN_FLOAT_WIDE_INSERT:
1657 code = InsetBase::FLOAT_CODE;
1659 case LFUN_WRAP_INSERT:
1660 code = InsetBase::WRAP_CODE;
1662 case LFUN_FLOAT_LIST:
1663 code = InsetBase::FLOAT_LIST_CODE;
1666 case LFUN_LIST_INSERT:
1667 code = InsetBase::LIST_CODE;
1669 case LFUN_THEOREM_INSERT:
1670 code = InsetBase::THEOREM_CODE;
1673 case LFUN_CAPTION_INSERT:
1674 code = InsetBase::CAPTION_CODE;
1676 case LFUN_NOTE_INSERT:
1677 code = InsetBase::NOTE_CODE;
1679 case LFUN_CHARSTYLE_INSERT:
1680 code = InsetBase::CHARSTYLE_CODE;
1681 if (cur.buffer().params().getLyXTextClass().charstyles().empty())
1684 case LFUN_BOX_INSERT:
1685 code = InsetBase::BOX_CODE;
1687 case LFUN_BRANCH_INSERT:
1688 code = InsetBase::BRANCH_CODE;
1689 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1692 case LFUN_LABEL_INSERT:
1693 code = InsetBase::LABEL_CODE;
1695 case LFUN_OPTIONAL_INSERT:
1696 code = InsetBase::OPTARG_CODE;
1697 enable = numberOfOptArgs(cur.paragraph())
1698 < cur.paragraph().layout()->optionalargs;
1700 case LFUN_ENVIRONMENT_INSERT:
1701 code = InsetBase::BOX_CODE;
1703 case LFUN_INDEX_INSERT:
1704 code = InsetBase::INDEX_CODE;
1706 case LFUN_INDEX_PRINT:
1707 code = InsetBase::INDEX_PRINT_CODE;
1709 case LFUN_NOMENCL_INSERT:
1710 code = InsetBase::NOMENCL_CODE;
1712 case LFUN_NOMENCL_PRINT:
1713 code = InsetBase::NOMENCL_PRINT_CODE;
1715 case LFUN_TOC_INSERT:
1716 code = InsetBase::TOC_CODE;
1718 case LFUN_HTML_INSERT:
1719 case LFUN_URL_INSERT:
1720 code = InsetBase::URL_CODE;
1722 case LFUN_QUOTE_INSERT:
1723 // always allow this, since we will inset a raw quote
1724 // if an inset is not allowed.
1726 case LFUN_HYPHENATION_POINT_INSERT:
1727 case LFUN_LIGATURE_BREAK_INSERT:
1728 case LFUN_HFILL_INSERT:
1729 case LFUN_MENU_SEPARATOR_INSERT:
1730 case LFUN_DOTS_INSERT:
1731 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
1732 code = InsetBase::SPECIALCHAR_CODE;
1734 case LFUN_SPACE_INSERT:
1735 // slight hack: we know this is allowed in math mode
1737 code = InsetBase::SPACE_CODE;
1740 case LFUN_INSET_MODIFY:
1741 // We need to disable this, because we may get called for a
1743 // InsetTabular::getStatus() -> InsetText::getStatus()
1744 // and we don't handle LFUN_INSET_MODIFY.
1748 case LFUN_FONT_EMPH:
1749 flag.setOnOff(font.emph() == LyXFont::ON);
1752 case LFUN_FONT_NOUN:
1753 flag.setOnOff(font.noun() == LyXFont::ON);
1756 case LFUN_FONT_BOLD:
1757 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
1760 case LFUN_FONT_SANS:
1761 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
1764 case LFUN_FONT_ROMAN:
1765 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
1768 case LFUN_FONT_CODE:
1769 flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
1774 enable = cur.selection();
1778 if (cmd.argument().empty()) {
1779 if (theClipboard().isInternal())
1780 enable = cap::numberOfSelections() > 0;
1782 enable = !theClipboard().empty();
1784 string const arg = to_utf8(cmd.argument());
1785 if (isStrUnsignedInt(arg)) {
1786 unsigned int n = convert<unsigned int>(arg);
1787 enable = cap::numberOfSelections() > n;
1794 case LFUN_CLIPBOARD_PASTE:
1795 enable = !theClipboard().empty();
1798 case LFUN_PRIMARY_SELECTION_PASTE:
1799 enable = cur.selection() || !theSelection().empty();
1802 case LFUN_PARAGRAPH_MOVE_UP:
1803 enable = cur.pit() > 0 && !cur.selection();
1806 case LFUN_PARAGRAPH_MOVE_DOWN:
1807 enable = cur.pit() < cur.lastpit() && !cur.selection();
1810 case LFUN_INSET_DISSOLVE:
1811 enable = !isMainText(*cur.bv().buffer()) && cur.inset().nargs() == 1;
1814 case LFUN_CHANGE_ACCEPT:
1815 case LFUN_CHANGE_REJECT:
1816 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
1817 // In principle, these LFUNs should only be enabled if there
1818 // is a change at the current position/in the current selection.
1819 // However, without proper optimizations, this will inevitably
1820 // result in unacceptable performance - just imagine a user who
1821 // wants to select the complete content of a long document.
1825 case LFUN_WORD_DELETE_FORWARD:
1826 case LFUN_WORD_DELETE_BACKWARD:
1827 case LFUN_LINE_DELETE:
1828 case LFUN_WORD_FORWARD:
1829 case LFUN_WORD_BACKWARD:
1830 case LFUN_CHAR_FORWARD:
1831 case LFUN_CHAR_FORWARD_SELECT:
1832 case LFUN_CHAR_BACKWARD:
1833 case LFUN_CHAR_BACKWARD_SELECT:
1835 case LFUN_UP_SELECT:
1837 case LFUN_DOWN_SELECT:
1838 case LFUN_PARAGRAPH_UP_SELECT:
1839 case LFUN_PARAGRAPH_DOWN_SELECT:
1840 case LFUN_SCREEN_UP_SELECT:
1841 case LFUN_SCREEN_DOWN_SELECT:
1842 case LFUN_LINE_BEGIN_SELECT:
1843 case LFUN_LINE_END_SELECT:
1844 case LFUN_WORD_FORWARD_SELECT:
1845 case LFUN_WORD_BACKWARD_SELECT:
1846 case LFUN_WORD_SELECT:
1847 case LFUN_PARAGRAPH_UP:
1848 case LFUN_PARAGRAPH_DOWN:
1849 case LFUN_SCREEN_UP:
1850 case LFUN_SCREEN_DOWN:
1851 case LFUN_LINE_BEGIN:
1853 case LFUN_BREAK_LINE:
1854 case LFUN_CHAR_DELETE_FORWARD:
1855 case LFUN_DELETE_FORWARD_SKIP:
1856 case LFUN_CHAR_DELETE_BACKWARD:
1857 case LFUN_DELETE_BACKWARD_SKIP:
1858 case LFUN_BREAK_PARAGRAPH:
1859 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
1860 case LFUN_BREAK_PARAGRAPH_SKIP:
1861 case LFUN_PARAGRAPH_SPACING:
1862 case LFUN_INSET_INSERT:
1863 case LFUN_WORD_UPCASE:
1864 case LFUN_WORD_LOWCASE:
1865 case LFUN_WORD_CAPITALIZE:
1866 case LFUN_CHARS_TRANSPOSE:
1867 case LFUN_SERVER_GET_XY:
1868 case LFUN_SERVER_SET_XY:
1869 case LFUN_SERVER_GET_FONT:
1870 case LFUN_SERVER_GET_LAYOUT:
1872 case LFUN_DATE_INSERT:
1873 case LFUN_SELF_INSERT:
1874 case LFUN_LINE_INSERT:
1875 case LFUN_PAGEBREAK_INSERT:
1876 case LFUN_CLEARPAGE_INSERT:
1877 case LFUN_CLEARDOUBLEPAGE_INSERT:
1878 case LFUN_MATH_DISPLAY:
1879 case LFUN_MATH_IMPORT_SELECTION:
1880 case LFUN_MATH_MODE:
1881 case LFUN_MATH_MACRO:
1882 case LFUN_MATH_MATRIX:
1883 case LFUN_MATH_DELIM:
1884 case LFUN_MATH_BIGDELIM:
1885 case LFUN_MATH_SUBSCRIPT:
1886 case LFUN_MATH_SUPERSCRIPT:
1887 case LFUN_FONT_DEFAULT:
1888 case LFUN_FONT_UNDERLINE:
1889 case LFUN_FONT_SIZE:
1891 case LFUN_FONT_FREE_APPLY:
1892 case LFUN_FONT_FREE_UPDATE:
1893 case LFUN_LAYOUT_PARAGRAPH:
1894 case LFUN_PARAGRAPH_UPDATE:
1895 case LFUN_ACCENT_UMLAUT:
1896 case LFUN_ACCENT_CIRCUMFLEX:
1897 case LFUN_ACCENT_GRAVE:
1898 case LFUN_ACCENT_ACUTE:
1899 case LFUN_ACCENT_TILDE:
1900 case LFUN_ACCENT_CEDILLA:
1901 case LFUN_ACCENT_MACRON:
1902 case LFUN_ACCENT_DOT:
1903 case LFUN_ACCENT_UNDERDOT:
1904 case LFUN_ACCENT_UNDERBAR:
1905 case LFUN_ACCENT_CARON:
1906 case LFUN_ACCENT_SPECIAL_CARON:
1907 case LFUN_ACCENT_BREVE:
1908 case LFUN_ACCENT_TIE:
1909 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1910 case LFUN_ACCENT_CIRCLE:
1911 case LFUN_ACCENT_OGONEK:
1912 case LFUN_THESAURUS_ENTRY:
1913 case LFUN_PARAGRAPH_PARAMS_APPLY:
1915 case LFUN_BUFFER_END:
1916 case LFUN_BUFFER_BEGIN:
1917 case LFUN_BUFFER_BEGIN_SELECT:
1918 case LFUN_BUFFER_END_SELECT:
1919 case LFUN_UNICODE_INSERT:
1920 // these are handled in our dispatch()
1928 if (code != InsetBase::NO_CODE
1929 && (cur.empty() || !cur.inset().insetAllowed(code)))
1932 flag.enabled(enable);
1937 void LyXText::pasteString(LCursor & cur, docstring const & clip,
1940 cur.clearSelection();
1941 if (!clip.empty()) {
1944 insertStringAsParagraphs(cur, clip);
1946 insertStringAsLines(cur, clip);