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/insetfloatlist.h"
49 #include "insets/insetref.h"
51 #include "frontends/Alert.h"
52 #include "frontends/Dialogs.h"
53 #include "frontends/FileDialog.h"
54 #include "frontends/LyXView.h"
55 #include "frontends/LyXScreenFactory.h"
56 #include "frontends/screen.h"
57 #include "frontends/WorkArea.h"
58 #include "frontends/WorkAreaFactory.h"
60 #include "graphics/Previews.h"
62 #include "support/filetools.h"
63 #include "support/globbing.h"
64 #include "support/path_defines.h"
65 #include "support/tostr.h"
67 #include <boost/bind.hpp>
69 using bv_funcs::currentState;
73 using lyx::support::AddPath;
74 using lyx::support::bformat;
75 using lyx::support::FileFilterList;
76 using lyx::support::FileSearch;
77 using lyx::support::IsDirWriteable;
78 using lyx::support::MakeDisplayPath;
79 using lyx::support::strToUnsignedInt;
80 using lyx::support::system_lyxdir;
88 extern BufferList bufferlist;
93 unsigned int const saved_positions_num = 20;
95 // All the below connection objects are needed because of a bug in some
96 // versions of GCC (<=2.96 are on the suspects list.) By having and assigning
97 // to these connections we avoid a segfault upon startup, and also at exit.
100 boost::signals::connection dispatchcon;
101 boost::signals::connection timecon;
102 boost::signals::connection doccon;
103 boost::signals::connection resizecon;
104 boost::signals::connection kpresscon;
105 boost::signals::connection selectioncon;
106 boost::signals::connection lostcon;
112 BufferView::Pimpl::Pimpl(BufferView & bv, LyXView * owner,
113 int xpos, int ypos, int width, int height)
114 : bv_(&bv), owner_(owner), buffer_(0), cursor_timeout(400),
115 using_xterm_cursor(false), cursor_(bv)
117 xsel_cache_.set = false;
119 workarea_.reset(WorkAreaFactory::create(xpos, ypos, width, height));
120 screen_.reset(LyXScreenFactory::create(workarea()));
123 doccon = workarea().scrollDocView
124 .connect(boost::bind(&BufferView::Pimpl::scrollDocView, this, _1));
125 resizecon = workarea().workAreaResize
126 .connect(boost::bind(&BufferView::Pimpl::workAreaResize, this));
127 dispatchcon = workarea().dispatch
128 .connect(boost::bind(&BufferView::Pimpl::workAreaDispatch, this, _1));
129 kpresscon = workarea().workAreaKeyPress
130 .connect(boost::bind(&BufferView::Pimpl::workAreaKeyPress, this, _1, _2));
131 selectioncon = workarea().selectionRequested
132 .connect(boost::bind(&BufferView::Pimpl::selectionRequested, this));
133 lostcon = workarea().selectionLost
134 .connect(boost::bind(&BufferView::Pimpl::selectionLost, this));
136 timecon = cursor_timeout.timeout
137 .connect(boost::bind(&BufferView::Pimpl::cursorToggle, this));
138 cursor_timeout.start();
139 saved_positions.resize(saved_positions_num);
143 void BufferView::Pimpl::addError(ErrorItem const & ei)
145 errorlist_.push_back(ei);
149 void BufferView::Pimpl::showReadonly(bool)
151 owner_->updateWindowTitle();
152 owner_->getDialogs().updateBufferDependent(false);
156 void BufferView::Pimpl::connectBuffer(Buffer & buf)
158 if (errorConnection_.connected())
162 buf.error.connect(boost::bind(&BufferView::Pimpl::addError, this, _1));
164 buf.message.connect(boost::bind(&LyXView::message, owner_, _1));
166 buf.busy.connect(boost::bind(&LyXView::busy, owner_, _1));
168 buf.updateTitles.connect(boost::bind(&LyXView::updateWindowTitle, owner_));
170 buf.resetAutosaveTimers.connect(boost::bind(&LyXView::resetAutosaveTimer, owner_));
171 readonlyConnection_ =
172 buf.readonly.connect(boost::bind(&BufferView::Pimpl::showReadonly, this, _1));
174 buf.closing.connect(boost::bind(&BufferView::Pimpl::buffer, this, (Buffer *)0));
178 void BufferView::Pimpl::disconnectBuffer()
180 errorConnection_.disconnect();
181 messageConnection_.disconnect();
182 busyConnection_.disconnect();
183 titleConnection_.disconnect();
184 timerConnection_.disconnect();
185 readonlyConnection_.disconnect();
186 closingConnection_.disconnect();
190 bool BufferView::Pimpl::newFile(string const & filename,
191 string const & tname,
194 Buffer * b = ::newFile(filename, tname, isNamed);
200 bool BufferView::Pimpl::loadLyXFile(string const & filename, bool tolastfiles)
202 // get absolute path of file and add ".lyx" to the filename if
204 string s = FileSearch(string(), filename, "lyx");
206 bool const found = !s.empty();
211 // file already open?
212 if (bufferlist.exists(s)) {
213 string const file = MakeDisplayPath(s, 20);
214 string text = bformat(_("The document %1$s is already "
215 "loaded.\n\nDo you want to revert "
216 "to the saved version?"), file);
217 int const ret = Alert::prompt(_("Revert to saved document?"),
218 text, 0, 1, _("&Revert"), _("&Switch to document"));
221 buffer(bufferlist.getBuffer(s));
224 // FIXME: should be LFUN_REVERT
225 if (!bufferlist.close(bufferlist.getBuffer(s), false))
227 // Fall through to new load. (Asger)
234 b = bufferlist.newBuffer(s);
236 if (!::loadLyXFile(b, s)) {
237 bufferlist.release(b);
241 string text = bformat(_("The document %1$s does not yet "
242 "exist.\n\nDo you want to create "
243 "a new document?"), s);
244 int const ret = Alert::prompt(_("Create new document?"),
245 text, 0, 1, _("&Create"), _("Cancel"));
248 b = ::newFile(s, string(), true);
254 bv_->showErrorList(_("Parse"));
257 LyX::ref().lastfiles().newFile(b->fileName());
263 WorkArea & BufferView::Pimpl::workarea() const
265 return *workarea_.get();
269 LyXScreen & BufferView::Pimpl::screen() const
271 return *screen_.get();
275 Painter & BufferView::Pimpl::painter() const
277 return workarea().getPainter();
281 void BufferView::Pimpl::top_y(int y)
287 int BufferView::Pimpl::top_y() const
293 void BufferView::Pimpl::buffer(Buffer * b)
295 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
299 //delete bv_->text();
306 // set current buffer
311 // if we're quitting lyx, don't bother updating stuff
315 // if we are closing the buffer, use the first buffer as current
317 buffer_ = bufferlist.first();
320 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
321 connectBuffer(*buffer_);
323 buffer_->text().init(bv_);
324 buffer_->text().textwidth_ = workarea().workWidth();
325 buffer_->text().fullRebreak();
327 // If we don't have a text object for this, we make one
328 if (bv_->text() == 0)
329 resizeCurrentBuffer();
331 // Buffer-dependent dialogs should be updated or
332 // hidden. This should go here because some dialogs (eg ToC)
333 // require bv_->text.
334 owner_->getDialogs().updateBufferDependent(true);
336 lyxerr[Debug::INFO] << " No Buffer!" << endl;
337 owner_->getDialogs().hideBufferDependent();
342 owner_->updateMenubar();
343 owner_->updateToolbar();
344 owner_->updateLayoutChoice();
345 owner_->updateWindowTitle();
347 // Don't forget to update the Layout
349 owner_->setLayout(bv_->text()->cursorPar()->layout()->name());
351 if (lyx::graphics::Previews::activated() && buffer_)
352 lyx::graphics::Previews::get().generateBufferPreviews(*buffer_);
356 bool BufferView::Pimpl::fitCursor()
358 if (screen().fitCursor(bv_)) {
366 void BufferView::Pimpl::redoCurrentBuffer()
368 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
369 if (buffer_ && bv_->text()) {
370 resizeCurrentBuffer();
372 owner_->updateLayoutChoice();
377 void BufferView::Pimpl::resizeCurrentBuffer()
379 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
382 int selstartpar = -1;
386 pos_type selstartpos = 0;
387 pos_type selendpos = 0;
389 bool mark_set = false;
393 owner_->message(_("Formatting document..."));
395 LyXText * text = bv_->text();
396 lyxerr << "### resizeCurrentBuffer: text " << text << endl;
400 LCursor & cur = bv_->cursor();
403 selstartpar = cur.selBegin().par();
404 selstartpos = cur.selBegin().pos();
405 selendpar = cur.selEnd().par();
406 selendpos = cur.selEnd().pos();
407 sel = cur.selection();
408 mark_set = cur.mark();
409 text->textwidth_ = bv_->workWidth();
414 cur.selection() = true;
415 // At this point just to avoid the Delete-Empty-Paragraph-
416 // Mechanism when setting the cursor.
417 cur.mark() = mark_set;
419 text->setCursor(selstartpar, selstartpos);
421 text->setCursor(selendpar, selendpos);
423 text->setCursor(par, pos);
425 text->setCursor(par, pos);
427 cur.selection() = false;
436 // reset the "Formatting..." message
437 owner_->clearMessage();
443 void BufferView::Pimpl::updateScrollbar()
446 lyxerr[Debug::GUI] << "no text in updateScrollbar" << endl;
447 workarea().setScrollbarParams(0, 0, 0);
451 LyXText const & t = *bv_->text();
453 lyxerr[Debug::GUI] << "Updating scrollbar: h " << t.height << ", top_y() "
454 << top_y() << ", default height " << defaultRowHeight() << endl;
456 workarea().setScrollbarParams(t.height, top_y(), defaultRowHeight());
460 void BufferView::Pimpl::scrollDocView(int value)
462 lyxerr[Debug::GUI] << "scrollDocView of " << value << endl;
467 screen().hideCursor();
470 screen().redraw(*bv_);
472 if (!lyxrc.cursor_follows_scrollbar)
475 int const height = defaultRowHeight();
476 int const first = top_y() + height;
477 int const last = top_y() + workarea().workHeight() - height;
479 LyXText * text = bv_->text();
480 int y = text->cursorY(bv_->cursor().cursor_.front());
482 text->setCursorFromCoordinates(0, first);
484 text->setCursorFromCoordinates(0, last);
486 owner_->updateLayoutChoice();
490 void BufferView::Pimpl::scroll(int lines)
495 LyXText const * t = bv_->text();
496 int const line_height = defaultRowHeight();
498 // The new absolute coordinate
499 int new_top_y = top_y() + lines * line_height;
501 // Restrict to a valid value
502 new_top_y = std::min(t->height - 4 * line_height, new_top_y);
503 new_top_y = std::max(0, new_top_y);
505 scrollDocView(new_top_y);
507 // Update the scrollbar.
508 workarea().setScrollbarParams(t->height, top_y(), defaultRowHeight());
512 void BufferView::Pimpl::workAreaKeyPress(LyXKeySymPtr key,
513 key_modifier::state state)
515 bv_->owner()->getLyXFunc().processKeySym(key, state);
517 /* This is perhaps a bit of a hack. When we move
518 * around, or type, it's nice to be able to see
519 * the cursor immediately after the keypress. So
520 * we reset the toggle timeout and force the visibility
521 * of the cursor. Note we cannot do this inside
522 * dispatch() itself, because that's called recursively.
525 cursor_timeout.restart();
526 screen().showCursor(*bv_);
531 void BufferView::Pimpl::selectionRequested()
538 LCursor & cur = bv_->cursor();
540 if (!cur.selection()) {
541 xsel_cache_.set = false;
545 if (!xsel_cache_.set ||
546 cur.cursor_.back() != xsel_cache_.cursor ||
547 cur.anchor_.back() != xsel_cache_.anchor)
549 xsel_cache_.cursor = cur.cursor_.back();
550 xsel_cache_.anchor = cur.anchor_.back();
551 xsel_cache_.set = cur.selection();
552 sel = cur.selectionAsString(false);
554 workarea().putClipboard(sel);
559 void BufferView::Pimpl::selectionLost()
562 screen().hideCursor();
563 bv_->cursor().clearSelection();
564 xsel_cache_.set = false;
569 void BufferView::Pimpl::workAreaResize()
571 static int work_area_width;
572 static int work_area_height;
574 bool const widthChange = workarea().workWidth() != work_area_width;
575 bool const heightChange = workarea().workHeight() != work_area_height;
577 // update from work area
578 work_area_width = workarea().workWidth();
579 work_area_height = workarea().workHeight();
581 if (buffer_ && widthChange) {
582 // The visible LyXView need a resize
583 resizeCurrentBuffer();
586 if (widthChange || heightChange)
589 // always make sure that the scrollbar is sane.
591 owner_->updateLayoutChoice();
595 void BufferView::Pimpl::update()
597 //lyxerr << "BufferView::update()" << endl;
598 // fix cursor coordinate cache in case something went wrong
600 // check needed to survive LyX startup
601 if (bv_->getLyXText()) {
602 // update all 'visible' paragraphs
603 ParagraphList::iterator beg;
604 ParagraphList::iterator end;
605 getParsInRange(buffer_->paragraphs(),
606 top_y(), top_y() + workarea().workHeight(),
608 bv_->text()->redoParagraphs(beg, end);
611 screen().redraw(*bv_);
615 // Callback for cursor timer
616 void BufferView::Pimpl::cursorToggle()
619 cursor_timeout.restart();
623 screen().toggleCursor(*bv_);
624 cursor_timeout.restart();
628 bool BufferView::Pimpl::available() const
630 return buffer_ && bv_->text();
634 Change const BufferView::Pimpl::getCurrentChange()
636 if (!bv_->buffer()->params().tracking_changes)
637 return Change(Change::UNCHANGED);
639 LyXText * text = bv_->getLyXText();
640 LCursor & cur = bv_->cursor();
642 if (!cur.selection())
643 return Change(Change::UNCHANGED);
645 return text->getPar(cur.selBegin())
646 ->lookupChangeFull(cur.selBegin().pos());
650 void BufferView::Pimpl::savePosition(unsigned int i)
652 if (i >= saved_positions_num)
654 saved_positions[i] = Position(buffer_->fileName(),
655 bv_->text()->cursorPar()->id(),
656 bv_->text()->cursor().pos());
658 owner_->message(bformat(_("Saved bookmark %1$s"), tostr(i)));
662 void BufferView::Pimpl::restorePosition(unsigned int i)
664 if (i >= saved_positions_num)
667 string const fname = saved_positions[i].filename;
669 bv_->cursor().clearSelection();
671 if (fname != buffer_->fileName()) {
673 if (bufferlist.exists(fname))
674 b = bufferlist.getBuffer(fname);
676 b = bufferlist.newBuffer(fname);
677 ::loadLyXFile(b, fname); // don't ask, just load it
683 ParIterator par = buffer_->getParFromID(saved_positions[i].par_id);
684 if (par == buffer_->par_iterator_end())
687 bv_->text()->setCursor(par.pit(),
688 min(par->size(), saved_positions[i].par_pos));
691 owner_->message(bformat(_("Moved to bookmark %1$s"), tostr(i)));
695 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
697 return i < saved_positions_num && !saved_positions[i].filename.empty();
701 void BufferView::Pimpl::switchKeyMap()
703 if (!lyxrc.rtl_support)
706 Intl & intl = owner_->getIntl();
707 if (bv_->getLyXText()->real_current_font.isRightToLeft()) {
708 if (intl.keymap == Intl::PRIMARY)
711 if (intl.keymap == Intl::SECONDARY)
717 void BufferView::Pimpl::center()
719 LyXText * text = bv_->text();
721 bv_->cursor().clearSelection();
722 int const half_height = workarea().workHeight() / 2;
723 int new_y = text->cursorY(bv_->cursor().cursor_.front()) - half_height;
727 // FIXME: look at this comment again ...
728 // This updates top_y() but means the fitCursor() call
729 // from the update(FITCUR) doesn't realise that we might
730 // have moved (e.g. from GOTOPARAGRAPH), so doesn't cause
731 // the scrollbar to be updated as it should, so we have
732 // to do it manually. Any operation that does a center()
733 // and also might have moved top_y() must make sure to call
734 // updateScrollbar() currently. Never mind that this is a
735 // pretty obfuscated way of updating text->top_y()
740 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
742 workarea().putClipboard(stuff);
746 InsetBase * BufferView::Pimpl::getInsetByCode(InsetBase::Code code)
749 CursorSlice cursor = bv_->getLyXText()->cursor;
750 Buffer::inset_iterator it =
751 find_if(Buffer::inset_iterator(
752 cursorPar(), cursor().pos()),
753 buffer_->inset_iterator_end(),
754 lyx::compare_memfun(&Inset::lyxCode, code));
755 return it != buffer_->inset_iterator_end() ? (*it) : 0;
757 // Ok, this is a little bit too brute force but it
758 // should work for now. Better infrastructure is coming. (Lgb)
760 Buffer * b = bv_->buffer();
761 LyXText * text = bv_->getLyXText();
763 Buffer::inset_iterator beg = b->inset_iterator_begin();
764 Buffer::inset_iterator end = b->inset_iterator_end();
766 bool cursor_par_seen = false;
768 for (; beg != end; ++beg) {
769 if (beg.getPar() == text->cursorPar()) {
770 cursor_par_seen = true;
772 if (cursor_par_seen) {
773 if (beg.getPar() == text->cursorPar()
774 && beg.getPos() >= text->cursor().pos()) {
777 if (beg.getPar() != text->cursorPar()) {
784 // Now find the first inset that matches code.
785 for (; beg != end; ++beg) {
786 if (beg->lyxCode() == code)
795 void BufferView::Pimpl::MenuInsertLyXFile(string const & filenm)
797 string filename = filenm;
799 if (filename.empty()) {
800 // Launch a file browser
801 string initpath = lyxrc.document_path;
804 string const trypath = owner_->buffer()->filePath();
805 // If directory is writeable, use this as default.
806 if (IsDirWriteable(trypath))
810 FileDialog fileDlg(_("Select LyX document to insert"),
812 make_pair(string(_("Documents|#o#O")),
813 string(lyxrc.document_path)),
814 make_pair(string(_("Examples|#E#e")),
815 string(AddPath(system_lyxdir(), "examples"))));
817 FileDialog::Result result =
818 fileDlg.open(initpath,
819 FileFilterList(_("LyX Documents (*.lyx)")),
822 if (result.first == FileDialog::Later)
825 filename = result.second;
827 // check selected filename
828 if (filename.empty()) {
829 owner_->message(_("Canceled."));
834 // get absolute path of file and add ".lyx" to the filename if
836 filename = FileSearch(string(), filename, "lyx");
838 string const disp_fn = MakeDisplayPath(filename);
839 owner_->message(bformat(_("Inserting document %1$s..."), disp_fn));
840 if (bv_->insertLyXFile(filename))
841 owner_->message(bformat(_("Document %1$s inserted."),
844 owner_->message(bformat(_("Could not insert document %1$s"),
849 void BufferView::Pimpl::trackChanges()
851 Buffer * buf = bv_->buffer();
852 bool const tracking(buf->params().tracking_changes);
855 ParIterator const end = buf->par_iterator_end();
856 for (ParIterator it = buf->par_iterator_begin(); it != end; ++it)
858 buf->params().tracking_changes = true;
860 // we cannot allow undos beyond the freeze point
861 buf->undostack().clear();
864 bv_->text()->setCursor(0, 0);
865 #warning changes FIXME
866 bool found = lyx::find::findNextChange(bv_);
868 owner_->getDialogs().show("changes");
872 ParIterator const end = buf->par_iterator_end();
873 for (ParIterator it = buf->par_iterator_begin(); it != end; ++it)
874 it->untrackChanges();
875 buf->params().tracking_changes = false;
878 buf->redostack().clear();
882 bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd0)
885 // this is only called for mouse related events.
887 FuncRequest cmd = cmd0;
888 cmd.y += bv_->top_y();
889 //lyxerr << "*** workAreaDispatch: request: " << cmd << std::endl;
891 cur.selection() = bv_->cursor().selection();
892 switch (cmd.action) {
895 case LFUN_MOUSE_MOTION: {
898 FuncRequest cmd1 = cmd;
899 InsetBase * inset = cur.inset();
902 res = inset->dispatch(cur, cmd);
904 res = bv_->text()->dispatch(cur, cmd);
907 if (fitCursor() || res.update()) {
914 case LFUN_MOUSE_MOTION:
917 case LFUN_MOUSE_PRESS:
918 case LFUN_MOUSE_RELEASE:
919 case LFUN_MOUSE_DOUBLE:
920 case LFUN_MOUSE_TRIPLE: {
921 // We pass those directly to the Bufferview, since
922 // otherwise selection handling breaks down
924 // Doesn't go through lyxfunc, so we need to update
925 // the layout choice etc. ourselves
927 // e.g. Qt mouse press when no buffer
931 screen().hideCursor();
933 // either the inset under the cursor or the
934 // surrounding LyXText will handle this event.
936 // built temporary path to inset
937 LyXText * text = bv_->text();
938 InsetBase * const inset_hit = text->checkInsetHit(cmd.x, cmd.y);
940 inset_hit->edit(cur, cmd.x, cmd.y);
942 text->setCursorFromCoordinates(cur.current(), cmd.x, cmd.y);
943 lyxerr << "created temp cursor: " << cur << endl;
945 // Dispatch to the temp cursor.
946 // An inset (or LyXText) can assign this to bv->cursor()
947 // if it wishes to do so.
948 DispatchResult res = cur.dispatch(cmd);
950 if (fitCursor() || res.update())
953 // see workAreaKeyPress
954 cursor_timeout.restart();
955 screen().showCursor(*bv_);
957 // skip these when selecting
958 if (cmd.action != LFUN_MOUSE_MOTION) {
959 owner_->updateLayoutChoice();
960 owner_->updateToolbar();
963 // slight hack: this is only called currently when we
964 // clicked somewhere, so we force through the display
965 // of the new status here.
966 owner_->clearMessage();
977 bool BufferView::Pimpl::dispatch(FuncRequest const & cmd)
979 //lyxerr << "*** BufferView::Pimpl: request: " << cmd << std::endl;
980 // Make sure that the cached BufferView is correct.
981 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch:"
982 << " action[" << cmd.action << ']'
983 << " arg[" << cmd.argument << ']'
984 << " x[" << cmd.x << ']'
985 << " y[" << cmd.y << ']'
986 << " button[" << cmd.button() << ']'
989 LyXTextClass const & tclass = buffer_->params().getLyXTextClass();
990 LCursor & cur = bv_->cursor();
992 switch (cmd.action) {
996 cur.message(_("Undo"));
997 cur.clearSelection();
999 cur.message(_("No further undo information"));
1007 cur.message(_("Redo"));
1008 cur.clearSelection();
1009 if (!textRedo(*bv_))
1010 cur.message(_("No further redo information"));
1016 case LFUN_FILE_INSERT:
1017 MenuInsertLyXFile(cmd.argument);
1020 case LFUN_FILE_INSERT_ASCII_PARA:
1021 InsertAsciiFile(bv_, cmd.argument, true);
1024 case LFUN_FILE_INSERT_ASCII:
1025 InsertAsciiFile(bv_, cmd.argument, false);
1028 case LFUN_FONT_STATE:
1029 owner_->getLyXFunc().setMessage(currentState(bv_));
1032 case LFUN_INSERT_LABEL: {
1033 // Try and generate a valid label
1034 string const contents = cmd.argument.empty() ?
1035 getPossibleLabel(*bv_) : cmd.argument;
1036 InsetCommandParams icp("label", contents);
1037 string data = InsetCommandMailer::params2string("label", icp);
1038 owner_->getDialogs().show("label", data, 0);
1042 case LFUN_BOOKMARK_SAVE:
1043 savePosition(strToUnsignedInt(cmd.argument));
1046 case LFUN_BOOKMARK_GOTO:
1047 restorePosition(strToUnsignedInt(cmd.argument));
1050 case LFUN_REF_GOTO: {
1051 string label = cmd.argument;
1052 if (label.empty()) {
1054 static_cast<InsetRef*>(getInsetByCode(InsetBase::REF_CODE));
1056 label = inset->getContents();
1062 bv_->gotoLabel(label);
1066 case LFUN_FLOAT_LIST:
1067 if (tclass.floats().typeExist(cmd.argument)) {
1068 InsetBase * inset = new InsetFloatList(cmd.argument);
1070 // not quite sure if we want this...
1071 bv_->text()->recUndo(bv_->text()->cursor().par());
1074 cur.clearSelection();
1075 bv_->text()->breakParagraph(bv_->buffer()->paragraphs());
1077 if (!bv_->text()->cursorPar()->empty()) {
1078 bv_->text()->cursorLeft(true);
1079 bv_->text()->breakParagraph(bv_->buffer()->paragraphs());
1082 bv_->text()->setLayout(tclass.defaultLayoutName());
1083 bv_->text()->setParagraph(Spacing(), LYX_ALIGN_LAYOUT, string(), 0);
1084 bv_->getLyXText()->insertInset(inset);
1087 lyxerr << "Non-existent float type: "
1088 << cmd.argument << endl;
1092 case LFUN_PARAGRAPH_APPLY:
1093 setParagraphParams(*bv_, cmd.argument);
1096 case LFUN_THESAURUS_ENTRY: {
1097 string arg = cmd.argument;
1100 arg = cur.selectionAsString(false);
1102 if (arg.size() > 100 || arg.empty()) {
1103 // Get word or selection
1104 bv_->getLyXText()->selectWordWhenUnderCursor(lyx::WHOLE_WORD);
1105 arg = cur.selectionAsString(false);
1106 // FIXME: where is getLyXText()->unselect(bv_) ?
1110 bv_->owner()->getDialogs().show("thesaurus", arg);
1114 case LFUN_TRACK_CHANGES:
1118 case LFUN_MERGE_CHANGES:
1119 owner_->getDialogs().show("changes");
1122 case LFUN_ACCEPT_ALL_CHANGES: {
1123 bv_->text()->setCursor(0, 0);
1124 #warning FIXME changes
1125 while (lyx::find::findNextChange(bv_))
1126 bv_->getLyXText()->acceptChange();
1131 case LFUN_REJECT_ALL_CHANGES: {
1132 bv_->text()->setCursor(0, 0);
1133 #warning FIXME changes
1134 while (lyx::find::findNextChange(bv_))
1135 bv_->getLyXText()->rejectChange();
1140 case LFUN_ACCEPT_CHANGE: {
1141 bv_->getLyXText()->acceptChange();
1146 case LFUN_REJECT_CHANGE: {
1147 bv_->getLyXText()->rejectChange();
1152 case LFUN_WORD_FIND:
1153 lyx::find::find(bv_, cmd);
1156 case LFUN_WORD_REPLACE:
1157 lyx::find::replace(bv_, cmd);
1161 cur.clearSelection();
1164 cur.message(N_("Mark off"));
1168 cur.clearSelection();
1172 cur.message(N_("Mark on"));
1176 cur.clearSelection();
1178 cur.message(N_("Mark removed"));
1181 cur.message(N_("Mark set"));
1187 case LFUN_UNKNOWN_ACTION:
1188 cur.errorMessage(N_("Unknown function!"));
1199 bool BufferView::Pimpl::ChangeInsets(InsetBase::Code code,
1200 string const & from, string const & to)
1202 bool need_update = false;
1203 CursorSlice cur = bv_->text()->cursor();
1205 ParIterator end = bv_->buffer()->par_iterator_end();
1206 for (ParIterator it = bv_->buffer()->par_iterator_begin();
1208 bool changed_inset = false;
1209 for (InsetList::iterator it2 = it->insetlist.begin();
1210 it2 != it->insetlist.end(); ++it2) {
1211 if (it2->inset->lyxCode() == code) {
1212 InsetCommand * inset = static_cast<InsetCommand *>(it2->inset);
1213 if (inset->getContents() == from) {
1214 inset->setContents(to);
1215 changed_inset = true;
1219 if (changed_inset) {
1224 // The test it.size() == 1 was needed to prevent crashes.
1225 // How to set the cursor correctly when it.size() > 1 ??
1226 if (it.size() == 1) {
1227 bv_->text()->setCursorIntern(bv_->text()->parOffset(it.pit()), 0);
1228 bv_->text()->redoParagraph(bv_->text()->cursorPar());
1232 bv_->text()->setCursorIntern(cur.par(), cur.pos());