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