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"
76 extern bool cursor_follows_scrollbar;
78 extern void InsertAsciiFile(BufferView *, string const &, bool);
79 extern void math_insert_symbol(char const *);
80 extern Bool math_insert_greek(char const); // why "Bool"?
81 extern BufferList bufferlist;
82 extern LyXServer * lyxserver;
83 extern short greek_kb_flag;
84 extern FD_form_toc * fd_form_toc;
85 extern bool selection_possible;
87 extern kb_keymap * toplevel_keymap;
89 extern void MenuWrite(Buffer *);
90 extern void MenuWriteAs(Buffer *);
91 extern int MenuRunLaTeX(Buffer *);
92 extern int MenuBuildProg(Buffer *);
93 extern int MenuRunChktex(Buffer *);
94 extern bool CreatePostscript(Buffer *, bool);
95 extern void MenuPrint(Buffer *);
96 extern void MenuSendto();
97 extern void QuitLyX();
98 extern void MenuFax(Buffer *);
99 extern void MenuExport(Buffer *, string const &);
100 extern void MenuPasteSelection(char at);
101 extern LyXAction lyxaction;
103 extern tex_accent_struct get_accent(kb_action action);
105 extern void AutoSave();
106 extern void SetUpdateTimer(float timer = 0.3);
107 extern void FreeUpdateTimer();
108 extern bool PreviewDVI(Buffer *);
109 extern bool PreviewPostscript(Buffer *);
110 extern void MenuInsertLabel(char const *);
111 extern void MenuInsertRef();
112 extern void MenuLayoutCharacter();
113 extern void MenuLayoutParagraph();
114 extern void MenuLayoutDocument();
115 extern void MenuLayoutPaper();
116 extern void MenuLayoutTable(int flag);
117 extern void MenuLayoutQuotes();
118 extern void MenuLayoutPreamble();
119 extern void MenuLayoutSave();
120 extern void bulletForm();
122 extern Buffer * NewLyxFile(string const &);
123 extern void LoadLyXFile(string const &);
124 extern void Reconfigure(BufferView *);
126 extern LyXTextClass::size_type current_layout;
127 extern int getISOCodeFromLaTeX(char *);
129 extern void ShowLatexLog();
131 /* === globals =========================================================== */
133 bool LyXFunc::show_sc = true;
136 LyXFunc::LyXFunc(LyXView * o)
140 lyx_dead_action = LFUN_NOACTION;
141 lyx_calling_dead_action = LFUN_NOACTION;
146 // I changed this func slightly. I commented out the ...FinishUndo(),
147 // this means that all places that used to have a moveCursorUpdate, now
148 // have a ...FinishUndo() as the preceeding statement. I have also added
149 // a moveCursorUpdate to some of the functions that updated the cursor, but
150 // that did not show its new position.
152 void LyXFunc::moveCursorUpdate(bool selecting)
154 if (selecting || owner->view()->text->mark_set) {
155 owner->view()->text->SetSelection();
156 owner->view()->toggleToggle();
157 owner->view()->update(0);
159 owner->view()->update(-2); // this IS necessary
163 owner->view()->showCursor();
165 /* ---> Everytime the cursor is moved, show the current font state. */
166 // should this too me moved out of this func?
167 //owner->getMiniBuffer()->Set(CurrentState());
168 owner->view()->setState();
172 int LyXFunc::processKeyEvent(XEvent * ev)
176 XKeyEvent * keyevent = &ev->xkey;
177 KeySym keysym_return;
179 int num_bytes = LyXLookupString(ev, s_r, 10, &keysym_return);
180 s_r[num_bytes] = '\0';
182 if (lyxerr.debugging(Debug::KEY)) {
183 char * tmp = XKeysymToString(keysym_return);
184 string stm = (tmp ? tmp : "");
185 lyxerr << "KeySym is "
188 << keysym_return << "]"
189 << " and num_bytes is "
191 << " the string returned is \""
192 << s_r << '\"' << endl;
194 // Do nothing if we have nothing (JMarc)
195 if (num_bytes == 0 && keysym_return == NoSymbol) {
196 lyxerr[Debug::KEY] << "Empty kbd action (probably composing)"
201 // this function should be used always [asierra060396]
202 if (owner->view()->available() &&
203 owner->view()->the_locking_inset &&
204 keysym_return == XK_Escape) {
205 owner->view()->unlockInset(owner->view()->the_locking_inset);
206 owner->view()->text->CursorRight();
207 moveCursorUpdate(false);
208 owner->getMiniBuffer()->Set(CurrentState());
212 // Can we be sure that this will work for all X-Windows
213 // implementations? (Lgb)
214 // This code snippet makes lyx ignore some keys. Perhaps
215 // all of them should be explictly mentioned?
216 if((keysym_return >= XK_Shift_L && keysym_return <= XK_Hyper_R)
217 || keysym_return == XK_Mode_switch || keysym_return == 0x0)
220 // Do a one-deep top-level lookup for
221 // cancel and meta-fake keys. RVDK_PATCH_5
222 cancel_meta_seq.reset();
224 int action = cancel_meta_seq.addkey(keysym_return, keyevent->state
225 &(ShiftMask|ControlMask
228 // When not cancel or meta-fake, do the normal lookup.
229 // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
230 // Mostly, meta_fake_bit = 0. RVDK_PATCH_5.
231 if ( (action != LFUN_CANCEL) && (action != LFUN_META_FAKE) ) {
233 // remove Caps Lock and Mod2 as a modifiers
234 action = keyseq.addkey(keysym_return,
235 (keyevent->state | meta_fake_bit)
236 &(ShiftMask|ControlMask
239 // Dont remove this unless you know what you are doing.
242 if (action == 0) action = LFUN_PREFIX;
244 if (lyxerr.debugging(Debug::KEY)) {
250 << num_bytes << "]" << endl;
253 // already here we know if it any point in going further
254 // why not return already here if action == -1 and
255 // num_bytes == 0? (Lgb)
257 if(keyseq.length > 1 || keyseq.length < -1) {
260 owner->getMiniBuffer()->Set(buf);
264 if (keyseq.length < -1) { // unknown key sequence...
268 owner->getMiniBuffer()->Set(_("Unknown sequence:"), buf);
272 char isochar = keyseq.getiso();
273 if (!(keyevent->state&ControlMask) &&
274 !(keyevent->state&Mod1Mask) &&
275 (isochar && keysym_return < 0xF000)) {
278 if (argument.empty()) {
279 lyxerr.debug() << "Empty argument!" << endl;
280 // This can`t possibly be of any use
281 // so we`ll skip the dispatch.
285 if (action == LFUN_SELFINSERT) {
289 bool tmp_sc = show_sc;
291 Dispatch(action, argument.c_str());
298 LyXFunc::func_status LyXFunc::getStatus(int ac) const
301 func_status flag = LyXFunc::OK;
303 Buffer * buf = owner->buffer();
305 if (lyxaction.isPseudoAction(ac))
306 action = lyxaction.retrieveActionArg(ac, argument);
308 action = static_cast<kb_action>(ac);
310 if (action == LFUN_UNKNOWN_ACTION) {
311 setErrorMessage(N_("Unknown action"));
312 return LyXFunc::Unknown;
315 // Check whether we need a buffer
316 if (!lyxaction.funcHasFlag(action, LyXAction::NoBuffer)) {
317 // Yes we need a buffer, do we have one?
320 // Can we use a readonly buffer?
321 if (buf->isReadonly() &&
322 !lyxaction.funcHasFlag(action,
323 LyXAction::ReadOnly)) {
325 setErrorMessage(N_("Document is read-only"));
326 flag |= LyXFunc::Disabled;
330 setErrorMessage(N_("Command not allowed with"
331 "out any document open"));
332 flag |= LyXFunc::Disabled;
336 if (flag & LyXFunc::Disabled)
339 // I would really like to avoid having this switch and rather try to
340 // encode this in the function itself.
341 static bool noLaTeX = lyxrc.latex_command == "none";
342 bool disable = false;
345 disable = noLaTeX || lyxrc.view_dvi_command == "none";
348 disable = noLaTeX || lyxrc.view_ps_command == "none";
355 disable = noLaTeX || lyxrc.print_command == "none";
358 disable = noLaTeX || lyxrc.fax_command == "none";
361 if (argument == "latex")
362 disable = lyxrc.relyx_command == "none";
363 if (argument == "linuxdoc")
364 disable = lyxrc.linuxdoc_to_lyx_command == "none";
367 if (argument == "dvi" || argument == "postscript")
369 if (argument == "html")
370 disable = lyxrc.html_command == "none";
371 if (argument == "html-linuxdoc")
372 disable = lyxrc.linuxdoc_to_html_command == "none";
373 if (argument == "html-docbook")
374 disable = lyxrc.docbook_to_html_command == "none";
377 disable = buf->undostack.empty();
380 disable = buf->redostack.empty();
382 case LFUN_SPELLCHECK:
383 disable = lyxrc.isp_command == "none";
386 disable = lyxrc.chktex_command == "none";
388 case LFUN_LAYOUT_TABLE:
389 disable = ! owner->view()->text->cursor.par->table;
395 flag |= LyXFunc::Disabled;
398 func_status box = LyXFunc::ToggleOff;
399 LyXFont font = owner->view()->text->real_current_font;
402 if (font.emph() == LyXFont::ON)
403 box = LyXFunc::ToggleOn;
406 if (font.noun() == LyXFont::ON)
407 box = LyXFunc::ToggleOn;
410 if (font.series() == LyXFont::BOLD_SERIES)
411 box = LyXFunc::ToggleOn;
414 if (font.latex() == LyXFont::ON)
415 box = LyXFunc::ToggleOn;
428 string LyXFunc::Dispatch(string const & s)
430 // Split command string into command and argument
431 string cmd, line = frontStrip(s);
432 string arg = strip(frontStrip(split(line, cmd, ' ')));
434 return Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
438 string LyXFunc::Dispatch(int ac,
439 char const * do_not_use_this_arg)
444 // we have not done anything wrong yet.
446 dispatch_buffer.clear();
448 // if action is a pseudo-action, we need the real action
449 if (lyxaction.isPseudoAction(ac)) {
451 action = static_cast<kb_action>
452 (lyxaction.retrieveActionArg(ac, tmparg));
456 action = static_cast<kb_action>(ac);
457 if (do_not_use_this_arg)
458 argument = do_not_use_this_arg; // except here
461 selection_possible = false;
463 if (owner->view()->available())
464 owner->view()->hideCursor();
466 // We cannot use this function here
467 if (getStatus(action) & Disabled)
468 goto exit_with_message;
470 commandshortcut.clear();
472 if (lyxrc.display_shortcuts && show_sc) {
473 if (action != LFUN_SELFINSERT) {
474 // Put name of command and list of shortcuts
475 // for it in minibuffer
476 string comname = lyxaction.getActionName(action);
478 int pseudoaction = action;
479 bool argsadded = false;
481 if (!argument.empty()) {
482 // If we have the command with argument,
485 lyxaction.searchActionArg(action,
488 if (pseudoaction == -1) {
489 pseudoaction = action;
491 comname += " " + argument;
496 string shortcuts = toplevel_keymap->findbinding(pseudoaction);
498 if (!shortcuts.empty()) {
499 comname += ": " + shortcuts;
500 } else if (!argsadded) {
501 comname += " " + argument;
504 if (!comname.empty()) {
505 comname = strip(comname);
506 commandshortcut = "(" + comname + ')';
507 owner->getMiniBuffer()->Set(commandshortcut);
508 // Here we could even add a small pause,
509 // to annoy the user and make him learn
511 // No! That will just annoy, not teach
512 // anything. The user will read the messages
513 // if they are interested. (Asger)
518 // If in math mode pass the control to
519 // the math inset [asierra060396]
520 if (owner->view()->available() &&
521 owner->view()->the_locking_inset) {
523 || (action == LFUN_UNKNOWN_ACTION
524 && keyseq.length >= -1)) {
525 if (action == LFUN_UNKNOWN_ACTION
526 && argument.empty()) {
527 argument = keyseq.getiso();
529 // Undo/Redo pre 0.13 is a bit tricky for insets.
530 if (action == LFUN_UNDO) {
532 UpdatableInset * inset =
533 owner->view()->the_locking_inset;
534 inset->GetCursorPos(slx, sly);
535 owner->view()->unlockInset(inset);
536 owner->view()->menuUndo();
537 if (owner->view()->text->cursor.par->
538 IsInset(owner->view()->text->cursor.pos)) {
539 inset = static_cast<UpdatableInset*>(
540 owner->view()->text->cursor.par->
541 GetInset(owner->view()->text->
547 inset->Edit(owner->view(),slx,sly,0);
549 } else if (action == LFUN_REDO) {
551 UpdatableInset * inset = owner->view()->
553 inset->GetCursorPos(slx, sly);
554 owner->view()->unlockInset(inset);
555 owner->view()->menuRedo();
556 inset = static_cast<UpdatableInset*>(
557 owner->view()->text->cursor.par->
558 GetInset(owner->view()->text->
561 inset->Edit(owner->view(),slx,sly,0);
563 } else if (owner->view()->the_locking_inset->
564 LocalDispatch(owner->view(), action,
566 UpdatableInset::DISPATCHED)
569 setMessage(N_("Text mode"));
570 LyXDirection direction = owner->view()->text->
571 cursor.par->getParDirection();
573 case LFUN_UNKNOWN_ACTION:
574 case LFUN_BREAKPARAGRAPH:
576 owner->view()->text->CursorRight();
577 owner->view()->setState();
578 owner->getMiniBuffer()->Set(CurrentState());
581 if (direction == LYX_DIR_LEFT_TO_RIGHT) {
582 owner->view()->text->CursorRight();
583 moveCursorUpdate(false);
584 owner->getMiniBuffer()->
589 if (direction == LYX_DIR_RIGHT_TO_LEFT) {
590 owner->view()->text->CursorRight();
591 moveCursorUpdate(false);
592 owner->getMiniBuffer()->
604 // --- Misc -------------------------------------------
605 case LFUN_WORDFINDFORWARD :
606 case LFUN_WORDFINDBACKWARD : {
607 static string last_search;
608 string searched_string;
610 if (!argument.empty()) {
611 last_search = argument;
612 searched_string = argument;
614 searched_string = last_search;
617 LyXText * ltCur = owner->view()->text ;
619 if (!searched_string.empty() &&
620 ((action == LFUN_WORDFINDBACKWARD) ?
621 ltCur->SearchBackward(searched_string.c_str()) :
622 ltCur->SearchForward(searched_string.c_str()))) {
624 // ??? What is that ???
625 owner->view()->update(-2);
628 // clear the selection (if there is any)
629 owner->view()->toggleSelection();
630 owner->view()->text->ClearSelection();
632 // Move cursor so that successive C-s 's will not stand in place.
633 if( action == LFUN_WORDFINDFORWARD )
634 owner->view()->text->CursorRightOneWord();
635 owner->view()->text->FinishUndo();
636 moveCursorUpdate(false);
639 // set the new selection
640 // SetSelectionOverLenChars(owner->view()->currentBuffer()->text, iLenSelected);
641 owner->view()->toggleSelection(false);
645 // REMOVED : if (owner->view()->getWorkArea()->focus)
646 owner->view()->showCursor();
652 if (owner->view()->available()) {
653 owner->view()->update(-2);
656 keyseq.print(buf, true);
657 owner->getMiniBuffer()->Set(buf, string(), string(), 1);
661 // --- Misc -------------------------------------------
662 case LFUN_EXEC_COMMAND:
663 owner->getMiniBuffer()->ExecCommand();
666 case LFUN_CANCEL: // RVDK_PATCH_5
669 if(owner->view()->available())
670 // cancel any selection
671 Dispatch(LFUN_MARK_OFF, 0);
672 setMessage(N_("Cancel"));
675 case LFUN_META_FAKE: // RVDK_PATCH_5
677 meta_fake_bit = Mod1Mask;
679 keyseq.print(buf, true);
680 string res = string("M-") + buf;
681 setMessage(buf); // RVDK_PATCH_5
685 case LFUN_READ_ONLY_TOGGLE:
686 if (owner->buffer()->lyxvc.inUse()) {
687 owner->buffer()->lyxvc.toggleReadOnly();
689 owner->buffer()->setReadonly(
690 !owner->buffer()->isReadonly());
694 case LFUN_CENTER: // this is center and redraw.
695 owner->view()->center();
699 if (owner->view()->available()) {
700 owner->view()->text->toggleAppendix();
701 owner->view()->update(1);
705 // --- Menus -----------------------------------------------
710 case LFUN_MENUNEWTMPLT:
718 case LFUN_CLOSEBUFFER:
723 owner->getMiniBuffer()->Set(_("Saving document"),
724 MakeDisplayPath(owner->buffer()->fileName()),
726 MenuWrite(owner->buffer());
727 //owner->getMiniBuffer()->
728 // Set(_("Document saved as"),
729 // MakeDisplayPath(owner->buffer()->fileName()));
731 //owner->getMiniBuffer()->Set(_("Save failed!"));
735 case LFUN_MENUWRITEAS:
736 MenuWriteAs(owner->buffer());
739 case LFUN_MENURELOAD:
744 PreviewDVI(owner->buffer());
748 PreviewPostscript(owner->buffer());
752 MenuRunLaTeX(owner->buffer());
756 MenuBuildProg(owner->buffer());
760 MenuRunChktex(owner->buffer());
764 CreatePostscript(owner->buffer(), false);
768 MenuPrint(owner->buffer());
772 MenuFax(owner->buffer());
776 MenuExport(owner->buffer(), argument);
781 //needs argument as string
782 string imtyp = argument;
785 if (imtyp == "latex") {
786 doImportLaTeX(false);
789 else if (imtyp == "ascii") {
790 doImportASCII(false);
791 } else if (imtyp == "asciiparagraph") {
794 } else if (imtyp == "noweb") {
796 } else if (imtyp == "linuxdoc") {
799 setErrorMessage(string(N_("Unknown import type: "))
811 if (fd_form_toc->form_toc->visible) {
812 fl_raise_form(fd_form_toc->form_toc);
814 static int ow = -1, oh;
815 fl_show_form(fd_form_toc->form_toc,
817 FL_FREE_SIZE, FL_FULLBORDER,
818 _("Table of Contents"));
820 ow = fd_form_toc->form_toc->w;
821 oh = fd_form_toc->form_toc->h;
823 fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
827 case LFUN_TOC_INSERT:
829 Inset * new_inset = new InsetTOC(owner->buffer());
830 owner->view()->insertInset(new_inset, "Standard", true);
834 case LFUN_LOF_INSERT:
836 Inset * new_inset = new InsetLOF(owner->buffer());
837 owner->view()->insertInset(new_inset, "Standard", true);
841 case LFUN_LOA_INSERT:
843 Inset * new_inset = new InsetLOA(owner->buffer());
844 owner->view()->insertInset(new_inset, "Standard", true);
848 case LFUN_LOT_INSERT:
850 Inset * new_inset = new InsetLOT(owner->buffer());
851 owner->view()->insertInset(new_inset, "Standard", true);
863 case LFUN_INSERT_GRAPHICS:
865 Inset * new_inset = new InsetGraphics;
866 owner->view()->insertInset(new_inset);
875 owner->view()->menuUndo();
879 owner->view()->menuRedo();
882 case LFUN_MENUSEARCH:
884 // Ok this is one _very_ bad solution, but I think that some
885 // of this will be rewritten as part of GUI indep anyway.
887 static LyXFindReplace FR_;
888 FR_.StartSearch(owner->view());
894 owner->view()->paste();
895 owner->view()->setState();
898 case LFUN_PASTESELECTION:
901 if (argument == "paragraph") asPara = true;
902 MenuPasteSelection(asPara);
907 owner->view()->cut();
911 owner->view()->copy();
914 case LFUN_LAYOUT_COPY:
915 owner->view()->copyEnvironment();
918 case LFUN_LAYOUT_PASTE:
919 owner->view()->pasteEnvironment();
920 owner->view()->setState();
924 owner->view()->gotoError();
927 case LFUN_REMOVEERRORS:
928 if (owner->view()->removeAutoInsets()) {
929 owner->view()->redraw();
930 owner->view()->fitCursor();
931 owner->view()->updateScrollbar();
936 owner->view()->gotoNote();
940 owner->view()->openStuff();
943 case LFUN_HYPHENATION:
944 owner->view()->hyphenationPoint();
948 owner->view()->ldots();
951 case LFUN_END_OF_SENTENCE:
952 owner->view()->endOfSentenceDot();
955 case LFUN_MENU_SEPARATOR:
956 owner->view()->menuSeparator();
960 owner->view()->hfill();
964 changeDepth(owner->view(), 0);
968 changeDepth(owner->view(), -1);
971 case LFUN_DEPTH_PLUS:
972 changeDepth(owner->view(), 1);
981 owner->view()->setState();
982 owner->getMiniBuffer()->Set(CurrentState());
989 case LFUN_RECONFIGURE:
990 Reconfigure(owner->view());
994 if (owner->view()->available()
995 && !owner->view()->text->selection
996 && owner->view()->text->cursor.par->footnoteflag
997 != LyXParagraph::NO_FOOTNOTE)
998 { // only melt footnotes with FOOTMELT, not margins etc
999 if(owner->view()->text->cursor.par->footnotekind == LyXParagraph::FOOTNOTE)
1000 Melt(owner->view());
1003 Foot(owner->view());
1004 owner->view()->setState();
1007 case LFUN_MARGINMELT:
1008 if (owner->view()->available()
1009 && !owner->view()->text->selection
1010 && owner->view()->text->cursor.par->footnoteflag
1011 != LyXParagraph::NO_FOOTNOTE) {
1012 // only melt margins
1013 if(owner->view()->text->cursor.par->footnotekind == LyXParagraph::MARGIN)
1014 Melt(owner->view());
1016 Margin(owner->view());
1017 owner->view()->setState();
1020 // --- version control -------------------------------
1021 case LFUN_VC_REGISTER:
1023 if (!owner->buffer()->lyxvc.inUse())
1024 owner->buffer()->lyxvc.registrer();
1028 case LFUN_VC_CHECKIN:
1030 if (owner->buffer()->lyxvc.inUse()
1031 && !owner->buffer()->isReadonly())
1032 owner->buffer()->lyxvc.checkIn();
1036 case LFUN_VC_CHECKOUT:
1038 if (owner->buffer()->lyxvc.inUse()
1039 && owner->buffer()->isReadonly())
1040 owner->buffer()->lyxvc.checkOut();
1044 case LFUN_VC_REVERT:
1046 owner->buffer()->lyxvc.revert();
1052 owner->buffer()->lyxvc.undoLast();
1056 case LFUN_VC_HISTORY:
1058 owner->buffer()->lyxvc.showLog();
1062 // --- buffers ----------------------------------------
1064 case LFUN_FILE_INSERT:
1066 MenuInsertLyXFile(argument);
1070 case LFUN_FILE_INSERT_ASCII:
1072 bool asPara = (argument == "paragraph");
1073 InsertAsciiFile(owner->view(), string(), asPara);
1079 // servercmd: argument must be <file>:<template>
1080 Buffer * tmpbuf = NewLyxFile(argument);
1082 owner->view()->buffer(tmpbuf);
1086 case LFUN_FILE_OPEN:
1087 owner->view()->buffer(bufferlist.loadLyXFile(argument));
1090 case LFUN_LATEX_LOG:
1096 lyxerr.debug() << "LFUN_LAYOUTNO: (arg) " << argument << endl;
1097 int sel = strToInt(argument);
1098 lyxerr.debug() << "LFUN_LAYOUTNO: (sel) "<< sel << endl;
1100 // Should this give a setMessage instead?
1102 return string(); // illegal argument
1104 --sel; // sel 1..., but layout 0...
1106 // Pretend we got the name instead.
1107 Dispatch(int(LFUN_LAYOUT),
1108 textclasslist.NameOfLayout(owner->view()->
1117 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1118 << argument << endl;
1120 // Derive layout number from given argument (string)
1121 // and current buffer's textclass (number). */
1122 LyXTextClassList::ClassList::size_type tclass =
1123 owner->view()->text->parameters->textclass;
1124 pair <bool, LyXTextClass::size_type> layout =
1125 textclasslist.NumberOfLayout(tclass, argument);
1127 // If the entry is obsolete, use the new one instead.
1129 string obs = textclasslist.Style(tclass,layout.second)
1133 textclasslist.NumberOfLayout(tclass, obs);
1136 // see if we found the layout number:
1137 if (!layout.first) {
1138 setErrorMessage(string(N_("Layout ")) + argument +
1143 if (current_layout != layout.second) {
1144 owner->view()->hideCursor();
1145 current_layout = layout.second;
1146 owner->view()->update(-2);
1147 owner->view()->text->
1148 SetLayout(layout.second);
1149 owner->getToolbar()->combox->
1150 select(owner->view()->
1153 owner->view()->update(1);
1154 owner->view()->setState();
1159 case LFUN_LAYOUT_DOCUMENT:
1160 MenuLayoutDocument();
1163 case LFUN_LAYOUT_PARAGRAPH:
1164 MenuLayoutParagraph();
1167 case LFUN_LAYOUT_CHARACTER:
1168 MenuLayoutCharacter();
1171 case LFUN_LAYOUT_TABLE:
1174 if (argument == "true") flag = 1;
1175 MenuLayoutTable(flag);
1179 case LFUN_LAYOUT_PAPER:
1183 case LFUN_LAYOUT_QUOTES:
1187 case LFUN_LAYOUT_PREAMBLE:
1188 MenuLayoutPreamble();
1191 case LFUN_LAYOUT_SAVE_DEFAULT:
1195 case LFUN_DROP_LAYOUTS_CHOICE:
1196 owner->getToolbar()->combox->Show();
1202 owner->view()->setState();
1203 owner->getMiniBuffer()->Set(CurrentState());
1235 case LFUN_UNDERLINE:
1239 case LFUN_FONT_SIZE:
1243 case LFUN_FONT_STATE:
1244 setMessage(CurrentState());
1247 case LFUN_UPCASE_WORD:
1248 owner->view()->update(-2);
1250 owner->view()->text->ChangeWordCase(LyXText::text_uppercase);
1251 owner->view()->update(1);
1255 case LFUN_LOWCASE_WORD:
1256 owner->view()->update(-2);
1258 owner->view()->text->ChangeWordCase(LyXText::text_lowercase);
1259 owner->view()->update(1);
1263 case LFUN_CAPITALIZE_WORD:
1264 owner->view()->update(-2);
1266 owner->view()->text->ChangeWordCase(LyXText::text_capitalization);
1267 owner->view()->update(1);
1271 case LFUN_INSERT_LABEL:
1272 MenuInsertLabel(argument.c_str());
1275 case LFUN_INSERT_REF:
1279 case LFUN_REFTOGGLE:
1282 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1284 if (inset->getFlag() == InsetRef::REF)
1285 inset->setFlag(InsetRef::PAGE_REF);
1287 inset->setFlag(InsetRef::REF);
1288 owner->view()->updateInset(inset, true);
1290 setErrorMessage(N_("No cross-reference to toggle"));
1297 owner->view()->restorePosition();
1303 string label(argument);
1304 if (label.empty()) {
1306 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1308 label = inset->getContents();
1311 if (!label.empty()) {
1312 owner->view()->savePosition();
1313 owner->view()->gotoLabel(label.c_str());
1318 case LFUN_MENU_OPEN_BY_NAME:
1319 owner->getMenus()->openByName(argument);
1320 break; // RVDK_PATCH_5
1322 case LFUN_SPELLCHECK:
1323 if (lyxrc.isp_command != "none")
1324 ShowSpellChecker(owner->view());
1325 break; // RVDK_PATCH_5
1327 // --- Cursor Movements -----------------------------
1330 LyXText * tmptext = owner->view()->text;
1331 LyXDirection direction =
1332 tmptext->cursor.par->getParDirection();
1333 if(!tmptext->mark_set)
1334 owner->view()->beforeChange();
1335 owner->view()->update(-2);
1336 if (direction == LYX_DIR_RIGHT_TO_LEFT)
1337 tmptext->CursorLeft();
1338 if (tmptext->cursor.pos < tmptext->cursor.par->Last()
1339 && tmptext->cursor.par->GetChar(tmptext->cursor.pos)
1340 == LyXParagraph::META_INSET
1341 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)
1342 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)->Editable() == Inset::HIGHLY_EDITABLE){
1343 Inset * tmpinset = tmptext->cursor.par->GetInset(tmptext->cursor.pos);
1344 setMessage(tmpinset->EditMessage());
1345 tmpinset->Edit(owner->view(), 0, 0, 0);
1348 if (direction == LYX_DIR_LEFT_TO_RIGHT)
1349 tmptext->CursorRight();
1350 owner->view()->text->FinishUndo();
1351 moveCursorUpdate(false);
1352 owner->getMiniBuffer()->Set(CurrentState());
1358 // This is soooo ugly. Isn`t it possible to make
1359 // it simpler? (Lgb)
1360 LyXText * txt = owner->view()->text;
1361 LyXDirection direction = txt->cursor.par->getParDirection();
1362 if(!txt->mark_set) owner->view()->beforeChange();
1363 owner->view()->update(-2);
1364 if (direction == LYX_DIR_LEFT_TO_RIGHT)
1366 if (txt->cursor.pos < txt->cursor.par->Last()
1367 && txt->cursor.par->GetChar(txt->cursor.pos)
1368 == LyXParagraph::META_INSET
1369 && txt->cursor.par->GetInset(txt->cursor.pos)
1370 && txt->cursor.par->GetInset(txt->cursor.pos)->Editable() == Inset::HIGHLY_EDITABLE) {
1371 Inset * tmpinset = txt->cursor.par->GetInset(txt->cursor.pos);
1372 setMessage(tmpinset->EditMessage());
1373 tmpinset->Edit(owner->view(),
1374 tmpinset->width(owner->view()->painter(),
1375 txt->GetFont(txt->cursor.par,
1380 if (direction == LYX_DIR_RIGHT_TO_LEFT)
1383 owner->view()->text->FinishUndo();
1384 moveCursorUpdate(false);
1385 owner->getMiniBuffer()->Set(CurrentState());
1390 if(!owner->view()->text->mark_set) owner->view()->beforeChange();
1391 owner->view()->update(-3);
1392 owner->view()->text->CursorUp();
1393 owner->view()->text->FinishUndo();
1394 moveCursorUpdate(false);
1395 owner->getMiniBuffer()->Set(CurrentState());
1399 if(!owner->view()->text->mark_set)
1400 owner->view()->beforeChange();
1401 owner->view()->update(-3);
1402 owner->view()->text->CursorDown();
1403 owner->view()->text->FinishUndo();
1404 moveCursorUpdate(false);
1405 owner->getMiniBuffer()->Set(CurrentState());
1408 case LFUN_UP_PARAGRAPH:
1409 if(!owner->view()->text->mark_set)
1410 owner->view()->beforeChange();
1411 owner->view()->update(-3);
1412 owner->view()->text->CursorUpParagraph();
1413 owner->view()->text->FinishUndo();
1414 moveCursorUpdate(false);
1415 owner->getMiniBuffer()->Set(CurrentState());
1418 case LFUN_DOWN_PARAGRAPH:
1419 if(!owner->view()->text->mark_set)
1420 owner->view()->beforeChange();
1421 owner->view()->update(-3);
1422 owner->view()->text->CursorDownParagraph();
1423 owner->view()->text->FinishUndo();
1424 moveCursorUpdate(false);
1425 owner->getMiniBuffer()->Set(CurrentState());
1429 if(!owner->view()->text->mark_set)
1430 owner->view()->beforeChange();
1431 owner->view()->update(-3);
1432 owner->view()->cursorPrevious();
1433 owner->view()->text->FinishUndo();
1434 moveCursorUpdate(false);
1435 owner->getMiniBuffer()->Set(CurrentState());
1439 if(!owner->view()->text->mark_set)
1440 owner->view()->beforeChange();
1441 owner->view()->update(-3);
1442 owner->view()->cursorNext();
1443 owner->view()->text->FinishUndo();
1444 moveCursorUpdate(false);
1445 owner->getMiniBuffer()->Set(CurrentState());
1449 if(!owner->view()->text->mark_set)
1450 owner->view()->beforeChange();
1451 owner->view()->update(-2);
1452 owner->view()->text->CursorHome();
1453 owner->view()->text->FinishUndo();
1454 moveCursorUpdate(false);
1455 owner->getMiniBuffer()->Set(CurrentState());
1459 if(!owner->view()->text->mark_set)
1460 owner->view()->beforeChange();
1461 owner->view()->update(-2);
1462 owner->view()->text->CursorEnd();
1463 owner->view()->text->FinishUndo();
1464 moveCursorUpdate(false);
1465 owner->getMiniBuffer()->Set(CurrentState());
1469 if(!owner->view()->text->mark_set)
1470 owner->view()->beforeChange();
1471 owner->view()->update(-2);
1472 owner->view()->text->CursorTab();
1473 owner->view()->text->FinishUndo();
1474 moveCursorUpdate(false);
1475 owner->getMiniBuffer()->Set(CurrentState());
1478 case LFUN_WORDRIGHT:
1479 if(!owner->view()->text->mark_set)
1480 owner->view()->beforeChange();
1481 owner->view()->update(-2);
1482 if (owner->view()->text->cursor.par->getParDirection()
1483 == LYX_DIR_LEFT_TO_RIGHT)
1484 owner->view()->text->CursorRightOneWord();
1486 owner->view()->text->CursorLeftOneWord();
1487 owner->view()->text->FinishUndo();
1488 moveCursorUpdate(false);
1489 owner->getMiniBuffer()->Set(CurrentState());
1493 if(!owner->view()->text->mark_set)
1494 owner->view()->beforeChange();
1495 owner->view()->update(-2);
1496 if (owner->view()->text->cursor.par->getParDirection()
1497 == LYX_DIR_LEFT_TO_RIGHT)
1498 owner->view()->text->CursorLeftOneWord();
1500 owner->view()->text->CursorRightOneWord();
1501 owner->view()->text->FinishUndo();
1502 moveCursorUpdate(false);
1503 owner->getMiniBuffer()->Set(CurrentState());
1506 case LFUN_BEGINNINGBUF:
1507 if(!owner->view()->text->mark_set)
1508 owner->view()->beforeChange();
1509 owner->view()->update(-2);
1510 owner->view()->text->CursorTop();
1511 owner->view()->text->FinishUndo();
1512 moveCursorUpdate(false);
1513 owner->getMiniBuffer()->Set(CurrentState());
1517 if(!owner->view()->text->mark_set)
1518 owner->view()->beforeChange();
1519 owner->view()->update(-2);
1520 owner->view()->text->CursorBottom();
1521 owner->view()->text->FinishUndo();
1522 moveCursorUpdate(false);
1523 owner->getMiniBuffer()->Set(CurrentState());
1527 /* cursor selection ---------------------------- */
1529 owner->view()->update(-2);
1530 if (owner->view()->text->cursor.par->getParDirection()
1531 == LYX_DIR_LEFT_TO_RIGHT)
1532 owner->view()->text->CursorRight();
1534 owner->view()->text->CursorLeft();
1535 owner->view()->text->FinishUndo();
1536 moveCursorUpdate(true);
1537 owner->getMiniBuffer()->Set(CurrentState());
1541 owner->view()->update(-2);
1542 if (owner->view()->text->cursor.par->getParDirection()
1543 == LYX_DIR_LEFT_TO_RIGHT)
1544 owner->view()->text->CursorLeft();
1546 owner->view()->text->CursorRight();
1547 owner->view()->text->FinishUndo();
1548 moveCursorUpdate(true);
1549 owner->getMiniBuffer()->Set(CurrentState());
1553 owner->view()->update(-2);
1554 owner->view()->text->CursorUp();
1555 owner->view()->text->FinishUndo();
1556 moveCursorUpdate(true);
1557 owner->getMiniBuffer()->Set(CurrentState());
1561 owner->view()->update(-2);
1562 owner->view()->text->CursorDown();
1563 owner->view()->text->FinishUndo();
1564 moveCursorUpdate(true);
1565 owner->getMiniBuffer()->Set(CurrentState());
1568 case LFUN_UP_PARAGRAPHSEL:
1569 owner->view()->update(-2);
1570 owner->view()->text->CursorUpParagraph();
1571 owner->view()->text->FinishUndo();
1572 moveCursorUpdate(true);
1573 owner->getMiniBuffer()->Set(CurrentState());
1576 case LFUN_DOWN_PARAGRAPHSEL:
1577 owner->view()->update(-2);
1578 owner->view()->text->CursorDownParagraph();
1579 owner->view()->text->FinishUndo();
1580 moveCursorUpdate(true);
1581 owner->getMiniBuffer()->Set(CurrentState());
1585 owner->view()->update(-2);
1586 owner->view()->cursorPrevious();
1587 owner->view()->text->FinishUndo();
1588 moveCursorUpdate(true);
1589 owner->getMiniBuffer()->Set(CurrentState());
1593 owner->view()->update(-2);
1594 owner->view()->cursorNext();
1595 owner->view()->text->FinishUndo();
1596 moveCursorUpdate(true);
1597 owner->getMiniBuffer()->Set(CurrentState());
1601 owner->view()->update(-2);
1602 owner->view()->text->CursorHome();
1603 owner->view()->text->FinishUndo();
1604 moveCursorUpdate(true);
1605 owner->getMiniBuffer()->Set(CurrentState());
1609 owner->view()->update(-2);
1610 owner->view()->text->CursorEnd();
1611 owner->view()->text->FinishUndo();
1612 moveCursorUpdate(true);
1613 owner->getMiniBuffer()->Set(CurrentState());
1616 case LFUN_WORDRIGHTSEL:
1617 owner->view()->update(-2);
1618 if (owner->view()->text->cursor.par->getParDirection()
1619 == LYX_DIR_LEFT_TO_RIGHT)
1620 owner->view()->text->CursorRightOneWord();
1622 owner->view()->text->CursorLeftOneWord();
1623 owner->view()->text->FinishUndo();
1624 moveCursorUpdate(true);
1625 owner->getMiniBuffer()->Set(CurrentState());
1628 case LFUN_WORDLEFTSEL:
1629 owner->view()->update(-2);
1630 if (owner->view()->text->cursor.par->getParDirection()
1631 == LYX_DIR_LEFT_TO_RIGHT)
1632 owner->view()->text->CursorLeftOneWord();
1634 owner->view()->text->CursorRightOneWord();
1635 owner->view()->text->FinishUndo();
1636 moveCursorUpdate(true);
1637 owner->getMiniBuffer()->Set(CurrentState());
1640 case LFUN_BEGINNINGBUFSEL:
1641 owner->view()->update(-2);
1642 owner->view()->text->CursorTop();
1643 owner->view()->text->FinishUndo();
1644 moveCursorUpdate(true);
1645 owner->getMiniBuffer()->Set(CurrentState());
1648 case LFUN_ENDBUFSEL:
1649 owner->view()->update(-2);
1650 owner->view()->text->CursorBottom();
1651 owner->view()->text->FinishUndo();
1652 moveCursorUpdate(true);
1653 owner->getMiniBuffer()->Set(CurrentState());
1656 // --- text changing commands ------------------------
1657 case LFUN_BREAKLINE:
1659 owner->view()->beforeChange();
1660 owner->view()->text->InsertChar(LyXParagraph::META_NEWLINE);
1661 owner->view()->smallUpdate(1);
1662 SetUpdateTimer(0.01);
1663 moveCursorUpdate(false);
1665 owner->view()->newline();
1669 case LFUN_PROTECTEDSPACE:
1672 LyXLayout const & style =
1673 textclasslist.Style(owner->view()->buffer()->params.textclass,
1674 owner->view()->text->cursor.par->GetLayout());
1676 if (style.free_spacing) {
1677 owner->view()->text->InsertChar(' ');
1678 owner->view()->update(-1);
1680 owner->view()->protectedBlank();
1682 moveCursorUpdate(false);
1685 owner->view()->beforeChange();
1686 owner->view()->text->
1687 InsertChar(LyXParagraph::META_PROTECTED_SEPARATOR);
1688 owner->view()->smallUpdate(1);
1690 moveCursorUpdate(false);
1695 if(owner->view()->text->mark_set) {
1696 owner->view()->beforeChange();
1697 owner->view()->update(0);
1698 setMessage(N_("Mark removed"));
1700 owner->view()->beforeChange();
1701 owner->view()->text->mark_set = 1;
1702 owner->view()->update(0);
1703 setMessage(N_("Mark set"));
1705 owner->view()->text->sel_cursor =
1706 owner->view()->text->cursor;
1711 if (!owner->view()->text->selection) {
1712 owner->view()->text->Delete();
1713 owner->view()->text->sel_cursor =
1714 owner->view()->text->cursor;
1715 owner->view()->smallUpdate(1);
1716 // It is possible to make it a lot faster still
1717 // just comment out the lone below...
1718 owner->view()->showCursor();
1720 owner->view()->cut();
1723 moveCursorUpdate(false);
1724 owner->getMiniBuffer()->Set(CurrentState());
1725 owner->view()->setState();
1728 case LFUN_DELETE_SKIP:
1730 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1732 LyXCursor cursor = owner->view()->text->cursor;
1735 if (!owner->view()->text->selection) {
1736 if (cursor.pos == cursor.par->Last()) {
1737 owner->view()->text->CursorRight();
1738 cursor = owner->view()->text->cursor;
1740 && !(cursor.par->added_space_top
1741 == VSpace (VSpace::NONE))) {
1742 owner->view()->text->SetParagraph
1743 (cursor.par->line_top,
1744 cursor.par->line_bottom,
1745 cursor.par->pagebreak_top,
1746 cursor.par->pagebreak_bottom,
1747 VSpace(VSpace::NONE),
1748 cursor.par->added_space_bottom,
1750 cursor.par->labelwidthstring, 0);
1751 owner->view()->text->CursorLeft();
1752 owner->view()->update (1);
1754 owner->view()->text->CursorLeft();
1755 owner->view()->text->Delete();
1756 owner->view()->text->sel_cursor =
1757 owner->view()->text->cursor;
1758 owner->view()->smallUpdate(1);
1761 owner->view()->text->Delete();
1762 owner->view()->text->sel_cursor =
1763 owner->view()->text->cursor;
1764 owner->view()->smallUpdate(1);
1767 owner->view()->cut();
1773 /* -------> Delete word forward. */
1774 case LFUN_DELETE_WORD_FORWARD:
1775 owner->view()->update(-2);
1777 owner->view()->text->DeleteWordForward();
1778 owner->view()->update( 1 );
1780 moveCursorUpdate(false);
1781 owner->getMiniBuffer()->Set(CurrentState());
1784 /* -------> Delete word backward. */
1785 case LFUN_DELETE_WORD_BACKWARD:
1786 owner->view()->update(-2);
1788 owner->view()->text->DeleteWordBackward();
1789 owner->view()->update( 1 );
1791 moveCursorUpdate(false);
1792 owner->getMiniBuffer()->Set(CurrentState());
1795 /* -------> Kill to end of line. */
1796 case LFUN_DELETE_LINE_FORWARD:
1798 owner->view()->update(-2);
1799 owner->view()->text->DeleteLineForward();
1800 owner->view()->update( 1 );
1802 moveCursorUpdate(false);
1805 /* -------> Set mark off. */
1807 owner->view()->beforeChange();
1808 owner->view()->update(0);
1809 owner->view()->text->sel_cursor =
1810 owner->view()->text->cursor;
1811 setMessage(N_("Mark off"));
1814 /* -------> Set mark on. */
1816 owner->view()->beforeChange();
1817 owner->view()->text->mark_set = 1;
1818 owner->view()->update( 0 );
1819 owner->view()->text->sel_cursor =
1820 owner->view()->text->cursor;
1821 setMessage(N_("Mark on"));
1824 case LFUN_BACKSPACE:
1827 if (!owner->view()->text->selection) {
1828 if (owner->getIntl()->getTrans()->backspace()) {
1829 owner->view()->text->Backspace();
1830 owner->view()->text->sel_cursor =
1831 owner->view()->text->cursor;
1832 owner->view()->smallUpdate(1);
1833 // It is possible to make it a lot faster still
1834 // just comment out the lone below...
1835 owner->view()->showCursor();
1838 owner->view()->cut();
1841 owner->getMiniBuffer()->Set(CurrentState());
1842 owner->view()->setState();
1846 case LFUN_BACKSPACE_SKIP:
1848 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1850 LyXCursor cursor = owner->view()->text->cursor;
1853 if (!owner->view()->text->selection) {
1855 && !(cursor.par->added_space_top
1856 == VSpace (VSpace::NONE))) {
1857 owner->view()->text->SetParagraph
1858 (cursor.par->line_top,
1859 cursor.par->line_bottom,
1860 cursor.par->pagebreak_top,
1861 cursor.par->pagebreak_bottom,
1862 VSpace(VSpace::NONE), cursor.par->added_space_bottom,
1864 cursor.par->labelwidthstring, 0);
1865 owner->view()->update (1);
1867 owner->view()->text->Backspace();
1868 owner->view()->text->sel_cursor
1870 owner->view()->smallUpdate (1);
1873 owner->view()->cut();
1878 case LFUN_BREAKPARAGRAPH:
1880 owner->view()->beforeChange();
1881 owner->view()->text->BreakParagraph(0);
1882 owner->view()->smallUpdate(1);
1883 SetUpdateTimer(0.01);
1884 owner->view()->text->sel_cursor =
1885 owner->view()->text->cursor;
1886 owner->view()->setState();
1887 owner->getMiniBuffer()->Set(CurrentState());
1891 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1893 owner->view()->beforeChange();
1894 owner->view()->text->BreakParagraph(1);
1895 owner->view()->smallUpdate(1);
1896 SetUpdateTimer(0.01);
1897 owner->view()->text->sel_cursor =
1898 owner->view()->text->cursor;
1899 owner->view()->setState();
1900 owner->getMiniBuffer()->Set(CurrentState());
1904 case LFUN_BREAKPARAGRAPH_SKIP:
1906 // When at the beginning of a paragraph, remove
1907 // indentation and add a "defskip" at the top.
1908 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
1910 LyXCursor cursor = owner->view()->text->cursor;
1912 owner->view()->beforeChange();
1913 if (cursor.pos == 0) {
1914 if (cursor.par->added_space_top == VSpace(VSpace::NONE)) {
1915 owner->view()->text->SetParagraph
1916 (cursor.par->line_top,
1917 cursor.par->line_bottom,
1918 cursor.par->pagebreak_top,
1919 cursor.par->pagebreak_bottom,
1920 VSpace(VSpace::DEFSKIP), cursor.par->added_space_bottom,
1922 cursor.par->labelwidthstring, 1);
1923 owner->view()->update(1);
1927 owner->view()->text->BreakParagraph(0);
1928 owner->view()->smallUpdate(1);
1930 SetUpdateTimer(0.01);
1931 owner->view()->text->sel_cursor = cursor;
1932 owner->view()->setState();
1933 owner->getMiniBuffer()->Set(CurrentState());
1938 owner->view()->beforeChange();
1939 owner->view()->text->InsertChar('\"'); // This " matches the single quote in the code
1940 owner->view()->smallUpdate(1);
1942 moveCursorUpdate(false);
1948 InsetCommand * new_inset;
1949 if (action == LFUN_HTMLURL)
1950 new_inset = new InsetUrl("htmlurl", "", "");
1952 new_inset = new InsetUrl("url", "", "");
1953 owner->view()->insertInset(new_inset);
1954 new_inset->Edit(owner->view(), 0, 0, 0);
1957 case LFUN_INSET_TEXT:
1959 InsetText * new_inset = new InsetText(owner->buffer());
1960 owner->view()->insertInset(new_inset);
1961 new_inset->Edit(owner->view(), 0, 0, 0);
1965 case LFUN_INSET_NUMBER:
1967 InsetNumber * new_inset = new InsetNumber(owner->buffer());
1968 owner->view()->insertInset(new_inset);
1969 new_inset->Edit(owner->view(), 0, 0, 0);
1973 case LFUN_INSET_ERT:
1975 InsetERT * new_inset = new InsetERT(owner->buffer());
1976 owner->view()->insertInset(new_inset);
1977 new_inset->Edit(owner->view(), 0, 0, 0);
1980 case LFUN_INSET_FOOTNOTE:
1982 InsetFoot * new_inset = new InsetFoot(owner->buffer());
1983 owner->view()->insertInset(new_inset);
1984 new_inset->Edit(owner->view(), 0, 0, 0);
1988 // --- lyxserver commands ----------------------------
1990 case LFUN_CHARATCURSOR:
1992 LyXParagraph::size_type pos =
1993 owner->view()->text->cursor.pos;
1994 if(pos < owner->view()->text->cursor.par->size())
1995 //dispatch_buffer = owner->view()->text->
1996 // cursor.par->text[pos];
1998 owner->view()->text->
1999 cursor.par->GetChar(pos);
2001 dispatch_buffer = "EOF";
2007 tostr(owner->view()->text->cursor.x) + ' '
2008 + tostr(owner->view()->text->cursor.y);
2015 sscanf(argument.c_str(), " %d %ld", &x, &y);
2016 owner->view()->text->SetCursorFromCoordinates(x, y);
2020 case LFUN_GETLAYOUT:
2022 tostr(owner->view()->text->cursor.par->layout);
2027 LyXFont * font = &(owner->view()->text->current_font);
2028 if(font->shape() == LyXFont::ITALIC_SHAPE)
2029 dispatch_buffer = 'E';
2030 else if(font->shape() == LyXFont::SMALLCAPS_SHAPE)
2031 dispatch_buffer = 'N';
2033 dispatch_buffer = '0';
2040 LyXFont * font = &(owner->view()->text->current_font);
2041 if(font->latex() == LyXFont::ON)
2042 dispatch_buffer = 'L';
2044 dispatch_buffer = '0';
2049 setMessage(owner->buffer()->fileName());
2050 lyxerr.debug() << "FNAME["
2051 << owner->buffer()->fileName()
2059 dispatch_buffer = buf;
2060 lyxserver->notifyClient(dispatch_buffer);
2064 case LFUN_GOTOFILEROW:
2066 char file_name[100];
2068 sscanf(argument.c_str(), " %s %d", file_name, &row);
2070 // Must replace extension of the file to be .lyx and get full path
2071 string s = ChangeExtension(string(file_name), ".lyx", false);
2073 // Either change buffer or load the file
2074 if (bufferlist.exists(s))
2075 owner->view()->buffer(bufferlist.getBuffer(s));
2077 owner->view()->buffer(bufferlist.loadLyXFile(s));
2080 owner->view()->setCursorFromRow(row);
2083 owner->view()->center();
2090 int qa = lyxaction.LookupFunc(argument.c_str());
2091 setMessage(lyxaction.helpText(static_cast<kb_action>(qa)));
2095 // --- accented characters ---------------------------
2098 case LFUN_CIRCUMFLEX:
2108 case LFUN_SPECIAL_CARON:
2111 case LFUN_HUNG_UMLAUT:
2117 if (keyseq.length == -1 && keyseq.getiso() != 0)
2118 c = keyseq.getiso();
2122 owner->getIntl()->getTrans()->
2123 deadkey(c, get_accent(action).accent,
2124 owner->view()->text);
2126 // Need to reset, in case the minibuffer calls these
2131 // copied verbatim from do_accent_char
2132 owner->view()->smallUpdate(1);
2134 owner->view()->text->sel_cursor =
2135 owner->view()->text->cursor;
2139 // --- toolbar ----------------------------------
2140 case LFUN_PUSH_TOOLBAR:
2142 int nth = strToInt(argument);
2143 if (lyxerr.debugging(Debug::TOOLBAR)) {
2144 lyxerr << "LFUN_PUSH_TOOLBAR: argument = `"
2145 << argument << "'\n"
2146 << "LFUN_PUSH_TOOLBAR: nth = `"
2147 << nth << "'" << endl;
2152 setErrorMessage(N_("Push-toolbar needs argument > 0"));
2154 owner->getToolbar()->push(nth);
2159 case LFUN_ADD_TO_TOOLBAR:
2161 if (lyxerr.debugging(Debug::TOOLBAR)) {
2162 lyxerr << "LFUN_ADD_TO_TOOLBAR:"
2163 "argument = `" << argument << '\'' << endl;
2165 string tmp(argument);
2166 //lyxerr <<string("Argument: ") + argument);
2167 //lyxerr <<string("Tmp : ") + tmp);
2170 setErrorMessage(N_("Usage: toolbar-add-to <LyX command>"));
2172 owner->getToolbar()->add(argument, false);
2173 owner->getToolbar()->set();
2178 // --- insert characters ----------------------------------------
2180 // --- Mathed stuff. If we are here, there is no locked inset yet.
2185 if (!greek_kb_flag) {
2187 setMessage(N_("Math greek mode on"));
2194 case LFUN_GREEK_TOGGLE:
2196 greek_kb_flag = greek_kb_flag ? 0 : 2;
2197 if (greek_kb_flag) {
2198 setMessage(N_("Math greek keyboard on"));
2200 setMessage(N_("Math greek keyboard off"));
2205 case LFUN_MATH_DELIM:
2206 case LFUN_INSERT_MATRIX:
2208 if (owner->view()->available()) {
2210 open_new_inset(new InsetFormula(false));
2213 ->LocalDispatch(owner->view(),
2220 case LFUN_INSERT_MATH:
2222 math_insert_symbol(argument.c_str());
2226 case LFUN_MATH_DISPLAY:
2228 if (owner->view()->available())
2229 owner->view()->open_new_inset(new InsetFormula(true));
2233 case LFUN_MATH_MACRO:
2235 if (owner->view()->available()) {
2238 setErrorMessage(N_("Missing argument"));
2240 string s1 = token(s, ' ', 1);
2241 int na = s1.empty() ? 0: atoi(s1.c_str());
2243 open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2249 case LFUN_MATH_MODE: // Open or create a math inset
2252 if (owner->view()->available())
2253 owner->view()->open_new_inset(new InsetFormula);
2254 setMessage(N_("Math editor mode"));
2258 case LFUN_MATH_NUMBER:
2259 case LFUN_MATH_LIMITS:
2261 setErrorMessage(N_("This is only allowed in math mode!"));
2265 case LFUN_INSERT_CITATION:
2267 InsetCitation * new_inset = new InsetCitation();
2269 // The note, if any, must be after the key, delimited
2270 // by a | so both key and remark can have spaces.
2271 if (!argument.empty()) {
2272 string lsarg(argument);
2273 if (contains(lsarg, "|")) {
2274 new_inset->setContents(token(lsarg, '|', 0));
2275 new_inset->setOptions(token(lsarg, '|', 1));
2277 new_inset->setContents(lsarg);
2278 owner->view()->insertInset(new_inset);
2280 owner->view()->insertInset(new_inset);
2281 new_inset->Edit(owner->view(), 0, 0, 0);
2286 case LFUN_INSERT_BIBTEX:
2288 // ale970405+lasgoutt970425
2289 // The argument can be up to two tokens separated
2290 // by a space. The first one is the bibstyle.
2291 string lsarg(argument);
2292 string bibstyle = token(lsarg, ' ', 1);
2293 if (bibstyle.empty())
2295 InsetBibtex * new_inset
2296 = new InsetBibtex(token(lsarg, ' ', 0),
2300 owner->view()->insertInset(new_inset);
2301 if (lsarg.empty()) {
2302 new_inset->Edit(owner->view(), 0, 0, 0);
2307 // BibTeX data bases
2308 case LFUN_BIBDB_ADD:
2310 InsetBibtex * inset =
2311 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2313 inset->addDatabase(argument);
2318 case LFUN_BIBDB_DEL:
2320 InsetBibtex * inset =
2321 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2323 inset->delDatabase(argument);
2328 case LFUN_BIBTEX_STYLE:
2330 InsetBibtex * inset =
2331 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2333 inset->setOptions(argument);
2338 case LFUN_INDEX_INSERT:
2339 case LFUN_INDEX_INSERT_LAST:
2341 // Can't do that at the beginning of a paragraph.
2342 if (owner->view()->text->cursor.pos - 1 < 0)
2345 InsetIndex * new_inset = new InsetIndex();
2346 if (!argument.empty()) {
2347 string lsarg(argument);
2348 new_inset->setContents(lsarg);
2349 owner->view()->insertInset(new_inset);
2352 //get the current word for an argument
2353 LyXParagraph::size_type lastpos =
2354 owner->view()->text->cursor.pos - 1;
2355 // Get the current word. note that this must be done
2356 // before inserting the inset, or the inset will
2358 string curstring(owner->view()
2359 ->text->cursor.par->GetWord(lastpos));
2361 //make the new inset and write the current word into it
2362 InsetIndex * new_inset = new InsetIndex();
2364 new_inset->setContents(curstring);
2366 //don't edit it if the call was to INSERT_LAST
2367 if(action != LFUN_INDEX_INSERT_LAST) {
2368 new_inset->Edit(owner->view(), 0, 0, 0);
2370 //it looks blank on the screen unless
2371 //we do something. put it here.
2373 // move the cursor to the returned value of lastpos
2374 // but only for the auto-insert
2375 owner->view()->text->cursor.pos = lastpos;
2378 //put the new inset into the buffer.
2379 // there should be some way of knowing the user
2380 //cancelled & avoiding this, but i don't know how
2381 owner->view()->insertInset(new_inset);
2386 case LFUN_INDEX_PRINT:
2388 Inset * new_inset = new InsetPrintIndex(owner->buffer());
2389 owner->view()->insertInset(new_inset, "Standard", true);
2393 case LFUN_PARENTINSERT:
2395 lyxerr << "arg " << argument << endl;
2396 Inset * new_inset = new InsetParent(argument, owner->buffer());
2397 owner->view()->insertInset(new_inset, "Standard", true);
2401 case LFUN_CHILDINSERT:
2403 Inset * new_inset = new InsetInclude(argument,
2405 owner->view()->insertInset(new_inset, "Standard", true);
2406 new_inset->Edit(owner->view(), 0, 0, 0);
2410 case LFUN_CHILDOPEN:
2413 MakeAbsPath(argument,
2414 OnlyPath(owner->buffer()->fileName()));
2415 setMessage(N_("Opening child document ") +
2416 MakeDisplayPath(filename) + "...");
2417 owner->view()->savePosition();
2418 if (bufferlist.exists(filename))
2419 owner->view()->buffer(bufferlist.getBuffer(filename));
2421 owner->view()->buffer(bufferlist.loadLyXFile(filename));
2425 case LFUN_INSERT_NOTE:
2426 owner->view()->insertNote();
2429 case LFUN_INSERTFOOTNOTE:
2431 LyXParagraph::footnote_kind kind;
2432 if (argument == "footnote")
2433 { kind = LyXParagraph::FOOTNOTE; }
2434 else if (argument == "margin")
2435 { kind = LyXParagraph::MARGIN; }
2436 else if (argument == "figure")
2437 { kind = LyXParagraph::FIG; }
2438 else if (argument == "table")
2439 { kind = LyXParagraph::TAB; }
2440 else if (argument == "wide-fig")
2441 { kind = LyXParagraph::WIDE_FIG; }
2442 else if (argument == "wide-tab")
2443 { kind = LyXParagraph::WIDE_TAB; }
2444 else if (argument == "algorithm")
2445 { kind = LyXParagraph::ALGORITHM; }
2447 setErrorMessage(N_("Unknown kind of footnote"));
2450 owner->view()->text->InsertFootnoteEnvironment(kind);
2451 owner->view()->update(1);
2452 owner->view()->setState();
2456 case LFUN_BUFFERBULLETSSELECT:
2460 case LFUN_TOGGLECURSORFOLLOW:
2461 cursor_follows_scrollbar = !cursor_follows_scrollbar;
2464 case LFUN_KMAP_OFF: // keymap off
2465 owner->getIntl()->KeyMapOn(false);
2468 case LFUN_KMAP_PRIM: // primary keymap
2469 owner->getIntl()->KeyMapPrim();
2472 case LFUN_KMAP_SEC: // secondary keymap
2473 owner->getIntl()->KeyMapSec();
2476 case LFUN_KMAP_TOGGLE: // toggle keymap
2477 owner->getIntl()->ToggleKeyMap();
2480 case LFUN_SELFINSERT:
2482 for (string::size_type i = 0; i < argument.length(); ++i) {
2483 owner->view()->text->InsertChar(argument[i]);
2484 // This needs to be in the loop, or else we
2485 // won't break lines correctly. (Asger)
2486 owner->view()->smallUpdate(1);
2489 owner->view()->text->sel_cursor =
2490 owner->view()->text->cursor;
2491 moveCursorUpdate(false);
2497 // argument contains ';'-terminated commands
2498 while (argument.find(';') != string::npos) {
2500 argument = split(argument, first, ';');
2506 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
2514 now_time_t = time(NULL);
2515 now_tm = localtime(&now_time_t);
2516 (void)setlocale(LC_TIME, "");
2517 if (!argument.empty())
2519 else if (arg.empty())
2520 arg = lyxrc.date_insert_format;
2521 datetmp_len = (int) strftime(datetmp, 32, arg.c_str(), now_tm);
2522 for (int i = 0; i < datetmp_len; i++) {
2523 owner->view()->text->InsertChar(datetmp[i]);
2524 owner->view()->smallUpdate(1);
2527 owner->view()->text->sel_cursor = owner->view()->text->cursor;
2528 moveCursorUpdate(false);
2532 case LFUN_SAVEPREFERENCES:
2534 Path p(user_lyxdir);
2535 lyxrc.write("preferences");
2539 case LFUN_UNKNOWN_ACTION:
2541 if(!owner->buffer()) {
2543 setErrorMessage(N_("No document open"));
2547 if (owner->buffer()->isReadonly()) {
2549 setErrorMessage(N_("Document is read only"));
2553 if (!argument.empty()) {
2555 /* Automatically delete the currently selected
2556 * text and replace it with what is being
2557 * typed in now. Depends on lyxrc settings
2558 * "auto_region_delete", which defaults to
2561 if ( lyxrc.auto_region_delete ) {
2562 if (owner->view()->text->selection){
2563 owner->view()->text->CutSelection(false);
2564 owner->view()->update(-1);
2568 owner->view()->beforeChange();
2571 if (isdigit(argument[0]) &&
2572 (lyxrc.number_inset == "true" ||
2573 (lyxrc.number_inset == "rtl" &&
2574 owner->view()->text->real_current_font.isVisibleRightToLeft()
2576 UpdatableInset * tmpinset = new InsetNumber(owner->buffer());
2577 owner->view()->open_new_inset(tmpinset);
2578 tmpinset->LocalDispatch(owner->view(), action,
2584 for (string::size_type i = 0;
2585 i < argument.length(); ++i) {
2586 if (greek_kb_flag) {
2587 if (!math_insert_greek(argument[i]))
2588 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2590 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2593 owner->view()->smallUpdate(1);
2596 owner->view()->text->sel_cursor =
2597 owner->view()->text->cursor;
2598 moveCursorUpdate(false);
2601 // why is an "Unknown action" with empty
2602 // argument even dispatched in the first
2603 // place? I`ll probably change that. (Lgb)
2605 setErrorMessage(N_("Unknown action"));
2609 lyxerr << "A truly unknown func!" << endl;
2615 string res = getMessage();
2618 if (!commandshortcut.empty()) {
2619 string newbuf = owner->getMiniBuffer()->GetText();
2620 if (newbuf != commandshortcut) {
2621 owner->getMiniBuffer()->Set(newbuf
2627 owner->getMiniBuffer()->Set(string(_(res.c_str()))
2628 + " " + commandshortcut);
2635 void LyXFunc::setupLocalKeymap()
2637 keyseq.stdmap = keyseq.curmap = toplevel_keymap;
2638 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap;
2642 void LyXFunc::MenuNew(bool fromTemplate)
2644 string fname, initpath = lyxrc.document_path;
2647 if (owner->view()->available()) {
2648 string trypath = owner->buffer()->filepath;
2649 // If directory is writeable, use this as default.
2650 if (IsDirWriteable(trypath) == 1)
2655 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
2656 fileDlg.SetButton(1, _("Templates"), lyxrc.template_path);
2657 fname = fileDlg.Select(_("Enter Filename for new document"),
2658 initpath, "*.lyx", _("newfile"));
2661 if (fname.empty()) {
2662 owner->getMiniBuffer()->Set(_("Canceled."));
2663 lyxerr.debug() << "New Document Cancelled." << endl;
2667 // get absolute path of file and make sure the filename ends
2669 string s = MakeAbsPath(fname);
2670 if (!IsLyXFilename(s))
2673 // Check if the document already is open
2674 if (bufferlist.exists(s)){
2675 switch(AskConfirmation(_("Document is already open:"),
2676 MakeDisplayPath(s, 50),
2677 _("Do you want to close that document now?\n"
2678 "('No' will just switch to the open version)")))
2680 case 1: // Yes: close the document
2681 if (!bufferlist.close(bufferlist.getBuffer(s)))
2682 // If close is canceled, we cancel here too.
2685 case 2: // No: switch to the open document
2686 owner->view()->buffer(bufferlist.getBuffer(s));
2688 case 3: // Cancel: Do nothing
2689 owner->getMiniBuffer()->Set(_("Canceled."));
2694 // Check whether the file already exists
2695 if (IsLyXFilename(s)) {
2697 if (fi.readable() &&
2698 AskQuestion(_("File already exists:"),
2699 MakeDisplayPath(s, 50),
2700 _("Do you want to open the document?"))) {
2702 owner->getMiniBuffer()->Set(_("Opening document"),
2703 MakeDisplayPath(s), "...");
2705 owner->view()->buffer(
2706 bufferlist.loadLyXFile(s));
2707 owner->getMiniBuffer()->Set(_("Document"),
2714 // The template stuff
2718 fname = fileDlg.Select(_("Choose template"),
2719 lyxrc.template_path,
2725 // find a free buffer
2726 lyxerr.debug() << "Find a free buffer." << endl;
2727 owner->view()->buffer(bufferlist.newFile(s, templname));
2731 void LyXFunc::MenuOpen()
2733 string initpath = lyxrc.document_path;
2736 if (owner->view()->available()) {
2737 string trypath = owner->buffer()->filepath;
2738 // If directory is writeable, use this as default.
2739 if (IsDirWriteable(trypath) == 1)
2745 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
2746 fileDlg.SetButton(1, _("Examples"),
2747 AddPath(system_lyxdir, "examples"));
2748 string filename = fileDlg.Select(_("Select Document to Open"),
2752 // check selected filename
2753 if (filename.empty()) {
2754 owner->getMiniBuffer()->Set(_("Canceled."));
2758 // get absolute path of file and make sure the filename ends
2760 filename = MakeAbsPath(filename);
2761 if (!IsLyXFilename(filename))
2765 owner->getMiniBuffer()->Set(_("Opening document"),
2766 MakeDisplayPath(filename), "...");
2767 Buffer * openbuf = bufferlist.loadLyXFile(filename);
2769 owner->view()->buffer(openbuf);
2770 owner->getMiniBuffer()->Set(_("Document"),
2771 MakeDisplayPath(filename),
2774 owner->getMiniBuffer()->Set(_("Could not open document"),
2775 MakeDisplayPath(filename));
2780 void LyXFunc::doImportASCII(bool linorpar)
2782 string initpath = lyxrc.document_path;
2785 if (owner->view()->available()) {
2786 string trypath = owner->buffer()->filepath;
2787 // If directory is writeable, use this as default.
2788 if (IsDirWriteable(trypath) == 1)
2794 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
2795 fileDlg.SetButton(1, _("Examples"),
2796 AddPath(system_lyxdir, "examples"));
2797 string filename = fileDlg.Select(_("Select ASCII file to Import"),
2801 // check selected filename
2802 if (filename.empty()) {
2803 owner->getMiniBuffer()->Set(_("Canceled."));
2807 // get absolute path of file
2808 filename = MakeAbsPath(filename);
2810 string s = ChangeExtension(filename, ".lyx", false);
2812 // Check if the document already is open
2813 if (bufferlist.exists(s)) {
2814 switch(AskConfirmation(_("Document is already open:"),
2815 MakeDisplayPath(s, 50),
2816 _("Do you want to close that document now?\n"
2817 "('No' will just switch to the open version)")))
2819 case 1: // Yes: close the document
2820 if (!bufferlist.close(bufferlist.getBuffer(s)))
2821 // If close is canceled, we cancel here too.
2824 case 2: // No: switch to the open document
2825 owner->view()->buffer(bufferlist.getBuffer(s));
2827 case 3: // Cancel: Do nothing
2828 owner->getMiniBuffer()->Set(_("Canceled."));
2833 // Check if a LyX document by the same root exists in filesystem
2834 FileInfo f(s, true);
2835 if (f.exist() && !AskQuestion(_("A document by the name"),
2837 _("already exists. Overwrite?"))) {
2838 owner->getMiniBuffer()->Set(_("Canceled."));
2842 owner->view()->buffer(bufferlist.newFile(s, string()));
2843 owner->getMiniBuffer()->Set(_("Importing ASCII file"),
2844 MakeDisplayPath(filename), "...");
2845 // Insert ASCII file
2846 InsertAsciiFile(owner->view(), filename, linorpar);
2847 owner->getMiniBuffer()->Set(_("ASCII file "),
2848 MakeDisplayPath(filename),
2853 void LyXFunc::doImportLaTeX(bool isnoweb)
2855 string initpath = lyxrc.document_path;
2858 if (owner->view()->available()) {
2859 string trypath = owner->buffer()->filepath;
2860 // If directory is writeable, use this as default.
2861 if (IsDirWriteable(trypath) == 1)
2867 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
2868 fileDlg.SetButton(1, _("Examples"),
2869 AddPath(system_lyxdir, "examples"));
2872 filename = fileDlg.Select(_("Select Noweb file to Import"),
2875 filename = fileDlg.Select(_("Select LaTeX file to Import"),
2881 // check selected filename
2882 if (filename.empty()) {
2883 owner->getMiniBuffer()->Set(_("Canceled."));
2887 // get absolute path of file
2888 filename = MakeAbsPath(filename);
2890 // Check if the document already is open
2891 string LyXfilename = ChangeExtension(filename, ".lyx", false);
2892 if (bufferlist.exists(LyXfilename)){
2893 switch(AskConfirmation(_("Document is already open:"),
2894 MakeDisplayPath(LyXfilename, 50),
2895 _("Do you want to close that document now?\n"
2896 "('No' will just switch to the open version)")))
2898 case 1: // Yes: close the document
2899 if (!bufferlist.close(bufferlist.getBuffer(LyXfilename)))
2900 // If close is canceled, we cancel here too.
2903 case 2: // No: switch to the open document
2904 owner->view()->buffer(
2905 bufferlist.getBuffer(LyXfilename));
2907 case 3: // Cancel: Do nothing
2908 owner->getMiniBuffer()->Set(_("Canceled."));
2913 // Check if a LyX document by the same root exists in filesystem
2914 FileInfo f(LyXfilename, true);
2915 if (f.exist() && !AskQuestion(_("A document by the name"),
2916 MakeDisplayPath(LyXfilename),
2917 _("already exists. Overwrite?"))) {
2918 owner->getMiniBuffer()->Set(_("Canceled."));
2925 owner->getMiniBuffer()->Set(_("Importing LaTeX file"),
2926 MakeDisplayPath(filename), "...");
2927 ImportLaTeX myImport(filename);
2928 openbuf = myImport.run();
2930 owner->getMiniBuffer()->Set(_("Importing Noweb file"),
2931 MakeDisplayPath(filename), "...");
2932 ImportNoweb myImport(filename);
2933 openbuf = myImport.run();
2936 owner->view()->buffer(openbuf);
2937 owner->getMiniBuffer()->Set(isnoweb ?
2938 _("Noweb file ") : _("LateX file "),
2939 MakeDisplayPath(filename),
2942 owner->getMiniBuffer()->Set(isnoweb ?
2943 _("Could not import Noweb file") :
2944 _("Could not import LaTeX file"),
2945 MakeDisplayPath(filename));
2950 void LyXFunc::doImportLinuxDoc()
2952 string initpath = lyxrc.document_path;
2955 if (owner->view()->available()) {
2956 string trypath = owner->buffer()->filepath;
2957 // If directory is writeable, use this as default.
2958 if (IsDirWriteable(trypath) == 1)
2964 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
2965 fileDlg.SetButton(1, _("Examples"),
2966 AddPath(system_lyxdir, "examples"));
2968 string filename = fileDlg.Select(_("Select LinuxDoc file to Import"),
2969 initpath, "*.sgml");
2973 // check selected filename
2974 if (filename.empty()) {
2975 owner->getMiniBuffer()->Set(_("Canceled."));
2979 // get absolute path of file
2980 filename = MakeAbsPath(filename);
2982 // Check if the document already is open
2983 string LyXfilename = ChangeExtension(filename, ".lyx", false);
2984 if (bufferlist.exists(LyXfilename)){
2985 switch(AskConfirmation(_("Document is already open:"),
2986 MakeDisplayPath(LyXfilename, 50),
2987 _("Do you want to close that document now?\n"
2988 "('No' will just switch to the open version)")))
2990 case 1: // Yes: close the document
2991 if (!bufferlist.close(bufferlist.getBuffer(LyXfilename)))
2992 // If close is canceled, we cancel here too.
2995 case 2: // No: switch to the open document
2996 owner->view()->buffer(
2997 bufferlist.getBuffer(LyXfilename));
2999 case 3: // Cancel: Do nothing
3000 owner->getMiniBuffer()->Set(_("Canceled."));
3005 // Check if a LyX document by the same root exists in filesystem
3006 FileInfo f(LyXfilename, true);
3007 if (f.exist() && !AskQuestion(_("A document by the name"),
3008 MakeDisplayPath(LyXfilename),
3009 _("already exists. Overwrite?"))) {
3010 owner->getMiniBuffer()->Set(_("Canceled."));
3015 owner->getMiniBuffer()->Set(_("Importing LinuxDoc file"),
3016 MakeDisplayPath(filename), "...");
3019 string tmp = lyxrc.linuxdoc_to_lyx_command + filename;
3023 int result = one.startscript(Systemcalls::System, tmp);
3025 string filename = ChangeExtension(filename, ".lyx", false);
3026 // File was generated without problems. Load it.
3027 buf = bufferlist.loadLyXFile(filename);
3028 owner->view()->buffer(buf);
3029 owner->getMiniBuffer()->Set(_("LinuxDoc file "),
3030 MakeDisplayPath(filename),
3033 owner->getMiniBuffer()->Set(_("Could not import LinuxDoc file"),
3034 MakeDisplayPath(filename));
3039 void LyXFunc::MenuInsertLyXFile(string const & filen)
3041 string filename = filen;
3043 if (filename.empty()) {
3044 // Launch a file browser
3045 string initpath = lyxrc.document_path;
3048 if (owner->view()->available()) {
3049 string trypath = owner->buffer()->filepath;
3050 // If directory is writeable, use this as default.
3051 if (IsDirWriteable(trypath) == 1)
3057 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
3058 fileDlg.SetButton(1, _("Examples"),
3059 AddPath(system_lyxdir, "examples"));
3060 filename = fileDlg.Select(_("Select Document to Insert"),
3064 // check selected filename
3065 if (filename.empty()) {
3066 owner->getMiniBuffer()->Set(_("Canceled."));
3071 // get absolute path of file and make sure the filename ends
3073 filename = MakeAbsPath(filename);
3074 if (!IsLyXFilename(filename))
3078 owner->getMiniBuffer()->Set(_("Inserting document"),
3079 MakeDisplayPath(filename), "...");
3080 bool res = owner->view()->insertLyXFile(filename);
3082 owner->getMiniBuffer()->Set(_("Document"),
3083 MakeDisplayPath(filename),
3086 owner->getMiniBuffer()->Set(_("Could not insert document"),
3087 MakeDisplayPath(filename));
3092 void LyXFunc::reloadBuffer()
3094 string fn = owner->buffer()->fileName();
3095 if (bufferlist.close(owner->buffer()))
3096 owner->view()->buffer(bufferlist.loadLyXFile(fn));
3100 void LyXFunc::CloseBuffer()
3102 if (bufferlist.close(owner->buffer()) && !quitting) {
3103 if (bufferlist.empty()) {
3104 // need this otherwise SEGV may occur while trying to
3105 // set variables that don't exist
3106 // since there's no current buffer
3107 CloseAllBufferRelatedPopups();
3110 owner->view()->buffer(bufferlist.first());
3116 Inset * LyXFunc::getInsetByCode(Inset::Code code)
3120 LyXCursor cursor = owner->view()->text->cursor;
3121 LyXParagraph::size_type pos = cursor.pos;
3122 LyXParagraph * par = cursor.par;
3124 while (par && !found) {
3125 while ((inset = par->ReturnNextInsetPointer(pos))){
3126 if (inset->LyxCode() == code) {
3134 return found ? inset : 0;
3138 // Each "owner" should have it's own message method. lyxview and
3139 // the minibuffer would use the minibuffer, but lyxserver would
3140 // send an ERROR signal to its client. Alejandro 970603
3141 // This func is bit problematic when it comes to NLS, to make the
3142 // lyx servers client be language indepenent we must not translate
3143 // strings sent to this func.
3144 void LyXFunc::setErrorMessage(string const & m) const
3146 dispatch_buffer = m;
3151 void LyXFunc::setMessage(string const & m)
3153 dispatch_buffer = m;