]> git.lyx.org Git - lyx.git/blob - src/lyxfunc.C
3e4ea34e7a6964258cc9652658699d0b041524fd
[lyx.git] / src / lyxfunc.C
1 /* This file is part of
2  * ====================================================== 
3  * 
4  *           LyX, The Document Processor
5  *       
6  *          Copyright 1995 Matthias Ettrich
7  *          Copyright 1995-2000 The LyX Team.
8  *
9  * ====================================================== */
10
11 #include <config.h>
12
13 #include "Lsstream.h"
14
15 #include <time.h>
16 #include <locale.h>
17
18 #include <cstdlib>
19 #include <cctype>
20 #include <cstring>
21
22 #ifdef __GNUG__
23 #pragma implementation
24 #endif
25
26 #include "version.h"
27 #include "kbmap.h"
28 #include "lyxfunc.h"
29 #include "bufferlist.h"
30 #include "ColorHandler.h"
31 #include "lyxserver.h"
32 #include "lyx.h"
33 #include "intl.h"
34 #include "lyx_main.h"
35 #include "lyx_cb.h"
36 #include "LyXAction.h"
37 #include "insets/inseturl.h"
38 #include "insets/insetlatexaccent.h"
39 #include "insets/insettoc.h"
40 #include "insets/insetref.h"
41 #include "insets/insetparent.h"
42 #include "insets/insetindex.h"
43 #include "insets/insetinclude.h"
44 #include "insets/insetbib.h"
45 #include "insets/insetcite.h"
46 #include "insets/insettext.h"
47 #include "insets/insetert.h"
48 #include "insets/insetexternal.h"
49 #include "insets/insetgraphics.h"
50 #include "insets/insetfoot.h"
51 #include "insets/insetmarginal.h"
52 #include "insets/insetminipage.h"
53 #include "insets/insetfloat.h"
54 #include "insets/insetlist.h"
55 #include "insets/insettabular.h"
56 #include "insets/insettheorem.h"
57 #include "insets/insetcaption.h"
58 #include "mathed/formulamacro.h"
59 #include "spellchecker.h" // RVDK_PATCH_5
60 #include "minibuffer.h"
61 #include "vspace.h"
62 #include "LyXView.h"
63 #include "filedlg.h"
64 #include "lyx_gui_misc.h"
65 #include "support/filetools.h"
66 #include "support/FileInfo.h"
67 #include "support/syscall.h"
68 #include "support/lstrings.h"
69 #include "support/path.h"
70 #include "support/lyxfunctional.h"
71 #include "debug.h"
72 #include "lyxrc.h"
73 #include "lyxtext.h"
74 #include "gettext.h"
75 #include "trans_mgr.h"
76 #include "layout.h"
77 #include "WorkArea.h"
78 #include "lyxfr1.h"
79 #include "bufferview_funcs.h"
80 #include "frontends/Dialogs.h"
81 #include "frontends/Toolbar.h"
82 #include "frontends/Menubar.h"
83 #include "FloatList.h"
84 #include "converter.h"
85 #include "exporter.h"
86 #include "importer.h"
87 #include "FontLoader.h"
88 #include "TextCache.h"
89
90 using std::pair;
91 using std::endl;
92 using std::find_if;
93
94 extern void math_insert_symbol(BufferView *, string const &);
95 extern bool math_insert_greek(BufferView *, char);
96 extern BufferList bufferlist;
97 extern LyXServer * lyxserver;
98 extern int greek_kb_flag;
99 extern bool selection_possible;
100
101 extern kb_keymap * toplevel_keymap;
102
103 extern void show_symbols_form(LyXFunc *);
104
105 extern LyXAction lyxaction;
106 // (alkis)
107 extern tex_accent_struct get_accent(kb_action action);
108
109 extern LyXTextClass::size_type current_layout;
110
111 extern void ShowLatexLog();
112
113 /* === globals =========================================================== */
114
115 bool LyXFunc::show_sc = true;
116
117 LyXFunc::LyXFunc(LyXView * o)
118         : owner(o)
119 {
120         meta_fake_bit = 0;
121         lyx_dead_action = LFUN_NOACTION;
122         lyx_calling_dead_action = LFUN_NOACTION;
123         setupLocalKeymap();
124 }
125
126 inline
127 LyXText * LyXFunc::TEXT(bool flag=true) const
128 {
129         if (flag)
130                 return owner->view()->text;
131         return owner->view()->getLyXText();
132 }
133
134 // I changed this func slightly. I commented out the ...FinishUndo(),
135 // this means that all places that used to have a moveCursorUpdate, now
136 // have a ...FinishUndo() as the preceeding statement. I have also added
137 // a moveCursorUpdate to some of the functions that updated the cursor, but
138 // that did not show its new position.
139 inline
140 void LyXFunc::moveCursorUpdate(bool flag, bool selecting)
141 {
142         if (selecting || TEXT(flag)->mark_set) {
143                 TEXT(flag)->SetSelection(owner->view());
144                 if (TEXT(flag)->bv_owner)
145                     owner->view()->toggleToggle();
146         }
147         owner->view()->update(TEXT(flag), BufferView::SELECT|BufferView::FITCUR);
148         owner->view()->showCursor();
149         
150         /* ---> Everytime the cursor is moved, show the current font state. */
151         // should this too me moved out of this func?
152         //owner->showState();
153         owner->view()->setState();
154 }
155
156
157 int LyXFunc::processKeySym(KeySym keysym, unsigned int state) 
158 {
159         string argument;
160         
161         if (lyxerr.debugging(Debug::KEY)) {
162                 char * tmp = XKeysymToString(keysym);
163                 string const stm = (tmp ? tmp : "");
164                 lyxerr << "KeySym is "
165                        << stm
166                        << "["
167                        << keysym << "] State is ["
168                        << state << "]"
169                        << endl;
170         }
171         // Do nothing if we have nothing (JMarc)
172         if (keysym == NoSymbol) {
173                 lyxerr[Debug::KEY] << "Empty kbd action (probably composing)"
174                                    << endl;
175                 //return 0;
176                 return FL_PREEMPT;
177         }
178
179         if (owner->view()->available()) {
180                 // this function should be used always [asierra060396]
181                 UpdatableInset * tli = owner->view()->theLockingInset();
182                 if (tli && (keysym == XK_Escape)) {
183                         if (tli == tli->GetLockingInset()) {
184                                 owner->view()->unlockInset(tli);
185                                 TEXT()->CursorRight(owner->view());
186                                 moveCursorUpdate(true, false);
187                                 owner->showState();
188                         } else {
189                                 tli->UnlockInsetInInset(owner->view(),
190                                                         tli->GetLockingInset(),true);
191                         }
192                         //return 0;
193                         return FL_PREEMPT;
194                 }
195         }
196         
197         // Can we be sure that this will work for all X-Windows
198         // implementations? (Lgb)
199         // This code snippet makes lyx ignore some keys. Perhaps
200         // all of them should be explictly mentioned?
201         if ((keysym >= XK_Shift_L && keysym <= XK_Hyper_R)
202            || keysym == XK_Mode_switch || keysym == 0x0)
203                 return 0;
204
205         // Do a one-deep top-level lookup for
206         // cancel and meta-fake keys. RVDK_PATCH_5
207         cancel_meta_seq.reset();
208
209         int action = cancel_meta_seq.addkey(keysym, state
210                                             &(ShiftMask|ControlMask
211                                               |Mod1Mask)); 
212         if (lyxerr.debugging(Debug::KEY)) {
213                 lyxerr << "action first set to [" << action << "]" << endl;
214         }
215         
216         // When not cancel or meta-fake, do the normal lookup. 
217         // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
218         // Mostly, meta_fake_bit = 0. RVDK_PATCH_5.
219         if ((action != LFUN_CANCEL) && (action != LFUN_META_FAKE)) {
220                 if (lyxerr.debugging(Debug::KEY)) {
221                         lyxerr << "meta_fake_bit is [" << meta_fake_bit << "]" << endl;
222                 }
223                 // remove Caps Lock and Mod2 as a modifiers
224                 action = keyseq.addkey(keysym,
225                                        (state | meta_fake_bit)
226                                        &(ShiftMask|ControlMask
227                                          |Mod1Mask));
228                 if (lyxerr.debugging(Debug::KEY)) {
229                         lyxerr << "action now set to [" << action << "]" << endl;
230                 }
231         }
232         // Dont remove this unless you know what you are doing.
233         meta_fake_bit = 0;
234                 
235         if (action == 0) action = LFUN_PREFIX;
236
237         if (lyxerr.debugging(Debug::KEY)) {
238                 string buf;
239                 keyseq.print(buf);
240                 lyxerr << "Key ["
241                        << action << "]["
242                        << buf << "]"
243                        << endl;
244         }
245
246         // already here we know if it any point in going further
247         // why not return already here if action == -1 and
248         // num_bytes == 0? (Lgb)
249
250         if (keyseq.length > 1 || keyseq.length < -1) {
251                 string buf;
252                 keyseq.print(buf);
253                 owner->getMiniBuffer()->Set(buf);
254         }
255
256         if (action == -1) {
257                 if (keyseq.length < -1) { // unknown key sequence...
258                         string buf;
259                         keyseq.print(buf);
260                         owner->getMiniBuffer()->Set(_("Unknown sequence:"), buf);
261                         return 0;
262                 }
263         
264                 char const isochar = keyseq.getiso();
265                 if (!(state & ControlMask) &&
266                     !(state & Mod1Mask) &&
267                     (isochar && keysym < 0xF000)) {
268                         argument += isochar;
269                 }
270                 if (argument.empty()) {
271                         lyxerr.debug() << "Empty argument!" << endl;
272                         // This can`t possibly be of any use
273                         // so we`ll skip the dispatch.
274                         return 0;
275                 }
276         } else if (action == LFUN_SELFINSERT) {
277                 // We must set the argument to the char looked up by
278                 // XKeysymToString
279                 XKeyEvent xke;
280                 xke.type = KeyPress;
281                 xke.serial = 0;
282                 xke.send_event = False;
283                 xke.display = fl_get_display();
284                 xke.window = 0;
285                 xke.root = 0;
286                 xke.subwindow = 0;
287                 xke.time = 0;
288                 xke.x = 0;
289                 xke.y = 0;
290                 xke.x_root = 0;
291                 xke.y_root = 0;
292                 xke.state = state;
293                 xke.keycode = XKeysymToKeycode(fl_get_display(), keysym);
294                 xke.same_screen = True;
295                 char ret[10];
296                 KeySym tmpkeysym;
297                 int res = XLookupString(&xke, ret, 10, &tmpkeysym, 0);
298                 //Assert(keysym == tmpkeysym);
299                 lyxerr[Debug::KEY] << "TmpKeysym ["
300                                    << tmpkeysym << "]" << endl;
301                 
302                 if (res > 0)
303                         argument = string(ret, res);
304                 lyxerr[Debug::KEY] << "SelfInsert arg["
305                                    << argument << "]" << endl;
306         }
307         
308
309         bool tmp_sc = show_sc;
310         show_sc = false;
311         Dispatch(action, argument);
312         show_sc = tmp_sc;
313         
314         return 0;
315
316
317
318 LyXFunc::func_status LyXFunc::getStatus(int ac) const
319 {
320         kb_action action;
321         func_status flag = LyXFunc::OK;
322         string argument;
323         Buffer * buf = owner->buffer();
324         
325         if (lyxaction.isPseudoAction(ac)) 
326                 action = lyxaction.retrieveActionArg(ac, argument);
327         else
328                 action = static_cast<kb_action>(ac);
329         
330         if (action == LFUN_UNKNOWN_ACTION) {
331                 setErrorMessage(N_("Unknown action"));
332                 return LyXFunc::Unknown;
333         }
334         
335         // Check whether we need a buffer
336         if (!lyxaction.funcHasFlag(action, LyXAction::NoBuffer)) {
337                 // Yes we need a buffer, do we have one?
338                 if (buf) {
339                         // yes
340                         // Can we use a readonly buffer?
341                         if (buf->isReadonly() && 
342                             !lyxaction.funcHasFlag(action,
343                                                    LyXAction::ReadOnly)) {
344                                 // no
345                                 setErrorMessage(N_("Document is read-only"));
346                                 flag |= LyXFunc::Disabled;
347                         }
348                 } else {
349                         // no
350                         setErrorMessage(N_("Command not allowed with"
351                                            "out any document open"));
352                         flag |= LyXFunc::Disabled;
353                         return flag;
354                 }
355         }
356
357         // I would really like to avoid having this switch and rather try to
358         // encode this in the function itself.
359         bool disable = false;
360         switch (action) {
361         case LFUN_MENUPRINT:
362                 disable = !Exporter::IsExportable(buf, "dvi")
363                         || lyxrc.print_command == "none";
364                 break;
365         case LFUN_EXPORT:
366                 disable = argument == "fax" &&
367                         !Exporter::IsExportable(buf, argument);
368                 break;
369         case LFUN_UNDO:
370                 disable = buf->undostack.empty();
371                 break;
372         case LFUN_REDO:
373                 disable = buf->redostack.empty();
374                 break;
375         case LFUN_SPELLCHECK:
376                 disable = lyxrc.isp_command == "none";
377                 break;
378         case LFUN_RUNCHKTEX:
379                 disable = lyxrc.chktex_command == "none";
380                 break;
381         case LFUN_BUILDPROG:
382                 disable = !Exporter::IsExportable(buf, "program");
383                 break;
384
385         case LFUN_INSERTFOOTNOTE:
386         case LFUN_FOOTMELT:
387         case LFUN_MARGINMELT:
388                 // Disable insertion of floats in a tabular.
389                 disable = false;
390                 if (owner->view()->theLockingInset()) {
391                         disable = (owner->view()->theLockingInset()->LyxCode() == Inset::TABULAR_CODE) ||
392                                 owner->view()->theLockingInset()->GetFirstLockingInsetOfType(Inset::TABULAR_CODE);
393                 }
394                 break;
395
396         case LFUN_LAYOUT_TABULAR:
397                 disable = true;
398                 if (owner->view()->theLockingInset()) {
399                         disable = (owner->view()->theLockingInset()->LyxCode() != Inset::TABULAR_CODE) &&
400                                 !owner->view()->theLockingInset()->GetFirstLockingInsetOfType(Inset::TABULAR_CODE);
401                 }
402                 break;
403
404         case LFUN_TABULAR_FEATURE:
405                 disable = true;
406                 if (owner->view()->theLockingInset()) {
407                         func_status ret = LyXFunc::Disabled;
408                         if (owner->view()->theLockingInset()->LyxCode() == Inset::TABULAR_CODE) {
409                                 ret = static_cast<InsetTabular *>
410                                         (owner->view()->theLockingInset())->
411                                         getStatus(argument);
412                         } else if (owner->view()->theLockingInset()->GetFirstLockingInsetOfType(Inset::TABULAR_CODE)) {
413                                 ret = static_cast<InsetTabular *>
414                                         (owner->view()->theLockingInset()->
415                                         GetFirstLockingInsetOfType(Inset::TABULAR_CODE))->
416                                         getStatus(argument);
417                         }
418                         flag |= ret;
419                         disable = false;
420                 } else {
421                     static InsetTabular inset(*owner->buffer(), 1, 1);
422                     func_status ret;
423
424                     disable = true;
425                     ret = inset.getStatus(argument);
426                     if ((ret & LyXFunc::ToggleOn) ||
427                         (ret & LyXFunc::ToggleOff))
428                         flag |= LyXFunc::ToggleOff;
429                 }
430                 break;
431
432         case LFUN_VC_REGISTER:
433                 disable = buf->lyxvc.inUse();
434                 break;
435         case LFUN_VC_CHECKIN:
436                 disable = !buf->lyxvc.inUse() || buf->isReadonly();
437                 break;
438         case LFUN_VC_CHECKOUT:
439                 disable = !buf->lyxvc.inUse() || !buf->isReadonly();
440                 break;
441         case LFUN_VC_REVERT:
442         case LFUN_VC_UNDO:
443         case LFUN_VC_HISTORY:
444                 disable = !buf->lyxvc.inUse();
445                 break;
446         case LFUN_BOOKMARK_GOTO:
447                 disable =  !owner->view()->
448                         isSavedPosition(strToUnsignedInt(argument));
449         default:
450                 break;
451         }
452         if (disable)
453                 flag |= LyXFunc::Disabled;
454
455         if (buf) {
456                 func_status box = LyXFunc::ToggleOff;
457                 LyXFont const & font =
458                         TEXT(false)->real_current_font;
459                 switch (action) {
460                 case LFUN_EMPH:
461                         if (font.emph() == LyXFont::ON)
462                                 box = LyXFunc::ToggleOn;
463                         break;
464                 case LFUN_NOUN:
465                         if (font.noun() == LyXFont::ON)
466                                 box = LyXFunc::ToggleOn;
467                         break;
468                 case LFUN_BOLD:
469                         if (font.series() == LyXFont::BOLD_SERIES)
470                                 box = LyXFunc::ToggleOn;
471                         break;
472                 case LFUN_TEX:
473                         if (font.latex() == LyXFont::ON)
474                                 box = LyXFunc::ToggleOn;
475                         break;
476                 default:
477                         box = LyXFunc::OK;
478                         break;
479                 }
480                 flag |= box;
481         }
482
483         return flag;
484 }
485
486
487 string const LyXFunc::Dispatch(string const & s) 
488 {
489         // Split command string into command and argument
490         string cmd;
491         string line = frontStrip(s);
492         string arg = strip(frontStrip(split(line, cmd, ' ')));
493
494         return Dispatch(lyxaction.LookupFunc(cmd), arg);
495 }
496
497
498 string const LyXFunc::Dispatch(int ac,
499                          string const & do_not_use_this_arg)
500 {
501         lyxerr[Debug::ACTION] << "LyXFunc::Dispatch: action[" << ac
502                               <<"] arg[" << do_not_use_this_arg << "]" << endl;
503         
504         string argument;
505         kb_action action;
506         
507         // we have not done anything wrong yet.
508         errorstat = false;
509         dispatch_buffer.erase();
510         
511         // if action is a pseudo-action, we need the real action
512         if (lyxaction.isPseudoAction(ac)) {
513                 string tmparg;
514                 action = static_cast<kb_action>
515                         (lyxaction.retrieveActionArg(ac, tmparg));
516                 if (!tmparg.empty())
517                         argument = tmparg;
518         } else {
519                 action = static_cast<kb_action>(ac);
520                 if (!do_not_use_this_arg.empty())
521                         argument = do_not_use_this_arg; // except here
522         }
523     
524         selection_possible = false;
525         
526         if (owner->view()->available())
527                 owner->view()->hideCursor();
528
529         // We cannot use this function here
530         if (getStatus(ac) & Disabled)
531                 goto exit_with_message;
532
533         commandshortcut.erase();
534         
535         if (lyxrc.display_shortcuts && show_sc) {
536                 if (action != LFUN_SELFINSERT) {
537                         // Put name of command and list of shortcuts
538                         // for it in minibuffer
539                         string comname = lyxaction.getActionName(action);
540
541                         int pseudoaction = action;
542                         bool argsadded = false;
543
544                         if (!argument.empty()) {
545                                 // If we have the command with argument, 
546                                 // this is better
547                                 pseudoaction = 
548                                         lyxaction.searchActionArg(action,
549                                                                   argument);
550
551                                 if (pseudoaction == -1) {
552                                         pseudoaction = action;
553                                 } else {
554                                         comname += " " + argument;
555                                         argsadded = true;
556                                 }
557                         }
558
559                         string const shortcuts =
560                                 toplevel_keymap->findbinding(pseudoaction);
561
562                         if (!shortcuts.empty()) {
563                                 comname += ": " + shortcuts;
564                         } else if (!argsadded) {
565                                 comname += " " + argument;
566                         }
567
568                         if (!comname.empty()) {
569                                 comname = strip(comname);
570                                 commandshortcut = "(" + comname + ')';
571                                 owner->getMiniBuffer()->Set(commandshortcut);
572                                 // Here we could even add a small pause,
573                                 // to annoy the user and make him learn
574                                 // the shortcuts.
575                                 // No! That will just annoy, not teach
576                                 // anything. The user will read the messages
577                                 // if they are interested. (Asger)
578                         }
579                 }
580         }
581
582         if (owner->view()->available() && owner->view()->theLockingInset()) {
583                 UpdatableInset::RESULT result;
584                 if ((action > 1) || ((action == LFUN_UNKNOWN_ACTION) &&
585                                      (keyseq.length >= -1)))
586                 {
587                         if ((action==LFUN_UNKNOWN_ACTION) && argument.empty()){
588                                 argument = keyseq.getiso();
589                         }
590                         // Undo/Redo pre 0.13 is a bit tricky for insets.
591                         if (action == LFUN_UNDO) {
592                                 int slx;
593                                 int sly;
594                                 UpdatableInset * inset = 
595                                         owner->view()->theLockingInset();
596                                 inset->GetCursorPos(owner->view(), slx, sly);
597                                 owner->view()->unlockInset(inset);
598                                 owner->view()->menuUndo();
599                                 if (TEXT()->cursor.par()->
600                                     IsInset(TEXT()->cursor.pos())) {
601                                         inset = static_cast<UpdatableInset*>(
602                                                 TEXT()->cursor.par()->
603                                                 GetInset(TEXT()->
604                                                          cursor.pos()));
605                                 } else {
606                                         inset = 0;
607                                 }
608                                 if (inset)
609                                         inset->Edit(owner->view(),slx,sly,0);
610                                 return string();
611                         } else if (action == LFUN_REDO) {
612                                 int slx;
613                                 int sly;
614                                 UpdatableInset * inset = owner->view()->
615                                         theLockingInset();
616                                 inset->GetCursorPos(owner->view(), slx, sly);
617                                 owner->view()->unlockInset(inset);
618                                 owner->view()->menuRedo();
619                                 inset = static_cast<UpdatableInset*>(
620                                         TEXT()->cursor.par()->
621                                         GetInset(TEXT()->
622                                                  cursor.pos()));
623                                 if (inset)
624                                         inset->Edit(owner->view(),slx,sly,0); 
625                                 return string();
626                         } else if (((result=owner->view()->theLockingInset()->
627                                    LocalDispatch(owner->view(), action,
628                                                  argument)) ==
629                                    UpdatableInset::DISPATCHED) ||
630                                    (result == UpdatableInset::DISPATCHED_NOUPDATE))
631                                 return string();
632                         else {
633                                 //setMessage(N_("Text mode"));
634                                 switch (action) {
635                                 case LFUN_UNKNOWN_ACTION:
636                                 case LFUN_BREAKPARAGRAPH:
637                                 case LFUN_BREAKLINE:
638                                         TEXT()->CursorRight(owner->view());
639                                         owner->view()->setState();
640                                         owner->showState();
641                                         break;
642                                 case LFUN_RIGHT:
643                                         if (!TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params)) {
644                                                 TEXT()->CursorRight(owner->view());
645                                                 moveCursorUpdate(true, false);
646                                                 owner->showState();
647                                         }
648                                         return string();
649                                 case LFUN_LEFT: 
650                                         if (TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params)) {
651                                                 TEXT()->CursorRight(owner->view());
652                                                 moveCursorUpdate(true, false);
653                                                 owner->showState();
654                                         }
655                                         return string();
656                                 case LFUN_DOWN:
657                                         TEXT()->CursorDown(owner->view());
658                                         moveCursorUpdate(true, false);
659                                         owner->showState();
660                                         return string();
661                                 default:
662                                         break;
663                                 }
664                         }
665                 }
666         }
667
668         switch (action) {
669                 // --- Misc -------------------------------------------
670         case LFUN_WORDFINDFORWARD  : 
671         case LFUN_WORDFINDBACKWARD : {
672                 static string last_search;
673                 string searched_string;
674             
675                 if (!argument.empty()) {
676                         last_search = argument;
677                         searched_string = argument;
678                 } else {
679                         searched_string = last_search;
680                 }
681
682                 if (!searched_string.empty() &&
683                     ((action == LFUN_WORDFINDBACKWARD) ? 
684                      TEXT()->SearchBackward(owner->view(), searched_string) :
685                      TEXT()->SearchForward(owner->view(), searched_string))) {
686
687                         // ??? What is that ???
688                         owner->view()->update(TEXT(), BufferView::SELECT|BufferView::FITCUR);
689
690                         // ??? Needed ???
691                         // clear the selection (if there is any) 
692                         owner->view()->toggleSelection();
693                         TEXT()->ClearSelection(owner->view());
694
695                         // Move cursor so that successive C-s 's will not stand in place. 
696                         if (action == LFUN_WORDFINDFORWARD ) 
697                                 TEXT()->CursorRightOneWord(owner->view());
698                         TEXT()->FinishUndo();
699                         moveCursorUpdate(true, false);
700
701                         // ??? Needed ???
702                         // set the new selection 
703                         // SetSelectionOverLenChars(owner->view()->currentBuffer()->text, iLenSelected);
704                         owner->view()->toggleSelection(false);
705                 }
706          
707                 // REMOVED : if (owner->view()->getWorkArea()->focus)
708                 owner->view()->showCursor();
709         }
710         break;
711
712         case LFUN_PREFIX:
713         {
714                 if (owner->view()->available()) {
715                         owner->view()->update(TEXT(),
716                                               BufferView::SELECT|BufferView::FITCUR);
717                 }
718                 string buf;
719                 keyseq.print(buf, true);
720                 owner->getMiniBuffer()->Set(buf, string(), string(), 1);
721         }
722         break;
723
724         // --- Misc -------------------------------------------
725         case LFUN_EXEC_COMMAND:
726                 owner->getMiniBuffer()->PrepareForCommand(); 
727                 break;
728                 
729         case LFUN_CANCEL:                   // RVDK_PATCH_5
730                 keyseq.reset();
731                 meta_fake_bit = 0;
732                 if (owner->view()->available())
733                         // cancel any selection
734                         Dispatch(LFUN_MARK_OFF);
735                 setMessage(N_("Cancel"));
736                 break;
737
738         case LFUN_META_FAKE:                                 // RVDK_PATCH_5
739         {
740                 meta_fake_bit = Mod1Mask;
741                 string buf;
742                 keyseq.print(buf, true);
743                 setMessage(buf); // RVDK_PATCH_5
744         }
745         break;  
746
747         case LFUN_READ_ONLY_TOGGLE:
748                 if (owner->buffer()->lyxvc.inUse()) {
749                         owner->buffer()->lyxvc.toggleReadOnly();
750                 } else {
751                         owner->buffer()->setReadonly(
752                                 !owner->buffer()->isReadonly());
753                 }
754                 break;
755                 
756         case LFUN_CENTER: // this is center and redraw.
757                 owner->view()->center();
758                 break;
759                 
760         case LFUN_APPENDIX:
761                 if (owner->view()->available()) {
762                         TEXT(false)->toggleAppendix(owner->view());
763                         owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
764                 }
765                 break;
766
767                 // --- Menus -----------------------------------------------
768         case LFUN_MENUNEW:
769                 MenuNew(false);
770                 break;
771                 
772         case LFUN_MENUNEWTMPLT:
773                 MenuNew(true);
774                 break;
775                 
776         case LFUN_MENUOPEN:
777                 MenuOpen();
778                 break;
779                 
780         case LFUN_CLOSEBUFFER:
781                 CloseBuffer();
782                 break;
783                 
784         case LFUN_MENUWRITE:
785                 if (!owner->buffer()->isUnnamed()) {
786                         owner->getMiniBuffer()->Set(_("Saving document"),
787                                                     MakeDisplayPath(owner->buffer()->fileName()),
788                                                     "...");
789                         MenuWrite(owner->view(), owner->buffer());
790                         //owner->getMiniBuffer()-> {
791                         //      Set(_("Document saved as"),
792                         //          MakeDisplayPath(owner->buffer()->fileName()));
793                         //} else {
794                         //owner->getMiniBuffer()->Set(_("Save failed!"));
795                         //}
796                 } else {
797                         MenuWriteAs(owner->view(), owner->buffer());
798                 }
799                 break;
800                 
801         case LFUN_MENUWRITEAS:
802                 MenuWriteAs(owner->view(), owner->buffer());
803                 break;
804                 
805         case LFUN_MENURELOAD:
806                 reloadBuffer();
807                 break;
808                 
809         case LFUN_UPDATE:
810                 Exporter::Export(owner->buffer(), argument, true);
811                 break;
812
813         case LFUN_PREVIEW:
814                 Exporter::Preview(owner->buffer(), argument);
815                 break;
816                 
817         case LFUN_BUILDPROG:
818                 Exporter::Export(owner->buffer(), "program", true);
819                 break;
820                 
821         case LFUN_RUNCHKTEX:
822                 MenuRunChktex(owner->buffer());
823                 break;
824                                 
825         case LFUN_MENUPRINT:
826                 owner->getDialogs()->showPrint();
827                 break;
828
829         case LFUN_EXPORT:
830                 Exporter::Export(owner->buffer(), argument, false);
831                 break;
832
833         case LFUN_IMPORT:
834                 doImport(argument);
835                 break;
836                 
837         case LFUN_QUIT:
838                 QuitLyX();
839                 break;
840                 
841         case LFUN_TOCVIEW:
842         case LFUN_LOFVIEW:
843         case LFUN_LOTVIEW:
844         case LFUN_LOAVIEW:
845         {
846                 InsetCommandParams p;
847                 
848                 if (action == LFUN_TOCVIEW )
849                         p.setCmdName( "tableofcontents" );
850                 else if (action == LFUN_LOAVIEW )
851                         p.setCmdName( "listofalgorithms" );
852                 else if (action == LFUN_LOFVIEW )
853                         p.setCmdName( "listoffigures" );
854                 else
855                         p.setCmdName( "listoftables" );
856
857                 owner->getDialogs()->createTOC( p.getAsString() );
858                 break;
859         }       
860
861         case LFUN_TOC_INSERT:
862         case LFUN_LOA_INSERT:
863         case LFUN_LOF_INSERT:
864         case LFUN_LOT_INSERT:
865         {
866                 InsetCommandParams p;
867                 
868                 if (action == LFUN_TOC_INSERT )
869                         p.setCmdName( "tableofcontents" );
870                 else if (action == LFUN_LOA_INSERT )
871                         p.setCmdName( "listofalgorithms" );
872                 else if (action == LFUN_LOF_INSERT )
873                         p.setCmdName( "listoffigures" );
874                 else
875                         p.setCmdName( "listoftables" );
876
877                 Inset * inset = new InsetTOC( p );
878                 if (!owner->view()->insertInset( inset, "Standard", true ) )
879                         delete inset;
880                 break;
881         }
882                 
883         case LFUN_DIALOG_TABULAR_INSERT:
884                 owner->getDialogs()->showTabularCreate();
885                 break;
886                 
887         case LFUN_TABULAR_FEATURE:
888         case LFUN_SCROLL_INSET:
889                 // this is not handled here as this funktion is only aktive
890                 // if we have a locking_inset and that one is (or contains)
891                 // a tabular-inset
892                 break;
893
894         case LFUN_FIGURE:
895                 Figure();
896                 break;
897
898         case LFUN_INSET_GRAPHICS:
899         {
900                 Inset * new_inset = new InsetGraphics;
901                 if (!owner->view()->insertInset(new_inset)) {
902                         delete new_inset;
903                 } else {
904                         // this is need because you don't use a inset->Edit()
905                         owner->view()->updateInset(new_inset, true);
906                         new_inset->Edit(owner->view(), 0, 0, 0);
907                 }
908                 break;
909         }
910         
911         case LFUN_AUTOSAVE:
912                 AutoSave(owner->view());
913                 break;
914                 
915         case LFUN_UNDO:
916                 owner->view()->menuUndo();
917                 break;
918                 
919         case LFUN_REDO:
920                 owner->view()->menuRedo();
921                 break;
922                 
923         case LFUN_MENUSEARCH:
924         {
925                 // Ok this is one _very_ bad solution, but I think that some
926                 // of this will be rewritten as part of GUI indep anyway.
927                 // Lgb
928                 static LyXFindReplace FR_;
929                 FR_.StartSearch(owner->view());
930         }
931         break;
932                 
933         case LFUN_PASTE:
934                 owner->view()->paste();
935                 owner->view()->setState();
936                 break;
937                 
938         case LFUN_PASTESELECTION:
939         {
940                 bool asPara = false;
941                 if (argument == "paragraph") asPara = true;
942                 owner->view()->pasteClipboard(asPara);
943         }
944         break;
945         
946         case LFUN_CUT:
947                 owner->view()->cut();
948                 break;
949                 
950         case LFUN_COPY:
951                 owner->view()->copy();
952                 break;
953                 
954         case LFUN_LAYOUT_COPY:
955                 owner->view()->copyEnvironment();
956                 break;
957                 
958         case LFUN_LAYOUT_PASTE:
959                 owner->view()->pasteEnvironment();
960                 owner->view()->setState();
961                 break;
962                 
963         case LFUN_GOTOERROR:
964                 owner->view()->gotoInset(Inset::ERROR_CODE, false);
965                 break;
966                 
967         case LFUN_REMOVEERRORS:
968                 if (owner->view()->removeAutoInsets()) {
969                         owner->view()->redraw();
970                         owner->view()->fitCursor(TEXT());
971                 }
972                 break;
973                 
974         case LFUN_GOTONOTE:
975                 owner->view()->gotoInset(Inset::IGNORE_CODE, false);
976                 break;
977
978         case LFUN_REFERENCE_GOTO:
979         {
980                 vector<Inset::Code> tmp;
981                 tmp.push_back(Inset::LABEL_CODE);
982                 tmp.push_back(Inset::REF_CODE);
983                 owner->view()->gotoInset(tmp, true);
984                 break;
985         }
986
987 #ifndef NEW_INSETS
988         case LFUN_OPENSTUFF:
989                 owner->view()->openStuff();
990                 break;
991 #endif
992                 
993         case LFUN_HYPHENATION:
994                 owner->view()->hyphenationPoint();
995                 break;
996                 
997         case LFUN_LDOTS:
998                 owner->view()->ldots();
999                 break;
1000                 
1001         case LFUN_END_OF_SENTENCE:
1002                 owner->view()->endOfSentenceDot();
1003                 break;
1004
1005         case LFUN_MENU_SEPARATOR:
1006                 owner->view()->menuSeparator();
1007                 break;
1008                 
1009         case LFUN_HFILL:
1010                 owner->view()->hfill();
1011                 break;
1012                 
1013         case LFUN_DEPTH:
1014                 changeDepth(owner->view(), TEXT(false), 0);
1015                 break;
1016                 
1017         case LFUN_DEPTH_MIN:
1018                 changeDepth(owner->view(), TEXT(false), -1);
1019                 break;
1020                 
1021         case LFUN_DEPTH_PLUS:
1022                 changeDepth(owner->view(), TEXT(false), 1);
1023                 break;
1024                 
1025         case LFUN_FREE:
1026                 Free(owner->view());
1027                 owner->view()->setState();
1028                 owner->showState();
1029                 break;
1030                 
1031         case LFUN_TEX:
1032                 Tex(owner->view());
1033                 owner->view()->setState();
1034                 owner->showState();
1035                 break;
1036 #ifndef NEW_INSETS              
1037         case LFUN_MELT:
1038                 Melt(owner->view());
1039                 break;
1040 #endif
1041         case LFUN_RECONFIGURE:
1042                 Reconfigure(owner->view());
1043                 break;
1044 #ifndef NEW_INSETS
1045         case LFUN_FOOTMELT:
1046                 if (owner->view()->available()
1047                     && !TEXT()->selection
1048                     && TEXT()->cursor.par()->footnoteflag
1049                     != LyXParagraph::NO_FOOTNOTE)
1050                         { // only melt footnotes with FOOTMELT, not margins etc
1051                                 if (TEXT()->cursor.par()->footnotekind == LyXParagraph::FOOTNOTE)
1052                                         Melt(owner->view());
1053                         }
1054                 else
1055                         Foot(owner->view()); 
1056                 owner->view()->setState();
1057                 break;
1058
1059         case LFUN_MARGINMELT:
1060                 if (owner->view()->available()
1061                     && !TEXT()->selection
1062                     && TEXT()->cursor.par()->footnoteflag
1063                     != LyXParagraph::NO_FOOTNOTE) {
1064                         // only melt margins
1065                         if (TEXT()->cursor.par()->footnotekind == LyXParagraph::MARGIN)
1066                                 Melt(owner->view());
1067                 } else
1068                         Margin(owner->view()); 
1069                 owner->view()->setState();
1070                 break;
1071 #endif
1072 #ifndef NEW_INSETS
1073         case LFUN_FLOATSOPERATE:
1074                 if (argument == "openfoot")
1075                         owner->view()->allFloats(1,0);
1076                 else if (argument == "closefoot")
1077                         owner->view()->allFloats(0,0);
1078                 else if (argument == "openfig")
1079                         owner->view()->allFloats(1,1);
1080                 else if (argument == "closefig")
1081                         owner->view()->allFloats(0,1);
1082                 break;
1083 #else
1084 #warning Find another implementation here (or another lyxfunc)!
1085 #endif
1086         case LFUN_HELP_COPYRIGHT:
1087                 owner->getDialogs()->showCopyright();
1088                 break;
1089
1090         case LFUN_HELP_CREDITS:
1091                 owner->getDialogs()->showCredits();
1092                 break;
1093
1094         case LFUN_HELP_OPEN: {
1095                 string arg = argument;
1096                 if (arg.empty()) {
1097                         setErrorMessage(N_("Missing argument"));
1098                         break;
1099                 }
1100                 ProhibitInput(owner->view());
1101                 string fname = i18nLibFileSearch("doc", arg, "lyx");
1102                 if (fname.empty()) {
1103                         lyxerr << "LyX: unable to find documentation file `"
1104                                << arg << "'. Bad installation?" << endl;
1105                         AllowInput(owner->view());
1106                         break;
1107                 }
1108                 owner->getMiniBuffer()->Set(_("Opening help file"),
1109                                             MakeDisplayPath(fname),"...");
1110                 owner->view()->buffer(bufferlist.loadLyXFile(fname,false));
1111                 AllowInput(owner->view());
1112                 break;
1113         }
1114
1115         case LFUN_HELP_VERSION: {
1116                 ProhibitInput(owner->view());
1117                 string msg(_("LyX Version "));
1118                 msg += LYX_VERSION;
1119                 msg += " of ";
1120                 msg += LYX_RELEASE;
1121                 fl_show_message(msg.c_str(),
1122                                 (_("Library directory: ")
1123                                  + MakeDisplayPath(system_lyxdir)).c_str(),
1124                                 (_("User directory: ") 
1125                                  + MakeDisplayPath(user_lyxdir)).c_str());
1126                 AllowInput(owner->view());
1127                 break;
1128         }
1129         
1130                 // --- version control -------------------------------
1131         case LFUN_VC_REGISTER:
1132         {
1133                 if (!owner->buffer()->lyxvc.inUse())
1134                         owner->buffer()->lyxvc.registrer();
1135         }
1136         break;
1137                 
1138         case LFUN_VC_CHECKIN:
1139         {
1140                 if (owner->buffer()->lyxvc.inUse()
1141                     && !owner->buffer()->isReadonly())
1142                         owner->buffer()->lyxvc.checkIn();
1143         }
1144         break;
1145                 
1146         case LFUN_VC_CHECKOUT:
1147         {
1148                 if (owner->buffer()->lyxvc.inUse()
1149                     && owner->buffer()->isReadonly())
1150                         owner->buffer()->lyxvc.checkOut();
1151         }
1152         break;
1153         
1154         case LFUN_VC_REVERT:
1155         {
1156                 owner->buffer()->lyxvc.revert();
1157         }
1158         break;
1159                 
1160         case LFUN_VC_UNDO:
1161         {
1162                 owner->buffer()->lyxvc.undoLast();
1163         }
1164         break;
1165                 
1166         case LFUN_VC_HISTORY:
1167         {
1168                 owner->getDialogs()->showVCLogFile();
1169                 break;
1170         }
1171         
1172         // --- buffers ----------------------------------------
1173
1174         case LFUN_SWITCHBUFFER:
1175                 owner->view()->buffer(bufferlist.getBuffer(argument));
1176                 break;
1177
1178
1179         case LFUN_FILE_INSERT:
1180         {
1181                 MenuInsertLyXFile(argument);
1182         }
1183         break;
1184         
1185         case LFUN_FILE_INSERT_ASCII:
1186         {
1187                 bool asPara = (argument == "paragraph");
1188                 InsertAsciiFile(owner->view(), string(), asPara);
1189         }
1190         break;
1191         
1192         case LFUN_FILE_NEW:
1193         {
1194                 // servercmd: argument must be <file>:<template>
1195                 Buffer * tmpbuf = NewLyxFile(argument);
1196                 if (tmpbuf)
1197                         owner->view()->buffer(tmpbuf);
1198         }
1199         break;
1200                         
1201         case LFUN_FILE_OPEN:
1202                 owner->view()->buffer(bufferlist.loadLyXFile(argument));
1203                 break;
1204
1205         case LFUN_LATEX_LOG:
1206                 owner->getDialogs()->showLogFile();
1207                 break;
1208                 
1209         case LFUN_LAYOUTNO:
1210         {
1211                 lyxerr.debug() << "LFUN_LAYOUTNO: (arg) " << argument << endl;
1212                 int sel = strToInt(argument);
1213                 lyxerr.debug() << "LFUN_LAYOUTNO: (sel) "<< sel << endl;
1214                 
1215                 // Should this give a setMessage instead?
1216                 if (sel == 0) 
1217                         return string(); // illegal argument
1218
1219                 --sel; // sel 1..., but layout 0...
1220
1221                 // Pretend we got the name instead.
1222                 Dispatch(int(LFUN_LAYOUT), 
1223                          textclasslist.NameOfLayout(owner->view()
1224                                                     ->buffer()->params.textclass,
1225                                                     sel));
1226                 return string();
1227         }
1228                 
1229         case LFUN_LAYOUT:
1230         {
1231                 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1232                                << argument << endl;
1233                 
1234                 // Derive layout number from given argument (string)
1235                 // and current buffer's textclass (number). */    
1236                 LyXTextClassList::ClassList::size_type tclass =
1237                         owner->view()->buffer()->params.textclass;
1238                 pair <bool, LyXTextClass::size_type> layout = 
1239                         textclasslist.NumberOfLayout(tclass, argument);
1240
1241                 // If the entry is obsolete, use the new one instead.
1242                 if (layout.first) {
1243                         string obs = textclasslist.Style(tclass,layout.second)
1244                               .obsoleted_by();
1245                         if (!obs.empty()) 
1246                                 layout = 
1247                                   textclasslist.NumberOfLayout(tclass, obs);
1248                 }
1249
1250                 // see if we found the layout number:
1251                 if (!layout.first) {
1252                         setErrorMessage(string(N_("Layout ")) + argument + 
1253                                         N_(" not known"));
1254                         break;
1255                 }
1256
1257                 if (current_layout != layout.second) {
1258                         owner->view()->hideCursor();
1259                         current_layout = layout.second;
1260                         owner->view()->update(TEXT(),
1261                                               BufferView::SELECT|BufferView::FITCUR);
1262                         TEXT()->
1263                                 SetLayout(owner->view(), layout.second);
1264                         owner->setLayout(layout.second);
1265                         owner->view()->update(TEXT(),
1266                                               BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1267                         owner->view()->setState();
1268                 }
1269         }
1270         break;
1271
1272         case LFUN_LAYOUT_DOCUMENT:
1273                 owner->getDialogs()->showLayoutDocument();
1274                 break;
1275                 
1276         case LFUN_LAYOUT_PARAGRAPH:
1277 #ifdef USE_OLD_PARAGRAPH_LAYOUT
1278                 MenuLayoutParagraph();
1279 #else
1280                 owner->getDialogs()->showLayoutParagraph();
1281 #endif
1282                 break;
1283                 
1284         case LFUN_LAYOUT_CHARACTER:
1285                 MenuLayoutCharacter();
1286                 break;
1287
1288         case LFUN_LAYOUT_TABULAR:
1289             if (owner->view()->theLockingInset()) {
1290                 if (owner->view()->theLockingInset()->LyxCode()==Inset::TABULAR_CODE) {
1291                     InsetTabular * inset = static_cast<InsetTabular *>
1292                         (owner->view()->theLockingInset());
1293                     inset->OpenLayoutDialog(owner->view());
1294                 } else if (owner->view()->theLockingInset()->
1295                            GetFirstLockingInsetOfType(Inset::TABULAR_CODE)!=0) {
1296                     InsetTabular * inset = static_cast<InsetTabular *>(
1297                         owner->view()->theLockingInset()->GetFirstLockingInsetOfType(Inset::TABULAR_CODE));
1298                     inset->OpenLayoutDialog(owner->view());
1299                 }
1300             }
1301             break;
1302
1303         case LFUN_LAYOUT_PREAMBLE:
1304                 owner->getDialogs()->showPreamble();
1305                 break;
1306                 
1307         case LFUN_LAYOUT_SAVE_DEFAULT:
1308                 MenuLayoutSave(owner->view());
1309                 break;
1310                 
1311         case LFUN_DROP_LAYOUTS_CHOICE:
1312                 owner->getToolbar()->openLayoutList();
1313                 break;
1314
1315         case LFUN_LANGUAGE:
1316                 Lang(owner->view(), argument);
1317                 owner->view()->setState();
1318                 owner->showState();
1319                 break;
1320
1321         case LFUN_EMPH:
1322                 Emph(owner->view());
1323                 owner->showState();
1324                 break;
1325
1326         case LFUN_BOLD:
1327                 Bold(owner->view());
1328                 owner->showState();
1329                 break;
1330                 
1331         case LFUN_NOUN:
1332                 Noun(owner->view());
1333                 owner->showState();
1334                 break;
1335                 
1336         case LFUN_CODE:
1337                 Code(owner->view());
1338                 owner->showState();
1339                 break;
1340                 
1341         case LFUN_SANS:
1342                 Sans(owner->view());
1343                 owner->showState();
1344                 break;
1345                 
1346         case LFUN_ROMAN:
1347                 Roman(owner->view());
1348                 owner->showState();
1349                 break;
1350                 
1351         case LFUN_DEFAULT:
1352                 StyleReset(owner->view());
1353                 owner->showState();
1354                 break;
1355                 
1356         case LFUN_UNDERLINE:
1357                 Underline(owner->view());
1358                 owner->showState();
1359                 break;
1360                 
1361         case LFUN_FONT_SIZE:
1362                 FontSize(owner->view(), argument);
1363                 owner->showState();
1364                 break;
1365                 
1366         case LFUN_FONT_STATE:
1367                 setMessage(CurrentState(owner->view()));
1368                 break;
1369                 
1370         case LFUN_UPCASE_WORD:
1371                 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR);
1372                 TEXT(false)->ChangeWordCase(owner->view(), LyXText::text_uppercase);
1373                 if (TEXT(false)->inset_owner)
1374                     owner->view()->updateInset(TEXT(false)->inset_owner, true);
1375                 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1376                 break;
1377                 
1378         case LFUN_LOWCASE_WORD:
1379                 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR);
1380                 TEXT(false)->ChangeWordCase(owner->view(), LyXText::text_lowercase);
1381                 if (TEXT(false)->inset_owner)
1382                     owner->view()->updateInset(TEXT(false)->inset_owner, true);
1383                 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1384                 break;
1385                 
1386         case LFUN_CAPITALIZE_WORD:
1387                 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR);
1388                 TEXT(false)->ChangeWordCase(owner->view(),
1389                                      LyXText::text_capitalization);
1390                 if (TEXT(false)->inset_owner)
1391                     owner->view()->updateInset(TEXT(false)->inset_owner, true);
1392                 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1393                 break;
1394                 
1395         case LFUN_INSERT_LABEL:
1396                 MenuInsertLabel(owner->view(), argument);
1397                 break;
1398                 
1399         case LFUN_REF_INSERT:
1400                 if (argument.empty()) {
1401                         InsetCommandParams p("ref");
1402                 owner->getDialogs()->createRef(p.getAsString());
1403                 } else {
1404                         InsetCommandParams p;
1405                         p.setFromString(argument);
1406
1407                         InsetRef * inset = new InsetRef(p, *owner->buffer());
1408                         if (!owner->view()->insertInset(inset))
1409                                 delete inset;
1410                         else
1411                                 owner->view()->updateInset(inset, true);
1412                 }
1413                 break;
1414
1415         case LFUN_BOOKMARK_SAVE:
1416                 owner->view()->savePosition(strToUnsignedInt(argument));
1417                 break;
1418
1419         case LFUN_BOOKMARK_GOTO:
1420                 owner->view()->restorePosition(strToUnsignedInt(argument));
1421                 break;
1422
1423         case LFUN_REF_GOTO:
1424         {
1425                 string label(argument);
1426                 if (label.empty()) {
1427                         InsetRef * inset = 
1428                                 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1429                         if (inset) {
1430                                 label = inset->getContents();
1431                                 owner->view()->savePosition(0);
1432                         }
1433                 }
1434                 
1435                 if (!label.empty()) {
1436                         //owner->view()->savePosition(0);
1437                         if (!owner->view()->gotoLabel(label))
1438                                 WriteAlert(_("Error"), 
1439                                            _("Couldn't find this label"), 
1440                                            _("in current document."));
1441                 }
1442         }
1443         break;
1444                 
1445         case LFUN_MENU_OPEN_BY_NAME:
1446                 owner->getMenubar()->openByName(argument);
1447                 break; // RVDK_PATCH_5
1448                 
1449         case LFUN_SPELLCHECK:
1450                 if (lyxrc.isp_command != "none")
1451                         ShowSpellChecker(owner->view());
1452                 break; // RVDK_PATCH_5
1453                 
1454                 // --- Cursor Movements -----------------------------
1455         case LFUN_RIGHT:
1456         {
1457                 bool is_rtl = TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params);
1458                 if (!TEXT()->mark_set)
1459                         owner->view()->beforeChange(TEXT());
1460                 owner->view()->update(TEXT(), BufferView::SELECT|BufferView::FITCUR);
1461                 if (is_rtl)
1462                         TEXT()->CursorLeft(owner->view(), false);
1463                 if (TEXT()->cursor.pos() < TEXT()->cursor.par()->Last()
1464                     && TEXT()->cursor.par()->GetChar(TEXT()->cursor.pos())
1465                     == LyXParagraph::META_INSET
1466                     && TEXT()->cursor.par()->GetInset(TEXT()->cursor.pos())
1467                     && TEXT()->cursor.par()->GetInset(TEXT()->cursor.pos())->Editable() == Inset::HIGHLY_EDITABLE){
1468                         Inset * tmpinset = TEXT()->cursor.par()->GetInset(TEXT()->cursor.pos());
1469                         setMessage(tmpinset->EditMessage());
1470                         int y = 0;
1471                         if (is_rtl) {
1472                                 LyXFont font = 
1473                                         TEXT()->GetFont(owner->view()->buffer(),
1474                                                          TEXT()->cursor.par(),
1475                                                          TEXT()->cursor.pos()); 
1476                                 y = tmpinset->descent(owner->view(),font);
1477                         }
1478                         tmpinset->Edit(owner->view(), 0, y, 0);
1479                         break;
1480                 }
1481                 if (!is_rtl)
1482                         TEXT()->CursorRight(owner->view(), false);
1483                 TEXT()->FinishUndo();
1484                 moveCursorUpdate(true, false);
1485                 owner->showState();
1486         }
1487         break;
1488                 
1489         case LFUN_LEFT:
1490         {
1491                 // This is soooo ugly. Isn`t it possible to make
1492                 // it simpler? (Lgb)
1493                 bool is_rtl = TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params);
1494                 if (!TEXT()->mark_set)
1495                         owner->view()->beforeChange(TEXT());
1496                 owner->view()->update(TEXT(), BufferView::SELECT|BufferView::FITCUR);
1497                 LyXCursor cur = TEXT()->cursor;
1498                 if (!is_rtl)
1499                         TEXT()->CursorLeft(owner->view(), false);
1500                 if ((is_rtl || cur != TEXT()->cursor) && // only if really moved!
1501                     TEXT()->cursor.pos() < TEXT()->cursor.par()->Last() &&
1502                     (TEXT()->cursor.par()->GetChar(TEXT()->cursor.pos()) ==
1503                      LyXParagraph::META_INSET) &&
1504                     TEXT()->cursor.par()->GetInset(TEXT()->cursor.pos()) &&
1505                     (TEXT()->cursor.par()->GetInset(TEXT()->cursor.pos())->Editable()
1506                      == Inset::HIGHLY_EDITABLE))
1507                 {
1508                         Inset * tmpinset = TEXT()->cursor.par()->GetInset(TEXT()->cursor.pos());
1509                         setMessage(tmpinset->EditMessage());
1510                         LyXFont font = TEXT()->GetFont(owner->view()->buffer(),
1511                                                     TEXT()->cursor.par(),
1512                                                     TEXT()->cursor.pos());
1513                         int y = is_rtl ? 0 
1514                                 : tmpinset->descent(owner->view(),font);
1515                         tmpinset->Edit(owner->view(),
1516                                        tmpinset->x() +
1517                                        tmpinset->width(owner->view(),font),
1518                                        y, 0);
1519                         break;
1520                 }
1521                 if  (is_rtl)
1522                         TEXT()->CursorRight(owner->view(), false);
1523
1524                 TEXT()->FinishUndo();
1525                 moveCursorUpdate(true, false);
1526                 owner->showState();
1527         }
1528         break;
1529                 
1530         case LFUN_UP:
1531                 if (!TEXT()->mark_set)
1532                         owner->view()->beforeChange(TEXT());
1533                 owner->view()->update(TEXT(), BufferView::UPDATE);
1534                 TEXT()->CursorUp(owner->view());
1535                 TEXT()->FinishUndo();
1536                 moveCursorUpdate(true, false);
1537                 owner->showState();
1538                 break;
1539                 
1540         case LFUN_DOWN:
1541                 if (!TEXT()->mark_set)
1542                         owner->view()->beforeChange(TEXT());
1543                 owner->view()->update(TEXT(), BufferView::UPDATE);
1544                 TEXT()->CursorDown(owner->view());
1545                 TEXT()->FinishUndo();
1546                 moveCursorUpdate(true, false);
1547                 owner->showState();
1548                 break;
1549
1550         case LFUN_UP_PARAGRAPH:
1551                 if (!TEXT()->mark_set)
1552                         owner->view()->beforeChange(TEXT());
1553                 owner->view()->update(TEXT(), BufferView::UPDATE);
1554                 TEXT()->CursorUpParagraph(owner->view());
1555                 TEXT()->FinishUndo();
1556                 moveCursorUpdate(true, false);
1557                 owner->showState();
1558                 break;
1559                 
1560         case LFUN_DOWN_PARAGRAPH:
1561                 if (!TEXT()->mark_set)
1562                         owner->view()->beforeChange(TEXT());
1563                 owner->view()->update(TEXT(), BufferView::UPDATE);
1564                 TEXT()->CursorDownParagraph(owner->view());
1565                 TEXT()->FinishUndo();
1566                 moveCursorUpdate(true, false);
1567                 owner->showState();
1568                 break;
1569                 
1570         case LFUN_PRIOR:
1571                 if (!TEXT(false)->mark_set)
1572                     owner->view()->beforeChange(TEXT());
1573                 owner->view()->update(TEXT(), BufferView::UPDATE);
1574                 owner->view()->cursorPrevious(TEXT(false));
1575                 TEXT()->FinishUndo();
1576                 moveCursorUpdate(false, false);
1577                 owner->showState();
1578                 break;
1579                 
1580         case LFUN_NEXT:
1581                 if (!TEXT(false)->mark_set)
1582                         owner->view()->beforeChange(TEXT());
1583                 owner->view()->update(TEXT(), BufferView::UPDATE);
1584                 owner->view()->cursorNext(TEXT(false));
1585                 TEXT()->FinishUndo();
1586                 moveCursorUpdate(false, false);
1587                 owner->showState();
1588                 break;
1589                 
1590         case LFUN_HOME:
1591                 if (!TEXT()->mark_set)
1592                         owner->view()->beforeChange(TEXT());
1593                 owner->view()->update(TEXT(), BufferView::SELECT|BufferView::FITCUR);
1594                 TEXT()->CursorHome(owner->view());
1595                 TEXT()->FinishUndo();
1596                 moveCursorUpdate(true, false);
1597                 owner->showState();
1598                 break;
1599                 
1600         case LFUN_END:
1601                 if (!TEXT()->mark_set)
1602                         owner->view()->beforeChange(TEXT());
1603                 owner->view()->update(TEXT(),
1604                                       BufferView::SELECT|BufferView::FITCUR);
1605                 TEXT()->CursorEnd(owner->view());
1606                 TEXT()->FinishUndo();
1607                 moveCursorUpdate(true, false);
1608                 owner->showState();
1609                 break;
1610                 
1611         case LFUN_SHIFT_TAB:
1612         case LFUN_TAB:
1613                 if (!TEXT()->mark_set)
1614                         owner->view()->beforeChange(TEXT());
1615                 owner->view()->update(TEXT(),
1616                                       BufferView::SELECT|BufferView::FITCUR);
1617                 TEXT()->CursorTab(owner->view());
1618                 TEXT()->FinishUndo();
1619                 moveCursorUpdate(true, false);
1620                 owner->showState();
1621                 break;
1622                 
1623         case LFUN_WORDRIGHT:
1624                 if (!TEXT(false)->mark_set)
1625                         owner->view()->beforeChange(TEXT(false));
1626                 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR);
1627                 if (TEXT(false)->cursor.par()->isRightToLeftPar(owner->buffer()->params))
1628                         TEXT(false)->CursorLeftOneWord(owner->view());
1629                 else
1630                         TEXT(false)->CursorRightOneWord(owner->view());
1631                 TEXT()->FinishUndo();
1632                 moveCursorUpdate(false, false);
1633                 owner->showState();
1634                 break;
1635                 
1636         case LFUN_WORDLEFT:
1637                 if (!TEXT(false)->mark_set)
1638                         owner->view()->beforeChange(TEXT(false));
1639                 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR);
1640                 if (TEXT(false)->cursor.par()->isRightToLeftPar(owner->buffer()->params))
1641                         TEXT(false)->CursorRightOneWord(owner->view());
1642                 else
1643                         TEXT(false)->CursorLeftOneWord(owner->view());
1644                 TEXT()->FinishUndo();
1645                 moveCursorUpdate(false, false);
1646                 owner->showState();
1647                 break;
1648                 
1649         case LFUN_BEGINNINGBUF:
1650                 if (!TEXT()->mark_set)
1651                         owner->view()->beforeChange(TEXT());
1652                 owner->view()->update(TEXT(),
1653                                       BufferView::SELECT|BufferView::FITCUR);
1654                 TEXT()->CursorTop(owner->view());
1655                 TEXT()->FinishUndo();
1656                 moveCursorUpdate(true, false);
1657                 owner->showState();
1658                 break;
1659                 
1660         case LFUN_ENDBUF:
1661                 if (!TEXT()->mark_set)
1662                         owner->view()->beforeChange(TEXT());
1663                 owner->view()->update(TEXT(),
1664                                       BufferView::SELECT|BufferView::FITCUR);
1665                 TEXT()->CursorBottom(owner->view());
1666                 TEXT()->FinishUndo();
1667                 moveCursorUpdate(true, false);
1668                 owner->showState();
1669                 break;
1670
1671       
1672                 /* cursor selection ---------------------------- */
1673         case LFUN_RIGHTSEL:
1674                 owner->view()->update(TEXT(),
1675                                       BufferView::SELECT|BufferView::FITCUR);
1676                 if (TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params))
1677                         TEXT()->CursorLeft(owner->view());
1678                 else
1679                         TEXT()->CursorRight(owner->view());
1680                 TEXT()->FinishUndo();
1681                 moveCursorUpdate(true, true);
1682                 owner->showState();
1683                 break;
1684                 
1685         case LFUN_LEFTSEL:
1686                 owner->view()->update(TEXT(),
1687                                       BufferView::SELECT|BufferView::FITCUR);
1688                 if (TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params))
1689                         TEXT()->CursorRight(owner->view());
1690                 else
1691                         TEXT()->CursorLeft(owner->view());
1692                 TEXT()->FinishUndo();
1693                 moveCursorUpdate(true, true);
1694                 owner->showState();
1695                 break;
1696                 
1697         case LFUN_UPSEL:
1698                 owner->view()->update(TEXT(),
1699                                       BufferView::SELECT|BufferView::FITCUR);
1700                 TEXT()->CursorUp(owner->view());
1701                 TEXT()->FinishUndo();
1702                 moveCursorUpdate(true, true);
1703                 owner->showState();
1704                 break;
1705                 
1706         case LFUN_DOWNSEL:
1707                 owner->view()->update(TEXT(),
1708                                       BufferView::SELECT|BufferView::FITCUR);
1709                 TEXT()->CursorDown(owner->view());
1710                 TEXT()->FinishUndo();
1711                 moveCursorUpdate(true, true);
1712                 owner->showState();
1713                 break;
1714
1715         case LFUN_UP_PARAGRAPHSEL:
1716                 owner->view()->update(TEXT(),
1717                                       BufferView::SELECT|BufferView::FITCUR);
1718                 TEXT()->CursorUpParagraph(owner->view());
1719                 TEXT()->FinishUndo();
1720                 moveCursorUpdate(true, true);
1721                 owner->showState();
1722                 break;
1723                 
1724         case LFUN_DOWN_PARAGRAPHSEL:
1725                 owner->view()->update(TEXT(),
1726                                       BufferView::SELECT|BufferView::FITCUR);
1727                 TEXT()->CursorDownParagraph(owner->view());
1728                 TEXT()->FinishUndo();
1729                 moveCursorUpdate(true, true);
1730                 owner->showState();
1731                 break;
1732                 
1733         case LFUN_PRIORSEL:
1734                 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR);
1735                 owner->view()->cursorPrevious(TEXT(false));
1736                 TEXT()->FinishUndo();
1737                 moveCursorUpdate(false, true);
1738                 owner->showState();
1739                 break;
1740                 
1741         case LFUN_NEXTSEL:
1742                 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR);
1743                 owner->view()->cursorNext(TEXT(false));
1744                 TEXT()->FinishUndo();
1745                 moveCursorUpdate(false, true);
1746                 owner->showState();
1747                 break;
1748                 
1749         case LFUN_HOMESEL:
1750                 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR);
1751                 TEXT(false)->CursorHome(owner->view());
1752                 TEXT()->FinishUndo();
1753                 moveCursorUpdate(false, true);
1754                 owner->showState();
1755                 break;
1756                 
1757         case LFUN_ENDSEL:
1758                 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR);
1759                 TEXT(false)->CursorEnd(owner->view());
1760                 TEXT()->FinishUndo();
1761                 moveCursorUpdate(false, true);
1762                 owner->showState();
1763                 break;
1764                 
1765         case LFUN_WORDRIGHTSEL:
1766                 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR);
1767                 if (TEXT(false)->cursor.par()->isRightToLeftPar(owner->buffer()->params))
1768                         TEXT(false)->CursorLeftOneWord(owner->view());
1769                 else
1770                         TEXT(false)->CursorRightOneWord(owner->view());
1771                 TEXT()->FinishUndo();
1772                 moveCursorUpdate(false, true);
1773                 owner->showState();
1774                 break;
1775                 
1776         case LFUN_WORDLEFTSEL:
1777                 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR);
1778                 if (TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params))
1779                         TEXT(false)->CursorRightOneWord(owner->view());
1780                 else
1781                         TEXT(false)->CursorLeftOneWord(owner->view());
1782                 TEXT()->FinishUndo();
1783                 moveCursorUpdate(false, true);
1784                 owner->showState();
1785                 break;
1786                 
1787         case LFUN_BEGINNINGBUFSEL:
1788                 if (TEXT(false)->inset_owner)
1789                     break;
1790                 owner->view()->update(TEXT(), BufferView::SELECT|BufferView::FITCUR);
1791                 TEXT()->CursorTop(owner->view());
1792                 TEXT()->FinishUndo();
1793                 moveCursorUpdate(true, true);
1794                 owner->showState();
1795                 break;
1796                 
1797         case LFUN_ENDBUFSEL:
1798                 if (TEXT(false)->inset_owner)
1799                     break;
1800                 owner->view()->update(TEXT(),
1801                                       BufferView::SELECT|BufferView::FITCUR);
1802                 TEXT()->CursorBottom(owner->view());
1803                 TEXT()->FinishUndo();
1804                 moveCursorUpdate(true, true);
1805                 owner->showState();
1806                 break;
1807
1808                 // --- text changing commands ------------------------
1809         case LFUN_BREAKLINE:
1810                 owner->view()->beforeChange(TEXT());
1811                 TEXT()->InsertChar(owner->view(), LyXParagraph::META_NEWLINE);
1812                 owner->view()->update(TEXT(),
1813                                       BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1814                 moveCursorUpdate(true, false);
1815                 break;
1816                 
1817         case LFUN_PROTECTEDSPACE:
1818         {
1819                 LyXLayout const & style =
1820                         textclasslist.Style(owner->view()->buffer()->params.textclass,
1821                                             TEXT(false)->cursor.par()->GetLayout());
1822
1823                 if (style.free_spacing) {
1824                         TEXT(false)->InsertChar(owner->view(), ' ');
1825                         owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1826                 } else {
1827                         owner->view()->protectedBlank(TEXT(false));
1828                 }
1829                 moveCursorUpdate(false, false);
1830         }
1831         break;
1832                 
1833         case LFUN_SETMARK:
1834                 if (TEXT(false)->mark_set) {
1835                         owner->view()->beforeChange(TEXT(false));
1836                         owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR);
1837                         setMessage(N_("Mark removed"));
1838                 } else {
1839                         owner->view()->beforeChange(TEXT(false));
1840                         TEXT(false)->mark_set = 1;
1841                         owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR);
1842                         setMessage(N_("Mark set"));
1843                 }
1844                 TEXT(false)->sel_cursor = TEXT(false)->cursor;
1845                 break;
1846                 
1847         case LFUN_DELETE:
1848                 if (!TEXT()->selection) {
1849                         TEXT()->Delete(owner->view());
1850                         TEXT()->sel_cursor = 
1851                                 TEXT()->cursor;
1852                         owner->view()->update(TEXT(),
1853                                               BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1854                         // It is possible to make it a lot faster still
1855                         // just comment out the line below...
1856                         owner->view()->showCursor();
1857                 } else {
1858                         owner->view()->cut();
1859                 }
1860                 moveCursorUpdate(true, false);
1861                 owner->showState();
1862                 owner->view()->setState();
1863                 break;
1864
1865         case LFUN_DELETE_SKIP:
1866         {
1867                 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1868                 
1869                 LyXCursor cursor = TEXT()->cursor;
1870
1871                 if (!TEXT()->selection) {
1872                         if (cursor.pos() == cursor.par()->Last()) {
1873                                 TEXT()->CursorRight(owner->view());
1874                                 cursor = TEXT()->cursor;
1875                                 if (cursor.pos() == 0
1876                                     && !(cursor.par()->added_space_top 
1877                                          == VSpace (VSpace::NONE))) {
1878                                         TEXT()->SetParagraph
1879                                                 (owner->view(),
1880                                                  cursor.par()->line_top,
1881                                                  cursor.par()->line_bottom,
1882                                                  cursor.par()->pagebreak_top, 
1883                                                  cursor.par()->pagebreak_bottom,
1884                                                  VSpace(VSpace::NONE), 
1885                                                  cursor.par()->added_space_bottom,
1886                                                  cursor.par()->align, 
1887                                                  cursor.par()->labelwidthstring, 0);
1888                                         TEXT()->CursorLeft(owner->view());
1889                                         owner->view()->update(TEXT(), 
1890                                                               BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1891                                 } else {
1892                                         TEXT()->CursorLeft(owner->view());
1893                                         TEXT()->Delete(owner->view());
1894                                         TEXT()->sel_cursor = 
1895                                                 TEXT()->cursor;
1896                                         owner->view()->update(TEXT(),
1897                                                               BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1898                                 }
1899                         } else {
1900                                 TEXT()->Delete(owner->view());
1901                                 TEXT()->sel_cursor = 
1902                                         TEXT()->cursor;
1903                                 owner->view()->update(TEXT(),
1904                                                       BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1905                         }
1906                 } else {
1907                         owner->view()->cut();
1908                 }
1909         }
1910         break;
1911
1912         /* -------> Delete word forward. */
1913         case LFUN_DELETE_WORD_FORWARD:
1914                 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR);
1915                 TEXT(false)->DeleteWordForward(owner->view());
1916                 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1917                 moveCursorUpdate(false, false);
1918                 owner->showState();
1919                 break;
1920
1921                 /* -------> Delete word backward. */
1922         case LFUN_DELETE_WORD_BACKWARD:
1923                 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR);
1924                 TEXT(false)->DeleteWordBackward(owner->view());
1925                 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1926                 moveCursorUpdate(false, false);
1927                 owner->showState();
1928                 break;
1929                 
1930                 /* -------> Kill to end of line. */
1931         case LFUN_DELETE_LINE_FORWARD:
1932                 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR);
1933                 TEXT(false)->DeleteLineForward(owner->view());
1934                 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1935                 moveCursorUpdate(false, false);
1936                 break;
1937                 
1938                 /* -------> Set mark off. */
1939         case LFUN_MARK_OFF:
1940                 owner->view()->beforeChange(TEXT(false));
1941                 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR);
1942                 TEXT(false)->sel_cursor = TEXT(false)->cursor;
1943                 setMessage(N_("Mark off"));
1944                 break;
1945
1946                 /* -------> Set mark on. */
1947         case LFUN_MARK_ON:
1948                 owner->view()->beforeChange(TEXT(false));
1949                 TEXT(false)->mark_set = 1;
1950                 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR);
1951                 TEXT(false)->sel_cursor = TEXT(false)->cursor;
1952                 setMessage(N_("Mark on"));
1953                 break;
1954                 
1955         case LFUN_BACKSPACE:
1956         {
1957                 if (!TEXT()->selection) {
1958                         if (owner->getIntl()->getTrans().backspace()) {
1959                                 TEXT()->Backspace(owner->view());
1960                                 TEXT()->sel_cursor = 
1961                                         TEXT()->cursor;
1962                                 owner->view()->update(TEXT(),
1963                                                       BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1964                                 // It is possible to make it a lot faster still
1965                                 // just comment out the line below...
1966                                 owner->view()->showCursor();
1967                         }
1968                 } else {
1969                         owner->view()->cut();
1970                 }
1971                 owner->showState();
1972                 owner->view()->setState();
1973         }
1974         break;
1975
1976         case LFUN_BACKSPACE_SKIP:
1977         {
1978                 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1979                 
1980                 LyXCursor cursor = TEXT()->cursor;
1981                 
1982                 if (!TEXT()->selection) {
1983                         if (cursor.pos() == 0 
1984                             && !(cursor.par()->added_space_top 
1985                                  == VSpace (VSpace::NONE))) {
1986                                 TEXT()->SetParagraph 
1987                                         (owner->view(),
1988                                          cursor.par()->line_top,      
1989                                          cursor.par()->line_bottom,
1990                                          cursor.par()->pagebreak_top, 
1991                                          cursor.par()->pagebreak_bottom,
1992                                          VSpace(VSpace::NONE), cursor.par()->added_space_bottom,
1993                                          cursor.par()->align, 
1994                                          cursor.par()->labelwidthstring, 0);
1995                                 owner->view()->update(TEXT(),
1996                                                       BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1997                         } else {
1998                                 TEXT()->Backspace(owner->view());
1999                                 TEXT()->sel_cursor 
2000                                         = cursor;
2001                                 owner->view()->update(TEXT(),
2002                                                       BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2003                         }
2004                 } else
2005                         owner->view()->cut();
2006         }
2007         break;
2008
2009         case LFUN_BREAKPARAGRAPH:
2010         {
2011                 owner->view()->beforeChange(TEXT());
2012                 TEXT()->BreakParagraph(owner->view(), 0);
2013                 owner->view()->update(TEXT(),
2014                                       BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2015                 TEXT()->sel_cursor = 
2016                         TEXT()->cursor;
2017                 owner->view()->setState();
2018                 owner->showState();
2019                 break;
2020         }
2021
2022         case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2023         {
2024                 owner->view()->beforeChange(TEXT());
2025                 TEXT()->BreakParagraph(owner->view(), 1);
2026                 owner->view()->update(TEXT(),
2027                                       BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2028                 TEXT()->sel_cursor = 
2029                         TEXT()->cursor;
2030                 owner->view()->setState();
2031                 owner->showState();
2032                 break;
2033         }
2034         
2035         case LFUN_BREAKPARAGRAPH_SKIP:
2036         {
2037                 // When at the beginning of a paragraph, remove
2038                 // indentation and add a "defskip" at the top.
2039                 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2040                 
2041                 LyXCursor cursor = TEXT()->cursor;
2042                 
2043                 owner->view()->beforeChange(TEXT());
2044                 if (cursor.pos() == 0) {
2045                         if (cursor.par()->added_space_top == VSpace(VSpace::NONE)) {
2046                                 TEXT()->SetParagraph
2047                                         (owner->view(),
2048                                          cursor.par()->line_top,      
2049                                          cursor.par()->line_bottom,
2050                                          cursor.par()->pagebreak_top, 
2051                                          cursor.par()->pagebreak_bottom,
2052                                          VSpace(VSpace::DEFSKIP), cursor.par()->added_space_bottom,
2053                                          cursor.par()->align, 
2054                                          cursor.par()->labelwidthstring, 1);
2055                                 //owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2056                         } 
2057                 }
2058                 else {
2059                         TEXT()->BreakParagraph(owner->view(), 0);
2060                         //owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2061                 }
2062
2063                 owner->view()->update(TEXT(),
2064                                       BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2065                 TEXT()->sel_cursor = cursor;
2066                 owner->view()->setState();
2067                 owner->showState();
2068         }
2069         break;
2070
2071         case LFUN_PARAGRAPH_SPACING:
2072         {
2073                 LyXParagraph * par = TEXT()->cursor.par();
2074                 Spacing::Space cur_spacing = par->spacing.getSpace();
2075                 float cur_value = 1.0;
2076                 if (cur_spacing == Spacing::Other) {
2077                         cur_value = par->spacing.getValue();
2078                 }
2079                 
2080                 istringstream istr(argument.c_str());
2081
2082                 string tmp;
2083                 istr >> tmp;
2084                 Spacing::Space new_spacing = cur_spacing;
2085                 float new_value = cur_value;
2086                 if (tmp.empty()) {
2087                         lyxerr << "Missing argument to `paragraph-spacing'"
2088                                << endl;
2089                 } else if (tmp == "single") {
2090                         new_spacing = Spacing::Single;
2091                 } else if (tmp == "onehalf") {
2092                         new_spacing = Spacing::Onehalf;
2093                 } else if (tmp == "double") {
2094                         new_spacing = Spacing::Double;
2095                 } else if (tmp == "other") {
2096                         new_spacing = Spacing::Other;
2097                         float tmpval = 0.0;
2098                         istr >> tmpval;
2099                         lyxerr << "new_value = " << tmpval << endl;
2100                         if (tmpval != 0.0)
2101                                 new_value = tmpval;
2102                 } else if (tmp == "default") {
2103                         new_spacing = Spacing::Default;
2104                 } else {
2105                         lyxerr << _("Unknown spacing argument: ")
2106                                << argument << endl;
2107                 }
2108                 if (cur_spacing != new_spacing || cur_value != new_value) {
2109                         par->spacing.set(new_spacing, new_value);
2110                         TEXT()->RedoParagraph(owner->view());
2111                         owner->view()->update(TEXT(),
2112                                               BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2113                 }
2114         }
2115         break;
2116         
2117         case LFUN_QUOTE:
2118                 owner->view()->beforeChange(TEXT(false));
2119                 TEXT(false)->InsertChar(owner->view(), '\"');  // This " matches the single quote in the code
2120                 owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2121                 moveCursorUpdate(false, false);
2122                 break;
2123
2124         case LFUN_HTMLURL:
2125         case LFUN_URL:
2126         {
2127                 InsetCommandParams p;
2128                 if (action == LFUN_HTMLURL)
2129                         p.setCmdName("htmlurl");
2130                 else
2131                         p.setCmdName("url");
2132                 owner->getDialogs()->createUrl( p.getAsString() );
2133         }
2134         break;
2135                     
2136         case LFUN_INSERT_URL:
2137         {
2138                 InsetCommandParams p;
2139                 p.setFromString( argument );
2140
2141                 InsetUrl * inset = new InsetUrl( p );
2142                 if (!owner->view()->insertInset(inset))
2143                         delete inset;
2144                 else
2145                         owner->view()->updateInset( inset, true );
2146         }
2147         break;
2148                     
2149         case LFUN_INSET_TEXT:
2150         {
2151                 InsetText * new_inset = new InsetText;
2152                 if (owner->view()->insertInset(new_inset))
2153                         new_inset->Edit(owner->view(), 0, 0, 0);
2154                 else
2155                         delete new_inset;
2156         }
2157         break;
2158         
2159         case LFUN_INSET_ERT:
2160         {
2161                 InsetERT * new_inset = new InsetERT;
2162                 if (owner->view()->insertInset(new_inset))
2163                         new_inset->Edit(owner->view(), 0, 0, 0);
2164                 else
2165                         delete new_inset;
2166         }
2167         break;
2168         
2169         case LFUN_INSET_EXTERNAL:
2170         {
2171                 InsetExternal * new_inset = new InsetExternal;
2172                 if (owner->view()->insertInset(new_inset))
2173                         new_inset->Edit(owner->view(), 0, 0, 0);
2174                 else
2175                         delete new_inset;
2176         }
2177         break;
2178         
2179         case LFUN_INSET_FOOTNOTE:
2180         {
2181                 InsetFoot * new_inset = new InsetFoot;
2182                 if (owner->view()->insertInset(new_inset))
2183                         new_inset->Edit(owner->view(), 0, 0, 0);
2184                 else
2185                         delete new_inset;
2186         }
2187         break;
2188
2189         case LFUN_INSET_MARGINAL:
2190         {
2191                 InsetMarginal * new_inset = new InsetMarginal;
2192                 if (owner->view()->insertInset(new_inset))
2193                         new_inset->Edit(owner->view(), 0, 0, 0);
2194                 else
2195                         delete new_inset;
2196         }
2197         break;
2198
2199         case LFUN_INSET_MINIPAGE:
2200         {
2201                 InsetMinipage * new_inset = new InsetMinipage;
2202                 if (owner->view()->insertInset(new_inset))
2203                         new_inset->Edit(owner->view(), 0, 0, 0);
2204                 else
2205                         delete new_inset;
2206         }
2207         break;
2208
2209         case LFUN_INSET_FLOAT:
2210         {
2211                 // check if the float type exist
2212                 if (floatList.typeExist(argument)) {
2213                         InsetFloat * new_inset = new InsetFloat(argument);
2214                         if (owner->view()->insertInset(new_inset))
2215                                 new_inset->Edit(owner->view(), 0, 0, 0);
2216                         else
2217                                 delete new_inset;
2218                 } else {
2219                         lyxerr << "Non-existant float type: "
2220                                << argument << endl;
2221                 }
2222                 
2223         }
2224         break;
2225
2226         case LFUN_INSET_LIST:
2227         {
2228                 InsetList * new_inset = new InsetList;
2229                 if (owner->view()->insertInset(new_inset))
2230                         new_inset->Edit(owner->view(), 0, 0, 0);
2231                 else
2232                         delete new_inset;
2233         }
2234         break;
2235
2236         case LFUN_INSET_THEOREM:
2237         {
2238                 InsetTheorem * new_inset = new InsetTheorem;
2239                 if (owner->view()->insertInset(new_inset))
2240                         new_inset->Edit(owner->view(), 0, 0, 0);
2241                 else
2242                         delete new_inset;
2243         }
2244         break;
2245
2246         case LFUN_INSET_CAPTION:
2247         {
2248                 // Do we have a locking inset...
2249                 if (owner->view()->theLockingInset()) {
2250                         lyxerr << "Locking inset code: "
2251                                << static_cast<int>(owner->view()->theLockingInset()->LyxCode());
2252                         InsetCaption * new_inset = new InsetCaption;
2253                         new_inset->setOwner(owner->view()->theLockingInset());
2254                         new_inset->SetAutoBreakRows(true);
2255                         new_inset->SetDrawFrame(0, InsetText::LOCKED);
2256                         new_inset->SetFrameColor(0, LColor::footnoteframe);
2257                         if (owner->view()->insertInset(new_inset))
2258                                 new_inset->Edit(owner->view(), 0, 0, 0);
2259                         else
2260                                 delete new_inset;
2261                 }
2262         }
2263         break;
2264         
2265         case LFUN_INSET_TABULAR:
2266         {
2267                 int r = 2, c = 2;
2268                 if (!argument.empty())
2269                         ::sscanf(argument.c_str(),"%d%d", &r, &c);
2270                 InsetTabular * new_inset =
2271                         new InsetTabular(*owner->buffer(), r, c);
2272                 bool rtl =
2273                         TEXT(false)->real_current_font.isRightToLeft();
2274                 if (!owner->view()->open_new_inset(new_inset, rtl))
2275                         delete new_inset;
2276         }
2277         break;
2278
2279         // --- lyxserver commands ----------------------------
2280
2281         case LFUN_CHARATCURSOR:
2282         {
2283                 LyXParagraph::size_type pos = 
2284                         TEXT()->cursor.pos();
2285                 if (pos < TEXT()->cursor.par()->size())
2286                         //dispatch_buffer = TEXT()->
2287                         //      cursor.par()->text[pos];
2288                         dispatch_buffer =
2289                                 TEXT()->
2290                                 cursor.par()->GetChar(pos);
2291                 else
2292                         dispatch_buffer = "EOF";
2293         }
2294         break;
2295         
2296         case LFUN_GETXY:
2297                 dispatch_buffer = 
2298                         tostr(TEXT()->cursor.x()) + ' '
2299                         + tostr(TEXT()->cursor.y());
2300                 break;
2301                 
2302         case LFUN_SETXY:
2303         {
2304                 int x;
2305                 int y;
2306                 ::sscanf(argument.c_str(), " %d %d", &x, &y);
2307                 TEXT()->SetCursorFromCoordinates(owner->view(), x, y);
2308         }
2309         break;
2310         
2311         case LFUN_GETLAYOUT:
2312                 dispatch_buffer =  
2313                         tostr(TEXT()->cursor.par()->layout);
2314                 break;
2315                         
2316         case LFUN_GETFONT:
2317         {
2318                 LyXFont & font = TEXT()->current_font;
2319                 if (font.shape() == LyXFont::ITALIC_SHAPE)
2320                         dispatch_buffer = 'E';
2321                 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2322                         dispatch_buffer = 'N';
2323                 else
2324                         dispatch_buffer = '0';
2325
2326         }
2327         break;
2328
2329         case LFUN_GETLATEX:
2330         {
2331                 LyXFont & font = TEXT()->current_font;
2332                 if (font.latex() == LyXFont::ON)
2333                         dispatch_buffer = 'L';
2334                 else
2335                         dispatch_buffer = '0';
2336         }
2337         break;
2338
2339         case LFUN_GETNAME:
2340                 setMessage(owner->buffer()->fileName());
2341                 lyxerr.debug() << "FNAME["
2342                                << owner->buffer()->fileName()
2343                                << "] " << endl;
2344                 break;
2345                 
2346         case LFUN_NOTIFY:
2347         {
2348                 string buf;
2349                 keyseq.print(buf);
2350                 dispatch_buffer = buf;
2351                 lyxserver->notifyClient(dispatch_buffer);
2352         }
2353         break;
2354
2355         case LFUN_GOTOFILEROW:
2356         {
2357                 char file_name[100];
2358                 int row;
2359                 ::sscanf(argument.c_str(), " %s %d", file_name, &row);
2360
2361                 // Must replace extension of the file to be .lyx and get full path
2362                 string s = ChangeExtension(string(file_name), ".lyx");
2363
2364                 // Either change buffer or load the file
2365                 if (bufferlist.exists(s))
2366                         owner->view()->buffer(bufferlist.getBuffer(s));
2367                 else
2368                         owner->view()->buffer(bufferlist.loadLyXFile(s));
2369
2370                 // Set the cursor  
2371                 owner->view()->setCursorFromRow(row);
2372
2373                 // Recenter screen
2374                 owner->view()->center();
2375         }
2376         break;
2377
2378         case LFUN_GOTO_PARAGRAPH:
2379         {
2380                 istringstream istr(argument.c_str());
2381
2382                 int id;
2383                 istr >> id;
2384                 LyXParagraph * par = TEXT()->GetParFromID(id);
2385
2386                 // Set the cursor
2387                 TEXT()->SetCursor(owner->view(), par, 0);
2388                 owner->view()->setState();
2389                 owner->showState();
2390
2391                 // Recenter screen
2392                 owner->view()->center();
2393         }
2394         break;
2395
2396         case LFUN_APROPOS:
2397         case LFUN_GETTIP:
2398         {
2399                 int const qa = lyxaction.LookupFunc(argument);
2400                 setMessage(lyxaction.helpText(static_cast<kb_action>(qa)));
2401         }
2402         break;
2403
2404         // --- accented characters ---------------------------
2405                 
2406         case LFUN_UMLAUT:
2407         case LFUN_CIRCUMFLEX:
2408         case LFUN_GRAVE:
2409         case LFUN_ACUTE:
2410         case LFUN_TILDE:
2411         case LFUN_CEDILLA:
2412         case LFUN_MACRON:
2413         case LFUN_DOT:
2414         case LFUN_UNDERDOT:
2415         case LFUN_UNDERBAR:
2416         case LFUN_CARON:
2417         case LFUN_SPECIAL_CARON:
2418         case LFUN_BREVE:
2419         case LFUN_TIE:
2420         case LFUN_HUNG_UMLAUT:
2421         case LFUN_CIRCLE:
2422         case LFUN_OGONEK:
2423         {
2424                 char c = 0;
2425                 
2426                 if (keyseq.length == -1 && keyseq.getiso() != 0) 
2427                         c = keyseq.getiso();
2428
2429                 owner->getIntl()->getTrans()
2430                         .deadkey(c, get_accent(action).accent, 
2431                                 TEXT());
2432                 
2433                 // Need to reset, in case the minibuffer calls these
2434                 // actions
2435                 keyseq.reset();
2436                 keyseq.length = 0;
2437                 
2438                 // copied verbatim from do_accent_char
2439                 owner->view()->update(TEXT(),
2440                                       BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2441
2442                 TEXT()->sel_cursor = 
2443                         TEXT()->cursor;
2444         }   
2445         break;
2446         
2447         // --- toolbar ----------------------------------
2448         case LFUN_PUSH_TOOLBAR:
2449         {
2450                 int nth = strToInt(argument);
2451                 if (nth <= 0) {
2452                         setErrorMessage(N_("Push-toolbar needs argument > 0"));
2453                 } else {
2454                         owner->getToolbar()->push(nth);
2455                 }
2456         }
2457         break;
2458         
2459         case LFUN_ADD_TO_TOOLBAR:
2460         {
2461                 if (lyxerr.debugging(Debug::GUI)) {
2462                         lyxerr << "LFUN_ADD_TO_TOOLBAR:"
2463                                 "argument = `" << argument << '\'' << endl;
2464                 }
2465                 string tmp(argument);
2466                 //lyxerr <<string("Argument: ") + argument);
2467                 //lyxerr <<string("Tmp     : ") + tmp);
2468                 if (tmp.empty()) {
2469                         setErrorMessage(N_("Usage: toolbar-add-to <LyX command>"));
2470                 } else {
2471                         owner->getToolbar()->add(argument, false);
2472                         owner->getToolbar()->set();
2473                 }
2474         }
2475         break;
2476         
2477         // --- insert characters ----------------------------------------
2478
2479         // ---  Mathed stuff. If we are here, there is no locked inset yet.
2480         
2481         // Greek mode     
2482         case LFUN_GREEK:
2483         {
2484                 if (!greek_kb_flag) {
2485                         greek_kb_flag = 1;
2486                         setMessage(N_("Math greek mode on"));
2487                 } else
2488                         greek_kb_flag = 0;
2489         }  
2490         break;
2491       
2492         // Greek keyboard      
2493         case LFUN_GREEK_TOGGLE:
2494         {
2495                 greek_kb_flag = greek_kb_flag ? 0 : 2;
2496                 if (greek_kb_flag) {
2497                         setMessage(N_("Math greek keyboard on"));
2498                 } else {
2499                         setMessage(N_("Math greek keyboard off"));
2500                 }
2501         }
2502         break;
2503         
2504         case LFUN_MATH_DELIM:     
2505         case LFUN_INSERT_MATRIX:
2506         {          
2507                 if (owner->view()->available()) { 
2508                         if (owner->view()->
2509                             open_new_inset(new InsetFormula(false)))
2510                         {
2511                                 owner->view()->theLockingInset()
2512                                         ->LocalDispatch(owner->view(),
2513                                                         action,
2514                                                         argument);
2515                         }
2516                 }
2517         }          
2518         break;
2519                
2520         case LFUN_INSERT_MATH:
2521         {
2522                 math_insert_symbol(owner->view(), argument);
2523         }
2524         break;
2525         
2526         case LFUN_MATH_DISPLAY:
2527         {
2528                 if (owner->view()->available())
2529                         owner->view()->open_new_inset(new InsetFormula(true));
2530                 break;
2531         }
2532                     
2533         case LFUN_MATH_MACRO:
2534         {
2535                 if (owner->view()->available()) {
2536                         string s(argument);
2537                         if (s.empty())
2538                                 setErrorMessage(N_("Missing argument"));
2539                         else {
2540                                 string const s1 = token(s, ' ', 1);
2541                                 int const na = s1.empty() ? 0 : lyx::atoi(s1);
2542                                 owner->view()->
2543                                         open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2544                         }
2545                 }
2546         }
2547         break;
2548
2549         case LFUN_MATH_MODE:   // Open or create a math inset
2550         {               
2551                 if (owner->view()->available())
2552                         owner->view()->open_new_inset(new InsetFormula);
2553                 setMessage(N_("Math editor mode"));
2554         }
2555         break;
2556           
2557         case LFUN_MATH_NUMBER:
2558         case LFUN_MATH_LIMITS:
2559         {
2560                 setErrorMessage(N_("This is only allowed in math mode!"));
2561         
2562         }
2563         break;
2564
2565         case LFUN_MATH_PANEL:
2566         {
2567                 show_symbols_form(this);
2568         }
2569         break;
2570         
2571         case LFUN_CITATION_CREATE:
2572         {
2573                 InsetCommandParams p( "cite" );
2574                 
2575                 if (!argument.empty()) {
2576                         // This should be set at source, ie when typing
2577                         // "citation-insert foo" in the minibuffer.
2578                         // Question: would pybibliographer also need to be
2579                         // changed. Suspect so. Leave as-is therefore.
2580                         if (contains(argument, "|")) {
2581                                 p.setContents( token(argument, '|', 0) );
2582                                 p.setOptions(  token(argument, '|', 1) );
2583                         } else {
2584                                 p.setContents( argument );
2585                         }
2586                         Dispatch(LFUN_CITATION_INSERT, p.getAsString());
2587                 } else
2588                         owner->getDialogs()->createCitation( p.getAsString() );
2589         }
2590         break;
2591                     
2592         case LFUN_CITATION_INSERT:
2593         {
2594                 InsetCommandParams p;
2595                 p.setFromString( argument );
2596
2597                 InsetCitation * inset = new InsetCitation( p );
2598                 if (!owner->view()->insertInset(inset))
2599                         delete inset;
2600                 else
2601                         owner->view()->updateInset( inset, true );
2602         }
2603         break;
2604                     
2605         case LFUN_INSERT_BIBTEX:
2606         {   
2607                 // ale970405+lasgoutt970425
2608                 // The argument can be up to two tokens separated 
2609                 // by a space. The first one is the bibstyle.
2610                 string const db       = token(argument, ' ', 0);
2611                 string bibstyle = token(argument, ' ', 1);
2612                 if (bibstyle.empty())
2613                         bibstyle = "plain";
2614
2615                 InsetCommandParams p( "BibTeX", db, bibstyle );
2616                 InsetBibtex * inset = new InsetBibtex(p);
2617                 
2618                 if (owner->view()->insertInset(inset)) {
2619                         if (argument.empty())
2620                                 inset->Edit(owner->view(), 0, 0, 0);
2621                 } else
2622                         delete inset;
2623         }
2624         break;
2625                 
2626         // BibTeX data bases
2627         case LFUN_BIBDB_ADD:
2628         {
2629                 InsetBibtex * inset = 
2630                         static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2631                 if (inset) {
2632                         inset->addDatabase(argument);
2633                 }
2634         }
2635         break;
2636                     
2637         case LFUN_BIBDB_DEL:
2638         {
2639                 InsetBibtex * inset = 
2640                         static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2641                 if (inset) {
2642                         inset->delDatabase(argument);
2643                 }
2644         }
2645         break;
2646         
2647         case LFUN_BIBTEX_STYLE:
2648         {
2649                 InsetBibtex * inset = 
2650                         static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2651                 if (inset) {
2652                         inset->setOptions(argument);
2653                 }
2654         }
2655         break;
2656                 
2657         case LFUN_INDEX_CREATE:
2658         {
2659                 InsetCommandParams p( "index" );
2660                 
2661                 if (argument.empty()) {
2662                         // Get the word immediately preceding the cursor
2663                         LyXParagraph::size_type curpos = 
2664                                 TEXT()->cursor.pos() - 1;
2665
2666                         string curstring;
2667                         if (curpos >= 0 )
2668                                 curstring = TEXT()
2669                                             ->cursor.par()->GetWord(curpos);
2670
2671                         p.setContents( curstring );
2672                 } else {
2673                         p.setContents( argument );
2674                 }
2675
2676                 owner->getDialogs()->createIndex( p.getAsString() );
2677         }
2678         break;
2679                     
2680         case LFUN_INDEX_INSERT:
2681         {
2682                 InsetCommandParams p;
2683                 p.setFromString(argument);
2684                 InsetIndex * inset = new InsetIndex(p);
2685
2686                 if (!owner->view()->insertInset(inset))
2687                         delete inset;
2688                 else
2689                         owner->view()->updateInset(inset, true);
2690         }
2691         break;
2692                     
2693         case LFUN_INDEX_INSERT_LAST:
2694         {
2695                 // Get word immediately preceding the cursor
2696                 LyXParagraph::size_type curpos = 
2697                         TEXT()->cursor.pos() - 1;
2698                 // Can't do that at the beginning of a paragraph
2699                 if (curpos < 0) break;
2700
2701                 string const curstring(TEXT()
2702                                   ->cursor.par()->GetWord(curpos));
2703
2704                 InsetCommandParams p("index", curstring);
2705                 InsetIndex * inset = new InsetIndex(p);
2706
2707                 if (!owner->view()->insertInset(inset))
2708                         delete inset;
2709                 else
2710                         owner->view()->updateInset(inset, true);
2711         }
2712         break;
2713                     
2714         case LFUN_INDEX_PRINT:
2715         {
2716                 InsetCommandParams p("printindex");
2717                 Inset * inset = new InsetPrintIndex(p);
2718                 if (!owner->view()->insertInset(inset, "Standard", true))
2719                         delete inset;
2720         }
2721         break;
2722
2723         case LFUN_PARENTINSERT:
2724         {
2725                 lyxerr << "arg " << argument << endl;
2726                 InsetCommandParams p( "lyxparent", argument );
2727                 Inset * inset = new InsetParent(p, *owner->buffer());
2728                 if (!owner->view()->insertInset(inset, "Standard", true))
2729                         delete inset;
2730         }
2731         break;
2732
2733         case LFUN_CHILD_CREATE:
2734         {
2735                 InsetCommandParams p("include");
2736  
2737                 if (!argument.empty()) {
2738                         if (contains(argument, "|")) {
2739                                 p.setContents(token(argument, '|', 0));
2740                                 p.setOptions(token(argument, '|', 1));
2741                         } else
2742                                 p.setContents(argument);
2743                         Dispatch(LFUN_CHILD_INSERT, p.getAsString());
2744                 } else
2745                         owner->getDialogs()->createInclude(p.getAsString());
2746         }
2747         break;
2748
2749         case LFUN_CHILD_INSERT:
2750         {
2751                 InsetCommandParams p;
2752                 p.setFromString(argument);
2753
2754                 InsetInclude * inset = new InsetInclude(p, *owner->buffer());
2755                 if (!owner->view()->insertInset(inset))
2756                         delete inset;
2757                 else
2758                         owner->view()->updateInset(inset, true);
2759         }
2760         break; 
2761
2762         case LFUN_CHILDOPEN:
2763         {
2764                 string const filename =
2765                         MakeAbsPath(argument, 
2766                                     OnlyPath(owner->buffer()->fileName()));
2767                 setMessage(N_("Opening child document ") +
2768                            MakeDisplayPath(filename) + "...");
2769                 owner->view()->savePosition(0);
2770                 if (bufferlist.exists(filename))
2771                         owner->view()->buffer(bufferlist.getBuffer(filename));
2772                 else
2773                         owner->view()->buffer(bufferlist.loadLyXFile(filename));
2774         }
2775         break;
2776
2777         case LFUN_INSERT_NOTE:
2778                 owner->view()->insertNote();
2779                 break;
2780 #ifndef NEW_INSETS
2781         case LFUN_INSERTFOOTNOTE: 
2782         {
2783                 LyXParagraph::footnote_kind kind;
2784                 if (argument == "footnote") {
2785                         kind = LyXParagraph::FOOTNOTE;
2786                 } else if (argument == "margin") {
2787                         kind = LyXParagraph::MARGIN;
2788                 } else if (argument == "figure") {
2789                         kind = LyXParagraph::FIG;
2790                 } else if (argument == "table") {
2791                         kind = LyXParagraph::TAB;
2792                 } else if (argument == "wide-fig") {
2793                         kind = LyXParagraph::WIDE_FIG;
2794                 } else if (argument == "wide-tab") {
2795                         kind = LyXParagraph::WIDE_TAB;
2796                 } else if (argument == "algorithm") {
2797                         kind = LyXParagraph::ALGORITHM;
2798                 } else {
2799                         setErrorMessage(N_("Unknown kind of footnote"));
2800                         break;
2801                 }
2802                 TEXT()->InsertFootnoteEnvironment(owner->view(), kind);
2803                 owner->view()->update(TEXT(),
2804                                       BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2805                 owner->view()->setState();
2806         }
2807         break;
2808 #endif
2809         case LFUN_TOGGLECURSORFOLLOW:
2810                 lyxrc.cursor_follows_scrollbar = !lyxrc.cursor_follows_scrollbar;
2811                 break;
2812                 
2813         case LFUN_KMAP_OFF:             // keymap off
2814                 owner->getIntl()->KeyMapOn(false);
2815                 break;
2816                 
2817         case LFUN_KMAP_PRIM:    // primary keymap
2818                 owner->getIntl()->KeyMapPrim();
2819                 break;
2820                 
2821         case LFUN_KMAP_SEC:             // secondary keymap
2822                 owner->getIntl()->KeyMapSec();
2823                 break;
2824                 
2825         case LFUN_KMAP_TOGGLE:  // toggle keymap
2826                 owner->getIntl()->ToggleKeyMap();
2827                 break;
2828
2829         case LFUN_SELFINSERT:
2830         {
2831                 LyXFont const old_font(TEXT(false)->real_current_font);
2832                 for (string::size_type i = 0; i < argument.length(); ++i) {
2833                         TEXT(false)->InsertChar(owner->view(), argument[i]);
2834                         // This needs to be in the loop, or else we
2835                         // won't break lines correctly. (Asger)
2836                         owner->view()->update(TEXT(false),
2837                                               BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2838                 }
2839                 TEXT(false)->sel_cursor = TEXT(false)->cursor;
2840                 moveCursorUpdate(false, false);
2841
2842                 // real_current_font.number can change so we need to 
2843                 // update the minibuffer
2844                 if (old_font != TEXT(false)->real_current_font)
2845                         owner->showState();
2846         }
2847         break;
2848
2849         case LFUN_SEQUENCE: 
2850         {
2851                 // argument contains ';'-terminated commands
2852                 while (argument.find(';') != string::npos) {
2853                         string first;
2854                         argument = split(argument, first, ';');
2855                         Dispatch(first);
2856                 }
2857         }
2858         break;
2859
2860         case LFUN_DATE_INSERT:  // jdblair: date-insert cmd
2861         {
2862                 struct tm * now_tm;
2863                 
2864                 time_t now_time_t = time(NULL);
2865                 now_tm = localtime(&now_time_t);
2866                 setlocale(LC_TIME, "");
2867                 string arg;
2868                 if (!argument.empty())
2869                         arg = argument;
2870                 else 
2871                         arg = lyxrc.date_insert_format;
2872                 char datetmp[32];
2873                 int const datetmp_len =
2874                         ::strftime(datetmp, 32, arg.c_str(), now_tm);
2875                 for (int i = 0; i < datetmp_len; i++) {
2876                         TEXT()->InsertChar(owner->view(), datetmp[i]);
2877                         owner->view()->update(TEXT(),
2878                                               BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2879                 }
2880
2881                 TEXT()->sel_cursor = TEXT()->cursor;
2882                 moveCursorUpdate(true, false);
2883         }
2884         break;
2885
2886         case LFUN_DIALOG_PREFERENCES:
2887                 owner->getDialogs()->showPreferences();
2888                 break;
2889                 
2890         case LFUN_SAVEPREFERENCES:
2891         {
2892                 Path p(user_lyxdir);
2893                 lyxrc.write("preferences");
2894         }
2895         break;
2896
2897         case LFUN_SCREEN_FONT_UPDATE:
2898         {
2899                 // handle the screen font changes.
2900                 // 
2901                 lyxrc.set_font_norm_type();
2902                 fontloader.update();
2903                 // Of course we should only do the resize and the textcache.clear
2904                 // if values really changed...but not very important right now. (Lgb)
2905                 // All buffers will need resize
2906                 bufferlist.resize();
2907                 // We also need to empty the textcache so that
2908                 // the buffer will be formatted correctly after
2909                 // a zoom change.
2910                 textcache.clear();
2911         }
2912         break;
2913
2914         case LFUN_SET_COLOR:
2915         {
2916                 string lyx_name;
2917                 string const x11_name = split(argument, lyx_name, ' ');
2918                 if (lyx_name.empty() || x11_name.empty()) {
2919                         setErrorMessage(N_("Syntax: set-color <lyx_name>"
2920                                                 " <x11_name>"));
2921                         break;
2922                         }
2923
2924                 if (!lcolor.setColor(lyx_name, x11_name)) {
2925                         static string const err1 (N_("Set-color \""));
2926                         static string const err2 (
2927                                 N_("\" failed - color is undefined "
2928                                    "or may not be redefined"));
2929                         setErrorMessage(_(err1) + lyx_name + _(err2));
2930                         break;
2931                 }
2932                 lyxColorHandler->updateColor(lcolor.getFromLyXName(lyx_name));
2933                 owner->view()->redraw();
2934                 break;
2935         }
2936
2937         case LFUN_UNKNOWN_ACTION:
2938         {
2939                 if (!owner->buffer()) {
2940                         setErrorMessage(N_("No document open"));
2941                         break;
2942                 }
2943
2944                 if (owner->buffer()->isReadonly()) {
2945                         setErrorMessage(N_("Document is read only"));
2946                         break;
2947                 }
2948                          
2949                 if (!argument.empty()) {
2950                         
2951                         /* Automatically delete the currently selected
2952                          * text and replace it with what is being
2953                          * typed in now. Depends on lyxrc settings
2954                          * "auto_region_delete", which defaults to
2955                          * true (on). */
2956                 
2957                         if (lyxrc.auto_region_delete) {
2958                                 if (TEXT()->selection){
2959                                         TEXT()->CutSelection(owner->view(), false);
2960                                         owner->view()->update(TEXT(),
2961                                                               BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2962                                 }
2963                         }
2964                         
2965                         owner->view()->beforeChange(TEXT());
2966                         LyXFont const old_font(TEXT()->real_current_font);
2967                         for (string::size_type i = 0;
2968                              i < argument.length(); ++i) {
2969                                 if (greek_kb_flag) {
2970                                         if (!math_insert_greek(owner->view(),
2971                                                                argument[i]))
2972                                                 owner->getIntl()->getTrans().TranslateAndInsert(argument[i], TEXT());
2973                                 } else
2974                                         owner->getIntl()->getTrans().TranslateAndInsert(argument[i], TEXT());
2975                         }
2976
2977                         owner->view()->update(TEXT(),
2978                                               BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2979
2980                         TEXT()->sel_cursor = 
2981                                 TEXT()->cursor;
2982                         moveCursorUpdate(true, false);
2983
2984                         // real_current_font.number can change so we need to
2985                         // update the minibuffer
2986                         if (old_font != TEXT()->real_current_font)
2987                                 owner->showState();
2988                         return string();
2989                 } else {
2990                         // why is an "Unknown action" with empty
2991                         // argument even dispatched in the first
2992                         // place? I`ll probably change that. (Lgb)
2993                         setErrorMessage(N_("Unknown action"));
2994                 }
2995                 break;
2996         }
2997
2998         default:
2999                 lyxerr << "A truly unknown func!" << endl;
3000                 break;
3001         } // end of switch
3002   exit_with_message:
3003
3004         string const res = getMessage();
3005
3006         if (res.empty()) {
3007                 if (!commandshortcut.empty()) {
3008                         string const newbuf =
3009                                 owner->getMiniBuffer()->GetText();
3010                         if (newbuf != commandshortcut) {
3011                                 owner->getMiniBuffer()->Set(newbuf
3012                                                             + " " +
3013                                                             commandshortcut);
3014                         }
3015                 }
3016         } else {
3017                 string msg(_(res));
3018                 msg += " ";
3019                 msg += commandshortcut;
3020                 owner->getMiniBuffer()->Set(msg);
3021         }
3022
3023         return res;
3024 }
3025
3026
3027 void LyXFunc::setupLocalKeymap()
3028 {
3029         keyseq.stdmap = keyseq.curmap = toplevel_keymap;
3030         cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap;
3031 }
3032
3033
3034 void LyXFunc::MenuNew(bool fromTemplate)
3035 {
3036         string initpath = lyxrc.document_path;
3037         LyXFileDlg fileDlg;
3038
3039         if (owner->view()->available()) {
3040                 string const trypath = owner->buffer()->filepath;
3041                 // If directory is writeable, use this as default.
3042                 if (IsDirWriteable(trypath) == 1)
3043                         initpath = trypath;
3044         }
3045
3046         static int newfile_number = 0;
3047         string s;
3048         
3049         if (lyxrc.new_ask_filename) {
3050                 ProhibitInput(owner->view());
3051                 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
3052                 fileDlg.SetButton(1, _("Templates"), lyxrc.template_path);
3053                 string fname = fileDlg.Select(_("Enter Filename for new document"), 
3054                                        initpath, "*.lyx", _("newfile"));
3055                 AllowInput(owner->view());
3056         
3057                 if (fname.empty()) {
3058                         owner->getMiniBuffer()->Set(_("Canceled."));
3059                         lyxerr.debug() << "New Document Cancelled." << endl;
3060                         return;
3061                 }
3062         
3063                 // get absolute path of file and make sure the filename ends
3064                 // with .lyx
3065                 s = MakeAbsPath(fname);
3066                 if (!IsLyXFilename(s))
3067                         s += ".lyx";
3068
3069                 // Check if the document already is open
3070                 if (bufferlist.exists(s)) {
3071                         switch (AskConfirmation(_("Document is already open:"), 
3072                                                MakeDisplayPath(s, 50),
3073                                                _("Do you want to close that document now?\n"
3074                                                  "('No' will just switch to the open version)")))
3075                         {
3076                         case 1: // Yes: close the document
3077                                 if (!bufferlist.close(bufferlist.getBuffer(s)))
3078                                 // If close is canceled, we cancel here too.
3079                                         return;
3080                                 break;
3081                         case 2: // No: switch to the open document
3082                                 owner->view()->buffer(bufferlist.getBuffer(s));
3083                                 return;
3084                         case 3: // Cancel: Do nothing
3085                                 owner->getMiniBuffer()->Set(_("Canceled."));
3086                                 return;
3087                         }
3088                 }
3089                 // Check whether the file already exists
3090                 if (IsLyXFilename(s)) {
3091                         FileInfo fi(s);
3092                         if (fi.readable() &&
3093                             AskQuestion(_("File already exists:"), 
3094                                         MakeDisplayPath(s, 50),
3095                                         _("Do you want to open the document?"))) {
3096                                 // loads document
3097                                 owner->getMiniBuffer()->Set(_("Opening document"), 
3098                                                             MakeDisplayPath(s), "...");
3099                                 XFlush(fl_get_display());
3100                                 owner->view()->buffer(
3101                                         bufferlist.loadLyXFile(s));
3102                                 owner->getMiniBuffer()->Set(_("Document"),
3103                                                             MakeDisplayPath(s),
3104                                                             _("opened."));
3105                                 return;
3106                         }
3107                 }
3108         } else {
3109                 s = AddName(lyxrc.document_path,
3110                             "newfile" + tostr(++newfile_number) + ".lyx");
3111                 FileInfo fi(s);
3112                 while (bufferlist.exists(s) || fi.readable()) {
3113                         ++newfile_number;
3114                         s = AddName(lyxrc.document_path,
3115                                     "newfile" + tostr(newfile_number) +
3116                                     ".lyx");
3117                         fi.newFile(s);
3118                 }
3119         }
3120
3121         // The template stuff
3122         string templname;
3123         if (fromTemplate) {
3124                 ProhibitInput(owner->view());
3125                 string const fname = fileDlg.Select(_("Choose template"),
3126                                                     lyxrc.template_path,
3127                                                     "*.lyx");
3128                 AllowInput(owner->view());
3129                 if (fname.empty()) return;
3130                 templname = fname;
3131         }
3132   
3133         // find a free buffer
3134         lyxerr.debug() << "Find a free buffer." << endl;
3135         owner->view()->buffer(bufferlist.newFile(s, templname));
3136 }
3137
3138
3139 void LyXFunc::MenuOpen()
3140 {
3141         string initpath = lyxrc.document_path;
3142         LyXFileDlg fileDlg;
3143   
3144         if (owner->view()->available()) {
3145                 string const trypath = owner->buffer()->filepath;
3146                 // If directory is writeable, use this as default.
3147                 if (IsDirWriteable(trypath) == 1)
3148                         initpath = trypath;
3149         }
3150
3151         // launches dialog
3152         ProhibitInput(owner->view());
3153         fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
3154         fileDlg.SetButton(1, _("Examples"), 
3155                           AddPath(system_lyxdir, "examples"));
3156         string filename = fileDlg.Select(_("Select Document to Open"),
3157                                          initpath, "*.lyx");
3158         AllowInput(owner->view());
3159  
3160         // check selected filename
3161         if (filename.empty()) {
3162                 owner->getMiniBuffer()->Set(_("Canceled."));
3163                 return;
3164         }
3165
3166         // get absolute path of file and make sure the filename ends
3167         // with .lyx
3168         filename = MakeAbsPath(filename);
3169         if (!IsLyXFilename(filename))
3170                 filename += ".lyx";
3171
3172         // loads document
3173         owner->getMiniBuffer()->Set(_("Opening document"),
3174                                     MakeDisplayPath(filename), "...");
3175         Buffer * openbuf = bufferlist.loadLyXFile(filename);
3176         if (openbuf) {
3177                 owner->view()->buffer(openbuf);
3178                 owner->getMiniBuffer()->Set(_("Document"),
3179                                             MakeDisplayPath(filename),
3180                                             _("opened."));
3181         } else {
3182                 owner->getMiniBuffer()->Set(_("Could not open document"),
3183                                             MakeDisplayPath(filename));
3184         }
3185 }
3186
3187
3188 // checks for running without gui are missing.
3189 void LyXFunc::doImport(string const & argument)
3190 {
3191         string format;
3192         string filename = split(argument, format, ' ');
3193         lyxerr.debug() << "LyXFunc::doImport: " << format 
3194                        << " file: " << filename << endl;
3195
3196         if (filename.empty()) { // need user interaction
3197                 string initpath = lyxrc.document_path;
3198                 LyXFileDlg fileDlg;
3199                 
3200                 if (owner->view()->available()) {
3201                         string const trypath = owner->buffer()->filepath;
3202                         // If directory is writeable, use this as default.
3203                         if (IsDirWriteable(trypath) == 1)
3204                                 initpath = trypath;
3205                 }
3206
3207                 // launches dialog
3208                 ProhibitInput(owner->view());
3209                 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
3210                 fileDlg.SetButton(1, _("Examples"), 
3211                                         AddPath(system_lyxdir, "examples"));
3212                 string const text = _("Select ") + formats.PrettyName(format)
3213                         + _(" file to import");
3214                 string const extension = "*." + formats.Extension(format);
3215                 filename = fileDlg.Select(text, initpath, extension);
3216                 AllowInput(owner->view());
3217  
3218                 // check selected filename
3219                 if (filename.empty()) 
3220                         owner->getMiniBuffer()->Set(_("Canceled."));
3221         }
3222
3223         // still no filename? abort
3224         if (filename.empty()) 
3225                 return;
3226
3227         // get absolute path of file
3228         filename = MakeAbsPath(filename);
3229
3230         string const lyxfile = ChangeExtension(filename, ".lyx");
3231
3232         // Check if the document already is open
3233         if (bufferlist.exists(lyxfile)) {
3234                 switch (AskConfirmation(_("Document is already open:"), 
3235                                        MakeDisplayPath(lyxfile, 50),
3236                                        _("Do you want to close that document now?\n"
3237                                          "('No' will just switch to the open version)")))
3238                         {
3239                         case 1: // Yes: close the document
3240                                 if (!bufferlist.close(bufferlist.getBuffer(lyxfile)))
3241                                 // If close is canceled, we cancel here too.
3242                                         return;
3243                                 break;
3244                         case 2: // No: switch to the open document
3245                                 owner->view()->buffer(bufferlist.getBuffer(lyxfile));
3246                                 return;
3247                         case 3: // Cancel: Do nothing
3248                                 owner->getMiniBuffer()->Set(_("Canceled."));
3249                                 return;
3250                         }
3251         }
3252
3253         // Check if a LyX document by the same root exists in filesystem
3254         FileInfo const f(lyxfile, true);
3255         if (f.exist() && !AskQuestion(_("A document by the name"), 
3256                                       MakeDisplayPath(lyxfile),
3257                                       _("already exists. Overwrite?"))) {
3258                 owner->getMiniBuffer()->Set(_("Canceled."));
3259                 return;
3260         }
3261         // filename should be valid now
3262
3263         Importer::Import(owner, filename, format);
3264 }
3265
3266
3267 void LyXFunc::MenuInsertLyXFile(string const & filen)
3268 {
3269         string filename = filen;
3270
3271         if (filename.empty()) {
3272                 // Launch a file browser
3273                 string initpath = lyxrc.document_path;
3274                 LyXFileDlg fileDlg;
3275
3276                 if (owner->view()->available()) {
3277                         string const trypath = owner->buffer()->filepath;
3278                         // If directory is writeable, use this as default.
3279                         if (IsDirWriteable(trypath) == 1)
3280                                 initpath = trypath;
3281                 }
3282
3283                 // launches dialog
3284                 ProhibitInput(owner->view());
3285                 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
3286                 fileDlg.SetButton(1, _("Examples"), 
3287                                   AddPath(system_lyxdir, "examples"));
3288                 filename = fileDlg.Select(_("Select Document to Insert"),
3289                                           initpath, "*.lyx");
3290                 AllowInput(owner->view());
3291
3292                 // check selected filename
3293                 if (filename.empty()) {
3294                         owner->getMiniBuffer()->Set(_("Canceled."));
3295                         return;
3296                 }
3297         } 
3298
3299         // get absolute path of file and make sure the filename ends
3300         // with .lyx
3301         filename = MakeAbsPath(filename);
3302         if (!IsLyXFilename(filename))
3303                 filename += ".lyx";
3304
3305         // Inserts document
3306         owner->getMiniBuffer()->Set(_("Inserting document"),
3307                                     MakeDisplayPath(filename), "...");
3308         bool const res = owner->view()->insertLyXFile(filename);
3309         if (res) {
3310                 owner->getMiniBuffer()->Set(_("Document"),
3311                                             MakeDisplayPath(filename),
3312                                             _("inserted."));
3313         } else {
3314                 owner->getMiniBuffer()->Set(_("Could not insert document"),
3315                                             MakeDisplayPath(filename));
3316         }
3317 }
3318
3319
3320 void LyXFunc::reloadBuffer()
3321 {
3322         string const fn = owner->buffer()->fileName();
3323         if (bufferlist.close(owner->buffer()))
3324                 owner->view()->buffer(bufferlist.loadLyXFile(fn));
3325 }
3326
3327
3328 void LyXFunc::CloseBuffer()
3329 {
3330         if (bufferlist.close(owner->buffer()) && !quitting) {
3331                 if (bufferlist.empty()) {
3332                         // need this otherwise SEGV may occur while trying to
3333                         // set variables that don't exist
3334                         // since there's no current buffer
3335                         owner->getDialogs()->hideBufferDependent();
3336                 } else {
3337                         owner->view()->buffer(bufferlist.first());
3338                 }
3339         }
3340 }
3341
3342
3343 Inset * LyXFunc::getInsetByCode(Inset::Code code)
3344 {
3345         LyXCursor cursor = TEXT()->cursor;
3346         Buffer * buffer = owner->view()->buffer();
3347         Buffer::inset_iterator it =
3348                 find_if(Buffer::inset_iterator(cursor.par(),
3349                                                cursor.pos()),
3350                         buffer->inset_iterator_end(),
3351                         compare_memfun(&Inset::LyxCode, code));
3352         return it != buffer->inset_iterator_end() ? (*it) : 0;
3353 }
3354
3355
3356 // Each "owner" should have it's own message method. lyxview and
3357 // the minibuffer would use the minibuffer, but lyxserver would
3358 // send an ERROR signal to its client.  Alejandro 970603
3359 // This func is bit problematic when it comes to NLS, to make the
3360 // lyx servers client be language indepenent we must not translate
3361 // strings sent to this func.
3362 void LyXFunc::setErrorMessage(string const & m) const
3363 {
3364         dispatch_buffer = m;
3365         errorstat = true;
3366 }
3367
3368
3369 void LyXFunc::setMessage(string const & m)
3370 {
3371         dispatch_buffer = m;
3372 }