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