2 * \file BufferView_pimpl.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Asger Alstrup
7 * \author Alfredo Braunstein
8 * \author Lars Gullik Bjønnes
9 * \author Jean-Marc Lasgouttes
10 * \author Angus Leeming
12 * \author André Pönitz
14 * \author Jürgen Vigna
16 * Full author contact details are available in file CREDITS.
21 #include "BufferView_pimpl.h"
23 #include "buffer_funcs.h"
24 #include "bufferlist.h"
25 #include "bufferparams.h"
28 #include "dispatchresult.h"
30 #include "FloatList.h"
31 #include "funcrequest.h"
34 #include "iterators.h"
35 #include "lyx_cb.h" // added for Dispatch functions
41 #include "lastfiles.h"
42 #include "paragraph.h"
43 #include "paragraph_funcs.h"
44 #include "ParagraphParameters.h"
48 #include "insets/insetref.h"
50 #include "frontends/Alert.h"
51 #include "frontends/Dialogs.h"
52 #include "frontends/FileDialog.h"
53 #include "frontends/LyXView.h"
54 #include "frontends/LyXScreenFactory.h"
55 #include "frontends/screen.h"
56 #include "frontends/WorkArea.h"
57 #include "frontends/WorkAreaFactory.h"
59 #include "graphics/Previews.h"
61 #include "support/filetools.h"
62 #include "support/globbing.h"
63 #include "support/path_defines.h"
64 #include "support/tostr.h"
66 #include <boost/bind.hpp>
70 using lyx::support::AddPath;
71 using lyx::support::bformat;
72 using lyx::support::FileFilterList;
73 using lyx::support::FileSearch;
74 using lyx::support::IsDirWriteable;
75 using lyx::support::MakeDisplayPath;
76 using lyx::support::strToUnsignedInt;
77 using lyx::support::system_lyxdir;
85 extern BufferList bufferlist;
90 unsigned int const saved_positions_num = 20;
92 // All the below connection objects are needed because of a bug in some
93 // versions of GCC (<=2.96 are on the suspects list.) By having and assigning
94 // to these connections we avoid a segfault upon startup, and also at exit.
97 boost::signals::connection dispatchcon;
98 boost::signals::connection timecon;
99 boost::signals::connection doccon;
100 boost::signals::connection resizecon;
101 boost::signals::connection kpresscon;
102 boost::signals::connection selectioncon;
103 boost::signals::connection lostcon;
109 BufferView::Pimpl::Pimpl(BufferView & bv, LyXView * owner,
110 int xpos, int ypos, int width, int height)
111 : bv_(&bv), owner_(owner), buffer_(0), cursor_timeout(400),
112 using_xterm_cursor(false), cursor_(bv)
114 xsel_cache_.set = false;
116 workarea_.reset(WorkAreaFactory::create(xpos, ypos, width, height));
117 screen_.reset(LyXScreenFactory::create(workarea()));
120 doccon = workarea().scrollDocView
121 .connect(boost::bind(&BufferView::Pimpl::scrollDocView, this, _1));
122 resizecon = workarea().workAreaResize
123 .connect(boost::bind(&BufferView::Pimpl::workAreaResize, this));
124 dispatchcon = workarea().dispatch
125 .connect(boost::bind(&BufferView::Pimpl::workAreaDispatch, this, _1));
126 kpresscon = workarea().workAreaKeyPress
127 .connect(boost::bind(&BufferView::Pimpl::workAreaKeyPress, this, _1, _2));
128 selectioncon = workarea().selectionRequested
129 .connect(boost::bind(&BufferView::Pimpl::selectionRequested, this));
130 lostcon = workarea().selectionLost
131 .connect(boost::bind(&BufferView::Pimpl::selectionLost, this));
133 timecon = cursor_timeout.timeout
134 .connect(boost::bind(&BufferView::Pimpl::cursorToggle, this));
135 cursor_timeout.start();
136 saved_positions.resize(saved_positions_num);
140 void BufferView::Pimpl::addError(ErrorItem const & ei)
142 errorlist_.push_back(ei);
146 void BufferView::Pimpl::showReadonly(bool)
148 owner_->updateWindowTitle();
149 owner_->getDialogs().updateBufferDependent(false);
153 void BufferView::Pimpl::connectBuffer(Buffer & buf)
155 if (errorConnection_.connected())
159 buf.error.connect(boost::bind(&BufferView::Pimpl::addError, this, _1));
161 buf.message.connect(boost::bind(&LyXView::message, owner_, _1));
163 buf.busy.connect(boost::bind(&LyXView::busy, owner_, _1));
165 buf.updateTitles.connect(boost::bind(&LyXView::updateWindowTitle, owner_));
167 buf.resetAutosaveTimers.connect(boost::bind(&LyXView::resetAutosaveTimer, owner_));
168 readonlyConnection_ =
169 buf.readonly.connect(boost::bind(&BufferView::Pimpl::showReadonly, this, _1));
171 buf.closing.connect(boost::bind(&BufferView::Pimpl::buffer, this, (Buffer *)0));
175 void BufferView::Pimpl::disconnectBuffer()
177 errorConnection_.disconnect();
178 messageConnection_.disconnect();
179 busyConnection_.disconnect();
180 titleConnection_.disconnect();
181 timerConnection_.disconnect();
182 readonlyConnection_.disconnect();
183 closingConnection_.disconnect();
187 bool BufferView::Pimpl::newFile(string const & filename,
188 string const & tname,
191 Buffer * b = ::newFile(filename, tname, isNamed);
197 bool BufferView::Pimpl::loadLyXFile(string const & filename, bool tolastfiles)
199 // get absolute path of file and add ".lyx" to the filename if
201 string s = FileSearch(string(), filename, "lyx");
203 bool const found = !s.empty();
208 // file already open?
209 if (bufferlist.exists(s)) {
210 string const file = MakeDisplayPath(s, 20);
211 string text = bformat(_("The document %1$s is already "
212 "loaded.\n\nDo you want to revert "
213 "to the saved version?"), file);
214 int const ret = Alert::prompt(_("Revert to saved document?"),
215 text, 0, 1, _("&Revert"), _("&Switch to document"));
218 buffer(bufferlist.getBuffer(s));
221 // FIXME: should be LFUN_REVERT
222 if (!bufferlist.close(bufferlist.getBuffer(s), false))
224 // Fall through to new load. (Asger)
231 b = bufferlist.newBuffer(s);
233 if (!::loadLyXFile(b, s)) {
234 bufferlist.release(b);
238 string text = bformat(_("The document %1$s does not yet "
239 "exist.\n\nDo you want to create "
240 "a new document?"), s);
241 int const ret = Alert::prompt(_("Create new document?"),
242 text, 0, 1, _("&Create"), _("Cancel"));
245 b = ::newFile(s, string(), true);
251 bv_->showErrorList(_("Parse"));
254 LyX::ref().lastfiles().newFile(b->fileName());
260 WorkArea & BufferView::Pimpl::workarea() const
262 return *workarea_.get();
266 LyXScreen & BufferView::Pimpl::screen() const
268 return *screen_.get();
272 Painter & BufferView::Pimpl::painter() const
274 return workarea().getPainter();
278 void BufferView::Pimpl::top_y(int y)
284 int BufferView::Pimpl::top_y() const
290 void BufferView::Pimpl::buffer(Buffer * b)
292 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
296 //delete bv_->text();
303 // set current buffer
308 // if we're quitting lyx, don't bother updating stuff
312 // if we are closing the buffer, use the first buffer as current
314 buffer_ = bufferlist.first();
317 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
318 connectBuffer(*buffer_);
320 buffer_->text().init(bv_);
321 buffer_->text().textwidth_ = workarea().workWidth();
322 buffer_->text().fullRebreak();
324 // If we don't have a text object for this, we make one
325 if (bv_->text() == 0)
326 resizeCurrentBuffer();
328 // Buffer-dependent dialogs should be updated or
329 // hidden. This should go here because some dialogs (eg ToC)
330 // require bv_->text.
331 owner_->getDialogs().updateBufferDependent(true);
333 lyxerr[Debug::INFO] << " No Buffer!" << endl;
334 owner_->getDialogs().hideBufferDependent();
339 owner_->updateMenubar();
340 owner_->updateToolbar();
341 owner_->updateLayoutChoice();
342 owner_->updateWindowTitle();
344 // Don't forget to update the Layout
346 owner_->setLayout(bv_->text()->getPar(0)->layout()->name());
348 if (lyx::graphics::Previews::activated() && buffer_)
349 lyx::graphics::Previews::get().generateBufferPreviews(*buffer_);
353 bool BufferView::Pimpl::fitCursor()
355 if (screen().fitCursor(bv_)) {
363 void BufferView::Pimpl::redoCurrentBuffer()
365 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
366 if (buffer_ && bv_->text()) {
367 resizeCurrentBuffer();
369 owner_->updateLayoutChoice();
374 void BufferView::Pimpl::resizeCurrentBuffer()
376 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
379 int selstartpar = -1;
383 pos_type selstartpos = 0;
384 pos_type selendpos = 0;
386 bool mark_set = false;
390 owner_->message(_("Formatting document..."));
392 LyXText * text = bv_->text();
393 lyxerr << "### resizeCurrentBuffer: text " << text << endl;
397 LCursor & cur = bv_->cursor();
400 selstartpar = cur.selBegin().par();
401 selstartpos = cur.selBegin().pos();
402 selendpar = cur.selEnd().par();
403 selendpos = cur.selEnd().pos();
404 sel = cur.selection();
405 mark_set = cur.mark();
406 text->textwidth_ = bv_->workWidth();
411 cur.selection() = true;
412 // At this point just to avoid the Delete-Empty-Paragraph-
413 // Mechanism when setting the cursor.
414 cur.mark() = mark_set;
416 text->setCursor(selstartpar, selstartpos);
418 text->setCursor(selendpar, selendpos);
420 text->setCursor(par, pos);
422 text->setCursor(par, pos);
424 cur.selection() = false;
433 // reset the "Formatting..." message
434 owner_->clearMessage();
440 void BufferView::Pimpl::updateScrollbar()
443 lyxerr[Debug::GUI] << "no text in updateScrollbar" << endl;
444 workarea().setScrollbarParams(0, 0, 0);
448 LyXText const & t = *bv_->text();
450 lyxerr[Debug::GUI] << "Updating scrollbar: h " << t.height << ", top_y() "
451 << top_y() << ", default height " << defaultRowHeight() << endl;
453 workarea().setScrollbarParams(t.height, top_y(), defaultRowHeight());
457 void BufferView::Pimpl::scrollDocView(int value)
459 lyxerr[Debug::GUI] << "scrollDocView of " << value << endl;
464 screen().hideCursor();
467 screen().redraw(*bv_);
469 if (!lyxrc.cursor_follows_scrollbar)
472 int const height = defaultRowHeight();
473 int const first = top_y() + height;
474 int const last = top_y() + workarea().workHeight() - height;
476 LyXText * text = bv_->text();
477 int y = text->cursorY(bv_->cursor().cursor_.front());
479 text->setCursorFromCoordinates(0, first);
481 text->setCursorFromCoordinates(0, last);
483 owner_->updateLayoutChoice();
487 void BufferView::Pimpl::scroll(int lines)
492 LyXText const * t = bv_->text();
493 int const line_height = defaultRowHeight();
495 // The new absolute coordinate
496 int new_top_y = top_y() + lines * line_height;
498 // Restrict to a valid value
499 new_top_y = std::min(t->height - 4 * line_height, new_top_y);
500 new_top_y = std::max(0, new_top_y);
502 scrollDocView(new_top_y);
504 // Update the scrollbar.
505 workarea().setScrollbarParams(t->height, top_y(), defaultRowHeight());
509 void BufferView::Pimpl::workAreaKeyPress(LyXKeySymPtr key,
510 key_modifier::state state)
512 bv_->owner()->getLyXFunc().processKeySym(key, state);
514 /* This is perhaps a bit of a hack. When we move
515 * around, or type, it's nice to be able to see
516 * the cursor immediately after the keypress. So
517 * we reset the toggle timeout and force the visibility
518 * of the cursor. Note we cannot do this inside
519 * dispatch() itself, because that's called recursively.
522 cursor_timeout.restart();
523 screen().showCursor(*bv_);
528 void BufferView::Pimpl::selectionRequested()
535 LCursor & cur = bv_->cursor();
537 if (!cur.selection()) {
538 xsel_cache_.set = false;
542 if (!xsel_cache_.set ||
543 cur.cursor_.back() != xsel_cache_.cursor ||
544 cur.anchor_.back() != xsel_cache_.anchor)
546 xsel_cache_.cursor = cur.cursor_.back();
547 xsel_cache_.anchor = cur.anchor_.back();
548 xsel_cache_.set = cur.selection();
549 sel = cur.selectionAsString(false);
551 workarea().putClipboard(sel);
556 void BufferView::Pimpl::selectionLost()
559 screen().hideCursor();
560 bv_->cursor().clearSelection();
561 xsel_cache_.set = false;
566 void BufferView::Pimpl::workAreaResize()
568 static int work_area_width;
569 static int work_area_height;
571 bool const widthChange = workarea().workWidth() != work_area_width;
572 bool const heightChange = workarea().workHeight() != work_area_height;
574 // update from work area
575 work_area_width = workarea().workWidth();
576 work_area_height = workarea().workHeight();
578 if (buffer_ && widthChange) {
579 // The visible LyXView need a resize
580 resizeCurrentBuffer();
583 if (widthChange || heightChange)
586 // always make sure that the scrollbar is sane.
588 owner_->updateLayoutChoice();
592 void BufferView::Pimpl::update()
594 //lyxerr << "BufferView::update()" << endl;
595 // fix cursor coordinate cache in case something went wrong
597 // check needed to survive LyX startup
598 if (bv_->getLyXText()) {
599 // update all 'visible' paragraphs
600 ParagraphList::iterator beg;
601 ParagraphList::iterator end;
602 getParsInRange(buffer_->paragraphs(),
603 top_y(), top_y() + workarea().workHeight(),
605 bv_->text()->redoParagraphs(beg, end);
608 screen().redraw(*bv_);
612 // Callback for cursor timer
613 void BufferView::Pimpl::cursorToggle()
616 cursor_timeout.restart();
620 screen().toggleCursor(*bv_);
621 cursor_timeout.restart();
625 bool BufferView::Pimpl::available() const
627 return buffer_ && bv_->text();
631 Change const BufferView::Pimpl::getCurrentChange()
633 if (!bv_->buffer()->params().tracking_changes)
634 return Change(Change::UNCHANGED);
636 LyXText * text = bv_->getLyXText();
637 LCursor & cur = bv_->cursor();
639 if (!cur.selection())
640 return Change(Change::UNCHANGED);
642 return text->getPar(cur.selBegin())
643 ->lookupChangeFull(cur.selBegin().pos());
647 void BufferView::Pimpl::savePosition(unsigned int i)
649 if (i >= saved_positions_num)
651 saved_positions[i] = Position(buffer_->fileName(),
652 bv_->text()->cursorPar()->id(),
653 bv_->text()->cursor().pos());
655 owner_->message(bformat(_("Saved bookmark %1$s"), tostr(i)));
659 void BufferView::Pimpl::restorePosition(unsigned int i)
661 if (i >= saved_positions_num)
664 string const fname = saved_positions[i].filename;
666 bv_->cursor().clearSelection();
668 if (fname != buffer_->fileName()) {
670 if (bufferlist.exists(fname))
671 b = bufferlist.getBuffer(fname);
673 b = bufferlist.newBuffer(fname);
674 ::loadLyXFile(b, fname); // don't ask, just load it
680 ParIterator par = buffer_->getParFromID(saved_positions[i].par_id);
681 if (par == buffer_->par_iterator_end())
684 bv_->text()->setCursor(bv_->text()->parOffset(par.pit()),
685 min(par->size(), saved_positions[i].par_pos));
688 owner_->message(bformat(_("Moved to bookmark %1$s"), tostr(i)));
692 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
694 return i < saved_positions_num && !saved_positions[i].filename.empty();
698 void BufferView::Pimpl::switchKeyMap()
700 if (!lyxrc.rtl_support)
703 Intl & intl = owner_->getIntl();
704 if (bv_->getLyXText()->real_current_font.isRightToLeft()) {
705 if (intl.keymap == Intl::PRIMARY)
708 if (intl.keymap == Intl::SECONDARY)
714 void BufferView::Pimpl::center()
716 LyXText * text = bv_->text();
718 bv_->cursor().clearSelection();
719 int const half_height = workarea().workHeight() / 2;
720 int new_y = text->cursorY(bv_->cursor().cursor_.front()) - half_height;
724 // FIXME: look at this comment again ...
725 // This updates top_y() but means the fitCursor() call
726 // from the update(FITCUR) doesn't realise that we might
727 // have moved (e.g. from GOTOPARAGRAPH), so doesn't cause
728 // the scrollbar to be updated as it should, so we have
729 // to do it manually. Any operation that does a center()
730 // and also might have moved top_y() must make sure to call
731 // updateScrollbar() currently. Never mind that this is a
732 // pretty obfuscated way of updating text->top_y()
737 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
739 workarea().putClipboard(stuff);
743 InsetBase * BufferView::Pimpl::getInsetByCode(InsetBase::Code code)
745 // Ok, this is a little bit too brute force but it
746 // should work for now. Better infrastructure is coming. (Lgb)
748 Buffer * b = bv_->buffer();
749 LyXText * text = bv_->getLyXText();
751 Buffer::inset_iterator beg = b->inset_iterator_begin();
752 Buffer::inset_iterator end = b->inset_iterator_end();
754 bool cursor_par_seen = false;
756 for (; beg != end; ++beg) {
757 if (beg.getPar() == text->cursorPar()) {
758 cursor_par_seen = true;
760 if (cursor_par_seen) {
761 if (beg.getPar() == text->cursorPar()
762 && beg.getPos() >= text->cursor().pos()) {
765 if (beg.getPar() != text->cursorPar()) {
772 // Now find the first inset that matches code.
773 for (; beg != end; ++beg) {
774 if (beg->lyxCode() == code)
782 void BufferView::Pimpl::MenuInsertLyXFile(string const & filenm)
784 string filename = filenm;
786 if (filename.empty()) {
787 // Launch a file browser
788 string initpath = lyxrc.document_path;
791 string const trypath = owner_->buffer()->filePath();
792 // If directory is writeable, use this as default.
793 if (IsDirWriteable(trypath))
797 FileDialog fileDlg(_("Select LyX document to insert"),
799 make_pair(string(_("Documents|#o#O")),
800 string(lyxrc.document_path)),
801 make_pair(string(_("Examples|#E#e")),
802 string(AddPath(system_lyxdir(), "examples"))));
804 FileDialog::Result result =
805 fileDlg.open(initpath,
806 FileFilterList(_("LyX Documents (*.lyx)")),
809 if (result.first == FileDialog::Later)
812 filename = result.second;
814 // check selected filename
815 if (filename.empty()) {
816 owner_->message(_("Canceled."));
821 // get absolute path of file and add ".lyx" to the filename if
823 filename = FileSearch(string(), filename, "lyx");
825 string const disp_fn = MakeDisplayPath(filename);
826 owner_->message(bformat(_("Inserting document %1$s..."), disp_fn));
827 if (bv_->insertLyXFile(filename))
828 owner_->message(bformat(_("Document %1$s inserted."),
831 owner_->message(bformat(_("Could not insert document %1$s"),
836 void BufferView::Pimpl::trackChanges()
838 Buffer * buf = bv_->buffer();
839 bool const tracking(buf->params().tracking_changes);
842 ParIterator const end = buf->par_iterator_end();
843 for (ParIterator it = buf->par_iterator_begin(); it != end; ++it)
845 buf->params().tracking_changes = true;
847 // we cannot allow undos beyond the freeze point
848 buf->undostack().clear();
851 bv_->text()->setCursor(0, 0);
852 #warning changes FIXME
853 bool found = lyx::find::findNextChange(bv_);
855 owner_->getDialogs().show("changes");
859 ParIterator const end = buf->par_iterator_end();
860 for (ParIterator it = buf->par_iterator_begin(); it != end; ++it)
861 it->untrackChanges();
862 buf->params().tracking_changes = false;
865 buf->redostack().clear();
869 bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd0)
872 // this is only called for mouse related events.
874 FuncRequest cmd = cmd0;
875 cmd.y += bv_->top_y();
876 //lyxerr << "*** workAreaDispatch: request: " << cmd << std::endl;
878 cur.selection() = bv_->cursor().selection();
879 switch (cmd.action) {
882 case LFUN_MOUSE_MOTION: {
885 FuncRequest cmd1 = cmd;
886 InsetBase * inset = cur.inset();
889 res = inset->dispatch(cur, cmd);
891 res = bv_->text()->dispatch(cur, cmd);
894 if (fitCursor() || res.update()) {
901 case LFUN_MOUSE_MOTION:
904 case LFUN_MOUSE_PRESS:
905 case LFUN_MOUSE_RELEASE:
906 case LFUN_MOUSE_DOUBLE:
907 case LFUN_MOUSE_TRIPLE: {
908 // We pass those directly to the Bufferview, since
909 // otherwise selection handling breaks down
911 // Doesn't go through lyxfunc, so we need to update
912 // the layout choice etc. ourselves
914 // e.g. Qt mouse press when no buffer
918 screen().hideCursor();
920 // either the inset under the cursor or the
921 // surrounding LyXText will handle this event.
923 // built temporary path to inset
924 LyXText * text = bv_->text();
925 InsetBase * const inset_hit = text->checkInsetHit(cmd.x, cmd.y);
927 inset_hit->edit(cur, cmd.x, cmd.y);
929 text->setCursorFromCoordinates(cur.current(), cmd.x, cmd.y);
930 lyxerr << "created temp cursor: " << cur << endl;
932 // Dispatch to the temp cursor.
933 // An inset (or LyXText) can assign this to bv->cursor()
934 // if it wishes to do so.
935 DispatchResult res = cur.dispatch(cmd);
937 if (fitCursor() || res.update())
940 // see workAreaKeyPress
941 cursor_timeout.restart();
942 screen().showCursor(*bv_);
944 // skip these when selecting
945 if (cmd.action != LFUN_MOUSE_MOTION) {
946 owner_->updateLayoutChoice();
947 owner_->updateToolbar();
950 // slight hack: this is only called currently when we
951 // clicked somewhere, so we force through the display
952 // of the new status here.
953 owner_->clearMessage();
964 bool BufferView::Pimpl::dispatch(FuncRequest const & cmd)
966 //lyxerr << "*** BufferView::Pimpl: request: " << cmd << std::endl;
967 // Make sure that the cached BufferView is correct.
968 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch:"
969 << " action[" << cmd.action << ']'
970 << " arg[" << cmd.argument << ']'
971 << " x[" << cmd.x << ']'
972 << " y[" << cmd.y << ']'
973 << " button[" << cmd.button() << ']'
976 LCursor & cur = bv_->cursor();
978 switch (cmd.action) {
982 cur.message(_("Undo"));
983 cur.clearSelection();
985 cur.message(_("No further undo information"));
993 cur.message(_("Redo"));
994 cur.clearSelection();
996 cur.message(_("No further redo information"));
1002 case LFUN_FILE_INSERT:
1003 MenuInsertLyXFile(cmd.argument);
1006 case LFUN_FILE_INSERT_ASCII_PARA:
1007 InsertAsciiFile(bv_, cmd.argument, true);
1010 case LFUN_FILE_INSERT_ASCII:
1011 InsertAsciiFile(bv_, cmd.argument, false);
1014 case LFUN_FONT_STATE:
1015 cur.message(cur.currentState());
1018 case LFUN_INSERT_LABEL: {
1019 // Try and generate a valid label
1020 string const contents = cmd.argument.empty() ?
1021 getPossibleLabel(*bv_) : cmd.argument;
1022 InsetCommandParams icp("label", contents);
1023 string data = InsetCommandMailer::params2string("label", icp);
1024 owner_->getDialogs().show("label", data, 0);
1028 case LFUN_BOOKMARK_SAVE:
1029 savePosition(strToUnsignedInt(cmd.argument));
1032 case LFUN_BOOKMARK_GOTO:
1033 restorePosition(strToUnsignedInt(cmd.argument));
1036 case LFUN_REF_GOTO: {
1037 string label = cmd.argument;
1038 if (label.empty()) {
1040 static_cast<InsetRef*>(getInsetByCode(InsetBase::REF_CODE));
1042 label = inset->getContents();
1048 bv_->gotoLabel(label);
1052 case LFUN_PARAGRAPH_APPLY:
1053 setParagraphParams(*bv_, cmd.argument);
1056 case LFUN_TRACK_CHANGES:
1060 case LFUN_MERGE_CHANGES:
1061 owner_->getDialogs().show("changes");
1064 case LFUN_ACCEPT_ALL_CHANGES: {
1065 bv_->cursor().reset();
1066 #warning FIXME changes
1067 while (lyx::find::findNextChange(bv_))
1068 bv_->getLyXText()->acceptChange(bv_->cursor());
1073 case LFUN_REJECT_ALL_CHANGES: {
1074 bv_->cursor().reset();
1075 #warning FIXME changes
1076 while (lyx::find::findNextChange(bv_))
1077 bv_->getLyXText()->rejectChange(bv_->cursor());
1082 case LFUN_WORD_FIND:
1083 lyx::find::find(bv_, cmd);
1086 case LFUN_WORD_REPLACE:
1087 lyx::find::replace(bv_, cmd);
1091 cur.clearSelection();
1094 cur.message(N_("Mark off"));
1098 cur.clearSelection();
1102 cur.message(N_("Mark on"));
1106 cur.clearSelection();
1108 cur.message(N_("Mark removed"));
1111 cur.message(N_("Mark set"));
1117 case LFUN_UNKNOWN_ACTION:
1118 cur.errorMessage(N_("Unknown function!"));
1129 bool BufferView::Pimpl::ChangeInsets(InsetBase::Code code,
1130 string const & from, string const & to)
1132 bool need_update = false;
1133 CursorSlice cur = bv_->text()->cursor();
1135 ParIterator end = bv_->buffer()->par_iterator_end();
1136 for (ParIterator it = bv_->buffer()->par_iterator_begin();
1138 bool changed_inset = false;
1139 for (InsetList::iterator it2 = it->insetlist.begin();
1140 it2 != it->insetlist.end(); ++it2) {
1141 if (it2->inset->lyxCode() == code) {
1142 InsetCommand * inset = static_cast<InsetCommand *>(it2->inset);
1143 if (inset->getContents() == from) {
1144 inset->setContents(to);
1145 changed_inset = true;
1149 if (changed_inset) {
1154 // The test it.size() == 1 was needed to prevent crashes.
1155 // How to set the cursor correctly when it.size() > 1 ??
1156 if (it.size() == 1) {
1157 bv_->text()->setCursorIntern(bv_->text()->parOffset(it.pit()), 0);
1158 bv_->text()->redoParagraph(bv_->text()->cursorPar());
1162 bv_->text()->setCursorIntern(cur.par(), cur.pos());