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