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