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:
411 #if !defined(HAVE_LIBMYTHES) && !defined(HAVE_LIBAIKSAURUS)
412 case LFUN_THESAURUS_ENTRY:
415 flag.setEnabled(false);
422 if (flag.unknown()) {
423 flag.message(from_utf8(N_("Unknown action")));
427 if (!flag.enabled()) {
428 if (flag.message().empty())
429 flag.message(from_utf8(N_("Command disabled")));
433 // Check whether we need a buffer
434 if (!lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer) && !buf) {
436 flag.message(from_utf8(N_("Command not allowed with"
437 "out any document open")));
438 flag.setEnabled(false);
442 // I would really like to avoid having this switch and rather try to
443 // encode this in the function itself.
444 // -- And I'd rather let an inset decide which LFUNs it is willing
445 // to handle (Andre')
447 switch (cmd.action) {
449 case LFUN_BUFFER_TOGGLE_READ_ONLY:
450 flag.setOnOff(buf->isReadonly());
453 case LFUN_BUFFER_SWITCH:
454 // toggle on the current buffer, but do not toggle off
455 // the other ones (is that a good idea?)
456 if (buf && to_utf8(cmd.argument()) == buf->absFileName())
460 case LFUN_BUFFER_CHKTEX:
461 enable = buf->isLatex() && !lyxrc.chktex_command.empty();
464 case LFUN_BUILD_PROGRAM:
465 enable = buf->isExportable("program");
468 case LFUN_VC_REGISTER:
469 enable = !buf->lyxvc().inUse();
471 case LFUN_VC_CHECK_IN:
472 enable = buf->lyxvc().checkInEnabled();
474 case LFUN_VC_CHECK_OUT:
475 enable = buf->lyxvc().checkOutEnabled();
478 enable = buf->lyxvc().inUse();
480 case LFUN_VC_UNDO_LAST:
481 enable = buf->lyxvc().undoLastEnabled();
483 case LFUN_BUFFER_RELOAD:
484 enable = !buf->isUnnamed() && buf->fileName().exists()
485 && (!buf->isClean() || buf->isExternallyModified(Buffer::timestamp_method));
488 case LFUN_CITATION_INSERT: {
489 FuncRequest fr(LFUN_INSET_INSERT, "citation");
490 enable = getStatus(fr).enabled();
494 // This could be used for the no-GUI version. The GUI version is handled in
495 // LyXView::getStatus(). See above.
497 case LFUN_BUFFER_WRITE:
498 case LFUN_BUFFER_WRITE_AS: {
499 Buffer * b = theBufferList().getBuffer(FileName(cmd.getArg(0)));
500 enable = b && (b->isUnnamed() || !b->isClean());
505 case LFUN_BUFFER_WRITE_ALL: {
506 // We enable the command only if there are some modified buffers
507 Buffer * first = theBufferList().first();
512 // We cannot use a for loop as the buffer list is a cycle.
518 b = theBufferList().next(b);
519 } while (b != first);
523 case LFUN_BOOKMARK_GOTO: {
524 const unsigned int num = convert<unsigned int>(to_utf8(cmd.argument()));
525 enable = theSession().bookmarks().isValid(num);
529 case LFUN_BOOKMARK_CLEAR:
530 enable = theSession().bookmarks().hasValid();
533 // this one is difficult to get right. As a half-baked
534 // solution, we consider only the first action of the sequence
535 case LFUN_COMMAND_SEQUENCE: {
536 // argument contains ';'-terminated commands
537 string const firstcmd = token(to_utf8(cmd.argument()), ';', 0);
538 FuncRequest func(lyxaction.lookupFunc(firstcmd));
539 func.origin = cmd.origin;
540 flag = getStatus(func);
544 // we want to check if at least one of these is enabled
545 case LFUN_COMMAND_ALTERNATIVES: {
546 // argument contains ';'-terminated commands
547 string arg = to_utf8(cmd.argument());
548 while (!arg.empty()) {
550 arg = split(arg, first, ';');
551 FuncRequest func(lyxaction.lookupFunc(first));
552 func.origin = cmd.origin;
553 flag = getStatus(func);
554 // if this one is enabled, the whole thing is
563 string name = to_utf8(cmd.argument());
564 if (theTopLevelCmdDef().lock(name, func)) {
565 func.origin = cmd.origin;
566 flag = getStatus(func);
567 theTopLevelCmdDef().release(name);
569 // catch recursion or unknown command definiton
570 // all operations until the recursion or unknown command
571 // definiton occures are performed, so set the state to enabled
577 case LFUN_VC_COMMAND: {
578 if (cmd.argument().empty())
581 if (!buf && contains(cmd.getArg(0), 'D'))
586 case LFUN_MASTER_BUFFER_UPDATE:
587 case LFUN_MASTER_BUFFER_VIEW:
588 if (!buf->parent()) {
592 case LFUN_BUFFER_UPDATE:
593 case LFUN_BUFFER_VIEW: {
594 string format = to_utf8(cmd.argument());
595 if (cmd.argument().empty())
596 format = buf->getDefaultOutputFormat();
597 typedef vector<Format const *> Formats;
599 formats = buf->exportableFormats(true);
600 Formats::const_iterator fit = formats.begin();
601 Formats::const_iterator end = formats.end();
603 for (; fit != end ; ++fit) {
604 if ((*fit)->name() == format)
610 case LFUN_WORD_FIND_FORWARD:
611 case LFUN_WORD_FIND_BACKWARD:
612 case LFUN_WORD_FINDADV:
613 case LFUN_COMMAND_PREFIX:
614 case LFUN_COMMAND_EXECUTE:
616 case LFUN_META_PREFIX:
617 case LFUN_BUFFER_CLOSE:
618 case LFUN_BUFFER_IMPORT:
619 case LFUN_BUFFER_AUTO_SAVE:
620 case LFUN_RECONFIGURE:
622 case LFUN_DROP_LAYOUTS_CHOICE:
624 case LFUN_SERVER_GET_FILENAME:
625 case LFUN_SERVER_NOTIFY:
626 case LFUN_SERVER_GOTO_FILE_ROW:
627 case LFUN_DIALOG_HIDE:
628 case LFUN_DIALOG_DISCONNECT_INSET:
629 case LFUN_BUFFER_CHILD_OPEN:
630 case LFUN_CURSOR_FOLLOWS_SCROLLBAR_TOGGLE:
631 case LFUN_KEYMAP_OFF:
632 case LFUN_KEYMAP_PRIMARY:
633 case LFUN_KEYMAP_SECONDARY:
634 case LFUN_KEYMAP_TOGGLE:
636 case LFUN_BUFFER_EXPORT_CUSTOM:
637 case LFUN_PREFERENCES_SAVE:
639 case LFUN_INSET_EDIT:
640 case LFUN_BUFFER_LANGUAGE:
641 case LFUN_TEXTCLASS_APPLY:
642 case LFUN_TEXTCLASS_LOAD:
643 case LFUN_BUFFER_SAVE_AS_DEFAULT:
644 case LFUN_BUFFER_PARAMS_APPLY:
645 case LFUN_LAYOUT_MODULES_CLEAR:
646 case LFUN_LAYOUT_MODULE_ADD:
647 case LFUN_LAYOUT_RELOAD:
648 case LFUN_LYXRC_APPLY:
649 case LFUN_BUFFER_NEXT:
650 case LFUN_BUFFER_PREVIOUS:
651 // these are handled in our dispatch()
659 if (theApp()->getStatus(cmd, flag))
662 // Does the view know something?
667 if (lyx_view_->getStatus(cmd, flag))
670 // If we do not have a BufferView, then other functions are disabled
676 // Is this a function that acts on inset at point?
677 Inset * inset = view()->cursor().nextInset();
678 if (lyxaction.funcHasFlag(cmd.action, LyXAction::AtPoint)
679 && inset && inset->getStatus(view()->cursor(), cmd, flag))
682 bool decided = getLocalStatus(view()->cursor(), cmd, flag);
684 // try the BufferView
685 decided = view()->getStatus(cmd, flag);
688 view()->buffer().getStatus(cmd, flag);
692 flag.setEnabled(false);
694 // Can we use a readonly buffer?
695 if (buf && buf->isReadonly()
696 && !lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly)
697 && !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)) {
698 flag.message(from_utf8(N_("Document is read-only")));
699 flag.setEnabled(false);
702 // Are we in a DELETED change-tracking region?
704 && lookupChangeType(view()->cursor(), true) == Change::DELETED
705 && !lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly)
706 && !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)) {
707 flag.message(from_utf8(N_("This portion of the document is deleted.")));
708 flag.setEnabled(false);
711 // the default error message if we disable the command
712 if (!flag.enabled() && flag.message().empty())
713 flag.message(from_utf8(N_("Command disabled")));
719 bool LyXFunc::ensureBufferClean(BufferView * bv)
721 Buffer & buf = bv->buffer();
722 if (buf.isClean() && !buf.isUnnamed())
725 docstring const file = buf.fileName().displayName(30);
728 if (!buf.isUnnamed()) {
729 text = bformat(_("The document %1$s has unsaved "
730 "changes.\n\nDo you want to save "
731 "the document?"), file);
732 title = _("Save changed document?");
735 text = bformat(_("The document %1$s has not been "
736 "saved yet.\n\nDo you want to save "
737 "the document?"), file);
738 title = _("Save new document?");
740 int const ret = Alert::prompt(title, text, 0, 1, _("&Save"), _("&Cancel"));
743 lyx_view_->dispatch(FuncRequest(LFUN_BUFFER_WRITE));
745 return buf.isClean() && !buf.isUnnamed();
751 bool loadLayoutFile(string const & name, string const & buf_path)
753 if (!LayoutFileList::get().haveClass(name)) {
754 lyxerr << "Document class \"" << name
755 << "\" does not exist."
760 LayoutFile & tc = LayoutFileList::get()[name];
761 if (!tc.load(buf_path)) {
762 docstring s = bformat(_("The document class %1$s "
763 "could not be loaded."), from_utf8(name));
764 Alert::error(_("Could not load class"), s);
771 void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new);
776 void LyXFunc::dispatch(FuncRequest const & cmd)
778 string const argument = to_utf8(cmd.argument());
779 FuncCode const action = cmd.action;
781 LYXERR(Debug::ACTION, "\nLyXFunc::dispatch: cmd: " << cmd);
782 //lyxerr << "LyXFunc::dispatch: cmd: " << cmd << endl;
784 // we have not done anything wrong yet.
786 dispatch_buffer.erase();
788 // redraw the screen at the end (first of the two drawing steps).
789 //This is done unless explicitely requested otherwise
790 Update::flags updateFlags = Update::FitCursor;
792 FuncStatus const flag = getStatus(cmd);
793 if (!flag.enabled()) {
794 // We cannot use this function here
795 LYXERR(Debug::ACTION, "LyXFunc::dispatch: "
796 << lyxaction.getActionName(action)
797 << " [" << action << "] is disabled at this location");
798 setErrorMessage(flag.message());
800 lyx_view_->restartCursor();
802 Buffer * buffer = lyx_view_ ? lyx_view_->buffer() : 0;
805 case LFUN_WORD_FIND_FORWARD:
806 case LFUN_WORD_FIND_BACKWARD: {
807 LASSERT(lyx_view_ && lyx_view_->view(), /**/);
808 static docstring last_search;
809 docstring searched_string;
811 if (!cmd.argument().empty()) {
812 last_search = cmd.argument();
813 searched_string = cmd.argument();
815 searched_string = last_search;
818 if (searched_string.empty())
821 bool const fw = action == LFUN_WORD_FIND_FORWARD;
822 docstring const data =
823 find2string(searched_string, true, false, fw);
824 find(view(), FuncRequest(LFUN_WORD_FIND, data));
828 case LFUN_COMMAND_PREFIX:
829 LASSERT(lyx_view_, /**/);
830 lyx_view_->message(keyseq.printOptions(true));
834 LASSERT(lyx_view_ && lyx_view_->view(), /**/);
836 meta_fake_bit = NoModifier;
838 // cancel any selection
839 dispatch(FuncRequest(LFUN_MARK_OFF));
840 setMessage(from_ascii(N_("Cancel")));
843 case LFUN_META_PREFIX:
844 meta_fake_bit = AltModifier;
845 setMessage(keyseq.print(KeySequence::ForGui));
848 case LFUN_BUFFER_TOGGLE_READ_ONLY: {
849 LASSERT(lyx_view_ && lyx_view_->view() && buffer, /**/);
850 if (buffer->lyxvc().inUse())
851 buffer->lyxvc().toggleReadOnly();
853 buffer->setReadonly(!buffer->isReadonly());
857 // --- Menus -----------------------------------------------
858 case LFUN_BUFFER_CLOSE:
859 lyx_view_->closeBuffer();
861 updateFlags = Update::None;
864 case LFUN_BUFFER_RELOAD: {
865 LASSERT(lyx_view_ && buffer, /**/);
866 docstring const file = makeDisplayPath(buffer->absFileName(), 20);
867 docstring text = bformat(_("Any changes will be lost. Are you sure "
868 "you want to revert to the saved version of the document %1$s?"), file);
869 int const ret = Alert::prompt(_("Revert to saved document?"),
870 text, 1, 1, _("&Revert"), _("&Cancel"));
877 case LFUN_BUFFER_UPDATE: {
878 LASSERT(lyx_view_ && buffer, /**/);
879 string format = argument;
880 if (argument.empty())
881 format = buffer->getDefaultOutputFormat();
882 buffer->doExport(format, true);
886 case LFUN_BUFFER_VIEW: {
887 LASSERT(lyx_view_ && buffer, /**/);
888 string format = argument;
889 if (argument.empty())
890 format = buffer->getDefaultOutputFormat();
891 buffer->preview(format);
895 case LFUN_MASTER_BUFFER_UPDATE: {
896 LASSERT(lyx_view_ && buffer && buffer->masterBuffer(), /**/);
897 string format = argument;
898 if (argument.empty())
899 format = buffer->masterBuffer()->getDefaultOutputFormat();
900 buffer->masterBuffer()->doExport(format, true);
904 case LFUN_MASTER_BUFFER_VIEW: {
905 LASSERT(lyx_view_ && buffer && buffer->masterBuffer(), /**/);
906 string format = argument;
907 if (argument.empty())
908 format = buffer->masterBuffer()->getDefaultOutputFormat();
909 buffer->masterBuffer()->preview(format);
913 case LFUN_BUILD_PROGRAM:
914 LASSERT(lyx_view_ && buffer, /**/);
915 buffer->doExport("program", true);
918 case LFUN_BUFFER_CHKTEX:
919 LASSERT(lyx_view_ && buffer, /**/);
923 case LFUN_BUFFER_EXPORT:
924 LASSERT(lyx_view_ && buffer, /**/);
925 if (argument == "custom")
926 dispatch(FuncRequest(LFUN_DIALOG_SHOW, "sendto"));
928 buffer->doExport(argument, false);
931 case LFUN_BUFFER_EXPORT_CUSTOM: {
932 LASSERT(lyx_view_ && buffer, /**/);
934 string command = split(argument, format_name, ' ');
935 Format const * format = formats.getFormat(format_name);
937 lyxerr << "Format \"" << format_name
938 << "\" not recognized!"
943 // The name of the file created by the conversion process
946 // Output to filename
947 if (format->name() == "lyx") {
948 string const latexname = buffer->latexName(false);
949 filename = changeExtension(latexname,
950 format->extension());
951 filename = addName(buffer->temppath(), filename);
953 if (!buffer->writeFile(FileName(filename)))
957 buffer->doExport(format_name, true, filename);
960 // Substitute $$FName for filename
961 if (!contains(command, "$$FName"))
962 command = "( " + command + " ) < $$FName";
963 command = subst(command, "$$FName", filename);
965 // Execute the command in the background
967 call.startscript(Systemcall::DontWait, command);
971 // FIXME: There is need for a command-line import.
973 case LFUN_BUFFER_IMPORT:
978 case LFUN_BUFFER_AUTO_SAVE:
982 case LFUN_RECONFIGURE:
983 // argument is any additional parameter to the configure.py command
984 reconfigure(lyx_view_, argument);
987 case LFUN_HELP_OPEN: {
989 theApp()->dispatch(FuncRequest(LFUN_WINDOW_NEW));
990 string const arg = argument;
992 setErrorMessage(from_utf8(N_("Missing argument")));
995 FileName fname = i18nLibFileSearch("doc", arg, "lyx");
997 fname = i18nLibFileSearch("examples", arg, "lyx");
1000 lyxerr << "LyX: unable to find documentation file `"
1001 << arg << "'. Bad installation?" << endl;
1004 lyx_view_->message(bformat(_("Opening help file %1$s..."),
1005 makeDisplayPath(fname.absFilename())));
1006 Buffer * buf = lyx_view_->loadDocument(fname, false);
1008 buf->updateLabels();
1009 lyx_view_->setBuffer(buf);
1010 buf->errors("Parse");
1012 updateFlags = Update::None;
1016 // --- version control -------------------------------
1017 case LFUN_VC_REGISTER:
1018 LASSERT(lyx_view_ && buffer, /**/);
1019 if (!ensureBufferClean(view()))
1021 if (!buffer->lyxvc().inUse()) {
1022 if (buffer->lyxvc().registrer())
1025 updateFlags = Update::Force;
1028 case LFUN_VC_CHECK_IN:
1029 LASSERT(lyx_view_ && buffer, /**/);
1030 if (!ensureBufferClean(view()))
1032 if (buffer->lyxvc().inUse()
1033 && !buffer->isReadonly()) {
1034 setMessage(from_utf8(buffer->lyxvc().checkIn()));
1039 case LFUN_VC_CHECK_OUT:
1040 LASSERT(lyx_view_ && buffer, /**/);
1041 if (!ensureBufferClean(view()))
1043 if (buffer->lyxvc().inUse()) {
1044 setMessage(from_utf8(buffer->lyxvc().checkOut()));
1049 case LFUN_VC_REVERT:
1050 LASSERT(lyx_view_ && buffer, /**/);
1051 buffer->lyxvc().revert();
1055 case LFUN_VC_UNDO_LAST:
1056 LASSERT(lyx_view_ && buffer, /**/);
1057 buffer->lyxvc().undoLast();
1061 // --- lyxserver commands ----------------------------
1062 case LFUN_SERVER_GET_FILENAME:
1063 LASSERT(lyx_view_ && buffer, /**/);
1064 setMessage(from_utf8(buffer->absFileName()));
1065 LYXERR(Debug::INFO, "FNAME["
1066 << buffer->absFileName() << ']');
1069 case LFUN_SERVER_NOTIFY:
1070 dispatch_buffer = keyseq.print(KeySequence::Portable);
1071 theServer().notifyClient(to_utf8(dispatch_buffer));
1074 case LFUN_SERVER_GOTO_FILE_ROW: {
1075 LASSERT(lyx_view_, /**/);
1078 istringstream is(argument);
1079 is >> file_name >> row;
1081 bool loaded = false;
1082 string const abstmp = package().temp_dir().absFilename();
1083 string const realtmp = package().temp_dir().realPath();
1084 if (prefixIs(file_name, abstmp) || prefixIs(file_name, realtmp)) {
1085 // Needed by inverse dvi search. If it is a file
1086 // in tmpdir, call the apropriated function.
1087 // If tmpdir is a symlink, we may have the real
1088 // path passed back, so we correct for that.
1089 if (!prefixIs(file_name, abstmp))
1090 file_name = subst(file_name, realtmp, abstmp);
1091 buf = theBufferList().getBufferFromTmp(file_name);
1093 // Must replace extension of the file to be .lyx
1094 // and get full path
1095 FileName const s = fileSearch(string(), changeExtension(file_name, ".lyx"), "lyx");
1096 // Either change buffer or load the file
1097 if (theBufferList().exists(s))
1098 buf = theBufferList().getBuffer(s);
1099 else if (s.exists()) {
1100 buf = lyx_view_->loadDocument(s);
1103 lyx_view_->message(bformat(
1104 _("File does not exist: %1$s"),
1105 makeDisplayPath(file_name)));
1109 updateFlags = Update::None;
1113 buf->updateLabels();
1114 lyx_view_->setBuffer(buf);
1115 view()->setCursorFromRow(row);
1117 buf->errors("Parse");
1118 updateFlags = Update::FitCursor;
1123 case LFUN_DIALOG_SHOW_NEW_INSET: {
1124 LASSERT(lyx_view_, /**/);
1125 string const name = cmd.getArg(0);
1126 InsetCode code = insetCode(name);
1127 string data = trim(to_utf8(cmd.argument()).substr(name.size()));
1128 bool insetCodeOK = true;
1137 case HYPERLINK_CODE: {
1138 InsetCommandParams p(code);
1139 data = InsetCommand::params2string(name, p);
1142 case INCLUDE_CODE: {
1143 // data is the include type: one of "include",
1144 // "input", "verbatiminput" or "verbatiminput*"
1146 // default type is requested
1148 InsetCommandParams p(INCLUDE_CODE, data);
1149 data = InsetCommand::params2string("include", p);
1153 // \c data == "Boxed" || "Frameless" etc
1154 InsetBoxParams p(data);
1155 data = InsetBox::params2string(p);
1159 InsetBranchParams p;
1160 data = InsetBranch::params2string(p);
1164 InsetCommandParams p(CITE_CODE);
1165 data = InsetCommand::params2string(name, p);
1169 data = InsetERT::params2string(InsetCollapsable::Open);
1172 case EXTERNAL_CODE: {
1173 InsetExternalParams p;
1174 data = InsetExternal::params2string(p, *buffer);
1179 data = InsetFloat::params2string(p);
1182 case LISTINGS_CODE: {
1183 InsetListingsParams p;
1184 data = InsetListings::params2string(p);
1187 case GRAPHICS_CODE: {
1188 InsetGraphicsParams p;
1189 data = InsetGraphics::params2string(p, *buffer);
1194 data = InsetNote::params2string(p);
1197 case PHANTOM_CODE: {
1198 InsetPhantomParams p;
1199 data = InsetPhantom::params2string(p);
1204 data = InsetSpace::params2string(p);
1209 data = InsetVSpace::params2string(space);
1214 data = InsetWrap::params2string(p);
1218 lyxerr << "Inset type '" << name <<
1219 "' not recognized in LFUN_DIALOG_SHOW_NEW_INSET" << endl;
1220 insetCodeOK = false;
1222 } // end switch(code)
1224 dispatch(FuncRequest(LFUN_DIALOG_SHOW, name + " " + data));
1228 case LFUN_CITATION_INSERT: {
1229 LASSERT(lyx_view_, /**/);
1230 if (!argument.empty()) {
1231 // we can have one optional argument, delimited by '|'
1232 // citation-insert <key>|<text_before>
1233 // this should be enhanced to also support text_after
1234 // and citation style
1235 string arg = argument;
1237 if (contains(argument, "|")) {
1238 arg = token(argument, '|', 0);
1239 opt1 = token(argument, '|', 1);
1241 InsetCommandParams icp(CITE_CODE);
1242 icp["key"] = from_utf8(arg);
1244 icp["before"] = from_utf8(opt1);
1245 string icstr = InsetCommand::params2string("citation", icp);
1246 FuncRequest fr(LFUN_INSET_INSERT, icstr);
1249 dispatch(FuncRequest(LFUN_DIALOG_SHOW_NEW_INSET, "citation"));
1253 case LFUN_BUFFER_CHILD_OPEN: {
1254 LASSERT(lyx_view_ && buffer, /**/);
1255 FileName filename = makeAbsPath(argument, buffer->filePath());
1256 view()->saveBookmark(false);
1258 bool parsed = false;
1259 if (theBufferList().exists(filename)) {
1260 child = theBufferList().getBuffer(filename);
1262 setMessage(bformat(_("Opening child document %1$s..."),
1263 makeDisplayPath(filename.absFilename())));
1264 child = lyx_view_->loadDocument(filename, false);
1268 // Set the parent name of the child document.
1269 // This makes insertion of citations and references in the child work,
1270 // when the target is in the parent or another child document.
1271 child->setParent(buffer);
1272 child->masterBuffer()->updateLabels();
1273 lyx_view_->setBuffer(child);
1275 child->errors("Parse");
1278 // If a screen update is required (in case where auto_open is false),
1279 // setBuffer() would have taken care of it already. Otherwise we shall
1280 // reset the update flag because it can cause a circular problem.
1282 updateFlags = Update::None;
1286 case LFUN_CURSOR_FOLLOWS_SCROLLBAR_TOGGLE:
1287 LASSERT(lyx_view_, /**/);
1288 lyxrc.cursor_follows_scrollbar = !lyxrc.cursor_follows_scrollbar;
1291 case LFUN_KEYMAP_OFF:
1292 LASSERT(lyx_view_ && lyx_view_->view(), /**/);
1293 lyx_view_->view()->getIntl().keyMapOn(false);
1296 case LFUN_KEYMAP_PRIMARY:
1297 LASSERT(lyx_view_ && lyx_view_->view(), /**/);
1298 lyx_view_->view()->getIntl().keyMapPrim();
1301 case LFUN_KEYMAP_SECONDARY:
1302 LASSERT(lyx_view_ && lyx_view_->view(), /**/);
1303 lyx_view_->view()->getIntl().keyMapSec();
1306 case LFUN_KEYMAP_TOGGLE:
1307 LASSERT(lyx_view_ && lyx_view_->view(), /**/);
1308 lyx_view_->view()->getIntl().toggleKeyMap();
1314 string rest = split(argument, countstr, ' ');
1315 istringstream is(countstr);
1318 //lyxerr << "repeat: count: " << count << " cmd: " << rest << endl;
1319 for (int i = 0; i < count; ++i)
1320 dispatch(lyxaction.lookupFunc(rest));
1324 case LFUN_COMMAND_SEQUENCE: {
1325 // argument contains ';'-terminated commands
1326 string arg = argument;
1327 if (theBufferList().isLoaded(buffer))
1328 buffer->undo().beginUndoGroup();
1329 while (!arg.empty()) {
1331 arg = split(arg, first, ';');
1332 FuncRequest func(lyxaction.lookupFunc(first));
1333 func.origin = cmd.origin;
1336 if (theBufferList().isLoaded(buffer))
1337 buffer->undo().endUndoGroup();
1341 case LFUN_COMMAND_ALTERNATIVES: {
1342 // argument contains ';'-terminated commands
1343 string arg = argument;
1344 while (!arg.empty()) {
1346 arg = split(arg, first, ';');
1347 FuncRequest func(lyxaction.lookupFunc(first));
1348 func.origin = cmd.origin;
1349 FuncStatus stat = getStatus(func);
1350 if (stat.enabled()) {
1360 if (theTopLevelCmdDef().lock(argument, func)) {
1361 func.origin = cmd.origin;
1363 theTopLevelCmdDef().release(argument);
1365 if (func.action == LFUN_UNKNOWN_ACTION) {
1366 // unknown command definition
1367 lyxerr << "Warning: unknown command definition `"
1371 // recursion detected
1372 lyxerr << "Warning: Recursion in the command definition `"
1373 << argument << "' detected"
1380 case LFUN_PREFERENCES_SAVE: {
1381 lyxrc.write(makeAbsPath("preferences",
1382 package().user_support().absFilename()),
1388 LASSERT(lyx_view_, /**/);
1389 lyx_view_->message(from_utf8(argument));
1392 case LFUN_BUFFER_LANGUAGE: {
1393 LASSERT(lyx_view_, /**/);
1394 Language const * oldL = buffer->params().language;
1395 Language const * newL = languages.getLanguage(argument);
1396 if (!newL || oldL == newL)
1399 if (oldL->rightToLeft() == newL->rightToLeft()
1400 && !buffer->isMultiLingual())
1401 buffer->changeLanguage(oldL, newL);
1405 case LFUN_BUFFER_SAVE_AS_DEFAULT: {
1406 string const fname =
1407 addName(addPath(package().user_support().absFilename(), "templates/"),
1409 Buffer defaults(fname);
1411 istringstream ss(argument);
1414 int const unknown_tokens = defaults.readHeader(lex);
1416 if (unknown_tokens != 0) {
1417 lyxerr << "Warning in LFUN_BUFFER_SAVE_AS_DEFAULT!\n"
1418 << unknown_tokens << " unknown token"
1419 << (unknown_tokens == 1 ? "" : "s")
1423 if (defaults.writeFile(FileName(defaults.absFileName())))
1424 setMessage(bformat(_("Document defaults saved in %1$s"),
1425 makeDisplayPath(fname)));
1427 setErrorMessage(from_ascii(N_("Unable to save document defaults")));
1431 case LFUN_BUFFER_PARAMS_APPLY: {
1432 LASSERT(lyx_view_, /**/);
1434 DocumentClass const * const oldClass = buffer->params().documentClassPtr();
1435 Cursor & cur = view()->cursor();
1436 cur.recordUndoFullDocument();
1438 istringstream ss(argument);
1441 int const unknown_tokens = buffer->readHeader(lex);
1443 if (unknown_tokens != 0) {
1444 lyxerr << "Warning in LFUN_BUFFER_PARAMS_APPLY!\n"
1445 << unknown_tokens << " unknown token"
1446 << (unknown_tokens == 1 ? "" : "s")
1450 updateLayout(oldClass, buffer);
1452 updateFlags = Update::Force | Update::FitCursor;
1453 // We are most certainly here because of a change in the document
1454 // It is then better to make sure that all dialogs are in sync with
1455 // current document settings. LyXView::restartCursor() achieve this.
1456 lyx_view_->restartCursor();
1460 case LFUN_LAYOUT_MODULES_CLEAR: {
1461 LASSERT(lyx_view_, /**/);
1462 DocumentClass const * const oldClass = buffer->params().documentClassPtr();
1463 view()->cursor().recordUndoFullDocument();
1464 buffer->params().clearLayoutModules();
1465 buffer->params().makeDocumentClass();
1466 updateLayout(oldClass, buffer);
1467 updateFlags = Update::Force | Update::FitCursor;
1471 case LFUN_LAYOUT_MODULE_ADD: {
1472 LASSERT(lyx_view_, /**/);
1473 BufferParams const & params = buffer->params();
1474 if (!params.moduleCanBeAdded(argument)) {
1475 LYXERR0("Module `" << argument <<
1476 "' cannot be added due to failed requirements or "
1477 "conflicts with installed modules.");
1480 DocumentClass const * const oldClass = params.documentClassPtr();
1481 view()->cursor().recordUndoFullDocument();
1482 buffer->params().addLayoutModule(argument);
1483 buffer->params().makeDocumentClass();
1484 updateLayout(oldClass, buffer);
1485 updateFlags = Update::Force | Update::FitCursor;
1489 case LFUN_TEXTCLASS_APPLY: {
1490 LASSERT(lyx_view_, /**/);
1492 if (!loadLayoutFile(argument, buffer->temppath()) &&
1493 !loadLayoutFile(argument, buffer->filePath()))
1496 LayoutFile const * old_layout = buffer->params().baseClass();
1497 LayoutFile const * new_layout = &(LayoutFileList::get()[argument]);
1499 if (old_layout == new_layout)
1503 //Save the old, possibly modular, layout for use in conversion.
1504 DocumentClass const * const oldDocClass = buffer->params().documentClassPtr();
1505 view()->cursor().recordUndoFullDocument();
1506 buffer->params().setBaseClass(argument);
1507 buffer->params().makeDocumentClass();
1508 updateLayout(oldDocClass, buffer);
1509 updateFlags = Update::Force | Update::FitCursor;
1513 case LFUN_LAYOUT_RELOAD: {
1514 LASSERT(lyx_view_, /**/);
1515 DocumentClass const * const oldClass = buffer->params().documentClassPtr();
1516 LayoutFileIndex bc = buffer->params().baseClassID();
1517 LayoutFileList::get().reset(bc);
1518 buffer->params().setBaseClass(bc);
1519 buffer->params().makeDocumentClass();
1520 updateLayout(oldClass, buffer);
1521 updateFlags = Update::Force | Update::FitCursor;
1525 case LFUN_TEXTCLASS_LOAD:
1526 loadLayoutFile(argument, buffer->temppath()) ||
1527 loadLayoutFile(argument, buffer->filePath());
1530 case LFUN_LYXRC_APPLY: {
1531 LyXRC const lyxrc_orig = lyxrc;
1533 istringstream ss(argument);
1534 bool const success = lyxrc.read(ss) == 0;
1537 lyxerr << "Warning in LFUN_LYXRC_APPLY!\n"
1538 << "Unable to read lyxrc data"
1543 actOnUpdatedPrefs(lyxrc_orig, lyxrc);
1545 theApp()->resetGui();
1547 /// We force the redraw in any case because there might be
1548 /// some screen font changes.
1549 /// FIXME: only the current view will be updated. the Gui
1550 /// class is able to furnish the list of views.
1551 updateFlags = Update::Force;
1555 case LFUN_BOOKMARK_GOTO:
1556 // go to bookmark, open unopened file and switch to buffer if necessary
1557 gotoBookmark(convert<unsigned int>(to_utf8(cmd.argument())), true, true);
1558 updateFlags = Update::FitCursor;
1561 case LFUN_BOOKMARK_CLEAR:
1562 theSession().bookmarks().clear();
1565 case LFUN_VC_COMMAND: {
1566 string flag = cmd.getArg(0);
1567 if (buffer && contains(flag, 'R') && !ensureBufferClean(view()))
1570 if (contains(flag, 'M'))
1571 if (!Alert::askForText(message, _("LyX VC: Log Message")))
1574 string path = cmd.getArg(1);
1575 if (contains(path, "$$p") && buffer)
1576 path = subst(path, "$$p", buffer->filePath());
1577 LYXERR(Debug::LYXVC, "Directory: " << path);
1579 if (!pp.isReadableDirectory()) {
1580 lyxerr << _("Directory is not accessible.") << endl;
1583 support::PathChanger p(pp);
1585 string command = cmd.getArg(2);
1586 if (command.empty())
1589 command = subst(command, "$$i", buffer->absFileName());
1590 command = subst(command, "$$p", buffer->filePath());
1592 command = subst(command, "$$m", to_utf8(message));
1593 LYXERR(Debug::LYXVC, "Command: " << command);
1595 one.startscript(Systemcall::Wait, command);
1599 if (contains(flag, 'I'))
1600 buffer->markDirty();
1601 if (contains(flag, 'R'))
1608 LASSERT(theApp(), /**/);
1609 // Let the frontend dispatch its own actions.
1610 if (theApp()->dispatch(cmd))
1611 // Nothing more to do.
1614 // Everything below is only for active lyx_view_
1618 // Start an undo group. This may be needed for
1619 // some stuff like inset-apply on labels.
1620 if (theBufferList().isLoaded(buffer))
1621 buffer->undo().beginUndoGroup();
1623 // Let the current LyXView dispatch its own actions.
1624 if (lyx_view_->dispatch(cmd)) {
1625 if (lyx_view_->view()) {
1626 updateFlags = lyx_view_->view()->cursor().result().update();
1627 if (theBufferList().isLoaded(buffer))
1628 buffer->undo().endUndoGroup();
1633 LASSERT(lyx_view_->view(), /**/);
1635 // Let the current BufferView dispatch its own actions.
1636 if (view()->dispatch(cmd)) {
1637 // The BufferView took care of its own updates if needed.
1638 updateFlags = Update::None;
1639 if (theBufferList().isLoaded(buffer))
1640 buffer->undo().endUndoGroup();
1644 // OK, so try the Buffer itself
1646 view()->buffer().dispatch(cmd, dr);
1647 if (dr.dispatched()) {
1648 updateFlags = dr.update();
1652 // Is this a function that acts on inset at point?
1653 Inset * inset = view()->cursor().nextInset();
1654 if (lyxaction.funcHasFlag(action, LyXAction::AtPoint)
1656 view()->cursor().result().dispatched(true);
1657 view()->cursor().result().update(Update::FitCursor | Update::Force);
1658 FuncRequest tmpcmd = cmd;
1659 inset->dispatch(view()->cursor(), tmpcmd);
1660 if (view()->cursor().result().dispatched()) {
1661 updateFlags = view()->cursor().result().update();
1666 // Let the current Cursor dispatch its own actions.
1667 Cursor old = view()->cursor();
1668 view()->cursor().getPos(cursorPosBeforeDispatchX_,
1669 cursorPosBeforeDispatchY_);
1670 view()->cursor().dispatch(cmd);
1672 // notify insets we just left
1673 if (view()->cursor() != old) {
1675 bool badcursor = notifyCursorLeavesOrEnters(old, view()->cursor());
1677 view()->cursor().fixIfBroken();
1680 if (theBufferList().isLoaded(buffer))
1681 buffer->undo().endUndoGroup();
1683 // update completion. We do it here and not in
1684 // processKeySym to avoid another redraw just for a
1685 // changed inline completion
1686 if (cmd.origin == FuncRequest::KEYBOARD) {
1687 if (cmd.action == LFUN_SELF_INSERT)
1688 lyx_view_->updateCompletion(view()->cursor(), true, true);
1689 else if (cmd.action == LFUN_CHAR_DELETE_BACKWARD)
1690 lyx_view_->updateCompletion(view()->cursor(), false, true);
1692 lyx_view_->updateCompletion(view()->cursor(), false, false);
1695 updateFlags = view()->cursor().result().update();
1698 // if we executed a mutating lfun, mark the buffer as dirty
1699 if (theBufferList().isLoaded(buffer) && flag.enabled()
1700 && !lyxaction.funcHasFlag(action, LyXAction::NoBuffer)
1701 && !lyxaction.funcHasFlag(action, LyXAction::ReadOnly))
1702 buffer->markDirty();
1704 if (lyx_view_ && lyx_view_->buffer()) {
1705 // BufferView::update() updates the ViewMetricsInfo and
1706 // also initializes the position cache for all insets in
1707 // (at least partially) visible top-level paragraphs.
1708 // We will redraw the screen only if needed.
1709 view()->processUpdateFlags(updateFlags);
1711 // Do we have a selection?
1712 theSelection().haveSelection(view()->cursor().selection());
1715 lyx_view_->restartCursor();
1719 // Some messages may already be translated, so we cannot use _()
1720 sendDispatchMessage(translateIfPossible(getMessage()), cmd);
1725 void LyXFunc::sendDispatchMessage(docstring const & msg, FuncRequest const & cmd)
1727 const bool verbose = (cmd.origin == FuncRequest::MENU
1728 || cmd.origin == FuncRequest::TOOLBAR
1729 || cmd.origin == FuncRequest::COMMANDBUFFER);
1731 if (cmd.action == LFUN_SELF_INSERT || !verbose) {
1732 LYXERR(Debug::ACTION, "dispatch msg is " << to_utf8(msg));
1734 lyx_view_->message(msg);
1738 docstring dispatch_msg = msg;
1739 if (!dispatch_msg.empty())
1740 dispatch_msg += ' ';
1742 docstring comname = from_utf8(lyxaction.getActionName(cmd.action));
1744 bool argsadded = false;
1746 if (!cmd.argument().empty()) {
1747 if (cmd.action != LFUN_UNKNOWN_ACTION) {
1748 comname += ' ' + cmd.argument();
1753 docstring const shortcuts = theTopLevelKeymap().printBindings(cmd, KeySequence::ForGui);
1755 if (!shortcuts.empty())
1756 comname += ": " + shortcuts;
1757 else if (!argsadded && !cmd.argument().empty())
1758 comname += ' ' + cmd.argument();
1760 if (!comname.empty()) {
1761 comname = rtrim(comname);
1762 dispatch_msg += '(' + rtrim(comname) + ')';
1765 LYXERR(Debug::ACTION, "verbose dispatch msg " << to_utf8(dispatch_msg));
1766 if (!dispatch_msg.empty())
1767 lyx_view_->message(dispatch_msg);
1771 void LyXFunc::reloadBuffer()
1773 FileName filename = lyx_view_->buffer()->fileName();
1774 // The user has already confirmed that the changes, if any, should
1775 // be discarded. So we just release the Buffer and don't call closeBuffer();
1776 theBufferList().release(lyx_view_->buffer());
1777 // if the lyx_view_ has been destroyed, create a new one
1779 theApp()->dispatch(FuncRequest(LFUN_WINDOW_NEW));
1780 Buffer * buf = lyx_view_->loadDocument(filename);
1781 docstring const disp_fn = makeDisplayPath(filename.absFilename());
1784 buf->updateLabels();
1785 lyx_view_->setBuffer(buf);
1786 buf->errors("Parse");
1787 str = bformat(_("Document %1$s reloaded."), disp_fn);
1789 str = bformat(_("Could not reload document %1$s"), disp_fn);
1791 lyx_view_->message(str);
1794 // Each "lyx_view_" should have it's own message method. lyxview and
1795 // the minibuffer would use the minibuffer, but lyxserver would
1796 // send an ERROR signal to its client. Alejandro 970603
1797 // This function is bit problematic when it comes to NLS, to make the
1798 // lyx servers client be language indepenent we must not translate
1799 // strings sent to this func.
1800 void LyXFunc::setErrorMessage(docstring const & m) const
1802 dispatch_buffer = m;
1807 void LyXFunc::setMessage(docstring const & m) const
1809 dispatch_buffer = m;
1813 docstring LyXFunc::viewStatusMessage()
1815 // When meta-fake key is pressed, show the key sequence so far + "M-".
1817 return keyseq.print(KeySequence::ForGui) + "M-";
1819 // Else, when a non-complete key sequence is pressed,
1820 // show the available options.
1821 if (keyseq.length() > 0 && !keyseq.deleted())
1822 return keyseq.printOptions(true);
1824 LASSERT(lyx_view_, /**/);
1825 if (!lyx_view_->buffer())
1826 return _("Welcome to LyX!");
1828 return view()->cursor().currentState();
1832 BufferView * LyXFunc::view() const
1834 LASSERT(lyx_view_, /**/);
1835 return lyx_view_->view();
1839 bool LyXFunc::wasMetaKey() const
1841 return (meta_fake_bit != NoModifier);
1845 void LyXFunc::updateLayout(DocumentClass const * const oldlayout, Buffer * buf)
1847 lyx_view_->message(_("Converting document to new document class..."));
1849 StableDocIterator backcur(view()->cursor());
1850 ErrorList & el = buf->errorList("Class Switch");
1851 cap::switchBetweenClasses(
1852 oldlayout, buf->params().documentClassPtr(),
1853 static_cast<InsetText &>(buf->inset()), el);
1855 view()->setCursor(backcur.asDocIterator(buf));
1857 buf->errors("Class Switch");
1858 buf->updateLabels();
1864 void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
1866 // Why the switch you might ask. It is a trick to ensure that all
1867 // the elements in the LyXRCTags enum is handled. As you can see
1868 // there are no breaks at all. So it is just a huge fall-through.
1869 // The nice thing is that we will get a warning from the compiler
1870 // if we forget an element.
1871 LyXRC::LyXRCTags tag = LyXRC::RC_LAST;
1873 case LyXRC::RC_ACCEPT_COMPOUND:
1874 case LyXRC::RC_ALT_LANG:
1875 case LyXRC::RC_PLAINTEXT_LINELEN:
1876 case LyXRC::RC_PLAINTEXT_ROFF_COMMAND:
1877 case LyXRC::RC_AUTOCORRECTION_MATH:
1878 case LyXRC::RC_AUTOREGIONDELETE:
1879 case LyXRC::RC_AUTORESET_OPTIONS:
1880 case LyXRC::RC_AUTOSAVE:
1881 case LyXRC::RC_AUTO_NUMBER:
1882 case LyXRC::RC_BACKUPDIR_PATH:
1883 case LyXRC::RC_BIBTEX_COMMAND:
1884 case LyXRC::RC_BINDFILE:
1885 case LyXRC::RC_CHECKLASTFILES:
1886 case LyXRC::RC_COMPLETION_CURSOR_TEXT:
1887 case LyXRC::RC_COMPLETION_INLINE_DELAY:
1888 case LyXRC::RC_COMPLETION_INLINE_DOTS:
1889 case LyXRC::RC_COMPLETION_INLINE_MATH:
1890 case LyXRC::RC_COMPLETION_INLINE_TEXT:
1891 case LyXRC::RC_COMPLETION_POPUP_AFTER_COMPLETE:
1892 case LyXRC::RC_COMPLETION_POPUP_DELAY:
1893 case LyXRC::RC_COMPLETION_POPUP_MATH:
1894 case LyXRC::RC_COMPLETION_POPUP_TEXT:
1895 case LyXRC::RC_USELASTFILEPOS:
1896 case LyXRC::RC_LOADSESSION:
1897 case LyXRC::RC_CHKTEX_COMMAND:
1898 case LyXRC::RC_CONVERTER:
1899 case LyXRC::RC_CONVERTER_CACHE_MAXAGE:
1900 case LyXRC::RC_COPIER:
1901 case LyXRC::RC_CURSOR_FOLLOWS_SCROLLBAR:
1902 case LyXRC::RC_SCROLL_BELOW_DOCUMENT:
1903 case LyXRC::RC_DATE_INSERT_FORMAT:
1904 case LyXRC::RC_DEFAULT_LANGUAGE:
1905 case LyXRC::RC_GUI_LANGUAGE:
1906 case LyXRC::RC_DEFAULT_PAPERSIZE:
1907 case LyXRC::RC_DEFAULT_VIEW_FORMAT:
1908 case LyXRC::RC_DEFFILE:
1909 case LyXRC::RC_DIALOGS_ICONIFY_WITH_MAIN:
1910 case LyXRC::RC_DISPLAY_GRAPHICS:
1911 case LyXRC::RC_DOCUMENTPATH:
1912 if (lyxrc_orig.document_path != lyxrc_new.document_path) {
1913 FileName path(lyxrc_new.document_path);
1914 if (path.exists() && path.isDirectory())
1915 package().document_dir() = FileName(lyxrc.document_path);
1917 case LyXRC::RC_ESC_CHARS:
1918 case LyXRC::RC_EXAMPLEPATH:
1919 case LyXRC::RC_FONT_ENCODING:
1920 case LyXRC::RC_FORMAT:
1921 case LyXRC::RC_GROUP_LAYOUTS:
1922 case LyXRC::RC_INDEX_COMMAND:
1923 case LyXRC::RC_JBIBTEX_COMMAND:
1924 case LyXRC::RC_JINDEX_COMMAND:
1925 case LyXRC::RC_NOMENCL_COMMAND:
1926 case LyXRC::RC_INPUT:
1927 case LyXRC::RC_KBMAP:
1928 case LyXRC::RC_KBMAP_PRIMARY:
1929 case LyXRC::RC_KBMAP_SECONDARY:
1930 case LyXRC::RC_LABEL_INIT_LENGTH:
1931 case LyXRC::RC_LANGUAGE_AUTO_BEGIN:
1932 case LyXRC::RC_LANGUAGE_AUTO_END:
1933 case LyXRC::RC_LANGUAGE_COMMAND_BEGIN:
1934 case LyXRC::RC_LANGUAGE_COMMAND_END:
1935 case LyXRC::RC_LANGUAGE_COMMAND_LOCAL:
1936 case LyXRC::RC_LANGUAGE_GLOBAL_OPTIONS:
1937 case LyXRC::RC_LANGUAGE_PACKAGE:
1938 case LyXRC::RC_LANGUAGE_USE_BABEL:
1939 case LyXRC::RC_MAC_LIKE_WORD_MOVEMENT:
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_OPEN_BUFFERS_IN_TABS:
1987 case LyXRC::RC_SPELL_COMMAND:
1988 case LyXRC::RC_SPELLCHECK_CONTINUOUSLY:
1989 case LyXRC::RC_SPLITINDEX_COMMAND:
1990 case LyXRC::RC_TEMPDIRPATH:
1991 case LyXRC::RC_TEMPLATEPATH:
1992 case LyXRC::RC_TEX_ALLOWS_SPACES:
1993 case LyXRC::RC_TEX_EXPECTS_WINDOWS_PATHS:
1994 if (lyxrc_orig.windows_style_tex_paths != lyxrc_new.windows_style_tex_paths) {
1995 os::windows_style_tex_paths(lyxrc_new.windows_style_tex_paths);
1997 case LyXRC::RC_THESAURUSDIRPATH:
1998 case LyXRC::RC_UIFILE:
1999 case LyXRC::RC_USER_EMAIL:
2000 case LyXRC::RC_USER_NAME:
2001 case LyXRC::RC_USETEMPDIR:
2002 case LyXRC::RC_USE_ALT_LANG:
2003 case LyXRC::RC_USE_CONVERTER_CACHE:
2004 case LyXRC::RC_USE_ESC_CHARS:
2005 case LyXRC::RC_USE_INP_ENC:
2006 case LyXRC::RC_USE_PERS_DICT:
2007 case LyXRC::RC_USE_TOOLTIP:
2008 case LyXRC::RC_USE_PIXMAP_CACHE:
2009 case LyXRC::RC_USE_SPELL_LIB:
2010 case LyXRC::RC_VIEWDVI_PAPEROPTION:
2011 case LyXRC::RC_SORT_LAYOUTS:
2012 case LyXRC::RC_FULL_SCREEN_LIMIT:
2013 case LyXRC::RC_FULL_SCREEN_SCROLLBAR:
2014 case LyXRC::RC_FULL_SCREEN_TABBAR:
2015 case LyXRC::RC_FULL_SCREEN_TOOLBARS:
2016 case LyXRC::RC_FULL_SCREEN_WIDTH:
2017 case LyXRC::RC_VISUAL_CURSOR:
2018 case LyXRC::RC_VIEWER:
2019 case LyXRC::RC_LAST: