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