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"
53 #include "insets/insetcommand.h"
54 #include "insets/insetexternal.h"
55 #include "insets/insettabular.h"
57 #include "mathed/math_cursor.h"
59 #include "frontends/Alert.h"
60 #include "frontends/Dialogs.h"
61 #include "frontends/FileDialog.h"
62 #include "frontends/lyx_gui.h"
63 #include "frontends/LyXKeySym.h"
64 #include "frontends/LyXView.h"
65 #include "frontends/Menubar.h"
66 #include "frontends/Toolbar.h"
68 #include "support/FileInfo.h"
69 #include "support/filetools.h"
70 #include "support/forkedcontr.h"
71 #include "support/path.h"
72 #include "support/path_defines.h"
73 #include "support/tostr.h"
74 #include "support/std_sstream.h"
75 #include "support/os.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;
107 using lyx::support::prefixIs;
108 using lyx::support::os::getTmpDir;
111 using std::make_pair;
113 using std::istringstream;
116 extern BufferList bufferlist;
117 extern LyXServer * lyxserver;
118 extern bool selection_possible;
120 extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
123 extern tex_accent_struct get_accent(kb_action action);
125 extern void ShowLatexLog();
128 LyXFunc::LyXFunc(LyXView * o)
131 keyseq(toplevel_keymap.get(), toplevel_keymap.get()),
132 cancel_meta_seq(toplevel_keymap.get(), toplevel_keymap.get()),
133 meta_fake_bit(key_modifier::none)
138 void LyXFunc::moveCursorUpdate()
140 LyXText * lt = view()->text;
141 if (lt->selection.mark())
144 view()->switchKeyMap();
148 void LyXFunc::handleKeyFunc(kb_action action)
150 char c = encoded_last_key;
152 if (keyseq.length()) {
156 owner->getIntl().getTransManager()
157 .deadkey(c, get_accent(action).accent, view()->getLyXText());
158 // Need to clear, in case the minibuffer calls these
161 // copied verbatim from do_accent_char
163 view()->getLyXText()->selection.cursor = view()->getLyXText()->cursor;
167 void LyXFunc::processKeySym(LyXKeySymPtr keysym,
168 key_modifier::state state)
172 if (lyxerr.debugging(Debug::KEY)) {
173 lyxerr << "KeySym is "
174 << keysym->getSymbolName()
178 // Do nothing if we have nothing (JMarc)
179 if (!keysym->isOK()) {
180 lyxerr[Debug::KEY] << "Empty kbd action (probably composing)"
185 if (keysym->isModifier()) {
186 lyxerr[Debug::KEY] << "isModifier true" << endl;
190 Encoding const * encoding = view()->getEncoding();
192 encoded_last_key = keysym->getISOEncoded(encoding ? encoding->Name() : "");
194 // Do a one-deep top-level lookup for
195 // cancel and meta-fake keys. RVDK_PATCH_5
196 cancel_meta_seq.reset();
198 FuncRequest func = cancel_meta_seq.addkey(keysym, state);
199 lyxerr[Debug::KEY] << "action first set to [" << func.action << ']' << endl;
201 // When not cancel or meta-fake, do the normal lookup.
202 // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
203 // Mostly, meta_fake_bit = key_modifier::none. RVDK_PATCH_5.
204 if ((func.action != LFUN_CANCEL) && (func.action != LFUN_META_FAKE)) {
205 // remove Caps Lock and Mod2 as a modifiers
206 func = keyseq.addkey(keysym, (state | meta_fake_bit));
207 lyxerr[Debug::KEY] << "action now set to ["
208 << func.action << ']' << endl;
211 // Dont remove this unless you know what you are doing.
212 meta_fake_bit = key_modifier::none;
214 // can this happen now ?
215 if (func.action == LFUN_NOACTION) {
216 func = FuncRequest(LFUN_PREFIX);
219 if (lyxerr.debugging(Debug::KEY)) {
220 lyxerr << "Key [action="
221 << func.action << "]["
222 << keyseq.print() << ']'
226 // already here we know if it any point in going further
227 // why not return already here if action == -1 and
228 // num_bytes == 0? (Lgb)
230 if (keyseq.length() > 1) {
231 owner->message(keyseq.print());
235 // Maybe user can only reach the key via holding down shift.
236 // Let's see. But only if shift is the only modifier
237 if (func.action == LFUN_UNKNOWN_ACTION &&
238 state == key_modifier::shift) {
239 lyxerr[Debug::KEY] << "Trying without shift" << endl;
240 func = keyseq.addkey(keysym, key_modifier::none);
241 lyxerr[Debug::KEY] << "Action now " << func.action << endl;
244 if (func.action == LFUN_UNKNOWN_ACTION) {
245 // Hmm, we didn't match any of the keysequences. See
246 // if it's normal insertable text not already covered
248 if (keysym->isText() && keyseq.length() == 1) {
249 lyxerr[Debug::KEY] << "isText() is true, inserting." << endl;
250 func = FuncRequest(LFUN_SELFINSERT);
252 lyxerr[Debug::KEY] << "Unknown, !isText() - giving up" << endl;
253 owner->message(_("Unknown function."));
258 if (func.action == LFUN_SELFINSERT) {
259 if (encoded_last_key != 0) {
261 arg += encoded_last_key;
263 dispatch(FuncRequest(view(), LFUN_SELFINSERT, arg));
265 lyxerr[Debug::KEY] << "SelfInsert arg[`"
266 << argument << "']" << endl;
274 FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
277 Buffer * buf = owner->buffer();
279 if (ev.action == LFUN_NOACTION) {
280 setStatusMessage(N_("Nothing to do"));
286 case LFUN_UNKNOWN_ACTION:
287 #ifndef HAVE_LIBAIKSAURUS
288 case LFUN_THESAURUS_ENTRY:
294 flag |= lyx_gui::getStatus(ev);
297 if (flag.unknown()) {
298 setStatusMessage(N_("Unknown action"));
302 // the default error message if we disable the command
303 setStatusMessage(N_("Command disabled"));
305 // Check whether we need a buffer
306 if (!lyxaction.funcHasFlag(ev.action, LyXAction::NoBuffer)) {
307 // Yes we need a buffer, do we have one?
310 // Can we use a readonly buffer?
311 if (buf->isReadonly() &&
312 !lyxaction.funcHasFlag(ev.action,
313 LyXAction::ReadOnly)) {
315 setStatusMessage(N_("Document is read-only"));
320 setStatusMessage(N_("Command not allowed with"
321 "out any document open"));
327 UpdatableInset * tli = view()->theLockingInset();
329 // I would really like to avoid having this switch and rather try to
330 // encode this in the function itself.
331 bool disable = false;
334 disable = ev.argument != "custom"
335 && !Exporter::IsExportable(*buf, ev.argument);
338 disable = buf->undostack().empty();
341 disable = buf->redostack().empty();
346 UpdatableInset * in = tli;
347 if (in->lyxCode() != InsetOld::TABULAR_CODE) {
348 in = tli->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE);
350 if (in && static_cast<InsetTabular*>(in)->hasSelection()) {
355 disable = !mathcursor && !view()->getLyXText()->selection.set();
358 disable = !buf->isLatex() || lyxrc.chktex_command == "none";
361 disable = !Exporter::IsExportable(*buf, "program");
364 case LFUN_LAYOUT_TABULAR:
366 || (tli->lyxCode() != InsetOld::TABULAR_CODE
367 && !tli->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE));
371 disable = !changeDepth(view(), view()->getLyXText(), DEC_DEPTH, true);
374 case LFUN_DEPTH_PLUS:
375 disable = !changeDepth(view(), view()->getLyXText(), INC_DEPTH, true);
379 case LFUN_LAYOUT_PARAGRAPH: {
380 InsetOld * inset = view()->getLyXText()->cursorPar()->inInset();
381 disable = inset && inset->forceDefaultParagraphs(inset);
385 case LFUN_INSET_OPTARG:
386 disable = (view()->getLyXText()->cursorPar()->layout()->optionalargs == 0);
389 case LFUN_TABULAR_FEATURE:
392 // FIXME: check temporarily disabled
394 char align = mathcursor->valign();
399 if (ev.argument.empty()) {
403 if (!contains("tcb", ev.argument[0])) {
407 flag.setOnOff(ev.argument[0] == align);
411 char align = mathcursor->halign();
416 if (ev.argument.empty()) {
420 if (!contains("lcr", ev.argument[0])) {
424 flag.setOnOff(ev.argument[0] == align);
427 disable = !mathcursor->halign();
433 //ret.disabled(true);
434 if (tli->lyxCode() == InsetOld::TABULAR_CODE) {
435 ret = static_cast<InsetTabular *>(tli)
436 ->getStatus(ev.argument);
439 } else if (tli->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE)) {
440 ret = static_cast<InsetTabular *>
441 (tli->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE))
442 ->getStatus(ev.argument);
449 static InsetTabular inset(*owner->buffer(), 1, 1);
453 ret = inset.getStatus(ev.argument);
454 if (ret.onoff(true) || ret.onoff(false))
455 flag.setOnOff(false);
459 case LFUN_VC_REGISTER:
460 disable = buf->lyxvc().inUse();
462 case LFUN_VC_CHECKIN:
463 disable = !buf->lyxvc().inUse() || buf->isReadonly();
465 case LFUN_VC_CHECKOUT:
466 disable = !buf->lyxvc().inUse() || !buf->isReadonly();
470 disable = !buf->lyxvc().inUse();
472 case LFUN_MENURELOAD:
473 disable = buf->isUnnamed() || buf->isClean();
475 case LFUN_BOOKMARK_GOTO:
477 isSavedPosition(strToUnsignedInt(ev.argument));
479 case LFUN_MERGE_CHANGES:
480 case LFUN_ACCEPT_CHANGE:
481 case LFUN_REJECT_CHANGE:
482 case LFUN_ACCEPT_ALL_CHANGES:
483 case LFUN_REJECT_ALL_CHANGES:
484 disable = !buf->params().tracking_changes;
486 case LFUN_INSET_TOGGLE: {
487 LyXText * lt = view()->getLyXText();
488 disable = !(isEditableInset(lt->getInset())
490 && lt->inset_owner->owner()
491 && lt->inset_owner->owner()->isOpen()));
495 case LFUN_INSET_SETTINGS: {
497 UpdatableInset * inset = view()->theLockingInset();
502 // get the innermost inset
503 inset = inset->getLockingInset();
505 // jump back to owner if an InsetText, so
506 // we get back to the InsetTabular or whatever
507 if (inset->lyxCode() == InsetOld::TEXT_CODE)
508 inset = inset->owner();
510 InsetOld::Code code = inset->lyxCode();
512 case InsetOld::TABULAR_CODE:
513 disable = ev.argument != "tabular";
515 case InsetOld::ERT_CODE:
516 disable = ev.argument != "ert";
518 case InsetOld::FLOAT_CODE:
519 disable = ev.argument != "float";
521 case InsetOld::MINIPAGE_CODE:
522 disable = ev.argument != "minipage";
524 case InsetOld::WRAP_CODE:
525 disable = ev.argument != "wrap";
527 case InsetOld::NOTE_CODE:
528 disable = ev.argument != "note";
530 case InsetOld::BRANCH_CODE:
531 disable = ev.argument != "branch";
533 case InsetOld::BOX_CODE:
534 disable = ev.argument != "box";
542 case LFUN_MATH_MUTATE:
544 //flag.setOnOff(mathcursor->formula()->hullType() == ev.argument);
545 flag.setOnOff(false);
550 // we just need to be in math mode to enable that
552 case LFUN_MATH_SPACE:
553 case LFUN_MATH_LIMITS:
554 case LFUN_MATH_NONUMBER:
555 case LFUN_MATH_NUMBER:
556 case LFUN_MATH_EXTERN:
557 disable = !mathcursor;
560 case LFUN_DIALOG_SHOW: {
561 string const name = ev.getArg(0);
563 disable = !(name == "aboutlyx" ||
566 name == "preferences" ||
571 if (name == "print") {
572 disable = !Exporter::IsExportable(*buf, "dvi") ||
573 lyxrc.print_command == "none";
574 } else if (name == "character") {
575 UpdatableInset * tli = view()->theLockingInset();
576 disable = tli && tli->lyxCode() == InsetOld::ERT_CODE;
577 } else if (name == "vclog") {
578 disable = !buf->lyxvc().inUse();
579 } else if (name == "latexlog") {
580 disable = !IsFileReadable(buf->getLogName().second);
589 // the functions which insert insets
590 InsetOld::Code code = InsetOld::NO_CODE;
592 case LFUN_DIALOG_SHOW_NEW_INSET:
593 if (ev.argument == "bibitem")
594 code = InsetOld::BIBITEM_CODE;
595 else if (ev.argument == "bibtex")
596 code = InsetOld::BIBTEX_CODE;
597 else if (ev.argument == "citation")
598 code = InsetOld::CITE_CODE;
599 else if (ev.argument == "ert")
600 code = InsetOld::ERT_CODE;
601 else if (ev.argument == "external")
602 code = InsetOld::EXTERNAL_CODE;
603 else if (ev.argument == "float")
604 code = InsetOld::FLOAT_CODE;
605 else if (ev.argument == "graphics")
606 code = InsetOld::GRAPHICS_CODE;
607 else if (ev.argument == "include")
608 code = InsetOld::INCLUDE_CODE;
609 else if (ev.argument == "index")
610 code = InsetOld::INDEX_CODE;
611 else if (ev.argument == "label")
612 code = InsetOld::LABEL_CODE;
613 else if (ev.argument == "minipage")
614 code = InsetOld::MINIPAGE_CODE;
615 else if (ev.argument == "ref")
616 code = InsetOld::REF_CODE;
617 else if (ev.argument == "toc")
618 code = InsetOld::TOC_CODE;
619 else if (ev.argument == "url")
620 code = InsetOld::URL_CODE;
621 else if (ev.argument == "wrap")
622 code = InsetOld::WRAP_CODE;
626 code = InsetOld::ERT_CODE;
628 case LFUN_INSET_FOOTNOTE:
629 code = InsetOld::FOOT_CODE;
631 case LFUN_TABULAR_INSERT:
632 code = InsetOld::TABULAR_CODE;
634 case LFUN_INSET_MARGINAL:
635 code = InsetOld::MARGIN_CODE;
637 case LFUN_INSET_MINIPAGE:
638 code = InsetOld::MINIPAGE_CODE;
640 case LFUN_INSET_FLOAT:
641 case LFUN_INSET_WIDE_FLOAT:
642 code = InsetOld::FLOAT_CODE;
644 case LFUN_INSET_WRAP:
645 code = InsetOld::WRAP_CODE;
647 case LFUN_FLOAT_LIST:
648 code = InsetOld::FLOAT_LIST_CODE;
651 case LFUN_INSET_LIST:
652 code = InsetOld::LIST_CODE;
654 case LFUN_INSET_THEOREM:
655 code = InsetOld::THEOREM_CODE;
658 case LFUN_INSET_CAPTION:
659 code = InsetOld::CAPTION_CODE;
661 case LFUN_INSERT_NOTE:
662 code = InsetOld::NOTE_CODE;
664 case LFUN_INSERT_BOX:
665 code = InsetOld::BOX_CODE;
667 case LFUN_INSERT_BRANCH:
668 code = InsetOld::BRANCH_CODE;
669 if (buf->params().branchlist().empty())
672 case LFUN_INSERT_LABEL:
673 code = InsetOld::LABEL_CODE;
675 case LFUN_INSET_OPTARG:
676 code = InsetOld::OPTARG_CODE;
678 case LFUN_ENVIRONMENT_INSERT:
679 code = InsetOld::MINIPAGE_CODE;
681 case LFUN_INDEX_INSERT:
682 code = InsetOld::INDEX_CODE;
684 case LFUN_INDEX_PRINT:
685 code = InsetOld::INDEX_PRINT_CODE;
687 case LFUN_TOC_INSERT:
688 code = InsetOld::TOC_CODE;
692 code = InsetOld::URL_CODE;
695 // always allow this, since we will inset a raw quote
696 // if an inset is not allowed.
698 case LFUN_HYPHENATION:
699 case LFUN_LIGATURE_BREAK:
701 case LFUN_MENU_SEPARATOR:
703 case LFUN_END_OF_SENTENCE:
704 code = InsetOld::SPECIALCHAR_CODE;
706 case LFUN_SPACE_INSERT:
707 // slight hack: we know this is allowed in math mode
709 code = InsetOld::SPACE_CODE;
711 case LFUN_INSET_DIALOG_SHOW: {
712 LyXText * lt = view()->getLyXText();
713 InsetOld * inset = lt->getInset();
716 code = inset->lyxCode();
717 if (!(code == InsetOld::INCLUDE_CODE
718 || code == InsetOld::BIBTEX_CODE
719 || code == InsetOld::FLOAT_LIST_CODE
720 || code == InsetOld::TOC_CODE))
728 if (code != InsetOld::NO_CODE && tli && !tli->insetAllowed(code))
734 // A few general toggles
736 case LFUN_TOOLTIPS_TOGGLE:
737 flag.setOnOff(owner->getDialogs().tooltipsEnabled());
740 case LFUN_READ_ONLY_TOGGLE:
741 flag.setOnOff(buf->isReadonly());
744 flag.setOnOff(view()->getLyXText()->cursorPar()->params().startOfAppendix());
746 case LFUN_SWITCHBUFFER:
747 // toggle on the current buffer, but do not toggle off
748 // the other ones (is that a good idea?)
749 if (ev.argument == buf->fileName())
752 case LFUN_TRACK_CHANGES:
753 flag.setOnOff(buf->params().tracking_changes);
759 // the font related toggles
761 LyXFont const & font = view()->getLyXText()->real_current_font;
764 flag.setOnOff(font.emph() == LyXFont::ON);
767 flag.setOnOff(font.noun() == LyXFont::ON);
770 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
773 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
776 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
779 flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
785 string tc = mathcursor->getLastCode();
788 flag.setOnOff(tc == "mathbf");
791 flag.setOnOff(tc == "mathsf");
794 flag.setOnOff(tc == "mathcal");
797 flag.setOnOff(tc == "mathrm");
800 flag.setOnOff(tc == "mathtt");
803 flag.setOnOff(tc == "mathbb");
806 flag.setOnOff(tc == "mathnormal");
813 // this one is difficult to get right. As a half-baked
814 // solution, we consider only the first action of the sequence
815 if (ev.action == LFUN_SEQUENCE) {
816 // argument contains ';'-terminated commands
817 #warning LyXAction arguments not handled here.
818 flag = getStatus(FuncRequest(lyxaction.lookupFunc(token(ev.argument, ';', 0))));
827 bool ensureBufferClean(BufferView * bv)
829 Buffer & buf = *bv->buffer();
833 string const file = MakeDisplayPath(buf.fileName(), 30);
834 string text = bformat(_("The document %1$s has unsaved "
835 "changes.\n\nDo you want to save "
836 "the document?"), file);
837 int const ret = Alert::prompt(_("Save changed document?"),
838 text, 0, 1, _("&Save"),
842 bv->owner()->dispatch(FuncRequest(LFUN_MENUWRITE));
844 return buf.isClean();
850 void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
852 string argument = func.argument;
853 kb_action action = func.action;
855 lyxerr[Debug::ACTION] << "LyXFunc::dispatch: action[" << action
856 <<"] arg[" << argument << ']' << endl;
858 // we have not done anything wrong yet.
860 dispatch_buffer.erase();
862 #ifdef NEW_DISPATCHER
863 // We try do call the most specific dispatcher first:
864 // 1. the lockinginset's dispatch
865 // 2. the bufferview's dispatch
866 // 3. the lyxview's dispatch
869 selection_possible = false;
871 // We cannot use this function here
872 if (getStatus(func).disabled()) {
873 lyxerr[Debug::ACTION] << "LyXFunc::dispatch: "
874 << lyxaction.getActionName(action)
875 << " [" << action << "] is disabled at this location"
877 setErrorMessage(getStatusMessage());
878 goto exit_with_message;
881 if (view()->available())
882 view()->hideCursor();
887 buildCursor(cursor, *view());
888 if (cursor.dispatch(FuncRequest(func, view())) == DISPATCHED) {
889 lyxerr << "dispatched by Cursor::dispatch()\n";
890 goto exit_with_message;
896 if (view()->available() && view()->theLockingInset()) {
897 dispatch_result result;
898 if (action > 1 || (action == LFUN_UNKNOWN_ACTION &&
901 UpdatableInset * inset = view()->theLockingInset();
905 inset->getCursorPos(view(), inset_x, dummy_y);
907 if (action == LFUN_UNKNOWN_ACTION
908 && argument.empty()) {
909 argument = encoded_last_key;
912 // the insets can't try to handle this,
913 // a table cell in the dummy position will
914 // lock its insettext, the insettext will
915 // pass it the bufferview, and succeed,
916 // so it will stay not locked. Not good
917 // if we've just done LFUN_ESCAPE (which
918 // injects an LFUN_PARAGRAPH_UPDATE)
919 if (action == LFUN_PARAGRAPH_UPDATE) {
920 view()->dispatch(func);
921 goto exit_with_message;
924 // Undo/Redo is a bit tricky for insets.
925 if (action == LFUN_UNDO) {
927 goto exit_with_message;
930 if (action == LFUN_REDO) {
932 goto exit_with_message;
935 // Hand-over to inset's own dispatch:
936 result = inset->dispatch(FuncRequest(view(), action, argument));
937 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
938 goto exit_with_message;
941 // If UNDISPATCHED, just soldier on
942 if (result == FINISHED) {
943 owner->clearMessage();
944 goto exit_with_message;
945 // We do not need special RTL handling here:
946 // FINISHED means that the cursor should be
947 // one position after the inset.
950 if (result == FINISHED_RIGHT) {
951 view()->text->cursorRight(view());
953 owner->clearMessage();
954 goto exit_with_message;
957 if (result == FINISHED_UP) {
958 LyXText * text = view()->text;
959 ParagraphList::iterator pit = text->cursorPar();
960 Row const & row = *pit->getRow(text->cursor.pos());
961 if (text->isFirstRow(pit, row)) {
963 text->setCursorFromCoordinates(
964 text->cursor.x() + inset_x,
967 text->cursor.x_fix(text->cursor.x());
969 text->cursorUp(view());
975 owner->clearMessage();
976 goto exit_with_message;
979 if (result == FINISHED_DOWN) {
980 LyXText * text = view()->text;
981 ParagraphList::iterator pit = text->cursorPar();
982 Row const & row = *pit->getRow(text->cursor.pos());
983 if (text->isLastRow(pit, row)) {
985 text->setCursorFromCoordinates(
986 text->cursor.x() + inset_x,
990 text->cursor.x_fix(text->cursor.x());
992 text->cursorDown(view());
995 text->cursorRight(view());
998 owner->clearMessage();
999 goto exit_with_message;
1002 #warning I am not sure this is still right, please have a look! (Jug 20020417)
1003 // result == UNDISPATCHED
1004 //setMessage(N_("Text mode"));
1006 case LFUN_UNKNOWN_ACTION:
1007 case LFUN_BREAKPARAGRAPH:
1008 case LFUN_BREAKLINE:
1009 view()->text->cursorRight(view());
1010 view()->switchKeyMap();
1011 owner->view_state_changed();
1014 if (!view()->text->cursorPar()->isRightToLeftPar(owner->buffer()->params())) {
1015 view()->text->cursorRight(view());
1017 owner->view_state_changed();
1019 goto exit_with_message;
1021 if (view()->text->cursorPar()->isRightToLeftPar(owner->buffer()->params())) {
1022 view()->text->cursorRight(view());
1024 owner->view_state_changed();
1026 goto exit_with_message;
1028 LyXText * text = view()->text;
1029 ParagraphList::iterator pit = text->cursorPar();
1030 if (text->isLastRow(pit, *pit->getRow(text->cursor.pos())))
1031 view()->text->cursorDown(view());
1033 view()->text->cursorRight(view());
1035 owner->view_state_changed();
1036 goto exit_with_message;
1047 if (!view()->available())
1049 // this function should be used always [asierra060396]
1050 UpdatableInset * tli = view()->theLockingInset();
1052 UpdatableInset * lock = tli->getLockingInset();
1055 view()->unlockInset(tli);
1056 view()->text->cursorRight(view());
1058 owner->view_state_changed();
1060 tli->unlockInsetInInset(view(), lock, true);
1063 // Tell the paragraph dialog that we changed paragraph
1064 dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
1069 case LFUN_WORDFINDFORWARD:
1070 case LFUN_WORDFINDBACKWARD: {
1071 static string last_search;
1072 string searched_string;
1074 if (!argument.empty()) {
1075 last_search = argument;
1076 searched_string = argument;
1078 searched_string = last_search;
1080 bool fw = (action == LFUN_WORDFINDFORWARD);
1081 if (!searched_string.empty())
1082 lyx::find::find(view(), searched_string, fw);
1087 if (view()->available() && !view()->theLockingInset())
1089 owner->message(keyseq.printOptions());
1092 // --- Misc -------------------------------------------
1093 case LFUN_EXEC_COMMAND:
1094 owner->focus_command_buffer();
1099 meta_fake_bit = key_modifier::none;
1100 if (view()->available())
1101 // cancel any selection
1102 dispatch(FuncRequest(LFUN_MARK_OFF));
1103 setMessage(N_("Cancel"));
1106 case LFUN_META_FAKE:
1107 meta_fake_bit = key_modifier::alt;
1108 setMessage(keyseq.print());
1111 case LFUN_READ_ONLY_TOGGLE:
1112 if (owner->buffer()->lyxvc().inUse())
1113 owner->buffer()->lyxvc().toggleReadOnly();
1115 owner->buffer()->setReadonly(
1116 !owner->buffer()->isReadonly());
1119 case LFUN_CENTER: // this is center and redraw.
1123 // --- Menus -----------------------------------------------
1125 menuNew(argument, false);
1128 case LFUN_MENUNEWTMPLT:
1129 menuNew(argument, true);
1132 case LFUN_CLOSEBUFFER:
1136 case LFUN_MENUWRITE:
1137 if (!owner->buffer()->isUnnamed()) {
1138 string const str = bformat(_("Saving document %1$s..."),
1139 MakeDisplayPath(owner->buffer()->fileName()));
1140 owner->message(str);
1141 MenuWrite(owner->buffer());
1142 owner->message(str + _(" done."));
1144 WriteAs(owner->buffer());
1148 WriteAs(owner->buffer(), argument);
1151 case LFUN_MENURELOAD: {
1152 string const file = MakeDisplayPath(view()->buffer()->fileName(), 20);
1153 string text = bformat(_("Any changes will be lost. Are you sure "
1154 "you want to revert to the saved version of the document %1$s?"), file);
1155 int const ret = Alert::prompt(_("Revert to saved document?"),
1156 text, 0, 1, _("&Revert"), _("&Cancel"));
1164 Exporter::Export(owner->buffer(), argument, true);
1165 view()->showErrorList(BufferFormat(*owner->buffer()));
1169 Exporter::Preview(owner->buffer(), argument);
1170 view()->showErrorList(BufferFormat(*owner->buffer()));
1173 case LFUN_BUILDPROG:
1174 Exporter::Export(owner->buffer(), "program", true);
1175 view()->showErrorList(_("Build"));
1178 case LFUN_RUNCHKTEX:
1179 owner->buffer()->runChktex();
1180 view()->showErrorList(_("ChkTeX"));
1184 if (argument == "custom")
1185 owner->getDialogs().showSendto();
1187 Exporter::Export(owner->buffer(), argument, false);
1188 view()->showErrorList(BufferFormat(*owner->buffer()));
1202 InsetCommandParams p("tableofcontents");
1203 string const data = InsetCommandMailer::params2string("toc", p);
1204 owner->getDialogs().show("toc", data, 0);
1220 case LFUN_FREEFONT_APPLY:
1221 apply_freefont(view());
1224 case LFUN_FREEFONT_UPDATE:
1225 update_and_apply_freefont(view(), argument);
1228 case LFUN_RECONFIGURE:
1229 Reconfigure(view());
1233 case LFUN_FLOATSOPERATE:
1234 if (argument == "openfoot")
1235 view()->allFloats(1,0);
1236 else if (argument == "closefoot")
1237 view()->allFloats(0,0);
1238 else if (argument == "openfig")
1239 view()->allFloats(1,1);
1240 else if (argument == "closefig")
1241 view()->allFloats(0,1);
1244 #ifdef WITH_WARNINGS
1245 //#warning Find another implementation here (or another lyxfunc)!
1248 case LFUN_HELP_OPEN:
1250 string const arg = argument;
1252 setErrorMessage(N_("Missing argument"));
1255 string const fname = i18nLibFileSearch("doc", arg, "lyx");
1256 if (fname.empty()) {
1257 lyxerr << "LyX: unable to find documentation file `"
1258 << arg << "'. Bad installation?" << endl;
1261 owner->message(bformat(_("Opening help file %1$s..."),
1262 MakeDisplayPath(fname)));
1263 view()->loadLyXFile(fname, false);
1267 // --- version control -------------------------------
1268 case LFUN_VC_REGISTER:
1269 if (!ensureBufferClean(view()))
1271 if (!owner->buffer()->lyxvc().inUse()) {
1272 owner->buffer()->lyxvc().registrer();
1277 case LFUN_VC_CHECKIN:
1278 if (!ensureBufferClean(view()))
1280 if (owner->buffer()->lyxvc().inUse()
1281 && !owner->buffer()->isReadonly()) {
1282 owner->buffer()->lyxvc().checkIn();
1287 case LFUN_VC_CHECKOUT:
1288 if (!ensureBufferClean(view()))
1290 if (owner->buffer()->lyxvc().inUse()
1291 && owner->buffer()->isReadonly()) {
1292 owner->buffer()->lyxvc().checkOut();
1297 case LFUN_VC_REVERT:
1298 owner->buffer()->lyxvc().revert();
1303 owner->buffer()->lyxvc().undoLast();
1307 // --- buffers ----------------------------------------
1309 case LFUN_SWITCHBUFFER:
1310 view()->buffer(bufferlist.getBuffer(argument));
1314 NewFile(view(), argument);
1317 case LFUN_FILE_OPEN:
1321 case LFUN_LAYOUT_TABULAR: {
1322 UpdatableInset * tli = view()->theLockingInset();
1324 if (tli->lyxCode() == InsetOld::TABULAR_CODE) {
1325 static_cast<InsetTabular *>(tli)->openLayoutDialog(view());
1326 } else if (tli->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE)) {
1327 static_cast<InsetTabular *>(
1328 tli->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE))
1329 ->openLayoutDialog(view());
1335 case LFUN_DROP_LAYOUTS_CHOICE:
1336 owner->getToolbar().openLayoutList();
1339 case LFUN_MENU_OPEN_BY_NAME:
1340 owner->getMenubar().openByName(argument);
1341 break; // RVDK_PATCH_5
1343 // --- lyxserver commands ----------------------------
1347 setMessage(owner->buffer()->fileName());
1348 lyxerr[Debug::INFO] << "FNAME["
1349 << owner->buffer()->fileName()
1354 dispatch_buffer = keyseq.print();
1355 lyxserver->notifyClient(dispatch_buffer);
1358 case LFUN_GOTOFILEROW: {
1361 istringstream is(argument);
1362 is >> file_name >> row;
1363 if (prefixIs(file_name, getTmpDir())) {
1364 // Needed by inverse dvi search. If it is a file
1365 // in tmpdir, call the apropriated function
1366 view()->buffer(bufferlist.getBufferFromTmp(file_name));
1368 // Must replace extension of the file to be .lyx
1369 // and get full path
1370 string const s = ChangeExtension(file_name, ".lyx");
1371 // Either change buffer or load the file
1372 if (bufferlist.exists(s)) {
1373 view()->buffer(bufferlist.getBuffer(s));
1375 view()->loadLyXFile(s);
1379 view()->setCursorFromRow(row);
1382 // see BufferView_pimpl::center()
1383 view()->updateScrollbar();
1387 case LFUN_GOTO_PARAGRAPH: {
1388 istringstream is(argument);
1391 ParIterator par = owner->buffer()->getParFromID(id);
1392 if (par == owner->buffer()->par_iterator_end()) {
1393 lyxerr[Debug::INFO] << "No matching paragraph found! ["
1394 << id << ']' << endl;
1397 lyxerr[Debug::INFO] << "Paragraph " << par->id()
1398 << " found." << endl;
1401 if (view()->theLockingInset())
1402 view()->unlockInset(view()->theLockingInset());
1404 LyXText * lt = view()->getLyXText();
1405 if (par->inInset()) {
1406 FuncRequest cmd(view(), LFUN_INSET_EDIT, "left");
1407 par.inset()->dispatch(cmd);
1408 lt = par->inInset()->getLyXText(view());
1412 lt->setCursor(par.pit(), 0);
1413 view()->switchKeyMap();
1414 owner->view_state_changed();
1417 // see BufferView_pimpl::center()
1418 view()->updateScrollbar();
1422 // --- insert characters ----------------------------------------
1424 // --- Mathed stuff. If we are here, there is no locked inset yet.
1425 case LFUN_MATH_EXTERN:
1426 case LFUN_MATH_NUMBER:
1427 case LFUN_MATH_NONUMBER:
1428 case LFUN_MATH_LIMITS:
1429 setErrorMessage(N_("This is only allowed in math mode!"));
1432 // passthrough hat and underscore outside mathed:
1433 case LFUN_SUBSCRIPT:
1434 dispatch(FuncRequest(view(), LFUN_SELFINSERT, "_"));
1437 case LFUN_SUPERSCRIPT:
1438 dispatch(FuncRequest(view(), LFUN_SELFINSERT, "^"));
1441 case LFUN_DIALOG_SHOW: {
1442 string const name = func.getArg(0);
1443 string data = trim(func.argument.substr(name.size()));
1445 if (name == "character") {
1446 data = freefont2string();
1448 owner->getDialogs().show("character", data);
1449 } else if (name == "document")
1450 owner->getDialogs().showDocument();
1451 else if (name == "findreplace")
1452 owner->getDialogs().showSearch();
1453 else if (name == "forks")
1454 owner->getDialogs().showForks();
1455 else if (name == "preamble")
1456 owner->getDialogs().showPreamble();
1457 else if (name == "preferences")
1458 owner->getDialogs().showPreferences();
1459 else if (name == "print")
1460 owner->getDialogs().showPrint();
1461 else if (name == "spellchecker")
1462 owner->getDialogs().showSpellchecker();
1464 owner->getDialogs().show(name, data);
1468 case LFUN_DIALOG_SHOW_NEW_INSET: {
1469 string const & name = argument;
1471 if (name == "bibitem" ||
1473 name == "include" ||
1478 InsetCommandParams p(name);
1479 data = InsetCommandMailer::params2string(name, p);
1480 } else if (name == "citation") {
1481 InsetCommandParams p("cite");
1482 data = InsetCommandMailer::params2string(name, p);
1484 owner->getDialogs().show(name, data, 0);
1488 case LFUN_DIALOG_SHOW_NEXT_INSET:
1491 case LFUN_INSET_DIALOG_SHOW: {
1492 InsetOld * inset = view()->getLyXText()->getInset();
1494 inset->dispatch(FuncRequest(view(), LFUN_INSET_DIALOG_SHOW));
1498 case LFUN_DIALOG_UPDATE: {
1499 string const & name = argument;
1500 // Can only update a dialog connected to an existing inset
1501 InsetBase * inset = owner->getDialogs().getOpenInset(name);
1503 FuncRequest fr(view(), LFUN_INSET_DIALOG_UPDATE,
1505 inset->dispatch(fr);
1506 } else if (name == "paragraph") {
1507 dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
1512 case LFUN_DIALOG_HIDE:
1513 Dialogs::hide(argument, 0);
1516 case LFUN_DIALOG_DISCONNECT_INSET:
1517 owner->getDialogs().disconnect(argument);
1520 case LFUN_CHILDOPEN: {
1521 string const filename =
1522 MakeAbsPath(argument, owner->buffer()->filePath());
1523 setMessage(N_("Opening child document ") +
1524 MakeDisplayPath(filename) + "...");
1525 view()->savePosition(0);
1526 if (bufferlist.exists(filename))
1527 view()->buffer(bufferlist.getBuffer(filename));
1529 view()->loadLyXFile(filename);
1533 case LFUN_TOGGLECURSORFOLLOW:
1534 lyxrc.cursor_follows_scrollbar = !lyxrc.cursor_follows_scrollbar;
1538 owner->getIntl().KeyMapOn(false);
1541 case LFUN_KMAP_PRIM:
1542 owner->getIntl().KeyMapPrim();
1546 owner->getIntl().KeyMapSec();
1549 case LFUN_KMAP_TOGGLE:
1550 owner->getIntl().ToggleKeyMap();
1556 argument = split(argument, countstr, ' ');
1557 istringstream is(countstr);
1560 lyxerr << "repeat: count: " << count << " cmd: " << argument << endl;
1561 for (int i = 0; i < count; ++i)
1562 dispatch(lyxaction.lookupFunc(argument));
1567 // argument contains ';'-terminated commands
1568 while (!argument.empty()) {
1570 argument = split(argument, first, ';');
1571 dispatch(lyxaction.lookupFunc(first));
1575 case LFUN_SAVEPREFERENCES: {
1576 Path p(user_lyxdir());
1577 lyxrc.write("preferences");
1581 case LFUN_SCREEN_FONT_UPDATE:
1582 // handle the screen font changes.
1583 lyxrc.set_font_norm_type();
1584 lyx_gui::update_fonts();
1585 // All visible buffers will need resize
1590 case LFUN_SET_COLOR: {
1592 string const x11_name = split(argument, lyx_name, ' ');
1593 if (lyx_name.empty() || x11_name.empty()) {
1594 setErrorMessage(N_("Syntax: set-color <lyx_name>"
1599 bool const graphicsbg_changed =
1600 (lyx_name == lcolor.getLyXName(LColor::graphicsbg) &&
1601 x11_name != lcolor.getX11Name(LColor::graphicsbg));
1603 if (!lcolor.setColor(lyx_name, x11_name)) {
1605 bformat(_("Set-color \"%1$s\" failed "
1606 "- color is undefined or "
1607 "may not be redefined"), lyx_name));
1611 lyx_gui::update_color(lcolor.getFromLyXName(lyx_name));
1613 if (graphicsbg_changed) {
1614 #ifdef WITH_WARNINGS
1615 #warning FIXME!! The graphics cache no longer has a changeDisplay method.
1618 lyx::graphics::GCache::get().changeDisplay(true);
1627 owner->message(argument);
1630 case LFUN_FORKS_KILL:
1631 if (isStrInt(argument)) {
1632 pid_t const pid = strToInt(argument);
1633 ForkedcallsController & fcc = ForkedcallsController::get();
1638 case LFUN_TOOLTIPS_TOGGLE:
1639 owner->getDialogs().toggleTooltips();
1642 case LFUN_EXTERNAL_EDIT:
1643 InsetExternal().dispatch(FuncRequest(view(), action, argument));
1647 // Then if it was none of the above
1648 // Trying the BufferView::pimpl dispatch:
1649 if (!view()->dispatch(func))
1650 lyxerr << "A truly unknown func ["
1651 << lyxaction.getActionName(func.action) << "]!"
1658 view()->owner()->updateLayoutChoice();
1660 if (view()->available()) {
1661 if (view()->fitCursor()) {
1662 //lyxerr << "LyXFunc->fitCursor->update" << endl;
1666 // If we executed a mutating lfun, mark the buffer as dirty
1667 if (!getStatus(func).disabled()
1668 && !lyxaction.funcHasFlag(func.action, LyXAction::NoBuffer)
1669 && !lyxaction.funcHasFlag(func.action, LyXAction::ReadOnly))
1670 view()->buffer()->markDirty();
1673 sendDispatchMessage(getMessage(), func, verbose);
1677 void LyXFunc::sendDispatchMessage(string const & msg,
1678 FuncRequest const & func, bool verbose)
1680 owner->updateMenubar();
1681 owner->updateToolbar();
1683 if (func.action == LFUN_SELFINSERT || !verbose) {
1684 lyxerr[Debug::ACTION] << "dispatch msg is " << msg << endl;
1686 owner->message(msg);
1690 string dispatch_msg = msg;
1691 if (!dispatch_msg.empty())
1692 dispatch_msg += ' ';
1694 string comname = lyxaction.getActionName(func.action);
1696 bool argsadded = false;
1698 if (!func.argument.empty()) {
1699 if (func.action != LFUN_UNKNOWN_ACTION) {
1700 comname += ' ' + func.argument;
1705 string const shortcuts = toplevel_keymap->findbinding(func);
1707 if (!shortcuts.empty()) {
1708 comname += ": " + shortcuts;
1709 } else if (!argsadded && !func.argument.empty()) {
1710 comname += ' ' + func.argument;
1713 if (!comname.empty()) {
1714 comname = rtrim(comname);
1715 dispatch_msg += '(' + comname + ')';
1718 lyxerr[Debug::ACTION] << "verbose dispatch msg " << dispatch_msg << endl;
1719 if (!dispatch_msg.empty())
1720 owner->message(dispatch_msg);
1724 void LyXFunc::setupLocalKeymap()
1726 keyseq.stdmap = keyseq.curmap = toplevel_keymap.get();
1727 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap.get();
1731 void LyXFunc::menuNew(string const & name, bool fromTemplate)
1733 string initpath = lyxrc.document_path;
1734 string filename(name);
1736 if (view()->available()) {
1737 string const trypath = owner->buffer()->filePath();
1738 // If directory is writeable, use this as default.
1739 if (IsDirWriteable(trypath))
1743 static int newfile_number;
1745 if (filename.empty()) {
1746 filename = AddName(lyxrc.document_path,
1747 "newfile" + tostr(++newfile_number) + ".lyx");
1748 FileInfo fi(filename);
1749 while (bufferlist.exists(filename) || fi.readable()) {
1751 filename = AddName(lyxrc.document_path,
1752 "newfile" + tostr(newfile_number) +
1754 fi.newFile(filename);
1758 // The template stuff
1761 FileDialog fileDlg(_("Select template file"),
1762 LFUN_SELECT_FILE_SYNC,
1763 make_pair(string(_("Documents|#o#O")),
1764 string(lyxrc.document_path)),
1765 make_pair(string(_("Templates|#T#t")),
1766 string(lyxrc.template_path)));
1768 FileDialog::Result result =
1769 fileDlg.open(lyxrc.template_path,
1770 _("*.lyx| LyX Documents (*.lyx)"));
1772 if (result.first == FileDialog::Later)
1775 string const fname = result.second;
1782 view()->newFile(filename, templname, !name.empty());
1786 void LyXFunc::open(string const & fname)
1788 string initpath = lyxrc.document_path;
1790 if (view()->available()) {
1791 string const trypath = owner->buffer()->filePath();
1792 // If directory is writeable, use this as default.
1793 if (IsDirWriteable(trypath))
1799 if (fname.empty()) {
1800 FileDialog fileDlg(_("Select document to open"),
1802 make_pair(string(_("Documents|#o#O")),
1803 string(lyxrc.document_path)),
1804 make_pair(string(_("Examples|#E#e")),
1805 string(AddPath(system_lyxdir(), "examples"))));
1807 FileDialog::Result result =
1808 fileDlg.open(initpath,
1809 _("*.lyx| LyX Documents (*.lyx)"));
1811 if (result.first == FileDialog::Later)
1814 filename = result.second;
1816 // check selected filename
1817 if (filename.empty()) {
1818 owner->message(_("Canceled."));
1824 // get absolute path of file and add ".lyx" to the filename if
1826 string const fullpath = FileSearch(string(), filename, "lyx");
1827 if (!fullpath.empty()) {
1828 filename = fullpath;
1831 string const disp_fn(MakeDisplayPath(filename));
1833 // if the file doesn't exist, let the user create one
1834 FileInfo const f(filename, true);
1836 // the user specifically chose this name. Believe them.
1837 view()->newFile(filename, "", true);
1841 owner->message(bformat(_("Opening document %1$s..."), disp_fn));
1844 if (view()->loadLyXFile(filename)) {
1845 str2 = bformat(_("Document %1$s opened."), disp_fn);
1847 str2 = bformat(_("Could not open document %1$s"), disp_fn);
1849 owner->message(str2);
1853 void LyXFunc::doImport(string const & argument)
1856 string filename = split(argument, format, ' ');
1858 lyxerr[Debug::INFO] << "LyXFunc::doImport: " << format
1859 << " file: " << filename << endl;
1861 // need user interaction
1862 if (filename.empty()) {
1863 string initpath = lyxrc.document_path;
1865 if (view()->available()) {
1866 string const trypath = owner->buffer()->filePath();
1867 // If directory is writeable, use this as default.
1868 if (IsDirWriteable(trypath))
1872 string const text = bformat(_("Select %1$s file to import"),
1873 formats.prettyName(format));
1875 FileDialog fileDlg(text,
1877 make_pair(string(_("Documents|#o#O")),
1878 string(lyxrc.document_path)),
1879 make_pair(string(_("Examples|#E#e")),
1880 string(AddPath(system_lyxdir(), "examples"))));
1882 string const extension = "*." + formats.extension(format)
1883 + "| " + formats.prettyName(format)
1884 + " (*." + formats.extension(format) + ')';
1886 FileDialog::Result result = fileDlg.open(initpath,
1889 if (result.first == FileDialog::Later)
1892 filename = result.second;
1894 // check selected filename
1895 if (filename.empty())
1896 owner->message(_("Canceled."));
1899 if (filename.empty())
1902 // get absolute path of file
1903 filename = MakeAbsPath(filename);
1905 string const lyxfile = ChangeExtension(filename, ".lyx");
1907 // Check if the document already is open
1908 if (lyx_gui::use_gui && bufferlist.exists(lyxfile)) {
1909 if (!bufferlist.close(bufferlist.getBuffer(lyxfile), true)) {
1910 owner->message(_("Canceled."));
1915 // if the file exists already, and we didn't do
1916 // -i lyx thefile.lyx, warn
1917 if (FileInfo(lyxfile, true).exist() && filename != lyxfile) {
1918 string const file = MakeDisplayPath(lyxfile, 30);
1920 string text = bformat(_("The document %1$s already exists.\n\n"
1921 "Do you want to over-write that document?"), file);
1922 int const ret = Alert::prompt(_("Over-write document?"),
1923 text, 0, 1, _("&Over-write"), _("&Cancel"));
1926 owner->message(_("Canceled."));
1931 Importer::Import(owner, filename, format);
1935 void LyXFunc::closeBuffer()
1937 if (bufferlist.close(owner->buffer(), true) && !quitting) {
1938 if (bufferlist.empty()) {
1939 // need this otherwise SEGV may occur while
1940 // trying to set variables that don't exist
1941 // since there's no current buffer
1942 owner->getDialogs().hideBufferDependent();
1944 view()->buffer(bufferlist.first());
1950 // Each "owner" should have it's own message method. lyxview and
1951 // the minibuffer would use the minibuffer, but lyxserver would
1952 // send an ERROR signal to its client. Alejandro 970603
1953 // This func is bit problematic when it comes to NLS, to make the
1954 // lyx servers client be language indepenent we must not translate
1955 // strings sent to this func.
1956 void LyXFunc::setErrorMessage(string const & m) const
1958 dispatch_buffer = m;
1963 void LyXFunc::setMessage(string const & m) const
1965 dispatch_buffer = m;
1969 void LyXFunc::setStatusMessage(string const & m) const
1975 string const LyXFunc::view_status_message()
1977 // When meta-fake key is pressed, show the key sequence so far + "M-".
1979 return keyseq.print() + "M-";
1982 // Else, when a non-complete key sequence is pressed,
1983 // show the available options.
1984 if (keyseq.length() > 0 && !keyseq.deleted()) {
1985 return keyseq.printOptions();
1988 if (!view()->available())
1989 return _("Welcome to LyX!");
1991 return currentState(view());
1995 BufferView * LyXFunc::view() const
1997 BOOST_ASSERT(owner);
1998 return owner->view().get();
2002 bool LyXFunc::wasMetaKey() const
2004 return (meta_fake_bit != key_modifier::none);