]> git.lyx.org Git - lyx.git/blob - src/lyxfunc.C
* lyxfunc.C (getStatus): fix handling of LFUN_RUNCHKTEX (bug 2831)
[lyx.git] / src / lyxfunc.C
1 /**
2  * \file lyxfunc.C
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 "BranchList.h"
25 #include "buffer.h"
26 #include "buffer_funcs.h"
27 #include "bufferlist.h"
28 #include "bufferparams.h"
29 #include "BufferView.h"
30 #include "cursor.h"
31 #include "CutAndPaste.h"
32 #include "debug.h"
33 #include "dispatchresult.h"
34 #include "encoding.h"
35 #include "errorlist.h"
36 #include "exporter.h"
37 #include "format.h"
38 #include "funcrequest.h"
39 #include "gettext.h"
40 #include "importer.h"
41 #include "insetiterator.h"
42 #include "intl.h"
43 #include "kbmap.h"
44 #include "language.h"
45 #include "LColor.h"
46 #include "session.h"
47 #include "lyx_main.h"
48 #include "lyx_cb.h"
49 #include "LyXAction.h"
50 #include "lyxfind.h"
51 #include "lyxlex.h"
52 #include "lyxrc.h"
53 #include "lyxrow.h"
54 #include "lyxserver.h"
55 #include "lyxtextclasslist.h"
56 #include "lyxvc.h"
57 #include "paragraph.h"
58 #include "pariterator.h"
59 #include "ParagraphParameters.h"
60 #include "undo.h"
61
62 #include "insets/insetbox.h"
63 #include "insets/insetbranch.h"
64 #include "insets/insetcommand.h"
65 #include "insets/insetert.h"
66 #include "insets/insetexternal.h"
67 #include "insets/insetfloat.h"
68 #include "insets/insetgraphics.h"
69 #include "insets/insetinclude.h"
70 #include "insets/insetnote.h"
71 #include "insets/insettabular.h"
72 #include "insets/insetvspace.h"
73 #include "insets/insetwrap.h"
74
75 #include "frontends/Alert.h"
76 #include "frontends/Dialogs.h"
77 #include "frontends/FileDialog.h"
78 #include "frontends/lyx_gui.h"
79 #include "frontends/LyXKeySym.h"
80 #include "frontends/LyXView.h"
81 #include "frontends/Menubar.h"
82 #include "frontends/Toolbars.h"
83
84 #include "support/environment.h"
85 #include "support/filefilterlist.h"
86 #include "support/filetools.h"
87 #include "support/forkedcontr.h"
88 #include "support/fs_extras.h"
89 #include "support/lstrings.h"
90 #include "support/path.h"
91 #include "support/package.h"
92 #include "support/systemcall.h"
93 #include "support/convert.h"
94 #include "support/os.h"
95
96 #include <boost/current_function.hpp>
97 #include <boost/filesystem/operations.hpp>
98
99 #include <sstream>
100
101 using bv_funcs::freefont2string;
102
103 using lyx::docstring;
104
105 using lyx::support::absolutePath;
106 using lyx::support::addName;
107 using lyx::support::addPath;
108 using lyx::support::bformat;
109 using lyx::support::changeExtension;
110 using lyx::support::contains;
111 using lyx::support::FileFilterList;
112 using lyx::support::fileSearch;
113 using lyx::support::ForkedcallsController;
114 using lyx::support::i18nLibFileSearch;
115 using lyx::support::isDirWriteable;
116 using lyx::support::isFileReadable;
117 using lyx::support::isStrInt;
118 using lyx::support::makeAbsPath;
119 using lyx::support::makeDisplayPath;
120 using lyx::support::package;
121 using lyx::support::quoteName;
122 using lyx::support::rtrim;
123 using lyx::support::split;
124 using lyx::support::subst;
125 using lyx::support::Systemcall;
126 using lyx::support::token;
127 using lyx::support::trim;
128 using lyx::support::prefixIs;
129
130 using std::endl;
131 using std::make_pair;
132 using std::pair;
133 using std::string;
134 using std::istringstream;
135 using std::ostringstream;
136
137 namespace biblio = lyx::biblio;
138 namespace fs = boost::filesystem;
139
140
141 extern BufferList bufferlist;
142 extern LyXServer * lyxserver;
143
144 extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
145
146 // (alkis)
147 extern tex_accent_struct get_accent(kb_action action);
148
149
150 namespace {
151
152 bool getStatus(LCursor cursor,
153                FuncRequest const & cmd, FuncStatus & status)
154 {
155         // Try to fix cursor in case it is broken.
156         cursor.fixIfBroken();
157
158         // This is, of course, a mess. Better create a new doc iterator and use
159         // this in Inset::getStatus. This might require an additional
160         // BufferView * arg, though (which should be avoided)
161         //LCursor safe = *this;
162         bool res = false;
163         for ( ; cursor.depth(); cursor.pop()) {
164                 //lyxerr << "\nLCursor::getStatus: cmd: " << cmd << endl << *this << endl;
165                 BOOST_ASSERT(cursor.idx() <= cursor.lastidx());
166                 BOOST_ASSERT(cursor.pit() <= cursor.lastpit());
167                 BOOST_ASSERT(cursor.pos() <= cursor.lastpos());
168
169                 // The inset's getStatus() will return 'true' if it made
170                 // a definitive decision on whether it want to handle the
171                 // request or not. The result of this decision is put into
172                 // the 'status' parameter.
173                 if (cursor.inset().getStatus(cursor, cmd, status)) {
174                         res = true;
175                         break;
176                 }
177         }
178         return res;
179 }
180
181
182 /** Return the change status at cursor position, taking in account the
183  * status at each level of the document iterator (a table in a deleted
184  * footnote is deleted).
185  * When \param outer is true, the top slice is not looked at.
186  */
187 Change::Type lookupChangeType(DocIterator const & dit, bool outer = false)
188 {
189         size_t const depth = dit.depth() - (outer ? 1 : 0);
190
191         for (size_t i = 0 ; i < depth ; ++i) {
192                 CursorSlice const & slice = dit[i];
193                 if (!slice.inset().inMathed()
194                     && slice.pos() < slice.paragraph().size()) {
195                         Change::Type const ch = slice.paragraph().lookupChange(slice.pos()).type;
196                         if (ch != Change::UNCHANGED)
197                                 return ch;
198                 }
199         }
200         return Change::UNCHANGED;
201 }
202
203 }
204
205 LyXFunc::LyXFunc(LyXView * lv)
206         : owner(lv),
207         encoded_last_key(0),
208         keyseq(toplevel_keymap.get(), toplevel_keymap.get()),
209         cancel_meta_seq(toplevel_keymap.get(), toplevel_keymap.get()),
210         meta_fake_bit(key_modifier::none)
211 {
212 }
213
214
215 void LyXFunc::handleKeyFunc(kb_action action)
216 {
217         char c = encoded_last_key;
218
219         if (keyseq.length()) {
220                 c = 0;
221         }
222
223         owner->view()->getIntl().getTransManager()
224                 .deadkey(c, get_accent(action).accent, view()->getLyXText());
225         // Need to clear, in case the minibuffer calls these
226         // actions
227         keyseq.clear();
228         // copied verbatim from do_accent_char
229         view()->cursor().resetAnchor();
230         view()->update();
231 }
232
233
234 void LyXFunc::processKeySym(LyXKeySymPtr keysym, key_modifier::state state)
235 {
236         lyxerr[Debug::KEY] << "KeySym is " << keysym->getSymbolName() << endl;
237
238         // Do nothing if we have nothing (JMarc)
239         if (!keysym->isOK()) {
240                 lyxerr[Debug::KEY] << "Empty kbd action (probably composing)"
241                                    << endl;
242                 return;
243         }
244
245         if (keysym->isModifier()) {
246                 lyxerr[Debug::KEY] << "isModifier true" << endl;
247                 return;
248         }
249
250         Encoding const * encoding = view()->cursor().getEncoding();
251
252         //encoded_last_key = keysym->getISOEncoded(encoding ? encoding->name() : "");
253         size_t encoded_last_key = keysym->getUCSEncoded();
254
255         // Do a one-deep top-level lookup for
256         // cancel and meta-fake keys. RVDK_PATCH_5
257         cancel_meta_seq.reset();
258
259         FuncRequest func = cancel_meta_seq.addkey(keysym, state);
260         lyxerr[Debug::KEY] << BOOST_CURRENT_FUNCTION
261                            << " action first set to [" << func.action << ']'
262                            << endl;
263
264         // When not cancel or meta-fake, do the normal lookup.
265         // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
266         // Mostly, meta_fake_bit = key_modifier::none. RVDK_PATCH_5.
267         if ((func.action != LFUN_CANCEL) && (func.action != LFUN_META_PREFIX)) {
268                 // remove Caps Lock and Mod2 as a modifiers
269                 func = keyseq.addkey(keysym, (state | meta_fake_bit));
270                 lyxerr[Debug::KEY] << BOOST_CURRENT_FUNCTION
271                                    << "action now set to ["
272                                    << func.action << ']' << endl;
273         }
274
275         // Dont remove this unless you know what you are doing.
276         meta_fake_bit = key_modifier::none;
277
278         // Can this happen now ?
279         if (func.action == LFUN_NOACTION) {
280                 func = FuncRequest(LFUN_COMMAND_PREFIX);
281         }
282
283         if (lyxerr.debugging(Debug::KEY)) {
284                 lyxerr << BOOST_CURRENT_FUNCTION
285                        << " Key [action="
286                        << func.action << "]["
287                        << keyseq.print() << ']'
288                        << endl;
289         }
290
291         // already here we know if it any point in going further
292         // why not return already here if action == -1 and
293         // num_bytes == 0? (Lgb)
294
295         if (keyseq.length() > 1) {
296                 owner->message(lyx::from_utf8(keyseq.print()));
297         }
298
299
300         // Maybe user can only reach the key via holding down shift.
301         // Let's see. But only if shift is the only modifier
302         if (func.action == LFUN_UNKNOWN_ACTION &&
303             state == key_modifier::shift) {
304                 lyxerr[Debug::KEY] << "Trying without shift" << endl;
305                 func = keyseq.addkey(keysym, key_modifier::none);
306                 lyxerr[Debug::KEY] << "Action now " << func.action << endl;
307         }
308
309         if (func.action == LFUN_UNKNOWN_ACTION) {
310                 // Hmm, we didn't match any of the keysequences. See
311                 // if it's normal insertable text not already covered
312                 // by a binding
313                 if (keysym->isText() && keyseq.length() == 1) {
314                         lyxerr[Debug::KEY] << "isText() is true, inserting." << endl;
315                         func = FuncRequest(LFUN_SELF_INSERT,
316                                            FuncRequest::KEYBOARD);
317                 } else {
318                         lyxerr[Debug::KEY] << "Unknown, !isText() - giving up" << endl;
319                         owner->message(_("Unknown function."));
320                         return;
321                 }
322         }
323
324         if (func.action == LFUN_SELF_INSERT) {
325                 if (encoded_last_key != 0) {
326                         docstring const arg(1, encoded_last_key);
327                         dispatch(FuncRequest(LFUN_SELF_INSERT, arg,
328                                              FuncRequest::KEYBOARD));
329                         lyxerr[Debug::KEY]
330                                 << "SelfInsert arg[`" << lyx::to_utf8(arg) << "']" << endl;
331                 }
332         } else {
333                 dispatch(func);
334         }
335 }
336
337
338 FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
339 {
340         //lyxerr << "LyXFunc::getStatus: cmd: " << cmd << endl;
341         FuncStatus flag;
342         LCursor & cur = view()->cursor();
343
344         /* In LyX/Mac, when a dialog is open, the menus of the
345            application can still be accessed without giving focus to
346            the main window. In this case, we want to disable the menu
347            entries that are buffer-related.
348
349            Note that this code is not perfect, as bug 1941 attests:
350            http://bugzilla.lyx.org/show_bug.cgi?id=1941#c4
351         */
352         Buffer * buf;
353         if (cmd.origin == FuncRequest::UI && !owner->hasFocus())
354                 buf = 0;
355         else
356                 buf = owner->buffer();
357
358         if (cmd.action == LFUN_NOACTION) {
359                 flag.message(lyx::from_utf8(N_("Nothing to do")));
360                 flag.enabled(false);
361                 return flag;
362         }
363
364         switch (cmd.action) {
365         case LFUN_UNKNOWN_ACTION:
366 #ifndef HAVE_LIBAIKSAURUS
367         case LFUN_THESAURUS_ENTRY:
368 #endif
369                 flag.unknown(true);
370                 flag.enabled(false);
371                 break;
372         default:
373                 flag |= lyx_gui::getStatus(cmd);
374         }
375
376         if (flag.unknown()) {
377                 flag.message(lyx::from_utf8(N_("Unknown action")));
378                 return flag;
379         }
380
381         if (!flag.enabled()) {
382                 if (flag.message().empty())
383                         flag.message(lyx::from_utf8(N_("Command disabled")));
384                 return flag;
385         }
386
387         // Check whether we need a buffer
388         if (!lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer) && !buf) {
389                 // no, exit directly
390                 flag.message(lyx::from_utf8(N_("Command not allowed with"
391                                     "out any document open")));
392                 flag.enabled(false);
393                 return flag;
394         }
395
396         // I would really like to avoid having this switch and rather try to
397         // encode this in the function itself.
398         // -- And I'd rather let an inset decide which LFUNs it is willing
399         // to handle (Andre')
400         bool enable = true;
401         switch (cmd.action) {
402         case LFUN_TOOLTIPS_TOGGLE:
403                 flag.setOnOff(owner->getDialogs().tooltipsEnabled());
404                 break;
405
406         case LFUN_BUFFER_TOGGLE_READ_ONLY:
407                 flag.setOnOff(buf->isReadonly());
408                 break;
409
410         case LFUN_BUFFER_SWITCH:
411                 // toggle on the current buffer, but do not toggle off
412                 // the other ones (is that a good idea?)
413                 if (lyx::to_utf8(cmd.argument()) == buf->fileName())
414                         flag.setOnOff(true);
415                 break;
416
417         case LFUN_BUFFER_EXPORT:
418                 enable = cmd.argument() == "custom"
419                         || Exporter::isExportable(*buf, lyx::to_utf8(cmd.argument()));
420                 break;
421
422         case LFUN_BUFFER_CHKTEX:
423                 enable = buf->isLatex() && !lyxrc.chktex_command.empty();
424                 break;
425
426         case LFUN_BUILD_PROGRAM:
427                 enable = Exporter::isExportable(*buf, "program");
428                 break;
429
430         case LFUN_LAYOUT_TABULAR:
431                 enable = cur.innerInsetOfType(InsetBase::TABULAR_CODE);
432                 break;
433
434         case LFUN_LAYOUT:
435         case LFUN_LAYOUT_PARAGRAPH:
436                 enable = !cur.inset().forceDefaultParagraphs(cur.idx());
437                 break;
438
439         case LFUN_VC_REGISTER:
440                 enable = !buf->lyxvc().inUse();
441                 break;
442         case LFUN_VC_CHECK_IN:
443                 enable = buf->lyxvc().inUse() && !buf->isReadonly();
444                 break;
445         case LFUN_VC_CHECK_OUT:
446                 enable = buf->lyxvc().inUse() && buf->isReadonly();
447                 break;
448         case LFUN_VC_REVERT:
449         case LFUN_VC_UNDO_LAST:
450                 enable = buf->lyxvc().inUse();
451                 break;
452         case LFUN_BUFFER_RELOAD:
453                 enable = !buf->isUnnamed() && !buf->isClean();
454                 break;
455
456         case LFUN_INSET_SETTINGS: {
457                 enable = false;
458                 if (!cur)
459                         break;
460                 InsetBase::Code code = cur.inset().lyxCode();
461                 switch (code) {
462                         case InsetBase::TABULAR_CODE:
463                                 enable = cmd.argument() == "tabular";
464                                 break;
465                         case InsetBase::ERT_CODE:
466                                 enable = cmd.argument() == "ert";
467                                 break;
468                         case InsetBase::FLOAT_CODE:
469                                 enable = cmd.argument() == "float";
470                                 break;
471                         case InsetBase::WRAP_CODE:
472                                 enable = cmd.argument() == "wrap";
473                                 break;
474                         case InsetBase::NOTE_CODE:
475                                 enable = cmd.argument() == "note";
476                                 break;
477                         case InsetBase::BRANCH_CODE:
478                                 enable = cmd.argument() == "branch";
479                                 break;
480                         case InsetBase::BOX_CODE:
481                                 enable = cmd.argument() == "box";
482                                 break;
483                         default:
484                                 break;
485                 }
486                 break;
487         }
488
489         case LFUN_INSET_APPLY: {
490                 string const name = cmd.getArg(0);
491                 InsetBase * inset = owner->getDialogs().getOpenInset(name);
492                 if (inset) {
493                         FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument());
494                         FuncStatus fs;
495                         bool const success = inset->getStatus(cur, fr, fs);
496                         // Every inset is supposed to handle this
497                         BOOST_ASSERT(success);
498                         flag |= fs;
499                 } else {
500                         FuncRequest fr(LFUN_INSET_INSERT, cmd.argument());
501                         flag |= getStatus(fr);
502                 }
503                 enable = flag.enabled();
504                 break;
505         }
506
507         case LFUN_DIALOG_SHOW: {
508                 string const name = cmd.getArg(0);
509                 if (!buf)
510                         enable = name == "aboutlyx"
511                                 || name == "file"
512                                 || name == "forks"
513                                 || name == "prefs"
514                                 || name == "texinfo";
515                 else if (name == "print")
516                         enable = Exporter::isExportable(*buf, "dvi")
517                                 && lyxrc.print_command != "none";
518                 else if (name == "character" || name == "mathpanel")
519                         enable = cur.inset().lyxCode() != InsetBase::ERT_CODE;
520                 else if (name == "latexlog")
521                         enable = isFileReadable(buf->getLogName().second);
522 #if !defined (USE_ASPELL) && !defined (USE_ISPELL) && !defined (USE_PSPELL)
523                 else if (name == "spellchecker")
524                         enable = false;
525 #endif
526                 else if (name == "vclog")
527                         enable = buf->lyxvc().inUse();
528                 else if (name == "view-source")
529                         enable = buf;
530                 break;
531         }
532
533         case LFUN_DIALOG_SHOW_NEW_INSET:
534                 enable = cur.inset().lyxCode() != InsetBase::ERT_CODE;
535                 break;
536
537         case LFUN_DIALOG_UPDATE: {
538                 string const name = cmd.getArg(0);
539                 if (!buf)
540                         enable = name == "prefs";
541                 break;
542         }
543
544         case LFUN_CITATION_INSERT: {
545                 FuncRequest fr(LFUN_INSET_INSERT, "citation");
546                 enable = getStatus(fr).enabled();
547                 break;
548         }
549
550         case LFUN_BUFFER_WRITE: {
551                 enable = view()->buffer()->isUnnamed()
552                         || !view()->buffer()->isClean();
553                 break;
554         }
555
556         // this one is difficult to get right. As a half-baked
557         // solution, we consider only the first action of the sequence
558         case LFUN_COMMAND_SEQUENCE: {
559                 // argument contains ';'-terminated commands
560                 string const firstcmd = token(lyx::to_utf8(cmd.argument()), ';', 0);
561                 FuncRequest func(lyxaction.lookupFunc(firstcmd));
562                 func.origin = cmd.origin;
563                 flag = getStatus(func);
564         }
565
566         case LFUN_BUFFER_NEW:
567         case LFUN_BUFFER_NEW_TEMPLATE:
568         case LFUN_WORD_FIND_FORWARD:
569         case LFUN_WORD_FIND_BACKWARD:
570         case LFUN_COMMAND_PREFIX:
571         case LFUN_COMMAND_EXECUTE:
572         case LFUN_CANCEL:
573         case LFUN_META_PREFIX:
574         case LFUN_BUFFER_CLOSE:
575         case LFUN_BUFFER_WRITE_AS:
576         case LFUN_BUFFER_UPDATE:
577         case LFUN_BUFFER_VIEW:
578         case LFUN_BUFFER_IMPORT:
579         case LFUN_LYX_QUIT:
580         case LFUN_TOC_VIEW:
581         case LFUN_BUFFER_AUTO_SAVE:
582         case LFUN_RECONFIGURE:
583         case LFUN_HELP_OPEN:
584         case LFUN_FILE_NEW:
585         case LFUN_FILE_OPEN:
586         case LFUN_DROP_LAYOUTS_CHOICE:
587         case LFUN_MENU_OPEN:
588         case LFUN_SERVER_GET_NAME:
589         case LFUN_SERVER_NOTIFY:
590         case LFUN_SERVER_GOTO_FILE_ROW:
591         case LFUN_DIALOG_HIDE:
592         case LFUN_DIALOG_DISCONNECT_INSET:
593         case LFUN_BUFFER_CHILD_OPEN:
594         case LFUN_TOGGLE_CURSOR_FOLLOWS_SCROLLBAR:
595         case LFUN_KEYMAP_OFF:
596         case LFUN_KEYMAP_PRIMARY:
597         case LFUN_KEYMAP_SECONDARY:
598         case LFUN_KEYMAP_TOGGLE:
599         case LFUN_REPEAT:
600         case LFUN_BUFFER_EXPORT_CUSTOM:
601         case LFUN_BUFFER_PRINT:
602         case LFUN_PREFERENCES_SAVE:
603         case LFUN_SCREEN_FONT_UPDATE:
604         case LFUN_SET_COLOR:
605         case LFUN_MESSAGE:
606         case LFUN_EXTERNAL_EDIT:
607         case LFUN_GRAPHICS_EDIT:
608         case LFUN_ALL_INSETS_TOGGLE:
609         case LFUN_BUFFER_LANGUAGE:
610         case LFUN_TEXTCLASS_APPLY:
611         case LFUN_TEXTCLASS_LOAD:
612         case LFUN_BUFFER_SAVE_AS_DEFAULT:
613         case LFUN_BUFFER_PARAMS_APPLY:
614         case LFUN_LYXRC_APPLY:
615         case LFUN_BUFFER_NEXT:
616         case LFUN_BUFFER_PREVIOUS:
617                 // these are handled in our dispatch()
618                 break;
619
620         default:
621
622                 if (!::getStatus(cur, cmd, flag))
623                         flag = view()->getStatus(cmd);
624         }
625
626         if (!enable)
627                 flag.enabled(false);
628
629         // Can we use a readonly buffer?
630         if (buf && buf->isReadonly()
631             && !lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly)
632             && !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)) {
633                 flag.message(lyx::from_utf8(N_("Document is read-only")));
634                 flag.enabled(false);
635         }
636
637         // Are we in a DELETED change-tracking region?
638         if (buf && buf->params().tracking_changes
639             && lookupChangeType(cur, true) == Change::DELETED
640             && !lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly)
641             && !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)) {
642                 flag.message(lyx::from_utf8(N_("This portion of the document is deleted.")));
643                 flag.enabled(false);
644         }
645
646         // the default error message if we disable the command
647         if (!flag.enabled() && flag.message().empty())
648                 flag.message(lyx::from_utf8(N_("Command disabled")));
649
650         return flag;
651 }
652
653
654 bool LyXFunc::ensureBufferClean(BufferView * bv)
655 {
656         Buffer & buf = *bv->buffer();
657         if (buf.isClean())
658                 return true;
659
660         docstring const file = makeDisplayPath(buf.fileName(), 30);
661         docstring text = bformat(_("The document %1$s has unsaved "
662                                              "changes.\n\nDo you want to save "
663                                              "the document?"), file);
664         int const ret = Alert::prompt(_("Save changed document?"),
665                                       text, 0, 1, _("&Save"),
666                                       _("&Cancel"));
667
668         if (ret == 0)
669                 dispatch(FuncRequest(LFUN_BUFFER_WRITE));
670
671         return buf.isClean();
672 }
673
674
675 namespace {
676
677 void showPrintError(string const & name)
678 {
679         docstring str = bformat(_("Could not print the document %1$s.\n"
680                                             "Check that your printer is set up correctly."),
681                              makeDisplayPath(name, 50));
682         Alert::error(_("Print document failed"), str);
683 }
684
685
686 void loadTextclass(string const & name)
687 {
688         std::pair<bool, lyx::textclass_type> const tc_pair =
689                 textclasslist.numberOfClass(name);
690
691         if (!tc_pair.first) {
692                 lyxerr << "Document class \"" << name
693                        << "\" does not exist."
694                        << std::endl;
695                 return;
696         }
697
698         lyx::textclass_type const tc = tc_pair.second;
699
700         if (!textclasslist[tc].load()) {
701                 docstring s = bformat(_("The document could not be converted\n"
702                                                   "into the document class %1$s."),
703                                    lyx::from_utf8(textclasslist[tc].name()));
704                 Alert::error(_("Could not change class"), s);
705         }
706 }
707
708
709 void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new);
710
711 } //namespace anon
712
713
714 void LyXFunc::dispatch(FuncRequest const & cmd)
715 {
716         BOOST_ASSERT(view());
717         string const argument = lyx::to_utf8(cmd.argument());
718         kb_action const action = cmd.action;
719
720         lyxerr[Debug::ACTION] << "LyXFunc::dispatch: cmd: " << cmd << endl;
721         //lyxerr << "LyXFunc::dispatch: cmd: " << cmd << endl;
722
723         // we have not done anything wrong yet.
724         errorstat = false;
725         dispatch_buffer.erase();
726
727         // redraw the screen at the end (first of the two drawing steps).
728         //This is done unless explicitely requested otherwise
729         bool update = true;
730         // also do the second redrawing step. Only done if requested.
731         bool updateforce = false;
732
733         FuncStatus const flag = getStatus(cmd);
734         if (!flag.enabled()) {
735                 // We cannot use this function here
736                 lyxerr[Debug::ACTION] << "LyXFunc::dispatch: "
737                        << lyxaction.getActionName(action)
738                        << " [" << action << "] is disabled at this location"
739                        << endl;
740                 setErrorMessage(flag.message());
741         } else {
742                 switch (action) {
743
744                 case LFUN_WORD_FIND_FORWARD:
745                 case LFUN_WORD_FIND_BACKWARD: {
746                         static string last_search;
747                         string searched_string;
748
749                         if (!argument.empty()) {
750                                 last_search = argument;
751                                 searched_string = argument;
752                         } else {
753                                 searched_string = last_search;
754                         }
755
756                         if (searched_string.empty())
757                                 break;
758
759                         bool const fw = action == LFUN_WORD_FIND_FORWARD;
760                         string const data =
761                                 lyx::find::find2string(searched_string, true, false, fw);
762                         lyx::find::find(view(), FuncRequest(LFUN_WORD_FIND, data));
763                         break;
764                 }
765
766                 case LFUN_COMMAND_PREFIX:
767                         owner->message(lyx::from_utf8(keyseq.printOptions()));
768                         break;
769
770                 case LFUN_COMMAND_EXECUTE:
771                         owner->getToolbars().display("minibuffer", true);
772                         owner->focus_command_buffer();
773                         break;
774
775                 case LFUN_CANCEL:
776                         keyseq.reset();
777                         meta_fake_bit = key_modifier::none;
778                         if (view()->buffer())
779                                 // cancel any selection
780                                 dispatch(FuncRequest(LFUN_MARK_OFF));
781                         setMessage(_("Cancel"));
782                         break;
783
784                 case LFUN_META_PREFIX:
785                         meta_fake_bit = key_modifier::alt;
786                         setMessage(lyx::from_utf8(keyseq.print()));
787                         break;
788
789                 case LFUN_BUFFER_TOGGLE_READ_ONLY:
790                         if (owner->buffer()->lyxvc().inUse())
791                                 owner->buffer()->lyxvc().toggleReadOnly();
792                         else
793                                 owner->buffer()->setReadonly(
794                                         !owner->buffer()->isReadonly());
795                         break;
796
797                 // --- Menus -----------------------------------------------
798                 case LFUN_BUFFER_NEW:
799                         menuNew(argument, false);
800                         break;
801
802                 case LFUN_BUFFER_NEW_TEMPLATE:
803                         menuNew(argument, true);
804                         break;
805
806                 case LFUN_BUFFER_CLOSE:
807                         closeBuffer();
808                         break;
809
810                 case LFUN_BUFFER_WRITE:
811                         if (!owner->buffer()->isUnnamed()) {
812                                 docstring const str = bformat(_("Saving document %1$s..."),
813                                          makeDisplayPath(owner->buffer()->fileName()));
814                                 owner->message(str);
815                                 menuWrite(owner->buffer());
816                                 owner->message(str + _(" done."));
817                         } else
818                                 writeAs(owner->buffer());
819                         update = false;
820                         break;
821
822                 case LFUN_BUFFER_WRITE_AS:
823                         writeAs(owner->buffer(), argument);
824                         update = false;
825                         break;
826
827                 case LFUN_BUFFER_RELOAD: {
828                         docstring const file = makeDisplayPath(view()->buffer()->fileName(), 20);
829                         docstring text = bformat(_("Any changes will be lost. Are you sure "
830                                                              "you want to revert to the saved version of the document %1$s?"), file);
831                         int const ret = Alert::prompt(_("Revert to saved document?"),
832                                 text, 0, 1, _("&Revert"), _("&Cancel"));
833
834                         if (ret == 0)
835                                 view()->reload();
836                         break;
837                 }
838
839                 case LFUN_BUFFER_UPDATE:
840                         Exporter::Export(owner->buffer(), argument, true);
841                         break;
842
843                 case LFUN_BUFFER_VIEW:
844                         Exporter::preview(owner->buffer(), argument);
845                         break;
846
847                 case LFUN_BUILD_PROGRAM:
848                         Exporter::Export(owner->buffer(), "program", true);
849                         break;
850
851                 case LFUN_BUFFER_CHKTEX:
852                         owner->buffer()->runChktex();
853                         break;
854
855                 case LFUN_BUFFER_EXPORT:
856                         if (argument == "custom")
857                                 owner->getDialogs().show("sendto");
858                         else {
859                                 Exporter::Export(owner->buffer(), argument, false);
860                         }
861                         break;
862
863                 case LFUN_BUFFER_EXPORT_CUSTOM: {
864                         string format_name;
865                         string command = split(argument, format_name, ' ');
866                         Format const * format = formats.getFormat(format_name);
867                         if (!format) {
868                                 lyxerr << "Format \"" << format_name
869                                        << "\" not recognized!"
870                                        << std::endl;
871                                 break;
872                         }
873
874                         Buffer * buffer = owner->buffer();
875
876                         // The name of the file created by the conversion process
877                         string filename;
878
879                         // Output to filename
880                         if (format->name() == "lyx") {
881                                 string const latexname =
882                                         buffer->getLatexName(false);
883                                 filename = changeExtension(latexname,
884                                                            format->extension());
885                                 filename = addName(buffer->temppath(), filename);
886
887                                 if (!buffer->writeFile(filename))
888                                         break;
889
890                         } else {
891                                 Exporter::Export(buffer, format_name, true, filename);
892                         }
893
894                         // Substitute $$FName for filename
895                         if (!contains(command, "$$FName"))
896                                 command = "( " + command + " ) < $$FName";
897                         command = subst(command, "$$FName", filename);
898
899                         // Execute the command in the background
900                         Systemcall call;
901                         call.startscript(Systemcall::DontWait, command);
902                         break;
903                 }
904
905                 case LFUN_BUFFER_PRINT: {
906                         string target;
907                         string target_name;
908                         string command = split(split(argument, target, ' '),
909                                                target_name, ' ');
910
911                         if (target.empty()
912                             || target_name.empty()
913                             || command.empty()) {
914                                 lyxerr << "Unable to parse \""
915                                        << argument << '"' << std::endl;
916                                 break;
917                         }
918                         if (target != "printer" && target != "file") {
919                                 lyxerr << "Unrecognized target \""
920                                        << target << '"' << std::endl;
921                                 break;
922                         }
923
924                         Buffer * buffer = owner->buffer();
925
926                         if (!Exporter::Export(buffer, "dvi", true)) {
927                                 showPrintError(buffer->fileName());
928                                 break;
929                         }
930
931                         // Push directory path.
932                         string const path = buffer->temppath();
933                         lyx::support::Path p(path);
934
935                         // there are three cases here:
936                         // 1. we print to a file
937                         // 2. we print directly to a printer
938                         // 3. we print using a spool command (print to file first)
939                         Systemcall one;
940                         int res = 0;
941                         string const dviname =
942                                 changeExtension(buffer->getLatexName(true),
943                                                 "dvi");
944
945                         if (target == "printer") {
946                                 if (!lyxrc.print_spool_command.empty()) {
947                                         // case 3: print using a spool
948                                         string const psname =
949                                                 changeExtension(dviname,".ps");
950                                         command += lyxrc.print_to_file
951                                                 + quoteName(psname)
952                                                 + ' '
953                                                 + quoteName(dviname);
954
955                                         string command2 =
956                                                 lyxrc.print_spool_command +' ';
957                                         if (target_name != "default") {
958                                                 command2 += lyxrc.print_spool_printerprefix
959                                                         + target_name
960                                                         + ' ';
961                                         }
962                                         command2 += quoteName(psname);
963                                         // First run dvips.
964                                         // If successful, then spool command
965                                         res = one.startscript(
966                                                 Systemcall::Wait,
967                                                 command);
968
969                                         if (res == 0)
970                                                 res = one.startscript(
971                                                         Systemcall::DontWait,
972                                                         command2);
973                                 } else {
974                                         // case 2: print directly to a printer
975                                         res = one.startscript(
976                                                 Systemcall::DontWait,
977                                                 command + quoteName(dviname));
978                                 }
979
980                         } else {
981                                 // case 1: print to a file
982                                 command += lyxrc.print_to_file
983                                         + quoteName(makeAbsPath(target_name,
984                                                                 path))
985                                         + ' '
986                                         + quoteName(dviname);
987                                 res = one.startscript(Systemcall::DontWait,
988                                                       command);
989                         }
990
991                         if (res != 0)
992                                 showPrintError(buffer->fileName());
993                         break;
994                 }
995
996                 case LFUN_BUFFER_IMPORT:
997                         doImport(argument);
998                         break;
999
1000                 case LFUN_LYX_QUIT:
1001                         if (view()->buffer()) {
1002                                 // save cursor Position for opened files to .lyx/session
1003                                 LyX::ref().session().saveFilePosition(owner->buffer()->fileName(),
1004                                         boost::tie(view()->cursor().pit(), view()->cursor().pos()) );
1005                                 // save bookmarks to .lyx/session
1006                                 view()->saveSavedPositions();
1007                         }
1008                         quitLyX(argument == "force");
1009                         break;
1010
1011                 case LFUN_TOC_VIEW: {
1012                         InsetCommandParams p("tableofcontents");
1013                         string const data = InsetCommandMailer::params2string("toc", p);
1014                         owner->getDialogs().show("toc", data, 0);
1015                         break;
1016                 }
1017
1018                 case LFUN_BUFFER_AUTO_SAVE:
1019                         autoSave(view());
1020                         break;
1021
1022                 case LFUN_RECONFIGURE:
1023                         reconfigure(view());
1024                         break;
1025
1026                 case LFUN_HELP_OPEN: {
1027                         string const arg = argument;
1028                         if (arg.empty()) {
1029                                 setErrorMessage(_("Missing argument"));
1030                                 break;
1031                         }
1032                         string const fname = i18nLibFileSearch("doc", arg, "lyx");
1033                         if (fname.empty()) {
1034                                 lyxerr << "LyX: unable to find documentation file `"
1035                                                          << arg << "'. Bad installation?" << endl;
1036                                 break;
1037                         }
1038                         owner->message(bformat(_("Opening help file %1$s..."),
1039                                 makeDisplayPath(fname)));
1040                         owner->loadLyXFile(fname, false);
1041                         break;
1042                 }
1043
1044                 // --- version control -------------------------------
1045                 case LFUN_VC_REGISTER:
1046                         if (!ensureBufferClean(view()))
1047                                 break;
1048                         if (!owner->buffer()->lyxvc().inUse()) {
1049                                 owner->buffer()->lyxvc().registrer();
1050                                 view()->reload();
1051                         }
1052                         break;
1053
1054                 case LFUN_VC_CHECK_IN:
1055                         if (!ensureBufferClean(view()))
1056                                 break;
1057                         if (owner->buffer()->lyxvc().inUse()
1058                                         && !owner->buffer()->isReadonly()) {
1059                                 owner->buffer()->lyxvc().checkIn();
1060                                 view()->reload();
1061                         }
1062                         break;
1063
1064                 case LFUN_VC_CHECK_OUT:
1065                         if (!ensureBufferClean(view()))
1066                                 break;
1067                         if (owner->buffer()->lyxvc().inUse()
1068                                         && owner->buffer()->isReadonly()) {
1069                                 owner->buffer()->lyxvc().checkOut();
1070                                 view()->reload();
1071                         }
1072                         break;
1073
1074                 case LFUN_VC_REVERT:
1075                         owner->buffer()->lyxvc().revert();
1076                         view()->reload();
1077                         break;
1078
1079                 case LFUN_VC_UNDO_LAST:
1080                         owner->buffer()->lyxvc().undoLast();
1081                         view()->reload();
1082                         break;
1083
1084                 // --- buffers ----------------------------------------
1085                 case LFUN_BUFFER_SWITCH:
1086                         owner->setBuffer(bufferlist.getBuffer(argument));
1087                         break;
1088
1089                 case LFUN_BUFFER_NEXT:
1090                         owner->setBuffer(bufferlist.next(view()->buffer()));
1091                         break;
1092
1093                 case LFUN_BUFFER_PREVIOUS:
1094                         owner->setBuffer(bufferlist.previous(view()->buffer()));
1095                         break;
1096
1097                 case LFUN_FILE_NEW:
1098                         newFile(view(), argument);
1099                         break;
1100
1101                 case LFUN_FILE_OPEN:
1102                         open(argument);
1103                         break;
1104
1105                 case LFUN_DROP_LAYOUTS_CHOICE:
1106                         owner->getToolbars().openLayoutList();
1107                         break;
1108
1109                 case LFUN_MENU_OPEN:
1110                         owner->getMenubar().openByName(lyx::from_utf8(argument));
1111                         break;
1112
1113                 // --- lyxserver commands ----------------------------
1114                 case LFUN_SERVER_GET_NAME:
1115                         setMessage(lyx::from_utf8(owner->buffer()->fileName()));
1116                         lyxerr[Debug::INFO] << "FNAME["
1117                                                          << owner->buffer()->fileName()
1118                                                          << "] " << endl;
1119                         break;
1120
1121                 case LFUN_SERVER_NOTIFY:
1122                         dispatch_buffer = lyx::from_utf8(keyseq.print());
1123                         lyxserver->notifyClient(lyx::to_utf8(dispatch_buffer));
1124                         break;
1125
1126                 case LFUN_SERVER_GOTO_FILE_ROW: {
1127                         string file_name;
1128                         int row;
1129                         istringstream is(argument);
1130                         is >> file_name >> row;
1131                         if (prefixIs(file_name, package().temp_dir())) {
1132                                 // Needed by inverse dvi search. If it is a file
1133                                 // in tmpdir, call the apropriated function
1134                                 owner->setBuffer(bufferlist.getBufferFromTmp(file_name));
1135                         } else {
1136                                 // Must replace extension of the file to be .lyx
1137                                 // and get full path
1138                                 string const s = changeExtension(file_name, ".lyx");
1139                                 // Either change buffer or load the file
1140                                 if (bufferlist.exists(s)) {
1141                                         owner->setBuffer(bufferlist.getBuffer(s));
1142                                 } else {
1143                                         owner->loadLyXFile(s);
1144                                 }
1145                         }
1146
1147                         view()->setCursorFromRow(row);
1148
1149                         view()->center();
1150                         // see BufferView::center()
1151                         break;
1152                 }
1153
1154                 case LFUN_DIALOG_SHOW: {
1155                         string const name = cmd.getArg(0);
1156                         string data = trim(lyx::to_utf8(cmd.argument()).substr(name.size()));
1157
1158                         if (name == "character") {
1159                                 data = freefont2string();
1160                                 if (!data.empty())
1161                                         owner->getDialogs().show("character", data);
1162                         } else if (name == "latexlog") {
1163                                 pair<Buffer::LogType, string> const logfile =
1164                                         owner->buffer()->getLogName();
1165                                 switch (logfile.first) {
1166                                 case Buffer::latexlog:
1167                                         data = "latex ";
1168                                         break;
1169                                 case Buffer::buildlog:
1170                                         data = "literate ";
1171                                         break;
1172                                 }
1173                                 data += LyXLex::quoteString(logfile.second);
1174                                 owner->getDialogs().show("log", data);
1175                         } else if (name == "vclog") {
1176                                 string const data = "vc " +
1177                                         LyXLex::quoteString(owner->buffer()->lyxvc().getLogFile());
1178                                 owner->getDialogs().show("log", data);
1179                         } else
1180                                 owner->getDialogs().show(name, data);
1181                         break;
1182                 }
1183
1184                 case LFUN_DIALOG_SHOW_NEW_INSET: {
1185                         string const name = cmd.getArg(0);
1186                         string data = trim(lyx::to_utf8(cmd.argument()).substr(name.size()));
1187                         if (name == "bibitem" ||
1188                             name == "bibtex" ||
1189                             name == "index" ||
1190                             name == "label" ||
1191                             name == "ref" ||
1192                             name == "toc" ||
1193                             name == "url") {
1194                                 InsetCommandParams p(name);
1195                                 data = InsetCommandMailer::params2string(name, p);
1196                         } else if (name == "include") {
1197                                 InsetCommandParams p(data);
1198                                 data = InsetIncludeMailer::params2string(p);
1199                         } else if (name == "box") {
1200                                 // \c data == "Boxed" || "Frameless" etc
1201                                 InsetBoxParams p(data);
1202                                 data = InsetBoxMailer::params2string(p);
1203                         } else if (name == "branch") {
1204                                 InsetBranchParams p;
1205                                 data = InsetBranchMailer::params2string(p);
1206                         } else if (name == "citation") {
1207                                 InsetCommandParams p("cite");
1208                                 data = InsetCommandMailer::params2string(name, p);
1209                         } else if (name == "ert") {
1210                                 data = InsetERTMailer::params2string(InsetCollapsable::Open);
1211                         } else if (name == "external") {
1212                                 InsetExternalParams p;
1213                                 Buffer const & buffer = *owner->buffer();
1214                                 data = InsetExternalMailer::params2string(p, buffer);
1215                         } else if (name == "float") {
1216                                 InsetFloatParams p;
1217                                 data = InsetFloatMailer::params2string(p);
1218                         } else if (name == "graphics") {
1219                                 InsetGraphicsParams p;
1220                                 Buffer const & buffer = *owner->buffer();
1221                                 data = InsetGraphicsMailer::params2string(p, buffer);
1222                         } else if (name == "note") {
1223                                 InsetNoteParams p;
1224                                 data = InsetNoteMailer::params2string(p);
1225                         } else if (name == "vspace") {
1226                                 VSpace space;
1227                                 data = InsetVSpaceMailer::params2string(space);
1228                         } else if (name == "wrap") {
1229                                 InsetWrapParams p;
1230                                 data = InsetWrapMailer::params2string(p);
1231                         }
1232                         owner->getDialogs().show(name, data, 0);
1233                         break;
1234                 }
1235
1236                 case LFUN_DIALOG_UPDATE: {
1237                         string const & name = argument;
1238                         // Can only update a dialog connected to an existing inset
1239                         InsetBase * inset = owner->getDialogs().getOpenInset(name);
1240                         if (inset) {
1241                                 FuncRequest fr(LFUN_INSET_DIALOG_UPDATE, cmd.argument());
1242                                 inset->dispatch(view()->cursor(), fr);
1243                         } else if (name == "paragraph") {
1244                                 dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
1245                         } else if (name == "prefs") {
1246                                 owner->getDialogs().update(name, string());
1247                         }
1248                         break;
1249                 }
1250
1251                 case LFUN_DIALOG_HIDE:
1252                         Dialogs::hide(argument, 0);
1253                         break;
1254
1255                 case LFUN_DIALOG_DISCONNECT_INSET:
1256                         owner->getDialogs().disconnect(argument);
1257                         break;
1258
1259
1260                 case LFUN_CITATION_INSERT: {
1261                         if (!argument.empty()) {
1262                                 // we can have one optional argument, delimited by '|'
1263                                 // citation-insert <key>|<text_before>
1264                                 // this should be enhanced to also support text_after
1265                                 // and citation style
1266                                 string arg = argument;
1267                                 string opt1;
1268                                 if (contains(argument, "|")) {
1269                                         arg = token(argument, '|', 0);
1270                                         opt1 = '[' + token(argument, '|', 1) + ']';
1271                                 }
1272                                 std::ostringstream os;
1273                                 os << "citation LatexCommand\n"
1274                                    << "\\cite" << opt1 << "{" << arg << "}\n"
1275                                    << "\\end_inset";
1276                                 FuncRequest fr(LFUN_INSET_INSERT, os.str());
1277                                 dispatch(fr);
1278                         } else
1279                                 dispatch(FuncRequest(LFUN_DIALOG_SHOW, "citation"));
1280                         break;
1281                 }
1282
1283                 case LFUN_BUFFER_CHILD_OPEN: {
1284                         string const filename =
1285                                 makeAbsPath(argument, owner->buffer()->filePath());
1286                         // FIXME Should use bformat
1287                         setMessage(_("Opening child document ") +
1288                                          makeDisplayPath(filename) + lyx::from_ascii("..."));
1289                         view()->savePosition(0);
1290                         string const parentfilename = owner->buffer()->fileName();
1291                         if (bufferlist.exists(filename))
1292                                 owner->setBuffer(bufferlist.getBuffer(filename));
1293                         else
1294                                 owner->loadLyXFile(filename);
1295                         // Set the parent name of the child document.
1296                         // This makes insertion of citations and references in the child work,
1297                         // when the target is in the parent or another child document.
1298                         owner->buffer()->setParentName(parentfilename);
1299                         break;
1300                 }
1301
1302                 case LFUN_TOGGLE_CURSOR_FOLLOWS_SCROLLBAR:
1303                         lyxrc.cursor_follows_scrollbar = !lyxrc.cursor_follows_scrollbar;
1304                         break;
1305
1306                 case LFUN_KEYMAP_OFF:
1307                         owner->view()->getIntl().keyMapOn(false);
1308                         break;
1309
1310                 case LFUN_KEYMAP_PRIMARY:
1311                         owner->view()->getIntl().keyMapPrim();
1312                         break;
1313
1314                 case LFUN_KEYMAP_SECONDARY:
1315                         owner->view()->getIntl().keyMapSec();
1316                         break;
1317
1318                 case LFUN_KEYMAP_TOGGLE:
1319                         owner->view()->getIntl().toggleKeyMap();
1320                         break;
1321
1322                 case LFUN_REPEAT: {
1323                         // repeat command
1324                         string countstr;
1325                         string rest = split(argument, countstr, ' ');
1326                         istringstream is(countstr);
1327                         int count = 0;
1328                         is >> count;
1329                         lyxerr << "repeat: count: " << count << " cmd: " << rest << endl;
1330                         for (int i = 0; i < count; ++i)
1331                                 dispatch(lyxaction.lookupFunc(rest));
1332                         break;
1333                 }
1334
1335                 case LFUN_COMMAND_SEQUENCE: {
1336                         // argument contains ';'-terminated commands
1337                         string arg = argument;
1338                         while (!arg.empty()) {
1339                                 string first;
1340                                 arg = split(arg, first, ';');
1341                                 FuncRequest func(lyxaction.lookupFunc(first));
1342                                 func.origin = cmd.origin;
1343                                 dispatch(func);
1344                         }
1345                         break;
1346                 }
1347
1348                 case LFUN_PREFERENCES_SAVE: {
1349                         lyx::support::Path p(package().user_support());
1350                         lyxrc.write("preferences", false);
1351                         break;
1352                 }
1353
1354                 case LFUN_SCREEN_FONT_UPDATE:
1355                         // handle the screen font changes.
1356                         lyxrc.set_font_norm_type();
1357                         lyx_gui::update_fonts();
1358                         // All visible buffers will need resize
1359                         view()->resize();
1360                         break;
1361
1362                 case LFUN_SET_COLOR: {
1363                         string lyx_name;
1364                         string const x11_name = split(argument, lyx_name, ' ');
1365                         if (lyx_name.empty() || x11_name.empty()) {
1366                                 setErrorMessage(_("Syntax: set-color <lyx_name>"
1367                                                         " <x11_name>"));
1368                                 break;
1369                         }
1370
1371                         bool const graphicsbg_changed =
1372                                 (lyx_name == lcolor.getLyXName(LColor::graphicsbg) &&
1373                                  x11_name != lcolor.getX11Name(LColor::graphicsbg));
1374
1375                         if (!lcolor.setColor(lyx_name, x11_name)) {
1376                                 setErrorMessage(
1377                                                 bformat(_("Set-color \"%1$s\" failed "
1378                                                                        "- color is undefined or "
1379                                                                        "may not be redefined"),
1380                                                                            lyx::from_utf8(lyx_name)));
1381                                 break;
1382                         }
1383
1384                         lyx_gui::update_color(lcolor.getFromLyXName(lyx_name));
1385
1386                         if (graphicsbg_changed) {
1387 #ifdef WITH_WARNINGS
1388 #warning FIXME!! The graphics cache no longer has a changeDisplay method.
1389 #endif
1390 #if 0
1391                                 lyx::graphics::GCache::get().changeDisplay(true);
1392 #endif
1393                         }
1394                         break;
1395                 }
1396
1397                 case LFUN_MESSAGE:
1398                         owner->message(lyx::from_utf8(argument));
1399                         break;
1400
1401                 case LFUN_TOOLTIPS_TOGGLE:
1402                         owner->getDialogs().toggleTooltips();
1403                         break;
1404
1405                 case LFUN_EXTERNAL_EDIT: {
1406                         FuncRequest fr(action, argument);
1407                         InsetExternal().dispatch(view()->cursor(), fr);
1408                         break;
1409                 }
1410
1411                 case LFUN_GRAPHICS_EDIT: {
1412                         FuncRequest fr(action, argument);
1413                         InsetGraphics().dispatch(view()->cursor(), fr);
1414                         break;
1415                 }
1416
1417                 case LFUN_INSET_APPLY: {
1418                         string const name = cmd.getArg(0);
1419                         InsetBase * inset = owner->getDialogs().getOpenInset(name);
1420                         if (inset) {
1421                                 FuncRequest fr(LFUN_INSET_MODIFY, argument);
1422                                 inset->dispatch(view()->cursor(), fr);
1423                         } else {
1424                                 FuncRequest fr(LFUN_INSET_INSERT, argument);
1425                                 dispatch(fr);
1426                         }
1427                         // ideally, the update flag should be set by the insets,
1428                         // but this is not possible currently
1429                         updateforce = true;
1430                         break;
1431                 }
1432
1433                 case LFUN_ALL_INSETS_TOGGLE: {
1434                         string action;
1435                         string const name = split(argument, action, ' ');
1436                         InsetBase::Code const inset_code =
1437                                 InsetBase::translate(name);
1438
1439                         LCursor & cur = view()->cursor();
1440                         FuncRequest fr(LFUN_INSET_TOGGLE, action);
1441
1442                         InsetBase & inset = owner->buffer()->inset();
1443                         InsetIterator it  = inset_iterator_begin(inset);
1444                         InsetIterator const end = inset_iterator_end(inset);
1445                         for (; it != end; ++it) {
1446                                 if (inset_code == InsetBase::NO_CODE
1447                                     || inset_code == it->lyxCode()) {
1448                                         LCursor tmpcur = cur;
1449                                         tmpcur.pushLeft(*it);
1450                                         it->dispatch(tmpcur, fr);
1451                                 }
1452                         }
1453                         updateforce = true;
1454                         break;
1455                 }
1456
1457                 case LFUN_BUFFER_LANGUAGE: {
1458                         Buffer & buffer = *owner->buffer();
1459                         Language const * oldL = buffer.params().language;
1460                         Language const * newL = languages.getLanguage(argument);
1461                         if (!newL || oldL == newL)
1462                                 break;
1463
1464                         if (oldL->rightToLeft() == newL->rightToLeft()
1465                             && !buffer.isMultiLingual())
1466                                 buffer.changeLanguage(oldL, newL);
1467                         else
1468                                 buffer.updateDocLang(newL);
1469                         break;
1470                 }
1471
1472                 case LFUN_BUFFER_SAVE_AS_DEFAULT: {
1473                         string const fname =
1474                                 addName(addPath(package().user_support(), "templates/"),
1475                                         "defaults.lyx");
1476                         Buffer defaults(fname);
1477
1478                         istringstream ss(argument);
1479                         LyXLex lex(0,0);
1480                         lex.setStream(ss);
1481                         int const unknown_tokens = defaults.readHeader(lex);
1482
1483                         if (unknown_tokens != 0) {
1484                                 lyxerr << "Warning in LFUN_BUFFER_SAVE_AS_DEFAULT!\n"
1485                                        << unknown_tokens << " unknown token"
1486                                        << (unknown_tokens == 1 ? "" : "s")
1487                                        << endl;
1488                         }
1489
1490                         if (defaults.writeFile(defaults.fileName()))
1491                                 // FIXME Should use bformat
1492                                 setMessage(_("Document defaults saved in ")
1493                                            + makeDisplayPath(fname));
1494                         else
1495                                 setErrorMessage(_("Unable to save document defaults"));
1496                         break;
1497                 }
1498
1499                 case LFUN_BUFFER_PARAMS_APPLY: {
1500                         biblio::CiteEngine const engine =
1501                                 owner->buffer()->params().cite_engine;
1502
1503                         istringstream ss(argument);
1504                         LyXLex lex(0,0);
1505                         lex.setStream(ss);
1506                         int const unknown_tokens =
1507                                 owner->buffer()->readHeader(lex);
1508
1509                         if (unknown_tokens != 0) {
1510                                 lyxerr << "Warning in LFUN_BUFFER_PARAMS_APPLY!\n"
1511                                        << unknown_tokens << " unknown token"
1512                                        << (unknown_tokens == 1 ? "" : "s")
1513                                        << endl;
1514                         }
1515                         if (engine == owner->buffer()->params().cite_engine)
1516                                 break;
1517
1518                         LCursor & cur = view()->cursor();
1519                         FuncRequest fr(LFUN_INSET_REFRESH);
1520
1521                         InsetBase & inset = owner->buffer()->inset();
1522                         InsetIterator it  = inset_iterator_begin(inset);
1523                         InsetIterator const end = inset_iterator_end(inset);
1524                         for (; it != end; ++it)
1525                                 if (it->lyxCode() == InsetBase::CITE_CODE)
1526                                         it->dispatch(cur, fr);
1527                         break;
1528                 }
1529
1530                 case LFUN_TEXTCLASS_APPLY: {
1531                         Buffer * buffer = owner->buffer();
1532
1533                         lyx::textclass_type const old_class =
1534                                 buffer->params().textclass;
1535
1536                         loadTextclass(argument);
1537
1538                         std::pair<bool, lyx::textclass_type> const tc_pair =
1539                                 textclasslist.numberOfClass(argument);
1540
1541                         if (!tc_pair.first)
1542                                 break;
1543
1544                         lyx::textclass_type const new_class = tc_pair.second;
1545                         if (old_class == new_class)
1546                                 // nothing to do
1547                                 break;
1548
1549                         owner->message(_("Converting document to new document class..."));
1550                         recordUndoFullDocument(view());
1551                         buffer->params().textclass = new_class;
1552                         StableDocIterator backcur(view()->cursor());
1553                         ErrorList & el = buffer->errorList("Class Switch");
1554                         lyx::cap::switchBetweenClasses(
1555                                 old_class, new_class,
1556                                 static_cast<InsetText &>(buffer->inset()), el);
1557
1558                         view()->setCursor(backcur.asDocIterator(&(buffer->inset())));
1559
1560                         buffer->errors("Class Switch");
1561                         updateLabels(*buffer);
1562                         updateforce = true;
1563                         break;
1564                 }
1565
1566                 case LFUN_TEXTCLASS_LOAD:
1567                         loadTextclass(argument);
1568                         break;
1569
1570                 case LFUN_LYXRC_APPLY: {
1571                         LyXRC const lyxrc_orig = lyxrc;
1572
1573                         istringstream ss(argument);
1574                         bool const success = lyxrc.read(ss) == 0;
1575
1576                         if (!success) {
1577                                 lyxerr << "Warning in LFUN_LYXRC_APPLY!\n"
1578                                        << "Unable to read lyxrc data"
1579                                        << endl;
1580                                 break;
1581                         }
1582
1583                         actOnUpdatedPrefs(lyxrc_orig, lyxrc);
1584                         break;
1585                 }
1586
1587                 default: {
1588                         view()->cursor().dispatch(cmd);
1589                         updateforce |= view()->cursor().result().update();
1590                         if (!view()->cursor().result().dispatched())
1591                                 updateforce |= view()->dispatch(cmd);
1592                         break;
1593                 }
1594                 }
1595
1596                 if (view()->buffer()) {
1597                         // Redraw screen unless explicitly told otherwise.
1598                         // This also initializes the position cache for all insets
1599                         // in (at least partially) visible top-level paragraphs.
1600                         if (updateforce)
1601                                 view()->update(Update::FitCursor | Update::Force);
1602                         else if (update)
1603                                 view()->update(Update::FitCursor);
1604
1605                         owner->redrawWorkArea();
1606
1607                         // if we executed a mutating lfun, mark the buffer as dirty
1608                         if (flag.enabled()
1609                             && !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)
1610                             && !lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly))
1611                                 view()->buffer()->markDirty();
1612
1613                         if (view()->cursor().inTexted()) {
1614                                 owner->updateLayoutChoice();
1615                         }
1616                 }
1617         }
1618         if (!quitting)
1619                 // FIXME UNICODE: _() does not support anything but ascii.
1620                 // Do we need a lyx::to_ascii() method?
1621                 sendDispatchMessage(getMessage(), cmd);
1622 }
1623
1624
1625 void LyXFunc::sendDispatchMessage(docstring const & msg, FuncRequest const & cmd)
1626 {
1627         /* When an action did not originate from the UI/kbd, it makes
1628          * sense to avoid updating the GUI. It turns out that this
1629          * fixes bug 1941, for reasons that are described here:
1630          * http://bugzilla.lyx.org/show_bug.cgi?id=1941#c4
1631          */
1632         if (cmd.origin != FuncRequest::INTERNAL) {
1633                 owner->updateMenubar();
1634                 owner->updateToolbars();
1635         }
1636
1637         const bool verbose = (cmd.origin == FuncRequest::UI
1638                               || cmd.origin == FuncRequest::COMMANDBUFFER);
1639
1640         if (cmd.action == LFUN_SELF_INSERT || !verbose) {
1641                 lyxerr[Debug::ACTION] << "dispatch msg is " << lyx::to_utf8(msg) << endl;
1642                 if (!msg.empty())
1643                         owner->message(msg);
1644                 return;
1645         }
1646
1647         docstring dispatch_msg = msg;
1648         if (!dispatch_msg.empty())
1649                 dispatch_msg += ' ';
1650
1651         string comname = lyxaction.getActionName(cmd.action);
1652
1653         bool argsadded = false;
1654
1655         if (!cmd.argument().empty()) {
1656                 if (cmd.action != LFUN_UNKNOWN_ACTION) {
1657                         comname += ' ' + lyx::to_utf8(cmd.argument());
1658                         argsadded = true;
1659                 }
1660         }
1661
1662         string const shortcuts = toplevel_keymap->printbindings(cmd);
1663
1664         if (!shortcuts.empty())
1665                 comname += ": " + shortcuts;
1666         else if (!argsadded && !cmd.argument().empty())
1667                 comname += ' ' + lyx::to_utf8(cmd.argument());
1668
1669         if (!comname.empty()) {
1670                 comname = rtrim(comname);
1671                 dispatch_msg += lyx::from_utf8('(' + rtrim(comname) + ')');
1672         }
1673
1674         lyxerr[Debug::ACTION] << "verbose dispatch msg "
1675                 << lyx::to_utf8(dispatch_msg) << endl;
1676         if (!dispatch_msg.empty())
1677                 owner->message(dispatch_msg);
1678 }
1679
1680
1681 void LyXFunc::setupLocalKeymap()
1682 {
1683         keyseq.stdmap = toplevel_keymap.get();
1684         keyseq.curmap = toplevel_keymap.get();
1685         cancel_meta_seq.stdmap = toplevel_keymap.get();
1686         cancel_meta_seq.curmap = toplevel_keymap.get();
1687 }
1688
1689
1690 void LyXFunc::menuNew(string const & name, bool fromTemplate)
1691 {
1692         string initpath = lyxrc.document_path;
1693         string filename(name);
1694
1695         if (view()->buffer()) {
1696                 string const trypath = owner->buffer()->filePath();
1697                 // If directory is writeable, use this as default.
1698                 if (isDirWriteable(trypath))
1699                         initpath = trypath;
1700         }
1701
1702         static int newfile_number;
1703
1704         if (filename.empty()) {
1705                 filename = addName(lyxrc.document_path,
1706                             "newfile" + convert<string>(++newfile_number) + ".lyx");
1707                 while (bufferlist.exists(filename) || fs::is_readable(filename)) {
1708                         ++newfile_number;
1709                         filename = addName(lyxrc.document_path,
1710                                            "newfile" +  convert<string>(newfile_number) +
1711                                     ".lyx");
1712                 }
1713         }
1714
1715         // The template stuff
1716         string templname;
1717         if (fromTemplate) {
1718                 FileDialog fileDlg(lyx::to_utf8(_("Select template file")),
1719                         LFUN_SELECT_FILE_SYNC,
1720                         make_pair(string(lyx::to_utf8(_("Documents|#o#O"))),
1721                                   string(lyxrc.document_path)),
1722                         make_pair(string(lyx::to_utf8(_("Templates|#T#t"))),
1723                                   string(lyxrc.template_path)));
1724
1725                 FileDialog::Result result =
1726                         fileDlg.open(lyxrc.template_path,
1727                                      FileFilterList(lyx::to_utf8(_("LyX Documents (*.lyx)"))),
1728                                      string());
1729
1730                 if (result.first == FileDialog::Later)
1731                         return;
1732                 if (result.second.empty())
1733                         return;
1734                 templname = result.second;
1735         }
1736
1737         Buffer * const b = newFile(filename, templname, !name.empty());
1738         if (b)
1739                 owner->setBuffer(b);
1740 }
1741
1742
1743 void LyXFunc::open(string const & fname)
1744 {
1745         string initpath = lyxrc.document_path;
1746
1747         if (view()->buffer()) {
1748                 string const trypath = owner->buffer()->filePath();
1749                 // If directory is writeable, use this as default.
1750                 if (isDirWriteable(trypath))
1751                         initpath = trypath;
1752         }
1753
1754         string filename;
1755
1756         if (fname.empty()) {
1757                 FileDialog fileDlg(lyx::to_utf8(_("Select document to open")),
1758                         LFUN_FILE_OPEN,
1759                         make_pair(string(lyx::to_utf8(_("Documents|#o#O"))),
1760                                   string(lyxrc.document_path)),
1761                         make_pair(string(lyx::to_utf8(_("Examples|#E#e"))),
1762                                   string(addPath(package().system_support(), "examples"))));
1763
1764                 FileDialog::Result result =
1765                         fileDlg.open(initpath,
1766                                      FileFilterList(lyx::to_utf8(_("LyX Documents (*.lyx)"))),
1767                                      string());
1768
1769                 if (result.first == FileDialog::Later)
1770                         return;
1771
1772                 filename = result.second;
1773
1774                 // check selected filename
1775                 if (filename.empty()) {
1776                         owner->message(_("Canceled."));
1777                         return;
1778                 }
1779         } else
1780                 filename = fname;
1781
1782         // get absolute path of file and add ".lyx" to the filename if
1783         // necessary
1784         string const fullpath = fileSearch(string(), filename, "lyx");
1785         if (!fullpath.empty()) {
1786                 filename = fullpath;
1787         }
1788
1789         docstring const disp_fn = makeDisplayPath(filename);
1790
1791         // if the file doesn't exist, let the user create one
1792         if (!fs::exists(filename)) {
1793                 // the user specifically chose this name. Believe him.
1794                 Buffer * const b = newFile(filename, string(), true);
1795                 if (b)
1796                         owner->setBuffer(b);
1797                 return;
1798         }
1799
1800         owner->message(bformat(_("Opening document %1$s..."), disp_fn));
1801
1802         docstring str2;
1803         if (owner->loadLyXFile(filename)) {
1804                 str2 = bformat(_("Document %1$s opened."), disp_fn);
1805         } else {
1806                 str2 = bformat(_("Could not open document %1$s"), disp_fn);
1807         }
1808         owner->message(str2);
1809 }
1810
1811
1812 void LyXFunc::doImport(string const & argument)
1813 {
1814         string format;
1815         string filename = split(argument, format, ' ');
1816
1817         lyxerr[Debug::INFO] << "LyXFunc::doImport: " << format
1818                             << " file: " << filename << endl;
1819
1820         // need user interaction
1821         if (filename.empty()) {
1822                 string initpath = lyxrc.document_path;
1823
1824                 if (view()->buffer()) {
1825                         string const trypath = owner->buffer()->filePath();
1826                         // If directory is writeable, use this as default.
1827                         if (isDirWriteable(trypath))
1828                                 initpath = trypath;
1829                 }
1830
1831                 docstring const text = bformat(_("Select %1$s file to import"),
1832                         formats.prettyName(format));
1833
1834                 FileDialog fileDlg(lyx::to_utf8(text),
1835                         LFUN_BUFFER_IMPORT,
1836                         make_pair(string(lyx::to_utf8(_("Documents|#o#O"))),
1837                                   string(lyxrc.document_path)),
1838                         make_pair(string(lyx::to_utf8(_("Examples|#E#e"))),
1839                                   string(addPath(package().system_support(), "examples"))));
1840
1841                 string const filter = lyx::to_utf8(formats.prettyName(format))
1842                         + " (*." + formats.extension(format) + ')';
1843
1844                 FileDialog::Result result =
1845                         fileDlg.open(initpath,
1846                                      FileFilterList(filter),
1847                                      string());
1848
1849                 if (result.first == FileDialog::Later)
1850                         return;
1851
1852                 filename = result.second;
1853
1854                 // check selected filename
1855                 if (filename.empty())
1856                         owner->message(_("Canceled."));
1857         }
1858
1859         if (filename.empty())
1860                 return;
1861
1862         // get absolute path of file
1863         filename = makeAbsPath(filename);
1864
1865         string const lyxfile = changeExtension(filename, ".lyx");
1866
1867         // Check if the document already is open
1868         if (lyx_gui::use_gui && bufferlist.exists(lyxfile)) {
1869                 if (!bufferlist.close(bufferlist.getBuffer(lyxfile), true)) {
1870                         owner->message(_("Canceled."));
1871                         return;
1872                 }
1873         }
1874
1875         // if the file exists already, and we didn't do
1876         // -i lyx thefile.lyx, warn
1877         if (fs::exists(lyxfile) && filename != lyxfile) {
1878                 docstring const file = makeDisplayPath(lyxfile, 30);
1879
1880                 docstring text = bformat(_("The document %1$s already exists.\n\n"
1881                                                      "Do you want to over-write that document?"), file);
1882                 int const ret = Alert::prompt(_("Over-write document?"),
1883                         text, 0, 1, _("&Over-write"), _("&Cancel"));
1884
1885                 if (ret == 1) {
1886                         owner->message(_("Canceled."));
1887                         return;
1888                 }
1889         }
1890
1891         ErrorList errorList;
1892         Importer::Import(owner, filename, format, errorList);
1893         // FIXME (Abdel 12/08/06): Is there a need to display the error list here?
1894 }
1895
1896
1897 void LyXFunc::closeBuffer()
1898 {
1899         // save current cursor position
1900         LyX::ref().session().saveFilePosition(owner->buffer()->fileName(),
1901                 boost::tie(view()->cursor().pit(), view()->cursor().pos()) );
1902         if (bufferlist.close(owner->buffer(), true) && !quitting) {
1903                 if (bufferlist.empty()) {
1904                         // need this otherwise SEGV may occur while
1905                         // trying to set variables that don't exist
1906                         // since there's no current buffer
1907                         owner->getDialogs().hideBufferDependent();
1908                 } else {
1909                         owner->setBuffer(bufferlist.first());
1910                 }
1911         }
1912 }
1913
1914
1915 // Each "owner" should have it's own message method. lyxview and
1916 // the minibuffer would use the minibuffer, but lyxserver would
1917 // send an ERROR signal to its client.  Alejandro 970603
1918 // This function is bit problematic when it comes to NLS, to make the
1919 // lyx servers client be language indepenent we must not translate
1920 // strings sent to this func.
1921 void LyXFunc::setErrorMessage(docstring const & m) const
1922 {
1923         dispatch_buffer = m;
1924         errorstat = true;
1925 }
1926
1927
1928 void LyXFunc::setMessage(docstring const & m) const
1929 {
1930         dispatch_buffer = m;
1931 }
1932
1933
1934 string const LyXFunc::viewStatusMessage()
1935 {
1936         // When meta-fake key is pressed, show the key sequence so far + "M-".
1937         if (wasMetaKey())
1938                 return keyseq.print() + "M-";
1939
1940         // Else, when a non-complete key sequence is pressed,
1941         // show the available options.
1942         if (keyseq.length() > 0 && !keyseq.deleted())
1943                 return keyseq.printOptions();
1944
1945         if (!view()->buffer())
1946                 return lyx::to_utf8(_("Welcome to LyX!"));
1947
1948         return view()->cursor().currentState();
1949 }
1950
1951
1952 BufferView * LyXFunc::view() const
1953 {
1954         BOOST_ASSERT(owner);
1955         return owner->view();
1956 }
1957
1958
1959 bool LyXFunc::wasMetaKey() const
1960 {
1961         return (meta_fake_bit != key_modifier::none);
1962 }
1963
1964
1965 namespace {
1966
1967 void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
1968 {
1969         // Why the switch you might ask. It is a trick to ensure that all
1970         // the elements in the LyXRCTags enum is handled. As you can see
1971         // there are no breaks at all. So it is just a huge fall-through.
1972         // The nice thing is that we will get a warning from the compiler
1973         // if we forget an element.
1974         LyXRC::LyXRCTags tag = LyXRC::RC_LAST;
1975         switch (tag) {
1976         case LyXRC::RC_ACCEPT_COMPOUND:
1977         case LyXRC::RC_ALT_LANG:
1978         case LyXRC::RC_ASCIIROFF_COMMAND:
1979         case LyXRC::RC_ASCII_LINELEN:
1980         case LyXRC::RC_AUTOREGIONDELETE:
1981         case LyXRC::RC_AUTORESET_OPTIONS:
1982         case LyXRC::RC_AUTOSAVE:
1983         case LyXRC::RC_AUTO_NUMBER:
1984         case LyXRC::RC_BACKUPDIR_PATH:
1985         case LyXRC::RC_BIBTEX_COMMAND:
1986         case LyXRC::RC_BINDFILE:
1987         case LyXRC::RC_CHECKLASTFILES:
1988         case LyXRC::RC_USELASTFILEPOS:
1989         case LyXRC::RC_LOADSESSION:
1990         case LyXRC::RC_CHKTEX_COMMAND:
1991         case LyXRC::RC_CONVERTER:
1992         case LyXRC::RC_COPIER:
1993         case LyXRC::RC_CURSOR_FOLLOWS_SCROLLBAR:
1994         case LyXRC::RC_CUSTOM_EXPORT_COMMAND:
1995         case LyXRC::RC_CUSTOM_EXPORT_FORMAT:
1996         case LyXRC::RC_DATE_INSERT_FORMAT:
1997         case LyXRC::RC_DEFAULT_LANGUAGE:
1998         case LyXRC::RC_DEFAULT_PAPERSIZE:
1999         case LyXRC::RC_DIALOGS_ICONIFY_WITH_MAIN:
2000         case LyXRC::RC_DISPLAY_GRAPHICS:
2001         case LyXRC::RC_DOCUMENTPATH:
2002                 if (lyxrc_orig.document_path != lyxrc_new.document_path) {
2003                         if (fs::exists(lyxrc_new.document_path) &&
2004                             fs::is_directory(lyxrc_new.document_path)) {
2005                                 using lyx::support::package;
2006                                 package().document_dir() = lyxrc.document_path;
2007                         }
2008                 }
2009         case LyXRC::RC_ESC_CHARS:
2010         case LyXRC::RC_FONT_ENCODING:
2011         case LyXRC::RC_FORMAT:
2012         case LyXRC::RC_INDEX_COMMAND:
2013         case LyXRC::RC_INPUT:
2014         case LyXRC::RC_KBMAP:
2015         case LyXRC::RC_KBMAP_PRIMARY:
2016         case LyXRC::RC_KBMAP_SECONDARY:
2017         case LyXRC::RC_LABEL_INIT_LENGTH:
2018         case LyXRC::RC_LANGUAGE_AUTO_BEGIN:
2019         case LyXRC::RC_LANGUAGE_AUTO_END:
2020         case LyXRC::RC_LANGUAGE_COMMAND_BEGIN:
2021         case LyXRC::RC_LANGUAGE_COMMAND_END:
2022         case LyXRC::RC_LANGUAGE_COMMAND_LOCAL:
2023         case LyXRC::RC_LANGUAGE_GLOBAL_OPTIONS:
2024         case LyXRC::RC_LANGUAGE_PACKAGE:
2025         case LyXRC::RC_LANGUAGE_USE_BABEL:
2026         case LyXRC::RC_MAKE_BACKUP:
2027         case LyXRC::RC_MARK_FOREIGN_LANGUAGE:
2028         case LyXRC::RC_NUMLASTFILES:
2029         case LyXRC::RC_PATH_PREFIX:
2030                 if (lyxrc_orig.path_prefix != lyxrc_new.path_prefix) {
2031                         using lyx::support::prependEnvPath;
2032                         prependEnvPath("PATH", lyxrc.path_prefix);
2033                 }
2034         case LyXRC::RC_PERS_DICT:
2035         case LyXRC::RC_POPUP_BOLD_FONT:
2036         case LyXRC::RC_POPUP_FONT_ENCODING:
2037         case LyXRC::RC_POPUP_NORMAL_FONT:
2038         case LyXRC::RC_PREVIEW:
2039         case LyXRC::RC_PREVIEW_HASHED_LABELS:
2040         case LyXRC::RC_PREVIEW_SCALE_FACTOR:
2041         case LyXRC::RC_PRINTCOLLCOPIESFLAG:
2042         case LyXRC::RC_PRINTCOPIESFLAG:
2043         case LyXRC::RC_PRINTER:
2044         case LyXRC::RC_PRINTEVENPAGEFLAG:
2045         case LyXRC::RC_PRINTEXSTRAOPTIONS:
2046         case LyXRC::RC_PRINTFILEEXTENSION:
2047         case LyXRC::RC_PRINTLANDSCAPEFLAG:
2048         case LyXRC::RC_PRINTODDPAGEFLAG:
2049         case LyXRC::RC_PRINTPAGERANGEFLAG:
2050         case LyXRC::RC_PRINTPAPERDIMENSIONFLAG:
2051         case LyXRC::RC_PRINTPAPERFLAG:
2052         case LyXRC::RC_PRINTREVERSEFLAG:
2053         case LyXRC::RC_PRINTSPOOL_COMMAND:
2054         case LyXRC::RC_PRINTSPOOL_PRINTERPREFIX:
2055         case LyXRC::RC_PRINTTOFILE:
2056         case LyXRC::RC_PRINTTOPRINTER:
2057         case LyXRC::RC_PRINT_ADAPTOUTPUT:
2058         case LyXRC::RC_PRINT_COMMAND:
2059         case LyXRC::RC_RTL_SUPPORT:
2060         case LyXRC::RC_SCREEN_DPI:
2061         case LyXRC::RC_SCREEN_FONT_ENCODING:
2062         case LyXRC::RC_SCREEN_FONT_ROMAN:
2063         case LyXRC::RC_SCREEN_FONT_ROMAN_FOUNDRY:
2064         case LyXRC::RC_SCREEN_FONT_SANS:
2065         case LyXRC::RC_SCREEN_FONT_SANS_FOUNDRY:
2066         case LyXRC::RC_SCREEN_FONT_SCALABLE:
2067         case LyXRC::RC_SCREEN_FONT_SIZES:
2068         case LyXRC::RC_SCREEN_FONT_TYPEWRITER:
2069         case LyXRC::RC_SCREEN_FONT_TYPEWRITER_FOUNDRY:
2070         case LyXRC::RC_SCREEN_GEOMETRY_HEIGHT:
2071         case LyXRC::RC_SCREEN_GEOMETRY_WIDTH:
2072         case LyXRC::RC_SCREEN_GEOMETRY_XYSAVED:
2073         case LyXRC::RC_SCREEN_ZOOM:
2074         case LyXRC::RC_SERVERPIPE:
2075         case LyXRC::RC_SET_COLOR:
2076         case LyXRC::RC_SHOW_BANNER:
2077         case LyXRC::RC_SPELL_COMMAND:
2078         case LyXRC::RC_TEMPDIRPATH:
2079         case LyXRC::RC_TEMPLATEPATH:
2080         case LyXRC::RC_TEX_ALLOWS_SPACES:
2081         case LyXRC::RC_TEX_EXPECTS_WINDOWS_PATHS:
2082                 if (lyxrc_orig.windows_style_tex_paths != lyxrc_new.windows_style_tex_paths) {
2083                         namespace os = lyx::support::os;
2084                         os::windows_style_tex_paths(lyxrc_new.windows_style_tex_paths);
2085                 }
2086         case LyXRC::RC_UIFILE:
2087         case LyXRC::RC_USER_EMAIL:
2088         case LyXRC::RC_USER_NAME:
2089         case LyXRC::RC_USETEMPDIR:
2090         case LyXRC::RC_USE_ALT_LANG:
2091         case LyXRC::RC_USE_ESC_CHARS:
2092         case LyXRC::RC_USE_INP_ENC:
2093         case LyXRC::RC_USE_PERS_DICT:
2094         case LyXRC::RC_USE_SPELL_LIB:
2095         case LyXRC::RC_VIEWDVI_PAPEROPTION:
2096         case LyXRC::RC_VIEWER:
2097         case LyXRC::RC_LAST:
2098                 break;
2099         }
2100 }
2101
2102 } // namespace anon