]> git.lyx.org Git - lyx.git/blob - src/LyXFunc.cpp
Add explicative comment.
[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()->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 definiton
567                         // all operations until the recursion or unknown command 
568                         // definiton occures are performed, so set the state to enabled
569                         enable = true;
570                 }
571                 break;
572         }
573
574         case LFUN_VC_COMMAND: {
575                 if (cmd.argument().empty())
576                         enable = false;
577
578                 if (!buf && contains(cmd.getArg(0), 'D'))
579                         enable = false;
580                 break;
581         }
582
583         case LFUN_MASTER_BUFFER_UPDATE:
584         case LFUN_MASTER_BUFFER_VIEW: 
585                 if (!buf->parent()) {
586                         enable = false;
587                         break;
588                 }
589         case LFUN_BUFFER_UPDATE:
590         case LFUN_BUFFER_VIEW: {
591                 string format = to_utf8(cmd.argument());
592                 if (cmd.argument().empty())
593                         format = buf->getDefaultOutputFormat();
594                 typedef vector<Format const *> Formats;
595                 Formats formats;
596                 formats = buf->exportableFormats(true);
597                 Formats::const_iterator fit = formats.begin();
598                 Formats::const_iterator end = formats.end();
599                 enable = false;
600                 for (; fit != end ; ++fit) {
601                         if ((*fit)->name() == format)
602                                 enable = true;
603                 }
604                 break;
605         }
606
607         case LFUN_WORD_FIND_FORWARD:
608         case LFUN_WORD_FIND_BACKWARD:
609         case LFUN_WORD_FINDADV:
610         case LFUN_COMMAND_PREFIX:
611         case LFUN_COMMAND_EXECUTE:
612         case LFUN_CANCEL:
613         case LFUN_META_PREFIX:
614         case LFUN_BUFFER_CLOSE:
615         case LFUN_BUFFER_IMPORT:
616         case LFUN_BUFFER_AUTO_SAVE:
617         case LFUN_RECONFIGURE:
618         case LFUN_HELP_OPEN:
619         case LFUN_DROP_LAYOUTS_CHOICE:
620         case LFUN_MENU_OPEN:
621         case LFUN_SERVER_GET_FILENAME:
622         case LFUN_SERVER_NOTIFY:
623         case LFUN_SERVER_GOTO_FILE_ROW:
624         case LFUN_DIALOG_HIDE:
625         case LFUN_DIALOG_DISCONNECT_INSET:
626         case LFUN_BUFFER_CHILD_OPEN:
627         case LFUN_CURSOR_FOLLOWS_SCROLLBAR_TOGGLE:
628         case LFUN_KEYMAP_OFF:
629         case LFUN_KEYMAP_PRIMARY:
630         case LFUN_KEYMAP_SECONDARY:
631         case LFUN_KEYMAP_TOGGLE:
632         case LFUN_REPEAT:
633         case LFUN_BUFFER_EXPORT_CUSTOM:
634         case LFUN_PREFERENCES_SAVE:
635         case LFUN_MESSAGE:
636         case LFUN_INSET_EDIT:
637         case LFUN_BUFFER_LANGUAGE:
638         case LFUN_TEXTCLASS_APPLY:
639         case LFUN_TEXTCLASS_LOAD:
640         case LFUN_BUFFER_SAVE_AS_DEFAULT:
641         case LFUN_BUFFER_PARAMS_APPLY:
642         case LFUN_LAYOUT_MODULES_CLEAR:
643         case LFUN_LAYOUT_MODULE_ADD:
644         case LFUN_LAYOUT_RELOAD:
645         case LFUN_LYXRC_APPLY:
646         case LFUN_BUFFER_NEXT:
647         case LFUN_BUFFER_PREVIOUS:
648                 // these are handled in our dispatch()
649                 break;
650
651         default:
652                 if (!theApp()) {
653                         enable = false;
654                         break;
655                 }
656                 if (theApp()->getStatus(cmd, flag))
657                         break;
658
659                 // Does the view know something?
660                 if (!lyx_view_) {
661                         enable = false;
662                         break;
663                 }
664                 if (lyx_view_->getStatus(cmd, flag))
665                         break;
666
667                 // If we do not have a BufferView, then other functions are disabled
668                 if (!view()) {
669                         enable = false;
670                         break;
671                 }
672
673                 // Is this a function that acts on inset at point?
674                 Inset * inset = view()->cursor().nextInset();
675                 if (lyxaction.funcHasFlag(cmd.action, LyXAction::AtPoint)
676                     && inset && inset->getStatus(view()->cursor(), cmd, flag))
677                         break;
678
679                 bool decided = getLocalStatus(view()->cursor(), cmd, flag);
680                 if (!decided)
681                         // try the BufferView
682                         decided = view()->getStatus(cmd, flag);
683                 if (!decided)
684                         // try the Buffer
685                         view()->buffer().getStatus(cmd, flag);
686         }
687
688         if (!enable)
689                 flag.setEnabled(false);
690
691         // Can we use a readonly buffer?
692         if (buf && buf->isReadonly()
693             && !lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly)
694             && !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)) {
695                 flag.message(from_utf8(N_("Document is read-only")));
696                 flag.setEnabled(false);
697         }
698
699         // Are we in a DELETED change-tracking region?
700         if (buf && view() 
701                 && lookupChangeType(view()->cursor(), true) == Change::DELETED
702             && !lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly)
703             && !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)) {
704                 flag.message(from_utf8(N_("This portion of the document is deleted.")));
705                 flag.setEnabled(false);
706         }
707
708         // the default error message if we disable the command
709         if (!flag.enabled() && flag.message().empty())
710                 flag.message(from_utf8(N_("Command disabled")));
711
712         return flag;
713 }
714
715
716 bool LyXFunc::ensureBufferClean(BufferView * bv)
717 {
718         Buffer & buf = bv->buffer();
719         if (buf.isClean() && !buf.isUnnamed())
720                 return true;
721
722         docstring const file = buf.fileName().displayName(30);
723         docstring title;
724         docstring text;
725         if (!buf.isUnnamed()) {
726                 text = bformat(_("The document %1$s has unsaved "
727                                              "changes.\n\nDo you want to save "
728                                              "the document?"), file);
729                 title = _("Save changed document?");
730                 
731         } else {
732                 text = bformat(_("The document %1$s has not been "
733                                              "saved yet.\n\nDo you want to save "
734                                              "the document?"), file);
735                 title = _("Save new document?");
736         }
737         int const ret = Alert::prompt(title, text, 0, 1, _("&Save"), _("&Cancel"));
738
739         if (ret == 0)
740                 lyx_view_->dispatch(FuncRequest(LFUN_BUFFER_WRITE));
741
742         return buf.isClean() && !buf.isUnnamed();
743 }
744
745
746 namespace {
747
748 bool loadLayoutFile(string const & name, string const & buf_path)
749 {
750         if (!LayoutFileList::get().haveClass(name)) {
751                 lyxerr << "Document class \"" << name
752                        << "\" does not exist."
753                        << endl;
754                 return false;
755         }
756
757         LayoutFile & tc = LayoutFileList::get()[name];
758         if (!tc.load(buf_path)) {
759                 docstring s = bformat(_("The document class %1$s "
760                                    "could not be loaded."), from_utf8(name));
761                 Alert::error(_("Could not load class"), s);
762                 return false;
763         }
764         return true;
765 }
766
767
768 void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new);
769
770 } //namespace anon
771
772
773 void LyXFunc::dispatch(FuncRequest const & cmd)
774 {
775         string const argument = to_utf8(cmd.argument());
776         FuncCode const action = cmd.action;
777
778         LYXERR(Debug::ACTION, "\nLyXFunc::dispatch: cmd: " << cmd);
779         //lyxerr << "LyXFunc::dispatch: cmd: " << cmd << endl;
780
781         // we have not done anything wrong yet.
782         errorstat = false;
783         dispatch_buffer.erase();
784
785         // redraw the screen at the end (first of the two drawing steps).
786         //This is done unless explicitely requested otherwise
787         Update::flags updateFlags = Update::FitCursor;
788
789         FuncStatus const flag = getStatus(cmd);
790         if (!flag.enabled()) {
791                 // We cannot use this function here
792                 LYXERR(Debug::ACTION, "LyXFunc::dispatch: "
793                        << lyxaction.getActionName(action)
794                        << " [" << action << "] is disabled at this location");
795                 setErrorMessage(flag.message());
796                 if (lyx_view_)
797                         lyx_view_->restartCursor();
798         } else {
799                 Buffer * buffer = lyx_view_ ? lyx_view_->buffer() : 0;
800                 switch (action) {
801
802                 case LFUN_WORD_FIND_FORWARD:
803                 case LFUN_WORD_FIND_BACKWARD: {
804                         LASSERT(lyx_view_ && lyx_view_->view(), /**/);
805                         static docstring last_search;
806                         docstring searched_string;
807
808                         if (!cmd.argument().empty()) {
809                                 last_search = cmd.argument();
810                                 searched_string = cmd.argument();
811                         } else {
812                                 searched_string = last_search;
813                         }
814
815                         if (searched_string.empty())
816                                 break;
817
818                         bool const fw = action == LFUN_WORD_FIND_FORWARD;
819                         docstring const data =
820                                 find2string(searched_string, true, false, fw);
821                         find(view(), FuncRequest(LFUN_WORD_FIND, data));
822                         break;
823                 }
824
825                 case LFUN_COMMAND_PREFIX:
826                         LASSERT(lyx_view_, /**/);
827                         lyx_view_->message(keyseq.printOptions(true));
828                         break;
829
830                 case LFUN_CANCEL:
831                         LASSERT(lyx_view_ && lyx_view_->view(), /**/);
832                         keyseq.reset();
833                         meta_fake_bit = NoModifier;
834                         if (buffer)
835                                 // cancel any selection
836                                 dispatch(FuncRequest(LFUN_MARK_OFF));
837                         setMessage(from_ascii(N_("Cancel")));
838                         break;
839
840                 case LFUN_META_PREFIX:
841                         meta_fake_bit = AltModifier;
842                         setMessage(keyseq.print(KeySequence::ForGui));
843                         break;
844
845                 case LFUN_BUFFER_TOGGLE_READ_ONLY: {
846                         LASSERT(lyx_view_ && lyx_view_->view() && buffer, /**/);
847                         if (buffer->lyxvc().inUse())
848                                 buffer->lyxvc().toggleReadOnly();
849                         else
850                                 buffer->setReadonly(!buffer->isReadonly());
851                         break;
852                 }
853
854                 // --- Menus -----------------------------------------------
855                 case LFUN_BUFFER_CLOSE:
856                         lyx_view_->closeBuffer();
857                         buffer = 0;
858                         updateFlags = Update::None;
859                         break;
860
861                 case LFUN_BUFFER_RELOAD: {
862                         LASSERT(lyx_view_ && buffer, /**/);
863                         docstring const file = makeDisplayPath(buffer->absFileName(), 20);
864                         docstring text = bformat(_("Any changes will be lost. Are you sure "
865                                                              "you want to revert to the saved version of the document %1$s?"), file);
866                         int const ret = Alert::prompt(_("Revert to saved document?"),
867                                 text, 1, 1, _("&Revert"), _("&Cancel"));
868
869                         if (ret == 0)
870                                 reloadBuffer();
871                         break;
872                 }
873
874                 case LFUN_BUFFER_UPDATE: {
875                         LASSERT(lyx_view_ && buffer, /**/);
876                         string format = argument;
877                         if (argument.empty())
878                                 format = buffer->getDefaultOutputFormat();
879                         buffer->doExport(format, true);
880                         break;
881                 }
882
883                 case LFUN_BUFFER_VIEW: {
884                         LASSERT(lyx_view_ && buffer, /**/);
885                         string format = argument;
886                         if (argument.empty())
887                                 format = buffer->getDefaultOutputFormat();
888                         buffer->preview(format);
889                         break;
890                 }
891
892                 case LFUN_MASTER_BUFFER_UPDATE: {
893                         LASSERT(lyx_view_ && buffer && buffer->masterBuffer(), /**/);
894                         string format = argument;
895                         if (argument.empty())
896                                 format = buffer->masterBuffer()->getDefaultOutputFormat();
897                         buffer->masterBuffer()->doExport(format, true);
898                         break;
899                 }
900
901                 case LFUN_MASTER_BUFFER_VIEW: {
902                         LASSERT(lyx_view_ && buffer && buffer->masterBuffer(), /**/);
903                         string format = argument;
904                         if (argument.empty())
905                                 format = buffer->masterBuffer()->getDefaultOutputFormat();
906                         buffer->masterBuffer()->preview(format);
907                         break;
908                 }
909
910                 case LFUN_BUILD_PROGRAM:
911                         LASSERT(lyx_view_ && buffer, /**/);
912                         buffer->doExport("program", true);
913                         break;
914
915                 case LFUN_BUFFER_CHKTEX:
916                         LASSERT(lyx_view_ && buffer, /**/);
917                         buffer->runChktex();
918                         break;
919
920                 case LFUN_BUFFER_EXPORT:
921                         LASSERT(lyx_view_ && buffer, /**/);
922                         if (argument == "custom")
923                                 dispatch(FuncRequest(LFUN_DIALOG_SHOW, "sendto"));
924                         else
925                                 buffer->doExport(argument, false);
926                         break;
927
928                 case LFUN_BUFFER_EXPORT_CUSTOM: {
929                         LASSERT(lyx_view_ && buffer, /**/);
930                         string format_name;
931                         string command = split(argument, format_name, ' ');
932                         Format const * format = formats.getFormat(format_name);
933                         if (!format) {
934                                 lyxerr << "Format \"" << format_name
935                                        << "\" not recognized!"
936                                        << endl;
937                                 break;
938                         }
939
940                         // The name of the file created by the conversion process
941                         string filename;
942
943                         // Output to filename
944                         if (format->name() == "lyx") {
945                                 string const latexname = buffer->latexName(false);
946                                 filename = changeExtension(latexname,
947                                                            format->extension());
948                                 filename = addName(buffer->temppath(), filename);
949
950                                 if (!buffer->writeFile(FileName(filename)))
951                                         break;
952
953                         } else {
954                                 buffer->doExport(format_name, true, filename);
955                         }
956
957                         // Substitute $$FName for filename
958                         if (!contains(command, "$$FName"))
959                                 command = "( " + command + " ) < $$FName";
960                         command = subst(command, "$$FName", filename);
961
962                         // Execute the command in the background
963                         Systemcall call;
964                         call.startscript(Systemcall::DontWait, command);
965                         break;
966                 }
967
968                 // FIXME: There is need for a command-line import.
969                 /*
970                 case LFUN_BUFFER_IMPORT:
971                         doImport(argument);
972                         break;
973                 */
974
975                 case LFUN_BUFFER_AUTO_SAVE:
976                         buffer->autoSave();
977                         break;
978
979                 case LFUN_RECONFIGURE:
980                         // argument is any additional parameter to the configure.py command
981                         reconfigure(lyx_view_, argument);
982                         break;
983
984                 case LFUN_HELP_OPEN: {
985                         if (lyx_view_ == 0)
986                                 theApp()->dispatch(FuncRequest(LFUN_WINDOW_NEW));
987                         string const arg = argument;
988                         if (arg.empty()) {
989                                 setErrorMessage(from_utf8(N_("Missing argument")));
990                                 break;
991                         }
992                         FileName fname = i18nLibFileSearch("doc", arg, "lyx");
993                         if (fname.empty()) 
994                                 fname = i18nLibFileSearch("examples", arg, "lyx");
995
996                         if (fname.empty()) {
997                                 lyxerr << "LyX: unable to find documentation file `"
998                                                          << arg << "'. Bad installation?" << endl;
999                                 break;
1000                         }
1001                         lyx_view_->message(bformat(_("Opening help file %1$s..."),
1002                                 makeDisplayPath(fname.absFilename())));
1003                         Buffer * buf = lyx_view_->loadDocument(fname, false);
1004                         if (buf) {
1005                                 buf->updateLabels();
1006                                 lyx_view_->setBuffer(buf);
1007                                 buf->errors("Parse");
1008                         }
1009                         updateFlags = Update::None;
1010                         break;
1011                 }
1012
1013                 // --- version control -------------------------------
1014                 case LFUN_VC_REGISTER:
1015                         LASSERT(lyx_view_ && buffer, /**/);
1016                         if (!ensureBufferClean(view()))
1017                                 break;
1018                         if (!buffer->lyxvc().inUse()) {
1019                                 if (buffer->lyxvc().registrer())
1020                                         reloadBuffer();
1021                         }
1022                         updateFlags = Update::Force;
1023                         break;
1024
1025                 case LFUN_VC_CHECK_IN:
1026                         LASSERT(lyx_view_ && buffer, /**/);
1027                         if (!ensureBufferClean(view()))
1028                                 break;
1029                         if (buffer->lyxvc().inUse()
1030                                         && !buffer->isReadonly()) {
1031                                 setMessage(from_utf8(buffer->lyxvc().checkIn()));
1032                                 reloadBuffer();
1033                         }
1034                         break;
1035
1036                 case LFUN_VC_CHECK_OUT:
1037                         LASSERT(lyx_view_ && buffer, /**/);
1038                         if (!ensureBufferClean(view()))
1039                                 break;
1040                         if (buffer->lyxvc().inUse()) {
1041                                 setMessage(from_utf8(buffer->lyxvc().checkOut()));
1042                                 reloadBuffer();
1043                         }
1044                         break;
1045
1046                 case LFUN_VC_REVERT:
1047                         LASSERT(lyx_view_ && buffer, /**/);
1048                         buffer->lyxvc().revert();
1049                         reloadBuffer();
1050                         break;
1051
1052                 case LFUN_VC_UNDO_LAST:
1053                         LASSERT(lyx_view_ && buffer, /**/);
1054                         buffer->lyxvc().undoLast();
1055                         reloadBuffer();
1056                         break;
1057
1058                 // --- lyxserver commands ----------------------------
1059                 case LFUN_SERVER_GET_FILENAME:
1060                         LASSERT(lyx_view_ && buffer, /**/);
1061                         setMessage(from_utf8(buffer->absFileName()));
1062                         LYXERR(Debug::INFO, "FNAME["
1063                                 << buffer->absFileName() << ']');
1064                         break;
1065
1066                 case LFUN_SERVER_NOTIFY:
1067                         dispatch_buffer = keyseq.print(KeySequence::Portable);
1068                         theServer().notifyClient(to_utf8(dispatch_buffer));
1069                         break;
1070
1071                 case LFUN_SERVER_GOTO_FILE_ROW: {
1072                         LASSERT(lyx_view_, /**/);
1073                         string file_name;
1074                         int row;
1075                         istringstream is(argument);
1076                         is >> file_name >> row;
1077                         Buffer * buf = 0;
1078                         bool loaded = false;
1079                         string const abstmp = package().temp_dir().absFilename();
1080                         string const realtmp = package().temp_dir().realPath();
1081                         // We have to use os::path_prefix_is() here, instead of
1082                         // simply prefixIs(), because the file name comes from
1083                         // an external application and may need case adjustment.
1084                         if (os::path_prefix_is(file_name, abstmp, os::CASE_ADJUSTED)
1085                             || os::path_prefix_is(file_name, realtmp, os::CASE_ADJUSTED)) {
1086                                 // Needed by inverse dvi search. If it is a file
1087                                 // in tmpdir, call the apropriated function.
1088                                 // If tmpdir is a symlink, we may have the real
1089                                 // path passed back, so we correct for that.
1090                                 if (!prefixIs(file_name, abstmp))
1091                                         file_name = subst(file_name, realtmp, abstmp);
1092                                 buf = theBufferList().getBufferFromTmp(file_name);
1093                         } else {
1094                                 // Must replace extension of the file to be .lyx
1095                                 // and get full path
1096                                 FileName const s = fileSearch(string(), changeExtension(file_name, ".lyx"), "lyx");
1097                                 // Either change buffer or load the file
1098                                 if (theBufferList().exists(s))
1099                                         buf = theBufferList().getBuffer(s);
1100                                 else if (s.exists()) {
1101                                         buf = lyx_view_->loadDocument(s);
1102                                         loaded = true;
1103                                 } else
1104                                         lyx_view_->message(bformat(
1105                                                 _("File does not exist: %1$s"),
1106                                                 makeDisplayPath(file_name)));
1107                         }
1108
1109                         if (!buf) {
1110                                 updateFlags = Update::None;
1111                                 break;
1112                         }
1113
1114                         buf->updateLabels();
1115                         lyx_view_->setBuffer(buf);
1116                         view()->setCursorFromRow(row);
1117                         if (loaded)
1118                                 buf->errors("Parse");
1119                         updateFlags = Update::FitCursor;
1120                         break;
1121                 }
1122
1123
1124                 case LFUN_DIALOG_SHOW_NEW_INSET: {
1125                         LASSERT(lyx_view_, /**/);
1126                         string const name = cmd.getArg(0);
1127                         InsetCode code = insetCode(name);
1128                         string data = trim(to_utf8(cmd.argument()).substr(name.size()));
1129                         bool insetCodeOK = true;
1130                         switch (code) {
1131                         case BIBITEM_CODE:
1132                         case BIBTEX_CODE:
1133                         case INDEX_CODE:
1134                         case LABEL_CODE:
1135                         case NOMENCL_CODE:
1136                         case NOMENCL_PRINT_CODE:
1137                         case REF_CODE:
1138                         case TOC_CODE:
1139                         case HYPERLINK_CODE: {
1140                                 InsetCommandParams p(code);
1141                                 data = InsetCommand::params2string(name, p);
1142                                 break;
1143                         }
1144                         case INCLUDE_CODE: {
1145                                 // data is the include type: one of "include",
1146                                 // "input", "verbatiminput" or "verbatiminput*"
1147                                 if (data.empty())
1148                                         // default type is requested
1149                                         data = "include";
1150                                 InsetCommandParams p(INCLUDE_CODE, data);
1151                                 data = InsetCommand::params2string("include", p);
1152                                 break;
1153                         }
1154                         case BOX_CODE: {
1155                                 // \c data == "Boxed" || "Frameless" etc
1156                                 InsetBoxParams p(data);
1157                                 data = InsetBox::params2string(p);
1158                                 break;
1159                         }
1160                         case BRANCH_CODE: {
1161                                 InsetBranchParams p;
1162                                 data = InsetBranch::params2string(p);
1163                                 break;
1164                         }
1165                         case CITE_CODE: {
1166                                 InsetCommandParams p(CITE_CODE);
1167                                 data = InsetCommand::params2string(name, p);
1168                                 break;
1169                         }
1170                         case ERT_CODE: {
1171                                 data = InsetERT::params2string(InsetCollapsable::Open);
1172                                 break;
1173                         }
1174                         case EXTERNAL_CODE: {
1175                                 InsetExternalParams p;
1176                                 data = InsetExternal::params2string(p, *buffer);
1177                                 break;
1178                         }
1179                         case FLOAT_CODE:  {
1180                                 InsetFloatParams p;
1181                                 data = InsetFloat::params2string(p);
1182                                 break;
1183                         }
1184                         case LISTINGS_CODE: {
1185                                 InsetListingsParams p;
1186                                 data = InsetListings::params2string(p);
1187                                 break;
1188                         }
1189                         case GRAPHICS_CODE: {
1190                                 InsetGraphicsParams p;
1191                                 data = InsetGraphics::params2string(p, *buffer);
1192                                 break;
1193                         }
1194                         case NOTE_CODE: {
1195                                 InsetNoteParams p;
1196                                 data = InsetNote::params2string(p);
1197                                 break;
1198                         }
1199                         case PHANTOM_CODE: {
1200                                 InsetPhantomParams p;
1201                                 data = InsetPhantom::params2string(p);
1202                                 break;
1203                         }
1204                         case SPACE_CODE: {
1205                                 InsetSpaceParams p;
1206                                 data = InsetSpace::params2string(p);
1207                                 break;
1208                         }
1209                         case VSPACE_CODE: {
1210                                 VSpace space;
1211                                 data = InsetVSpace::params2string(space);
1212                                 break;
1213                         }
1214                         case WRAP_CODE: {
1215                                 InsetWrapParams p;
1216                                 data = InsetWrap::params2string(p);
1217                                 break;
1218                         }
1219                         default:
1220                                 lyxerr << "Inset type '" << name << 
1221                                         "' not recognized in LFUN_DIALOG_SHOW_NEW_INSET" <<  endl;
1222                                 insetCodeOK = false;
1223                                 break;
1224                         } // end switch(code)
1225                         if (insetCodeOK)
1226                                 dispatch(FuncRequest(LFUN_DIALOG_SHOW, name + " " + data));
1227                         break;
1228                 }
1229
1230                 case LFUN_CITATION_INSERT: {
1231                         LASSERT(lyx_view_, /**/);
1232                         if (!argument.empty()) {
1233                                 // we can have one optional argument, delimited by '|'
1234                                 // citation-insert <key>|<text_before>
1235                                 // this should be enhanced to also support text_after
1236                                 // and citation style
1237                                 string arg = argument;
1238                                 string opt1;
1239                                 if (contains(argument, "|")) {
1240                                         arg = token(argument, '|', 0);
1241                                         opt1 = token(argument, '|', 1);
1242                                 }
1243                                 InsetCommandParams icp(CITE_CODE);
1244                                 icp["key"] = from_utf8(arg);
1245                                 if (!opt1.empty())
1246                                         icp["before"] = from_utf8(opt1);
1247                                 string icstr = InsetCommand::params2string("citation", icp);
1248                                 FuncRequest fr(LFUN_INSET_INSERT, icstr);
1249                                 dispatch(fr);
1250                         } else
1251                                 dispatch(FuncRequest(LFUN_DIALOG_SHOW_NEW_INSET, "citation"));
1252                         break;
1253                 }
1254
1255                 case LFUN_BUFFER_CHILD_OPEN: {
1256                         LASSERT(lyx_view_ && buffer, /**/);
1257                         FileName filename = makeAbsPath(argument, buffer->filePath());
1258                         view()->saveBookmark(false);
1259                         Buffer * child = 0;
1260                         bool parsed = false;
1261                         if (theBufferList().exists(filename)) {
1262                                 child = theBufferList().getBuffer(filename);
1263                         } else {
1264                                 setMessage(bformat(_("Opening child document %1$s..."),
1265                                         makeDisplayPath(filename.absFilename())));
1266                                 child = lyx_view_->loadDocument(filename, false);
1267                                 parsed = true;
1268                         }
1269                         if (child) {
1270                                 // Set the parent name of the child document.
1271                                 // This makes insertion of citations and references in the child work,
1272                                 // when the target is in the parent or another child document.
1273                                 child->setParent(buffer);
1274                                 child->masterBuffer()->updateLabels();
1275                                 lyx_view_->setBuffer(child);
1276                                 if (parsed)
1277                                         child->errors("Parse");
1278                         }
1279
1280                         // If a screen update is required (in case where auto_open is false), 
1281                         // setBuffer() would have taken care of it already. Otherwise we shall 
1282                         // reset the update flag because it can cause a circular problem.
1283                         // See bug 3970.
1284                         updateFlags = Update::None;
1285                         break;
1286                 }
1287
1288                 case LFUN_CURSOR_FOLLOWS_SCROLLBAR_TOGGLE:
1289                         LASSERT(lyx_view_, /**/);
1290                         lyxrc.cursor_follows_scrollbar = !lyxrc.cursor_follows_scrollbar;
1291                         break;
1292
1293                 case LFUN_KEYMAP_OFF:
1294                         LASSERT(lyx_view_ && lyx_view_->view(), /**/);
1295                         lyx_view_->view()->getIntl().keyMapOn(false);
1296                         break;
1297
1298                 case LFUN_KEYMAP_PRIMARY:
1299                         LASSERT(lyx_view_ && lyx_view_->view(), /**/);
1300                         lyx_view_->view()->getIntl().keyMapPrim();
1301                         break;
1302
1303                 case LFUN_KEYMAP_SECONDARY:
1304                         LASSERT(lyx_view_ && lyx_view_->view(), /**/);
1305                         lyx_view_->view()->getIntl().keyMapSec();
1306                         break;
1307
1308                 case LFUN_KEYMAP_TOGGLE:
1309                         LASSERT(lyx_view_ && lyx_view_->view(), /**/);
1310                         lyx_view_->view()->getIntl().toggleKeyMap();
1311                         break;
1312
1313                 case LFUN_REPEAT: {
1314                         // repeat command
1315                         string countstr;
1316                         string rest = split(argument, countstr, ' ');
1317                         istringstream is(countstr);
1318                         int count = 0;
1319                         is >> count;
1320                         //lyxerr << "repeat: count: " << count << " cmd: " << rest << endl;
1321                         for (int i = 0; i < count; ++i)
1322                                 dispatch(lyxaction.lookupFunc(rest));
1323                         break;
1324                 }
1325
1326                 case LFUN_COMMAND_SEQUENCE: {
1327                         // argument contains ';'-terminated commands
1328                         string arg = argument;
1329                         if (theBufferList().isLoaded(buffer))
1330                                 buffer->undo().beginUndoGroup();
1331                         while (!arg.empty()) {
1332                                 string first;
1333                                 arg = split(arg, first, ';');
1334                                 FuncRequest func(lyxaction.lookupFunc(first));
1335                                 func.origin = cmd.origin;
1336                                 dispatch(func);
1337                         }
1338                         if (theBufferList().isLoaded(buffer))
1339                                 buffer->undo().endUndoGroup();
1340                         break;
1341                 }
1342
1343                 case LFUN_COMMAND_ALTERNATIVES: {
1344                         // argument contains ';'-terminated commands
1345                         string arg = argument;
1346                         while (!arg.empty()) {
1347                                 string first;
1348                                 arg = split(arg, first, ';');
1349                                 FuncRequest func(lyxaction.lookupFunc(first));
1350                                 func.origin = cmd.origin;
1351                                 FuncStatus stat = getStatus(func);
1352                                 if (stat.enabled()) {
1353                                         dispatch(func);
1354                                         break;
1355                                 }
1356                         }
1357                         break;
1358                 }
1359
1360                 case LFUN_CALL: {
1361                         FuncRequest func;
1362                         if (theTopLevelCmdDef().lock(argument, func)) {
1363                                 func.origin = cmd.origin;
1364                                 dispatch(func);
1365                                 theTopLevelCmdDef().release(argument);
1366                         } else {
1367                                 if (func.action == LFUN_UNKNOWN_ACTION) {
1368                                         // unknown command definition
1369                                         lyxerr << "Warning: unknown command definition `"
1370                                                    << argument << "'"
1371                                                    << endl;
1372                                 } else {
1373                                         // recursion detected
1374                                         lyxerr << "Warning: Recursion in the command definition `"
1375                                                    << argument << "' detected"
1376                                                    << endl;
1377                                 }
1378                         }
1379                         break;
1380                 }
1381
1382                 case LFUN_PREFERENCES_SAVE: {
1383                         lyxrc.write(makeAbsPath("preferences",
1384                                                 package().user_support().absFilename()),
1385                                     false);
1386                         break;
1387                 }
1388
1389                 case LFUN_MESSAGE:
1390                         LASSERT(lyx_view_, /**/);
1391                         lyx_view_->message(from_utf8(argument));
1392                         break;
1393
1394                 case LFUN_BUFFER_LANGUAGE: {
1395                         LASSERT(lyx_view_, /**/);
1396                         Language const * oldL = buffer->params().language;
1397                         Language const * newL = languages.getLanguage(argument);
1398                         if (!newL || oldL == newL)
1399                                 break;
1400
1401                         if (oldL->rightToLeft() == newL->rightToLeft()
1402                             && !buffer->isMultiLingual())
1403                                 buffer->changeLanguage(oldL, newL);
1404                         break;
1405                 }
1406
1407                 case LFUN_BUFFER_SAVE_AS_DEFAULT: {
1408                         string const fname =
1409                                 addName(addPath(package().user_support().absFilename(), "templates/"),
1410                                         "defaults.lyx");
1411                         Buffer defaults(fname);
1412
1413                         istringstream ss(argument);
1414                         Lexer lex;
1415                         lex.setStream(ss);
1416                         int const unknown_tokens = defaults.readHeader(lex);
1417
1418                         if (unknown_tokens != 0) {
1419                                 lyxerr << "Warning in LFUN_BUFFER_SAVE_AS_DEFAULT!\n"
1420                                        << unknown_tokens << " unknown token"
1421                                        << (unknown_tokens == 1 ? "" : "s")
1422                                        << endl;
1423                         }
1424
1425                         if (defaults.writeFile(FileName(defaults.absFileName())))
1426                                 setMessage(bformat(_("Document defaults saved in %1$s"),
1427                                                    makeDisplayPath(fname)));
1428                         else
1429                                 setErrorMessage(from_ascii(N_("Unable to save document defaults")));
1430                         break;
1431                 }
1432
1433                 case LFUN_BUFFER_PARAMS_APPLY: {
1434                         LASSERT(lyx_view_, /**/);
1435                         
1436                         DocumentClass const * const oldClass = buffer->params().documentClassPtr();
1437                         Cursor & cur = view()->cursor();
1438                         cur.recordUndoFullDocument();
1439                         
1440                         istringstream ss(argument);
1441                         Lexer lex;
1442                         lex.setStream(ss);
1443                         int const unknown_tokens = buffer->readHeader(lex);
1444
1445                         if (unknown_tokens != 0) {
1446                                 lyxerr << "Warning in LFUN_BUFFER_PARAMS_APPLY!\n"
1447                                                 << unknown_tokens << " unknown token"
1448                                                 << (unknown_tokens == 1 ? "" : "s")
1449                                                 << endl;
1450                         }
1451                         
1452                         updateLayout(oldClass, buffer);
1453                         
1454                         updateFlags = Update::Force | Update::FitCursor;
1455                         // We are most certainly here because of a change in the document
1456                         // It is then better to make sure that all dialogs are in sync with
1457                         // current document settings. LyXView::restartCursor() achieve this.
1458                         lyx_view_->restartCursor();
1459                         break;
1460                 }
1461                 
1462                 case LFUN_LAYOUT_MODULES_CLEAR: {
1463                         LASSERT(lyx_view_, /**/);
1464                         DocumentClass const * const oldClass = buffer->params().documentClassPtr();
1465                         view()->cursor().recordUndoFullDocument();
1466                         buffer->params().clearLayoutModules();
1467                         buffer->params().makeDocumentClass();
1468                         updateLayout(oldClass, buffer);
1469                         updateFlags = Update::Force | Update::FitCursor;
1470                         break;
1471                 }
1472                 
1473                 case LFUN_LAYOUT_MODULE_ADD: {
1474                         LASSERT(lyx_view_, /**/);
1475                         BufferParams const & params = buffer->params();
1476                         if (!params.moduleCanBeAdded(argument)) {
1477                                 LYXERR0("Module `" << argument << 
1478                                                 "' cannot be added due to failed requirements or "
1479                                                 "conflicts with installed modules.");
1480                                 break;
1481                         }
1482                         DocumentClass const * const oldClass = params.documentClassPtr();
1483                         view()->cursor().recordUndoFullDocument();
1484                         buffer->params().addLayoutModule(argument);
1485                         buffer->params().makeDocumentClass();
1486                         updateLayout(oldClass, buffer);
1487                         updateFlags = Update::Force | Update::FitCursor;
1488                         break;
1489                 }
1490
1491                 case LFUN_TEXTCLASS_APPLY: {
1492                         LASSERT(lyx_view_, /**/);
1493
1494                         if (!loadLayoutFile(argument, buffer->temppath()) &&
1495                                 !loadLayoutFile(argument, buffer->filePath()))
1496                                 break;
1497
1498                         LayoutFile const * old_layout = buffer->params().baseClass();
1499                         LayoutFile const * new_layout = &(LayoutFileList::get()[argument]);
1500
1501                         if (old_layout == new_layout)
1502                                 // nothing to do
1503                                 break;
1504
1505                         //Save the old, possibly modular, layout for use in conversion.
1506                         DocumentClass const * const oldDocClass = buffer->params().documentClassPtr();
1507                         view()->cursor().recordUndoFullDocument();
1508                         buffer->params().setBaseClass(argument);
1509                         buffer->params().makeDocumentClass();
1510                         updateLayout(oldDocClass, buffer);
1511                         updateFlags = Update::Force | Update::FitCursor;
1512                         break;
1513                 }
1514                 
1515                 case LFUN_LAYOUT_RELOAD: {
1516                         LASSERT(lyx_view_, /**/);
1517                         DocumentClass const * const oldClass = buffer->params().documentClassPtr();
1518                         LayoutFileIndex bc = buffer->params().baseClassID();
1519                         LayoutFileList::get().reset(bc);
1520                         buffer->params().setBaseClass(bc);
1521                         buffer->params().makeDocumentClass();
1522                         updateLayout(oldClass, buffer);
1523                         updateFlags = Update::Force | Update::FitCursor;
1524                         break;
1525                 }
1526
1527                 case LFUN_TEXTCLASS_LOAD:
1528                         loadLayoutFile(argument, buffer->temppath()) ||
1529                         loadLayoutFile(argument, buffer->filePath());
1530                         break;
1531
1532                 case LFUN_LYXRC_APPLY: {
1533                         LyXRC const lyxrc_orig = lyxrc;
1534
1535                         istringstream ss(argument);
1536                         bool const success = lyxrc.read(ss) == 0;
1537
1538                         if (!success) {
1539                                 lyxerr << "Warning in LFUN_LYXRC_APPLY!\n"
1540                                        << "Unable to read lyxrc data"
1541                                        << endl;
1542                                 break;
1543                         }
1544
1545                         actOnUpdatedPrefs(lyxrc_orig, lyxrc);
1546
1547                         theApp()->resetGui();
1548
1549                         /// We force the redraw in any case because there might be
1550                         /// some screen font changes.
1551                         /// FIXME: only the current view will be updated. the Gui
1552                         /// class is able to furnish the list of views.
1553                         updateFlags = Update::Force;
1554                         break;
1555                 }
1556
1557                 case LFUN_BOOKMARK_GOTO:
1558                         // go to bookmark, open unopened file and switch to buffer if necessary
1559                         gotoBookmark(convert<unsigned int>(to_utf8(cmd.argument())), true, true);
1560                         updateFlags = Update::FitCursor;
1561                         break;
1562
1563                 case LFUN_BOOKMARK_CLEAR:
1564                         theSession().bookmarks().clear();
1565                         break;
1566
1567                 case LFUN_VC_COMMAND: {
1568                         string flag = cmd.getArg(0);
1569                         if (buffer && contains(flag, 'R') && !ensureBufferClean(view()))
1570                                 break;
1571                         docstring message;
1572                         if (contains(flag, 'M'))
1573                                 if (!Alert::askForText(message, _("LyX VC: Log Message")))
1574                                         break;
1575
1576                         string path = cmd.getArg(1);
1577                         if (contains(path, "$$p") && buffer)
1578                                 path = subst(path, "$$p", buffer->filePath());
1579                         LYXERR(Debug::LYXVC, "Directory: " << path);
1580                         FileName pp(path);
1581                         if (!pp.isReadableDirectory()) {
1582                                 lyxerr << _("Directory is not accessible.") << endl;
1583                                 break;
1584                         }
1585                         support::PathChanger p(pp);
1586
1587                         string command = cmd.getArg(2);
1588                         if (command.empty())
1589                                 break;
1590                         if (buffer) {
1591                                 command = subst(command, "$$i", buffer->absFileName());
1592                                 command = subst(command, "$$p", buffer->filePath());
1593                         }
1594                         command = subst(command, "$$m", to_utf8(message));
1595                         LYXERR(Debug::LYXVC, "Command: " << command);
1596                         Systemcall one;
1597                         one.startscript(Systemcall::Wait, command);
1598
1599                         if (!buffer)
1600                                 break;
1601                         if (contains(flag, 'I'))
1602                                 buffer->markDirty();
1603                         if (contains(flag, 'R'))
1604                                 reloadBuffer();
1605
1606                         break;
1607                 }
1608
1609                 default:
1610                         LASSERT(theApp(), /**/);
1611                         // Let the frontend dispatch its own actions.
1612                         if (theApp()->dispatch(cmd))
1613                                 // Nothing more to do.
1614                                 return;
1615
1616                         // Everything below is only for active lyx_view_
1617                         if (lyx_view_ == 0)
1618                                 break;
1619
1620                         // Start an undo group. This may be needed for
1621                         // some stuff like inset-apply on labels.
1622                         if (theBufferList().isLoaded(buffer))
1623                                 buffer->undo().beginUndoGroup();
1624                                 
1625                         // Let the current LyXView dispatch its own actions.
1626                         if (lyx_view_->dispatch(cmd)) {
1627                                 if (lyx_view_->view()) {
1628                                         updateFlags = lyx_view_->view()->cursor().result().update();
1629                                         if (theBufferList().isLoaded(buffer))
1630                                                 buffer->undo().endUndoGroup();
1631                                 }
1632                                 break;
1633                         }
1634
1635                         LASSERT(lyx_view_->view(), /**/);
1636
1637                         // Let the current BufferView dispatch its own actions.
1638                         if (view()->dispatch(cmd)) {
1639                                 // The BufferView took care of its own updates if needed.
1640                                 updateFlags = Update::None;
1641                                 if (theBufferList().isLoaded(buffer))
1642                                         buffer->undo().endUndoGroup();
1643                                 break;
1644                         }
1645
1646                         // OK, so try the Buffer itself
1647                         DispatchResult dr;
1648                         view()->buffer().dispatch(cmd, dr);
1649                         if (dr.dispatched()) {
1650                                 updateFlags = dr.update();
1651                                 break;
1652                         }
1653
1654                         // Is this a function that acts on inset at point?
1655                         Inset * inset = view()->cursor().nextInset();
1656                         if (lyxaction.funcHasFlag(action, LyXAction::AtPoint)
1657                             && inset) {
1658                                 view()->cursor().result().dispatched(true);
1659                                 view()->cursor().result().update(Update::FitCursor | Update::Force);
1660                                 FuncRequest tmpcmd = cmd;
1661                                 inset->dispatch(view()->cursor(), tmpcmd);
1662                                 if (view()->cursor().result().dispatched()) {
1663                                         updateFlags = view()->cursor().result().update();
1664                                         break;
1665                                 }
1666                         }
1667
1668                         // Let the current Cursor dispatch its own actions.
1669                         Cursor old = view()->cursor();
1670                         view()->cursor().getPos(cursorPosBeforeDispatchX_,
1671                                                 cursorPosBeforeDispatchY_);
1672                         view()->cursor().dispatch(cmd);
1673
1674                         // notify insets we just left
1675                         if (view()->cursor() != old) {
1676                                 old.fixIfBroken();
1677                                 bool badcursor = notifyCursorLeavesOrEnters(old, view()->cursor());
1678                                 if (badcursor)
1679                                         view()->cursor().fixIfBroken();
1680                         }
1681
1682                         if (theBufferList().isLoaded(buffer))
1683                                 buffer->undo().endUndoGroup();
1684
1685                         // update completion. We do it here and not in
1686                         // processKeySym to avoid another redraw just for a
1687                         // changed inline completion
1688                         if (cmd.origin == FuncRequest::KEYBOARD) {
1689                                 if (cmd.action == LFUN_SELF_INSERT)
1690                                         lyx_view_->updateCompletion(view()->cursor(), true, true);
1691                                 else if (cmd.action == LFUN_CHAR_DELETE_BACKWARD)
1692                                         lyx_view_->updateCompletion(view()->cursor(), false, true);
1693                                 else
1694                                         lyx_view_->updateCompletion(view()->cursor(), false, false);
1695                         }
1696
1697                         updateFlags = view()->cursor().result().update();
1698                 }
1699
1700                 // if we executed a mutating lfun, mark the buffer as dirty
1701                 if (theBufferList().isLoaded(buffer) && flag.enabled()
1702                     && !lyxaction.funcHasFlag(action, LyXAction::NoBuffer)
1703                     && !lyxaction.funcHasFlag(action, LyXAction::ReadOnly))
1704                         buffer->markDirty();                    
1705
1706                 if (lyx_view_ && lyx_view_->buffer()) {
1707                         // BufferView::update() updates the ViewMetricsInfo and
1708                         // also initializes the position cache for all insets in
1709                         // (at least partially) visible top-level paragraphs.
1710                         // We will redraw the screen only if needed.
1711                         view()->processUpdateFlags(updateFlags);
1712
1713                         // Do we have a selection?
1714                         theSelection().haveSelection(view()->cursor().selection());
1715                         
1716                         // update gui
1717                         lyx_view_->restartCursor();
1718                 }
1719         }
1720         if (lyx_view_) {
1721                 // Some messages may already be translated, so we cannot use _()
1722                 sendDispatchMessage(translateIfPossible(getMessage()), cmd);
1723         }
1724 }
1725
1726
1727 void LyXFunc::sendDispatchMessage(docstring const & msg, FuncRequest const & cmd)
1728 {
1729         const bool verbose = (cmd.origin == FuncRequest::MENU
1730                               || cmd.origin == FuncRequest::TOOLBAR
1731                               || cmd.origin == FuncRequest::COMMANDBUFFER);
1732
1733         if (cmd.action == LFUN_SELF_INSERT || !verbose) {
1734                 LYXERR(Debug::ACTION, "dispatch msg is " << to_utf8(msg));
1735                 if (!msg.empty())
1736                         lyx_view_->message(msg);
1737                 return;
1738         }
1739
1740         docstring dispatch_msg = msg;
1741         if (!dispatch_msg.empty())
1742                 dispatch_msg += ' ';
1743
1744         docstring comname = from_utf8(lyxaction.getActionName(cmd.action));
1745
1746         bool argsadded = false;
1747
1748         if (!cmd.argument().empty()) {
1749                 if (cmd.action != LFUN_UNKNOWN_ACTION) {
1750                         comname += ' ' + cmd.argument();
1751                         argsadded = true;
1752                 }
1753         }
1754
1755         docstring const shortcuts = theTopLevelKeymap().printBindings(cmd, KeySequence::ForGui);
1756
1757         if (!shortcuts.empty())
1758                 comname += ": " + shortcuts;
1759         else if (!argsadded && !cmd.argument().empty())
1760                 comname += ' ' + cmd.argument();
1761
1762         if (!comname.empty()) {
1763                 comname = rtrim(comname);
1764                 dispatch_msg += '(' + rtrim(comname) + ')';
1765         }
1766
1767         LYXERR(Debug::ACTION, "verbose dispatch msg " << to_utf8(dispatch_msg));
1768         if (!dispatch_msg.empty())
1769                 lyx_view_->message(dispatch_msg);
1770 }
1771
1772
1773 void LyXFunc::reloadBuffer()
1774 {
1775         FileName filename = lyx_view_->buffer()->fileName();
1776         // The user has already confirmed that the changes, if any, should
1777         // be discarded. So we just release the Buffer and don't call closeBuffer();
1778         theBufferList().release(lyx_view_->buffer());
1779         // if the lyx_view_ has been destroyed, create a new one
1780         if (!lyx_view_)
1781                 theApp()->dispatch(FuncRequest(LFUN_WINDOW_NEW));
1782         Buffer * buf = lyx_view_->loadDocument(filename);
1783         docstring const disp_fn = makeDisplayPath(filename.absFilename());
1784         docstring str;
1785         if (buf) {
1786                 buf->updateLabels();
1787                 lyx_view_->setBuffer(buf);
1788                 buf->errors("Parse");
1789                 str = bformat(_("Document %1$s reloaded."), disp_fn);
1790         } else {
1791                 str = bformat(_("Could not reload document %1$s"), disp_fn);
1792         }
1793         lyx_view_->message(str);
1794 }
1795
1796 // Each "lyx_view_" should have it's own message method. lyxview and
1797 // the minibuffer would use the minibuffer, but lyxserver would
1798 // send an ERROR signal to its client.  Alejandro 970603
1799 // This function is bit problematic when it comes to NLS, to make the
1800 // lyx servers client be language indepenent we must not translate
1801 // strings sent to this func.
1802 void LyXFunc::setErrorMessage(docstring const & m) const
1803 {
1804         dispatch_buffer = m;
1805         errorstat = true;
1806 }
1807
1808
1809 void LyXFunc::setMessage(docstring const & m) const
1810 {
1811         dispatch_buffer = m;
1812 }
1813
1814
1815 docstring LyXFunc::viewStatusMessage()
1816 {
1817         // When meta-fake key is pressed, show the key sequence so far + "M-".
1818         if (wasMetaKey())
1819                 return keyseq.print(KeySequence::ForGui) + "M-";
1820
1821         // Else, when a non-complete key sequence is pressed,
1822         // show the available options.
1823         if (keyseq.length() > 0 && !keyseq.deleted())
1824                 return keyseq.printOptions(true);
1825
1826         LASSERT(lyx_view_, /**/);
1827         if (!lyx_view_->buffer())
1828                 return _("Welcome to LyX!");
1829
1830         return view()->cursor().currentState();
1831 }
1832
1833
1834 BufferView * LyXFunc::view() const
1835 {
1836         LASSERT(lyx_view_, /**/);
1837         return lyx_view_->view();
1838 }
1839
1840
1841 bool LyXFunc::wasMetaKey() const
1842 {
1843         return (meta_fake_bit != NoModifier);
1844 }
1845
1846
1847 void LyXFunc::updateLayout(DocumentClass const * const oldlayout, Buffer * buf)
1848 {
1849         lyx_view_->message(_("Converting document to new document class..."));
1850         
1851         StableDocIterator backcur(view()->cursor());
1852         ErrorList & el = buf->errorList("Class Switch");
1853         cap::switchBetweenClasses(
1854                         oldlayout, buf->params().documentClassPtr(),
1855                         static_cast<InsetText &>(buf->inset()), el);
1856
1857         view()->setCursor(backcur.asDocIterator(buf));
1858
1859         buf->errors("Class Switch");
1860         buf->updateLabels();
1861 }
1862
1863
1864 namespace {
1865
1866 void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
1867 {
1868         // Why the switch you might ask. It is a trick to ensure that all
1869         // the elements in the LyXRCTags enum is handled. As you can see
1870         // there are no breaks at all. So it is just a huge fall-through.
1871         // The nice thing is that we will get a warning from the compiler
1872         // if we forget an element.
1873         LyXRC::LyXRCTags tag = LyXRC::RC_LAST;
1874         switch (tag) {
1875         case LyXRC::RC_ACCEPT_COMPOUND:
1876         case LyXRC::RC_ALT_LANG:
1877         case LyXRC::RC_PLAINTEXT_LINELEN:
1878         case LyXRC::RC_PLAINTEXT_ROFF_COMMAND:
1879         case LyXRC::RC_AUTOCORRECTION_MATH:
1880         case LyXRC::RC_AUTOREGIONDELETE:
1881         case LyXRC::RC_AUTORESET_OPTIONS:
1882         case LyXRC::RC_AUTOSAVE:
1883         case LyXRC::RC_AUTO_NUMBER:
1884         case LyXRC::RC_BACKUPDIR_PATH:
1885         case LyXRC::RC_BIBTEX_ALTERNATIVES:
1886         case LyXRC::RC_BIBTEX_COMMAND:
1887         case LyXRC::RC_BINDFILE:
1888         case LyXRC::RC_CHECKLASTFILES:
1889         case LyXRC::RC_COMPLETION_CURSOR_TEXT:
1890         case LyXRC::RC_COMPLETION_INLINE_DELAY:
1891         case LyXRC::RC_COMPLETION_INLINE_DOTS:
1892         case LyXRC::RC_COMPLETION_INLINE_MATH:
1893         case LyXRC::RC_COMPLETION_INLINE_TEXT:
1894         case LyXRC::RC_COMPLETION_POPUP_AFTER_COMPLETE:
1895         case LyXRC::RC_COMPLETION_POPUP_DELAY:
1896         case LyXRC::RC_COMPLETION_POPUP_MATH:
1897         case LyXRC::RC_COMPLETION_POPUP_TEXT:
1898         case LyXRC::RC_USELASTFILEPOS:
1899         case LyXRC::RC_LOADSESSION:
1900         case LyXRC::RC_CHKTEX_COMMAND:
1901         case LyXRC::RC_CONVERTER:
1902         case LyXRC::RC_CONVERTER_CACHE_MAXAGE:
1903         case LyXRC::RC_COPIER:
1904         case LyXRC::RC_CURSOR_FOLLOWS_SCROLLBAR:
1905         case LyXRC::RC_SCROLL_BELOW_DOCUMENT:
1906         case LyXRC::RC_DATE_INSERT_FORMAT:
1907         case LyXRC::RC_DEFAULT_LANGUAGE:
1908         case LyXRC::RC_GUI_LANGUAGE:
1909         case LyXRC::RC_DEFAULT_PAPERSIZE:
1910         case LyXRC::RC_DEFAULT_VIEW_FORMAT:
1911         case LyXRC::RC_DEFFILE:
1912         case LyXRC::RC_DIALOGS_ICONIFY_WITH_MAIN:
1913         case LyXRC::RC_DISPLAY_GRAPHICS:
1914         case LyXRC::RC_DOCUMENTPATH:
1915                 if (lyxrc_orig.document_path != lyxrc_new.document_path) {
1916                         FileName path(lyxrc_new.document_path);
1917                         if (path.exists() && path.isDirectory())
1918                                 package().document_dir() = FileName(lyxrc.document_path);
1919                 }
1920         case LyXRC::RC_ESC_CHARS:
1921         case LyXRC::RC_EXAMPLEPATH:
1922         case LyXRC::RC_FONT_ENCODING:
1923         case LyXRC::RC_FORMAT:
1924         case LyXRC::RC_GROUP_LAYOUTS:
1925         case LyXRC::RC_INDEX_ALTERNATIVES:
1926         case LyXRC::RC_INDEX_COMMAND:
1927         case LyXRC::RC_JBIBTEX_COMMAND:
1928         case LyXRC::RC_JINDEX_COMMAND:
1929         case LyXRC::RC_NOMENCL_COMMAND:
1930         case LyXRC::RC_INPUT:
1931         case LyXRC::RC_KBMAP:
1932         case LyXRC::RC_KBMAP_PRIMARY:
1933         case LyXRC::RC_KBMAP_SECONDARY:
1934         case LyXRC::RC_LABEL_INIT_LENGTH:
1935         case LyXRC::RC_LANGUAGE_AUTO_BEGIN:
1936         case LyXRC::RC_LANGUAGE_AUTO_END:
1937         case LyXRC::RC_LANGUAGE_COMMAND_BEGIN:
1938         case LyXRC::RC_LANGUAGE_COMMAND_END:
1939         case LyXRC::RC_LANGUAGE_COMMAND_LOCAL:
1940         case LyXRC::RC_LANGUAGE_GLOBAL_OPTIONS:
1941         case LyXRC::RC_LANGUAGE_PACKAGE:
1942         case LyXRC::RC_LANGUAGE_USE_BABEL:
1943         case LyXRC::RC_MAC_LIKE_WORD_MOVEMENT:
1944         case LyXRC::RC_MACRO_EDIT_STYLE:
1945         case LyXRC::RC_MAKE_BACKUP:
1946         case LyXRC::RC_MARK_FOREIGN_LANGUAGE:
1947         case LyXRC::RC_MOUSE_WHEEL_SPEED:
1948         case LyXRC::RC_NUMLASTFILES:
1949         case LyXRC::RC_PATH_PREFIX:
1950                 if (lyxrc_orig.path_prefix != lyxrc_new.path_prefix) {
1951                         prependEnvPath("PATH", lyxrc.path_prefix);
1952                 }
1953         case LyXRC::RC_PERS_DICT:
1954         case LyXRC::RC_PREVIEW:
1955         case LyXRC::RC_PREVIEW_HASHED_LABELS:
1956         case LyXRC::RC_PREVIEW_SCALE_FACTOR:
1957         case LyXRC::RC_PRINTCOLLCOPIESFLAG:
1958         case LyXRC::RC_PRINTCOPIESFLAG:
1959         case LyXRC::RC_PRINTER:
1960         case LyXRC::RC_PRINTEVENPAGEFLAG:
1961         case LyXRC::RC_PRINTEXSTRAOPTIONS:
1962         case LyXRC::RC_PRINTFILEEXTENSION:
1963         case LyXRC::RC_PRINTLANDSCAPEFLAG:
1964         case LyXRC::RC_PRINTODDPAGEFLAG:
1965         case LyXRC::RC_PRINTPAGERANGEFLAG:
1966         case LyXRC::RC_PRINTPAPERDIMENSIONFLAG:
1967         case LyXRC::RC_PRINTPAPERFLAG:
1968         case LyXRC::RC_PRINTREVERSEFLAG:
1969         case LyXRC::RC_PRINTSPOOL_COMMAND:
1970         case LyXRC::RC_PRINTSPOOL_PRINTERPREFIX:
1971         case LyXRC::RC_PRINTTOFILE:
1972         case LyXRC::RC_PRINTTOPRINTER:
1973         case LyXRC::RC_PRINT_ADAPTOUTPUT:
1974         case LyXRC::RC_PRINT_COMMAND:
1975         case LyXRC::RC_RTL_SUPPORT:
1976         case LyXRC::RC_SCREEN_DPI:
1977         case LyXRC::RC_SCREEN_FONT_ROMAN:
1978         case LyXRC::RC_SCREEN_FONT_ROMAN_FOUNDRY:
1979         case LyXRC::RC_SCREEN_FONT_SANS:
1980         case LyXRC::RC_SCREEN_FONT_SANS_FOUNDRY:
1981         case LyXRC::RC_SCREEN_FONT_SCALABLE:
1982         case LyXRC::RC_SCREEN_FONT_SIZES:
1983         case LyXRC::RC_SCREEN_FONT_TYPEWRITER:
1984         case LyXRC::RC_SCREEN_FONT_TYPEWRITER_FOUNDRY:
1985         case LyXRC::RC_GEOMETRY_SESSION:
1986         case LyXRC::RC_SCREEN_ZOOM:
1987         case LyXRC::RC_SERVERPIPE:
1988         case LyXRC::RC_SET_COLOR:
1989         case LyXRC::RC_SHOW_BANNER:
1990         case LyXRC::RC_OPEN_BUFFERS_IN_TABS:
1991         case LyXRC::RC_SPELL_COMMAND:
1992         case LyXRC::RC_SPELLCHECK_CONTINUOUSLY:
1993         case LyXRC::RC_SPLITINDEX_COMMAND:
1994         case LyXRC::RC_TEMPDIRPATH:
1995         case LyXRC::RC_TEMPLATEPATH:
1996         case LyXRC::RC_TEX_ALLOWS_SPACES:
1997         case LyXRC::RC_TEX_EXPECTS_WINDOWS_PATHS:
1998                 if (lyxrc_orig.windows_style_tex_paths != lyxrc_new.windows_style_tex_paths) {
1999                         os::windows_style_tex_paths(lyxrc_new.windows_style_tex_paths);
2000                 }
2001         case LyXRC::RC_THESAURUSDIRPATH:
2002         case LyXRC::RC_UIFILE:
2003         case LyXRC::RC_USER_EMAIL:
2004         case LyXRC::RC_USER_NAME:
2005         case LyXRC::RC_USETEMPDIR:
2006         case LyXRC::RC_USE_ALT_LANG:
2007         case LyXRC::RC_USE_CONVERTER_CACHE:
2008         case LyXRC::RC_USE_ESC_CHARS:
2009         case LyXRC::RC_USE_INP_ENC:
2010         case LyXRC::RC_USE_PERS_DICT:
2011         case LyXRC::RC_USE_TOOLTIP:
2012         case LyXRC::RC_USE_PIXMAP_CACHE:
2013         case LyXRC::RC_USE_SPELL_LIB:
2014         case LyXRC::RC_VIEWDVI_PAPEROPTION:
2015         case LyXRC::RC_SORT_LAYOUTS:
2016         case LyXRC::RC_FULL_SCREEN_LIMIT:
2017         case LyXRC::RC_FULL_SCREEN_SCROLLBAR:
2018         case LyXRC::RC_FULL_SCREEN_TABBAR:
2019         case LyXRC::RC_FULL_SCREEN_TOOLBARS:
2020         case LyXRC::RC_FULL_SCREEN_WIDTH:
2021         case LyXRC::RC_VISUAL_CURSOR:
2022         case LyXRC::RC_VIEWER:
2023         case LyXRC::RC_LAST:
2024                 break;
2025         }
2026 }
2027
2028 } // namespace anon
2029 } // namespace lyx