3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Alfredo Braunstein
7 * \author Lars Gullik Bjønnes
8 * \author Jean-Marc Lasgouttes
9 * \author Angus Leeming
11 * \author André Pönitz
14 * \author Martin Vermeer
15 * \author Jürgen Vigna
17 * Full author contact details are available in file CREDITS.
24 #include "LayoutFile.h"
25 #include "BranchList.h"
26 #include "buffer_funcs.h"
28 #include "BufferList.h"
29 #include "BufferParams.h"
30 #include "BufferView.h"
33 #include "Converter.h"
35 #include "CutAndPaste.h"
36 #include "DispatchResult.h"
38 #include "ErrorList.h"
40 #include "FuncRequest.h"
41 #include "FuncStatus.h"
42 #include "InsetIterator.h"
47 #include "LyXAction.h"
52 #include "Paragraph.h"
53 #include "ParagraphParameters.h"
54 #include "ParIterator.h"
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/InsetGraphics.h"
66 #include "insets/InsetInclude.h"
67 #include "insets/InsetListings.h"
68 #include "insets/InsetNote.h"
69 #include "insets/InsetSpace.h"
70 #include "insets/InsetTabular.h"
71 #include "insets/InsetVSpace.h"
72 #include "insets/InsetWrap.h"
74 #include "frontends/alert.h"
75 #include "frontends/Application.h"
76 #include "frontends/KeySymbol.h"
77 #include "frontends/LyXView.h"
78 #include "frontends/Selection.h"
80 #include "support/debug.h"
81 #include "support/environment.h"
82 #include "support/FileName.h"
83 #include "support/filetools.h"
84 #include "support/gettext.h"
85 #include "support/lstrings.h"
86 #include "support/Path.h"
87 #include "support/Package.h"
88 #include "support/Systemcall.h"
89 #include "support/convert.h"
90 #include "support/os.h"
96 using namespace lyx::support;
100 using frontend::LyXView;
102 namespace Alert = frontend::Alert;
107 // This function runs "configure" and then rereads lyx.defaults to
108 // reconfigure the automatic settings.
109 void reconfigure(LyXView * lv, string const & option)
111 // emit message signal.
113 lv->message(_("Running configure..."));
115 // Run configure in user lyx directory
116 PathChanger p(package().user_support());
117 string configure_command = package().configure_command();
118 configure_command += option;
120 int ret = one.startscript(Systemcall::Wait, configure_command);
122 // emit message signal.
124 lv->message(_("Reloading configuration..."));
125 lyxrc.read(libFileSearch(string(), "lyxrc.defaults"));
126 // Re-read packages.lst
127 LaTeXFeatures::getAvailable();
130 Alert::information(_("System reconfiguration failed"),
131 _("The system reconfiguration has failed.\n"
132 "Default textclass is used but LyX may "
133 "not be able to work properly.\n"
134 "Please reconfigure again if needed."));
137 Alert::information(_("System reconfigured"),
138 _("The system has been reconfigured.\n"
139 "You need to restart LyX to make use of any\n"
140 "updated document class specifications."));
144 bool getLocalStatus(Cursor cursor, FuncRequest const & cmd, FuncStatus & status)
146 // Try to fix cursor in case it is broken.
147 cursor.fixIfBroken();
149 // This is, of course, a mess. Better create a new doc iterator and use
150 // this in Inset::getStatus. This might require an additional
151 // BufferView * arg, though (which should be avoided)
152 //Cursor safe = *this;
154 for ( ; cursor.depth(); cursor.pop()) {
155 //lyxerr << "\nCursor::getStatus: cmd: " << cmd << endl << *this << endl;
156 LASSERT(cursor.idx() <= cursor.lastidx(), /**/);
157 LASSERT(cursor.pit() <= cursor.lastpit(), /**/);
158 LASSERT(cursor.pos() <= cursor.lastpos(), /**/);
160 // The inset's getStatus() will return 'true' if it made
161 // a definitive decision on whether it want to handle the
162 // request or not. The result of this decision is put into
163 // the 'status' parameter.
164 if (cursor.inset().getStatus(cursor, cmd, status)) {
173 /** Return the change status at cursor position, taking in account the
174 * status at each level of the document iterator (a table in a deleted
175 * footnote is deleted).
176 * When \param outer is true, the top slice is not looked at.
178 Change::Type lookupChangeType(DocIterator const & dit, bool outer = false)
180 size_t const depth = dit.depth() - (outer ? 1 : 0);
182 for (size_t i = 0 ; i < depth ; ++i) {
183 CursorSlice const & slice = dit[i];
184 if (!slice.inset().inMathed()
185 && slice.pos() < slice.paragraph().size()) {
186 Change::Type const ch = slice.paragraph().lookupChange(slice.pos()).type;
187 if (ch != Change::UNCHANGED)
191 return Change::UNCHANGED;
198 : lyx_view_(0), encoded_last_key(0), meta_fake_bit(NoModifier)
203 void LyXFunc::initKeySequences(KeyMap * kb)
205 keyseq = KeySequence(kb, kb);
206 cancel_meta_seq = KeySequence(kb, kb);
210 void LyXFunc::setLyXView(LyXView * lv)
212 if (lyx_view_ && lyx_view_->view() && lyx_view_ != lv)
213 // save current selection to the selection buffer to allow
214 // middle-button paste in another window
215 cap::saveSelection(lyx_view_->view()->cursor());
220 void LyXFunc::handleKeyFunc(FuncCode action)
222 char_type c = encoded_last_key;
227 LASSERT(lyx_view_ && lyx_view_->view(), /**/);
228 lyx_view_->view()->getIntl().getTransManager().deadkey(
229 c, get_accent(action).accent, view()->cursor().innerText(), view()->cursor());
230 // Need to clear, in case the minibuffer calls these
233 // copied verbatim from do_accent_char
234 view()->cursor().resetAnchor();
235 view()->processUpdateFlags(Update::FitCursor);
238 //FIXME: bookmark handling is a frontend issue. This code should be transferred
239 // to GuiView and be GuiView and be window dependent.
240 void LyXFunc::gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer)
242 LASSERT(lyx_view_, /**/);
243 if (!theSession().bookmarks().isValid(idx))
245 BookmarksSection::Bookmark const & bm = theSession().bookmarks().bookmark(idx);
246 LASSERT(!bm.filename.empty(), /**/);
247 string const file = bm.filename.absFilename();
248 // if the file is not opened, open it.
249 if (!theBufferList().exists(bm.filename)) {
251 dispatch(FuncRequest(LFUN_FILE_OPEN, file));
255 // open may fail, so we need to test it again
256 if (!theBufferList().exists(bm.filename))
259 // if the current buffer is not that one, switch to it.
260 if (lyx_view_->buffer()->fileName() != bm.filename) {
263 dispatch(FuncRequest(LFUN_BUFFER_SWITCH, file));
265 // moveToPosition try paragraph id first and then paragraph (pit, pos).
266 if (!view()->moveToPosition(bm.bottom_pit, bm.bottom_pos,
267 bm.top_id, bm.top_pos))
270 // Cursor jump succeeded!
271 Cursor const & cur = view()->cursor();
272 pit_type new_pit = cur.pit();
273 pos_type new_pos = cur.pos();
274 int new_id = cur.paragraph().id();
276 // if bottom_pit, bottom_pos or top_id has been changed, update bookmark
277 // see http://bugzilla.lyx.org/show_bug.cgi?id=3092
278 if (bm.bottom_pit != new_pit || bm.bottom_pos != new_pos
279 || bm.top_id != new_id) {
280 const_cast<BookmarksSection::Bookmark &>(bm).updatePos(
281 new_pit, new_pos, new_id);
286 void LyXFunc::processKeySym(KeySymbol const & keysym, KeyModifier state)
288 LYXERR(Debug::KEY, "KeySym is " << keysym.getSymbolName());
290 // Do nothing if we have nothing (JMarc)
291 if (!keysym.isOK()) {
292 LYXERR(Debug::KEY, "Empty kbd action (probably composing)");
293 lyx_view_->restartCursor();
297 if (keysym.isModifier()) {
298 LYXERR(Debug::KEY, "isModifier true");
300 lyx_view_->restartCursor();
304 //Encoding const * encoding = view()->cursor().getEncoding();
305 //encoded_last_key = keysym.getISOEncoded(encoding ? encoding->name() : "");
306 // FIXME: encoded_last_key shadows the member variable of the same
307 // name. Is that intended?
308 char_type encoded_last_key = keysym.getUCSEncoded();
310 // Do a one-deep top-level lookup for
311 // cancel and meta-fake keys. RVDK_PATCH_5
312 cancel_meta_seq.reset();
314 FuncRequest func = cancel_meta_seq.addkey(keysym, state);
315 LYXERR(Debug::KEY, "action first set to [" << func.action << ']');
317 // When not cancel or meta-fake, do the normal lookup.
318 // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
319 // Mostly, meta_fake_bit = NoModifier. RVDK_PATCH_5.
320 if ((func.action != LFUN_CANCEL) && (func.action != LFUN_META_PREFIX)) {
321 // remove Caps Lock and Mod2 as a modifiers
322 func = keyseq.addkey(keysym, (state | meta_fake_bit));
323 LYXERR(Debug::KEY, "action now set to [" << func.action << ']');
326 // Dont remove this unless you know what you are doing.
327 meta_fake_bit = NoModifier;
329 // Can this happen now ?
330 if (func.action == LFUN_NOACTION)
331 func = FuncRequest(LFUN_COMMAND_PREFIX);
333 LYXERR(Debug::KEY, " Key [action=" << func.action << "]["
334 << keyseq.print(KeySequence::Portable) << ']');
336 // already here we know if it any point in going further
337 // why not return already here if action == -1 and
338 // num_bytes == 0? (Lgb)
340 if (keyseq.length() > 1)
341 lyx_view_->message(keyseq.print(KeySequence::ForGui));
344 // Maybe user can only reach the key via holding down shift.
345 // Let's see. But only if shift is the only modifier
346 if (func.action == LFUN_UNKNOWN_ACTION && state == ShiftModifier) {
347 LYXERR(Debug::KEY, "Trying without shift");
348 func = keyseq.addkey(keysym, NoModifier);
349 LYXERR(Debug::KEY, "Action now " << func.action);
352 if (func.action == LFUN_UNKNOWN_ACTION) {
353 // Hmm, we didn't match any of the keysequences. See
354 // if it's normal insertable text not already covered
356 if (keysym.isText() && keyseq.length() == 1) {
357 LYXERR(Debug::KEY, "isText() is true, inserting.");
358 func = FuncRequest(LFUN_SELF_INSERT,
359 FuncRequest::KEYBOARD);
361 LYXERR(Debug::KEY, "Unknown, !isText() - giving up");
362 lyx_view_->message(_("Unknown function."));
363 lyx_view_->restartCursor();
368 if (func.action == LFUN_SELF_INSERT) {
369 if (encoded_last_key != 0) {
370 docstring const arg(1, encoded_last_key);
371 dispatch(FuncRequest(LFUN_SELF_INSERT, arg,
372 FuncRequest::KEYBOARD));
373 LYXERR(Debug::KEY, "SelfInsert arg[`" << to_utf8(arg) << "']");
383 FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
385 //lyxerr << "LyXFunc::getStatus: cmd: " << cmd << endl;
388 Buffer * buf = lyx_view_ ? lyx_view_->buffer() : 0;
390 if (cmd.action == LFUN_NOACTION) {
391 flag.message(from_utf8(N_("Nothing to do")));
392 flag.setEnabled(false);
396 switch (cmd.action) {
397 case LFUN_UNKNOWN_ACTION:
398 #ifndef HAVE_LIBAIKSAURUS
399 case LFUN_THESAURUS_ENTRY:
402 flag.setEnabled(false);
409 if (flag.unknown()) {
410 flag.message(from_utf8(N_("Unknown action")));
414 if (!flag.enabled()) {
415 if (flag.message().empty())
416 flag.message(from_utf8(N_("Command disabled")));
420 // Check whether we need a buffer
421 if (!lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer) && !buf) {
423 flag.message(from_utf8(N_("Command not allowed with"
424 "out any document open")));
425 flag.setEnabled(false);
429 // I would really like to avoid having this switch and rather try to
430 // encode this in the function itself.
431 // -- And I'd rather let an inset decide which LFUNs it is willing
432 // to handle (Andre')
434 switch (cmd.action) {
436 case LFUN_BUFFER_TOGGLE_READ_ONLY:
437 flag.setOnOff(buf->isReadonly());
440 case LFUN_BUFFER_SWITCH:
441 // toggle on the current buffer, but do not toggle off
442 // the other ones (is that a good idea?)
443 if (buf && to_utf8(cmd.argument()) == buf->absFileName())
447 case LFUN_BUFFER_EXPORT:
448 enable = cmd.argument() == "custom"
449 || buf->isExportable(to_utf8(cmd.argument()));
452 case LFUN_BUFFER_CHKTEX:
453 enable = buf->isLatex() && !lyxrc.chktex_command.empty();
456 case LFUN_BUILD_PROGRAM:
457 enable = buf->isExportable("program");
460 case LFUN_VC_REGISTER:
461 enable = !buf->lyxvc().inUse() && !buf->isUnnamed();
463 case LFUN_VC_CHECK_IN:
464 enable = buf->lyxvc().checkInEnabled();
466 case LFUN_VC_CHECK_OUT:
467 enable = buf->lyxvc().checkOutEnabled();
470 enable = buf->lyxvc().inUse();
472 case LFUN_VC_UNDO_LAST:
473 enable = buf->lyxvc().undoLastEnabled();
475 case LFUN_BUFFER_RELOAD:
476 enable = !buf->isUnnamed() && buf->fileName().exists()
477 && (!buf->isClean() || buf->isExternallyModified(Buffer::timestamp_method));
480 case LFUN_CITATION_INSERT: {
481 FuncRequest fr(LFUN_INSET_INSERT, "citation");
482 enable = getStatus(fr).enabled();
486 // This could be used for the no-GUI version. The GUI version is handled in
487 // LyXView::getStatus(). See above.
489 case LFUN_BUFFER_WRITE:
490 case LFUN_BUFFER_WRITE_AS: {
491 Buffer * b = theBufferList().getBuffer(FileName(cmd.getArg(0)));
492 enable = b && (b->isUnnamed() || !b->isClean());
497 case LFUN_BUFFER_WRITE_ALL: {
498 // We enable the command only if there are some modified buffers
499 Buffer * first = theBufferList().first();
504 // We cannot use a for loop as the buffer list is a cycle.
510 b = theBufferList().next(b);
511 } while (b != first);
515 case LFUN_BOOKMARK_GOTO: {
516 const unsigned int num = convert<unsigned int>(to_utf8(cmd.argument()));
517 enable = theSession().bookmarks().isValid(num);
521 case LFUN_BOOKMARK_CLEAR:
522 enable = theSession().bookmarks().size() > 0;
525 // this one is difficult to get right. As a half-baked
526 // solution, we consider only the first action of the sequence
527 case LFUN_COMMAND_SEQUENCE: {
528 // argument contains ';'-terminated commands
529 string const firstcmd = token(to_utf8(cmd.argument()), ';', 0);
530 FuncRequest func(lyxaction.lookupFunc(firstcmd));
531 func.origin = cmd.origin;
532 flag = getStatus(func);
536 // we want to check if at least one of these is enabled
537 case LFUN_COMMAND_ALTERNATIVES: {
538 // argument contains ';'-terminated commands
539 string arg = to_utf8(cmd.argument());
540 while (!arg.empty()) {
542 arg = split(arg, first, ';');
543 FuncRequest func(lyxaction.lookupFunc(first));
544 func.origin = cmd.origin;
545 flag = getStatus(func);
546 // if this one is enabled, the whole thing is
555 string name = to_utf8(cmd.argument());
556 if (theTopLevelCmdDef().lock(name, func)) {
557 func.origin = cmd.origin;
558 flag = getStatus(func);
559 theTopLevelCmdDef().release(name);
561 // catch recursion or unknown command definiton
562 // all operations until the recursion or unknown command
563 // definiton occures are performed, so set the state to enabled
569 case LFUN_WORD_FIND_FORWARD:
570 case LFUN_WORD_FIND_BACKWARD:
571 case LFUN_COMMAND_PREFIX:
572 case LFUN_COMMAND_EXECUTE:
574 case LFUN_META_PREFIX:
575 case LFUN_BUFFER_CLOSE:
576 case LFUN_BUFFER_UPDATE:
577 case LFUN_BUFFER_VIEW:
578 case LFUN_MASTER_BUFFER_UPDATE:
579 case LFUN_MASTER_BUFFER_VIEW:
580 case LFUN_BUFFER_IMPORT:
581 case LFUN_BUFFER_AUTO_SAVE:
582 case LFUN_RECONFIGURE:
584 case LFUN_DROP_LAYOUTS_CHOICE:
586 case LFUN_SERVER_GET_FILENAME:
587 case LFUN_SERVER_NOTIFY:
588 case LFUN_SERVER_GOTO_FILE_ROW:
589 case LFUN_DIALOG_HIDE:
590 case LFUN_DIALOG_DISCONNECT_INSET:
591 case LFUN_BUFFER_CHILD_OPEN:
592 case LFUN_CURSOR_FOLLOWS_SCROLLBAR_TOGGLE:
593 case LFUN_KEYMAP_OFF:
594 case LFUN_KEYMAP_PRIMARY:
595 case LFUN_KEYMAP_SECONDARY:
596 case LFUN_KEYMAP_TOGGLE:
598 case LFUN_BUFFER_EXPORT_CUSTOM:
599 case LFUN_BUFFER_PRINT:
600 case LFUN_PREFERENCES_SAVE:
602 case LFUN_INSET_EDIT:
603 case LFUN_BUFFER_LANGUAGE:
604 case LFUN_TEXTCLASS_APPLY:
605 case LFUN_TEXTCLASS_LOAD:
606 case LFUN_BUFFER_SAVE_AS_DEFAULT:
607 case LFUN_BUFFER_PARAMS_APPLY:
608 case LFUN_LAYOUT_MODULES_CLEAR:
609 case LFUN_LAYOUT_MODULE_ADD:
610 case LFUN_LAYOUT_RELOAD:
611 case LFUN_LYXRC_APPLY:
612 case LFUN_BUFFER_NEXT:
613 case LFUN_BUFFER_PREVIOUS:
614 // these are handled in our dispatch()
622 if (theApp()->getStatus(cmd, flag))
625 // Does the view know something?
630 if (lyx_view_->getStatus(cmd, flag))
633 // If we have a BufferView, try cursor position and
634 // then the BufferView.
639 if (!getLocalStatus(view()->cursor(), cmd, flag))
640 flag = view()->getStatus(cmd);
644 flag.setEnabled(false);
646 // Can we use a readonly buffer?
647 if (buf && buf->isReadonly()
648 && !lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly)
649 && !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)) {
650 flag.message(from_utf8(N_("Document is read-only")));
651 flag.setEnabled(false);
654 // Are we in a DELETED change-tracking region?
656 && lookupChangeType(view()->cursor(), true) == Change::DELETED
657 && !lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly)
658 && !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)) {
659 flag.message(from_utf8(N_("This portion of the document is deleted.")));
660 flag.setEnabled(false);
663 // the default error message if we disable the command
664 if (!flag.enabled() && flag.message().empty())
665 flag.message(from_utf8(N_("Command disabled")));
671 bool LyXFunc::ensureBufferClean(BufferView * bv)
673 Buffer & buf = bv->buffer();
677 docstring const file = buf.fileName().displayName(30);
678 docstring text = bformat(_("The document %1$s has unsaved "
679 "changes.\n\nDo you want to save "
680 "the document?"), file);
681 int const ret = Alert::prompt(_("Save changed document?"),
682 text, 0, 1, _("&Save"),
686 dispatch(FuncRequest(LFUN_BUFFER_WRITE));
688 return buf.isClean();
694 void showPrintError(string const & name)
696 docstring str = bformat(_("Could not print the document %1$s.\n"
697 "Check that your printer is set up correctly."),
698 makeDisplayPath(name, 50));
699 Alert::error(_("Print document failed"), str);
703 bool loadLayoutFile(string const & name, string const & buf_path)
705 if (!LayoutFileList::get().haveClass(name)) {
706 lyxerr << "Document class \"" << name
707 << "\" does not exist."
712 LayoutFile & tc = LayoutFileList::get()[name];
713 if (!tc.load(buf_path)) {
714 docstring s = bformat(_("The document class %1$s "
715 "could not be loaded."), from_utf8(name));
716 Alert::error(_("Could not load class"), s);
723 void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new);
728 void LyXFunc::dispatch(FuncRequest const & cmd)
730 string const argument = to_utf8(cmd.argument());
731 FuncCode const action = cmd.action;
733 LYXERR(Debug::ACTION, "\nLyXFunc::dispatch: cmd: " << cmd);
734 //lyxerr << "LyXFunc::dispatch: cmd: " << cmd << endl;
736 // we have not done anything wrong yet.
738 dispatch_buffer.erase();
740 // redraw the screen at the end (first of the two drawing steps).
741 //This is done unless explicitely requested otherwise
742 Update::flags updateFlags = Update::FitCursor;
744 FuncStatus const flag = getStatus(cmd);
745 if (!flag.enabled()) {
746 // We cannot use this function here
747 LYXERR(Debug::ACTION, "LyXFunc::dispatch: "
748 << lyxaction.getActionName(action)
749 << " [" << action << "] is disabled at this location");
750 setErrorMessage(flag.message());
752 lyx_view_->restartCursor();
756 case LFUN_WORD_FIND_FORWARD:
757 case LFUN_WORD_FIND_BACKWARD: {
758 LASSERT(lyx_view_ && lyx_view_->view(), /**/);
759 static docstring last_search;
760 docstring searched_string;
762 if (!cmd.argument().empty()) {
763 last_search = cmd.argument();
764 searched_string = cmd.argument();
766 searched_string = last_search;
769 if (searched_string.empty())
772 bool const fw = action == LFUN_WORD_FIND_FORWARD;
773 docstring const data =
774 find2string(searched_string, true, false, fw);
775 find(view(), FuncRequest(LFUN_WORD_FIND, data));
779 case LFUN_COMMAND_PREFIX:
780 LASSERT(lyx_view_, /**/);
781 lyx_view_->message(keyseq.printOptions(true));
785 LASSERT(lyx_view_ && lyx_view_->view(), /**/);
787 meta_fake_bit = NoModifier;
788 if (lyx_view_->buffer())
789 // cancel any selection
790 dispatch(FuncRequest(LFUN_MARK_OFF));
791 setMessage(from_ascii(N_("Cancel")));
794 case LFUN_META_PREFIX:
795 meta_fake_bit = AltModifier;
796 setMessage(keyseq.print(KeySequence::ForGui));
799 case LFUN_BUFFER_TOGGLE_READ_ONLY: {
800 LASSERT(lyx_view_ && lyx_view_->view() && lyx_view_->buffer(), /**/);
801 Buffer * buf = lyx_view_->buffer();
802 if (buf->lyxvc().inUse())
803 buf->lyxvc().toggleReadOnly();
805 buf->setReadonly(!lyx_view_->buffer()->isReadonly());
809 // --- Menus -----------------------------------------------
810 case LFUN_BUFFER_CLOSE:
811 lyx_view_->closeBuffer();
812 updateFlags = Update::None;
815 case LFUN_BUFFER_RELOAD: {
816 LASSERT(lyx_view_ && lyx_view_->buffer(), /**/);
817 docstring const file = makeDisplayPath(lyx_view_->buffer()->absFileName(), 20);
818 docstring text = bformat(_("Any changes will be lost. Are you sure "
819 "you want to revert to the saved version of the document %1$s?"), file);
820 int const ret = Alert::prompt(_("Revert to saved document?"),
821 text, 1, 1, _("&Revert"), _("&Cancel"));
828 case LFUN_BUFFER_UPDATE:
829 LASSERT(lyx_view_ && lyx_view_->buffer(), /**/);
830 lyx_view_->buffer()->doExport(argument, true);
833 case LFUN_BUFFER_VIEW:
834 LASSERT(lyx_view_ && lyx_view_->buffer(), /**/);
835 lyx_view_->buffer()->preview(argument);
838 case LFUN_MASTER_BUFFER_UPDATE:
839 LASSERT(lyx_view_ && lyx_view_->buffer() && lyx_view_->buffer()->masterBuffer(), /**/);
840 lyx_view_->buffer()->masterBuffer()->doExport(argument, true);
843 case LFUN_MASTER_BUFFER_VIEW:
844 LASSERT(lyx_view_ && lyx_view_->buffer() && lyx_view_->buffer()->masterBuffer(), /**/);
845 lyx_view_->buffer()->masterBuffer()->preview(argument);
848 case LFUN_BUILD_PROGRAM:
849 LASSERT(lyx_view_ && lyx_view_->buffer(), /**/);
850 lyx_view_->buffer()->doExport("program", true);
853 case LFUN_BUFFER_CHKTEX:
854 LASSERT(lyx_view_ && lyx_view_->buffer(), /**/);
855 lyx_view_->buffer()->runChktex();
858 case LFUN_BUFFER_EXPORT:
859 LASSERT(lyx_view_ && lyx_view_->buffer(), /**/);
860 if (argument == "custom")
861 dispatch(FuncRequest(LFUN_DIALOG_SHOW, "sendto"));
863 lyx_view_->buffer()->doExport(argument, false);
866 case LFUN_BUFFER_EXPORT_CUSTOM: {
867 LASSERT(lyx_view_ && lyx_view_->buffer(), /**/);
869 string command = split(argument, format_name, ' ');
870 Format const * format = formats.getFormat(format_name);
872 lyxerr << "Format \"" << format_name
873 << "\" not recognized!"
878 Buffer * buffer = lyx_view_->buffer();
880 // The name of the file created by the conversion process
883 // Output to filename
884 if (format->name() == "lyx") {
885 string const latexname = buffer->latexName(false);
886 filename = changeExtension(latexname,
887 format->extension());
888 filename = addName(buffer->temppath(), filename);
890 if (!buffer->writeFile(FileName(filename)))
894 buffer->doExport(format_name, true, filename);
897 // Substitute $$FName for filename
898 if (!contains(command, "$$FName"))
899 command = "( " + command + " ) < $$FName";
900 command = subst(command, "$$FName", filename);
902 // Execute the command in the background
904 call.startscript(Systemcall::DontWait, command);
908 case LFUN_BUFFER_PRINT: {
909 LASSERT(lyx_view_ && lyx_view_->buffer(), /**/);
910 // FIXME: cmd.getArg() might fail if one of the arguments
911 // contains double quotes
912 string target = cmd.getArg(0);
913 string target_name = cmd.getArg(1);
914 string command = cmd.getArg(2);
917 || target_name.empty()
918 || command.empty()) {
919 lyxerr << "Unable to parse \""
920 << argument << '"' << endl;
923 if (target != "printer" && target != "file") {
924 lyxerr << "Unrecognized target \""
925 << target << '"' << endl;
929 Buffer * buffer = lyx_view_->buffer();
931 if (!buffer->doExport("dvi", true)) {
932 showPrintError(buffer->absFileName());
936 // Push directory path.
937 string const path = buffer->temppath();
938 // Prevent the compiler from optimizing away p
942 // there are three cases here:
943 // 1. we print to a file
944 // 2. we print directly to a printer
945 // 3. we print using a spool command (print to file first)
948 string const dviname =
949 changeExtension(buffer->latexName(true), "dvi");
951 if (target == "printer") {
952 if (!lyxrc.print_spool_command.empty()) {
953 // case 3: print using a spool
954 string const psname =
955 changeExtension(dviname,".ps");
956 command += ' ' + lyxrc.print_to_file
959 + quoteName(dviname);
962 lyxrc.print_spool_command + ' ';
963 if (target_name != "default") {
964 command2 += lyxrc.print_spool_printerprefix
968 command2 += quoteName(psname);
970 // If successful, then spool command
971 res = one.startscript(
976 res = one.startscript(
977 Systemcall::DontWait,
980 // case 2: print directly to a printer
981 if (target_name != "default")
982 command += ' ' + lyxrc.print_to_printer + target_name + ' ';
983 res = one.startscript(
984 Systemcall::DontWait,
985 command + quoteName(dviname));
989 // case 1: print to a file
990 FileName const filename(makeAbsPath(target_name,
991 lyx_view_->buffer()->filePath()));
992 FileName const dvifile(makeAbsPath(dviname, path));
993 if (filename.exists()) {
994 docstring text = bformat(
995 _("The file %1$s already exists.\n\n"
996 "Do you want to overwrite that file?"),
997 makeDisplayPath(filename.absFilename()));
998 if (Alert::prompt(_("Overwrite file?"),
999 text, 0, 1, _("&Overwrite"), _("&Cancel")) != 0)
1002 command += ' ' + lyxrc.print_to_file
1003 + quoteName(filename.toFilesystemEncoding())
1005 + quoteName(dvifile.toFilesystemEncoding());
1006 res = one.startscript(Systemcall::DontWait,
1011 showPrintError(buffer->absFileName());
1015 // FIXME: There is need for a command-line import.
1017 case LFUN_BUFFER_IMPORT:
1022 case LFUN_BUFFER_AUTO_SAVE:
1023 lyx_view_->buffer()->autoSave();
1026 case LFUN_RECONFIGURE:
1027 // argument is any additional parameter to the configure.py command
1028 reconfigure(lyx_view_, argument);
1031 case LFUN_HELP_OPEN: {
1033 theApp()->dispatch(FuncRequest(LFUN_WINDOW_NEW));
1034 string const arg = argument;
1036 setErrorMessage(from_ascii(N_("Missing argument")));
1039 FileName const fname = i18nLibFileSearch("doc", arg, "lyx");
1040 if (fname.empty()) {
1041 lyxerr << "LyX: unable to find documentation file `"
1042 << arg << "'. Bad installation?" << endl;
1045 lyx_view_->message(bformat(_("Opening help file %1$s..."),
1046 makeDisplayPath(fname.absFilename())));
1047 Buffer * buf = lyx_view_->loadDocument(fname, false);
1050 lyx_view_->setBuffer(buf);
1051 buf->errors("Parse");
1053 updateFlags = Update::None;
1057 // --- version control -------------------------------
1058 case LFUN_VC_REGISTER:
1059 LASSERT(lyx_view_ && lyx_view_->buffer(), /**/);
1060 if (!ensureBufferClean(view()) || lyx_view_->buffer()->isUnnamed())
1062 if (!lyx_view_->buffer()->lyxvc().inUse()) {
1063 lyx_view_->buffer()->lyxvc().registrer();
1066 updateFlags = Update::Force;
1069 case LFUN_VC_CHECK_IN:
1070 LASSERT(lyx_view_ && lyx_view_->buffer(), /**/);
1071 if (!ensureBufferClean(view()))
1073 if (lyx_view_->buffer()->lyxvc().inUse()
1074 && !lyx_view_->buffer()->isReadonly()) {
1075 setMessage(from_utf8(lyx_view_->buffer()->lyxvc().checkIn()));
1080 case LFUN_VC_CHECK_OUT:
1081 LASSERT(lyx_view_ && lyx_view_->buffer(), /**/);
1082 if (!ensureBufferClean(view()))
1084 if (lyx_view_->buffer()->lyxvc().inUse()) {
1085 setMessage(from_utf8(lyx_view_->buffer()->lyxvc().checkOut()));
1090 case LFUN_VC_REVERT:
1091 LASSERT(lyx_view_ && lyx_view_->buffer(), /**/);
1092 lyx_view_->buffer()->lyxvc().revert();
1096 case LFUN_VC_UNDO_LAST:
1097 LASSERT(lyx_view_ && lyx_view_->buffer(), /**/);
1098 lyx_view_->buffer()->lyxvc().undoLast();
1102 // --- lyxserver commands ----------------------------
1103 case LFUN_SERVER_GET_FILENAME:
1104 LASSERT(lyx_view_ && lyx_view_->buffer(), /**/);
1105 setMessage(from_utf8(lyx_view_->buffer()->absFileName()));
1106 LYXERR(Debug::INFO, "FNAME["
1107 << lyx_view_->buffer()->absFileName() << ']');
1110 case LFUN_SERVER_NOTIFY:
1111 dispatch_buffer = keyseq.print(KeySequence::Portable);
1112 theServer().notifyClient(to_utf8(dispatch_buffer));
1115 case LFUN_SERVER_GOTO_FILE_ROW: {
1116 LASSERT(lyx_view_, /**/);
1119 istringstream is(argument);
1120 is >> file_name >> row;
1122 bool loaded = false;
1123 if (prefixIs(file_name, package().temp_dir().absFilename()))
1124 // Needed by inverse dvi search. If it is a file
1125 // in tmpdir, call the apropriated function
1126 buf = theBufferList().getBufferFromTmp(file_name);
1128 // Must replace extension of the file to be .lyx
1129 // and get full path
1130 FileName const s = fileSearch(string(), changeExtension(file_name, ".lyx"), "lyx");
1131 // Either change buffer or load the file
1132 if (theBufferList().exists(s))
1133 buf = theBufferList().getBuffer(s);
1135 buf = lyx_view_->loadDocument(s);
1141 updateFlags = Update::None;
1146 lyx_view_->setBuffer(buf);
1147 view()->setCursorFromRow(row);
1149 buf->errors("Parse");
1150 updateFlags = Update::FitCursor;
1155 case LFUN_DIALOG_SHOW_NEW_INSET: {
1156 LASSERT(lyx_view_, /**/);
1157 string const name = cmd.getArg(0);
1158 InsetCode code = insetCode(name);
1159 string data = trim(to_utf8(cmd.argument()).substr(name.size()));
1160 bool insetCodeOK = true;
1169 case HYPERLINK_CODE: {
1170 InsetCommandParams p(code);
1171 data = InsetCommand::params2string(name, p);
1174 case INCLUDE_CODE: {
1175 // data is the include type: one of "include",
1176 // "input", "verbatiminput" or "verbatiminput*"
1178 // default type is requested
1180 InsetCommandParams p(INCLUDE_CODE, data);
1181 data = InsetCommand::params2string("include", p);
1185 // \c data == "Boxed" || "Frameless" etc
1186 InsetBoxParams p(data);
1187 data = InsetBox::params2string(p);
1191 InsetBranchParams p;
1192 data = InsetBranch::params2string(p);
1196 InsetCommandParams p(CITE_CODE);
1197 data = InsetCommand::params2string(name, p);
1201 data = InsetERT::params2string(InsetCollapsable::Open);
1204 case EXTERNAL_CODE: {
1205 InsetExternalParams p;
1206 Buffer const & buffer = *lyx_view_->buffer();
1207 data = InsetExternal::params2string(p, buffer);
1212 data = InsetFloat::params2string(p);
1215 case LISTINGS_CODE: {
1216 InsetListingsParams p;
1217 data = InsetListings::params2string(p);
1220 case GRAPHICS_CODE: {
1221 InsetGraphicsParams p;
1222 Buffer const & buffer = *lyx_view_->buffer();
1223 data = InsetGraphics::params2string(p, buffer);
1228 data = InsetNote::params2string(p);
1233 data = InsetSpace::params2string(p);
1238 data = InsetVSpace::params2string(space);
1243 data = InsetWrap::params2string(p);
1247 lyxerr << "Inset type '" << name <<
1248 "' not recognized in LFUN_DIALOG_SHOW_NEW_INSET" << endl;
1249 insetCodeOK = false;
1251 } // end switch(code)
1253 dispatch(FuncRequest(LFUN_DIALOG_SHOW, name + " " + data));
1257 case LFUN_CITATION_INSERT: {
1258 LASSERT(lyx_view_, /**/);
1259 if (!argument.empty()) {
1260 // we can have one optional argument, delimited by '|'
1261 // citation-insert <key>|<text_before>
1262 // this should be enhanced to also support text_after
1263 // and citation style
1264 string arg = argument;
1266 if (contains(argument, "|")) {
1267 arg = token(argument, '|', 0);
1268 opt1 = token(argument, '|', 1);
1270 InsetCommandParams icp(CITE_CODE);
1271 icp["key"] = from_utf8(arg);
1273 icp["before"] = from_utf8(opt1);
1274 string icstr = InsetCommand::params2string("citation", icp);
1275 FuncRequest fr(LFUN_INSET_INSERT, icstr);
1278 dispatch(FuncRequest(LFUN_DIALOG_SHOW_NEW_INSET, "citation"));
1282 case LFUN_BUFFER_CHILD_OPEN: {
1283 LASSERT(lyx_view_ && lyx_view_->buffer(), /**/);
1284 Buffer * parent = lyx_view_->buffer();
1285 FileName filename = makeAbsPath(argument, parent->filePath());
1286 view()->saveBookmark(false);
1288 bool parsed = false;
1289 if (theBufferList().exists(filename)) {
1290 child = theBufferList().getBuffer(filename);
1292 setMessage(bformat(_("Opening child document %1$s..."),
1293 makeDisplayPath(filename.absFilename())));
1294 child = lyx_view_->loadDocument(filename, false);
1298 // Set the parent name of the child document.
1299 // This makes insertion of citations and references in the child work,
1300 // when the target is in the parent or another child document.
1301 child->setParent(parent);
1302 updateLabels(*child->masterBuffer());
1303 lyx_view_->setBuffer(child);
1305 child->errors("Parse");
1308 // If a screen update is required (in case where auto_open is false),
1309 // setBuffer() would have taken care of it already. Otherwise we shall
1310 // reset the update flag because it can cause a circular problem.
1312 updateFlags = Update::None;
1316 case LFUN_CURSOR_FOLLOWS_SCROLLBAR_TOGGLE:
1317 LASSERT(lyx_view_, /**/);
1318 lyxrc.cursor_follows_scrollbar = !lyxrc.cursor_follows_scrollbar;
1321 case LFUN_KEYMAP_OFF:
1322 LASSERT(lyx_view_ && lyx_view_->view(), /**/);
1323 lyx_view_->view()->getIntl().keyMapOn(false);
1326 case LFUN_KEYMAP_PRIMARY:
1327 LASSERT(lyx_view_ && lyx_view_->view(), /**/);
1328 lyx_view_->view()->getIntl().keyMapPrim();
1331 case LFUN_KEYMAP_SECONDARY:
1332 LASSERT(lyx_view_ && lyx_view_->view(), /**/);
1333 lyx_view_->view()->getIntl().keyMapSec();
1336 case LFUN_KEYMAP_TOGGLE:
1337 LASSERT(lyx_view_ && lyx_view_->view(), /**/);
1338 lyx_view_->view()->getIntl().toggleKeyMap();
1344 string rest = split(argument, countstr, ' ');
1345 istringstream is(countstr);
1348 lyxerr << "repeat: count: " << count << " cmd: " << rest << endl;
1349 for (int i = 0; i < count; ++i)
1350 dispatch(lyxaction.lookupFunc(rest));
1354 case LFUN_COMMAND_SEQUENCE: {
1355 // argument contains ';'-terminated commands
1356 string arg = argument;
1357 while (!arg.empty()) {
1359 arg = split(arg, first, ';');
1360 FuncRequest func(lyxaction.lookupFunc(first));
1361 func.origin = cmd.origin;
1367 case LFUN_COMMAND_ALTERNATIVES: {
1368 // argument contains ';'-terminated commands
1369 string arg = argument;
1370 while (!arg.empty()) {
1372 arg = split(arg, first, ';');
1373 FuncRequest func(lyxaction.lookupFunc(first));
1374 func.origin = cmd.origin;
1375 FuncStatus stat = getStatus(func);
1376 if (stat.enabled()) {
1386 if (theTopLevelCmdDef().lock(argument, func)) {
1387 func.origin = cmd.origin;
1389 theTopLevelCmdDef().release(argument);
1391 if (func.action == LFUN_UNKNOWN_ACTION) {
1392 // unknown command definition
1393 lyxerr << "Warning: unknown command definition `"
1397 // recursion detected
1398 lyxerr << "Warning: Recursion in the command definition `"
1399 << argument << "' detected"
1406 case LFUN_PREFERENCES_SAVE: {
1407 lyxrc.write(makeAbsPath("preferences",
1408 package().user_support().absFilename()),
1414 LASSERT(lyx_view_, /**/);
1415 lyx_view_->message(from_utf8(argument));
1418 case LFUN_BUFFER_LANGUAGE: {
1419 LASSERT(lyx_view_, /**/);
1420 Buffer & buffer = *lyx_view_->buffer();
1421 Language const * oldL = buffer.params().language;
1422 Language const * newL = languages.getLanguage(argument);
1423 if (!newL || oldL == newL)
1426 if (oldL->rightToLeft() == newL->rightToLeft()
1427 && !buffer.isMultiLingual())
1428 buffer.changeLanguage(oldL, newL);
1432 case LFUN_BUFFER_SAVE_AS_DEFAULT: {
1433 string const fname =
1434 addName(addPath(package().user_support().absFilename(), "templates/"),
1436 Buffer defaults(fname);
1438 istringstream ss(argument);
1441 int const unknown_tokens = defaults.readHeader(lex);
1443 if (unknown_tokens != 0) {
1444 lyxerr << "Warning in LFUN_BUFFER_SAVE_AS_DEFAULT!\n"
1445 << unknown_tokens << " unknown token"
1446 << (unknown_tokens == 1 ? "" : "s")
1450 if (defaults.writeFile(FileName(defaults.absFileName())))
1451 setMessage(bformat(_("Document defaults saved in %1$s"),
1452 makeDisplayPath(fname)));
1454 setErrorMessage(from_ascii(N_("Unable to save document defaults")));
1458 case LFUN_BUFFER_PARAMS_APPLY: {
1459 LASSERT(lyx_view_, /**/);
1461 Buffer * buffer = lyx_view_->buffer();
1462 DocumentClass const * const oldClass = buffer->params().documentClassPtr();
1463 Cursor & cur = view()->cursor();
1464 cur.recordUndoFullDocument();
1466 istringstream ss(argument);
1469 int const unknown_tokens = buffer->readHeader(lex);
1471 if (unknown_tokens != 0) {
1472 lyxerr << "Warning in LFUN_BUFFER_PARAMS_APPLY!\n"
1473 << unknown_tokens << " unknown token"
1474 << (unknown_tokens == 1 ? "" : "s")
1478 updateLayout(oldClass, buffer);
1480 updateFlags = Update::Force | Update::FitCursor;
1481 // We are most certainly here because of a change in the document
1482 // It is then better to make sure that all dialogs are in sync with
1483 // current document settings. LyXView::restartCursor() achieve this.
1484 lyx_view_->restartCursor();
1488 case LFUN_LAYOUT_MODULES_CLEAR: {
1489 LASSERT(lyx_view_, /**/);
1490 Buffer * buffer = lyx_view_->buffer();
1491 DocumentClass const * const oldClass = buffer->params().documentClassPtr();
1492 view()->cursor().recordUndoFullDocument();
1493 buffer->params().clearLayoutModules();
1494 buffer->params().makeDocumentClass();
1495 updateLayout(oldClass, buffer);
1496 updateFlags = Update::Force | Update::FitCursor;
1500 case LFUN_LAYOUT_MODULE_ADD: {
1501 LASSERT(lyx_view_, /**/);
1502 Buffer * buffer = lyx_view_->buffer();
1503 BufferParams const & params = buffer->params();
1504 if (!params.moduleCanBeAdded(argument)) {
1505 LYXERR0("Module `" << argument <<
1506 "' cannot be added due to failed requirements or "
1507 "conflicts with installed modules.");
1510 DocumentClass const * const oldClass = params.documentClassPtr();
1511 view()->cursor().recordUndoFullDocument();
1512 buffer->params().addLayoutModule(argument);
1513 buffer->params().makeDocumentClass();
1514 updateLayout(oldClass, buffer);
1515 updateFlags = Update::Force | Update::FitCursor;
1519 case LFUN_TEXTCLASS_APPLY: {
1520 LASSERT(lyx_view_, /**/);
1521 Buffer * buffer = lyx_view_->buffer();
1523 if (!loadLayoutFile(argument, buffer->temppath()) &&
1524 !loadLayoutFile(argument, buffer->filePath()))
1527 LayoutFile const * old_layout = buffer->params().baseClass();
1528 LayoutFile const * new_layout = &(LayoutFileList::get()[argument]);
1530 if (old_layout == new_layout)
1534 //Save the old, possibly modular, layout for use in conversion.
1535 DocumentClass const * const oldDocClass = buffer->params().documentClassPtr();
1536 view()->cursor().recordUndoFullDocument();
1537 buffer->params().setBaseClass(argument);
1538 buffer->params().makeDocumentClass();
1539 updateLayout(oldDocClass, buffer);
1540 updateFlags = Update::Force | Update::FitCursor;
1544 case LFUN_LAYOUT_RELOAD: {
1545 LASSERT(lyx_view_, /**/);
1546 Buffer * buffer = lyx_view_->buffer();
1547 DocumentClass const * const oldClass = buffer->params().documentClassPtr();
1548 LayoutFileIndex bc = buffer->params().baseClassID();
1549 LayoutFileList::get().reset(bc);
1550 buffer->params().setBaseClass(bc);
1551 buffer->params().makeDocumentClass();
1552 updateLayout(oldClass, buffer);
1553 updateFlags = Update::Force | Update::FitCursor;
1557 case LFUN_TEXTCLASS_LOAD:
1558 loadLayoutFile(argument, lyx_view_->buffer()->temppath()) ||
1559 loadLayoutFile(argument, lyx_view_->buffer()->filePath());
1562 case LFUN_LYXRC_APPLY: {
1563 LyXRC const lyxrc_orig = lyxrc;
1565 istringstream ss(argument);
1566 bool const success = lyxrc.read(ss) == 0;
1569 lyxerr << "Warning in LFUN_LYXRC_APPLY!\n"
1570 << "Unable to read lyxrc data"
1575 actOnUpdatedPrefs(lyxrc_orig, lyxrc);
1577 theApp()->resetGui();
1579 /// We force the redraw in any case because there might be
1580 /// some screen font changes.
1581 /// FIXME: only the current view will be updated. the Gui
1582 /// class is able to furnish the list of views.
1583 updateFlags = Update::Force;
1587 case LFUN_BOOKMARK_GOTO:
1588 // go to bookmark, open unopened file and switch to buffer if necessary
1589 gotoBookmark(convert<unsigned int>(to_utf8(cmd.argument())), true, true);
1590 updateFlags = Update::FitCursor;
1593 case LFUN_BOOKMARK_CLEAR:
1594 theSession().bookmarks().clear();
1598 LASSERT(theApp(), /**/);
1599 // Let the frontend dispatch its own actions.
1600 if (theApp()->dispatch(cmd))
1601 // Nothing more to do.
1604 // Everything below is only for active lyx_view_
1608 // Start an undo group. This may be needed for
1609 // some stuff like inset-apply on labels.
1610 if (lyx_view_->view())
1611 view()->cursor().beginUndoGroup();
1613 // Let the current LyXView dispatch its own actions.
1614 if (lyx_view_->dispatch(cmd)) {
1615 if (lyx_view_->view()) {
1616 updateFlags = lyx_view_->view()->cursor().result().update();
1617 view()->cursor().endUndoGroup();
1622 LASSERT(lyx_view_->view(), /**/);
1624 // Let the current BufferView dispatch its own actions.
1625 if (view()->dispatch(cmd)) {
1626 // The BufferView took care of its own updates if needed.
1627 updateFlags = Update::None;
1628 view()->cursor().endUndoGroup();
1632 // Let the current Cursor dispatch its own actions.
1633 Cursor old = view()->cursor();
1634 view()->cursor().getPos(cursorPosBeforeDispatchX_,
1635 cursorPosBeforeDispatchY_);
1636 view()->cursor().dispatch(cmd);
1638 // notify insets we just left
1639 if (view()->cursor() != old) {
1641 bool badcursor = notifyCursorLeaves(old, view()->cursor());
1643 view()->cursor().fixIfBroken();
1646 // we assume here that the buffer view has not
1647 // changed since the beginUndoGroup.
1648 view()->cursor().endUndoGroup();
1650 // update completion. We do it here and not in
1651 // processKeySym to avoid another redraw just for a
1652 // changed inline completion
1653 if (cmd.origin == FuncRequest::KEYBOARD) {
1654 if (cmd.action == LFUN_SELF_INSERT)
1655 lyx_view_->updateCompletion(view()->cursor(), true, true);
1656 else if (cmd.action == LFUN_CHAR_DELETE_BACKWARD)
1657 lyx_view_->updateCompletion(view()->cursor(), false, true);
1659 lyx_view_->updateCompletion(view()->cursor(), false, false);
1662 updateFlags = view()->cursor().result().update();
1665 if (lyx_view_ && lyx_view_->buffer()) {
1666 // BufferView::update() updates the ViewMetricsInfo and
1667 // also initializes the position cache for all insets in
1668 // (at least partially) visible top-level paragraphs.
1669 // We will redraw the screen only if needed.
1670 view()->processUpdateFlags(updateFlags);
1672 // if we executed a mutating lfun, mark the buffer as dirty
1674 && !lyxaction.funcHasFlag(action, LyXAction::NoBuffer)
1675 && !lyxaction.funcHasFlag(action, LyXAction::ReadOnly))
1676 lyx_view_->buffer()->markDirty();
1678 // Do we have a selection?
1679 theSelection().haveSelection(view()->cursor().selection());
1682 lyx_view_->restartCursor();
1686 // Some messages may already be translated, so we cannot use _()
1687 sendDispatchMessage(translateIfPossible(getMessage()), cmd);
1692 void LyXFunc::sendDispatchMessage(docstring const & msg, FuncRequest const & cmd)
1694 const bool verbose = (cmd.origin == FuncRequest::MENU
1695 || cmd.origin == FuncRequest::TOOLBAR
1696 || cmd.origin == FuncRequest::COMMANDBUFFER);
1698 if (cmd.action == LFUN_SELF_INSERT || !verbose) {
1699 LYXERR(Debug::ACTION, "dispatch msg is " << to_utf8(msg));
1701 lyx_view_->message(msg);
1705 docstring dispatch_msg = msg;
1706 if (!dispatch_msg.empty())
1707 dispatch_msg += ' ';
1709 docstring comname = from_utf8(lyxaction.getActionName(cmd.action));
1711 bool argsadded = false;
1713 if (!cmd.argument().empty()) {
1714 if (cmd.action != LFUN_UNKNOWN_ACTION) {
1715 comname += ' ' + cmd.argument();
1720 docstring const shortcuts = theTopLevelKeymap().printBindings(cmd);
1722 if (!shortcuts.empty())
1723 comname += ": " + shortcuts;
1724 else if (!argsadded && !cmd.argument().empty())
1725 comname += ' ' + cmd.argument();
1727 if (!comname.empty()) {
1728 comname = rtrim(comname);
1729 dispatch_msg += '(' + rtrim(comname) + ')';
1732 LYXERR(Debug::ACTION, "verbose dispatch msg " << to_utf8(dispatch_msg));
1733 if (!dispatch_msg.empty())
1734 lyx_view_->message(dispatch_msg);
1738 void LyXFunc::reloadBuffer()
1740 FileName filename = lyx_view_->buffer()->fileName();
1741 // The user has already confirmed that the changes, if any, should
1742 // be discarded. So we just release the Buffer and don't call closeBuffer();
1743 theBufferList().release(lyx_view_->buffer());
1744 Buffer * buf = lyx_view_->loadDocument(filename);
1745 docstring const disp_fn = makeDisplayPath(filename.absFilename());
1749 lyx_view_->setBuffer(buf);
1750 buf->errors("Parse");
1751 str = bformat(_("Document %1$s reloaded."), disp_fn);
1753 str = bformat(_("Could not reload document %1$s"), disp_fn);
1755 lyx_view_->message(str);
1758 // Each "lyx_view_" should have it's own message method. lyxview and
1759 // the minibuffer would use the minibuffer, but lyxserver would
1760 // send an ERROR signal to its client. Alejandro 970603
1761 // This function is bit problematic when it comes to NLS, to make the
1762 // lyx servers client be language indepenent we must not translate
1763 // strings sent to this func.
1764 void LyXFunc::setErrorMessage(docstring const & m) const
1766 dispatch_buffer = m;
1771 void LyXFunc::setMessage(docstring const & m) const
1773 dispatch_buffer = m;
1777 docstring LyXFunc::viewStatusMessage()
1779 // When meta-fake key is pressed, show the key sequence so far + "M-".
1781 return keyseq.print(KeySequence::ForGui) + "M-";
1783 // Else, when a non-complete key sequence is pressed,
1784 // show the available options.
1785 if (keyseq.length() > 0 && !keyseq.deleted())
1786 return keyseq.printOptions(true);
1788 LASSERT(lyx_view_, /**/);
1789 if (!lyx_view_->buffer())
1790 return _("Welcome to LyX!");
1792 return view()->cursor().currentState();
1796 BufferView * LyXFunc::view() const
1798 LASSERT(lyx_view_, /**/);
1799 return lyx_view_->view();
1803 bool LyXFunc::wasMetaKey() const
1805 return (meta_fake_bit != NoModifier);
1809 void LyXFunc::updateLayout(DocumentClass const * const oldlayout, Buffer * buffer)
1811 lyx_view_->message(_("Converting document to new document class..."));
1813 StableDocIterator backcur(view()->cursor());
1814 ErrorList & el = buffer->errorList("Class Switch");
1815 cap::switchBetweenClasses(
1816 oldlayout, buffer->params().documentClassPtr(),
1817 static_cast<InsetText &>(buffer->inset()), el);
1819 view()->setCursor(backcur.asDocIterator(&(buffer->inset())));
1821 buffer->errors("Class Switch");
1822 updateLabels(*buffer);
1828 void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
1830 // Why the switch you might ask. It is a trick to ensure that all
1831 // the elements in the LyXRCTags enum is handled. As you can see
1832 // there are no breaks at all. So it is just a huge fall-through.
1833 // The nice thing is that we will get a warning from the compiler
1834 // if we forget an element.
1835 LyXRC::LyXRCTags tag = LyXRC::RC_LAST;
1837 case LyXRC::RC_ACCEPT_COMPOUND:
1838 case LyXRC::RC_ALT_LANG:
1839 case LyXRC::RC_PLAINTEXT_ROFF_COMMAND:
1840 case LyXRC::RC_PLAINTEXT_LINELEN:
1841 case LyXRC::RC_AUTOREGIONDELETE:
1842 case LyXRC::RC_AUTORESET_OPTIONS:
1843 case LyXRC::RC_AUTOSAVE:
1844 case LyXRC::RC_AUTO_NUMBER:
1845 case LyXRC::RC_BACKUPDIR_PATH:
1846 case LyXRC::RC_BIBTEX_COMMAND:
1847 case LyXRC::RC_BINDFILE:
1848 case LyXRC::RC_CHECKLASTFILES:
1849 case LyXRC::RC_COMPLETION_CURSOR_TEXT:
1850 case LyXRC::RC_COMPLETION_INLINE_DELAY:
1851 case LyXRC::RC_COMPLETION_INLINE_DOTS:
1852 case LyXRC::RC_COMPLETION_INLINE_MATH:
1853 case LyXRC::RC_COMPLETION_INLINE_TEXT:
1854 case LyXRC::RC_COMPLETION_POPUP_AFTER_COMPLETE:
1855 case LyXRC::RC_COMPLETION_POPUP_DELAY:
1856 case LyXRC::RC_COMPLETION_POPUP_MATH:
1857 case LyXRC::RC_COMPLETION_POPUP_TEXT:
1858 case LyXRC::RC_USELASTFILEPOS:
1859 case LyXRC::RC_LOADSESSION:
1860 case LyXRC::RC_CHKTEX_COMMAND:
1861 case LyXRC::RC_CONVERTER:
1862 case LyXRC::RC_CONVERTER_CACHE_MAXAGE:
1863 case LyXRC::RC_COPIER:
1864 case LyXRC::RC_CURSOR_FOLLOWS_SCROLLBAR:
1865 case LyXRC::RC_CUSTOM_EXPORT_COMMAND:
1866 case LyXRC::RC_CUSTOM_EXPORT_FORMAT:
1867 case LyXRC::RC_DATE_INSERT_FORMAT:
1868 case LyXRC::RC_DEFAULT_LANGUAGE:
1869 case LyXRC::RC_GUI_LANGUAGE:
1870 case LyXRC::RC_DEFAULT_PAPERSIZE:
1871 case LyXRC::RC_DEFFILE:
1872 case LyXRC::RC_DIALOGS_ICONIFY_WITH_MAIN:
1873 case LyXRC::RC_DISPLAY_GRAPHICS:
1874 case LyXRC::RC_DOCUMENTPATH:
1875 if (lyxrc_orig.document_path != lyxrc_new.document_path) {
1876 FileName path(lyxrc_new.document_path);
1877 if (path.exists() && path.isDirectory())
1878 package().document_dir() = FileName(lyxrc.document_path);
1880 case LyXRC::RC_ESC_CHARS:
1881 case LyXRC::RC_EXAMPLEPATH:
1882 case LyXRC::RC_FONT_ENCODING:
1883 case LyXRC::RC_FORMAT:
1884 case LyXRC::RC_GROUP_LAYOUTS:
1885 case LyXRC::RC_INDEX_COMMAND:
1886 case LyXRC::RC_NOMENCL_COMMAND:
1887 case LyXRC::RC_INPUT:
1888 case LyXRC::RC_KBMAP:
1889 case LyXRC::RC_KBMAP_PRIMARY:
1890 case LyXRC::RC_KBMAP_SECONDARY:
1891 case LyXRC::RC_LABEL_INIT_LENGTH:
1892 case LyXRC::RC_LANGUAGE_AUTO_BEGIN:
1893 case LyXRC::RC_LANGUAGE_AUTO_END:
1894 case LyXRC::RC_LANGUAGE_COMMAND_BEGIN:
1895 case LyXRC::RC_LANGUAGE_COMMAND_END:
1896 case LyXRC::RC_LANGUAGE_COMMAND_LOCAL:
1897 case LyXRC::RC_LANGUAGE_GLOBAL_OPTIONS:
1898 case LyXRC::RC_LANGUAGE_PACKAGE:
1899 case LyXRC::RC_LANGUAGE_USE_BABEL:
1900 case LyXRC::RC_MAC_LIKE_WORD_MOVEMENT:
1901 case LyXRC::RC_MACRO_EDIT_STYLE:
1902 case LyXRC::RC_MAKE_BACKUP:
1903 case LyXRC::RC_MARK_FOREIGN_LANGUAGE:
1904 case LyXRC::RC_MOUSE_WHEEL_SPEED:
1905 case LyXRC::RC_NUMLASTFILES:
1906 case LyXRC::RC_PATH_PREFIX:
1907 if (lyxrc_orig.path_prefix != lyxrc_new.path_prefix) {
1908 prependEnvPath("PATH", lyxrc.path_prefix);
1910 case LyXRC::RC_PERS_DICT:
1911 case LyXRC::RC_PREVIEW:
1912 case LyXRC::RC_PREVIEW_HASHED_LABELS:
1913 case LyXRC::RC_PREVIEW_SCALE_FACTOR:
1914 case LyXRC::RC_PRINTCOLLCOPIESFLAG:
1915 case LyXRC::RC_PRINTCOPIESFLAG:
1916 case LyXRC::RC_PRINTER:
1917 case LyXRC::RC_PRINTEVENPAGEFLAG:
1918 case LyXRC::RC_PRINTEXSTRAOPTIONS:
1919 case LyXRC::RC_PRINTFILEEXTENSION:
1920 case LyXRC::RC_PRINTLANDSCAPEFLAG:
1921 case LyXRC::RC_PRINTODDPAGEFLAG:
1922 case LyXRC::RC_PRINTPAGERANGEFLAG:
1923 case LyXRC::RC_PRINTPAPERDIMENSIONFLAG:
1924 case LyXRC::RC_PRINTPAPERFLAG:
1925 case LyXRC::RC_PRINTREVERSEFLAG:
1926 case LyXRC::RC_PRINTSPOOL_COMMAND:
1927 case LyXRC::RC_PRINTSPOOL_PRINTERPREFIX:
1928 case LyXRC::RC_PRINTTOFILE:
1929 case LyXRC::RC_PRINTTOPRINTER:
1930 case LyXRC::RC_PRINT_ADAPTOUTPUT:
1931 case LyXRC::RC_PRINT_COMMAND:
1932 case LyXRC::RC_RTL_SUPPORT:
1933 case LyXRC::RC_SCREEN_DPI:
1934 case LyXRC::RC_SCREEN_FONT_ROMAN:
1935 case LyXRC::RC_SCREEN_FONT_ROMAN_FOUNDRY:
1936 case LyXRC::RC_SCREEN_FONT_SANS:
1937 case LyXRC::RC_SCREEN_FONT_SANS_FOUNDRY:
1938 case LyXRC::RC_SCREEN_FONT_SCALABLE:
1939 case LyXRC::RC_SCREEN_FONT_SIZES:
1940 case LyXRC::RC_SCREEN_FONT_TYPEWRITER:
1941 case LyXRC::RC_SCREEN_FONT_TYPEWRITER_FOUNDRY:
1942 case LyXRC::RC_GEOMETRY_SESSION:
1943 case LyXRC::RC_SCREEN_ZOOM:
1944 case LyXRC::RC_SERVERPIPE:
1945 case LyXRC::RC_SET_COLOR:
1946 case LyXRC::RC_SHOW_BANNER:
1947 case LyXRC::RC_OPEN_BUFFERS_IN_TABS:
1948 case LyXRC::RC_SPELL_COMMAND:
1949 case LyXRC::RC_TEMPDIRPATH:
1950 case LyXRC::RC_TEMPLATEPATH:
1951 case LyXRC::RC_TEX_ALLOWS_SPACES:
1952 case LyXRC::RC_TEX_EXPECTS_WINDOWS_PATHS:
1953 if (lyxrc_orig.windows_style_tex_paths != lyxrc_new.windows_style_tex_paths) {
1954 os::windows_style_tex_paths(lyxrc_new.windows_style_tex_paths);
1956 case LyXRC::RC_UIFILE:
1957 case LyXRC::RC_USER_EMAIL:
1958 case LyXRC::RC_USER_NAME:
1959 case LyXRC::RC_USETEMPDIR:
1960 case LyXRC::RC_USE_ALT_LANG:
1961 case LyXRC::RC_USE_CONVERTER_CACHE:
1962 case LyXRC::RC_USE_ESC_CHARS:
1963 case LyXRC::RC_USE_INP_ENC:
1964 case LyXRC::RC_USE_PERS_DICT:
1965 case LyXRC::RC_USE_TOOLTIP:
1966 case LyXRC::RC_USE_PIXMAP_CACHE:
1967 case LyXRC::RC_USE_SPELL_LIB:
1968 case LyXRC::RC_VIEWDVI_PAPEROPTION:
1969 case LyXRC::RC_SORT_LAYOUTS:
1970 case LyXRC::RC_FULL_SCREEN_LIMIT:
1971 case LyXRC::RC_FULL_SCREEN_SCROLLBAR:
1972 case LyXRC::RC_FULL_SCREEN_TABBAR:
1973 case LyXRC::RC_FULL_SCREEN_TOOLBARS:
1974 case LyXRC::RC_FULL_SCREEN_WIDTH:
1975 case LyXRC::RC_VISUAL_CURSOR:
1976 case LyXRC::RC_VIEWER:
1977 case LyXRC::RC_LAST: