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 int action = cancel_meta_seq.addkey(keysym, state);
198 lyxerr[Debug::KEY] << "action first set to [" << 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 ((action != LFUN_CANCEL) && (action != LFUN_META_FAKE)) {
204 // remove Caps Lock and Mod2 as a modifiers
205 action = keyseq.addkey(keysym, (state | meta_fake_bit));
206 lyxerr[Debug::KEY] << "action now set to ["
207 << 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 (action == LFUN_NOACTION) {
215 action = LFUN_PREFIX;
218 if (lyxerr.debugging(Debug::KEY)) {
219 lyxerr << "Key [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 (action == LFUN_UNKNOWN_ACTION && state == key_modifier::shift) {
237 lyxerr[Debug::KEY] << "Trying without shift" << endl;
238 action = keyseq.addkey(keysym, key_modifier::none);
239 lyxerr[Debug::KEY] << "Action now " << action << endl;
242 if (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 action = LFUN_SELFINSERT;
250 lyxerr[Debug::KEY] << "Unknown, !isText() - giving up" << endl;
251 owner->message(_("Unknown function."));
256 if (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;
267 dispatch(FuncRequest(kb_action(action)));
272 FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
275 Buffer * buf = owner->buffer();
277 if (ev.action == LFUN_NOACTION) {
278 setStatusMessage(N_("Nothing to do"));
279 return flag.disabled(true);
283 case LFUN_UNKNOWN_ACTION:
284 #ifndef HAVE_LIBAIKSAURUS
285 case LFUN_THESAURUS_ENTRY:
290 flag |= lyx_gui::getStatus(ev);
293 if (flag.unknown()) {
294 setStatusMessage(N_("Unknown action"));
298 // the default error message if we disable the command
299 setStatusMessage(N_("Command disabled"));
301 // Check whether we need a buffer
302 if (!lyxaction.funcHasFlag(ev.action, LyXAction::NoBuffer)) {
303 // Yes we need a buffer, do we have one?
306 // Can we use a readonly buffer?
307 if (buf->isReadonly() &&
308 !lyxaction.funcHasFlag(ev.action,
309 LyXAction::ReadOnly)) {
311 setStatusMessage(N_("Document is read-only"));
316 setStatusMessage(N_("Command not allowed with"
317 "out any document open"));
318 return flag.disabled(true);
322 UpdatableInset * tli = view()->theLockingInset();
324 // I would really like to avoid having this switch and rather try to
325 // encode this in the function itself.
326 bool disable = false;
329 disable = ev.argument != "custom"
330 && !Exporter::IsExportable(*buf, ev.argument);
333 disable = buf->undostack().empty();
336 disable = buf->redostack().empty();
341 UpdatableInset * in = tli;
342 if (in->lyxCode() != InsetOld::TABULAR_CODE) {
343 in = tli->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE);
345 if (in && static_cast<InsetTabular*>(in)->hasSelection()) {
350 disable = !mathcursor && !view()->getLyXText()->selection.set();
353 disable = !buf->isLatex() || lyxrc.chktex_command == "none";
356 disable = !Exporter::IsExportable(*buf, "program");
359 case LFUN_LAYOUT_TABULAR:
361 || (tli->lyxCode() != InsetOld::TABULAR_CODE
362 && !tli->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE));
366 disable = !changeDepth(view(), view()->getLyXText(), DEC_DEPTH, true);
369 case LFUN_DEPTH_PLUS:
370 disable = !changeDepth(view(), view()->getLyXText(), INC_DEPTH, true);
374 case LFUN_LAYOUT_PARAGRAPH: {
375 InsetOld * inset = view()->getLyXText()->cursor.par()->inInset();
376 disable = inset && inset->forceDefaultParagraphs(inset);
380 case LFUN_INSET_OPTARG:
381 disable = (view()->getLyXText()->cursor.par()->layout()->optionalargs == 0);
384 case LFUN_TABULAR_FEATURE:
387 // FIXME: check temporarily disabled
389 char align = mathcursor->valign();
394 if (ev.argument.empty()) {
398 if (!contains("tcb", ev.argument[0])) {
402 flag.setOnOff(ev.argument[0] == align);
406 char align = mathcursor->halign();
411 if (ev.argument.empty()) {
415 if (!contains("lcr", ev.argument[0])) {
419 flag.setOnOff(ev.argument[0] == align);
422 disable = !mathcursor->halign();
428 //ret.disabled(true);
429 if (tli->lyxCode() == InsetOld::TABULAR_CODE) {
430 ret = static_cast<InsetTabular *>(tli)
431 ->getStatus(ev.argument);
434 } else if (tli->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE)) {
435 ret = static_cast<InsetTabular *>
436 (tli->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE))
437 ->getStatus(ev.argument);
444 static InsetTabular inset(*owner->buffer(), 1, 1);
448 ret = inset.getStatus(ev.argument);
449 if (ret.onoff(true) || ret.onoff(false))
450 flag.setOnOff(false);
454 case LFUN_VC_REGISTER:
455 disable = buf->lyxvc().inUse();
457 case LFUN_VC_CHECKIN:
458 disable = !buf->lyxvc().inUse() || buf->isReadonly();
460 case LFUN_VC_CHECKOUT:
461 disable = !buf->lyxvc().inUse() || !buf->isReadonly();
465 disable = !buf->lyxvc().inUse();
467 case LFUN_MENURELOAD:
468 disable = buf->isUnnamed() || buf->isClean();
470 case LFUN_BOOKMARK_GOTO:
472 isSavedPosition(strToUnsignedInt(ev.argument));
474 case LFUN_MERGE_CHANGES:
475 case LFUN_ACCEPT_CHANGE:
476 case LFUN_REJECT_CHANGE:
477 case LFUN_ACCEPT_ALL_CHANGES:
478 case LFUN_REJECT_ALL_CHANGES:
479 disable = !buf->params().tracking_changes;
481 case LFUN_INSET_TOGGLE: {
482 LyXText * lt = view()->getLyXText();
483 disable = !(isEditableInset(lt->getInset())
485 && lt->inset_owner->owner()
486 && lt->inset_owner->owner()->isOpen()));
490 case LFUN_INSET_SETTINGS: {
492 UpdatableInset * inset = view()->theLockingInset();
497 // get the innermost inset
498 inset = inset->getLockingInset();
500 // jump back to owner if an InsetText, so
501 // we get back to the InsetTabular or whatever
502 if (inset->lyxCode() == InsetOld::TEXT_CODE)
503 inset = inset->owner();
505 InsetOld::Code code = inset->lyxCode();
507 case InsetOld::TABULAR_CODE:
508 disable = ev.argument != "tabular";
510 case InsetOld::ERT_CODE:
511 disable = ev.argument != "ert";
513 case InsetOld::FLOAT_CODE:
514 disable = ev.argument != "float";
516 case InsetOld::MINIPAGE_CODE:
517 disable = ev.argument != "minipage";
519 case InsetOld::WRAP_CODE:
520 disable = ev.argument != "wrap";
522 case InsetOld::NOTE_CODE:
523 disable = ev.argument != "note";
525 case InsetOld::BRANCH_CODE:
526 disable = ev.argument != "branch";
534 case LFUN_MATH_MUTATE:
536 //flag.setOnOff(mathcursor->formula()->hullType() == ev.argument);
537 flag.setOnOff(false);
542 // we just need to be in math mode to enable that
544 case LFUN_MATH_SPACE:
545 case LFUN_MATH_LIMITS:
546 case LFUN_MATH_NONUMBER:
547 case LFUN_MATH_NUMBER:
548 case LFUN_MATH_EXTERN:
549 disable = !mathcursor;
552 case LFUN_DIALOG_SHOW: {
553 string const name = ev.getArg(0);
555 disable = !(name == "aboutlyx" ||
558 name == "preferences" ||
563 if (name == "print") {
564 disable = !Exporter::IsExportable(*buf, "dvi") ||
565 lyxrc.print_command == "none";
566 } else if (name == "character") {
567 UpdatableInset * tli = view()->theLockingInset();
568 disable = tli && tli->lyxCode() == InsetOld::ERT_CODE;
569 } else if (name == "vclog") {
570 disable = !buf->lyxvc().inUse();
571 } else if (name == "latexlog") {
572 disable = !IsFileReadable(buf->getLogName().second);
581 // the functions which insert insets
582 InsetOld::Code code = InsetOld::NO_CODE;
584 case LFUN_DIALOG_SHOW_NEW_INSET:
585 if (ev.argument == "bibitem")
586 code = InsetOld::BIBITEM_CODE;
587 else if (ev.argument == "bibtex")
588 code = InsetOld::BIBTEX_CODE;
589 else if (ev.argument == "citation")
590 code = InsetOld::CITE_CODE;
591 else if (ev.argument == "ert")
592 code = InsetOld::ERT_CODE;
593 else if (ev.argument == "external")
594 code = InsetOld::EXTERNAL_CODE;
595 else if (ev.argument == "float")
596 code = InsetOld::FLOAT_CODE;
597 else if (ev.argument == "graphics")
598 code = InsetOld::GRAPHICS_CODE;
599 else if (ev.argument == "include")
600 code = InsetOld::INCLUDE_CODE;
601 else if (ev.argument == "index")
602 code = InsetOld::INDEX_CODE;
603 else if (ev.argument == "label")
604 code = InsetOld::LABEL_CODE;
605 else if (ev.argument == "minipage")
606 code = InsetOld::MINIPAGE_CODE;
607 else if (ev.argument == "ref")
608 code = InsetOld::REF_CODE;
609 else if (ev.argument == "toc")
610 code = InsetOld::TOC_CODE;
611 else if (ev.argument == "url")
612 code = InsetOld::URL_CODE;
613 else if (ev.argument == "wrap")
614 code = InsetOld::WRAP_CODE;
618 code = InsetOld::ERT_CODE;
620 case LFUN_INSET_FOOTNOTE:
621 code = InsetOld::FOOT_CODE;
623 case LFUN_TABULAR_INSERT:
624 code = InsetOld::TABULAR_CODE;
626 case LFUN_INSET_MARGINAL:
627 code = InsetOld::MARGIN_CODE;
629 case LFUN_INSET_MINIPAGE:
630 code = InsetOld::MINIPAGE_CODE;
632 case LFUN_INSET_FLOAT:
633 case LFUN_INSET_WIDE_FLOAT:
634 code = InsetOld::FLOAT_CODE;
636 case LFUN_INSET_WRAP:
637 code = InsetOld::WRAP_CODE;
639 case LFUN_FLOAT_LIST:
640 code = InsetOld::FLOAT_LIST_CODE;
643 case LFUN_INSET_LIST:
644 code = InsetOld::LIST_CODE;
646 case LFUN_INSET_THEOREM:
647 code = InsetOld::THEOREM_CODE;
650 case LFUN_INSET_CAPTION:
651 code = InsetOld::CAPTION_CODE;
653 case LFUN_INSERT_NOTE:
654 code = InsetOld::NOTE_CODE;
656 case LFUN_INSERT_BRANCH:
657 code = InsetOld::BRANCH_CODE;
658 if (buf->params().branchlist().empty())
661 case LFUN_INSERT_LABEL:
662 code = InsetOld::LABEL_CODE;
664 case LFUN_INSET_OPTARG:
665 code = InsetOld::OPTARG_CODE;
667 case LFUN_ENVIRONMENT_INSERT:
668 code = InsetOld::MINIPAGE_CODE;
670 case LFUN_INDEX_INSERT:
671 code = InsetOld::INDEX_CODE;
673 case LFUN_INDEX_PRINT:
674 code = InsetOld::INDEX_PRINT_CODE;
676 case LFUN_TOC_INSERT:
677 code = InsetOld::TOC_CODE;
681 code = InsetOld::URL_CODE;
684 // always allow this, since we will inset a raw quote
685 // if an inset is not allowed.
687 case LFUN_HYPHENATION:
688 case LFUN_LIGATURE_BREAK:
690 case LFUN_MENU_SEPARATOR:
692 case LFUN_END_OF_SENTENCE:
693 code = InsetOld::SPECIALCHAR_CODE;
695 case LFUN_SPACE_INSERT:
696 // slight hack: we know this is allowed in math mode
698 code = InsetOld::SPACE_CODE;
700 case LFUN_INSET_DIALOG_SHOW: {
701 LyXText * lt = view()->getLyXText();
702 InsetOld * inset = lt->getInset();
705 code = inset->lyxCode();
706 if (!(code == InsetOld::INCLUDE_CODE
707 || code == InsetOld::BIBTEX_CODE
708 || code == InsetOld::FLOAT_LIST_CODE
709 || code == InsetOld::TOC_CODE))
717 if (code != InsetOld::NO_CODE && tli && !tli->insetAllowed(code))
723 // A few general toggles
725 case LFUN_TOOLTIPS_TOGGLE:
726 flag.setOnOff(owner->getDialogs().tooltipsEnabled());
729 case LFUN_READ_ONLY_TOGGLE:
730 flag.setOnOff(buf->isReadonly());
733 flag.setOnOff(view()->getLyXText()->cursor.par()->params().startOfAppendix());
735 case LFUN_SWITCHBUFFER:
736 // toggle on the current buffer, but do not toggle off
737 // the other ones (is that a good idea?)
738 if (ev.argument == buf->fileName())
741 case LFUN_TRACK_CHANGES:
742 flag.setOnOff(buf->params().tracking_changes);
748 // the font related toggles
750 LyXFont const & font = view()->getLyXText()->real_current_font;
753 flag.setOnOff(font.emph() == LyXFont::ON);
756 flag.setOnOff(font.noun() == LyXFont::ON);
759 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
762 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
765 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
768 flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
774 string tc = mathcursor->getLastCode();
777 flag.setOnOff(tc == "mathbf");
780 flag.setOnOff(tc == "mathsf");
783 flag.setOnOff(tc == "mathcal");
786 flag.setOnOff(tc == "mathrm");
789 flag.setOnOff(tc == "mathtt");
792 flag.setOnOff(tc == "mathbb");
795 flag.setOnOff(tc == "mathnormal");
802 // this one is difficult to get right. As a half-baked
803 // solution, we consider only the first action of the sequence
804 if (ev.action == LFUN_SEQUENCE) {
805 // argument contains ';'-terminated commands
806 flag = getStatus(FuncRequest(lyxaction.LookupFunc(token(ev.argument, ';', 0))));
813 void LyXFunc::dispatch(string const & s, bool verbose)
815 int const action = lyxaction.LookupFunc(s);
817 if (action == LFUN_UNKNOWN_ACTION) {
818 owner->message(bformat(_("Unknown function (%1$s)"), s));
822 dispatch(FuncRequest(kb_action(action)), verbose);
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 & ev, bool verbose)
852 lyxerr[Debug::ACTION] << "LyXFunc::dispatch: action[" << ev.action
853 <<"] arg[" << ev.argument << ']' << endl;
855 // we have not done anything wrong yet.
857 dispatch_buffer.erase();
859 #ifdef NEW_DISPATCHER
860 // We try do call the most specific dispatcher first:
861 // 1. the lockinginset's dispatch
862 // 2. the bufferview's dispatch
863 // 3. the lyxview's dispatch
866 selection_possible = false;
868 string argument = ev.argument;
869 kb_action action = ev.action;
871 // We cannot use this function here
872 if (getStatus(ev).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(ev, view())) == DISPATCHED) {
889 lyxerr << "dispatched by Cursor::dispatch()\n";
890 goto exit_with_message;
896 if (view()->available() && view()->theLockingInset()) {
897 InsetOld::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(ev);
921 goto exit_with_message;
924 // Undo/Redo is a bit tricky for insets.
925 if (action == LFUN_UNDO) {
927 goto exit_with_message;
928 } else if (action == LFUN_REDO) {
930 goto exit_with_message;
931 } else if (((result=inset->
932 // Hand-over to inset's own dispatch:
933 localDispatch(FuncRequest(view(), action, argument))) ==
935 (result == DISPATCHED_NOUPDATE))
936 goto exit_with_message;
937 // If UNDISPATCHED, just soldier on
938 else if (result == FINISHED) {
939 owner->clearMessage();
940 goto exit_with_message;
941 // We do not need special RTL handling here:
942 // FINISHED means that the cursor should be
943 // one position after the inset.
944 } else if (result == FINISHED_RIGHT) {
945 view()->text->cursorRight(view());
947 owner->clearMessage();
948 goto exit_with_message;
949 } else if (result == FINISHED_UP) {
950 RowList::iterator const irow = view()->text->cursorIRow();
951 if (irow != view()->text->firstRow()) {
953 view()->text->setCursorFromCoordinates(
954 view()->text->cursor.x() + inset_x,
955 view()->text->cursor.y() -
956 irow->baseline() - 1);
957 view()->text->cursor.x_fix(view()->text->cursor.x());
959 view()->text->cursorUp(view());
965 owner->clearMessage();
966 goto exit_with_message;
967 } else if (result == FINISHED_DOWN) {
968 RowList::iterator const irow = view()->text->cursorIRow();
969 if (irow != view()->text->lastRow()) {
971 view()->text->setCursorFromCoordinates(
972 view()->text->cursor.x() + inset_x,
973 view()->text->cursor.y() -
976 view()->text->cursor.x_fix(view()->text->cursor.x());
978 view()->text->cursorDown(view());
981 view()->text->cursorRight(view());
984 owner->clearMessage();
985 goto exit_with_message;
987 #warning I am not sure this is still right, please have a look! (Jug 20020417)
988 else { // result == UNDISPATCHED
989 //setMessage(N_("Text mode"));
991 case LFUN_UNKNOWN_ACTION:
992 case LFUN_BREAKPARAGRAPH:
994 view()->text->cursorRight(view());
995 view()->switchKeyMap();
996 owner->view_state_changed();
999 if (!view()->text->cursor.par()->isRightToLeftPar(owner->buffer()->params())) {
1000 view()->text->cursorRight(view());
1002 owner->view_state_changed();
1004 goto exit_with_message;
1006 if (view()->text->cursor.par()->isRightToLeftPar(owner->buffer()->params())) {
1007 view()->text->cursorRight(view());
1009 owner->view_state_changed();
1011 goto exit_with_message;
1013 if (view()->text->cursorRow() != view()->text->lastRow())
1014 view()->text->cursorDown(view());
1016 view()->text->cursorRight(view());
1018 owner->view_state_changed();
1019 goto exit_with_message;
1030 if (!view()->available())
1032 // this function should be used always [asierra060396]
1033 UpdatableInset * tli = view()->theLockingInset();
1035 UpdatableInset * lock = tli->getLockingInset();
1038 view()->unlockInset(tli);
1039 view()->text->cursorRight(view());
1041 owner->view_state_changed();
1043 tli->unlockInsetInInset(view(), lock, true);
1046 // Tell the paragraph dialog that we changed paragraph
1047 dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
1052 case LFUN_WORDFINDFORWARD:
1053 case LFUN_WORDFINDBACKWARD: {
1054 static string last_search;
1055 string searched_string;
1057 if (!argument.empty()) {
1058 last_search = argument;
1059 searched_string = argument;
1061 searched_string = last_search;
1063 bool fw = (action == LFUN_WORDFINDFORWARD);
1064 if (!searched_string.empty())
1065 lyx::find::find(view(), searched_string, fw);
1070 if (view()->available() && !view()->theLockingInset())
1072 owner->message(keyseq.printOptions());
1075 // --- Misc -------------------------------------------
1076 case LFUN_EXEC_COMMAND:
1077 owner->focus_command_buffer();
1082 meta_fake_bit = key_modifier::none;
1083 if (view()->available())
1084 // cancel any selection
1085 dispatch(FuncRequest(LFUN_MARK_OFF));
1086 setMessage(N_("Cancel"));
1089 case LFUN_META_FAKE:
1090 meta_fake_bit = key_modifier::alt;
1091 setMessage(keyseq.print());
1094 case LFUN_READ_ONLY_TOGGLE:
1095 if (owner->buffer()->lyxvc().inUse())
1096 owner->buffer()->lyxvc().toggleReadOnly();
1098 owner->buffer()->setReadonly(
1099 !owner->buffer()->isReadonly());
1102 case LFUN_CENTER: // this is center and redraw.
1106 // --- Menus -----------------------------------------------
1108 menuNew(argument, false);
1111 case LFUN_MENUNEWTMPLT:
1112 menuNew(argument, true);
1115 case LFUN_CLOSEBUFFER:
1119 case LFUN_MENUWRITE:
1120 if (!owner->buffer()->isUnnamed()) {
1121 string const str = bformat(_("Saving document %1$s..."),
1122 MakeDisplayPath(owner->buffer()->fileName()));
1123 owner->message(str);
1124 MenuWrite(owner->buffer());
1125 owner->message(str + _(" done."));
1127 WriteAs(owner->buffer());
1131 WriteAs(owner->buffer(), argument);
1134 case LFUN_MENURELOAD: {
1135 string const file = MakeDisplayPath(view()->buffer()->fileName(), 20);
1136 string text = bformat(_("Any changes will be lost. Are you sure "
1137 "you want to revert to the saved version of the document %1$s?"), file);
1138 int const ret = Alert::prompt(_("Revert to saved document?"),
1139 text, 0, 1, _("&Revert"), _("&Cancel"));
1147 Exporter::Export(owner->buffer(), argument, true);
1148 view()->showErrorList(BufferFormat(*owner->buffer()));
1152 Exporter::Preview(owner->buffer(), argument);
1153 view()->showErrorList(BufferFormat(*owner->buffer()));
1156 case LFUN_BUILDPROG:
1157 Exporter::Export(owner->buffer(), "program", true);
1158 view()->showErrorList(_("Build"));
1161 case LFUN_RUNCHKTEX:
1162 owner->buffer()->runChktex();
1163 view()->showErrorList(_("ChkTeX"));
1167 if (argument == "custom")
1168 owner->getDialogs().showSendto();
1170 Exporter::Export(owner->buffer(), argument, false);
1171 view()->showErrorList(BufferFormat(*owner->buffer()));
1185 InsetCommandParams p("tableofcontents");
1186 string const data = InsetCommandMailer::params2string("toc", p);
1187 owner->getDialogs().show("toc", data, 0);
1203 case LFUN_DEPTH_MIN:
1204 changeDepth(view(), view()->getLyXText(), DEC_DEPTH, false);
1205 owner->view_state_changed();
1208 case LFUN_DEPTH_PLUS:
1209 changeDepth(view(), view()->getLyXText(), INC_DEPTH, false);
1210 owner->view_state_changed();
1213 case LFUN_FREEFONT_APPLY:
1214 apply_freefont(view());
1217 case LFUN_FREEFONT_UPDATE:
1218 update_and_apply_freefont(view(), argument);
1221 case LFUN_RECONFIGURE:
1222 Reconfigure(view());
1226 case LFUN_FLOATSOPERATE:
1227 if (argument == "openfoot")
1228 view()->allFloats(1,0);
1229 else if (argument == "closefoot")
1230 view()->allFloats(0,0);
1231 else if (argument == "openfig")
1232 view()->allFloats(1,1);
1233 else if (argument == "closefig")
1234 view()->allFloats(0,1);
1237 #ifdef WITH_WARNINGS
1238 //#warning Find another implementation here (or another lyxfunc)!
1241 case LFUN_HELP_OPEN:
1243 string const arg = argument;
1245 setErrorMessage(N_("Missing argument"));
1248 string const fname = i18nLibFileSearch("doc", arg, "lyx");
1249 if (fname.empty()) {
1250 lyxerr << "LyX: unable to find documentation file `"
1251 << arg << "'. Bad installation?" << endl;
1254 owner->message(bformat(_("Opening help file %1$s..."),
1255 MakeDisplayPath(fname)));
1256 view()->loadLyXFile(fname, false);
1260 // --- version control -------------------------------
1261 case LFUN_VC_REGISTER:
1263 if (!ensureBufferClean(view()))
1265 if (!owner->buffer()->lyxvc().inUse()) {
1266 owner->buffer()->lyxvc().registrer();
1272 case LFUN_VC_CHECKIN:
1274 if (!ensureBufferClean(view()))
1276 if (owner->buffer()->lyxvc().inUse()
1277 && !owner->buffer()->isReadonly()) {
1278 owner->buffer()->lyxvc().checkIn();
1284 case LFUN_VC_CHECKOUT:
1286 if (!ensureBufferClean(view()))
1288 if (owner->buffer()->lyxvc().inUse()
1289 && owner->buffer()->isReadonly()) {
1290 owner->buffer()->lyxvc().checkOut();
1296 case LFUN_VC_REVERT:
1298 owner->buffer()->lyxvc().revert();
1305 owner->buffer()->lyxvc().undoLast();
1310 // --- buffers ----------------------------------------
1312 case LFUN_SWITCHBUFFER:
1313 view()->buffer(bufferlist.getBuffer(argument));
1317 NewFile(view(), argument);
1320 case LFUN_FILE_OPEN:
1324 case LFUN_LAYOUT_TABULAR:
1325 if (view()->theLockingInset()) {
1326 if (view()->theLockingInset()->lyxCode()== InsetOld::TABULAR_CODE) {
1327 InsetTabular * inset = static_cast<InsetTabular *>
1328 (view()->theLockingInset());
1329 inset->openLayoutDialog(view());
1330 } else if (view()->theLockingInset()->
1331 getFirstLockingInsetOfType(InsetOld::TABULAR_CODE)!=0) {
1332 InsetTabular * inset = static_cast<InsetTabular *>(
1333 view()->theLockingInset()->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE));
1334 inset->openLayoutDialog(view());
1339 case LFUN_DROP_LAYOUTS_CHOICE:
1340 owner->getToolbar().openLayoutList();
1343 case LFUN_MENU_OPEN_BY_NAME:
1344 owner->getMenubar().openByName(argument);
1345 break; // RVDK_PATCH_5
1347 // --- lyxserver commands ----------------------------
1351 setMessage(owner->buffer()->fileName());
1352 lyxerr[Debug::INFO] << "FNAME["
1353 << owner->buffer()->fileName()
1359 dispatch_buffer = keyseq.print();
1360 lyxserver->notifyClient(dispatch_buffer);
1364 case LFUN_GOTOFILEROW:
1368 istringstream istr(argument.c_str());
1369 istr >> file_name >> row;
1370 // Must replace extension of the file to be .lyx and get full path
1371 string const s(ChangeExtension(file_name, ".lyx"));
1373 // Either change buffer or load the file
1374 if (bufferlist.exists(s)) {
1375 view()->buffer(bufferlist.getBuffer(s));
1377 view()->loadLyXFile(s);
1380 view()->setCursorFromRow(row);
1383 // see BufferView_pimpl::center()
1384 view()->updateScrollbar();
1388 case LFUN_GOTO_PARAGRAPH:
1390 istringstream istr(argument.c_str());
1394 ParIterator par = owner->buffer()->getParFromID(id);
1395 if (par == owner->buffer()->par_iterator_end()) {
1396 lyxerr[Debug::INFO] << "No matching paragraph found! ["
1397 << id << ']' << endl;
1400 lyxerr[Debug::INFO] << "Paragraph " << par->id()
1401 << " found." << endl;
1404 if (view()->theLockingInset())
1405 view()->unlockInset(view()->theLockingInset());
1406 if (par->inInset()) {
1407 FuncRequest cmd(view(), LFUN_INSET_EDIT, "left");
1408 par->inInset()->localDispatch(cmd);
1411 view()->getLyXText()->setCursor(par.pit(), 0);
1412 view()->switchKeyMap();
1413 owner->view_state_changed();
1416 // see BufferView_pimpl::center()
1417 view()->updateScrollbar();
1421 // --- insert characters ----------------------------------------
1423 // --- Mathed stuff. If we are here, there is no locked inset yet.
1424 case LFUN_MATH_EXTERN:
1425 case LFUN_MATH_NUMBER:
1426 case LFUN_MATH_NONUMBER:
1427 case LFUN_MATH_LIMITS:
1429 setErrorMessage(N_("This is only allowed in math mode!"));
1433 // passthrough hat and underscore outside mathed:
1434 case LFUN_SUBSCRIPT:
1435 dispatch(FuncRequest(view(), LFUN_SELFINSERT, "_"));
1437 case LFUN_SUPERSCRIPT:
1438 dispatch(FuncRequest(view(), LFUN_SELFINSERT, "^"));
1441 case LFUN_DIALOG_SHOW: {
1442 string const name = ev.getArg(0);
1443 string data = trim(ev.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: {
1492 case LFUN_INSET_DIALOG_SHOW: {
1493 LyXText * lt = view()->getLyXText();
1494 InsetOld * inset = lt->getInset();
1496 FuncRequest cmd(view(), LFUN_INSET_DIALOG_SHOW);
1497 inset->localDispatch(cmd);
1502 case LFUN_DIALOG_UPDATE: {
1503 string const & name = argument;
1504 // Can only update a dialog connected to an existing inset
1505 InsetBase * inset = owner->getDialogs().getOpenInset(name);
1507 FuncRequest fr(view(), LFUN_INSET_DIALOG_UPDATE,
1509 inset->localDispatch(fr);
1510 } else if (name == "paragraph") {
1511 dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
1516 case LFUN_DIALOG_HIDE:
1517 Dialogs::hide(argument, 0);
1520 case LFUN_DIALOG_DISCONNECT_INSET:
1521 owner->getDialogs().disconnect(argument);
1524 case LFUN_CHILDOPEN:
1526 string const filename =
1527 MakeAbsPath(argument,
1528 owner->buffer()->filePath());
1529 setMessage(N_("Opening child document ") +
1530 MakeDisplayPath(filename) + "...");
1531 view()->savePosition(0);
1532 if (bufferlist.exists(filename))
1533 view()->buffer(bufferlist.getBuffer(filename));
1535 view()->loadLyXFile(filename);
1539 case LFUN_TOGGLECURSORFOLLOW:
1540 lyxrc.cursor_follows_scrollbar = !lyxrc.cursor_follows_scrollbar;
1544 owner->getIntl().KeyMapOn(false);
1547 case LFUN_KMAP_PRIM:
1548 owner->getIntl().KeyMapPrim();
1552 owner->getIntl().KeyMapSec();
1555 case LFUN_KMAP_TOGGLE:
1556 owner->getIntl().ToggleKeyMap();
1561 // argument contains ';'-terminated commands
1562 while (!argument.empty()) {
1564 argument = split(argument, first, ';');
1570 case LFUN_SAVEPREFERENCES:
1572 Path p(user_lyxdir());
1573 lyxrc.write("preferences");
1577 case LFUN_SCREEN_FONT_UPDATE:
1579 // handle the screen font changes.
1580 lyxrc.set_font_norm_type();
1581 lyx_gui::update_fonts();
1582 // We also need to empty the textcache so that
1583 // the buffer will be formatted correctly after
1586 // Of course we should only do the resize and the textcache.clear
1587 // if values really changed...but not very important right now. (Lgb)
1588 // All visible buffers will need resize
1594 case LFUN_SET_COLOR:
1597 string const x11_name = split(argument, lyx_name, ' ');
1598 if (lyx_name.empty() || x11_name.empty()) {
1599 setErrorMessage(N_("Syntax: set-color <lyx_name>"
1604 bool const graphicsbg_changed =
1605 (lyx_name == lcolor.getLyXName(LColor::graphicsbg) &&
1606 x11_name != lcolor.getX11Name(LColor::graphicsbg));
1608 if (!lcolor.setColor(lyx_name, x11_name)) {
1610 bformat(_("Set-color \"%1$s\" failed "
1611 "- color is undefined or "
1612 "may not be redefined"), lyx_name));
1616 lyx_gui::update_color(lcolor.getFromLyXName(lyx_name));
1618 if (graphicsbg_changed) {
1619 #ifdef WITH_WARNINGS
1620 #warning FIXME!! The graphics cache no longer has a changeDisplay method.
1623 lyx::graphics::GCache & gc =
1624 lyx::graphics::GCache::get();
1625 gc.changeDisplay(true);
1634 owner->message(argument);
1637 case LFUN_FORKS_KILL:
1639 if (!isStrInt(argument))
1642 pid_t const pid = strToInt(argument);
1643 ForkedcallsController & fcc = ForkedcallsController::get();
1648 case LFUN_TOOLTIPS_TOGGLE:
1649 owner->getDialogs().toggleTooltips();
1652 case LFUN_EXTERNAL_EDIT: {
1654 .localDispatch(FuncRequest(view(), action, argument));
1659 // Then if it was none of the above
1660 // Trying the BufferView::pimpl dispatch:
1661 if (!view()->dispatch(ev))
1662 lyxerr << "A truly unknown func ["
1663 << lyxaction.getActionName(ev.action) << "]!"
1670 view()->owner()->updateLayoutChoice();
1672 if (view()->available()) {
1673 if (view()->fitCursor()) {
1674 //lyxerr << "LyXFunc->fitCursor->update" << endl;
1678 // If we executed a mutating lfun, mark the buffer as dirty
1679 if (!getStatus(ev).disabled()
1680 && !lyxaction.funcHasFlag(ev.action, LyXAction::NoBuffer)
1681 && !lyxaction.funcHasFlag(ev.action, LyXAction::ReadOnly))
1682 view()->buffer()->markDirty();
1685 sendDispatchMessage(getMessage(), ev, verbose);
1689 void LyXFunc::sendDispatchMessage(string const & msg, FuncRequest const & ev, bool verbose)
1691 owner->updateMenubar();
1692 owner->updateToolbar();
1694 if (ev.action == LFUN_SELFINSERT || !verbose) {
1695 lyxerr[Debug::ACTION] << "dispatch msg is " << msg << endl;
1697 owner->message(msg);
1701 string dispatch_msg = msg;
1702 if (!dispatch_msg.empty())
1703 dispatch_msg += ' ';
1705 string comname = lyxaction.getActionName(ev.action);
1707 bool argsadded = false;
1709 if (!ev.argument.empty()) {
1710 if (ev.action != LFUN_UNKNOWN_ACTION) {
1711 comname += ' ' + ev.argument;
1716 string const shortcuts = toplevel_keymap->findbinding(ev.action);
1718 if (!shortcuts.empty()) {
1719 comname += ": " + shortcuts;
1720 } else if (!argsadded && !ev.argument.empty()) {
1721 comname += ' ' + ev.argument;
1724 if (!comname.empty()) {
1725 comname = rtrim(comname);
1726 dispatch_msg += '(' + comname + ')';
1729 lyxerr[Debug::ACTION] << "verbose dispatch msg " << dispatch_msg << endl;
1730 if (!dispatch_msg.empty())
1731 owner->message(dispatch_msg);
1735 void LyXFunc::setupLocalKeymap()
1737 keyseq.stdmap = keyseq.curmap = toplevel_keymap.get();
1738 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap.get();
1742 void LyXFunc::menuNew(string const & name, bool fromTemplate)
1744 string initpath = lyxrc.document_path;
1745 string filename(name);
1747 if (view()->available()) {
1748 string const trypath = owner->buffer()->filePath();
1749 // If directory is writeable, use this as default.
1750 if (IsDirWriteable(trypath))
1754 static int newfile_number;
1756 if (filename.empty()) {
1757 filename = AddName(lyxrc.document_path,
1758 "newfile" + tostr(++newfile_number) + ".lyx");
1759 FileInfo fi(filename);
1760 while (bufferlist.exists(filename) || fi.readable()) {
1762 filename = AddName(lyxrc.document_path,
1763 "newfile" + tostr(newfile_number) +
1765 fi.newFile(filename);
1769 // The template stuff
1772 FileDialog fileDlg(_("Select template file"),
1773 LFUN_SELECT_FILE_SYNC,
1774 make_pair(string(_("Documents|#o#O")),
1775 string(lyxrc.document_path)),
1776 make_pair(string(_("Templates|#T#t")),
1777 string(lyxrc.template_path)));
1779 FileDialog::Result result =
1780 fileDlg.open(lyxrc.template_path,
1781 _("*.lyx| LyX Documents (*.lyx)"));
1783 if (result.first == FileDialog::Later)
1786 string const fname = result.second;
1793 view()->newFile(filename, templname, !name.empty());
1797 void LyXFunc::open(string const & fname)
1799 string initpath = lyxrc.document_path;
1801 if (view()->available()) {
1802 string const trypath = owner->buffer()->filePath();
1803 // If directory is writeable, use this as default.
1804 if (IsDirWriteable(trypath))
1810 if (fname.empty()) {
1811 FileDialog fileDlg(_("Select document to open"),
1813 make_pair(string(_("Documents|#o#O")),
1814 string(lyxrc.document_path)),
1815 make_pair(string(_("Examples|#E#e")),
1816 string(AddPath(system_lyxdir(), "examples"))));
1818 FileDialog::Result result =
1819 fileDlg.open(initpath,
1820 _("*.lyx| LyX Documents (*.lyx)"));
1822 if (result.first == FileDialog::Later)
1825 filename = result.second;
1827 // check selected filename
1828 if (filename.empty()) {
1829 owner->message(_("Canceled."));
1835 // get absolute path of file and add ".lyx" to the filename if
1837 string const fullpath = FileSearch(string(), filename, "lyx");
1838 if (!fullpath.empty()) {
1839 filename = fullpath;
1842 string const disp_fn(MakeDisplayPath(filename));
1844 // if the file doesn't exist, let the user create one
1845 FileInfo const f(filename, true);
1847 // the user specifically chose this name. Believe them.
1848 view()->newFile(filename, "", true);
1852 owner->message(bformat(_("Opening document %1$s..."), disp_fn));
1855 if (view()->loadLyXFile(filename)) {
1856 str2 = bformat(_("Document %1$s opened."), disp_fn);
1858 str2 = bformat(_("Could not open document %1$s"), disp_fn);
1860 owner->message(str2);
1864 void LyXFunc::doImport(string const & argument)
1867 string filename = split(argument, format, ' ');
1869 lyxerr[Debug::INFO] << "LyXFunc::doImport: " << format
1870 << " file: " << filename << endl;
1872 // need user interaction
1873 if (filename.empty()) {
1874 string initpath = lyxrc.document_path;
1876 if (view()->available()) {
1877 string const trypath = owner->buffer()->filePath();
1878 // If directory is writeable, use this as default.
1879 if (IsDirWriteable(trypath))
1883 string const text = bformat(_("Select %1$s file to import"),
1884 formats.prettyName(format));
1886 FileDialog fileDlg(text,
1888 make_pair(string(_("Documents|#o#O")),
1889 string(lyxrc.document_path)),
1890 make_pair(string(_("Examples|#E#e")),
1891 string(AddPath(system_lyxdir(), "examples"))));
1893 string const extension = "*." + formats.extension(format)
1894 + "| " + formats.prettyName(format)
1895 + " (*." + formats.extension(format) + ')';
1897 FileDialog::Result result = fileDlg.open(initpath,
1900 if (result.first == FileDialog::Later)
1903 filename = result.second;
1905 // check selected filename
1906 if (filename.empty())
1907 owner->message(_("Canceled."));
1910 if (filename.empty())
1913 // get absolute path of file
1914 filename = MakeAbsPath(filename);
1916 string const lyxfile = ChangeExtension(filename, ".lyx");
1918 // Check if the document already is open
1919 if (lyx_gui::use_gui && bufferlist.exists(lyxfile)) {
1920 if (!bufferlist.close(bufferlist.getBuffer(lyxfile), true)) {
1921 owner->message(_("Canceled."));
1926 // if the file exists already, and we didn't do
1927 // -i lyx thefile.lyx, warn
1928 if (FileInfo(lyxfile, true).exist() && filename != lyxfile) {
1929 string const file = MakeDisplayPath(lyxfile, 30);
1931 string text = bformat(_("The document %1$s already exists.\n\n"
1932 "Do you want to over-write that document?"), file);
1933 int const ret = Alert::prompt(_("Over-write document?"),
1934 text, 0, 1, _("&Over-write"), _("&Cancel"));
1937 owner->message(_("Canceled."));
1942 Importer::Import(owner, filename, format);
1946 void LyXFunc::closeBuffer()
1948 if (bufferlist.close(owner->buffer(), true) && !quitting) {
1949 if (bufferlist.empty()) {
1950 // need this otherwise SEGV may occur while
1951 // trying to set variables that don't exist
1952 // since there's no current buffer
1953 owner->getDialogs().hideBufferDependent();
1955 view()->buffer(bufferlist.first());
1961 // Each "owner" should have it's own message method. lyxview and
1962 // the minibuffer would use the minibuffer, but lyxserver would
1963 // send an ERROR signal to its client. Alejandro 970603
1964 // This func is bit problematic when it comes to NLS, to make the
1965 // lyx servers client be language indepenent we must not translate
1966 // strings sent to this func.
1967 void LyXFunc::setErrorMessage(string const & m) const
1969 dispatch_buffer = m;
1974 void LyXFunc::setMessage(string const & m) const
1976 dispatch_buffer = m;
1980 void LyXFunc::setStatusMessage(string const & m) const
1986 string const LyXFunc::view_status_message()
1988 // When meta-fake key is pressed, show the key sequence so far + "M-".
1990 return keyseq.print() + "M-";
1993 // Else, when a non-complete key sequence is pressed,
1994 // show the available options.
1995 if (keyseq.length() > 0 && !keyseq.deleted()) {
1996 return keyseq.printOptions();
1999 if (!view()->available())
2000 return _("Welcome to LyX!");
2002 return currentState(view());
2006 BufferView * LyXFunc::view() const
2008 BOOST_ASSERT(owner);
2009 return owner->view().get();
2013 bool LyXFunc::wasMetaKey() const
2015 return (meta_fake_bit != key_modifier::none);