]> git.lyx.org Git - lyx.git/blob - src/Text3.cpp
small simplification
[lyx.git] / src / Text3.cpp
1 /**
2  * \file text3.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Asger Alstrup
7  * \author Lars Gullik Bjønnes
8  * \author Alfredo Braunstein
9  * \author Angus Leeming
10  * \author John Levon
11  * \author André Pönitz
12  *
13  * Full author contact details are available in file CREDITS.
14  */
15
16 #include <config.h>
17
18 #include "Text.h"
19
20 #include "Bidi.h"
21 #include "BranchList.h"
22 #include "FloatList.h"
23 #include "FuncStatus.h"
24 #include "Buffer.h"
25 #include "buffer_funcs.h"
26 #include "BufferParams.h"
27 #include "BufferView.h"
28 #include "Cursor.h"
29 #include "CutAndPaste.h"
30 #include "debug.h"
31 #include "DispatchResult.h"
32 #include "ErrorList.h"
33 #include "factory.h"
34 #include "FuncRequest.h"
35 #include "gettext.h"
36 #include "Intl.h"
37 #include "Language.h"
38 #include "Layout.h"
39 #include "LyXAction.h"
40 #include "LyXFunc.h"
41 #include "Lexer.h"
42 #include "LyXRC.h"
43 #include "Paragraph.h"
44 #include "paragraph_funcs.h"
45 #include "ParagraphParameters.h"
46 #include "Undo.h"
47 #include "VSpace.h"
48 #include "ParIterator.h"
49
50 #include "frontends/Clipboard.h"
51 #include "frontends/Selection.h"
52
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
60 #include "support/lstrings.h"
61 #include "support/lyxlib.h"
62 #include "support/convert.h"
63 #include "support/lyxtime.h"
64
65 #include "mathed/InsetMathHull.h"
66 #include "mathed/MathMacroTemplate.h"
67
68 #include <boost/current_function.hpp>
69
70 #include <clocale>
71 #include <sstream>
72
73 using std::endl;
74 using std::string;
75 using std::istringstream;
76 using std::ostringstream;
77
78 namespace lyx {
79
80 using cap::copySelection;
81 using cap::cutSelection;
82 using cap::pasteFromStack;
83 using cap::pasteClipboard;
84 using cap::replaceSelection;
85
86 using support::isStrUnsignedInt;
87 using support::token;
88
89 // globals...
90 static Font freefont(Font::ALL_IGNORE);
91 static bool toggleall = false;
92
93 static void toggleAndShow(Cursor & cur, Text * text,
94         Font const & font, bool toggleall = true)
95 {
96         text->toggleFree(cur, font, toggleall);
97
98         if (font.language() != ignore_language ||
99                         font.number() != Font::IGNORE) {
100                 TextMetrics const & tm = cur.bv().textMetrics(text);
101                 if (cur.boundary() != tm.isRTLBoundary(cur.pit(),
102                                                                                                                 cur.pos(), cur.real_current_font))
103                         text->setCursor(cur, cur.pit(), cur.pos(),
104                                                                                         false, !cur.boundary());
105         }
106 }
107
108
109 static void moveCursor(Cursor & cur, bool selecting)
110 {
111         if (selecting || cur.mark())
112                 cur.setSelection();
113 }
114
115
116 static void finishChange(Cursor & cur, bool selecting)
117 {
118         finishUndo();
119         moveCursor(cur, selecting);
120 }
121
122
123 static void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
124 {
125         recordUndo(cur);
126         docstring sel = cur.selectionAsString(false);
127
128         // It may happen that sel is empty but there is a selection
129         replaceSelection(cur);
130
131         if (sel.empty()) {
132 #ifdef ENABLE_ASSERTIONS
133                 const int old_pos = cur.pos();
134 #endif
135                 cur.insert(new InsetMathHull(hullSimple));
136                 BOOST_ASSERT(old_pos == cur.pos());
137                 cur.nextInset()->edit(cur, true);
138                 // don't do that also for LFUN_MATH_MODE
139                 // unless you want end up with always changing
140                 // to mathrm when opening an inlined inset --
141                 // I really hate "LyXfunc overloading"...
142                 if (display)
143                         cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
144                 // Avoid an unnecessary undo step if cmd.argument
145                 // is empty
146                 if (!cmd.argument().empty())
147                         cur.dispatch(FuncRequest(LFUN_MATH_INSERT,
148                                                  cmd.argument()));
149         } else {
150                 // create a macro if we see "\\newcommand"
151                 // somewhere, and an ordinary formula
152                 // otherwise
153                 if (sel.find(from_ascii("\\newcommand")) == string::npos
154                                 && sel.find(from_ascii("\\def")) == string::npos)
155                 {
156                         InsetMathHull * formula = new InsetMathHull;
157                         istringstream is(to_utf8(sel));
158                         Lexer lex(0, 0);
159                         lex.setStream(is);
160                         formula->read(cur.buffer(), lex);
161                         if (formula->getType() == hullNone)
162                                 // Don't create pseudo formulas if
163                                 // delimiters are left out
164                                 formula->mutate(hullSimple);
165                         cur.insert(formula);
166                 } else {
167                         cur.insert(new MathMacroTemplate(sel));
168                 }
169         }
170         cur.message(from_utf8(N_("Math editor mode")));
171 }
172
173
174 static void specialChar(Cursor & cur, InsetSpecialChar::Kind kind)
175 {
176         recordUndo(cur);
177         cap::replaceSelection(cur);
178         cur.insert(new InsetSpecialChar(kind));
179         cur.posRight();
180 }
181
182
183 static bool doInsertInset(Cursor & cur, Text * text,
184         FuncRequest const & cmd, bool edit, bool pastesel)
185 {
186         Inset * inset = createInset(&cur.bv(), cmd);
187         if (!inset)
188                 return false;
189
190         recordUndo(cur);
191         bool gotsel = false;
192         if (cur.selection()) {
193                 lyx::dispatch(FuncRequest(LFUN_CUT));
194                 gotsel = true;
195         }
196         text->insertInset(cur, inset);
197
198         if (edit)
199                 inset->edit(cur, true);
200
201         if (gotsel && pastesel) {
202                 lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
203                 // reset first par to default
204                 if (cur.lastpit() != 0 || cur.lastpos() != 0) {
205                         LayoutPtr const layout =
206                                 cur.buffer().params().getTextClass().defaultLayout();
207                         cur.text()->paragraphs().begin()->layout(layout);
208                 }
209         }
210         return true;
211 }
212
213
214 string const freefont2string()
215 {
216         return freefont.toString(toggleall);
217 }
218
219
220 void Text::number(Cursor & cur)
221 {
222         Font font(Font::ALL_IGNORE);
223         font.setNumber(Font::TOGGLE);
224         toggleAndShow(cur, this, font);
225 }
226
227
228 bool Text::isRTL(Buffer const & buffer, Paragraph const & par) const
229 {
230         return par.isRTL(buffer.params());
231 }
232
233
234 void Text::dispatch(Cursor & cur, FuncRequest & cmd)
235 {
236         LYXERR(Debug::ACTION) << "Text::dispatch: cmd: " << cmd << endl;
237
238         // FIXME: We use the update flag to indicates wether a singlePar or a
239         // full screen update is needed. We reset it here but shall we restore it
240         // at the end?
241         cur.noUpdate();
242
243         BOOST_ASSERT(cur.text() == this);
244         BufferView * bv = &cur.bv();
245         TextMetrics & tm = cur.bv().textMetrics(this);
246         CursorSlice oldTopSlice = cur.top();
247         bool oldBoundary = cur.boundary();
248         bool sel = cur.selection();
249         // Signals that, even if needsUpdate == false, an update of the
250         // cursor paragraph is required
251         bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
252                 LyXAction::SingleParUpdate);
253         // Signals that a full-screen update is required
254         bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
255                 LyXAction::NoUpdate) || singleParUpdate);
256         // Remember the old paragraph metric (_outer_ paragraph!)
257         ParagraphMetrics const & pm = cur.bv().parMetrics(
258                 cur.bottom().text(), cur.bottom().pit());
259         Dimension olddim = pm.dim();
260
261         switch (cmd.action) {
262
263         case LFUN_PARAGRAPH_MOVE_DOWN: {
264                 pit_type const pit = cur.pit();
265                 recUndo(cur, pit, pit + 1);
266                 finishUndo();
267                 std::swap(pars_[pit], pars_[pit + 1]);
268                 updateLabels(cur.buffer());
269                 needsUpdate = true;
270                 ++cur.pit();
271                 break;
272         }
273
274         case LFUN_PARAGRAPH_MOVE_UP: {
275                 pit_type const pit = cur.pit();
276                 recUndo(cur, pit - 1, pit);
277                 finishUndo();
278                 std::swap(pars_[pit], pars_[pit - 1]);
279                 updateLabels(cur.buffer());
280                 --cur.pit();
281                 needsUpdate = true;
282                 break;
283         }
284
285         case LFUN_APPENDIX: {
286                 Paragraph & par = cur.paragraph();
287                 bool start = !par.params().startOfAppendix();
288
289 // FIXME: The code below only makes sense at top level.
290 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
291                 // ensure that we have only one start_of_appendix in this document
292                 // FIXME: this don't work for multipart document!
293                 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
294                         if (pars_[tmp].params().startOfAppendix()) {
295                                 recUndo(cur, tmp);
296                                 pars_[tmp].params().startOfAppendix(false);
297                                 break;
298                         }
299                 }
300
301                 recordUndo(cur);
302                 par.params().startOfAppendix(start);
303
304                 // we can set the refreshing parameters now
305                 updateLabels(cur.buffer());
306                 break;
307         }
308
309         case LFUN_WORD_DELETE_FORWARD:
310                 if (cur.selection()) {
311                         cutSelection(cur, true, false);
312                 } else
313                         deleteWordForward(cur);
314                 finishChange(cur, false);
315                 break;
316
317         case LFUN_WORD_DELETE_BACKWARD:
318                 if (cur.selection()) {
319                         cutSelection(cur, true, false);
320                 } else
321                         deleteWordBackward(cur);
322                 finishChange(cur, false);
323                 break;
324
325         case LFUN_LINE_DELETE:
326                 if (cur.selection()) {
327                         cutSelection(cur, true, false);
328                 } else
329                         tm.deleteLineForward(cur);
330                 finishChange(cur, false);
331                 break;
332
333         case LFUN_BUFFER_BEGIN:
334         case LFUN_BUFFER_BEGIN_SELECT:
335                 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
336                 if (cur.depth() == 1) {
337                         needsUpdate |= cursorTop(cur);
338                 } else {
339                         cur.undispatched();
340                 }
341                 break;
342
343         case LFUN_BUFFER_END:
344         case LFUN_BUFFER_END_SELECT:
345                 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
346                 if (cur.depth() == 1) {
347                         needsUpdate |= cursorBottom(cur);
348                 } else {
349                         cur.undispatched();
350                 }
351                 break;
352
353         case LFUN_CHAR_FORWARD:
354         case LFUN_CHAR_FORWARD_SELECT:
355                 //lyxerr << BOOST_CURRENT_FUNCTION
356                 //       << " LFUN_CHAR_FORWARD[SEL]:\n" << cur << endl;
357                 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
358                 if (reverseDirectionNeeded(cur))
359                         needsUpdate |= cursorLeft(cur);
360                 else
361                         needsUpdate |= cursorRight(cur);
362
363                 if (!needsUpdate && oldTopSlice == cur.top()
364                                 && cur.boundary() == oldBoundary) {
365                         cur.undispatched();
366                         cmd = FuncRequest(LFUN_FINISHED_RIGHT);
367                 }
368                 break;
369
370         case LFUN_CHAR_BACKWARD:
371         case LFUN_CHAR_BACKWARD_SELECT:
372                 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
373                 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
374                 if (reverseDirectionNeeded(cur))
375                         needsUpdate |= cursorRight(cur);
376                 else
377                         needsUpdate |= cursorLeft(cur);
378
379                 if (!needsUpdate && oldTopSlice == cur.top()
380                         && cur.boundary() == oldBoundary) {
381                         cur.undispatched();
382                         cmd = FuncRequest(LFUN_FINISHED_LEFT);
383                 }
384                 break;
385
386         case LFUN_UP_SELECT:
387         case LFUN_DOWN_SELECT:
388         case LFUN_UP:
389         case LFUN_DOWN: {
390                 // stop/start the selection
391                 bool select = cmd.action == LFUN_DOWN_SELECT ||
392                         cmd.action == LFUN_UP_SELECT;
393                 cur.selHandle(select);
394                 
395                 // move cursor up/down
396                 bool up = cmd.action == LFUN_UP_SELECT || cmd.action == LFUN_UP;
397                 bool const successful = cur.upDownInText(up, needsUpdate);
398                 if (successful) {
399                         // notify insets which were left and get their update flags 
400                         notifyCursorLeaves(cur.beforeDispatchCursor(), cur);
401                         cur.fixIfBroken();
402                         
403                         // redraw if you leave mathed (for the decorations)
404                         needsUpdate |= cur.beforeDispatchCursor().inMathed();
405                 } else
406                         cur.undispatched();
407                 
408                 break;
409         }
410
411         case LFUN_PARAGRAPH_UP:
412         case LFUN_PARAGRAPH_UP_SELECT:
413                 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
414                 needsUpdate |= cursorUpParagraph(cur);
415                 break;
416
417         case LFUN_PARAGRAPH_DOWN:
418         case LFUN_PARAGRAPH_DOWN_SELECT:
419                 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
420                 needsUpdate |= cursorDownParagraph(cur);
421                 break;
422
423         case LFUN_SCREEN_UP_SELECT:
424                 needsUpdate |= cur.selHandle(true);
425                 if (cur.pit() == 0 && cur.textRow().pos() == 0)
426                         cur.undispatched();
427                 else {
428                         tm.cursorPrevious(cur);
429                 }
430                 break;
431
432         case LFUN_SCREEN_DOWN_SELECT:
433                 needsUpdate |= cur.selHandle(true);
434                 if (cur.pit() == cur.lastpit()
435                           && cur.textRow().endpos() == cur.lastpos())
436                         cur.undispatched();
437                 else {
438                         tm.cursorNext(cur);
439                 }
440                 break;
441
442         case LFUN_LINE_BEGIN:
443         case LFUN_LINE_BEGIN_SELECT:
444                 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
445                 needsUpdate |= tm.cursorHome(cur);
446                 break;
447
448         case LFUN_LINE_END:
449         case LFUN_LINE_END_SELECT:
450                 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
451                 needsUpdate |= tm.cursorEnd(cur);
452                 break;
453
454         case LFUN_WORD_FORWARD:
455         case LFUN_WORD_FORWARD_SELECT:
456                 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
457                 if (reverseDirectionNeeded(cur))
458                         needsUpdate |= cursorLeftOneWord(cur);
459                 else
460                         needsUpdate |= cursorRightOneWord(cur);
461                 break;
462
463         case LFUN_WORD_BACKWARD:
464         case LFUN_WORD_BACKWARD_SELECT:
465                 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
466                 if (reverseDirectionNeeded(cur))
467                         needsUpdate |= cursorRightOneWord(cur);
468                 else
469                         needsUpdate |= cursorLeftOneWord(cur);
470                 break;
471
472         case LFUN_WORD_SELECT: {
473                 selectWord(cur, WHOLE_WORD);
474                 finishChange(cur, true);
475                 break;
476         }
477
478         case LFUN_BREAK_LINE: {
479                 // Not allowed by LaTeX (labels or empty par)
480                 if (cur.pos() > cur.paragraph().beginOfBody()) {
481                         // this avoids a double undo
482                         // FIXME: should not be needed, ideally
483                         if (!cur.selection())
484                                 recordUndo(cur);
485                         cap::replaceSelection(cur);
486                         cur.insert(new InsetNewline);
487                         cur.posRight();
488                         moveCursor(cur, false);
489                 }
490                 break;
491         }
492
493         case LFUN_CHAR_DELETE_FORWARD:
494                 if (!cur.selection()) {
495                         if (cur.pos() == cur.paragraph().size())
496                                 // Par boundary, force full-screen update
497                                 singleParUpdate = false;
498                         needsUpdate |= erase(cur);
499                         cur.resetAnchor();
500                         // It is possible to make it a lot faster still
501                         // just comment out the line below...
502                 } else {
503                         cutSelection(cur, true, false);
504                         singleParUpdate = false;
505                 }
506                 moveCursor(cur, false);
507                 break;
508
509         case LFUN_DELETE_FORWARD_SKIP:
510                 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
511                 if (!cur.selection()) {
512                         if (cur.pos() == cur.lastpos()) {
513                                 cursorRight(cur);
514                                 cursorLeft(cur);
515                         }
516                         erase(cur);
517                         cur.resetAnchor();
518                 } else {
519                         cutSelection(cur, true, false);
520                 }
521                 break;
522
523
524         case LFUN_CHAR_DELETE_BACKWARD:
525                 if (!cur.selection()) {
526                         if (bv->getIntl().getTransManager().backspace()) {
527                                 // Par boundary, full-screen update
528                                 if (cur.pos() == 0)
529                                         singleParUpdate = false;
530                                 needsUpdate |= backspace(cur);
531                                 cur.resetAnchor();
532                                 // It is possible to make it a lot faster still
533                                 // just comment out the line below...
534                         }
535                 } else {
536                         cutSelection(cur, true, false);
537                         singleParUpdate = false;
538                 }
539                 break;
540
541         case LFUN_DELETE_BACKWARD_SKIP:
542                 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
543                 if (!cur.selection()) {
544                         // FIXME: look here
545                         //CursorSlice cur = cursor();
546                         backspace(cur);
547                         //anchor() = cur;
548                 } else {
549                         cutSelection(cur, true, false);
550                 }
551                 break;
552
553         case LFUN_BREAK_PARAGRAPH:
554                 cap::replaceSelection(cur);
555                 breakParagraph(cur, false);
556                 cur.resetAnchor();
557                 break;
558
559         case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
560                 cap::replaceSelection(cur);
561                 breakParagraph(cur, true);
562                 cur.resetAnchor();
563                 break;
564
565         case LFUN_BREAK_PARAGRAPH_SKIP: {
566                 // When at the beginning of a paragraph, remove
567                 // indentation.  Otherwise, do the same as LFUN_BREAK_PARAGRAPH.
568                 cap::replaceSelection(cur);
569                 if (cur.pos() == 0)
570                         cur.paragraph().params().labelWidthString(docstring());
571                 else
572                         breakParagraph(cur, false);
573                 cur.resetAnchor();
574                 break;
575         }
576
577         // TODO
578         // With the creation of LFUN_PARAGRAPH_PARAMS, this is now redundant,
579         // as its duties can be performed there. Should it be removed??
580         // FIXME For now, it can just dispatch LFUN_PARAGRAPH_PARAMS...
581         case LFUN_PARAGRAPH_SPACING: {
582                 Paragraph & par = cur.paragraph();
583                 Spacing::Space cur_spacing = par.params().spacing().getSpace();
584                 string cur_value = "1.0";
585                 if (cur_spacing == Spacing::Other)
586                         cur_value = par.params().spacing().getValueAsString();
587
588                 istringstream is(to_utf8(cmd.argument()));
589                 string tmp;
590                 is >> tmp;
591                 Spacing::Space new_spacing = cur_spacing;
592                 string new_value = cur_value;
593                 if (tmp.empty()) {
594                         lyxerr << "Missing argument to `paragraph-spacing'"
595                                << endl;
596                 } else if (tmp == "single") {
597                         new_spacing = Spacing::Single;
598                 } else if (tmp == "onehalf") {
599                         new_spacing = Spacing::Onehalf;
600                 } else if (tmp == "double") {
601                         new_spacing = Spacing::Double;
602                 } else if (tmp == "other") {
603                         new_spacing = Spacing::Other;
604                         string tmpval = "0.0";
605                         is >> tmpval;
606                         lyxerr << "new_value = " << tmpval << endl;
607                         if (tmpval != "0.0")
608                                 new_value = tmpval;
609                 } else if (tmp == "default") {
610                         new_spacing = Spacing::Default;
611                 } else {
612                         lyxerr << to_utf8(_("Unknown spacing argument: "))
613                                << to_utf8(cmd.argument()) << endl;
614                 }
615                 if (cur_spacing != new_spacing || cur_value != new_value)
616                         par.params().spacing(Spacing(new_spacing, new_value));
617                 break;
618         }
619
620         case LFUN_INSET_INSERT: {
621                 recordUndo(cur);
622                 Inset * inset = createInset(bv, cmd);
623                 if (inset) {
624                         // FIXME (Abdel 01/02/2006):
625                         // What follows would be a partial fix for bug 2154:
626                         //   http://bugzilla.lyx.org/show_bug.cgi?id=2154
627                         // This automatically put the label inset _after_ a
628                         // numbered section. It should be possible to extend the mechanism
629                         // to any kind of LateX environement.
630                         // The correct way to fix that bug would be at LateX generation.
631                         // I'll let the code here for reference as it could be used for some
632                         // other feature like "automatic labelling".
633                         /*
634                         Paragraph & par = pars_[cur.pit()];
635                         if (inset->lyxCode() == Inset::LABEL_CODE
636                                 && par.layout()->labeltype == LABEL_COUNTER) {
637                                 // Go to the end of the paragraph
638                                 // Warning: Because of Change-Tracking, the last
639                                 // position is 'size()' and not 'size()-1':
640                                 cur.pos() = par.size();
641                                 // Insert a new paragraph
642                                 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
643                                 dispatch(cur, fr);
644                         }
645                         */
646                         if (cur.selection())
647                                 cutSelection(cur, true, false);
648                         insertInset(cur, inset);
649                         cur.posRight();
650                 }
651                 break;
652         }
653
654         case LFUN_INSET_DISSOLVE:
655                 needsUpdate |= dissolveInset(cur);
656                 break;
657
658         case LFUN_INSET_SETTINGS:
659                 cur.inset().showInsetDialog(bv);
660                 break;
661
662         case LFUN_SPACE_INSERT:
663                 if (cur.paragraph().layout()->free_spacing)
664                         insertChar(cur, ' ');
665                 else {
666                         doInsertInset(cur, this, cmd, false, false);
667                         cur.posRight();
668                 }
669                 moveCursor(cur, false);
670                 break;
671
672         case LFUN_HYPHENATION_POINT_INSERT:
673                 specialChar(cur, InsetSpecialChar::HYPHENATION);
674                 break;
675
676         case LFUN_LIGATURE_BREAK_INSERT:
677                 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
678                 break;
679
680         case LFUN_DOTS_INSERT:
681                 specialChar(cur, InsetSpecialChar::LDOTS);
682                 break;
683
684         case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
685                 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
686                 break;
687
688         case LFUN_MENU_SEPARATOR_INSERT:
689                 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
690                 break;
691
692         case LFUN_WORD_UPCASE:
693                 changeCase(cur, Text::text_uppercase);
694                 break;
695
696         case LFUN_WORD_LOWCASE:
697                 changeCase(cur, Text::text_lowercase);
698                 break;
699
700         case LFUN_WORD_CAPITALIZE:
701                 changeCase(cur, Text::text_capitalization);
702                 break;
703
704         case LFUN_CHARS_TRANSPOSE:
705                 charsTranspose(cur);
706                 break;
707
708         case LFUN_PASTE:
709                 cur.message(_("Paste"));
710                 cap::replaceSelection(cur);
711                 if (cmd.argument().empty() && !theClipboard().isInternal())
712                         pasteClipboard(cur, bv->buffer().errorList("Paste"));
713                 else {
714                         string const arg(to_utf8(cmd.argument()));
715                         pasteFromStack(cur, bv->buffer().errorList("Paste"),
716                                         isStrUnsignedInt(arg) ?
717                                                 convert<unsigned int>(arg) :
718                                                 0);
719                 }
720                 bv->buffer().errors("Paste");
721                 cur.clearSelection(); // bug 393
722                 finishUndo();
723                 break;
724
725         case LFUN_CUT:
726                 cutSelection(cur, true, true);
727                 cur.message(_("Cut"));
728                 break;
729
730         case LFUN_COPY:
731                 copySelection(cur);
732                 cur.message(_("Copy"));
733                 break;
734
735         case LFUN_SERVER_GET_XY:
736                 cur.message(from_utf8(
737                         convert<string>(tm.cursorX(cur.top(), cur.boundary()))
738                         + ' ' + convert<string>(tm.cursorY(cur.top(), cur.boundary()))));
739                 break;
740
741         case LFUN_SERVER_SET_XY: {
742                 int x = 0;
743                 int y = 0;
744                 istringstream is(to_utf8(cmd.argument()));
745                 is >> x >> y;
746                 if (!is)
747                         lyxerr << "SETXY: Could not parse coordinates in '"
748                                << to_utf8(cmd.argument()) << std::endl;
749                 else
750                         tm.setCursorFromCoordinates(cur, x, y);
751                 break;
752         }
753
754         case LFUN_SERVER_GET_FONT:
755                 if (cur.current_font.shape() == Font::ITALIC_SHAPE)
756                         cur.message(from_ascii("E"));
757                 else if (cur.current_font.shape() == Font::SMALLCAPS_SHAPE)
758                         cur.message(from_ascii("N"));
759                 else
760                         cur.message(from_ascii("0"));
761                 break;
762
763         case LFUN_SERVER_GET_LAYOUT:
764                 cur.message(cur.paragraph().layout()->name());
765                 break;
766
767         case LFUN_LAYOUT: {
768                 docstring layout = cmd.argument();
769                 LYXERR(Debug::INFO) << "LFUN_LAYOUT: (arg) " << to_utf8(layout) << endl;
770
771                 docstring const old_layout = cur.paragraph().layout()->name();
772
773                 // Derive layout number from given argument (string)
774                 // and current buffer's textclass (number)
775                 TextClass const & tclass = bv->buffer().params().getTextClass();
776                 if (layout.empty())
777                         layout = tclass.defaultLayoutName();
778                 bool hasLayout = tclass.hasLayout(layout);
779
780                 // If the entry is obsolete, use the new one instead.
781                 if (hasLayout) {
782                         docstring const & obs = tclass[layout]->obsoleted_by();
783                         if (!obs.empty())
784                                 layout = obs;
785                 }
786
787                 if (!hasLayout) {
788                         cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
789                                 from_utf8(N_(" not known")));
790                         break;
791                 }
792
793                 bool change_layout = (old_layout != layout);
794
795                 if (!change_layout && cur.selection() &&
796                         cur.selBegin().pit() != cur.selEnd().pit())
797                 {
798                         pit_type spit = cur.selBegin().pit();
799                         pit_type epit = cur.selEnd().pit() + 1;
800                         while (spit != epit) {
801                                 if (pars_[spit].layout()->name() != old_layout) {
802                                         change_layout = true;
803                                         break;
804                                 }
805                                 ++spit;
806                         }
807                 }
808
809                 if (change_layout)
810                         setLayout(cur, layout);
811
812                 break;
813         }
814
815         case LFUN_CLIPBOARD_PASTE:
816                 cur.clearSelection();
817                 pasteClipboard(cur, bv->buffer().errorList("Paste"),
818                                cmd.argument() == "paragraph");
819                 bv->buffer().errors("Paste");
820                 break;
821
822         case LFUN_PRIMARY_SELECTION_PASTE:
823                 pasteString(cur, theSelection().get(),
824                             cmd.argument() == "paragraph");
825                 break;
826
827         case LFUN_UNICODE_INSERT: {
828                 if (cmd.argument().empty())
829                         break;
830                 docstring hexstring = cmd.argument();
831                 if (lyx::support::isHex(hexstring)) {
832                         char_type c = lyx::support::hexToInt(hexstring);
833                         if (c >= 32 && c < 0x10ffff) {
834                                 lyxerr << "Inserting c: " << c << endl;
835                                 docstring s = docstring(1, c);
836                                 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
837                         }
838                 }
839                 break;
840         }
841
842         case LFUN_QUOTE_INSERT: {
843                 Paragraph & par = cur.paragraph();
844                 pos_type pos = cur.pos();
845                 BufferParams const & bufparams = bv->buffer().params();
846                 LayoutPtr const & style = par.layout();
847                 if (!style->pass_thru
848                     && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
849                         // this avoids a double undo
850                         // FIXME: should not be needed, ideally
851                         if (!cur.selection())
852                                 recordUndo(cur);
853                         cap::replaceSelection(cur);
854                         pos = cur.pos();
855                         char_type c;
856                         if (pos == 0)
857                                 c = ' ';
858                         else if (cur.prevInset() && cur.prevInset()->isSpace())
859                                 c = ' ';
860                         else
861                                 c = par.getChar(pos - 1);
862                         string arg = to_utf8(cmd.argument());
863                         if (arg == "single")
864                                 cur.insert(new InsetQuotes(c,
865                                     bufparams.quotes_language,
866                                     InsetQuotes::SingleQ));
867                         else
868                                 cur.insert(new InsetQuotes(c,
869                                     bufparams.quotes_language,
870                                     InsetQuotes::DoubleQ));
871                         cur.posRight();
872                 }
873                 else
874                         lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
875                 break;
876         }
877
878         case LFUN_DATE_INSERT: {
879                 string const format = cmd.argument().empty()
880                         ? lyxrc.date_insert_format : to_utf8(cmd.argument());
881                 string const time = formatted_time(current_time(), format);
882                 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, time));
883                 break;
884         }
885
886         case LFUN_MOUSE_TRIPLE:
887                 if (cmd.button() == mouse_button::button1) {
888                         tm.cursorHome(cur);
889                         cur.resetAnchor();
890                         tm.cursorEnd(cur);
891                         cur.setSelection();
892                         bv->cursor() = cur;
893                 }
894                 break;
895
896         case LFUN_MOUSE_DOUBLE:
897                 if (cmd.button() == mouse_button::button1) {
898                         selectWord(cur, WHOLE_WORD_STRICT);
899                         bv->cursor() = cur;
900                 }
901                 break;
902
903         // Single-click on work area
904         case LFUN_MOUSE_PRESS: {
905                 // Right click on a footnote flag opens float menu
906                 if (cmd.button() == mouse_button::button3)
907                         cur.clearSelection();
908
909                 // Set the cursor
910                 bool update = bv->mouseSetCursor(cur);
911
912                 // Insert primary selection with middle mouse
913                 // if there is a local selection in the current buffer,
914                 // insert this
915                 if (cmd.button() == mouse_button::button2) {
916                         if (cap::selection()) {
917                                 // Copy the selection buffer to the clipboard
918                                 // stack, because we want it to appear in the
919                                 // "Edit->Paste recent" menu.
920                                 cap::copySelectionToStack();
921
922                                 cap::pasteSelection(bv->cursor(), 
923                                                     bv->buffer().errorList("Paste"));
924                                 bv->buffer().errors("Paste");
925                                 bv->buffer().markDirty();
926                                 finishUndo();
927                         } else {
928                                 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
929                         }
930                 }
931
932                 // we have to update after dEPM triggered
933                 if (!update && cmd.button() == mouse_button::button1) {
934                         needsUpdate = false;
935                         cur.noUpdate();
936                 }
937
938                 break;
939         }
940
941         case LFUN_MOUSE_MOTION: {
942                 // Only use motion with button 1
943                 //if (cmd.button() != mouse_button::button1)
944                 //      return false;
945
946                 // ignore motions deeper nested than the real anchor
947                 Cursor & bvcur = cur.bv().cursor();
948                 if (bvcur.anchor_.hasPart(cur)) {
949                         CursorSlice old = bvcur.top();
950
951                         int const wh = bv->workHeight();
952                         int const y = std::max(0, std::min(wh - 1, cmd.y));
953
954                         tm.setCursorFromCoordinates(cur, cmd.x, y);
955                         cur.setTargetX(cmd.x);
956                         if (cmd.y >= wh)
957                                 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
958                         else if (cmd.y < 0)
959                                 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
960                         // This is to allow jumping over large insets
961                         if (cur.top() == old) {
962                                 if (cmd.y >= wh)
963                                         lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
964                                 else if (cmd.y < 0)
965                                         lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
966                         }
967
968                         if (cur.top() == old)
969                                 cur.noUpdate();
970                         else {
971                                 // don't set anchor_
972                                 bvcur.setCursor(cur);
973                                 bvcur.selection() = true;
974                                 //lyxerr << "MOTION: " << bv->cursor() << endl;
975                         }
976
977                 } else
978                         cur.undispatched();
979                 break;
980         }
981
982         case LFUN_MOUSE_RELEASE: {
983                 if (cmd.button() == mouse_button::button2)
984                         break;
985
986                 if (cmd.button() == mouse_button::button1) {
987                         // if there is new selection, update persistent
988                         // selection, otherwise, single click does not
989                         // clear persistent selection buffer
990                         if (cur.selection()) {
991                                 // finish selection
992                                 // if double click, cur is moved to the end of word by selectWord
993                                 // but bvcur is current mouse position
994                                 Cursor & bvcur = cur.bv().cursor();
995                                 bvcur.selection() = true;
996                         }
997                         needsUpdate = false;
998                         cur.noUpdate();
999                 }
1000
1001                 break;
1002         }
1003
1004         case LFUN_SELF_INSERT: {
1005                 if (cmd.argument().empty())
1006                         break;
1007
1008                 // Automatically delete the currently selected
1009                 // text and replace it with what is being
1010                 // typed in now. Depends on lyxrc settings
1011                 // "auto_region_delete", which defaults to
1012                 // true (on).
1013
1014                 if (lyxrc.auto_region_delete && cur.selection()) {
1015                         cutSelection(cur, false, false);
1016                         // When change tracking is set to off, the metrics update
1017                         // mechanism correctly detects if a full update is needed or not.
1018                         // This detection fails when a selection spans multiple rows and
1019                         // change tracking is enabled because the paragraph metrics stays
1020                         // the same. In this case, we force the full update:
1021                         // (see http://bugzilla.lyx.org/show_bug.cgi?id=3992)
1022                         if (cur.buffer().params().trackChanges)
1023                                 cur.updateFlags(Update::Force);
1024                 }
1025
1026                 cur.clearSelection();
1027                 Font const old_font = cur.real_current_font;
1028
1029                 docstring::const_iterator cit = cmd.argument().begin();
1030                 docstring::const_iterator end = cmd.argument().end();
1031                 for (; cit != end; ++cit)
1032                         bv->translateAndInsert(*cit, this, cur);
1033
1034                 cur.resetAnchor();
1035                 moveCursor(cur, false);
1036                 break;
1037         }
1038
1039         case LFUN_URL_INSERT: {
1040                 InsetCommandParams p("url");
1041                 docstring content;
1042                 if (cur.selection()) {
1043                         content = cur.selectionAsString(false);
1044                         cutSelection(cur, true, false);
1045                 }
1046                 p["target"] = (cmd.argument().empty()) ?
1047                         content : cmd.argument();
1048                 string const data = InsetCommandMailer::params2string("url", p);
1049                 if (p["target"].empty()) {
1050                         bv->showInsetDialog("url", data, 0);
1051                 } else {
1052                         FuncRequest fr(LFUN_INSET_INSERT, data);
1053                         dispatch(cur, fr);
1054                 }
1055                 break;
1056         }
1057
1058         case LFUN_HTML_INSERT: {
1059                 InsetCommandParams p("htmlurl");
1060                 docstring content;
1061                 if (cur.selection()) {
1062                         content = cur.selectionAsString(false);
1063                         cutSelection(cur, true, false);
1064                 }
1065                 p["target"] = (cmd.argument().empty()) ?
1066                         content : cmd.argument();
1067                 string const data = InsetCommandMailer::params2string("url", p);
1068                 if (p["target"].empty()) {
1069                         bv->showInsetDialog("url", data, 0);
1070                 } else {
1071                         FuncRequest fr(LFUN_INSET_INSERT, data);
1072                         dispatch(cur, fr);
1073                 }
1074                 break;
1075         }
1076
1077         case LFUN_LABEL_INSERT: {
1078                 InsetCommandParams p("label");
1079                 // Try to generate a valid label
1080                 p["name"] = (cmd.argument().empty()) ?
1081                         cur.getPossibleLabel() :
1082                         cmd.argument();
1083                 string const data = InsetCommandMailer::params2string("label", p);
1084
1085                 if (cmd.argument().empty()) {
1086                         bv->showInsetDialog("label", data, 0);
1087                 } else {
1088                         FuncRequest fr(LFUN_INSET_INSERT, data);
1089                         dispatch(cur, fr);
1090                 }
1091                 break;
1092         }
1093
1094
1095 #if 0
1096         case LFUN_LIST_INSERT:
1097         case LFUN_THEOREM_INSERT:
1098 #endif
1099         case LFUN_CAPTION_INSERT:
1100                 // Open the inset, and move the current selection
1101                 // inside it.
1102                 doInsertInset(cur, this, cmd, true, true);
1103                 cur.posRight();
1104                 updateLabels(bv->buffer());
1105                 break;
1106         case LFUN_NOTE_INSERT:
1107         case LFUN_FLEX_INSERT:
1108         case LFUN_BOX_INSERT:
1109         case LFUN_BRANCH_INSERT:
1110         case LFUN_BIBITEM_INSERT:
1111         case LFUN_ERT_INSERT:
1112         case LFUN_LISTING_INSERT:
1113         case LFUN_FOOTNOTE_INSERT:
1114         case LFUN_MARGINALNOTE_INSERT:
1115         case LFUN_OPTIONAL_INSERT:
1116         case LFUN_ENVIRONMENT_INSERT:
1117                 // Open the inset, and move the current selection
1118                 // inside it.
1119                 doInsertInset(cur, this, cmd, true, true);
1120                 cur.posRight();
1121                 break;
1122
1123         case LFUN_TABULAR_INSERT:
1124                 // if there were no arguments, just open the dialog
1125                 if (doInsertInset(cur, this, cmd, false, true))
1126                         cur.posRight();
1127                 else
1128                         bv->showDialog("tabularcreate");
1129
1130                 break;
1131
1132         case LFUN_FLOAT_INSERT:
1133         case LFUN_FLOAT_WIDE_INSERT:
1134         case LFUN_WRAP_INSERT: {
1135                 bool content = cur.selection();  // will some text be moved into the inset?
1136
1137                 doInsertInset(cur, this, cmd, true, true);
1138                 cur.posRight();
1139                 ParagraphList & pars = cur.text()->paragraphs();
1140
1141                 TextClass const & tclass = bv->buffer().params().getTextClass();
1142
1143                 // add a separate paragraph for the caption inset
1144                 pars.push_back(Paragraph());
1145                 pars.back().setInsetOwner(pars[0].inInset());
1146                 pars.back().layout(tclass.defaultLayout());
1147
1148                 int cap_pit = pars.size() - 1;
1149
1150                 // if an empty inset was created, we create an additional empty
1151                 // paragraph at the bottom so that the user can choose where to put
1152                 // the graphics (or table).
1153                 if (!content) {
1154                         pars.push_back(Paragraph());
1155                         pars.back().setInsetOwner(pars[0].inInset());
1156                         pars.back().layout(tclass.defaultLayout());
1157
1158                 }
1159
1160                 // reposition the cursor to the caption
1161                 cur.pit() = cap_pit;
1162                 cur.pos() = 0;
1163                 // FIXME: This Text/Cursor dispatch handling is a mess!
1164                 // We cannot use Cursor::dispatch here it needs access to up to
1165                 // date metrics.
1166                 FuncRequest cmd_caption(LFUN_CAPTION_INSERT);
1167                 cur.text()->dispatch(cur, cmd_caption);
1168                 cur.updateFlags(Update::Force);
1169                 // FIXME: When leaving the Float (or Wrap) inset we should
1170                 // delete any empty paragraph left above or below the
1171                 // caption.
1172                 break;
1173         }
1174
1175         case LFUN_INDEX_INSERT:
1176         case LFUN_NOMENCL_INSERT: {
1177                 Inset * inset = createInset(&cur.bv(), cmd);
1178                 if (!inset)
1179                         break;
1180                 recordUndo(cur);
1181                 cur.clearSelection();
1182                 insertInset(cur, inset);
1183                 // Show the dialog for the nomenclature entry, since the
1184                 // description entry still needs to be filled in.
1185                 if (cmd.action == LFUN_NOMENCL_INSERT)
1186                         inset->edit(cur, true);
1187                 cur.posRight();
1188                 break;
1189         }
1190
1191         case LFUN_INDEX_PRINT:
1192         case LFUN_NOMENCL_PRINT:
1193         case LFUN_TOC_INSERT:
1194         case LFUN_HFILL_INSERT:
1195         case LFUN_LINE_INSERT:
1196         case LFUN_PAGEBREAK_INSERT:
1197         case LFUN_CLEARPAGE_INSERT:
1198         case LFUN_CLEARDOUBLEPAGE_INSERT:
1199                 // do nothing fancy
1200                 doInsertInset(cur, this, cmd, false, false);
1201                 cur.posRight();
1202                 break;
1203
1204         case LFUN_DEPTH_DECREMENT:
1205                 changeDepth(cur, DEC_DEPTH);
1206                 break;
1207
1208         case LFUN_DEPTH_INCREMENT:
1209                 changeDepth(cur, INC_DEPTH);
1210                 break;
1211
1212         case LFUN_MATH_DISPLAY:
1213                 mathDispatch(cur, cmd, true);
1214                 break;
1215
1216         case LFUN_MATH_IMPORT_SELECTION:
1217         case LFUN_MATH_MODE:
1218                 if (cmd.argument() == "on")
1219                         // don't pass "on" as argument
1220                         mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1221                 else
1222                         mathDispatch(cur, cmd, false);
1223                 break;
1224
1225         case LFUN_MATH_MACRO:
1226                 if (cmd.argument().empty())
1227                         cur.errorMessage(from_utf8(N_("Missing argument")));
1228                 else {
1229                         string s = to_utf8(cmd.argument());
1230                         string const s1 = token(s, ' ', 1);
1231                         int const nargs = s1.empty() ? 0 : convert<int>(s1);
1232                         string const s2 = token(s, ' ', 2);
1233                         string const type = s2.empty() ? "newcommand" : s2;
1234                         cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, from_utf8(type)));
1235                         //cur.nextInset()->edit(cur, true);
1236                 }
1237                 break;
1238
1239         // passthrough hat and underscore outside mathed:
1240         case LFUN_MATH_SUBSCRIPT:
1241                 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1242                 break;
1243         case LFUN_MATH_SUPERSCRIPT:
1244                 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1245                 break;
1246
1247         case LFUN_MATH_INSERT:
1248         case LFUN_MATH_MATRIX:
1249         case LFUN_MATH_DELIM:
1250         case LFUN_MATH_BIGDELIM: {
1251                 if (cur.selection())
1252                         cur.clearSelection();
1253                 // FIXME: instead of the above, this one
1254                 // should be used (but it asserts with Bidi enabled)
1255                 // cf. http://bugzilla.lyx.org/show_bug.cgi?id=4055
1256                 // cap::replaceSelection(cur);
1257                 cur.insert(new InsetMathHull(hullSimple));
1258                 checkAndActivateInset(cur, true);
1259                 BOOST_ASSERT(cur.inMathed());
1260                 cur.dispatch(cmd);
1261                 break;
1262         }
1263
1264         case LFUN_FONT_EMPH: {
1265                 Font font(Font::ALL_IGNORE);
1266                 font.setEmph(Font::TOGGLE);
1267                 toggleAndShow(cur, this, font);
1268                 break;
1269         }
1270
1271         case LFUN_FONT_BOLD: {
1272                 Font font(Font::ALL_IGNORE);
1273                 font.setSeries(Font::BOLD_SERIES);
1274                 toggleAndShow(cur, this, font);
1275                 break;
1276         }
1277
1278         case LFUN_FONT_NOUN: {
1279                 Font font(Font::ALL_IGNORE);
1280                 font.setNoun(Font::TOGGLE);
1281                 toggleAndShow(cur, this, font);
1282                 break;
1283         }
1284
1285         case LFUN_FONT_TYPEWRITER: {
1286                 Font font(Font::ALL_IGNORE);
1287                 font.setFamily(Font::TYPEWRITER_FAMILY); // no good
1288                 toggleAndShow(cur, this, font);
1289                 break;
1290         }
1291
1292         case LFUN_FONT_SANS: {
1293                 Font font(Font::ALL_IGNORE);
1294                 font.setFamily(Font::SANS_FAMILY);
1295                 toggleAndShow(cur, this, font);
1296                 break;
1297         }
1298
1299         case LFUN_FONT_ROMAN: {
1300                 Font font(Font::ALL_IGNORE);
1301                 font.setFamily(Font::ROMAN_FAMILY);
1302                 toggleAndShow(cur, this, font);
1303                 break;
1304         }
1305
1306         case LFUN_FONT_DEFAULT: {
1307                 Font font(Font::ALL_INHERIT, ignore_language);
1308                 toggleAndShow(cur, this, font);
1309                 break;
1310         }
1311
1312         case LFUN_FONT_UNDERLINE: {
1313                 Font font(Font::ALL_IGNORE);
1314                 font.setUnderbar(Font::TOGGLE);
1315                 toggleAndShow(cur, this, font);
1316                 break;
1317         }
1318
1319         case LFUN_FONT_SIZE: {
1320                 Font font(Font::ALL_IGNORE);
1321                 font.setLyXSize(to_utf8(cmd.argument()));
1322                 toggleAndShow(cur, this, font);
1323                 break;
1324         }
1325
1326         case LFUN_LANGUAGE: {
1327                 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1328                 if (!lang)
1329                         break;
1330                 Font font(Font::ALL_IGNORE);
1331                 font.setLanguage(lang);
1332                 toggleAndShow(cur, this, font);
1333                 break;
1334         }
1335
1336         case LFUN_FONT_FREE_APPLY:
1337                 toggleAndShow(cur, this, freefont, toggleall);
1338                 cur.message(_("Character set"));
1339                 break;
1340
1341         // Set the freefont using the contents of \param data dispatched from
1342         // the frontends and apply it at the current cursor location.
1343         case LFUN_FONT_FREE_UPDATE: {
1344                 Font font;
1345                 bool toggle;
1346                 if (font.fromString(to_utf8(cmd.argument()), toggle)) {
1347                         freefont = font;
1348                         toggleall = toggle;
1349                         toggleAndShow(cur, this, freefont, toggleall);
1350                         cur.message(_("Character set"));
1351                 }
1352                 break;
1353         }
1354
1355         case LFUN_FINISHED_LEFT:
1356                 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1357                 if (reverseDirectionNeeded(cur)) {
1358                         ++cur.pos();
1359                         cur.setCurrentFont();
1360                 }
1361                 break;
1362
1363         case LFUN_FINISHED_RIGHT:
1364                 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1365                 if (!reverseDirectionNeeded(cur)) {
1366                         ++cur.pos();
1367                         cur.setCurrentFont();
1368                 }
1369                 break;
1370
1371         case LFUN_LAYOUT_PARAGRAPH: {
1372                 string data;
1373                 params2string(cur.paragraph(), data);
1374                 data = "show\n" + data;
1375                 bv->showDialogWithData("paragraph", data);
1376                 break;
1377         }
1378
1379         case LFUN_PARAGRAPH_UPDATE: {
1380                 string data;
1381                 params2string(cur.paragraph(), data);
1382
1383                 // Will the paragraph accept changes from the dialog?
1384                 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1385
1386                 data = "update " + convert<string>(accept) + '\n' + data;
1387                 bv->updateDialog("paragraph", data);
1388                 break;
1389         }
1390
1391         case LFUN_ACCENT_UMLAUT:
1392         case LFUN_ACCENT_CIRCUMFLEX:
1393         case LFUN_ACCENT_GRAVE:
1394         case LFUN_ACCENT_ACUTE:
1395         case LFUN_ACCENT_TILDE:
1396         case LFUN_ACCENT_CEDILLA:
1397         case LFUN_ACCENT_MACRON:
1398         case LFUN_ACCENT_DOT:
1399         case LFUN_ACCENT_UNDERDOT:
1400         case LFUN_ACCENT_UNDERBAR:
1401         case LFUN_ACCENT_CARON:
1402         case LFUN_ACCENT_SPECIAL_CARON:
1403         case LFUN_ACCENT_BREVE:
1404         case LFUN_ACCENT_TIE:
1405         case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1406         case LFUN_ACCENT_CIRCLE:
1407         case LFUN_ACCENT_OGONEK:
1408                 theLyXFunc().handleKeyFunc(cmd.action);
1409                 if (!cmd.argument().empty())
1410                         // FIXME: Are all these characters encoded in one byte in utf8?
1411                         bv->translateAndInsert(cmd.argument()[0], this, cur);
1412                 break;
1413
1414         case LFUN_FLOAT_LIST: {
1415                 TextClass const & tclass = bv->buffer().params().getTextClass();
1416                 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1417                         recordUndo(cur);
1418                         if (cur.selection())
1419                                 cutSelection(cur, true, false);
1420                         breakParagraph(cur);
1421
1422                         if (cur.lastpos() != 0) {
1423                                 cursorLeft(cur);
1424                                 breakParagraph(cur);
1425                         }
1426
1427                         setLayout(cur, tclass.defaultLayoutName());
1428                         ParagraphParameters p;
1429                         setParagraphs(cur, p);
1430                         insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1431                         cur.posRight();
1432                 } else {
1433                         lyxerr << "Non-existent float type: "
1434                                << to_utf8(cmd.argument()) << endl;
1435                 }
1436                 break;
1437         }
1438
1439         case LFUN_CHANGE_ACCEPT: {
1440                 acceptOrRejectChanges(cur, ACCEPT);
1441                 break;
1442         }
1443
1444         case LFUN_CHANGE_REJECT: {
1445                 acceptOrRejectChanges(cur, REJECT);
1446                 break;
1447         }
1448
1449         case LFUN_THESAURUS_ENTRY: {
1450                 docstring arg = cmd.argument();
1451                 if (arg.empty()) {
1452                         arg = cur.selectionAsString(false);
1453                         // FIXME
1454                         if (arg.size() > 100 || arg.empty()) {
1455                                 // Get word or selection
1456                                 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1457                                 arg = cur.selectionAsString(false);
1458                         }
1459                 }
1460                 bv->showDialogWithData("thesaurus", to_utf8(arg));
1461                 break;
1462         }
1463
1464         case LFUN_PARAGRAPH_PARAMS_APPLY: {
1465                 // Given data, an encoding of the ParagraphParameters
1466                 // generated in the Paragraph dialog, this function sets
1467                 // the current paragraph, or currently selected paragraphs,
1468                 // appropriately. 
1469                 // NOTE: This function overrides all existing settings.
1470                 setParagraphs(cur, cmd.argument());
1471                 cur.message(_("Paragraph layout set"));
1472                 break;
1473         }
1474         
1475         case LFUN_PARAGRAPH_PARAMS: {
1476                 // Given data, an encoding of the ParagraphParameters as we'd
1477                 // find them in a LyX file, this function modifies the current paragraph, 
1478                 // or currently selected paragraphs. 
1479                 // NOTE: This function only modifies, and does not override, existing
1480                 // settings.
1481                 setParagraphs(cur, cmd.argument(), true);
1482                 cur.message(_("Paragraph layout set"));
1483                 break;
1484         }
1485
1486         case LFUN_ESCAPE:
1487                 if (cur.selection()) {
1488                         cur.selection() = false;
1489                 } else {
1490                         cur.undispatched();
1491                         cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1492                 }
1493                 break;
1494
1495         default:
1496                 LYXERR(Debug::ACTION)
1497                         << BOOST_CURRENT_FUNCTION
1498                         << ": Command " << cmd
1499                         << " not DISPATCHED by Text" << endl;
1500                 cur.undispatched();
1501                 break;
1502         }
1503
1504         needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1505
1506         // FIXME: The cursor flag is reset two lines below
1507         // so we need to check here if some of the LFUN did touch that.
1508         // for now only Text::erase() and Text::backspace() do that.
1509         // The plan is to verify all the LFUNs and then to remove this
1510         // singleParUpdate boolean altogether.
1511         if (cur.result().update() & Update::Force) {
1512                 singleParUpdate = false;
1513                 needsUpdate = true;
1514         }
1515
1516         // FIXME: the following code should go in favor of fine grained
1517         // update flag treatment.
1518         if (singleParUpdate) {
1519                 // Inserting characters does not change par height
1520                 ParagraphMetrics const & pms
1521                         = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
1522                 if (pms.dim().height()
1523                     == olddim.height()) {
1524                         // if so, update _only_ this paragraph
1525                         cur.updateFlags(Update::SinglePar |
1526                                 Update::FitCursor |
1527                                 Update::MultiParSel);
1528                         return;
1529                 } else
1530                         needsUpdate = true;
1531         }
1532
1533         if (!needsUpdate
1534             && &oldTopSlice.inset() == &cur.inset()
1535             && oldTopSlice.idx() == cur.idx()
1536             && !sel // sel is a backup of cur.selection() at the biginning of the function.
1537             && !cur.selection())
1538                 // FIXME: it would be better if we could just do this
1539                 //
1540                 //if (cur.result().update() != Update::FitCursor)
1541                 //      cur.noUpdate();
1542                 //
1543                 // But some LFUNs do not set Update::FitCursor when needed, so we
1544                 // do it for all. This is not very harmfull as FitCursor will provoke
1545                 // a full redraw only if needed but still, a proper review of all LFUN
1546                 // should be done and this needsUpdate boolean can then be removed.
1547                 cur.updateFlags(Update::FitCursor);
1548         else
1549                 cur.updateFlags(Update::Force | Update::FitCursor);
1550 }
1551
1552
1553 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
1554                         FuncStatus & flag) const
1555 {
1556         BOOST_ASSERT(cur.text() == this);
1557
1558         Font const & font = cur.real_current_font;
1559         bool enable = true;
1560         Inset::Code code = Inset::NO_CODE;
1561
1562         switch (cmd.action) {
1563
1564         case LFUN_DEPTH_DECREMENT:
1565                 enable = changeDepthAllowed(cur, DEC_DEPTH);
1566                 break;
1567
1568         case LFUN_DEPTH_INCREMENT:
1569                 enable = changeDepthAllowed(cur, INC_DEPTH);
1570                 break;
1571
1572         case LFUN_APPENDIX:
1573                 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1574                 return true;
1575
1576         case LFUN_BIBITEM_INSERT:
1577                 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO
1578                           && cur.pos() == 0);
1579                 break;
1580
1581         case LFUN_DIALOG_SHOW_NEW_INSET:
1582                 if (cmd.argument() == "bibitem")
1583                         code = Inset::BIBITEM_CODE;
1584                 else if (cmd.argument() == "bibtex")
1585                         code = Inset::BIBTEX_CODE;
1586                 else if (cmd.argument() == "box")
1587                         code = Inset::BOX_CODE;
1588                 else if (cmd.argument() == "branch")
1589                         code = Inset::BRANCH_CODE;
1590                 else if (cmd.argument() == "citation")
1591                         code = Inset::CITE_CODE;
1592                 else if (cmd.argument() == "ert")
1593                         code = Inset::ERT_CODE;
1594                 else if (cmd.argument() == "external")
1595                         code = Inset::EXTERNAL_CODE;
1596                 else if (cmd.argument() == "float")
1597                         code = Inset::FLOAT_CODE;
1598                 else if (cmd.argument() == "graphics")
1599                         code = Inset::GRAPHICS_CODE;
1600                 else if (cmd.argument() == "include")
1601                         code = Inset::INCLUDE_CODE;
1602                 else if (cmd.argument() == "index")
1603                         code = Inset::INDEX_CODE;
1604                 else if (cmd.argument() == "nomenclature")
1605                         code = Inset::NOMENCL_CODE;
1606                 else if (cmd.argument() == "label")
1607                         code = Inset::LABEL_CODE;
1608                 else if (cmd.argument() == "note")
1609                         code = Inset::NOTE_CODE;
1610                 else if (cmd.argument() == "ref")
1611                         code = Inset::REF_CODE;
1612                 else if (cmd.argument() == "toc")
1613                         code = Inset::TOC_CODE;
1614                 else if (cmd.argument() == "url")
1615                         code = Inset::URL_CODE;
1616                 else if (cmd.argument() == "vspace")
1617                         code = Inset::VSPACE_CODE;
1618                 else if (cmd.argument() == "wrap")
1619                         code = Inset::WRAP_CODE;
1620                 else if (cmd.argument() == "listings")
1621                         code = Inset::LISTINGS_CODE;
1622                 break;
1623
1624         case LFUN_ERT_INSERT:
1625                 code = Inset::ERT_CODE;
1626                 break;
1627         case LFUN_LISTING_INSERT:
1628             code = Inset::LISTINGS_CODE;
1629                 break;
1630         case LFUN_FOOTNOTE_INSERT:
1631                 code = Inset::FOOT_CODE;
1632                 break;
1633         case LFUN_TABULAR_INSERT:
1634                 code = Inset::TABULAR_CODE;
1635                 break;
1636         case LFUN_MARGINALNOTE_INSERT:
1637                 code = Inset::MARGIN_CODE;
1638                 break;
1639         case LFUN_FLOAT_INSERT:
1640         case LFUN_FLOAT_WIDE_INSERT:
1641                 code = Inset::FLOAT_CODE;
1642                 break;
1643         case LFUN_WRAP_INSERT:
1644                 code = Inset::WRAP_CODE;
1645                 break;
1646         case LFUN_FLOAT_LIST:
1647                 code = Inset::FLOAT_LIST_CODE;
1648                 break;
1649 #if 0
1650         case LFUN_LIST_INSERT:
1651                 code = Inset::LIST_CODE;
1652                 break;
1653         case LFUN_THEOREM_INSERT:
1654                 code = Inset::THEOREM_CODE;
1655                 break;
1656 #endif
1657         case LFUN_CAPTION_INSERT:
1658                 code = Inset::CAPTION_CODE;
1659                 break;
1660         case LFUN_NOTE_INSERT:
1661                 code = Inset::NOTE_CODE;
1662                 break;
1663         case LFUN_FLEX_INSERT: {
1664                 code = Inset::FLEX_CODE;
1665                 string s = cmd.getArg(0);
1666                 InsetLayout il =  cur.buffer().params().getTextClass().insetlayout(from_utf8(s));
1667                 if (il.lyxtype != "charstyle" &&
1668                     il.lyxtype != "custom" &&
1669                     il.lyxtype != "element")
1670                         enable = false;
1671                 break;
1672                 }
1673         case LFUN_BOX_INSERT:
1674                 code = Inset::BOX_CODE;
1675                 break;
1676         case LFUN_BRANCH_INSERT:
1677                 code = Inset::BRANCH_CODE;
1678                 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1679                         enable = false;
1680                 break;
1681         case LFUN_LABEL_INSERT:
1682                 code = Inset::LABEL_CODE;
1683                 break;
1684         case LFUN_OPTIONAL_INSERT:
1685                 code = Inset::OPTARG_CODE;
1686                 enable = numberOfOptArgs(cur.paragraph())
1687                         < cur.paragraph().layout()->optionalargs;
1688                 break;
1689         case LFUN_ENVIRONMENT_INSERT:
1690                 code = Inset::BOX_CODE;
1691                 break;
1692         case LFUN_INDEX_INSERT:
1693                 code = Inset::INDEX_CODE;
1694                 break;
1695         case LFUN_INDEX_PRINT:
1696                 code = Inset::INDEX_PRINT_CODE;
1697                 break;
1698         case LFUN_NOMENCL_INSERT:
1699                 code = Inset::NOMENCL_CODE;
1700                 break;
1701         case LFUN_NOMENCL_PRINT:
1702                 code = Inset::NOMENCL_PRINT_CODE;
1703                 break;
1704         case LFUN_TOC_INSERT:
1705                 code = Inset::TOC_CODE;
1706                 break;
1707         case LFUN_HTML_INSERT:
1708         case LFUN_URL_INSERT:
1709                 code = Inset::URL_CODE;
1710                 break;
1711         case LFUN_QUOTE_INSERT:
1712                 // always allow this, since we will inset a raw quote
1713                 // if an inset is not allowed.
1714                 break;
1715         case LFUN_HYPHENATION_POINT_INSERT:
1716         case LFUN_LIGATURE_BREAK_INSERT:
1717         case LFUN_HFILL_INSERT:
1718         case LFUN_MENU_SEPARATOR_INSERT:
1719         case LFUN_DOTS_INSERT:
1720         case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
1721                 code = Inset::SPECIALCHAR_CODE;
1722                 break;
1723         case LFUN_SPACE_INSERT:
1724                 // slight hack: we know this is allowed in math mode
1725                 if (cur.inTexted())
1726                         code = Inset::SPACE_CODE;
1727                 break;
1728
1729         case LFUN_INSET_MODIFY:
1730                 // We need to disable this, because we may get called for a
1731                 // tabular cell via
1732                 // InsetTabular::getStatus() -> InsetText::getStatus()
1733                 // and we don't handle LFUN_INSET_MODIFY.
1734                 enable = false;
1735                 break;
1736
1737         case LFUN_FONT_EMPH:
1738                 flag.setOnOff(font.emph() == Font::ON);
1739                 return true;
1740
1741         case LFUN_FONT_NOUN:
1742                 flag.setOnOff(font.noun() == Font::ON);
1743                 return true;
1744
1745         case LFUN_FONT_BOLD:
1746                 flag.setOnOff(font.series() == Font::BOLD_SERIES);
1747                 return true;
1748
1749         case LFUN_FONT_SANS:
1750                 flag.setOnOff(font.family() == Font::SANS_FAMILY);
1751                 return true;
1752
1753         case LFUN_FONT_ROMAN:
1754                 flag.setOnOff(font.family() == Font::ROMAN_FAMILY);
1755                 return true;
1756
1757         case LFUN_FONT_TYPEWRITER:
1758                 flag.setOnOff(font.family() == Font::TYPEWRITER_FAMILY);
1759                 return true;
1760
1761         case LFUN_CUT:
1762         case LFUN_COPY:
1763                 enable = cur.selection();
1764                 break;
1765
1766         case LFUN_PASTE:
1767                 if (cmd.argument().empty()) {
1768                         if (theClipboard().isInternal())
1769                                 enable = cap::numberOfSelections() > 0;
1770                         else
1771                                 enable = !theClipboard().empty();
1772                 } else {
1773                         string const arg = to_utf8(cmd.argument());
1774                         if (isStrUnsignedInt(arg)) {
1775                                 unsigned int n = convert<unsigned int>(arg);
1776                                 enable = cap::numberOfSelections() > n;
1777                         } else
1778                                 // unknown argument
1779                                 enable = false;
1780                 }
1781                 break;
1782
1783         case LFUN_CLIPBOARD_PASTE:
1784                 enable = !theClipboard().empty();
1785                 break;
1786
1787         case LFUN_PRIMARY_SELECTION_PASTE:
1788                 enable = cur.selection() || !theSelection().empty();
1789                 break;
1790
1791         case LFUN_PARAGRAPH_MOVE_UP:
1792                 enable = cur.pit() > 0 && !cur.selection();
1793                 break;
1794
1795         case LFUN_PARAGRAPH_MOVE_DOWN:
1796                 enable = cur.pit() < cur.lastpit() && !cur.selection();
1797                 break;
1798
1799         case LFUN_INSET_DISSOLVE:
1800                 enable = !isMainText(cur.bv().buffer()) && cur.inset().nargs() == 1;
1801                 break;
1802
1803         case LFUN_CHANGE_ACCEPT:
1804         case LFUN_CHANGE_REJECT:
1805                 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
1806                 // In principle, these LFUNs should only be enabled if there
1807                 // is a change at the current position/in the current selection.
1808                 // However, without proper optimizations, this will inevitably
1809                 // result in unacceptable performance - just imagine a user who
1810                 // wants to select the complete content of a long document.
1811                 enable = true;
1812                 break;
1813
1814         case LFUN_WORD_DELETE_FORWARD:
1815         case LFUN_WORD_DELETE_BACKWARD:
1816         case LFUN_LINE_DELETE:
1817         case LFUN_WORD_FORWARD:
1818         case LFUN_WORD_BACKWARD:
1819         case LFUN_CHAR_FORWARD:
1820         case LFUN_CHAR_FORWARD_SELECT:
1821         case LFUN_CHAR_BACKWARD:
1822         case LFUN_CHAR_BACKWARD_SELECT:
1823         case LFUN_UP:
1824         case LFUN_UP_SELECT:
1825         case LFUN_DOWN:
1826         case LFUN_DOWN_SELECT:
1827         case LFUN_PARAGRAPH_UP_SELECT:
1828         case LFUN_PARAGRAPH_DOWN_SELECT:
1829         case LFUN_SCREEN_UP_SELECT:
1830         case LFUN_SCREEN_DOWN_SELECT:
1831         case LFUN_LINE_BEGIN_SELECT:
1832         case LFUN_LINE_END_SELECT:
1833         case LFUN_WORD_FORWARD_SELECT:
1834         case LFUN_WORD_BACKWARD_SELECT:
1835         case LFUN_WORD_SELECT:
1836         case LFUN_PARAGRAPH_UP:
1837         case LFUN_PARAGRAPH_DOWN:
1838         case LFUN_LINE_BEGIN:
1839         case LFUN_LINE_END:
1840         case LFUN_BREAK_LINE:
1841         case LFUN_CHAR_DELETE_FORWARD:
1842         case LFUN_DELETE_FORWARD_SKIP:
1843         case LFUN_CHAR_DELETE_BACKWARD:
1844         case LFUN_DELETE_BACKWARD_SKIP:
1845         case LFUN_BREAK_PARAGRAPH:
1846         case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
1847         case LFUN_BREAK_PARAGRAPH_SKIP:
1848         case LFUN_PARAGRAPH_SPACING:
1849         case LFUN_INSET_INSERT:
1850         case LFUN_WORD_UPCASE:
1851         case LFUN_WORD_LOWCASE:
1852         case LFUN_WORD_CAPITALIZE:
1853         case LFUN_CHARS_TRANSPOSE:
1854         case LFUN_SERVER_GET_XY:
1855         case LFUN_SERVER_SET_XY:
1856         case LFUN_SERVER_GET_FONT:
1857         case LFUN_SERVER_GET_LAYOUT:
1858         case LFUN_LAYOUT:
1859         case LFUN_DATE_INSERT:
1860         case LFUN_SELF_INSERT:
1861         case LFUN_LINE_INSERT:
1862         case LFUN_PAGEBREAK_INSERT:
1863         case LFUN_CLEARPAGE_INSERT:
1864         case LFUN_CLEARDOUBLEPAGE_INSERT:
1865         case LFUN_MATH_DISPLAY:
1866         case LFUN_MATH_IMPORT_SELECTION:
1867         case LFUN_MATH_MODE:
1868         case LFUN_MATH_MACRO:
1869         case LFUN_MATH_MATRIX:
1870         case LFUN_MATH_DELIM:
1871         case LFUN_MATH_BIGDELIM:
1872         case LFUN_MATH_INSERT:
1873         case LFUN_MATH_SUBSCRIPT:
1874         case LFUN_MATH_SUPERSCRIPT:
1875         case LFUN_FONT_DEFAULT:
1876         case LFUN_FONT_UNDERLINE:
1877         case LFUN_FONT_SIZE:
1878         case LFUN_LANGUAGE:
1879         case LFUN_FONT_FREE_APPLY:
1880         case LFUN_FONT_FREE_UPDATE:
1881         case LFUN_LAYOUT_PARAGRAPH:
1882         case LFUN_PARAGRAPH_UPDATE:
1883         case LFUN_ACCENT_UMLAUT:
1884         case LFUN_ACCENT_CIRCUMFLEX:
1885         case LFUN_ACCENT_GRAVE:
1886         case LFUN_ACCENT_ACUTE:
1887         case LFUN_ACCENT_TILDE:
1888         case LFUN_ACCENT_CEDILLA:
1889         case LFUN_ACCENT_MACRON:
1890         case LFUN_ACCENT_DOT:
1891         case LFUN_ACCENT_UNDERDOT:
1892         case LFUN_ACCENT_UNDERBAR:
1893         case LFUN_ACCENT_CARON:
1894         case LFUN_ACCENT_SPECIAL_CARON:
1895         case LFUN_ACCENT_BREVE:
1896         case LFUN_ACCENT_TIE:
1897         case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1898         case LFUN_ACCENT_CIRCLE:
1899         case LFUN_ACCENT_OGONEK:
1900         case LFUN_THESAURUS_ENTRY:
1901         case LFUN_PARAGRAPH_PARAMS_APPLY:
1902         case LFUN_PARAGRAPH_PARAMS:
1903         case LFUN_ESCAPE:
1904         case LFUN_BUFFER_END:
1905         case LFUN_BUFFER_BEGIN:
1906         case LFUN_BUFFER_BEGIN_SELECT:
1907         case LFUN_BUFFER_END_SELECT:
1908         case LFUN_UNICODE_INSERT:
1909                 // these are handled in our dispatch()
1910                 enable = true;
1911                 break;
1912
1913         default:
1914                 return false;
1915         }
1916
1917         if (code != Inset::NO_CODE
1918             && (cur.empty() || !cur.inset().insetAllowed(code)))
1919                 enable = false;
1920
1921         flag.enabled(enable);
1922         return true;
1923 }
1924
1925
1926 void Text::pasteString(Cursor & cur, docstring const & clip,
1927                 bool asParagraphs)
1928 {
1929         cur.clearSelection();
1930         if (!clip.empty()) {
1931                 recordUndo(cur);
1932                 if (asParagraphs)
1933                         insertStringAsParagraphs(cur, clip);
1934                 else
1935                         insertStringAsLines(cur, clip);
1936         }
1937 }
1938
1939 } // namespace lyx