]> git.lyx.org Git - features.git/blob - src/lyxfunc.C
Small fix for a purify report; update of fr.po
[features.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-1999 The LyX Team.
8  *
9  * ====================================================== */
10
11 #include <config.h>
12
13 #include <cstdlib>
14 #include <cctype>
15 #include <cstring>
16
17 #ifdef __GNUG__
18 #pragma implementation
19 #endif
20
21 #include "lyxlookup.h"
22 #include "kbmap.h"
23 #include "lyxfunc.h"
24 #include "bufferlist.h"
25 #include "lyxserver.h"
26 #include "lyx.h"
27 #include "intl.h"
28 #include "lyx_main.h"
29 #include "lyx_cb.h"
30 #include "LyXAction.h"
31 #if 0
32 #include "insets/insetlatex.h"
33 #endif
34 #include "insets/inseturl.h"
35 #include "insets/insetlatexaccent.h"
36 #include "insets/insettoc.h"
37 #include "insets/insetlof.h"
38 #include "insets/insetloa.h"
39 #include "insets/insetlot.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 "mathed/formulamacro.h"
46 #include "toolbar.h"
47 #include "spellchecker.h" // RVDK_PATCH_5
48 #include "minibuffer.h"
49 #include "vspace.h"
50 #include "LyXView.h"
51 #include "filedlg.h"
52 #include "lyx_gui_misc.h"
53 #include "support/filetools.h"
54 #include "support/FileInfo.h"
55 #include "support/syscall.h"
56 #include "support/lstrings.h"
57 #include "support/path.h"
58 #include "lyxscreen.h"
59 #include "debug.h"
60 #include "lyxrc.h"
61 #include "lyxtext.h"
62 #include "gettext.h"
63 #include "trans_mgr.h"
64 #include "ImportLaTeX.h"
65 #include "ImportNoweb.h"
66 #include "layout.h"
67
68 extern bool cursor_follows_scrollbar;
69
70 extern void InsertAsciiFile(string const &, bool);
71 extern void math_insert_symbol(char const *);
72 extern Bool math_insert_greek(char const); // why "Bool"?
73 extern BufferList bufferlist;
74 extern LyXServer * lyxserver;
75 extern short greek_kb_flag;
76 extern FD_form_toc * fd_form_toc;
77 extern bool selection_possible;
78
79 extern kb_keymap * toplevel_keymap;
80
81 extern void MenuWrite(Buffer *);
82 extern void MenuWriteAs(Buffer *);
83 extern int  MenuRunLaTeX(Buffer *);
84 extern int  MenuBuildProg(Buffer *);
85 extern int  MenuRunChktex(Buffer *);
86 extern bool CreatePostscript(Buffer *, bool);
87 extern void MenuPrint(Buffer *);
88 extern void MenuSendto();
89 extern void QuitLyX();
90 extern void MenuFax(Buffer *);
91 extern void MenuExport(Buffer *, string const &);
92 extern void MenuPasteSelection(char at);
93 extern LyXAction lyxaction;
94 // (alkis)
95 extern tex_accent_struct get_accent(kb_action action);
96
97 extern void AutoSave();
98 extern void MenuSearch();
99 extern void SetUpdateTimer(float timer = 0.3);
100 extern void FreeUpdateTimer();
101 extern bool PreviewDVI(Buffer *);
102 extern bool PreviewPostscript(Buffer *);
103 extern void MenuInsertLabel(char const *);
104 extern void MenuInsertRef();
105 extern void MenuLayoutCharacter();
106 extern void MenuLayoutParagraph();
107 extern void MenuLayoutDocument();
108 extern void MenuLayoutPaper();
109 extern void MenuLayoutTable(int flag);
110 extern void MenuLayoutQuotes();
111 extern void MenuLayoutPreamble();
112 extern void MenuLayoutSave();
113 extern void bulletForm();
114
115 extern Buffer * NewLyxFile(string const &);
116 extern void LoadLyXFile(string const &);
117 extern void Reconfigure();
118
119 extern int current_layout;
120 extern int getISOCodeFromLaTeX(char *);
121
122 //extern int UnlockInset(UpdatableInset *);
123
124 extern void ShowLatexLog();
125
126 extern void UpdateInset(Inset * inset, bool mark_dirty = true);
127
128 /* === globals =========================================================== */
129
130 bool LyXFunc::show_sc = true;
131
132
133 LyXFunc::LyXFunc(LyXView * o)
134         : owner(o)
135 {
136         meta_fake_bit = 0;
137         lyx_dead_action = LFUN_NOACTION;
138         lyx_calling_dead_action = LFUN_NOACTION;
139         setupLocalKeymap();
140 }
141
142
143 // I changed this func slightly. I commented out the ...FinishUndo(),
144 // this means that all places that used to have a moveCursorUpdate, now
145 // have a ...FinishUndo() as the preceeding statement. I have also added
146 // a moveCursorUpdate to some of the functions that updated the cursor, but
147 // that did not show its new position.
148 inline
149 void LyXFunc::moveCursorUpdate(bool selecting)
150 {
151         if (selecting || owner->view()->text->mark_set) {
152                 owner->view()->text->SetSelection();
153                 owner->view()->getScreen()->ToggleToggle();
154                 owner->view()->update(0);
155         } else {
156                 owner->view()->update(-2); // this IS necessary
157                 // (Matthias) 
158         }
159
160         owner->view()->getScreen()->ShowCursor();
161         
162         /* ---> Everytime the cursor is moved, show the current font state. */
163         // should this too me moved out of this func?
164         //owner->getMiniBuffer()->Set(CurrentState());
165 }
166
167
168 int LyXFunc::processKeyEvent(XEvent * ev)
169 {
170         char s_r[10];
171         string argument;
172         XKeyEvent * keyevent = &ev->xkey;
173         KeySym keysym_return;
174
175         int num_bytes = LyXLookupString(ev, s_r, 10, &keysym_return);
176         s_r[num_bytes] = '\0';
177
178         if (lyxerr.debugging(Debug::KEY)) {
179                 char * tmp = XKeysymToString(keysym_return);
180                 string stm = (tmp ? tmp : "");
181                 lyxerr << "KeySym is "
182                        << stm
183                        << "["
184                        << keysym_return << "]"
185                        << " and num_bytes is "
186                        << num_bytes
187                        << " the string returned is \""
188                        << s_r << '\"' << endl;
189         }
190         // Do nothing if we have nothing (JMarc)
191         if (num_bytes == 0 && keysym_return == NoSymbol) {
192                 lyxerr[Debug::KEY] << "Empty kbd action (probably composing)"
193                                    << endl;
194                 return 0;
195         }
196         
197         // this function should be used always [asierra060396]
198         if (owner->view()->available() &&
199             owner->view()->the_locking_inset &&
200             keysym_return == XK_Escape) {
201                 owner->view()->unlockInset(owner->view()->the_locking_inset);
202                 owner->view()->text->CursorRight();
203                 return 0;
204         }
205
206         // Can we be sure that this will work for all X-Windows
207         // implementations? (Lgb)
208         // This code snippet makes lyx ignore some keys. Perhaps
209         // all of them should be explictly mentioned?
210         if((keysym_return >= XK_Shift_L && keysym_return <= XK_Hyper_R)
211            || keysym_return == XK_Mode_switch || keysym_return == 0x0)
212                 return 0;
213
214         // Do a one-deep top-level lookup for
215         // cancel and meta-fake keys. RVDK_PATCH_5
216         cancel_meta_seq.reset();
217
218         int action = cancel_meta_seq.addkey(keysym_return, keyevent->state
219                                             &(ShiftMask|ControlMask
220                                               |Mod1Mask)); 
221
222         // When not cancel or meta-fake, do the normal lookup. 
223         // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
224         // Mostly, meta_fake_bit = 0. RVDK_PATCH_5.
225         if ( (action != LFUN_CANCEL) && (action != LFUN_META_FAKE) ) {
226
227                 // remove Caps Lock and Mod2 as a modifiers
228                 action = keyseq.addkey(keysym_return,
229                                        (keyevent->state | meta_fake_bit)
230                                        &(ShiftMask|ControlMask
231                                          |Mod1Mask));      
232         }
233         // Dont remove this unless you know what you are doing.
234         meta_fake_bit = 0;
235                 
236         if (action == 0) action = LFUN_PREFIX;
237
238         if (lyxerr.debugging(Debug::KEY)) {
239                 string buf;
240                 keyseq.print(buf);
241                 lyxerr << "Key ["
242                        << action << "]["
243                        << buf << "]["
244                        << num_bytes << "]" << endl;
245         }
246
247         // already here we know if it any point in going further
248         // why not return already here if action == -1 and
249         // num_bytes == 0? (Lgb)
250
251         if(keyseq.length > 1 || keyseq.length < -1){
252                 string buf;
253                 keyseq.print(buf);
254                 owner->getMiniBuffer()->Set(buf);
255         }
256
257         if (action == -1) {
258                 if (keyseq.length < -1) { // unknown key sequence...
259                         string buf;
260                         LyXBell();
261                         keyseq.print(buf);
262                         owner->getMiniBuffer()->Set(_("Unknown sequence:"), buf);
263                         return 0;
264                 }
265         
266                 char isochar = keyseq.getiso();
267                 if (!(keyevent->state&ControlMask) &&
268                     !(keyevent->state&Mod1Mask) &&
269                     (isochar && keysym_return < 0xF000)) {
270                         argument += isochar;
271                 }
272                 if (argument.empty()) {
273                         lyxerr.debug() << "Empty argument!" << endl;
274                         // This can`t possibly be of any use
275                         // so we`ll skip the dispatch.
276                         return 0;
277                 }
278         } else
279                 if (action == LFUN_SELFINSERT) {
280                         argument = s_r[0];
281                 }
282     
283         bool tmp_sc = show_sc;
284         show_sc = false;
285         Dispatch(action, argument.c_str());
286         show_sc = tmp_sc;
287         
288         return 0;
289
290
291
292 LyXFunc::func_status LyXFunc::getStatus(int ac) const
293 {
294         kb_action action;
295         func_status flag = LyXFunc::OK;
296         string argument;
297         Buffer * buf = owner->buffer();
298         
299         if (lyxaction.isPseudoAction(ac)) 
300                 action = lyxaction.retrieveActionArg(ac, argument);
301         else 
302                 action = static_cast<kb_action>(ac);
303         
304         if (action == LFUN_UNKNOWN_ACTION) {
305                 setErrorMessage(N_("Unknown action"));
306                 return LyXFunc::Unknown;
307         } 
308         
309         // Check whether we need a buffer
310         if (!lyxaction.funcHasFlag(action, LyXAction::NoBuffer)) {
311                 // Yes we need a buffer, do we have one?
312                 if (buf) {
313                         // yes
314                         // Can we use a readonly buffer?
315                         if (buf->isReadonly() && 
316                             !lyxaction.funcHasFlag(action,
317                                                    LyXAction::ReadOnly)) {
318                                 // no
319                                 setErrorMessage(N_("Document is read-only"));
320                                 flag |= LyXFunc::Disabled;
321                         }
322                 } else {
323                         // no
324                         setErrorMessage(N_("Command not allowed with"
325                                            "out any document open"));
326                         flag |= LyXFunc::Disabled;
327                 }
328         }
329
330         if (flag & LyXFunc::Disabled)
331                 return flag;
332
333         // I would really like to avoid having this switch and rather try to
334         // encode this in the function itself.
335         static bool noLaTeX = lyxrc->latex_command == "none";
336         bool disable = false;
337         switch (action) {
338         case LFUN_PREVIEW:
339                 disable = noLaTeX || lyxrc->view_dvi_command == "none";
340                 break;  
341         case LFUN_PREVIEWPS: 
342                 disable = noLaTeX || lyxrc->view_ps_command == "none";
343                 break;
344         case LFUN_RUNLATEX:
345         case LFUN_RUNDVIPS:
346                 disable = noLaTeX;
347                 break;
348         case LFUN_MENUPRINT:
349                 disable = noLaTeX || lyxrc->print_command == "none";
350                 break;
351         case LFUN_FAX:
352                 disable = noLaTeX || lyxrc->fax_command == "none"; 
353                 break;
354         case LFUN_IMPORT:
355                 if (argument == "latex")
356                         disable = lyxrc->relyx_command == "none";
357                 break;
358         case LFUN_EXPORT:
359                 if (argument == "dvi" || argument == "postscript")
360                         disable = noLaTeX;
361                 if (argument == "html")
362                         disable = lyxrc->html_command == "none";
363                 break;
364         case LFUN_UNDO:
365                 disable = buf->undostack.empty();
366                 break;
367         case LFUN_REDO:
368                 disable = buf->redostack.empty();
369                 break;
370         case LFUN_SPELLCHECK:
371                 disable = lyxrc->isp_command == "none";
372                 break;
373         case LFUN_RUNCHKTEX:
374                 disable = lyxrc->chktex_command == "none";
375                 break;
376         case LFUN_LAYOUT_TABLE:
377                 disable = ! owner->view()->text->cursor.par->table;
378                 break;
379         default:
380                 break;
381         }
382         if (disable)
383                 flag |= LyXFunc::Disabled;
384
385         if (buf) {
386                 func_status box = LyXFunc::ToggleOff;
387                 LyXFont font = owner->view()->text->real_current_font;
388                 switch (action) {
389                 case LFUN_EMPH:
390                         if (font.emph() == LyXFont::ON)
391                                 box = LyXFunc::ToggleOn;
392                         break;
393                 case LFUN_NOUN:
394                         if (font.noun() == LyXFont::ON)
395                                 box = LyXFunc::ToggleOn;
396                         break;
397                 case LFUN_BOLD:
398                         if (font.series() == LyXFont::BOLD_SERIES)
399                                 box = LyXFunc::ToggleOn;
400                         break;
401                 case LFUN_TEX:
402                         if (font.latex() == LyXFont::ON)
403                                 box = LyXFunc::ToggleOn;
404                         break;
405                 default:
406                         box = LyXFunc::OK;
407                         break;
408                 }
409                 flag |= box;
410         }
411
412         return flag;
413 }
414
415
416 string LyXFunc::Dispatch(string const & s) 
417 {
418         // Split command string into command and argument
419         string cmd, line = frontStrip(s);
420         string arg = strip(frontStrip(split(line, cmd, ' ')));
421
422         return Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
423 }
424
425
426 string LyXFunc::Dispatch(int ac,
427                          char const * do_not_use_this_arg)
428 {
429         string argument;
430         kb_action action;
431         
432         FL_OBJECT * ob = 0;  // This will disapear soon
433     
434         // we have not done anything wrong yet.
435         errorstat = false;
436         dispatch_buffer.clear();
437         
438         // if action is a pseudo-action, we need the real action
439         if (lyxaction.isPseudoAction(ac)) {
440                 string tmparg;
441                 action = static_cast<kb_action>
442                         (lyxaction.retrieveActionArg(ac, tmparg));
443                 if (!tmparg.empty())
444                         argument = tmparg;
445         } else {
446                 action = static_cast<kb_action>(ac);
447                 if (do_not_use_this_arg)
448                         argument = do_not_use_this_arg; // except here
449         }
450     
451         selection_possible = false;
452         
453         if (owner->view()->available() 
454             && owner->view()->getScreen())
455                 owner->view()->getScreen()->HideCursor();
456
457         // We cannot use this function here
458         if (getStatus(action) & Disabled)
459                 goto exit_with_message;
460
461         commandshortcut.clear();
462         
463         if (lyxrc->display_shortcuts && show_sc) {
464                 if (action != LFUN_SELFINSERT) {
465                         // Put name of command and list of shortcuts
466                         // for it in minibuffer
467                         string comname = lyxaction.getActionName(action);
468
469                         int pseudoaction = action;
470                         bool argsadded = false;
471
472                         if (!argument.empty()) {
473                                 // If we have the command with argument, 
474                                 // this is better
475                                 pseudoaction = 
476                                         lyxaction.searchActionArg(action,
477                                                                   argument.c_str());
478
479                                 if (pseudoaction == -1) {
480                                         pseudoaction = action;
481                                 } else {
482                                         comname += " " + argument;
483                                         argsadded = true;
484                                 }
485                         }
486
487                         string shortcuts = toplevel_keymap->findbinding(pseudoaction);
488
489                         if (!shortcuts.empty()) {
490                                 comname += ": " + shortcuts;
491                         } else if (!argsadded) {
492                                 comname += " " + argument;
493                         }
494
495                         if (!comname.empty()) {
496                                 comname = strip(comname);
497                                 commandshortcut = "(" + comname + ')';
498                                 owner->getMiniBuffer()->Set(commandshortcut);
499                                 // Here we could even add a small pause,
500                                 // to annoy the user and make him learn
501                                 // the shortcuts.
502                                 // No! That will just annoy, not teach
503                                 // anything. The user will read the messages
504                                 // if they are interested. (Asger)
505                         }
506                 }
507         }
508
509         // If in math mode pass the control to
510         // the math inset [asierra060396]
511         if (owner->view()->available() &&
512             owner->view()->the_locking_inset) {
513                 if (action > 1
514                     || (action == LFUN_UNKNOWN_ACTION
515                         && keyseq.length >= -1)) {
516                         if (action == LFUN_UNKNOWN_ACTION
517                             && argument.empty()) {
518                                 argument = keyseq.getiso();
519                         }
520                         // Undo/Redo pre 0.13 is a bit tricky for insets.
521                         if (action == LFUN_UNDO) {
522                                 int slx, sly;
523                                 UpdatableInset * inset = 
524                                         owner->view()->the_locking_inset;
525                                 inset->GetCursorPos(slx, sly);
526                                 owner->view()->unlockInset(inset);
527                                 owner->view()->menuUndo();
528                                 inset = static_cast<UpdatableInset*>(owner->view()->text->cursor.par->GetInset(owner->view()->text->cursor.pos));
529                                 if (inset) 
530                                         inset->Edit(slx, sly);
531                                 return string();
532                         } else 
533                                 if (action == LFUN_REDO) {
534                                         int slx, sly;
535                                         UpdatableInset * inset = owner->view()->the_locking_inset;
536                                         inset->GetCursorPos(slx, sly);
537                                         owner->view()->unlockInset(inset);
538                                         owner->view()->menuRedo();
539                                         inset = static_cast<UpdatableInset*>(owner->view()->text->cursor.par->GetInset(owner->view()->text->cursor.pos));
540                                         if (inset)
541                                                 inset->Edit(slx, sly);
542                                         return string();
543                                 } else
544                                         if (owner->view()->the_locking_inset->LocalDispatch(action, argument.c_str()))
545                                                 return string();
546                                         else {
547                                                 setMessage(N_("Text mode"));
548                                                 if (action == LFUN_RIGHT || action == -1)
549                                                         owner->view()->text->CursorRight();
550                                                 if (action == LFUN_LEFT || action == LFUN_RIGHT)
551                                                         return string();
552                                         }
553                 }
554         }
555
556         switch(action) {
557                 // --- Misc -------------------------------------------
558         case LFUN_WORDFINDFORWARD  : 
559         case LFUN_WORDFINDBACKWARD : {
560                 static string last_search;
561                 string searched_string;
562             
563                 if (!argument.empty()) {
564                         last_search = argument;
565                         searched_string = argument;
566                 } else {
567                         searched_string = last_search;
568                 }
569
570                 LyXText * ltCur = owner->view()->text ;
571
572                 if (!searched_string.empty() &&
573                     ((action == LFUN_WORDFINDBACKWARD) ? 
574                      ltCur->SearchBackward(searched_string.c_str()) :
575                      ltCur->SearchForward(searched_string.c_str()))) {
576
577                         // ??? What is that ???
578                         owner->view()->update(-2);
579
580                         // ??? Needed ???
581                         // clear the selection (if there is any) 
582                         owner->view()->getScreen()->ToggleSelection();
583                         owner->view()->text->ClearSelection();
584
585                         // Move cursor so that successive C-s 's will not stand in place. 
586                         if( action == LFUN_WORDFINDFORWARD ) 
587                                 owner->view()->text->CursorRightOneWord();
588                         owner->view()->text->FinishUndo();
589                         moveCursorUpdate(false);
590
591                         // ??? Needed ???
592                         // set the new selection 
593                         // SetSelectionOverLenChars(owner->view()->currentBuffer()->text, iLenSelected);
594                         owner->view()->getScreen()->ToggleSelection(false);
595                 } else 
596                         LyXBell();      
597          
598                 // REMOVED : if (owner->view()->getWorkArea()->focus)
599                 owner->view()->getScreen()->ShowCursor();
600         }
601         break;
602
603         case LFUN_PREFIX:
604         {
605                 if (owner->view()->available()
606                     && owner->view()->getScreen()) {
607                         owner->view()->update(-2);
608                 }
609                 string buf;
610                 keyseq.print(buf, true);
611                 owner->getMiniBuffer()->Set(buf, string(), string(), 1);
612         }
613         break;
614
615         // --- Misc -------------------------------------------
616         case LFUN_EXEC_COMMAND:
617                 owner->getMiniBuffer()->ExecCommand(); 
618                 break;
619                 
620         case LFUN_CANCEL:                   // RVDK_PATCH_5
621                 keyseq.reset();
622                 meta_fake_bit = 0;
623                 if(owner->view()->available())
624                         // cancel any selection
625                         Dispatch(LFUN_MARK_OFF, 0);
626                 setMessage(N_("Cancel"));
627                 break;
628
629         case LFUN_META_FAKE:                                 // RVDK_PATCH_5
630         {
631                 meta_fake_bit = Mod1Mask;
632                 string buf;
633                 keyseq.print(buf, true);
634                 string res = string("M-") + buf;
635                 setMessage(buf); // RVDK_PATCH_5
636         }
637         break;  
638
639         case LFUN_READ_ONLY_TOGGLE:
640                 if (owner->buffer()->lyxvc.inUse()) {
641                         owner->buffer()->lyxvc.toggleReadOnly();
642                 } else {
643                         owner->buffer()->setReadonly(
644                                 !owner->buffer()->isReadonly());
645                 }
646                 break;
647                 
648         case LFUN_CENTER: // this is center and redraw.
649                 owner->view()->beforeChange();
650                 if (owner->view()->text->cursor.y >
651                     owner->view()->getWorkArea()->h / 2)        {
652                         owner->view()->getScreen()->
653                                 Draw(owner->view()->text->cursor.y -
654                                      owner->view()->getWorkArea()->h / 2);
655                 } else { // <= 
656                         owner->view()->getScreen()->
657                                 Draw(0);
658                 }
659                 owner->view()->update(0);
660                 owner->view()->redraw();
661                 break;
662                 
663         case LFUN_APPENDIX:
664                 if (owner->view()->available()) {
665                         owner->view()->text->toggleAppendix();
666                         owner->view()->update(1);
667                 }
668                 break;
669
670                 // --- Menus -----------------------------------------------
671         case LFUN_MENUNEW:
672                 MenuNew(false);
673                 break;
674                 
675         case LFUN_MENUNEWTMPLT:
676                 MenuNew(true);
677                 break;
678                 
679         case LFUN_MENUOPEN:
680                 MenuOpen();
681                 break;
682                 
683         case LFUN_CLOSEBUFFER:
684                 CloseBuffer();
685                 break;
686                 
687         case LFUN_MENUWRITE:
688                 MenuWrite(owner->buffer());
689                 break;
690                 
691         case LFUN_MENUWRITEAS:
692                 MenuWriteAs(owner->buffer());
693                 break;
694                 
695         case LFUN_MENURELOAD:
696                 reloadBuffer();
697                 break;
698                 
699         case LFUN_PREVIEW:
700                 PreviewDVI(owner->buffer());
701                 break;
702                         
703         case LFUN_PREVIEWPS:
704                 PreviewPostscript(owner->buffer());
705                 break;
706                 
707         case LFUN_RUNLATEX:
708                 MenuRunLaTeX(owner->buffer());
709                 break;
710                 
711         case LFUN_BUILDPROG:
712                 MenuBuildProg(owner->buffer());
713                 break;
714                 
715         case LFUN_RUNCHKTEX:
716                 MenuRunChktex(owner->buffer());
717                 break;
718                 
719         case LFUN_RUNDVIPS:
720                 CreatePostscript(owner->buffer(), false);
721                 break;
722                 
723         case LFUN_MENUPRINT:
724                 MenuPrint(owner->buffer());
725                 break;
726                 
727         case LFUN_FAX:
728                 MenuFax(owner->buffer());
729                 break;
730                         
731         case LFUN_EXPORT:
732                 MenuExport(owner->buffer(), argument);
733                 break;
734
735         case LFUN_IMPORT:
736         {
737                 //needs argument as string
738                 string imtyp = argument;
739                 
740                 // latex
741                 if (imtyp == "latex") {
742                         doImportLaTeX(false);
743                 }
744                 // ascii
745                 else if (imtyp == "ascii") {
746                         doImportASCII(false);
747                 } else if (imtyp == "asciiparagraph") {
748                         doImportASCII(true);
749                         // noweb
750                 } else if (imtyp == "noweb") {
751                         doImportLaTeX(true);
752                 } else {
753                         setErrorMessage(string(N_("Unknown import type: "))
754                                         + imtyp);
755                 }
756                 break;
757         }
758                 
759         case LFUN_QUIT:
760                 QuitLyX();
761                 break;
762                 
763         case LFUN_TOCVIEW:
764                 TocUpdateCB(ob, 0);
765                 if (fd_form_toc->form_toc->visible) {
766                         fl_raise_form(fd_form_toc->form_toc);
767                 } else {
768                         static int ow = -1, oh;
769                         fl_show_form(fd_form_toc->form_toc,
770                                      FL_PLACE_MOUSE |
771                                      FL_FREE_SIZE, FL_FULLBORDER,
772                                      _("Table of Contents"));
773                         if (ow < 0) {
774                                 ow = fd_form_toc->form_toc->w;
775                                 oh = fd_form_toc->form_toc->h;
776                         }
777                         fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
778                 }
779                 break;
780                 
781         case LFUN_TOC_INSERT:
782         {
783                 Inset * new_inset = new InsetTOC(owner->buffer());
784                 owner->view()->insertInset(new_inset, "Standard", true);
785                 break;
786         }
787         
788         case LFUN_LOF_INSERT:
789         {
790                 Inset * new_inset = new InsetLOF(owner->buffer());
791                 owner->view()->insertInset(new_inset, "Standard", true);
792                 break;
793         }
794         
795         case LFUN_LOA_INSERT:
796         {
797                 Inset * new_inset = new InsetLOA(owner->buffer());
798                 owner->view()->insertInset(new_inset, "Standard", true);
799                 break;
800         }
801
802         case LFUN_LOT_INSERT:
803         {
804                 Inset * new_inset = new InsetLOT(owner->buffer());
805                 owner->view()->insertInset(new_inset, "Standard", true);
806                 break;
807         }
808                 
809         case LFUN_TABLE:
810                 TableCB(ob, 0);
811                 break;
812                 
813         case LFUN_FIGURE:
814                 FigureCB(ob, 0);
815                 break;
816                 
817         case LFUN_AUTOSAVE:
818                 AutoSave();
819                 break;
820                 
821         case LFUN_UNDO:
822                 owner->view()->menuUndo();
823                 break;
824                 
825         case LFUN_REDO:
826                 owner->view()->menuRedo();
827                 break;
828                 
829         case LFUN_MENUSEARCH:
830                 MenuSearch();
831                 break;
832                 
833         case LFUN_PASTE:
834                 owner->view()->paste();
835                 break;
836                 
837         case LFUN_PASTESELECTION:
838         {
839                 bool asPara = false;
840                 if (argument == "paragraph") asPara = true;
841                 MenuPasteSelection(asPara);
842                 break;
843         }
844
845         case LFUN_CUT:
846                 owner->view()->cut();
847                 break;
848                 
849         case LFUN_COPY:
850                 owner->view()->copy();
851                 break;
852                 
853         case LFUN_LAYOUT_COPY:
854                 owner->view()->copyEnvironment();
855                 break;
856                 
857         case LFUN_LAYOUT_PASTE:
858                 owner->view()->pasteEnvironment();
859                 break;
860                 
861         case LFUN_GOTOERROR:
862                 owner->view()->gotoError();
863                 break;
864                 
865         case LFUN_REMOVEERRORS:
866                 if (owner->view()->removeAutoInsets()) {
867                         owner->view()->redraw();
868                         owner->view()->fitCursor();
869                         owner->view()->updateScrollbar();
870                 }
871                 break;
872                 
873         case LFUN_GOTONOTE:
874                 owner->view()->gotoNote();
875                 break;
876                 
877         case LFUN_OPENSTUFF:
878                 owner->view()->openStuff();
879                 break;
880                 
881         case LFUN_HYPHENATION:
882                 owner->view()->hyphenationPoint();
883                 break;
884                 
885         case LFUN_LDOTS:
886                 owner->view()->ldots();
887                 break;
888                 
889         case LFUN_END_OF_SENTENCE:
890                 owner->view()->endOfSentenceDot();
891                 break;
892
893         case LFUN_MENU_SEPARATOR:
894                 owner->view()->menuSeparator();
895                 break;
896                 
897         case LFUN_HFILL:
898                 owner->view()->hfill();
899                 break;
900                 
901         case LFUN_DEPTH:
902                 DepthCB(ob, 0);
903                 break;
904                 
905         case LFUN_DEPTH_MIN:
906                 DepthCB(ob, -1);
907                 break;
908                 
909         case LFUN_DEPTH_PLUS:
910                 DepthCB(ob, 1);
911                 break;
912                 
913         case LFUN_FREE:
914                 FreeCB();
915                 break;
916                 
917         case LFUN_TEX:
918                 TexCB();
919                 break;
920                 
921         case LFUN_MELT:
922                 MeltCB(ob, 0);
923                 break;
924                 
925         case LFUN_RECONFIGURE:
926                 Reconfigure();
927                 break;
928
929         case LFUN_FOOTMELT:
930                 if (owner->view()->available()
931                     && !owner->view()->text->selection
932                     && owner->view()->text->cursor.par->footnoteflag
933                     != LyXParagraph::NO_FOOTNOTE)
934                         { // only melt footnotes with FOOTMELT, not margins etc
935                                 if(owner->view()->text->cursor.par->footnotekind == LyXParagraph::FOOTNOTE)
936                                         MeltCB(ob, 0);
937                         }
938                 else
939                         FootCB(ob, 0); 
940                 break;
941
942         case LFUN_MARGINMELT:
943                 if (owner->view()->available()
944                     && !owner->view()->text->selection
945                     && owner->view()->text->cursor.par->footnoteflag
946                     != LyXParagraph::NO_FOOTNOTE) {
947                         // only melt margins
948                         if(owner->view()->text->cursor.par->footnotekind == LyXParagraph::MARGIN)
949                                 MeltCB(ob, 0);
950                 }
951                 else
952                         MarginCB(ob, 0); 
953                 break;
954                 
955                 // --- version control -------------------------------
956         case LFUN_VC_REGISTER:
957         {
958                 if (!owner->buffer()->lyxvc.inUse())
959                         owner->buffer()->lyxvc.registrer();
960         }
961         break;
962                 
963         case LFUN_VC_CHECKIN:
964         {
965                 if (owner->buffer()->lyxvc.inUse()
966                     && !owner->buffer()->isReadonly())
967                         owner->buffer()->lyxvc.checkIn();
968         }
969         break;
970                 
971         case LFUN_VC_CHECKOUT:
972         {
973                 if (owner->buffer()->lyxvc.inUse()
974                     && owner->buffer()->isReadonly())
975                         owner->buffer()->lyxvc.checkOut();
976         }
977         break;
978         
979         case LFUN_VC_REVERT:
980         {
981                 owner->buffer()->lyxvc.revert();
982         }
983         break;
984                 
985         case LFUN_VC_UNDO:
986         {
987                 owner->buffer()->lyxvc.undoLast();
988         }
989         break;
990                 
991         case LFUN_VC_HISTORY:
992         {
993                 owner->buffer()->lyxvc.showLog();
994                 break;
995         }
996         
997         // --- buffers ----------------------------------------
998         case LFUN_PREVBUFFER:
999 #ifdef WITH_WARNINGS
1000 #warning fix this please
1001 #endif
1002                 // it is the LyXView or the BufferView that should
1003                 // remember the previous buffer, not bufferlist.
1004 //                      if (owner->view()->available()){          
1005 //                              owner->view()->beforeChange();
1006 //                              owner->buffer()->update(-2);
1007 //                      }
1008 //                      owner->view()->setBuffer(bufferlist.prev());
1009
1010 //                      owner->view()->
1011 //                              resizeCurrentBufferPseudoExpose();
1012                 break;
1013                         
1014         case LFUN_FILE_INSERT:
1015         {
1016                 MenuInsertLyXFile(argument);
1017         }
1018         break;
1019         
1020         case LFUN_FILE_INSERT_ASCII:
1021         {
1022                 bool asPara = (argument == "paragraph");
1023                 InsertAsciiFile(string(), asPara);
1024         }
1025         break;
1026         
1027         case LFUN_FILE_NEW:
1028         {
1029                 // servercmd: argument must be <file>:<template>
1030                 Buffer * tmpbuf = NewLyxFile(argument);
1031                 if (tmpbuf)
1032                         owner->view()->buffer(tmpbuf);
1033         }
1034         break;
1035                         
1036         case LFUN_FILE_OPEN:
1037                 owner->view()->buffer(bufferlist.loadLyXFile(argument));
1038                 break;
1039
1040         case LFUN_LATEX_LOG:
1041                 ShowLatexLog();
1042                 break;
1043                 
1044         case LFUN_LAYOUTNO:
1045         {
1046                 lyxerr.debug() << "LFUN_LAYOUTNO: (arg) " << argument << endl;
1047                 int sel = strToInt(argument);
1048                 lyxerr.debug() << "LFUN_LAYOUTNO: (sel) "<< sel << endl;
1049                 
1050                 // Should this give a setMessage instead?
1051                 if (sel == 0) 
1052                         return string(); // illegal argument
1053
1054                 --sel; // sel 1..., but layout 0...
1055
1056                 // Pretend we got the name instead.
1057                 Dispatch(int(LFUN_LAYOUT), 
1058                          textclasslist.NameOfLayout(owner->view()->
1059                                                     text->parameters->
1060                                                     textclass,
1061                                                     sel).c_str());
1062                 return string();
1063         }
1064                 
1065         case LFUN_LAYOUT:
1066         {
1067                 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1068                                << argument << endl;
1069                 
1070                 // Derive layout number from given argument (string)
1071                 // and current buffer's textclass (number). */    
1072                 int layoutno = 
1073                         textclasslist.NumberOfLayout(owner->
1074                                                      view()->
1075                                                      text->parameters->
1076                                                      textclass,
1077                                                      argument).second;
1078
1079                 // see if we found the layout number:
1080                 if (layoutno == -1) {
1081                         setErrorMessage(string(N_("Layout ")) + argument + 
1082                                         N_(" not known"));
1083                         break;
1084                 }
1085                         
1086                 if (current_layout != layoutno) {
1087                         owner->view()->getScreen()->HideCursor();
1088                         current_layout = layoutno;
1089                         owner->view()->update(-2);
1090                         owner->view()->text->
1091                                 SetLayout(layoutno);
1092                         owner->getToolbar()->combox->
1093                                 select(owner->view()->
1094                                        text->cursor.par->
1095                                        GetLayout() + 1);
1096                         owner->view()->update(1);
1097                 }
1098         }
1099         break;
1100
1101         case LFUN_LAYOUT_DOCUMENT:
1102                 MenuLayoutDocument();
1103                 break;
1104                 
1105         case LFUN_LAYOUT_PARAGRAPH:
1106                 MenuLayoutParagraph();
1107                 break;
1108                 
1109         case LFUN_LAYOUT_CHARACTER:
1110                 MenuLayoutCharacter();
1111                 break;
1112                 
1113         case LFUN_LAYOUT_TABLE:
1114         {
1115                 int flag = 0;
1116                 if (argument == "true") flag = 1;
1117                 MenuLayoutTable(flag);
1118         }
1119         break;
1120                 
1121         case LFUN_LAYOUT_PAPER:
1122                 MenuLayoutPaper();
1123                 break;
1124                 
1125         case LFUN_LAYOUT_QUOTES:
1126                 MenuLayoutQuotes();
1127                 break;
1128                 
1129         case LFUN_LAYOUT_PREAMBLE:
1130                 MenuLayoutPreamble();
1131                 break;
1132                 
1133         case LFUN_LAYOUT_SAVE_DEFAULT:
1134                 MenuLayoutSave();
1135                 break;
1136                 
1137         case LFUN_DROP_LAYOUTS_CHOICE:
1138                 owner->getToolbar()->combox->Show();
1139                 break;
1140
1141         case LFUN_EMPH:
1142                 EmphCB();
1143                 break;
1144                 
1145         case LFUN_BOLD:
1146                 BoldCB();
1147                 break;
1148                 
1149         case LFUN_NOUN:
1150                 NounCB();
1151                 break;
1152                 
1153         case LFUN_CODE:
1154                 CodeCB();
1155                 break;
1156                 
1157         case LFUN_SANS:
1158                 SansCB();
1159                 break;
1160                 
1161         case LFUN_ROMAN:
1162                 RomanCB();
1163                 break;
1164                 
1165         case LFUN_DEFAULT:
1166                 StyleResetCB();
1167                 break;
1168                 
1169         case LFUN_UNDERLINE:
1170                 UnderlineCB();
1171                 break;
1172                 
1173         case LFUN_FONT_SIZE:
1174                 FontSizeCB(argument);
1175                 break;
1176                 
1177         case LFUN_FONT_STATE:
1178                 setMessage(CurrentState());
1179                 break;
1180                 
1181         case LFUN_UPCASE_WORD:
1182                 owner->view()->update(-2);
1183                 FreeUpdateTimer();
1184                 owner->view()->text->ChangeWordCase(LyXText::text_uppercase);
1185                 owner->view()->update(1);
1186                 SetUpdateTimer();
1187                 break;
1188                 
1189         case LFUN_LOWCASE_WORD:
1190                 owner->view()->update(-2);
1191                 FreeUpdateTimer();
1192                 owner->view()->text->ChangeWordCase(LyXText::text_lowercase);
1193                 owner->view()->update(1);
1194                 SetUpdateTimer();
1195                 break;
1196                 
1197         case LFUN_CAPITALIZE_WORD:
1198                 owner->view()->update(-2);
1199                 FreeUpdateTimer();
1200                 owner->view()->text->ChangeWordCase(LyXText::text_capitalization);
1201                 owner->view()->update(1);
1202                 SetUpdateTimer();
1203                 break;
1204                 
1205         case LFUN_INSERT_LABEL:
1206                 MenuInsertLabel(argument.c_str());
1207                 break;
1208                 
1209         case LFUN_INSERT_REF:
1210                 MenuInsertRef();
1211                 break;
1212                 
1213         case LFUN_REFTOGGLE:
1214         {
1215                 InsetRef * inset = 
1216                         static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1217                 if (inset) {
1218                         if (inset->getFlag() == InsetRef::REF)
1219                                 inset->setFlag(InsetRef::PAGE_REF);
1220                         else
1221                                 inset->setFlag(InsetRef::REF);
1222                         UpdateInset(inset);
1223                 } else {
1224                         setErrorMessage(N_("No cross-reference to toggle"));
1225                 }
1226         }
1227         break;
1228         
1229         case LFUN_REFBACK:
1230         {
1231                 owner->view()->restorePosition();
1232         }
1233         break;
1234
1235         case LFUN_REFGOTO:
1236         {
1237                 string label(argument);
1238                 if (label.empty()) {
1239                         InsetRef * inset = 
1240                                 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1241                         if (inset)
1242                                 label = inset->getContents();
1243                 }
1244                 
1245                 if (!label.empty()) {
1246                         owner->view()->savePosition();
1247                         owner->view()->gotoLabel(label.c_str());
1248                 }
1249         }
1250         break;
1251                 
1252         case LFUN_MENU_OPEN_BY_NAME:
1253                 owner->getMenus()->openByName(argument);
1254                 break; // RVDK_PATCH_5
1255                 
1256         case LFUN_SPELLCHECK:
1257                 if (lyxrc->isp_command != "none")
1258                         ShowSpellChecker();
1259                 break; // RVDK_PATCH_5
1260                 
1261                 // --- Cursor Movements -----------------------------
1262         case LFUN_RIGHT:
1263         {
1264                 LyXText * tmptext = owner->view()->text;
1265                 if(!tmptext->mark_set)
1266                         owner->view()->beforeChange();
1267                 owner->view()->update(-2);
1268                 if (tmptext->cursor.pos < tmptext->cursor.par->Last()
1269                     && tmptext->cursor.par->GetChar(tmptext->cursor.pos)
1270                     == LyXParagraph::META_INSET
1271                     && tmptext->cursor.par->GetInset(tmptext->cursor.pos)
1272                     && tmptext->cursor.par->GetInset(tmptext->cursor.pos)->Editable() == 2){
1273                         Inset * tmpinset = tmptext->cursor.par->GetInset(tmptext->cursor.pos);
1274                         setMessage(tmpinset->EditMessage());
1275                         tmpinset->Edit(0, 0);
1276                         break;
1277                 }
1278                 tmptext->CursorRight();
1279                 owner->view()->text->FinishUndo();
1280                 moveCursorUpdate(false);
1281                 owner->getMiniBuffer()->Set(CurrentState());
1282         }
1283         break;
1284                 
1285         case LFUN_LEFT:
1286         {
1287                 // This is soooo ugly. Isn`t it possible to make
1288                 // it simpler? (Lgb)
1289                 LyXText * txt = owner->view()->text;
1290                 if(!txt->mark_set) owner->view()->beforeChange();
1291                 owner->view()->update(-2);
1292                 txt->CursorLeft();
1293                 if (txt->cursor.pos < txt->cursor.par->Last()
1294                     && txt->cursor.par->GetChar(txt->cursor.pos)
1295                     == LyXParagraph::META_INSET
1296                     && txt->cursor.par->GetInset(txt->cursor.pos)
1297                     && txt->cursor.par->GetInset(txt->cursor.pos)->Editable() == 2) {
1298                         Inset * tmpinset = txt->cursor.par->GetInset(txt->cursor.pos);
1299                         setMessage(tmpinset->EditMessage());
1300                         tmpinset->Edit(tmpinset->Width(txt->GetFont(txt->cursor.par,
1301                                                                     txt->cursor.pos)), 0);
1302                         break;
1303                 }
1304                 owner->view()->text->FinishUndo();
1305                 moveCursorUpdate(false);
1306                 owner->getMiniBuffer()->Set(CurrentState());
1307         }
1308         break;
1309                 
1310         case LFUN_UP:
1311                 if(!owner->view()->text->mark_set) owner->view()->beforeChange();
1312                 owner->view()->update(-3);
1313                 owner->view()->text->CursorUp();
1314                 owner->view()->text->FinishUndo();
1315                 moveCursorUpdate(false);
1316                 owner->getMiniBuffer()->Set(CurrentState());
1317                 break;
1318                 
1319         case LFUN_DOWN:
1320                 if(!owner->view()->text->mark_set)
1321                         owner->view()->beforeChange();
1322                 owner->view()->update(-3);
1323                 owner->view()->text->CursorDown();
1324                 owner->view()->text->FinishUndo();
1325                 moveCursorUpdate(false);
1326                 owner->getMiniBuffer()->Set(CurrentState());
1327                 break;
1328
1329         case LFUN_UP_PARAGRAPH:
1330                 if(!owner->view()->text->mark_set)
1331                         owner->view()->beforeChange();
1332                 owner->view()->update(-3);
1333                 owner->view()->text->CursorUpParagraph();
1334                 owner->view()->text->FinishUndo();
1335                 moveCursorUpdate(false);
1336                 owner->getMiniBuffer()->Set(CurrentState());
1337                 break;
1338                 
1339         case LFUN_DOWN_PARAGRAPH:
1340                 if(!owner->view()->text->mark_set)
1341                         owner->view()->beforeChange();
1342                 owner->view()->update(-3);
1343                 owner->view()->text->CursorDownParagraph();
1344                 owner->view()->text->FinishUndo();
1345                 moveCursorUpdate(false);
1346                 owner->getMiniBuffer()->Set(CurrentState());
1347                 break;
1348                 
1349         case LFUN_PRIOR:
1350                 if(!owner->view()->text->mark_set)
1351                         owner->view()->beforeChange();
1352                 owner->view()->update(-3);
1353                 owner->view()->cursorPrevious();
1354                 owner->view()->text->FinishUndo();
1355                 moveCursorUpdate(false);
1356                 owner->getMiniBuffer()->Set(CurrentState());
1357                 break;
1358                 
1359         case LFUN_NEXT:
1360                 if(!owner->view()->text->mark_set)
1361                         owner->view()->beforeChange();
1362                 owner->view()->update(-3);
1363                 owner->view()->cursorNext();
1364                 owner->view()->text->FinishUndo();
1365                 moveCursorUpdate(false);
1366                 owner->getMiniBuffer()->Set(CurrentState());
1367                 break;
1368                 
1369         case LFUN_HOME:
1370                 if(!owner->view()->text->mark_set)
1371                         owner->view()->beforeChange();
1372                 owner->view()->update(-2);
1373                 owner->view()->text->CursorHome();
1374                 owner->view()->text->FinishUndo();
1375                 moveCursorUpdate(false);
1376                 owner->getMiniBuffer()->Set(CurrentState());
1377                 break;
1378                 
1379         case LFUN_END:
1380                 if(!owner->view()->text->mark_set)
1381                         owner->view()->beforeChange();
1382                 owner->view()->update(-2);
1383                 owner->view()->text->CursorEnd();
1384                 owner->view()->text->FinishUndo();
1385                 moveCursorUpdate(false);
1386                 owner->getMiniBuffer()->Set(CurrentState());
1387                 break;
1388                 
1389         case LFUN_TAB:
1390                 if(!owner->view()->text->mark_set)
1391                         owner->view()->beforeChange();
1392                 owner->view()->update(-2);
1393                 owner->view()->text->CursorTab();
1394                 owner->view()->text->FinishUndo();
1395                 moveCursorUpdate(false);
1396                 owner->getMiniBuffer()->Set(CurrentState());
1397                 break;
1398                 
1399         case LFUN_WORDRIGHT:
1400                 if(!owner->view()->text->mark_set)
1401                         owner->view()->beforeChange();
1402                 owner->view()->update(-2);
1403                 owner->view()->text->CursorRightOneWord();
1404                 owner->view()->text->FinishUndo();
1405                 moveCursorUpdate(false);
1406                 owner->getMiniBuffer()->Set(CurrentState());
1407                 break;
1408                 
1409         case LFUN_WORDLEFT:
1410                 if(!owner->view()->text->mark_set)
1411                         owner->view()->beforeChange();
1412                 owner->view()->update(-2);
1413                 owner->view()->text->CursorLeftOneWord();
1414                 owner->view()->text->FinishUndo();
1415                 moveCursorUpdate(false);
1416                 owner->getMiniBuffer()->Set(CurrentState());
1417                 break;
1418                 
1419         case LFUN_BEGINNINGBUF:
1420                 if(!owner->view()->text->mark_set)
1421                         owner->view()->beforeChange();
1422                 owner->view()->update(-2);
1423                 owner->view()->text->CursorTop();
1424                 owner->view()->text->FinishUndo();
1425                 moveCursorUpdate(false);
1426                 owner->getMiniBuffer()->Set(CurrentState());
1427                 break;
1428                 
1429         case LFUN_ENDBUF:
1430                 if(!owner->view()->text->mark_set)
1431                         owner->view()->beforeChange();
1432                 owner->view()->update(-2);
1433                 owner->view()->text->CursorBottom();
1434                 owner->view()->text->FinishUndo();
1435                 moveCursorUpdate(false);
1436                 owner->getMiniBuffer()->Set(CurrentState());
1437                 break;
1438
1439       
1440                 /* cursor selection ---------------------------- */
1441         case LFUN_RIGHTSEL:
1442                 owner->view()->update(-2);
1443                 owner->view()->text->CursorRight();
1444                 owner->view()->text->FinishUndo();
1445                 moveCursorUpdate(true);
1446                 owner->getMiniBuffer()->Set(CurrentState());
1447                 break;
1448                 
1449         case LFUN_LEFTSEL:
1450                 owner->view()->update(-2);
1451                 owner->view()->text->CursorLeft();
1452                 owner->view()->text->FinishUndo();
1453                 moveCursorUpdate(true);
1454                 owner->getMiniBuffer()->Set(CurrentState());
1455                 break;
1456                 
1457         case LFUN_UPSEL:
1458                 owner->view()->update(-2);
1459                 owner->view()->text->CursorUp();
1460                 owner->view()->text->FinishUndo();
1461                 moveCursorUpdate(true);
1462                 owner->getMiniBuffer()->Set(CurrentState());
1463                 break;
1464                 
1465         case LFUN_DOWNSEL:
1466                 owner->view()->update(-2);
1467                 owner->view()->text->CursorDown();
1468                 owner->view()->text->FinishUndo();
1469                 moveCursorUpdate(true);
1470                 owner->getMiniBuffer()->Set(CurrentState());
1471                 break;
1472
1473         case LFUN_UP_PARAGRAPHSEL:
1474                 owner->view()->update(-2);
1475                 owner->view()->text->CursorUpParagraph();
1476                 owner->view()->text->FinishUndo();
1477                 moveCursorUpdate(true);
1478                 owner->getMiniBuffer()->Set(CurrentState());
1479                 break;
1480                 
1481         case LFUN_DOWN_PARAGRAPHSEL:
1482                 owner->view()->update(-2);
1483                 owner->view()->text->CursorDownParagraph();
1484                 owner->view()->text->FinishUndo();
1485                 moveCursorUpdate(true);
1486                 owner->getMiniBuffer()->Set(CurrentState());
1487                 break;
1488                 
1489         case LFUN_PRIORSEL:
1490                 owner->view()->update(-2);
1491                 owner->view()->cursorPrevious();
1492                 owner->view()->text->FinishUndo();
1493                 moveCursorUpdate(true);
1494                 owner->getMiniBuffer()->Set(CurrentState());
1495                 break;
1496                 
1497         case LFUN_NEXTSEL:
1498                 owner->view()->update(-2);
1499                 owner->view()->cursorNext();
1500                 owner->view()->text->FinishUndo();
1501                 moveCursorUpdate(true);
1502                 owner->getMiniBuffer()->Set(CurrentState());
1503                 break;
1504                 
1505         case LFUN_HOMESEL:
1506                 owner->view()->update(-2);
1507                 owner->view()->text->CursorHome();
1508                 owner->view()->text->FinishUndo();
1509                 moveCursorUpdate(true);
1510                 owner->getMiniBuffer()->Set(CurrentState());
1511                 break;
1512                 
1513         case LFUN_ENDSEL:
1514                 owner->view()->update(-2);
1515                 owner->view()->text->CursorEnd();
1516                 owner->view()->text->FinishUndo();
1517                 moveCursorUpdate(true);
1518                 owner->getMiniBuffer()->Set(CurrentState());
1519                 break;
1520                 
1521         case LFUN_WORDRIGHTSEL:
1522                 owner->view()->update(-2);
1523                 owner->view()->text->CursorRightOneWord();
1524                 owner->view()->text->FinishUndo();
1525                 moveCursorUpdate(true);
1526                 owner->getMiniBuffer()->Set(CurrentState());
1527                 break;
1528                 
1529         case LFUN_WORDLEFTSEL:
1530                 owner->view()->update(-2);
1531                 owner->view()->text->CursorLeftOneWord();
1532                 owner->view()->text->FinishUndo();
1533                 moveCursorUpdate(true);
1534                 owner->getMiniBuffer()->Set(CurrentState());
1535                 break;
1536                 
1537         case LFUN_BEGINNINGBUFSEL:
1538                 owner->view()->update(-2);
1539                 owner->view()->text->CursorTop();
1540                 owner->view()->text->FinishUndo();
1541                 moveCursorUpdate(true);
1542                 owner->getMiniBuffer()->Set(CurrentState());
1543                 break;
1544                 
1545         case LFUN_ENDBUFSEL:
1546                 owner->view()->update(-2);
1547                 owner->view()->text->CursorBottom();
1548                 owner->view()->text->FinishUndo();
1549                 moveCursorUpdate(true);
1550                 owner->getMiniBuffer()->Set(CurrentState());
1551                 break;
1552
1553                 // --- text changing commands ------------------------
1554         case LFUN_BREAKLINE:
1555                 owner->view()->beforeChange();
1556                 owner->view()->text->InsertChar(LyXParagraph::META_NEWLINE);
1557                 owner->view()->smallUpdate(1);
1558                 SetUpdateTimer(0.01);
1559                 moveCursorUpdate(false);
1560                 break;
1561                 
1562         case LFUN_PROTECTEDSPACE:
1563                 owner->view()->beforeChange();
1564                 owner->view()->text->
1565                         InsertChar(LyXParagraph::META_PROTECTED_SEPARATOR);
1566                 owner->view()->smallUpdate(1);
1567                 SetUpdateTimer();
1568                 moveCursorUpdate(false);
1569                 break;
1570                 
1571         case LFUN_SETMARK:
1572                 if(owner->view()->text->mark_set) {
1573                         owner->view()->beforeChange();
1574                         owner->view()->update(0);
1575                         setMessage(N_("Mark removed"));
1576                 } else {
1577                         owner->view()->beforeChange();
1578                         owner->view()->text->mark_set = 1;
1579                         owner->view()->update(0);
1580                         setMessage(N_("Mark set"));
1581                 }
1582                 owner->view()->text->sel_cursor = 
1583                         owner->view()->text->cursor;
1584                 break;
1585                 
1586         case LFUN_DELETE:
1587                 FreeUpdateTimer();
1588                 if (!owner->view()->text->selection) {
1589                         owner->view()->text->Delete();
1590                         owner->view()->text->sel_cursor = 
1591                                 owner->view()->text->cursor;
1592                         owner->view()->smallUpdate(1);
1593                         // It is possible to make it a lot faster still
1594                         // just comment out the lone below...
1595                         owner->view()->getScreen()->ShowCursor();
1596                 } else {
1597                         owner->view()->cut();
1598                 }
1599                 SetUpdateTimer();
1600                 break;
1601
1602         case LFUN_DELETE_SKIP:
1603         {
1604                 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1605                 
1606                 LyXCursor cursor = owner->view()->text->cursor;
1607
1608                 FreeUpdateTimer();
1609                 if (!owner->view()->text->selection) {
1610                         if (cursor.pos == cursor.par->Last()) {
1611                                 owner->view()->text->CursorRight();
1612                                 cursor = owner->view()->text->cursor;
1613                                 if (cursor.pos == 0
1614                                     && !(cursor.par->added_space_top 
1615                                          == VSpace (VSpace::NONE))) {
1616                                         owner->view()->text->SetParagraph
1617                                                 (cursor.par->line_top,
1618                                                  cursor.par->line_bottom,
1619                                                  cursor.par->pagebreak_top, 
1620                                                  cursor.par->pagebreak_bottom,
1621                                                  VSpace(VSpace::NONE), 
1622                                                  cursor.par->added_space_bottom,
1623                                                  cursor.par->align, 
1624                                                  cursor.par->labelwidthstring, 0);
1625                                         owner->view()->text->CursorLeft();
1626                                         owner->view()->update (1);
1627                                 } else {
1628                                         owner->view()->text->CursorLeft();
1629                                         owner->view()->text->Delete();
1630                                         owner->view()->text->sel_cursor = 
1631                                                 owner->view()->text->cursor;
1632                                         owner->view()->smallUpdate(1);
1633                                 }
1634                         } else {
1635                                 owner->view()->text->Delete();
1636                                 owner->view()->text->sel_cursor = 
1637                                         owner->view()->text->cursor;
1638                                 owner->view()->smallUpdate(1);
1639                         }
1640                 } else {
1641                         owner->view()->cut();
1642                 }
1643                 SetUpdateTimer();
1644         }
1645         break;
1646
1647         /* -------> Delete word forward. */
1648         case LFUN_DELETE_WORD_FORWARD:
1649                 owner->view()->update(-2);
1650                 FreeUpdateTimer();
1651                 owner->view()->text->DeleteWordForward();
1652                 owner->view()->update( 1 );
1653                 SetUpdateTimer();
1654                 moveCursorUpdate(false);
1655                 break;
1656
1657                 /* -------> Delete word backward. */
1658         case LFUN_DELETE_WORD_BACKWARD:
1659                 owner->view()->update(-2);
1660                 FreeUpdateTimer();
1661                 owner->view()->text->DeleteWordBackward();
1662                 owner->view()->update( 1 );
1663                 SetUpdateTimer();
1664                 moveCursorUpdate(false);
1665                 break;
1666                 
1667                 /* -------> Kill to end of line. */
1668         case LFUN_DELETE_LINE_FORWARD:
1669                 FreeUpdateTimer();
1670                 owner->view()->update(-2);
1671                 owner->view()->text->DeleteLineForward();
1672                 owner->view()->update( 1 );
1673                 SetUpdateTimer();
1674                 moveCursorUpdate(false);
1675                 break;
1676                 
1677                 /* -------> Set mark off. */
1678         case LFUN_MARK_OFF:
1679                 owner->view()->beforeChange();
1680                 owner->view()->update(0);
1681                 owner->view()->text->sel_cursor = 
1682                         owner->view()->text->cursor;
1683                 setMessage(N_("Mark off"));
1684                 break;
1685
1686                 /* -------> Set mark on. */
1687         case LFUN_MARK_ON:
1688                 owner->view()->beforeChange();
1689                 owner->view()->text->mark_set = 1;
1690                 owner->view()->update( 0 );
1691                 owner->view()->text->sel_cursor = 
1692                         owner->view()->text->cursor;
1693                 setMessage(N_("Mark on"));
1694                 break;
1695                 
1696         case LFUN_BACKSPACE:
1697         {
1698                 FreeUpdateTimer();
1699                 if (!owner->view()->text->selection) {
1700                         if (owner->getIntl()->getTrans()->backspace()) {
1701                                 owner->view()->text->Backspace();
1702                                 owner->view()->text->sel_cursor = 
1703                                         owner->view()->text->cursor;
1704                                 owner->view()->smallUpdate(1);
1705                                 // It is possible to make it a lot faster still
1706                                 // just comment out the lone below...
1707                                 owner->view()->getScreen()->ShowCursor();
1708                         }
1709                 } else {
1710                         owner->view()->cut();
1711                 }
1712                 SetUpdateTimer();
1713         }
1714         break;
1715
1716         case LFUN_BACKSPACE_SKIP:
1717         {
1718                 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1719                 
1720                 LyXCursor cursor = owner->view()->text->cursor;
1721                 
1722                 FreeUpdateTimer();
1723                 if (!owner->view()->text->selection) {
1724                         if (cursor.pos == 0 
1725                             && !(cursor.par->added_space_top 
1726                                  == VSpace (VSpace::NONE))) {
1727                                 owner->view()->text->SetParagraph 
1728                                         (cursor.par->line_top,      
1729                                          cursor.par->line_bottom,
1730                                          cursor.par->pagebreak_top, 
1731                                          cursor.par->pagebreak_bottom,
1732                                          VSpace(VSpace::NONE), cursor.par->added_space_bottom,
1733                                          cursor.par->align, 
1734                                          cursor.par->labelwidthstring, 0);
1735                                 owner->view()->update (1);
1736                         } else {
1737                                 owner->view()->text->Backspace();
1738                                 owner->view()->text->sel_cursor 
1739                                         = cursor;
1740                                 owner->view()->smallUpdate (1);
1741                         }
1742                 } else
1743                         owner->view()->cut();
1744                 SetUpdateTimer();
1745         }
1746         break;
1747
1748         case LFUN_BREAKPARAGRAPH:
1749         {
1750                 owner->view()->beforeChange();
1751                 owner->view()->text->BreakParagraph(0);
1752                 owner->view()->smallUpdate(1);
1753                 SetUpdateTimer(0.01);
1754                 owner->view()->text->sel_cursor = 
1755                         owner->view()->text->cursor;
1756                 break;
1757         }
1758
1759         case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1760         {
1761                 owner->view()->beforeChange();
1762                 owner->view()->text->BreakParagraph(1);
1763                 owner->view()->smallUpdate(1);
1764                 SetUpdateTimer(0.01);
1765                 owner->view()->text->sel_cursor = 
1766                         owner->view()->text->cursor;
1767                 break;
1768         }
1769         
1770         case LFUN_BREAKPARAGRAPH_SKIP:
1771         {
1772                 // When at the beginning of a paragraph, remove
1773                 // indentation and add a "defskip" at the top.
1774                 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
1775                 
1776                 LyXCursor cursor = owner->view()->text->cursor;
1777                 
1778                 owner->view()->beforeChange();
1779                 if (cursor.pos == 0) {
1780                         if (cursor.par->added_space_top == VSpace(VSpace::NONE)) {
1781                                 owner->view()->text->SetParagraph
1782                                         (cursor.par->line_top,      
1783                                          cursor.par->line_bottom,
1784                                          cursor.par->pagebreak_top, 
1785                                          cursor.par->pagebreak_bottom,
1786                                          VSpace(VSpace::DEFSKIP), cursor.par->added_space_bottom,
1787                                          cursor.par->align, 
1788                                          cursor.par->labelwidthstring, 1);
1789                                 owner->view()->update(1);
1790                         } 
1791                 }
1792                 else {
1793                         owner->view()->text->BreakParagraph(0);
1794                         owner->view()->smallUpdate(1);
1795                 }
1796                 SetUpdateTimer(0.01);
1797                 owner->view()->text->sel_cursor = cursor;
1798         }
1799         break;
1800         
1801         case LFUN_QUOTE:
1802                 owner->view()->beforeChange();
1803                 owner->view()->text->InsertChar('\"');  // This " matches the single quote in the code
1804                 owner->view()->smallUpdate(1);
1805                 SetUpdateTimer();
1806                 moveCursorUpdate(false);
1807                 break;
1808
1809         case LFUN_HTMLURL:
1810         case LFUN_URL:
1811         {
1812                 InsetCommand * new_inset;
1813                 if (action == LFUN_HTMLURL)
1814                         new_inset = new InsetUrl("htmlurl", "", "");
1815                 else
1816                         new_inset = new InsetUrl("url", "", "");
1817                 owner->view()->insertInset(new_inset);
1818                 new_inset->Edit(0, 0);
1819         }
1820         break;
1821
1822         // --- lyxserver commands ----------------------------
1823
1824         case LFUN_CHARATCURSOR:
1825         {
1826                 LyXParagraph::size_type pos = 
1827                         owner->view()->text->cursor.pos;
1828                 if(pos < owner->view()->text->cursor.par->size())
1829                         dispatch_buffer = owner->view()->text->
1830                                 cursor.par->text[pos];
1831                 else
1832                         dispatch_buffer = "EOF";
1833         }
1834         break;
1835         
1836         case LFUN_GETXY:
1837                 dispatch_buffer = 
1838                         tostr(owner->view()->text->cursor.x) + ' '
1839                         + tostr(owner->view()->text->cursor.y);
1840                 break;
1841                 
1842         case LFUN_SETXY:
1843         {
1844                 int  x;
1845                 long y;
1846                 sscanf(argument.c_str(), " %d %ld", &x, &y);
1847                 owner->view()->text->SetCursorFromCoordinates(x, y);
1848         }
1849         break;
1850         
1851         case LFUN_GETLAYOUT:
1852                 dispatch_buffer =  
1853                         tostr(owner->view()->text->cursor.par->layout);
1854                 break;
1855                         
1856         case LFUN_GETFONT:
1857         {
1858                 LyXFont * font = &(owner->view()->text->current_font);
1859                 if(font->shape() == LyXFont::ITALIC_SHAPE)
1860                         dispatch_buffer = 'E';
1861                 else if(font->shape() == LyXFont::SMALLCAPS_SHAPE)
1862                         dispatch_buffer = 'N';
1863                 else
1864                         dispatch_buffer = '0';
1865
1866         }
1867         break;
1868
1869         case LFUN_GETLATEX:
1870         {
1871                 LyXFont * font = &(owner->view()->text->current_font);
1872                 if(font->latex() == LyXFont::ON)
1873                         dispatch_buffer = 'L';
1874                 else
1875                         dispatch_buffer = '0';
1876         }
1877         break;
1878
1879         case LFUN_GETNAME:
1880                 setMessage(owner->buffer()->fileName());
1881                 lyxerr.debug() << "FNAME["
1882                                << owner->buffer()->fileName()
1883                                << "] " << endl;
1884                 break;
1885                 
1886         case LFUN_NOTIFY:
1887         {
1888                 string buf;
1889                 keyseq.print(buf);
1890                 dispatch_buffer = buf;
1891                 lyxserver->notifyClient(dispatch_buffer);
1892         }
1893         break;
1894
1895         case LFUN_GOTOFILEROW:
1896         {
1897                 char file_name[100];
1898                 int  row;
1899                 sscanf(argument.c_str(), " %s %d", file_name, &row);
1900
1901                 // Must replace extension of the file to be .lyx and get full path
1902                 string s = ChangeExtension(string(file_name), ".lyx", false);
1903
1904                 // Either change buffer or load the file
1905                 if (bufferlist.exists(s))
1906                         owner->view()->buffer(bufferlist.getBuffer(s));
1907                 else
1908                         owner->view()->buffer(bufferlist.loadLyXFile(s));
1909
1910                 // Set the cursor  
1911                 owner->view()->setCursorFromRow(row);
1912
1913                 // Recenter screen
1914                 owner->view()->beforeChange();
1915                 if (owner->view()->text->cursor.y >
1916                     owner->view()->getWorkArea()->h / 2)        {
1917                         owner->view()->getScreen()->
1918                                 Draw(owner->view()->text->cursor.y -
1919                                      owner->view()->getWorkArea()->h/2);
1920                 } else { // <= 
1921                         owner->view()->getScreen()->
1922                                 Draw(0);
1923                 }
1924                 owner->view()->update(0);
1925                 owner->view()->redraw();
1926         }
1927         break;
1928
1929         case LFUN_APROPOS:
1930         case LFUN_GETTIP:
1931         {
1932                 int qa = lyxaction.LookupFunc(argument.c_str());
1933                 setMessage(lyxaction.helpText(static_cast<kb_action>(qa)));
1934         }
1935         break;
1936
1937         // --- accented characters ---------------------------
1938                 
1939         case LFUN_UMLAUT:
1940         case LFUN_CIRCUMFLEX:
1941         case LFUN_GRAVE:
1942         case LFUN_ACUTE:
1943         case LFUN_TILDE:
1944         case LFUN_CEDILLA:
1945         case LFUN_MACRON:
1946         case LFUN_DOT:
1947         case LFUN_UNDERDOT:
1948         case LFUN_UNDERBAR:
1949         case LFUN_CARON:
1950         case LFUN_SPECIAL_CARON:
1951         case LFUN_BREVE:
1952         case LFUN_TIE:
1953         case LFUN_HUNG_UMLAUT:
1954         case LFUN_CIRCLE:
1955         case LFUN_OGONEK:
1956         {
1957                 char c;
1958                 
1959                 if (keyseq.length == -1 && keyseq.getiso() != 0) 
1960                         c = keyseq.getiso();
1961                 else
1962                         c = 0;
1963                 
1964                 owner->getIntl()->getTrans()->
1965                         deadkey(c, get_accent(action).accent, 
1966                                 owner->view()->text);
1967                 
1968                 // Need to reset, in case the minibuffer calls these
1969                 // actions
1970                 keyseq.reset();
1971                 keyseq.length = 0;
1972                 
1973                 // copied verbatim from do_accent_char
1974                 owner->view()->smallUpdate(1);
1975                 SetUpdateTimer();
1976                 owner->view()->text->sel_cursor = 
1977                         owner->view()->text->cursor;
1978         }   
1979         break;
1980         
1981         // --- toolbar ----------------------------------
1982         case LFUN_PUSH_TOOLBAR:
1983         {
1984                 int nth = strToInt(argument);
1985                 if (lyxerr.debugging(Debug::TOOLBAR)) {
1986                         lyxerr << "LFUN_PUSH_TOOLBAR: argument = `"
1987                                << argument << "'\n"
1988                                << "LFUN_PUSH_TOOLBAR: nth = `"
1989                                << nth << "'" << endl;
1990                 }
1991                 
1992                 if (nth <= 0) {
1993                         LyXBell();
1994                         setErrorMessage(N_("Push-toolbar needs argument > 0"));
1995                 } else {
1996                         owner->getToolbar()->push(nth);
1997                 }
1998         }
1999         break;
2000         
2001         case LFUN_ADD_TO_TOOLBAR:
2002         {
2003                 if (lyxerr.debugging(Debug::TOOLBAR)) {
2004                         lyxerr << "LFUN_ADD_TO_TOOLBAR:"
2005                                 "argument = `" << argument << '\'' << endl;
2006                 }
2007                 string tmp(argument);
2008                 //lyxerr <<string("Argument: ") + argument);
2009                 //lyxerr <<string("Tmp     : ") + tmp);
2010                 if (tmp.empty()) {
2011                         LyXBell();
2012                         setErrorMessage(N_("Usage: toolbar-add-to <LyX command>"));
2013                 } else {
2014                         owner->getToolbar()->add(argument, false);
2015                         owner->getToolbar()->set();
2016                 }
2017         }
2018         break;
2019         
2020         // --- insert characters ----------------------------------------
2021 #if 0
2022         case LFUN_INSERT_INSET_LATEX:
2023         {
2024                 Inset * new_inset = new InsetLatex(argument);
2025                 owner->buffer()->insertInset(new_inset);
2026         }
2027         break;
2028 #endif
2029         // ---  Mathed stuff. If we are here, there is no locked inset yet.
2030         
2031         // Greek mode     
2032         case LFUN_GREEK:
2033         {
2034                 if (!greek_kb_flag) {
2035                         greek_kb_flag = 1;
2036                         setMessage(N_("Math greek mode on"));
2037                 } else
2038                         greek_kb_flag = 0;
2039         }  
2040         break;
2041       
2042         // Greek keyboard      
2043         case LFUN_GREEK_TOGGLE:
2044         {
2045                 greek_kb_flag = greek_kb_flag ? 0 : 2;
2046                 if (greek_kb_flag) {
2047                         setMessage(N_("Math greek keyboard on"));
2048                 } else {
2049                         setMessage(N_("Math greek keyboard off"));
2050                 }
2051         }
2052         break;
2053         
2054         case LFUN_MATH_DELIM:     
2055         case LFUN_INSERT_MATRIX:
2056         {          
2057                 if (owner->view()->available()) { 
2058                         owner->view()->
2059                                 open_new_inset(new InsetFormula(false));
2060                         owner->view()->
2061                                 the_locking_inset->LocalDispatch(action, argument.c_str());
2062                 }
2063         }          
2064         break;
2065                
2066         case LFUN_INSERT_MATH:
2067         {
2068                 math_insert_symbol(argument.c_str());
2069         }
2070         break;
2071         
2072         case LFUN_MATH_DISPLAY:
2073         {
2074                 if (owner->view()->available())
2075                         owner->view()->open_new_inset(new InsetFormula(true));
2076                 break;
2077         }
2078                     
2079         case LFUN_MATH_MACRO:
2080         {
2081                 if (owner->view()->available()) {
2082                         string s(argument);
2083                         if (s.empty())
2084                                 setErrorMessage(N_("Missing argument"));
2085                         else {
2086                                 string s1 = token(s, ' ', 1);
2087                                 int na = s1.empty() ? 0: atoi(s1.c_str());
2088                                 owner->view()->
2089                                         open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2090                         }
2091                 }
2092         }
2093         break;
2094
2095         case LFUN_MATH_MODE:   // Open or create a math inset
2096         {
2097                 
2098                 if (owner->view()->available())
2099                         owner->view()->open_new_inset(new InsetFormula);
2100                 setMessage(N_("Math editor mode"));
2101         }
2102         break;
2103           
2104         case LFUN_MATH_NUMBER:
2105         case LFUN_MATH_LIMITS:
2106         {
2107                 setErrorMessage(N_("This is only allowed in math mode!"));
2108         }
2109         break;
2110         
2111         case LFUN_INSERT_CITATION:
2112         {   
2113                 InsetCitation * new_inset = new InsetCitation();
2114                 // ale970405
2115                 // The note, if any, must be after the key, delimited
2116                 // by a | so both key and remark can have spaces.
2117                 if (!argument.empty()) {
2118                         string lsarg(argument);
2119                         if (contains(lsarg, "|")) {
2120                                 new_inset->setContents(token(lsarg, '|', 0));
2121                                 new_inset->setOptions(token(lsarg, '|', 1));
2122                         } else
2123                                 new_inset->setContents(lsarg);
2124                         owner->view()->insertInset(new_inset);
2125                 } else {
2126                         owner->view()->insertInset(new_inset);
2127                         new_inset->Edit(0, 0);
2128                 }
2129         }
2130         break;
2131                     
2132         case LFUN_INSERT_BIBTEX:
2133         {   
2134                 // ale970405+lasgoutt970425
2135                 // The argument can be up to two tokens separated 
2136                 // by a space. The first one is the bibstyle.
2137                 string lsarg(argument);
2138                 string bibstyle = token(lsarg, ' ', 1);
2139                 if (bibstyle.empty())
2140                         bibstyle = "plain";
2141                 InsetBibtex * new_inset 
2142                         = new InsetBibtex(token(lsarg, ' ', 0),
2143                                           bibstyle,
2144                                           owner->buffer());
2145                 
2146                 owner->view()->insertInset(new_inset);
2147                 if (lsarg.empty()) {
2148                         new_inset->Edit(0, 0);
2149                 }
2150         }
2151         break;
2152                 
2153         // BibTeX data bases
2154         case LFUN_BIBDB_ADD:
2155         {
2156                 InsetBibtex * inset = 
2157                         static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2158                 if (inset) {
2159                         inset->addDatabase(argument);
2160                 }
2161         }
2162         break;
2163                     
2164         case LFUN_BIBDB_DEL:
2165         {
2166                 InsetBibtex * inset = 
2167                         static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2168                 if (inset) {
2169                         inset->delDatabase(argument);
2170                 }
2171         }
2172         break;
2173         
2174         case LFUN_BIBTEX_STYLE:
2175         {
2176                 InsetBibtex * inset = 
2177                         static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2178                 if (inset) {
2179                         inset->setOptions(argument);
2180                 }
2181         }
2182         break;
2183                 
2184         case LFUN_INDEX_INSERT:
2185         case LFUN_INDEX_INSERT_LAST:
2186         {
2187                 // Can't do that at the beginning of a paragraph.
2188                 if (owner->view()->text->cursor.pos - 1 < 0)
2189                         break;
2190
2191                 InsetIndex * new_inset = new InsetIndex();
2192                 if (!argument.empty()) {
2193                         string lsarg(argument);
2194                         new_inset->setContents(lsarg);
2195                         owner->view()->insertInset(new_inset);
2196                 } else {
2197                         //reh 98/09/21
2198                         //get the current word for an argument
2199                         LyXParagraph::size_type lastpos = 
2200                                 owner->view()->text->cursor.pos - 1;
2201                         // Get the current word. note that this must be done
2202                         // before inserting the inset, or the inset will
2203                         // break the word
2204                         string curstring(owner->view()
2205                                          ->text->cursor.par->GetWord(lastpos));
2206
2207                         //make the new inset and write the current word into it
2208                         InsetIndex * new_inset = new InsetIndex();
2209
2210                         new_inset->setContents(curstring);
2211
2212                         //don't edit it if the call was to INSERT_LAST
2213                         if(action != LFUN_INDEX_INSERT_LAST) {
2214                                 new_inset->Edit(0, 0);
2215                         } else {
2216                                 //it looks blank on the screen unless
2217                                 //we do  something.  put it here.
2218
2219                                 // move the cursor to the returned value of lastpos
2220                                 // but only for the auto-insert
2221                                 owner->view()->text->cursor.pos = lastpos;
2222                         }
2223
2224                         //put the new inset into the buffer.
2225                         // there should be some way of knowing the user
2226                         //cancelled & avoiding this, but i don't know how
2227                         owner->view()->insertInset(new_inset);
2228                 }
2229         }
2230         break;
2231
2232         case LFUN_INDEX_PRINT:
2233         {
2234                 Inset * new_inset = new InsetPrintIndex(owner->buffer());
2235                 owner->view()->insertInset(new_inset, "Standard", true);
2236         }
2237         break;
2238
2239         case LFUN_PARENTINSERT:
2240         {
2241                 lyxerr << "arg " << argument << endl;
2242                 Inset * new_inset = new InsetParent(argument, owner->buffer());
2243                 owner->view()->insertInset(new_inset, "Standard", true);
2244         }
2245         break;
2246
2247         case LFUN_CHILDINSERT:
2248         {
2249                 Inset * new_inset = new InsetInclude(argument,
2250                                                      owner->buffer());
2251                 owner->view()->insertInset(new_inset, "Standard", true);
2252                 new_inset->Edit(0, 0);
2253         }
2254         break;
2255
2256         case LFUN_CHILDOPEN:
2257         {
2258                 string filename =
2259                         MakeAbsPath(argument, 
2260                                     OnlyPath(owner->buffer()->fileName()));
2261                 setMessage(N_("Opening child document ") +
2262                            MakeDisplayPath(filename) + "...");
2263                 owner->view()->savePosition();
2264                 if (bufferlist.exists(filename))
2265                         owner->view()->buffer(bufferlist.getBuffer(filename));
2266                 else
2267                         owner->view()->buffer(bufferlist.loadLyXFile(filename));
2268         }
2269         break;
2270
2271         case LFUN_INSERT_NOTE:
2272                 owner->view()->insertNote();
2273                 break;
2274                 
2275         case LFUN_INSERTFOOTNOTE: 
2276         {
2277                 LyXParagraph::footnote_kind kind;
2278                 if (argument == "footnote")
2279                         { kind = LyXParagraph::FOOTNOTE; }
2280                 else if (argument == "margin")
2281                         { kind = LyXParagraph::MARGIN; }
2282                 else if (argument == "figure")
2283                         { kind = LyXParagraph::FIG; }
2284                 else if (argument == "table")
2285                         { kind = LyXParagraph::TAB; }
2286                 else if (argument == "wide-fig")
2287                         { kind = LyXParagraph::WIDE_FIG; }
2288                 else if (argument == "wide-tab")
2289                         { kind = LyXParagraph::WIDE_TAB; }
2290                 else if (argument == "algorithm")
2291                         { kind = LyXParagraph::ALGORITHM; }
2292                 else {
2293                         setErrorMessage(N_("Unknown kind of footnote"));
2294                         break;
2295                 }
2296                 owner->view()->text->InsertFootnoteEnvironment(kind);
2297                 owner->view()->update(1);
2298         }
2299         break;
2300         
2301         case LFUN_BUFFERBULLETSSELECT:
2302                 bulletForm();
2303                 break;
2304                 
2305         case LFUN_TOGGLECURSORFOLLOW:
2306                 cursor_follows_scrollbar = !cursor_follows_scrollbar;
2307                 break;
2308                 
2309         case LFUN_KMAP_OFF:             // keymap off
2310                 owner->getIntl()->KeyMapOn(false);
2311                 break;
2312                 
2313         case LFUN_KMAP_PRIM:    // primary keymap
2314                 owner->getIntl()->KeyMapPrim();
2315                 break;
2316                 
2317         case LFUN_KMAP_SEC:             // secondary keymap
2318                 owner->getIntl()->KeyMapSec();
2319                 break;
2320                 
2321         case LFUN_KMAP_TOGGLE:  // toggle keymap
2322                 owner->getIntl()->ToggleKeyMap();
2323                 break;
2324
2325         case LFUN_SELFINSERT:
2326         {
2327                 for (string::size_type i = 0; i < argument.length(); ++i) {
2328                         owner->view()->text->InsertChar(argument[i]);
2329                         // This needs to be in the loop, or else we
2330                         // won't break lines correctly. (Asger)
2331                         owner->view()->smallUpdate(1);
2332                 }
2333                 SetUpdateTimer();
2334                 owner->view()->text->sel_cursor = 
2335                         owner->view()->text->cursor;
2336                 moveCursorUpdate(false);
2337         }
2338         break;
2339
2340         case LFUN_SEQUENCE: 
2341         {
2342                 // argument contains ';'-terminated commands
2343                 while (argument.find(';') != string::npos) {
2344                         string first;
2345                         argument = split(argument, first, ';');
2346                         Dispatch(first);
2347                 }
2348         }
2349         break;
2350
2351         case LFUN_SAVEPREFERENCES:
2352         {
2353                 Path p(user_lyxdir);
2354                 lyxrc->write("preferences");
2355         }
2356         break;
2357         
2358         case LFUN_UNKNOWN_ACTION:
2359         {
2360                 if(!owner->buffer()) {
2361                         LyXBell();
2362                         setErrorMessage(N_("No document open"));
2363                         break;
2364                 }
2365
2366                 if (owner->buffer()->isReadonly()) {
2367                         LyXBell();
2368                         setErrorMessage(N_("Document is read only"));
2369                         break;
2370                 }
2371                          
2372                 if (!argument.empty()) {
2373                         
2374                         /* Automatically delete the currently selected
2375                          * text and replace it with what is being
2376                          * typed in now. Depends on lyxrc settings
2377                          * "auto_region_delete", which defaults to
2378                          * true (on). */
2379                 
2380                         if ( lyxrc->auto_region_delete ) {
2381                                 if (owner->view()->text->selection){
2382                                         owner->view()->text->CutSelection(false);
2383                                         owner->view()->update(-1);
2384                                 }
2385                         }
2386                         
2387                         owner->view()->beforeChange();
2388                         for (string::size_type i = 0;
2389                              i < argument.length(); ++i) {
2390                                 if (greek_kb_flag) {
2391                                         if (!math_insert_greek(argument[i]))
2392                                                 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2393                                 } else
2394                                         owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2395                         }
2396                         
2397                         owner->view()->smallUpdate(1);
2398                         SetUpdateTimer();
2399
2400                         owner->view()->text->sel_cursor = 
2401                                 owner->view()->text->cursor;
2402                         moveCursorUpdate(false);
2403                         return string();
2404                 } else {
2405                         // why is an "Unknown action" with empty
2406                         // argument even dispatched in the first
2407                         // place? I`ll probably change that. (Lgb)
2408                         LyXBell();
2409                         setErrorMessage(N_("Unknown action"));
2410                 }
2411                 break;
2412         default:
2413                 lyxerr << "A truly unknown func!" << endl;
2414                 break;
2415         }
2416         } // end of switch
2417   exit_with_message:
2418
2419         string res = getMessage();
2420
2421         if (res.empty()) {
2422                 if (!commandshortcut.empty()) {
2423                         string newbuf = owner->getMiniBuffer()->GetText();
2424                         if (newbuf != commandshortcut) {
2425                                 owner->getMiniBuffer()->Set(newbuf
2426                                                             + " " +
2427                                                             commandshortcut);
2428                         }
2429                 }
2430         } else {
2431                 owner->getMiniBuffer()->Set(string(_(res.c_str()))
2432                                             + " " + commandshortcut);
2433         }
2434
2435         return res;
2436 }
2437
2438
2439 void LyXFunc::setupLocalKeymap()
2440 {
2441         keyseq.stdmap = keyseq.curmap = toplevel_keymap;
2442         cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap;
2443 }
2444
2445
2446 void LyXFunc::MenuNew(bool fromTemplate)
2447 {
2448         string fname, initpath = lyxrc->document_path;
2449         LyXFileDlg fileDlg;
2450
2451         if (owner->view()->available()) {
2452                 string trypath = owner->buffer()->filepath;
2453                 // If directory is writeable, use this as default.
2454                 if (IsDirWriteable(trypath) == 1)
2455                         initpath = trypath;
2456         }
2457
2458         ProhibitInput();
2459         fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2460         fileDlg.SetButton(1, _("Templates"), lyxrc->template_path);
2461         fname = fileDlg.Select(_("Enter Filename for new document"), 
2462                                initpath, "*.lyx", _("newfile"));
2463         AllowInput();
2464         
2465         if (fname.empty()) {
2466                 owner->getMiniBuffer()->Set(_("Canceled."));
2467                 lyxerr.debug() << "New Document Cancelled." << endl;
2468                 return;
2469         }
2470         
2471         // get absolute path of file and make sure the filename ends
2472         // with .lyx
2473         string s = MakeAbsPath(fname);
2474         if (!IsLyXFilename(s))
2475                 s += ".lyx";
2476
2477         // Check if the document already is open
2478         if (bufferlist.exists(s)){
2479                 switch(AskConfirmation(_("Document is already open:"), 
2480                                        MakeDisplayPath(s, 50),
2481                                        _("Do you want to close that document now?\n"
2482                                          "('No' will just switch to the open version)")))
2483                         {
2484                         case 1: // Yes: close the document
2485                                 if (!bufferlist.close(bufferlist.getBuffer(s)))
2486                                 // If close is canceled, we cancel here too.
2487                                         return;
2488                                 break;
2489                         case 2: // No: switch to the open document
2490                                 owner->view()->buffer(bufferlist.getBuffer(s));
2491                                 return;
2492                         case 3: // Cancel: Do nothing
2493                                 owner->getMiniBuffer()->Set(_("Canceled."));
2494                                 return;
2495                         }
2496         }
2497         
2498         // Check whether the file already exists
2499         if (IsLyXFilename(s)) {
2500                 FileInfo fi(s);
2501                 if (fi.readable() &&
2502                     AskQuestion(_("File already exists:"), 
2503                                 MakeDisplayPath(s, 50),
2504                                 _("Do you want to open the document?"))) {
2505                         // loads document
2506                         owner->getMiniBuffer()->Set(_("Opening document"), 
2507                                                     MakeDisplayPath(s), "...");
2508                         XFlush(fl_display);
2509                         owner->view()->buffer(
2510                                 bufferlist.loadLyXFile(s));
2511                         owner->getMiniBuffer()->Set(_("Document"),
2512                                                     MakeDisplayPath(s),
2513                                                     _("opened."));
2514                         return;
2515                 }
2516         }
2517
2518         // The template stuff
2519         string templname;
2520         if (fromTemplate) {
2521                 ProhibitInput();
2522                 fname = fileDlg.Select(_("Choose template"),
2523                                        lyxrc->template_path,
2524                                        "*.lyx");
2525                 templname = fname;
2526                 AllowInput();
2527         }
2528   
2529         // find a free buffer
2530         lyxerr.debug() << "Find a free buffer." << endl;
2531         owner->view()->buffer(bufferlist.newFile(s, templname));
2532 }
2533
2534
2535 void LyXFunc::MenuOpen()
2536 {
2537         string initpath = lyxrc->document_path;
2538         LyXFileDlg fileDlg;
2539   
2540         if (owner->view()->available()) {
2541                 string trypath = owner->buffer()->filepath;
2542                 // If directory is writeable, use this as default.
2543                 if (IsDirWriteable(trypath) == 1)
2544                         initpath = trypath;
2545         }
2546
2547         // launches dialog
2548         ProhibitInput();
2549         fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2550         fileDlg.SetButton(1, _("Examples"), 
2551                           AddPath(system_lyxdir, "examples"));
2552         string filename = fileDlg.Select(_("Select Document to Open"),
2553                                          initpath, "*.lyx");
2554         AllowInput();
2555  
2556         // check selected filename
2557         if (filename.empty()) {
2558                 owner->getMiniBuffer()->Set(_("Canceled."));
2559                 return;
2560         }
2561
2562         // get absolute path of file and make sure the filename ends
2563         // with .lyx
2564         filename = MakeAbsPath(filename);
2565         if (!IsLyXFilename(filename))
2566                 filename += ".lyx";
2567
2568         // loads document
2569         owner->getMiniBuffer()->Set(_("Opening document"),
2570                                     MakeDisplayPath(filename), "...");
2571         Buffer * openbuf = bufferlist.loadLyXFile(filename);
2572         if (openbuf) {
2573                 owner->view()->buffer(openbuf);
2574                 owner->getMiniBuffer()->Set(_("Document"),
2575                                             MakeDisplayPath(filename),
2576                                             _("opened."));
2577         } else {
2578                 owner->getMiniBuffer()->Set(_("Could not open document"),
2579                                             MakeDisplayPath(filename));
2580         }
2581 }
2582
2583
2584 void LyXFunc::doImportASCII(bool linorpar)
2585 {
2586         string initpath = lyxrc->document_path;
2587         LyXFileDlg fileDlg;
2588   
2589         if (owner->view()->available()) {
2590                 string trypath = owner->buffer()->filepath;
2591                 // If directory is writeable, use this as default.
2592                 if (IsDirWriteable(trypath) == 1)
2593                         initpath = trypath;
2594         }
2595
2596         // launches dialog
2597         ProhibitInput();
2598         fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2599         fileDlg.SetButton(1, _("Examples"), 
2600                           AddPath(system_lyxdir, "examples"));
2601         string filename = fileDlg.Select(_("Select ASCII file to Import"),
2602                                          initpath, "*.txt");
2603         AllowInput();
2604  
2605         // check selected filename
2606         if (filename.empty()) {
2607                 owner->getMiniBuffer()->Set(_("Canceled."));
2608                 return;
2609         }
2610
2611         // get absolute path of file
2612         filename = MakeAbsPath(filename);
2613
2614         string s = ChangeExtension(filename, ".lyx", false);
2615
2616         // Check if the document already is open
2617         if (bufferlist.exists(s)) {
2618                 switch(AskConfirmation(_("Document is already open:"), 
2619                                        MakeDisplayPath(s, 50),
2620                                        _("Do you want to close that document now?\n"
2621                                          "('No' will just switch to the open version)")))
2622                         {
2623                         case 1: // Yes: close the document
2624                                 if (!bufferlist.close(bufferlist.getBuffer(s)))
2625                                 // If close is canceled, we cancel here too.
2626                                         return;
2627                                 break;
2628                         case 2: // No: switch to the open document
2629                                 owner->view()->buffer(bufferlist.getBuffer(s));
2630                                 return;
2631                         case 3: // Cancel: Do nothing
2632                                 owner->getMiniBuffer()->Set(_("Canceled."));
2633                                 return;
2634                         }
2635         }
2636
2637         // Check if a LyX document by the same root exists in filesystem
2638         FileInfo f(s, true);
2639         if (f.exist() && !AskQuestion(_("A document by the name"), 
2640                                       MakeDisplayPath(s),
2641                                       _("already exists. Overwrite?"))) {
2642                 owner->getMiniBuffer()->Set(_("Canceled."));
2643                 return;
2644         }
2645
2646         owner->view()->buffer(bufferlist.newFile(s, string()));
2647         owner->getMiniBuffer()->Set(_("Importing ASCII file"),
2648                                     MakeDisplayPath(filename), "...");
2649         // Insert ASCII file
2650         InsertAsciiFile(filename, linorpar);
2651         owner->getMiniBuffer()->Set(_("ASCII file "),
2652                                     MakeDisplayPath(filename),
2653                                     _("imported."));
2654 }
2655
2656
2657 void LyXFunc::doImportLaTeX(bool isnoweb)
2658 {
2659         string initpath = lyxrc->document_path;
2660         LyXFileDlg fileDlg;
2661   
2662         if (owner->view()->available()) {
2663                 string trypath = owner->buffer()->filepath;
2664                 // If directory is writeable, use this as default.
2665                 if (IsDirWriteable(trypath) == 1)
2666                         initpath = trypath;
2667         }
2668
2669         // launches dialog
2670         ProhibitInput();
2671         fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2672         fileDlg.SetButton(1, _("Examples"), 
2673                           AddPath(system_lyxdir, "examples"));
2674         string filename;
2675         if (isnoweb) {
2676                 filename = fileDlg.Select(_("Select Noweb file to Import"),
2677                                           initpath, "*.nw");
2678         } else {
2679                 filename = fileDlg.Select(_("Select LaTeX file to Import"),
2680                                           initpath, "*.tex");
2681         }
2682         
2683         AllowInput();
2684  
2685         // check selected filename
2686         if (filename.empty()) {
2687                 owner->getMiniBuffer()->Set(_("Canceled."));
2688                 return;
2689         }
2690
2691         // get absolute path of file
2692         filename = MakeAbsPath(filename);
2693
2694         // Check if the document already is open
2695         string LyXfilename = ChangeExtension(filename, ".lyx", false);
2696         if (bufferlist.exists(LyXfilename)){
2697                 switch(AskConfirmation(_("Document is already open:"), 
2698                                        MakeDisplayPath(LyXfilename, 50),
2699                                        _("Do you want to close that document now?\n"
2700                                          "('No' will just switch to the open version)")))
2701                         {
2702                         case 1: // Yes: close the document
2703                                 if (!bufferlist.close(bufferlist.getBuffer(LyXfilename)))
2704                                 // If close is canceled, we cancel here too.
2705                                         return;
2706                                 break;
2707                         case 2: // No: switch to the open document
2708                                 owner->view()->buffer(
2709                                         bufferlist.getBuffer(LyXfilename));
2710                                 return;
2711                         case 3: // Cancel: Do nothing
2712                                 owner->getMiniBuffer()->Set(_("Canceled."));
2713                                 return;
2714                         }
2715         }
2716
2717         // Check if a LyX document by the same root exists in filesystem
2718         FileInfo f(LyXfilename, true);
2719         if (f.exist() && !AskQuestion(_("A document by the name"), 
2720                                       MakeDisplayPath(LyXfilename),
2721                                       _("already exists. Overwrite?"))) {
2722                 owner->getMiniBuffer()->Set(_("Canceled."));
2723                 return;
2724         }
2725
2726         // loads document
2727         Buffer * openbuf;
2728         if (!isnoweb) {
2729                 owner->getMiniBuffer()->Set(_("Importing LaTeX file"),
2730                                             MakeDisplayPath(filename), "...");
2731                 ImportLaTeX myImport(filename);
2732                 openbuf = myImport.run();
2733         } else {
2734                 owner->getMiniBuffer()->Set(_("Importing Noweb file"),
2735                                             MakeDisplayPath(filename), "...");
2736                 ImportNoweb myImport(filename);
2737                 openbuf = myImport.run();
2738         }
2739         if (openbuf) {
2740                 owner->view()->buffer(openbuf);
2741                 owner->getMiniBuffer()->Set(isnoweb ?
2742                                             _("Noweb file ") : _("LateX file "),
2743                                             MakeDisplayPath(filename),
2744                                             _("imported."));
2745         } else {
2746                 owner->getMiniBuffer()->Set(isnoweb ?
2747                                             _("Could not import Noweb file") :
2748                                             _("Could not import LaTeX file"),
2749                                             MakeDisplayPath(filename));
2750         }
2751 }
2752
2753
2754 void LyXFunc::MenuInsertLyXFile(string const & filen)
2755 {
2756         string filename = filen;
2757
2758         if (filename.empty()) {
2759                 // Launch a file browser
2760                 string initpath = lyxrc->document_path;
2761                 LyXFileDlg fileDlg;
2762
2763                 if (owner->view()->available()) {
2764                         string trypath = owner->buffer()->filepath;
2765                         // If directory is writeable, use this as default.
2766                         if (IsDirWriteable(trypath) == 1)
2767                                 initpath = trypath;
2768                 }
2769
2770                 // launches dialog
2771                 ProhibitInput();
2772                 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
2773                 fileDlg.SetButton(1, _("Examples"), 
2774                                   AddPath(system_lyxdir, "examples"));
2775                 filename = fileDlg.Select(_("Select Document to Insert"),
2776                                           initpath, "*.lyx");
2777                 AllowInput();
2778
2779                 // check selected filename
2780                 if (filename.empty()) {
2781                         owner->getMiniBuffer()->Set(_("Canceled."));
2782                         return;
2783                 }
2784         } 
2785
2786         // get absolute path of file and make sure the filename ends
2787         // with .lyx
2788         filename = MakeAbsPath(filename);
2789         if (!IsLyXFilename(filename))
2790                 filename += ".lyx";
2791
2792         // Inserts document
2793         owner->getMiniBuffer()->Set(_("Inserting document"),
2794                                     MakeDisplayPath(filename), "...");
2795         bool res = owner->view()->insertLyXFile(filename);
2796         if (res) {
2797                 owner->getMiniBuffer()->Set(_("Document"),
2798                                             MakeDisplayPath(filename),
2799                                             _("inserted."));
2800         } else {
2801                 owner->getMiniBuffer()->Set(_("Could not insert document"),
2802                                             MakeDisplayPath(filename));
2803         }
2804 }
2805
2806
2807 void LyXFunc::reloadBuffer()
2808 {
2809         string fn = owner->buffer()->fileName();
2810         if (bufferlist.close(owner->buffer()))
2811                 owner->view()->buffer(bufferlist.loadLyXFile(fn));
2812 }
2813
2814
2815 void LyXFunc::CloseBuffer()
2816 {
2817         if (bufferlist.close(owner->buffer()) && !quitting) {
2818                 if (bufferlist.empty()) {
2819                         // need this otherwise SEGV may occur while trying to
2820                         // set variables that don't exist
2821                         // since there's no current buffer
2822                         CloseAllBufferRelatedPopups();
2823                 }
2824                 else {
2825                         owner->view()->buffer(bufferlist.first());
2826                 }
2827         }
2828 }
2829
2830
2831 Inset * LyXFunc::getInsetByCode(Inset::Code code)
2832 {
2833         bool found = false;
2834         Inset * inset = 0;
2835         LyXCursor cursor = owner->view()->text->cursor;
2836         LyXParagraph::size_type pos = cursor.pos;
2837         LyXParagraph * par = cursor.par;
2838         
2839         while (par && !found) {
2840                 while ((inset = par->ReturnNextInsetPointer(pos))){
2841                         if (inset->LyxCode() == code) {
2842                                 found = true;
2843                                 break;
2844                         }
2845                         ++pos;
2846                 } 
2847                 par = par->next;
2848         }
2849         return found ? inset : 0;
2850 }
2851
2852
2853 // Each "owner" should have it's own message method. lyxview and
2854 // the minibuffer would use the minibuffer, but lyxserver would
2855 // send an ERROR signal to its client.  Alejandro 970603
2856 // This func is bit problematic when it comes to NLS, to make the
2857 // lyx servers client be language indepenent we must not translate
2858 // strings sent to this func.
2859 void LyXFunc::setErrorMessage(string const & m) const
2860 {
2861         dispatch_buffer = m;
2862         errorstat = true;
2863 }
2864
2865
2866 void LyXFunc::setMessage(string const & m)
2867 {
2868         dispatch_buffer = m;
2869 }