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