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 "frontends/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 == "alignat") {
525 flag.setOnOff(type == LM_OT_ALIGNAT);
526 } else if (argument == "xalignat") {
527 flag.setOnOff(type == LM_OT_XALIGNAT);
528 } else if (argument == "xxalignat") {
529 flag.setOnOff(type == LM_OT_XXALIGNAT);
530 } else if (argument == "none") {
531 flag.setOnOff(type == LM_OT_NONE);
539 // we just need to be in math mode to enable that
541 case LFUN_MATH_SPACE:
542 case LFUN_MATH_LIMITS:
543 case LFUN_MATH_NONUMBER:
544 case LFUN_MATH_NUMBER:
545 disable = !mathcursor;
548 // we need to be math mode and a math array for that
549 // Hack: halign produces non-zero result iff we are in a math array
550 case LFUN_MATH_ROW_INSERT:
551 case LFUN_MATH_ROW_DELETE:
552 case LFUN_MATH_COLUMN_INSERT:
553 case LFUN_MATH_COLUMN_DELETE:
554 disable = !mathcursor || !mathcursor->halign() ||
555 mathcursor->formula()->getType() == LM_OT_SIMPLE;
562 // the functions which insert insets
563 Inset::Code code = Inset::NO_CODE;
566 code = Inset::ERT_CODE;
568 case LFUN_INSET_GRAPHICS:
569 code = Inset::GRAPHICS_CODE;
571 case LFUN_INSET_FOOTNOTE:
572 code = Inset::FOOT_CODE;
574 case LFUN_DIALOG_TABULAR_INSERT:
575 case LFUN_INSET_TABULAR:
576 code = Inset::TABULAR_CODE;
578 case LFUN_INSET_EXTERNAL:
579 code = Inset::EXTERNAL_CODE;
581 case LFUN_INSET_MARGINAL:
582 code = Inset::MARGIN_CODE;
584 case LFUN_INSET_MINIPAGE:
585 code = Inset::MINIPAGE_CODE;
587 case LFUN_INSET_FLOAT:
588 case LFUN_INSET_WIDE_FLOAT:
589 code = Inset::FLOAT_CODE;
591 case LFUN_FLOAT_LIST:
592 code = Inset::FLOAT_LIST_CODE;
595 case LFUN_INSET_LIST:
596 code = Inset::LIST_CODE;
598 case LFUN_INSET_THEOREM:
599 code = Inset::THEOREM_CODE;
602 case LFUN_INSET_CAPTION:
603 code = Inset::CAPTION_CODE;
605 case LFUN_INSERT_NOTE:
606 code = Inset::IGNORE_CODE;
608 case LFUN_INSERT_LABEL:
609 code = Inset::LABEL_CODE;
611 case LFUN_REF_INSERT:
612 code = Inset::REF_CODE;
614 case LFUN_CITATION_CREATE:
615 case LFUN_CITATION_INSERT:
616 code = Inset::CITE_CODE;
618 case LFUN_INSERT_BIBTEX:
619 code = Inset::BIBTEX_CODE;
621 case LFUN_INDEX_INSERT:
622 code = Inset::INDEX_CODE;
624 case LFUN_INDEX_PRINT:
625 code = Inset::INDEX_PRINT_CODE;
627 case LFUN_CHILD_INSERT:
628 code = Inset::INCLUDE_CODE;
630 case LFUN_TOC_INSERT:
631 code = Inset::TOC_CODE;
633 case LFUN_PARENTINSERT:
634 code = Inset::PARENT_CODE;
638 case LFUN_INSERT_URL:
639 code = Inset::URL_CODE;
642 // always allow this, since we will inset a raw quote
643 // if an inset is not allowed.
645 case LFUN_HYPHENATION:
646 case LFUN_LIGATURE_BREAK:
648 case LFUN_MENU_SEPARATOR:
650 case LFUN_END_OF_SENTENCE:
651 code = Inset::SPECIALCHAR_CODE;
653 case LFUN_PROTECTEDSPACE:
654 // slight hack: we know this is allowed in math mode
656 code = Inset::SPECIALCHAR_CODE;
661 if (code != Inset::NO_CODE && tli && !tli->insetAllowed(code)) {
668 // A few general toggles
670 case LFUN_TOOLTIPS_TOGGLE:
671 flag.setOnOff(owner->getDialogs()->tooltipsEnabled());
674 case LFUN_READ_ONLY_TOGGLE:
675 flag.setOnOff(buf->isReadonly());
678 flag.setOnOff(TEXT(false)->cursor.par()->params().startOfAppendix());
680 case LFUN_SWITCHBUFFER:
681 // toggle on the current buffer, but do not toggle off
682 // the other ones (is that a good idea?)
683 if (argument == buf->fileName())
690 // the font related toggles
692 LyXFont const & font = TEXT(false)->real_current_font;
695 flag.setOnOff(font.emph() == LyXFont::ON);
698 flag.setOnOff(font.noun() == LyXFont::ON);
701 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
704 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
707 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
710 flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
717 string tc = mathcursor->getLastCode();
720 flag.setOnOff(tc == "mathbf");
723 flag.setOnOff(tc == "mathsf");
726 flag.setOnOff(tc == "mathcal");
729 flag.setOnOff(tc == "mathrm");
732 flag.setOnOff(tc == "mathtt");
735 flag.setOnOff(tc == "mathbb");
738 flag.setOnOff(tc == "mathnormal");
749 // temporary dispatch method
750 void LyXFunc::miniDispatch(string const & s)
752 string s2(frontStrip(strip(s)));
755 verboseDispatch(s2, true);
760 void LyXFunc::verboseDispatch(string const & s, bool show_sc)
762 int action = lyxaction.LookupFunc(frontStrip(s));
764 if (action == LFUN_UNKNOWN_ACTION) {
765 string const msg = string(_("Unknown function ("))
769 verboseDispatch(action, show_sc);
774 void LyXFunc::verboseDispatch(int ac, bool show_sc)
779 // get the real action and argument
780 action = lyxaction.retrieveActionArg(ac, argument);
782 verboseDispatch(action, argument, show_sc);
787 void LyXFunc::verboseDispatch(kb_action action,
788 string const & argument, bool show_sc)
790 string res = dispatch(action, argument);
792 commandshortcut.erase();
794 if (show_sc && action != LFUN_SELFINSERT) {
795 // Put name of command and list of shortcuts
796 // for it in minibuffer
797 string comname = lyxaction.getActionName(action);
799 int pseudoaction = action;
800 bool argsadded = false;
802 if (!argument.empty()) {
803 // the pseudoaction is useful for the bindings
805 lyxaction.searchActionArg(action,
808 if (pseudoaction == LFUN_UNKNOWN_ACTION) {
809 pseudoaction = action;
811 comname += " " + argument;
816 string const shortcuts =
817 toplevel_keymap->findbinding(pseudoaction);
819 if (!shortcuts.empty()) {
820 comname += ": " + shortcuts;
821 } else if (!argsadded && !argument.empty()) {
822 comname += " " + argument;
825 if (!comname.empty()) {
826 comname = strip(comname);
827 commandshortcut = "(" + comname + ')';
832 if (!commandshortcut.empty()) {
833 owner->getMiniBuffer()->addSet(commandshortcut);
836 owner->getMiniBuffer()->addSet(' ' + commandshortcut);
841 string const LyXFunc::dispatch(kb_action action, string argument)
843 lyxerr[Debug::ACTION] << "LyXFunc::Dispatch: action[" << action
844 <<"] arg[" << argument << "]" << endl;
846 // we have not done anything wrong yet.
848 dispatch_buffer.erase();
850 #ifdef NEW_DISPATCHER
851 // We try do call the most specific dispatcher first:
852 // 1. the lockinginset's dispatch
853 // 2. the bufferview's dispatch
854 // 3. the lyxview's dispatch
857 selection_possible = false;
859 if (owner->view()->available())
860 owner->view()->hideCursor();
862 // We cannot use this function here
863 if (getStatus(action, argument).disabled()) {
864 lyxerr[Debug::ACTION] << "LyXFunc::Dispatch: "
865 << lyxaction.getActionName(action)
866 << " [" << action << "] is disabled at this location"
868 setErrorMessage(getStatusMessage());
869 goto exit_with_message;
872 if (owner->view()->available() && owner->view()->theLockingInset()) {
873 UpdatableInset::RESULT result;
874 if ((action > 1) || ((action == LFUN_UNKNOWN_ACTION) &&
875 (!keyseq.deleted())))
877 UpdatableInset * inset = owner->view()->theLockingInset();
881 inset->getCursorPos(owner->view(), inset_x, dummy_y);
883 if ((action == LFUN_UNKNOWN_ACTION)
884 && argument.empty()) {
885 argument = keyseq.getLastKeyEncoded();
887 // Undo/Redo is a bit tricky for insets.
888 if (action == LFUN_UNDO) {
889 owner->view()->menuUndo();
890 goto exit_with_message;
891 } else if (action == LFUN_REDO) {
892 owner->view()->menuRedo();
893 goto exit_with_message;
894 } else if (((result=inset->
895 // Hand-over to inset's own dispatch:
896 localDispatch(owner->view(), action, argument)) ==
897 UpdatableInset::DISPATCHED) ||
898 (result == UpdatableInset::DISPATCHED_NOUPDATE))
899 goto exit_with_message;
900 // If UNDISPATCHED, just soldier on
901 else if (result == UpdatableInset::FINISHED) {
902 if (TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params)) {
903 TEXT()->cursorRight(owner->view());
904 moveCursorUpdate(true, false);
907 goto exit_with_message;
908 } else if (result == UpdatableInset::FINISHED_RIGHT) {
909 if (!TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params)) {
910 TEXT()->cursorRight(owner->view());
911 moveCursorUpdate(true, false);
914 goto exit_with_message;
915 } else if (result == UpdatableInset::FINISHED_UP) {
916 if (TEXT()->cursor.irow()->previous()) {
918 TEXT()->setCursorFromCoordinates(
919 owner->view(), TEXT()->cursor.ix() + inset_x,
920 TEXT()->cursor.iy() -
921 TEXT()->cursor.irow()->baseline() - 1);
922 TEXT()->cursor.x_fix(TEXT()->cursor.x());
924 TEXT()->cursorUp(owner->view());
926 moveCursorUpdate(true, false);
929 owner->view()->update(TEXT(), BufferView::SELECT|BufferView::FITCUR);
931 goto exit_with_message;
932 } else if (result == UpdatableInset::FINISHED_DOWN) {
933 if (TEXT()->cursor.irow()->next()) {
935 TEXT()->setCursorFromCoordinates(
936 owner->view(), TEXT()->cursor.ix() + inset_x,
937 TEXT()->cursor.iy() -
938 TEXT()->cursor.irow()->baseline() +
939 TEXT()->cursor.irow()->height() + 1);
940 TEXT()->cursor.x_fix(TEXT()->cursor.x());
942 TEXT()->cursorDown(owner->view());
945 TEXT()->cursorRight(owner->view());
947 moveCursorUpdate(true, false);
949 goto exit_with_message;
951 #warning I am not sure this is still right, please have a look! (Jug 20020417)
952 else { // result == UNDISPATCHED
953 //setMessage(N_("Text mode"));
955 case LFUN_UNKNOWN_ACTION:
956 case LFUN_BREAKPARAGRAPH:
958 TEXT()->cursorRight(owner->view());
959 owner->view()->setState();
963 if (!TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params)) {
964 TEXT()->cursorRight(owner->view());
965 moveCursorUpdate(true, false);
968 goto exit_with_message;
970 if (TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params)) {
971 TEXT()->cursorRight(owner->view());
972 moveCursorUpdate(true, false);
975 goto exit_with_message;
977 if (TEXT()->cursor.row()->next())
978 TEXT()->cursorDown(owner->view());
980 TEXT()->cursorRight(owner->view());
981 moveCursorUpdate(true, false);
983 goto exit_with_message;
995 if (!owner->view()->available()) break;
996 // this function should be used always [asierra060396]
997 UpdatableInset * tli =
998 owner->view()->theLockingInset();
1000 UpdatableInset * lock = tli->getLockingInset();
1003 owner->view()->unlockInset(tli);
1004 TEXT()->cursorRight(owner->view());
1005 moveCursorUpdate(true, false);
1008 tli->unlockInsetInInset(owner->view(),
1013 // Tell the paragraph dialog that we changed paragraph
1014 owner->getDialogs()->updateParagraph();
1019 // --- Misc -------------------------------------------
1020 case LFUN_WORDFINDFORWARD :
1021 case LFUN_WORDFINDBACKWARD : {
1022 static string last_search;
1023 string searched_string;
1025 if (!argument.empty()) {
1026 last_search = argument;
1027 searched_string = argument;
1029 searched_string = last_search;
1031 bool fw = (action == LFUN_WORDFINDBACKWARD);
1032 if (!searched_string.empty()) {
1033 lyxfind::LyXFind(owner->view(), searched_string, fw);
1035 // owner->view()->showCursor();
1041 if (owner->view()->available() && !owner->view()->theLockingInset()) {
1042 owner->view()->update(TEXT(),
1043 BufferView::SELECT|BufferView::FITCUR);
1045 owner->message(keyseq.printOptions());
1049 // --- Misc -------------------------------------------
1050 case LFUN_EXEC_COMMAND:
1052 vector<string> allCmds;
1053 transform(lyxaction.func_begin(), lyxaction.func_end(),
1054 back_inserter(allCmds), lyx::firster());
1055 static vector<string> hist;
1056 owner->getMiniBuffer()->prepareForInput(allCmds, hist);
1060 case LFUN_CANCEL: // RVDK_PATCH_5
1062 meta_fake_bit = key_modifier::none;
1063 if (owner->view()->available())
1064 // cancel any selection
1065 dispatch(LFUN_MARK_OFF);
1066 setMessage(N_("Cancel"));
1069 case LFUN_META_FAKE: // RVDK_PATCH_5
1071 meta_fake_bit = key_modifier::alt;
1072 setMessage(keyseq.print());
1076 case LFUN_READ_ONLY_TOGGLE:
1077 if (owner->buffer()->lyxvc.inUse()) {
1078 owner->buffer()->lyxvc.toggleReadOnly();
1080 owner->buffer()->setReadonly(
1081 !owner->buffer()->isReadonly());
1085 case LFUN_CENTER: // this is center and redraw.
1086 owner->view()->center();
1089 // --- Menus -----------------------------------------------
1094 case LFUN_MENUNEWTMPLT:
1098 case LFUN_CLOSEBUFFER:
1102 case LFUN_MENUWRITE:
1103 if (!owner->buffer()->isUnnamed()) {
1105 s1 << _("Saving document") << ' '
1106 << MakeDisplayPath(owner->buffer()->fileName() + "...");
1107 owner->message(s1.str().c_str());
1108 MenuWrite(owner->view(), owner->buffer());
1110 WriteAs(owner->view(), owner->buffer());
1114 WriteAs(owner->view(), owner->buffer(), argument);
1117 case LFUN_MENURELOAD:
1122 Exporter::Export(owner->buffer(), argument, true);
1126 Exporter::Preview(owner->buffer(), argument);
1129 case LFUN_BUILDPROG:
1130 Exporter::Export(owner->buffer(), "program", true);
1133 case LFUN_RUNCHKTEX:
1134 MenuRunChktex(owner->buffer());
1137 case LFUN_MENUPRINT:
1138 owner->getDialogs()->showPrint();
1142 if (argument == "custom")
1143 owner->getDialogs()->showSendto();
1145 Exporter::Export(owner->buffer(), argument, false);
1163 InsetCommandParams p;
1166 if (action == LFUN_TOCVIEW)
1168 p.setCmdName("tableofcontents");
1170 else if (action == LFUN_LOAVIEW)
1171 p.setCmdName("listof{algorithm}{List of Algorithms}");
1172 else if (action == LFUN_LOFVIEW)
1173 p.setCmdName("listoffigures");
1175 p.setCmdName("listoftables");
1177 owner->getDialogs()->createTOC(p.getAsString());
1181 case LFUN_DIALOG_TABULAR_INSERT:
1182 owner->getDialogs()->showTabularCreate();
1186 AutoSave(owner->view());
1190 owner->view()->menuUndo();
1194 owner->view()->menuRedo();
1197 case LFUN_MENUSEARCH:
1198 owner->getDialogs()->showSearch();
1201 case LFUN_REMOVEERRORS:
1202 if (owner->view()->removeAutoInsets()) {
1203 #warning repaint() or update() or nothing ?
1204 owner->view()->repaint();
1205 owner->view()->fitCursor();
1209 case LFUN_DEPTH_MIN:
1210 changeDepth(owner->view(), TEXT(false), -1);
1213 case LFUN_DEPTH_PLUS:
1214 changeDepth(owner->view(), TEXT(false), 1);
1218 owner->getDialogs()->setUserFreeFont();
1221 case LFUN_RECONFIGURE:
1222 Reconfigure(owner->view());
1226 case LFUN_FLOATSOPERATE:
1227 if (argument == "openfoot")
1228 owner->view()->allFloats(1,0);
1229 else if (argument == "closefoot")
1230 owner->view()->allFloats(0,0);
1231 else if (argument == "openfig")
1232 owner->view()->allFloats(1,1);
1233 else if (argument == "closefig")
1234 owner->view()->allFloats(0,1);
1237 #ifdef WITH_WARNINGS
1238 //#warning Find another implementation here (or another lyxfunc)!
1241 case LFUN_HELP_ABOUTLYX:
1242 owner->getDialogs()->showAboutlyx();
1245 case LFUN_HELP_TEXINFO:
1246 owner->getDialogs()->showTexinfo();
1249 case LFUN_HELP_OPEN:
1251 string const arg = argument;
1253 setErrorMessage(N_("Missing argument"));
1256 owner->prohibitInput();
1257 string const fname = i18nLibFileSearch("doc", arg, "lyx");
1258 if (fname.empty()) {
1259 lyxerr << "LyX: unable to find documentation file `"
1260 << arg << "'. Bad installation?" << endl;
1261 owner->allowInput();
1265 str << _("Opening help file") << ' '
1266 << MakeDisplayPath(fname) << "...";
1267 owner->message(str.str().c_str());
1268 owner->view()->buffer(bufferlist.loadLyXFile(fname, false));
1269 owner->allowInput();
1273 // --- version control -------------------------------
1274 case LFUN_VC_REGISTER:
1276 if (!owner->buffer()->lyxvc.inUse())
1277 owner->buffer()->lyxvc.registrer();
1281 case LFUN_VC_CHECKIN:
1283 if (owner->buffer()->lyxvc.inUse()
1284 && !owner->buffer()->isReadonly())
1285 owner->buffer()->lyxvc.checkIn();
1289 case LFUN_VC_CHECKOUT:
1291 if (owner->buffer()->lyxvc.inUse()
1292 && owner->buffer()->isReadonly())
1293 owner->buffer()->lyxvc.checkOut();
1297 case LFUN_VC_REVERT:
1299 owner->buffer()->lyxvc.revert();
1305 owner->buffer()->lyxvc.undoLast();
1309 case LFUN_VC_HISTORY:
1311 owner->getDialogs()->showVCLogFile();
1315 // --- buffers ----------------------------------------
1317 case LFUN_SWITCHBUFFER:
1318 owner->view()->buffer(bufferlist.getBuffer(argument));
1323 // servercmd: argument must be <file>:<template>
1324 Buffer * tmpbuf = NewLyxFile(argument);
1326 owner->view()->buffer(tmpbuf);
1330 case LFUN_FILE_OPEN:
1334 case LFUN_LATEX_LOG:
1335 owner->getDialogs()->showLogFile();
1338 case LFUN_LAYOUT_DOCUMENT:
1339 owner->getDialogs()->showDocument();
1342 case LFUN_LAYOUT_PARAGRAPH:
1343 owner->getDialogs()->showParagraph();
1346 case LFUN_LAYOUT_CHARACTER:
1347 owner->getDialogs()->showCharacter();
1350 case LFUN_LAYOUT_TABULAR:
1351 if (owner->view()->theLockingInset()) {
1352 if (owner->view()->theLockingInset()->lyxCode()==Inset::TABULAR_CODE) {
1353 InsetTabular * inset = static_cast<InsetTabular *>
1354 (owner->view()->theLockingInset());
1355 inset->openLayoutDialog(owner->view());
1356 } else if (owner->view()->theLockingInset()->
1357 getFirstLockingInsetOfType(Inset::TABULAR_CODE)!=0) {
1358 InsetTabular * inset = static_cast<InsetTabular *>(
1359 owner->view()->theLockingInset()->getFirstLockingInsetOfType(Inset::TABULAR_CODE));
1360 inset->openLayoutDialog(owner->view());
1365 case LFUN_LAYOUT_PREAMBLE:
1366 owner->getDialogs()->showPreamble();
1369 case LFUN_DROP_LAYOUTS_CHOICE:
1370 owner->getToolbar()->openLayoutList();
1373 case LFUN_MENU_OPEN_BY_NAME:
1374 owner->getMenubar()->openByName(argument);
1375 break; // RVDK_PATCH_5
1377 case LFUN_SPELLCHECK:
1378 if (lyxrc.isp_command != "none")
1379 owner->getDialogs()->showSpellchecker();
1382 // --- lyxserver commands ----------------------------
1386 setMessage(owner->buffer()->fileName());
1387 lyxerr[Debug::INFO] << "FNAME["
1388 << owner->buffer()->fileName()
1394 dispatch_buffer = keyseq.print();
1395 lyxserver->notifyClient(dispatch_buffer);
1399 case LFUN_GOTOFILEROW:
1403 istringstream istr(argument.c_str());
1404 istr >> file_name >> row;
1405 // Must replace extension of the file to be .lyx and get full path
1406 string const s(ChangeExtension(file_name, ".lyx"));
1408 // Either change buffer or load the file
1409 if (bufferlist.exists(s)) {
1410 owner->view()->buffer(bufferlist.getBuffer(s));
1412 owner->view()->buffer(bufferlist.loadLyXFile(s));
1416 owner->view()->setCursorFromRow(row);
1419 owner->view()->center();
1423 case LFUN_GOTO_PARAGRAPH:
1425 istringstream istr(argument.c_str());
1429 Paragraph * par = owner->buffer()->getParFromID(id);
1431 lyxerr[Debug::INFO] << "No matching paragraph found! ["
1432 << id << "]" << endl;
1435 lyxerr[Debug::INFO] << "Paragraph " << par->id()
1436 << " found." << endl;
1439 if (owner->view()->theLockingInset())
1440 owner->view()->unlockInset(owner->view()->theLockingInset());
1441 if (par->inInset()) {
1442 par->inInset()->edit(owner->view());
1445 owner->view()->getLyXText()->setCursor(owner->view(), par, 0);
1446 owner->view()->setState();
1450 owner->view()->center();
1457 int const qa = lyxaction.LookupFunc(argument);
1458 setMessage(lyxaction.helpText(static_cast<kb_action>(qa)));
1462 // --- toolbar ----------------------------------
1463 case LFUN_PUSH_TOOLBAR:
1465 int nth = strToInt(argument);
1467 setErrorMessage(N_("Push-toolbar needs argument > 0"));
1469 owner->getToolbar()->push(nth);
1474 case LFUN_ADD_TO_TOOLBAR:
1476 if (lyxerr.debugging(Debug::GUI)) {
1477 lyxerr << "LFUN_ADD_TO_TOOLBAR:"
1478 "argument = `" << argument << '\'' << endl;
1480 string tmp(argument);
1481 //lyxerr <<string("Argument: ") + argument);
1482 //lyxerr <<string("Tmp : ") + tmp);
1484 setErrorMessage(N_("Usage: toolbar-add-to <LyX command>"));
1486 owner->getToolbar()->add(argument, false);
1487 owner->getToolbar()->set();
1492 // --- insert characters ----------------------------------------
1494 // --- Mathed stuff. If we are here, there is no locked inset yet.
1495 case LFUN_MATH_EXTERN:
1496 case LFUN_MATH_NUMBER:
1497 case LFUN_MATH_NONUMBER:
1498 case LFUN_MATH_LIMITS:
1500 setErrorMessage(N_("This is only allowed in math mode!"));
1504 // passthrough hat and underscore outside mathed:
1505 case LFUN_SUBSCRIPT:
1506 dispatch(LFUN_SELFINSERT, "_");
1508 case LFUN_SUPERSCRIPT:
1509 dispatch(LFUN_SELFINSERT, "^");
1512 case LFUN_MATH_PANEL:
1513 owner->getDialogs()->showMathPanel();
1516 case LFUN_CITATION_CREATE:
1518 InsetCommandParams p("cite");
1520 if (!argument.empty()) {
1521 // This should be set at source, ie when typing
1522 // "citation-insert foo" in the minibuffer.
1523 // Question: would pybibliographer also need to be
1524 // changed. Suspect so. Leave as-is therefore.
1525 if (contains(argument, "|")) {
1526 p.setContents(token(argument, '|', 0));
1527 p.setOptions( token(argument, '|', 1));
1529 p.setContents(argument);
1531 dispatch(LFUN_CITATION_INSERT, p.getAsString());
1533 owner->getDialogs()->createCitation(p.getAsString());
1537 case LFUN_CHILDOPEN:
1539 string const filename =
1540 MakeAbsPath(argument,
1541 owner->buffer()->filePath());
1542 setMessage(N_("Opening child document ") +
1543 MakeDisplayPath(filename) + "...");
1544 owner->view()->savePosition(0);
1545 if (bufferlist.exists(filename))
1546 owner->view()->buffer(bufferlist.getBuffer(filename));
1548 owner->view()->buffer(bufferlist.loadLyXFile(filename));
1552 case LFUN_TOGGLECURSORFOLLOW:
1553 lyxrc.cursor_follows_scrollbar = !lyxrc.cursor_follows_scrollbar;
1556 case LFUN_KMAP_OFF: // keymap off
1557 owner->getIntl()->KeyMapOn(false);
1560 case LFUN_KMAP_PRIM: // primary keymap
1561 owner->getIntl()->KeyMapPrim();
1564 case LFUN_KMAP_SEC: // secondary keymap
1565 owner->getIntl()->KeyMapSec();
1568 case LFUN_KMAP_TOGGLE: // toggle keymap
1569 owner->getIntl()->ToggleKeyMap();
1574 // argument contains ';'-terminated commands
1575 while (argument.find(';') != string::npos) {
1577 argument = split(argument, first, ';');
1578 verboseDispatch(first, false);
1583 case LFUN_DIALOG_PREFERENCES:
1584 owner->getDialogs()->showPreferences();
1587 case LFUN_SAVEPREFERENCES:
1589 Path p(user_lyxdir);
1590 lyxrc.write("preferences");
1594 case LFUN_SCREEN_FONT_UPDATE:
1596 // handle the screen font changes.
1598 lyxrc.set_font_norm_type();
1599 fontloader.update();
1600 // Of course we should only do the resize and the textcache.clear
1601 // if values really changed...but not very important right now. (Lgb)
1602 // All visible buffers will need resize
1603 owner->view()->resize();
1604 // We also need to empty the textcache so that
1605 // the buffer will be formatted correctly after
1611 case LFUN_SET_COLOR:
1614 string const x11_name = split(argument, lyx_name, ' ');
1615 if (lyx_name.empty() || x11_name.empty()) {
1616 setErrorMessage(N_("Syntax: set-color <lyx_name>"
1621 bool const graphicsbg_changed =
1622 (lyx_name == lcolor.getLyXName(LColor::graphicsbg) &&
1623 x11_name != lcolor.getX11Name(LColor::graphicsbg));
1625 if (!lcolor.setColor(lyx_name, x11_name)) {
1626 static string const err1 (N_("Set-color \""));
1627 static string const err2 (
1628 N_("\" failed - color is undefined "
1629 "or may not be redefined"));
1630 setErrorMessage(_(err1) + lyx_name + _(err2));
1634 lyxColorHandler->updateColor(lcolor.getFromLyXName(lyx_name));
1636 if (graphicsbg_changed) {
1637 #ifdef WITH_WARNINGS
1638 #warning FIXME!! The graphics cache no longer has a changeDisplay method.
1641 grfx::GCache & gc = grfx::GCache::get();
1642 gc.changeDisplay(true);
1646 owner->view()->repaint();
1651 owner->message(argument);
1654 case LFUN_MESSAGE_PUSH:
1655 owner->messagePush(argument);
1658 case LFUN_MESSAGE_POP:
1659 owner->messagePop();
1662 case LFUN_FORKS_SHOW:
1663 owner->getDialogs()->showForks();
1666 case LFUN_FORKS_KILL:
1668 if (!isStrInt(argument))
1671 pid_t const pid = strToInt(argument);
1672 ForkedcallsController & fcc = ForkedcallsController::get();
1677 case LFUN_TOOLTIPS_TOGGLE:
1678 owner->getDialogs()->toggleTooltips();
1682 // Then if it was none of the above
1683 // Trying the BufferView::pimpl dispatch:
1684 if (!owner->view()->Dispatch(action, argument))
1685 lyxerr << "A truly unknown func ["
1686 << lyxaction.getActionName(action) << "]!"
1693 string const res = getMessage();
1696 owner->message(_(res));
1697 owner->updateMenubar();
1698 owner->updateToolbar();
1704 void LyXFunc::setupLocalKeymap()
1706 keyseq.stdmap = keyseq.curmap = toplevel_keymap.get();
1707 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap.get();
1711 void LyXFunc::menuNew(bool fromTemplate)
1713 string initpath = lyxrc.document_path;
1715 if (owner->view()->available()) {
1716 string const trypath = owner->buffer()->filePath();
1717 // If directory is writeable, use this as default.
1718 if (IsDirWriteable(trypath))
1722 static int newfile_number;
1725 if (lyxrc.new_ask_filename) {
1726 FileDialog fileDlg(owner, _("Enter filename for new document"),
1727 LFUN_SELECT_FILE_SYNC,
1728 make_pair(string(_("Documents|#o#O")),
1729 string(lyxrc.document_path)),
1730 make_pair(string(_("Templates|#T#t")),
1731 string(lyxrc.template_path)));
1733 FileDialog::Result result =
1734 fileDlg.Select(initpath,
1735 _("*.lyx|LyX Documents (*.lyx)"),
1738 if (result.second.empty()) {
1739 owner->message(_("Canceled."));
1740 lyxerr[Debug::INFO] << "New Document Cancelled." << endl;
1744 // get absolute path of file and make sure the filename ends
1746 s = MakeAbsPath(result.second);
1747 if (!IsLyXFilename(s))
1750 // Check if the document already is open
1751 if (bufferlist.exists(s)) {
1752 switch (Alert::askConfirmation(_("Document is already open:"),
1753 MakeDisplayPath(s, 50),
1754 _("Do you want to close that document now?\n"
1755 "('No' will just switch to the open version)")))
1757 case 1: // Yes: close the document
1758 if (!bufferlist.close(bufferlist.getBuffer(s)))
1759 // If close is canceled, we cancel here too.
1762 case 2: // No: switch to the open document
1763 owner->view()->buffer(bufferlist.getBuffer(s));
1765 case 3: // Cancel: Do nothing
1766 owner->message(_("Canceled."));
1770 // Check whether the file already exists
1772 if (fi.readable() &&
1773 Alert::askQuestion(_("File already exists:"),
1774 MakeDisplayPath(s, 50),
1775 _("Do you want to open the document?"))) {
1777 string const disp_fn(MakeDisplayPath(s));
1780 str << _("Opening document") << ' '
1781 << disp_fn << "...";
1783 owner->message(str.str().c_str());
1784 owner->view()->buffer(bufferlist.loadLyXFile(s));
1786 str2 << _("Document") << ' '
1787 << disp_fn << ' ' << _("opened.");
1789 owner->message(str2.str().c_str());
1794 s = AddName(lyxrc.document_path,
1795 "newfile" + tostr(++newfile_number) + ".lyx");
1797 while (bufferlist.exists(s) || fi.readable()) {
1799 s = AddName(lyxrc.document_path,
1800 "newfile" + tostr(newfile_number) +
1806 // The template stuff
1809 FileDialog fileDlg(owner, _("Select template file"),
1810 LFUN_SELECT_FILE_SYNC,
1811 make_pair(string(_("Documents|#o#O")),
1812 string(lyxrc.document_path)),
1813 make_pair(string(_("Templates|#T#t")),
1814 string(lyxrc.template_path)));
1816 FileDialog::Result result =
1817 fileDlg.Select(lyxrc.template_path,
1818 _("*.lyx|LyX Documents (*.lyx)"));
1820 if (result.first == FileDialog::Later)
1823 string const fname = result.second;
1830 // find a free buffer
1831 lyxerr[Debug::INFO] << "Find a free buffer." << endl;
1832 owner->view()->buffer(bufferlist.newFile(s, templname));
1836 void LyXFunc::open(string const & fname)
1838 string initpath = lyxrc.document_path;
1840 if (owner->view()->available()) {
1841 string const trypath = owner->buffer()->filePath();
1842 // If directory is writeable, use this as default.
1843 if (IsDirWriteable(trypath))
1849 if (fname.empty()) {
1850 FileDialog fileDlg(owner, _("Select document to open"),
1852 make_pair(string(_("Documents|#o#O")),
1853 string(lyxrc.document_path)),
1854 make_pair(string(_("Examples|#E#e")),
1855 string(AddPath(system_lyxdir, "examples"))));
1857 FileDialog::Result result =
1858 fileDlg.Select(initpath,
1859 "*.lyx|LyX Documents (*.lyx)");
1861 if (result.first == FileDialog::Later)
1864 filename = result.second;
1866 // check selected filename
1867 if (filename.empty()) {
1868 owner->message(_("Canceled."));
1874 // get absolute path of file and add ".lyx" to the filename if
1876 string const fullpath = FileSearch(string(), filename, "lyx");
1877 if (fullpath.empty()) {
1878 Alert::alert(_("Error"), _("Could not find file"), filename);
1882 filename = fullpath;
1885 string const disp_fn(MakeDisplayPath(filename));
1888 str << _("Opening document") << ' ' << disp_fn << "...";
1890 owner->message(str.str().c_str());
1892 Buffer * openbuf = bufferlist.loadLyXFile(filename);
1894 owner->view()->buffer(openbuf);
1896 str << _("Document") << ' ' << disp_fn << ' ' << _("opened.");
1897 owner->message(str.str().c_str());
1900 str << _("Could not open document") << ' ' << disp_fn;
1901 owner->message(str.str().c_str());
1906 void LyXFunc::doImport(string const & argument)
1909 string filename = split(argument, format, ' ');
1911 lyxerr[Debug::INFO] << "LyXFunc::doImport: " << format
1912 << " file: " << filename << endl;
1914 // need user interaction
1915 if (filename.empty()) {
1916 string initpath = lyxrc.document_path;
1918 if (owner->view()->available()) {
1919 string const trypath = owner->buffer()->filePath();
1920 // If directory is writeable, use this as default.
1921 if (IsDirWriteable(trypath))
1925 string const text = _("Select ") + formats.prettyName(format)
1926 + _(" file to import");
1928 FileDialog fileDlg(owner, text,
1930 make_pair(string(_("Documents|#o#O")),
1931 string(lyxrc.document_path)),
1932 make_pair(string(_("Examples|#E#e")),
1933 string(AddPath(system_lyxdir, "examples"))));
1935 string const extension = "*." + formats.extension(format)
1936 + "| " + formats.prettyName(format)
1937 + " (*." + formats.extension(format) + ")";
1939 FileDialog::Result result = fileDlg.Select(initpath,
1942 if (result.first == FileDialog::Later)
1945 filename = result.second;
1947 // check selected filename
1948 if (filename.empty())
1949 owner->message(_("Canceled."));
1952 if (filename.empty())
1955 // get absolute path of file
1956 filename = MakeAbsPath(filename);
1958 string const lyxfile = ChangeExtension(filename, ".lyx");
1960 // Check if the document already is open
1961 if (lyxrc.use_gui && bufferlist.exists(lyxfile)) {
1962 switch (Alert::askConfirmation(_("Document is already open:"),
1963 MakeDisplayPath(lyxfile, 50),
1964 _("Do you want to close that document now?\n"
1965 "('No' will just switch to the open version)")))
1968 // If close is canceled, we cancel here too.
1969 if (!bufferlist.close(bufferlist.getBuffer(lyxfile)))
1973 owner->view()->buffer(bufferlist.getBuffer(lyxfile));
1976 owner->message(_("Canceled."));
1981 // if the file exists already, and we didn't do
1982 // -i lyx thefile.lyx, warn
1983 if (FileInfo(lyxfile, true).exist() && filename != lyxfile) {
1984 if (!Alert::askQuestion(_("A document by the name"),
1985 MakeDisplayPath(lyxfile), _("already exists. Overwrite?"))) {
1986 owner->message(_("Canceled"));
1991 Importer::Import(owner, filename, format);
1995 void LyXFunc::reloadBuffer()
1997 string const fn = owner->buffer()->fileName();
1998 if (bufferlist.close(owner->buffer()))
1999 owner->view()->buffer(bufferlist.loadLyXFile(fn));
2003 void LyXFunc::closeBuffer()
2005 if (bufferlist.close(owner->buffer()) && !quitting) {
2006 if (bufferlist.empty()) {
2007 // need this otherwise SEGV may occur while trying to
2008 // set variables that don't exist
2009 // since there's no current buffer
2010 owner->getDialogs()->hideBufferDependent();
2012 owner->view()->buffer(bufferlist.first());
2018 // Each "owner" should have it's own message method. lyxview and
2019 // the minibuffer would use the minibuffer, but lyxserver would
2020 // send an ERROR signal to its client. Alejandro 970603
2021 // This func is bit problematic when it comes to NLS, to make the
2022 // lyx servers client be language indepenent we must not translate
2023 // strings sent to this func.
2024 void LyXFunc::setErrorMessage(string const & m) const
2026 dispatch_buffer = m;
2031 void LyXFunc::setMessage(string const & m) const
2033 dispatch_buffer = m;
2037 void LyXFunc::setStatusMessage(string const & m) const
2043 void LyXFunc::initMiniBuffer()
2045 string text = _("Welcome to LyX!");
2047 // When meta-fake key is pressed, show the key sequence so far + "M-".
2049 text = keyseq.print();
2053 // Else, when a non-complete key sequence is pressed,
2054 // show the available options.
2055 if (keyseq.length() > 0 && !keyseq.deleted()) {
2056 text = keyseq.printOptions();
2059 // Else, show the buffer state.
2060 else if (owner->view()->available()) {
2061 Buffer * tmpbuf = owner->buffer();
2063 string const nicename =
2064 MakeDisplayPath(tmpbuf->fileName());
2065 // Should we do this instead? (kindo like emacs)
2066 // leaves more room for other information
2069 if (tmpbuf->lyxvc.inUse()) {
2071 text += tmpbuf->lyxvc.versionString();
2073 text += tmpbuf->lyxvc.locker();
2074 if (tmpbuf->isReadonly())
2077 } else if (tmpbuf->isReadonly())
2079 if (!tmpbuf->isLyxClean())
2080 text += _(" (Changed)");
2082 if (text != _("Welcome to LyX!")) // this is a hack
2083 text = _("* No document open *");
2086 owner->message(text);