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