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