1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2001 The LyX Team.
9 * ====================================================== */
25 #pragma implementation
28 #include "support/lyxalgo.h"
32 #include "bufferlist.h"
33 #include "ColorHandler.h"
34 #include "lyxserver.h"
35 #include "figure_form.h"
39 #include "LyXAction.h"
40 #include "insets/inseturl.h"
41 #include "insets/insetlatexaccent.h"
42 #include "insets/insettoc.h"
43 #include "insets/insetref.h"
44 #include "insets/insetparent.h"
45 #include "insets/insetindex.h"
46 #include "insets/insetinclude.h"
47 #include "insets/insetbib.h"
48 #include "insets/insetcite.h"
49 #include "insets/insettext.h"
50 #include "insets/insetert.h"
51 #include "insets/insetexternal.h"
52 #include "insets/insetgraphics.h"
53 #include "insets/insetfoot.h"
54 #include "insets/insetmarginal.h"
55 #include "insets/insetminipage.h"
56 #include "insets/insetfloat.h"
57 #include "insets/insetlist.h"
58 #include "insets/insettabular.h"
59 #include "insets/insettheorem.h"
60 #include "insets/insetcaption.h"
61 #include "mathed/formulamacro.h"
62 #include "spellchecker.h" // RVDK_PATCH_5
63 #include "minibuffer.h"
66 #include "lyx_gui_misc.h"
67 #include "support/filetools.h"
68 #include "support/FileInfo.h"
69 #include "support/syscall.h"
70 #include "support/lstrings.h"
71 #include "support/path.h"
72 #include "support/lyxfunctional.h"
77 #include "trans_mgr.h"
80 #include "bufferview_funcs.h"
81 #include "frontends/FileDialog.h"
82 #include "frontends/Dialogs.h"
83 #include "frontends/Toolbar.h"
84 #include "frontends/Menubar.h"
85 #include "FloatList.h"
86 #include "converter.h"
89 #include "FontLoader.h"
90 #include "TextCache.h"
98 extern BufferList bufferlist;
99 extern LyXServer * lyxserver;
100 extern int greek_kb_flag;
101 extern bool selection_possible;
102 extern void MenuSendto();
104 extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
106 extern void show_symbols_form(LyXFunc *);
108 extern LyXAction lyxaction;
110 extern tex_accent_struct get_accent(kb_action action);
112 extern LyXTextClass::size_type current_layout;
114 extern void ShowLatexLog();
120 class MiniBufferController : public SigC::Object {
123 MiniBufferController() {
127 &MiniBufferController::receiveCommand));
131 &MiniBufferController::receiveArg));
134 void receiveCmd(string const & cmd) {}
136 void receiveArg(string const & arg) {}
144 MiniBufferController mb_ctrl;
150 /* === globals =========================================================== */
152 // Initialization of static member var
153 bool LyXFunc::show_sc = true;
156 LyXFunc::LyXFunc(LyXView * o)
160 lyx_dead_action = LFUN_NOACTION;
161 lyx_calling_dead_action = LFUN_NOACTION;
167 LyXText * LyXFunc::TEXT(bool flag = true) const
170 return owner->view()->text;
171 return owner->view()->getLyXText();
175 // I changed this func slightly. I commented out the ...FinishUndo(),
176 // this means that all places that used to have a moveCursorUpdate, now
177 // have a ...FinishUndo() as the preceeding statement. I have also added
178 // a moveCursorUpdate to some of the functions that updated the cursor, but
179 // that did not show its new position.
181 void LyXFunc::moveCursorUpdate(bool flag, bool selecting)
183 if (selecting || TEXT(flag)->selection.mark()) {
184 TEXT(flag)->SetSelection(owner->view());
185 if (TEXT(flag)->bv_owner)
186 owner->view()->toggleToggle();
188 owner->view()->update(TEXT(flag), BufferView::SELECT|BufferView::FITCUR);
189 owner->view()->showCursor();
191 /* ---> Everytime the cursor is moved, show the current font state. */
192 // should this too me moved out of this func?
193 //owner->showState();
194 owner->view()->setState();
198 void LyXFunc::handleKeyFunc(kb_action action)
200 char c = keyseq.getiso();
202 if (keyseq.length != -1) c = 0;
204 owner->getIntl()->getTrans()
205 .deadkey(c, get_accent(action).accent, TEXT(false));
206 // Need to reset, in case the minibuffer calls these
210 // copied verbatim from do_accent_char
211 owner->view()->update(TEXT(false),
212 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
213 TEXT(false)->selection.cursor = TEXT(false)->cursor;
217 void LyXFunc::processKeySym(KeySym keysym, unsigned int state)
221 if (lyxerr.debugging(Debug::KEY)) {
222 char const * tmp = XKeysymToString(keysym);
223 string const stm = (tmp ? tmp : "");
224 lyxerr << "KeySym is "
227 << keysym << "] State is ["
231 // Do nothing if we have nothing (JMarc)
232 if (keysym == NoSymbol) {
233 lyxerr[Debug::KEY] << "Empty kbd action (probably composing)"
240 // Can we be sure that this will work for all X-Windows
241 // implementations? (Lgb)
242 // This code snippet makes lyx ignore some keys. Perhaps
243 // all of them should be explictly mentioned?
244 if ((keysym >= XK_Shift_L && keysym <= XK_Hyper_R)
245 || keysym == XK_Mode_switch || keysym == 0x0) {
250 // Do a one-deep top-level lookup for
251 // cancel and meta-fake keys. RVDK_PATCH_5
252 cancel_meta_seq.reset();
254 int action = cancel_meta_seq.addkey(keysym, state
255 &(ShiftMask|ControlMask
257 if (lyxerr.debugging(Debug::KEY)) {
258 lyxerr << "action first set to [" << action << "]" << endl;
261 // When not cancel or meta-fake, do the normal lookup.
262 // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
263 // Mostly, meta_fake_bit = 0. RVDK_PATCH_5.
264 if ((action != LFUN_CANCEL) && (action != LFUN_META_FAKE)) {
265 if (lyxerr.debugging(Debug::KEY)) {
266 lyxerr << "meta_fake_bit is ["
267 << meta_fake_bit << "]" << endl;
269 // remove Caps Lock and Mod2 as a modifiers
270 action = keyseq.addkey(keysym,
271 (state | meta_fake_bit)
272 &(ShiftMask|ControlMask
274 if (lyxerr.debugging(Debug::KEY)) {
275 lyxerr << "action now set to ["
276 << action << "]" << endl;
279 // Dont remove this unless you know what you are doing.
282 if (action == 0) action = LFUN_PREFIX;
284 if (lyxerr.debugging(Debug::KEY)) {
287 lyxerr << "Key [action="
293 // already here we know if it any point in going further
294 // why not return already here if action == -1 and
295 // num_bytes == 0? (Lgb)
297 if (keyseq.length > 1 || keyseq.length < -1) {
304 // It is unknown, but what if we remove all
305 // the modifiers? (Lgb)
306 action = keyseq.addkey(keysym, 0);
308 if (lyxerr.debugging(Debug::KEY)) {
309 lyxerr << "Removing modifiers...\n"
310 << "Action now set to ["
311 << action << "]" << endl;
314 owner->message(_("Unknown function."));
320 if (action == LFUN_SELFINSERT) {
321 // This is very X dependant.
322 unsigned int c = keysym;
324 switch (c & 0x0000FF00) {
325 // latin 1 byte 3 = 0
326 case 0x00000000: break;
327 // latin 2 byte 3 = 1
329 // latin 3 byte 3 = 2
331 // latin 4 byte 3 = 3
333 // latin 8 byte 3 = 18 (0x12)
335 // latin 9 byte 3 = 19 (0x13)
344 argument = static_cast<char>(c);
345 lyxerr[Debug::KEY] << "SelfInsert arg[`"
346 << argument << "']" << endl;
349 bool tmp_sc = show_sc;
351 Dispatch(action, argument);
358 LyXFunc::func_status LyXFunc::getStatus(int ac) const
360 return getStatus(ac, string());
364 LyXFunc::func_status LyXFunc::getStatus(int ac,
365 string const & not_to_use_arg) const
368 func_status flag = LyXFunc::OK;
370 Buffer * buf = owner->buffer();
372 if (lyxaction.isPseudoAction(ac))
373 action = lyxaction.retrieveActionArg(ac, argument);
375 action = static_cast<kb_action>(ac);
376 if (!not_to_use_arg.empty())
377 argument = not_to_use_arg; // exept here
380 if (action == LFUN_UNKNOWN_ACTION) {
381 setErrorMessage(N_("Unknown action"));
382 return LyXFunc::Unknown;
385 // Check whether we need a buffer
386 if (!lyxaction.funcHasFlag(action, LyXAction::NoBuffer)) {
387 // Yes we need a buffer, do we have one?
390 // Can we use a readonly buffer?
391 if (buf->isReadonly() &&
392 !lyxaction.funcHasFlag(action,
393 LyXAction::ReadOnly)) {
395 setErrorMessage(N_("Document is read-only"));
396 flag |= LyXFunc::Disabled;
400 setErrorMessage(N_("Command not allowed with"
401 "out any document open"));
402 flag |= LyXFunc::Disabled;
407 // I would really like to avoid having this switch and rather try to
408 // encode this in the function itself.
409 bool disable = false;
412 disable = !Exporter::IsExportable(buf, "dvi")
413 || lyxrc.print_command == "none";
416 disable = argument == "fax" &&
417 !Exporter::IsExportable(buf, argument);
420 disable = buf->undostack.empty();
423 disable = buf->redostack.empty();
425 case LFUN_SPELLCHECK:
426 disable = lyxrc.isp_command == "none";
429 disable = lyxrc.chktex_command == "none";
432 disable = !Exporter::IsExportable(buf, "program");
435 case LFUN_INSERTFOOTNOTE:
436 // Disable insertion of floats in a tabular.
438 if (owner->view()->theLockingInset()) {
439 disable = (owner->view()->theLockingInset()->LyxCode() == Inset::TABULAR_CODE) ||
440 owner->view()->theLockingInset()->GetFirstLockingInsetOfType(Inset::TABULAR_CODE);
444 case LFUN_LAYOUT_TABULAR:
446 if (owner->view()->theLockingInset()) {
447 disable = (owner->view()->theLockingInset()->LyxCode() != Inset::TABULAR_CODE) &&
448 !owner->view()->theLockingInset()->GetFirstLockingInsetOfType(Inset::TABULAR_CODE);
452 case LFUN_TABULAR_FEATURE:
454 if (owner->view()->theLockingInset()) {
455 func_status ret = LyXFunc::Disabled;
456 if (owner->view()->theLockingInset()->LyxCode() == Inset::TABULAR_CODE) {
457 ret = static_cast<InsetTabular *>
458 (owner->view()->theLockingInset())->
460 } else if (owner->view()->theLockingInset()->GetFirstLockingInsetOfType(Inset::TABULAR_CODE)) {
461 ret = static_cast<InsetTabular *>
462 (owner->view()->theLockingInset()->
463 GetFirstLockingInsetOfType(Inset::TABULAR_CODE))->
469 static InsetTabular inset(*owner->buffer(), 1, 1);
473 ret = inset.getStatus(argument);
474 if ((ret & LyXFunc::ToggleOn) ||
475 (ret & LyXFunc::ToggleOff))
476 flag |= LyXFunc::ToggleOff;
480 case LFUN_VC_REGISTER:
481 disable = buf->lyxvc.inUse();
483 case LFUN_VC_CHECKIN:
484 disable = !buf->lyxvc.inUse() || buf->isReadonly();
486 case LFUN_VC_CHECKOUT:
487 disable = !buf->lyxvc.inUse() || !buf->isReadonly();
491 case LFUN_VC_HISTORY:
492 disable = !buf->lyxvc.inUse();
494 case LFUN_BOOKMARK_GOTO:
495 disable = !owner->view()->
496 isSavedPosition(strToUnsignedInt(argument));
501 flag |= LyXFunc::Disabled;
504 func_status box = LyXFunc::ToggleOff;
505 LyXFont const & font =
506 TEXT(false)->real_current_font;
509 if (font.emph() == LyXFont::ON)
510 box = LyXFunc::ToggleOn;
513 if (font.noun() == LyXFont::ON)
514 box = LyXFunc::ToggleOn;
517 if (font.series() == LyXFont::BOLD_SERIES)
518 box = LyXFunc::ToggleOn;
521 if (font.latex() == LyXFont::ON)
522 box = LyXFunc::ToggleOn;
524 case LFUN_READ_ONLY_TOGGLE:
525 if (buf->isReadonly())
526 box = LyXFunc::ToggleOn;
539 // temporary dispatch method
540 void LyXFunc::miniDispatch(string const & s)
546 string const LyXFunc::Dispatch(string const & s)
548 // Split command string into command and argument
550 string line = frontStrip(s);
551 string arg = strip(frontStrip(split(line, cmd, ' ')));
553 return Dispatch(lyxaction.LookupFunc(cmd), arg);
557 string const LyXFunc::Dispatch(int ac,
558 string const & do_not_use_this_arg)
560 lyxerr[Debug::ACTION] << "LyXFunc::Dispatch: action[" << ac
561 <<"] arg[" << do_not_use_this_arg << "]" << endl;
566 // we have not done anything wrong yet.
568 dispatch_buffer.erase();
570 // if action is a pseudo-action, we need the real action
571 if (lyxaction.isPseudoAction(ac)) {
573 action = static_cast<kb_action>
574 (lyxaction.retrieveActionArg(ac, tmparg));
578 action = static_cast<kb_action>(ac);
579 if (!do_not_use_this_arg.empty())
580 argument = do_not_use_this_arg; // except here
583 selection_possible = false;
585 if (owner->view()->available())
586 owner->view()->hideCursor();
588 // We cannot use this function here
589 if (getStatus(ac, do_not_use_this_arg) & Disabled)
590 goto exit_with_message;
592 commandshortcut.erase();
594 if (lyxrc.display_shortcuts && show_sc) {
595 if (action != LFUN_SELFINSERT) {
596 // Put name of command and list of shortcuts
597 // for it in minibuffer
598 string comname = lyxaction.getActionName(action);
600 int pseudoaction = action;
601 bool argsadded = false;
603 if (!argument.empty()) {
604 // If we have the command with argument,
607 lyxaction.searchActionArg(action,
610 if (pseudoaction == -1) {
611 pseudoaction = action;
613 comname += " " + argument;
618 string const shortcuts =
619 toplevel_keymap->findbinding(pseudoaction);
621 if (!shortcuts.empty()) {
622 comname += ": " + shortcuts;
623 } else if (!argsadded) {
624 comname += " " + argument;
627 if (!comname.empty()) {
628 comname = strip(comname);
629 commandshortcut = "(" + comname + ')';
630 owner->message(commandshortcut);
632 // Here we could even add a small pause,
633 // to annoy the user and make him learn
635 // No! That will just annoy, not teach
636 // anything. The user will read the messages
637 // if they are interested. (Asger)
642 if (owner->view()->available() && owner->view()->theLockingInset()) {
643 UpdatableInset::RESULT result;
644 if ((action > 1) || ((action == LFUN_UNKNOWN_ACTION) &&
645 (keyseq.length >= -1)))
647 if ((action==LFUN_UNKNOWN_ACTION) && argument.empty()){
648 argument = keyseq.getiso();
650 // Undo/Redo pre 0.13 is a bit tricky for insets.
651 if (action == LFUN_UNDO) {
654 UpdatableInset * inset =
655 owner->view()->theLockingInset();
656 inset->GetCursorPos(owner->view(), slx, sly);
657 owner->view()->unlockInset(inset);
658 owner->view()->menuUndo();
659 if (TEXT()->cursor.par()->
660 IsInset(TEXT()->cursor.pos())) {
661 inset = static_cast<UpdatableInset*>(
662 TEXT()->cursor.par()->
669 inset->Edit(owner->view(),slx,sly,0);
671 } else if (action == LFUN_REDO) {
674 UpdatableInset * inset = owner->view()->
676 inset->GetCursorPos(owner->view(), slx, sly);
677 owner->view()->unlockInset(inset);
678 owner->view()->menuRedo();
679 inset = static_cast<UpdatableInset*>(
680 TEXT()->cursor.par()->
684 inset->Edit(owner->view(),slx,sly,0);
686 } else if (((result=owner->view()->theLockingInset()->
687 LocalDispatch(owner->view(), action,
689 UpdatableInset::DISPATCHED) ||
690 (result == UpdatableInset::DISPATCHED_NOUPDATE))
693 //setMessage(N_("Text mode"));
695 case LFUN_UNKNOWN_ACTION:
696 case LFUN_BREAKPARAGRAPH:
698 TEXT()->CursorRight(owner->view());
699 owner->view()->setState();
703 if (!TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params)) {
704 TEXT()->CursorRight(owner->view());
705 moveCursorUpdate(true, false);
710 if (TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params)) {
711 TEXT()->CursorRight(owner->view());
712 moveCursorUpdate(true, false);
717 if (TEXT()->cursor.row()->next())
718 TEXT()->CursorDown(owner->view());
720 TEXT()->CursorRight(owner->view());
721 moveCursorUpdate(true, false);
731 lyx::Assert(action != LFUN_SELECT_FILE_SYNC);
737 if (!owner->view()->available()) break;
739 // this function should be used always [asierra060396]
740 UpdatableInset * tli =
741 owner->view()->theLockingInset();
743 UpdatableInset * lock = tli->GetLockingInset();
746 owner->view()->unlockInset(tli);
747 TEXT()->CursorRight(owner->view());
748 moveCursorUpdate(true, false);
751 tli->UnlockInsetInInset(owner->view(),
759 // --- Misc -------------------------------------------
760 case LFUN_WORDFINDFORWARD :
761 case LFUN_WORDFINDBACKWARD : {
762 static string last_search;
763 string searched_string;
765 if (!argument.empty()) {
766 last_search = argument;
767 searched_string = argument;
769 searched_string = last_search;
772 if (!searched_string.empty() &&
773 ((action == LFUN_WORDFINDBACKWARD) ?
774 SearchBackward(owner->view(), searched_string) :
775 SearchForward(owner->view(), searched_string))) {
777 // ??? What is that ???
778 owner->view()->update(TEXT(), BufferView::SELECT|BufferView::FITCUR);
781 // clear the selection (if there is any)
782 owner->view()->toggleSelection();
783 TEXT()->ClearSelection(owner->view());
785 // Move cursor so that successive C-s 's will not stand in place.
786 if (action == LFUN_WORDFINDFORWARD )
787 TEXT()->CursorRightOneWord(owner->view());
788 TEXT()->FinishUndo();
789 moveCursorUpdate(true, false);
792 // set the new selection
793 // SetSelectionOverLenChars(owner->view()->currentBuffer()->text, iLenSelected);
794 owner->view()->toggleSelection(false);
797 // REMOVED : if (owner->view()->getWorkArea()->focus)
798 owner->view()->showCursor();
804 if (owner->view()->available() && !owner->view()->theLockingInset()) {
805 owner->view()->update(TEXT(),
806 BufferView::SELECT|BufferView::FITCUR);
809 keyseq.print(buf, true);
814 // --- Misc -------------------------------------------
815 case LFUN_EXEC_COMMAND:
817 std::vector<string> allCmds;
818 std::transform(lyxaction.func_begin(), lyxaction.func_end(),
819 std::back_inserter(allCmds), lyx::firster());
820 static std::vector<string> hist;
821 owner->getMiniBuffer()->getString(MiniBuffer::spaces,
826 case LFUN_CANCEL: // RVDK_PATCH_5
829 if (owner->view()->available())
830 // cancel any selection
831 Dispatch(LFUN_MARK_OFF);
832 setMessage(N_("Cancel"));
835 case LFUN_META_FAKE: // RVDK_PATCH_5
837 meta_fake_bit = Mod1Mask;
839 keyseq.print(buf, true);
840 setMessage(buf); // RVDK_PATCH_5
844 case LFUN_READ_ONLY_TOGGLE:
845 if (owner->buffer()->lyxvc.inUse()) {
846 owner->buffer()->lyxvc.toggleReadOnly();
848 owner->buffer()->setReadonly(
849 !owner->buffer()->isReadonly());
853 case LFUN_CENTER: // this is center and redraw.
854 owner->view()->center();
857 // --- Menus -----------------------------------------------
862 case LFUN_MENUNEWTMPLT:
866 case LFUN_CLOSEBUFFER:
871 if (!owner->buffer()->isUnnamed()) {
873 s1 << _("Saving document") << ' '
874 << MakeDisplayPath(owner->buffer()->fileName() + "...");
875 owner->message(s1.str().c_str());
876 MenuWrite(owner->view(), owner->buffer());
878 WriteAs(owner->view(), owner->buffer());
882 WriteAs(owner->view(), owner->buffer(), argument);
885 case LFUN_MENURELOAD:
890 Exporter::Export(owner->buffer(), argument, true);
894 Exporter::Preview(owner->buffer(), argument);
898 Exporter::Export(owner->buffer(), "program", true);
902 MenuRunChktex(owner->buffer());
906 owner->getDialogs()->showPrint();
910 if (argument == "custom")
913 Exporter::Export(owner->buffer(), argument, false);
931 InsetCommandParams p;
934 if (action == LFUN_TOCVIEW)
936 p.setCmdName("tableofcontents");
938 else if (action == LFUN_LOAVIEW )
939 p.setCmdName("listof{algorithm}{List of Algorithms}");
940 else if (action == LFUN_LOFVIEW)
941 p.setCmdName("listoffigures");
943 p.setCmdName("listoftables");
945 owner->getDialogs()->createTOC(p.getAsString());
949 case LFUN_DIALOG_TABULAR_INSERT:
950 owner->getDialogs()->showTabularCreate();
958 AutoSave(owner->view());
962 owner->view()->menuUndo();
966 owner->view()->menuRedo();
969 case LFUN_MENUSEARCH:
970 owner->getDialogs()->showSearch();
973 case LFUN_REMOVEERRORS:
974 if (owner->view()->removeAutoInsets()) {
975 owner->view()->redraw();
976 owner->view()->fitCursor(TEXT());
981 changeDepth(owner->view(), TEXT(false), 0);
985 changeDepth(owner->view(), TEXT(false), -1);
988 case LFUN_DEPTH_PLUS:
989 changeDepth(owner->view(), TEXT(false), 1);
993 owner->getDialogs()->setUserFreeFont();
998 owner->view()->setState();
1002 case LFUN_RECONFIGURE:
1003 Reconfigure(owner->view());
1007 case LFUN_FLOATSOPERATE:
1008 if (argument == "openfoot")
1009 owner->view()->allFloats(1,0);
1010 else if (argument == "closefoot")
1011 owner->view()->allFloats(0,0);
1012 else if (argument == "openfig")
1013 owner->view()->allFloats(1,1);
1014 else if (argument == "closefig")
1015 owner->view()->allFloats(0,1);
1018 #ifdef WITH_WARNINGS
1019 #warning Find another implementation here (or another lyxfunc)!
1022 case LFUN_HELP_COPYRIGHT:
1023 owner->getDialogs()->showCopyright();
1026 case LFUN_HELP_CREDITS:
1027 owner->getDialogs()->showCredits();
1030 case LFUN_HELP_OPEN:
1032 string const arg = argument;
1034 setErrorMessage(N_("Missing argument"));
1037 ProhibitInput(owner->view());
1038 string const fname = i18nLibFileSearch("doc", arg, "lyx");
1039 if (fname.empty()) {
1040 lyxerr << "LyX: unable to find documentation file `"
1041 << arg << "'. Bad installation?" << endl;
1042 AllowInput(owner->view());
1046 str << _("Opening help file") << ' '
1047 << MakeDisplayPath(fname) << "...";
1048 owner->message(str.str().c_str());
1049 owner->view()->buffer(bufferlist.loadLyXFile(fname,false));
1050 AllowInput(owner->view());
1054 case LFUN_HELP_VERSION: {
1055 ProhibitInput(owner->view());
1056 string msg(_("LyX Version "));
1060 fl_show_message(msg.c_str(),
1061 (_("Library directory: ")
1062 + MakeDisplayPath(system_lyxdir)).c_str(),
1063 (_("User directory: ")
1064 + MakeDisplayPath(user_lyxdir)).c_str());
1065 AllowInput(owner->view());
1069 // --- version control -------------------------------
1070 case LFUN_VC_REGISTER:
1072 if (!owner->buffer()->lyxvc.inUse())
1073 owner->buffer()->lyxvc.registrer();
1077 case LFUN_VC_CHECKIN:
1079 if (owner->buffer()->lyxvc.inUse()
1080 && !owner->buffer()->isReadonly())
1081 owner->buffer()->lyxvc.checkIn();
1085 case LFUN_VC_CHECKOUT:
1087 if (owner->buffer()->lyxvc.inUse()
1088 && owner->buffer()->isReadonly())
1089 owner->buffer()->lyxvc.checkOut();
1093 case LFUN_VC_REVERT:
1095 owner->buffer()->lyxvc.revert();
1101 owner->buffer()->lyxvc.undoLast();
1105 case LFUN_VC_HISTORY:
1107 owner->getDialogs()->showVCLogFile();
1111 // --- buffers ----------------------------------------
1113 case LFUN_SWITCHBUFFER:
1114 owner->view()->buffer(bufferlist.getBuffer(argument));
1119 // servercmd: argument must be <file>:<template>
1120 Buffer * tmpbuf = NewLyxFile(argument);
1122 owner->view()->buffer(tmpbuf);
1126 case LFUN_FILE_OPEN:
1130 case LFUN_LATEX_LOG:
1131 owner->getDialogs()->showLogFile();
1136 lyxerr.debug() << "LFUN_LAYOUTNO: (arg) " << argument << endl;
1137 int sel = strToInt(argument);
1138 lyxerr.debug() << "LFUN_LAYOUTNO: (sel) "<< sel << endl;
1140 // Should this give a setMessage instead?
1142 return string(); // illegal argument
1144 --sel; // sel 1..., but layout 0...
1146 // Pretend we got the name instead.
1147 Dispatch(int(LFUN_LAYOUT),
1148 textclasslist.NameOfLayout(owner->view()
1149 ->buffer()->params.textclass,
1154 case LFUN_LAYOUT_DOCUMENT:
1155 owner->getDialogs()->showDocument();
1158 case LFUN_LAYOUT_PARAGRAPH:
1159 owner->getDialogs()->showParagraph();
1162 case LFUN_LAYOUT_CHARACTER:
1163 owner->getDialogs()->showCharacter();
1166 case LFUN_LAYOUT_TABULAR:
1167 if (owner->view()->theLockingInset()) {
1168 if (owner->view()->theLockingInset()->LyxCode()==Inset::TABULAR_CODE) {
1169 InsetTabular * inset = static_cast<InsetTabular *>
1170 (owner->view()->theLockingInset());
1171 inset->OpenLayoutDialog(owner->view());
1172 } else if (owner->view()->theLockingInset()->
1173 GetFirstLockingInsetOfType(Inset::TABULAR_CODE)!=0) {
1174 InsetTabular * inset = static_cast<InsetTabular *>(
1175 owner->view()->theLockingInset()->GetFirstLockingInsetOfType(Inset::TABULAR_CODE));
1176 inset->OpenLayoutDialog(owner->view());
1181 case LFUN_LAYOUT_PREAMBLE:
1182 owner->getDialogs()->showPreamble();
1185 case LFUN_LAYOUT_SAVE_DEFAULT:
1186 MenuLayoutSave(owner->view());
1189 case LFUN_DROP_LAYOUTS_CHOICE:
1190 owner->getToolbar()->openLayoutList();
1193 case LFUN_MENU_OPEN_BY_NAME:
1194 owner->getMenubar()->openByName(argument);
1195 break; // RVDK_PATCH_5
1197 case LFUN_SPELLCHECK:
1198 if (lyxrc.isp_command != "none")
1199 ShowSpellChecker(owner->view());
1200 break; // RVDK_PATCH_5
1202 // --- lyxserver commands ----------------------------
1206 setMessage(owner->buffer()->fileName());
1207 lyxerr.debug() << "FNAME["
1208 << owner->buffer()->fileName()
1216 dispatch_buffer = buf;
1217 lyxserver->notifyClient(dispatch_buffer);
1221 case LFUN_GOTOFILEROW:
1223 char file_name[100];
1225 ::sscanf(argument.c_str(), " %s %d", file_name, &row);
1227 // Must replace extension of the file to be .lyx and get full path
1228 string s = ChangeExtension(string(file_name), ".lyx");
1230 // Either change buffer or load the file
1231 if (bufferlist.exists(s))
1232 owner->view()->buffer(bufferlist.getBuffer(s));
1234 owner->view()->buffer(bufferlist.loadLyXFile(s));
1237 owner->view()->setCursorFromRow(row);
1240 owner->view()->center();
1244 case LFUN_GOTO_PARAGRAPH:
1246 istringstream istr(argument.c_str());
1250 LyXParagraph * par = TEXT()->GetParFromID(id);
1255 TEXT()->SetCursor(owner->view(), par, 0);
1256 owner->view()->setState();
1260 owner->view()->center();
1267 int const qa = lyxaction.LookupFunc(argument);
1268 setMessage(lyxaction.helpText(static_cast<kb_action>(qa)));
1272 // --- toolbar ----------------------------------
1273 case LFUN_PUSH_TOOLBAR:
1275 int nth = strToInt(argument);
1277 setErrorMessage(N_("Push-toolbar needs argument > 0"));
1279 owner->getToolbar()->push(nth);
1284 case LFUN_ADD_TO_TOOLBAR:
1286 if (lyxerr.debugging(Debug::GUI)) {
1287 lyxerr << "LFUN_ADD_TO_TOOLBAR:"
1288 "argument = `" << argument << '\'' << endl;
1290 string tmp(argument);
1291 //lyxerr <<string("Argument: ") + argument);
1292 //lyxerr <<string("Tmp : ") + tmp);
1294 setErrorMessage(N_("Usage: toolbar-add-to <LyX command>"));
1296 owner->getToolbar()->add(argument, false);
1297 owner->getToolbar()->set();
1302 // --- insert characters ----------------------------------------
1304 // --- Mathed stuff. If we are here, there is no locked inset yet.
1309 if (!greek_kb_flag) {
1311 setMessage(N_("Math greek mode on"));
1318 case LFUN_GREEK_TOGGLE:
1320 greek_kb_flag = greek_kb_flag ? 0 : 2;
1321 if (greek_kb_flag) {
1322 setMessage(N_("Math greek keyboard on"));
1324 setMessage(N_("Math greek keyboard off"));
1329 case LFUN_MATH_EXTERN:
1330 case LFUN_MATH_NUMBER:
1331 case LFUN_MATH_LIMITS:
1333 setErrorMessage(N_("This is only allowed in math mode!"));
1337 case LFUN_MATH_PANEL:
1338 owner->getDialogs()->showMathPanel();
1341 case LFUN_CITATION_CREATE:
1343 InsetCommandParams p( "cite" );
1345 if (!argument.empty()) {
1346 // This should be set at source, ie when typing
1347 // "citation-insert foo" in the minibuffer.
1348 // Question: would pybibliographer also need to be
1349 // changed. Suspect so. Leave as-is therefore.
1350 if (contains(argument, "|")) {
1351 p.setContents( token(argument, '|', 0) );
1352 p.setOptions( token(argument, '|', 1) );
1354 p.setContents( argument );
1356 Dispatch(LFUN_CITATION_INSERT, p.getAsString());
1358 owner->getDialogs()->createCitation( p.getAsString() );
1362 case LFUN_CHILDOPEN:
1364 string const filename =
1365 MakeAbsPath(argument,
1366 OnlyPath(owner->buffer()->fileName()));
1367 setMessage(N_("Opening child document ") +
1368 MakeDisplayPath(filename) + "...");
1369 owner->view()->savePosition(0);
1370 if (bufferlist.exists(filename))
1371 owner->view()->buffer(bufferlist.getBuffer(filename));
1373 owner->view()->buffer(bufferlist.loadLyXFile(filename));
1377 case LFUN_TOGGLECURSORFOLLOW:
1378 lyxrc.cursor_follows_scrollbar = !lyxrc.cursor_follows_scrollbar;
1381 case LFUN_KMAP_OFF: // keymap off
1382 owner->getIntl()->KeyMapOn(false);
1385 case LFUN_KMAP_PRIM: // primary keymap
1386 owner->getIntl()->KeyMapPrim();
1389 case LFUN_KMAP_SEC: // secondary keymap
1390 owner->getIntl()->KeyMapSec();
1393 case LFUN_KMAP_TOGGLE: // toggle keymap
1394 owner->getIntl()->ToggleKeyMap();
1399 // argument contains ';'-terminated commands
1400 while (argument.find(';') != string::npos) {
1402 argument = split(argument, first, ';');
1408 case LFUN_DIALOG_PREFERENCES:
1409 owner->getDialogs()->showPreferences();
1412 case LFUN_SAVEPREFERENCES:
1414 Path p(user_lyxdir);
1415 lyxrc.write("preferences");
1419 case LFUN_SCREEN_FONT_UPDATE:
1421 // handle the screen font changes.
1423 lyxrc.set_font_norm_type();
1424 fontloader.update();
1425 // Of course we should only do the resize and the textcache.clear
1426 // if values really changed...but not very important right now. (Lgb)
1427 // All buffers will need resize
1428 bufferlist.resize();
1429 // We also need to empty the textcache so that
1430 // the buffer will be formatted correctly after
1436 case LFUN_SET_COLOR:
1439 string const x11_name = split(argument, lyx_name, ' ');
1440 if (lyx_name.empty() || x11_name.empty()) {
1441 setErrorMessage(N_("Syntax: set-color <lyx_name>"
1446 if (!lcolor.setColor(lyx_name, x11_name)) {
1447 static string const err1 (N_("Set-color \""));
1448 static string const err2 (
1449 N_("\" failed - color is undefined "
1450 "or may not be redefined"));
1451 setErrorMessage(_(err1) + lyx_name + _(err2));
1454 lyxColorHandler->updateColor(lcolor.getFromLyXName(lyx_name));
1455 owner->view()->redraw();
1460 owner->message(argument);
1463 case LFUN_MESSAGE_PUSH:
1464 owner->messagePush(argument);
1467 case LFUN_MESSAGE_POP:
1468 owner->messagePop();
1472 // Then if it was none of the above
1473 if (!owner->view()->Dispatch(action, argument))
1474 lyxerr << "A truly unknown func ["
1475 << action << "]!" << endl;
1481 string const res = getMessage();
1484 if (!commandshortcut.empty()) {
1485 owner->getMiniBuffer()->addSet(commandshortcut);
1488 string const msg(_(res) + ' ' + commandshortcut);
1489 owner->message(msg);
1496 void LyXFunc::setupLocalKeymap()
1498 keyseq.stdmap = keyseq.curmap = toplevel_keymap.get();
1499 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap.get();
1503 void LyXFunc::MenuNew(bool fromTemplate)
1505 string initpath = lyxrc.document_path;
1507 if (owner->view()->available()) {
1508 string const trypath = owner->buffer()->filepath;
1509 // If directory is writeable, use this as default.
1510 if (IsDirWriteable(trypath) == 1)
1514 static int newfile_number;
1517 if (lyxrc.new_ask_filename) {
1518 FileDialog fileDlg(owner, _("Enter filename for new document"),
1519 LFUN_SELECT_FILE_SYNC,
1520 make_pair(string(_("Documents")),
1521 string(lyxrc.document_path)),
1522 make_pair(string(_("Templates")),
1523 string(lyxrc.template_path)));
1525 FileDialog::Result result =
1526 fileDlg.Select(initpath,
1527 _("*.lyx|LyX Documents (*.lyx)"),
1530 if (result.second.empty()) {
1531 owner->message(_("Canceled."));
1532 lyxerr.debug() << "New Document Cancelled." << endl;
1536 // get absolute path of file and make sure the filename ends
1538 s = MakeAbsPath(result.second);
1539 if (!IsLyXFilename(s))
1542 // Check if the document already is open
1543 if (bufferlist.exists(s)) {
1544 switch (AskConfirmation(_("Document is already open:"),
1545 MakeDisplayPath(s, 50),
1546 _("Do you want to close that document now?\n"
1547 "('No' will just switch to the open version)")))
1549 case 1: // Yes: close the document
1550 if (!bufferlist.close(bufferlist.getBuffer(s)))
1551 // If close is canceled, we cancel here too.
1554 case 2: // No: switch to the open document
1555 owner->view()->buffer(bufferlist.getBuffer(s));
1557 case 3: // Cancel: Do nothing
1558 owner->message(_("Canceled."));
1562 // Check whether the file already exists
1563 if (IsLyXFilename(s)) {
1565 if (fi.readable() &&
1566 AskQuestion(_("File already exists:"),
1567 MakeDisplayPath(s, 50),
1568 _("Do you want to open the document?"))) {
1570 string const disp_fn(MakeDisplayPath(s));
1573 str << _("Opening document") << ' '
1574 << disp_fn << "...";
1576 owner->message(str.str().c_str());
1577 //XFlush(fl_get_display());
1578 owner->view()->buffer(
1579 bufferlist.loadLyXFile(s));
1581 str2 << _("Document") << ' '
1582 << disp_fn << ' ' << _("opened.");
1584 owner->message(str2.str().c_str());
1590 s = AddName(lyxrc.document_path,
1591 "newfile" + tostr(++newfile_number) + ".lyx");
1593 while (bufferlist.exists(s) || fi.readable()) {
1595 s = AddName(lyxrc.document_path,
1596 "newfile" + tostr(newfile_number) +
1602 // The template stuff
1605 FileDialog fileDlg(owner, _("Select template file"),
1606 LFUN_SELECT_FILE_SYNC,
1607 make_pair(string(_("Documents")),
1608 string(lyxrc.document_path)),
1609 make_pair(string(_("Templates")),
1610 string(lyxrc.template_path)));
1612 FileDialog::Result result =
1613 fileDlg.Select(initpath,
1614 _("*.lyx|LyX Documents (*.lyx)"));
1616 if (result.first == FileDialog::Later)
1619 string const fname = result.second;
1626 // find a free buffer
1627 lyxerr.debug() << "Find a free buffer." << endl;
1628 owner->view()->buffer(bufferlist.newFile(s, templname));
1632 void LyXFunc::Open(string const & fname)
1634 string initpath = lyxrc.document_path;
1636 if (owner->view()->available()) {
1637 string const trypath = owner->buffer()->filepath;
1638 // If directory is writeable, use this as default.
1639 if (IsDirWriteable(trypath) == 1)
1645 if (fname.empty()) {
1646 FileDialog fileDlg(owner, _("Select document to open"),
1648 make_pair(string(_("Documents")),
1649 string(lyxrc.document_path)),
1650 make_pair(string(_("Examples")),
1651 string(AddPath(system_lyxdir, "examples"))));
1653 FileDialog::Result result =
1654 fileDlg.Select(initpath,
1655 "*.lyx|LyX Documents (*.lyx)");
1657 if (result.first == FileDialog::Later)
1660 filename = result.second;
1662 // check selected filename
1663 if (filename.empty()) {
1664 owner->message(_("Canceled."));
1670 // get absolute path of file and make sure the filename ends
1672 filename = MakeAbsPath(filename);
1673 if (!IsLyXFilename(filename))
1677 string const disp_fn(MakeDisplayPath(filename));
1680 str << _("Opening document") << ' ' << disp_fn << "...";
1682 owner->message(str.str().c_str());
1684 Buffer * openbuf = bufferlist.loadLyXFile(filename);
1686 owner->view()->buffer(openbuf);
1688 str << _("Document") << ' ' << disp_fn << ' ' << _("opened.");
1689 owner->message(str.str().c_str());
1692 str << _("Could not open docuent") << ' ' << disp_fn;
1693 owner->message(str.str().c_str());
1698 // checks for running without gui are missing.
1699 void LyXFunc::doImport(string const & argument)
1702 string filename = split(argument, format, ' ');
1703 lyxerr.debug() << "LyXFunc::doImport: " << format
1704 << " file: " << filename << endl;
1706 if (filename.empty()) { // need user interaction
1707 string initpath = lyxrc.document_path;
1709 if (owner->view()->available()) {
1710 string const trypath = owner->buffer()->filepath;
1711 // If directory is writeable, use this as default.
1712 if (IsDirWriteable(trypath) == 1)
1716 string const text = _("Select ") + formats.PrettyName(format)
1717 + _(" file to import");
1719 FileDialog fileDlg(owner, text,
1721 make_pair(string(_("Documents")),
1722 string(lyxrc.document_path)),
1723 make_pair(string(_("Examples")),
1724 string(AddPath(system_lyxdir, "examples"))));
1726 string const extension = "*." + formats.Extension(format)
1727 + "| " + formats.PrettyName(format)
1728 + " (*." + formats.Extension(format) + ")";
1730 FileDialog::Result result = fileDlg.Select(initpath,
1733 if (result.first == FileDialog::Later)
1736 filename = result.second;
1738 // check selected filename
1739 if (filename.empty())
1740 owner->message(_("Canceled."));
1743 // still no filename? abort
1744 if (filename.empty())
1747 // get absolute path of file
1748 filename = MakeAbsPath(filename);
1750 string const lyxfile = ChangeExtension(filename, ".lyx");
1752 // Check if the document already is open
1753 if (bufferlist.exists(lyxfile)) {
1754 switch (AskConfirmation(_("Document is already open:"),
1755 MakeDisplayPath(lyxfile, 50),
1756 _("Do you want to close that document now?\n"
1757 "('No' will just switch to the open version)")))
1759 case 1: // Yes: close the document
1760 if (!bufferlist.close(bufferlist.getBuffer(lyxfile)))
1761 // If close is canceled, we cancel here too.
1764 case 2: // No: switch to the open document
1765 owner->view()->buffer(bufferlist.getBuffer(lyxfile));
1767 case 3: // Cancel: Do nothing
1768 owner->message(_("Canceled."));
1773 // Check if a LyX document by the same root exists in filesystem
1774 FileInfo const f(lyxfile, true);
1775 if (f.exist() && !AskQuestion(_("A document by the name"),
1776 MakeDisplayPath(lyxfile),
1777 _("already exists. Overwrite?"))) {
1778 owner->message(_("Canceled"));
1781 // filename should be valid now
1783 Importer::Import(owner, filename, format);
1787 void LyXFunc::reloadBuffer()
1789 string const fn = owner->buffer()->fileName();
1790 if (bufferlist.close(owner->buffer()))
1791 owner->view()->buffer(bufferlist.loadLyXFile(fn));
1795 void LyXFunc::CloseBuffer()
1797 if (bufferlist.close(owner->buffer()) && !quitting) {
1798 if (bufferlist.empty()) {
1799 // need this otherwise SEGV may occur while trying to
1800 // set variables that don't exist
1801 // since there's no current buffer
1802 owner->getDialogs()->hideBufferDependent();
1804 owner->view()->buffer(bufferlist.first());
1810 // Each "owner" should have it's own message method. lyxview and
1811 // the minibuffer would use the minibuffer, but lyxserver would
1812 // send an ERROR signal to its client. Alejandro 970603
1813 // This func is bit problematic when it comes to NLS, to make the
1814 // lyx servers client be language indepenent we must not translate
1815 // strings sent to this func.
1816 void LyXFunc::setErrorMessage(string const & m) const
1818 dispatch_buffer = m;
1823 void LyXFunc::setMessage(string const & m)
1825 dispatch_buffer = m;
1829 void LyXFunc::initMiniBuffer()
1831 string text = _("Welcome to LyX!");
1833 // When meta-fake key is pressed, show the key sequence so far + "M-".
1839 // Else, when a non-complete key sequence is pressed,
1840 // show the available options.
1841 else if (keyseqUncomplete())
1842 text = keyseqOptions();
1844 // Else, show the buffer state.
1845 else if (owner->view()->available()) {
1846 Buffer * tmpbuf = owner->buffer();
1848 string const nicename =
1849 MakeDisplayPath(tmpbuf->fileName());
1850 // Should we do this instead? (kindo like emacs)
1851 // leaves more room for other information
1854 if (tmpbuf->lyxvc.inUse()) {
1856 text += tmpbuf->lyxvc.version();
1858 text += tmpbuf->lyxvc.locker();
1859 if (tmpbuf->isReadonly())
1862 } else if (tmpbuf->isReadonly())
1864 if (!tmpbuf->isLyxClean())
1865 text += _(" (Changed)");
1867 if (text != _("Welcome to LyX!")) // this is a hack
1868 text = _("* No document open *");
1871 owner->message(text);