3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Alfredo Braunstein
7 * \author Lars Gullik Bjønnes
8 * \author Jean-Marc Lasgouttes
9 * \author Angus Leeming
11 * \author André Pönitz
14 * \author Martin Vermeer
15 * \author Jürgen Vigna
17 * Full author contact details are available in file CREDITS.
24 #include "LayoutFile.h"
25 #include "BranchList.h"
26 #include "buffer_funcs.h"
28 #include "BufferList.h"
29 #include "BufferParams.h"
30 #include "BufferView.h"
33 #include "Converter.h"
35 #include "CutAndPaste.h"
36 #include "DispatchResult.h"
38 #include "ErrorList.h"
40 #include "FuncRequest.h"
41 #include "FuncStatus.h"
42 #include "InsetIterator.h"
47 #include "LyXAction.h"
52 #include "Paragraph.h"
53 #include "ParagraphParameters.h"
54 #include "ParIterator.h"
59 #include "insets/InsetBox.h"
60 #include "insets/InsetBranch.h"
61 #include "insets/InsetCommand.h"
62 #include "insets/InsetERT.h"
63 #include "insets/InsetExternal.h"
64 #include "insets/InsetFloat.h"
65 #include "insets/InsetListings.h"
66 #include "insets/InsetGraphics.h"
67 #include "insets/InsetInclude.h"
68 #include "insets/InsetSpace.h"
69 #include "insets/InsetTabular.h"
70 #include "insets/InsetVSpace.h"
71 #include "insets/InsetWrap.h"
73 #include "frontends/alert.h"
74 #include "frontends/Application.h"
75 #include "frontends/KeySymbol.h"
76 #include "frontends/LyXView.h"
77 #include "frontends/Selection.h"
79 #include "support/debug.h"
80 #include "support/environment.h"
81 #include "support/FileName.h"
82 #include "support/filetools.h"
83 #include "support/gettext.h"
84 #include "support/lstrings.h"
85 #include "support/Path.h"
86 #include "support/Package.h"
87 #include "support/Systemcall.h"
88 #include "support/convert.h"
89 #include "support/os.h"
95 using namespace lyx::support;
99 using frontend::LyXView;
101 namespace Alert = frontend::Alert;
106 // This function runs "configure" and then rereads lyx.defaults to
107 // reconfigure the automatic settings.
108 void reconfigure(LyXView * lv, string const & option)
110 // emit message signal.
112 lv->message(_("Running configure..."));
114 // Run configure in user lyx directory
115 PathChanger p(package().user_support());
116 string configure_command = package().configure_command();
117 configure_command += option;
119 int ret = one.startscript(Systemcall::Wait, configure_command);
121 // emit message signal.
123 lv->message(_("Reloading configuration..."));
124 lyxrc.read(libFileSearch(string(), "lyxrc.defaults"));
125 // Re-read packages.lst
126 LaTeXFeatures::getAvailable();
129 Alert::information(_("System reconfiguration failed"),
130 _("The system reconfiguration has failed.\n"
131 "Default textclass is used but LyX may "
132 "not be able to work properly.\n"
133 "Please reconfigure again if needed."));
136 Alert::information(_("System reconfigured"),
137 _("The system has been reconfigured.\n"
138 "You need to restart LyX to make use of any\n"
139 "updated document class specifications."));
143 bool getLocalStatus(Cursor cursor, FuncRequest const & cmd, FuncStatus & status)
145 // Try to fix cursor in case it is broken.
146 cursor.fixIfBroken();
148 // This is, of course, a mess. Better create a new doc iterator and use
149 // this in Inset::getStatus. This might require an additional
150 // BufferView * arg, though (which should be avoided)
151 //Cursor safe = *this;
153 for ( ; cursor.depth(); cursor.pop()) {
154 //lyxerr << "\nCursor::getStatus: cmd: " << cmd << endl << *this << endl;
155 LASSERT(cursor.idx() <= cursor.lastidx(), /**/);
156 LASSERT(cursor.pit() <= cursor.lastpit(), /**/);
157 LASSERT(cursor.pos() <= cursor.lastpos(), /**/);
159 // The inset's getStatus() will return 'true' if it made
160 // a definitive decision on whether it want to handle the
161 // request or not. The result of this decision is put into
162 // the 'status' parameter.
163 if (cursor.inset().getStatus(cursor, cmd, status)) {
172 /** Return the change status at cursor position, taking in account the
173 * status at each level of the document iterator (a table in a deleted
174 * footnote is deleted).
175 * When \param outer is true, the top slice is not looked at.
177 Change::Type lookupChangeType(DocIterator const & dit, bool outer = false)
179 size_t const depth = dit.depth() - (outer ? 1 : 0);
181 for (size_t i = 0 ; i < depth ; ++i) {
182 CursorSlice const & slice = dit[i];
183 if (!slice.inset().inMathed()
184 && slice.pos() < slice.paragraph().size()) {
185 Change::Type const ch = slice.paragraph().lookupChange(slice.pos()).type;
186 if (ch != Change::UNCHANGED)
190 return Change::UNCHANGED;
197 : lyx_view_(0), encoded_last_key(0), meta_fake_bit(NoModifier)
202 void LyXFunc::initKeySequences(KeyMap * kb)
204 keyseq = KeySequence(kb, kb);
205 cancel_meta_seq = KeySequence(kb, kb);
209 void LyXFunc::setLyXView(LyXView * lv)
211 if (lyx_view_ && lyx_view_->view() && lyx_view_ != lv)
212 // save current selection to the selection buffer to allow
213 // middle-button paste in another window
214 cap::saveSelection(lyx_view_->view()->cursor());
219 void LyXFunc::handleKeyFunc(FuncCode action)
221 char_type c = encoded_last_key;
226 LASSERT(lyx_view_ && lyx_view_->view(), /**/);
227 lyx_view_->view()->getIntl().getTransManager().deadkey(
228 c, get_accent(action).accent, view()->cursor().innerText(), view()->cursor());
229 // Need to clear, in case the minibuffer calls these
232 // copied verbatim from do_accent_char
233 view()->cursor().resetAnchor();
234 view()->processUpdateFlags(Update::FitCursor);
237 //FIXME: bookmark handling is a frontend issue. This code should be transferred
238 // to GuiView and be GuiView and be window dependent.
239 void LyXFunc::gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer)
241 LASSERT(lyx_view_, /**/);
242 if (!LyX::ref().session().bookmarks().isValid(idx))
244 BookmarksSection::Bookmark const & bm = LyX::ref().session().bookmarks().bookmark(idx);
245 LASSERT(!bm.filename.empty(), /**/);
246 string const file = bm.filename.absFilename();
247 // if the file is not opened, open it.
248 if (!theBufferList().exists(file)) {
250 dispatch(FuncRequest(LFUN_FILE_OPEN, file));
254 // open may fail, so we need to test it again
255 if (!theBufferList().exists(file))
258 // if the current buffer is not that one, switch to it.
259 if (lyx_view_->buffer()->absFileName() != file) {
262 dispatch(FuncRequest(LFUN_BUFFER_SWITCH, file));
264 // moveToPosition try paragraph id first and then paragraph (pit, pos).
265 if (!view()->moveToPosition(bm.bottom_pit, bm.bottom_pos,
266 bm.top_id, bm.top_pos))
269 // Cursor jump succeeded!
270 Cursor const & cur = view()->cursor();
271 pit_type new_pit = cur.pit();
272 pos_type new_pos = cur.pos();
273 int new_id = cur.paragraph().id();
275 // if bottom_pit, bottom_pos or top_id has been changed, update bookmark
276 // see http://bugzilla.lyx.org/show_bug.cgi?id=3092
277 if (bm.bottom_pit != new_pit || bm.bottom_pos != new_pos
278 || bm.top_id != new_id) {
279 const_cast<BookmarksSection::Bookmark &>(bm).updatePos(
280 new_pit, new_pos, new_id);
285 void LyXFunc::processKeySym(KeySymbol const & keysym, KeyModifier state)
287 LYXERR(Debug::KEY, "KeySym is " << keysym.getSymbolName());
289 // Do nothing if we have nothing (JMarc)
290 if (!keysym.isOK()) {
291 LYXERR(Debug::KEY, "Empty kbd action (probably composing)");
292 lyx_view_->restartCursor();
296 if (keysym.isModifier()) {
297 LYXERR(Debug::KEY, "isModifier true");
299 lyx_view_->restartCursor();
303 //Encoding const * encoding = view()->cursor().getEncoding();
304 //encoded_last_key = keysym.getISOEncoded(encoding ? encoding->name() : "");
305 // FIXME: encoded_last_key shadows the member variable of the same
306 // name. Is that intended?
307 char_type encoded_last_key = keysym.getUCSEncoded();
309 // Do a one-deep top-level lookup for
310 // cancel and meta-fake keys. RVDK_PATCH_5
311 cancel_meta_seq.reset();
313 FuncRequest func = cancel_meta_seq.addkey(keysym, state);
314 LYXERR(Debug::KEY, "action first set to [" << func.action << ']');
316 // When not cancel or meta-fake, do the normal lookup.
317 // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
318 // Mostly, meta_fake_bit = NoModifier. RVDK_PATCH_5.
319 if ((func.action != LFUN_CANCEL) && (func.action != LFUN_META_PREFIX)) {
320 // remove Caps Lock and Mod2 as a modifiers
321 func = keyseq.addkey(keysym, (state | meta_fake_bit));
322 LYXERR(Debug::KEY, "action now set to [" << func.action << ']');
325 // Dont remove this unless you know what you are doing.
326 meta_fake_bit = NoModifier;
328 // Can this happen now ?
329 if (func.action == LFUN_NOACTION)
330 func = FuncRequest(LFUN_COMMAND_PREFIX);
332 LYXERR(Debug::KEY, " Key [action=" << func.action << "]["
333 << keyseq.print(KeySequence::Portable) << ']');
335 // already here we know if it any point in going further
336 // why not return already here if action == -1 and
337 // num_bytes == 0? (Lgb)
339 if (keyseq.length() > 1)
340 lyx_view_->message(keyseq.print(KeySequence::ForGui));
343 // Maybe user can only reach the key via holding down shift.
344 // Let's see. But only if shift is the only modifier
345 if (func.action == LFUN_UNKNOWN_ACTION && state == ShiftModifier) {
346 LYXERR(Debug::KEY, "Trying without shift");
347 func = keyseq.addkey(keysym, NoModifier);
348 LYXERR(Debug::KEY, "Action now " << func.action);
351 if (func.action == LFUN_UNKNOWN_ACTION) {
352 // Hmm, we didn't match any of the keysequences. See
353 // if it's normal insertable text not already covered
355 if (keysym.isText() && keyseq.length() == 1) {
356 LYXERR(Debug::KEY, "isText() is true, inserting.");
357 func = FuncRequest(LFUN_SELF_INSERT,
358 FuncRequest::KEYBOARD);
360 LYXERR(Debug::KEY, "Unknown, !isText() - giving up");
361 lyx_view_->message(_("Unknown function."));
362 lyx_view_->restartCursor();
367 if (func.action == LFUN_SELF_INSERT) {
368 if (encoded_last_key != 0) {
369 docstring const arg(1, encoded_last_key);
370 dispatch(FuncRequest(LFUN_SELF_INSERT, arg,
371 FuncRequest::KEYBOARD));
372 LYXERR(Debug::KEY, "SelfInsert arg[`" << to_utf8(arg) << "']");
382 FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
384 //lyxerr << "LyXFunc::getStatus: cmd: " << cmd << endl;
387 Buffer * buf = lyx_view_ ? lyx_view_->buffer() : 0;
389 if (cmd.action == LFUN_NOACTION) {
390 flag.message(from_utf8(N_("Nothing to do")));
391 flag.setEnabled(false);
395 switch (cmd.action) {
396 case LFUN_UNKNOWN_ACTION:
397 #ifndef HAVE_LIBAIKSAURUS
398 case LFUN_THESAURUS_ENTRY:
401 flag.setEnabled(false);
408 if (flag.unknown()) {
409 flag.message(from_utf8(N_("Unknown action")));
413 if (!flag.enabled()) {
414 if (flag.message().empty())
415 flag.message(from_utf8(N_("Command disabled")));
419 // Check whether we need a buffer
420 if (!lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer) && !buf) {
422 flag.message(from_utf8(N_("Command not allowed with"
423 "out any document open")));
424 flag.setEnabled(false);
428 // I would really like to avoid having this switch and rather try to
429 // encode this in the function itself.
430 // -- And I'd rather let an inset decide which LFUNs it is willing
431 // to handle (Andre')
433 switch (cmd.action) {
435 case LFUN_BUFFER_TOGGLE_READ_ONLY:
436 flag.setOnOff(buf->isReadonly());
439 case LFUN_BUFFER_SWITCH:
440 // toggle on the current buffer, but do not toggle off
441 // the other ones (is that a good idea?)
442 if (buf && to_utf8(cmd.argument()) == buf->absFileName())
446 case LFUN_BUFFER_EXPORT:
447 enable = cmd.argument() == "custom"
448 || buf->isExportable(to_utf8(cmd.argument()));
451 case LFUN_BUFFER_CHKTEX:
452 enable = buf->isLatex() && !lyxrc.chktex_command.empty();
455 case LFUN_BUILD_PROGRAM:
456 enable = buf->isExportable("program");
459 case LFUN_VC_REGISTER:
460 enable = !buf->lyxvc().inUse();
462 case LFUN_VC_CHECK_IN:
463 enable = buf->lyxvc().inUse() && !buf->isReadonly();
465 case LFUN_VC_CHECK_OUT:
466 enable = buf->lyxvc().inUse() && buf->isReadonly();
469 case LFUN_VC_UNDO_LAST:
470 enable = buf->lyxvc().inUse();
472 case LFUN_BUFFER_RELOAD:
473 enable = !buf->isUnnamed() && buf->fileName().exists()
474 && (!buf->isClean() || buf->isExternallyModified(Buffer::timestamp_method));
477 case LFUN_CITATION_INSERT: {
478 FuncRequest fr(LFUN_INSET_INSERT, "citation");
479 enable = getStatus(fr).enabled();
483 // This could be used for the no-GUI version. The GUI version is handled in
484 // LyXView::getStatus(). See above.
486 case LFUN_BUFFER_WRITE:
487 case LFUN_BUFFER_WRITE_AS: {
488 Buffer * b = theBufferList().getBuffer(cmd.getArg(0));
489 enable = b && (b->isUnnamed() || !b->isClean());
494 case LFUN_BUFFER_WRITE_ALL: {
495 // We enable the command only if there are some modified buffers
496 Buffer * first = theBufferList().first();
501 // We cannot use a for loop as the buffer list is a cycle.
507 b = theBufferList().next(b);
508 } while (b != first);
512 case LFUN_BOOKMARK_GOTO: {
513 const unsigned int num = convert<unsigned int>(to_utf8(cmd.argument()));
514 enable = LyX::ref().session().bookmarks().isValid(num);
518 case LFUN_BOOKMARK_CLEAR:
519 enable = LyX::ref().session().bookmarks().size() > 0;
522 // this one is difficult to get right. As a half-baked
523 // solution, we consider only the first action of the sequence
524 case LFUN_COMMAND_SEQUENCE: {
525 // argument contains ';'-terminated commands
526 string const firstcmd = token(to_utf8(cmd.argument()), ';', 0);
527 FuncRequest func(lyxaction.lookupFunc(firstcmd));
528 func.origin = cmd.origin;
529 flag = getStatus(func);
535 string name = to_utf8(cmd.argument());
536 if (LyX::ref().topLevelCmdDef().lock(name, func)) {
537 func.origin = cmd.origin;
538 flag = getStatus(func);
539 LyX::ref().topLevelCmdDef().release(name);
541 // catch recursion or unknown command definiton
542 // all operations until the recursion or unknown command
543 // definiton occures are performed, so set the state to enabled
549 case LFUN_WORD_FIND_FORWARD:
550 case LFUN_WORD_FIND_BACKWARD:
551 case LFUN_COMMAND_PREFIX:
552 case LFUN_COMMAND_EXECUTE:
554 case LFUN_META_PREFIX:
555 case LFUN_BUFFER_CLOSE:
556 case LFUN_BUFFER_UPDATE:
557 case LFUN_BUFFER_VIEW:
558 case LFUN_MASTER_BUFFER_UPDATE:
559 case LFUN_MASTER_BUFFER_VIEW:
560 case LFUN_BUFFER_IMPORT:
561 case LFUN_BUFFER_AUTO_SAVE:
562 case LFUN_RECONFIGURE:
564 case LFUN_DROP_LAYOUTS_CHOICE:
566 case LFUN_SERVER_GET_NAME:
567 case LFUN_SERVER_NOTIFY:
568 case LFUN_SERVER_GOTO_FILE_ROW:
569 case LFUN_DIALOG_HIDE:
570 case LFUN_DIALOG_DISCONNECT_INSET:
571 case LFUN_BUFFER_CHILD_OPEN:
572 case LFUN_CURSOR_FOLLOWS_SCROLLBAR_TOGGLE:
573 case LFUN_KEYMAP_OFF:
574 case LFUN_KEYMAP_PRIMARY:
575 case LFUN_KEYMAP_SECONDARY:
576 case LFUN_KEYMAP_TOGGLE:
578 case LFUN_BUFFER_EXPORT_CUSTOM:
579 case LFUN_BUFFER_PRINT:
580 case LFUN_PREFERENCES_SAVE:
582 case LFUN_INSET_EDIT:
583 case LFUN_ALL_INSETS_TOGGLE:
584 case LFUN_GRAPHICS_GROUPS_UNIFY:
585 case LFUN_BUFFER_LANGUAGE:
586 case LFUN_TEXTCLASS_APPLY:
587 case LFUN_TEXTCLASS_LOAD:
588 case LFUN_BUFFER_SAVE_AS_DEFAULT:
589 case LFUN_BUFFER_PARAMS_APPLY:
590 case LFUN_LAYOUT_MODULES_CLEAR:
591 case LFUN_LAYOUT_MODULE_ADD:
592 case LFUN_LAYOUT_RELOAD:
593 case LFUN_LYXRC_APPLY:
594 case LFUN_BUFFER_NEXT:
595 case LFUN_BUFFER_PREVIOUS:
596 // these are handled in our dispatch()
604 if (theApp()->getStatus(cmd, flag))
607 // Does the view know something?
612 if (lyx_view_->getStatus(cmd, flag))
615 // If we have a BufferView, try cursor position and
616 // then the BufferView.
621 if (!getLocalStatus(view()->cursor(), cmd, flag))
622 flag = view()->getStatus(cmd);
626 flag.setEnabled(false);
628 // Can we use a readonly buffer?
629 if (buf && buf->isReadonly()
630 && !lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly)
631 && !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)) {
632 flag.message(from_utf8(N_("Document is read-only")));
633 flag.setEnabled(false);
636 // Are we in a DELETED change-tracking region?
638 && lookupChangeType(view()->cursor(), true) == Change::DELETED
639 && !lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly)
640 && !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)) {
641 flag.message(from_utf8(N_("This portion of the document is deleted.")));
642 flag.setEnabled(false);
645 // the default error message if we disable the command
646 if (!flag.enabled() && flag.message().empty())
647 flag.message(from_utf8(N_("Command disabled")));
653 bool LyXFunc::ensureBufferClean(BufferView * bv)
655 Buffer & buf = bv->buffer();
659 docstring const file = buf.fileName().displayName(30);
660 docstring text = bformat(_("The document %1$s has unsaved "
661 "changes.\n\nDo you want to save "
662 "the document?"), file);
663 int const ret = Alert::prompt(_("Save changed document?"),
664 text, 0, 1, _("&Save"),
668 dispatch(FuncRequest(LFUN_BUFFER_WRITE));
670 return buf.isClean();
676 void showPrintError(string const & name)
678 docstring str = bformat(_("Could not print the document %1$s.\n"
679 "Check that your printer is set up correctly."),
680 makeDisplayPath(name, 50));
681 Alert::error(_("Print document failed"), str);
685 bool loadLayoutFile(string const & name, string const & buf_path)
687 if (!LayoutFileList::get().haveClass(name)) {
688 lyxerr << "Document class \"" << name
689 << "\" does not exist."
694 LayoutFile & tc = LayoutFileList::get()[name];
695 if (!tc.load(buf_path)) {
696 docstring s = bformat(_("The document class %1$s "
697 "could not be loaded."), from_utf8(name));
698 Alert::error(_("Could not load class"), s);
705 void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new);
710 void LyXFunc::dispatch(FuncRequest const & cmd)
712 string const argument = to_utf8(cmd.argument());
713 FuncCode const action = cmd.action;
715 LYXERR(Debug::ACTION, "\nLyXFunc::dispatch: cmd: " << cmd);
716 //lyxerr << "LyXFunc::dispatch: cmd: " << cmd << endl;
718 // we have not done anything wrong yet.
720 dispatch_buffer.erase();
722 // redraw the screen at the end (first of the two drawing steps).
723 //This is done unless explicitely requested otherwise
724 Update::flags updateFlags = Update::FitCursor;
726 FuncStatus const flag = getStatus(cmd);
727 if (!flag.enabled()) {
728 // We cannot use this function here
729 LYXERR(Debug::ACTION, "LyXFunc::dispatch: "
730 << lyxaction.getActionName(action)
731 << " [" << action << "] is disabled at this location");
732 setErrorMessage(flag.message());
736 case LFUN_WORD_FIND_FORWARD:
737 case LFUN_WORD_FIND_BACKWARD: {
738 LASSERT(lyx_view_ && lyx_view_->view(), /**/);
739 static docstring last_search;
740 docstring searched_string;
742 if (!cmd.argument().empty()) {
743 last_search = cmd.argument();
744 searched_string = cmd.argument();
746 searched_string = last_search;
749 if (searched_string.empty())
752 bool const fw = action == LFUN_WORD_FIND_FORWARD;
753 docstring const data =
754 find2string(searched_string, true, false, fw);
755 find(view(), FuncRequest(LFUN_WORD_FIND, data));
759 case LFUN_COMMAND_PREFIX:
760 LASSERT(lyx_view_, /**/);
761 lyx_view_->message(keyseq.printOptions(true));
765 LASSERT(lyx_view_ && lyx_view_->view(), /**/);
767 meta_fake_bit = NoModifier;
768 if (lyx_view_->buffer())
769 // cancel any selection
770 dispatch(FuncRequest(LFUN_MARK_OFF));
771 setMessage(from_ascii(N_("Cancel")));
774 case LFUN_META_PREFIX:
775 meta_fake_bit = AltModifier;
776 setMessage(keyseq.print(KeySequence::ForGui));
779 case LFUN_BUFFER_TOGGLE_READ_ONLY: {
780 LASSERT(lyx_view_ && lyx_view_->view() && lyx_view_->buffer(), /**/);
781 Buffer * buf = lyx_view_->buffer();
782 if (buf->lyxvc().inUse())
783 buf->lyxvc().toggleReadOnly();
785 buf->setReadonly(!lyx_view_->buffer()->isReadonly());
789 // --- Menus -----------------------------------------------
790 case LFUN_BUFFER_CLOSE:
791 lyx_view_->closeBuffer();
792 updateFlags = Update::None;
795 case LFUN_BUFFER_RELOAD: {
796 LASSERT(lyx_view_ && lyx_view_->buffer(), /**/);
797 docstring const file = makeDisplayPath(lyx_view_->buffer()->absFileName(), 20);
798 docstring text = bformat(_("Any changes will be lost. Are you sure "
799 "you want to revert to the saved version of the document %1$s?"), file);
800 int const ret = Alert::prompt(_("Revert to saved document?"),
801 text, 1, 1, _("&Revert"), _("&Cancel"));
808 case LFUN_BUFFER_UPDATE:
809 LASSERT(lyx_view_ && lyx_view_->buffer(), /**/);
810 lyx_view_->buffer()->doExport(argument, true);
813 case LFUN_BUFFER_VIEW:
814 LASSERT(lyx_view_ && lyx_view_->buffer(), /**/);
815 lyx_view_->buffer()->preview(argument);
818 case LFUN_MASTER_BUFFER_UPDATE:
819 LASSERT(lyx_view_ && lyx_view_->buffer() && lyx_view_->buffer()->masterBuffer(), /**/);
820 lyx_view_->buffer()->masterBuffer()->doExport(argument, true);
823 case LFUN_MASTER_BUFFER_VIEW:
824 LASSERT(lyx_view_ && lyx_view_->buffer() && lyx_view_->buffer()->masterBuffer(), /**/);
825 lyx_view_->buffer()->masterBuffer()->preview(argument);
828 case LFUN_BUILD_PROGRAM:
829 LASSERT(lyx_view_ && lyx_view_->buffer(), /**/);
830 lyx_view_->buffer()->doExport("program", true);
833 case LFUN_BUFFER_CHKTEX:
834 LASSERT(lyx_view_ && lyx_view_->buffer(), /**/);
835 lyx_view_->buffer()->runChktex();
838 case LFUN_BUFFER_EXPORT:
839 LASSERT(lyx_view_ && lyx_view_->buffer(), /**/);
840 if (argument == "custom")
841 dispatch(FuncRequest(LFUN_DIALOG_SHOW, "sendto"));
843 lyx_view_->buffer()->doExport(argument, false);
846 case LFUN_BUFFER_EXPORT_CUSTOM: {
847 LASSERT(lyx_view_ && lyx_view_->buffer(), /**/);
849 string command = split(argument, format_name, ' ');
850 Format const * format = formats.getFormat(format_name);
852 lyxerr << "Format \"" << format_name
853 << "\" not recognized!"
858 Buffer * buffer = lyx_view_->buffer();
860 // The name of the file created by the conversion process
863 // Output to filename
864 if (format->name() == "lyx") {
865 string const latexname = buffer->latexName(false);
866 filename = changeExtension(latexname,
867 format->extension());
868 filename = addName(buffer->temppath(), filename);
870 if (!buffer->writeFile(FileName(filename)))
874 buffer->doExport(format_name, true, filename);
877 // Substitute $$FName for filename
878 if (!contains(command, "$$FName"))
879 command = "( " + command + " ) < $$FName";
880 command = subst(command, "$$FName", filename);
882 // Execute the command in the background
884 call.startscript(Systemcall::DontWait, command);
888 case LFUN_BUFFER_PRINT: {
889 LASSERT(lyx_view_ && lyx_view_->buffer(), /**/);
890 // FIXME: cmd.getArg() might fail if one of the arguments
891 // contains double quotes
892 string target = cmd.getArg(0);
893 string target_name = cmd.getArg(1);
894 string command = cmd.getArg(2);
897 || target_name.empty()
898 || command.empty()) {
899 lyxerr << "Unable to parse \""
900 << argument << '"' << endl;
903 if (target != "printer" && target != "file") {
904 lyxerr << "Unrecognized target \""
905 << target << '"' << endl;
909 Buffer * buffer = lyx_view_->buffer();
911 if (!buffer->doExport("dvi", true)) {
912 showPrintError(buffer->absFileName());
916 // Push directory path.
917 string const path = buffer->temppath();
918 // Prevent the compiler from optimizing away p
922 // there are three cases here:
923 // 1. we print to a file
924 // 2. we print directly to a printer
925 // 3. we print using a spool command (print to file first)
928 string const dviname =
929 changeExtension(buffer->latexName(true), "dvi");
931 if (target == "printer") {
932 if (!lyxrc.print_spool_command.empty()) {
933 // case 3: print using a spool
934 string const psname =
935 changeExtension(dviname,".ps");
936 command += ' ' + lyxrc.print_to_file
939 + quoteName(dviname);
942 lyxrc.print_spool_command + ' ';
943 if (target_name != "default") {
944 command2 += lyxrc.print_spool_printerprefix
948 command2 += quoteName(psname);
950 // If successful, then spool command
951 res = one.startscript(
956 res = one.startscript(
957 Systemcall::DontWait,
960 // case 2: print directly to a printer
961 if (target_name != "default")
962 command += ' ' + lyxrc.print_to_printer + target_name + ' ';
963 res = one.startscript(
964 Systemcall::DontWait,
965 command + quoteName(dviname));
969 // case 1: print to a file
970 FileName const filename(makeAbsPath(target_name,
971 lyx_view_->buffer()->filePath()));
972 FileName const dvifile(makeAbsPath(dviname, path));
973 if (filename.exists()) {
974 docstring text = bformat(
975 _("The file %1$s already exists.\n\n"
976 "Do you want to overwrite that file?"),
977 makeDisplayPath(filename.absFilename()));
978 if (Alert::prompt(_("Overwrite file?"),
979 text, 0, 1, _("&Overwrite"), _("&Cancel")) != 0)
982 command += ' ' + lyxrc.print_to_file
983 + quoteName(filename.toFilesystemEncoding())
985 + quoteName(dvifile.toFilesystemEncoding());
986 res = one.startscript(Systemcall::DontWait,
991 showPrintError(buffer->absFileName());
995 // FIXME: There is need for a command-line import.
997 case LFUN_BUFFER_IMPORT:
1002 case LFUN_BUFFER_AUTO_SAVE:
1003 lyx_view_->buffer()->autoSave();
1006 case LFUN_RECONFIGURE:
1007 // argument is any additional parameter to the configure.py command
1008 reconfigure(lyx_view_, argument);
1011 case LFUN_HELP_OPEN: {
1012 LASSERT(lyx_view_, /**/);
1013 string const arg = argument;
1015 setErrorMessage(from_ascii(N_("Missing argument")));
1018 FileName const fname = i18nLibFileSearch("doc", arg, "lyx");
1019 if (fname.empty()) {
1020 lyxerr << "LyX: unable to find documentation file `"
1021 << arg << "'. Bad installation?" << endl;
1024 lyx_view_->message(bformat(_("Opening help file %1$s..."),
1025 makeDisplayPath(fname.absFilename())));
1026 Buffer * buf = lyx_view_->loadDocument(fname, false);
1029 lyx_view_->setBuffer(buf);
1030 buf->errors("Parse");
1032 updateFlags = Update::None;
1036 // --- version control -------------------------------
1037 case LFUN_VC_REGISTER:
1038 LASSERT(lyx_view_ && lyx_view_->buffer(), /**/);
1039 if (!ensureBufferClean(view()))
1041 if (!lyx_view_->buffer()->lyxvc().inUse()) {
1042 lyx_view_->buffer()->lyxvc().registrer();
1045 updateFlags = Update::Force;
1048 case LFUN_VC_CHECK_IN:
1049 LASSERT(lyx_view_ && lyx_view_->buffer(), /**/);
1050 if (!ensureBufferClean(view()))
1052 if (lyx_view_->buffer()->lyxvc().inUse()
1053 && !lyx_view_->buffer()->isReadonly()) {
1054 lyx_view_->buffer()->lyxvc().checkIn();
1059 case LFUN_VC_CHECK_OUT:
1060 LASSERT(lyx_view_ && lyx_view_->buffer(), /**/);
1061 if (!ensureBufferClean(view()))
1063 if (lyx_view_->buffer()->lyxvc().inUse()
1064 && lyx_view_->buffer()->isReadonly()) {
1065 lyx_view_->buffer()->lyxvc().checkOut();
1070 case LFUN_VC_REVERT:
1071 LASSERT(lyx_view_ && lyx_view_->buffer(), /**/);
1072 lyx_view_->buffer()->lyxvc().revert();
1076 case LFUN_VC_UNDO_LAST:
1077 LASSERT(lyx_view_ && lyx_view_->buffer(), /**/);
1078 lyx_view_->buffer()->lyxvc().undoLast();
1082 // --- lyxserver commands ----------------------------
1083 case LFUN_SERVER_GET_NAME:
1084 LASSERT(lyx_view_ && lyx_view_->buffer(), /**/);
1085 setMessage(from_utf8(lyx_view_->buffer()->absFileName()));
1086 LYXERR(Debug::INFO, "FNAME["
1087 << lyx_view_->buffer()->absFileName() << ']');
1090 case LFUN_SERVER_NOTIFY:
1091 dispatch_buffer = keyseq.print(KeySequence::Portable);
1092 theServer().notifyClient(to_utf8(dispatch_buffer));
1095 case LFUN_SERVER_GOTO_FILE_ROW: {
1096 LASSERT(lyx_view_, /**/);
1099 istringstream is(argument);
1100 is >> file_name >> row;
1102 bool loaded = false;
1103 if (prefixIs(file_name, package().temp_dir().absFilename()))
1104 // Needed by inverse dvi search. If it is a file
1105 // in tmpdir, call the apropriated function
1106 buf = theBufferList().getBufferFromTmp(file_name);
1108 // Must replace extension of the file to be .lyx
1109 // and get full path
1110 FileName const s = fileSearch(string(), changeExtension(file_name, ".lyx"), "lyx");
1111 // Either change buffer or load the file
1112 if (theBufferList().exists(s.absFilename()))
1113 buf = theBufferList().getBuffer(s.absFilename());
1115 buf = lyx_view_->loadDocument(s);
1121 updateFlags = Update::None;
1126 lyx_view_->setBuffer(buf);
1127 view()->setCursorFromRow(row);
1129 buf->errors("Parse");
1130 updateFlags = Update::FitCursor;
1135 case LFUN_DIALOG_SHOW_NEW_INSET: {
1136 LASSERT(lyx_view_, /**/);
1137 string const name = cmd.getArg(0);
1138 InsetCode code = insetCode(name);
1139 string data = trim(to_utf8(cmd.argument()).substr(name.size()));
1140 bool insetCodeOK = true;
1149 case HYPERLINK_CODE: {
1150 InsetCommandParams p(code);
1151 data = InsetCommand::params2string(name, p);
1154 case INCLUDE_CODE: {
1155 // data is the include type: one of "include",
1156 // "input", "verbatiminput" or "verbatiminput*"
1158 // default type is requested
1160 InsetCommandParams p(INCLUDE_CODE, data);
1161 data = InsetCommand::params2string("include", p);
1165 // \c data == "Boxed" || "Frameless" etc
1166 InsetBoxParams p(data);
1167 data = InsetBox::params2string(p);
1171 InsetBranchParams p;
1172 data = InsetBranch::params2string(p);
1176 InsetCommandParams p(CITE_CODE);
1177 data = InsetCommand::params2string(name, p);
1181 data = InsetERT::params2string(InsetCollapsable::Open);
1184 case EXTERNAL_CODE: {
1185 InsetExternalParams p;
1186 Buffer const & buffer = *lyx_view_->buffer();
1187 data = InsetExternal::params2string(p, buffer);
1192 data = InsetFloat::params2string(p);
1195 case LISTINGS_CODE: {
1196 InsetListingsParams p;
1197 data = InsetListings::params2string(p);
1200 case GRAPHICS_CODE: {
1201 InsetGraphicsParams p;
1202 Buffer const & buffer = *lyx_view_->buffer();
1203 data = InsetGraphics::params2string(p, buffer);
1208 data = InsetNote::params2string(p);
1213 data = InsetSpace::params2string(p);
1218 data = InsetVSpace::params2string(space);
1223 data = InsetWrap::params2string(p);
1227 lyxerr << "Inset type '" << name <<
1228 "' not recognized in LFUN_DIALOG_SHOW_NEW_INSET" << endl;
1229 insetCodeOK = false;
1231 } // end switch(code)
1233 dispatch(FuncRequest(LFUN_DIALOG_SHOW, name + " " + data));
1237 case LFUN_CITATION_INSERT: {
1238 LASSERT(lyx_view_, /**/);
1239 if (!argument.empty()) {
1240 // we can have one optional argument, delimited by '|'
1241 // citation-insert <key>|<text_before>
1242 // this should be enhanced to also support text_after
1243 // and citation style
1244 string arg = argument;
1246 if (contains(argument, "|")) {
1247 arg = token(argument, '|', 0);
1248 opt1 = token(argument, '|', 1);
1250 InsetCommandParams icp(CITE_CODE);
1251 icp["key"] = from_utf8(arg);
1253 icp["before"] = from_utf8(opt1);
1254 string icstr = InsetCommand::params2string("citation", icp);
1255 FuncRequest fr(LFUN_INSET_INSERT, icstr);
1258 dispatch(FuncRequest(LFUN_DIALOG_SHOW_NEW_INSET, "citation"));
1262 case LFUN_BUFFER_CHILD_OPEN: {
1263 LASSERT(lyx_view_ && lyx_view_->buffer(), /**/);
1264 Buffer * parent = lyx_view_->buffer();
1265 FileName filename = makeAbsPath(argument, parent->filePath());
1266 view()->saveBookmark(false);
1268 bool parsed = false;
1269 if (theBufferList().exists(filename.absFilename())) {
1270 child = theBufferList().getBuffer(filename.absFilename());
1272 setMessage(bformat(_("Opening child document %1$s..."),
1273 makeDisplayPath(filename.absFilename())));
1274 child = lyx_view_->loadDocument(filename, false);
1278 // Set the parent name of the child document.
1279 // This makes insertion of citations and references in the child work,
1280 // when the target is in the parent or another child document.
1281 child->setParent(parent);
1282 updateLabels(*child->masterBuffer());
1283 lyx_view_->setBuffer(child);
1285 child->errors("Parse");
1288 // If a screen update is required (in case where auto_open is false),
1289 // setBuffer() would have taken care of it already. Otherwise we shall
1290 // reset the update flag because it can cause a circular problem.
1292 updateFlags = Update::None;
1296 case LFUN_CURSOR_FOLLOWS_SCROLLBAR_TOGGLE:
1297 LASSERT(lyx_view_, /**/);
1298 lyxrc.cursor_follows_scrollbar = !lyxrc.cursor_follows_scrollbar;
1301 case LFUN_KEYMAP_OFF:
1302 LASSERT(lyx_view_ && lyx_view_->view(), /**/);
1303 lyx_view_->view()->getIntl().keyMapOn(false);
1306 case LFUN_KEYMAP_PRIMARY:
1307 LASSERT(lyx_view_ && lyx_view_->view(), /**/);
1308 lyx_view_->view()->getIntl().keyMapPrim();
1311 case LFUN_KEYMAP_SECONDARY:
1312 LASSERT(lyx_view_ && lyx_view_->view(), /**/);
1313 lyx_view_->view()->getIntl().keyMapSec();
1316 case LFUN_KEYMAP_TOGGLE:
1317 LASSERT(lyx_view_ && lyx_view_->view(), /**/);
1318 lyx_view_->view()->getIntl().toggleKeyMap();
1324 string rest = split(argument, countstr, ' ');
1325 istringstream is(countstr);
1328 lyxerr << "repeat: count: " << count << " cmd: " << rest << endl;
1329 for (int i = 0; i < count; ++i)
1330 dispatch(lyxaction.lookupFunc(rest));
1334 case LFUN_COMMAND_SEQUENCE: {
1335 // argument contains ';'-terminated commands
1336 string arg = argument;
1337 while (!arg.empty()) {
1339 arg = split(arg, first, ';');
1340 FuncRequest func(lyxaction.lookupFunc(first));
1341 func.origin = cmd.origin;
1349 if (LyX::ref().topLevelCmdDef().lock(argument, func)) {
1350 func.origin = cmd.origin;
1352 LyX::ref().topLevelCmdDef().release(argument);
1354 if (func.action == LFUN_UNKNOWN_ACTION) {
1355 // unknown command definition
1356 lyxerr << "Warning: unknown command definition `"
1360 // recursion detected
1361 lyxerr << "Warning: Recursion in the command definition `"
1362 << argument << "' detected"
1369 case LFUN_PREFERENCES_SAVE: {
1370 lyxrc.write(makeAbsPath("preferences",
1371 package().user_support().absFilename()),
1377 LASSERT(lyx_view_, /**/);
1378 lyx_view_->message(from_utf8(argument));
1382 case LFUN_ALL_INSETS_TOGGLE: {
1383 LASSERT(lyx_view_, /**/);
1385 string const name = split(argument, action, ' ');
1386 InsetCode const inset_code = insetCode(name);
1388 Cursor & cur = view()->cursor();
1389 FuncRequest fr(LFUN_INSET_TOGGLE, action);
1391 Inset & inset = lyx_view_->buffer()->inset();
1392 InsetIterator it = inset_iterator_begin(inset);
1393 InsetIterator const end = inset_iterator_end(inset);
1394 for (; it != end; ++it) {
1395 if (!it->asInsetMath()
1396 && (inset_code == NO_CODE
1397 || inset_code == it->lyxCode())) {
1398 Cursor tmpcur = cur;
1399 tmpcur.pushBackward(*it);
1400 it->dispatch(tmpcur, fr);
1403 updateFlags = Update::Force | Update::FitCursor;
1407 case LFUN_GRAPHICS_GROUPS_UNIFY: {
1408 LASSERT(lyx_view_, /**/);
1409 if (argument.empty())
1411 //view()->cursor().recordUndoFullDocument(); let inset-apply do that job
1412 graphics::unifyGraphicsGroups(*lyx_view_->buffer(), argument);
1413 updateFlags = Update::Force | Update::FitCursor;
1417 case LFUN_BUFFER_LANGUAGE: {
1418 LASSERT(lyx_view_, /**/);
1419 Buffer & buffer = *lyx_view_->buffer();
1420 Language const * oldL = buffer.params().language;
1421 Language const * newL = languages.getLanguage(argument);
1422 if (!newL || oldL == newL)
1425 if (oldL->rightToLeft() == newL->rightToLeft()
1426 && !buffer.isMultiLingual())
1427 buffer.changeLanguage(oldL, newL);
1431 case LFUN_BUFFER_SAVE_AS_DEFAULT: {
1432 string const fname =
1433 addName(addPath(package().user_support().absFilename(), "templates/"),
1435 Buffer defaults(fname);
1437 istringstream ss(argument);
1440 int const unknown_tokens = defaults.readHeader(lex);
1442 if (unknown_tokens != 0) {
1443 lyxerr << "Warning in LFUN_BUFFER_SAVE_AS_DEFAULT!\n"
1444 << unknown_tokens << " unknown token"
1445 << (unknown_tokens == 1 ? "" : "s")
1449 if (defaults.writeFile(FileName(defaults.absFileName())))
1450 setMessage(bformat(_("Document defaults saved in %1$s"),
1451 makeDisplayPath(fname)));
1453 setErrorMessage(from_ascii(N_("Unable to save document defaults")));
1457 case LFUN_BUFFER_PARAMS_APPLY: {
1458 LASSERT(lyx_view_, /**/);
1460 Buffer * buffer = lyx_view_->buffer();
1461 DocumentClass const * const oldClass = buffer->params().documentClassPtr();
1462 Cursor & cur = view()->cursor();
1463 cur.recordUndoFullDocument();
1465 istringstream ss(argument);
1468 int const unknown_tokens = buffer->readHeader(lex);
1470 if (unknown_tokens != 0) {
1471 lyxerr << "Warning in LFUN_BUFFER_PARAMS_APPLY!\n"
1472 << unknown_tokens << " unknown token"
1473 << (unknown_tokens == 1 ? "" : "s")
1477 updateLayout(oldClass, buffer);
1479 updateFlags = Update::Force | Update::FitCursor;
1480 // We are most certainly here because of a change in the document
1481 // It is then better to make sure that all dialogs are in sync with
1482 // current document settings. LyXView::restartCursor() achieve this.
1483 lyx_view_->restartCursor();
1487 case LFUN_LAYOUT_MODULES_CLEAR: {
1488 LASSERT(lyx_view_, /**/);
1489 Buffer * buffer = lyx_view_->buffer();
1490 DocumentClass const * const oldClass = buffer->params().documentClassPtr();
1491 view()->cursor().recordUndoFullDocument();
1492 buffer->params().clearLayoutModules();
1493 buffer->params().makeDocumentClass();
1494 updateLayout(oldClass, buffer);
1495 updateFlags = Update::Force | Update::FitCursor;
1499 case LFUN_LAYOUT_MODULE_ADD: {
1500 LASSERT(lyx_view_, /**/);
1501 Buffer * buffer = lyx_view_->buffer();
1502 DocumentClass const * const oldClass = buffer->params().documentClassPtr();
1503 view()->cursor().recordUndoFullDocument();
1504 buffer->params().addLayoutModule(argument);
1505 buffer->params().makeDocumentClass();
1506 updateLayout(oldClass, buffer);
1507 updateFlags = Update::Force | Update::FitCursor;
1511 case LFUN_TEXTCLASS_APPLY: {
1512 LASSERT(lyx_view_, /**/);
1513 Buffer * buffer = lyx_view_->buffer();
1515 if (!loadLayoutFile(argument, buffer->temppath()) &&
1516 !loadLayoutFile(argument, buffer->filePath()))
1519 LayoutFile const * old_layout = buffer->params().baseClass();
1520 LayoutFile const * new_layout = &(LayoutFileList::get()[argument]);
1522 if (old_layout == new_layout)
1526 //Save the old, possibly modular, layout for use in conversion.
1527 DocumentClass const * const oldDocClass = buffer->params().documentClassPtr();
1528 view()->cursor().recordUndoFullDocument();
1529 buffer->params().setBaseClass(argument);
1530 buffer->params().makeDocumentClass();
1531 updateLayout(oldDocClass, buffer);
1532 updateFlags = Update::Force | Update::FitCursor;
1536 case LFUN_LAYOUT_RELOAD: {
1537 LASSERT(lyx_view_, /**/);
1538 Buffer * buffer = lyx_view_->buffer();
1539 DocumentClass const * const oldClass = buffer->params().documentClassPtr();
1540 LayoutFileIndex bc = buffer->params().baseClassID();
1541 LayoutFileList::get().reset(bc);
1542 buffer->params().setBaseClass(bc);
1543 buffer->params().makeDocumentClass();
1544 updateLayout(oldClass, buffer);
1545 updateFlags = Update::Force | Update::FitCursor;
1549 case LFUN_TEXTCLASS_LOAD:
1550 loadLayoutFile(argument, lyx_view_->buffer()->temppath()) ||
1551 loadLayoutFile(argument, lyx_view_->buffer()->filePath());
1554 case LFUN_LYXRC_APPLY: {
1555 LyXRC const lyxrc_orig = lyxrc;
1557 istringstream ss(argument);
1558 bool const success = lyxrc.read(ss) == 0;
1561 lyxerr << "Warning in LFUN_LYXRC_APPLY!\n"
1562 << "Unable to read lyxrc data"
1567 actOnUpdatedPrefs(lyxrc_orig, lyxrc);
1569 theApp()->resetGui();
1571 /// We force the redraw in any case because there might be
1572 /// some screen font changes.
1573 /// FIXME: only the current view will be updated. the Gui
1574 /// class is able to furnish the list of views.
1575 updateFlags = Update::Force;
1579 case LFUN_BOOKMARK_GOTO:
1580 // go to bookmark, open unopened file and switch to buffer if necessary
1581 gotoBookmark(convert<unsigned int>(to_utf8(cmd.argument())), true, true);
1582 updateFlags = Update::FitCursor;
1585 case LFUN_BOOKMARK_CLEAR:
1586 LyX::ref().session().bookmarks().clear();
1590 LASSERT(theApp(), /**/);
1591 // Let the frontend dispatch its own actions.
1592 if (theApp()->dispatch(cmd))
1593 // Nothing more to do.
1596 // Everything below is only for active lyx_view_
1600 // Let the current LyXView dispatch its own actions.
1601 if (lyx_view_->dispatch(cmd)) {
1602 if (lyx_view_->view())
1603 updateFlags = lyx_view_->view()->cursor().result().update();
1607 LASSERT(lyx_view_->view(), /**/);
1608 // Let the current BufferView dispatch its own actions.
1609 if (view()->dispatch(cmd)) {
1610 // The BufferView took care of its own updates if needed.
1611 updateFlags = Update::None;
1615 // Let the current Cursor dispatch its own actions.
1616 Cursor old = view()->cursor();
1617 view()->cursor().getPos(cursorPosBeforeDispatchX_,
1618 cursorPosBeforeDispatchY_);
1619 view()->cursor().dispatch(cmd);
1621 // notify insets we just left
1622 if (view()->cursor() != old) {
1624 bool badcursor = notifyCursorLeaves(old, view()->cursor());
1626 view()->cursor().fixIfBroken();
1629 // update completion. We do it here and not in
1630 // processKeySym to avoid another redraw just for a
1631 // changed inline completion
1632 if (cmd.origin == FuncRequest::KEYBOARD) {
1633 if (cmd.action == LFUN_SELF_INSERT)
1634 lyx_view_->updateCompletion(view()->cursor(), true, true);
1635 else if (cmd.action == LFUN_CHAR_DELETE_BACKWARD)
1636 lyx_view_->updateCompletion(view()->cursor(), false, true);
1638 lyx_view_->updateCompletion(view()->cursor(), false, false);
1641 updateFlags = view()->cursor().result().update();
1644 if (lyx_view_ && lyx_view_->buffer()) {
1645 // BufferView::update() updates the ViewMetricsInfo and
1646 // also initializes the position cache for all insets in
1647 // (at least partially) visible top-level paragraphs.
1648 // We will redraw the screen only if needed.
1649 view()->processUpdateFlags(updateFlags);
1651 // if we executed a mutating lfun, mark the buffer as dirty
1653 && !lyxaction.funcHasFlag(action, LyXAction::NoBuffer)
1654 && !lyxaction.funcHasFlag(action, LyXAction::ReadOnly))
1655 lyx_view_->buffer()->markDirty();
1657 // Do we have a selection?
1658 theSelection().haveSelection(view()->cursor().selection());
1661 lyx_view_->restartCursor();
1665 // Some messages may already be translated, so we cannot use _()
1666 sendDispatchMessage(translateIfPossible(getMessage()), cmd);
1671 void LyXFunc::sendDispatchMessage(docstring const & msg, FuncRequest const & cmd)
1673 const bool verbose = (cmd.origin == FuncRequest::MENU
1674 || cmd.origin == FuncRequest::TOOLBAR
1675 || cmd.origin == FuncRequest::COMMANDBUFFER);
1677 if (cmd.action == LFUN_SELF_INSERT || !verbose) {
1678 LYXERR(Debug::ACTION, "dispatch msg is " << to_utf8(msg));
1680 lyx_view_->message(msg);
1684 docstring dispatch_msg = msg;
1685 if (!dispatch_msg.empty())
1686 dispatch_msg += ' ';
1688 docstring comname = from_utf8(lyxaction.getActionName(cmd.action));
1690 bool argsadded = false;
1692 if (!cmd.argument().empty()) {
1693 if (cmd.action != LFUN_UNKNOWN_ACTION) {
1694 comname += ' ' + cmd.argument();
1699 docstring const shortcuts = theTopLevelKeymap().printBindings(cmd);
1701 if (!shortcuts.empty())
1702 comname += ": " + shortcuts;
1703 else if (!argsadded && !cmd.argument().empty())
1704 comname += ' ' + cmd.argument();
1706 if (!comname.empty()) {
1707 comname = rtrim(comname);
1708 dispatch_msg += '(' + rtrim(comname) + ')';
1711 LYXERR(Debug::ACTION, "verbose dispatch msg " << to_utf8(dispatch_msg));
1712 if (!dispatch_msg.empty())
1713 lyx_view_->message(dispatch_msg);
1717 void LyXFunc::reloadBuffer()
1719 FileName filename = lyx_view_->buffer()->fileName();
1720 // The user has already confirmed that the changes, if any, should
1721 // be discarded. So we just release the Buffer and don't call closeBuffer();
1722 theBufferList().release(lyx_view_->buffer());
1723 Buffer * buf = lyx_view_->loadDocument(filename);
1724 docstring const disp_fn = makeDisplayPath(filename.absFilename());
1728 lyx_view_->setBuffer(buf);
1729 buf->errors("Parse");
1730 str = bformat(_("Document %1$s reloaded."), disp_fn);
1732 str = bformat(_("Could not reload document %1$s"), disp_fn);
1734 lyx_view_->message(str);
1737 // Each "lyx_view_" should have it's own message method. lyxview and
1738 // the minibuffer would use the minibuffer, but lyxserver would
1739 // send an ERROR signal to its client. Alejandro 970603
1740 // This function is bit problematic when it comes to NLS, to make the
1741 // lyx servers client be language indepenent we must not translate
1742 // strings sent to this func.
1743 void LyXFunc::setErrorMessage(docstring const & m) const
1745 dispatch_buffer = m;
1750 void LyXFunc::setMessage(docstring const & m) const
1752 dispatch_buffer = m;
1756 docstring LyXFunc::viewStatusMessage()
1758 // When meta-fake key is pressed, show the key sequence so far + "M-".
1760 return keyseq.print(KeySequence::ForGui) + "M-";
1762 // Else, when a non-complete key sequence is pressed,
1763 // show the available options.
1764 if (keyseq.length() > 0 && !keyseq.deleted())
1765 return keyseq.printOptions(true);
1767 LASSERT(lyx_view_, /**/);
1768 if (!lyx_view_->buffer())
1769 return _("Welcome to LyX!");
1771 return view()->cursor().currentState();
1775 BufferView * LyXFunc::view() const
1777 LASSERT(lyx_view_, /**/);
1778 return lyx_view_->view();
1782 bool LyXFunc::wasMetaKey() const
1784 return (meta_fake_bit != NoModifier);
1788 void LyXFunc::updateLayout(DocumentClass const * const oldlayout, Buffer * buffer)
1790 lyx_view_->message(_("Converting document to new document class..."));
1792 StableDocIterator backcur(view()->cursor());
1793 ErrorList & el = buffer->errorList("Class Switch");
1794 cap::switchBetweenClasses(
1795 oldlayout, buffer->params().documentClassPtr(),
1796 static_cast<InsetText &>(buffer->inset()), el);
1798 view()->setCursor(backcur.asDocIterator(&(buffer->inset())));
1800 buffer->errors("Class Switch");
1801 updateLabels(*buffer);
1807 void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
1809 // Why the switch you might ask. It is a trick to ensure that all
1810 // the elements in the LyXRCTags enum is handled. As you can see
1811 // there are no breaks at all. So it is just a huge fall-through.
1812 // The nice thing is that we will get a warning from the compiler
1813 // if we forget an element.
1814 LyXRC::LyXRCTags tag = LyXRC::RC_LAST;
1816 case LyXRC::RC_ACCEPT_COMPOUND:
1817 case LyXRC::RC_ALT_LANG:
1818 case LyXRC::RC_PLAINTEXT_ROFF_COMMAND:
1819 case LyXRC::RC_PLAINTEXT_LINELEN:
1820 case LyXRC::RC_AUTOREGIONDELETE:
1821 case LyXRC::RC_AUTORESET_OPTIONS:
1822 case LyXRC::RC_AUTOSAVE:
1823 case LyXRC::RC_AUTO_NUMBER:
1824 case LyXRC::RC_BACKUPDIR_PATH:
1825 case LyXRC::RC_BIBTEX_COMMAND:
1826 case LyXRC::RC_BINDFILE:
1827 case LyXRC::RC_CHECKLASTFILES:
1828 case LyXRC::RC_COMPLETION_CURSOR_TEXT:
1829 case LyXRC::RC_COMPLETION_INLINE_DELAY:
1830 case LyXRC::RC_COMPLETION_INLINE_DOTS:
1831 case LyXRC::RC_COMPLETION_INLINE_MATH:
1832 case LyXRC::RC_COMPLETION_INLINE_TEXT:
1833 case LyXRC::RC_COMPLETION_POPUP_AFTER_COMPLETE:
1834 case LyXRC::RC_COMPLETION_POPUP_DELAY:
1835 case LyXRC::RC_COMPLETION_POPUP_MATH:
1836 case LyXRC::RC_COMPLETION_POPUP_TEXT:
1837 case LyXRC::RC_USELASTFILEPOS:
1838 case LyXRC::RC_LOADSESSION:
1839 case LyXRC::RC_CHKTEX_COMMAND:
1840 case LyXRC::RC_CONVERTER:
1841 case LyXRC::RC_CONVERTER_CACHE_MAXAGE:
1842 case LyXRC::RC_COPIER:
1843 case LyXRC::RC_CURSOR_FOLLOWS_SCROLLBAR:
1844 case LyXRC::RC_CUSTOM_EXPORT_COMMAND:
1845 case LyXRC::RC_CUSTOM_EXPORT_FORMAT:
1846 case LyXRC::RC_DATE_INSERT_FORMAT:
1847 case LyXRC::RC_DEFAULT_LANGUAGE:
1848 case LyXRC::RC_DEFAULT_PAPERSIZE:
1849 case LyXRC::RC_DEFFILE:
1850 case LyXRC::RC_DIALOGS_ICONIFY_WITH_MAIN:
1851 case LyXRC::RC_DISPLAY_GRAPHICS:
1852 case LyXRC::RC_DOCUMENTPATH:
1853 if (lyxrc_orig.document_path != lyxrc_new.document_path) {
1854 FileName path(lyxrc_new.document_path);
1855 if (path.exists() && path.isDirectory())
1856 package().document_dir() = FileName(lyxrc.document_path);
1858 case LyXRC::RC_ESC_CHARS:
1859 case LyXRC::RC_EXAMPLEPATH:
1860 case LyXRC::RC_FONT_ENCODING:
1861 case LyXRC::RC_FORMAT:
1862 case LyXRC::RC_GROUP_LAYOUTS:
1863 case LyXRC::RC_INDEX_COMMAND:
1864 case LyXRC::RC_INPUT:
1865 case LyXRC::RC_KBMAP:
1866 case LyXRC::RC_KBMAP_PRIMARY:
1867 case LyXRC::RC_KBMAP_SECONDARY:
1868 case LyXRC::RC_LABEL_INIT_LENGTH:
1869 case LyXRC::RC_LANGUAGE_AUTO_BEGIN:
1870 case LyXRC::RC_LANGUAGE_AUTO_END:
1871 case LyXRC::RC_LANGUAGE_COMMAND_BEGIN:
1872 case LyXRC::RC_LANGUAGE_COMMAND_END:
1873 case LyXRC::RC_LANGUAGE_COMMAND_LOCAL:
1874 case LyXRC::RC_LANGUAGE_GLOBAL_OPTIONS:
1875 case LyXRC::RC_LANGUAGE_PACKAGE:
1876 case LyXRC::RC_LANGUAGE_USE_BABEL:
1877 case LyXRC::RC_MACRO_EDIT_STYLE:
1878 case LyXRC::RC_MAKE_BACKUP:
1879 case LyXRC::RC_MARK_FOREIGN_LANGUAGE:
1880 case LyXRC::RC_MOUSE_WHEEL_SPEED:
1881 case LyXRC::RC_NUMLASTFILES:
1882 case LyXRC::RC_PATH_PREFIX:
1883 if (lyxrc_orig.path_prefix != lyxrc_new.path_prefix) {
1884 prependEnvPath("PATH", lyxrc.path_prefix);
1886 case LyXRC::RC_PERS_DICT:
1887 case LyXRC::RC_PREVIEW:
1888 case LyXRC::RC_PREVIEW_HASHED_LABELS:
1889 case LyXRC::RC_PREVIEW_SCALE_FACTOR:
1890 case LyXRC::RC_PRINTCOLLCOPIESFLAG:
1891 case LyXRC::RC_PRINTCOPIESFLAG:
1892 case LyXRC::RC_PRINTER:
1893 case LyXRC::RC_PRINTEVENPAGEFLAG:
1894 case LyXRC::RC_PRINTEXSTRAOPTIONS:
1895 case LyXRC::RC_PRINTFILEEXTENSION:
1896 case LyXRC::RC_PRINTLANDSCAPEFLAG:
1897 case LyXRC::RC_PRINTODDPAGEFLAG:
1898 case LyXRC::RC_PRINTPAGERANGEFLAG:
1899 case LyXRC::RC_PRINTPAPERDIMENSIONFLAG:
1900 case LyXRC::RC_PRINTPAPERFLAG:
1901 case LyXRC::RC_PRINTREVERSEFLAG:
1902 case LyXRC::RC_PRINTSPOOL_COMMAND:
1903 case LyXRC::RC_PRINTSPOOL_PRINTERPREFIX:
1904 case LyXRC::RC_PRINTTOFILE:
1905 case LyXRC::RC_PRINTTOPRINTER:
1906 case LyXRC::RC_PRINT_ADAPTOUTPUT:
1907 case LyXRC::RC_PRINT_COMMAND:
1908 case LyXRC::RC_RTL_SUPPORT:
1909 case LyXRC::RC_SCREEN_DPI:
1910 case LyXRC::RC_SCREEN_FONT_ROMAN:
1911 case LyXRC::RC_SCREEN_FONT_ROMAN_FOUNDRY:
1912 case LyXRC::RC_SCREEN_FONT_SANS:
1913 case LyXRC::RC_SCREEN_FONT_SANS_FOUNDRY:
1914 case LyXRC::RC_SCREEN_FONT_SCALABLE:
1915 case LyXRC::RC_SCREEN_FONT_SIZES:
1916 case LyXRC::RC_SCREEN_FONT_TYPEWRITER:
1917 case LyXRC::RC_SCREEN_FONT_TYPEWRITER_FOUNDRY:
1918 case LyXRC::RC_GEOMETRY_SESSION:
1919 case LyXRC::RC_SCREEN_ZOOM:
1920 case LyXRC::RC_SERVERPIPE:
1921 case LyXRC::RC_SET_COLOR:
1922 case LyXRC::RC_SHOW_BANNER:
1923 case LyXRC::RC_OPEN_BUFFERS_IN_TABS:
1924 case LyXRC::RC_SPELL_COMMAND:
1925 case LyXRC::RC_TEMPDIRPATH:
1926 case LyXRC::RC_TEMPLATEPATH:
1927 case LyXRC::RC_TEX_ALLOWS_SPACES:
1928 case LyXRC::RC_TEX_EXPECTS_WINDOWS_PATHS:
1929 if (lyxrc_orig.windows_style_tex_paths != lyxrc_new.windows_style_tex_paths) {
1930 os::windows_style_tex_paths(lyxrc_new.windows_style_tex_paths);
1932 case LyXRC::RC_UIFILE:
1933 case LyXRC::RC_USER_EMAIL:
1934 case LyXRC::RC_USER_NAME:
1935 case LyXRC::RC_USETEMPDIR:
1936 case LyXRC::RC_USE_ALT_LANG:
1937 case LyXRC::RC_USE_CONVERTER_CACHE:
1938 case LyXRC::RC_USE_ESC_CHARS:
1939 case LyXRC::RC_USE_INP_ENC:
1940 case LyXRC::RC_USE_PERS_DICT:
1941 case LyXRC::RC_USE_TOOLTIP:
1942 case LyXRC::RC_USE_PIXMAP_CACHE:
1943 case LyXRC::RC_USE_SPELL_LIB:
1944 case LyXRC::RC_VIEWDVI_PAPEROPTION:
1945 case LyXRC::RC_SORT_LAYOUTS:
1946 case LyXRC::RC_FULL_SCREEN_LIMIT:
1947 case LyXRC::RC_FULL_SCREEN_SCROLLBAR:
1948 case LyXRC::RC_FULL_SCREEN_TABBAR:
1949 case LyXRC::RC_FULL_SCREEN_TOOLBARS:
1950 case LyXRC::RC_FULL_SCREEN_WIDTH:
1951 case LyXRC::RC_VISUAL_CURSOR:
1952 case LyXRC::RC_VIEWER:
1953 case LyXRC::RC_LAST: