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