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.getiso();
209 if (keyseq.length() > 1) {
213 owner->getIntl()->getTrans()
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(KeySym keysym, key_modifier::state state)
229 if (lyxerr.debugging(Debug::KEY)) {
230 char const * tmp = XKeysymToString(keysym);
231 string const stm = (tmp ? tmp : "");
232 lyxerr << "KeySym 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 if (lyxerr.debugging(Debug::KEY)) {
260 lyxerr << "action first set to [" << action << "]" << endl;
263 // When not cancel or meta-fake, do the normal lookup.
264 // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
265 // Mostly, meta_fake_bit = key_modifier::none. RVDK_PATCH_5.
266 if ((action != LFUN_CANCEL) && (action != LFUN_META_FAKE)) {
268 if (lyxerr.debugging(Debug::KEY)) {
269 lyxerr << "meta_fake_bit is ["
270 << meta_fake_bit << "]" << endl;
273 // remove Caps Lock and Mod2 as a modifiers
274 action = keyseq.addkey(keysym, (state | meta_fake_bit));
275 if (lyxerr.debugging(Debug::KEY)) {
276 lyxerr << "action now set to ["
277 << action << "]" << endl;
280 // Dont remove this unless you know what you are doing.
281 meta_fake_bit = key_modifier::none;
283 // can this happen now ?
284 if (action == LFUN_NOACTION) {
285 action = LFUN_PREFIX;
288 if (lyxerr.debugging(Debug::KEY)) {
289 lyxerr << "Key [action="
291 << keyseq.print() << "]"
295 // already here we know if it any point in going further
296 // why not return already here if action == -1 and
297 // num_bytes == 0? (Lgb)
299 if (keyseq.length() > 1) {
300 owner->message(keyseq.print());
303 if (action == LFUN_UNKNOWN_ACTION) {
304 // It is unknown, but what if we remove all
305 // the modifiers? (Lgb)
306 action = keyseq.addkey(keysym, key_modifier::none);
308 if (lyxerr.debugging(Debug::KEY)) {
309 lyxerr << "Removing modifiers...\n"
310 << "Action now set to ["
311 << action << "]" << endl;
313 if (action == LFUN_UNKNOWN_ACTION) {
314 owner->message(_("Unknown function."));
319 if (action == LFUN_SELFINSERT) {
320 // This is very X dependent.
321 unsigned int c = keysym;
324 c = kb_keymap::getiso(c);
327 argument = static_cast<char>(c);
329 dispatch(LFUN_SELFINSERT, argument);
330 lyxerr[Debug::KEY] << "SelfInsert arg[`"
331 << argument << "']" << endl;
334 verboseDispatch(action, false);
338 FuncStatus LyXFunc::getStatus(int ac) const
342 action = lyxaction.retrieveActionArg(ac, argument);
343 return getStatus(action, argument);
347 FuncStatus LyXFunc::getStatus(kb_action action,
348 string const & argument) const
351 Buffer * buf = owner->buffer();
353 if (action == LFUN_NOACTION) {
354 setStatusMessage(N_("Nothing to do"));
355 return flag.disabled(true);
358 if (action == LFUN_UNKNOWN_ACTION) {
359 setStatusMessage(N_("Unknown action"));
360 return flag.unknown(true);
363 // the default error message if we disable the command
364 setStatusMessage(N_("Command disabled"));
366 // Check whether we need a buffer
367 if (!lyxaction.funcHasFlag(action, LyXAction::NoBuffer)) {
368 // Yes we need a buffer, do we have one?
371 // Can we use a readonly buffer?
372 if (buf->isReadonly() &&
373 !lyxaction.funcHasFlag(action,
374 LyXAction::ReadOnly)) {
376 setStatusMessage(N_("Document is read-only"));
381 setStatusMessage(N_("Command not allowed with"
382 "out any document open"));
383 return flag.disabled(true);
387 UpdatableInset * tli = owner->view()->theLockingInset();
389 // I would really like to avoid having this switch and rather try to
390 // encode this in the function itself.
391 bool disable = false;
394 disable = !Exporter::IsExportable(buf, "dvi")
395 || lyxrc.print_command == "none";
398 disable = argument == "fax" &&
399 !Exporter::IsExportable(buf, argument);
402 disable = buf->undostack.empty();
405 disable = buf->redostack.empty();
407 case LFUN_SPELLCHECK:
408 disable = lyxrc.isp_command == "none";
410 #ifndef HAVE_LIBAIKSAURUS
411 case LFUN_THESAURUS_ENTRY:
416 disable = lyxrc.chktex_command == "none";
419 disable = !Exporter::IsExportable(buf, "program");
422 case LFUN_LAYOUT_TABULAR:
424 || (tli->lyxCode() != Inset::TABULAR_CODE
425 && !tli->getFirstLockingInsetOfType(Inset::TABULAR_CODE));
429 case LFUN_LAYOUT_PARAGRAPH: {
430 Inset * inset = TEXT(false)->cursor.par()->inInset();
431 disable = inset && inset->forceDefaultParagraphs(inset);
435 case LFUN_TABULAR_FEATURE:
439 //ret.disabled(true);
440 if (tli->lyxCode() == Inset::TABULAR_CODE) {
441 ret = static_cast<InsetTabular *>(tli)
442 ->getStatus(argument);
443 } else if (tli->getFirstLockingInsetOfType(Inset::TABULAR_CODE)) {
444 ret = static_cast<InsetTabular *>
445 (tli->getFirstLockingInsetOfType(Inset::TABULAR_CODE))
446 ->getStatus(argument);
451 static InsetTabular inset(*owner->buffer(), 1, 1);
455 ret = inset.getStatus(argument);
456 if (ret.onoff(true) || ret.onoff(false))
457 flag.setOnOff(false);
461 case LFUN_VC_REGISTER:
462 disable = buf->lyxvc.inUse();
464 case LFUN_VC_CHECKIN:
465 disable = !buf->lyxvc.inUse() || buf->isReadonly();
467 case LFUN_VC_CHECKOUT:
468 disable = !buf->lyxvc.inUse() || !buf->isReadonly();
472 case LFUN_VC_HISTORY:
473 disable = !buf->lyxvc.inUse();
475 case LFUN_BOOKMARK_GOTO:
476 disable = !owner->view()->
477 isSavedPosition(strToUnsignedInt(argument));
481 case LFUN_INSET_TOGGLE: {
482 LyXText * lt = owner->view()->getLyXText();
483 disable = !(isEditableInset(lt->getInset())
485 && lt->inset_owner->owner()
486 && lt->inset_owner->owner()->isOpen()));
489 case LFUN_MATH_VALIGN:
490 if (mathcursor && mathcursor->formula()->getType() != LM_OT_SIMPLE) {
491 char align = mathcursor->valign();
496 if (argument.empty()) {
500 if (!contains("tcb", argument[0])) {
504 flag.setOnOff(argument[0] == align);
509 case LFUN_MATH_HALIGN:
510 if (mathcursor && mathcursor->formula()->getType() != LM_OT_SIMPLE) {
511 char align = mathcursor->halign();
516 if (argument.empty()) {
520 if (!contains("lcr", argument[0])) {
524 flag.setOnOff(argument[0] == align);
529 case LFUN_MATH_MUTATE:
530 if (tli && (tli->lyxCode() == Inset::MATH_CODE)) {
531 MathInsetTypes type = mathcursor->formula()->getType();
532 if (argument == "inline") {
533 flag.setOnOff(type == LM_OT_SIMPLE);
534 } else if (argument == "display") {
535 flag.setOnOff(type == LM_OT_EQUATION);
536 } else if (argument == "eqnarray") {
537 flag.setOnOff(type == LM_OT_EQNARRAY);
538 } else if (argument == "align") {
539 flag.setOnOff(type == LM_OT_ALIGN);
540 } else if (argument == "none") {
541 flag.setOnOff(type == LM_OT_NONE);
549 // we just need to be in math mode to enable that
551 case LFUN_MATH_SPACE:
552 case LFUN_MATH_LIMITS:
553 case LFUN_MATH_NONUMBER:
554 case LFUN_MATH_NUMBER:
555 disable = !mathcursor;
558 // we need to be math mode and a math array for that
559 // Hack: halign produces non-zero result iff we are in a math array
560 case LFUN_MATH_ROW_INSERT:
561 case LFUN_MATH_ROW_DELETE:
562 case LFUN_MATH_COLUMN_INSERT:
563 case LFUN_MATH_COLUMN_DELETE:
564 disable = !mathcursor || !mathcursor->halign() ||
565 mathcursor->formula()->getType() == LM_OT_SIMPLE;
572 // the functions which insert insets
573 Inset::Code code = Inset::NO_CODE;
576 code = Inset::ERT_CODE;
578 case LFUN_INSET_GRAPHICS:
579 code = Inset::GRAPHICS_CODE;
581 case LFUN_INSET_FOOTNOTE:
582 code = Inset::FOOT_CODE;
584 case LFUN_DIALOG_TABULAR_INSERT:
585 case LFUN_INSET_TABULAR:
586 code = Inset::TABULAR_CODE;
588 case LFUN_INSET_EXTERNAL:
589 code = Inset::EXTERNAL_CODE;
591 case LFUN_INSET_MARGINAL:
592 code = Inset::MARGIN_CODE;
594 case LFUN_INSET_MINIPAGE:
595 code = Inset::MINIPAGE_CODE;
597 case LFUN_INSET_FLOAT:
598 case LFUN_INSET_WIDE_FLOAT:
599 code = Inset::FLOAT_CODE;
601 case LFUN_FLOAT_LIST:
602 code = Inset::FLOAT_LIST_CODE;
605 case LFUN_INSET_LIST:
606 code = Inset::LIST_CODE;
608 case LFUN_INSET_THEOREM:
609 code = Inset::THEOREM_CODE;
612 case LFUN_INSET_CAPTION:
613 code = Inset::CAPTION_CODE;
615 case LFUN_INSERT_NOTE:
616 code = Inset::IGNORE_CODE;
618 case LFUN_INSERT_LABEL:
619 code = Inset::LABEL_CODE;
621 case LFUN_REF_INSERT:
622 code = Inset::REF_CODE;
624 case LFUN_CITATION_CREATE:
625 case LFUN_CITATION_INSERT:
626 code = Inset::CITE_CODE;
628 case LFUN_INSERT_BIBTEX:
629 code = Inset::BIBTEX_CODE;
631 case LFUN_INDEX_INSERT:
632 case LFUN_INDEX_INSERT_LAST:
633 case LFUN_INDEX_CREATE:
634 code = Inset::INDEX_CODE;
636 case LFUN_INDEX_PRINT:
637 code = Inset::INDEX_PRINT_CODE;
639 case LFUN_CHILD_INSERT:
640 code = Inset::INCLUDE_CODE;
642 case LFUN_TOC_INSERT:
643 code = Inset::TOC_CODE;
645 case LFUN_PARENTINSERT:
646 code = Inset::PARENT_CODE;
650 case LFUN_INSERT_URL:
651 code = Inset::URL_CODE;
654 // always allow this, since we will inset a raw quote
655 // if an inset is not allowed.
657 case LFUN_HYPHENATION:
658 case LFUN_LIGATURE_BREAK:
660 case LFUN_MENU_SEPARATOR:
662 case LFUN_END_OF_SENTENCE:
663 code = Inset::SPECIALCHAR_CODE;
665 case LFUN_PROTECTEDSPACE:
666 // slight hack: we know this is allowed in math mode
668 code = Inset::SPECIALCHAR_CODE;
673 if (code != Inset::NO_CODE && tli && !tli->insetAllowed(code)) {
680 // A few general toggles
682 case LFUN_TOOLTIPS_TOGGLE:
683 flag.setOnOff(owner->getDialogs()->tooltipsEnabled());
686 case LFUN_READ_ONLY_TOGGLE:
687 flag.setOnOff(buf->isReadonly());
690 flag.setOnOff(TEXT(false)->cursor.par()->params().startOfAppendix());
692 case LFUN_SWITCHBUFFER:
693 // toggle on the current buffer, but do not toggle off
694 // the other ones (is that a good idea?)
695 if (argument == buf->fileName())
702 // the font related toggles
704 LyXFont const & font = TEXT(false)->real_current_font;
707 flag.setOnOff(font.emph() == LyXFont::ON);
710 flag.setOnOff(font.noun() == LyXFont::ON);
713 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
716 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
719 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
722 flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
729 string tc = mathcursor->getLastCode();
732 flag.setOnOff(tc == "mathbf");
735 flag.setOnOff(tc == "mathsf");
738 flag.setOnOff(tc == "mathcal");
741 flag.setOnOff(tc == "mathrm");
744 flag.setOnOff(tc == "mathtt");
747 flag.setOnOff(tc == "mathbb");
750 flag.setOnOff(tc == "mathnormal");
761 // temporary dispatch method
762 void LyXFunc::miniDispatch(string const & s)
764 string s2(frontStrip(strip(s)));
767 verboseDispatch(s2, true);
772 void LyXFunc::verboseDispatch(string const & s, bool show_sc)
774 int action = lyxaction.LookupFunc(frontStrip(s));
776 if (action == LFUN_UNKNOWN_ACTION) {
777 string const msg = string(_("Unknown function ("))
781 verboseDispatch(action, show_sc);
786 void LyXFunc::verboseDispatch(int ac, bool show_sc)
791 // get the real action and argument
792 action = lyxaction.retrieveActionArg(ac, argument);
794 verboseDispatch(action, argument, show_sc);
799 void LyXFunc::verboseDispatch(kb_action action,
800 string const & argument, bool show_sc)
802 string res = dispatch(action, argument);
804 commandshortcut.erase();
806 if (lyxrc.display_shortcuts && show_sc) {
807 if (action != LFUN_SELFINSERT) {
808 // Put name of command and list of shortcuts
809 // for it in minibuffer
810 string comname = lyxaction.getActionName(action);
812 int pseudoaction = action;
813 bool argsadded = false;
815 if (!argument.empty()) {
816 // the pseudoaction is useful for the bindings
818 lyxaction.searchActionArg(action,
821 if (pseudoaction == LFUN_UNKNOWN_ACTION) {
822 pseudoaction = action;
824 comname += " " + argument;
829 string const shortcuts =
830 toplevel_keymap->findbinding(pseudoaction);
832 if (!shortcuts.empty()) {
833 comname += ": " + shortcuts;
834 } else if (!argsadded && !argument.empty()) {
835 comname += " " + argument;
838 if (!comname.empty()) {
839 comname = strip(comname);
840 commandshortcut = "(" + comname + ')';
846 if (!commandshortcut.empty()) {
847 owner->getMiniBuffer()->addSet(commandshortcut);
850 owner->getMiniBuffer()->addSet(' ' + commandshortcut);
855 string const LyXFunc::dispatch(kb_action action, string argument)
857 lyxerr[Debug::ACTION] << "LyXFunc::Dispatch: action[" << action
858 <<"] arg[" << argument << "]" << endl;
860 // we have not done anything wrong yet.
862 dispatch_buffer.erase();
864 #ifdef NEW_DISPATCHER
865 // We try do call the most specific dispatcher first:
866 // 1. the lockinginset's dispatch
867 // 2. the bufferview's dispatch
868 // 3. the lyxview's dispatch
871 selection_possible = false;
873 if (owner->view()->available())
874 owner->view()->hideCursor();
876 // We cannot use this function here
877 if (getStatus(action, argument).disabled()) {
878 lyxerr[Debug::ACTION] << "LyXFunc::Dispatch: "
879 << lyxaction.getActionName(action)
880 << " [" << action << "] is disabled at this location"
882 setErrorMessage(getStatusMessage());
883 goto exit_with_message;
886 if (owner->view()->available() && owner->view()->theLockingInset()) {
887 UpdatableInset::RESULT result;
888 if ((action > 1) || ((action == LFUN_UNKNOWN_ACTION) &&
889 (!keyseq.deleted())))
891 UpdatableInset * inset = owner->view()->theLockingInset();
895 inset->getCursorPos(owner->view(), inset_x, dummy_y);
897 if ((action == LFUN_UNKNOWN_ACTION)
898 && argument.empty()) {
899 argument = keyseq.getiso();
901 // Undo/Redo is a bit tricky for insets.
902 if (action == LFUN_UNDO) {
903 owner->view()->menuUndo();
904 goto exit_with_message;
905 } else if (action == LFUN_REDO) {
906 owner->view()->menuRedo();
907 goto exit_with_message;
908 } else if (((result=inset->
909 // Hand-over to inset's own dispatch:
910 localDispatch(owner->view(), action, argument)) ==
911 UpdatableInset::DISPATCHED) ||
912 (result == UpdatableInset::DISPATCHED_NOUPDATE))
913 goto exit_with_message;
914 // If UNDISPATCHED, just soldier on
915 else if (result == UpdatableInset::FINISHED) {
916 if (TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params)) {
917 TEXT()->cursorRight(owner->view());
918 moveCursorUpdate(true, false);
921 goto exit_with_message;
922 } else if (result == UpdatableInset::FINISHED_RIGHT) {
923 if (!TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params)) {
924 TEXT()->cursorRight(owner->view());
925 moveCursorUpdate(true, false);
928 goto exit_with_message;
929 } else if (result == UpdatableInset::FINISHED_UP) {
930 if (TEXT()->cursor.irow()->previous()) {
932 TEXT()->setCursorFromCoordinates(
933 owner->view(), TEXT()->cursor.ix() + inset_x,
934 TEXT()->cursor.iy() -
935 TEXT()->cursor.irow()->baseline() - 1);
936 TEXT()->cursor.x_fix(TEXT()->cursor.x());
938 TEXT()->cursorUp(owner->view());
940 moveCursorUpdate(true, false);
943 owner->view()->update(TEXT(), BufferView::SELECT|BufferView::FITCUR);
945 goto exit_with_message;
946 } else if (result == UpdatableInset::FINISHED_DOWN) {
947 if (TEXT()->cursor.irow()->next()) {
949 TEXT()->setCursorFromCoordinates(
950 owner->view(), TEXT()->cursor.ix() + inset_x,
951 TEXT()->cursor.iy() -
952 TEXT()->cursor.irow()->baseline() +
953 TEXT()->cursor.irow()->height() + 1);
954 TEXT()->cursor.x_fix(TEXT()->cursor.x());
956 TEXT()->cursorDown(owner->view());
959 TEXT()->cursorRight(owner->view());
961 moveCursorUpdate(true, false);
963 goto exit_with_message;
965 #warning I am not sure this is still right, please have a look! (Jug 20020417)
966 else { // result == UNDISPATCHED
967 //setMessage(N_("Text mode"));
969 case LFUN_UNKNOWN_ACTION:
970 case LFUN_BREAKPARAGRAPH:
972 TEXT()->cursorRight(owner->view());
973 owner->view()->setState();
977 if (!TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params)) {
978 TEXT()->cursorRight(owner->view());
979 moveCursorUpdate(true, false);
982 goto exit_with_message;
984 if (TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params)) {
985 TEXT()->cursorRight(owner->view());
986 moveCursorUpdate(true, false);
989 goto exit_with_message;
991 if (TEXT()->cursor.row()->next())
992 TEXT()->cursorDown(owner->view());
994 TEXT()->cursorRight(owner->view());
995 moveCursorUpdate(true, false);
997 goto exit_with_message;
1009 if (!owner->view()->available()) break;
1010 // this function should be used always [asierra060396]
1011 UpdatableInset * tli =
1012 owner->view()->theLockingInset();
1014 UpdatableInset * lock = tli->getLockingInset();
1017 owner->view()->unlockInset(tli);
1018 TEXT()->cursorRight(owner->view());
1019 moveCursorUpdate(true, false);
1022 tli->unlockInsetInInset(owner->view(),
1027 // Tell the paragraph dialog that we changed paragraph
1028 owner->getDialogs()->updateParagraph();
1033 // --- Misc -------------------------------------------
1034 case LFUN_WORDFINDFORWARD :
1035 case LFUN_WORDFINDBACKWARD : {
1036 static string last_search;
1037 string searched_string;
1039 if (!argument.empty()) {
1040 last_search = argument;
1041 searched_string = argument;
1043 searched_string = last_search;
1045 bool fw = (action == LFUN_WORDFINDBACKWARD);
1046 if (!searched_string.empty()) {
1047 LyXFind(owner->view(), searched_string, fw);
1049 // owner->view()->showCursor();
1055 if (owner->view()->available() && !owner->view()->theLockingInset()) {
1056 owner->view()->update(TEXT(),
1057 BufferView::SELECT|BufferView::FITCUR);
1059 owner->message(keyseq.printOptions());
1063 // --- Misc -------------------------------------------
1064 case LFUN_EXEC_COMMAND:
1066 vector<string> allCmds;
1067 transform(lyxaction.func_begin(), lyxaction.func_end(),
1068 back_inserter(allCmds), lyx::firster());
1069 static vector<string> hist;
1070 owner->getMiniBuffer()->getString(MiniBuffer::spaces,
1075 case LFUN_CANCEL: // RVDK_PATCH_5
1077 meta_fake_bit = key_modifier::none;
1078 if (owner->view()->available())
1079 // cancel any selection
1080 dispatch(LFUN_MARK_OFF);
1081 setMessage(N_("Cancel"));
1084 case LFUN_META_FAKE: // RVDK_PATCH_5
1086 meta_fake_bit = key_modifier::alt;
1087 setMessage(keyseq.print());
1091 case LFUN_READ_ONLY_TOGGLE:
1092 if (owner->buffer()->lyxvc.inUse()) {
1093 owner->buffer()->lyxvc.toggleReadOnly();
1095 owner->buffer()->setReadonly(
1096 !owner->buffer()->isReadonly());
1100 case LFUN_CENTER: // this is center and redraw.
1101 owner->view()->center();
1104 // --- Menus -----------------------------------------------
1109 case LFUN_MENUNEWTMPLT:
1113 case LFUN_CLOSEBUFFER:
1117 case LFUN_MENUWRITE:
1118 if (!owner->buffer()->isUnnamed()) {
1120 s1 << _("Saving document") << ' '
1121 << MakeDisplayPath(owner->buffer()->fileName() + "...");
1122 owner->message(s1.str().c_str());
1123 MenuWrite(owner->view(), owner->buffer());
1125 WriteAs(owner->view(), owner->buffer());
1129 WriteAs(owner->view(), owner->buffer(), argument);
1132 case LFUN_MENURELOAD:
1137 Exporter::Export(owner->buffer(), argument, true);
1141 Exporter::Preview(owner->buffer(), argument);
1144 case LFUN_BUILDPROG:
1145 Exporter::Export(owner->buffer(), "program", true);
1148 case LFUN_RUNCHKTEX:
1149 MenuRunChktex(owner->buffer());
1152 case LFUN_MENUPRINT:
1153 owner->getDialogs()->showPrint();
1157 if (argument == "custom")
1158 owner->getDialogs()->showSendto();
1160 Exporter::Export(owner->buffer(), argument, false);
1178 InsetCommandParams p;
1181 if (action == LFUN_TOCVIEW)
1183 p.setCmdName("tableofcontents");
1185 else if (action == LFUN_LOAVIEW)
1186 p.setCmdName("listof{algorithm}{List of Algorithms}");
1187 else if (action == LFUN_LOFVIEW)
1188 p.setCmdName("listoffigures");
1190 p.setCmdName("listoftables");
1192 owner->getDialogs()->createTOC(p.getAsString());
1196 case LFUN_DIALOG_TABULAR_INSERT:
1197 owner->getDialogs()->showTabularCreate();
1201 AutoSave(owner->view());
1205 owner->view()->menuUndo();
1209 owner->view()->menuRedo();
1212 case LFUN_MENUSEARCH:
1213 owner->getDialogs()->showSearch();
1216 case LFUN_REMOVEERRORS:
1217 if (owner->view()->removeAutoInsets()) {
1218 owner->view()->redraw();
1219 owner->view()->fitCursor();
1223 case LFUN_DEPTH_MIN:
1224 changeDepth(owner->view(), TEXT(false), -1);
1227 case LFUN_DEPTH_PLUS:
1228 changeDepth(owner->view(), TEXT(false), 1);
1232 owner->getDialogs()->setUserFreeFont();
1235 case LFUN_RECONFIGURE:
1236 Reconfigure(owner->view());
1240 case LFUN_FLOATSOPERATE:
1241 if (argument == "openfoot")
1242 owner->view()->allFloats(1,0);
1243 else if (argument == "closefoot")
1244 owner->view()->allFloats(0,0);
1245 else if (argument == "openfig")
1246 owner->view()->allFloats(1,1);
1247 else if (argument == "closefig")
1248 owner->view()->allFloats(0,1);
1251 #ifdef WITH_WARNINGS
1252 //#warning Find another implementation here (or another lyxfunc)!
1255 case LFUN_HELP_ABOUTLYX:
1256 owner->getDialogs()->showAboutlyx();
1259 case LFUN_HELP_TEXINFO:
1260 owner->getDialogs()->showTexinfo();
1263 case LFUN_HELP_OPEN:
1265 string const arg = argument;
1267 setErrorMessage(N_("Missing argument"));
1270 owner->prohibitInput();
1271 string const fname = i18nLibFileSearch("doc", arg, "lyx");
1272 if (fname.empty()) {
1273 lyxerr << "LyX: unable to find documentation file `"
1274 << arg << "'. Bad installation?" << endl;
1275 owner->allowInput();
1279 str << _("Opening help file") << ' '
1280 << MakeDisplayPath(fname) << "...";
1281 owner->message(str.str().c_str());
1282 owner->view()->buffer(bufferlist.loadLyXFile(fname, false));
1283 owner->allowInput();
1287 // --- version control -------------------------------
1288 case LFUN_VC_REGISTER:
1290 if (!owner->buffer()->lyxvc.inUse())
1291 owner->buffer()->lyxvc.registrer();
1295 case LFUN_VC_CHECKIN:
1297 if (owner->buffer()->lyxvc.inUse()
1298 && !owner->buffer()->isReadonly())
1299 owner->buffer()->lyxvc.checkIn();
1303 case LFUN_VC_CHECKOUT:
1305 if (owner->buffer()->lyxvc.inUse()
1306 && owner->buffer()->isReadonly())
1307 owner->buffer()->lyxvc.checkOut();
1311 case LFUN_VC_REVERT:
1313 owner->buffer()->lyxvc.revert();
1319 owner->buffer()->lyxvc.undoLast();
1323 case LFUN_VC_HISTORY:
1325 owner->getDialogs()->showVCLogFile();
1329 // --- buffers ----------------------------------------
1331 case LFUN_SWITCHBUFFER:
1332 owner->view()->buffer(bufferlist.getBuffer(argument));
1337 // servercmd: argument must be <file>:<template>
1338 Buffer * tmpbuf = NewLyxFile(argument);
1340 owner->view()->buffer(tmpbuf);
1344 case LFUN_FILE_OPEN:
1348 case LFUN_LATEX_LOG:
1349 owner->getDialogs()->showLogFile();
1352 case LFUN_LAYOUT_DOCUMENT:
1353 owner->getDialogs()->showDocument();
1356 case LFUN_LAYOUT_PARAGRAPH:
1357 owner->getDialogs()->showParagraph();
1360 case LFUN_LAYOUT_CHARACTER:
1361 owner->getDialogs()->showCharacter();
1364 case LFUN_LAYOUT_TABULAR:
1365 if (owner->view()->theLockingInset()) {
1366 if (owner->view()->theLockingInset()->lyxCode()==Inset::TABULAR_CODE) {
1367 InsetTabular * inset = static_cast<InsetTabular *>
1368 (owner->view()->theLockingInset());
1369 inset->openLayoutDialog(owner->view());
1370 } else if (owner->view()->theLockingInset()->
1371 getFirstLockingInsetOfType(Inset::TABULAR_CODE)!=0) {
1372 InsetTabular * inset = static_cast<InsetTabular *>(
1373 owner->view()->theLockingInset()->getFirstLockingInsetOfType(Inset::TABULAR_CODE));
1374 inset->openLayoutDialog(owner->view());
1379 case LFUN_LAYOUT_PREAMBLE:
1380 owner->getDialogs()->showPreamble();
1383 case LFUN_DROP_LAYOUTS_CHOICE:
1384 owner->getToolbar()->openLayoutList();
1387 case LFUN_MENU_OPEN_BY_NAME:
1388 owner->getMenubar()->openByName(argument);
1389 break; // RVDK_PATCH_5
1391 case LFUN_SPELLCHECK:
1392 if (lyxrc.isp_command != "none")
1393 owner->getDialogs()->showSpellchecker();
1396 // --- lyxserver commands ----------------------------
1400 setMessage(owner->buffer()->fileName());
1401 lyxerr[Debug::INFO] << "FNAME["
1402 << owner->buffer()->fileName()
1408 dispatch_buffer = keyseq.print();
1409 lyxserver->notifyClient(dispatch_buffer);
1413 case LFUN_GOTOFILEROW:
1417 istringstream istr(argument.c_str());
1418 istr >> file_name >> row;
1419 // Must replace extension of the file to be .lyx and get full path
1420 string const s(ChangeExtension(file_name, ".lyx"));
1422 // Either change buffer or load the file
1423 if (bufferlist.exists(s)) {
1424 owner->view()->buffer(bufferlist.getBuffer(s));
1426 owner->view()->buffer(bufferlist.loadLyXFile(s));
1430 owner->view()->setCursorFromRow(row);
1433 owner->view()->center();
1437 case LFUN_GOTO_PARAGRAPH:
1439 istringstream istr(argument.c_str());
1443 Paragraph * par = owner->buffer()->getParFromID(id);
1445 lyxerr[Debug::INFO] << "No matching paragraph found! ["
1446 << id << "]" << endl;
1449 lyxerr[Debug::INFO] << "Paragraph " << par->id()
1450 << " found." << endl;
1453 if (owner->view()->theLockingInset())
1454 owner->view()->unlockInset(owner->view()->theLockingInset());
1455 if (par->inInset()) {
1456 par->inInset()->edit(owner->view());
1459 owner->view()->getLyXText()->setCursor(owner->view(), par, 0);
1460 owner->view()->setState();
1464 owner->view()->center();
1471 int const qa = lyxaction.LookupFunc(argument);
1472 setMessage(lyxaction.helpText(static_cast<kb_action>(qa)));
1476 // --- toolbar ----------------------------------
1477 case LFUN_PUSH_TOOLBAR:
1479 int nth = strToInt(argument);
1481 setErrorMessage(N_("Push-toolbar needs argument > 0"));
1483 owner->getToolbar()->push(nth);
1488 case LFUN_ADD_TO_TOOLBAR:
1490 if (lyxerr.debugging(Debug::GUI)) {
1491 lyxerr << "LFUN_ADD_TO_TOOLBAR:"
1492 "argument = `" << argument << '\'' << endl;
1494 string tmp(argument);
1495 //lyxerr <<string("Argument: ") + argument);
1496 //lyxerr <<string("Tmp : ") + tmp);
1498 setErrorMessage(N_("Usage: toolbar-add-to <LyX command>"));
1500 owner->getToolbar()->add(argument, false);
1501 owner->getToolbar()->set();
1506 // --- insert characters ----------------------------------------
1508 // --- Mathed stuff. If we are here, there is no locked inset yet.
1509 case LFUN_MATH_EXTERN:
1510 case LFUN_MATH_NUMBER:
1511 case LFUN_MATH_NONUMBER:
1512 case LFUN_MATH_LIMITS:
1514 setErrorMessage(N_("This is only allowed in math mode!"));
1518 // passthrough hat and underscore outside mathed:
1519 case LFUN_SUBSCRIPT:
1520 dispatch(LFUN_SELFINSERT, "_");
1522 case LFUN_SUPERSCRIPT:
1523 dispatch(LFUN_SELFINSERT, "^");
1526 case LFUN_MATH_PANEL:
1527 owner->getDialogs()->showMathPanel();
1530 case LFUN_CITATION_CREATE:
1532 InsetCommandParams p("cite");
1534 if (!argument.empty()) {
1535 // This should be set at source, ie when typing
1536 // "citation-insert foo" in the minibuffer.
1537 // Question: would pybibliographer also need to be
1538 // changed. Suspect so. Leave as-is therefore.
1539 if (contains(argument, "|")) {
1540 p.setContents(token(argument, '|', 0));
1541 p.setOptions( token(argument, '|', 1));
1543 p.setContents(argument);
1545 dispatch(LFUN_CITATION_INSERT, p.getAsString());
1547 owner->getDialogs()->createCitation(p.getAsString());
1551 case LFUN_CHILDOPEN:
1553 string const filename =
1554 MakeAbsPath(argument,
1555 owner->buffer()->filePath());
1556 setMessage(N_("Opening child document ") +
1557 MakeDisplayPath(filename) + "...");
1558 owner->view()->savePosition(0);
1559 if (bufferlist.exists(filename))
1560 owner->view()->buffer(bufferlist.getBuffer(filename));
1562 owner->view()->buffer(bufferlist.loadLyXFile(filename));
1566 case LFUN_TOGGLECURSORFOLLOW:
1567 lyxrc.cursor_follows_scrollbar = !lyxrc.cursor_follows_scrollbar;
1570 case LFUN_KMAP_OFF: // keymap off
1571 owner->getIntl()->KeyMapOn(false);
1574 case LFUN_KMAP_PRIM: // primary keymap
1575 owner->getIntl()->KeyMapPrim();
1578 case LFUN_KMAP_SEC: // secondary keymap
1579 owner->getIntl()->KeyMapSec();
1582 case LFUN_KMAP_TOGGLE: // toggle keymap
1583 owner->getIntl()->ToggleKeyMap();
1588 // argument contains ';'-terminated commands
1589 while (argument.find(';') != string::npos) {
1591 argument = split(argument, first, ';');
1592 verboseDispatch(first, false);
1597 case LFUN_DIALOG_PREFERENCES:
1598 owner->getDialogs()->showPreferences();
1601 case LFUN_SAVEPREFERENCES:
1603 Path p(user_lyxdir);
1604 lyxrc.write("preferences");
1608 case LFUN_SCREEN_FONT_UPDATE:
1610 // handle the screen font changes.
1612 lyxrc.set_font_norm_type();
1613 fontloader.update();
1614 // Of course we should only do the resize and the textcache.clear
1615 // if values really changed...but not very important right now. (Lgb)
1616 // All visible buffers will need resize
1617 owner->view()->resize();
1618 // We also need to empty the textcache so that
1619 // the buffer will be formatted correctly after
1625 case LFUN_SET_COLOR:
1628 string const x11_name = split(argument, lyx_name, ' ');
1629 if (lyx_name.empty() || x11_name.empty()) {
1630 setErrorMessage(N_("Syntax: set-color <lyx_name>"
1635 bool const graphicsbg_changed =
1636 (lyx_name == lcolor.getLyXName(LColor::graphicsbg) &&
1637 x11_name != lcolor.getX11Name(LColor::graphicsbg));
1639 if (!lcolor.setColor(lyx_name, x11_name)) {
1640 static string const err1 (N_("Set-color \""));
1641 static string const err2 (
1642 N_("\" failed - color is undefined "
1643 "or may not be redefined"));
1644 setErrorMessage(_(err1) + lyx_name + _(err2));
1648 lyxColorHandler->updateColor(lcolor.getFromLyXName(lyx_name));
1650 if (graphicsbg_changed) {
1651 grfx::GCache & gc = grfx::GCache::get();
1652 gc.changeDisplay(true);
1655 owner->view()->redraw();
1660 owner->message(argument);
1663 case LFUN_MESSAGE_PUSH:
1664 owner->messagePush(argument);
1667 case LFUN_MESSAGE_POP:
1668 owner->messagePop();
1671 case LFUN_FORKS_SHOW:
1672 owner->getDialogs()->showForks();
1675 case LFUN_FORKS_KILL:
1677 if (!isStrInt(argument))
1680 pid_t const pid = strToInt(argument);
1681 ForkedcallsController & fcc = ForkedcallsController::get();
1686 case LFUN_TOOLTIPS_TOGGLE:
1687 owner->getDialogs()->toggleTooltips();
1691 // Then if it was none of the above
1692 // Trying the BufferView::pimpl dispatch:
1693 if (!owner->view()->Dispatch(action, argument))
1694 lyxerr << "A truly unknown func ["
1695 << lyxaction.getActionName(action) << "]!"
1702 string const res = getMessage();
1705 owner->message(_(res));
1706 owner->updateMenubar();
1707 owner->updateToolbar();
1713 void LyXFunc::setupLocalKeymap()
1715 keyseq.stdmap = keyseq.curmap = toplevel_keymap.get();
1716 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap.get();
1720 void LyXFunc::menuNew(bool fromTemplate)
1722 string initpath = lyxrc.document_path;
1724 if (owner->view()->available()) {
1725 string const trypath = owner->buffer()->filePath();
1726 // If directory is writeable, use this as default.
1727 if (IsDirWriteable(trypath))
1731 static int newfile_number;
1734 if (lyxrc.new_ask_filename) {
1735 FileDialog fileDlg(owner, _("Enter filename for new document"),
1736 LFUN_SELECT_FILE_SYNC,
1737 make_pair(string(_("Documents|#o#O")),
1738 string(lyxrc.document_path)),
1739 make_pair(string(_("Templates|#T#t")),
1740 string(lyxrc.template_path)));
1742 FileDialog::Result result =
1743 fileDlg.Select(initpath,
1744 _("*.lyx|LyX Documents (*.lyx)"),
1747 if (result.second.empty()) {
1748 owner->message(_("Canceled."));
1749 lyxerr[Debug::INFO] << "New Document Cancelled." << endl;
1753 // get absolute path of file and make sure the filename ends
1755 s = MakeAbsPath(result.second);
1756 if (!IsLyXFilename(s))
1759 // Check if the document already is open
1760 if (bufferlist.exists(s)) {
1761 switch (Alert::askConfirmation(_("Document is already open:"),
1762 MakeDisplayPath(s, 50),
1763 _("Do you want to close that document now?\n"
1764 "('No' will just switch to the open version)")))
1766 case 1: // Yes: close the document
1767 if (!bufferlist.close(bufferlist.getBuffer(s)))
1768 // If close is canceled, we cancel here too.
1771 case 2: // No: switch to the open document
1772 owner->view()->buffer(bufferlist.getBuffer(s));
1774 case 3: // Cancel: Do nothing
1775 owner->message(_("Canceled."));
1779 // Check whether the file already exists
1781 if (fi.readable() &&
1782 Alert::askQuestion(_("File already exists:"),
1783 MakeDisplayPath(s, 50),
1784 _("Do you want to open the document?"))) {
1786 string const disp_fn(MakeDisplayPath(s));
1789 str << _("Opening document") << ' '
1790 << disp_fn << "...";
1792 owner->message(str.str().c_str());
1793 //XFlush(fl_get_display());
1794 owner->view()->buffer(bufferlist.loadLyXFile(s));
1796 str2 << _("Document") << ' '
1797 << disp_fn << ' ' << _("opened.");
1799 owner->message(str2.str().c_str());
1804 s = AddName(lyxrc.document_path,
1805 "newfile" + tostr(++newfile_number) + ".lyx");
1807 while (bufferlist.exists(s) || fi.readable()) {
1809 s = AddName(lyxrc.document_path,
1810 "newfile" + tostr(newfile_number) +
1816 // The template stuff
1819 FileDialog fileDlg(owner, _("Select template file"),
1820 LFUN_SELECT_FILE_SYNC,
1821 make_pair(string(_("Documents|#o#O")),
1822 string(lyxrc.document_path)),
1823 make_pair(string(_("Templates|#T#t")),
1824 string(lyxrc.template_path)));
1826 FileDialog::Result result =
1827 fileDlg.Select(lyxrc.template_path,
1828 _("*.lyx|LyX Documents (*.lyx)"));
1830 if (result.first == FileDialog::Later)
1833 string const fname = result.second;
1840 // find a free buffer
1841 lyxerr[Debug::INFO] << "Find a free buffer." << endl;
1842 owner->view()->buffer(bufferlist.newFile(s, templname));
1846 void LyXFunc::open(string const & fname)
1848 string initpath = lyxrc.document_path;
1850 if (owner->view()->available()) {
1851 string const trypath = owner->buffer()->filePath();
1852 // If directory is writeable, use this as default.
1853 if (IsDirWriteable(trypath))
1859 if (fname.empty()) {
1860 FileDialog fileDlg(owner, _("Select document to open"),
1862 make_pair(string(_("Documents|#o#O")),
1863 string(lyxrc.document_path)),
1864 make_pair(string(_("Examples|#E#e")),
1865 string(AddPath(system_lyxdir, "examples"))));
1867 FileDialog::Result result =
1868 fileDlg.Select(initpath,
1869 "*.lyx|LyX Documents (*.lyx)");
1871 if (result.first == FileDialog::Later)
1874 filename = result.second;
1876 // check selected filename
1877 if (filename.empty()) {
1878 owner->message(_("Canceled."));
1884 // get absolute path of file and add ".lyx" to the filename if
1886 string const fullpath = FileSearch(string(), filename, "lyx");
1887 if (fullpath.empty()) {
1888 Alert::alert(_("Error"), _("Could not find file"), filename);
1892 filename = fullpath;
1895 string const disp_fn(MakeDisplayPath(filename));
1898 str << _("Opening document") << ' ' << disp_fn << "...";
1900 owner->message(str.str().c_str());
1902 Buffer * openbuf = bufferlist.loadLyXFile(filename);
1904 owner->view()->buffer(openbuf);
1906 str << _("Document") << ' ' << disp_fn << ' ' << _("opened.");
1907 owner->message(str.str().c_str());
1910 str << _("Could not open document") << ' ' << disp_fn;
1911 owner->message(str.str().c_str());
1916 void LyXFunc::doImport(string const & argument)
1919 string filename = split(argument, format, ' ');
1921 lyxerr[Debug::INFO] << "LyXFunc::doImport: " << format
1922 << " file: " << filename << endl;
1924 // need user interaction
1925 if (filename.empty()) {
1926 string initpath = lyxrc.document_path;
1928 if (owner->view()->available()) {
1929 string const trypath = owner->buffer()->filePath();
1930 // If directory is writeable, use this as default.
1931 if (IsDirWriteable(trypath))
1935 string const text = _("Select ") + formats.prettyName(format)
1936 + _(" file to import");
1938 FileDialog fileDlg(owner, text,
1940 make_pair(string(_("Documents|#o#O")),
1941 string(lyxrc.document_path)),
1942 make_pair(string(_("Examples|#E#e")),
1943 string(AddPath(system_lyxdir, "examples"))));
1945 string const extension = "*." + formats.extension(format)
1946 + "| " + formats.prettyName(format)
1947 + " (*." + formats.extension(format) + ")";
1949 FileDialog::Result result = fileDlg.Select(initpath,
1952 if (result.first == FileDialog::Later)
1955 filename = result.second;
1957 // check selected filename
1958 if (filename.empty())
1959 owner->message(_("Canceled."));
1962 if (filename.empty())
1965 // get absolute path of file
1966 filename = MakeAbsPath(filename);
1968 string const lyxfile = ChangeExtension(filename, ".lyx");
1970 // Check if the document already is open
1971 if (lyxrc.use_gui && bufferlist.exists(lyxfile)) {
1972 switch (Alert::askConfirmation(_("Document is already open:"),
1973 MakeDisplayPath(lyxfile, 50),
1974 _("Do you want to close that document now?\n"
1975 "('No' will just switch to the open version)")))
1978 // If close is canceled, we cancel here too.
1979 if (!bufferlist.close(bufferlist.getBuffer(lyxfile)))
1983 owner->view()->buffer(bufferlist.getBuffer(lyxfile));
1986 owner->message(_("Canceled."));
1991 // if the file exists already, and we didn't do
1992 // -i lyx thefile.lyx, warn
1993 if (FileInfo(lyxfile, true).exist() && filename != lyxfile) {
1994 if (!Alert::askQuestion(_("A document by the name"),
1995 MakeDisplayPath(lyxfile), _("already exists. Overwrite?"))) {
1996 owner->message(_("Canceled"));
2001 Importer::Import(owner, filename, format);
2005 void LyXFunc::reloadBuffer()
2007 string const fn = owner->buffer()->fileName();
2008 if (bufferlist.close(owner->buffer()))
2009 owner->view()->buffer(bufferlist.loadLyXFile(fn));
2013 void LyXFunc::closeBuffer()
2015 if (bufferlist.close(owner->buffer()) && !quitting) {
2016 if (bufferlist.empty()) {
2017 // need this otherwise SEGV may occur while trying to
2018 // set variables that don't exist
2019 // since there's no current buffer
2020 owner->getDialogs()->hideBufferDependent();
2022 owner->view()->buffer(bufferlist.first());
2028 // Each "owner" should have it's own message method. lyxview and
2029 // the minibuffer would use the minibuffer, but lyxserver would
2030 // send an ERROR signal to its client. Alejandro 970603
2031 // This func is bit problematic when it comes to NLS, to make the
2032 // lyx servers client be language indepenent we must not translate
2033 // strings sent to this func.
2034 void LyXFunc::setErrorMessage(string const & m) const
2036 dispatch_buffer = m;
2041 void LyXFunc::setMessage(string const & m) const
2043 dispatch_buffer = m;
2047 void LyXFunc::setStatusMessage(string const & m) const
2053 void LyXFunc::initMiniBuffer()
2055 string text = _("Welcome to LyX!");
2057 // When meta-fake key is pressed, show the key sequence so far + "M-".
2059 text = keyseq.print();
2063 // Else, when a non-complete key sequence is pressed,
2064 // show the available options.
2065 if (keyseq.length() > 0 && !keyseq.deleted()) {
2066 text = keyseq.printOptions();
2069 // Else, show the buffer state.
2070 else if (owner->view()->available()) {
2071 Buffer * tmpbuf = owner->buffer();
2073 string const nicename =
2074 MakeDisplayPath(tmpbuf->fileName());
2075 // Should we do this instead? (kindo like emacs)
2076 // leaves more room for other information
2079 if (tmpbuf->lyxvc.inUse()) {
2081 text += tmpbuf->lyxvc.versionString();
2083 text += tmpbuf->lyxvc.locker();
2084 if (tmpbuf->isReadonly())
2087 } else if (tmpbuf->isReadonly())
2089 if (!tmpbuf->isLyxClean())
2090 text += _(" (Changed)");
2092 if (text != _("Welcome to LyX!")) // this is a hack
2093 text = _("* No document open *");
2096 owner->message(text);