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 * ====================================================== */
15 using std::istringstream;
28 #pragma implementation
31 #include "lyxlookup.h"
34 #include "bufferlist.h"
35 #include "lyxserver.h"
40 #include "LyXAction.h"
41 #include "insets/inseturl.h"
42 #include "insets/insetlatexaccent.h"
43 #include "insets/insettoc.h"
44 #include "insets/insetlof.h"
45 #include "insets/insetloa.h"
46 #include "insets/insetlot.h"
47 #include "insets/insetref.h"
48 #include "insets/insetparent.h"
49 #include "insets/insetindex.h"
50 #include "insets/insetinclude.h"
51 #include "insets/insetbib.h"
52 #include "insets/insettext.h"
53 #include "insets/insetert.h"
54 #include "insets/insetgraphics.h"
55 #include "insets/insetfoot.h"
56 #include "insets/insettabular.h"
57 #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"
74 #include "trans_mgr.h"
75 #include "ImportLaTeX.h"
76 #include "ImportNoweb.h"
81 #include "bufferview_funcs.h"
86 extern bool cursor_follows_scrollbar;
88 extern void InsertAsciiFile(BufferView *, string const &, bool);
89 extern void math_insert_symbol(char const *);
90 extern Bool math_insert_greek(char const); // why "Bool"?
91 extern BufferList bufferlist;
92 extern LyXServer * lyxserver;
93 extern short greek_kb_flag;
94 extern FD_form_toc * fd_form_toc;
95 extern bool selection_possible;
97 extern kb_keymap * toplevel_keymap;
99 extern void MenuWrite(Buffer *);
100 extern void MenuWriteAs(Buffer *);
101 extern int MenuRunLaTeX(Buffer *);
102 extern int MenuBuildProg(Buffer *);
103 extern int MenuRunChktex(Buffer *);
104 extern bool CreatePostscript(Buffer *, bool);
105 extern void MenuPrint(Buffer *);
106 extern void MenuSendto();
107 extern void QuitLyX();
108 extern void MenuFax(Buffer *);
109 extern void MenuExport(Buffer *, string const &);
111 #define XFORMS_CLIPBOARD 1
113 #ifndef XFORMS_CLIPBOARD
114 extern void MenuPasteSelection(char at);
117 extern LyXAction lyxaction;
119 extern tex_accent_struct get_accent(kb_action action);
121 extern void AutoSave(BufferView *);
122 extern void SetUpdateTimer(float timer = 0.3);
123 extern void FreeUpdateTimer();
124 extern bool PreviewDVI(Buffer *);
125 extern bool PreviewPostscript(Buffer *);
126 extern void MenuInsertLabel(char const *);
127 extern void MenuInsertRef();
128 extern void MenuLayoutCharacter();
129 extern void MenuLayoutParagraph();
130 extern void MenuLayoutDocument();
131 extern void MenuLayoutPaper();
132 extern void MenuLayoutTable(int flag);
133 extern void MenuLayoutQuotes();
134 extern void MenuLayoutPreamble();
135 extern void MenuLayoutSave();
136 extern void bulletForm();
138 extern Buffer * NewLyxFile(string const &);
139 extern void LoadLyXFile(string const &);
140 extern void Reconfigure(BufferView *);
142 extern LyXTextClass::size_type current_layout;
143 extern int getISOCodeFromLaTeX(char *);
145 extern void ShowLatexLog();
147 /* === globals =========================================================== */
149 bool LyXFunc::show_sc = true;
152 LyXFunc::LyXFunc(LyXView * o)
156 lyx_dead_action = LFUN_NOACTION;
157 lyx_calling_dead_action = LFUN_NOACTION;
162 // I changed this func slightly. I commented out the ...FinishUndo(),
163 // this means that all places that used to have a moveCursorUpdate, now
164 // have a ...FinishUndo() as the preceeding statement. I have also added
165 // a moveCursorUpdate to some of the functions that updated the cursor, but
166 // that did not show its new position.
168 void LyXFunc::moveCursorUpdate(bool selecting)
170 if (selecting || owner->view()->text->mark_set) {
171 owner->view()->text->SetSelection();
172 owner->view()->toggleToggle();
173 //owner->view()->update(0);
175 //owner->view()->update(-2); // this IS necessary
178 owner->view()->update(0);
179 owner->view()->showCursor();
181 /* ---> Everytime the cursor is moved, show the current font state. */
182 // should this too me moved out of this func?
183 //owner->getMiniBuffer()->Set(CurrentState());
184 owner->view()->setState();
188 int LyXFunc::processKeyEvent(XEvent * ev)
192 XKeyEvent * keyevent = &ev->xkey;
193 KeySym keysym_return;
195 int num_bytes = LyXLookupString(ev, s_r, 10, &keysym_return);
196 s_r[num_bytes] = '\0';
198 if (lyxerr.debugging(Debug::KEY)) {
199 char * tmp = XKeysymToString(keysym_return);
200 string stm = (tmp ? tmp : "");
201 lyxerr << "KeySym is "
204 << keysym_return << "]"
205 << " and num_bytes is "
207 << " the string returned is \""
208 << s_r << '\"' << endl;
210 // Do nothing if we have nothing (JMarc)
211 if (num_bytes == 0 && keysym_return == NoSymbol) {
212 lyxerr[Debug::KEY] << "Empty kbd action (probably composing)"
217 // this function should be used always [asierra060396]
218 UpdatableInset * tli = owner->view()->the_locking_inset;
219 if (owner->view()->available() && tli && (keysym_return==XK_Escape)) {
220 if (tli == tli->GetLockingInset()) {
221 owner->view()->unlockInset(tli);
222 owner->view()->text->CursorRight();
223 moveCursorUpdate(false);
224 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
226 tli->UnlockInsetInInset(owner->view(),
227 tli->GetLockingInset());
232 // Can we be sure that this will work for all X-Windows
233 // implementations? (Lgb)
234 // This code snippet makes lyx ignore some keys. Perhaps
235 // all of them should be explictly mentioned?
236 if((keysym_return >= XK_Shift_L && keysym_return <= XK_Hyper_R)
237 || keysym_return == XK_Mode_switch || keysym_return == 0x0)
240 // Do a one-deep top-level lookup for
241 // cancel and meta-fake keys. RVDK_PATCH_5
242 cancel_meta_seq.reset();
244 int action = cancel_meta_seq.addkey(keysym_return, keyevent->state
245 &(ShiftMask|ControlMask
248 // When not cancel or meta-fake, do the normal lookup.
249 // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
250 // Mostly, meta_fake_bit = 0. RVDK_PATCH_5.
251 if ( (action != LFUN_CANCEL) && (action != LFUN_META_FAKE) ) {
253 // remove Caps Lock and Mod2 as a modifiers
254 action = keyseq.addkey(keysym_return,
255 (keyevent->state | meta_fake_bit)
256 &(ShiftMask|ControlMask
259 // Dont remove this unless you know what you are doing.
262 if (action == 0) action = LFUN_PREFIX;
264 if (lyxerr.debugging(Debug::KEY)) {
270 << num_bytes << "]" << endl;
273 // already here we know if it any point in going further
274 // why not return already here if action == -1 and
275 // num_bytes == 0? (Lgb)
277 if(keyseq.length > 1 || keyseq.length < -1) {
280 owner->getMiniBuffer()->Set(buf);
284 if (keyseq.length < -1) { // unknown key sequence...
288 owner->getMiniBuffer()->Set(_("Unknown sequence:"), buf);
292 char isochar = keyseq.getiso();
293 if (!(keyevent->state&ControlMask) &&
294 !(keyevent->state&Mod1Mask) &&
295 (isochar && keysym_return < 0xF000)) {
298 if (argument.empty()) {
299 lyxerr.debug() << "Empty argument!" << endl;
300 // This can`t possibly be of any use
301 // so we`ll skip the dispatch.
305 if (action == LFUN_SELFINSERT) {
309 bool tmp_sc = show_sc;
311 Dispatch(action, argument.c_str());
318 LyXFunc::func_status LyXFunc::getStatus(int ac) const
321 func_status flag = LyXFunc::OK;
323 Buffer * buf = owner->buffer();
325 if (lyxaction.isPseudoAction(ac))
326 action = lyxaction.retrieveActionArg(ac, argument);
328 action = static_cast<kb_action>(ac);
330 if (action == LFUN_UNKNOWN_ACTION) {
331 setErrorMessage(N_("Unknown action"));
332 return LyXFunc::Unknown;
335 // Check whether we need a buffer
336 if (!lyxaction.funcHasFlag(action, LyXAction::NoBuffer)) {
337 // Yes we need a buffer, do we have one?
340 // Can we use a readonly buffer?
341 if (buf->isReadonly() &&
342 !lyxaction.funcHasFlag(action,
343 LyXAction::ReadOnly)) {
345 setErrorMessage(N_("Document is read-only"));
346 flag |= LyXFunc::Disabled;
350 setErrorMessage(N_("Command not allowed with"
351 "out any document open"));
352 flag |= LyXFunc::Disabled;
356 if (flag & LyXFunc::Disabled)
359 // I would really like to avoid having this switch and rather try to
360 // encode this in the function itself.
361 static bool noLaTeX = lyxrc.latex_command == "none";
362 bool disable = false;
365 disable = noLaTeX || lyxrc.view_dvi_command == "none";
368 disable = noLaTeX || lyxrc.view_ps_command == "none";
375 disable = noLaTeX || lyxrc.print_command == "none";
378 disable = noLaTeX || lyxrc.fax_command == "none";
381 if (argument == "latex")
382 disable = lyxrc.relyx_command == "none";
383 if (argument == "linuxdoc")
384 disable = lyxrc.linuxdoc_to_lyx_command == "none";
387 if (argument == "dvi" || argument == "postscript")
389 if (argument == "html")
390 disable = lyxrc.html_command == "none";
391 if (argument == "html-linuxdoc")
392 disable = lyxrc.linuxdoc_to_html_command == "none";
393 if (argument == "html-docbook")
394 disable = lyxrc.docbook_to_html_command == "none";
397 disable = buf->undostack.empty();
400 disable = buf->redostack.empty();
402 case LFUN_SPELLCHECK:
403 disable = lyxrc.isp_command == "none";
406 disable = lyxrc.chktex_command == "none";
408 case LFUN_LAYOUT_TABLE:
409 disable = ! owner->view()->text->cursor.par->table;
415 flag |= LyXFunc::Disabled;
418 func_status box = LyXFunc::ToggleOff;
419 LyXFont font = owner->view()->text->real_current_font;
422 if (font.emph() == LyXFont::ON)
423 box = LyXFunc::ToggleOn;
426 if (font.noun() == LyXFont::ON)
427 box = LyXFunc::ToggleOn;
430 if (font.series() == LyXFont::BOLD_SERIES)
431 box = LyXFunc::ToggleOn;
434 if (font.latex() == LyXFont::ON)
435 box = LyXFunc::ToggleOn;
448 string LyXFunc::Dispatch(string const & s)
450 // Split command string into command and argument
451 string cmd, line = frontStrip(s);
452 string arg = strip(frontStrip(split(line, cmd, ' ')));
454 return Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
458 string LyXFunc::Dispatch(int ac,
459 char const * do_not_use_this_arg)
464 // we have not done anything wrong yet.
466 dispatch_buffer.erase();
468 // if action is a pseudo-action, we need the real action
469 if (lyxaction.isPseudoAction(ac)) {
471 action = static_cast<kb_action>
472 (lyxaction.retrieveActionArg(ac, tmparg));
476 action = static_cast<kb_action>(ac);
477 if (do_not_use_this_arg)
478 argument = do_not_use_this_arg; // except here
481 selection_possible = false;
483 if (owner->view()->available())
484 owner->view()->hideCursor();
486 // We cannot use this function here
487 if (getStatus(action) & Disabled)
488 goto exit_with_message;
490 commandshortcut.erase();
492 if (lyxrc.display_shortcuts && show_sc) {
493 if (action != LFUN_SELFINSERT) {
494 // Put name of command and list of shortcuts
495 // for it in minibuffer
496 string comname = lyxaction.getActionName(action);
498 int pseudoaction = action;
499 bool argsadded = false;
501 if (!argument.empty()) {
502 // If we have the command with argument,
505 lyxaction.searchActionArg(action,
508 if (pseudoaction == -1) {
509 pseudoaction = action;
511 comname += " " + argument;
516 string shortcuts = toplevel_keymap->findbinding(pseudoaction);
518 if (!shortcuts.empty()) {
519 comname += ": " + shortcuts;
520 } else if (!argsadded) {
521 comname += " " + argument;
524 if (!comname.empty()) {
525 comname = strip(comname);
526 commandshortcut = "(" + comname + ')';
527 owner->getMiniBuffer()->Set(commandshortcut);
528 // Here we could even add a small pause,
529 // to annoy the user and make him learn
531 // No! That will just annoy, not teach
532 // anything. The user will read the messages
533 // if they are interested. (Asger)
538 // If in math mode pass the control to
539 // the math inset [asierra060396]
540 if (owner->view()->available() &&
541 owner->view()->the_locking_inset) {
542 UpdatableInset::RESULT result;
544 || (action == LFUN_UNKNOWN_ACTION
545 && keyseq.length >= -1)) {
546 if (action == LFUN_UNKNOWN_ACTION
547 && argument.empty()) {
548 argument = keyseq.getiso();
550 // Undo/Redo pre 0.13 is a bit tricky for insets.
551 if (action == LFUN_UNDO) {
553 UpdatableInset * inset =
554 owner->view()->the_locking_inset;
555 inset->GetCursorPos(slx, sly);
556 owner->view()->unlockInset(inset);
557 owner->view()->menuUndo();
558 if (owner->view()->text->cursor.par->
559 IsInset(owner->view()->text->cursor.pos)) {
560 inset = static_cast<UpdatableInset*>(
561 owner->view()->text->cursor.par->
562 GetInset(owner->view()->text->
568 inset->Edit(owner->view(),slx,sly,0);
570 } else if (action == LFUN_REDO) {
572 UpdatableInset * inset = owner->view()->
574 inset->GetCursorPos(slx, sly);
575 owner->view()->unlockInset(inset);
576 owner->view()->menuRedo();
577 inset = static_cast<UpdatableInset*>(
578 owner->view()->text->cursor.par->
579 GetInset(owner->view()->text->
582 inset->Edit(owner->view(),slx,sly,0);
584 } else if (((result=owner->view()->the_locking_inset->
585 LocalDispatch(owner->view(), action,
587 UpdatableInset::DISPATCHED) ||
588 (result == UpdatableInset::DISPATCHED_NOUPDATE))
591 setMessage(N_("Text mode"));
593 case LFUN_UNKNOWN_ACTION:
594 case LFUN_BREAKPARAGRAPH:
596 owner->view()->text->CursorRight();
597 owner->view()->setState();
598 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
601 if (!owner->view()->text->cursor.par->isRightToLeftPar()) {
602 owner->view()->text->CursorRight();
603 moveCursorUpdate(false);
604 owner->getMiniBuffer()->
605 Set(CurrentState(owner->view()));
609 if (owner->view()->text->cursor.par->isRightToLeftPar()) {
610 owner->view()->text->CursorRight();
611 moveCursorUpdate(false);
612 owner->getMiniBuffer()->
613 Set(CurrentState(owner->view()));
617 owner->view()->text->CursorDown();
618 moveCursorUpdate(false);
619 owner->getMiniBuffer()->
620 Set(CurrentState(owner->view()));
630 // --- Misc -------------------------------------------
631 case LFUN_WORDFINDFORWARD :
632 case LFUN_WORDFINDBACKWARD : {
633 static string last_search;
634 string searched_string;
636 if (!argument.empty()) {
637 last_search = argument;
638 searched_string = argument;
640 searched_string = last_search;
643 LyXText * ltCur = owner->view()->text ;
645 if (!searched_string.empty() &&
646 ((action == LFUN_WORDFINDBACKWARD) ?
647 ltCur->SearchBackward(searched_string.c_str()) :
648 ltCur->SearchForward(searched_string.c_str()))) {
650 // ??? What is that ???
651 owner->view()->update(-2);
654 // clear the selection (if there is any)
655 owner->view()->toggleSelection();
656 owner->view()->text->ClearSelection();
658 // Move cursor so that successive C-s 's will not stand in place.
659 if( action == LFUN_WORDFINDFORWARD )
660 owner->view()->text->CursorRightOneWord();
661 owner->view()->text->FinishUndo();
662 moveCursorUpdate(false);
665 // set the new selection
666 // SetSelectionOverLenChars(owner->view()->currentBuffer()->text, iLenSelected);
667 owner->view()->toggleSelection(false);
671 // REMOVED : if (owner->view()->getWorkArea()->focus)
672 owner->view()->showCursor();
678 if (owner->view()->available()) {
679 owner->view()->update(-2);
682 keyseq.print(buf, true);
683 owner->getMiniBuffer()->Set(buf, string(), string(), 1);
687 // --- Misc -------------------------------------------
688 case LFUN_EXEC_COMMAND:
689 owner->getMiniBuffer()->ExecCommand();
692 case LFUN_CANCEL: // RVDK_PATCH_5
695 if(owner->view()->available())
696 // cancel any selection
697 Dispatch(LFUN_MARK_OFF, 0);
698 setMessage(N_("Cancel"));
701 case LFUN_META_FAKE: // RVDK_PATCH_5
703 meta_fake_bit = Mod1Mask;
705 keyseq.print(buf, true);
706 string res = string("M-") + buf;
707 setMessage(buf); // RVDK_PATCH_5
711 case LFUN_READ_ONLY_TOGGLE:
712 if (owner->buffer()->lyxvc.inUse()) {
713 owner->buffer()->lyxvc.toggleReadOnly();
715 owner->buffer()->setReadonly(
716 !owner->buffer()->isReadonly());
720 case LFUN_CENTER: // this is center and redraw.
721 owner->view()->center();
725 if (owner->view()->available()) {
726 owner->view()->text->toggleAppendix();
727 owner->view()->update(1);
731 // --- Menus -----------------------------------------------
736 case LFUN_MENUNEWTMPLT:
744 case LFUN_CLOSEBUFFER:
749 owner->getMiniBuffer()->Set(_("Saving document"),
750 MakeDisplayPath(owner->buffer()->fileName()),
752 MenuWrite(owner->buffer());
753 //owner->getMiniBuffer()-> {
754 // Set(_("Document saved as"),
755 // MakeDisplayPath(owner->buffer()->fileName()));
757 //owner->getMiniBuffer()->Set(_("Save failed!"));
761 case LFUN_MENUWRITEAS:
762 MenuWriteAs(owner->buffer());
765 case LFUN_MENURELOAD:
770 PreviewDVI(owner->buffer());
774 PreviewPostscript(owner->buffer());
778 MenuRunLaTeX(owner->buffer());
782 MenuBuildProg(owner->buffer());
786 MenuRunChktex(owner->buffer());
790 CreatePostscript(owner->buffer(), false);
794 MenuPrint(owner->buffer());
798 MenuFax(owner->buffer());
802 MenuExport(owner->buffer(), argument);
818 Buffer::TocType type = Buffer::TOC_TOC;
819 if (action == LFUN_LOFVIEW)
820 type = Buffer::TOC_LOF;
821 else if (action == LFUN_LOTVIEW)
822 type = Buffer::TOC_LOT;
823 else if (action == LFUN_LOAVIEW)
824 type = Buffer::TOC_LOA;
825 fl_set_choice(fd_form_toc->toctype,type + 1);
827 if (fd_form_toc->form_toc->visible) {
828 fl_raise_form(fd_form_toc->form_toc);
830 static int ow = -1, oh;
831 fl_show_form(fd_form_toc->form_toc,
833 FL_FREE_SIZE, FL_FULLBORDER,
834 _("Table of Contents"));
836 ow = fd_form_toc->form_toc->w;
837 oh = fd_form_toc->form_toc->h;
839 fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
843 case LFUN_TOC_INSERT:
845 Inset * new_inset = new InsetTOC(owner->buffer());
846 if (!owner->view()->insertInset(new_inset, "Standard", true))
851 case LFUN_LOF_INSERT:
853 Inset * new_inset = new InsetLOF(owner->buffer());
854 if (!owner->view()->insertInset(new_inset, "Standard", true))
859 case LFUN_LOA_INSERT:
861 Inset * new_inset = new InsetLOA(owner->buffer());
862 if (!owner->view()->insertInset(new_inset, "Standard", true))
867 case LFUN_LOT_INSERT:
869 Inset * new_inset = new InsetLOT(owner->buffer());
870 if (!owner->view()->insertInset(new_inset, "Standard", true))
883 case LFUN_INSERT_GRAPHICS:
885 Inset * new_inset = new InsetGraphics;
886 if (!owner->view()->insertInset(new_inset))
892 AutoSave(owner->view());
896 owner->view()->menuUndo();
900 owner->view()->menuRedo();
903 case LFUN_MENUSEARCH:
905 // Ok this is one _very_ bad solution, but I think that some
906 // of this will be rewritten as part of GUI indep anyway.
908 static LyXFindReplace FR_;
909 FR_.StartSearch(owner->view());
914 owner->view()->paste();
915 owner->view()->setState();
918 case LFUN_PASTESELECTION:
921 if (argument == "paragraph") asPara = true;
922 #ifdef XFORMS_CLIPBOARD
923 owner->view()->pasteClipboard(asPara);
925 MenuPasteSelection(asPara);
931 owner->view()->cut();
935 owner->view()->copy();
938 case LFUN_LAYOUT_COPY:
939 owner->view()->copyEnvironment();
942 case LFUN_LAYOUT_PASTE:
943 owner->view()->pasteEnvironment();
944 owner->view()->setState();
948 owner->view()->gotoError();
951 case LFUN_REMOVEERRORS:
952 if (owner->view()->removeAutoInsets()) {
953 owner->view()->redraw();
954 owner->view()->fitCursor();
955 //owner->view()->updateScrollbar();
960 owner->view()->gotoNote();
964 owner->view()->openStuff();
967 case LFUN_HYPHENATION:
968 owner->view()->hyphenationPoint();
972 owner->view()->ldots();
975 case LFUN_END_OF_SENTENCE:
976 owner->view()->endOfSentenceDot();
979 case LFUN_MENU_SEPARATOR:
980 owner->view()->menuSeparator();
984 owner->view()->hfill();
988 changeDepth(owner->view(), 0);
992 changeDepth(owner->view(), -1);
995 case LFUN_DEPTH_PLUS:
996 changeDepth(owner->view(), 1);
1000 Free(owner->view());
1001 owner->view()->setState();
1002 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1007 owner->view()->setState();
1008 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1012 Melt(owner->view());
1015 case LFUN_RECONFIGURE:
1016 Reconfigure(owner->view());
1020 if (owner->view()->available()
1021 && !owner->view()->text->selection
1022 && owner->view()->text->cursor.par->footnoteflag
1023 != LyXParagraph::NO_FOOTNOTE)
1024 { // only melt footnotes with FOOTMELT, not margins etc
1025 if(owner->view()->text->cursor.par->footnotekind == LyXParagraph::FOOTNOTE)
1026 Melt(owner->view());
1029 Foot(owner->view());
1030 owner->view()->setState();
1033 case LFUN_MARGINMELT:
1034 if (owner->view()->available()
1035 && !owner->view()->text->selection
1036 && owner->view()->text->cursor.par->footnoteflag
1037 != LyXParagraph::NO_FOOTNOTE) {
1038 // only melt margins
1039 if(owner->view()->text->cursor.par->footnotekind == LyXParagraph::MARGIN)
1040 Melt(owner->view());
1042 Margin(owner->view());
1043 owner->view()->setState();
1046 // --- version control -------------------------------
1047 case LFUN_VC_REGISTER:
1049 if (!owner->buffer()->lyxvc.inUse())
1050 owner->buffer()->lyxvc.registrer();
1054 case LFUN_VC_CHECKIN:
1056 if (owner->buffer()->lyxvc.inUse()
1057 && !owner->buffer()->isReadonly())
1058 owner->buffer()->lyxvc.checkIn();
1062 case LFUN_VC_CHECKOUT:
1064 if (owner->buffer()->lyxvc.inUse()
1065 && owner->buffer()->isReadonly())
1066 owner->buffer()->lyxvc.checkOut();
1070 case LFUN_VC_REVERT:
1072 owner->buffer()->lyxvc.revert();
1078 owner->buffer()->lyxvc.undoLast();
1082 case LFUN_VC_HISTORY:
1084 owner->buffer()->lyxvc.showLog();
1088 // --- buffers ----------------------------------------
1090 case LFUN_FILE_INSERT:
1092 MenuInsertLyXFile(argument);
1096 case LFUN_FILE_INSERT_ASCII:
1098 bool asPara = (argument == "paragraph");
1099 InsertAsciiFile(owner->view(), string(), asPara);
1105 // servercmd: argument must be <file>:<template>
1106 Buffer * tmpbuf = NewLyxFile(argument);
1108 owner->view()->buffer(tmpbuf);
1112 case LFUN_FILE_OPEN:
1113 owner->view()->buffer(bufferlist.loadLyXFile(argument));
1116 case LFUN_LATEX_LOG:
1122 lyxerr.debug() << "LFUN_LAYOUTNO: (arg) " << argument << endl;
1123 int sel = strToInt(argument);
1124 lyxerr.debug() << "LFUN_LAYOUTNO: (sel) "<< sel << endl;
1126 // Should this give a setMessage instead?
1128 return string(); // illegal argument
1130 --sel; // sel 1..., but layout 0...
1132 // Pretend we got the name instead.
1133 Dispatch(int(LFUN_LAYOUT),
1134 textclasslist.NameOfLayout(owner->view()
1135 ->buffer()->params.textclass,
1142 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1143 << argument << endl;
1145 // Derive layout number from given argument (string)
1146 // and current buffer's textclass (number). */
1147 LyXTextClassList::ClassList::size_type tclass =
1148 owner->view()->buffer()->params.textclass;
1149 pair <bool, LyXTextClass::size_type> layout =
1150 textclasslist.NumberOfLayout(tclass, argument);
1152 // If the entry is obsolete, use the new one instead.
1154 string obs = textclasslist.Style(tclass,layout.second)
1158 textclasslist.NumberOfLayout(tclass, obs);
1161 // see if we found the layout number:
1162 if (!layout.first) {
1163 setErrorMessage(string(N_("Layout ")) + argument +
1168 if (current_layout != layout.second) {
1169 owner->view()->hideCursor();
1170 current_layout = layout.second;
1171 owner->view()->update(-2);
1172 owner->view()->text->
1173 SetLayout(layout.second);
1174 owner->getToolbar()->combox->
1175 select(owner->view()->
1178 owner->view()->update(1);
1179 owner->view()->setState();
1184 case LFUN_LAYOUT_DOCUMENT:
1185 MenuLayoutDocument();
1188 case LFUN_LAYOUT_PARAGRAPH:
1189 MenuLayoutParagraph();
1192 case LFUN_LAYOUT_CHARACTER:
1193 MenuLayoutCharacter();
1196 case LFUN_LAYOUT_TABLE:
1199 if (argument == "true") flag = 1;
1200 MenuLayoutTable(flag);
1204 case LFUN_LAYOUT_PAPER:
1208 case LFUN_LAYOUT_QUOTES:
1212 case LFUN_LAYOUT_PREAMBLE:
1213 MenuLayoutPreamble();
1216 case LFUN_LAYOUT_SAVE_DEFAULT:
1220 case LFUN_DROP_LAYOUTS_CHOICE:
1221 owner->getToolbar()->combox->Show();
1226 Lang(owner->view(), argument);
1227 owner->view()->setState();
1228 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1233 Emph(owner->view());
1234 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1238 Bold(owner->view());
1239 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1243 Noun(owner->view());
1244 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1248 Code(owner->view());
1249 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1253 Sans(owner->view());
1254 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1258 Roman(owner->view());
1259 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1263 StyleReset(owner->view());
1264 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1267 case LFUN_UNDERLINE:
1268 Underline(owner->view());
1269 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1272 case LFUN_FONT_SIZE:
1273 FontSize(owner->view(), argument);
1274 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1277 case LFUN_FONT_STATE:
1278 setMessage(CurrentState(owner->view()));
1281 case LFUN_UPCASE_WORD:
1282 owner->view()->update(-2);
1284 owner->view()->text->ChangeWordCase(LyXText::text_uppercase);
1285 owner->view()->update(1);
1289 case LFUN_LOWCASE_WORD:
1290 owner->view()->update(-2);
1292 owner->view()->text->ChangeWordCase(LyXText::text_lowercase);
1293 owner->view()->update(1);
1297 case LFUN_CAPITALIZE_WORD:
1298 owner->view()->update(-2);
1300 owner->view()->text->ChangeWordCase(LyXText::text_capitalization);
1301 owner->view()->update(1);
1305 case LFUN_INSERT_LABEL:
1306 MenuInsertLabel(argument.c_str());
1309 case LFUN_INSERT_REF:
1313 case LFUN_REFTOGGLE:
1316 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1319 owner->view()->updateInset(inset, true);
1321 setErrorMessage(N_("No cross-reference to toggle"));
1328 owner->view()->restorePosition();
1334 string label(argument);
1335 if (label.empty()) {
1337 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1339 label = inset->getContents();
1342 if (!label.empty()) {
1343 owner->view()->savePosition();
1344 if (!owner->view()->gotoLabel(label))
1345 WriteAlert(_("Error"),
1346 _("Couldn't find this label"),
1347 _("in current document."));
1352 case LFUN_MENU_OPEN_BY_NAME:
1353 owner->getMenus()->openByName(argument);
1354 break; // RVDK_PATCH_5
1356 case LFUN_SPELLCHECK:
1357 if (lyxrc.isp_command != "none")
1358 ShowSpellChecker(owner->view());
1359 break; // RVDK_PATCH_5
1361 // --- Cursor Movements -----------------------------
1364 LyXText * tmptext = owner->view()->text;
1365 bool is_rtl = tmptext->cursor.par->isRightToLeftPar();
1366 if(!tmptext->mark_set)
1367 owner->view()->beforeChange();
1368 owner->view()->update(-2);
1370 tmptext->CursorLeft();
1371 if (tmptext->cursor.pos < tmptext->cursor.par->Last()
1372 && tmptext->cursor.par->GetChar(tmptext->cursor.pos)
1373 == LyXParagraph::META_INSET
1374 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)
1375 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)->Editable() == Inset::HIGHLY_EDITABLE){
1376 Inset * tmpinset = tmptext->cursor.par->GetInset(tmptext->cursor.pos);
1377 setMessage(tmpinset->EditMessage());
1378 tmpinset->Edit(owner->view(), 0, 0, 0);
1382 tmptext->CursorRight();
1383 owner->view()->text->FinishUndo();
1384 moveCursorUpdate(false);
1385 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1391 // This is soooo ugly. Isn`t it possible to make
1392 // it simpler? (Lgb)
1393 LyXText * txt = owner->view()->text;
1394 bool is_rtl = txt->cursor.par->isRightToLeftPar();
1395 if(!txt->mark_set) owner->view()->beforeChange();
1396 owner->view()->update(-2);
1399 if (txt->cursor.pos < txt->cursor.par->Last()
1400 && txt->cursor.par->GetChar(txt->cursor.pos)
1401 == LyXParagraph::META_INSET
1402 && txt->cursor.par->GetInset(txt->cursor.pos)
1403 && txt->cursor.par->GetInset(txt->cursor.pos)->Editable() == Inset::HIGHLY_EDITABLE) {
1404 Inset * tmpinset = txt->cursor.par->GetInset(txt->cursor.pos);
1405 setMessage(tmpinset->EditMessage());
1406 LyXFont font = txt->GetFont(txt->cursor.par,
1408 tmpinset->Edit(owner->view(),
1409 tmpinset->x() + tmpinset->width(owner->view()->painter(),font),
1410 tmpinset->descent(owner->view()->painter(),font),
1417 owner->view()->text->FinishUndo();
1418 moveCursorUpdate(false);
1419 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1424 if(!owner->view()->text->mark_set) owner->view()->beforeChange();
1425 owner->view()->update(-3);
1426 owner->view()->text->CursorUp();
1427 owner->view()->text->FinishUndo();
1428 moveCursorUpdate(false);
1429 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1433 if(!owner->view()->text->mark_set)
1434 owner->view()->beforeChange();
1435 owner->view()->update(-3);
1436 owner->view()->text->CursorDown();
1437 owner->view()->text->FinishUndo();
1438 moveCursorUpdate(false);
1439 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1442 case LFUN_UP_PARAGRAPH:
1443 if(!owner->view()->text->mark_set)
1444 owner->view()->beforeChange();
1445 owner->view()->update(-3);
1446 owner->view()->text->CursorUpParagraph();
1447 owner->view()->text->FinishUndo();
1448 moveCursorUpdate(false);
1449 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1452 case LFUN_DOWN_PARAGRAPH:
1453 if(!owner->view()->text->mark_set)
1454 owner->view()->beforeChange();
1455 owner->view()->update(-3);
1456 owner->view()->text->CursorDownParagraph();
1457 owner->view()->text->FinishUndo();
1458 moveCursorUpdate(false);
1459 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1463 if(!owner->view()->text->mark_set)
1464 owner->view()->beforeChange();
1465 owner->view()->update(-3);
1466 owner->view()->cursorPrevious();
1467 owner->view()->text->FinishUndo();
1468 moveCursorUpdate(false);
1469 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1473 if(!owner->view()->text->mark_set)
1474 owner->view()->beforeChange();
1475 owner->view()->update(-3);
1476 owner->view()->cursorNext();
1477 owner->view()->text->FinishUndo();
1478 moveCursorUpdate(false);
1479 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1483 if(!owner->view()->text->mark_set)
1484 owner->view()->beforeChange();
1485 owner->view()->update(-2);
1486 owner->view()->text->CursorHome();
1487 owner->view()->text->FinishUndo();
1488 moveCursorUpdate(false);
1489 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1493 if(!owner->view()->text->mark_set)
1494 owner->view()->beforeChange();
1495 owner->view()->update(-2);
1496 owner->view()->text->CursorEnd();
1497 owner->view()->text->FinishUndo();
1498 moveCursorUpdate(false);
1499 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1503 if(!owner->view()->text->mark_set)
1504 owner->view()->beforeChange();
1505 owner->view()->update(-2);
1506 owner->view()->text->CursorTab();
1507 owner->view()->text->FinishUndo();
1508 moveCursorUpdate(false);
1509 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1512 case LFUN_WORDRIGHT:
1513 if(!owner->view()->text->mark_set)
1514 owner->view()->beforeChange();
1515 owner->view()->update(-2);
1516 if (owner->view()->text->cursor.par->isRightToLeftPar())
1517 owner->view()->text->CursorLeftOneWord();
1519 owner->view()->text->CursorRightOneWord();
1520 owner->view()->text->FinishUndo();
1521 moveCursorUpdate(false);
1522 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1526 if(!owner->view()->text->mark_set)
1527 owner->view()->beforeChange();
1528 owner->view()->update(-2);
1529 if (owner->view()->text->cursor.par->isRightToLeftPar())
1530 owner->view()->text->CursorRightOneWord();
1532 owner->view()->text->CursorLeftOneWord();
1533 owner->view()->text->FinishUndo();
1534 moveCursorUpdate(false);
1535 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1538 case LFUN_BEGINNINGBUF:
1539 if(!owner->view()->text->mark_set)
1540 owner->view()->beforeChange();
1541 owner->view()->update(-2);
1542 owner->view()->text->CursorTop();
1543 owner->view()->text->FinishUndo();
1544 moveCursorUpdate(false);
1545 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1549 if(!owner->view()->text->mark_set)
1550 owner->view()->beforeChange();
1551 owner->view()->update(-2);
1552 owner->view()->text->CursorBottom();
1553 owner->view()->text->FinishUndo();
1554 moveCursorUpdate(false);
1555 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1559 /* cursor selection ---------------------------- */
1561 owner->view()->update(-2);
1562 if (owner->view()->text->cursor.par->isRightToLeftPar())
1563 owner->view()->text->CursorLeft();
1565 owner->view()->text->CursorRight();
1566 owner->view()->text->FinishUndo();
1567 moveCursorUpdate(true);
1568 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1572 owner->view()->update(-2);
1573 if (owner->view()->text->cursor.par->isRightToLeftPar())
1574 owner->view()->text->CursorRight();
1576 owner->view()->text->CursorLeft();
1577 owner->view()->text->FinishUndo();
1578 moveCursorUpdate(true);
1579 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1583 owner->view()->update(-2);
1584 owner->view()->text->CursorUp();
1585 owner->view()->text->FinishUndo();
1586 moveCursorUpdate(true);
1587 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1591 owner->view()->update(-2);
1592 owner->view()->text->CursorDown();
1593 owner->view()->text->FinishUndo();
1594 moveCursorUpdate(true);
1595 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1598 case LFUN_UP_PARAGRAPHSEL:
1599 owner->view()->update(-2);
1600 owner->view()->text->CursorUpParagraph();
1601 owner->view()->text->FinishUndo();
1602 moveCursorUpdate(true);
1603 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1606 case LFUN_DOWN_PARAGRAPHSEL:
1607 owner->view()->update(-2);
1608 owner->view()->text->CursorDownParagraph();
1609 owner->view()->text->FinishUndo();
1610 moveCursorUpdate(true);
1611 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1615 owner->view()->update(-2);
1616 owner->view()->cursorPrevious();
1617 owner->view()->text->FinishUndo();
1618 moveCursorUpdate(true);
1619 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1623 owner->view()->update(-2);
1624 owner->view()->cursorNext();
1625 owner->view()->text->FinishUndo();
1626 moveCursorUpdate(true);
1627 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1631 owner->view()->update(-2);
1632 owner->view()->text->CursorHome();
1633 owner->view()->text->FinishUndo();
1634 moveCursorUpdate(true);
1635 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1639 owner->view()->update(-2);
1640 owner->view()->text->CursorEnd();
1641 owner->view()->text->FinishUndo();
1642 moveCursorUpdate(true);
1643 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1646 case LFUN_WORDRIGHTSEL:
1647 owner->view()->update(-2);
1648 if (owner->view()->text->cursor.par->isRightToLeftPar())
1649 owner->view()->text->CursorLeftOneWord();
1651 owner->view()->text->CursorRightOneWord();
1652 owner->view()->text->FinishUndo();
1653 moveCursorUpdate(true);
1654 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1657 case LFUN_WORDLEFTSEL:
1658 owner->view()->update(-2);
1659 if (owner->view()->text->cursor.par->isRightToLeftPar())
1660 owner->view()->text->CursorRightOneWord();
1662 owner->view()->text->CursorLeftOneWord();
1663 owner->view()->text->FinishUndo();
1664 moveCursorUpdate(true);
1665 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1668 case LFUN_BEGINNINGBUFSEL:
1669 owner->view()->update(-2);
1670 owner->view()->text->CursorTop();
1671 owner->view()->text->FinishUndo();
1672 moveCursorUpdate(true);
1673 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1676 case LFUN_ENDBUFSEL:
1677 owner->view()->update(-2);
1678 owner->view()->text->CursorBottom();
1679 owner->view()->text->FinishUndo();
1680 moveCursorUpdate(true);
1681 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1684 // --- text changing commands ------------------------
1685 case LFUN_BREAKLINE:
1686 owner->view()->beforeChange();
1687 owner->view()->text->InsertChar(LyXParagraph::META_NEWLINE);
1688 owner->view()->update(1);
1689 SetUpdateTimer(0.01);
1690 moveCursorUpdate(false);
1693 case LFUN_PROTECTEDSPACE:
1695 LyXLayout const & style =
1696 textclasslist.Style(owner->view()->buffer()->params.textclass,
1697 owner->view()->text->cursor.par->GetLayout());
1699 if (style.free_spacing) {
1700 owner->view()->text->InsertChar(' ');
1701 owner->view()->update(-1);
1703 owner->view()->protectedBlank();
1705 moveCursorUpdate(false);
1710 if(owner->view()->text->mark_set) {
1711 owner->view()->beforeChange();
1712 owner->view()->update(0);
1713 setMessage(N_("Mark removed"));
1715 owner->view()->beforeChange();
1716 owner->view()->text->mark_set = 1;
1717 owner->view()->update(0);
1718 setMessage(N_("Mark set"));
1720 owner->view()->text->sel_cursor =
1721 owner->view()->text->cursor;
1726 if (!owner->view()->text->selection) {
1727 owner->view()->text->Delete();
1728 owner->view()->text->sel_cursor =
1729 owner->view()->text->cursor;
1730 owner->view()->update(1);
1731 // It is possible to make it a lot faster still
1732 // just comment out the lone below...
1733 owner->view()->showCursor();
1735 owner->view()->cut();
1738 moveCursorUpdate(false);
1739 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1740 owner->view()->setState();
1743 case LFUN_DELETE_SKIP:
1745 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1747 LyXCursor cursor = owner->view()->text->cursor;
1750 if (!owner->view()->text->selection) {
1751 if (cursor.pos == cursor.par->Last()) {
1752 owner->view()->text->CursorRight();
1753 cursor = owner->view()->text->cursor;
1755 && !(cursor.par->added_space_top
1756 == VSpace (VSpace::NONE))) {
1757 owner->view()->text->SetParagraph
1758 (cursor.par->line_top,
1759 cursor.par->line_bottom,
1760 cursor.par->pagebreak_top,
1761 cursor.par->pagebreak_bottom,
1762 VSpace(VSpace::NONE),
1763 cursor.par->added_space_bottom,
1765 cursor.par->labelwidthstring, 0);
1766 owner->view()->text->CursorLeft();
1767 owner->view()->update (1);
1769 owner->view()->text->CursorLeft();
1770 owner->view()->text->Delete();
1771 owner->view()->text->sel_cursor =
1772 owner->view()->text->cursor;
1773 owner->view()->update(1);
1776 owner->view()->text->Delete();
1777 owner->view()->text->sel_cursor =
1778 owner->view()->text->cursor;
1779 owner->view()->update(1);
1782 owner->view()->cut();
1788 /* -------> Delete word forward. */
1789 case LFUN_DELETE_WORD_FORWARD:
1790 owner->view()->update(-2);
1792 owner->view()->text->DeleteWordForward();
1793 owner->view()->update( 1 );
1795 moveCursorUpdate(false);
1796 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1799 /* -------> Delete word backward. */
1800 case LFUN_DELETE_WORD_BACKWARD:
1801 owner->view()->update(-2);
1803 owner->view()->text->DeleteWordBackward();
1804 owner->view()->update( 1 );
1806 moveCursorUpdate(false);
1807 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1810 /* -------> Kill to end of line. */
1811 case LFUN_DELETE_LINE_FORWARD:
1813 owner->view()->update(-2);
1814 owner->view()->text->DeleteLineForward();
1815 owner->view()->update( 1 );
1817 moveCursorUpdate(false);
1820 /* -------> Set mark off. */
1822 owner->view()->beforeChange();
1823 owner->view()->update(0);
1824 owner->view()->text->sel_cursor =
1825 owner->view()->text->cursor;
1826 setMessage(N_("Mark off"));
1829 /* -------> Set mark on. */
1831 owner->view()->beforeChange();
1832 owner->view()->text->mark_set = 1;
1833 owner->view()->update( 0 );
1834 owner->view()->text->sel_cursor =
1835 owner->view()->text->cursor;
1836 setMessage(N_("Mark on"));
1839 case LFUN_BACKSPACE:
1842 if (!owner->view()->text->selection) {
1843 if (owner->getIntl()->getTrans()->backspace()) {
1844 owner->view()->text->Backspace();
1845 owner->view()->text->sel_cursor =
1846 owner->view()->text->cursor;
1847 owner->view()->update(1);
1848 // It is possible to make it a lot faster still
1849 // just comment out the lone below...
1850 owner->view()->showCursor();
1853 owner->view()->cut();
1856 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1857 owner->view()->setState();
1861 case LFUN_BACKSPACE_SKIP:
1863 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1865 LyXCursor cursor = owner->view()->text->cursor;
1868 if (!owner->view()->text->selection) {
1870 && !(cursor.par->added_space_top
1871 == VSpace (VSpace::NONE))) {
1872 owner->view()->text->SetParagraph
1873 (cursor.par->line_top,
1874 cursor.par->line_bottom,
1875 cursor.par->pagebreak_top,
1876 cursor.par->pagebreak_bottom,
1877 VSpace(VSpace::NONE), cursor.par->added_space_bottom,
1879 cursor.par->labelwidthstring, 0);
1880 owner->view()->update (1);
1882 owner->view()->text->Backspace();
1883 owner->view()->text->sel_cursor
1885 owner->view()->update(1);
1888 owner->view()->cut();
1893 case LFUN_BREAKPARAGRAPH:
1895 owner->view()->beforeChange();
1896 owner->view()->text->BreakParagraph(0);
1897 owner->view()->update(1);
1898 SetUpdateTimer(0.01);
1899 owner->view()->text->sel_cursor =
1900 owner->view()->text->cursor;
1901 owner->view()->setState();
1902 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1906 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1908 owner->view()->beforeChange();
1909 owner->view()->text->BreakParagraph(1);
1910 owner->view()->update(1);
1911 SetUpdateTimer(0.01);
1912 owner->view()->text->sel_cursor =
1913 owner->view()->text->cursor;
1914 owner->view()->setState();
1915 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1919 case LFUN_BREAKPARAGRAPH_SKIP:
1921 // When at the beginning of a paragraph, remove
1922 // indentation and add a "defskip" at the top.
1923 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
1925 LyXCursor cursor = owner->view()->text->cursor;
1927 owner->view()->beforeChange();
1928 if (cursor.pos == 0) {
1929 if (cursor.par->added_space_top == VSpace(VSpace::NONE)) {
1930 owner->view()->text->SetParagraph
1931 (cursor.par->line_top,
1932 cursor.par->line_bottom,
1933 cursor.par->pagebreak_top,
1934 cursor.par->pagebreak_bottom,
1935 VSpace(VSpace::DEFSKIP), cursor.par->added_space_bottom,
1937 cursor.par->labelwidthstring, 1);
1938 owner->view()->update(1);
1942 owner->view()->text->BreakParagraph(0);
1943 owner->view()->update(1);
1945 SetUpdateTimer(0.01);
1946 owner->view()->text->sel_cursor = cursor;
1947 owner->view()->setState();
1948 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1952 case LFUN_PARAGRAPH_SPACING:
1954 LyXParagraph * par = owner->view()->text->cursor.par;
1955 Spacing::Space cur_spacing = par->spacing.getSpace();
1956 float cur_value = 1.0;
1957 if (cur_spacing == Spacing::Other) {
1958 cur_value = par->spacing.getValue();
1962 istringstream istr(argument);
1964 istrstream istr(argument.c_str());
1968 Spacing::Space new_spacing = cur_spacing;
1969 float new_value = cur_value;
1971 lyxerr << "Missing argument to `paragraph-spacing'"
1973 } else if (tmp == "single") {
1974 new_spacing = Spacing::Single;
1975 } else if (tmp == "onehalf") {
1976 new_spacing = Spacing::Onehalf;
1977 } else if (tmp == "double") {
1978 new_spacing = Spacing::Double;
1979 } else if (tmp == "other") {
1980 new_spacing = Spacing::Other;
1983 lyxerr << "new_value = " << tmpval << endl;
1986 } else if (tmp == "default") {
1987 new_spacing = Spacing::Default;
1989 lyxerr << _("Unknown spacing argument: ")
1990 << argument << endl;
1992 if (cur_spacing != new_spacing || cur_value != new_value) {
1993 par->spacing.set(new_spacing, new_value);
1994 owner->view()->text->RedoParagraph();
1995 owner->view()->update(-1);
2001 owner->view()->beforeChange();
2002 owner->view()->text->InsertChar('\"'); // This " matches the single quote in the code
2003 owner->view()->update(1);
2005 moveCursorUpdate(false);
2011 InsetCommand * new_inset;
2012 if (action == LFUN_HTMLURL)
2013 new_inset = new InsetUrl("htmlurl", "", "");
2015 new_inset = new InsetUrl("url", "", "");
2016 if (owner->view()->insertInset(new_inset))
2017 new_inset->Edit(owner->view(), 0, 0, 0);
2023 case LFUN_INSET_TEXT:
2025 InsetText * new_inset = new InsetText(owner->buffer());
2026 if (owner->view()->insertInset(new_inset))
2027 new_inset->Edit(owner->view(), 0, 0, 0);
2032 case LFUN_INSET_ERT:
2034 InsetERT * new_inset = new InsetERT(owner->buffer());
2035 if (owner->view()->insertInset(new_inset))
2036 new_inset->Edit(owner->view(), 0, 0, 0);
2042 case LFUN_INSET_FOOTNOTE:
2044 InsetFoot * new_inset = new InsetFoot(owner->buffer());
2045 if (owner->view()->insertInset(new_inset))
2046 new_inset->Edit(owner->view(), 0, 0, 0);
2052 case LFUN_INSET_TABULAR:
2055 if (!argument.empty())
2056 sscanf(argument.c_str(),"%d%d",&r,&c);
2057 InsetTabular * new_inset = new InsetTabular(owner->buffer(),r,c);
2058 if (owner->view()->insertInset(new_inset))
2059 new_inset->Edit(owner->view(), 0, 0, 0);
2065 // --- lyxserver commands ----------------------------
2067 case LFUN_CHARATCURSOR:
2069 LyXParagraph::size_type pos =
2070 owner->view()->text->cursor.pos;
2071 if(pos < owner->view()->text->cursor.par->size())
2072 //dispatch_buffer = owner->view()->text->
2073 // cursor.par->text[pos];
2075 owner->view()->text->
2076 cursor.par->GetChar(pos);
2078 dispatch_buffer = "EOF";
2084 tostr(owner->view()->text->cursor.x) + ' '
2085 + tostr(owner->view()->text->cursor.y);
2092 sscanf(argument.c_str(), " %d %ld", &x, &y);
2093 owner->view()->text->SetCursorFromCoordinates(x, y);
2097 case LFUN_GETLAYOUT:
2099 tostr(owner->view()->text->cursor.par->layout);
2104 LyXFont & font = owner->view()->text->current_font;
2105 if(font.shape() == LyXFont::ITALIC_SHAPE)
2106 dispatch_buffer = 'E';
2107 else if(font.shape() == LyXFont::SMALLCAPS_SHAPE)
2108 dispatch_buffer = 'N';
2110 dispatch_buffer = '0';
2117 LyXFont & font = owner->view()->text->current_font;
2118 if(font.latex() == LyXFont::ON)
2119 dispatch_buffer = 'L';
2121 dispatch_buffer = '0';
2126 setMessage(owner->buffer()->fileName());
2127 lyxerr.debug() << "FNAME["
2128 << owner->buffer()->fileName()
2136 dispatch_buffer = buf;
2137 lyxserver->notifyClient(dispatch_buffer);
2141 case LFUN_GOTOFILEROW:
2143 char file_name[100];
2145 sscanf(argument.c_str(), " %s %d", file_name, &row);
2147 // Must replace extension of the file to be .lyx and get full path
2148 string s = ChangeExtension(string(file_name), ".lyx");
2150 // Either change buffer or load the file
2151 if (bufferlist.exists(s))
2152 owner->view()->buffer(bufferlist.getBuffer(s));
2154 owner->view()->buffer(bufferlist.loadLyXFile(s));
2157 owner->view()->setCursorFromRow(row);
2160 owner->view()->center();
2167 int qa = lyxaction.LookupFunc(argument.c_str());
2168 setMessage(lyxaction.helpText(static_cast<kb_action>(qa)));
2172 // --- accented characters ---------------------------
2175 case LFUN_CIRCUMFLEX:
2185 case LFUN_SPECIAL_CARON:
2188 case LFUN_HUNG_UMLAUT:
2194 if (keyseq.length == -1 && keyseq.getiso() != 0)
2195 c = keyseq.getiso();
2197 owner->getIntl()->getTrans()->
2198 deadkey(c, get_accent(action).accent,
2199 owner->view()->text);
2201 // Need to reset, in case the minibuffer calls these
2206 // copied verbatim from do_accent_char
2207 owner->view()->update(1);
2210 owner->view()->text->sel_cursor =
2211 owner->view()->text->cursor;
2215 // --- toolbar ----------------------------------
2216 case LFUN_PUSH_TOOLBAR:
2218 int nth = strToInt(argument);
2219 if (lyxerr.debugging(Debug::TOOLBAR)) {
2220 lyxerr << "LFUN_PUSH_TOOLBAR: argument = `"
2221 << argument << "'\n"
2222 << "LFUN_PUSH_TOOLBAR: nth = `"
2223 << nth << "'" << endl;
2228 setErrorMessage(N_("Push-toolbar needs argument > 0"));
2230 owner->getToolbar()->push(nth);
2235 case LFUN_ADD_TO_TOOLBAR:
2237 if (lyxerr.debugging(Debug::TOOLBAR)) {
2238 lyxerr << "LFUN_ADD_TO_TOOLBAR:"
2239 "argument = `" << argument << '\'' << endl;
2241 string tmp(argument);
2242 //lyxerr <<string("Argument: ") + argument);
2243 //lyxerr <<string("Tmp : ") + tmp);
2246 setErrorMessage(N_("Usage: toolbar-add-to <LyX command>"));
2248 owner->getToolbar()->add(argument, false);
2249 owner->getToolbar()->set();
2254 // --- insert characters ----------------------------------------
2256 // --- Mathed stuff. If we are here, there is no locked inset yet.
2261 if (!greek_kb_flag) {
2263 setMessage(N_("Math greek mode on"));
2270 case LFUN_GREEK_TOGGLE:
2272 greek_kb_flag = greek_kb_flag ? 0 : 2;
2273 if (greek_kb_flag) {
2274 setMessage(N_("Math greek keyboard on"));
2276 setMessage(N_("Math greek keyboard off"));
2281 case LFUN_MATH_DELIM:
2282 case LFUN_INSERT_MATRIX:
2284 if (owner->view()->available()) {
2286 open_new_inset(new InsetFormula(false));
2289 ->LocalDispatch(owner->view(),
2296 case LFUN_INSERT_MATH:
2298 math_insert_symbol(argument.c_str());
2302 case LFUN_MATH_DISPLAY:
2304 if (owner->view()->available())
2305 owner->view()->open_new_inset(new InsetFormula(true));
2309 case LFUN_MATH_MACRO:
2311 if (owner->view()->available()) {
2314 setErrorMessage(N_("Missing argument"));
2316 string s1 = token(s, ' ', 1);
2317 int na = s1.empty() ? 0: atoi(s1.c_str());
2319 open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2325 case LFUN_MATH_MODE: // Open or create a math inset
2328 if (owner->view()->available())
2329 owner->view()->open_new_inset(new InsetFormula);
2330 setMessage(N_("Math editor mode"));
2334 case LFUN_MATH_NUMBER:
2335 case LFUN_MATH_LIMITS:
2337 setErrorMessage(N_("This is only allowed in math mode!"));
2341 case LFUN_INSERT_CITATION:
2343 InsetCitation * new_inset = new InsetCitation();
2345 // The note, if any, must be after the key, delimited
2346 // by a | so both key and remark can have spaces.
2347 if (!argument.empty()) {
2348 string lsarg(argument);
2349 if (contains(lsarg, "|")) {
2350 new_inset->setContents(token(lsarg, '|', 0));
2351 new_inset->setOptions(token(lsarg, '|', 1));
2353 new_inset->setContents(lsarg);
2354 if (!owner->view()->insertInset(new_inset))
2357 if (owner->view()->insertInset(new_inset))
2358 new_inset->Edit(owner->view(), 0, 0, 0);
2365 case LFUN_INSERT_BIBTEX:
2367 // ale970405+lasgoutt970425
2368 // The argument can be up to two tokens separated
2369 // by a space. The first one is the bibstyle.
2370 string lsarg(argument);
2371 string bibstyle = token(lsarg, ' ', 1);
2372 if (bibstyle.empty())
2374 InsetBibtex * new_inset
2375 = new InsetBibtex(token(lsarg, ' ', 0),
2379 if (owner->view()->insertInset(new_inset)) {
2381 new_inset->Edit(owner->view(), 0, 0, 0);
2387 // BibTeX data bases
2388 case LFUN_BIBDB_ADD:
2390 InsetBibtex * inset =
2391 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2393 inset->addDatabase(argument);
2398 case LFUN_BIBDB_DEL:
2400 InsetBibtex * inset =
2401 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2403 inset->delDatabase(argument);
2408 case LFUN_BIBTEX_STYLE:
2410 InsetBibtex * inset =
2411 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2413 inset->setOptions(argument);
2418 case LFUN_INDEX_INSERT:
2419 case LFUN_INDEX_INSERT_LAST:
2421 // Can't do that at the beginning of a paragraph.
2422 if (owner->view()->text->cursor.pos - 1 < 0)
2425 InsetIndex * new_inset = new InsetIndex();
2426 if (!argument.empty()) {
2427 string lsarg(argument);
2428 new_inset->setContents(lsarg);
2429 if (!owner->view()->insertInset(new_inset))
2433 //get the current word for an argument
2434 LyXParagraph::size_type lastpos =
2435 owner->view()->text->cursor.pos - 1;
2436 // Get the current word. note that this must be done
2437 // before inserting the inset, or the inset will
2439 string curstring(owner->view()
2440 ->text->cursor.par->GetWord(lastpos));
2442 //make the new inset and write the current word into it
2443 InsetIndex * new_inset = new InsetIndex();
2445 new_inset->setContents(curstring);
2447 //don't edit it if the call was to INSERT_LAST
2448 if(action != LFUN_INDEX_INSERT_LAST) {
2449 new_inset->Edit(owner->view(), 0, 0, 0);
2451 //it looks blank on the screen unless
2452 //we do something. put it here.
2454 // move the cursor to the returned value of lastpos
2455 // but only for the auto-insert
2456 owner->view()->text->cursor.pos = lastpos;
2459 //put the new inset into the buffer.
2460 // there should be some way of knowing the user
2461 //cancelled & avoiding this, but i don't know how
2462 if (!owner->view()->insertInset(new_inset))
2468 case LFUN_INDEX_PRINT:
2470 Inset * new_inset = new InsetPrintIndex(owner->buffer());
2471 if (!owner->view()->insertInset(new_inset, "Standard", true))
2476 case LFUN_PARENTINSERT:
2478 lyxerr << "arg " << argument << endl;
2479 Inset * new_inset = new InsetParent(argument, owner->buffer());
2480 if (!owner->view()->insertInset(new_inset, "Standard", true))
2485 case LFUN_CHILDINSERT:
2487 Inset * new_inset = new InsetInclude(argument,
2489 if (owner->view()->insertInset(new_inset, "Standard", true))
2490 new_inset->Edit(owner->view(), 0, 0, 0);
2496 case LFUN_CHILDOPEN:
2499 MakeAbsPath(argument,
2500 OnlyPath(owner->buffer()->fileName()));
2501 setMessage(N_("Opening child document ") +
2502 MakeDisplayPath(filename) + "...");
2503 owner->view()->savePosition();
2504 if (bufferlist.exists(filename))
2505 owner->view()->buffer(bufferlist.getBuffer(filename));
2507 owner->view()->buffer(bufferlist.loadLyXFile(filename));
2511 case LFUN_INSERT_NOTE:
2512 owner->view()->insertNote();
2515 case LFUN_INSERTFOOTNOTE:
2517 LyXParagraph::footnote_kind kind;
2518 if (argument == "footnote")
2519 { kind = LyXParagraph::FOOTNOTE; }
2520 else if (argument == "margin")
2521 { kind = LyXParagraph::MARGIN; }
2522 else if (argument == "figure")
2523 { kind = LyXParagraph::FIG; }
2524 else if (argument == "table")
2525 { kind = LyXParagraph::TAB; }
2526 else if (argument == "wide-fig")
2527 { kind = LyXParagraph::WIDE_FIG; }
2528 else if (argument == "wide-tab")
2529 { kind = LyXParagraph::WIDE_TAB; }
2530 else if (argument == "algorithm")
2531 { kind = LyXParagraph::ALGORITHM; }
2533 setErrorMessage(N_("Unknown kind of footnote"));
2536 owner->view()->text->InsertFootnoteEnvironment(kind);
2537 owner->view()->update(1);
2538 owner->view()->setState();
2542 case LFUN_BUFFERBULLETSSELECT:
2546 case LFUN_TOGGLECURSORFOLLOW:
2547 cursor_follows_scrollbar = !cursor_follows_scrollbar;
2550 case LFUN_KMAP_OFF: // keymap off
2551 owner->getIntl()->KeyMapOn(false);
2554 case LFUN_KMAP_PRIM: // primary keymap
2555 owner->getIntl()->KeyMapPrim();
2558 case LFUN_KMAP_SEC: // secondary keymap
2559 owner->getIntl()->KeyMapSec();
2562 case LFUN_KMAP_TOGGLE: // toggle keymap
2563 owner->getIntl()->ToggleKeyMap();
2566 case LFUN_SELFINSERT:
2568 for (string::size_type i = 0; i < argument.length(); ++i) {
2569 owner->view()->text->InsertChar(argument[i]);
2570 // This needs to be in the loop, or else we
2571 // won't break lines correctly. (Asger)
2572 owner->view()->update(1);
2575 owner->view()->text->sel_cursor =
2576 owner->view()->text->cursor;
2577 moveCursorUpdate(false);
2583 // argument contains ';'-terminated commands
2584 while (argument.find(';') != string::npos) {
2586 argument = split(argument, first, ';');
2592 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
2600 now_time_t = time(NULL);
2601 now_tm = localtime(&now_time_t);
2602 (void)setlocale(LC_TIME, "");
2603 if (!argument.empty())
2605 else if (arg.empty())
2606 arg = lyxrc.date_insert_format;
2607 datetmp_len = (int) strftime(datetmp, 32, arg.c_str(), now_tm);
2608 for (int i = 0; i < datetmp_len; i++) {
2609 owner->view()->text->InsertChar(datetmp[i]);
2610 owner->view()->update(1);
2613 owner->view()->text->sel_cursor = owner->view()->text->cursor;
2614 moveCursorUpdate(false);
2618 case LFUN_SAVEPREFERENCES:
2620 Path p(user_lyxdir);
2621 lyxrc.write("preferences");
2625 case LFUN_UNKNOWN_ACTION:
2627 if(!owner->buffer()) {
2629 setErrorMessage(N_("No document open"));
2633 if (owner->buffer()->isReadonly()) {
2635 setErrorMessage(N_("Document is read only"));
2639 if (!argument.empty()) {
2641 /* Automatically delete the currently selected
2642 * text and replace it with what is being
2643 * typed in now. Depends on lyxrc settings
2644 * "auto_region_delete", which defaults to
2647 if ( lyxrc.auto_region_delete ) {
2648 if (owner->view()->text->selection){
2649 owner->view()->text->CutSelection(false);
2650 owner->view()->update(-1);
2654 owner->view()->beforeChange();
2656 for (string::size_type i = 0;
2657 i < argument.length(); ++i) {
2658 if (greek_kb_flag) {
2659 if (!math_insert_greek(argument[i]))
2660 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2662 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2665 owner->view()->update(1);
2668 owner->view()->text->sel_cursor =
2669 owner->view()->text->cursor;
2670 moveCursorUpdate(false);
2673 // why is an "Unknown action" with empty
2674 // argument even dispatched in the first
2675 // place? I`ll probably change that. (Lgb)
2677 setErrorMessage(N_("Unknown action"));
2681 lyxerr << "A truly unknown func!" << endl;
2687 string res = getMessage();
2690 if (!commandshortcut.empty()) {
2691 string newbuf = owner->getMiniBuffer()->GetText();
2692 if (newbuf != commandshortcut) {
2693 owner->getMiniBuffer()->Set(newbuf
2699 owner->getMiniBuffer()->Set(string(_(res.c_str()))
2700 + " " + commandshortcut);
2707 void LyXFunc::setupLocalKeymap()
2709 keyseq.stdmap = keyseq.curmap = toplevel_keymap;
2710 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap;
2714 void LyXFunc::MenuNew(bool fromTemplate)
2716 string fname, initpath = lyxrc.document_path;
2719 if (owner->view()->available()) {
2720 string trypath = owner->buffer()->filepath;
2721 // If directory is writeable, use this as default.
2722 if (IsDirWriteable(trypath) == 1)
2726 ProhibitInput(owner->view());
2727 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
2728 fileDlg.SetButton(1, _("Templates"), lyxrc.template_path);
2729 fname = fileDlg.Select(_("Enter Filename for new document"),
2730 initpath, "*.lyx", _("newfile"));
2731 AllowInput(owner->view());
2733 if (fname.empty()) {
2734 owner->getMiniBuffer()->Set(_("Canceled."));
2735 lyxerr.debug() << "New Document Cancelled." << endl;
2739 // get absolute path of file and make sure the filename ends
2741 string s = MakeAbsPath(fname);
2742 if (!IsLyXFilename(s))
2745 // Check if the document already is open
2746 if (bufferlist.exists(s)){
2747 switch(AskConfirmation(_("Document is already open:"),
2748 MakeDisplayPath(s, 50),
2749 _("Do you want to close that document now?\n"
2750 "('No' will just switch to the open version)")))
2752 case 1: // Yes: close the document
2753 if (!bufferlist.close(bufferlist.getBuffer(s)))
2754 // If close is canceled, we cancel here too.
2757 case 2: // No: switch to the open document
2758 owner->view()->buffer(bufferlist.getBuffer(s));
2760 case 3: // Cancel: Do nothing
2761 owner->getMiniBuffer()->Set(_("Canceled."));
2766 // Check whether the file already exists
2767 if (IsLyXFilename(s)) {
2769 if (fi.readable() &&
2770 AskQuestion(_("File already exists:"),
2771 MakeDisplayPath(s, 50),
2772 _("Do you want to open the document?"))) {
2774 owner->getMiniBuffer()->Set(_("Opening document"),
2775 MakeDisplayPath(s), "...");
2777 owner->view()->buffer(
2778 bufferlist.loadLyXFile(s));
2779 owner->getMiniBuffer()->Set(_("Document"),
2786 // The template stuff
2789 ProhibitInput(owner->view());
2790 fname = fileDlg.Select(_("Choose template"),
2791 lyxrc.template_path,
2794 AllowInput(owner->view());
2797 // find a free buffer
2798 lyxerr.debug() << "Find a free buffer." << endl;
2799 owner->view()->buffer(bufferlist.newFile(s, templname));
2803 void LyXFunc::MenuOpen()
2805 string initpath = lyxrc.document_path;
2808 if (owner->view()->available()) {
2809 string trypath = owner->buffer()->filepath;
2810 // If directory is writeable, use this as default.
2811 if (IsDirWriteable(trypath) == 1)
2816 ProhibitInput(owner->view());
2817 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
2818 fileDlg.SetButton(1, _("Examples"),
2819 AddPath(system_lyxdir, "examples"));
2820 string filename = fileDlg.Select(_("Select Document to Open"),
2822 AllowInput(owner->view());
2824 // check selected filename
2825 if (filename.empty()) {
2826 owner->getMiniBuffer()->Set(_("Canceled."));
2830 // get absolute path of file and make sure the filename ends
2832 filename = MakeAbsPath(filename);
2833 if (!IsLyXFilename(filename))
2837 owner->getMiniBuffer()->Set(_("Opening document"),
2838 MakeDisplayPath(filename), "...");
2839 Buffer * openbuf = bufferlist.loadLyXFile(filename);
2841 owner->view()->buffer(openbuf);
2842 owner->getMiniBuffer()->Set(_("Document"),
2843 MakeDisplayPath(filename),
2846 owner->getMiniBuffer()->Set(_("Could not open document"),
2847 MakeDisplayPath(filename));
2851 // returns filename if file must be imported,
2852 // empty string if either file not found or already loaded
2853 // checks for running without gui are missing.
2855 void LyXFunc::doImportHelper(
2856 string const & file, // filename (possibly empty)
2857 string const & text, // info when asking for filename
2858 string const & pattern, // filetype
2859 bool func(BufferView *, string const &) // the real import function
2862 string filename = file;
2864 if (filename.empty()) { // need user interaction
2865 string initpath = lyxrc.document_path;
2868 if (owner->view()->available()) {
2869 string trypath = owner->buffer()->filepath;
2870 // If directory is writeable, use this as default.
2871 if (IsDirWriteable(trypath) == 1)
2876 ProhibitInput(owner->view());
2877 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
2878 fileDlg.SetButton(1, _("Examples"),
2879 AddPath(system_lyxdir, "examples"));
2880 filename = fileDlg.Select(text, initpath, pattern);
2881 AllowInput(owner->view());
2883 // check selected filename
2884 if (filename.empty())
2885 owner->getMiniBuffer()->Set(_("Canceled."));
2888 // still no filename? abort
2889 if (filename.empty())
2892 // get absolute path of file
2893 filename = MakeAbsPath(filename);
2895 string lyxfile = ChangeExtension(filename, ".lyx");
2897 // Check if the document already is open
2898 if (bufferlist.exists(lyxfile)) {
2899 switch(AskConfirmation(_("Document is already open:"),
2900 MakeDisplayPath(lyxfile, 50),
2901 _("Do you want to close that document now?\n"
2902 "('No' will just switch to the open version)")))
2904 case 1: // Yes: close the document
2905 if (!bufferlist.close(bufferlist.getBuffer(lyxfile)))
2906 // If close is canceled, we cancel here too.
2909 case 2: // No: switch to the open document
2910 owner->view()->buffer(bufferlist.getBuffer(lyxfile));
2912 case 3: // Cancel: Do nothing
2913 owner->getMiniBuffer()->Set(_("Canceled."));
2918 // Check if a LyX document by the same root exists in filesystem
2919 FileInfo f(lyxfile, true);
2920 if (f.exist() && !AskQuestion(_("A document by the name"),
2921 MakeDisplayPath(lyxfile),
2922 _("already exists. Overwrite?"))) {
2923 owner->getMiniBuffer()->Set(_("Canceled."));
2926 // filename should be valid now
2928 // notify user of import ahead
2929 string displaypath = MakeDisplayPath(filename);
2930 owner->view()->buffer(bufferlist.newFile(lyxfile, string()));
2931 owner->getMiniBuffer()->Set(_("Importing"), displaypath, "...");
2933 // call real importer
2934 bool result = func(owner->view(), filename);
2938 owner->getMiniBuffer()->Set(displaypath, _("imported."));
2940 owner->getMiniBuffer()->Set(displaypath, _(": import failed."));
2944 bool doImportASCIIasLines(BufferView * view, string const & filename)
2946 InsertAsciiFile(view, filename, false);
2951 bool doImportASCIIasParagraphs(BufferView * view, string const & filename)
2953 InsertAsciiFile(view, filename, true);
2958 bool doImportLaTeX(BufferView *, string const & filename)
2960 ImportLaTeX myImport(filename);
2961 Buffer * openbuf = myImport.run();
2962 return openbuf != NULL;
2966 bool doImportNoweb(BufferView *, string const & filename)
2968 ImportNoweb myImport(filename);
2969 Buffer * openbuf = myImport.run();
2970 return openbuf != NULL;
2974 bool doImportLinuxDoc(BufferView *, string const & filename)
2977 string tmp = lyxrc.linuxdoc_to_lyx_command + filename;
2981 int result = one.startscript(Systemcalls::System, tmp);
2983 string filename = ChangeExtension(filename, ".lyx");
2984 // File was generated without problems. Load it.
2985 buf = bufferlist.loadLyXFile(filename);
2992 void LyXFunc::MenuInsertLyXFile(string const & filen)
2994 string filename = filen;
2996 if (filename.empty()) {
2997 // Launch a file browser
2998 string initpath = lyxrc.document_path;
3001 if (owner->view()->available()) {
3002 string trypath = owner->buffer()->filepath;
3003 // If directory is writeable, use this as default.
3004 if (IsDirWriteable(trypath) == 1)
3009 ProhibitInput(owner->view());
3010 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
3011 fileDlg.SetButton(1, _("Examples"),
3012 AddPath(system_lyxdir, "examples"));
3013 filename = fileDlg.Select(_("Select Document to Insert"),
3015 AllowInput(owner->view());
3017 // check selected filename
3018 if (filename.empty()) {
3019 owner->getMiniBuffer()->Set(_("Canceled."));
3024 // get absolute path of file and make sure the filename ends
3026 filename = MakeAbsPath(filename);
3027 if (!IsLyXFilename(filename))
3031 owner->getMiniBuffer()->Set(_("Inserting document"),
3032 MakeDisplayPath(filename), "...");
3033 bool res = owner->view()->insertLyXFile(filename);
3035 owner->getMiniBuffer()->Set(_("Document"),
3036 MakeDisplayPath(filename),
3039 owner->getMiniBuffer()->Set(_("Could not insert document"),
3040 MakeDisplayPath(filename));
3044 void LyXFunc::doImport(string const & argument)
3047 string filename = split(argument, type, ' ');
3048 lyxerr.debug() << "LyXFunc::doImport: " << type
3049 << " file: " << filename << endl;
3051 if (type == "latex")
3052 doImportHelper(filename,
3053 _("Select LaTeX file to import"), "*.tex",
3055 else if (type == "ascii")
3056 doImportHelper(filename,
3057 _("Select ASCII file to import"), "*.txt",
3058 doImportASCIIasLines);
3059 else if (type == "asciiparagraph")
3060 doImportHelper(filename,
3061 _("Select ASCII file to import"), "*.txt",
3062 doImportASCIIasParagraphs);
3063 else if (type == "noweb")
3064 doImportHelper(filename,
3065 _("Select NoWeb file to import"), "*.nw",
3067 else if (type == "linuxdoc")
3068 doImportHelper(filename,
3069 _("Select LinuxDoc file to import"), "*.doc",
3072 setErrorMessage(string(N_("Unknown import type: ")) + type);
3075 void LyXFunc::reloadBuffer()
3077 string fn = owner->buffer()->fileName();
3078 if (bufferlist.close(owner->buffer()))
3079 owner->view()->buffer(bufferlist.loadLyXFile(fn));
3083 void LyXFunc::CloseBuffer()
3085 if (bufferlist.close(owner->buffer()) && !quitting) {
3086 if (bufferlist.empty()) {
3087 // need this otherwise SEGV may occur while trying to
3088 // set variables that don't exist
3089 // since there's no current buffer
3090 CloseAllBufferRelatedPopups();
3093 owner->view()->buffer(bufferlist.first());
3099 Inset * LyXFunc::getInsetByCode(Inset::Code code)
3101 LyXCursor cursor = owner->view()->text->cursor;
3102 Buffer * buffer = owner->view()->buffer();
3103 for (Buffer::inset_iterator it = Buffer::inset_iterator(cursor.par,
3105 it != buffer->inset_iterator_end(); ++it) {
3106 if ((*it)->LyxCode() == code)
3113 // Each "owner" should have it's own message method. lyxview and
3114 // the minibuffer would use the minibuffer, but lyxserver would
3115 // send an ERROR signal to its client. Alejandro 970603
3116 // This func is bit problematic when it comes to NLS, to make the
3117 // lyx servers client be language indepenent we must not translate
3118 // strings sent to this func.
3119 void LyXFunc::setErrorMessage(string const & m) const
3121 dispatch_buffer = m;
3126 void LyXFunc::setMessage(string const & m)
3128 dispatch_buffer = m;