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