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