]> git.lyx.org Git - lyx.git/blob - src/text3.C
IU stuff + shuffling things from BV::dispatch to LyXText::dispatch
[lyx.git] / src / text3.C
1 /**
2  * \file text3.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Asger Alstrup
7  * \author Lars Gullik Bjønnes
8  * \author Alfredo Braunstein
9  * \author Angus Leeming
10  * \author John Levon
11  * \author André Pönitz
12  *
13  * Full author contact details are available in file CREDITS.
14  */
15
16 #include <config.h>
17
18 #include "lyxtext.h"
19
20 #include "buffer.h"
21 #include "bufferparams.h"
22 #include "BufferView.h"
23 #include "cursor.h"
24 #include "debug.h"
25 #include "dispatchresult.h"
26 #include "factory.h"
27 #include "FloatList.h"
28 #include "funcrequest.h"
29 #include "gettext.h"
30 #include "intl.h"
31 #include "language.h"
32 #include "lyxfunc.h"
33 #include "lyxrc.h"
34 #include "lyxrow.h"
35 #include "paragraph.h"
36 #include "paragraph_funcs.h"
37 #include "ParagraphParameters.h"
38 #include "undo.h"
39 #include "vspace.h"
40
41 #include "frontends/Dialogs.h"
42 #include "frontends/LyXView.h"
43
44 #include "insets/insetcommand.h"
45 #include "insets/insetfloatlist.h"
46 #include "insets/insetnewline.h"
47 #include "insets/insetspecialchar.h"
48 #include "insets/insettext.h"
49
50 #include "support/lstrings.h"
51 #include "support/lyxlib.h"
52 #include "support/tostr.h"
53 #include "support/std_sstream.h"
54
55 #include "mathed/math_hullinset.h"
56 #include "mathed/formulamacro.h"
57
58 #include <clocale>
59
60 using lyx::pos_type;
61
62 using lyx::support::isStrUnsignedInt;
63 using lyx::support::strToUnsignedInt;
64 using lyx::support::atoi;
65 using lyx::support::token;
66
67 using std::endl;
68 using std::find;
69 using std::string;
70 using std::istringstream;
71 using std::vector;
72
73
74 extern string current_layout;
75
76 // the selection possible is needed, that only motion events are
77 // used, where the button press event was on the drawing area too
78 bool selection_possible = false;
79
80
81 namespace {
82
83         // globals...
84         LyXFont freefont(LyXFont::ALL_IGNORE);
85         bool toggleall = false;
86
87
88         void toggleAndShow(LCursor & cur, LyXText * text,
89                 LyXFont const & font, bool toggleall = true)
90         {
91                 if (!cur.bv().available())
92                         return;
93
94                 text->toggleFree(cur, font, toggleall);
95
96                 if (font.language() != ignore_language ||
97                                 font.number() != LyXFont::IGNORE) {
98                         Paragraph & par = cur.paragraph();
99                         text->bidi.computeTables(par, *cur.bv().buffer(), cur.textRow());
100                         if (cur.boundary() !=
101                                         text->bidi.isBoundary(*cur.bv().buffer(), par,
102                                                         cur.pos(),
103                                                         text->real_current_font))
104                                 text->setCursor(cur.par(), cur.pos(),
105                                                 false, !cur.boundary());
106                 }
107                 cur.bv().update();
108         }
109
110
111         void moveCursor(LCursor & cur, bool selecting)
112         {
113                 if (selecting || cur.mark())
114                         cur.setSelection();
115                 if (!cur.selection())
116                         cur.bv().haveSelection(false);
117                 cur.bv().switchKeyMap();
118         }
119
120
121         void finishChange(LCursor & cur, bool selecting = false)
122         {
123                 finishUndo();
124                 moveCursor(cur, selecting);
125                 cur.bv().owner()->view_state_changed();
126         }
127
128
129         void mathDispatch(LCursor & cur, FuncRequest const & cmd, bool display)
130         {
131                 string sel = cur.selectionAsString(false);
132                 lyxerr << "selection is: '" << sel << "'" << endl;
133
134                 if (sel.empty()) {
135                         cur.insert(new MathHullInset);
136                         cur.dispatch(FuncRequest(LFUN_RIGHT));
137                         cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
138                         // don't do that also for LFUN_MATH_MODE unless you want end up with
139                         // always changing to mathrm when opening an inlined inset
140                         // -- I really hate "LyXfunc overloading"...
141                         if (display)
142                                 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
143                         cur.dispatch(FuncRequest(LFUN_INSERT_MATH, cmd.argument));
144                 } else {
145                         // create a macro if we see "\\newcommand" somewhere, and an ordinary
146                         // formula otherwise
147                         cur.bv().getLyXText()->cutSelection(true, true);
148                         if (sel.find("\\newcommand") == string::npos &&
149                                         sel.find("\\def") == string::npos)
150                         {
151                                 cur.insert(new MathHullInset);
152                                 cur.dispatch(FuncRequest(LFUN_RIGHT));
153                                 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
154                                 cur.dispatch(FuncRequest(LFUN_INSERT_MATH, sel));
155                         } else {
156                                 cur.insert(new InsetFormulaMacro(sel));
157                                 cur.dispatch(FuncRequest(LFUN_RIGHT));
158                         }
159                 }
160                 cur.message(N_("Math editor mode"));
161         }
162
163 } // namespace anon
164
165
166
167 namespace bv_funcs {
168
169 string const freefont2string()
170 {
171         string data;
172         if (font2string(freefont, toggleall, data))
173                 return data;
174         return string();
175 }
176
177 }
178
179
180 //takes absolute x,y coordinates
181 InsetBase * LyXText::checkInsetHit(int x, int y)
182 {
183         ParagraphList::iterator pit;
184         ParagraphList::iterator end;
185
186         getParsInRange(paragraphs(),
187                        bv()->top_y() - yo_,
188                        bv()->top_y() - yo_ + bv()->workHeight(),
189                        pit, end);
190
191         lyxerr << "checkInsetHit: x: " << x << " y: " << y << endl;
192         for ( ; pit != end; ++pit) {
193                 InsetList::iterator iit = pit->insetlist.begin();
194                 InsetList::iterator iend = pit->insetlist.end();
195                 for ( ; iit != iend; ++iit) {
196                         InsetBase * inset = iit->inset;
197 #if 1
198                         lyxerr << "examining inset " << inset
199                         //<< " xo/yo: " << inset->xo() << "/" << inset->yo()
200                                 << " xo: " << inset->xo() << "..." << inset->xo() + inset->width()
201                                 << " yo: " << inset->yo() - inset->ascent() << "..."
202                                 << inset->yo() + inset->descent() << endl;
203 #endif
204                         if (inset->covers(x, y)) {
205                                 lyxerr << "Hit inset: " << inset << endl;
206                                 return inset;
207                         }
208                 }
209         }
210         lyxerr << "No inset hit. " << endl;
211         return 0;
212 }
213
214
215 bool LyXText::gotoNextInset(vector<InsetOld_code> const & codes,
216                             string const & contents)
217 {
218         ParagraphList::iterator end = paragraphs().end();
219         ParagraphList::iterator pit = cursorPar();
220         pos_type pos = cursor().pos();
221
222         InsetBase * inset;
223         do {
224                 if (pos + 1 < pit->size()) {
225                         ++pos;
226                 } else  {
227                         ++pit;
228                         pos = 0;
229                 }
230
231         } while (pit != end &&
232                  !(pit->isInset(pos) &&
233                    (inset = pit->getInset(pos)) != 0 &&
234                    find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() &&
235                    (contents.empty() ||
236                     static_cast<InsetCommand *>(pit->getInset(pos))->getContents()
237                     == contents)));
238
239         if (pit == end)
240                 return false;
241
242         setCursor(parOffset(pit), pos, false);
243         return true;
244 }
245
246
247 void LyXText::gotoInset(vector<InsetOld_code> const & codes, bool same_content)
248 {
249         LCursor & cur = bv()->cursor();
250         cur.clearSelection();
251
252         string contents;
253         if (same_content
254             && cur.pos() < cur.lastpos()
255             && cur.paragraph().isInset(cur.pos())) {
256                 InsetBase const * inset = cur.paragraph().getInset(cur.pos());
257                 if (find(codes.begin(), codes.end(), inset->lyxCode())
258                     != codes.end())
259                         contents = static_cast<InsetCommand const *>(inset)->getContents();
260         }
261
262         if (!gotoNextInset(codes, contents)) {
263                 if (cur.pos() || cur.par() != 0) {
264                         CursorSlice tmp = cursor();
265                         cur.par() = 0;
266                         cur.pos() = 0;
267                         if (!gotoNextInset(codes, contents)) {
268                                 cursor() = tmp;
269                                 cur.message(_("No more insets"));
270                         }
271                 } else {
272                         cur.message(_("No more insets"));
273                 }
274         }
275         cur.bv().update();
276         cur.resetAnchor();
277 }
278
279
280 void LyXText::gotoInset(InsetOld_code code, bool same_content)
281 {
282         gotoInset(vector<InsetOld_code>(1, code), same_content);
283 }
284
285
286 void LyXText::cursorPrevious(LCursor & cur)
287 {
288         pos_type cpos = cur.pos();
289         lyx::paroffset_type cpar = cur.par();
290
291         int x = cur.x_target();
292         int y = bv()->top_y();
293         setCursorFromCoordinates(x, y);
294
295         if (cpar == cur.par() && cpos == cur.pos()) {
296                 // we have a row which is taller than the workarea. The
297                 // simplest solution is to move to the previous row instead.
298                 cursorUp(cur, true);
299         }
300
301         bv()->updateScrollbar();
302         finishUndo();
303 }
304
305
306 void LyXText::cursorNext(LCursor & cur)
307 {
308         pos_type cpos = cur.pos();
309         lyx::paroffset_type cpar = cur.par();
310
311         int x = cur.x_target();
312         int y = bv()->top_y() + bv()->workHeight();
313         setCursorFromCoordinates(x, y);
314
315         if (cpar == cur.par() && cpos == cur.pos()) {
316                 // we have a row which is taller than the workarea. The
317                 // simplest solution is to move to the next row instead.
318                 cursorDown(cur, true);
319         }
320
321         bv()->updateScrollbar();
322         finishUndo();
323 }
324
325
326 namespace {
327
328 void specialChar(LCursor & cur, LyXText * text, BufferView * bv,
329         InsetSpecialChar::Kind kind)
330 {
331         bv->update();
332         text->replaceSelection(cur);
333         cur.insert(new InsetSpecialChar(kind));
334         bv->update();
335 }
336
337
338 void doInsertInset(LCursor & cur, LyXText * text, BufferView * bv,
339         FuncRequest const & cmd, bool edit, bool pastesel)
340 {
341         InsetBase * inset = createInset(bv, cmd);
342         if (!inset)
343                 return;
344
345         bool gotsel = false;
346         if (cur.selection()) {
347                 bv->owner()->dispatch(FuncRequest(LFUN_CUT));
348                 gotsel = true;
349         }
350         text->insertInset(cur, inset);
351         if (edit)
352                 inset->edit(cur, true);
353         if (gotsel && pastesel)
354                 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
355 }
356
357 } // anon namespace
358
359
360 void LyXText::number()
361 {
362         LyXFont font(LyXFont::ALL_IGNORE);
363         font.setNumber(LyXFont::TOGGLE);
364         toggleAndShow(bv()->cursor(), this, font);
365 }
366
367
368 bool LyXText::rtl() const
369 {
370         return cursorPar()->isRightToLeftPar(bv()->buffer()->params());
371 }
372
373
374 DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
375 {
376         lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
377         //lyxerr << "*** LyXText::dispatch: cmd: " << cmd << endl;
378
379         BufferView * bv = &cur.bv();
380
381         switch (cmd.action) {
382
383         case LFUN_APPENDIX: {
384                 Paragraph & par = cur.paragraph();
385                 bool start = !par.params().startOfAppendix();
386
387                 // ensure that we have only one start_of_appendix in this document
388                 ParagraphList::iterator tmp = paragraphs().begin();
389                 ParagraphList::iterator end = paragraphs().end();
390
391                 for (; tmp != end; ++tmp) {
392                         if (tmp->params().startOfAppendix()) {
393                                 recUndo(parOffset(tmp));
394                                 tmp->params().startOfAppendix(false);
395                                 redoParagraph(tmp);
396                                 break;
397                         }
398                 }
399
400                 recordUndo(cur);
401                 par.params().startOfAppendix(start);
402
403                 // we can set the refreshing parameters now
404                 updateCounters();
405                 redoParagraph(cur);
406                 bv->update();
407                 break;
408         }
409
410         case LFUN_DELETE_WORD_FORWARD:
411                 cur.clearSelection();
412                 deleteWordForward(cur);
413                 finishChange(cur);
414                 break;
415
416         case LFUN_DELETE_WORD_BACKWARD:
417                 cur.clearSelection();
418                 deleteWordBackward(cur);
419                 finishChange(cur);
420                 break;
421
422         case LFUN_DELETE_LINE_FORWARD:
423                 cur.clearSelection();
424                 deleteLineForward(cur);
425                 finishChange(cur);
426                 break;
427
428         case LFUN_WORDRIGHT:
429                 if (!cur.mark())
430                         cur.clearSelection();
431                 if (rtl())
432                         cursorLeftOneWord(cur);
433                 else
434                         cursorRightOneWord(cur);
435                 finishChange(cur);
436                 break;
437
438         case LFUN_WORDLEFT:
439                 if (!cur.mark())
440                         cur.clearSelection();
441                 if (rtl())
442                         cursorRightOneWord(cur);
443                 else
444                         cursorLeftOneWord(cur);
445                 finishChange(cur);
446                 break;
447
448         case LFUN_BEGINNINGBUF:
449                 if (!cur.mark())
450                         cur.clearSelection();
451                 cursorTop(cur);
452                 finishChange(cur);
453                 break;
454
455         case LFUN_ENDBUF:
456                 if (!cur.mark())
457                         cur.clearSelection();
458                 cursorBottom(cur);
459                 finishChange(cur);
460                 break;
461
462         case LFUN_RIGHTSEL:
463                 if (!cur.selection())
464                         cur.resetAnchor();
465                 if (rtl())
466                         cursorLeft(cur, true);
467                 else
468                         cursorRight(cur, true);
469                 finishChange(cur, true);
470                 break;
471
472         case LFUN_LEFTSEL:
473                 if (!cur.selection())
474                         cur.resetAnchor();
475                 if (rtl())
476                         cursorRight(cur, true);
477                 else
478                         cursorLeft(cur, true);
479                 finishChange(cur, true);
480                 break;
481
482         case LFUN_UPSEL:
483                 if (!cur.selection())
484                         cur.resetAnchor();
485                 cursorUp(cur, true);
486                 finishChange(cur, true);
487                 break;
488
489         case LFUN_DOWNSEL:
490                 if (!cur.selection())
491                         cur.resetAnchor();
492                 cursorDown(cur, true);
493                 finishChange(cur, true);
494                 break;
495
496         case LFUN_UP_PARAGRAPHSEL:
497                 if (!cur.selection())
498                         cur.resetAnchor();
499                 cursorUpParagraph(cur);
500                 finishChange(cur, true);
501                 break;
502
503         case LFUN_DOWN_PARAGRAPHSEL:
504                 if (!cur.selection())
505                         cur.resetAnchor();
506                 cursorDownParagraph(cur);
507                 finishChange(cur, true);
508                 break;
509
510         case LFUN_PRIORSEL:
511                 if (!cur.selection())
512                         cur.resetAnchor();
513                 cursorPrevious(cur);
514                 finishChange(cur, true);
515                 break;
516
517         case LFUN_NEXTSEL:
518                 if (!cur.selection())
519                         cur.resetAnchor();
520                 cursorNext(cur);
521                 finishChange(cur, true);
522                 break;
523
524         case LFUN_HOMESEL:
525                 if (!cur.selection())
526                         cur.resetAnchor();
527                 cursorHome(cur);
528                 finishChange(cur, true);
529                 break;
530
531         case LFUN_ENDSEL:
532                 if (!cur.selection())
533                         cur.resetAnchor();
534                 cursorEnd(cur);
535                 finishChange(cur, true);
536                 break;
537
538         case LFUN_WORDRIGHTSEL:
539                 if (!cur.selection())
540                         cur.resetAnchor();
541                 if (rtl())
542                         cursorLeftOneWord(cur);
543                 else
544                         cursorRightOneWord(cur);
545                 finishChange(cur, true);
546                 break;
547
548         case LFUN_WORDLEFTSEL:
549                 if (!cur.selection())
550                         cur.resetAnchor();
551                 if (rtl())
552                         cursorRightOneWord(cur);
553                 else
554                         cursorLeftOneWord(cur);
555                 finishChange(cur, true);
556                 break;
557
558         case LFUN_WORDSEL: {
559                 selectWord(cur, lyx::WHOLE_WORD);
560                 finishChange(cur, true);
561                 break;
562         }
563
564         case LFUN_RIGHT:
565                 finishChange(cur);
566                 return moveRight(cur);
567
568         case LFUN_LEFT:
569                 finishChange(cur);
570                 return moveLeft(cur);
571
572         case LFUN_UP:
573                 finishChange(cur);
574                 return moveUp(cur);
575
576         case LFUN_DOWN:
577                 finishChange(cur);
578                 return moveDown(cur);
579
580         case LFUN_UP_PARAGRAPH:
581                 if (!cur.mark())
582                         cur.clearSelection();
583                 cursorUpParagraph(cur);
584                 finishChange(cur);
585                 break;
586
587         case LFUN_DOWN_PARAGRAPH:
588                 if (!cur.mark())
589                         cur.clearSelection();
590                 cursorDownParagraph(cur);
591                 finishChange(cur, false);
592                 break;
593
594         case LFUN_PRIOR:
595                 if (!cur.mark())
596                         cur.clearSelection();
597                 finishChange(cur, false);
598                 if (cur.par() == 0 && cur.textRow().pos() == 0)
599                         return DispatchResult(false, FINISHED_UP);
600                 cursorPrevious(cur);
601                 break;
602
603         case LFUN_NEXT:
604                 if (!cur.mark())
605                         cur.clearSelection();
606                 finishChange(cur, false);
607                 if (cur.par() == cur.lastpar()
608                           && cur.textRow().endpos() == cur.lastpos())
609                         return DispatchResult(false, FINISHED_DOWN);
610                 cursorNext(cur);
611                 break;
612
613         case LFUN_HOME:
614                 if (!cur.mark())
615                         cur.clearSelection();
616                 cursorHome(cur);
617                 finishChange(cur, false);
618                 break;
619
620         case LFUN_END:
621                 if (!cur.mark())
622                         cur.clearSelection();
623                 cursorEnd(cur);
624                 finishChange(cur, false);
625                 break;
626
627         case LFUN_BREAKLINE: {
628                 // Not allowed by LaTeX (labels or empty par)
629                 if (cur.pos() > cur.paragraph().beginOfBody()) {
630                         replaceSelection(cur);
631                         cur.insert(new InsetNewline);
632                         moveCursor(cur, false);
633                 }
634                 break;
635         }
636
637         case LFUN_DELETE:
638                 if (!cur.selection()) {
639                         Delete(cur);
640                         cur.resetAnchor();
641                         // It is possible to make it a lot faster still
642                         // just comment out the line below...
643                 } else {
644                         cutSelection(true, false);
645                 }
646                 moveCursor(cur, false);
647                 bv->owner()->view_state_changed();
648                 break;
649
650         case LFUN_DELETE_SKIP:
651                 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
652                 if (!cur.selection()) {
653                         if (cur.pos() == cur.lastpos()) {
654                                 cursorRight(cur, true);
655                                 cursorLeft(cur, true);
656                         }
657                         Delete(cur);
658                         cur.resetAnchor();
659                 } else {
660                         cutSelection(true, false);
661                 }
662                 bv->update();
663                 break;
664
665
666         case LFUN_BACKSPACE:
667                 if (!cur.selection()) {
668                         if (bv->owner()->getIntl().getTransManager().backspace()) {
669                                 backspace(cur);
670                                 cur.resetAnchor();
671                                 // It is possible to make it a lot faster still
672                                 // just comment out the line below...
673                         }
674                 } else {
675                         cutSelection(true, false);
676                 }
677                 bv->owner()->view_state_changed();
678                 bv->switchKeyMap();
679                 bv->update();
680                 break;
681
682         case LFUN_BACKSPACE_SKIP:
683                 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
684                 if (!cur.selection()) {
685 #warning look here
686                         //CursorSlice cur = cursor();
687                         backspace(cur);
688                         //anchor() = cur;
689                 } else {
690                         cutSelection(true, false);
691                 }
692                 bv->update();
693                 break;
694
695         case LFUN_BREAKPARAGRAPH:
696                 replaceSelection(cur);
697                 breakParagraph(cur, 0);
698                 bv->update();
699                 cur.resetAnchor();
700                 bv->switchKeyMap();
701                 bv->owner()->view_state_changed();
702                 break;
703
704         case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
705                 replaceSelection(cur);
706                 breakParagraph(cur, 1);
707                 bv->update();
708                 cur.resetAnchor();
709                 bv->switchKeyMap();
710                 bv->owner()->view_state_changed();
711                 break;
712
713         case LFUN_BREAKPARAGRAPH_SKIP: {
714                 // When at the beginning of a paragraph, remove
715                 // indentation and add a "defskip" at the top.
716                 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
717 #warning look here
718                 replaceSelection(cur);
719                 if (cur.pos() == 0) {
720                         ParagraphParameters & params = cur.paragraph().params();
721                         setParagraph(
722                                         params.spacing(),
723                                         params.align(),
724                                         params.labelWidthString(), 1);
725                 } else {
726                         breakParagraph(cur, 0);
727                 }
728                 bv->update();
729 //      anchor() = cur;
730                 bv->switchKeyMap();
731                 bv->owner()->view_state_changed();
732                 break;
733         }
734
735         case LFUN_PARAGRAPH_SPACING: {
736                 Paragraph & par = cur.paragraph();
737                 Spacing::Space cur_spacing = par.params().spacing().getSpace();
738                 float cur_value = 1.0;
739                 if (cur_spacing == Spacing::Other)
740                         cur_value = par.params().spacing().getValue();
741
742                 istringstream is(cmd.argument);
743                 string tmp;
744                 is >> tmp;
745                 Spacing::Space new_spacing = cur_spacing;
746                 float new_value = cur_value;
747                 if (tmp.empty()) {
748                         lyxerr << "Missing argument to `paragraph-spacing'"
749                                << endl;
750                 } else if (tmp == "single") {
751                         new_spacing = Spacing::Single;
752                 } else if (tmp == "onehalf") {
753                         new_spacing = Spacing::Onehalf;
754                 } else if (tmp == "double") {
755                         new_spacing = Spacing::Double;
756                 } else if (tmp == "other") {
757                         new_spacing = Spacing::Other;
758                         float tmpval = 0.0;
759                         is >> tmpval;
760                         lyxerr << "new_value = " << tmpval << endl;
761                         if (tmpval != 0.0)
762                                 new_value = tmpval;
763                 } else if (tmp == "default") {
764                         new_spacing = Spacing::Default;
765                 } else {
766                         lyxerr << _("Unknown spacing argument: ")
767                                << cmd.argument << endl;
768                 }
769                 if (cur_spacing != new_spacing || cur_value != new_value) {
770                         par.params().spacing(Spacing(new_spacing, new_value));
771                         redoParagraph(cur);
772                         bv->update();
773                 }
774                 break;
775         }
776
777         case LFUN_INSET_APPLY: {
778                 string const name = cmd.getArg(0);
779                 InsetBase * inset = bv->owner()->getDialogs().getOpenInset(name);
780                 if (inset)
781                         inset->dispatch(cur, FuncRequest(LFUN_INSET_MODIFY, cmd.argument));
782                 else
783                         dispatch(cur, FuncRequest(LFUN_INSET_INSERT, cmd.argument));
784                 break;
785         }
786
787         case LFUN_INSET_INSERT: {
788                 InsetBase * inset = createInset(bv, cmd);
789                 if (inset)
790                         insertInset(cur, inset);
791                 break;
792         }
793
794         case LFUN_INSET_SETTINGS:
795                 if (cur.inset() && cur.inset()->asUpdatableInset())
796                         cur.inset()->asUpdatableInset()->showInsetDialog(bv);
797                 break;
798
799         case LFUN_INSET_TOGGLE:
800                 cur.clearSelection();
801                 if (!toggleInset(cur))
802                         return DispatchResult(false);
803                 bv->update();
804                 bv->switchKeyMap();
805                 break;
806
807         case LFUN_SPACE_INSERT:
808                 if (cur.paragraph().layout()->free_spacing)
809                         insertChar(cur, ' ');
810                 else
811                         doInsertInset(cur, this, bv, cmd, false, false);
812                 moveCursor(cur, false);
813                 break;
814
815         case LFUN_HYPHENATION:
816                 specialChar(cur, this, bv, InsetSpecialChar::HYPHENATION);
817                 break;
818
819         case LFUN_LIGATURE_BREAK:
820                 specialChar(cur, this, bv, InsetSpecialChar::LIGATURE_BREAK);
821                 break;
822
823         case LFUN_LDOTS:
824                 specialChar(cur, this, bv, InsetSpecialChar::LDOTS);
825                 break;
826
827         case LFUN_END_OF_SENTENCE:
828                 specialChar(cur, this, bv, InsetSpecialChar::END_OF_SENTENCE);
829                 break;
830
831         case LFUN_MENU_SEPARATOR:
832                 specialChar(cur, this, bv, InsetSpecialChar::MENU_SEPARATOR);
833                 break;
834
835         case LFUN_UPCASE_WORD:
836                 changeCase(cur, LyXText::text_uppercase);
837                 bv->update();
838                 break;
839
840         case LFUN_LOWCASE_WORD:
841                 changeCase(cur, LyXText::text_lowercase);
842                 bv->update();
843                 break;
844
845         case LFUN_CAPITALIZE_WORD:
846                 changeCase(cur, LyXText::text_capitalization);
847                 bv->update();
848                 break;
849
850         case LFUN_TRANSPOSE_CHARS:
851                 recordUndo(cur);
852                 redoParagraph(cur);
853                 bv->update();
854                 break;
855
856         case LFUN_PASTE:
857                 cur.message(_("Paste"));
858                 replaceSelection(cur);
859 #warning FIXME Check if the arg is in the domain of available selections.
860                 if (isStrUnsignedInt(cmd.argument))
861                         pasteSelection(cur, strToUnsignedInt(cmd.argument));
862                 else
863                         pasteSelection(cur, 0);
864                 cur.clearSelection(); // bug 393
865                 bv->update();
866                 bv->switchKeyMap();
867                 finishUndo();
868                 break;
869
870         case LFUN_CUT:
871                 cutSelection(true, true);
872                 cur.message(_("Cut"));
873                 bv->update();
874                 break;
875
876         case LFUN_COPY:
877                 copySelection();
878                 cur.message(_("Copy"));
879                 break;
880
881         case LFUN_BEGINNINGBUFSEL:
882                 if (in_inset_)
883                         return DispatchResult(false);
884                 if (!cur.selection())
885                         cur.resetAnchor();
886                 cursorTop(cur);
887                 finishChange(cur, true);
888                 break;
889
890         case LFUN_ENDBUFSEL:
891                 if (in_inset_)
892                         return DispatchResult(false);
893                 if (!cur.selection())
894                         cur.resetAnchor();
895                 cursorBottom(cur);
896                 finishChange(cur, true);
897                 break;
898
899         case LFUN_GETXY:
900                 cur.message(tostr(cursorX(cur.current())) + ' '
901                           + tostr(cursorY(cur.current())));
902                 break;
903
904         case LFUN_SETXY: {
905                 int x = 0;
906                 int y = 0;
907                 istringstream is(cmd.argument);
908                 is >> x >> y;
909                 if (!is)
910                         lyxerr << "SETXY: Could not parse coordinates in '"
911                                << cmd.argument << std::endl;
912                 else
913                         setCursorFromCoordinates(x, y);
914                 break;
915         }
916
917         case LFUN_GETFONT:
918                 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
919                         cur.message("E");
920                 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
921                         cur.message("N");
922                 else
923                         cur.message("0");
924                 break;
925
926         case LFUN_GETLAYOUT:
927                 cur.message(cur.paragraph().layout()->name());
928                 break;
929
930         case LFUN_LAYOUT: {
931                 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
932                   << cmd.argument << endl;
933
934                 // This is not the good solution to the empty argument
935                 // problem, but it will hopefully suffice for 1.2.0.
936                 // The correct solution would be to augument the
937                 // function list/array with information about what
938                 // functions needs arguments and their type.
939                 if (cmd.argument.empty()) {
940                         cur.errorMessage(_("LyX function 'layout' needs an argument."));
941                         break;
942                 }
943
944                 // Derive layout number from given argument (string)
945                 // and current buffer's textclass (number)
946                 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
947                 bool hasLayout = tclass.hasLayout(cmd.argument);
948                 string layout = cmd.argument;
949
950                 // If the entry is obsolete, use the new one instead.
951                 if (hasLayout) {
952                         string const & obs = tclass[layout]->obsoleted_by();
953                         if (!obs.empty())
954                                 layout = obs;
955                 }
956
957                 if (!hasLayout) {
958                         cur.errorMessage(string(N_("Layout ")) + cmd.argument +
959                                 N_(" not known"));
960                         break;
961                 }
962
963                 bool change_layout = (current_layout != layout);
964
965                 if (!change_layout && cur.selection() &&
966                         cur.selBegin().par() != cur.selEnd().par())
967                 {
968                         ParagraphList::iterator spit = getPar(cur.selBegin());
969                         ParagraphList::iterator epit = boost::next(getPar(cur.selEnd()));
970                         while (spit != epit) {
971                                 if (spit->layout()->name() != current_layout) {
972                                         change_layout = true;
973                                         break;
974                                 }
975                                 ++spit;
976                         }
977                 }
978
979                 if (change_layout) {
980                         current_layout = layout;
981                         setLayout(cur, layout);
982                         bv->owner()->setLayout(layout);
983                         bv->update();
984                         bv->switchKeyMap();
985                 }
986                 break;
987         }
988
989         case LFUN_PASTESELECTION: {
990                 cur.clearSelection();
991                 string const clip = bv->getClipboard();
992                 if (!clip.empty()) {
993                         if (cmd.argument == "paragraph")
994                                 insertStringAsParagraphs(cur, clip);
995                         else
996                                 insertStringAsLines(cur, clip);
997                         bv->update();
998                 }
999                 break;
1000         }
1001
1002         case LFUN_GOTOERROR:
1003                 gotoInset(InsetBase::ERROR_CODE, false);
1004                 break;
1005
1006         case LFUN_GOTONOTE:
1007                 gotoInset(InsetBase::NOTE_CODE, false);
1008                 break;
1009
1010         case LFUN_REFERENCE_GOTO: {
1011                 vector<InsetOld_code> tmp;
1012                 tmp.push_back(InsetBase::LABEL_CODE);
1013                 tmp.push_back(InsetBase::REF_CODE);
1014                 gotoInset(tmp, true);
1015                 break;
1016         }
1017
1018         case LFUN_QUOTE: {
1019                 replaceSelection(cur);
1020                 Paragraph & par = cur.paragraph();
1021                 lyx::pos_type pos = cur.pos();
1022                 char c;
1023                 if (pos == 0)
1024                         c = ' ';
1025                 else if (cur.prevInset() && cur.prevInset()->isSpace())
1026                         c = ' ';
1027                 else
1028                         c = par.getChar(pos - 1);
1029
1030                 LyXLayout_ptr const & style = par.layout();
1031
1032                 BufferParams const & bufparams = bv->buffer()->params();
1033                 if (style->pass_thru ||
1034                     par.getFontSettings(bufparams, pos).language()->lang() == "hebrew")
1035                   cur.insert(new InsetQuotes(c, bufparams));
1036                 else
1037                         bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1038                 break;
1039         }
1040
1041         case LFUN_DATE_INSERT: {
1042                 replaceSelection(cur);
1043                 time_t now_time_t = time(NULL);
1044                 struct tm * now_tm = localtime(&now_time_t);
1045                 setlocale(LC_TIME, "");
1046                 string arg;
1047                 if (!cmd.argument.empty())
1048                         arg = cmd.argument;
1049                 else
1050                         arg = lyxrc.date_insert_format;
1051                 char datetmp[32];
1052                 int const datetmp_len =
1053                         ::strftime(datetmp, 32, arg.c_str(), now_tm);
1054
1055                 for (int i = 0; i < datetmp_len; i++)
1056                         insertChar(cur, datetmp[i]);
1057
1058                 cur.resetAnchor();
1059                 moveCursor(cur, false);
1060                 break;
1061         }
1062
1063         case LFUN_MOUSE_TRIPLE:
1064                 if (cmd.button() == mouse_button::button1) {
1065                         selection_possible = true;
1066                         cursorHome(cur);
1067                         cur.resetAnchor();
1068                         cursorEnd(cur);
1069                         cur.setSelection();
1070                         bv->haveSelection(cur.selection());
1071                 }
1072                 break;
1073
1074         case LFUN_MOUSE_DOUBLE:
1075                 if (cmd.button() == mouse_button::button1) {
1076                         selection_possible = true;
1077                         selectWord(cur, lyx::WHOLE_WORD_STRICT);
1078                         bv->haveSelection(cur.selection());
1079                 }
1080                 break;
1081
1082         case LFUN_MOUSE_MOTION: {
1083                 // Only use motion with button 1
1084                 //if (ev.button() != mouse_button::button1)
1085                 //      return false;
1086                 // The test for not selection possible is needed, that
1087                 // only motion events are used, where the bottom press
1088                 // event was on the drawing area too
1089                 if (!selection_possible) {
1090                         lyxerr[Debug::ACTION] << "BufferView::Pimpl::"
1091                                 "Dispatch: no selection possible\n";
1092                         break;
1093                 }
1094                 CursorSlice old = cur.current();
1095
1096 #warning
1097                 setCursorFromCoordinates(cmd.x, cmd.y);
1098
1099                 // This is to allow jumping over large insets
1100                 // FIXME: shouldn't be top-text-specific
1101                 if (!in_inset_ && cur.current() == old) {
1102                         if (cmd.y - bv->top_y() >= bv->workHeight())
1103                                 cursorDown(cur, true);
1104                         else if (cmd.y - bv->top_y() < 0)
1105                                 cursorUp(cur, true);
1106                 }
1107
1108                 // don't set anchor_
1109                 bv->cursor().cursor_ = cur.cursor_;
1110                 bv->cursor().setSelection();
1111
1112                 break;
1113         }
1114
1115         // Single-click on work area
1116         case LFUN_MOUSE_PRESS: {
1117                 // ok ok, this is a hack (for xforms)
1118                 // We shouldn't go further down as we really should only do the
1119                 // scrolling and be done with this. Otherwise we may open some
1120                 // dialogs (Jug 20020424).
1121                 if (cmd.button() == mouse_button::button4) {
1122                         bv->scroll(-lyxrc.wheel_jump);
1123                         break;
1124                 }
1125
1126                 if (cmd.button() == mouse_button::button5) {
1127                         bv->scroll(lyxrc.wheel_jump);
1128                         break;
1129                 }
1130
1131                 // Right click on a footnote flag opens float menu
1132                 if (cmd.button() == mouse_button::button3) {
1133                         cur.clearSelection();
1134                         selection_possible = false;
1135                         break;
1136                 }
1137
1138                 // Middle button press pastes if we have a selection
1139                 // We do this here as if the selection was inside an inset
1140                 // it could get cleared on the unlocking of the inset so
1141                 // we have to check this first
1142                 bool paste_internally = false;
1143                 if (cmd.button() == mouse_button::button2 && cur.selection()) {
1144                         bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1145                         paste_internally = true;
1146                 }
1147
1148                 selection_possible = true;
1149
1150                 // Clear the selection
1151                 cur.clearSelection();
1152
1153                 setCursorFromCoordinates(cur.current(), cmd.x - xo_,
1154                                          cmd.y - yo_);
1155                 cur.resetAnchor();
1156                 finishUndo();
1157                 cur.x_target() = cursorX(cur.current());
1158
1159                 // set cursor and anchor to this position
1160                 bv->cursor() = cur;
1161
1162                 if (bv->fitCursor())
1163                         selection_possible = false;
1164
1165                 // Insert primary selection with middle mouse
1166                 // if there is a local selection in the current buffer,
1167                 // insert this
1168                 if (cmd.button() == mouse_button::button2) {
1169                         if (paste_internally)
1170                                 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1171                         else
1172                                 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1173                         selection_possible = false;
1174                 }
1175                 break;
1176         }
1177
1178         case LFUN_MOUSE_RELEASE: {
1179                 // do nothing if we used the mouse wheel
1180                 if (cmd.button() == mouse_button::button4
1181                  || cmd.button() == mouse_button::button5)
1182                         return DispatchResult(true, false);
1183
1184                 selection_possible = false;
1185
1186                 if (cmd.button() == mouse_button::button2)
1187                         break;
1188
1189                 // finish selection
1190                 if (cmd.button() == mouse_button::button1)
1191                         bv->haveSelection(cur.selection());
1192
1193                 bv->switchKeyMap();
1194                 bv->owner()->view_state_changed();
1195                 bv->owner()->updateMenubar();
1196                 bv->owner()->updateToolbar();
1197                 break;
1198         }
1199
1200         case LFUN_SELFINSERT: {
1201                 if (cmd.argument.empty())
1202                         break;
1203
1204                 // Automatically delete the currently selected
1205                 // text and replace it with what is being
1206                 // typed in now. Depends on lyxrc settings
1207                 // "auto_region_delete", which defaults to
1208                 // true (on).
1209
1210                 if (lyxrc.auto_region_delete) {
1211                         if (cur.selection())
1212                                 cutSelection(false, false);
1213                         bv->haveSelection(false);
1214                 }
1215
1216                 cur.clearSelection();
1217                 LyXFont const old_font = real_current_font;
1218
1219                 string::const_iterator cit = cmd.argument.begin();
1220                 string::const_iterator end = cmd.argument.end();
1221                 for (; cit != end; ++cit)
1222                         bv->owner()->getIntl().getTransManager().
1223                                 TranslateAndInsert(*cit, this);
1224
1225                 cur.resetAnchor();
1226                 moveCursor(cur, false);
1227
1228                 // real_current_font.number can change so we need to
1229                 // update the minibuffer
1230                 if (old_font != real_current_font)
1231                         bv->owner()->view_state_changed();
1232                 bv->updateScrollbar();
1233                 break;
1234         }
1235
1236         case LFUN_URL: {
1237                 InsetCommandParams p("url");
1238                 string const data = InsetCommandMailer::params2string("url", p);
1239                 bv->owner()->getDialogs().show("url", data, 0);
1240                 break;
1241         }
1242
1243         case LFUN_HTMLURL: {
1244                 InsetCommandParams p("htmlurl");
1245                 string const data = InsetCommandMailer::params2string("url", p);
1246                 bv->owner()->getDialogs().show("url", data, 0);
1247                 break;
1248         }
1249
1250         case LFUN_INSERT_LABEL: {
1251                 InsetCommandParams p("label");
1252                 string const data = InsetCommandMailer::params2string("label", p);
1253                 bv->owner()->getDialogs().show("label", data, 0);
1254                 break;
1255         }
1256
1257
1258 #if 0
1259         case LFUN_INSET_LIST:
1260         case LFUN_INSET_THEOREM:
1261         case LFUN_INSET_CAPTION:
1262 #endif
1263         case LFUN_INSERT_NOTE:
1264         case LFUN_INSERT_CHARSTYLE:
1265         case LFUN_INSERT_BOX:
1266         case LFUN_INSERT_BRANCH:
1267         case LFUN_INSERT_BIBITEM:
1268         case LFUN_INSET_ERT:
1269         case LFUN_INSET_FLOAT:
1270         case LFUN_INSET_FOOTNOTE:
1271         case LFUN_INSET_MARGINAL:
1272         case LFUN_INSET_OPTARG:
1273         case LFUN_INSET_WIDE_FLOAT:
1274         case LFUN_INSET_WRAP:
1275         case LFUN_TABULAR_INSERT:
1276         case LFUN_ENVIRONMENT_INSERT:
1277                 // Open the inset, and move the current selection
1278                 // inside it.
1279                 doInsertInset(cur, this, bv, cmd, true, true);
1280                 break;
1281
1282         case LFUN_INDEX_INSERT:
1283                 // Just open the inset
1284                 doInsertInset(cur, this, bv, cmd, true, false);
1285                 break;
1286
1287         case LFUN_INDEX_PRINT:
1288         case LFUN_TOC_INSERT:
1289         case LFUN_HFILL:
1290         case LFUN_INSERT_LINE:
1291         case LFUN_INSERT_PAGEBREAK:
1292                 // do nothing fancy
1293                 doInsertInset(cur, this, bv, cmd, false, false);
1294                 break;
1295
1296         case LFUN_DEPTH_MIN:
1297                 changeDepth(cur, bv_funcs::DEC_DEPTH);
1298                 bv->update();
1299                 break;
1300
1301         case LFUN_DEPTH_PLUS:
1302                 changeDepth(cur, bv_funcs::INC_DEPTH);
1303                 bv->update();
1304                 break;
1305
1306         case LFUN_MATH_DISPLAY:
1307                 mathDispatch(cur, cmd, true);
1308                 break;
1309
1310         case LFUN_MATH_IMPORT_SELECTION:
1311         case LFUN_MATH_MODE:
1312                 mathDispatch(cur, cmd, false);
1313                 break;
1314
1315         case LFUN_MATH_MACRO:
1316                 if (cmd.argument.empty())
1317                         cur.errorMessage(N_("Missing argument"));
1318                 else {
1319                         string s = cmd.argument;
1320                         string const s1 = token(s, ' ', 1);
1321                         int const nargs = s1.empty() ? 0 : atoi(s1);
1322                         string const s2 = token(s, ' ', 2);
1323                         string const type = s2.empty() ? "newcommand" : s2;
1324                         cur.insert(new InsetFormulaMacro(token(s, ' ', 0), nargs, s2));
1325                         cur.nextInset()->edit(cur, true);
1326                 }
1327                 break;
1328
1329         case LFUN_INSERT_MATH:
1330         case LFUN_INSERT_MATRIX:
1331         case LFUN_MATH_DELIM: {
1332                 cur.insert(new MathHullInset);
1333                 cur.dispatch(FuncRequest(LFUN_RIGHT));
1334                 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
1335                 cur.dispatch(cmd);
1336                 break;
1337         }
1338
1339         case LFUN_EMPH: {
1340                 LyXFont font(LyXFont::ALL_IGNORE);
1341                 font.setEmph(LyXFont::TOGGLE);
1342                 toggleAndShow(cur, this, font);
1343                 bv->owner()->view_state_changed();
1344                 break;
1345         }
1346
1347         case LFUN_BOLD: {
1348                 LyXFont font(LyXFont::ALL_IGNORE);
1349                 font.setSeries(LyXFont::BOLD_SERIES);
1350                 toggleAndShow(cur, this, font);
1351                 bv->owner()->view_state_changed();
1352                 break;
1353         }
1354
1355         case LFUN_NOUN: {
1356                 LyXFont font(LyXFont::ALL_IGNORE);
1357                 font.setNoun(LyXFont::TOGGLE);
1358                 toggleAndShow(cur, this, font);
1359                 bv->owner()->view_state_changed();
1360                 break;
1361         }
1362
1363         case LFUN_CODE: {
1364                 LyXFont font(LyXFont::ALL_IGNORE);
1365                 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1366                 toggleAndShow(cur, this, font);
1367                 bv->owner()->view_state_changed();
1368                 break;
1369         }
1370
1371         case LFUN_SANS: {
1372                 LyXFont font(LyXFont::ALL_IGNORE);
1373                 font.setFamily(LyXFont::SANS_FAMILY);
1374                 toggleAndShow(cur, this, font);
1375                 bv->owner()->view_state_changed();
1376                 break;
1377         }
1378
1379         case LFUN_ROMAN: {
1380                 LyXFont font(LyXFont::ALL_IGNORE);
1381                 font.setFamily(LyXFont::ROMAN_FAMILY);
1382                 toggleAndShow(cur, this, font);
1383                 bv->owner()->view_state_changed();
1384                 break;
1385         }
1386
1387         case LFUN_DEFAULT: {
1388                 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1389                 toggleAndShow(cur, this, font);
1390                 bv->owner()->view_state_changed();
1391                 break;
1392         }
1393
1394         case LFUN_UNDERLINE: {
1395                 LyXFont font(LyXFont::ALL_IGNORE);
1396                 font.setUnderbar(LyXFont::TOGGLE);
1397                 toggleAndShow(cur, this, font);
1398                 bv->owner()->view_state_changed();
1399                 break;
1400         }
1401
1402         case LFUN_FONT_SIZE: {
1403                 LyXFont font(LyXFont::ALL_IGNORE);
1404                 font.setLyXSize(cmd.argument);
1405                 toggleAndShow(cur, this, font);
1406                 bv->owner()->view_state_changed();
1407                 break;
1408         }
1409
1410         case LFUN_LANGUAGE: {
1411                 Language const * lang = languages.getLanguage(cmd.argument);
1412                 if (!lang)
1413                         break;
1414                 LyXFont font(LyXFont::ALL_IGNORE);
1415                 font.setLanguage(lang);
1416                 toggleAndShow(cur, this, font);
1417                 bv->switchKeyMap();
1418                 bv->owner()->view_state_changed();
1419                 break;
1420         }
1421
1422         case LFUN_FREEFONT_APPLY:
1423                 toggleAndShow(cur, this, freefont, toggleall);
1424                 bv->owner()->view_state_changed();
1425                 cur.message(_("Character set"));
1426                 break;
1427
1428         // Set the freefont using the contents of \param data dispatched from
1429         // the frontends and apply it at the current cursor location.
1430         case LFUN_FREEFONT_UPDATE: {
1431                 LyXFont font;
1432                 bool toggle;
1433                 if (bv_funcs::string2font(cmd.argument, font, toggle)) {
1434                         freefont = font;
1435                         toggleall = toggle;
1436                         toggleAndShow(cur, this, freefont, toggleall);
1437                         bv->owner()->view_state_changed();
1438                         cur.message(_("Character set"));
1439                 }
1440                 break;
1441         }
1442
1443         case LFUN_FINISHED_LEFT:
1444                 lyxerr << "handle LFUN_FINISHED_LEFT" << endl;
1445                 cur.pop(cur.currentDepth());
1446                 if (rtl())
1447                         cursorLeft(cur, true);
1448                 cur.bv().cursor() = cur;
1449                 break;
1450
1451         case LFUN_FINISHED_RIGHT:
1452                 lyxerr << "handle LFUN_FINISHED_RIGHT" << endl;
1453                 cur.pop(cur.currentDepth());
1454                 if (!rtl())
1455                         cursorRight(cur, true);
1456                 cur.bv().cursor() = cur;
1457                 break;
1458
1459         case LFUN_FINISHED_UP:
1460                 lyxerr << "handle LFUN_FINISHED_UP" << endl;
1461                 cur.pop(cur.currentDepth());
1462                 cursorUp(cur, true);
1463                 cur.bv().cursor() = cur;
1464                 break;
1465
1466         case LFUN_FINISHED_DOWN:
1467                 lyxerr << "handle LFUN_FINISHED_DOWN" << endl;
1468                 cur.pop(cur.currentDepth());
1469                 cursorDown(cur, true);
1470                 cur.bv().cursor() = cur;
1471                 break;
1472
1473         case LFUN_LAYOUT_PARAGRAPH: {
1474                 string data;
1475                 params2string(cur.paragraph(), data);
1476                 data = "show\n" + data;
1477                 bv->owner()->getDialogs().show("paragraph", data);
1478                 break;
1479         }
1480
1481         case LFUN_PARAGRAPH_UPDATE: {
1482                 if (!bv->owner()->getDialogs().visible("paragraph"))
1483                         break;
1484                 string data;
1485                 params2string(cur.paragraph(), data);
1486
1487                 // Will the paragraph accept changes from the dialog?
1488                 InsetBase * const inset = cur.inset();
1489                 bool const accept =
1490                         !(inset && inset->forceDefaultParagraphs(inset));
1491
1492                 data = "update " + tostr(accept) + '\n' + data;
1493                 bv->owner()->getDialogs().update("paragraph", data);
1494                 break;
1495         }
1496
1497         case LFUN_UMLAUT:
1498         case LFUN_CIRCUMFLEX:
1499         case LFUN_GRAVE:
1500         case LFUN_ACUTE:
1501         case LFUN_TILDE:
1502         case LFUN_CEDILLA:
1503         case LFUN_MACRON:
1504         case LFUN_DOT:
1505         case LFUN_UNDERDOT:
1506         case LFUN_UNDERBAR:
1507         case LFUN_CARON:
1508         case LFUN_SPECIAL_CARON:
1509         case LFUN_BREVE:
1510         case LFUN_TIE:
1511         case LFUN_HUNG_UMLAUT:
1512         case LFUN_CIRCLE:
1513         case LFUN_OGONEK:
1514                 bv->owner()->getLyXFunc().handleKeyFunc(cmd.action);
1515                 if (!cmd.argument.empty())
1516                         bv->owner()->getIntl().getTransManager()
1517                                 .TranslateAndInsert(cmd.argument[0], this);
1518                 break;
1519
1520         case LFUN_FLOAT_LIST: {
1521                 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1522                 if (tclass.floats().typeExist(cmd.argument)) {
1523                         // not quite sure if we want this...
1524                         recordUndo(cur);
1525                         freezeUndo();
1526                         cur.clearSelection();
1527                         breakParagraph(cur);
1528
1529                         if (cur.lastpos() != 0) {
1530                                 cursorLeft(cur, true);
1531                                 breakParagraph(cur);
1532                         }
1533
1534                         setLayout(cur, tclass.defaultLayoutName());
1535                         setParagraph(Spacing(), LYX_ALIGN_LAYOUT, string(), 0);
1536                         cur.insert(new InsetFloatList(cmd.argument));
1537                         unFreezeUndo();
1538                 } else {
1539                         lyxerr << "Non-existent float type: "
1540                                << cmd.argument << endl;
1541                 }
1542                 break;
1543         }
1544
1545         case LFUN_ACCEPT_CHANGE: {
1546                 acceptChange(cur);
1547                 bv->update();
1548                 break;
1549         }
1550
1551         case LFUN_REJECT_CHANGE: {
1552                 rejectChange(cur);
1553                 bv->update();
1554                 break;
1555         }
1556
1557         case LFUN_THESAURUS_ENTRY: {
1558                 string arg = cmd.argument;
1559                 if (arg.empty()) {
1560                         arg = cur.selectionAsString(false);
1561                         // FIXME
1562                         if (arg.size() > 100 || arg.empty()) {
1563                                 // Get word or selection
1564                                 selectWordWhenUnderCursor(cur, lyx::WHOLE_WORD);
1565                                 arg = cur.selectionAsString(false);
1566                         }
1567                 }
1568                 bv->owner()->getDialogs().show("thesaurus", arg);
1569                 break;
1570         }
1571
1572         default:
1573                 return DispatchResult(false);
1574         }
1575
1576         return DispatchResult(true, true);
1577 }