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