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