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