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