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