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