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 "ColorHandler.h"
24 #include "lyxserver.h"
28 #include "LyXAction.h"
34 #include "trans_mgr.h"
36 #include "bufferview_funcs.h"
37 #include "minibuffer.h"
40 #include "FloatList.h"
41 #include "converter.h"
44 #include "FontLoader.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())
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, unsigned int state)
229 if (lyxerr.debugging(Debug::KEY)) {
230 char const * tmp = XKeysymToString(keysym);
231 string const stm = (tmp ? tmp : "");
232 lyxerr << "KeySym is "
235 << keysym << "] State is ["
239 // Do nothing if we have nothing (JMarc)
240 if (keysym == NoSymbol) {
241 lyxerr[Debug::KEY] << "Empty kbd action (probably composing)"
246 // Can we be sure that this will work for all X Window
247 // implementations? (Lgb)
248 // This code snippet makes lyx ignore some keys. Perhaps
249 // all of them should be explictly mentioned?
250 if ((keysym >= XK_Shift_L && keysym <= XK_Hyper_R)
251 || keysym == XK_Mode_switch || keysym == 0x0) {
255 // Do a one-deep top-level lookup for
256 // cancel and meta-fake keys. RVDK_PATCH_5
257 cancel_meta_seq.reset();
259 int action = cancel_meta_seq.addkey(keysym, state
260 &(ShiftMask|ControlMask
262 if (lyxerr.debugging(Debug::KEY)) {
263 lyxerr << "action first set to [" << action << "]" << endl;
266 // When not cancel or meta-fake, do the normal lookup.
267 // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
268 // Mostly, meta_fake_bit = 0. RVDK_PATCH_5.
269 if ((action != LFUN_CANCEL) && (action != LFUN_META_FAKE)) {
270 if (lyxerr.debugging(Debug::KEY)) {
271 lyxerr << "meta_fake_bit is ["
272 << meta_fake_bit << "]" << endl;
274 // remove Caps Lock and Mod2 as a modifiers
275 action = keyseq.addkey(keysym,
276 (state | meta_fake_bit)
277 &(ShiftMask|ControlMask
279 if (lyxerr.debugging(Debug::KEY)) {
280 lyxerr << "action now set to ["
281 << action << "]" << endl;
284 // Dont remove this unless you know what you are doing.
287 // can this happen now ?
288 if (action == LFUN_NOACTION) {
289 action = LFUN_PREFIX;
292 if (lyxerr.debugging(Debug::KEY)) {
293 lyxerr << "Key [action="
295 << keyseq.print() << "]"
299 // already here we know if it any point in going further
300 // why not return already here if action == -1 and
301 // num_bytes == 0? (Lgb)
303 if (keyseq.length() > 1) {
304 owner->message(keyseq.print());
307 if (action == LFUN_UNKNOWN_ACTION) {
308 // It is unknown, but what if we remove all
309 // the modifiers? (Lgb)
310 action = keyseq.addkey(keysym, 0);
312 if (lyxerr.debugging(Debug::KEY)) {
313 lyxerr << "Removing modifiers...\n"
314 << "Action now set to ["
315 << action << "]" << endl;
317 if (action == LFUN_UNKNOWN_ACTION) {
318 owner->message(_("Unknown function."));
323 if (action == LFUN_SELFINSERT) {
324 // This is very X dependent.
325 unsigned int c = keysym;
328 c = kb_keymap::getiso(c);
331 argument = static_cast<char>(c);
333 dispatch(LFUN_SELFINSERT, argument);
334 lyxerr[Debug::KEY] << "SelfInsert arg[`"
335 << argument << "']" << endl;
338 verboseDispatch(action, false);
342 FuncStatus LyXFunc::getStatus(int ac) const
346 action = lyxaction.retrieveActionArg(ac, argument);
347 return getStatus(action, argument);
351 FuncStatus LyXFunc::getStatus(kb_action action,
352 string const & argument) const
355 Buffer * buf = owner->buffer();
357 if (action == LFUN_NOACTION) {
358 setStatusMessage(N_("Nothing to do"));
359 return flag.disabled(true);
362 if (action == LFUN_UNKNOWN_ACTION) {
363 setStatusMessage(N_("Unknown action"));
364 return flag.unknown(true);
367 // the default error message if we disable the command
368 setStatusMessage(N_("Command disabled"));
370 // Check whether we need a buffer
371 if (!lyxaction.funcHasFlag(action, LyXAction::NoBuffer)) {
372 // Yes we need a buffer, do we have one?
375 // Can we use a readonly buffer?
376 if (buf->isReadonly() &&
377 !lyxaction.funcHasFlag(action,
378 LyXAction::ReadOnly)) {
380 setStatusMessage(N_("Document is read-only"));
385 setStatusMessage(N_("Command not allowed with"
386 "out any document open"));
387 return flag.disabled(true);
391 UpdatableInset * tli = owner->view()->theLockingInset();
393 // I would really like to avoid having this switch and rather try to
394 // encode this in the function itself.
395 bool disable = false;
398 disable = !Exporter::IsExportable(buf, "dvi")
399 || lyxrc.print_command == "none";
402 disable = argument == "fax" &&
403 !Exporter::IsExportable(buf, argument);
406 disable = buf->undostack.empty();
409 disable = buf->redostack.empty();
411 case LFUN_SPELLCHECK:
412 disable = lyxrc.isp_command == "none";
414 #ifndef HAVE_LIBAIKSAURUS
415 case LFUN_THESAURUS_ENTRY:
420 disable = lyxrc.chktex_command == "none";
423 disable = !Exporter::IsExportable(buf, "program");
426 case LFUN_LAYOUT_TABULAR:
428 || (tli->lyxCode() != Inset::TABULAR_CODE
429 && !tli->getFirstLockingInsetOfType(Inset::TABULAR_CODE));
433 case LFUN_LAYOUT_PARAGRAPH: {
434 Inset * inset = TEXT(false)->cursor.par()->inInset();
435 disable = inset && inset->forceDefaultParagraphs(inset);
439 case LFUN_TABULAR_FEATURE:
443 //ret.disabled(true);
444 if (tli->lyxCode() == Inset::TABULAR_CODE) {
445 ret = static_cast<InsetTabular *>(tli)
446 ->getStatus(argument);
447 } else if (tli->getFirstLockingInsetOfType(Inset::TABULAR_CODE)) {
448 ret = static_cast<InsetTabular *>
449 (tli->getFirstLockingInsetOfType(Inset::TABULAR_CODE))
450 ->getStatus(argument);
455 static InsetTabular inset(*owner->buffer(), 1, 1);
459 ret = inset.getStatus(argument);
460 if (ret.onoff(true) || ret.onoff(false))
461 flag.setOnOff(false);
465 case LFUN_VC_REGISTER:
466 disable = buf->lyxvc.inUse();
468 case LFUN_VC_CHECKIN:
469 disable = !buf->lyxvc.inUse() || buf->isReadonly();
471 case LFUN_VC_CHECKOUT:
472 disable = !buf->lyxvc.inUse() || !buf->isReadonly();
476 case LFUN_VC_HISTORY:
477 disable = !buf->lyxvc.inUse();
479 case LFUN_BOOKMARK_GOTO:
480 disable = !owner->view()->
481 isSavedPosition(strToUnsignedInt(argument));
485 case LFUN_INSET_TOGGLE: {
486 LyXText * lt = owner->view()->getLyXText();
487 disable = !(isEditableInset(lt->getInset())
489 && lt->inset_owner->owner()
490 && lt->inset_owner->owner()->isOpen()));
493 case LFUN_MATH_VALIGN:
495 char align = mathcursor->valign();
500 if (argument.empty()) {
504 if (!contains("tcb", argument[0])) {
508 flag.setOnOff(argument[0] == align);
513 case LFUN_MATH_HALIGN:
515 char align = mathcursor->halign();
520 if (argument.empty()) {
524 if (!contains("lcr", argument[0])) {
528 flag.setOnOff(argument[0] == align);
533 case LFUN_MATH_MUTATE:
534 if (tli && (tli->lyxCode() == Inset::MATH_CODE)) {
535 MathInsetTypes type = mathcursor->formula()->getType();
536 if (argument == "inline") {
537 flag.setOnOff(type == LM_OT_SIMPLE);
538 } else if (argument == "display") {
539 flag.setOnOff(type == LM_OT_EQUATION);
540 } else if (argument == "eqnarray") {
541 flag.setOnOff(type == LM_OT_EQNARRAY);
542 } else if (argument == "align") {
543 flag.setOnOff(type == LM_OT_ALIGN);
551 // we just need to be in math mode to enable that
553 case LFUN_MATH_SPACE:
554 case LFUN_MATH_LIMITS:
555 case LFUN_MATH_NONUMBER:
556 case LFUN_MATH_NUMBER:
557 disable = !mathcursor;
560 // we need to be math mode and a math array for that
561 // Hack: halign produces non-zero result iff we are in a math array
562 case LFUN_MATH_ROW_INSERT:
563 case LFUN_MATH_ROW_DELETE:
564 case LFUN_MATH_COLUMN_INSERT:
565 case LFUN_MATH_COLUMN_DELETE:
566 disable = !mathcursor || !mathcursor->halign();
573 // the functions which insert insets
574 Inset::Code code = Inset::NO_CODE;
577 code = Inset::ERT_CODE;
579 case LFUN_INSET_GRAPHICS:
580 code = Inset::GRAPHICS_CODE;
582 case LFUN_INSET_FOOTNOTE:
583 code = Inset::FOOT_CODE;
585 case LFUN_DIALOG_TABULAR_INSERT:
586 case LFUN_INSET_TABULAR:
587 code = Inset::TABULAR_CODE;
589 case LFUN_INSET_EXTERNAL:
590 code = Inset::EXTERNAL_CODE;
592 case LFUN_INSET_MARGINAL:
593 code = Inset::MARGIN_CODE;
595 case LFUN_INSET_MINIPAGE:
596 code = Inset::MINIPAGE_CODE;
598 case LFUN_INSET_FLOAT:
599 case LFUN_INSET_WIDE_FLOAT:
600 code = Inset::FLOAT_CODE;
602 case LFUN_FLOAT_LIST:
603 code = Inset::FLOAT_LIST_CODE;
606 case LFUN_INSET_LIST:
607 code = Inset::LIST_CODE;
609 case LFUN_INSET_THEOREM:
610 code = Inset::THEOREM_CODE;
613 case LFUN_INSET_CAPTION:
614 code = Inset::CAPTION_CODE;
616 case LFUN_INSERT_NOTE:
617 code = Inset::IGNORE_CODE;
619 case LFUN_INSERT_LABEL:
620 code = Inset::LABEL_CODE;
622 case LFUN_REF_INSERT:
623 code = Inset::REF_CODE;
625 case LFUN_CITATION_CREATE:
626 case LFUN_CITATION_INSERT:
627 code = Inset::CITE_CODE;
629 case LFUN_INSERT_BIBTEX:
630 code = Inset::BIBTEX_CODE;
632 case LFUN_INDEX_INSERT:
633 case LFUN_INDEX_INSERT_LAST:
634 case LFUN_INDEX_CREATE:
635 code = Inset::INDEX_CODE;
637 case LFUN_INDEX_PRINT:
638 code = Inset::INDEX_PRINT_CODE;
640 case LFUN_CHILD_INSERT:
641 code = Inset::INCLUDE_CODE;
643 case LFUN_TOC_INSERT:
644 code = Inset::TOC_CODE;
646 case LFUN_PARENTINSERT:
647 code = Inset::PARENT_CODE;
651 case LFUN_INSERT_URL:
652 code = Inset::URL_CODE;
655 // always allow this, since we will inset a raw quote
656 // if an inset is not allowed.
658 case LFUN_HYPHENATION:
659 case LFUN_LIGATURE_BREAK:
661 case LFUN_MENU_SEPARATOR:
663 case LFUN_END_OF_SENTENCE:
664 case LFUN_PROTECTEDSPACE:
665 code = Inset::SPECIALCHAR_CODE;
670 if (code != Inset::NO_CODE && tli && !tli->insetAllowed(code)) {
677 // A few general toggles
679 case LFUN_TOOLTIPS_TOGGLE:
680 flag.setOnOff(owner->getDialogs()->tooltipsEnabled());
683 case LFUN_READ_ONLY_TOGGLE:
684 flag.setOnOff(buf->isReadonly());
687 flag.setOnOff(TEXT(false)->cursor.par()->params().startOfAppendix());
689 case LFUN_SWITCHBUFFER:
690 // toggle on the current buffer, but do not toggle off
691 // the other ones (is that a good idea?)
692 if (argument == buf->fileName())
699 // the font related toggles
701 LyXFont const & font = TEXT(false)->real_current_font;
704 flag.setOnOff(font.emph() == LyXFont::ON);
707 flag.setOnOff(font.noun() == LyXFont::ON);
710 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
713 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
716 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
719 flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
726 MathTextCodes tc = mathcursor->getLastCode();
729 flag.setOnOff(tc == LM_TC_BF);
732 flag.setOnOff(tc == LM_TC_SF);
735 flag.setOnOff(tc == LM_TC_CAL);
738 flag.setOnOff(tc == LM_TC_RM);
741 flag.setOnOff(tc == LM_TC_TT);
744 flag.setOnOff(tc == LM_TC_BB);
747 flag.setOnOff(tc == LM_TC_VAR);
758 // temporary dispatch method
759 void LyXFunc::miniDispatch(string const & s)
761 string s2(frontStrip(strip(s)));
764 verboseDispatch(s2, true);
769 void LyXFunc::verboseDispatch(string const & s, bool show_sc)
771 int action = lyxaction.LookupFunc(frontStrip(s));
773 if (action == LFUN_UNKNOWN_ACTION) {
774 string const msg = string(_("Unknown function ("))
778 verboseDispatch(action, show_sc);
783 void LyXFunc::verboseDispatch(int ac, bool show_sc)
788 // get the real action and argument
789 action = lyxaction.retrieveActionArg(ac, argument);
791 verboseDispatch(action, argument, show_sc);
796 void LyXFunc::verboseDispatch(kb_action action,
797 string const & argument, bool show_sc)
799 string res = dispatch(action, argument);
801 commandshortcut.erase();
803 if (lyxrc.display_shortcuts && show_sc) {
804 if (action != LFUN_SELFINSERT) {
805 // Put name of command and list of shortcuts
806 // for it in minibuffer
807 string comname = lyxaction.getActionName(action);
809 int pseudoaction = action;
810 bool argsadded = false;
812 if (!argument.empty()) {
813 // the pseudoaction is useful for the bindings
815 lyxaction.searchActionArg(action,
818 if (pseudoaction == LFUN_UNKNOWN_ACTION) {
819 pseudoaction = action;
821 comname += " " + argument;
826 string const shortcuts =
827 toplevel_keymap->findbinding(pseudoaction);
829 if (!shortcuts.empty()) {
830 comname += ": " + shortcuts;
831 } else if (!argsadded && !argument.empty()) {
832 comname += " " + argument;
835 if (!comname.empty()) {
836 comname = strip(comname);
837 commandshortcut = "(" + comname + ')';
843 if (!commandshortcut.empty()) {
844 owner->getMiniBuffer()->addSet(commandshortcut);
847 owner->getMiniBuffer()->addSet(' ' + commandshortcut);
852 string const LyXFunc::dispatch(kb_action action, string argument)
854 lyxerr[Debug::ACTION] << "LyXFunc::Dispatch: action[" << action
855 <<"] arg[" << argument << "]" << endl;
857 // we have not done anything wrong yet.
859 dispatch_buffer.erase();
861 #ifdef NEW_DISPATCHER
862 // We try do call the most specific dispatcher first:
863 // 1. the lockinginset's dispatch
864 // 2. the bufferview's dispatch
865 // 3. the lyxview's dispatch
868 selection_possible = false;
870 if (owner->view()->available())
871 owner->view()->hideCursor();
873 // We cannot use this function here
874 if (getStatus(action, argument).disabled()) {
875 lyxerr[Debug::ACTION] << "LyXFunc::Dispatch: "
876 << lyxaction.getActionName(action)
877 << " [" << action << "] is disabled at this location"
879 setErrorMessage(getStatusMessage());
880 goto exit_with_message;
883 if (owner->view()->available() && owner->view()->theLockingInset()) {
884 UpdatableInset::RESULT result;
885 if ((action > 1) || ((action == LFUN_UNKNOWN_ACTION) &&
886 (!keyseq.deleted())))
888 UpdatableInset * inset = owner->view()->theLockingInset();
892 inset->getCursorPos(owner->view(), inset_x, dummy_y);
894 if ((action == LFUN_UNKNOWN_ACTION)
895 && argument.empty()) {
896 argument = keyseq.getiso();
898 // Undo/Redo is a bit tricky for insets.
899 if (action == LFUN_UNDO) {
900 owner->view()->menuUndo();
901 goto exit_with_message;
902 } else if (action == LFUN_REDO) {
903 owner->view()->menuRedo();
904 goto exit_with_message;
905 } else if (((result=inset->
906 // Hand-over to inset's own dispatch:
907 localDispatch(owner->view(), action, argument)) ==
908 UpdatableInset::DISPATCHED) ||
909 (result == UpdatableInset::DISPATCHED_NOUPDATE))
910 goto exit_with_message;
911 // If UNDISPATCHED, just soldier on
912 else if (result == UpdatableInset::FINISHED) {
913 if (TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params)) {
914 TEXT()->cursorRight(owner->view());
915 moveCursorUpdate(true, false);
918 goto exit_with_message;
919 } else if (result == UpdatableInset::FINISHED_RIGHT) {
920 if (!TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params)) {
921 TEXT()->cursorRight(owner->view());
922 moveCursorUpdate(true, false);
925 goto exit_with_message;
926 } else if (result == UpdatableInset::FINISHED_UP) {
927 if (TEXT()->cursor.irow()->previous()) {
929 TEXT()->setCursorFromCoordinates(
930 owner->view(), TEXT()->cursor.ix() + inset_x,
931 TEXT()->cursor.iy() -
932 TEXT()->cursor.irow()->baseline() - 1);
933 TEXT()->cursor.x_fix(TEXT()->cursor.x());
935 TEXT()->cursorUp(owner->view());
937 moveCursorUpdate(true, false);
940 owner->view()->update(TEXT(), BufferView::SELECT|BufferView::FITCUR);
942 goto exit_with_message;
943 } else if (result == UpdatableInset::FINISHED_DOWN) {
944 if (TEXT()->cursor.irow()->next()) {
946 TEXT()->setCursorFromCoordinates(
947 owner->view(), TEXT()->cursor.ix() + inset_x,
948 TEXT()->cursor.iy() -
949 TEXT()->cursor.irow()->baseline() +
950 TEXT()->cursor.irow()->height() + 1);
951 TEXT()->cursor.x_fix(TEXT()->cursor.x());
953 TEXT()->cursorDown(owner->view());
956 TEXT()->cursorRight(owner->view());
958 moveCursorUpdate(true, false);
960 goto exit_with_message;
962 #warning I am not sure this is still right, please have a look! (Jug 20020417)
963 else { // result == UNDISPATCHED
964 //setMessage(N_("Text mode"));
966 case LFUN_UNKNOWN_ACTION:
967 case LFUN_BREAKPARAGRAPH:
969 TEXT()->cursorRight(owner->view());
970 owner->view()->setState();
974 if (!TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params)) {
975 TEXT()->cursorRight(owner->view());
976 moveCursorUpdate(true, false);
979 goto exit_with_message;
981 if (TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params)) {
982 TEXT()->cursorRight(owner->view());
983 moveCursorUpdate(true, false);
986 goto exit_with_message;
988 if (TEXT()->cursor.row()->next())
989 TEXT()->cursorDown(owner->view());
991 TEXT()->cursorRight(owner->view());
992 moveCursorUpdate(true, false);
994 goto exit_with_message;
1006 if (!owner->view()->available()) break;
1007 // this function should be used always [asierra060396]
1008 UpdatableInset * tli =
1009 owner->view()->theLockingInset();
1011 UpdatableInset * lock = tli->getLockingInset();
1014 owner->view()->unlockInset(tli);
1015 TEXT()->cursorRight(owner->view());
1016 moveCursorUpdate(true, false);
1019 tli->unlockInsetInInset(owner->view(),
1024 // Tell the paragraph dialog that we changed paragraph
1025 owner->getDialogs()->updateParagraph();
1030 // --- Misc -------------------------------------------
1031 case LFUN_WORDFINDFORWARD :
1032 case LFUN_WORDFINDBACKWARD : {
1033 static string last_search;
1034 string searched_string;
1036 if (!argument.empty()) {
1037 last_search = argument;
1038 searched_string = argument;
1040 searched_string = last_search;
1042 bool fw = (action == LFUN_WORDFINDBACKWARD);
1043 if (!searched_string.empty()) {
1044 LyXFind(owner->view(), searched_string, fw);
1046 // owner->view()->showCursor();
1052 if (owner->view()->available() && !owner->view()->theLockingInset()) {
1053 owner->view()->update(TEXT(),
1054 BufferView::SELECT|BufferView::FITCUR);
1056 owner->message(keyseq.printOptions());
1060 // --- Misc -------------------------------------------
1061 case LFUN_EXEC_COMMAND:
1063 vector<string> allCmds;
1064 transform(lyxaction.func_begin(), lyxaction.func_end(),
1065 back_inserter(allCmds), lyx::firster());
1066 static vector<string> hist;
1067 owner->getMiniBuffer()->getString(MiniBuffer::spaces,
1072 case LFUN_CANCEL: // RVDK_PATCH_5
1075 if (owner->view()->available())
1076 // cancel any selection
1077 dispatch(LFUN_MARK_OFF);
1078 setMessage(N_("Cancel"));
1081 case LFUN_META_FAKE: // RVDK_PATCH_5
1083 meta_fake_bit = Mod1Mask;
1084 setMessage(keyseq.print());
1088 case LFUN_READ_ONLY_TOGGLE:
1089 if (owner->buffer()->lyxvc.inUse()) {
1090 owner->buffer()->lyxvc.toggleReadOnly();
1092 owner->buffer()->setReadonly(
1093 !owner->buffer()->isReadonly());
1097 case LFUN_CENTER: // this is center and redraw.
1098 owner->view()->center();
1101 // --- Menus -----------------------------------------------
1106 case LFUN_MENUNEWTMPLT:
1110 case LFUN_CLOSEBUFFER:
1114 case LFUN_MENUWRITE:
1115 if (!owner->buffer()->isUnnamed()) {
1117 s1 << _("Saving document") << ' '
1118 << MakeDisplayPath(owner->buffer()->fileName() + "...");
1119 owner->message(s1.str().c_str());
1120 MenuWrite(owner->view(), owner->buffer());
1122 WriteAs(owner->view(), owner->buffer());
1126 WriteAs(owner->view(), owner->buffer(), argument);
1129 case LFUN_MENURELOAD:
1134 Exporter::Export(owner->buffer(), argument, true);
1138 Exporter::Preview(owner->buffer(), argument);
1141 case LFUN_BUILDPROG:
1142 Exporter::Export(owner->buffer(), "program", true);
1145 case LFUN_RUNCHKTEX:
1146 MenuRunChktex(owner->buffer());
1149 case LFUN_MENUPRINT:
1150 owner->getDialogs()->showPrint();
1154 if (argument == "custom")
1155 owner->getDialogs()->showSendto();
1157 Exporter::Export(owner->buffer(), argument, false);
1175 InsetCommandParams p;
1178 if (action == LFUN_TOCVIEW)
1180 p.setCmdName("tableofcontents");
1182 else if (action == LFUN_LOAVIEW)
1183 p.setCmdName("listof{algorithm}{List of Algorithms}");
1184 else if (action == LFUN_LOFVIEW)
1185 p.setCmdName("listoffigures");
1187 p.setCmdName("listoftables");
1189 owner->getDialogs()->createTOC(p.getAsString());
1193 case LFUN_DIALOG_TABULAR_INSERT:
1194 owner->getDialogs()->showTabularCreate();
1198 AutoSave(owner->view());
1202 owner->view()->menuUndo();
1206 owner->view()->menuRedo();
1209 case LFUN_MENUSEARCH:
1210 owner->getDialogs()->showSearch();
1213 case LFUN_REMOVEERRORS:
1214 if (owner->view()->removeAutoInsets()) {
1215 owner->view()->redraw();
1216 owner->view()->fitCursor();
1220 case LFUN_DEPTH_MIN:
1221 changeDepth(owner->view(), TEXT(false), -1);
1224 case LFUN_DEPTH_PLUS:
1225 changeDepth(owner->view(), TEXT(false), 1);
1229 owner->getDialogs()->setUserFreeFont();
1232 case LFUN_RECONFIGURE:
1233 Reconfigure(owner->view());
1237 case LFUN_FLOATSOPERATE:
1238 if (argument == "openfoot")
1239 owner->view()->allFloats(1,0);
1240 else if (argument == "closefoot")
1241 owner->view()->allFloats(0,0);
1242 else if (argument == "openfig")
1243 owner->view()->allFloats(1,1);
1244 else if (argument == "closefig")
1245 owner->view()->allFloats(0,1);
1248 #ifdef WITH_WARNINGS
1249 //#warning Find another implementation here (or another lyxfunc)!
1252 case LFUN_HELP_ABOUTLYX:
1253 owner->getDialogs()->showAboutlyx();
1256 case LFUN_HELP_TEXINFO:
1257 owner->getDialogs()->showTexinfo();
1260 case LFUN_HELP_OPEN:
1262 string const arg = argument;
1264 setErrorMessage(N_("Missing argument"));
1267 owner->prohibitInput();
1268 string const fname = i18nLibFileSearch("doc", arg, "lyx");
1269 if (fname.empty()) {
1270 lyxerr << "LyX: unable to find documentation file `"
1271 << arg << "'. Bad installation?" << endl;
1272 owner->allowInput();
1276 str << _("Opening help file") << ' '
1277 << MakeDisplayPath(fname) << "...";
1278 owner->message(str.str().c_str());
1279 owner->view()->buffer(bufferlist.loadLyXFile(fname, false));
1280 owner->allowInput();
1284 // --- version control -------------------------------
1285 case LFUN_VC_REGISTER:
1287 if (!owner->buffer()->lyxvc.inUse())
1288 owner->buffer()->lyxvc.registrer();
1292 case LFUN_VC_CHECKIN:
1294 if (owner->buffer()->lyxvc.inUse()
1295 && !owner->buffer()->isReadonly())
1296 owner->buffer()->lyxvc.checkIn();
1300 case LFUN_VC_CHECKOUT:
1302 if (owner->buffer()->lyxvc.inUse()
1303 && owner->buffer()->isReadonly())
1304 owner->buffer()->lyxvc.checkOut();
1308 case LFUN_VC_REVERT:
1310 owner->buffer()->lyxvc.revert();
1316 owner->buffer()->lyxvc.undoLast();
1320 case LFUN_VC_HISTORY:
1322 owner->getDialogs()->showVCLogFile();
1326 // --- buffers ----------------------------------------
1328 case LFUN_SWITCHBUFFER:
1329 owner->view()->buffer(bufferlist.getBuffer(argument));
1334 // servercmd: argument must be <file>:<template>
1335 Buffer * tmpbuf = NewLyxFile(argument);
1337 owner->view()->buffer(tmpbuf);
1341 case LFUN_FILE_OPEN:
1345 case LFUN_LATEX_LOG:
1346 owner->getDialogs()->showLogFile();
1349 case LFUN_LAYOUT_DOCUMENT:
1350 owner->getDialogs()->showDocument();
1353 case LFUN_LAYOUT_PARAGRAPH:
1354 owner->getDialogs()->showParagraph();
1357 case LFUN_LAYOUT_CHARACTER:
1358 owner->getDialogs()->showCharacter();
1361 case LFUN_LAYOUT_TABULAR:
1362 if (owner->view()->theLockingInset()) {
1363 if (owner->view()->theLockingInset()->lyxCode()==Inset::TABULAR_CODE) {
1364 InsetTabular * inset = static_cast<InsetTabular *>
1365 (owner->view()->theLockingInset());
1366 inset->openLayoutDialog(owner->view());
1367 } else if (owner->view()->theLockingInset()->
1368 getFirstLockingInsetOfType(Inset::TABULAR_CODE)!=0) {
1369 InsetTabular * inset = static_cast<InsetTabular *>(
1370 owner->view()->theLockingInset()->getFirstLockingInsetOfType(Inset::TABULAR_CODE));
1371 inset->openLayoutDialog(owner->view());
1376 case LFUN_LAYOUT_PREAMBLE:
1377 owner->getDialogs()->showPreamble();
1380 case LFUN_DROP_LAYOUTS_CHOICE:
1381 owner->getToolbar()->openLayoutList();
1384 case LFUN_MENU_OPEN_BY_NAME:
1385 owner->getMenubar()->openByName(argument);
1386 break; // RVDK_PATCH_5
1388 case LFUN_SPELLCHECK:
1389 if (lyxrc.isp_command != "none")
1390 owner->getDialogs()->showSpellchecker();
1393 // --- lyxserver commands ----------------------------
1397 setMessage(owner->buffer()->fileName());
1398 lyxerr[Debug::INFO] << "FNAME["
1399 << owner->buffer()->fileName()
1405 dispatch_buffer = keyseq.print();
1406 lyxserver->notifyClient(dispatch_buffer);
1410 case LFUN_GOTOFILEROW:
1414 istringstream istr(argument.c_str());
1415 istr >> file_name >> row;
1416 // Must replace extension of the file to be .lyx and get full path
1417 string const s(ChangeExtension(file_name, ".lyx"));
1419 // Either change buffer or load the file
1420 if (bufferlist.exists(s)) {
1421 owner->view()->buffer(bufferlist.getBuffer(s));
1423 owner->view()->buffer(bufferlist.loadLyXFile(s));
1427 owner->view()->setCursorFromRow(row);
1430 owner->view()->center();
1434 case LFUN_GOTO_PARAGRAPH:
1436 istringstream istr(argument.c_str());
1440 Paragraph * par = owner->buffer()->getParFromID(id);
1442 lyxerr[Debug::INFO] << "No matching paragraph found! ["
1443 << id << "]" << endl;
1446 lyxerr[Debug::INFO] << "Paragraph " << par->id()
1447 << " found." << endl;
1450 if (owner->view()->theLockingInset())
1451 owner->view()->unlockInset(owner->view()->theLockingInset());
1452 if (par->inInset()) {
1453 par->inInset()->edit(owner->view());
1456 owner->view()->getLyXText()->setCursor(owner->view(), par, 0);
1457 owner->view()->setState();
1461 owner->view()->center();
1468 int const qa = lyxaction.LookupFunc(argument);
1469 setMessage(lyxaction.helpText(static_cast<kb_action>(qa)));
1473 // --- toolbar ----------------------------------
1474 case LFUN_PUSH_TOOLBAR:
1476 int nth = strToInt(argument);
1478 setErrorMessage(N_("Push-toolbar needs argument > 0"));
1480 owner->getToolbar()->push(nth);
1485 case LFUN_ADD_TO_TOOLBAR:
1487 if (lyxerr.debugging(Debug::GUI)) {
1488 lyxerr << "LFUN_ADD_TO_TOOLBAR:"
1489 "argument = `" << argument << '\'' << endl;
1491 string tmp(argument);
1492 //lyxerr <<string("Argument: ") + argument);
1493 //lyxerr <<string("Tmp : ") + tmp);
1495 setErrorMessage(N_("Usage: toolbar-add-to <LyX command>"));
1497 owner->getToolbar()->add(argument, false);
1498 owner->getToolbar()->set();
1503 // --- insert characters ----------------------------------------
1505 // --- Mathed stuff. If we are here, there is no locked inset yet.
1506 case LFUN_MATH_EXTERN:
1507 case LFUN_MATH_NUMBER:
1508 case LFUN_MATH_NONUMBER:
1509 case LFUN_MATH_LIMITS:
1511 setErrorMessage(N_("This is only allowed in math mode!"));
1515 // passthrough hat and underscore outside mathed:
1516 case LFUN_SUBSCRIPT:
1517 dispatch(LFUN_SELFINSERT, "_");
1519 case LFUN_SUPERSCRIPT:
1520 dispatch(LFUN_SELFINSERT, "^");
1523 case LFUN_MATH_PANEL:
1524 owner->getDialogs()->showMathPanel();
1527 case LFUN_CITATION_CREATE:
1529 InsetCommandParams p("cite");
1531 if (!argument.empty()) {
1532 // This should be set at source, ie when typing
1533 // "citation-insert foo" in the minibuffer.
1534 // Question: would pybibliographer also need to be
1535 // changed. Suspect so. Leave as-is therefore.
1536 if (contains(argument, "|")) {
1537 p.setContents(token(argument, '|', 0));
1538 p.setOptions( token(argument, '|', 1));
1540 p.setContents(argument);
1542 dispatch(LFUN_CITATION_INSERT, p.getAsString());
1544 owner->getDialogs()->createCitation(p.getAsString());
1548 case LFUN_CHILDOPEN:
1550 string const filename =
1551 MakeAbsPath(argument,
1552 owner->buffer()->filePath());
1553 setMessage(N_("Opening child document ") +
1554 MakeDisplayPath(filename) + "...");
1555 owner->view()->savePosition(0);
1556 if (bufferlist.exists(filename))
1557 owner->view()->buffer(bufferlist.getBuffer(filename));
1559 owner->view()->buffer(bufferlist.loadLyXFile(filename));
1563 case LFUN_TOGGLECURSORFOLLOW:
1564 lyxrc.cursor_follows_scrollbar = !lyxrc.cursor_follows_scrollbar;
1567 case LFUN_KMAP_OFF: // keymap off
1568 owner->getIntl()->KeyMapOn(false);
1571 case LFUN_KMAP_PRIM: // primary keymap
1572 owner->getIntl()->KeyMapPrim();
1575 case LFUN_KMAP_SEC: // secondary keymap
1576 owner->getIntl()->KeyMapSec();
1579 case LFUN_KMAP_TOGGLE: // toggle keymap
1580 owner->getIntl()->ToggleKeyMap();
1585 // argument contains ';'-terminated commands
1586 while (argument.find(';') != string::npos) {
1588 argument = split(argument, first, ';');
1589 verboseDispatch(first, false);
1594 case LFUN_DIALOG_PREFERENCES:
1595 owner->getDialogs()->showPreferences();
1598 case LFUN_SAVEPREFERENCES:
1600 Path p(user_lyxdir);
1601 lyxrc.write("preferences");
1605 case LFUN_SCREEN_FONT_UPDATE:
1607 // handle the screen font changes.
1609 lyxrc.set_font_norm_type();
1610 fontloader.update();
1611 // Of course we should only do the resize and the textcache.clear
1612 // if values really changed...but not very important right now. (Lgb)
1613 // All visible buffers will need resize
1615 // We also need to empty the textcache so that
1616 // the buffer will be formatted correctly after
1622 case LFUN_SET_COLOR:
1625 string const x11_name = split(argument, lyx_name, ' ');
1626 if (lyx_name.empty() || x11_name.empty()) {
1627 setErrorMessage(N_("Syntax: set-color <lyx_name>"
1632 bool const graphicsbg_changed =
1633 (lyx_name == lcolor.getLyXName(LColor::graphicsbg) &&
1634 x11_name != lcolor.getX11Name(LColor::graphicsbg));
1636 if (!lcolor.setColor(lyx_name, x11_name)) {
1637 static string const err1 (N_("Set-color \""));
1638 static string const err2 (
1639 N_("\" failed - color is undefined "
1640 "or may not be redefined"));
1641 setErrorMessage(_(err1) + lyx_name + _(err2));
1645 lyxColorHandler->updateColor(lcolor.getFromLyXName(lyx_name));
1647 if (graphicsbg_changed) {
1648 grfx::GCache & gc = grfx::GCache::get();
1649 gc.changeDisplay(true);
1652 owner->view()->redraw();
1657 owner->message(argument);
1660 case LFUN_MESSAGE_PUSH:
1661 owner->messagePush(argument);
1664 case LFUN_MESSAGE_POP:
1665 owner->messagePop();
1668 case LFUN_FORKS_SHOW:
1669 owner->getDialogs()->showForks();
1672 case LFUN_FORKS_KILL:
1674 if (!isStrInt(argument))
1677 pid_t const pid = strToInt(argument);
1678 ForkedcallsController & fcc = ForkedcallsController::get();
1683 case LFUN_TOOLTIPS_TOGGLE:
1684 owner->getDialogs()->toggleTooltips();
1688 // Then if it was none of the above
1689 // Trying the BufferView::pimpl dispatch:
1690 if (!owner->view()->Dispatch(action, argument))
1691 lyxerr << "A truly unknown func ["
1692 << lyxaction.getActionName(action) << "]!"
1699 string const res = getMessage();
1702 owner->message(_(res));
1703 owner->updateMenubar();
1704 owner->updateToolbar();
1710 void LyXFunc::setupLocalKeymap()
1712 keyseq.stdmap = keyseq.curmap = toplevel_keymap.get();
1713 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap.get();
1717 void LyXFunc::menuNew(bool fromTemplate)
1719 string initpath = lyxrc.document_path;
1721 if (owner->view()->available()) {
1722 string const trypath = owner->buffer()->filePath();
1723 // If directory is writeable, use this as default.
1724 if (IsDirWriteable(trypath))
1728 static int newfile_number;
1731 if (lyxrc.new_ask_filename) {
1732 FileDialog fileDlg(owner, _("Enter filename for new document"),
1733 LFUN_SELECT_FILE_SYNC,
1734 make_pair(string(_("Documents|#o#O")),
1735 string(lyxrc.document_path)),
1736 make_pair(string(_("Templates|#T#t")),
1737 string(lyxrc.template_path)));
1739 FileDialog::Result result =
1740 fileDlg.Select(initpath,
1741 _("*.lyx|LyX Documents (*.lyx)"),
1744 if (result.second.empty()) {
1745 owner->message(_("Canceled."));
1746 lyxerr[Debug::INFO] << "New Document Cancelled." << endl;
1750 // get absolute path of file and make sure the filename ends
1752 s = MakeAbsPath(result.second);
1753 if (!IsLyXFilename(s))
1756 // Check if the document already is open
1757 if (bufferlist.exists(s)) {
1758 switch (Alert::askConfirmation(_("Document is already open:"),
1759 MakeDisplayPath(s, 50),
1760 _("Do you want to close that document now?\n"
1761 "('No' will just switch to the open version)")))
1763 case 1: // Yes: close the document
1764 if (!bufferlist.close(bufferlist.getBuffer(s)))
1765 // If close is canceled, we cancel here too.
1768 case 2: // No: switch to the open document
1769 owner->view()->buffer(bufferlist.getBuffer(s));
1771 case 3: // Cancel: Do nothing
1772 owner->message(_("Canceled."));
1776 // Check whether the file already exists
1778 if (fi.readable() &&
1779 Alert::askQuestion(_("File already exists:"),
1780 MakeDisplayPath(s, 50),
1781 _("Do you want to open the document?"))) {
1783 string const disp_fn(MakeDisplayPath(s));
1786 str << _("Opening document") << ' '
1787 << disp_fn << "...";
1789 owner->message(str.str().c_str());
1790 //XFlush(fl_get_display());
1791 owner->view()->buffer(bufferlist.loadLyXFile(s));
1793 str2 << _("Document") << ' '
1794 << disp_fn << ' ' << _("opened.");
1796 owner->message(str2.str().c_str());
1801 s = AddName(lyxrc.document_path,
1802 "newfile" + tostr(++newfile_number) + ".lyx");
1804 while (bufferlist.exists(s) || fi.readable()) {
1806 s = AddName(lyxrc.document_path,
1807 "newfile" + tostr(newfile_number) +
1813 // The template stuff
1816 FileDialog fileDlg(owner, _("Select template file"),
1817 LFUN_SELECT_FILE_SYNC,
1818 make_pair(string(_("Documents|#o#O")),
1819 string(lyxrc.document_path)),
1820 make_pair(string(_("Templates|#T#t")),
1821 string(lyxrc.template_path)));
1823 FileDialog::Result result =
1824 fileDlg.Select(lyxrc.template_path,
1825 _("*.lyx|LyX Documents (*.lyx)"));
1827 if (result.first == FileDialog::Later)
1830 string const fname = result.second;
1837 // find a free buffer
1838 lyxerr[Debug::INFO] << "Find a free buffer." << endl;
1839 owner->view()->buffer(bufferlist.newFile(s, templname));
1843 void LyXFunc::open(string const & fname)
1845 string initpath = lyxrc.document_path;
1847 if (owner->view()->available()) {
1848 string const trypath = owner->buffer()->filePath();
1849 // If directory is writeable, use this as default.
1850 if (IsDirWriteable(trypath))
1856 if (fname.empty()) {
1857 FileDialog fileDlg(owner, _("Select document to open"),
1859 make_pair(string(_("Documents|#o#O")),
1860 string(lyxrc.document_path)),
1861 make_pair(string(_("Examples|#E#e")),
1862 string(AddPath(system_lyxdir, "examples"))));
1864 FileDialog::Result result =
1865 fileDlg.Select(initpath,
1866 "*.lyx|LyX Documents (*.lyx)");
1868 if (result.first == FileDialog::Later)
1871 filename = result.second;
1873 // check selected filename
1874 if (filename.empty()) {
1875 owner->message(_("Canceled."));
1881 // get absolute path of file and add ".lyx" to the filename if
1883 string const fullpath = FileSearch(string(), filename, "lyx");
1884 if (fullpath.empty()) {
1885 Alert::alert(_("Error"), _("Could not find file"), filename);
1889 filename = fullpath;
1892 string const disp_fn(MakeDisplayPath(filename));
1895 str << _("Opening document") << ' ' << disp_fn << "...";
1897 owner->message(str.str().c_str());
1899 Buffer * openbuf = bufferlist.loadLyXFile(filename);
1901 owner->view()->buffer(openbuf);
1903 str << _("Document") << ' ' << disp_fn << ' ' << _("opened.");
1904 owner->message(str.str().c_str());
1907 str << _("Could not open document") << ' ' << disp_fn;
1908 owner->message(str.str().c_str());
1913 // checks for running without gui are missing.
1914 void LyXFunc::doImport(string const & argument)
1917 string filename = split(argument, format, ' ');
1918 lyxerr[Debug::INFO] << "LyXFunc::doImport: " << format
1919 << " file: " << filename << endl;
1921 if (filename.empty()) { // need user interaction
1922 string initpath = lyxrc.document_path;
1924 if (owner->view()->available()) {
1925 string const trypath = owner->buffer()->filePath();
1926 // If directory is writeable, use this as default.
1927 if (IsDirWriteable(trypath))
1931 string const text = _("Select ") + formats.prettyName(format)
1932 + _(" file to import");
1934 FileDialog fileDlg(owner, text,
1936 make_pair(string(_("Documents|#o#O")),
1937 string(lyxrc.document_path)),
1938 make_pair(string(_("Examples|#E#e")),
1939 string(AddPath(system_lyxdir, "examples"))));
1941 string const extension = "*." + formats.extension(format)
1942 + "| " + formats.prettyName(format)
1943 + " (*." + formats.extension(format) + ")";
1945 FileDialog::Result result = fileDlg.Select(initpath,
1948 if (result.first == FileDialog::Later)
1951 filename = result.second;
1953 // check selected filename
1954 if (filename.empty())
1955 owner->message(_("Canceled."));
1958 // still no filename? abort
1959 if (filename.empty())
1962 // get absolute path of file
1963 filename = MakeAbsPath(filename);
1965 string const lyxfile = ChangeExtension(filename, ".lyx");
1967 // Check if the document already is open
1968 if (bufferlist.exists(lyxfile)) {
1969 switch (Alert::askConfirmation(_("Document is already open:"),
1970 MakeDisplayPath(lyxfile, 50),
1971 _("Do you want to close that document now?\n"
1972 "('No' will just switch to the open version)")))
1974 case 1: // Yes: close the document
1975 if (!bufferlist.close(bufferlist.getBuffer(lyxfile)))
1976 // If close is canceled, we cancel here too.
1979 case 2: // No: switch to the open document
1980 owner->view()->buffer(bufferlist.getBuffer(lyxfile));
1982 case 3: // Cancel: Do nothing
1983 owner->message(_("Canceled."));
1988 // Check if a LyX document by the same root exists in filesystem
1989 FileInfo const f(lyxfile, true);
1990 if (f.exist() && !Alert::askQuestion(_("A document by the name"),
1991 MakeDisplayPath(lyxfile),
1992 _("already exists. Overwrite?"))) {
1993 owner->message(_("Canceled"));
1996 // filename should be valid now
1998 Importer::Import(owner, filename, format);
2002 void LyXFunc::reloadBuffer()
2004 string const fn = owner->buffer()->fileName();
2005 if (bufferlist.close(owner->buffer()))
2006 owner->view()->buffer(bufferlist.loadLyXFile(fn));
2010 void LyXFunc::closeBuffer()
2012 if (bufferlist.close(owner->buffer()) && !quitting) {
2013 if (bufferlist.empty()) {
2014 // need this otherwise SEGV may occur while trying to
2015 // set variables that don't exist
2016 // since there's no current buffer
2017 owner->getDialogs()->hideBufferDependent();
2019 owner->view()->buffer(bufferlist.first());
2025 // Each "owner" should have it's own message method. lyxview and
2026 // the minibuffer would use the minibuffer, but lyxserver would
2027 // send an ERROR signal to its client. Alejandro 970603
2028 // This func is bit problematic when it comes to NLS, to make the
2029 // lyx servers client be language indepenent we must not translate
2030 // strings sent to this func.
2031 void LyXFunc::setErrorMessage(string const & m) const
2033 dispatch_buffer = m;
2038 void LyXFunc::setMessage(string const & m) const
2040 dispatch_buffer = m;
2044 void LyXFunc::setStatusMessage(string const & m) const
2050 void LyXFunc::initMiniBuffer()
2052 string text = _("Welcome to LyX!");
2054 // When meta-fake key is pressed, show the key sequence so far + "M-".
2056 text = keyseq.print();
2060 // Else, when a non-complete key sequence is pressed,
2061 // show the available options.
2062 if (keyseq.length() > 0 && !keyseq.deleted()) {
2063 text = keyseq.printOptions();
2066 // Else, show the buffer state.
2067 else if (owner->view()->available()) {
2068 Buffer * tmpbuf = owner->buffer();
2070 string const nicename =
2071 MakeDisplayPath(tmpbuf->fileName());
2072 // Should we do this instead? (kindo like emacs)
2073 // leaves more room for other information
2076 if (tmpbuf->lyxvc.inUse()) {
2078 text += tmpbuf->lyxvc.versionString();
2080 text += tmpbuf->lyxvc.locker();
2081 if (tmpbuf->isReadonly())
2084 } else if (tmpbuf->isReadonly())
2086 if (!tmpbuf->isLyxClean())
2087 text += _(" (Changed)");
2089 if (text != _("Welcome to LyX!")) // this is a hack
2090 text = _("* No document open *");
2093 owner->message(text);