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