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