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