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"
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"
76 #include "support/os.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;
108 using lyx::support::prefixIs;
109 using lyx::support::os::getTmpDir;
112 using std::make_pair;
114 using std::istringstream;
117 extern BufferList bufferlist;
118 extern LyXServer * lyxserver;
119 extern bool selection_possible;
121 extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
124 extern tex_accent_struct get_accent(kb_action action);
126 extern void ShowLatexLog();
129 LyXFunc::LyXFunc(LyXView * o)
132 keyseq(toplevel_keymap.get(), toplevel_keymap.get()),
133 cancel_meta_seq(toplevel_keymap.get(), toplevel_keymap.get()),
134 meta_fake_bit(key_modifier::none)
139 void LyXFunc::moveCursorUpdate()
141 LyXText * lt = view()->text;
142 if (lt->selection.mark())
145 view()->switchKeyMap();
149 void LyXFunc::handleKeyFunc(kb_action action)
151 char c = encoded_last_key;
153 if (keyseq.length()) {
157 owner->getIntl().getTransManager()
158 .deadkey(c, get_accent(action).accent, view()->getLyXText());
159 // Need to clear, in case the minibuffer calls these
162 // copied verbatim from do_accent_char
164 view()->getLyXText()->selection.cursor = view()->getLyXText()->cursor;
168 void LyXFunc::processKeySym(LyXKeySymPtr keysym,
169 key_modifier::state state)
173 if (lyxerr.debugging(Debug::KEY)) {
174 lyxerr << "KeySym is "
175 << keysym->getSymbolName()
179 // Do nothing if we have nothing (JMarc)
180 if (!keysym->isOK()) {
181 lyxerr[Debug::KEY] << "Empty kbd action (probably composing)"
186 if (keysym->isModifier()) {
187 lyxerr[Debug::KEY] << "isModifier true" << endl;
191 Encoding const * encoding = view()->getEncoding();
193 encoded_last_key = keysym->getISOEncoded(encoding ? encoding->Name() : "");
195 // Do a one-deep top-level lookup for
196 // cancel and meta-fake keys. RVDK_PATCH_5
197 cancel_meta_seq.reset();
199 FuncRequest func = cancel_meta_seq.addkey(keysym, state);
200 lyxerr[Debug::KEY] << "action first set to [" << func.action << ']' << endl;
202 // When not cancel or meta-fake, do the normal lookup.
203 // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
204 // Mostly, meta_fake_bit = key_modifier::none. RVDK_PATCH_5.
205 if ((func.action != LFUN_CANCEL) && (func.action != LFUN_META_FAKE)) {
206 // remove Caps Lock and Mod2 as a modifiers
207 func = keyseq.addkey(keysym, (state | meta_fake_bit));
208 lyxerr[Debug::KEY] << "action now set to ["
209 << func.action << ']' << endl;
212 // Dont remove this unless you know what you are doing.
213 meta_fake_bit = key_modifier::none;
215 // can this happen now ?
216 if (func.action == LFUN_NOACTION) {
217 func = FuncRequest(LFUN_PREFIX);
220 if (lyxerr.debugging(Debug::KEY)) {
221 lyxerr << "Key [action="
222 << func.action << "]["
223 << keyseq.print() << ']'
227 // already here we know if it any point in going further
228 // why not return already here if action == -1 and
229 // num_bytes == 0? (Lgb)
231 if (keyseq.length() > 1) {
232 owner->message(keyseq.print());
236 // Maybe user can only reach the key via holding down shift.
237 // Let's see. But only if shift is the only modifier
238 if (func.action == LFUN_UNKNOWN_ACTION &&
239 state == key_modifier::shift) {
240 lyxerr[Debug::KEY] << "Trying without shift" << endl;
241 func = keyseq.addkey(keysym, key_modifier::none);
242 lyxerr[Debug::KEY] << "Action now " << func.action << endl;
245 if (func.action == LFUN_UNKNOWN_ACTION) {
246 // Hmm, we didn't match any of the keysequences. See
247 // if it's normal insertable text not already covered
249 if (keysym->isText() && keyseq.length() == 1) {
250 lyxerr[Debug::KEY] << "isText() is true, inserting." << endl;
251 func = FuncRequest(LFUN_SELFINSERT);
253 lyxerr[Debug::KEY] << "Unknown, !isText() - giving up" << endl;
254 owner->message(_("Unknown function."));
259 if (func.action == LFUN_SELFINSERT) {
260 if (encoded_last_key != 0) {
262 arg += encoded_last_key;
264 dispatch(FuncRequest(view(), LFUN_SELFINSERT, arg));
266 lyxerr[Debug::KEY] << "SelfInsert arg[`"
267 << argument << "']" << endl;
275 FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
278 Buffer * buf = owner->buffer();
280 if (ev.action == LFUN_NOACTION) {
281 setStatusMessage(N_("Nothing to do"));
282 return flag.disabled(true);
286 case LFUN_UNKNOWN_ACTION:
287 #ifndef HAVE_LIBAIKSAURUS
288 case LFUN_THESAURUS_ENTRY:
294 flag |= lyx_gui::getStatus(ev);
297 if (flag.unknown()) {
298 setStatusMessage(N_("Unknown action"));
302 // the default error message if we disable the command
303 setStatusMessage(N_("Command disabled"));
305 // Check whether we need a buffer
306 if (!lyxaction.funcHasFlag(ev.action, LyXAction::NoBuffer)) {
307 // Yes we need a buffer, do we have one?
310 // Can we use a readonly buffer?
311 if (buf->isReadonly() &&
312 !lyxaction.funcHasFlag(ev.action,
313 LyXAction::ReadOnly)) {
315 setStatusMessage(N_("Document is read-only"));
320 setStatusMessage(N_("Command not allowed with"
321 "out any document open"));
322 return flag.disabled(true);
326 UpdatableInset * tli = view()->theLockingInset();
328 // I would really like to avoid having this switch and rather try to
329 // encode this in the function itself.
330 bool disable = false;
333 disable = ev.argument != "custom"
334 && !Exporter::IsExportable(*buf, ev.argument);
337 disable = buf->undostack().empty();
340 disable = buf->redostack().empty();
345 UpdatableInset * in = tli;
346 if (in->lyxCode() != InsetOld::TABULAR_CODE) {
347 in = tli->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE);
349 if (in && static_cast<InsetTabular*>(in)->hasSelection()) {
354 disable = !mathcursor && !view()->getLyXText()->selection.set();
357 disable = !buf->isLatex() || lyxrc.chktex_command == "none";
360 disable = !Exporter::IsExportable(*buf, "program");
363 case LFUN_LAYOUT_TABULAR:
365 || (tli->lyxCode() != InsetOld::TABULAR_CODE
366 && !tli->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE));
370 disable = !changeDepth(view(), view()->getLyXText(), DEC_DEPTH, true);
373 case LFUN_DEPTH_PLUS:
374 disable = !changeDepth(view(), view()->getLyXText(), INC_DEPTH, true);
378 case LFUN_LAYOUT_PARAGRAPH: {
379 InsetOld * inset = view()->getLyXText()->cursorPar()->inInset();
380 disable = inset && inset->forceDefaultParagraphs(inset);
384 case LFUN_INSET_OPTARG:
385 disable = (view()->getLyXText()->cursorPar()->layout()->optionalargs == 0);
388 case LFUN_TABULAR_FEATURE:
391 // FIXME: check temporarily disabled
393 char align = mathcursor->valign();
398 if (ev.argument.empty()) {
402 if (!contains("tcb", ev.argument[0])) {
406 flag.setOnOff(ev.argument[0] == align);
410 char align = mathcursor->halign();
415 if (ev.argument.empty()) {
419 if (!contains("lcr", ev.argument[0])) {
423 flag.setOnOff(ev.argument[0] == align);
426 disable = !mathcursor->halign();
432 //ret.disabled(true);
433 if (tli->lyxCode() == InsetOld::TABULAR_CODE) {
434 ret = static_cast<InsetTabular *>(tli)
435 ->getStatus(ev.argument);
438 } else if (tli->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE)) {
439 ret = static_cast<InsetTabular *>
440 (tli->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE))
441 ->getStatus(ev.argument);
448 static InsetTabular inset(*owner->buffer(), 1, 1);
452 ret = inset.getStatus(ev.argument);
453 if (ret.onoff(true) || ret.onoff(false))
454 flag.setOnOff(false);
458 case LFUN_VC_REGISTER:
459 disable = buf->lyxvc().inUse();
461 case LFUN_VC_CHECKIN:
462 disable = !buf->lyxvc().inUse() || buf->isReadonly();
464 case LFUN_VC_CHECKOUT:
465 disable = !buf->lyxvc().inUse() || !buf->isReadonly();
469 disable = !buf->lyxvc().inUse();
471 case LFUN_MENURELOAD:
472 disable = buf->isUnnamed() || buf->isClean();
474 case LFUN_BOOKMARK_GOTO:
476 isSavedPosition(strToUnsignedInt(ev.argument));
478 case LFUN_MERGE_CHANGES:
479 case LFUN_ACCEPT_CHANGE:
480 case LFUN_REJECT_CHANGE:
481 case LFUN_ACCEPT_ALL_CHANGES:
482 case LFUN_REJECT_ALL_CHANGES:
483 disable = !buf->params().tracking_changes;
485 case LFUN_INSET_TOGGLE: {
486 LyXText * lt = view()->getLyXText();
487 disable = !(isEditableInset(lt->getInset())
489 && lt->inset_owner->owner()
490 && lt->inset_owner->owner()->isOpen()));
494 case LFUN_INSET_SETTINGS: {
496 UpdatableInset * inset = view()->theLockingInset();
501 // get the innermost inset
502 inset = inset->getLockingInset();
504 // jump back to owner if an InsetText, so
505 // we get back to the InsetTabular or whatever
506 if (inset->lyxCode() == InsetOld::TEXT_CODE)
507 inset = inset->owner();
509 InsetOld::Code code = inset->lyxCode();
511 case InsetOld::TABULAR_CODE:
512 disable = ev.argument != "tabular";
514 case InsetOld::ERT_CODE:
515 disable = ev.argument != "ert";
517 case InsetOld::FLOAT_CODE:
518 disable = ev.argument != "float";
520 case InsetOld::MINIPAGE_CODE:
521 disable = ev.argument != "minipage";
523 case InsetOld::WRAP_CODE:
524 disable = ev.argument != "wrap";
526 case InsetOld::NOTE_CODE:
527 disable = ev.argument != "note";
529 case InsetOld::BRANCH_CODE:
530 disable = ev.argument != "branch";
532 case InsetOld::BOX_CODE:
533 disable = ev.argument != "box";
541 case LFUN_MATH_MUTATE:
543 //flag.setOnOff(mathcursor->formula()->hullType() == ev.argument);
544 flag.setOnOff(false);
549 // we just need to be in math mode to enable that
551 case LFUN_MATH_SPACE:
552 case LFUN_MATH_LIMITS:
553 case LFUN_MATH_NONUMBER:
554 case LFUN_MATH_NUMBER:
555 case LFUN_MATH_EXTERN:
556 disable = !mathcursor;
559 case LFUN_DIALOG_SHOW: {
560 string const name = ev.getArg(0);
562 disable = !(name == "aboutlyx" ||
565 name == "preferences" ||
570 if (name == "print") {
571 disable = !Exporter::IsExportable(*buf, "dvi") ||
572 lyxrc.print_command == "none";
573 } else if (name == "character") {
574 UpdatableInset * tli = view()->theLockingInset();
575 disable = tli && tli->lyxCode() == InsetOld::ERT_CODE;
576 } else if (name == "vclog") {
577 disable = !buf->lyxvc().inUse();
578 } else if (name == "latexlog") {
579 disable = !IsFileReadable(buf->getLogName().second);
588 // the functions which insert insets
589 InsetOld::Code code = InsetOld::NO_CODE;
591 case LFUN_DIALOG_SHOW_NEW_INSET:
592 if (ev.argument == "bibitem")
593 code = InsetOld::BIBITEM_CODE;
594 else if (ev.argument == "bibtex")
595 code = InsetOld::BIBTEX_CODE;
596 else if (ev.argument == "citation")
597 code = InsetOld::CITE_CODE;
598 else if (ev.argument == "ert")
599 code = InsetOld::ERT_CODE;
600 else if (ev.argument == "external")
601 code = InsetOld::EXTERNAL_CODE;
602 else if (ev.argument == "float")
603 code = InsetOld::FLOAT_CODE;
604 else if (ev.argument == "graphics")
605 code = InsetOld::GRAPHICS_CODE;
606 else if (ev.argument == "include")
607 code = InsetOld::INCLUDE_CODE;
608 else if (ev.argument == "index")
609 code = InsetOld::INDEX_CODE;
610 else if (ev.argument == "label")
611 code = InsetOld::LABEL_CODE;
612 else if (ev.argument == "minipage")
613 code = InsetOld::MINIPAGE_CODE;
614 else if (ev.argument == "ref")
615 code = InsetOld::REF_CODE;
616 else if (ev.argument == "toc")
617 code = InsetOld::TOC_CODE;
618 else if (ev.argument == "url")
619 code = InsetOld::URL_CODE;
620 else if (ev.argument == "wrap")
621 code = InsetOld::WRAP_CODE;
625 code = InsetOld::ERT_CODE;
627 case LFUN_INSET_FOOTNOTE:
628 code = InsetOld::FOOT_CODE;
630 case LFUN_TABULAR_INSERT:
631 code = InsetOld::TABULAR_CODE;
633 case LFUN_INSET_MARGINAL:
634 code = InsetOld::MARGIN_CODE;
636 case LFUN_INSET_MINIPAGE:
637 code = InsetOld::MINIPAGE_CODE;
639 case LFUN_INSET_FLOAT:
640 case LFUN_INSET_WIDE_FLOAT:
641 code = InsetOld::FLOAT_CODE;
643 case LFUN_INSET_WRAP:
644 code = InsetOld::WRAP_CODE;
646 case LFUN_FLOAT_LIST:
647 code = InsetOld::FLOAT_LIST_CODE;
650 case LFUN_INSET_LIST:
651 code = InsetOld::LIST_CODE;
653 case LFUN_INSET_THEOREM:
654 code = InsetOld::THEOREM_CODE;
657 case LFUN_INSET_CAPTION:
658 code = InsetOld::CAPTION_CODE;
660 case LFUN_INSERT_NOTE:
661 code = InsetOld::NOTE_CODE;
663 case LFUN_INSERT_BOX:
664 code = InsetOld::BOX_CODE;
666 case LFUN_INSERT_BRANCH:
667 code = InsetOld::BRANCH_CODE;
668 if (buf->params().branchlist().empty())
671 case LFUN_INSERT_LABEL:
672 code = InsetOld::LABEL_CODE;
674 case LFUN_INSET_OPTARG:
675 code = InsetOld::OPTARG_CODE;
677 case LFUN_ENVIRONMENT_INSERT:
678 code = InsetOld::MINIPAGE_CODE;
680 case LFUN_INDEX_INSERT:
681 code = InsetOld::INDEX_CODE;
683 case LFUN_INDEX_PRINT:
684 code = InsetOld::INDEX_PRINT_CODE;
686 case LFUN_TOC_INSERT:
687 code = InsetOld::TOC_CODE;
691 code = InsetOld::URL_CODE;
694 // always allow this, since we will inset a raw quote
695 // if an inset is not allowed.
697 case LFUN_HYPHENATION:
698 case LFUN_LIGATURE_BREAK:
700 case LFUN_MENU_SEPARATOR:
702 case LFUN_END_OF_SENTENCE:
703 code = InsetOld::SPECIALCHAR_CODE;
705 case LFUN_SPACE_INSERT:
706 // slight hack: we know this is allowed in math mode
708 code = InsetOld::SPACE_CODE;
710 case LFUN_INSET_DIALOG_SHOW: {
711 LyXText * lt = view()->getLyXText();
712 InsetOld * inset = lt->getInset();
715 code = inset->lyxCode();
716 if (!(code == InsetOld::INCLUDE_CODE
717 || code == InsetOld::BIBTEX_CODE
718 || code == InsetOld::FLOAT_LIST_CODE
719 || code == InsetOld::TOC_CODE))
727 if (code != InsetOld::NO_CODE && tli && !tli->insetAllowed(code))
733 // A few general toggles
735 case LFUN_TOOLTIPS_TOGGLE:
736 flag.setOnOff(owner->getDialogs().tooltipsEnabled());
739 case LFUN_READ_ONLY_TOGGLE:
740 flag.setOnOff(buf->isReadonly());
743 flag.setOnOff(view()->getLyXText()->cursorPar()->params().startOfAppendix());
745 case LFUN_SWITCHBUFFER:
746 // toggle on the current buffer, but do not toggle off
747 // the other ones (is that a good idea?)
748 if (ev.argument == buf->fileName())
751 case LFUN_TRACK_CHANGES:
752 flag.setOnOff(buf->params().tracking_changes);
758 // the font related toggles
760 LyXFont const & font = view()->getLyXText()->real_current_font;
763 flag.setOnOff(font.emph() == LyXFont::ON);
766 flag.setOnOff(font.noun() == LyXFont::ON);
769 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
772 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
775 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
778 flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
784 string tc = mathcursor->getLastCode();
787 flag.setOnOff(tc == "mathbf");
790 flag.setOnOff(tc == "mathsf");
793 flag.setOnOff(tc == "mathcal");
796 flag.setOnOff(tc == "mathrm");
799 flag.setOnOff(tc == "mathtt");
802 flag.setOnOff(tc == "mathbb");
805 flag.setOnOff(tc == "mathnormal");
812 // this one is difficult to get right. As a half-baked
813 // solution, we consider only the first action of the sequence
814 if (ev.action == LFUN_SEQUENCE) {
815 // argument contains ';'-terminated commands
816 #warning LyXAction arguements not handled here.
817 flag = getStatus(FuncRequest(lyxaction.lookupFunc(token(ev.argument, ';', 0))));
826 bool ensureBufferClean(BufferView * bv)
828 Buffer & buf = *bv->buffer();
832 string const file = MakeDisplayPath(buf.fileName(), 30);
833 string text = bformat(_("The document %1$s has unsaved "
834 "changes.\n\nDo you want to save "
835 "the document?"), file);
836 int const ret = Alert::prompt(_("Save changed document?"),
837 text, 0, 1, _("&Save"),
841 bv->owner()->dispatch(FuncRequest(LFUN_MENUWRITE));
843 return buf.isClean();
849 void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
851 string argument = func.argument;
852 kb_action action = func.action;
854 lyxerr[Debug::ACTION] << "LyXFunc::dispatch: action[" << action
855 <<"] arg[" << argument << ']' << endl;
857 // we have not done anything wrong yet.
859 dispatch_buffer.erase();
861 #ifdef NEW_DISPATCHER
862 // We try do call the most specific dispatcher first:
863 // 1. the lockinginset's dispatch
864 // 2. the bufferview's dispatch
865 // 3. the lyxview's dispatch
868 selection_possible = false;
870 // We cannot use this function here
871 if (getStatus(func).disabled()) {
872 lyxerr[Debug::ACTION] << "LyXFunc::dispatch: "
873 << lyxaction.getActionName(action)
874 << " [" << action << "] is disabled at this location"
876 setErrorMessage(getStatusMessage());
877 goto exit_with_message;
880 if (view()->available())
881 view()->hideCursor();
886 buildCursor(cursor, *view());
887 if (cursor.dispatch(FuncRequest(func, view())) == DISPATCHED) {
888 lyxerr << "dispatched by Cursor::dispatch()\n";
889 goto exit_with_message;
895 if (view()->available() && view()->theLockingInset()) {
896 dispatch_result result;
897 if (action > 1 || (action == LFUN_UNKNOWN_ACTION &&
900 UpdatableInset * inset = view()->theLockingInset();
904 inset->getCursorPos(view(), inset_x, dummy_y);
906 if (action == LFUN_UNKNOWN_ACTION
907 && argument.empty()) {
908 argument = encoded_last_key;
911 // the insets can't try to handle this,
912 // a table cell in the dummy position will
913 // lock its insettext, the insettext will
914 // pass it the bufferview, and succeed,
915 // so it will stay not locked. Not good
916 // if we've just done LFUN_ESCAPE (which
917 // injects an LFUN_PARAGRAPH_UPDATE)
918 if (action == LFUN_PARAGRAPH_UPDATE) {
919 view()->dispatch(func);
920 goto exit_with_message;
923 // Undo/Redo is a bit tricky for insets.
924 if (action == LFUN_UNDO) {
926 goto exit_with_message;
929 if (action == LFUN_REDO) {
931 goto exit_with_message;
934 // Hand-over to inset's own dispatch:
935 result = inset->localDispatch(FuncRequest(view(), action, argument));
936 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
937 goto exit_with_message;
940 // If UNDISPATCHED, just soldier on
941 if (result == FINISHED) {
942 owner->clearMessage();
943 goto exit_with_message;
944 // We do not need special RTL handling here:
945 // FINISHED means that the cursor should be
946 // one position after the inset.
949 if (result == FINISHED_RIGHT) {
950 view()->text->cursorRight(view());
952 owner->clearMessage();
953 goto exit_with_message;
956 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;
976 if (result == FINISHED_DOWN) {
977 RowList::iterator const irow = view()->text->cursorIRow();
978 if (irow != view()->text->lastRow()) {
980 view()->text->setCursorFromCoordinates(
981 view()->text->cursor.x() + inset_x,
982 view()->text->cursor.y() -
985 view()->text->cursor.x_fix(view()->text->cursor.x());
987 view()->text->cursorDown(view());
990 view()->text->cursorRight(view());
993 owner->clearMessage();
994 goto exit_with_message;
997 #warning I am not sure this is still right, please have a look! (Jug 20020417)
998 // result == UNDISPATCHED
999 //setMessage(N_("Text mode"));
1001 case LFUN_UNKNOWN_ACTION:
1002 case LFUN_BREAKPARAGRAPH:
1003 case LFUN_BREAKLINE:
1004 view()->text->cursorRight(view());
1005 view()->switchKeyMap();
1006 owner->view_state_changed();
1009 if (!view()->text->cursorPar()->isRightToLeftPar(owner->buffer()->params())) {
1010 view()->text->cursorRight(view());
1012 owner->view_state_changed();
1014 goto exit_with_message;
1016 if (view()->text->cursorPar()->isRightToLeftPar(owner->buffer()->params())) {
1017 view()->text->cursorRight(view());
1019 owner->view_state_changed();
1021 goto exit_with_message;
1023 if (view()->text->cursorRow() != view()->text->lastRow())
1024 view()->text->cursorDown(view());
1026 view()->text->cursorRight(view());
1028 owner->view_state_changed();
1029 goto exit_with_message;
1039 if (!view()->available())
1041 // this function should be used always [asierra060396]
1042 UpdatableInset * tli = view()->theLockingInset();
1044 UpdatableInset * lock = tli->getLockingInset();
1047 view()->unlockInset(tli);
1048 view()->text->cursorRight(view());
1050 owner->view_state_changed();
1052 tli->unlockInsetInInset(view(), lock, true);
1055 // Tell the paragraph dialog that we changed paragraph
1056 dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
1061 case LFUN_WORDFINDFORWARD:
1062 case LFUN_WORDFINDBACKWARD: {
1063 static string last_search;
1064 string searched_string;
1066 if (!argument.empty()) {
1067 last_search = argument;
1068 searched_string = argument;
1070 searched_string = last_search;
1072 bool fw = (action == LFUN_WORDFINDFORWARD);
1073 if (!searched_string.empty())
1074 lyx::find::find(view(), searched_string, fw);
1079 if (view()->available() && !view()->theLockingInset())
1081 owner->message(keyseq.printOptions());
1084 // --- Misc -------------------------------------------
1085 case LFUN_EXEC_COMMAND:
1086 owner->focus_command_buffer();
1091 meta_fake_bit = key_modifier::none;
1092 if (view()->available())
1093 // cancel any selection
1094 dispatch(FuncRequest(LFUN_MARK_OFF));
1095 setMessage(N_("Cancel"));
1098 case LFUN_META_FAKE:
1099 meta_fake_bit = key_modifier::alt;
1100 setMessage(keyseq.print());
1103 case LFUN_READ_ONLY_TOGGLE:
1104 if (owner->buffer()->lyxvc().inUse())
1105 owner->buffer()->lyxvc().toggleReadOnly();
1107 owner->buffer()->setReadonly(
1108 !owner->buffer()->isReadonly());
1111 case LFUN_CENTER: // this is center and redraw.
1115 // --- Menus -----------------------------------------------
1117 menuNew(argument, false);
1120 case LFUN_MENUNEWTMPLT:
1121 menuNew(argument, true);
1124 case LFUN_CLOSEBUFFER:
1128 case LFUN_MENUWRITE:
1129 if (!owner->buffer()->isUnnamed()) {
1130 string const str = bformat(_("Saving document %1$s..."),
1131 MakeDisplayPath(owner->buffer()->fileName()));
1132 owner->message(str);
1133 MenuWrite(owner->buffer());
1134 owner->message(str + _(" done."));
1136 WriteAs(owner->buffer());
1140 WriteAs(owner->buffer(), argument);
1143 case LFUN_MENURELOAD: {
1144 string const file = MakeDisplayPath(view()->buffer()->fileName(), 20);
1145 string text = bformat(_("Any changes will be lost. Are you sure "
1146 "you want to revert to the saved version of the document %1$s?"), file);
1147 int const ret = Alert::prompt(_("Revert to saved document?"),
1148 text, 0, 1, _("&Revert"), _("&Cancel"));
1156 Exporter::Export(owner->buffer(), argument, true);
1157 view()->showErrorList(BufferFormat(*owner->buffer()));
1161 Exporter::Preview(owner->buffer(), argument);
1162 view()->showErrorList(BufferFormat(*owner->buffer()));
1165 case LFUN_BUILDPROG:
1166 Exporter::Export(owner->buffer(), "program", true);
1167 view()->showErrorList(_("Build"));
1170 case LFUN_RUNCHKTEX:
1171 owner->buffer()->runChktex();
1172 view()->showErrorList(_("ChkTeX"));
1176 if (argument == "custom")
1177 owner->getDialogs().showSendto();
1179 Exporter::Export(owner->buffer(), argument, false);
1180 view()->showErrorList(BufferFormat(*owner->buffer()));
1194 InsetCommandParams p("tableofcontents");
1195 string const data = InsetCommandMailer::params2string("toc", p);
1196 owner->getDialogs().show("toc", data, 0);
1212 case LFUN_FREEFONT_APPLY:
1213 apply_freefont(view());
1216 case LFUN_FREEFONT_UPDATE:
1217 update_and_apply_freefont(view(), argument);
1220 case LFUN_RECONFIGURE:
1221 Reconfigure(view());
1225 case LFUN_FLOATSOPERATE:
1226 if (argument == "openfoot")
1227 view()->allFloats(1,0);
1228 else if (argument == "closefoot")
1229 view()->allFloats(0,0);
1230 else if (argument == "openfig")
1231 view()->allFloats(1,1);
1232 else if (argument == "closefig")
1233 view()->allFloats(0,1);
1236 #ifdef WITH_WARNINGS
1237 //#warning Find another implementation here (or another lyxfunc)!
1240 case LFUN_HELP_OPEN:
1242 string const arg = argument;
1244 setErrorMessage(N_("Missing argument"));
1247 string const fname = i18nLibFileSearch("doc", arg, "lyx");
1248 if (fname.empty()) {
1249 lyxerr << "LyX: unable to find documentation file `"
1250 << arg << "'. Bad installation?" << endl;
1253 owner->message(bformat(_("Opening help file %1$s..."),
1254 MakeDisplayPath(fname)));
1255 view()->loadLyXFile(fname, false);
1259 // --- version control -------------------------------
1260 case LFUN_VC_REGISTER:
1262 if (!ensureBufferClean(view()))
1264 if (!owner->buffer()->lyxvc().inUse()) {
1265 owner->buffer()->lyxvc().registrer();
1271 case LFUN_VC_CHECKIN:
1273 if (!ensureBufferClean(view()))
1275 if (owner->buffer()->lyxvc().inUse()
1276 && !owner->buffer()->isReadonly()) {
1277 owner->buffer()->lyxvc().checkIn();
1283 case LFUN_VC_CHECKOUT:
1285 if (!ensureBufferClean(view()))
1287 if (owner->buffer()->lyxvc().inUse()
1288 && owner->buffer()->isReadonly()) {
1289 owner->buffer()->lyxvc().checkOut();
1295 case LFUN_VC_REVERT:
1297 owner->buffer()->lyxvc().revert();
1304 owner->buffer()->lyxvc().undoLast();
1309 // --- buffers ----------------------------------------
1311 case LFUN_SWITCHBUFFER:
1312 view()->buffer(bufferlist.getBuffer(argument));
1316 NewFile(view(), argument);
1319 case LFUN_FILE_OPEN:
1323 case LFUN_LAYOUT_TABULAR:
1324 if (view()->theLockingInset()) {
1325 if (view()->theLockingInset()->lyxCode()== InsetOld::TABULAR_CODE) {
1326 InsetTabular * inset = static_cast<InsetTabular *>
1327 (view()->theLockingInset());
1328 inset->openLayoutDialog(view());
1329 } else if (view()->theLockingInset()->
1330 getFirstLockingInsetOfType(InsetOld::TABULAR_CODE)!=0) {
1331 InsetTabular * inset = static_cast<InsetTabular *>(
1332 view()->theLockingInset()->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE));
1333 inset->openLayoutDialog(view());
1338 case LFUN_DROP_LAYOUTS_CHOICE:
1339 owner->getToolbar().openLayoutList();
1342 case LFUN_MENU_OPEN_BY_NAME:
1343 owner->getMenubar().openByName(argument);
1344 break; // RVDK_PATCH_5
1346 // --- lyxserver commands ----------------------------
1350 setMessage(owner->buffer()->fileName());
1351 lyxerr[Debug::INFO] << "FNAME["
1352 << owner->buffer()->fileName()
1358 dispatch_buffer = keyseq.print();
1359 lyxserver->notifyClient(dispatch_buffer);
1363 case LFUN_GOTOFILEROW:
1367 istringstream istr(argument.c_str());
1368 istr >> file_name >> row;
1369 if (prefixIs(file_name, getTmpDir())) {
1370 // Needed by inverse dvi search. If it is a file
1371 // in tmpdir, call the apropriated function
1372 view()->buffer(bufferlist.getBufferFromTmp(file_name));
1374 // Must replace extension of the file to be .lyx
1375 // and get full path
1376 string const s(ChangeExtension(file_name, ".lyx"));
1377 // Either change buffer or load the file
1378 if (bufferlist.exists(s)) {
1379 view()->buffer(bufferlist.getBuffer(s));
1381 view()->loadLyXFile(s);
1385 view()->setCursorFromRow(row);
1388 // see BufferView_pimpl::center()
1389 view()->updateScrollbar();
1393 case LFUN_GOTO_PARAGRAPH:
1395 istringstream istr(argument.c_str());
1399 ParIterator par = owner->buffer()->getParFromID(id);
1400 if (par == owner->buffer()->par_iterator_end()) {
1401 lyxerr[Debug::INFO] << "No matching paragraph found! ["
1402 << id << ']' << endl;
1405 lyxerr[Debug::INFO] << "Paragraph " << par->id()
1406 << " found." << endl;
1409 if (view()->theLockingInset())
1410 view()->unlockInset(view()->theLockingInset());
1411 if (par->inInset()) {
1412 FuncRequest cmd(view(), LFUN_INSET_EDIT, "left");
1413 par->inInset()->localDispatch(cmd);
1416 view()->getLyXText()->setCursor(par.pit(), 0);
1417 view()->switchKeyMap();
1418 owner->view_state_changed();
1421 // see BufferView_pimpl::center()
1422 view()->updateScrollbar();
1426 // --- insert characters ----------------------------------------
1428 // --- Mathed stuff. If we are here, there is no locked inset yet.
1429 case LFUN_MATH_EXTERN:
1430 case LFUN_MATH_NUMBER:
1431 case LFUN_MATH_NONUMBER:
1432 case LFUN_MATH_LIMITS:
1434 setErrorMessage(N_("This is only allowed in math mode!"));
1438 // passthrough hat and underscore outside mathed:
1439 case LFUN_SUBSCRIPT:
1440 dispatch(FuncRequest(view(), LFUN_SELFINSERT, "_"));
1442 case LFUN_SUPERSCRIPT:
1443 dispatch(FuncRequest(view(), LFUN_SELFINSERT, "^"));
1446 case LFUN_DIALOG_SHOW: {
1447 string const name = func.getArg(0);
1448 string data = trim(func.argument.substr(name.size()));
1450 if (name == "character") {
1451 data = freefont2string();
1453 owner->getDialogs().show("character", data);
1454 } else if (name == "document")
1455 owner->getDialogs().showDocument();
1456 else if (name == "findreplace")
1457 owner->getDialogs().showSearch();
1458 else if (name == "forks")
1459 owner->getDialogs().showForks();
1460 else if (name == "preamble")
1461 owner->getDialogs().showPreamble();
1462 else if (name == "preferences")
1463 owner->getDialogs().showPreferences();
1464 else if (name == "print")
1465 owner->getDialogs().showPrint();
1466 else if (name == "spellchecker")
1467 owner->getDialogs().showSpellchecker();
1469 owner->getDialogs().show(name, data);
1473 case LFUN_DIALOG_SHOW_NEW_INSET: {
1474 string const & name = argument;
1476 if (name == "bibitem" ||
1478 name == "include" ||
1483 InsetCommandParams p(name);
1484 data = InsetCommandMailer::params2string(name, p);
1485 } else if (name == "citation") {
1486 InsetCommandParams p("cite");
1487 data = InsetCommandMailer::params2string(name, p);
1489 owner->getDialogs().show(name, data, 0);
1493 case LFUN_DIALOG_SHOW_NEXT_INSET: {
1497 case LFUN_INSET_DIALOG_SHOW: {
1498 LyXText * lt = view()->getLyXText();
1499 InsetOld * inset = lt->getInset();
1501 FuncRequest cmd(view(), LFUN_INSET_DIALOG_SHOW);
1502 inset->localDispatch(cmd);
1507 case LFUN_DIALOG_UPDATE: {
1508 string const & name = argument;
1509 // Can only update a dialog connected to an existing inset
1510 InsetBase * inset = owner->getDialogs().getOpenInset(name);
1512 FuncRequest fr(view(), LFUN_INSET_DIALOG_UPDATE,
1514 inset->localDispatch(fr);
1515 } else if (name == "paragraph") {
1516 dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
1521 case LFUN_DIALOG_HIDE:
1522 Dialogs::hide(argument, 0);
1525 case LFUN_DIALOG_DISCONNECT_INSET:
1526 owner->getDialogs().disconnect(argument);
1529 case LFUN_CHILDOPEN:
1531 string const filename =
1532 MakeAbsPath(argument, owner->buffer()->filePath());
1533 setMessage(N_("Opening child document ") +
1534 MakeDisplayPath(filename) + "...");
1535 view()->savePosition(0);
1536 if (bufferlist.exists(filename))
1537 view()->buffer(bufferlist.getBuffer(filename));
1539 view()->loadLyXFile(filename);
1543 case LFUN_TOGGLECURSORFOLLOW:
1544 lyxrc.cursor_follows_scrollbar = !lyxrc.cursor_follows_scrollbar;
1548 owner->getIntl().KeyMapOn(false);
1551 case LFUN_KMAP_PRIM:
1552 owner->getIntl().KeyMapPrim();
1556 owner->getIntl().KeyMapSec();
1559 case LFUN_KMAP_TOGGLE:
1560 owner->getIntl().ToggleKeyMap();
1565 // argument contains ';'-terminated commands
1566 while (!argument.empty()) {
1568 argument = split(argument, first, ';');
1569 dispatch(lyxaction.lookupFunc(first));
1574 case LFUN_SAVEPREFERENCES:
1576 Path p(user_lyxdir());
1577 lyxrc.write("preferences");
1581 case LFUN_SCREEN_FONT_UPDATE:
1583 // handle the screen font changes.
1584 lyxrc.set_font_norm_type();
1585 lyx_gui::update_fonts();
1586 // We also need to empty the textcache so that
1587 // the buffer will be formatted correctly after
1590 // Of course we should only do the resize and the textcache.clear
1591 // if values really changed...but not very important right now. (Lgb)
1592 // All visible buffers will need resize
1598 case LFUN_SET_COLOR:
1601 string const x11_name = split(argument, lyx_name, ' ');
1602 if (lyx_name.empty() || x11_name.empty()) {
1603 setErrorMessage(N_("Syntax: set-color <lyx_name>"
1608 bool const graphicsbg_changed =
1609 (lyx_name == lcolor.getLyXName(LColor::graphicsbg) &&
1610 x11_name != lcolor.getX11Name(LColor::graphicsbg));
1612 if (!lcolor.setColor(lyx_name, x11_name)) {
1614 bformat(_("Set-color \"%1$s\" failed "
1615 "- color is undefined or "
1616 "may not be redefined"), lyx_name));
1620 lyx_gui::update_color(lcolor.getFromLyXName(lyx_name));
1622 if (graphicsbg_changed) {
1623 #ifdef WITH_WARNINGS
1624 #warning FIXME!! The graphics cache no longer has a changeDisplay method.
1627 lyx::graphics::GCache & gc =
1628 lyx::graphics::GCache::get();
1629 gc.changeDisplay(true);
1638 owner->message(argument);
1641 case LFUN_FORKS_KILL:
1643 if (!isStrInt(argument))
1646 pid_t const pid = strToInt(argument);
1647 ForkedcallsController & fcc = ForkedcallsController::get();
1652 case LFUN_TOOLTIPS_TOGGLE:
1653 owner->getDialogs().toggleTooltips();
1656 case LFUN_EXTERNAL_EDIT: {
1657 InsetExternal().localDispatch(FuncRequest(view(), action, argument));
1662 // Then if it was none of the above
1663 // Trying the BufferView::pimpl dispatch:
1664 if (!view()->dispatch(func))
1665 lyxerr << "A truly unknown func ["
1666 << lyxaction.getActionName(func.action) << "]!"
1673 view()->owner()->updateLayoutChoice();
1675 if (view()->available()) {
1676 if (view()->fitCursor()) {
1677 //lyxerr << "LyXFunc->fitCursor->update" << endl;
1681 // If we executed a mutating lfun, mark the buffer as dirty
1682 if (!getStatus(func).disabled()
1683 && !lyxaction.funcHasFlag(func.action, LyXAction::NoBuffer)
1684 && !lyxaction.funcHasFlag(func.action, LyXAction::ReadOnly))
1685 view()->buffer()->markDirty();
1688 sendDispatchMessage(getMessage(), func, verbose);
1692 void LyXFunc::sendDispatchMessage(string const & msg,
1693 FuncRequest const & func, bool verbose)
1695 owner->updateMenubar();
1696 owner->updateToolbar();
1698 if (func.action == LFUN_SELFINSERT || !verbose) {
1699 lyxerr[Debug::ACTION] << "dispatch msg is " << msg << endl;
1701 owner->message(msg);
1705 string dispatch_msg = msg;
1706 if (!dispatch_msg.empty())
1707 dispatch_msg += ' ';
1709 string comname = lyxaction.getActionName(func.action);
1711 bool argsadded = false;
1713 if (!func.argument.empty()) {
1714 if (func.action != LFUN_UNKNOWN_ACTION) {
1715 comname += ' ' + func.argument;
1720 string const shortcuts = toplevel_keymap->findbinding(func);
1722 if (!shortcuts.empty()) {
1723 comname += ": " + shortcuts;
1724 } else if (!argsadded && !func.argument.empty()) {
1725 comname += ' ' + func.argument;
1728 if (!comname.empty()) {
1729 comname = rtrim(comname);
1730 dispatch_msg += '(' + comname + ')';
1733 lyxerr[Debug::ACTION] << "verbose dispatch msg " << dispatch_msg << endl;
1734 if (!dispatch_msg.empty())
1735 owner->message(dispatch_msg);
1739 void LyXFunc::setupLocalKeymap()
1741 keyseq.stdmap = keyseq.curmap = toplevel_keymap.get();
1742 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap.get();
1746 void LyXFunc::menuNew(string const & name, bool fromTemplate)
1748 string initpath = lyxrc.document_path;
1749 string filename(name);
1751 if (view()->available()) {
1752 string const trypath = owner->buffer()->filePath();
1753 // If directory is writeable, use this as default.
1754 if (IsDirWriteable(trypath))
1758 static int newfile_number;
1760 if (filename.empty()) {
1761 filename = AddName(lyxrc.document_path,
1762 "newfile" + tostr(++newfile_number) + ".lyx");
1763 FileInfo fi(filename);
1764 while (bufferlist.exists(filename) || fi.readable()) {
1766 filename = AddName(lyxrc.document_path,
1767 "newfile" + tostr(newfile_number) +
1769 fi.newFile(filename);
1773 // The template stuff
1776 FileDialog fileDlg(_("Select template file"),
1777 LFUN_SELECT_FILE_SYNC,
1778 make_pair(string(_("Documents|#o#O")),
1779 string(lyxrc.document_path)),
1780 make_pair(string(_("Templates|#T#t")),
1781 string(lyxrc.template_path)));
1783 FileDialog::Result result =
1784 fileDlg.open(lyxrc.template_path,
1785 _("*.lyx| LyX Documents (*.lyx)"));
1787 if (result.first == FileDialog::Later)
1790 string const fname = result.second;
1797 view()->newFile(filename, templname, !name.empty());
1801 void LyXFunc::open(string const & fname)
1803 string initpath = lyxrc.document_path;
1805 if (view()->available()) {
1806 string const trypath = owner->buffer()->filePath();
1807 // If directory is writeable, use this as default.
1808 if (IsDirWriteable(trypath))
1814 if (fname.empty()) {
1815 FileDialog fileDlg(_("Select document to open"),
1817 make_pair(string(_("Documents|#o#O")),
1818 string(lyxrc.document_path)),
1819 make_pair(string(_("Examples|#E#e")),
1820 string(AddPath(system_lyxdir(), "examples"))));
1822 FileDialog::Result result =
1823 fileDlg.open(initpath,
1824 _("*.lyx| LyX Documents (*.lyx)"));
1826 if (result.first == FileDialog::Later)
1829 filename = result.second;
1831 // check selected filename
1832 if (filename.empty()) {
1833 owner->message(_("Canceled."));
1839 // get absolute path of file and add ".lyx" to the filename if
1841 string const fullpath = FileSearch(string(), filename, "lyx");
1842 if (!fullpath.empty()) {
1843 filename = fullpath;
1846 string const disp_fn(MakeDisplayPath(filename));
1848 // if the file doesn't exist, let the user create one
1849 FileInfo const f(filename, true);
1851 // the user specifically chose this name. Believe them.
1852 view()->newFile(filename, "", true);
1856 owner->message(bformat(_("Opening document %1$s..."), disp_fn));
1859 if (view()->loadLyXFile(filename)) {
1860 str2 = bformat(_("Document %1$s opened."), disp_fn);
1862 str2 = bformat(_("Could not open document %1$s"), disp_fn);
1864 owner->message(str2);
1868 void LyXFunc::doImport(string const & argument)
1871 string filename = split(argument, format, ' ');
1873 lyxerr[Debug::INFO] << "LyXFunc::doImport: " << format
1874 << " file: " << filename << endl;
1876 // need user interaction
1877 if (filename.empty()) {
1878 string initpath = lyxrc.document_path;
1880 if (view()->available()) {
1881 string const trypath = owner->buffer()->filePath();
1882 // If directory is writeable, use this as default.
1883 if (IsDirWriteable(trypath))
1887 string const text = bformat(_("Select %1$s file to import"),
1888 formats.prettyName(format));
1890 FileDialog fileDlg(text,
1892 make_pair(string(_("Documents|#o#O")),
1893 string(lyxrc.document_path)),
1894 make_pair(string(_("Examples|#E#e")),
1895 string(AddPath(system_lyxdir(), "examples"))));
1897 string const extension = "*." + formats.extension(format)
1898 + "| " + formats.prettyName(format)
1899 + " (*." + formats.extension(format) + ')';
1901 FileDialog::Result result = fileDlg.open(initpath,
1904 if (result.first == FileDialog::Later)
1907 filename = result.second;
1909 // check selected filename
1910 if (filename.empty())
1911 owner->message(_("Canceled."));
1914 if (filename.empty())
1917 // get absolute path of file
1918 filename = MakeAbsPath(filename);
1920 string const lyxfile = ChangeExtension(filename, ".lyx");
1922 // Check if the document already is open
1923 if (lyx_gui::use_gui && bufferlist.exists(lyxfile)) {
1924 if (!bufferlist.close(bufferlist.getBuffer(lyxfile), true)) {
1925 owner->message(_("Canceled."));
1930 // if the file exists already, and we didn't do
1931 // -i lyx thefile.lyx, warn
1932 if (FileInfo(lyxfile, true).exist() && filename != lyxfile) {
1933 string const file = MakeDisplayPath(lyxfile, 30);
1935 string text = bformat(_("The document %1$s already exists.\n\n"
1936 "Do you want to over-write that document?"), file);
1937 int const ret = Alert::prompt(_("Over-write document?"),
1938 text, 0, 1, _("&Over-write"), _("&Cancel"));
1941 owner->message(_("Canceled."));
1946 Importer::Import(owner, filename, format);
1950 void LyXFunc::closeBuffer()
1952 if (bufferlist.close(owner->buffer(), true) && !quitting) {
1953 if (bufferlist.empty()) {
1954 // need this otherwise SEGV may occur while
1955 // trying to set variables that don't exist
1956 // since there's no current buffer
1957 owner->getDialogs().hideBufferDependent();
1959 view()->buffer(bufferlist.first());
1965 // Each "owner" should have it's own message method. lyxview and
1966 // the minibuffer would use the minibuffer, but lyxserver would
1967 // send an ERROR signal to its client. Alejandro 970603
1968 // This func is bit problematic when it comes to NLS, to make the
1969 // lyx servers client be language indepenent we must not translate
1970 // strings sent to this func.
1971 void LyXFunc::setErrorMessage(string const & m) const
1973 dispatch_buffer = m;
1978 void LyXFunc::setMessage(string const & m) const
1980 dispatch_buffer = m;
1984 void LyXFunc::setStatusMessage(string const & m) const
1990 string const LyXFunc::view_status_message()
1992 // When meta-fake key is pressed, show the key sequence so far + "M-".
1994 return keyseq.print() + "M-";
1997 // Else, when a non-complete key sequence is pressed,
1998 // show the available options.
1999 if (keyseq.length() > 0 && !keyseq.deleted()) {
2000 return keyseq.printOptions();
2003 if (!view()->available())
2004 return _("Welcome to LyX!");
2006 return currentState(view());
2010 BufferView * LyXFunc::view() const
2012 BOOST_ASSERT(owner);
2013 return owner->view().get();
2017 bool LyXFunc::wasMetaKey() const
2019 return (meta_fake_bit != key_modifier::none);