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 * ====================================================== */
20 #pragma implementation
23 #include "lyxlookup.h"
26 #include "bufferlist.h"
27 #include "lyxserver.h"
32 #include "LyXAction.h"
33 #include "insets/inseturl.h"
34 #include "insets/insetlatexaccent.h"
35 #include "insets/insettoc.h"
36 #include "insets/insetlof.h"
37 #include "insets/insetloa.h"
38 #include "insets/insetlot.h"
39 #include "insets/insetref.h"
40 #include "insets/insetparent.h"
41 #include "insets/insetindex.h"
42 #include "insets/insetinclude.h"
43 #include "insets/insetbib.h"
44 #include "insets/insettext.h"
45 //#include "insets/insetnumber.h"
46 #include "insets/insetert.h"
47 #include "insets/insetgraphics.h"
48 #include "insets/insetfoot.h"
49 #include "mathed/formulamacro.h"
51 #include "spellchecker.h" // RVDK_PATCH_5
52 #include "minibuffer.h"
56 #include "lyx_gui_misc.h"
57 #include "support/filetools.h"
58 #include "support/FileInfo.h"
59 #include "support/syscall.h"
60 #include "support/lstrings.h"
61 #include "support/path.h"
66 #include "trans_mgr.h"
67 #include "ImportLaTeX.h"
68 #include "ImportNoweb.h"
77 extern bool cursor_follows_scrollbar;
79 extern void InsertAsciiFile(BufferView *, string const &, bool);
80 extern void math_insert_symbol(char const *);
81 extern Bool math_insert_greek(char const); // why "Bool"?
82 extern BufferList bufferlist;
83 extern LyXServer * lyxserver;
84 extern short greek_kb_flag;
85 extern FD_form_toc * fd_form_toc;
86 extern bool selection_possible;
88 extern kb_keymap * toplevel_keymap;
90 extern void MenuWrite(Buffer *);
91 extern void MenuWriteAs(Buffer *);
92 extern int MenuRunLaTeX(Buffer *);
93 extern int MenuBuildProg(Buffer *);
94 extern int MenuRunChktex(Buffer *);
95 extern bool CreatePostscript(Buffer *, bool);
96 extern void MenuPrint(Buffer *);
97 extern void MenuSendto();
98 extern void QuitLyX();
99 extern void MenuFax(Buffer *);
100 extern void MenuExport(Buffer *, string const &);
101 extern void MenuPasteSelection(char at);
102 extern LyXAction lyxaction;
104 extern tex_accent_struct get_accent(kb_action action);
106 extern void AutoSave();
107 extern void SetUpdateTimer(float timer = 0.3);
108 extern void FreeUpdateTimer();
109 extern bool PreviewDVI(Buffer *);
110 extern bool PreviewPostscript(Buffer *);
111 extern void MenuInsertLabel(char const *);
112 extern void MenuInsertRef();
113 extern void MenuLayoutCharacter();
114 extern void MenuLayoutParagraph();
115 extern void MenuLayoutDocument();
116 extern void MenuLayoutPaper();
117 extern void MenuLayoutTable(int flag);
118 extern void MenuLayoutQuotes();
119 extern void MenuLayoutPreamble();
120 extern void MenuLayoutSave();
121 extern void bulletForm();
123 extern Buffer * NewLyxFile(string const &);
124 extern void LoadLyXFile(string const &);
125 extern void Reconfigure(BufferView *);
127 extern LyXTextClass::size_type current_layout;
128 extern int getISOCodeFromLaTeX(char *);
130 extern void ShowLatexLog();
132 /* === globals =========================================================== */
134 bool LyXFunc::show_sc = true;
137 LyXFunc::LyXFunc(LyXView * o)
141 lyx_dead_action = LFUN_NOACTION;
142 lyx_calling_dead_action = LFUN_NOACTION;
147 // I changed this func slightly. I commented out the ...FinishUndo(),
148 // this means that all places that used to have a moveCursorUpdate, now
149 // have a ...FinishUndo() as the preceeding statement. I have also added
150 // a moveCursorUpdate to some of the functions that updated the cursor, but
151 // that did not show its new position.
153 void LyXFunc::moveCursorUpdate(bool selecting)
155 if (selecting || owner->view()->text->mark_set) {
156 owner->view()->text->SetSelection();
157 owner->view()->toggleToggle();
158 owner->view()->update(0);
160 owner->view()->update(-2); // this IS necessary
164 owner->view()->showCursor();
166 /* ---> Everytime the cursor is moved, show the current font state. */
167 // should this too me moved out of this func?
168 //owner->getMiniBuffer()->Set(CurrentState());
169 owner->view()->setState();
173 int LyXFunc::processKeyEvent(XEvent * ev)
177 XKeyEvent * keyevent = &ev->xkey;
178 KeySym keysym_return;
180 int num_bytes = LyXLookupString(ev, s_r, 10, &keysym_return);
181 s_r[num_bytes] = '\0';
183 if (lyxerr.debugging(Debug::KEY)) {
184 char * tmp = XKeysymToString(keysym_return);
185 string stm = (tmp ? tmp : "");
186 lyxerr << "KeySym is "
189 << keysym_return << "]"
190 << " and num_bytes is "
192 << " the string returned is \""
193 << s_r << '\"' << endl;
195 // Do nothing if we have nothing (JMarc)
196 if (num_bytes == 0 && keysym_return == NoSymbol) {
197 lyxerr[Debug::KEY] << "Empty kbd action (probably composing)"
202 // this function should be used always [asierra060396]
203 UpdatableInset * tli = owner->view()->the_locking_inset;
204 if (owner->view()->available() && tli && (keysym_return==XK_Escape)) {
205 if (tli == tli->GetLockingInset()) {
206 owner->view()->unlockInset(tli);
207 owner->view()->text->CursorRight();
208 moveCursorUpdate(false);
209 owner->getMiniBuffer()->Set(CurrentState());
211 tli->UnlockInsetInInset(owner->view(),
212 tli->GetLockingInset());
217 // Can we be sure that this will work for all X-Windows
218 // implementations? (Lgb)
219 // This code snippet makes lyx ignore some keys. Perhaps
220 // all of them should be explictly mentioned?
221 if((keysym_return >= XK_Shift_L && keysym_return <= XK_Hyper_R)
222 || keysym_return == XK_Mode_switch || keysym_return == 0x0)
225 // Do a one-deep top-level lookup for
226 // cancel and meta-fake keys. RVDK_PATCH_5
227 cancel_meta_seq.reset();
229 int action = cancel_meta_seq.addkey(keysym_return, keyevent->state
230 &(ShiftMask|ControlMask
233 // When not cancel or meta-fake, do the normal lookup.
234 // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
235 // Mostly, meta_fake_bit = 0. RVDK_PATCH_5.
236 if ( (action != LFUN_CANCEL) && (action != LFUN_META_FAKE) ) {
238 // remove Caps Lock and Mod2 as a modifiers
239 action = keyseq.addkey(keysym_return,
240 (keyevent->state | meta_fake_bit)
241 &(ShiftMask|ControlMask
244 // Dont remove this unless you know what you are doing.
247 if (action == 0) action = LFUN_PREFIX;
249 if (lyxerr.debugging(Debug::KEY)) {
255 << num_bytes << "]" << endl;
258 // already here we know if it any point in going further
259 // why not return already here if action == -1 and
260 // num_bytes == 0? (Lgb)
262 if(keyseq.length > 1 || keyseq.length < -1) {
265 owner->getMiniBuffer()->Set(buf);
269 if (keyseq.length < -1) { // unknown key sequence...
273 owner->getMiniBuffer()->Set(_("Unknown sequence:"), buf);
277 char isochar = keyseq.getiso();
278 if (!(keyevent->state&ControlMask) &&
279 !(keyevent->state&Mod1Mask) &&
280 (isochar && keysym_return < 0xF000)) {
283 if (argument.empty()) {
284 lyxerr.debug() << "Empty argument!" << endl;
285 // This can`t possibly be of any use
286 // so we`ll skip the dispatch.
290 if (action == LFUN_SELFINSERT) {
294 bool tmp_sc = show_sc;
296 Dispatch(action, argument.c_str());
303 LyXFunc::func_status LyXFunc::getStatus(int ac) const
306 func_status flag = LyXFunc::OK;
308 Buffer * buf = owner->buffer();
310 if (lyxaction.isPseudoAction(ac))
311 action = lyxaction.retrieveActionArg(ac, argument);
313 action = static_cast<kb_action>(ac);
315 if (action == LFUN_UNKNOWN_ACTION) {
316 setErrorMessage(N_("Unknown action"));
317 return LyXFunc::Unknown;
320 // Check whether we need a buffer
321 if (!lyxaction.funcHasFlag(action, LyXAction::NoBuffer)) {
322 // Yes we need a buffer, do we have one?
325 // Can we use a readonly buffer?
326 if (buf->isReadonly() &&
327 !lyxaction.funcHasFlag(action,
328 LyXAction::ReadOnly)) {
330 setErrorMessage(N_("Document is read-only"));
331 flag |= LyXFunc::Disabled;
335 setErrorMessage(N_("Command not allowed with"
336 "out any document open"));
337 flag |= LyXFunc::Disabled;
341 if (flag & LyXFunc::Disabled)
344 // I would really like to avoid having this switch and rather try to
345 // encode this in the function itself.
346 static bool noLaTeX = lyxrc.latex_command == "none";
347 bool disable = false;
350 disable = noLaTeX || lyxrc.view_dvi_command == "none";
353 disable = noLaTeX || lyxrc.view_ps_command == "none";
360 disable = noLaTeX || lyxrc.print_command == "none";
363 disable = noLaTeX || lyxrc.fax_command == "none";
366 if (argument == "latex")
367 disable = lyxrc.relyx_command == "none";
368 if (argument == "linuxdoc")
369 disable = lyxrc.linuxdoc_to_lyx_command == "none";
372 if (argument == "dvi" || argument == "postscript")
374 if (argument == "html")
375 disable = lyxrc.html_command == "none";
376 if (argument == "html-linuxdoc")
377 disable = lyxrc.linuxdoc_to_html_command == "none";
378 if (argument == "html-docbook")
379 disable = lyxrc.docbook_to_html_command == "none";
382 disable = buf->undostack.empty();
385 disable = buf->redostack.empty();
387 case LFUN_SPELLCHECK:
388 disable = lyxrc.isp_command == "none";
391 disable = lyxrc.chktex_command == "none";
393 case LFUN_LAYOUT_TABLE:
394 disable = ! owner->view()->text->cursor.par->table;
400 flag |= LyXFunc::Disabled;
403 func_status box = LyXFunc::ToggleOff;
404 LyXFont font = owner->view()->text->real_current_font;
407 if (font.emph() == LyXFont::ON)
408 box = LyXFunc::ToggleOn;
411 if (font.noun() == LyXFont::ON)
412 box = LyXFunc::ToggleOn;
415 if (font.series() == LyXFont::BOLD_SERIES)
416 box = LyXFunc::ToggleOn;
419 if (font.latex() == LyXFont::ON)
420 box = LyXFunc::ToggleOn;
433 string LyXFunc::Dispatch(string const & s)
435 // Split command string into command and argument
436 string cmd, line = frontStrip(s);
437 string arg = strip(frontStrip(split(line, cmd, ' ')));
439 return Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
443 string LyXFunc::Dispatch(int ac,
444 char const * do_not_use_this_arg)
449 // we have not done anything wrong yet.
451 dispatch_buffer.clear();
453 // if action is a pseudo-action, we need the real action
454 if (lyxaction.isPseudoAction(ac)) {
456 action = static_cast<kb_action>
457 (lyxaction.retrieveActionArg(ac, tmparg));
461 action = static_cast<kb_action>(ac);
462 if (do_not_use_this_arg)
463 argument = do_not_use_this_arg; // except here
466 selection_possible = false;
468 if (owner->view()->available())
469 owner->view()->hideCursor();
471 // We cannot use this function here
472 if (getStatus(action) & Disabled)
473 goto exit_with_message;
475 commandshortcut.clear();
477 if (lyxrc.display_shortcuts && show_sc) {
478 if (action != LFUN_SELFINSERT) {
479 // Put name of command and list of shortcuts
480 // for it in minibuffer
481 string comname = lyxaction.getActionName(action);
483 int pseudoaction = action;
484 bool argsadded = false;
486 if (!argument.empty()) {
487 // If we have the command with argument,
490 lyxaction.searchActionArg(action,
493 if (pseudoaction == -1) {
494 pseudoaction = action;
496 comname += " " + argument;
501 string shortcuts = toplevel_keymap->findbinding(pseudoaction);
503 if (!shortcuts.empty()) {
504 comname += ": " + shortcuts;
505 } else if (!argsadded) {
506 comname += " " + argument;
509 if (!comname.empty()) {
510 comname = strip(comname);
511 commandshortcut = "(" + comname + ')';
512 owner->getMiniBuffer()->Set(commandshortcut);
513 // Here we could even add a small pause,
514 // to annoy the user and make him learn
516 // No! That will just annoy, not teach
517 // anything. The user will read the messages
518 // if they are interested. (Asger)
523 // If in math mode pass the control to
524 // the math inset [asierra060396]
525 if (owner->view()->available() &&
526 owner->view()->the_locking_inset) {
528 || (action == LFUN_UNKNOWN_ACTION
529 && keyseq.length >= -1)) {
530 if (action == LFUN_UNKNOWN_ACTION
531 && argument.empty()) {
532 argument = keyseq.getiso();
534 // Undo/Redo pre 0.13 is a bit tricky for insets.
535 if (action == LFUN_UNDO) {
537 UpdatableInset * inset =
538 owner->view()->the_locking_inset;
539 inset->GetCursorPos(slx, sly);
540 owner->view()->unlockInset(inset);
541 owner->view()->menuUndo();
542 if (owner->view()->text->cursor.par->
543 IsInset(owner->view()->text->cursor.pos)) {
544 inset = static_cast<UpdatableInset*>(
545 owner->view()->text->cursor.par->
546 GetInset(owner->view()->text->
552 inset->Edit(owner->view(),slx,sly,0);
554 } else if (action == LFUN_REDO) {
556 UpdatableInset * inset = owner->view()->
558 inset->GetCursorPos(slx, sly);
559 owner->view()->unlockInset(inset);
560 owner->view()->menuRedo();
561 inset = static_cast<UpdatableInset*>(
562 owner->view()->text->cursor.par->
563 GetInset(owner->view()->text->
566 inset->Edit(owner->view(),slx,sly,0);
568 } else if (owner->view()->the_locking_inset->
569 LocalDispatch(owner->view(), action,
571 UpdatableInset::DISPATCHED)
574 setMessage(N_("Text mode"));
576 case LFUN_UNKNOWN_ACTION:
577 case LFUN_BREAKPARAGRAPH:
579 owner->view()->text->CursorRight();
580 owner->view()->setState();
581 owner->getMiniBuffer()->Set(CurrentState());
584 if (!owner->view()->text->cursor.par->isRightToLeftPar()) {
585 owner->view()->text->CursorRight();
586 moveCursorUpdate(false);
587 owner->getMiniBuffer()->
592 if (owner->view()->text->cursor.par->isRightToLeftPar()) {
593 owner->view()->text->CursorRight();
594 moveCursorUpdate(false);
595 owner->getMiniBuffer()->
607 // --- Misc -------------------------------------------
608 case LFUN_WORDFINDFORWARD :
609 case LFUN_WORDFINDBACKWARD : {
610 static string last_search;
611 string searched_string;
613 if (!argument.empty()) {
614 last_search = argument;
615 searched_string = argument;
617 searched_string = last_search;
620 LyXText * ltCur = owner->view()->text ;
622 if (!searched_string.empty() &&
623 ((action == LFUN_WORDFINDBACKWARD) ?
624 ltCur->SearchBackward(searched_string.c_str()) :
625 ltCur->SearchForward(searched_string.c_str()))) {
627 // ??? What is that ???
628 owner->view()->update(-2);
631 // clear the selection (if there is any)
632 owner->view()->toggleSelection();
633 owner->view()->text->ClearSelection();
635 // Move cursor so that successive C-s 's will not stand in place.
636 if( action == LFUN_WORDFINDFORWARD )
637 owner->view()->text->CursorRightOneWord();
638 owner->view()->text->FinishUndo();
639 moveCursorUpdate(false);
642 // set the new selection
643 // SetSelectionOverLenChars(owner->view()->currentBuffer()->text, iLenSelected);
644 owner->view()->toggleSelection(false);
648 // REMOVED : if (owner->view()->getWorkArea()->focus)
649 owner->view()->showCursor();
655 if (owner->view()->available()) {
656 owner->view()->update(-2);
659 keyseq.print(buf, true);
660 owner->getMiniBuffer()->Set(buf, string(), string(), 1);
664 // --- Misc -------------------------------------------
665 case LFUN_EXEC_COMMAND:
666 owner->getMiniBuffer()->ExecCommand();
669 case LFUN_CANCEL: // RVDK_PATCH_5
672 if(owner->view()->available())
673 // cancel any selection
674 Dispatch(LFUN_MARK_OFF, 0);
675 setMessage(N_("Cancel"));
678 case LFUN_META_FAKE: // RVDK_PATCH_5
680 meta_fake_bit = Mod1Mask;
682 keyseq.print(buf, true);
683 string res = string("M-") + buf;
684 setMessage(buf); // RVDK_PATCH_5
688 case LFUN_READ_ONLY_TOGGLE:
689 if (owner->buffer()->lyxvc.inUse()) {
690 owner->buffer()->lyxvc.toggleReadOnly();
692 owner->buffer()->setReadonly(
693 !owner->buffer()->isReadonly());
697 case LFUN_CENTER: // this is center and redraw.
698 owner->view()->center();
702 if (owner->view()->available()) {
703 owner->view()->text->toggleAppendix();
704 owner->view()->update(1);
708 // --- Menus -----------------------------------------------
713 case LFUN_MENUNEWTMPLT:
721 case LFUN_CLOSEBUFFER:
726 owner->getMiniBuffer()->Set(_("Saving document"),
727 MakeDisplayPath(owner->buffer()->fileName()),
729 MenuWrite(owner->buffer());
730 //owner->getMiniBuffer()->
731 // Set(_("Document saved as"),
732 // MakeDisplayPath(owner->buffer()->fileName()));
734 //owner->getMiniBuffer()->Set(_("Save failed!"));
738 case LFUN_MENUWRITEAS:
739 MenuWriteAs(owner->buffer());
742 case LFUN_MENURELOAD:
747 PreviewDVI(owner->buffer());
751 PreviewPostscript(owner->buffer());
755 MenuRunLaTeX(owner->buffer());
759 MenuBuildProg(owner->buffer());
763 MenuRunChktex(owner->buffer());
767 CreatePostscript(owner->buffer(), false);
771 MenuPrint(owner->buffer());
775 MenuFax(owner->buffer());
779 MenuExport(owner->buffer(), argument);
784 //needs argument as string
785 string imtyp = argument;
788 if (imtyp == "latex") {
789 doImportLaTeX(false);
792 else if (imtyp == "ascii") {
793 doImportASCII(false);
794 } else if (imtyp == "asciiparagraph") {
797 } else if (imtyp == "noweb") {
799 } else if (imtyp == "linuxdoc") {
802 setErrorMessage(string(N_("Unknown import type: "))
814 if (fd_form_toc->form_toc->visible) {
815 fl_raise_form(fd_form_toc->form_toc);
817 static int ow = -1, oh;
818 fl_show_form(fd_form_toc->form_toc,
820 FL_FREE_SIZE, FL_FULLBORDER,
821 _("Table of Contents"));
823 ow = fd_form_toc->form_toc->w;
824 oh = fd_form_toc->form_toc->h;
826 fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
830 case LFUN_TOC_INSERT:
832 Inset * new_inset = new InsetTOC(owner->buffer());
833 owner->view()->insertInset(new_inset, "Standard", true);
837 case LFUN_LOF_INSERT:
839 Inset * new_inset = new InsetLOF(owner->buffer());
840 owner->view()->insertInset(new_inset, "Standard", true);
844 case LFUN_LOA_INSERT:
846 Inset * new_inset = new InsetLOA(owner->buffer());
847 owner->view()->insertInset(new_inset, "Standard", true);
851 case LFUN_LOT_INSERT:
853 Inset * new_inset = new InsetLOT(owner->buffer());
854 owner->view()->insertInset(new_inset, "Standard", true);
866 case LFUN_INSERT_GRAPHICS:
868 Inset * new_inset = new InsetGraphics;
869 owner->view()->insertInset(new_inset);
878 owner->view()->menuUndo();
882 owner->view()->menuRedo();
885 case LFUN_MENUSEARCH:
887 // Ok this is one _very_ bad solution, but I think that some
888 // of this will be rewritten as part of GUI indep anyway.
890 static LyXFindReplace FR_;
891 FR_.StartSearch(owner->view());
897 owner->view()->paste();
898 owner->view()->setState();
901 case LFUN_PASTESELECTION:
904 if (argument == "paragraph") asPara = true;
905 MenuPasteSelection(asPara);
910 owner->view()->cut();
914 owner->view()->copy();
917 case LFUN_LAYOUT_COPY:
918 owner->view()->copyEnvironment();
921 case LFUN_LAYOUT_PASTE:
922 owner->view()->pasteEnvironment();
923 owner->view()->setState();
927 owner->view()->gotoError();
930 case LFUN_REMOVEERRORS:
931 if (owner->view()->removeAutoInsets()) {
932 owner->view()->redraw();
933 owner->view()->fitCursor();
934 owner->view()->updateScrollbar();
939 owner->view()->gotoNote();
943 owner->view()->openStuff();
946 case LFUN_HYPHENATION:
947 owner->view()->hyphenationPoint();
951 owner->view()->ldots();
954 case LFUN_END_OF_SENTENCE:
955 owner->view()->endOfSentenceDot();
958 case LFUN_MENU_SEPARATOR:
959 owner->view()->menuSeparator();
963 owner->view()->hfill();
967 changeDepth(owner->view(), 0);
971 changeDepth(owner->view(), -1);
974 case LFUN_DEPTH_PLUS:
975 changeDepth(owner->view(), 1);
984 owner->view()->setState();
985 owner->getMiniBuffer()->Set(CurrentState());
992 case LFUN_RECONFIGURE:
993 Reconfigure(owner->view());
997 if (owner->view()->available()
998 && !owner->view()->text->selection
999 && owner->view()->text->cursor.par->footnoteflag
1000 != LyXParagraph::NO_FOOTNOTE)
1001 { // only melt footnotes with FOOTMELT, not margins etc
1002 if(owner->view()->text->cursor.par->footnotekind == LyXParagraph::FOOTNOTE)
1003 Melt(owner->view());
1006 Foot(owner->view());
1007 owner->view()->setState();
1010 case LFUN_MARGINMELT:
1011 if (owner->view()->available()
1012 && !owner->view()->text->selection
1013 && owner->view()->text->cursor.par->footnoteflag
1014 != LyXParagraph::NO_FOOTNOTE) {
1015 // only melt margins
1016 if(owner->view()->text->cursor.par->footnotekind == LyXParagraph::MARGIN)
1017 Melt(owner->view());
1019 Margin(owner->view());
1020 owner->view()->setState();
1023 // --- version control -------------------------------
1024 case LFUN_VC_REGISTER:
1026 if (!owner->buffer()->lyxvc.inUse())
1027 owner->buffer()->lyxvc.registrer();
1031 case LFUN_VC_CHECKIN:
1033 if (owner->buffer()->lyxvc.inUse()
1034 && !owner->buffer()->isReadonly())
1035 owner->buffer()->lyxvc.checkIn();
1039 case LFUN_VC_CHECKOUT:
1041 if (owner->buffer()->lyxvc.inUse()
1042 && owner->buffer()->isReadonly())
1043 owner->buffer()->lyxvc.checkOut();
1047 case LFUN_VC_REVERT:
1049 owner->buffer()->lyxvc.revert();
1055 owner->buffer()->lyxvc.undoLast();
1059 case LFUN_VC_HISTORY:
1061 owner->buffer()->lyxvc.showLog();
1065 // --- buffers ----------------------------------------
1067 case LFUN_FILE_INSERT:
1069 MenuInsertLyXFile(argument);
1073 case LFUN_FILE_INSERT_ASCII:
1075 bool asPara = (argument == "paragraph");
1076 InsertAsciiFile(owner->view(), string(), asPara);
1082 // servercmd: argument must be <file>:<template>
1083 Buffer * tmpbuf = NewLyxFile(argument);
1085 owner->view()->buffer(tmpbuf);
1089 case LFUN_FILE_OPEN:
1090 owner->view()->buffer(bufferlist.loadLyXFile(argument));
1093 case LFUN_LATEX_LOG:
1099 lyxerr.debug() << "LFUN_LAYOUTNO: (arg) " << argument << endl;
1100 int sel = strToInt(argument);
1101 lyxerr.debug() << "LFUN_LAYOUTNO: (sel) "<< sel << endl;
1103 // Should this give a setMessage instead?
1105 return string(); // illegal argument
1107 --sel; // sel 1..., but layout 0...
1109 // Pretend we got the name instead.
1110 Dispatch(int(LFUN_LAYOUT),
1111 textclasslist.NameOfLayout(owner->view()->
1120 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1121 << argument << endl;
1123 // Derive layout number from given argument (string)
1124 // and current buffer's textclass (number). */
1125 LyXTextClassList::ClassList::size_type tclass =
1126 owner->view()->text->bparams->textclass;
1127 pair <bool, LyXTextClass::size_type> layout =
1128 textclasslist.NumberOfLayout(tclass, argument);
1130 // If the entry is obsolete, use the new one instead.
1132 string obs = textclasslist.Style(tclass,layout.second)
1136 textclasslist.NumberOfLayout(tclass, obs);
1139 // see if we found the layout number:
1140 if (!layout.first) {
1141 setErrorMessage(string(N_("Layout ")) + argument +
1146 if (current_layout != layout.second) {
1147 owner->view()->hideCursor();
1148 current_layout = layout.second;
1149 owner->view()->update(-2);
1150 owner->view()->text->
1151 SetLayout(layout.second);
1152 owner->getToolbar()->combox->
1153 select(owner->view()->
1156 owner->view()->update(1);
1157 owner->view()->setState();
1162 case LFUN_LAYOUT_DOCUMENT:
1163 MenuLayoutDocument();
1166 case LFUN_LAYOUT_PARAGRAPH:
1167 MenuLayoutParagraph();
1170 case LFUN_LAYOUT_CHARACTER:
1171 MenuLayoutCharacter();
1174 case LFUN_LAYOUT_TABLE:
1177 if (argument == "true") flag = 1;
1178 MenuLayoutTable(flag);
1182 case LFUN_LAYOUT_PAPER:
1186 case LFUN_LAYOUT_QUOTES:
1190 case LFUN_LAYOUT_PREAMBLE:
1191 MenuLayoutPreamble();
1194 case LFUN_LAYOUT_SAVE_DEFAULT:
1198 case LFUN_DROP_LAYOUTS_CHOICE:
1199 owner->getToolbar()->combox->Show();
1205 owner->view()->setState();
1206 owner->getMiniBuffer()->Set(CurrentState());
1212 owner->getMiniBuffer()->Set(CurrentState());
1217 owner->getMiniBuffer()->Set(CurrentState());
1222 owner->getMiniBuffer()->Set(CurrentState());
1227 owner->getMiniBuffer()->Set(CurrentState());
1232 owner->getMiniBuffer()->Set(CurrentState());
1237 owner->getMiniBuffer()->Set(CurrentState());
1242 owner->getMiniBuffer()->Set(CurrentState());
1245 case LFUN_UNDERLINE:
1247 owner->getMiniBuffer()->Set(CurrentState());
1250 case LFUN_FONT_SIZE:
1252 owner->getMiniBuffer()->Set(CurrentState());
1255 case LFUN_FONT_STATE:
1256 setMessage(CurrentState());
1259 case LFUN_UPCASE_WORD:
1260 owner->view()->update(-2);
1262 owner->view()->text->ChangeWordCase(LyXText::text_uppercase);
1263 owner->view()->update(1);
1267 case LFUN_LOWCASE_WORD:
1268 owner->view()->update(-2);
1270 owner->view()->text->ChangeWordCase(LyXText::text_lowercase);
1271 owner->view()->update(1);
1275 case LFUN_CAPITALIZE_WORD:
1276 owner->view()->update(-2);
1278 owner->view()->text->ChangeWordCase(LyXText::text_capitalization);
1279 owner->view()->update(1);
1283 case LFUN_INSERT_LABEL:
1284 MenuInsertLabel(argument.c_str());
1287 case LFUN_INSERT_REF:
1291 case LFUN_REFTOGGLE:
1294 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1296 if (inset->getFlag() == InsetRef::REF)
1297 inset->setFlag(InsetRef::PAGE_REF);
1299 inset->setFlag(InsetRef::REF);
1300 owner->view()->updateInset(inset, true);
1302 setErrorMessage(N_("No cross-reference to toggle"));
1309 owner->view()->restorePosition();
1315 string label(argument);
1316 if (label.empty()) {
1318 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1320 label = inset->getContents();
1323 if (!label.empty()) {
1324 owner->view()->savePosition();
1325 owner->view()->gotoLabel(label.c_str());
1330 case LFUN_MENU_OPEN_BY_NAME:
1331 owner->getMenus()->openByName(argument);
1332 break; // RVDK_PATCH_5
1334 case LFUN_SPELLCHECK:
1335 if (lyxrc.isp_command != "none")
1336 ShowSpellChecker(owner->view());
1337 break; // RVDK_PATCH_5
1339 // --- Cursor Movements -----------------------------
1342 LyXText * tmptext = owner->view()->text;
1343 bool is_rtl = tmptext->cursor.par->isRightToLeftPar();
1344 if(!tmptext->mark_set)
1345 owner->view()->beforeChange();
1346 owner->view()->update(-2);
1348 tmptext->CursorLeft();
1349 if (tmptext->cursor.pos < tmptext->cursor.par->Last()
1350 && tmptext->cursor.par->GetChar(tmptext->cursor.pos)
1351 == LyXParagraph::META_INSET
1352 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)
1353 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)->Editable() == Inset::HIGHLY_EDITABLE){
1354 Inset * tmpinset = tmptext->cursor.par->GetInset(tmptext->cursor.pos);
1355 setMessage(tmpinset->EditMessage());
1356 tmpinset->Edit(owner->view(), 0, 0, 0);
1360 tmptext->CursorRight();
1361 owner->view()->text->FinishUndo();
1362 moveCursorUpdate(false);
1363 owner->getMiniBuffer()->Set(CurrentState());
1369 // This is soooo ugly. Isn`t it possible to make
1370 // it simpler? (Lgb)
1371 LyXText * txt = owner->view()->text;
1372 bool is_rtl = txt->cursor.par->isRightToLeftPar();
1373 if(!txt->mark_set) owner->view()->beforeChange();
1374 owner->view()->update(-2);
1377 if (txt->cursor.pos < txt->cursor.par->Last()
1378 && txt->cursor.par->GetChar(txt->cursor.pos)
1379 == LyXParagraph::META_INSET
1380 && txt->cursor.par->GetInset(txt->cursor.pos)
1381 && txt->cursor.par->GetInset(txt->cursor.pos)->Editable() == Inset::HIGHLY_EDITABLE) {
1382 Inset * tmpinset = txt->cursor.par->GetInset(txt->cursor.pos);
1383 setMessage(tmpinset->EditMessage());
1384 tmpinset->Edit(owner->view(),
1385 tmpinset->width(owner->view()->painter(),
1386 txt->GetFont(txt->cursor.par,
1394 owner->view()->text->FinishUndo();
1395 moveCursorUpdate(false);
1396 owner->getMiniBuffer()->Set(CurrentState());
1401 if(!owner->view()->text->mark_set) owner->view()->beforeChange();
1402 owner->view()->update(-3);
1403 owner->view()->text->CursorUp();
1404 owner->view()->text->FinishUndo();
1405 moveCursorUpdate(false);
1406 owner->getMiniBuffer()->Set(CurrentState());
1410 if(!owner->view()->text->mark_set)
1411 owner->view()->beforeChange();
1412 owner->view()->update(-3);
1413 owner->view()->text->CursorDown();
1414 owner->view()->text->FinishUndo();
1415 moveCursorUpdate(false);
1416 owner->getMiniBuffer()->Set(CurrentState());
1419 case LFUN_UP_PARAGRAPH:
1420 if(!owner->view()->text->mark_set)
1421 owner->view()->beforeChange();
1422 owner->view()->update(-3);
1423 owner->view()->text->CursorUpParagraph();
1424 owner->view()->text->FinishUndo();
1425 moveCursorUpdate(false);
1426 owner->getMiniBuffer()->Set(CurrentState());
1429 case LFUN_DOWN_PARAGRAPH:
1430 if(!owner->view()->text->mark_set)
1431 owner->view()->beforeChange();
1432 owner->view()->update(-3);
1433 owner->view()->text->CursorDownParagraph();
1434 owner->view()->text->FinishUndo();
1435 moveCursorUpdate(false);
1436 owner->getMiniBuffer()->Set(CurrentState());
1440 if(!owner->view()->text->mark_set)
1441 owner->view()->beforeChange();
1442 owner->view()->update(-3);
1443 owner->view()->cursorPrevious();
1444 owner->view()->text->FinishUndo();
1445 moveCursorUpdate(false);
1446 owner->getMiniBuffer()->Set(CurrentState());
1450 if(!owner->view()->text->mark_set)
1451 owner->view()->beforeChange();
1452 owner->view()->update(-3);
1453 owner->view()->cursorNext();
1454 owner->view()->text->FinishUndo();
1455 moveCursorUpdate(false);
1456 owner->getMiniBuffer()->Set(CurrentState());
1460 if(!owner->view()->text->mark_set)
1461 owner->view()->beforeChange();
1462 owner->view()->update(-2);
1463 owner->view()->text->CursorHome();
1464 owner->view()->text->FinishUndo();
1465 moveCursorUpdate(false);
1466 owner->getMiniBuffer()->Set(CurrentState());
1470 if(!owner->view()->text->mark_set)
1471 owner->view()->beforeChange();
1472 owner->view()->update(-2);
1473 owner->view()->text->CursorEnd();
1474 owner->view()->text->FinishUndo();
1475 moveCursorUpdate(false);
1476 owner->getMiniBuffer()->Set(CurrentState());
1480 if(!owner->view()->text->mark_set)
1481 owner->view()->beforeChange();
1482 owner->view()->update(-2);
1483 owner->view()->text->CursorTab();
1484 owner->view()->text->FinishUndo();
1485 moveCursorUpdate(false);
1486 owner->getMiniBuffer()->Set(CurrentState());
1489 case LFUN_WORDRIGHT:
1490 if(!owner->view()->text->mark_set)
1491 owner->view()->beforeChange();
1492 owner->view()->update(-2);
1493 if (owner->view()->text->cursor.par->isRightToLeftPar())
1494 owner->view()->text->CursorLeftOneWord();
1496 owner->view()->text->CursorRightOneWord();
1497 owner->view()->text->FinishUndo();
1498 moveCursorUpdate(false);
1499 owner->getMiniBuffer()->Set(CurrentState());
1503 if(!owner->view()->text->mark_set)
1504 owner->view()->beforeChange();
1505 owner->view()->update(-2);
1506 if (owner->view()->text->cursor.par->isRightToLeftPar())
1507 owner->view()->text->CursorRightOneWord();
1509 owner->view()->text->CursorLeftOneWord();
1510 owner->view()->text->FinishUndo();
1511 moveCursorUpdate(false);
1512 owner->getMiniBuffer()->Set(CurrentState());
1515 case LFUN_BEGINNINGBUF:
1516 if(!owner->view()->text->mark_set)
1517 owner->view()->beforeChange();
1518 owner->view()->update(-2);
1519 owner->view()->text->CursorTop();
1520 owner->view()->text->FinishUndo();
1521 moveCursorUpdate(false);
1522 owner->getMiniBuffer()->Set(CurrentState());
1526 if(!owner->view()->text->mark_set)
1527 owner->view()->beforeChange();
1528 owner->view()->update(-2);
1529 owner->view()->text->CursorBottom();
1530 owner->view()->text->FinishUndo();
1531 moveCursorUpdate(false);
1532 owner->getMiniBuffer()->Set(CurrentState());
1536 /* cursor selection ---------------------------- */
1538 owner->view()->update(-2);
1539 if (owner->view()->text->cursor.par->isRightToLeftPar())
1540 owner->view()->text->CursorLeft();
1542 owner->view()->text->CursorRight();
1543 owner->view()->text->FinishUndo();
1544 moveCursorUpdate(true);
1545 owner->getMiniBuffer()->Set(CurrentState());
1549 owner->view()->update(-2);
1550 if (owner->view()->text->cursor.par->isRightToLeftPar())
1551 owner->view()->text->CursorRight();
1553 owner->view()->text->CursorLeft();
1554 owner->view()->text->FinishUndo();
1555 moveCursorUpdate(true);
1556 owner->getMiniBuffer()->Set(CurrentState());
1560 owner->view()->update(-2);
1561 owner->view()->text->CursorUp();
1562 owner->view()->text->FinishUndo();
1563 moveCursorUpdate(true);
1564 owner->getMiniBuffer()->Set(CurrentState());
1568 owner->view()->update(-2);
1569 owner->view()->text->CursorDown();
1570 owner->view()->text->FinishUndo();
1571 moveCursorUpdate(true);
1572 owner->getMiniBuffer()->Set(CurrentState());
1575 case LFUN_UP_PARAGRAPHSEL:
1576 owner->view()->update(-2);
1577 owner->view()->text->CursorUpParagraph();
1578 owner->view()->text->FinishUndo();
1579 moveCursorUpdate(true);
1580 owner->getMiniBuffer()->Set(CurrentState());
1583 case LFUN_DOWN_PARAGRAPHSEL:
1584 owner->view()->update(-2);
1585 owner->view()->text->CursorDownParagraph();
1586 owner->view()->text->FinishUndo();
1587 moveCursorUpdate(true);
1588 owner->getMiniBuffer()->Set(CurrentState());
1592 owner->view()->update(-2);
1593 owner->view()->cursorPrevious();
1594 owner->view()->text->FinishUndo();
1595 moveCursorUpdate(true);
1596 owner->getMiniBuffer()->Set(CurrentState());
1600 owner->view()->update(-2);
1601 owner->view()->cursorNext();
1602 owner->view()->text->FinishUndo();
1603 moveCursorUpdate(true);
1604 owner->getMiniBuffer()->Set(CurrentState());
1608 owner->view()->update(-2);
1609 owner->view()->text->CursorHome();
1610 owner->view()->text->FinishUndo();
1611 moveCursorUpdate(true);
1612 owner->getMiniBuffer()->Set(CurrentState());
1616 owner->view()->update(-2);
1617 owner->view()->text->CursorEnd();
1618 owner->view()->text->FinishUndo();
1619 moveCursorUpdate(true);
1620 owner->getMiniBuffer()->Set(CurrentState());
1623 case LFUN_WORDRIGHTSEL:
1624 owner->view()->update(-2);
1625 if (owner->view()->text->cursor.par->isRightToLeftPar())
1626 owner->view()->text->CursorLeftOneWord();
1628 owner->view()->text->CursorRightOneWord();
1629 owner->view()->text->FinishUndo();
1630 moveCursorUpdate(true);
1631 owner->getMiniBuffer()->Set(CurrentState());
1634 case LFUN_WORDLEFTSEL:
1635 owner->view()->update(-2);
1636 if (owner->view()->text->cursor.par->isRightToLeftPar())
1637 owner->view()->text->CursorRightOneWord();
1639 owner->view()->text->CursorLeftOneWord();
1640 owner->view()->text->FinishUndo();
1641 moveCursorUpdate(true);
1642 owner->getMiniBuffer()->Set(CurrentState());
1645 case LFUN_BEGINNINGBUFSEL:
1646 owner->view()->update(-2);
1647 owner->view()->text->CursorTop();
1648 owner->view()->text->FinishUndo();
1649 moveCursorUpdate(true);
1650 owner->getMiniBuffer()->Set(CurrentState());
1653 case LFUN_ENDBUFSEL:
1654 owner->view()->update(-2);
1655 owner->view()->text->CursorBottom();
1656 owner->view()->text->FinishUndo();
1657 moveCursorUpdate(true);
1658 owner->getMiniBuffer()->Set(CurrentState());
1661 // --- text changing commands ------------------------
1662 case LFUN_BREAKLINE:
1664 owner->view()->beforeChange();
1665 owner->view()->text->InsertChar(LyXParagraph::META_NEWLINE);
1666 owner->view()->smallUpdate(1);
1667 SetUpdateTimer(0.01);
1668 moveCursorUpdate(false);
1670 owner->view()->newline();
1674 case LFUN_PROTECTEDSPACE:
1677 LyXLayout const & style =
1678 textclasslist.Style(owner->view()->buffer()->params.textclass,
1679 owner->view()->text->cursor.par->GetLayout());
1681 if (style.free_spacing) {
1682 owner->view()->text->InsertChar(' ');
1683 owner->view()->update(-1);
1685 owner->view()->protectedBlank();
1687 moveCursorUpdate(false);
1690 owner->view()->beforeChange();
1691 owner->view()->text->
1692 InsertChar(LyXParagraph::META_PROTECTED_SEPARATOR);
1693 owner->view()->smallUpdate(1);
1695 moveCursorUpdate(false);
1700 if(owner->view()->text->mark_set) {
1701 owner->view()->beforeChange();
1702 owner->view()->update(0);
1703 setMessage(N_("Mark removed"));
1705 owner->view()->beforeChange();
1706 owner->view()->text->mark_set = 1;
1707 owner->view()->update(0);
1708 setMessage(N_("Mark set"));
1710 owner->view()->text->sel_cursor =
1711 owner->view()->text->cursor;
1716 if (!owner->view()->text->selection) {
1717 owner->view()->text->Delete();
1718 owner->view()->text->sel_cursor =
1719 owner->view()->text->cursor;
1720 owner->view()->smallUpdate(1);
1721 // It is possible to make it a lot faster still
1722 // just comment out the lone below...
1723 owner->view()->showCursor();
1725 owner->view()->cut();
1728 moveCursorUpdate(false);
1729 owner->getMiniBuffer()->Set(CurrentState());
1730 owner->view()->setState();
1733 case LFUN_DELETE_SKIP:
1735 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1737 LyXCursor cursor = owner->view()->text->cursor;
1740 if (!owner->view()->text->selection) {
1741 if (cursor.pos == cursor.par->Last()) {
1742 owner->view()->text->CursorRight();
1743 cursor = owner->view()->text->cursor;
1745 && !(cursor.par->added_space_top
1746 == VSpace (VSpace::NONE))) {
1747 owner->view()->text->SetParagraph
1748 (cursor.par->line_top,
1749 cursor.par->line_bottom,
1750 cursor.par->pagebreak_top,
1751 cursor.par->pagebreak_bottom,
1752 VSpace(VSpace::NONE),
1753 cursor.par->added_space_bottom,
1755 cursor.par->labelwidthstring, 0);
1756 owner->view()->text->CursorLeft();
1757 owner->view()->update (1);
1759 owner->view()->text->CursorLeft();
1760 owner->view()->text->Delete();
1761 owner->view()->text->sel_cursor =
1762 owner->view()->text->cursor;
1763 owner->view()->smallUpdate(1);
1766 owner->view()->text->Delete();
1767 owner->view()->text->sel_cursor =
1768 owner->view()->text->cursor;
1769 owner->view()->smallUpdate(1);
1772 owner->view()->cut();
1778 /* -------> Delete word forward. */
1779 case LFUN_DELETE_WORD_FORWARD:
1780 owner->view()->update(-2);
1782 owner->view()->text->DeleteWordForward();
1783 owner->view()->update( 1 );
1785 moveCursorUpdate(false);
1786 owner->getMiniBuffer()->Set(CurrentState());
1789 /* -------> Delete word backward. */
1790 case LFUN_DELETE_WORD_BACKWARD:
1791 owner->view()->update(-2);
1793 owner->view()->text->DeleteWordBackward();
1794 owner->view()->update( 1 );
1796 moveCursorUpdate(false);
1797 owner->getMiniBuffer()->Set(CurrentState());
1800 /* -------> Kill to end of line. */
1801 case LFUN_DELETE_LINE_FORWARD:
1803 owner->view()->update(-2);
1804 owner->view()->text->DeleteLineForward();
1805 owner->view()->update( 1 );
1807 moveCursorUpdate(false);
1810 /* -------> Set mark off. */
1812 owner->view()->beforeChange();
1813 owner->view()->update(0);
1814 owner->view()->text->sel_cursor =
1815 owner->view()->text->cursor;
1816 setMessage(N_("Mark off"));
1819 /* -------> Set mark on. */
1821 owner->view()->beforeChange();
1822 owner->view()->text->mark_set = 1;
1823 owner->view()->update( 0 );
1824 owner->view()->text->sel_cursor =
1825 owner->view()->text->cursor;
1826 setMessage(N_("Mark on"));
1829 case LFUN_BACKSPACE:
1832 if (!owner->view()->text->selection) {
1833 if (owner->getIntl()->getTrans()->backspace()) {
1834 owner->view()->text->Backspace();
1835 owner->view()->text->sel_cursor =
1836 owner->view()->text->cursor;
1837 owner->view()->smallUpdate(1);
1838 // It is possible to make it a lot faster still
1839 // just comment out the lone below...
1840 owner->view()->showCursor();
1843 owner->view()->cut();
1846 owner->getMiniBuffer()->Set(CurrentState());
1847 owner->view()->setState();
1851 case LFUN_BACKSPACE_SKIP:
1853 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1855 LyXCursor cursor = owner->view()->text->cursor;
1858 if (!owner->view()->text->selection) {
1860 && !(cursor.par->added_space_top
1861 == VSpace (VSpace::NONE))) {
1862 owner->view()->text->SetParagraph
1863 (cursor.par->line_top,
1864 cursor.par->line_bottom,
1865 cursor.par->pagebreak_top,
1866 cursor.par->pagebreak_bottom,
1867 VSpace(VSpace::NONE), cursor.par->added_space_bottom,
1869 cursor.par->labelwidthstring, 0);
1870 owner->view()->update (1);
1872 owner->view()->text->Backspace();
1873 owner->view()->text->sel_cursor
1875 owner->view()->smallUpdate (1);
1878 owner->view()->cut();
1883 case LFUN_BREAKPARAGRAPH:
1885 owner->view()->beforeChange();
1886 owner->view()->text->BreakParagraph(0);
1887 owner->view()->smallUpdate(1);
1888 SetUpdateTimer(0.01);
1889 owner->view()->text->sel_cursor =
1890 owner->view()->text->cursor;
1891 owner->view()->setState();
1892 owner->getMiniBuffer()->Set(CurrentState());
1896 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1898 owner->view()->beforeChange();
1899 owner->view()->text->BreakParagraph(1);
1900 owner->view()->smallUpdate(1);
1901 SetUpdateTimer(0.01);
1902 owner->view()->text->sel_cursor =
1903 owner->view()->text->cursor;
1904 owner->view()->setState();
1905 owner->getMiniBuffer()->Set(CurrentState());
1909 case LFUN_BREAKPARAGRAPH_SKIP:
1911 // When at the beginning of a paragraph, remove
1912 // indentation and add a "defskip" at the top.
1913 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
1915 LyXCursor cursor = owner->view()->text->cursor;
1917 owner->view()->beforeChange();
1918 if (cursor.pos == 0) {
1919 if (cursor.par->added_space_top == VSpace(VSpace::NONE)) {
1920 owner->view()->text->SetParagraph
1921 (cursor.par->line_top,
1922 cursor.par->line_bottom,
1923 cursor.par->pagebreak_top,
1924 cursor.par->pagebreak_bottom,
1925 VSpace(VSpace::DEFSKIP), cursor.par->added_space_bottom,
1927 cursor.par->labelwidthstring, 1);
1928 owner->view()->update(1);
1932 owner->view()->text->BreakParagraph(0);
1933 owner->view()->smallUpdate(1);
1935 SetUpdateTimer(0.01);
1936 owner->view()->text->sel_cursor = cursor;
1937 owner->view()->setState();
1938 owner->getMiniBuffer()->Set(CurrentState());
1943 owner->view()->beforeChange();
1944 owner->view()->text->InsertChar('\"'); // This " matches the single quote in the code
1945 owner->view()->smallUpdate(1);
1947 moveCursorUpdate(false);
1953 InsetCommand * new_inset;
1954 if (action == LFUN_HTMLURL)
1955 new_inset = new InsetUrl("htmlurl", "", "");
1957 new_inset = new InsetUrl("url", "", "");
1958 owner->view()->insertInset(new_inset);
1959 new_inset->Edit(owner->view(), 0, 0, 0);
1962 case LFUN_INSET_TEXT:
1964 InsetText * new_inset = new InsetText(owner->buffer());
1965 owner->view()->insertInset(new_inset);
1966 new_inset->Edit(owner->view(), 0, 0, 0);
1970 case LFUN_INSET_NUMBER:
1972 InsetNumber * new_inset = new InsetNumber(owner->buffer());
1973 owner->view()->insertInset(new_inset);
1974 new_inset->Edit(owner->view(), 0, 0, 0);
1978 case LFUN_INSET_ERT:
1980 InsetERT * new_inset = new InsetERT(owner->buffer());
1981 owner->view()->insertInset(new_inset);
1982 new_inset->Edit(owner->view(), 0, 0, 0);
1985 case LFUN_INSET_FOOTNOTE:
1987 InsetFoot * new_inset = new InsetFoot(owner->buffer());
1988 owner->view()->insertInset(new_inset);
1989 new_inset->Edit(owner->view(), 0, 0, 0);
1993 // --- lyxserver commands ----------------------------
1995 case LFUN_CHARATCURSOR:
1997 LyXParagraph::size_type pos =
1998 owner->view()->text->cursor.pos;
1999 if(pos < owner->view()->text->cursor.par->size())
2000 //dispatch_buffer = owner->view()->text->
2001 // cursor.par->text[pos];
2003 owner->view()->text->
2004 cursor.par->GetChar(pos);
2006 dispatch_buffer = "EOF";
2012 tostr(owner->view()->text->cursor.x) + ' '
2013 + tostr(owner->view()->text->cursor.y);
2020 sscanf(argument.c_str(), " %d %ld", &x, &y);
2021 owner->view()->text->SetCursorFromCoordinates(x, y);
2025 case LFUN_GETLAYOUT:
2027 tostr(owner->view()->text->cursor.par->layout);
2032 LyXFont * font = &(owner->view()->text->current_font);
2033 if(font->shape() == LyXFont::ITALIC_SHAPE)
2034 dispatch_buffer = 'E';
2035 else if(font->shape() == LyXFont::SMALLCAPS_SHAPE)
2036 dispatch_buffer = 'N';
2038 dispatch_buffer = '0';
2045 LyXFont * font = &(owner->view()->text->current_font);
2046 if(font->latex() == LyXFont::ON)
2047 dispatch_buffer = 'L';
2049 dispatch_buffer = '0';
2054 setMessage(owner->buffer()->fileName());
2055 lyxerr.debug() << "FNAME["
2056 << owner->buffer()->fileName()
2064 dispatch_buffer = buf;
2065 lyxserver->notifyClient(dispatch_buffer);
2069 case LFUN_GOTOFILEROW:
2071 char file_name[100];
2073 sscanf(argument.c_str(), " %s %d", file_name, &row);
2075 // Must replace extension of the file to be .lyx and get full path
2076 string s = ChangeExtension(string(file_name), ".lyx", false);
2078 // Either change buffer or load the file
2079 if (bufferlist.exists(s))
2080 owner->view()->buffer(bufferlist.getBuffer(s));
2082 owner->view()->buffer(bufferlist.loadLyXFile(s));
2085 owner->view()->setCursorFromRow(row);
2088 owner->view()->center();
2095 int qa = lyxaction.LookupFunc(argument.c_str());
2096 setMessage(lyxaction.helpText(static_cast<kb_action>(qa)));
2100 // --- accented characters ---------------------------
2103 case LFUN_CIRCUMFLEX:
2113 case LFUN_SPECIAL_CARON:
2116 case LFUN_HUNG_UMLAUT:
2122 if (keyseq.length == -1 && keyseq.getiso() != 0)
2123 c = keyseq.getiso();
2127 owner->getIntl()->getTrans()->
2128 deadkey(c, get_accent(action).accent,
2129 owner->view()->text);
2131 // Need to reset, in case the minibuffer calls these
2136 // copied verbatim from do_accent_char
2137 owner->view()->smallUpdate(1);
2139 owner->view()->text->sel_cursor =
2140 owner->view()->text->cursor;
2144 // --- toolbar ----------------------------------
2145 case LFUN_PUSH_TOOLBAR:
2147 int nth = strToInt(argument);
2148 if (lyxerr.debugging(Debug::TOOLBAR)) {
2149 lyxerr << "LFUN_PUSH_TOOLBAR: argument = `"
2150 << argument << "'\n"
2151 << "LFUN_PUSH_TOOLBAR: nth = `"
2152 << nth << "'" << endl;
2157 setErrorMessage(N_("Push-toolbar needs argument > 0"));
2159 owner->getToolbar()->push(nth);
2164 case LFUN_ADD_TO_TOOLBAR:
2166 if (lyxerr.debugging(Debug::TOOLBAR)) {
2167 lyxerr << "LFUN_ADD_TO_TOOLBAR:"
2168 "argument = `" << argument << '\'' << endl;
2170 string tmp(argument);
2171 //lyxerr <<string("Argument: ") + argument);
2172 //lyxerr <<string("Tmp : ") + tmp);
2175 setErrorMessage(N_("Usage: toolbar-add-to <LyX command>"));
2177 owner->getToolbar()->add(argument, false);
2178 owner->getToolbar()->set();
2183 // --- insert characters ----------------------------------------
2185 // --- Mathed stuff. If we are here, there is no locked inset yet.
2190 if (!greek_kb_flag) {
2192 setMessage(N_("Math greek mode on"));
2199 case LFUN_GREEK_TOGGLE:
2201 greek_kb_flag = greek_kb_flag ? 0 : 2;
2202 if (greek_kb_flag) {
2203 setMessage(N_("Math greek keyboard on"));
2205 setMessage(N_("Math greek keyboard off"));
2210 case LFUN_MATH_DELIM:
2211 case LFUN_INSERT_MATRIX:
2213 if (owner->view()->available()) {
2215 open_new_inset(new InsetFormula(false));
2218 ->LocalDispatch(owner->view(),
2225 case LFUN_INSERT_MATH:
2227 math_insert_symbol(argument.c_str());
2231 case LFUN_MATH_DISPLAY:
2233 if (owner->view()->available())
2234 owner->view()->open_new_inset(new InsetFormula(true));
2238 case LFUN_MATH_MACRO:
2240 if (owner->view()->available()) {
2243 setErrorMessage(N_("Missing argument"));
2245 string s1 = token(s, ' ', 1);
2246 int na = s1.empty() ? 0: atoi(s1.c_str());
2248 open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2254 case LFUN_MATH_MODE: // Open or create a math inset
2257 if (owner->view()->available())
2258 owner->view()->open_new_inset(new InsetFormula);
2259 setMessage(N_("Math editor mode"));
2263 case LFUN_MATH_NUMBER:
2264 case LFUN_MATH_LIMITS:
2266 setErrorMessage(N_("This is only allowed in math mode!"));
2270 case LFUN_INSERT_CITATION:
2272 InsetCitation * new_inset = new InsetCitation();
2274 // The note, if any, must be after the key, delimited
2275 // by a | so both key and remark can have spaces.
2276 if (!argument.empty()) {
2277 string lsarg(argument);
2278 if (contains(lsarg, "|")) {
2279 new_inset->setContents(token(lsarg, '|', 0));
2280 new_inset->setOptions(token(lsarg, '|', 1));
2282 new_inset->setContents(lsarg);
2283 owner->view()->insertInset(new_inset);
2285 owner->view()->insertInset(new_inset);
2286 new_inset->Edit(owner->view(), 0, 0, 0);
2291 case LFUN_INSERT_BIBTEX:
2293 // ale970405+lasgoutt970425
2294 // The argument can be up to two tokens separated
2295 // by a space. The first one is the bibstyle.
2296 string lsarg(argument);
2297 string bibstyle = token(lsarg, ' ', 1);
2298 if (bibstyle.empty())
2300 InsetBibtex * new_inset
2301 = new InsetBibtex(token(lsarg, ' ', 0),
2305 owner->view()->insertInset(new_inset);
2306 if (lsarg.empty()) {
2307 new_inset->Edit(owner->view(), 0, 0, 0);
2312 // BibTeX data bases
2313 case LFUN_BIBDB_ADD:
2315 InsetBibtex * inset =
2316 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2318 inset->addDatabase(argument);
2323 case LFUN_BIBDB_DEL:
2325 InsetBibtex * inset =
2326 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2328 inset->delDatabase(argument);
2333 case LFUN_BIBTEX_STYLE:
2335 InsetBibtex * inset =
2336 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2338 inset->setOptions(argument);
2343 case LFUN_INDEX_INSERT:
2344 case LFUN_INDEX_INSERT_LAST:
2346 // Can't do that at the beginning of a paragraph.
2347 if (owner->view()->text->cursor.pos - 1 < 0)
2350 InsetIndex * new_inset = new InsetIndex();
2351 if (!argument.empty()) {
2352 string lsarg(argument);
2353 new_inset->setContents(lsarg);
2354 owner->view()->insertInset(new_inset);
2357 //get the current word for an argument
2358 LyXParagraph::size_type lastpos =
2359 owner->view()->text->cursor.pos - 1;
2360 // Get the current word. note that this must be done
2361 // before inserting the inset, or the inset will
2363 string curstring(owner->view()
2364 ->text->cursor.par->GetWord(lastpos));
2366 //make the new inset and write the current word into it
2367 InsetIndex * new_inset = new InsetIndex();
2369 new_inset->setContents(curstring);
2371 //don't edit it if the call was to INSERT_LAST
2372 if(action != LFUN_INDEX_INSERT_LAST) {
2373 new_inset->Edit(owner->view(), 0, 0, 0);
2375 //it looks blank on the screen unless
2376 //we do something. put it here.
2378 // move the cursor to the returned value of lastpos
2379 // but only for the auto-insert
2380 owner->view()->text->cursor.pos = lastpos;
2383 //put the new inset into the buffer.
2384 // there should be some way of knowing the user
2385 //cancelled & avoiding this, but i don't know how
2386 owner->view()->insertInset(new_inset);
2391 case LFUN_INDEX_PRINT:
2393 Inset * new_inset = new InsetPrintIndex(owner->buffer());
2394 owner->view()->insertInset(new_inset, "Standard", true);
2398 case LFUN_PARENTINSERT:
2400 lyxerr << "arg " << argument << endl;
2401 Inset * new_inset = new InsetParent(argument, owner->buffer());
2402 owner->view()->insertInset(new_inset, "Standard", true);
2406 case LFUN_CHILDINSERT:
2408 Inset * new_inset = new InsetInclude(argument,
2410 owner->view()->insertInset(new_inset, "Standard", true);
2411 new_inset->Edit(owner->view(), 0, 0, 0);
2415 case LFUN_CHILDOPEN:
2418 MakeAbsPath(argument,
2419 OnlyPath(owner->buffer()->fileName()));
2420 setMessage(N_("Opening child document ") +
2421 MakeDisplayPath(filename) + "...");
2422 owner->view()->savePosition();
2423 if (bufferlist.exists(filename))
2424 owner->view()->buffer(bufferlist.getBuffer(filename));
2426 owner->view()->buffer(bufferlist.loadLyXFile(filename));
2430 case LFUN_INSERT_NOTE:
2431 owner->view()->insertNote();
2434 case LFUN_INSERTFOOTNOTE:
2436 LyXParagraph::footnote_kind kind;
2437 if (argument == "footnote")
2438 { kind = LyXParagraph::FOOTNOTE; }
2439 else if (argument == "margin")
2440 { kind = LyXParagraph::MARGIN; }
2441 else if (argument == "figure")
2442 { kind = LyXParagraph::FIG; }
2443 else if (argument == "table")
2444 { kind = LyXParagraph::TAB; }
2445 else if (argument == "wide-fig")
2446 { kind = LyXParagraph::WIDE_FIG; }
2447 else if (argument == "wide-tab")
2448 { kind = LyXParagraph::WIDE_TAB; }
2449 else if (argument == "algorithm")
2450 { kind = LyXParagraph::ALGORITHM; }
2452 setErrorMessage(N_("Unknown kind of footnote"));
2455 owner->view()->text->InsertFootnoteEnvironment(kind);
2456 owner->view()->update(1);
2457 owner->view()->setState();
2461 case LFUN_BUFFERBULLETSSELECT:
2465 case LFUN_TOGGLECURSORFOLLOW:
2466 cursor_follows_scrollbar = !cursor_follows_scrollbar;
2469 case LFUN_KMAP_OFF: // keymap off
2470 owner->getIntl()->KeyMapOn(false);
2473 case LFUN_KMAP_PRIM: // primary keymap
2474 owner->getIntl()->KeyMapPrim();
2477 case LFUN_KMAP_SEC: // secondary keymap
2478 owner->getIntl()->KeyMapSec();
2481 case LFUN_KMAP_TOGGLE: // toggle keymap
2482 owner->getIntl()->ToggleKeyMap();
2485 case LFUN_SELFINSERT:
2487 for (string::size_type i = 0; i < argument.length(); ++i) {
2488 owner->view()->text->InsertChar(argument[i]);
2489 // This needs to be in the loop, or else we
2490 // won't break lines correctly. (Asger)
2491 owner->view()->smallUpdate(1);
2494 owner->view()->text->sel_cursor =
2495 owner->view()->text->cursor;
2496 moveCursorUpdate(false);
2502 // argument contains ';'-terminated commands
2503 while (argument.find(';') != string::npos) {
2505 argument = split(argument, first, ';');
2511 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
2519 now_time_t = time(NULL);
2520 now_tm = localtime(&now_time_t);
2521 (void)setlocale(LC_TIME, "");
2522 if (!argument.empty())
2524 else if (arg.empty())
2525 arg = lyxrc.date_insert_format;
2526 datetmp_len = (int) strftime(datetmp, 32, arg.c_str(), now_tm);
2527 for (int i = 0; i < datetmp_len; i++) {
2528 owner->view()->text->InsertChar(datetmp[i]);
2529 owner->view()->smallUpdate(1);
2532 owner->view()->text->sel_cursor = owner->view()->text->cursor;
2533 moveCursorUpdate(false);
2537 case LFUN_SAVEPREFERENCES:
2539 Path p(user_lyxdir);
2540 lyxrc.write("preferences");
2544 case LFUN_UNKNOWN_ACTION:
2546 if(!owner->buffer()) {
2548 setErrorMessage(N_("No document open"));
2552 if (owner->buffer()->isReadonly()) {
2554 setErrorMessage(N_("Document is read only"));
2558 if (!argument.empty()) {
2560 /* Automatically delete the currently selected
2561 * text and replace it with what is being
2562 * typed in now. Depends on lyxrc settings
2563 * "auto_region_delete", which defaults to
2566 if ( lyxrc.auto_region_delete ) {
2567 if (owner->view()->text->selection){
2568 owner->view()->text->CutSelection(false);
2569 owner->view()->update(-1);
2573 owner->view()->beforeChange();
2576 if (isdigit(argument[0]) &&
2577 (lyxrc.number_inset == "true" ||
2578 (lyxrc.number_inset == "rtl" &&
2579 owner->view()->text->real_current_font.isVisibleRightToLeft()
2581 UpdatableInset * tmpinset = new InsetNumber(owner->buffer());
2582 owner->view()->open_new_inset(tmpinset);
2583 tmpinset->LocalDispatch(owner->view(), action,
2589 for (string::size_type i = 0;
2590 i < argument.length(); ++i) {
2591 if (greek_kb_flag) {
2592 if (!math_insert_greek(argument[i]))
2593 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2595 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2598 owner->view()->smallUpdate(1);
2601 owner->view()->text->sel_cursor =
2602 owner->view()->text->cursor;
2603 moveCursorUpdate(false);
2606 // why is an "Unknown action" with empty
2607 // argument even dispatched in the first
2608 // place? I`ll probably change that. (Lgb)
2610 setErrorMessage(N_("Unknown action"));
2614 lyxerr << "A truly unknown func!" << endl;
2620 string res = getMessage();
2623 if (!commandshortcut.empty()) {
2624 string newbuf = owner->getMiniBuffer()->GetText();
2625 if (newbuf != commandshortcut) {
2626 owner->getMiniBuffer()->Set(newbuf
2632 owner->getMiniBuffer()->Set(string(_(res.c_str()))
2633 + " " + commandshortcut);
2640 void LyXFunc::setupLocalKeymap()
2642 keyseq.stdmap = keyseq.curmap = toplevel_keymap;
2643 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap;
2647 void LyXFunc::MenuNew(bool fromTemplate)
2649 string fname, initpath = lyxrc.document_path;
2652 if (owner->view()->available()) {
2653 string trypath = owner->buffer()->filepath;
2654 // If directory is writeable, use this as default.
2655 if (IsDirWriteable(trypath) == 1)
2660 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
2661 fileDlg.SetButton(1, _("Templates"), lyxrc.template_path);
2662 fname = fileDlg.Select(_("Enter Filename for new document"),
2663 initpath, "*.lyx", _("newfile"));
2666 if (fname.empty()) {
2667 owner->getMiniBuffer()->Set(_("Canceled."));
2668 lyxerr.debug() << "New Document Cancelled." << endl;
2672 // get absolute path of file and make sure the filename ends
2674 string s = MakeAbsPath(fname);
2675 if (!IsLyXFilename(s))
2678 // Check if the document already is open
2679 if (bufferlist.exists(s)){
2680 switch(AskConfirmation(_("Document is already open:"),
2681 MakeDisplayPath(s, 50),
2682 _("Do you want to close that document now?\n"
2683 "('No' will just switch to the open version)")))
2685 case 1: // Yes: close the document
2686 if (!bufferlist.close(bufferlist.getBuffer(s)))
2687 // If close is canceled, we cancel here too.
2690 case 2: // No: switch to the open document
2691 owner->view()->buffer(bufferlist.getBuffer(s));
2693 case 3: // Cancel: Do nothing
2694 owner->getMiniBuffer()->Set(_("Canceled."));
2699 // Check whether the file already exists
2700 if (IsLyXFilename(s)) {
2702 if (fi.readable() &&
2703 AskQuestion(_("File already exists:"),
2704 MakeDisplayPath(s, 50),
2705 _("Do you want to open the document?"))) {
2707 owner->getMiniBuffer()->Set(_("Opening document"),
2708 MakeDisplayPath(s), "...");
2710 owner->view()->buffer(
2711 bufferlist.loadLyXFile(s));
2712 owner->getMiniBuffer()->Set(_("Document"),
2719 // The template stuff
2723 fname = fileDlg.Select(_("Choose template"),
2724 lyxrc.template_path,
2730 // find a free buffer
2731 lyxerr.debug() << "Find a free buffer." << endl;
2732 owner->view()->buffer(bufferlist.newFile(s, templname));
2736 void LyXFunc::MenuOpen()
2738 string initpath = lyxrc.document_path;
2741 if (owner->view()->available()) {
2742 string trypath = owner->buffer()->filepath;
2743 // If directory is writeable, use this as default.
2744 if (IsDirWriteable(trypath) == 1)
2750 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
2751 fileDlg.SetButton(1, _("Examples"),
2752 AddPath(system_lyxdir, "examples"));
2753 string filename = fileDlg.Select(_("Select Document to Open"),
2757 // check selected filename
2758 if (filename.empty()) {
2759 owner->getMiniBuffer()->Set(_("Canceled."));
2763 // get absolute path of file and make sure the filename ends
2765 filename = MakeAbsPath(filename);
2766 if (!IsLyXFilename(filename))
2770 owner->getMiniBuffer()->Set(_("Opening document"),
2771 MakeDisplayPath(filename), "...");
2772 Buffer * openbuf = bufferlist.loadLyXFile(filename);
2774 owner->view()->buffer(openbuf);
2775 owner->getMiniBuffer()->Set(_("Document"),
2776 MakeDisplayPath(filename),
2779 owner->getMiniBuffer()->Set(_("Could not open document"),
2780 MakeDisplayPath(filename));
2785 void LyXFunc::doImportASCII(bool linorpar)
2787 string initpath = lyxrc.document_path;
2790 if (owner->view()->available()) {
2791 string trypath = owner->buffer()->filepath;
2792 // If directory is writeable, use this as default.
2793 if (IsDirWriteable(trypath) == 1)
2799 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
2800 fileDlg.SetButton(1, _("Examples"),
2801 AddPath(system_lyxdir, "examples"));
2802 string filename = fileDlg.Select(_("Select ASCII file to Import"),
2806 // check selected filename
2807 if (filename.empty()) {
2808 owner->getMiniBuffer()->Set(_("Canceled."));
2812 // get absolute path of file
2813 filename = MakeAbsPath(filename);
2815 string s = ChangeExtension(filename, ".lyx", false);
2817 // Check if the document already is open
2818 if (bufferlist.exists(s)) {
2819 switch(AskConfirmation(_("Document is already open:"),
2820 MakeDisplayPath(s, 50),
2821 _("Do you want to close that document now?\n"
2822 "('No' will just switch to the open version)")))
2824 case 1: // Yes: close the document
2825 if (!bufferlist.close(bufferlist.getBuffer(s)))
2826 // If close is canceled, we cancel here too.
2829 case 2: // No: switch to the open document
2830 owner->view()->buffer(bufferlist.getBuffer(s));
2832 case 3: // Cancel: Do nothing
2833 owner->getMiniBuffer()->Set(_("Canceled."));
2838 // Check if a LyX document by the same root exists in filesystem
2839 FileInfo f(s, true);
2840 if (f.exist() && !AskQuestion(_("A document by the name"),
2842 _("already exists. Overwrite?"))) {
2843 owner->getMiniBuffer()->Set(_("Canceled."));
2847 owner->view()->buffer(bufferlist.newFile(s, string()));
2848 owner->getMiniBuffer()->Set(_("Importing ASCII file"),
2849 MakeDisplayPath(filename), "...");
2850 // Insert ASCII file
2851 InsertAsciiFile(owner->view(), filename, linorpar);
2852 owner->getMiniBuffer()->Set(_("ASCII file "),
2853 MakeDisplayPath(filename),
2858 void LyXFunc::doImportLaTeX(bool isnoweb)
2860 string initpath = lyxrc.document_path;
2863 if (owner->view()->available()) {
2864 string trypath = owner->buffer()->filepath;
2865 // If directory is writeable, use this as default.
2866 if (IsDirWriteable(trypath) == 1)
2872 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
2873 fileDlg.SetButton(1, _("Examples"),
2874 AddPath(system_lyxdir, "examples"));
2877 filename = fileDlg.Select(_("Select Noweb file to Import"),
2880 filename = fileDlg.Select(_("Select LaTeX file to Import"),
2886 // check selected filename
2887 if (filename.empty()) {
2888 owner->getMiniBuffer()->Set(_("Canceled."));
2892 // get absolute path of file
2893 filename = MakeAbsPath(filename);
2895 // Check if the document already is open
2896 string LyXfilename = ChangeExtension(filename, ".lyx", false);
2897 if (bufferlist.exists(LyXfilename)){
2898 switch(AskConfirmation(_("Document is already open:"),
2899 MakeDisplayPath(LyXfilename, 50),
2900 _("Do you want to close that document now?\n"
2901 "('No' will just switch to the open version)")))
2903 case 1: // Yes: close the document
2904 if (!bufferlist.close(bufferlist.getBuffer(LyXfilename)))
2905 // If close is canceled, we cancel here too.
2908 case 2: // No: switch to the open document
2909 owner->view()->buffer(
2910 bufferlist.getBuffer(LyXfilename));
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(LyXfilename, true);
2920 if (f.exist() && !AskQuestion(_("A document by the name"),
2921 MakeDisplayPath(LyXfilename),
2922 _("already exists. Overwrite?"))) {
2923 owner->getMiniBuffer()->Set(_("Canceled."));
2930 owner->getMiniBuffer()->Set(_("Importing LaTeX file"),
2931 MakeDisplayPath(filename), "...");
2932 ImportLaTeX myImport(filename);
2933 openbuf = myImport.run();
2935 owner->getMiniBuffer()->Set(_("Importing Noweb file"),
2936 MakeDisplayPath(filename), "...");
2937 ImportNoweb myImport(filename);
2938 openbuf = myImport.run();
2941 owner->view()->buffer(openbuf);
2942 owner->getMiniBuffer()->Set(isnoweb ?
2943 _("Noweb file ") : _("LateX file "),
2944 MakeDisplayPath(filename),
2947 owner->getMiniBuffer()->Set(isnoweb ?
2948 _("Could not import Noweb file") :
2949 _("Could not import LaTeX file"),
2950 MakeDisplayPath(filename));
2955 void LyXFunc::doImportLinuxDoc()
2957 string initpath = lyxrc.document_path;
2960 if (owner->view()->available()) {
2961 string trypath = owner->buffer()->filepath;
2962 // If directory is writeable, use this as default.
2963 if (IsDirWriteable(trypath) == 1)
2969 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
2970 fileDlg.SetButton(1, _("Examples"),
2971 AddPath(system_lyxdir, "examples"));
2973 string filename = fileDlg.Select(_("Select LinuxDoc file to Import"),
2974 initpath, "*.sgml");
2978 // check selected filename
2979 if (filename.empty()) {
2980 owner->getMiniBuffer()->Set(_("Canceled."));
2984 // get absolute path of file
2985 filename = MakeAbsPath(filename);
2987 // Check if the document already is open
2988 string LyXfilename = ChangeExtension(filename, ".lyx", false);
2989 if (bufferlist.exists(LyXfilename)){
2990 switch(AskConfirmation(_("Document is already open:"),
2991 MakeDisplayPath(LyXfilename, 50),
2992 _("Do you want to close that document now?\n"
2993 "('No' will just switch to the open version)")))
2995 case 1: // Yes: close the document
2996 if (!bufferlist.close(bufferlist.getBuffer(LyXfilename)))
2997 // If close is canceled, we cancel here too.
3000 case 2: // No: switch to the open document
3001 owner->view()->buffer(
3002 bufferlist.getBuffer(LyXfilename));
3004 case 3: // Cancel: Do nothing
3005 owner->getMiniBuffer()->Set(_("Canceled."));
3010 // Check if a LyX document by the same root exists in filesystem
3011 FileInfo f(LyXfilename, true);
3012 if (f.exist() && !AskQuestion(_("A document by the name"),
3013 MakeDisplayPath(LyXfilename),
3014 _("already exists. Overwrite?"))) {
3015 owner->getMiniBuffer()->Set(_("Canceled."));
3020 owner->getMiniBuffer()->Set(_("Importing LinuxDoc file"),
3021 MakeDisplayPath(filename), "...");
3024 string tmp = lyxrc.linuxdoc_to_lyx_command + filename;
3028 int result = one.startscript(Systemcalls::System, tmp);
3030 string filename = ChangeExtension(filename, ".lyx", false);
3031 // File was generated without problems. Load it.
3032 buf = bufferlist.loadLyXFile(filename);
3033 owner->view()->buffer(buf);
3034 owner->getMiniBuffer()->Set(_("LinuxDoc file "),
3035 MakeDisplayPath(filename),
3038 owner->getMiniBuffer()->Set(_("Could not import LinuxDoc file"),
3039 MakeDisplayPath(filename));
3044 void LyXFunc::MenuInsertLyXFile(string const & filen)
3046 string filename = filen;
3048 if (filename.empty()) {
3049 // Launch a file browser
3050 string initpath = lyxrc.document_path;
3053 if (owner->view()->available()) {
3054 string trypath = owner->buffer()->filepath;
3055 // If directory is writeable, use this as default.
3056 if (IsDirWriteable(trypath) == 1)
3062 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
3063 fileDlg.SetButton(1, _("Examples"),
3064 AddPath(system_lyxdir, "examples"));
3065 filename = fileDlg.Select(_("Select Document to Insert"),
3069 // check selected filename
3070 if (filename.empty()) {
3071 owner->getMiniBuffer()->Set(_("Canceled."));
3076 // get absolute path of file and make sure the filename ends
3078 filename = MakeAbsPath(filename);
3079 if (!IsLyXFilename(filename))
3083 owner->getMiniBuffer()->Set(_("Inserting document"),
3084 MakeDisplayPath(filename), "...");
3085 bool res = owner->view()->insertLyXFile(filename);
3087 owner->getMiniBuffer()->Set(_("Document"),
3088 MakeDisplayPath(filename),
3091 owner->getMiniBuffer()->Set(_("Could not insert document"),
3092 MakeDisplayPath(filename));
3097 void LyXFunc::reloadBuffer()
3099 string fn = owner->buffer()->fileName();
3100 if (bufferlist.close(owner->buffer()))
3101 owner->view()->buffer(bufferlist.loadLyXFile(fn));
3105 void LyXFunc::CloseBuffer()
3107 if (bufferlist.close(owner->buffer()) && !quitting) {
3108 if (bufferlist.empty()) {
3109 // need this otherwise SEGV may occur while trying to
3110 // set variables that don't exist
3111 // since there's no current buffer
3112 CloseAllBufferRelatedPopups();
3115 owner->view()->buffer(bufferlist.first());
3121 Inset * LyXFunc::getInsetByCode(Inset::Code code)
3125 LyXCursor cursor = owner->view()->text->cursor;
3126 LyXParagraph::size_type pos = cursor.pos;
3127 LyXParagraph * par = cursor.par;
3129 while (par && !found) {
3130 while ((inset = par->ReturnNextInsetPointer(pos))){
3131 if (inset->LyxCode() == code) {
3139 return found ? inset : 0;
3143 // Each "owner" should have it's own message method. lyxview and
3144 // the minibuffer would use the minibuffer, but lyxserver would
3145 // send an ERROR signal to its client. Alejandro 970603
3146 // This func is bit problematic when it comes to NLS, to make the
3147 // lyx servers client be language indepenent we must not translate
3148 // strings sent to this func.
3149 void LyXFunc::setErrorMessage(string const & m) const
3151 dispatch_buffer = m;
3156 void LyXFunc::setMessage(string const & m)
3158 dispatch_buffer = m;