1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * ====================================================== */
20 #pragma implementation
23 #include "lyxlookup.h"
26 #include "bufferlist.h"
27 #include "lyxserver.h"
32 #include "LyXAction.h"
33 #include "insets/inseturl.h"
34 #include "insets/insetlatexaccent.h"
35 #include "insets/insettoc.h"
36 #include "insets/insetlof.h"
37 #include "insets/insetloa.h"
38 #include "insets/insetlot.h"
39 #include "insets/insetref.h"
40 #include "insets/insetparent.h"
41 #include "insets/insetindex.h"
42 #include "insets/insetinclude.h"
43 #include "insets/insetbib.h"
44 #include "insets/insettext.h"
45 //#include "insets/insetnumber.h"
46 #include "insets/insetert.h"
47 #include "insets/insetgraphics.h"
48 #include "insets/insetfoot.h"
49 #include "mathed/formulamacro.h"
51 #include "spellchecker.h" // RVDK_PATCH_5
52 #include "minibuffer.h"
56 #include "lyx_gui_misc.h"
57 #include "support/filetools.h"
58 #include "support/FileInfo.h"
59 #include "support/syscall.h"
60 #include "support/lstrings.h"
61 #include "support/path.h"
66 #include "trans_mgr.h"
67 #include "ImportLaTeX.h"
68 #include "ImportNoweb.h"
77 extern bool cursor_follows_scrollbar;
79 extern void InsertAsciiFile(BufferView *, string const &, bool);
80 extern void math_insert_symbol(char const *);
81 extern Bool math_insert_greek(char const); // why "Bool"?
82 extern BufferList bufferlist;
83 extern LyXServer * lyxserver;
84 extern short greek_kb_flag;
85 extern FD_form_toc * fd_form_toc;
86 extern bool selection_possible;
88 extern kb_keymap * toplevel_keymap;
90 extern void MenuWrite(Buffer *);
91 extern void MenuWriteAs(Buffer *);
92 extern int MenuRunLaTeX(Buffer *);
93 extern int MenuBuildProg(Buffer *);
94 extern int MenuRunChktex(Buffer *);
95 extern bool CreatePostscript(Buffer *, bool);
96 extern void MenuPrint(Buffer *);
97 extern void MenuSendto();
98 extern void QuitLyX();
99 extern void MenuFax(Buffer *);
100 extern void MenuExport(Buffer *, string const &);
101 extern void MenuPasteSelection(char at);
102 extern LyXAction lyxaction;
104 extern tex_accent_struct get_accent(kb_action action);
106 extern void AutoSave();
107 extern void SetUpdateTimer(float timer = 0.3);
108 extern void FreeUpdateTimer();
109 extern bool PreviewDVI(Buffer *);
110 extern bool PreviewPostscript(Buffer *);
111 extern void MenuInsertLabel(char const *);
112 extern void MenuInsertRef();
113 extern void MenuLayoutCharacter();
114 extern void MenuLayoutParagraph();
115 extern void MenuLayoutDocument();
116 extern void MenuLayoutPaper();
117 extern void MenuLayoutTable(int flag);
118 extern void MenuLayoutQuotes();
119 extern void MenuLayoutPreamble();
120 extern void MenuLayoutSave();
121 extern void bulletForm();
123 extern Buffer * NewLyxFile(string const &);
124 extern void LoadLyXFile(string const &);
125 extern void Reconfigure(BufferView *);
127 extern LyXTextClass::size_type current_layout;
128 extern int getISOCodeFromLaTeX(char *);
130 extern void ShowLatexLog();
132 /* === globals =========================================================== */
134 bool LyXFunc::show_sc = true;
137 LyXFunc::LyXFunc(LyXView * o)
141 lyx_dead_action = LFUN_NOACTION;
142 lyx_calling_dead_action = LFUN_NOACTION;
147 // I changed this func slightly. I commented out the ...FinishUndo(),
148 // this means that all places that used to have a moveCursorUpdate, now
149 // have a ...FinishUndo() as the preceeding statement. I have also added
150 // a moveCursorUpdate to some of the functions that updated the cursor, but
151 // that did not show its new position.
153 void LyXFunc::moveCursorUpdate(bool selecting)
155 if (selecting || owner->view()->text->mark_set) {
156 owner->view()->text->SetSelection();
157 owner->view()->toggleToggle();
158 owner->view()->update(0);
160 owner->view()->update(-2); // this IS necessary
164 owner->view()->showCursor();
166 /* ---> Everytime the cursor is moved, show the current font state. */
167 // should this too me moved out of this func?
168 //owner->getMiniBuffer()->Set(CurrentState());
169 owner->view()->setState();
173 int LyXFunc::processKeyEvent(XEvent * ev)
177 XKeyEvent * keyevent = &ev->xkey;
178 KeySym keysym_return;
180 int num_bytes = LyXLookupString(ev, s_r, 10, &keysym_return);
181 s_r[num_bytes] = '\0';
183 if (lyxerr.debugging(Debug::KEY)) {
184 char * tmp = XKeysymToString(keysym_return);
185 string stm = (tmp ? tmp : "");
186 lyxerr << "KeySym is "
189 << keysym_return << "]"
190 << " and num_bytes is "
192 << " the string returned is \""
193 << s_r << '\"' << endl;
195 // Do nothing if we have nothing (JMarc)
196 if (num_bytes == 0 && keysym_return == NoSymbol) {
197 lyxerr[Debug::KEY] << "Empty kbd action (probably composing)"
202 // this function should be used always [asierra060396]
203 if (owner->view()->available() &&
204 owner->view()->the_locking_inset &&
205 keysym_return == XK_Escape) {
206 owner->view()->unlockInset(owner->view()->the_locking_inset);
207 owner->view()->text->CursorRight();
208 moveCursorUpdate(false);
209 owner->getMiniBuffer()->Set(CurrentState());
213 // Can we be sure that this will work for all X-Windows
214 // implementations? (Lgb)
215 // This code snippet makes lyx ignore some keys. Perhaps
216 // all of them should be explictly mentioned?
217 if((keysym_return >= XK_Shift_L && keysym_return <= XK_Hyper_R)
218 || keysym_return == XK_Mode_switch || keysym_return == 0x0)
221 // Do a one-deep top-level lookup for
222 // cancel and meta-fake keys. RVDK_PATCH_5
223 cancel_meta_seq.reset();
225 int action = cancel_meta_seq.addkey(keysym_return, keyevent->state
226 &(ShiftMask|ControlMask
229 // When not cancel or meta-fake, do the normal lookup.
230 // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
231 // Mostly, meta_fake_bit = 0. RVDK_PATCH_5.
232 if ( (action != LFUN_CANCEL) && (action != LFUN_META_FAKE) ) {
234 // remove Caps Lock and Mod2 as a modifiers
235 action = keyseq.addkey(keysym_return,
236 (keyevent->state | meta_fake_bit)
237 &(ShiftMask|ControlMask
240 // Dont remove this unless you know what you are doing.
243 if (action == 0) action = LFUN_PREFIX;
245 if (lyxerr.debugging(Debug::KEY)) {
251 << num_bytes << "]" << endl;
254 // already here we know if it any point in going further
255 // why not return already here if action == -1 and
256 // num_bytes == 0? (Lgb)
258 if(keyseq.length > 1 || keyseq.length < -1) {
261 owner->getMiniBuffer()->Set(buf);
265 if (keyseq.length < -1) { // unknown key sequence...
269 owner->getMiniBuffer()->Set(_("Unknown sequence:"), buf);
273 char isochar = keyseq.getiso();
274 if (!(keyevent->state&ControlMask) &&
275 !(keyevent->state&Mod1Mask) &&
276 (isochar && keysym_return < 0xF000)) {
279 if (argument.empty()) {
280 lyxerr.debug() << "Empty argument!" << endl;
281 // This can`t possibly be of any use
282 // so we`ll skip the dispatch.
286 if (action == LFUN_SELFINSERT) {
290 bool tmp_sc = show_sc;
292 Dispatch(action, argument.c_str());
299 LyXFunc::func_status LyXFunc::getStatus(int ac) const
302 func_status flag = LyXFunc::OK;
304 Buffer * buf = owner->buffer();
306 if (lyxaction.isPseudoAction(ac))
307 action = lyxaction.retrieveActionArg(ac, argument);
309 action = static_cast<kb_action>(ac);
311 if (action == LFUN_UNKNOWN_ACTION) {
312 setErrorMessage(N_("Unknown action"));
313 return LyXFunc::Unknown;
316 // Check whether we need a buffer
317 if (!lyxaction.funcHasFlag(action, LyXAction::NoBuffer)) {
318 // Yes we need a buffer, do we have one?
321 // Can we use a readonly buffer?
322 if (buf->isReadonly() &&
323 !lyxaction.funcHasFlag(action,
324 LyXAction::ReadOnly)) {
326 setErrorMessage(N_("Document is read-only"));
327 flag |= LyXFunc::Disabled;
331 setErrorMessage(N_("Command not allowed with"
332 "out any document open"));
333 flag |= LyXFunc::Disabled;
337 if (flag & LyXFunc::Disabled)
340 // I would really like to avoid having this switch and rather try to
341 // encode this in the function itself.
342 static bool noLaTeX = lyxrc.latex_command == "none";
343 bool disable = false;
346 disable = noLaTeX || lyxrc.view_dvi_command == "none";
349 disable = noLaTeX || lyxrc.view_ps_command == "none";
356 disable = noLaTeX || lyxrc.print_command == "none";
359 disable = noLaTeX || lyxrc.fax_command == "none";
362 if (argument == "latex")
363 disable = lyxrc.relyx_command == "none";
364 if (argument == "linuxdoc")
365 disable = lyxrc.linuxdoc_to_lyx_command == "none";
368 if (argument == "dvi" || argument == "postscript")
370 if (argument == "html")
371 disable = lyxrc.html_command == "none";
372 if (argument == "html-linuxdoc")
373 disable = lyxrc.linuxdoc_to_html_command == "none";
374 if (argument == "html-docbook")
375 disable = lyxrc.docbook_to_html_command == "none";
378 disable = buf->undostack.empty();
381 disable = buf->redostack.empty();
383 case LFUN_SPELLCHECK:
384 disable = lyxrc.isp_command == "none";
387 disable = lyxrc.chktex_command == "none";
389 case LFUN_LAYOUT_TABLE:
390 disable = ! owner->view()->text->cursor.par->table;
396 flag |= LyXFunc::Disabled;
399 func_status box = LyXFunc::ToggleOff;
400 LyXFont font = owner->view()->text->real_current_font;
403 if (font.emph() == LyXFont::ON)
404 box = LyXFunc::ToggleOn;
407 if (font.noun() == LyXFont::ON)
408 box = LyXFunc::ToggleOn;
411 if (font.series() == LyXFont::BOLD_SERIES)
412 box = LyXFunc::ToggleOn;
415 if (font.latex() == LyXFont::ON)
416 box = LyXFunc::ToggleOn;
429 string LyXFunc::Dispatch(string const & s)
431 // Split command string into command and argument
432 string cmd, line = frontStrip(s);
433 string arg = strip(frontStrip(split(line, cmd, ' ')));
435 return Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
439 string LyXFunc::Dispatch(int ac,
440 char const * do_not_use_this_arg)
445 // we have not done anything wrong yet.
447 dispatch_buffer.clear();
449 // if action is a pseudo-action, we need the real action
450 if (lyxaction.isPseudoAction(ac)) {
452 action = static_cast<kb_action>
453 (lyxaction.retrieveActionArg(ac, tmparg));
457 action = static_cast<kb_action>(ac);
458 if (do_not_use_this_arg)
459 argument = do_not_use_this_arg; // except here
462 selection_possible = false;
464 if (owner->view()->available())
465 owner->view()->hideCursor();
467 // We cannot use this function here
468 if (getStatus(action) & Disabled)
469 goto exit_with_message;
471 commandshortcut.clear();
473 if (lyxrc.display_shortcuts && show_sc) {
474 if (action != LFUN_SELFINSERT) {
475 // Put name of command and list of shortcuts
476 // for it in minibuffer
477 string comname = lyxaction.getActionName(action);
479 int pseudoaction = action;
480 bool argsadded = false;
482 if (!argument.empty()) {
483 // If we have the command with argument,
486 lyxaction.searchActionArg(action,
489 if (pseudoaction == -1) {
490 pseudoaction = action;
492 comname += " " + argument;
497 string shortcuts = toplevel_keymap->findbinding(pseudoaction);
499 if (!shortcuts.empty()) {
500 comname += ": " + shortcuts;
501 } else if (!argsadded) {
502 comname += " " + argument;
505 if (!comname.empty()) {
506 comname = strip(comname);
507 commandshortcut = "(" + comname + ')';
508 owner->getMiniBuffer()->Set(commandshortcut);
509 // Here we could even add a small pause,
510 // to annoy the user and make him learn
512 // No! That will just annoy, not teach
513 // anything. The user will read the messages
514 // if they are interested. (Asger)
519 // If in math mode pass the control to
520 // the math inset [asierra060396]
521 if (owner->view()->available() &&
522 owner->view()->the_locking_inset) {
524 || (action == LFUN_UNKNOWN_ACTION
525 && keyseq.length >= -1)) {
526 if (action == LFUN_UNKNOWN_ACTION
527 && argument.empty()) {
528 argument = keyseq.getiso();
530 // Undo/Redo pre 0.13 is a bit tricky for insets.
531 if (action == LFUN_UNDO) {
533 UpdatableInset * inset =
534 owner->view()->the_locking_inset;
535 inset->GetCursorPos(slx, sly);
536 owner->view()->unlockInset(inset);
537 owner->view()->menuUndo();
538 if (owner->view()->text->cursor.par->
539 IsInset(owner->view()->text->cursor.pos)) {
540 inset = static_cast<UpdatableInset*>(
541 owner->view()->text->cursor.par->
542 GetInset(owner->view()->text->
548 inset->Edit(owner->view(),slx,sly,0);
550 } else if (action == LFUN_REDO) {
552 UpdatableInset * inset = owner->view()->
554 inset->GetCursorPos(slx, sly);
555 owner->view()->unlockInset(inset);
556 owner->view()->menuRedo();
557 inset = static_cast<UpdatableInset*>(
558 owner->view()->text->cursor.par->
559 GetInset(owner->view()->text->
562 inset->Edit(owner->view(),slx,sly,0);
564 } else if (owner->view()->the_locking_inset->
565 LocalDispatch(owner->view(), action,
567 UpdatableInset::DISPATCHED)
570 setMessage(N_("Text mode"));
571 LyXDirection direction = owner->view()->text->
572 cursor.par->getParDirection();
574 case LFUN_UNKNOWN_ACTION:
575 case LFUN_BREAKPARAGRAPH:
577 owner->view()->text->CursorRight();
578 owner->view()->setState();
579 owner->getMiniBuffer()->Set(CurrentState());
582 if (direction == LYX_DIR_LEFT_TO_RIGHT) {
583 owner->view()->text->CursorRight();
584 moveCursorUpdate(false);
585 owner->getMiniBuffer()->
590 if (direction == LYX_DIR_RIGHT_TO_LEFT) {
591 owner->view()->text->CursorRight();
592 moveCursorUpdate(false);
593 owner->getMiniBuffer()->
605 // --- Misc -------------------------------------------
606 case LFUN_WORDFINDFORWARD :
607 case LFUN_WORDFINDBACKWARD : {
608 static string last_search;
609 string searched_string;
611 if (!argument.empty()) {
612 last_search = argument;
613 searched_string = argument;
615 searched_string = last_search;
618 LyXText * ltCur = owner->view()->text ;
620 if (!searched_string.empty() &&
621 ((action == LFUN_WORDFINDBACKWARD) ?
622 ltCur->SearchBackward(searched_string.c_str()) :
623 ltCur->SearchForward(searched_string.c_str()))) {
625 // ??? What is that ???
626 owner->view()->update(-2);
629 // clear the selection (if there is any)
630 owner->view()->toggleSelection();
631 owner->view()->text->ClearSelection();
633 // Move cursor so that successive C-s 's will not stand in place.
634 if( action == LFUN_WORDFINDFORWARD )
635 owner->view()->text->CursorRightOneWord();
636 owner->view()->text->FinishUndo();
637 moveCursorUpdate(false);
640 // set the new selection
641 // SetSelectionOverLenChars(owner->view()->currentBuffer()->text, iLenSelected);
642 owner->view()->toggleSelection(false);
646 // REMOVED : if (owner->view()->getWorkArea()->focus)
647 owner->view()->showCursor();
653 if (owner->view()->available()) {
654 owner->view()->update(-2);
657 keyseq.print(buf, true);
658 owner->getMiniBuffer()->Set(buf, string(), string(), 1);
662 // --- Misc -------------------------------------------
663 case LFUN_EXEC_COMMAND:
664 owner->getMiniBuffer()->ExecCommand();
667 case LFUN_CANCEL: // RVDK_PATCH_5
670 if(owner->view()->available())
671 // cancel any selection
672 Dispatch(LFUN_MARK_OFF, 0);
673 setMessage(N_("Cancel"));
676 case LFUN_META_FAKE: // RVDK_PATCH_5
678 meta_fake_bit = Mod1Mask;
680 keyseq.print(buf, true);
681 string res = string("M-") + buf;
682 setMessage(buf); // RVDK_PATCH_5
686 case LFUN_READ_ONLY_TOGGLE:
687 if (owner->buffer()->lyxvc.inUse()) {
688 owner->buffer()->lyxvc.toggleReadOnly();
690 owner->buffer()->setReadonly(
691 !owner->buffer()->isReadonly());
695 case LFUN_CENTER: // this is center and redraw.
696 owner->view()->center();
700 if (owner->view()->available()) {
701 owner->view()->text->toggleAppendix();
702 owner->view()->update(1);
706 // --- Menus -----------------------------------------------
711 case LFUN_MENUNEWTMPLT:
719 case LFUN_CLOSEBUFFER:
724 owner->getMiniBuffer()->Set(_("Saving document"),
725 MakeDisplayPath(owner->buffer()->fileName()),
727 MenuWrite(owner->buffer());
728 //owner->getMiniBuffer()->
729 // Set(_("Document saved as"),
730 // MakeDisplayPath(owner->buffer()->fileName()));
732 //owner->getMiniBuffer()->Set(_("Save failed!"));
736 case LFUN_MENUWRITEAS:
737 MenuWriteAs(owner->buffer());
740 case LFUN_MENURELOAD:
745 PreviewDVI(owner->buffer());
749 PreviewPostscript(owner->buffer());
753 MenuRunLaTeX(owner->buffer());
757 MenuBuildProg(owner->buffer());
761 MenuRunChktex(owner->buffer());
765 CreatePostscript(owner->buffer(), false);
769 MenuPrint(owner->buffer());
773 MenuFax(owner->buffer());
777 MenuExport(owner->buffer(), argument);
782 //needs argument as string
783 string imtyp = argument;
786 if (imtyp == "latex") {
787 doImportLaTeX(false);
790 else if (imtyp == "ascii") {
791 doImportASCII(false);
792 } else if (imtyp == "asciiparagraph") {
795 } else if (imtyp == "noweb") {
797 } else if (imtyp == "linuxdoc") {
800 setErrorMessage(string(N_("Unknown import type: "))
812 if (fd_form_toc->form_toc->visible) {
813 fl_raise_form(fd_form_toc->form_toc);
815 static int ow = -1, oh;
816 fl_show_form(fd_form_toc->form_toc,
818 FL_FREE_SIZE, FL_FULLBORDER,
819 _("Table of Contents"));
821 ow = fd_form_toc->form_toc->w;
822 oh = fd_form_toc->form_toc->h;
824 fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
828 case LFUN_TOC_INSERT:
830 Inset * new_inset = new InsetTOC(owner->buffer());
831 owner->view()->insertInset(new_inset, "Standard", true);
835 case LFUN_LOF_INSERT:
837 Inset * new_inset = new InsetLOF(owner->buffer());
838 owner->view()->insertInset(new_inset, "Standard", true);
842 case LFUN_LOA_INSERT:
844 Inset * new_inset = new InsetLOA(owner->buffer());
845 owner->view()->insertInset(new_inset, "Standard", true);
849 case LFUN_LOT_INSERT:
851 Inset * new_inset = new InsetLOT(owner->buffer());
852 owner->view()->insertInset(new_inset, "Standard", true);
864 case LFUN_INSERT_GRAPHICS:
866 Inset * new_inset = new InsetGraphics;
867 owner->view()->insertInset(new_inset);
876 owner->view()->menuUndo();
880 owner->view()->menuRedo();
883 case LFUN_MENUSEARCH:
885 // Ok this is one _very_ bad solution, but I think that some
886 // of this will be rewritten as part of GUI indep anyway.
888 static LyXFindReplace FR_;
889 FR_.StartSearch(owner->view());
895 owner->view()->paste();
896 owner->view()->setState();
899 case LFUN_PASTESELECTION:
902 if (argument == "paragraph") asPara = true;
903 MenuPasteSelection(asPara);
908 owner->view()->cut();
912 owner->view()->copy();
915 case LFUN_LAYOUT_COPY:
916 owner->view()->copyEnvironment();
919 case LFUN_LAYOUT_PASTE:
920 owner->view()->pasteEnvironment();
921 owner->view()->setState();
925 owner->view()->gotoError();
928 case LFUN_REMOVEERRORS:
929 if (owner->view()->removeAutoInsets()) {
930 owner->view()->redraw();
931 owner->view()->fitCursor();
932 owner->view()->updateScrollbar();
937 owner->view()->gotoNote();
941 owner->view()->openStuff();
944 case LFUN_HYPHENATION:
945 owner->view()->hyphenationPoint();
949 owner->view()->ldots();
952 case LFUN_END_OF_SENTENCE:
953 owner->view()->endOfSentenceDot();
956 case LFUN_MENU_SEPARATOR:
957 owner->view()->menuSeparator();
961 owner->view()->hfill();
965 changeDepth(owner->view(), 0);
969 changeDepth(owner->view(), -1);
972 case LFUN_DEPTH_PLUS:
973 changeDepth(owner->view(), 1);
982 owner->view()->setState();
983 owner->getMiniBuffer()->Set(CurrentState());
990 case LFUN_RECONFIGURE:
991 Reconfigure(owner->view());
995 if (owner->view()->available()
996 && !owner->view()->text->selection
997 && owner->view()->text->cursor.par->footnoteflag
998 != LyXParagraph::NO_FOOTNOTE)
999 { // only melt footnotes with FOOTMELT, not margins etc
1000 if(owner->view()->text->cursor.par->footnotekind == LyXParagraph::FOOTNOTE)
1001 Melt(owner->view());
1004 Foot(owner->view());
1005 owner->view()->setState();
1008 case LFUN_MARGINMELT:
1009 if (owner->view()->available()
1010 && !owner->view()->text->selection
1011 && owner->view()->text->cursor.par->footnoteflag
1012 != LyXParagraph::NO_FOOTNOTE) {
1013 // only melt margins
1014 if(owner->view()->text->cursor.par->footnotekind == LyXParagraph::MARGIN)
1015 Melt(owner->view());
1017 Margin(owner->view());
1018 owner->view()->setState();
1021 // --- version control -------------------------------
1022 case LFUN_VC_REGISTER:
1024 if (!owner->buffer()->lyxvc.inUse())
1025 owner->buffer()->lyxvc.registrer();
1029 case LFUN_VC_CHECKIN:
1031 if (owner->buffer()->lyxvc.inUse()
1032 && !owner->buffer()->isReadonly())
1033 owner->buffer()->lyxvc.checkIn();
1037 case LFUN_VC_CHECKOUT:
1039 if (owner->buffer()->lyxvc.inUse()
1040 && owner->buffer()->isReadonly())
1041 owner->buffer()->lyxvc.checkOut();
1045 case LFUN_VC_REVERT:
1047 owner->buffer()->lyxvc.revert();
1053 owner->buffer()->lyxvc.undoLast();
1057 case LFUN_VC_HISTORY:
1059 owner->buffer()->lyxvc.showLog();
1063 // --- buffers ----------------------------------------
1065 case LFUN_FILE_INSERT:
1067 MenuInsertLyXFile(argument);
1071 case LFUN_FILE_INSERT_ASCII:
1073 bool asPara = (argument == "paragraph");
1074 InsertAsciiFile(owner->view(), string(), asPara);
1080 // servercmd: argument must be <file>:<template>
1081 Buffer * tmpbuf = NewLyxFile(argument);
1083 owner->view()->buffer(tmpbuf);
1087 case LFUN_FILE_OPEN:
1088 owner->view()->buffer(bufferlist.loadLyXFile(argument));
1091 case LFUN_LATEX_LOG:
1097 lyxerr.debug() << "LFUN_LAYOUTNO: (arg) " << argument << endl;
1098 int sel = strToInt(argument);
1099 lyxerr.debug() << "LFUN_LAYOUTNO: (sel) "<< sel << endl;
1101 // Should this give a setMessage instead?
1103 return string(); // illegal argument
1105 --sel; // sel 1..., but layout 0...
1107 // Pretend we got the name instead.
1108 Dispatch(int(LFUN_LAYOUT),
1109 textclasslist.NameOfLayout(owner->view()->
1118 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1119 << argument << endl;
1121 // Derive layout number from given argument (string)
1122 // and current buffer's textclass (number). */
1123 LyXTextClassList::ClassList::size_type tclass =
1124 owner->view()->text->parameters->textclass;
1125 pair <bool, LyXTextClass::size_type> layout =
1126 textclasslist.NumberOfLayout(tclass, argument);
1128 // If the entry is obsolete, use the new one instead.
1130 string obs = textclasslist.Style(tclass,layout.second)
1134 textclasslist.NumberOfLayout(tclass, obs);
1137 // see if we found the layout number:
1138 if (!layout.first) {
1139 setErrorMessage(string(N_("Layout ")) + argument +
1144 if (current_layout != layout.second) {
1145 owner->view()->hideCursor();
1146 current_layout = layout.second;
1147 owner->view()->update(-2);
1148 owner->view()->text->
1149 SetLayout(layout.second);
1150 owner->getToolbar()->combox->
1151 select(owner->view()->
1154 owner->view()->update(1);
1155 owner->view()->setState();
1160 case LFUN_LAYOUT_DOCUMENT:
1161 MenuLayoutDocument();
1164 case LFUN_LAYOUT_PARAGRAPH:
1165 MenuLayoutParagraph();
1168 case LFUN_LAYOUT_CHARACTER:
1169 MenuLayoutCharacter();
1172 case LFUN_LAYOUT_TABLE:
1175 if (argument == "true") flag = 1;
1176 MenuLayoutTable(flag);
1180 case LFUN_LAYOUT_PAPER:
1184 case LFUN_LAYOUT_QUOTES:
1188 case LFUN_LAYOUT_PREAMBLE:
1189 MenuLayoutPreamble();
1192 case LFUN_LAYOUT_SAVE_DEFAULT:
1196 case LFUN_DROP_LAYOUTS_CHOICE:
1197 owner->getToolbar()->combox->Show();
1203 owner->view()->setState();
1204 owner->getMiniBuffer()->Set(CurrentState());
1236 case LFUN_UNDERLINE:
1240 case LFUN_FONT_SIZE:
1244 case LFUN_FONT_STATE:
1245 setMessage(CurrentState());
1248 case LFUN_UPCASE_WORD:
1249 owner->view()->update(-2);
1251 owner->view()->text->ChangeWordCase(LyXText::text_uppercase);
1252 owner->view()->update(1);
1256 case LFUN_LOWCASE_WORD:
1257 owner->view()->update(-2);
1259 owner->view()->text->ChangeWordCase(LyXText::text_lowercase);
1260 owner->view()->update(1);
1264 case LFUN_CAPITALIZE_WORD:
1265 owner->view()->update(-2);
1267 owner->view()->text->ChangeWordCase(LyXText::text_capitalization);
1268 owner->view()->update(1);
1272 case LFUN_INSERT_LABEL:
1273 MenuInsertLabel(argument.c_str());
1276 case LFUN_INSERT_REF:
1280 case LFUN_REFTOGGLE:
1283 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1285 if (inset->getFlag() == InsetRef::REF)
1286 inset->setFlag(InsetRef::PAGE_REF);
1288 inset->setFlag(InsetRef::REF);
1289 owner->view()->updateInset(inset, true);
1291 setErrorMessage(N_("No cross-reference to toggle"));
1298 owner->view()->restorePosition();
1304 string label(argument);
1305 if (label.empty()) {
1307 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1309 label = inset->getContents();
1312 if (!label.empty()) {
1313 owner->view()->savePosition();
1314 owner->view()->gotoLabel(label.c_str());
1319 case LFUN_MENU_OPEN_BY_NAME:
1320 owner->getMenus()->openByName(argument);
1321 break; // RVDK_PATCH_5
1323 case LFUN_SPELLCHECK:
1324 if (lyxrc.isp_command != "none")
1325 ShowSpellChecker(owner->view());
1326 break; // RVDK_PATCH_5
1328 // --- Cursor Movements -----------------------------
1331 LyXText * tmptext = owner->view()->text;
1332 LyXDirection direction =
1333 tmptext->cursor.par->getParDirection();
1334 if(!tmptext->mark_set)
1335 owner->view()->beforeChange();
1336 owner->view()->update(-2);
1337 if (direction == LYX_DIR_RIGHT_TO_LEFT)
1338 tmptext->CursorLeft();
1339 if (tmptext->cursor.pos < tmptext->cursor.par->Last()
1340 && tmptext->cursor.par->GetChar(tmptext->cursor.pos)
1341 == LyXParagraph::META_INSET
1342 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)
1343 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)->Editable() == Inset::HIGHLY_EDITABLE){
1344 Inset * tmpinset = tmptext->cursor.par->GetInset(tmptext->cursor.pos);
1345 setMessage(tmpinset->EditMessage());
1346 tmpinset->Edit(owner->view(), 0, 0, 0);
1349 if (direction == LYX_DIR_LEFT_TO_RIGHT)
1350 tmptext->CursorRight();
1351 owner->view()->text->FinishUndo();
1352 moveCursorUpdate(false);
1353 owner->getMiniBuffer()->Set(CurrentState());
1359 // This is soooo ugly. Isn`t it possible to make
1360 // it simpler? (Lgb)
1361 LyXText * txt = owner->view()->text;
1362 LyXDirection direction = txt->cursor.par->getParDirection();
1363 if(!txt->mark_set) owner->view()->beforeChange();
1364 owner->view()->update(-2);
1365 if (direction == LYX_DIR_LEFT_TO_RIGHT)
1367 if (txt->cursor.pos < txt->cursor.par->Last()
1368 && txt->cursor.par->GetChar(txt->cursor.pos)
1369 == LyXParagraph::META_INSET
1370 && txt->cursor.par->GetInset(txt->cursor.pos)
1371 && txt->cursor.par->GetInset(txt->cursor.pos)->Editable() == Inset::HIGHLY_EDITABLE) {
1372 Inset * tmpinset = txt->cursor.par->GetInset(txt->cursor.pos);
1373 setMessage(tmpinset->EditMessage());
1374 tmpinset->Edit(owner->view(),
1375 tmpinset->width(owner->view()->painter(),
1376 txt->GetFont(txt->cursor.par,
1381 if (direction == LYX_DIR_RIGHT_TO_LEFT)
1384 owner->view()->text->FinishUndo();
1385 moveCursorUpdate(false);
1386 owner->getMiniBuffer()->Set(CurrentState());
1391 if(!owner->view()->text->mark_set) owner->view()->beforeChange();
1392 owner->view()->update(-3);
1393 owner->view()->text->CursorUp();
1394 owner->view()->text->FinishUndo();
1395 moveCursorUpdate(false);
1396 owner->getMiniBuffer()->Set(CurrentState());
1400 if(!owner->view()->text->mark_set)
1401 owner->view()->beforeChange();
1402 owner->view()->update(-3);
1403 owner->view()->text->CursorDown();
1404 owner->view()->text->FinishUndo();
1405 moveCursorUpdate(false);
1406 owner->getMiniBuffer()->Set(CurrentState());
1409 case LFUN_UP_PARAGRAPH:
1410 if(!owner->view()->text->mark_set)
1411 owner->view()->beforeChange();
1412 owner->view()->update(-3);
1413 owner->view()->text->CursorUpParagraph();
1414 owner->view()->text->FinishUndo();
1415 moveCursorUpdate(false);
1416 owner->getMiniBuffer()->Set(CurrentState());
1419 case LFUN_DOWN_PARAGRAPH:
1420 if(!owner->view()->text->mark_set)
1421 owner->view()->beforeChange();
1422 owner->view()->update(-3);
1423 owner->view()->text->CursorDownParagraph();
1424 owner->view()->text->FinishUndo();
1425 moveCursorUpdate(false);
1426 owner->getMiniBuffer()->Set(CurrentState());
1430 if(!owner->view()->text->mark_set)
1431 owner->view()->beforeChange();
1432 owner->view()->update(-3);
1433 owner->view()->cursorPrevious();
1434 owner->view()->text->FinishUndo();
1435 moveCursorUpdate(false);
1436 owner->getMiniBuffer()->Set(CurrentState());
1440 if(!owner->view()->text->mark_set)
1441 owner->view()->beforeChange();
1442 owner->view()->update(-3);
1443 owner->view()->cursorNext();
1444 owner->view()->text->FinishUndo();
1445 moveCursorUpdate(false);
1446 owner->getMiniBuffer()->Set(CurrentState());
1450 if(!owner->view()->text->mark_set)
1451 owner->view()->beforeChange();
1452 owner->view()->update(-2);
1453 owner->view()->text->CursorHome();
1454 owner->view()->text->FinishUndo();
1455 moveCursorUpdate(false);
1456 owner->getMiniBuffer()->Set(CurrentState());
1460 if(!owner->view()->text->mark_set)
1461 owner->view()->beforeChange();
1462 owner->view()->update(-2);
1463 owner->view()->text->CursorEnd();
1464 owner->view()->text->FinishUndo();
1465 moveCursorUpdate(false);
1466 owner->getMiniBuffer()->Set(CurrentState());
1470 if(!owner->view()->text->mark_set)
1471 owner->view()->beforeChange();
1472 owner->view()->update(-2);
1473 owner->view()->text->CursorTab();
1474 owner->view()->text->FinishUndo();
1475 moveCursorUpdate(false);
1476 owner->getMiniBuffer()->Set(CurrentState());
1479 case LFUN_WORDRIGHT:
1480 if(!owner->view()->text->mark_set)
1481 owner->view()->beforeChange();
1482 owner->view()->update(-2);
1483 if (owner->view()->text->cursor.par->getParDirection()
1484 == LYX_DIR_LEFT_TO_RIGHT)
1485 owner->view()->text->CursorRightOneWord();
1487 owner->view()->text->CursorLeftOneWord();
1488 owner->view()->text->FinishUndo();
1489 moveCursorUpdate(false);
1490 owner->getMiniBuffer()->Set(CurrentState());
1494 if(!owner->view()->text->mark_set)
1495 owner->view()->beforeChange();
1496 owner->view()->update(-2);
1497 if (owner->view()->text->cursor.par->getParDirection()
1498 == LYX_DIR_LEFT_TO_RIGHT)
1499 owner->view()->text->CursorLeftOneWord();
1501 owner->view()->text->CursorRightOneWord();
1502 owner->view()->text->FinishUndo();
1503 moveCursorUpdate(false);
1504 owner->getMiniBuffer()->Set(CurrentState());
1507 case LFUN_BEGINNINGBUF:
1508 if(!owner->view()->text->mark_set)
1509 owner->view()->beforeChange();
1510 owner->view()->update(-2);
1511 owner->view()->text->CursorTop();
1512 owner->view()->text->FinishUndo();
1513 moveCursorUpdate(false);
1514 owner->getMiniBuffer()->Set(CurrentState());
1518 if(!owner->view()->text->mark_set)
1519 owner->view()->beforeChange();
1520 owner->view()->update(-2);
1521 owner->view()->text->CursorBottom();
1522 owner->view()->text->FinishUndo();
1523 moveCursorUpdate(false);
1524 owner->getMiniBuffer()->Set(CurrentState());
1528 /* cursor selection ---------------------------- */
1530 owner->view()->update(-2);
1531 if (owner->view()->text->cursor.par->getParDirection()
1532 == LYX_DIR_LEFT_TO_RIGHT)
1533 owner->view()->text->CursorRight();
1535 owner->view()->text->CursorLeft();
1536 owner->view()->text->FinishUndo();
1537 moveCursorUpdate(true);
1538 owner->getMiniBuffer()->Set(CurrentState());
1542 owner->view()->update(-2);
1543 if (owner->view()->text->cursor.par->getParDirection()
1544 == LYX_DIR_LEFT_TO_RIGHT)
1545 owner->view()->text->CursorLeft();
1547 owner->view()->text->CursorRight();
1548 owner->view()->text->FinishUndo();
1549 moveCursorUpdate(true);
1550 owner->getMiniBuffer()->Set(CurrentState());
1554 owner->view()->update(-2);
1555 owner->view()->text->CursorUp();
1556 owner->view()->text->FinishUndo();
1557 moveCursorUpdate(true);
1558 owner->getMiniBuffer()->Set(CurrentState());
1562 owner->view()->update(-2);
1563 owner->view()->text->CursorDown();
1564 owner->view()->text->FinishUndo();
1565 moveCursorUpdate(true);
1566 owner->getMiniBuffer()->Set(CurrentState());
1569 case LFUN_UP_PARAGRAPHSEL:
1570 owner->view()->update(-2);
1571 owner->view()->text->CursorUpParagraph();
1572 owner->view()->text->FinishUndo();
1573 moveCursorUpdate(true);
1574 owner->getMiniBuffer()->Set(CurrentState());
1577 case LFUN_DOWN_PARAGRAPHSEL:
1578 owner->view()->update(-2);
1579 owner->view()->text->CursorDownParagraph();
1580 owner->view()->text->FinishUndo();
1581 moveCursorUpdate(true);
1582 owner->getMiniBuffer()->Set(CurrentState());
1586 owner->view()->update(-2);
1587 owner->view()->cursorPrevious();
1588 owner->view()->text->FinishUndo();
1589 moveCursorUpdate(true);
1590 owner->getMiniBuffer()->Set(CurrentState());
1594 owner->view()->update(-2);
1595 owner->view()->cursorNext();
1596 owner->view()->text->FinishUndo();
1597 moveCursorUpdate(true);
1598 owner->getMiniBuffer()->Set(CurrentState());
1602 owner->view()->update(-2);
1603 owner->view()->text->CursorHome();
1604 owner->view()->text->FinishUndo();
1605 moveCursorUpdate(true);
1606 owner->getMiniBuffer()->Set(CurrentState());
1610 owner->view()->update(-2);
1611 owner->view()->text->CursorEnd();
1612 owner->view()->text->FinishUndo();
1613 moveCursorUpdate(true);
1614 owner->getMiniBuffer()->Set(CurrentState());
1617 case LFUN_WORDRIGHTSEL:
1618 owner->view()->update(-2);
1619 if (owner->view()->text->cursor.par->getParDirection()
1620 == LYX_DIR_LEFT_TO_RIGHT)
1621 owner->view()->text->CursorRightOneWord();
1623 owner->view()->text->CursorLeftOneWord();
1624 owner->view()->text->FinishUndo();
1625 moveCursorUpdate(true);
1626 owner->getMiniBuffer()->Set(CurrentState());
1629 case LFUN_WORDLEFTSEL:
1630 owner->view()->update(-2);
1631 if (owner->view()->text->cursor.par->getParDirection()
1632 == LYX_DIR_LEFT_TO_RIGHT)
1633 owner->view()->text->CursorLeftOneWord();
1635 owner->view()->text->CursorRightOneWord();
1636 owner->view()->text->FinishUndo();
1637 moveCursorUpdate(true);
1638 owner->getMiniBuffer()->Set(CurrentState());
1641 case LFUN_BEGINNINGBUFSEL:
1642 owner->view()->update(-2);
1643 owner->view()->text->CursorTop();
1644 owner->view()->text->FinishUndo();
1645 moveCursorUpdate(true);
1646 owner->getMiniBuffer()->Set(CurrentState());
1649 case LFUN_ENDBUFSEL:
1650 owner->view()->update(-2);
1651 owner->view()->text->CursorBottom();
1652 owner->view()->text->FinishUndo();
1653 moveCursorUpdate(true);
1654 owner->getMiniBuffer()->Set(CurrentState());
1657 // --- text changing commands ------------------------
1658 case LFUN_BREAKLINE:
1660 owner->view()->beforeChange();
1661 owner->view()->text->InsertChar(LyXParagraph::META_NEWLINE);
1662 owner->view()->smallUpdate(1);
1663 SetUpdateTimer(0.01);
1664 moveCursorUpdate(false);
1666 owner->view()->newline();
1670 case LFUN_PROTECTEDSPACE:
1673 LyXLayout const & style =
1674 textclasslist.Style(owner->view()->buffer()->params.textclass,
1675 owner->view()->text->cursor.par->GetLayout());
1677 if (style.free_spacing) {
1678 owner->view()->text->InsertChar(' ');
1679 owner->view()->update(-1);
1681 owner->view()->protectedBlank();
1683 moveCursorUpdate(false);
1686 owner->view()->beforeChange();
1687 owner->view()->text->
1688 InsertChar(LyXParagraph::META_PROTECTED_SEPARATOR);
1689 owner->view()->smallUpdate(1);
1691 moveCursorUpdate(false);
1696 if(owner->view()->text->mark_set) {
1697 owner->view()->beforeChange();
1698 owner->view()->update(0);
1699 setMessage(N_("Mark removed"));
1701 owner->view()->beforeChange();
1702 owner->view()->text->mark_set = 1;
1703 owner->view()->update(0);
1704 setMessage(N_("Mark set"));
1706 owner->view()->text->sel_cursor =
1707 owner->view()->text->cursor;
1712 if (!owner->view()->text->selection) {
1713 owner->view()->text->Delete();
1714 owner->view()->text->sel_cursor =
1715 owner->view()->text->cursor;
1716 owner->view()->smallUpdate(1);
1717 // It is possible to make it a lot faster still
1718 // just comment out the lone below...
1719 owner->view()->showCursor();
1721 owner->view()->cut();
1724 moveCursorUpdate(false);
1725 owner->getMiniBuffer()->Set(CurrentState());
1726 owner->view()->setState();
1729 case LFUN_DELETE_SKIP:
1731 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1733 LyXCursor cursor = owner->view()->text->cursor;
1736 if (!owner->view()->text->selection) {
1737 if (cursor.pos == cursor.par->Last()) {
1738 owner->view()->text->CursorRight();
1739 cursor = owner->view()->text->cursor;
1741 && !(cursor.par->added_space_top
1742 == VSpace (VSpace::NONE))) {
1743 owner->view()->text->SetParagraph
1744 (cursor.par->line_top,
1745 cursor.par->line_bottom,
1746 cursor.par->pagebreak_top,
1747 cursor.par->pagebreak_bottom,
1748 VSpace(VSpace::NONE),
1749 cursor.par->added_space_bottom,
1751 cursor.par->labelwidthstring, 0);
1752 owner->view()->text->CursorLeft();
1753 owner->view()->update (1);
1755 owner->view()->text->CursorLeft();
1756 owner->view()->text->Delete();
1757 owner->view()->text->sel_cursor =
1758 owner->view()->text->cursor;
1759 owner->view()->smallUpdate(1);
1762 owner->view()->text->Delete();
1763 owner->view()->text->sel_cursor =
1764 owner->view()->text->cursor;
1765 owner->view()->smallUpdate(1);
1768 owner->view()->cut();
1774 /* -------> Delete word forward. */
1775 case LFUN_DELETE_WORD_FORWARD:
1776 owner->view()->update(-2);
1778 owner->view()->text->DeleteWordForward();
1779 owner->view()->update( 1 );
1781 moveCursorUpdate(false);
1782 owner->getMiniBuffer()->Set(CurrentState());
1785 /* -------> Delete word backward. */
1786 case LFUN_DELETE_WORD_BACKWARD:
1787 owner->view()->update(-2);
1789 owner->view()->text->DeleteWordBackward();
1790 owner->view()->update( 1 );
1792 moveCursorUpdate(false);
1793 owner->getMiniBuffer()->Set(CurrentState());
1796 /* -------> Kill to end of line. */
1797 case LFUN_DELETE_LINE_FORWARD:
1799 owner->view()->update(-2);
1800 owner->view()->text->DeleteLineForward();
1801 owner->view()->update( 1 );
1803 moveCursorUpdate(false);
1806 /* -------> Set mark off. */
1808 owner->view()->beforeChange();
1809 owner->view()->update(0);
1810 owner->view()->text->sel_cursor =
1811 owner->view()->text->cursor;
1812 setMessage(N_("Mark off"));
1815 /* -------> Set mark on. */
1817 owner->view()->beforeChange();
1818 owner->view()->text->mark_set = 1;
1819 owner->view()->update( 0 );
1820 owner->view()->text->sel_cursor =
1821 owner->view()->text->cursor;
1822 setMessage(N_("Mark on"));
1825 case LFUN_BACKSPACE:
1828 if (!owner->view()->text->selection) {
1829 if (owner->getIntl()->getTrans()->backspace()) {
1830 owner->view()->text->Backspace();
1831 owner->view()->text->sel_cursor =
1832 owner->view()->text->cursor;
1833 owner->view()->smallUpdate(1);
1834 // It is possible to make it a lot faster still
1835 // just comment out the lone below...
1836 owner->view()->showCursor();
1839 owner->view()->cut();
1842 owner->getMiniBuffer()->Set(CurrentState());
1843 owner->view()->setState();
1847 case LFUN_BACKSPACE_SKIP:
1849 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1851 LyXCursor cursor = owner->view()->text->cursor;
1854 if (!owner->view()->text->selection) {
1856 && !(cursor.par->added_space_top
1857 == VSpace (VSpace::NONE))) {
1858 owner->view()->text->SetParagraph
1859 (cursor.par->line_top,
1860 cursor.par->line_bottom,
1861 cursor.par->pagebreak_top,
1862 cursor.par->pagebreak_bottom,
1863 VSpace(VSpace::NONE), cursor.par->added_space_bottom,
1865 cursor.par->labelwidthstring, 0);
1866 owner->view()->update (1);
1868 owner->view()->text->Backspace();
1869 owner->view()->text->sel_cursor
1871 owner->view()->smallUpdate (1);
1874 owner->view()->cut();
1879 case LFUN_BREAKPARAGRAPH:
1881 owner->view()->beforeChange();
1882 owner->view()->text->BreakParagraph(0);
1883 owner->view()->smallUpdate(1);
1884 SetUpdateTimer(0.01);
1885 owner->view()->text->sel_cursor =
1886 owner->view()->text->cursor;
1887 owner->view()->setState();
1888 owner->getMiniBuffer()->Set(CurrentState());
1892 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1894 owner->view()->beforeChange();
1895 owner->view()->text->BreakParagraph(1);
1896 owner->view()->smallUpdate(1);
1897 SetUpdateTimer(0.01);
1898 owner->view()->text->sel_cursor =
1899 owner->view()->text->cursor;
1900 owner->view()->setState();
1901 owner->getMiniBuffer()->Set(CurrentState());
1905 case LFUN_BREAKPARAGRAPH_SKIP:
1907 // When at the beginning of a paragraph, remove
1908 // indentation and add a "defskip" at the top.
1909 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
1911 LyXCursor cursor = owner->view()->text->cursor;
1913 owner->view()->beforeChange();
1914 if (cursor.pos == 0) {
1915 if (cursor.par->added_space_top == VSpace(VSpace::NONE)) {
1916 owner->view()->text->SetParagraph
1917 (cursor.par->line_top,
1918 cursor.par->line_bottom,
1919 cursor.par->pagebreak_top,
1920 cursor.par->pagebreak_bottom,
1921 VSpace(VSpace::DEFSKIP), cursor.par->added_space_bottom,
1923 cursor.par->labelwidthstring, 1);
1924 owner->view()->update(1);
1928 owner->view()->text->BreakParagraph(0);
1929 owner->view()->smallUpdate(1);
1931 SetUpdateTimer(0.01);
1932 owner->view()->text->sel_cursor = cursor;
1933 owner->view()->setState();
1934 owner->getMiniBuffer()->Set(CurrentState());
1939 owner->view()->beforeChange();
1940 owner->view()->text->InsertChar('\"'); // This " matches the single quote in the code
1941 owner->view()->smallUpdate(1);
1943 moveCursorUpdate(false);
1949 InsetCommand * new_inset;
1950 if (action == LFUN_HTMLURL)
1951 new_inset = new InsetUrl("htmlurl", "", "");
1953 new_inset = new InsetUrl("url", "", "");
1954 owner->view()->insertInset(new_inset);
1955 new_inset->Edit(owner->view(), 0, 0, 0);
1958 case LFUN_INSET_TEXT:
1960 InsetText * new_inset = new InsetText(owner->buffer());
1961 owner->view()->insertInset(new_inset);
1962 new_inset->Edit(owner->view(), 0, 0, 0);
1966 case LFUN_INSET_NUMBER:
1968 InsetNumber * new_inset = new InsetNumber(owner->buffer());
1969 owner->view()->insertInset(new_inset);
1970 new_inset->Edit(owner->view(), 0, 0, 0);
1974 case LFUN_INSET_ERT:
1976 InsetERT * new_inset = new InsetERT(owner->buffer());
1977 owner->view()->insertInset(new_inset);
1978 new_inset->Edit(owner->view(), 0, 0, 0);
1981 case LFUN_INSET_FOOTNOTE:
1983 InsetFoot * new_inset = new InsetFoot(owner->buffer());
1984 owner->view()->insertInset(new_inset);
1985 new_inset->Edit(owner->view(), 0, 0, 0);
1989 // --- lyxserver commands ----------------------------
1991 case LFUN_CHARATCURSOR:
1993 LyXParagraph::size_type pos =
1994 owner->view()->text->cursor.pos;
1995 if(pos < owner->view()->text->cursor.par->size())
1996 //dispatch_buffer = owner->view()->text->
1997 // cursor.par->text[pos];
1999 owner->view()->text->
2000 cursor.par->GetChar(pos);
2002 dispatch_buffer = "EOF";
2008 tostr(owner->view()->text->cursor.x) + ' '
2009 + tostr(owner->view()->text->cursor.y);
2016 sscanf(argument.c_str(), " %d %ld", &x, &y);
2017 owner->view()->text->SetCursorFromCoordinates(x, y);
2021 case LFUN_GETLAYOUT:
2023 tostr(owner->view()->text->cursor.par->layout);
2028 LyXFont * font = &(owner->view()->text->current_font);
2029 if(font->shape() == LyXFont::ITALIC_SHAPE)
2030 dispatch_buffer = 'E';
2031 else if(font->shape() == LyXFont::SMALLCAPS_SHAPE)
2032 dispatch_buffer = 'N';
2034 dispatch_buffer = '0';
2041 LyXFont * font = &(owner->view()->text->current_font);
2042 if(font->latex() == LyXFont::ON)
2043 dispatch_buffer = 'L';
2045 dispatch_buffer = '0';
2050 setMessage(owner->buffer()->fileName());
2051 lyxerr.debug() << "FNAME["
2052 << owner->buffer()->fileName()
2060 dispatch_buffer = buf;
2061 lyxserver->notifyClient(dispatch_buffer);
2065 case LFUN_GOTOFILEROW:
2067 char file_name[100];
2069 sscanf(argument.c_str(), " %s %d", file_name, &row);
2071 // Must replace extension of the file to be .lyx and get full path
2072 string s = ChangeExtension(string(file_name), ".lyx", false);
2074 // Either change buffer or load the file
2075 if (bufferlist.exists(s))
2076 owner->view()->buffer(bufferlist.getBuffer(s));
2078 owner->view()->buffer(bufferlist.loadLyXFile(s));
2081 owner->view()->setCursorFromRow(row);
2084 owner->view()->center();
2091 int qa = lyxaction.LookupFunc(argument.c_str());
2092 setMessage(lyxaction.helpText(static_cast<kb_action>(qa)));
2096 // --- accented characters ---------------------------
2099 case LFUN_CIRCUMFLEX:
2109 case LFUN_SPECIAL_CARON:
2112 case LFUN_HUNG_UMLAUT:
2118 if (keyseq.length == -1 && keyseq.getiso() != 0)
2119 c = keyseq.getiso();
2123 owner->getIntl()->getTrans()->
2124 deadkey(c, get_accent(action).accent,
2125 owner->view()->text);
2127 // Need to reset, in case the minibuffer calls these
2132 // copied verbatim from do_accent_char
2133 owner->view()->smallUpdate(1);
2135 owner->view()->text->sel_cursor =
2136 owner->view()->text->cursor;
2140 // --- toolbar ----------------------------------
2141 case LFUN_PUSH_TOOLBAR:
2143 int nth = strToInt(argument);
2144 if (lyxerr.debugging(Debug::TOOLBAR)) {
2145 lyxerr << "LFUN_PUSH_TOOLBAR: argument = `"
2146 << argument << "'\n"
2147 << "LFUN_PUSH_TOOLBAR: nth = `"
2148 << nth << "'" << endl;
2153 setErrorMessage(N_("Push-toolbar needs argument > 0"));
2155 owner->getToolbar()->push(nth);
2160 case LFUN_ADD_TO_TOOLBAR:
2162 if (lyxerr.debugging(Debug::TOOLBAR)) {
2163 lyxerr << "LFUN_ADD_TO_TOOLBAR:"
2164 "argument = `" << argument << '\'' << endl;
2166 string tmp(argument);
2167 //lyxerr <<string("Argument: ") + argument);
2168 //lyxerr <<string("Tmp : ") + tmp);
2171 setErrorMessage(N_("Usage: toolbar-add-to <LyX command>"));
2173 owner->getToolbar()->add(argument, false);
2174 owner->getToolbar()->set();
2179 // --- insert characters ----------------------------------------
2181 // --- Mathed stuff. If we are here, there is no locked inset yet.
2186 if (!greek_kb_flag) {
2188 setMessage(N_("Math greek mode on"));
2195 case LFUN_GREEK_TOGGLE:
2197 greek_kb_flag = greek_kb_flag ? 0 : 2;
2198 if (greek_kb_flag) {
2199 setMessage(N_("Math greek keyboard on"));
2201 setMessage(N_("Math greek keyboard off"));
2206 case LFUN_MATH_DELIM:
2207 case LFUN_INSERT_MATRIX:
2209 if (owner->view()->available()) {
2211 open_new_inset(new InsetFormula(false));
2214 ->LocalDispatch(owner->view(),
2221 case LFUN_INSERT_MATH:
2223 math_insert_symbol(argument.c_str());
2227 case LFUN_MATH_DISPLAY:
2229 if (owner->view()->available())
2230 owner->view()->open_new_inset(new InsetFormula(true));
2234 case LFUN_MATH_MACRO:
2236 if (owner->view()->available()) {
2239 setErrorMessage(N_("Missing argument"));
2241 string s1 = token(s, ' ', 1);
2242 int na = s1.empty() ? 0: atoi(s1.c_str());
2244 open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2250 case LFUN_MATH_MODE: // Open or create a math inset
2253 if (owner->view()->available())
2254 owner->view()->open_new_inset(new InsetFormula);
2255 setMessage(N_("Math editor mode"));
2259 case LFUN_MATH_NUMBER:
2260 case LFUN_MATH_LIMITS:
2262 setErrorMessage(N_("This is only allowed in math mode!"));
2266 case LFUN_INSERT_CITATION:
2268 InsetCitation * new_inset = new InsetCitation();
2270 // The note, if any, must be after the key, delimited
2271 // by a | so both key and remark can have spaces.
2272 if (!argument.empty()) {
2273 string lsarg(argument);
2274 if (contains(lsarg, "|")) {
2275 new_inset->setContents(token(lsarg, '|', 0));
2276 new_inset->setOptions(token(lsarg, '|', 1));
2278 new_inset->setContents(lsarg);
2279 owner->view()->insertInset(new_inset);
2281 owner->view()->insertInset(new_inset);
2282 new_inset->Edit(owner->view(), 0, 0, 0);
2287 case LFUN_INSERT_BIBTEX:
2289 // ale970405+lasgoutt970425
2290 // The argument can be up to two tokens separated
2291 // by a space. The first one is the bibstyle.
2292 string lsarg(argument);
2293 string bibstyle = token(lsarg, ' ', 1);
2294 if (bibstyle.empty())
2296 InsetBibtex * new_inset
2297 = new InsetBibtex(token(lsarg, ' ', 0),
2301 owner->view()->insertInset(new_inset);
2302 if (lsarg.empty()) {
2303 new_inset->Edit(owner->view(), 0, 0, 0);
2308 // BibTeX data bases
2309 case LFUN_BIBDB_ADD:
2311 InsetBibtex * inset =
2312 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2314 inset->addDatabase(argument);
2319 case LFUN_BIBDB_DEL:
2321 InsetBibtex * inset =
2322 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2324 inset->delDatabase(argument);
2329 case LFUN_BIBTEX_STYLE:
2331 InsetBibtex * inset =
2332 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2334 inset->setOptions(argument);
2339 case LFUN_INDEX_INSERT:
2340 case LFUN_INDEX_INSERT_LAST:
2342 // Can't do that at the beginning of a paragraph.
2343 if (owner->view()->text->cursor.pos - 1 < 0)
2346 InsetIndex * new_inset = new InsetIndex();
2347 if (!argument.empty()) {
2348 string lsarg(argument);
2349 new_inset->setContents(lsarg);
2350 owner->view()->insertInset(new_inset);
2353 //get the current word for an argument
2354 LyXParagraph::size_type lastpos =
2355 owner->view()->text->cursor.pos - 1;
2356 // Get the current word. note that this must be done
2357 // before inserting the inset, or the inset will
2359 string curstring(owner->view()
2360 ->text->cursor.par->GetWord(lastpos));
2362 //make the new inset and write the current word into it
2363 InsetIndex * new_inset = new InsetIndex();
2365 new_inset->setContents(curstring);
2367 //don't edit it if the call was to INSERT_LAST
2368 if(action != LFUN_INDEX_INSERT_LAST) {
2369 new_inset->Edit(owner->view(), 0, 0, 0);
2371 //it looks blank on the screen unless
2372 //we do something. put it here.
2374 // move the cursor to the returned value of lastpos
2375 // but only for the auto-insert
2376 owner->view()->text->cursor.pos = lastpos;
2379 //put the new inset into the buffer.
2380 // there should be some way of knowing the user
2381 //cancelled & avoiding this, but i don't know how
2382 owner->view()->insertInset(new_inset);
2387 case LFUN_INDEX_PRINT:
2389 Inset * new_inset = new InsetPrintIndex(owner->buffer());
2390 owner->view()->insertInset(new_inset, "Standard", true);
2394 case LFUN_PARENTINSERT:
2396 lyxerr << "arg " << argument << endl;
2397 Inset * new_inset = new InsetParent(argument, owner->buffer());
2398 owner->view()->insertInset(new_inset, "Standard", true);
2402 case LFUN_CHILDINSERT:
2404 Inset * new_inset = new InsetInclude(argument,
2406 owner->view()->insertInset(new_inset, "Standard", true);
2407 new_inset->Edit(owner->view(), 0, 0, 0);
2411 case LFUN_CHILDOPEN:
2414 MakeAbsPath(argument,
2415 OnlyPath(owner->buffer()->fileName()));
2416 setMessage(N_("Opening child document ") +
2417 MakeDisplayPath(filename) + "...");
2418 owner->view()->savePosition();
2419 if (bufferlist.exists(filename))
2420 owner->view()->buffer(bufferlist.getBuffer(filename));
2422 owner->view()->buffer(bufferlist.loadLyXFile(filename));
2426 case LFUN_INSERT_NOTE:
2427 owner->view()->insertNote();
2430 case LFUN_INSERTFOOTNOTE:
2432 LyXParagraph::footnote_kind kind;
2433 if (argument == "footnote")
2434 { kind = LyXParagraph::FOOTNOTE; }
2435 else if (argument == "margin")
2436 { kind = LyXParagraph::MARGIN; }
2437 else if (argument == "figure")
2438 { kind = LyXParagraph::FIG; }
2439 else if (argument == "table")
2440 { kind = LyXParagraph::TAB; }
2441 else if (argument == "wide-fig")
2442 { kind = LyXParagraph::WIDE_FIG; }
2443 else if (argument == "wide-tab")
2444 { kind = LyXParagraph::WIDE_TAB; }
2445 else if (argument == "algorithm")
2446 { kind = LyXParagraph::ALGORITHM; }
2448 setErrorMessage(N_("Unknown kind of footnote"));
2451 owner->view()->text->InsertFootnoteEnvironment(kind);
2452 owner->view()->update(1);
2453 owner->view()->setState();
2457 case LFUN_BUFFERBULLETSSELECT:
2461 case LFUN_TOGGLECURSORFOLLOW:
2462 cursor_follows_scrollbar = !cursor_follows_scrollbar;
2465 case LFUN_KMAP_OFF: // keymap off
2466 owner->getIntl()->KeyMapOn(false);
2469 case LFUN_KMAP_PRIM: // primary keymap
2470 owner->getIntl()->KeyMapPrim();
2473 case LFUN_KMAP_SEC: // secondary keymap
2474 owner->getIntl()->KeyMapSec();
2477 case LFUN_KMAP_TOGGLE: // toggle keymap
2478 owner->getIntl()->ToggleKeyMap();
2481 case LFUN_SELFINSERT:
2483 for (string::size_type i = 0; i < argument.length(); ++i) {
2484 owner->view()->text->InsertChar(argument[i]);
2485 // This needs to be in the loop, or else we
2486 // won't break lines correctly. (Asger)
2487 owner->view()->smallUpdate(1);
2490 owner->view()->text->sel_cursor =
2491 owner->view()->text->cursor;
2492 moveCursorUpdate(false);
2498 // argument contains ';'-terminated commands
2499 while (argument.find(';') != string::npos) {
2501 argument = split(argument, first, ';');
2507 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
2515 now_time_t = time(NULL);
2516 now_tm = localtime(&now_time_t);
2517 (void)setlocale(LC_TIME, "");
2518 if (!argument.empty())
2520 else if (arg.empty())
2521 arg = lyxrc.date_insert_format;
2522 datetmp_len = (int) strftime(datetmp, 32, arg.c_str(), now_tm);
2523 for (int i = 0; i < datetmp_len; i++) {
2524 owner->view()->text->InsertChar(datetmp[i]);
2525 owner->view()->smallUpdate(1);
2528 owner->view()->text->sel_cursor = owner->view()->text->cursor;
2529 moveCursorUpdate(false);
2533 case LFUN_SAVEPREFERENCES:
2535 Path p(user_lyxdir);
2536 lyxrc.write("preferences");
2540 case LFUN_UNKNOWN_ACTION:
2542 if(!owner->buffer()) {
2544 setErrorMessage(N_("No document open"));
2548 if (owner->buffer()->isReadonly()) {
2550 setErrorMessage(N_("Document is read only"));
2554 if (!argument.empty()) {
2556 /* Automatically delete the currently selected
2557 * text and replace it with what is being
2558 * typed in now. Depends on lyxrc settings
2559 * "auto_region_delete", which defaults to
2562 if ( lyxrc.auto_region_delete ) {
2563 if (owner->view()->text->selection){
2564 owner->view()->text->CutSelection(false);
2565 owner->view()->update(-1);
2569 owner->view()->beforeChange();
2572 if (isdigit(argument[0]) &&
2573 (lyxrc.number_inset == "true" ||
2574 (lyxrc.number_inset == "rtl" &&
2575 owner->view()->text->real_current_font.isVisibleRightToLeft()
2577 UpdatableInset * tmpinset = new InsetNumber(owner->buffer());
2578 owner->view()->open_new_inset(tmpinset);
2579 tmpinset->LocalDispatch(owner->view(), action,
2585 for (string::size_type i = 0;
2586 i < argument.length(); ++i) {
2587 if (greek_kb_flag) {
2588 if (!math_insert_greek(argument[i]))
2589 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2591 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2594 owner->view()->smallUpdate(1);
2597 owner->view()->text->sel_cursor =
2598 owner->view()->text->cursor;
2599 moveCursorUpdate(false);
2602 // why is an "Unknown action" with empty
2603 // argument even dispatched in the first
2604 // place? I`ll probably change that. (Lgb)
2606 setErrorMessage(N_("Unknown action"));
2610 lyxerr << "A truly unknown func!" << endl;
2616 string res = getMessage();
2619 if (!commandshortcut.empty()) {
2620 string newbuf = owner->getMiniBuffer()->GetText();
2621 if (newbuf != commandshortcut) {
2622 owner->getMiniBuffer()->Set(newbuf
2628 owner->getMiniBuffer()->Set(string(_(res.c_str()))
2629 + " " + commandshortcut);
2636 void LyXFunc::setupLocalKeymap()
2638 keyseq.stdmap = keyseq.curmap = toplevel_keymap;
2639 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap;
2643 void LyXFunc::MenuNew(bool fromTemplate)
2645 string fname, initpath = lyxrc.document_path;
2648 if (owner->view()->available()) {
2649 string trypath = owner->buffer()->filepath;
2650 // If directory is writeable, use this as default.
2651 if (IsDirWriteable(trypath) == 1)
2656 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
2657 fileDlg.SetButton(1, _("Templates"), lyxrc.template_path);
2658 fname = fileDlg.Select(_("Enter Filename for new document"),
2659 initpath, "*.lyx", _("newfile"));
2662 if (fname.empty()) {
2663 owner->getMiniBuffer()->Set(_("Canceled."));
2664 lyxerr.debug() << "New Document Cancelled." << endl;
2668 // get absolute path of file and make sure the filename ends
2670 string s = MakeAbsPath(fname);
2671 if (!IsLyXFilename(s))
2674 // Check if the document already is open
2675 if (bufferlist.exists(s)){
2676 switch(AskConfirmation(_("Document is already open:"),
2677 MakeDisplayPath(s, 50),
2678 _("Do you want to close that document now?\n"
2679 "('No' will just switch to the open version)")))
2681 case 1: // Yes: close the document
2682 if (!bufferlist.close(bufferlist.getBuffer(s)))
2683 // If close is canceled, we cancel here too.
2686 case 2: // No: switch to the open document
2687 owner->view()->buffer(bufferlist.getBuffer(s));
2689 case 3: // Cancel: Do nothing
2690 owner->getMiniBuffer()->Set(_("Canceled."));
2695 // Check whether the file already exists
2696 if (IsLyXFilename(s)) {
2698 if (fi.readable() &&
2699 AskQuestion(_("File already exists:"),
2700 MakeDisplayPath(s, 50),
2701 _("Do you want to open the document?"))) {
2703 owner->getMiniBuffer()->Set(_("Opening document"),
2704 MakeDisplayPath(s), "...");
2706 owner->view()->buffer(
2707 bufferlist.loadLyXFile(s));
2708 owner->getMiniBuffer()->Set(_("Document"),
2715 // The template stuff
2719 fname = fileDlg.Select(_("Choose template"),
2720 lyxrc.template_path,
2726 // find a free buffer
2727 lyxerr.debug() << "Find a free buffer." << endl;
2728 owner->view()->buffer(bufferlist.newFile(s, templname));
2732 void LyXFunc::MenuOpen()
2734 string initpath = lyxrc.document_path;
2737 if (owner->view()->available()) {
2738 string trypath = owner->buffer()->filepath;
2739 // If directory is writeable, use this as default.
2740 if (IsDirWriteable(trypath) == 1)
2746 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
2747 fileDlg.SetButton(1, _("Examples"),
2748 AddPath(system_lyxdir, "examples"));
2749 string filename = fileDlg.Select(_("Select Document to Open"),
2753 // check selected filename
2754 if (filename.empty()) {
2755 owner->getMiniBuffer()->Set(_("Canceled."));
2759 // get absolute path of file and make sure the filename ends
2761 filename = MakeAbsPath(filename);
2762 if (!IsLyXFilename(filename))
2766 owner->getMiniBuffer()->Set(_("Opening document"),
2767 MakeDisplayPath(filename), "...");
2768 Buffer * openbuf = bufferlist.loadLyXFile(filename);
2770 owner->view()->buffer(openbuf);
2771 owner->getMiniBuffer()->Set(_("Document"),
2772 MakeDisplayPath(filename),
2775 owner->getMiniBuffer()->Set(_("Could not open document"),
2776 MakeDisplayPath(filename));
2781 void LyXFunc::doImportASCII(bool linorpar)
2783 string initpath = lyxrc.document_path;
2786 if (owner->view()->available()) {
2787 string trypath = owner->buffer()->filepath;
2788 // If directory is writeable, use this as default.
2789 if (IsDirWriteable(trypath) == 1)
2795 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
2796 fileDlg.SetButton(1, _("Examples"),
2797 AddPath(system_lyxdir, "examples"));
2798 string filename = fileDlg.Select(_("Select ASCII file to Import"),
2802 // check selected filename
2803 if (filename.empty()) {
2804 owner->getMiniBuffer()->Set(_("Canceled."));
2808 // get absolute path of file
2809 filename = MakeAbsPath(filename);
2811 string s = ChangeExtension(filename, ".lyx", false);
2813 // Check if the document already is open
2814 if (bufferlist.exists(s)) {
2815 switch(AskConfirmation(_("Document is already open:"),
2816 MakeDisplayPath(s, 50),
2817 _("Do you want to close that document now?\n"
2818 "('No' will just switch to the open version)")))
2820 case 1: // Yes: close the document
2821 if (!bufferlist.close(bufferlist.getBuffer(s)))
2822 // If close is canceled, we cancel here too.
2825 case 2: // No: switch to the open document
2826 owner->view()->buffer(bufferlist.getBuffer(s));
2828 case 3: // Cancel: Do nothing
2829 owner->getMiniBuffer()->Set(_("Canceled."));
2834 // Check if a LyX document by the same root exists in filesystem
2835 FileInfo f(s, true);
2836 if (f.exist() && !AskQuestion(_("A document by the name"),
2838 _("already exists. Overwrite?"))) {
2839 owner->getMiniBuffer()->Set(_("Canceled."));
2843 owner->view()->buffer(bufferlist.newFile(s, string()));
2844 owner->getMiniBuffer()->Set(_("Importing ASCII file"),
2845 MakeDisplayPath(filename), "...");
2846 // Insert ASCII file
2847 InsertAsciiFile(owner->view(), filename, linorpar);
2848 owner->getMiniBuffer()->Set(_("ASCII file "),
2849 MakeDisplayPath(filename),
2854 void LyXFunc::doImportLaTeX(bool isnoweb)
2856 string initpath = lyxrc.document_path;
2859 if (owner->view()->available()) {
2860 string trypath = owner->buffer()->filepath;
2861 // If directory is writeable, use this as default.
2862 if (IsDirWriteable(trypath) == 1)
2868 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
2869 fileDlg.SetButton(1, _("Examples"),
2870 AddPath(system_lyxdir, "examples"));
2873 filename = fileDlg.Select(_("Select Noweb file to Import"),
2876 filename = fileDlg.Select(_("Select LaTeX file to Import"),
2882 // check selected filename
2883 if (filename.empty()) {
2884 owner->getMiniBuffer()->Set(_("Canceled."));
2888 // get absolute path of file
2889 filename = MakeAbsPath(filename);
2891 // Check if the document already is open
2892 string LyXfilename = ChangeExtension(filename, ".lyx", false);
2893 if (bufferlist.exists(LyXfilename)){
2894 switch(AskConfirmation(_("Document is already open:"),
2895 MakeDisplayPath(LyXfilename, 50),
2896 _("Do you want to close that document now?\n"
2897 "('No' will just switch to the open version)")))
2899 case 1: // Yes: close the document
2900 if (!bufferlist.close(bufferlist.getBuffer(LyXfilename)))
2901 // If close is canceled, we cancel here too.
2904 case 2: // No: switch to the open document
2905 owner->view()->buffer(
2906 bufferlist.getBuffer(LyXfilename));
2908 case 3: // Cancel: Do nothing
2909 owner->getMiniBuffer()->Set(_("Canceled."));
2914 // Check if a LyX document by the same root exists in filesystem
2915 FileInfo f(LyXfilename, true);
2916 if (f.exist() && !AskQuestion(_("A document by the name"),
2917 MakeDisplayPath(LyXfilename),
2918 _("already exists. Overwrite?"))) {
2919 owner->getMiniBuffer()->Set(_("Canceled."));
2926 owner->getMiniBuffer()->Set(_("Importing LaTeX file"),
2927 MakeDisplayPath(filename), "...");
2928 ImportLaTeX myImport(filename);
2929 openbuf = myImport.run();
2931 owner->getMiniBuffer()->Set(_("Importing Noweb file"),
2932 MakeDisplayPath(filename), "...");
2933 ImportNoweb myImport(filename);
2934 openbuf = myImport.run();
2937 owner->view()->buffer(openbuf);
2938 owner->getMiniBuffer()->Set(isnoweb ?
2939 _("Noweb file ") : _("LateX file "),
2940 MakeDisplayPath(filename),
2943 owner->getMiniBuffer()->Set(isnoweb ?
2944 _("Could not import Noweb file") :
2945 _("Could not import LaTeX file"),
2946 MakeDisplayPath(filename));
2951 void LyXFunc::doImportLinuxDoc()
2953 string initpath = lyxrc.document_path;
2956 if (owner->view()->available()) {
2957 string trypath = owner->buffer()->filepath;
2958 // If directory is writeable, use this as default.
2959 if (IsDirWriteable(trypath) == 1)
2965 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
2966 fileDlg.SetButton(1, _("Examples"),
2967 AddPath(system_lyxdir, "examples"));
2969 string filename = fileDlg.Select(_("Select LinuxDoc file to Import"),
2970 initpath, "*.sgml");
2974 // check selected filename
2975 if (filename.empty()) {
2976 owner->getMiniBuffer()->Set(_("Canceled."));
2980 // get absolute path of file
2981 filename = MakeAbsPath(filename);
2983 // Check if the document already is open
2984 string LyXfilename = ChangeExtension(filename, ".lyx", false);
2985 if (bufferlist.exists(LyXfilename)){
2986 switch(AskConfirmation(_("Document is already open:"),
2987 MakeDisplayPath(LyXfilename, 50),
2988 _("Do you want to close that document now?\n"
2989 "('No' will just switch to the open version)")))
2991 case 1: // Yes: close the document
2992 if (!bufferlist.close(bufferlist.getBuffer(LyXfilename)))
2993 // If close is canceled, we cancel here too.
2996 case 2: // No: switch to the open document
2997 owner->view()->buffer(
2998 bufferlist.getBuffer(LyXfilename));
3000 case 3: // Cancel: Do nothing
3001 owner->getMiniBuffer()->Set(_("Canceled."));
3006 // Check if a LyX document by the same root exists in filesystem
3007 FileInfo f(LyXfilename, true);
3008 if (f.exist() && !AskQuestion(_("A document by the name"),
3009 MakeDisplayPath(LyXfilename),
3010 _("already exists. Overwrite?"))) {
3011 owner->getMiniBuffer()->Set(_("Canceled."));
3016 owner->getMiniBuffer()->Set(_("Importing LinuxDoc file"),
3017 MakeDisplayPath(filename), "...");
3020 string tmp = lyxrc.linuxdoc_to_lyx_command + filename;
3024 int result = one.startscript(Systemcalls::System, tmp);
3026 string filename = ChangeExtension(filename, ".lyx", false);
3027 // File was generated without problems. Load it.
3028 buf = bufferlist.loadLyXFile(filename);
3029 owner->view()->buffer(buf);
3030 owner->getMiniBuffer()->Set(_("LinuxDoc file "),
3031 MakeDisplayPath(filename),
3034 owner->getMiniBuffer()->Set(_("Could not import LinuxDoc file"),
3035 MakeDisplayPath(filename));
3040 void LyXFunc::MenuInsertLyXFile(string const & filen)
3042 string filename = filen;
3044 if (filename.empty()) {
3045 // Launch a file browser
3046 string initpath = lyxrc.document_path;
3049 if (owner->view()->available()) {
3050 string trypath = owner->buffer()->filepath;
3051 // If directory is writeable, use this as default.
3052 if (IsDirWriteable(trypath) == 1)
3058 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
3059 fileDlg.SetButton(1, _("Examples"),
3060 AddPath(system_lyxdir, "examples"));
3061 filename = fileDlg.Select(_("Select Document to Insert"),
3065 // check selected filename
3066 if (filename.empty()) {
3067 owner->getMiniBuffer()->Set(_("Canceled."));
3072 // get absolute path of file and make sure the filename ends
3074 filename = MakeAbsPath(filename);
3075 if (!IsLyXFilename(filename))
3079 owner->getMiniBuffer()->Set(_("Inserting document"),
3080 MakeDisplayPath(filename), "...");
3081 bool res = owner->view()->insertLyXFile(filename);
3083 owner->getMiniBuffer()->Set(_("Document"),
3084 MakeDisplayPath(filename),
3087 owner->getMiniBuffer()->Set(_("Could not insert document"),
3088 MakeDisplayPath(filename));
3093 void LyXFunc::reloadBuffer()
3095 string fn = owner->buffer()->fileName();
3096 if (bufferlist.close(owner->buffer()))
3097 owner->view()->buffer(bufferlist.loadLyXFile(fn));
3101 void LyXFunc::CloseBuffer()
3103 if (bufferlist.close(owner->buffer()) && !quitting) {
3104 if (bufferlist.empty()) {
3105 // need this otherwise SEGV may occur while trying to
3106 // set variables that don't exist
3107 // since there's no current buffer
3108 CloseAllBufferRelatedPopups();
3111 owner->view()->buffer(bufferlist.first());
3117 Inset * LyXFunc::getInsetByCode(Inset::Code code)
3121 LyXCursor cursor = owner->view()->text->cursor;
3122 LyXParagraph::size_type pos = cursor.pos;
3123 LyXParagraph * par = cursor.par;
3125 while (par && !found) {
3126 while ((inset = par->ReturnNextInsetPointer(pos))){
3127 if (inset->LyxCode() == code) {
3135 return found ? inset : 0;
3139 // Each "owner" should have it's own message method. lyxview and
3140 // the minibuffer would use the minibuffer, but lyxserver would
3141 // send an ERROR signal to its client. Alejandro 970603
3142 // This func is bit problematic when it comes to NLS, to make the
3143 // lyx servers client be language indepenent we must not translate
3144 // strings sent to this func.
3145 void LyXFunc::setErrorMessage(string const & m) const
3147 dispatch_buffer = m;
3152 void LyXFunc::setMessage(string const & m)
3154 dispatch_buffer = m;