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