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