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