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"
34 #include "bufferlist.h"
35 #include "BufferView.h"
36 #include "ColorHandler.h"
37 #include "lyxserver.h"
41 #include "LyXAction.h"
42 #include "insets/inseturl.h"
43 #include "insets/insetlatexaccent.h"
44 #include "insets/insettoc.h"
45 #include "insets/insetref.h"
46 #include "insets/insetparent.h"
47 #include "insets/insetindex.h"
48 #include "insets/insetinclude.h"
49 #include "insets/insetbib.h"
50 #include "insets/insetcite.h"
51 #include "insets/insettext.h"
52 #include "insets/insetert.h"
53 #include "insets/insetexternal.h"
54 #include "insets/insetgraphics.h"
55 #include "insets/insetfoot.h"
56 #include "insets/insetmarginal.h"
57 #include "insets/insetminipage.h"
58 #include "insets/insetfloat.h"
60 #include "insets/insetlist.h"
61 #include "insets/insettheorem.h"
63 #include "insets/insettabular.h"
64 #include "insets/insetcaption.h"
65 #include "mathed/formulamacro.h"
66 #include "mathed/math_cursor.h"
67 #include "mathed/math_inset.h"
68 #include "minibuffer.h"
71 #include "lyx_gui_misc.h"
72 #include "support/filetools.h"
73 #include "support/FileInfo.h"
74 #include "support/syscall.h"
75 #include "support/lstrings.h"
76 #include "support/path.h"
77 #include "support/lyxfunctional.h"
82 #include "trans_mgr.h"
85 #include "bufferview_funcs.h"
86 #include "frontends/FileDialog.h"
87 #include "frontends/Dialogs.h"
88 #include "frontends/Toolbar.h"
89 #include "frontends/Menubar.h"
90 #include "frontends/Alert.h"
91 #include "FloatList.h"
92 #include "converter.h"
95 #include "FontLoader.h"
96 #include "TextCache.h"
98 #include "undo_funcs.h"
99 #include "ParagraphParameters.h"
100 #include "figureForm.h"
103 using std::make_pair;
107 extern BufferList bufferlist;
108 extern LyXServer * lyxserver;
109 extern bool selection_possible;
110 extern void MenuSendto();
112 extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
114 extern void show_symbols_form(LyXFunc *);
116 extern LyXAction lyxaction;
118 extern tex_accent_struct get_accent(kb_action action);
120 extern LyXTextClass::size_type current_layout;
122 extern void ShowLatexLog();
128 class MiniBufferController : public SigC::Object {
131 MiniBufferController() {
135 &MiniBufferController::receiveCommand));
139 &MiniBufferController::receiveArg));
142 void receiveCmd(string const & cmd) {}
144 void receiveArg(string const & arg) {}
152 MiniBufferController mb_ctrl;
158 /* === globals =========================================================== */
160 // Initialization of static member var
161 bool LyXFunc::show_sc = true;
164 LyXFunc::LyXFunc(LyXView * o)
168 lyx_dead_action = LFUN_NOACTION;
169 lyx_calling_dead_action = LFUN_NOACTION;
175 LyXText * LyXFunc::TEXT(bool flag = true) const
178 return owner->view()->text;
179 return owner->view()->getLyXText();
183 // I changed this func slightly. I commented out the ...FinishUndo(),
184 // this means that all places that used to have a moveCursorUpdate, now
185 // have a ...FinishUndo() as the preceeding statement. I have also added
186 // a moveCursorUpdate to some of the functions that updated the cursor, but
187 // that did not show its new position.
189 void LyXFunc::moveCursorUpdate(bool flag, bool selecting)
191 if (selecting || TEXT(flag)->selection.mark()) {
192 TEXT(flag)->setSelection(owner->view());
193 if (TEXT(flag)->bv_owner)
194 owner->view()->toggleToggle();
196 owner->view()->update(TEXT(flag), BufferView::SELECT|BufferView::FITCUR);
197 owner->view()->showCursor();
199 /* ---> Everytime the cursor is moved, show the current font state. */
200 // should this too me moved out of this func?
201 owner->view()->setState();
205 void LyXFunc::handleKeyFunc(kb_action action)
207 char c = keyseq.getiso();
209 if (keyseq.length != -1) c = 0;
211 owner->getIntl()->getTrans()
212 .deadkey(c, get_accent(action).accent, TEXT(false));
213 // Need to reset, in case the minibuffer calls these
217 // copied verbatim from do_accent_char
218 owner->view()->update(TEXT(false),
219 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
220 TEXT(false)->selection.cursor = TEXT(false)->cursor;
224 void LyXFunc::processKeySym(KeySym keysym, unsigned int state)
228 if (lyxerr.debugging(Debug::KEY)) {
229 char const * tmp = XKeysymToString(keysym);
230 string const stm = (tmp ? tmp : "");
231 lyxerr << "KeySym is "
234 << keysym << "] State is ["
238 // Do nothing if we have nothing (JMarc)
239 if (keysym == NoSymbol) {
240 lyxerr[Debug::KEY] << "Empty kbd action (probably composing)"
245 // Can we be sure that this will work for all X Window
246 // implementations? (Lgb)
247 // This code snippet makes lyx ignore some keys. Perhaps
248 // all of them should be explictly mentioned?
249 if ((keysym >= XK_Shift_L && keysym <= XK_Hyper_R)
250 || keysym == XK_Mode_switch || keysym == 0x0) {
254 // Do a one-deep top-level lookup for
255 // cancel and meta-fake keys. RVDK_PATCH_5
256 cancel_meta_seq.reset();
258 int action = cancel_meta_seq.addkey(keysym, state
259 &(ShiftMask|ControlMask
261 if (lyxerr.debugging(Debug::KEY)) {
262 lyxerr << "action first set to [" << action << "]" << endl;
265 // When not cancel or meta-fake, do the normal lookup.
266 // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
267 // Mostly, meta_fake_bit = 0. RVDK_PATCH_5.
268 if ((action != LFUN_CANCEL) && (action != LFUN_META_FAKE)) {
269 if (lyxerr.debugging(Debug::KEY)) {
270 lyxerr << "meta_fake_bit is ["
271 << meta_fake_bit << "]" << endl;
273 // remove Caps Lock and Mod2 as a modifiers
274 action = keyseq.addkey(keysym,
275 (state | meta_fake_bit)
276 &(ShiftMask|ControlMask
278 if (lyxerr.debugging(Debug::KEY)) {
279 lyxerr << "action now set to ["
280 << action << "]" << endl;
283 // Dont remove this unless you know what you are doing.
286 if (action == 0) action = LFUN_PREFIX;
288 if (lyxerr.debugging(Debug::KEY)) {
291 lyxerr << "Key [action="
297 // already here we know if it any point in going further
298 // why not return already here if action == -1 and
299 // num_bytes == 0? (Lgb)
301 if (keyseq.length > 1 || keyseq.length < -1) {
308 // It is unknown, but what if we remove all
309 // the modifiers? (Lgb)
310 action = keyseq.addkey(keysym, 0);
312 if (lyxerr.debugging(Debug::KEY)) {
313 lyxerr << "Removing modifiers...\n"
314 << "Action now set to ["
315 << action << "]" << endl;
318 owner->message(_("Unknown function."));
323 if (action == LFUN_SELFINSERT) {
324 // This is very X dependant.
325 unsigned int c = keysym;
327 switch (c & 0x0000FF00) {
328 // latin 1 byte 3 = 0
329 case 0x00000000: break;
330 // latin 2 byte 3 = 1
332 // latin 3 byte 3 = 2
334 // latin 4 byte 3 = 3
336 // latin 8 byte 3 = 18 (0x12)
338 // latin 9 byte 3 = 19 (0x13)
347 argument = static_cast<char>(c);
348 lyxerr[Debug::KEY] << "SelfInsert arg[`"
349 << argument << "']" << endl;
352 bool tmp_sc = show_sc;
354 dispatch(action, argument);
361 func_status::value_type LyXFunc::getStatus(int ac) const
363 return getStatus(ac, string());
367 func_status::value_type LyXFunc::getStatus(int ac,
368 string const & not_to_use_arg) const
371 func_status::value_type flag = func_status::OK;
373 Buffer * buf = owner->buffer();
375 if (lyxaction.isPseudoAction(ac))
376 action = lyxaction.retrieveActionArg(ac, argument);
378 action = static_cast<kb_action>(ac);
379 if (!not_to_use_arg.empty())
380 argument = not_to_use_arg; // exept here
383 if (action == LFUN_UNKNOWN_ACTION) {
384 setErrorMessage(N_("Unknown action"));
385 return func_status::Unknown;
388 // Check whether we need a buffer
389 if (!lyxaction.funcHasFlag(action, LyXAction::NoBuffer)) {
390 // Yes we need a buffer, do we have one?
393 // Can we use a readonly buffer?
394 if (buf->isReadonly() &&
395 !lyxaction.funcHasFlag(action,
396 LyXAction::ReadOnly)) {
398 setErrorMessage(N_("Document is read-only"));
399 flag |= func_status::Disabled;
403 setErrorMessage(N_("Command not allowed with"
404 "out any document open"));
405 flag |= func_status::Disabled;
410 // I would really like to avoid having this switch and rather try to
411 // encode this in the function itself.
412 bool disable = false;
415 disable = !Exporter::IsExportable(buf, "dvi")
416 || lyxrc.print_command == "none";
419 disable = argument == "fax" &&
420 !Exporter::IsExportable(buf, argument);
423 disable = buf->undostack.empty();
426 disable = buf->redostack.empty();
428 case LFUN_SPELLCHECK:
429 disable = lyxrc.isp_command == "none";
431 #ifndef HAVE_LIBAIKSAURUS
432 case LFUN_THESAURUS_ENTRY:
437 disable = lyxrc.chktex_command == "none";
440 disable = !Exporter::IsExportable(buf, "program");
443 case LFUN_LAYOUT_TABULAR:
445 if (owner->view()->theLockingInset()) {
446 disable = (owner->view()->theLockingInset()->lyxCode() != Inset::TABULAR_CODE) &&
447 !owner->view()->theLockingInset()->getFirstLockingInsetOfType(Inset::TABULAR_CODE);
451 case LFUN_TABULAR_FEATURE:
453 if (owner->view()->theLockingInset()) {
454 func_status::value_type ret = func_status::Disabled;
455 if (owner->view()->theLockingInset()->lyxCode() == Inset::TABULAR_CODE) {
456 ret = static_cast<InsetTabular *>
457 (owner->view()->theLockingInset())->
459 } else if (owner->view()->theLockingInset()->getFirstLockingInsetOfType(Inset::TABULAR_CODE)) {
460 ret = static_cast<InsetTabular *>
461 (owner->view()->theLockingInset()->
462 getFirstLockingInsetOfType(Inset::TABULAR_CODE))->
468 static InsetTabular inset(*owner->buffer(), 1, 1);
469 func_status::value_type ret;
472 ret = inset.getStatus(argument);
473 if ((ret & func_status::ToggleOn) ||
474 (ret & func_status::ToggleOff))
475 flag |= func_status::ToggleOff;
479 case LFUN_VC_REGISTER:
480 disable = buf->lyxvc.inUse();
482 case LFUN_VC_CHECKIN:
483 disable = !buf->lyxvc.inUse() || buf->isReadonly();
485 case LFUN_VC_CHECKOUT:
486 disable = !buf->lyxvc.inUse() || !buf->isReadonly();
490 case LFUN_VC_HISTORY:
491 disable = !buf->lyxvc.inUse();
493 case LFUN_BOOKMARK_GOTO:
494 disable = !owner->view()->
495 isSavedPosition(strToUnsignedInt(argument));
499 case LFUN_INSET_TOGGLE:
500 disable = (TEXT(false)->getInset() == 0);
503 case LFUN_MATH_VALIGN: {
504 // I think this test can be simplified (Andre')
505 // mathcursor is != 0 iff we are in math mode
506 //Inset * tli = owner->view()->theLockingInset();
507 //if (tli && (tli->lyxCode() == Inset::MATH_CODE
508 // || tli->lyxCode() == Inset::MATHMACRO_CODE)) {
511 char align = mathcursor->valign();
516 if (argument.empty()) {
517 flag = func_status::OK;
520 if (!contains("tcb", argument[0])) {
524 if (argument[0] == align)
525 flag |= func_status::ToggleOn;
527 flag |= func_status::ToggleOff;
532 case LFUN_MATH_HALIGN: {
533 //Inset * tli = owner->view()->theLockingInset();
534 //if (tli && (tli->lyxCode() == Inset::MATH_CODE
535 // || tli->lyxCode() == Inset::MATHMACRO_CODE)) {
537 char align = mathcursor->halign();
542 if (argument.empty()) {
543 flag = func_status::OK;
546 if (!contains("lcr", argument[0])) {
550 if (argument[0] == align)
551 flag |= func_status::ToggleOn;
553 flag |= func_status::ToggleOff;
558 case LFUN_MATH_MUTATE: {
559 Inset * tli = owner->view()->theLockingInset();
560 if (tli && (tli->lyxCode() == Inset::MATH_CODE)) {
561 MathInsetTypes type = mathcursor->formula()->getType();
562 func_status::value_type box = func_status::ToggleOff;
563 if (argument == "inline") {
564 if (type == LM_OT_SIMPLE)
565 box = func_status::ToggleOn;
566 } else if (argument == "display") {
567 if (type == LM_OT_EQUATION)
568 box = func_status::ToggleOn;
569 } else if (argument == "eqnarray") {
570 if (type == LM_OT_EQNARRAY)
571 box = func_status::ToggleOn;
572 } else if (argument == "align") {
573 if (type == LM_OT_ALIGN)
574 box = func_status::ToggleOn;
576 box = func_status::OK;
585 // we just need to be in math mode to enable that
587 case LFUN_MATH_SPACE:
588 case LFUN_MATH_LIMITS:
589 case LFUN_MATH_NONUMBER:
590 case LFUN_MATH_NUMBER:
591 disable = !mathcursor;
594 // we need to be math mode and a math array for that
595 // Hack: halign produces non-zero result iff we are in a math array
596 case LFUN_MATH_ROW_INSERT:
597 case LFUN_MATH_ROW_DELETE:
598 case LFUN_MATH_COLUMN_INSERT:
599 case LFUN_MATH_COLUMN_DELETE:
600 disable = !mathcursor || !mathcursor->halign();
607 // the functions which insert insets
608 Inset::Code code = Inset::NO_CODE;
610 case LFUN_INSET_TEXT:
611 code = Inset::TEXT_CODE;
614 code = Inset::ERT_CODE;
617 case LFUN_INSET_GRAPHICS:
618 code = Inset::GRAPHICS_CODE;
620 case LFUN_INSET_FOOTNOTE:
621 code = Inset::FOOT_CODE;
623 case LFUN_DIALOG_TABULAR_INSERT:
624 case LFUN_INSET_TABULAR:
625 code = Inset::TABULAR_CODE;
627 case LFUN_INSET_EXTERNAL:
628 code = Inset::EXTERNAL_CODE;
630 case LFUN_INSET_MARGINAL:
631 code = Inset::MARGIN_CODE;
633 case LFUN_INSET_MINIPAGE:
634 code = Inset::MINIPAGE_CODE;
636 case LFUN_INSET_FLOAT:
637 case LFUN_INSET_WIDE_FLOAT:
638 code = Inset::FLOAT_CODE;
640 case LFUN_FLOAT_LIST:
641 code = Inset::FLOAT_LIST_CODE;
644 case LFUN_INSET_LIST:
645 code = Inset::LIST_CODE;
647 case LFUN_INSET_THEOREM:
648 code = Inset::THEOREM_CODE;
651 case LFUN_INSET_CAPTION:
652 code = Inset::CAPTION_CODE;
654 case LFUN_INSERT_NOTE:
655 code = Inset::IGNORE_CODE;
657 case LFUN_INSERT_LABEL:
658 code = Inset::LABEL_CODE;
660 case LFUN_REF_INSERT:
661 code = Inset::REF_CODE;
663 case LFUN_CITATION_CREATE:
664 case LFUN_CITATION_INSERT:
665 code = Inset::CITE_CODE;
667 case LFUN_INSERT_BIBTEX:
668 code = Inset::BIBTEX_CODE;
670 case LFUN_INDEX_INSERT:
671 case LFUN_INDEX_INSERT_LAST:
672 case LFUN_INDEX_CREATE:
673 code = Inset::INDEX_CODE;
675 case LFUN_INDEX_PRINT:
676 code = Inset::INDEX_PRINT_CODE;
678 case LFUN_CHILD_INSERT:
679 code = Inset::INCLUDE_CODE;
681 case LFUN_TOC_INSERT:
682 code = Inset::TOC_CODE;
684 case LFUN_PARENTINSERT:
685 code = Inset::PARENT_CODE;
689 case LFUN_INSERT_URL:
690 code = Inset::URL_CODE;
693 // always allow this, since we will inset a raw quote
694 // if an inset is not allowed.
696 case LFUN_HYPHENATION:
697 case LFUN_LIGATURE_BREAK:
699 case LFUN_MENU_SEPARATOR:
701 case LFUN_END_OF_SENTENCE:
702 case LFUN_PROTECTEDSPACE:
703 code = Inset::SPECIALCHAR_CODE;
708 if (code != Inset::NO_CODE
709 && owner->view()->theLockingInset()
710 && !owner->view()->theLockingInset()->insetAllowed(code)) {
715 flag |= func_status::Disabled;
717 // the font related functions (and a few others)
718 func_status::value_type box = func_status::ToggleOff;
719 LyXFont const & font =
720 TEXT(false)->real_current_font;
723 if (font.emph() == LyXFont::ON)
724 box = func_status::ToggleOn;
727 if (font.noun() == LyXFont::ON)
728 box = func_status::ToggleOn;
731 if (font.series() == LyXFont::BOLD_SERIES)
732 box = func_status::ToggleOn;
734 case LFUN_READ_ONLY_TOGGLE:
735 if (buf->isReadonly())
736 box = func_status::ToggleOn;
739 if (TEXT(false)->cursor.par()->params().startOfAppendix())
740 box = func_status::ToggleOn;
743 box = func_status::OK;
752 // temporary dispatch method
753 void LyXFunc::miniDispatch(string const & s)
761 string const LyXFunc::dispatch(string const & s)
763 // Split command string into command and argument
765 string line = frontStrip(s);
766 string const arg = strip(frontStrip(split(line, cmd, ' ')));
768 return dispatch(lyxaction.LookupFunc(cmd), arg);
772 string const LyXFunc::dispatch(int ac,
773 string const & do_not_use_this_arg)
775 lyxerr[Debug::ACTION] << "LyXFunc::Dispatch: action[" << ac
776 <<"] arg[" << do_not_use_this_arg << "]" << endl;
781 // we have not done anything wrong yet.
783 dispatch_buffer.erase();
785 // if action is a pseudo-action, we need the real action
786 if (lyxaction.isPseudoAction(ac)) {
788 action = static_cast<kb_action>
789 (lyxaction.retrieveActionArg(ac, tmparg));
793 action = static_cast<kb_action>(ac);
794 if (!do_not_use_this_arg.empty())
795 argument = do_not_use_this_arg; // except here
798 #ifdef NEW_DISPATCHER
799 // We try do call the most specific dispatcher first:
800 // 1. the lockinginset's dispatch
801 // 2. the bufferview's dispatch
802 // 3. the lyxview's dispatch
805 selection_possible = false;
807 if (owner->view()->available())
808 owner->view()->hideCursor();
810 // We cannot use this function here
811 if (getStatus(ac, do_not_use_this_arg) & func_status::Disabled) {
812 lyxerr[Debug::ACTION] << "LyXFunc::Dispatch: "
813 << lyxaction.getActionName(ac)
814 << " [" << ac << "] is disabled at this location"
816 goto exit_with_message;
819 if (owner->view()->available() && owner->view()->theLockingInset()) {
820 UpdatableInset::RESULT result;
821 if ((action > 1) || ((action == LFUN_UNKNOWN_ACTION) &&
822 (keyseq.length >= -1)))
824 if ((action==LFUN_UNKNOWN_ACTION) && argument.empty()){
825 argument = keyseq.getiso();
827 // Undo/Redo is a bit tricky for insets.
828 if (action == LFUN_UNDO) {
829 #ifdef RETHINK_THIS_FOR_NOW_WE_LEAVE_ALL_UNLOCKED
832 UpdatableInset * inset =
833 owner->view()->theLockingInset()->getLockingInset();
834 int inset_id = inset->id();
835 inset->getCursorPos(owner->view(), slx, sly);
836 owner->view()->unlockInset(inset);
838 owner->view()->unlockInset(owner->view()->theLockingInset());
840 owner->view()->menuUndo();
841 #ifdef RETHINK_THIS_FOR_NOW_WE_LEAVE_ALL_UNLOCKED
843 if (TEXT()->cursor.par()->
844 isInset(TEXT()->cursor.pos())) {
845 inset = static_cast<UpdatableInset*>(
846 TEXT()->cursor.par()->
853 inset = static_cast<UpdatableInset *>(owner->view()->buffer()->getInsetFromID(inset_id));
856 inset->edit(owner->view(),slx,sly,0);
859 } else if (action == LFUN_REDO) {
862 UpdatableInset * inset = owner->view()->
864 inset->getCursorPos(owner->view(), slx, sly);
865 owner->view()->unlockInset(inset);
866 owner->view()->menuRedo();
867 inset = static_cast<UpdatableInset*>(
868 TEXT()->cursor.par()->
872 inset->edit(owner->view(),slx,sly,0);
874 } else if (((result=owner->view()->theLockingInset()->
875 localDispatch(owner->view(), action, argument)) ==
876 UpdatableInset::DISPATCHED) ||
877 (result == UpdatableInset::DISPATCHED_NOUPDATE))
879 else if (result == UpdatableInset::FINISHED) {
880 if (TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params)) {
881 TEXT()->cursorRight(owner->view());
882 moveCursorUpdate(true, false);
886 } else if (result == UpdatableInset::FINISHED_RIGHT) {
887 if (!TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params)) {
888 TEXT()->cursorRight(owner->view());
889 moveCursorUpdate(true, false);
893 } else if (result == UpdatableInset::FINISHED_UP) {
894 if (TEXT()->cursor.row()->previous()) {
895 TEXT()->cursorUp(owner->view());
896 moveCursorUpdate(true, false);
900 } else if (result == UpdatableInset::FINISHED_DOWN) {
901 if (TEXT()->cursor.row()->next())
902 TEXT()->cursorDown(owner->view());
904 TEXT()->cursorRight(owner->view());
905 moveCursorUpdate(true, false);
909 //setMessage(N_("Text mode"));
911 case LFUN_UNKNOWN_ACTION:
912 case LFUN_BREAKPARAGRAPH:
914 TEXT()->cursorRight(owner->view());
915 owner->view()->setState();
919 if (!TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params)) {
920 TEXT()->cursorRight(owner->view());
921 moveCursorUpdate(true, false);
926 if (TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params)) {
927 TEXT()->cursorRight(owner->view());
928 moveCursorUpdate(true, false);
933 if (TEXT()->cursor.row()->next())
934 TEXT()->cursorDown(owner->view());
936 TEXT()->cursorRight(owner->view());
937 moveCursorUpdate(true, false);
951 if (!owner->view()->available()) break;
953 // this function should be used always [asierra060396]
954 UpdatableInset * tli =
955 owner->view()->theLockingInset();
957 UpdatableInset * lock = tli->getLockingInset();
960 owner->view()->unlockInset(tli);
961 TEXT()->cursorRight(owner->view());
962 moveCursorUpdate(true, false);
965 tli->unlockInsetInInset(owner->view(),
973 // --- Misc -------------------------------------------
974 case LFUN_WORDFINDFORWARD :
975 case LFUN_WORDFINDBACKWARD : {
976 static string last_search;
977 string searched_string;
979 if (!argument.empty()) {
980 last_search = argument;
981 searched_string = argument;
983 searched_string = last_search;
985 bool fw = (action == LFUN_WORDFINDBACKWARD);
986 if (!searched_string.empty()) {
987 LyXFind(owner->view(), searched_string, fw);
989 // owner->view()->showCursor();
995 if (owner->view()->available() && !owner->view()->theLockingInset()) {
996 owner->view()->update(TEXT(),
997 BufferView::SELECT|BufferView::FITCUR);
1000 keyseq.print(buf, true);
1001 owner->message(buf);
1005 // --- Misc -------------------------------------------
1006 case LFUN_EXEC_COMMAND:
1008 std::vector<string> allCmds;
1009 std::transform(lyxaction.func_begin(), lyxaction.func_end(),
1010 std::back_inserter(allCmds), lyx::firster());
1011 static std::vector<string> hist;
1012 owner->getMiniBuffer()->getString(MiniBuffer::spaces,
1017 case LFUN_CANCEL: // RVDK_PATCH_5
1020 if (owner->view()->available())
1021 // cancel any selection
1022 dispatch(LFUN_MARK_OFF);
1023 setMessage(N_("Cancel"));
1026 case LFUN_META_FAKE: // RVDK_PATCH_5
1028 meta_fake_bit = Mod1Mask;
1030 keyseq.print(buf, true);
1031 setMessage(buf); // RVDK_PATCH_5
1035 case LFUN_READ_ONLY_TOGGLE:
1036 if (owner->buffer()->lyxvc.inUse()) {
1037 owner->buffer()->lyxvc.toggleReadOnly();
1039 owner->buffer()->setReadonly(
1040 !owner->buffer()->isReadonly());
1044 case LFUN_CENTER: // this is center and redraw.
1045 owner->view()->center();
1048 // --- Menus -----------------------------------------------
1053 case LFUN_MENUNEWTMPLT:
1057 case LFUN_CLOSEBUFFER:
1061 case LFUN_MENUWRITE:
1062 if (!owner->buffer()->isUnnamed()) {
1064 s1 << _("Saving document") << ' '
1065 << MakeDisplayPath(owner->buffer()->fileName() + "...");
1066 owner->message(s1.str().c_str());
1067 MenuWrite(owner->view(), owner->buffer());
1069 WriteAs(owner->view(), owner->buffer());
1073 WriteAs(owner->view(), owner->buffer(), argument);
1076 case LFUN_MENURELOAD:
1081 Exporter::Export(owner->buffer(), argument, true);
1085 Exporter::Preview(owner->buffer(), argument);
1088 case LFUN_BUILDPROG:
1089 Exporter::Export(owner->buffer(), "program", true);
1092 case LFUN_RUNCHKTEX:
1093 MenuRunChktex(owner->buffer());
1096 case LFUN_MENUPRINT:
1097 owner->getDialogs()->showPrint();
1101 if (argument == "custom")
1104 Exporter::Export(owner->buffer(), argument, false);
1122 InsetCommandParams p;
1125 if (action == LFUN_TOCVIEW)
1127 p.setCmdName("tableofcontents");
1129 else if (action == LFUN_LOAVIEW )
1130 p.setCmdName("listof{algorithm}{List of Algorithms}");
1131 else if (action == LFUN_LOFVIEW)
1132 p.setCmdName("listoffigures");
1134 p.setCmdName("listoftables");
1136 owner->getDialogs()->createTOC(p.getAsString());
1140 case LFUN_DIALOG_TABULAR_INSERT:
1141 owner->getDialogs()->showTabularCreate();
1149 AutoSave(owner->view());
1153 owner->view()->menuUndo();
1157 owner->view()->menuRedo();
1160 case LFUN_MENUSEARCH:
1161 owner->getDialogs()->showSearch();
1164 case LFUN_REMOVEERRORS:
1165 if (owner->view()->removeAutoInsets()) {
1166 owner->view()->redraw();
1167 owner->view()->fitCursor();
1172 changeDepth(owner->view(), TEXT(false), 0);
1175 case LFUN_DEPTH_MIN:
1176 changeDepth(owner->view(), TEXT(false), -1);
1179 case LFUN_DEPTH_PLUS:
1180 changeDepth(owner->view(), TEXT(false), 1);
1184 owner->getDialogs()->setUserFreeFont();
1187 case LFUN_RECONFIGURE:
1188 Reconfigure(owner->view());
1192 case LFUN_FLOATSOPERATE:
1193 if (argument == "openfoot")
1194 owner->view()->allFloats(1,0);
1195 else if (argument == "closefoot")
1196 owner->view()->allFloats(0,0);
1197 else if (argument == "openfig")
1198 owner->view()->allFloats(1,1);
1199 else if (argument == "closefig")
1200 owner->view()->allFloats(0,1);
1203 #ifdef WITH_WARNINGS
1204 //#warning Find another implementation here (or another lyxfunc)!
1207 case LFUN_HELP_ABOUTLYX:
1208 owner->getDialogs()->showAboutlyx();
1211 case LFUN_HELP_TEXINFO:
1212 owner->getDialogs()->showTexinfo();
1215 case LFUN_HELP_OPEN:
1217 string const arg = argument;
1219 setErrorMessage(N_("Missing argument"));
1222 owner->prohibitInput();
1223 string const fname = i18nLibFileSearch("doc", arg, "lyx");
1224 if (fname.empty()) {
1225 lyxerr << "LyX: unable to find documentation file `"
1226 << arg << "'. Bad installation?" << endl;
1227 owner->allowInput();
1231 str << _("Opening help file") << ' '
1232 << MakeDisplayPath(fname) << "...";
1233 owner->message(str.str().c_str());
1234 owner->view()->buffer(bufferlist.loadLyXFile(fname, false));
1235 owner->allowInput();
1239 // --- version control -------------------------------
1240 case LFUN_VC_REGISTER:
1242 if (!owner->buffer()->lyxvc.inUse())
1243 owner->buffer()->lyxvc.registrer();
1247 case LFUN_VC_CHECKIN:
1249 if (owner->buffer()->lyxvc.inUse()
1250 && !owner->buffer()->isReadonly())
1251 owner->buffer()->lyxvc.checkIn();
1255 case LFUN_VC_CHECKOUT:
1257 if (owner->buffer()->lyxvc.inUse()
1258 && owner->buffer()->isReadonly())
1259 owner->buffer()->lyxvc.checkOut();
1263 case LFUN_VC_REVERT:
1265 owner->buffer()->lyxvc.revert();
1271 owner->buffer()->lyxvc.undoLast();
1275 case LFUN_VC_HISTORY:
1277 owner->getDialogs()->showVCLogFile();
1281 // --- buffers ----------------------------------------
1283 case LFUN_SWITCHBUFFER:
1284 owner->view()->buffer(bufferlist.getBuffer(argument));
1289 // servercmd: argument must be <file>:<template>
1290 Buffer * tmpbuf = NewLyxFile(argument);
1292 owner->view()->buffer(tmpbuf);
1296 case LFUN_FILE_OPEN:
1300 case LFUN_LATEX_LOG:
1301 owner->getDialogs()->showLogFile();
1306 lyxerr[Debug::INFO] << "LFUN_LAYOUTNO: (arg) " << argument << endl;
1307 int sel = strToInt(argument);
1308 lyxerr[Debug::INFO] << "LFUN_LAYOUTNO: (sel) "<< sel << endl;
1310 // Should this give a setMessage instead?
1312 return string(); // illegal argument
1314 --sel; // sel 1..., but layout 0...
1316 // Pretend we got the name instead.
1317 dispatch(int(LFUN_LAYOUT),
1318 textclasslist.NameOfLayout(owner->view()
1319 ->buffer()->params.textclass,
1324 case LFUN_LAYOUT_DOCUMENT:
1325 owner->getDialogs()->showDocument();
1328 case LFUN_LAYOUT_PARAGRAPH:
1329 owner->getDialogs()->showParagraph();
1332 case LFUN_LAYOUT_CHARACTER:
1333 owner->getDialogs()->showCharacter();
1336 case LFUN_LAYOUT_TABULAR:
1337 if (owner->view()->theLockingInset()) {
1338 if (owner->view()->theLockingInset()->lyxCode()==Inset::TABULAR_CODE) {
1339 InsetTabular * inset = static_cast<InsetTabular *>
1340 (owner->view()->theLockingInset());
1341 inset->openLayoutDialog(owner->view());
1342 } else if (owner->view()->theLockingInset()->
1343 getFirstLockingInsetOfType(Inset::TABULAR_CODE)!=0) {
1344 InsetTabular * inset = static_cast<InsetTabular *>(
1345 owner->view()->theLockingInset()->getFirstLockingInsetOfType(Inset::TABULAR_CODE));
1346 inset->openLayoutDialog(owner->view());
1351 case LFUN_LAYOUT_PREAMBLE:
1352 owner->getDialogs()->showPreamble();
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 (Alert::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 Alert::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 Alert::alert(_("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 (Alert::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() && !Alert::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);