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