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"
58 #include "SpellChecker.h"
60 #include "insets/InsetBox.h"
61 #include "insets/InsetBranch.h"
62 #include "insets/InsetCommand.h"
63 #include "insets/InsetERT.h"
64 #include "insets/InsetExternal.h"
65 #include "insets/InsetFloat.h"
66 #include "insets/InsetGraphics.h"
67 #include "insets/InsetInclude.h"
68 #include "insets/InsetListings.h"
69 #include "insets/InsetNote.h"
70 #include "insets/InsetPhantom.h"
71 #include "insets/InsetSpace.h"
72 #include "insets/InsetTabular.h"
73 #include "insets/InsetVSpace.h"
74 #include "insets/InsetWrap.h"
76 #include "frontends/alert.h"
77 #include "frontends/Application.h"
78 #include "frontends/KeySymbol.h"
79 #include "frontends/LyXView.h"
80 #include "frontends/Selection.h"
82 #include "support/debug.h"
83 #include "support/environment.h"
84 #include "support/FileName.h"
85 #include "support/filetools.h"
86 #include "support/gettext.h"
87 #include "support/lstrings.h"
88 #include "support/Path.h"
89 #include "support/Package.h"
90 #include "support/Systemcall.h"
91 #include "support/convert.h"
92 #include "support/os.h"
98 using namespace lyx::support;
102 using frontend::LyXView;
104 namespace Alert = frontend::Alert;
109 // This function runs "configure" and then rereads lyx.defaults to
110 // reconfigure the automatic settings.
111 void reconfigure(LyXView * lv, string const & option)
113 // emit message signal.
115 lv->message(_("Running configure..."));
117 // Run configure in user lyx directory
118 PathChanger p(package().user_support());
119 string configure_command = package().configure_command();
120 configure_command += option;
122 int ret = one.startscript(Systemcall::Wait, configure_command);
124 // emit message signal.
126 lv->message(_("Reloading configuration..."));
127 lyxrc.read(libFileSearch(string(), "lyxrc.defaults"));
128 // Re-read packages.lst
129 LaTeXFeatures::getAvailable();
132 Alert::information(_("System reconfiguration failed"),
133 _("The system reconfiguration has failed.\n"
134 "Default textclass is used but LyX may "
135 "not be able to work properly.\n"
136 "Please reconfigure again if needed."));
139 Alert::information(_("System reconfigured"),
140 _("The system has been reconfigured.\n"
141 "You need to restart LyX to make use of any\n"
142 "updated document class specifications."));
149 : encoded_last_key(0), meta_fake_bit(NoModifier)
154 void LyXFunc::initKeySequences(KeyMap * kb)
156 keyseq = KeySequence(kb, kb);
157 cancel_meta_seq = KeySequence(kb, kb);
161 void LyXFunc::handleKeyFunc(FuncCode action)
163 char_type c = encoded_last_key;
167 LyXView * lv = theApp()->currentWindow();
168 LASSERT(lv && lv->currentBufferView(), /**/);
169 BufferView * bv = lv->currentBufferView();
170 bv->getIntl().getTransManager().deadkey(
171 c, get_accent(action).accent, bv->cursor().innerText(),
173 // Need to clear, in case the minibuffer calls these
176 // copied verbatim from do_accent_char
177 bv->cursor().resetAnchor();
178 bv->processUpdateFlags(Update::FitCursor);
181 //FIXME: bookmark handling is a frontend issue. This code should be transferred
182 // to GuiView and be GuiView and be window dependent.
183 void LyXFunc::gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer)
185 LyXView * lv = theApp()->currentWindow();
187 if (!theSession().bookmarks().isValid(idx))
189 BookmarksSection::Bookmark const & bm = theSession().bookmarks().bookmark(idx);
190 LASSERT(!bm.filename.empty(), /**/);
191 string const file = bm.filename.absFilename();
192 // if the file is not opened, open it.
193 if (!theBufferList().exists(bm.filename)) {
195 dispatch(FuncRequest(LFUN_FILE_OPEN, file));
199 // open may fail, so we need to test it again
200 if (!theBufferList().exists(bm.filename))
203 // bm can be changed when saving
204 BookmarksSection::Bookmark tmp = bm;
206 // Special case idx == 0 used for back-from-back jump navigation
208 dispatch(FuncRequest(LFUN_BOOKMARK_SAVE, "0"));
210 // if the current buffer is not that one, switch to it.
211 if (!lv->documentBufferView()
212 || lv->documentBufferView()->buffer().fileName() != tmp.filename) {
215 dispatch(FuncRequest(LFUN_BUFFER_SWITCH, file));
218 // moveToPosition try paragraph id first and then paragraph (pit, pos).
219 if (!lv->documentBufferView()->moveToPosition(
220 tmp.bottom_pit, tmp.bottom_pos, tmp.top_id, tmp.top_pos))
227 // Cursor jump succeeded!
228 Cursor const & cur = lv->documentBufferView()->cursor();
229 pit_type new_pit = cur.pit();
230 pos_type new_pos = cur.pos();
231 int new_id = cur.paragraph().id();
233 // if bottom_pit, bottom_pos or top_id has been changed, update bookmark
234 // see http://bugzilla.lyx.org/show_bug.cgi?id=3092
235 if (bm.bottom_pit != new_pit || bm.bottom_pos != new_pos
236 || bm.top_id != new_id) {
237 const_cast<BookmarksSection::Bookmark &>(bm).updatePos(
238 new_pit, new_pos, new_id);
243 void LyXFunc::processKeySym(KeySymbol const & keysym, KeyModifier state)
245 LYXERR(Debug::KEY, "KeySym is " << keysym.getSymbolName());
247 LyXView * lv = theApp()->currentWindow();
249 // Do nothing if we have nothing (JMarc)
250 if (!keysym.isOK()) {
251 LYXERR(Debug::KEY, "Empty kbd action (probably composing)");
256 if (keysym.isModifier()) {
257 LYXERR(Debug::KEY, "isModifier true");
263 //Encoding const * encoding = lv->documentBufferView()->cursor().getEncoding();
264 //encoded_last_key = keysym.getISOEncoded(encoding ? encoding->name() : "");
265 // FIXME: encoded_last_key shadows the member variable of the same
266 // name. Is that intended?
267 char_type encoded_last_key = keysym.getUCSEncoded();
269 // Do a one-deep top-level lookup for
270 // cancel and meta-fake keys. RVDK_PATCH_5
271 cancel_meta_seq.reset();
273 FuncRequest func = cancel_meta_seq.addkey(keysym, state);
274 LYXERR(Debug::KEY, "action first set to [" << func.action << ']');
276 // When not cancel or meta-fake, do the normal lookup.
277 // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
278 // Mostly, meta_fake_bit = NoModifier. RVDK_PATCH_5.
279 if ((func.action != LFUN_CANCEL) && (func.action != LFUN_META_PREFIX)) {
280 // remove Caps Lock and Mod2 as a modifiers
281 func = keyseq.addkey(keysym, (state | meta_fake_bit));
282 LYXERR(Debug::KEY, "action now set to [" << func.action << ']');
285 // Dont remove this unless you know what you are doing.
286 meta_fake_bit = NoModifier;
288 // Can this happen now ?
289 if (func.action == LFUN_NOACTION)
290 func = FuncRequest(LFUN_COMMAND_PREFIX);
292 LYXERR(Debug::KEY, " Key [action=" << func.action << "]["
293 << keyseq.print(KeySequence::Portable) << ']');
295 // already here we know if it any point in going further
296 // why not return already here if action == -1 and
297 // num_bytes == 0? (Lgb)
299 if (keyseq.length() > 1)
300 lv->message(keyseq.print(KeySequence::ForGui));
303 // Maybe user can only reach the key via holding down shift.
304 // Let's see. But only if shift is the only modifier
305 if (func.action == LFUN_UNKNOWN_ACTION && state == ShiftModifier) {
306 LYXERR(Debug::KEY, "Trying without shift");
307 func = keyseq.addkey(keysym, NoModifier);
308 LYXERR(Debug::KEY, "Action now " << func.action);
311 if (func.action == LFUN_UNKNOWN_ACTION) {
312 // Hmm, we didn't match any of the keysequences. See
313 // if it's normal insertable text not already covered
315 if (keysym.isText() && keyseq.length() == 1) {
316 LYXERR(Debug::KEY, "isText() is true, inserting.");
317 func = FuncRequest(LFUN_SELF_INSERT,
318 FuncRequest::KEYBOARD);
320 LYXERR(Debug::KEY, "Unknown, !isText() - giving up");
321 lv->message(_("Unknown function."));
327 if (func.action == LFUN_SELF_INSERT) {
328 if (encoded_last_key != 0) {
329 docstring const arg(1, encoded_last_key);
330 dispatch(FuncRequest(LFUN_SELF_INSERT, arg,
331 FuncRequest::KEYBOARD));
332 LYXERR(Debug::KEY, "SelfInsert arg[`" << to_utf8(arg) << "']");
342 FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
344 //lyxerr << "LyXFunc::getStatus: cmd: " << cmd << endl;
347 if (cmd.action == LFUN_NOACTION) {
348 flag.message(from_utf8(N_("Nothing to do")));
349 flag.setEnabled(false);
353 switch (cmd.action) {
354 case LFUN_UNKNOWN_ACTION:
356 flag.setEnabled(false);
363 if (flag.unknown()) {
364 flag.message(from_utf8(N_("Unknown action")));
368 if (!flag.enabled()) {
369 if (flag.message().empty())
370 flag.message(from_utf8(N_("Command disabled")));
374 // I would really like to avoid having this switch and rather try to
375 // encode this in the function itself.
376 // -- And I'd rather let an inset decide which LFUNs it is willing
377 // to handle (Andre')
379 switch (cmd.action) {
381 case LFUN_CITATION_INSERT: {
382 FuncRequest fr(LFUN_INSET_INSERT, "citation");
383 enable = getStatus(fr).enabled();
387 // This could be used for the no-GUI version. The GUI version is handled in
388 // LyXView::getStatus(). See above.
390 case LFUN_BUFFER_WRITE:
391 case LFUN_BUFFER_WRITE_AS: {
392 Buffer * b = theBufferList().getBuffer(FileName(cmd.getArg(0)));
393 enable = b && (b->isUnnamed() || !b->isClean());
398 case LFUN_BOOKMARK_GOTO: {
399 const unsigned int num = convert<unsigned int>(to_utf8(cmd.argument()));
400 enable = theSession().bookmarks().isValid(num);
404 case LFUN_BOOKMARK_CLEAR:
405 enable = theSession().bookmarks().hasValid();
408 // this one is difficult to get right. As a half-baked
409 // solution, we consider only the first action of the sequence
410 case LFUN_COMMAND_SEQUENCE: {
411 // argument contains ';'-terminated commands
412 string const firstcmd = token(to_utf8(cmd.argument()), ';', 0);
413 FuncRequest func(lyxaction.lookupFunc(firstcmd));
414 func.origin = cmd.origin;
415 flag = getStatus(func);
419 // we want to check if at least one of these is enabled
420 case LFUN_COMMAND_ALTERNATIVES: {
421 // argument contains ';'-terminated commands
422 string arg = to_utf8(cmd.argument());
423 while (!arg.empty()) {
425 arg = split(arg, first, ';');
426 FuncRequest func(lyxaction.lookupFunc(first));
427 func.origin = cmd.origin;
428 flag = getStatus(func);
429 // if this one is enabled, the whole thing is
438 string name = to_utf8(cmd.argument());
439 if (theTopLevelCmdDef().lock(name, func)) {
440 func.origin = cmd.origin;
441 flag = getStatus(func);
442 theTopLevelCmdDef().release(name);
444 // catch recursion or unknown command
445 // definition. all operations until the
446 // recursion or unknown command definition
447 // occurs are performed, so set the state to
454 case LFUN_COMMAND_PREFIX:
456 case LFUN_META_PREFIX:
457 case LFUN_RECONFIGURE:
458 case LFUN_DROP_LAYOUTS_CHOICE:
459 case LFUN_SERVER_GET_FILENAME:
460 case LFUN_SERVER_NOTIFY:
461 case LFUN_CURSOR_FOLLOWS_SCROLLBAR_TOGGLE:
463 case LFUN_PREFERENCES_SAVE:
464 case LFUN_INSET_EDIT:
465 case LFUN_BUFFER_SAVE_AS_DEFAULT:
466 case LFUN_LYXRC_APPLY:
467 // these are handled in our dispatch()
475 if (theApp()->getStatus(cmd, flag))
478 // Does the view know something?
479 LyXView * lv = theApp()->currentWindow();
484 if (lv->getStatus(cmd, flag))
487 BufferView * bv = lv->currentBufferView();
488 BufferView * doc_bv = lv->documentBufferView();
489 // If we do not have a BufferView, then other functions are disabled
494 // try the BufferView
495 bool decided = bv->getStatus(cmd, flag);
498 decided = bv->buffer().getStatus(cmd, flag);
499 if (!decided && doc_bv)
500 // try the Document Buffer
501 decided = doc_bv->buffer().getStatus(cmd, flag);
505 flag.setEnabled(false);
507 // the default error message if we disable the command
508 if (!flag.enabled() && flag.message().empty())
509 flag.message(from_utf8(N_("Command disabled")));
517 void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new);
522 void LyXFunc::dispatch(FuncRequest const & cmd)
524 string const argument = to_utf8(cmd.argument());
525 FuncCode const action = cmd.action;
527 LYXERR(Debug::ACTION, "\nLyXFunc::dispatch: cmd: " << cmd);
528 //lyxerr << "LyXFunc::dispatch: cmd: " << cmd << endl;
530 // we have not done anything wrong yet.
532 dispatch_buffer.erase();
534 // redraw the screen at the end (first of the two drawing steps).
535 //This is done unless explicitely requested otherwise
536 Update::flags updateFlags = Update::FitCursor;
538 LyXView * lv = theApp()->currentWindow();
540 FuncStatus const flag = getStatus(cmd);
541 if (!flag.enabled()) {
542 // We cannot use this function here
543 LYXERR(Debug::ACTION, "LyXFunc::dispatch: "
544 << lyxaction.getActionName(action)
545 << " [" << action << "] is disabled at this location");
546 setErrorMessage(flag.message());
551 if (lv && lv->currentBufferView())
552 buffer = &lv->currentBufferView()->buffer();
555 case LFUN_COMMAND_PREFIX:
557 lv->message(keyseq.printOptions(true));
561 LASSERT(lv && lv->currentBufferView(), /**/);
563 meta_fake_bit = NoModifier;
565 // cancel any selection
566 dispatch(FuncRequest(LFUN_MARK_OFF));
567 setMessage(from_ascii(N_("Cancel")));
570 case LFUN_META_PREFIX:
571 meta_fake_bit = AltModifier;
572 setMessage(keyseq.print(KeySequence::ForGui));
575 // --- Menus -----------------------------------------------
576 case LFUN_RECONFIGURE:
577 // argument is any additional parameter to the configure.py command
578 reconfigure(lv, argument);
581 // --- lyxserver commands ----------------------------
582 case LFUN_SERVER_GET_FILENAME:
583 LASSERT(lv && buffer, /**/);
584 setMessage(from_utf8(buffer->absFileName()));
585 LYXERR(Debug::INFO, "FNAME["
586 << buffer->absFileName() << ']');
589 case LFUN_SERVER_NOTIFY:
590 dispatch_buffer = keyseq.print(KeySequence::Portable);
591 theServer().notifyClient(to_utf8(dispatch_buffer));
594 case LFUN_DIALOG_SHOW_NEW_INSET: {
596 string const name = cmd.getArg(0);
597 InsetCode code = insetCode(name);
598 string data = trim(to_utf8(cmd.argument()).substr(name.size()));
599 bool insetCodeOK = true;
606 case NOMENCL_PRINT_CODE:
609 case HYPERLINK_CODE: {
610 InsetCommandParams p(code);
611 data = InsetCommand::params2string(name, p);
615 // data is the include type: one of "include",
616 // "input", "verbatiminput" or "verbatiminput*"
618 // default type is requested
620 InsetCommandParams p(INCLUDE_CODE, data);
621 data = InsetCommand::params2string("include", p);
625 // \c data == "Boxed" || "Frameless" etc
626 InsetBoxParams p(data);
627 data = InsetBox::params2string(p);
632 data = InsetBranch::params2string(p);
636 InsetCommandParams p(CITE_CODE);
637 data = InsetCommand::params2string(name, p);
641 data = InsetERT::params2string(InsetCollapsable::Open);
644 case EXTERNAL_CODE: {
645 InsetExternalParams p;
646 data = InsetExternal::params2string(p, *buffer);
651 data = InsetFloat::params2string(p);
654 case LISTINGS_CODE: {
655 InsetListingsParams p;
656 data = InsetListings::params2string(p);
659 case GRAPHICS_CODE: {
660 InsetGraphicsParams p;
661 data = InsetGraphics::params2string(p, *buffer);
666 data = InsetNote::params2string(p);
670 InsetPhantomParams p;
671 data = InsetPhantom::params2string(p);
676 data = InsetSpace::params2string(p);
681 data = InsetVSpace::params2string(space);
686 data = InsetWrap::params2string(p);
690 lyxerr << "Inset type '" << name <<
691 "' not recognized in LFUN_DIALOG_SHOW_NEW_INSET" << endl;
694 } // end switch(code)
696 dispatch(FuncRequest(LFUN_DIALOG_SHOW, name + " " + data));
700 case LFUN_CITATION_INSERT: {
702 if (!argument.empty()) {
703 // we can have one optional argument, delimited by '|'
704 // citation-insert <key>|<text_before>
705 // this should be enhanced to also support text_after
706 // and citation style
707 string arg = argument;
709 if (contains(argument, "|")) {
710 arg = token(argument, '|', 0);
711 opt1 = token(argument, '|', 1);
713 InsetCommandParams icp(CITE_CODE);
714 icp["key"] = from_utf8(arg);
716 icp["before"] = from_utf8(opt1);
717 string icstr = InsetCommand::params2string("citation", icp);
718 FuncRequest fr(LFUN_INSET_INSERT, icstr);
721 dispatch(FuncRequest(LFUN_DIALOG_SHOW_NEW_INSET, "citation"));
725 case LFUN_CURSOR_FOLLOWS_SCROLLBAR_TOGGLE:
727 lyxrc.cursor_follows_scrollbar = !lyxrc.cursor_follows_scrollbar;
733 string rest = split(argument, countstr, ' ');
734 istringstream is(countstr);
737 //lyxerr << "repeat: count: " << count << " cmd: " << rest << endl;
738 for (int i = 0; i < count; ++i)
739 dispatch(lyxaction.lookupFunc(rest));
743 case LFUN_COMMAND_SEQUENCE: {
744 // argument contains ';'-terminated commands
745 string arg = argument;
746 if (theBufferList().isLoaded(buffer))
747 buffer->undo().beginUndoGroup();
748 while (!arg.empty()) {
750 arg = split(arg, first, ';');
751 FuncRequest func(lyxaction.lookupFunc(first));
752 func.origin = cmd.origin;
755 if (theBufferList().isLoaded(buffer))
756 buffer->undo().endUndoGroup();
760 case LFUN_COMMAND_ALTERNATIVES: {
761 // argument contains ';'-terminated commands
762 string arg = argument;
763 while (!arg.empty()) {
765 arg = split(arg, first, ';');
766 FuncRequest func(lyxaction.lookupFunc(first));
767 func.origin = cmd.origin;
768 FuncStatus stat = getStatus(func);
769 if (stat.enabled()) {
779 if (theTopLevelCmdDef().lock(argument, func)) {
780 func.origin = cmd.origin;
782 theTopLevelCmdDef().release(argument);
784 if (func.action == LFUN_UNKNOWN_ACTION) {
785 // unknown command definition
786 lyxerr << "Warning: unknown command definition `"
790 // recursion detected
791 lyxerr << "Warning: Recursion in the command definition `"
792 << argument << "' detected"
799 case LFUN_PREFERENCES_SAVE: {
800 lyxrc.write(makeAbsPath("preferences",
801 package().user_support().absFilename()),
806 case LFUN_BUFFER_SAVE_AS_DEFAULT: {
808 addName(addPath(package().user_support().absFilename(), "templates/"),
810 Buffer defaults(fname);
812 istringstream ss(argument);
815 int const unknown_tokens = defaults.readHeader(lex);
817 if (unknown_tokens != 0) {
818 lyxerr << "Warning in LFUN_BUFFER_SAVE_AS_DEFAULT!\n"
819 << unknown_tokens << " unknown token"
820 << (unknown_tokens == 1 ? "" : "s")
824 if (defaults.writeFile(FileName(defaults.absFileName())))
825 setMessage(bformat(_("Document defaults saved in %1$s"),
826 makeDisplayPath(fname)));
828 setErrorMessage(from_ascii(N_("Unable to save document defaults")));
832 case LFUN_LYXRC_APPLY: {
833 // reset active key sequences, since the bindings
834 // are updated (bug 6064)
836 LyXRC const lyxrc_orig = lyxrc;
838 istringstream ss(argument);
839 bool const success = lyxrc.read(ss) == 0;
842 lyxerr << "Warning in LFUN_LYXRC_APPLY!\n"
843 << "Unable to read lyxrc data"
848 actOnUpdatedPrefs(lyxrc_orig, lyxrc);
852 theApp()->resetGui();
854 /// We force the redraw in any case because there might be
855 /// some screen font changes.
856 /// FIXME: only the current view will be updated. the Gui
857 /// class is able to furnish the list of views.
858 updateFlags = Update::Force;
862 case LFUN_BOOKMARK_GOTO:
863 // go to bookmark, open unopened file and switch to buffer if necessary
864 gotoBookmark(convert<unsigned int>(to_utf8(cmd.argument())), true, true);
865 updateFlags = Update::FitCursor;
868 case LFUN_BOOKMARK_CLEAR:
869 theSession().bookmarks().clear();
873 LASSERT(theApp(), /**/);
874 // Let the frontend dispatch its own actions.
875 if (theApp()->dispatch(cmd))
876 // Nothing more to do.
879 // Everything below is only for active window
883 // Start an undo group. This may be needed for
884 // some stuff like inset-apply on labels.
885 if (theBufferList().isLoaded(buffer))
886 buffer->undo().beginUndoGroup();
888 // Let the current LyXView dispatch its own actions.
889 if (lv->dispatch(cmd)) {
890 BufferView * bv = lv->currentBufferView();
892 buffer = &(bv->buffer());
893 updateFlags = bv->cursor().result().update();
894 if (theBufferList().isLoaded(buffer))
895 buffer->undo().endUndoGroup();
900 BufferView * bv = lv->currentBufferView();
903 // Let the current BufferView dispatch its own actions.
904 if (bv->dispatch(cmd)) {
905 // The BufferView took care of its own updates if needed.
906 buffer = &(bv->buffer());
907 updateFlags = Update::None;
908 if (theBufferList().isLoaded(buffer))
909 buffer->undo().endUndoGroup();
913 BufferView * doc_bv = lv->documentBufferView();
914 // Try with the document BufferView dispatch if any.
915 if (doc_bv && doc_bv->dispatch(cmd)) {
916 // The BufferView took care of its own updates if needed.
917 buffer = &(doc_bv->buffer());
918 updateFlags = Update::None;
919 if (theBufferList().isLoaded(buffer))
920 buffer->undo().endUndoGroup();
924 // OK, so try the current Buffer itself...
926 bv->buffer().dispatch(cmd, dr);
927 if (dr.dispatched()) {
928 updateFlags = dr.update();
931 // and with the document Buffer.
933 doc_bv->buffer().dispatch(cmd, dr);
934 if (dr.dispatched()) {
935 updateFlags = dr.update();
940 // Is this a function that acts on inset at point?
941 Inset * inset = bv->cursor().nextInset();
942 if (lyxaction.funcHasFlag(action, LyXAction::AtPoint)
944 bv->cursor().result().dispatched(true);
945 bv->cursor().result().update(Update::FitCursor | Update::Force);
946 FuncRequest tmpcmd = cmd;
947 inset->dispatch(bv->cursor(), tmpcmd);
948 if (bv->cursor().result().dispatched()) {
949 updateFlags = bv->cursor().result().update();
954 // Let the current Cursor dispatch its own actions.
955 Cursor old = bv->cursor();
956 bv->cursor().getPos(cursorPosBeforeDispatchX_,
957 cursorPosBeforeDispatchY_);
958 bv->cursor().dispatch(cmd);
960 // notify insets we just left
961 if (bv->cursor() != old) {
963 bool badcursor = notifyCursorLeavesOrEnters(old, bv->cursor());
965 bv->cursor().fixIfBroken();
968 if (theBufferList().isLoaded(buffer))
969 buffer->undo().endUndoGroup();
971 // update completion. We do it here and not in
972 // processKeySym to avoid another redraw just for a
973 // changed inline completion
974 if (cmd.origin == FuncRequest::KEYBOARD) {
975 if (cmd.action == LFUN_SELF_INSERT
976 || (cmd.action == LFUN_ERT_INSERT && bv->cursor().inMathed()))
977 lv->updateCompletion(bv->cursor(), true, true);
978 else if (cmd.action == LFUN_CHAR_DELETE_BACKWARD)
979 lv->updateCompletion(bv->cursor(), false, true);
981 lv->updateCompletion(bv->cursor(), false, false);
984 updateFlags = bv->cursor().result().update();
987 // if we executed a mutating lfun, mark the buffer as dirty
988 if (theBufferList().isLoaded(buffer) && flag.enabled()
989 && !lyxaction.funcHasFlag(action, LyXAction::NoBuffer)
990 && !lyxaction.funcHasFlag(action, LyXAction::ReadOnly))
993 if (lv && lv->currentBufferView()) {
994 // BufferView::update() updates the ViewMetricsInfo and
995 // also initializes the position cache for all insets in
996 // (at least partially) visible top-level paragraphs.
997 // We will redraw the screen only if needed.
998 lv->currentBufferView()->processUpdateFlags(updateFlags);
1000 // Do we have a selection?
1001 theSelection().haveSelection(
1002 lv->currentBufferView()->cursor().selection());
1005 lv->restartCursor();
1009 // Some messages may already be translated, so we cannot use _()
1010 sendDispatchMessage(translateIfPossible(getMessage()), cmd);
1015 void LyXFunc::sendDispatchMessage(docstring const & msg, FuncRequest const & cmd)
1017 const bool verbose = (cmd.origin == FuncRequest::MENU
1018 || cmd.origin == FuncRequest::TOOLBAR
1019 || cmd.origin == FuncRequest::COMMANDBUFFER);
1021 LyXView * lv = theApp()->currentWindow();
1022 if (cmd.action == LFUN_SELF_INSERT || !verbose) {
1023 LYXERR(Debug::ACTION, "dispatch msg is " << to_utf8(msg));
1029 docstring dispatch_msg = msg;
1030 if (!dispatch_msg.empty())
1031 dispatch_msg += ' ';
1033 docstring comname = from_utf8(lyxaction.getActionName(cmd.action));
1035 bool argsadded = false;
1037 if (!cmd.argument().empty()) {
1038 if (cmd.action != LFUN_UNKNOWN_ACTION) {
1039 comname += ' ' + cmd.argument();
1044 docstring const shortcuts = theTopLevelKeymap().printBindings(cmd, KeySequence::ForGui);
1046 if (!shortcuts.empty())
1047 comname += ": " + shortcuts;
1048 else if (!argsadded && !cmd.argument().empty())
1049 comname += ' ' + cmd.argument();
1051 if (!comname.empty()) {
1052 comname = rtrim(comname);
1053 dispatch_msg += '(' + rtrim(comname) + ')';
1056 LYXERR(Debug::ACTION, "verbose dispatch msg " << to_utf8(dispatch_msg));
1057 if (!dispatch_msg.empty())
1058 lv->message(dispatch_msg);
1062 // Each LyXView should have it's own message method. lyxview and
1063 // the minibuffer would use the minibuffer, but lyxserver would
1064 // send an ERROR signal to its client. Alejandro 970603
1065 // This function is bit problematic when it comes to NLS, to make the
1066 // lyx servers client be language indepenent we must not translate
1067 // strings sent to this func.
1068 void LyXFunc::setErrorMessage(docstring const & m) const
1070 dispatch_buffer = m;
1075 void LyXFunc::setMessage(docstring const & m) const
1077 dispatch_buffer = m;
1081 docstring LyXFunc::viewStatusMessage()
1083 // When meta-fake key is pressed, show the key sequence so far + "M-".
1085 return keyseq.print(KeySequence::ForGui) + "M-";
1087 // Else, when a non-complete key sequence is pressed,
1088 // show the available options.
1089 if (keyseq.length() > 0 && !keyseq.deleted())
1090 return keyseq.printOptions(true);
1092 LyXView * lv = theApp()->currentWindow();
1094 if (!lv->currentBufferView())
1095 return _("Welcome to LyX!");
1097 return lv->currentBufferView()->cursor().currentState();
1101 bool LyXFunc::wasMetaKey() const
1103 return (meta_fake_bit != NoModifier);
1109 void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
1111 // Why the switch you might ask. It is a trick to ensure that all
1112 // the elements in the LyXRCTags enum is handled. As you can see
1113 // there are no breaks at all. So it is just a huge fall-through.
1114 // The nice thing is that we will get a warning from the compiler
1115 // if we forget an element.
1116 LyXRC::LyXRCTags tag = LyXRC::RC_LAST;
1118 case LyXRC::RC_ACCEPT_COMPOUND:
1119 case LyXRC::RC_ALT_LANG:
1120 case LyXRC::RC_PLAINTEXT_LINELEN:
1121 case LyXRC::RC_PLAINTEXT_ROFF_COMMAND:
1122 case LyXRC::RC_AUTOCORRECTION_MATH:
1123 case LyXRC::RC_AUTOREGIONDELETE:
1124 case LyXRC::RC_AUTORESET_OPTIONS:
1125 case LyXRC::RC_AUTOSAVE:
1126 case LyXRC::RC_AUTO_NUMBER:
1127 case LyXRC::RC_BACKUPDIR_PATH:
1128 case LyXRC::RC_BIBTEX_ALTERNATIVES:
1129 case LyXRC::RC_BIBTEX_COMMAND:
1130 case LyXRC::RC_BINDFILE:
1131 case LyXRC::RC_CHECKLASTFILES:
1132 case LyXRC::RC_COMPLETION_CURSOR_TEXT:
1133 case LyXRC::RC_COMPLETION_INLINE_DELAY:
1134 case LyXRC::RC_COMPLETION_INLINE_DOTS:
1135 case LyXRC::RC_COMPLETION_INLINE_MATH:
1136 case LyXRC::RC_COMPLETION_INLINE_TEXT:
1137 case LyXRC::RC_COMPLETION_POPUP_AFTER_COMPLETE:
1138 case LyXRC::RC_COMPLETION_POPUP_DELAY:
1139 case LyXRC::RC_COMPLETION_POPUP_MATH:
1140 case LyXRC::RC_COMPLETION_POPUP_TEXT:
1141 case LyXRC::RC_USELASTFILEPOS:
1142 case LyXRC::RC_LOADSESSION:
1143 case LyXRC::RC_CHKTEX_COMMAND:
1144 case LyXRC::RC_CONVERTER:
1145 case LyXRC::RC_CONVERTER_CACHE_MAXAGE:
1146 case LyXRC::RC_COPIER:
1147 case LyXRC::RC_CURSOR_FOLLOWS_SCROLLBAR:
1148 case LyXRC::RC_SCROLL_BELOW_DOCUMENT:
1149 case LyXRC::RC_DATE_INSERT_FORMAT:
1150 case LyXRC::RC_DEFAULT_LANGUAGE:
1151 case LyXRC::RC_GUI_LANGUAGE:
1152 case LyXRC::RC_DEFAULT_PAPERSIZE:
1153 case LyXRC::RC_DEFAULT_VIEW_FORMAT:
1154 case LyXRC::RC_DEFFILE:
1155 case LyXRC::RC_DIALOGS_ICONIFY_WITH_MAIN:
1156 case LyXRC::RC_DISPLAY_GRAPHICS:
1157 case LyXRC::RC_DOCUMENTPATH:
1158 if (lyxrc_orig.document_path != lyxrc_new.document_path) {
1159 FileName path(lyxrc_new.document_path);
1160 if (path.exists() && path.isDirectory())
1161 package().document_dir() = FileName(lyxrc.document_path);
1163 case LyXRC::RC_EDITOR_ALTERNATIVES:
1164 case LyXRC::RC_ESC_CHARS:
1165 case LyXRC::RC_EXAMPLEPATH:
1166 case LyXRC::RC_FONT_ENCODING:
1167 case LyXRC::RC_FORMAT:
1168 case LyXRC::RC_GROUP_LAYOUTS:
1169 case LyXRC::RC_HUNSPELLDIR_PATH:
1170 case LyXRC::RC_INDEX_ALTERNATIVES:
1171 case LyXRC::RC_INDEX_COMMAND:
1172 case LyXRC::RC_JBIBTEX_COMMAND:
1173 case LyXRC::RC_JINDEX_COMMAND:
1174 case LyXRC::RC_NOMENCL_COMMAND:
1175 case LyXRC::RC_INPUT:
1176 case LyXRC::RC_KBMAP:
1177 case LyXRC::RC_KBMAP_PRIMARY:
1178 case LyXRC::RC_KBMAP_SECONDARY:
1179 case LyXRC::RC_LABEL_INIT_LENGTH:
1180 case LyXRC::RC_LANGUAGE_AUTO_BEGIN:
1181 case LyXRC::RC_LANGUAGE_AUTO_END:
1182 case LyXRC::RC_LANGUAGE_COMMAND_BEGIN:
1183 case LyXRC::RC_LANGUAGE_COMMAND_END:
1184 case LyXRC::RC_LANGUAGE_COMMAND_LOCAL:
1185 case LyXRC::RC_LANGUAGE_GLOBAL_OPTIONS:
1186 case LyXRC::RC_LANGUAGE_PACKAGE:
1187 case LyXRC::RC_LANGUAGE_USE_BABEL:
1188 case LyXRC::RC_MAC_LIKE_WORD_MOVEMENT:
1189 case LyXRC::RC_MACRO_EDIT_STYLE:
1190 case LyXRC::RC_MAKE_BACKUP:
1191 case LyXRC::RC_MARK_FOREIGN_LANGUAGE:
1192 case LyXRC::RC_MOUSE_WHEEL_SPEED:
1193 case LyXRC::RC_NUMLASTFILES:
1194 case LyXRC::RC_PARAGRAPH_MARKERS:
1195 case LyXRC::RC_PATH_PREFIX:
1196 if (lyxrc_orig.path_prefix != lyxrc_new.path_prefix) {
1197 prependEnvPath("PATH", lyxrc.path_prefix);
1199 case LyXRC::RC_PERS_DICT:
1200 case LyXRC::RC_PREVIEW:
1201 case LyXRC::RC_PREVIEW_HASHED_LABELS:
1202 case LyXRC::RC_PREVIEW_SCALE_FACTOR:
1203 case LyXRC::RC_PRINTCOLLCOPIESFLAG:
1204 case LyXRC::RC_PRINTCOPIESFLAG:
1205 case LyXRC::RC_PRINTER:
1206 case LyXRC::RC_PRINTEVENPAGEFLAG:
1207 case LyXRC::RC_PRINTEXSTRAOPTIONS:
1208 case LyXRC::RC_PRINTFILEEXTENSION:
1209 case LyXRC::RC_PRINTLANDSCAPEFLAG:
1210 case LyXRC::RC_PRINTODDPAGEFLAG:
1211 case LyXRC::RC_PRINTPAGERANGEFLAG:
1212 case LyXRC::RC_PRINTPAPERDIMENSIONFLAG:
1213 case LyXRC::RC_PRINTPAPERFLAG:
1214 case LyXRC::RC_PRINTREVERSEFLAG:
1215 case LyXRC::RC_PRINTSPOOL_COMMAND:
1216 case LyXRC::RC_PRINTSPOOL_PRINTERPREFIX:
1217 case LyXRC::RC_PRINTTOFILE:
1218 case LyXRC::RC_PRINTTOPRINTER:
1219 case LyXRC::RC_PRINT_ADAPTOUTPUT:
1220 case LyXRC::RC_PRINT_COMMAND:
1221 case LyXRC::RC_RTL_SUPPORT:
1222 case LyXRC::RC_SCREEN_DPI:
1223 case LyXRC::RC_SCREEN_FONT_ROMAN:
1224 case LyXRC::RC_SCREEN_FONT_ROMAN_FOUNDRY:
1225 case LyXRC::RC_SCREEN_FONT_SANS:
1226 case LyXRC::RC_SCREEN_FONT_SANS_FOUNDRY:
1227 case LyXRC::RC_SCREEN_FONT_SCALABLE:
1228 case LyXRC::RC_SCREEN_FONT_SIZES:
1229 case LyXRC::RC_SCREEN_FONT_TYPEWRITER:
1230 case LyXRC::RC_SCREEN_FONT_TYPEWRITER_FOUNDRY:
1231 case LyXRC::RC_GEOMETRY_SESSION:
1232 case LyXRC::RC_SCREEN_ZOOM:
1233 case LyXRC::RC_SERVERPIPE:
1234 case LyXRC::RC_SET_COLOR:
1235 case LyXRC::RC_SHOW_BANNER:
1236 case LyXRC::RC_OPEN_BUFFERS_IN_TABS:
1237 case LyXRC::RC_SPELL_COMMAND:
1238 case LyXRC::RC_SPELLCHECKER:
1239 case LyXRC::RC_SPELLCHECK_CONTINUOUSLY:
1240 case LyXRC::RC_SPLITINDEX_COMMAND:
1241 case LyXRC::RC_TEMPDIRPATH:
1242 case LyXRC::RC_TEMPLATEPATH:
1243 case LyXRC::RC_TEX_ALLOWS_SPACES:
1244 case LyXRC::RC_TEX_EXPECTS_WINDOWS_PATHS:
1245 if (lyxrc_orig.windows_style_tex_paths != lyxrc_new.windows_style_tex_paths) {
1246 os::windows_style_tex_paths(lyxrc_new.windows_style_tex_paths);
1248 case LyXRC::RC_THESAURUSDIRPATH:
1249 case LyXRC::RC_UIFILE:
1250 case LyXRC::RC_USER_EMAIL:
1251 case LyXRC::RC_USER_NAME:
1252 case LyXRC::RC_USETEMPDIR:
1253 case LyXRC::RC_USE_ALT_LANG:
1254 case LyXRC::RC_USE_CONVERTER_CACHE:
1255 case LyXRC::RC_USE_ESC_CHARS:
1256 case LyXRC::RC_USE_INP_ENC:
1257 case LyXRC::RC_USE_PERS_DICT:
1258 case LyXRC::RC_USE_TOOLTIP:
1259 case LyXRC::RC_USE_PIXMAP_CACHE:
1260 case LyXRC::RC_USE_SPELL_LIB:
1261 case LyXRC::RC_VIEWDVI_PAPEROPTION:
1262 case LyXRC::RC_SORT_LAYOUTS:
1263 case LyXRC::RC_FULL_SCREEN_LIMIT:
1264 case LyXRC::RC_FULL_SCREEN_SCROLLBAR:
1265 case LyXRC::RC_FULL_SCREEN_MENUBAR:
1266 case LyXRC::RC_FULL_SCREEN_TABBAR:
1267 case LyXRC::RC_FULL_SCREEN_TOOLBARS:
1268 case LyXRC::RC_FULL_SCREEN_WIDTH:
1269 case LyXRC::RC_VISUAL_CURSOR:
1270 case LyXRC::RC_VIEWER:
1271 case LyXRC::RC_VIEWER_ALTERNATIVES:
1272 case LyXRC::RC_LAST: