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