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