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