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