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