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