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"
30 #include "DispatchResult.h"
31 #include "ErrorList.h"
33 #include "FuncRequest.h"
34 #include "InsetList.h"
38 #include "LyXAction.h"
42 #include "Paragraph.h"
43 #include "paragraph_funcs.h"
44 #include "ParagraphParameters.h"
45 #include "TextClass.h"
46 #include "TextMetrics.h"
49 #include "frontends/Application.h"
50 #include "frontends/Clipboard.h"
51 #include "frontends/LyXView.h"
52 #include "frontends/Selection.h"
53 #include "frontends/WorkArea.h"
55 #include "insets/InsetCollapsable.h"
56 #include "insets/InsetCommand.h"
57 #include "insets/InsetExternal.h"
58 #include "insets/InsetFloatList.h"
59 #include "insets/InsetGraphics.h"
60 #include "insets/InsetGraphicsParams.h"
61 #include "insets/InsetNewline.h"
62 #include "insets/InsetQuotes.h"
63 #include "insets/InsetSpecialChar.h"
64 #include "insets/InsetText.h"
66 #include "support/convert.h"
67 #include "support/debug.h"
68 #include "support/gettext.h"
69 #include "support/lstrings.h"
70 #include "support/lyxtime.h"
71 #include "support/os.h"
73 #include "mathed/InsetMathHull.h"
74 #include "mathed/MathMacroTemplate.h"
76 #include <boost/next_prior.hpp>
82 using namespace lyx::support;
86 using cap::copySelection;
87 using cap::cutSelection;
88 using cap::pasteFromStack;
89 using cap::pasteClipboardText;
90 using cap::pasteClipboardGraphics;
91 using cap::replaceSelection;
92 using cap::grabAndEraseSelection;
93 using cap::selClearOrDel;
96 static Font freefont(ignore_font, ignore_language);
97 static bool toggleall = false;
99 static void toggleAndShow(Cursor & cur, Text * text,
100 Font const & font, bool toggleall = true)
102 text->toggleFree(cur, font, toggleall);
104 if (font.language() != ignore_language ||
105 font.fontInfo().number() != FONT_IGNORE) {
106 TextMetrics const & tm = cur.bv().textMetrics(text);
107 if (cur.boundary() != tm.isRTLBoundary(cur.pit(), cur.pos(),
108 cur.real_current_font))
109 text->setCursor(cur, cur.pit(), cur.pos(),
110 false, !cur.boundary());
115 static void moveCursor(Cursor & cur, bool selecting)
117 if (selecting || cur.mark())
122 static void finishChange(Cursor & cur, bool selecting)
125 moveCursor(cur, selecting);
129 static void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
132 docstring sel = cur.selectionAsString(false);
134 // It may happen that sel is empty but there is a selection
135 replaceSelection(cur);
137 // Is this a valid formula?
141 #ifdef ENABLE_ASSERTIONS
142 const int old_pos = cur.pos();
144 cur.insert(new InsetMathHull(hullSimple));
145 #ifdef ENABLE_ASSERTIONS
146 LASSERT(old_pos == cur.pos(), /**/);
148 cur.nextInset()->edit(cur, true);
149 // don't do that also for LFUN_MATH_MODE
150 // unless you want end up with always changing
151 // to mathrm when opening an inlined inset --
152 // I really hate "LyXfunc overloading"...
154 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
155 // Avoid an unnecessary undo step if cmd.argument
157 if (!cmd.argument().empty())
158 cur.dispatch(FuncRequest(LFUN_MATH_INSERT,
161 // create a macro if we see "\\newcommand"
162 // somewhere, and an ordinary formula
164 if (sel.find(from_ascii("\\newcommand")) == string::npos
165 && sel.find(from_ascii("\\newlyxcommand")) == string::npos
166 && sel.find(from_ascii("\\def")) == string::npos)
168 InsetMathHull * formula = new InsetMathHull;
169 string const selstr = to_utf8(sel);
170 istringstream is(selstr);
173 if (!formula->readQuiet(lex)) {
174 // No valid formula, let's try with delims
175 is.str("$" + selstr + "$");
177 if (!formula->readQuiet(lex)) {
178 // Still not valid, leave it as is
187 cur.insert(new MathMacroTemplate(sel));
191 cur.message(from_utf8(N_("Math editor mode")));
193 cur.message(from_utf8(N_("No valid math formula")));
197 void regexpDispatch(Cursor & cur, FuncRequest const & cmd)
199 BOOST_ASSERT(cmd.action == LFUN_REGEXP_MODE);
200 if (cur.inRegexped()) {
201 cur.message(_("Already in regexp mode"));
205 docstring const save_selection = grabAndEraseSelection(cur);
207 // replaceSelection(cur);
209 cur.insert(new InsetMathHull(hullRegexp));
210 cur.nextInset()->edit(cur, true);
211 cur.niceInsert(save_selection);
213 cur.message(_("Regexp editor mode"));
217 static void specialChar(Cursor & cur, InsetSpecialChar::Kind kind)
220 cap::replaceSelection(cur);
221 cur.insert(new InsetSpecialChar(kind));
226 static bool doInsertInset(Cursor & cur, Text * text,
227 FuncRequest const & cmd, bool edit, bool pastesel)
229 Buffer & buffer = cur.bv().buffer();
230 BufferParams const & bparams = buffer.params();
231 Inset * inset = createInset(buffer, cmd);
235 if (InsetCollapsable * ci = inset->asInsetCollapsable())
236 ci->setLayout(bparams);
239 if (cmd.action == LFUN_INDEX_INSERT) {
240 docstring ds = subst(text->getStringToIndex(cur), '\n', ' ');
241 text->insertInset(cur, inset);
243 inset->edit(cur, true);
244 // Now put this into inset
245 static_cast<InsetCollapsable *>(inset)->
246 text().insertStringAsParagraphs(cur, ds);
251 if (cur.selection()) {
252 cutSelection(cur, false, pastesel);
253 cur.clearSelection();
256 text->insertInset(cur, inset);
259 inset->edit(cur, true);
261 if (!gotsel || !pastesel)
264 pasteFromStack(cur, cur.buffer()->errorList("Paste"), 0);
265 cur.buffer()->errors("Paste");
266 cur.clearSelection(); // bug 393
268 InsetText * insetText = dynamic_cast<InsetText *>(inset);
269 if (insetText && (!insetText->allowMultiPar() || cur.lastpit() == 0)) {
270 // reset first par to default
271 cur.text()->paragraphs().begin()
272 ->setPlainOrDefaultLayout(bparams.documentClass());
275 // Merge multiple paragraphs -- hack
276 while (cur.lastpit() > 0)
277 mergeParagraph(bparams, cur.text()->paragraphs(), 0);
278 cur.leaveInset(*inset);
280 cur.leaveInset(*inset);
281 // reset surrounding par to default
282 DocumentClass const & dc = bparams.documentClass();
283 docstring const layoutname = inset->usePlainLayout()
284 ? dc.plainLayoutName()
285 : dc.defaultLayoutName();
286 text->setLayout(cur, layoutname);
293 string const freefont2string()
295 return freefont.toString(toggleall);
299 /// the type of outline operation
301 OutlineUp, // Move this header with text down
302 OutlineDown, // Move this header with text up
303 OutlineIn, // Make this header deeper
304 OutlineOut // Make this header shallower
308 static void outline(OutlineOp mode, Cursor & cur)
310 Buffer & buf = *cur.buffer();
311 pit_type & pit = cur.pit();
312 ParagraphList & pars = buf.text().paragraphs();
313 ParagraphList::iterator bgn = pars.begin();
314 // The first paragraph of the area to be copied:
315 ParagraphList::iterator start = boost::next(bgn, pit);
316 // The final paragraph of area to be copied:
317 ParagraphList::iterator finish = start;
318 ParagraphList::iterator end = pars.end();
320 DocumentClass const & tc = buf.params().documentClass();
322 int const thistoclevel = start->layout().toclevel;
325 // Move out (down) from this section header
328 // Seek the one (on same level) below
329 for (; finish != end; ++finish) {
330 toclevel = finish->layout().toclevel;
331 if (toclevel != Layout::NOT_IN_TOC && toclevel <= thistoclevel) {
338 if (start == pars.begin())
341 ParagraphList::iterator dest = start;
342 // Move out (up) from this header
345 // Search previous same-level header above
348 toclevel = dest->layout().toclevel;
350 && (toclevel == Layout::NOT_IN_TOC
351 || toclevel > thistoclevel));
352 // Not found; do nothing
353 if (toclevel == Layout::NOT_IN_TOC || toclevel > thistoclevel)
355 pit_type const newpit = distance(bgn, dest);
356 pit_type const len = distance(start, finish);
357 pit_type const deletepit = pit + len;
358 buf.undo().recordUndo(cur, ATOMIC_UNDO, newpit, deletepit - 1);
359 pars.insert(dest, start, finish);
360 start = boost::next(pars.begin(), deletepit);
362 pars.erase(start, finish);
369 // Go one down from *this* header:
370 ParagraphList::iterator dest = boost::next(finish, 1);
371 // Go further down to find header to insert in front of:
372 for (; dest != end; ++dest) {
373 toclevel = dest->layout().toclevel;
374 if (toclevel != Layout::NOT_IN_TOC
375 && toclevel <= thistoclevel) {
379 // One such was found:
380 pit_type newpit = distance(bgn, dest);
381 pit_type const len = distance(start, finish);
382 buf.undo().recordUndo(cur, ATOMIC_UNDO, pit, newpit - 1);
383 pars.insert(dest, start, finish);
384 start = boost::next(bgn, pit);
386 pars.erase(start, finish);
390 pit_type const len = distance(start, finish);
391 buf.undo().recordUndo(cur, ATOMIC_UNDO, pit, pit + len - 1);
392 for (; start != finish; ++start) {
393 toclevel = start->layout().toclevel;
394 if (toclevel == Layout::NOT_IN_TOC)
396 DocumentClass::const_iterator lit = tc.begin();
397 DocumentClass::const_iterator len = tc.end();
398 for (; lit != len; ++lit) {
399 if (lit->toclevel == toclevel + 1 &&
400 start->layout().labeltype == lit->labeltype) {
401 start->setLayout(*lit);
409 pit_type const len = distance(start, finish);
410 buf.undo().recordUndo(cur, ATOMIC_UNDO, pit, pit + len - 1);
411 for (; start != finish; ++start) {
412 toclevel = start->layout().toclevel;
413 if (toclevel == Layout::NOT_IN_TOC)
415 DocumentClass::const_iterator lit = tc.begin();
416 DocumentClass::const_iterator len = tc.end();
417 for (; lit != len; ++lit) {
418 if (lit->toclevel == toclevel - 1 &&
419 start->layout().labeltype == lit->labeltype) {
420 start->setLayout(*lit);
431 void Text::number(Cursor & cur)
433 FontInfo font = ignore_font;
434 font.setNumber(FONT_TOGGLE);
435 toggleAndShow(cur, this, Font(font, ignore_language));
439 bool Text::isRTL(Buffer const & buffer, Paragraph const & par) const
441 return par.isRTL(buffer.params());
445 void Text::dispatch(Cursor & cur, FuncRequest & cmd)
447 LYXERR(Debug::ACTION, "Text::dispatch: cmd: " << cmd);
449 BufferView * bv = &cur.bv();
450 TextMetrics & tm = bv->textMetrics(this);
451 if (!tm.contains(cur.pit())) {
452 lyx::dispatch(FuncRequest(LFUN_SCREEN_SHOW_CURSOR));
453 tm = bv->textMetrics(this);
456 // FIXME: We use the update flag to indicates wether a singlePar or a
457 // full screen update is needed. We reset it here but shall we restore it
461 LASSERT(cur.text() == this, /**/);
462 CursorSlice oldTopSlice = cur.top();
463 bool oldBoundary = cur.boundary();
464 bool sel = cur.selection();
465 // Signals that, even if needsUpdate == false, an update of the
466 // cursor paragraph is required
467 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
468 LyXAction::SingleParUpdate);
469 // Signals that a full-screen update is required
470 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
471 LyXAction::NoUpdate) || singleParUpdate);
473 switch (cmd.action) {
475 case LFUN_PARAGRAPH_MOVE_DOWN: {
476 pit_type const pit = cur.pit();
477 recUndo(cur, pit, pit + 1);
479 swap(pars_[pit], pars_[pit + 1]);
480 cur.buffer()->updateLabels();
486 case LFUN_PARAGRAPH_MOVE_UP: {
487 pit_type const pit = cur.pit();
488 recUndo(cur, pit - 1, pit);
490 swap(pars_[pit], pars_[pit - 1]);
491 cur.buffer()->updateLabels();
497 case LFUN_APPENDIX: {
498 Paragraph & par = cur.paragraph();
499 bool start = !par.params().startOfAppendix();
501 // FIXME: The code below only makes sense at top level.
502 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
503 // ensure that we have only one start_of_appendix in this document
504 // FIXME: this don't work for multipart document!
505 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
506 if (pars_[tmp].params().startOfAppendix()) {
508 pars_[tmp].params().startOfAppendix(false);
514 par.params().startOfAppendix(start);
516 // we can set the refreshing parameters now
517 cur.buffer()->updateLabels();
521 case LFUN_WORD_DELETE_FORWARD:
523 cutSelection(cur, true, false);
525 deleteWordForward(cur);
526 finishChange(cur, false);
529 case LFUN_WORD_DELETE_BACKWARD:
531 cutSelection(cur, true, false);
533 deleteWordBackward(cur);
534 finishChange(cur, false);
537 case LFUN_LINE_DELETE:
539 cutSelection(cur, true, false);
541 tm.deleteLineForward(cur);
542 finishChange(cur, false);
545 case LFUN_BUFFER_BEGIN:
546 case LFUN_BUFFER_BEGIN_SELECT:
547 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
548 if (cur.depth() == 1)
549 needsUpdate |= cursorTop(cur);
552 cur.updateFlags(Update::FitCursor);
555 case LFUN_BUFFER_END:
556 case LFUN_BUFFER_END_SELECT:
557 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
558 if (cur.depth() == 1)
559 needsUpdate |= cursorBottom(cur);
562 cur.updateFlags(Update::FitCursor);
565 case LFUN_INSET_BEGIN:
566 case LFUN_INSET_BEGIN_SELECT:
567 needsUpdate |= cur.selHandle(cmd.action == LFUN_INSET_BEGIN_SELECT);
568 if (cur.depth() == 1 || cur.pos() > 0)
569 needsUpdate |= cursorTop(cur);
572 cur.updateFlags(Update::FitCursor);
576 case LFUN_INSET_END_SELECT:
577 needsUpdate |= cur.selHandle(cmd.action == LFUN_INSET_END_SELECT);
578 if (cur.depth() == 1 || cur.pos() < cur.lastpos())
579 needsUpdate |= cursorBottom(cur);
582 cur.updateFlags(Update::FitCursor);
585 case LFUN_CHAR_FORWARD:
586 case LFUN_CHAR_FORWARD_SELECT:
587 //LYXERR0(" LFUN_CHAR_FORWARD[SEL]:\n" << cur);
588 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
589 needsUpdate |= cursorForward(cur);
591 if (!needsUpdate && oldTopSlice == cur.top()
592 && cur.boundary() == oldBoundary) {
594 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
598 case LFUN_CHAR_BACKWARD:
599 case LFUN_CHAR_BACKWARD_SELECT:
600 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
601 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
602 needsUpdate |= cursorBackward(cur);
604 if (!needsUpdate && oldTopSlice == cur.top()
605 && cur.boundary() == oldBoundary) {
607 cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
612 case LFUN_CHAR_LEFT_SELECT:
613 if (lyxrc.visual_cursor) {
614 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_LEFT_SELECT);
615 needsUpdate |= cursorVisLeft(cur);
616 if (!needsUpdate && oldTopSlice == cur.top()
617 && cur.boundary() == oldBoundary) {
619 cmd = FuncRequest(LFUN_FINISHED_LEFT);
622 if (reverseDirectionNeeded(cur)) {
623 cmd.action = cmd.action == LFUN_CHAR_LEFT_SELECT ?
624 LFUN_CHAR_FORWARD_SELECT : LFUN_CHAR_FORWARD;
626 cmd.action = cmd.action == LFUN_CHAR_LEFT_SELECT ?
627 LFUN_CHAR_BACKWARD_SELECT : LFUN_CHAR_BACKWARD;
634 case LFUN_CHAR_RIGHT:
635 case LFUN_CHAR_RIGHT_SELECT:
636 if (lyxrc.visual_cursor) {
637 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_RIGHT_SELECT);
638 needsUpdate |= cursorVisRight(cur);
639 if (!needsUpdate && oldTopSlice == cur.top()
640 && cur.boundary() == oldBoundary) {
642 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
645 if (reverseDirectionNeeded(cur)) {
646 cmd.action = cmd.action == LFUN_CHAR_RIGHT_SELECT ?
647 LFUN_CHAR_BACKWARD_SELECT : LFUN_CHAR_BACKWARD;
649 cmd.action = cmd.action == LFUN_CHAR_RIGHT_SELECT ?
650 LFUN_CHAR_FORWARD_SELECT : LFUN_CHAR_FORWARD;
659 case LFUN_DOWN_SELECT:
662 // stop/start the selection
663 bool select = cmd.action == LFUN_DOWN_SELECT ||
664 cmd.action == LFUN_UP_SELECT;
666 // move cursor up/down
667 bool up = cmd.action == LFUN_UP_SELECT || cmd.action == LFUN_UP;
668 bool const atFirstOrLastRow = cur.atFirstOrLastRow(up);
670 if (!atFirstOrLastRow) {
671 needsUpdate |= cur.selHandle(select);
672 cur.selHandle(select);
673 cur.upDownInText(up, needsUpdate);
674 needsUpdate |= cur.beforeDispatchCursor().inMathed();
676 // if the cursor cannot be moved up or down do not remove
677 // the selection right now, but wait for the next dispatch.
679 needsUpdate |= cur.selHandle(select);
680 cur.upDownInText(up, needsUpdate);
687 case LFUN_PARAGRAPH_UP:
688 case LFUN_PARAGRAPH_UP_SELECT:
689 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
690 needsUpdate |= cursorUpParagraph(cur);
693 case LFUN_PARAGRAPH_DOWN:
694 case LFUN_PARAGRAPH_DOWN_SELECT:
695 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
696 needsUpdate |= cursorDownParagraph(cur);
699 case LFUN_LINE_BEGIN:
700 case LFUN_LINE_BEGIN_SELECT:
701 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
702 needsUpdate |= tm.cursorHome(cur);
706 case LFUN_LINE_END_SELECT:
707 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
708 needsUpdate |= tm.cursorEnd(cur);
711 case LFUN_WORD_RIGHT:
712 case LFUN_WORD_RIGHT_SELECT:
713 if (lyxrc.visual_cursor) {
714 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_RIGHT_SELECT);
715 needsUpdate |= cursorVisRightOneWord(cur);
716 if (!needsUpdate && oldTopSlice == cur.top()
717 && cur.boundary() == oldBoundary) {
719 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
722 if (reverseDirectionNeeded(cur)) {
723 cmd.action = cmd.action == LFUN_WORD_RIGHT_SELECT ?
724 LFUN_WORD_BACKWARD_SELECT : LFUN_WORD_BACKWARD;
726 cmd.action = cmd.action == LFUN_WORD_RIGHT_SELECT ?
727 LFUN_WORD_FORWARD_SELECT : LFUN_WORD_FORWARD;
734 case LFUN_WORD_FORWARD:
735 case LFUN_WORD_FORWARD_SELECT:
736 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
737 needsUpdate |= cursorForwardOneWord(cur);
741 case LFUN_WORD_LEFT_SELECT:
742 if (lyxrc.visual_cursor) {
743 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_LEFT_SELECT);
744 needsUpdate |= cursorVisLeftOneWord(cur);
745 if (!needsUpdate && oldTopSlice == cur.top()
746 && cur.boundary() == oldBoundary) {
748 cmd = FuncRequest(LFUN_FINISHED_LEFT);
751 if (reverseDirectionNeeded(cur)) {
752 cmd.action = cmd.action == LFUN_WORD_LEFT_SELECT ?
753 LFUN_WORD_FORWARD_SELECT : LFUN_WORD_FORWARD;
755 cmd.action = cmd.action == LFUN_WORD_LEFT_SELECT ?
756 LFUN_WORD_BACKWARD_SELECT : LFUN_WORD_BACKWARD;
763 case LFUN_WORD_BACKWARD:
764 case LFUN_WORD_BACKWARD_SELECT:
765 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
766 needsUpdate |= cursorBackwardOneWord(cur);
769 case LFUN_WORD_SELECT: {
770 selectWord(cur, WHOLE_WORD);
771 finishChange(cur, true);
775 case LFUN_NEWLINE_INSERT: {
776 InsetNewlineParams inp;
777 docstring arg = cmd.argument();
778 // this avoids a double undo
779 // FIXME: should not be needed, ideally
780 if (!cur.selection())
782 cap::replaceSelection(cur);
783 if (arg == "linebreak")
784 inp.kind = InsetNewlineParams::LINEBREAK;
786 inp.kind = InsetNewlineParams::NEWLINE;
787 cur.insert(new InsetNewline(inp));
789 moveCursor(cur, false);
793 case LFUN_CHAR_DELETE_FORWARD:
794 if (!cur.selection()) {
795 if (cur.pos() == cur.paragraph().size())
796 // Par boundary, force full-screen update
797 singleParUpdate = false;
798 needsUpdate |= erase(cur);
800 // It is possible to make it a lot faster still
801 // just comment out the line below...
803 cutSelection(cur, true, false);
804 singleParUpdate = false;
806 moveCursor(cur, false);
809 case LFUN_CHAR_DELETE_BACKWARD:
810 if (!cur.selection()) {
811 if (bv->getIntl().getTransManager().backspace()) {
812 // Par boundary, full-screen update
814 singleParUpdate = false;
815 needsUpdate |= backspace(cur);
817 // It is possible to make it a lot faster still
818 // just comment out the line below...
821 cutSelection(cur, true, false);
822 singleParUpdate = false;
826 case LFUN_BREAK_PARAGRAPH:
827 cap::replaceSelection(cur);
828 breakParagraph(cur, cmd.argument() == "inverse");
833 // With the creation of LFUN_PARAGRAPH_PARAMS, this is now redundant,
834 // as its duties can be performed there. Should it be removed??
835 // FIXME For now, it can just dispatch LFUN_PARAGRAPH_PARAMS...
836 case LFUN_PARAGRAPH_SPACING: {
837 Paragraph & par = cur.paragraph();
838 Spacing::Space cur_spacing = par.params().spacing().getSpace();
839 string cur_value = "1.0";
840 if (cur_spacing == Spacing::Other)
841 cur_value = par.params().spacing().getValueAsString();
843 istringstream is(to_utf8(cmd.argument()));
846 Spacing::Space new_spacing = cur_spacing;
847 string new_value = cur_value;
849 lyxerr << "Missing argument to `paragraph-spacing'"
851 } else if (tmp == "single") {
852 new_spacing = Spacing::Single;
853 } else if (tmp == "onehalf") {
854 new_spacing = Spacing::Onehalf;
855 } else if (tmp == "double") {
856 new_spacing = Spacing::Double;
857 } else if (tmp == "other") {
858 new_spacing = Spacing::Other;
859 string tmpval = "0.0";
861 lyxerr << "new_value = " << tmpval << endl;
864 } else if (tmp == "default") {
865 new_spacing = Spacing::Default;
867 lyxerr << to_utf8(_("Unknown spacing argument: "))
868 << to_utf8(cmd.argument()) << endl;
870 if (cur_spacing != new_spacing || cur_value != new_value)
871 par.params().spacing(Spacing(new_spacing, new_value));
875 case LFUN_INSET_INSERT: {
878 // We have to avoid triggering InstantPreview loading
879 // before inserting into the document. See bug #5626.
880 bool loaded = bv->buffer().isFullyLoaded();
881 bv->buffer().setFullyLoaded(false);
882 Inset * inset = createInset(bv->buffer(), cmd);
883 bv->buffer().setFullyLoaded(loaded);
886 // FIXME (Abdel 01/02/2006):
887 // What follows would be a partial fix for bug 2154:
888 // http://bugzilla.lyx.org/show_bug.cgi?id=2154
889 // This automatically put the label inset _after_ a
890 // numbered section. It should be possible to extend the mechanism
891 // to any kind of LateX environement.
892 // The correct way to fix that bug would be at LateX generation.
893 // I'll let the code here for reference as it could be used for some
894 // other feature like "automatic labelling".
896 Paragraph & par = pars_[cur.pit()];
897 if (inset->lyxCode() == LABEL_CODE
898 && par.layout().labeltype == LABEL_COUNTER) {
899 // Go to the end of the paragraph
900 // Warning: Because of Change-Tracking, the last
901 // position is 'size()' and not 'size()-1':
902 cur.pos() = par.size();
903 // Insert a new paragraph
904 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
909 cutSelection(cur, true, false);
913 // trigger InstantPreview now
914 if (inset->lyxCode() == EXTERNAL_CODE) {
915 InsetExternal & ins =
916 static_cast<InsetExternal &>(*inset);
924 case LFUN_INSET_DISSOLVE: {
925 // first, try if there's an inset at cursor
926 // FIXME: this first part should be moved to
927 // a LFUN_NEXT_INSET_DISSOLVE, or be called via
928 // some generic "next-inset inset-dissolve"
929 Inset * inset = cur.nextInset();
930 if (inset && inset->isActive()) {
932 tmpcur.pushBackward(*inset);
933 inset->dispatch(tmpcur, cmd);
934 if (tmpcur.result().dispatched()) {
939 // if it did not work, try the underlying inset
940 if (dissolveInset(cur)) {
944 // if it did not work, do nothing.
948 case LFUN_SET_GRAPHICS_GROUP: {
949 InsetGraphics * ins = graphics::getCurrentGraphicsInset(cur);
955 string id = to_utf8(cmd.argument());
956 string grp = graphics::getGroupParams(bv->buffer(), id);
957 InsetGraphicsParams tmp, inspar = ins->getParams();
960 inspar.groupId = to_utf8(cmd.argument());
962 InsetGraphics::string2params(grp, bv->buffer(), tmp);
963 tmp.filename = inspar.filename;
967 ins->setParams(inspar);
970 case LFUN_SPACE_INSERT:
971 if (cur.paragraph().layout().free_spacing)
972 insertChar(cur, ' ');
974 doInsertInset(cur, this, cmd, false, false);
977 moveCursor(cur, false);
980 case LFUN_SPECIALCHAR_INSERT: {
981 string const name = to_utf8(cmd.argument());
982 if (name == "hyphenation")
983 specialChar(cur, InsetSpecialChar::HYPHENATION);
984 else if (name == "ligature-break")
985 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
986 else if (name == "slash")
987 specialChar(cur, InsetSpecialChar::SLASH);
988 else if (name == "nobreakdash")
989 specialChar(cur, InsetSpecialChar::NOBREAKDASH);
990 else if (name == "dots")
991 specialChar(cur, InsetSpecialChar::LDOTS);
992 else if (name == "end-of-sentence")
993 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
994 else if (name == "menu-separator")
995 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
996 else if (name.empty())
997 lyxerr << "LyX function 'specialchar-insert' needs an argument." << endl;
999 lyxerr << "Wrong argument for LyX function 'specialchar-insert'." << endl;
1003 case LFUN_WORD_UPCASE:
1004 changeCase(cur, text_uppercase);
1007 case LFUN_WORD_LOWCASE:
1008 changeCase(cur, text_lowercase);
1011 case LFUN_WORD_CAPITALIZE:
1012 changeCase(cur, text_capitalization);
1015 case LFUN_CHARS_TRANSPOSE:
1016 charsTranspose(cur);
1020 cur.message(_("Paste"));
1021 LASSERT(cur.selBegin().idx() == cur.selEnd().idx(), /**/);
1022 cap::replaceSelection(cur);
1024 // without argument?
1025 string const arg = to_utf8(cmd.argument());
1027 if (theClipboard().isInternal())
1028 pasteFromStack(cur, bv->buffer().errorList("Paste"), 0);
1029 else if (theClipboard().hasGraphicsContents()
1030 && !theClipboard().hasTextContents())
1031 pasteClipboardGraphics(cur, bv->buffer().errorList("Paste"));
1033 pasteClipboardText(cur, bv->buffer().errorList("Paste"));
1034 } else if (isStrUnsignedInt(arg)) {
1035 // we have a numerical argument
1036 pasteFromStack(cur, bv->buffer().errorList("Paste"),
1037 convert<unsigned int>(arg));
1039 Clipboard::GraphicsType type = Clipboard::AnyGraphicsType;
1041 type = Clipboard::PdfGraphicsType;
1042 else if (arg == "png")
1043 type = Clipboard::PngGraphicsType;
1044 else if (arg == "jpeg")
1045 type = Clipboard::JpegGraphicsType;
1046 else if (arg == "linkback")
1047 type = Clipboard::LinkBackGraphicsType;
1049 LASSERT(false, /**/);
1051 pasteClipboardGraphics(cur, bv->buffer().errorList("Paste"), type);
1054 bv->buffer().errors("Paste");
1055 cur.clearSelection(); // bug 393
1061 cutSelection(cur, true, true);
1062 cur.message(_("Cut"));
1067 cur.message(_("Copy"));
1070 case LFUN_SERVER_GET_XY:
1071 cur.message(from_utf8(
1072 convert<string>(tm.cursorX(cur.top(), cur.boundary()))
1073 + ' ' + convert<string>(tm.cursorY(cur.top(), cur.boundary()))));
1076 case LFUN_SERVER_SET_XY: {
1079 istringstream is(to_utf8(cmd.argument()));
1082 lyxerr << "SETXY: Could not parse coordinates in '"
1083 << to_utf8(cmd.argument()) << endl;
1085 tm.setCursorFromCoordinates(cur, x, y);
1089 case LFUN_SERVER_GET_LAYOUT:
1090 cur.message(cur.paragraph().layout().name());
1094 docstring layout = cmd.argument();
1095 LYXERR(Debug::INFO, "LFUN_LAYOUT: (arg) " << to_utf8(layout));
1097 Paragraph const & para = cur.paragraph();
1098 docstring const old_layout = para.layout().name();
1099 DocumentClass const & tclass = bv->buffer().params().documentClass();
1102 layout = tclass.defaultLayoutName();
1104 if (para.forcePlainLayout())
1105 // in this case only the empty layout is allowed
1106 layout = tclass.plainLayoutName();
1107 else if (para.usePlainLayout()) {
1108 // in this case, default layout maps to empty layout
1109 if (layout == tclass.defaultLayoutName())
1110 layout = tclass.plainLayoutName();
1112 // otherwise, the empty layout maps to the default
1113 if (layout == tclass.plainLayoutName())
1114 layout = tclass.defaultLayoutName();
1117 bool hasLayout = tclass.hasLayout(layout);
1119 // If the entry is obsolete, use the new one instead.
1121 docstring const & obs = tclass[layout].obsoleted_by();
1127 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
1128 from_utf8(N_(" not known")));
1132 bool change_layout = (old_layout != layout);
1134 if (!change_layout && cur.selection() &&
1135 cur.selBegin().pit() != cur.selEnd().pit())
1137 pit_type spit = cur.selBegin().pit();
1138 pit_type epit = cur.selEnd().pit() + 1;
1139 while (spit != epit) {
1140 if (pars_[spit].layout().name() != old_layout) {
1141 change_layout = true;
1149 setLayout(cur, layout);
1154 case LFUN_CLIPBOARD_PASTE:
1155 cur.clearSelection();
1156 pasteClipboardText(cur, bv->buffer().errorList("Paste"),
1157 cmd.argument() == "paragraph");
1158 bv->buffer().errors("Paste");
1161 case LFUN_PRIMARY_SELECTION_PASTE:
1162 pasteString(cur, theSelection().get(),
1163 cmd.argument() == "paragraph");
1166 case LFUN_SELECTION_PASTE:
1167 // Copy the selection buffer to the clipboard stack,
1168 // because we want it to appear in the "Edit->Paste
1170 cap::copySelectionToStack();
1171 cap::pasteSelection(bv->cursor(), bv->buffer().errorList("Paste"));
1172 bv->buffer().errors("Paste");
1175 case LFUN_UNICODE_INSERT: {
1176 if (cmd.argument().empty())
1178 docstring hexstring = cmd.argument();
1179 if (isHex(hexstring)) {
1180 char_type c = hexToInt(hexstring);
1181 if (c >= 32 && c < 0x10ffff) {
1182 lyxerr << "Inserting c: " << c << endl;
1183 docstring s = docstring(1, c);
1184 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
1190 case LFUN_QUOTE_INSERT: {
1191 Paragraph & par = cur.paragraph();
1192 pos_type pos = cur.pos();
1193 BufferParams const & bufparams = bv->buffer().params();
1194 Layout const & style = par.layout();
1195 InsetLayout const & ilayout = cur.inset().getLayout(bufparams);
1196 if (!style.pass_thru && !ilayout.isPassThru()
1197 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
1198 // this avoids a double undo
1199 // FIXME: should not be needed, ideally
1200 if (!cur.selection())
1202 cap::replaceSelection(cur);
1207 else if (cur.prevInset() && cur.prevInset()->isSpace())
1210 c = par.getChar(pos - 1);
1211 string arg = to_utf8(cmd.argument());
1212 cur.insert(new InsetQuotes(bv->buffer(), c, (arg == "single")
1213 ? InsetQuotes::SingleQuotes : InsetQuotes::DoubleQuotes));
1217 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
1221 case LFUN_DATE_INSERT: {
1222 string const format = cmd.argument().empty()
1223 ? lyxrc.date_insert_format : to_utf8(cmd.argument());
1224 string const time = formatted_time(current_time(), format);
1225 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, time));
1229 case LFUN_MOUSE_TRIPLE:
1230 if (cmd.button() == mouse_button::button1) {
1239 case LFUN_MOUSE_DOUBLE:
1240 if (cmd.button() == mouse_button::button1) {
1241 selectWord(cur, WHOLE_WORD_STRICT);
1246 // Single-click on work area
1247 case LFUN_MOUSE_PRESS:
1248 // We are not marking a selection with the keyboard in any case.
1249 cur.bv().cursor().setMark(false);
1250 switch (cmd.button()) {
1251 case mouse_button::button1:
1253 if (!bv->mouseSetCursor(cur, cmd.argument() == "region-select"))
1254 cur.updateFlags(Update::SinglePar | Update::FitCursor);
1257 case mouse_button::button2:
1258 // Middle mouse pasting.
1259 bv->mouseSetCursor(cur);
1261 FuncRequest(LFUN_COMMAND_ALTERNATIVES,
1262 "selection-paste ; primary-selection-paste paragraph"));
1266 case mouse_button::button3: {
1267 Cursor const & bvcur = cur.bv().cursor();
1268 // Don't do anything if we right-click a
1269 // selection, a context menu will popup.
1270 if (bvcur.selection() && cur >= bvcur.selectionBegin()
1271 && cur < bvcur.selectionEnd()) {
1275 if (!bv->mouseSetCursor(cur, false))
1276 cur.updateFlags(Update::SinglePar | Update::FitCursor);
1282 } // switch (cmd.button())
1285 case LFUN_MOUSE_MOTION: {
1286 // Mouse motion with right or middle mouse do nothing for now.
1287 if (cmd.button() != mouse_button::button1) {
1291 // ignore motions deeper nested than the real anchor
1292 Cursor & bvcur = cur.bv().cursor();
1293 if (!bvcur.anchor_.hasPart(cur)) {
1297 CursorSlice old = bvcur.top();
1299 int const wh = bv->workHeight();
1300 int const y = max(0, min(wh - 1, cmd.y));
1302 tm.setCursorFromCoordinates(cur, cmd.x, y);
1303 cur.setTargetX(cmd.x);
1305 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1307 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1308 // This is to allow jumping over large insets
1309 if (cur.top() == old) {
1311 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1313 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1315 // We continue with our existing selection or start a new one, so don't
1316 // reset the anchor.
1317 bvcur.setCursor(cur);
1318 bvcur.setSelection(true);
1319 if (cur.top() == old) {
1320 // We didn't move one iota, so no need to update the screen.
1321 cur.updateFlags(Update::SinglePar | Update::FitCursor);
1328 case LFUN_MOUSE_RELEASE:
1329 switch (cmd.button()) {
1330 case mouse_button::button1:
1331 // Cursor was set at LFUN_MOUSE_PRESS or LFUN_MOUSE_MOTION time.
1332 // If there is a new selection, update persistent selection;
1333 // otherwise, single click does not clear persistent selection
1335 if (cur.selection()) {
1336 // Finish selection. If double click,
1337 // cur is moved to the end of word by
1338 // selectWord but bvcur is current
1340 cur.bv().cursor().setSelection();
1341 // We might have removed an empty but drawn selection
1342 // (probably a margin)
1343 cur.updateFlags(Update::SinglePar | Update::FitCursor);
1346 // FIXME: We could try to handle drag and drop of selection here.
1349 case mouse_button::button2:
1350 // Middle mouse pasting is handled at mouse press time,
1351 // see LFUN_MOUSE_PRESS.
1355 case mouse_button::button3:
1356 // Cursor was set at LFUN_MOUSE_PRESS time.
1357 // FIXME: If there is a selection we could try to handle a special
1358 // drag & drop context menu.
1362 case mouse_button::none:
1363 case mouse_button::button4:
1364 case mouse_button::button5:
1366 } // switch (cmd.button())
1370 case LFUN_SELF_INSERT: {
1371 if (cmd.argument().empty())
1374 // Automatically delete the currently selected
1375 // text and replace it with what is being
1376 // typed in now. Depends on lyxrc settings
1377 // "auto_region_delete", which defaults to
1380 if (lyxrc.auto_region_delete && cur.selection())
1381 cutSelection(cur, false, false);
1383 cur.clearSelection();
1385 docstring::const_iterator cit = cmd.argument().begin();
1386 docstring::const_iterator const end = cmd.argument().end();
1387 for (; cit != end; ++cit)
1388 bv->translateAndInsert(*cit, this, cur);
1391 moveCursor(cur, false);
1392 bv->bookmarkEditPosition();
1396 case LFUN_HYPERLINK_INSERT: {
1397 InsetCommandParams p(HYPERLINK_CODE);
1399 if (cur.selection()) {
1400 content = cur.selectionAsString(false);
1401 cutSelection(cur, true, false);
1403 p["target"] = (cmd.argument().empty()) ?
1404 content : cmd.argument();
1405 string const data = InsetCommand::params2string("href", p);
1406 if (p["target"].empty()) {
1407 bv->showDialog("href", data);
1409 FuncRequest fr(LFUN_INSET_INSERT, data);
1415 case LFUN_LABEL_INSERT: {
1416 InsetCommandParams p(LABEL_CODE);
1417 // Try to generate a valid label
1418 p["name"] = (cmd.argument().empty()) ?
1419 cur.getPossibleLabel() :
1421 string const data = InsetCommand::params2string("label", p);
1423 if (cmd.argument().empty()) {
1424 bv->showDialog("label", data);
1426 FuncRequest fr(LFUN_INSET_INSERT, data);
1432 case LFUN_INFO_INSERT: {
1434 if (cmd.argument().empty() && cur.selection()) {
1435 // if command argument is empty use current selection as parameter.
1436 docstring ds = cur.selectionAsString(false);
1437 cutSelection(cur, true, false);
1438 FuncRequest cmd0(cmd, ds);
1439 inset = createInset(cur.bv().buffer(), cmd0);
1441 inset = createInset(cur.bv().buffer(), cmd);
1445 insertInset(cur, inset);
1449 case LFUN_CAPTION_INSERT:
1450 case LFUN_FOOTNOTE_INSERT:
1451 case LFUN_NOTE_INSERT:
1452 case LFUN_FLEX_INSERT:
1453 case LFUN_BOX_INSERT:
1454 case LFUN_BRANCH_INSERT:
1455 case LFUN_PHANTOM_INSERT:
1456 case LFUN_ERT_INSERT:
1457 case LFUN_LISTING_INSERT:
1458 case LFUN_MARGINALNOTE_INSERT:
1459 case LFUN_OPTIONAL_INSERT:
1460 case LFUN_INDEX_INSERT:
1461 // Open the inset, and move the current selection
1463 doInsertInset(cur, this, cmd, true, true);
1465 // Some insets are numbered, others are shown in the outline pane so
1466 // let's update the labels and the toc backend.
1467 bv->buffer().updateLabels();
1470 case LFUN_TABULAR_INSERT:
1471 // if there were no arguments, just open the dialog
1472 if (doInsertInset(cur, this, cmd, false, true))
1475 bv->showDialog("tabularcreate");
1479 case LFUN_FLOAT_INSERT:
1480 case LFUN_FLOAT_WIDE_INSERT:
1481 case LFUN_WRAP_INSERT: {
1482 // will some text be moved into the inset?
1483 bool content = cur.selection();
1485 doInsertInset(cur, this, cmd, true, true);
1488 // If some text is moved into the inset, doInsertInset
1489 // puts the cursor outside the inset. To insert the
1490 // caption we put it back into the inset.
1494 ParagraphList & pars = cur.text()->paragraphs();
1496 DocumentClass const & tclass = bv->buffer().params().documentClass();
1498 // add a separate paragraph for the caption inset
1499 pars.push_back(Paragraph());
1500 pars.back().setInsetOwner(&pars[0].inInset());
1501 pars.back().setPlainOrDefaultLayout(tclass);
1502 int cap_pit = pars.size() - 1;
1504 // if an empty inset was created, we create an additional empty
1505 // paragraph at the bottom so that the user can choose where to put
1506 // the graphics (or table).
1508 pars.push_back(Paragraph());
1509 pars.back().setInsetOwner(&pars[0].inInset());
1510 pars.back().setPlainOrDefaultLayout(tclass);
1513 // reposition the cursor to the caption
1514 cur.pit() = cap_pit;
1516 // FIXME: This Text/Cursor dispatch handling is a mess!
1517 // We cannot use Cursor::dispatch here it needs access to up to
1519 FuncRequest cmd_caption(LFUN_CAPTION_INSERT);
1520 doInsertInset(cur, cur.text(), cmd_caption, true, false);
1521 bv->buffer().updateLabels();
1522 cur.updateFlags(Update::Force);
1523 // FIXME: When leaving the Float (or Wrap) inset we should
1524 // delete any empty paragraph left above or below the
1529 case LFUN_NOMENCL_INSERT: {
1530 InsetCommandParams p(NOMENCL_CODE);
1531 if (cmd.argument().empty())
1532 p["symbol"] = bv->cursor().innerText()->getStringToIndex(bv->cursor());
1534 p["symbol"] = cmd.argument();
1535 string const data = InsetCommand::params2string("nomenclature", p);
1536 bv->showDialog("nomenclature", data);
1540 case LFUN_INDEX_PRINT: {
1541 InsetCommandParams p(INDEX_PRINT_CODE);
1542 if (cmd.argument().empty())
1543 p["type"] = from_ascii("idx");
1545 p["type"] = cmd.argument();
1546 string const data = InsetCommand::params2string("index_print", p);
1547 FuncRequest fr(LFUN_INSET_INSERT, data);
1552 case LFUN_NOMENCL_PRINT:
1553 case LFUN_TOC_INSERT:
1554 case LFUN_LINE_INSERT:
1555 case LFUN_NEWPAGE_INSERT:
1557 doInsertInset(cur, this, cmd, false, false);
1561 case LFUN_DEPTH_DECREMENT:
1562 changeDepth(cur, DEC_DEPTH);
1565 case LFUN_DEPTH_INCREMENT:
1566 changeDepth(cur, INC_DEPTH);
1569 case LFUN_MATH_DISPLAY:
1570 mathDispatch(cur, cmd, true);
1573 case LFUN_REGEXP_MODE:
1574 regexpDispatch(cur, cmd);
1577 case LFUN_MATH_MODE:
1578 if (cmd.argument() == "on")
1579 // don't pass "on" as argument
1580 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1582 mathDispatch(cur, cmd, false);
1585 case LFUN_MATH_MACRO:
1586 if (cmd.argument().empty())
1587 cur.errorMessage(from_utf8(N_("Missing argument")));
1589 string s = to_utf8(cmd.argument());
1590 string const s1 = token(s, ' ', 1);
1591 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1592 string const s2 = token(s, ' ', 2);
1593 MacroType type = MacroTypeNewcommand;
1595 type = MacroTypeDef;
1596 MathMacroTemplate * inset = new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, false, type);
1597 inset->setBuffer(bv->buffer());
1598 insertInset(cur, inset);
1600 // enter macro inset and select the name
1602 cur.top().pos() = cur.top().lastpos();
1604 cur.setSelection(true);
1605 cur.top().pos() = 0;
1609 // passthrough hat and underscore outside mathed:
1610 case LFUN_MATH_SUBSCRIPT:
1611 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1613 case LFUN_MATH_SUPERSCRIPT:
1614 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1617 case LFUN_MATH_INSERT:
1618 case LFUN_MATH_MATRIX:
1619 case LFUN_MATH_DELIM:
1620 case LFUN_MATH_BIGDELIM: {
1622 cap::replaceSelection(cur);
1623 cur.insert(new InsetMathHull(hullSimple));
1624 checkAndActivateInset(cur, true);
1625 LASSERT(cur.inMathed(), /**/);
1630 case LFUN_FONT_EMPH: {
1631 Font font(ignore_font, ignore_language);
1632 font.fontInfo().setEmph(FONT_TOGGLE);
1633 toggleAndShow(cur, this, font);
1637 case LFUN_FONT_ITAL: {
1638 Font font(ignore_font, ignore_language);
1639 font.fontInfo().setShape(ITALIC_SHAPE);
1640 toggleAndShow(cur, this, font);
1644 case LFUN_FONT_BOLD:
1645 case LFUN_FONT_BOLDSYMBOL: {
1646 Font font(ignore_font, ignore_language);
1647 font.fontInfo().setSeries(BOLD_SERIES);
1648 toggleAndShow(cur, this, font);
1652 case LFUN_FONT_NOUN: {
1653 Font font(ignore_font, ignore_language);
1654 font.fontInfo().setNoun(FONT_TOGGLE);
1655 toggleAndShow(cur, this, font);
1659 case LFUN_FONT_TYPEWRITER: {
1660 Font font(ignore_font, ignore_language);
1661 font.fontInfo().setFamily(TYPEWRITER_FAMILY); // no good
1662 toggleAndShow(cur, this, font);
1666 case LFUN_FONT_SANS: {
1667 Font font(ignore_font, ignore_language);
1668 font.fontInfo().setFamily(SANS_FAMILY);
1669 toggleAndShow(cur, this, font);
1673 case LFUN_FONT_ROMAN: {
1674 Font font(ignore_font, ignore_language);
1675 font.fontInfo().setFamily(ROMAN_FAMILY);
1676 toggleAndShow(cur, this, font);
1680 case LFUN_FONT_DEFAULT: {
1681 Font font(inherit_font, ignore_language);
1682 toggleAndShow(cur, this, font);
1686 case LFUN_FONT_UNDERLINE: {
1687 Font font(ignore_font, ignore_language);
1688 font.fontInfo().setUnderbar(FONT_TOGGLE);
1689 toggleAndShow(cur, this, font);
1693 case LFUN_FONT_SIZE: {
1694 Font font(ignore_font, ignore_language);
1695 setLyXSize(to_utf8(cmd.argument()), font.fontInfo());
1696 toggleAndShow(cur, this, font);
1700 case LFUN_LANGUAGE: {
1701 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1704 Font font(ignore_font, lang);
1705 toggleAndShow(cur, this, font);
1709 case LFUN_TEXTSTYLE_APPLY:
1710 toggleAndShow(cur, this, freefont, toggleall);
1711 cur.message(_("Character set"));
1714 // Set the freefont using the contents of \param data dispatched from
1715 // the frontends and apply it at the current cursor location.
1716 case LFUN_TEXTSTYLE_UPDATE: {
1719 if (font.fromString(to_utf8(cmd.argument()), toggle)) {
1722 toggleAndShow(cur, this, freefont, toggleall);
1723 cur.message(_("Character set"));
1725 lyxerr << "Argument not ok";
1730 case LFUN_FINISHED_LEFT:
1731 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_LEFT:\n" << cur);
1732 // We're leaving an inset, going left. If the inset is LTR, we're
1733 // leaving from the front, so we should not move (remain at --- but
1734 // not in --- the inset). If the inset is RTL, move left, without
1735 // entering the inset itself; i.e., move to after the inset.
1736 if (cur.paragraph().getFontSettings(
1737 cur.bv().buffer().params(), cur.pos()).isRightToLeft())
1738 cursorVisLeft(cur, true);
1741 case LFUN_FINISHED_RIGHT:
1742 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_RIGHT:\n" << cur);
1743 // We're leaving an inset, going right. If the inset is RTL, we're
1744 // leaving from the front, so we should not move (remain at --- but
1745 // not in --- the inset). If the inset is LTR, move right, without
1746 // entering the inset itself; i.e., move to after the inset.
1747 if (!cur.paragraph().getFontSettings(
1748 cur.bv().buffer().params(), cur.pos()).isRightToLeft())
1749 cursorVisRight(cur, true);
1752 case LFUN_FINISHED_BACKWARD:
1753 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_BACKWARD:\n" << cur);
1756 case LFUN_FINISHED_FORWARD:
1757 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_FORWARD:\n" << cur);
1759 cur.setCurrentFont();
1762 case LFUN_LAYOUT_PARAGRAPH: {
1764 params2string(cur.paragraph(), data);
1765 data = "show\n" + data;
1766 bv->showDialog("paragraph", data);
1770 case LFUN_PARAGRAPH_UPDATE: {
1772 params2string(cur.paragraph(), data);
1774 // Will the paragraph accept changes from the dialog?
1776 cur.inset().allowParagraphCustomization(cur.idx());
1778 data = "update " + convert<string>(accept) + '\n' + data;
1779 bv->updateDialog("paragraph", data);
1783 case LFUN_ACCENT_UMLAUT:
1784 case LFUN_ACCENT_CIRCUMFLEX:
1785 case LFUN_ACCENT_GRAVE:
1786 case LFUN_ACCENT_ACUTE:
1787 case LFUN_ACCENT_TILDE:
1788 case LFUN_ACCENT_CEDILLA:
1789 case LFUN_ACCENT_MACRON:
1790 case LFUN_ACCENT_DOT:
1791 case LFUN_ACCENT_UNDERDOT:
1792 case LFUN_ACCENT_UNDERBAR:
1793 case LFUN_ACCENT_CARON:
1794 case LFUN_ACCENT_BREVE:
1795 case LFUN_ACCENT_TIE:
1796 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1797 case LFUN_ACCENT_CIRCLE:
1798 case LFUN_ACCENT_OGONEK:
1799 theLyXFunc().handleKeyFunc(cmd.action);
1800 if (!cmd.argument().empty())
1801 // FIXME: Are all these characters encoded in one byte in utf8?
1802 bv->translateAndInsert(cmd.argument()[0], this, cur);
1805 case LFUN_FLOAT_LIST_INSERT: {
1806 DocumentClass const & tclass = bv->buffer().params().documentClass();
1807 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1809 if (cur.selection())
1810 cutSelection(cur, true, false);
1811 breakParagraph(cur);
1813 if (cur.lastpos() != 0) {
1814 cursorBackward(cur);
1815 breakParagraph(cur);
1818 docstring const laystr = cur.inset().usePlainLayout() ?
1819 tclass.plainLayoutName() :
1820 tclass.defaultLayoutName();
1821 setLayout(cur, laystr);
1822 ParagraphParameters p;
1823 // FIXME If this call were replaced with one to clearParagraphParams(),
1824 // then we could get rid of this method altogether.
1825 setParagraphs(cur, p);
1826 // FIXME This should be simplified when InsetFloatList takes a
1827 // Buffer in its constructor.
1828 InsetFloatList * ifl = new InsetFloatList(to_utf8(cmd.argument()));
1829 ifl->setBuffer(bv->buffer());
1830 insertInset(cur, ifl);
1833 lyxerr << "Non-existent float type: "
1834 << to_utf8(cmd.argument()) << endl;
1839 case LFUN_CHANGE_ACCEPT: {
1840 acceptOrRejectChanges(cur, ACCEPT);
1844 case LFUN_CHANGE_REJECT: {
1845 acceptOrRejectChanges(cur, REJECT);
1849 case LFUN_THESAURUS_ENTRY: {
1850 docstring arg = cmd.argument();
1852 arg = cur.selectionAsString(false);
1854 if (arg.size() > 100 || arg.empty()) {
1855 // Get word or selection
1856 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1857 arg = cur.selectionAsString(false);
1858 arg += " lang=" + from_ascii(cur.getFont().language()->lang());
1861 bv->showDialog("thesaurus", to_utf8(arg));
1865 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1866 // Given data, an encoding of the ParagraphParameters
1867 // generated in the Paragraph dialog, this function sets
1868 // the current paragraph, or currently selected paragraphs,
1870 // NOTE: This function overrides all existing settings.
1871 setParagraphs(cur, cmd.argument());
1872 cur.message(_("Paragraph layout set"));
1876 case LFUN_PARAGRAPH_PARAMS: {
1877 // Given data, an encoding of the ParagraphParameters as we'd
1878 // find them in a LyX file, this function modifies the current paragraph,
1879 // or currently selected paragraphs.
1880 // NOTE: This function only modifies, and does not override, existing
1882 setParagraphs(cur, cmd.argument(), true);
1883 cur.message(_("Paragraph layout set"));
1888 if (cur.selection()) {
1889 cur.setSelection(false);
1892 // This used to be LFUN_FINISHED_RIGHT, I think FORWARD is more
1893 // correct, but I'm not 100% sure -- dov, 071019
1894 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
1898 case LFUN_OUTLINE_UP:
1899 outline(OutlineUp, cur);
1900 setCursor(cur, cur.pit(), 0);
1901 cur.buffer()->updateLabels();
1905 case LFUN_OUTLINE_DOWN:
1906 outline(OutlineDown, cur);
1907 setCursor(cur, cur.pit(), 0);
1908 cur.buffer()->updateLabels();
1912 case LFUN_OUTLINE_IN:
1913 outline(OutlineIn, cur);
1914 cur.buffer()->updateLabels();
1918 case LFUN_OUTLINE_OUT:
1919 outline(OutlineOut, cur);
1920 cur.buffer()->updateLabels();
1925 LYXERR(Debug::ACTION, "Command " << cmd << " not DISPATCHED by Text");
1930 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1932 // FIXME: The cursor flag is reset two lines below
1933 // so we need to check here if some of the LFUN did touch that.
1934 // for now only Text::erase() and Text::backspace() do that.
1935 // The plan is to verify all the LFUNs and then to remove this
1936 // singleParUpdate boolean altogether.
1937 if (cur.result().update() & Update::Force) {
1938 singleParUpdate = false;
1942 // FIXME: the following code should go in favor of fine grained
1943 // update flag treatment.
1944 if (singleParUpdate) {
1945 // Inserting characters does not change par height in general. So, try
1946 // to update _only_ this paragraph. BufferView will detect if a full
1947 // metrics update is needed anyway.
1948 cur.updateFlags(Update::SinglePar | Update::FitCursor);
1953 && &oldTopSlice.inset() == &cur.inset()
1954 && oldTopSlice.idx() == cur.idx()
1955 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1956 && !cur.selection())
1957 // FIXME: it would be better if we could just do this
1959 //if (cur.result().update() != Update::FitCursor)
1962 // But some LFUNs do not set Update::FitCursor when needed, so we
1963 // do it for all. This is not very harmfull as FitCursor will provoke
1964 // a full redraw only if needed but still, a proper review of all LFUN
1965 // should be done and this needsUpdate boolean can then be removed.
1966 cur.updateFlags(Update::FitCursor);
1968 cur.updateFlags(Update::Force | Update::FitCursor);
1972 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
1973 FuncStatus & flag) const
1975 LASSERT(cur.text() == this, /**/);
1977 FontInfo const & fontinfo = cur.real_current_font.fontInfo();
1979 InsetCode code = NO_CODE;
1981 switch (cmd.action) {
1983 case LFUN_DEPTH_DECREMENT:
1984 enable = changeDepthAllowed(cur, DEC_DEPTH);
1987 case LFUN_DEPTH_INCREMENT:
1988 enable = changeDepthAllowed(cur, INC_DEPTH);
1992 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1995 case LFUN_DIALOG_SHOW_NEW_INSET:
1996 if (cmd.argument() == "bibitem")
1997 code = BIBITEM_CODE;
1998 else if (cmd.argument() == "bibtex")
2000 else if (cmd.argument() == "box")
2002 else if (cmd.argument() == "branch")
2004 else if (cmd.argument() == "citation")
2006 else if (cmd.argument() == "ert")
2008 else if (cmd.argument() == "external")
2009 code = EXTERNAL_CODE;
2010 else if (cmd.argument() == "float")
2012 else if (cmd.argument() == "graphics")
2013 code = GRAPHICS_CODE;
2014 else if (cmd.argument() == "href")
2015 code = HYPERLINK_CODE;
2016 else if (cmd.argument() == "include")
2017 code = INCLUDE_CODE;
2018 else if (cmd.argument() == "index")
2020 else if (cmd.argument() == "index_print")
2021 code = INDEX_PRINT_CODE;
2022 else if (cmd.argument() == "nomenclature")
2023 code = NOMENCL_CODE;
2024 else if (cmd.argument() == "label")
2026 else if (cmd.argument() == "note")
2028 else if (cmd.argument() == "phantom")
2029 code = PHANTOM_CODE;
2030 else if (cmd.argument() == "ref")
2032 else if (cmd.argument() == "space")
2034 else if (cmd.argument() == "toc")
2036 else if (cmd.argument() == "vspace")
2038 else if (cmd.argument() == "wrap")
2040 else if (cmd.argument() == "listings")
2041 code = LISTINGS_CODE;
2044 case LFUN_ERT_INSERT:
2047 case LFUN_LISTING_INSERT:
2048 code = LISTINGS_CODE;
2049 // not allowed in description items
2050 enable = !inDescriptionItem(cur);
2052 case LFUN_FOOTNOTE_INSERT:
2055 case LFUN_TABULAR_INSERT:
2056 code = TABULAR_CODE;
2058 case LFUN_MARGINALNOTE_INSERT:
2061 case LFUN_FLOAT_INSERT:
2062 case LFUN_FLOAT_WIDE_INSERT:
2064 // not allowed in description items
2065 enable = !inDescriptionItem(cur);
2067 case LFUN_WRAP_INSERT:
2069 // not allowed in description items
2070 enable = !inDescriptionItem(cur);
2072 case LFUN_FLOAT_LIST_INSERT:
2073 code = FLOAT_LIST_CODE;
2075 case LFUN_CAPTION_INSERT:
2076 code = CAPTION_CODE;
2077 // not allowed in description items
2078 enable = !inDescriptionItem(cur);
2080 case LFUN_NOTE_INSERT:
2082 // in commands (sections etc.) and description items,
2083 // only Notes are allowed
2084 enable = (cmd.argument().empty() || cmd.getArg(0) == "Note" ||
2085 (!cur.paragraph().layout().isCommand()
2086 && !inDescriptionItem(cur)));
2088 case LFUN_FLEX_INSERT: {
2090 string s = cmd.getArg(0);
2092 cur.buffer()->params().documentClass().insetLayout(from_utf8(s));
2093 if (il.lyxtype() != InsetLayout::CHARSTYLE &&
2094 il.lyxtype() != InsetLayout::CUSTOM &&
2095 il.lyxtype() != InsetLayout::ELEMENT &&
2096 il.lyxtype ()!= InsetLayout::STANDARD)
2100 case LFUN_BOX_INSERT:
2103 case LFUN_BRANCH_INSERT:
2105 if (cur.buffer()->masterBuffer()->params().branchlist().empty())
2108 case LFUN_PHANTOM_INSERT:
2109 code = PHANTOM_CODE;
2111 case LFUN_LABEL_INSERT:
2114 case LFUN_INFO_INSERT:
2117 case LFUN_OPTIONAL_INSERT:
2119 enable = cur.paragraph().insetList().count(OPTARG_CODE)
2120 < cur.paragraph().layout().optionalargs;
2122 case LFUN_INDEX_INSERT:
2125 case LFUN_INDEX_PRINT:
2126 code = INDEX_PRINT_CODE;
2128 case LFUN_NOMENCL_INSERT:
2129 if (cur.selIsMultiCell() || cur.selIsMultiLine()) {
2133 code = NOMENCL_CODE;
2135 case LFUN_NOMENCL_PRINT:
2136 code = NOMENCL_PRINT_CODE;
2138 case LFUN_TOC_INSERT:
2141 case LFUN_HYPERLINK_INSERT:
2142 if (cur.selIsMultiCell() || cur.selIsMultiLine()) {
2146 code = HYPERLINK_CODE;
2148 case LFUN_QUOTE_INSERT:
2149 // always allow this, since we will inset a raw quote
2150 // if an inset is not allowed.
2152 case LFUN_SPECIALCHAR_INSERT:
2153 code = SPECIALCHAR_CODE;
2155 case LFUN_SPACE_INSERT:
2156 // slight hack: we know this is allowed in math mode
2161 case LFUN_INSET_MODIFY:
2162 // We need to disable this, because we may get called for a
2164 // InsetTabular::getStatus() -> InsetText::getStatus()
2165 // and we don't handle LFUN_INSET_MODIFY.
2169 case LFUN_FONT_EMPH:
2170 flag.setOnOff(fontinfo.emph() == FONT_ON);
2173 case LFUN_FONT_ITAL:
2174 flag.setOnOff(fontinfo.shape() == ITALIC_SHAPE);
2177 case LFUN_FONT_NOUN:
2178 flag.setOnOff(fontinfo.noun() == FONT_ON);
2181 case LFUN_FONT_BOLD:
2182 case LFUN_FONT_BOLDSYMBOL:
2183 flag.setOnOff(fontinfo.series() == BOLD_SERIES);
2186 case LFUN_FONT_SANS:
2187 flag.setOnOff(fontinfo.family() == SANS_FAMILY);
2190 case LFUN_FONT_ROMAN:
2191 flag.setOnOff(fontinfo.family() == ROMAN_FAMILY);
2194 case LFUN_FONT_TYPEWRITER:
2195 flag.setOnOff(fontinfo.family() == TYPEWRITER_FAMILY);
2200 enable = cur.selection();
2204 if (cmd.argument().empty()) {
2205 if (theClipboard().isInternal())
2206 enable = cap::numberOfSelections() > 0;
2208 enable = !theClipboard().empty();
2212 // we have an argument
2213 string const arg = to_utf8(cmd.argument());
2214 if (isStrUnsignedInt(arg)) {
2215 // it's a number and therefore means the internal stack
2216 unsigned int n = convert<unsigned int>(arg);
2217 enable = cap::numberOfSelections() > n;
2221 // explicit graphics type?
2222 if ((arg == "pdf" && theClipboard().hasGraphicsContents(Clipboard::PdfGraphicsType))
2223 || (arg == "png" && theClipboard().hasGraphicsContents(Clipboard::PngGraphicsType))
2224 || (arg == "jpeg" && theClipboard().hasGraphicsContents(Clipboard::JpegGraphicsType))
2225 || (arg == "linkback" && theClipboard().hasGraphicsContents(Clipboard::LinkBackGraphicsType))) {
2235 case LFUN_CLIPBOARD_PASTE:
2236 enable = !theClipboard().empty();
2239 case LFUN_PRIMARY_SELECTION_PASTE:
2240 enable = cur.selection() || !theSelection().empty();
2243 case LFUN_SELECTION_PASTE:
2244 enable = cap::selection();
2247 case LFUN_PARAGRAPH_MOVE_UP:
2248 enable = cur.pit() > 0 && !cur.selection();
2251 case LFUN_PARAGRAPH_MOVE_DOWN:
2252 enable = cur.pit() < cur.lastpit() && !cur.selection();
2255 case LFUN_INSET_DISSOLVE:
2256 if (!cmd.argument().empty()) {
2257 InsetLayout const & il = cur.inset().getLayout(cur.buffer()->params());
2258 InsetLayout::InsetLyXType const type =
2259 translateLyXType(to_utf8(cmd.argument()));
2260 enable = cur.inset().lyxCode() == FLEX_CODE
2261 && il.lyxtype() == type;
2263 enable = ((!isMainText(cur.bv().buffer())
2264 && cur.inset().nargs() == 1)
2266 && cur.nextInset()->nargs() == 1));
2270 case LFUN_CHANGE_ACCEPT:
2271 case LFUN_CHANGE_REJECT:
2272 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
2273 // In principle, these LFUNs should only be enabled if there
2274 // is a change at the current position/in the current selection.
2275 // However, without proper optimizations, this will inevitably
2276 // result in unacceptable performance - just imagine a user who
2277 // wants to select the complete content of a long document.
2281 case LFUN_OUTLINE_UP:
2282 case LFUN_OUTLINE_DOWN:
2283 case LFUN_OUTLINE_IN:
2284 case LFUN_OUTLINE_OUT:
2285 // FIXME: LyX is not ready for outlining within inset.
2286 enable = isMainText(cur.bv().buffer())
2287 && cur.paragraph().layout().toclevel != Layout::NOT_IN_TOC;
2290 case LFUN_NEWLINE_INSERT:
2291 // LaTeX restrictions (labels or empty par)
2292 enable = (cur.pos() > cur.paragraph().beginOfBody());
2295 case LFUN_SET_GRAPHICS_GROUP: {
2296 InsetGraphics * ins = graphics::getCurrentGraphicsInset(cur);
2300 flag.setOnOff(to_utf8(cmd.argument()) == ins->getParams().groupId);
2304 case LFUN_NEWPAGE_INSERT:
2305 // not allowed in description items
2306 enable = !inDescriptionItem(cur);
2309 case LFUN_MATH_INSERT:
2310 case LFUN_MATH_MATRIX:
2311 case LFUN_MATH_DELIM:
2312 case LFUN_MATH_BIGDELIM:
2313 // not allowed in ERT, for example.
2314 enable = cur.inset().insetAllowed(MATH_CODE);
2317 case LFUN_DATE_INSERT: {
2318 string const format = cmd.argument().empty()
2319 ? lyxrc.date_insert_format : to_utf8(cmd.argument());
2320 enable = support::os::is_valid_strftime(format);
2324 case LFUN_WORD_DELETE_FORWARD:
2325 case LFUN_WORD_DELETE_BACKWARD:
2326 case LFUN_LINE_DELETE:
2327 case LFUN_WORD_FORWARD:
2328 case LFUN_WORD_BACKWARD:
2329 case LFUN_WORD_RIGHT:
2330 case LFUN_WORD_LEFT:
2331 case LFUN_CHAR_FORWARD:
2332 case LFUN_CHAR_FORWARD_SELECT:
2333 case LFUN_CHAR_BACKWARD:
2334 case LFUN_CHAR_BACKWARD_SELECT:
2335 case LFUN_CHAR_LEFT:
2336 case LFUN_CHAR_LEFT_SELECT:
2337 case LFUN_CHAR_RIGHT:
2338 case LFUN_CHAR_RIGHT_SELECT:
2340 case LFUN_UP_SELECT:
2342 case LFUN_DOWN_SELECT:
2343 case LFUN_PARAGRAPH_UP_SELECT:
2344 case LFUN_PARAGRAPH_DOWN_SELECT:
2345 case LFUN_LINE_BEGIN_SELECT:
2346 case LFUN_LINE_END_SELECT:
2347 case LFUN_WORD_FORWARD_SELECT:
2348 case LFUN_WORD_BACKWARD_SELECT:
2349 case LFUN_WORD_RIGHT_SELECT:
2350 case LFUN_WORD_LEFT_SELECT:
2351 case LFUN_WORD_SELECT:
2352 case LFUN_PARAGRAPH_UP:
2353 case LFUN_PARAGRAPH_DOWN:
2354 case LFUN_LINE_BEGIN:
2356 case LFUN_CHAR_DELETE_FORWARD:
2357 case LFUN_CHAR_DELETE_BACKWARD:
2358 case LFUN_BREAK_PARAGRAPH:
2359 case LFUN_PARAGRAPH_SPACING:
2360 case LFUN_INSET_INSERT:
2361 case LFUN_WORD_UPCASE:
2362 case LFUN_WORD_LOWCASE:
2363 case LFUN_WORD_CAPITALIZE:
2364 case LFUN_CHARS_TRANSPOSE:
2365 case LFUN_SERVER_GET_XY:
2366 case LFUN_SERVER_SET_XY:
2367 case LFUN_SERVER_GET_LAYOUT:
2369 case LFUN_SELF_INSERT:
2370 case LFUN_LINE_INSERT:
2371 case LFUN_MATH_DISPLAY:
2372 case LFUN_MATH_MODE:
2373 case LFUN_MATH_MACRO:
2374 case LFUN_MATH_SUBSCRIPT:
2375 case LFUN_MATH_SUPERSCRIPT:
2376 case LFUN_FONT_DEFAULT:
2377 case LFUN_FONT_UNDERLINE:
2378 case LFUN_FONT_SIZE:
2380 case LFUN_TEXTSTYLE_APPLY:
2381 case LFUN_TEXTSTYLE_UPDATE:
2382 case LFUN_LAYOUT_PARAGRAPH:
2383 case LFUN_PARAGRAPH_UPDATE:
2384 case LFUN_ACCENT_UMLAUT:
2385 case LFUN_ACCENT_CIRCUMFLEX:
2386 case LFUN_ACCENT_GRAVE:
2387 case LFUN_ACCENT_ACUTE:
2388 case LFUN_ACCENT_TILDE:
2389 case LFUN_ACCENT_CEDILLA:
2390 case LFUN_ACCENT_MACRON:
2391 case LFUN_ACCENT_DOT:
2392 case LFUN_ACCENT_UNDERDOT:
2393 case LFUN_ACCENT_UNDERBAR:
2394 case LFUN_ACCENT_CARON:
2395 case LFUN_ACCENT_BREVE:
2396 case LFUN_ACCENT_TIE:
2397 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
2398 case LFUN_ACCENT_CIRCLE:
2399 case LFUN_ACCENT_OGONEK:
2400 case LFUN_THESAURUS_ENTRY:
2401 case LFUN_PARAGRAPH_PARAMS_APPLY:
2402 case LFUN_PARAGRAPH_PARAMS:
2404 case LFUN_BUFFER_BEGIN:
2405 case LFUN_BUFFER_END:
2406 case LFUN_BUFFER_BEGIN_SELECT:
2407 case LFUN_BUFFER_END_SELECT:
2408 case LFUN_INSET_BEGIN:
2409 case LFUN_INSET_END:
2410 case LFUN_INSET_BEGIN_SELECT:
2411 case LFUN_INSET_END_SELECT:
2412 case LFUN_UNICODE_INSERT:
2413 // these are handled in our dispatch()
2422 && (cur.empty() || !cur.inset().insetAllowed(code)))
2425 flag.setEnabled(enable);
2430 void Text::pasteString(Cursor & cur, docstring const & clip,
2433 cur.clearSelection();
2434 if (!clip.empty()) {
2437 insertStringAsParagraphs(cur, clip);
2439 insertStringAsLines(cur, clip);
2444 // FIXME: an item inset would make things much easier.
2445 bool Text::inDescriptionItem(Cursor & cur) const
2447 Paragraph & par = cur.paragraph();
2448 pos_type const pos = cur.pos();
2449 pos_type const body_pos = par.beginOfBody();
2451 if (par.layout().latextype != LATEX_LIST_ENVIRONMENT
2452 && (par.layout().latextype != LATEX_ITEM_ENVIRONMENT
2453 || par.layout().margintype != MARGIN_FIRST_DYNAMIC))
2456 return (pos < body_pos
2458 && (pos == 0 || par.getChar(pos - 1) != ' ')));