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"
41 #include "LyXAction.h"
45 #include "lyxserver.h"
47 #include "paragraph.h"
48 #include "ParagraphParameters.h"
49 #include "TextCache.h"
50 #include "undo_funcs.h"
52 #include "insets/insetcommand.h"
53 #include "insets/insetexternal.h"
54 #include "insets/insettabular.h"
56 #include "mathed/math_cursor.h"
58 #include "frontends/Alert.h"
59 #include "frontends/Dialogs.h"
60 #include "frontends/FileDialog.h"
61 #include "frontends/lyx_gui.h"
62 #include "frontends/LyXKeySym.h"
63 #include "frontends/LyXView.h"
64 #include "frontends/Menubar.h"
65 #include "frontends/Toolbar.h"
67 #include "support/FileInfo.h"
68 #include "support/filetools.h"
69 #include "support/forkedcontr.h"
70 #include "support/path.h"
71 #include "support/path_defines.h"
72 #include "support/tostr.h"
74 #include "support/std_sstream.h"
76 using bv_funcs::apply_freefont;
77 using bv_funcs::changeDepth;
78 using bv_funcs::currentState;
79 using bv_funcs::DEC_DEPTH;
80 using bv_funcs::freefont2string;
81 using bv_funcs::INC_DEPTH;
82 using bv_funcs::update_and_apply_freefont;
84 using lyx::support::AddName;
85 using lyx::support::AddPath;
86 using lyx::support::bformat;
87 using lyx::support::ChangeExtension;
88 using lyx::support::FileInfo;
89 using lyx::support::FileSearch;
90 using lyx::support::ForkedcallsController;
91 using lyx::support::i18nLibFileSearch;
92 using lyx::support::IsDirWriteable;
93 using lyx::support::IsFileReadable;
94 using lyx::support::isStrInt;
95 using lyx::support::MakeAbsPath;
96 using lyx::support::MakeDisplayPath;
97 using lyx::support::Path;
98 using lyx::support::rtrim;
99 using lyx::support::split;
100 using lyx::support::strToInt;
101 using lyx::support::strToUnsignedInt;
102 using lyx::support::system_lyxdir;
103 using lyx::support::token;
104 using lyx::support::trim;
105 using lyx::support::user_lyxdir;
108 using std::make_pair;
110 using std::istringstream;
113 extern BufferList bufferlist;
114 extern LyXServer * lyxserver;
115 extern bool selection_possible;
117 extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
120 extern tex_accent_struct get_accent(kb_action action);
122 extern void ShowLatexLog();
125 LyXFunc::LyXFunc(LyXView * o)
128 keyseq(toplevel_keymap.get(), toplevel_keymap.get()),
129 cancel_meta_seq(toplevel_keymap.get(), toplevel_keymap.get()),
130 meta_fake_bit(key_modifier::none)
135 void LyXFunc::moveCursorUpdate()
137 LyXText * lt = view()->text;
138 if (lt->selection.mark())
141 view()->switchKeyMap();
145 void LyXFunc::handleKeyFunc(kb_action action)
147 char c = encoded_last_key;
149 if (keyseq.length()) {
153 owner->getIntl().getTransManager()
154 .deadkey(c, get_accent(action).accent, view()->getLyXText());
155 // Need to clear, in case the minibuffer calls these
158 // copied verbatim from do_accent_char
160 view()->getLyXText()->selection.cursor = view()->getLyXText()->cursor;
164 void LyXFunc::processKeySym(LyXKeySymPtr keysym,
165 key_modifier::state state)
169 if (lyxerr.debugging(Debug::KEY)) {
170 lyxerr << "KeySym is "
171 << keysym->getSymbolName()
175 // Do nothing if we have nothing (JMarc)
176 if (!keysym->isOK()) {
177 lyxerr[Debug::KEY] << "Empty kbd action (probably composing)"
182 if (keysym->isModifier()) {
183 lyxerr[Debug::KEY] << "isModifier true" << endl;
187 Encoding const * encoding = view()->getEncoding();
189 encoded_last_key = keysym->getISOEncoded(encoding ? encoding->Name() : "");
191 // Do a one-deep top-level lookup for
192 // cancel and meta-fake keys. RVDK_PATCH_5
193 cancel_meta_seq.reset();
195 int action = cancel_meta_seq.addkey(keysym, state);
196 lyxerr[Debug::KEY] << "action first set to [" << action << ']' << endl;
198 // When not cancel or meta-fake, do the normal lookup.
199 // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
200 // Mostly, meta_fake_bit = key_modifier::none. RVDK_PATCH_5.
201 if ((action != LFUN_CANCEL) && (action != LFUN_META_FAKE)) {
202 // remove Caps Lock and Mod2 as a modifiers
203 action = keyseq.addkey(keysym, (state | meta_fake_bit));
204 lyxerr[Debug::KEY] << "action now set to ["
205 << action << ']' << endl;
208 // Dont remove this unless you know what you are doing.
209 meta_fake_bit = key_modifier::none;
211 // can this happen now ?
212 if (action == LFUN_NOACTION) {
213 action = LFUN_PREFIX;
216 if (lyxerr.debugging(Debug::KEY)) {
217 lyxerr << "Key [action="
219 << keyseq.print() << ']'
223 // already here we know if it any point in going further
224 // why not return already here if action == -1 and
225 // num_bytes == 0? (Lgb)
227 if (keyseq.length() > 1) {
228 owner->message(keyseq.print());
232 // Maybe user can only reach the key via holding down shift.
233 // Let's see. But only if shift is the only modifier
234 if (action == LFUN_UNKNOWN_ACTION && state == key_modifier::shift) {
235 lyxerr[Debug::KEY] << "Trying without shift" << endl;
236 action = keyseq.addkey(keysym, key_modifier::none);
237 lyxerr[Debug::KEY] << "Action now " << action << endl;
240 if (action == LFUN_UNKNOWN_ACTION) {
241 // Hmm, we didn't match any of the keysequences. See
242 // if it's normal insertable text not already covered
244 if (keysym->isText() && keyseq.length() == 1) {
245 lyxerr[Debug::KEY] << "isText() is true, inserting." << endl;
246 action = LFUN_SELFINSERT;
248 lyxerr[Debug::KEY] << "Unknown, !isText() - giving up" << endl;
249 owner->message(_("Unknown function."));
254 if (action == LFUN_SELFINSERT) {
255 if (encoded_last_key != 0) {
257 arg += encoded_last_key;
259 dispatch(FuncRequest(view(), LFUN_SELFINSERT, arg));
261 lyxerr[Debug::KEY] << "SelfInsert arg[`"
262 << argument << "']" << endl;
270 FuncStatus LyXFunc::getStatus(int ac) const
272 return getStatus(lyxaction.retrieveActionArg(ac));
276 FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
279 Buffer * buf = owner->buffer();
281 if (ev.action == LFUN_NOACTION) {
282 setStatusMessage(N_("Nothing to do"));
283 return flag.disabled(true);
287 case LFUN_UNKNOWN_ACTION:
288 #ifndef HAVE_LIBAIKSAURUS
289 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()->cursor.par()->inInset();
380 disable = inset && inset->forceDefaultParagraphs(inset);
384 case LFUN_INSET_OPTARG:
385 disable = (view()->getLyXText()->cursor.par()->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";
538 case LFUN_MATH_MUTATE:
540 //flag.setOnOff(mathcursor->formula()->hullType() == ev.argument);
541 flag.setOnOff(false);
546 // we just need to be in math mode to enable that
548 case LFUN_MATH_SPACE:
549 case LFUN_MATH_LIMITS:
550 case LFUN_MATH_NONUMBER:
551 case LFUN_MATH_NUMBER:
552 case LFUN_MATH_EXTERN:
553 disable = !mathcursor;
556 case LFUN_DIALOG_SHOW: {
557 string const name = ev.getArg(0);
559 disable = !(name == "aboutlyx" ||
562 name == "preferences" ||
567 if (name == "print") {
568 disable = !Exporter::IsExportable(*buf, "dvi") ||
569 lyxrc.print_command == "none";
570 } else if (name == "character") {
571 UpdatableInset * tli = view()->theLockingInset();
572 disable = tli && tli->lyxCode() == InsetOld::ERT_CODE;
573 } else if (name == "vclog") {
574 disable = !buf->lyxvc().inUse();
575 } else if (name == "latexlog") {
576 disable = !IsFileReadable(buf->getLogName().second);
585 // the functions which insert insets
586 InsetOld::Code code = InsetOld::NO_CODE;
588 case LFUN_DIALOG_SHOW_NEW_INSET:
589 if (ev.argument == "bibitem")
590 code = InsetOld::BIBITEM_CODE;
591 else if (ev.argument == "bibtex")
592 code = InsetOld::BIBTEX_CODE;
593 else if (ev.argument == "citation")
594 code = InsetOld::CITE_CODE;
595 else if (ev.argument == "ert")
596 code = InsetOld::ERT_CODE;
597 else if (ev.argument == "external")
598 code = InsetOld::EXTERNAL_CODE;
599 else if (ev.argument == "float")
600 code = InsetOld::FLOAT_CODE;
601 else if (ev.argument == "graphics")
602 code = InsetOld::GRAPHICS_CODE;
603 else if (ev.argument == "include")
604 code = InsetOld::INCLUDE_CODE;
605 else if (ev.argument == "index")
606 code = InsetOld::INDEX_CODE;
607 else if (ev.argument == "label")
608 code = InsetOld::LABEL_CODE;
609 else if (ev.argument == "minipage")
610 code = InsetOld::MINIPAGE_CODE;
611 else if (ev.argument == "ref")
612 code = InsetOld::REF_CODE;
613 else if (ev.argument == "toc")
614 code = InsetOld::TOC_CODE;
615 else if (ev.argument == "url")
616 code = InsetOld::URL_CODE;
617 else if (ev.argument == "wrap")
618 code = InsetOld::WRAP_CODE;
622 code = InsetOld::ERT_CODE;
624 case LFUN_INSET_FOOTNOTE:
625 code = InsetOld::FOOT_CODE;
627 case LFUN_TABULAR_INSERT:
628 code = InsetOld::TABULAR_CODE;
630 case LFUN_INSET_MARGINAL:
631 code = InsetOld::MARGIN_CODE;
633 case LFUN_INSET_MINIPAGE:
634 code = InsetOld::MINIPAGE_CODE;
636 case LFUN_INSET_FLOAT:
637 case LFUN_INSET_WIDE_FLOAT:
638 code = InsetOld::FLOAT_CODE;
640 case LFUN_INSET_WRAP:
641 code = InsetOld::WRAP_CODE;
643 case LFUN_FLOAT_LIST:
644 code = InsetOld::FLOAT_LIST_CODE;
647 case LFUN_INSET_LIST:
648 code = InsetOld::LIST_CODE;
650 case LFUN_INSET_THEOREM:
651 code = InsetOld::THEOREM_CODE;
654 case LFUN_INSET_CAPTION:
655 code = InsetOld::CAPTION_CODE;
657 case LFUN_INSERT_NOTE:
658 code = InsetOld::NOTE_CODE;
660 case LFUN_INSERT_BRANCH:
661 code = InsetOld::BRANCH_CODE;
662 if (buf->params().branchlist().empty())
665 case LFUN_INSERT_LABEL:
666 code = InsetOld::LABEL_CODE;
668 case LFUN_INSET_OPTARG:
669 code = InsetOld::OPTARG_CODE;
671 case LFUN_ENVIRONMENT_INSERT:
672 code = InsetOld::MINIPAGE_CODE;
674 case LFUN_INDEX_INSERT:
675 code = InsetOld::INDEX_CODE;
677 case LFUN_INDEX_PRINT:
678 code = InsetOld::INDEX_PRINT_CODE;
680 case LFUN_TOC_INSERT:
681 code = InsetOld::TOC_CODE;
685 code = InsetOld::URL_CODE;
688 // always allow this, since we will inset a raw quote
689 // if an inset is not allowed.
691 case LFUN_HYPHENATION:
692 case LFUN_LIGATURE_BREAK:
694 case LFUN_MENU_SEPARATOR:
696 case LFUN_END_OF_SENTENCE:
697 code = InsetOld::SPECIALCHAR_CODE;
699 case LFUN_SPACE_INSERT:
700 // slight hack: we know this is allowed in math mode
702 code = InsetOld::SPACE_CODE;
704 case LFUN_INSET_DIALOG_SHOW: {
705 LyXText * lt = view()->getLyXText();
706 InsetOld * inset = lt->getInset();
709 code = inset->lyxCode();
710 if (!(code == InsetOld::INCLUDE_CODE
711 || code == InsetOld::BIBTEX_CODE
712 || code == InsetOld::FLOAT_LIST_CODE
713 || code == InsetOld::TOC_CODE))
721 if (code != InsetOld::NO_CODE && tli && !tli->insetAllowed(code))
727 // A few general toggles
729 case LFUN_TOOLTIPS_TOGGLE:
730 flag.setOnOff(owner->getDialogs().tooltipsEnabled());
733 case LFUN_READ_ONLY_TOGGLE:
734 flag.setOnOff(buf->isReadonly());
737 flag.setOnOff(view()->getLyXText()->cursor.par()->params().startOfAppendix());
739 case LFUN_SWITCHBUFFER:
740 // toggle on the current buffer, but do not toggle off
741 // the other ones (is that a good idea?)
742 if (ev.argument == buf->fileName())
745 case LFUN_TRACK_CHANGES:
746 flag.setOnOff(buf->params().tracking_changes);
752 // the font related toggles
754 LyXFont const & font = view()->getLyXText()->real_current_font;
757 flag.setOnOff(font.emph() == LyXFont::ON);
760 flag.setOnOff(font.noun() == LyXFont::ON);
763 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
766 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
769 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
772 flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
778 string tc = mathcursor->getLastCode();
781 flag.setOnOff(tc == "mathbf");
784 flag.setOnOff(tc == "mathsf");
787 flag.setOnOff(tc == "mathcal");
790 flag.setOnOff(tc == "mathrm");
793 flag.setOnOff(tc == "mathtt");
796 flag.setOnOff(tc == "mathbb");
799 flag.setOnOff(tc == "mathnormal");
806 // this one is difficult to get right. As a half-baked
807 // solution, we consider only the first action of the sequence
808 if (ev.action == LFUN_SEQUENCE) {
809 // argument contains ';'-terminated commands
810 flag = getStatus(lyxaction.LookupFunc(token(ev.argument, ';', 0)));
817 void LyXFunc::dispatch(string const & s, bool verbose)
819 int const action = lyxaction.LookupFunc(s);
821 if (action == LFUN_UNKNOWN_ACTION) {
822 owner->message(bformat(_("Unknown function (%1$s)"), s));
826 dispatch(action, verbose);
830 void LyXFunc::dispatch(int ac, bool verbose)
832 dispatch(lyxaction.retrieveActionArg(ac), verbose);
836 bool ensureBufferClean(BufferView * bv) {
838 Buffer & buf = *bv->buffer();
842 string const file = MakeDisplayPath(buf.fileName(), 30);
843 string text = bformat(_("The document %1$s has unsaved "
844 "changes.\n\nDo you want to save "
845 "the document?"), file);
846 int const ret = Alert::prompt(_("Save changed document?"),
847 text, 0, 1, _("&Save"),
851 bv->owner()->dispatch(FuncRequest(LFUN_MENUWRITE));
853 return buf.isClean();
859 void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
861 lyxerr[Debug::ACTION] << "LyXFunc::dispatch: action[" << ev.action
862 <<"] arg[" << ev.argument << ']' << endl;
864 // we have not done anything wrong yet.
866 dispatch_buffer.erase();
868 #ifdef NEW_DISPATCHER
869 // We try do call the most specific dispatcher first:
870 // 1. the lockinginset's dispatch
871 // 2. the bufferview's dispatch
872 // 3. the lyxview's dispatch
875 selection_possible = false;
877 string argument = ev.argument;
878 kb_action action = ev.action;
880 // We cannot use this function here
881 if (getStatus(ev).disabled()) {
882 lyxerr[Debug::ACTION] << "LyXFunc::dispatch: "
883 << lyxaction.getActionName(action)
884 << " [" << action << "] is disabled at this location"
886 setErrorMessage(getStatusMessage());
887 goto exit_with_message;
890 if (view()->available())
891 view()->hideCursor();
893 if (view()->available() && view()->theLockingInset()) {
894 InsetOld::RESULT result;
895 if (action > 1 || (action == LFUN_UNKNOWN_ACTION &&
898 UpdatableInset * inset = view()->theLockingInset();
902 inset->getCursorPos(view(), inset_x, dummy_y);
904 if ((action == LFUN_UNKNOWN_ACTION)
905 && argument.empty()) {
906 argument = encoded_last_key;
909 // the insets can't try to handle this,
910 // a table cell in the dummy position will
911 // lock its insettext, the insettext will
912 // pass it the bufferview, and succeed,
913 // so it will stay not locked. Not good
914 // if we've just done LFUN_ESCAPE (which
915 // injects an LFUN_PARAGRAPH_UPDATE)
916 if (action == LFUN_PARAGRAPH_UPDATE) {
917 view()->dispatch(ev);
918 goto exit_with_message;
921 // Undo/Redo is a bit tricky for insets.
922 if (action == LFUN_UNDO) {
924 goto exit_with_message;
925 } else if (action == LFUN_REDO) {
927 goto exit_with_message;
928 } else if (((result=inset->
929 // Hand-over to inset's own dispatch:
930 localDispatch(FuncRequest(view(), action, argument))) ==
932 (result == DISPATCHED_NOUPDATE))
933 goto exit_with_message;
934 // If UNDISPATCHED, just soldier on
935 else if (result == FINISHED) {
936 owner->clearMessage();
937 goto exit_with_message;
938 // We do not need special RTL handling here:
939 // FINISHED means that the cursor should be
940 // one position after the inset.
941 } else if (result == FINISHED_RIGHT) {
942 view()->text->cursorRight(view());
944 owner->clearMessage();
945 goto exit_with_message;
946 } else if (result == FINISHED_UP) {
947 RowList::iterator const irow = view()->text->cursorIRow();
948 if (irow != view()->text->firstRow()) {
950 view()->text->setCursorFromCoordinates(
951 view()->text->cursor.x() + inset_x,
952 view()->text->cursor.y() -
953 irow->baseline() - 1);
954 view()->text->cursor.x_fix(view()->text->cursor.x());
956 view()->text->cursorUp(view());
962 owner->clearMessage();
963 goto exit_with_message;
964 } else if (result == FINISHED_DOWN) {
965 RowList::iterator const irow = view()->text->cursorIRow();
966 if (irow != view()->text->lastRow()) {
968 view()->text->setCursorFromCoordinates(
969 view()->text->cursor.x() + inset_x,
970 view()->text->cursor.y() -
973 view()->text->cursor.x_fix(view()->text->cursor.x());
975 view()->text->cursorDown(view());
978 view()->text->cursorRight(view());
981 owner->clearMessage();
982 goto exit_with_message;
984 #warning I am not sure this is still right, please have a look! (Jug 20020417)
985 else { // result == UNDISPATCHED
986 //setMessage(N_("Text mode"));
988 case LFUN_UNKNOWN_ACTION:
989 case LFUN_BREAKPARAGRAPH:
991 view()->text->cursorRight(view());
992 view()->switchKeyMap();
993 owner->view_state_changed();
996 if (!view()->text->cursor.par()->isRightToLeftPar(owner->buffer()->params())) {
997 view()->text->cursorRight(view());
999 owner->view_state_changed();
1001 goto exit_with_message;
1003 if (view()->text->cursor.par()->isRightToLeftPar(owner->buffer()->params())) {
1004 view()->text->cursorRight(view());
1006 owner->view_state_changed();
1008 goto exit_with_message;
1010 if (view()->text->cursorRow() != view()->text->lastRow())
1011 view()->text->cursorDown(view());
1013 view()->text->cursorRight(view());
1015 owner->view_state_changed();
1016 goto exit_with_message;
1027 if (!view()->available())
1029 // this function should be used always [asierra060396]
1030 UpdatableInset * tli = view()->theLockingInset();
1032 UpdatableInset * lock = tli->getLockingInset();
1035 view()->unlockInset(tli);
1036 view()->text->cursorRight(view());
1038 owner->view_state_changed();
1040 tli->unlockInsetInInset(view(), lock, true);
1043 // Tell the paragraph dialog that we changed paragraph
1044 dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
1049 case LFUN_WORDFINDFORWARD:
1050 case LFUN_WORDFINDBACKWARD: {
1051 static string last_search;
1052 string searched_string;
1054 if (!argument.empty()) {
1055 last_search = argument;
1056 searched_string = argument;
1058 searched_string = last_search;
1060 bool fw = (action == LFUN_WORDFINDFORWARD);
1061 if (!searched_string.empty())
1062 lyx::find::find(view(), searched_string, fw);
1067 if (view()->available() && !view()->theLockingInset())
1069 owner->message(keyseq.printOptions());
1072 // --- Misc -------------------------------------------
1073 case LFUN_EXEC_COMMAND:
1074 owner->focus_command_buffer();
1079 meta_fake_bit = key_modifier::none;
1080 if (view()->available())
1081 // cancel any selection
1082 dispatch(LFUN_MARK_OFF);
1083 setMessage(N_("Cancel"));
1086 case LFUN_META_FAKE:
1087 meta_fake_bit = key_modifier::alt;
1088 setMessage(keyseq.print());
1091 case LFUN_READ_ONLY_TOGGLE:
1092 if (owner->buffer()->lyxvc().inUse())
1093 owner->buffer()->lyxvc().toggleReadOnly();
1095 owner->buffer()->setReadonly(
1096 !owner->buffer()->isReadonly());
1099 case LFUN_CENTER: // this is center and redraw.
1103 // --- Menus -----------------------------------------------
1105 menuNew(argument, false);
1108 case LFUN_MENUNEWTMPLT:
1109 menuNew(argument, true);
1112 case LFUN_CLOSEBUFFER:
1116 case LFUN_MENUWRITE:
1117 if (!owner->buffer()->isUnnamed()) {
1118 string const str = bformat(_("Saving document %1$s..."),
1119 MakeDisplayPath(owner->buffer()->fileName()));
1120 owner->message(str);
1121 MenuWrite(owner->buffer());
1122 owner->message(str + _(" done."));
1124 WriteAs(owner->buffer());
1128 WriteAs(owner->buffer(), argument);
1131 case LFUN_MENURELOAD: {
1132 string const file = MakeDisplayPath(view()->buffer()->fileName(), 20);
1133 string text = bformat(_("Any changes will be lost. Are you sure "
1134 "you want to revert to the saved version of the document %1$s?"), file);
1135 int const ret = Alert::prompt(_("Revert to saved document?"),
1136 text, 0, 1, _("&Revert"), _("&Cancel"));
1144 Exporter::Export(owner->buffer(), argument, true);
1145 view()->showErrorList(BufferFormat(*owner->buffer()));
1149 Exporter::Preview(owner->buffer(), argument);
1150 view()->showErrorList(BufferFormat(*owner->buffer()));
1153 case LFUN_BUILDPROG:
1154 Exporter::Export(owner->buffer(), "program", true);
1155 view()->showErrorList(_("Build"));
1158 case LFUN_RUNCHKTEX:
1159 owner->buffer()->runChktex();
1160 view()->showErrorList(_("ChkTeX"));
1164 if (argument == "custom")
1165 owner->getDialogs().showSendto();
1167 Exporter::Export(owner->buffer(), argument, false);
1168 view()->showErrorList(BufferFormat(*owner->buffer()));
1182 InsetCommandParams p("tableofcontents");
1183 string const data = InsetCommandMailer::params2string("toc", p);
1184 owner->getDialogs().show("toc", data, 0);
1200 case LFUN_DEPTH_MIN:
1201 changeDepth(view(), view()->getLyXText(), DEC_DEPTH, false);
1202 owner->view_state_changed();
1205 case LFUN_DEPTH_PLUS:
1206 changeDepth(view(), view()->getLyXText(), INC_DEPTH, false);
1207 owner->view_state_changed();
1210 case LFUN_FREEFONT_APPLY:
1211 apply_freefont(view());
1214 case LFUN_FREEFONT_UPDATE:
1215 update_and_apply_freefont(view(), argument);
1218 case LFUN_RECONFIGURE:
1219 Reconfigure(view());
1223 case LFUN_FLOATSOPERATE:
1224 if (argument == "openfoot")
1225 view()->allFloats(1,0);
1226 else if (argument == "closefoot")
1227 view()->allFloats(0,0);
1228 else if (argument == "openfig")
1229 view()->allFloats(1,1);
1230 else if (argument == "closefig")
1231 view()->allFloats(0,1);
1234 #ifdef WITH_WARNINGS
1235 //#warning Find another implementation here (or another lyxfunc)!
1238 case LFUN_HELP_OPEN:
1240 string const arg = argument;
1242 setErrorMessage(N_("Missing argument"));
1245 string const fname = i18nLibFileSearch("doc", arg, "lyx");
1246 if (fname.empty()) {
1247 lyxerr << "LyX: unable to find documentation file `"
1248 << arg << "'. Bad installation?" << endl;
1251 owner->message(bformat(_("Opening help file %1$s..."),
1252 MakeDisplayPath(fname)));
1253 view()->loadLyXFile(fname, false);
1257 // --- version control -------------------------------
1258 case LFUN_VC_REGISTER:
1260 if (!ensureBufferClean(view()))
1262 if (!owner->buffer()->lyxvc().inUse()) {
1263 owner->buffer()->lyxvc().registrer();
1269 case LFUN_VC_CHECKIN:
1271 if (!ensureBufferClean(view()))
1273 if (owner->buffer()->lyxvc().inUse()
1274 && !owner->buffer()->isReadonly()) {
1275 owner->buffer()->lyxvc().checkIn();
1281 case LFUN_VC_CHECKOUT:
1283 if (!ensureBufferClean(view()))
1285 if (owner->buffer()->lyxvc().inUse()
1286 && owner->buffer()->isReadonly()) {
1287 owner->buffer()->lyxvc().checkOut();
1293 case LFUN_VC_REVERT:
1295 owner->buffer()->lyxvc().revert();
1302 owner->buffer()->lyxvc().undoLast();
1307 // --- buffers ----------------------------------------
1309 case LFUN_SWITCHBUFFER:
1310 view()->buffer(bufferlist.getBuffer(argument));
1314 NewFile(view(), argument);
1317 case LFUN_FILE_OPEN:
1321 case LFUN_LAYOUT_TABULAR:
1322 if (view()->theLockingInset()) {
1323 if (view()->theLockingInset()->lyxCode()== InsetOld::TABULAR_CODE) {
1324 InsetTabular * inset = static_cast<InsetTabular *>
1325 (view()->theLockingInset());
1326 inset->openLayoutDialog(view());
1327 } else if (view()->theLockingInset()->
1328 getFirstLockingInsetOfType(InsetOld::TABULAR_CODE)!=0) {
1329 InsetTabular * inset = static_cast<InsetTabular *>(
1330 view()->theLockingInset()->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE));
1331 inset->openLayoutDialog(view());
1336 case LFUN_DROP_LAYOUTS_CHOICE:
1337 owner->getToolbar().openLayoutList();
1340 case LFUN_MENU_OPEN_BY_NAME:
1341 owner->getMenubar().openByName(argument);
1342 break; // RVDK_PATCH_5
1344 // --- lyxserver commands ----------------------------
1348 setMessage(owner->buffer()->fileName());
1349 lyxerr[Debug::INFO] << "FNAME["
1350 << owner->buffer()->fileName()
1356 dispatch_buffer = keyseq.print();
1357 lyxserver->notifyClient(dispatch_buffer);
1361 case LFUN_GOTOFILEROW:
1365 istringstream istr(argument.c_str());
1366 istr >> file_name >> row;
1367 // Must replace extension of the file to be .lyx and get full path
1368 string const s(ChangeExtension(file_name, ".lyx"));
1370 // Either change buffer or load the file
1371 if (bufferlist.exists(s)) {
1372 view()->buffer(bufferlist.getBuffer(s));
1374 view()->loadLyXFile(s);
1377 view()->setCursorFromRow(row);
1380 // see BufferView_pimpl::center()
1381 view()->updateScrollbar();
1385 case LFUN_GOTO_PARAGRAPH:
1387 istringstream istr(argument.c_str());
1391 ParIterator par = owner->buffer()->getParFromID(id);
1392 if (par == owner->buffer()->par_iterator_end()) {
1393 lyxerr[Debug::INFO] << "No matching paragraph found! ["
1394 << id << ']' << endl;
1397 lyxerr[Debug::INFO] << "Paragraph " << par->id()
1398 << " found." << endl;
1401 if (view()->theLockingInset())
1402 view()->unlockInset(view()->theLockingInset());
1403 if (par->inInset()) {
1404 FuncRequest cmd(view(), LFUN_INSET_EDIT, "left");
1405 par->inInset()->localDispatch(cmd);
1408 view()->getLyXText()->setCursor(par.pit(), 0);
1409 view()->switchKeyMap();
1410 owner->view_state_changed();
1413 // see BufferView_pimpl::center()
1414 view()->updateScrollbar();
1418 // --- insert characters ----------------------------------------
1420 // --- Mathed stuff. If we are here, there is no locked inset yet.
1421 case LFUN_MATH_EXTERN:
1422 case LFUN_MATH_NUMBER:
1423 case LFUN_MATH_NONUMBER:
1424 case LFUN_MATH_LIMITS:
1426 setErrorMessage(N_("This is only allowed in math mode!"));
1430 // passthrough hat and underscore outside mathed:
1431 case LFUN_SUBSCRIPT:
1432 dispatch(FuncRequest(view(), LFUN_SELFINSERT, "_"));
1434 case LFUN_SUPERSCRIPT:
1435 dispatch(FuncRequest(view(), LFUN_SELFINSERT, "^"));
1438 case LFUN_DIALOG_SHOW: {
1439 string const name = ev.getArg(0);
1440 string data = trim(ev.argument.substr(name.size()));
1442 if (name == "character") {
1443 data = freefont2string();
1445 owner->getDialogs().show("character", data);
1446 } else if (name == "document")
1447 owner->getDialogs().showDocument();
1448 else if (name == "findreplace")
1449 owner->getDialogs().showSearch();
1450 else if (name == "forks")
1451 owner->getDialogs().showForks();
1452 else if (name == "preamble")
1453 owner->getDialogs().showPreamble();
1454 else if (name == "preferences")
1455 owner->getDialogs().showPreferences();
1456 else if (name == "print")
1457 owner->getDialogs().showPrint();
1458 else if (name == "spellchecker")
1459 owner->getDialogs().showSpellchecker();
1461 owner->getDialogs().show(name, data);
1465 case LFUN_DIALOG_SHOW_NEW_INSET: {
1466 string const & name = argument;
1468 if (name == "bibitem" ||
1470 name == "include" ||
1475 InsetCommandParams p(name);
1476 data = InsetCommandMailer::params2string(name, p);
1477 } else if (name == "citation") {
1478 InsetCommandParams p("cite");
1479 data = InsetCommandMailer::params2string(name, p);
1481 owner->getDialogs().show(name, data, 0);
1485 case LFUN_DIALOG_SHOW_NEXT_INSET: {
1489 case LFUN_INSET_DIALOG_SHOW: {
1490 LyXText * lt = view()->getLyXText();
1491 InsetOld * inset = lt->getInset();
1493 FuncRequest cmd(view(), LFUN_INSET_DIALOG_SHOW);
1494 inset->localDispatch(cmd);
1499 case LFUN_DIALOG_UPDATE: {
1500 string const & name = argument;
1501 // Can only update a dialog connected to an existing inset
1502 InsetBase * inset = owner->getDialogs().getOpenInset(name);
1504 FuncRequest fr(view(), LFUN_INSET_DIALOG_UPDATE,
1506 inset->localDispatch(fr);
1507 } else if (name == "paragraph") {
1508 dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
1513 case LFUN_DIALOG_HIDE:
1514 Dialogs::hide(argument, 0);
1517 case LFUN_DIALOG_DISCONNECT_INSET:
1518 owner->getDialogs().disconnect(argument);
1521 case LFUN_CHILDOPEN:
1523 string const filename =
1524 MakeAbsPath(argument,
1525 owner->buffer()->filePath());
1526 setMessage(N_("Opening child document ") +
1527 MakeDisplayPath(filename) + "...");
1528 view()->savePosition(0);
1529 if (bufferlist.exists(filename))
1530 view()->buffer(bufferlist.getBuffer(filename));
1532 view()->loadLyXFile(filename);
1536 case LFUN_TOGGLECURSORFOLLOW:
1537 lyxrc.cursor_follows_scrollbar = !lyxrc.cursor_follows_scrollbar;
1541 owner->getIntl().KeyMapOn(false);
1544 case LFUN_KMAP_PRIM:
1545 owner->getIntl().KeyMapPrim();
1549 owner->getIntl().KeyMapSec();
1552 case LFUN_KMAP_TOGGLE:
1553 owner->getIntl().ToggleKeyMap();
1558 // argument contains ';'-terminated commands
1559 while (!argument.empty()) {
1561 argument = split(argument, first, ';');
1567 case LFUN_SAVEPREFERENCES:
1569 Path p(user_lyxdir());
1570 lyxrc.write("preferences");
1574 case LFUN_SCREEN_FONT_UPDATE:
1576 // handle the screen font changes.
1577 lyxrc.set_font_norm_type();
1578 lyx_gui::update_fonts();
1579 // We also need to empty the textcache so that
1580 // the buffer will be formatted correctly after
1583 // Of course we should only do the resize and the textcache.clear
1584 // if values really changed...but not very important right now. (Lgb)
1585 // All visible buffers will need resize
1591 case LFUN_SET_COLOR:
1594 string const x11_name = split(argument, lyx_name, ' ');
1595 if (lyx_name.empty() || x11_name.empty()) {
1596 setErrorMessage(N_("Syntax: set-color <lyx_name>"
1601 bool const graphicsbg_changed =
1602 (lyx_name == lcolor.getLyXName(LColor::graphicsbg) &&
1603 x11_name != lcolor.getX11Name(LColor::graphicsbg));
1605 if (!lcolor.setColor(lyx_name, x11_name)) {
1607 bformat(_("Set-color \"%1$s\" failed "
1608 "- color is undefined or "
1609 "may not be redefined"), lyx_name));
1613 lyx_gui::update_color(lcolor.getFromLyXName(lyx_name));
1615 if (graphicsbg_changed) {
1616 #ifdef WITH_WARNINGS
1617 #warning FIXME!! The graphics cache no longer has a changeDisplay method.
1620 lyx::graphics::GCache & gc =
1621 lyx::graphics::GCache::get();
1622 gc.changeDisplay(true);
1631 owner->message(argument);
1634 case LFUN_FORKS_KILL:
1636 if (!isStrInt(argument))
1639 pid_t const pid = strToInt(argument);
1640 ForkedcallsController & fcc = ForkedcallsController::get();
1645 case LFUN_TOOLTIPS_TOGGLE:
1646 owner->getDialogs().toggleTooltips();
1649 case LFUN_EXTERNAL_EDIT: {
1651 .localDispatch(FuncRequest(view(), action, argument));
1656 // Then if it was none of the above
1657 // Trying the BufferView::pimpl dispatch:
1658 if (!view()->dispatch(ev))
1659 lyxerr << "A truly unknown func ["
1660 << lyxaction.getActionName(ev.action) << "]!"
1667 view()->owner()->updateLayoutChoice();
1669 if (view()->available()) {
1670 if (view()->fitCursor()) {
1671 //lyxerr << "LyXFunc->fitCursor->update" << endl;
1675 // If we executed a mutating lfun, mark the buffer as dirty
1676 if (!getStatus(ev).disabled()
1677 && !lyxaction.funcHasFlag(ev.action, LyXAction::NoBuffer)
1678 && !lyxaction.funcHasFlag(ev.action, LyXAction::ReadOnly))
1679 view()->buffer()->markDirty();
1682 sendDispatchMessage(getMessage(), ev, verbose);
1686 void LyXFunc::sendDispatchMessage(string const & msg, FuncRequest const & ev, bool verbose)
1688 owner->updateMenubar();
1689 owner->updateToolbar();
1691 if (ev.action == LFUN_SELFINSERT || !verbose) {
1692 lyxerr[Debug::ACTION] << "dispatch msg is " << msg << endl;
1694 owner->message(msg);
1698 string dispatch_msg = msg;
1699 if (!dispatch_msg.empty())
1700 dispatch_msg += ' ';
1702 string comname = lyxaction.getActionName(ev.action);
1704 int pseudoaction = ev.action;
1705 bool argsadded = false;
1707 if (!ev.argument.empty()) {
1708 // the pseudoaction is useful for the bindings
1709 pseudoaction = lyxaction.searchActionArg(ev.action, ev.argument);
1711 if (pseudoaction == LFUN_UNKNOWN_ACTION) {
1712 pseudoaction = ev.action;
1714 comname += ' ' + ev.argument;
1719 string const shortcuts = toplevel_keymap->findbinding(pseudoaction);
1721 if (!shortcuts.empty()) {
1722 comname += ": " + shortcuts;
1723 } else if (!argsadded && !ev.argument.empty()) {
1724 comname += ' ' + ev.argument;
1727 if (!comname.empty()) {
1728 comname = rtrim(comname);
1729 dispatch_msg += '(' + comname + ')';
1732 lyxerr[Debug::ACTION] << "verbose dispatch msg " << dispatch_msg << endl;
1733 if (!dispatch_msg.empty())
1734 owner->message(dispatch_msg);
1738 void LyXFunc::setupLocalKeymap()
1740 keyseq.stdmap = keyseq.curmap = toplevel_keymap.get();
1741 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap.get();
1745 void LyXFunc::menuNew(string const & name, bool fromTemplate)
1747 string initpath = lyxrc.document_path;
1748 string filename(name);
1750 if (view()->available()) {
1751 string const trypath = owner->buffer()->filePath();
1752 // If directory is writeable, use this as default.
1753 if (IsDirWriteable(trypath))
1757 static int newfile_number;
1759 if (filename.empty()) {
1760 filename = AddName(lyxrc.document_path,
1761 "newfile" + tostr(++newfile_number) + ".lyx");
1762 FileInfo fi(filename);
1763 while (bufferlist.exists(filename) || fi.readable()) {
1765 filename = AddName(lyxrc.document_path,
1766 "newfile" + tostr(newfile_number) +
1768 fi.newFile(filename);
1772 // The template stuff
1775 FileDialog fileDlg(_("Select template file"),
1776 LFUN_SELECT_FILE_SYNC,
1777 make_pair(string(_("Documents|#o#O")),
1778 string(lyxrc.document_path)),
1779 make_pair(string(_("Templates|#T#t")),
1780 string(lyxrc.template_path)));
1782 FileDialog::Result result =
1783 fileDlg.open(lyxrc.template_path,
1784 _("*.lyx| LyX Documents (*.lyx)"));
1786 if (result.first == FileDialog::Later)
1789 string const fname = result.second;
1796 view()->newFile(filename, templname, !name.empty());
1800 void LyXFunc::open(string const & fname)
1802 string initpath = lyxrc.document_path;
1804 if (view()->available()) {
1805 string const trypath = owner->buffer()->filePath();
1806 // If directory is writeable, use this as default.
1807 if (IsDirWriteable(trypath))
1813 if (fname.empty()) {
1814 FileDialog fileDlg(_("Select document to open"),
1816 make_pair(string(_("Documents|#o#O")),
1817 string(lyxrc.document_path)),
1818 make_pair(string(_("Examples|#E#e")),
1819 string(AddPath(system_lyxdir(), "examples"))));
1821 FileDialog::Result result =
1822 fileDlg.open(initpath,
1823 _("*.lyx| LyX Documents (*.lyx)"));
1825 if (result.first == FileDialog::Later)
1828 filename = result.second;
1830 // check selected filename
1831 if (filename.empty()) {
1832 owner->message(_("Canceled."));
1838 // get absolute path of file and add ".lyx" to the filename if
1840 string const fullpath = FileSearch(string(), filename, "lyx");
1841 if (!fullpath.empty()) {
1842 filename = fullpath;
1845 string const disp_fn(MakeDisplayPath(filename));
1847 // if the file doesn't exist, let the user create one
1848 FileInfo const f(filename, true);
1850 // the user specifically chose this name. Believe them.
1851 view()->newFile(filename, "", true);
1855 owner->message(bformat(_("Opening document %1$s..."), disp_fn));
1858 if (view()->loadLyXFile(filename)) {
1859 str2 = bformat(_("Document %1$s opened."), disp_fn);
1861 str2 = bformat(_("Could not open document %1$s"), disp_fn);
1863 owner->message(str2);
1867 void LyXFunc::doImport(string const & argument)
1870 string filename = split(argument, format, ' ');
1872 lyxerr[Debug::INFO] << "LyXFunc::doImport: " << format
1873 << " file: " << filename << endl;
1875 // need user interaction
1876 if (filename.empty()) {
1877 string initpath = lyxrc.document_path;
1879 if (view()->available()) {
1880 string const trypath = owner->buffer()->filePath();
1881 // If directory is writeable, use this as default.
1882 if (IsDirWriteable(trypath))
1886 string const text = bformat(_("Select %1$s file to import"),
1887 formats.prettyName(format));
1889 FileDialog fileDlg(text,
1891 make_pair(string(_("Documents|#o#O")),
1892 string(lyxrc.document_path)),
1893 make_pair(string(_("Examples|#E#e")),
1894 string(AddPath(system_lyxdir(), "examples"))));
1896 string const extension = "*." + formats.extension(format)
1897 + "| " + formats.prettyName(format)
1898 + " (*." + formats.extension(format) + ')';
1900 FileDialog::Result result = fileDlg.open(initpath,
1903 if (result.first == FileDialog::Later)
1906 filename = result.second;
1908 // check selected filename
1909 if (filename.empty())
1910 owner->message(_("Canceled."));
1913 if (filename.empty())
1916 // get absolute path of file
1917 filename = MakeAbsPath(filename);
1919 string const lyxfile = ChangeExtension(filename, ".lyx");
1921 // Check if the document already is open
1922 if (lyx_gui::use_gui && bufferlist.exists(lyxfile)) {
1923 if (!bufferlist.close(bufferlist.getBuffer(lyxfile), true)) {
1924 owner->message(_("Canceled."));
1929 // if the file exists already, and we didn't do
1930 // -i lyx thefile.lyx, warn
1931 if (FileInfo(lyxfile, true).exist() && filename != lyxfile) {
1932 string const file = MakeDisplayPath(lyxfile, 30);
1934 string text = bformat(_("The document %1$s already exists.\n\n"
1935 "Do you want to over-write that document?"), file);
1936 int const ret = Alert::prompt(_("Over-write document?"),
1937 text, 0, 1, _("&Over-write"), _("&Cancel"));
1940 owner->message(_("Canceled."));
1945 Importer::Import(owner, filename, format);
1949 void LyXFunc::closeBuffer()
1951 if (bufferlist.close(owner->buffer(), true) && !quitting) {
1952 if (bufferlist.empty()) {
1953 // need this otherwise SEGV may occur while
1954 // trying to set variables that don't exist
1955 // since there's no current buffer
1956 owner->getDialogs().hideBufferDependent();
1958 view()->buffer(bufferlist.first());
1964 // Each "owner" should have it's own message method. lyxview and
1965 // the minibuffer would use the minibuffer, but lyxserver would
1966 // send an ERROR signal to its client. Alejandro 970603
1967 // This func is bit problematic when it comes to NLS, to make the
1968 // lyx servers client be language indepenent we must not translate
1969 // strings sent to this func.
1970 void LyXFunc::setErrorMessage(string const & m) const
1972 dispatch_buffer = m;
1977 void LyXFunc::setMessage(string const & m) const
1979 dispatch_buffer = m;
1983 void LyXFunc::setStatusMessage(string const & m) const
1989 string const LyXFunc::view_status_message()
1991 // When meta-fake key is pressed, show the key sequence so far + "M-".
1993 return keyseq.print() + "M-";
1996 // Else, when a non-complete key sequence is pressed,
1997 // show the available options.
1998 if (keyseq.length() > 0 && !keyseq.deleted()) {
1999 return keyseq.printOptions();
2002 if (!view()->available())
2003 return _("Welcome to LyX!");
2005 return currentState(view());
2009 BufferView * LyXFunc::view() const
2011 BOOST_ASSERT(owner);
2012 return owner->view().get();
2016 bool LyXFunc::wasMetaKey() const
2018 return (meta_fake_bit != key_modifier::none);