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