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