3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Alfredo Braunstein
7 * \author Lars Gullik Bjønnes
8 * \author Jean-Marc Lasgouttes
9 * \author Angus Leeming
11 * \author André Pönitz
14 * \author Martin Vermeer
15 * \author Jürgen Vigna
17 * Full author contact details are available in file CREDITS.
24 #include "BranchList.h"
26 #include "buffer_funcs.h"
27 #include "bufferlist.h"
28 #include "bufferparams.h"
29 #include "BufferView.h"
35 #include "funcrequest.h"
39 #include "iterators.h"
43 #include "LyXAction.h"
47 #include "lyxserver.h"
49 #include "paragraph.h"
50 #include "ParagraphParameters.h"
51 #include "TextCache.h"
52 #include "undo_funcs.h"
54 #include "insets/insetcommand.h"
55 #include "insets/insetexternal.h"
56 #include "insets/insettabular.h"
58 #include "mathed/math_cursor.h"
60 #include "frontends/Alert.h"
61 #include "frontends/Dialogs.h"
62 #include "frontends/FileDialog.h"
63 #include "frontends/lyx_gui.h"
64 #include "frontends/LyXKeySym.h"
65 #include "frontends/LyXView.h"
66 #include "frontends/Menubar.h"
67 #include "frontends/Toolbar.h"
69 #include "support/FileInfo.h"
70 #include "support/filetools.h"
71 #include "support/forkedcontr.h"
72 #include "support/path.h"
73 #include "support/path_defines.h"
74 #include "support/tostr.h"
75 #include "support/std_sstream.h"
77 using bv_funcs::apply_freefont;
78 using bv_funcs::changeDepth;
79 using bv_funcs::currentState;
80 using bv_funcs::DEC_DEPTH;
81 using bv_funcs::freefont2string;
82 using bv_funcs::INC_DEPTH;
83 using bv_funcs::update_and_apply_freefont;
85 using lyx::support::AddName;
86 using lyx::support::AddPath;
87 using lyx::support::bformat;
88 using lyx::support::ChangeExtension;
89 using lyx::support::FileInfo;
90 using lyx::support::FileSearch;
91 using lyx::support::ForkedcallsController;
92 using lyx::support::i18nLibFileSearch;
93 using lyx::support::IsDirWriteable;
94 using lyx::support::IsFileReadable;
95 using lyx::support::isStrInt;
96 using lyx::support::MakeAbsPath;
97 using lyx::support::MakeDisplayPath;
98 using lyx::support::Path;
99 using lyx::support::rtrim;
100 using lyx::support::split;
101 using lyx::support::strToInt;
102 using lyx::support::strToUnsignedInt;
103 using lyx::support::system_lyxdir;
104 using lyx::support::token;
105 using lyx::support::trim;
106 using lyx::support::user_lyxdir;
109 using std::make_pair;
111 using std::istringstream;
114 extern BufferList bufferlist;
115 extern LyXServer * lyxserver;
116 extern bool selection_possible;
118 extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
121 extern tex_accent_struct get_accent(kb_action action);
123 extern void ShowLatexLog();
126 LyXFunc::LyXFunc(LyXView * o)
129 keyseq(toplevel_keymap.get(), toplevel_keymap.get()),
130 cancel_meta_seq(toplevel_keymap.get(), toplevel_keymap.get()),
131 meta_fake_bit(key_modifier::none)
136 void LyXFunc::moveCursorUpdate()
138 LyXText * lt = view()->text;
139 if (lt->selection.mark())
142 view()->switchKeyMap();
146 void LyXFunc::handleKeyFunc(kb_action action)
148 char c = encoded_last_key;
150 if (keyseq.length()) {
154 owner->getIntl().getTransManager()
155 .deadkey(c, get_accent(action).accent, view()->getLyXText());
156 // Need to clear, in case the minibuffer calls these
159 // copied verbatim from do_accent_char
161 view()->getLyXText()->selection.cursor = view()->getLyXText()->cursor;
165 void LyXFunc::processKeySym(LyXKeySymPtr keysym,
166 key_modifier::state state)
170 if (lyxerr.debugging(Debug::KEY)) {
171 lyxerr << "KeySym is "
172 << keysym->getSymbolName()
176 // Do nothing if we have nothing (JMarc)
177 if (!keysym->isOK()) {
178 lyxerr[Debug::KEY] << "Empty kbd action (probably composing)"
183 if (keysym->isModifier()) {
184 lyxerr[Debug::KEY] << "isModifier true" << endl;
188 Encoding const * encoding = view()->getEncoding();
190 encoded_last_key = keysym->getISOEncoded(encoding ? encoding->Name() : "");
192 // Do a one-deep top-level lookup for
193 // cancel and meta-fake keys. RVDK_PATCH_5
194 cancel_meta_seq.reset();
196 FuncRequest func = cancel_meta_seq.addkey(keysym, state);
197 lyxerr[Debug::KEY] << "action first set to [" << func.action << ']' << endl;
199 // When not cancel or meta-fake, do the normal lookup.
200 // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
201 // Mostly, meta_fake_bit = key_modifier::none. RVDK_PATCH_5.
202 if ((func.action != LFUN_CANCEL) && (func.action != LFUN_META_FAKE)) {
203 // remove Caps Lock and Mod2 as a modifiers
204 func = keyseq.addkey(keysym, (state | meta_fake_bit));
205 lyxerr[Debug::KEY] << "action now set to ["
206 << func.action << ']' << endl;
209 // Dont remove this unless you know what you are doing.
210 meta_fake_bit = key_modifier::none;
212 // can this happen now ?
213 if (func.action == LFUN_NOACTION) {
214 func = FuncRequest(LFUN_PREFIX);
217 if (lyxerr.debugging(Debug::KEY)) {
218 lyxerr << "Key [action="
219 << func.action << "]["
220 << keyseq.print() << ']'
224 // already here we know if it any point in going further
225 // why not return already here if action == -1 and
226 // num_bytes == 0? (Lgb)
228 if (keyseq.length() > 1) {
229 owner->message(keyseq.print());
233 // Maybe user can only reach the key via holding down shift.
234 // Let's see. But only if shift is the only modifier
235 if (func.action == LFUN_UNKNOWN_ACTION &&
236 state == key_modifier::shift) {
237 lyxerr[Debug::KEY] << "Trying without shift" << endl;
238 func = keyseq.addkey(keysym, key_modifier::none);
239 lyxerr[Debug::KEY] << "Action now " << func.action << endl;
242 if (func.action == LFUN_UNKNOWN_ACTION) {
243 // Hmm, we didn't match any of the keysequences. See
244 // if it's normal insertable text not already covered
246 if (keysym->isText() && keyseq.length() == 1) {
247 lyxerr[Debug::KEY] << "isText() is true, inserting." << endl;
248 func = FuncRequest(LFUN_SELFINSERT);
250 lyxerr[Debug::KEY] << "Unknown, !isText() - giving up" << endl;
251 owner->message(_("Unknown function."));
256 if (func.action == LFUN_SELFINSERT) {
257 if (encoded_last_key != 0) {
259 arg += encoded_last_key;
261 dispatch(FuncRequest(view(), LFUN_SELFINSERT, arg));
263 lyxerr[Debug::KEY] << "SelfInsert arg[`"
264 << argument << "']" << endl;
272 FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
275 Buffer * buf = owner->buffer();
277 if (ev.action == LFUN_NOACTION) {
278 setStatusMessage(N_("Nothing to do"));
279 return flag.disabled(true);
283 case LFUN_UNKNOWN_ACTION:
284 #ifndef HAVE_LIBAIKSAURUS
285 case LFUN_THESAURUS_ENTRY:
290 flag |= lyx_gui::getStatus(ev);
293 if (flag.unknown()) {
294 setStatusMessage(N_("Unknown action"));
298 // the default error message if we disable the command
299 setStatusMessage(N_("Command disabled"));
301 // Check whether we need a buffer
302 if (!lyxaction.funcHasFlag(ev.action, LyXAction::NoBuffer)) {
303 // Yes we need a buffer, do we have one?
306 // Can we use a readonly buffer?
307 if (buf->isReadonly() &&
308 !lyxaction.funcHasFlag(ev.action,
309 LyXAction::ReadOnly)) {
311 setStatusMessage(N_("Document is read-only"));
316 setStatusMessage(N_("Command not allowed with"
317 "out any document open"));
318 return flag.disabled(true);
322 UpdatableInset * tli = view()->theLockingInset();
324 // I would really like to avoid having this switch and rather try to
325 // encode this in the function itself.
326 bool disable = false;
329 disable = ev.argument != "custom"
330 && !Exporter::IsExportable(*buf, ev.argument);
333 disable = buf->undostack().empty();
336 disable = buf->redostack().empty();
341 UpdatableInset * in = tli;
342 if (in->lyxCode() != InsetOld::TABULAR_CODE) {
343 in = tli->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE);
345 if (in && static_cast<InsetTabular*>(in)->hasSelection()) {
350 disable = !mathcursor && !view()->getLyXText()->selection.set();
353 disable = !buf->isLatex() || lyxrc.chktex_command == "none";
356 disable = !Exporter::IsExportable(*buf, "program");
359 case LFUN_LAYOUT_TABULAR:
361 || (tli->lyxCode() != InsetOld::TABULAR_CODE
362 && !tli->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE));
366 disable = !changeDepth(view(), view()->getLyXText(), DEC_DEPTH, true);
369 case LFUN_DEPTH_PLUS:
370 disable = !changeDepth(view(), view()->getLyXText(), INC_DEPTH, true);
374 case LFUN_LAYOUT_PARAGRAPH: {
375 InsetOld * inset = view()->getLyXText()->cursor.par()->inInset();
376 disable = inset && inset->forceDefaultParagraphs(inset);
380 case LFUN_INSET_OPTARG:
381 disable = (view()->getLyXText()->cursor.par()->layout()->optionalargs == 0);
384 case LFUN_TABULAR_FEATURE:
387 // FIXME: check temporarily disabled
389 char align = mathcursor->valign();
394 if (ev.argument.empty()) {
398 if (!contains("tcb", ev.argument[0])) {
402 flag.setOnOff(ev.argument[0] == align);
406 char align = mathcursor->halign();
411 if (ev.argument.empty()) {
415 if (!contains("lcr", ev.argument[0])) {
419 flag.setOnOff(ev.argument[0] == align);
422 disable = !mathcursor->halign();
428 //ret.disabled(true);
429 if (tli->lyxCode() == InsetOld::TABULAR_CODE) {
430 ret = static_cast<InsetTabular *>(tli)
431 ->getStatus(ev.argument);
434 } else if (tli->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE)) {
435 ret = static_cast<InsetTabular *>
436 (tli->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE))
437 ->getStatus(ev.argument);
444 static InsetTabular inset(*owner->buffer(), 1, 1);
448 ret = inset.getStatus(ev.argument);
449 if (ret.onoff(true) || ret.onoff(false))
450 flag.setOnOff(false);
454 case LFUN_VC_REGISTER:
455 disable = buf->lyxvc().inUse();
457 case LFUN_VC_CHECKIN:
458 disable = !buf->lyxvc().inUse() || buf->isReadonly();
460 case LFUN_VC_CHECKOUT:
461 disable = !buf->lyxvc().inUse() || !buf->isReadonly();
465 disable = !buf->lyxvc().inUse();
467 case LFUN_MENURELOAD:
468 disable = buf->isUnnamed() || buf->isClean();
470 case LFUN_BOOKMARK_GOTO:
472 isSavedPosition(strToUnsignedInt(ev.argument));
474 case LFUN_MERGE_CHANGES:
475 case LFUN_ACCEPT_CHANGE:
476 case LFUN_REJECT_CHANGE:
477 case LFUN_ACCEPT_ALL_CHANGES:
478 case LFUN_REJECT_ALL_CHANGES:
479 disable = !buf->params().tracking_changes;
481 case LFUN_INSET_TOGGLE: {
482 LyXText * lt = view()->getLyXText();
483 disable = !(isEditableInset(lt->getInset())
485 && lt->inset_owner->owner()
486 && lt->inset_owner->owner()->isOpen()));
490 case LFUN_INSET_SETTINGS: {
492 UpdatableInset * inset = view()->theLockingInset();
497 // get the innermost inset
498 inset = inset->getLockingInset();
500 // jump back to owner if an InsetText, so
501 // we get back to the InsetTabular or whatever
502 if (inset->lyxCode() == InsetOld::TEXT_CODE)
503 inset = inset->owner();
505 InsetOld::Code code = inset->lyxCode();
507 case InsetOld::TABULAR_CODE:
508 disable = ev.argument != "tabular";
510 case InsetOld::ERT_CODE:
511 disable = ev.argument != "ert";
513 case InsetOld::FLOAT_CODE:
514 disable = ev.argument != "float";
516 case InsetOld::MINIPAGE_CODE:
517 disable = ev.argument != "minipage";
519 case InsetOld::WRAP_CODE:
520 disable = ev.argument != "wrap";
522 case InsetOld::NOTE_CODE:
523 disable = ev.argument != "note";
525 case InsetOld::BRANCH_CODE:
526 disable = ev.argument != "branch";
534 case LFUN_MATH_MUTATE:
536 //flag.setOnOff(mathcursor->formula()->hullType() == ev.argument);
537 flag.setOnOff(false);
542 // we just need to be in math mode to enable that
544 case LFUN_MATH_SPACE:
545 case LFUN_MATH_LIMITS:
546 case LFUN_MATH_NONUMBER:
547 case LFUN_MATH_NUMBER:
548 case LFUN_MATH_EXTERN:
549 disable = !mathcursor;
552 case LFUN_DIALOG_SHOW: {
553 string const name = ev.getArg(0);
555 disable = !(name == "aboutlyx" ||
558 name == "preferences" ||
563 if (name == "print") {
564 disable = !Exporter::IsExportable(*buf, "dvi") ||
565 lyxrc.print_command == "none";
566 } else if (name == "character") {
567 UpdatableInset * tli = view()->theLockingInset();
568 disable = tli && tli->lyxCode() == InsetOld::ERT_CODE;
569 } else if (name == "vclog") {
570 disable = !buf->lyxvc().inUse();
571 } else if (name == "latexlog") {
572 disable = !IsFileReadable(buf->getLogName().second);
581 // the functions which insert insets
582 InsetOld::Code code = InsetOld::NO_CODE;
584 case LFUN_DIALOG_SHOW_NEW_INSET:
585 if (ev.argument == "bibitem")
586 code = InsetOld::BIBITEM_CODE;
587 else if (ev.argument == "bibtex")
588 code = InsetOld::BIBTEX_CODE;
589 else if (ev.argument == "citation")
590 code = InsetOld::CITE_CODE;
591 else if (ev.argument == "ert")
592 code = InsetOld::ERT_CODE;
593 else if (ev.argument == "external")
594 code = InsetOld::EXTERNAL_CODE;
595 else if (ev.argument == "float")
596 code = InsetOld::FLOAT_CODE;
597 else if (ev.argument == "graphics")
598 code = InsetOld::GRAPHICS_CODE;
599 else if (ev.argument == "include")
600 code = InsetOld::INCLUDE_CODE;
601 else if (ev.argument == "index")
602 code = InsetOld::INDEX_CODE;
603 else if (ev.argument == "label")
604 code = InsetOld::LABEL_CODE;
605 else if (ev.argument == "minipage")
606 code = InsetOld::MINIPAGE_CODE;
607 else if (ev.argument == "ref")
608 code = InsetOld::REF_CODE;
609 else if (ev.argument == "toc")
610 code = InsetOld::TOC_CODE;
611 else if (ev.argument == "url")
612 code = InsetOld::URL_CODE;
613 else if (ev.argument == "wrap")
614 code = InsetOld::WRAP_CODE;
618 code = InsetOld::ERT_CODE;
620 case LFUN_INSET_FOOTNOTE:
621 code = InsetOld::FOOT_CODE;
623 case LFUN_TABULAR_INSERT:
624 code = InsetOld::TABULAR_CODE;
626 case LFUN_INSET_MARGINAL:
627 code = InsetOld::MARGIN_CODE;
629 case LFUN_INSET_MINIPAGE:
630 code = InsetOld::MINIPAGE_CODE;
632 case LFUN_INSET_FLOAT:
633 case LFUN_INSET_WIDE_FLOAT:
634 code = InsetOld::FLOAT_CODE;
636 case LFUN_INSET_WRAP:
637 code = InsetOld::WRAP_CODE;
639 case LFUN_FLOAT_LIST:
640 code = InsetOld::FLOAT_LIST_CODE;
643 case LFUN_INSET_LIST:
644 code = InsetOld::LIST_CODE;
646 case LFUN_INSET_THEOREM:
647 code = InsetOld::THEOREM_CODE;
650 case LFUN_INSET_CAPTION:
651 code = InsetOld::CAPTION_CODE;
653 case LFUN_INSERT_NOTE:
654 code = InsetOld::NOTE_CODE;
656 case LFUN_INSERT_BRANCH:
657 code = InsetOld::BRANCH_CODE;
658 if (buf->params().branchlist().empty())
661 case LFUN_INSERT_LABEL:
662 code = InsetOld::LABEL_CODE;
664 case LFUN_INSET_OPTARG:
665 code = InsetOld::OPTARG_CODE;
667 case LFUN_ENVIRONMENT_INSERT:
668 code = InsetOld::MINIPAGE_CODE;
670 case LFUN_INDEX_INSERT:
671 code = InsetOld::INDEX_CODE;
673 case LFUN_INDEX_PRINT:
674 code = InsetOld::INDEX_PRINT_CODE;
676 case LFUN_TOC_INSERT:
677 code = InsetOld::TOC_CODE;
681 code = InsetOld::URL_CODE;
684 // always allow this, since we will inset a raw quote
685 // if an inset is not allowed.
687 case LFUN_HYPHENATION:
688 case LFUN_LIGATURE_BREAK:
690 case LFUN_MENU_SEPARATOR:
692 case LFUN_END_OF_SENTENCE:
693 code = InsetOld::SPECIALCHAR_CODE;
695 case LFUN_SPACE_INSERT:
696 // slight hack: we know this is allowed in math mode
698 code = InsetOld::SPACE_CODE;
700 case LFUN_INSET_DIALOG_SHOW: {
701 LyXText * lt = view()->getLyXText();
702 InsetOld * inset = lt->getInset();
705 code = inset->lyxCode();
706 if (!(code == InsetOld::INCLUDE_CODE
707 || code == InsetOld::BIBTEX_CODE
708 || code == InsetOld::FLOAT_LIST_CODE
709 || code == InsetOld::TOC_CODE))
717 if (code != InsetOld::NO_CODE && tli && !tli->insetAllowed(code))
723 // A few general toggles
725 case LFUN_TOOLTIPS_TOGGLE:
726 flag.setOnOff(owner->getDialogs().tooltipsEnabled());
729 case LFUN_READ_ONLY_TOGGLE:
730 flag.setOnOff(buf->isReadonly());
733 flag.setOnOff(view()->getLyXText()->cursor.par()->params().startOfAppendix());
735 case LFUN_SWITCHBUFFER:
736 // toggle on the current buffer, but do not toggle off
737 // the other ones (is that a good idea?)
738 if (ev.argument == buf->fileName())
741 case LFUN_TRACK_CHANGES:
742 flag.setOnOff(buf->params().tracking_changes);
748 // the font related toggles
750 LyXFont const & font = view()->getLyXText()->real_current_font;
753 flag.setOnOff(font.emph() == LyXFont::ON);
756 flag.setOnOff(font.noun() == LyXFont::ON);
759 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
762 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
765 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
768 flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
774 string tc = mathcursor->getLastCode();
777 flag.setOnOff(tc == "mathbf");
780 flag.setOnOff(tc == "mathsf");
783 flag.setOnOff(tc == "mathcal");
786 flag.setOnOff(tc == "mathrm");
789 flag.setOnOff(tc == "mathtt");
792 flag.setOnOff(tc == "mathbb");
795 flag.setOnOff(tc == "mathnormal");
802 // this one is difficult to get right. As a half-baked
803 // solution, we consider only the first action of the sequence
804 if (ev.action == LFUN_SEQUENCE) {
805 // argument contains ';'-terminated commands
806 #warning LyXAction arguements not handled here.
807 flag = getStatus(FuncRequest(lyxaction.lookupFunc(token(ev.argument, ';', 0))));
814 void LyXFunc::dispatch(string const & s, bool verbose)
816 FuncRequest func = lyxaction.lookupFunc(s);
818 if (func.action == LFUN_UNKNOWN_ACTION) {
819 owner->message(bformat(_("Unknown function (%1$s)"), s));
823 dispatch(func, verbose);
828 bool ensureBufferClean(BufferView * bv) {
830 Buffer & buf = *bv->buffer();
834 string const file = MakeDisplayPath(buf.fileName(), 30);
835 string text = bformat(_("The document %1$s has unsaved "
836 "changes.\n\nDo you want to save "
837 "the document?"), file);
838 int const ret = Alert::prompt(_("Save changed document?"),
839 text, 0, 1, _("&Save"),
843 bv->owner()->dispatch(FuncRequest(LFUN_MENUWRITE));
845 return buf.isClean();
851 void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
853 string argument = func.argument;
854 kb_action action = func.action;
856 lyxerr[Debug::ACTION] << "LyXFunc::dispatch: action[" << action
857 <<"] arg[" << argument << ']' << endl;
859 // we have not done anything wrong yet.
861 dispatch_buffer.erase();
863 #ifdef NEW_DISPATCHER
864 // We try do call the most specific dispatcher first:
865 // 1. the lockinginset's dispatch
866 // 2. the bufferview's dispatch
867 // 3. the lyxview's dispatch
870 selection_possible = false;
872 // We cannot use this function here
873 if (getStatus(func).disabled()) {
874 lyxerr[Debug::ACTION] << "LyXFunc::dispatch: "
875 << lyxaction.getActionName(action)
876 << " [" << action << "] is disabled at this location"
878 setErrorMessage(getStatusMessage());
879 goto exit_with_message;
882 if (view()->available())
883 view()->hideCursor();
888 buildCursor(cursor, *view());
889 if (cursor.dispatch(FuncRequest(func, view())) == DISPATCHED) {
890 lyxerr << "dispatched by Cursor::dispatch()\n";
891 goto exit_with_message;
897 if (view()->available() && view()->theLockingInset()) {
898 InsetOld::RESULT result;
899 if (action > 1 || (action == LFUN_UNKNOWN_ACTION &&
902 UpdatableInset * inset = view()->theLockingInset();
906 inset->getCursorPos(view(), inset_x, dummy_y);
908 if ((action == LFUN_UNKNOWN_ACTION)
909 && argument.empty()) {
910 argument = encoded_last_key;
913 // the insets can't try to handle this,
914 // a table cell in the dummy position will
915 // lock its insettext, the insettext will
916 // pass it the bufferview, and succeed,
917 // so it will stay not locked. Not good
918 // if we've just done LFUN_ESCAPE (which
919 // injects an LFUN_PARAGRAPH_UPDATE)
920 if (action == LFUN_PARAGRAPH_UPDATE) {
921 view()->dispatch(func);
922 goto exit_with_message;
925 // Undo/Redo is a bit tricky for insets.
926 if (action == LFUN_UNDO) {
928 goto exit_with_message;
929 } else if (action == LFUN_REDO) {
931 goto exit_with_message;
932 } else if (((result=inset->
933 // Hand-over to inset's own dispatch:
934 localDispatch(FuncRequest(view(), action, argument))) ==
936 (result == DISPATCHED_NOUPDATE))
937 goto exit_with_message;
938 // If UNDISPATCHED, just soldier on
939 else if (result == FINISHED) {
940 owner->clearMessage();
941 goto exit_with_message;
942 // We do not need special RTL handling here:
943 // FINISHED means that the cursor should be
944 // one position after the inset.
945 } else if (result == FINISHED_RIGHT) {
946 view()->text->cursorRight(view());
948 owner->clearMessage();
949 goto exit_with_message;
950 } else if (result == FINISHED_UP) {
951 RowList::iterator const irow = view()->text->cursorIRow();
952 if (irow != view()->text->firstRow()) {
954 view()->text->setCursorFromCoordinates(
955 view()->text->cursor.x() + inset_x,
956 view()->text->cursor.y() -
957 irow->baseline() - 1);
958 view()->text->cursor.x_fix(view()->text->cursor.x());
960 view()->text->cursorUp(view());
966 owner->clearMessage();
967 goto exit_with_message;
968 } else if (result == FINISHED_DOWN) {
969 RowList::iterator const irow = view()->text->cursorIRow();
970 if (irow != view()->text->lastRow()) {
972 view()->text->setCursorFromCoordinates(
973 view()->text->cursor.x() + inset_x,
974 view()->text->cursor.y() -
977 view()->text->cursor.x_fix(view()->text->cursor.x());
979 view()->text->cursorDown(view());
982 view()->text->cursorRight(view());
985 owner->clearMessage();
986 goto exit_with_message;
988 #warning I am not sure this is still right, please have a look! (Jug 20020417)
989 else { // result == UNDISPATCHED
990 //setMessage(N_("Text mode"));
992 case LFUN_UNKNOWN_ACTION:
993 case LFUN_BREAKPARAGRAPH:
995 view()->text->cursorRight(view());
996 view()->switchKeyMap();
997 owner->view_state_changed();
1000 if (!view()->text->cursor.par()->isRightToLeftPar(owner->buffer()->params())) {
1001 view()->text->cursorRight(view());
1003 owner->view_state_changed();
1005 goto exit_with_message;
1007 if (view()->text->cursor.par()->isRightToLeftPar(owner->buffer()->params())) {
1008 view()->text->cursorRight(view());
1010 owner->view_state_changed();
1012 goto exit_with_message;
1014 if (view()->text->cursorRow() != view()->text->lastRow())
1015 view()->text->cursorDown(view());
1017 view()->text->cursorRight(view());
1019 owner->view_state_changed();
1020 goto exit_with_message;
1031 if (!view()->available())
1033 // this function should be used always [asierra060396]
1034 UpdatableInset * tli = view()->theLockingInset();
1036 UpdatableInset * lock = tli->getLockingInset();
1039 view()->unlockInset(tli);
1040 view()->text->cursorRight(view());
1042 owner->view_state_changed();
1044 tli->unlockInsetInInset(view(), lock, true);
1047 // Tell the paragraph dialog that we changed paragraph
1048 dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
1053 case LFUN_WORDFINDFORWARD:
1054 case LFUN_WORDFINDBACKWARD: {
1055 static string last_search;
1056 string searched_string;
1058 if (!argument.empty()) {
1059 last_search = argument;
1060 searched_string = argument;
1062 searched_string = last_search;
1064 bool fw = (action == LFUN_WORDFINDFORWARD);
1065 if (!searched_string.empty())
1066 lyx::find::find(view(), searched_string, fw);
1071 if (view()->available() && !view()->theLockingInset())
1073 owner->message(keyseq.printOptions());
1076 // --- Misc -------------------------------------------
1077 case LFUN_EXEC_COMMAND:
1078 owner->focus_command_buffer();
1083 meta_fake_bit = key_modifier::none;
1084 if (view()->available())
1085 // cancel any selection
1086 dispatch(FuncRequest(LFUN_MARK_OFF));
1087 setMessage(N_("Cancel"));
1090 case LFUN_META_FAKE:
1091 meta_fake_bit = key_modifier::alt;
1092 setMessage(keyseq.print());
1095 case LFUN_READ_ONLY_TOGGLE:
1096 if (owner->buffer()->lyxvc().inUse())
1097 owner->buffer()->lyxvc().toggleReadOnly();
1099 owner->buffer()->setReadonly(
1100 !owner->buffer()->isReadonly());
1103 case LFUN_CENTER: // this is center and redraw.
1107 // --- Menus -----------------------------------------------
1109 menuNew(argument, false);
1112 case LFUN_MENUNEWTMPLT:
1113 menuNew(argument, true);
1116 case LFUN_CLOSEBUFFER:
1120 case LFUN_MENUWRITE:
1121 if (!owner->buffer()->isUnnamed()) {
1122 string const str = bformat(_("Saving document %1$s..."),
1123 MakeDisplayPath(owner->buffer()->fileName()));
1124 owner->message(str);
1125 MenuWrite(owner->buffer());
1126 owner->message(str + _(" done."));
1128 WriteAs(owner->buffer());
1132 WriteAs(owner->buffer(), argument);
1135 case LFUN_MENURELOAD: {
1136 string const file = MakeDisplayPath(view()->buffer()->fileName(), 20);
1137 string text = bformat(_("Any changes will be lost. Are you sure "
1138 "you want to revert to the saved version of the document %1$s?"), file);
1139 int const ret = Alert::prompt(_("Revert to saved document?"),
1140 text, 0, 1, _("&Revert"), _("&Cancel"));
1148 Exporter::Export(owner->buffer(), argument, true);
1149 view()->showErrorList(BufferFormat(*owner->buffer()));
1153 Exporter::Preview(owner->buffer(), argument);
1154 view()->showErrorList(BufferFormat(*owner->buffer()));
1157 case LFUN_BUILDPROG:
1158 Exporter::Export(owner->buffer(), "program", true);
1159 view()->showErrorList(_("Build"));
1162 case LFUN_RUNCHKTEX:
1163 owner->buffer()->runChktex();
1164 view()->showErrorList(_("ChkTeX"));
1168 if (argument == "custom")
1169 owner->getDialogs().showSendto();
1171 Exporter::Export(owner->buffer(), argument, false);
1172 view()->showErrorList(BufferFormat(*owner->buffer()));
1186 InsetCommandParams p("tableofcontents");
1187 string const data = InsetCommandMailer::params2string("toc", p);
1188 owner->getDialogs().show("toc", data, 0);
1204 case LFUN_FREEFONT_APPLY:
1205 apply_freefont(view());
1208 case LFUN_FREEFONT_UPDATE:
1209 update_and_apply_freefont(view(), argument);
1212 case LFUN_RECONFIGURE:
1213 Reconfigure(view());
1217 case LFUN_FLOATSOPERATE:
1218 if (argument == "openfoot")
1219 view()->allFloats(1,0);
1220 else if (argument == "closefoot")
1221 view()->allFloats(0,0);
1222 else if (argument == "openfig")
1223 view()->allFloats(1,1);
1224 else if (argument == "closefig")
1225 view()->allFloats(0,1);
1228 #ifdef WITH_WARNINGS
1229 //#warning Find another implementation here (or another lyxfunc)!
1232 case LFUN_HELP_OPEN:
1234 string const arg = argument;
1236 setErrorMessage(N_("Missing argument"));
1239 string const fname = i18nLibFileSearch("doc", arg, "lyx");
1240 if (fname.empty()) {
1241 lyxerr << "LyX: unable to find documentation file `"
1242 << arg << "'. Bad installation?" << endl;
1245 owner->message(bformat(_("Opening help file %1$s..."),
1246 MakeDisplayPath(fname)));
1247 view()->loadLyXFile(fname, false);
1251 // --- version control -------------------------------
1252 case LFUN_VC_REGISTER:
1254 if (!ensureBufferClean(view()))
1256 if (!owner->buffer()->lyxvc().inUse()) {
1257 owner->buffer()->lyxvc().registrer();
1263 case LFUN_VC_CHECKIN:
1265 if (!ensureBufferClean(view()))
1267 if (owner->buffer()->lyxvc().inUse()
1268 && !owner->buffer()->isReadonly()) {
1269 owner->buffer()->lyxvc().checkIn();
1275 case LFUN_VC_CHECKOUT:
1277 if (!ensureBufferClean(view()))
1279 if (owner->buffer()->lyxvc().inUse()
1280 && owner->buffer()->isReadonly()) {
1281 owner->buffer()->lyxvc().checkOut();
1287 case LFUN_VC_REVERT:
1289 owner->buffer()->lyxvc().revert();
1296 owner->buffer()->lyxvc().undoLast();
1301 // --- buffers ----------------------------------------
1303 case LFUN_SWITCHBUFFER:
1304 view()->buffer(bufferlist.getBuffer(argument));
1308 NewFile(view(), argument);
1311 case LFUN_FILE_OPEN:
1315 case LFUN_LAYOUT_TABULAR:
1316 if (view()->theLockingInset()) {
1317 if (view()->theLockingInset()->lyxCode()== InsetOld::TABULAR_CODE) {
1318 InsetTabular * inset = static_cast<InsetTabular *>
1319 (view()->theLockingInset());
1320 inset->openLayoutDialog(view());
1321 } else if (view()->theLockingInset()->
1322 getFirstLockingInsetOfType(InsetOld::TABULAR_CODE)!=0) {
1323 InsetTabular * inset = static_cast<InsetTabular *>(
1324 view()->theLockingInset()->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE));
1325 inset->openLayoutDialog(view());
1330 case LFUN_DROP_LAYOUTS_CHOICE:
1331 owner->getToolbar().openLayoutList();
1334 case LFUN_MENU_OPEN_BY_NAME:
1335 owner->getMenubar().openByName(argument);
1336 break; // RVDK_PATCH_5
1338 // --- lyxserver commands ----------------------------
1342 setMessage(owner->buffer()->fileName());
1343 lyxerr[Debug::INFO] << "FNAME["
1344 << owner->buffer()->fileName()
1350 dispatch_buffer = keyseq.print();
1351 lyxserver->notifyClient(dispatch_buffer);
1355 case LFUN_GOTOFILEROW:
1359 istringstream istr(argument.c_str());
1360 istr >> file_name >> row;
1361 // Must replace extension of the file to be .lyx and get full path
1362 string const s(ChangeExtension(file_name, ".lyx"));
1364 // Either change buffer or load the file
1365 if (bufferlist.exists(s)) {
1366 view()->buffer(bufferlist.getBuffer(s));
1368 view()->loadLyXFile(s);
1371 view()->setCursorFromRow(row);
1374 // see BufferView_pimpl::center()
1375 view()->updateScrollbar();
1379 case LFUN_GOTO_PARAGRAPH:
1381 istringstream istr(argument.c_str());
1385 ParIterator par = owner->buffer()->getParFromID(id);
1386 if (par == owner->buffer()->par_iterator_end()) {
1387 lyxerr[Debug::INFO] << "No matching paragraph found! ["
1388 << id << ']' << endl;
1391 lyxerr[Debug::INFO] << "Paragraph " << par->id()
1392 << " found." << endl;
1395 if (view()->theLockingInset())
1396 view()->unlockInset(view()->theLockingInset());
1397 if (par->inInset()) {
1398 FuncRequest cmd(view(), LFUN_INSET_EDIT, "left");
1399 par->inInset()->localDispatch(cmd);
1402 view()->getLyXText()->setCursor(par.pit(), 0);
1403 view()->switchKeyMap();
1404 owner->view_state_changed();
1407 // see BufferView_pimpl::center()
1408 view()->updateScrollbar();
1412 // --- insert characters ----------------------------------------
1414 // --- Mathed stuff. If we are here, there is no locked inset yet.
1415 case LFUN_MATH_EXTERN:
1416 case LFUN_MATH_NUMBER:
1417 case LFUN_MATH_NONUMBER:
1418 case LFUN_MATH_LIMITS:
1420 setErrorMessage(N_("This is only allowed in math mode!"));
1424 // passthrough hat and underscore outside mathed:
1425 case LFUN_SUBSCRIPT:
1426 dispatch(FuncRequest(view(), LFUN_SELFINSERT, "_"));
1428 case LFUN_SUPERSCRIPT:
1429 dispatch(FuncRequest(view(), LFUN_SELFINSERT, "^"));
1432 case LFUN_DIALOG_SHOW: {
1433 string const name = func.getArg(0);
1434 string data = trim(func.argument.substr(name.size()));
1436 if (name == "character") {
1437 data = freefont2string();
1439 owner->getDialogs().show("character", data);
1440 } else if (name == "document")
1441 owner->getDialogs().showDocument();
1442 else if (name == "findreplace")
1443 owner->getDialogs().showSearch();
1444 else if (name == "forks")
1445 owner->getDialogs().showForks();
1446 else if (name == "preamble")
1447 owner->getDialogs().showPreamble();
1448 else if (name == "preferences")
1449 owner->getDialogs().showPreferences();
1450 else if (name == "print")
1451 owner->getDialogs().showPrint();
1452 else if (name == "spellchecker")
1453 owner->getDialogs().showSpellchecker();
1455 owner->getDialogs().show(name, data);
1459 case LFUN_DIALOG_SHOW_NEW_INSET: {
1460 string const & name = argument;
1462 if (name == "bibitem" ||
1464 name == "include" ||
1469 InsetCommandParams p(name);
1470 data = InsetCommandMailer::params2string(name, p);
1471 } else if (name == "citation") {
1472 InsetCommandParams p("cite");
1473 data = InsetCommandMailer::params2string(name, p);
1475 owner->getDialogs().show(name, data, 0);
1479 case LFUN_DIALOG_SHOW_NEXT_INSET: {
1483 case LFUN_INSET_DIALOG_SHOW: {
1484 LyXText * lt = view()->getLyXText();
1485 InsetOld * inset = lt->getInset();
1487 FuncRequest cmd(view(), LFUN_INSET_DIALOG_SHOW);
1488 inset->localDispatch(cmd);
1493 case LFUN_DIALOG_UPDATE: {
1494 string const & name = argument;
1495 // Can only update a dialog connected to an existing inset
1496 InsetBase * inset = owner->getDialogs().getOpenInset(name);
1498 FuncRequest fr(view(), LFUN_INSET_DIALOG_UPDATE,
1500 inset->localDispatch(fr);
1501 } else if (name == "paragraph") {
1502 dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
1507 case LFUN_DIALOG_HIDE:
1508 Dialogs::hide(argument, 0);
1511 case LFUN_DIALOG_DISCONNECT_INSET:
1512 owner->getDialogs().disconnect(argument);
1515 case LFUN_CHILDOPEN:
1517 string const filename =
1518 MakeAbsPath(argument,
1519 owner->buffer()->filePath());
1520 setMessage(N_("Opening child document ") +
1521 MakeDisplayPath(filename) + "...");
1522 view()->savePosition(0);
1523 if (bufferlist.exists(filename))
1524 view()->buffer(bufferlist.getBuffer(filename));
1526 view()->loadLyXFile(filename);
1530 case LFUN_TOGGLECURSORFOLLOW:
1531 lyxrc.cursor_follows_scrollbar = !lyxrc.cursor_follows_scrollbar;
1535 owner->getIntl().KeyMapOn(false);
1538 case LFUN_KMAP_PRIM:
1539 owner->getIntl().KeyMapPrim();
1543 owner->getIntl().KeyMapSec();
1546 case LFUN_KMAP_TOGGLE:
1547 owner->getIntl().ToggleKeyMap();
1552 // argument contains ';'-terminated commands
1553 while (!argument.empty()) {
1555 argument = split(argument, first, ';');
1561 case LFUN_SAVEPREFERENCES:
1563 Path p(user_lyxdir());
1564 lyxrc.write("preferences");
1568 case LFUN_SCREEN_FONT_UPDATE:
1570 // handle the screen font changes.
1571 lyxrc.set_font_norm_type();
1572 lyx_gui::update_fonts();
1573 // We also need to empty the textcache so that
1574 // the buffer will be formatted correctly after
1577 // Of course we should only do the resize and the textcache.clear
1578 // if values really changed...but not very important right now. (Lgb)
1579 // All visible buffers will need resize
1585 case LFUN_SET_COLOR:
1588 string const x11_name = split(argument, lyx_name, ' ');
1589 if (lyx_name.empty() || x11_name.empty()) {
1590 setErrorMessage(N_("Syntax: set-color <lyx_name>"
1595 bool const graphicsbg_changed =
1596 (lyx_name == lcolor.getLyXName(LColor::graphicsbg) &&
1597 x11_name != lcolor.getX11Name(LColor::graphicsbg));
1599 if (!lcolor.setColor(lyx_name, x11_name)) {
1601 bformat(_("Set-color \"%1$s\" failed "
1602 "- color is undefined or "
1603 "may not be redefined"), lyx_name));
1607 lyx_gui::update_color(lcolor.getFromLyXName(lyx_name));
1609 if (graphicsbg_changed) {
1610 #ifdef WITH_WARNINGS
1611 #warning FIXME!! The graphics cache no longer has a changeDisplay method.
1614 lyx::graphics::GCache & gc =
1615 lyx::graphics::GCache::get();
1616 gc.changeDisplay(true);
1625 owner->message(argument);
1628 case LFUN_FORKS_KILL:
1630 if (!isStrInt(argument))
1633 pid_t const pid = strToInt(argument);
1634 ForkedcallsController & fcc = ForkedcallsController::get();
1639 case LFUN_TOOLTIPS_TOGGLE:
1640 owner->getDialogs().toggleTooltips();
1643 case LFUN_EXTERNAL_EDIT: {
1645 .localDispatch(FuncRequest(view(), action, argument));
1650 // Then if it was none of the above
1651 // Trying the BufferView::pimpl dispatch:
1652 if (!view()->dispatch(func))
1653 lyxerr << "A truly unknown func ["
1654 << lyxaction.getActionName(func.action) << "]!"
1661 view()->owner()->updateLayoutChoice();
1663 if (view()->available()) {
1664 if (view()->fitCursor()) {
1665 //lyxerr << "LyXFunc->fitCursor->update" << endl;
1669 // If we executed a mutating lfun, mark the buffer as dirty
1670 if (!getStatus(func).disabled()
1671 && !lyxaction.funcHasFlag(func.action, LyXAction::NoBuffer)
1672 && !lyxaction.funcHasFlag(func.action, LyXAction::ReadOnly))
1673 view()->buffer()->markDirty();
1676 sendDispatchMessage(getMessage(), func, verbose);
1680 void LyXFunc::sendDispatchMessage(string const & msg,
1681 FuncRequest const & func, bool verbose)
1683 owner->updateMenubar();
1684 owner->updateToolbar();
1686 if (func.action == LFUN_SELFINSERT || !verbose) {
1687 lyxerr[Debug::ACTION] << "dispatch msg is " << msg << endl;
1689 owner->message(msg);
1693 string dispatch_msg = msg;
1694 if (!dispatch_msg.empty())
1695 dispatch_msg += ' ';
1697 string comname = lyxaction.getActionName(func.action);
1699 bool argsadded = false;
1701 if (!func.argument.empty()) {
1702 if (func.action != LFUN_UNKNOWN_ACTION) {
1703 comname += ' ' + func.argument;
1708 string const shortcuts = toplevel_keymap->findbinding(func);
1710 if (!shortcuts.empty()) {
1711 comname += ": " + shortcuts;
1712 } else if (!argsadded && !func.argument.empty()) {
1713 comname += ' ' + func.argument;
1716 if (!comname.empty()) {
1717 comname = rtrim(comname);
1718 dispatch_msg += '(' + comname + ')';
1721 lyxerr[Debug::ACTION] << "verbose dispatch msg " << dispatch_msg << endl;
1722 if (!dispatch_msg.empty())
1723 owner->message(dispatch_msg);
1727 void LyXFunc::setupLocalKeymap()
1729 keyseq.stdmap = keyseq.curmap = toplevel_keymap.get();
1730 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap.get();
1734 void LyXFunc::menuNew(string const & name, bool fromTemplate)
1736 string initpath = lyxrc.document_path;
1737 string filename(name);
1739 if (view()->available()) {
1740 string const trypath = owner->buffer()->filePath();
1741 // If directory is writeable, use this as default.
1742 if (IsDirWriteable(trypath))
1746 static int newfile_number;
1748 if (filename.empty()) {
1749 filename = AddName(lyxrc.document_path,
1750 "newfile" + tostr(++newfile_number) + ".lyx");
1751 FileInfo fi(filename);
1752 while (bufferlist.exists(filename) || fi.readable()) {
1754 filename = AddName(lyxrc.document_path,
1755 "newfile" + tostr(newfile_number) +
1757 fi.newFile(filename);
1761 // The template stuff
1764 FileDialog fileDlg(_("Select template file"),
1765 LFUN_SELECT_FILE_SYNC,
1766 make_pair(string(_("Documents|#o#O")),
1767 string(lyxrc.document_path)),
1768 make_pair(string(_("Templates|#T#t")),
1769 string(lyxrc.template_path)));
1771 FileDialog::Result result =
1772 fileDlg.open(lyxrc.template_path,
1773 _("*.lyx| LyX Documents (*.lyx)"));
1775 if (result.first == FileDialog::Later)
1778 string const fname = result.second;
1785 view()->newFile(filename, templname, !name.empty());
1789 void LyXFunc::open(string const & fname)
1791 string initpath = lyxrc.document_path;
1793 if (view()->available()) {
1794 string const trypath = owner->buffer()->filePath();
1795 // If directory is writeable, use this as default.
1796 if (IsDirWriteable(trypath))
1802 if (fname.empty()) {
1803 FileDialog fileDlg(_("Select document to open"),
1805 make_pair(string(_("Documents|#o#O")),
1806 string(lyxrc.document_path)),
1807 make_pair(string(_("Examples|#E#e")),
1808 string(AddPath(system_lyxdir(), "examples"))));
1810 FileDialog::Result result =
1811 fileDlg.open(initpath,
1812 _("*.lyx| LyX Documents (*.lyx)"));
1814 if (result.first == FileDialog::Later)
1817 filename = result.second;
1819 // check selected filename
1820 if (filename.empty()) {
1821 owner->message(_("Canceled."));
1827 // get absolute path of file and add ".lyx" to the filename if
1829 string const fullpath = FileSearch(string(), filename, "lyx");
1830 if (!fullpath.empty()) {
1831 filename = fullpath;
1834 string const disp_fn(MakeDisplayPath(filename));
1836 // if the file doesn't exist, let the user create one
1837 FileInfo const f(filename, true);
1839 // the user specifically chose this name. Believe them.
1840 view()->newFile(filename, "", true);
1844 owner->message(bformat(_("Opening document %1$s..."), disp_fn));
1847 if (view()->loadLyXFile(filename)) {
1848 str2 = bformat(_("Document %1$s opened."), disp_fn);
1850 str2 = bformat(_("Could not open document %1$s"), disp_fn);
1852 owner->message(str2);
1856 void LyXFunc::doImport(string const & argument)
1859 string filename = split(argument, format, ' ');
1861 lyxerr[Debug::INFO] << "LyXFunc::doImport: " << format
1862 << " file: " << filename << endl;
1864 // need user interaction
1865 if (filename.empty()) {
1866 string initpath = lyxrc.document_path;
1868 if (view()->available()) {
1869 string const trypath = owner->buffer()->filePath();
1870 // If directory is writeable, use this as default.
1871 if (IsDirWriteable(trypath))
1875 string const text = bformat(_("Select %1$s file to import"),
1876 formats.prettyName(format));
1878 FileDialog fileDlg(text,
1880 make_pair(string(_("Documents|#o#O")),
1881 string(lyxrc.document_path)),
1882 make_pair(string(_("Examples|#E#e")),
1883 string(AddPath(system_lyxdir(), "examples"))));
1885 string const extension = "*." + formats.extension(format)
1886 + "| " + formats.prettyName(format)
1887 + " (*." + formats.extension(format) + ')';
1889 FileDialog::Result result = fileDlg.open(initpath,
1892 if (result.first == FileDialog::Later)
1895 filename = result.second;
1897 // check selected filename
1898 if (filename.empty())
1899 owner->message(_("Canceled."));
1902 if (filename.empty())
1905 // get absolute path of file
1906 filename = MakeAbsPath(filename);
1908 string const lyxfile = ChangeExtension(filename, ".lyx");
1910 // Check if the document already is open
1911 if (lyx_gui::use_gui && bufferlist.exists(lyxfile)) {
1912 if (!bufferlist.close(bufferlist.getBuffer(lyxfile), true)) {
1913 owner->message(_("Canceled."));
1918 // if the file exists already, and we didn't do
1919 // -i lyx thefile.lyx, warn
1920 if (FileInfo(lyxfile, true).exist() && filename != lyxfile) {
1921 string const file = MakeDisplayPath(lyxfile, 30);
1923 string text = bformat(_("The document %1$s already exists.\n\n"
1924 "Do you want to over-write that document?"), file);
1925 int const ret = Alert::prompt(_("Over-write document?"),
1926 text, 0, 1, _("&Over-write"), _("&Cancel"));
1929 owner->message(_("Canceled."));
1934 Importer::Import(owner, filename, format);
1938 void LyXFunc::closeBuffer()
1940 if (bufferlist.close(owner->buffer(), true) && !quitting) {
1941 if (bufferlist.empty()) {
1942 // need this otherwise SEGV may occur while
1943 // trying to set variables that don't exist
1944 // since there's no current buffer
1945 owner->getDialogs().hideBufferDependent();
1947 view()->buffer(bufferlist.first());
1953 // Each "owner" should have it's own message method. lyxview and
1954 // the minibuffer would use the minibuffer, but lyxserver would
1955 // send an ERROR signal to its client. Alejandro 970603
1956 // This func is bit problematic when it comes to NLS, to make the
1957 // lyx servers client be language indepenent we must not translate
1958 // strings sent to this func.
1959 void LyXFunc::setErrorMessage(string const & m) const
1961 dispatch_buffer = m;
1966 void LyXFunc::setMessage(string const & m) const
1968 dispatch_buffer = m;
1972 void LyXFunc::setStatusMessage(string const & m) const
1978 string const LyXFunc::view_status_message()
1980 // When meta-fake key is pressed, show the key sequence so far + "M-".
1982 return keyseq.print() + "M-";
1985 // Else, when a non-complete key sequence is pressed,
1986 // show the available options.
1987 if (keyseq.length() > 0 && !keyseq.deleted()) {
1988 return keyseq.printOptions();
1991 if (!view()->available())
1992 return _("Welcome to LyX!");
1994 return currentState(view());
1998 BufferView * LyXFunc::view() const
2000 BOOST_ASSERT(owner);
2001 return owner->view().get();
2005 bool LyXFunc::wasMetaKey() const
2007 return (meta_fake_bit != key_modifier::none);