1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2001 The LyX Team.
9 * ====================================================== */
25 #pragma implementation
28 #include "support/lyxalgo.h"
29 #include "support/LAssert.h"
33 #include "bufferlist.h"
34 #include "BufferView.h"
35 #include "ColorHandler.h"
36 #include "lyxserver.h"
40 #include "LyXAction.h"
41 #include "insets/inseturl.h"
42 #include "insets/insetlatexaccent.h"
43 #include "insets/insettoc.h"
44 #include "insets/insetref.h"
45 #include "insets/insetparent.h"
46 #include "insets/insetindex.h"
47 #include "insets/insetinclude.h"
48 #include "insets/insetbib.h"
49 #include "insets/insetcite.h"
50 #include "insets/insettext.h"
51 #include "insets/insetert.h"
52 #include "insets/insetexternal.h"
53 #include "insets/insetgraphics.h"
54 #include "insets/insetfoot.h"
55 #include "insets/insetmarginal.h"
56 #include "insets/insetminipage.h"
57 #include "insets/insetfloat.h"
59 #include "insets/insetlist.h"
60 #include "insets/insettheorem.h"
62 #include "insets/insettabular.h"
63 #include "insets/insetcaption.h"
64 #include "mathed/formulamacro.h"
65 #include "mathed/math_cursor.h"
66 #include "mathed/math_inset.h"
67 #include "minibuffer.h"
70 #include "lyx_gui_misc.h"
71 #include "support/filetools.h"
72 #include "support/FileInfo.h"
73 #include "support/syscall.h"
74 #include "support/lstrings.h"
75 #include "support/path.h"
76 #include "support/lyxfunctional.h"
81 #include "trans_mgr.h"
84 #include "bufferview_funcs.h"
85 #include "frontends/FileDialog.h"
86 #include "frontends/Dialogs.h"
87 #include "frontends/Toolbar.h"
88 #include "frontends/Menubar.h"
89 #include "FloatList.h"
90 #include "converter.h"
93 #include "FontLoader.h"
94 #include "TextCache.h"
96 #include "undo_funcs.h"
97 #include "ParagraphParameters.h"
98 #include "figureForm.h"
101 using std::make_pair;
105 extern BufferList bufferlist;
106 extern LyXServer * lyxserver;
107 extern int greek_kb_flag;
108 extern bool selection_possible;
109 extern void MenuSendto();
111 extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
113 extern void show_symbols_form(LyXFunc *);
115 extern LyXAction lyxaction;
117 extern tex_accent_struct get_accent(kb_action action);
119 extern LyXTextClass::size_type current_layout;
121 extern void ShowLatexLog();
127 class MiniBufferController : public SigC::Object {
130 MiniBufferController() {
134 &MiniBufferController::receiveCommand));
138 &MiniBufferController::receiveArg));
141 void receiveCmd(string const & cmd) {}
143 void receiveArg(string const & arg) {}
151 MiniBufferController mb_ctrl;
157 /* === globals =========================================================== */
159 // Initialization of static member var
160 bool LyXFunc::show_sc = true;
163 LyXFunc::LyXFunc(LyXView * o)
167 lyx_dead_action = LFUN_NOACTION;
168 lyx_calling_dead_action = LFUN_NOACTION;
174 LyXText * LyXFunc::TEXT(bool flag = true) const
177 return owner->view()->text;
178 return owner->view()->getLyXText();
182 // I changed this func slightly. I commented out the ...FinishUndo(),
183 // this means that all places that used to have a moveCursorUpdate, now
184 // have a ...FinishUndo() as the preceeding statement. I have also added
185 // a moveCursorUpdate to some of the functions that updated the cursor, but
186 // that did not show its new position.
188 void LyXFunc::moveCursorUpdate(bool flag, bool selecting)
190 if (selecting || TEXT(flag)->selection.mark()) {
191 TEXT(flag)->setSelection(owner->view());
192 if (TEXT(flag)->bv_owner)
193 owner->view()->toggleToggle();
195 owner->view()->update(TEXT(flag), BufferView::SELECT|BufferView::FITCUR);
196 owner->view()->showCursor();
198 /* ---> Everytime the cursor is moved, show the current font state. */
199 // should this too me moved out of this func?
200 owner->view()->setState();
204 void LyXFunc::handleKeyFunc(kb_action action)
206 char c = keyseq.getiso();
208 if (keyseq.length != -1) c = 0;
210 owner->getIntl()->getTrans()
211 .deadkey(c, get_accent(action).accent, TEXT(false));
212 // Need to reset, in case the minibuffer calls these
216 // copied verbatim from do_accent_char
217 owner->view()->update(TEXT(false),
218 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
219 TEXT(false)->selection.cursor = TEXT(false)->cursor;
223 void LyXFunc::processKeySym(KeySym keysym, unsigned int state)
227 if (lyxerr.debugging(Debug::KEY)) {
228 char const * tmp = XKeysymToString(keysym);
229 string const stm = (tmp ? tmp : "");
230 lyxerr << "KeySym is "
233 << keysym << "] State is ["
237 // Do nothing if we have nothing (JMarc)
238 if (keysym == NoSymbol) {
239 lyxerr[Debug::KEY] << "Empty kbd action (probably composing)"
244 // Can we be sure that this will work for all X-Windows
245 // implementations? (Lgb)
246 // This code snippet makes lyx ignore some keys. Perhaps
247 // all of them should be explictly mentioned?
248 if ((keysym >= XK_Shift_L && keysym <= XK_Hyper_R)
249 || keysym == XK_Mode_switch || keysym == 0x0) {
253 // Do a one-deep top-level lookup for
254 // cancel and meta-fake keys. RVDK_PATCH_5
255 cancel_meta_seq.reset();
257 int action = cancel_meta_seq.addkey(keysym, state
258 &(ShiftMask|ControlMask
260 if (lyxerr.debugging(Debug::KEY)) {
261 lyxerr << "action first set to [" << action << "]" << endl;
264 // When not cancel or meta-fake, do the normal lookup.
265 // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
266 // Mostly, meta_fake_bit = 0. RVDK_PATCH_5.
267 if ((action != LFUN_CANCEL) && (action != LFUN_META_FAKE)) {
268 if (lyxerr.debugging(Debug::KEY)) {
269 lyxerr << "meta_fake_bit is ["
270 << meta_fake_bit << "]" << endl;
272 // remove Caps Lock and Mod2 as a modifiers
273 action = keyseq.addkey(keysym,
274 (state | meta_fake_bit)
275 &(ShiftMask|ControlMask
277 if (lyxerr.debugging(Debug::KEY)) {
278 lyxerr << "action now set to ["
279 << action << "]" << endl;
282 // Dont remove this unless you know what you are doing.
285 if (action == 0) action = LFUN_PREFIX;
287 if (lyxerr.debugging(Debug::KEY)) {
290 lyxerr << "Key [action="
296 // already here we know if it any point in going further
297 // why not return already here if action == -1 and
298 // num_bytes == 0? (Lgb)
300 if (keyseq.length > 1 || keyseq.length < -1) {
307 // It is unknown, but what if we remove all
308 // the modifiers? (Lgb)
309 action = keyseq.addkey(keysym, 0);
311 if (lyxerr.debugging(Debug::KEY)) {
312 lyxerr << "Removing modifiers...\n"
313 << "Action now set to ["
314 << action << "]" << endl;
317 owner->message(_("Unknown function."));
322 if (action == LFUN_SELFINSERT) {
323 // This is very X dependant.
324 unsigned int c = keysym;
326 switch (c & 0x0000FF00) {
327 // latin 1 byte 3 = 0
328 case 0x00000000: break;
329 // latin 2 byte 3 = 1
331 // latin 3 byte 3 = 2
333 // latin 4 byte 3 = 3
335 // latin 8 byte 3 = 18 (0x12)
337 // latin 9 byte 3 = 19 (0x13)
346 argument = static_cast<char>(c);
347 lyxerr[Debug::KEY] << "SelfInsert arg[`"
348 << argument << "']" << endl;
351 bool tmp_sc = show_sc;
353 dispatch(action, argument);
360 func_status::value_type LyXFunc::getStatus(int ac) const
362 return getStatus(ac, string());
366 func_status::value_type LyXFunc::getStatus(int ac,
367 string const & not_to_use_arg) const
370 func_status::value_type flag = func_status::OK;
372 Buffer * buf = owner->buffer();
374 if (lyxaction.isPseudoAction(ac))
375 action = lyxaction.retrieveActionArg(ac, argument);
377 action = static_cast<kb_action>(ac);
378 if (!not_to_use_arg.empty())
379 argument = not_to_use_arg; // exept here
382 if (action == LFUN_UNKNOWN_ACTION) {
383 setErrorMessage(N_("Unknown action"));
384 return func_status::Unknown;
387 // Check whether we need a buffer
388 if (!lyxaction.funcHasFlag(action, LyXAction::NoBuffer)) {
389 // Yes we need a buffer, do we have one?
392 // Can we use a readonly buffer?
393 if (buf->isReadonly() &&
394 !lyxaction.funcHasFlag(action,
395 LyXAction::ReadOnly)) {
397 setErrorMessage(N_("Document is read-only"));
398 flag |= func_status::Disabled;
402 setErrorMessage(N_("Command not allowed with"
403 "out any document open"));
404 flag |= func_status::Disabled;
409 // I would really like to avoid having this switch and rather try to
410 // encode this in the function itself.
411 bool disable = false;
414 disable = !Exporter::IsExportable(buf, "dvi")
415 || lyxrc.print_command == "none";
418 disable = argument == "fax" &&
419 !Exporter::IsExportable(buf, argument);
422 disable = buf->undostack.empty();
425 disable = buf->redostack.empty();
427 case LFUN_SPELLCHECK:
428 disable = lyxrc.isp_command == "none";
431 disable = lyxrc.chktex_command == "none";
434 disable = !Exporter::IsExportable(buf, "program");
437 case LFUN_LAYOUT_TABULAR:
439 if (owner->view()->theLockingInset()) {
440 disable = (owner->view()->theLockingInset()->lyxCode() != Inset::TABULAR_CODE) &&
441 !owner->view()->theLockingInset()->getFirstLockingInsetOfType(Inset::TABULAR_CODE);
445 case LFUN_TABULAR_FEATURE:
447 if (owner->view()->theLockingInset()) {
448 func_status::value_type ret = func_status::Disabled;
449 if (owner->view()->theLockingInset()->lyxCode() == Inset::TABULAR_CODE) {
450 ret = static_cast<InsetTabular *>
451 (owner->view()->theLockingInset())->
453 } else if (owner->view()->theLockingInset()->getFirstLockingInsetOfType(Inset::TABULAR_CODE)) {
454 ret = static_cast<InsetTabular *>
455 (owner->view()->theLockingInset()->
456 getFirstLockingInsetOfType(Inset::TABULAR_CODE))->
462 static InsetTabular inset(*owner->buffer(), 1, 1);
463 func_status::value_type ret;
466 ret = inset.getStatus(argument);
467 if ((ret & func_status::ToggleOn) ||
468 (ret & func_status::ToggleOff))
469 flag |= func_status::ToggleOff;
473 case LFUN_VC_REGISTER:
474 disable = buf->lyxvc.inUse();
476 case LFUN_VC_CHECKIN:
477 disable = !buf->lyxvc.inUse() || buf->isReadonly();
479 case LFUN_VC_CHECKOUT:
480 disable = !buf->lyxvc.inUse() || !buf->isReadonly();
484 case LFUN_VC_HISTORY:
485 disable = !buf->lyxvc.inUse();
487 case LFUN_BOOKMARK_GOTO:
488 disable = !owner->view()->
489 isSavedPosition(strToUnsignedInt(argument));
493 case LFUN_INSET_TOGGLE:
494 disable = (TEXT(false)->getInset() == 0);
497 case LFUN_MATH_VALIGN: {
498 // I think this test can be simplified (Andre')
499 // mathcursor is != 0 iff we are in math mode
500 //Inset * tli = owner->view()->theLockingInset();
501 //if (tli && (tli->lyxCode() == Inset::MATH_CODE
502 // || tli->lyxCode() == Inset::MATHMACRO_CODE)) {
505 char align = mathcursor->valign();
510 if (argument.empty()) {
511 flag = func_status::OK;
514 if (!contains("tcb", argument[0])) {
518 if (argument[0] == align)
519 flag |= func_status::ToggleOn;
521 flag |= func_status::ToggleOff;
526 case LFUN_MATH_HALIGN: {
527 //Inset * tli = owner->view()->theLockingInset();
528 //if (tli && (tli->lyxCode() == Inset::MATH_CODE
529 // || tli->lyxCode() == Inset::MATHMACRO_CODE)) {
531 char align = mathcursor->halign();
536 if (argument.empty()) {
537 flag = func_status::OK;
540 if (!contains("lcr", argument[0])) {
544 if (argument[0] == align)
545 flag |= func_status::ToggleOn;
547 flag |= func_status::ToggleOff;
552 case LFUN_MATH_MUTATE: {
553 Inset * tli = owner->view()->theLockingInset();
554 if (tli && (tli->lyxCode() == Inset::MATH_CODE)) {
555 MathInsetTypes type = mathcursor->formula()->getType();
556 func_status::value_type box = func_status::ToggleOff;
557 if (argument == "inline") {
558 if (type == LM_OT_SIMPLE)
559 box = func_status::ToggleOn;
560 } else if (argument == "display") {
561 if (type == LM_OT_EQUATION)
562 box = func_status::ToggleOn;
563 } else if (argument == "eqnarray") {
564 if (type == LM_OT_EQNARRAY)
565 box = func_status::ToggleOn;
566 } else if (argument == "align") {
567 if (type == LM_OT_ALIGN)
568 box = func_status::ToggleOn;
570 box = func_status::OK;
579 // we just need to be in math mode to enable that
581 case LFUN_MATH_SPACE:
582 case LFUN_MATH_LIMITS:
583 case LFUN_MATH_NONUMBER:
584 case LFUN_MATH_NUMBER:
585 disable = !mathcursor;
588 // we need to be math mode and a math array for that
589 // Hack: halign produces non-zero result iff we are in a math array
590 case LFUN_MATH_ROW_INSERT:
591 case LFUN_MATH_ROW_DELETE:
592 case LFUN_MATH_COLUMN_INSERT:
593 case LFUN_MATH_COLUMN_DELETE:
594 disable = !mathcursor || !mathcursor->halign();
601 // the functions which insert insets
602 Inset::Code code = Inset::NO_CODE;
604 case LFUN_INSET_TEXT:
605 code = Inset::TEXT_CODE;
608 code = Inset::ERT_CODE;
611 case LFUN_INSET_GRAPHICS:
612 code = Inset::GRAPHICS_CODE;
614 case LFUN_INSET_FOOTNOTE:
615 code = Inset::FOOT_CODE;
617 case LFUN_DIALOG_TABULAR_INSERT:
618 case LFUN_INSET_TABULAR:
619 code = Inset::TABULAR_CODE;
621 case LFUN_INSET_EXTERNAL:
622 code = Inset::EXTERNAL_CODE;
624 case LFUN_INSET_MARGINAL:
625 code = Inset::MARGIN_CODE;
627 case LFUN_INSET_MINIPAGE:
628 code = Inset::MINIPAGE_CODE;
630 case LFUN_INSET_FLOAT:
631 case LFUN_INSET_WIDE_FLOAT:
632 code = Inset::FLOAT_CODE;
634 case LFUN_FLOAT_LIST:
635 code = Inset::FLOAT_LIST_CODE;
638 case LFUN_INSET_LIST:
639 code = Inset::LIST_CODE;
641 case LFUN_INSET_THEOREM:
642 code = Inset::THEOREM_CODE;
645 case LFUN_INSET_CAPTION:
646 code = Inset::CAPTION_CODE;
648 case LFUN_INSERT_NOTE:
649 code = Inset::IGNORE_CODE;
651 case LFUN_INSERT_LABEL:
652 code = Inset::LABEL_CODE;
654 case LFUN_REF_INSERT:
655 code = Inset::REF_CODE;
657 case LFUN_CITATION_CREATE:
658 case LFUN_CITATION_INSERT:
659 code = Inset::CITE_CODE;
661 case LFUN_INSERT_BIBTEX:
662 code = Inset::BIBTEX_CODE;
664 case LFUN_INDEX_INSERT:
665 case LFUN_INDEX_INSERT_LAST:
666 case LFUN_INDEX_CREATE:
667 code = Inset::INDEX_CODE;
669 case LFUN_INDEX_PRINT:
670 code = Inset::INDEX_PRINT_CODE;
672 case LFUN_CHILD_INSERT:
673 code = Inset::INCLUDE_CODE;
675 case LFUN_TOC_INSERT:
676 code = Inset::TOC_CODE;
678 case LFUN_PARENTINSERT:
679 code = Inset::PARENT_CODE;
683 case LFUN_INSERT_URL:
684 code = Inset::URL_CODE;
687 // always allow this, since we will inset a raw quote
688 // if an inset is not allowed.
690 case LFUN_HYPHENATION:
691 case LFUN_LIGATURE_BREAK:
693 case LFUN_MENU_SEPARATOR:
695 case LFUN_END_OF_SENTENCE:
696 case LFUN_PROTECTEDSPACE:
697 code = Inset::SPECIALCHAR_CODE;
702 if (code != Inset::NO_CODE
703 && owner->view()->theLockingInset()
704 && !owner->view()->theLockingInset()->insetAllowed(code)) {
709 flag |= func_status::Disabled;
711 // the font related functions (and a few others)
712 func_status::value_type box = func_status::ToggleOff;
713 LyXFont const & font =
714 TEXT(false)->real_current_font;
717 if (font.emph() == LyXFont::ON)
718 box = func_status::ToggleOn;
721 if (font.noun() == LyXFont::ON)
722 box = func_status::ToggleOn;
725 if (font.series() == LyXFont::BOLD_SERIES)
726 box = func_status::ToggleOn;
728 case LFUN_READ_ONLY_TOGGLE:
729 if (buf->isReadonly())
730 box = func_status::ToggleOn;
733 if (TEXT(false)->cursor.par()->params().startOfAppendix())
734 box = func_status::ToggleOn;
737 box = func_status::OK;
746 // temporary dispatch method
747 void LyXFunc::miniDispatch(string const & s)
755 string const LyXFunc::dispatch(string const & s)
757 // Split command string into command and argument
759 string line = frontStrip(s);
760 string const arg = strip(frontStrip(split(line, cmd, ' ')));
762 return dispatch(lyxaction.LookupFunc(cmd), arg);
766 string const LyXFunc::dispatch(int ac,
767 string const & do_not_use_this_arg)
769 lyxerr[Debug::ACTION] << "LyXFunc::Dispatch: action[" << ac
770 <<"] arg[" << do_not_use_this_arg << "]" << endl;
775 // we have not done anything wrong yet.
777 dispatch_buffer.erase();
779 // if action is a pseudo-action, we need the real action
780 if (lyxaction.isPseudoAction(ac)) {
782 action = static_cast<kb_action>
783 (lyxaction.retrieveActionArg(ac, tmparg));
787 action = static_cast<kb_action>(ac);
788 if (!do_not_use_this_arg.empty())
789 argument = do_not_use_this_arg; // except here
792 #ifdef NEW_DISPATCHER
793 // We try do call the most specific dispatcher first:
794 // 1. the lockinginset's dispatch
795 // 2. the bufferview's dispatch
796 // 3. the lyxview's dispatch
799 selection_possible = false;
801 if (owner->view()->available())
802 owner->view()->hideCursor();
804 // We cannot use this function here
805 if (getStatus(ac, do_not_use_this_arg) & func_status::Disabled) {
806 lyxerr << "LyXFunc::Dispatch: "
807 << lyxaction.getActionName(ac)
808 << " [" << ac << "] is disabled at this location"
810 goto exit_with_message;
813 if (owner->view()->available() && owner->view()->theLockingInset()) {
814 UpdatableInset::RESULT result;
815 if ((action > 1) || ((action == LFUN_UNKNOWN_ACTION) &&
816 (keyseq.length >= -1)))
818 if ((action==LFUN_UNKNOWN_ACTION) && argument.empty()){
819 argument = keyseq.getiso();
821 // Undo/Redo is a bit tricky for insets.
822 if (action == LFUN_UNDO) {
823 #ifdef RETHINK_THIS_FOR_NOW_WE_LEAVE_ALL_UNLOCKED
826 UpdatableInset * inset =
827 owner->view()->theLockingInset()->getLockingInset();
828 int inset_id = inset->id();
829 inset->getCursorPos(owner->view(), slx, sly);
830 owner->view()->unlockInset(inset);
832 owner->view()->unlockInset(owner->view()->theLockingInset());
834 owner->view()->menuUndo();
835 #ifdef RETHINK_THIS_FOR_NOW_WE_LEAVE_ALL_UNLOCKED
837 if (TEXT()->cursor.par()->
838 isInset(TEXT()->cursor.pos())) {
839 inset = static_cast<UpdatableInset*>(
840 TEXT()->cursor.par()->
847 inset = static_cast<UpdatableInset *>(owner->view()->buffer()->getInsetFromID(inset_id));
850 inset->edit(owner->view(),slx,sly,0);
853 } else if (action == LFUN_REDO) {
856 UpdatableInset * inset = owner->view()->
858 inset->getCursorPos(owner->view(), slx, sly);
859 owner->view()->unlockInset(inset);
860 owner->view()->menuRedo();
861 inset = static_cast<UpdatableInset*>(
862 TEXT()->cursor.par()->
866 inset->edit(owner->view(),slx,sly,0);
868 } else if (((result=owner->view()->theLockingInset()->
869 localDispatch(owner->view(), action, argument)) ==
870 UpdatableInset::DISPATCHED) ||
871 (result == UpdatableInset::DISPATCHED_NOUPDATE))
873 else if (result == UpdatableInset::FINISHED) {
874 if (TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params)) {
875 TEXT()->cursorRight(owner->view());
876 moveCursorUpdate(true, false);
880 } else if (result == UpdatableInset::FINISHED_RIGHT) {
881 if (!TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params)) {
882 TEXT()->cursorRight(owner->view());
883 moveCursorUpdate(true, false);
887 } else if (result == UpdatableInset::FINISHED_UP) {
888 if (TEXT()->cursor.row()->previous()) {
889 TEXT()->cursorUp(owner->view());
890 moveCursorUpdate(true, false);
894 } else if (result == UpdatableInset::FINISHED_DOWN) {
895 if (TEXT()->cursor.row()->next())
896 TEXT()->cursorDown(owner->view());
898 TEXT()->cursorRight(owner->view());
899 moveCursorUpdate(true, false);
903 //setMessage(N_("Text mode"));
905 case LFUN_UNKNOWN_ACTION:
906 case LFUN_BREAKPARAGRAPH:
908 TEXT()->cursorRight(owner->view());
909 owner->view()->setState();
913 if (!TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params)) {
914 TEXT()->cursorRight(owner->view());
915 moveCursorUpdate(true, false);
920 if (TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params)) {
921 TEXT()->cursorRight(owner->view());
922 moveCursorUpdate(true, false);
927 if (TEXT()->cursor.row()->next())
928 TEXT()->cursorDown(owner->view());
930 TEXT()->cursorRight(owner->view());
931 moveCursorUpdate(true, false);
945 if (!owner->view()->available()) break;
947 // this function should be used always [asierra060396]
948 UpdatableInset * tli =
949 owner->view()->theLockingInset();
951 UpdatableInset * lock = tli->getLockingInset();
954 owner->view()->unlockInset(tli);
955 TEXT()->cursorRight(owner->view());
956 moveCursorUpdate(true, false);
959 tli->unlockInsetInInset(owner->view(),
967 // --- Misc -------------------------------------------
968 case LFUN_WORDFINDFORWARD :
969 case LFUN_WORDFINDBACKWARD : {
970 static string last_search;
971 string searched_string;
973 if (!argument.empty()) {
974 last_search = argument;
975 searched_string = argument;
977 searched_string = last_search;
979 bool fw = (action == LFUN_WORDFINDBACKWARD);
980 if (!searched_string.empty()) {
981 LyXFind(owner->view(), searched_string, fw);
983 // owner->view()->showCursor();
989 if (owner->view()->available() && !owner->view()->theLockingInset()) {
990 owner->view()->update(TEXT(),
991 BufferView::SELECT|BufferView::FITCUR);
994 keyseq.print(buf, true);
999 // --- Misc -------------------------------------------
1000 case LFUN_EXEC_COMMAND:
1002 std::vector<string> allCmds;
1003 std::transform(lyxaction.func_begin(), lyxaction.func_end(),
1004 std::back_inserter(allCmds), lyx::firster());
1005 static std::vector<string> hist;
1006 owner->getMiniBuffer()->getString(MiniBuffer::spaces,
1011 case LFUN_CANCEL: // RVDK_PATCH_5
1014 if (owner->view()->available())
1015 // cancel any selection
1016 dispatch(LFUN_MARK_OFF);
1017 setMessage(N_("Cancel"));
1020 case LFUN_META_FAKE: // RVDK_PATCH_5
1022 meta_fake_bit = Mod1Mask;
1024 keyseq.print(buf, true);
1025 setMessage(buf); // RVDK_PATCH_5
1029 case LFUN_READ_ONLY_TOGGLE:
1030 if (owner->buffer()->lyxvc.inUse()) {
1031 owner->buffer()->lyxvc.toggleReadOnly();
1033 owner->buffer()->setReadonly(
1034 !owner->buffer()->isReadonly());
1038 case LFUN_CENTER: // this is center and redraw.
1039 owner->view()->center();
1042 // --- Menus -----------------------------------------------
1047 case LFUN_MENUNEWTMPLT:
1051 case LFUN_CLOSEBUFFER:
1055 case LFUN_MENUWRITE:
1056 if (!owner->buffer()->isUnnamed()) {
1058 s1 << _("Saving document") << ' '
1059 << MakeDisplayPath(owner->buffer()->fileName() + "...");
1060 owner->message(s1.str().c_str());
1061 MenuWrite(owner->view(), owner->buffer());
1063 WriteAs(owner->view(), owner->buffer());
1067 WriteAs(owner->view(), owner->buffer(), argument);
1070 case LFUN_MENURELOAD:
1075 Exporter::Export(owner->buffer(), argument, true);
1079 Exporter::Preview(owner->buffer(), argument);
1082 case LFUN_BUILDPROG:
1083 Exporter::Export(owner->buffer(), "program", true);
1086 case LFUN_RUNCHKTEX:
1087 MenuRunChktex(owner->buffer());
1090 case LFUN_MENUPRINT:
1091 owner->getDialogs()->showPrint();
1095 if (argument == "custom")
1098 Exporter::Export(owner->buffer(), argument, false);
1116 InsetCommandParams p;
1119 if (action == LFUN_TOCVIEW)
1121 p.setCmdName("tableofcontents");
1123 else if (action == LFUN_LOAVIEW )
1124 p.setCmdName("listof{algorithm}{List of Algorithms}");
1125 else if (action == LFUN_LOFVIEW)
1126 p.setCmdName("listoffigures");
1128 p.setCmdName("listoftables");
1130 owner->getDialogs()->createTOC(p.getAsString());
1134 case LFUN_DIALOG_TABULAR_INSERT:
1135 owner->getDialogs()->showTabularCreate();
1143 AutoSave(owner->view());
1147 owner->view()->menuUndo();
1151 owner->view()->menuRedo();
1154 case LFUN_MENUSEARCH:
1155 owner->getDialogs()->showSearch();
1158 case LFUN_REMOVEERRORS:
1159 if (owner->view()->removeAutoInsets()) {
1160 owner->view()->redraw();
1161 owner->view()->fitCursor();
1166 changeDepth(owner->view(), TEXT(false), 0);
1169 case LFUN_DEPTH_MIN:
1170 changeDepth(owner->view(), TEXT(false), -1);
1173 case LFUN_DEPTH_PLUS:
1174 changeDepth(owner->view(), TEXT(false), 1);
1178 owner->getDialogs()->setUserFreeFont();
1181 case LFUN_RECONFIGURE:
1182 Reconfigure(owner->view());
1186 case LFUN_FLOATSOPERATE:
1187 if (argument == "openfoot")
1188 owner->view()->allFloats(1,0);
1189 else if (argument == "closefoot")
1190 owner->view()->allFloats(0,0);
1191 else if (argument == "openfig")
1192 owner->view()->allFloats(1,1);
1193 else if (argument == "closefig")
1194 owner->view()->allFloats(0,1);
1197 #ifdef WITH_WARNINGS
1198 #warning Find another implementation here (or another lyxfunc)!
1201 case LFUN_HELP_ABOUTLYX:
1202 owner->getDialogs()->showAboutlyx();
1205 case LFUN_HELP_COPYRIGHT:
1206 case LFUN_HELP_CREDITS:
1209 case LFUN_HELP_OPEN:
1211 string const arg = argument;
1213 setErrorMessage(N_("Missing argument"));
1216 owner->prohibitInput();
1217 string const fname = i18nLibFileSearch("doc", arg, "lyx");
1218 if (fname.empty()) {
1219 lyxerr << "LyX: unable to find documentation file `"
1220 << arg << "'. Bad installation?" << endl;
1221 owner->allowInput();
1225 str << _("Opening help file") << ' '
1226 << MakeDisplayPath(fname) << "...";
1227 owner->message(str.str().c_str());
1228 owner->view()->buffer(bufferlist.loadLyXFile(fname, false));
1229 owner->allowInput();
1233 case LFUN_HELP_VERSION:
1235 // --- version control -------------------------------
1236 case LFUN_VC_REGISTER:
1238 if (!owner->buffer()->lyxvc.inUse())
1239 owner->buffer()->lyxvc.registrer();
1243 case LFUN_VC_CHECKIN:
1245 if (owner->buffer()->lyxvc.inUse()
1246 && !owner->buffer()->isReadonly())
1247 owner->buffer()->lyxvc.checkIn();
1251 case LFUN_VC_CHECKOUT:
1253 if (owner->buffer()->lyxvc.inUse()
1254 && owner->buffer()->isReadonly())
1255 owner->buffer()->lyxvc.checkOut();
1259 case LFUN_VC_REVERT:
1261 owner->buffer()->lyxvc.revert();
1267 owner->buffer()->lyxvc.undoLast();
1271 case LFUN_VC_HISTORY:
1273 owner->getDialogs()->showVCLogFile();
1277 // --- buffers ----------------------------------------
1279 case LFUN_SWITCHBUFFER:
1280 owner->view()->buffer(bufferlist.getBuffer(argument));
1285 // servercmd: argument must be <file>:<template>
1286 Buffer * tmpbuf = NewLyxFile(argument);
1288 owner->view()->buffer(tmpbuf);
1292 case LFUN_FILE_OPEN:
1296 case LFUN_LATEX_LOG:
1297 owner->getDialogs()->showLogFile();
1302 lyxerr[Debug::INFO] << "LFUN_LAYOUTNO: (arg) " << argument << endl;
1303 int sel = strToInt(argument);
1304 lyxerr[Debug::INFO] << "LFUN_LAYOUTNO: (sel) "<< sel << endl;
1306 // Should this give a setMessage instead?
1308 return string(); // illegal argument
1310 --sel; // sel 1..., but layout 0...
1312 // Pretend we got the name instead.
1313 dispatch(int(LFUN_LAYOUT),
1314 textclasslist.NameOfLayout(owner->view()
1315 ->buffer()->params.textclass,
1320 case LFUN_LAYOUT_DOCUMENT:
1321 owner->getDialogs()->showDocument();
1324 case LFUN_LAYOUT_PARAGRAPH:
1325 owner->getDialogs()->showParagraph();
1328 case LFUN_LAYOUT_CHARACTER:
1329 owner->getDialogs()->showCharacter();
1332 case LFUN_LAYOUT_TABULAR:
1333 if (owner->view()->theLockingInset()) {
1334 if (owner->view()->theLockingInset()->lyxCode()==Inset::TABULAR_CODE) {
1335 InsetTabular * inset = static_cast<InsetTabular *>
1336 (owner->view()->theLockingInset());
1337 inset->openLayoutDialog(owner->view());
1338 } else if (owner->view()->theLockingInset()->
1339 getFirstLockingInsetOfType(Inset::TABULAR_CODE)!=0) {
1340 InsetTabular * inset = static_cast<InsetTabular *>(
1341 owner->view()->theLockingInset()->getFirstLockingInsetOfType(Inset::TABULAR_CODE));
1342 inset->openLayoutDialog(owner->view());
1347 case LFUN_LAYOUT_PREAMBLE:
1348 owner->getDialogs()->showPreamble();
1351 case LFUN_LAYOUT_SAVE_DEFAULT:
1352 MenuLayoutSave(owner->view());
1355 case LFUN_DROP_LAYOUTS_CHOICE:
1356 owner->getToolbar()->openLayoutList();
1359 case LFUN_MENU_OPEN_BY_NAME:
1360 owner->getMenubar()->openByName(argument);
1361 break; // RVDK_PATCH_5
1363 case LFUN_SPELLCHECK:
1364 if (lyxrc.isp_command != "none")
1365 owner->getDialogs()->showSpellchecker();
1368 // --- lyxserver commands ----------------------------
1372 setMessage(owner->buffer()->fileName());
1373 lyxerr[Debug::INFO] << "FNAME["
1374 << owner->buffer()->fileName()
1382 dispatch_buffer = buf;
1383 lyxserver->notifyClient(dispatch_buffer);
1387 case LFUN_GOTOFILEROW:
1391 istringstream istr(argument.c_str());
1392 istr >> file_name >> row;
1393 // Must replace extension of the file to be .lyx and get full path
1394 string const s(ChangeExtension(file_name, ".lyx"));
1396 // Either change buffer or load the file
1397 if (bufferlist.exists(s)) {
1398 owner->view()->buffer(bufferlist.getBuffer(s));
1400 owner->view()->buffer(bufferlist.loadLyXFile(s));
1404 owner->view()->setCursorFromRow(row);
1407 owner->view()->center();
1411 case LFUN_GOTO_PARAGRAPH:
1413 istringstream istr(argument.c_str());
1417 Paragraph * par = owner->buffer()->getParFromID(id);
1419 lyxerr[Debug::INFO] << "No matching paragraph found! ["
1420 << id << "]" << std::endl;
1423 lyxerr << "Paragraph " << par->id()
1424 << " found." << endl;
1428 owner->view()->text->setCursor(owner->view(), par, 0);
1429 owner->view()->setState();
1433 owner->view()->center();
1440 int const qa = lyxaction.LookupFunc(argument);
1441 setMessage(lyxaction.helpText(static_cast<kb_action>(qa)));
1445 // --- toolbar ----------------------------------
1446 case LFUN_PUSH_TOOLBAR:
1448 int nth = strToInt(argument);
1450 setErrorMessage(N_("Push-toolbar needs argument > 0"));
1452 owner->getToolbar()->push(nth);
1457 case LFUN_ADD_TO_TOOLBAR:
1459 if (lyxerr.debugging(Debug::GUI)) {
1460 lyxerr << "LFUN_ADD_TO_TOOLBAR:"
1461 "argument = `" << argument << '\'' << endl;
1463 string tmp(argument);
1464 //lyxerr <<string("Argument: ") + argument);
1465 //lyxerr <<string("Tmp : ") + tmp);
1467 setErrorMessage(N_("Usage: toolbar-add-to <LyX command>"));
1469 owner->getToolbar()->add(argument, false);
1470 owner->getToolbar()->set();
1475 // --- insert characters ----------------------------------------
1477 // --- Mathed stuff. If we are here, there is no locked inset yet.
1478 case LFUN_MATH_EXTERN:
1479 case LFUN_MATH_NUMBER:
1480 case LFUN_MATH_NONUMBER:
1481 case LFUN_MATH_LIMITS:
1483 setErrorMessage(N_("This is only allowed in math mode!"));
1487 case LFUN_MATH_PANEL:
1488 owner->getDialogs()->showMathPanel();
1491 case LFUN_CITATION_CREATE:
1493 InsetCommandParams p( "cite" );
1495 if (!argument.empty()) {
1496 // This should be set at source, ie when typing
1497 // "citation-insert foo" in the minibuffer.
1498 // Question: would pybibliographer also need to be
1499 // changed. Suspect so. Leave as-is therefore.
1500 if (contains(argument, "|")) {
1501 p.setContents( token(argument, '|', 0) );
1502 p.setOptions( token(argument, '|', 1) );
1504 p.setContents( argument );
1506 dispatch(LFUN_CITATION_INSERT, p.getAsString());
1508 owner->getDialogs()->createCitation( p.getAsString() );
1512 case LFUN_CHILDOPEN:
1514 string const filename =
1515 MakeAbsPath(argument,
1516 OnlyPath(owner->buffer()->fileName()));
1517 setMessage(N_("Opening child document ") +
1518 MakeDisplayPath(filename) + "...");
1519 owner->view()->savePosition(0);
1520 if (bufferlist.exists(filename))
1521 owner->view()->buffer(bufferlist.getBuffer(filename));
1523 owner->view()->buffer(bufferlist.loadLyXFile(filename));
1527 case LFUN_TOGGLECURSORFOLLOW:
1528 lyxrc.cursor_follows_scrollbar = !lyxrc.cursor_follows_scrollbar;
1531 case LFUN_KMAP_OFF: // keymap off
1532 owner->getIntl()->KeyMapOn(false);
1535 case LFUN_KMAP_PRIM: // primary keymap
1536 owner->getIntl()->KeyMapPrim();
1539 case LFUN_KMAP_SEC: // secondary keymap
1540 owner->getIntl()->KeyMapSec();
1543 case LFUN_KMAP_TOGGLE: // toggle keymap
1544 owner->getIntl()->ToggleKeyMap();
1549 // argument contains ';'-terminated commands
1550 while (argument.find(';') != string::npos) {
1552 argument = split(argument, first, ';');
1558 case LFUN_DIALOG_PREFERENCES:
1559 owner->getDialogs()->showPreferences();
1562 case LFUN_SAVEPREFERENCES:
1564 Path p(user_lyxdir);
1565 lyxrc.write("preferences");
1569 case LFUN_SCREEN_FONT_UPDATE:
1571 // handle the screen font changes.
1573 lyxrc.set_font_norm_type();
1574 fontloader.update();
1575 // Of course we should only do the resize and the textcache.clear
1576 // if values really changed...but not very important right now. (Lgb)
1577 // All visible buffers will need resize
1579 // We also need to empty the textcache so that
1580 // the buffer will be formatted correctly after
1586 case LFUN_SET_COLOR:
1589 string const x11_name = split(argument, lyx_name, ' ');
1590 if (lyx_name.empty() || x11_name.empty()) {
1591 setErrorMessage(N_("Syntax: set-color <lyx_name>"
1596 if (!lcolor.setColor(lyx_name, x11_name)) {
1597 static string const err1 (N_("Set-color \""));
1598 static string const err2 (
1599 N_("\" failed - color is undefined "
1600 "or may not be redefined"));
1601 setErrorMessage(_(err1) + lyx_name + _(err2));
1604 lyxColorHandler->updateColor(lcolor.getFromLyXName(lyx_name));
1605 owner->view()->redraw();
1610 owner->message(argument);
1613 case LFUN_MESSAGE_PUSH:
1614 owner->messagePush(argument);
1617 case LFUN_MESSAGE_POP:
1618 owner->messagePop();
1622 // Then if it was none of the above
1623 if (!owner->view()->Dispatch(action, argument))
1624 lyxerr << "A truly unknown func ["
1625 << lyxaction.getActionName(action) << "]!"
1632 commandshortcut.erase();
1634 if (lyxrc.display_shortcuts && show_sc) {
1635 if (action != LFUN_SELFINSERT) {
1636 // Put name of command and list of shortcuts
1637 // for it in minibuffer
1638 string comname = lyxaction.getActionName(action);
1640 int pseudoaction = action;
1641 bool argsadded = false;
1643 if (!argument.empty()) {
1644 // If we have the command with argument,
1647 lyxaction.searchActionArg(action,
1650 if (pseudoaction == -1) {
1651 pseudoaction = action;
1653 comname += " " + argument;
1658 string const shortcuts =
1659 toplevel_keymap->findbinding(pseudoaction);
1661 if (!shortcuts.empty()) {
1662 comname += ": " + shortcuts;
1663 } else if (!argsadded) {
1664 comname += " " + argument;
1667 if (!comname.empty()) {
1668 comname = strip(comname);
1669 commandshortcut = "(" + comname + ')';
1671 // Here we could even add a small pause,
1672 // to annoy the user and make him learn
1674 // No! That will just annoy, not teach
1675 // anything. The user will read the messages
1676 // if they are interested. (Asger)
1681 string const res = getMessage();
1684 if (!commandshortcut.empty()) {
1685 owner->getMiniBuffer()->addSet(commandshortcut);
1688 string const msg(_(res) + ' ' + commandshortcut);
1689 owner->message(msg);
1696 void LyXFunc::setupLocalKeymap()
1698 keyseq.stdmap = keyseq.curmap = toplevel_keymap.get();
1699 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap.get();
1703 void LyXFunc::menuNew(bool fromTemplate)
1705 string initpath = lyxrc.document_path;
1707 if (owner->view()->available()) {
1708 string const trypath = owner->buffer()->filepath;
1709 // If directory is writeable, use this as default.
1710 if (IsDirWriteable(trypath))
1714 static int newfile_number;
1717 if (lyxrc.new_ask_filename) {
1718 FileDialog fileDlg(owner, _("Enter filename for new document"),
1719 LFUN_SELECT_FILE_SYNC,
1720 make_pair(string(_("Documents")),
1721 string(lyxrc.document_path)),
1722 make_pair(string(_("Templates")),
1723 string(lyxrc.template_path)));
1725 FileDialog::Result result =
1726 fileDlg.Select(initpath,
1727 _("*.lyx|LyX Documents (*.lyx)"),
1730 if (result.second.empty()) {
1731 owner->message(_("Canceled."));
1732 lyxerr[Debug::INFO] << "New Document Cancelled." << endl;
1736 // get absolute path of file and make sure the filename ends
1738 s = MakeAbsPath(result.second);
1739 if (!IsLyXFilename(s))
1742 // Check if the document already is open
1743 if (bufferlist.exists(s)) {
1744 switch (AskConfirmation(_("Document is already open:"),
1745 MakeDisplayPath(s, 50),
1746 _("Do you want to close that document now?\n"
1747 "('No' will just switch to the open version)")))
1749 case 1: // Yes: close the document
1750 if (!bufferlist.close(bufferlist.getBuffer(s)))
1751 // If close is canceled, we cancel here too.
1754 case 2: // No: switch to the open document
1755 owner->view()->buffer(bufferlist.getBuffer(s));
1757 case 3: // Cancel: Do nothing
1758 owner->message(_("Canceled."));
1762 // Check whether the file already exists
1764 if (fi.readable() &&
1765 AskQuestion(_("File already exists:"),
1766 MakeDisplayPath(s, 50),
1767 _("Do you want to open the document?"))) {
1769 string const disp_fn(MakeDisplayPath(s));
1772 str << _("Opening document") << ' '
1773 << disp_fn << "...";
1775 owner->message(str.str().c_str());
1776 //XFlush(fl_get_display());
1777 owner->view()->buffer(bufferlist.loadLyXFile(s));
1779 str2 << _("Document") << ' '
1780 << disp_fn << ' ' << _("opened.");
1782 owner->message(str2.str().c_str());
1787 s = AddName(lyxrc.document_path,
1788 "newfile" + tostr(++newfile_number) + ".lyx");
1790 while (bufferlist.exists(s) || fi.readable()) {
1792 s = AddName(lyxrc.document_path,
1793 "newfile" + tostr(newfile_number) +
1799 // The template stuff
1802 FileDialog fileDlg(owner, _("Select template file"),
1803 LFUN_SELECT_FILE_SYNC,
1804 make_pair(string(_("Documents")),
1805 string(lyxrc.document_path)),
1806 make_pair(string(_("Templates")),
1807 string(lyxrc.template_path)));
1809 FileDialog::Result result =
1810 fileDlg.Select(lyxrc.template_path,
1811 _("*.lyx|LyX Documents (*.lyx)"));
1813 if (result.first == FileDialog::Later)
1816 string const fname = result.second;
1823 // find a free buffer
1824 lyxerr[Debug::INFO] << "Find a free buffer." << endl;
1825 owner->view()->buffer(bufferlist.newFile(s, templname));
1829 void LyXFunc::open(string const & fname)
1831 string initpath = lyxrc.document_path;
1833 if (owner->view()->available()) {
1834 string const trypath = owner->buffer()->filepath;
1835 // If directory is writeable, use this as default.
1836 if (IsDirWriteable(trypath))
1842 if (fname.empty()) {
1843 FileDialog fileDlg(owner, _("Select document to open"),
1845 make_pair(string(_("Documents")),
1846 string(lyxrc.document_path)),
1847 make_pair(string(_("Examples")),
1848 string(AddPath(system_lyxdir, "examples"))));
1850 FileDialog::Result result =
1851 fileDlg.Select(initpath,
1852 "*.lyx|LyX Documents (*.lyx)");
1854 if (result.first == FileDialog::Later)
1857 filename = result.second;
1859 // check selected filename
1860 if (filename.empty()) {
1861 owner->message(_("Canceled."));
1867 // get absolute path of file and add ".lyx" to the filename if
1869 string const fullpath = FileSearch(string(), filename, "lyx");
1870 if (fullpath.empty()) {
1871 WriteAlert(_("Error"), _("Could not find file"), filename);
1875 filename = fullpath;
1878 string const disp_fn(MakeDisplayPath(filename));
1881 str << _("Opening document") << ' ' << disp_fn << "...";
1883 owner->message(str.str().c_str());
1885 Buffer * openbuf = bufferlist.loadLyXFile(filename);
1887 owner->view()->buffer(openbuf);
1889 str << _("Document") << ' ' << disp_fn << ' ' << _("opened.");
1890 owner->message(str.str().c_str());
1893 str << _("Could not open document") << ' ' << disp_fn;
1894 owner->message(str.str().c_str());
1899 // checks for running without gui are missing.
1900 void LyXFunc::doImport(string const & argument)
1903 string filename = split(argument, format, ' ');
1904 lyxerr[Debug::INFO] << "LyXFunc::doImport: " << format
1905 << " file: " << filename << endl;
1907 if (filename.empty()) { // need user interaction
1908 string initpath = lyxrc.document_path;
1910 if (owner->view()->available()) {
1911 string const trypath = owner->buffer()->filepath;
1912 // If directory is writeable, use this as default.
1913 if (IsDirWriteable(trypath))
1917 string const text = _("Select ") + formats.prettyName(format)
1918 + _(" file to import");
1920 FileDialog fileDlg(owner, text,
1922 make_pair(string(_("Documents")),
1923 string(lyxrc.document_path)),
1924 make_pair(string(_("Examples")),
1925 string(AddPath(system_lyxdir, "examples"))));
1927 string const extension = "*." + formats.extension(format)
1928 + "| " + formats.prettyName(format)
1929 + " (*." + formats.extension(format) + ")";
1931 FileDialog::Result result = fileDlg.Select(initpath,
1934 if (result.first == FileDialog::Later)
1937 filename = result.second;
1939 // check selected filename
1940 if (filename.empty())
1941 owner->message(_("Canceled."));
1944 // still no filename? abort
1945 if (filename.empty())
1948 // get absolute path of file
1949 filename = MakeAbsPath(filename);
1951 string const lyxfile = ChangeExtension(filename, ".lyx");
1953 // Check if the document already is open
1954 if (bufferlist.exists(lyxfile)) {
1955 switch (AskConfirmation(_("Document is already open:"),
1956 MakeDisplayPath(lyxfile, 50),
1957 _("Do you want to close that document now?\n"
1958 "('No' will just switch to the open version)")))
1960 case 1: // Yes: close the document
1961 if (!bufferlist.close(bufferlist.getBuffer(lyxfile)))
1962 // If close is canceled, we cancel here too.
1965 case 2: // No: switch to the open document
1966 owner->view()->buffer(bufferlist.getBuffer(lyxfile));
1968 case 3: // Cancel: Do nothing
1969 owner->message(_("Canceled."));
1974 // Check if a LyX document by the same root exists in filesystem
1975 FileInfo const f(lyxfile, true);
1976 if (f.exist() && !AskQuestion(_("A document by the name"),
1977 MakeDisplayPath(lyxfile),
1978 _("already exists. Overwrite?"))) {
1979 owner->message(_("Canceled"));
1982 // filename should be valid now
1984 Importer::Import(owner, filename, format);
1988 void LyXFunc::reloadBuffer()
1990 string const fn = owner->buffer()->fileName();
1991 if (bufferlist.close(owner->buffer()))
1992 owner->view()->buffer(bufferlist.loadLyXFile(fn));
1996 void LyXFunc::closeBuffer()
1998 if (bufferlist.close(owner->buffer()) && !quitting) {
1999 if (bufferlist.empty()) {
2000 // need this otherwise SEGV may occur while trying to
2001 // set variables that don't exist
2002 // since there's no current buffer
2003 owner->getDialogs()->hideBufferDependent();
2005 owner->view()->buffer(bufferlist.first());
2011 // Each "owner" should have it's own message method. lyxview and
2012 // the minibuffer would use the minibuffer, but lyxserver would
2013 // send an ERROR signal to its client. Alejandro 970603
2014 // This func is bit problematic when it comes to NLS, to make the
2015 // lyx servers client be language indepenent we must not translate
2016 // strings sent to this func.
2017 void LyXFunc::setErrorMessage(string const & m) const
2019 dispatch_buffer = m;
2024 void LyXFunc::setMessage(string const & m)
2026 dispatch_buffer = m;
2030 void LyXFunc::initMiniBuffer()
2032 string text = _("Welcome to LyX!");
2034 // When meta-fake key is pressed, show the key sequence so far + "M-".
2040 // Else, when a non-complete key sequence is pressed,
2041 // show the available options.
2042 else if (keyseqUncomplete())
2043 text = keyseqOptions();
2045 // Else, show the buffer state.
2046 else if (owner->view()->available()) {
2047 Buffer * tmpbuf = owner->buffer();
2049 string const nicename =
2050 MakeDisplayPath(tmpbuf->fileName());
2051 // Should we do this instead? (kindo like emacs)
2052 // leaves more room for other information
2055 if (tmpbuf->lyxvc.inUse()) {
2057 text += tmpbuf->lyxvc.versionString();
2059 text += tmpbuf->lyxvc.locker();
2060 if (tmpbuf->isReadonly())
2063 } else if (tmpbuf->isReadonly())
2065 if (!tmpbuf->isLyxClean())
2066 text += _(" (Changed)");
2068 if (text != _("Welcome to LyX!")) // this is a hack
2069 text = _("* No document open *");
2072 owner->message(text);