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