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