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::pasteFromStack;
80 using cap::pasteClipboard;
81 using cap::replaceSelection;
82 using cap::saveSelection;
84 using support::isStrUnsignedInt;
89 using std::istringstream;
90 using std::ostringstream;
93 extern string current_layout;
99 LyXFont freefont(LyXFont::ALL_IGNORE);
100 bool toggleall = false;
103 void toggleAndShow(LCursor & cur, LyXText * text,
104 LyXFont const & font, bool toggleall = true)
106 text->toggleFree(cur, font, toggleall);
108 if (font.language() != ignore_language ||
109 font.number() != LyXFont::IGNORE) {
110 Paragraph & par = cur.paragraph();
111 text->bidi.computeTables(par, cur.buffer(), cur.textRow());
112 if (cur.boundary() !=
113 text->bidi.isBoundary(cur.buffer(), par,
115 text->real_current_font))
116 text->setCursor(cur, cur.pit(), cur.pos(),
117 false, !cur.boundary());
122 void moveCursor(LCursor & cur, bool selecting)
124 if (selecting || cur.mark())
127 cur.bv().switchKeyMap();
131 void finishChange(LCursor & cur, bool selecting)
134 moveCursor(cur, selecting);
138 void mathDispatch(LCursor & cur, FuncRequest const & cmd, bool display)
141 docstring sel = cur.selectionAsString(false);
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);
441 case LFUN_CHAR_BACKWARD:
442 case LFUN_CHAR_BACKWARD_SELECT:
443 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
444 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
445 if (isRTL(*cur.bv().buffer(), cur.paragraph()))
446 needsUpdate |= cursorRight(cur);
448 needsUpdate |= cursorLeft(cur);
450 if (!needsUpdate && oldTopSlice == cur.top()
451 && cur.boundary() == oldBoundary) {
453 cmd = FuncRequest(LFUN_FINISHED_LEFT);
461 //lyxerr << "handle LFUN_UP[SEL]:\n" << cur << endl;
462 needsUpdate |= cur.selHandle(cmd.action == LFUN_UP_SELECT);
464 needsUpdate |= cursorUp(cur);
466 if (!needsUpdate && oldTopSlice == cur.top()
467 && cur.boundary() == oldBoundary) {
469 cmd = FuncRequest(LFUN_FINISHED_UP);
476 case LFUN_DOWN_SELECT:
477 //lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
478 needsUpdate |= cur.selHandle(cmd.action == LFUN_DOWN_SELECT);
479 needsUpdate |= cursorDown(cur);
481 if (!needsUpdate && oldTopSlice == cur.top() &&
482 cur.boundary() == oldBoundary)
485 cmd = FuncRequest(LFUN_FINISHED_DOWN);
491 case LFUN_PARAGRAPH_UP:
492 case LFUN_PARAGRAPH_UP_SELECT:
493 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
494 needsUpdate |= cursorUpParagraph(cur);
499 case LFUN_PARAGRAPH_DOWN:
500 case LFUN_PARAGRAPH_DOWN_SELECT:
501 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
502 needsUpdate |= cursorDownParagraph(cur);
508 case LFUN_SCREEN_UP_SELECT:
509 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_UP_SELECT);
510 if (cur.pit() == 0 && cur.textRow().pos() == 0) {
512 cmd = FuncRequest(LFUN_FINISHED_UP);
520 case LFUN_SCREEN_DOWN:
521 case LFUN_SCREEN_DOWN_SELECT:
522 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_DOWN_SELECT);
523 if (cur.pit() == cur.lastpit()
524 && cur.textRow().endpos() == cur.lastpos()) {
526 cmd = FuncRequest(LFUN_FINISHED_DOWN);
534 case LFUN_LINE_BEGIN:
535 case LFUN_LINE_BEGIN_SELECT:
536 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
537 needsUpdate |= cursorHome(cur);
541 case LFUN_LINE_END_SELECT:
542 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
543 needsUpdate |= cursorEnd(cur);
548 case LFUN_WORD_FORWARD:
549 case LFUN_WORD_FORWARD_SELECT:
550 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
551 if (isRTL(*cur.bv().buffer(), cur.paragraph()))
552 needsUpdate |= cursorLeftOneWord(cur);
554 needsUpdate |= cursorRightOneWord(cur);
559 case LFUN_WORD_BACKWARD:
560 case LFUN_WORD_BACKWARD_SELECT:
561 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
562 if (isRTL(*cur.bv().buffer(), cur.paragraph()))
563 needsUpdate |= cursorRightOneWord(cur);
565 needsUpdate |= cursorLeftOneWord(cur);
570 case LFUN_WORD_SELECT: {
571 selectWord(cur, WHOLE_WORD);
572 finishChange(cur, true);
576 case LFUN_BREAK_LINE: {
577 // Not allowed by LaTeX (labels or empty par)
578 if (cur.pos() > cur.paragraph().beginOfBody()) {
579 if (!cur.selection())
581 cap::replaceSelection(cur);
582 cur.insert(new InsetNewline);
584 moveCursor(cur, false);
589 case LFUN_CHAR_DELETE_FORWARD:
590 if (!cur.selection()) {
591 if (cur.pos() == cur.paragraph().size())
592 // Par boundary, force full-screen update
593 singleParUpdate = false;
594 needsUpdate |= erase(cur);
596 // It is possible to make it a lot faster still
597 // just comment out the line below...
599 cutSelection(cur, true, false);
600 singleParUpdate = false;
602 moveCursor(cur, false);
605 case LFUN_DELETE_FORWARD_SKIP:
606 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
607 if (!cur.selection()) {
608 if (cur.pos() == cur.lastpos()) {
615 cutSelection(cur, true, false);
620 case LFUN_CHAR_DELETE_BACKWARD:
621 if (!cur.selection()) {
622 if (bv->getIntl().getTransManager().backspace()) {
623 // Par boundary, full-screen update
625 singleParUpdate = false;
626 needsUpdate |= backspace(cur);
628 // It is possible to make it a lot faster still
629 // just comment out the line below...
632 cutSelection(cur, true, false);
633 singleParUpdate = false;
638 case LFUN_DELETE_BACKWARD_SKIP:
639 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
640 if (!cur.selection()) {
644 //CursorSlice cur = cursor();
648 cutSelection(cur, true, false);
652 case LFUN_BREAK_PARAGRAPH:
653 cap::replaceSelection(cur);
654 breakParagraph(cur, 0);
659 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
660 cap::replaceSelection(cur);
661 breakParagraph(cur, 1);
666 case LFUN_BREAK_PARAGRAPH_SKIP: {
667 // When at the beginning of a paragraph, remove
668 // indentation. Otherwise, do the same as LFUN_BREAK_PARAGRAPH.
669 cap::replaceSelection(cur);
671 cur.paragraph().params().labelWidthString(docstring());
673 breakParagraph(cur, 0);
679 case LFUN_PARAGRAPH_SPACING: {
680 Paragraph & par = cur.paragraph();
681 Spacing::Space cur_spacing = par.params().spacing().getSpace();
682 string cur_value = "1.0";
683 if (cur_spacing == Spacing::Other)
684 cur_value = par.params().spacing().getValueAsString();
686 istringstream is(to_utf8(cmd.argument()));
689 Spacing::Space new_spacing = cur_spacing;
690 string new_value = cur_value;
692 lyxerr << "Missing argument to `paragraph-spacing'"
694 } else if (tmp == "single") {
695 new_spacing = Spacing::Single;
696 } else if (tmp == "onehalf") {
697 new_spacing = Spacing::Onehalf;
698 } else if (tmp == "double") {
699 new_spacing = Spacing::Double;
700 } else if (tmp == "other") {
701 new_spacing = Spacing::Other;
702 string tmpval = "0.0";
704 lyxerr << "new_value = " << tmpval << endl;
707 } else if (tmp == "default") {
708 new_spacing = Spacing::Default;
710 lyxerr << to_utf8(_("Unknown spacing argument: "))
711 << to_utf8(cmd.argument()) << endl;
713 if (cur_spacing != new_spacing || cur_value != new_value)
714 par.params().spacing(Spacing(new_spacing, new_value));
718 case LFUN_INSET_INSERT: {
720 InsetBase * inset = createInset(bv, cmd);
722 // FIXME (Abdel 01/02/2006):
723 // What follows would be a partial fix for bug 2154:
724 // http://bugzilla.lyx.org/show_bug.cgi?id=2154
725 // This automatically put the label inset _after_ a
726 // numbered section. It should be possible to extend the mechanism
727 // to any kind of LateX environement.
728 // The correct way to fix that bug would be at LateX generation.
729 // I'll let the code here for reference as it could be used for some
730 // other feature like "automatic labelling".
732 Paragraph & par = pars_[cur.pit()];
733 if (inset->lyxCode() == InsetBase::LABEL_CODE
734 && par.layout()->labeltype == LABEL_COUNTER) {
735 // Go to the end of the paragraph
736 // Warning: Because of Change-Tracking, the last
737 // position is 'size()' and not 'size()-1':
738 cur.pos() = par.size();
739 // Insert a new paragraph
740 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
744 insertInset(cur, inset);
750 case LFUN_INSET_DISSOLVE:
751 needsUpdate |= dissolveInset(cur);
754 case LFUN_INSET_SETTINGS:
755 cur.inset().showInsetDialog(bv);
758 case LFUN_SPACE_INSERT:
759 if (cur.paragraph().layout()->free_spacing)
760 insertChar(cur, ' ');
762 doInsertInset(cur, this, cmd, false, false);
765 moveCursor(cur, false);
768 case LFUN_HYPHENATION_POINT_INSERT:
769 specialChar(cur, InsetSpecialChar::HYPHENATION);
772 case LFUN_LIGATURE_BREAK_INSERT:
773 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
776 case LFUN_DOTS_INSERT:
777 specialChar(cur, InsetSpecialChar::LDOTS);
780 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
781 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
784 case LFUN_MENU_SEPARATOR_INSERT:
785 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
788 case LFUN_WORD_UPCASE:
789 changeCase(cur, LyXText::text_uppercase);
792 case LFUN_WORD_LOWCASE:
793 changeCase(cur, LyXText::text_lowercase);
796 case LFUN_WORD_CAPITALIZE:
797 changeCase(cur, LyXText::text_capitalization);
800 case LFUN_CHARS_TRANSPOSE:
805 cur.message(_("Paste"));
806 cap::replaceSelection(cur);
807 if (cmd.argument().empty() && !theClipboard().isInternal())
808 pasteClipboard(cur, bv->buffer()->errorList("Paste"));
810 string const arg(to_utf8(cmd.argument()));
811 pasteFromStack(cur, bv->buffer()->errorList("Paste"),
812 isStrUnsignedInt(arg) ?
813 convert<unsigned int>(arg) :
816 bv->buffer()->errors("Paste");
817 cur.clearSelection(); // bug 393
823 cutSelection(cur, true, true);
824 cur.message(_("Cut"));
829 cur.message(_("Copy"));
832 case LFUN_SERVER_GET_XY:
833 cur.message(from_utf8(
834 convert<string>(cursorX(cur.bv(), cur.top(), cur.boundary()))
835 + ' ' + convert<string>(cursorY(cur.bv(), cur.top(), cur.boundary()))));
838 case LFUN_SERVER_SET_XY: {
841 istringstream is(to_utf8(cmd.argument()));
844 lyxerr << "SETXY: Could not parse coordinates in '"
845 << to_utf8(cmd.argument()) << std::endl;
847 setCursorFromCoordinates(cur, x, y);
851 case LFUN_SERVER_GET_FONT:
852 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
853 cur.message(from_ascii("E"));
854 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
855 cur.message(from_ascii("N"));
857 cur.message(from_ascii("0"));
860 case LFUN_SERVER_GET_LAYOUT:
861 cur.message(from_utf8(cur.paragraph().layout()->name()));
865 string layout = to_ascii(cmd.argument());
866 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) " << layout << endl;
868 // Derive layout number from given argument (string)
869 // and current buffer's textclass (number)
870 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
872 layout = tclass.defaultLayoutName();
873 bool hasLayout = tclass.hasLayout(layout);
875 // If the entry is obsolete, use the new one instead.
877 string const & obs = tclass[layout]->obsoleted_by();
883 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
884 from_utf8(N_(" not known")));
888 bool change_layout = (current_layout != layout);
890 if (!change_layout && cur.selection() &&
891 cur.selBegin().pit() != cur.selEnd().pit())
893 pit_type spit = cur.selBegin().pit();
894 pit_type epit = cur.selEnd().pit() + 1;
895 while (spit != epit) {
896 if (pars_[spit].layout()->name() != current_layout) {
897 change_layout = true;
905 current_layout = layout;
906 setLayout(cur, layout);
907 // inform the GUI that the layout has changed.
908 bv->layoutChanged(layout);
914 case LFUN_CLIPBOARD_PASTE:
915 cur.clearSelection();
916 pasteClipboard(cur, bv->buffer()->errorList("Paste"),
917 cmd.argument() == "paragraph");
918 bv->buffer()->errors("Paste");
921 case LFUN_PRIMARY_SELECTION_PASTE:
922 pasteString(cur, theSelection().get(),
923 cmd.argument() == "paragraph");
926 case LFUN_UNICODE_INSERT: {
927 if (cmd.argument().empty())
929 docstring hexstring = cmd.argument();
930 if (lyx::support::isHex(hexstring)) {
931 char_type c = lyx::support::hexToInt(hexstring);
932 if (c > 32 && c < 0x10ffff) {
933 lyxerr << "Inserting c: " << c << endl;
934 docstring s = docstring(1, c);
935 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
941 case LFUN_QUOTE_INSERT: {
942 cap::replaceSelection(cur);
943 Paragraph & par = cur.paragraph();
944 pos_type pos = cur.pos();
948 else if (cur.prevInset() && cur.prevInset()->isSpace())
951 c = par.getChar(pos - 1);
953 LyXLayout_ptr const & style = par.layout();
955 BufferParams const & bufparams = bv->buffer()->params();
956 if (!style->pass_thru
957 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
958 string arg = to_utf8(cmd.argument());
960 cur.insert(new InsetQuotes(c,
961 bufparams.quotes_language,
962 InsetQuotes::SingleQ));
964 cur.insert(new InsetQuotes(c,
965 bufparams.quotes_language,
966 InsetQuotes::DoubleQ));
970 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
974 case LFUN_DATE_INSERT:
975 if (cmd.argument().empty())
976 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
977 formatted_time(current_time())));
979 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
980 formatted_time(current_time(), to_utf8(cmd.argument()))));
983 case LFUN_MOUSE_TRIPLE:
984 if (cmd.button() == mouse_button::button1) {
994 case LFUN_MOUSE_DOUBLE:
995 if (cmd.button() == mouse_button::button1) {
996 selectWord(cur, WHOLE_WORD_STRICT);
1001 // Single-click on work area
1002 case LFUN_MOUSE_PRESS: {
1003 // Right click on a footnote flag opens float menu
1004 if (cmd.button() == mouse_button::button3)
1005 cur.clearSelection();
1007 // Middle button press pastes if we have a selection
1008 // We do this here as if the selection was inside an inset
1009 // it could get cleared on the unlocking of the inset so
1010 // we have to check this first
1011 bool paste_internally = false;
1012 if (cmd.button() == mouse_button::button2 && cap::selection()) {
1013 // Copy the selection buffer to the clipboard
1014 // stack, because we want it to appear in the
1015 // "Edit->Paste recent" menu.
1016 cap::copySelectionToStack();
1017 paste_internally = true;
1020 // we have to update after dePM triggered
1021 bool update = bv->mouseSetCursor(cur);
1023 // Insert primary selection with middle mouse
1024 // if there is a local selection in the current buffer,
1026 if (cmd.button() == mouse_button::button2) {
1027 if (paste_internally) {
1028 cap::pasteSelection(cur, bv->buffer()->errorList("Paste"));
1029 bv->buffer()->errors("Paste");
1030 cur.clearSelection(); // bug 393
1034 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
1037 if (!update && cmd.button() == mouse_button::button1) {
1038 needsUpdate = false;
1045 case LFUN_MOUSE_MOTION: {
1046 // Only use motion with button 1
1047 //if (cmd.button() != mouse_button::button1)
1050 // ignore motions deeper nested than the real anchor
1051 LCursor & bvcur = cur.bv().cursor();
1052 if (bvcur.anchor_.hasPart(cur)) {
1053 CursorSlice old = bvcur.top();
1055 int const wh = bv->workHeight();
1056 int const y = std::max(0, std::min(wh - 1, cmd.y));
1058 setCursorFromCoordinates(cur, cmd.x, y);
1059 cur.x_target() = cmd.x;
1061 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1063 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1064 // This is to allow jumping over large insets
1065 if (cur.top() == old) {
1067 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1069 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1072 if (cur.top() == old)
1075 // don't set anchor_
1076 bvcur.setCursor(cur);
1077 bvcur.selection() = true;
1078 //lyxerr << "MOTION: " << bv->cursor() << endl;
1086 case LFUN_MOUSE_RELEASE: {
1087 if (cmd.button() == mouse_button::button2)
1090 if (cmd.button() == mouse_button::button1) {
1091 // if there is new selection, update persistent
1092 // selection, otherwise, single click does not
1093 // clear persistent selection buffer
1094 if (cur.selection()) {
1096 // if double click, cur is moved to the end of word by selectWord
1097 // but bvcur is current mouse position
1098 LCursor & bvcur = cur.bv().cursor();
1099 bvcur.selection() = true;
1100 saveSelection(bvcur);
1102 needsUpdate = false;
1110 case LFUN_SELF_INSERT: {
1111 if (cmd.argument().empty())
1114 // Automatically delete the currently selected
1115 // text and replace it with what is being
1116 // typed in now. Depends on lyxrc settings
1117 // "auto_region_delete", which defaults to
1120 if (lyxrc.auto_region_delete)
1121 if (cur.selection())
1122 cutSelection(cur, false, false);
1124 cur.clearSelection();
1125 LyXFont const old_font = real_current_font;
1127 docstring::const_iterator cit = cmd.argument().begin();
1128 docstring::const_iterator end = cmd.argument().end();
1129 for (; cit != end; ++cit)
1131 bv->getIntl().getTransManager().
1132 translateAndInsert(*cit, this);
1134 insertChar(bv->cursor(), *cit);
1138 moveCursor(cur, false);
1142 case LFUN_URL_INSERT: {
1143 InsetCommandParams p("url");
1144 string const data = InsetCommandMailer::params2string("url", p);
1145 bv->showInsetDialog("url", data, 0);
1149 case LFUN_HTML_INSERT: {
1150 InsetCommandParams p("htmlurl");
1151 string const data = InsetCommandMailer::params2string("url", p);
1152 bv->showInsetDialog("url", data, 0);
1156 case LFUN_LABEL_INSERT: {
1157 InsetCommandParams p("label");
1158 // Try to generate a valid label
1159 p["name"] = (cmd.argument().empty()) ?
1160 cur.getPossibleLabel() :
1162 string const data = InsetCommandMailer::params2string("label", p);
1164 if (cmd.argument().empty()) {
1165 bv->showInsetDialog("label", data, 0);
1167 FuncRequest fr(LFUN_INSET_INSERT, data);
1175 case LFUN_LIST_INSERT:
1176 case LFUN_THEOREM_INSERT:
1178 case LFUN_CAPTION_INSERT:
1179 // Open the inset, and move the current selection
1181 doInsertInset(cur, this, cmd, true, true);
1183 updateLabels(*bv->buffer());
1185 case LFUN_NOTE_INSERT:
1186 case LFUN_CHARSTYLE_INSERT:
1187 case LFUN_BOX_INSERT:
1188 case LFUN_BRANCH_INSERT:
1189 case LFUN_BIBITEM_INSERT:
1190 case LFUN_ERT_INSERT:
1191 case LFUN_FOOTNOTE_INSERT:
1192 case LFUN_MARGINALNOTE_INSERT:
1193 case LFUN_OPTIONAL_INSERT:
1194 case LFUN_ENVIRONMENT_INSERT:
1195 // Open the inset, and move the current selection
1197 doInsertInset(cur, this, cmd, true, true);
1201 case LFUN_TABULAR_INSERT:
1202 // if there were no arguments, just open the dialog
1203 if (doInsertInset(cur, this, cmd, false, true))
1206 bv->showDialog("tabularcreate");
1210 case LFUN_FLOAT_INSERT:
1211 case LFUN_FLOAT_WIDE_INSERT:
1212 case LFUN_WRAP_INSERT: {
1213 doInsertInset(cur, this, cmd, true, true);
1215 ParagraphList & pars = cur.text()->paragraphs();
1216 // We create two additional empty paragraphs so that the
1217 // user can choose where to put the graphics (or table).
1218 pars.push_back(pars[0]);
1219 pars.push_back(pars[0]);
1220 // Now that we have three paragraphs, we reposition the cursor
1221 // at the beginning of the second one.
1224 cur.dispatch(FuncRequest(LFUN_CAPTION_INSERT));
1225 // FIXME: When leaving the Float (or Wrap) inset we should
1226 // delete any empty paragraph left above or below the
1231 case LFUN_INDEX_INSERT:
1232 case LFUN_NOMENCL_INSERT: {
1233 InsetBase * inset = createInset(&cur.bv(), cmd);
1238 cur.clearSelection();
1239 insertInset(cur, inset);
1240 inset->edit(cur, true);
1241 // Show the dialog for the nomenclature entry, since the
1242 // description entry still needs to be filled in.
1243 if (cmd.action == LFUN_NOMENCL_INSERT)
1244 InsetCommandMailer("nomenclature",
1245 *reinterpret_cast<InsetCommand *>(inset)).showDialog(&cur.bv());
1250 case LFUN_INDEX_PRINT:
1251 case LFUN_NOMENCL_PRINT:
1252 case LFUN_TOC_INSERT:
1253 case LFUN_HFILL_INSERT:
1254 case LFUN_LINE_INSERT:
1255 case LFUN_PAGEBREAK_INSERT:
1256 case LFUN_CLEARPAGE_INSERT:
1257 case LFUN_CLEARDOUBLEPAGE_INSERT:
1259 doInsertInset(cur, this, cmd, false, false);
1263 case LFUN_DEPTH_DECREMENT:
1264 changeDepth(cur, DEC_DEPTH);
1267 case LFUN_DEPTH_INCREMENT:
1268 changeDepth(cur, INC_DEPTH);
1271 case LFUN_MATH_DISPLAY:
1272 mathDispatch(cur, cmd, true);
1275 case LFUN_MATH_IMPORT_SELECTION:
1276 case LFUN_MATH_MODE:
1277 if (cmd.argument() == "on")
1278 // don't pass "on" as argument
1279 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1281 mathDispatch(cur, cmd, false);
1284 case LFUN_MATH_MACRO:
1285 if (cmd.argument().empty())
1286 cur.errorMessage(from_utf8(N_("Missing argument")));
1288 string s = to_utf8(cmd.argument());
1289 string const s1 = token(s, ' ', 1);
1290 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1291 string const s2 = token(s, ' ', 2);
1292 string const type = s2.empty() ? "newcommand" : s2;
1293 cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, from_utf8(type)));
1294 //cur.nextInset()->edit(cur, true);
1298 // passthrough hat and underscore outside mathed:
1299 case LFUN_MATH_SUBSCRIPT:
1300 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1302 case LFUN_MATH_SUPERSCRIPT:
1303 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1306 case LFUN_MATH_INSERT:
1307 case LFUN_MATH_MATRIX:
1308 case LFUN_MATH_DELIM:
1309 case LFUN_MATH_BIGDELIM: {
1310 cur.insert(new InsetMathHull(hullSimple));
1311 cur.dispatch(FuncRequest(LFUN_CHAR_FORWARD));
1316 case LFUN_FONT_EMPH: {
1317 LyXFont font(LyXFont::ALL_IGNORE);
1318 font.setEmph(LyXFont::TOGGLE);
1319 toggleAndShow(cur, this, font);
1323 case LFUN_FONT_BOLD: {
1324 LyXFont font(LyXFont::ALL_IGNORE);
1325 font.setSeries(LyXFont::BOLD_SERIES);
1326 toggleAndShow(cur, this, font);
1330 case LFUN_FONT_NOUN: {
1331 LyXFont font(LyXFont::ALL_IGNORE);
1332 font.setNoun(LyXFont::TOGGLE);
1333 toggleAndShow(cur, this, font);
1337 case LFUN_FONT_CODE: {
1338 LyXFont font(LyXFont::ALL_IGNORE);
1339 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1340 toggleAndShow(cur, this, font);
1344 case LFUN_FONT_SANS: {
1345 LyXFont font(LyXFont::ALL_IGNORE);
1346 font.setFamily(LyXFont::SANS_FAMILY);
1347 toggleAndShow(cur, this, font);
1351 case LFUN_FONT_ROMAN: {
1352 LyXFont font(LyXFont::ALL_IGNORE);
1353 font.setFamily(LyXFont::ROMAN_FAMILY);
1354 toggleAndShow(cur, this, font);
1358 case LFUN_FONT_DEFAULT: {
1359 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1360 toggleAndShow(cur, this, font);
1364 case LFUN_FONT_UNDERLINE: {
1365 LyXFont font(LyXFont::ALL_IGNORE);
1366 font.setUnderbar(LyXFont::TOGGLE);
1367 toggleAndShow(cur, this, font);
1371 case LFUN_FONT_SIZE: {
1372 LyXFont font(LyXFont::ALL_IGNORE);
1373 font.setLyXSize(to_utf8(cmd.argument()));
1374 toggleAndShow(cur, this, font);
1378 case LFUN_LANGUAGE: {
1379 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1382 LyXFont font(LyXFont::ALL_IGNORE);
1383 font.setLanguage(lang);
1384 toggleAndShow(cur, this, font);
1389 case LFUN_FONT_FREE_APPLY:
1390 toggleAndShow(cur, this, freefont, toggleall);
1391 cur.message(_("Character set"));
1394 // Set the freefont using the contents of \param data dispatched from
1395 // the frontends and apply it at the current cursor location.
1396 case LFUN_FONT_FREE_UPDATE: {
1399 if (bv_funcs::string2font(to_utf8(cmd.argument()), font, toggle)) {
1402 toggleAndShow(cur, this, freefont, toggleall);
1403 cur.message(_("Character set"));
1408 case LFUN_FINISHED_LEFT:
1409 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1412 case LFUN_FINISHED_RIGHT:
1413 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1417 case LFUN_FINISHED_UP:
1418 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_UP:\n" << cur << endl;
1422 case LFUN_FINISHED_DOWN:
1423 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_DOWN:\n" << cur << endl;
1427 case LFUN_LAYOUT_PARAGRAPH: {
1429 params2string(cur.paragraph(), data);
1430 data = "show\n" + data;
1431 bv->showDialogWithData("paragraph", data);
1435 case LFUN_PARAGRAPH_UPDATE: {
1437 params2string(cur.paragraph(), data);
1439 // Will the paragraph accept changes from the dialog?
1440 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1442 data = "update " + convert<string>(accept) + '\n' + data;
1443 bv->updateDialog("paragraph", data);
1447 case LFUN_ACCENT_UMLAUT:
1448 case LFUN_ACCENT_CIRCUMFLEX:
1449 case LFUN_ACCENT_GRAVE:
1450 case LFUN_ACCENT_ACUTE:
1451 case LFUN_ACCENT_TILDE:
1452 case LFUN_ACCENT_CEDILLA:
1453 case LFUN_ACCENT_MACRON:
1454 case LFUN_ACCENT_DOT:
1455 case LFUN_ACCENT_UNDERDOT:
1456 case LFUN_ACCENT_UNDERBAR:
1457 case LFUN_ACCENT_CARON:
1458 case LFUN_ACCENT_SPECIAL_CARON:
1459 case LFUN_ACCENT_BREVE:
1460 case LFUN_ACCENT_TIE:
1461 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1462 case LFUN_ACCENT_CIRCLE:
1463 case LFUN_ACCENT_OGONEK:
1464 theLyXFunc().handleKeyFunc(cmd.action);
1465 if (!cmd.argument().empty())
1466 // FIXME: Are all these characters encoded in one byte in utf8?
1467 bv->getIntl().getTransManager()
1468 .translateAndInsert(cmd.argument()[0], this, cur);
1471 case LFUN_FLOAT_LIST: {
1472 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1473 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1474 // not quite sure if we want this...
1476 cur.clearSelection();
1477 breakParagraph(cur);
1479 if (cur.lastpos() != 0) {
1481 breakParagraph(cur);
1484 setLayout(cur, tclass.defaultLayoutName());
1485 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, docstring(), 0);
1486 insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1489 lyxerr << "Non-existent float type: "
1490 << to_utf8(cmd.argument()) << endl;
1495 case LFUN_CHANGE_ACCEPT: {
1496 acceptOrRejectChanges(cur, ACCEPT);
1500 case LFUN_CHANGE_REJECT: {
1501 acceptOrRejectChanges(cur, REJECT);
1505 case LFUN_THESAURUS_ENTRY: {
1506 docstring arg = cmd.argument();
1508 arg = cur.selectionAsString(false);
1510 if (arg.size() > 100 || arg.empty()) {
1511 // Get word or selection
1512 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1513 arg = cur.selectionAsString(false);
1516 bv->showDialogWithData("thesaurus", to_utf8(arg));
1520 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1521 // Given data, an encoding of the ParagraphParameters
1522 // generated in the Paragraph dialog, this function sets
1523 // the current paragraph appropriately.
1524 istringstream is(to_utf8(cmd.argument()));
1527 ParagraphParameters params;
1532 params.labelWidthString(),
1534 cur.message(_("Paragraph layout set"));
1539 if (cur.selection()) {
1540 cur.selection() = false;
1544 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1549 lyxerr[Debug::ACTION]
1550 << BOOST_CURRENT_FUNCTION
1551 << ": Command " << cmd
1552 << " not DISPATCHED by LyXText" << endl;
1557 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1559 // FIXME: The cursor flag is reset two lines below
1560 // so we need to check here if some of the LFUN did touch that.
1561 // for now only LyXText::erase() and LyXText::backspace() do that.
1562 // The plan is to verify all the LFUNs and then to remove this
1563 // singleParUpdate boolean altogether.
1564 if (cur.result().update() & Update::Force) {
1565 singleParUpdate = false;
1569 // FIXME: the following code should go in favor of fine grained
1570 // update flag treatment.
1571 if (singleParUpdate) {
1572 // Inserting characters does not change par height
1573 ParagraphMetrics const & pms
1574 = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
1575 if (pms.dim().height()
1576 == olddim.height()) {
1577 // if so, update _only_ this paragraph
1578 cur.updateFlags(Update::SinglePar |
1580 Update::MultiParSel);
1587 && &oldTopSlice.inset() == &cur.inset()
1588 && oldTopSlice.idx() == cur.idx()
1589 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1590 && !cur.selection())
1591 // FIXME: it would be better if we could just do this
1593 //if (cur.result().update() != Update::FitCursor)
1596 // But some LFUNs do not set Update::FitCursor when needed, so we
1597 // do it for all. This is not very harmfull as FitCursor will provoke
1598 // a full redraw only if needed but still, a proper review of all LFUN
1599 // should be done and this needsUpdate boolean can then be removed.
1600 cur.updateFlags(Update::FitCursor);
1602 cur.updateFlags(Update::Force | Update::FitCursor);
1606 bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
1607 FuncStatus & flag) const
1609 BOOST_ASSERT(cur.text() == this);
1611 LyXFont const & font = real_current_font;
1613 InsetBase::Code code = InsetBase::NO_CODE;
1615 switch (cmd.action) {
1617 case LFUN_DEPTH_DECREMENT:
1618 enable = changeDepthAllowed(cur, DEC_DEPTH);
1621 case LFUN_DEPTH_INCREMENT:
1622 enable = changeDepthAllowed(cur, INC_DEPTH);
1626 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1629 case LFUN_BIBITEM_INSERT:
1630 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO);
1633 case LFUN_DIALOG_SHOW_NEW_INSET:
1634 if (cmd.argument() == "bibitem")
1635 code = InsetBase::BIBITEM_CODE;
1636 else if (cmd.argument() == "bibtex")
1637 code = InsetBase::BIBTEX_CODE;
1638 else if (cmd.argument() == "box")
1639 code = InsetBase::BOX_CODE;
1640 else if (cmd.argument() == "branch")
1641 code = InsetBase::BRANCH_CODE;
1642 else if (cmd.argument() == "citation")
1643 code = InsetBase::CITE_CODE;
1644 else if (cmd.argument() == "ert")
1645 code = InsetBase::ERT_CODE;
1646 else if (cmd.argument() == "external")
1647 code = InsetBase::EXTERNAL_CODE;
1648 else if (cmd.argument() == "float")
1649 code = InsetBase::FLOAT_CODE;
1650 else if (cmd.argument() == "graphics")
1651 code = InsetBase::GRAPHICS_CODE;
1652 else if (cmd.argument() == "include")
1653 code = InsetBase::INCLUDE_CODE;
1654 else if (cmd.argument() == "index")
1655 code = InsetBase::INDEX_CODE;
1656 else if (cmd.argument() == "nomenclature")
1657 code = InsetBase::NOMENCL_CODE;
1658 else if (cmd.argument() == "label")
1659 code = InsetBase::LABEL_CODE;
1660 else if (cmd.argument() == "note")
1661 code = InsetBase::NOTE_CODE;
1662 else if (cmd.argument() == "ref")
1663 code = InsetBase::REF_CODE;
1664 else if (cmd.argument() == "toc")
1665 code = InsetBase::TOC_CODE;
1666 else if (cmd.argument() == "url")
1667 code = InsetBase::URL_CODE;
1668 else if (cmd.argument() == "vspace")
1669 code = InsetBase::VSPACE_CODE;
1670 else if (cmd.argument() == "wrap")
1671 code = InsetBase::WRAP_CODE;
1674 case LFUN_ERT_INSERT:
1675 code = InsetBase::ERT_CODE;
1677 case LFUN_FOOTNOTE_INSERT:
1678 code = InsetBase::FOOT_CODE;
1680 case LFUN_TABULAR_INSERT:
1681 code = InsetBase::TABULAR_CODE;
1683 case LFUN_MARGINALNOTE_INSERT:
1684 code = InsetBase::MARGIN_CODE;
1686 case LFUN_FLOAT_INSERT:
1687 case LFUN_FLOAT_WIDE_INSERT:
1688 code = InsetBase::FLOAT_CODE;
1690 case LFUN_WRAP_INSERT:
1691 code = InsetBase::WRAP_CODE;
1693 case LFUN_FLOAT_LIST:
1694 code = InsetBase::FLOAT_LIST_CODE;
1697 case LFUN_LIST_INSERT:
1698 code = InsetBase::LIST_CODE;
1700 case LFUN_THEOREM_INSERT:
1701 code = InsetBase::THEOREM_CODE;
1704 case LFUN_CAPTION_INSERT:
1705 code = InsetBase::CAPTION_CODE;
1707 case LFUN_NOTE_INSERT:
1708 code = InsetBase::NOTE_CODE;
1710 case LFUN_CHARSTYLE_INSERT:
1711 code = InsetBase::CHARSTYLE_CODE;
1712 if (cur.buffer().params().getLyXTextClass().charstyles().empty())
1715 case LFUN_BOX_INSERT:
1716 code = InsetBase::BOX_CODE;
1718 case LFUN_BRANCH_INSERT:
1719 code = InsetBase::BRANCH_CODE;
1720 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1723 case LFUN_LABEL_INSERT:
1724 code = InsetBase::LABEL_CODE;
1726 case LFUN_OPTIONAL_INSERT:
1727 code = InsetBase::OPTARG_CODE;
1728 enable = numberOfOptArgs(cur.paragraph())
1729 < cur.paragraph().layout()->optionalargs;
1731 case LFUN_ENVIRONMENT_INSERT:
1732 code = InsetBase::BOX_CODE;
1734 case LFUN_INDEX_INSERT:
1735 code = InsetBase::INDEX_CODE;
1737 case LFUN_INDEX_PRINT:
1738 code = InsetBase::INDEX_PRINT_CODE;
1740 case LFUN_NOMENCL_INSERT:
1741 code = InsetBase::NOMENCL_CODE;
1743 case LFUN_NOMENCL_PRINT:
1744 code = InsetBase::NOMENCL_PRINT_CODE;
1746 case LFUN_TOC_INSERT:
1747 code = InsetBase::TOC_CODE;
1749 case LFUN_HTML_INSERT:
1750 case LFUN_URL_INSERT:
1751 code = InsetBase::URL_CODE;
1753 case LFUN_QUOTE_INSERT:
1754 // always allow this, since we will inset a raw quote
1755 // if an inset is not allowed.
1757 case LFUN_HYPHENATION_POINT_INSERT:
1758 case LFUN_LIGATURE_BREAK_INSERT:
1759 case LFUN_HFILL_INSERT:
1760 case LFUN_MENU_SEPARATOR_INSERT:
1761 case LFUN_DOTS_INSERT:
1762 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
1763 code = InsetBase::SPECIALCHAR_CODE;
1765 case LFUN_SPACE_INSERT:
1766 // slight hack: we know this is allowed in math mode
1768 code = InsetBase::SPACE_CODE;
1771 case LFUN_INSET_MODIFY:
1772 // We need to disable this, because we may get called for a
1774 // InsetTabular::getStatus() -> InsetText::getStatus()
1775 // and we don't handle LFUN_INSET_MODIFY.
1779 case LFUN_FONT_EMPH:
1780 flag.setOnOff(font.emph() == LyXFont::ON);
1783 case LFUN_FONT_NOUN:
1784 flag.setOnOff(font.noun() == LyXFont::ON);
1787 case LFUN_FONT_BOLD:
1788 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
1791 case LFUN_FONT_SANS:
1792 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
1795 case LFUN_FONT_ROMAN:
1796 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
1799 case LFUN_FONT_CODE:
1800 flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
1805 enable = cur.selection();
1809 if (cmd.argument().empty()) {
1810 if (theClipboard().isInternal())
1811 enable = cap::numberOfSelections() > 0;
1813 enable = !theClipboard().empty();
1815 string const arg = to_utf8(cmd.argument());
1816 if (isStrUnsignedInt(arg)) {
1817 unsigned int n = convert<unsigned int>(arg);
1818 enable = cap::numberOfSelections() > n;
1825 case LFUN_CLIPBOARD_PASTE:
1826 enable = !theClipboard().empty();
1829 case LFUN_PRIMARY_SELECTION_PASTE:
1830 enable = cur.selection() || !theSelection().empty();
1833 case LFUN_PARAGRAPH_MOVE_UP:
1834 enable = cur.pit() > 0 && !cur.selection();
1837 case LFUN_PARAGRAPH_MOVE_DOWN:
1838 enable = cur.pit() < cur.lastpit() && !cur.selection();
1841 case LFUN_INSET_DISSOLVE:
1842 enable = !isMainText(*cur.bv().buffer()) && cur.inset().nargs() == 1;
1845 case LFUN_CHANGE_ACCEPT:
1846 case LFUN_CHANGE_REJECT:
1847 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
1848 // In principle, these LFUNs should only be enabled if there
1849 // is a change at the current position/in the current selection.
1850 // However, without proper optimizations, this will inevitably
1851 // result in unacceptable performance - just imagine a user who
1852 // wants to select the complete content of a long document.
1856 case LFUN_WORD_DELETE_FORWARD:
1857 case LFUN_WORD_DELETE_BACKWARD:
1858 case LFUN_LINE_DELETE:
1859 case LFUN_WORD_FORWARD:
1860 case LFUN_WORD_BACKWARD:
1861 case LFUN_CHAR_FORWARD:
1862 case LFUN_CHAR_FORWARD_SELECT:
1863 case LFUN_CHAR_BACKWARD:
1864 case LFUN_CHAR_BACKWARD_SELECT:
1866 case LFUN_UP_SELECT:
1868 case LFUN_DOWN_SELECT:
1869 case LFUN_PARAGRAPH_UP_SELECT:
1870 case LFUN_PARAGRAPH_DOWN_SELECT:
1871 case LFUN_SCREEN_UP_SELECT:
1872 case LFUN_SCREEN_DOWN_SELECT:
1873 case LFUN_LINE_BEGIN_SELECT:
1874 case LFUN_LINE_END_SELECT:
1875 case LFUN_WORD_FORWARD_SELECT:
1876 case LFUN_WORD_BACKWARD_SELECT:
1877 case LFUN_WORD_SELECT:
1878 case LFUN_PARAGRAPH_UP:
1879 case LFUN_PARAGRAPH_DOWN:
1880 case LFUN_SCREEN_UP:
1881 case LFUN_SCREEN_DOWN:
1882 case LFUN_LINE_BEGIN:
1884 case LFUN_BREAK_LINE:
1885 case LFUN_CHAR_DELETE_FORWARD:
1886 case LFUN_DELETE_FORWARD_SKIP:
1887 case LFUN_CHAR_DELETE_BACKWARD:
1888 case LFUN_DELETE_BACKWARD_SKIP:
1889 case LFUN_BREAK_PARAGRAPH:
1890 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
1891 case LFUN_BREAK_PARAGRAPH_SKIP:
1892 case LFUN_PARAGRAPH_SPACING:
1893 case LFUN_INSET_INSERT:
1894 case LFUN_WORD_UPCASE:
1895 case LFUN_WORD_LOWCASE:
1896 case LFUN_WORD_CAPITALIZE:
1897 case LFUN_CHARS_TRANSPOSE:
1898 case LFUN_SERVER_GET_XY:
1899 case LFUN_SERVER_SET_XY:
1900 case LFUN_SERVER_GET_FONT:
1901 case LFUN_SERVER_GET_LAYOUT:
1903 case LFUN_DATE_INSERT:
1904 case LFUN_SELF_INSERT:
1905 case LFUN_LINE_INSERT:
1906 case LFUN_PAGEBREAK_INSERT:
1907 case LFUN_CLEARPAGE_INSERT:
1908 case LFUN_CLEARDOUBLEPAGE_INSERT:
1909 case LFUN_MATH_DISPLAY:
1910 case LFUN_MATH_IMPORT_SELECTION:
1911 case LFUN_MATH_MODE:
1912 case LFUN_MATH_MACRO:
1913 case LFUN_MATH_MATRIX:
1914 case LFUN_MATH_DELIM:
1915 case LFUN_MATH_BIGDELIM:
1916 case LFUN_MATH_SUBSCRIPT:
1917 case LFUN_MATH_SUPERSCRIPT:
1918 case LFUN_FONT_DEFAULT:
1919 case LFUN_FONT_UNDERLINE:
1920 case LFUN_FONT_SIZE:
1922 case LFUN_FONT_FREE_APPLY:
1923 case LFUN_FONT_FREE_UPDATE:
1924 case LFUN_LAYOUT_PARAGRAPH:
1925 case LFUN_PARAGRAPH_UPDATE:
1926 case LFUN_ACCENT_UMLAUT:
1927 case LFUN_ACCENT_CIRCUMFLEX:
1928 case LFUN_ACCENT_GRAVE:
1929 case LFUN_ACCENT_ACUTE:
1930 case LFUN_ACCENT_TILDE:
1931 case LFUN_ACCENT_CEDILLA:
1932 case LFUN_ACCENT_MACRON:
1933 case LFUN_ACCENT_DOT:
1934 case LFUN_ACCENT_UNDERDOT:
1935 case LFUN_ACCENT_UNDERBAR:
1936 case LFUN_ACCENT_CARON:
1937 case LFUN_ACCENT_SPECIAL_CARON:
1938 case LFUN_ACCENT_BREVE:
1939 case LFUN_ACCENT_TIE:
1940 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1941 case LFUN_ACCENT_CIRCLE:
1942 case LFUN_ACCENT_OGONEK:
1943 case LFUN_THESAURUS_ENTRY:
1944 case LFUN_PARAGRAPH_PARAMS_APPLY:
1946 case LFUN_BUFFER_END:
1947 case LFUN_BUFFER_BEGIN:
1948 case LFUN_BUFFER_BEGIN_SELECT:
1949 case LFUN_BUFFER_END_SELECT:
1950 case LFUN_UNICODE_INSERT:
1951 // these are handled in our dispatch()
1959 if (code != InsetBase::NO_CODE
1960 && (cur.empty() || !cur.inset().insetAllowed(code)))
1963 flag.enabled(enable);
1968 void LyXText::pasteString(LCursor & cur, docstring const & clip,
1971 cur.clearSelection();
1972 if (!clip.empty()) {
1975 insertStringAsParagraphs(cur, clip);
1977 insertStringAsLines(cur, clip);