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