3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Alfredo Braunstein
7 * \author Lars Gullik Bjønnes
8 * \author Jean-Marc Lasgouttes
9 * \author Angus Leeming
11 * \author André Pönitz
14 * \author Martin Vermeer
15 * \author Jürgen Vigna
17 * Full author contact details are available in file CREDITS.
24 #include "LayoutFile.h"
25 #include "BranchList.h"
26 #include "buffer_funcs.h"
28 #include "BufferList.h"
29 #include "BufferParams.h"
30 #include "BufferView.h"
33 #include "Converter.h"
35 #include "CutAndPaste.h"
36 #include "DispatchResult.h"
38 #include "ErrorList.h"
40 #include "FuncRequest.h"
41 #include "FuncStatus.h"
42 #include "InsetIterator.h"
47 #include "LyXAction.h"
52 #include "Paragraph.h"
53 #include "ParagraphParameters.h"
54 #include "ParIterator.h"
59 #include "insets/InsetBox.h"
60 #include "insets/InsetBranch.h"
61 #include "insets/InsetCommand.h"
62 #include "insets/InsetERT.h"
63 #include "insets/InsetExternal.h"
64 #include "insets/InsetFloat.h"
65 #include "insets/InsetGraphics.h"
66 #include "insets/InsetInclude.h"
67 #include "insets/InsetListings.h"
68 #include "insets/InsetNote.h"
69 #include "insets/InsetPhantom.h"
70 #include "insets/InsetSpace.h"
71 #include "insets/InsetTabular.h"
72 #include "insets/InsetVSpace.h"
73 #include "insets/InsetWrap.h"
75 #include "frontends/alert.h"
76 #include "frontends/Application.h"
77 #include "frontends/KeySymbol.h"
78 #include "frontends/LyXView.h"
79 #include "frontends/Selection.h"
81 #include "support/debug.h"
82 #include "support/environment.h"
83 #include "support/FileName.h"
84 #include "support/filetools.h"
85 #include "support/gettext.h"
86 #include "support/lstrings.h"
87 #include "support/Path.h"
88 #include "support/Package.h"
89 #include "support/Systemcall.h"
90 #include "support/convert.h"
91 #include "support/os.h"
97 using namespace lyx::support;
101 using frontend::LyXView;
103 namespace Alert = frontend::Alert;
108 // This function runs "configure" and then rereads lyx.defaults to
109 // reconfigure the automatic settings.
110 void reconfigure(LyXView * lv, string const & option)
112 // emit message signal.
114 lv->message(_("Running configure..."));
116 // Run configure in user lyx directory
117 PathChanger p(package().user_support());
118 string configure_command = package().configure_command();
119 configure_command += option;
121 int ret = one.startscript(Systemcall::Wait, configure_command);
123 // emit message signal.
125 lv->message(_("Reloading configuration..."));
126 lyxrc.read(libFileSearch(string(), "lyxrc.defaults"));
127 // Re-read packages.lst
128 LaTeXFeatures::getAvailable();
131 Alert::information(_("System reconfiguration failed"),
132 _("The system reconfiguration has failed.\n"
133 "Default textclass is used but LyX may "
134 "not be able to work properly.\n"
135 "Please reconfigure again if needed."));
138 Alert::information(_("System reconfigured"),
139 _("The system has been reconfigured.\n"
140 "You need to restart LyX to make use of any\n"
141 "updated document class specifications."));
145 bool getLocalStatus(Cursor cursor, FuncRequest const & cmd, FuncStatus & status)
147 // Try to fix cursor in case it is broken.
148 cursor.fixIfBroken();
150 // This is, of course, a mess. Better create a new doc iterator and use
151 // this in Inset::getStatus. This might require an additional
152 // BufferView * arg, though (which should be avoided)
153 //Cursor safe = *this;
155 for ( ; cursor.depth(); cursor.pop()) {
156 //lyxerr << "\nCursor::getStatus: cmd: " << cmd << endl << *this << endl;
157 LASSERT(cursor.idx() <= cursor.lastidx(), /**/);
158 LASSERT(cursor.pit() <= cursor.lastpit(), /**/);
159 LASSERT(cursor.pos() <= cursor.lastpos(), /**/);
161 // The inset's getStatus() will return 'true' if it made
162 // a definitive decision on whether it want to handle the
163 // request or not. The result of this decision is put into
164 // the 'status' parameter.
165 if (cursor.inset().getStatus(cursor, cmd, status)) {
174 /** Return the change status at cursor position, taking in account the
175 * status at each level of the document iterator (a table in a deleted
176 * footnote is deleted).
177 * When \param outer is true, the top slice is not looked at.
179 Change::Type lookupChangeType(DocIterator const & dit, bool outer = false)
181 size_t const depth = dit.depth() - (outer ? 1 : 0);
183 for (size_t i = 0 ; i < depth ; ++i) {
184 CursorSlice const & slice = dit[i];
185 if (!slice.inset().inMathed()
186 && slice.pos() < slice.paragraph().size()) {
187 Change::Type const ch = slice.paragraph().lookupChange(slice.pos()).type;
188 if (ch != Change::UNCHANGED)
192 return Change::UNCHANGED;
199 : lyx_view_(0), encoded_last_key(0), meta_fake_bit(NoModifier)
204 void LyXFunc::initKeySequences(KeyMap * kb)
206 keyseq = KeySequence(kb, kb);
207 cancel_meta_seq = KeySequence(kb, kb);
211 void LyXFunc::setLyXView(LyXView * lv)
213 if (lyx_view_ && lyx_view_->view() && lyx_view_ != lv)
214 // save current selection to the selection buffer to allow
215 // middle-button paste in another window
216 cap::saveSelection(lyx_view_->view()->cursor());
221 void LyXFunc::handleKeyFunc(FuncCode action)
223 char_type c = encoded_last_key;
228 LASSERT(lyx_view_ && lyx_view_->view(), /**/);
229 lyx_view_->view()->getIntl().getTransManager().deadkey(
230 c, get_accent(action).accent, view()->cursor().innerText(), view()->cursor());
231 // Need to clear, in case the minibuffer calls these
234 // copied verbatim from do_accent_char
235 view()->cursor().resetAnchor();
236 view()->processUpdateFlags(Update::FitCursor);
239 //FIXME: bookmark handling is a frontend issue. This code should be transferred
240 // to GuiView and be GuiView and be window dependent.
241 void LyXFunc::gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer)
243 LASSERT(lyx_view_, /**/);
244 if (!theSession().bookmarks().isValid(idx))
246 BookmarksSection::Bookmark const & bm = theSession().bookmarks().bookmark(idx);
247 LASSERT(!bm.filename.empty(), /**/);
248 string const file = bm.filename.absFilename();
249 // if the file is not opened, open it.
250 if (!theBufferList().exists(bm.filename)) {
252 dispatch(FuncRequest(LFUN_FILE_OPEN, file));
256 // open may fail, so we need to test it again
257 if (!theBufferList().exists(bm.filename))
260 // bm can be changed when saving
261 BookmarksSection::Bookmark tmp = bm;
263 // Special case idx == 0 used for back-from-back jump navigation
265 dispatch(FuncRequest(LFUN_BOOKMARK_SAVE, "0"));
267 // if the current buffer is not that one, switch to it.
268 if (lyx_view_->buffer()->fileName() != tmp.filename) {
271 dispatch(FuncRequest(LFUN_BUFFER_SWITCH, file));
274 // moveToPosition try paragraph id first and then paragraph (pit, pos).
275 if (!view()->moveToPosition(tmp.bottom_pit, tmp.bottom_pos,
276 tmp.top_id, tmp.top_pos))
283 // Cursor jump succeeded!
284 Cursor const & cur = view()->cursor();
285 pit_type new_pit = cur.pit();
286 pos_type new_pos = cur.pos();
287 int new_id = cur.paragraph().id();
289 // if bottom_pit, bottom_pos or top_id has been changed, update bookmark
290 // see http://bugzilla.lyx.org/show_bug.cgi?id=3092
291 if (bm.bottom_pit != new_pit || bm.bottom_pos != new_pos
292 || bm.top_id != new_id) {
293 const_cast<BookmarksSection::Bookmark &>(bm).updatePos(
294 new_pit, new_pos, new_id);
299 void LyXFunc::processKeySym(KeySymbol const & keysym, KeyModifier state)
301 LYXERR(Debug::KEY, "KeySym is " << keysym.getSymbolName());
303 // Do nothing if we have nothing (JMarc)
304 if (!keysym.isOK()) {
305 LYXERR(Debug::KEY, "Empty kbd action (probably composing)");
306 lyx_view_->restartCursor();
310 if (keysym.isModifier()) {
311 LYXERR(Debug::KEY, "isModifier true");
313 lyx_view_->restartCursor();
317 //Encoding const * encoding = view()->cursor().getEncoding();
318 //encoded_last_key = keysym.getISOEncoded(encoding ? encoding->name() : "");
319 // FIXME: encoded_last_key shadows the member variable of the same
320 // name. Is that intended?
321 char_type encoded_last_key = keysym.getUCSEncoded();
323 // Do a one-deep top-level lookup for
324 // cancel and meta-fake keys. RVDK_PATCH_5
325 cancel_meta_seq.reset();
327 FuncRequest func = cancel_meta_seq.addkey(keysym, state);
328 LYXERR(Debug::KEY, "action first set to [" << func.action << ']');
330 // When not cancel or meta-fake, do the normal lookup.
331 // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
332 // Mostly, meta_fake_bit = NoModifier. RVDK_PATCH_5.
333 if ((func.action != LFUN_CANCEL) && (func.action != LFUN_META_PREFIX)) {
334 // remove Caps Lock and Mod2 as a modifiers
335 func = keyseq.addkey(keysym, (state | meta_fake_bit));
336 LYXERR(Debug::KEY, "action now set to [" << func.action << ']');
339 // Dont remove this unless you know what you are doing.
340 meta_fake_bit = NoModifier;
342 // Can this happen now ?
343 if (func.action == LFUN_NOACTION)
344 func = FuncRequest(LFUN_COMMAND_PREFIX);
346 LYXERR(Debug::KEY, " Key [action=" << func.action << "]["
347 << keyseq.print(KeySequence::Portable) << ']');
349 // already here we know if it any point in going further
350 // why not return already here if action == -1 and
351 // num_bytes == 0? (Lgb)
353 if (keyseq.length() > 1)
354 lyx_view_->message(keyseq.print(KeySequence::ForGui));
357 // Maybe user can only reach the key via holding down shift.
358 // Let's see. But only if shift is the only modifier
359 if (func.action == LFUN_UNKNOWN_ACTION && state == ShiftModifier) {
360 LYXERR(Debug::KEY, "Trying without shift");
361 func = keyseq.addkey(keysym, NoModifier);
362 LYXERR(Debug::KEY, "Action now " << func.action);
365 if (func.action == LFUN_UNKNOWN_ACTION) {
366 // Hmm, we didn't match any of the keysequences. See
367 // if it's normal insertable text not already covered
369 if (keysym.isText() && keyseq.length() == 1) {
370 LYXERR(Debug::KEY, "isText() is true, inserting.");
371 func = FuncRequest(LFUN_SELF_INSERT,
372 FuncRequest::KEYBOARD);
374 LYXERR(Debug::KEY, "Unknown, !isText() - giving up");
375 lyx_view_->message(_("Unknown function."));
376 lyx_view_->restartCursor();
381 if (func.action == LFUN_SELF_INSERT) {
382 if (encoded_last_key != 0) {
383 docstring const arg(1, encoded_last_key);
384 dispatch(FuncRequest(LFUN_SELF_INSERT, arg,
385 FuncRequest::KEYBOARD));
386 LYXERR(Debug::KEY, "SelfInsert arg[`" << to_utf8(arg) << "']");
396 FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
398 //lyxerr << "LyXFunc::getStatus: cmd: " << cmd << endl;
401 Buffer * buf = lyx_view_ ? lyx_view_->buffer() : 0;
403 if (cmd.action == LFUN_NOACTION) {
404 flag.message(from_utf8(N_("Nothing to do")));
405 flag.setEnabled(false);
409 switch (cmd.action) {
410 case LFUN_UNKNOWN_ACTION:
412 flag.setEnabled(false);
419 if (flag.unknown()) {
420 flag.message(from_utf8(N_("Unknown action")));
424 if (!flag.enabled()) {
425 if (flag.message().empty())
426 flag.message(from_utf8(N_("Command disabled")));
430 // Check whether we need a buffer
431 if (!lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer) && !buf) {
433 flag.message(from_utf8(N_("Command not allowed with"
434 "out any document open")));
435 flag.setEnabled(false);
439 // I would really like to avoid having this switch and rather try to
440 // encode this in the function itself.
441 // -- And I'd rather let an inset decide which LFUNs it is willing
442 // to handle (Andre')
444 switch (cmd.action) {
446 case LFUN_BUFFER_TOGGLE_READ_ONLY:
447 flag.setOnOff(buf->isReadonly());
450 case LFUN_BUFFER_SWITCH:
451 // toggle on the current buffer, but do not toggle off
452 // the other ones (is that a good idea?)
453 if (buf && to_utf8(cmd.argument()) == buf->absFileName())
457 case LFUN_BUFFER_CHKTEX:
458 enable = buf->isLatex() && !lyxrc.chktex_command.empty();
461 case LFUN_BUILD_PROGRAM:
462 enable = buf->isExportable("program");
465 case LFUN_VC_REGISTER:
466 enable = !buf->lyxvc().inUse();
468 case LFUN_VC_CHECK_IN:
469 enable = buf->lyxvc().checkInEnabled();
471 case LFUN_VC_CHECK_OUT:
472 enable = buf->lyxvc().checkOutEnabled();
475 enable = buf->lyxvc().inUse();
477 case LFUN_VC_UNDO_LAST:
478 enable = buf->lyxvc().undoLastEnabled();
480 case LFUN_BUFFER_RELOAD:
481 enable = !buf->isUnnamed() && buf->fileName().exists()
482 && (!buf->isClean() || buf->isExternallyModified(Buffer::timestamp_method));
485 case LFUN_CITATION_INSERT: {
486 FuncRequest fr(LFUN_INSET_INSERT, "citation");
487 enable = getStatus(fr).enabled();
491 // This could be used for the no-GUI version. The GUI version is handled in
492 // LyXView::getStatus(). See above.
494 case LFUN_BUFFER_WRITE:
495 case LFUN_BUFFER_WRITE_AS: {
496 Buffer * b = theBufferList().getBuffer(FileName(cmd.getArg(0)));
497 enable = b && (b->isUnnamed() || !b->isClean());
502 case LFUN_BUFFER_WRITE_ALL: {
503 // We enable the command only if there are some modified buffers
504 Buffer * first = theBufferList().first();
509 // We cannot use a for loop as the buffer list is a cycle.
515 b = theBufferList().next(b);
516 } while (b != first);
520 case LFUN_BOOKMARK_GOTO: {
521 const unsigned int num = convert<unsigned int>(to_utf8(cmd.argument()));
522 enable = theSession().bookmarks().isValid(num);
526 case LFUN_BOOKMARK_CLEAR:
527 enable = theSession().bookmarks().hasValid();
530 // this one is difficult to get right. As a half-baked
531 // solution, we consider only the first action of the sequence
532 case LFUN_COMMAND_SEQUENCE: {
533 // argument contains ';'-terminated commands
534 string const firstcmd = token(to_utf8(cmd.argument()), ';', 0);
535 FuncRequest func(lyxaction.lookupFunc(firstcmd));
536 func.origin = cmd.origin;
537 flag = getStatus(func);
541 // we want to check if at least one of these is enabled
542 case LFUN_COMMAND_ALTERNATIVES: {
543 // argument contains ';'-terminated commands
544 string arg = to_utf8(cmd.argument());
545 while (!arg.empty()) {
547 arg = split(arg, first, ';');
548 FuncRequest func(lyxaction.lookupFunc(first));
549 func.origin = cmd.origin;
550 flag = getStatus(func);
551 // if this one is enabled, the whole thing is
560 string name = to_utf8(cmd.argument());
561 if (theTopLevelCmdDef().lock(name, func)) {
562 func.origin = cmd.origin;
563 flag = getStatus(func);
564 theTopLevelCmdDef().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_VC_COMMAND: {
575 if (cmd.argument().empty())
578 if (!buf && contains(cmd.getArg(0), 'D'))
583 case LFUN_MASTER_BUFFER_UPDATE:
584 case LFUN_MASTER_BUFFER_VIEW:
585 if (!buf->parent()) {
589 case LFUN_BUFFER_UPDATE:
590 case LFUN_BUFFER_VIEW: {
591 string format = to_utf8(cmd.argument());
592 if (cmd.argument().empty())
593 format = buf->getDefaultOutputFormat();
594 typedef vector<Format const *> Formats;
596 formats = buf->exportableFormats(true);
597 Formats::const_iterator fit = formats.begin();
598 Formats::const_iterator end = formats.end();
600 for (; fit != end ; ++fit) {
601 if ((*fit)->name() == format)
607 case LFUN_WORD_FIND_FORWARD:
608 case LFUN_WORD_FIND_BACKWARD:
609 case LFUN_WORD_FINDADV:
610 case LFUN_COMMAND_PREFIX:
611 case LFUN_COMMAND_EXECUTE:
613 case LFUN_META_PREFIX:
614 case LFUN_BUFFER_CLOSE:
615 case LFUN_BUFFER_IMPORT:
616 case LFUN_BUFFER_AUTO_SAVE:
617 case LFUN_RECONFIGURE:
619 case LFUN_DROP_LAYOUTS_CHOICE:
621 case LFUN_SERVER_GET_FILENAME:
622 case LFUN_SERVER_NOTIFY:
623 case LFUN_SERVER_GOTO_FILE_ROW:
624 case LFUN_DIALOG_HIDE:
625 case LFUN_DIALOG_DISCONNECT_INSET:
626 case LFUN_BUFFER_CHILD_OPEN:
627 case LFUN_CURSOR_FOLLOWS_SCROLLBAR_TOGGLE:
628 case LFUN_KEYMAP_OFF:
629 case LFUN_KEYMAP_PRIMARY:
630 case LFUN_KEYMAP_SECONDARY:
631 case LFUN_KEYMAP_TOGGLE:
633 case LFUN_BUFFER_EXPORT_CUSTOM:
634 case LFUN_PREFERENCES_SAVE:
636 case LFUN_INSET_EDIT:
637 case LFUN_BUFFER_LANGUAGE:
638 case LFUN_TEXTCLASS_APPLY:
639 case LFUN_TEXTCLASS_LOAD:
640 case LFUN_BUFFER_SAVE_AS_DEFAULT:
641 case LFUN_BUFFER_PARAMS_APPLY:
642 case LFUN_LAYOUT_MODULES_CLEAR:
643 case LFUN_LAYOUT_MODULE_ADD:
644 case LFUN_LAYOUT_RELOAD:
645 case LFUN_LYXRC_APPLY:
646 case LFUN_BUFFER_NEXT:
647 case LFUN_BUFFER_PREVIOUS:
648 // these are handled in our dispatch()
656 if (theApp()->getStatus(cmd, flag))
659 // Does the view know something?
664 if (lyx_view_->getStatus(cmd, flag))
667 // If we do not have a BufferView, then other functions are disabled
673 // Is this a function that acts on inset at point?
674 Inset * inset = view()->cursor().nextInset();
675 if (lyxaction.funcHasFlag(cmd.action, LyXAction::AtPoint)
676 && inset && inset->getStatus(view()->cursor(), cmd, flag))
679 bool decided = getLocalStatus(view()->cursor(), cmd, flag);
681 // try the BufferView
682 decided = view()->getStatus(cmd, flag);
685 view()->buffer().getStatus(cmd, flag);
689 flag.setEnabled(false);
691 // Can we use a readonly buffer?
692 if (buf && buf->isReadonly()
693 && !lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly)
694 && !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)) {
695 flag.message(from_utf8(N_("Document is read-only")));
696 flag.setEnabled(false);
699 // Are we in a DELETED change-tracking region?
701 && lookupChangeType(view()->cursor(), true) == Change::DELETED
702 && !lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly)
703 && !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)) {
704 flag.message(from_utf8(N_("This portion of the document is deleted.")));
705 flag.setEnabled(false);
708 // the default error message if we disable the command
709 if (!flag.enabled() && flag.message().empty())
710 flag.message(from_utf8(N_("Command disabled")));
716 bool LyXFunc::ensureBufferClean(BufferView * bv)
718 Buffer & buf = bv->buffer();
719 if (buf.isClean() && !buf.isUnnamed())
722 docstring const file = buf.fileName().displayName(30);
725 if (!buf.isUnnamed()) {
726 text = bformat(_("The document %1$s has unsaved "
727 "changes.\n\nDo you want to save "
728 "the document?"), file);
729 title = _("Save changed document?");
732 text = bformat(_("The document %1$s has not been "
733 "saved yet.\n\nDo you want to save "
734 "the document?"), file);
735 title = _("Save new document?");
737 int const ret = Alert::prompt(title, text, 0, 1, _("&Save"), _("&Cancel"));
740 lyx_view_->dispatch(FuncRequest(LFUN_BUFFER_WRITE));
742 return buf.isClean() && !buf.isUnnamed();
748 bool loadLayoutFile(string const & name, string const & buf_path)
750 if (!LayoutFileList::get().haveClass(name)) {
751 lyxerr << "Document class \"" << name
752 << "\" does not exist."
757 LayoutFile & tc = LayoutFileList::get()[name];
758 if (!tc.load(buf_path)) {
759 docstring s = bformat(_("The document class %1$s "
760 "could not be loaded."), from_utf8(name));
761 Alert::error(_("Could not load class"), s);
768 void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new);
773 void LyXFunc::dispatch(FuncRequest const & cmd)
775 string const argument = to_utf8(cmd.argument());
776 FuncCode const action = cmd.action;
778 LYXERR(Debug::ACTION, "\nLyXFunc::dispatch: cmd: " << cmd);
779 //lyxerr << "LyXFunc::dispatch: cmd: " << cmd << endl;
781 // we have not done anything wrong yet.
783 dispatch_buffer.erase();
785 // redraw the screen at the end (first of the two drawing steps).
786 //This is done unless explicitely requested otherwise
787 Update::flags updateFlags = Update::FitCursor;
789 FuncStatus const flag = getStatus(cmd);
790 if (!flag.enabled()) {
791 // We cannot use this function here
792 LYXERR(Debug::ACTION, "LyXFunc::dispatch: "
793 << lyxaction.getActionName(action)
794 << " [" << action << "] is disabled at this location");
795 setErrorMessage(flag.message());
797 lyx_view_->restartCursor();
799 Buffer * buffer = lyx_view_ ? lyx_view_->buffer() : 0;
802 case LFUN_WORD_FIND_FORWARD:
803 case LFUN_WORD_FIND_BACKWARD: {
804 LASSERT(lyx_view_ && lyx_view_->view(), /**/);
805 static docstring last_search;
806 docstring searched_string;
808 if (!cmd.argument().empty()) {
809 last_search = cmd.argument();
810 searched_string = cmd.argument();
812 searched_string = last_search;
815 if (searched_string.empty())
818 bool const fw = action == LFUN_WORD_FIND_FORWARD;
819 docstring const data =
820 find2string(searched_string, true, false, fw);
821 find(view(), FuncRequest(LFUN_WORD_FIND, data));
825 case LFUN_COMMAND_PREFIX:
826 LASSERT(lyx_view_, /**/);
827 lyx_view_->message(keyseq.printOptions(true));
831 LASSERT(lyx_view_ && lyx_view_->view(), /**/);
833 meta_fake_bit = NoModifier;
835 // cancel any selection
836 dispatch(FuncRequest(LFUN_MARK_OFF));
837 setMessage(from_ascii(N_("Cancel")));
840 case LFUN_META_PREFIX:
841 meta_fake_bit = AltModifier;
842 setMessage(keyseq.print(KeySequence::ForGui));
845 case LFUN_BUFFER_TOGGLE_READ_ONLY: {
846 LASSERT(lyx_view_ && lyx_view_->view() && buffer, /**/);
847 if (buffer->lyxvc().inUse())
848 buffer->lyxvc().toggleReadOnly();
850 buffer->setReadonly(!buffer->isReadonly());
854 // --- Menus -----------------------------------------------
855 case LFUN_BUFFER_CLOSE:
856 lyx_view_->closeBuffer();
858 updateFlags = Update::None;
861 case LFUN_BUFFER_RELOAD: {
862 LASSERT(lyx_view_ && buffer, /**/);
863 docstring const file = makeDisplayPath(buffer->absFileName(), 20);
864 docstring text = bformat(_("Any changes will be lost. Are you sure "
865 "you want to revert to the saved version of the document %1$s?"), file);
866 int const ret = Alert::prompt(_("Revert to saved document?"),
867 text, 1, 1, _("&Revert"), _("&Cancel"));
874 case LFUN_BUFFER_UPDATE: {
875 LASSERT(lyx_view_ && buffer, /**/);
876 string format = argument;
877 if (argument.empty())
878 format = buffer->getDefaultOutputFormat();
879 buffer->doExport(format, true);
883 case LFUN_BUFFER_VIEW: {
884 LASSERT(lyx_view_ && buffer, /**/);
885 string format = argument;
886 if (argument.empty())
887 format = buffer->getDefaultOutputFormat();
888 buffer->preview(format);
892 case LFUN_MASTER_BUFFER_UPDATE: {
893 LASSERT(lyx_view_ && buffer && buffer->masterBuffer(), /**/);
894 string format = argument;
895 if (argument.empty())
896 format = buffer->masterBuffer()->getDefaultOutputFormat();
897 buffer->masterBuffer()->doExport(format, true);
901 case LFUN_MASTER_BUFFER_VIEW: {
902 LASSERT(lyx_view_ && buffer && buffer->masterBuffer(), /**/);
903 string format = argument;
904 if (argument.empty())
905 format = buffer->masterBuffer()->getDefaultOutputFormat();
906 buffer->masterBuffer()->preview(format);
910 case LFUN_BUILD_PROGRAM:
911 LASSERT(lyx_view_ && buffer, /**/);
912 buffer->doExport("program", true);
915 case LFUN_BUFFER_CHKTEX:
916 LASSERT(lyx_view_ && buffer, /**/);
920 case LFUN_BUFFER_EXPORT:
921 LASSERT(lyx_view_ && buffer, /**/);
922 if (argument == "custom")
923 dispatch(FuncRequest(LFUN_DIALOG_SHOW, "sendto"));
925 buffer->doExport(argument, false);
928 case LFUN_BUFFER_EXPORT_CUSTOM: {
929 LASSERT(lyx_view_ && buffer, /**/);
931 string command = split(argument, format_name, ' ');
932 Format const * format = formats.getFormat(format_name);
934 lyxerr << "Format \"" << format_name
935 << "\" not recognized!"
940 // The name of the file created by the conversion process
943 // Output to filename
944 if (format->name() == "lyx") {
945 string const latexname = buffer->latexName(false);
946 filename = changeExtension(latexname,
947 format->extension());
948 filename = addName(buffer->temppath(), filename);
950 if (!buffer->writeFile(FileName(filename)))
954 buffer->doExport(format_name, true, filename);
957 // Substitute $$FName for filename
958 if (!contains(command, "$$FName"))
959 command = "( " + command + " ) < $$FName";
960 command = subst(command, "$$FName", filename);
962 // Execute the command in the background
964 call.startscript(Systemcall::DontWait, command);
968 // FIXME: There is need for a command-line import.
970 case LFUN_BUFFER_IMPORT:
975 case LFUN_BUFFER_AUTO_SAVE:
979 case LFUN_RECONFIGURE:
980 // argument is any additional parameter to the configure.py command
981 reconfigure(lyx_view_, argument);
984 case LFUN_HELP_OPEN: {
986 theApp()->dispatch(FuncRequest(LFUN_WINDOW_NEW));
987 string const arg = argument;
989 setErrorMessage(from_utf8(N_("Missing argument")));
992 FileName fname = i18nLibFileSearch("doc", arg, "lyx");
994 fname = i18nLibFileSearch("examples", arg, "lyx");
997 lyxerr << "LyX: unable to find documentation file `"
998 << arg << "'. Bad installation?" << endl;
1001 lyx_view_->message(bformat(_("Opening help file %1$s..."),
1002 makeDisplayPath(fname.absFilename())));
1003 Buffer * buf = lyx_view_->loadDocument(fname, false);
1005 buf->updateLabels();
1006 lyx_view_->setBuffer(buf);
1007 buf->errors("Parse");
1009 updateFlags = Update::None;
1013 // --- version control -------------------------------
1014 case LFUN_VC_REGISTER:
1015 LASSERT(lyx_view_ && buffer, /**/);
1016 if (!ensureBufferClean(view()))
1018 if (!buffer->lyxvc().inUse()) {
1019 if (buffer->lyxvc().registrer())
1022 updateFlags = Update::Force;
1025 case LFUN_VC_CHECK_IN:
1026 LASSERT(lyx_view_ && buffer, /**/);
1027 if (!ensureBufferClean(view()))
1029 if (buffer->lyxvc().inUse()
1030 && !buffer->isReadonly()) {
1031 setMessage(from_utf8(buffer->lyxvc().checkIn()));
1036 case LFUN_VC_CHECK_OUT:
1037 LASSERT(lyx_view_ && buffer, /**/);
1038 if (!ensureBufferClean(view()))
1040 if (buffer->lyxvc().inUse()) {
1041 setMessage(from_utf8(buffer->lyxvc().checkOut()));
1046 case LFUN_VC_REVERT:
1047 LASSERT(lyx_view_ && buffer, /**/);
1048 buffer->lyxvc().revert();
1052 case LFUN_VC_UNDO_LAST:
1053 LASSERT(lyx_view_ && buffer, /**/);
1054 buffer->lyxvc().undoLast();
1058 // --- lyxserver commands ----------------------------
1059 case LFUN_SERVER_GET_FILENAME:
1060 LASSERT(lyx_view_ && buffer, /**/);
1061 setMessage(from_utf8(buffer->absFileName()));
1062 LYXERR(Debug::INFO, "FNAME["
1063 << buffer->absFileName() << ']');
1066 case LFUN_SERVER_NOTIFY:
1067 dispatch_buffer = keyseq.print(KeySequence::Portable);
1068 theServer().notifyClient(to_utf8(dispatch_buffer));
1071 case LFUN_SERVER_GOTO_FILE_ROW: {
1072 LASSERT(lyx_view_, /**/);
1075 istringstream is(argument);
1076 is >> file_name >> row;
1078 bool loaded = false;
1079 string const abstmp = package().temp_dir().absFilename();
1080 string const realtmp = package().temp_dir().realPath();
1081 if (prefixIs(file_name, abstmp) || prefixIs(file_name, realtmp)) {
1082 // Needed by inverse dvi search. If it is a file
1083 // in tmpdir, call the apropriated function.
1084 // If tmpdir is a symlink, we may have the real
1085 // path passed back, so we correct for that.
1086 if (!prefixIs(file_name, abstmp))
1087 file_name = subst(file_name, realtmp, abstmp);
1088 buf = theBufferList().getBufferFromTmp(file_name);
1090 // Must replace extension of the file to be .lyx
1091 // and get full path
1092 FileName const s = fileSearch(string(), changeExtension(file_name, ".lyx"), "lyx");
1093 // Either change buffer or load the file
1094 if (theBufferList().exists(s))
1095 buf = theBufferList().getBuffer(s);
1096 else if (s.exists()) {
1097 buf = lyx_view_->loadDocument(s);
1100 lyx_view_->message(bformat(
1101 _("File does not exist: %1$s"),
1102 makeDisplayPath(file_name)));
1106 updateFlags = Update::None;
1110 buf->updateLabels();
1111 lyx_view_->setBuffer(buf);
1112 view()->setCursorFromRow(row);
1114 buf->errors("Parse");
1115 updateFlags = Update::FitCursor;
1120 case LFUN_DIALOG_SHOW_NEW_INSET: {
1121 LASSERT(lyx_view_, /**/);
1122 string const name = cmd.getArg(0);
1123 InsetCode code = insetCode(name);
1124 string data = trim(to_utf8(cmd.argument()).substr(name.size()));
1125 bool insetCodeOK = true;
1134 case HYPERLINK_CODE: {
1135 InsetCommandParams p(code);
1136 data = InsetCommand::params2string(name, p);
1139 case INCLUDE_CODE: {
1140 // data is the include type: one of "include",
1141 // "input", "verbatiminput" or "verbatiminput*"
1143 // default type is requested
1145 InsetCommandParams p(INCLUDE_CODE, data);
1146 data = InsetCommand::params2string("include", p);
1150 // \c data == "Boxed" || "Frameless" etc
1151 InsetBoxParams p(data);
1152 data = InsetBox::params2string(p);
1156 InsetBranchParams p;
1157 data = InsetBranch::params2string(p);
1161 InsetCommandParams p(CITE_CODE);
1162 data = InsetCommand::params2string(name, p);
1166 data = InsetERT::params2string(InsetCollapsable::Open);
1169 case EXTERNAL_CODE: {
1170 InsetExternalParams p;
1171 data = InsetExternal::params2string(p, *buffer);
1176 data = InsetFloat::params2string(p);
1179 case LISTINGS_CODE: {
1180 InsetListingsParams p;
1181 data = InsetListings::params2string(p);
1184 case GRAPHICS_CODE: {
1185 InsetGraphicsParams p;
1186 data = InsetGraphics::params2string(p, *buffer);
1191 data = InsetNote::params2string(p);
1194 case PHANTOM_CODE: {
1195 InsetPhantomParams p;
1196 data = InsetPhantom::params2string(p);
1201 data = InsetSpace::params2string(p);
1206 data = InsetVSpace::params2string(space);
1211 data = InsetWrap::params2string(p);
1215 lyxerr << "Inset type '" << name <<
1216 "' not recognized in LFUN_DIALOG_SHOW_NEW_INSET" << endl;
1217 insetCodeOK = false;
1219 } // end switch(code)
1221 dispatch(FuncRequest(LFUN_DIALOG_SHOW, name + " " + data));
1225 case LFUN_CITATION_INSERT: {
1226 LASSERT(lyx_view_, /**/);
1227 if (!argument.empty()) {
1228 // we can have one optional argument, delimited by '|'
1229 // citation-insert <key>|<text_before>
1230 // this should be enhanced to also support text_after
1231 // and citation style
1232 string arg = argument;
1234 if (contains(argument, "|")) {
1235 arg = token(argument, '|', 0);
1236 opt1 = token(argument, '|', 1);
1238 InsetCommandParams icp(CITE_CODE);
1239 icp["key"] = from_utf8(arg);
1241 icp["before"] = from_utf8(opt1);
1242 string icstr = InsetCommand::params2string("citation", icp);
1243 FuncRequest fr(LFUN_INSET_INSERT, icstr);
1246 dispatch(FuncRequest(LFUN_DIALOG_SHOW_NEW_INSET, "citation"));
1250 case LFUN_BUFFER_CHILD_OPEN: {
1251 LASSERT(lyx_view_ && buffer, /**/);
1252 FileName filename = makeAbsPath(argument, buffer->filePath());
1253 view()->saveBookmark(false);
1255 bool parsed = false;
1256 if (theBufferList().exists(filename)) {
1257 child = theBufferList().getBuffer(filename);
1259 setMessage(bformat(_("Opening child document %1$s..."),
1260 makeDisplayPath(filename.absFilename())));
1261 child = lyx_view_->loadDocument(filename, false);
1265 // Set the parent name of the child document.
1266 // This makes insertion of citations and references in the child work,
1267 // when the target is in the parent or another child document.
1268 child->setParent(buffer);
1269 child->masterBuffer()->updateLabels();
1270 lyx_view_->setBuffer(child);
1272 child->errors("Parse");
1275 // If a screen update is required (in case where auto_open is false),
1276 // setBuffer() would have taken care of it already. Otherwise we shall
1277 // reset the update flag because it can cause a circular problem.
1279 updateFlags = Update::None;
1283 case LFUN_CURSOR_FOLLOWS_SCROLLBAR_TOGGLE:
1284 LASSERT(lyx_view_, /**/);
1285 lyxrc.cursor_follows_scrollbar = !lyxrc.cursor_follows_scrollbar;
1288 case LFUN_KEYMAP_OFF:
1289 LASSERT(lyx_view_ && lyx_view_->view(), /**/);
1290 lyx_view_->view()->getIntl().keyMapOn(false);
1293 case LFUN_KEYMAP_PRIMARY:
1294 LASSERT(lyx_view_ && lyx_view_->view(), /**/);
1295 lyx_view_->view()->getIntl().keyMapPrim();
1298 case LFUN_KEYMAP_SECONDARY:
1299 LASSERT(lyx_view_ && lyx_view_->view(), /**/);
1300 lyx_view_->view()->getIntl().keyMapSec();
1303 case LFUN_KEYMAP_TOGGLE:
1304 LASSERT(lyx_view_ && lyx_view_->view(), /**/);
1305 lyx_view_->view()->getIntl().toggleKeyMap();
1311 string rest = split(argument, countstr, ' ');
1312 istringstream is(countstr);
1315 //lyxerr << "repeat: count: " << count << " cmd: " << rest << endl;
1316 for (int i = 0; i < count; ++i)
1317 dispatch(lyxaction.lookupFunc(rest));
1321 case LFUN_COMMAND_SEQUENCE: {
1322 // argument contains ';'-terminated commands
1323 string arg = argument;
1324 if (theBufferList().isLoaded(buffer))
1325 buffer->undo().beginUndoGroup();
1326 while (!arg.empty()) {
1328 arg = split(arg, first, ';');
1329 FuncRequest func(lyxaction.lookupFunc(first));
1330 func.origin = cmd.origin;
1333 if (theBufferList().isLoaded(buffer))
1334 buffer->undo().endUndoGroup();
1338 case LFUN_COMMAND_ALTERNATIVES: {
1339 // argument contains ';'-terminated commands
1340 string arg = argument;
1341 while (!arg.empty()) {
1343 arg = split(arg, first, ';');
1344 FuncRequest func(lyxaction.lookupFunc(first));
1345 func.origin = cmd.origin;
1346 FuncStatus stat = getStatus(func);
1347 if (stat.enabled()) {
1357 if (theTopLevelCmdDef().lock(argument, func)) {
1358 func.origin = cmd.origin;
1360 theTopLevelCmdDef().release(argument);
1362 if (func.action == LFUN_UNKNOWN_ACTION) {
1363 // unknown command definition
1364 lyxerr << "Warning: unknown command definition `"
1368 // recursion detected
1369 lyxerr << "Warning: Recursion in the command definition `"
1370 << argument << "' detected"
1377 case LFUN_PREFERENCES_SAVE: {
1378 lyxrc.write(makeAbsPath("preferences",
1379 package().user_support().absFilename()),
1385 LASSERT(lyx_view_, /**/);
1386 lyx_view_->message(from_utf8(argument));
1389 case LFUN_BUFFER_LANGUAGE: {
1390 LASSERT(lyx_view_, /**/);
1391 Language const * oldL = buffer->params().language;
1392 Language const * newL = languages.getLanguage(argument);
1393 if (!newL || oldL == newL)
1396 if (oldL->rightToLeft() == newL->rightToLeft()
1397 && !buffer->isMultiLingual())
1398 buffer->changeLanguage(oldL, newL);
1402 case LFUN_BUFFER_SAVE_AS_DEFAULT: {
1403 string const fname =
1404 addName(addPath(package().user_support().absFilename(), "templates/"),
1406 Buffer defaults(fname);
1408 istringstream ss(argument);
1411 int const unknown_tokens = defaults.readHeader(lex);
1413 if (unknown_tokens != 0) {
1414 lyxerr << "Warning in LFUN_BUFFER_SAVE_AS_DEFAULT!\n"
1415 << unknown_tokens << " unknown token"
1416 << (unknown_tokens == 1 ? "" : "s")
1420 if (defaults.writeFile(FileName(defaults.absFileName())))
1421 setMessage(bformat(_("Document defaults saved in %1$s"),
1422 makeDisplayPath(fname)));
1424 setErrorMessage(from_ascii(N_("Unable to save document defaults")));
1428 case LFUN_BUFFER_PARAMS_APPLY: {
1429 LASSERT(lyx_view_, /**/);
1431 DocumentClass const * const oldClass = buffer->params().documentClassPtr();
1432 Cursor & cur = view()->cursor();
1433 cur.recordUndoFullDocument();
1435 istringstream ss(argument);
1438 int const unknown_tokens = buffer->readHeader(lex);
1440 if (unknown_tokens != 0) {
1441 lyxerr << "Warning in LFUN_BUFFER_PARAMS_APPLY!\n"
1442 << unknown_tokens << " unknown token"
1443 << (unknown_tokens == 1 ? "" : "s")
1447 updateLayout(oldClass, buffer);
1449 updateFlags = Update::Force | Update::FitCursor;
1450 // We are most certainly here because of a change in the document
1451 // It is then better to make sure that all dialogs are in sync with
1452 // current document settings. LyXView::restartCursor() achieve this.
1453 lyx_view_->restartCursor();
1457 case LFUN_LAYOUT_MODULES_CLEAR: {
1458 LASSERT(lyx_view_, /**/);
1459 DocumentClass const * const oldClass = buffer->params().documentClassPtr();
1460 view()->cursor().recordUndoFullDocument();
1461 buffer->params().clearLayoutModules();
1462 buffer->params().makeDocumentClass();
1463 updateLayout(oldClass, buffer);
1464 updateFlags = Update::Force | Update::FitCursor;
1468 case LFUN_LAYOUT_MODULE_ADD: {
1469 LASSERT(lyx_view_, /**/);
1470 BufferParams const & params = buffer->params();
1471 if (!params.moduleCanBeAdded(argument)) {
1472 LYXERR0("Module `" << argument <<
1473 "' cannot be added due to failed requirements or "
1474 "conflicts with installed modules.");
1477 DocumentClass const * const oldClass = params.documentClassPtr();
1478 view()->cursor().recordUndoFullDocument();
1479 buffer->params().addLayoutModule(argument);
1480 buffer->params().makeDocumentClass();
1481 updateLayout(oldClass, buffer);
1482 updateFlags = Update::Force | Update::FitCursor;
1486 case LFUN_TEXTCLASS_APPLY: {
1487 LASSERT(lyx_view_, /**/);
1489 if (!loadLayoutFile(argument, buffer->temppath()) &&
1490 !loadLayoutFile(argument, buffer->filePath()))
1493 LayoutFile const * old_layout = buffer->params().baseClass();
1494 LayoutFile const * new_layout = &(LayoutFileList::get()[argument]);
1496 if (old_layout == new_layout)
1500 //Save the old, possibly modular, layout for use in conversion.
1501 DocumentClass const * const oldDocClass = buffer->params().documentClassPtr();
1502 view()->cursor().recordUndoFullDocument();
1503 buffer->params().setBaseClass(argument);
1504 buffer->params().makeDocumentClass();
1505 updateLayout(oldDocClass, buffer);
1506 updateFlags = Update::Force | Update::FitCursor;
1510 case LFUN_LAYOUT_RELOAD: {
1511 LASSERT(lyx_view_, /**/);
1512 DocumentClass const * const oldClass = buffer->params().documentClassPtr();
1513 LayoutFileIndex bc = buffer->params().baseClassID();
1514 LayoutFileList::get().reset(bc);
1515 buffer->params().setBaseClass(bc);
1516 buffer->params().makeDocumentClass();
1517 updateLayout(oldClass, buffer);
1518 updateFlags = Update::Force | Update::FitCursor;
1522 case LFUN_TEXTCLASS_LOAD:
1523 loadLayoutFile(argument, buffer->temppath()) ||
1524 loadLayoutFile(argument, buffer->filePath());
1527 case LFUN_LYXRC_APPLY: {
1528 LyXRC const lyxrc_orig = lyxrc;
1530 istringstream ss(argument);
1531 bool const success = lyxrc.read(ss) == 0;
1534 lyxerr << "Warning in LFUN_LYXRC_APPLY!\n"
1535 << "Unable to read lyxrc data"
1540 actOnUpdatedPrefs(lyxrc_orig, lyxrc);
1542 theApp()->resetGui();
1544 /// We force the redraw in any case because there might be
1545 /// some screen font changes.
1546 /// FIXME: only the current view will be updated. the Gui
1547 /// class is able to furnish the list of views.
1548 updateFlags = Update::Force;
1552 case LFUN_BOOKMARK_GOTO:
1553 // go to bookmark, open unopened file and switch to buffer if necessary
1554 gotoBookmark(convert<unsigned int>(to_utf8(cmd.argument())), true, true);
1555 updateFlags = Update::FitCursor;
1558 case LFUN_BOOKMARK_CLEAR:
1559 theSession().bookmarks().clear();
1562 case LFUN_VC_COMMAND: {
1563 string flag = cmd.getArg(0);
1564 if (buffer && contains(flag, 'R') && !ensureBufferClean(view()))
1567 if (contains(flag, 'M'))
1568 if (!Alert::askForText(message, _("LyX VC: Log Message")))
1571 string path = cmd.getArg(1);
1572 if (contains(path, "$$p") && buffer)
1573 path = subst(path, "$$p", buffer->filePath());
1574 LYXERR(Debug::LYXVC, "Directory: " << path);
1576 if (!pp.isReadableDirectory()) {
1577 lyxerr << _("Directory is not accessible.") << endl;
1580 support::PathChanger p(pp);
1582 string command = cmd.getArg(2);
1583 if (command.empty())
1586 command = subst(command, "$$i", buffer->absFileName());
1587 command = subst(command, "$$p", buffer->filePath());
1589 command = subst(command, "$$m", to_utf8(message));
1590 LYXERR(Debug::LYXVC, "Command: " << command);
1592 one.startscript(Systemcall::Wait, command);
1596 if (contains(flag, 'I'))
1597 buffer->markDirty();
1598 if (contains(flag, 'R'))
1605 LASSERT(theApp(), /**/);
1606 // Let the frontend dispatch its own actions.
1607 if (theApp()->dispatch(cmd))
1608 // Nothing more to do.
1611 // Everything below is only for active lyx_view_
1615 // Start an undo group. This may be needed for
1616 // some stuff like inset-apply on labels.
1617 if (theBufferList().isLoaded(buffer))
1618 buffer->undo().beginUndoGroup();
1620 // Let the current LyXView dispatch its own actions.
1621 if (lyx_view_->dispatch(cmd)) {
1622 if (lyx_view_->view()) {
1623 updateFlags = lyx_view_->view()->cursor().result().update();
1624 if (theBufferList().isLoaded(buffer))
1625 buffer->undo().endUndoGroup();
1630 LASSERT(lyx_view_->view(), /**/);
1632 // Let the current BufferView dispatch its own actions.
1633 if (view()->dispatch(cmd)) {
1634 // The BufferView took care of its own updates if needed.
1635 updateFlags = Update::None;
1636 if (theBufferList().isLoaded(buffer))
1637 buffer->undo().endUndoGroup();
1641 // OK, so try the Buffer itself
1643 view()->buffer().dispatch(cmd, dr);
1644 if (dr.dispatched()) {
1645 updateFlags = dr.update();
1649 // Is this a function that acts on inset at point?
1650 Inset * inset = view()->cursor().nextInset();
1651 if (lyxaction.funcHasFlag(action, LyXAction::AtPoint)
1653 view()->cursor().result().dispatched(true);
1654 view()->cursor().result().update(Update::FitCursor | Update::Force);
1655 FuncRequest tmpcmd = cmd;
1656 inset->dispatch(view()->cursor(), tmpcmd);
1657 if (view()->cursor().result().dispatched()) {
1658 updateFlags = view()->cursor().result().update();
1663 // Let the current Cursor dispatch its own actions.
1664 Cursor old = view()->cursor();
1665 view()->cursor().getPos(cursorPosBeforeDispatchX_,
1666 cursorPosBeforeDispatchY_);
1667 view()->cursor().dispatch(cmd);
1669 // notify insets we just left
1670 if (view()->cursor() != old) {
1672 bool badcursor = notifyCursorLeavesOrEnters(old, view()->cursor());
1674 view()->cursor().fixIfBroken();
1677 if (theBufferList().isLoaded(buffer))
1678 buffer->undo().endUndoGroup();
1680 // update completion. We do it here and not in
1681 // processKeySym to avoid another redraw just for a
1682 // changed inline completion
1683 if (cmd.origin == FuncRequest::KEYBOARD) {
1684 if (cmd.action == LFUN_SELF_INSERT)
1685 lyx_view_->updateCompletion(view()->cursor(), true, true);
1686 else if (cmd.action == LFUN_CHAR_DELETE_BACKWARD)
1687 lyx_view_->updateCompletion(view()->cursor(), false, true);
1689 lyx_view_->updateCompletion(view()->cursor(), false, false);
1692 updateFlags = view()->cursor().result().update();
1695 // if we executed a mutating lfun, mark the buffer as dirty
1696 if (theBufferList().isLoaded(buffer) && flag.enabled()
1697 && !lyxaction.funcHasFlag(action, LyXAction::NoBuffer)
1698 && !lyxaction.funcHasFlag(action, LyXAction::ReadOnly))
1699 buffer->markDirty();
1701 if (lyx_view_ && lyx_view_->buffer()) {
1702 // BufferView::update() updates the ViewMetricsInfo and
1703 // also initializes the position cache for all insets in
1704 // (at least partially) visible top-level paragraphs.
1705 // We will redraw the screen only if needed.
1706 view()->processUpdateFlags(updateFlags);
1708 // Do we have a selection?
1709 theSelection().haveSelection(view()->cursor().selection());
1712 lyx_view_->restartCursor();
1716 // Some messages may already be translated, so we cannot use _()
1717 sendDispatchMessage(translateIfPossible(getMessage()), cmd);
1722 void LyXFunc::sendDispatchMessage(docstring const & msg, FuncRequest const & cmd)
1724 const bool verbose = (cmd.origin == FuncRequest::MENU
1725 || cmd.origin == FuncRequest::TOOLBAR
1726 || cmd.origin == FuncRequest::COMMANDBUFFER);
1728 if (cmd.action == LFUN_SELF_INSERT || !verbose) {
1729 LYXERR(Debug::ACTION, "dispatch msg is " << to_utf8(msg));
1731 lyx_view_->message(msg);
1735 docstring dispatch_msg = msg;
1736 if (!dispatch_msg.empty())
1737 dispatch_msg += ' ';
1739 docstring comname = from_utf8(lyxaction.getActionName(cmd.action));
1741 bool argsadded = false;
1743 if (!cmd.argument().empty()) {
1744 if (cmd.action != LFUN_UNKNOWN_ACTION) {
1745 comname += ' ' + cmd.argument();
1750 docstring const shortcuts = theTopLevelKeymap().printBindings(cmd, KeySequence::ForGui);
1752 if (!shortcuts.empty())
1753 comname += ": " + shortcuts;
1754 else if (!argsadded && !cmd.argument().empty())
1755 comname += ' ' + cmd.argument();
1757 if (!comname.empty()) {
1758 comname = rtrim(comname);
1759 dispatch_msg += '(' + rtrim(comname) + ')';
1762 LYXERR(Debug::ACTION, "verbose dispatch msg " << to_utf8(dispatch_msg));
1763 if (!dispatch_msg.empty())
1764 lyx_view_->message(dispatch_msg);
1768 void LyXFunc::reloadBuffer()
1770 FileName filename = lyx_view_->buffer()->fileName();
1771 // The user has already confirmed that the changes, if any, should
1772 // be discarded. So we just release the Buffer and don't call closeBuffer();
1773 theBufferList().release(lyx_view_->buffer());
1774 // if the lyx_view_ has been destroyed, create a new one
1776 theApp()->dispatch(FuncRequest(LFUN_WINDOW_NEW));
1777 Buffer * buf = lyx_view_->loadDocument(filename);
1778 docstring const disp_fn = makeDisplayPath(filename.absFilename());
1781 buf->updateLabels();
1782 lyx_view_->setBuffer(buf);
1783 buf->errors("Parse");
1784 str = bformat(_("Document %1$s reloaded."), disp_fn);
1786 str = bformat(_("Could not reload document %1$s"), disp_fn);
1788 lyx_view_->message(str);
1791 // Each "lyx_view_" should have it's own message method. lyxview and
1792 // the minibuffer would use the minibuffer, but lyxserver would
1793 // send an ERROR signal to its client. Alejandro 970603
1794 // This function is bit problematic when it comes to NLS, to make the
1795 // lyx servers client be language indepenent we must not translate
1796 // strings sent to this func.
1797 void LyXFunc::setErrorMessage(docstring const & m) const
1799 dispatch_buffer = m;
1804 void LyXFunc::setMessage(docstring const & m) const
1806 dispatch_buffer = m;
1810 docstring LyXFunc::viewStatusMessage()
1812 // When meta-fake key is pressed, show the key sequence so far + "M-".
1814 return keyseq.print(KeySequence::ForGui) + "M-";
1816 // Else, when a non-complete key sequence is pressed,
1817 // show the available options.
1818 if (keyseq.length() > 0 && !keyseq.deleted())
1819 return keyseq.printOptions(true);
1821 LASSERT(lyx_view_, /**/);
1822 if (!lyx_view_->buffer())
1823 return _("Welcome to LyX!");
1825 return view()->cursor().currentState();
1829 BufferView * LyXFunc::view() const
1831 LASSERT(lyx_view_, /**/);
1832 return lyx_view_->view();
1836 bool LyXFunc::wasMetaKey() const
1838 return (meta_fake_bit != NoModifier);
1842 void LyXFunc::updateLayout(DocumentClass const * const oldlayout, Buffer * buf)
1844 lyx_view_->message(_("Converting document to new document class..."));
1846 StableDocIterator backcur(view()->cursor());
1847 ErrorList & el = buf->errorList("Class Switch");
1848 cap::switchBetweenClasses(
1849 oldlayout, buf->params().documentClassPtr(),
1850 static_cast<InsetText &>(buf->inset()), el);
1852 view()->setCursor(backcur.asDocIterator(buf));
1854 buf->errors("Class Switch");
1855 buf->updateLabels();
1861 void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
1863 // Why the switch you might ask. It is a trick to ensure that all
1864 // the elements in the LyXRCTags enum is handled. As you can see
1865 // there are no breaks at all. So it is just a huge fall-through.
1866 // The nice thing is that we will get a warning from the compiler
1867 // if we forget an element.
1868 LyXRC::LyXRCTags tag = LyXRC::RC_LAST;
1870 case LyXRC::RC_ACCEPT_COMPOUND:
1871 case LyXRC::RC_ALT_LANG:
1872 case LyXRC::RC_PLAINTEXT_LINELEN:
1873 case LyXRC::RC_PLAINTEXT_ROFF_COMMAND:
1874 case LyXRC::RC_AUTOCORRECTION_MATH:
1875 case LyXRC::RC_AUTOREGIONDELETE:
1876 case LyXRC::RC_AUTORESET_OPTIONS:
1877 case LyXRC::RC_AUTOSAVE:
1878 case LyXRC::RC_AUTO_NUMBER:
1879 case LyXRC::RC_BACKUPDIR_PATH:
1880 case LyXRC::RC_BIBTEX_ALTERNATIVES:
1881 case LyXRC::RC_BIBTEX_COMMAND:
1882 case LyXRC::RC_BINDFILE:
1883 case LyXRC::RC_CHECKLASTFILES:
1884 case LyXRC::RC_COMPLETION_CURSOR_TEXT:
1885 case LyXRC::RC_COMPLETION_INLINE_DELAY:
1886 case LyXRC::RC_COMPLETION_INLINE_DOTS:
1887 case LyXRC::RC_COMPLETION_INLINE_MATH:
1888 case LyXRC::RC_COMPLETION_INLINE_TEXT:
1889 case LyXRC::RC_COMPLETION_POPUP_AFTER_COMPLETE:
1890 case LyXRC::RC_COMPLETION_POPUP_DELAY:
1891 case LyXRC::RC_COMPLETION_POPUP_MATH:
1892 case LyXRC::RC_COMPLETION_POPUP_TEXT:
1893 case LyXRC::RC_USELASTFILEPOS:
1894 case LyXRC::RC_LOADSESSION:
1895 case LyXRC::RC_CHKTEX_COMMAND:
1896 case LyXRC::RC_CONVERTER:
1897 case LyXRC::RC_CONVERTER_CACHE_MAXAGE:
1898 case LyXRC::RC_COPIER:
1899 case LyXRC::RC_CURSOR_FOLLOWS_SCROLLBAR:
1900 case LyXRC::RC_SCROLL_BELOW_DOCUMENT:
1901 case LyXRC::RC_DATE_INSERT_FORMAT:
1902 case LyXRC::RC_DEFAULT_LANGUAGE:
1903 case LyXRC::RC_GUI_LANGUAGE:
1904 case LyXRC::RC_DEFAULT_PAPERSIZE:
1905 case LyXRC::RC_DEFAULT_VIEW_FORMAT:
1906 case LyXRC::RC_DEFFILE:
1907 case LyXRC::RC_DIALOGS_ICONIFY_WITH_MAIN:
1908 case LyXRC::RC_DISPLAY_GRAPHICS:
1909 case LyXRC::RC_DOCUMENTPATH:
1910 if (lyxrc_orig.document_path != lyxrc_new.document_path) {
1911 FileName path(lyxrc_new.document_path);
1912 if (path.exists() && path.isDirectory())
1913 package().document_dir() = FileName(lyxrc.document_path);
1915 case LyXRC::RC_ESC_CHARS:
1916 case LyXRC::RC_EXAMPLEPATH:
1917 case LyXRC::RC_FONT_ENCODING:
1918 case LyXRC::RC_FORMAT:
1919 case LyXRC::RC_GROUP_LAYOUTS:
1920 case LyXRC::RC_INDEX_ALTERNATIVES:
1921 case LyXRC::RC_INDEX_COMMAND:
1922 case LyXRC::RC_JBIBTEX_COMMAND:
1923 case LyXRC::RC_JINDEX_COMMAND:
1924 case LyXRC::RC_NOMENCL_COMMAND:
1925 case LyXRC::RC_INPUT:
1926 case LyXRC::RC_KBMAP:
1927 case LyXRC::RC_KBMAP_PRIMARY:
1928 case LyXRC::RC_KBMAP_SECONDARY:
1929 case LyXRC::RC_LABEL_INIT_LENGTH:
1930 case LyXRC::RC_LANGUAGE_AUTO_BEGIN:
1931 case LyXRC::RC_LANGUAGE_AUTO_END:
1932 case LyXRC::RC_LANGUAGE_COMMAND_BEGIN:
1933 case LyXRC::RC_LANGUAGE_COMMAND_END:
1934 case LyXRC::RC_LANGUAGE_COMMAND_LOCAL:
1935 case LyXRC::RC_LANGUAGE_GLOBAL_OPTIONS:
1936 case LyXRC::RC_LANGUAGE_PACKAGE:
1937 case LyXRC::RC_LANGUAGE_USE_BABEL:
1938 case LyXRC::RC_MAC_LIKE_WORD_MOVEMENT:
1939 case LyXRC::RC_MACRO_EDIT_STYLE:
1940 case LyXRC::RC_MAKE_BACKUP:
1941 case LyXRC::RC_MARK_FOREIGN_LANGUAGE:
1942 case LyXRC::RC_MOUSE_WHEEL_SPEED:
1943 case LyXRC::RC_NUMLASTFILES:
1944 case LyXRC::RC_PATH_PREFIX:
1945 if (lyxrc_orig.path_prefix != lyxrc_new.path_prefix) {
1946 prependEnvPath("PATH", lyxrc.path_prefix);
1948 case LyXRC::RC_PERS_DICT:
1949 case LyXRC::RC_PREVIEW:
1950 case LyXRC::RC_PREVIEW_HASHED_LABELS:
1951 case LyXRC::RC_PREVIEW_SCALE_FACTOR:
1952 case LyXRC::RC_PRINTCOLLCOPIESFLAG:
1953 case LyXRC::RC_PRINTCOPIESFLAG:
1954 case LyXRC::RC_PRINTER:
1955 case LyXRC::RC_PRINTEVENPAGEFLAG:
1956 case LyXRC::RC_PRINTEXSTRAOPTIONS:
1957 case LyXRC::RC_PRINTFILEEXTENSION:
1958 case LyXRC::RC_PRINTLANDSCAPEFLAG:
1959 case LyXRC::RC_PRINTODDPAGEFLAG:
1960 case LyXRC::RC_PRINTPAGERANGEFLAG:
1961 case LyXRC::RC_PRINTPAPERDIMENSIONFLAG:
1962 case LyXRC::RC_PRINTPAPERFLAG:
1963 case LyXRC::RC_PRINTREVERSEFLAG:
1964 case LyXRC::RC_PRINTSPOOL_COMMAND:
1965 case LyXRC::RC_PRINTSPOOL_PRINTERPREFIX:
1966 case LyXRC::RC_PRINTTOFILE:
1967 case LyXRC::RC_PRINTTOPRINTER:
1968 case LyXRC::RC_PRINT_ADAPTOUTPUT:
1969 case LyXRC::RC_PRINT_COMMAND:
1970 case LyXRC::RC_RTL_SUPPORT:
1971 case LyXRC::RC_SCREEN_DPI:
1972 case LyXRC::RC_SCREEN_FONT_ROMAN:
1973 case LyXRC::RC_SCREEN_FONT_ROMAN_FOUNDRY:
1974 case LyXRC::RC_SCREEN_FONT_SANS:
1975 case LyXRC::RC_SCREEN_FONT_SANS_FOUNDRY:
1976 case LyXRC::RC_SCREEN_FONT_SCALABLE:
1977 case LyXRC::RC_SCREEN_FONT_SIZES:
1978 case LyXRC::RC_SCREEN_FONT_TYPEWRITER:
1979 case LyXRC::RC_SCREEN_FONT_TYPEWRITER_FOUNDRY:
1980 case LyXRC::RC_GEOMETRY_SESSION:
1981 case LyXRC::RC_SCREEN_ZOOM:
1982 case LyXRC::RC_SERVERPIPE:
1983 case LyXRC::RC_SET_COLOR:
1984 case LyXRC::RC_SHOW_BANNER:
1985 case LyXRC::RC_OPEN_BUFFERS_IN_TABS:
1986 case LyXRC::RC_SPELL_COMMAND:
1987 case LyXRC::RC_SPELLCHECK_CONTINUOUSLY:
1988 case LyXRC::RC_SPLITINDEX_COMMAND:
1989 case LyXRC::RC_TEMPDIRPATH:
1990 case LyXRC::RC_TEMPLATEPATH:
1991 case LyXRC::RC_TEX_ALLOWS_SPACES:
1992 case LyXRC::RC_TEX_EXPECTS_WINDOWS_PATHS:
1993 if (lyxrc_orig.windows_style_tex_paths != lyxrc_new.windows_style_tex_paths) {
1994 os::windows_style_tex_paths(lyxrc_new.windows_style_tex_paths);
1996 case LyXRC::RC_THESAURUSDIRPATH:
1997 case LyXRC::RC_UIFILE:
1998 case LyXRC::RC_USER_EMAIL:
1999 case LyXRC::RC_USER_NAME:
2000 case LyXRC::RC_USETEMPDIR:
2001 case LyXRC::RC_USE_ALT_LANG:
2002 case LyXRC::RC_USE_CONVERTER_CACHE:
2003 case LyXRC::RC_USE_ESC_CHARS:
2004 case LyXRC::RC_USE_INP_ENC:
2005 case LyXRC::RC_USE_PERS_DICT:
2006 case LyXRC::RC_USE_TOOLTIP:
2007 case LyXRC::RC_USE_PIXMAP_CACHE:
2008 case LyXRC::RC_USE_SPELL_LIB:
2009 case LyXRC::RC_VIEWDVI_PAPEROPTION:
2010 case LyXRC::RC_SORT_LAYOUTS:
2011 case LyXRC::RC_FULL_SCREEN_LIMIT:
2012 case LyXRC::RC_FULL_SCREEN_SCROLLBAR:
2013 case LyXRC::RC_FULL_SCREEN_TABBAR:
2014 case LyXRC::RC_FULL_SCREEN_TOOLBARS:
2015 case LyXRC::RC_FULL_SCREEN_WIDTH:
2016 case LyXRC::RC_VISUAL_CURSOR:
2017 case LyXRC::RC_VIEWER:
2018 case LyXRC::RC_LAST: