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 "BaseClassList.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/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 (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);
235 //FIXME: bookmark handling is a frontend issue. This code should be transferred
236 // to GuiView and be GuiView and be window dependent.
237 void LyXFunc::gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer)
239 BOOST_ASSERT(lyx_view_);
240 if (!LyX::ref().session().bookmarks().isValid(idx))
242 BookmarksSection::Bookmark const & bm = LyX::ref().session().bookmarks().bookmark(idx);
243 BOOST_ASSERT(!bm.filename.empty());
244 string const file = bm.filename.absFilename();
245 // if the file is not opened, open it.
246 if (!theBufferList().exists(file)) {
248 dispatch(FuncRequest(LFUN_FILE_OPEN, file));
252 // open may fail, so we need to test it again
253 if (!theBufferList().exists(file))
256 // if the current buffer is not that one, switch to it.
257 if (lyx_view_->buffer()->absFileName() != file) {
260 dispatch(FuncRequest(LFUN_BUFFER_SWITCH, file));
262 // moveToPosition try paragraph id first and then paragraph (pit, pos).
263 if (!view()->moveToPosition(bm.bottom_pit, bm.bottom_pos,
264 bm.top_id, bm.top_pos))
267 // Cursor jump succeeded!
268 Cursor const & cur = view()->cursor();
269 pit_type new_pit = cur.pit();
270 pos_type new_pos = cur.pos();
271 int new_id = cur.paragraph().id();
273 // if bottom_pit, bottom_pos or top_id has been changed, update bookmark
274 // see http://bugzilla.lyx.org/show_bug.cgi?id=3092
275 if (bm.bottom_pit != new_pit || bm.bottom_pos != new_pos
276 || bm.top_id != new_id) {
277 const_cast<BookmarksSection::Bookmark &>(bm).updatePos(
278 new_pit, new_pos, new_id);
283 void LyXFunc::processKeySym(KeySymbol const & keysym, KeyModifier state)
285 LYXERR(Debug::KEY, "KeySym is " << keysym.getSymbolName());
287 // Do nothing if we have nothing (JMarc)
288 if (!keysym.isOK()) {
289 LYXERR(Debug::KEY, "Empty kbd action (probably composing)");
290 lyx_view_->restartCursor();
294 if (keysym.isModifier()) {
295 LYXERR(Debug::KEY, "isModifier true");
296 lyx_view_->restartCursor();
300 //Encoding const * encoding = view()->cursor().getEncoding();
301 //encoded_last_key = keysym.getISOEncoded(encoding ? encoding->name() : "");
302 // FIXME: encoded_last_key shadows the member variable of the same
303 // name. Is that intended?
304 char_type encoded_last_key = keysym.getUCSEncoded();
306 // Do a one-deep top-level lookup for
307 // cancel and meta-fake keys. RVDK_PATCH_5
308 cancel_meta_seq.reset();
310 FuncRequest func = cancel_meta_seq.addkey(keysym, state);
311 LYXERR(Debug::KEY, "action first set to [" << func.action << ']');
313 // When not cancel or meta-fake, do the normal lookup.
314 // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
315 // Mostly, meta_fake_bit = NoModifier. RVDK_PATCH_5.
316 if ((func.action != LFUN_CANCEL) && (func.action != LFUN_META_PREFIX)) {
317 // remove Caps Lock and Mod2 as a modifiers
318 func = keyseq.addkey(keysym, (state | meta_fake_bit));
319 LYXERR(Debug::KEY, "action now set to [" << func.action << ']');
322 // Dont remove this unless you know what you are doing.
323 meta_fake_bit = NoModifier;
325 // Can this happen now ?
326 if (func.action == LFUN_NOACTION)
327 func = FuncRequest(LFUN_COMMAND_PREFIX);
329 LYXERR(Debug::KEY, " Key [action=" << func.action << "]["
330 << keyseq.print(KeySequence::Portable) << ']');
332 // already here we know if it any point in going further
333 // why not return already here if action == -1 and
334 // num_bytes == 0? (Lgb)
336 if (keyseq.length() > 1)
337 lyx_view_->message(keyseq.print(KeySequence::ForGui));
340 // Maybe user can only reach the key via holding down shift.
341 // Let's see. But only if shift is the only modifier
342 if (func.action == LFUN_UNKNOWN_ACTION && state == ShiftModifier) {
343 LYXERR(Debug::KEY, "Trying without shift");
344 func = keyseq.addkey(keysym, NoModifier);
345 LYXERR(Debug::KEY, "Action now " << func.action);
348 if (func.action == LFUN_UNKNOWN_ACTION) {
349 // Hmm, we didn't match any of the keysequences. See
350 // if it's normal insertable text not already covered
352 if (keysym.isText() && keyseq.length() == 1) {
353 LYXERR(Debug::KEY, "isText() is true, inserting.");
354 func = FuncRequest(LFUN_SELF_INSERT,
355 FuncRequest::KEYBOARD);
357 LYXERR(Debug::KEY, "Unknown, !isText() - giving up");
358 lyx_view_->message(_("Unknown function."));
359 lyx_view_->restartCursor();
364 if (func.action == LFUN_SELF_INSERT) {
365 if (encoded_last_key != 0) {
366 docstring const arg(1, encoded_last_key);
367 dispatch(FuncRequest(LFUN_SELF_INSERT, arg,
368 FuncRequest::KEYBOARD));
369 LYXERR(Debug::KEY, "SelfInsert arg[`" << to_utf8(arg) << "']");
378 lyx_view_->restartCursor();
382 FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
384 //lyxerr << "LyXFunc::getStatus: cmd: " << cmd << endl;
387 Buffer * buf = lyx_view_? lyx_view_->buffer() : 0;
389 if (cmd.action == LFUN_NOACTION) {
390 flag.message(from_utf8(N_("Nothing to do")));
395 switch (cmd.action) {
396 case LFUN_UNKNOWN_ACTION:
397 #ifndef HAVE_LIBAIKSAURUS
398 case LFUN_THESAURUS_ENTRY:
408 if (flag.unknown()) {
409 flag.message(from_utf8(N_("Unknown action")));
413 if (!flag.enabled()) {
414 if (flag.message().empty())
415 flag.message(from_utf8(N_("Command disabled")));
419 // Check whether we need a buffer
420 if (!lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer) && !buf) {
422 flag.message(from_utf8(N_("Command not allowed with"
423 "out any document open")));
428 // I would really like to avoid having this switch and rather try to
429 // encode this in the function itself.
430 // -- And I'd rather let an inset decide which LFUNs it is willing
431 // to handle (Andre')
433 switch (cmd.action) {
435 // FIXME: these cases should be hidden in GuiApplication::getStatus().
436 case LFUN_WINDOW_CLOSE:
438 return theApp()->getStatus(cmd);
442 // FIXME: these cases should be hidden in GuiView::getStatus().
443 case LFUN_DIALOG_TOGGLE:
444 case LFUN_DIALOG_SHOW:
445 case LFUN_DIALOG_UPDATE:
446 if (cmd.argument() == "prefs"
447 || cmd.argument() == "aboutlyx")
450 return lyx_view_->getStatus(cmd);
455 case LFUN_TOOLBAR_TOGGLE:
456 case LFUN_INSET_APPLY:
457 case LFUN_BUFFER_WRITE:
458 case LFUN_BUFFER_WRITE_AS:
459 case LFUN_SPLIT_VIEW:
460 case LFUN_CLOSE_TAB_GROUP:
461 case LFUN_COMPLETION_POPUP:
462 case LFUN_COMPLETION_INLINE:
463 case LFUN_COMPLETION_COMPLETE:
465 return lyx_view_->getStatus(cmd);
469 case LFUN_BUFFER_TOGGLE_READ_ONLY:
470 flag.setOnOff(buf->isReadonly());
473 case LFUN_BUFFER_SWITCH:
474 // toggle on the current buffer, but do not toggle off
475 // the other ones (is that a good idea?)
476 if (buf && to_utf8(cmd.argument()) == buf->absFileName())
480 case LFUN_BUFFER_EXPORT:
481 enable = cmd.argument() == "custom"
482 || buf->isExportable(to_utf8(cmd.argument()));
485 case LFUN_BUFFER_CHKTEX:
486 enable = buf->isLatex() && !lyxrc.chktex_command.empty();
489 case LFUN_BUILD_PROGRAM:
490 enable = buf->isExportable("program");
493 case LFUN_VC_REGISTER:
494 enable = !buf->lyxvc().inUse();
496 case LFUN_VC_CHECK_IN:
497 enable = buf->lyxvc().inUse() && !buf->isReadonly();
499 case LFUN_VC_CHECK_OUT:
500 enable = buf->lyxvc().inUse() && buf->isReadonly();
503 case LFUN_VC_UNDO_LAST:
504 enable = buf->lyxvc().inUse();
506 case LFUN_BUFFER_RELOAD:
507 enable = !buf->isUnnamed() && buf->fileName().exists()
508 && (!buf->isClean() || buf->isExternallyModified(Buffer::timestamp_method));
511 case LFUN_CITATION_INSERT: {
512 FuncRequest fr(LFUN_INSET_INSERT, "citation");
513 enable = getStatus(fr).enabled();
517 // This could be used for the no-GUI version. The GUI version is handled in
518 // LyXView::getStatus(). See above.
520 case LFUN_BUFFER_WRITE:
521 case LFUN_BUFFER_WRITE_AS: {
522 Buffer * b = theBufferList().getBuffer(cmd.getArg(0));
523 enable = b && (b->isUnnamed() || !b->isClean());
528 case LFUN_BUFFER_WRITE_ALL: {
529 // We enable the command only if there are some modified buffers
530 Buffer * first = theBufferList().first();
535 // We cannot use a for loop as the buffer list is a cycle.
541 b = theBufferList().next(b);
542 } while (b != first);
546 case LFUN_BOOKMARK_GOTO: {
547 const unsigned int num = convert<unsigned int>(to_utf8(cmd.argument()));
548 enable = LyX::ref().session().bookmarks().isValid(num);
552 case LFUN_BOOKMARK_CLEAR:
553 enable = LyX::ref().session().bookmarks().size() > 0;
556 // this one is difficult to get right. As a half-baked
557 // solution, we consider only the first action of the sequence
558 case LFUN_COMMAND_SEQUENCE: {
559 // argument contains ';'-terminated commands
560 string const firstcmd = token(to_utf8(cmd.argument()), ';', 0);
561 FuncRequest func(lyxaction.lookupFunc(firstcmd));
562 func.origin = cmd.origin;
563 flag = getStatus(func);
569 string name = to_utf8(cmd.argument());
570 if (LyX::ref().topLevelCmdDef().lock(name, func)) {
571 func.origin = cmd.origin;
572 flag = getStatus(func);
573 LyX::ref().topLevelCmdDef().release(name);
575 // catch recursion or unknown command definiton
576 // all operations until the recursion or unknown command
577 // definiton occures are performed, so set the state to enabled
583 case LFUN_BUFFER_NEW:
584 case LFUN_BUFFER_NEW_TEMPLATE:
585 case LFUN_WORD_FIND_FORWARD:
586 case LFUN_WORD_FIND_BACKWARD:
587 case LFUN_COMMAND_PREFIX:
588 case LFUN_COMMAND_EXECUTE:
590 case LFUN_META_PREFIX:
591 case LFUN_BUFFER_CLOSE:
592 case LFUN_BUFFER_UPDATE:
593 case LFUN_BUFFER_VIEW:
594 case LFUN_MASTER_BUFFER_UPDATE:
595 case LFUN_MASTER_BUFFER_VIEW:
596 case LFUN_BUFFER_IMPORT:
597 case LFUN_BUFFER_AUTO_SAVE:
598 case LFUN_RECONFIGURE:
601 case LFUN_DROP_LAYOUTS_CHOICE:
603 case LFUN_SERVER_GET_NAME:
604 case LFUN_SERVER_NOTIFY:
605 case LFUN_SERVER_GOTO_FILE_ROW:
606 case LFUN_DIALOG_HIDE:
607 case LFUN_DIALOG_DISCONNECT_INSET:
608 case LFUN_BUFFER_CHILD_OPEN:
610 case LFUN_TOGGLE_CURSOR_FOLLOWS_SCROLLBAR:
611 case LFUN_KEYMAP_OFF:
612 case LFUN_KEYMAP_PRIMARY:
613 case LFUN_KEYMAP_SECONDARY:
614 case LFUN_KEYMAP_TOGGLE:
616 case LFUN_BUFFER_EXPORT_CUSTOM:
617 case LFUN_BUFFER_PRINT:
618 case LFUN_PREFERENCES_SAVE:
619 case LFUN_SCREEN_FONT_UPDATE:
622 case LFUN_EXTERNAL_EDIT:
623 case LFUN_GRAPHICS_EDIT:
624 case LFUN_ALL_INSETS_TOGGLE:
625 case LFUN_BUFFER_LANGUAGE:
626 case LFUN_TEXTCLASS_APPLY:
627 case LFUN_TEXTCLASS_LOAD:
628 case LFUN_BUFFER_SAVE_AS_DEFAULT:
629 case LFUN_BUFFER_PARAMS_APPLY:
630 case LFUN_LAYOUT_MODULES_CLEAR:
631 case LFUN_LAYOUT_MODULE_ADD:
632 case LFUN_LAYOUT_RELOAD:
633 case LFUN_LYXRC_APPLY:
634 case LFUN_BUFFER_NEXT:
635 case LFUN_BUFFER_PREVIOUS:
636 case LFUN_WINDOW_NEW:
638 // these are handled in our dispatch()
646 if (!getLocalStatus(view()->cursor(), cmd, flag))
647 flag = view()->getStatus(cmd);
653 // Can we use a readonly buffer?
654 if (buf && buf->isReadonly()
655 && !lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly)
656 && !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)) {
657 flag.message(from_utf8(N_("Document is read-only")));
661 // Are we in a DELETED change-tracking region?
663 && lookupChangeType(view()->cursor(), true) == Change::DELETED
664 && !lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly)
665 && !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)) {
666 flag.message(from_utf8(N_("This portion of the document is deleted.")));
670 // the default error message if we disable the command
671 if (!flag.enabled() && flag.message().empty())
672 flag.message(from_utf8(N_("Command disabled")));
678 bool LyXFunc::ensureBufferClean(BufferView * bv)
680 Buffer & buf = bv->buffer();
684 docstring const file = buf.fileName().displayName(30);
685 docstring text = bformat(_("The document %1$s has unsaved "
686 "changes.\n\nDo you want to save "
687 "the document?"), file);
688 int const ret = Alert::prompt(_("Save changed document?"),
689 text, 0, 1, _("&Save"),
693 dispatch(FuncRequest(LFUN_BUFFER_WRITE));
695 return buf.isClean();
701 void showPrintError(string const & name)
703 docstring str = bformat(_("Could not print the document %1$s.\n"
704 "Check that your printer is set up correctly."),
705 makeDisplayPath(name, 50));
706 Alert::error(_("Print document failed"), str);
710 bool loadLayoutFile(string const & name, string const & buf_path)
712 if (!BaseClassList::get().haveClass(name)) {
713 lyxerr << "Document class \"" << name
714 << "\" does not exist."
719 LayoutFile & tc = BaseClassList::get()[name];
720 if (!tc.load(buf_path)) {
721 docstring s = bformat(_("The document class %1$s."
722 "could not be loaded."), from_utf8(name));
723 Alert::error(_("Could not load class"), s);
730 void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new);
735 void LyXFunc::dispatch(FuncRequest const & cmd)
737 string const argument = to_utf8(cmd.argument());
738 kb_action const action = cmd.action;
740 LYXERR(Debug::ACTION, "\nLyXFunc::dispatch: cmd: " << cmd);
741 //lyxerr << "LyXFunc::dispatch: cmd: " << cmd << endl;
743 // we have not done anything wrong yet.
745 dispatch_buffer.erase();
747 // redraw the screen at the end (first of the two drawing steps).
748 //This is done unless explicitely requested otherwise
749 Update::flags updateFlags = Update::FitCursor;
751 FuncStatus const flag = getStatus(cmd);
752 if (!flag.enabled()) {
753 // We cannot use this function here
754 LYXERR(Debug::ACTION, "LyXFunc::dispatch: "
755 << lyxaction.getActionName(action)
756 << " [" << action << "] is disabled at this location");
757 setErrorMessage(flag.message());
761 case LFUN_WORD_FIND_FORWARD:
762 case LFUN_WORD_FIND_BACKWARD: {
763 BOOST_ASSERT(lyx_view_ && lyx_view_->view());
764 static docstring last_search;
765 docstring searched_string;
767 if (!cmd.argument().empty()) {
768 last_search = cmd.argument();
769 searched_string = cmd.argument();
771 searched_string = last_search;
774 if (searched_string.empty())
777 bool const fw = action == LFUN_WORD_FIND_FORWARD;
778 docstring const data =
779 find2string(searched_string, true, false, fw);
780 find(view(), FuncRequest(LFUN_WORD_FIND, data));
784 case LFUN_COMMAND_PREFIX:
785 BOOST_ASSERT(lyx_view_);
786 lyx_view_->message(keyseq.printOptions(true));
790 BOOST_ASSERT(lyx_view_ && lyx_view_->view());
792 meta_fake_bit = NoModifier;
793 if (lyx_view_->buffer())
794 // cancel any selection
795 dispatch(FuncRequest(LFUN_MARK_OFF));
796 setMessage(from_ascii(N_("Cancel")));
799 case LFUN_META_PREFIX:
800 meta_fake_bit = AltModifier;
801 setMessage(keyseq.print(KeySequence::ForGui));
804 case LFUN_BUFFER_TOGGLE_READ_ONLY: {
805 BOOST_ASSERT(lyx_view_ && lyx_view_->view() && lyx_view_->buffer());
806 Buffer * buf = lyx_view_->buffer();
807 if (buf->lyxvc().inUse())
808 buf->lyxvc().toggleReadOnly();
810 buf->setReadonly(!lyx_view_->buffer()->isReadonly());
814 // --- Menus -----------------------------------------------
815 case LFUN_BUFFER_NEW:
816 lyx_view_->newDocument(argument, false);
817 updateFlags = Update::None;
820 case LFUN_BUFFER_NEW_TEMPLATE:
821 lyx_view_->newDocument(argument, true);
822 updateFlags = Update::None;
825 case LFUN_BUFFER_CLOSE:
826 lyx_view_->closeBuffer();
827 updateFlags = Update::None;
830 case LFUN_BUFFER_RELOAD: {
831 BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
832 docstring const file = makeDisplayPath(lyx_view_->buffer()->absFileName(), 20);
833 docstring text = bformat(_("Any changes will be lost. Are you sure "
834 "you want to revert to the saved version of the document %1$s?"), file);
835 int const ret = Alert::prompt(_("Revert to saved document?"),
836 text, 1, 1, _("&Revert"), _("&Cancel"));
843 case LFUN_BUFFER_UPDATE:
844 BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
845 lyx_view_->buffer()->doExport(argument, true);
848 case LFUN_BUFFER_VIEW:
849 BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
850 lyx_view_->buffer()->preview(argument);
853 case LFUN_MASTER_BUFFER_UPDATE:
854 BOOST_ASSERT(lyx_view_ && lyx_view_->buffer() && lyx_view_->buffer()->masterBuffer());
855 lyx_view_->buffer()->masterBuffer()->doExport(argument, true);
858 case LFUN_MASTER_BUFFER_VIEW:
859 BOOST_ASSERT(lyx_view_ && lyx_view_->buffer() && lyx_view_->buffer()->masterBuffer());
860 lyx_view_->buffer()->masterBuffer()->preview(argument);
863 case LFUN_BUILD_PROGRAM:
864 BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
865 lyx_view_->buffer()->doExport("program", true);
868 case LFUN_BUFFER_CHKTEX:
869 BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
870 lyx_view_->buffer()->runChktex();
873 case LFUN_BUFFER_EXPORT:
874 BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
875 if (argument == "custom")
876 dispatch(FuncRequest(LFUN_DIALOG_SHOW, "sendto"));
878 lyx_view_->buffer()->doExport(argument, false);
881 case LFUN_BUFFER_EXPORT_CUSTOM: {
882 BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
884 string command = split(argument, format_name, ' ');
885 Format const * format = formats.getFormat(format_name);
887 lyxerr << "Format \"" << format_name
888 << "\" not recognized!"
893 Buffer * buffer = lyx_view_->buffer();
895 // The name of the file created by the conversion process
898 // Output to filename
899 if (format->name() == "lyx") {
900 string const latexname = buffer->latexName(false);
901 filename = changeExtension(latexname,
902 format->extension());
903 filename = addName(buffer->temppath(), filename);
905 if (!buffer->writeFile(FileName(filename)))
909 buffer->doExport(format_name, true, filename);
912 // Substitute $$FName for filename
913 if (!contains(command, "$$FName"))
914 command = "( " + command + " ) < $$FName";
915 command = subst(command, "$$FName", filename);
917 // Execute the command in the background
919 call.startscript(Systemcall::DontWait, command);
923 case LFUN_BUFFER_PRINT: {
924 BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
925 // FIXME: cmd.getArg() might fail if one of the arguments
926 // contains double quotes
927 string target = cmd.getArg(0);
928 string target_name = cmd.getArg(1);
929 string command = cmd.getArg(2);
932 || target_name.empty()
933 || command.empty()) {
934 lyxerr << "Unable to parse \""
935 << argument << '"' << endl;
938 if (target != "printer" && target != "file") {
939 lyxerr << "Unrecognized target \""
940 << target << '"' << endl;
944 Buffer * buffer = lyx_view_->buffer();
946 if (!buffer->doExport("dvi", true)) {
947 showPrintError(buffer->absFileName());
951 // Push directory path.
952 string const path = buffer->temppath();
953 // Prevent the compiler from optimizing away p
957 // there are three cases here:
958 // 1. we print to a file
959 // 2. we print directly to a printer
960 // 3. we print using a spool command (print to file first)
963 string const dviname =
964 changeExtension(buffer->latexName(true), "dvi");
966 if (target == "printer") {
967 if (!lyxrc.print_spool_command.empty()) {
968 // case 3: print using a spool
969 string const psname =
970 changeExtension(dviname,".ps");
971 command += ' ' + lyxrc.print_to_file
974 + quoteName(dviname);
977 lyxrc.print_spool_command + ' ';
978 if (target_name != "default") {
979 command2 += lyxrc.print_spool_printerprefix
983 command2 += quoteName(psname);
985 // If successful, then spool command
986 res = one.startscript(
991 res = one.startscript(
992 Systemcall::DontWait,
995 // case 2: print directly to a printer
996 if (target_name != "default")
997 command += ' ' + lyxrc.print_to_printer + target_name + ' ';
998 res = one.startscript(
999 Systemcall::DontWait,
1000 command + quoteName(dviname));
1004 // case 1: print to a file
1005 FileName const filename(makeAbsPath(target_name,
1006 lyx_view_->buffer()->filePath()));
1007 FileName const dvifile(makeAbsPath(dviname, path));
1008 if (filename.exists()) {
1009 docstring text = bformat(
1010 _("The file %1$s already exists.\n\n"
1011 "Do you want to overwrite that file?"),
1012 makeDisplayPath(filename.absFilename()));
1013 if (Alert::prompt(_("Overwrite file?"),
1014 text, 0, 1, _("&Overwrite"), _("&Cancel")) != 0)
1017 command += ' ' + lyxrc.print_to_file
1018 + quoteName(filename.toFilesystemEncoding())
1020 + quoteName(dvifile.toFilesystemEncoding());
1021 res = one.startscript(Systemcall::DontWait,
1026 showPrintError(buffer->absFileName());
1030 // FIXME: There is need for a command-line import.
1032 case LFUN_BUFFER_IMPORT:
1037 case LFUN_BUFFER_AUTO_SAVE:
1038 lyx_view_->buffer()->autoSave();
1041 case LFUN_RECONFIGURE:
1042 BOOST_ASSERT(lyx_view_);
1043 // argument is any additional parameter to the configure.py command
1044 reconfigure(*lyx_view_, argument);
1047 case LFUN_HELP_OPEN: {
1048 BOOST_ASSERT(lyx_view_);
1049 string const arg = argument;
1051 setErrorMessage(from_ascii(N_("Missing argument")));
1054 FileName const fname = i18nLibFileSearch("doc", arg, "lyx");
1055 if (fname.empty()) {
1056 lyxerr << "LyX: unable to find documentation file `"
1057 << arg << "'. Bad installation?" << endl;
1060 lyx_view_->message(bformat(_("Opening help file %1$s..."),
1061 makeDisplayPath(fname.absFilename())));
1062 Buffer * buf = lyx_view_->loadDocument(fname, false);
1065 lyx_view_->setBuffer(buf);
1066 buf->errors("Parse");
1068 updateFlags = Update::None;
1072 // --- version control -------------------------------
1073 case LFUN_VC_REGISTER:
1074 BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
1075 if (!ensureBufferClean(view()))
1077 if (!lyx_view_->buffer()->lyxvc().inUse()) {
1078 lyx_view_->buffer()->lyxvc().registrer();
1081 updateFlags = Update::Force;
1084 case LFUN_VC_CHECK_IN:
1085 BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
1086 if (!ensureBufferClean(view()))
1088 if (lyx_view_->buffer()->lyxvc().inUse()
1089 && !lyx_view_->buffer()->isReadonly()) {
1090 lyx_view_->buffer()->lyxvc().checkIn();
1095 case LFUN_VC_CHECK_OUT:
1096 BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
1097 if (!ensureBufferClean(view()))
1099 if (lyx_view_->buffer()->lyxvc().inUse()
1100 && lyx_view_->buffer()->isReadonly()) {
1101 lyx_view_->buffer()->lyxvc().checkOut();
1106 case LFUN_VC_REVERT:
1107 BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
1108 lyx_view_->buffer()->lyxvc().revert();
1112 case LFUN_VC_UNDO_LAST:
1113 BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
1114 lyx_view_->buffer()->lyxvc().undoLast();
1118 // --- lyxserver commands ----------------------------
1119 case LFUN_SERVER_GET_NAME:
1120 BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
1121 setMessage(from_utf8(lyx_view_->buffer()->absFileName()));
1122 LYXERR(Debug::INFO, "FNAME["
1123 << lyx_view_->buffer()->absFileName() << ']');
1126 case LFUN_SERVER_NOTIFY:
1127 dispatch_buffer = keyseq.print(KeySequence::Portable);
1128 theServer().notifyClient(to_utf8(dispatch_buffer));
1131 case LFUN_SERVER_GOTO_FILE_ROW: {
1132 BOOST_ASSERT(lyx_view_);
1135 istringstream is(argument);
1136 is >> file_name >> row;
1138 bool loaded = false;
1139 if (prefixIs(file_name, package().temp_dir().absFilename()))
1140 // Needed by inverse dvi search. If it is a file
1141 // in tmpdir, call the apropriated function
1142 buf = theBufferList().getBufferFromTmp(file_name);
1144 // Must replace extension of the file to be .lyx
1145 // and get full path
1146 FileName const s = fileSearch(string(), changeExtension(file_name, ".lyx"), "lyx");
1147 // Either change buffer or load the file
1148 if (theBufferList().exists(s.absFilename()))
1149 buf = theBufferList().getBuffer(s.absFilename());
1151 buf = lyx_view_->loadDocument(s);
1157 updateFlags = Update::None;
1162 lyx_view_->setBuffer(buf);
1163 view()->setCursorFromRow(row);
1165 buf->errors("Parse");
1166 updateFlags = Update::FitCursor;
1171 case LFUN_DIALOG_SHOW_NEW_INSET: {
1172 BOOST_ASSERT(lyx_view_);
1173 string const name = cmd.getArg(0);
1174 InsetCode code = insetCode(name);
1175 string data = trim(to_utf8(cmd.argument()).substr(name.size()));
1176 bool insetCodeOK = true;
1185 case HYPERLINK_CODE: {
1186 InsetCommandParams p(code);
1187 data = InsetCommandMailer::params2string(name, p);
1190 case INCLUDE_CODE: {
1191 // data is the include type: one of "include",
1192 // "input", "verbatiminput" or "verbatiminput*"
1194 // default type is requested
1196 InsetCommandParams p(INCLUDE_CODE, data);
1197 data = InsetCommandMailer::params2string("include", p);
1201 // \c data == "Boxed" || "Frameless" etc
1202 InsetBoxParams p(data);
1203 data = InsetBoxMailer::params2string(p);
1207 InsetBranchParams p;
1208 data = InsetBranchMailer::params2string(p);
1212 InsetCommandParams p(CITE_CODE);
1213 data = InsetCommandMailer::params2string(name, p);
1217 data = InsetERTMailer::params2string(InsetCollapsable::Open);
1220 case EXTERNAL_CODE: {
1221 InsetExternalParams p;
1222 Buffer const & buffer = *lyx_view_->buffer();
1223 data = InsetExternalMailer::params2string(p, buffer);
1228 data = InsetFloatMailer::params2string(p);
1231 case LISTINGS_CODE: {
1232 InsetListingsParams p;
1233 data = InsetListingsMailer::params2string(p);
1236 case GRAPHICS_CODE: {
1237 InsetGraphicsParams p;
1238 Buffer const & buffer = *lyx_view_->buffer();
1239 data = InsetGraphicsMailer::params2string(p, buffer);
1244 data = InsetNoteMailer::params2string(p);
1249 data = InsetVSpaceMailer::params2string(space);
1254 data = InsetWrapMailer::params2string(p);
1258 lyxerr << "Inset type '" << name <<
1259 "' not recognized in LFUN_DIALOG_SHOW_NEW_INSET" << endl;
1260 insetCodeOK = false;
1262 } // end switch(code)
1264 dispatch(FuncRequest(LFUN_DIALOG_SHOW, name + " " + data));
1268 case LFUN_CITATION_INSERT: {
1269 BOOST_ASSERT(lyx_view_);
1270 if (!argument.empty()) {
1271 // we can have one optional argument, delimited by '|'
1272 // citation-insert <key>|<text_before>
1273 // this should be enhanced to also support text_after
1274 // and citation style
1275 string arg = argument;
1277 if (contains(argument, "|")) {
1278 arg = token(argument, '|', 0);
1279 opt1 = token(argument, '|', 1);
1281 InsetCommandParams icp(CITE_CODE);
1282 icp["key"] = from_utf8(arg);
1284 icp["before"] = from_utf8(opt1);
1285 string icstr = InsetCommandMailer::params2string("citation", icp);
1286 FuncRequest fr(LFUN_INSET_INSERT, icstr);
1289 dispatch(FuncRequest(LFUN_DIALOG_SHOW_NEW_INSET, "citation"));
1293 case LFUN_BUFFER_CHILD_OPEN: {
1294 BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
1295 Buffer * parent = lyx_view_->buffer();
1296 FileName filename = makeAbsPath(argument, parent->filePath());
1297 view()->saveBookmark(false);
1299 bool parsed = false;
1300 if (theBufferList().exists(filename.absFilename())) {
1301 child = theBufferList().getBuffer(filename.absFilename());
1303 setMessage(bformat(_("Opening child document %1$s..."),
1304 makeDisplayPath(filename.absFilename())));
1305 child = lyx_view_->loadDocument(filename, false);
1309 // Set the parent name of the child document.
1310 // This makes insertion of citations and references in the child work,
1311 // when the target is in the parent or another child document.
1312 child->setParent(parent);
1313 updateLabels(*child->masterBuffer());
1314 lyx_view_->setBuffer(child);
1316 child->errors("Parse");
1319 // If a screen update is required (in case where auto_open is false),
1320 // setBuffer() would have taken care of it already. Otherwise we shall
1321 // reset the update flag because it can cause a circular problem.
1323 updateFlags = Update::None;
1327 case LFUN_TOGGLE_CURSOR_FOLLOWS_SCROLLBAR:
1328 BOOST_ASSERT(lyx_view_);
1329 lyxrc.cursor_follows_scrollbar = !lyxrc.cursor_follows_scrollbar;
1332 case LFUN_KEYMAP_OFF:
1333 BOOST_ASSERT(lyx_view_ && lyx_view_->view());
1334 lyx_view_->view()->getIntl().keyMapOn(false);
1337 case LFUN_KEYMAP_PRIMARY:
1338 BOOST_ASSERT(lyx_view_ && lyx_view_->view());
1339 lyx_view_->view()->getIntl().keyMapPrim();
1342 case LFUN_KEYMAP_SECONDARY:
1343 BOOST_ASSERT(lyx_view_ && lyx_view_->view());
1344 lyx_view_->view()->getIntl().keyMapSec();
1347 case LFUN_KEYMAP_TOGGLE:
1348 BOOST_ASSERT(lyx_view_ && lyx_view_->view());
1349 lyx_view_->view()->getIntl().toggleKeyMap();
1355 string rest = split(argument, countstr, ' ');
1356 istringstream is(countstr);
1359 lyxerr << "repeat: count: " << count << " cmd: " << rest << endl;
1360 for (int i = 0; i < count; ++i)
1361 dispatch(lyxaction.lookupFunc(rest));
1365 case LFUN_COMMAND_SEQUENCE: {
1366 // argument contains ';'-terminated commands
1367 string arg = argument;
1368 while (!arg.empty()) {
1370 arg = split(arg, first, ';');
1371 FuncRequest func(lyxaction.lookupFunc(first));
1372 func.origin = cmd.origin;
1380 if (LyX::ref().topLevelCmdDef().lock(argument, func)) {
1381 func.origin = cmd.origin;
1383 LyX::ref().topLevelCmdDef().release(argument);
1385 if (func.action == LFUN_UNKNOWN_ACTION) {
1386 // unknown command definition
1387 lyxerr << "Warning: unknown command definition `"
1391 // recursion detected
1392 lyxerr << "Warning: Recursion in the command definition `"
1393 << argument << "' detected"
1400 case LFUN_PREFERENCES_SAVE: {
1401 lyxrc.write(makeAbsPath("preferences",
1402 package().user_support().absFilename()),
1407 case LFUN_SET_COLOR: {
1409 string const x11_name = split(argument, lyx_name, ' ');
1410 if (lyx_name.empty() || x11_name.empty()) {
1411 setErrorMessage(from_ascii(N_(
1412 "Syntax: set-color <lyx_name>"
1417 bool const graphicsbg_changed =
1418 (lyx_name == lcolor.getLyXName(Color_graphicsbg) &&
1419 x11_name != lcolor.getX11Name(Color_graphicsbg));
1421 if (!lcolor.setColor(lyx_name, x11_name)) {
1423 bformat(_("Set-color \"%1$s\" failed "
1424 "- color is undefined or "
1425 "may not be redefined"),
1426 from_utf8(lyx_name)));
1430 theApp()->updateColor(lcolor.getFromLyXName(lyx_name));
1432 if (graphicsbg_changed) {
1433 // FIXME: The graphics cache no longer has a changeDisplay method.
1435 graphics::GCache::get().changeDisplay(true);
1442 BOOST_ASSERT(lyx_view_);
1443 lyx_view_->message(from_utf8(argument));
1446 case LFUN_EXTERNAL_EDIT: {
1447 BOOST_ASSERT(lyx_view_);
1448 FuncRequest fr(action, argument);
1449 InsetExternal().dispatch(view()->cursor(), fr);
1453 case LFUN_GRAPHICS_EDIT: {
1454 FuncRequest fr(action, argument);
1455 InsetGraphics().dispatch(view()->cursor(), fr);
1459 case LFUN_ALL_INSETS_TOGGLE: {
1460 BOOST_ASSERT(lyx_view_);
1462 string const name = split(argument, action, ' ');
1463 InsetCode const inset_code = insetCode(name);
1465 Cursor & cur = view()->cursor();
1466 FuncRequest fr(LFUN_INSET_TOGGLE, action);
1468 Inset & inset = lyx_view_->buffer()->inset();
1469 InsetIterator it = inset_iterator_begin(inset);
1470 InsetIterator const end = inset_iterator_end(inset);
1471 for (; it != end; ++it) {
1472 if (!it->asInsetMath()
1473 && (inset_code == NO_CODE
1474 || inset_code == it->lyxCode())) {
1475 Cursor tmpcur = cur;
1476 tmpcur.pushBackward(*it);
1477 it->dispatch(tmpcur, fr);
1480 updateFlags = Update::Force | Update::FitCursor;
1484 case LFUN_BUFFER_LANGUAGE: {
1485 BOOST_ASSERT(lyx_view_);
1486 Buffer & buffer = *lyx_view_->buffer();
1487 Language const * oldL = buffer.params().language;
1488 Language const * newL = languages.getLanguage(argument);
1489 if (!newL || oldL == newL)
1492 if (oldL->rightToLeft() == newL->rightToLeft()
1493 && !buffer.isMultiLingual())
1494 buffer.changeLanguage(oldL, newL);
1498 case LFUN_BUFFER_SAVE_AS_DEFAULT: {
1499 string const fname =
1500 addName(addPath(package().user_support().absFilename(), "templates/"),
1502 Buffer defaults(fname);
1504 istringstream ss(argument);
1507 int const unknown_tokens = defaults.readHeader(lex);
1509 if (unknown_tokens != 0) {
1510 lyxerr << "Warning in LFUN_BUFFER_SAVE_AS_DEFAULT!\n"
1511 << unknown_tokens << " unknown token"
1512 << (unknown_tokens == 1 ? "" : "s")
1516 if (defaults.writeFile(FileName(defaults.absFileName())))
1517 setMessage(bformat(_("Document defaults saved in %1$s"),
1518 makeDisplayPath(fname)));
1520 setErrorMessage(from_ascii(N_("Unable to save document defaults")));
1524 case LFUN_BUFFER_PARAMS_APPLY: {
1525 BOOST_ASSERT(lyx_view_);
1526 biblio::CiteEngine const oldEngine =
1527 lyx_view_->buffer()->params().getEngine();
1529 Buffer * buffer = lyx_view_->buffer();
1531 DocumentClass * oldClass = buffer->params().documentClassPtr();
1533 Cursor & cur = view()->cursor();
1534 cur.recordUndoFullDocument();
1536 istringstream ss(argument);
1539 int const unknown_tokens = buffer->readHeader(lex);
1541 if (unknown_tokens != 0) {
1542 lyxerr << "Warning in LFUN_BUFFER_PARAMS_APPLY!\n"
1543 << unknown_tokens << " unknown token"
1544 << (unknown_tokens == 1 ? "" : "s")
1548 updateLayout(oldClass, buffer);
1550 biblio::CiteEngine const newEngine =
1551 lyx_view_->buffer()->params().getEngine();
1553 updateFlags = Update::Force | Update::FitCursor;
1554 // We are here most certainaly because of a change in the document
1555 // It is then better to make sure that all dialogs are in sync
1556 // with current document settings. LyXView::restartCursor() achieve this.
1557 lyx_view_->restartCursor();
1561 case LFUN_LAYOUT_MODULES_CLEAR: {
1562 BOOST_ASSERT(lyx_view_);
1563 Buffer * buffer = lyx_view_->buffer();
1564 DocumentClass * oldClass = buffer->params().documentClassPtr();
1565 view()->cursor().recordUndoFullDocument();
1566 buffer->params().clearLayoutModules();
1567 buffer->params().makeDocumentClass();
1568 updateLayout(oldClass, buffer);
1569 updateFlags = Update::Force | Update::FitCursor;
1573 case LFUN_LAYOUT_MODULE_ADD: {
1574 BOOST_ASSERT(lyx_view_);
1575 Buffer * buffer = lyx_view_->buffer();
1576 DocumentClass * oldClass = buffer->params().documentClassPtr();
1577 view()->cursor().recordUndoFullDocument();
1578 buffer->params().addLayoutModule(argument);
1579 buffer->params().makeDocumentClass();
1580 updateLayout(oldClass, buffer);
1581 updateFlags = Update::Force | Update::FitCursor;
1585 case LFUN_TEXTCLASS_APPLY: {
1586 BOOST_ASSERT(lyx_view_);
1587 Buffer * buffer = lyx_view_->buffer();
1589 if (!loadLayoutFile(argument, buffer->filePath()))
1592 LayoutFile const * old_layout = buffer->params().baseClass();
1593 LayoutFile const * new_layout = &(BaseClassList::get()[argument]);
1595 if (old_layout == new_layout)
1599 //Save the old, possibly modular, layout for use in conversion.
1600 DocumentClass * oldDocClass = buffer->params().documentClassPtr();
1601 view()->cursor().recordUndoFullDocument();
1602 buffer->params().setBaseClass(argument);
1603 buffer->params().makeDocumentClass();
1604 updateLayout(oldDocClass, buffer);
1605 updateFlags = Update::Force | Update::FitCursor;
1609 case LFUN_LAYOUT_RELOAD: {
1610 BOOST_ASSERT(lyx_view_);
1611 Buffer * buffer = lyx_view_->buffer();
1612 DocumentClass * oldClass = buffer->params().documentClassPtr();
1613 LayoutFileIndex bc = buffer->params().baseClassID();
1614 BaseClassList::get().reset(bc);
1615 buffer->params().makeDocumentClass();
1616 updateLayout(oldClass, buffer);
1617 updateFlags = Update::Force | Update::FitCursor;
1621 case LFUN_TEXTCLASS_LOAD:
1622 loadLayoutFile(argument, lyx_view_->buffer()->filePath());
1625 case LFUN_LYXRC_APPLY: {
1626 LyXRC const lyxrc_orig = lyxrc;
1628 istringstream ss(argument);
1629 bool const success = lyxrc.read(ss) == 0;
1632 lyxerr << "Warning in LFUN_LYXRC_APPLY!\n"
1633 << "Unable to read lyxrc data"
1638 actOnUpdatedPrefs(lyxrc_orig, lyxrc);
1640 theApp()->resetGui();
1642 /// We force the redraw in any case because there might be
1643 /// some screen font changes.
1644 /// FIXME: only the current view will be updated. the Gui
1645 /// class is able to furnish the list of views.
1646 updateFlags = Update::Force;
1650 case LFUN_BOOKMARK_GOTO:
1651 // go to bookmark, open unopened file and switch to buffer if necessary
1652 gotoBookmark(convert<unsigned int>(to_utf8(cmd.argument())), true, true);
1653 updateFlags = Update::FitCursor;
1656 case LFUN_BOOKMARK_CLEAR:
1657 LyX::ref().session().bookmarks().clear();
1661 BOOST_ASSERT(theApp());
1662 // Let the frontend dispatch its own actions.
1663 if (theApp()->dispatch(cmd))
1664 // Nothing more to do.
1667 // Let the current LyXView dispatch its own actions.
1668 BOOST_ASSERT(lyx_view_);
1669 if (lyx_view_->dispatch(cmd)) {
1670 if (lyx_view_->view())
1671 updateFlags = lyx_view_->view()->cursor().result().update();
1675 BOOST_ASSERT(lyx_view_->view());
1676 // Let the current BufferView dispatch its own actions.
1677 if (view()->dispatch(cmd)) {
1678 // The BufferView took care of its own updates if needed.
1679 updateFlags = Update::None;
1683 // Let the current Cursor dispatch its own actions.
1684 Cursor old = view()->cursor();
1685 view()->cursor().getPos(cursorPosBeforeDispatchX_,
1686 cursorPosBeforeDispatchY_);
1687 view()->cursor().dispatch(cmd);
1689 // notify insets we just left
1690 if (view()->cursor() != old) {
1692 bool badcursor = notifyCursorLeaves(old, view()->cursor());
1694 view()->cursor().fixIfBroken();
1697 // update completion. We do it here and not in
1698 // processKeySym to avoid another redraw just for a
1699 // changed inline completion
1700 if (cmd.origin == FuncRequest::KEYBOARD) {
1701 if (cmd.action == LFUN_SELF_INSERT)
1702 lyx_view_->updateCompletion(view()->cursor(), true, true);
1703 else if (cmd.action == LFUN_CHAR_DELETE_BACKWARD)
1704 lyx_view_->updateCompletion(view()->cursor(), false, true);
1706 lyx_view_->updateCompletion(view()->cursor(), false, false);
1709 updateFlags = view()->cursor().result().update();
1712 if (lyx_view_ && lyx_view_->buffer()) {
1713 // BufferView::update() updates the ViewMetricsInfo and
1714 // also initializes the position cache for all insets in
1715 // (at least partially) visible top-level paragraphs.
1716 // We will redraw the screen only if needed.
1717 view()->processUpdateFlags(updateFlags);
1719 // if we executed a mutating lfun, mark the buffer as dirty
1721 && !lyxaction.funcHasFlag(action, LyXAction::NoBuffer)
1722 && !lyxaction.funcHasFlag(action, LyXAction::ReadOnly))
1723 lyx_view_->buffer()->markDirty();
1725 //Do we have a selection?
1726 theSelection().haveSelection(view()->cursor().selection());
1730 // Some messages may already be translated, so we cannot use _()
1731 sendDispatchMessage(translateIfPossible(getMessage()), cmd);
1736 void LyXFunc::sendDispatchMessage(docstring const & msg, FuncRequest const & cmd)
1738 const bool verbose = (cmd.origin == FuncRequest::MENU
1739 || cmd.origin == FuncRequest::TOOLBAR
1740 || cmd.origin == FuncRequest::COMMANDBUFFER);
1742 if (cmd.action == LFUN_SELF_INSERT || !verbose) {
1743 LYXERR(Debug::ACTION, "dispatch msg is " << to_utf8(msg));
1745 lyx_view_->message(msg);
1749 docstring dispatch_msg = msg;
1750 if (!dispatch_msg.empty())
1751 dispatch_msg += ' ';
1753 docstring comname = from_utf8(lyxaction.getActionName(cmd.action));
1755 bool argsadded = false;
1757 if (!cmd.argument().empty()) {
1758 if (cmd.action != LFUN_UNKNOWN_ACTION) {
1759 comname += ' ' + cmd.argument();
1764 docstring const shortcuts = theTopLevelKeymap().printBindings(cmd);
1766 if (!shortcuts.empty())
1767 comname += ": " + shortcuts;
1768 else if (!argsadded && !cmd.argument().empty())
1769 comname += ' ' + cmd.argument();
1771 if (!comname.empty()) {
1772 comname = rtrim(comname);
1773 dispatch_msg += '(' + rtrim(comname) + ')';
1776 LYXERR(Debug::ACTION, "verbose dispatch msg " << to_utf8(dispatch_msg));
1777 if (!dispatch_msg.empty())
1778 lyx_view_->message(dispatch_msg);
1782 void LyXFunc::reloadBuffer()
1784 FileName filename = lyx_view_->buffer()->fileName();
1785 // The user has already confirmed that the changes, if any, should
1786 // be discarded. So we just release the Buffer and don't call closeBuffer();
1787 theBufferList().release(lyx_view_->buffer());
1788 Buffer * buf = lyx_view_->loadDocument(filename);
1789 docstring const disp_fn = makeDisplayPath(filename.absFilename());
1793 lyx_view_->setBuffer(buf);
1794 buf->errors("Parse");
1795 str = bformat(_("Document %1$s reloaded."), disp_fn);
1797 str = bformat(_("Could not reload document %1$s"), disp_fn);
1799 lyx_view_->message(str);
1802 // Each "lyx_view_" should have it's own message method. lyxview and
1803 // the minibuffer would use the minibuffer, but lyxserver would
1804 // send an ERROR signal to its client. Alejandro 970603
1805 // This function is bit problematic when it comes to NLS, to make the
1806 // lyx servers client be language indepenent we must not translate
1807 // strings sent to this func.
1808 void LyXFunc::setErrorMessage(docstring const & m) const
1810 dispatch_buffer = m;
1815 void LyXFunc::setMessage(docstring const & m) const
1817 dispatch_buffer = m;
1821 docstring const LyXFunc::viewStatusMessage()
1823 // When meta-fake key is pressed, show the key sequence so far + "M-".
1825 return keyseq.print(KeySequence::ForGui) + "M-";
1827 // Else, when a non-complete key sequence is pressed,
1828 // show the available options.
1829 if (keyseq.length() > 0 && !keyseq.deleted())
1830 return keyseq.printOptions(true);
1832 BOOST_ASSERT(lyx_view_);
1833 if (!lyx_view_->buffer())
1834 return _("Welcome to LyX!");
1836 return view()->cursor().currentState();
1840 BufferView * LyXFunc::view() const
1842 BOOST_ASSERT(lyx_view_);
1843 return lyx_view_->view();
1847 bool LyXFunc::wasMetaKey() const
1849 return (meta_fake_bit != NoModifier);
1853 void LyXFunc::updateLayout(DocumentClass * oldlayout,Buffer * buffer)
1855 lyx_view_->message(_("Converting document to new document class..."));
1857 StableDocIterator backcur(view()->cursor());
1858 ErrorList & el = buffer->errorList("Class Switch");
1859 cap::switchBetweenClasses(
1860 oldlayout, buffer->params().documentClassPtr(),
1861 static_cast<InsetText &>(buffer->inset()), el);
1863 view()->setCursor(backcur.asDocIterator(&(buffer->inset())));
1865 buffer->errors("Class Switch");
1866 updateLabels(*buffer);
1872 void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
1874 // Why the switch you might ask. It is a trick to ensure that all
1875 // the elements in the LyXRCTags enum is handled. As you can see
1876 // there are no breaks at all. So it is just a huge fall-through.
1877 // The nice thing is that we will get a warning from the compiler
1878 // if we forget an element.
1879 LyXRC::LyXRCTags tag = LyXRC::RC_LAST;
1881 case LyXRC::RC_ACCEPT_COMPOUND:
1882 case LyXRC::RC_ALT_LANG:
1883 case LyXRC::RC_PLAINTEXT_ROFF_COMMAND:
1884 case LyXRC::RC_PLAINTEXT_LINELEN:
1885 case LyXRC::RC_AUTOREGIONDELETE:
1886 case LyXRC::RC_AUTORESET_OPTIONS:
1887 case LyXRC::RC_AUTOSAVE:
1888 case LyXRC::RC_AUTO_NUMBER:
1889 case LyXRC::RC_BACKUPDIR_PATH:
1890 case LyXRC::RC_BIBTEX_COMMAND:
1891 case LyXRC::RC_BINDFILE:
1892 case LyXRC::RC_CHECKLASTFILES:
1893 case LyXRC::RC_COMPLETION_INLINE_DELAY:
1894 case LyXRC::RC_COMPLETION_INLINE_DOTS:
1895 case LyXRC::RC_COMPLETION_INLINE_MATH:
1896 case LyXRC::RC_COMPLETION_INLINE_TEXT:
1897 case LyXRC::RC_COMPLETION_POPUP_AFTER_COMPLETE:
1898 case LyXRC::RC_COMPLETION_POPUP_DELAY:
1899 case LyXRC::RC_COMPLETION_POPUP_MATH:
1900 case LyXRC::RC_COMPLETION_POPUP_TEXT:
1901 case LyXRC::RC_USELASTFILEPOS:
1902 case LyXRC::RC_LOADSESSION:
1903 case LyXRC::RC_CHKTEX_COMMAND:
1904 case LyXRC::RC_CONVERTER:
1905 case LyXRC::RC_CONVERTER_CACHE_MAXAGE:
1906 case LyXRC::RC_COPIER:
1907 case LyXRC::RC_CURSOR_FOLLOWS_SCROLLBAR:
1908 case LyXRC::RC_CUSTOM_EXPORT_COMMAND:
1909 case LyXRC::RC_CUSTOM_EXPORT_FORMAT:
1910 case LyXRC::RC_DATE_INSERT_FORMAT:
1911 case LyXRC::RC_DEFAULT_LANGUAGE:
1912 case LyXRC::RC_DEFAULT_PAPERSIZE:
1913 case LyXRC::RC_DEFFILE:
1914 case LyXRC::RC_DIALOGS_ICONIFY_WITH_MAIN:
1915 case LyXRC::RC_DISPLAY_GRAPHICS:
1916 case LyXRC::RC_DOCUMENTPATH:
1917 if (lyxrc_orig.document_path != lyxrc_new.document_path) {
1918 FileName path(lyxrc_new.document_path);
1919 if (path.exists() && path.isDirectory())
1920 package().document_dir() = FileName(lyxrc.document_path);
1922 case LyXRC::RC_ESC_CHARS:
1923 case LyXRC::RC_EXAMPLEPATH:
1924 case LyXRC::RC_FONT_ENCODING:
1925 case LyXRC::RC_FORMAT:
1926 case LyXRC::RC_INDEX_COMMAND:
1927 case LyXRC::RC_INPUT:
1928 case LyXRC::RC_KBMAP:
1929 case LyXRC::RC_KBMAP_PRIMARY:
1930 case LyXRC::RC_KBMAP_SECONDARY:
1931 case LyXRC::RC_LABEL_INIT_LENGTH:
1932 case LyXRC::RC_LANGUAGE_AUTO_BEGIN:
1933 case LyXRC::RC_LANGUAGE_AUTO_END:
1934 case LyXRC::RC_LANGUAGE_COMMAND_BEGIN:
1935 case LyXRC::RC_LANGUAGE_COMMAND_END:
1936 case LyXRC::RC_LANGUAGE_COMMAND_LOCAL:
1937 case LyXRC::RC_LANGUAGE_GLOBAL_OPTIONS:
1938 case LyXRC::RC_LANGUAGE_PACKAGE:
1939 case LyXRC::RC_LANGUAGE_USE_BABEL:
1940 case LyXRC::RC_MACRO_EDIT_STYLE:
1941 case LyXRC::RC_MAKE_BACKUP:
1942 case LyXRC::RC_MARK_FOREIGN_LANGUAGE:
1943 case LyXRC::RC_MOUSE_WHEEL_SPEED:
1944 case LyXRC::RC_NUMLASTFILES:
1945 case LyXRC::RC_PATH_PREFIX:
1946 if (lyxrc_orig.path_prefix != lyxrc_new.path_prefix) {
1947 prependEnvPath("PATH", lyxrc.path_prefix);
1949 case LyXRC::RC_PERS_DICT:
1950 case LyXRC::RC_PREVIEW:
1951 case LyXRC::RC_PREVIEW_HASHED_LABELS:
1952 case LyXRC::RC_PREVIEW_SCALE_FACTOR:
1953 case LyXRC::RC_PRINTCOLLCOPIESFLAG:
1954 case LyXRC::RC_PRINTCOPIESFLAG:
1955 case LyXRC::RC_PRINTER:
1956 case LyXRC::RC_PRINTEVENPAGEFLAG:
1957 case LyXRC::RC_PRINTEXSTRAOPTIONS:
1958 case LyXRC::RC_PRINTFILEEXTENSION:
1959 case LyXRC::RC_PRINTLANDSCAPEFLAG:
1960 case LyXRC::RC_PRINTODDPAGEFLAG:
1961 case LyXRC::RC_PRINTPAGERANGEFLAG:
1962 case LyXRC::RC_PRINTPAPERDIMENSIONFLAG:
1963 case LyXRC::RC_PRINTPAPERFLAG:
1964 case LyXRC::RC_PRINTREVERSEFLAG:
1965 case LyXRC::RC_PRINTSPOOL_COMMAND:
1966 case LyXRC::RC_PRINTSPOOL_PRINTERPREFIX:
1967 case LyXRC::RC_PRINTTOFILE:
1968 case LyXRC::RC_PRINTTOPRINTER:
1969 case LyXRC::RC_PRINT_ADAPTOUTPUT:
1970 case LyXRC::RC_PRINT_COMMAND:
1971 case LyXRC::RC_RTL_SUPPORT:
1972 case LyXRC::RC_SCREEN_DPI:
1973 case LyXRC::RC_SCREEN_FONT_ROMAN:
1974 case LyXRC::RC_SCREEN_FONT_ROMAN_FOUNDRY:
1975 case LyXRC::RC_SCREEN_FONT_SANS:
1976 case LyXRC::RC_SCREEN_FONT_SANS_FOUNDRY:
1977 case LyXRC::RC_SCREEN_FONT_SCALABLE:
1978 case LyXRC::RC_SCREEN_FONT_SIZES:
1979 case LyXRC::RC_SCREEN_FONT_TYPEWRITER:
1980 case LyXRC::RC_SCREEN_FONT_TYPEWRITER_FOUNDRY:
1981 case LyXRC::RC_GEOMETRY_SESSION:
1982 case LyXRC::RC_SCREEN_ZOOM:
1983 case LyXRC::RC_SERVERPIPE:
1984 case LyXRC::RC_SET_COLOR:
1985 case LyXRC::RC_SHOW_BANNER:
1986 case LyXRC::RC_SPELL_COMMAND:
1987 case LyXRC::RC_TEMPDIRPATH:
1988 case LyXRC::RC_TEMPLATEPATH:
1989 case LyXRC::RC_TEX_ALLOWS_SPACES:
1990 case LyXRC::RC_TEX_EXPECTS_WINDOWS_PATHS:
1991 if (lyxrc_orig.windows_style_tex_paths != lyxrc_new.windows_style_tex_paths) {
1992 os::windows_style_tex_paths(lyxrc_new.windows_style_tex_paths);
1994 case LyXRC::RC_UIFILE:
1995 case LyXRC::RC_USER_EMAIL:
1996 case LyXRC::RC_USER_NAME:
1997 case LyXRC::RC_USETEMPDIR:
1998 case LyXRC::RC_USE_ALT_LANG:
1999 case LyXRC::RC_USE_CONVERTER_CACHE:
2000 case LyXRC::RC_USE_ESC_CHARS:
2001 case LyXRC::RC_USE_INP_ENC:
2002 case LyXRC::RC_USE_PERS_DICT:
2003 case LyXRC::RC_USE_TOOLTIP:
2004 case LyXRC::RC_USE_PIXMAP_CACHE:
2005 case LyXRC::RC_USE_SPELL_LIB:
2006 case LyXRC::RC_VIEWDVI_PAPEROPTION:
2007 case LyXRC::RC_SORT_LAYOUTS:
2008 case LyXRC::RC_FULL_SCREEN_LIMIT:
2009 case LyXRC::RC_FULL_SCREEN_SCROLLBAR:
2010 case LyXRC::RC_FULL_SCREEN_TABBAR:
2011 case LyXRC::RC_FULL_SCREEN_TOOLBARS:
2012 case LyXRC::RC_FULL_SCREEN_WIDTH:
2013 case LyXRC::RC_VISUAL_CURSOR:
2014 case LyXRC::RC_VIEWER:
2015 case LyXRC::RC_LAST: