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 "BranchList.h"
25 #include "buffer_funcs.h"
27 #include "BufferList.h"
28 #include "BufferParams.h"
29 #include "BufferView.h"
32 #include "Converter.h"
34 #include "CutAndPaste.h"
35 #include "DispatchResult.h"
37 #include "ErrorList.h"
39 #include "FuncRequest.h"
40 #include "FuncStatus.h"
41 #include "InsetIterator.h"
46 #include "LyXAction.h"
51 #include "Paragraph.h"
52 #include "ParagraphParameters.h"
53 #include "ParIterator.h"
57 #include "TextClassList.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/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"
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"
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"
95 using namespace lyx::support;
99 using frontend::LyXView;
101 namespace Alert = frontend::Alert;
106 // This function runs "configure" and then rereads lyx.defaults to
107 // reconfigure the automatic settings.
108 void reconfigure(LyXView & lv, string const & option)
110 // emit message signal.
111 lv.message(_("Running configure..."));
113 // Run configure in user lyx directory
114 PathChanger p(package().user_support());
115 string configure_command = package().configure_command();
116 configure_command += option;
118 int ret = one.startscript(Systemcall::Wait, configure_command);
120 // emit message signal.
121 lv.message(_("Reloading configuration..."));
122 lyxrc.read(libFileSearch(string(), "lyxrc.defaults"));
123 // Re-read packages.lst
124 LaTeXFeatures::getAvailable();
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."));
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."));
141 bool getLocalStatus(Cursor cursor, FuncRequest const & cmd, FuncStatus & status)
143 // Try to fix cursor in case it is broken.
144 cursor.fixIfBroken();
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;
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());
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)) {
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.
175 Change::Type lookupChangeType(DocIterator const & dit, bool outer = false)
177 size_t const depth = dit.depth() - (outer ? 1 : 0);
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)
188 return Change::UNCHANGED;
195 : lyx_view_(0), encoded_last_key(0), meta_fake_bit(NoModifier)
200 void LyXFunc::initKeySequences(KeyMap * kb)
202 keyseq = KeySequence(kb, kb);
203 cancel_meta_seq = KeySequence(kb, kb);
207 void LyXFunc::setLyXView(LyXView * lv)
209 if (!quitting && lyx_view_ && lyx_view_->view() && lyx_view_ != lv)
210 // save current selection to the selection buffer to allow
211 // middle-button paste in another window
212 cap::saveSelection(lyx_view_->view()->cursor());
217 void LyXFunc::handleKeyFunc(kb_action action)
219 char_type c = encoded_last_key;
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
230 // copied verbatim from do_accent_char
231 view()->cursor().resetAnchor();
232 view()->processUpdateFlags(Update::FitCursor);
236 void LyXFunc::gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer)
238 BOOST_ASSERT(lyx_view_);
239 if (!LyX::ref().session().bookmarks().isValid(idx))
241 BookmarksSection::Bookmark const & bm = LyX::ref().session().bookmarks().bookmark(idx);
242 BOOST_ASSERT(!bm.filename.empty());
243 string const file = bm.filename.absFilename();
244 // if the file is not opened, open it.
245 if (!theBufferList().exists(file)) {
247 dispatch(FuncRequest(LFUN_FILE_OPEN, file));
251 // open may fail, so we need to test it again
252 if (!theBufferList().exists(file))
255 // if the current buffer is not that one, switch to it.
256 if (lyx_view_->buffer()->absFileName() != file) {
259 dispatch(FuncRequest(LFUN_BUFFER_SWITCH, file));
261 // moveToPosition try paragraph id first and then paragraph (pit, pos).
262 if (!view()->moveToPosition(bm.bottom_pit, bm.bottom_pos,
263 bm.top_id, bm.top_pos))
266 // Cursor jump succeeded!
267 Cursor const & cur = view()->cursor();
268 pit_type new_pit = cur.pit();
269 pos_type new_pos = cur.pos();
270 int new_id = cur.paragraph().id();
272 // if bottom_pit, bottom_pos or top_id has been changed, update bookmark
273 // see http://bugzilla.lyx.org/show_bug.cgi?id=3092
274 if (bm.bottom_pit != new_pit || bm.bottom_pos != new_pos
275 || bm.top_id != new_id) {
276 const_cast<BookmarksSection::Bookmark &>(bm).updatePos(
277 new_pit, new_pos, new_id);
282 void LyXFunc::processKeySym(KeySymbol const & keysym, KeyModifier state)
284 LYXERR(Debug::KEY, "KeySym is " << keysym.getSymbolName());
286 // Do nothing if we have nothing (JMarc)
287 if (!keysym.isOK()) {
288 LYXERR(Debug::KEY, "Empty kbd action (probably composing)");
289 lyx_view_->restartCursor();
293 if (keysym.isModifier()) {
294 LYXERR(Debug::KEY, "isModifier true");
295 lyx_view_->restartCursor();
299 //Encoding const * encoding = view()->cursor().getEncoding();
300 //encoded_last_key = keysym.getISOEncoded(encoding ? encoding->name() : "");
301 // FIXME: encoded_last_key shadows the member variable of the same
302 // name. Is that intended?
303 char_type encoded_last_key = keysym.getUCSEncoded();
305 // Do a one-deep top-level lookup for
306 // cancel and meta-fake keys. RVDK_PATCH_5
307 cancel_meta_seq.reset();
309 FuncRequest func = cancel_meta_seq.addkey(keysym, state);
310 LYXERR(Debug::KEY, "action first set to [" << func.action << ']');
312 // When not cancel or meta-fake, do the normal lookup.
313 // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
314 // Mostly, meta_fake_bit = NoModifier. RVDK_PATCH_5.
315 if ((func.action != LFUN_CANCEL) && (func.action != LFUN_META_PREFIX)) {
316 // remove Caps Lock and Mod2 as a modifiers
317 func = keyseq.addkey(keysym, (state | meta_fake_bit));
318 LYXERR(Debug::KEY, "action now set to [" << func.action << ']');
321 // Dont remove this unless you know what you are doing.
322 meta_fake_bit = NoModifier;
324 // Can this happen now ?
325 if (func.action == LFUN_NOACTION)
326 func = FuncRequest(LFUN_COMMAND_PREFIX);
328 LYXERR(Debug::KEY, " Key [action=" << func.action << "]["
329 << keyseq.print(KeySequence::Portable) << ']');
331 // already here we know if it any point in going further
332 // why not return already here if action == -1 and
333 // num_bytes == 0? (Lgb)
335 if (keyseq.length() > 1)
336 lyx_view_->message(keyseq.print(KeySequence::ForGui));
339 // Maybe user can only reach the key via holding down shift.
340 // Let's see. But only if shift is the only modifier
341 if (func.action == LFUN_UNKNOWN_ACTION && state == ShiftModifier) {
342 LYXERR(Debug::KEY, "Trying without shift");
343 func = keyseq.addkey(keysym, NoModifier);
344 LYXERR(Debug::KEY, "Action now " << func.action);
347 if (func.action == LFUN_UNKNOWN_ACTION) {
348 // Hmm, we didn't match any of the keysequences. See
349 // if it's normal insertable text not already covered
351 if (keysym.isText() && keyseq.length() == 1) {
352 LYXERR(Debug::KEY, "isText() is true, inserting.");
353 func = FuncRequest(LFUN_SELF_INSERT,
354 FuncRequest::KEYBOARD);
356 LYXERR(Debug::KEY, "Unknown, !isText() - giving up");
357 lyx_view_->message(_("Unknown function."));
358 lyx_view_->restartCursor();
363 if (func.action == LFUN_SELF_INSERT) {
364 if (encoded_last_key != 0) {
365 docstring const arg(1, encoded_last_key);
366 dispatch(FuncRequest(LFUN_SELF_INSERT, arg,
367 FuncRequest::KEYBOARD));
368 LYXERR(Debug::KEY, "SelfInsert arg[`" << to_utf8(arg) << "']");
374 lyx_view_->restartCursor();
378 FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
380 //lyxerr << "LyXFunc::getStatus: cmd: " << cmd << endl;
383 Buffer * buf = lyx_view_? lyx_view_->buffer() : 0;
385 if (cmd.action == LFUN_NOACTION) {
386 flag.message(from_utf8(N_("Nothing to do")));
391 switch (cmd.action) {
392 case LFUN_UNKNOWN_ACTION:
393 #ifndef HAVE_LIBAIKSAURUS
394 case LFUN_THESAURUS_ENTRY:
404 if (flag.unknown()) {
405 flag.message(from_utf8(N_("Unknown action")));
409 if (!flag.enabled()) {
410 if (flag.message().empty())
411 flag.message(from_utf8(N_("Command disabled")));
415 // Check whether we need a buffer
416 if (!lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer) && !buf) {
418 flag.message(from_utf8(N_("Command not allowed with"
419 "out any document open")));
424 // I would really like to avoid having this switch and rather try to
425 // encode this in the function itself.
426 // -- And I'd rather let an inset decide which LFUNs it is willing
427 // to handle (Andre')
429 switch (cmd.action) {
431 // FIXME: these cases should be hidden in GuiApplication::getStatus().
432 case LFUN_WINDOW_CLOSE:
434 return theApp()->getStatus(cmd);
438 // FIXME: these cases should be hidden in GuiView::getStatus().
439 case LFUN_DIALOG_TOGGLE:
440 case LFUN_DIALOG_SHOW:
441 case LFUN_DIALOG_UPDATE:
442 if (cmd.argument() == "prefs"
443 || cmd.argument() == "aboutlyx")
446 return lyx_view_->getStatus(cmd);
451 case LFUN_TOOLBAR_TOGGLE:
452 case LFUN_INSET_APPLY:
453 case LFUN_BUFFER_WRITE:
454 case LFUN_BUFFER_WRITE_AS:
456 return lyx_view_->getStatus(cmd);
460 case LFUN_BUFFER_TOGGLE_READ_ONLY:
461 flag.setOnOff(buf->isReadonly());
464 case LFUN_BUFFER_SWITCH:
465 // toggle on the current buffer, but do not toggle off
466 // the other ones (is that a good idea?)
467 if (buf && to_utf8(cmd.argument()) == buf->absFileName())
471 case LFUN_BUFFER_EXPORT:
472 enable = cmd.argument() == "custom"
473 || buf->isExportable(to_utf8(cmd.argument()));
476 case LFUN_BUFFER_CHKTEX:
477 enable = buf->isLatex() && !lyxrc.chktex_command.empty();
480 case LFUN_BUILD_PROGRAM:
481 enable = buf->isExportable("program");
484 case LFUN_VC_REGISTER:
485 enable = !buf->lyxvc().inUse();
487 case LFUN_VC_CHECK_IN:
488 enable = buf->lyxvc().inUse() && !buf->isReadonly();
490 case LFUN_VC_CHECK_OUT:
491 enable = buf->lyxvc().inUse() && buf->isReadonly();
494 case LFUN_VC_UNDO_LAST:
495 enable = buf->lyxvc().inUse();
497 case LFUN_BUFFER_RELOAD:
498 enable = !buf->isUnnamed() && buf->fileName().exists()
499 && (!buf->isClean() || buf->isExternallyModified(Buffer::timestamp_method));
502 case LFUN_CITATION_INSERT: {
503 FuncRequest fr(LFUN_INSET_INSERT, "citation");
504 enable = getStatus(fr).enabled();
508 // This could be used for the no-GUI version. The GUI version is handled in
509 // LyXView::getStatus(). See above.
511 case LFUN_BUFFER_WRITE:
512 case LFUN_BUFFER_WRITE_AS: {
513 Buffer * b = theBufferList().getBuffer(cmd.getArg(0));
514 enable = b && (b->isUnnamed() || !b->isClean());
519 case LFUN_BUFFER_WRITE_ALL: {
520 // We enable the command only if there are some modified buffers
521 Buffer * first = theBufferList().first();
526 // We cannot use a for loop as the buffer list is a cycle.
532 b = theBufferList().next(b);
533 } while (b != first);
537 case LFUN_BOOKMARK_GOTO: {
538 const unsigned int num = convert<unsigned int>(to_utf8(cmd.argument()));
539 enable = LyX::ref().session().bookmarks().isValid(num);
543 case LFUN_BOOKMARK_CLEAR:
544 enable = LyX::ref().session().bookmarks().size() > 0;
547 // this one is difficult to get right. As a half-baked
548 // solution, we consider only the first action of the sequence
549 case LFUN_COMMAND_SEQUENCE: {
550 // argument contains ';'-terminated commands
551 string const firstcmd = token(to_utf8(cmd.argument()), ';', 0);
552 FuncRequest func(lyxaction.lookupFunc(firstcmd));
553 func.origin = cmd.origin;
554 flag = getStatus(func);
560 string name = to_utf8(cmd.argument());
561 if (LyX::ref().topLevelCmdDef().lock(name, func)) {
562 func.origin = cmd.origin;
563 flag = getStatus(func);
564 LyX::ref().topLevelCmdDef().release(name);
566 // catch recursion or unknown command definiton
567 // all operations until the recursion or unknown command
568 // definiton occures are performed, so set the state to enabled
574 case LFUN_BUFFER_NEW:
575 case LFUN_BUFFER_NEW_TEMPLATE:
576 case LFUN_WORD_FIND_FORWARD:
577 case LFUN_WORD_FIND_BACKWARD:
578 case LFUN_COMMAND_PREFIX:
579 case LFUN_COMMAND_EXECUTE:
581 case LFUN_META_PREFIX:
582 case LFUN_BUFFER_CLOSE:
583 case LFUN_BUFFER_UPDATE:
584 case LFUN_BUFFER_VIEW:
585 case LFUN_MASTER_BUFFER_UPDATE:
586 case LFUN_MASTER_BUFFER_VIEW:
587 case LFUN_BUFFER_IMPORT:
588 case LFUN_BUFFER_AUTO_SAVE:
589 case LFUN_RECONFIGURE:
592 case LFUN_DROP_LAYOUTS_CHOICE:
594 case LFUN_SERVER_GET_NAME:
595 case LFUN_SERVER_NOTIFY:
596 case LFUN_SERVER_GOTO_FILE_ROW:
597 case LFUN_DIALOG_HIDE:
598 case LFUN_DIALOG_DISCONNECT_INSET:
599 case LFUN_BUFFER_CHILD_OPEN:
601 case LFUN_TOGGLE_CURSOR_FOLLOWS_SCROLLBAR:
602 case LFUN_KEYMAP_OFF:
603 case LFUN_KEYMAP_PRIMARY:
604 case LFUN_KEYMAP_SECONDARY:
605 case LFUN_KEYMAP_TOGGLE:
607 case LFUN_BUFFER_EXPORT_CUSTOM:
608 case LFUN_BUFFER_PRINT:
609 case LFUN_PREFERENCES_SAVE:
610 case LFUN_SCREEN_FONT_UPDATE:
613 case LFUN_EXTERNAL_EDIT:
614 case LFUN_GRAPHICS_EDIT:
615 case LFUN_ALL_INSETS_TOGGLE:
616 case LFUN_BUFFER_LANGUAGE:
617 case LFUN_TEXTCLASS_APPLY:
618 case LFUN_TEXTCLASS_LOAD:
619 case LFUN_BUFFER_SAVE_AS_DEFAULT:
620 case LFUN_BUFFER_PARAMS_APPLY:
621 case LFUN_LAYOUT_MODULES_CLEAR:
622 case LFUN_LAYOUT_MODULE_ADD:
623 case LFUN_LAYOUT_RELOAD:
624 case LFUN_LYXRC_APPLY:
625 case LFUN_BUFFER_NEXT:
626 case LFUN_BUFFER_PREVIOUS:
627 case LFUN_WINDOW_NEW:
629 // these are handled in our dispatch()
637 if (!getLocalStatus(view()->cursor(), cmd, flag))
638 flag = view()->getStatus(cmd);
644 // Can we use a readonly buffer?
645 if (buf && buf->isReadonly()
646 && !lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly)
647 && !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)) {
648 flag.message(from_utf8(N_("Document is read-only")));
652 // Are we in a DELETED change-tracking region?
654 && lookupChangeType(view()->cursor(), true) == Change::DELETED
655 && !lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly)
656 && !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)) {
657 flag.message(from_utf8(N_("This portion of the document is deleted.")));
661 // the default error message if we disable the command
662 if (!flag.enabled() && flag.message().empty())
663 flag.message(from_utf8(N_("Command disabled")));
669 bool LyXFunc::ensureBufferClean(BufferView * bv)
671 Buffer & buf = bv->buffer();
675 docstring const file = buf.fileName().displayName(30);
676 docstring text = bformat(_("The document %1$s has unsaved "
677 "changes.\n\nDo you want to save "
678 "the document?"), file);
679 int const ret = Alert::prompt(_("Save changed document?"),
680 text, 0, 1, _("&Save"),
684 dispatch(FuncRequest(LFUN_BUFFER_WRITE));
686 return buf.isClean();
692 void showPrintError(string const & name)
694 docstring str = bformat(_("Could not print the document %1$s.\n"
695 "Check that your printer is set up correctly."),
696 makeDisplayPath(name, 50));
697 Alert::error(_("Print document failed"), str);
701 void loadTextClass(string const & name)
703 pair<bool, textclass_type> const tc_pair =
704 textclasslist.numberOfClass(name);
706 if (!tc_pair.first) {
707 lyxerr << "Document class \"" << name
708 << "\" does not exist."
713 textclass_type const tc = tc_pair.second;
715 if (!textclasslist[tc].load()) {
716 docstring s = bformat(_("The document class %1$s."
717 "could not be loaded."),
718 from_utf8(textclasslist[tc].name()));
719 Alert::error(_("Could not load class"), s);
724 void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new);
729 void LyXFunc::dispatch(FuncRequest const & cmd)
731 string const argument = to_utf8(cmd.argument());
732 kb_action const action = cmd.action;
734 LYXERR(Debug::ACTION, "\nLyXFunc::dispatch: cmd: " << cmd);
735 //lyxerr << "LyXFunc::dispatch: cmd: " << cmd << endl;
737 // we have not done anything wrong yet.
739 dispatch_buffer.erase();
741 // redraw the screen at the end (first of the two drawing steps).
742 //This is done unless explicitely requested otherwise
743 Update::flags updateFlags = Update::FitCursor;
745 FuncStatus const flag = getStatus(cmd);
746 if (!flag.enabled()) {
747 // We cannot use this function here
748 LYXERR(Debug::ACTION, "LyXFunc::dispatch: "
749 << lyxaction.getActionName(action)
750 << " [" << action << "] is disabled at this location");
751 setErrorMessage(flag.message());
755 case LFUN_WORD_FIND_FORWARD:
756 case LFUN_WORD_FIND_BACKWARD: {
757 BOOST_ASSERT(lyx_view_ && lyx_view_->view());
758 static docstring last_search;
759 docstring searched_string;
761 if (!cmd.argument().empty()) {
762 last_search = cmd.argument();
763 searched_string = cmd.argument();
765 searched_string = last_search;
768 if (searched_string.empty())
771 bool const fw = action == LFUN_WORD_FIND_FORWARD;
772 docstring const data =
773 find2string(searched_string, true, false, fw);
774 find(view(), FuncRequest(LFUN_WORD_FIND, data));
778 case LFUN_COMMAND_PREFIX:
779 BOOST_ASSERT(lyx_view_);
780 lyx_view_->message(keyseq.printOptions(true));
784 BOOST_ASSERT(lyx_view_ && lyx_view_->view());
786 meta_fake_bit = NoModifier;
787 if (lyx_view_->buffer())
788 // cancel any selection
789 dispatch(FuncRequest(LFUN_MARK_OFF));
790 setMessage(from_ascii(N_("Cancel")));
793 case LFUN_META_PREFIX:
794 meta_fake_bit = AltModifier;
795 setMessage(keyseq.print(KeySequence::ForGui));
798 case LFUN_BUFFER_TOGGLE_READ_ONLY: {
799 BOOST_ASSERT(lyx_view_ && lyx_view_->view() && lyx_view_->buffer());
800 Buffer * buf = lyx_view_->buffer();
801 if (buf->lyxvc().inUse())
802 buf->lyxvc().toggleReadOnly();
804 buf->setReadonly(!lyx_view_->buffer()->isReadonly());
808 // --- Menus -----------------------------------------------
809 case LFUN_BUFFER_NEW:
810 lyx_view_->newDocument(argument, false);
811 updateFlags = Update::None;
814 case LFUN_BUFFER_NEW_TEMPLATE:
815 lyx_view_->newDocument(argument, true);
816 updateFlags = Update::None;
819 case LFUN_BUFFER_CLOSE:
821 updateFlags = Update::None;
824 case LFUN_BUFFER_RELOAD: {
825 BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
826 docstring const file = makeDisplayPath(lyx_view_->buffer()->absFileName(), 20);
827 docstring text = bformat(_("Any changes will be lost. Are you sure "
828 "you want to revert to the saved version of the document %1$s?"), file);
829 int const ret = Alert::prompt(_("Revert to saved document?"),
830 text, 1, 1, _("&Revert"), _("&Cancel"));
837 case LFUN_BUFFER_UPDATE:
838 BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
839 lyx_view_->buffer()->doExport(argument, true);
842 case LFUN_BUFFER_VIEW:
843 BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
844 lyx_view_->buffer()->preview(argument);
847 case LFUN_MASTER_BUFFER_UPDATE:
848 BOOST_ASSERT(lyx_view_ && lyx_view_->buffer() && lyx_view_->buffer()->masterBuffer());
849 lyx_view_->buffer()->masterBuffer()->doExport(argument, true);
852 case LFUN_MASTER_BUFFER_VIEW:
853 BOOST_ASSERT(lyx_view_ && lyx_view_->buffer() && lyx_view_->buffer()->masterBuffer());
854 lyx_view_->buffer()->masterBuffer()->preview(argument);
857 case LFUN_BUILD_PROGRAM:
858 BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
859 lyx_view_->buffer()->doExport("program", true);
862 case LFUN_BUFFER_CHKTEX:
863 BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
864 lyx_view_->buffer()->runChktex();
867 case LFUN_BUFFER_EXPORT:
868 BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
869 if (argument == "custom")
870 dispatch(FuncRequest(LFUN_DIALOG_SHOW, "sendto"));
872 lyx_view_->buffer()->doExport(argument, false);
875 case LFUN_BUFFER_EXPORT_CUSTOM: {
876 BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
878 string command = split(argument, format_name, ' ');
879 Format const * format = formats.getFormat(format_name);
881 lyxerr << "Format \"" << format_name
882 << "\" not recognized!"
887 Buffer * buffer = lyx_view_->buffer();
889 // The name of the file created by the conversion process
892 // Output to filename
893 if (format->name() == "lyx") {
894 string const latexname = buffer->latexName(false);
895 filename = changeExtension(latexname,
896 format->extension());
897 filename = addName(buffer->temppath(), filename);
899 if (!buffer->writeFile(FileName(filename)))
903 buffer->doExport(format_name, true, filename);
906 // Substitute $$FName for filename
907 if (!contains(command, "$$FName"))
908 command = "( " + command + " ) < $$FName";
909 command = subst(command, "$$FName", filename);
911 // Execute the command in the background
913 call.startscript(Systemcall::DontWait, command);
917 case LFUN_BUFFER_PRINT: {
918 BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
919 // FIXME: cmd.getArg() might fail if one of the arguments
920 // contains double quotes
921 string target = cmd.getArg(0);
922 string target_name = cmd.getArg(1);
923 string command = cmd.getArg(2);
926 || target_name.empty()
927 || command.empty()) {
928 lyxerr << "Unable to parse \""
929 << argument << '"' << endl;
932 if (target != "printer" && target != "file") {
933 lyxerr << "Unrecognized target \""
934 << target << '"' << endl;
938 Buffer * buffer = lyx_view_->buffer();
940 if (!buffer->doExport("dvi", true)) {
941 showPrintError(buffer->absFileName());
945 // Push directory path.
946 string const path = buffer->temppath();
947 // Prevent the compiler from optimizing away p
951 // there are three cases here:
952 // 1. we print to a file
953 // 2. we print directly to a printer
954 // 3. we print using a spool command (print to file first)
957 string const dviname =
958 changeExtension(buffer->latexName(true), "dvi");
960 if (target == "printer") {
961 if (!lyxrc.print_spool_command.empty()) {
962 // case 3: print using a spool
963 string const psname =
964 changeExtension(dviname,".ps");
965 command += ' ' + lyxrc.print_to_file
968 + quoteName(dviname);
971 lyxrc.print_spool_command + ' ';
972 if (target_name != "default") {
973 command2 += lyxrc.print_spool_printerprefix
977 command2 += quoteName(psname);
979 // If successful, then spool command
980 res = one.startscript(
985 res = one.startscript(
986 Systemcall::DontWait,
989 // case 2: print directly to a printer
990 if (target_name != "default")
991 command += ' ' + lyxrc.print_to_printer + target_name + ' ';
992 res = one.startscript(
993 Systemcall::DontWait,
994 command + quoteName(dviname));
998 // case 1: print to a file
999 FileName const filename(makeAbsPath(target_name,
1000 lyx_view_->buffer()->filePath()));
1001 FileName const dvifile(makeAbsPath(dviname, path));
1002 if (filename.exists()) {
1003 docstring text = bformat(
1004 _("The file %1$s already exists.\n\n"
1005 "Do you want to overwrite that file?"),
1006 makeDisplayPath(filename.absFilename()));
1007 if (Alert::prompt(_("Overwrite file?"),
1008 text, 0, 1, _("&Overwrite"), _("&Cancel")) != 0)
1011 command += ' ' + lyxrc.print_to_file
1012 + quoteName(filename.toFilesystemEncoding())
1014 + quoteName(dvifile.toFilesystemEncoding());
1015 res = one.startscript(Systemcall::DontWait,
1020 showPrintError(buffer->absFileName());
1024 // FIXME: There is need for a command-line import.
1026 case LFUN_BUFFER_IMPORT:
1031 case LFUN_BUFFER_AUTO_SAVE:
1032 lyx_view_->buffer()->autoSave();
1035 case LFUN_RECONFIGURE:
1036 BOOST_ASSERT(lyx_view_);
1037 // argument is any additional parameter to the configure.py command
1038 reconfigure(*lyx_view_, argument);
1041 case LFUN_HELP_OPEN: {
1042 BOOST_ASSERT(lyx_view_);
1043 string const arg = argument;
1045 setErrorMessage(from_ascii(N_("Missing argument")));
1048 FileName const fname = i18nLibFileSearch("doc", arg, "lyx");
1049 if (fname.empty()) {
1050 lyxerr << "LyX: unable to find documentation file `"
1051 << arg << "'. Bad installation?" << endl;
1054 lyx_view_->message(bformat(_("Opening help file %1$s..."),
1055 makeDisplayPath(fname.absFilename())));
1056 Buffer * buf = lyx_view_->loadDocument(fname, false);
1059 lyx_view_->setBuffer(buf);
1060 buf->errors("Parse");
1062 updateFlags = Update::None;
1066 // --- version control -------------------------------
1067 case LFUN_VC_REGISTER:
1068 BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
1069 if (!ensureBufferClean(view()))
1071 if (!lyx_view_->buffer()->lyxvc().inUse()) {
1072 lyx_view_->buffer()->lyxvc().registrer();
1075 updateFlags = Update::Force;
1078 case LFUN_VC_CHECK_IN:
1079 BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
1080 if (!ensureBufferClean(view()))
1082 if (lyx_view_->buffer()->lyxvc().inUse()
1083 && !lyx_view_->buffer()->isReadonly()) {
1084 lyx_view_->buffer()->lyxvc().checkIn();
1089 case LFUN_VC_CHECK_OUT:
1090 BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
1091 if (!ensureBufferClean(view()))
1093 if (lyx_view_->buffer()->lyxvc().inUse()
1094 && lyx_view_->buffer()->isReadonly()) {
1095 lyx_view_->buffer()->lyxvc().checkOut();
1100 case LFUN_VC_REVERT:
1101 BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
1102 lyx_view_->buffer()->lyxvc().revert();
1106 case LFUN_VC_UNDO_LAST:
1107 BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
1108 lyx_view_->buffer()->lyxvc().undoLast();
1112 // --- lyxserver commands ----------------------------
1113 case LFUN_SERVER_GET_NAME:
1114 BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
1115 setMessage(from_utf8(lyx_view_->buffer()->absFileName()));
1116 LYXERR(Debug::INFO, "FNAME["
1117 << lyx_view_->buffer()->absFileName() << ']');
1120 case LFUN_SERVER_NOTIFY:
1121 dispatch_buffer = keyseq.print(KeySequence::Portable);
1122 theServer().notifyClient(to_utf8(dispatch_buffer));
1125 case LFUN_SERVER_GOTO_FILE_ROW: {
1126 BOOST_ASSERT(lyx_view_);
1129 istringstream is(argument);
1130 is >> file_name >> row;
1132 bool loaded = false;
1133 if (prefixIs(file_name, package().temp_dir().absFilename()))
1134 // Needed by inverse dvi search. If it is a file
1135 // in tmpdir, call the apropriated function
1136 buf = theBufferList().getBufferFromTmp(file_name);
1138 // Must replace extension of the file to be .lyx
1139 // and get full path
1140 FileName const s = fileSearch(string(), changeExtension(file_name, ".lyx"), "lyx");
1141 // Either change buffer or load the file
1142 if (theBufferList().exists(s.absFilename()))
1143 buf = theBufferList().getBuffer(s.absFilename());
1145 buf = lyx_view_->loadDocument(s);
1151 updateFlags = Update::None;
1156 lyx_view_->setBuffer(buf);
1157 view()->setCursorFromRow(row);
1159 buf->errors("Parse");
1160 updateFlags = Update::FitCursor;
1165 case LFUN_DIALOG_SHOW_NEW_INSET: {
1166 BOOST_ASSERT(lyx_view_);
1167 string const name = cmd.getArg(0);
1168 InsetCode code = insetCode(name);
1169 string data = trim(to_utf8(cmd.argument()).substr(name.size()));
1170 bool insetCodeOK = true;
1179 case HYPERLINK_CODE: {
1180 InsetCommandParams p(code);
1181 data = InsetCommandMailer::params2string(name, p);
1184 case INCLUDE_CODE: {
1185 // data is the include type: one of "include",
1186 // "input", "verbatiminput" or "verbatiminput*"
1188 // default type is requested
1190 InsetCommandParams p(INCLUDE_CODE, data);
1191 data = InsetCommandMailer::params2string("include", p);
1195 // \c data == "Boxed" || "Frameless" etc
1196 InsetBoxParams p(data);
1197 data = InsetBoxMailer::params2string(p);
1201 InsetBranchParams p;
1202 data = InsetBranchMailer::params2string(p);
1206 InsetCommandParams p(CITE_CODE);
1207 data = InsetCommandMailer::params2string(name, p);
1211 data = InsetERTMailer::params2string(InsetCollapsable::Open);
1214 case EXTERNAL_CODE: {
1215 InsetExternalParams p;
1216 Buffer const & buffer = *lyx_view_->buffer();
1217 data = InsetExternalMailer::params2string(p, buffer);
1222 data = InsetFloatMailer::params2string(p);
1225 case LISTINGS_CODE: {
1226 InsetListingsParams p;
1227 data = InsetListingsMailer::params2string(p);
1230 case GRAPHICS_CODE: {
1231 InsetGraphicsParams p;
1232 Buffer const & buffer = *lyx_view_->buffer();
1233 data = InsetGraphicsMailer::params2string(p, buffer);
1238 data = InsetNoteMailer::params2string(p);
1243 data = InsetVSpaceMailer::params2string(space);
1248 data = InsetWrapMailer::params2string(p);
1252 lyxerr << "Inset type '" << name <<
1253 "' not recognized in LFUN_DIALOG_SHOW_NEW_INSET" << endl;
1254 insetCodeOK = false;
1256 } // end switch(code)
1258 dispatch(FuncRequest(LFUN_DIALOG_SHOW, name + " " + data));
1262 case LFUN_CITATION_INSERT: {
1263 BOOST_ASSERT(lyx_view_);
1264 if (!argument.empty()) {
1265 // we can have one optional argument, delimited by '|'
1266 // citation-insert <key>|<text_before>
1267 // this should be enhanced to also support text_after
1268 // and citation style
1269 string arg = argument;
1271 if (contains(argument, "|")) {
1272 arg = token(argument, '|', 0);
1273 opt1 = token(argument, '|', 1);
1275 InsetCommandParams icp(CITE_CODE);
1276 icp["key"] = from_utf8(arg);
1278 icp["before"] = from_utf8(opt1);
1279 string icstr = InsetCommandMailer::params2string("citation", icp);
1280 FuncRequest fr(LFUN_INSET_INSERT, icstr);
1283 dispatch(FuncRequest(LFUN_DIALOG_SHOW_NEW_INSET, "citation"));
1287 case LFUN_BUFFER_CHILD_OPEN: {
1288 BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
1289 Buffer * parent = lyx_view_->buffer();
1290 FileName filename = makeAbsPath(argument, parent->filePath());
1291 view()->saveBookmark(false);
1293 bool parsed = false;
1294 if (theBufferList().exists(filename.absFilename())) {
1295 child = theBufferList().getBuffer(filename.absFilename());
1297 setMessage(bformat(_("Opening child document %1$s..."),
1298 makeDisplayPath(filename.absFilename())));
1299 child = lyx_view_->loadDocument(filename, false);
1303 // Set the parent name of the child document.
1304 // This makes insertion of citations and references in the child work,
1305 // when the target is in the parent or another child document.
1306 child->setParent(parent);
1307 updateLabels(*child->masterBuffer());
1308 lyx_view_->setBuffer(child);
1310 child->errors("Parse");
1313 // If a screen update is required (in case where auto_open is false),
1314 // setBuffer() would have taken care of it already. Otherwise we shall
1315 // reset the update flag because it can cause a circular problem.
1317 updateFlags = Update::None;
1321 case LFUN_TOGGLE_CURSOR_FOLLOWS_SCROLLBAR:
1322 BOOST_ASSERT(lyx_view_);
1323 lyxrc.cursor_follows_scrollbar = !lyxrc.cursor_follows_scrollbar;
1326 case LFUN_KEYMAP_OFF:
1327 BOOST_ASSERT(lyx_view_ && lyx_view_->view());
1328 lyx_view_->view()->getIntl().keyMapOn(false);
1331 case LFUN_KEYMAP_PRIMARY:
1332 BOOST_ASSERT(lyx_view_ && lyx_view_->view());
1333 lyx_view_->view()->getIntl().keyMapPrim();
1336 case LFUN_KEYMAP_SECONDARY:
1337 BOOST_ASSERT(lyx_view_ && lyx_view_->view());
1338 lyx_view_->view()->getIntl().keyMapSec();
1341 case LFUN_KEYMAP_TOGGLE:
1342 BOOST_ASSERT(lyx_view_ && lyx_view_->view());
1343 lyx_view_->view()->getIntl().toggleKeyMap();
1349 string rest = split(argument, countstr, ' ');
1350 istringstream is(countstr);
1353 lyxerr << "repeat: count: " << count << " cmd: " << rest << endl;
1354 for (int i = 0; i < count; ++i)
1355 dispatch(lyxaction.lookupFunc(rest));
1359 case LFUN_COMMAND_SEQUENCE: {
1360 // argument contains ';'-terminated commands
1361 string arg = argument;
1362 while (!arg.empty()) {
1364 arg = split(arg, first, ';');
1365 FuncRequest func(lyxaction.lookupFunc(first));
1366 func.origin = cmd.origin;
1374 if (LyX::ref().topLevelCmdDef().lock(argument, func)) {
1375 func.origin = cmd.origin;
1377 LyX::ref().topLevelCmdDef().release(argument);
1379 if (func.action == LFUN_UNKNOWN_ACTION) {
1380 // unknown command definition
1381 lyxerr << "Warning: unknown command definition `"
1385 // recursion detected
1386 lyxerr << "Warning: Recursion in the command definition `"
1387 << argument << "' detected"
1394 case LFUN_PREFERENCES_SAVE: {
1395 lyxrc.write(makeAbsPath("preferences",
1396 package().user_support().absFilename()),
1401 case LFUN_SET_COLOR: {
1403 string const x11_name = split(argument, lyx_name, ' ');
1404 if (lyx_name.empty() || x11_name.empty()) {
1405 setErrorMessage(from_ascii(N_(
1406 "Syntax: set-color <lyx_name>"
1411 bool const graphicsbg_changed =
1412 (lyx_name == lcolor.getLyXName(Color_graphicsbg) &&
1413 x11_name != lcolor.getX11Name(Color_graphicsbg));
1415 if (!lcolor.setColor(lyx_name, x11_name)) {
1417 bformat(_("Set-color \"%1$s\" failed "
1418 "- color is undefined or "
1419 "may not be redefined"),
1420 from_utf8(lyx_name)));
1424 theApp()->updateColor(lcolor.getFromLyXName(lyx_name));
1426 if (graphicsbg_changed) {
1427 // FIXME: The graphics cache no longer has a changeDisplay method.
1429 graphics::GCache::get().changeDisplay(true);
1436 BOOST_ASSERT(lyx_view_);
1437 lyx_view_->message(from_utf8(argument));
1440 case LFUN_EXTERNAL_EDIT: {
1441 BOOST_ASSERT(lyx_view_);
1442 FuncRequest fr(action, argument);
1443 InsetExternal().dispatch(view()->cursor(), fr);
1447 case LFUN_GRAPHICS_EDIT: {
1448 FuncRequest fr(action, argument);
1449 InsetGraphics().dispatch(view()->cursor(), fr);
1453 case LFUN_ALL_INSETS_TOGGLE: {
1454 BOOST_ASSERT(lyx_view_);
1456 string const name = split(argument, action, ' ');
1457 InsetCode const inset_code = insetCode(name);
1459 Cursor & cur = view()->cursor();
1460 FuncRequest fr(LFUN_INSET_TOGGLE, action);
1462 Inset & inset = lyx_view_->buffer()->inset();
1463 InsetIterator it = inset_iterator_begin(inset);
1464 InsetIterator const end = inset_iterator_end(inset);
1465 for (; it != end; ++it) {
1466 if (!it->asInsetMath()
1467 && (inset_code == NO_CODE
1468 || inset_code == it->lyxCode())) {
1469 Cursor tmpcur = cur;
1470 tmpcur.pushBackward(*it);
1471 it->dispatch(tmpcur, fr);
1474 updateFlags = Update::Force | Update::FitCursor;
1478 case LFUN_BUFFER_LANGUAGE: {
1479 BOOST_ASSERT(lyx_view_);
1480 Buffer & buffer = *lyx_view_->buffer();
1481 Language const * oldL = buffer.params().language;
1482 Language const * newL = languages.getLanguage(argument);
1483 if (!newL || oldL == newL)
1486 if (oldL->rightToLeft() == newL->rightToLeft()
1487 && !buffer.isMultiLingual())
1488 buffer.changeLanguage(oldL, newL);
1492 case LFUN_BUFFER_SAVE_AS_DEFAULT: {
1493 string const fname =
1494 addName(addPath(package().user_support().absFilename(), "templates/"),
1496 Buffer defaults(fname);
1498 istringstream ss(argument);
1501 int const unknown_tokens = defaults.readHeader(lex);
1503 if (unknown_tokens != 0) {
1504 lyxerr << "Warning in LFUN_BUFFER_SAVE_AS_DEFAULT!\n"
1505 << unknown_tokens << " unknown token"
1506 << (unknown_tokens == 1 ? "" : "s")
1510 if (defaults.writeFile(FileName(defaults.absFileName())))
1511 setMessage(bformat(_("Document defaults saved in %1$s"),
1512 makeDisplayPath(fname)));
1514 setErrorMessage(from_ascii(N_("Unable to save document defaults")));
1518 case LFUN_BUFFER_PARAMS_APPLY: {
1519 BOOST_ASSERT(lyx_view_);
1520 biblio::CiteEngine const oldEngine =
1521 lyx_view_->buffer()->params().getEngine();
1523 Buffer * buffer = lyx_view_->buffer();
1525 TextClassPtr oldClass = buffer->params().getTextClassPtr();
1527 Cursor & cur = view()->cursor();
1528 cur.recordUndoFullDocument();
1530 istringstream ss(argument);
1533 int const unknown_tokens = buffer->readHeader(lex);
1535 if (unknown_tokens != 0) {
1536 lyxerr << "Warning in LFUN_BUFFER_PARAMS_APPLY!\n"
1537 << unknown_tokens << " unknown token"
1538 << (unknown_tokens == 1 ? "" : "s")
1542 updateLayout(oldClass, buffer);
1544 biblio::CiteEngine const newEngine =
1545 lyx_view_->buffer()->params().getEngine();
1547 if (oldEngine != newEngine) {
1548 FuncRequest fr(LFUN_INSET_REFRESH);
1550 Inset & inset = lyx_view_->buffer()->inset();
1551 InsetIterator it = inset_iterator_begin(inset);
1552 InsetIterator const end = inset_iterator_end(inset);
1553 for (; it != end; ++it)
1554 if (it->lyxCode() == CITE_CODE)
1555 it->dispatch(cur, fr);
1558 updateFlags = Update::Force | Update::FitCursor;
1559 // We are here most certainaly because of a change in the document
1560 // It is then better to make sure that all dialogs are in sync
1561 // with current document settings. LyXView::restartCursor() achieve this.
1562 lyx_view_->restartCursor();
1566 case LFUN_LAYOUT_MODULES_CLEAR: {
1567 BOOST_ASSERT(lyx_view_);
1568 Buffer * buffer = lyx_view_->buffer();
1569 TextClassPtr oldClass = buffer->params().getTextClassPtr();
1570 view()->cursor().recordUndoFullDocument();
1571 buffer->params().clearLayoutModules();
1572 buffer->params().makeTextClass();
1573 updateLayout(oldClass, buffer);
1574 updateFlags = Update::Force | Update::FitCursor;
1578 case LFUN_LAYOUT_MODULE_ADD: {
1579 BOOST_ASSERT(lyx_view_);
1580 Buffer * buffer = lyx_view_->buffer();
1581 TextClassPtr oldClass = buffer->params().getTextClassPtr();
1582 view()->cursor().recordUndoFullDocument();
1583 buffer->params().addLayoutModule(argument);
1584 buffer->params().makeTextClass();
1585 updateLayout(oldClass, buffer);
1586 updateFlags = Update::Force | Update::FitCursor;
1590 case LFUN_TEXTCLASS_APPLY: {
1591 BOOST_ASSERT(lyx_view_);
1592 Buffer * buffer = lyx_view_->buffer();
1594 loadTextClass(argument);
1596 pair<bool, textclass_type> const tc_pair =
1597 textclasslist.numberOfClass(argument);
1602 textclass_type const old_class = buffer->params().getBaseClass();
1603 textclass_type const new_class = tc_pair.second;
1605 if (old_class == new_class)
1609 //Save the old, possibly modular, layout for use in conversion.
1610 TextClassPtr oldClass = buffer->params().getTextClassPtr();
1611 view()->cursor().recordUndoFullDocument();
1612 buffer->params().setBaseClass(new_class);
1613 buffer->params().makeTextClass();
1614 updateLayout(oldClass, buffer);
1615 updateFlags = Update::Force | Update::FitCursor;
1619 case LFUN_LAYOUT_RELOAD: {
1620 BOOST_ASSERT(lyx_view_);
1621 Buffer * buffer = lyx_view_->buffer();
1622 TextClassPtr oldClass = buffer->params().getTextClassPtr();
1623 textclass_type const tc = buffer->params().getBaseClass();
1624 textclasslist.reset(tc);
1625 buffer->params().setBaseClass(tc);
1626 buffer->params().makeTextClass();
1627 updateLayout(oldClass, buffer);
1628 updateFlags = Update::Force | Update::FitCursor;
1632 case LFUN_TEXTCLASS_LOAD:
1633 loadTextClass(argument);
1636 case LFUN_LYXRC_APPLY: {
1637 LyXRC const lyxrc_orig = lyxrc;
1639 istringstream ss(argument);
1640 bool const success = lyxrc.read(ss) == 0;
1643 lyxerr << "Warning in LFUN_LYXRC_APPLY!\n"
1644 << "Unable to read lyxrc data"
1649 actOnUpdatedPrefs(lyxrc_orig, lyxrc);
1651 theApp()->resetGui();
1653 /// We force the redraw in any case because there might be
1654 /// some screen font changes.
1655 /// FIXME: only the current view will be updated. the Gui
1656 /// class is able to furnish the list of views.
1657 updateFlags = Update::Force;
1661 case LFUN_BOOKMARK_GOTO:
1662 // go to bookmark, open unopened file and switch to buffer if necessary
1663 gotoBookmark(convert<unsigned int>(to_utf8(cmd.argument())), true, true);
1664 updateFlags = Update::FitCursor;
1667 case LFUN_BOOKMARK_CLEAR:
1668 LyX::ref().session().bookmarks().clear();
1672 BOOST_ASSERT(theApp());
1673 // Let the frontend dispatch its own actions.
1674 if (theApp()->dispatch(cmd))
1675 // Nothing more to do.
1678 // Let the current LyXView dispatch its own actions.
1679 BOOST_ASSERT(lyx_view_);
1680 if (lyx_view_->dispatch(cmd)) {
1681 if (lyx_view_->view())
1682 updateFlags = lyx_view_->view()->cursor().result().update();
1686 BOOST_ASSERT(lyx_view_->view());
1687 // Let the current BufferView dispatch its own actions.
1688 if (view()->dispatch(cmd)) {
1689 // The BufferView took care of its own updates if needed.
1690 updateFlags = Update::None;
1694 // Let the current Cursor dispatch its own actions.
1695 view()->cursor().getPos(cursorPosBeforeDispatchX_,
1696 cursorPosBeforeDispatchY_);
1697 view()->cursor().dispatch(cmd);
1698 updateFlags = view()->cursor().result().update();
1699 if (!view()->cursor().result().dispatched()) {
1700 // No update needed in this case (e.g. when reaching
1702 updateFlags = Update::None;
1706 if (lyx_view_ && lyx_view_->buffer()) {
1707 // BufferView::update() updates the ViewMetricsInfo and
1708 // also initializes the position cache for all insets in
1709 // (at least partially) visible top-level paragraphs.
1710 // We will redraw the screen only if needed.
1711 view()->processUpdateFlags(updateFlags);
1713 // if we executed a mutating lfun, mark the buffer as dirty
1715 && !lyxaction.funcHasFlag(action, LyXAction::NoBuffer)
1716 && !lyxaction.funcHasFlag(action, LyXAction::ReadOnly))
1717 lyx_view_->buffer()->markDirty();
1719 //Do we have a selection?
1720 theSelection().haveSelection(view()->cursor().selection());
1723 if (!quitting && lyx_view_) {
1724 // Some messages may already be translated, so we cannot use _()
1725 sendDispatchMessage(translateIfPossible(getMessage()), cmd);
1730 void LyXFunc::sendDispatchMessage(docstring const & msg, FuncRequest const & cmd)
1732 const bool verbose = (cmd.origin == FuncRequest::MENU
1733 || cmd.origin == FuncRequest::TOOLBAR
1734 || cmd.origin == FuncRequest::COMMANDBUFFER);
1736 if (cmd.action == LFUN_SELF_INSERT || !verbose) {
1737 LYXERR(Debug::ACTION, "dispatch msg is " << to_utf8(msg));
1739 lyx_view_->message(msg);
1743 docstring dispatch_msg = msg;
1744 if (!dispatch_msg.empty())
1745 dispatch_msg += ' ';
1747 docstring comname = from_utf8(lyxaction.getActionName(cmd.action));
1749 bool argsadded = false;
1751 if (!cmd.argument().empty()) {
1752 if (cmd.action != LFUN_UNKNOWN_ACTION) {
1753 comname += ' ' + cmd.argument();
1758 docstring const shortcuts = theTopLevelKeymap().printBindings(cmd);
1760 if (!shortcuts.empty())
1761 comname += ": " + shortcuts;
1762 else if (!argsadded && !cmd.argument().empty())
1763 comname += ' ' + cmd.argument();
1765 if (!comname.empty()) {
1766 comname = rtrim(comname);
1767 dispatch_msg += '(' + rtrim(comname) + ')';
1770 LYXERR(Debug::ACTION, "verbose dispatch msg " << to_utf8(dispatch_msg));
1771 if (!dispatch_msg.empty())
1772 lyx_view_->message(dispatch_msg);
1776 void LyXFunc::closeBuffer()
1778 // goto bookmark to update bookmark pit.
1779 for (size_t i = 0; i < LyX::ref().session().bookmarks().size(); ++i)
1780 gotoBookmark(i+1, false, false);
1782 lyx_view_->closeBuffer();
1786 void LyXFunc::reloadBuffer()
1788 FileName filename = lyx_view_->buffer()->fileName();
1789 // The user has already confirmed that the changes, if any, should
1790 // be discarded. So we just release the Buffer and don't call closeBuffer();
1791 theBufferList().release(lyx_view_->buffer());
1792 Buffer * buf = lyx_view_->loadDocument(filename);
1793 docstring const disp_fn = makeDisplayPath(filename.absFilename());
1797 lyx_view_->setBuffer(buf);
1798 buf->errors("Parse");
1799 str = bformat(_("Document %1$s reloaded."), disp_fn);
1801 str = bformat(_("Could not reload document %1$s"), disp_fn);
1803 lyx_view_->message(str);
1806 // Each "lyx_view_" should have it's own message method. lyxview and
1807 // the minibuffer would use the minibuffer, but lyxserver would
1808 // send an ERROR signal to its client. Alejandro 970603
1809 // This function is bit problematic when it comes to NLS, to make the
1810 // lyx servers client be language indepenent we must not translate
1811 // strings sent to this func.
1812 void LyXFunc::setErrorMessage(docstring const & m) const
1814 dispatch_buffer = m;
1819 void LyXFunc::setMessage(docstring const & m) const
1821 dispatch_buffer = m;
1825 docstring const LyXFunc::viewStatusMessage()
1827 // When meta-fake key is pressed, show the key sequence so far + "M-".
1829 return keyseq.print(KeySequence::ForGui) + "M-";
1831 // Else, when a non-complete key sequence is pressed,
1832 // show the available options.
1833 if (keyseq.length() > 0 && !keyseq.deleted())
1834 return keyseq.printOptions(true);
1836 BOOST_ASSERT(lyx_view_);
1837 if (!lyx_view_->buffer())
1838 return _("Welcome to LyX!");
1840 return view()->cursor().currentState();
1844 BufferView * LyXFunc::view() const
1846 BOOST_ASSERT(lyx_view_);
1847 return lyx_view_->view();
1851 bool LyXFunc::wasMetaKey() const
1853 return (meta_fake_bit != NoModifier);
1857 void LyXFunc::updateLayout(TextClassPtr const & oldlayout,
1860 lyx_view_->message(_("Converting document to new document class..."));
1862 StableDocIterator backcur(view()->cursor());
1863 ErrorList & el = buffer->errorList("Class Switch");
1864 cap::switchBetweenClasses(
1865 oldlayout, buffer->params().getTextClassPtr(),
1866 static_cast<InsetText &>(buffer->inset()), el);
1868 view()->setCursor(backcur.asDocIterator(&(buffer->inset())));
1870 buffer->errors("Class Switch");
1871 updateLabels(*buffer);
1877 void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
1879 // Why the switch you might ask. It is a trick to ensure that all
1880 // the elements in the LyXRCTags enum is handled. As you can see
1881 // there are no breaks at all. So it is just a huge fall-through.
1882 // The nice thing is that we will get a warning from the compiler
1883 // if we forget an element.
1884 LyXRC::LyXRCTags tag = LyXRC::RC_LAST;
1886 case LyXRC::RC_ACCEPT_COMPOUND:
1887 case LyXRC::RC_ALT_LANG:
1888 case LyXRC::RC_PLAINTEXT_ROFF_COMMAND:
1889 case LyXRC::RC_PLAINTEXT_LINELEN:
1890 case LyXRC::RC_AUTOREGIONDELETE:
1891 case LyXRC::RC_AUTORESET_OPTIONS:
1892 case LyXRC::RC_AUTOSAVE:
1893 case LyXRC::RC_AUTO_NUMBER:
1894 case LyXRC::RC_BACKUPDIR_PATH:
1895 case LyXRC::RC_BIBTEX_COMMAND:
1896 case LyXRC::RC_BINDFILE:
1897 case LyXRC::RC_CHECKLASTFILES:
1898 case LyXRC::RC_USELASTFILEPOS:
1899 case LyXRC::RC_LOADSESSION:
1900 case LyXRC::RC_CHKTEX_COMMAND:
1901 case LyXRC::RC_CONVERTER:
1902 case LyXRC::RC_CONVERTER_CACHE_MAXAGE:
1903 case LyXRC::RC_COPIER:
1904 case LyXRC::RC_CURSOR_FOLLOWS_SCROLLBAR:
1905 case LyXRC::RC_CUSTOM_EXPORT_COMMAND:
1906 case LyXRC::RC_CUSTOM_EXPORT_FORMAT:
1907 case LyXRC::RC_DATE_INSERT_FORMAT:
1908 case LyXRC::RC_DEFAULT_LANGUAGE:
1909 case LyXRC::RC_DEFAULT_PAPERSIZE:
1910 case LyXRC::RC_DEFFILE:
1911 case LyXRC::RC_DIALOGS_ICONIFY_WITH_MAIN:
1912 case LyXRC::RC_DISPLAY_GRAPHICS:
1913 case LyXRC::RC_DOCUMENTPATH:
1914 if (lyxrc_orig.document_path != lyxrc_new.document_path) {
1915 FileName path(lyxrc_new.document_path);
1916 if (path.exists() && path.isDirectory())
1917 package().document_dir() = FileName(lyxrc.document_path);
1919 case LyXRC::RC_ESC_CHARS:
1920 case LyXRC::RC_EXAMPLEPATH:
1921 case LyXRC::RC_FONT_ENCODING:
1922 case LyXRC::RC_FORMAT:
1923 case LyXRC::RC_INDEX_COMMAND:
1924 case LyXRC::RC_INPUT:
1925 case LyXRC::RC_KBMAP:
1926 case LyXRC::RC_KBMAP_PRIMARY:
1927 case LyXRC::RC_KBMAP_SECONDARY:
1928 case LyXRC::RC_LABEL_INIT_LENGTH:
1929 case LyXRC::RC_LANGUAGE_AUTO_BEGIN:
1930 case LyXRC::RC_LANGUAGE_AUTO_END:
1931 case LyXRC::RC_LANGUAGE_COMMAND_BEGIN:
1932 case LyXRC::RC_LANGUAGE_COMMAND_END:
1933 case LyXRC::RC_LANGUAGE_COMMAND_LOCAL:
1934 case LyXRC::RC_LANGUAGE_GLOBAL_OPTIONS:
1935 case LyXRC::RC_LANGUAGE_PACKAGE:
1936 case LyXRC::RC_LANGUAGE_USE_BABEL:
1937 case LyXRC::RC_MACRO_EDIT_STYLE:
1938 case LyXRC::RC_MAKE_BACKUP:
1939 case LyXRC::RC_MARK_FOREIGN_LANGUAGE:
1940 case LyXRC::RC_MOUSE_WHEEL_SPEED:
1941 case LyXRC::RC_NUMLASTFILES:
1942 case LyXRC::RC_PATH_PREFIX:
1943 if (lyxrc_orig.path_prefix != lyxrc_new.path_prefix) {
1944 prependEnvPath("PATH", lyxrc.path_prefix);
1946 case LyXRC::RC_PERS_DICT:
1947 case LyXRC::RC_PREVIEW:
1948 case LyXRC::RC_PREVIEW_HASHED_LABELS:
1949 case LyXRC::RC_PREVIEW_SCALE_FACTOR:
1950 case LyXRC::RC_PRINTCOLLCOPIESFLAG:
1951 case LyXRC::RC_PRINTCOPIESFLAG:
1952 case LyXRC::RC_PRINTER:
1953 case LyXRC::RC_PRINTEVENPAGEFLAG:
1954 case LyXRC::RC_PRINTEXSTRAOPTIONS:
1955 case LyXRC::RC_PRINTFILEEXTENSION:
1956 case LyXRC::RC_PRINTLANDSCAPEFLAG:
1957 case LyXRC::RC_PRINTODDPAGEFLAG:
1958 case LyXRC::RC_PRINTPAGERANGEFLAG:
1959 case LyXRC::RC_PRINTPAPERDIMENSIONFLAG:
1960 case LyXRC::RC_PRINTPAPERFLAG:
1961 case LyXRC::RC_PRINTREVERSEFLAG:
1962 case LyXRC::RC_PRINTSPOOL_COMMAND:
1963 case LyXRC::RC_PRINTSPOOL_PRINTERPREFIX:
1964 case LyXRC::RC_PRINTTOFILE:
1965 case LyXRC::RC_PRINTTOPRINTER:
1966 case LyXRC::RC_PRINT_ADAPTOUTPUT:
1967 case LyXRC::RC_PRINT_COMMAND:
1968 case LyXRC::RC_RTL_SUPPORT:
1969 case LyXRC::RC_SCREEN_DPI:
1970 case LyXRC::RC_SCREEN_FONT_ROMAN:
1971 case LyXRC::RC_SCREEN_FONT_ROMAN_FOUNDRY:
1972 case LyXRC::RC_SCREEN_FONT_SANS:
1973 case LyXRC::RC_SCREEN_FONT_SANS_FOUNDRY:
1974 case LyXRC::RC_SCREEN_FONT_SCALABLE:
1975 case LyXRC::RC_SCREEN_FONT_SIZES:
1976 case LyXRC::RC_SCREEN_FONT_TYPEWRITER:
1977 case LyXRC::RC_SCREEN_FONT_TYPEWRITER_FOUNDRY:
1978 case LyXRC::RC_GEOMETRY_SESSION:
1979 case LyXRC::RC_SCREEN_ZOOM:
1980 case LyXRC::RC_SERVERPIPE:
1981 case LyXRC::RC_SET_COLOR:
1982 case LyXRC::RC_SHOW_BANNER:
1983 case LyXRC::RC_SPELL_COMMAND:
1984 case LyXRC::RC_TEMPDIRPATH:
1985 case LyXRC::RC_TEMPLATEPATH:
1986 case LyXRC::RC_TEX_ALLOWS_SPACES:
1987 case LyXRC::RC_TEX_EXPECTS_WINDOWS_PATHS:
1988 if (lyxrc_orig.windows_style_tex_paths != lyxrc_new.windows_style_tex_paths) {
1989 os::windows_style_tex_paths(lyxrc_new.windows_style_tex_paths);
1991 case LyXRC::RC_UIFILE:
1992 case LyXRC::RC_USER_EMAIL:
1993 case LyXRC::RC_USER_NAME:
1994 case LyXRC::RC_USETEMPDIR:
1995 case LyXRC::RC_USE_ALT_LANG:
1996 case LyXRC::RC_USE_CONVERTER_CACHE:
1997 case LyXRC::RC_USE_ESC_CHARS:
1998 case LyXRC::RC_USE_INP_ENC:
1999 case LyXRC::RC_USE_PERS_DICT:
2000 case LyXRC::RC_USE_TOOLTIP:
2001 case LyXRC::RC_USE_PIXMAP_CACHE:
2002 case LyXRC::RC_USE_SPELL_LIB:
2003 case LyXRC::RC_VIEWDVI_PAPEROPTION:
2004 case LyXRC::RC_SORT_LAYOUTS:
2005 case LyXRC::RC_VIEWER:
2006 case LyXRC::RC_LAST: