1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * ====================================================== */
23 #pragma implementation
29 #include "bufferlist.h"
30 #include "ColorHandler.h"
31 #include "lyxserver.h"
36 #include "LyXAction.h"
37 #include "insets/inseturl.h"
38 #include "insets/insetlatexaccent.h"
39 #include "insets/insettoc.h"
40 #include "insets/insetref.h"
41 #include "insets/insetparent.h"
42 #include "insets/insetindex.h"
43 #include "insets/insetinclude.h"
44 #include "insets/insetbib.h"
45 #include "insets/insetcite.h"
46 #include "insets/insettext.h"
47 #include "insets/insetert.h"
48 #include "insets/insetexternal.h"
49 #include "insets/insetgraphics.h"
50 #include "insets/insetfoot.h"
51 #include "insets/insetmarginal.h"
52 #include "insets/insetminipage.h"
53 #include "insets/insetfloat.h"
54 #include "insets/insetlist.h"
55 #include "insets/insettabular.h"
56 #include "insets/insettheorem.h"
57 #include "insets/insetcaption.h"
58 #include "mathed/formulamacro.h"
59 #include "spellchecker.h" // RVDK_PATCH_5
60 #include "minibuffer.h"
64 #include "lyx_gui_misc.h"
65 #include "support/filetools.h"
66 #include "support/FileInfo.h"
67 #include "support/syscall.h"
68 #include "support/lstrings.h"
69 #include "support/path.h"
70 #include "support/lyxfunctional.h"
75 #include "trans_mgr.h"
79 #include "bufferview_funcs.h"
80 #include "frontends/Dialogs.h"
81 #include "frontends/Toolbar.h"
82 #include "frontends/Menubar.h"
83 #include "FloatList.h"
84 #include "converter.h"
87 #include "FontLoader.h"
88 #include "TextCache.h"
94 extern void math_insert_symbol(string const &);
95 extern bool math_insert_greek(char);
96 extern BufferList bufferlist;
97 extern LyXServer * lyxserver;
98 extern int greek_kb_flag;
99 extern bool selection_possible;
101 extern kb_keymap * toplevel_keymap;
104 extern void MenuFax(Buffer *);
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();
116 /* === globals =========================================================== */
118 bool LyXFunc::show_sc = true;
121 LyXFunc::LyXFunc(LyXView * o)
125 lyx_dead_action = LFUN_NOACTION;
126 lyx_calling_dead_action = LFUN_NOACTION;
131 // I changed this func slightly. I commented out the ...FinishUndo(),
132 // this means that all places that used to have a moveCursorUpdate, now
133 // have a ...FinishUndo() as the preceeding statement. I have also added
134 // a moveCursorUpdate to some of the functions that updated the cursor, but
135 // that did not show its new position.
137 void LyXFunc::moveCursorUpdate(bool selecting)
139 if (selecting || owner->view()->text->mark_set) {
140 owner->view()->text->SetSelection();
141 owner->view()->toggleToggle();
143 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
144 owner->view()->showCursor();
146 /* ---> Everytime the cursor is moved, show the current font state. */
147 // should this too me moved out of this func?
148 //owner->showState();
149 owner->view()->setState();
153 int LyXFunc::processKeySym(KeySym keysym, unsigned int state)
157 if (lyxerr.debugging(Debug::KEY)) {
158 char * tmp = XKeysymToString(keysym);
159 string const stm = (tmp ? tmp : "");
160 lyxerr << "KeySym is "
163 << keysym << "] State is ["
167 // Do nothing if we have nothing (JMarc)
168 if (keysym == NoSymbol) {
169 lyxerr[Debug::KEY] << "Empty kbd action (probably composing)"
175 if (owner->view()->available()) {
176 // this function should be used always [asierra060396]
177 UpdatableInset * tli = owner->view()->theLockingInset();
178 if (tli && (keysym == XK_Escape)) {
179 if (tli == tli->GetLockingInset()) {
180 owner->view()->unlockInset(tli);
181 owner->view()->text->CursorRight(owner->view());
182 moveCursorUpdate(false);
185 tli->UnlockInsetInInset(owner->view(),
186 tli->GetLockingInset(),true);
193 // Can we be sure that this will work for all X-Windows
194 // implementations? (Lgb)
195 // This code snippet makes lyx ignore some keys. Perhaps
196 // all of them should be explictly mentioned?
197 if ((keysym >= XK_Shift_L && keysym <= XK_Hyper_R)
198 || keysym == XK_Mode_switch || keysym == 0x0)
201 // Do a one-deep top-level lookup for
202 // cancel and meta-fake keys. RVDK_PATCH_5
203 cancel_meta_seq.reset();
205 int action = cancel_meta_seq.addkey(keysym, state
206 &(ShiftMask|ControlMask
208 if (lyxerr.debugging(Debug::KEY)) {
209 lyxerr << "action first set to [" << action << "]" << endl;
212 // When not cancel or meta-fake, do the normal lookup.
213 // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
214 // Mostly, meta_fake_bit = 0. RVDK_PATCH_5.
215 if ((action != LFUN_CANCEL) && (action != LFUN_META_FAKE)) {
216 if (lyxerr.debugging(Debug::KEY)) {
217 lyxerr << "meta_fake_bit is [" << meta_fake_bit << "]" << endl;
219 // remove Caps Lock and Mod2 as a modifiers
220 action = keyseq.addkey(keysym,
221 (state | meta_fake_bit)
222 &(ShiftMask|ControlMask
224 if (lyxerr.debugging(Debug::KEY)) {
225 lyxerr << "action now set to [" << action << "]" << endl;
228 // Dont remove this unless you know what you are doing.
231 if (action == 0) action = LFUN_PREFIX;
233 if (lyxerr.debugging(Debug::KEY)) {
242 // already here we know if it any point in going further
243 // why not return already here if action == -1 and
244 // num_bytes == 0? (Lgb)
246 if (keyseq.length > 1 || keyseq.length < -1) {
249 owner->getMiniBuffer()->Set(buf);
253 if (keyseq.length < -1) { // unknown key sequence...
257 owner->getMiniBuffer()->Set(_("Unknown sequence:"), buf);
261 char const isochar = keyseq.getiso();
262 if (!(state & ControlMask) &&
263 !(state & Mod1Mask) &&
264 (isochar && keysym < 0xF000)) {
267 if (argument.empty()) {
268 lyxerr.debug() << "Empty argument!" << endl;
269 // This can`t possibly be of any use
270 // so we`ll skip the dispatch.
273 } else if (action == LFUN_SELFINSERT) {
274 // We must set the argument to the char looked up by
276 char const * tmp = XKeysymToString(keysym);
277 // if (!argument.empty()) {
278 argument = tmp ? tmp : "";
280 lyxerr[Debug::KEY] << "SelfInsert arg["
281 << argument << "]" << endl;
285 bool tmp_sc = show_sc;
287 Dispatch(action, argument);
294 LyXFunc::func_status LyXFunc::getStatus(int ac) const
297 func_status flag = LyXFunc::OK;
299 Buffer * buf = owner->buffer();
301 if (lyxaction.isPseudoAction(ac))
302 action = lyxaction.retrieveActionArg(ac, argument);
304 action = static_cast<kb_action>(ac);
306 if (action == LFUN_UNKNOWN_ACTION) {
307 setErrorMessage(N_("Unknown action"));
308 return LyXFunc::Unknown;
311 // Check whether we need a buffer
312 if (!lyxaction.funcHasFlag(action, LyXAction::NoBuffer)) {
313 // Yes we need a buffer, do we have one?
316 // Can we use a readonly buffer?
317 if (buf->isReadonly() &&
318 !lyxaction.funcHasFlag(action,
319 LyXAction::ReadOnly)) {
321 setErrorMessage(N_("Document is read-only"));
322 flag |= LyXFunc::Disabled;
326 setErrorMessage(N_("Command not allowed with"
327 "out any document open"));
328 flag |= LyXFunc::Disabled;
333 // I would really like to avoid having this switch and rather try to
334 // encode this in the function itself.
335 bool disable = false;
338 disable = !Exporter::IsExportable(buf, "dvi")
339 || lyxrc.print_command == "none";
343 disable = !Exporter::IsExportable(buf, "ps")
344 || lyxrc.fax_command == "none";
348 disable = argument == "fax" &&
349 !Exporter::IsExportable(buf, argument);
353 disable = buf->undostack.empty();
356 disable = buf->redostack.empty();
358 case LFUN_SPELLCHECK:
359 disable = lyxrc.isp_command == "none";
362 disable = lyxrc.chktex_command == "none";
365 disable = !Exporter::IsExportable(buf, "program");
368 case LFUN_INSERTFOOTNOTE:
370 case LFUN_MARGINMELT:
371 // Disable insertion of floats in a tabular.
373 if (owner->view()->theLockingInset()) {
374 disable = (owner->view()->theLockingInset()->LyxCode() == Inset::TABULAR_CODE) ||
375 owner->view()->theLockingInset()->GetFirstLockingInsetOfType(Inset::TABULAR_CODE);
379 case LFUN_LAYOUT_TABULAR:
381 if (owner->view()->theLockingInset()) {
382 disable = (owner->view()->theLockingInset()->LyxCode() != Inset::TABULAR_CODE) &&
383 !owner->view()->theLockingInset()->GetFirstLockingInsetOfType(Inset::TABULAR_CODE);
387 case LFUN_TABULAR_FEATURE:
389 if (owner->view()->theLockingInset()) {
390 func_status ret = LyXFunc::Disabled;
391 if (owner->view()->theLockingInset()->LyxCode() == Inset::TABULAR_CODE) {
392 ret = static_cast<InsetTabular *>
393 (owner->view()->theLockingInset())->
395 } else if (owner->view()->theLockingInset()->GetFirstLockingInsetOfType(Inset::TABULAR_CODE)) {
396 ret = static_cast<InsetTabular *>
397 (owner->view()->theLockingInset()->
398 GetFirstLockingInsetOfType(Inset::TABULAR_CODE))->
404 static InsetTabular inset(*owner->buffer(), 1, 1);
408 ret = inset.getStatus(argument);
409 if ((ret & LyXFunc::ToggleOn) ||
410 (ret & LyXFunc::ToggleOff))
411 flag |= LyXFunc::ToggleOff;
415 case LFUN_VC_REGISTER:
416 disable = buf->lyxvc.inUse();
418 case LFUN_VC_CHECKIN:
419 disable = !buf->lyxvc.inUse() || buf->isReadonly();
421 case LFUN_VC_CHECKOUT:
422 disable = !buf->lyxvc.inUse() || !buf->isReadonly();
426 case LFUN_VC_HISTORY:
427 disable = !buf->lyxvc.inUse();
430 disable = owner->view()->NoSavedPositions();
436 flag |= LyXFunc::Disabled;
439 func_status box = LyXFunc::ToggleOff;
440 LyXFont const & font =
441 owner->view()->getLyXText()->real_current_font;
444 if (font.emph() == LyXFont::ON)
445 box = LyXFunc::ToggleOn;
448 if (font.noun() == LyXFont::ON)
449 box = LyXFunc::ToggleOn;
452 if (font.series() == LyXFont::BOLD_SERIES)
453 box = LyXFunc::ToggleOn;
456 if (font.latex() == LyXFont::ON)
457 box = LyXFunc::ToggleOn;
470 string const LyXFunc::Dispatch(string const & s)
472 // Split command string into command and argument
474 string line = frontStrip(s);
475 string arg = strip(frontStrip(split(line, cmd, ' ')));
477 return Dispatch(lyxaction.LookupFunc(cmd), arg);
481 string const LyXFunc::Dispatch(int ac,
482 string const & do_not_use_this_arg)
484 lyxerr[Debug::ACTION] << "LyXFunc::Dispatch: action[" << ac
485 <<"] arg[" << do_not_use_this_arg << "]" << endl;
490 // we have not done anything wrong yet.
492 dispatch_buffer.erase();
494 // if action is a pseudo-action, we need the real action
495 if (lyxaction.isPseudoAction(ac)) {
497 action = static_cast<kb_action>
498 (lyxaction.retrieveActionArg(ac, tmparg));
502 action = static_cast<kb_action>(ac);
503 if (!do_not_use_this_arg.empty())
504 argument = do_not_use_this_arg; // except here
507 selection_possible = false;
509 if (owner->view()->available())
510 owner->view()->hideCursor();
512 // We have to do this heare because of te goto below. (Lgb)
513 LyXText * text = owner->view()->getLyXText();
515 // We cannot use this function here
516 if (getStatus(ac) & Disabled)
517 goto exit_with_message;
519 commandshortcut.erase();
521 if (lyxrc.display_shortcuts && show_sc) {
522 if (action != LFUN_SELFINSERT) {
523 // Put name of command and list of shortcuts
524 // for it in minibuffer
525 string comname = lyxaction.getActionName(action);
527 int pseudoaction = action;
528 bool argsadded = false;
530 if (!argument.empty()) {
531 // If we have the command with argument,
534 lyxaction.searchActionArg(action,
537 if (pseudoaction == -1) {
538 pseudoaction = action;
540 comname += " " + argument;
545 string const shortcuts =
546 toplevel_keymap->findbinding(pseudoaction);
548 if (!shortcuts.empty()) {
549 comname += ": " + shortcuts;
550 } else if (!argsadded) {
551 comname += " " + argument;
554 if (!comname.empty()) {
555 comname = strip(comname);
556 commandshortcut = "(" + comname + ')';
557 owner->getMiniBuffer()->Set(commandshortcut);
558 // Here we could even add a small pause,
559 // to annoy the user and make him learn
561 // No! That will just annoy, not teach
562 // anything. The user will read the messages
563 // if they are interested. (Asger)
568 if (owner->view()->available() && owner->view()->theLockingInset()) {
569 UpdatableInset::RESULT result;
570 if ((action > 1) || ((action == LFUN_UNKNOWN_ACTION) &&
571 (keyseq.length >= -1)))
573 if ((action==LFUN_UNKNOWN_ACTION) && argument.empty()){
574 argument = keyseq.getiso();
576 // Undo/Redo pre 0.13 is a bit tricky for insets.
577 if (action == LFUN_UNDO) {
580 UpdatableInset * inset =
581 owner->view()->theLockingInset();
582 inset->GetCursorPos(owner->view(), slx, sly);
583 owner->view()->unlockInset(inset);
584 owner->view()->menuUndo();
585 if (owner->view()->text->cursor.par()->
586 IsInset(owner->view()->text->cursor.pos())) {
587 inset = static_cast<UpdatableInset*>(
588 owner->view()->text->cursor.par()->
589 GetInset(owner->view()->text->
595 inset->Edit(owner->view(),slx,sly,0);
597 } else if (action == LFUN_REDO) {
600 UpdatableInset * inset = owner->view()->
602 inset->GetCursorPos(owner->view(), slx, sly);
603 owner->view()->unlockInset(inset);
604 owner->view()->menuRedo();
605 inset = static_cast<UpdatableInset*>(
606 owner->view()->text->cursor.par()->
607 GetInset(owner->view()->text->
610 inset->Edit(owner->view(),slx,sly,0);
612 } else if (((result=owner->view()->theLockingInset()->
613 LocalDispatch(owner->view(), action,
615 UpdatableInset::DISPATCHED) ||
616 (result == UpdatableInset::DISPATCHED_NOUPDATE))
619 setMessage(N_("Text mode"));
621 case LFUN_UNKNOWN_ACTION:
622 case LFUN_BREAKPARAGRAPH:
624 owner->view()->text->CursorRight(owner->view());
625 owner->view()->setState();
629 if (!owner->view()->text->cursor.par()->isRightToLeftPar(owner->buffer()->params)) {
630 owner->view()->text->CursorRight(owner->view());
631 moveCursorUpdate(false);
636 if (owner->view()->text->cursor.par()->isRightToLeftPar(owner->buffer()->params)) {
637 owner->view()->text->CursorRight(owner->view());
638 moveCursorUpdate(false);
643 owner->view()->text->CursorDown(owner->view());
644 moveCursorUpdate(false);
655 // --- Misc -------------------------------------------
656 case LFUN_WORDFINDFORWARD :
657 case LFUN_WORDFINDBACKWARD : {
658 static string last_search;
659 string searched_string;
661 if (!argument.empty()) {
662 last_search = argument;
663 searched_string = argument;
665 searched_string = last_search;
668 LyXText * ltCur = owner->view()->text ;
670 if (!searched_string.empty() &&
671 ((action == LFUN_WORDFINDBACKWARD) ?
672 ltCur->SearchBackward(owner->view(), searched_string) :
673 ltCur->SearchForward(owner->view(), searched_string))) {
675 // ??? What is that ???
676 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
679 // clear the selection (if there is any)
680 owner->view()->toggleSelection();
681 owner->view()->text->ClearSelection();
683 // Move cursor so that successive C-s 's will not stand in place.
684 if (action == LFUN_WORDFINDFORWARD )
685 owner->view()->text->CursorRightOneWord(owner->view());
686 owner->view()->text->FinishUndo();
687 moveCursorUpdate(false);
690 // set the new selection
691 // SetSelectionOverLenChars(owner->view()->currentBuffer()->text, iLenSelected);
692 owner->view()->toggleSelection(false);
696 // REMOVED : if (owner->view()->getWorkArea()->focus)
697 owner->view()->showCursor();
703 if (owner->view()->available()) {
704 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
707 keyseq.print(buf, true);
708 owner->getMiniBuffer()->Set(buf, string(), string(), 1);
712 // --- Misc -------------------------------------------
713 case LFUN_EXEC_COMMAND:
714 owner->getMiniBuffer()->PrepareForCommand();
717 case LFUN_CANCEL: // RVDK_PATCH_5
720 if (owner->view()->available())
721 // cancel any selection
722 Dispatch(LFUN_MARK_OFF);
723 setMessage(N_("Cancel"));
726 case LFUN_META_FAKE: // RVDK_PATCH_5
728 meta_fake_bit = Mod1Mask;
730 keyseq.print(buf, true);
731 setMessage(buf); // RVDK_PATCH_5
735 case LFUN_READ_ONLY_TOGGLE:
736 if (owner->buffer()->lyxvc.inUse()) {
737 owner->buffer()->lyxvc.toggleReadOnly();
739 owner->buffer()->setReadonly(
740 !owner->buffer()->isReadonly());
744 case LFUN_CENTER: // this is center and redraw.
745 owner->view()->center();
749 if (owner->view()->available()) {
750 owner->view()->text->toggleAppendix(owner->view());
751 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
755 // --- Menus -----------------------------------------------
760 case LFUN_MENUNEWTMPLT:
768 case LFUN_CLOSEBUFFER:
773 if (!owner->buffer()->isUnnamed()) {
774 owner->getMiniBuffer()->Set(_("Saving document"),
775 MakeDisplayPath(owner->buffer()->fileName()),
777 MenuWrite(owner->view(), owner->buffer());
778 //owner->getMiniBuffer()-> {
779 // Set(_("Document saved as"),
780 // MakeDisplayPath(owner->buffer()->fileName()));
782 //owner->getMiniBuffer()->Set(_("Save failed!"));
785 MenuWriteAs(owner->view(), owner->buffer());
789 case LFUN_MENUWRITEAS:
790 MenuWriteAs(owner->view(), owner->buffer());
793 case LFUN_MENURELOAD:
798 Exporter::Export(owner->buffer(), argument, true);
802 Exporter::Preview(owner->buffer(), argument);
806 Exporter::Export(owner->buffer(), "program", true);
810 MenuRunChktex(owner->buffer());
814 owner->getDialogs()->showPrint();
819 MenuFax(owner->buffer());
824 Exporter::Export(owner->buffer(), argument, false);
840 InsetCommandParams p;
842 if (action == LFUN_TOCVIEW )
843 p.setCmdName( "tableofcontents" );
844 else if (action == LFUN_LOAVIEW )
845 p.setCmdName( "listofalgorithms" );
846 else if (action == LFUN_LOFVIEW )
847 p.setCmdName( "listoffigures" );
849 p.setCmdName( "listoftables" );
851 owner->getDialogs()->createTOC( p.getAsString() );
855 case LFUN_TOC_INSERT:
856 case LFUN_LOA_INSERT:
857 case LFUN_LOF_INSERT:
858 case LFUN_LOT_INSERT:
860 InsetCommandParams p;
862 if (action == LFUN_TOC_INSERT )
863 p.setCmdName( "tableofcontents" );
864 else if (action == LFUN_LOA_INSERT )
865 p.setCmdName( "listofalgorithms" );
866 else if (action == LFUN_LOF_INSERT )
867 p.setCmdName( "listoffigures" );
869 p.setCmdName( "listoftables" );
871 Inset * inset = new InsetTOC( p );
872 if (!owner->view()->insertInset( inset, "Standard", true ) )
877 case LFUN_DIALOG_TABULAR_INSERT:
878 owner->getDialogs()->showTabularCreate();
881 case LFUN_TABULAR_FEATURE:
882 case LFUN_SCROLL_INSET:
883 // this is not handled here as this funktion is only aktive
884 // if we have a locking_inset and that one is (or contains)
892 case LFUN_INSET_GRAPHICS:
894 Inset * new_inset = new InsetGraphics;
895 if (!owner->view()->insertInset(new_inset)) {
898 // this is need because you don't use a inset->Edit()
899 owner->view()->updateInset(new_inset, true);
900 new_inset->Edit(owner->view(), 0, 0, 0);
906 AutoSave(owner->view());
910 owner->view()->menuUndo();
914 owner->view()->menuRedo();
917 case LFUN_MENUSEARCH:
919 // Ok this is one _very_ bad solution, but I think that some
920 // of this will be rewritten as part of GUI indep anyway.
922 static LyXFindReplace FR_;
923 FR_.StartSearch(owner->view());
928 owner->view()->paste();
929 owner->view()->setState();
932 case LFUN_PASTESELECTION:
935 if (argument == "paragraph") asPara = true;
936 owner->view()->pasteClipboard(asPara);
941 owner->view()->cut();
945 owner->view()->copy();
948 case LFUN_LAYOUT_COPY:
949 owner->view()->copyEnvironment();
952 case LFUN_LAYOUT_PASTE:
953 owner->view()->pasteEnvironment();
954 owner->view()->setState();
958 owner->view()->gotoError();
961 case LFUN_REMOVEERRORS:
962 if (owner->view()->removeAutoInsets()) {
963 owner->view()->redraw();
964 owner->view()->fitCursor(owner->view()->text);
969 owner->view()->gotoNote();
974 owner->view()->openStuff();
978 case LFUN_HYPHENATION:
979 owner->view()->hyphenationPoint();
983 owner->view()->ldots();
986 case LFUN_END_OF_SENTENCE:
987 owner->view()->endOfSentenceDot();
990 case LFUN_MENU_SEPARATOR:
991 owner->view()->menuSeparator();
995 owner->view()->hfill();
999 changeDepth(owner->view(), 0);
1002 case LFUN_DEPTH_MIN:
1003 changeDepth(owner->view(), -1);
1006 case LFUN_DEPTH_PLUS:
1007 changeDepth(owner->view(), 1);
1011 Free(owner->view());
1012 owner->view()->setState();
1018 owner->view()->setState();
1023 Melt(owner->view());
1026 case LFUN_RECONFIGURE:
1027 Reconfigure(owner->view());
1031 if (owner->view()->available()
1032 && !owner->view()->text->selection
1033 && owner->view()->text->cursor.par()->footnoteflag
1034 != LyXParagraph::NO_FOOTNOTE)
1035 { // only melt footnotes with FOOTMELT, not margins etc
1036 if (owner->view()->text->cursor.par()->footnotekind == LyXParagraph::FOOTNOTE)
1037 Melt(owner->view());
1040 Foot(owner->view());
1041 owner->view()->setState();
1044 case LFUN_MARGINMELT:
1045 if (owner->view()->available()
1046 && !owner->view()->text->selection
1047 && owner->view()->text->cursor.par()->footnoteflag
1048 != LyXParagraph::NO_FOOTNOTE) {
1049 // only melt margins
1050 if (owner->view()->text->cursor.par()->footnotekind == LyXParagraph::MARGIN)
1051 Melt(owner->view());
1053 Margin(owner->view());
1054 owner->view()->setState();
1058 case LFUN_FLOATSOPERATE:
1059 if (argument == "openfoot")
1060 owner->view()->allFloats(1,0);
1061 else if (argument == "closefoot")
1062 owner->view()->allFloats(0,0);
1063 else if (argument == "openfig")
1064 owner->view()->allFloats(1,1);
1065 else if (argument == "closefig")
1066 owner->view()->allFloats(0,1);
1069 #warning Find another implementation here (or another lyxfunc)!
1071 case LFUN_HELP_COPYRIGHT:
1072 owner->getDialogs()->showCopyright();
1075 case LFUN_HELP_CREDITS:
1076 owner->getDialogs()->showCredits();
1079 case LFUN_HELP_OPEN: {
1080 string arg = argument;
1082 setErrorMessage(N_("Missing argument"));
1085 ProhibitInput(owner->view());
1086 string fname = i18nLibFileSearch("doc", arg, "lyx");
1087 if (fname.empty()) {
1088 lyxerr << "LyX: unable to find documentation file `"
1089 << arg << "'. Bad installation?" << endl;
1090 AllowInput(owner->view());
1093 owner->getMiniBuffer()->Set(_("Opening help file"),
1094 MakeDisplayPath(fname),"...");
1095 owner->view()->buffer(bufferlist.loadLyXFile(fname,false));
1096 AllowInput(owner->view());
1100 case LFUN_HELP_VERSION: {
1101 ProhibitInput(owner->view());
1102 string msg(_("LyX Version "));
1106 fl_show_message(msg.c_str(),
1107 (_("Library directory: ")
1108 + MakeDisplayPath(system_lyxdir)).c_str(),
1109 (_("User directory: ")
1110 + MakeDisplayPath(user_lyxdir)).c_str());
1111 AllowInput(owner->view());
1115 // --- version control -------------------------------
1116 case LFUN_VC_REGISTER:
1118 if (!owner->buffer()->lyxvc.inUse())
1119 owner->buffer()->lyxvc.registrer();
1123 case LFUN_VC_CHECKIN:
1125 if (owner->buffer()->lyxvc.inUse()
1126 && !owner->buffer()->isReadonly())
1127 owner->buffer()->lyxvc.checkIn();
1131 case LFUN_VC_CHECKOUT:
1133 if (owner->buffer()->lyxvc.inUse()
1134 && owner->buffer()->isReadonly())
1135 owner->buffer()->lyxvc.checkOut();
1139 case LFUN_VC_REVERT:
1141 owner->buffer()->lyxvc.revert();
1147 owner->buffer()->lyxvc.undoLast();
1151 case LFUN_VC_HISTORY:
1153 owner->buffer()->lyxvc.showLog();
1157 // --- buffers ----------------------------------------
1159 case LFUN_SWITCHBUFFER:
1160 owner->view()->buffer(bufferlist.getBuffer(argument));
1164 case LFUN_FILE_INSERT:
1166 MenuInsertLyXFile(argument);
1170 case LFUN_FILE_INSERT_ASCII:
1172 bool asPara = (argument == "paragraph");
1173 InsertAsciiFile(owner->view(), string(), asPara);
1179 // servercmd: argument must be <file>:<template>
1180 Buffer * tmpbuf = NewLyxFile(argument);
1182 owner->view()->buffer(tmpbuf);
1186 case LFUN_FILE_OPEN:
1187 owner->view()->buffer(bufferlist.loadLyXFile(argument));
1190 case LFUN_LATEX_LOG:
1196 lyxerr.debug() << "LFUN_LAYOUTNO: (arg) " << argument << endl;
1197 int sel = strToInt(argument);
1198 lyxerr.debug() << "LFUN_LAYOUTNO: (sel) "<< sel << endl;
1200 // Should this give a setMessage instead?
1202 return string(); // illegal argument
1204 --sel; // sel 1..., but layout 0...
1206 // Pretend we got the name instead.
1207 Dispatch(int(LFUN_LAYOUT),
1208 textclasslist.NameOfLayout(owner->view()
1209 ->buffer()->params.textclass,
1216 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1217 << argument << endl;
1219 // Derive layout number from given argument (string)
1220 // and current buffer's textclass (number). */
1221 LyXTextClassList::ClassList::size_type tclass =
1222 owner->view()->buffer()->params.textclass;
1223 pair <bool, LyXTextClass::size_type> layout =
1224 textclasslist.NumberOfLayout(tclass, argument);
1226 // If the entry is obsolete, use the new one instead.
1228 string obs = textclasslist.Style(tclass,layout.second)
1232 textclasslist.NumberOfLayout(tclass, obs);
1235 // see if we found the layout number:
1236 if (!layout.first) {
1237 setErrorMessage(string(N_("Layout ")) + argument +
1242 if (current_layout != layout.second) {
1243 owner->view()->hideCursor();
1244 current_layout = layout.second;
1245 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1246 owner->view()->text->
1247 SetLayout(owner->view(), layout.second);
1248 owner->setLayout(layout.second);
1249 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1250 owner->view()->setState();
1255 case LFUN_LAYOUT_DOCUMENT:
1256 owner->getDialogs()->showLayoutDocument();
1259 case LFUN_LAYOUT_PARAGRAPH:
1260 #ifdef USE_OLD_PARAGRAPH_LAYOUT
1261 MenuLayoutParagraph();
1263 owner->getDialogs()->showLayoutParagraph();
1267 case LFUN_LAYOUT_CHARACTER:
1268 MenuLayoutCharacter();
1271 case LFUN_LAYOUT_TABULAR:
1272 if (owner->view()->theLockingInset()) {
1273 if (owner->view()->theLockingInset()->LyxCode()==Inset::TABULAR_CODE) {
1274 InsetTabular * inset = static_cast<InsetTabular *>
1275 (owner->view()->theLockingInset());
1276 inset->OpenLayoutDialog(owner->view());
1277 } else if (owner->view()->theLockingInset()->
1278 GetFirstLockingInsetOfType(Inset::TABULAR_CODE)!=0) {
1279 InsetTabular * inset = static_cast<InsetTabular *>(
1280 owner->view()->theLockingInset()->GetFirstLockingInsetOfType(Inset::TABULAR_CODE));
1281 inset->OpenLayoutDialog(owner->view());
1286 case LFUN_LAYOUT_PREAMBLE:
1287 MenuLayoutPreamble();
1290 case LFUN_LAYOUT_SAVE_DEFAULT:
1291 MenuLayoutSave(owner->view());
1294 case LFUN_DROP_LAYOUTS_CHOICE:
1295 owner->getToolbar()->openLayoutList();
1299 Lang(owner->view(), argument);
1300 owner->view()->setState();
1305 Emph(owner->view());
1310 Bold(owner->view());
1315 Noun(owner->view());
1320 Code(owner->view());
1325 Sans(owner->view());
1330 Roman(owner->view());
1335 StyleReset(owner->view());
1339 case LFUN_UNDERLINE:
1340 Underline(owner->view());
1344 case LFUN_FONT_SIZE:
1345 FontSize(owner->view(), argument);
1349 case LFUN_FONT_STATE:
1350 setMessage(CurrentState(owner->view()));
1353 case LFUN_UPCASE_WORD:
1354 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1355 text->ChangeWordCase(owner->view(), LyXText::text_uppercase);
1356 if (text->inset_owner)
1357 owner->view()->updateInset(text->inset_owner, true);
1358 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1361 case LFUN_LOWCASE_WORD:
1362 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1363 text->ChangeWordCase(owner->view(), LyXText::text_lowercase);
1364 if (text->inset_owner)
1365 owner->view()->updateInset(text->inset_owner, true);
1366 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1369 case LFUN_CAPITALIZE_WORD:
1370 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1371 text->ChangeWordCase(owner->view(),
1372 LyXText::text_capitalization);
1373 if (text->inset_owner)
1374 owner->view()->updateInset(text->inset_owner, true);
1375 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1378 case LFUN_INSERT_LABEL:
1379 MenuInsertLabel(owner->view(), argument);
1382 case LFUN_REF_INSERT:
1383 if (argument.empty()) {
1384 InsetCommandParams p("ref");
1385 owner->getDialogs()->createRef(p.getAsString());
1387 InsetCommandParams p;
1388 p.setFromString(argument);
1390 InsetRef * inset = new InsetRef(p, *owner->buffer());
1391 if (!owner->view()->insertInset(inset))
1394 owner->view()->updateInset(inset, true);
1400 owner->view()->restorePosition();
1406 string label(argument);
1407 if (label.empty()) {
1409 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1411 label = inset->getContents();
1414 if (!label.empty()) {
1415 owner->view()->savePosition();
1416 if (!owner->view()->gotoLabel(label))
1417 WriteAlert(_("Error"),
1418 _("Couldn't find this label"),
1419 _("in current document."));
1424 case LFUN_MENU_OPEN_BY_NAME:
1425 owner->getMenubar()->openByName(argument);
1426 break; // RVDK_PATCH_5
1428 case LFUN_SPELLCHECK:
1429 if (lyxrc.isp_command != "none")
1430 ShowSpellChecker(owner->view());
1431 break; // RVDK_PATCH_5
1433 // --- Cursor Movements -----------------------------
1436 LyXText * tmptext = owner->view()->text;
1437 bool is_rtl = tmptext->cursor.par()->isRightToLeftPar(owner->buffer()->params);
1438 if (!tmptext->mark_set)
1439 owner->view()->beforeChange();
1440 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1442 tmptext->CursorLeft(owner->view(), false);
1443 if (tmptext->cursor.pos() < tmptext->cursor.par()->Last()
1444 && tmptext->cursor.par()->GetChar(tmptext->cursor.pos())
1445 == LyXParagraph::META_INSET
1446 && tmptext->cursor.par()->GetInset(tmptext->cursor.pos())
1447 && tmptext->cursor.par()->GetInset(tmptext->cursor.pos())->Editable() == Inset::HIGHLY_EDITABLE){
1448 Inset * tmpinset = tmptext->cursor.par()->GetInset(tmptext->cursor.pos());
1449 setMessage(tmpinset->EditMessage());
1450 tmpinset->Edit(owner->view(), 0, 0, 0);
1454 tmptext->CursorRight(owner->view(), false);
1455 owner->view()->text->FinishUndo();
1456 moveCursorUpdate(false);
1463 // This is soooo ugly. Isn`t it possible to make
1464 // it simpler? (Lgb)
1465 LyXText * txt = owner->view()->text;
1466 bool is_rtl = txt->cursor.par()->isRightToLeftPar(owner->buffer()->params);
1467 if (!txt->mark_set) owner->view()->beforeChange();
1468 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1469 LyXCursor cur = txt->cursor;
1471 txt->CursorLeft(owner->view(), false);
1472 if ((cur != txt->cursor) && // only if really moved!
1473 txt->cursor.pos() < txt->cursor.par()->Last() &&
1474 (txt->cursor.par()->GetChar(txt->cursor.pos()) ==
1475 LyXParagraph::META_INSET) &&
1476 txt->cursor.par()->GetInset(txt->cursor.pos()) &&
1477 (txt->cursor.par()->GetInset(txt->cursor.pos())->Editable()
1478 == Inset::HIGHLY_EDITABLE))
1480 Inset * tmpinset = txt->cursor.par()->GetInset(txt->cursor.pos());
1481 setMessage(tmpinset->EditMessage());
1482 LyXFont font = txt->GetFont(owner->view()->buffer(),
1485 tmpinset->Edit(owner->view(),
1487 tmpinset->width(owner->view(),font),
1488 tmpinset->descent(owner->view(),font),
1493 txt->CursorRight(owner->view(), false);
1495 owner->view()->text->FinishUndo();
1496 moveCursorUpdate(false);
1502 if (!owner->view()->text->mark_set) owner->view()->beforeChange();
1503 owner->view()->update(BufferView::UPDATE);
1504 owner->view()->text->CursorUp(owner->view());
1505 owner->view()->text->FinishUndo();
1506 moveCursorUpdate(false);
1511 if (!owner->view()->text->mark_set)
1512 owner->view()->beforeChange();
1513 owner->view()->update(BufferView::UPDATE);
1514 owner->view()->text->CursorDown(owner->view());
1515 owner->view()->text->FinishUndo();
1516 moveCursorUpdate(false);
1520 case LFUN_UP_PARAGRAPH:
1521 if (!owner->view()->text->mark_set)
1522 owner->view()->beforeChange();
1523 owner->view()->update(BufferView::UPDATE);
1524 owner->view()->text->CursorUpParagraph(owner->view());
1525 owner->view()->text->FinishUndo();
1526 moveCursorUpdate(false);
1530 case LFUN_DOWN_PARAGRAPH:
1531 if (!owner->view()->text->mark_set)
1532 owner->view()->beforeChange();
1533 owner->view()->update(BufferView::UPDATE);
1534 owner->view()->text->CursorDownParagraph(owner->view());
1535 owner->view()->text->FinishUndo();
1536 moveCursorUpdate(false);
1541 if (!text->mark_set)
1542 owner->view()->beforeChange();
1543 owner->view()->update(BufferView::UPDATE);
1544 owner->view()->cursorPrevious(text);
1545 owner->view()->text->FinishUndo();
1546 if (text->inset_owner)
1547 owner->view()->updateInset(text->inset_owner, false);
1549 moveCursorUpdate(false);
1554 if (!text->mark_set)
1555 owner->view()->beforeChange();
1556 owner->view()->update(BufferView::UPDATE);
1557 owner->view()->cursorNext(text);
1558 owner->view()->text->FinishUndo();
1559 if (text->inset_owner)
1560 owner->view()->updateInset(text->inset_owner, false);
1562 moveCursorUpdate(false);
1567 if (!owner->view()->text->mark_set)
1568 owner->view()->beforeChange();
1569 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1570 owner->view()->text->CursorHome(owner->view());
1571 owner->view()->text->FinishUndo();
1572 moveCursorUpdate(false);
1577 if (!owner->view()->text->mark_set)
1578 owner->view()->beforeChange();
1579 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1580 owner->view()->text->CursorEnd(owner->view());
1581 owner->view()->text->FinishUndo();
1582 moveCursorUpdate(false);
1586 case LFUN_SHIFT_TAB:
1588 if (!owner->view()->text->mark_set)
1589 owner->view()->beforeChange();
1590 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1591 owner->view()->text->CursorTab(owner->view());
1592 owner->view()->text->FinishUndo();
1593 moveCursorUpdate(false);
1597 case LFUN_WORDRIGHT:
1598 if (!text->mark_set)
1599 owner->view()->beforeChange();
1600 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1601 if (text->cursor.par()->isRightToLeftPar(owner->buffer()->params))
1602 text->CursorLeftOneWord(owner->view());
1604 text->CursorRightOneWord(owner->view());
1605 owner->view()->text->FinishUndo();
1606 if (text->inset_owner)
1607 owner->view()->updateInset(text->inset_owner, true);
1608 moveCursorUpdate(false);
1613 if (!text->mark_set)
1614 owner->view()->beforeChange();
1615 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1616 if (text->cursor.par()->isRightToLeftPar(owner->buffer()->params))
1617 text->CursorRightOneWord(owner->view());
1619 text->CursorLeftOneWord(owner->view());
1620 owner->view()->text->FinishUndo();
1621 if (text->inset_owner)
1622 owner->view()->updateInset(text->inset_owner, true);
1623 moveCursorUpdate(false);
1627 case LFUN_BEGINNINGBUF:
1628 if (!owner->view()->text->mark_set)
1629 owner->view()->beforeChange();
1630 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1631 owner->view()->text->CursorTop(owner->view());
1632 owner->view()->text->FinishUndo();
1633 moveCursorUpdate(false);
1638 if (!owner->view()->text->mark_set)
1639 owner->view()->beforeChange();
1640 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1641 owner->view()->text->CursorBottom(owner->view());
1642 owner->view()->text->FinishUndo();
1643 moveCursorUpdate(false);
1648 /* cursor selection ---------------------------- */
1650 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1651 if (owner->view()->text->cursor.par()->isRightToLeftPar(owner->buffer()->params))
1652 owner->view()->text->CursorLeft(owner->view());
1654 owner->view()->text->CursorRight(owner->view());
1655 owner->view()->text->FinishUndo();
1656 moveCursorUpdate(true);
1661 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1662 if (owner->view()->text->cursor.par()->isRightToLeftPar(owner->buffer()->params))
1663 owner->view()->text->CursorRight(owner->view());
1665 owner->view()->text->CursorLeft(owner->view());
1666 owner->view()->text->FinishUndo();
1667 moveCursorUpdate(true);
1672 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1673 owner->view()->text->CursorUp(owner->view());
1674 owner->view()->text->FinishUndo();
1675 moveCursorUpdate(true);
1680 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1681 owner->view()->text->CursorDown(owner->view());
1682 owner->view()->text->FinishUndo();
1683 moveCursorUpdate(true);
1687 case LFUN_UP_PARAGRAPHSEL:
1688 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1689 owner->view()->text->CursorUpParagraph(owner->view());
1690 owner->view()->text->FinishUndo();
1691 moveCursorUpdate(true);
1695 case LFUN_DOWN_PARAGRAPHSEL:
1696 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1697 owner->view()->text->CursorDownParagraph(owner->view());
1698 owner->view()->text->FinishUndo();
1699 moveCursorUpdate(true);
1704 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1705 owner->view()->cursorPrevious(text);
1706 owner->view()->text->FinishUndo();
1707 if (text->inset_owner)
1708 owner->view()->updateInset(text->inset_owner, false);
1710 moveCursorUpdate(true);
1715 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1716 owner->view()->cursorNext(text);
1717 owner->view()->text->FinishUndo();
1718 if (text->inset_owner)
1719 owner->view()->updateInset(text->inset_owner, false);
1721 moveCursorUpdate(true);
1726 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1727 owner->view()->text->CursorHome(owner->view());
1728 owner->view()->text->FinishUndo();
1729 moveCursorUpdate(true);
1734 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1735 owner->view()->text->CursorEnd(owner->view());
1736 owner->view()->text->FinishUndo();
1737 moveCursorUpdate(true);
1741 case LFUN_WORDRIGHTSEL:
1742 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1743 if (owner->view()->text->cursor.par()->isRightToLeftPar(owner->buffer()->params))
1744 owner->view()->text->CursorLeftOneWord(owner->view());
1746 owner->view()->text->CursorRightOneWord(owner->view());
1747 owner->view()->text->FinishUndo();
1748 moveCursorUpdate(true);
1752 case LFUN_WORDLEFTSEL:
1753 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1754 if (owner->view()->text->cursor.par()->isRightToLeftPar(owner->buffer()->params))
1755 owner->view()->text->CursorRightOneWord(owner->view());
1757 owner->view()->text->CursorLeftOneWord(owner->view());
1758 owner->view()->text->FinishUndo();
1759 moveCursorUpdate(true);
1763 case LFUN_BEGINNINGBUFSEL:
1764 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1765 owner->view()->text->CursorTop(owner->view());
1766 owner->view()->text->FinishUndo();
1767 moveCursorUpdate(true);
1771 case LFUN_ENDBUFSEL:
1772 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1773 owner->view()->text->CursorBottom(owner->view());
1774 owner->view()->text->FinishUndo();
1775 moveCursorUpdate(true);
1779 // --- text changing commands ------------------------
1780 case LFUN_BREAKLINE:
1781 owner->view()->beforeChange();
1782 owner->view()->text->InsertChar(owner->view(), LyXParagraph::META_NEWLINE);
1783 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1784 moveCursorUpdate(false);
1787 case LFUN_PROTECTEDSPACE:
1789 LyXLayout const & style =
1790 textclasslist.Style(owner->view()->buffer()->params.textclass,
1791 owner->view()->text->cursor.par()->GetLayout());
1793 if (style.free_spacing) {
1794 owner->view()->text->InsertChar(owner->view(), ' ');
1795 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1797 owner->view()->protectedBlank();
1799 moveCursorUpdate(false);
1804 if (text->mark_set) {
1805 owner->view()->beforeChange();
1806 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1807 setMessage(N_("Mark removed"));
1809 owner->view()->beforeChange();
1811 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1812 setMessage(N_("Mark set"));
1814 text->sel_cursor = text->cursor;
1815 if (text->inset_owner)
1816 owner->view()->updateInset(text->inset_owner, true);
1820 if (!owner->view()->text->selection) {
1821 owner->view()->text->Delete(owner->view());
1822 owner->view()->text->sel_cursor =
1823 owner->view()->text->cursor;
1824 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1825 // It is possible to make it a lot faster still
1826 // just comment out the lone below...
1827 owner->view()->showCursor();
1829 owner->view()->cut();
1831 moveCursorUpdate(false);
1833 owner->view()->setState();
1836 case LFUN_DELETE_SKIP:
1838 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1840 LyXCursor cursor = owner->view()->text->cursor;
1842 if (!owner->view()->text->selection) {
1843 if (cursor.pos() == cursor.par()->Last()) {
1844 owner->view()->text->CursorRight(owner->view());
1845 cursor = owner->view()->text->cursor;
1846 if (cursor.pos() == 0
1847 && !(cursor.par()->added_space_top
1848 == VSpace (VSpace::NONE))) {
1849 owner->view()->text->SetParagraph
1851 cursor.par()->line_top,
1852 cursor.par()->line_bottom,
1853 cursor.par()->pagebreak_top,
1854 cursor.par()->pagebreak_bottom,
1855 VSpace(VSpace::NONE),
1856 cursor.par()->added_space_bottom,
1857 cursor.par()->align,
1858 cursor.par()->labelwidthstring, 0);
1859 owner->view()->text->CursorLeft(owner->view());
1860 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1862 owner->view()->text->CursorLeft(owner->view());
1863 owner->view()->text->Delete(owner->view());
1864 owner->view()->text->sel_cursor =
1865 owner->view()->text->cursor;
1866 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1869 owner->view()->text->Delete(owner->view());
1870 owner->view()->text->sel_cursor =
1871 owner->view()->text->cursor;
1872 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1875 owner->view()->cut();
1880 /* -------> Delete word forward. */
1881 case LFUN_DELETE_WORD_FORWARD:
1882 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1883 text->DeleteWordForward(owner->view());
1884 if (text->inset_owner)
1885 owner->view()->updateInset(text->inset_owner, true);
1886 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1887 moveCursorUpdate(false);
1891 /* -------> Delete word backward. */
1892 case LFUN_DELETE_WORD_BACKWARD:
1893 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1894 text->DeleteWordBackward(owner->view());
1895 if (text->inset_owner)
1896 owner->view()->updateInset(text->inset_owner, true);
1897 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1898 moveCursorUpdate(false);
1902 /* -------> Kill to end of line. */
1903 case LFUN_DELETE_LINE_FORWARD:
1904 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1905 text->DeleteLineForward(owner->view());
1906 if (text->inset_owner)
1907 owner->view()->updateInset(text->inset_owner, true);
1908 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1909 moveCursorUpdate(false);
1912 /* -------> Set mark off. */
1914 owner->view()->beforeChange();
1915 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1916 text->sel_cursor = text->cursor;
1917 setMessage(N_("Mark off"));
1918 if (text->inset_owner)
1919 owner->view()->updateInset(text->inset_owner, true);
1922 /* -------> Set mark on. */
1924 owner->view()->beforeChange();
1925 owner->view()->text->mark_set = 1;
1926 owner->view()->update(BufferView::SELECT|BufferView::FITCUR);
1927 text->sel_cursor = text->cursor;
1928 if (text->inset_owner)
1929 owner->view()->updateInset(text->inset_owner, true);
1930 setMessage(N_("Mark on"));
1933 case LFUN_BACKSPACE:
1935 if (!owner->view()->text->selection) {
1936 if (owner->getIntl()->getTrans()->backspace()) {
1937 owner->view()->text->Backspace(owner->view());
1938 owner->view()->text->sel_cursor =
1939 owner->view()->text->cursor;
1940 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1941 // It is possible to make it a lot faster still
1942 // just comment out the lone below...
1943 owner->view()->showCursor();
1946 owner->view()->cut();
1949 owner->view()->setState();
1953 case LFUN_BACKSPACE_SKIP:
1955 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1957 LyXCursor cursor = owner->view()->text->cursor;
1959 if (!owner->view()->text->selection) {
1960 if (cursor.pos() == 0
1961 && !(cursor.par()->added_space_top
1962 == VSpace (VSpace::NONE))) {
1963 owner->view()->text->SetParagraph
1965 cursor.par()->line_top,
1966 cursor.par()->line_bottom,
1967 cursor.par()->pagebreak_top,
1968 cursor.par()->pagebreak_bottom,
1969 VSpace(VSpace::NONE), cursor.par()->added_space_bottom,
1970 cursor.par()->align,
1971 cursor.par()->labelwidthstring, 0);
1972 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1974 owner->view()->text->Backspace(owner->view());
1975 owner->view()->text->sel_cursor
1977 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1980 owner->view()->cut();
1984 case LFUN_BREAKPARAGRAPH:
1986 owner->view()->beforeChange();
1987 owner->view()->text->BreakParagraph(owner->view(), 0);
1988 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1989 owner->view()->text->sel_cursor =
1990 owner->view()->text->cursor;
1991 owner->view()->setState();
1996 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1998 owner->view()->beforeChange();
1999 owner->view()->text->BreakParagraph(owner->view(), 1);
2000 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2001 owner->view()->text->sel_cursor =
2002 owner->view()->text->cursor;
2003 owner->view()->setState();
2008 case LFUN_BREAKPARAGRAPH_SKIP:
2010 // When at the beginning of a paragraph, remove
2011 // indentation and add a "defskip" at the top.
2012 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2014 LyXCursor cursor = owner->view()->text->cursor;
2016 owner->view()->beforeChange();
2017 if (cursor.pos() == 0) {
2018 if (cursor.par()->added_space_top == VSpace(VSpace::NONE)) {
2019 owner->view()->text->SetParagraph
2021 cursor.par()->line_top,
2022 cursor.par()->line_bottom,
2023 cursor.par()->pagebreak_top,
2024 cursor.par()->pagebreak_bottom,
2025 VSpace(VSpace::DEFSKIP), cursor.par()->added_space_bottom,
2026 cursor.par()->align,
2027 cursor.par()->labelwidthstring, 1);
2028 //owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2032 owner->view()->text->BreakParagraph(owner->view(), 0);
2033 //owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2036 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2037 owner->view()->text->sel_cursor = cursor;
2038 owner->view()->setState();
2043 case LFUN_PARAGRAPH_SPACING:
2045 LyXParagraph * par = owner->view()->text->cursor.par();
2046 Spacing::Space cur_spacing = par->spacing.getSpace();
2047 float cur_value = 1.0;
2048 if (cur_spacing == Spacing::Other) {
2049 cur_value = par->spacing.getValue();
2052 istringstream istr(argument.c_str());
2056 Spacing::Space new_spacing = cur_spacing;
2057 float new_value = cur_value;
2059 lyxerr << "Missing argument to `paragraph-spacing'"
2061 } else if (tmp == "single") {
2062 new_spacing = Spacing::Single;
2063 } else if (tmp == "onehalf") {
2064 new_spacing = Spacing::Onehalf;
2065 } else if (tmp == "double") {
2066 new_spacing = Spacing::Double;
2067 } else if (tmp == "other") {
2068 new_spacing = Spacing::Other;
2071 lyxerr << "new_value = " << tmpval << endl;
2074 } else if (tmp == "default") {
2075 new_spacing = Spacing::Default;
2077 lyxerr << _("Unknown spacing argument: ")
2078 << argument << endl;
2080 if (cur_spacing != new_spacing || cur_value != new_value) {
2081 par->spacing.set(new_spacing, new_value);
2082 owner->view()->text->RedoParagraph(owner->view());
2083 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2089 owner->view()->beforeChange();
2090 owner->view()->text->InsertChar(owner->view(), '\"'); // This " matches the single quote in the code
2091 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2092 moveCursorUpdate(false);
2098 InsetCommandParams p;
2099 if (action == LFUN_HTMLURL)
2100 p.setCmdName("htmlurl");
2102 p.setCmdName("url");
2103 owner->getDialogs()->createUrl( p.getAsString() );
2107 case LFUN_INSERT_URL:
2109 InsetCommandParams p;
2110 p.setFromString( argument );
2112 InsetUrl * inset = new InsetUrl( p );
2113 if (!owner->view()->insertInset(inset))
2116 owner->view()->updateInset( inset, true );
2120 case LFUN_INSET_TEXT:
2122 InsetText * new_inset = new InsetText;
2123 if (owner->view()->insertInset(new_inset))
2124 new_inset->Edit(owner->view(), 0, 0, 0);
2130 case LFUN_INSET_ERT:
2132 InsetERT * new_inset = new InsetERT;
2133 if (owner->view()->insertInset(new_inset))
2134 new_inset->Edit(owner->view(), 0, 0, 0);
2140 case LFUN_INSET_EXTERNAL:
2142 InsetExternal * new_inset = new InsetExternal;
2143 if (owner->view()->insertInset(new_inset))
2144 new_inset->Edit(owner->view(), 0, 0, 0);
2150 case LFUN_INSET_FOOTNOTE:
2152 InsetFoot * new_inset = new InsetFoot;
2153 if (owner->view()->insertInset(new_inset))
2154 new_inset->Edit(owner->view(), 0, 0, 0);
2160 case LFUN_INSET_MARGINAL:
2162 InsetMarginal * new_inset = new InsetMarginal;
2163 if (owner->view()->insertInset(new_inset))
2164 new_inset->Edit(owner->view(), 0, 0, 0);
2170 case LFUN_INSET_MINIPAGE:
2172 InsetMinipage * new_inset = new InsetMinipage;
2173 if (owner->view()->insertInset(new_inset))
2174 new_inset->Edit(owner->view(), 0, 0, 0);
2180 case LFUN_INSET_FLOAT:
2182 // check if the float type exist
2183 if (floatList.typeExist(argument)) {
2184 InsetFloat * new_inset = new InsetFloat(argument);
2185 if (owner->view()->insertInset(new_inset))
2186 new_inset->Edit(owner->view(), 0, 0, 0);
2190 lyxerr << "Non-existant float type: "
2191 << argument << endl;
2197 case LFUN_INSET_LIST:
2199 InsetList * new_inset = new InsetList;
2200 if (owner->view()->insertInset(new_inset))
2201 new_inset->Edit(owner->view(), 0, 0, 0);
2207 case LFUN_INSET_THEOREM:
2209 InsetTheorem * new_inset = new InsetTheorem;
2210 if (owner->view()->insertInset(new_inset))
2211 new_inset->Edit(owner->view(), 0, 0, 0);
2217 case LFUN_INSET_CAPTION:
2219 // Do we have a locking inset...
2220 if (owner->view()->theLockingInset()) {
2221 lyxerr << "Locking inset code: "
2222 << static_cast<int>(owner->view()->theLockingInset()->LyxCode());
2223 InsetCaption * new_inset = new InsetCaption;
2224 new_inset->setOwner(owner->view()->theLockingInset());
2225 new_inset->SetAutoBreakRows(true);
2226 new_inset->SetDrawFrame(0, InsetText::LOCKED);
2227 new_inset->SetFrameColor(0, LColor::footnoteframe);
2228 if (owner->view()->insertInset(new_inset))
2229 new_inset->Edit(owner->view(), 0, 0, 0);
2236 case LFUN_INSET_TABULAR:
2239 if (!argument.empty())
2240 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2241 InsetTabular * new_inset =
2242 new InsetTabular(*owner->buffer(), r, c);
2243 if (owner->view()->insertInset(new_inset))
2244 new_inset->Edit(owner->view(), 0, 0, 0);
2250 // --- lyxserver commands ----------------------------
2252 case LFUN_CHARATCURSOR:
2254 LyXParagraph::size_type pos =
2255 owner->view()->text->cursor.pos();
2256 if (pos < owner->view()->text->cursor.par()->size())
2257 //dispatch_buffer = owner->view()->text->
2258 // cursor.par()->text[pos];
2260 owner->view()->text->
2261 cursor.par()->GetChar(pos);
2263 dispatch_buffer = "EOF";
2269 tostr(owner->view()->text->cursor.x()) + ' '
2270 + tostr(owner->view()->text->cursor.y());
2277 ::sscanf(argument.c_str(), " %d %d", &x, &y);
2278 owner->view()->text->SetCursorFromCoordinates(owner->view(), x, y);
2282 case LFUN_GETLAYOUT:
2284 tostr(owner->view()->text->cursor.par()->layout);
2289 LyXFont & font = owner->view()->text->current_font;
2290 if (font.shape() == LyXFont::ITALIC_SHAPE)
2291 dispatch_buffer = 'E';
2292 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2293 dispatch_buffer = 'N';
2295 dispatch_buffer = '0';
2302 LyXFont & font = owner->view()->text->current_font;
2303 if (font.latex() == LyXFont::ON)
2304 dispatch_buffer = 'L';
2306 dispatch_buffer = '0';
2311 setMessage(owner->buffer()->fileName());
2312 lyxerr.debug() << "FNAME["
2313 << owner->buffer()->fileName()
2321 dispatch_buffer = buf;
2322 lyxserver->notifyClient(dispatch_buffer);
2326 case LFUN_GOTOFILEROW:
2328 char file_name[100];
2330 ::sscanf(argument.c_str(), " %s %d", file_name, &row);
2332 // Must replace extension of the file to be .lyx and get full path
2333 string s = ChangeExtension(string(file_name), ".lyx");
2335 // Either change buffer or load the file
2336 if (bufferlist.exists(s))
2337 owner->view()->buffer(bufferlist.getBuffer(s));
2339 owner->view()->buffer(bufferlist.loadLyXFile(s));
2342 owner->view()->setCursorFromRow(row);
2345 owner->view()->center();
2349 case LFUN_GOTO_PARAGRAPH:
2351 istringstream istr(argument.c_str());
2355 LyXParagraph * par = owner->view()->text->GetParFromID(id);
2358 owner->view()->text->SetCursor(owner->view(), par, 0);
2359 owner->view()->setState();
2363 owner->view()->center();
2370 int const qa = lyxaction.LookupFunc(argument);
2371 setMessage(lyxaction.helpText(static_cast<kb_action>(qa)));
2375 // --- accented characters ---------------------------
2378 case LFUN_CIRCUMFLEX:
2388 case LFUN_SPECIAL_CARON:
2391 case LFUN_HUNG_UMLAUT:
2397 if (keyseq.length == -1 && keyseq.getiso() != 0)
2398 c = keyseq.getiso();
2400 owner->getIntl()->getTrans()->
2401 deadkey(c, get_accent(action).accent,
2402 owner->view()->text);
2404 // Need to reset, in case the minibuffer calls these
2409 // copied verbatim from do_accent_char
2410 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2412 owner->view()->text->sel_cursor =
2413 owner->view()->text->cursor;
2417 // --- toolbar ----------------------------------
2418 case LFUN_PUSH_TOOLBAR:
2420 int nth = strToInt(argument);
2422 setErrorMessage(N_("Push-toolbar needs argument > 0"));
2424 owner->getToolbar()->push(nth);
2429 case LFUN_ADD_TO_TOOLBAR:
2431 if (lyxerr.debugging(Debug::GUI)) {
2432 lyxerr << "LFUN_ADD_TO_TOOLBAR:"
2433 "argument = `" << argument << '\'' << endl;
2435 string tmp(argument);
2436 //lyxerr <<string("Argument: ") + argument);
2437 //lyxerr <<string("Tmp : ") + tmp);
2439 setErrorMessage(N_("Usage: toolbar-add-to <LyX command>"));
2441 owner->getToolbar()->add(argument, false);
2442 owner->getToolbar()->set();
2447 // --- insert characters ----------------------------------------
2449 // --- Mathed stuff. If we are here, there is no locked inset yet.
2454 if (!greek_kb_flag) {
2456 setMessage(N_("Math greek mode on"));
2463 case LFUN_GREEK_TOGGLE:
2465 greek_kb_flag = greek_kb_flag ? 0 : 2;
2466 if (greek_kb_flag) {
2467 setMessage(N_("Math greek keyboard on"));
2469 setMessage(N_("Math greek keyboard off"));
2474 case LFUN_MATH_DELIM:
2475 case LFUN_INSERT_MATRIX:
2477 if (owner->view()->available()) {
2479 open_new_inset(new InsetFormula(false)))
2481 owner->view()->theLockingInset()
2482 ->LocalDispatch(owner->view(),
2490 case LFUN_INSERT_MATH:
2492 math_insert_symbol(argument);
2496 case LFUN_MATH_DISPLAY:
2498 if (owner->view()->available())
2499 owner->view()->open_new_inset(new InsetFormula(true));
2503 case LFUN_MATH_MACRO:
2505 if (owner->view()->available()) {
2508 setErrorMessage(N_("Missing argument"));
2510 string const s1 = token(s, ' ', 1);
2511 int const na = s1.empty() ? 0 : lyx::atoi(s1);
2513 open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2519 case LFUN_MATH_MODE: // Open or create a math inset
2521 if (owner->view()->available())
2522 owner->view()->open_new_inset(new InsetFormula);
2523 setMessage(N_("Math editor mode"));
2527 case LFUN_MATH_NUMBER:
2528 case LFUN_MATH_LIMITS:
2530 setErrorMessage(N_("This is only allowed in math mode!"));
2535 case LFUN_MATH_PANEL:
2537 show_symbols_form(this);
2541 case LFUN_CITATION_CREATE:
2543 InsetCommandParams p( "cite" );
2545 if (!argument.empty()) {
2546 // This should be set at source, ie when typing
2547 // "citation-insert foo" in the minibuffer.
2548 // Question: would pybibliographer also need to be
2549 // changed. Suspect so. Leave as-is therefore.
2550 if (contains(argument, "|")) {
2551 p.setContents( token(argument, '|', 0) );
2552 p.setOptions( token(argument, '|', 1) );
2554 p.setContents( argument );
2556 Dispatch(LFUN_CITATION_INSERT, p.getAsString());
2558 owner->getDialogs()->createCitation( p.getAsString() );
2562 case LFUN_CITATION_INSERT:
2564 InsetCommandParams p;
2565 p.setFromString( argument );
2567 InsetCitation * inset = new InsetCitation( p );
2568 if (!owner->view()->insertInset(inset))
2571 owner->view()->updateInset( inset, true );
2575 case LFUN_INSERT_BIBTEX:
2577 // ale970405+lasgoutt970425
2578 // The argument can be up to two tokens separated
2579 // by a space. The first one is the bibstyle.
2580 string const db = token(argument, ' ', 0);
2581 string bibstyle = token(argument, ' ', 1);
2582 if (bibstyle.empty())
2585 InsetCommandParams p( "BibTeX", db, bibstyle );
2586 InsetBibtex * inset = new InsetBibtex(p);
2588 if (owner->view()->insertInset(inset)) {
2589 if (argument.empty())
2590 inset->Edit(owner->view(), 0, 0, 0);
2596 // BibTeX data bases
2597 case LFUN_BIBDB_ADD:
2599 InsetBibtex * inset =
2600 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2602 inset->addDatabase(argument);
2607 case LFUN_BIBDB_DEL:
2609 InsetBibtex * inset =
2610 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2612 inset->delDatabase(argument);
2617 case LFUN_BIBTEX_STYLE:
2619 InsetBibtex * inset =
2620 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2622 inset->setOptions(argument);
2627 case LFUN_INDEX_CREATE:
2629 InsetCommandParams p( "index" );
2631 if (argument.empty()) {
2632 // Get the word immediately preceding the cursor
2633 LyXParagraph::size_type curpos =
2634 owner->view()->text->cursor.pos() - 1;
2638 curstring = owner->view()->text
2639 ->cursor.par()->GetWord(curpos);
2641 p.setContents( curstring );
2643 p.setContents( argument );
2646 owner->getDialogs()->createIndex( p.getAsString() );
2650 case LFUN_INDEX_INSERT:
2652 InsetCommandParams p;
2653 p.setFromString(argument);
2654 InsetIndex * inset = new InsetIndex(p);
2656 if (!owner->view()->insertInset(inset))
2659 owner->view()->updateInset(inset, true);
2663 case LFUN_INDEX_INSERT_LAST:
2665 // Get word immediately preceding the cursor
2666 LyXParagraph::size_type curpos =
2667 owner->view()->text->cursor.pos() - 1;
2668 // Can't do that at the beginning of a paragraph
2669 if (curpos < 0) break;
2671 string const curstring(owner->view()->text
2672 ->cursor.par()->GetWord(curpos));
2674 InsetCommandParams p("index", curstring);
2675 InsetIndex * inset = new InsetIndex(p);
2677 if (!owner->view()->insertInset(inset))
2680 owner->view()->updateInset(inset, true);
2684 case LFUN_INDEX_PRINT:
2686 InsetCommandParams p("printindex");
2687 Inset * inset = new InsetPrintIndex(p);
2688 if (!owner->view()->insertInset(inset, "Standard", true))
2693 case LFUN_PARENTINSERT:
2695 lyxerr << "arg " << argument << endl;
2696 InsetCommandParams p( "lyxparent", argument );
2697 Inset * inset = new InsetParent(p, *owner->buffer());
2698 if (!owner->view()->insertInset(inset, "Standard", true))
2703 case LFUN_CHILDINSERT:
2705 InsetCommandParams p( "Include", argument );
2706 Inset * inset = new InsetInclude(p, *owner->buffer());
2707 if (owner->view()->insertInset(inset, "Standard", true))
2708 inset->Edit(owner->view(), 0, 0, 0);
2714 case LFUN_CHILDOPEN:
2716 string const filename =
2717 MakeAbsPath(argument,
2718 OnlyPath(owner->buffer()->fileName()));
2719 setMessage(N_("Opening child document ") +
2720 MakeDisplayPath(filename) + "...");
2721 owner->view()->savePosition();
2722 if (bufferlist.exists(filename))
2723 owner->view()->buffer(bufferlist.getBuffer(filename));
2725 owner->view()->buffer(bufferlist.loadLyXFile(filename));
2729 case LFUN_INSERT_NOTE:
2730 owner->view()->insertNote();
2733 case LFUN_INSERTFOOTNOTE:
2735 LyXParagraph::footnote_kind kind;
2736 if (argument == "footnote") {
2737 kind = LyXParagraph::FOOTNOTE;
2738 } else if (argument == "margin") {
2739 kind = LyXParagraph::MARGIN;
2740 } else if (argument == "figure") {
2741 kind = LyXParagraph::FIG;
2742 } else if (argument == "table") {
2743 kind = LyXParagraph::TAB;
2744 } else if (argument == "wide-fig") {
2745 kind = LyXParagraph::WIDE_FIG;
2746 } else if (argument == "wide-tab") {
2747 kind = LyXParagraph::WIDE_TAB;
2748 } else if (argument == "algorithm") {
2749 kind = LyXParagraph::ALGORITHM;
2751 setErrorMessage(N_("Unknown kind of footnote"));
2754 owner->view()->text->InsertFootnoteEnvironment(owner->view(), kind);
2755 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2756 owner->view()->setState();
2760 case LFUN_TOGGLECURSORFOLLOW:
2761 lyxrc.cursor_follows_scrollbar = !lyxrc.cursor_follows_scrollbar;
2764 case LFUN_KMAP_OFF: // keymap off
2765 owner->getIntl()->KeyMapOn(false);
2768 case LFUN_KMAP_PRIM: // primary keymap
2769 owner->getIntl()->KeyMapPrim();
2772 case LFUN_KMAP_SEC: // secondary keymap
2773 owner->getIntl()->KeyMapSec();
2776 case LFUN_KMAP_TOGGLE: // toggle keymap
2777 owner->getIntl()->ToggleKeyMap();
2780 case LFUN_SELFINSERT:
2782 LyXFont const old_font(owner->view()->text->real_current_font);
2783 for (string::size_type i = 0; i < argument.length(); ++i) {
2784 owner->view()->text->InsertChar(owner->view(), argument[i]);
2785 // This needs to be in the loop, or else we
2786 // won't break lines correctly. (Asger)
2787 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2789 owner->view()->text->sel_cursor =
2790 owner->view()->text->cursor;
2791 moveCursorUpdate(false);
2793 // real_current_font.number can change so we need to
2794 // update the minibuffer
2795 if (old_font != owner->view()->text->real_current_font)
2802 // argument contains ';'-terminated commands
2803 while (argument.find(';') != string::npos) {
2805 argument = split(argument, first, ';');
2811 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
2815 time_t now_time_t = time(NULL);
2816 now_tm = localtime(&now_time_t);
2817 setlocale(LC_TIME, "");
2819 if (!argument.empty())
2822 arg = lyxrc.date_insert_format;
2824 int const datetmp_len =
2825 ::strftime(datetmp, 32, arg.c_str(), now_tm);
2826 for (int i = 0; i < datetmp_len; i++) {
2827 owner->view()->text->InsertChar(owner->view(), datetmp[i]);
2828 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2831 owner->view()->text->sel_cursor = owner->view()->text->cursor;
2832 moveCursorUpdate(false);
2836 case LFUN_DIALOG_PREFERENCES:
2837 owner->getDialogs()->showPreferences();
2840 case LFUN_SAVEPREFERENCES:
2842 Path p(user_lyxdir);
2843 lyxrc.write("preferences");
2847 case LFUN_SCREEN_FONT_UPDATE:
2849 // handle the screen font changes.
2851 lyxrc.set_font_norm_type();
2852 fontloader.update();
2853 // Of course we should only do the resize and the textcache.clear
2854 // if values really changed...but not very important right now. (Lgb)
2855 // All buffers will need resize
2856 bufferlist.resize();
2857 // We also need to empty the textcache so that
2858 // the buffer will be formatted correctly after
2864 case LFUN_SET_COLOR:
2867 string const x11_name = split(argument, lyx_name, ' ');
2868 if (lyx_name.empty() || x11_name.empty()) {
2870 setErrorMessage(N_("Syntax: set-color <lyx_name>"
2875 if (!lcolor.setColor(lyx_name, x11_name)) {
2876 static string const err1 (N_("Set-color \""));
2877 static string const err2 (
2878 N_("\" failed - color is undefined "
2879 "or may not be redefined"));
2881 setErrorMessage(_(err1) + lyx_name + _(err2));
2884 lyxColorHandler->updateColor(lcolor.getFromLyXName(lyx_name));
2885 owner->view()->redraw();
2889 case LFUN_UNKNOWN_ACTION:
2891 if (!owner->buffer()) {
2893 setErrorMessage(N_("No document open"));
2897 if (owner->buffer()->isReadonly()) {
2899 setErrorMessage(N_("Document is read only"));
2903 if (!argument.empty()) {
2905 /* Automatically delete the currently selected
2906 * text and replace it with what is being
2907 * typed in now. Depends on lyxrc settings
2908 * "auto_region_delete", which defaults to
2911 if (lyxrc.auto_region_delete) {
2912 if (owner->view()->text->selection){
2913 owner->view()->text->CutSelection(owner->view(), false);
2914 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2918 owner->view()->beforeChange();
2919 LyXFont const old_font(owner->view()->text->real_current_font);
2920 for (string::size_type i = 0;
2921 i < argument.length(); ++i) {
2922 if (greek_kb_flag) {
2923 if (!math_insert_greek(argument[i]))
2924 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2926 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2929 owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2931 owner->view()->text->sel_cursor =
2932 owner->view()->text->cursor;
2933 moveCursorUpdate(false);
2935 // real_current_font.number can change so we need to
2936 // update the minibuffer
2937 if (old_font != owner->view()->text->real_current_font)
2941 // why is an "Unknown action" with empty
2942 // argument even dispatched in the first
2943 // place? I`ll probably change that. (Lgb)
2945 setErrorMessage(N_("Unknown action"));
2951 lyxerr << "A truly unknown func!" << endl;
2956 string const res = getMessage();
2959 if (!commandshortcut.empty()) {
2960 string const newbuf =
2961 owner->getMiniBuffer()->GetText();
2962 if (newbuf != commandshortcut) {
2963 owner->getMiniBuffer()->Set(newbuf
2971 msg += commandshortcut;
2972 owner->getMiniBuffer()->Set(msg);
2979 void LyXFunc::setupLocalKeymap()
2981 keyseq.stdmap = keyseq.curmap = toplevel_keymap;
2982 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap;
2986 void LyXFunc::MenuNew(bool fromTemplate)
2988 string initpath = lyxrc.document_path;
2991 if (owner->view()->available()) {
2992 string const trypath = owner->buffer()->filepath;
2993 // If directory is writeable, use this as default.
2994 if (IsDirWriteable(trypath) == 1)
2998 static int newfile_number = 0;
3001 if (lyxrc.new_ask_filename) {
3002 ProhibitInput(owner->view());
3003 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
3004 fileDlg.SetButton(1, _("Templates"), lyxrc.template_path);
3005 string fname = fileDlg.Select(_("Enter Filename for new document"),
3006 initpath, "*.lyx", _("newfile"));
3007 AllowInput(owner->view());
3009 if (fname.empty()) {
3010 owner->getMiniBuffer()->Set(_("Canceled."));
3011 lyxerr.debug() << "New Document Cancelled." << endl;
3015 // get absolute path of file and make sure the filename ends
3017 s = MakeAbsPath(fname);
3018 if (!IsLyXFilename(s))
3021 // Check if the document already is open
3022 if (bufferlist.exists(s)) {
3023 switch (AskConfirmation(_("Document is already open:"),
3024 MakeDisplayPath(s, 50),
3025 _("Do you want to close that document now?\n"
3026 "('No' will just switch to the open version)")))
3028 case 1: // Yes: close the document
3029 if (!bufferlist.close(bufferlist.getBuffer(s)))
3030 // If close is canceled, we cancel here too.
3033 case 2: // No: switch to the open document
3034 owner->view()->buffer(bufferlist.getBuffer(s));
3036 case 3: // Cancel: Do nothing
3037 owner->getMiniBuffer()->Set(_("Canceled."));
3041 // Check whether the file already exists
3042 if (IsLyXFilename(s)) {
3044 if (fi.readable() &&
3045 AskQuestion(_("File already exists:"),
3046 MakeDisplayPath(s, 50),
3047 _("Do you want to open the document?"))) {
3049 owner->getMiniBuffer()->Set(_("Opening document"),
3050 MakeDisplayPath(s), "...");
3051 XFlush(fl_get_display());
3052 owner->view()->buffer(
3053 bufferlist.loadLyXFile(s));
3054 owner->getMiniBuffer()->Set(_("Document"),
3061 s = AddName(lyxrc.document_path,
3062 "newfile" + tostr(++newfile_number) + ".lyx");
3064 while (bufferlist.exists(s) || fi.readable()) {
3066 s = AddName(lyxrc.document_path,
3067 "newfile" + tostr(newfile_number) +
3073 // The template stuff
3076 ProhibitInput(owner->view());
3077 string const fname = fileDlg.Select(_("Choose template"),
3078 lyxrc.template_path,
3080 AllowInput(owner->view());
3081 if (fname.empty()) return;
3085 // find a free buffer
3086 lyxerr.debug() << "Find a free buffer." << endl;
3087 owner->view()->buffer(bufferlist.newFile(s, templname));
3091 void LyXFunc::MenuOpen()
3093 string initpath = lyxrc.document_path;
3096 if (owner->view()->available()) {
3097 string const trypath = owner->buffer()->filepath;
3098 // If directory is writeable, use this as default.
3099 if (IsDirWriteable(trypath) == 1)
3104 ProhibitInput(owner->view());
3105 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
3106 fileDlg.SetButton(1, _("Examples"),
3107 AddPath(system_lyxdir, "examples"));
3108 string filename = fileDlg.Select(_("Select Document to Open"),
3110 AllowInput(owner->view());
3112 // check selected filename
3113 if (filename.empty()) {
3114 owner->getMiniBuffer()->Set(_("Canceled."));
3118 // get absolute path of file and make sure the filename ends
3120 filename = MakeAbsPath(filename);
3121 if (!IsLyXFilename(filename))
3125 owner->getMiniBuffer()->Set(_("Opening document"),
3126 MakeDisplayPath(filename), "...");
3127 Buffer * openbuf = bufferlist.loadLyXFile(filename);
3129 owner->view()->buffer(openbuf);
3130 owner->getMiniBuffer()->Set(_("Document"),
3131 MakeDisplayPath(filename),
3134 owner->getMiniBuffer()->Set(_("Could not open document"),
3135 MakeDisplayPath(filename));
3140 // checks for running without gui are missing.
3141 void LyXFunc::doImport(string const & argument)
3144 string filename = split(argument, format, ' ');
3145 lyxerr.debug() << "LyXFunc::doImport: " << format
3146 << " file: " << filename << endl;
3148 if (filename.empty()) { // need user interaction
3149 string initpath = lyxrc.document_path;
3152 if (owner->view()->available()) {
3153 string const trypath = owner->buffer()->filepath;
3154 // If directory is writeable, use this as default.
3155 if (IsDirWriteable(trypath) == 1)
3160 ProhibitInput(owner->view());
3161 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
3162 fileDlg.SetButton(1, _("Examples"),
3163 AddPath(system_lyxdir, "examples"));
3164 string const text = _("Select ") + formats.PrettyName(format)
3165 + _(" file to import");
3166 string const extension = "*." + formats.Extension(format);
3167 filename = fileDlg.Select(text, initpath, extension);
3168 AllowInput(owner->view());
3170 // check selected filename
3171 if (filename.empty())
3172 owner->getMiniBuffer()->Set(_("Canceled."));
3175 // still no filename? abort
3176 if (filename.empty())
3179 // get absolute path of file
3180 filename = MakeAbsPath(filename);
3182 string const lyxfile = ChangeExtension(filename, ".lyx");
3184 // Check if the document already is open
3185 if (bufferlist.exists(lyxfile)) {
3186 switch (AskConfirmation(_("Document is already open:"),
3187 MakeDisplayPath(lyxfile, 50),
3188 _("Do you want to close that document now?\n"
3189 "('No' will just switch to the open version)")))
3191 case 1: // Yes: close the document
3192 if (!bufferlist.close(bufferlist.getBuffer(lyxfile)))
3193 // If close is canceled, we cancel here too.
3196 case 2: // No: switch to the open document
3197 owner->view()->buffer(bufferlist.getBuffer(lyxfile));
3199 case 3: // Cancel: Do nothing
3200 owner->getMiniBuffer()->Set(_("Canceled."));
3205 // Check if a LyX document by the same root exists in filesystem
3206 FileInfo const f(lyxfile, true);
3207 if (f.exist() && !AskQuestion(_("A document by the name"),
3208 MakeDisplayPath(lyxfile),
3209 _("already exists. Overwrite?"))) {
3210 owner->getMiniBuffer()->Set(_("Canceled."));
3213 // filename should be valid now
3215 Importer::Import(owner, filename, format);
3219 void LyXFunc::MenuInsertLyXFile(string const & filen)
3221 string filename = filen;
3223 if (filename.empty()) {
3224 // Launch a file browser
3225 string initpath = lyxrc.document_path;
3228 if (owner->view()->available()) {
3229 string const trypath = owner->buffer()->filepath;
3230 // If directory is writeable, use this as default.
3231 if (IsDirWriteable(trypath) == 1)
3236 ProhibitInput(owner->view());
3237 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
3238 fileDlg.SetButton(1, _("Examples"),
3239 AddPath(system_lyxdir, "examples"));
3240 filename = fileDlg.Select(_("Select Document to Insert"),
3242 AllowInput(owner->view());
3244 // check selected filename
3245 if (filename.empty()) {
3246 owner->getMiniBuffer()->Set(_("Canceled."));
3251 // get absolute path of file and make sure the filename ends
3253 filename = MakeAbsPath(filename);
3254 if (!IsLyXFilename(filename))
3258 owner->getMiniBuffer()->Set(_("Inserting document"),
3259 MakeDisplayPath(filename), "...");
3260 bool const res = owner->view()->insertLyXFile(filename);
3262 owner->getMiniBuffer()->Set(_("Document"),
3263 MakeDisplayPath(filename),
3266 owner->getMiniBuffer()->Set(_("Could not insert document"),
3267 MakeDisplayPath(filename));
3272 void LyXFunc::reloadBuffer()
3274 string const fn = owner->buffer()->fileName();
3275 if (bufferlist.close(owner->buffer()))
3276 owner->view()->buffer(bufferlist.loadLyXFile(fn));
3280 void LyXFunc::CloseBuffer()
3282 if (bufferlist.close(owner->buffer()) && !quitting) {
3283 if (bufferlist.empty()) {
3284 // need this otherwise SEGV may occur while trying to
3285 // set variables that don't exist
3286 // since there's no current buffer
3287 owner->getDialogs()->hideBufferDependent();
3289 owner->view()->buffer(bufferlist.first());
3295 Inset * LyXFunc::getInsetByCode(Inset::Code code)
3297 LyXCursor cursor = owner->view()->text->cursor;
3298 Buffer * buffer = owner->view()->buffer();
3299 Buffer::inset_iterator it =
3300 find_if(Buffer::inset_iterator(cursor.par(),
3302 buffer->inset_iterator_end(),
3303 compare_memfun(&Inset::LyxCode, code));
3304 return it != buffer->inset_iterator_end() ? (*it) : 0;
3308 // Each "owner" should have it's own message method. lyxview and
3309 // the minibuffer would use the minibuffer, but lyxserver would
3310 // send an ERROR signal to its client. Alejandro 970603
3311 // This func is bit problematic when it comes to NLS, to make the
3312 // lyx servers client be language indepenent we must not translate
3313 // strings sent to this func.
3314 void LyXFunc::setErrorMessage(string const & m) const
3316 dispatch_buffer = m;
3321 void LyXFunc::setMessage(string const & m)
3323 dispatch_buffer = m;