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