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