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"
34 #include "funcrequest.h"
38 #include "iterators.h"
42 #include "LyXAction.h"
46 #include "lyxserver.h"
48 #include "paragraph.h"
49 #include "ParagraphParameters.h"
50 #include "TextCache.h"
51 #include "undo_funcs.h"
53 #include "insets/insetcommand.h"
54 #include "insets/insetexternal.h"
55 #include "insets/insettabular.h"
57 #include "mathed/math_cursor.h"
59 #include "frontends/Alert.h"
60 #include "frontends/Dialogs.h"
61 #include "frontends/FileDialog.h"
62 #include "frontends/lyx_gui.h"
63 #include "frontends/LyXKeySym.h"
64 #include "frontends/LyXView.h"
65 #include "frontends/Menubar.h"
66 #include "frontends/Toolbar.h"
68 #include "support/FileInfo.h"
69 #include "support/filetools.h"
70 #include "support/forkedcontr.h"
71 #include "support/path.h"
72 #include "support/path_defines.h"
73 #include "support/tostr.h"
75 #include "support/std_sstream.h"
77 using bv_funcs::apply_freefont;
78 using bv_funcs::changeDepth;
79 using bv_funcs::currentState;
80 using bv_funcs::DEC_DEPTH;
81 using bv_funcs::freefont2string;
82 using bv_funcs::INC_DEPTH;
83 using bv_funcs::update_and_apply_freefont;
85 using lyx::support::AddName;
86 using lyx::support::AddPath;
87 using lyx::support::bformat;
88 using lyx::support::ChangeExtension;
89 using lyx::support::FileInfo;
90 using lyx::support::FileSearch;
91 using lyx::support::ForkedcallsController;
92 using lyx::support::i18nLibFileSearch;
93 using lyx::support::IsDirWriteable;
94 using lyx::support::IsFileReadable;
95 using lyx::support::isStrInt;
96 using lyx::support::MakeAbsPath;
97 using lyx::support::MakeDisplayPath;
98 using lyx::support::Path;
99 using lyx::support::rtrim;
100 using lyx::support::split;
101 using lyx::support::strToInt;
102 using lyx::support::strToUnsignedInt;
103 using lyx::support::system_lyxdir;
104 using lyx::support::token;
105 using lyx::support::trim;
106 using lyx::support::user_lyxdir;
109 using std::make_pair;
111 using std::istringstream;
114 extern BufferList bufferlist;
115 extern LyXServer * lyxserver;
116 extern bool selection_possible;
118 extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
121 extern tex_accent_struct get_accent(kb_action action);
123 extern void ShowLatexLog();
126 LyXFunc::LyXFunc(LyXView * o)
129 keyseq(toplevel_keymap.get(), toplevel_keymap.get()),
130 cancel_meta_seq(toplevel_keymap.get(), toplevel_keymap.get()),
131 meta_fake_bit(key_modifier::none)
136 void LyXFunc::moveCursorUpdate()
138 LyXText * lt = view()->text;
139 if (lt->selection.mark())
142 view()->switchKeyMap();
146 void LyXFunc::handleKeyFunc(kb_action action)
148 char c = encoded_last_key;
150 if (keyseq.length()) {
154 owner->getIntl().getTransManager()
155 .deadkey(c, get_accent(action).accent, view()->getLyXText());
156 // Need to clear, in case the minibuffer calls these
159 // copied verbatim from do_accent_char
161 view()->getLyXText()->selection.cursor = view()->getLyXText()->cursor;
165 void LyXFunc::processKeySym(LyXKeySymPtr keysym,
166 key_modifier::state state)
170 if (lyxerr.debugging(Debug::KEY)) {
171 lyxerr << "KeySym is "
172 << keysym->getSymbolName()
176 // Do nothing if we have nothing (JMarc)
177 if (!keysym->isOK()) {
178 lyxerr[Debug::KEY] << "Empty kbd action (probably composing)"
183 if (keysym->isModifier()) {
184 lyxerr[Debug::KEY] << "isModifier true" << endl;
188 Encoding const * encoding = view()->getEncoding();
190 encoded_last_key = keysym->getISOEncoded(encoding ? encoding->Name() : "");
192 // Do a one-deep top-level lookup for
193 // cancel and meta-fake keys. RVDK_PATCH_5
194 cancel_meta_seq.reset();
196 int action = cancel_meta_seq.addkey(keysym, state);
197 lyxerr[Debug::KEY] << "action first set to [" << action << ']' << endl;
199 // When not cancel or meta-fake, do the normal lookup.
200 // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
201 // Mostly, meta_fake_bit = key_modifier::none. RVDK_PATCH_5.
202 if ((action != LFUN_CANCEL) && (action != LFUN_META_FAKE)) {
203 // remove Caps Lock and Mod2 as a modifiers
204 action = keyseq.addkey(keysym, (state | meta_fake_bit));
205 lyxerr[Debug::KEY] << "action now set to ["
206 << action << ']' << endl;
209 // Dont remove this unless you know what you are doing.
210 meta_fake_bit = key_modifier::none;
212 // can this happen now ?
213 if (action == LFUN_NOACTION) {
214 action = LFUN_PREFIX;
217 if (lyxerr.debugging(Debug::KEY)) {
218 lyxerr << "Key [action="
220 << keyseq.print() << ']'
224 // already here we know if it any point in going further
225 // why not return already here if action == -1 and
226 // num_bytes == 0? (Lgb)
228 if (keyseq.length() > 1) {
229 owner->message(keyseq.print());
233 // Maybe user can only reach the key via holding down shift.
234 // Let's see. But only if shift is the only modifier
235 if (action == LFUN_UNKNOWN_ACTION && state == key_modifier::shift) {
236 lyxerr[Debug::KEY] << "Trying without shift" << endl;
237 action = keyseq.addkey(keysym, key_modifier::none);
238 lyxerr[Debug::KEY] << "Action now " << action << endl;
241 if (action == LFUN_UNKNOWN_ACTION) {
242 // Hmm, we didn't match any of the keysequences. See
243 // if it's normal insertable text not already covered
245 if (keysym->isText() && keyseq.length() == 1) {
246 lyxerr[Debug::KEY] << "isText() is true, inserting." << endl;
247 action = LFUN_SELFINSERT;
249 lyxerr[Debug::KEY] << "Unknown, !isText() - giving up" << endl;
250 owner->message(_("Unknown function."));
255 if (action == LFUN_SELFINSERT) {
256 if (encoded_last_key != 0) {
258 arg += encoded_last_key;
260 dispatch(FuncRequest(view(), LFUN_SELFINSERT, arg));
262 lyxerr[Debug::KEY] << "SelfInsert arg[`"
263 << argument << "']" << endl;
271 FuncStatus LyXFunc::getStatus(int ac) const
273 return getStatus(lyxaction.retrieveActionArg(ac));
277 FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
280 Buffer * buf = owner->buffer();
282 if (ev.action == LFUN_NOACTION) {
283 setStatusMessage(N_("Nothing to do"));
284 return flag.disabled(true);
288 case LFUN_UNKNOWN_ACTION:
289 #ifndef HAVE_LIBAIKSAURUS
290 case LFUN_THESAURUS_ENTRY:
295 flag |= lyx_gui::getStatus(ev);
298 if (flag.unknown()) {
299 setStatusMessage(N_("Unknown action"));
303 // the default error message if we disable the command
304 setStatusMessage(N_("Command disabled"));
306 // Check whether we need a buffer
307 if (!lyxaction.funcHasFlag(ev.action, LyXAction::NoBuffer)) {
308 // Yes we need a buffer, do we have one?
311 // Can we use a readonly buffer?
312 if (buf->isReadonly() &&
313 !lyxaction.funcHasFlag(ev.action,
314 LyXAction::ReadOnly)) {
316 setStatusMessage(N_("Document is read-only"));
321 setStatusMessage(N_("Command not allowed with"
322 "out any document open"));
323 return flag.disabled(true);
327 UpdatableInset * tli = view()->theLockingInset();
329 // I would really like to avoid having this switch and rather try to
330 // encode this in the function itself.
331 bool disable = false;
334 disable = ev.argument != "custom"
335 && !Exporter::IsExportable(*buf, ev.argument);
338 disable = buf->undostack().empty();
341 disable = buf->redostack().empty();
346 UpdatableInset * in = tli;
347 if (in->lyxCode() != InsetOld::TABULAR_CODE) {
348 in = tli->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE);
350 if (in && static_cast<InsetTabular*>(in)->hasSelection()) {
355 disable = !mathcursor && !view()->getLyXText()->selection.set();
358 disable = !buf->isLatex() || lyxrc.chktex_command == "none";
361 disable = !Exporter::IsExportable(*buf, "program");
364 case LFUN_LAYOUT_TABULAR:
366 || (tli->lyxCode() != InsetOld::TABULAR_CODE
367 && !tli->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE));
371 disable = !changeDepth(view(), view()->getLyXText(), DEC_DEPTH, true);
374 case LFUN_DEPTH_PLUS:
375 disable = !changeDepth(view(), view()->getLyXText(), INC_DEPTH, true);
379 case LFUN_LAYOUT_PARAGRAPH: {
380 InsetOld * inset = view()->getLyXText()->cursor.par()->inInset();
381 disable = inset && inset->forceDefaultParagraphs(inset);
385 case LFUN_INSET_OPTARG:
386 disable = (view()->getLyXText()->cursor.par()->layout()->optionalargs == 0);
389 case LFUN_TABULAR_FEATURE:
392 // FIXME: check temporarily disabled
394 char align = mathcursor->valign();
399 if (ev.argument.empty()) {
403 if (!contains("tcb", ev.argument[0])) {
407 flag.setOnOff(ev.argument[0] == align);
411 char align = mathcursor->halign();
416 if (ev.argument.empty()) {
420 if (!contains("lcr", ev.argument[0])) {
424 flag.setOnOff(ev.argument[0] == align);
427 disable = !mathcursor->halign();
433 //ret.disabled(true);
434 if (tli->lyxCode() == InsetOld::TABULAR_CODE) {
435 ret = static_cast<InsetTabular *>(tli)
436 ->getStatus(ev.argument);
439 } else if (tli->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE)) {
440 ret = static_cast<InsetTabular *>
441 (tli->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE))
442 ->getStatus(ev.argument);
449 static InsetTabular inset(*owner->buffer(), 1, 1);
453 ret = inset.getStatus(ev.argument);
454 if (ret.onoff(true) || ret.onoff(false))
455 flag.setOnOff(false);
459 case LFUN_VC_REGISTER:
460 disable = buf->lyxvc().inUse();
462 case LFUN_VC_CHECKIN:
463 disable = !buf->lyxvc().inUse() || buf->isReadonly();
465 case LFUN_VC_CHECKOUT:
466 disable = !buf->lyxvc().inUse() || !buf->isReadonly();
470 disable = !buf->lyxvc().inUse();
472 case LFUN_MENURELOAD:
473 disable = buf->isUnnamed() || buf->isClean();
475 case LFUN_BOOKMARK_GOTO:
477 isSavedPosition(strToUnsignedInt(ev.argument));
479 case LFUN_MERGE_CHANGES:
480 case LFUN_ACCEPT_CHANGE:
481 case LFUN_REJECT_CHANGE:
482 case LFUN_ACCEPT_ALL_CHANGES:
483 case LFUN_REJECT_ALL_CHANGES:
484 disable = !buf->params().tracking_changes;
486 case LFUN_INSET_TOGGLE: {
487 LyXText * lt = view()->getLyXText();
488 disable = !(isEditableInset(lt->getInset())
490 && lt->inset_owner->owner()
491 && lt->inset_owner->owner()->isOpen()));
495 case LFUN_INSET_SETTINGS: {
497 UpdatableInset * inset = view()->theLockingInset();
502 // get the innermost inset
503 inset = inset->getLockingInset();
505 // jump back to owner if an InsetText, so
506 // we get back to the InsetTabular or whatever
507 if (inset->lyxCode() == InsetOld::TEXT_CODE)
508 inset = inset->owner();
510 InsetOld::Code code = inset->lyxCode();
512 case InsetOld::TABULAR_CODE:
513 disable = ev.argument != "tabular";
515 case InsetOld::ERT_CODE:
516 disable = ev.argument != "ert";
518 case InsetOld::FLOAT_CODE:
519 disable = ev.argument != "float";
521 case InsetOld::MINIPAGE_CODE:
522 disable = ev.argument != "minipage";
524 case InsetOld::WRAP_CODE:
525 disable = ev.argument != "wrap";
527 case InsetOld::NOTE_CODE:
528 disable = ev.argument != "note";
530 case InsetOld::BRANCH_CODE:
531 disable = ev.argument != "branch";
539 case LFUN_MATH_MUTATE:
541 //flag.setOnOff(mathcursor->formula()->hullType() == ev.argument);
542 flag.setOnOff(false);
547 // we just need to be in math mode to enable that
549 case LFUN_MATH_SPACE:
550 case LFUN_MATH_LIMITS:
551 case LFUN_MATH_NONUMBER:
552 case LFUN_MATH_NUMBER:
553 case LFUN_MATH_EXTERN:
554 disable = !mathcursor;
557 case LFUN_DIALOG_SHOW: {
558 string const name = ev.getArg(0);
560 disable = !(name == "aboutlyx" ||
563 name == "preferences" ||
568 if (name == "print") {
569 disable = !Exporter::IsExportable(*buf, "dvi") ||
570 lyxrc.print_command == "none";
571 } else if (name == "character") {
572 UpdatableInset * tli = view()->theLockingInset();
573 disable = tli && tli->lyxCode() == InsetOld::ERT_CODE;
574 } else if (name == "vclog") {
575 disable = !buf->lyxvc().inUse();
576 } else if (name == "latexlog") {
577 disable = !IsFileReadable(buf->getLogName().second);
586 // the functions which insert insets
587 InsetOld::Code code = InsetOld::NO_CODE;
589 case LFUN_DIALOG_SHOW_NEW_INSET:
590 if (ev.argument == "bibitem")
591 code = InsetOld::BIBITEM_CODE;
592 else if (ev.argument == "bibtex")
593 code = InsetOld::BIBTEX_CODE;
594 else if (ev.argument == "citation")
595 code = InsetOld::CITE_CODE;
596 else if (ev.argument == "ert")
597 code = InsetOld::ERT_CODE;
598 else if (ev.argument == "external")
599 code = InsetOld::EXTERNAL_CODE;
600 else if (ev.argument == "float")
601 code = InsetOld::FLOAT_CODE;
602 else if (ev.argument == "graphics")
603 code = InsetOld::GRAPHICS_CODE;
604 else if (ev.argument == "include")
605 code = InsetOld::INCLUDE_CODE;
606 else if (ev.argument == "index")
607 code = InsetOld::INDEX_CODE;
608 else if (ev.argument == "label")
609 code = InsetOld::LABEL_CODE;
610 else if (ev.argument == "minipage")
611 code = InsetOld::MINIPAGE_CODE;
612 else if (ev.argument == "ref")
613 code = InsetOld::REF_CODE;
614 else if (ev.argument == "toc")
615 code = InsetOld::TOC_CODE;
616 else if (ev.argument == "url")
617 code = InsetOld::URL_CODE;
618 else if (ev.argument == "wrap")
619 code = InsetOld::WRAP_CODE;
623 code = InsetOld::ERT_CODE;
625 case LFUN_INSET_FOOTNOTE:
626 code = InsetOld::FOOT_CODE;
628 case LFUN_TABULAR_INSERT:
629 code = InsetOld::TABULAR_CODE;
631 case LFUN_INSET_MARGINAL:
632 code = InsetOld::MARGIN_CODE;
634 case LFUN_INSET_MINIPAGE:
635 code = InsetOld::MINIPAGE_CODE;
637 case LFUN_INSET_FLOAT:
638 case LFUN_INSET_WIDE_FLOAT:
639 code = InsetOld::FLOAT_CODE;
641 case LFUN_INSET_WRAP:
642 code = InsetOld::WRAP_CODE;
644 case LFUN_FLOAT_LIST:
645 code = InsetOld::FLOAT_LIST_CODE;
648 case LFUN_INSET_LIST:
649 code = InsetOld::LIST_CODE;
651 case LFUN_INSET_THEOREM:
652 code = InsetOld::THEOREM_CODE;
655 case LFUN_INSET_CAPTION:
656 code = InsetOld::CAPTION_CODE;
658 case LFUN_INSERT_NOTE:
659 code = InsetOld::NOTE_CODE;
661 case LFUN_INSERT_BRANCH:
662 code = InsetOld::BRANCH_CODE;
663 if (buf->params().branchlist().empty())
666 case LFUN_INSERT_LABEL:
667 code = InsetOld::LABEL_CODE;
669 case LFUN_INSET_OPTARG:
670 code = InsetOld::OPTARG_CODE;
672 case LFUN_ENVIRONMENT_INSERT:
673 code = InsetOld::MINIPAGE_CODE;
675 case LFUN_INDEX_INSERT:
676 code = InsetOld::INDEX_CODE;
678 case LFUN_INDEX_PRINT:
679 code = InsetOld::INDEX_PRINT_CODE;
681 case LFUN_TOC_INSERT:
682 code = InsetOld::TOC_CODE;
686 code = InsetOld::URL_CODE;
689 // always allow this, since we will inset a raw quote
690 // if an inset is not allowed.
692 case LFUN_HYPHENATION:
693 case LFUN_LIGATURE_BREAK:
695 case LFUN_MENU_SEPARATOR:
697 case LFUN_END_OF_SENTENCE:
698 code = InsetOld::SPECIALCHAR_CODE;
700 case LFUN_SPACE_INSERT:
701 // slight hack: we know this is allowed in math mode
703 code = InsetOld::SPACE_CODE;
705 case LFUN_INSET_DIALOG_SHOW: {
706 LyXText * lt = view()->getLyXText();
707 InsetOld * inset = lt->getInset();
710 code = inset->lyxCode();
711 if (!(code == InsetOld::INCLUDE_CODE
712 || code == InsetOld::BIBTEX_CODE
713 || code == InsetOld::FLOAT_LIST_CODE
714 || code == InsetOld::TOC_CODE))
722 if (code != InsetOld::NO_CODE && tli && !tli->insetAllowed(code))
728 // A few general toggles
730 case LFUN_TOOLTIPS_TOGGLE:
731 flag.setOnOff(owner->getDialogs().tooltipsEnabled());
734 case LFUN_READ_ONLY_TOGGLE:
735 flag.setOnOff(buf->isReadonly());
738 flag.setOnOff(view()->getLyXText()->cursor.par()->params().startOfAppendix());
740 case LFUN_SWITCHBUFFER:
741 // toggle on the current buffer, but do not toggle off
742 // the other ones (is that a good idea?)
743 if (ev.argument == buf->fileName())
746 case LFUN_TRACK_CHANGES:
747 flag.setOnOff(buf->params().tracking_changes);
753 // the font related toggles
755 LyXFont const & font = view()->getLyXText()->real_current_font;
758 flag.setOnOff(font.emph() == LyXFont::ON);
761 flag.setOnOff(font.noun() == LyXFont::ON);
764 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
767 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
770 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
773 flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
779 string tc = mathcursor->getLastCode();
782 flag.setOnOff(tc == "mathbf");
785 flag.setOnOff(tc == "mathsf");
788 flag.setOnOff(tc == "mathcal");
791 flag.setOnOff(tc == "mathrm");
794 flag.setOnOff(tc == "mathtt");
797 flag.setOnOff(tc == "mathbb");
800 flag.setOnOff(tc == "mathnormal");
807 // this one is difficult to get right. As a half-baked
808 // solution, we consider only the first action of the sequence
809 if (ev.action == LFUN_SEQUENCE) {
810 // argument contains ';'-terminated commands
811 flag = getStatus(lyxaction.LookupFunc(token(ev.argument, ';', 0)));
818 void LyXFunc::dispatch(string const & s, bool verbose)
820 int const action = lyxaction.LookupFunc(s);
822 if (action == LFUN_UNKNOWN_ACTION) {
823 owner->message(bformat(_("Unknown function (%1$s)"), s));
827 dispatch(action, verbose);
831 void LyXFunc::dispatch(int ac, bool verbose)
833 dispatch(lyxaction.retrieveActionArg(ac), verbose);
837 bool ensureBufferClean(BufferView * bv) {
839 Buffer & buf = *bv->buffer();
843 string const file = MakeDisplayPath(buf.fileName(), 30);
844 string text = bformat(_("The document %1$s has unsaved "
845 "changes.\n\nDo you want to save "
846 "the document?"), file);
847 int const ret = Alert::prompt(_("Save changed document?"),
848 text, 0, 1, _("&Save"),
852 bv->owner()->dispatch(FuncRequest(LFUN_MENUWRITE));
854 return buf.isClean();
860 void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
862 lyxerr[Debug::ACTION] << "LyXFunc::dispatch: action[" << ev.action
863 <<"] arg[" << ev.argument << ']' << endl;
865 // we have not done anything wrong yet.
867 dispatch_buffer.erase();
869 #ifdef NEW_DISPATCHER
870 // We try do call the most specific dispatcher first:
871 // 1. the lockinginset's dispatch
872 // 2. the bufferview's dispatch
873 // 3. the lyxview's dispatch
876 selection_possible = false;
878 string argument = ev.argument;
879 kb_action action = ev.action;
881 // We cannot use this function here
882 if (getStatus(ev).disabled()) {
883 lyxerr[Debug::ACTION] << "LyXFunc::dispatch: "
884 << lyxaction.getActionName(action)
885 << " [" << action << "] is disabled at this location"
887 setErrorMessage(getStatusMessage());
888 goto exit_with_message;
891 if (view()->available())
892 view()->hideCursor();
894 if (view()->available() && view()->theLockingInset()) {
895 InsetOld::RESULT result;
896 if (action > 1 || (action == LFUN_UNKNOWN_ACTION &&
899 UpdatableInset * inset = view()->theLockingInset();
903 inset->getCursorPos(view(), inset_x, dummy_y);
905 if ((action == LFUN_UNKNOWN_ACTION)
906 && argument.empty()) {
907 argument = encoded_last_key;
910 // the insets can't try to handle this,
911 // a table cell in the dummy position will
912 // lock its insettext, the insettext will
913 // pass it the bufferview, and succeed,
914 // so it will stay not locked. Not good
915 // if we've just done LFUN_ESCAPE (which
916 // injects an LFUN_PARAGRAPH_UPDATE)
917 if (action == LFUN_PARAGRAPH_UPDATE) {
918 view()->dispatch(ev);
919 goto exit_with_message;
922 // Undo/Redo is a bit tricky for insets.
923 if (action == LFUN_UNDO) {
925 goto exit_with_message;
926 } else if (action == LFUN_REDO) {
928 goto exit_with_message;
929 } else if (((result=inset->
930 // Hand-over to inset's own dispatch:
931 localDispatch(FuncRequest(view(), action, argument))) ==
933 (result == DISPATCHED_NOUPDATE))
934 goto exit_with_message;
935 // If UNDISPATCHED, just soldier on
936 else if (result == FINISHED) {
937 owner->clearMessage();
938 goto exit_with_message;
939 // We do not need special RTL handling here:
940 // FINISHED means that the cursor should be
941 // one position after the inset.
942 } else if (result == FINISHED_RIGHT) {
943 view()->text->cursorRight(view());
945 owner->clearMessage();
946 goto exit_with_message;
947 } else if (result == FINISHED_UP) {
948 RowList::iterator const irow = view()->text->cursorIRow();
949 if (irow != view()->text->firstRow()) {
951 view()->text->setCursorFromCoordinates(
952 view()->text->cursor.x() + inset_x,
953 view()->text->cursor.y() -
954 irow->baseline() - 1);
955 view()->text->cursor.x_fix(view()->text->cursor.x());
957 view()->text->cursorUp(view());
963 owner->clearMessage();
964 goto exit_with_message;
965 } else if (result == FINISHED_DOWN) {
966 RowList::iterator const irow = view()->text->cursorIRow();
967 if (irow != view()->text->lastRow()) {
969 view()->text->setCursorFromCoordinates(
970 view()->text->cursor.x() + inset_x,
971 view()->text->cursor.y() -
974 view()->text->cursor.x_fix(view()->text->cursor.x());
976 view()->text->cursorDown(view());
979 view()->text->cursorRight(view());
982 owner->clearMessage();
983 goto exit_with_message;
985 #warning I am not sure this is still right, please have a look! (Jug 20020417)
986 else { // result == UNDISPATCHED
987 //setMessage(N_("Text mode"));
989 case LFUN_UNKNOWN_ACTION:
990 case LFUN_BREAKPARAGRAPH:
992 view()->text->cursorRight(view());
993 view()->switchKeyMap();
994 owner->view_state_changed();
997 if (!view()->text->cursor.par()->isRightToLeftPar(owner->buffer()->params())) {
998 view()->text->cursorRight(view());
1000 owner->view_state_changed();
1002 goto exit_with_message;
1004 if (view()->text->cursor.par()->isRightToLeftPar(owner->buffer()->params())) {
1005 view()->text->cursorRight(view());
1007 owner->view_state_changed();
1009 goto exit_with_message;
1011 if (view()->text->cursorRow() != view()->text->lastRow())
1012 view()->text->cursorDown(view());
1014 view()->text->cursorRight(view());
1016 owner->view_state_changed();
1017 goto exit_with_message;
1028 if (!view()->available())
1030 // this function should be used always [asierra060396]
1031 UpdatableInset * tli = view()->theLockingInset();
1033 UpdatableInset * lock = tli->getLockingInset();
1036 view()->unlockInset(tli);
1037 view()->text->cursorRight(view());
1039 owner->view_state_changed();
1041 tli->unlockInsetInInset(view(), lock, true);
1044 // Tell the paragraph dialog that we changed paragraph
1045 dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
1050 case LFUN_WORDFINDFORWARD:
1051 case LFUN_WORDFINDBACKWARD: {
1052 static string last_search;
1053 string searched_string;
1055 if (!argument.empty()) {
1056 last_search = argument;
1057 searched_string = argument;
1059 searched_string = last_search;
1061 bool fw = (action == LFUN_WORDFINDFORWARD);
1062 if (!searched_string.empty())
1063 lyx::find::find(view(), searched_string, fw);
1068 if (view()->available() && !view()->theLockingInset())
1070 owner->message(keyseq.printOptions());
1073 // --- Misc -------------------------------------------
1074 case LFUN_EXEC_COMMAND:
1075 owner->focus_command_buffer();
1080 meta_fake_bit = key_modifier::none;
1081 if (view()->available())
1082 // cancel any selection
1083 dispatch(LFUN_MARK_OFF);
1084 setMessage(N_("Cancel"));
1087 case LFUN_META_FAKE:
1088 meta_fake_bit = key_modifier::alt;
1089 setMessage(keyseq.print());
1092 case LFUN_READ_ONLY_TOGGLE:
1093 if (owner->buffer()->lyxvc().inUse())
1094 owner->buffer()->lyxvc().toggleReadOnly();
1096 owner->buffer()->setReadonly(
1097 !owner->buffer()->isReadonly());
1100 case LFUN_CENTER: // this is center and redraw.
1104 // --- Menus -----------------------------------------------
1106 menuNew(argument, false);
1109 case LFUN_MENUNEWTMPLT:
1110 menuNew(argument, true);
1113 case LFUN_CLOSEBUFFER:
1117 case LFUN_MENUWRITE:
1118 if (!owner->buffer()->isUnnamed()) {
1119 string const str = bformat(_("Saving document %1$s..."),
1120 MakeDisplayPath(owner->buffer()->fileName()));
1121 owner->message(str);
1122 MenuWrite(owner->buffer());
1123 owner->message(str + _(" done."));
1125 WriteAs(owner->buffer());
1129 WriteAs(owner->buffer(), argument);
1132 case LFUN_MENURELOAD: {
1133 string const file = MakeDisplayPath(view()->buffer()->fileName(), 20);
1134 string text = bformat(_("Any changes will be lost. Are you sure "
1135 "you want to revert to the saved version of the document %1$s?"), file);
1136 int const ret = Alert::prompt(_("Revert to saved document?"),
1137 text, 0, 1, _("&Revert"), _("&Cancel"));
1145 Exporter::Export(owner->buffer(), argument, true);
1146 view()->showErrorList(BufferFormat(*owner->buffer()));
1150 Exporter::Preview(owner->buffer(), argument);
1151 view()->showErrorList(BufferFormat(*owner->buffer()));
1154 case LFUN_BUILDPROG:
1155 Exporter::Export(owner->buffer(), "program", true);
1156 view()->showErrorList(_("Build"));
1159 case LFUN_RUNCHKTEX:
1160 owner->buffer()->runChktex();
1161 view()->showErrorList(_("ChkTeX"));
1165 if (argument == "custom")
1166 owner->getDialogs().showSendto();
1168 Exporter::Export(owner->buffer(), argument, false);
1169 view()->showErrorList(BufferFormat(*owner->buffer()));
1183 InsetCommandParams p("tableofcontents");
1184 string const data = InsetCommandMailer::params2string("toc", p);
1185 owner->getDialogs().show("toc", data, 0);
1201 case LFUN_DEPTH_MIN:
1202 changeDepth(view(), view()->getLyXText(), DEC_DEPTH, false);
1203 owner->view_state_changed();
1206 case LFUN_DEPTH_PLUS:
1207 changeDepth(view(), view()->getLyXText(), INC_DEPTH, false);
1208 owner->view_state_changed();
1211 case LFUN_FREEFONT_APPLY:
1212 apply_freefont(view());
1215 case LFUN_FREEFONT_UPDATE:
1216 update_and_apply_freefont(view(), argument);
1219 case LFUN_RECONFIGURE:
1220 Reconfigure(view());
1224 case LFUN_FLOATSOPERATE:
1225 if (argument == "openfoot")
1226 view()->allFloats(1,0);
1227 else if (argument == "closefoot")
1228 view()->allFloats(0,0);
1229 else if (argument == "openfig")
1230 view()->allFloats(1,1);
1231 else if (argument == "closefig")
1232 view()->allFloats(0,1);
1235 #ifdef WITH_WARNINGS
1236 //#warning Find another implementation here (or another lyxfunc)!
1239 case LFUN_HELP_OPEN:
1241 string const arg = argument;
1243 setErrorMessage(N_("Missing argument"));
1246 string const fname = i18nLibFileSearch("doc", arg, "lyx");
1247 if (fname.empty()) {
1248 lyxerr << "LyX: unable to find documentation file `"
1249 << arg << "'. Bad installation?" << endl;
1252 owner->message(bformat(_("Opening help file %1$s..."),
1253 MakeDisplayPath(fname)));
1254 view()->loadLyXFile(fname, false);
1258 // --- version control -------------------------------
1259 case LFUN_VC_REGISTER:
1261 if (!ensureBufferClean(view()))
1263 if (!owner->buffer()->lyxvc().inUse()) {
1264 owner->buffer()->lyxvc().registrer();
1270 case LFUN_VC_CHECKIN:
1272 if (!ensureBufferClean(view()))
1274 if (owner->buffer()->lyxvc().inUse()
1275 && !owner->buffer()->isReadonly()) {
1276 owner->buffer()->lyxvc().checkIn();
1282 case LFUN_VC_CHECKOUT:
1284 if (!ensureBufferClean(view()))
1286 if (owner->buffer()->lyxvc().inUse()
1287 && owner->buffer()->isReadonly()) {
1288 owner->buffer()->lyxvc().checkOut();
1294 case LFUN_VC_REVERT:
1296 owner->buffer()->lyxvc().revert();
1303 owner->buffer()->lyxvc().undoLast();
1308 // --- buffers ----------------------------------------
1310 case LFUN_SWITCHBUFFER:
1311 view()->buffer(bufferlist.getBuffer(argument));
1315 NewFile(view(), argument);
1318 case LFUN_FILE_OPEN:
1322 case LFUN_LAYOUT_TABULAR:
1323 if (view()->theLockingInset()) {
1324 if (view()->theLockingInset()->lyxCode()== InsetOld::TABULAR_CODE) {
1325 InsetTabular * inset = static_cast<InsetTabular *>
1326 (view()->theLockingInset());
1327 inset->openLayoutDialog(view());
1328 } else if (view()->theLockingInset()->
1329 getFirstLockingInsetOfType(InsetOld::TABULAR_CODE)!=0) {
1330 InsetTabular * inset = static_cast<InsetTabular *>(
1331 view()->theLockingInset()->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE));
1332 inset->openLayoutDialog(view());
1337 case LFUN_DROP_LAYOUTS_CHOICE:
1338 owner->getToolbar().openLayoutList();
1341 case LFUN_MENU_OPEN_BY_NAME:
1342 owner->getMenubar().openByName(argument);
1343 break; // RVDK_PATCH_5
1345 // --- lyxserver commands ----------------------------
1349 setMessage(owner->buffer()->fileName());
1350 lyxerr[Debug::INFO] << "FNAME["
1351 << owner->buffer()->fileName()
1357 dispatch_buffer = keyseq.print();
1358 lyxserver->notifyClient(dispatch_buffer);
1362 case LFUN_GOTOFILEROW:
1366 istringstream istr(argument.c_str());
1367 istr >> file_name >> row;
1368 // Must replace extension of the file to be .lyx and get full path
1369 string const s(ChangeExtension(file_name, ".lyx"));
1371 // Either change buffer or load the file
1372 if (bufferlist.exists(s)) {
1373 view()->buffer(bufferlist.getBuffer(s));
1375 view()->loadLyXFile(s);
1378 view()->setCursorFromRow(row);
1381 // see BufferView_pimpl::center()
1382 view()->updateScrollbar();
1386 case LFUN_GOTO_PARAGRAPH:
1388 istringstream istr(argument.c_str());
1392 ParIterator par = owner->buffer()->getParFromID(id);
1393 if (par == owner->buffer()->par_iterator_end()) {
1394 lyxerr[Debug::INFO] << "No matching paragraph found! ["
1395 << id << ']' << endl;
1398 lyxerr[Debug::INFO] << "Paragraph " << par->id()
1399 << " found." << endl;
1402 if (view()->theLockingInset())
1403 view()->unlockInset(view()->theLockingInset());
1404 if (par->inInset()) {
1405 FuncRequest cmd(view(), LFUN_INSET_EDIT, "left");
1406 par->inInset()->localDispatch(cmd);
1409 view()->getLyXText()->setCursor(par.pit(), 0);
1410 view()->switchKeyMap();
1411 owner->view_state_changed();
1414 // see BufferView_pimpl::center()
1415 view()->updateScrollbar();
1419 // --- insert characters ----------------------------------------
1421 // --- Mathed stuff. If we are here, there is no locked inset yet.
1422 case LFUN_MATH_EXTERN:
1423 case LFUN_MATH_NUMBER:
1424 case LFUN_MATH_NONUMBER:
1425 case LFUN_MATH_LIMITS:
1427 setErrorMessage(N_("This is only allowed in math mode!"));
1431 // passthrough hat and underscore outside mathed:
1432 case LFUN_SUBSCRIPT:
1433 dispatch(FuncRequest(view(), LFUN_SELFINSERT, "_"));
1435 case LFUN_SUPERSCRIPT:
1436 dispatch(FuncRequest(view(), LFUN_SELFINSERT, "^"));
1439 case LFUN_DIALOG_SHOW: {
1440 string const name = ev.getArg(0);
1441 string data = trim(ev.argument.substr(name.size()));
1443 if (name == "character") {
1444 data = freefont2string();
1446 owner->getDialogs().show("character", data);
1447 } else if (name == "document")
1448 owner->getDialogs().showDocument();
1449 else if (name == "findreplace")
1450 owner->getDialogs().showSearch();
1451 else if (name == "forks")
1452 owner->getDialogs().showForks();
1453 else if (name == "preamble")
1454 owner->getDialogs().showPreamble();
1455 else if (name == "preferences")
1456 owner->getDialogs().showPreferences();
1457 else if (name == "print")
1458 owner->getDialogs().showPrint();
1459 else if (name == "spellchecker")
1460 owner->getDialogs().showSpellchecker();
1462 owner->getDialogs().show(name, data);
1466 case LFUN_DIALOG_SHOW_NEW_INSET: {
1467 string const & name = argument;
1469 if (name == "bibitem" ||
1471 name == "include" ||
1476 InsetCommandParams p(name);
1477 data = InsetCommandMailer::params2string(name, p);
1478 } else if (name == "citation") {
1479 InsetCommandParams p("cite");
1480 data = InsetCommandMailer::params2string(name, p);
1482 owner->getDialogs().show(name, data, 0);
1486 case LFUN_DIALOG_SHOW_NEXT_INSET: {
1490 case LFUN_INSET_DIALOG_SHOW: {
1491 LyXText * lt = view()->getLyXText();
1492 InsetOld * inset = lt->getInset();
1494 FuncRequest cmd(view(), LFUN_INSET_DIALOG_SHOW);
1495 inset->localDispatch(cmd);
1500 case LFUN_DIALOG_UPDATE: {
1501 string const & name = argument;
1502 // Can only update a dialog connected to an existing inset
1503 InsetBase * inset = owner->getDialogs().getOpenInset(name);
1505 FuncRequest fr(view(), LFUN_INSET_DIALOG_UPDATE,
1507 inset->localDispatch(fr);
1508 } else if (name == "paragraph") {
1509 dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
1514 case LFUN_DIALOG_HIDE:
1515 Dialogs::hide(argument, 0);
1518 case LFUN_DIALOG_DISCONNECT_INSET:
1519 owner->getDialogs().disconnect(argument);
1522 case LFUN_CHILDOPEN:
1524 string const filename =
1525 MakeAbsPath(argument,
1526 owner->buffer()->filePath());
1527 setMessage(N_("Opening child document ") +
1528 MakeDisplayPath(filename) + "...");
1529 view()->savePosition(0);
1530 if (bufferlist.exists(filename))
1531 view()->buffer(bufferlist.getBuffer(filename));
1533 view()->loadLyXFile(filename);
1537 case LFUN_TOGGLECURSORFOLLOW:
1538 lyxrc.cursor_follows_scrollbar = !lyxrc.cursor_follows_scrollbar;
1542 owner->getIntl().KeyMapOn(false);
1545 case LFUN_KMAP_PRIM:
1546 owner->getIntl().KeyMapPrim();
1550 owner->getIntl().KeyMapSec();
1553 case LFUN_KMAP_TOGGLE:
1554 owner->getIntl().ToggleKeyMap();
1559 // argument contains ';'-terminated commands
1560 while (!argument.empty()) {
1562 argument = split(argument, first, ';');
1568 case LFUN_SAVEPREFERENCES:
1570 Path p(user_lyxdir());
1571 lyxrc.write("preferences");
1575 case LFUN_SCREEN_FONT_UPDATE:
1577 // handle the screen font changes.
1578 lyxrc.set_font_norm_type();
1579 lyx_gui::update_fonts();
1580 // We also need to empty the textcache so that
1581 // the buffer will be formatted correctly after
1584 // Of course we should only do the resize and the textcache.clear
1585 // if values really changed...but not very important right now. (Lgb)
1586 // All visible buffers will need resize
1592 case LFUN_SET_COLOR:
1595 string const x11_name = split(argument, lyx_name, ' ');
1596 if (lyx_name.empty() || x11_name.empty()) {
1597 setErrorMessage(N_("Syntax: set-color <lyx_name>"
1602 bool const graphicsbg_changed =
1603 (lyx_name == lcolor.getLyXName(LColor::graphicsbg) &&
1604 x11_name != lcolor.getX11Name(LColor::graphicsbg));
1606 if (!lcolor.setColor(lyx_name, x11_name)) {
1608 bformat(_("Set-color \"%1$s\" failed "
1609 "- color is undefined or "
1610 "may not be redefined"), lyx_name));
1614 lyx_gui::update_color(lcolor.getFromLyXName(lyx_name));
1616 if (graphicsbg_changed) {
1617 #ifdef WITH_WARNINGS
1618 #warning FIXME!! The graphics cache no longer has a changeDisplay method.
1621 lyx::graphics::GCache & gc =
1622 lyx::graphics::GCache::get();
1623 gc.changeDisplay(true);
1632 owner->message(argument);
1635 case LFUN_FORKS_KILL:
1637 if (!isStrInt(argument))
1640 pid_t const pid = strToInt(argument);
1641 ForkedcallsController & fcc = ForkedcallsController::get();
1646 case LFUN_TOOLTIPS_TOGGLE:
1647 owner->getDialogs().toggleTooltips();
1650 case LFUN_EXTERNAL_EDIT: {
1652 .localDispatch(FuncRequest(view(), action, argument));
1657 // Then if it was none of the above
1658 // Trying the BufferView::pimpl dispatch:
1659 if (!view()->dispatch(ev))
1660 lyxerr << "A truly unknown func ["
1661 << lyxaction.getActionName(ev.action) << "]!"
1668 view()->owner()->updateLayoutChoice();
1670 if (view()->available()) {
1671 if (view()->fitCursor()) {
1672 //lyxerr << "LyXFunc->fitCursor->update" << endl;
1676 // If we executed a mutating lfun, mark the buffer as dirty
1677 if (!getStatus(ev).disabled()
1678 && !lyxaction.funcHasFlag(ev.action, LyXAction::NoBuffer)
1679 && !lyxaction.funcHasFlag(ev.action, LyXAction::ReadOnly))
1680 view()->buffer()->markDirty();
1683 sendDispatchMessage(getMessage(), ev, verbose);
1687 void LyXFunc::sendDispatchMessage(string const & msg, FuncRequest const & ev, bool verbose)
1689 owner->updateMenubar();
1690 owner->updateToolbar();
1692 if (ev.action == LFUN_SELFINSERT || !verbose) {
1693 lyxerr[Debug::ACTION] << "dispatch msg is " << msg << endl;
1695 owner->message(msg);
1699 string dispatch_msg = msg;
1700 if (!dispatch_msg.empty())
1701 dispatch_msg += ' ';
1703 string comname = lyxaction.getActionName(ev.action);
1705 int pseudoaction = ev.action;
1706 bool argsadded = false;
1708 if (!ev.argument.empty()) {
1709 // the pseudoaction is useful for the bindings
1710 pseudoaction = lyxaction.searchActionArg(ev.action, ev.argument);
1712 if (pseudoaction == LFUN_UNKNOWN_ACTION) {
1713 pseudoaction = ev.action;
1715 comname += ' ' + ev.argument;
1720 string const shortcuts = toplevel_keymap->findbinding(pseudoaction);
1722 if (!shortcuts.empty()) {
1723 comname += ": " + shortcuts;
1724 } else if (!argsadded && !ev.argument.empty()) {
1725 comname += ' ' + ev.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);