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"
32 #include "dispatchresult.h"
36 #include "funcrequest.h"
40 #include "iterators.h"
44 #include "LyXAction.h"
48 #include "lyxserver.h"
50 #include "paragraph.h"
51 #include "ParagraphParameters.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"));
287 case LFUN_UNKNOWN_ACTION:
288 #ifndef HAVE_LIBAIKSAURUS
289 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"));
328 UpdatableInset * tli = view()->theLockingInset();
330 // I would really like to avoid having this switch and rather try to
331 // encode this in the function itself.
332 bool disable = false;
335 disable = ev.argument != "custom"
336 && !Exporter::IsExportable(*buf, ev.argument);
339 disable = buf->undostack().empty();
342 disable = buf->redostack().empty();
347 UpdatableInset * in = tli;
348 if (in->lyxCode() != InsetOld::TABULAR_CODE) {
349 in = tli->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE);
351 if (in && static_cast<InsetTabular*>(in)->hasSelection()) {
356 disable = !mathcursor && !view()->getLyXText()->selection.set();
359 disable = !buf->isLatex() || lyxrc.chktex_command == "none";
362 disable = !Exporter::IsExportable(*buf, "program");
365 case LFUN_LAYOUT_TABULAR:
367 || (tli->lyxCode() != InsetOld::TABULAR_CODE
368 && !tli->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE));
372 disable = !changeDepth(view(), view()->getLyXText(), DEC_DEPTH, true);
375 case LFUN_DEPTH_PLUS:
376 disable = !changeDepth(view(), view()->getLyXText(), INC_DEPTH, true);
380 case LFUN_LAYOUT_PARAGRAPH: {
381 InsetOld * inset = view()->getLyXText()->cursorPar()->inInset();
382 disable = inset && inset->forceDefaultParagraphs(inset);
386 case LFUN_INSET_OPTARG:
387 disable = (view()->getLyXText()->cursorPar()->layout()->optionalargs == 0);
390 case LFUN_TABULAR_FEATURE:
393 // FIXME: check temporarily disabled
395 char align = mathcursor->valign();
400 if (ev.argument.empty()) {
404 if (!contains("tcb", ev.argument[0])) {
408 flag.setOnOff(ev.argument[0] == align);
412 char align = mathcursor->halign();
417 if (ev.argument.empty()) {
421 if (!contains("lcr", ev.argument[0])) {
425 flag.setOnOff(ev.argument[0] == align);
428 disable = !mathcursor->halign();
434 //ret.disabled(true);
435 if (tli->lyxCode() == InsetOld::TABULAR_CODE) {
436 ret = static_cast<InsetTabular *>(tli)
437 ->getStatus(ev.argument);
440 } else if (tli->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE)) {
441 ret = static_cast<InsetTabular *>
442 (tli->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE))
443 ->getStatus(ev.argument);
450 static InsetTabular inset(*buf, 1, 1);
452 FuncStatus 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));
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;
487 case LFUN_INSET_TOGGLE: {
488 LyXText * lt = view()->getLyXText();
489 disable = !(isEditableInset(lt->getInset())
491 && lt->inset_owner->owner()
492 && lt->inset_owner->owner()->isOpen()));
496 case LFUN_INSET_SETTINGS: {
498 UpdatableInset * inset = view()->theLockingInset();
503 // get the innermost inset
504 inset = inset->getLockingInset();
506 // jump back to owner if an InsetText, so
507 // we get back to the InsetTabular or whatever
508 if (inset->lyxCode() == InsetOld::TEXT_CODE)
509 inset = inset->owner();
511 InsetOld::Code code = inset->lyxCode();
513 case InsetOld::TABULAR_CODE:
514 disable = ev.argument != "tabular";
516 case InsetOld::ERT_CODE:
517 disable = ev.argument != "ert";
519 case InsetOld::FLOAT_CODE:
520 disable = ev.argument != "float";
522 case InsetOld::MINIPAGE_CODE:
523 disable = ev.argument != "minipage";
525 case InsetOld::WRAP_CODE:
526 disable = ev.argument != "wrap";
528 case InsetOld::NOTE_CODE:
529 disable = ev.argument != "note";
531 case InsetOld::BRANCH_CODE:
532 disable = ev.argument != "branch";
534 case InsetOld::BOX_CODE:
535 disable = ev.argument != "box";
543 case LFUN_MATH_MUTATE:
545 //flag.setOnOff(mathcursor->formula()->hullType() == ev.argument);
546 flag.setOnOff(false);
551 // we just need to be in math mode to enable that
553 case LFUN_MATH_SPACE:
554 case LFUN_MATH_LIMITS:
555 case LFUN_MATH_NONUMBER:
556 case LFUN_MATH_NUMBER:
557 case LFUN_MATH_EXTERN:
558 disable = !mathcursor;
561 case LFUN_DIALOG_SHOW: {
562 string const name = ev.getArg(0);
564 disable = !(name == "aboutlyx" ||
567 name == "preferences" ||
572 if (name == "print") {
573 disable = !Exporter::IsExportable(*buf, "dvi") ||
574 lyxrc.print_command == "none";
575 } else if (name == "character") {
576 UpdatableInset * tli = view()->theLockingInset();
577 disable = tli && tli->lyxCode() == InsetOld::ERT_CODE;
578 } else if (name == "vclog") {
579 disable = !buf->lyxvc().inUse();
580 } else if (name == "latexlog") {
581 disable = !IsFileReadable(buf->getLogName().second);
590 // the functions which insert insets
591 InsetOld::Code code = InsetOld::NO_CODE;
593 case LFUN_DIALOG_SHOW_NEW_INSET:
594 if (ev.argument == "bibitem")
595 code = InsetOld::BIBITEM_CODE;
596 else if (ev.argument == "bibtex")
597 code = InsetOld::BIBTEX_CODE;
598 else if (ev.argument == "citation")
599 code = InsetOld::CITE_CODE;
600 else if (ev.argument == "ert")
601 code = InsetOld::ERT_CODE;
602 else if (ev.argument == "external")
603 code = InsetOld::EXTERNAL_CODE;
604 else if (ev.argument == "float")
605 code = InsetOld::FLOAT_CODE;
606 else if (ev.argument == "graphics")
607 code = InsetOld::GRAPHICS_CODE;
608 else if (ev.argument == "include")
609 code = InsetOld::INCLUDE_CODE;
610 else if (ev.argument == "index")
611 code = InsetOld::INDEX_CODE;
612 else if (ev.argument == "label")
613 code = InsetOld::LABEL_CODE;
614 else if (ev.argument == "minipage")
615 code = InsetOld::MINIPAGE_CODE;
616 else if (ev.argument == "ref")
617 code = InsetOld::REF_CODE;
618 else if (ev.argument == "toc")
619 code = InsetOld::TOC_CODE;
620 else if (ev.argument == "url")
621 code = InsetOld::URL_CODE;
622 else if (ev.argument == "wrap")
623 code = InsetOld::WRAP_CODE;
627 code = InsetOld::ERT_CODE;
629 case LFUN_INSET_FOOTNOTE:
630 code = InsetOld::FOOT_CODE;
632 case LFUN_TABULAR_INSERT:
633 code = InsetOld::TABULAR_CODE;
635 case LFUN_INSET_MARGINAL:
636 code = InsetOld::MARGIN_CODE;
638 case LFUN_INSET_MINIPAGE:
639 code = InsetOld::MINIPAGE_CODE;
641 case LFUN_INSET_FLOAT:
642 case LFUN_INSET_WIDE_FLOAT:
643 code = InsetOld::FLOAT_CODE;
645 case LFUN_INSET_WRAP:
646 code = InsetOld::WRAP_CODE;
648 case LFUN_FLOAT_LIST:
649 code = InsetOld::FLOAT_LIST_CODE;
652 case LFUN_INSET_LIST:
653 code = InsetOld::LIST_CODE;
655 case LFUN_INSET_THEOREM:
656 code = InsetOld::THEOREM_CODE;
659 case LFUN_INSET_CAPTION:
660 code = InsetOld::CAPTION_CODE;
662 case LFUN_INSERT_NOTE:
663 code = InsetOld::NOTE_CODE;
665 case LFUN_INSERT_BOX:
666 code = InsetOld::BOX_CODE;
668 case LFUN_INSERT_BRANCH:
669 code = InsetOld::BRANCH_CODE;
670 if (buf->params().branchlist().empty())
673 case LFUN_INSERT_LABEL:
674 code = InsetOld::LABEL_CODE;
676 case LFUN_INSET_OPTARG:
677 code = InsetOld::OPTARG_CODE;
679 case LFUN_ENVIRONMENT_INSERT:
680 code = InsetOld::MINIPAGE_CODE;
682 case LFUN_INDEX_INSERT:
683 code = InsetOld::INDEX_CODE;
685 case LFUN_INDEX_PRINT:
686 code = InsetOld::INDEX_PRINT_CODE;
688 case LFUN_TOC_INSERT:
689 code = InsetOld::TOC_CODE;
693 code = InsetOld::URL_CODE;
696 // always allow this, since we will inset a raw quote
697 // if an inset is not allowed.
699 case LFUN_HYPHENATION:
700 case LFUN_LIGATURE_BREAK:
702 case LFUN_MENU_SEPARATOR:
704 case LFUN_END_OF_SENTENCE:
705 code = InsetOld::SPECIALCHAR_CODE;
707 case LFUN_SPACE_INSERT:
708 // slight hack: we know this is allowed in math mode
710 code = InsetOld::SPACE_CODE;
712 case LFUN_INSET_DIALOG_SHOW: {
713 InsetOld * inset = view()->getLyXText()->getInset();
716 code = inset->lyxCode();
717 if (!(code == InsetOld::INCLUDE_CODE
718 || code == InsetOld::BIBTEX_CODE
719 || code == InsetOld::FLOAT_LIST_CODE
720 || code == InsetOld::TOC_CODE))
728 if (code != InsetOld::NO_CODE && tli && !tli->insetAllowed(code))
734 // A few general toggles
736 case LFUN_TOOLTIPS_TOGGLE:
737 flag.setOnOff(owner->getDialogs().tooltipsEnabled());
740 case LFUN_READ_ONLY_TOGGLE:
741 flag.setOnOff(buf->isReadonly());
744 flag.setOnOff(view()->getLyXText()->cursorPar()->params().startOfAppendix());
746 case LFUN_SWITCHBUFFER:
747 // toggle on the current buffer, but do not toggle off
748 // the other ones (is that a good idea?)
749 if (ev.argument == buf->fileName())
752 case LFUN_TRACK_CHANGES:
753 flag.setOnOff(buf->params().tracking_changes);
759 // the font related toggles
761 LyXFont const & font = view()->getLyXText()->real_current_font;
764 flag.setOnOff(font.emph() == LyXFont::ON);
767 flag.setOnOff(font.noun() == LyXFont::ON);
770 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
773 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
776 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
779 flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
785 string tc = mathcursor->getLastCode();
788 flag.setOnOff(tc == "mathbf");
791 flag.setOnOff(tc == "mathsf");
794 flag.setOnOff(tc == "mathcal");
797 flag.setOnOff(tc == "mathrm");
800 flag.setOnOff(tc == "mathtt");
803 flag.setOnOff(tc == "mathbb");
806 flag.setOnOff(tc == "mathnormal");
813 // this one is difficult to get right. As a half-baked
814 // solution, we consider only the first action of the sequence
815 if (ev.action == LFUN_SEQUENCE) {
816 // argument contains ';'-terminated commands
817 #warning LyXAction arguments not handled here.
818 flag = getStatus(FuncRequest(lyxaction.lookupFunc(token(ev.argument, ';', 0))));
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 & func, bool verbose)
852 string argument = func.argument;
853 kb_action action = func.action;
855 lyxerr[Debug::ACTION] << "LyXFunc::dispatch: action[" << action
856 <<"] arg[" << argument << ']' << endl;
858 // we have not done anything wrong yet.
860 dispatch_buffer.erase();
862 #ifdef NEW_DISPATCHER
863 // We try do call the most specific dispatcher first:
864 // 1. the lockinginset's dispatch
865 // 2. the bufferview's dispatch
866 // 3. the lyxview's dispatch
869 selection_possible = false;
871 // We cannot use this function here
872 if (getStatus(func).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();
886 UpdatableInset * innerinset = view()->theLockingInset();
887 for (UpdatableInset * tmp = innerinset; tmp; tmp = tmp->lockingInset())
890 if (view()->cursor().innerInset() != innerinset) {
891 lyxerr << "### CURSOR OUT OF SYNC: tli: "
892 << view()->theLockingInset() << " inner: "
894 << "\ncursor: " << view()->cursor() << endl;
899 DispatchResult result =
900 view()->cursor().dispatch(FuncRequest(func, view()));
902 if (result.dispatched()) {
903 if (result.update()) {
906 lyxerr << "dispatched by Cursor::dispatch()\n";
907 goto exit_with_message;
909 lyxerr << "### NOT DispatchResult(true, true) BY Cursor::dispatch() ###\n";
914 if (view()->available() && view()->theLockingInset()) {
915 DispatchResult result;
916 if (action > 1 || (action == LFUN_UNKNOWN_ACTION &&
919 UpdatableInset * inset = view()->theLockingInset();
923 inset->getCursorPos(view(), inset_x, dummy_y);
925 if (action == LFUN_UNKNOWN_ACTION && argument.empty())
926 argument = encoded_last_key;
928 // the insets can't try to handle this,
929 // a table cell in the dummy position will
930 // lock its insettext, the insettext will
931 // pass it the bufferview, and succeed,
932 // so it will stay not locked. Not good
933 // if we've just done LFUN_ESCAPE (which
934 // injects an LFUN_PARAGRAPH_UPDATE)
935 if (action == LFUN_PARAGRAPH_UPDATE) {
936 view()->dispatch(func);
937 goto exit_with_message;
940 // Undo/Redo is a bit tricky for insets.
941 if (action == LFUN_UNDO) {
943 goto exit_with_message;
946 if (action == LFUN_REDO) {
948 goto exit_with_message;
951 // Hand-over to inset's own dispatch:
952 result = inset->dispatch(FuncRequest(view(), action, argument));
953 if (result.dispatched()) {
957 goto exit_with_message;
960 // If DispatchResult(false), just soldier on
961 if (result.val() == FINISHED) {
962 owner->clearMessage();
963 goto exit_with_message;
964 // We do not need special RTL handling here:
965 // FINISHED means that the cursor should be
966 // one position after the inset.
969 if (result.val() == FINISHED_RIGHT) {
970 view()->text->cursorRight(view());
972 owner->clearMessage();
973 goto exit_with_message;
976 if (result.val() == FINISHED_UP) {
977 LyXText * text = view()->text;
978 ParagraphList::iterator pit = text->cursorPar();
979 Row const & row = *pit->getRow(text->cursor.pos());
980 if (text->isFirstRow(pit, row)) {
982 text->setCursorFromCoordinates(
983 text->cursor.x() + inset_x,
986 view()->x_target(text->cursor.x());
988 text->cursorUp(view());
994 owner->clearMessage();
995 goto exit_with_message;
998 if (result.val() == FINISHED_DOWN) {
999 LyXText * text = view()->text;
1000 ParagraphList::iterator pit = text->cursorPar();
1001 Row const & row = *pit->getRow(text->cursor.pos());
1002 if (text->isLastRow(pit, row)) {
1004 text->setCursorFromCoordinates(
1005 text->cursor.x() + inset_x,
1009 view()->x_target(text->cursor.x());
1011 text->cursorDown(view());
1014 text->cursorRight(view());
1017 owner->clearMessage();
1018 goto exit_with_message;
1021 #warning I am not sure this is still right, please have a look! (Jug 20020417)
1022 // result == DispatchResult()
1023 //setMessage(N_("Text mode"));
1025 case LFUN_UNKNOWN_ACTION:
1026 case LFUN_BREAKPARAGRAPH:
1027 case LFUN_BREAKLINE:
1028 view()->text->cursorRight(view());
1029 view()->switchKeyMap();
1030 owner->view_state_changed();
1033 if (!view()->text->cursorPar()->isRightToLeftPar(owner->buffer()->params())) {
1034 view()->text->cursorRight(view());
1036 owner->view_state_changed();
1038 goto exit_with_message;
1040 if (view()->text->cursorPar()->isRightToLeftPar(owner->buffer()->params())) {
1041 view()->text->cursorRight(view());
1043 owner->view_state_changed();
1045 goto exit_with_message;
1047 LyXText * text = view()->text;
1048 ParagraphList::iterator pit = text->cursorPar();
1049 if (text->isLastRow(pit, *pit->getRow(text->cursor.pos())))
1050 view()->text->cursorDown(view());
1052 view()->text->cursorRight(view());
1054 owner->view_state_changed();
1055 goto exit_with_message;
1066 if (!view()->available())
1068 // this function should be used always [asierra060396]
1069 UpdatableInset * tli = view()->theLockingInset();
1071 UpdatableInset * lock = tli->getLockingInset();
1074 view()->unlockInset(tli);
1075 view()->text->cursorRight(view());
1077 owner->view_state_changed();
1079 tli->unlockInsetInInset(view(), lock, true);
1082 // Tell the paragraph dialog that we changed paragraph
1083 dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
1088 case LFUN_WORDFINDFORWARD:
1089 case LFUN_WORDFINDBACKWARD: {
1090 static string last_search;
1091 string searched_string;
1093 if (!argument.empty()) {
1094 last_search = argument;
1095 searched_string = argument;
1097 searched_string = last_search;
1099 bool fw = (action == LFUN_WORDFINDFORWARD);
1100 if (!searched_string.empty())
1101 lyx::find::find(view(), searched_string,
1107 if (view()->available() && !view()->theLockingInset())
1109 owner->message(keyseq.printOptions());
1112 // --- Misc -------------------------------------------
1113 case LFUN_EXEC_COMMAND:
1114 owner->focus_command_buffer();
1119 meta_fake_bit = key_modifier::none;
1120 if (view()->available())
1121 // cancel any selection
1122 dispatch(FuncRequest(LFUN_MARK_OFF));
1123 setMessage(N_("Cancel"));
1126 case LFUN_META_FAKE:
1127 meta_fake_bit = key_modifier::alt;
1128 setMessage(keyseq.print());
1131 case LFUN_READ_ONLY_TOGGLE:
1132 if (owner->buffer()->lyxvc().inUse())
1133 owner->buffer()->lyxvc().toggleReadOnly();
1135 owner->buffer()->setReadonly(
1136 !owner->buffer()->isReadonly());
1139 case LFUN_CENTER: // this is center and redraw.
1143 // --- Menus -----------------------------------------------
1145 menuNew(argument, false);
1148 case LFUN_MENUNEWTMPLT:
1149 menuNew(argument, true);
1152 case LFUN_CLOSEBUFFER:
1156 case LFUN_MENUWRITE:
1157 if (!owner->buffer()->isUnnamed()) {
1158 string const str = bformat(_("Saving document %1$s..."),
1159 MakeDisplayPath(owner->buffer()->fileName()));
1160 owner->message(str);
1161 MenuWrite(owner->buffer());
1162 owner->message(str + _(" done."));
1164 WriteAs(owner->buffer());
1168 WriteAs(owner->buffer(), argument);
1171 case LFUN_MENURELOAD: {
1172 string const file = MakeDisplayPath(view()->buffer()->fileName(), 20);
1173 string text = bformat(_("Any changes will be lost. Are you sure "
1174 "you want to revert to the saved version of the document %1$s?"), file);
1175 int const ret = Alert::prompt(_("Revert to saved document?"),
1176 text, 0, 1, _("&Revert"), _("&Cancel"));
1184 Exporter::Export(owner->buffer(), argument, true);
1185 view()->showErrorList(BufferFormat(*owner->buffer()));
1189 Exporter::Preview(owner->buffer(), argument);
1190 view()->showErrorList(BufferFormat(*owner->buffer()));
1193 case LFUN_BUILDPROG:
1194 Exporter::Export(owner->buffer(), "program", true);
1195 view()->showErrorList(_("Build"));
1198 case LFUN_RUNCHKTEX:
1199 owner->buffer()->runChktex();
1200 view()->showErrorList(_("ChkTeX"));
1204 if (argument == "custom")
1205 owner->getDialogs().showSendto();
1207 Exporter::Export(owner->buffer(), argument, false);
1208 view()->showErrorList(BufferFormat(*owner->buffer()));
1220 case LFUN_TOCVIEW: {
1221 InsetCommandParams p("tableofcontents");
1222 string const data = InsetCommandMailer::params2string("toc", p);
1223 owner->getDialogs().show("toc", data, 0);
1239 case LFUN_FREEFONT_APPLY:
1240 apply_freefont(view());
1243 case LFUN_FREEFONT_UPDATE:
1244 update_and_apply_freefont(view(), argument);
1247 case LFUN_RECONFIGURE:
1248 Reconfigure(view());
1252 case LFUN_FLOATSOPERATE:
1253 if (argument == "openfoot")
1254 view()->allFloats(1,0);
1255 else if (argument == "closefoot")
1256 view()->allFloats(0,0);
1257 else if (argument == "openfig")
1258 view()->allFloats(1,1);
1259 else if (argument == "closefig")
1260 view()->allFloats(0,1);
1263 #ifdef WITH_WARNINGS
1264 //#warning Find another implementation here (or another lyxfunc)!
1268 case LFUN_HELP_OPEN: {
1269 string const arg = argument;
1271 setErrorMessage(N_("Missing argument"));
1274 string const fname = i18nLibFileSearch("doc", arg, "lyx");
1275 if (fname.empty()) {
1276 lyxerr << "LyX: unable to find documentation file `"
1277 << arg << "'. Bad installation?" << endl;
1280 owner->message(bformat(_("Opening help file %1$s..."),
1281 MakeDisplayPath(fname)));
1282 view()->loadLyXFile(fname, false);
1286 // --- version control -------------------------------
1287 case LFUN_VC_REGISTER:
1288 if (!ensureBufferClean(view()))
1290 if (!owner->buffer()->lyxvc().inUse()) {
1291 owner->buffer()->lyxvc().registrer();
1296 case LFUN_VC_CHECKIN:
1297 if (!ensureBufferClean(view()))
1299 if (owner->buffer()->lyxvc().inUse()
1300 && !owner->buffer()->isReadonly()) {
1301 owner->buffer()->lyxvc().checkIn();
1306 case LFUN_VC_CHECKOUT:
1307 if (!ensureBufferClean(view()))
1309 if (owner->buffer()->lyxvc().inUse()
1310 && owner->buffer()->isReadonly()) {
1311 owner->buffer()->lyxvc().checkOut();
1316 case LFUN_VC_REVERT:
1317 owner->buffer()->lyxvc().revert();
1322 owner->buffer()->lyxvc().undoLast();
1326 // --- buffers ----------------------------------------
1328 case LFUN_SWITCHBUFFER:
1329 view()->buffer(bufferlist.getBuffer(argument));
1333 NewFile(view(), argument);
1336 case LFUN_FILE_OPEN:
1340 case LFUN_LAYOUT_TABULAR: {
1341 UpdatableInset * tli = view()->theLockingInset();
1343 if (tli->lyxCode() == InsetOld::TABULAR_CODE) {
1344 static_cast<InsetTabular *>(tli)->openLayoutDialog(view());
1345 } else if (tli->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE)) {
1346 static_cast<InsetTabular *>(
1347 tli->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE))
1348 ->openLayoutDialog(view());
1354 case LFUN_DROP_LAYOUTS_CHOICE:
1355 owner->getToolbar().openLayoutList();
1358 case LFUN_MENU_OPEN_BY_NAME:
1359 owner->getMenubar().openByName(argument);
1360 break; // RVDK_PATCH_5
1362 // --- lyxserver commands ----------------------------
1366 setMessage(owner->buffer()->fileName());
1367 lyxerr[Debug::INFO] << "FNAME["
1368 << owner->buffer()->fileName()
1373 dispatch_buffer = keyseq.print();
1374 lyxserver->notifyClient(dispatch_buffer);
1377 case LFUN_GOTOFILEROW: {
1380 istringstream is(argument);
1381 is >> file_name >> row;
1382 if (prefixIs(file_name, getTmpDir())) {
1383 // Needed by inverse dvi search. If it is a file
1384 // in tmpdir, call the apropriated function
1385 view()->buffer(bufferlist.getBufferFromTmp(file_name));
1387 // Must replace extension of the file to be .lyx
1388 // and get full path
1389 string const s = ChangeExtension(file_name, ".lyx");
1390 // Either change buffer or load the file
1391 if (bufferlist.exists(s)) {
1392 view()->buffer(bufferlist.getBuffer(s));
1394 view()->loadLyXFile(s);
1398 view()->setCursorFromRow(row);
1401 // see BufferView_pimpl::center()
1402 view()->updateScrollbar();
1406 case LFUN_GOTO_PARAGRAPH: {
1407 istringstream is(argument);
1410 ParIterator par = owner->buffer()->getParFromID(id);
1411 if (par == owner->buffer()->par_iterator_end()) {
1412 lyxerr[Debug::INFO] << "No matching paragraph found! ["
1413 << id << ']' << endl;
1416 lyxerr[Debug::INFO] << "Paragraph " << par->id()
1417 << " found." << endl;
1421 par.lockPath(view());
1422 LyXText * lt = par.text(view());
1425 lt->setCursor(par.pit(), 0);
1426 view()->switchKeyMap();
1427 owner->view_state_changed();
1430 // see BufferView_pimpl::center()
1431 view()->updateScrollbar();
1435 // --- insert characters ----------------------------------------
1437 // --- Mathed stuff. If we are here, there is no locked inset yet.
1438 case LFUN_MATH_EXTERN:
1439 case LFUN_MATH_NUMBER:
1440 case LFUN_MATH_NONUMBER:
1441 case LFUN_MATH_LIMITS:
1442 setErrorMessage(N_("This is only allowed in math mode!"));
1445 // passthrough hat and underscore outside mathed:
1446 case LFUN_SUBSCRIPT:
1447 dispatch(FuncRequest(view(), LFUN_SELFINSERT, "_"));
1450 case LFUN_SUPERSCRIPT:
1451 dispatch(FuncRequest(view(), LFUN_SELFINSERT, "^"));
1454 case LFUN_DIALOG_SHOW: {
1455 string const name = func.getArg(0);
1456 string data = trim(func.argument.substr(name.size()));
1458 if (name == "character") {
1459 data = freefont2string();
1461 owner->getDialogs().show("character", data);
1462 } else if (name == "document")
1463 owner->getDialogs().showDocument();
1464 else if (name == "findreplace")
1465 owner->getDialogs().showSearch();
1466 else if (name == "forks")
1467 owner->getDialogs().showForks();
1468 else if (name == "preamble")
1469 owner->getDialogs().showPreamble();
1470 else if (name == "preferences")
1471 owner->getDialogs().showPreferences();
1472 else if (name == "print")
1473 owner->getDialogs().showPrint();
1474 else if (name == "spellchecker")
1475 owner->getDialogs().showSpellchecker();
1477 owner->getDialogs().show(name, data);
1481 case LFUN_DIALOG_SHOW_NEW_INSET: {
1482 string const & name = argument;
1484 if (name == "bibitem" ||
1486 name == "include" ||
1491 InsetCommandParams p(name);
1492 data = InsetCommandMailer::params2string(name, p);
1493 } else if (name == "citation") {
1494 InsetCommandParams p("cite");
1495 data = InsetCommandMailer::params2string(name, p);
1497 owner->getDialogs().show(name, data, 0);
1501 case LFUN_DIALOG_SHOW_NEXT_INSET:
1504 case LFUN_INSET_DIALOG_SHOW: {
1505 InsetOld * inset = view()->getLyXText()->getInset();
1507 inset->dispatch(FuncRequest(view(), LFUN_INSET_DIALOG_SHOW));
1511 case LFUN_DIALOG_UPDATE: {
1512 string const & name = argument;
1513 // Can only update a dialog connected to an existing inset
1514 InsetBase * inset = owner->getDialogs().getOpenInset(name);
1516 FuncRequest fr(view(), LFUN_INSET_DIALOG_UPDATE,
1518 inset->dispatch(fr);
1519 } else if (name == "paragraph") {
1520 dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
1525 case LFUN_DIALOG_HIDE:
1526 Dialogs::hide(argument, 0);
1529 case LFUN_DIALOG_DISCONNECT_INSET:
1530 owner->getDialogs().disconnect(argument);
1533 case LFUN_CHILDOPEN: {
1534 string const filename =
1535 MakeAbsPath(argument, owner->buffer()->filePath());
1536 setMessage(N_("Opening child document ") +
1537 MakeDisplayPath(filename) + "...");
1538 view()->savePosition(0);
1539 if (bufferlist.exists(filename))
1540 view()->buffer(bufferlist.getBuffer(filename));
1542 view()->loadLyXFile(filename);
1546 case LFUN_TOGGLECURSORFOLLOW:
1547 lyxrc.cursor_follows_scrollbar = !lyxrc.cursor_follows_scrollbar;
1551 owner->getIntl().KeyMapOn(false);
1554 case LFUN_KMAP_PRIM:
1555 owner->getIntl().KeyMapPrim();
1559 owner->getIntl().KeyMapSec();
1562 case LFUN_KMAP_TOGGLE:
1563 owner->getIntl().ToggleKeyMap();
1569 argument = split(argument, countstr, ' ');
1570 istringstream is(countstr);
1573 lyxerr << "repeat: count: " << count << " cmd: " << argument << endl;
1574 for (int i = 0; i < count; ++i)
1575 dispatch(lyxaction.lookupFunc(argument));
1580 // argument contains ';'-terminated commands
1581 while (!argument.empty()) {
1583 argument = split(argument, first, ';');
1584 dispatch(lyxaction.lookupFunc(first));
1588 case LFUN_SAVEPREFERENCES: {
1589 Path p(user_lyxdir());
1590 lyxrc.write("preferences");
1594 case LFUN_SCREEN_FONT_UPDATE:
1595 // handle the screen font changes.
1596 lyxrc.set_font_norm_type();
1597 lyx_gui::update_fonts();
1598 // All visible buffers will need resize
1603 case LFUN_SET_COLOR: {
1605 string const x11_name = split(argument, lyx_name, ' ');
1606 if (lyx_name.empty() || x11_name.empty()) {
1607 setErrorMessage(N_("Syntax: set-color <lyx_name>"
1612 bool const graphicsbg_changed =
1613 (lyx_name == lcolor.getLyXName(LColor::graphicsbg) &&
1614 x11_name != lcolor.getX11Name(LColor::graphicsbg));
1616 if (!lcolor.setColor(lyx_name, x11_name)) {
1618 bformat(_("Set-color \"%1$s\" failed "
1619 "- color is undefined or "
1620 "may not be redefined"), lyx_name));
1624 lyx_gui::update_color(lcolor.getFromLyXName(lyx_name));
1626 if (graphicsbg_changed) {
1627 #ifdef WITH_WARNINGS
1628 #warning FIXME!! The graphics cache no longer has a changeDisplay method.
1631 lyx::graphics::GCache::get().changeDisplay(true);
1640 owner->message(argument);
1643 case LFUN_FORKS_KILL:
1644 if (isStrInt(argument)) {
1645 pid_t const pid = strToInt(argument);
1646 ForkedcallsController & fcc = ForkedcallsController::get();
1651 case LFUN_TOOLTIPS_TOGGLE:
1652 owner->getDialogs().toggleTooltips();
1655 case LFUN_EXTERNAL_EDIT:
1656 InsetExternal().dispatch(FuncRequest(view(), action, argument));
1660 // Then if it was none of the above
1661 // Trying the BufferView::pimpl dispatch:
1662 if (!view()->dispatch(func))
1663 lyxerr << "A truly unknown func ["
1664 << lyxaction.getActionName(func.action) << "]!"
1671 view()->owner()->updateLayoutChoice();
1673 if (view()->available()) {
1674 if (view()->fitCursor()) {
1675 //lyxerr << "LyXFunc->fitCursor->update" << endl;
1679 // If we executed a mutating lfun, mark the buffer as dirty
1680 if (!getStatus(func).disabled()
1681 && !lyxaction.funcHasFlag(func.action, LyXAction::NoBuffer)
1682 && !lyxaction.funcHasFlag(func.action, LyXAction::ReadOnly))
1683 view()->buffer()->markDirty();
1686 sendDispatchMessage(getMessage(), func, verbose);
1690 void LyXFunc::sendDispatchMessage(string const & msg,
1691 FuncRequest const & func, bool verbose)
1693 owner->updateMenubar();
1694 owner->updateToolbar();
1696 if (func.action == LFUN_SELFINSERT || !verbose) {
1697 lyxerr[Debug::ACTION] << "dispatch msg is " << msg << endl;
1699 owner->message(msg);
1703 string dispatch_msg = msg;
1704 if (!dispatch_msg.empty())
1705 dispatch_msg += ' ';
1707 string comname = lyxaction.getActionName(func.action);
1709 bool argsadded = false;
1711 if (!func.argument.empty()) {
1712 if (func.action != LFUN_UNKNOWN_ACTION) {
1713 comname += ' ' + func.argument;
1718 string const shortcuts = toplevel_keymap->findbinding(func);
1720 if (!shortcuts.empty()) {
1721 comname += ": " + shortcuts;
1722 } else if (!argsadded && !func.argument.empty()) {
1723 comname += ' ' + func.argument;
1726 if (!comname.empty()) {
1727 comname = rtrim(comname);
1728 dispatch_msg += '(' + comname + ')';
1731 lyxerr[Debug::ACTION] << "verbose dispatch msg " << dispatch_msg << endl;
1732 if (!dispatch_msg.empty())
1733 owner->message(dispatch_msg);
1737 void LyXFunc::setupLocalKeymap()
1739 keyseq.stdmap = keyseq.curmap = toplevel_keymap.get();
1740 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap.get();
1744 void LyXFunc::menuNew(string const & name, bool fromTemplate)
1746 string initpath = lyxrc.document_path;
1747 string filename(name);
1749 if (view()->available()) {
1750 string const trypath = owner->buffer()->filePath();
1751 // If directory is writeable, use this as default.
1752 if (IsDirWriteable(trypath))
1756 static int newfile_number;
1758 if (filename.empty()) {
1759 filename = AddName(lyxrc.document_path,
1760 "newfile" + tostr(++newfile_number) + ".lyx");
1761 FileInfo fi(filename);
1762 while (bufferlist.exists(filename) || fi.readable()) {
1764 filename = AddName(lyxrc.document_path,
1765 "newfile" + tostr(newfile_number) +
1767 fi.newFile(filename);
1771 // The template stuff
1774 FileDialog fileDlg(_("Select template file"),
1775 LFUN_SELECT_FILE_SYNC,
1776 make_pair(string(_("Documents|#o#O")),
1777 string(lyxrc.document_path)),
1778 make_pair(string(_("Templates|#T#t")),
1779 string(lyxrc.template_path)));
1781 FileDialog::Result result =
1782 fileDlg.open(lyxrc.template_path,
1783 _("*.lyx| LyX Documents (*.lyx)"));
1785 if (result.first == FileDialog::Later)
1788 string const fname = result.second;
1795 view()->newFile(filename, templname, !name.empty());
1799 void LyXFunc::open(string const & fname)
1801 string initpath = lyxrc.document_path;
1803 if (view()->available()) {
1804 string const trypath = owner->buffer()->filePath();
1805 // If directory is writeable, use this as default.
1806 if (IsDirWriteable(trypath))
1812 if (fname.empty()) {
1813 FileDialog fileDlg(_("Select document to open"),
1815 make_pair(string(_("Documents|#o#O")),
1816 string(lyxrc.document_path)),
1817 make_pair(string(_("Examples|#E#e")),
1818 string(AddPath(system_lyxdir(), "examples"))));
1820 FileDialog::Result result =
1821 fileDlg.open(initpath,
1822 _("*.lyx| LyX Documents (*.lyx)"));
1824 if (result.first == FileDialog::Later)
1827 filename = result.second;
1829 // check selected filename
1830 if (filename.empty()) {
1831 owner->message(_("Canceled."));
1837 // get absolute path of file and add ".lyx" to the filename if
1839 string const fullpath = FileSearch(string(), filename, "lyx");
1840 if (!fullpath.empty()) {
1841 filename = fullpath;
1844 string const disp_fn(MakeDisplayPath(filename));
1846 // if the file doesn't exist, let the user create one
1847 FileInfo const f(filename, true);
1849 // the user specifically chose this name. Believe them.
1850 view()->newFile(filename, "", true);
1854 owner->message(bformat(_("Opening document %1$s..."), disp_fn));
1857 if (view()->loadLyXFile(filename)) {
1858 str2 = bformat(_("Document %1$s opened."), disp_fn);
1860 str2 = bformat(_("Could not open document %1$s"), disp_fn);
1862 owner->message(str2);
1866 void LyXFunc::doImport(string const & argument)
1869 string filename = split(argument, format, ' ');
1871 lyxerr[Debug::INFO] << "LyXFunc::doImport: " << format
1872 << " file: " << filename << endl;
1874 // need user interaction
1875 if (filename.empty()) {
1876 string initpath = lyxrc.document_path;
1878 if (view()->available()) {
1879 string const trypath = owner->buffer()->filePath();
1880 // If directory is writeable, use this as default.
1881 if (IsDirWriteable(trypath))
1885 string const text = bformat(_("Select %1$s file to import"),
1886 formats.prettyName(format));
1888 FileDialog fileDlg(text,
1890 make_pair(string(_("Documents|#o#O")),
1891 string(lyxrc.document_path)),
1892 make_pair(string(_("Examples|#E#e")),
1893 string(AddPath(system_lyxdir(), "examples"))));
1895 string const extension = "*." + formats.extension(format)
1896 + "| " + formats.prettyName(format)
1897 + " (*." + formats.extension(format) + ')';
1899 FileDialog::Result result = fileDlg.open(initpath,
1902 if (result.first == FileDialog::Later)
1905 filename = result.second;
1907 // check selected filename
1908 if (filename.empty())
1909 owner->message(_("Canceled."));
1912 if (filename.empty())
1915 // get absolute path of file
1916 filename = MakeAbsPath(filename);
1918 string const lyxfile = ChangeExtension(filename, ".lyx");
1920 // Check if the document already is open
1921 if (lyx_gui::use_gui && bufferlist.exists(lyxfile)) {
1922 if (!bufferlist.close(bufferlist.getBuffer(lyxfile), true)) {
1923 owner->message(_("Canceled."));
1928 // if the file exists already, and we didn't do
1929 // -i lyx thefile.lyx, warn
1930 if (FileInfo(lyxfile, true).exist() && filename != lyxfile) {
1931 string const file = MakeDisplayPath(lyxfile, 30);
1933 string text = bformat(_("The document %1$s already exists.\n\n"
1934 "Do you want to over-write that document?"), file);
1935 int const ret = Alert::prompt(_("Over-write document?"),
1936 text, 0, 1, _("&Over-write"), _("&Cancel"));
1939 owner->message(_("Canceled."));
1944 Importer::Import(owner, filename, format);
1948 void LyXFunc::closeBuffer()
1950 if (bufferlist.close(owner->buffer(), true) && !quitting) {
1951 if (bufferlist.empty()) {
1952 // need this otherwise SEGV may occur while
1953 // trying to set variables that don't exist
1954 // since there's no current buffer
1955 owner->getDialogs().hideBufferDependent();
1957 view()->buffer(bufferlist.first());
1963 // Each "owner" should have it's own message method. lyxview and
1964 // the minibuffer would use the minibuffer, but lyxserver would
1965 // send an ERROR signal to its client. Alejandro 970603
1966 // This func is bit problematic when it comes to NLS, to make the
1967 // lyx servers client be language indepenent we must not translate
1968 // strings sent to this func.
1969 void LyXFunc::setErrorMessage(string const & m) const
1971 dispatch_buffer = m;
1976 void LyXFunc::setMessage(string const & m) const
1978 dispatch_buffer = m;
1982 void LyXFunc::setStatusMessage(string const & m) const
1988 string const LyXFunc::view_status_message()
1990 // When meta-fake key is pressed, show the key sequence so far + "M-".
1992 return keyseq.print() + "M-";
1995 // Else, when a non-complete key sequence is pressed,
1996 // show the available options.
1997 if (keyseq.length() > 0 && !keyseq.deleted()) {
1998 return keyseq.printOptions();
2001 if (!view()->available())
2002 return _("Welcome to LyX!");
2004 return currentState(view());
2008 BufferView * LyXFunc::view() const
2010 BOOST_ASSERT(owner);
2011 return owner->view().get();
2015 bool LyXFunc::wasMetaKey() const
2017 return (meta_fake_bit != key_modifier::none);