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()->cursorPar()->inInset();
376 disable = inset && inset->forceDefaultParagraphs(inset);
380 case LFUN_INSET_OPTARG:
381 disable = (view()->getLyXText()->cursorPar()->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";
528 case InsetOld::BOX_CODE:
529 disable = ev.argument != "box";
537 case LFUN_MATH_MUTATE:
539 //flag.setOnOff(mathcursor->formula()->hullType() == ev.argument);
540 flag.setOnOff(false);
545 // we just need to be in math mode to enable that
547 case LFUN_MATH_SPACE:
548 case LFUN_MATH_LIMITS:
549 case LFUN_MATH_NONUMBER:
550 case LFUN_MATH_NUMBER:
551 case LFUN_MATH_EXTERN:
552 disable = !mathcursor;
555 case LFUN_DIALOG_SHOW: {
556 string const name = ev.getArg(0);
558 disable = !(name == "aboutlyx" ||
561 name == "preferences" ||
566 if (name == "print") {
567 disable = !Exporter::IsExportable(*buf, "dvi") ||
568 lyxrc.print_command == "none";
569 } else if (name == "character") {
570 UpdatableInset * tli = view()->theLockingInset();
571 disable = tli && tli->lyxCode() == InsetOld::ERT_CODE;
572 } else if (name == "vclog") {
573 disable = !buf->lyxvc().inUse();
574 } else if (name == "latexlog") {
575 disable = !IsFileReadable(buf->getLogName().second);
584 // the functions which insert insets
585 InsetOld::Code code = InsetOld::NO_CODE;
587 case LFUN_DIALOG_SHOW_NEW_INSET:
588 if (ev.argument == "bibitem")
589 code = InsetOld::BIBITEM_CODE;
590 else if (ev.argument == "bibtex")
591 code = InsetOld::BIBTEX_CODE;
592 else if (ev.argument == "citation")
593 code = InsetOld::CITE_CODE;
594 else if (ev.argument == "ert")
595 code = InsetOld::ERT_CODE;
596 else if (ev.argument == "external")
597 code = InsetOld::EXTERNAL_CODE;
598 else if (ev.argument == "float")
599 code = InsetOld::FLOAT_CODE;
600 else if (ev.argument == "graphics")
601 code = InsetOld::GRAPHICS_CODE;
602 else if (ev.argument == "include")
603 code = InsetOld::INCLUDE_CODE;
604 else if (ev.argument == "index")
605 code = InsetOld::INDEX_CODE;
606 else if (ev.argument == "label")
607 code = InsetOld::LABEL_CODE;
608 else if (ev.argument == "minipage")
609 code = InsetOld::MINIPAGE_CODE;
610 else if (ev.argument == "ref")
611 code = InsetOld::REF_CODE;
612 else if (ev.argument == "toc")
613 code = InsetOld::TOC_CODE;
614 else if (ev.argument == "url")
615 code = InsetOld::URL_CODE;
616 else if (ev.argument == "wrap")
617 code = InsetOld::WRAP_CODE;
621 code = InsetOld::ERT_CODE;
623 case LFUN_INSET_FOOTNOTE:
624 code = InsetOld::FOOT_CODE;
626 case LFUN_TABULAR_INSERT:
627 code = InsetOld::TABULAR_CODE;
629 case LFUN_INSET_MARGINAL:
630 code = InsetOld::MARGIN_CODE;
632 case LFUN_INSET_MINIPAGE:
633 code = InsetOld::MINIPAGE_CODE;
635 case LFUN_INSET_FLOAT:
636 case LFUN_INSET_WIDE_FLOAT:
637 code = InsetOld::FLOAT_CODE;
639 case LFUN_INSET_WRAP:
640 code = InsetOld::WRAP_CODE;
642 case LFUN_FLOAT_LIST:
643 code = InsetOld::FLOAT_LIST_CODE;
646 case LFUN_INSET_LIST:
647 code = InsetOld::LIST_CODE;
649 case LFUN_INSET_THEOREM:
650 code = InsetOld::THEOREM_CODE;
653 case LFUN_INSET_CAPTION:
654 code = InsetOld::CAPTION_CODE;
656 case LFUN_INSERT_NOTE:
657 code = InsetOld::NOTE_CODE;
659 case LFUN_INSERT_BOX:
660 code = InsetOld::BOX_CODE;
662 case LFUN_INSERT_BRANCH:
663 code = InsetOld::BRANCH_CODE;
664 if (buf->params().branchlist().empty())
667 case LFUN_INSERT_LABEL:
668 code = InsetOld::LABEL_CODE;
670 case LFUN_INSET_OPTARG:
671 code = InsetOld::OPTARG_CODE;
673 case LFUN_ENVIRONMENT_INSERT:
674 code = InsetOld::MINIPAGE_CODE;
676 case LFUN_INDEX_INSERT:
677 code = InsetOld::INDEX_CODE;
679 case LFUN_INDEX_PRINT:
680 code = InsetOld::INDEX_PRINT_CODE;
682 case LFUN_TOC_INSERT:
683 code = InsetOld::TOC_CODE;
687 code = InsetOld::URL_CODE;
690 // always allow this, since we will inset a raw quote
691 // if an inset is not allowed.
693 case LFUN_HYPHENATION:
694 case LFUN_LIGATURE_BREAK:
696 case LFUN_MENU_SEPARATOR:
698 case LFUN_END_OF_SENTENCE:
699 code = InsetOld::SPECIALCHAR_CODE;
701 case LFUN_SPACE_INSERT:
702 // slight hack: we know this is allowed in math mode
704 code = InsetOld::SPACE_CODE;
706 case LFUN_INSET_DIALOG_SHOW: {
707 LyXText * lt = view()->getLyXText();
708 InsetOld * inset = lt->getInset();
711 code = inset->lyxCode();
712 if (!(code == InsetOld::INCLUDE_CODE
713 || code == InsetOld::BIBTEX_CODE
714 || code == InsetOld::FLOAT_LIST_CODE
715 || code == InsetOld::TOC_CODE))
723 if (code != InsetOld::NO_CODE && tli && !tli->insetAllowed(code))
729 // A few general toggles
731 case LFUN_TOOLTIPS_TOGGLE:
732 flag.setOnOff(owner->getDialogs().tooltipsEnabled());
735 case LFUN_READ_ONLY_TOGGLE:
736 flag.setOnOff(buf->isReadonly());
739 flag.setOnOff(view()->getLyXText()->cursorPar()->params().startOfAppendix());
741 case LFUN_SWITCHBUFFER:
742 // toggle on the current buffer, but do not toggle off
743 // the other ones (is that a good idea?)
744 if (ev.argument == buf->fileName())
747 case LFUN_TRACK_CHANGES:
748 flag.setOnOff(buf->params().tracking_changes);
754 // the font related toggles
756 LyXFont const & font = view()->getLyXText()->real_current_font;
759 flag.setOnOff(font.emph() == LyXFont::ON);
762 flag.setOnOff(font.noun() == LyXFont::ON);
765 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
768 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
771 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
774 flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
780 string tc = mathcursor->getLastCode();
783 flag.setOnOff(tc == "mathbf");
786 flag.setOnOff(tc == "mathsf");
789 flag.setOnOff(tc == "mathcal");
792 flag.setOnOff(tc == "mathrm");
795 flag.setOnOff(tc == "mathtt");
798 flag.setOnOff(tc == "mathbb");
801 flag.setOnOff(tc == "mathnormal");
808 // this one is difficult to get right. As a half-baked
809 // solution, we consider only the first action of the sequence
810 if (ev.action == LFUN_SEQUENCE) {
811 // argument contains ';'-terminated commands
812 #warning LyXAction arguements not handled here.
813 flag = getStatus(FuncRequest(lyxaction.lookupFunc(token(ev.argument, ';', 0))));
820 void LyXFunc::dispatch(string const & s, bool verbose)
822 FuncRequest func = lyxaction.lookupFunc(s);
824 if (func.action == LFUN_UNKNOWN_ACTION) {
825 owner->message(bformat(_("Unknown function (%1$s)"), s));
829 dispatch(func, verbose);
834 bool ensureBufferClean(BufferView * bv) {
836 Buffer & buf = *bv->buffer();
840 string const file = MakeDisplayPath(buf.fileName(), 30);
841 string text = bformat(_("The document %1$s has unsaved "
842 "changes.\n\nDo you want to save "
843 "the document?"), file);
844 int const ret = Alert::prompt(_("Save changed document?"),
845 text, 0, 1, _("&Save"),
849 bv->owner()->dispatch(FuncRequest(LFUN_MENUWRITE));
851 return buf.isClean();
857 void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
859 string argument = func.argument;
860 kb_action action = func.action;
862 lyxerr[Debug::ACTION] << "LyXFunc::dispatch: action[" << action
863 <<"] arg[" << argument << ']' << endl;
865 // we have not done anything wrong yet.
867 dispatch_buffer.erase();
869 #ifdef NEW_DISPATCHER
870 // We try do call the most specific dispatcher first:
871 // 1. the lockinginset's dispatch
872 // 2. the bufferview's dispatch
873 // 3. the lyxview's dispatch
876 selection_possible = false;
878 // We cannot use this function here
879 if (getStatus(func).disabled()) {
880 lyxerr[Debug::ACTION] << "LyXFunc::dispatch: "
881 << lyxaction.getActionName(action)
882 << " [" << action << "] is disabled at this location"
884 setErrorMessage(getStatusMessage());
885 goto exit_with_message;
888 if (view()->available())
889 view()->hideCursor();
894 buildCursor(cursor, *view());
895 if (cursor.dispatch(FuncRequest(func, view())) == DISPATCHED) {
896 lyxerr << "dispatched by Cursor::dispatch()\n";
897 goto exit_with_message;
903 if (view()->available() && view()->theLockingInset()) {
904 InsetOld::RESULT result;
905 if (action > 1 || (action == LFUN_UNKNOWN_ACTION &&
908 UpdatableInset * inset = view()->theLockingInset();
912 inset->getCursorPos(view(), inset_x, dummy_y);
914 if (action == LFUN_UNKNOWN_ACTION
915 && argument.empty()) {
916 argument = encoded_last_key;
919 // the insets can't try to handle this,
920 // a table cell in the dummy position will
921 // lock its insettext, the insettext will
922 // pass it the bufferview, and succeed,
923 // so it will stay not locked. Not good
924 // if we've just done LFUN_ESCAPE (which
925 // injects an LFUN_PARAGRAPH_UPDATE)
926 if (action == LFUN_PARAGRAPH_UPDATE) {
927 view()->dispatch(func);
928 goto exit_with_message;
931 // Undo/Redo is a bit tricky for insets.
932 if (action == LFUN_UNDO) {
934 goto exit_with_message;
935 } else if (action == LFUN_REDO) {
937 goto exit_with_message;
938 } else if (((result=inset->
939 // Hand-over to inset's own dispatch:
940 localDispatch(FuncRequest(view(), action, argument))) ==
942 (result == DISPATCHED_NOUPDATE))
943 goto exit_with_message;
944 // If UNDISPATCHED, just soldier on
945 else if (result == FINISHED) {
946 owner->clearMessage();
947 goto exit_with_message;
948 // We do not need special RTL handling here:
949 // FINISHED means that the cursor should be
950 // one position after the inset.
951 } else if (result == FINISHED_RIGHT) {
952 view()->text->cursorRight(view());
954 owner->clearMessage();
955 goto exit_with_message;
956 } else if (result == FINISHED_UP) {
957 RowList::iterator const irow = view()->text->cursorIRow();
958 if (irow != view()->text->firstRow()) {
960 view()->text->setCursorFromCoordinates(
961 view()->text->cursor.x() + inset_x,
962 view()->text->cursor.y() -
963 irow->baseline() - 1);
964 view()->text->cursor.x_fix(view()->text->cursor.x());
966 view()->text->cursorUp(view());
972 owner->clearMessage();
973 goto exit_with_message;
974 } else if (result == FINISHED_DOWN) {
975 RowList::iterator const irow = view()->text->cursorIRow();
976 if (irow != view()->text->lastRow()) {
978 view()->text->setCursorFromCoordinates(
979 view()->text->cursor.x() + inset_x,
980 view()->text->cursor.y() -
983 view()->text->cursor.x_fix(view()->text->cursor.x());
985 view()->text->cursorDown(view());
988 view()->text->cursorRight(view());
991 owner->clearMessage();
992 goto exit_with_message;
994 #warning I am not sure this is still right, please have a look! (Jug 20020417)
995 else { // result == UNDISPATCHED
996 //setMessage(N_("Text mode"));
998 case LFUN_UNKNOWN_ACTION:
999 case LFUN_BREAKPARAGRAPH:
1000 case LFUN_BREAKLINE:
1001 view()->text->cursorRight(view());
1002 view()->switchKeyMap();
1003 owner->view_state_changed();
1006 if (!view()->text->cursorPar()->isRightToLeftPar(owner->buffer()->params())) {
1007 view()->text->cursorRight(view());
1009 owner->view_state_changed();
1011 goto exit_with_message;
1013 if (view()->text->cursorPar()->isRightToLeftPar(owner->buffer()->params())) {
1014 view()->text->cursorRight(view());
1016 owner->view_state_changed();
1018 goto exit_with_message;
1020 if (view()->text->cursorRow() != view()->text->lastRow())
1021 view()->text->cursorDown(view());
1023 view()->text->cursorRight(view());
1025 owner->view_state_changed();
1026 goto exit_with_message;
1037 if (!view()->available())
1039 // this function should be used always [asierra060396]
1040 UpdatableInset * tli = view()->theLockingInset();
1042 UpdatableInset * lock = tli->getLockingInset();
1045 view()->unlockInset(tli);
1046 view()->text->cursorRight(view());
1048 owner->view_state_changed();
1050 tli->unlockInsetInInset(view(), lock, true);
1053 // Tell the paragraph dialog that we changed paragraph
1054 dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
1059 case LFUN_WORDFINDFORWARD:
1060 case LFUN_WORDFINDBACKWARD: {
1061 static string last_search;
1062 string searched_string;
1064 if (!argument.empty()) {
1065 last_search = argument;
1066 searched_string = argument;
1068 searched_string = last_search;
1070 bool fw = (action == LFUN_WORDFINDFORWARD);
1071 if (!searched_string.empty())
1072 lyx::find::find(view(), searched_string, fw);
1077 if (view()->available() && !view()->theLockingInset())
1079 owner->message(keyseq.printOptions());
1082 // --- Misc -------------------------------------------
1083 case LFUN_EXEC_COMMAND:
1084 owner->focus_command_buffer();
1089 meta_fake_bit = key_modifier::none;
1090 if (view()->available())
1091 // cancel any selection
1092 dispatch(FuncRequest(LFUN_MARK_OFF));
1093 setMessage(N_("Cancel"));
1096 case LFUN_META_FAKE:
1097 meta_fake_bit = key_modifier::alt;
1098 setMessage(keyseq.print());
1101 case LFUN_READ_ONLY_TOGGLE:
1102 if (owner->buffer()->lyxvc().inUse())
1103 owner->buffer()->lyxvc().toggleReadOnly();
1105 owner->buffer()->setReadonly(
1106 !owner->buffer()->isReadonly());
1109 case LFUN_CENTER: // this is center and redraw.
1113 // --- Menus -----------------------------------------------
1115 menuNew(argument, false);
1118 case LFUN_MENUNEWTMPLT:
1119 menuNew(argument, true);
1122 case LFUN_CLOSEBUFFER:
1126 case LFUN_MENUWRITE:
1127 if (!owner->buffer()->isUnnamed()) {
1128 string const str = bformat(_("Saving document %1$s..."),
1129 MakeDisplayPath(owner->buffer()->fileName()));
1130 owner->message(str);
1131 MenuWrite(owner->buffer());
1132 owner->message(str + _(" done."));
1134 WriteAs(owner->buffer());
1138 WriteAs(owner->buffer(), argument);
1141 case LFUN_MENURELOAD: {
1142 string const file = MakeDisplayPath(view()->buffer()->fileName(), 20);
1143 string text = bformat(_("Any changes will be lost. Are you sure "
1144 "you want to revert to the saved version of the document %1$s?"), file);
1145 int const ret = Alert::prompt(_("Revert to saved document?"),
1146 text, 0, 1, _("&Revert"), _("&Cancel"));
1154 Exporter::Export(owner->buffer(), argument, true);
1155 view()->showErrorList(BufferFormat(*owner->buffer()));
1159 Exporter::Preview(owner->buffer(), argument);
1160 view()->showErrorList(BufferFormat(*owner->buffer()));
1163 case LFUN_BUILDPROG:
1164 Exporter::Export(owner->buffer(), "program", true);
1165 view()->showErrorList(_("Build"));
1168 case LFUN_RUNCHKTEX:
1169 owner->buffer()->runChktex();
1170 view()->showErrorList(_("ChkTeX"));
1174 if (argument == "custom")
1175 owner->getDialogs().showSendto();
1177 Exporter::Export(owner->buffer(), argument, false);
1178 view()->showErrorList(BufferFormat(*owner->buffer()));
1192 InsetCommandParams p("tableofcontents");
1193 string const data = InsetCommandMailer::params2string("toc", p);
1194 owner->getDialogs().show("toc", data, 0);
1210 case LFUN_FREEFONT_APPLY:
1211 apply_freefont(view());
1214 case LFUN_FREEFONT_UPDATE:
1215 update_and_apply_freefont(view(), argument);
1218 case LFUN_RECONFIGURE:
1219 Reconfigure(view());
1223 case LFUN_FLOATSOPERATE:
1224 if (argument == "openfoot")
1225 view()->allFloats(1,0);
1226 else if (argument == "closefoot")
1227 view()->allFloats(0,0);
1228 else if (argument == "openfig")
1229 view()->allFloats(1,1);
1230 else if (argument == "closefig")
1231 view()->allFloats(0,1);
1234 #ifdef WITH_WARNINGS
1235 //#warning Find another implementation here (or another lyxfunc)!
1238 case LFUN_HELP_OPEN:
1240 string const arg = argument;
1242 setErrorMessage(N_("Missing argument"));
1245 string const fname = i18nLibFileSearch("doc", arg, "lyx");
1246 if (fname.empty()) {
1247 lyxerr << "LyX: unable to find documentation file `"
1248 << arg << "'. Bad installation?" << endl;
1251 owner->message(bformat(_("Opening help file %1$s..."),
1252 MakeDisplayPath(fname)));
1253 view()->loadLyXFile(fname, false);
1257 // --- version control -------------------------------
1258 case LFUN_VC_REGISTER:
1260 if (!ensureBufferClean(view()))
1262 if (!owner->buffer()->lyxvc().inUse()) {
1263 owner->buffer()->lyxvc().registrer();
1269 case LFUN_VC_CHECKIN:
1271 if (!ensureBufferClean(view()))
1273 if (owner->buffer()->lyxvc().inUse()
1274 && !owner->buffer()->isReadonly()) {
1275 owner->buffer()->lyxvc().checkIn();
1281 case LFUN_VC_CHECKOUT:
1283 if (!ensureBufferClean(view()))
1285 if (owner->buffer()->lyxvc().inUse()
1286 && owner->buffer()->isReadonly()) {
1287 owner->buffer()->lyxvc().checkOut();
1293 case LFUN_VC_REVERT:
1295 owner->buffer()->lyxvc().revert();
1302 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 if (view()->theLockingInset()) {
1323 if (view()->theLockingInset()->lyxCode()== InsetOld::TABULAR_CODE) {
1324 InsetTabular * inset = static_cast<InsetTabular *>
1325 (view()->theLockingInset());
1326 inset->openLayoutDialog(view());
1327 } else if (view()->theLockingInset()->
1328 getFirstLockingInsetOfType(InsetOld::TABULAR_CODE)!=0) {
1329 InsetTabular * inset = static_cast<InsetTabular *>(
1330 view()->theLockingInset()->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE));
1331 inset->openLayoutDialog(view());
1336 case LFUN_DROP_LAYOUTS_CHOICE:
1337 owner->getToolbar().openLayoutList();
1340 case LFUN_MENU_OPEN_BY_NAME:
1341 owner->getMenubar().openByName(argument);
1342 break; // RVDK_PATCH_5
1344 // --- lyxserver commands ----------------------------
1348 setMessage(owner->buffer()->fileName());
1349 lyxerr[Debug::INFO] << "FNAME["
1350 << owner->buffer()->fileName()
1356 dispatch_buffer = keyseq.print();
1357 lyxserver->notifyClient(dispatch_buffer);
1361 case LFUN_GOTOFILEROW:
1365 istringstream istr(argument.c_str());
1366 istr >> file_name >> row;
1367 // Must replace extension of the file to be .lyx and get full path
1368 string const s(ChangeExtension(file_name, ".lyx"));
1370 // Either change buffer or load the file
1371 if (bufferlist.exists(s)) {
1372 view()->buffer(bufferlist.getBuffer(s));
1374 view()->loadLyXFile(s);
1377 view()->setCursorFromRow(row);
1380 // see BufferView_pimpl::center()
1381 view()->updateScrollbar();
1385 case LFUN_GOTO_PARAGRAPH:
1387 istringstream istr(argument.c_str());
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());
1403 if (par->inInset()) {
1404 FuncRequest cmd(view(), LFUN_INSET_EDIT, "left");
1405 par->inInset()->localDispatch(cmd);
1408 view()->getLyXText()->setCursor(par.pit(), 0);
1409 view()->switchKeyMap();
1410 owner->view_state_changed();
1413 // see BufferView_pimpl::center()
1414 view()->updateScrollbar();
1418 // --- insert characters ----------------------------------------
1420 // --- Mathed stuff. If we are here, there is no locked inset yet.
1421 case LFUN_MATH_EXTERN:
1422 case LFUN_MATH_NUMBER:
1423 case LFUN_MATH_NONUMBER:
1424 case LFUN_MATH_LIMITS:
1426 setErrorMessage(N_("This is only allowed in math mode!"));
1430 // passthrough hat and underscore outside mathed:
1431 case LFUN_SUBSCRIPT:
1432 dispatch(FuncRequest(view(), LFUN_SELFINSERT, "_"));
1434 case LFUN_SUPERSCRIPT:
1435 dispatch(FuncRequest(view(), LFUN_SELFINSERT, "^"));
1438 case LFUN_DIALOG_SHOW: {
1439 string const name = func.getArg(0);
1440 string data = trim(func.argument.substr(name.size()));
1442 if (name == "character") {
1443 data = freefont2string();
1445 owner->getDialogs().show("character", data);
1446 } else if (name == "document")
1447 owner->getDialogs().showDocument();
1448 else if (name == "findreplace")
1449 owner->getDialogs().showSearch();
1450 else if (name == "forks")
1451 owner->getDialogs().showForks();
1452 else if (name == "preamble")
1453 owner->getDialogs().showPreamble();
1454 else if (name == "preferences")
1455 owner->getDialogs().showPreferences();
1456 else if (name == "print")
1457 owner->getDialogs().showPrint();
1458 else if (name == "spellchecker")
1459 owner->getDialogs().showSpellchecker();
1461 owner->getDialogs().show(name, data);
1465 case LFUN_DIALOG_SHOW_NEW_INSET: {
1466 string const & name = argument;
1468 if (name == "bibitem" ||
1470 name == "include" ||
1475 InsetCommandParams p(name);
1476 data = InsetCommandMailer::params2string(name, p);
1477 } else if (name == "citation") {
1478 InsetCommandParams p("cite");
1479 data = InsetCommandMailer::params2string(name, p);
1481 owner->getDialogs().show(name, data, 0);
1485 case LFUN_DIALOG_SHOW_NEXT_INSET: {
1489 case LFUN_INSET_DIALOG_SHOW: {
1490 LyXText * lt = view()->getLyXText();
1491 InsetOld * inset = lt->getInset();
1493 FuncRequest cmd(view(), LFUN_INSET_DIALOG_SHOW);
1494 inset->localDispatch(cmd);
1499 case LFUN_DIALOG_UPDATE: {
1500 string const & name = argument;
1501 // Can only update a dialog connected to an existing inset
1502 InsetBase * inset = owner->getDialogs().getOpenInset(name);
1504 FuncRequest fr(view(), LFUN_INSET_DIALOG_UPDATE,
1506 inset->localDispatch(fr);
1507 } else if (name == "paragraph") {
1508 dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
1513 case LFUN_DIALOG_HIDE:
1514 Dialogs::hide(argument, 0);
1517 case LFUN_DIALOG_DISCONNECT_INSET:
1518 owner->getDialogs().disconnect(argument);
1521 case LFUN_CHILDOPEN:
1523 string const filename =
1524 MakeAbsPath(argument,
1525 owner->buffer()->filePath());
1526 setMessage(N_("Opening child document ") +
1527 MakeDisplayPath(filename) + "...");
1528 view()->savePosition(0);
1529 if (bufferlist.exists(filename))
1530 view()->buffer(bufferlist.getBuffer(filename));
1532 view()->loadLyXFile(filename);
1536 case LFUN_TOGGLECURSORFOLLOW:
1537 lyxrc.cursor_follows_scrollbar = !lyxrc.cursor_follows_scrollbar;
1541 owner->getIntl().KeyMapOn(false);
1544 case LFUN_KMAP_PRIM:
1545 owner->getIntl().KeyMapPrim();
1549 owner->getIntl().KeyMapSec();
1552 case LFUN_KMAP_TOGGLE:
1553 owner->getIntl().ToggleKeyMap();
1558 // argument contains ';'-terminated commands
1559 while (!argument.empty()) {
1561 argument = split(argument, first, ';');
1567 case LFUN_SAVEPREFERENCES:
1569 Path p(user_lyxdir());
1570 lyxrc.write("preferences");
1574 case LFUN_SCREEN_FONT_UPDATE:
1576 // handle the screen font changes.
1577 lyxrc.set_font_norm_type();
1578 lyx_gui::update_fonts();
1579 // We also need to empty the textcache so that
1580 // the buffer will be formatted correctly after
1583 // Of course we should only do the resize and the textcache.clear
1584 // if values really changed...but not very important right now. (Lgb)
1585 // All visible buffers will need resize
1591 case LFUN_SET_COLOR:
1594 string const x11_name = split(argument, lyx_name, ' ');
1595 if (lyx_name.empty() || x11_name.empty()) {
1596 setErrorMessage(N_("Syntax: set-color <lyx_name>"
1601 bool const graphicsbg_changed =
1602 (lyx_name == lcolor.getLyXName(LColor::graphicsbg) &&
1603 x11_name != lcolor.getX11Name(LColor::graphicsbg));
1605 if (!lcolor.setColor(lyx_name, x11_name)) {
1607 bformat(_("Set-color \"%1$s\" failed "
1608 "- color is undefined or "
1609 "may not be redefined"), lyx_name));
1613 lyx_gui::update_color(lcolor.getFromLyXName(lyx_name));
1615 if (graphicsbg_changed) {
1616 #ifdef WITH_WARNINGS
1617 #warning FIXME!! The graphics cache no longer has a changeDisplay method.
1620 lyx::graphics::GCache & gc =
1621 lyx::graphics::GCache::get();
1622 gc.changeDisplay(true);
1631 owner->message(argument);
1634 case LFUN_FORKS_KILL:
1636 if (!isStrInt(argument))
1639 pid_t const pid = strToInt(argument);
1640 ForkedcallsController & fcc = ForkedcallsController::get();
1645 case LFUN_TOOLTIPS_TOGGLE:
1646 owner->getDialogs().toggleTooltips();
1649 case LFUN_EXTERNAL_EDIT: {
1651 .localDispatch(FuncRequest(view(), action, argument));
1656 // Then if it was none of the above
1657 // Trying the BufferView::pimpl dispatch:
1658 if (!view()->dispatch(func))
1659 lyxerr << "A truly unknown func ["
1660 << lyxaction.getActionName(func.action) << "]!"
1667 view()->owner()->updateLayoutChoice();
1669 if (view()->available()) {
1670 if (view()->fitCursor()) {
1671 //lyxerr << "LyXFunc->fitCursor->update" << endl;
1675 // If we executed a mutating lfun, mark the buffer as dirty
1676 if (!getStatus(func).disabled()
1677 && !lyxaction.funcHasFlag(func.action, LyXAction::NoBuffer)
1678 && !lyxaction.funcHasFlag(func.action, LyXAction::ReadOnly))
1679 view()->buffer()->markDirty();
1682 sendDispatchMessage(getMessage(), func, verbose);
1686 void LyXFunc::sendDispatchMessage(string const & msg,
1687 FuncRequest const & func, bool verbose)
1689 owner->updateMenubar();
1690 owner->updateToolbar();
1692 if (func.action == LFUN_SELFINSERT || !verbose) {
1693 lyxerr[Debug::ACTION] << "dispatch msg is " << msg << endl;
1695 owner->message(msg);
1699 string dispatch_msg = msg;
1700 if (!dispatch_msg.empty())
1701 dispatch_msg += ' ';
1703 string comname = lyxaction.getActionName(func.action);
1705 bool argsadded = false;
1707 if (!func.argument.empty()) {
1708 if (func.action != LFUN_UNKNOWN_ACTION) {
1709 comname += ' ' + func.argument;
1714 string const shortcuts = toplevel_keymap->findbinding(func);
1716 if (!shortcuts.empty()) {
1717 comname += ": " + shortcuts;
1718 } else if (!argsadded && !func.argument.empty()) {
1719 comname += ' ' + func.argument;
1722 if (!comname.empty()) {
1723 comname = rtrim(comname);
1724 dispatch_msg += '(' + comname + ')';
1727 lyxerr[Debug::ACTION] << "verbose dispatch msg " << dispatch_msg << endl;
1728 if (!dispatch_msg.empty())
1729 owner->message(dispatch_msg);
1733 void LyXFunc::setupLocalKeymap()
1735 keyseq.stdmap = keyseq.curmap = toplevel_keymap.get();
1736 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap.get();
1740 void LyXFunc::menuNew(string const & name, bool fromTemplate)
1742 string initpath = lyxrc.document_path;
1743 string filename(name);
1745 if (view()->available()) {
1746 string const trypath = owner->buffer()->filePath();
1747 // If directory is writeable, use this as default.
1748 if (IsDirWriteable(trypath))
1752 static int newfile_number;
1754 if (filename.empty()) {
1755 filename = AddName(lyxrc.document_path,
1756 "newfile" + tostr(++newfile_number) + ".lyx");
1757 FileInfo fi(filename);
1758 while (bufferlist.exists(filename) || fi.readable()) {
1760 filename = AddName(lyxrc.document_path,
1761 "newfile" + tostr(newfile_number) +
1763 fi.newFile(filename);
1767 // The template stuff
1770 FileDialog fileDlg(_("Select template file"),
1771 LFUN_SELECT_FILE_SYNC,
1772 make_pair(string(_("Documents|#o#O")),
1773 string(lyxrc.document_path)),
1774 make_pair(string(_("Templates|#T#t")),
1775 string(lyxrc.template_path)));
1777 FileDialog::Result result =
1778 fileDlg.open(lyxrc.template_path,
1779 _("*.lyx| LyX Documents (*.lyx)"));
1781 if (result.first == FileDialog::Later)
1784 string const fname = result.second;
1791 view()->newFile(filename, templname, !name.empty());
1795 void LyXFunc::open(string const & fname)
1797 string initpath = lyxrc.document_path;
1799 if (view()->available()) {
1800 string const trypath = owner->buffer()->filePath();
1801 // If directory is writeable, use this as default.
1802 if (IsDirWriteable(trypath))
1808 if (fname.empty()) {
1809 FileDialog fileDlg(_("Select document to open"),
1811 make_pair(string(_("Documents|#o#O")),
1812 string(lyxrc.document_path)),
1813 make_pair(string(_("Examples|#E#e")),
1814 string(AddPath(system_lyxdir(), "examples"))));
1816 FileDialog::Result result =
1817 fileDlg.open(initpath,
1818 _("*.lyx| LyX Documents (*.lyx)"));
1820 if (result.first == FileDialog::Later)
1823 filename = result.second;
1825 // check selected filename
1826 if (filename.empty()) {
1827 owner->message(_("Canceled."));
1833 // get absolute path of file and add ".lyx" to the filename if
1835 string const fullpath = FileSearch(string(), filename, "lyx");
1836 if (!fullpath.empty()) {
1837 filename = fullpath;
1840 string const disp_fn(MakeDisplayPath(filename));
1842 // if the file doesn't exist, let the user create one
1843 FileInfo const f(filename, true);
1845 // the user specifically chose this name. Believe them.
1846 view()->newFile(filename, "", true);
1850 owner->message(bformat(_("Opening document %1$s..."), disp_fn));
1853 if (view()->loadLyXFile(filename)) {
1854 str2 = bformat(_("Document %1$s opened."), disp_fn);
1856 str2 = bformat(_("Could not open document %1$s"), disp_fn);
1858 owner->message(str2);
1862 void LyXFunc::doImport(string const & argument)
1865 string filename = split(argument, format, ' ');
1867 lyxerr[Debug::INFO] << "LyXFunc::doImport: " << format
1868 << " file: " << filename << endl;
1870 // need user interaction
1871 if (filename.empty()) {
1872 string initpath = lyxrc.document_path;
1874 if (view()->available()) {
1875 string const trypath = owner->buffer()->filePath();
1876 // If directory is writeable, use this as default.
1877 if (IsDirWriteable(trypath))
1881 string const text = bformat(_("Select %1$s file to import"),
1882 formats.prettyName(format));
1884 FileDialog fileDlg(text,
1886 make_pair(string(_("Documents|#o#O")),
1887 string(lyxrc.document_path)),
1888 make_pair(string(_("Examples|#E#e")),
1889 string(AddPath(system_lyxdir(), "examples"))));
1891 string const extension = "*." + formats.extension(format)
1892 + "| " + formats.prettyName(format)
1893 + " (*." + formats.extension(format) + ')';
1895 FileDialog::Result result = fileDlg.open(initpath,
1898 if (result.first == FileDialog::Later)
1901 filename = result.second;
1903 // check selected filename
1904 if (filename.empty())
1905 owner->message(_("Canceled."));
1908 if (filename.empty())
1911 // get absolute path of file
1912 filename = MakeAbsPath(filename);
1914 string const lyxfile = ChangeExtension(filename, ".lyx");
1916 // Check if the document already is open
1917 if (lyx_gui::use_gui && bufferlist.exists(lyxfile)) {
1918 if (!bufferlist.close(bufferlist.getBuffer(lyxfile), true)) {
1919 owner->message(_("Canceled."));
1924 // if the file exists already, and we didn't do
1925 // -i lyx thefile.lyx, warn
1926 if (FileInfo(lyxfile, true).exist() && filename != lyxfile) {
1927 string const file = MakeDisplayPath(lyxfile, 30);
1929 string text = bformat(_("The document %1$s already exists.\n\n"
1930 "Do you want to over-write that document?"), file);
1931 int const ret = Alert::prompt(_("Over-write document?"),
1932 text, 0, 1, _("&Over-write"), _("&Cancel"));
1935 owner->message(_("Canceled."));
1940 Importer::Import(owner, filename, format);
1944 void LyXFunc::closeBuffer()
1946 if (bufferlist.close(owner->buffer(), true) && !quitting) {
1947 if (bufferlist.empty()) {
1948 // need this otherwise SEGV may occur while
1949 // trying to set variables that don't exist
1950 // since there's no current buffer
1951 owner->getDialogs().hideBufferDependent();
1953 view()->buffer(bufferlist.first());
1959 // Each "owner" should have it's own message method. lyxview and
1960 // the minibuffer would use the minibuffer, but lyxserver would
1961 // send an ERROR signal to its client. Alejandro 970603
1962 // This func is bit problematic when it comes to NLS, to make the
1963 // lyx servers client be language indepenent we must not translate
1964 // strings sent to this func.
1965 void LyXFunc::setErrorMessage(string const & m) const
1967 dispatch_buffer = m;
1972 void LyXFunc::setMessage(string const & m) const
1974 dispatch_buffer = m;
1978 void LyXFunc::setStatusMessage(string const & m) const
1984 string const LyXFunc::view_status_message()
1986 // When meta-fake key is pressed, show the key sequence so far + "M-".
1988 return keyseq.print() + "M-";
1991 // Else, when a non-complete key sequence is pressed,
1992 // show the available options.
1993 if (keyseq.length() > 0 && !keyseq.deleted()) {
1994 return keyseq.printOptions();
1997 if (!view()->available())
1998 return _("Welcome to LyX!");
2000 return currentState(view());
2004 BufferView * LyXFunc::view() const
2006 BOOST_ASSERT(owner);
2007 return owner->view().get();
2011 bool LyXFunc::wasMetaKey() const
2013 return (meta_fake_bit != key_modifier::none);