]> git.lyx.org Git - lyx.git/blob - src/LyXFunc.cpp
Fix crash http://www.lyx.org/trac/ticket/6000
[lyx.git] / src / LyXFunc.cpp
1 /**
2  * \file LyXFunc.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Alfredo Braunstein
7  * \author Lars Gullik Bjønnes
8  * \author Jean-Marc Lasgouttes
9  * \author Angus Leeming
10  * \author John Levon
11  * \author André Pönitz
12  * \author Allan Rae
13  * \author Dekel Tsur
14  * \author Martin Vermeer
15  * \author Jürgen Vigna
16  *
17  * Full author contact details are available in file CREDITS.
18  */
19
20 #include <config.h>
21
22 #include "LyXFunc.h"
23
24 #include "LayoutFile.h"
25 #include "BranchList.h"
26 #include "buffer_funcs.h"
27 #include "Buffer.h"
28 #include "BufferList.h"
29 #include "BufferParams.h"
30 #include "BufferView.h"
31 #include "CmdDef.h"
32 #include "Color.h"
33 #include "Converter.h"
34 #include "Cursor.h"
35 #include "CutAndPaste.h"
36 #include "DispatchResult.h"
37 #include "Encoding.h"
38 #include "ErrorList.h"
39 #include "Format.h"
40 #include "FuncRequest.h"
41 #include "FuncStatus.h"
42 #include "InsetIterator.h"
43 #include "Intl.h"
44 #include "KeyMap.h"
45 #include "Language.h"
46 #include "Lexer.h"
47 #include "LyXAction.h"
48 #include "lyxfind.h"
49 #include "LyX.h"
50 #include "LyXRC.h"
51 #include "LyXVC.h"
52 #include "Paragraph.h"
53 #include "ParagraphParameters.h"
54 #include "ParIterator.h"
55 #include "Row.h"
56 #include "Server.h"
57 #include "Session.h"
58
59 #include "insets/InsetBox.h"
60 #include "insets/InsetBranch.h"
61 #include "insets/InsetCommand.h"
62 #include "insets/InsetERT.h"
63 #include "insets/InsetExternal.h"
64 #include "insets/InsetFloat.h"
65 #include "insets/InsetGraphics.h"
66 #include "insets/InsetInclude.h"
67 #include "insets/InsetListings.h"
68 #include "insets/InsetNote.h"
69 #include "insets/InsetPhantom.h"
70 #include "insets/InsetSpace.h"
71 #include "insets/InsetTabular.h"
72 #include "insets/InsetVSpace.h"
73 #include "insets/InsetWrap.h"
74
75 #include "frontends/alert.h"
76 #include "frontends/Application.h"
77 #include "frontends/KeySymbol.h"
78 #include "frontends/LyXView.h"
79 #include "frontends/Selection.h"
80
81 #include "support/debug.h"
82 #include "support/environment.h"
83 #include "support/FileName.h"
84 #include "support/filetools.h"
85 #include "support/gettext.h"
86 #include "support/lstrings.h"
87 #include "support/Path.h"
88 #include "support/Package.h"
89 #include "support/Systemcall.h"
90 #include "support/convert.h"
91 #include "support/os.h"
92
93 #include <sstream>
94 #include <vector>
95
96 using namespace std;
97 using namespace lyx::support;
98
99 namespace lyx {
100
101 using frontend::LyXView;
102
103 namespace Alert = frontend::Alert;
104
105 namespace {
106
107
108 // This function runs "configure" and then rereads lyx.defaults to
109 // reconfigure the automatic settings.
110 void reconfigure(LyXView * lv, string const & option)
111 {
112         // emit message signal.
113         if (lv)
114                 lv->message(_("Running configure..."));
115
116         // Run configure in user lyx directory
117         PathChanger p(package().user_support());
118         string configure_command = package().configure_command();
119         configure_command += option;
120         Systemcall one;
121         int ret = one.startscript(Systemcall::Wait, configure_command);
122         p.pop();
123         // emit message signal.
124         if (lv)
125                 lv->message(_("Reloading configuration..."));
126         lyxrc.read(libFileSearch(string(), "lyxrc.defaults"));
127         // Re-read packages.lst
128         LaTeXFeatures::getAvailable();
129
130         if (ret)
131                 Alert::information(_("System reconfiguration failed"),
132                            _("The system reconfiguration has failed.\n"
133                                   "Default textclass is used but LyX may "
134                                   "not be able to work properly.\n"
135                                   "Please reconfigure again if needed."));
136         else
137
138                 Alert::information(_("System reconfigured"),
139                            _("The system has been reconfigured.\n"
140                              "You need to restart LyX to make use of any\n"
141                              "updated document class specifications."));
142 }
143
144
145 bool getLocalStatus(Cursor cursor, FuncRequest const & cmd, FuncStatus & status)
146 {
147         // Try to fix cursor in case it is broken.
148         cursor.fixIfBroken();
149
150         // This is, of course, a mess. Better create a new doc iterator and use
151         // this in Inset::getStatus. This might require an additional
152         // BufferView * arg, though (which should be avoided)
153         //Cursor safe = *this;
154         bool res = false;
155         for ( ; cursor.depth(); cursor.pop()) {
156                 //lyxerr << "\nCursor::getStatus: cmd: " << cmd << endl << *this << endl;
157                 LASSERT(cursor.idx() <= cursor.lastidx(), /**/);
158                 LASSERT(cursor.pit() <= cursor.lastpit(), /**/);
159                 LASSERT(cursor.pos() <= cursor.lastpos(), /**/);
160
161                 // The inset's getStatus() will return 'true' if it made
162                 // a definitive decision on whether it want to handle the
163                 // request or not. The result of this decision is put into
164                 // the 'status' parameter.
165                 if (cursor.inset().getStatus(cursor, cmd, status)) {
166                         res = true;
167                         break;
168                 }
169         }
170         return res;
171 }
172
173
174 /** Return the change status at cursor position, taking in account the
175  * status at each level of the document iterator (a table in a deleted
176  * footnote is deleted).
177  * When \param outer is true, the top slice is not looked at.
178  */
179 Change::Type lookupChangeType(DocIterator const & dit, bool outer = false)
180 {
181         size_t const depth = dit.depth() - (outer ? 1 : 0);
182
183         for (size_t i = 0 ; i < depth ; ++i) {
184                 CursorSlice const & slice = dit[i];
185                 if (!slice.inset().inMathed()
186                     && slice.pos() < slice.paragraph().size()) {
187                         Change::Type const ch = slice.paragraph().lookupChange(slice.pos()).type;
188                         if (ch != Change::UNCHANGED)
189                                 return ch;
190                 }
191         }
192         return Change::UNCHANGED;
193 }
194
195 }
196
197
198 LyXFunc::LyXFunc()
199         : lyx_view_(0), encoded_last_key(0), meta_fake_bit(NoModifier)
200 {
201 }
202
203
204 void LyXFunc::initKeySequences(KeyMap * kb)
205 {
206         keyseq = KeySequence(kb, kb);
207         cancel_meta_seq = KeySequence(kb, kb);
208 }
209
210
211 void LyXFunc::setLyXView(LyXView * lv)
212 {
213         if (lyx_view_ && lyx_view_->view() && lyx_view_ != lv)
214                 // save current selection to the selection buffer to allow
215                 // middle-button paste in another window
216                 cap::saveSelection(lyx_view_->view()->cursor());
217         lyx_view_ = lv;
218 }
219
220
221 void LyXFunc::handleKeyFunc(FuncCode action)
222 {
223         char_type c = encoded_last_key;
224
225         if (keyseq.length())
226                 c = 0;
227
228         LASSERT(lyx_view_ && lyx_view_->view(), /**/);
229         lyx_view_->view()->getIntl().getTransManager().deadkey(
230                 c, get_accent(action).accent, view()->cursor().innerText(), view()->cursor());
231         // Need to clear, in case the minibuffer calls these
232         // actions
233         keyseq.clear();
234         // copied verbatim from do_accent_char
235         view()->cursor().resetAnchor();
236         view()->processUpdateFlags(Update::FitCursor);
237 }
238
239 //FIXME: bookmark handling is a frontend issue. This code should be transferred
240 // to GuiView and be GuiView and be window dependent.
241 void LyXFunc::gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer)
242 {
243         LASSERT(lyx_view_, /**/);
244         if (!theSession().bookmarks().isValid(idx))
245                 return;
246         BookmarksSection::Bookmark const & bm = theSession().bookmarks().bookmark(idx);
247         LASSERT(!bm.filename.empty(), /**/);
248         string const file = bm.filename.absFilename();
249         // if the file is not opened, open it.
250         if (!theBufferList().exists(bm.filename)) {
251                 if (openFile)
252                         dispatch(FuncRequest(LFUN_FILE_OPEN, file));
253                 else
254                         return;
255         }
256         // open may fail, so we need to test it again
257         if (!theBufferList().exists(bm.filename))
258                 return;
259
260         // bm can be changed when saving
261         BookmarksSection::Bookmark tmp = bm;
262
263         // Special case idx == 0 used for back-from-back jump navigation
264         if (idx == 0)
265                 dispatch(FuncRequest(LFUN_BOOKMARK_SAVE, "0"));
266
267         // if the current buffer is not that one, switch to it.
268         if (!lyx_view_->buffer() || lyx_view_->buffer()->fileName() != tmp.filename) {
269                 if (!switchToBuffer)
270                         return;
271                 dispatch(FuncRequest(LFUN_BUFFER_SWITCH, file));
272         }
273
274         // moveToPosition try paragraph id first and then paragraph (pit, pos).
275         if (!view()->moveToPosition(tmp.bottom_pit, tmp.bottom_pos,
276                 tmp.top_id, tmp.top_pos))
277                 return;
278
279         // bm changed
280         if (idx == 0)
281                 return;
282
283         // Cursor jump succeeded!
284         Cursor const & cur = view()->cursor();
285         pit_type new_pit = cur.pit();
286         pos_type new_pos = cur.pos();
287         int new_id = cur.paragraph().id();
288
289         // if bottom_pit, bottom_pos or top_id has been changed, update bookmark
290         // see http://bugzilla.lyx.org/show_bug.cgi?id=3092
291         if (bm.bottom_pit != new_pit || bm.bottom_pos != new_pos 
292                 || bm.top_id != new_id) {
293                 const_cast<BookmarksSection::Bookmark &>(bm).updatePos(
294                         new_pit, new_pos, new_id);
295         }
296 }
297
298
299 void LyXFunc::processKeySym(KeySymbol const & keysym, KeyModifier state)
300 {
301         LYXERR(Debug::KEY, "KeySym is " << keysym.getSymbolName());
302
303         // Do nothing if we have nothing (JMarc)
304         if (!keysym.isOK()) {
305                 LYXERR(Debug::KEY, "Empty kbd action (probably composing)");
306                 lyx_view_->restartCursor();
307                 return;
308         }
309
310         if (keysym.isModifier()) {
311                 LYXERR(Debug::KEY, "isModifier true");
312                 if (lyx_view_)
313                         lyx_view_->restartCursor();
314                 return;
315         }
316
317         //Encoding const * encoding = view()->cursor().getEncoding();
318         //encoded_last_key = keysym.getISOEncoded(encoding ? encoding->name() : "");
319         // FIXME: encoded_last_key shadows the member variable of the same
320         // name. Is that intended?
321         char_type encoded_last_key = keysym.getUCSEncoded();
322
323         // Do a one-deep top-level lookup for
324         // cancel and meta-fake keys. RVDK_PATCH_5
325         cancel_meta_seq.reset();
326
327         FuncRequest func = cancel_meta_seq.addkey(keysym, state);
328         LYXERR(Debug::KEY, "action first set to [" << func.action << ']');
329
330         // When not cancel or meta-fake, do the normal lookup.
331         // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
332         // Mostly, meta_fake_bit = NoModifier. RVDK_PATCH_5.
333         if ((func.action != LFUN_CANCEL) && (func.action != LFUN_META_PREFIX)) {
334                 // remove Caps Lock and Mod2 as a modifiers
335                 func = keyseq.addkey(keysym, (state | meta_fake_bit));
336                 LYXERR(Debug::KEY, "action now set to [" << func.action << ']');
337         }
338
339         // Dont remove this unless you know what you are doing.
340         meta_fake_bit = NoModifier;
341
342         // Can this happen now ?
343         if (func.action == LFUN_NOACTION)
344                 func = FuncRequest(LFUN_COMMAND_PREFIX);
345
346         LYXERR(Debug::KEY, " Key [action=" << func.action << "]["
347                 << keyseq.print(KeySequence::Portable) << ']');
348
349         // already here we know if it any point in going further
350         // why not return already here if action == -1 and
351         // num_bytes == 0? (Lgb)
352
353         if (keyseq.length() > 1)
354                 lyx_view_->message(keyseq.print(KeySequence::ForGui));
355
356
357         // Maybe user can only reach the key via holding down shift.
358         // Let's see. But only if shift is the only modifier
359         if (func.action == LFUN_UNKNOWN_ACTION && state == ShiftModifier) {
360                 LYXERR(Debug::KEY, "Trying without shift");
361                 func = keyseq.addkey(keysym, NoModifier);
362                 LYXERR(Debug::KEY, "Action now " << func.action);
363         }
364
365         if (func.action == LFUN_UNKNOWN_ACTION) {
366                 // Hmm, we didn't match any of the keysequences. See
367                 // if it's normal insertable text not already covered
368                 // by a binding
369                 if (keysym.isText() && keyseq.length() == 1) {
370                         LYXERR(Debug::KEY, "isText() is true, inserting.");
371                         func = FuncRequest(LFUN_SELF_INSERT,
372                                            FuncRequest::KEYBOARD);
373                 } else {
374                         LYXERR(Debug::KEY, "Unknown, !isText() - giving up");
375                         lyx_view_->message(_("Unknown function."));
376                         lyx_view_->restartCursor();
377                         return;
378                 }
379         }
380
381         if (func.action == LFUN_SELF_INSERT) {
382                 if (encoded_last_key != 0) {
383                         docstring const arg(1, encoded_last_key);
384                         dispatch(FuncRequest(LFUN_SELF_INSERT, arg,
385                                              FuncRequest::KEYBOARD));
386                         LYXERR(Debug::KEY, "SelfInsert arg[`" << to_utf8(arg) << "']");
387                 }
388         } else {
389                 dispatch(func);
390                 if (!lyx_view_)
391                         return;
392         }
393 }
394
395
396 FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
397 {
398         //lyxerr << "LyXFunc::getStatus: cmd: " << cmd << endl;
399         FuncStatus flag;
400
401         Buffer * buf = lyx_view_ ? lyx_view_->buffer() : 0;
402
403         if (cmd.action == LFUN_NOACTION) {
404                 flag.message(from_utf8(N_("Nothing to do")));
405                 flag.setEnabled(false);
406                 return flag;
407         }
408
409         switch (cmd.action) {
410         case LFUN_UNKNOWN_ACTION:
411                 flag.unknown(true);
412                 flag.setEnabled(false);
413                 break;
414
415         default:
416                 break;
417         }
418
419         if (flag.unknown()) {
420                 flag.message(from_utf8(N_("Unknown action")));
421                 return flag;
422         }
423
424         if (!flag.enabled()) {
425                 if (flag.message().empty())
426                         flag.message(from_utf8(N_("Command disabled")));
427                 return flag;
428         }
429
430         // Check whether we need a buffer
431         if (!lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer) && !buf) {
432                 // no, exit directly
433                 flag.message(from_utf8(N_("Command not allowed with"
434                                     "out any document open")));
435                 flag.setEnabled(false);
436                 return flag;
437         }
438
439         // I would really like to avoid having this switch and rather try to
440         // encode this in the function itself.
441         // -- And I'd rather let an inset decide which LFUNs it is willing
442         // to handle (Andre')
443         bool enable = true;
444         switch (cmd.action) {
445
446         case LFUN_BUFFER_TOGGLE_READ_ONLY:
447                 flag.setOnOff(buf->isReadonly());
448                 break;
449
450         case LFUN_BUFFER_SWITCH:
451                 // toggle on the current buffer, but do not toggle off
452                 // the other ones (is that a good idea?)
453                 if (buf && to_utf8(cmd.argument()) == buf->absFileName())
454                         flag.setOnOff(true);
455                 break;
456
457         case LFUN_BUFFER_CHKTEX:
458                 enable = buf->isLatex() && !lyxrc.chktex_command.empty();
459                 break;
460
461         case LFUN_BUILD_PROGRAM:
462                 enable = buf->isExportable("program");
463                 break;
464
465         case LFUN_VC_REGISTER:
466                 enable = !buf->lyxvc().inUse();
467                 break;
468         case LFUN_VC_CHECK_IN:
469                 enable = buf->lyxvc().checkInEnabled();
470                 break;
471         case LFUN_VC_CHECK_OUT:
472                 enable = buf->lyxvc().checkOutEnabled();
473                 break;
474         case LFUN_VC_REVERT:
475                 enable = buf->lyxvc().inUse();
476                 break;
477         case LFUN_VC_UNDO_LAST:
478                 enable = buf->lyxvc().undoLastEnabled();
479                 break;
480         case LFUN_BUFFER_RELOAD:
481                 enable = !buf->isUnnamed() && buf->fileName().exists()
482                         && (!buf->isClean() || buf->isExternallyModified(Buffer::timestamp_method));
483                 break;
484
485         case LFUN_CITATION_INSERT: {
486                 FuncRequest fr(LFUN_INSET_INSERT, "citation");
487                 enable = getStatus(fr).enabled();
488                 break;
489         }
490         
491         // This could be used for the no-GUI version. The GUI version is handled in
492         // LyXView::getStatus(). See above.
493         /*
494         case LFUN_BUFFER_WRITE:
495         case LFUN_BUFFER_WRITE_AS: {
496                 Buffer * b = theBufferList().getBuffer(FileName(cmd.getArg(0)));
497                 enable = b && (b->isUnnamed() || !b->isClean());
498                 break;
499         }
500         */
501
502         case LFUN_BUFFER_WRITE_ALL: {
503                 // We enable the command only if there are some modified buffers
504                 Buffer * first = theBufferList().first();
505                 enable = false;
506                 if (!first)
507                         break;
508                 Buffer * b = first;
509                 // We cannot use a for loop as the buffer list is a cycle.
510                 do {
511                         if (!b->isClean()) {
512                                 enable = true;
513                                 break;
514                         }
515                         b = theBufferList().next(b);
516                 } while (b != first); 
517                 break;
518         }
519
520         case LFUN_BOOKMARK_GOTO: {
521                 const unsigned int num = convert<unsigned int>(to_utf8(cmd.argument()));
522                 enable = theSession().bookmarks().isValid(num);
523                 break;
524         }
525
526         case LFUN_BOOKMARK_CLEAR:
527                 enable = theSession().bookmarks().hasValid();
528                 break;
529
530         // this one is difficult to get right. As a half-baked
531         // solution, we consider only the first action of the sequence
532         case LFUN_COMMAND_SEQUENCE: {
533                 // argument contains ';'-terminated commands
534                 string const firstcmd = token(to_utf8(cmd.argument()), ';', 0);
535                 FuncRequest func(lyxaction.lookupFunc(firstcmd));
536                 func.origin = cmd.origin;
537                 flag = getStatus(func);
538                 break;
539         }
540
541         // we want to check if at least one of these is enabled
542         case LFUN_COMMAND_ALTERNATIVES: {
543                 // argument contains ';'-terminated commands
544                 string arg = to_utf8(cmd.argument());
545                 while (!arg.empty()) {
546                         string first;
547                         arg = split(arg, first, ';');
548                         FuncRequest func(lyxaction.lookupFunc(first));
549                         func.origin = cmd.origin;
550                         flag = getStatus(func);
551                         // if this one is enabled, the whole thing is
552                         if (flag.enabled())
553                                 break;
554                 }
555                 break;
556         }
557
558         case LFUN_CALL: {
559                 FuncRequest func;
560                 string name = to_utf8(cmd.argument());
561                 if (theTopLevelCmdDef().lock(name, func)) {
562                         func.origin = cmd.origin;
563                         flag = getStatus(func);
564                         theTopLevelCmdDef().release(name);
565                 } else {
566                         // catch recursion or unknown command
567                         // definition. all operations until the
568                         // recursion or unknown command definition
569                         // occurs are performed, so set the state to
570                         // enabled
571                         enable = true;
572                 }
573                 break;
574         }
575
576         case LFUN_VC_COMMAND: {
577                 if (cmd.argument().empty())
578                         enable = false;
579
580                 if (!buf && contains(cmd.getArg(0), 'D'))
581                         enable = false;
582                 break;
583         }
584
585         case LFUN_MASTER_BUFFER_UPDATE:
586         case LFUN_MASTER_BUFFER_VIEW: 
587                 if (!buf->parent()) {
588                         enable = false;
589                         break;
590                 }
591         case LFUN_BUFFER_UPDATE:
592         case LFUN_BUFFER_VIEW: {
593                 string format = to_utf8(cmd.argument());
594                 if (cmd.argument().empty())
595                         format = buf->getDefaultOutputFormat();
596                 typedef vector<Format const *> Formats;
597                 Formats formats;
598                 formats = buf->exportableFormats(true);
599                 Formats::const_iterator fit = formats.begin();
600                 Formats::const_iterator end = formats.end();
601                 enable = false;
602                 for (; fit != end ; ++fit) {
603                         if ((*fit)->name() == format)
604                                 enable = true;
605                 }
606                 break;
607         }
608
609         case LFUN_WORD_FIND_FORWARD:
610         case LFUN_WORD_FIND_BACKWARD:
611         case LFUN_WORD_FINDADV:
612         case LFUN_COMMAND_PREFIX:
613         case LFUN_COMMAND_EXECUTE:
614         case LFUN_CANCEL:
615         case LFUN_META_PREFIX:
616         case LFUN_BUFFER_CLOSE:
617         case LFUN_BUFFER_IMPORT:
618         case LFUN_BUFFER_AUTO_SAVE:
619         case LFUN_RECONFIGURE:
620         case LFUN_HELP_OPEN:
621         case LFUN_DROP_LAYOUTS_CHOICE:
622         case LFUN_MENU_OPEN:
623         case LFUN_SERVER_GET_FILENAME:
624         case LFUN_SERVER_NOTIFY:
625         case LFUN_SERVER_GOTO_FILE_ROW:
626         case LFUN_DIALOG_HIDE:
627         case LFUN_DIALOG_DISCONNECT_INSET:
628         case LFUN_BUFFER_CHILD_OPEN:
629         case LFUN_CURSOR_FOLLOWS_SCROLLBAR_TOGGLE:
630         case LFUN_KEYMAP_OFF:
631         case LFUN_KEYMAP_PRIMARY:
632         case LFUN_KEYMAP_SECONDARY:
633         case LFUN_KEYMAP_TOGGLE:
634         case LFUN_REPEAT:
635         case LFUN_BUFFER_EXPORT_CUSTOM:
636         case LFUN_PREFERENCES_SAVE:
637         case LFUN_MESSAGE:
638         case LFUN_INSET_EDIT:
639         case LFUN_BUFFER_LANGUAGE:
640         case LFUN_TEXTCLASS_APPLY:
641         case LFUN_TEXTCLASS_LOAD:
642         case LFUN_BUFFER_SAVE_AS_DEFAULT:
643         case LFUN_BUFFER_PARAMS_APPLY:
644         case LFUN_LAYOUT_MODULES_CLEAR:
645         case LFUN_LAYOUT_MODULE_ADD:
646         case LFUN_LAYOUT_RELOAD:
647         case LFUN_LYXRC_APPLY:
648         case LFUN_BUFFER_NEXT:
649         case LFUN_BUFFER_PREVIOUS:
650                 // these are handled in our dispatch()
651                 break;
652
653         default:
654                 if (!theApp()) {
655                         enable = false;
656                         break;
657                 }
658                 if (theApp()->getStatus(cmd, flag))
659                         break;
660
661                 // Does the view know something?
662                 if (!lyx_view_) {
663                         enable = false;
664                         break;
665                 }
666                 if (lyx_view_->getStatus(cmd, flag))
667                         break;
668
669                 // If we do not have a BufferView, then other functions are disabled
670                 if (!view()) {
671                         enable = false;
672                         break;
673                 }
674
675                 // Is this a function that acts on inset at point?
676                 Inset * inset = view()->cursor().nextInset();
677                 if (lyxaction.funcHasFlag(cmd.action, LyXAction::AtPoint)
678                     && inset && inset->getStatus(view()->cursor(), cmd, flag))
679                         break;
680
681                 bool decided = getLocalStatus(view()->cursor(), cmd, flag);
682                 if (!decided)
683                         // try the BufferView
684                         decided = view()->getStatus(cmd, flag);
685                 if (!decided)
686                         // try the Buffer
687                         view()->buffer().getStatus(cmd, flag);
688         }
689
690         if (!enable)
691                 flag.setEnabled(false);
692
693         // Can we use a readonly buffer?
694         if (buf && buf->isReadonly()
695             && !lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly)
696             && !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)) {
697                 flag.message(from_utf8(N_("Document is read-only")));
698                 flag.setEnabled(false);
699         }
700
701         // Are we in a DELETED change-tracking region?
702         if (buf && view() 
703                 && lookupChangeType(view()->cursor(), true) == Change::DELETED
704             && !lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly)
705             && !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)) {
706                 flag.message(from_utf8(N_("This portion of the document is deleted.")));
707                 flag.setEnabled(false);
708         }
709
710         // the default error message if we disable the command
711         if (!flag.enabled() && flag.message().empty())
712                 flag.message(from_utf8(N_("Command disabled")));
713
714         return flag;
715 }
716
717
718 bool LyXFunc::ensureBufferClean(BufferView * bv)
719 {
720         Buffer & buf = bv->buffer();
721         if (buf.isClean() && !buf.isUnnamed())
722                 return true;
723
724         docstring const file = buf.fileName().displayName(30);
725         docstring title;
726         docstring text;
727         if (!buf.isUnnamed()) {
728                 text = bformat(_("The document %1$s has unsaved "
729                                              "changes.\n\nDo you want to save "
730                                              "the document?"), file);
731                 title = _("Save changed document?");
732                 
733         } else {
734                 text = bformat(_("The document %1$s has not been "
735                                              "saved yet.\n\nDo you want to save "
736                                              "the document?"), file);
737                 title = _("Save new document?");
738         }
739         int const ret = Alert::prompt(title, text, 0, 1, _("&Save"), _("&Cancel"));
740
741         if (ret == 0)
742                 lyx_view_->dispatch(FuncRequest(LFUN_BUFFER_WRITE));
743
744         return buf.isClean() && !buf.isUnnamed();
745 }
746
747
748 namespace {
749
750 bool loadLayoutFile(string const & name, string const & buf_path)
751 {
752         if (!LayoutFileList::get().haveClass(name)) {
753                 lyxerr << "Document class \"" << name
754                        << "\" does not exist."
755                        << endl;
756                 return false;
757         }
758
759         LayoutFile & tc = LayoutFileList::get()[name];
760         if (!tc.load(buf_path)) {
761                 docstring s = bformat(_("The document class %1$s "
762                                    "could not be loaded."), from_utf8(name));
763                 Alert::error(_("Could not load class"), s);
764                 return false;
765         }
766         return true;
767 }
768
769
770 void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new);
771
772 } //namespace anon
773
774
775 void LyXFunc::dispatch(FuncRequest const & cmd)
776 {
777         string const argument = to_utf8(cmd.argument());
778         FuncCode const action = cmd.action;
779
780         LYXERR(Debug::ACTION, "\nLyXFunc::dispatch: cmd: " << cmd);
781         //lyxerr << "LyXFunc::dispatch: cmd: " << cmd << endl;
782
783         // we have not done anything wrong yet.
784         errorstat = false;
785         dispatch_buffer.erase();
786
787         // redraw the screen at the end (first of the two drawing steps).
788         //This is done unless explicitely requested otherwise
789         Update::flags updateFlags = Update::FitCursor;
790
791         FuncStatus const flag = getStatus(cmd);
792         if (!flag.enabled()) {
793                 // We cannot use this function here
794                 LYXERR(Debug::ACTION, "LyXFunc::dispatch: "
795                        << lyxaction.getActionName(action)
796                        << " [" << action << "] is disabled at this location");
797                 setErrorMessage(flag.message());
798                 if (lyx_view_)
799                         lyx_view_->restartCursor();
800         } else {
801                 Buffer * buffer = lyx_view_ ? lyx_view_->buffer() : 0;
802                 switch (action) {
803
804                 case LFUN_WORD_FIND_FORWARD:
805                 case LFUN_WORD_FIND_BACKWARD: {
806                         LASSERT(lyx_view_ && lyx_view_->view(), /**/);
807                         static docstring last_search;
808                         docstring searched_string;
809
810                         if (!cmd.argument().empty()) {
811                                 last_search = cmd.argument();
812                                 searched_string = cmd.argument();
813                         } else {
814                                 searched_string = last_search;
815                         }
816
817                         if (searched_string.empty())
818                                 break;
819
820                         bool const fw = action == LFUN_WORD_FIND_FORWARD;
821                         docstring const data =
822                                 find2string(searched_string, true, false, fw);
823                         find(view(), FuncRequest(LFUN_WORD_FIND, data));
824                         break;
825                 }
826
827                 case LFUN_COMMAND_PREFIX:
828                         LASSERT(lyx_view_, /**/);
829                         lyx_view_->message(keyseq.printOptions(true));
830                         break;
831
832                 case LFUN_CANCEL:
833                         LASSERT(lyx_view_ && lyx_view_->view(), /**/);
834                         keyseq.reset();
835                         meta_fake_bit = NoModifier;
836                         if (buffer)
837                                 // cancel any selection
838                                 dispatch(FuncRequest(LFUN_MARK_OFF));
839                         setMessage(from_ascii(N_("Cancel")));
840                         break;
841
842                 case LFUN_META_PREFIX:
843                         meta_fake_bit = AltModifier;
844                         setMessage(keyseq.print(KeySequence::ForGui));
845                         break;
846
847                 case LFUN_BUFFER_TOGGLE_READ_ONLY: {
848                         LASSERT(lyx_view_ && lyx_view_->view() && buffer, /**/);
849                         if (buffer->lyxvc().inUse())
850                                 buffer->lyxvc().toggleReadOnly();
851                         else
852                                 buffer->setReadonly(!buffer->isReadonly());
853                         break;
854                 }
855
856                 // --- Menus -----------------------------------------------
857                 case LFUN_BUFFER_CLOSE:
858                         lyx_view_->closeBuffer();
859                         buffer = 0;
860                         updateFlags = Update::None;
861                         break;
862
863                 case LFUN_BUFFER_RELOAD: {
864                         LASSERT(lyx_view_ && buffer, /**/);
865                         docstring const file = makeDisplayPath(buffer->absFileName(), 20);
866                         docstring text = bformat(_("Any changes will be lost. Are you sure "
867                                                              "you want to revert to the saved version of the document %1$s?"), file);
868                         int const ret = Alert::prompt(_("Revert to saved document?"),
869                                 text, 1, 1, _("&Revert"), _("&Cancel"));
870
871                         if (ret == 0)
872                                 reloadBuffer();
873                         break;
874                 }
875
876                 case LFUN_BUFFER_UPDATE: {
877                         LASSERT(lyx_view_ && buffer, /**/);
878                         string format = argument;
879                         if (argument.empty())
880                                 format = buffer->getDefaultOutputFormat();
881                         buffer->doExport(format, true);
882                         break;
883                 }
884
885                 case LFUN_BUFFER_VIEW: {
886                         LASSERT(lyx_view_ && buffer, /**/);
887                         string format = argument;
888                         if (argument.empty())
889                                 format = buffer->getDefaultOutputFormat();
890                         buffer->preview(format);
891                         break;
892                 }
893
894                 case LFUN_MASTER_BUFFER_UPDATE: {
895                         LASSERT(lyx_view_ && buffer && buffer->masterBuffer(), /**/);
896                         string format = argument;
897                         if (argument.empty())
898                                 format = buffer->masterBuffer()->getDefaultOutputFormat();
899                         buffer->masterBuffer()->doExport(format, true);
900                         break;
901                 }
902
903                 case LFUN_MASTER_BUFFER_VIEW: {
904                         LASSERT(lyx_view_ && buffer && buffer->masterBuffer(), /**/);
905                         string format = argument;
906                         if (argument.empty())
907                                 format = buffer->masterBuffer()->getDefaultOutputFormat();
908                         buffer->masterBuffer()->preview(format);
909                         break;
910                 }
911
912                 case LFUN_BUILD_PROGRAM:
913                         LASSERT(lyx_view_ && buffer, /**/);
914                         buffer->doExport("program", true);
915                         break;
916
917                 case LFUN_BUFFER_CHKTEX:
918                         LASSERT(lyx_view_ && buffer, /**/);
919                         buffer->runChktex();
920                         break;
921
922                 case LFUN_BUFFER_EXPORT:
923                         LASSERT(lyx_view_ && buffer, /**/);
924                         if (argument == "custom")
925                                 dispatch(FuncRequest(LFUN_DIALOG_SHOW, "sendto"));
926                         else
927                                 buffer->doExport(argument, false);
928                         break;
929
930                 case LFUN_BUFFER_EXPORT_CUSTOM: {
931                         LASSERT(lyx_view_ && buffer, /**/);
932                         string format_name;
933                         string command = split(argument, format_name, ' ');
934                         Format const * format = formats.getFormat(format_name);
935                         if (!format) {
936                                 lyxerr << "Format \"" << format_name
937                                        << "\" not recognized!"
938                                        << endl;
939                                 break;
940                         }
941
942                         // The name of the file created by the conversion process
943                         string filename;
944
945                         // Output to filename
946                         if (format->name() == "lyx") {
947                                 string const latexname = buffer->latexName(false);
948                                 filename = changeExtension(latexname,
949                                                            format->extension());
950                                 filename = addName(buffer->temppath(), filename);
951
952                                 if (!buffer->writeFile(FileName(filename)))
953                                         break;
954
955                         } else {
956                                 buffer->doExport(format_name, true, filename);
957                         }
958
959                         // Substitute $$FName for filename
960                         if (!contains(command, "$$FName"))
961                                 command = "( " + command + " ) < $$FName";
962                         command = subst(command, "$$FName", filename);
963
964                         // Execute the command in the background
965                         Systemcall call;
966                         call.startscript(Systemcall::DontWait, command);
967                         break;
968                 }
969
970                 // FIXME: There is need for a command-line import.
971                 /*
972                 case LFUN_BUFFER_IMPORT:
973                         doImport(argument);
974                         break;
975                 */
976
977                 case LFUN_BUFFER_AUTO_SAVE:
978                         buffer->autoSave();
979                         break;
980
981                 case LFUN_RECONFIGURE:
982                         // argument is any additional parameter to the configure.py command
983                         reconfigure(lyx_view_, argument);
984                         break;
985
986                 case LFUN_HELP_OPEN: {
987                         if (lyx_view_ == 0)
988                                 theApp()->dispatch(FuncRequest(LFUN_WINDOW_NEW));
989                         string const arg = argument;
990                         if (arg.empty()) {
991                                 setErrorMessage(from_utf8(N_("Missing argument")));
992                                 break;
993                         }
994                         FileName fname = i18nLibFileSearch("doc", arg, "lyx");
995                         if (fname.empty()) 
996                                 fname = i18nLibFileSearch("examples", arg, "lyx");
997
998                         if (fname.empty()) {
999                                 lyxerr << "LyX: unable to find documentation file `"
1000                                                          << arg << "'. Bad installation?" << endl;
1001                                 break;
1002                         }
1003                         lyx_view_->message(bformat(_("Opening help file %1$s..."),
1004                                 makeDisplayPath(fname.absFilename())));
1005                         Buffer * buf = lyx_view_->loadDocument(fname, false);
1006                         if (buf) {
1007                                 buf->updateLabels();
1008                                 lyx_view_->setBuffer(buf);
1009                                 buf->errors("Parse");
1010                         }
1011                         updateFlags = Update::None;
1012                         break;
1013                 }
1014
1015                 // --- version control -------------------------------
1016                 case LFUN_VC_REGISTER:
1017                         LASSERT(lyx_view_ && buffer, /**/);
1018                         if (!ensureBufferClean(view()))
1019                                 break;
1020                         if (!buffer->lyxvc().inUse()) {
1021                                 if (buffer->lyxvc().registrer())
1022                                         reloadBuffer();
1023                         }
1024                         updateFlags = Update::Force;
1025                         break;
1026
1027                 case LFUN_VC_CHECK_IN:
1028                         LASSERT(lyx_view_ && buffer, /**/);
1029                         if (!ensureBufferClean(view()))
1030                                 break;
1031                         if (buffer->lyxvc().inUse()
1032                                         && !buffer->isReadonly()) {
1033                                 setMessage(from_utf8(buffer->lyxvc().checkIn()));
1034                                 reloadBuffer();
1035                         }
1036                         break;
1037
1038                 case LFUN_VC_CHECK_OUT:
1039                         LASSERT(lyx_view_ && buffer, /**/);
1040                         if (!ensureBufferClean(view()))
1041                                 break;
1042                         if (buffer->lyxvc().inUse()) {
1043                                 setMessage(from_utf8(buffer->lyxvc().checkOut()));
1044                                 reloadBuffer();
1045                         }
1046                         break;
1047
1048                 case LFUN_VC_REVERT:
1049                         LASSERT(lyx_view_ && buffer, /**/);
1050                         buffer->lyxvc().revert();
1051                         reloadBuffer();
1052                         break;
1053
1054                 case LFUN_VC_UNDO_LAST:
1055                         LASSERT(lyx_view_ && buffer, /**/);
1056                         buffer->lyxvc().undoLast();
1057                         reloadBuffer();
1058                         break;
1059
1060                 // --- lyxserver commands ----------------------------
1061                 case LFUN_SERVER_GET_FILENAME:
1062                         LASSERT(lyx_view_ && buffer, /**/);
1063                         setMessage(from_utf8(buffer->absFileName()));
1064                         LYXERR(Debug::INFO, "FNAME["
1065                                 << buffer->absFileName() << ']');
1066                         break;
1067
1068                 case LFUN_SERVER_NOTIFY:
1069                         dispatch_buffer = keyseq.print(KeySequence::Portable);
1070                         theServer().notifyClient(to_utf8(dispatch_buffer));
1071                         break;
1072
1073                 case LFUN_SERVER_GOTO_FILE_ROW: {
1074                         LASSERT(lyx_view_, /**/);
1075                         string file_name;
1076                         int row;
1077                         istringstream is(argument);
1078                         is >> file_name >> row;
1079                         Buffer * buf = 0;
1080                         bool loaded = false;
1081                         string const abstmp = package().temp_dir().absFilename();
1082                         string const realtmp = package().temp_dir().realPath();
1083                         // We have to use os::path_prefix_is() here, instead of
1084                         // simply prefixIs(), because the file name comes from
1085                         // an external application and may need case adjustment.
1086                         if (os::path_prefix_is(file_name, abstmp, os::CASE_ADJUSTED)
1087                             || os::path_prefix_is(file_name, realtmp, os::CASE_ADJUSTED)) {
1088                                 // Needed by inverse dvi search. If it is a file
1089                                 // in tmpdir, call the apropriated function.
1090                                 // If tmpdir is a symlink, we may have the real
1091                                 // path passed back, so we correct for that.
1092                                 if (!prefixIs(file_name, abstmp))
1093                                         file_name = subst(file_name, realtmp, abstmp);
1094                                 buf = theBufferList().getBufferFromTmp(file_name);
1095                         } else {
1096                                 // Must replace extension of the file to be .lyx
1097                                 // and get full path
1098                                 FileName const s = fileSearch(string(), changeExtension(file_name, ".lyx"), "lyx");
1099                                 // Either change buffer or load the file
1100                                 if (theBufferList().exists(s))
1101                                         buf = theBufferList().getBuffer(s);
1102                                 else if (s.exists()) {
1103                                         buf = lyx_view_->loadDocument(s);
1104                                         loaded = true;
1105                                 } else
1106                                         lyx_view_->message(bformat(
1107                                                 _("File does not exist: %1$s"),
1108                                                 makeDisplayPath(file_name)));
1109                         }
1110
1111                         if (!buf) {
1112                                 updateFlags = Update::None;
1113                                 break;
1114                         }
1115
1116                         buf->updateLabels();
1117                         lyx_view_->setBuffer(buf);
1118                         view()->setCursorFromRow(row);
1119                         if (loaded)
1120                                 buf->errors("Parse");
1121                         updateFlags = Update::FitCursor;
1122                         break;
1123                 }
1124
1125
1126                 case LFUN_DIALOG_SHOW_NEW_INSET: {
1127                         LASSERT(lyx_view_, /**/);
1128                         string const name = cmd.getArg(0);
1129                         InsetCode code = insetCode(name);
1130                         string data = trim(to_utf8(cmd.argument()).substr(name.size()));
1131                         bool insetCodeOK = true;
1132                         switch (code) {
1133                         case BIBITEM_CODE:
1134                         case BIBTEX_CODE:
1135                         case INDEX_CODE:
1136                         case LABEL_CODE:
1137                         case NOMENCL_CODE:
1138                         case NOMENCL_PRINT_CODE:
1139                         case REF_CODE:
1140                         case TOC_CODE:
1141                         case HYPERLINK_CODE: {
1142                                 InsetCommandParams p(code);
1143                                 data = InsetCommand::params2string(name, p);
1144                                 break;
1145                         }
1146                         case INCLUDE_CODE: {
1147                                 // data is the include type: one of "include",
1148                                 // "input", "verbatiminput" or "verbatiminput*"
1149                                 if (data.empty())
1150                                         // default type is requested
1151                                         data = "include";
1152                                 InsetCommandParams p(INCLUDE_CODE, data);
1153                                 data = InsetCommand::params2string("include", p);
1154                                 break;
1155                         }
1156                         case BOX_CODE: {
1157                                 // \c data == "Boxed" || "Frameless" etc
1158                                 InsetBoxParams p(data);
1159                                 data = InsetBox::params2string(p);
1160                                 break;
1161                         }
1162                         case BRANCH_CODE: {
1163                                 InsetBranchParams p;
1164                                 data = InsetBranch::params2string(p);
1165                                 break;
1166                         }
1167                         case CITE_CODE: {
1168                                 InsetCommandParams p(CITE_CODE);
1169                                 data = InsetCommand::params2string(name, p);
1170                                 break;
1171                         }
1172                         case ERT_CODE: {
1173                                 data = InsetERT::params2string(InsetCollapsable::Open);
1174                                 break;
1175                         }
1176                         case EXTERNAL_CODE: {
1177                                 InsetExternalParams p;
1178                                 data = InsetExternal::params2string(p, *buffer);
1179                                 break;
1180                         }
1181                         case FLOAT_CODE:  {
1182                                 InsetFloatParams p;
1183                                 data = InsetFloat::params2string(p);
1184                                 break;
1185                         }
1186                         case LISTINGS_CODE: {
1187                                 InsetListingsParams p;
1188                                 data = InsetListings::params2string(p);
1189                                 break;
1190                         }
1191                         case GRAPHICS_CODE: {
1192                                 InsetGraphicsParams p;
1193                                 data = InsetGraphics::params2string(p, *buffer);
1194                                 break;
1195                         }
1196                         case NOTE_CODE: {
1197                                 InsetNoteParams p;
1198                                 data = InsetNote::params2string(p);
1199                                 break;
1200                         }
1201                         case PHANTOM_CODE: {
1202                                 InsetPhantomParams p;
1203                                 data = InsetPhantom::params2string(p);
1204                                 break;
1205                         }
1206                         case SPACE_CODE: {
1207                                 InsetSpaceParams p;
1208                                 data = InsetSpace::params2string(p);
1209                                 break;
1210                         }
1211                         case VSPACE_CODE: {
1212                                 VSpace space;
1213                                 data = InsetVSpace::params2string(space);
1214                                 break;
1215                         }
1216                         case WRAP_CODE: {
1217                                 InsetWrapParams p;
1218                                 data = InsetWrap::params2string(p);
1219                                 break;
1220                         }
1221                         default:
1222                                 lyxerr << "Inset type '" << name << 
1223                                         "' not recognized in LFUN_DIALOG_SHOW_NEW_INSET" <<  endl;
1224                                 insetCodeOK = false;
1225                                 break;
1226                         } // end switch(code)
1227                         if (insetCodeOK)
1228                                 dispatch(FuncRequest(LFUN_DIALOG_SHOW, name + " " + data));
1229                         break;
1230                 }
1231
1232                 case LFUN_CITATION_INSERT: {
1233                         LASSERT(lyx_view_, /**/);
1234                         if (!argument.empty()) {
1235                                 // we can have one optional argument, delimited by '|'
1236                                 // citation-insert <key>|<text_before>
1237                                 // this should be enhanced to also support text_after
1238                                 // and citation style
1239                                 string arg = argument;
1240                                 string opt1;
1241                                 if (contains(argument, "|")) {
1242                                         arg = token(argument, '|', 0);
1243                                         opt1 = token(argument, '|', 1);
1244                                 }
1245                                 InsetCommandParams icp(CITE_CODE);
1246                                 icp["key"] = from_utf8(arg);
1247                                 if (!opt1.empty())
1248                                         icp["before"] = from_utf8(opt1);
1249                                 string icstr = InsetCommand::params2string("citation", icp);
1250                                 FuncRequest fr(LFUN_INSET_INSERT, icstr);
1251                                 dispatch(fr);
1252                         } else
1253                                 dispatch(FuncRequest(LFUN_DIALOG_SHOW_NEW_INSET, "citation"));
1254                         break;
1255                 }
1256
1257                 case LFUN_BUFFER_CHILD_OPEN: {
1258                         LASSERT(lyx_view_ && buffer, /**/);
1259                         FileName filename = makeAbsPath(argument, buffer->filePath());
1260                         view()->saveBookmark(false);
1261                         Buffer * child = 0;
1262                         bool parsed = false;
1263                         if (theBufferList().exists(filename)) {
1264                                 child = theBufferList().getBuffer(filename);
1265                         } else {
1266                                 setMessage(bformat(_("Opening child document %1$s..."),
1267                                         makeDisplayPath(filename.absFilename())));
1268                                 child = lyx_view_->loadDocument(filename, false);
1269                                 parsed = true;
1270                         }
1271                         if (child) {
1272                                 // Set the parent name of the child document.
1273                                 // This makes insertion of citations and references in the child work,
1274                                 // when the target is in the parent or another child document.
1275                                 child->setParent(buffer);
1276                                 child->masterBuffer()->updateLabels();
1277                                 lyx_view_->setBuffer(child);
1278                                 if (parsed)
1279                                         child->errors("Parse");
1280                         }
1281
1282                         // If a screen update is required (in case where auto_open is false), 
1283                         // setBuffer() would have taken care of it already. Otherwise we shall 
1284                         // reset the update flag because it can cause a circular problem.
1285                         // See bug 3970.
1286                         updateFlags = Update::None;
1287                         break;
1288                 }
1289
1290                 case LFUN_CURSOR_FOLLOWS_SCROLLBAR_TOGGLE:
1291                         LASSERT(lyx_view_, /**/);
1292                         lyxrc.cursor_follows_scrollbar = !lyxrc.cursor_follows_scrollbar;
1293                         break;
1294
1295                 case LFUN_KEYMAP_OFF:
1296                         LASSERT(lyx_view_ && lyx_view_->view(), /**/);
1297                         lyx_view_->view()->getIntl().keyMapOn(false);
1298                         break;
1299
1300                 case LFUN_KEYMAP_PRIMARY:
1301                         LASSERT(lyx_view_ && lyx_view_->view(), /**/);
1302                         lyx_view_->view()->getIntl().keyMapPrim();
1303                         break;
1304
1305                 case LFUN_KEYMAP_SECONDARY:
1306                         LASSERT(lyx_view_ && lyx_view_->view(), /**/);
1307                         lyx_view_->view()->getIntl().keyMapSec();
1308                         break;
1309
1310                 case LFUN_KEYMAP_TOGGLE:
1311                         LASSERT(lyx_view_ && lyx_view_->view(), /**/);
1312                         lyx_view_->view()->getIntl().toggleKeyMap();
1313                         break;
1314
1315                 case LFUN_REPEAT: {
1316                         // repeat command
1317                         string countstr;
1318                         string rest = split(argument, countstr, ' ');
1319                         istringstream is(countstr);
1320                         int count = 0;
1321                         is >> count;
1322                         //lyxerr << "repeat: count: " << count << " cmd: " << rest << endl;
1323                         for (int i = 0; i < count; ++i)
1324                                 dispatch(lyxaction.lookupFunc(rest));
1325                         break;
1326                 }
1327
1328                 case LFUN_COMMAND_SEQUENCE: {
1329                         // argument contains ';'-terminated commands
1330                         string arg = argument;
1331                         if (theBufferList().isLoaded(buffer))
1332                                 buffer->undo().beginUndoGroup();
1333                         while (!arg.empty()) {
1334                                 string first;
1335                                 arg = split(arg, first, ';');
1336                                 FuncRequest func(lyxaction.lookupFunc(first));
1337                                 func.origin = cmd.origin;
1338                                 dispatch(func);
1339                         }
1340                         if (theBufferList().isLoaded(buffer))
1341                                 buffer->undo().endUndoGroup();
1342                         break;
1343                 }
1344
1345                 case LFUN_COMMAND_ALTERNATIVES: {
1346                         // argument contains ';'-terminated commands
1347                         string arg = argument;
1348                         while (!arg.empty()) {
1349                                 string first;
1350                                 arg = split(arg, first, ';');
1351                                 FuncRequest func(lyxaction.lookupFunc(first));
1352                                 func.origin = cmd.origin;
1353                                 FuncStatus stat = getStatus(func);
1354                                 if (stat.enabled()) {
1355                                         dispatch(func);
1356                                         break;
1357                                 }
1358                         }
1359                         break;
1360                 }
1361
1362                 case LFUN_CALL: {
1363                         FuncRequest func;
1364                         if (theTopLevelCmdDef().lock(argument, func)) {
1365                                 func.origin = cmd.origin;
1366                                 dispatch(func);
1367                                 theTopLevelCmdDef().release(argument);
1368                         } else {
1369                                 if (func.action == LFUN_UNKNOWN_ACTION) {
1370                                         // unknown command definition
1371                                         lyxerr << "Warning: unknown command definition `"
1372                                                    << argument << "'"
1373                                                    << endl;
1374                                 } else {
1375                                         // recursion detected
1376                                         lyxerr << "Warning: Recursion in the command definition `"
1377                                                    << argument << "' detected"
1378                                                    << endl;
1379                                 }
1380                         }
1381                         break;
1382                 }
1383
1384                 case LFUN_PREFERENCES_SAVE: {
1385                         lyxrc.write(makeAbsPath("preferences",
1386                                                 package().user_support().absFilename()),
1387                                     false);
1388                         break;
1389                 }
1390
1391                 case LFUN_MESSAGE:
1392                         LASSERT(lyx_view_, /**/);
1393                         lyx_view_->message(from_utf8(argument));
1394                         break;
1395
1396                 case LFUN_BUFFER_LANGUAGE: {
1397                         LASSERT(lyx_view_, /**/);
1398                         Language const * oldL = buffer->params().language;
1399                         Language const * newL = languages.getLanguage(argument);
1400                         if (!newL || oldL == newL)
1401                                 break;
1402
1403                         if (oldL->rightToLeft() == newL->rightToLeft()
1404                             && !buffer->isMultiLingual())
1405                                 buffer->changeLanguage(oldL, newL);
1406                         break;
1407                 }
1408
1409                 case LFUN_BUFFER_SAVE_AS_DEFAULT: {
1410                         string const fname =
1411                                 addName(addPath(package().user_support().absFilename(), "templates/"),
1412                                         "defaults.lyx");
1413                         Buffer defaults(fname);
1414
1415                         istringstream ss(argument);
1416                         Lexer lex;
1417                         lex.setStream(ss);
1418                         int const unknown_tokens = defaults.readHeader(lex);
1419
1420                         if (unknown_tokens != 0) {
1421                                 lyxerr << "Warning in LFUN_BUFFER_SAVE_AS_DEFAULT!\n"
1422                                        << unknown_tokens << " unknown token"
1423                                        << (unknown_tokens == 1 ? "" : "s")
1424                                        << endl;
1425                         }
1426
1427                         if (defaults.writeFile(FileName(defaults.absFileName())))
1428                                 setMessage(bformat(_("Document defaults saved in %1$s"),
1429                                                    makeDisplayPath(fname)));
1430                         else
1431                                 setErrorMessage(from_ascii(N_("Unable to save document defaults")));
1432                         break;
1433                 }
1434
1435                 case LFUN_BUFFER_PARAMS_APPLY: {
1436                         LASSERT(lyx_view_, /**/);
1437                         
1438                         DocumentClass const * const oldClass = buffer->params().documentClassPtr();
1439                         Cursor & cur = view()->cursor();
1440                         cur.recordUndoFullDocument();
1441                         
1442                         istringstream ss(argument);
1443                         Lexer lex;
1444                         lex.setStream(ss);
1445                         int const unknown_tokens = buffer->readHeader(lex);
1446
1447                         if (unknown_tokens != 0) {
1448                                 lyxerr << "Warning in LFUN_BUFFER_PARAMS_APPLY!\n"
1449                                                 << unknown_tokens << " unknown token"
1450                                                 << (unknown_tokens == 1 ? "" : "s")
1451                                                 << endl;
1452                         }
1453                         
1454                         updateLayout(oldClass, buffer);
1455                         
1456                         updateFlags = Update::Force | Update::FitCursor;
1457                         // We are most certainly here because of a change in the document
1458                         // It is then better to make sure that all dialogs are in sync with
1459                         // current document settings. LyXView::restartCursor() achieve this.
1460                         lyx_view_->restartCursor();
1461                         break;
1462                 }
1463                 
1464                 case LFUN_LAYOUT_MODULES_CLEAR: {
1465                         LASSERT(lyx_view_, /**/);
1466                         DocumentClass const * const oldClass = buffer->params().documentClassPtr();
1467                         view()->cursor().recordUndoFullDocument();
1468                         buffer->params().clearLayoutModules();
1469                         buffer->params().makeDocumentClass();
1470                         updateLayout(oldClass, buffer);
1471                         updateFlags = Update::Force | Update::FitCursor;
1472                         break;
1473                 }
1474                 
1475                 case LFUN_LAYOUT_MODULE_ADD: {
1476                         LASSERT(lyx_view_, /**/);
1477                         BufferParams const & params = buffer->params();
1478                         if (!params.moduleCanBeAdded(argument)) {
1479                                 LYXERR0("Module `" << argument << 
1480                                                 "' cannot be added due to failed requirements or "
1481                                                 "conflicts with installed modules.");
1482                                 break;
1483                         }
1484                         DocumentClass const * const oldClass = params.documentClassPtr();
1485                         view()->cursor().recordUndoFullDocument();
1486                         buffer->params().addLayoutModule(argument);
1487                         buffer->params().makeDocumentClass();
1488                         updateLayout(oldClass, buffer);
1489                         updateFlags = Update::Force | Update::FitCursor;
1490                         break;
1491                 }
1492
1493                 case LFUN_TEXTCLASS_APPLY: {
1494                         LASSERT(lyx_view_, /**/);
1495
1496                         if (!loadLayoutFile(argument, buffer->temppath()) &&
1497                                 !loadLayoutFile(argument, buffer->filePath()))
1498                                 break;
1499
1500                         LayoutFile const * old_layout = buffer->params().baseClass();
1501                         LayoutFile const * new_layout = &(LayoutFileList::get()[argument]);
1502
1503                         if (old_layout == new_layout)
1504                                 // nothing to do
1505                                 break;
1506
1507                         //Save the old, possibly modular, layout for use in conversion.
1508                         DocumentClass const * const oldDocClass = buffer->params().documentClassPtr();
1509                         view()->cursor().recordUndoFullDocument();
1510                         buffer->params().setBaseClass(argument);
1511                         buffer->params().makeDocumentClass();
1512                         updateLayout(oldDocClass, buffer);
1513                         updateFlags = Update::Force | Update::FitCursor;
1514                         break;
1515                 }
1516                 
1517                 case LFUN_LAYOUT_RELOAD: {
1518                         LASSERT(lyx_view_, /**/);
1519                         DocumentClass const * const oldClass = buffer->params().documentClassPtr();
1520                         LayoutFileIndex bc = buffer->params().baseClassID();
1521                         LayoutFileList::get().reset(bc);
1522                         buffer->params().setBaseClass(bc);
1523                         buffer->params().makeDocumentClass();
1524                         updateLayout(oldClass, buffer);
1525                         updateFlags = Update::Force | Update::FitCursor;
1526                         break;
1527                 }
1528
1529                 case LFUN_TEXTCLASS_LOAD:
1530                         loadLayoutFile(argument, buffer->temppath()) ||
1531                         loadLayoutFile(argument, buffer->filePath());
1532                         break;
1533
1534                 case LFUN_LYXRC_APPLY: {
1535                         LyXRC const lyxrc_orig = lyxrc;
1536
1537                         istringstream ss(argument);
1538                         bool const success = lyxrc.read(ss) == 0;
1539
1540                         if (!success) {
1541                                 lyxerr << "Warning in LFUN_LYXRC_APPLY!\n"
1542                                        << "Unable to read lyxrc data"
1543                                        << endl;
1544                                 break;
1545                         }
1546
1547                         actOnUpdatedPrefs(lyxrc_orig, lyxrc);
1548
1549                         theApp()->resetGui();
1550
1551                         /// We force the redraw in any case because there might be
1552                         /// some screen font changes.
1553                         /// FIXME: only the current view will be updated. the Gui
1554                         /// class is able to furnish the list of views.
1555                         updateFlags = Update::Force;
1556                         break;
1557                 }
1558
1559                 case LFUN_BOOKMARK_GOTO:
1560                         // go to bookmark, open unopened file and switch to buffer if necessary
1561                         gotoBookmark(convert<unsigned int>(to_utf8(cmd.argument())), true, true);
1562                         updateFlags = Update::FitCursor;
1563                         break;
1564
1565                 case LFUN_BOOKMARK_CLEAR:
1566                         theSession().bookmarks().clear();
1567                         break;
1568
1569                 case LFUN_VC_COMMAND: {
1570                         string flag = cmd.getArg(0);
1571                         if (buffer && contains(flag, 'R') && !ensureBufferClean(view()))
1572                                 break;
1573                         docstring message;
1574                         if (contains(flag, 'M'))
1575                                 if (!Alert::askForText(message, _("LyX VC: Log Message")))
1576                                         break;
1577
1578                         string path = cmd.getArg(1);
1579                         if (contains(path, "$$p") && buffer)
1580                                 path = subst(path, "$$p", buffer->filePath());
1581                         LYXERR(Debug::LYXVC, "Directory: " << path);
1582                         FileName pp(path);
1583                         if (!pp.isReadableDirectory()) {
1584                                 lyxerr << _("Directory is not accessible.") << endl;
1585                                 break;
1586                         }
1587                         support::PathChanger p(pp);
1588
1589                         string command = cmd.getArg(2);
1590                         if (command.empty())
1591                                 break;
1592                         if (buffer) {
1593                                 command = subst(command, "$$i", buffer->absFileName());
1594                                 command = subst(command, "$$p", buffer->filePath());
1595                         }
1596                         command = subst(command, "$$m", to_utf8(message));
1597                         LYXERR(Debug::LYXVC, "Command: " << command);
1598                         Systemcall one;
1599                         one.startscript(Systemcall::Wait, command);
1600
1601                         if (!buffer)
1602                                 break;
1603                         if (contains(flag, 'I'))
1604                                 buffer->markDirty();
1605                         if (contains(flag, 'R'))
1606                                 reloadBuffer();
1607
1608                         break;
1609                 }
1610
1611                 default:
1612                         LASSERT(theApp(), /**/);
1613                         // Let the frontend dispatch its own actions.
1614                         if (theApp()->dispatch(cmd))
1615                                 // Nothing more to do.
1616                                 return;
1617
1618                         // Everything below is only for active lyx_view_
1619                         if (lyx_view_ == 0)
1620                                 break;
1621
1622                         // Start an undo group. This may be needed for
1623                         // some stuff like inset-apply on labels.
1624                         if (theBufferList().isLoaded(buffer))
1625                                 buffer->undo().beginUndoGroup();
1626                                 
1627                         // Let the current LyXView dispatch its own actions.
1628                         if (lyx_view_->dispatch(cmd)) {
1629                                 if (lyx_view_->view()) {
1630                                         updateFlags = lyx_view_->view()->cursor().result().update();
1631                                         if (theBufferList().isLoaded(buffer))
1632                                                 buffer->undo().endUndoGroup();
1633                                 }
1634                                 break;
1635                         }
1636
1637                         LASSERT(lyx_view_->view(), /**/);
1638
1639                         // Let the current BufferView dispatch its own actions.
1640                         if (view()->dispatch(cmd)) {
1641                                 // The BufferView took care of its own updates if needed.
1642                                 updateFlags = Update::None;
1643                                 if (theBufferList().isLoaded(buffer))
1644                                         buffer->undo().endUndoGroup();
1645                                 break;
1646                         }
1647
1648                         // OK, so try the Buffer itself
1649                         DispatchResult dr;
1650                         view()->buffer().dispatch(cmd, dr);
1651                         if (dr.dispatched()) {
1652                                 updateFlags = dr.update();
1653                                 break;
1654                         }
1655
1656                         // Is this a function that acts on inset at point?
1657                         Inset * inset = view()->cursor().nextInset();
1658                         if (lyxaction.funcHasFlag(action, LyXAction::AtPoint)
1659                             && inset) {
1660                                 view()->cursor().result().dispatched(true);
1661                                 view()->cursor().result().update(Update::FitCursor | Update::Force);
1662                                 FuncRequest tmpcmd = cmd;
1663                                 inset->dispatch(view()->cursor(), tmpcmd);
1664                                 if (view()->cursor().result().dispatched()) {
1665                                         updateFlags = view()->cursor().result().update();
1666                                         break;
1667                                 }
1668                         }
1669
1670                         // Let the current Cursor dispatch its own actions.
1671                         Cursor old = view()->cursor();
1672                         view()->cursor().getPos(cursorPosBeforeDispatchX_,
1673                                                 cursorPosBeforeDispatchY_);
1674                         view()->cursor().dispatch(cmd);
1675
1676                         // notify insets we just left
1677                         if (view()->cursor() != old) {
1678                                 old.fixIfBroken();
1679                                 bool badcursor = notifyCursorLeavesOrEnters(old, view()->cursor());
1680                                 if (badcursor)
1681                                         view()->cursor().fixIfBroken();
1682                         }
1683
1684                         if (theBufferList().isLoaded(buffer))
1685                                 buffer->undo().endUndoGroup();
1686
1687                         // update completion. We do it here and not in
1688                         // processKeySym to avoid another redraw just for a
1689                         // changed inline completion
1690                         if (cmd.origin == FuncRequest::KEYBOARD) {
1691                                 if (cmd.action == LFUN_SELF_INSERT)
1692                                         lyx_view_->updateCompletion(view()->cursor(), true, true);
1693                                 else if (cmd.action == LFUN_CHAR_DELETE_BACKWARD)
1694                                         lyx_view_->updateCompletion(view()->cursor(), false, true);
1695                                 else
1696                                         lyx_view_->updateCompletion(view()->cursor(), false, false);
1697                         }
1698
1699                         updateFlags = view()->cursor().result().update();
1700                 }
1701
1702                 // if we executed a mutating lfun, mark the buffer as dirty
1703                 if (theBufferList().isLoaded(buffer) && flag.enabled()
1704                     && !lyxaction.funcHasFlag(action, LyXAction::NoBuffer)
1705                     && !lyxaction.funcHasFlag(action, LyXAction::ReadOnly))
1706                         buffer->markDirty();                    
1707
1708                 if (lyx_view_ && lyx_view_->buffer()) {
1709                         // BufferView::update() updates the ViewMetricsInfo and
1710                         // also initializes the position cache for all insets in
1711                         // (at least partially) visible top-level paragraphs.
1712                         // We will redraw the screen only if needed.
1713                         view()->processUpdateFlags(updateFlags);
1714
1715                         // Do we have a selection?
1716                         theSelection().haveSelection(view()->cursor().selection());
1717                         
1718                         // update gui
1719                         lyx_view_->restartCursor();
1720                 }
1721         }
1722         if (lyx_view_) {
1723                 // Some messages may already be translated, so we cannot use _()
1724                 sendDispatchMessage(translateIfPossible(getMessage()), cmd);
1725         }
1726 }
1727
1728
1729 void LyXFunc::sendDispatchMessage(docstring const & msg, FuncRequest const & cmd)
1730 {
1731         const bool verbose = (cmd.origin == FuncRequest::MENU
1732                               || cmd.origin == FuncRequest::TOOLBAR
1733                               || cmd.origin == FuncRequest::COMMANDBUFFER);
1734
1735         if (cmd.action == LFUN_SELF_INSERT || !verbose) {
1736                 LYXERR(Debug::ACTION, "dispatch msg is " << to_utf8(msg));
1737                 if (!msg.empty())
1738                         lyx_view_->message(msg);
1739                 return;
1740         }
1741
1742         docstring dispatch_msg = msg;
1743         if (!dispatch_msg.empty())
1744                 dispatch_msg += ' ';
1745
1746         docstring comname = from_utf8(lyxaction.getActionName(cmd.action));
1747
1748         bool argsadded = false;
1749
1750         if (!cmd.argument().empty()) {
1751                 if (cmd.action != LFUN_UNKNOWN_ACTION) {
1752                         comname += ' ' + cmd.argument();
1753                         argsadded = true;
1754                 }
1755         }
1756
1757         docstring const shortcuts = theTopLevelKeymap().printBindings(cmd, KeySequence::ForGui);
1758
1759         if (!shortcuts.empty())
1760                 comname += ": " + shortcuts;
1761         else if (!argsadded && !cmd.argument().empty())
1762                 comname += ' ' + cmd.argument();
1763
1764         if (!comname.empty()) {
1765                 comname = rtrim(comname);
1766                 dispatch_msg += '(' + rtrim(comname) + ')';
1767         }
1768
1769         LYXERR(Debug::ACTION, "verbose dispatch msg " << to_utf8(dispatch_msg));
1770         if (!dispatch_msg.empty())
1771                 lyx_view_->message(dispatch_msg);
1772 }
1773
1774
1775 void LyXFunc::reloadBuffer()
1776 {
1777         FileName filename = lyx_view_->buffer()->fileName();
1778         // The user has already confirmed that the changes, if any, should
1779         // be discarded. So we just release the Buffer and don't call closeBuffer();
1780         theBufferList().release(lyx_view_->buffer());
1781         // if the lyx_view_ has been destroyed, create a new one
1782         if (!lyx_view_)
1783                 theApp()->dispatch(FuncRequest(LFUN_WINDOW_NEW));
1784         Buffer * buf = lyx_view_->loadDocument(filename);
1785         docstring const disp_fn = makeDisplayPath(filename.absFilename());
1786         docstring str;
1787         if (buf) {
1788                 buf->updateLabels();
1789                 lyx_view_->setBuffer(buf);
1790                 buf->errors("Parse");
1791                 str = bformat(_("Document %1$s reloaded."), disp_fn);
1792         } else {
1793                 str = bformat(_("Could not reload document %1$s"), disp_fn);
1794         }
1795         lyx_view_->message(str);
1796 }
1797
1798 // Each "lyx_view_" should have it's own message method. lyxview and
1799 // the minibuffer would use the minibuffer, but lyxserver would
1800 // send an ERROR signal to its client.  Alejandro 970603
1801 // This function is bit problematic when it comes to NLS, to make the
1802 // lyx servers client be language indepenent we must not translate
1803 // strings sent to this func.
1804 void LyXFunc::setErrorMessage(docstring const & m) const
1805 {
1806         dispatch_buffer = m;
1807         errorstat = true;
1808 }
1809
1810
1811 void LyXFunc::setMessage(docstring const & m) const
1812 {
1813         dispatch_buffer = m;
1814 }
1815
1816
1817 docstring LyXFunc::viewStatusMessage()
1818 {
1819         // When meta-fake key is pressed, show the key sequence so far + "M-".
1820         if (wasMetaKey())
1821                 return keyseq.print(KeySequence::ForGui) + "M-";
1822
1823         // Else, when a non-complete key sequence is pressed,
1824         // show the available options.
1825         if (keyseq.length() > 0 && !keyseq.deleted())
1826                 return keyseq.printOptions(true);
1827
1828         LASSERT(lyx_view_, /**/);
1829         if (!lyx_view_->buffer())
1830                 return _("Welcome to LyX!");
1831
1832         return view()->cursor().currentState();
1833 }
1834
1835
1836 BufferView * LyXFunc::view() const
1837 {
1838         LASSERT(lyx_view_, /**/);
1839         return lyx_view_->view();
1840 }
1841
1842
1843 bool LyXFunc::wasMetaKey() const
1844 {
1845         return (meta_fake_bit != NoModifier);
1846 }
1847
1848
1849 void LyXFunc::updateLayout(DocumentClass const * const oldlayout, Buffer * buf)
1850 {
1851         lyx_view_->message(_("Converting document to new document class..."));
1852         
1853         StableDocIterator backcur(view()->cursor());
1854         ErrorList & el = buf->errorList("Class Switch");
1855         cap::switchBetweenClasses(
1856                         oldlayout, buf->params().documentClassPtr(),
1857                         static_cast<InsetText &>(buf->inset()), el);
1858
1859         view()->setCursor(backcur.asDocIterator(buf));
1860
1861         buf->errors("Class Switch");
1862         buf->updateLabels();
1863 }
1864
1865
1866 namespace {
1867
1868 void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
1869 {
1870         // Why the switch you might ask. It is a trick to ensure that all
1871         // the elements in the LyXRCTags enum is handled. As you can see
1872         // there are no breaks at all. So it is just a huge fall-through.
1873         // The nice thing is that we will get a warning from the compiler
1874         // if we forget an element.
1875         LyXRC::LyXRCTags tag = LyXRC::RC_LAST;
1876         switch (tag) {
1877         case LyXRC::RC_ACCEPT_COMPOUND:
1878         case LyXRC::RC_ALT_LANG:
1879         case LyXRC::RC_PLAINTEXT_LINELEN:
1880         case LyXRC::RC_PLAINTEXT_ROFF_COMMAND:
1881         case LyXRC::RC_AUTOCORRECTION_MATH:
1882         case LyXRC::RC_AUTOREGIONDELETE:
1883         case LyXRC::RC_AUTORESET_OPTIONS:
1884         case LyXRC::RC_AUTOSAVE:
1885         case LyXRC::RC_AUTO_NUMBER:
1886         case LyXRC::RC_BACKUPDIR_PATH:
1887         case LyXRC::RC_BIBTEX_ALTERNATIVES:
1888         case LyXRC::RC_BIBTEX_COMMAND:
1889         case LyXRC::RC_BINDFILE:
1890         case LyXRC::RC_CHECKLASTFILES:
1891         case LyXRC::RC_COMPLETION_CURSOR_TEXT:
1892         case LyXRC::RC_COMPLETION_INLINE_DELAY:
1893         case LyXRC::RC_COMPLETION_INLINE_DOTS:
1894         case LyXRC::RC_COMPLETION_INLINE_MATH:
1895         case LyXRC::RC_COMPLETION_INLINE_TEXT:
1896         case LyXRC::RC_COMPLETION_POPUP_AFTER_COMPLETE:
1897         case LyXRC::RC_COMPLETION_POPUP_DELAY:
1898         case LyXRC::RC_COMPLETION_POPUP_MATH:
1899         case LyXRC::RC_COMPLETION_POPUP_TEXT:
1900         case LyXRC::RC_USELASTFILEPOS:
1901         case LyXRC::RC_LOADSESSION:
1902         case LyXRC::RC_CHKTEX_COMMAND:
1903         case LyXRC::RC_CONVERTER:
1904         case LyXRC::RC_CONVERTER_CACHE_MAXAGE:
1905         case LyXRC::RC_COPIER:
1906         case LyXRC::RC_CURSOR_FOLLOWS_SCROLLBAR:
1907         case LyXRC::RC_SCROLL_BELOW_DOCUMENT:
1908         case LyXRC::RC_DATE_INSERT_FORMAT:
1909         case LyXRC::RC_DEFAULT_LANGUAGE:
1910         case LyXRC::RC_GUI_LANGUAGE:
1911         case LyXRC::RC_DEFAULT_PAPERSIZE:
1912         case LyXRC::RC_DEFAULT_VIEW_FORMAT:
1913         case LyXRC::RC_DEFFILE:
1914         case LyXRC::RC_DIALOGS_ICONIFY_WITH_MAIN:
1915         case LyXRC::RC_DISPLAY_GRAPHICS:
1916         case LyXRC::RC_DOCUMENTPATH:
1917                 if (lyxrc_orig.document_path != lyxrc_new.document_path) {
1918                         FileName path(lyxrc_new.document_path);
1919                         if (path.exists() && path.isDirectory())
1920                                 package().document_dir() = FileName(lyxrc.document_path);
1921                 }
1922         case LyXRC::RC_ESC_CHARS:
1923         case LyXRC::RC_EXAMPLEPATH:
1924         case LyXRC::RC_FONT_ENCODING:
1925         case LyXRC::RC_FORMAT:
1926         case LyXRC::RC_GROUP_LAYOUTS:
1927         case LyXRC::RC_INDEX_ALTERNATIVES:
1928         case LyXRC::RC_INDEX_COMMAND:
1929         case LyXRC::RC_JBIBTEX_COMMAND:
1930         case LyXRC::RC_JINDEX_COMMAND:
1931         case LyXRC::RC_NOMENCL_COMMAND:
1932         case LyXRC::RC_INPUT:
1933         case LyXRC::RC_KBMAP:
1934         case LyXRC::RC_KBMAP_PRIMARY:
1935         case LyXRC::RC_KBMAP_SECONDARY:
1936         case LyXRC::RC_LABEL_INIT_LENGTH:
1937         case LyXRC::RC_LANGUAGE_AUTO_BEGIN:
1938         case LyXRC::RC_LANGUAGE_AUTO_END:
1939         case LyXRC::RC_LANGUAGE_COMMAND_BEGIN:
1940         case LyXRC::RC_LANGUAGE_COMMAND_END:
1941         case LyXRC::RC_LANGUAGE_COMMAND_LOCAL:
1942         case LyXRC::RC_LANGUAGE_GLOBAL_OPTIONS:
1943         case LyXRC::RC_LANGUAGE_PACKAGE:
1944         case LyXRC::RC_LANGUAGE_USE_BABEL:
1945         case LyXRC::RC_MAC_LIKE_WORD_MOVEMENT:
1946         case LyXRC::RC_MACRO_EDIT_STYLE:
1947         case LyXRC::RC_MAKE_BACKUP:
1948         case LyXRC::RC_MARK_FOREIGN_LANGUAGE:
1949         case LyXRC::RC_MOUSE_WHEEL_SPEED:
1950         case LyXRC::RC_NUMLASTFILES:
1951         case LyXRC::RC_PATH_PREFIX:
1952                 if (lyxrc_orig.path_prefix != lyxrc_new.path_prefix) {
1953                         prependEnvPath("PATH", lyxrc.path_prefix);
1954                 }
1955         case LyXRC::RC_PERS_DICT:
1956         case LyXRC::RC_PREVIEW:
1957         case LyXRC::RC_PREVIEW_HASHED_LABELS:
1958         case LyXRC::RC_PREVIEW_SCALE_FACTOR:
1959         case LyXRC::RC_PRINTCOLLCOPIESFLAG:
1960         case LyXRC::RC_PRINTCOPIESFLAG:
1961         case LyXRC::RC_PRINTER:
1962         case LyXRC::RC_PRINTEVENPAGEFLAG:
1963         case LyXRC::RC_PRINTEXSTRAOPTIONS:
1964         case LyXRC::RC_PRINTFILEEXTENSION:
1965         case LyXRC::RC_PRINTLANDSCAPEFLAG:
1966         case LyXRC::RC_PRINTODDPAGEFLAG:
1967         case LyXRC::RC_PRINTPAGERANGEFLAG:
1968         case LyXRC::RC_PRINTPAPERDIMENSIONFLAG:
1969         case LyXRC::RC_PRINTPAPERFLAG:
1970         case LyXRC::RC_PRINTREVERSEFLAG:
1971         case LyXRC::RC_PRINTSPOOL_COMMAND:
1972         case LyXRC::RC_PRINTSPOOL_PRINTERPREFIX:
1973         case LyXRC::RC_PRINTTOFILE:
1974         case LyXRC::RC_PRINTTOPRINTER:
1975         case LyXRC::RC_PRINT_ADAPTOUTPUT:
1976         case LyXRC::RC_PRINT_COMMAND:
1977         case LyXRC::RC_RTL_SUPPORT:
1978         case LyXRC::RC_SCREEN_DPI:
1979         case LyXRC::RC_SCREEN_FONT_ROMAN:
1980         case LyXRC::RC_SCREEN_FONT_ROMAN_FOUNDRY:
1981         case LyXRC::RC_SCREEN_FONT_SANS:
1982         case LyXRC::RC_SCREEN_FONT_SANS_FOUNDRY:
1983         case LyXRC::RC_SCREEN_FONT_SCALABLE:
1984         case LyXRC::RC_SCREEN_FONT_SIZES:
1985         case LyXRC::RC_SCREEN_FONT_TYPEWRITER:
1986         case LyXRC::RC_SCREEN_FONT_TYPEWRITER_FOUNDRY:
1987         case LyXRC::RC_GEOMETRY_SESSION:
1988         case LyXRC::RC_SCREEN_ZOOM:
1989         case LyXRC::RC_SERVERPIPE:
1990         case LyXRC::RC_SET_COLOR:
1991         case LyXRC::RC_SHOW_BANNER:
1992         case LyXRC::RC_OPEN_BUFFERS_IN_TABS:
1993         case LyXRC::RC_SPELL_COMMAND:
1994         case LyXRC::RC_SPELLCHECK_CONTINUOUSLY:
1995         case LyXRC::RC_SPLITINDEX_COMMAND:
1996         case LyXRC::RC_TEMPDIRPATH:
1997         case LyXRC::RC_TEMPLATEPATH:
1998         case LyXRC::RC_TEX_ALLOWS_SPACES:
1999         case LyXRC::RC_TEX_EXPECTS_WINDOWS_PATHS:
2000                 if (lyxrc_orig.windows_style_tex_paths != lyxrc_new.windows_style_tex_paths) {
2001                         os::windows_style_tex_paths(lyxrc_new.windows_style_tex_paths);
2002                 }
2003         case LyXRC::RC_THESAURUSDIRPATH:
2004         case LyXRC::RC_UIFILE:
2005         case LyXRC::RC_USER_EMAIL:
2006         case LyXRC::RC_USER_NAME:
2007         case LyXRC::RC_USETEMPDIR:
2008         case LyXRC::RC_USE_ALT_LANG:
2009         case LyXRC::RC_USE_CONVERTER_CACHE:
2010         case LyXRC::RC_USE_ESC_CHARS:
2011         case LyXRC::RC_USE_INP_ENC:
2012         case LyXRC::RC_USE_PERS_DICT:
2013         case LyXRC::RC_USE_TOOLTIP:
2014         case LyXRC::RC_USE_PIXMAP_CACHE:
2015         case LyXRC::RC_USE_SPELL_LIB:
2016         case LyXRC::RC_VIEWDVI_PAPEROPTION:
2017         case LyXRC::RC_SORT_LAYOUTS:
2018         case LyXRC::RC_FULL_SCREEN_LIMIT:
2019         case LyXRC::RC_FULL_SCREEN_SCROLLBAR:
2020         case LyXRC::RC_FULL_SCREEN_MENUBAR:
2021         case LyXRC::RC_FULL_SCREEN_TABBAR:
2022         case LyXRC::RC_FULL_SCREEN_TOOLBARS:
2023         case LyXRC::RC_FULL_SCREEN_WIDTH:
2024         case LyXRC::RC_VISUAL_CURSOR:
2025         case LyXRC::RC_VIEWER:
2026         case LyXRC::RC_LAST:
2027                 break;
2028         }
2029 }
2030
2031 } // namespace anon
2032 } // namespace lyx