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/Clipboard.h"
50 #include "frontends/Selection.h"
52 #include "insets/InsetCollapsable.h"
53 #include "insets/InsetCommand.h"
54 #include "insets/InsetFloatList.h"
55 #include "insets/InsetNewline.h"
56 #include "insets/InsetQuotes.h"
57 #include "insets/InsetSpecialChar.h"
58 #include "insets/InsetText.h"
59 #include "insets/InsetInfo.h"
60 #include "insets/InsetGraphics.h"
61 #include "insets/InsetGraphicsParams.h"
63 #include "support/convert.h"
64 #include "support/debug.h"
65 #include "support/gettext.h"
66 #include "support/lstrings.h"
67 #include "support/lyxtime.h"
69 #include "mathed/InsetMathHull.h"
70 #include "mathed/MathMacroTemplate.h"
72 #include <boost/next_prior.hpp>
78 using namespace lyx::support;
82 using cap::copySelection;
83 using cap::cutSelection;
84 using cap::pasteFromStack;
85 using cap::pasteClipboardText;
86 using cap::pasteClipboardGraphics;
87 using cap::replaceSelection;
90 static Font freefont(ignore_font, ignore_language);
91 static bool toggleall = false;
93 static void toggleAndShow(Cursor & cur, Text * text,
94 Font const & font, bool toggleall = true)
96 text->toggleFree(cur, font, toggleall);
98 if (font.language() != ignore_language ||
99 font.fontInfo().number() != FONT_IGNORE) {
100 TextMetrics const & tm = cur.bv().textMetrics(text);
101 if (cur.boundary() != tm.isRTLBoundary(cur.pit(), cur.pos(),
102 cur.real_current_font))
103 text->setCursor(cur, cur.pit(), cur.pos(),
104 false, !cur.boundary());
109 static void moveCursor(Cursor & cur, bool selecting)
111 if (selecting || cur.mark())
116 static void finishChange(Cursor & cur, bool selecting)
119 moveCursor(cur, selecting);
123 static void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
126 docstring sel = cur.selectionAsString(false);
128 // It may happen that sel is empty but there is a selection
129 replaceSelection(cur);
132 #ifdef ENABLE_ASSERTIONS
133 const int old_pos = cur.pos();
135 cur.insert(new InsetMathHull(hullSimple));
136 #ifdef ENABLE_ASSERTIONS
137 LASSERT(old_pos == cur.pos(), /**/);
139 cur.nextInset()->edit(cur, true);
140 // don't do that also for LFUN_MATH_MODE
141 // unless you want end up with always changing
142 // to mathrm when opening an inlined inset --
143 // I really hate "LyXfunc overloading"...
145 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
146 // Avoid an unnecessary undo step if cmd.argument
148 if (!cmd.argument().empty())
149 cur.dispatch(FuncRequest(LFUN_MATH_INSERT,
152 // create a macro if we see "\\newcommand"
153 // somewhere, and an ordinary formula
155 if (sel.find(from_ascii("\\newcommand")) == string::npos
156 && sel.find(from_ascii("\\newlyxcommand")) == string::npos
157 && sel.find(from_ascii("\\def")) == string::npos)
159 InsetMathHull * formula = new InsetMathHull;
160 istringstream is(to_utf8(sel));
164 if (formula->getType() == hullNone)
165 // Don't create pseudo formulas if
166 // delimiters are left out
167 formula->mutate(hullSimple);
170 cur.insert(new MathMacroTemplate(sel));
173 cur.message(from_utf8(N_("Math editor mode")));
177 static void specialChar(Cursor & cur, InsetSpecialChar::Kind kind)
180 cap::replaceSelection(cur);
181 cur.insert(new InsetSpecialChar(kind));
186 static bool doInsertInset(Cursor & cur, Text * text,
187 FuncRequest const & cmd, bool edit, bool pastesel)
189 Buffer & buffer = cur.bv().buffer();
190 BufferParams const & bparams = buffer.params();
191 Inset * inset = createInset(buffer, cmd);
195 if (InsetCollapsable * ci = inset->asInsetCollapsable())
196 ci->setLayout(bparams);
199 if (cmd.action == LFUN_INDEX_INSERT) {
200 docstring ds = subst(text->getStringToIndex(cur), '\n', ' ');
201 text->insertInset(cur, inset);
203 inset->edit(cur, true);
204 // Now put this into inset
205 static_cast<InsetCollapsable *>(inset)->text_.insertStringAsParagraphs(cur, ds);
210 if (cur.selection()) {
211 lyx::dispatch(FuncRequest(LFUN_CUT));
214 text->insertInset(cur, inset);
217 inset->edit(cur, true);
219 if (!gotsel || !pastesel)
222 lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
223 InsetText * insetText = dynamic_cast<InsetText *>(inset);
224 if (insetText && !insetText->allowMultiPar() || cur.lastpit() == 0) {
225 // reset first par to default
226 cur.text()->paragraphs().begin()
227 ->setEmptyOrDefaultLayout(bparams.documentClass());
230 // Merge multiple paragraphs -- hack
231 while (cur.lastpit() > 0)
232 mergeParagraph(bparams, cur.text()->paragraphs(), 0);
234 // reset surrounding par to default
235 docstring const layoutname = insetText->useEmptyLayout()
236 ? bparams.documentClass().emptyLayoutName()
237 : bparams.documentClass().defaultLayoutName();
238 cur.leaveInset(*inset);
239 text->setLayout(cur, layoutname);
246 string const freefont2string()
248 return freefont.toString(toggleall);
252 /// the type of outline operation
254 OutlineUp, // Move this header with text down
255 OutlineDown, // Move this header with text up
256 OutlineIn, // Make this header deeper
257 OutlineOut // Make this header shallower
261 static void outline(OutlineOp mode, Cursor & cur)
263 Buffer & buf = cur.buffer();
264 pit_type & pit = cur.pit();
265 ParagraphList & pars = buf.text().paragraphs();
266 ParagraphList::iterator bgn = pars.begin();
267 // The first paragraph of the area to be copied:
268 ParagraphList::iterator start = boost::next(bgn, pit);
269 // The final paragraph of area to be copied:
270 ParagraphList::iterator finish = start;
271 ParagraphList::iterator end = pars.end();
273 DocumentClass const & tc = buf.params().documentClass();
275 int const thistoclevel = start->layout().toclevel;
278 // Move out (down) from this section header
281 // Seek the one (on same level) below
282 for (; finish != end; ++finish) {
283 toclevel = finish->layout().toclevel;
284 if (toclevel != Layout::NOT_IN_TOC && toclevel <= thistoclevel) {
291 if (start == pars.begin())
294 ParagraphList::iterator dest = start;
295 // Move out (up) from this header
298 // Search previous same-level header above
301 toclevel = dest->layout().toclevel;
303 && (toclevel == Layout::NOT_IN_TOC
304 || toclevel > thistoclevel));
305 // Not found; do nothing
306 if (toclevel == Layout::NOT_IN_TOC || toclevel > thistoclevel)
308 pit_type const newpit = distance(bgn, dest);
309 pit_type const len = distance(start, finish);
310 pit_type const deletepit = pit + len;
311 buf.undo().recordUndo(cur, ATOMIC_UNDO, newpit, deletepit - 1);
312 pars.insert(dest, start, finish);
313 start = boost::next(pars.begin(), deletepit);
315 pars.erase(start, finish);
322 // Go one down from *this* header:
323 ParagraphList::iterator dest = boost::next(finish, 1);
324 // Go further down to find header to insert in front of:
325 for (; dest != end; ++dest) {
326 toclevel = dest->layout().toclevel;
327 if (toclevel != Layout::NOT_IN_TOC
328 && toclevel <= thistoclevel) {
332 // One such was found:
333 pit_type newpit = distance(bgn, dest);
334 pit_type const len = distance(start, finish);
335 buf.undo().recordUndo(cur, ATOMIC_UNDO, pit, newpit - 1);
336 pars.insert(dest, start, finish);
337 start = boost::next(bgn, pit);
339 pars.erase(start, finish);
343 pit_type const len = distance(start, finish);
344 buf.undo().recordUndo(cur, ATOMIC_UNDO, pit, pit + len - 1);
345 for (; start != finish; ++start) {
346 toclevel = start->layout().toclevel;
347 if (toclevel == Layout::NOT_IN_TOC)
349 DocumentClass::const_iterator lit = tc.begin();
350 DocumentClass::const_iterator len = tc.end();
351 for (; lit != len; ++lit) {
352 if (lit->toclevel == toclevel + 1 &&
353 start->layout().labeltype == lit->labeltype) {
354 start->setLayout(*lit);
362 pit_type const len = distance(start, finish);
363 buf.undo().recordUndo(cur, ATOMIC_UNDO, pit, pit + len - 1);
364 for (; start != finish; ++start) {
365 toclevel = start->layout().toclevel;
366 if (toclevel == Layout::NOT_IN_TOC)
368 DocumentClass::const_iterator lit = tc.begin();
369 DocumentClass::const_iterator len = tc.end();
370 for (; lit != len; ++lit) {
371 if (lit->toclevel == toclevel - 1 &&
372 start->layout().labeltype == lit->labeltype) {
373 start->setLayout(*lit);
384 void Text::number(Cursor & cur)
386 FontInfo font = ignore_font;
387 font.setNumber(FONT_TOGGLE);
388 toggleAndShow(cur, this, Font(font, ignore_language));
392 bool Text::isRTL(Buffer const & buffer, Paragraph const & par) const
394 return par.isRTL(buffer.params());
398 void Text::dispatch(Cursor & cur, FuncRequest & cmd)
400 LYXERR(Debug::ACTION, "Text::dispatch: cmd: " << cmd);
402 BufferView * bv = &cur.bv();
403 TextMetrics & tm = bv->textMetrics(this);
404 if (!tm.contains(cur.pit()))
405 lyx::dispatch(FuncRequest(LFUN_SCREEN_RECENTER));
407 // FIXME: We use the update flag to indicates wether a singlePar or a
408 // full screen update is needed. We reset it here but shall we restore it
412 LASSERT(cur.text() == this, /**/);
413 CursorSlice oldTopSlice = cur.top();
414 bool oldBoundary = cur.boundary();
415 bool sel = cur.selection();
416 // Signals that, even if needsUpdate == false, an update of the
417 // cursor paragraph is required
418 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
419 LyXAction::SingleParUpdate);
420 // Signals that a full-screen update is required
421 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
422 LyXAction::NoUpdate) || singleParUpdate);
424 switch (cmd.action) {
426 case LFUN_PARAGRAPH_MOVE_DOWN: {
427 pit_type const pit = cur.pit();
428 recUndo(cur, pit, pit + 1);
430 swap(pars_[pit], pars_[pit + 1]);
431 updateLabels(cur.buffer());
437 case LFUN_PARAGRAPH_MOVE_UP: {
438 pit_type const pit = cur.pit();
439 recUndo(cur, pit - 1, pit);
441 swap(pars_[pit], pars_[pit - 1]);
442 updateLabels(cur.buffer());
448 case LFUN_APPENDIX: {
449 Paragraph & par = cur.paragraph();
450 bool start = !par.params().startOfAppendix();
452 // FIXME: The code below only makes sense at top level.
453 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
454 // ensure that we have only one start_of_appendix in this document
455 // FIXME: this don't work for multipart document!
456 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
457 if (pars_[tmp].params().startOfAppendix()) {
459 pars_[tmp].params().startOfAppendix(false);
465 par.params().startOfAppendix(start);
467 // we can set the refreshing parameters now
468 updateLabels(cur.buffer());
472 case LFUN_WORD_DELETE_FORWARD:
473 if (cur.selection()) {
474 cutSelection(cur, true, false);
476 deleteWordForward(cur);
477 finishChange(cur, false);
480 case LFUN_WORD_DELETE_BACKWARD:
481 if (cur.selection()) {
482 cutSelection(cur, true, false);
484 deleteWordBackward(cur);
485 finishChange(cur, false);
488 case LFUN_LINE_DELETE:
489 if (cur.selection()) {
490 cutSelection(cur, true, false);
492 tm.deleteLineForward(cur);
493 finishChange(cur, false);
496 case LFUN_BUFFER_BEGIN:
497 case LFUN_BUFFER_BEGIN_SELECT:
498 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
499 if (cur.depth() == 1) {
500 needsUpdate |= cursorTop(cur);
504 cur.updateFlags(Update::FitCursor);
507 case LFUN_BUFFER_END:
508 case LFUN_BUFFER_END_SELECT:
509 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
510 if (cur.depth() == 1) {
511 needsUpdate |= cursorBottom(cur);
515 cur.updateFlags(Update::FitCursor);
518 case LFUN_CHAR_FORWARD:
519 case LFUN_CHAR_FORWARD_SELECT:
520 //LYXERR0(" LFUN_CHAR_FORWARD[SEL]:\n" << cur);
521 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
522 needsUpdate |= cursorForward(cur);
524 if (!needsUpdate && oldTopSlice == cur.top()
525 && cur.boundary() == oldBoundary) {
527 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
531 case LFUN_CHAR_BACKWARD:
532 case LFUN_CHAR_BACKWARD_SELECT:
533 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
534 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
535 needsUpdate |= cursorBackward(cur);
537 if (!needsUpdate && oldTopSlice == cur.top()
538 && cur.boundary() == oldBoundary) {
540 cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
545 case LFUN_CHAR_LEFT_SELECT:
546 if (lyxrc.visual_cursor) {
547 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_LEFT_SELECT);
548 needsUpdate |= cursorVisLeft(cur);
549 if (!needsUpdate && oldTopSlice == cur.top()
550 && cur.boundary() == oldBoundary) {
552 cmd = FuncRequest(LFUN_FINISHED_LEFT);
555 if (reverseDirectionNeeded(cur)) {
556 cmd.action = cmd.action == LFUN_CHAR_LEFT_SELECT ?
557 LFUN_CHAR_FORWARD_SELECT : LFUN_CHAR_FORWARD;
559 cmd.action = cmd.action == LFUN_CHAR_LEFT_SELECT ?
560 LFUN_CHAR_BACKWARD_SELECT : LFUN_CHAR_BACKWARD;
567 case LFUN_CHAR_RIGHT:
568 case LFUN_CHAR_RIGHT_SELECT:
569 if (lyxrc.visual_cursor) {
570 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_RIGHT_SELECT);
571 needsUpdate |= cursorVisRight(cur);
572 if (!needsUpdate && oldTopSlice == cur.top()
573 && cur.boundary() == oldBoundary) {
575 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
578 if (reverseDirectionNeeded(cur)) {
579 cmd.action = cmd.action == LFUN_CHAR_RIGHT_SELECT ?
580 LFUN_CHAR_BACKWARD_SELECT : LFUN_CHAR_BACKWARD;
582 cmd.action = cmd.action == LFUN_CHAR_RIGHT_SELECT ?
583 LFUN_CHAR_FORWARD_SELECT : LFUN_CHAR_FORWARD;
592 case LFUN_DOWN_SELECT:
595 // stop/start the selection
596 bool select = cmd.action == LFUN_DOWN_SELECT ||
597 cmd.action == LFUN_UP_SELECT;
598 cur.selHandle(select);
600 // move cursor up/down
601 bool up = cmd.action == LFUN_UP_SELECT || cmd.action == LFUN_UP;
602 bool const successful = cur.upDownInText(up, needsUpdate);
604 // redraw if you leave mathed (for the decorations)
605 needsUpdate |= cur.beforeDispatchCursor().inMathed();
612 case LFUN_PARAGRAPH_UP:
613 case LFUN_PARAGRAPH_UP_SELECT:
614 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
615 needsUpdate |= cursorUpParagraph(cur);
618 case LFUN_PARAGRAPH_DOWN:
619 case LFUN_PARAGRAPH_DOWN_SELECT:
620 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
621 needsUpdate |= cursorDownParagraph(cur);
624 case LFUN_LINE_BEGIN:
625 case LFUN_LINE_BEGIN_SELECT:
626 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
627 needsUpdate |= tm.cursorHome(cur);
631 case LFUN_LINE_END_SELECT:
632 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
633 needsUpdate |= tm.cursorEnd(cur);
636 case LFUN_WORD_RIGHT:
637 case LFUN_WORD_RIGHT_SELECT:
638 if (lyxrc.visual_cursor) {
639 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_RIGHT_SELECT);
640 needsUpdate |= cursorVisRightOneWord(cur);
641 if (!needsUpdate && oldTopSlice == cur.top()
642 && cur.boundary() == oldBoundary) {
644 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
647 if (reverseDirectionNeeded(cur)) {
648 cmd.action = cmd.action == LFUN_WORD_RIGHT_SELECT ?
649 LFUN_WORD_BACKWARD_SELECT : LFUN_WORD_BACKWARD;
651 cmd.action = cmd.action == LFUN_WORD_RIGHT_SELECT ?
652 LFUN_WORD_FORWARD_SELECT : LFUN_WORD_FORWARD;
659 case LFUN_WORD_FORWARD:
660 case LFUN_WORD_FORWARD_SELECT:
661 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
662 needsUpdate |= cursorForwardOneWord(cur);
666 case LFUN_WORD_LEFT_SELECT:
667 if (lyxrc.visual_cursor) {
668 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_LEFT_SELECT);
669 needsUpdate |= cursorVisLeftOneWord(cur);
670 if (!needsUpdate && oldTopSlice == cur.top()
671 && cur.boundary() == oldBoundary) {
673 cmd = FuncRequest(LFUN_FINISHED_LEFT);
676 if (reverseDirectionNeeded(cur)) {
677 cmd.action = cmd.action == LFUN_WORD_LEFT_SELECT ?
678 LFUN_WORD_FORWARD_SELECT : LFUN_WORD_FORWARD;
680 cmd.action = cmd.action == LFUN_WORD_LEFT_SELECT ?
681 LFUN_WORD_BACKWARD_SELECT : LFUN_WORD_BACKWARD;
688 case LFUN_WORD_BACKWARD:
689 case LFUN_WORD_BACKWARD_SELECT:
690 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
691 needsUpdate |= cursorBackwardOneWord(cur);
694 case LFUN_WORD_SELECT: {
695 selectWord(cur, WHOLE_WORD);
696 finishChange(cur, true);
700 case LFUN_NEWLINE_INSERT: {
701 InsetNewlineParams inp;
702 docstring arg = cmd.argument();
703 // this avoids a double undo
704 // FIXME: should not be needed, ideally
705 if (!cur.selection())
707 cap::replaceSelection(cur);
708 if (arg == "linebreak")
709 inp.kind = InsetNewlineParams::LINEBREAK;
711 inp.kind = InsetNewlineParams::NEWLINE;
712 cur.insert(new InsetNewline(inp));
714 moveCursor(cur, false);
718 case LFUN_CHAR_DELETE_FORWARD:
719 if (!cur.selection()) {
720 if (cur.pos() == cur.paragraph().size())
721 // Par boundary, force full-screen update
722 singleParUpdate = false;
723 needsUpdate |= erase(cur);
725 // It is possible to make it a lot faster still
726 // just comment out the line below...
728 cutSelection(cur, true, false);
729 singleParUpdate = false;
731 moveCursor(cur, false);
734 case LFUN_DELETE_FORWARD_SKIP:
735 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
736 if (!cur.selection()) {
737 if (cur.pos() == cur.lastpos()) {
744 cutSelection(cur, true, false);
749 case LFUN_CHAR_DELETE_BACKWARD:
750 if (!cur.selection()) {
751 if (bv->getIntl().getTransManager().backspace()) {
752 // Par boundary, full-screen update
754 singleParUpdate = false;
755 needsUpdate |= backspace(cur);
757 // It is possible to make it a lot faster still
758 // just comment out the line below...
761 cutSelection(cur, true, false);
762 singleParUpdate = false;
766 case LFUN_DELETE_BACKWARD_SKIP:
767 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
768 if (!cur.selection()) {
770 //CursorSlice cur = cursor();
774 cutSelection(cur, true, false);
778 case LFUN_BREAK_PARAGRAPH:
779 cap::replaceSelection(cur);
780 breakParagraph(cur, cmd.argument() == "inverse");
784 case LFUN_BREAK_PARAGRAPH_SKIP: {
785 // When at the beginning of a paragraph, remove
786 // indentation. Otherwise, do the same as LFUN_BREAK_PARAGRAPH.
787 cap::replaceSelection(cur);
789 cur.paragraph().params().labelWidthString(docstring());
791 breakParagraph(cur, false);
797 // With the creation of LFUN_PARAGRAPH_PARAMS, this is now redundant,
798 // as its duties can be performed there. Should it be removed??
799 // FIXME For now, it can just dispatch LFUN_PARAGRAPH_PARAMS...
800 case LFUN_PARAGRAPH_SPACING: {
801 Paragraph & par = cur.paragraph();
802 Spacing::Space cur_spacing = par.params().spacing().getSpace();
803 string cur_value = "1.0";
804 if (cur_spacing == Spacing::Other)
805 cur_value = par.params().spacing().getValueAsString();
807 istringstream is(to_utf8(cmd.argument()));
810 Spacing::Space new_spacing = cur_spacing;
811 string new_value = cur_value;
813 lyxerr << "Missing argument to `paragraph-spacing'"
815 } else if (tmp == "single") {
816 new_spacing = Spacing::Single;
817 } else if (tmp == "onehalf") {
818 new_spacing = Spacing::Onehalf;
819 } else if (tmp == "double") {
820 new_spacing = Spacing::Double;
821 } else if (tmp == "other") {
822 new_spacing = Spacing::Other;
823 string tmpval = "0.0";
825 lyxerr << "new_value = " << tmpval << endl;
828 } else if (tmp == "default") {
829 new_spacing = Spacing::Default;
831 lyxerr << to_utf8(_("Unknown spacing argument: "))
832 << to_utf8(cmd.argument()) << endl;
834 if (cur_spacing != new_spacing || cur_value != new_value)
835 par.params().spacing(Spacing(new_spacing, new_value));
839 case LFUN_INSET_INSERT: {
841 Inset * inset = createInset(bv->buffer(), cmd);
843 // FIXME (Abdel 01/02/2006):
844 // What follows would be a partial fix for bug 2154:
845 // http://bugzilla.lyx.org/show_bug.cgi?id=2154
846 // This automatically put the label inset _after_ a
847 // numbered section. It should be possible to extend the mechanism
848 // to any kind of LateX environement.
849 // The correct way to fix that bug would be at LateX generation.
850 // I'll let the code here for reference as it could be used for some
851 // other feature like "automatic labelling".
853 Paragraph & par = pars_[cur.pit()];
854 if (inset->lyxCode() == LABEL_CODE
855 && par.layout().labeltype == LABEL_COUNTER) {
856 // Go to the end of the paragraph
857 // Warning: Because of Change-Tracking, the last
858 // position is 'size()' and not 'size()-1':
859 cur.pos() = par.size();
860 // Insert a new paragraph
861 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
866 cutSelection(cur, true, false);
873 case LFUN_INSET_DISSOLVE:
874 needsUpdate |= dissolveInset(cur);
877 case LFUN_INSET_SETTINGS: {
878 Inset & inset = cur.inset();
879 if (cmd.getArg(0) == insetName(inset.lyxCode())) {
880 // This inset dialog has been explicitely requested.
881 inset.showInsetDialog(bv);
884 // else, if there is an inset at the cursor, access this
885 Inset * next_inset = cur.nextInset();
887 next_inset->showInsetDialog(bv);
890 // if not then access the underlying inset.
891 inset.showInsetDialog(bv);
895 case LFUN_SET_GRAPHICS_GROUP: {
896 InsetGraphics * ins = graphics::getCurrentGraphicsInset(cur);
900 cur.recordUndoFullDocument();
902 string id = to_utf8(cmd.argument());
903 string grp = graphics::getGroupParams(bv->buffer(), id);
904 InsetGraphicsParams tmp, inspar = ins->getParams();
907 inspar.groupId = to_utf8(cmd.argument());
909 InsetGraphics::string2params(grp, bv->buffer(), tmp);
910 tmp.filename = inspar.filename;
914 ins->setParams(inspar);
917 case LFUN_SPACE_INSERT:
918 if (cur.paragraph().layout().free_spacing)
919 insertChar(cur, ' ');
921 doInsertInset(cur, this, cmd, false, false);
924 moveCursor(cur, false);
927 case LFUN_SPECIALCHAR_INSERT: {
928 string const name = to_utf8(cmd.argument());
929 if (name == "hyphenation")
930 specialChar(cur, InsetSpecialChar::HYPHENATION);
931 else if (name == "ligature-break")
932 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
933 else if (name == "slash")
934 specialChar(cur, InsetSpecialChar::SLASH);
935 else if (name == "nobreakdash")
936 specialChar(cur, InsetSpecialChar::NOBREAKDASH);
937 else if (name == "dots")
938 specialChar(cur, InsetSpecialChar::LDOTS);
939 else if (name == "end-of-sentence")
940 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
941 else if (name == "menu-separator")
942 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
943 else if (name.empty())
944 lyxerr << "LyX function 'specialchar-insert' needs an argument." << endl;
946 lyxerr << "Wrong argument for LyX function 'specialchar-insert'." << endl;
950 case LFUN_WORD_UPCASE:
951 changeCase(cur, text_uppercase);
954 case LFUN_WORD_LOWCASE:
955 changeCase(cur, text_lowercase);
958 case LFUN_WORD_CAPITALIZE:
959 changeCase(cur, text_capitalization);
962 case LFUN_CHARS_TRANSPOSE:
967 cur.message(_("Paste"));
968 cap::replaceSelection(cur);
971 string const arg = to_utf8(cmd.argument());
973 if (theClipboard().isInternal())
974 pasteFromStack(cur, bv->buffer().errorList("Paste"), 0);
975 else if (theClipboard().hasGraphicsContents())
976 pasteClipboardGraphics(cur, bv->buffer().errorList("Paste"));
978 pasteClipboardText(cur, bv->buffer().errorList("Paste"));
979 } else if (isStrUnsignedInt(arg)) {
980 // we have a numerical argument
981 pasteFromStack(cur, bv->buffer().errorList("Paste"),
982 convert<unsigned int>(arg));
984 Clipboard::GraphicsType type = Clipboard::AnyGraphicsType;
986 type = Clipboard::PdfGraphicsType;
987 else if (arg == "png")
988 type = Clipboard::PngGraphicsType;
989 else if (arg == "jpeg")
990 type = Clipboard::JpegGraphicsType;
991 else if (arg == "linkback")
992 type = Clipboard::LinkBackGraphicsType;
994 LASSERT(false, /**/);
996 pasteClipboardGraphics(cur, bv->buffer().errorList("Paste"), type);
999 bv->buffer().errors("Paste");
1000 cur.clearSelection(); // bug 393
1006 cutSelection(cur, true, true);
1007 cur.message(_("Cut"));
1012 cur.message(_("Copy"));
1015 case LFUN_SERVER_GET_XY:
1016 cur.message(from_utf8(
1017 convert<string>(tm.cursorX(cur.top(), cur.boundary()))
1018 + ' ' + convert<string>(tm.cursorY(cur.top(), cur.boundary()))));
1021 case LFUN_SERVER_SET_XY: {
1024 istringstream is(to_utf8(cmd.argument()));
1027 lyxerr << "SETXY: Could not parse coordinates in '"
1028 << to_utf8(cmd.argument()) << endl;
1030 tm.setCursorFromCoordinates(cur, x, y);
1034 case LFUN_SERVER_GET_LAYOUT:
1035 cur.message(cur.paragraph().layout().name());
1039 docstring layout = cmd.argument();
1040 LYXERR(Debug::INFO, "LFUN_LAYOUT: (arg) " << to_utf8(layout));
1042 Paragraph const & para = cur.paragraph();
1043 docstring const old_layout = para.layout().name();
1044 DocumentClass const & tclass = bv->buffer().params().documentClass();
1047 layout = tclass.defaultLayoutName();
1049 if (para.forceEmptyLayout())
1050 // in this case only the empty layout is allowed
1051 layout = tclass.emptyLayoutName();
1052 else if (para.useEmptyLayout()) {
1053 // in this case, default layout maps to empty layout
1054 if (layout == tclass.defaultLayoutName())
1055 layout = tclass.emptyLayoutName();
1057 // otherwise, the empty layout maps to the default
1058 if (layout == tclass.emptyLayoutName())
1059 layout = tclass.defaultLayoutName();
1062 bool hasLayout = tclass.hasLayout(layout);
1064 // If the entry is obsolete, use the new one instead.
1066 docstring const & obs = tclass[layout].obsoleted_by();
1072 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
1073 from_utf8(N_(" not known")));
1077 bool change_layout = (old_layout != layout);
1079 if (!change_layout && cur.selection() &&
1080 cur.selBegin().pit() != cur.selEnd().pit())
1082 pit_type spit = cur.selBegin().pit();
1083 pit_type epit = cur.selEnd().pit() + 1;
1084 while (spit != epit) {
1085 if (pars_[spit].layout().name() != old_layout) {
1086 change_layout = true;
1094 setLayout(cur, layout);
1099 case LFUN_CLIPBOARD_PASTE:
1100 cur.clearSelection();
1101 pasteClipboardText(cur, bv->buffer().errorList("Paste"),
1102 cmd.argument() == "paragraph");
1103 bv->buffer().errors("Paste");
1106 case LFUN_PRIMARY_SELECTION_PASTE:
1107 pasteString(cur, theSelection().get(),
1108 cmd.argument() == "paragraph");
1111 case LFUN_UNICODE_INSERT: {
1112 if (cmd.argument().empty())
1114 docstring hexstring = cmd.argument();
1115 if (isHex(hexstring)) {
1116 char_type c = hexToInt(hexstring);
1117 if (c >= 32 && c < 0x10ffff) {
1118 lyxerr << "Inserting c: " << c << endl;
1119 docstring s = docstring(1, c);
1120 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
1126 case LFUN_QUOTE_INSERT: {
1127 Paragraph & par = cur.paragraph();
1128 pos_type pos = cur.pos();
1129 BufferParams const & bufparams = bv->buffer().params();
1130 Layout const & style = par.layout();
1131 if (!style.pass_thru
1132 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
1133 // this avoids a double undo
1134 // FIXME: should not be needed, ideally
1135 if (!cur.selection())
1137 cap::replaceSelection(cur);
1142 else if (cur.prevInset() && cur.prevInset()->isSpace())
1145 c = par.getChar(pos - 1);
1146 string arg = to_utf8(cmd.argument());
1147 cur.insert(new InsetQuotes(c, bufparams.quotes_language,
1148 (arg == "single") ? InsetQuotes::SingleQuotes
1149 : InsetQuotes::DoubleQuotes));
1153 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
1157 case LFUN_DATE_INSERT: {
1158 string const format = cmd.argument().empty()
1159 ? lyxrc.date_insert_format : to_utf8(cmd.argument());
1160 string const time = formatted_time(current_time(), format);
1161 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, time));
1165 case LFUN_MOUSE_TRIPLE:
1166 if (cmd.button() == mouse_button::button1) {
1175 case LFUN_MOUSE_DOUBLE:
1176 if (cmd.button() == mouse_button::button1) {
1177 selectWord(cur, WHOLE_WORD_STRICT);
1182 // Single-click on work area
1183 case LFUN_MOUSE_PRESS:
1184 // We are not marking a selection with the keyboard in any case.
1185 cur.bv().cursor().mark() = false;
1186 switch (cmd.button()) {
1187 case mouse_button::button1:
1189 if (!bv->mouseSetCursor(cur, cmd.argument() == "region-select"))
1190 cur.updateFlags(Update::SinglePar | Update::FitCursor);
1193 case mouse_button::button2:
1194 // Middle mouse pasting.
1195 if (!cap::selection()) {
1196 // There is no local selection in the current buffer, so try to
1197 // paste primary selection instead.
1198 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE,
1200 // Nothing else to do.
1204 // Copy the selection buffer to the clipboard stack, because we want it
1205 // to appear in the "Edit->Paste recent" menu.
1206 cap::copySelectionToStack();
1207 cap::pasteSelection(bv->cursor(), bv->buffer().errorList("Paste"));
1208 cur.updateFlags(Update::Force | Update::FitCursor);
1209 bv->buffer().errors("Paste");
1210 bv->buffer().markDirty();
1211 bv->cursor().finishUndo();
1214 case mouse_button::button3:
1215 if (cur.selection()) {
1216 DocIterator const selbeg = cur.selectionBegin();
1217 DocIterator const selend = cur.selectionEnd();
1218 Cursor tmpcur = cur;
1219 tm.setCursorFromCoordinates(tmpcur, cmd.x, cmd.y);
1220 // Don't do anything if we right-click a selection, a selection
1221 // context menu should popup instead.
1222 if (tmpcur < selbeg || tmpcur >= selend) {
1227 if (!bv->mouseSetCursor(cur, false)) {
1228 cur.updateFlags(Update::SinglePar | Update::FitCursor);
1233 } // switch (cmd.button())
1236 case LFUN_MOUSE_MOTION: {
1237 // Mouse motion with right or middle mouse do nothing for now.
1238 if (cmd.button() != mouse_button::button1) {
1242 // ignore motions deeper nested than the real anchor
1243 Cursor & bvcur = cur.bv().cursor();
1244 if (!bvcur.anchor_.hasPart(cur)) {
1248 CursorSlice old = bvcur.top();
1250 int const wh = bv->workHeight();
1251 int const y = max(0, min(wh - 1, cmd.y));
1253 tm.setCursorFromCoordinates(cur, cmd.x, y);
1254 cur.setTargetX(cmd.x);
1256 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1258 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1259 // This is to allow jumping over large insets
1260 if (cur.top() == old) {
1262 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1264 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1266 // We continue with our existing selection or start a new one, so don't
1267 // reset the anchor.
1268 bvcur.setCursor(cur);
1269 bvcur.selection() = true;
1270 if (cur.top() == old) {
1271 // We didn't move one iota, so no need to update the screen.
1272 cur.updateFlags(Update::SinglePar | Update::FitCursor);
1279 case LFUN_MOUSE_RELEASE:
1280 switch (cmd.button()) {
1281 case mouse_button::button1:
1282 // Cursor was set at LFUN_MOUSE_PRESS or LFUN_MOUSE_MOTION time.
1283 // If there is a new selection, update persistent selection;
1284 // otherwise, single click does not clear persistent selection
1286 if (cur.selection()) {
1287 // Finish selection.
1288 // If double click, cur is moved to the end of word by selectWord
1289 // but bvcur is current mouse position.
1290 cur.bv().cursor().selection() = true;
1292 // FIXME: We could try to handle drag and drop of selection here.
1296 case mouse_button::button2:
1297 // Middle mouse pasting is handled at mouse press time,
1298 // see LFUN_MOUSE_PRESS.
1302 case mouse_button::button3:
1303 // Cursor was set at LFUN_MOUSE_PRESS time.
1304 // FIXME: If there is a selection we could try to handle a special
1305 // drag & drop context menu.
1309 case mouse_button::none:
1310 case mouse_button::button4:
1311 case mouse_button::button5:
1313 } // switch (cmd.button())
1317 case LFUN_SELF_INSERT: {
1318 if (cmd.argument().empty())
1321 // Automatically delete the currently selected
1322 // text and replace it with what is being
1323 // typed in now. Depends on lyxrc settings
1324 // "auto_region_delete", which defaults to
1327 if (lyxrc.auto_region_delete && cur.selection())
1328 cutSelection(cur, false, false);
1330 cur.clearSelection();
1331 Font const old_font = cur.real_current_font;
1333 docstring::const_iterator cit = cmd.argument().begin();
1334 docstring::const_iterator end = cmd.argument().end();
1335 for (; cit != end; ++cit)
1336 bv->translateAndInsert(*cit, this, cur);
1339 moveCursor(cur, false);
1343 case LFUN_HYPERLINK_INSERT: {
1344 InsetCommandParams p(HYPERLINK_CODE);
1346 if (cur.selection()) {
1347 content = cur.selectionAsString(false);
1348 cutSelection(cur, true, false);
1350 p["target"] = (cmd.argument().empty()) ?
1351 content : cmd.argument();
1352 string const data = InsetCommand::params2string("href", p);
1353 if (p["target"].empty()) {
1354 bv->showDialog("href", data);
1356 FuncRequest fr(LFUN_INSET_INSERT, data);
1362 case LFUN_LABEL_INSERT: {
1363 InsetCommandParams p(LABEL_CODE);
1364 // Try to generate a valid label
1365 p["name"] = (cmd.argument().empty()) ?
1366 cur.getPossibleLabel() :
1368 string const data = InsetCommand::params2string("label", p);
1370 if (cmd.argument().empty()) {
1371 bv->showDialog("label", data);
1373 FuncRequest fr(LFUN_INSET_INSERT, data);
1379 case LFUN_INFO_INSERT: {
1380 Inset * inset = createInset(cur.bv().buffer(), cmd);
1383 // if an empty inset is created (cmd.argument() is empty)
1384 // use current selection as parameter.
1385 if (cmd.argument().empty() && cur.selection()) {
1386 // use selected text as info to avoid a separate UI
1387 docstring ds = cur.selectionAsString(false);
1388 cutSelection(cur, true, false);
1389 static_cast<InsetInfo *>(inset)->setInfo(to_utf8(ds));
1390 static_cast<InsetInfo *>(inset)->updateInfo();
1392 insertInset(cur, inset);
1397 case LFUN_LIST_INSERT:
1399 case LFUN_CAPTION_INSERT:
1400 case LFUN_FOOTNOTE_INSERT:
1401 case LFUN_NOTE_INSERT:
1402 case LFUN_FLEX_INSERT:
1403 case LFUN_BOX_INSERT:
1404 case LFUN_BRANCH_INSERT:
1405 case LFUN_BIBITEM_INSERT:
1406 case LFUN_ERT_INSERT:
1407 case LFUN_LISTING_INSERT:
1408 case LFUN_MARGINALNOTE_INSERT:
1409 case LFUN_OPTIONAL_INSERT:
1410 case LFUN_ENVIRONMENT_INSERT:
1411 case LFUN_INDEX_INSERT:
1412 // Open the inset, and move the current selection
1414 doInsertInset(cur, this, cmd, true, true);
1416 // Some insets are numbered, others are shown in the outline pane so
1417 // let's update the labels and the toc backend.
1418 updateLabels(bv->buffer());
1421 case LFUN_TABULAR_INSERT:
1422 // if there were no arguments, just open the dialog
1423 if (doInsertInset(cur, this, cmd, false, true))
1426 bv->showDialog("tabularcreate");
1430 case LFUN_FLOAT_INSERT:
1431 case LFUN_FLOAT_WIDE_INSERT:
1432 case LFUN_WRAP_INSERT: {
1433 bool content = cur.selection(); // will some text be moved into the inset?
1435 doInsertInset(cur, this, cmd, true, true);
1437 ParagraphList & pars = cur.text()->paragraphs();
1439 DocumentClass const & tclass = bv->buffer().params().documentClass();
1441 // add a separate paragraph for the caption inset
1442 pars.push_back(Paragraph());
1443 pars.back().setInsetOwner(pars[0].inInset());
1444 pars.back().setEmptyOrDefaultLayout(tclass);
1445 int cap_pit = pars.size() - 1;
1447 // if an empty inset was created, we create an additional empty
1448 // paragraph at the bottom so that the user can choose where to put
1449 // the graphics (or table).
1451 pars.push_back(Paragraph());
1452 pars.back().setInsetOwner(pars[0].inInset());
1453 pars.back().setEmptyOrDefaultLayout(tclass);
1456 // reposition the cursor to the caption
1457 cur.pit() = cap_pit;
1459 // FIXME: This Text/Cursor dispatch handling is a mess!
1460 // We cannot use Cursor::dispatch here it needs access to up to
1462 FuncRequest cmd_caption(LFUN_CAPTION_INSERT);
1463 cur.text()->dispatch(cur, cmd_caption);
1464 cur.updateFlags(Update::Force);
1465 // FIXME: When leaving the Float (or Wrap) inset we should
1466 // delete any empty paragraph left above or below the
1471 case LFUN_NOMENCL_INSERT: {
1472 FuncRequest cmd1 = cmd;
1473 if (cmd.argument().empty())
1474 cmd1 = FuncRequest(cmd,
1475 bv->cursor().innerText()->getStringToIndex(bv->cursor()));
1476 Inset * inset = createInset(cur.bv().buffer(), cmd1);
1480 cur.clearSelection();
1481 insertInset(cur, inset);
1482 // Show the dialog for the nomenclature entry, since the
1483 // description entry still needs to be filled in.
1484 if (cmd.action == LFUN_NOMENCL_INSERT)
1485 inset->edit(cur, true);
1490 case LFUN_INDEX_PRINT:
1491 case LFUN_NOMENCL_PRINT:
1492 case LFUN_TOC_INSERT:
1493 case LFUN_LINE_INSERT:
1494 case LFUN_NEWPAGE_INSERT:
1496 doInsertInset(cur, this, cmd, false, false);
1500 case LFUN_DEPTH_DECREMENT:
1501 changeDepth(cur, DEC_DEPTH);
1504 case LFUN_DEPTH_INCREMENT:
1505 changeDepth(cur, INC_DEPTH);
1508 case LFUN_MATH_DISPLAY:
1509 mathDispatch(cur, cmd, true);
1512 case LFUN_MATH_IMPORT_SELECTION:
1513 case LFUN_MATH_MODE:
1514 if (cmd.argument() == "on")
1515 // don't pass "on" as argument
1516 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1518 mathDispatch(cur, cmd, false);
1521 case LFUN_MATH_MACRO:
1522 if (cmd.argument().empty())
1523 cur.errorMessage(from_utf8(N_("Missing argument")));
1525 string s = to_utf8(cmd.argument());
1526 string const s1 = token(s, ' ', 1);
1527 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1528 string const s2 = token(s, ' ', 2);
1529 MacroType type = MacroTypeNewcommand;
1531 type = MacroTypeDef;
1532 cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, false, type));
1533 //cur.nextInset()->edit(cur, true);
1537 // passthrough hat and underscore outside mathed:
1538 case LFUN_MATH_SUBSCRIPT:
1539 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1541 case LFUN_MATH_SUPERSCRIPT:
1542 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1545 case LFUN_MATH_INSERT:
1546 case LFUN_MATH_MATRIX:
1547 case LFUN_MATH_DELIM:
1548 case LFUN_MATH_BIGDELIM: {
1549 cap::replaceSelection(cur);
1550 cur.insert(new InsetMathHull(hullSimple));
1551 checkAndActivateInset(cur, true);
1552 LASSERT(cur.inMathed(), /**/);
1557 case LFUN_FONT_EMPH: {
1558 Font font(ignore_font, ignore_language);
1559 font.fontInfo().setEmph(FONT_TOGGLE);
1560 toggleAndShow(cur, this, font);
1564 case LFUN_FONT_BOLD: {
1565 Font font(ignore_font, ignore_language);
1566 font.fontInfo().setSeries(BOLD_SERIES);
1567 toggleAndShow(cur, this, font);
1571 case LFUN_FONT_NOUN: {
1572 Font font(ignore_font, ignore_language);
1573 font.fontInfo().setNoun(FONT_TOGGLE);
1574 toggleAndShow(cur, this, font);
1578 case LFUN_FONT_TYPEWRITER: {
1579 Font font(ignore_font, ignore_language);
1580 font.fontInfo().setFamily(TYPEWRITER_FAMILY); // no good
1581 toggleAndShow(cur, this, font);
1585 case LFUN_FONT_SANS: {
1586 Font font(ignore_font, ignore_language);
1587 font.fontInfo().setFamily(SANS_FAMILY);
1588 toggleAndShow(cur, this, font);
1592 case LFUN_FONT_ROMAN: {
1593 Font font(ignore_font, ignore_language);
1594 font.fontInfo().setFamily(ROMAN_FAMILY);
1595 toggleAndShow(cur, this, font);
1599 case LFUN_FONT_DEFAULT: {
1600 Font font(inherit_font, ignore_language);
1601 toggleAndShow(cur, this, font);
1605 case LFUN_FONT_UNDERLINE: {
1606 Font font(ignore_font, ignore_language);
1607 font.fontInfo().setUnderbar(FONT_TOGGLE);
1608 toggleAndShow(cur, this, font);
1612 case LFUN_FONT_SIZE: {
1613 Font font(ignore_font, ignore_language);
1614 setLyXSize(to_utf8(cmd.argument()), font.fontInfo());
1615 toggleAndShow(cur, this, font);
1619 case LFUN_LANGUAGE: {
1620 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1623 Font font(ignore_font, lang);
1624 toggleAndShow(cur, this, font);
1628 case LFUN_FONT_FREE_APPLY:
1629 toggleAndShow(cur, this, freefont, toggleall);
1630 cur.message(_("Character set"));
1633 // Set the freefont using the contents of \param data dispatched from
1634 // the frontends and apply it at the current cursor location.
1635 case LFUN_FONT_FREE_UPDATE: {
1638 if (font.fromString(to_utf8(cmd.argument()), toggle)) {
1641 toggleAndShow(cur, this, freefont, toggleall);
1642 cur.message(_("Character set"));
1644 lyxerr << "Argument not ok";
1649 case LFUN_FINISHED_LEFT:
1650 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_LEFT:\n" << cur);
1651 // We're leaving an inset, going left. If the inset is LTR, we're
1652 // leaving from the front, so we should not move (remain at --- but
1653 // not in --- the inset). If the inset is RTL, move left, without
1654 // entering the inset itself; i.e., move to after the inset.
1655 if (cur.paragraph().getFontSettings(
1656 cur.bv().buffer().params(), cur.pos()).isRightToLeft())
1657 cursorVisLeft(cur, true);
1660 case LFUN_FINISHED_RIGHT:
1661 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_RIGHT:\n" << cur);
1662 // We're leaving an inset, going right. If the inset is RTL, we're
1663 // leaving from the front, so we should not move (remain at --- but
1664 // not in --- the inset). If the inset is LTR, move right, without
1665 // entering the inset itself; i.e., move to after the inset.
1666 if (!cur.paragraph().getFontSettings(
1667 cur.bv().buffer().params(), cur.pos()).isRightToLeft())
1668 cursorVisRight(cur, true);
1671 case LFUN_FINISHED_BACKWARD:
1672 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_BACKWARD:\n" << cur);
1675 case LFUN_FINISHED_FORWARD:
1676 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_FORWARD:\n" << cur);
1678 cur.setCurrentFont();
1681 case LFUN_LAYOUT_PARAGRAPH: {
1683 params2string(cur.paragraph(), data);
1684 data = "show\n" + data;
1685 bv->showDialog("paragraph", data);
1689 case LFUN_PARAGRAPH_UPDATE: {
1691 params2string(cur.paragraph(), data);
1693 // Will the paragraph accept changes from the dialog?
1695 cur.inset().allowParagraphCustomization(cur.idx());
1697 data = "update " + convert<string>(accept) + '\n' + data;
1698 bv->updateDialog("paragraph", data);
1702 case LFUN_ACCENT_UMLAUT:
1703 case LFUN_ACCENT_CIRCUMFLEX:
1704 case LFUN_ACCENT_GRAVE:
1705 case LFUN_ACCENT_ACUTE:
1706 case LFUN_ACCENT_TILDE:
1707 case LFUN_ACCENT_CEDILLA:
1708 case LFUN_ACCENT_MACRON:
1709 case LFUN_ACCENT_DOT:
1710 case LFUN_ACCENT_UNDERDOT:
1711 case LFUN_ACCENT_UNDERBAR:
1712 case LFUN_ACCENT_CARON:
1713 case LFUN_ACCENT_BREVE:
1714 case LFUN_ACCENT_TIE:
1715 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1716 case LFUN_ACCENT_CIRCLE:
1717 case LFUN_ACCENT_OGONEK:
1718 theLyXFunc().handleKeyFunc(cmd.action);
1719 if (!cmd.argument().empty())
1720 // FIXME: Are all these characters encoded in one byte in utf8?
1721 bv->translateAndInsert(cmd.argument()[0], this, cur);
1724 case LFUN_FLOAT_LIST_INSERT: {
1725 DocumentClass const & tclass = bv->buffer().params().documentClass();
1726 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1728 if (cur.selection())
1729 cutSelection(cur, true, false);
1730 breakParagraph(cur);
1732 if (cur.lastpos() != 0) {
1733 cursorBackward(cur);
1734 breakParagraph(cur);
1737 docstring const laystr = cur.inset().useEmptyLayout() ?
1738 tclass.emptyLayoutName() :
1739 tclass.defaultLayoutName();
1740 setLayout(cur, laystr);
1741 ParagraphParameters p;
1742 setParagraphs(cur, p);
1743 // FIXME This should be simplified when InsetFloatList takes a
1744 // Buffer in its constructor.
1745 InsetFloatList * ifl = new InsetFloatList(to_utf8(cmd.argument()));
1746 ifl->setBuffer(bv->buffer());
1747 insertInset(cur, ifl);
1750 lyxerr << "Non-existent float type: "
1751 << to_utf8(cmd.argument()) << endl;
1756 case LFUN_CHANGE_ACCEPT: {
1757 acceptOrRejectChanges(cur, ACCEPT);
1761 case LFUN_CHANGE_REJECT: {
1762 acceptOrRejectChanges(cur, REJECT);
1766 case LFUN_THESAURUS_ENTRY: {
1767 docstring arg = cmd.argument();
1769 arg = cur.selectionAsString(false);
1771 if (arg.size() > 100 || arg.empty()) {
1772 // Get word or selection
1773 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1774 arg = cur.selectionAsString(false);
1777 bv->showDialog("thesaurus", to_utf8(arg));
1781 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1782 // Given data, an encoding of the ParagraphParameters
1783 // generated in the Paragraph dialog, this function sets
1784 // the current paragraph, or currently selected paragraphs,
1786 // NOTE: This function overrides all existing settings.
1787 setParagraphs(cur, cmd.argument());
1788 cur.message(_("Paragraph layout set"));
1792 case LFUN_PARAGRAPH_PARAMS: {
1793 // Given data, an encoding of the ParagraphParameters as we'd
1794 // find them in a LyX file, this function modifies the current paragraph,
1795 // or currently selected paragraphs.
1796 // NOTE: This function only modifies, and does not override, existing
1798 setParagraphs(cur, cmd.argument(), true);
1799 cur.message(_("Paragraph layout set"));
1804 if (cur.selection()) {
1805 cur.selection() = false;
1808 // This used to be LFUN_FINISHED_RIGHT, I think FORWARD is more
1809 // correct, but I'm not 100% sure -- dov, 071019
1810 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
1814 case LFUN_OUTLINE_UP:
1815 outline(OutlineUp, cur);
1816 setCursor(cur, cur.pit(), 0);
1817 updateLabels(cur.buffer());
1821 case LFUN_OUTLINE_DOWN:
1822 outline(OutlineDown, cur);
1823 setCursor(cur, cur.pit(), 0);
1824 updateLabels(cur.buffer());
1828 case LFUN_OUTLINE_IN:
1829 outline(OutlineIn, cur);
1830 updateLabels(cur.buffer());
1834 case LFUN_OUTLINE_OUT:
1835 outline(OutlineOut, cur);
1836 updateLabels(cur.buffer());
1841 LYXERR(Debug::ACTION, "Command " << cmd << " not DISPATCHED by Text");
1846 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1848 // FIXME: The cursor flag is reset two lines below
1849 // so we need to check here if some of the LFUN did touch that.
1850 // for now only Text::erase() and Text::backspace() do that.
1851 // The plan is to verify all the LFUNs and then to remove this
1852 // singleParUpdate boolean altogether.
1853 if (cur.result().update() & Update::Force) {
1854 singleParUpdate = false;
1858 // FIXME: the following code should go in favor of fine grained
1859 // update flag treatment.
1860 if (singleParUpdate) {
1861 // Inserting characters does not change par height in general. So, try
1862 // to update _only_ this paragraph. BufferView will detect if a full
1863 // metrics update is needed anyway.
1864 cur.updateFlags(Update::SinglePar | Update::FitCursor);
1869 && &oldTopSlice.inset() == &cur.inset()
1870 && oldTopSlice.idx() == cur.idx()
1871 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1872 && !cur.selection())
1873 // FIXME: it would be better if we could just do this
1875 //if (cur.result().update() != Update::FitCursor)
1878 // But some LFUNs do not set Update::FitCursor when needed, so we
1879 // do it for all. This is not very harmfull as FitCursor will provoke
1880 // a full redraw only if needed but still, a proper review of all LFUN
1881 // should be done and this needsUpdate boolean can then be removed.
1882 cur.updateFlags(Update::FitCursor);
1884 cur.updateFlags(Update::Force | Update::FitCursor);
1888 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
1889 FuncStatus & flag) const
1891 LASSERT(cur.text() == this, /**/);
1893 Font const & font = cur.real_current_font;
1894 FontInfo const & fontinfo = font.fontInfo();
1896 InsetCode code = NO_CODE;
1898 switch (cmd.action) {
1900 case LFUN_DEPTH_DECREMENT:
1901 enable = changeDepthAllowed(cur, DEC_DEPTH);
1904 case LFUN_DEPTH_INCREMENT:
1905 enable = changeDepthAllowed(cur, INC_DEPTH);
1909 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1912 case LFUN_BIBITEM_INSERT:
1913 enable = (cur.paragraph().layout().labeltype == LABEL_BIBLIO
1917 case LFUN_DIALOG_SHOW_NEW_INSET:
1918 if (cmd.argument() == "bibitem")
1919 code = BIBITEM_CODE;
1920 else if (cmd.argument() == "bibtex")
1922 else if (cmd.argument() == "box")
1924 else if (cmd.argument() == "branch")
1926 else if (cmd.argument() == "citation")
1928 else if (cmd.argument() == "ert")
1930 else if (cmd.argument() == "external")
1931 code = EXTERNAL_CODE;
1932 else if (cmd.argument() == "float")
1934 else if (cmd.argument() == "graphics")
1935 code = GRAPHICS_CODE;
1936 else if (cmd.argument() == "href")
1937 code = HYPERLINK_CODE;
1938 else if (cmd.argument() == "include")
1939 code = INCLUDE_CODE;
1940 else if (cmd.argument() == "index")
1942 else if (cmd.argument() == "nomenclature")
1943 code = NOMENCL_CODE;
1944 else if (cmd.argument() == "label")
1946 else if (cmd.argument() == "note")
1948 else if (cmd.argument() == "ref")
1950 else if (cmd.argument() == "space")
1952 else if (cmd.argument() == "toc")
1954 else if (cmd.argument() == "vspace")
1956 else if (cmd.argument() == "wrap")
1958 else if (cmd.argument() == "listings")
1959 code = LISTINGS_CODE;
1962 case LFUN_ERT_INSERT:
1965 case LFUN_LISTING_INSERT:
1966 code = LISTINGS_CODE;
1968 case LFUN_FOOTNOTE_INSERT:
1971 case LFUN_TABULAR_INSERT:
1972 code = TABULAR_CODE;
1974 case LFUN_MARGINALNOTE_INSERT:
1977 case LFUN_FLOAT_INSERT:
1978 case LFUN_FLOAT_WIDE_INSERT:
1981 case LFUN_WRAP_INSERT:
1984 case LFUN_FLOAT_LIST_INSERT:
1985 code = FLOAT_LIST_CODE;
1988 case LFUN_LIST_INSERT:
1992 case LFUN_CAPTION_INSERT:
1993 code = CAPTION_CODE;
1995 case LFUN_NOTE_INSERT:
1997 // in commands (sections etc., only Notes are allowed)
1998 enable = (cmd.argument().empty() || cmd.getArg(0) == "Note" ||
1999 !cur.paragraph().layout().isCommand());
2001 case LFUN_FLEX_INSERT: {
2003 string s = cmd.getArg(0);
2005 cur.buffer().params().documentClass().insetLayout(from_utf8(s));
2006 if (il.lyxtype() != "charstyle" &&
2007 il.lyxtype() != "custom" &&
2008 il.lyxtype() != "element" &&
2009 il.lyxtype ()!= "standard")
2013 case LFUN_BOX_INSERT:
2016 case LFUN_BRANCH_INSERT:
2018 if (cur.buffer().masterBuffer()->params().branchlist().empty())
2021 case LFUN_LABEL_INSERT:
2024 case LFUN_INFO_INSERT:
2027 case LFUN_OPTIONAL_INSERT:
2029 enable = cur.paragraph().insetList().count(OPTARG_CODE)
2030 < cur.paragraph().layout().optionalargs;
2032 case LFUN_ENVIRONMENT_INSERT:
2035 case LFUN_INDEX_INSERT:
2038 case LFUN_INDEX_PRINT:
2039 code = INDEX_PRINT_CODE;
2041 case LFUN_NOMENCL_INSERT:
2042 code = NOMENCL_CODE;
2044 case LFUN_NOMENCL_PRINT:
2045 code = NOMENCL_PRINT_CODE;
2047 case LFUN_TOC_INSERT:
2050 case LFUN_HYPERLINK_INSERT:
2051 code = HYPERLINK_CODE;
2053 case LFUN_QUOTE_INSERT:
2054 // always allow this, since we will inset a raw quote
2055 // if an inset is not allowed.
2057 case LFUN_SPECIALCHAR_INSERT:
2058 code = SPECIALCHAR_CODE;
2060 case LFUN_SPACE_INSERT:
2061 // slight hack: we know this is allowed in math mode
2066 case LFUN_INSET_MODIFY:
2067 // We need to disable this, because we may get called for a
2069 // InsetTabular::getStatus() -> InsetText::getStatus()
2070 // and we don't handle LFUN_INSET_MODIFY.
2074 case LFUN_FONT_EMPH:
2075 flag.setOnOff(fontinfo.emph() == FONT_ON);
2078 case LFUN_FONT_NOUN:
2079 flag.setOnOff(fontinfo.noun() == FONT_ON);
2082 case LFUN_FONT_BOLD:
2083 flag.setOnOff(fontinfo.series() == BOLD_SERIES);
2086 case LFUN_FONT_SANS:
2087 flag.setOnOff(fontinfo.family() == SANS_FAMILY);
2090 case LFUN_FONT_ROMAN:
2091 flag.setOnOff(fontinfo.family() == ROMAN_FAMILY);
2094 case LFUN_FONT_TYPEWRITER:
2095 flag.setOnOff(fontinfo.family() == TYPEWRITER_FAMILY);
2100 enable = cur.selection();
2104 if (cmd.argument().empty()) {
2105 if (theClipboard().isInternal())
2106 enable = cap::numberOfSelections() > 0;
2108 enable = !theClipboard().empty();
2112 // we have an argument
2113 string const arg = to_utf8(cmd.argument());
2114 if (isStrUnsignedInt(arg)) {
2115 // it's a number and therefore means the internal stack
2116 unsigned int n = convert<unsigned int>(arg);
2117 enable = cap::numberOfSelections() > n;
2121 // explicit graphics type?
2122 if ((arg == "pdf" && theClipboard().hasGraphicsContents(Clipboard::PdfGraphicsType))
2123 || (arg == "png" && theClipboard().hasGraphicsContents(Clipboard::PngGraphicsType))
2124 || (arg == "jpeg" && theClipboard().hasGraphicsContents(Clipboard::JpegGraphicsType))
2125 || (arg == "linkback" && theClipboard().hasGraphicsContents(Clipboard::LinkBackGraphicsType))) {
2135 case LFUN_CLIPBOARD_PASTE:
2136 enable = !theClipboard().empty();
2139 case LFUN_PRIMARY_SELECTION_PASTE:
2140 enable = cur.selection() || !theSelection().empty();
2143 case LFUN_PARAGRAPH_MOVE_UP:
2144 enable = cur.pit() > 0 && !cur.selection();
2147 case LFUN_PARAGRAPH_MOVE_DOWN:
2148 enable = cur.pit() < cur.lastpit() && !cur.selection();
2151 case LFUN_INSET_DISSOLVE:
2152 if (!cmd.argument().empty()) {
2153 InsetLayout il = cur.inset().getLayout(cur.buffer().params());
2154 enable = cur.inset().lyxCode() == FLEX_CODE
2155 && il.lyxtype() == to_utf8(cmd.argument());
2157 enable = !isMainText(cur.bv().buffer())
2158 && cur.inset().nargs() == 1;
2162 case LFUN_CHANGE_ACCEPT:
2163 case LFUN_CHANGE_REJECT:
2164 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
2165 // In principle, these LFUNs should only be enabled if there
2166 // is a change at the current position/in the current selection.
2167 // However, without proper optimizations, this will inevitably
2168 // result in unacceptable performance - just imagine a user who
2169 // wants to select the complete content of a long document.
2173 case LFUN_OUTLINE_UP:
2174 case LFUN_OUTLINE_DOWN:
2175 case LFUN_OUTLINE_IN:
2176 case LFUN_OUTLINE_OUT:
2177 enable = (cur.paragraph().layout().toclevel != Layout::NOT_IN_TOC);
2180 case LFUN_NEWLINE_INSERT:
2181 // LaTeX restrictions (labels or empty par)
2182 enable = (cur.pos() > cur.paragraph().beginOfBody());
2185 case LFUN_SET_GRAPHICS_GROUP: {
2186 InsetGraphics * ins = graphics::getCurrentGraphicsInset(cur);
2190 flag.setOnOff(to_utf8(cmd.argument()) == ins->getParams().groupId);
2194 case LFUN_WORD_DELETE_FORWARD:
2195 case LFUN_WORD_DELETE_BACKWARD:
2196 case LFUN_LINE_DELETE:
2197 case LFUN_WORD_FORWARD:
2198 case LFUN_WORD_BACKWARD:
2199 case LFUN_WORD_RIGHT:
2200 case LFUN_WORD_LEFT:
2201 case LFUN_CHAR_FORWARD:
2202 case LFUN_CHAR_FORWARD_SELECT:
2203 case LFUN_CHAR_BACKWARD:
2204 case LFUN_CHAR_BACKWARD_SELECT:
2205 case LFUN_CHAR_LEFT:
2206 case LFUN_CHAR_LEFT_SELECT:
2207 case LFUN_CHAR_RIGHT:
2208 case LFUN_CHAR_RIGHT_SELECT:
2210 case LFUN_UP_SELECT:
2212 case LFUN_DOWN_SELECT:
2213 case LFUN_PARAGRAPH_UP_SELECT:
2214 case LFUN_PARAGRAPH_DOWN_SELECT:
2215 case LFUN_LINE_BEGIN_SELECT:
2216 case LFUN_LINE_END_SELECT:
2217 case LFUN_WORD_FORWARD_SELECT:
2218 case LFUN_WORD_BACKWARD_SELECT:
2219 case LFUN_WORD_RIGHT_SELECT:
2220 case LFUN_WORD_LEFT_SELECT:
2221 case LFUN_WORD_SELECT:
2222 case LFUN_PARAGRAPH_UP:
2223 case LFUN_PARAGRAPH_DOWN:
2224 case LFUN_LINE_BEGIN:
2226 case LFUN_CHAR_DELETE_FORWARD:
2227 case LFUN_DELETE_FORWARD_SKIP:
2228 case LFUN_CHAR_DELETE_BACKWARD:
2229 case LFUN_DELETE_BACKWARD_SKIP:
2230 case LFUN_BREAK_PARAGRAPH:
2231 case LFUN_BREAK_PARAGRAPH_SKIP:
2232 case LFUN_PARAGRAPH_SPACING:
2233 case LFUN_INSET_INSERT:
2234 case LFUN_WORD_UPCASE:
2235 case LFUN_WORD_LOWCASE:
2236 case LFUN_WORD_CAPITALIZE:
2237 case LFUN_CHARS_TRANSPOSE:
2238 case LFUN_SERVER_GET_XY:
2239 case LFUN_SERVER_SET_XY:
2240 case LFUN_SERVER_GET_LAYOUT:
2242 case LFUN_DATE_INSERT:
2243 case LFUN_SELF_INSERT:
2244 case LFUN_LINE_INSERT:
2245 case LFUN_NEWPAGE_INSERT:
2246 case LFUN_MATH_DISPLAY:
2247 case LFUN_MATH_IMPORT_SELECTION:
2248 case LFUN_MATH_MODE:
2249 case LFUN_MATH_MACRO:
2250 case LFUN_MATH_MATRIX:
2251 case LFUN_MATH_DELIM:
2252 case LFUN_MATH_BIGDELIM:
2253 case LFUN_MATH_INSERT:
2254 case LFUN_MATH_SUBSCRIPT:
2255 case LFUN_MATH_SUPERSCRIPT:
2256 case LFUN_FONT_DEFAULT:
2257 case LFUN_FONT_UNDERLINE:
2258 case LFUN_FONT_SIZE:
2260 case LFUN_FONT_FREE_APPLY:
2261 case LFUN_FONT_FREE_UPDATE:
2262 case LFUN_LAYOUT_PARAGRAPH:
2263 case LFUN_PARAGRAPH_UPDATE:
2264 case LFUN_ACCENT_UMLAUT:
2265 case LFUN_ACCENT_CIRCUMFLEX:
2266 case LFUN_ACCENT_GRAVE:
2267 case LFUN_ACCENT_ACUTE:
2268 case LFUN_ACCENT_TILDE:
2269 case LFUN_ACCENT_CEDILLA:
2270 case LFUN_ACCENT_MACRON:
2271 case LFUN_ACCENT_DOT:
2272 case LFUN_ACCENT_UNDERDOT:
2273 case LFUN_ACCENT_UNDERBAR:
2274 case LFUN_ACCENT_CARON:
2275 case LFUN_ACCENT_BREVE:
2276 case LFUN_ACCENT_TIE:
2277 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
2278 case LFUN_ACCENT_CIRCLE:
2279 case LFUN_ACCENT_OGONEK:
2280 case LFUN_THESAURUS_ENTRY:
2281 case LFUN_PARAGRAPH_PARAMS_APPLY:
2282 case LFUN_PARAGRAPH_PARAMS:
2284 case LFUN_BUFFER_END:
2285 case LFUN_BUFFER_BEGIN:
2286 case LFUN_BUFFER_BEGIN_SELECT:
2287 case LFUN_BUFFER_END_SELECT:
2288 case LFUN_UNICODE_INSERT:
2289 // these are handled in our dispatch()
2298 && (cur.empty() || !cur.inset().insetAllowed(code)))
2301 flag.setEnabled(enable);
2306 void Text::pasteString(Cursor & cur, docstring const & clip,
2309 cur.clearSelection();
2310 if (!clip.empty()) {
2313 insertStringAsParagraphs(cur, clip);
2315 insertStringAsLines(cur, clip);