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"
75 extern bool cursor_follows_scrollbar;
77 extern void InsertAsciiFile(BufferView *, string const &, bool);
78 extern void math_insert_symbol(char const *);
79 extern Bool math_insert_greek(char const); // why "Bool"?
80 extern BufferList bufferlist;
81 extern LyXServer * lyxserver;
82 extern short greek_kb_flag;
83 extern FD_form_toc * fd_form_toc;
84 extern bool selection_possible;
86 extern kb_keymap * toplevel_keymap;
88 extern void MenuWrite(Buffer *);
89 extern void MenuWriteAs(Buffer *);
90 extern int MenuRunLaTeX(Buffer *);
91 extern int MenuBuildProg(Buffer *);
92 extern int MenuRunChktex(Buffer *);
93 extern bool CreatePostscript(Buffer *, bool);
94 extern void MenuPrint(Buffer *);
95 extern void MenuSendto();
96 extern void QuitLyX();
97 extern void MenuFax(Buffer *);
98 extern void MenuExport(Buffer *, string const &);
99 extern void MenuPasteSelection(char at);
100 extern LyXAction lyxaction;
102 extern tex_accent_struct get_accent(kb_action action);
104 extern void AutoSave();
105 extern void SetUpdateTimer(float timer = 0.3);
106 extern void FreeUpdateTimer();
107 extern bool PreviewDVI(Buffer *);
108 extern bool PreviewPostscript(Buffer *);
109 extern void MenuInsertLabel(char const *);
110 extern void MenuInsertRef();
111 extern void MenuLayoutCharacter();
112 extern void MenuLayoutParagraph();
113 extern void MenuLayoutDocument();
114 extern void MenuLayoutPaper();
115 extern void MenuLayoutTable(int flag);
116 extern void MenuLayoutQuotes();
117 extern void MenuLayoutPreamble();
118 extern void MenuLayoutSave();
119 extern void bulletForm();
121 extern Buffer * NewLyxFile(string const &);
122 extern void LoadLyXFile(string const &);
123 extern void Reconfigure(BufferView *);
125 extern LyXTextClass::size_type current_layout;
126 extern int getISOCodeFromLaTeX(char *);
128 extern void ShowLatexLog();
130 /* === globals =========================================================== */
132 bool LyXFunc::show_sc = true;
135 LyXFunc::LyXFunc(LyXView * o)
139 lyx_dead_action = LFUN_NOACTION;
140 lyx_calling_dead_action = LFUN_NOACTION;
145 // I changed this func slightly. I commented out the ...FinishUndo(),
146 // this means that all places that used to have a moveCursorUpdate, now
147 // have a ...FinishUndo() as the preceeding statement. I have also added
148 // a moveCursorUpdate to some of the functions that updated the cursor, but
149 // that did not show its new position.
151 void LyXFunc::moveCursorUpdate(bool selecting)
153 if (selecting || owner->view()->text->mark_set) {
154 owner->view()->text->SetSelection();
155 owner->view()->toggleToggle();
156 owner->view()->update(0);
158 owner->view()->update(-2); // this IS necessary
162 owner->view()->showCursor();
164 /* ---> Everytime the cursor is moved, show the current font state. */
165 // should this too me moved out of this func?
166 //owner->getMiniBuffer()->Set(CurrentState());
167 owner->view()->setState();
171 int LyXFunc::processKeyEvent(XEvent * ev)
175 XKeyEvent * keyevent = &ev->xkey;
176 KeySym keysym_return;
178 int num_bytes = LyXLookupString(ev, s_r, 10, &keysym_return);
179 s_r[num_bytes] = '\0';
181 if (lyxerr.debugging(Debug::KEY)) {
182 char * tmp = XKeysymToString(keysym_return);
183 string stm = (tmp ? tmp : "");
184 lyxerr << "KeySym is "
187 << keysym_return << "]"
188 << " and num_bytes is "
190 << " the string returned is \""
191 << s_r << '\"' << endl;
193 // Do nothing if we have nothing (JMarc)
194 if (num_bytes == 0 && keysym_return == NoSymbol) {
195 lyxerr[Debug::KEY] << "Empty kbd action (probably composing)"
200 // this function should be used always [asierra060396]
201 if (owner->view()->available() &&
202 owner->view()->the_locking_inset &&
203 keysym_return == XK_Escape) {
204 owner->view()->unlockInset(owner->view()->the_locking_inset);
205 owner->view()->text->CursorRight();
206 moveCursorUpdate(false);
207 owner->getMiniBuffer()->Set(CurrentState());
211 // Can we be sure that this will work for all X-Windows
212 // implementations? (Lgb)
213 // This code snippet makes lyx ignore some keys. Perhaps
214 // all of them should be explictly mentioned?
215 if((keysym_return >= XK_Shift_L && keysym_return <= XK_Hyper_R)
216 || keysym_return == XK_Mode_switch || keysym_return == 0x0)
219 // Do a one-deep top-level lookup for
220 // cancel and meta-fake keys. RVDK_PATCH_5
221 cancel_meta_seq.reset();
223 int action = cancel_meta_seq.addkey(keysym_return, keyevent->state
224 &(ShiftMask|ControlMask
227 // When not cancel or meta-fake, do the normal lookup.
228 // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
229 // Mostly, meta_fake_bit = 0. RVDK_PATCH_5.
230 if ( (action != LFUN_CANCEL) && (action != LFUN_META_FAKE) ) {
232 // remove Caps Lock and Mod2 as a modifiers
233 action = keyseq.addkey(keysym_return,
234 (keyevent->state | meta_fake_bit)
235 &(ShiftMask|ControlMask
238 // Dont remove this unless you know what you are doing.
241 if (action == 0) action = LFUN_PREFIX;
243 if (lyxerr.debugging(Debug::KEY)) {
249 << num_bytes << "]" << endl;
252 // already here we know if it any point in going further
253 // why not return already here if action == -1 and
254 // num_bytes == 0? (Lgb)
256 if(keyseq.length > 1 || keyseq.length < -1) {
259 owner->getMiniBuffer()->Set(buf);
263 if (keyseq.length < -1) { // unknown key sequence...
267 owner->getMiniBuffer()->Set(_("Unknown sequence:"), buf);
271 char isochar = keyseq.getiso();
272 if (!(keyevent->state&ControlMask) &&
273 !(keyevent->state&Mod1Mask) &&
274 (isochar && keysym_return < 0xF000)) {
277 if (argument.empty()) {
278 lyxerr.debug() << "Empty argument!" << endl;
279 // This can`t possibly be of any use
280 // so we`ll skip the dispatch.
284 if (action == LFUN_SELFINSERT) {
288 bool tmp_sc = show_sc;
290 Dispatch(action, argument.c_str());
297 LyXFunc::func_status LyXFunc::getStatus(int ac) const
300 func_status flag = LyXFunc::OK;
302 Buffer * buf = owner->buffer();
304 if (lyxaction.isPseudoAction(ac))
305 action = lyxaction.retrieveActionArg(ac, argument);
307 action = static_cast<kb_action>(ac);
309 if (action == LFUN_UNKNOWN_ACTION) {
310 setErrorMessage(N_("Unknown action"));
311 return LyXFunc::Unknown;
314 // Check whether we need a buffer
315 if (!lyxaction.funcHasFlag(action, LyXAction::NoBuffer)) {
316 // Yes we need a buffer, do we have one?
319 // Can we use a readonly buffer?
320 if (buf->isReadonly() &&
321 !lyxaction.funcHasFlag(action,
322 LyXAction::ReadOnly)) {
324 setErrorMessage(N_("Document is read-only"));
325 flag |= LyXFunc::Disabled;
329 setErrorMessage(N_("Command not allowed with"
330 "out any document open"));
331 flag |= LyXFunc::Disabled;
335 if (flag & LyXFunc::Disabled)
338 // I would really like to avoid having this switch and rather try to
339 // encode this in the function itself.
340 static bool noLaTeX = lyxrc.latex_command == "none";
341 bool disable = false;
344 disable = noLaTeX || lyxrc.view_dvi_command == "none";
347 disable = noLaTeX || lyxrc.view_ps_command == "none";
354 disable = noLaTeX || lyxrc.print_command == "none";
357 disable = noLaTeX || lyxrc.fax_command == "none";
360 if (argument == "latex")
361 disable = lyxrc.relyx_command == "none";
362 if (argument == "linuxdoc")
363 disable = lyxrc.linuxdoc_to_lyx_command == "none";
366 if (argument == "dvi" || argument == "postscript")
368 if (argument == "html")
369 disable = lyxrc.html_command == "none";
370 if (argument == "html-linuxdoc")
371 disable = lyxrc.linuxdoc_to_html_command == "none";
372 if (argument == "html-docbook")
373 disable = lyxrc.docbook_to_html_command == "none";
376 disable = buf->undostack.empty();
379 disable = buf->redostack.empty();
381 case LFUN_SPELLCHECK:
382 disable = lyxrc.isp_command == "none";
385 disable = lyxrc.chktex_command == "none";
387 case LFUN_LAYOUT_TABLE:
388 disable = ! owner->view()->text->cursor.par->table;
394 flag |= LyXFunc::Disabled;
397 func_status box = LyXFunc::ToggleOff;
398 LyXFont font = owner->view()->text->real_current_font;
401 if (font.emph() == LyXFont::ON)
402 box = LyXFunc::ToggleOn;
405 if (font.noun() == LyXFont::ON)
406 box = LyXFunc::ToggleOn;
409 if (font.series() == LyXFont::BOLD_SERIES)
410 box = LyXFunc::ToggleOn;
413 if (font.latex() == LyXFont::ON)
414 box = LyXFunc::ToggleOn;
427 string LyXFunc::Dispatch(string const & s)
429 // Split command string into command and argument
430 string cmd, line = frontStrip(s);
431 string arg = strip(frontStrip(split(line, cmd, ' ')));
433 return Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
437 string LyXFunc::Dispatch(int ac,
438 char const * do_not_use_this_arg)
443 // we have not done anything wrong yet.
445 dispatch_buffer.clear();
447 // if action is a pseudo-action, we need the real action
448 if (lyxaction.isPseudoAction(ac)) {
450 action = static_cast<kb_action>
451 (lyxaction.retrieveActionArg(ac, tmparg));
455 action = static_cast<kb_action>(ac);
456 if (do_not_use_this_arg)
457 argument = do_not_use_this_arg; // except here
460 selection_possible = false;
462 if (owner->view()->available())
463 owner->view()->hideCursor();
465 // We cannot use this function here
466 if (getStatus(action) & Disabled)
467 goto exit_with_message;
469 commandshortcut.clear();
471 if (lyxrc.display_shortcuts && show_sc) {
472 if (action != LFUN_SELFINSERT) {
473 // Put name of command and list of shortcuts
474 // for it in minibuffer
475 string comname = lyxaction.getActionName(action);
477 int pseudoaction = action;
478 bool argsadded = false;
480 if (!argument.empty()) {
481 // If we have the command with argument,
484 lyxaction.searchActionArg(action,
487 if (pseudoaction == -1) {
488 pseudoaction = action;
490 comname += " " + argument;
495 string shortcuts = toplevel_keymap->findbinding(pseudoaction);
497 if (!shortcuts.empty()) {
498 comname += ": " + shortcuts;
499 } else if (!argsadded) {
500 comname += " " + argument;
503 if (!comname.empty()) {
504 comname = strip(comname);
505 commandshortcut = "(" + comname + ')';
506 owner->getMiniBuffer()->Set(commandshortcut);
507 // Here we could even add a small pause,
508 // to annoy the user and make him learn
510 // No! That will just annoy, not teach
511 // anything. The user will read the messages
512 // if they are interested. (Asger)
517 // If in math mode pass the control to
518 // the math inset [asierra060396]
519 if (owner->view()->available() &&
520 owner->view()->the_locking_inset) {
522 || (action == LFUN_UNKNOWN_ACTION
523 && keyseq.length >= -1)) {
524 if (action == LFUN_UNKNOWN_ACTION
525 && argument.empty()) {
526 argument = keyseq.getiso();
528 // Undo/Redo pre 0.13 is a bit tricky for insets.
529 if (action == LFUN_UNDO) {
531 UpdatableInset * inset =
532 owner->view()->the_locking_inset;
533 inset->GetCursorPos(slx, sly);
534 owner->view()->unlockInset(inset);
535 owner->view()->menuUndo();
536 if (owner->view()->text->cursor.par->
537 IsInset(owner->view()->text->cursor.pos)) {
538 inset = static_cast<UpdatableInset*>(
539 owner->view()->text->cursor.par->
540 GetInset(owner->view()->text->
546 inset->Edit(owner->view(),slx,sly,0);
548 } else if (action == LFUN_REDO) {
550 UpdatableInset * inset = owner->view()->
552 inset->GetCursorPos(slx, sly);
553 owner->view()->unlockInset(inset);
554 owner->view()->menuRedo();
555 inset = static_cast<UpdatableInset*>(
556 owner->view()->text->cursor.par->
557 GetInset(owner->view()->text->
560 inset->Edit(owner->view(),slx,sly,0);
562 } else if (owner->view()->the_locking_inset->
563 LocalDispatch(owner->view(), action,
565 UpdatableInset::DISPATCHED)
568 setMessage(N_("Text mode"));
569 LyXDirection direction = owner->view()->text->
570 cursor.par->getParDirection();
572 case LFUN_UNKNOWN_ACTION:
573 case LFUN_BREAKPARAGRAPH:
575 owner->view()->text->CursorRight();
576 owner->view()->setState();
577 owner->getMiniBuffer()->Set(CurrentState());
580 if (direction == LYX_DIR_LEFT_TO_RIGHT) {
581 owner->view()->text->CursorRight();
582 moveCursorUpdate(false);
583 owner->getMiniBuffer()->
588 if (direction == LYX_DIR_RIGHT_TO_LEFT) {
589 owner->view()->text->CursorRight();
590 moveCursorUpdate(false);
591 owner->getMiniBuffer()->
603 // --- Misc -------------------------------------------
604 case LFUN_WORDFINDFORWARD :
605 case LFUN_WORDFINDBACKWARD : {
606 static string last_search;
607 string searched_string;
609 if (!argument.empty()) {
610 last_search = argument;
611 searched_string = argument;
613 searched_string = last_search;
616 LyXText * ltCur = owner->view()->text ;
618 if (!searched_string.empty() &&
619 ((action == LFUN_WORDFINDBACKWARD) ?
620 ltCur->SearchBackward(searched_string.c_str()) :
621 ltCur->SearchForward(searched_string.c_str()))) {
623 // ??? What is that ???
624 owner->view()->update(-2);
627 // clear the selection (if there is any)
628 owner->view()->toggleSelection();
629 owner->view()->text->ClearSelection();
631 // Move cursor so that successive C-s 's will not stand in place.
632 if( action == LFUN_WORDFINDFORWARD )
633 owner->view()->text->CursorRightOneWord();
634 owner->view()->text->FinishUndo();
635 moveCursorUpdate(false);
638 // set the new selection
639 // SetSelectionOverLenChars(owner->view()->currentBuffer()->text, iLenSelected);
640 owner->view()->toggleSelection(false);
644 // REMOVED : if (owner->view()->getWorkArea()->focus)
645 owner->view()->showCursor();
651 if (owner->view()->available()) {
652 owner->view()->update(-2);
655 keyseq.print(buf, true);
656 owner->getMiniBuffer()->Set(buf, string(), string(), 1);
660 // --- Misc -------------------------------------------
661 case LFUN_EXEC_COMMAND:
662 owner->getMiniBuffer()->ExecCommand();
665 case LFUN_CANCEL: // RVDK_PATCH_5
668 if(owner->view()->available())
669 // cancel any selection
670 Dispatch(LFUN_MARK_OFF, 0);
671 setMessage(N_("Cancel"));
674 case LFUN_META_FAKE: // RVDK_PATCH_5
676 meta_fake_bit = Mod1Mask;
678 keyseq.print(buf, true);
679 string res = string("M-") + buf;
680 setMessage(buf); // RVDK_PATCH_5
684 case LFUN_READ_ONLY_TOGGLE:
685 if (owner->buffer()->lyxvc.inUse()) {
686 owner->buffer()->lyxvc.toggleReadOnly();
688 owner->buffer()->setReadonly(
689 !owner->buffer()->isReadonly());
693 case LFUN_CENTER: // this is center and redraw.
694 owner->view()->center();
698 if (owner->view()->available()) {
699 owner->view()->text->toggleAppendix();
700 owner->view()->update(1);
704 // --- Menus -----------------------------------------------
709 case LFUN_MENUNEWTMPLT:
717 case LFUN_CLOSEBUFFER:
722 owner->getMiniBuffer()->Set(_("Saving document"),
723 MakeDisplayPath(owner->buffer()->fileName()),
725 MenuWrite(owner->buffer());
726 //owner->getMiniBuffer()->
727 // Set(_("Document saved as"),
728 // MakeDisplayPath(owner->buffer()->fileName()));
730 //owner->getMiniBuffer()->Set(_("Save failed!"));
734 case LFUN_MENUWRITEAS:
735 MenuWriteAs(owner->buffer());
738 case LFUN_MENURELOAD:
743 PreviewDVI(owner->buffer());
747 PreviewPostscript(owner->buffer());
751 MenuRunLaTeX(owner->buffer());
755 MenuBuildProg(owner->buffer());
759 MenuRunChktex(owner->buffer());
763 CreatePostscript(owner->buffer(), false);
767 MenuPrint(owner->buffer());
771 MenuFax(owner->buffer());
775 MenuExport(owner->buffer(), argument);
780 //needs argument as string
781 string imtyp = argument;
784 if (imtyp == "latex") {
785 doImportLaTeX(false);
788 else if (imtyp == "ascii") {
789 doImportASCII(false);
790 } else if (imtyp == "asciiparagraph") {
793 } else if (imtyp == "noweb") {
795 } else if (imtyp == "linuxdoc") {
798 setErrorMessage(string(N_("Unknown import type: "))
810 if (fd_form_toc->form_toc->visible) {
811 fl_raise_form(fd_form_toc->form_toc);
813 static int ow = -1, oh;
814 fl_show_form(fd_form_toc->form_toc,
816 FL_FREE_SIZE, FL_FULLBORDER,
817 _("Table of Contents"));
819 ow = fd_form_toc->form_toc->w;
820 oh = fd_form_toc->form_toc->h;
822 fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
826 case LFUN_TOC_INSERT:
828 Inset * new_inset = new InsetTOC(owner->buffer());
829 owner->view()->insertInset(new_inset, "Standard", true);
833 case LFUN_LOF_INSERT:
835 Inset * new_inset = new InsetLOF(owner->buffer());
836 owner->view()->insertInset(new_inset, "Standard", true);
840 case LFUN_LOA_INSERT:
842 Inset * new_inset = new InsetLOA(owner->buffer());
843 owner->view()->insertInset(new_inset, "Standard", true);
847 case LFUN_LOT_INSERT:
849 Inset * new_inset = new InsetLOT(owner->buffer());
850 owner->view()->insertInset(new_inset, "Standard", true);
862 case LFUN_INSERT_GRAPHICS:
864 Inset * new_inset = new InsetGraphics;
865 owner->view()->insertInset(new_inset);
874 owner->view()->menuUndo();
878 owner->view()->menuRedo();
881 case LFUN_MENUSEARCH:
883 // Ok this is one _very_ bad solution, but I think that some
884 // of this will be rewritten as part of GUI indep anyway.
886 static LyXFindReplace FR_;
887 FR_.StartSearch(owner->view());
893 owner->view()->paste();
894 owner->view()->setState();
897 case LFUN_PASTESELECTION:
900 if (argument == "paragraph") asPara = true;
901 MenuPasteSelection(asPara);
906 owner->view()->cut();
910 owner->view()->copy();
913 case LFUN_LAYOUT_COPY:
914 owner->view()->copyEnvironment();
917 case LFUN_LAYOUT_PASTE:
918 owner->view()->pasteEnvironment();
919 owner->view()->setState();
923 owner->view()->gotoError();
926 case LFUN_REMOVEERRORS:
927 if (owner->view()->removeAutoInsets()) {
928 owner->view()->redraw();
929 owner->view()->fitCursor();
930 owner->view()->updateScrollbar();
935 owner->view()->gotoNote();
939 owner->view()->openStuff();
942 case LFUN_HYPHENATION:
943 owner->view()->hyphenationPoint();
947 owner->view()->ldots();
950 case LFUN_END_OF_SENTENCE:
951 owner->view()->endOfSentenceDot();
954 case LFUN_MENU_SEPARATOR:
955 owner->view()->menuSeparator();
959 owner->view()->hfill();
963 changeDepth(owner->view(), 0);
967 changeDepth(owner->view(), -1);
970 case LFUN_DEPTH_PLUS:
971 changeDepth(owner->view(), 1);
980 owner->view()->setState();
981 owner->getMiniBuffer()->Set(CurrentState());
988 case LFUN_RECONFIGURE:
989 Reconfigure(owner->view());
993 if (owner->view()->available()
994 && !owner->view()->text->selection
995 && owner->view()->text->cursor.par->footnoteflag
996 != LyXParagraph::NO_FOOTNOTE)
997 { // only melt footnotes with FOOTMELT, not margins etc
998 if(owner->view()->text->cursor.par->footnotekind == LyXParagraph::FOOTNOTE)
1002 Foot(owner->view());
1003 owner->view()->setState();
1006 case LFUN_MARGINMELT:
1007 if (owner->view()->available()
1008 && !owner->view()->text->selection
1009 && owner->view()->text->cursor.par->footnoteflag
1010 != LyXParagraph::NO_FOOTNOTE) {
1011 // only melt margins
1012 if(owner->view()->text->cursor.par->footnotekind == LyXParagraph::MARGIN)
1013 Melt(owner->view());
1015 Margin(owner->view());
1016 owner->view()->setState();
1019 // --- version control -------------------------------
1020 case LFUN_VC_REGISTER:
1022 if (!owner->buffer()->lyxvc.inUse())
1023 owner->buffer()->lyxvc.registrer();
1027 case LFUN_VC_CHECKIN:
1029 if (owner->buffer()->lyxvc.inUse()
1030 && !owner->buffer()->isReadonly())
1031 owner->buffer()->lyxvc.checkIn();
1035 case LFUN_VC_CHECKOUT:
1037 if (owner->buffer()->lyxvc.inUse()
1038 && owner->buffer()->isReadonly())
1039 owner->buffer()->lyxvc.checkOut();
1043 case LFUN_VC_REVERT:
1045 owner->buffer()->lyxvc.revert();
1051 owner->buffer()->lyxvc.undoLast();
1055 case LFUN_VC_HISTORY:
1057 owner->buffer()->lyxvc.showLog();
1061 // --- buffers ----------------------------------------
1063 case LFUN_FILE_INSERT:
1065 MenuInsertLyXFile(argument);
1069 case LFUN_FILE_INSERT_ASCII:
1071 bool asPara = (argument == "paragraph");
1072 InsertAsciiFile(owner->view(), string(), asPara);
1078 // servercmd: argument must be <file>:<template>
1079 Buffer * tmpbuf = NewLyxFile(argument);
1081 owner->view()->buffer(tmpbuf);
1085 case LFUN_FILE_OPEN:
1086 owner->view()->buffer(bufferlist.loadLyXFile(argument));
1089 case LFUN_LATEX_LOG:
1095 lyxerr.debug() << "LFUN_LAYOUTNO: (arg) " << argument << endl;
1096 int sel = strToInt(argument);
1097 lyxerr.debug() << "LFUN_LAYOUTNO: (sel) "<< sel << endl;
1099 // Should this give a setMessage instead?
1101 return string(); // illegal argument
1103 --sel; // sel 1..., but layout 0...
1105 // Pretend we got the name instead.
1106 Dispatch(int(LFUN_LAYOUT),
1107 textclasslist.NameOfLayout(owner->view()->
1116 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1117 << argument << endl;
1119 // Derive layout number from given argument (string)
1120 // and current buffer's textclass (number). */
1121 LyXTextClassList::ClassList::size_type tclass =
1122 owner->view()->text->parameters->textclass;
1123 pair <bool, LyXTextClass::size_type> layout =
1124 textclasslist.NumberOfLayout(tclass, argument);
1126 // If the entry is obsolete, use the new one instead.
1128 string obs = textclasslist.Style(tclass,layout.second)
1132 textclasslist.NumberOfLayout(tclass, obs);
1135 // see if we found the layout number:
1136 if (!layout.first) {
1137 setErrorMessage(string(N_("Layout ")) + argument +
1142 if (current_layout != layout.second) {
1143 owner->view()->hideCursor();
1144 current_layout = layout.second;
1145 owner->view()->update(-2);
1146 owner->view()->text->
1147 SetLayout(layout.second);
1148 owner->getToolbar()->combox->
1149 select(owner->view()->
1152 owner->view()->update(1);
1153 owner->view()->setState();
1158 case LFUN_LAYOUT_DOCUMENT:
1159 MenuLayoutDocument();
1162 case LFUN_LAYOUT_PARAGRAPH:
1163 MenuLayoutParagraph();
1166 case LFUN_LAYOUT_CHARACTER:
1167 MenuLayoutCharacter();
1170 case LFUN_LAYOUT_TABLE:
1173 if (argument == "true") flag = 1;
1174 MenuLayoutTable(flag);
1178 case LFUN_LAYOUT_PAPER:
1182 case LFUN_LAYOUT_QUOTES:
1186 case LFUN_LAYOUT_PREAMBLE:
1187 MenuLayoutPreamble();
1190 case LFUN_LAYOUT_SAVE_DEFAULT:
1194 case LFUN_DROP_LAYOUTS_CHOICE:
1195 owner->getToolbar()->combox->Show();
1201 owner->view()->setState();
1202 owner->getMiniBuffer()->Set(CurrentState());
1234 case LFUN_UNDERLINE:
1238 case LFUN_FONT_SIZE:
1242 case LFUN_FONT_STATE:
1243 setMessage(CurrentState());
1246 case LFUN_UPCASE_WORD:
1247 owner->view()->update(-2);
1249 owner->view()->text->ChangeWordCase(LyXText::text_uppercase);
1250 owner->view()->update(1);
1254 case LFUN_LOWCASE_WORD:
1255 owner->view()->update(-2);
1257 owner->view()->text->ChangeWordCase(LyXText::text_lowercase);
1258 owner->view()->update(1);
1262 case LFUN_CAPITALIZE_WORD:
1263 owner->view()->update(-2);
1265 owner->view()->text->ChangeWordCase(LyXText::text_capitalization);
1266 owner->view()->update(1);
1270 case LFUN_INSERT_LABEL:
1271 MenuInsertLabel(argument.c_str());
1274 case LFUN_INSERT_REF:
1278 case LFUN_REFTOGGLE:
1281 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1283 if (inset->getFlag() == InsetRef::REF)
1284 inset->setFlag(InsetRef::PAGE_REF);
1286 inset->setFlag(InsetRef::REF);
1287 owner->view()->updateInset(inset, true);
1289 setErrorMessage(N_("No cross-reference to toggle"));
1296 owner->view()->restorePosition();
1302 string label(argument);
1303 if (label.empty()) {
1305 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1307 label = inset->getContents();
1310 if (!label.empty()) {
1311 owner->view()->savePosition();
1312 owner->view()->gotoLabel(label.c_str());
1317 case LFUN_MENU_OPEN_BY_NAME:
1318 owner->getMenus()->openByName(argument);
1319 break; // RVDK_PATCH_5
1321 case LFUN_SPELLCHECK:
1322 if (lyxrc.isp_command != "none")
1323 ShowSpellChecker(owner->view());
1324 break; // RVDK_PATCH_5
1326 // --- Cursor Movements -----------------------------
1329 LyXText * tmptext = owner->view()->text;
1330 LyXDirection direction =
1331 tmptext->cursor.par->getParDirection();
1332 if(!tmptext->mark_set)
1333 owner->view()->beforeChange();
1334 owner->view()->update(-2);
1335 if (direction == LYX_DIR_RIGHT_TO_LEFT)
1336 tmptext->CursorLeft();
1337 if (tmptext->cursor.pos < tmptext->cursor.par->Last()
1338 && tmptext->cursor.par->GetChar(tmptext->cursor.pos)
1339 == LyXParagraph::META_INSET
1340 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)
1341 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)->Editable() == Inset::HIGHLY_EDITABLE){
1342 Inset * tmpinset = tmptext->cursor.par->GetInset(tmptext->cursor.pos);
1343 setMessage(tmpinset->EditMessage());
1344 tmpinset->Edit(owner->view(), 0, 0, 0);
1347 if (direction == LYX_DIR_LEFT_TO_RIGHT)
1348 tmptext->CursorRight();
1349 owner->view()->text->FinishUndo();
1350 moveCursorUpdate(false);
1351 owner->getMiniBuffer()->Set(CurrentState());
1357 // This is soooo ugly. Isn`t it possible to make
1358 // it simpler? (Lgb)
1359 LyXText * txt = owner->view()->text;
1360 LyXDirection direction = txt->cursor.par->getParDirection();
1361 if(!txt->mark_set) owner->view()->beforeChange();
1362 owner->view()->update(-2);
1363 if (direction == LYX_DIR_LEFT_TO_RIGHT)
1365 if (txt->cursor.pos < txt->cursor.par->Last()
1366 && txt->cursor.par->GetChar(txt->cursor.pos)
1367 == LyXParagraph::META_INSET
1368 && txt->cursor.par->GetInset(txt->cursor.pos)
1369 && txt->cursor.par->GetInset(txt->cursor.pos)->Editable() == Inset::HIGHLY_EDITABLE) {
1370 Inset * tmpinset = txt->cursor.par->GetInset(txt->cursor.pos);
1371 setMessage(tmpinset->EditMessage());
1372 tmpinset->Edit(owner->view(),
1373 tmpinset->width(owner->view()->painter(),
1374 txt->GetFont(txt->cursor.par,
1379 if (direction == LYX_DIR_RIGHT_TO_LEFT)
1382 owner->view()->text->FinishUndo();
1383 moveCursorUpdate(false);
1384 owner->getMiniBuffer()->Set(CurrentState());
1389 if(!owner->view()->text->mark_set) owner->view()->beforeChange();
1390 owner->view()->update(-3);
1391 owner->view()->text->CursorUp();
1392 owner->view()->text->FinishUndo();
1393 moveCursorUpdate(false);
1394 owner->getMiniBuffer()->Set(CurrentState());
1398 if(!owner->view()->text->mark_set)
1399 owner->view()->beforeChange();
1400 owner->view()->update(-3);
1401 owner->view()->text->CursorDown();
1402 owner->view()->text->FinishUndo();
1403 moveCursorUpdate(false);
1404 owner->getMiniBuffer()->Set(CurrentState());
1407 case LFUN_UP_PARAGRAPH:
1408 if(!owner->view()->text->mark_set)
1409 owner->view()->beforeChange();
1410 owner->view()->update(-3);
1411 owner->view()->text->CursorUpParagraph();
1412 owner->view()->text->FinishUndo();
1413 moveCursorUpdate(false);
1414 owner->getMiniBuffer()->Set(CurrentState());
1417 case LFUN_DOWN_PARAGRAPH:
1418 if(!owner->view()->text->mark_set)
1419 owner->view()->beforeChange();
1420 owner->view()->update(-3);
1421 owner->view()->text->CursorDownParagraph();
1422 owner->view()->text->FinishUndo();
1423 moveCursorUpdate(false);
1424 owner->getMiniBuffer()->Set(CurrentState());
1428 if(!owner->view()->text->mark_set)
1429 owner->view()->beforeChange();
1430 owner->view()->update(-3);
1431 owner->view()->cursorPrevious();
1432 owner->view()->text->FinishUndo();
1433 moveCursorUpdate(false);
1434 owner->getMiniBuffer()->Set(CurrentState());
1438 if(!owner->view()->text->mark_set)
1439 owner->view()->beforeChange();
1440 owner->view()->update(-3);
1441 owner->view()->cursorNext();
1442 owner->view()->text->FinishUndo();
1443 moveCursorUpdate(false);
1444 owner->getMiniBuffer()->Set(CurrentState());
1448 if(!owner->view()->text->mark_set)
1449 owner->view()->beforeChange();
1450 owner->view()->update(-2);
1451 owner->view()->text->CursorHome();
1452 owner->view()->text->FinishUndo();
1453 moveCursorUpdate(false);
1454 owner->getMiniBuffer()->Set(CurrentState());
1458 if(!owner->view()->text->mark_set)
1459 owner->view()->beforeChange();
1460 owner->view()->update(-2);
1461 owner->view()->text->CursorEnd();
1462 owner->view()->text->FinishUndo();
1463 moveCursorUpdate(false);
1464 owner->getMiniBuffer()->Set(CurrentState());
1468 if(!owner->view()->text->mark_set)
1469 owner->view()->beforeChange();
1470 owner->view()->update(-2);
1471 owner->view()->text->CursorTab();
1472 owner->view()->text->FinishUndo();
1473 moveCursorUpdate(false);
1474 owner->getMiniBuffer()->Set(CurrentState());
1477 case LFUN_WORDRIGHT:
1478 if(!owner->view()->text->mark_set)
1479 owner->view()->beforeChange();
1480 owner->view()->update(-2);
1481 if (owner->view()->text->cursor.par->getParDirection()
1482 == LYX_DIR_LEFT_TO_RIGHT)
1483 owner->view()->text->CursorRightOneWord();
1485 owner->view()->text->CursorLeftOneWord();
1486 owner->view()->text->FinishUndo();
1487 moveCursorUpdate(false);
1488 owner->getMiniBuffer()->Set(CurrentState());
1492 if(!owner->view()->text->mark_set)
1493 owner->view()->beforeChange();
1494 owner->view()->update(-2);
1495 if (owner->view()->text->cursor.par->getParDirection()
1496 == LYX_DIR_LEFT_TO_RIGHT)
1497 owner->view()->text->CursorLeftOneWord();
1499 owner->view()->text->CursorRightOneWord();
1500 owner->view()->text->FinishUndo();
1501 moveCursorUpdate(false);
1502 owner->getMiniBuffer()->Set(CurrentState());
1505 case LFUN_BEGINNINGBUF:
1506 if(!owner->view()->text->mark_set)
1507 owner->view()->beforeChange();
1508 owner->view()->update(-2);
1509 owner->view()->text->CursorTop();
1510 owner->view()->text->FinishUndo();
1511 moveCursorUpdate(false);
1512 owner->getMiniBuffer()->Set(CurrentState());
1516 if(!owner->view()->text->mark_set)
1517 owner->view()->beforeChange();
1518 owner->view()->update(-2);
1519 owner->view()->text->CursorBottom();
1520 owner->view()->text->FinishUndo();
1521 moveCursorUpdate(false);
1522 owner->getMiniBuffer()->Set(CurrentState());
1526 /* cursor selection ---------------------------- */
1528 owner->view()->update(-2);
1529 if (owner->view()->text->cursor.par->getParDirection()
1530 == LYX_DIR_LEFT_TO_RIGHT)
1531 owner->view()->text->CursorRight();
1533 owner->view()->text->CursorLeft();
1534 owner->view()->text->FinishUndo();
1535 moveCursorUpdate(true);
1536 owner->getMiniBuffer()->Set(CurrentState());
1540 owner->view()->update(-2);
1541 if (owner->view()->text->cursor.par->getParDirection()
1542 == LYX_DIR_LEFT_TO_RIGHT)
1543 owner->view()->text->CursorLeft();
1545 owner->view()->text->CursorRight();
1546 owner->view()->text->FinishUndo();
1547 moveCursorUpdate(true);
1548 owner->getMiniBuffer()->Set(CurrentState());
1552 owner->view()->update(-2);
1553 owner->view()->text->CursorUp();
1554 owner->view()->text->FinishUndo();
1555 moveCursorUpdate(true);
1556 owner->getMiniBuffer()->Set(CurrentState());
1560 owner->view()->update(-2);
1561 owner->view()->text->CursorDown();
1562 owner->view()->text->FinishUndo();
1563 moveCursorUpdate(true);
1564 owner->getMiniBuffer()->Set(CurrentState());
1567 case LFUN_UP_PARAGRAPHSEL:
1568 owner->view()->update(-2);
1569 owner->view()->text->CursorUpParagraph();
1570 owner->view()->text->FinishUndo();
1571 moveCursorUpdate(true);
1572 owner->getMiniBuffer()->Set(CurrentState());
1575 case LFUN_DOWN_PARAGRAPHSEL:
1576 owner->view()->update(-2);
1577 owner->view()->text->CursorDownParagraph();
1578 owner->view()->text->FinishUndo();
1579 moveCursorUpdate(true);
1580 owner->getMiniBuffer()->Set(CurrentState());
1584 owner->view()->update(-2);
1585 owner->view()->cursorPrevious();
1586 owner->view()->text->FinishUndo();
1587 moveCursorUpdate(true);
1588 owner->getMiniBuffer()->Set(CurrentState());
1592 owner->view()->update(-2);
1593 owner->view()->cursorNext();
1594 owner->view()->text->FinishUndo();
1595 moveCursorUpdate(true);
1596 owner->getMiniBuffer()->Set(CurrentState());
1600 owner->view()->update(-2);
1601 owner->view()->text->CursorHome();
1602 owner->view()->text->FinishUndo();
1603 moveCursorUpdate(true);
1604 owner->getMiniBuffer()->Set(CurrentState());
1608 owner->view()->update(-2);
1609 owner->view()->text->CursorEnd();
1610 owner->view()->text->FinishUndo();
1611 moveCursorUpdate(true);
1612 owner->getMiniBuffer()->Set(CurrentState());
1615 case LFUN_WORDRIGHTSEL:
1616 owner->view()->update(-2);
1617 if (owner->view()->text->cursor.par->getParDirection()
1618 == LYX_DIR_LEFT_TO_RIGHT)
1619 owner->view()->text->CursorRightOneWord();
1621 owner->view()->text->CursorLeftOneWord();
1622 owner->view()->text->FinishUndo();
1623 moveCursorUpdate(true);
1624 owner->getMiniBuffer()->Set(CurrentState());
1627 case LFUN_WORDLEFTSEL:
1628 owner->view()->update(-2);
1629 if (owner->view()->text->cursor.par->getParDirection()
1630 == LYX_DIR_LEFT_TO_RIGHT)
1631 owner->view()->text->CursorLeftOneWord();
1633 owner->view()->text->CursorRightOneWord();
1634 owner->view()->text->FinishUndo();
1635 moveCursorUpdate(true);
1636 owner->getMiniBuffer()->Set(CurrentState());
1639 case LFUN_BEGINNINGBUFSEL:
1640 owner->view()->update(-2);
1641 owner->view()->text->CursorTop();
1642 owner->view()->text->FinishUndo();
1643 moveCursorUpdate(true);
1644 owner->getMiniBuffer()->Set(CurrentState());
1647 case LFUN_ENDBUFSEL:
1648 owner->view()->update(-2);
1649 owner->view()->text->CursorBottom();
1650 owner->view()->text->FinishUndo();
1651 moveCursorUpdate(true);
1652 owner->getMiniBuffer()->Set(CurrentState());
1655 // --- text changing commands ------------------------
1656 case LFUN_BREAKLINE:
1658 owner->view()->beforeChange();
1659 owner->view()->text->InsertChar(LyXParagraph::META_NEWLINE);
1660 owner->view()->smallUpdate(1);
1661 SetUpdateTimer(0.01);
1662 moveCursorUpdate(false);
1664 owner->view()->newline();
1668 case LFUN_PROTECTEDSPACE:
1671 LyXLayout const & style =
1672 textclasslist.Style(owner->view()->buffer()->params.textclass,
1673 owner->view()->text->cursor.par->GetLayout());
1675 if (style.free_spacing) {
1676 owner->view()->text->InsertChar(' ');
1677 owner->view()->update(-1);
1679 owner->view()->protectedBlank();
1681 moveCursorUpdate(false);
1684 owner->view()->beforeChange();
1685 owner->view()->text->
1686 InsertChar(LyXParagraph::META_PROTECTED_SEPARATOR);
1687 owner->view()->smallUpdate(1);
1689 moveCursorUpdate(false);
1694 if(owner->view()->text->mark_set) {
1695 owner->view()->beforeChange();
1696 owner->view()->update(0);
1697 setMessage(N_("Mark removed"));
1699 owner->view()->beforeChange();
1700 owner->view()->text->mark_set = 1;
1701 owner->view()->update(0);
1702 setMessage(N_("Mark set"));
1704 owner->view()->text->sel_cursor =
1705 owner->view()->text->cursor;
1710 if (!owner->view()->text->selection) {
1711 owner->view()->text->Delete();
1712 owner->view()->text->sel_cursor =
1713 owner->view()->text->cursor;
1714 owner->view()->smallUpdate(1);
1715 // It is possible to make it a lot faster still
1716 // just comment out the lone below...
1717 owner->view()->showCursor();
1719 owner->view()->cut();
1722 moveCursorUpdate(false);
1723 owner->getMiniBuffer()->Set(CurrentState());
1724 owner->view()->setState();
1727 case LFUN_DELETE_SKIP:
1729 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1731 LyXCursor cursor = owner->view()->text->cursor;
1734 if (!owner->view()->text->selection) {
1735 if (cursor.pos == cursor.par->Last()) {
1736 owner->view()->text->CursorRight();
1737 cursor = owner->view()->text->cursor;
1739 && !(cursor.par->added_space_top
1740 == VSpace (VSpace::NONE))) {
1741 owner->view()->text->SetParagraph
1742 (cursor.par->line_top,
1743 cursor.par->line_bottom,
1744 cursor.par->pagebreak_top,
1745 cursor.par->pagebreak_bottom,
1746 VSpace(VSpace::NONE),
1747 cursor.par->added_space_bottom,
1749 cursor.par->labelwidthstring, 0);
1750 owner->view()->text->CursorLeft();
1751 owner->view()->update (1);
1753 owner->view()->text->CursorLeft();
1754 owner->view()->text->Delete();
1755 owner->view()->text->sel_cursor =
1756 owner->view()->text->cursor;
1757 owner->view()->smallUpdate(1);
1760 owner->view()->text->Delete();
1761 owner->view()->text->sel_cursor =
1762 owner->view()->text->cursor;
1763 owner->view()->smallUpdate(1);
1766 owner->view()->cut();
1772 /* -------> Delete word forward. */
1773 case LFUN_DELETE_WORD_FORWARD:
1774 owner->view()->update(-2);
1776 owner->view()->text->DeleteWordForward();
1777 owner->view()->update( 1 );
1779 moveCursorUpdate(false);
1780 owner->getMiniBuffer()->Set(CurrentState());
1783 /* -------> Delete word backward. */
1784 case LFUN_DELETE_WORD_BACKWARD:
1785 owner->view()->update(-2);
1787 owner->view()->text->DeleteWordBackward();
1788 owner->view()->update( 1 );
1790 moveCursorUpdate(false);
1791 owner->getMiniBuffer()->Set(CurrentState());
1794 /* -------> Kill to end of line. */
1795 case LFUN_DELETE_LINE_FORWARD:
1797 owner->view()->update(-2);
1798 owner->view()->text->DeleteLineForward();
1799 owner->view()->update( 1 );
1801 moveCursorUpdate(false);
1804 /* -------> Set mark off. */
1806 owner->view()->beforeChange();
1807 owner->view()->update(0);
1808 owner->view()->text->sel_cursor =
1809 owner->view()->text->cursor;
1810 setMessage(N_("Mark off"));
1813 /* -------> Set mark on. */
1815 owner->view()->beforeChange();
1816 owner->view()->text->mark_set = 1;
1817 owner->view()->update( 0 );
1818 owner->view()->text->sel_cursor =
1819 owner->view()->text->cursor;
1820 setMessage(N_("Mark on"));
1823 case LFUN_BACKSPACE:
1826 if (!owner->view()->text->selection) {
1827 if (owner->getIntl()->getTrans()->backspace()) {
1828 owner->view()->text->Backspace();
1829 owner->view()->text->sel_cursor =
1830 owner->view()->text->cursor;
1831 owner->view()->smallUpdate(1);
1832 // It is possible to make it a lot faster still
1833 // just comment out the lone below...
1834 owner->view()->showCursor();
1837 owner->view()->cut();
1840 owner->getMiniBuffer()->Set(CurrentState());
1841 owner->view()->setState();
1845 case LFUN_BACKSPACE_SKIP:
1847 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1849 LyXCursor cursor = owner->view()->text->cursor;
1852 if (!owner->view()->text->selection) {
1854 && !(cursor.par->added_space_top
1855 == VSpace (VSpace::NONE))) {
1856 owner->view()->text->SetParagraph
1857 (cursor.par->line_top,
1858 cursor.par->line_bottom,
1859 cursor.par->pagebreak_top,
1860 cursor.par->pagebreak_bottom,
1861 VSpace(VSpace::NONE), cursor.par->added_space_bottom,
1863 cursor.par->labelwidthstring, 0);
1864 owner->view()->update (1);
1866 owner->view()->text->Backspace();
1867 owner->view()->text->sel_cursor
1869 owner->view()->smallUpdate (1);
1872 owner->view()->cut();
1877 case LFUN_BREAKPARAGRAPH:
1879 owner->view()->beforeChange();
1880 owner->view()->text->BreakParagraph(0);
1881 owner->view()->smallUpdate(1);
1882 SetUpdateTimer(0.01);
1883 owner->view()->text->sel_cursor =
1884 owner->view()->text->cursor;
1885 owner->view()->setState();
1886 owner->getMiniBuffer()->Set(CurrentState());
1890 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1892 owner->view()->beforeChange();
1893 owner->view()->text->BreakParagraph(1);
1894 owner->view()->smallUpdate(1);
1895 SetUpdateTimer(0.01);
1896 owner->view()->text->sel_cursor =
1897 owner->view()->text->cursor;
1898 owner->view()->setState();
1899 owner->getMiniBuffer()->Set(CurrentState());
1903 case LFUN_BREAKPARAGRAPH_SKIP:
1905 // When at the beginning of a paragraph, remove
1906 // indentation and add a "defskip" at the top.
1907 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
1909 LyXCursor cursor = owner->view()->text->cursor;
1911 owner->view()->beforeChange();
1912 if (cursor.pos == 0) {
1913 if (cursor.par->added_space_top == VSpace(VSpace::NONE)) {
1914 owner->view()->text->SetParagraph
1915 (cursor.par->line_top,
1916 cursor.par->line_bottom,
1917 cursor.par->pagebreak_top,
1918 cursor.par->pagebreak_bottom,
1919 VSpace(VSpace::DEFSKIP), cursor.par->added_space_bottom,
1921 cursor.par->labelwidthstring, 1);
1922 owner->view()->update(1);
1926 owner->view()->text->BreakParagraph(0);
1927 owner->view()->smallUpdate(1);
1929 SetUpdateTimer(0.01);
1930 owner->view()->text->sel_cursor = cursor;
1931 owner->view()->setState();
1932 owner->getMiniBuffer()->Set(CurrentState());
1937 owner->view()->beforeChange();
1938 owner->view()->text->InsertChar('\"'); // This " matches the single quote in the code
1939 owner->view()->smallUpdate(1);
1941 moveCursorUpdate(false);
1947 InsetCommand * new_inset;
1948 if (action == LFUN_HTMLURL)
1949 new_inset = new InsetUrl("htmlurl", "", "");
1951 new_inset = new InsetUrl("url", "", "");
1952 owner->view()->insertInset(new_inset);
1953 new_inset->Edit(owner->view(), 0, 0, 0);
1956 case LFUN_INSET_TEXT:
1958 InsetText * new_inset = new InsetText(owner->buffer());
1959 owner->view()->insertInset(new_inset);
1960 new_inset->Edit(owner->view(), 0, 0, 0);
1963 case LFUN_INSET_NUMBER:
1965 InsetNumber * new_inset = new InsetNumber(owner->buffer());
1966 owner->view()->insertInset(new_inset);
1967 new_inset->Edit(owner->view(), 0, 0, 0);
1970 case LFUN_INSET_ERT:
1972 InsetERT * new_inset = new InsetERT(owner->buffer());
1973 owner->view()->insertInset(new_inset);
1974 new_inset->Edit(owner->view(), 0, 0, 0);
1977 case LFUN_INSET_FOOTNOTE:
1979 InsetFoot * new_inset = new InsetFoot(owner->buffer());
1980 owner->view()->insertInset(new_inset);
1981 new_inset->Edit(owner->view(), 0, 0, 0);
1985 // --- lyxserver commands ----------------------------
1987 case LFUN_CHARATCURSOR:
1989 LyXParagraph::size_type pos =
1990 owner->view()->text->cursor.pos;
1991 if(pos < owner->view()->text->cursor.par->size())
1992 //dispatch_buffer = owner->view()->text->
1993 // cursor.par->text[pos];
1995 owner->view()->text->
1996 cursor.par->GetChar(pos);
1998 dispatch_buffer = "EOF";
2004 tostr(owner->view()->text->cursor.x) + ' '
2005 + tostr(owner->view()->text->cursor.y);
2012 sscanf(argument.c_str(), " %d %ld", &x, &y);
2013 owner->view()->text->SetCursorFromCoordinates(x, y);
2017 case LFUN_GETLAYOUT:
2019 tostr(owner->view()->text->cursor.par->layout);
2024 LyXFont * font = &(owner->view()->text->current_font);
2025 if(font->shape() == LyXFont::ITALIC_SHAPE)
2026 dispatch_buffer = 'E';
2027 else if(font->shape() == LyXFont::SMALLCAPS_SHAPE)
2028 dispatch_buffer = 'N';
2030 dispatch_buffer = '0';
2037 LyXFont * font = &(owner->view()->text->current_font);
2038 if(font->latex() == LyXFont::ON)
2039 dispatch_buffer = 'L';
2041 dispatch_buffer = '0';
2046 setMessage(owner->buffer()->fileName());
2047 lyxerr.debug() << "FNAME["
2048 << owner->buffer()->fileName()
2056 dispatch_buffer = buf;
2057 lyxserver->notifyClient(dispatch_buffer);
2061 case LFUN_GOTOFILEROW:
2063 char file_name[100];
2065 sscanf(argument.c_str(), " %s %d", file_name, &row);
2067 // Must replace extension of the file to be .lyx and get full path
2068 string s = ChangeExtension(string(file_name), ".lyx", false);
2070 // Either change buffer or load the file
2071 if (bufferlist.exists(s))
2072 owner->view()->buffer(bufferlist.getBuffer(s));
2074 owner->view()->buffer(bufferlist.loadLyXFile(s));
2077 owner->view()->setCursorFromRow(row);
2080 owner->view()->center();
2087 int qa = lyxaction.LookupFunc(argument.c_str());
2088 setMessage(lyxaction.helpText(static_cast<kb_action>(qa)));
2092 // --- accented characters ---------------------------
2095 case LFUN_CIRCUMFLEX:
2105 case LFUN_SPECIAL_CARON:
2108 case LFUN_HUNG_UMLAUT:
2114 if (keyseq.length == -1 && keyseq.getiso() != 0)
2115 c = keyseq.getiso();
2119 owner->getIntl()->getTrans()->
2120 deadkey(c, get_accent(action).accent,
2121 owner->view()->text);
2123 // Need to reset, in case the minibuffer calls these
2128 // copied verbatim from do_accent_char
2129 owner->view()->smallUpdate(1);
2131 owner->view()->text->sel_cursor =
2132 owner->view()->text->cursor;
2136 // --- toolbar ----------------------------------
2137 case LFUN_PUSH_TOOLBAR:
2139 int nth = strToInt(argument);
2140 if (lyxerr.debugging(Debug::TOOLBAR)) {
2141 lyxerr << "LFUN_PUSH_TOOLBAR: argument = `"
2142 << argument << "'\n"
2143 << "LFUN_PUSH_TOOLBAR: nth = `"
2144 << nth << "'" << endl;
2149 setErrorMessage(N_("Push-toolbar needs argument > 0"));
2151 owner->getToolbar()->push(nth);
2156 case LFUN_ADD_TO_TOOLBAR:
2158 if (lyxerr.debugging(Debug::TOOLBAR)) {
2159 lyxerr << "LFUN_ADD_TO_TOOLBAR:"
2160 "argument = `" << argument << '\'' << endl;
2162 string tmp(argument);
2163 //lyxerr <<string("Argument: ") + argument);
2164 //lyxerr <<string("Tmp : ") + tmp);
2167 setErrorMessage(N_("Usage: toolbar-add-to <LyX command>"));
2169 owner->getToolbar()->add(argument, false);
2170 owner->getToolbar()->set();
2175 // --- insert characters ----------------------------------------
2177 // --- Mathed stuff. If we are here, there is no locked inset yet.
2182 if (!greek_kb_flag) {
2184 setMessage(N_("Math greek mode on"));
2191 case LFUN_GREEK_TOGGLE:
2193 greek_kb_flag = greek_kb_flag ? 0 : 2;
2194 if (greek_kb_flag) {
2195 setMessage(N_("Math greek keyboard on"));
2197 setMessage(N_("Math greek keyboard off"));
2202 case LFUN_MATH_DELIM:
2203 case LFUN_INSERT_MATRIX:
2205 if (owner->view()->available()) {
2207 open_new_inset(new InsetFormula(false));
2210 ->LocalDispatch(owner->view(),
2217 case LFUN_INSERT_MATH:
2219 math_insert_symbol(argument.c_str());
2223 case LFUN_MATH_DISPLAY:
2225 if (owner->view()->available())
2226 owner->view()->open_new_inset(new InsetFormula(true));
2230 case LFUN_MATH_MACRO:
2232 if (owner->view()->available()) {
2235 setErrorMessage(N_("Missing argument"));
2237 string s1 = token(s, ' ', 1);
2238 int na = s1.empty() ? 0: atoi(s1.c_str());
2240 open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2246 case LFUN_MATH_MODE: // Open or create a math inset
2249 if (owner->view()->available())
2250 owner->view()->open_new_inset(new InsetFormula);
2251 setMessage(N_("Math editor mode"));
2255 case LFUN_MATH_NUMBER:
2256 case LFUN_MATH_LIMITS:
2258 setErrorMessage(N_("This is only allowed in math mode!"));
2262 case LFUN_INSERT_CITATION:
2264 InsetCitation * new_inset = new InsetCitation();
2266 // The note, if any, must be after the key, delimited
2267 // by a | so both key and remark can have spaces.
2268 if (!argument.empty()) {
2269 string lsarg(argument);
2270 if (contains(lsarg, "|")) {
2271 new_inset->setContents(token(lsarg, '|', 0));
2272 new_inset->setOptions(token(lsarg, '|', 1));
2274 new_inset->setContents(lsarg);
2275 owner->view()->insertInset(new_inset);
2277 owner->view()->insertInset(new_inset);
2278 new_inset->Edit(owner->view(), 0, 0, 0);
2283 case LFUN_INSERT_BIBTEX:
2285 // ale970405+lasgoutt970425
2286 // The argument can be up to two tokens separated
2287 // by a space. The first one is the bibstyle.
2288 string lsarg(argument);
2289 string bibstyle = token(lsarg, ' ', 1);
2290 if (bibstyle.empty())
2292 InsetBibtex * new_inset
2293 = new InsetBibtex(token(lsarg, ' ', 0),
2297 owner->view()->insertInset(new_inset);
2298 if (lsarg.empty()) {
2299 new_inset->Edit(owner->view(), 0, 0, 0);
2304 // BibTeX data bases
2305 case LFUN_BIBDB_ADD:
2307 InsetBibtex * inset =
2308 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2310 inset->addDatabase(argument);
2315 case LFUN_BIBDB_DEL:
2317 InsetBibtex * inset =
2318 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2320 inset->delDatabase(argument);
2325 case LFUN_BIBTEX_STYLE:
2327 InsetBibtex * inset =
2328 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2330 inset->setOptions(argument);
2335 case LFUN_INDEX_INSERT:
2336 case LFUN_INDEX_INSERT_LAST:
2338 // Can't do that at the beginning of a paragraph.
2339 if (owner->view()->text->cursor.pos - 1 < 0)
2342 InsetIndex * new_inset = new InsetIndex();
2343 if (!argument.empty()) {
2344 string lsarg(argument);
2345 new_inset->setContents(lsarg);
2346 owner->view()->insertInset(new_inset);
2349 //get the current word for an argument
2350 LyXParagraph::size_type lastpos =
2351 owner->view()->text->cursor.pos - 1;
2352 // Get the current word. note that this must be done
2353 // before inserting the inset, or the inset will
2355 string curstring(owner->view()
2356 ->text->cursor.par->GetWord(lastpos));
2358 //make the new inset and write the current word into it
2359 InsetIndex * new_inset = new InsetIndex();
2361 new_inset->setContents(curstring);
2363 //don't edit it if the call was to INSERT_LAST
2364 if(action != LFUN_INDEX_INSERT_LAST) {
2365 new_inset->Edit(owner->view(), 0, 0, 0);
2367 //it looks blank on the screen unless
2368 //we do something. put it here.
2370 // move the cursor to the returned value of lastpos
2371 // but only for the auto-insert
2372 owner->view()->text->cursor.pos = lastpos;
2375 //put the new inset into the buffer.
2376 // there should be some way of knowing the user
2377 //cancelled & avoiding this, but i don't know how
2378 owner->view()->insertInset(new_inset);
2383 case LFUN_INDEX_PRINT:
2385 Inset * new_inset = new InsetPrintIndex(owner->buffer());
2386 owner->view()->insertInset(new_inset, "Standard", true);
2390 case LFUN_PARENTINSERT:
2392 lyxerr << "arg " << argument << endl;
2393 Inset * new_inset = new InsetParent(argument, owner->buffer());
2394 owner->view()->insertInset(new_inset, "Standard", true);
2398 case LFUN_CHILDINSERT:
2400 Inset * new_inset = new InsetInclude(argument,
2402 owner->view()->insertInset(new_inset, "Standard", true);
2403 new_inset->Edit(owner->view(), 0, 0, 0);
2407 case LFUN_CHILDOPEN:
2410 MakeAbsPath(argument,
2411 OnlyPath(owner->buffer()->fileName()));
2412 setMessage(N_("Opening child document ") +
2413 MakeDisplayPath(filename) + "...");
2414 owner->view()->savePosition();
2415 if (bufferlist.exists(filename))
2416 owner->view()->buffer(bufferlist.getBuffer(filename));
2418 owner->view()->buffer(bufferlist.loadLyXFile(filename));
2422 case LFUN_INSERT_NOTE:
2423 owner->view()->insertNote();
2426 case LFUN_INSERTFOOTNOTE:
2428 LyXParagraph::footnote_kind kind;
2429 if (argument == "footnote")
2430 { kind = LyXParagraph::FOOTNOTE; }
2431 else if (argument == "margin")
2432 { kind = LyXParagraph::MARGIN; }
2433 else if (argument == "figure")
2434 { kind = LyXParagraph::FIG; }
2435 else if (argument == "table")
2436 { kind = LyXParagraph::TAB; }
2437 else if (argument == "wide-fig")
2438 { kind = LyXParagraph::WIDE_FIG; }
2439 else if (argument == "wide-tab")
2440 { kind = LyXParagraph::WIDE_TAB; }
2441 else if (argument == "algorithm")
2442 { kind = LyXParagraph::ALGORITHM; }
2444 setErrorMessage(N_("Unknown kind of footnote"));
2447 owner->view()->text->InsertFootnoteEnvironment(kind);
2448 owner->view()->update(1);
2449 owner->view()->setState();
2453 case LFUN_BUFFERBULLETSSELECT:
2457 case LFUN_TOGGLECURSORFOLLOW:
2458 cursor_follows_scrollbar = !cursor_follows_scrollbar;
2461 case LFUN_KMAP_OFF: // keymap off
2462 owner->getIntl()->KeyMapOn(false);
2465 case LFUN_KMAP_PRIM: // primary keymap
2466 owner->getIntl()->KeyMapPrim();
2469 case LFUN_KMAP_SEC: // secondary keymap
2470 owner->getIntl()->KeyMapSec();
2473 case LFUN_KMAP_TOGGLE: // toggle keymap
2474 owner->getIntl()->ToggleKeyMap();
2477 case LFUN_SELFINSERT:
2479 for (string::size_type i = 0; i < argument.length(); ++i) {
2480 owner->view()->text->InsertChar(argument[i]);
2481 // This needs to be in the loop, or else we
2482 // won't break lines correctly. (Asger)
2483 owner->view()->smallUpdate(1);
2486 owner->view()->text->sel_cursor =
2487 owner->view()->text->cursor;
2488 moveCursorUpdate(false);
2494 // argument contains ';'-terminated commands
2495 while (argument.find(';') != string::npos) {
2497 argument = split(argument, first, ';');
2503 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
2511 now_time_t = time(NULL);
2512 now_tm = localtime(&now_time_t);
2513 (void)setlocale(LC_TIME, "");
2514 if (!argument.empty())
2516 else if (arg.empty())
2517 arg = lyxrc.date_insert_format;
2518 datetmp_len = (int) strftime(datetmp, 32, arg.c_str(), now_tm);
2519 for (int i = 0; i < datetmp_len; i++) {
2520 owner->view()->text->InsertChar(datetmp[i]);
2521 owner->view()->smallUpdate(1);
2524 owner->view()->text->sel_cursor = owner->view()->text->cursor;
2525 moveCursorUpdate(false);
2529 case LFUN_SAVEPREFERENCES:
2531 Path p(user_lyxdir);
2532 lyxrc.write("preferences");
2536 case LFUN_UNKNOWN_ACTION:
2538 if(!owner->buffer()) {
2540 setErrorMessage(N_("No document open"));
2544 if (owner->buffer()->isReadonly()) {
2546 setErrorMessage(N_("Document is read only"));
2550 if (!argument.empty()) {
2552 /* Automatically delete the currently selected
2553 * text and replace it with what is being
2554 * typed in now. Depends on lyxrc settings
2555 * "auto_region_delete", which defaults to
2558 if ( lyxrc.auto_region_delete ) {
2559 if (owner->view()->text->selection){
2560 owner->view()->text->CutSelection(false);
2561 owner->view()->update(-1);
2565 owner->view()->beforeChange();
2567 if (isdigit(argument[0]) &&
2568 (lyxrc.number_inset == "true" ||
2569 (lyxrc.number_inset == "rtl" &&
2570 owner->view()->text->real_current_font.isVisibleRightToLeft()
2572 UpdatableInset * tmpinset = new InsetNumber(owner->buffer());
2573 owner->view()->open_new_inset(tmpinset);
2574 tmpinset->LocalDispatch(owner->view(), action,
2579 for (string::size_type i = 0;
2580 i < argument.length(); ++i) {
2581 if (greek_kb_flag) {
2582 if (!math_insert_greek(argument[i]))
2583 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2585 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2588 owner->view()->smallUpdate(1);
2591 owner->view()->text->sel_cursor =
2592 owner->view()->text->cursor;
2593 moveCursorUpdate(false);
2596 // why is an "Unknown action" with empty
2597 // argument even dispatched in the first
2598 // place? I`ll probably change that. (Lgb)
2600 setErrorMessage(N_("Unknown action"));
2604 lyxerr << "A truly unknown func!" << endl;
2610 string res = getMessage();
2613 if (!commandshortcut.empty()) {
2614 string newbuf = owner->getMiniBuffer()->GetText();
2615 if (newbuf != commandshortcut) {
2616 owner->getMiniBuffer()->Set(newbuf
2622 owner->getMiniBuffer()->Set(string(_(res.c_str()))
2623 + " " + commandshortcut);
2630 void LyXFunc::setupLocalKeymap()
2632 keyseq.stdmap = keyseq.curmap = toplevel_keymap;
2633 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap;
2637 void LyXFunc::MenuNew(bool fromTemplate)
2639 string fname, initpath = lyxrc.document_path;
2642 if (owner->view()->available()) {
2643 string trypath = owner->buffer()->filepath;
2644 // If directory is writeable, use this as default.
2645 if (IsDirWriteable(trypath) == 1)
2650 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
2651 fileDlg.SetButton(1, _("Templates"), lyxrc.template_path);
2652 fname = fileDlg.Select(_("Enter Filename for new document"),
2653 initpath, "*.lyx", _("newfile"));
2656 if (fname.empty()) {
2657 owner->getMiniBuffer()->Set(_("Canceled."));
2658 lyxerr.debug() << "New Document Cancelled." << endl;
2662 // get absolute path of file and make sure the filename ends
2664 string s = MakeAbsPath(fname);
2665 if (!IsLyXFilename(s))
2668 // Check if the document already is open
2669 if (bufferlist.exists(s)){
2670 switch(AskConfirmation(_("Document is already open:"),
2671 MakeDisplayPath(s, 50),
2672 _("Do you want to close that document now?\n"
2673 "('No' will just switch to the open version)")))
2675 case 1: // Yes: close the document
2676 if (!bufferlist.close(bufferlist.getBuffer(s)))
2677 // If close is canceled, we cancel here too.
2680 case 2: // No: switch to the open document
2681 owner->view()->buffer(bufferlist.getBuffer(s));
2683 case 3: // Cancel: Do nothing
2684 owner->getMiniBuffer()->Set(_("Canceled."));
2689 // Check whether the file already exists
2690 if (IsLyXFilename(s)) {
2692 if (fi.readable() &&
2693 AskQuestion(_("File already exists:"),
2694 MakeDisplayPath(s, 50),
2695 _("Do you want to open the document?"))) {
2697 owner->getMiniBuffer()->Set(_("Opening document"),
2698 MakeDisplayPath(s), "...");
2700 owner->view()->buffer(
2701 bufferlist.loadLyXFile(s));
2702 owner->getMiniBuffer()->Set(_("Document"),
2709 // The template stuff
2713 fname = fileDlg.Select(_("Choose template"),
2714 lyxrc.template_path,
2720 // find a free buffer
2721 lyxerr.debug() << "Find a free buffer." << endl;
2722 owner->view()->buffer(bufferlist.newFile(s, templname));
2726 void LyXFunc::MenuOpen()
2728 string initpath = lyxrc.document_path;
2731 if (owner->view()->available()) {
2732 string trypath = owner->buffer()->filepath;
2733 // If directory is writeable, use this as default.
2734 if (IsDirWriteable(trypath) == 1)
2740 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
2741 fileDlg.SetButton(1, _("Examples"),
2742 AddPath(system_lyxdir, "examples"));
2743 string filename = fileDlg.Select(_("Select Document to Open"),
2747 // check selected filename
2748 if (filename.empty()) {
2749 owner->getMiniBuffer()->Set(_("Canceled."));
2753 // get absolute path of file and make sure the filename ends
2755 filename = MakeAbsPath(filename);
2756 if (!IsLyXFilename(filename))
2760 owner->getMiniBuffer()->Set(_("Opening document"),
2761 MakeDisplayPath(filename), "...");
2762 Buffer * openbuf = bufferlist.loadLyXFile(filename);
2764 owner->view()->buffer(openbuf);
2765 owner->getMiniBuffer()->Set(_("Document"),
2766 MakeDisplayPath(filename),
2769 owner->getMiniBuffer()->Set(_("Could not open document"),
2770 MakeDisplayPath(filename));
2775 void LyXFunc::doImportASCII(bool linorpar)
2777 string initpath = lyxrc.document_path;
2780 if (owner->view()->available()) {
2781 string trypath = owner->buffer()->filepath;
2782 // If directory is writeable, use this as default.
2783 if (IsDirWriteable(trypath) == 1)
2789 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
2790 fileDlg.SetButton(1, _("Examples"),
2791 AddPath(system_lyxdir, "examples"));
2792 string filename = fileDlg.Select(_("Select ASCII file to Import"),
2796 // check selected filename
2797 if (filename.empty()) {
2798 owner->getMiniBuffer()->Set(_("Canceled."));
2802 // get absolute path of file
2803 filename = MakeAbsPath(filename);
2805 string s = ChangeExtension(filename, ".lyx", false);
2807 // Check if the document already is open
2808 if (bufferlist.exists(s)) {
2809 switch(AskConfirmation(_("Document is already open:"),
2810 MakeDisplayPath(s, 50),
2811 _("Do you want to close that document now?\n"
2812 "('No' will just switch to the open version)")))
2814 case 1: // Yes: close the document
2815 if (!bufferlist.close(bufferlist.getBuffer(s)))
2816 // If close is canceled, we cancel here too.
2819 case 2: // No: switch to the open document
2820 owner->view()->buffer(bufferlist.getBuffer(s));
2822 case 3: // Cancel: Do nothing
2823 owner->getMiniBuffer()->Set(_("Canceled."));
2828 // Check if a LyX document by the same root exists in filesystem
2829 FileInfo f(s, true);
2830 if (f.exist() && !AskQuestion(_("A document by the name"),
2832 _("already exists. Overwrite?"))) {
2833 owner->getMiniBuffer()->Set(_("Canceled."));
2837 owner->view()->buffer(bufferlist.newFile(s, string()));
2838 owner->getMiniBuffer()->Set(_("Importing ASCII file"),
2839 MakeDisplayPath(filename), "...");
2840 // Insert ASCII file
2841 InsertAsciiFile(owner->view(), filename, linorpar);
2842 owner->getMiniBuffer()->Set(_("ASCII file "),
2843 MakeDisplayPath(filename),
2848 void LyXFunc::doImportLaTeX(bool isnoweb)
2850 string initpath = lyxrc.document_path;
2853 if (owner->view()->available()) {
2854 string trypath = owner->buffer()->filepath;
2855 // If directory is writeable, use this as default.
2856 if (IsDirWriteable(trypath) == 1)
2862 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
2863 fileDlg.SetButton(1, _("Examples"),
2864 AddPath(system_lyxdir, "examples"));
2867 filename = fileDlg.Select(_("Select Noweb file to Import"),
2870 filename = fileDlg.Select(_("Select LaTeX file to Import"),
2876 // check selected filename
2877 if (filename.empty()) {
2878 owner->getMiniBuffer()->Set(_("Canceled."));
2882 // get absolute path of file
2883 filename = MakeAbsPath(filename);
2885 // Check if the document already is open
2886 string LyXfilename = ChangeExtension(filename, ".lyx", false);
2887 if (bufferlist.exists(LyXfilename)){
2888 switch(AskConfirmation(_("Document is already open:"),
2889 MakeDisplayPath(LyXfilename, 50),
2890 _("Do you want to close that document now?\n"
2891 "('No' will just switch to the open version)")))
2893 case 1: // Yes: close the document
2894 if (!bufferlist.close(bufferlist.getBuffer(LyXfilename)))
2895 // If close is canceled, we cancel here too.
2898 case 2: // No: switch to the open document
2899 owner->view()->buffer(
2900 bufferlist.getBuffer(LyXfilename));
2902 case 3: // Cancel: Do nothing
2903 owner->getMiniBuffer()->Set(_("Canceled."));
2908 // Check if a LyX document by the same root exists in filesystem
2909 FileInfo f(LyXfilename, true);
2910 if (f.exist() && !AskQuestion(_("A document by the name"),
2911 MakeDisplayPath(LyXfilename),
2912 _("already exists. Overwrite?"))) {
2913 owner->getMiniBuffer()->Set(_("Canceled."));
2920 owner->getMiniBuffer()->Set(_("Importing LaTeX file"),
2921 MakeDisplayPath(filename), "...");
2922 ImportLaTeX myImport(filename);
2923 openbuf = myImport.run();
2925 owner->getMiniBuffer()->Set(_("Importing Noweb file"),
2926 MakeDisplayPath(filename), "...");
2927 ImportNoweb myImport(filename);
2928 openbuf = myImport.run();
2931 owner->view()->buffer(openbuf);
2932 owner->getMiniBuffer()->Set(isnoweb ?
2933 _("Noweb file ") : _("LateX file "),
2934 MakeDisplayPath(filename),
2937 owner->getMiniBuffer()->Set(isnoweb ?
2938 _("Could not import Noweb file") :
2939 _("Could not import LaTeX file"),
2940 MakeDisplayPath(filename));
2945 void LyXFunc::doImportLinuxDoc()
2947 string initpath = lyxrc.document_path;
2950 if (owner->view()->available()) {
2951 string trypath = owner->buffer()->filepath;
2952 // If directory is writeable, use this as default.
2953 if (IsDirWriteable(trypath) == 1)
2959 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
2960 fileDlg.SetButton(1, _("Examples"),
2961 AddPath(system_lyxdir, "examples"));
2963 string filename = fileDlg.Select(_("Select LinuxDoc file to Import"),
2964 initpath, "*.sgml");
2968 // check selected filename
2969 if (filename.empty()) {
2970 owner->getMiniBuffer()->Set(_("Canceled."));
2974 // get absolute path of file
2975 filename = MakeAbsPath(filename);
2977 // Check if the document already is open
2978 string LyXfilename = ChangeExtension(filename, ".lyx", false);
2979 if (bufferlist.exists(LyXfilename)){
2980 switch(AskConfirmation(_("Document is already open:"),
2981 MakeDisplayPath(LyXfilename, 50),
2982 _("Do you want to close that document now?\n"
2983 "('No' will just switch to the open version)")))
2985 case 1: // Yes: close the document
2986 if (!bufferlist.close(bufferlist.getBuffer(LyXfilename)))
2987 // If close is canceled, we cancel here too.
2990 case 2: // No: switch to the open document
2991 owner->view()->buffer(
2992 bufferlist.getBuffer(LyXfilename));
2994 case 3: // Cancel: Do nothing
2995 owner->getMiniBuffer()->Set(_("Canceled."));
3000 // Check if a LyX document by the same root exists in filesystem
3001 FileInfo f(LyXfilename, true);
3002 if (f.exist() && !AskQuestion(_("A document by the name"),
3003 MakeDisplayPath(LyXfilename),
3004 _("already exists. Overwrite?"))) {
3005 owner->getMiniBuffer()->Set(_("Canceled."));
3010 owner->getMiniBuffer()->Set(_("Importing LinuxDoc file"),
3011 MakeDisplayPath(filename), "...");
3014 string tmp = lyxrc.linuxdoc_to_lyx_command + filename;
3018 int result = one.startscript(Systemcalls::System, tmp);
3020 string filename = ChangeExtension(filename, ".lyx", false);
3021 // File was generated without problems. Load it.
3022 buf = bufferlist.loadLyXFile(filename);
3023 owner->view()->buffer(buf);
3024 owner->getMiniBuffer()->Set(_("LinuxDoc file "),
3025 MakeDisplayPath(filename),
3028 owner->getMiniBuffer()->Set(_("Could not import LinuxDoc file"),
3029 MakeDisplayPath(filename));
3034 void LyXFunc::MenuInsertLyXFile(string const & filen)
3036 string filename = filen;
3038 if (filename.empty()) {
3039 // Launch a file browser
3040 string initpath = lyxrc.document_path;
3043 if (owner->view()->available()) {
3044 string trypath = owner->buffer()->filepath;
3045 // If directory is writeable, use this as default.
3046 if (IsDirWriteable(trypath) == 1)
3052 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
3053 fileDlg.SetButton(1, _("Examples"),
3054 AddPath(system_lyxdir, "examples"));
3055 filename = fileDlg.Select(_("Select Document to Insert"),
3059 // check selected filename
3060 if (filename.empty()) {
3061 owner->getMiniBuffer()->Set(_("Canceled."));
3066 // get absolute path of file and make sure the filename ends
3068 filename = MakeAbsPath(filename);
3069 if (!IsLyXFilename(filename))
3073 owner->getMiniBuffer()->Set(_("Inserting document"),
3074 MakeDisplayPath(filename), "...");
3075 bool res = owner->view()->insertLyXFile(filename);
3077 owner->getMiniBuffer()->Set(_("Document"),
3078 MakeDisplayPath(filename),
3081 owner->getMiniBuffer()->Set(_("Could not insert document"),
3082 MakeDisplayPath(filename));
3087 void LyXFunc::reloadBuffer()
3089 string fn = owner->buffer()->fileName();
3090 if (bufferlist.close(owner->buffer()))
3091 owner->view()->buffer(bufferlist.loadLyXFile(fn));
3095 void LyXFunc::CloseBuffer()
3097 if (bufferlist.close(owner->buffer()) && !quitting) {
3098 if (bufferlist.empty()) {
3099 // need this otherwise SEGV may occur while trying to
3100 // set variables that don't exist
3101 // since there's no current buffer
3102 CloseAllBufferRelatedPopups();
3105 owner->view()->buffer(bufferlist.first());
3111 Inset * LyXFunc::getInsetByCode(Inset::Code code)
3115 LyXCursor cursor = owner->view()->text->cursor;
3116 LyXParagraph::size_type pos = cursor.pos;
3117 LyXParagraph * par = cursor.par;
3119 while (par && !found) {
3120 while ((inset = par->ReturnNextInsetPointer(pos))){
3121 if (inset->LyxCode() == code) {
3129 return found ? inset : 0;
3133 // Each "owner" should have it's own message method. lyxview and
3134 // the minibuffer would use the minibuffer, but lyxserver would
3135 // send an ERROR signal to its client. Alejandro 970603
3136 // This func is bit problematic when it comes to NLS, to make the
3137 // lyx servers client be language indepenent we must not translate
3138 // strings sent to this func.
3139 void LyXFunc::setErrorMessage(string const & m) const
3141 dispatch_buffer = m;
3146 void LyXFunc::setMessage(string const & m)
3148 dispatch_buffer = m;