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