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