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