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