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"
76 #include "support/std_sstream.h"
78 using bv_funcs::apply_freefont;
79 using bv_funcs::changeDepth;
80 using bv_funcs::currentState;
81 using bv_funcs::DEC_DEPTH;
82 using bv_funcs::freefont2string;
83 using bv_funcs::INC_DEPTH;
84 using bv_funcs::update_and_apply_freefont;
86 using lyx::support::AddName;
87 using lyx::support::AddPath;
88 using lyx::support::bformat;
89 using lyx::support::ChangeExtension;
90 using lyx::support::FileInfo;
91 using lyx::support::FileSearch;
92 using lyx::support::ForkedcallsController;
93 using lyx::support::i18nLibFileSearch;
94 using lyx::support::IsDirWriteable;
95 using lyx::support::IsFileReadable;
96 using lyx::support::isStrInt;
97 using lyx::support::MakeAbsPath;
98 using lyx::support::MakeDisplayPath;
99 using lyx::support::Path;
100 using lyx::support::rtrim;
101 using lyx::support::split;
102 using lyx::support::strToInt;
103 using lyx::support::strToUnsignedInt;
104 using lyx::support::system_lyxdir;
105 using lyx::support::token;
106 using lyx::support::trim;
107 using lyx::support::user_lyxdir;
110 using std::make_pair;
112 using std::istringstream;
115 extern BufferList bufferlist;
116 extern LyXServer * lyxserver;
117 extern bool selection_possible;
119 extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
122 extern tex_accent_struct get_accent(kb_action action);
124 extern void ShowLatexLog();
127 LyXFunc::LyXFunc(LyXView * o)
130 keyseq(toplevel_keymap.get(), toplevel_keymap.get()),
131 cancel_meta_seq(toplevel_keymap.get(), toplevel_keymap.get()),
132 meta_fake_bit(key_modifier::none)
137 void LyXFunc::moveCursorUpdate()
139 LyXText * lt = view()->text;
140 if (lt->selection.mark())
143 view()->switchKeyMap();
147 void LyXFunc::handleKeyFunc(kb_action action)
149 char c = encoded_last_key;
151 if (keyseq.length()) {
155 owner->getIntl().getTransManager()
156 .deadkey(c, get_accent(action).accent, view()->getLyXText());
157 // Need to clear, in case the minibuffer calls these
160 // copied verbatim from do_accent_char
162 view()->getLyXText()->selection.cursor = view()->getLyXText()->cursor;
166 void LyXFunc::processKeySym(LyXKeySymPtr keysym,
167 key_modifier::state state)
171 if (lyxerr.debugging(Debug::KEY)) {
172 lyxerr << "KeySym is "
173 << keysym->getSymbolName()
177 // Do nothing if we have nothing (JMarc)
178 if (!keysym->isOK()) {
179 lyxerr[Debug::KEY] << "Empty kbd action (probably composing)"
184 if (keysym->isModifier()) {
185 lyxerr[Debug::KEY] << "isModifier true" << endl;
189 Encoding const * encoding = view()->getEncoding();
191 encoded_last_key = keysym->getISOEncoded(encoding ? encoding->Name() : "");
193 // Do a one-deep top-level lookup for
194 // cancel and meta-fake keys. RVDK_PATCH_5
195 cancel_meta_seq.reset();
197 FuncRequest func = cancel_meta_seq.addkey(keysym, state);
198 lyxerr[Debug::KEY] << "action first set to [" << func.action << ']' << endl;
200 // When not cancel or meta-fake, do the normal lookup.
201 // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
202 // Mostly, meta_fake_bit = key_modifier::none. RVDK_PATCH_5.
203 if ((func.action != LFUN_CANCEL) && (func.action != LFUN_META_FAKE)) {
204 // remove Caps Lock and Mod2 as a modifiers
205 func = keyseq.addkey(keysym, (state | meta_fake_bit));
206 lyxerr[Debug::KEY] << "action now set to ["
207 << func.action << ']' << endl;
210 // Dont remove this unless you know what you are doing.
211 meta_fake_bit = key_modifier::none;
213 // can this happen now ?
214 if (func.action == LFUN_NOACTION) {
215 func = FuncRequest(LFUN_PREFIX);
218 if (lyxerr.debugging(Debug::KEY)) {
219 lyxerr << "Key [action="
220 << func.action << "]["
221 << keyseq.print() << ']'
225 // already here we know if it any point in going further
226 // why not return already here if action == -1 and
227 // num_bytes == 0? (Lgb)
229 if (keyseq.length() > 1) {
230 owner->message(keyseq.print());
234 // Maybe user can only reach the key via holding down shift.
235 // Let's see. But only if shift is the only modifier
236 if (func.action == LFUN_UNKNOWN_ACTION &&
237 state == key_modifier::shift) {
238 lyxerr[Debug::KEY] << "Trying without shift" << endl;
239 func = keyseq.addkey(keysym, key_modifier::none);
240 lyxerr[Debug::KEY] << "Action now " << func.action << endl;
243 if (func.action == LFUN_UNKNOWN_ACTION) {
244 // Hmm, we didn't match any of the keysequences. See
245 // if it's normal insertable text not already covered
247 if (keysym->isText() && keyseq.length() == 1) {
248 lyxerr[Debug::KEY] << "isText() is true, inserting." << endl;
249 func = FuncRequest(LFUN_SELFINSERT);
251 lyxerr[Debug::KEY] << "Unknown, !isText() - giving up" << endl;
252 owner->message(_("Unknown function."));
257 if (func.action == LFUN_SELFINSERT) {
258 if (encoded_last_key != 0) {
260 arg += encoded_last_key;
262 dispatch(FuncRequest(view(), LFUN_SELFINSERT, arg));
264 lyxerr[Debug::KEY] << "SelfInsert arg[`"
265 << argument << "']" << endl;
273 FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
276 Buffer * buf = owner->buffer();
278 if (ev.action == LFUN_NOACTION) {
279 setStatusMessage(N_("Nothing to do"));
280 return flag.disabled(true);
284 case LFUN_UNKNOWN_ACTION:
285 #ifndef HAVE_LIBAIKSAURUS
286 case LFUN_THESAURUS_ENTRY:
291 flag |= lyx_gui::getStatus(ev);
294 if (flag.unknown()) {
295 setStatusMessage(N_("Unknown action"));
299 // the default error message if we disable the command
300 setStatusMessage(N_("Command disabled"));
302 // Check whether we need a buffer
303 if (!lyxaction.funcHasFlag(ev.action, LyXAction::NoBuffer)) {
304 // Yes we need a buffer, do we have one?
307 // Can we use a readonly buffer?
308 if (buf->isReadonly() &&
309 !lyxaction.funcHasFlag(ev.action,
310 LyXAction::ReadOnly)) {
312 setStatusMessage(N_("Document is read-only"));
317 setStatusMessage(N_("Command not allowed with"
318 "out any document open"));
319 return flag.disabled(true);
323 UpdatableInset * tli = view()->theLockingInset();
325 // I would really like to avoid having this switch and rather try to
326 // encode this in the function itself.
327 bool disable = false;
330 disable = ev.argument != "custom"
331 && !Exporter::IsExportable(*buf, ev.argument);
334 disable = buf->undostack().empty();
337 disable = buf->redostack().empty();
342 UpdatableInset * in = tli;
343 if (in->lyxCode() != InsetOld::TABULAR_CODE) {
344 in = tli->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE);
346 if (in && static_cast<InsetTabular*>(in)->hasSelection()) {
351 disable = !mathcursor && !view()->getLyXText()->selection.set();
354 disable = !buf->isLatex() || lyxrc.chktex_command == "none";
357 disable = !Exporter::IsExportable(*buf, "program");
360 case LFUN_LAYOUT_TABULAR:
362 || (tli->lyxCode() != InsetOld::TABULAR_CODE
363 && !tli->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE));
367 disable = !changeDepth(view(), view()->getLyXText(), DEC_DEPTH, true);
370 case LFUN_DEPTH_PLUS:
371 disable = !changeDepth(view(), view()->getLyXText(), INC_DEPTH, true);
375 case LFUN_LAYOUT_PARAGRAPH: {
376 InsetOld * inset = view()->getLyXText()->cursor.par()->inInset();
377 disable = inset && inset->forceDefaultParagraphs(inset);
381 case LFUN_INSET_OPTARG:
382 disable = (view()->getLyXText()->cursor.par()->layout()->optionalargs == 0);
385 case LFUN_TABULAR_FEATURE:
388 // FIXME: check temporarily disabled
390 char align = mathcursor->valign();
395 if (ev.argument.empty()) {
399 if (!contains("tcb", ev.argument[0])) {
403 flag.setOnOff(ev.argument[0] == align);
407 char align = mathcursor->halign();
412 if (ev.argument.empty()) {
416 if (!contains("lcr", ev.argument[0])) {
420 flag.setOnOff(ev.argument[0] == align);
423 disable = !mathcursor->halign();
429 //ret.disabled(true);
430 if (tli->lyxCode() == InsetOld::TABULAR_CODE) {
431 ret = static_cast<InsetTabular *>(tli)
432 ->getStatus(ev.argument);
435 } else if (tli->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE)) {
436 ret = static_cast<InsetTabular *>
437 (tli->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE))
438 ->getStatus(ev.argument);
445 static InsetTabular inset(*owner->buffer(), 1, 1);
449 ret = inset.getStatus(ev.argument);
450 if (ret.onoff(true) || ret.onoff(false))
451 flag.setOnOff(false);
455 case LFUN_VC_REGISTER:
456 disable = buf->lyxvc().inUse();
458 case LFUN_VC_CHECKIN:
459 disable = !buf->lyxvc().inUse() || buf->isReadonly();
461 case LFUN_VC_CHECKOUT:
462 disable = !buf->lyxvc().inUse() || !buf->isReadonly();
466 disable = !buf->lyxvc().inUse();
468 case LFUN_MENURELOAD:
469 disable = buf->isUnnamed() || buf->isClean();
471 case LFUN_BOOKMARK_GOTO:
473 isSavedPosition(strToUnsignedInt(ev.argument));
475 case LFUN_MERGE_CHANGES:
476 case LFUN_ACCEPT_CHANGE:
477 case LFUN_REJECT_CHANGE:
478 case LFUN_ACCEPT_ALL_CHANGES:
479 case LFUN_REJECT_ALL_CHANGES:
480 disable = !buf->params().tracking_changes;
482 case LFUN_INSET_TOGGLE: {
483 LyXText * lt = view()->getLyXText();
484 disable = !(isEditableInset(lt->getInset())
486 && lt->inset_owner->owner()
487 && lt->inset_owner->owner()->isOpen()));
491 case LFUN_INSET_SETTINGS: {
493 UpdatableInset * inset = view()->theLockingInset();
498 // get the innermost inset
499 inset = inset->getLockingInset();
501 // jump back to owner if an InsetText, so
502 // we get back to the InsetTabular or whatever
503 if (inset->lyxCode() == InsetOld::TEXT_CODE)
504 inset = inset->owner();
506 InsetOld::Code code = inset->lyxCode();
508 case InsetOld::TABULAR_CODE:
509 disable = ev.argument != "tabular";
511 case InsetOld::ERT_CODE:
512 disable = ev.argument != "ert";
514 case InsetOld::FLOAT_CODE:
515 disable = ev.argument != "float";
517 case InsetOld::MINIPAGE_CODE:
518 disable = ev.argument != "minipage";
520 case InsetOld::WRAP_CODE:
521 disable = ev.argument != "wrap";
523 case InsetOld::NOTE_CODE:
524 disable = ev.argument != "note";
526 case InsetOld::BRANCH_CODE:
527 disable = ev.argument != "branch";
535 case LFUN_MATH_MUTATE:
537 //flag.setOnOff(mathcursor->formula()->hullType() == ev.argument);
538 flag.setOnOff(false);
543 // we just need to be in math mode to enable that
545 case LFUN_MATH_SPACE:
546 case LFUN_MATH_LIMITS:
547 case LFUN_MATH_NONUMBER:
548 case LFUN_MATH_NUMBER:
549 case LFUN_MATH_EXTERN:
550 disable = !mathcursor;
553 case LFUN_DIALOG_SHOW: {
554 string const name = ev.getArg(0);
556 disable = !(name == "aboutlyx" ||
559 name == "preferences" ||
564 if (name == "print") {
565 disable = !Exporter::IsExportable(*buf, "dvi") ||
566 lyxrc.print_command == "none";
567 } else if (name == "character") {
568 UpdatableInset * tli = view()->theLockingInset();
569 disable = tli && tli->lyxCode() == InsetOld::ERT_CODE;
570 } else if (name == "vclog") {
571 disable = !buf->lyxvc().inUse();
572 } else if (name == "latexlog") {
573 disable = !IsFileReadable(buf->getLogName().second);
582 // the functions which insert insets
583 InsetOld::Code code = InsetOld::NO_CODE;
585 case LFUN_DIALOG_SHOW_NEW_INSET:
586 if (ev.argument == "bibitem")
587 code = InsetOld::BIBITEM_CODE;
588 else if (ev.argument == "bibtex")
589 code = InsetOld::BIBTEX_CODE;
590 else if (ev.argument == "citation")
591 code = InsetOld::CITE_CODE;
592 else if (ev.argument == "ert")
593 code = InsetOld::ERT_CODE;
594 else if (ev.argument == "external")
595 code = InsetOld::EXTERNAL_CODE;
596 else if (ev.argument == "float")
597 code = InsetOld::FLOAT_CODE;
598 else if (ev.argument == "graphics")
599 code = InsetOld::GRAPHICS_CODE;
600 else if (ev.argument == "include")
601 code = InsetOld::INCLUDE_CODE;
602 else if (ev.argument == "index")
603 code = InsetOld::INDEX_CODE;
604 else if (ev.argument == "label")
605 code = InsetOld::LABEL_CODE;
606 else if (ev.argument == "minipage")
607 code = InsetOld::MINIPAGE_CODE;
608 else if (ev.argument == "ref")
609 code = InsetOld::REF_CODE;
610 else if (ev.argument == "toc")
611 code = InsetOld::TOC_CODE;
612 else if (ev.argument == "url")
613 code = InsetOld::URL_CODE;
614 else if (ev.argument == "wrap")
615 code = InsetOld::WRAP_CODE;
619 code = InsetOld::ERT_CODE;
621 case LFUN_INSET_FOOTNOTE:
622 code = InsetOld::FOOT_CODE;
624 case LFUN_TABULAR_INSERT:
625 code = InsetOld::TABULAR_CODE;
627 case LFUN_INSET_MARGINAL:
628 code = InsetOld::MARGIN_CODE;
630 case LFUN_INSET_MINIPAGE:
631 code = InsetOld::MINIPAGE_CODE;
633 case LFUN_INSET_FLOAT:
634 case LFUN_INSET_WIDE_FLOAT:
635 code = InsetOld::FLOAT_CODE;
637 case LFUN_INSET_WRAP:
638 code = InsetOld::WRAP_CODE;
640 case LFUN_FLOAT_LIST:
641 code = InsetOld::FLOAT_LIST_CODE;
644 case LFUN_INSET_LIST:
645 code = InsetOld::LIST_CODE;
647 case LFUN_INSET_THEOREM:
648 code = InsetOld::THEOREM_CODE;
651 case LFUN_INSET_CAPTION:
652 code = InsetOld::CAPTION_CODE;
654 case LFUN_INSERT_NOTE:
655 code = InsetOld::NOTE_CODE;
657 case LFUN_INSERT_BRANCH:
658 code = InsetOld::BRANCH_CODE;
659 if (buf->params().branchlist().empty())
662 case LFUN_INSERT_LABEL:
663 code = InsetOld::LABEL_CODE;
665 case LFUN_INSET_OPTARG:
666 code = InsetOld::OPTARG_CODE;
668 case LFUN_ENVIRONMENT_INSERT:
669 code = InsetOld::MINIPAGE_CODE;
671 case LFUN_INDEX_INSERT:
672 code = InsetOld::INDEX_CODE;
674 case LFUN_INDEX_PRINT:
675 code = InsetOld::INDEX_PRINT_CODE;
677 case LFUN_TOC_INSERT:
678 code = InsetOld::TOC_CODE;
682 code = InsetOld::URL_CODE;
685 // always allow this, since we will inset a raw quote
686 // if an inset is not allowed.
688 case LFUN_HYPHENATION:
689 case LFUN_LIGATURE_BREAK:
691 case LFUN_MENU_SEPARATOR:
693 case LFUN_END_OF_SENTENCE:
694 code = InsetOld::SPECIALCHAR_CODE;
696 case LFUN_SPACE_INSERT:
697 // slight hack: we know this is allowed in math mode
699 code = InsetOld::SPACE_CODE;
701 case LFUN_INSET_DIALOG_SHOW: {
702 LyXText * lt = view()->getLyXText();
703 InsetOld * inset = lt->getInset();
706 code = inset->lyxCode();
707 if (!(code == InsetOld::INCLUDE_CODE
708 || code == InsetOld::BIBTEX_CODE
709 || code == InsetOld::FLOAT_LIST_CODE
710 || code == InsetOld::TOC_CODE))
718 if (code != InsetOld::NO_CODE && tli && !tli->insetAllowed(code))
724 // A few general toggles
726 case LFUN_TOOLTIPS_TOGGLE:
727 flag.setOnOff(owner->getDialogs().tooltipsEnabled());
730 case LFUN_READ_ONLY_TOGGLE:
731 flag.setOnOff(buf->isReadonly());
734 flag.setOnOff(view()->getLyXText()->cursor.par()->params().startOfAppendix());
736 case LFUN_SWITCHBUFFER:
737 // toggle on the current buffer, but do not toggle off
738 // the other ones (is that a good idea?)
739 if (ev.argument == buf->fileName())
742 case LFUN_TRACK_CHANGES:
743 flag.setOnOff(buf->params().tracking_changes);
749 // the font related toggles
751 LyXFont const & font = view()->getLyXText()->real_current_font;
754 flag.setOnOff(font.emph() == LyXFont::ON);
757 flag.setOnOff(font.noun() == LyXFont::ON);
760 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
763 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
766 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
769 flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
775 string tc = mathcursor->getLastCode();
778 flag.setOnOff(tc == "mathbf");
781 flag.setOnOff(tc == "mathsf");
784 flag.setOnOff(tc == "mathcal");
787 flag.setOnOff(tc == "mathrm");
790 flag.setOnOff(tc == "mathtt");
793 flag.setOnOff(tc == "mathbb");
796 flag.setOnOff(tc == "mathnormal");
803 // this one is difficult to get right. As a half-baked
804 // solution, we consider only the first action of the sequence
805 if (ev.action == LFUN_SEQUENCE) {
806 // argument contains ';'-terminated commands
807 #warning LyXAction arguements not handled here.
808 flag = getStatus(FuncRequest(lyxaction.lookupFunc(token(ev.argument, ';', 0))));
815 void LyXFunc::dispatch(string const & s, bool verbose)
817 FuncRequest func = lyxaction.lookupFunc(s);
819 if (func.action == LFUN_UNKNOWN_ACTION) {
820 owner->message(bformat(_("Unknown function (%1$s)"), s));
824 dispatch(func, verbose);
829 bool ensureBufferClean(BufferView * bv) {
831 Buffer & buf = *bv->buffer();
835 string const file = MakeDisplayPath(buf.fileName(), 30);
836 string text = bformat(_("The document %1$s has unsaved "
837 "changes.\n\nDo you want to save "
838 "the document?"), file);
839 int const ret = Alert::prompt(_("Save changed document?"),
840 text, 0, 1, _("&Save"),
844 bv->owner()->dispatch(FuncRequest(LFUN_MENUWRITE));
846 return buf.isClean();
852 void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
854 string argument = func.argument;
855 kb_action action = func.action;
857 lyxerr[Debug::ACTION] << "LyXFunc::dispatch: action[" << action
858 <<"] arg[" << argument << ']' << endl;
860 // we have not done anything wrong yet.
862 dispatch_buffer.erase();
864 #ifdef NEW_DISPATCHER
865 // We try do call the most specific dispatcher first:
866 // 1. the lockinginset's dispatch
867 // 2. the bufferview's dispatch
868 // 3. the lyxview's dispatch
871 selection_possible = false;
873 // We cannot use this function here
874 if (getStatus(func).disabled()) {
875 lyxerr[Debug::ACTION] << "LyXFunc::dispatch: "
876 << lyxaction.getActionName(action)
877 << " [" << action << "] is disabled at this location"
879 setErrorMessage(getStatusMessage());
880 goto exit_with_message;
883 if (view()->available())
884 view()->hideCursor();
889 buildCursor(cursor, *view());
890 if (cursor.dispatch(FuncRequest(func, view())) == DISPATCHED) {
891 lyxerr << "dispatched by Cursor::dispatch()\n";
892 goto exit_with_message;
898 if (view()->available() && view()->theLockingInset()) {
899 InsetOld::RESULT result;
900 if (action > 1 || (action == LFUN_UNKNOWN_ACTION &&
903 UpdatableInset * inset = view()->theLockingInset();
907 inset->getCursorPos(view(), inset_x, dummy_y);
909 if ((action == LFUN_UNKNOWN_ACTION)
910 && argument.empty()) {
911 argument = encoded_last_key;
914 // the insets can't try to handle this,
915 // a table cell in the dummy position will
916 // lock its insettext, the insettext will
917 // pass it the bufferview, and succeed,
918 // so it will stay not locked. Not good
919 // if we've just done LFUN_ESCAPE (which
920 // injects an LFUN_PARAGRAPH_UPDATE)
921 if (action == LFUN_PARAGRAPH_UPDATE) {
922 view()->dispatch(func);
923 goto exit_with_message;
926 // Undo/Redo is a bit tricky for insets.
927 if (action == LFUN_UNDO) {
929 goto exit_with_message;
930 } else if (action == LFUN_REDO) {
932 goto exit_with_message;
933 } else if (((result=inset->
934 // Hand-over to inset's own dispatch:
935 localDispatch(FuncRequest(view(), action, argument))) ==
937 (result == DISPATCHED_NOUPDATE))
938 goto exit_with_message;
939 // If UNDISPATCHED, just soldier on
940 else if (result == FINISHED) {
941 owner->clearMessage();
942 goto exit_with_message;
943 // We do not need special RTL handling here:
944 // FINISHED means that the cursor should be
945 // one position after the inset.
946 } else if (result == FINISHED_RIGHT) {
947 view()->text->cursorRight(view());
949 owner->clearMessage();
950 goto exit_with_message;
951 } else if (result == FINISHED_UP) {
952 RowList::iterator const irow = view()->text->cursorIRow();
953 if (irow != view()->text->firstRow()) {
955 view()->text->setCursorFromCoordinates(
956 view()->text->cursor.x() + inset_x,
957 view()->text->cursor.y() -
958 irow->baseline() - 1);
959 view()->text->cursor.x_fix(view()->text->cursor.x());
961 view()->text->cursorUp(view());
967 owner->clearMessage();
968 goto exit_with_message;
969 } else if (result == FINISHED_DOWN) {
970 RowList::iterator const irow = view()->text->cursorIRow();
971 if (irow != view()->text->lastRow()) {
973 view()->text->setCursorFromCoordinates(
974 view()->text->cursor.x() + inset_x,
975 view()->text->cursor.y() -
978 view()->text->cursor.x_fix(view()->text->cursor.x());
980 view()->text->cursorDown(view());
983 view()->text->cursorRight(view());
986 owner->clearMessage();
987 goto exit_with_message;
989 #warning I am not sure this is still right, please have a look! (Jug 20020417)
990 else { // result == UNDISPATCHED
991 //setMessage(N_("Text mode"));
993 case LFUN_UNKNOWN_ACTION:
994 case LFUN_BREAKPARAGRAPH:
996 view()->text->cursorRight(view());
997 view()->switchKeyMap();
998 owner->view_state_changed();
1001 if (!view()->text->cursor.par()->isRightToLeftPar(owner->buffer()->params())) {
1002 view()->text->cursorRight(view());
1004 owner->view_state_changed();
1006 goto exit_with_message;
1008 if (view()->text->cursor.par()->isRightToLeftPar(owner->buffer()->params())) {
1009 view()->text->cursorRight(view());
1011 owner->view_state_changed();
1013 goto exit_with_message;
1015 if (view()->text->cursorRow() != view()->text->lastRow())
1016 view()->text->cursorDown(view());
1018 view()->text->cursorRight(view());
1020 owner->view_state_changed();
1021 goto exit_with_message;
1032 if (!view()->available())
1034 // this function should be used always [asierra060396]
1035 UpdatableInset * tli = view()->theLockingInset();
1037 UpdatableInset * lock = tli->getLockingInset();
1040 view()->unlockInset(tli);
1041 view()->text->cursorRight(view());
1043 owner->view_state_changed();
1045 tli->unlockInsetInInset(view(), lock, true);
1048 // Tell the paragraph dialog that we changed paragraph
1049 dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
1054 case LFUN_WORDFINDFORWARD:
1055 case LFUN_WORDFINDBACKWARD: {
1056 static string last_search;
1057 string searched_string;
1059 if (!argument.empty()) {
1060 last_search = argument;
1061 searched_string = argument;
1063 searched_string = last_search;
1065 bool fw = (action == LFUN_WORDFINDFORWARD);
1066 if (!searched_string.empty())
1067 lyx::find::find(view(), searched_string, fw);
1072 if (view()->available() && !view()->theLockingInset())
1074 owner->message(keyseq.printOptions());
1077 // --- Misc -------------------------------------------
1078 case LFUN_EXEC_COMMAND:
1079 owner->focus_command_buffer();
1084 meta_fake_bit = key_modifier::none;
1085 if (view()->available())
1086 // cancel any selection
1087 dispatch(FuncRequest(LFUN_MARK_OFF));
1088 setMessage(N_("Cancel"));
1091 case LFUN_META_FAKE:
1092 meta_fake_bit = key_modifier::alt;
1093 setMessage(keyseq.print());
1096 case LFUN_READ_ONLY_TOGGLE:
1097 if (owner->buffer()->lyxvc().inUse())
1098 owner->buffer()->lyxvc().toggleReadOnly();
1100 owner->buffer()->setReadonly(
1101 !owner->buffer()->isReadonly());
1104 case LFUN_CENTER: // this is center and redraw.
1108 // --- Menus -----------------------------------------------
1110 menuNew(argument, false);
1113 case LFUN_MENUNEWTMPLT:
1114 menuNew(argument, true);
1117 case LFUN_CLOSEBUFFER:
1121 case LFUN_MENUWRITE:
1122 if (!owner->buffer()->isUnnamed()) {
1123 string const str = bformat(_("Saving document %1$s..."),
1124 MakeDisplayPath(owner->buffer()->fileName()));
1125 owner->message(str);
1126 MenuWrite(owner->buffer());
1127 owner->message(str + _(" done."));
1129 WriteAs(owner->buffer());
1133 WriteAs(owner->buffer(), argument);
1136 case LFUN_MENURELOAD: {
1137 string const file = MakeDisplayPath(view()->buffer()->fileName(), 20);
1138 string text = bformat(_("Any changes will be lost. Are you sure "
1139 "you want to revert to the saved version of the document %1$s?"), file);
1140 int const ret = Alert::prompt(_("Revert to saved document?"),
1141 text, 0, 1, _("&Revert"), _("&Cancel"));
1149 Exporter::Export(owner->buffer(), argument, true);
1150 view()->showErrorList(BufferFormat(*owner->buffer()));
1154 Exporter::Preview(owner->buffer(), argument);
1155 view()->showErrorList(BufferFormat(*owner->buffer()));
1158 case LFUN_BUILDPROG:
1159 Exporter::Export(owner->buffer(), "program", true);
1160 view()->showErrorList(_("Build"));
1163 case LFUN_RUNCHKTEX:
1164 owner->buffer()->runChktex();
1165 view()->showErrorList(_("ChkTeX"));
1169 if (argument == "custom")
1170 owner->getDialogs().showSendto();
1172 Exporter::Export(owner->buffer(), argument, false);
1173 view()->showErrorList(BufferFormat(*owner->buffer()));
1187 InsetCommandParams p("tableofcontents");
1188 string const data = InsetCommandMailer::params2string("toc", p);
1189 owner->getDialogs().show("toc", data, 0);
1205 case LFUN_DEPTH_MIN:
1206 changeDepth(view(), view()->getLyXText(), DEC_DEPTH, false);
1207 owner->view_state_changed();
1210 case LFUN_DEPTH_PLUS:
1211 changeDepth(view(), view()->getLyXText(), INC_DEPTH, false);
1212 owner->view_state_changed();
1215 case LFUN_FREEFONT_APPLY:
1216 apply_freefont(view());
1219 case LFUN_FREEFONT_UPDATE:
1220 update_and_apply_freefont(view(), argument);
1223 case LFUN_RECONFIGURE:
1224 Reconfigure(view());
1228 case LFUN_FLOATSOPERATE:
1229 if (argument == "openfoot")
1230 view()->allFloats(1,0);
1231 else if (argument == "closefoot")
1232 view()->allFloats(0,0);
1233 else if (argument == "openfig")
1234 view()->allFloats(1,1);
1235 else if (argument == "closefig")
1236 view()->allFloats(0,1);
1239 #ifdef WITH_WARNINGS
1240 //#warning Find another implementation here (or another lyxfunc)!
1243 case LFUN_HELP_OPEN:
1245 string const arg = argument;
1247 setErrorMessage(N_("Missing argument"));
1250 string const fname = i18nLibFileSearch("doc", arg, "lyx");
1251 if (fname.empty()) {
1252 lyxerr << "LyX: unable to find documentation file `"
1253 << arg << "'. Bad installation?" << endl;
1256 owner->message(bformat(_("Opening help file %1$s..."),
1257 MakeDisplayPath(fname)));
1258 view()->loadLyXFile(fname, false);
1262 // --- version control -------------------------------
1263 case LFUN_VC_REGISTER:
1265 if (!ensureBufferClean(view()))
1267 if (!owner->buffer()->lyxvc().inUse()) {
1268 owner->buffer()->lyxvc().registrer();
1274 case LFUN_VC_CHECKIN:
1276 if (!ensureBufferClean(view()))
1278 if (owner->buffer()->lyxvc().inUse()
1279 && !owner->buffer()->isReadonly()) {
1280 owner->buffer()->lyxvc().checkIn();
1286 case LFUN_VC_CHECKOUT:
1288 if (!ensureBufferClean(view()))
1290 if (owner->buffer()->lyxvc().inUse()
1291 && owner->buffer()->isReadonly()) {
1292 owner->buffer()->lyxvc().checkOut();
1298 case LFUN_VC_REVERT:
1300 owner->buffer()->lyxvc().revert();
1307 owner->buffer()->lyxvc().undoLast();
1312 // --- buffers ----------------------------------------
1314 case LFUN_SWITCHBUFFER:
1315 view()->buffer(bufferlist.getBuffer(argument));
1319 NewFile(view(), argument);
1322 case LFUN_FILE_OPEN:
1326 case LFUN_LAYOUT_TABULAR:
1327 if (view()->theLockingInset()) {
1328 if (view()->theLockingInset()->lyxCode()== InsetOld::TABULAR_CODE) {
1329 InsetTabular * inset = static_cast<InsetTabular *>
1330 (view()->theLockingInset());
1331 inset->openLayoutDialog(view());
1332 } else if (view()->theLockingInset()->
1333 getFirstLockingInsetOfType(InsetOld::TABULAR_CODE)!=0) {
1334 InsetTabular * inset = static_cast<InsetTabular *>(
1335 view()->theLockingInset()->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE));
1336 inset->openLayoutDialog(view());
1341 case LFUN_DROP_LAYOUTS_CHOICE:
1342 owner->getToolbar().openLayoutList();
1345 case LFUN_MENU_OPEN_BY_NAME:
1346 owner->getMenubar().openByName(argument);
1347 break; // RVDK_PATCH_5
1349 // --- lyxserver commands ----------------------------
1353 setMessage(owner->buffer()->fileName());
1354 lyxerr[Debug::INFO] << "FNAME["
1355 << owner->buffer()->fileName()
1361 dispatch_buffer = keyseq.print();
1362 lyxserver->notifyClient(dispatch_buffer);
1366 case LFUN_GOTOFILEROW:
1370 istringstream istr(argument.c_str());
1371 istr >> file_name >> row;
1372 // Must replace extension of the file to be .lyx and get full path
1373 string const s(ChangeExtension(file_name, ".lyx"));
1375 // Either change buffer or load the file
1376 if (bufferlist.exists(s)) {
1377 view()->buffer(bufferlist.getBuffer(s));
1379 view()->loadLyXFile(s);
1382 view()->setCursorFromRow(row);
1385 // see BufferView_pimpl::center()
1386 view()->updateScrollbar();
1390 case LFUN_GOTO_PARAGRAPH:
1392 istringstream istr(argument.c_str());
1396 ParIterator par = owner->buffer()->getParFromID(id);
1397 if (par == owner->buffer()->par_iterator_end()) {
1398 lyxerr[Debug::INFO] << "No matching paragraph found! ["
1399 << id << ']' << endl;
1402 lyxerr[Debug::INFO] << "Paragraph " << par->id()
1403 << " found." << endl;
1406 if (view()->theLockingInset())
1407 view()->unlockInset(view()->theLockingInset());
1408 if (par->inInset()) {
1409 FuncRequest cmd(view(), LFUN_INSET_EDIT, "left");
1410 par->inInset()->localDispatch(cmd);
1413 view()->getLyXText()->setCursor(par.pit(), 0);
1414 view()->switchKeyMap();
1415 owner->view_state_changed();
1418 // see BufferView_pimpl::center()
1419 view()->updateScrollbar();
1423 // --- insert characters ----------------------------------------
1425 // --- Mathed stuff. If we are here, there is no locked inset yet.
1426 case LFUN_MATH_EXTERN:
1427 case LFUN_MATH_NUMBER:
1428 case LFUN_MATH_NONUMBER:
1429 case LFUN_MATH_LIMITS:
1431 setErrorMessage(N_("This is only allowed in math mode!"));
1435 // passthrough hat and underscore outside mathed:
1436 case LFUN_SUBSCRIPT:
1437 dispatch(FuncRequest(view(), LFUN_SELFINSERT, "_"));
1439 case LFUN_SUPERSCRIPT:
1440 dispatch(FuncRequest(view(), LFUN_SELFINSERT, "^"));
1443 case LFUN_DIALOG_SHOW: {
1444 string const name = func.getArg(0);
1445 string data = trim(func.argument.substr(name.size()));
1447 if (name == "character") {
1448 data = freefont2string();
1450 owner->getDialogs().show("character", data);
1451 } else if (name == "document")
1452 owner->getDialogs().showDocument();
1453 else if (name == "findreplace")
1454 owner->getDialogs().showSearch();
1455 else if (name == "forks")
1456 owner->getDialogs().showForks();
1457 else if (name == "preamble")
1458 owner->getDialogs().showPreamble();
1459 else if (name == "preferences")
1460 owner->getDialogs().showPreferences();
1461 else if (name == "print")
1462 owner->getDialogs().showPrint();
1463 else if (name == "spellchecker")
1464 owner->getDialogs().showSpellchecker();
1466 owner->getDialogs().show(name, data);
1470 case LFUN_DIALOG_SHOW_NEW_INSET: {
1471 string const & name = argument;
1473 if (name == "bibitem" ||
1475 name == "include" ||
1480 InsetCommandParams p(name);
1481 data = InsetCommandMailer::params2string(name, p);
1482 } else if (name == "citation") {
1483 InsetCommandParams p("cite");
1484 data = InsetCommandMailer::params2string(name, p);
1486 owner->getDialogs().show(name, data, 0);
1490 case LFUN_DIALOG_SHOW_NEXT_INSET: {
1494 case LFUN_INSET_DIALOG_SHOW: {
1495 LyXText * lt = view()->getLyXText();
1496 InsetOld * inset = lt->getInset();
1498 FuncRequest cmd(view(), LFUN_INSET_DIALOG_SHOW);
1499 inset->localDispatch(cmd);
1504 case LFUN_DIALOG_UPDATE: {
1505 string const & name = argument;
1506 // Can only update a dialog connected to an existing inset
1507 InsetBase * inset = owner->getDialogs().getOpenInset(name);
1509 FuncRequest fr(view(), LFUN_INSET_DIALOG_UPDATE,
1511 inset->localDispatch(fr);
1512 } else if (name == "paragraph") {
1513 dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
1518 case LFUN_DIALOG_HIDE:
1519 Dialogs::hide(argument, 0);
1522 case LFUN_DIALOG_DISCONNECT_INSET:
1523 owner->getDialogs().disconnect(argument);
1526 case LFUN_CHILDOPEN:
1528 string const filename =
1529 MakeAbsPath(argument,
1530 owner->buffer()->filePath());
1531 setMessage(N_("Opening child document ") +
1532 MakeDisplayPath(filename) + "...");
1533 view()->savePosition(0);
1534 if (bufferlist.exists(filename))
1535 view()->buffer(bufferlist.getBuffer(filename));
1537 view()->loadLyXFile(filename);
1541 case LFUN_TOGGLECURSORFOLLOW:
1542 lyxrc.cursor_follows_scrollbar = !lyxrc.cursor_follows_scrollbar;
1546 owner->getIntl().KeyMapOn(false);
1549 case LFUN_KMAP_PRIM:
1550 owner->getIntl().KeyMapPrim();
1554 owner->getIntl().KeyMapSec();
1557 case LFUN_KMAP_TOGGLE:
1558 owner->getIntl().ToggleKeyMap();
1563 // argument contains ';'-terminated commands
1564 while (!argument.empty()) {
1566 argument = split(argument, first, ';');
1572 case LFUN_SAVEPREFERENCES:
1574 Path p(user_lyxdir());
1575 lyxrc.write("preferences");
1579 case LFUN_SCREEN_FONT_UPDATE:
1581 // handle the screen font changes.
1582 lyxrc.set_font_norm_type();
1583 lyx_gui::update_fonts();
1584 // We also need to empty the textcache so that
1585 // the buffer will be formatted correctly after
1588 // Of course we should only do the resize and the textcache.clear
1589 // if values really changed...but not very important right now. (Lgb)
1590 // All visible buffers will need resize
1596 case LFUN_SET_COLOR:
1599 string const x11_name = split(argument, lyx_name, ' ');
1600 if (lyx_name.empty() || x11_name.empty()) {
1601 setErrorMessage(N_("Syntax: set-color <lyx_name>"
1606 bool const graphicsbg_changed =
1607 (lyx_name == lcolor.getLyXName(LColor::graphicsbg) &&
1608 x11_name != lcolor.getX11Name(LColor::graphicsbg));
1610 if (!lcolor.setColor(lyx_name, x11_name)) {
1612 bformat(_("Set-color \"%1$s\" failed "
1613 "- color is undefined or "
1614 "may not be redefined"), lyx_name));
1618 lyx_gui::update_color(lcolor.getFromLyXName(lyx_name));
1620 if (graphicsbg_changed) {
1621 #ifdef WITH_WARNINGS
1622 #warning FIXME!! The graphics cache no longer has a changeDisplay method.
1625 lyx::graphics::GCache & gc =
1626 lyx::graphics::GCache::get();
1627 gc.changeDisplay(true);
1636 owner->message(argument);
1639 case LFUN_FORKS_KILL:
1641 if (!isStrInt(argument))
1644 pid_t const pid = strToInt(argument);
1645 ForkedcallsController & fcc = ForkedcallsController::get();
1650 case LFUN_TOOLTIPS_TOGGLE:
1651 owner->getDialogs().toggleTooltips();
1654 case LFUN_EXTERNAL_EDIT: {
1656 .localDispatch(FuncRequest(view(), action, argument));
1661 // Then if it was none of the above
1662 // Trying the BufferView::pimpl dispatch:
1663 if (!view()->dispatch(func))
1664 lyxerr << "A truly unknown func ["
1665 << lyxaction.getActionName(func.action) << "]!"
1672 view()->owner()->updateLayoutChoice();
1674 if (view()->available()) {
1675 if (view()->fitCursor()) {
1676 //lyxerr << "LyXFunc->fitCursor->update" << endl;
1680 // If we executed a mutating lfun, mark the buffer as dirty
1681 if (!getStatus(func).disabled()
1682 && !lyxaction.funcHasFlag(func.action, LyXAction::NoBuffer)
1683 && !lyxaction.funcHasFlag(func.action, LyXAction::ReadOnly))
1684 view()->buffer()->markDirty();
1687 sendDispatchMessage(getMessage(), func, verbose);
1691 void LyXFunc::sendDispatchMessage(string const & msg,
1692 FuncRequest const & func, bool verbose)
1694 owner->updateMenubar();
1695 owner->updateToolbar();
1697 if (func.action == LFUN_SELFINSERT || !verbose) {
1698 lyxerr[Debug::ACTION] << "dispatch msg is " << msg << endl;
1700 owner->message(msg);
1704 string dispatch_msg = msg;
1705 if (!dispatch_msg.empty())
1706 dispatch_msg += ' ';
1708 string comname = lyxaction.getActionName(func.action);
1710 bool argsadded = false;
1712 if (!func.argument.empty()) {
1713 if (func.action != LFUN_UNKNOWN_ACTION) {
1714 comname += ' ' + func.argument;
1719 string const shortcuts = toplevel_keymap->findbinding(func);
1721 if (!shortcuts.empty()) {
1722 comname += ": " + shortcuts;
1723 } else if (!argsadded && !func.argument.empty()) {
1724 comname += ' ' + func.argument;
1727 if (!comname.empty()) {
1728 comname = rtrim(comname);
1729 dispatch_msg += '(' + comname + ')';
1732 lyxerr[Debug::ACTION] << "verbose dispatch msg " << dispatch_msg << endl;
1733 if (!dispatch_msg.empty())
1734 owner->message(dispatch_msg);
1738 void LyXFunc::setupLocalKeymap()
1740 keyseq.stdmap = keyseq.curmap = toplevel_keymap.get();
1741 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap.get();
1745 void LyXFunc::menuNew(string const & name, bool fromTemplate)
1747 string initpath = lyxrc.document_path;
1748 string filename(name);
1750 if (view()->available()) {
1751 string const trypath = owner->buffer()->filePath();
1752 // If directory is writeable, use this as default.
1753 if (IsDirWriteable(trypath))
1757 static int newfile_number;
1759 if (filename.empty()) {
1760 filename = AddName(lyxrc.document_path,
1761 "newfile" + tostr(++newfile_number) + ".lyx");
1762 FileInfo fi(filename);
1763 while (bufferlist.exists(filename) || fi.readable()) {
1765 filename = AddName(lyxrc.document_path,
1766 "newfile" + tostr(newfile_number) +
1768 fi.newFile(filename);
1772 // The template stuff
1775 FileDialog fileDlg(_("Select template file"),
1776 LFUN_SELECT_FILE_SYNC,
1777 make_pair(string(_("Documents|#o#O")),
1778 string(lyxrc.document_path)),
1779 make_pair(string(_("Templates|#T#t")),
1780 string(lyxrc.template_path)));
1782 FileDialog::Result result =
1783 fileDlg.open(lyxrc.template_path,
1784 _("*.lyx| LyX Documents (*.lyx)"));
1786 if (result.first == FileDialog::Later)
1789 string const fname = result.second;
1796 view()->newFile(filename, templname, !name.empty());
1800 void LyXFunc::open(string const & fname)
1802 string initpath = lyxrc.document_path;
1804 if (view()->available()) {
1805 string const trypath = owner->buffer()->filePath();
1806 // If directory is writeable, use this as default.
1807 if (IsDirWriteable(trypath))
1813 if (fname.empty()) {
1814 FileDialog fileDlg(_("Select document to open"),
1816 make_pair(string(_("Documents|#o#O")),
1817 string(lyxrc.document_path)),
1818 make_pair(string(_("Examples|#E#e")),
1819 string(AddPath(system_lyxdir(), "examples"))));
1821 FileDialog::Result result =
1822 fileDlg.open(initpath,
1823 _("*.lyx| LyX Documents (*.lyx)"));
1825 if (result.first == FileDialog::Later)
1828 filename = result.second;
1830 // check selected filename
1831 if (filename.empty()) {
1832 owner->message(_("Canceled."));
1838 // get absolute path of file and add ".lyx" to the filename if
1840 string const fullpath = FileSearch(string(), filename, "lyx");
1841 if (!fullpath.empty()) {
1842 filename = fullpath;
1845 string const disp_fn(MakeDisplayPath(filename));
1847 // if the file doesn't exist, let the user create one
1848 FileInfo const f(filename, true);
1850 // the user specifically chose this name. Believe them.
1851 view()->newFile(filename, "", true);
1855 owner->message(bformat(_("Opening document %1$s..."), disp_fn));
1858 if (view()->loadLyXFile(filename)) {
1859 str2 = bformat(_("Document %1$s opened."), disp_fn);
1861 str2 = bformat(_("Could not open document %1$s"), disp_fn);
1863 owner->message(str2);
1867 void LyXFunc::doImport(string const & argument)
1870 string filename = split(argument, format, ' ');
1872 lyxerr[Debug::INFO] << "LyXFunc::doImport: " << format
1873 << " file: " << filename << endl;
1875 // need user interaction
1876 if (filename.empty()) {
1877 string initpath = lyxrc.document_path;
1879 if (view()->available()) {
1880 string const trypath = owner->buffer()->filePath();
1881 // If directory is writeable, use this as default.
1882 if (IsDirWriteable(trypath))
1886 string const text = bformat(_("Select %1$s file to import"),
1887 formats.prettyName(format));
1889 FileDialog fileDlg(text,
1891 make_pair(string(_("Documents|#o#O")),
1892 string(lyxrc.document_path)),
1893 make_pair(string(_("Examples|#E#e")),
1894 string(AddPath(system_lyxdir(), "examples"))));
1896 string const extension = "*." + formats.extension(format)
1897 + "| " + formats.prettyName(format)
1898 + " (*." + formats.extension(format) + ')';
1900 FileDialog::Result result = fileDlg.open(initpath,
1903 if (result.first == FileDialog::Later)
1906 filename = result.second;
1908 // check selected filename
1909 if (filename.empty())
1910 owner->message(_("Canceled."));
1913 if (filename.empty())
1916 // get absolute path of file
1917 filename = MakeAbsPath(filename);
1919 string const lyxfile = ChangeExtension(filename, ".lyx");
1921 // Check if the document already is open
1922 if (lyx_gui::use_gui && bufferlist.exists(lyxfile)) {
1923 if (!bufferlist.close(bufferlist.getBuffer(lyxfile), true)) {
1924 owner->message(_("Canceled."));
1929 // if the file exists already, and we didn't do
1930 // -i lyx thefile.lyx, warn
1931 if (FileInfo(lyxfile, true).exist() && filename != lyxfile) {
1932 string const file = MakeDisplayPath(lyxfile, 30);
1934 string text = bformat(_("The document %1$s already exists.\n\n"
1935 "Do you want to over-write that document?"), file);
1936 int const ret = Alert::prompt(_("Over-write document?"),
1937 text, 0, 1, _("&Over-write"), _("&Cancel"));
1940 owner->message(_("Canceled."));
1945 Importer::Import(owner, filename, format);
1949 void LyXFunc::closeBuffer()
1951 if (bufferlist.close(owner->buffer(), true) && !quitting) {
1952 if (bufferlist.empty()) {
1953 // need this otherwise SEGV may occur while
1954 // trying to set variables that don't exist
1955 // since there's no current buffer
1956 owner->getDialogs().hideBufferDependent();
1958 view()->buffer(bufferlist.first());
1964 // Each "owner" should have it's own message method. lyxview and
1965 // the minibuffer would use the minibuffer, but lyxserver would
1966 // send an ERROR signal to its client. Alejandro 970603
1967 // This func is bit problematic when it comes to NLS, to make the
1968 // lyx servers client be language indepenent we must not translate
1969 // strings sent to this func.
1970 void LyXFunc::setErrorMessage(string const & m) const
1972 dispatch_buffer = m;
1977 void LyXFunc::setMessage(string const & m) const
1979 dispatch_buffer = m;
1983 void LyXFunc::setStatusMessage(string const & m) const
1989 string const LyXFunc::view_status_message()
1991 // When meta-fake key is pressed, show the key sequence so far + "M-".
1993 return keyseq.print() + "M-";
1996 // Else, when a non-complete key sequence is pressed,
1997 // show the available options.
1998 if (keyseq.length() > 0 && !keyseq.deleted()) {
1999 return keyseq.printOptions();
2002 if (!view()->available())
2003 return _("Welcome to LyX!");
2005 return currentState(view());
2009 BufferView * LyXFunc::view() const
2011 BOOST_ASSERT(owner);
2012 return owner->view().get();
2016 bool LyXFunc::wasMetaKey() const
2018 return (meta_fake_bit != key_modifier::none);