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 * ====================================================== */
14 #pragma implementation
21 #include "bufferlist.h"
22 #include "BufferView.h"
23 #include "frontends/xforms/ColorHandler.h"
24 #include "lyxserver.h"
28 #include "LyXAction.h"
34 #include "trans_mgr.h"
36 #include "bufferview_funcs.h"
37 #include "minibuffer.h"
39 #include "frontends/LyXView.h"
40 #include "FloatList.h"
41 #include "converter.h"
44 #include "frontends/font_loader.h"
45 #include "TextCache.h"
47 #include "undo_funcs.h"
48 #include "ParagraphParameters.h"
50 #include "insets/inseturl.h"
51 #include "insets/insetlatexaccent.h"
52 #include "insets/insettoc.h"
53 #include "insets/insetref.h"
54 #include "insets/insetparent.h"
55 #include "insets/insetindex.h"
56 #include "insets/insetinclude.h"
57 #include "insets/insetbib.h"
58 #include "insets/insetcite.h"
59 #include "insets/insettext.h"
60 #include "insets/insetert.h"
61 #include "insets/insetexternal.h"
62 #include "insets/insetgraphics.h"
63 #include "insets/insetfoot.h"
64 #include "insets/insetmarginal.h"
65 #include "insets/insetminipage.h"
66 #include "insets/insetfloat.h"
68 #include "insets/insetlist.h"
69 #include "insets/insettheorem.h"
71 #include "insets/insettabular.h"
72 #include "insets/insetcaption.h"
74 #include "mathed/formulamacro.h"
75 #include "mathed/math_cursor.h"
76 #include "mathed/math_inset.h"
78 #include "frontends/FileDialog.h"
79 #include "frontends/Dialogs.h"
80 #include "frontends/Toolbar.h"
81 #include "frontends/Menubar.h"
82 #include "frontends/Alert.h"
84 #include "graphics/GraphicsCache.h"
86 #include "support/lyxalgo.h"
87 #include "support/LAssert.h"
88 #include "support/filetools.h"
89 #include "support/FileInfo.h"
90 #include "support/forkedcontr.h"
91 #include "support/lstrings.h"
92 #include "support/path.h"
93 #include "support/lyxfunctional.h"
105 using std::make_pair;
109 using std::transform;
110 using std::back_inserter;
112 extern BufferList bufferlist;
113 extern LyXServer * lyxserver;
114 extern bool selection_possible;
116 extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
118 extern void show_symbols_form(LyXFunc *);
120 extern LyXAction lyxaction;
122 extern tex_accent_struct get_accent(kb_action action);
124 extern void ShowLatexLog();
130 class MiniBufferController : public SigC::Object {
133 MiniBufferController() {
137 &MiniBufferController::receiveCommand));
141 &MiniBufferController::receiveArg));
144 void receiveCmd(string const & cmd) {}
146 void receiveArg(string const & arg) {}
154 MiniBufferController mb_ctrl;
160 /* === globals =========================================================== */
163 LyXFunc::LyXFunc(LyXView * o)
165 keyseq(toplevel_keymap.get(), toplevel_keymap.get()),
166 cancel_meta_seq(toplevel_keymap.get(), toplevel_keymap.get())
168 meta_fake_bit = key_modifier::none;
169 lyx_dead_action = LFUN_NOACTION;
170 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.getLastKeyEncoded();
209 if (keyseq.length() > 1) {
213 owner->getIntl()->getTransManager()
214 .deadkey(c, get_accent(action).accent, TEXT(false));
215 // Need to clear, in case the minibuffer calls these
218 // copied verbatim from do_accent_char
219 owner->view()->update(TEXT(false),
220 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
221 TEXT(false)->selection.cursor = TEXT(false)->cursor;
225 void LyXFunc::processKeySym(LyXKeySymPtr keysym,
226 key_modifier::state state)
230 if (lyxerr.debugging(Debug::KEY)) {
231 lyxerr << "KeySym is "
232 << keysym->getSymbolName()
235 // Do nothing if we have nothing (JMarc)
236 if ( ! keysym->isOK() ) {
237 lyxerr[Debug::KEY] << "Empty kbd action (probably composing)"
242 if (keysym->isModifier()) {
246 // Do a one-deep top-level lookup for
247 // cancel and meta-fake keys. RVDK_PATCH_5
248 cancel_meta_seq.reset();
250 int action = cancel_meta_seq.addkey(keysym, state);
251 if (lyxerr.debugging(Debug::KEY)) {
252 lyxerr << "action first set to [" << action << "]" << endl;
255 // When not cancel or meta-fake, do the normal lookup.
256 // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
257 // Mostly, meta_fake_bit = key_modifier::none. RVDK_PATCH_5.
258 if ((action != LFUN_CANCEL) && (action != LFUN_META_FAKE)) {
259 // remove Caps Lock and Mod2 as a modifiers
260 action = keyseq.addkey(keysym, (state | meta_fake_bit));
261 if (lyxerr.debugging(Debug::KEY)) {
262 lyxerr << "action now set to ["
263 << action << "]" << endl;
266 // Dont remove this unless you know what you are doing.
267 meta_fake_bit = key_modifier::none;
269 // can this happen now ?
270 if (action == LFUN_NOACTION) {
271 action = LFUN_PREFIX;
274 if (lyxerr.debugging(Debug::KEY)) {
275 lyxerr << "Key [action="
277 << keyseq.print() << "]"
281 // already here we know if it any point in going further
282 // why not return already here if action == -1 and
283 // num_bytes == 0? (Lgb)
285 if (keyseq.length() > 1) {
286 owner->message(keyseq.print());
289 if (action == LFUN_UNKNOWN_ACTION) {
290 // It is unknown, but what if we remove all
291 // the modifiers? (Lgb)
292 action = keyseq.addkey(keysym, key_modifier::none);
294 if (lyxerr.debugging(Debug::KEY)) {
295 lyxerr << "Removing modifiers...\n"
296 << "Action now set to ["
297 << action << "]" << endl;
299 if (action == LFUN_UNKNOWN_ACTION) {
300 owner->message(_("Unknown function."));
305 if (action == LFUN_SELFINSERT) {
306 // This is very X dependent.
307 char c = keysym->getISOEncoded();
313 dispatch(LFUN_SELFINSERT, argument);
314 lyxerr[Debug::KEY] << "SelfInsert arg[`"
315 << argument << "']" << endl;
317 verboseDispatch(action, false);
322 FuncStatus LyXFunc::getStatus(int ac) const
326 action = lyxaction.retrieveActionArg(ac, argument);
327 return getStatus(action, argument);
331 FuncStatus LyXFunc::getStatus(kb_action action,
332 string const & argument) const
335 Buffer * buf = owner->buffer();
337 if (action == LFUN_NOACTION) {
338 setStatusMessage(N_("Nothing to do"));
339 return flag.disabled(true);
342 if (action == LFUN_UNKNOWN_ACTION) {
343 setStatusMessage(N_("Unknown action"));
344 return flag.unknown(true);
347 // the default error message if we disable the command
348 setStatusMessage(N_("Command disabled"));
350 // Check whether we need a buffer
351 if (!lyxaction.funcHasFlag(action, LyXAction::NoBuffer)) {
352 // Yes we need a buffer, do we have one?
355 // Can we use a readonly buffer?
356 if (buf->isReadonly() &&
357 !lyxaction.funcHasFlag(action,
358 LyXAction::ReadOnly)) {
360 setStatusMessage(N_("Document is read-only"));
365 setStatusMessage(N_("Command not allowed with"
366 "out any document open"));
367 return flag.disabled(true);
371 UpdatableInset * tli = owner->view()->theLockingInset();
373 // I would really like to avoid having this switch and rather try to
374 // encode this in the function itself.
375 bool disable = false;
378 disable = !Exporter::IsExportable(buf, "dvi")
379 || lyxrc.print_command == "none";
382 disable = argument == "fax" &&
383 !Exporter::IsExportable(buf, argument);
386 disable = buf->undostack.empty();
389 disable = buf->redostack.empty();
391 case LFUN_SPELLCHECK:
392 disable = lyxrc.isp_command == "none";
394 #ifndef HAVE_LIBAIKSAURUS
395 case LFUN_THESAURUS_ENTRY:
400 disable = lyxrc.chktex_command == "none";
403 disable = !Exporter::IsExportable(buf, "program");
406 case LFUN_LAYOUT_TABULAR:
408 || (tli->lyxCode() != Inset::TABULAR_CODE
409 && !tli->getFirstLockingInsetOfType(Inset::TABULAR_CODE));
413 case LFUN_LAYOUT_PARAGRAPH: {
414 Inset * inset = TEXT(false)->cursor.par()->inInset();
415 disable = inset && inset->forceDefaultParagraphs(inset);
419 case LFUN_TABULAR_FEATURE:
423 //ret.disabled(true);
424 if (tli->lyxCode() == Inset::TABULAR_CODE) {
425 ret = static_cast<InsetTabular *>(tli)
426 ->getStatus(argument);
427 } else if (tli->getFirstLockingInsetOfType(Inset::TABULAR_CODE)) {
428 ret = static_cast<InsetTabular *>
429 (tli->getFirstLockingInsetOfType(Inset::TABULAR_CODE))
430 ->getStatus(argument);
435 static InsetTabular inset(*owner->buffer(), 1, 1);
439 ret = inset.getStatus(argument);
440 if (ret.onoff(true) || ret.onoff(false))
441 flag.setOnOff(false);
445 case LFUN_VC_REGISTER:
446 disable = buf->lyxvc.inUse();
448 case LFUN_VC_CHECKIN:
449 disable = !buf->lyxvc.inUse() || buf->isReadonly();
451 case LFUN_VC_CHECKOUT:
452 disable = !buf->lyxvc.inUse() || !buf->isReadonly();
456 case LFUN_VC_HISTORY:
457 disable = !buf->lyxvc.inUse();
459 case LFUN_BOOKMARK_GOTO:
460 disable = !owner->view()->
461 isSavedPosition(strToUnsignedInt(argument));
465 case LFUN_INSET_TOGGLE: {
466 LyXText * lt = owner->view()->getLyXText();
467 disable = !(isEditableInset(lt->getInset())
469 && lt->inset_owner->owner()
470 && lt->inset_owner->owner()->isOpen()));
473 case LFUN_MATH_VALIGN:
474 if (mathcursor && mathcursor->formula()->getType() != LM_OT_SIMPLE) {
475 char align = mathcursor->valign();
480 if (argument.empty()) {
484 if (!contains("tcb", argument[0])) {
488 flag.setOnOff(argument[0] == align);
493 case LFUN_MATH_HALIGN:
494 if (mathcursor && mathcursor->formula()->getType() != LM_OT_SIMPLE) {
495 char align = mathcursor->halign();
500 if (argument.empty()) {
504 if (!contains("lcr", argument[0])) {
508 flag.setOnOff(argument[0] == align);
513 case LFUN_MATH_MUTATE:
514 if (tli && (tli->lyxCode() == Inset::MATH_CODE)) {
515 MathInsetTypes type = mathcursor->formula()->getType();
516 if (argument == "inline") {
517 flag.setOnOff(type == LM_OT_SIMPLE);
518 } else if (argument == "display") {
519 flag.setOnOff(type == LM_OT_EQUATION);
520 } else if (argument == "eqnarray") {
521 flag.setOnOff(type == LM_OT_EQNARRAY);
522 } else if (argument == "align") {
523 flag.setOnOff(type == LM_OT_ALIGN);
524 } else if (argument == "none") {
525 flag.setOnOff(type == LM_OT_NONE);
533 // we just need to be in math mode to enable that
535 case LFUN_MATH_SPACE:
536 case LFUN_MATH_LIMITS:
537 case LFUN_MATH_NONUMBER:
538 case LFUN_MATH_NUMBER:
539 disable = !mathcursor;
542 // we need to be math mode and a math array for that
543 // Hack: halign produces non-zero result iff we are in a math array
544 case LFUN_MATH_ROW_INSERT:
545 case LFUN_MATH_ROW_DELETE:
546 case LFUN_MATH_COLUMN_INSERT:
547 case LFUN_MATH_COLUMN_DELETE:
548 disable = !mathcursor || !mathcursor->halign() ||
549 mathcursor->formula()->getType() == LM_OT_SIMPLE;
556 // the functions which insert insets
557 Inset::Code code = Inset::NO_CODE;
560 code = Inset::ERT_CODE;
562 case LFUN_INSET_GRAPHICS:
563 code = Inset::GRAPHICS_CODE;
565 case LFUN_INSET_FOOTNOTE:
566 code = Inset::FOOT_CODE;
568 case LFUN_DIALOG_TABULAR_INSERT:
569 case LFUN_INSET_TABULAR:
570 code = Inset::TABULAR_CODE;
572 case LFUN_INSET_EXTERNAL:
573 code = Inset::EXTERNAL_CODE;
575 case LFUN_INSET_MARGINAL:
576 code = Inset::MARGIN_CODE;
578 case LFUN_INSET_MINIPAGE:
579 code = Inset::MINIPAGE_CODE;
581 case LFUN_INSET_FLOAT:
582 case LFUN_INSET_WIDE_FLOAT:
583 code = Inset::FLOAT_CODE;
585 case LFUN_FLOAT_LIST:
586 code = Inset::FLOAT_LIST_CODE;
589 case LFUN_INSET_LIST:
590 code = Inset::LIST_CODE;
592 case LFUN_INSET_THEOREM:
593 code = Inset::THEOREM_CODE;
596 case LFUN_INSET_CAPTION:
597 code = Inset::CAPTION_CODE;
599 case LFUN_INSERT_NOTE:
600 code = Inset::IGNORE_CODE;
602 case LFUN_INSERT_LABEL:
603 code = Inset::LABEL_CODE;
605 case LFUN_REF_INSERT:
606 code = Inset::REF_CODE;
608 case LFUN_CITATION_CREATE:
609 case LFUN_CITATION_INSERT:
610 code = Inset::CITE_CODE;
612 case LFUN_INSERT_BIBTEX:
613 code = Inset::BIBTEX_CODE;
615 case LFUN_INDEX_INSERT:
616 case LFUN_INDEX_INSERT_LAST:
617 case LFUN_INDEX_CREATE:
618 code = Inset::INDEX_CODE;
620 case LFUN_INDEX_PRINT:
621 code = Inset::INDEX_PRINT_CODE;
623 case LFUN_CHILD_INSERT:
624 code = Inset::INCLUDE_CODE;
626 case LFUN_TOC_INSERT:
627 code = Inset::TOC_CODE;
629 case LFUN_PARENTINSERT:
630 code = Inset::PARENT_CODE;
634 case LFUN_INSERT_URL:
635 code = Inset::URL_CODE;
638 // always allow this, since we will inset a raw quote
639 // if an inset is not allowed.
641 case LFUN_HYPHENATION:
642 case LFUN_LIGATURE_BREAK:
644 case LFUN_MENU_SEPARATOR:
646 case LFUN_END_OF_SENTENCE:
647 code = Inset::SPECIALCHAR_CODE;
649 case LFUN_PROTECTEDSPACE:
650 // slight hack: we know this is allowed in math mode
652 code = Inset::SPECIALCHAR_CODE;
657 if (code != Inset::NO_CODE && tli && !tli->insetAllowed(code)) {
664 // A few general toggles
666 case LFUN_TOOLTIPS_TOGGLE:
667 flag.setOnOff(owner->getDialogs()->tooltipsEnabled());
670 case LFUN_READ_ONLY_TOGGLE:
671 flag.setOnOff(buf->isReadonly());
674 flag.setOnOff(TEXT(false)->cursor.par()->params().startOfAppendix());
676 case LFUN_SWITCHBUFFER:
677 // toggle on the current buffer, but do not toggle off
678 // the other ones (is that a good idea?)
679 if (argument == buf->fileName())
686 // the font related toggles
688 LyXFont const & font = TEXT(false)->real_current_font;
691 flag.setOnOff(font.emph() == LyXFont::ON);
694 flag.setOnOff(font.noun() == LyXFont::ON);
697 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
700 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
703 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
706 flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
713 string tc = mathcursor->getLastCode();
716 flag.setOnOff(tc == "mathbf");
719 flag.setOnOff(tc == "mathsf");
722 flag.setOnOff(tc == "mathcal");
725 flag.setOnOff(tc == "mathrm");
728 flag.setOnOff(tc == "mathtt");
731 flag.setOnOff(tc == "mathbb");
734 flag.setOnOff(tc == "mathnormal");
745 // temporary dispatch method
746 void LyXFunc::miniDispatch(string const & s)
748 string s2(frontStrip(strip(s)));
751 verboseDispatch(s2, true);
756 void LyXFunc::verboseDispatch(string const & s, bool show_sc)
758 int action = lyxaction.LookupFunc(frontStrip(s));
760 if (action == LFUN_UNKNOWN_ACTION) {
761 string const msg = string(_("Unknown function ("))
765 verboseDispatch(action, show_sc);
770 void LyXFunc::verboseDispatch(int ac, bool show_sc)
775 // get the real action and argument
776 action = lyxaction.retrieveActionArg(ac, argument);
778 verboseDispatch(action, argument, show_sc);
783 void LyXFunc::verboseDispatch(kb_action action,
784 string const & argument, bool show_sc)
786 string res = dispatch(action, argument);
788 commandshortcut.erase();
790 if (lyxrc.display_shortcuts && show_sc) {
791 if (action != LFUN_SELFINSERT) {
792 // Put name of command and list of shortcuts
793 // for it in minibuffer
794 string comname = lyxaction.getActionName(action);
796 int pseudoaction = action;
797 bool argsadded = false;
799 if (!argument.empty()) {
800 // the pseudoaction is useful for the bindings
802 lyxaction.searchActionArg(action,
805 if (pseudoaction == LFUN_UNKNOWN_ACTION) {
806 pseudoaction = action;
808 comname += " " + argument;
813 string const shortcuts =
814 toplevel_keymap->findbinding(pseudoaction);
816 if (!shortcuts.empty()) {
817 comname += ": " + shortcuts;
818 } else if (!argsadded && !argument.empty()) {
819 comname += " " + argument;
822 if (!comname.empty()) {
823 comname = strip(comname);
824 commandshortcut = "(" + comname + ')';
830 if (!commandshortcut.empty()) {
831 owner->getMiniBuffer()->addSet(commandshortcut);
834 owner->getMiniBuffer()->addSet(' ' + commandshortcut);
839 string const LyXFunc::dispatch(kb_action action, string argument)
841 lyxerr[Debug::ACTION] << "LyXFunc::Dispatch: action[" << action
842 <<"] arg[" << argument << "]" << endl;
844 // we have not done anything wrong yet.
846 dispatch_buffer.erase();
848 #ifdef NEW_DISPATCHER
849 // We try do call the most specific dispatcher first:
850 // 1. the lockinginset's dispatch
851 // 2. the bufferview's dispatch
852 // 3. the lyxview's dispatch
855 selection_possible = false;
857 if (owner->view()->available())
858 owner->view()->hideCursor();
860 // We cannot use this function here
861 if (getStatus(action, argument).disabled()) {
862 lyxerr[Debug::ACTION] << "LyXFunc::Dispatch: "
863 << lyxaction.getActionName(action)
864 << " [" << action << "] is disabled at this location"
866 setErrorMessage(getStatusMessage());
867 goto exit_with_message;
870 if (owner->view()->available() && owner->view()->theLockingInset()) {
871 UpdatableInset::RESULT result;
872 if ((action > 1) || ((action == LFUN_UNKNOWN_ACTION) &&
873 (!keyseq.deleted())))
875 UpdatableInset * inset = owner->view()->theLockingInset();
879 inset->getCursorPos(owner->view(), inset_x, dummy_y);
881 if ((action == LFUN_UNKNOWN_ACTION)
882 && argument.empty()) {
883 argument = keyseq.getLastKeyEncoded();
885 // Undo/Redo is a bit tricky for insets.
886 if (action == LFUN_UNDO) {
887 owner->view()->menuUndo();
888 goto exit_with_message;
889 } else if (action == LFUN_REDO) {
890 owner->view()->menuRedo();
891 goto exit_with_message;
892 } else if (((result=inset->
893 // Hand-over to inset's own dispatch:
894 localDispatch(owner->view(), action, argument)) ==
895 UpdatableInset::DISPATCHED) ||
896 (result == UpdatableInset::DISPATCHED_NOUPDATE))
897 goto exit_with_message;
898 // If UNDISPATCHED, just soldier on
899 else if (result == UpdatableInset::FINISHED) {
900 if (TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params)) {
901 TEXT()->cursorRight(owner->view());
902 moveCursorUpdate(true, false);
905 goto exit_with_message;
906 } else if (result == UpdatableInset::FINISHED_RIGHT) {
907 if (!TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params)) {
908 TEXT()->cursorRight(owner->view());
909 moveCursorUpdate(true, false);
912 goto exit_with_message;
913 } else if (result == UpdatableInset::FINISHED_UP) {
914 if (TEXT()->cursor.irow()->previous()) {
916 TEXT()->setCursorFromCoordinates(
917 owner->view(), TEXT()->cursor.ix() + inset_x,
918 TEXT()->cursor.iy() -
919 TEXT()->cursor.irow()->baseline() - 1);
920 TEXT()->cursor.x_fix(TEXT()->cursor.x());
922 TEXT()->cursorUp(owner->view());
924 moveCursorUpdate(true, false);
927 owner->view()->update(TEXT(), BufferView::SELECT|BufferView::FITCUR);
929 goto exit_with_message;
930 } else if (result == UpdatableInset::FINISHED_DOWN) {
931 if (TEXT()->cursor.irow()->next()) {
933 TEXT()->setCursorFromCoordinates(
934 owner->view(), TEXT()->cursor.ix() + inset_x,
935 TEXT()->cursor.iy() -
936 TEXT()->cursor.irow()->baseline() +
937 TEXT()->cursor.irow()->height() + 1);
938 TEXT()->cursor.x_fix(TEXT()->cursor.x());
940 TEXT()->cursorDown(owner->view());
943 TEXT()->cursorRight(owner->view());
945 moveCursorUpdate(true, false);
947 goto exit_with_message;
949 #warning I am not sure this is still right, please have a look! (Jug 20020417)
950 else { // result == UNDISPATCHED
951 //setMessage(N_("Text mode"));
953 case LFUN_UNKNOWN_ACTION:
954 case LFUN_BREAKPARAGRAPH:
956 TEXT()->cursorRight(owner->view());
957 owner->view()->setState();
961 if (!TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params)) {
962 TEXT()->cursorRight(owner->view());
963 moveCursorUpdate(true, false);
966 goto exit_with_message;
968 if (TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params)) {
969 TEXT()->cursorRight(owner->view());
970 moveCursorUpdate(true, false);
973 goto exit_with_message;
975 if (TEXT()->cursor.row()->next())
976 TEXT()->cursorDown(owner->view());
978 TEXT()->cursorRight(owner->view());
979 moveCursorUpdate(true, false);
981 goto exit_with_message;
993 if (!owner->view()->available()) break;
994 // this function should be used always [asierra060396]
995 UpdatableInset * tli =
996 owner->view()->theLockingInset();
998 UpdatableInset * lock = tli->getLockingInset();
1001 owner->view()->unlockInset(tli);
1002 TEXT()->cursorRight(owner->view());
1003 moveCursorUpdate(true, false);
1006 tli->unlockInsetInInset(owner->view(),
1011 // Tell the paragraph dialog that we changed paragraph
1012 owner->getDialogs()->updateParagraph();
1017 // --- Misc -------------------------------------------
1018 case LFUN_WORDFINDFORWARD :
1019 case LFUN_WORDFINDBACKWARD : {
1020 static string last_search;
1021 string searched_string;
1023 if (!argument.empty()) {
1024 last_search = argument;
1025 searched_string = argument;
1027 searched_string = last_search;
1029 bool fw = (action == LFUN_WORDFINDBACKWARD);
1030 if (!searched_string.empty()) {
1031 lyxfind::LyXFind(owner->view(), searched_string, fw);
1033 // owner->view()->showCursor();
1039 if (owner->view()->available() && !owner->view()->theLockingInset()) {
1040 owner->view()->update(TEXT(),
1041 BufferView::SELECT|BufferView::FITCUR);
1043 owner->message(keyseq.printOptions());
1047 // --- Misc -------------------------------------------
1048 case LFUN_EXEC_COMMAND:
1050 vector<string> allCmds;
1051 transform(lyxaction.func_begin(), lyxaction.func_end(),
1052 back_inserter(allCmds), lyx::firster());
1053 static vector<string> hist;
1054 owner->getMiniBuffer()->getString(MiniBuffer::spaces,
1059 case LFUN_CANCEL: // RVDK_PATCH_5
1061 meta_fake_bit = key_modifier::none;
1062 if (owner->view()->available())
1063 // cancel any selection
1064 dispatch(LFUN_MARK_OFF);
1065 setMessage(N_("Cancel"));
1068 case LFUN_META_FAKE: // RVDK_PATCH_5
1070 meta_fake_bit = key_modifier::alt;
1071 setMessage(keyseq.print());
1075 case LFUN_READ_ONLY_TOGGLE:
1076 if (owner->buffer()->lyxvc.inUse()) {
1077 owner->buffer()->lyxvc.toggleReadOnly();
1079 owner->buffer()->setReadonly(
1080 !owner->buffer()->isReadonly());
1084 case LFUN_CENTER: // this is center and redraw.
1085 owner->view()->center();
1088 // --- Menus -----------------------------------------------
1093 case LFUN_MENUNEWTMPLT:
1097 case LFUN_CLOSEBUFFER:
1101 case LFUN_MENUWRITE:
1102 if (!owner->buffer()->isUnnamed()) {
1104 s1 << _("Saving document") << ' '
1105 << MakeDisplayPath(owner->buffer()->fileName() + "...");
1106 owner->message(s1.str().c_str());
1107 MenuWrite(owner->view(), owner->buffer());
1109 WriteAs(owner->view(), owner->buffer());
1113 WriteAs(owner->view(), owner->buffer(), argument);
1116 case LFUN_MENURELOAD:
1121 Exporter::Export(owner->buffer(), argument, true);
1125 Exporter::Preview(owner->buffer(), argument);
1128 case LFUN_BUILDPROG:
1129 Exporter::Export(owner->buffer(), "program", true);
1132 case LFUN_RUNCHKTEX:
1133 MenuRunChktex(owner->buffer());
1136 case LFUN_MENUPRINT:
1137 owner->getDialogs()->showPrint();
1141 if (argument == "custom")
1142 owner->getDialogs()->showSendto();
1144 Exporter::Export(owner->buffer(), argument, false);
1162 InsetCommandParams p;
1165 if (action == LFUN_TOCVIEW)
1167 p.setCmdName("tableofcontents");
1169 else if (action == LFUN_LOAVIEW)
1170 p.setCmdName("listof{algorithm}{List of Algorithms}");
1171 else if (action == LFUN_LOFVIEW)
1172 p.setCmdName("listoffigures");
1174 p.setCmdName("listoftables");
1176 owner->getDialogs()->createTOC(p.getAsString());
1180 case LFUN_DIALOG_TABULAR_INSERT:
1181 owner->getDialogs()->showTabularCreate();
1185 AutoSave(owner->view());
1189 owner->view()->menuUndo();
1193 owner->view()->menuRedo();
1196 case LFUN_MENUSEARCH:
1197 owner->getDialogs()->showSearch();
1200 case LFUN_REMOVEERRORS:
1201 if (owner->view()->removeAutoInsets()) {
1202 owner->view()->redraw();
1203 owner->view()->fitCursor();
1207 case LFUN_DEPTH_MIN:
1208 changeDepth(owner->view(), TEXT(false), -1);
1211 case LFUN_DEPTH_PLUS:
1212 changeDepth(owner->view(), TEXT(false), 1);
1216 owner->getDialogs()->setUserFreeFont();
1219 case LFUN_RECONFIGURE:
1220 Reconfigure(owner->view());
1224 case LFUN_FLOATSOPERATE:
1225 if (argument == "openfoot")
1226 owner->view()->allFloats(1,0);
1227 else if (argument == "closefoot")
1228 owner->view()->allFloats(0,0);
1229 else if (argument == "openfig")
1230 owner->view()->allFloats(1,1);
1231 else if (argument == "closefig")
1232 owner->view()->allFloats(0,1);
1235 #ifdef WITH_WARNINGS
1236 //#warning Find another implementation here (or another lyxfunc)!
1239 case LFUN_HELP_ABOUTLYX:
1240 owner->getDialogs()->showAboutlyx();
1243 case LFUN_HELP_TEXINFO:
1244 owner->getDialogs()->showTexinfo();
1247 case LFUN_HELP_OPEN:
1249 string const arg = argument;
1251 setErrorMessage(N_("Missing argument"));
1254 owner->prohibitInput();
1255 string const fname = i18nLibFileSearch("doc", arg, "lyx");
1256 if (fname.empty()) {
1257 lyxerr << "LyX: unable to find documentation file `"
1258 << arg << "'. Bad installation?" << endl;
1259 owner->allowInput();
1263 str << _("Opening help file") << ' '
1264 << MakeDisplayPath(fname) << "...";
1265 owner->message(str.str().c_str());
1266 owner->view()->buffer(bufferlist.loadLyXFile(fname, false));
1267 owner->allowInput();
1271 // --- version control -------------------------------
1272 case LFUN_VC_REGISTER:
1274 if (!owner->buffer()->lyxvc.inUse())
1275 owner->buffer()->lyxvc.registrer();
1279 case LFUN_VC_CHECKIN:
1281 if (owner->buffer()->lyxvc.inUse()
1282 && !owner->buffer()->isReadonly())
1283 owner->buffer()->lyxvc.checkIn();
1287 case LFUN_VC_CHECKOUT:
1289 if (owner->buffer()->lyxvc.inUse()
1290 && owner->buffer()->isReadonly())
1291 owner->buffer()->lyxvc.checkOut();
1295 case LFUN_VC_REVERT:
1297 owner->buffer()->lyxvc.revert();
1303 owner->buffer()->lyxvc.undoLast();
1307 case LFUN_VC_HISTORY:
1309 owner->getDialogs()->showVCLogFile();
1313 // --- buffers ----------------------------------------
1315 case LFUN_SWITCHBUFFER:
1316 owner->view()->buffer(bufferlist.getBuffer(argument));
1321 // servercmd: argument must be <file>:<template>
1322 Buffer * tmpbuf = NewLyxFile(argument);
1324 owner->view()->buffer(tmpbuf);
1328 case LFUN_FILE_OPEN:
1332 case LFUN_LATEX_LOG:
1333 owner->getDialogs()->showLogFile();
1336 case LFUN_LAYOUT_DOCUMENT:
1337 owner->getDialogs()->showDocument();
1340 case LFUN_LAYOUT_PARAGRAPH:
1341 owner->getDialogs()->showParagraph();
1344 case LFUN_LAYOUT_CHARACTER:
1345 owner->getDialogs()->showCharacter();
1348 case LFUN_LAYOUT_TABULAR:
1349 if (owner->view()->theLockingInset()) {
1350 if (owner->view()->theLockingInset()->lyxCode()==Inset::TABULAR_CODE) {
1351 InsetTabular * inset = static_cast<InsetTabular *>
1352 (owner->view()->theLockingInset());
1353 inset->openLayoutDialog(owner->view());
1354 } else if (owner->view()->theLockingInset()->
1355 getFirstLockingInsetOfType(Inset::TABULAR_CODE)!=0) {
1356 InsetTabular * inset = static_cast<InsetTabular *>(
1357 owner->view()->theLockingInset()->getFirstLockingInsetOfType(Inset::TABULAR_CODE));
1358 inset->openLayoutDialog(owner->view());
1363 case LFUN_LAYOUT_PREAMBLE:
1364 owner->getDialogs()->showPreamble();
1367 case LFUN_DROP_LAYOUTS_CHOICE:
1368 owner->getToolbar()->openLayoutList();
1371 case LFUN_MENU_OPEN_BY_NAME:
1372 owner->getMenubar()->openByName(argument);
1373 break; // RVDK_PATCH_5
1375 case LFUN_SPELLCHECK:
1376 if (lyxrc.isp_command != "none")
1377 owner->getDialogs()->showSpellchecker();
1380 // --- lyxserver commands ----------------------------
1384 setMessage(owner->buffer()->fileName());
1385 lyxerr[Debug::INFO] << "FNAME["
1386 << owner->buffer()->fileName()
1392 dispatch_buffer = keyseq.print();
1393 lyxserver->notifyClient(dispatch_buffer);
1397 case LFUN_GOTOFILEROW:
1401 istringstream istr(argument.c_str());
1402 istr >> file_name >> row;
1403 // Must replace extension of the file to be .lyx and get full path
1404 string const s(ChangeExtension(file_name, ".lyx"));
1406 // Either change buffer or load the file
1407 if (bufferlist.exists(s)) {
1408 owner->view()->buffer(bufferlist.getBuffer(s));
1410 owner->view()->buffer(bufferlist.loadLyXFile(s));
1414 owner->view()->setCursorFromRow(row);
1417 owner->view()->center();
1421 case LFUN_GOTO_PARAGRAPH:
1423 istringstream istr(argument.c_str());
1427 Paragraph * par = owner->buffer()->getParFromID(id);
1429 lyxerr[Debug::INFO] << "No matching paragraph found! ["
1430 << id << "]" << endl;
1433 lyxerr[Debug::INFO] << "Paragraph " << par->id()
1434 << " found." << endl;
1437 if (owner->view()->theLockingInset())
1438 owner->view()->unlockInset(owner->view()->theLockingInset());
1439 if (par->inInset()) {
1440 par->inInset()->edit(owner->view());
1443 owner->view()->getLyXText()->setCursor(owner->view(), par, 0);
1444 owner->view()->setState();
1448 owner->view()->center();
1455 int const qa = lyxaction.LookupFunc(argument);
1456 setMessage(lyxaction.helpText(static_cast<kb_action>(qa)));
1460 // --- toolbar ----------------------------------
1461 case LFUN_PUSH_TOOLBAR:
1463 int nth = strToInt(argument);
1465 setErrorMessage(N_("Push-toolbar needs argument > 0"));
1467 owner->getToolbar()->push(nth);
1472 case LFUN_ADD_TO_TOOLBAR:
1474 if (lyxerr.debugging(Debug::GUI)) {
1475 lyxerr << "LFUN_ADD_TO_TOOLBAR:"
1476 "argument = `" << argument << '\'' << endl;
1478 string tmp(argument);
1479 //lyxerr <<string("Argument: ") + argument);
1480 //lyxerr <<string("Tmp : ") + tmp);
1482 setErrorMessage(N_("Usage: toolbar-add-to <LyX command>"));
1484 owner->getToolbar()->add(argument, false);
1485 owner->getToolbar()->set();
1490 // --- insert characters ----------------------------------------
1492 // --- Mathed stuff. If we are here, there is no locked inset yet.
1493 case LFUN_MATH_EXTERN:
1494 case LFUN_MATH_NUMBER:
1495 case LFUN_MATH_NONUMBER:
1496 case LFUN_MATH_LIMITS:
1498 setErrorMessage(N_("This is only allowed in math mode!"));
1502 // passthrough hat and underscore outside mathed:
1503 case LFUN_SUBSCRIPT:
1504 dispatch(LFUN_SELFINSERT, "_");
1506 case LFUN_SUPERSCRIPT:
1507 dispatch(LFUN_SELFINSERT, "^");
1510 case LFUN_MATH_PANEL:
1511 owner->getDialogs()->showMathPanel();
1514 case LFUN_CITATION_CREATE:
1516 InsetCommandParams p("cite");
1518 if (!argument.empty()) {
1519 // This should be set at source, ie when typing
1520 // "citation-insert foo" in the minibuffer.
1521 // Question: would pybibliographer also need to be
1522 // changed. Suspect so. Leave as-is therefore.
1523 if (contains(argument, "|")) {
1524 p.setContents(token(argument, '|', 0));
1525 p.setOptions( token(argument, '|', 1));
1527 p.setContents(argument);
1529 dispatch(LFUN_CITATION_INSERT, p.getAsString());
1531 owner->getDialogs()->createCitation(p.getAsString());
1535 case LFUN_CHILDOPEN:
1537 string const filename =
1538 MakeAbsPath(argument,
1539 owner->buffer()->filePath());
1540 setMessage(N_("Opening child document ") +
1541 MakeDisplayPath(filename) + "...");
1542 owner->view()->savePosition(0);
1543 if (bufferlist.exists(filename))
1544 owner->view()->buffer(bufferlist.getBuffer(filename));
1546 owner->view()->buffer(bufferlist.loadLyXFile(filename));
1550 case LFUN_TOGGLECURSORFOLLOW:
1551 lyxrc.cursor_follows_scrollbar = !lyxrc.cursor_follows_scrollbar;
1554 case LFUN_KMAP_OFF: // keymap off
1555 owner->getIntl()->KeyMapOn(false);
1558 case LFUN_KMAP_PRIM: // primary keymap
1559 owner->getIntl()->KeyMapPrim();
1562 case LFUN_KMAP_SEC: // secondary keymap
1563 owner->getIntl()->KeyMapSec();
1566 case LFUN_KMAP_TOGGLE: // toggle keymap
1567 owner->getIntl()->ToggleKeyMap();
1572 // argument contains ';'-terminated commands
1573 while (argument.find(';') != string::npos) {
1575 argument = split(argument, first, ';');
1576 verboseDispatch(first, false);
1581 case LFUN_DIALOG_PREFERENCES:
1582 owner->getDialogs()->showPreferences();
1585 case LFUN_SAVEPREFERENCES:
1587 Path p(user_lyxdir);
1588 lyxrc.write("preferences");
1592 case LFUN_SCREEN_FONT_UPDATE:
1594 // handle the screen font changes.
1596 lyxrc.set_font_norm_type();
1597 fontloader.update();
1598 // Of course we should only do the resize and the textcache.clear
1599 // if values really changed...but not very important right now. (Lgb)
1600 // All visible buffers will need resize
1601 owner->view()->resize();
1602 // We also need to empty the textcache so that
1603 // the buffer will be formatted correctly after
1609 case LFUN_SET_COLOR:
1612 string const x11_name = split(argument, lyx_name, ' ');
1613 if (lyx_name.empty() || x11_name.empty()) {
1614 setErrorMessage(N_("Syntax: set-color <lyx_name>"
1619 bool const graphicsbg_changed =
1620 (lyx_name == lcolor.getLyXName(LColor::graphicsbg) &&
1621 x11_name != lcolor.getX11Name(LColor::graphicsbg));
1623 if (!lcolor.setColor(lyx_name, x11_name)) {
1624 static string const err1 (N_("Set-color \""));
1625 static string const err2 (
1626 N_("\" failed - color is undefined "
1627 "or may not be redefined"));
1628 setErrorMessage(_(err1) + lyx_name + _(err2));
1632 lyxColorHandler->updateColor(lcolor.getFromLyXName(lyx_name));
1634 if (graphicsbg_changed) {
1635 grfx::GCache & gc = grfx::GCache::get();
1636 gc.changeDisplay(true);
1639 owner->view()->redraw();
1644 owner->message(argument);
1647 case LFUN_MESSAGE_PUSH:
1648 owner->messagePush(argument);
1651 case LFUN_MESSAGE_POP:
1652 owner->messagePop();
1655 case LFUN_FORKS_SHOW:
1656 owner->getDialogs()->showForks();
1659 case LFUN_FORKS_KILL:
1661 if (!isStrInt(argument))
1664 pid_t const pid = strToInt(argument);
1665 ForkedcallsController & fcc = ForkedcallsController::get();
1670 case LFUN_TOOLTIPS_TOGGLE:
1671 owner->getDialogs()->toggleTooltips();
1675 // Then if it was none of the above
1676 // Trying the BufferView::pimpl dispatch:
1677 if (!owner->view()->Dispatch(action, argument))
1678 lyxerr << "A truly unknown func ["
1679 << lyxaction.getActionName(action) << "]!"
1686 string const res = getMessage();
1689 owner->message(_(res));
1690 owner->updateMenubar();
1691 owner->updateToolbar();
1697 void LyXFunc::setupLocalKeymap()
1699 keyseq.stdmap = keyseq.curmap = toplevel_keymap.get();
1700 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap.get();
1704 void LyXFunc::menuNew(bool fromTemplate)
1706 string initpath = lyxrc.document_path;
1708 if (owner->view()->available()) {
1709 string const trypath = owner->buffer()->filePath();
1710 // If directory is writeable, use this as default.
1711 if (IsDirWriteable(trypath))
1715 static int newfile_number;
1718 if (lyxrc.new_ask_filename) {
1719 FileDialog fileDlg(owner, _("Enter filename for new document"),
1720 LFUN_SELECT_FILE_SYNC,
1721 make_pair(string(_("Documents|#o#O")),
1722 string(lyxrc.document_path)),
1723 make_pair(string(_("Templates|#T#t")),
1724 string(lyxrc.template_path)));
1726 FileDialog::Result result =
1727 fileDlg.Select(initpath,
1728 _("*.lyx|LyX Documents (*.lyx)"),
1731 if (result.second.empty()) {
1732 owner->message(_("Canceled."));
1733 lyxerr[Debug::INFO] << "New Document Cancelled." << endl;
1737 // get absolute path of file and make sure the filename ends
1739 s = MakeAbsPath(result.second);
1740 if (!IsLyXFilename(s))
1743 // Check if the document already is open
1744 if (bufferlist.exists(s)) {
1745 switch (Alert::askConfirmation(_("Document is already open:"),
1746 MakeDisplayPath(s, 50),
1747 _("Do you want to close that document now?\n"
1748 "('No' will just switch to the open version)")))
1750 case 1: // Yes: close the document
1751 if (!bufferlist.close(bufferlist.getBuffer(s)))
1752 // If close is canceled, we cancel here too.
1755 case 2: // No: switch to the open document
1756 owner->view()->buffer(bufferlist.getBuffer(s));
1758 case 3: // Cancel: Do nothing
1759 owner->message(_("Canceled."));
1763 // Check whether the file already exists
1765 if (fi.readable() &&
1766 Alert::askQuestion(_("File already exists:"),
1767 MakeDisplayPath(s, 50),
1768 _("Do you want to open the document?"))) {
1770 string const disp_fn(MakeDisplayPath(s));
1773 str << _("Opening document") << ' '
1774 << disp_fn << "...";
1776 owner->message(str.str().c_str());
1777 //XFlush(fl_get_display());
1778 owner->view()->buffer(bufferlist.loadLyXFile(s));
1780 str2 << _("Document") << ' '
1781 << disp_fn << ' ' << _("opened.");
1783 owner->message(str2.str().c_str());
1788 s = AddName(lyxrc.document_path,
1789 "newfile" + tostr(++newfile_number) + ".lyx");
1791 while (bufferlist.exists(s) || fi.readable()) {
1793 s = AddName(lyxrc.document_path,
1794 "newfile" + tostr(newfile_number) +
1800 // The template stuff
1803 FileDialog fileDlg(owner, _("Select template file"),
1804 LFUN_SELECT_FILE_SYNC,
1805 make_pair(string(_("Documents|#o#O")),
1806 string(lyxrc.document_path)),
1807 make_pair(string(_("Templates|#T#t")),
1808 string(lyxrc.template_path)));
1810 FileDialog::Result result =
1811 fileDlg.Select(lyxrc.template_path,
1812 _("*.lyx|LyX Documents (*.lyx)"));
1814 if (result.first == FileDialog::Later)
1817 string const fname = result.second;
1824 // find a free buffer
1825 lyxerr[Debug::INFO] << "Find a free buffer." << endl;
1826 owner->view()->buffer(bufferlist.newFile(s, templname));
1830 void LyXFunc::open(string const & fname)
1832 string initpath = lyxrc.document_path;
1834 if (owner->view()->available()) {
1835 string const trypath = owner->buffer()->filePath();
1836 // If directory is writeable, use this as default.
1837 if (IsDirWriteable(trypath))
1843 if (fname.empty()) {
1844 FileDialog fileDlg(owner, _("Select document to open"),
1846 make_pair(string(_("Documents|#o#O")),
1847 string(lyxrc.document_path)),
1848 make_pair(string(_("Examples|#E#e")),
1849 string(AddPath(system_lyxdir, "examples"))));
1851 FileDialog::Result result =
1852 fileDlg.Select(initpath,
1853 "*.lyx|LyX Documents (*.lyx)");
1855 if (result.first == FileDialog::Later)
1858 filename = result.second;
1860 // check selected filename
1861 if (filename.empty()) {
1862 owner->message(_("Canceled."));
1868 // get absolute path of file and add ".lyx" to the filename if
1870 string const fullpath = FileSearch(string(), filename, "lyx");
1871 if (fullpath.empty()) {
1872 Alert::alert(_("Error"), _("Could not find file"), filename);
1876 filename = fullpath;
1879 string const disp_fn(MakeDisplayPath(filename));
1882 str << _("Opening document") << ' ' << disp_fn << "...";
1884 owner->message(str.str().c_str());
1886 Buffer * openbuf = bufferlist.loadLyXFile(filename);
1888 owner->view()->buffer(openbuf);
1890 str << _("Document") << ' ' << disp_fn << ' ' << _("opened.");
1891 owner->message(str.str().c_str());
1894 str << _("Could not open document") << ' ' << disp_fn;
1895 owner->message(str.str().c_str());
1900 void LyXFunc::doImport(string const & argument)
1903 string filename = split(argument, format, ' ');
1905 lyxerr[Debug::INFO] << "LyXFunc::doImport: " << format
1906 << " file: " << filename << endl;
1908 // need user interaction
1909 if (filename.empty()) {
1910 string initpath = lyxrc.document_path;
1912 if (owner->view()->available()) {
1913 string const trypath = owner->buffer()->filePath();
1914 // If directory is writeable, use this as default.
1915 if (IsDirWriteable(trypath))
1919 string const text = _("Select ") + formats.prettyName(format)
1920 + _(" file to import");
1922 FileDialog fileDlg(owner, text,
1924 make_pair(string(_("Documents|#o#O")),
1925 string(lyxrc.document_path)),
1926 make_pair(string(_("Examples|#E#e")),
1927 string(AddPath(system_lyxdir, "examples"))));
1929 string const extension = "*." + formats.extension(format)
1930 + "| " + formats.prettyName(format)
1931 + " (*." + formats.extension(format) + ")";
1933 FileDialog::Result result = fileDlg.Select(initpath,
1936 if (result.first == FileDialog::Later)
1939 filename = result.second;
1941 // check selected filename
1942 if (filename.empty())
1943 owner->message(_("Canceled."));
1946 if (filename.empty())
1949 // get absolute path of file
1950 filename = MakeAbsPath(filename);
1952 string const lyxfile = ChangeExtension(filename, ".lyx");
1954 // Check if the document already is open
1955 if (lyxrc.use_gui && bufferlist.exists(lyxfile)) {
1956 switch (Alert::askConfirmation(_("Document is already open:"),
1957 MakeDisplayPath(lyxfile, 50),
1958 _("Do you want to close that document now?\n"
1959 "('No' will just switch to the open version)")))
1962 // If close is canceled, we cancel here too.
1963 if (!bufferlist.close(bufferlist.getBuffer(lyxfile)))
1967 owner->view()->buffer(bufferlist.getBuffer(lyxfile));
1970 owner->message(_("Canceled."));
1975 // if the file exists already, and we didn't do
1976 // -i lyx thefile.lyx, warn
1977 if (FileInfo(lyxfile, true).exist() && filename != lyxfile) {
1978 if (!Alert::askQuestion(_("A document by the name"),
1979 MakeDisplayPath(lyxfile), _("already exists. Overwrite?"))) {
1980 owner->message(_("Canceled"));
1985 Importer::Import(owner, filename, format);
1989 void LyXFunc::reloadBuffer()
1991 string const fn = owner->buffer()->fileName();
1992 if (bufferlist.close(owner->buffer()))
1993 owner->view()->buffer(bufferlist.loadLyXFile(fn));
1997 void LyXFunc::closeBuffer()
1999 if (bufferlist.close(owner->buffer()) && !quitting) {
2000 if (bufferlist.empty()) {
2001 // need this otherwise SEGV may occur while trying to
2002 // set variables that don't exist
2003 // since there's no current buffer
2004 owner->getDialogs()->hideBufferDependent();
2006 owner->view()->buffer(bufferlist.first());
2012 // Each "owner" should have it's own message method. lyxview and
2013 // the minibuffer would use the minibuffer, but lyxserver would
2014 // send an ERROR signal to its client. Alejandro 970603
2015 // This func is bit problematic when it comes to NLS, to make the
2016 // lyx servers client be language indepenent we must not translate
2017 // strings sent to this func.
2018 void LyXFunc::setErrorMessage(string const & m) const
2020 dispatch_buffer = m;
2025 void LyXFunc::setMessage(string const & m) const
2027 dispatch_buffer = m;
2031 void LyXFunc::setStatusMessage(string const & m) const
2037 void LyXFunc::initMiniBuffer()
2039 string text = _("Welcome to LyX!");
2041 // When meta-fake key is pressed, show the key sequence so far + "M-".
2043 text = keyseq.print();
2047 // Else, when a non-complete key sequence is pressed,
2048 // show the available options.
2049 if (keyseq.length() > 0 && !keyseq.deleted()) {
2050 text = keyseq.printOptions();
2053 // Else, show the buffer state.
2054 else if (owner->view()->available()) {
2055 Buffer * tmpbuf = owner->buffer();
2057 string const nicename =
2058 MakeDisplayPath(tmpbuf->fileName());
2059 // Should we do this instead? (kindo like emacs)
2060 // leaves more room for other information
2063 if (tmpbuf->lyxvc.inUse()) {
2065 text += tmpbuf->lyxvc.versionString();
2067 text += tmpbuf->lyxvc.locker();
2068 if (tmpbuf->isReadonly())
2071 } else if (tmpbuf->isReadonly())
2073 if (!tmpbuf->isLyxClean())
2074 text += _(" (Changed)");
2076 if (text != _("Welcome to LyX!")) // this is a hack
2077 text = _("* No document open *");
2080 owner->message(text);