1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * ====================================================== */
15 using std::istringstream;
28 #pragma implementation
31 #include "lyxlookup.h"
34 #include "bufferlist.h"
35 #include "lyxserver.h"
40 #include "LyXAction.h"
41 #include "insets/inseturl.h"
42 #include "insets/insetlatexaccent.h"
43 #include "insets/insettoc.h"
44 #include "insets/insetlof.h"
45 #include "insets/insetloa.h"
46 #include "insets/insetlot.h"
47 #include "insets/insetref.h"
48 #include "insets/insetparent.h"
49 #include "insets/insetindex.h"
50 #include "insets/insetinclude.h"
51 #include "insets/insetbib.h"
52 #include "insets/insettext.h"
53 //#include "insets/insetnumber.h"
54 #include "insets/insetert.h"
55 #include "insets/insetgraphics.h"
56 #include "insets/insetfoot.h"
57 #include "mathed/formulamacro.h"
59 #include "spellchecker.h" // RVDK_PATCH_5
60 #include "minibuffer.h"
64 #include "lyx_gui_misc.h"
65 #include "support/filetools.h"
66 #include "support/FileInfo.h"
67 #include "support/syscall.h"
68 #include "support/lstrings.h"
69 #include "support/path.h"
74 #include "trans_mgr.h"
75 #include "ImportLaTeX.h"
76 #include "ImportNoweb.h"
85 extern bool cursor_follows_scrollbar;
87 extern void InsertAsciiFile(BufferView *, string const &, bool);
88 extern void math_insert_symbol(char const *);
89 extern Bool math_insert_greek(char const); // why "Bool"?
90 extern BufferList bufferlist;
91 extern LyXServer * lyxserver;
92 extern short greek_kb_flag;
93 extern FD_form_toc * fd_form_toc;
94 extern bool selection_possible;
96 extern kb_keymap * toplevel_keymap;
98 extern void MenuWrite(Buffer *);
99 extern void MenuWriteAs(Buffer *);
100 extern int MenuRunLaTeX(Buffer *);
101 extern int MenuBuildProg(Buffer *);
102 extern int MenuRunChktex(Buffer *);
103 extern bool CreatePostscript(Buffer *, bool);
104 extern void MenuPrint(Buffer *);
105 extern void MenuSendto();
106 extern void QuitLyX();
107 extern void MenuFax(Buffer *);
108 extern void MenuExport(Buffer *, string const &);
109 extern void MenuPasteSelection(char at);
110 extern LyXAction lyxaction;
112 extern tex_accent_struct get_accent(kb_action action);
114 extern void AutoSave(BufferView *);
115 extern void SetUpdateTimer(float timer = 0.3);
116 extern void FreeUpdateTimer();
117 extern bool PreviewDVI(Buffer *);
118 extern bool PreviewPostscript(Buffer *);
119 extern void MenuInsertLabel(char const *);
120 extern void MenuInsertRef();
121 extern void MenuLayoutCharacter();
122 extern void MenuLayoutParagraph();
123 extern void MenuLayoutDocument();
124 extern void MenuLayoutPaper();
125 extern void MenuLayoutTable(int flag);
126 extern void MenuLayoutQuotes();
127 extern void MenuLayoutPreamble();
128 extern void MenuLayoutSave();
129 extern void bulletForm();
131 extern Buffer * NewLyxFile(string const &);
132 extern void LoadLyXFile(string const &);
133 extern void Reconfigure(BufferView *);
135 extern LyXTextClass::size_type current_layout;
136 extern int getISOCodeFromLaTeX(char *);
138 extern void ShowLatexLog();
140 /* === globals =========================================================== */
142 bool LyXFunc::show_sc = true;
145 LyXFunc::LyXFunc(LyXView * o)
149 lyx_dead_action = LFUN_NOACTION;
150 lyx_calling_dead_action = LFUN_NOACTION;
155 // I changed this func slightly. I commented out the ...FinishUndo(),
156 // this means that all places that used to have a moveCursorUpdate, now
157 // have a ...FinishUndo() as the preceeding statement. I have also added
158 // a moveCursorUpdate to some of the functions that updated the cursor, but
159 // that did not show its new position.
161 void LyXFunc::moveCursorUpdate(bool selecting)
163 if (selecting || owner->view()->text->mark_set) {
164 owner->view()->text->SetSelection();
165 owner->view()->toggleToggle();
166 owner->view()->update(0);
168 owner->view()->update(-2); // this IS necessary
172 owner->view()->showCursor();
174 /* ---> Everytime the cursor is moved, show the current font state. */
175 // should this too me moved out of this func?
176 //owner->getMiniBuffer()->Set(CurrentState());
177 owner->view()->setState();
181 int LyXFunc::processKeyEvent(XEvent * ev)
185 XKeyEvent * keyevent = &ev->xkey;
186 KeySym keysym_return;
188 int num_bytes = LyXLookupString(ev, s_r, 10, &keysym_return);
189 s_r[num_bytes] = '\0';
191 if (lyxerr.debugging(Debug::KEY)) {
192 char * tmp = XKeysymToString(keysym_return);
193 string stm = (tmp ? tmp : "");
194 lyxerr << "KeySym is "
197 << keysym_return << "]"
198 << " and num_bytes is "
200 << " the string returned is \""
201 << s_r << '\"' << endl;
203 // Do nothing if we have nothing (JMarc)
204 if (num_bytes == 0 && keysym_return == NoSymbol) {
205 lyxerr[Debug::KEY] << "Empty kbd action (probably composing)"
210 // this function should be used always [asierra060396]
211 UpdatableInset * tli = owner->view()->the_locking_inset;
212 if (owner->view()->available() && tli && (keysym_return==XK_Escape)) {
213 if (tli == tli->GetLockingInset()) {
214 owner->view()->unlockInset(tli);
215 owner->view()->text->CursorRight();
216 moveCursorUpdate(false);
217 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
219 tli->UnlockInsetInInset(owner->view(),
220 tli->GetLockingInset());
225 // Can we be sure that this will work for all X-Windows
226 // implementations? (Lgb)
227 // This code snippet makes lyx ignore some keys. Perhaps
228 // all of them should be explictly mentioned?
229 if((keysym_return >= XK_Shift_L && keysym_return <= XK_Hyper_R)
230 || keysym_return == XK_Mode_switch || keysym_return == 0x0)
233 // Do a one-deep top-level lookup for
234 // cancel and meta-fake keys. RVDK_PATCH_5
235 cancel_meta_seq.reset();
237 int action = cancel_meta_seq.addkey(keysym_return, keyevent->state
238 &(ShiftMask|ControlMask
241 // When not cancel or meta-fake, do the normal lookup.
242 // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
243 // Mostly, meta_fake_bit = 0. RVDK_PATCH_5.
244 if ( (action != LFUN_CANCEL) && (action != LFUN_META_FAKE) ) {
246 // remove Caps Lock and Mod2 as a modifiers
247 action = keyseq.addkey(keysym_return,
248 (keyevent->state | meta_fake_bit)
249 &(ShiftMask|ControlMask
252 // Dont remove this unless you know what you are doing.
255 if (action == 0) action = LFUN_PREFIX;
257 if (lyxerr.debugging(Debug::KEY)) {
263 << num_bytes << "]" << endl;
266 // already here we know if it any point in going further
267 // why not return already here if action == -1 and
268 // num_bytes == 0? (Lgb)
270 if(keyseq.length > 1 || keyseq.length < -1) {
273 owner->getMiniBuffer()->Set(buf);
277 if (keyseq.length < -1) { // unknown key sequence...
281 owner->getMiniBuffer()->Set(_("Unknown sequence:"), buf);
285 char isochar = keyseq.getiso();
286 if (!(keyevent->state&ControlMask) &&
287 !(keyevent->state&Mod1Mask) &&
288 (isochar && keysym_return < 0xF000)) {
291 if (argument.empty()) {
292 lyxerr.debug() << "Empty argument!" << endl;
293 // This can`t possibly be of any use
294 // so we`ll skip the dispatch.
298 if (action == LFUN_SELFINSERT) {
302 bool tmp_sc = show_sc;
304 Dispatch(action, argument.c_str());
311 LyXFunc::func_status LyXFunc::getStatus(int ac) const
314 func_status flag = LyXFunc::OK;
316 Buffer * buf = owner->buffer();
318 if (lyxaction.isPseudoAction(ac))
319 action = lyxaction.retrieveActionArg(ac, argument);
321 action = static_cast<kb_action>(ac);
323 if (action == LFUN_UNKNOWN_ACTION) {
324 setErrorMessage(N_("Unknown action"));
325 return LyXFunc::Unknown;
328 // Check whether we need a buffer
329 if (!lyxaction.funcHasFlag(action, LyXAction::NoBuffer)) {
330 // Yes we need a buffer, do we have one?
333 // Can we use a readonly buffer?
334 if (buf->isReadonly() &&
335 !lyxaction.funcHasFlag(action,
336 LyXAction::ReadOnly)) {
338 setErrorMessage(N_("Document is read-only"));
339 flag |= LyXFunc::Disabled;
343 setErrorMessage(N_("Command not allowed with"
344 "out any document open"));
345 flag |= LyXFunc::Disabled;
349 if (flag & LyXFunc::Disabled)
352 // I would really like to avoid having this switch and rather try to
353 // encode this in the function itself.
354 static bool noLaTeX = lyxrc.latex_command == "none";
355 bool disable = false;
358 disable = noLaTeX || lyxrc.view_dvi_command == "none";
361 disable = noLaTeX || lyxrc.view_ps_command == "none";
368 disable = noLaTeX || lyxrc.print_command == "none";
371 disable = noLaTeX || lyxrc.fax_command == "none";
374 if (argument == "latex")
375 disable = lyxrc.relyx_command == "none";
376 if (argument == "linuxdoc")
377 disable = lyxrc.linuxdoc_to_lyx_command == "none";
380 if (argument == "dvi" || argument == "postscript")
382 if (argument == "html")
383 disable = lyxrc.html_command == "none";
384 if (argument == "html-linuxdoc")
385 disable = lyxrc.linuxdoc_to_html_command == "none";
386 if (argument == "html-docbook")
387 disable = lyxrc.docbook_to_html_command == "none";
390 disable = buf->undostack.empty();
393 disable = buf->redostack.empty();
395 case LFUN_SPELLCHECK:
396 disable = lyxrc.isp_command == "none";
399 disable = lyxrc.chktex_command == "none";
401 case LFUN_LAYOUT_TABLE:
402 disable = ! owner->view()->text->cursor.par->table;
408 flag |= LyXFunc::Disabled;
411 func_status box = LyXFunc::ToggleOff;
412 LyXFont font = owner->view()->text->real_current_font;
415 if (font.emph() == LyXFont::ON)
416 box = LyXFunc::ToggleOn;
419 if (font.noun() == LyXFont::ON)
420 box = LyXFunc::ToggleOn;
423 if (font.series() == LyXFont::BOLD_SERIES)
424 box = LyXFunc::ToggleOn;
427 if (font.latex() == LyXFont::ON)
428 box = LyXFunc::ToggleOn;
441 string LyXFunc::Dispatch(string const & s)
443 // Split command string into command and argument
444 string cmd, line = frontStrip(s);
445 string arg = strip(frontStrip(split(line, cmd, ' ')));
447 return Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
451 string LyXFunc::Dispatch(int ac,
452 char const * do_not_use_this_arg)
457 // we have not done anything wrong yet.
459 dispatch_buffer.clear();
461 // if action is a pseudo-action, we need the real action
462 if (lyxaction.isPseudoAction(ac)) {
464 action = static_cast<kb_action>
465 (lyxaction.retrieveActionArg(ac, tmparg));
469 action = static_cast<kb_action>(ac);
470 if (do_not_use_this_arg)
471 argument = do_not_use_this_arg; // except here
474 selection_possible = false;
476 if (owner->view()->available())
477 owner->view()->hideCursor();
479 // We cannot use this function here
480 if (getStatus(action) & Disabled)
481 goto exit_with_message;
483 commandshortcut.clear();
485 if (lyxrc.display_shortcuts && show_sc) {
486 if (action != LFUN_SELFINSERT) {
487 // Put name of command and list of shortcuts
488 // for it in minibuffer
489 string comname = lyxaction.getActionName(action);
491 int pseudoaction = action;
492 bool argsadded = false;
494 if (!argument.empty()) {
495 // If we have the command with argument,
498 lyxaction.searchActionArg(action,
501 if (pseudoaction == -1) {
502 pseudoaction = action;
504 comname += " " + argument;
509 string shortcuts = toplevel_keymap->findbinding(pseudoaction);
511 if (!shortcuts.empty()) {
512 comname += ": " + shortcuts;
513 } else if (!argsadded) {
514 comname += " " + argument;
517 if (!comname.empty()) {
518 comname = strip(comname);
519 commandshortcut = "(" + comname + ')';
520 owner->getMiniBuffer()->Set(commandshortcut);
521 // Here we could even add a small pause,
522 // to annoy the user and make him learn
524 // No! That will just annoy, not teach
525 // anything. The user will read the messages
526 // if they are interested. (Asger)
531 // If in math mode pass the control to
532 // the math inset [asierra060396]
533 if (owner->view()->available() &&
534 owner->view()->the_locking_inset) {
536 || (action == LFUN_UNKNOWN_ACTION
537 && keyseq.length >= -1)) {
538 if (action == LFUN_UNKNOWN_ACTION
539 && argument.empty()) {
540 argument = keyseq.getiso();
542 // Undo/Redo pre 0.13 is a bit tricky for insets.
543 if (action == LFUN_UNDO) {
545 UpdatableInset * inset =
546 owner->view()->the_locking_inset;
547 inset->GetCursorPos(slx, sly);
548 owner->view()->unlockInset(inset);
549 owner->view()->menuUndo();
550 if (owner->view()->text->cursor.par->
551 IsInset(owner->view()->text->cursor.pos)) {
552 inset = static_cast<UpdatableInset*>(
553 owner->view()->text->cursor.par->
554 GetInset(owner->view()->text->
560 inset->Edit(owner->view(),slx,sly,0);
562 } else if (action == LFUN_REDO) {
564 UpdatableInset * inset = owner->view()->
566 inset->GetCursorPos(slx, sly);
567 owner->view()->unlockInset(inset);
568 owner->view()->menuRedo();
569 inset = static_cast<UpdatableInset*>(
570 owner->view()->text->cursor.par->
571 GetInset(owner->view()->text->
574 inset->Edit(owner->view(),slx,sly,0);
576 } else if (owner->view()->the_locking_inset->
577 LocalDispatch(owner->view(), action,
579 UpdatableInset::DISPATCHED)
582 setMessage(N_("Text mode"));
584 case LFUN_UNKNOWN_ACTION:
585 case LFUN_BREAKPARAGRAPH:
587 owner->view()->text->CursorRight();
588 owner->view()->setState();
589 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
592 if (!owner->view()->text->cursor.par->isRightToLeftPar()) {
593 owner->view()->text->CursorRight();
594 moveCursorUpdate(false);
595 owner->getMiniBuffer()->
596 Set(CurrentState(owner->view()));
600 if (owner->view()->text->cursor.par->isRightToLeftPar()) {
601 owner->view()->text->CursorRight();
602 moveCursorUpdate(false);
603 owner->getMiniBuffer()->
604 Set(CurrentState(owner->view()));
615 // --- Misc -------------------------------------------
616 case LFUN_WORDFINDFORWARD :
617 case LFUN_WORDFINDBACKWARD : {
618 static string last_search;
619 string searched_string;
621 if (!argument.empty()) {
622 last_search = argument;
623 searched_string = argument;
625 searched_string = last_search;
628 LyXText * ltCur = owner->view()->text ;
630 if (!searched_string.empty() &&
631 ((action == LFUN_WORDFINDBACKWARD) ?
632 ltCur->SearchBackward(searched_string.c_str()) :
633 ltCur->SearchForward(searched_string.c_str()))) {
635 // ??? What is that ???
636 owner->view()->update(-2);
639 // clear the selection (if there is any)
640 owner->view()->toggleSelection();
641 owner->view()->text->ClearSelection();
643 // Move cursor so that successive C-s 's will not stand in place.
644 if( action == LFUN_WORDFINDFORWARD )
645 owner->view()->text->CursorRightOneWord();
646 owner->view()->text->FinishUndo();
647 moveCursorUpdate(false);
650 // set the new selection
651 // SetSelectionOverLenChars(owner->view()->currentBuffer()->text, iLenSelected);
652 owner->view()->toggleSelection(false);
656 // REMOVED : if (owner->view()->getWorkArea()->focus)
657 owner->view()->showCursor();
663 if (owner->view()->available()) {
664 owner->view()->update(-2);
667 keyseq.print(buf, true);
668 owner->getMiniBuffer()->Set(buf, string(), string(), 1);
672 // --- Misc -------------------------------------------
673 case LFUN_EXEC_COMMAND:
674 owner->getMiniBuffer()->ExecCommand();
677 case LFUN_CANCEL: // RVDK_PATCH_5
680 if(owner->view()->available())
681 // cancel any selection
682 Dispatch(LFUN_MARK_OFF, 0);
683 setMessage(N_("Cancel"));
686 case LFUN_META_FAKE: // RVDK_PATCH_5
688 meta_fake_bit = Mod1Mask;
690 keyseq.print(buf, true);
691 string res = string("M-") + buf;
692 setMessage(buf); // RVDK_PATCH_5
696 case LFUN_READ_ONLY_TOGGLE:
697 if (owner->buffer()->lyxvc.inUse()) {
698 owner->buffer()->lyxvc.toggleReadOnly();
700 owner->buffer()->setReadonly(
701 !owner->buffer()->isReadonly());
705 case LFUN_CENTER: // this is center and redraw.
706 owner->view()->center();
710 if (owner->view()->available()) {
711 owner->view()->text->toggleAppendix();
712 owner->view()->update(1);
716 // --- Menus -----------------------------------------------
721 case LFUN_MENUNEWTMPLT:
729 case LFUN_CLOSEBUFFER:
734 owner->getMiniBuffer()->Set(_("Saving document"),
735 MakeDisplayPath(owner->buffer()->fileName()),
737 MenuWrite(owner->buffer());
738 //owner->getMiniBuffer()->
739 // Set(_("Document saved as"),
740 // MakeDisplayPath(owner->buffer()->fileName()));
742 //owner->getMiniBuffer()->Set(_("Save failed!"));
746 case LFUN_MENUWRITEAS:
747 MenuWriteAs(owner->buffer());
750 case LFUN_MENURELOAD:
755 PreviewDVI(owner->buffer());
759 PreviewPostscript(owner->buffer());
763 MenuRunLaTeX(owner->buffer());
767 MenuBuildProg(owner->buffer());
771 MenuRunChktex(owner->buffer());
775 CreatePostscript(owner->buffer(), false);
779 MenuPrint(owner->buffer());
783 MenuFax(owner->buffer());
787 MenuExport(owner->buffer(), argument);
792 //needs argument as string
793 string imtyp = argument;
796 if (imtyp == "latex") {
797 doImportLaTeX(false);
800 else if (imtyp == "ascii") {
801 doImportASCII(false);
802 } else if (imtyp == "asciiparagraph") {
805 } else if (imtyp == "noweb") {
807 } else if (imtyp == "linuxdoc") {
810 setErrorMessage(string(N_("Unknown import type: "))
822 if (fd_form_toc->form_toc->visible) {
823 fl_raise_form(fd_form_toc->form_toc);
825 static int ow = -1, oh;
826 fl_show_form(fd_form_toc->form_toc,
828 FL_FREE_SIZE, FL_FULLBORDER,
829 _("Table of Contents"));
831 ow = fd_form_toc->form_toc->w;
832 oh = fd_form_toc->form_toc->h;
834 fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
838 case LFUN_TOC_INSERT:
840 Inset * new_inset = new InsetTOC(owner->buffer());
841 owner->view()->insertInset(new_inset, "Standard", true);
845 case LFUN_LOF_INSERT:
847 Inset * new_inset = new InsetLOF(owner->buffer());
848 owner->view()->insertInset(new_inset, "Standard", true);
852 case LFUN_LOA_INSERT:
854 Inset * new_inset = new InsetLOA(owner->buffer());
855 owner->view()->insertInset(new_inset, "Standard", true);
859 case LFUN_LOT_INSERT:
861 Inset * new_inset = new InsetLOT(owner->buffer());
862 owner->view()->insertInset(new_inset, "Standard", true);
874 case LFUN_INSERT_GRAPHICS:
876 Inset * new_inset = new InsetGraphics;
877 owner->view()->insertInset(new_inset);
882 AutoSave(owner->view());
886 owner->view()->menuUndo();
890 owner->view()->menuRedo();
893 case LFUN_MENUSEARCH:
895 // Ok this is one _very_ bad solution, but I think that some
896 // of this will be rewritten as part of GUI indep anyway.
898 static LyXFindReplace FR_;
899 FR_.StartSearch(owner->view());
905 owner->view()->paste();
906 owner->view()->setState();
909 case LFUN_PASTESELECTION:
912 if (argument == "paragraph") asPara = true;
913 MenuPasteSelection(asPara);
918 owner->view()->cut();
922 owner->view()->copy();
925 case LFUN_LAYOUT_COPY:
926 owner->view()->copyEnvironment();
929 case LFUN_LAYOUT_PASTE:
930 owner->view()->pasteEnvironment();
931 owner->view()->setState();
935 owner->view()->gotoError();
938 case LFUN_REMOVEERRORS:
939 if (owner->view()->removeAutoInsets()) {
940 owner->view()->redraw();
941 owner->view()->fitCursor();
942 owner->view()->updateScrollbar();
947 owner->view()->gotoNote();
951 owner->view()->openStuff();
954 case LFUN_HYPHENATION:
955 owner->view()->hyphenationPoint();
959 owner->view()->ldots();
962 case LFUN_END_OF_SENTENCE:
963 owner->view()->endOfSentenceDot();
966 case LFUN_MENU_SEPARATOR:
967 owner->view()->menuSeparator();
971 owner->view()->hfill();
975 changeDepth(owner->view(), 0);
979 changeDepth(owner->view(), -1);
982 case LFUN_DEPTH_PLUS:
983 changeDepth(owner->view(), 1);
992 owner->view()->setState();
993 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1000 case LFUN_RECONFIGURE:
1001 Reconfigure(owner->view());
1005 if (owner->view()->available()
1006 && !owner->view()->text->selection
1007 && owner->view()->text->cursor.par->footnoteflag
1008 != LyXParagraph::NO_FOOTNOTE)
1009 { // only melt footnotes with FOOTMELT, not margins etc
1010 if(owner->view()->text->cursor.par->footnotekind == LyXParagraph::FOOTNOTE)
1011 Melt(owner->view());
1014 Foot(owner->view());
1015 owner->view()->setState();
1018 case LFUN_MARGINMELT:
1019 if (owner->view()->available()
1020 && !owner->view()->text->selection
1021 && owner->view()->text->cursor.par->footnoteflag
1022 != LyXParagraph::NO_FOOTNOTE) {
1023 // only melt margins
1024 if(owner->view()->text->cursor.par->footnotekind == LyXParagraph::MARGIN)
1025 Melt(owner->view());
1027 Margin(owner->view());
1028 owner->view()->setState();
1031 // --- version control -------------------------------
1032 case LFUN_VC_REGISTER:
1034 if (!owner->buffer()->lyxvc.inUse())
1035 owner->buffer()->lyxvc.registrer();
1039 case LFUN_VC_CHECKIN:
1041 if (owner->buffer()->lyxvc.inUse()
1042 && !owner->buffer()->isReadonly())
1043 owner->buffer()->lyxvc.checkIn();
1047 case LFUN_VC_CHECKOUT:
1049 if (owner->buffer()->lyxvc.inUse()
1050 && owner->buffer()->isReadonly())
1051 owner->buffer()->lyxvc.checkOut();
1055 case LFUN_VC_REVERT:
1057 owner->buffer()->lyxvc.revert();
1063 owner->buffer()->lyxvc.undoLast();
1067 case LFUN_VC_HISTORY:
1069 owner->buffer()->lyxvc.showLog();
1073 // --- buffers ----------------------------------------
1075 case LFUN_FILE_INSERT:
1077 MenuInsertLyXFile(argument);
1081 case LFUN_FILE_INSERT_ASCII:
1083 bool asPara = (argument == "paragraph");
1084 InsertAsciiFile(owner->view(), string(), asPara);
1090 // servercmd: argument must be <file>:<template>
1091 Buffer * tmpbuf = NewLyxFile(argument);
1093 owner->view()->buffer(tmpbuf);
1097 case LFUN_FILE_OPEN:
1098 owner->view()->buffer(bufferlist.loadLyXFile(argument));
1101 case LFUN_LATEX_LOG:
1107 lyxerr.debug() << "LFUN_LAYOUTNO: (arg) " << argument << endl;
1108 int sel = strToInt(argument);
1109 lyxerr.debug() << "LFUN_LAYOUTNO: (sel) "<< sel << endl;
1111 // Should this give a setMessage instead?
1113 return string(); // illegal argument
1115 --sel; // sel 1..., but layout 0...
1117 // Pretend we got the name instead.
1118 Dispatch(int(LFUN_LAYOUT),
1119 textclasslist.NameOfLayout(owner->view()->
1128 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1129 << argument << endl;
1131 // Derive layout number from given argument (string)
1132 // and current buffer's textclass (number). */
1133 LyXTextClassList::ClassList::size_type tclass =
1134 owner->view()->text->bparams->textclass;
1135 pair <bool, LyXTextClass::size_type> layout =
1136 textclasslist.NumberOfLayout(tclass, argument);
1138 // If the entry is obsolete, use the new one instead.
1140 string obs = textclasslist.Style(tclass,layout.second)
1144 textclasslist.NumberOfLayout(tclass, obs);
1147 // see if we found the layout number:
1148 if (!layout.first) {
1149 setErrorMessage(string(N_("Layout ")) + argument +
1154 if (current_layout != layout.second) {
1155 owner->view()->hideCursor();
1156 current_layout = layout.second;
1157 owner->view()->update(-2);
1158 owner->view()->text->
1159 SetLayout(layout.second);
1160 owner->getToolbar()->combox->
1161 select(owner->view()->
1164 owner->view()->update(1);
1165 owner->view()->setState();
1170 case LFUN_LAYOUT_DOCUMENT:
1171 MenuLayoutDocument();
1174 case LFUN_LAYOUT_PARAGRAPH:
1175 MenuLayoutParagraph();
1178 case LFUN_LAYOUT_CHARACTER:
1179 MenuLayoutCharacter();
1182 case LFUN_LAYOUT_TABLE:
1185 if (argument == "true") flag = 1;
1186 MenuLayoutTable(flag);
1190 case LFUN_LAYOUT_PAPER:
1194 case LFUN_LAYOUT_QUOTES:
1198 case LFUN_LAYOUT_PREAMBLE:
1199 MenuLayoutPreamble();
1202 case LFUN_LAYOUT_SAVE_DEFAULT:
1206 case LFUN_DROP_LAYOUTS_CHOICE:
1207 owner->getToolbar()->combox->Show();
1212 Lang(owner->view(), argument);
1213 owner->view()->setState();
1214 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1219 Emph(owner->view());
1220 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1224 Bold(owner->view());
1225 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1229 Noun(owner->view());
1230 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1234 Code(owner->view());
1235 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1239 Sans(owner->view());
1240 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1244 Roman(owner->view());
1245 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1249 StyleReset(owner->view());
1250 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1253 case LFUN_UNDERLINE:
1254 Underline(owner->view());
1255 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1258 case LFUN_FONT_SIZE:
1259 FontSize(owner->view(), argument);
1260 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1263 case LFUN_FONT_STATE:
1264 setMessage(CurrentState(owner->view()));
1267 case LFUN_UPCASE_WORD:
1268 owner->view()->update(-2);
1270 owner->view()->text->ChangeWordCase(LyXText::text_uppercase);
1271 owner->view()->update(1);
1275 case LFUN_LOWCASE_WORD:
1276 owner->view()->update(-2);
1278 owner->view()->text->ChangeWordCase(LyXText::text_lowercase);
1279 owner->view()->update(1);
1283 case LFUN_CAPITALIZE_WORD:
1284 owner->view()->update(-2);
1286 owner->view()->text->ChangeWordCase(LyXText::text_capitalization);
1287 owner->view()->update(1);
1291 case LFUN_INSERT_LABEL:
1292 MenuInsertLabel(argument.c_str());
1295 case LFUN_INSERT_REF:
1299 case LFUN_REFTOGGLE:
1302 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1304 if (inset->getFlag() == InsetRef::REF)
1305 inset->setFlag(InsetRef::PAGE_REF);
1307 inset->setFlag(InsetRef::REF);
1308 owner->view()->updateInset(inset, true);
1310 setErrorMessage(N_("No cross-reference to toggle"));
1317 owner->view()->restorePosition();
1323 string label(argument);
1324 if (label.empty()) {
1326 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1328 label = inset->getContents();
1331 if (!label.empty()) {
1332 owner->view()->savePosition();
1333 owner->view()->gotoLabel(label.c_str());
1338 case LFUN_MENU_OPEN_BY_NAME:
1339 owner->getMenus()->openByName(argument);
1340 break; // RVDK_PATCH_5
1342 case LFUN_SPELLCHECK:
1343 if (lyxrc.isp_command != "none")
1344 ShowSpellChecker(owner->view());
1345 break; // RVDK_PATCH_5
1347 // --- Cursor Movements -----------------------------
1350 LyXText * tmptext = owner->view()->text;
1351 bool is_rtl = tmptext->cursor.par->isRightToLeftPar();
1352 if(!tmptext->mark_set)
1353 owner->view()->beforeChange();
1354 owner->view()->update(-2);
1356 tmptext->CursorLeft();
1357 if (tmptext->cursor.pos < tmptext->cursor.par->Last()
1358 && tmptext->cursor.par->GetChar(tmptext->cursor.pos)
1359 == LyXParagraph::META_INSET
1360 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)
1361 && tmptext->cursor.par->GetInset(tmptext->cursor.pos)->Editable() == Inset::HIGHLY_EDITABLE){
1362 Inset * tmpinset = tmptext->cursor.par->GetInset(tmptext->cursor.pos);
1363 setMessage(tmpinset->EditMessage());
1364 tmpinset->Edit(owner->view(), 0, 0, 0);
1368 tmptext->CursorRight();
1369 owner->view()->text->FinishUndo();
1370 moveCursorUpdate(false);
1371 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1377 // This is soooo ugly. Isn`t it possible to make
1378 // it simpler? (Lgb)
1379 LyXText * txt = owner->view()->text;
1380 bool is_rtl = txt->cursor.par->isRightToLeftPar();
1381 if(!txt->mark_set) owner->view()->beforeChange();
1382 owner->view()->update(-2);
1385 if (txt->cursor.pos < txt->cursor.par->Last()
1386 && txt->cursor.par->GetChar(txt->cursor.pos)
1387 == LyXParagraph::META_INSET
1388 && txt->cursor.par->GetInset(txt->cursor.pos)
1389 && txt->cursor.par->GetInset(txt->cursor.pos)->Editable() == Inset::HIGHLY_EDITABLE) {
1390 Inset * tmpinset = txt->cursor.par->GetInset(txt->cursor.pos);
1391 setMessage(tmpinset->EditMessage());
1392 tmpinset->Edit(owner->view(),
1393 tmpinset->width(owner->view()->painter(),
1394 txt->GetFont(txt->cursor.par,
1402 owner->view()->text->FinishUndo();
1403 moveCursorUpdate(false);
1404 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1409 if(!owner->view()->text->mark_set) owner->view()->beforeChange();
1410 owner->view()->update(-3);
1411 owner->view()->text->CursorUp();
1412 owner->view()->text->FinishUndo();
1413 moveCursorUpdate(false);
1414 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1418 if(!owner->view()->text->mark_set)
1419 owner->view()->beforeChange();
1420 owner->view()->update(-3);
1421 owner->view()->text->CursorDown();
1422 owner->view()->text->FinishUndo();
1423 moveCursorUpdate(false);
1424 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1427 case LFUN_UP_PARAGRAPH:
1428 if(!owner->view()->text->mark_set)
1429 owner->view()->beforeChange();
1430 owner->view()->update(-3);
1431 owner->view()->text->CursorUpParagraph();
1432 owner->view()->text->FinishUndo();
1433 moveCursorUpdate(false);
1434 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1437 case LFUN_DOWN_PARAGRAPH:
1438 if(!owner->view()->text->mark_set)
1439 owner->view()->beforeChange();
1440 owner->view()->update(-3);
1441 owner->view()->text->CursorDownParagraph();
1442 owner->view()->text->FinishUndo();
1443 moveCursorUpdate(false);
1444 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1448 if(!owner->view()->text->mark_set)
1449 owner->view()->beforeChange();
1450 owner->view()->update(-3);
1451 owner->view()->cursorPrevious();
1452 owner->view()->text->FinishUndo();
1453 moveCursorUpdate(false);
1454 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1458 if(!owner->view()->text->mark_set)
1459 owner->view()->beforeChange();
1460 owner->view()->update(-3);
1461 owner->view()->cursorNext();
1462 owner->view()->text->FinishUndo();
1463 moveCursorUpdate(false);
1464 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1468 if(!owner->view()->text->mark_set)
1469 owner->view()->beforeChange();
1470 owner->view()->update(-2);
1471 owner->view()->text->CursorHome();
1472 owner->view()->text->FinishUndo();
1473 moveCursorUpdate(false);
1474 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1478 if(!owner->view()->text->mark_set)
1479 owner->view()->beforeChange();
1480 owner->view()->update(-2);
1481 owner->view()->text->CursorEnd();
1482 owner->view()->text->FinishUndo();
1483 moveCursorUpdate(false);
1484 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1488 if(!owner->view()->text->mark_set)
1489 owner->view()->beforeChange();
1490 owner->view()->update(-2);
1491 owner->view()->text->CursorTab();
1492 owner->view()->text->FinishUndo();
1493 moveCursorUpdate(false);
1494 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1497 case LFUN_WORDRIGHT:
1498 if(!owner->view()->text->mark_set)
1499 owner->view()->beforeChange();
1500 owner->view()->update(-2);
1501 if (owner->view()->text->cursor.par->isRightToLeftPar())
1502 owner->view()->text->CursorLeftOneWord();
1504 owner->view()->text->CursorRightOneWord();
1505 owner->view()->text->FinishUndo();
1506 moveCursorUpdate(false);
1507 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1511 if(!owner->view()->text->mark_set)
1512 owner->view()->beforeChange();
1513 owner->view()->update(-2);
1514 if (owner->view()->text->cursor.par->isRightToLeftPar())
1515 owner->view()->text->CursorRightOneWord();
1517 owner->view()->text->CursorLeftOneWord();
1518 owner->view()->text->FinishUndo();
1519 moveCursorUpdate(false);
1520 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1523 case LFUN_BEGINNINGBUF:
1524 if(!owner->view()->text->mark_set)
1525 owner->view()->beforeChange();
1526 owner->view()->update(-2);
1527 owner->view()->text->CursorTop();
1528 owner->view()->text->FinishUndo();
1529 moveCursorUpdate(false);
1530 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1534 if(!owner->view()->text->mark_set)
1535 owner->view()->beforeChange();
1536 owner->view()->update(-2);
1537 owner->view()->text->CursorBottom();
1538 owner->view()->text->FinishUndo();
1539 moveCursorUpdate(false);
1540 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1544 /* cursor selection ---------------------------- */
1546 owner->view()->update(-2);
1547 if (owner->view()->text->cursor.par->isRightToLeftPar())
1548 owner->view()->text->CursorLeft();
1550 owner->view()->text->CursorRight();
1551 owner->view()->text->FinishUndo();
1552 moveCursorUpdate(true);
1553 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1557 owner->view()->update(-2);
1558 if (owner->view()->text->cursor.par->isRightToLeftPar())
1559 owner->view()->text->CursorRight();
1561 owner->view()->text->CursorLeft();
1562 owner->view()->text->FinishUndo();
1563 moveCursorUpdate(true);
1564 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1568 owner->view()->update(-2);
1569 owner->view()->text->CursorUp();
1570 owner->view()->text->FinishUndo();
1571 moveCursorUpdate(true);
1572 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1576 owner->view()->update(-2);
1577 owner->view()->text->CursorDown();
1578 owner->view()->text->FinishUndo();
1579 moveCursorUpdate(true);
1580 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1583 case LFUN_UP_PARAGRAPHSEL:
1584 owner->view()->update(-2);
1585 owner->view()->text->CursorUpParagraph();
1586 owner->view()->text->FinishUndo();
1587 moveCursorUpdate(true);
1588 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1591 case LFUN_DOWN_PARAGRAPHSEL:
1592 owner->view()->update(-2);
1593 owner->view()->text->CursorDownParagraph();
1594 owner->view()->text->FinishUndo();
1595 moveCursorUpdate(true);
1596 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1600 owner->view()->update(-2);
1601 owner->view()->cursorPrevious();
1602 owner->view()->text->FinishUndo();
1603 moveCursorUpdate(true);
1604 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1608 owner->view()->update(-2);
1609 owner->view()->cursorNext();
1610 owner->view()->text->FinishUndo();
1611 moveCursorUpdate(true);
1612 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1616 owner->view()->update(-2);
1617 owner->view()->text->CursorHome();
1618 owner->view()->text->FinishUndo();
1619 moveCursorUpdate(true);
1620 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1624 owner->view()->update(-2);
1625 owner->view()->text->CursorEnd();
1626 owner->view()->text->FinishUndo();
1627 moveCursorUpdate(true);
1628 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1631 case LFUN_WORDRIGHTSEL:
1632 owner->view()->update(-2);
1633 if (owner->view()->text->cursor.par->isRightToLeftPar())
1634 owner->view()->text->CursorLeftOneWord();
1636 owner->view()->text->CursorRightOneWord();
1637 owner->view()->text->FinishUndo();
1638 moveCursorUpdate(true);
1639 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1642 case LFUN_WORDLEFTSEL:
1643 owner->view()->update(-2);
1644 if (owner->view()->text->cursor.par->isRightToLeftPar())
1645 owner->view()->text->CursorRightOneWord();
1647 owner->view()->text->CursorLeftOneWord();
1648 owner->view()->text->FinishUndo();
1649 moveCursorUpdate(true);
1650 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1653 case LFUN_BEGINNINGBUFSEL:
1654 owner->view()->update(-2);
1655 owner->view()->text->CursorTop();
1656 owner->view()->text->FinishUndo();
1657 moveCursorUpdate(true);
1658 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1661 case LFUN_ENDBUFSEL:
1662 owner->view()->update(-2);
1663 owner->view()->text->CursorBottom();
1664 owner->view()->text->FinishUndo();
1665 moveCursorUpdate(true);
1666 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1669 // --- text changing commands ------------------------
1670 case LFUN_BREAKLINE:
1672 owner->view()->beforeChange();
1673 owner->view()->text->InsertChar(LyXParagraph::META_NEWLINE);
1674 owner->view()->smallUpdate(1);
1675 SetUpdateTimer(0.01);
1676 moveCursorUpdate(false);
1678 owner->view()->newline();
1682 case LFUN_PROTECTEDSPACE:
1685 LyXLayout const & style =
1686 textclasslist.Style(owner->view()->buffer()->params.textclass,
1687 owner->view()->text->cursor.par->GetLayout());
1689 if (style.free_spacing) {
1690 owner->view()->text->InsertChar(' ');
1691 owner->view()->update(-1);
1693 owner->view()->protectedBlank();
1695 moveCursorUpdate(false);
1698 owner->view()->beforeChange();
1699 owner->view()->text->
1700 InsertChar(LyXParagraph::META_PROTECTED_SEPARATOR);
1701 owner->view()->smallUpdate(1);
1703 moveCursorUpdate(false);
1708 if(owner->view()->text->mark_set) {
1709 owner->view()->beforeChange();
1710 owner->view()->update(0);
1711 setMessage(N_("Mark removed"));
1713 owner->view()->beforeChange();
1714 owner->view()->text->mark_set = 1;
1715 owner->view()->update(0);
1716 setMessage(N_("Mark set"));
1718 owner->view()->text->sel_cursor =
1719 owner->view()->text->cursor;
1724 if (!owner->view()->text->selection) {
1725 owner->view()->text->Delete();
1726 owner->view()->text->sel_cursor =
1727 owner->view()->text->cursor;
1728 owner->view()->smallUpdate(1);
1729 // It is possible to make it a lot faster still
1730 // just comment out the lone below...
1731 owner->view()->showCursor();
1733 owner->view()->cut();
1736 moveCursorUpdate(false);
1737 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1738 owner->view()->setState();
1741 case LFUN_DELETE_SKIP:
1743 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1745 LyXCursor cursor = owner->view()->text->cursor;
1748 if (!owner->view()->text->selection) {
1749 if (cursor.pos == cursor.par->Last()) {
1750 owner->view()->text->CursorRight();
1751 cursor = owner->view()->text->cursor;
1753 && !(cursor.par->added_space_top
1754 == VSpace (VSpace::NONE))) {
1755 owner->view()->text->SetParagraph
1756 (cursor.par->line_top,
1757 cursor.par->line_bottom,
1758 cursor.par->pagebreak_top,
1759 cursor.par->pagebreak_bottom,
1760 VSpace(VSpace::NONE),
1761 cursor.par->added_space_bottom,
1763 cursor.par->labelwidthstring, 0);
1764 owner->view()->text->CursorLeft();
1765 owner->view()->update (1);
1767 owner->view()->text->CursorLeft();
1768 owner->view()->text->Delete();
1769 owner->view()->text->sel_cursor =
1770 owner->view()->text->cursor;
1771 owner->view()->smallUpdate(1);
1774 owner->view()->text->Delete();
1775 owner->view()->text->sel_cursor =
1776 owner->view()->text->cursor;
1777 owner->view()->smallUpdate(1);
1780 owner->view()->cut();
1786 /* -------> Delete word forward. */
1787 case LFUN_DELETE_WORD_FORWARD:
1788 owner->view()->update(-2);
1790 owner->view()->text->DeleteWordForward();
1791 owner->view()->update( 1 );
1793 moveCursorUpdate(false);
1794 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1797 /* -------> Delete word backward. */
1798 case LFUN_DELETE_WORD_BACKWARD:
1799 owner->view()->update(-2);
1801 owner->view()->text->DeleteWordBackward();
1802 owner->view()->update( 1 );
1804 moveCursorUpdate(false);
1805 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1808 /* -------> Kill to end of line. */
1809 case LFUN_DELETE_LINE_FORWARD:
1811 owner->view()->update(-2);
1812 owner->view()->text->DeleteLineForward();
1813 owner->view()->update( 1 );
1815 moveCursorUpdate(false);
1818 /* -------> Set mark off. */
1820 owner->view()->beforeChange();
1821 owner->view()->update(0);
1822 owner->view()->text->sel_cursor =
1823 owner->view()->text->cursor;
1824 setMessage(N_("Mark off"));
1827 /* -------> Set mark on. */
1829 owner->view()->beforeChange();
1830 owner->view()->text->mark_set = 1;
1831 owner->view()->update( 0 );
1832 owner->view()->text->sel_cursor =
1833 owner->view()->text->cursor;
1834 setMessage(N_("Mark on"));
1837 case LFUN_BACKSPACE:
1840 if (!owner->view()->text->selection) {
1841 if (owner->getIntl()->getTrans()->backspace()) {
1842 owner->view()->text->Backspace();
1843 owner->view()->text->sel_cursor =
1844 owner->view()->text->cursor;
1845 owner->view()->smallUpdate(1);
1846 // It is possible to make it a lot faster still
1847 // just comment out the lone below...
1848 owner->view()->showCursor();
1851 owner->view()->cut();
1854 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1855 owner->view()->setState();
1859 case LFUN_BACKSPACE_SKIP:
1861 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
1863 LyXCursor cursor = owner->view()->text->cursor;
1866 if (!owner->view()->text->selection) {
1868 && !(cursor.par->added_space_top
1869 == VSpace (VSpace::NONE))) {
1870 owner->view()->text->SetParagraph
1871 (cursor.par->line_top,
1872 cursor.par->line_bottom,
1873 cursor.par->pagebreak_top,
1874 cursor.par->pagebreak_bottom,
1875 VSpace(VSpace::NONE), cursor.par->added_space_bottom,
1877 cursor.par->labelwidthstring, 0);
1878 owner->view()->update (1);
1880 owner->view()->text->Backspace();
1881 owner->view()->text->sel_cursor
1883 owner->view()->smallUpdate (1);
1886 owner->view()->cut();
1891 case LFUN_BREAKPARAGRAPH:
1893 owner->view()->beforeChange();
1894 owner->view()->text->BreakParagraph(0);
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(owner->view()));
1904 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1906 owner->view()->beforeChange();
1907 owner->view()->text->BreakParagraph(1);
1908 owner->view()->smallUpdate(1);
1909 SetUpdateTimer(0.01);
1910 owner->view()->text->sel_cursor =
1911 owner->view()->text->cursor;
1912 owner->view()->setState();
1913 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1917 case LFUN_BREAKPARAGRAPH_SKIP:
1919 // When at the beginning of a paragraph, remove
1920 // indentation and add a "defskip" at the top.
1921 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
1923 LyXCursor cursor = owner->view()->text->cursor;
1925 owner->view()->beforeChange();
1926 if (cursor.pos == 0) {
1927 if (cursor.par->added_space_top == VSpace(VSpace::NONE)) {
1928 owner->view()->text->SetParagraph
1929 (cursor.par->line_top,
1930 cursor.par->line_bottom,
1931 cursor.par->pagebreak_top,
1932 cursor.par->pagebreak_bottom,
1933 VSpace(VSpace::DEFSKIP), cursor.par->added_space_bottom,
1935 cursor.par->labelwidthstring, 1);
1936 owner->view()->update(1);
1940 owner->view()->text->BreakParagraph(0);
1941 owner->view()->smallUpdate(1);
1943 SetUpdateTimer(0.01);
1944 owner->view()->text->sel_cursor = cursor;
1945 owner->view()->setState();
1946 owner->getMiniBuffer()->Set(CurrentState(owner->view()));
1950 case LFUN_PARAGRAPH_SPACING:
1952 LyXParagraph * par = owner->view()->text->cursor.par;
1953 Spacing::Space cur_spacing = par->spacing.getSpace();
1954 float cur_value = 1.0;
1955 if (cur_spacing == Spacing::Other) {
1956 cur_value = par->spacing.getValue();
1959 lyxerr << "all spacing arguments: " << argument << endl;
1960 istringstream istr(argument);
1963 lyxerr << "spacing = " << tmp << endl;
1964 Spacing::Space new_spacing = cur_spacing;
1965 float new_value = cur_value;
1966 if (tmp == "single") {
1967 new_spacing = Spacing::Single;
1968 } else if (tmp == "onehalf") {
1969 new_spacing = Spacing::Onehalf;
1970 } else if (tmp == "double") {
1971 new_spacing = Spacing::Double;
1972 } else if (tmp == "other") {
1973 new_spacing = Spacing::Other;
1976 lyxerr << "new_value = " << tmpval << endl;
1979 } else if (tmp == "default") {
1980 new_spacing = Spacing::Default;
1982 lyxerr << _("Unknown spacing argument: ")
1983 << argument << endl;
1985 if (cur_spacing != new_spacing || cur_value != new_value) {
1986 par->spacing.set(new_spacing, new_value);
1987 owner->view()->text->RedoParagraph();
1988 owner->view()->update(-1);
1994 owner->view()->beforeChange();
1995 owner->view()->text->InsertChar('\"'); // This " matches the single quote in the code
1996 owner->view()->smallUpdate(1);
1998 moveCursorUpdate(false);
2004 InsetCommand * new_inset;
2005 if (action == LFUN_HTMLURL)
2006 new_inset = new InsetUrl("htmlurl", "", "");
2008 new_inset = new InsetUrl("url", "", "");
2009 owner->view()->insertInset(new_inset);
2010 new_inset->Edit(owner->view(), 0, 0, 0);
2014 case LFUN_INSET_TEXT:
2016 InsetText * new_inset = new InsetText(owner->buffer());
2017 owner->view()->insertInset(new_inset);
2018 new_inset->Edit(owner->view(), 0, 0, 0);
2022 case LFUN_INSET_NUMBER:
2024 InsetNumber * new_inset = new InsetNumber(owner->buffer());
2025 owner->view()->insertInset(new_inset);
2026 new_inset->Edit(owner->view(), 0, 0, 0);
2030 case LFUN_INSET_ERT:
2032 InsetERT * new_inset = new InsetERT(owner->buffer());
2033 owner->view()->insertInset(new_inset);
2034 new_inset->Edit(owner->view(), 0, 0, 0);
2038 case LFUN_INSET_FOOTNOTE:
2040 InsetFoot * new_inset = new InsetFoot(owner->buffer());
2041 owner->view()->insertInset(new_inset);
2042 new_inset->Edit(owner->view(), 0, 0, 0);
2046 // --- lyxserver commands ----------------------------
2048 case LFUN_CHARATCURSOR:
2050 LyXParagraph::size_type pos =
2051 owner->view()->text->cursor.pos;
2052 if(pos < owner->view()->text->cursor.par->size())
2053 //dispatch_buffer = owner->view()->text->
2054 // cursor.par->text[pos];
2056 owner->view()->text->
2057 cursor.par->GetChar(pos);
2059 dispatch_buffer = "EOF";
2065 tostr(owner->view()->text->cursor.x) + ' '
2066 + tostr(owner->view()->text->cursor.y);
2073 sscanf(argument.c_str(), " %d %ld", &x, &y);
2074 owner->view()->text->SetCursorFromCoordinates(x, y);
2078 case LFUN_GETLAYOUT:
2080 tostr(owner->view()->text->cursor.par->layout);
2085 LyXFont & font = owner->view()->text->current_font;
2086 if(font.shape() == LyXFont::ITALIC_SHAPE)
2087 dispatch_buffer = 'E';
2088 else if(font.shape() == LyXFont::SMALLCAPS_SHAPE)
2089 dispatch_buffer = 'N';
2091 dispatch_buffer = '0';
2098 LyXFont & font = owner->view()->text->current_font;
2099 if(font.latex() == LyXFont::ON)
2100 dispatch_buffer = 'L';
2102 dispatch_buffer = '0';
2107 setMessage(owner->buffer()->fileName());
2108 lyxerr.debug() << "FNAME["
2109 << owner->buffer()->fileName()
2117 dispatch_buffer = buf;
2118 lyxserver->notifyClient(dispatch_buffer);
2122 case LFUN_GOTOFILEROW:
2124 char file_name[100];
2126 sscanf(argument.c_str(), " %s %d", file_name, &row);
2128 // Must replace extension of the file to be .lyx and get full path
2129 string s = ChangeExtension(string(file_name), ".lyx", false);
2131 // Either change buffer or load the file
2132 if (bufferlist.exists(s))
2133 owner->view()->buffer(bufferlist.getBuffer(s));
2135 owner->view()->buffer(bufferlist.loadLyXFile(s));
2138 owner->view()->setCursorFromRow(row);
2141 owner->view()->center();
2148 int qa = lyxaction.LookupFunc(argument.c_str());
2149 setMessage(lyxaction.helpText(static_cast<kb_action>(qa)));
2153 // --- accented characters ---------------------------
2156 case LFUN_CIRCUMFLEX:
2166 case LFUN_SPECIAL_CARON:
2169 case LFUN_HUNG_UMLAUT:
2175 if (keyseq.length == -1 && keyseq.getiso() != 0)
2176 c = keyseq.getiso();
2180 owner->getIntl()->getTrans()->
2181 deadkey(c, get_accent(action).accent,
2182 owner->view()->text);
2184 // Need to reset, in case the minibuffer calls these
2189 // copied verbatim from do_accent_char
2190 owner->view()->smallUpdate(1);
2192 owner->view()->text->sel_cursor =
2193 owner->view()->text->cursor;
2197 // --- toolbar ----------------------------------
2198 case LFUN_PUSH_TOOLBAR:
2200 int nth = strToInt(argument);
2201 if (lyxerr.debugging(Debug::TOOLBAR)) {
2202 lyxerr << "LFUN_PUSH_TOOLBAR: argument = `"
2203 << argument << "'\n"
2204 << "LFUN_PUSH_TOOLBAR: nth = `"
2205 << nth << "'" << endl;
2210 setErrorMessage(N_("Push-toolbar needs argument > 0"));
2212 owner->getToolbar()->push(nth);
2217 case LFUN_ADD_TO_TOOLBAR:
2219 if (lyxerr.debugging(Debug::TOOLBAR)) {
2220 lyxerr << "LFUN_ADD_TO_TOOLBAR:"
2221 "argument = `" << argument << '\'' << endl;
2223 string tmp(argument);
2224 //lyxerr <<string("Argument: ") + argument);
2225 //lyxerr <<string("Tmp : ") + tmp);
2228 setErrorMessage(N_("Usage: toolbar-add-to <LyX command>"));
2230 owner->getToolbar()->add(argument, false);
2231 owner->getToolbar()->set();
2236 // --- insert characters ----------------------------------------
2238 // --- Mathed stuff. If we are here, there is no locked inset yet.
2243 if (!greek_kb_flag) {
2245 setMessage(N_("Math greek mode on"));
2252 case LFUN_GREEK_TOGGLE:
2254 greek_kb_flag = greek_kb_flag ? 0 : 2;
2255 if (greek_kb_flag) {
2256 setMessage(N_("Math greek keyboard on"));
2258 setMessage(N_("Math greek keyboard off"));
2263 case LFUN_MATH_DELIM:
2264 case LFUN_INSERT_MATRIX:
2266 if (owner->view()->available()) {
2268 open_new_inset(new InsetFormula(false));
2271 ->LocalDispatch(owner->view(),
2278 case LFUN_INSERT_MATH:
2280 math_insert_symbol(argument.c_str());
2284 case LFUN_MATH_DISPLAY:
2286 if (owner->view()->available())
2287 owner->view()->open_new_inset(new InsetFormula(true));
2291 case LFUN_MATH_MACRO:
2293 if (owner->view()->available()) {
2296 setErrorMessage(N_("Missing argument"));
2298 string s1 = token(s, ' ', 1);
2299 int na = s1.empty() ? 0: atoi(s1.c_str());
2301 open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2307 case LFUN_MATH_MODE: // Open or create a math inset
2310 if (owner->view()->available())
2311 owner->view()->open_new_inset(new InsetFormula);
2312 setMessage(N_("Math editor mode"));
2316 case LFUN_MATH_NUMBER:
2317 case LFUN_MATH_LIMITS:
2319 setErrorMessage(N_("This is only allowed in math mode!"));
2323 case LFUN_INSERT_CITATION:
2325 InsetCitation * new_inset = new InsetCitation();
2327 // The note, if any, must be after the key, delimited
2328 // by a | so both key and remark can have spaces.
2329 if (!argument.empty()) {
2330 string lsarg(argument);
2331 if (contains(lsarg, "|")) {
2332 new_inset->setContents(token(lsarg, '|', 0));
2333 new_inset->setOptions(token(lsarg, '|', 1));
2335 new_inset->setContents(lsarg);
2336 owner->view()->insertInset(new_inset);
2338 owner->view()->insertInset(new_inset);
2339 new_inset->Edit(owner->view(), 0, 0, 0);
2344 case LFUN_INSERT_BIBTEX:
2346 // ale970405+lasgoutt970425
2347 // The argument can be up to two tokens separated
2348 // by a space. The first one is the bibstyle.
2349 string lsarg(argument);
2350 string bibstyle = token(lsarg, ' ', 1);
2351 if (bibstyle.empty())
2353 InsetBibtex * new_inset
2354 = new InsetBibtex(token(lsarg, ' ', 0),
2358 owner->view()->insertInset(new_inset);
2359 if (lsarg.empty()) {
2360 new_inset->Edit(owner->view(), 0, 0, 0);
2365 // BibTeX data bases
2366 case LFUN_BIBDB_ADD:
2368 InsetBibtex * inset =
2369 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2371 inset->addDatabase(argument);
2376 case LFUN_BIBDB_DEL:
2378 InsetBibtex * inset =
2379 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2381 inset->delDatabase(argument);
2386 case LFUN_BIBTEX_STYLE:
2388 InsetBibtex * inset =
2389 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2391 inset->setOptions(argument);
2396 case LFUN_INDEX_INSERT:
2397 case LFUN_INDEX_INSERT_LAST:
2399 // Can't do that at the beginning of a paragraph.
2400 if (owner->view()->text->cursor.pos - 1 < 0)
2403 InsetIndex * new_inset = new InsetIndex();
2404 if (!argument.empty()) {
2405 string lsarg(argument);
2406 new_inset->setContents(lsarg);
2407 owner->view()->insertInset(new_inset);
2410 //get the current word for an argument
2411 LyXParagraph::size_type lastpos =
2412 owner->view()->text->cursor.pos - 1;
2413 // Get the current word. note that this must be done
2414 // before inserting the inset, or the inset will
2416 string curstring(owner->view()
2417 ->text->cursor.par->GetWord(lastpos));
2419 //make the new inset and write the current word into it
2420 InsetIndex * new_inset = new InsetIndex();
2422 new_inset->setContents(curstring);
2424 //don't edit it if the call was to INSERT_LAST
2425 if(action != LFUN_INDEX_INSERT_LAST) {
2426 new_inset->Edit(owner->view(), 0, 0, 0);
2428 //it looks blank on the screen unless
2429 //we do something. put it here.
2431 // move the cursor to the returned value of lastpos
2432 // but only for the auto-insert
2433 owner->view()->text->cursor.pos = lastpos;
2436 //put the new inset into the buffer.
2437 // there should be some way of knowing the user
2438 //cancelled & avoiding this, but i don't know how
2439 owner->view()->insertInset(new_inset);
2444 case LFUN_INDEX_PRINT:
2446 Inset * new_inset = new InsetPrintIndex(owner->buffer());
2447 owner->view()->insertInset(new_inset, "Standard", true);
2451 case LFUN_PARENTINSERT:
2453 lyxerr << "arg " << argument << endl;
2454 Inset * new_inset = new InsetParent(argument, owner->buffer());
2455 owner->view()->insertInset(new_inset, "Standard", true);
2459 case LFUN_CHILDINSERT:
2461 Inset * new_inset = new InsetInclude(argument,
2463 owner->view()->insertInset(new_inset, "Standard", true);
2464 new_inset->Edit(owner->view(), 0, 0, 0);
2468 case LFUN_CHILDOPEN:
2471 MakeAbsPath(argument,
2472 OnlyPath(owner->buffer()->fileName()));
2473 setMessage(N_("Opening child document ") +
2474 MakeDisplayPath(filename) + "...");
2475 owner->view()->savePosition();
2476 if (bufferlist.exists(filename))
2477 owner->view()->buffer(bufferlist.getBuffer(filename));
2479 owner->view()->buffer(bufferlist.loadLyXFile(filename));
2483 case LFUN_INSERT_NOTE:
2484 owner->view()->insertNote();
2487 case LFUN_INSERTFOOTNOTE:
2489 LyXParagraph::footnote_kind kind;
2490 if (argument == "footnote")
2491 { kind = LyXParagraph::FOOTNOTE; }
2492 else if (argument == "margin")
2493 { kind = LyXParagraph::MARGIN; }
2494 else if (argument == "figure")
2495 { kind = LyXParagraph::FIG; }
2496 else if (argument == "table")
2497 { kind = LyXParagraph::TAB; }
2498 else if (argument == "wide-fig")
2499 { kind = LyXParagraph::WIDE_FIG; }
2500 else if (argument == "wide-tab")
2501 { kind = LyXParagraph::WIDE_TAB; }
2502 else if (argument == "algorithm")
2503 { kind = LyXParagraph::ALGORITHM; }
2505 setErrorMessage(N_("Unknown kind of footnote"));
2508 owner->view()->text->InsertFootnoteEnvironment(kind);
2509 owner->view()->update(1);
2510 owner->view()->setState();
2514 case LFUN_BUFFERBULLETSSELECT:
2518 case LFUN_TOGGLECURSORFOLLOW:
2519 cursor_follows_scrollbar = !cursor_follows_scrollbar;
2522 case LFUN_KMAP_OFF: // keymap off
2523 owner->getIntl()->KeyMapOn(false);
2526 case LFUN_KMAP_PRIM: // primary keymap
2527 owner->getIntl()->KeyMapPrim();
2530 case LFUN_KMAP_SEC: // secondary keymap
2531 owner->getIntl()->KeyMapSec();
2534 case LFUN_KMAP_TOGGLE: // toggle keymap
2535 owner->getIntl()->ToggleKeyMap();
2538 case LFUN_SELFINSERT:
2540 for (string::size_type i = 0; i < argument.length(); ++i) {
2541 owner->view()->text->InsertChar(argument[i]);
2542 // This needs to be in the loop, or else we
2543 // won't break lines correctly. (Asger)
2544 owner->view()->smallUpdate(1);
2547 owner->view()->text->sel_cursor =
2548 owner->view()->text->cursor;
2549 moveCursorUpdate(false);
2555 // argument contains ';'-terminated commands
2556 while (argument.find(';') != string::npos) {
2558 argument = split(argument, first, ';');
2564 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
2572 now_time_t = time(NULL);
2573 now_tm = localtime(&now_time_t);
2574 (void)setlocale(LC_TIME, "");
2575 if (!argument.empty())
2577 else if (arg.empty())
2578 arg = lyxrc.date_insert_format;
2579 datetmp_len = (int) strftime(datetmp, 32, arg.c_str(), now_tm);
2580 for (int i = 0; i < datetmp_len; i++) {
2581 owner->view()->text->InsertChar(datetmp[i]);
2582 owner->view()->smallUpdate(1);
2585 owner->view()->text->sel_cursor = owner->view()->text->cursor;
2586 moveCursorUpdate(false);
2590 case LFUN_SAVEPREFERENCES:
2592 Path p(user_lyxdir);
2593 lyxrc.write("preferences");
2597 case LFUN_UNKNOWN_ACTION:
2599 if(!owner->buffer()) {
2601 setErrorMessage(N_("No document open"));
2605 if (owner->buffer()->isReadonly()) {
2607 setErrorMessage(N_("Document is read only"));
2611 if (!argument.empty()) {
2613 /* Automatically delete the currently selected
2614 * text and replace it with what is being
2615 * typed in now. Depends on lyxrc settings
2616 * "auto_region_delete", which defaults to
2619 if ( lyxrc.auto_region_delete ) {
2620 if (owner->view()->text->selection){
2621 owner->view()->text->CutSelection(false);
2622 owner->view()->update(-1);
2626 owner->view()->beforeChange();
2629 if (isdigit(argument[0]) &&
2630 (lyxrc.number_inset == "true" ||
2631 (lyxrc.number_inset == "rtl" &&
2632 owner->view()->text->real_current_font.isVisibleRightToLeft()
2634 UpdatableInset * tmpinset = new InsetNumber(owner->buffer());
2635 owner->view()->open_new_inset(tmpinset);
2636 tmpinset->LocalDispatch(owner->view(), action,
2642 for (string::size_type i = 0;
2643 i < argument.length(); ++i) {
2644 if (greek_kb_flag) {
2645 if (!math_insert_greek(argument[i]))
2646 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2648 owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
2651 owner->view()->smallUpdate(1);
2654 owner->view()->text->sel_cursor =
2655 owner->view()->text->cursor;
2656 moveCursorUpdate(false);
2659 // why is an "Unknown action" with empty
2660 // argument even dispatched in the first
2661 // place? I`ll probably change that. (Lgb)
2663 setErrorMessage(N_("Unknown action"));
2667 lyxerr << "A truly unknown func!" << endl;
2673 string res = getMessage();
2676 if (!commandshortcut.empty()) {
2677 string newbuf = owner->getMiniBuffer()->GetText();
2678 if (newbuf != commandshortcut) {
2679 owner->getMiniBuffer()->Set(newbuf
2685 owner->getMiniBuffer()->Set(string(_(res.c_str()))
2686 + " " + commandshortcut);
2693 void LyXFunc::setupLocalKeymap()
2695 keyseq.stdmap = keyseq.curmap = toplevel_keymap;
2696 cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap;
2700 void LyXFunc::MenuNew(bool fromTemplate)
2702 string fname, initpath = lyxrc.document_path;
2705 if (owner->view()->available()) {
2706 string trypath = owner->buffer()->filepath;
2707 // If directory is writeable, use this as default.
2708 if (IsDirWriteable(trypath) == 1)
2712 ProhibitInput(owner->view());
2713 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
2714 fileDlg.SetButton(1, _("Templates"), lyxrc.template_path);
2715 fname = fileDlg.Select(_("Enter Filename for new document"),
2716 initpath, "*.lyx", _("newfile"));
2717 AllowInput(owner->view());
2719 if (fname.empty()) {
2720 owner->getMiniBuffer()->Set(_("Canceled."));
2721 lyxerr.debug() << "New Document Cancelled." << endl;
2725 // get absolute path of file and make sure the filename ends
2727 string s = MakeAbsPath(fname);
2728 if (!IsLyXFilename(s))
2731 // Check if the document already is open
2732 if (bufferlist.exists(s)){
2733 switch(AskConfirmation(_("Document is already open:"),
2734 MakeDisplayPath(s, 50),
2735 _("Do you want to close that document now?\n"
2736 "('No' will just switch to the open version)")))
2738 case 1: // Yes: close the document
2739 if (!bufferlist.close(bufferlist.getBuffer(s)))
2740 // If close is canceled, we cancel here too.
2743 case 2: // No: switch to the open document
2744 owner->view()->buffer(bufferlist.getBuffer(s));
2746 case 3: // Cancel: Do nothing
2747 owner->getMiniBuffer()->Set(_("Canceled."));
2752 // Check whether the file already exists
2753 if (IsLyXFilename(s)) {
2755 if (fi.readable() &&
2756 AskQuestion(_("File already exists:"),
2757 MakeDisplayPath(s, 50),
2758 _("Do you want to open the document?"))) {
2760 owner->getMiniBuffer()->Set(_("Opening document"),
2761 MakeDisplayPath(s), "...");
2763 owner->view()->buffer(
2764 bufferlist.loadLyXFile(s));
2765 owner->getMiniBuffer()->Set(_("Document"),
2772 // The template stuff
2775 ProhibitInput(owner->view());
2776 fname = fileDlg.Select(_("Choose template"),
2777 lyxrc.template_path,
2780 AllowInput(owner->view());
2783 // find a free buffer
2784 lyxerr.debug() << "Find a free buffer." << endl;
2785 owner->view()->buffer(bufferlist.newFile(s, templname));
2789 void LyXFunc::MenuOpen()
2791 string initpath = lyxrc.document_path;
2794 if (owner->view()->available()) {
2795 string trypath = owner->buffer()->filepath;
2796 // If directory is writeable, use this as default.
2797 if (IsDirWriteable(trypath) == 1)
2802 ProhibitInput(owner->view());
2803 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
2804 fileDlg.SetButton(1, _("Examples"),
2805 AddPath(system_lyxdir, "examples"));
2806 string filename = fileDlg.Select(_("Select Document to Open"),
2808 AllowInput(owner->view());
2810 // check selected filename
2811 if (filename.empty()) {
2812 owner->getMiniBuffer()->Set(_("Canceled."));
2816 // get absolute path of file and make sure the filename ends
2818 filename = MakeAbsPath(filename);
2819 if (!IsLyXFilename(filename))
2823 owner->getMiniBuffer()->Set(_("Opening document"),
2824 MakeDisplayPath(filename), "...");
2825 Buffer * openbuf = bufferlist.loadLyXFile(filename);
2827 owner->view()->buffer(openbuf);
2828 owner->getMiniBuffer()->Set(_("Document"),
2829 MakeDisplayPath(filename),
2832 owner->getMiniBuffer()->Set(_("Could not open document"),
2833 MakeDisplayPath(filename));
2838 void LyXFunc::doImportASCII(bool linorpar)
2840 string initpath = lyxrc.document_path;
2843 if (owner->view()->available()) {
2844 string trypath = owner->buffer()->filepath;
2845 // If directory is writeable, use this as default.
2846 if (IsDirWriteable(trypath) == 1)
2851 ProhibitInput(owner->view());
2852 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
2853 fileDlg.SetButton(1, _("Examples"),
2854 AddPath(system_lyxdir, "examples"));
2855 string filename = fileDlg.Select(_("Select ASCII file to Import"),
2857 AllowInput(owner->view());
2859 // check selected filename
2860 if (filename.empty()) {
2861 owner->getMiniBuffer()->Set(_("Canceled."));
2865 // get absolute path of file
2866 filename = MakeAbsPath(filename);
2868 string s = ChangeExtension(filename, ".lyx", false);
2870 // Check if the document already is open
2871 if (bufferlist.exists(s)) {
2872 switch(AskConfirmation(_("Document is already open:"),
2873 MakeDisplayPath(s, 50),
2874 _("Do you want to close that document now?\n"
2875 "('No' will just switch to the open version)")))
2877 case 1: // Yes: close the document
2878 if (!bufferlist.close(bufferlist.getBuffer(s)))
2879 // If close is canceled, we cancel here too.
2882 case 2: // No: switch to the open document
2883 owner->view()->buffer(bufferlist.getBuffer(s));
2885 case 3: // Cancel: Do nothing
2886 owner->getMiniBuffer()->Set(_("Canceled."));
2891 // Check if a LyX document by the same root exists in filesystem
2892 FileInfo f(s, true);
2893 if (f.exist() && !AskQuestion(_("A document by the name"),
2895 _("already exists. Overwrite?"))) {
2896 owner->getMiniBuffer()->Set(_("Canceled."));
2900 owner->view()->buffer(bufferlist.newFile(s, string()));
2901 owner->getMiniBuffer()->Set(_("Importing ASCII file"),
2902 MakeDisplayPath(filename), "...");
2903 // Insert ASCII file
2904 InsertAsciiFile(owner->view(), filename, linorpar);
2905 owner->getMiniBuffer()->Set(_("ASCII file "),
2906 MakeDisplayPath(filename),
2911 void LyXFunc::doImportLaTeX(bool isnoweb)
2913 string initpath = lyxrc.document_path;
2916 if (owner->view()->available()) {
2917 string trypath = owner->buffer()->filepath;
2918 // If directory is writeable, use this as default.
2919 if (IsDirWriteable(trypath) == 1)
2924 ProhibitInput(owner->view());
2925 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
2926 fileDlg.SetButton(1, _("Examples"),
2927 AddPath(system_lyxdir, "examples"));
2930 filename = fileDlg.Select(_("Select Noweb file to Import"),
2933 filename = fileDlg.Select(_("Select LaTeX file to Import"),
2937 AllowInput(owner->view());
2939 // check selected filename
2940 if (filename.empty()) {
2941 owner->getMiniBuffer()->Set(_("Canceled."));
2945 // get absolute path of file
2946 filename = MakeAbsPath(filename);
2948 // Check if the document already is open
2949 string LyXfilename = ChangeExtension(filename, ".lyx", false);
2950 if (bufferlist.exists(LyXfilename)){
2951 switch(AskConfirmation(_("Document is already open:"),
2952 MakeDisplayPath(LyXfilename, 50),
2953 _("Do you want to close that document now?\n"
2954 "('No' will just switch to the open version)")))
2956 case 1: // Yes: close the document
2957 if (!bufferlist.close(bufferlist.getBuffer(LyXfilename)))
2958 // If close is canceled, we cancel here too.
2961 case 2: // No: switch to the open document
2962 owner->view()->buffer(
2963 bufferlist.getBuffer(LyXfilename));
2965 case 3: // Cancel: Do nothing
2966 owner->getMiniBuffer()->Set(_("Canceled."));
2971 // Check if a LyX document by the same root exists in filesystem
2972 FileInfo f(LyXfilename, true);
2973 if (f.exist() && !AskQuestion(_("A document by the name"),
2974 MakeDisplayPath(LyXfilename),
2975 _("already exists. Overwrite?"))) {
2976 owner->getMiniBuffer()->Set(_("Canceled."));
2983 owner->getMiniBuffer()->Set(_("Importing LaTeX file"),
2984 MakeDisplayPath(filename), "...");
2985 ImportLaTeX myImport(filename);
2986 openbuf = myImport.run();
2988 owner->getMiniBuffer()->Set(_("Importing Noweb file"),
2989 MakeDisplayPath(filename), "...");
2990 ImportNoweb myImport(filename);
2991 openbuf = myImport.run();
2994 owner->view()->buffer(openbuf);
2995 owner->getMiniBuffer()->Set(isnoweb ?
2996 _("Noweb file ") : _("LateX file "),
2997 MakeDisplayPath(filename),
3000 owner->getMiniBuffer()->Set(isnoweb ?
3001 _("Could not import Noweb file") :
3002 _("Could not import LaTeX file"),
3003 MakeDisplayPath(filename));
3008 void LyXFunc::doImportLinuxDoc()
3010 string initpath = lyxrc.document_path;
3013 if (owner->view()->available()) {
3014 string trypath = owner->buffer()->filepath;
3015 // If directory is writeable, use this as default.
3016 if (IsDirWriteable(trypath) == 1)
3021 ProhibitInput(owner->view());
3022 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
3023 fileDlg.SetButton(1, _("Examples"),
3024 AddPath(system_lyxdir, "examples"));
3026 string filename = fileDlg.Select(_("Select LinuxDoc file to Import"),
3027 initpath, "*.sgml");
3029 AllowInput(owner->view());
3031 // check selected filename
3032 if (filename.empty()) {
3033 owner->getMiniBuffer()->Set(_("Canceled."));
3037 // get absolute path of file
3038 filename = MakeAbsPath(filename);
3040 // Check if the document already is open
3041 string LyXfilename = ChangeExtension(filename, ".lyx", false);
3042 if (bufferlist.exists(LyXfilename)){
3043 switch(AskConfirmation(_("Document is already open:"),
3044 MakeDisplayPath(LyXfilename, 50),
3045 _("Do you want to close that document now?\n"
3046 "('No' will just switch to the open version)")))
3048 case 1: // Yes: close the document
3049 if (!bufferlist.close(bufferlist.getBuffer(LyXfilename)))
3050 // If close is canceled, we cancel here too.
3053 case 2: // No: switch to the open document
3054 owner->view()->buffer(
3055 bufferlist.getBuffer(LyXfilename));
3057 case 3: // Cancel: Do nothing
3058 owner->getMiniBuffer()->Set(_("Canceled."));
3063 // Check if a LyX document by the same root exists in filesystem
3064 FileInfo f(LyXfilename, true);
3065 if (f.exist() && !AskQuestion(_("A document by the name"),
3066 MakeDisplayPath(LyXfilename),
3067 _("already exists. Overwrite?"))) {
3068 owner->getMiniBuffer()->Set(_("Canceled."));
3073 owner->getMiniBuffer()->Set(_("Importing LinuxDoc file"),
3074 MakeDisplayPath(filename), "...");
3077 string tmp = lyxrc.linuxdoc_to_lyx_command + filename;
3081 int result = one.startscript(Systemcalls::System, tmp);
3083 string filename = ChangeExtension(filename, ".lyx", false);
3084 // File was generated without problems. Load it.
3085 buf = bufferlist.loadLyXFile(filename);
3086 owner->view()->buffer(buf);
3087 owner->getMiniBuffer()->Set(_("LinuxDoc file "),
3088 MakeDisplayPath(filename),
3091 owner->getMiniBuffer()->Set(_("Could not import LinuxDoc file"),
3092 MakeDisplayPath(filename));
3097 void LyXFunc::MenuInsertLyXFile(string const & filen)
3099 string filename = filen;
3101 if (filename.empty()) {
3102 // Launch a file browser
3103 string initpath = lyxrc.document_path;
3106 if (owner->view()->available()) {
3107 string trypath = owner->buffer()->filepath;
3108 // If directory is writeable, use this as default.
3109 if (IsDirWriteable(trypath) == 1)
3114 ProhibitInput(owner->view());
3115 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
3116 fileDlg.SetButton(1, _("Examples"),
3117 AddPath(system_lyxdir, "examples"));
3118 filename = fileDlg.Select(_("Select Document to Insert"),
3120 AllowInput(owner->view());
3122 // check selected filename
3123 if (filename.empty()) {
3124 owner->getMiniBuffer()->Set(_("Canceled."));
3129 // get absolute path of file and make sure the filename ends
3131 filename = MakeAbsPath(filename);
3132 if (!IsLyXFilename(filename))
3136 owner->getMiniBuffer()->Set(_("Inserting document"),
3137 MakeDisplayPath(filename), "...");
3138 bool res = owner->view()->insertLyXFile(filename);
3140 owner->getMiniBuffer()->Set(_("Document"),
3141 MakeDisplayPath(filename),
3144 owner->getMiniBuffer()->Set(_("Could not insert document"),
3145 MakeDisplayPath(filename));
3150 void LyXFunc::reloadBuffer()
3152 string fn = owner->buffer()->fileName();
3153 if (bufferlist.close(owner->buffer()))
3154 owner->view()->buffer(bufferlist.loadLyXFile(fn));
3158 void LyXFunc::CloseBuffer()
3160 if (bufferlist.close(owner->buffer()) && !quitting) {
3161 if (bufferlist.empty()) {
3162 // need this otherwise SEGV may occur while trying to
3163 // set variables that don't exist
3164 // since there's no current buffer
3165 CloseAllBufferRelatedPopups();
3168 owner->view()->buffer(bufferlist.first());
3174 Inset * LyXFunc::getInsetByCode(Inset::Code code)
3178 LyXCursor cursor = owner->view()->text->cursor;
3179 LyXParagraph::size_type pos = cursor.pos;
3180 LyXParagraph * par = cursor.par;
3182 while (par && !found) {
3183 while ((inset = par->ReturnNextInsetPointer(pos))){
3184 if (inset->LyxCode() == code) {
3192 return found ? inset : 0;
3196 // Each "owner" should have it's own message method. lyxview and
3197 // the minibuffer would use the minibuffer, but lyxserver would
3198 // send an ERROR signal to its client. Alejandro 970603
3199 // This func is bit problematic when it comes to NLS, to make the
3200 // lyx servers client be language indepenent we must not translate
3201 // strings sent to this func.
3202 void LyXFunc::setErrorMessage(string const & m) const
3204 dispatch_buffer = m;
3209 void LyXFunc::setMessage(string const & m)
3211 dispatch_buffer = m;